BxBaseModProfileUploaderCoverCrop.php 3.1 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 BxBaseModProfileUploaderCoverCrop extends BxTemplUploaderHTML5
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. public function __construct ($aObject, $sStorageObject, $sUniqId, $oTemplate)
  16. {
  17. if(!empty($this->_sModule) && empty($this->_oModule))
  18. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  19. parent::__construct($aObject, $sStorageObject, $sUniqId, $oTemplate ? $oTemplate : $this->_oModule->_oTemplate);
  20. $this->_sUploaderFormTemplate = 'uploader_form_crop_cover.html';
  21. }
  22. public function deleteGhostsForProfile($iProfileId, $iContentId = false)
  23. {
  24. if (!$iContentId)
  25. return parent::deleteGhostsForProfile($iProfileId, $iContentId);
  26. $CNF = $this->_oModule->_oConfig->CNF;
  27. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  28. $iCount = 0;
  29. $oStorage = BxDolStorage::getObjectInstance($this->_sStorageObject);
  30. $aGhosts = $oStorage->getGhosts($iProfileId, $iContentId, $iContentId ? true : false);
  31. foreach ($aGhosts as $aFile) {
  32. // for cover image delete only unassigned ghosts and currently set covers
  33. if ($aFile['id'] == $aContentInfo[$CNF['FIELD_COVER']] || !in_array($aFile['id'], [$aContentInfo[$CNF['FIELD_BADGE']], $aContentInfo[$CNF['FIELD_PICTURE']]]))
  34. $iCount += $oStorage->deleteFile($aFile['id']);
  35. }
  36. return $iCount;
  37. }
  38. public function getGhosts($iProfileId, $sFormat, $sImagesTranscoder = false, $iContentId = false)
  39. {
  40. $s = parent::getGhosts($iProfileId, $sFormat, $sImagesTranscoder, $iContentId);
  41. if (!$s || !$iContentId) // if we're creating new profile return all ghosts
  42. return $s;
  43. $a = array();
  44. if ($sFormat == 'array')
  45. $a = $s;
  46. else if ($sFormat == 'json')
  47. $a = json_decode($s, true);
  48. if (!$a)
  49. return $s;
  50. // filter out thumbnails
  51. $CNF = $this->_oModule->_oConfig->CNF;
  52. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  53. $aResult = array();
  54. foreach ($a as $aFile) {
  55. // for cover image show only unassigned ghosts and currently set covers
  56. if ($aFile['file_id'] == $aContentInfo[$CNF['FIELD_COVER']] || !in_array(aFile['file_id'], [$aContentInfo[$CNF['FIELD_BADGE']], $aContentInfo[$CNF['FIELD_PICTURE']]]))
  57. $aResult[$aFile['file_id']] = $aFile;
  58. }
  59. if ('array' == $sFormat) {
  60. return $aResult;
  61. }
  62. else if ('json' == $sFormat) {
  63. return json_encode($aResult);
  64. } else { // html format is not suported for this data type
  65. return false;
  66. }
  67. }
  68. protected function isAdmin ($iContentId = 0)
  69. {
  70. return $this->_oModule->_isModerator (false);
  71. }
  72. }
  73. /** @} */