| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
- * CC-BY License - http://creativecommons.org/licenses/by/3.0/
- *
- * @defgroup Forum Forum
- * @ingroup TridentModules
- *
- * @{
- */
- class BxForumModule extends BxBaseModTextModule
- {
- function __construct(&$aModule)
- {
- parent::__construct($aModule);
- }
- public function sortParticipants ($aParticipants, $iProfileIdLastComment, $iProfileIdAuthor, $iProfileIdCurrent = 0)
- {
- if (!$iProfileIdCurrent)
- $iProfileIdCurrent = bx_get_logged_profile_id();
- $aMoveUp = array($iProfileIdCurrent, $iProfileIdLastComment, $iProfileIdAuthor);
- asort($aParticipants, SORT_NUMERIC);
- foreach ($aMoveUp as $iProfileId) {
- if (!isset($aParticipants[$iProfileId]))
- continue;
- $a = array($iProfileId => $aParticipants[$iProfileId]);
- unset($aParticipants[$iProfileId]);
- $aParticipants = $a + $aParticipants;
- }
- return $aParticipants;
- }
- /**
- * Action methods
- */
- public function actionUpdateStatus($sAction = '', $iContentId = 0)
- {
- if(empty($sAction) && bx_get('action') !== false)
- $sAction = bx_process_input(bx_get('action'));
- if(empty($iContentId) && bx_get('id') !== false)
- $iContentId = (int)bx_get('id');
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if(empty($aContentInfo) || !is_array($aContentInfo))
- return echoJson(array('code' => 1, 'message' => _t('_bx_forum_err_not_found')));
- $sMethodCheck = 'checkAllowed' . bx_gen_method_name($sAction) . 'AnyEntry';
- $sResult = $this->$sMethodCheck($aContentInfo);
- if($sResult !== CHECK_ACTION_RESULT_ALLOWED)
- return echoJson(array('code' => 2, 'message' => $sResult));
- if(!$this->_oDb->updateStatus($sAction, $aContentInfo))
- return echoJson(array('code' => 3, 'message' => _t('_error occured')));
- echoJson(array('code' => 0, 'id' => $iContentId, 'reload' => 1));
- }
- /**
- * Service methods
- */
- public function serviceBrowseNew ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
- {
- $sType = 'new';
- if($sUnitView != 'table')
- return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
- return $this->_serviceBrowseTable(array('type' => $sType));
- }
- public function serviceBrowseLatest($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
- {
- $sType = 'latest';
- if($sUnitView != 'table')
- return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
- return $this->_serviceBrowseTable(array('type' => $sType));
- }
- public function serviceBrowseTop($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
- {
- $sType = 'top';
- if($sUnitView != 'table')
- return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
- return $this->_serviceBrowseTable(array('type' => $sType));
- }
- public function serviceBrowseCategories($bEmptyMessage = true)
- {
- return $this->_oTemplate->getCategories($bEmptyMessage);
- }
- public function serviceBrowseCategory($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
- {
- $sType = 'category';
- $iCategory = bx_process_input(bx_get('category'), BX_DATA_INT);
- $aCategory = $this->_oDb->getCategories(array('type' => 'by_category', 'category' => $iCategory));
- if(!empty($aCategory['visible_for_levels']) && !BxDolAcl::getInstance()->isMemberLevelInSet($aCategory['visible_for_levels']))
- return $bEmptyMessage ? MsgBox(_t('_sys_txt_access_denied')) : '';
- if($sUnitView != 'table')
- return $this->_serviceBrowse($sType, $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
- return $this->_serviceBrowseTable(array('type' => $sType, 'where' => array('cat' => $iCategory)));
- }
- /**
- * Get number of unread messages for spme profile
- * @param $iProfileId - profile to get unread messages for, if omitted then currently logged is profile is used
- * @return integer
- */
- public function serviceGetUnrepliedDiscussionsNum ($iProfileId = 0)
- {
- if (!$iProfileId)
- $iProfileId = bx_get_logged_profile_id();
- return $this->_oDb->getUnrepliedDiscussionsNum((int)$iProfileId);
- }
- /**
- * Update last comment time and author
- */
- public function serviceTriggerCommentPost ($iContentId, $iProfileId, $iCommentId, $iTimestamp = 0, $sCommentText = '')
- {
- $CNT = $this->_oConfig->CNF;
- $iContentId = (int)$iContentId;
- if(!$iContentId)
- return false;
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if(!$aContentInfo)
- return false;
- if(!$iTimestamp)
- $iTimestamp = time();
- if(!$this->_oDb->updateLastCommentTimeProfile((int)$iContentId, (int)$iProfileId, $iCommentId, $iTimestamp))
- return false;
- // send notification to author
- if($iProfileId != $aContentInfo[$CNT['FIELD_AUTHOR']]) {
- $oProfile = BxDolProfile::getInstance($iProfileId);
- if($oProfile)
- sendMailTemplate('bx_forum_new_reply', 0, $aContentInfo[$CNT['FIELD_AUTHOR']], array(
- 'SenderDisplayName' => $oProfile->getDisplayName(),
- 'SenderUrl' => $oProfile->getUrl(),
- 'Message' => $sCommentText,
- ), BX_EMAIL_NOTIFY);
- }
- return true;
- }
- public function serviceEntityBreadcrumb ($iContentId = 0)
- {
- if (!$iContentId)
- $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if (!$iContentId)
- return false;
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if (!$aContentInfo)
- return false;
- return $this->_oTemplate->entryBreadcrumb($aContentInfo);
- }
- /**
- * Entry collaborators block
- */
- public function serviceEntityParticipants ($iContentId = 0)
- {
- if (!$iContentId)
- $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
- if (!$iContentId)
- return false;
- $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
- if (!$aContentInfo)
- return false;
- return $this->_oTemplate->entryParticipants ($aContentInfo, 5, 'right');
- }
- /**
- * No social sharing for private discussions
- */
- public function serviceEntitySocialSharing($iContentId = 0)
- {
- return '';
- }
- /**
- * No thumbs for discussions
- */
- public function checkAllowedSetThumb()
- {
- return _t('_sys_txt_access_denied');
- }
- public function checkAllowedStickAnyEntry($aDataEntry, $isPerformAction = false)
- {
- $CNF = $this->_oConfig->CNF;
- if((int)$aDataEntry[$CNF['FIELD_STICK']] != 0)
- return false;
- return $this->_checkAllowedAction('stick any entry', $aDataEntry, $isPerformAction);
- }
- public function checkAllowedUnstickAnyEntry($aDataEntry, $isPerformAction = false)
- {
- $CNF = $this->_oConfig->CNF;
- if((int)$aDataEntry[$CNF['FIELD_STICK']] != 1)
- return false;
- return $this->_checkAllowedAction('stick any entry', $aDataEntry, $isPerformAction);
- }
- public function checkAllowedLockAnyEntry($aDataEntry, $isPerformAction = false)
- {
- $CNF = $this->_oConfig->CNF;
- if((int)$aDataEntry[$CNF['FIELD_LOCK']] != 0)
- return false;
- return $this->_checkAllowedAction('lock any entry', $aDataEntry, $isPerformAction);
- }
- public function checkAllowedUnlockAnyEntry($aDataEntry, $isPerformAction = false)
- {
- $CNF = $this->_oConfig->CNF;
- if((int)$aDataEntry[$CNF['FIELD_LOCK']] != 1)
- return false;
- return $this->_checkAllowedAction('lock any entry', $aDataEntry, $isPerformAction);
- }
- public function checkAllowedHideAnyEntry($aDataEntry, $isPerformAction = false)
- {
- $CNF = $this->_oConfig->CNF;
- if($aDataEntry[$CNF['FIELD_STATUS_ADMIN']] == 'hidden')
- return false;
- return $this->_checkAllowedAction('hide any entry', $aDataEntry, $isPerformAction);
- }
- public function checkAllowedUnhideAnyEntry($aDataEntry, $isPerformAction = false)
- {
- $CNF = $this->_oConfig->CNF;
- if($aDataEntry[$CNF['FIELD_STATUS_ADMIN']] != 'hidden')
- return false;
- return $this->_checkAllowedAction('hide any entry', $aDataEntry, $isPerformAction);
- }
- /**
- * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
- */
- protected function _checkAllowedAction($sAction, $aDataEntry, $isPerformAction = false)
- {
- if($this->_isModerator($isPerformAction))
- return CHECK_ACTION_RESULT_ALLOWED;
- $aCheck = checkActionModule($this->_iProfileId, $sAction, $this->getName(), $isPerformAction);
- if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
- return CHECK_ACTION_RESULT_ALLOWED;
- return _t('_sys_txt_access_denied');
- }
- protected function _serviceBrowseTable($aParams)
- {
- $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID']);
- if(!$oGrid)
- return false;
- $oGrid->setBrowseParams($aParams);
- return $oGrid->getCode();
- }
- }
- /** @} */
|