| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- <?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 BaseGeneral Base classes for modules
- * @ingroup TridentModules
- *
- * @{
- */
- bx_import ('BxDolModule');
- /**
- * Base module class.
- */
- class BxBaseModGeneralModule extends BxDolModule
- {
- protected $_iProfileId;
- function __construct(&$aModule)
- {
- parent::__construct($aModule);
- $this->_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
- public function serviceManageTools($sType = 'common')
- {
- bx_import('BxDolGrid');
- $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getGridObject($sType));
- if(!$oGrid)
- return '';
- $CNF = &$this->_oConfig->CNF;
- bx_import('BxDolAcl');
- $oAcl = BxDolAcl::getInstance();
- $sMenu = '';
- if($oAcl->isMemberLevelInSet(192)) {
- bx_import('BxDolPermalinks');
- $oPermalink = BxDolPermalinks::getInstance();
- $aMenuItems = array(
- array('id' => 'manage-common', 'name' => 'manage-common', 'class' => '', 'link' => $oPermalink->permalink($CNF['URL_MANAGE_COMMON']), 'target' => '_self', 'title' => _t($CNF['T']['menu_item_manage_my']), 'active' => 1)
- );
- if($oAcl->isMemberLevelInSet(64))
- $aMenuItems[] = array('id' => 'manage-moderation', 'name' => 'manage-moderation', 'class' => '', 'link' => $oPermalink->permalink($CNF['URL_MANAGE_MODERATION']), 'target' => '_self', 'title' => _t($CNF['T']['menu_item_manage_all']), 'active' => 1);
- if($oAcl->isMemberLevelInSet(128))
- $aMenuItems[] = array('id' => 'manage-administration', 'name' => 'manage-administration', 'class' => '', 'link' => $oPermalink->permalink($CNF['URL_MANAGE_ADMINISTRATION']), 'target' => '_self', 'title' => _t($CNF['T']['menu_item_manage_all']), 'active' => 1);
- bx_import('BxTemplMenu');
- $oMenu = new BxTemplMenu(array(
- 'template' => 'menu_vertical.html',
- 'menu_items' => $aMenuItems
- ), $this->_oTemplate);
- $oMenu->setSelected($this->_aModule['name'], 'manage-' . $sType);
- $sMenu = $oMenu->getCode();
- }
- bx_import('BxTemplMenu');
- BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU'])->setSelected($this->_aModule['name'], $CNF['URI_MANAGE_COMMON']);
- $this->_oTemplate->addCss(array('manage_tools.css'));
- $this->_oTemplate->addJs(array('manage_tools.js'));
- $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
- return array(
- 'content' => $this->_oTemplate->getJsCode('manage_tools', array('sObjNameGrid' => $this->_oConfig->getGridObject($sType))) . $oGrid->getCode(),
- 'menu' => $sMenu
- );
- }
- public function serviceGetMenuAddonManageTools()
- {
- return 0;
- }
-
- public function serviceGetMenuAddonManageToolsProfileStats()
- {
- return 0;
- }
- /**
- * 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');
- }
- /**
- * @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 checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
- {
- // admin always has access
- if (isAdmin($this->_iProfileId))
- return CHECK_ACTION_RESULT_ALLOWED;
- // check ACL
- $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
- if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
- return $aCheck[CHECK_ACTION_MESSAGE];
- return CHECK_ACTION_RESULT_ALLOWED;
- }
- // ====== 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);
- }
- }
- /** @} */
|