BxAlbumsModule.php 48 KB

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