BxForumModule.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Forum Forum
  7. * @ingroup TridentModules
  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. /**
  53. * Service methods
  54. */
  55. public function serviceBrowseNew ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  56. {
  57. $sType = 'new';
  58. if($sUnitView != 'table')
  59. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  60. return $this->_serviceBrowseTable($sType);
  61. }
  62. public function serviceBrowseLatest($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  63. {
  64. $sType = 'latest';
  65. if($sUnitView != 'table')
  66. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  67. return $this->_serviceBrowseTable($sType);
  68. }
  69. public function serviceBrowseTop($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  70. {
  71. $sType = 'top';
  72. if($sUnitView != 'table')
  73. return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  74. return $this->_serviceBrowseTable($sType);
  75. }
  76. /**
  77. * Get number of unread messages for spme profile
  78. * @param $iProfileId - profile to get unread messages for, if omitted then currently logged is profile is used
  79. * @return integer
  80. */
  81. public function serviceGetUnrepliedDiscussionsNum ($iProfileId = 0)
  82. {
  83. if (!$iProfileId)
  84. $iProfileId = bx_get_logged_profile_id();
  85. return $this->_oDb->getUnrepliedDiscussionsNum((int)$iProfileId);
  86. }
  87. /**
  88. * Update last comment time and author
  89. */
  90. public function serviceTriggerCommentPost ($iContentId, $iProfileId, $iCommentId, $iTimestamp = 0, $sCommentText = '')
  91. {
  92. $CNT = $this->_oConfig->CNF;
  93. $iContentId = (int)$iContentId;
  94. if(!$iContentId)
  95. return false;
  96. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  97. if(!$aContentInfo)
  98. return false;
  99. if(!$iTimestamp)
  100. $iTimestamp = time();
  101. if(!$this->_oDb->updateLastCommentTimeProfile((int)$iContentId, (int)$iProfileId, $iCommentId, $iTimestamp))
  102. return false;
  103. // send notification to author
  104. if($iProfileId != $aContentInfo[$CNT['FIELD_AUTHOR']]) {
  105. $oProfile = BxDolProfile::getInstance($iProfileId);
  106. if($oProfile)
  107. sendMailTemplate('bx_forum_new_reply', 0, $aContentInfo[$CNT['FIELD_AUTHOR']], array(
  108. 'SenderDisplayName' => $oProfile->getDisplayName(),
  109. 'SenderUrl' => $oProfile->getUrl(),
  110. 'Message' => $sCommentText,
  111. ), BX_EMAIL_NOTIFY);
  112. }
  113. return true;
  114. }
  115. public function serviceEntityBreadcrumb ($iContentId = 0)
  116. {
  117. if (!$iContentId)
  118. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  119. if (!$iContentId)
  120. return false;
  121. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  122. if (!$aContentInfo)
  123. return false;
  124. return $this->_oTemplate->entryBreadcrumb($aContentInfo);
  125. }
  126. /**
  127. * Entry collaborators block
  128. */
  129. public function serviceEntityParticipants ($iContentId = 0)
  130. {
  131. if (!$iContentId)
  132. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  133. if (!$iContentId)
  134. return false;
  135. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  136. if (!$aContentInfo)
  137. return false;
  138. return $this->_oTemplate->entryParticipants ($aContentInfo, 5, 'right');
  139. }
  140. /**
  141. * No social sharing for private discussions
  142. */
  143. public function serviceEntitySocialSharing($iContentId = 0)
  144. {
  145. return '';
  146. }
  147. /**
  148. * No thumbs for discussions
  149. */
  150. public function checkAllowedSetThumb()
  151. {
  152. return _t('_sys_txt_access_denied');
  153. }
  154. public function checkAllowedStickAnyEntry($aDataEntry, $isPerformAction = false)
  155. {
  156. $CNF = $this->_oConfig->CNF;
  157. if((int)$aDataEntry[$CNF['FIELD_STICK']] != 0)
  158. return false;
  159. return $this->_checkAllowedAction('stick any entry', $aDataEntry, $isPerformAction);
  160. }
  161. public function checkAllowedUnstickAnyEntry($aDataEntry, $isPerformAction = false)
  162. {
  163. $CNF = $this->_oConfig->CNF;
  164. if((int)$aDataEntry[$CNF['FIELD_STICK']] != 1)
  165. return false;
  166. return $this->_checkAllowedAction('stick any entry', $aDataEntry, $isPerformAction);
  167. }
  168. public function checkAllowedLockAnyEntry($aDataEntry, $isPerformAction = false)
  169. {
  170. $CNF = $this->_oConfig->CNF;
  171. if((int)$aDataEntry[$CNF['FIELD_LOCK']] != 0)
  172. return false;
  173. return $this->_checkAllowedAction('lock any entry', $aDataEntry, $isPerformAction);
  174. }
  175. public function checkAllowedUnlockAnyEntry($aDataEntry, $isPerformAction = false)
  176. {
  177. $CNF = $this->_oConfig->CNF;
  178. if((int)$aDataEntry[$CNF['FIELD_LOCK']] != 1)
  179. return false;
  180. return $this->_checkAllowedAction('lock any entry', $aDataEntry, $isPerformAction);
  181. }
  182. public function checkAllowedHideAnyEntry($aDataEntry, $isPerformAction = false)
  183. {
  184. $CNF = $this->_oConfig->CNF;
  185. if($aDataEntry[$CNF['FIELD_STATUS_ADMIN']] == 'hidden')
  186. return false;
  187. return $this->_checkAllowedAction('hide any entry', $aDataEntry, $isPerformAction);
  188. }
  189. public function checkAllowedUnhideAnyEntry($aDataEntry, $isPerformAction = false)
  190. {
  191. $CNF = $this->_oConfig->CNF;
  192. if($aDataEntry[$CNF['FIELD_STATUS_ADMIN']] != 'hidden')
  193. return false;
  194. return $this->_checkAllowedAction('hide any entry', $aDataEntry, $isPerformAction);
  195. }
  196. /**
  197. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  198. */
  199. protected function _checkAllowedAction($sAction, $aDataEntry, $isPerformAction = false)
  200. {
  201. if($this->_isModerator($isPerformAction))
  202. return CHECK_ACTION_RESULT_ALLOWED;
  203. $aCheck = checkActionModule($this->_iProfileId, $sAction, $this->getName(), $isPerformAction);
  204. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  205. return CHECK_ACTION_RESULT_ALLOWED;
  206. return _t('_sys_txt_access_denied');
  207. }
  208. protected function _serviceBrowseTable($sType)
  209. {
  210. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID']);
  211. if(!$oGrid)
  212. return false;
  213. $oGrid->setBrowseType($sType);
  214. $oGrid->addMarkers(array(
  215. 'profile_id' => bx_get_logged_profile_id(),
  216. ));
  217. return $oGrid->getCode();
  218. }
  219. }
  220. /** @} */