BxBaseModProfileUploaderPictureCrop.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup BaseProfile Base classes for profile modules
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModProfileUploaderPictureCrop extends BxTemplUploaderCrop
  12. {
  13. protected $_oModule;
  14. public function __construct ($aObject, $sStorageObject, $sUniqId, $oTemplate)
  15. {
  16. parent::__construct($aObject, $sStorageObject, $sUniqId, $oTemplate);
  17. }
  18. public function deleteGhostsForProfile($iProfileId, $iContentId = false)
  19. {
  20. if (!$iContentId)
  21. return parent::deleteGhostsForProfile($iProfileId, $iContentId);
  22. $CNF = $this->_oModule->_oConfig->CNF;
  23. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  24. $iCount = 0;
  25. $oStorage = BxDolStorage::getObjectInstance($this->_sStorageObject);
  26. $aGhosts = $oStorage->getGhosts($iProfileId, $iContentId, $iContentId ? true : false);
  27. foreach ($aGhosts as $aFile) {
  28. // for profile image delete only unassigned ghosts and currently set profile pictures
  29. if ($aFile['id'] == $aContentInfo[$CNF['FIELD_PICTURE']] || $aFile['id'] != $aContentInfo[$CNF['FIELD_COVER']])
  30. $iCount += $oStorage->deleteFile($aFile['id']);
  31. }
  32. return $iCount;
  33. }
  34. public function getGhosts($iProfileId, $sFormat, $sImagesTranscoder = false, $iContentId = false)
  35. {
  36. $s = parent::getGhosts($iProfileId, $sFormat, $sImagesTranscoder, $iContentId);
  37. if (!$s || !$iContentId) // if we're creating new profile return all ghosts
  38. return $s;
  39. $a = json_decode($s, true);
  40. if (!$a)
  41. return $s;
  42. // filter out thumbnails
  43. $CNF = $this->_oModule->_oConfig->CNF;
  44. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  45. $aResult = array();
  46. foreach ($a as $aFile) {
  47. // for profile pictures show only unassigned ghosts and currently set profile pictures
  48. if ($sImagesTranscoder == $CNF['OBJECT_IMAGES_TRANSCODER_THUMB'] && ($aFile['file_id'] == $aContentInfo[$CNF['FIELD_PICTURE']] || $aFile['file_id'] != $aContentInfo[$CNF['FIELD_COVER']]))
  49. $aResult[] = $aFile;
  50. }
  51. return json_encode($aResult);
  52. }
  53. }
  54. /** @} */