BxForumModule.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  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 = false)
  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. 'grid' => $CNF['OBJECT_GRID_FEATURE'],
  228. 'type' => $sType,
  229. 'where' => array('fld' => 'featured', 'val' => 0, 'opr' => '<>'),
  230. 'empty_message' => $bEmptyMessage,
  231. 'ajax_paginate' => $bAjaxPaginate
  232. ), $bShowHeader);
  233. }
  234. /**
  235. * @page service Service Calls
  236. * @section bx_forum Discussions
  237. * @subsection bx_forum-page_blocks Page Blocks
  238. * @subsubsection bx_forum-browse_top browse_top
  239. *
  240. * @code bx_srv('bx_forum', 'browse_top', [...]); @endcode
  241. *
  242. * Get page block with a list of items ordered by a number of comments and represented as table.
  243. *
  244. * @param $sUnitView (optional) string with unit view type.
  245. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  246. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  247. * @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.
  248. *
  249. * @see BxForumModule::serviceBrowseTop
  250. */
  251. /**
  252. * @ref bx_forum-browse_top "browse_top"
  253. */
  254. public function serviceBrowseTop($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = false)
  255. {
  256. $sType = 'top';
  257. if($sUnitView != 'table')
  258. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  259. return $this->_serviceBrowseTable(array(
  260. 'type' => $sType,
  261. 'empty_message' => $bEmptyMessage,
  262. 'ajax_paginate' => $bAjaxPaginate
  263. ), $bShowHeader);
  264. }
  265. /**
  266. * @page service Service Calls
  267. * @section bx_forum Discussions
  268. * @subsection bx_forum-page_blocks Page Blocks
  269. * @subsubsection bx_forum-browse_popular browse_popular
  270. *
  271. * @code bx_srv('bx_forum', 'browse_popular', [...]); @endcode
  272. *
  273. * Get page block with a list of items ordered by a number of views and represented as table.
  274. *
  275. * @param $sUnitView (optional) string with unit view type.
  276. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  277. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  278. * @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.
  279. *
  280. * @see BxForumModule::serviceBrowsePopular
  281. */
  282. /**
  283. * @ref bx_forum-browse_popular "browse_popular"
  284. */
  285. public function serviceBrowsePopular ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = false)
  286. {
  287. $sType = 'popular';
  288. if($sUnitView != 'table')
  289. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  290. return $this->_serviceBrowseTable(array(
  291. 'type' => $sType,
  292. 'empty_message' => $bEmptyMessage,
  293. 'ajax_paginate' => $bAjaxPaginate
  294. ), $bShowHeader);
  295. }
  296. /**
  297. * @page service Service Calls
  298. * @section bx_forum Discussions
  299. * @subsection bx_forum-page_blocks Page Blocks
  300. * @subsubsection bx_forum-browse_updated browse_updated
  301. *
  302. * @code bx_srv('bx_forum', 'browse_updated', [...]); @endcode
  303. *
  304. * Get page block with a list of updated items represented as table.
  305. *
  306. * @param $sUnitView (optional) string with unit view type.
  307. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  308. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  309. * @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.
  310. *
  311. * @see BxForumModule::serviceBrowseUpdated
  312. */
  313. /**
  314. * @ref bx_forum-browse_updated "browse_updated"
  315. */
  316. public function serviceBrowseUpdated ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = false)
  317. {
  318. $sType = 'updated';
  319. if($sUnitView != 'table')
  320. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  321. return $this->_serviceBrowseTable(array(
  322. 'type' => $sType,
  323. 'empty_message' => $bEmptyMessage,
  324. 'ajax_paginate' => $bAjaxPaginate
  325. ), $bShowHeader);
  326. }
  327. /**
  328. * @page service Service Calls
  329. * @section bx_forum Discussions
  330. * @subsection bx_forum-page_blocks Page Blocks
  331. * @subsubsection bx_forum-browse_partaken browse_partaken
  332. *
  333. * @code bx_srv('bx_forum', 'browse_partaken', [...]); @endcode
  334. *
  335. * Get page block with a list of partaken items represented as table.
  336. *
  337. * @param $sUnitView (optional) string with unit view type.
  338. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  339. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  340. * @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.
  341. *
  342. * @see BxForumModule::serviceBrowsePartaken
  343. */
  344. /**
  345. * @ref bx_forum-browse_partaken "browse_partaken"
  346. */
  347. public function serviceBrowsePartaken ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = false)
  348. {
  349. $sType = 'partaken';
  350. if($sUnitView != 'table')
  351. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  352. $aSelect = array(
  353. 'tbla' => 'tco',
  354. 'fld' => 'cmt_author_id',
  355. );
  356. $aJoin = array(
  357. 'tp' => 'INNER',
  358. 'tbl1' => 'bx_forum_cmts',
  359. 'tbl1a' => 'tco',
  360. 'fld1' => 'cmt_object_id',
  361. 'tbl2' => 'bx_forum_discussions',
  362. 'fld2' => 'id'
  363. );
  364. $aWhere = array(
  365. 'tbl' => 'tco',
  366. 'fld' => 'cmt_author_id',
  367. 'val' => bx_get_logged_profile_id(),
  368. 'opr' => '='
  369. );
  370. $aGroupBy = array(
  371. 'tbl' => 'bx_forum_discussions',
  372. 'fld' => 'id',
  373. );
  374. return $this->_serviceBrowseTable(array(
  375. 'type' => $sType,
  376. 'select' => $aSelect,
  377. 'join' => $aJoin,
  378. 'where' => $aWhere,
  379. 'group_by' => $aGroupBy,
  380. 'empty_message' => $bEmptyMessage,
  381. 'ajax_paginate' => $bAjaxPaginate
  382. ), $bShowHeader);
  383. }
  384. /**
  385. * @page service Service Calls
  386. * @section bx_forum Discussions
  387. * @subsection bx_forum-page_blocks Page Blocks
  388. * @subsubsection bx_forum-browse_index browse_index
  389. *
  390. * @code bx_srv('bx_forum', 'browse_index', [...]); @endcode
  391. *
  392. * Get page block for Site's Home page with a list of items ordered by newness and represented as table.
  393. *
  394. * @param $sUnitView (optional) string with unit view type.
  395. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  396. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  397. * @param $bShowHeader (optional) boolean value determining whether a resulting table should have Header section or not.
  398. * @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.
  399. *
  400. * @see BxForumModule::serviceBrowseIndex
  401. */
  402. /**
  403. * @ref bx_forum-browse_index "browse_index"
  404. */
  405. public function serviceBrowseIndex($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = false)
  406. {
  407. $sType = 'index';
  408. if($sUnitView != 'table')
  409. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  410. return $this->_serviceBrowseTable(array(
  411. 'type' => $sType,
  412. 'per_page' => (int)$this->_oDb->getParam('bx_forum_per_page_index'),
  413. 'empty_message' => $bEmptyMessage,
  414. 'ajax_paginate' => $bAjaxPaginate
  415. ), $bShowHeader);
  416. }
  417. /**
  418. * @page service Service Calls
  419. * @section bx_forum Discussions
  420. * @subsection bx_forum-page_blocks Page Blocks
  421. * @subsubsection bx_forum-browse_author browse_author
  422. *
  423. * @code bx_srv('bx_forum', 'browse_author', [...]); @endcode
  424. *
  425. * Get page block with a list of items filtered by Author and represented as table.
  426. *
  427. * @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.
  428. * @param $aParams (optional) an array of additional params. It's not used for now.
  429. * @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.
  430. *
  431. * @see BxForumModule::serviceBrowseAuthor
  432. */
  433. /**
  434. * @ref bx_forum-browse_author "browse_author"
  435. */
  436. public function serviceBrowseAuthor ($iProfileId = 0, $aParams = array())
  437. {
  438. if(!$iProfileId)
  439. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  440. if(!$iProfileId)
  441. return '';
  442. $bEmptyMessage = true;
  443. if(isset($aParams['empty_message'])) {
  444. $bEmptyMessage = (bool)$aParams['empty_message'];
  445. unset($aParams['empty_message']);
  446. }
  447. $bAjaxPaginate = true;
  448. if(isset($aParams['ajax_paginate'])) {
  449. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  450. unset($aParams['ajax_paginate']);
  451. }
  452. return $this->_serviceBrowseTable(array(
  453. 'type' => 'author',
  454. 'author' => $iProfileId,
  455. 'where' => array('fld' => 'author', 'val' => $iProfileId, 'opr' => '='),
  456. 'per_page' => (int)$this->_oDb->getParam('bx_forum_per_page_profile'),
  457. 'empty_message' => $bEmptyMessage,
  458. 'ajax_paginate' => $bAjaxPaginate
  459. ), false);
  460. }
  461. /**
  462. * @page service Service Calls
  463. * @section bx_forum Discussions
  464. * @subsection bx_forum-page_blocks Page Blocks
  465. * @subsubsection bx_forum-browse_favorite browse_favorite
  466. *
  467. * @code bx_srv('bx_forum', 'browse_favorite', [...]); @endcode
  468. *
  469. * Get page block with a list of favorited items by some profile and represented as table.
  470. *
  471. * @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.
  472. * @param $aParams (optional) an array of additional params. It's not used for now.
  473. * @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.
  474. *
  475. * @see BxForumModule::serviceBrowseFavorite
  476. */
  477. /**
  478. * @ref bx_forum-browse_favorite "browse_favorite"
  479. */
  480. public function serviceBrowseFavorite ($iProfileId = 0, $aParams = array())
  481. {
  482. $CNF = &$this->_oConfig->CNF;
  483. $oProfile = null;
  484. if((int)$iProfileId)
  485. $oProfile = BxDolProfile::getInstance($iProfileId);
  486. if(!$oProfile && bx_get('profile_id') !== false)
  487. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  488. if(!$oProfile)
  489. $oProfile = BxDolProfile::getInstance();
  490. if(!$oProfile)
  491. return '';
  492. $iProfileAuthor = $oProfile->id();
  493. $oFavorite = $this->getObjectFavorite();
  494. if(!$oFavorite->isPublic() && $iProfileAuthor != bx_get_logged_profile_id())
  495. return '';
  496. $bEmptyMessage = false;
  497. if(isset($aParams['empty_message'])) {
  498. $bEmptyMessage = (bool)$aParams['empty_message'];
  499. unset($aParams['empty_message']);
  500. }
  501. $bAjaxPaginate = true;
  502. if(isset($aParams['ajax_paginate'])) {
  503. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  504. unset($aParams['ajax_paginate']);
  505. }
  506. $aConditions = $oFavorite->getConditionsTrack($CNF['TABLE_ENTRIES'], 'id', $iProfileAuthor);
  507. if(empty($aConditions) || !is_array($aConditions))
  508. return '';
  509. $aJoinGroup = array('grp' => true, 'cnds' => array());
  510. if(!empty($aConditions['join']))
  511. foreach($aConditions['join'] as $aCondition)
  512. $aJoinGroup['cnds'][] = array(
  513. 'tp' => $aCondition['type'],
  514. 'tbl1' => $aCondition['table'],
  515. 'fld1' => $aCondition['onField'],
  516. 'tbl2' => $aCondition['mainTable'],
  517. 'fld2' => $aCondition['mainField']
  518. );
  519. $aWhereGroup = array('grp' => true, 'opr' => 'AND', 'cnds' => array());
  520. if(!empty($aConditions['restriction']))
  521. foreach($aConditions['restriction'] as $aCondition)
  522. $aWhereGroup['cnds'][] = array(
  523. 'tbl' => (!empty($aCondition['table']) ? $aCondition['table'] : ''),
  524. 'fld' => $aCondition['field'],
  525. 'val' => $aCondition['value'],
  526. 'opr' => $aCondition['operator']
  527. );
  528. return $this->_serviceBrowseTable(array(
  529. 'grid' => $CNF['OBJECT_GRID_FAVORITE'],
  530. 'type' => 'favorite',
  531. 'author' => $iProfileId,
  532. 'join' => $aJoinGroup,
  533. 'where' => $aWhereGroup,
  534. 'per_page' => (int)$this->_oDb->getParam('bx_forum_per_page_profile'),
  535. 'empty_message' => $bEmptyMessage,
  536. 'ajax_paginate' => $bAjaxPaginate
  537. ), false);
  538. }
  539. /**
  540. * @page service Service Calls
  541. * @section bx_forum Discussions
  542. * @subsection bx_forum-page_blocks Page Blocks
  543. * @subsubsection bx_forum-browse_category browse_category
  544. *
  545. * @code bx_srv('bx_forum', 'browse_category', [...]); @endcode
  546. *
  547. * Get page block with a list of items filter by some category and represented as table.
  548. *
  549. * @param $sUnitView (optional) string with unit view type.
  550. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  551. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  552. * @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.
  553. *
  554. * @see BxForumModule::serviceBrowseCategory
  555. */
  556. /**
  557. * @ref bx_forum-browse_category "browse_category"
  558. */
  559. public function serviceBrowseCategory($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = false)
  560. {
  561. $sType = 'category';
  562. $iCategory = bx_process_input(bx_get('category'), BX_DATA_INT);
  563. $aCategory = $this->_oDb->getCategories(array('type' => 'by_category', 'category' => $iCategory));
  564. if(!empty($aCategory['visible_for_levels']) && !BxDolAcl::getInstance()->isMemberLevelInSet($aCategory['visible_for_levels']))
  565. return $bEmptyMessage ? MsgBox(_t('_sys_txt_access_denied')) : '';
  566. if($sUnitView != 'table')
  567. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  568. return $this->_serviceBrowseTable(array(
  569. 'type' => $sType,
  570. 'where' => array('fld' => 'cat', 'val' => $iCategory, 'opr' => '='),
  571. 'empty_message' => $bEmptyMessage,
  572. 'ajax_paginate' => $bAjaxPaginate
  573. ), $bShowHeader);
  574. }
  575. /**
  576. * @page service Service Calls
  577. * @section bx_forum Discussions
  578. * @subsection bx_forum-page_blocks Page Blocks
  579. * @subsubsection bx_forum-browse_keyword browse_keyword
  580. *
  581. * @code bx_srv('bx_forum', 'browse_keyword', [...]); @endcode
  582. *
  583. * Get page block with a list of items filter by some keyword and represented as table.
  584. *
  585. * @param $sUnitView (optional) string with unit view type.
  586. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  587. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  588. * @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.
  589. *
  590. * @see BxForumModule::serviceBrowseKeyword
  591. */
  592. /**
  593. * @ref bx_forum-browse_keyword "browse_keyword"
  594. */
  595. public function serviceBrowseKeyword($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true, $bShowHeader = false)
  596. {
  597. $sType = 'keyword';
  598. $sKeyword = bx_process_input(bx_get('keyword'));
  599. if($sUnitView != 'table')
  600. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  601. return $this->_serviceBrowseTable(array(
  602. 'type' => $sType,
  603. 'where' => $this->_getSearchKeywordDescriptor('#' . $sKeyword),
  604. 'empty_message' => $bEmptyMessage,
  605. 'ajax_paginate' => $bAjaxPaginate
  606. ), $bShowHeader);
  607. }
  608. /**
  609. * @page service Service Calls
  610. * @section bx_forum Discussions
  611. * @subsection bx_forum-page_blocks Page Blocks
  612. * @subsubsection bx_forum-browse_search_results browse_search_results
  613. *
  614. * @code bx_srv('bx_forum', 'browse_search_results', [...]); @endcode
  615. *
  616. * Get page block with search results by Author(s), Category, Keyword represented as table.
  617. *
  618. * @param $sUnitView (optional) string with unit view type.
  619. * @param $bEmptyMessage (optional) boolean value determining whether an "Empty" message should be returned or not.
  620. * @param $bAjaxPaginate (optional) boolean value determining whether an Ajax based pagination should be used or not.
  621. * @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.
  622. *
  623. * @see BxForumModule::serviceBrowseSearchResults
  624. */
  625. /**
  626. * @ref bx_forum-browse_search_results "browse_search_results"
  627. */
  628. public function serviceBrowseSearchResults($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  629. {
  630. $sType = 'search';
  631. $aAuthors = bx_process_input(bx_get('author'));
  632. $iCategory = bx_process_input(bx_get('category'), BX_DATA_INT);
  633. $sKeyword = bx_process_input(bx_get('keyword'));
  634. $aCategory = $this->_oDb->getCategories(array('type' => 'by_category', 'category' => $iCategory));
  635. if(!empty($aCategory['visible_for_levels']) && !BxDolAcl::getInstance()->isMemberLevelInSet($aCategory['visible_for_levels']))
  636. return $bEmptyMessage ? MsgBox(_t('_sys_txt_access_denied')) : '';
  637. if($sUnitView != 'table')
  638. return $this->_serviceBrowse('', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  639. $aWhereGroupAnd = array('grp' => true, 'opr' => 'AND', 'cnds' => array());
  640. if(!empty($aAuthors) && is_array($aAuthors))
  641. $aWhereGroupAnd['cnds'][] = $this->_getSearchAuthorDescriptor($aAuthors);
  642. if(!empty($iCategory))
  643. $aWhereGroupAnd['cnds'][] = array('fld' => 'cat', 'val' => $iCategory, 'opr' => '=');
  644. if(!empty($sKeyword))
  645. $aWhereGroupAnd['cnds'][] = $this->_getSearchKeywordDescriptor($sKeyword);
  646. return $this->_serviceBrowseTable(array(
  647. 'type' => $sType,
  648. 'where' => $aWhereGroupAnd,
  649. 'empty_message' => $bEmptyMessage,
  650. 'ajax_paginate' => $bAjaxPaginate
  651. ), false);
  652. }
  653. /**
  654. * @page service Service Calls
  655. * @section bx_forum Discussions
  656. * @subsection bx_forum-other Other
  657. * @subsubsection bx_forum-get_discussions_num get_discussions_num
  658. *
  659. * @code bx_srv('bx_forum', 'get_discussions_num', [...]); @endcode
  660. *
  661. * Get number of discussions for some profile.
  662. *
  663. * @param $iProfileId (optional) profile to get discussions for, if omitted then currently logged in profile is used.
  664. * @return integer value with a number of discussions.
  665. *
  666. * @see BxForumModule::serviceGetDiscussionsNum
  667. */
  668. /**
  669. * @ref bx_forum-get_discussions_num "get_discussions_num"
  670. */
  671. public function serviceGetDiscussionsNum ($iProfileId = 0)
  672. {
  673. if (!$iProfileId)
  674. $iProfileId = bx_get_logged_profile_id();
  675. return $this->_oDb->getEntriesNumByAuthor((int)$iProfileId);
  676. }
  677. /**
  678. * @page service Service Calls
  679. * @section bx_forum Discussions
  680. * @subsection bx_forum-other Other
  681. * @subsubsection bx_forum-get_unreplied_discussions_num get_unreplied_discussions_num
  682. *
  683. * @code bx_srv('bx_forum', 'get_unreplied_discussions_num', [...]); @endcode
  684. *
  685. * Get number of unreplied discussions for some profile.
  686. *
  687. * @param $iProfileId (optional) profile to get unreplied discussions for, if omitted then currently logged is profile is used.
  688. * @return integer value with a number of discussions.
  689. *
  690. * @see BxForumModule::serviceGetUnrepliedDiscussionsNum
  691. */
  692. /**
  693. * @ref bx_forum-get_unreplied_discussions_num "get_unreplied_discussions_num"
  694. */
  695. public function serviceGetUnrepliedDiscussionsNum ($iProfileId = 0)
  696. {
  697. if (!$iProfileId)
  698. $iProfileId = bx_get_logged_profile_id();
  699. return $this->_oDb->getUnrepliedDiscussionsNum((int)$iProfileId);
  700. }
  701. /**
  702. *
  703. */
  704. /**
  705. * @page service Service Calls
  706. * @section bx_forum Discussions
  707. * @subsection bx_forum-other Other
  708. * @subsubsection bx_forum-trigger_comment_post trigger_comment_post
  709. *
  710. * @code bx_srv('bx_forum', 'trigger_comment_post', [...]); @endcode
  711. *
  712. * Update last comment time and author when new comment was added in the discussion.
  713. *
  714. * @param $iContentId integer value with content ID.
  715. * @param $iProfileId integer value with profile ID.
  716. * @param $iCommentId integer value with comment ID.
  717. * @param $iTimestamp (optional) date in UNIX Timestamp format, if omitted then current date is used.
  718. * @param $sCommentText (optional) string value with text of comment.
  719. * @return boolean value determining where the operation is successful or not.
  720. *
  721. * @see BxForumModule::serviceTriggerCommentPost
  722. */
  723. /**
  724. * @ref bx_forum-trigger_comment_post "trigger_comment_post"
  725. */
  726. public function serviceTriggerCommentPost ($iContentId, $iProfileId, $iCommentId, $iTimestamp = 0, $sCommentText = '')
  727. {
  728. $CNF = $this->_oConfig->CNF;
  729. $iContentId = (int)$iContentId;
  730. if(!$iContentId)
  731. return false;
  732. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  733. if(!$aContentInfo)
  734. return false;
  735. $oCmts = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  736. if(!$oCmts)
  737. return false;
  738. if(!$iTimestamp)
  739. $iTimestamp = time();
  740. if(!$this->_oDb->updateLastCommentTimeProfile((int)$iContentId, (int)$iProfileId, $iCommentId, $iTimestamp))
  741. return false;
  742. // send notification to author
  743. if($iProfileId != $aContentInfo[$CNF['FIELD_AUTHOR']]) {
  744. $oProfile = BxDolProfile::getInstanceMagic($iProfileId);
  745. if($oProfile)
  746. sendMailTemplate('bx_forum_new_reply', 0, $aContentInfo[$CNF['FIELD_AUTHOR']], array(
  747. 'SenderDisplayName' => $oProfile->getDisplayName(),
  748. 'SenderUrl' => $oProfile->getUrl(),
  749. 'PageUrl' => $oCmts->getItemUrl($iCommentId),
  750. 'PageTitle' => $oCmts->getObjectTitle(),
  751. 'Message' => $sCommentText,
  752. ), BX_EMAIL_NOTIFY);
  753. }
  754. return true;
  755. }
  756. /**
  757. * @page service Service Calls
  758. * @section bx_forum Discussions
  759. * @subsection bx_forum-page_blocks Page Blocks
  760. * @subsubsection bx_forum-entity_participants entity_participants
  761. *
  762. * @code bx_srv('bx_forum', 'entity_participants', [...]); @endcode
  763. *
  764. * Get page block with discussion's collaborators.
  765. *
  766. * @param $iContentId (optional) content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  767. * @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.
  768. *
  769. * @see BxForumModule::serviceEntityParticipants
  770. */
  771. /**
  772. * @ref bx_forum-entity_participants "entity_participants"
  773. */
  774. public function serviceEntityParticipants ($iContentId = 0)
  775. {
  776. if (!$iContentId)
  777. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  778. if (!$iContentId)
  779. return false;
  780. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  781. if (!$aContentInfo)
  782. return false;
  783. return $this->_oTemplate->entryParticipants ($aContentInfo, 5, 'right');
  784. }
  785. /**
  786. * @page service Service Calls
  787. * @section bx_forum Discussions
  788. * @subsection bx_forum-page_blocks Page Blocks
  789. * @subsubsection bx_forum-search search
  790. *
  791. * @code bx_srv('bx_forum', 'search', [...]); @endcode
  792. *
  793. * Get page block with search form.
  794. *
  795. * @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.
  796. *
  797. * @see BxForumModule::serviceSearch
  798. */
  799. /**
  800. * @ref bx_forum-search "search"
  801. */
  802. public function serviceSearch()
  803. {
  804. $CNF = $this->_oConfig->CNF;
  805. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_SEARCH'], $CNF['OBJECT_FORM_SEARCH_DISPLAY_FULL'], $this->_oTemplate);
  806. $oForm->initChecker();
  807. return $oForm->getCode();
  808. }
  809. public function checkAllowedSubscribe(&$aDataEntry, $isPerformAction = false)
  810. {
  811. $CNF = &$this->_oConfig->CNF;
  812. $sMsg = $this->checkAllowedView($aDataEntry);
  813. if($sMsg !== CHECK_ACTION_RESULT_ALLOWED)
  814. return $sMsg;
  815. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $CNF['OBJECT_CONNECTION_SUBSCRIBERS'], false, false);
  816. }
  817. public function checkAllowedUnsubscribe(&$aDataEntry, $isPerformAction = false)
  818. {
  819. $CNF = &$this->_oConfig->CNF;
  820. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $CNF['OBJECT_CONNECTION_SUBSCRIBERS'], false, true);
  821. }
  822. public function checkAllowedStickAnyEntry($aDataEntry, $isPerformAction = false)
  823. {
  824. $CNF = &$this->_oConfig->CNF;
  825. if((int)$aDataEntry[$CNF['FIELD_STICK']] != 0)
  826. return false;
  827. return $this->_checkAllowedAction('stick any entry', $aDataEntry, $isPerformAction);
  828. }
  829. public function checkAllowedUnstickAnyEntry($aDataEntry, $isPerformAction = false)
  830. {
  831. $CNF = $this->_oConfig->CNF;
  832. if((int)$aDataEntry[$CNF['FIELD_STICK']] != 1)
  833. return false;
  834. return $this->_checkAllowedAction('stick 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. return $oGrid->getCode($isDisplayHeader);
  898. }
  899. protected function _getSearchAuthorDescriptor($aAutor)
  900. {
  901. return array('grp' => true, 'opr' => 'OR', 'cnds' => array(
  902. array('fld' => 'author', 'val' => $aAutor, 'opr' => 'IN'),
  903. array('fld' => 'author_comment', 'val' => $aAutor, 'opr' => 'IN'),
  904. ));
  905. }
  906. protected function _getSearchKeywordDescriptor($sKeyword)
  907. {
  908. return array('grp' => true, 'opr' => 'OR', 'cnds' => array(
  909. array('fld' => 'title', 'val' => $sKeyword, 'opr' => 'LIKE'),
  910. array('fld' => 'text', 'val' => $sKeyword, 'opr' => 'LIKE'),
  911. array('fld' => 'text_comments', 'val' => $sKeyword, 'opr' => 'LIKE')
  912. ));
  913. }
  914. }
  915. /** @} */