BxBaseModTextModule.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  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. define('BX_BASE_MOD_TEXT_STATUS_PENDING', 'pending');
  15. /**
  16. * Base module class for text based modules
  17. */
  18. class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolContentInfoService
  19. {
  20. function __construct(&$aModule)
  21. {
  22. parent::__construct($aModule);
  23. }
  24. // ====== ACTIONS METHODS
  25. public function actionEmbedPoll($iPollId = 0)
  26. {
  27. if(empty($iPollId) && bx_get('poll_id') !== false)
  28. $iPollId = (int)bx_get('poll_id');
  29. $aParams = bx_get_with_prefix('param');
  30. array_walk($aParams, function(&$sValue) {
  31. $sValue = bx_process_input($sValue);
  32. });
  33. $this->_oTemplate->embedPollItem($iPollId, $aParams);
  34. }
  35. public function actionEmbedPolls($iId = 0)
  36. {
  37. list($iContentId, $aContentInfo) = $this->_getContent($iId);
  38. if($iContentId === false)
  39. return;
  40. $aParams = bx_get_with_prefix('param');
  41. array_walk($aParams, function(&$sValue) {
  42. $sValue = bx_process_input($sValue);
  43. });
  44. $this->_oTemplate->embedPollItems($aContentInfo, $aParams);
  45. }
  46. public function actionGetPoll()
  47. {
  48. $iPollId = (int)bx_get('poll_id');
  49. $sView = bx_process_input(bx_get('view'));
  50. $sMethod = 'serviceGetBlockPoll' . bx_gen_method_name($sView);
  51. if(!method_exists($this, $sMethod))
  52. return echoJson(array());
  53. $aBlock = $this->$sMethod($iPollId, true);
  54. if(empty($aBlock) || !is_array($aBlock))
  55. return echoJson(array());
  56. return echoJson(array(
  57. 'content' => $aBlock['content']
  58. ));
  59. }
  60. public function actionDeletePoll()
  61. {
  62. $CNF = &$this->_oConfig->CNF;
  63. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  64. if(empty($iId))
  65. return echoJson(array());
  66. $aResult = array();
  67. if($this->_oDb->deletePolls(array($CNF['FIELD_POLL_ID'] => $iId)))
  68. $aResult = array('code' => 0);
  69. else
  70. $aResult = array('code' => 1, 'message' => _t($CNF['txt_err_cannot_perform_action']));
  71. echoJson($aResult);
  72. }
  73. public function actionGetPollForm()
  74. {
  75. echo $this->_oTemplate->getPollForm();
  76. }
  77. public function actionSubmitPollForm()
  78. {
  79. echoJson($this->getPollForm());
  80. }
  81. public function actionFileEmbedVideo($iFileId)
  82. {
  83. $this->_oTemplate->embedVideo($iFileId);
  84. }
  85. public function actionFileEmbedSound($iFileId)
  86. {
  87. $this->_oTemplate->embedSound($iFileId);
  88. }
  89. public function actionApprove()
  90. {
  91. $CNF = &$this->_oConfig->CNF;
  92. if(!isset($CNF['FIELD_STATUS_ADMIN']))
  93. return echoJson(array());
  94. $iContentId = (int)bx_get('content_id');
  95. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  96. if(empty($aContentInfo) || !is_array($aContentInfo) || $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_TEXT_STATUS_PENDING)
  97. return echoJson(array());
  98. $oForm = $this->_getApproveForm($iContentId, $aContentInfo);
  99. $oForm->initChecker();
  100. if(!$oForm->isSubmitted() || !$oForm->isValid()) {
  101. $sPopupId = $this->getName() . '_approve_' . $iContentId;
  102. $sPopupTitle = !empty($CNF['T']['txt_approve_popup_title']) ? $CNF['T']['txt_approve_popup_title'] : '_sys_manage_popup_approve_title';
  103. return echoJson(array('popup' => BxTemplFunctions::getInstance()->popupBox($sPopupId, _t($sPopupTitle), $oForm->getCode(true))));
  104. }
  105. if($oForm->getCleanValue('do_send')) {
  106. $aResult = array();
  107. if($this->_sendApproveMessage($iContentId, $aContentInfo, $oForm))
  108. $aResult = array('msg' => _t('_sys_manage_txt_sent'));
  109. else
  110. $aResult = array('msg' => _t('_sys_manage_err_cannot_perform_action'));
  111. return echoJson($aResult);
  112. }
  113. if($oForm->getCleanValue('do_submit')) {
  114. $aResult = array();
  115. if($this->_oDb->updateEntriesBy(array($CNF['FIELD_STATUS_ADMIN'] => BX_BASE_MOD_TEXT_STATUS_ACTIVE), array($CNF['FIELD_ID'] => $iContentId))) {
  116. $this->onApprove($aContentInfo);
  117. $aResult = array('msg' => _t('_sys_manage_txt_approved'), 'reload' => 1);
  118. }
  119. else
  120. $aResult = array('msg' => _t('_sys_manage_err_cannot_perform_action'));
  121. return echoJson($aResult);
  122. }
  123. }
  124. // ====== SERVICE METHODS
  125. public function serviceGetSafeServices()
  126. {
  127. $a = parent::serviceGetSafeServices();
  128. return array_merge($a, array (
  129. 'GetBlockPollAnswers' => '',
  130. 'GetBlockPollResults' => '',
  131. 'GetMenuAddonManageToolsProfileStats' => '',
  132. 'BrowsePublic' => '',
  133. 'BrowsePopular' => '',
  134. 'BrowseTop' => '',
  135. 'BrowseUpdated' => '',
  136. 'BrowseAuthor' => '',
  137. 'CategoriesMultiListContext' => ''
  138. ));
  139. }
  140. /**
  141. * @page service Service Calls
  142. * @section bx_base_text Base Text
  143. * @subsection bx_base_general-page_blocks Page Blocks
  144. * @subsubsection bx_base_general-categories_multi_list_context categories_multi_list_context
  145. *
  146. * @code bx_srv('bx_posts', 'categories_multi_list_context', [...]); @endcode
  147. *
  148. * Display multi-categorories block with number of posts in each category for current context
  149. * @param $bDisplayEmptyCats display empty categories
  150. *
  151. * @see BxBaseModGeneralModule::serviceCategoriesMultiListContext
  152. */
  153. /**
  154. * @ref bx_base_general-categories_multi_list_context "categories_multi_list_context"
  155. */
  156. public function serviceCategoriesMultiListContext($iProfileId = 0, $bDisplayEmptyCats = true)
  157. {
  158. if ($iProfileId == 0)
  159. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  160. $oCategories = BxDolCategories::getInstance();
  161. $aCats = $oCategories->getData([
  162. 'type' => 'by_module&context_with_num',
  163. 'module' => $this->getName(),
  164. 'context_id' => $iProfileId
  165. ]
  166. );
  167. $aVars = array('bx_repeat:cats' => array());
  168. foreach ($aCats as $oCat) {
  169. $sValue = $oCat['value'];
  170. $iNum = $oCat['num'];
  171. $aVars['bx_repeat:cats'][] = array(
  172. 'url' => $oCategories->getUrl($this->getName(), $sValue, '&context_id=' . $iProfileId),
  173. 'name' => _t($sValue),
  174. 'value' => $sValue,
  175. 'num' => $iNum,
  176. );
  177. }
  178. if (!$aVars['bx_repeat:cats'])
  179. return '';
  180. return $this->_oTemplate->parseHtmlByName('category_list_multi.html', $aVars);
  181. }
  182. /**
  183. * @page service Service Calls
  184. * @section bx_base_text Base Text
  185. * @subsection bx_base_text-polls Polls Blocks
  186. * @subsubsection bx_base_text-get_block_poll_answers get_block_poll_answers
  187. *
  188. * @code bx_srv('bx_posts', 'get_block_poll_answers', [...]); @endcode
  189. *
  190. * Get block with poll answers
  191. * @param $iPollId poll ID
  192. *
  193. * @see BxBaseModTextModule::serviceGetBlockPollAnswers
  194. */
  195. /**
  196. * @ref bx_base_text-get_block_poll_answers "get_block_poll_answers"
  197. */
  198. public function serviceGetBlockPollAnswers($iPollId, $bForceDisplay = false)
  199. {
  200. if(!$iPollId)
  201. return false;
  202. if(!$bForceDisplay && $this->isPollPerformed($iPollId))
  203. return $this->serviceGetBlockPollResults($iPollId);
  204. return $this->_serviceTemplateFunc('entryPollAnswers', $iPollId, 'getPollInfoById');
  205. }
  206. /**
  207. * @page service Service Calls
  208. * @section bx_base_text Base Text
  209. * @subsection bx_base_text-polls Polls Blocks
  210. * @subsubsection bx_base_text-get_block_poll_results get_block_poll_results
  211. *
  212. * @code bx_srv('bx_posts', 'get_block_poll_results', [...]); @endcode
  213. *
  214. * Get block with poll results
  215. * @param $iPollId poll ID
  216. *
  217. * @see BxBaseModTextModule::serviceGetBlockPollResults
  218. */
  219. /**
  220. * @ref bx_base_text-get_block_poll_results "get_block_poll_results"
  221. */
  222. public function serviceGetBlockPollResults($iPollId)
  223. {
  224. return $this->_serviceTemplateFunc('entryPollResults', $iPollId, 'getPollInfoById');
  225. }
  226. /**
  227. * Display media EXIF information.
  228. * @param $iMediaId media ID, if it's omitted then it's taken from 'id' GET variable.
  229. * @return HTML string with EXIF info. On error empty string is returned.
  230. */
  231. public function serviceMediaExif ($iMediaId = 0)
  232. {
  233. $CNF = &$this->_oConfig->CNF;
  234. return $this->_serviceTemplateFunc ('mediaExif', $iMediaId, $CNF['FUNCTION_FOR_GET_ITEM_INFO']);
  235. }
  236. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  237. {
  238. $CNF = &$this->_oConfig->CNF;
  239. if(empty($sTranscoder) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']))
  240. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_GALLERY'];
  241. $mixedResult = $this->_getFieldValueThumb('FIELD_THUMB', $iContentId, $sTranscoder);
  242. return $mixedResult !== false ? $mixedResult : '';
  243. }
  244. public function serviceGetMenuAddonManageTools()
  245. {
  246. $CNF = &$this->_oConfig->CNF;
  247. $iNumTotal = $this->_oDb->getEntriesNumByParams();
  248. $iNum1 = $this->_oDb->getEntriesNumByParams([
  249. [
  250. 'key' => $CNF['FIELD_STATUS'],
  251. 'value' => 'hidden',
  252. 'operator' => '='
  253. ]
  254. ]);
  255. $iNum2 = 0;
  256. if (isset($CNF['OBJECT_REPORTS'])){
  257. $iNum2 = $this->_oDb->getEntriesNumByParams([
  258. [
  259. 'key' => 'reports',
  260. 'value' => '0',
  261. 'operator' => '>'
  262. ]
  263. ]);
  264. }
  265. return array('counter1_value' => $iNum1, 'counter2_value' => $iNum2, 'counter3_value' => $iNumTotal );
  266. }
  267. /**
  268. * @page service Service Calls
  269. * @section bx_base_text Base Text
  270. * @subsection bx_base_text-other Other
  271. * @subsubsection bx_base_text-get_menu_addon_manage_tools_profile_stats get_menu_addon_manage_tools_profile_stats
  272. *
  273. * @code bx_srv('bx_posts', 'get_menu_addon_manage_tools_profile_stats', []); @endcode
  274. *
  275. * Get number of posts for currently logged in user
  276. *
  277. * @see BxBaseModTextModule::serviceGetMenuAddonManageToolsProfileStats
  278. */
  279. /**
  280. * @ref bx_base_text-get_menu_addon_manage_tools_profile_stats "get_menu_addon_manage_tools_profile_stats"
  281. */
  282. public function serviceGetMenuAddonManageToolsProfileStats()
  283. {
  284. bx_import('SearchResult', $this->_aModule);
  285. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  286. $o = new $sClass();
  287. $o->fillFilters(array(
  288. 'author' => bx_get_logged_profile_id()
  289. ));
  290. $o->unsetPaginate();
  291. return $o->getNum();
  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_public browse_public
  298. *
  299. * @code bx_srv('bx_posts', 'browse_public', [...]); @endcode
  300. *
  301. * Display public posts
  302. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  303. * @param $bEmptyMessage display or not "empty" message when there is no content
  304. * @param $bAjaxPaginate use AJAX paginate or not
  305. *
  306. * @see BxBaseModTextModule::serviceBrowsePublic
  307. */
  308. /**
  309. * @ref bx_base_text-browse_public "browse_public"
  310. */
  311. public function serviceBrowsePublic ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  312. {
  313. return $this->_serviceBrowse ('public', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  314. }
  315. /**
  316. * @page service Service Calls
  317. * @section bx_base_text Base Text
  318. * @subsection bx_base_text-browse Browse
  319. * @subsubsection bx_base_text-browse_popular browse_popular
  320. *
  321. * @code bx_srv('bx_posts', 'browse_popular', [...]); @endcode
  322. *
  323. * Display popular posts
  324. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  325. * @param $bEmptyMessage display or not "empty" message when there is no content
  326. * @param $bAjaxPaginate use AJAX paginate or not
  327. *
  328. * @see BxBaseModTextModule::serviceBrowsePopular
  329. */
  330. /**
  331. * @ref bx_base_text-browse_popular "browse_popular"
  332. */
  333. public function serviceBrowsePopular ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  334. {
  335. return $this->_serviceBrowse ('popular', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  336. }
  337. /**
  338. * @page service Service Calls
  339. * @section bx_base_text Base Text
  340. * @subsection bx_base_text-browse Browse
  341. * @subsubsection bx_base_text-browse_top browse_top
  342. *
  343. * @code bx_srv('bx_posts', 'browse_top', [...]); @endcode
  344. *
  345. * Display top posts
  346. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  347. * @param $bEmptyMessage display or not "empty" message when there is no content
  348. * @param $bAjaxPaginate use AJAX paginate or not
  349. *
  350. * @see BxBaseModTextModule::serviceBrowseTop
  351. */
  352. /**
  353. * @ref bx_base_text-browse_top "browse_top"
  354. */
  355. public function serviceBrowseTop ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  356. {
  357. return $this->_serviceBrowse ('top', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  358. }
  359. /**
  360. * @page service Service Calls
  361. * @section bx_base_text Base Text
  362. * @subsection bx_base_text-browse Browse
  363. * @subsubsection bx_base_text-browse_updated browse_updated
  364. *
  365. * @code bx_srv('bx_posts', 'browse_updated', [...]); @endcode
  366. *
  367. * Display recently updated posts
  368. * @param $sUnitView unit view, such as: full, extended, gallery, showcase
  369. * @param $bEmptyMessage display or not "empty" message when there is no content
  370. * @param $bAjaxPaginate use AJAX paginate or not
  371. *
  372. * @see BxBaseModTextModule::serviceBrowseUpdated
  373. */
  374. /**
  375. * @ref bx_base_text-browse_updated "browse_updated"
  376. */
  377. public function serviceBrowseUpdated ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  378. {
  379. return $this->_serviceBrowse ('updated', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  380. }
  381. /**
  382. * @page service Service Calls
  383. * @section bx_base_text Base Text
  384. * @subsection bx_base_text-browse Browse
  385. * @subsubsection bx_base_text-browse_author browse_author
  386. *
  387. * @code bx_srv('bx_posts', 'browse_author', [...]); @endcode
  388. *
  389. * Display posts of specified author
  390. * @param $iProfileId profile ID
  391. * @param $aParams additional params, see BxBaseModGeneralModule::serviceBrowse
  392. *
  393. * @see BxBaseModTextModule::serviceBrowseAuthor
  394. */
  395. /**
  396. * @ref bx_base_text-browse_author "browse_author"
  397. */
  398. public function serviceBrowseAuthor ($iProfileId = 0, $aParams = array())
  399. {
  400. return $this->_serviceBrowseWithParam ('author', 'profile_id', $iProfileId, $aParams);
  401. }
  402. /**
  403. * @page service Service Calls
  404. * @section bx_base_text Base Text
  405. * @subsection bx_base_text-page_blocks Page Blocks
  406. * @subsubsection bx_base_text-entity_author entity_author
  407. *
  408. * @code bx_srv('bx_posts', 'entity_author', [...]); @endcode
  409. *
  410. * Display author block for the specified post
  411. * @param $iContentId content ID
  412. *
  413. * @see BxBaseModTextModule::serviceEntityAuthor
  414. */
  415. /**
  416. * @ref bx_base_text-entity_author "entity_author"
  417. */
  418. public function serviceEntityAuthor ($iContentId = 0)
  419. {
  420. return $this->_serviceTemplateFunc ('entryAuthor', $iContentId);
  421. }
  422. /**
  423. * @page service Service Calls
  424. * @section bx_base_text Base Text
  425. * @subsection bx_base_text-page_blocks Page Blocks
  426. * @subsubsection bx_base_text-entity_polls entity_polls
  427. *
  428. * @code bx_srv('bx_posts', 'entity_polls', [...]); @endcode
  429. *
  430. * Display polls for the specified post
  431. * @param $iContentId content ID
  432. *
  433. * @see BxBaseModTextModule::serviceEntityPolls
  434. */
  435. /**
  436. * @ref bx_base_text-entity_polls "entity_polls"
  437. */
  438. public function serviceEntityPolls ($iContentId = 0)
  439. {
  440. return $this->_serviceTemplateFunc ('entryPolls', $iContentId);
  441. }
  442. /**
  443. * @page service Service Calls
  444. * @section bx_base_text Base Text
  445. * @subsection bx_base_text-page_blocks Page Blocks
  446. * @subsubsection bx_base_text-entity_breadcrumb entity_breadcrumb
  447. *
  448. * @code bx_srv('bx_forum', 'entity_breadcrumb', [...]); @endcode
  449. *
  450. * Display breadcrumb for the specified post
  451. * @param $iContentId content ID
  452. *
  453. * @see BxBaseModTextModule::serviceEntityBreadcrumb
  454. */
  455. /**
  456. * @ref bx_base_text-entity_breadcrumb "entity_breadcrumb"
  457. */
  458. public function serviceEntityBreadcrumb ($iContentId = 0)
  459. {
  460. return $this->_serviceTemplateFunc ('entryBreadcrumb', $iContentId);
  461. }
  462. /**
  463. * Delete all content by profile
  464. * @param $iProfileId profile id
  465. * @return number of deleted items
  466. */
  467. public function serviceDeleteEntitiesByAuthor ($iProfileId)
  468. {
  469. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  470. if (!$a)
  471. return 0;
  472. $iCount = 0;
  473. foreach ($a as $aContentInfo)
  474. $iCount += ('' == $this->serviceDeleteEntity($aContentInfo[$this->_oConfig->CNF['FIELD_ID']]) ? 1 : 0);
  475. return $iCount;
  476. }
  477. // ====== PERMISSION METHODS
  478. /**
  479. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  480. */
  481. public function checkAllowedSetThumb ($iContentId = 0)
  482. {
  483. // check ACL
  484. $aCheck = checkActionModule($this->_iProfileId, 'set thumb', $this->getName(), false);
  485. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  486. return $aCheck[CHECK_ACTION_MESSAGE];
  487. return CHECK_ACTION_RESULT_ALLOWED;
  488. }
  489. public function isAllowedApprove($mixedContent, $isPerformAction = false)
  490. {
  491. return $this->checkAllowedApprove($mixedContent, $isPerformAction) === CHECK_ACTION_RESULT_ALLOWED;
  492. }
  493. public function checkAllowedApprove($mixedContent, $isPerformAction = false)
  494. {
  495. $CNF = &$this->_oConfig->CNF;
  496. $sTxtError = '_sys_txt_access_denied';
  497. if(!is_array($mixedContent))
  498. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  499. if(empty($mixedContent) || !is_array($mixedContent))
  500. return _t($sTxtError);
  501. if(!isset($CNF['FIELD_STATUS_ADMIN']) || $mixedContent[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_TEXT_STATUS_PENDING)
  502. return _t($sTxtError);
  503. if($this->_isModerator())
  504. return CHECK_ACTION_RESULT_ALLOWED;
  505. return _t($sTxtError);
  506. }
  507. public function isPollPerformed($iObjectId, $iAuthorId = 0, $iAuthorIp = 0)
  508. {
  509. if(empty($iAuthorId)) {
  510. $iAuthorId = bx_get_logged_profile_id();
  511. $iAuthorIp = ip2long(getVisitorIP());
  512. }
  513. return $this->_oDb->isPollPerformed($iObjectId, $iAuthorId, $iAuthorIp);
  514. }
  515. // ====== COMMON METHODS
  516. public function onApprove($mixedContent)
  517. {
  518. $CNF = &$this->_oConfig->CNF;
  519. if(!is_array($mixedContent))
  520. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  521. $this->alertAfterApprove($mixedContent);
  522. $this->onPublished($mixedContent[$CNF['FIELD_ID']]);
  523. }
  524. public function alertAfterAdd($aContentInfo)
  525. {
  526. $CNF = &$this->_oConfig->CNF;
  527. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  528. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  529. $sAction = 'added';
  530. if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == BX_BASE_MOD_TEXT_STATUS_AWAITING)
  531. $sAction = 'deferred';
  532. else if(isset($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == BX_BASE_MOD_TEXT_STATUS_PENDING)
  533. $sAction = 'deferred';
  534. $aParams = $this->_alertParamsAdd($aContentInfo);
  535. bx_alert('system', 'prepare_alert_params', 0, 0, array('unit'=> $this->getName(), 'action' => &$sAction, 'object_id' => &$iId, 'sender_id' => &$iAuthorId, 'extras' => &$aParams));
  536. bx_alert($this->getName(), $sAction, $iId, $iAuthorId, $aParams);
  537. }
  538. public function alertAfterEdit($aContentInfo)
  539. {
  540. $CNF = &$this->_oConfig->CNF;
  541. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  542. $aParams = $this->_alertParams($aContentInfo);
  543. bx_alert($this->getName(), 'edited', $iId, false, $aParams);
  544. }
  545. public function alertAfterApprove($aContentInfo)
  546. {
  547. $CNF = &$this->_oConfig->CNF;
  548. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  549. $aParams = $this->_alertParams($aContentInfo);
  550. bx_alert($this->getName(), 'approved', $iId, false, $aParams);
  551. }
  552. /**
  553. * Get array of params to be passed in Add/Edit Alert.
  554. */
  555. protected function _alertParams($aContentInfo)
  556. {
  557. $aParams = parent::_alertParams($aContentInfo);
  558. $CNF = &$this->_oConfig->CNF;
  559. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  560. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  561. return $aParams;
  562. }
  563. protected function _alertParamsAdd($aContentInfo)
  564. {
  565. $aParams = $this->_alertParams($aContentInfo);
  566. $CNF = &$this->_oConfig->CNF;
  567. if(!empty($CNF['OBJECT_METATAGS']))
  568. $aParams['timeline_group'] = array(
  569. 'by' => $this->getName() . '_' . (int)$aContentInfo[$CNF['FIELD_AUTHOR']] . '_' . (int)$aContentInfo[$CNF['FIELD_ID']],
  570. 'field' => 'owner_id'
  571. );
  572. return $aParams;
  573. }
  574. public function isEntryActive($aContentInfo)
  575. {
  576. $CNF = &$this->_oConfig->CNF;
  577. if($aContentInfo[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id() || $this->_isModerator())
  578. return true;
  579. if(isset($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active')
  580. return false;
  581. if(isset($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active')
  582. return false;
  583. return true;
  584. }
  585. public function getPollForm()
  586. {
  587. $CNF = &$this->_oConfig->CNF;
  588. if(empty($CNF['OBJECT_FORM_POLL']))
  589. return array('code' => 1, 'message' => '_sys_txt_error_occured');
  590. $iProfileId = bx_get_logged_profile_id();
  591. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_POLL'], $CNF['OBJECT_FORM_POLL_DISPLAY_ADD'], $this->_oTemplate);
  592. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_poll_form/';
  593. $oForm->initChecker();
  594. if($oForm->isSubmittedAndValid()) {
  595. $iId = $oForm->insert();
  596. if($iId)
  597. return array('code' => 0, 'id' => $iId, 'item' => $this->_oTemplate->getPollItem($iId, $iProfileId, array(
  598. 'manage' => true
  599. )));
  600. else
  601. return array('code' => 2, 'message' => '_sys_txt_error_entry_creation');
  602. }
  603. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  604. }
  605. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  606. {
  607. $CNF = &$this->_oConfig->CNF;
  608. $mResult = parent::getEntryImageData($aContentInfo, $sField, $aTranscoders);
  609. if ($mResult === false && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  610. if(!empty($CNF['OBJECT_STORAGE_PHOTOS']) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS'])){
  611. $sStorage = $CNF['OBJECT_STORAGE_PHOTOS'];
  612. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  613. $aGhostFiles = $oStorage->getGhosts ($this->serviceGetContentOwnerProfileId($aContentInfo[$CNF['FIELD_ID']]), $aContentInfo[$CNF['FIELD_ID']]);
  614. if ($aGhostFiles){
  615. foreach ($aGhostFiles as $k => $a) {
  616. return array('id' => $a['id'], 'transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  617. }
  618. }
  619. }
  620. }
  621. return $mResult;
  622. }
  623. // ====== PROTECTED METHODS
  624. protected function _getApproveForm($iContentId, $aContentInfo)
  625. {
  626. $CNF = &$this->_oConfig->CNF;
  627. $sForm = 'sys_manage';
  628. if(!empty($CNF['OBJECT_FORM_MANAGE']))
  629. $sForm = $CNF['OBJECT_FORM_MANAGE'];
  630. $sFormDisplay = 'sys_manage_approve';
  631. if(!empty($CNF['OBJECT_FORM_MANAGE_APPROVE']))
  632. $sFormDisplay = $CNF['OBJECT_FORM_MANAGE_APPROVE'];
  633. $oForm = BxTemplFormView::getObjectInstance($sForm, $sFormDisplay);
  634. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'approve';
  635. $oForm->aInputs['content_id']['value'] = $iContentId;
  636. foreach($oForm->aInputs['controls'] as $iKey => $mixedValue)
  637. if(is_numeric($iKey) && isset($mixedValue['name']) && $mixedValue['name'] == 'do_submit')
  638. $oForm->aInputs['controls'][$iKey]['value'] = _t('_sys_form_manage_input_do_submit_approve');
  639. bx_alert($this->_oConfig->getName(), 'get_approve_form', 0, 0, array(
  640. 'content_id' => $iContentId,
  641. 'content_info' => $aContentInfo,
  642. 'override_result' => &$oForm
  643. ));
  644. return $oForm;
  645. }
  646. protected function _sendApproveMessage($iContentId, $aContentInfo, &$oForm)
  647. {
  648. $CNF = &$this->_oConfig->CNF;
  649. $sETemplate = 't_ManageApprove';
  650. if(!empty($CNF['ETEMPLATE_MANAGE_APPROVE']))
  651. $sETemplate = $CNF['ETEMPLATE_MANAGE_APPROVE'];
  652. $aEParams = array(
  653. 'content_title' => !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  654. 'notes' => $oForm->getCleanValue('notes'),
  655. );
  656. bx_alert($this->_oConfig->getName(), 'get_approve_message', 0, 0, array(
  657. 'content_id' => $iContentId,
  658. 'content_info' => $aContentInfo,
  659. 'form' => $oForm,
  660. 'email_template' => &$sETemplate,
  661. 'email_params' => &$aEParams
  662. ));
  663. return sendMailTemplate($sETemplate, 0, $aContentInfo[$CNF['FIELD_AUTHOR']], $aEParams);
  664. }
  665. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  666. {
  667. $CNF = &$this->_oConfig->CNF;
  668. $aResults = parent::_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  669. if (count($aResults) == 0 && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  670. $aResults = $this->_getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  671. if (count($aResults) > 1){
  672. $aResults = array_slice($aResults, 0, 1);
  673. }
  674. }
  675. return $aResults;
  676. }
  677. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  678. {
  679. $CNF = &$this->_oConfig->CNF;
  680. $aTmp = parent::_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  681. $aResults = $this->_getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  682. if (count($aTmp) == 0 && count($aResults) > 0 && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  683. $aResults = array_slice($aResults, 1);
  684. }
  685. return $aResults;
  686. }
  687. protected function _getImagesForTimelinePostAttachInner($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  688. {
  689. $CNF = &$this->_oConfig->CNF;
  690. $aResults = parent::_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  691. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_PHOTOS']) || empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']))
  692. return $aResults;
  693. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  694. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_PHOTOS']);
  695. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  696. if(!$aGhostFiles)
  697. return array();
  698. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']);
  699. foreach ($aGhostFiles as $k => $a) {
  700. $sPhotoSrc = $oTranscoder->getFileUrl($a['id']);
  701. if(empty($sPhotoSrc))
  702. continue;
  703. $aResults[] = array(
  704. 'id' => $a['id'],
  705. 'src' => $sPhotoSrc,
  706. 'src_medium' => $sPhotoSrc,
  707. 'src_orig' => $oStorage->getFileUrlById($a['id']),
  708. );
  709. }
  710. return $aResults;
  711. }
  712. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  713. {
  714. $CNF = &$this->_oConfig->CNF;
  715. $aResults = parent::_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  716. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_VIDEOS']) || empty($CNF['OBJECT_VIDEOS_TRANSCODERS']))
  717. return $aResults;
  718. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  719. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_VIDEOS']);
  720. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  721. if(!$aGhostFiles)
  722. return array();
  723. $oTcPoster = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']);
  724. $oTcMp4 = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  725. $oTcMp4Hd = BxDolTranscoderVideo::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4_hd']);
  726. if(!$oTcPoster || !$oTcMp4 || !$oTcMp4Hd)
  727. return array();
  728. $aResults = array();
  729. foreach ($aGhostFiles as $k => $a) {
  730. $sVideoUrl = $oStorage->getFileUrlById($a['id']);
  731. $aVideoFile = $oStorage->getFile($a['id']);
  732. $sVideoUrlHd = '';
  733. if (!empty($aVideoFile['dimensions']) && $oTcMp4Hd->isProcessHD($aVideoFile['dimensions']))
  734. $sVideoUrlHd = $oTcMp4Hd->getFileUrl($a['id']);
  735. $aResults[$a['id']] = array(
  736. 'id' => $a['id'],
  737. 'src_poster' => $oTcPoster->getFileUrl($a['id']),
  738. 'src_mp4' => $oTcMp4->getFileUrl($a['id']),
  739. 'src_mp4_hd' => $sVideoUrlHd,
  740. );
  741. }
  742. return $aResults;
  743. }
  744. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  745. {
  746. $CNF = &$this->_oConfig->CNF;
  747. $aResults = parent::_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  748. if(!$this->_oConfig->isAttachmentsInTimeline() || empty($CNF['OBJECT_STORAGE_FILES']))
  749. return $aResults;
  750. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  751. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_FILES']);
  752. $aGhostFiles = $oStorage->getGhosts($this->serviceGetContentOwnerProfileId($iContentId), $iContentId);
  753. if(!$aGhostFiles)
  754. return array();
  755. $oTranscoder = null;
  756. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']))
  757. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']);
  758. foreach ($aGhostFiles as $k => $a) {
  759. $bImage = in_array($a['ext'], array('jpg', 'jpeg', 'png', 'gif'));
  760. $sPhotoSrc = '';
  761. if($bImage && $oTranscoder)
  762. $sPhotoSrc = $oTranscoder->getFileUrl($a['id']);
  763. if(empty($sPhotoSrc) && $oStorage)
  764. $sPhotoSrc = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($a['file_name']));
  765. $sUrl = $oStorage->getFileUrlById($a['id']);
  766. $aResults[] = array(
  767. 'id' => $a['id'],
  768. 'src' => $sPhotoSrc,
  769. 'src_medium' => $sPhotoSrc,
  770. 'src_orig' => $bImage ? $sUrl : '',
  771. 'url' => !$bImage ? $sUrl : ''
  772. );
  773. }
  774. return $aResults;
  775. }
  776. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  777. {
  778. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  779. if(!$this->_oConfig->isAttachmentsInTimeline())
  780. return $aResult;
  781. $CNF = &$this->_oConfig->CNF;
  782. $bDynamic = isset($aBrowseParams['dynamic_mode']) && (bool)$aBrowseParams['dynamic_mode'] === true;
  783. if(!empty($CNF['PARAM_POLL_ENABLED']) && $CNF['PARAM_POLL_ENABLED'] == true)
  784. $aPolls = $this->_oDb->getPolls(array('type' => 'content_id', 'content_id' => (int)$aContentInfo[$CNF['FIELD_ID']]));
  785. if(!empty($aPolls) && is_array($aPolls)) {
  786. $sInclude = $this->_oTemplate->addCss(array('polls.css'), $bDynamic);
  787. $aResult['raw'] = ($bDynamic ? $sInclude : '') . $this->_oTemplate->parseHtmlByName('poll_items_embed.html', array(
  788. 'embed_url' => BX_DOL_URL_ROOT . bx_append_url_params($this->_oConfig->getBaseUri() . 'embed_polls/', array(
  789. 'id' => (int)$aContentInfo[$CNF['FIELD_ID']],
  790. 'param_switch_menu' => 0,
  791. 'param_showcase' => 1
  792. ))
  793. ));
  794. /*
  795. if((!empty($aResult['videos']) && is_array($aResult['videos'])) || (!empty($aResult['videos_attach']) && is_array($aResult['videos_attach'])))
  796. $aResult['_cache'] = false;
  797. */
  798. }
  799. return $aResult;
  800. }
  801. protected function _buildRssParams($sMode, $aArgs)
  802. {
  803. $aParams = array ();
  804. $sMode = bx_process_input($sMode);
  805. switch ($sMode) {
  806. case 'author':
  807. $aParams = array('author' => isset($aArgs[0]) ? (int)$aArgs[0] : '');
  808. break;
  809. }
  810. return $aParams;
  811. }
  812. }
  813. /** @} */