BxAlbumsModule.php 52 KB

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