BxForumModule.php 42 KB

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