BxBaseModProfileUploaderCoverCrop.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 = array();
  41. if ($sFormat == 'array')
  42. $a = $s;
  43. else if ($sFormat == 'json')
  44. $a = json_decode($s, true);
  45. if (!$a)
  46. return $s;
  47. // filter out thumbnails
  48. $CNF = $this->_oModule->_oConfig->CNF;
  49. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  50. $aResult = array();
  51. foreach ($a as $aFile) {
  52. // for cover image show only unassigned ghosts and currently set covers
  53. if ($aFile['file_id'] == $aContentInfo[$CNF['FIELD_COVER']] || $aFile['file_id'] != $aContentInfo[$CNF['FIELD_PICTURE']])
  54. $aResult[] = $aFile;
  55. }
  56. if ('array' == $sFormat) {
  57. return $a;
  58. }
  59. else if ('json' == $sFormat) {
  60. return json_encode($a);
  61. } else { // html format is not suported for this data type
  62. return false;
  63. }
  64. }
  65. protected function isAdmin ($iContentId = 0)
  66. {
  67. return $this->_oModule->_isModerator (false);
  68. }
  69. }
  70. /** @} */