BxAlbumsModule.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 Albums Albums
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolAcl');
  12. /**
  13. * Albums module
  14. */
  15. class BxAlbumsModule extends BxBaseModTextModule
  16. {
  17. protected $_aContexts = array('popular', 'public', 'author');
  18. function __construct(&$aModule)
  19. {
  20. parent::__construct($aModule);
  21. }
  22. public function serviceEntityAddFiles ($iContentId = 0)
  23. {
  24. return $this->_serviceEntityForm ('editDataForm', $iContentId, 'bx_albums_entry_add_images');
  25. }
  26. public function serviceDeleteFileAssociations($iFileId)
  27. {
  28. $CNF = &$this->_oConfig->CNF;
  29. if (!($aMediaInfo = $this->_oDb->getMediaInfoSimpleByFileId($iFileId))) // file is already deleted
  30. return true;
  31. if (!$this->_oDb->deassociateFileWithContent(0, $iFileId))
  32. return false;
  33. if (!empty($CNF['OBJECT_VIEWS_MEDIA'])) {
  34. $o = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS_MEDIA'], $aMediaInfo['id']);
  35. if ($o) $o->onObjectDelete();
  36. }
  37. if (!empty($CNF['OBJECT_VOTES_MEDIA'])) {
  38. $o = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_MEDIA'], $aMediaInfo['id']);
  39. if ($o) $o->onObjectDelete();
  40. }
  41. if (!empty($CNF['OBJECT_COMMENTS_MEDIA'])) {
  42. $o = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS_MEDIA'], $aMediaInfo['id']);
  43. if ($o) $o->onObjectDelete();
  44. }
  45. if (!empty($CNF['OBJECT_METATAGS_MEDIA'])) {
  46. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA']);
  47. $oMetatags->onDeleteContent($aMediaInfo['id']);
  48. }
  49. if (!empty($CNF['OBJECT_METATAGS_MEDIA_CAMERA'])) {
  50. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA_CAMERA']);
  51. $oMetatags->onDeleteContent($aMediaInfo['id']);
  52. }
  53. return true;
  54. }
  55. public function serviceMediaExif ($iMediaId = 0)
  56. {
  57. return $this->_serviceTemplateFunc ('mediaExif', $iMediaId, 'getMediaInfoById');
  58. }
  59. public function serviceMediaComments ($iMediaId = 0)
  60. {
  61. return $this->_entityComments($this->_oConfig->CNF['OBJECT_COMMENTS_MEDIA'], $iMediaId);
  62. }
  63. public function serviceMediaAuthor ($iMediaId = 0)
  64. {
  65. return $this->_serviceTemplateFunc ('mediaAuthor', $iMediaId, 'getMediaInfoById');
  66. }
  67. public function serviceMediaSocialSharing ($iMediaId = 0, $bEnableCommentsBtn = false, $bEnableSocialSharing = true)
  68. {
  69. if (!$iMediaId)
  70. $iMediaId = bx_process_input(bx_get('id'), BX_DATA_INT);
  71. if (!$iMediaId)
  72. return false;
  73. $aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
  74. if (!$aMediaInfo)
  75. return false;
  76. $CNF = &$this->_oConfig->CNF;
  77. return $this->_entitySocialSharing ($iMediaId, 0, $aMediaInfo['file_id'], $aMediaInfo['title'], false, $CNF['OBJECT_IMAGES_TRANSCODER_BIG'], $CNF['OBJECT_VOTES_MEDIA'], '', $CNF['URI_VIEW_MEDIA'], $bEnableCommentsBtn ? $CNF['OBJECT_COMMENTS_MEDIA'] : '', $bEnableSocialSharing);
  78. }
  79. public function serviceMediaView ($iMediaId = 0, $mixedContext = false)
  80. {
  81. if (!$iMediaId)
  82. $iMediaId = bx_process_input(bx_get('id'), BX_DATA_INT);
  83. if (!$iMediaId)
  84. return false;
  85. if (!$mixedContext) {
  86. $mixedContext = bx_process_input(bx_get('context'));
  87. if (!in_array($mixedContext, $this->_aContexts)) // when no context specified, it is assumed that it is an album context
  88. $mixedContext = bx_process_input($mixedContext, BX_DATA_INT); // numeric context is reserved for future use
  89. }
  90. return $this->_oTemplate->entryMediaView ($iMediaId, $mixedContext);
  91. }
  92. public function checkAllowedSetThumb ()
  93. {
  94. return CHECK_ACTION_RESULT_NOT_ALLOWED;
  95. }
  96. public function serviceBrowseRecentMedia ($sUnitView = false, $bDisplayEmptyMsg = true, $bAjaxPaginate = true)
  97. {
  98. return $this->_serviceBrowse ('recent', array('unit_view' => $sUnitView), BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate, 'SearchResultMedia');
  99. }
  100. public function serviceBrowsePopularMedia ($sUnitView = false, $bDisplayEmptyMsg = true, $bAjaxPaginate = true)
  101. {
  102. return $this->_serviceBrowse ('popular', array('unit_view' => $sUnitView), BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate, 'SearchResultMedia');
  103. }
  104. public function actionGetSiblingMedia($iMediaId, $mixedContext)
  105. {
  106. $aSiblings = false;
  107. $sErrorMsg = false;
  108. if (!($aMediaInfo = $this->_oDb->getMediaInfoById((int)$iMediaId)))
  109. $sErrorMsg = _t('_sys_txt_error_occured');
  110. if (empty($sErrorMsg) && !($aContentInfo = $this->_oDb->getContentInfoById($aMediaInfo['content_id'])))
  111. $sErrorMsg = _t('_sys_txt_error_occured');
  112. if (empty($sErrorMsg) && (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aContentInfo))))
  113. $sErrorMsg = $sMsg;
  114. if (empty($sErrorMsg)) {
  115. $aSiblings = array (
  116. 'next' => $this->_oTemplate->getNextPrevMedia($aMediaInfo, true, $mixedContext),
  117. 'prev' => $this->_oTemplate->getNextPrevMedia($aMediaInfo, false, $mixedContext),
  118. );
  119. }
  120. $a = $sErrorMsg ? array('error' => $sErrorMsg) : array('next' => $aSiblings['next'], 'prev' => $aSiblings['prev']);
  121. $s = json_encode($a);
  122. header('Content-type: text/html; charset=utf-8');
  123. echo $s;
  124. }
  125. public function actionRssMedia ()
  126. {
  127. $aArgs = func_get_args();
  128. $this->_rss($aArgs, 'SearchResultMedia');
  129. }
  130. protected function _buildRssParams($sMode, $aArgs)
  131. {
  132. if ($aParams = parent::_buildRssParams($sMode, $aArgs))
  133. return $aParams;
  134. $sMode = bx_process_input($sMode);
  135. switch ($sMode) {
  136. case 'album':
  137. $aParams = array('album_id' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  138. break;
  139. }
  140. return $aParams;
  141. }
  142. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl)
  143. {
  144. $CNF = &$this->_oConfig->CNF;
  145. if (!($aMediaList = $this->_oDb->getMediaListByContentId($aContentInfo[$CNF['FIELD_ID']])))
  146. return array();
  147. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  148. $aMediaList = array_slice($aMediaList, 0, 3);
  149. $aOutput = array();
  150. foreach ($aMediaList as $aMedia) {
  151. $aOutput[] = array (
  152. 'url' => $this->_oTemplate->getViewMediaUrl($CNF, $aMedia['id']),
  153. 'src' => $oTranscoder->getFileUrl($aMedia['file_id']),
  154. );
  155. }
  156. return $aOutput;
  157. }
  158. }
  159. /** @} */