BxBaseModTextModule.php 27 KB

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