BxAlbumsModule.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041
  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. public function serviceGetSafeServices()
  23. {
  24. $a = parent::serviceGetSafeServices();
  25. return array_merge($a, array (
  26. 'EntityAddFiles' => '',
  27. 'MediaComments' => '',
  28. 'BrowseRecentMedia' => '',
  29. 'BrowseFeaturedMedia' => '',
  30. 'BrowsePopularMedia' => '',
  31. 'BrowseTopMedia' => '',
  32. 'BrowseFavoriteMedia' => '',
  33. ));
  34. }
  35. public function actionEmbed($iContentId, $sUnitTemplate = '', $sAddCode = '')
  36. {
  37. return $this->_oTemplate->getJsCode('main') . parent::actionEmbed($iContentId);
  38. }
  39. public function actionEmbedMedia($iContentId)
  40. {
  41. $oTemplate = BxDolTemplate::getInstance();
  42. $aContentInfo = $this->_oDb->getMediaInfoById($iContentId);
  43. if(empty($aContentInfo))
  44. $oTemplate->getEmbed(false);
  45. if(empty($sUnitTemplate))
  46. $sUnitTemplate = 'unit_media_gallery.html';
  47. $oTemplate->getEmbed($this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate));
  48. }
  49. /**
  50. * Entry actions and social sharing block
  51. */
  52. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  53. {
  54. if(!empty($mixedContent)) {
  55. if(!is_array($mixedContent))
  56. $mixedContent = array((int)$mixedContent, array());
  57. }
  58. else {
  59. $mixedContent = $this->_getContent();
  60. if($mixedContent === false)
  61. return false;
  62. }
  63. list($iContentId, $aContentInfo) = $mixedContent;
  64. $aMedias = $this->_oDb->getMediaListByContentId($iContentId);
  65. if(!empty($aMedias) && is_array($aMedias)) {
  66. $aMedia = array_shift($aMedias);
  67. if(!empty($aMedia['file_id']))
  68. $aParams = array_merge(array(
  69. 'entry_thumb' => $aMedia['file_id']
  70. ), $aParams);
  71. }
  72. return parent::serviceEntityAllActions(array($iContentId, $aContentInfo), $aParams);
  73. }
  74. /**
  75. * @page service Service Calls
  76. * @section bx_albums Albums
  77. * @subsection bx_albums-forms Forms
  78. * @subsubsection bx_albums-entity_add_files entity_add_files
  79. *
  80. * @code bx_srv('bx_albums', 'entity_add_files', [...]); @endcode
  81. *
  82. * Display form for adding media to the album.
  83. * @param $iContentId album content id where media will be added, if it's not provided then it's determined from 'id' GET variable
  84. * @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.
  85. *
  86. * @see BxAlbumsModule::serviceEntityAddFiles
  87. */
  88. /**
  89. * @ref bx_albums-entity_add_files "entity_add_files"
  90. */
  91. public function serviceEntityAddFiles ($iContentId = 0)
  92. {
  93. return $this->_serviceEntityForm ('editDataForm', $iContentId, 'bx_albums_entry_add_images');
  94. }
  95. /**
  96. * Delete file and album association, also file views, votes, comments, meta data are also deleted
  97. * @param $iFileId file ID
  98. * @return true on success of false on error
  99. */
  100. public function serviceDeleteFileAssociations($iFileId)
  101. {
  102. $CNF = &$this->_oConfig->CNF;
  103. if (!($aMediaInfo = $this->_oDb->getMediaInfoSimpleByFileId($iFileId))) // file is already deleted
  104. return true;
  105. if (!$this->_oDb->deassociateFileWithContent(0, $iFileId))
  106. return false;
  107. $aContentInfo = $this->_oDb->getContentInfoById($aMediaInfo['content_id']);
  108. $iSender = isLogged() ? bx_get_logged_profile_id() : $aMediaInfo['author'];
  109. $iAuthor = isset($aContentInfo[$CNF['FIELD_AUTHOR']]) ? $aContentInfo[$CNF['FIELD_AUTHOR']] : $aMediaInfo['author'];
  110. bx_alert($this->getName(), 'media_deleted', $aMediaInfo['content_id'], $iSender, array(
  111. 'object_author_id' => $iAuthor,
  112. 'subobject_id' => $aMediaInfo['id'],
  113. 'media_id' => $aMediaInfo['id'],
  114. 'media_info' => $aMediaInfo,
  115. ));
  116. bx_alert($this->getName() . '_media', 'deleted', $aMediaInfo['id'], $iSender, array(
  117. 'object_id' => $aMediaInfo['content_id'],
  118. 'object_author_id' => $iAuthor,
  119. 'media_info' => $aMediaInfo,
  120. ));
  121. if (!empty($CNF['OBJECT_VIEWS_MEDIA'])) {
  122. $o = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS_MEDIA'], $aMediaInfo['id']);
  123. if ($o) $o->onObjectDelete();
  124. }
  125. if (!empty($CNF['OBJECT_VOTES_MEDIA'])) {
  126. $o = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_MEDIA'], $aMediaInfo['id']);
  127. if ($o) $o->onObjectDelete();
  128. }
  129. if (!empty($CNF['OBJECT_SCORES_MEDIA'])) {
  130. $o = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES_MEDIA'], $aMediaInfo['id']);
  131. if ($o) $o->onObjectDelete();
  132. }
  133. if (!empty($CNF['OBJECT_COMMENTS_MEDIA'])) {
  134. $o = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS_MEDIA'], $aMediaInfo['id']);
  135. if ($o) $o->onObjectDelete();
  136. }
  137. if (!empty($CNF['OBJECT_METATAGS_MEDIA'])) {
  138. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA']);
  139. $oMetatags->onDeleteContent($aMediaInfo['id']);
  140. }
  141. if (!empty($CNF['OBJECT_METATAGS_MEDIA_CAMERA'])) {
  142. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA_CAMERA']);
  143. $oMetatags->onDeleteContent($aMediaInfo['id']);
  144. }
  145. BxDolPage::deleteSeoLink ($this->getName(), 'bx_albums_media', $aMediaInfo['id']);
  146. return true;
  147. }
  148. /**
  149. * @page service Service Calls
  150. * @section bx_albums Albums
  151. * @subsection bx_albums-page_blocks Page Blocks
  152. * @subsubsection bx_albums-media_comments media_comments
  153. *
  154. * @code bx_srv('bx_albums', 'media_comments', [...]); @endcode
  155. *
  156. * Display media comments block.
  157. * @param $iMediaId media ID, if it's omitted then it's taken from 'id' GET variable.
  158. * @return HTML string with comments. On error false or empty string is returned.
  159. *
  160. * @see BxAlbumsModule::serviceMediaComments
  161. */
  162. /**
  163. * @ref bx_albums-media_comments "media_comments"
  164. */
  165. public function serviceMediaComments ($iMediaId = 0)
  166. {
  167. return $this->_entityComments($this->_oConfig->CNF['OBJECT_COMMENTS_MEDIA'], $iMediaId);
  168. }
  169. /**
  170. * Display media author block.
  171. * @param $iMediaId media ID, if it's omitted then it's taken from 'id' GET variable.
  172. * @return HTML string with block content. On error false or empty string is returned.
  173. */
  174. public function serviceMediaAuthor ($iMediaId = 0)
  175. {
  176. return $this->_serviceTemplateFunc ('mediaAuthor', $iMediaId, 'getMediaInfoById');
  177. }
  178. /**
  179. * Entry actions and social sharing block
  180. */
  181. public function serviceMediaAllActions ($mixedContent = false, $aParams = array())
  182. {
  183. $iMediaId = 0;
  184. $aMediaInfo = array();
  185. $bContent = !empty($mixedContent);
  186. if($bContent && is_array($mixedContent))
  187. list($iMediaId, $aMediaInfo) = $mixedContent;
  188. else {
  189. if($bContent)
  190. $iMediaId = (int)$mixedContent;
  191. else
  192. $iMediaId = bx_process_input(bx_get('id'), BX_DATA_INT);
  193. if(!$iMediaId)
  194. return false;
  195. $aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
  196. }
  197. if(!$iMediaId || !$aMediaInfo)
  198. return false;
  199. $CNF = &$this->_oConfig->CNF;
  200. return parent::serviceEntityAllActions (array($iMediaId, $aMediaInfo), array_merge(array(
  201. 'object_menu' => $CNF['OBJECT_MENU_ACTIONS_VIEW_MEDIA_ALL'],
  202. 'object_transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_BIG'],
  203. 'entry_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_MEDIA'] . '&id=' . $iMediaId),
  204. 'entry_title' => $aMediaInfo['title'],
  205. 'entry_thumb' => $aMediaInfo['file_id']
  206. ), $aParams));
  207. }
  208. /**
  209. * Entry actions block
  210. */
  211. public function serviceMediaActions ($iContentId = 0)
  212. {
  213. $iContentId = $this->_getContent($iContentId, false);
  214. if($iContentId === false)
  215. return false;
  216. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_MEDIA']);
  217. return $oMenu ? $oMenu->getCode() : false;
  218. }
  219. /**
  220. * Display media social sharing buttons block.
  221. * @param $iMediaId media ID, if it's omitted then it's taken from 'id' GET variable.
  222. * @return HTML string with block content. On error false or empty string is returned.
  223. */
  224. public function serviceMediaSocialSharing ($iMediaId = 0)
  225. {
  226. if(!$iMediaId)
  227. $iMediaId = bx_process_input(bx_get('id'), BX_DATA_INT);
  228. if(!$iMediaId)
  229. return false;
  230. $aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
  231. if(!$aMediaInfo)
  232. return false;
  233. $CNF = &$this->_oConfig->CNF;
  234. return $this->serviceEntitySocialSharing(array($iMediaId, $aMediaInfo), array(
  235. 'uri' => $CNF['URI_VIEW_MEDIA'],
  236. 'title' => $aMediaInfo['title'],
  237. 'id_thumb' => $aMediaInfo['file_id'],
  238. 'object_transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_BIG']
  239. ));
  240. }
  241. /**
  242. * Display media preview block.
  243. * @param $iMediaId media ID, if it's omitted then it's taken from 'id' GET variable.
  244. * @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.
  245. * @param $aParams array of additional params.
  246. * @return HTML string with block content. On error false or empty string is returned.
  247. */
  248. public function serviceMediaView ($iMediaId = 0, $mixedContext = false, $aParams = array())
  249. {
  250. if(!$iMediaId)
  251. $iMediaId = bx_process_input(bx_get('id'), BX_DATA_INT);
  252. if(!$iMediaId)
  253. return false;
  254. if(!$mixedContext) {
  255. $mixedContext = bx_process_input(bx_get('context'));
  256. if(!in_array($mixedContext, $this->_aContexts)) // when no context specified, it is assumed that it is an album context
  257. $mixedContext = bx_process_input($mixedContext, BX_DATA_INT); // numeric context is reserved for future use
  258. }
  259. $aParams['context'] = $mixedContext;
  260. $iAutoplay = 0;
  261. if(!isset($aParams['autoplay']) && ($iAutoplay = bx_get('autoplay')) !== false)
  262. $aParams['autoplay'] = (int)$iAutoplay;
  263. return $this->_oTemplate->entryMediaView ($iMediaId, $aParams);
  264. }
  265. public function checkAllowedSetThumb ($iContentId = 0)
  266. {
  267. return CHECK_ACTION_RESULT_NOT_ALLOWED;
  268. }
  269. /**
  270. * @page service Service Calls
  271. * @section bx_albums Albums
  272. * @subsection bx_albums-browse Browse
  273. * @subsubsection bx_albums-browse_recent_media browse_recent_media
  274. *
  275. * @code bx_srv('bx_albums', 'browse_recent_media', [...]); @endcode
  276. *
  277. * Display block for browsing recently uploaded media files.
  278. * @param $sUnitView unit view mode: gallery
  279. * @param $bDisplayEmptyMsg display 'empty' message when nothing to browse, or return empty string.
  280. * @param $bAjaxPaginate use AJAX or regular paginate.
  281. * @return HTML string with block content. On error false or empty string is returned.
  282. *
  283. * @see BxAlbumsModule::serviceBrowseRecentMedia
  284. */
  285. /**
  286. * @ref bx_albums-browse_recent_media "browse_recent_media"
  287. */
  288. public function serviceBrowseRecentMedia ($sUnitView = false, $bDisplayEmptyMsg = true, $bAjaxPaginate = true)
  289. {
  290. return $this->_serviceBrowse ('recent', array('unit_view' => $sUnitView), BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate, 'SearchResultMedia');
  291. }
  292. /**
  293. * @page service Service Calls
  294. * @section bx_albums Albums
  295. * @subsection bx_albums-browse Browse
  296. * @subsubsection bx_albums-browse_featured_media browse_featured_media
  297. *
  298. * @code bx_srv('bx_albums', 'browse_featured_media', [...]); @endcode
  299. *
  300. * Display featured media.
  301. * @param $sUnitView unit view mode: gallery
  302. * @param $bDisplayEmptyMsg display 'empty' message when nothing to browse, or return empty string.
  303. * @param $bAjaxPaginate use AJAX or regular paginate.
  304. * @return HTML string with block content. On error false or empty string is returned.
  305. *
  306. * @see BxAlbumsModule::serviceBrowseFeaturedMedia
  307. */
  308. /**
  309. * @ref bx_albums-browse_featured_media "browse_featured_media"
  310. */
  311. public function serviceBrowseFeaturedMedia ($sUnitView = false, $bDisplayEmptyMsg = false, $bAjaxPaginate = true)
  312. {
  313. return $this->_serviceBrowse ('featured', array('unit_view' => $sUnitView), BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate, 'SearchResultMedia');
  314. }
  315. /**
  316. * @page service Service Calls
  317. * @section bx_albums Albums
  318. * @subsection bx_albums-browse Browse
  319. * @subsubsection bx_albums-browse_popular_media browse_popular_media
  320. *
  321. * @code bx_srv('bx_albums', 'browse_popular_media', [...]); @endcode
  322. *
  323. * Display popular media.
  324. * @param $sUnitView unit view mode: gallery
  325. * @param $bDisplayEmptyMsg display 'empty' message when nothing to browse, or return empty string.
  326. * @param $bAjaxPaginate use AJAX or regular paginate.
  327. * @return HTML string with block content. On error false or empty string is returned.
  328. *
  329. * @see BxAlbumsModule::serviceBrowsePopularMedia
  330. */
  331. /**
  332. * @ref bx_albums-browse_popular_media "browse_popular_media"
  333. */
  334. public function serviceBrowsePopularMedia ($sUnitView = false, $bDisplayEmptyMsg = true, $bAjaxPaginate = true)
  335. {
  336. return $this->_serviceBrowse ('popular', array('unit_view' => $sUnitView), BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate, 'SearchResultMedia');
  337. }
  338. /**
  339. * @page service Service Calls
  340. * @section bx_albums Albums
  341. * @subsection bx_albums-browse Browse
  342. * @subsubsection bx_albums-browse_top_media browse_top_media
  343. *
  344. * @code bx_srv('bx_albums', 'browse_top_media', [...]); @endcode
  345. *
  346. * Display top media.
  347. * @param $sUnitView unit view mode: gallery
  348. * @param $bDisplayEmptyMsg display 'empty' message when nothing to browse, or return empty string.
  349. * @param $bAjaxPaginate use AJAX or regular paginate.
  350. * @return HTML string with block content. On error false or empty string is returned.
  351. *
  352. * @see BxAlbumsModule::serviceBrowseTopMedia
  353. */
  354. /**
  355. * @ref bx_albums-browse_top_media "browse_top_media"
  356. */
  357. public function serviceBrowseTopMedia ($sUnitView = false, $bDisplayEmptyMsg = true, $bAjaxPaginate = true)
  358. {
  359. return $this->_serviceBrowse ('top', array('unit_view' => $sUnitView), BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate, 'SearchResultMedia');
  360. }
  361. /**
  362. * @page service Service Calls
  363. * @section bx_albums Albums
  364. * @subsection bx_albums-browse Browse
  365. * @subsubsection bx_albums-browse_favorite_media browse_favorite_media
  366. *
  367. * @code bx_srv('bx_albums', 'browse_favorite_media', [...]); @endcode
  368. *
  369. * Display favorite media for particular profile.
  370. * @param $iProfileId profile ID, if omitted then 'profile_id' GET variable is used
  371. * @param $aParams additional params for browsing such as 'unit_view'
  372. *
  373. * @see BxAlbumsModule::serviceBrowseFavoriteMedia
  374. */
  375. /**
  376. * @ref bx_albums-browse_favorite_media "browse_favorite_media"
  377. */
  378. public function serviceBrowseFavoriteMedia ($iProfileId = 0, $aParams = array())
  379. {
  380. $oProfile = null;
  381. if((int)$iProfileId)
  382. $oProfile = BxDolProfile::getInstance($iProfileId);
  383. if(!$oProfile && bx_get('profile_id') !== false)
  384. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  385. if(!$oProfile)
  386. $oProfile = BxDolProfile::getInstance();
  387. if(!$oProfile)
  388. return '';
  389. $bEmptyMessage = false;
  390. if(isset($aParams['empty_message'])) {
  391. $bEmptyMessage = (bool)$aParams['empty_message'];
  392. unset($aParams['empty_message']);
  393. }
  394. return $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage, true, 'SearchResultMedia');
  395. }
  396. public function serviceGetTimelineData()
  397. {
  398. $sModule = $this->_aModule['name'];
  399. $aResult = parent::serviceGetTimelineData();
  400. $aResult['handlers'] = array_merge($aResult['handlers'], array(
  401. 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' => ''),
  402. ));
  403. $aResult['alerts'] = array_merge($aResult['alerts'], array(
  404. array('unit' => $sModule, 'action' => 'medias_added')
  405. ));
  406. return $aResult;
  407. }
  408. public function serviceGetTimelineMedia($aEvent, $aBrowseParams = array())
  409. {
  410. if(empty($aEvent['content']))
  411. return false;
  412. $aEvent['content'] = unserialize($aEvent['content']);
  413. if(empty($aEvent['content']['medias_added']) || !is_array($aEvent['content']['medias_added']))
  414. return false;
  415. $iContentId = (int)$aEvent['object_id'];
  416. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  417. if(empty($aContentInfo) || !is_array($aContentInfo))
  418. return false;
  419. $CNF = &$this->_oConfig->CNF;
  420. //--- Views
  421. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId) : null;
  422. $aViews = array();
  423. if ($oViews && $oViews->isEnabled())
  424. $aViews = array(
  425. 'system' => $CNF['OBJECT_VIEWS'],
  426. 'object_id' => $iContentId,
  427. 'count' => $aContentInfo['views']
  428. );
  429. //--- Votes
  430. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId) : null;
  431. $aVotes = array();
  432. if ($oVotes && $oVotes->isEnabled())
  433. $aVotes = array(
  434. 'system' => $CNF['OBJECT_VOTES'],
  435. 'object_id' => $iContentId,
  436. 'count' => $aContentInfo['votes']
  437. );
  438. //--- Scores
  439. $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContentId) : null;
  440. $aScores = array();
  441. if ($oScores && $oScores->isEnabled())
  442. $aScores = array(
  443. 'system' => $CNF['OBJECT_SCORES'],
  444. 'object_id' => $iContentId,
  445. 'score' => $aContentInfo['score']
  446. );
  447. //--- Reports
  448. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aEvent['object_id']) : null;
  449. $aReports = array();
  450. if ($oReports && $oReports->isEnabled())
  451. $aReports = array(
  452. 'system' => $CNF['OBJECT_REPORTS'],
  453. 'object_id' => $iContentId,
  454. 'count' => $aContentInfo['reports']
  455. );
  456. //--- Comments
  457. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId) : null;
  458. $aComments = array();
  459. if($oCmts && $oCmts->isEnabled())
  460. $aComments = array(
  461. 'system' => $CNF['OBJECT_COMMENTS'],
  462. 'object_id' => $iContentId,
  463. 'count' => $aContentInfo['comments']
  464. );
  465. //--- Title & Description
  466. $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, '...') : '');
  467. return array(
  468. '_cache' => true,
  469. 'owner_id' => $aEvent['owner_id'],
  470. 'object_owner_id' => $aContentInfo['author'],
  471. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  472. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  473. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  474. 'sample_action' => $CNF['T']['txt_sample_action_changed'],
  475. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId),
  476. 'content' => $this->_getContentForTimelineMedia($aEvent, $aContentInfo, $aBrowseParams), //a string to display or array to parse default template before displaying.
  477. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  478. 'views' => $aViews,
  479. 'votes' => $aVotes,
  480. 'scores' => $aScores,
  481. 'reports' => $aReports,
  482. 'comments' => $aComments,
  483. 'title' => $sTitle, //may be empty.
  484. 'description' => '' //may be empty.
  485. );
  486. }
  487. public function serviceGetNotificationsData()
  488. {
  489. $sModule = $this->_aModule['name'];
  490. $sEventPrivacy = $sModule . '_allow_view_event_to';
  491. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  492. $sEventPrivacy = '';
  493. $aResult = parent::serviceGetNotificationsData();
  494. $aResult['handlers'] = array_merge($aResult['handlers'], array(
  495. 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),
  496. array('group' => $sModule . '_object_media', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'media_deleted'),
  497. 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),
  498. array('group' => $sModule . '_comment_media', 'type' => 'delete', 'alert_unit' => $sModule . '_media', 'alert_action' => 'commentRemoved'),
  499. 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),
  500. array('group' => $sModule . '_vote_media', 'type' => 'delete', 'alert_unit' => $sModule . '_media', 'alert_action' => 'undoVote'),
  501. 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),
  502. 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),
  503. ));
  504. $aResult['settings'] = array_merge($aResult['settings'], array(
  505. array('group' => 'content', 'unit' => $sModule, 'action' => 'medias_added', 'types' => array('follow_member', 'follow_context')),
  506. array('group' => 'comment', 'unit' => $sModule . '_media', 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  507. array('group' => 'vote', 'unit' => $sModule . '_media', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  508. array('group' => 'score_up', 'unit' => $sModule . '_media', 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  509. array('group' => 'score_down', 'unit' => $sModule . '_media', 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  510. ));
  511. $aResult['alerts'] = array_merge($aResult['alerts'], array(
  512. array('unit' => $sModule, 'action' => 'medias_added'),
  513. array('unit' => $sModule, 'action' => 'media_deleted'),
  514. array('unit' => $sModule . '_media', 'action' => 'commentPost'),
  515. array('unit' => $sModule . '_media', 'action' => 'commentRemoved'),
  516. array('unit' => $sModule . '_media', 'action' => 'doVote'),
  517. array('unit' => $sModule . '_media', 'action' => 'undoVote'),
  518. array('unit' => $sModule . '_media', 'action' => 'doVoteUp'),
  519. array('unit' => $sModule . '_media', 'action' => 'doVoteDown'),
  520. ));
  521. return $aResult;
  522. }
  523. public function serviceGetNotificationsMedia($aEvent)
  524. {
  525. $CNF = &$this->_oConfig->CNF;
  526. $iContentId = (int)$aEvent['object_id'];
  527. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  528. if(empty($aContentInfo) || !is_array($aContentInfo))
  529. return array();
  530. $iMediaId = (int)$aEvent['subobject_id'];
  531. $aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
  532. if(empty($aMediaInfo) || !is_array($aMediaInfo))
  533. return array();
  534. $oPermalinks = BxDolPermalinks::getInstance();
  535. $sEntryUrl = '{bx_url_root}' . $oPermalinks->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  536. $sSubentryUrl = '{bx_url_root}' . $oPermalinks->permalink('page.php?i=' . $CNF['URI_VIEW_MEDIA'] . '&id=' . $iMediaId);
  537. $sEntryCaption = isset($aMediaInfo['title']) ? $aMediaInfo['title'] : _t('_bx_albums_media');
  538. return array(
  539. 'entry_sample' => $CNF['T']['txt_sample_single'],
  540. 'entry_url' => $sEntryUrl,
  541. 'entry_caption' => $sEntryCaption,
  542. 'entry_author' => $aMediaInfo['author'],
  543. 'subentry_sample' => $CNF['T']['txt_media_single'],
  544. 'subentry_url' => $sSubentryUrl,
  545. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  546. );
  547. }
  548. public function serviceGetNotificationsCommentMedia($aEvent)
  549. {
  550. $CNF = &$this->_oConfig->CNF;
  551. $iMediaId = (int)$aEvent['object_id'];
  552. $aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
  553. if(empty($aMediaInfo) || !is_array($aMediaInfo))
  554. return array();
  555. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS_MEDIA'], $iMediaId);
  556. if(!$oComment || !$oComment->isEnabled())
  557. return array();
  558. $sEntryUrl = '{bx_url_root}' . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_MEDIA'] . '&id=' . $aMediaInfo['id']);
  559. $sEntryCaption = isset($aMediaInfo['title']) ? $aMediaInfo['title'] : _t('_bx_albums_media');
  560. return array(
  561. 'entry_sample' => $CNF['T']['txt_media_single'],
  562. 'entry_url' => $sEntryUrl,
  563. 'entry_caption' => $sEntryCaption,
  564. 'entry_author' => $aMediaInfo['author'],
  565. 'subentry_sample' => $CNF['T']['txt_media_comment_single'],
  566. 'subentry_url' => '{bx_url_root}' . $oComment->getViewUrl((int)$aEvent['subobject_id'], false),
  567. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  568. );
  569. }
  570. public function serviceGetNotificationsVoteMedia($aEvent)
  571. {
  572. $CNF = &$this->_oConfig->CNF;
  573. $iMediaId = (int)$aEvent['object_id'];
  574. $aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
  575. if(empty($aMediaInfo) || !is_array($aMediaInfo))
  576. return array();
  577. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_MEDIA'], $iMediaId);
  578. if(!$oVote || !$oVote->isEnabled())
  579. return array();
  580. $sEntryUrl = '{bx_url_root}' . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_MEDIA'] . '&id=' . $aMediaInfo['id']);
  581. $sEntryCaption = isset($aMediaInfo['title']) ? $aMediaInfo['title'] : _t('_bx_albums_media');
  582. return array(
  583. 'entry_sample' => $CNF['T']['txt_media_single'],
  584. 'entry_url' => $sEntryUrl,
  585. 'entry_caption' => $sEntryCaption,
  586. 'entry_author' => $aMediaInfo['author'],
  587. 'subentry_sample' => $CNF['T']['txt_media_vote_single'],
  588. 'subentry_url' => '',
  589. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  590. );
  591. }
  592. public function serviceGetNotificationsScoreUpMedia($aEvent)
  593. {
  594. return $this->_serviceGetNotificationsScoreMedia('up', $aEvent);
  595. }
  596. public function serviceGetNotificationsScoreDownMedia($aEvent)
  597. {
  598. return $this->_serviceGetNotificationsScoreMedia('down', $aEvent);
  599. }
  600. protected function _serviceGetNotificationsScoreMedia($sType, $aEvent)
  601. {
  602. $CNF = &$this->_oConfig->CNF;
  603. $iMediaId = (int)$aEvent['object_id'];
  604. $aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
  605. if(empty($aMediaInfo) || !is_array($aMediaInfo))
  606. return array();
  607. $oVote = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES_MEDIA'], $iMediaId);
  608. if(!$oVote || !$oVote->isEnabled())
  609. return array();
  610. $sEntryUrl = '{bx_url_root}' . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_MEDIA'] . '&id=' . $aMediaInfo['id']);
  611. $sEntryCaption = isset($aMediaInfo['title']) ? $aMediaInfo['title'] : _t('_bx_albums_media');
  612. return array(
  613. 'entry_sample' => $CNF['T']['txt_media_single'],
  614. 'entry_url' => $sEntryUrl,
  615. 'entry_caption' => $sEntryCaption,
  616. 'entry_author' => $aMediaInfo['author'],
  617. 'subentry_sample' => $CNF['T']['txt_media_score_' . $sType . '_single'],
  618. 'subentry_url' => '',
  619. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  620. );
  621. }
  622. public function actionEditMedia($iMediaId)
  623. {
  624. $CNF = &$this->_oConfig->CNF;
  625. $iMediaId = (int)$iMediaId;
  626. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_MEDIA'], $CNF['OBJECT_FORM_MEDIA_DISPLAY_EDIT']);
  627. $oForm->initForm('edit', $iMediaId);
  628. $oForm->initChecker();
  629. if($oForm->isSubmittedAndValid()) {
  630. if($oForm->update($iMediaId) !== false) {
  631. $aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
  632. if(!empty($aMediaInfo) && is_array($aMediaInfo) && !empty($CNF['OBJECT_METATAGS_MEDIA'])) {
  633. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA']);
  634. if ($oMetatags->keywordsIsEnabled())
  635. $oMetatags->keywordsAdd($aMediaInfo['id'], $aMediaInfo['title']);
  636. }
  637. $aRes = array('reload' => 1);
  638. }
  639. else
  640. $aRes = array('msg' => _t('_bx_albums_txt_err_cannot_perform_action'));
  641. return echoJson($aRes);
  642. }
  643. $sContent = BxTemplStudioFunctions::getInstance()->transBox('bx-albums-edit-media-popup', $this->_oTemplate->parseHtmlByName('media-edit.html', array(
  644. 'form_id' => $oForm->aFormAttrs['id'],
  645. 'form' => $oForm->getCode(true)
  646. )));
  647. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  648. }
  649. public function actionDeleteMedia($iMediaId)
  650. {
  651. $CNF = &$this->_oConfig->CNF;
  652. $aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
  653. $oUploader = BxDolUploader::getObjectInstance($CNF['OBJECT_UPLOADERS'][0], $CNF['OBJECT_STORAGE'], '');
  654. $oUploader->deleteGhost($aMediaInfo['file_id'], bx_get_logged_profile_id());
  655. echoJson(['redirect' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aMediaInfo['content_id'])]);
  656. }
  657. public function actionMoveMedia($iMediaId)
  658. {
  659. $CNF = &$this->_oConfig->CNF;
  660. $iMediaId = (int)$iMediaId;
  661. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_MEDIA'], $CNF['OBJECT_FORM_MEDIA_DISPLAY_MOVE']);
  662. $oForm->initForm('move', $iMediaId);
  663. $oForm->initChecker();
  664. if($oForm->isSubmittedAndValid()) {
  665. if($oForm->update($iMediaId) !== false)
  666. $aRes = array('reload' => 1);
  667. else
  668. $aRes = array('msg' => _t('_bx_albums_txt_err_cannot_perform_action'));
  669. return echoJson($aRes);
  670. }
  671. $sContent = BxTemplStudioFunctions::getInstance()->transBox('bx-albums-move-media-popup', $this->_oTemplate->parseHtmlByName('media-edit.html', array(
  672. 'form_id' => $oForm->aFormAttrs['id'],
  673. 'form' => $oForm->getCode(true)
  674. )));
  675. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  676. }
  677. public function actionGetSiblingMedia($iMediaId, $mixedContext)
  678. {
  679. $aSiblings = false;
  680. $sErrorMsg = false;
  681. if (!($aMediaInfo = $this->_oDb->getMediaInfoById((int)$iMediaId)))
  682. $sErrorMsg = _t('_sys_txt_error_occured');
  683. if (empty($sErrorMsg) && !($aContentInfo = $this->_oDb->getContentInfoById($aMediaInfo['content_id'])))
  684. $sErrorMsg = _t('_sys_txt_error_occured');
  685. if (empty($sErrorMsg) && (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aContentInfo))))
  686. $sErrorMsg = $sMsg;
  687. if (empty($sErrorMsg)) {
  688. $aSiblings = array (
  689. 'next' => $this->_oTemplate->getNextPrevMedia($aMediaInfo, true, $mixedContext),
  690. 'prev' => $this->_oTemplate->getNextPrevMedia($aMediaInfo, false, $mixedContext),
  691. );
  692. }
  693. $a = $sErrorMsg ? array('error' => $sErrorMsg) : array('next' => $aSiblings['next'], 'prev' => $aSiblings['prev']);
  694. $s = json_encode($a);
  695. header('Content-type: text/html; charset=utf-8');
  696. echo $s;
  697. }
  698. public function actionRssMedia ()
  699. {
  700. $aArgs = func_get_args();
  701. $this->_rss($aArgs, 'SearchResultMedia');
  702. }
  703. public function getMediaDuration($aMediaInfo)
  704. {
  705. $CNF = &$this->_oConfig->CNF;
  706. if(empty($aMediaInfo) || !is_array($aMediaInfo))
  707. return 0;
  708. $sField = 'duration';
  709. if(!empty($aMediaInfo[$sField]))
  710. return (int)$aMediaInfo[$sField];
  711. $iMedia = $aMediaInfo['id'];
  712. $sMedia = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4'])->getFileUrl($iMedia);
  713. if(empty($sMedia))
  714. return 0;
  715. $iDuration = (int)BxDolTranscoderVideo::getDuration($sMedia);
  716. if(!empty($iDuration))
  717. $this->_oDb->updateMedia(array($sField => $iDuration), array('id' => $iMedia));
  718. return $iDuration;
  719. }
  720. protected function _buildRssParams($sMode, $aArgs)
  721. {
  722. if ($aParams = parent::_buildRssParams($sMode, $aArgs))
  723. return $aParams;
  724. $sMode = bx_process_input($sMode);
  725. switch ($sMode) {
  726. case 'album':
  727. $aParams = array('album_id' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  728. break;
  729. }
  730. return $aParams;
  731. }
  732. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  733. {
  734. $CNF = &$this->_oConfig->CNF;
  735. if(empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']) || empty($CNF['OBJECT_TRANSCODER_COVER']))
  736. return array();
  737. $aMediaList = $this->_oDb->getMediaListByContentId($aContentInfo[$CNF['FIELD_ID']]);
  738. if(empty($aMediaList) || !is_array($aMediaList))
  739. return array();
  740. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  741. $oTcPoster = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']);
  742. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  743. $oTranscoderCover = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_TRANSCODER_COVER']);
  744. if(!$oTranscoder || !$oTranscoderCover)
  745. return array();
  746. $aOutput = array();
  747. foreach ($aMediaList as $aMedia) {
  748. $aFileInfo = $oStorage->getFile($aMedia['file_id']);
  749. $bVideo = $oTcPoster && strncmp('video/', $aFileInfo['mime_type'], 6) === 0 && $oTcPoster->isMimeTypeSupported($aFileInfo['mime_type']);
  750. if($bVideo)
  751. continue;
  752. $aOutput[$aMedia['id']] = array (
  753. 'id' => $aMedia['id'],
  754. 'url' => $this->_oTemplate->getViewMediaUrl($CNF, $aMedia['id']),
  755. 'src' => $oTranscoder->getFileUrl($aMedia['file_id']),
  756. 'src_orig' => $oTranscoderCover->getFileUrl($aMedia['file_id'])
  757. );
  758. }
  759. if(empty($aOutput))
  760. return array();
  761. $iSlice = 4;
  762. $iTotal = count($aOutput);
  763. return array(
  764. 'total' => $iTotal,
  765. 'items' => $iTotal > $iSlice ? array_slice($aOutput, 0, $iSlice) : $aOutput
  766. );
  767. }
  768. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  769. {
  770. $CNF = &$this->_oConfig->CNF;
  771. if(empty($CNF['OBJECT_VIDEOS_TRANSCODERS']))
  772. return array();
  773. $aMediaList = $this->_oDb->getMediaListByContentId($aContentInfo[$CNF['FIELD_ID']]);
  774. if(empty($aMediaList) || !is_array($aMediaList))
  775. return array();
  776. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  777. $oTcPoster = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']);
  778. $oTcMp4 = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  779. $oTcMp4Hd = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4_hd']);
  780. if(!$oTcPoster || !$oTcMp4 || !$oTcMp4Hd)
  781. return array();
  782. $aOutput = array();
  783. foreach($aMediaList as $k => $aMedia) {
  784. $aFileInfo = $oStorage->getFile($aMedia['file_id']);
  785. $bVideo = $oTcPoster && strncmp('video/', $aFileInfo['mime_type'], 6) === 0 && $oTcPoster->isMimeTypeSupported($aFileInfo['mime_type']);
  786. if(!$bVideo)
  787. continue;
  788. $sVideoUrl = $oStorage->getFileUrlById($aMedia['file_id']);
  789. $aVideoFile = $oStorage->getFile($aMedia['file_id']);
  790. $sVideoUrlHd = '';
  791. if (!empty($aVideoFile['dimensions']) && $oTcMp4Hd->isProcessHD($aVideoFile['dimensions']))
  792. $sVideoUrlHd = $oTcMp4Hd->getFileUrl($aMedia['file_id']);
  793. $aOutput[$aMedia['id']] = array(
  794. 'id' => $aMedia['id'],
  795. 'src_poster' => $oTcPoster->getFileUrl($aMedia['file_id']),
  796. 'src_mp4' => $oTcMp4->getFileUrl($aMedia['file_id']),
  797. 'src_mp4_hd' => $sVideoUrlHd,
  798. 'duration' => $aFileInfo['duration'],
  799. );
  800. }
  801. if(empty($aOutput))
  802. return array();
  803. $iSlice = 4;
  804. $iTotal = count($aOutput);
  805. return array(
  806. 'total' => $iTotal,
  807. 'items' => $iTotal > $iSlice ? array_slice($aOutput, 0, $iSlice) : $aOutput
  808. );
  809. }
  810. protected function _getContentForTimelineMedia($aEvent, $aContentInfo, $aBrowseParams = array())
  811. {
  812. $CNF = &$this->_oConfig->CNF;
  813. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  814. $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, '...') : '');
  815. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  816. $oTcPoster = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']);
  817. $oTcMp4 = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  818. $oTcMp4Hd = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4_hd']);
  819. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  820. $oTranscoderCover = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_TRANSCODER_COVER']);
  821. //--- Image(s) and Video(s)
  822. $aImages = $aVideos = array();
  823. foreach($aEvent['content']['medias_added'] as $iMediaId) {
  824. $aMediaInfo = $this->_oDb->getMediaInfoById($iMediaId);
  825. if(empty($aMediaInfo) || !is_array($aMediaInfo))
  826. continue;
  827. $aFileInfo = $oStorage->getFile($aMediaInfo['file_id']);
  828. $bVideo = $oTcPoster && strncmp('video/', $aFileInfo['mime_type'], 6) === 0 && $oTcPoster->isMimeTypeSupported($aFileInfo['mime_type']);
  829. if($bVideo)
  830. $aVideos[$iMediaId] = array(
  831. 'id' => $aMediaInfo['id'],
  832. 'src_poster' => $oTcPoster->getFileUrl($aMediaInfo['file_id']),
  833. 'src_mp4' => $oTcMp4->getFileUrl($aMediaInfo['file_id']),
  834. 'src_mp4_hd' => $oTcMp4Hd->getFileUrl($aMediaInfo['file_id']),
  835. 'duration' => $aFileInfo['duration'],
  836. );
  837. else
  838. $aImages[$iMediaId] = array(
  839. 'id' => $aMediaInfo['id'],
  840. 'url' => $this->_oTemplate->getViewMediaUrl($CNF, $aMediaInfo['id']),
  841. 'src' => $oTranscoder->getFileUrl($aMediaInfo['file_id']),
  842. 'src_orig' => $oTranscoderCover->getFileUrl($aMediaInfo['file_id'])
  843. );
  844. }
  845. return array(
  846. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  847. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  848. 'sample_action' => isset($CNF['T']['txt_sample_action_changed']),
  849. 'url' => $sUrl,
  850. 'title' => $sTitle,
  851. 'text' => '',
  852. 'images_attach' => $aImages,
  853. 'videos_attach' => $aVideos
  854. );
  855. }
  856. protected function _getImagesForTimelineMedia($aEvent, $aMediaInfo, $sUrl, $aBrowseParams = array())
  857. {
  858. $CNF = &$this->_oConfig->CNF;
  859. $aImages = array();
  860. return $aImages;
  861. }
  862. }
  863. /** @} */