BxForumModule.php 36 KB

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