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

📄 plugin.inc.php

📁 PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php
/**
 * $Id: plugin.inc.php 9175 2008-08-14 13:01:06Z kevin_fourie $
 *
 * 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 . '/database/sqlfile.inc.php');

class KTPlugin {
    var $sNamespace;
    var $sFilename = null;
    var $bAlwaysInclude = false;
    var $iVersion = 0;
    var $iOrder = 0;
    var $sFriendlyName = null;
    var $sSQLDir = null;

    var $autoRegister = false;

    var $_aPortlets = array();
    var $_aTriggers = array();
    var $_aActions = array();
    var $_aPages = array();
    var $_aAuthenticationProviders = array();
    var $_aAdminCategories = array();
    var $_aAdminPages = array();
    var $_aDashlets = array();
    var $_ai18n = array();
    var $_ai18nLang = array();
    var $_aLanguage = array();
    var $_aHelpLanguage = array();
    var $_aWFTriggers = array();
    var $_aColumns = array();
    var $_aViews = array();
    var $_aNotificationHandlers = array();
    var $_aTemplateLocations = array();
    var $_aWidgets = array();
    var $_aValidators = array();
    var $_aCriteria = array();
    var $_aInterceptors = array();

    function KTPlugin($sFilename = null) {
        $this->sFilename = $sFilename;
    }

    function setFilename($sFilename) {
        $this->sFilename = $sFilename;
    }

    function registerPortlet($aLocation, $sPortletClassName, $sPortletNamespace, $sFilename = null) {
        $sFilename = $this->_fixFilename($sFilename);
        $this->_aPortlets[$sPortletNamespace] = array($aLocation, $sPortletClassName, $sPortletNamespace, $sFilename, $this->sNamespace);

        // Register helper in DB
        if(is_array($aLocation)){
            $aLocation = serialize($aLocation);
        }
        $params = $aLocation.'|'.$sPortletClassName.'|'.$sPortletNamespace.'|'.$sFilename.'|'.$this->sNamespace;
        $this->registerPluginHelper($sPortletNamespace, $sPortletClassName, $sFilename, $params, 'general', 'portlet');
    }

    function registerTrigger($sAction, $sStage, $sTriggerClassName, $sTriggerNamespace, $sFilename = null) {
        $sFilename = $this->_fixFilename($sFilename);
        $this->_aTriggers[$sTriggerNamespace] = array($sAction, $sStage, $sTriggerClassName, $sTriggerNamespace, $sFilename, $this->sNamespace);

        // Register helper in DB
        $params = $sAction.'|'.$sStage.'|'.$sTriggerClassName.'|'.$sTriggerNamespace.'|'.$sFilename.'|'.$this->sNamespace;
        $this->registerPluginHelper($sTriggerNamespace, $sTriggerClassName, $sFilename, $params, 'general', 'trigger');
    }

    function registerAction($sActionType, $sActionClassName, $sActionNamespace, $sFilename = null) {
        $sFilename = $this->_fixFilename($sFilename);
        $this->_aActions[$sActionNamespace] = array($sActionType, $sActionClassName, $sActionNamespace, $sFilename, $this->sNamespace);

        // Register helper in DB
        $params = $sActionType.'|'.$sActionClassName.'|'.$sActionNamespace.'|'.$sFilename.'|'.$this->sNamespace;
        $this->registerPluginHelper($sActionNamespace, $sActionClassName, $sFilename, $params, 'general', 'action');
    }

    function registerPage($sWebPath, $sPageClassName, $sFilename = null) {
        $sFilename = $this->_fixFilename($sFilename);
        $sWebPath = sprintf("%s/%s", $this->sNamespace, $sWebPath);

        $this->_aPages[$sWebPath] = array($sWebPath, $sPageClassName, $sFilename, $this->sNamespace);

        // Register helper in DB
        $params = $sWebPath.'|'.$sPageClassName.'|'.$sFilename.'|'.$this->sNamespace;
        $this->registerPluginHelper($sWebPath, $sPageClassName, $sFilename, $params, 'general', 'page');
    }

    function registerWorkflowTrigger($sNamespace, $sTriggerClassName, $sFilename = null) {
        $sFilename = $this->_fixFilename($sFilename);
        $this->_aWFTriggers[$sNamespace] = array($sNamespace, $sTriggerClassName, $sFilename);

        // Register helper in DB
        $params = $sNamespace.'|'.$sTriggerClassName.'|'.$sFilename;
        $this->registerPluginHelper($sNamespace, $sTriggerClassName, $sFilename, $params, 'general', 'workflow_trigger');
    }

    function getPagePath($sPath) {
        $sExt = ".php";
        if (KTUtil::arrayGet($_SERVER, 'kt_no_extensions')) {
            $sExt = "";
        }
        $oKTConfig =& KTConfig::getSingleton();
        if ($oKTConfig->get("KnowledgeTree/pathInfoSupport")) {
            return sprintf('%s/plugin%s/%s/%s', $GLOBALS['KTRootUrl'], $sExt, $this->sNamespace, $sPath);
        } else {
            return sprintf('%s/plugin%s?kt_path_info=%s/%s', $GLOBALS['KTRootUrl'], $sExt, $this->sNamespace, $sPath);
        }
    }

    function registerAuthenticationProvider($sName, $sClass, $sNamespace, $sFilename = null) {
        $sFilename = $this->_fixFilename($sFilename);
        $this->_aAuthenticationProviders[$sNamespace] = array($sName, $sClass, $sNamespace, $sFilename, $this->sNamespace);

        // Register helper in DB
        $params = $sName.'|'.$sClass.'|'.$sNamespace.'|'.$sFilename.'|'.$this->sNamespace;
        $this->registerPluginHelper($sNamespace, $sClass, $sFilename, $params, 'general', 'authentication_provider');
    }

//registerLocation($sName, $sClass, $sCategory, $sTitle, $sDescription, $sDispatcherFilePath = null, $sURL = null)
    function registerAdminPage($sName, $sClass, $sCategory, $sTitle, $sDescription, $sFilename) {
        $sFullname = $sCategory . '/' . $sName;
        $sFilename = $this->_fixFilename($sFilename);
        $this->_aAdminPages[$sFullname] = array($sName, $sClass, $sCategory, $sTitle, $sDescription, $sFilename, null, $this->sNamespace);

        // Register helper in DB
        $params = $sName.'|'.$sClass.'|'.$sCategory.'|'.$sTitle.'|'.$sDescription.'|'.$sFilename.'|'.null.'|'.$this->sNamespace;
        $this->registerPluginHelper($sFullname, $sClass, $sFilename, $params, 'general', 'admin_page');
    }

    function registerAdminCategory($sPath, $sName, $sDescription) {
        $this->_aAdminCategories[$sPath] = array($sPath, $sName, $sDescription);

        // Register helper in DB
        $params = $sPath.'|'.$sName.'|'.$sDescription;
        $this->registerPluginHelper($sPath, $sName, $sPath, $params, 'general', 'admin_category');
    }

    /**
     * Register a new dashlet
     *
     * @param string $sClassName
     * @param string $sNamespace
     * @param string $sFilename
     */
    function registerDashlet($sClassName, $sNamespace, $sFilename) {
        $sFilename = $this->_fixFilename($sFilename);
        $this->_aDashlets[$sNamespace] = array($sClassName, $sNamespace, $sFilename, $this->sNamespace);

        $params = $sClassName.'|'.$sNamespace.'|'.$sFilename.'|'.$this->sNamespace;
        $this->registerPluginHelper($sNamespace, $sClassName, $sFilename, $params, 'dashboard', 'dashlet');
    }

    function registeri18n($sDomain, $sPath) {
        $sPath = $this->_fixFilename($sPath);
        $this->_ai18n[$sDomain] = array($sDomain, $sPath);

        // Register helper in DB
        $params = $sDomain.'|'.$sPath;
        $this->registerPluginHelper($sDomain, $sDomain, $sPath, $params, 'general', 'i18n');
    }

    function registeri18nLang($sDomain, $sLang, $sPath) {
        if ($sPath !== "default") {
            $sPath = $this->_fixFilename($sPath);
        }
        $this->_ai18nLang["$sDomain/$sLang"] = array($sDomain, $sLang, $sPath);

        // Register helper in DB
        $params = $sDomain.'|'.$sLang.'|'.$sPath;
        $this->registerPluginHelper("$sDomain/$sLang", $sDomain, $sPath, $params, 'general', 'i18nlang');
    }

    function registerLanguage($sLanguage, $sLanguageName) {
        $this->_aLanguage[$sLanguage] = array($sLanguage, $sLanguageName);

        // Register helper in DB
        $params = $sLanguage.'|'.$sLanguageName;
        $this->registerPluginHelper($sLanguage, $sClassName, $sFilename, $params, 'general', 'language');
    }

    function registerHelpLanguage($sPlugin, $sLanguage, $sBasedir) {
        $sBasedir = (!empty($sBasedir)) ? $this->_fixFilename($sBasedir) : '';
        $this->_aHelpLanguage[$sLanguage] = array($sPlugin, $sLanguage, $sBasedir);

        // Register helper in DB
        $params = $sPlugin.'|'.$sLanguage.'|'.$sBasedir;
        $this->registerPluginHelper($sLanguage, $sClassName, '', $params, 'general', 'help_language');
    }

    function registerColumn($sName, $sNamespace, $sClassName, $sFile) {
        $sFile = $this->_fixFilename($sFile);
        $this->_aColumns[$sNamespace] = array($sName, $sNamespace, $sClassName, $sFile);

        // Register helper in DB
        $params = $sName.'|'.$sNamespace.'|'.$sClassName.'|'.$sFile;
        $this->registerPluginHelper($sNamespace, $sClassName, $sFile, $params, 'general', 'column');
    }

    function registerView($sName, $sNamespace) {
        $this->_aViews[$sNamespace] = array($sName, $sNamespace);

        // Register helper in DB
        $params = $sName.'|'.$sNamespace;
        $this->registerPluginHelper($sNamespace, '', '', $params, 'general', 'view');
    }

    function registerNotificationHandler($sName, $sNamespace, $sPath) {
        $sPath = $this->_fixFilename($sPath);
        $this->_aNotificationHandlers[$sNamespace] = array($sNamespace, $sName, $sPath);

        // Register helper in DB
        $params = $sNamespace.'|'.$sName.'|'.$sPath;
        $this->registerPluginHelper($sNamespace, $sName, $sPath, $params, 'general', 'notification_handler');
    }

    function registerTemplateLocation($sName, $sPath) {
        $sPath = $this->_fixFilename($sPath);
        $this->_aTemplateLocations[$sName] = array($sName, $sPath);

        // Register helper in DB
        $params = $sName.'|'.$sPath;
        $this->registerPluginHelper($sName, $sName, $sPath, $params, 'general', 'template_location');
    }


    /**
     * Register a new widget
     *
     * @param unknown_type $sClassname
     * @param unknown_type $sNamespace
     * @param unknown_type $sPath
     */
    function registerWidget($sClassname, $sNamespace, $sPath) {
        $sPath = $this->_fixFilename($sPath);
        $this->_aWidgets[$sNamespace] = array($sClassname, $sNamespace, $sPath);

        // Register helper in DB
        $params = $sClassname.'|'.$sNamespace.'|'.$sPath;
        $this->registerPluginHelper($sNamespace, $sClassname, $sPath, $params, 'general', 'widget');
    }

    function registerValidator($sClassname, $sNamespace, $sPath) {
        $sPath = $this->_fixFilename($sPath);
        $this->_aValidators[$sNamespace] = array($sClassname, $sNamespace, $sPath);

        // Register helper in DB
        $params = $sClassname.'|'.$sNamespace.'|'.$sPath;
        $this->registerPluginHelper($sNamespace, $sClassname, $sPath, $params, 'general', 'validator');
    }


    function registerCriterion($sClassName, $sNamespace, $sFilename = null, $aInitialize = null) {
        $sFilename = $this->_fixFilename($sFilename);
        $this->_aCriteria[$sNamespace] = array($sClassName, $sNamespace, $sFilename, $aInitialize);

        // Register helper in DB
        if(is_array($aInitialize)){
            $aInitialize = serialize($aInitialize);
        }

        $params = $sClassName.'|'.$sNamespace.'|'.$sFilename.'|'.$aInitialize;
        $this->registerPluginHelper($sNamespace, $sClassName, $sFilename, $params, 'general', 'criterion');
    }

    function registerInterceptor($sClassname, $sNamespace, $sPath = null) {
        $sPath = $this->_fixFilename($sPath);
        $this->_aInterceptors[$sNamespace] = array($sClassname, $sNamespace, $sPath);

        // Register helper in DB
        $params = $sClassname.'|'.$sNamespace.'|'.$sPath;
        $this->registerPluginHelper($sNamespace, $sClassname, $sPath, $params, 'general', 'interceptor');
    }

    /* ** Refactor into another class ** */
    /**
     * Register the plugin in the DB
     *
     * @param unknown_type $sClassName
     * @param unknown_type $path
     * @param unknown_type $object
     * @param unknown_type $type
     */
    function registerPluginHelper($sNamespace, $sClassName, $path, $object, $view, $type) {

        $sql = "SELECT id FROM plugin_helper WHERE namespace = '{$sNamespace}' AND classtype = '{$type}'";
        $res = DBUtil::getOneResult($sql);

        $aValues = array();
        $aValues['namespace'] = $sNamespace;
        $aValues['plugin'] = (!empty($this->sNamespace)) ? $this->sNamespace : $sNamespace;
        $aValues['classname'] = $sClassName;
        $aValues['pathname'] = $path;
        $aValues['object'] = $object;
        $aValues['viewtype'] = $view;
        $aValues['classtype'] = $type;

        // if record exists - update it.
        if(!empty($res)){
            $id = $res['id'];
            $updateRes = DBUtil::autoUpdate('plugin_helper', $aValues, $id);
            if(PEAR::isError($updateRes)){
                return $updateRes;
            }
            return true;
        }

        // Insert into DB
        $res = DBUtil::autoInsert('plugin_helper', $aValues);
        if(PEAR::isError($res)){
            return $res;
        }
        return true;
    }

    function deRegisterPluginHelper($sNamespace, $sClass) {
        $aWhere['namespace'] = $sNamespace;
        $aWhere['classtype'] = $sClass;
        $res = DBUtil::whereDelete('plugin_helper', $aWhere);
        return $res;
    }

    function _fixFilename($sFilename) {
        if (empty($sFilename)) {
            $sFilename = $this->sFilename;
        }

        if (!KTUtil::isAbsolutePath($sFilename)) {
            if ($this->sFilename) {
                $sDirPath = dirname($this->sFilename);
                $sFilename = sprintf("%s/%s", $sDirPath, $sFilename);
            }
        }

        $sKtDir = str_replace('\\', '/', KT_DIR);
        $sFilename = realpath($sFilename);
        $sFilename = str_replace('\\', '/', $sFilename);
        $sFilename = str_replace($sKtDir.'/', '', $sFilename);
        return $sFilename;
    }

    function isRegistered() {
        if ($this->bAlwaysInclude) {
            return true;
        }

        require_once(KT_LIB_DIR . '/plugins/pluginentity.inc.php');
        $oEntity = KTPluginEntity::getByNamespace($this->sNamespace);
        if (PEAR::isError($oEntity)) {
            if (is_a($oEntity, 'KTEntityNoObjects')) {
                // plugin not registered in database

                // XXX: nbm: Show an error on the page that a plugin
                // isn't registered or something, perhaps.
                return false;
            }
            return false;
        }

⌨️ 快捷键说明

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