BxBaseModProfileUploaderCrop.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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, $mixedContent = false)
  24. {
  25. if(!$mixedContent)
  26. return parent::deleteGhostsForProfile($iProfileId, $mixedContent);
  27. $iCount = 0;
  28. $oStorage = BxDolStorage::getObjectInstance($this->_sStorageObject);
  29. if($oStorage === false)
  30. return $iCount;
  31. $aContentInfo = $this->_oModule->_oDb->getContentInfoById(is_array($mixedContent) ? reset($mixedContent) : $mixedContent);
  32. $aGhosts = $oStorage->getGhosts($iProfileId, $mixedContent, $mixedContent ? true : false);
  33. foreach ($aGhosts as $aFile) {
  34. // for requested image type delete only unassigned ghosts and currently set images
  35. if ($aFile['id'] == $aContentInfo[$this->_sImage] || !in_array($aFile['id'], array_map(function($sField) use ($aContentInfo) {
  36. return $aContentInfo[$sField];
  37. }, $this->_aOtherImages)))
  38. $iCount += $oStorage->deleteFile($aFile['id']);
  39. }
  40. return $iCount;
  41. }
  42. public function getGhosts($iProfileId, $sFormat, $sImagesTranscoder = false, $iContentId = false)
  43. {
  44. $s = parent::getGhosts($iProfileId, $sFormat, $sImagesTranscoder, $iContentId);
  45. if (!$s || !$iContentId) // if we're creating new profile return all ghosts
  46. return $s;
  47. $a = array();
  48. if ($sFormat == 'array')
  49. $a = $s;
  50. else if ($sFormat == 'json')
  51. $a = json_decode($s, true);
  52. if (!$a)
  53. return $s;
  54. // filter out thumbnails
  55. $CNF = $this->_oModule->_oConfig->CNF;
  56. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  57. $aResult = array();
  58. foreach ($a as $aFile) {
  59. // for requested image type show only unassigned ghosts and currently set images
  60. if ($aFile['file_id'] == $aContentInfo[$this->_sImage] || !in_array($aFile['file_id'], array_map(function($sField) use ($aContentInfo) {
  61. return $aContentInfo[$sField];
  62. }, $this->_aOtherImages)))
  63. $aResult[$aFile['file_id']] = $aFile;
  64. }
  65. if ('array' == $sFormat) {
  66. return $aResult;
  67. }
  68. else if ('json' == $sFormat) {
  69. return json_encode($aResult);
  70. } else { // html format is not suported for this data type
  71. return false;
  72. }
  73. }
  74. protected function isAdmin ($iContentId = 0)
  75. {
  76. return $this->_oModule->_isModerator (false);
  77. }
  78. }
  79. /** @} */