_iProfileId = bx_get_logged_profile_id(); } // ====== ACTIONS METHODS public function actionRss ($sMode = '') { $aArgs = func_get_args(); $sMode = array_shift($aArgs); if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) { $this->_oTemplate->displayAccessDenied ($sMsg); exit; } $aParams = $this->_buildRssParams($sMode, $aArgs); bx_import ('SearchResult', $this->_aModule); $sClass = $this->_aModule['class_prefix'] . 'SearchResult'; $o = new $sClass($sMode, $aParams); if ($o->isError) { $this->_oTemplate->displayPageNotFound (); exit; } $o->outputRSS(); exit; } // ====== SERVICE METHODS /** * Add entry form * @return HTML string */ public function serviceEntityCreate () { bx_import('FormsEntryHelper', $this->_aModule); $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper'; $oFormsHelper = new $sClass($this); return $oFormsHelper->addDataForm(); } public function serviceEntityEdit ($iContentId = 0) { return $this->_serviceEntityForm ('editDataForm', $iContentId); } public function serviceEntityDelete ($iContentId = 0) { return $this->_serviceEntityForm ('deleteDataForm', $iContentId); } public function serviceEntityInfo ($iContentId = 0) { return $this->_serviceEntityForm ('viewDataForm', $iContentId); } /** * Entry actions block */ public function serviceEntityActions ($iContentId = 0) { if (!$iContentId) $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT); if (!$iContentId) return false; bx_import('BxTemplMenu'); $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']); return $oMenu ? $oMenu->getCode() : false; } // ====== PERMISSION METHODS /** * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking. */ public function checkAllowedBrowse () { return CHECK_ACTION_RESULT_ALLOWED; } /** * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking. */ public function checkAllowedView ($aDataEntry, $isPerformAction = false) { $CNF = &$this->_oConfig->CNF; // moderator and owner always have access if ($aDataEntry[$CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction)) return CHECK_ACTION_RESULT_ALLOWED; // check ACL $aCheck = checkActionModule($this->_iProfileId, 'view entry', $this->getName(), $isPerformAction); if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED) return $aCheck[CHECK_ACTION_MESSAGE]; // check privacy if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) { bx_import('BxDolPrivacy'); $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']); if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']])) return _t('_sys_access_denied_to_private_content'); } return CHECK_ACTION_RESULT_ALLOWED; } /** * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking. */ public function checkAllowedAdd ($isPerformAction = false) { // check ACL $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction); if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED) return $aCheck[CHECK_ACTION_MESSAGE]; return CHECK_ACTION_RESULT_ALLOWED; } /** * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking. */ public function checkAllowedEdit ($aDataEntry, $isPerformAction = false) { // moderator and owner always have access if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction)) return CHECK_ACTION_RESULT_ALLOWED; return _t('_sys_txt_access_denied'); } /** * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking. */ public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false) { // moderator always has access if ($this->_isModerator($isPerformAction)) return CHECK_ACTION_RESULT_ALLOWED; // check ACL $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction); if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED) return CHECK_ACTION_RESULT_ALLOWED; return _t('_sys_txt_access_denied'); } // ====== PROTECTED METHODS protected function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true) { if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) return MsgBox($sMsg); bx_import('SearchResult', $this->_aModule); $sClass = $this->_aModule['class_prefix'] . 'SearchResult'; $o = new $sClass($sMode, $aParams); $o->setDesignBoxTemplateId($iDesignBox); $o->setDisplayEmptyMsg($bDisplayEmptyMsg); $o->setAjaxPaginate($bAjaxPaginate); if ($o->isError) return ''; if ($s = $o->processing()) return $s; else return ''; } protected function _isModerator ($isPerformAction = false) { // check moderator ACL $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction); return $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED; } protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false) { if (!$iContentId) $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT); if (!$iContentId) return false; bx_import('FormsEntryHelper', $this->_aModule); $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper'; $oFormsHelper = new $sClass($this); return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay); } protected function _serviceTemplateFunc ($sFunc, $iContentId) { 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->$sFunc($aContentInfo); } } /** @} */