⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dispatcher.inc.php.svn-base

📁 PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
                        $aQuery[$k] = $v;                    }                }                // handle the case where action is passed in already.            }        }        // if it isn't already set        if ((!array_key_exists($this->event_var, $aQuery)) && (!empty($event))) {            $aQuery[$this->event_var] = urlencode($event);        }        //var_dump($aQuery);        if ($asArray) {            return $aQuery;        }        // encode and blend.        $aQueryStrings = array();        foreach ($aQuery as $k => $v) {            $aQueryStrings[] = urlencode($k) . "=" . urlencode($v);        }        $sQuery = join('&', $aQueryStrings);        return $sQuery;    }}class KTStandardDispatcher extends KTDispatcher {    var $bLogonRequired = true;    var $bAdminRequired = false;    var $aBreadcrumbs = array();    var $sSection = false;    var $oPage = false;    var $sHelpPage = null;    var $bJSONMode = false;    function KTStandardDispatcher() {        if (empty($GLOBALS['main'])) {            $GLOBALS['main'] =new KTPage;        }        $this->oPage =& $GLOBALS['main'];        parent::KTDispatcher();    }    function permissionDenied () {        // handle anonymous specially.        if ($this->oUser->getId() == -2) {            redirect(KTUtil::ktLink('login.php','',sprintf("redirect=%s&errorMessage=%s", urlencode($_SERVER['REQUEST_URI']), urlencode(_kt("You must be logged in to perform this action"))))); exit(0);        }	global $default;	$msg = '<h2>' . _kt('Permission Denied') . '</h2>';	$msg .= '<p>' . _kt('If you feel that this is incorrect, please report both the action and your username to a system administrator.') . '</p>';        $this->oPage->setPageContents($msg);        $this->oPage->setUser($this->oUser);	$this->oPage->hideSection();        $this->oPage->render();        exit(0);    }    function loginRequired() {	$oKTConfig =& KTConfig::getSingleton();	if ($oKTConfig->get('allowAnonymousLogin', false)) {	    // anonymous logins are now allowed.	    // the anonymous user is -1.	    //	    // we short-circuit the login mechanisms, setup the session, and go.	    $oUser =& User::get(-2);	    if (PEAR::isError($oUser) || ($oUser->getName() != 'Anonymous')) {		; // do nothing - the database integrity would break if we log the user in now.	    } else {		$session = new Session();                $sessionID = $session->create($oUser);                $this->sessionStatus = $this->session->verify();                if ($this->sessionStatus === true) {                    return ;                }            }        }        $sErrorMessage = "";        if (PEAR::isError($this->sessionStatus)) {            $sErrorMessage = $this->sessionStatus->getMessage();        }	// check if we're in JSON mode - in which case, throw error	// but JSON mode only gets set later, so gonna have to check action	if(KTUtil::arrayGet($_REQUEST, 'action', '') == 'json') { //$this->bJSONMode) {	    $this->handleOutputJSON(array('error'=>true,					  'type'=>'kt.not_logged_in',					  'alert'=>true,					  'message'=>_kt('Your session has expired, please log in again.')));	    exit(0);	}        // redirect to login with error message        if ($sErrorMessage) {            // session timed out            $url = generateControllerUrl("login", "errorMessage=" . urlencode($sErrorMessage));        } else {            $url = generateControllerUrl("login");        }        $redirect = urlencode(KTUtil::addQueryStringSelf($_SERVER["QUERY_STRING"]));        if ((strlen($redirect) > 1)) {            global $default;            $default->log->debug("checkSession:: redirect url=$redirect");            // this session verification failure represents either the first visit to            // the site OR a session timeout etc. (in which case we still want to bounce            // the user to the login page, and then back to whatever page they're on now)            $url = $url . urlencode("&redirect=" . urlencode($redirect));        }        $default->log->debug("checkSession:: about to redirect to $url");        redirect($url);        exit(0);    }    function dispatch () {        if (empty($this->session)) {            $this->session = new Session();            $this->sessionStatus = $this->session->verify();            if ($this->sessionStatus !== true) {                $this->loginRequired();            }            //var_dump($this->sessionStatus);            $this->oUser =& User::get($_SESSION['userID']);            $oProvider =& KTAuthenticationUtil::getAuthenticationProviderForUser($this->oUser);            $oProvider->verify($this->oUser);        }        if ($this->bAdminRequired !== false) {            if (!Permission::userIsSystemAdministrator($_SESSION['userID'])) {                $this->permissionDenied();                exit(0);            }        }        if ($this->check() !== true) {            $this->permissionDenied();            exit(0);        }        return parent::dispatch();    }    function check() {        return true;    }    function addInfoMessage($sMessage) { $_SESSION['KTInfoMessage'][] = $sMessage; }    function addErrorMessage($sMessage) { $_SESSION['KTErrorMessage'][] = $sMessage; }    function errorPage($errorMessage, $oException = null) {        if ($this->bTransactionStarted) {            $this->rollbackTransaction();        }        $sOutput = $errorMessage;        if ($oException) {            // $sOutput .= $oException->toString();        }        $this->handleOutput($sOutput);        exit(0);    }    function handleOutput($data) {	if($this->bJSONMode) {	    return $this->handleOutputJSON($data);	} else {	    return $this->handleOutputDefault($data);	}    }    function handleOutputDefault($data) {	global $default;	global $sectionName;        $this->oPage->setSection($this->sSection);        $this->oPage->setBreadcrumbs($this->aBreadcrumbs);        $this->oPage->setPageContents($data);        $this->oPage->setUser($this->oUser);	$this->oPage->setHelp($this->sHelpPage);	// handle errors that were set using KTErrorMessage.	$errors = KTUtil::arrayGet($_SESSION, 'KTErrorMessage', array());	if (!empty($errors)) {            foreach ($errors as $sError) {		$this->oPage->addError($sError);	    }	    $_SESSION['KTErrorMessage'] = array(); // clean it out.	}	// handle notices that were set using KTInfoMessage.	$info = KTUtil::arrayGet($_SESSION, 'KTInfoMessage', array());	if (!empty($info)) {            foreach ($info as $sInfo) {		$this->oPage->addInfo($sInfo);	    }	    $_SESSION['KTInfoMessage'] = array(); // clean it out.	}        // Get the portlets to display from the portlet registry        $oPRegistry =& KTPortletRegistry::getSingleton();        $aPortlets = $oPRegistry->getPortletsForPage($this->aBreadcrumbs);        foreach ($aPortlets as $oPortlet) {            $oPortlet->setDispatcher($this);            $this->oPage->addPortlet($oPortlet);        }        $this->oPage->render();    }    // JSON handling    function handleOutputJSON($data) {	$oJSON = new Services_JSON();	print $oJSON->encode($data);	exit(0);    }    function do_json() {	$this->bJSONMode = true;	$this->redispatch('json_action', 'json');    }    function json_main() {	return array('type'=>'error', 'value'=>'Not implemented');    }}class KTAdminDispatcher extends KTStandardDispatcher {    var $bAdminRequired = true;    var $sSection = 'administration';    function KTAdminDispatcher() {        $this->aBreadcrumbs = array(            array('action' => 'administration', 'name' => _kt('Administration')),        );        return parent::KTStandardDispatcher();    }}class KTErrorDispatcher extends KTStandardDispatcher {    var $bLogonRequired = true;    function KTErrorDispatcher($oError) {        parent::KTStandardDispatcher();        $this->oError =& $oError;    }    function dispatch() {                require_once(KT_LIB_DIR . '/validation/customerror.php');                $bCustomCheck = KTCustomErrorCheck::customErrorInit($this->oError);                      if($bCustomCheck)        {        	exit(0);        }                                //if either customer error messages is off or the custom error page doesn't exist the function will run         //the default error handling here        $oRegistry =& KTErrorViewerRegistry::getSingleton();        $oViewer =& $oRegistry->getViewer($this->oError);        $this->oPage->setTitle($oViewer->view());        $this->oPage->hideSection();        $this->handleOutput($oViewer->page());    }}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -