BxBaseModProfileUploaderPictureCrop.php 2.8 KB

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