BxAlbumsModule.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  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 Albums Albums
  7. * @ingroup UnaModules
  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. /**
  23. * Entry actions and social sharing block
  24. */
  25. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  26. {
  27. if(!empty($mixedContent)) {
  28. if(!is_array($mixedContent))
  29. $mixedContent = array((int)$mixedContent, array());
  30. }
  31. else {
  32. $mixedContent = $this->_getContent();
  33. if($mixedContent === false)
  34. return false;
  35. }
  36. list($iContentId, $aContentInfo) = $mixedContent;
  37. $aMedias = $this->_oDb->getMediaListByContentId($iContentId);
  38. if(!empty($aMedias) && is_array($aMedias)) {
  39. $aMedia = array_shift($aMedias);
  40. if(!empty($aMedia['file_id']))
  41. $aParams = array_merge(array(
  42. 'entry_thumb' => $aMedia['file_id']
  43. ), $aParams);
  44. }
  45. return parent::serviceEntityAllActions(array($iContentId, $aContentInfo), $aParams);
  46. }
  47. /**
  48. * Display form for adding media to the album.
  49. * @param $iContentId album content id where media will be added, if it's not provided then it's determined from 'id' GET variable
  50. * @return HTML string with form, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML. On error false or empty string is returned.
  51. */
  52. public function serviceEntityAddFiles ($iContentId = 0)
  53. {
  54. return $this->_serviceEntityForm ('editDataForm', $iContentId, 'bx_albums_entry_add_images');
  55. }
  56. /**
  57. * Delete file and album association, also file views, votes, comments, meta data are also deleted
  58. * @param $iFileId file ID
  59. * @return true on success of false on error
  60. */
  61. public function serviceDeleteFileAssociations($iFileId)
  62. {
  63. $CNF = &$this->_oConfig->CNF;
  64. if (!($aMediaInfo = $this->_oDb->getMediaInfoSimpleByFileId($iFileId))) // file is already deleted
  65. return true;
  66. if (!$this->_oDb->deassociateFileWithContent(0, $iFileId))
  67. return false;
  68. $aContentInfo = $this->_oDb->getContentInfoById($aMediaInfo['content_id']);
  69. $iSender = isLogged() ? bx_get_logged_profile_id() : $aMediaInfo['author'];
  70. $iAuthor = isset($aContentInfo[$CNF['FIELD_AUTHOR']]) ? $aContentInfo[$CNF['FIELD_AUTHOR']] : $aMediaInfo['author'];
  71. bx_alert($this->getName(), 'media_deleted', $aMediaInfo['content_id'], $iSender, array(
  72. 'object_author_id' => $iAuthor,
  73. 'subobject_id' => $aMediaInfo['id'],
  74. 'media_id' => $aMediaInfo['id'],
  75. 'media_info' => $aMediaInfo,
  76. ));
  77. bx_alert($this->getName() . '_media', 'deleted', $aMediaInfo['id'], $iSender, array(
  78. 'object_id' => $aMediaInfo['content_id'],
  79. 'object_author_id' => $iAuthor,
  80. 'media_info' => $aMediaInfo,
  81. ));
  82. if (!empty($CNF['OBJECT_VIEWS_MEDIA'])) {
  83. $o = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS_MEDIA'], $aMediaInfo['id']);
  84. if ($o) $o->onObjectDelete();
  85. }
  86. if (!empty($CNF['OBJECT_VOTES_MEDIA'])) {
  87. $o = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_MEDIA'], $aMediaInfo['id']);
  88. if ($o) $o->onObjectDelete();
  89. }
  90. if (!empty($CNF['OBJECT_SCORES_MEDIA'])) {
  91. $o = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES_MEDIA'], $aMediaInfo['id']);
  92. if ($o) $o->onObjectDelete();
  93. }
  94. if (!empty($CNF['OBJECT_COMMENTS_MEDIA'])) {
  95. $o = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS_MEDIA'], $aMediaInfo['id']);
  96. if ($o) $o->onObjectDelete();
  97. }
  98. if (!empty($CNF['OBJECT_METATAGS_MEDIA'])) {
  99. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA']);
  100. $oMetatags->onDeleteContent($aMediaInfo['id']);
  101. }
  102. if (!empty($CNF['OBJECT_METATAGS_MEDIA_CAMERA'])) {
  103. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA_CAMERA']);
  104. $oMetatags->onDeleteContent($aMediaInfo['id']);
  105. }
  106. return true;
  107. }
  108. /**
  109. * Display media EXIF information.
  110. * @param $iMediaId media ID, if it's omitted then it's taken from 'id' GET variable.
  111. * @return HTML string with EXIF info. On error empty string is returned.
  112. */
  113. public function serviceMediaExif ($iMediaId = 0)
  114. {
  115. return $this->_serviceTemplateFunc ('mediaExif', $iMediaId, 'getMediaInfoById');
  116. }
  117. /**
  118. * Display media comments block.
  119. * @param $iMediaId media ID, if it's omitted then it's taken from 'id' GET variable.
  120. * @return HTML string with comments. On error false or empty string is returned.
  121. */
  122. public function serviceMediaComments ($iMediaId = 0)
  123. {
  124. return $this->_entityComments($this->_oConfig->CNF['OBJECT_COMMENTS_MEDIA'], $iMediaId);
  125. }
  126. /**
  127. * Display media author block.
  128. * @param $iMediaId media ID, if it's omitted then it's taken from 'id' GET variable.
  129. * @return HTML string with block content. On error false or empty string is returned.
  130. */
  131. public function serviceMediaAuthor ($iMediaId = 0)
  132. {
  133. return $this->_serviceTemplateFunc ('mediaAuthor', $iMediaId, 'getMediaInfoById');
  134. }
  135. /**
  136. * Entry actions and social sharing block
  137. */
  138. public function serviceMediaAllActions ($mixedContent = false, $aParams = array())
  139. {
  140. $iMediaId = 0;
  141. $aMediaInfo = array();
  142. $bContent = !empty($mixedContent);
  143. if($bContent && is_array($mixedContent))
  144. list($iMediaId, $aMediaInfo) = $mixedContent;
  145. else {
  146. if($bContent)
  147. $iMediaId = (int)$mixedContent;
  148. else
  149. $iMediaId = bx_process_input(bx_get('id'), BX_DATA_INT);
  150. if(!$iMediaId)
  151. return false;
  152. $aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
  153. }
  154. if(!$iMediaId || !$aMediaInfo)
  155. return false;
  156. $CNF = &$this->_oConfig->CNF;
  157. return parent::serviceEntityAllActions (array($iMediaId, $aMediaInfo), array_merge(array(
  158. 'object_menu' => $CNF['OBJECT_MENU_ACTIONS_VIEW_MEDIA_ALL'],
  159. 'object_transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_BIG'],
  160. 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_MEDIA'] . '&id=' . $iMediaId),
  161. 'entry_title' => $aMediaInfo['title'],
  162. 'entry_thumb' => $aMediaInfo['file_id']
  163. ), $aParams));
  164. }
  165. /**
  166. * Entry actions block
  167. */
  168. public function serviceMediaActions ($iContentId = 0)
  169. {
  170. $iContentId = $this->_getContent($iContentId, false);
  171. if($iContentId === false)
  172. return false;
  173. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_MEDIA']);
  174. return $oMenu ? $oMenu->getCode() : false;
  175. }
  176. /**
  177. * Display media social sharing buttons block.
  178. * @param $iMediaId media ID, if it's omitted then it's taken from 'id' GET variable.
  179. * @return HTML string with block content. On error false or empty string is returned.
  180. */
  181. public function serviceMediaSocialSharing ($iMediaId = 0)
  182. {
  183. if(!$iMediaId)
  184. $iMediaId = bx_process_input(bx_get('id'), BX_DATA_INT);
  185. if(!$iMediaId)
  186. return false;
  187. $aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
  188. if(!$aMediaInfo)
  189. return false;
  190. $CNF = &$this->_oConfig->CNF;
  191. return $this->serviceEntitySocialSharing(array($iMediaId, $aMediaInfo), array(
  192. 'uri' => $CNF['URI_VIEW_MEDIA'],
  193. 'title' => $aMediaInfo['title'],
  194. 'id_thumb' => $aMediaInfo['file_id'],
  195. 'object_transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_BIG']
  196. ));
  197. }
  198. /**
  199. * Display media preview block.
  200. * @param $iMediaId media ID, if it's omitted then it's taken from 'id' GET variable.
  201. * @param $mixedContext current context to navigate to next and previous file, possible values: popular, public, author. If omitted then value from 'context' GTE variable is taken. Default context is 'album' - when nothin is specified.
  202. * @param $aParams array of additional params.
  203. * @return HTML string with block content. On error false or empty string is returned.
  204. */
  205. public function serviceMediaView ($iMediaId = 0, $mixedContext = false, $aParams = array())
  206. {
  207. if(!$iMediaId)
  208. $iMediaId = bx_process_input(bx_get('id'), BX_DATA_INT);
  209. if(!$iMediaId)
  210. return false;
  211. if(!$mixedContext) {
  212. $mixedContext = bx_process_input(bx_get('context'));
  213. if(!in_array($mixedContext, $this->_aContexts)) // when no context specified, it is assumed that it is an album context
  214. $mixedContext = bx_process_input($mixedContext, BX_DATA_INT); // numeric context is reserved for future use
  215. }
  216. $aParams['context'] = $mixedContext;
  217. $iAutoplay = 0;
  218. if(!isset($aParams['autoplay']) && ($iAutoplay = bx_get('autoplay')) !== false)
  219. $aParams['autoplay'] = (int)$iAutoplay;
  220. return $this->_oTemplate->entryMediaView ($iMediaId, $aParams);
  221. }
  222. public function checkAllowedSetThumb ($iContentId = 0)
  223. {
  224. return CHECK_ACTION_RESULT_NOT_ALLOWED;
  225. }
  226. /**
  227. * Display block for browsing recently uploaded media files.
  228. * @param $sUnitView unit view mode: gallery
  229. * @param $bDisplayEmptyMsg display 'empty' message when nothing to browse, or return empty string.
  230. * @param $bAjaxPaginate use AJAX or regular paginate.
  231. * @return HTML string with block content. On error false or empty string is returned.
  232. */
  233. public function serviceBrowseRecentMedia ($sUnitView = false, $bDisplayEmptyMsg = true, $bAjaxPaginate = true)
  234. {
  235. return $this->_serviceBrowse ('recent', array('unit_view' => $sUnitView), BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate, 'SearchResultMedia');
  236. }
  237. /**
  238. * Display featured media.
  239. * For the list of params @see BxAlbumsModule::serviceBrowseRecentMedia
  240. */
  241. public function serviceBrowseFeaturedMedia ($sUnitView = false, $bDisplayEmptyMsg = false, $bAjaxPaginate = true)
  242. {
  243. return $this->_serviceBrowse ('featured', array('unit_view' => $sUnitView), BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate, 'SearchResultMedia');
  244. }
  245. /**
  246. * Display popular media.
  247. * For the list of params @see BxAlbumsModule::serviceBrowseRecentMedia
  248. */
  249. public function serviceBrowsePopularMedia ($sUnitView = false, $bDisplayEmptyMsg = true, $bAjaxPaginate = true)
  250. {
  251. return $this->_serviceBrowse ('popular', array('unit_view' => $sUnitView), BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate, 'SearchResultMedia');
  252. }
  253. /**
  254. * Display favorite media for particular profile.
  255. * @param $iProfileId profile ID, if omitted then 'profile_id' GET variable is used
  256. * @param $aParams additional params for browsing such as 'unit_view'
  257. */
  258. public function serviceBrowseFavoriteMedia ($iProfileId = 0, $aParams = array())
  259. {
  260. $oProfile = null;
  261. if((int)$iProfileId)
  262. $oProfile = BxDolProfile::getInstance($iProfileId);
  263. if(!$oProfile && bx_get('profile_id') !== false)
  264. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  265. if(!$oProfile)
  266. $oProfile = BxDolProfile::getInstance();
  267. if(!$oProfile)
  268. return '';
  269. $bEmptyMessage = false;
  270. if(isset($aParams['empty_message'])) {
  271. $bEmptyMessage = (bool)$aParams['empty_message'];
  272. unset($aParams['empty_message']);
  273. }
  274. return $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage, true, 'SearchResultMedia');
  275. }
  276. public function serviceGetTimelineData()
  277. {
  278. $sModule = $this->_aModule['name'];
  279. $aResult = parent::serviceGetTimelineData();
  280. $aResult['handlers'] = array_merge($aResult['handlers'], array(
  281. array('group' => $sModule . '_object_media', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'medias_added', 'module_name' => $sModule, 'module_method' => 'get_timeline_media', 'module_class' => 'Module', 'groupable' => 0, 'group_by' => ''),
  282. ));
  283. $aResult['alerts'] = array_merge($aResult['alerts'], array(
  284. array('unit' => $sModule, 'action' => 'medias_added')
  285. ));
  286. return $aResult;
  287. }
  288. public function serviceGetTimelineMedia($aEvent, $aBrowseParams = array())
  289. {
  290. if(empty($aEvent['content']))
  291. return false;
  292. $aEvent['content'] = unserialize($aEvent['content']);
  293. if(empty($aEvent['content']['medias_added']) || !is_array($aEvent['content']['medias_added']))
  294. return false;
  295. $iContentId = (int)$aEvent['object_id'];
  296. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  297. if(empty($aContentInfo) || !is_array($aContentInfo))
  298. return false;
  299. $CNF = &$this->_oConfig->CNF;
  300. //--- Views
  301. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId) : null;
  302. $aViews = array();
  303. if ($oViews && $oViews->isEnabled())
  304. $aViews = array(
  305. 'system' => $CNF['OBJECT_VIEWS'],
  306. 'object_id' => $iContentId,
  307. 'count' => $aContentInfo['views']
  308. );
  309. //--- Votes
  310. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId) : null;
  311. $aVotes = array();
  312. if ($oVotes && $oVotes->isEnabled())
  313. $aVotes = array(
  314. 'system' => $CNF['OBJECT_VOTES'],
  315. 'object_id' => $iContentId,
  316. 'count' => $aContentInfo['votes']
  317. );
  318. //--- Scores
  319. $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContentId) : null;
  320. $aScores = array();
  321. if ($oScores && $oScores->isEnabled())
  322. $aScores = array(
  323. 'system' => $CNF['OBJECT_SCORES'],
  324. 'object_id' => $iContentId,
  325. 'score' => $aContentInfo['score']
  326. );
  327. //--- Reports
  328. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aEvent['object_id']) : null;
  329. $aReports = array();
  330. if ($oReports && $oReports->isEnabled())
  331. $aReports = array(
  332. 'system' => $CNF['OBJECT_REPORTS'],
  333. 'object_id' => $iContentId,
  334. 'count' => $aContentInfo['reports']
  335. );
  336. //--- Comments
  337. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId) : null;
  338. $aComments = array();
  339. if($oCmts && $oCmts->isEnabled())
  340. $aComments = array(
  341. 'system' => $CNF['OBJECT_COMMENTS'],
  342. 'object_id' => $iContentId,
  343. 'count' => $aContentInfo['comments']
  344. );
  345. //--- Title & Description
  346. $sTitle = isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : (isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...') : '');
  347. return array(
  348. 'owner_id' => $aEvent['owner_id'],
  349. 'object_owner_id' => $aContentInfo['author'],
  350. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  351. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  352. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  353. 'sample_action' => $CNF['T']['txt_sample_action_changed'],
  354. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId),
  355. 'content' => $this->_getContentForTimelineMedia($aEvent, $aContentInfo, $aBrowseParams), //a string to display or array to parse default template before displaying.
  356. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  357. 'views' => $aViews,
  358. 'votes' => $aVotes,
  359. 'scores' => $aScores,
  360. 'reports' => $aReports,
  361. 'comments' => $aComments,
  362. 'title' => $sTitle, //may be empty.
  363. 'description' => '' //may be empty.
  364. );
  365. }
  366. public function serviceGetNotificationsData()
  367. {
  368. $sModule = $this->_aModule['name'];
  369. $sEventPrivacy = $sModule . '_allow_view_event_to';
  370. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  371. $sEventPrivacy = '';
  372. $aResult = parent::serviceGetNotificationsData();
  373. $aResult['handlers'] = array_merge($aResult['handlers'], array(
  374. array('group' => $sModule . '_object_media', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'medias_added', 'module_name' => $sModule, 'module_method' => 'get_notifications_media', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  375. array('group' => $sModule . '_object_media', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'media_deleted'),
  376. array('group' => $sModule . '_comment_media', 'type' => 'insert', 'alert_unit' => $sModule . '_media', 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment_media', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  377. array('group' => $sModule . '_comment_media', 'type' => 'delete', 'alert_unit' => $sModule . '_media', 'alert_action' => 'commentRemoved'),
  378. array('group' => $sModule . '_vote_media', 'type' => 'insert', 'alert_unit' => $sModule . '_media', 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote_media', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  379. array('group' => $sModule . '_vote_media', 'type' => 'delete', 'alert_unit' => $sModule . '_media', 'alert_action' => 'undoVote'),
  380. array('group' => $sModule . '_score_up_media', 'type' => 'insert', 'alert_unit' => $sModule . '_media', 'alert_action' => 'doVoteUp', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_up_media', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  381. array('group' => $sModule . '_score_down_media', 'type' => 'insert', 'alert_unit' => $sModule . '_media', 'alert_action' => 'doVoteDown', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_down_media', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  382. ));
  383. $aResult['settings'] = array_merge($aResult['settings'], array(
  384. array('group' => 'content', 'unit' => $sModule, 'action' => 'medias_added', 'types' => array('follow_member', 'follow_context')),
  385. array('group' => 'comment', 'unit' => $sModule . '_media', 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  386. array('group' => 'vote', 'unit' => $sModule . '_media', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  387. array('group' => 'score_up', 'unit' => $sModule . '_media', 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  388. array('group' => 'score_down', 'unit' => $sModule . '_media', 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  389. ));
  390. $aResult['alerts'] = array_merge($aResult['alerts'], array(
  391. array('unit' => $sModule, 'action' => 'medias_added'),
  392. array('unit' => $sModule, 'action' => 'media_deleted'),
  393. array('unit' => $sModule . '_media', 'action' => 'commentPost'),
  394. array('unit' => $sModule . '_media', 'action' => 'commentRemoved'),
  395. array('unit' => $sModule . '_media', 'action' => 'doVote'),
  396. array('unit' => $sModule . '_media', 'action' => 'undoVote'),
  397. array('unit' => $sModule . '_media', 'action' => 'doVoteUp'),
  398. array('unit' => $sModule . '_media', 'action' => 'doVoteDown'),
  399. ));
  400. return $aResult;
  401. }
  402. public function serviceGetNotificationsMedia($aEvent)
  403. {
  404. $CNF = &$this->_oConfig->CNF;
  405. $iContentId = (int)$aEvent['object_id'];
  406. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  407. if(empty($aContentInfo) || !is_array($aContentInfo))
  408. return array();
  409. $iMediaId = (int)$aEvent['subobject_id'];
  410. $aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
  411. if(empty($aMediaInfo) || !is_array($aMediaInfo))
  412. return array();
  413. $oPermalinks = BxDolPermalinks::getInstance();
  414. $sEntryUrl = BX_DOL_URL_ROOT . $oPermalinks->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  415. $sSubentryUrl = BX_DOL_URL_ROOT . $oPermalinks->permalink('page.php?i=' . $CNF['URI_VIEW_MEDIA'] . '&id=' . $iMediaId);
  416. $sEntryCaption = isset($aMediaInfo['title']) ? $aMediaInfo['title'] : _t('_bx_albums_media');
  417. return array(
  418. 'entry_sample' => $CNF['T']['txt_sample_single'],
  419. 'entry_url' => $sEntryUrl,
  420. 'entry_caption' => $sEntryCaption,
  421. 'entry_author' => $aMediaInfo['author'],
  422. 'subentry_sample' => $CNF['T']['txt_media_single'],
  423. 'subentry_url' => $sSubentryUrl,
  424. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  425. );
  426. }
  427. public function serviceGetNotificationsCommentMedia($aEvent)
  428. {
  429. $CNF = &$this->_oConfig->CNF;
  430. $iMediaId = (int)$aEvent['object_id'];
  431. $aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
  432. if(empty($aMediaInfo) || !is_array($aMediaInfo))
  433. return array();
  434. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS_MEDIA'], $iMediaId);
  435. if(!$oComment || !$oComment->isEnabled())
  436. return array();
  437. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_MEDIA'] . '&id=' . $aMediaInfo['id']);
  438. $sEntryCaption = isset($aMediaInfo['title']) ? $aMediaInfo['title'] : _t('_bx_albums_media');
  439. return array(
  440. 'entry_sample' => $CNF['T']['txt_media_single'],
  441. 'entry_url' => $sEntryUrl,
  442. 'entry_caption' => $sEntryCaption,
  443. 'entry_author' => $aMediaInfo['author'],
  444. 'subentry_sample' => $CNF['T']['txt_media_comment_single'],
  445. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  446. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  447. );
  448. }
  449. public function serviceGetNotificationsVoteMedia($aEvent)
  450. {
  451. $CNF = &$this->_oConfig->CNF;
  452. $iMediaId = (int)$aEvent['object_id'];
  453. $aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
  454. if(empty($aMediaInfo) || !is_array($aMediaInfo))
  455. return array();
  456. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_MEDIA'], $iMediaId);
  457. if(!$oVote || !$oVote->isEnabled())
  458. return array();
  459. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_MEDIA'] . '&id=' . $aMediaInfo['id']);
  460. $sEntryCaption = isset($aMediaInfo['title']) ? $aMediaInfo['title'] : _t('_bx_albums_media');
  461. return array(
  462. 'entry_sample' => $CNF['T']['txt_media_single'],
  463. 'entry_url' => $sEntryUrl,
  464. 'entry_caption' => $sEntryCaption,
  465. 'entry_author' => $aMediaInfo['author'],
  466. 'subentry_sample' => $CNF['T']['txt_media_vote_single'],
  467. 'subentry_url' => '',
  468. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  469. );
  470. }
  471. public function serviceGetNotificationsScoreUpMedia($aEvent)
  472. {
  473. return $this->_serviceGetNotificationsScoreMedia('up', $aEvent);
  474. }
  475. public function serviceGetNotificationsScoreDownMedia($aEvent)
  476. {
  477. return $this->_serviceGetNotificationsScoreMedia('down', $aEvent);
  478. }
  479. protected function _serviceGetNotificationsScoreMedia($sType, $aEvent)
  480. {
  481. $CNF = &$this->_oConfig->CNF;
  482. $iMediaId = (int)$aEvent['object_id'];
  483. $aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
  484. if(empty($aMediaInfo) || !is_array($aMediaInfo))
  485. return array();
  486. $oVote = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES_MEDIA'], $iMediaId);
  487. if(!$oVote || !$oVote->isEnabled())
  488. return array();
  489. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_MEDIA'] . '&id=' . $aMediaInfo['id']);
  490. $sEntryCaption = isset($aMediaInfo['title']) ? $aMediaInfo['title'] : _t('_bx_albums_media');
  491. return array(
  492. 'entry_sample' => $CNF['T']['txt_media_single'],
  493. 'entry_url' => $sEntryUrl,
  494. 'entry_caption' => $sEntryCaption,
  495. 'entry_author' => $aMediaInfo['author'],
  496. 'subentry_sample' => $CNF['T']['txt_media_score_' . $sType . '_single'],
  497. 'subentry_url' => '',
  498. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  499. );
  500. }
  501. public function actionEditMedia($iMediaId)
  502. {
  503. $CNF = &$this->_oConfig->CNF;
  504. $iMediaId = (int)$iMediaId;
  505. $aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
  506. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_MEDIA'], $CNF['OBJECT_FORM_MEDIA_DISPLAY_EDIT']);
  507. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'edit_media/' . $iMediaId;
  508. $oForm->initChecker($aMediaInfo);
  509. if($oForm->isSubmittedAndValid()) {
  510. if($oForm->update($iMediaId) !== false)
  511. $aRes = array('reload' => 1);
  512. else
  513. $aRes = array('msg' => _t('_bx_albums_txt_err_cannot_perform_action'));
  514. return echoJson($aRes);
  515. }
  516. $sContent = BxTemplStudioFunctions::getInstance()->transBox('bx-albums-edit-media-popup', $this->_oTemplate->parseHtmlByName('media-edit.html', array(
  517. 'form_id' => $oForm->aFormAttrs['id'],
  518. 'form' => $oForm->getCode(true)
  519. )));
  520. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  521. }
  522. public function actionGetSiblingMedia($iMediaId, $mixedContext)
  523. {
  524. $aSiblings = false;
  525. $sErrorMsg = false;
  526. if (!($aMediaInfo = $this->_oDb->getMediaInfoById((int)$iMediaId)))
  527. $sErrorMsg = _t('_sys_txt_error_occured');
  528. if (empty($sErrorMsg) && !($aContentInfo = $this->_oDb->getContentInfoById($aMediaInfo['content_id'])))
  529. $sErrorMsg = _t('_sys_txt_error_occured');
  530. if (empty($sErrorMsg) && (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aContentInfo))))
  531. $sErrorMsg = $sMsg;
  532. if (empty($sErrorMsg)) {
  533. $aSiblings = array (
  534. 'next' => $this->_oTemplate->getNextPrevMedia($aMediaInfo, true, $mixedContext),
  535. 'prev' => $this->_oTemplate->getNextPrevMedia($aMediaInfo, false, $mixedContext),
  536. );
  537. }
  538. $a = $sErrorMsg ? array('error' => $sErrorMsg) : array('next' => $aSiblings['next'], 'prev' => $aSiblings['prev']);
  539. $s = json_encode($a);
  540. header('Content-type: text/html; charset=utf-8');
  541. echo $s;
  542. }
  543. public function actionRssMedia ()
  544. {
  545. $aArgs = func_get_args();
  546. $this->_rss($aArgs, 'SearchResultMedia');
  547. }
  548. public function getMediaDuration($aMediaInfo)
  549. {
  550. $CNF = &$this->_oConfig->CNF;
  551. if(empty($aMediaInfo) || !is_array($aMediaInfo))
  552. return 0;
  553. $sField = 'duration';
  554. if(!empty($aMediaInfo[$sField]))
  555. return (int)$aMediaInfo[$sField];
  556. $iMedia = $aMediaInfo['id'];
  557. $sMedia = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4'])->getFileUrl($iMedia);
  558. if(empty($sMedia))
  559. return 0;
  560. $iDuration = (int)BxDolTranscoderVideo::getDuration($sMedia);
  561. if(!empty($iDuration))
  562. $this->_oDb->updateMedia(array($sField => $iDuration), array('id' => $iMedia));
  563. return $iDuration;
  564. }
  565. protected function _buildRssParams($sMode, $aArgs)
  566. {
  567. if ($aParams = parent::_buildRssParams($sMode, $aArgs))
  568. return $aParams;
  569. $sMode = bx_process_input($sMode);
  570. switch ($sMode) {
  571. case 'album':
  572. $aParams = array('album_id' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  573. break;
  574. }
  575. return $aParams;
  576. }
  577. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  578. {
  579. $CNF = &$this->_oConfig->CNF;
  580. if(empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']))
  581. return array();
  582. $aMediaList = $this->_oDb->getMediaListByContentId($aContentInfo[$CNF['FIELD_ID']]);
  583. if(empty($aMediaList) || !is_array($aMediaList))
  584. return array();
  585. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  586. $oTcPoster = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']);
  587. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  588. $aOutput = array();
  589. foreach ($aMediaList as $aMedia) {
  590. $aFileInfo = $oStorage->getFile($aMedia['file_id']);
  591. $bVideo = $oTcPoster && strncmp('video/', $aFileInfo['mime_type'], 6) === 0 && $oTcPoster->isMimeTypeSupported($aFileInfo['mime_type']);
  592. if($bVideo)
  593. continue;
  594. $aOutput[$aMedia['id']] = array (
  595. 'url' => $this->_oTemplate->getViewMediaUrl($CNF, $aMedia['id']),
  596. 'src' => $oTranscoder->getFileUrl($aMedia['file_id']),
  597. );
  598. }
  599. return count($aOutput) > 3 ? array_slice($aOutput, 0, 3) : $aOutput;
  600. }
  601. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  602. {
  603. $CNF = &$this->_oConfig->CNF;
  604. if(empty($CNF['OBJECT_VIDEOS_TRANSCODERS']))
  605. return array();
  606. $aMediaList = $this->_oDb->getMediaListByContentId($aContentInfo[$CNF['FIELD_ID']]);
  607. if(empty($aMediaList) || !is_array($aMediaList))
  608. return array();
  609. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  610. $oTcPoster = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']);
  611. $oTcMp4 = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  612. $oTcMp4Hd = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4_hd']);
  613. if(!$oTcPoster || !$oTcMp4 || !$oTcMp4Hd)
  614. return $aResults;
  615. $aOutput = array();
  616. foreach($aMediaList as $k => $aMedia) {
  617. $aFileInfo = $oStorage->getFile($aMedia['file_id']);
  618. $bVideo = $oTcPoster && strncmp('video/', $aFileInfo['mime_type'], 6) === 0 && $oTcPoster->isMimeTypeSupported($aFileInfo['mime_type']);
  619. if(!$bVideo)
  620. continue;
  621. $sVideoUrl = $oStorage->getFileUrlById($aMedia['file_id']);
  622. $aVideoSize = $oTcMp4Hd->getVideoSize($sVideoUrl);
  623. $sVideoUrlHd = '';
  624. if(!empty($aVideoSize) && is_array($aVideoSize) && (int)$aVideoSize['h'] >= 720)
  625. $sVideoUrlHd = $oTcMp4Hd->getFileUrl($aMedia['file_id']);
  626. $aOutput[$aMedia['id']] = array(
  627. 'id' => $aMedia['id'],
  628. 'src_poster' => $oTcPoster->getFileUrl($aMedia['file_id']),
  629. 'src_mp4' => $oTcMp4->getFileUrl($aMedia['file_id']),
  630. 'src_mp4_hd' => $sVideoUrlHd,
  631. );
  632. }
  633. return count($aOutput) > 3 ? array_slice($aOutput, 0, 3) : $aOutput;
  634. }
  635. protected function _getContentForTimelineMedia($aEvent, $aContentInfo, $aBrowseParams = array())
  636. {
  637. $CNF = &$this->_oConfig->CNF;
  638. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  639. $sTitle = isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : (isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...') : '');
  640. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  641. $oTcPoster = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']);
  642. $oTcMp4 = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  643. $oTcMp4Hd = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4_hd']);
  644. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  645. //--- Image(s) and Video(s)
  646. $aImages = $aVideos = array();
  647. foreach($aEvent['content']['medias_added'] as $iMediaId) {
  648. $aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
  649. if(empty($aMediaInfo) || !is_array($aMediaInfo))
  650. continue;
  651. $aFileInfo = $oStorage->getFile($aMediaInfo['file_id']);
  652. $bVideo = $oTcPoster && strncmp('video/', $aFileInfo['mime_type'], 6) === 0 && $oTcPoster->isMimeTypeSupported($aFileInfo['mime_type']);
  653. if($bVideo)
  654. $aVideos[$iMediaId] = array(
  655. 'id' => $aMediaInfo['id'],
  656. 'src_poster' => $oTcPoster->getFileUrl($aMediaInfo['file_id']),
  657. 'src_mp4' => $oTcMp4->getFileUrl($aMediaInfo['file_id']),
  658. 'src_mp4_hd' => $oTcMp4Hd->getFileUrl($aMediaInfo['file_id']),
  659. );
  660. else
  661. $aImages[$iMediaId] = array(
  662. 'url' => $this->_oTemplate->getViewMediaUrl($CNF, $aMediaInfo['id']),
  663. 'src' => $oTranscoder->getFileUrl($aMediaInfo['file_id']),
  664. );
  665. }
  666. return array(
  667. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  668. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  669. 'sample_action' => isset($CNF['T']['txt_sample_action_changed']),
  670. 'url' => $sUrl,
  671. 'title' => $sTitle,
  672. 'text' => '',
  673. 'images_attach' => $aImages,
  674. 'videos_attach' => $aVideos
  675. );
  676. }
  677. protected function _getImagesForTimelineMedia($aEvent, $aMediaInfo, $sUrl, $aBrowseParams = array())
  678. {
  679. $CNF = &$this->_oConfig->CNF;
  680. $aImages = array();
  681. return $aImages;
  682. }
  683. }
  684. /** @} */