BxBaseModTextModule.php 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  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 BaseText Base classes for text modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_BASE_MOD_TEXT_STATUS_ACTIVE', 'active');
  12. define('BX_BASE_MOD_TEXT_STATUS_HIDDEN', 'hidden');
  13. define('BX_BASE_MOD_TEXT_STATUS_AWAITING', 'awaiting');
  14. /**
  15. * Saved for backward compatibility.
  16. * Can be removed in future releases of UNA 13.
  17. */
  18. define('BX_BASE_MOD_TEXT_STATUS_PENDING', 'pending');
  19. /**
  20. * Base module class for text based modules
  21. */
  22. class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolContentInfoService
  23. {
  24. function __construct(&$aModule)
  25. {
  26. parent::__construct($aModule);
  27. }
  28. // ====== ACTIONS METHODS
  29. public function actionEmbedPoll($iPollId = 0)
  30. {
  31. if(empty($iPollId) && bx_get('poll_id') !== false)
  32. $iPollId = (int)bx_get('poll_id');
  33. $aParams = bx_get_with_prefix('param');
  34. array_walk($aParams, function(&$sValue) {
  35. $sValue = bx_process_input($sValue);
  36. });
  37. $this->_oTemplate->embedPollItem($iPollId, $aParams);
  38. }
  39. public function actionEmbedPolls($iId = 0)
  40. {
  41. list($iContentId, $aContentInfo) = $this->_getContent($iId);
  42. if($iContentId === false)
  43. return;
  44. $aParams = bx_get_with_prefix('param');
  45. array_walk($aParams, function(&$sValue) {
  46. $sValue = bx_process_input($sValue);
  47. });
  48. $this->_oTemplate->embedPollItems($aContentInfo, $aParams);
  49. }
  50. public function actionGetPoll()
  51. {
  52. $iPollId = (int)bx_get('poll_id');
  53. $sView = bx_process_input(bx_get('view'));
  54. $sMethod = 'serviceGetBlockPoll' . bx_gen_method_name($sView);
  55. if(!method_exists($this, $sMethod))
  56. return echoJson(array());
  57. $aBlock = $this->$sMethod($iPollId, true);
  58. if(empty($aBlock) || !is_array($aBlock))
  59. return echoJson(array());
  60. return echoJson(array(
  61. 'content' => $aBlock['content']
  62. ));
  63. }
  64. public function actionDeletePoll()
  65. {
  66. $CNF = &$this->_oConfig->CNF;
  67. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  68. if(empty($iId))
  69. return echoJson(array());
  70. $aResult = array();
  71. if($this->_oDb->deletePolls(array($CNF['FIELD_POLL_ID'] => $iId)))
  72. $aResult = array('code' => 0);
  73. else
  74. $aResult = array('code' => 1, 'message' => _t($CNF['txt_err_cannot_perform_action']));
  75. echoJson($aResult);
  76. }
  77. public function actionGetPollForm()
  78. {
  79. echo $this->_oTemplate->getPollForm();
  80. }
  81. public function actionSubmitPollForm()
  82. {
  83. echoJson($this->getPollForm());
  84. }
  85. public function actionGetAttachLinkForm()
  86. {
  87. $iContentId = 0;
  88. if(bx_get('content_id') !== false)
  89. $iContentId = (int)bx_get('content_id');
  90. echo $this->_oTemplate->getAttachLinkForm($iContentId);
  91. }
  92. public function actionSubmitAttachLinkForm()
  93. {
  94. echoJson($this->getFormAttachLink());
  95. }
  96. public function actionAddAttachLink()
  97. {
  98. $sUrl = bx_process_input(bx_get('url'));
  99. if(empty($sUrl))
  100. return echoJson(array());
  101. $sUrl = htmlspecialchars_decode($sUrl);
  102. $oStreamContext = stream_context_create([
  103. 'http' => [
  104. 'timeout' => getParam('sys_default_socket_timeout'),
  105. ]
  106. ]);
  107. $sHeader = 'Content-Type';
  108. $aHeaders = @get_headers($sUrl, 1, $oStreamContext);
  109. if(!empty($aHeaders) && is_array($aHeaders) && !empty($aHeaders[$sHeader])) {
  110. $mixedContentType = $aHeaders[$sHeader];
  111. if(!is_array($mixedContentType))
  112. $mixedContentType = array($mixedContentType);
  113. foreach($mixedContentType as $sContentType)
  114. if(strpos($sContentType, 'image') !== false)
  115. return echoJson(array());
  116. }
  117. $iContentId = 0;
  118. if(bx_get('content_id') !== false)
  119. $iContentId = (int)bx_get('content_id');
  120. echoJson($this->addAttachLink(array(
  121. 'content_id' => $iContentId,
  122. 'url' => $sUrl
  123. )));
  124. }
  125. public function actionDeleteAttachLink()
  126. {
  127. $CNF = &$this->_oConfig->CNF;
  128. $iUserId = $this->getUserId();
  129. $iLinkId = bx_process_input(bx_get('id'), BX_DATA_INT);
  130. if(empty($iLinkId))
  131. return echoJson(array());
  132. $aLink = $this->_oDb->getLinksBy(array('type' => 'id', 'id' => $iLinkId, 'profile_id' => $iUserId));
  133. if(empty($aLink) || !is_array($aLink))
  134. return echoJson(array());
  135. if(!empty($aLink['media_id']))
  136. BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS'])->deleteFile($aLink['media_id']);
  137. $aResult = array();
  138. if($this->_oDb->deleteLink($iLinkId))
  139. $aResult = array('code' => 0);
  140. else
  141. $aResult = array('code' => 1, 'message' => _t('_bx_posts_form_post_input_link_err_delete'));
  142. echoJson($aResult);
  143. }
  144. public function actionFileEmbedVideo($iFileId)
  145. {
  146. $this->_oTemplate->embedVideo($iFileId);
  147. }
  148. public function actionFileEmbedSound($iFileId)
  149. {
  150. $this->_oTemplate->embedSound($iFileId);
  151. }
  152. // ====== SERVICE METHODS
  153. public function serviceGetSafeServices()
  154. {
  155. $a = parent::serviceGetSafeServices();
  156. return array_merge($a, array (
  157. 'GetBlockPollAnswers' => '',
  158. 'GetBlockPollResults' => '',
  159. 'GetMenuAddonManageToolsProfileStats' => '',
  160. 'BrowsePublic' => '',
  161. 'BrowsePopular' => '',
  162. 'BrowseTop' => '',
  163. 'BrowseUpdated' => '',
  164. 'BrowseAuthor' => '',
  165. 'CategoriesMultiListContext' => ''
  166. ));
  167. }
  168. public function serviceManageTools($sType = 'common')
  169. {
  170. $sResult = parent::serviceManageTools($sType);
  171. if(!empty($sResult))
  172. $this->_oTemplate->addJsSystem(['modules/base/text/js/|manage_tools.js']);
  173. return $sResult;
  174. }
  175. /**
  176. * @page service Service Calls
  177. * @section bx_base_text Base Text
  178. * @subsection bx_base_general-page_blocks Page Blocks
  179. * @subsubsection bx_base_general-categories_multi_list_context categories_multi_list_context
  180. *
  181. * @code bx_srv('bx_posts', 'categories_multi_list_context', [...]); @endcode
  182. *
  183. * Display multi-categorories block with number of posts in each category for current context
  184. * @param $bDisplayEmptyCats display empty categories
  185. *
  186. * @see BxBaseModGeneralModule::serviceCategoriesMultiListContext
  187. */
  188. /**
  189. * @ref bx_base_general-categories_multi_list_context "categories_multi_list_context"
  190. */
  191. public function serviceCategoriesMultiListContext($iProfileId = 0, $bDisplayEmptyCats = true)
  192. {
  193. if ($iProfileId == 0)
  194. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  195. $oCategories = BxDolCategories::getInstance();
  196. $aCats = $oCategories->getData([
  197. 'type' => 'by_module&context_with_num',
  198. 'module' => $this->getName(),
  199. 'context_id' => $iProfileId
  200. ]
  201. );
  202. $aVars = array('bx_repeat:cats' => array());
  203. foreach ($aCats as $oCat) {
  204. $sValue = $oCat['value'];
  205. $iNum = $oCat['num'];
  206. $aVars['bx_repeat:cats'][] = array(
  207. 'url' => $oCategories->getUrl($this->getName(), $sValue, '&context_id=' . $iProfileId),
  208. 'name' => _t($sValue),
  209. 'value' => $sValue,
  210. 'num' => $iNum,
  211. );
  212. }
  213. if (!$aVars['bx_repeat:cats'])
  214. return '';
  215. return $this->_oTemplate->parseHtmlByName('category_list_multi.html', $aVars);
  216. }
  217. /**
  218. * @page service Service Calls
  219. * @section bx_base_text Base Text
  220. * @subsection bx_base_text-polls Polls Blocks
  221. * @subsubsection bx_base_text-get_block_poll_answers get_block_poll_answers
  222. *
  223. * @code bx_srv('bx_posts', 'get_block_poll_answers', [...]); @endcode
  224. *
  225. * Get block with poll answers
  226. * @param $iPollId poll ID
  227. *
  228. * @see BxBaseModTextModule::serviceGetBlockPollAnswers
  229. */
  230. /**
  231. * @ref bx_base_text-get_block_poll_answers "get_block_poll_answers"
  232. */
  233. public function serviceGetBlockPollAnswers($iPollId, $bForceDisplay = false)
  234. {
  235. if(!$iPollId)
  236. return false;
  237. if(!$bForceDisplay && $this->isPollPerformed($iPollId))
  238. return $this->serviceGetBlockPollResults($iPollId);
  239. return $this->_serviceTemplateFunc('entryPollAnswers', $iPollId, 'getPollInfoById');
  240. }
  241. /**
  242. * @page service Service Calls
  243. * @section bx_base_text Base Text
  244. * @subsection bx_base_text-polls Polls Blocks
  245. * @subsubsection bx_base_text-get_block_poll_results get_block_poll_results
  246. *
  247. * @code bx_srv('bx_posts', 'get_block_poll_results', [...]); @endcode
  248. *
  249. * Get block with poll results
  250. * @param $iPollId poll ID
  251. *
  252. * @see BxBaseModTextModule::serviceGetBlockPollResults
  253. */
  254. /**
  255. * @ref bx_base_text-get_block_poll_results "get_block_poll_results"
  256. */
  257. public function serviceGetBlockPollResults($iPollId)
  258. {
  259. return $this->_serviceTemplateFunc('entryPollResults', $iPollId, 'getPollInfoById');
  260. }
  261. /**
  262. * Display media EXIF information.
  263. * @param $iMediaId media ID, if it's omitted then it's taken from 'id' GET variable.
  264. * @return HTML string with EXIF info. On error empty string is returned.
  265. */
  266. public function serviceMediaExif ($iMediaId = 0)
  267. {
  268. $CNF = &$this->_oConfig->CNF;
  269. return $this->_serviceTemplateFunc ('mediaExif', $iMediaId, $CNF['FUNCTION_FOR_GET_ITEM_INFO']);
  270. }
  271. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  272. {
  273. $CNF = &$this->_oConfig->CNF;
  274. if(bx_is_api()){
  275. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  276. if (isset($CNF['FIELD_THUMB']))
  277. return bx_api_get_image($CNF['OBJECT_STORAGE'], $aContentInfo[$CNF['FIELD_THUMB']]);
  278. }
  279. if(empty($sTranscoder) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']))
  280. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_GALLERY'];
  281. $mixedResult = $this->_getFieldValueThumb('FIELD_THUMB', $iContentId, $sTranscoder);
  282. return $mixedResult !== false ? $mixedResult : '';
  283. }
  284. public function serviceGetMenuAddonManageTools()
  285. {
  286. $CNF = &$this->_oConfig->CNF;
  287. $iNumTotal = $this->_oDb->getEntriesNumByParams();
  288. $iNum1 = $this->_oDb->getEntriesNumByParams([
  289. [
  290. 'key' => $CNF['FIELD_STATUS'],
  291. 'value' => 'hidden',
  292. 'operator' => '='
  293. ]
  294. ]);
  295. $iNum2 = 0;
  296. if (isset($CNF['OBJECT_REPORTS'])){
  297. $iNum2 = $this->_oDb->getEntriesNumByParams([
  298. [
  299. 'key' => 'reports',
  300. 'value' => '0',
  301. 'operator' => '>'
  302. ]
  303. ]);
  304. }
  305. return array('counter1_value' => $iNum1, 'counter2_value' => $iNum2, 'counter3_value' => $iNumTotal );
  306. }
  307. /**
  308. * @page service Service Calls
  309. * @section bx_base_text Base Text
  310. * @subsection bx_base_text-other Other
  311. * @subsubsection bx_base_text-get_menu_addon_manage_tools_profile_stats get_menu_addon_manage_tools_profile_stats
  312. *
  313. * @code bx_srv('bx_posts', 'get_menu_addon_manage_tools_profile_stats', []); @endcode
  314. *
  315. * Get number of posts for currently logged in user
  316. *
  317. * @see BxBaseModTextModule::serviceGetMenuAddonManageToolsProfileStats
  318. */
  319. /**
  320. * @ref bx_base_text-get_menu_addon_manage_tools_profile_stats "get_menu_addon_manage_tools_profile_stats"
  321. */
  322. public function serviceGetMenuAddonManageToolsProfileStats($iProfileId = 0)
  323. {
  324. if(!$iProfileId)
  325. $iProfileId = bx_get_logged_profile_id();
  326. bx_import('SearchResult', $this->_aModule);
  327. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  328. $o = new $sClass();
  329. $o->fillFilters([
  330. 'author' => $iProfileId
  331. ]);
  332. $o->unsetPaginate();
  333. return $o->getNum();
  334. }
  335. /**
  336. * @page service Service Calls
  337. * @section bx_base_text Base Text
  338. * @subsection bx_base_text-browse Browse
  339. * @subsubsection bx_base_text-browse_public browse_public
  340. *
  341. * @code bx_srv('bx_posts', 'browse_public', [...]); @endcode
  342. *
  343. * Display public posts
  344. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  345. * @param $bEmptyMessage display or not "empty" message when there is no content
  346. * @param $bAjaxPaginate use AJAX paginate or not
  347. *
  348. * @see BxBaseModTextModule::serviceBrowsePublic
  349. */
  350. /**
  351. * @ref bx_base_text-browse_public "browse_public"
  352. */
  353. public function serviceBrowsePublic ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  354. {
  355. return $this->_serviceBrowse ('public', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  356. }
  357. /**
  358. * @page service Service Calls
  359. * @section bx_base_text Base Text
  360. * @subsection bx_base_text-browse Browse
  361. * @subsubsection bx_base_text-browse_popular browse_popular
  362. *
  363. * @code bx_srv('bx_posts', 'browse_popular', [...]); @endcode
  364. *
  365. * Display popular posts
  366. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  367. * @param $bEmptyMessage display or not "empty" message when there is no content
  368. * @param $bAjaxPaginate use AJAX paginate or not
  369. *
  370. * @see BxBaseModTextModule::serviceBrowsePopular
  371. */
  372. /**
  373. * @ref bx_base_text-browse_popular "browse_popular"
  374. */
  375. public function serviceBrowsePopular ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  376. {
  377. return $this->_serviceBrowse ('popular', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  378. }
  379. /**
  380. * @page service Service Calls
  381. * @section bx_base_text Base Text
  382. * @subsection bx_base_text-browse Browse
  383. * @subsubsection bx_base_text-browse_top browse_top
  384. *
  385. * @code bx_srv('bx_posts', 'browse_top', [...]); @endcode
  386. *
  387. * Display top posts
  388. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  389. * @param $bEmptyMessage display or not "empty" message when there is no content
  390. * @param $bAjaxPaginate use AJAX paginate or not
  391. *
  392. * @see BxBaseModTextModule::serviceBrowseTop
  393. */
  394. /**
  395. * @ref bx_base_text-browse_top "browse_top"
  396. */
  397. public function serviceBrowseTop ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  398. {
  399. return $this->_serviceBrowse ('top', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  400. }
  401. /**
  402. * @page service Service Calls
  403. * @section bx_base_text Base Text
  404. * @subsection bx_base_text-browse Browse
  405. * @subsubsection bx_base_text-browse_updated browse_updated
  406. *
  407. * @code bx_srv('bx_posts', 'browse_updated', [...]); @endcode
  408. *
  409. * Display recently updated posts
  410. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  411. * @param $bEmptyMessage display or not "empty" message when there is no content
  412. * @param $bAjaxPaginate use AJAX paginate or not
  413. *
  414. * @see BxBaseModTextModule::serviceBrowseUpdated
  415. */
  416. /**
  417. * @ref bx_base_text-browse_updated "browse_updated"
  418. */
  419. public function serviceBrowseUpdated ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  420. {
  421. return $this->_serviceBrowse ('updated', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  422. }
  423. /**
  424. * @page service Service Calls
  425. * @section bx_base_text Base Text
  426. * @subsection bx_base_text-browse Browse
  427. * @subsubsection bx_base_text-browse_author browse_author
  428. *
  429. * @code bx_srv('bx_posts', 'browse_author', [...]); @endcode
  430. *
  431. * Display posts of specified author
  432. * @param $iProfileId profile ID
  433. * @param $aParams additional params, see BxBaseModGeneralModule::serviceBrowse
  434. *
  435. * @see BxBaseModTextModule::serviceBrowseAuthor
  436. */
  437. /**
  438. * @ref bx_base_text-browse_author "browse_author"
  439. */
  440. public function serviceBrowseAuthor ($iProfileId = 0, $aParams = array())
  441. {
  442. return $this->_serviceBrowseWithParam ('author', 'profile_id', $iProfileId, $aParams);
  443. }
  444. /**
  445. * @page service Service Calls
  446. * @section bx_base_text Base Text
  447. * @subsection bx_base_text-page_blocks Page Blocks
  448. * @subsubsection bx_base_text-entity_author entity_author
  449. *
  450. * @code bx_srv('bx_posts', 'entity_author', [...]); @endcode
  451. *
  452. * Display author block for the specified post
  453. * @param $iContentId content ID
  454. *
  455. * @see BxBaseModTextModule::serviceEntityAuthor
  456. */
  457. /**
  458. * @ref bx_base_text-entity_author "entity_author"
  459. */
  460. public function serviceEntityAuthor ($iContentId = 0)
  461. {
  462. return $this->_serviceTemplateFunc ('entryAuthor', $iContentId);
  463. }
  464. /**
  465. * @page service Service Calls
  466. * @section bx_base_text Base Text
  467. * @subsection bx_base_text-page_blocks Page Blocks
  468. * @subsubsection bx_base_text-entity_polls entity_polls
  469. *
  470. * @code bx_srv('bx_posts', 'entity_polls', [...]); @endcode
  471. *
  472. * Display polls for the specified post
  473. * @param $iContentId content ID
  474. *
  475. * @see BxBaseModTextModule::serviceEntityPolls
  476. */
  477. /**
  478. * @ref bx_base_text-entity_polls "entity_polls"
  479. */
  480. public function serviceEntityPolls ($iContentId = 0)
  481. {
  482. return $this->_serviceTemplateFunc ('entryPolls', $iContentId);
  483. }
  484. /**
  485. * @page service Service Calls
  486. * @section bx_base_text Base Text
  487. * @subsection bx_base_text-page_blocks Page Blocks
  488. * @subsubsection bx_base_text-entity_breadcrumb entity_breadcrumb
  489. *
  490. * @code bx_srv('bx_forum', 'entity_breadcrumb', [...]); @endcode
  491. *
  492. * Display breadcrumb for the specified post
  493. * @param $iContentId content ID
  494. *
  495. * @see BxBaseModTextModule::serviceEntityBreadcrumb
  496. */
  497. /**
  498. * @ref bx_base_text-entity_breadcrumb "entity_breadcrumb"
  499. */
  500. public function serviceEntityBreadcrumb ($iContentId = 0)
  501. {
  502. return $this->_serviceTemplateFunc ('entryBreadcrumb', $iContentId);
  503. }
  504. /**
  505. * Delete all content by profile
  506. * @param $iProfileId profile id
  507. * @return number of deleted items
  508. */
  509. public function serviceDeleteEntitiesByAuthor ($iProfileId)
  510. {
  511. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  512. if (!$a)
  513. return 0;
  514. $iCount = 0;
  515. foreach ($a as $aContentInfo)
  516. $iCount += ('' == $this->serviceDeleteEntity($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
  517. return $iCount;
  518. }
  519. // ====== PERMISSION METHODS
  520. /**
  521. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  522. */
  523. public function checkAllowedSetThumb ($iContentId = 0)
  524. {
  525. // check ACL
  526. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  527. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  528. return $aCheck[CHECK_ACTION_MESSAGE];
  529. return CHECK_ACTION_RESULT_ALLOWED;
  530. }
  531. public function isAllowedApprove($mixedContent, $isPerformAction = false)
  532. {
  533. return $this->checkAllowedApprove($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  534. }
  535. public function checkAllowedApprove($mixedContent, $isPerformAction = false)
  536. {
  537. $CNF = &$this->_oConfig->CNF;
  538. $sTxtError = '_sys_txt_access_denied';
  539. $iProfileId = bx_get_logged_profile_id();
  540. if(!is_array($mixedContent))
  541. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  542. if(empty($mixedContent) || !is_array($mixedContent))
  543. return _t($sTxtError);
  544. if(!isset($CNF['FIELD_STATUS_ADMIN']) || $mixedContent[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_GENERAL_STATUS_PENDING)
  545. return _t($sTxtError);
  546. if($this->_isModerator())
  547. return CHECK_ACTION_RESULT_ALLOWED;
  548. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && (int)$mixedContent[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  549. $iContextProfileId = abs((int)$mixedContent[$CNF['FIELD_ALLOW_VIEW_TO']]);
  550. $oContextProfile = BxDolProfile::getInstance($iContextProfileId);
  551. $aAdmins = bx_srv($oContextProfile->getModule(), 'get_admins_to_manage_content', [$iContextProfileId]);
  552. if(!empty($aAdmins) && in_array($iProfileId, $aAdmins))
  553. return CHECK_ACTION_RESULT_ALLOWED;
  554. }
  555. return _t($sTxtError);
  556. }
  557. public function isPollPerformed($iObjectId, $iAuthorId = 0, $iAuthorIp = 0)
  558. {
  559. if(empty($iAuthorId)) {
  560. $iAuthorId = bx_get_logged_profile_id();
  561. $iAuthorIp = bx_get_ip_hash(getVisitorIP());
  562. }
  563. return $this->_oDb->isPollPerformed($iObjectId, $iAuthorId, $iAuthorIp);
  564. }
  565. // ====== COMMON METHODS
  566. public function addAttachLink($aValues, $sDisplay = false)
  567. {
  568. $CNF = &$this->_oConfig->CNF;
  569. if(!$sDisplay)
  570. $sDisplay = $CNF['OBJECT_FORM_DISPLAY_ATTACH_LINK_ADD'];
  571. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ATTACH_LINK'], $sDisplay, $this->_oTemplate);
  572. if(!$oForm)
  573. return array('message' => '_sys_txt_error_occured');
  574. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  575. $oForm->aParams['csrf']['disable'] = true;
  576. if(!empty($oForm->aParams['db']['submit_name'])) {
  577. $sSubmitName = $oForm->aParams['db']['submit_name'];
  578. if(!isset($oForm->aInputs[$sSubmitName])) {
  579. if(isset($oForm->aInputs[$CNF['FIELD_ATTACH_LINK_CONTROLS']]))
  580. foreach($oForm->aInputs[$CNF['FIELD_ATTACH_LINK_CONTROLS']] as $mixedIndex => $aInput) {
  581. if(!is_numeric($mixedIndex) || empty($aInput['name']) || $aInput['name'] != $sSubmitName)
  582. continue;
  583. $aValues[$sSubmitName] = $aInput['value'];
  584. }
  585. }
  586. else
  587. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  588. }
  589. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  590. $oForm->initChecker(array(), $aValues);
  591. if(!$oForm->isSubmittedAndValid())
  592. return array('message' => '_sys_txt_error_occured');
  593. return $this->_addLink($oForm);
  594. }
  595. public function deleteAttachLinks($iId)
  596. {
  597. $CNF = &$this->_oConfig->CNF;
  598. $aLinks = $this->_oDb->getLinks($iId);
  599. if(empty($aLinks) || !is_array($aLinks))
  600. return;
  601. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  602. foreach($aLinks as $aLink)
  603. if(!empty($aLink['media_id']))
  604. $oStorage->deleteFile($aLink['media_id']);
  605. $this->_oDb->deleteLinks($iId);
  606. }
  607. public function deleteAttachLinksUnused($iProfileId)
  608. {
  609. $CNF = &$this->_oConfig->CNF;
  610. $aLinks = $this->_oDb->getUnusedLinks($iProfileId);
  611. if(empty($aLinks) || !is_array($aLinks))
  612. return;
  613. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  614. foreach($aLinks as $aLink)
  615. if(!empty($aLink['media_id']))
  616. $oStorage->deleteFile($aLink['media_id']);
  617. $this->_oDb->deleteUnusedLinks($iProfileId);
  618. }
  619. public function getFormAttachLink($iContentId = 0)
  620. {
  621. $CNF = &$this->_oConfig->CNF;
  622. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ATTACH_LINK'], $CNF['OBJECT_FORM_DISPLAY_ATTACH_LINK_ADD'], $this->_oTemplate);
  623. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_attach_link_form/';
  624. $oForm->aInputs['content_id']['value'] = $iContentId;
  625. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  626. $oForm->initChecker();
  627. if($oForm->isSubmittedAndValid())
  628. return $this->_addLink($oForm);
  629. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  630. }
  631. protected function _addLink(&$oForm)
  632. {
  633. $CNF = &$this->_oConfig->CNF;
  634. $iUserId = $this->getUserId();
  635. $iContentId = (int)$oForm->getCleanValue('content_id');
  636. $sLink = rtrim($oForm->getCleanValue('url'), '/');
  637. $sHost = parse_url($sLink, PHP_URL_HOST);
  638. if (is_private_ip(gethostbyname($sHost)))
  639. return array('message' => _t('_sys_txt_error_occured'));
  640. $aMatches = array();
  641. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  642. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  643. $aSiteInfo = bx_get_site_info($sLink, array(
  644. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  645. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  646. ));
  647. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : $sHost;
  648. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : '';
  649. $sMediaUrl = '';
  650. if(!empty($aSiteInfo['thumbnailUrl']))
  651. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  652. else if(!empty($aSiteInfo['OGImage']))
  653. $sMediaUrl = $aSiteInfo['OGImage'];
  654. $iMediaId = 0;
  655. $oStorage = null;
  656. if(!empty($sMediaUrl)) {
  657. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  658. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  659. }
  660. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  661. if(!empty($iId)) {
  662. if(!empty($oStorage) && !empty($iMediaId))
  663. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  664. return array(
  665. 'id' => $iId,
  666. 'content_id' => $iContentId,
  667. 'url' => $sLink,
  668. 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId)
  669. );
  670. }
  671. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  672. }
  673. public function onApprove($mixedContent)
  674. {
  675. $CNF = &$this->_oConfig->CNF;
  676. if(!is_array($mixedContent))
  677. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  678. $this->alertAfterApprove($mixedContent);
  679. $this->onPublished($mixedContent[$CNF['FIELD_ID']]);
  680. }
  681. public function alertAfterAdd($aContentInfo)
  682. {
  683. $CNF = &$this->_oConfig->CNF;
  684. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  685. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  686. $sAction = 'added';
  687. if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == BX_BASE_MOD_TEXT_STATUS_AWAITING)
  688. $sAction = 'deferred';
  689. else if(isset($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == BX_BASE_MOD_GENERAL_STATUS_PENDING)
  690. $sAction = 'deferred';
  691. $aParams = $this->_alertParamsAdd($aContentInfo);
  692. bx_alert('system', 'prepare_alert_params', 0, 0, array('unit'=> $this->getName(), 'action' => &$sAction, 'object_id' => &$iId, 'sender_id' => &$iAuthorId, 'extras' => &$aParams));
  693. bx_alert($this->getName(), $sAction, $iId, $iAuthorId, $aParams);
  694. $this->_processModerationNotifications($aContentInfo);
  695. }
  696. public function alertAfterEdit($aContentInfo)
  697. {
  698. $CNF = &$this->_oConfig->CNF;
  699. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  700. $aParams = $this->_alertParams($aContentInfo);
  701. bx_alert($this->getName(), 'edited', $iId, false, $aParams);
  702. }
  703. /**
  704. * Get array of params to be passed in Add/Edit Alert.
  705. */
  706. protected function _alertParams($aContentInfo)
  707. {
  708. $aParams = parent::_alertParams($aContentInfo);
  709. $CNF = &$this->_oConfig->CNF;
  710. if(!empty($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]))
  711. $aParams['status'] = $aContentInfo[$CNF['FIELD_STATUS']];
  712. if(!empty($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]))
  713. $aParams['status_admin'] = $aContentInfo[$CNF['FIELD_STATUS_ADMIN']];
  714. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  715. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  716. if(!empty($CNF['FIELD_CF']) && isset($aContentInfo[$CNF['FIELD_CF']]))
  717. $aParams['cf'] = $aContentInfo[$CNF['FIELD_CF']];
  718. return $aParams;
  719. }
  720. protected function _alertParamsAdd($aContentInfo)
  721. {
  722. $aParams = $this->_alertParams($aContentInfo);
  723. $CNF = &$this->_oConfig->CNF;
  724. if(!empty($CNF['OBJECT_METATAGS']))
  725. $aParams['timeline_group'] = array(
  726. 'by' => $this->getName() . '_' . abs((int)$aContentInfo[$CNF['FIELD_AUTHOR']]) . '_' . (int)$aContentInfo[$CNF['FIELD_ID']],
  727. 'field' => 'owner_id'
  728. );
  729. return $aParams;
  730. }
  731. public function getPollForm()
  732. {
  733. $CNF = &$this->_oConfig->CNF;
  734. if(empty($CNF['OBJECT_FORM_POLL']))
  735. return array('code' => 1, 'message' => '_sys_txt_error_occured');
  736. $iProfileId = bx_get_logged_profile_id();
  737. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_POLL'], $CNF['OBJECT_FORM_POLL_DISPLAY_ADD'], $this->_oTemplate);
  738. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_poll_form/';
  739. $oForm->initChecker();
  740. if($oForm->isSubmittedAndValid()) {
  741. $iId = $oForm->insert();
  742. if($iId)
  743. return array('code' => 0, 'id' => $iId, 'item' => $this->_oTemplate->getPollItem($iId, $iProfileId, array(
  744. 'manage' => true
  745. )));
  746. else
  747. return array('code' => 2, 'message' => '_sys_txt_error_entry_creation');
  748. }
  749. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  750. }
  751. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  752. {
  753. $CNF = &$this->_oConfig->CNF;
  754. $mResult = parent::getEntryImageData($aContentInfo, $sField, $aTranscoders);
  755. if ($mResult === false && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  756. if(!empty($CNF['OBJECT_STORAGE_PHOTOS']) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS'])){
  757. $sStorage = $CNF['OBJECT_STORAGE_PHOTOS'];
  758. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  759. $aGhostFiles = $oStorage->getGhosts ($this->serviceGetContentOwnerProfileId($aContentInfo[$CNF['FIELD_ID']]), $aContentInfo[$CNF['FIELD_ID']]);
  760. if ($aGhostFiles){
  761. foreach ($aGhostFiles as $k => $a) {
  762. return array('id' => $a['id'], 'transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  763. }
  764. }
  765. }
  766. }
  767. return $mResult;
  768. }
  769. public function decodeDataAPI($aData, $aParams = [])
  770. {
  771. $CNF = &$this->_oConfig->CNF;
  772. $sModule = $this->getName();
  773. $iId = (int)$aData[$CNF['FIELD_ID']];
  774. $sSummary = '';
  775. if(!empty($CNF['PARAM_CHARS_SUMMARY_PLAIN'])) {
  776. $sSummary = $this->_oTemplate->getText($aData);
  777. $sSummary = BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($sSummary), (int)getParam($CNF['PARAM_CHARS_SUMMARY_PLAIN']));
  778. }
  779. $aResult = [
  780. 'id' => $iId,
  781. 'module' => $sModule,
  782. 'module_title' => _t($CNF['T']['txt_sample_single']),
  783. 'added' => $aData[$CNF['FIELD_ADDED']],
  784. 'author' => $aData[$CNF['FIELD_AUTHOR']],
  785. 'author_data' => !empty($aData[$CNF['FIELD_AUTHOR']]) ? BxDolProfile::getData($aData[$CNF['FIELD_AUTHOR']]) : '',
  786. 'title' => $aData[$CNF['FIELD_TITLE']],
  787. 'url' => bx_api_get_relative_url($this->serviceGetLink($iId)),
  788. 'image' => $this->serviceGetThumb($iId),
  789. 'summary_plain' => $sSummary
  790. ];
  791. if(isset($aParams['extended']) && $aParams['extended'] === true)
  792. $aResult['text'] = $aData[$CNF['FIELD_TEXT']];
  793. if(!empty($CNF['OBJECT_MENU_SNIPPET_META']) && ($oMetaMenu = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this->_oTemplate)) !== false) {
  794. $oMetaMenu->setContentId($iId);
  795. $aResult['meta'] = $oMetaMenu->getCodeAPI();
  796. }
  797. return $aResult;
  798. }
  799. // ====== PROTECTED METHODS
  800. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  801. {
  802. $CNF = &$this->_oConfig->CNF;
  803. $aResults = parent::_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  804. if (bx_is_api())
  805. return $aResults;
  806. if (count($aResults) == 0 && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  807. $aResults = $this->_getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  808. if (count($aResults) > 1){
  809. $aResults = array_slice($aResults, 0, 1);
  810. }
  811. }
  812. return $aResults;
  813. }
  814. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  815. {
  816. $CNF = &$this->_oConfig->CNF;
  817. $aTmp = parent::_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  818. $aResults = $this->_getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  819. if (bx_is_api())
  820. return $aResults;
  821. if (count($aTmp) == 0 && count($aResults) > 0 && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  822. $aResults = array_slice($aResults, 1);
  823. }
  824. return $aResults;
  825. }
  826. protected function _getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  827. {
  828. $CNF = &$this->_oConfig->CNF;
  829. $aResults = parent::_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  830. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_PHOTOS']) || empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']))
  831. return $aResults;
  832. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  833. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  834. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  835. if(!$aGhostFiles)
  836. return [];
  837. $oTranscoderSm = false;
  838. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_MINIATURE_PHOTOS']))
  839. $oTranscoderSm = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_MINIATURE_PHOTOS']);
  840. $oTranscoderMd = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']);
  841. $oTranscoderXl = false;
  842. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']))
  843. $oTranscoderXl = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']);
  844. foreach($aGhostFiles as $k => $a) {
  845. $sPhotoSrcMd = $oTranscoderMd->getFileUrl($a['id']);
  846. if(empty($sPhotoSrcMd))
  847. continue;
  848. $sPhotoSrcSm = $oTranscoderSm !== false ? $oTranscoderSm->getFileUrl($a['id']) : '';
  849. if(!$sPhotoSrcSm)
  850. $sPhotoSrcSm = $sPhotoSrcMd;
  851. $sPhotoSrcXl = $oTranscoderXl !== false ? $oTranscoderXl->getFileUrl($a['id']) : $oStorage->getFileUrlById($a['id']);
  852. if(!$sPhotoSrcXl)
  853. $sPhotoSrcXl = $sPhotoSrcMd;
  854. if (bx_is_api()){
  855. $aResults[] = bx_api_get_image($CNF['OBJECT_STORAGE_PHOTOS'], (int)$a['id']);
  856. }
  857. else{
  858. $aResults[] = [
  859. 'id' => $a['id'],
  860. 'src' => $sPhotoSrcMd,
  861. 'src_small' => $sPhotoSrcSm,
  862. 'src_medium' => $sPhotoSrcMd,
  863. 'src_orig' => $sPhotoSrcXl,
  864. ];
  865. }
  866. }
  867. return $aResults;
  868. }
  869. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  870. {
  871. $CNF = &$this->_oConfig->CNF;
  872. $aResults = parent::_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  873. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_VIDEOS']) || empty($CNF['OBJECT_VIDEOS_TRANSCODERS']))
  874. return $aResults;
  875. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  876. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_VIDEOS']);
  877. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  878. if(!$aGhostFiles)
  879. return array();
  880. $oTcPoster = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']);
  881. $oTcMp4 = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  882. $oTcMp4Hd = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4_hd']);
  883. if(!$oTcPoster || !$oTcMp4 || !$oTcMp4Hd)
  884. return array();
  885. $aResults = array();
  886. foreach ($aGhostFiles as $k => $a) {
  887. $sVideoUrl = $oStorage->getFileUrlById($a['id']);
  888. $aVideoFile = $oStorage->getFile($a['id']);
  889. $sVideoUrlHd = '';
  890. if (!empty($aVideoFile['dimensions']) && $oTcMp4Hd->isProcessHD($aVideoFile['dimensions']))
  891. $sVideoUrlHd = $oTcMp4Hd->getFileUrl($a['id']);
  892. $aResults[$a['id']] = array(
  893. 'id' => $a['id'],
  894. 'src_poster' => $oTcPoster->getFileUrl($a['id']),
  895. 'src_mp4' => $oTcMp4->getFileUrl($a['id']),
  896. 'src_mp4_hd' => $sVideoUrlHd,
  897. );
  898. }
  899. return $aResults;
  900. }
  901. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  902. {
  903. $CNF = &$this->_oConfig->CNF;
  904. $aResults = parent::_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  905. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_FILES']))
  906. return $aResults;
  907. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  908. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_FILES']);
  909. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  910. if(!$aGhostFiles)
  911. return array();
  912. $oTranscoder = null;
  913. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']))
  914. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']);
  915. foreach ($aGhostFiles as $k => $a) {
  916. $bImage = in_array($a['ext'], array('jpg', 'jpeg', 'png', 'gif'));
  917. $sPhotoSrc = '';
  918. if($bImage && $oTranscoder)
  919. $sPhotoSrc = $oTranscoder->getFileUrl($a['id']);
  920. if(empty($sPhotoSrc) && $oStorage)
  921. $sPhotoSrc = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($a['file_name']));
  922. $sUrl = $oStorage->getFileUrlById($a['id']);
  923. $aResults[] = array(
  924. 'id' => $a['id'],
  925. 'src' => $sPhotoSrc,
  926. 'src_medium' => $sPhotoSrc,
  927. 'src_orig' => $bImage ? $sUrl : '',
  928. 'url' => !$bImage ? $sUrl : ''
  929. );
  930. }
  931. return $aResults;
  932. }
  933. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  934. {
  935. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  936. if(!$this->_oConfig->isAttachmentsInTimeline())
  937. return $aResult;
  938. $CNF = &$this->_oConfig->CNF;
  939. $bDynamic = isset($aBrowseParams['dynamic_mode']) && (bool)$aBrowseParams['dynamic_mode'] === true;
  940. if(!empty($CNF['PARAM_POLL_ENABLED']) && $CNF['PARAM_POLL_ENABLED'] == true)
  941. $aPolls = $this->_oDb->getPolls(array('type' => 'content_id', 'content_id' => (int)$aContentInfo[$CNF['FIELD_ID']]));
  942. if(!empty($aPolls) && is_array($aPolls)) {
  943. $sInclude = $this->_oTemplate->addCss(array('polls.css'), $bDynamic);
  944. $aResult['raw'] = ($bDynamic ? $sInclude : '') . $this->_oTemplate->parseHtmlByName('poll_items_embed.html', array(
  945. 'embed_url' => BX_DOL_URL_ROOT . bx_append_url_params($this->_oConfig->getBaseUri() . 'embed_polls/', array(
  946. 'id' => (int)$aContentInfo[$CNF['FIELD_ID']],
  947. 'param_switch_menu' => 0,
  948. 'param_showcase' => 1
  949. ))
  950. ));
  951. /*
  952. if((!empty($aResult['videos']) && is_array($aResult['videos'])) || (!empty($aResult['videos_attach']) && is_array($aResult['videos_attach'])))
  953. $aResult['_cache'] = false;
  954. */
  955. }
  956. return $aResult;
  957. }
  958. protected function _buildRssParams($sMode, $aArgs)
  959. {
  960. $aParams = array ();
  961. $sMode = bx_process_input($sMode);
  962. switch ($sMode) {
  963. case 'author':
  964. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  965. break;
  966. }
  967. return $aParams;
  968. }
  969. public function serviceIsAllowedPostInContext()
  970. {
  971. return true;
  972. }
  973. }
  974. /** @} */