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

📄 dispatcher.inc.php.svn-base

📁 PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
<?php/** * $Id$ * * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008 KnowledgeTree Inc. * Portions copyright The Jam Warehouse Software (Pty) Limited *  * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. *  * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more * details. *  * You should have received a copy of the GNU General Public License * along with this program.  If not, see <http://www.gnu.org/licenses/>. *  * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,  * California 94120-7775, or email info@knowledgetree.com. *  * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. *  * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * KnowledgeTree" logo and retain the original copyright notice. If the display of the  * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices * must display the words "Powered by KnowledgeTree" and retain the original  * copyright notice. * Contributor( s): ______________________________________ * */require_once(KT_LIB_DIR . '/validation/dispatchervalidation.inc.php');require_once(KT_LIB_DIR . '/actions/portletregistry.inc.php');require_once(KT_LIB_DIR . "/widgets/portlet.inc.php");require_once(KT_LIB_DIR . '/templating/kt3template.inc.php');require_once(KT_LIB_DIR . '/authentication/authenticationutil.inc.php');require_once(KT_DIR . "/thirdparty/pear/JSON.php");require_once(KT_DIR . '/thirdparty/pear/Net/URL.php');class KTDispatchStandardRedirector {    function redirect($url) {        redirect($url);    }}class KTDispatcher {    var $event_var = "action";    var $action_prefix = "do";    var $cancel_var = "kt_cancel";    var $bAutomaticTransaction = false;    var $bTransactionStarted = false;    var $oValidator = null;    var $sParentUrl = null; // it is handy for subdispatched items to have an "exit" url, for cancels, etc.    var $aPersistParams = array();    function KTDispatcher() {        $this->oValidator =new KTDispatcherValidation($this);        $this->oRedirector =new KTDispatchStandardRedirector($this);    }    function redispatch($event_var, $action_prefix = null, $orig_dispatcher = null, $parent_url = null) {        $previous_event = KTUtil::arrayGet($_REQUEST, $this->event_var);        $this->sParentUrl = $parent_url;        if ($action_prefix) {            $this->action_prefix = $action_prefix;        }        if (!is_null($orig_dispatcher)) {            $this->persistParams($orig_dispatcher->aPersistParams);            $this->persistParams(array($orig_dispatcher->event_var));            $core = array('aBreadcrumbs',                'bTransactionStarted',                'oUser',                'session',                'action_prefix',                'bJSONMode');            foreach($core as $k) {                if(isset($orig_dispatcher->$k)) {                    $this->$k = $orig_dispatcher->$k;                }            }        }        $this->event_var = $event_var;        return $this->dispatch();    }    function dispatch () {        if (array_key_exists($this->cancel_var, $_REQUEST)) {            $var = $_REQUEST[$this->cancel_var];            if (is_array($var)) {                $keys = array_keys($var);                if (empty($keys[0])) {                    redirect($_SERVER['PHP_SELF']);                    exit(0);                }                redirect($keys[0]);                exit(0);            }            if (!empty($var)) {                redirect($_SERVER['PHP_SELF']);                exit(0);            }        }        $method = sprintf('%s_main', $this->action_prefix);        if (array_key_exists($this->event_var, $_REQUEST)) {            $event = $_REQUEST[$this->event_var];            $proposed_method = sprintf('%s_%s', $this->action_prefix, $event);            if (method_exists($this, $proposed_method)) {                $method = $proposed_method;            }        }        if ($this->bAutomaticTransaction) {            $this->startTransaction();        }        if (method_exists($this, 'predispatch')) {            $this->predispatch();        }        $ret = $this->$method();        $this->handleOutput($ret);        if ($this->bTransactionStarted) {            $this->commitTransaction();        }    }    function subDispatch(&$oOrigDispatcher) {        $core = array('aBreadcrumbs',            'bTransactionStarted',            'oUser',            'session',            'event_var',            'action_prefix',            'bJSONMode');        foreach($core as $k) {            if(isset($oOrigDispatcher->$k)) {                $this->$k = $oOrigDispatcher->$k;            }        }        return $this->dispatch();    }    function startTransaction() {        DBUtil::startTransaction();        $this->bTransactionStarted = true;    }    function commitTransaction() {        DBUtil::commit();        $this->bTransactionStarted = false;    }    function rollbackTransaction() {        DBUtil::rollback();        $this->bTransactionStarted = false;    }    function errorRedirectTo($event, $error_message, $sQuery = "", $oException = null) {        if ($this->bTransactionStarted) {            $this->rollbackTransaction();        }        $_SESSION['KTErrorMessage'][] = $error_message;        /* if ($oException) {            $_SESSION['Exception'][$error_message] = $oException;        }*/        $this->redirectTo($event, $sQuery);    }    function successRedirectTo($event, $info_message, $sQuery = "") {        if ($this->bTransactionStarted) {            $this->commitTransaction();        }        if (!empty($info_message)) {            $_SESSION['KTInfoMessage'][] = $info_message;        }        $this->redirectTo($event, $sQuery);    }    function errorRedirectToParent($error_message) {        if ($this->bTransactionStarted) {            $this->rollbackTransaction();        }        $_SESSION['KTErrorMessage'][] = $error_message;        redirect($this->sParentUrl);        exit(0);    }    function successRedirectToParent($info_message) {        if ($this->bTransactionStarted) {            $this->commitTransaction();        }        if (!empty($info_message)) {            $_SESSION['KTInfoMessage'][] = $info_message;        }        redirect($this->sParentUrl);        exit(0);    }    function redirectTo($event, $sQuery = "") {        // meld persistant options        $sQuery = $this->meldPersistQuery($sQuery, $event);        $sRedirect = KTUtil::addQueryString($_SERVER['PHP_SELF'], $sQuery);        $this->oRedirector->redirect($sRedirect);        exit(0);    }    function errorRedirectToMain($error_message, $sQuery = "") {        return $this->errorRedirectTo('main', $error_message, $sQuery);    }    function successRedirectToMain($error_message, $sQuery = "") {        return $this->successRedirectTo('main', $error_message, $sQuery);    }    function redirectToMain($sQuery = "") {        return $this->redirectTo('main', $sQuery);    }    function errorRedirectToBrowse($sErrorMessage, $sQuery = "", $event = 'main') {        if ($this->bTransactionStarted) {            $this->rollbackTransaction();        }        $_SESSION['KTErrorMessage'][] = $sErrorMessage;        // meld persistant options        $sQuery = $this->meldPersistQuery($sQuery, $event);        $server = str_replace('action.php', 'browse.php', $_SERVER['PHP_SELF']);        $sRedirect = KTUtil::addQueryString($server, $sQuery);        $this->oRedirector->redirect($sRedirect);        exit(0);    }    function handleOutput($sOutput) {        print $sOutput;    }    /* persist the following parameters between requests (via redirect), unless a value is passed in. */    function persistParams($aParamKeys) {        $this->aPersistParams = kt_array_merge($this->aPersistParams, $aParamKeys);    }    function meldPersistQuery($sQuery = "", $event = "", $asArray = false) {        if (is_array($sQuery)) {            $aQuery = $sQuery;        } else {            if (!empty($sQuery)) {                // need an intermediate step here.                $aQuery = Net_URL::_parseRawQuerystring($sQuery);            } else {                $aQuery = array();            }        }        // now try to grab each persisted entry        // don't overwrite the existing values, if added.        if (is_array($this->aPersistParams)) {            foreach ($this->aPersistParams as $k) {                if (!array_key_exists($k, $aQuery)) {                    $v = KTUtil::arrayGet($_REQUEST, $k);                    if (!empty($v)) {

⌨️ 快捷键说明

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