BxForumModule.php 35 KB

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