BxBaseModProfileUploaderCoverCrop.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 BxBaseModProfileUploaderCoverCrop extends BxTemplUploaderCrop
  12. {
  13. protected $_oModule;
  14. public function __construct ($aObject, $sStorageObject, $sUniqId, $oTemplate)
  15. {
  16. parent::__construct($aObject, $sStorageObject, $sUniqId, $oTemplate ? $oTemplate : $this->_oModule->_oTemplate);
  17. $this->_sUploaderFormTemplate = 'uploader_form_crop_cover.html';
  18. }
  19. public function deleteGhostsForProfile($iProfileId, $iContentId = false)
  20. {
  21. if (!$iContentId)
  22. return parent::deleteGhostsForProfile($iProfileId, $iContentId);
  23. $CNF = $this->_oModule->_oConfig->CNF;
  24. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  25. $iCount = 0;
  26. $oStorage = BxDolStorage::getObjectInstance($this->_sStorageObject);
  27. $aGhosts = $oStorage->getGhosts($iProfileId, $iContentId, $iContentId ? true : false);
  28. foreach ($aGhosts as $aFile) {
  29. // for cover image delete only unassigned ghosts and currently set covers
  30. if ($aFile['id'] == $aContentInfo[$CNF['FIELD_COVER']] || $aFile['id'] != $aContentInfo[$CNF['FIELD_PICTURE']])
  31. $iCount += $oStorage->deleteFile($aFile['id']);
  32. }
  33. return $iCount;
  34. }
  35. public function getGhosts($iProfileId, $sFormat, $sImagesTranscoder = false, $iContentId = false)
  36. {
  37. $s = parent::getGhosts($iProfileId, $sFormat, $sImagesTranscoder, $iContentId);
  38. if (!$s || !$iContentId) // if we're creating new profile return all ghosts
  39. return $s;
  40. $a = json_decode($s, true);
  41. if (!$a)
  42. return $s;
  43. // filter out thumbnails
  44. $CNF = $this->_oModule->_oConfig->CNF;
  45. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  46. $aResult = array();
  47. foreach ($a as $aFile) {
  48. // for cover image show only unassigned ghosts and currently set covers
  49. if ($aFile['file_id'] == $aContentInfo[$CNF['FIELD_COVER']] || $aFile['file_id'] != $aContentInfo[$CNF['FIELD_PICTURE']])
  50. $aResult[] = $aFile;
  51. }
  52. return json_encode($aResult);
  53. }
  54. }
  55. /** @} */