BxBaseModTextModule.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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. /**
  12. * Base module class for text based modules
  13. */
  14. class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolContentInfoService
  15. {
  16. function __construct(&$aModule)
  17. {
  18. parent::__construct($aModule);
  19. }
  20. // ====== ACTIONS METHODS
  21. public function actionEmbedPoll($iPollId = 0)
  22. {
  23. if(empty($iPollId) && bx_get('poll_id') !== false)
  24. $iPollId = (int)bx_get('poll_id');
  25. $aParams = bx_get_with_prefix('param');
  26. array_walk($aParams, function(&$sValue) {
  27. $sValue = bx_process_input($sValue);
  28. });
  29. $this->_oTemplate->embedPollItem($iPollId, $aParams);
  30. }
  31. public function actionEmbedPolls($iId = 0)
  32. {
  33. list($iContentId, $aContentInfo) = $this->_getContent($iId);
  34. if($iContentId === false)
  35. return;
  36. $aParams = bx_get_with_prefix('param');
  37. array_walk($aParams, function(&$sValue) {
  38. $sValue = bx_process_input($sValue);
  39. });
  40. $this->_oTemplate->embedPollItems($aContentInfo, $aParams);
  41. }
  42. public function actionGetPoll()
  43. {
  44. $iPollId = (int)bx_get('poll_id');
  45. $sView = bx_process_input(bx_get('view'));
  46. $sMethod = 'serviceGetBlockPoll' . bx_gen_method_name($sView);
  47. if(!method_exists($this, $sMethod))
  48. return echoJson(array());
  49. $aBlock = $this->$sMethod($iPollId, true);
  50. if(empty($aBlock) || !is_array($aBlock))
  51. return echoJson(array());
  52. return echoJson(array(
  53. 'content' => $aBlock['content']
  54. ));
  55. }
  56. public function actionDeletePoll()
  57. {
  58. $CNF = &$this->_oConfig->CNF;
  59. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  60. if(empty($iId))
  61. return echoJson(array());
  62. $aResult = array();
  63. if($this->_oDb->deletePolls(array($CNF['FIELD_POLL_ID'] => $iId)))
  64. $aResult = array('code' => 0);
  65. else
  66. $aResult = array('code' => 1, 'message' => _t($CNF['txt_err_cannot_perform_action']));
  67. echoJson($aResult);
  68. }
  69. public function actionGetPollForm()
  70. {
  71. echo $this->_oTemplate->getPollForm();
  72. }
  73. public function actionSubmitPollForm()
  74. {
  75. echoJson($this->getPollForm());
  76. }
  77. public function actionFileEmbedVideo($iFileId)
  78. {
  79. $this->_oTemplate->embedVideo($iFileId);
  80. }
  81. public function actionFileEmbedSound($iFileId)
  82. {
  83. $this->_oTemplate->embedSound($iFileId);
  84. }
  85. // ====== SERVICE METHODS
  86. public function serviceGetSafeServices()
  87. {
  88. $a = parent::serviceGetSafeServices();
  89. return array_merge($a, array (
  90. 'GetBlockPollAnswers' => '',
  91. 'GetBlockPollResults' => '',
  92. 'GetMenuAddonManageToolsProfileStats' => '',
  93. 'BrowsePublic' => '',
  94. 'BrowsePopular' => '',
  95. 'BrowseTop' => '',
  96. 'BrowseUpdated' => '',
  97. 'BrowseAuthor' => '',
  98. 'CategoriesMultiList' => ''
  99. ));
  100. }
  101. /**
  102. * @page service Service Calls
  103. * @section bx_base_text Base Text
  104. * @subsection bx_base_text-polls Polls Blocks
  105. * @subsubsection bx_base_text-get_block_poll_answers get_block_poll_answers
  106. *
  107. * @code bx_srv('bx_posts', 'get_block_poll_answers', [...]); @endcode
  108. *
  109. * Get block with poll answers
  110. * @param $iPollId poll ID
  111. *
  112. * @see BxBaseModTextModule::serviceGetBlockPollAnswers
  113. */
  114. /**
  115. * @ref bx_base_text-get_block_poll_answers "get_block_poll_answers"
  116. */
  117. public function serviceGetBlockPollAnswers($iPollId, $bForceDisplay = false)
  118. {
  119. if(!$iPollId)
  120. return false;
  121. if(!$bForceDisplay && $this->isPollPerformed($iPollId))
  122. return $this->serviceGetBlockPollResults($iPollId);
  123. return $this->_serviceTemplateFunc('entryPollAnswers', $iPollId, 'getPollInfoById');
  124. }
  125. /**
  126. * @page service Service Calls
  127. * @section bx_base_text Base Text
  128. * @subsection bx_base_text-polls Polls Blocks
  129. * @subsubsection bx_base_text-get_block_poll_results get_block_poll_results
  130. *
  131. * @code bx_srv('bx_posts', 'get_block_poll_results', [...]); @endcode
  132. *
  133. * Get block with poll results
  134. * @param $iPollId poll ID
  135. *
  136. * @see BxBaseModTextModule::serviceGetBlockPollResults
  137. */
  138. /**
  139. * @ref bx_base_text-get_block_poll_results "get_block_poll_results"
  140. */
  141. public function serviceGetBlockPollResults($iPollId)
  142. {
  143. return $this->_serviceTemplateFunc('entryPollResults', $iPollId, 'getPollInfoById');
  144. }
  145. /**
  146. * Display media EXIF information.
  147. * @param $iMediaId media ID, if it's omitted then it's taken from 'id' GET variable.
  148. * @return HTML string with EXIF info. On error empty string is returned.
  149. */
  150. public function serviceMediaExif ($iMediaId = 0)
  151. {
  152. $CNF = &$this->_oConfig->CNF;
  153. return $this->_serviceTemplateFunc ('mediaExif', $iMediaId, $CNF['FUNCTION_FOR_GET_ITEM_INFO']);
  154. }
  155. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  156. {
  157. $CNF = &$this->_oConfig->CNF;
  158. if(empty($sTranscoder) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']))
  159. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_GALLERY'];
  160. $mixedResult = $this->_getFieldValueThumb('FIELD_THUMB', $iContentId, $sTranscoder);
  161. return $mixedResult !== false ? $mixedResult : '';
  162. }
  163. public function serviceGetMenuAddonManageTools()
  164. {
  165. bx_import('SearchResult', $this->_aModule);
  166. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  167. $o = new $sClass();
  168. $o->unsetPaginate();
  169. $iNumTotal = $o->getNum();
  170. $o->fillFilters(array(
  171. 'status' => 'hidden'
  172. ));
  173. $iNum1 = $o->getNum();
  174. $iNum2 = 0;
  175. $CNF = &$this->_oConfig->CNF;
  176. if (isset($CNF['OBJECT_REPORTS'])){
  177. $o->fillFilters(array('status' => ''));
  178. $o->fillFiltersByObjects(array('reported' => array('value' => '0', 'field' => 'reports', 'operator' => '>')));
  179. $iNum2 = $o->getNum();
  180. }
  181. return array('counter1_value' => $iNum1, 'counter2_value' => $iNum2, 'counter3_value' => $iNumTotal );
  182. }
  183. /**
  184. * @page service Service Calls
  185. * @section bx_base_text Base Text
  186. * @subsection bx_base_text-other Other
  187. * @subsubsection bx_base_text-get_menu_addon_manage_tools_profile_stats get_menu_addon_manage_tools_profile_stats
  188. *
  189. * @code bx_srv('bx_posts', 'get_menu_addon_manage_tools_profile_stats', []); @endcode
  190. *
  191. * Get number of posts for currently logged in user
  192. *
  193. * @see BxBaseModTextModule::serviceGetMenuAddonManageToolsProfileStats
  194. */
  195. /**
  196. * @ref bx_base_text-get_menu_addon_manage_tools_profile_stats "get_menu_addon_manage_tools_profile_stats"
  197. */
  198. public function serviceGetMenuAddonManageToolsProfileStats()
  199. {
  200. bx_import('SearchResult', $this->_aModule);
  201. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  202. $o = new $sClass();
  203. $o->fillFilters(array(
  204. 'author' => bx_get_logged_profile_id()
  205. ));
  206. $o->unsetPaginate();
  207. return $o->getNum();
  208. }
  209. /**
  210. * @page service Service Calls
  211. * @section bx_base_text Base Text
  212. * @subsection bx_base_text-browse Browse
  213. * @subsubsection bx_base_text-browse_public browse_public
  214. *
  215. * @code bx_srv('bx_posts', 'browse_public', [...]); @endcode
  216. *
  217. * Display public posts
  218. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  219. * @param $bEmptyMessage display or not "empty" message when there is no content
  220. * @param $bAjaxPaginate use AJAX paginate or not
  221. *
  222. * @see BxBaseModTextModule::serviceBrowsePublic
  223. */
  224. /**
  225. * @ref bx_base_text-browse_public "browse_public"
  226. */
  227. public function serviceBrowsePublic ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  228. {
  229. return $this->_serviceBrowse ('public', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  230. }
  231. /**
  232. * @page service Service Calls
  233. * @section bx_base_text Base Text
  234. * @subsection bx_base_text-browse Browse
  235. * @subsubsection bx_base_text-browse_popular browse_popular
  236. *
  237. * @code bx_srv('bx_posts', 'browse_popular', [...]); @endcode
  238. *
  239. * Display popular posts
  240. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  241. * @param $bEmptyMessage display or not "empty" message when there is no content
  242. * @param $bAjaxPaginate use AJAX paginate or not
  243. *
  244. * @see BxBaseModTextModule::serviceBrowsePopular
  245. */
  246. /**
  247. * @ref bx_base_text-browse_popular "browse_popular"
  248. */
  249. public function serviceBrowsePopular ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  250. {
  251. return $this->_serviceBrowse ('popular', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  252. }
  253. /**
  254. * @page service Service Calls
  255. * @section bx_base_text Base Text
  256. * @subsection bx_base_text-browse Browse
  257. * @subsubsection bx_base_text-browse_top browse_top
  258. *
  259. * @code bx_srv('bx_posts', 'browse_top', [...]); @endcode
  260. *
  261. * Display top posts
  262. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  263. * @param $bEmptyMessage display or not "empty" message when there is no content
  264. * @param $bAjaxPaginate use AJAX paginate or not
  265. *
  266. * @see BxBaseModTextModule::serviceBrowseTop
  267. */
  268. /**
  269. * @ref bx_base_text-browse_top "browse_top"
  270. */
  271. public function serviceBrowseTop ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  272. {
  273. return $this->_serviceBrowse ('top', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  274. }
  275. /**
  276. * @page service Service Calls
  277. * @section bx_base_text Base Text
  278. * @subsection bx_base_text-browse Browse
  279. * @subsubsection bx_base_text-browse_updated browse_updated
  280. *
  281. * @code bx_srv('bx_posts', 'browse_updated', [...]); @endcode
  282. *
  283. * Display recently updated posts
  284. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  285. * @param $bEmptyMessage display or not "empty" message when there is no content
  286. * @param $bAjaxPaginate use AJAX paginate or not
  287. *
  288. * @see BxBaseModTextModule::serviceBrowseUpdated
  289. */
  290. /**
  291. * @ref bx_base_text-browse_updated "browse_updated"
  292. */
  293. public function serviceBrowseUpdated ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  294. {
  295. return $this->_serviceBrowse ('updated', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  296. }
  297. /**
  298. * @page service Service Calls
  299. * @section bx_base_text Base Text
  300. * @subsection bx_base_text-browse Browse
  301. * @subsubsection bx_base_text-browse_author browse_author
  302. *
  303. * @code bx_srv('bx_posts', 'browse_author', [...]); @endcode
  304. *
  305. * Display posts of specified author
  306. * @param $iProfileId profile ID
  307. * @param $aParams additional params, see BxBaseModGeneralModule::serviceBrowse
  308. *
  309. * @see BxBaseModTextModule::serviceBrowseAuthor
  310. */
  311. /**
  312. * @ref bx_base_text-browse_author "browse_author"
  313. */
  314. public function serviceBrowseAuthor ($iProfileId = 0, $aParams = array())
  315. {
  316. return $this->_serviceBrowseWithParam ('author', 'profile_id', $iProfileId, $aParams);
  317. }
  318. /**
  319. * @page service Service Calls
  320. * @section bx_base_text Base Text
  321. * @subsection bx_base_text-page_blocks Page Blocks
  322. * @subsubsection bx_base_text-entity_author entity_author
  323. *
  324. * @code bx_srv('bx_posts', 'entity_author', [...]); @endcode
  325. *
  326. * Display author block for the specified post
  327. * @param $iContentId content ID
  328. *
  329. * @see BxBaseModTextModule::serviceEntityAuthor
  330. */
  331. /**
  332. * @ref bx_base_text-entity_author "entity_author"
  333. */
  334. public function serviceEntityAuthor ($iContentId = 0)
  335. {
  336. return $this->_serviceTemplateFunc ('entryAuthor', $iContentId);
  337. }
  338. /**
  339. * @page service Service Calls
  340. * @section bx_base_text Base Text
  341. * @subsection bx_base_text-page_blocks Page Blocks
  342. * @subsubsection bx_base_text-entity_polls entity_polls
  343. *
  344. * @code bx_srv('bx_posts', 'entity_polls', [...]); @endcode
  345. *
  346. * Display polls for the specified post
  347. * @param $iContentId content ID
  348. *
  349. * @see BxBaseModTextModule::serviceEntityPolls
  350. */
  351. /**
  352. * @ref bx_base_text-entity_polls "entity_polls"
  353. */
  354. public function serviceEntityPolls ($iContentId = 0)
  355. {
  356. return $this->_serviceTemplateFunc ('entryPolls', $iContentId);
  357. }
  358. /**
  359. * @page service Service Calls
  360. * @section bx_base_text Base Text
  361. * @subsection bx_base_text-page_blocks Page Blocks
  362. * @subsubsection bx_base_text-entity_breadcrumb entity_breadcrumb
  363. *
  364. * @code bx_srv('bx_forum', 'entity_breadcrumb', [...]); @endcode
  365. *
  366. * Display breadcrumb for the specified post
  367. * @param $iContentId content ID
  368. *
  369. * @see BxBaseModTextModule::serviceEntityBreadcrumb
  370. */
  371. /**
  372. * @ref bx_base_text-entity_breadcrumb "entity_breadcrumb"
  373. */
  374. public function serviceEntityBreadcrumb ($iContentId = 0)
  375. {
  376. return $this->_serviceTemplateFunc ('entryBreadcrumb', $iContentId);
  377. }
  378. /**
  379. * Delete all content by profile
  380. * @param $iProfileId profile id
  381. * @return number of deleted items
  382. */
  383. public function serviceDeleteEntitiesByAuthor ($iProfileId)
  384. {
  385. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  386. if (!$a)
  387. return 0;
  388. $iCount = 0;
  389. foreach ($a as $aContentInfo)
  390. $iCount += ('' == $this->serviceDeleteEntity($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
  391. return $iCount;
  392. }
  393. // ====== PERMISSION METHODS
  394. /**
  395. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  396. */
  397. public function checkAllowedSetThumb ($iContentId = 0)
  398. {
  399. // check ACL
  400. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  401. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  402. return $aCheck[CHECK_ACTION_MESSAGE];
  403. return CHECK_ACTION_RESULT_ALLOWED;
  404. }
  405. public function isPollPerformed($iObjectId, $iAuthorId = 0, $iAuthorIp = 0)
  406. {
  407. if(empty($iAuthorId)) {
  408. $iAuthorId = bx_get_logged_profile_id();
  409. $iAuthorIp = ip2long(getVisitorIP());
  410. }
  411. return $this->_oDb->isPollPerformed($iObjectId, $iAuthorId, $iAuthorIp);
  412. }
  413. // ====== COMMON METHODS
  414. public function onPublished($iContentId)
  415. {
  416. parent::onPublished($iContentId);
  417. $CNF = &$this->_oConfig->CNF;
  418. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  419. if(!$aContentInfo)
  420. return;
  421. $aParams = $this->_alertParams($aContentInfo);
  422. bx_alert($this->getName(), 'added', $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  423. }
  424. public function onFailed($iContentId)
  425. {
  426. parent::onFailed($iContentId);
  427. $CNF = &$this->_oConfig->CNF;
  428. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  429. if(!$aContentInfo)
  430. return;
  431. $aParams = array('object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']]);
  432. bx_alert($this->getName(), 'failed', $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  433. }
  434. public function alertAfterAdd($aContentInfo)
  435. {
  436. $CNF = &$this->_oConfig->CNF;
  437. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  438. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  439. $sAction = 'added';
  440. if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == 'awaiting')
  441. $sAction = 'deferred';
  442. $aParams = $this->_alertParams($aContentInfo);
  443. bx_alert('system', 'prepare_alert_params', 0, 0, array('unit'=> $this->getName(), 'action' => $sAction, 'object_id' => $iId, 'sender_id' => $iAuthorId, 'extras' => &$aParams));
  444. bx_alert($this->getName(), $sAction, $iId, $iAuthorId, $aParams);
  445. }
  446. public function alertAfterEdit($aContentInfo)
  447. {
  448. $CNF = &$this->_oConfig->CNF;
  449. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  450. $aParams = $this->_alertParams($aContentInfo);
  451. bx_alert($this->getName(), 'edited', $iId, false, $aParams);
  452. }
  453. /**
  454. * Get array of params to be passed in Add/Edit Alert.
  455. */
  456. protected function _alertParams($aContentInfo)
  457. {
  458. $CNF = &$this->_oConfig->CNF;
  459. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  460. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  461. $aParams = array(
  462. 'object_author_id' => $iAuthorId
  463. );
  464. if(isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  465. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  466. if(!empty($CNF['OBJECT_METATAGS']))
  467. $aParams['timeline_group'] = array(
  468. 'by' => $this->getName() . '_' . $iAuthorId . '_' . $iId,
  469. 'field' => 'owner_id'
  470. );
  471. return $aParams;
  472. }
  473. public function isEntryActive($aContentInfo)
  474. {
  475. $CNF = &$this->_oConfig->CNF;
  476. if($aContentInfo[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id() || $this->_isModerator())
  477. return true;
  478. if(isset($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active')
  479. return false;
  480. if(isset($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active')
  481. return false;
  482. return true;
  483. }
  484. public function getPollForm()
  485. {
  486. $CNF = &$this->_oConfig->CNF;
  487. if(empty($CNF['OBJECT_FORM_POLL']))
  488. return array('code' => 1, 'message' => '_sys_txt_error_occured');
  489. $iProfileId = bx_get_logged_profile_id();
  490. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_POLL'], $CNF['OBJECT_FORM_POLL_DISPLAY_ADD'], $this->_oTemplate);
  491. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_poll_form/';
  492. $oForm->initChecker();
  493. if($oForm->isSubmittedAndValid()) {
  494. $iId = $oForm->insert();
  495. if($iId)
  496. return array('code' => 0, 'id' => $iId, 'item' => $this->_oTemplate->getPollItem($iId, $iProfileId, array(
  497. 'manage' => true
  498. )));
  499. else
  500. return array('code' => 2, 'message' => '_sys_txt_error_entry_creation');
  501. }
  502. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  503. }
  504. // ====== PROTECTED METHODS
  505. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  506. {
  507. $CNF = &$this->_oConfig->CNF;
  508. $aResults = parent::_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  509. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_PHOTOS']) || empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']))
  510. return $aResults;
  511. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  512. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  513. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  514. if(!$aGhostFiles)
  515. return array();
  516. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']);
  517. foreach ($aGhostFiles as $k => $a) {
  518. $sPhotoSrc = $oTranscoder->getFileUrl($a['id']);
  519. if(empty($sPhotoSrc))
  520. continue;
  521. $aResults[] = array(
  522. 'id' => $a['id'],
  523. 'src' => $sPhotoSrc,
  524. 'src_medium' => $sPhotoSrc,
  525. 'src_orig' => $oStorage->getFileUrlById($a['id']),
  526. );
  527. }
  528. return $aResults;
  529. }
  530. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  531. {
  532. $CNF = &$this->_oConfig->CNF;
  533. $aResults = parent::_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  534. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_VIDEOS']) || empty($CNF['OBJECT_VIDEOS_TRANSCODERS']))
  535. return $aResults;
  536. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  537. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_VIDEOS']);
  538. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  539. if(!$aGhostFiles)
  540. return array();
  541. $oTcPoster = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']);
  542. $oTcMp4 = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  543. $oTcMp4Hd = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4_hd']);
  544. if(!$oTcPoster || !$oTcMp4 || !$oTcMp4Hd)
  545. return array();
  546. $aResults = array();
  547. foreach ($aGhostFiles as $k => $a) {
  548. $sVideoUrl = $oStorage->getFileUrlById($a['id']);
  549. $aVideoSize = $oTcMp4Hd->getVideoSize($sVideoUrl);
  550. $sVideoUrlHd = '';
  551. if(!empty($aVideoSize) && is_array($aVideoSize) && (int)$aVideoSize['h'] >= 720)
  552. $sVideoUrlHd = $oTcMp4Hd->getFileUrl($a['id']);
  553. $aResults[$a['id']] = array(
  554. 'id' => $a['id'],
  555. 'src_poster' => $oTcPoster->getFileUrl($a['id']),
  556. 'src_mp4' => $oTcMp4->getFileUrl($a['id']),
  557. 'src_mp4_hd' => $sVideoUrlHd,
  558. );
  559. }
  560. return $aResults;
  561. }
  562. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  563. {
  564. $CNF = &$this->_oConfig->CNF;
  565. $aResults = parent::_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  566. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_FILES']))
  567. return $aResults;
  568. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  569. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_FILES']);
  570. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  571. if(!$aGhostFiles)
  572. return array();
  573. $oTranscoder = null;
  574. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']))
  575. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']);
  576. foreach ($aGhostFiles as $k => $a) {
  577. $bImage = in_array($a['ext'], array('jpg', 'jpeg', 'png', 'gif'));
  578. $sPhotoSrc = '';
  579. if($bImage && $oTranscoder)
  580. $sPhotoSrc = $oTranscoder->getFileUrl($a['id']);
  581. if(empty($sPhotoSrc) && $oStorage)
  582. $sPhotoSrc = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($a['file_name']));
  583. $sUrl = $oStorage->getFileUrlById($a['id']);
  584. $aResults[] = array(
  585. 'id' => $a['id'],
  586. 'src' => $sPhotoSrc,
  587. 'src_medium' => $sPhotoSrc,
  588. 'src_orig' => $bImage ? $sUrl : '',
  589. 'url' => !$bImage ? $sUrl : ''
  590. );
  591. }
  592. return $aResults;
  593. }
  594. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  595. {
  596. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  597. if(!$this->_oConfig->isAttachmentsInTimeline())
  598. return $aResult;
  599. $CNF = &$this->_oConfig->CNF;
  600. $bDynamic = isset($aBrowseParams['dynamic_mode']) && (bool)$aBrowseParams['dynamic_mode'] === true;
  601. if(!empty($CNF['PARAM_POLL_ENABLED']) && $CNF['PARAM_POLL_ENABLED'] == true)
  602. $aPolls = $this->_oDb->getPolls(array('type' => 'content_id', 'content_id' => (int)$aContentInfo[$CNF['FIELD_ID']]));
  603. if(!empty($aPolls) && is_array($aPolls)) {
  604. $sInclude = $this->_oTemplate->addCss(array('polls.css'), $bDynamic);
  605. $aResult['raw'] = ($bDynamic ? $sInclude : '') . $this->_oTemplate->parseHtmlByName('poll_items_embed.html', array(
  606. 'embed_url' => BX_DOL_URL_ROOT . bx_append_url_params($this->_oConfig->getBaseUri() . 'embed_polls/', array(
  607. 'id' => (int)$aContentInfo[$CNF['FIELD_ID']],
  608. 'param_switch_menu' => 0,
  609. 'param_showcase' => 1
  610. ))
  611. ));
  612. /*
  613. if((!empty($aResult['videos']) && is_array($aResult['videos'])) || (!empty($aResult['videos_attach']) && is_array($aResult['videos_attach'])))
  614. $aResult['_cache'] = false;
  615. */
  616. }
  617. return $aResult;
  618. }
  619. protected function _buildRssParams($sMode, $aArgs)
  620. {
  621. $aParams = array ();
  622. $sMode = bx_process_input($sMode);
  623. switch ($sMode) {
  624. case 'author':
  625. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  626. break;
  627. }
  628. return $aParams;
  629. }
  630. }
  631. /** @} */