BxBaseModTextModule.php 35 KB

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