BxBaseModProfileUploaderCrop.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModProfileUploaderCrop extends BxTemplUploaderCrop
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. protected $_sImage;
  16. protected $_aOtherImages;
  17. public function __construct ($aObject, $sStorageObject, $sUniqId, $oTemplate)
  18. {
  19. if(!empty($this->_sModule) && empty($this->_oModule))
  20. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  21. parent::__construct($aObject, $sStorageObject, $sUniqId, $oTemplate ? $oTemplate : $this->_oModule->_oTemplate);
  22. }
  23. public function deleteGhostsForProfile($iProfileId, $iContentId = false)
  24. {
  25. if (!$iContentId)
  26. return parent::deleteGhostsForProfile($iProfileId, $iContentId);
  27. $CNF = $this->_oModule->_oConfig->CNF;
  28. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  29. $iCount = 0;
  30. $oStorage = BxDolStorage::getObjectInstance($this->_sStorageObject);
  31. $aGhosts = $oStorage->getGhosts($iProfileId, $iContentId, $iContentId ? true : false);
  32. foreach ($aGhosts as $aFile) {
  33. // for requested image type delete only unassigned ghosts and currently set images
  34. if ($aFile['id'] == $aContentInfo[$this->_sImage] || !in_array($aFile['id'], array_map(function($sField) use ($aContentInfo) {
  35. return $aContentInfo[$sField];
  36. }, $this->_aOtherImages)))
  37. $iCount += $oStorage->deleteFile($aFile['id']);
  38. }
  39. return $iCount;
  40. }
  41. public function getGhosts($iProfileId, $sFormat, $sImagesTranscoder = false, $iContentId = false)
  42. {
  43. $s = parent::getGhosts($iProfileId, $sFormat, $sImagesTranscoder, $iContentId);
  44. if (!$s || !$iContentId) // if we're creating new profile return all ghosts
  45. return $s;
  46. $a = array();
  47. if ($sFormat == 'array')
  48. $a = $s;
  49. else if ($sFormat == 'json')
  50. $a = json_decode($s, true);
  51. if (!$a)
  52. return $s;
  53. // filter out thumbnails
  54. $CNF = $this->_oModule->_oConfig->CNF;
  55. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  56. $aResult = array();
  57. foreach ($a as $aFile) {
  58. // for requested image type show only unassigned ghosts and currently set images
  59. if ($aFile['file_id'] == $aContentInfo[$this->_sImage] || !in_array($aFile['file_id'], array_map(function($sField) use ($aContentInfo) {
  60. return $aContentInfo[$sField];
  61. }, $this->_aOtherImages)))
  62. $aResult[$aFile['file_id']] = $aFile;
  63. }
  64. if ('array' == $sFormat) {
  65. return $aResult;
  66. }
  67. else if ('json' == $sFormat) {
  68. return json_encode($aResult);
  69. } else { // html format is not suported for this data type
  70. return false;
  71. }
  72. }
  73. protected function isAdmin ($iContentId = 0)
  74. {
  75. return $this->_oModule->_isModerator (false);
  76. }
  77. }
  78. /** @} */