BxBaseModTextModule.php 27 KB

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