BxForumModule.php 39 KB

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