BxBaseModTextModule.php 35 KB

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