BxForumModule.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  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 Forum Forum
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxForumModule extends BxBaseModTextModule
  12. {
  13. function __construct(&$aModule)
  14. {
  15. parent::__construct($aModule);
  16. }
  17. public function decodeDataApi ($aData, $bExtended = false)
  18. {
  19. $CNF = $this->_oConfig->CNF;
  20. $aResult = parent::decodeDataApi($aData, $bExtended);
  21. $oCategory = BxDolCategory::getObjectInstance($CNF['OBJECT_CATEGORY']);
  22. if(!$oCategory)
  23. return false;
  24. $aCategoryData = $this->_oDb->getCategories(['type' => 'by_category', 'category' => $aData[$CNF['FIELD_CATEGORY']]]);
  25. if(!empty($aCategoryData) &&is_array($aCategoryData))
  26. $aResult['category'] = [
  27. 'name' => $oCategory->getCategoryTitle($aData[$CNF['FIELD_CATEGORY']]),
  28. 'icon' => $aCategoryData['icon']
  29. ];
  30. return $aResult;
  31. }
  32. public function sortParticipants ($aParticipants, $iProfileIdLastComment, $iProfileIdAuthor, $iProfileIdCurrent = 0)
  33. {
  34. if (!$iProfileIdCurrent)
  35. $iProfileIdCurrent = bx_get_logged_profile_id();
  36. $aMoveUp = array($iProfileIdCurrent, $iProfileIdLastComment, $iProfileIdAuthor);
  37. asort($aParticipants, SORT_NUMERIC);
  38. foreach ($aMoveUp as $iProfileId) {
  39. if (!isset($aParticipants[$iProfileId]))
  40. continue;
  41. $a = array($iProfileId => $aParticipants[$iProfileId]);
  42. unset($aParticipants[$iProfileId]);
  43. $aParticipants = $a + $aParticipants;
  44. }
  45. return $aParticipants;
  46. }
  47. /**
  48. * Action methods
  49. */
  50. public function actionUpdateStatus($sAction = '', $iContentId = 0)
  51. {
  52. if(empty($sAction) && bx_get('action') !== false)
  53. $sAction = bx_process_input(bx_get('action'));
  54. if(empty($iContentId) && bx_get('id') !== false)
  55. $iContentId = (int)bx_get('id');
  56. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  57. if(empty($aContentInfo) || !is_array($aContentInfo))
  58. return echoJson(array('code' => 1, 'message' => _t('_bx_forum_err_not_found')));
  59. $sMethodCheck = 'checkAllowed' . bx_gen_method_name($sAction) . 'AnyEntry';
  60. $sResult = $this->$sMethodCheck($aContentInfo);
  61. if($sResult !== CHECK_ACTION_RESULT_ALLOWED)
  62. return echoJson(array('code' => 2, 'message' => $sResult));
  63. bx_audit(
  64. $iContentId,
  65. $this->getName(),
  66. '_sys_audit_action_' . $sAction,
  67. $this->_prepareAuditParams($aContentInfo, false)
  68. );
  69. if(!$this->_oDb->updateStatus($sAction, $aContentInfo))
  70. return echoJson(array('code' => 3, 'message' => _t('_error occured')));
  71. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  72. $this->alertAfterEdit($aContentInfo);
  73. echoJson(array('code' => 0, 'id' => $iContentId, 'reload' => 1));
  74. }
  75. public function actionAjaxGetAuthors()
  76. {
  77. $aResult = BxDolService::call('system', 'profiles_search', array(bx_get('term')), 'TemplServiceProfiles');
  78. header('Content-Type:text/javascript; charset=utf-8');
  79. echo json_encode($aResult);
  80. }
  81. /**
  82. * Service methods
  83. */
  84. public function serviceGetSafeServices()
  85. {
  86. $a = parent::serviceGetSafeServices();
  87. return array_merge($a, array (
  88. 'BrowseNew' => '',
  89. 'BrowseLatest' => '',
  90. 'BrowseTop' => '',
  91. 'BrowsePopular' => '',
  92. 'BrowseUpdated' => '',
  93. 'BrowsePartaken' => '',
  94. 'BrowseIndex' => '',
  95. 'Search' => '',
  96. ));
  97. }
  98. /**
  99. * @page service Service Calls
  100. * @section bx_forum Discussions
  101. * @subsection bx_forum-other Other
  102. * @subsubsection bx_forum-get_searchable_fields get_searchable_fields
  103. *
  104. * @code bx_srv('bx_forum', 'get_searchable_fields', [...]); @endcode
  105. *
  106. * Get searchable fields for Studio settings.
  107. *
  108. * @return an array with key-value pairs to be used in settings dropdown field.
  109. *
  110. * @see BxForumModule::serviceGetSearchableFields
  111. */
  112. /**
  113. * @ref bx_forum-get_searchable_fields "get_searchable_fields"
  114. */
  115. public function serviceGetSearchableFields ($aInputsAdd = array())
  116. {
  117. $CNF = &$this->_oConfig->CNF;
  118. $aResult = parent::serviceGetSearchableFields($aInputsAdd);
  119. $aResult[$CNF['FIELD_TEXT_COMMENTS']] = _t('_bx_forum_form_entry_input_text_comments');
  120. return $aResult;
  121. }
  122. /**
  123. * Service methods
  124. */
  125. /**
  126. * @page service Service Calls
  127. * @section bx_forum Discussions
  128. * @subsection bx_forum-other Other
  129. * @subsubsection bx_forum-get_info get_info
  130. *
  131. * @code bx_srv('bx_forum', 'get_info', [...]); @endcode
  132. *
  133. * Get content info by content ID. Is used in "Content Info Objects" system.
  134. *
  135. * @param $iContentId integer value with content ID.
  136. * @param $bSearchableFieldsOnly (optional) boolean value determining all info or "searchable fields" only will be returned.
  137. * @return an array with content info. Empty array is returned if something is wrong.
  138. *
  139. * @see BxForumModule::serviceGetInfo
  140. */
  141. /**
  142. * @ref bx_forum-get_info "get_info"
  143. */
  144. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  145. {
  146. $aContentInfo = $this->_getFields($iContentId);
  147. if(empty($aContentInfo))
  148. return array();
  149. return $aContentInfo;
  150. }
  151. /**
  152. * @page service Service Calls
  153. * @section bx_forum Discussions
  154. * @subsection bx_forum-page_blocks Page Blocks
  155. * @subsubsection bx_forum-browse_new browse_new
  156. *
  157. * @code bx_srv('bx_forum', 'browse_new', [...]); @endcode
  158. *
  159. * Get page block with a list of items ordered by newness and represented as table.
  160. *
  161. * @param $sUnitView (optional) string with unit view type.
  162. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  163. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  164. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  165. *
  166. * @see BxForumModule::serviceBrowseNew
  167. */
  168. /**
  169. * @ref bx_forum-browse_new "browse_new"
  170. */
  171. public function serviceBrowseNew ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = false)
  172. {
  173. $sType = 'new';
  174. if($sUnitView != 'table')
  175. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  176. return $this->_serviceBrowseTable(array(
  177. 'type' => $sType,
  178. 'empty_message' => $bEmptyMessage,
  179. 'ajax_paginate' => $bAjaxPaginate
  180. ), $bShowHeader);
  181. }
  182. /**
  183. * @page service Service Calls
  184. * @section bx_forum Discussions
  185. * @subsection bx_forum-page_blocks Page Blocks
  186. * @subsubsection bx_forum-browse_latest browse_latest
  187. *
  188. * @code bx_srv('bx_forum', 'browse_latest', [...]); @endcode
  189. *
  190. * Get page block with a list of items ordered by Recent Posts in them and represented as table.
  191. *
  192. * @param $sUnitView (optional) string with unit view type.
  193. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  194. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  195. * @param $bShowHeader (optional) boolean value determining whether a resulting table should have Header section or not.
  196. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  197. *
  198. * @see BxForumModule::serviceBrowseNew
  199. */
  200. /**
  201. * @ref bx_forum-browse_latest "browse_latest"
  202. */
  203. public function serviceBrowseLatest($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = true)
  204. {
  205. $sType = 'latest';
  206. if($sUnitView != 'table')
  207. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  208. return $this->_serviceBrowseTable(array(
  209. 'type' => $sType,
  210. 'empty_message' => $bEmptyMessage,
  211. 'ajax_paginate' => $bAjaxPaginate
  212. ), $bShowHeader);
  213. }
  214. /**
  215. * @page service Service Calls
  216. * @section bx_forum Discussions
  217. * @subsection bx_forum-page_blocks Page Blocks
  218. * @subsubsection bx_forum-browse_featured browse_featured
  219. *
  220. * @code bx_srv('bx_forum', 'browse_featured', [...]); @endcode
  221. *
  222. * Get page block with a list of featured items represented as table.
  223. *
  224. * @param $sUnitView (optional) string with unit view type.
  225. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  226. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  227. * @param $bShowHeader (optional) boolean value determining whether a resulting table should have Header section or not.
  228. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  229. *
  230. * @see BxForumModule::serviceBrowseFeatured
  231. */
  232. /**
  233. * @ref bx_forum-browse_featured "browse_featured"
  234. */
  235. public function serviceBrowseFeatured($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true, $bShowHeader = false)
  236. {
  237. $CNF = &$this->_oConfig->CNF;
  238. $sType = 'featured';
  239. if($sUnitView != 'table')
  240. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  241. return $this->_serviceBrowseTable(array(
  242. 'type' => $sType,
  243. 'empty_message' => $bEmptyMessage,
  244. 'ajax_paginate' => $bAjaxPaginate
  245. ), $bShowHeader);
  246. }
  247. /**
  248. * @page service Service Calls
  249. * @section bx_forum Discussions
  250. * @subsection bx_forum-page_blocks Page Blocks
  251. * @subsubsection bx_forum-browse_top browse_top
  252. *
  253. * @code bx_srv('bx_forum', 'browse_top', [...]); @endcode
  254. *
  255. * Get page block with a list of items ordered by a number of comments and represented as table.
  256. *
  257. * @param $sUnitView (optional) string with unit view type.
  258. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  259. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  260. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  261. *
  262. * @see BxForumModule::serviceBrowseTop
  263. */
  264. /**
  265. * @ref bx_forum-browse_top "browse_top"
  266. */
  267. public function serviceBrowseTop($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = true)
  268. {
  269. $sType = 'top';
  270. if($sUnitView != 'table')
  271. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  272. return $this->_serviceBrowseTable(array(
  273. 'type' => $sType,
  274. 'empty_message' => $bEmptyMessage,
  275. 'ajax_paginate' => $bAjaxPaginate
  276. ), $bShowHeader);
  277. }
  278. /**
  279. * @page service Service Calls
  280. * @section bx_forum Discussions
  281. * @subsection bx_forum-page_blocks Page Blocks
  282. * @subsubsection bx_forum-browse_popular browse_popular
  283. *
  284. * @code bx_srv('bx_forum', 'browse_popular', [...]); @endcode
  285. *
  286. * Get page block with a list of items ordered by a number of views and represented as table.
  287. *
  288. * @param $sUnitView (optional) string with unit view type.
  289. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  290. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  291. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  292. *
  293. * @see BxForumModule::serviceBrowsePopular
  294. */
  295. /**
  296. * @ref bx_forum-browse_popular "browse_popular"
  297. */
  298. public function serviceBrowsePopular ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = false)
  299. {
  300. $sType = 'popular';
  301. if($sUnitView != 'table')
  302. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  303. return $this->_serviceBrowseTable(array(
  304. 'type' => $sType,
  305. 'empty_message' => $bEmptyMessage,
  306. 'ajax_paginate' => $bAjaxPaginate
  307. ), $bShowHeader);
  308. }
  309. /**
  310. * @page service Service Calls
  311. * @section bx_forum Discussions
  312. * @subsection bx_forum-page_blocks Page Blocks
  313. * @subsubsection bx_forum-browse_updated browse_updated
  314. *
  315. * @code bx_srv('bx_forum', 'browse_updated', [...]); @endcode
  316. *
  317. * Get page block with a list of updated items represented as table.
  318. *
  319. * @param $sUnitView (optional) string with unit view type.
  320. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  321. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  322. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  323. *
  324. * @see BxForumModule::serviceBrowseUpdated
  325. */
  326. /**
  327. * @ref bx_forum-browse_updated "browse_updated"
  328. */
  329. public function serviceBrowseUpdated ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = false)
  330. {
  331. $sType = 'updated';
  332. if($sUnitView != 'table')
  333. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  334. return $this->_serviceBrowseTable(array(
  335. 'type' => $sType,
  336. 'empty_message' => $bEmptyMessage,
  337. 'ajax_paginate' => $bAjaxPaginate
  338. ), $bShowHeader);
  339. }
  340. /**
  341. * @page service Service Calls
  342. * @section bx_forum Discussions
  343. * @subsection bx_forum-page_blocks Page Blocks
  344. * @subsubsection bx_forum-browse_partaken browse_partaken
  345. *
  346. * @code bx_srv('bx_forum', 'browse_partaken', [...]); @endcode
  347. *
  348. * Get page block with a list of partaken items represented as table.
  349. *
  350. * @param $sUnitView (optional) string with unit view type.
  351. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  352. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  353. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  354. *
  355. * @see BxForumModule::serviceBrowsePartaken
  356. */
  357. /**
  358. * @ref bx_forum-browse_partaken "browse_partaken"
  359. */
  360. public function serviceBrowsePartaken ($iProfileId = 0, $aParams = [])
  361. {
  362. $sType = 'partaken';
  363. if(!$iProfileId)
  364. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  365. if(!$iProfileId)
  366. $iProfileId = bx_get_logged_profile_id();
  367. $bEmptyMessage = true;
  368. if(isset($aParams['empty_message'])) {
  369. $bEmptyMessage = (bool)$aParams['empty_message'];
  370. unset($aParams['empty_message']);
  371. }
  372. $bAjaxPaginate = true;
  373. if(isset($aParams['ajax_paginate'])) {
  374. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  375. unset($aParams['ajax_paginate']);
  376. }
  377. $bShowHeader = false;
  378. if(isset($aParams['show_header'])) {
  379. $bShowHeader = (bool)$aParams['show_header'];
  380. unset($aParams['show_header']);
  381. }
  382. if(isset($aParams['unit_view']) && $aParams['unit_view'] != 'table')
  383. return $this->_serviceBrowse($sType, array_merge(['author' => $iProfileId], $aParams), BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  384. return $this->_serviceBrowseTable([
  385. 'type' => $sType,
  386. 'author' => $iProfileId,
  387. 'include_contexts' => isset($aParams['include_contexts']) && $aParams['include_contexts'],
  388. 'empty_message' => $bEmptyMessage,
  389. 'ajax_paginate' => $bAjaxPaginate
  390. ], $bShowHeader);
  391. }
  392. /**
  393. * @page service Service Calls
  394. * @section bx_forum Discussions
  395. * @subsection bx_forum-page_blocks Page Blocks
  396. * @subsubsection bx_forum-browse_index browse_index
  397. *
  398. * @code bx_srv('bx_forum', 'browse_index', [...]); @endcode
  399. *
  400. * Get page block for Site's Home page with a list of items ordered by newness and represented as table.
  401. *
  402. * @param $sUnitView (optional) string with unit view type.
  403. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  404. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  405. * @param $bShowHeader (optional) boolean value determining whether a resulting table should have Header section or not.
  406. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  407. *
  408. * @see BxForumModule::serviceBrowseIndex
  409. */
  410. /**
  411. * @ref bx_forum-browse_index "browse_index"
  412. */
  413. public function serviceBrowseIndex($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = false)
  414. {
  415. $sType = 'index';
  416. if($sUnitView != 'table')
  417. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  418. return $this->_serviceBrowseTable(array(
  419. 'type' => $sType,
  420. 'per_page' => (int)$this->_oDb->getParam('bx_forum_per_page_index'),
  421. 'empty_message' => $bEmptyMessage,
  422. 'ajax_paginate' => $bAjaxPaginate
  423. ), $bShowHeader);
  424. }
  425. /**
  426. * @page service Service Calls
  427. * @section bx_forum Discussions
  428. * @subsection bx_forum-page_blocks Page Blocks
  429. * @subsubsection bx_forum-browse_author browse_author
  430. *
  431. * @code bx_srv('bx_forum', 'browse_author', [...]); @endcode
  432. *
  433. * Get page block with a list of items filtered by Author and represented as table.
  434. *
  435. * @param $iProfileId (optional) integer value with author ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  436. * @param $aParams (optional) an array of additional params. It's not used for now.
  437. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  438. *
  439. * @see BxForumModule::serviceBrowseAuthor
  440. */
  441. /**
  442. * @ref bx_forum-browse_author "browse_author"
  443. */
  444. public function serviceBrowseAuthor ($iProfileId = 0, $aParams = array())
  445. {
  446. if(!$iProfileId)
  447. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  448. if(!$iProfileId)
  449. return '';
  450. $bEmptyMessage = true;
  451. if(isset($aParams['empty_message'])) {
  452. $bEmptyMessage = (bool)$aParams['empty_message'];
  453. unset($aParams['empty_message']);
  454. }
  455. $bAjaxPaginate = true;
  456. if(isset($aParams['ajax_paginate'])) {
  457. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  458. unset($aParams['ajax_paginate']);
  459. }
  460. if(isset($aParams['unit_view']) && $aParams['unit_view'] != 'table')
  461. return $this->_serviceBrowse('author', array_merge(array('author' => $iProfileId), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  462. return $this->_serviceBrowseTable(array(
  463. 'type' => 'author',
  464. 'author' => $iProfileId,
  465. 'where' => array('fld' => 'author', 'val' => $iProfileId, 'opr' => '='),
  466. 'per_page' => (int)$this->_oDb->getParam('bx_forum_per_page_profile'),
  467. 'empty_message' => $bEmptyMessage,
  468. 'ajax_paginate' => $bAjaxPaginate
  469. ), false);
  470. }
  471. /**
  472. * @page service Service Calls
  473. * @section bx_forum Discussions
  474. * @subsection bx_forum-page_blocks Page Blocks
  475. * @subsubsection bx_forum-browse_category browse_category
  476. *
  477. * @code bx_srv('bx_forum', 'browse_category', [...]); @endcode
  478. *
  479. * Get page block with a list of items filter by some category and represented as table.
  480. *
  481. * @param $sUnitView (optional) string with unit view type.
  482. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  483. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  484. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  485. *
  486. * @see BxForumModule::serviceBrowseCategory
  487. */
  488. /**
  489. * @ref bx_forum-browse_category "browse_category"
  490. */
  491. public function serviceBrowseCategory($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $aParams = [])
  492. {
  493. if (bx_is_api()){
  494. return parent::serviceBrowseCategory($sUnitView, $bEmptyMessage, $bAjaxPaginate, []);
  495. }
  496. $sType = 'category';
  497. $iCategory = bx_process_input(bx_get('category'), BX_DATA_INT);
  498. $aCategory = $this->_oDb->getCategories(array('type' => 'by_category', 'category' => $iCategory));
  499. if(!empty($aCategory['visible_for_levels']) && !BxDolAcl::getInstance()->isMemberLevelInSet($aCategory['visible_for_levels']))
  500. return $bEmptyMessage ? MsgBox(_t('_sys_txt_access_denied')) : '';
  501. if($sUnitView != 'table') {
  502. $aParams = array_merge(['category' => $iCategory], $aParams);
  503. if($sUnitView)
  504. $aParams['unit_view'] = $sUnitView;
  505. return $this->_serviceBrowse($sType, $aParams, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  506. }
  507. return $this->_serviceBrowseTable(array(
  508. 'type' => $sType,
  509. 'where' => array('fld' => 'cat', 'val' => $iCategory, 'opr' => '='),
  510. 'empty_message' => $bEmptyMessage,
  511. 'ajax_paginate' => $bAjaxPaginate
  512. ), !isset($aParams['show_header']) || (bool)$aParams['show_header'] === true);
  513. }
  514. /**
  515. * @page service Service Calls
  516. * @section bx_forum Discussions
  517. * @subsection bx_forum-page_blocks Page Blocks
  518. * @subsubsection bx_forum-browse_keyword browse_keyword
  519. *
  520. * @code bx_srv('bx_forum', 'browse_keyword', [...]); @endcode
  521. *
  522. * Get page block with a list of items filter by some keyword and represented as table.
  523. *
  524. * @param $sUnitView (optional) string with unit view type.
  525. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  526. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  527. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  528. *
  529. * @see BxForumModule::serviceBrowseKeyword
  530. */
  531. /**
  532. * @ref bx_forum-browse_keyword "browse_keyword"
  533. */
  534. public function serviceBrowseKeyword($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = false)
  535. {
  536. $sType = 'keyword';
  537. $sKeyword = bx_process_input(bx_get('keyword'));
  538. if($sUnitView != 'table')
  539. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  540. return $this->_serviceBrowseTable(array(
  541. 'type' => $sType,
  542. 'where' => $this->_getSearchKeywordDescriptor('#' . $sKeyword),
  543. 'empty_message' => $bEmptyMessage,
  544. 'ajax_paginate' => $bAjaxPaginate
  545. ), $bShowHeader);
  546. }
  547. /**
  548. * @page service Service Calls
  549. * @section bx_forum Discussions
  550. * @subsection bx_forum-page_blocks Page Blocks
  551. * @subsubsection bx_forum-browse_search_results browse_search_results
  552. *
  553. * @code bx_srv('bx_forum', 'browse_search_results', [...]); @endcode
  554. *
  555. * Get page block with search results by Author(s), Category, Keyword represented as table.
  556. *
  557. * @param $sUnitView (optional) string with unit view type.
  558. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  559. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  560. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  561. *
  562. * @see BxForumModule::serviceBrowseSearchResults
  563. */
  564. /**
  565. * @ref bx_forum-browse_search_results "browse_search_results"
  566. */
  567. public function serviceBrowseSearchResults($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  568. {
  569. $sType = 'search';
  570. $aAuthors = bx_process_input(bx_get('author'));
  571. $iCategory = bx_process_input(bx_get('category'), BX_DATA_INT);
  572. $sKeyword = bx_process_input(bx_get('keyword'));
  573. $aCategory = $this->_oDb->getCategories(array('type' => 'by_category', 'category' => $iCategory));
  574. if(!empty($aCategory['visible_for_levels']) && !BxDolAcl::getInstance()->isMemberLevelInSet($aCategory['visible_for_levels']))
  575. return $bEmptyMessage ? MsgBox(_t('_sys_txt_access_denied')) : '';
  576. if($sUnitView != 'table')
  577. return $this->_serviceBrowse('', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  578. $aWhereGroupAnd = array('grp' => true, 'opr' => 'AND', 'cnds' => array());
  579. if(!empty($aAuthors) && is_array($aAuthors))
  580. $aWhereGroupAnd['cnds'][] = $this->_getSearchAuthorDescriptor($aAuthors);
  581. if(!empty($iCategory))
  582. $aWhereGroupAnd['cnds'][] = array('fld' => 'cat', 'val' => $iCategory, 'opr' => '=');
  583. if(!empty($sKeyword))
  584. $aWhereGroupAnd['cnds'][] = $this->_getSearchKeywordDescriptor($sKeyword);
  585. return $this->_serviceBrowseTable(array(
  586. 'type' => $sType,
  587. 'where' => $aWhereGroupAnd,
  588. 'empty_message' => $bEmptyMessage,
  589. 'ajax_paginate' => $bAjaxPaginate
  590. ), false);
  591. }
  592. /**
  593. * @page service Service Calls
  594. * @section bx_forum Discussions
  595. * @subsection bx_forum-other Other
  596. * @subsubsection bx_forum-get_discussions_num get_discussions_num
  597. *
  598. * @code bx_srv('bx_forum', 'get_discussions_num', [...]); @endcode
  599. *
  600. * Get number of discussions for some profile.
  601. *
  602. * @param $iProfileId (optional) profile to get discussions for, if omitted then currently logged in profile is used.
  603. * @return integer value with a number of discussions.
  604. *
  605. * @see BxForumModule::serviceGetDiscussionsNum
  606. */
  607. /**
  608. * @ref bx_forum-get_discussions_num "get_discussions_num"
  609. */
  610. public function serviceGetDiscussionsNum ($iProfileId = 0)
  611. {
  612. if (!$iProfileId)
  613. $iProfileId = bx_get_logged_profile_id();
  614. return $this->_oDb->getEntriesNumByAuthor((int)$iProfileId);
  615. }
  616. /**
  617. * @page service Service Calls
  618. * @section bx_forum Discussions
  619. * @subsection bx_forum-other Other
  620. * @subsubsection bx_forum-get_unreplied_discussions_num get_unreplied_discussions_num
  621. *
  622. * @code bx_srv('bx_forum', 'get_unreplied_discussions_num', [...]); @endcode
  623. *
  624. * Get number of unreplied discussions for some profile.
  625. *
  626. * @param $iProfileId (optional) profile to get unreplied discussions for, if omitted then currently logged is profile is used.
  627. * @return integer value with a number of discussions.
  628. *
  629. * @see BxForumModule::serviceGetUnrepliedDiscussionsNum
  630. */
  631. /**
  632. * @ref bx_forum-get_unreplied_discussions_num "get_unreplied_discussions_num"
  633. */
  634. public function serviceGetUnrepliedDiscussionsNum ($iProfileId = 0)
  635. {
  636. if (!$iProfileId)
  637. $iProfileId = bx_get_logged_profile_id();
  638. return $this->_oDb->getUnrepliedDiscussionsNum((int)$iProfileId);
  639. }
  640. /**
  641. *
  642. */
  643. /**
  644. * @page service Service Calls
  645. * @section bx_forum Discussions
  646. * @subsection bx_forum-other Other
  647. * @subsubsection bx_forum-trigger_comment_post trigger_comment_post
  648. *
  649. * @code bx_srv('bx_forum', 'trigger_comment_post', [...]); @endcode
  650. *
  651. * Update last comment time and author when new comment was added in the discussion.
  652. *
  653. * @param $iContentId integer value with content ID.
  654. * @param $iProfileId integer value with profile ID.
  655. * @param $iCommentId integer value with comment ID.
  656. * @param $iTimestamp (optional) date in UNIX Timestamp format, if omitted then current date is used.
  657. * @param $sCommentText (optional) string value with text of comment.
  658. * @return boolean value determining where the operation is successful or not.
  659. *
  660. * @see BxForumModule::serviceTriggerCommentPost
  661. */
  662. /**
  663. * @ref bx_forum-trigger_comment_post "trigger_comment_post"
  664. */
  665. public function serviceTriggerCommentPost ($iContentId, $iProfileId, $iCommentId, $iTimestamp = 0, $sCommentText = '')
  666. {
  667. $CNF = $this->_oConfig->CNF;
  668. $iContentId = (int)$iContentId;
  669. if(!$iContentId)
  670. return false;
  671. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  672. if(!$aContentInfo)
  673. return false;
  674. $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  675. if(!$oCmts)
  676. return false;
  677. if(!$iTimestamp)
  678. $iTimestamp = time();
  679. if(!$this->_oDb->updateLastCommentTimeProfile((int)$iContentId, (int)$iProfileId, $iCommentId, $iTimestamp))
  680. return false;
  681. // send notification to author
  682. if($iProfileId != $aContentInfo[$CNF['FIELD_AUTHOR']]) {
  683. $oProfile = BxDolProfile::getInstanceMagic($iProfileId);
  684. if($oProfile)
  685. sendMailTemplate('bx_forum_new_reply', 0, $aContentInfo[$CNF['FIELD_AUTHOR']], array(
  686. 'SenderDisplayName' => $oProfile->getDisplayName(),
  687. 'SenderUrl' => $oProfile->getUrl(),
  688. 'PageUrl' => $oCmts->getItemUrl($iCommentId),
  689. 'PageTitle' => $oCmts->getObjectTitle(),
  690. 'Message' => $sCommentText,
  691. ), BX_EMAIL_NOTIFY);
  692. }
  693. return true;
  694. }
  695. /**
  696. * @page service Service Calls
  697. * @section bx_forum Discussions
  698. * @subsection bx_forum-page_blocks Page Blocks
  699. * @subsubsection bx_forum-entity_author entity_author
  700. *
  701. * @code bx_srv('bx_forum', 'entity_author', [...]); @endcode
  702. *
  703. * Get page block with author.
  704. *
  705. * @param $iContentId (optional) content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  706. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  707. *
  708. * @see BxForumModule::serviceEntityAuthor
  709. */
  710. /**
  711. * @ref bx_forum-entity_author "entity_author"
  712. */
  713. public function serviceEntityAuthor ($iContentId = 0)
  714. {
  715. if (bx_is_api())
  716. return $this->_serviceTemplateFunc ('entryAuthor', $iContentId);
  717. return bx_srv('system', 'get_block_author', ['bx_forum', $iContentId], 'TemplServices');
  718. }
  719. /**
  720. * @page service Service Calls
  721. * @section bx_forum Discussions
  722. * @subsection bx_forum-page_blocks Page Blocks
  723. * @subsubsection bx_forum-entity_participants entity_participants
  724. *
  725. * @code bx_srv('bx_forum', 'entity_participants', [...]); @endcode
  726. *
  727. * Get page block with discussion's collaborators.
  728. *
  729. * @param $iContentId (optional) content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  730. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  731. *
  732. * @see BxForumModule::serviceEntityParticipants
  733. */
  734. /**
  735. * @ref bx_forum-entity_participants "entity_participants"
  736. */
  737. public function serviceEntityParticipants ($iContentId = 0)
  738. {
  739. if (!$iContentId)
  740. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  741. if (!$iContentId)
  742. return false;
  743. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  744. if (!$aContentInfo)
  745. return false;
  746. return $this->_oTemplate->entryParticipants ($aContentInfo, 5, 'right');
  747. }
  748. /**
  749. * @page service Service Calls
  750. * @section bx_forum Discussions
  751. * @subsection bx_forum-page_blocks Page Blocks
  752. * @subsubsection bx_forum-search search
  753. *
  754. * @code bx_srv('bx_forum', 'search', [...]); @endcode
  755. *
  756. * Get page block with search form.
  757. *
  758. * @return HTML string with block content to display on the site or false if something is wrong. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  759. *
  760. * @see BxForumModule::serviceSearch
  761. */
  762. /**
  763. * @ref bx_forum-search "search"
  764. */
  765. public function serviceSearch()
  766. {
  767. $CNF = $this->_oConfig->CNF;
  768. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_SEARCH'], $CNF['OBJECT_FORM_SEARCH_DISPLAY_FULL'], $this->_oTemplate);
  769. $oForm->initChecker();
  770. return $oForm->getCode();
  771. }
  772. public function checkAllowedSubscribe(&$aDataEntry, $isPerformAction = false)
  773. {
  774. $CNF = &$this->_oConfig->CNF;
  775. $sMsg = $this->checkAllowedView($aDataEntry);
  776. if($sMsg !== CHECK_ACTION_RESULT_ALLOWED)
  777. return $sMsg;
  778. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $CNF['OBJECT_CONNECTION_SUBSCRIBERS'], false, false);
  779. }
  780. public function checkAllowedUnsubscribe(&$aDataEntry, $isPerformAction = false)
  781. {
  782. $CNF = &$this->_oConfig->CNF;
  783. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $CNF['OBJECT_CONNECTION_SUBSCRIBERS'], false, true);
  784. }
  785. public function checkAllowedStickAnyEntry($aDataEntry, $isPerformAction = false)
  786. {
  787. $CNF = &$this->_oConfig->CNF;
  788. if((int)$aDataEntry[$CNF['FIELD_STICK']] != 0)
  789. return false;
  790. return $this->_checkAllowedAction('stick any entry', $aDataEntry, $isPerformAction);
  791. }
  792. public function checkAllowedUnstickAnyEntry($aDataEntry, $isPerformAction = false)
  793. {
  794. $CNF = $this->_oConfig->CNF;
  795. if((int)$aDataEntry[$CNF['FIELD_STICK']] != 1)
  796. return false;
  797. return $this->_checkAllowedAction('stick any entry', $aDataEntry, $isPerformAction);
  798. }
  799. public function checkAllowedResolveAnyEntry($aDataEntry, $isPerformAction = false)
  800. {
  801. $CNF = &$this->_oConfig->CNF;
  802. if((int)$aDataEntry[$CNF['FIELD_RESOLVABLE']] != 1 || (int)$aDataEntry[$CNF['FIELD_RESOLVE']] != 0)
  803. return false;
  804. if($aDataEntry[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id())
  805. return CHECK_ACTION_RESULT_ALLOWED;
  806. return $this->_checkAllowedAction('resolve any entry', $aDataEntry, $isPerformAction);
  807. }
  808. public function checkAllowedUnresolveAnyEntry($aDataEntry, $isPerformAction = false)
  809. {
  810. $CNF = $this->_oConfig->CNF;
  811. if((int)$aDataEntry[$CNF['FIELD_RESOLVABLE']] != 1 || (int)$aDataEntry[$CNF['FIELD_RESOLVE']] != 1)
  812. return false;
  813. if($aDataEntry[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id())
  814. return CHECK_ACTION_RESULT_ALLOWED;
  815. return $this->_checkAllowedAction('resolve any entry', $aDataEntry, $isPerformAction);
  816. }
  817. public function checkAllowedLockAnyEntry($aDataEntry, $isPerformAction = false)
  818. {
  819. $CNF = $this->_oConfig->CNF;
  820. if((int)$aDataEntry[$CNF['FIELD_LOCK']] != 0)
  821. return false;
  822. return $this->_checkAllowedAction('lock any entry', $aDataEntry, $isPerformAction);
  823. }
  824. public function checkAllowedUnlockAnyEntry($aDataEntry, $isPerformAction = false)
  825. {
  826. $CNF = $this->_oConfig->CNF;
  827. if((int)$aDataEntry[$CNF['FIELD_LOCK']] != 1)
  828. return false;
  829. return $this->_checkAllowedAction('lock any entry', $aDataEntry, $isPerformAction);
  830. }
  831. public function checkAllowedHideAnyEntry($aDataEntry, $isPerformAction = false)
  832. {
  833. $CNF = $this->_oConfig->CNF;
  834. if($aDataEntry[$CNF['FIELD_STATUS_ADMIN']] == 'hidden')
  835. return false;
  836. return $this->_checkAllowedAction('hide any entry', $aDataEntry, $isPerformAction);
  837. }
  838. public function checkAllowedUnhideAnyEntry($aDataEntry, $isPerformAction = false)
  839. {
  840. $CNF = &$this->_oConfig->CNF;
  841. if($aDataEntry[$CNF['FIELD_STATUS_ADMIN']] != 'hidden')
  842. return false;
  843. return $this->_checkAllowedAction('hide any entry', $aDataEntry, $isPerformAction);
  844. }
  845. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult)
  846. {
  847. $CNF = &$this->_oConfig->CNF;
  848. if(!$this->_iProfileId)
  849. return _t('_sys_txt_access_denied');
  850. $isConnected = BxDolConnection::getObjectInstance($sObjConnection)->isConnected($this->_iProfileId, $aDataEntry[$CNF['FIELD_ID']], $isMutual);
  851. if($isInvertResult)
  852. $isConnected = !$isConnected;
  853. return $isConnected ? _t('_sys_txt_access_denied') : CHECK_ACTION_RESULT_ALLOWED;
  854. }
  855. /**
  856. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  857. */
  858. protected function _checkAllowedAction($sAction, $aDataEntry, $isPerformAction = false)
  859. {
  860. if($this->_isModerator($isPerformAction))
  861. return CHECK_ACTION_RESULT_ALLOWED;
  862. $aCheck = checkActionModule($this->_iProfileId, $sAction, $this->getName(), $isPerformAction);
  863. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  864. return CHECK_ACTION_RESULT_ALLOWED;
  865. return _t('_sys_txt_access_denied');
  866. }
  867. protected function _serviceBrowseTable($aParams, $isDisplayHeader = true)
  868. {
  869. $sGrid = $this->_oConfig->CNF['OBJECT_GRID'];
  870. if(!empty($aParams['grid'])) {
  871. $sGrid = $aParams['grid'];
  872. unset($aParams['grid']);
  873. }
  874. $oGrid = BxDolGrid::getObjectInstance($sGrid);
  875. if(!$oGrid)
  876. return false;
  877. $oGrid->setBrowseParams($aParams);
  878. $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
  879. $this->_oTemplate->addCss(array('grid_tools.css'));
  880. return $oGrid->getCode($isDisplayHeader);
  881. }
  882. protected function _getSearchAuthorDescriptor($aAutor)
  883. {
  884. return array('grp' => true, 'opr' => 'OR', 'cnds' => array(
  885. array('fld' => 'author', 'val' => $aAutor, 'opr' => 'IN'),
  886. array('fld' => 'author_comment', 'val' => $aAutor, 'opr' => 'IN'),
  887. ));
  888. }
  889. protected function _getSearchKeywordDescriptor($sKeyword)
  890. {
  891. return array('grp' => true, 'opr' => 'OR', 'cnds' => array(
  892. array('fld' => 'title', 'val' => $sKeyword, 'opr' => 'LIKE'),
  893. array('fld' => 'text', 'val' => $sKeyword, 'opr' => 'LIKE'),
  894. array('fld' => 'text_comments', 'val' => $sKeyword, 'opr' => 'LIKE')
  895. ));
  896. }
  897. }
  898. /** @} */