📄 pluginutil.inc.php
字号:
<?php
/**
* $Id: pluginutil.inc.php 9476 2008-10-03 12:59:21Z 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 . '/plugins/pluginentity.inc.php');
require_once(KT_LIB_DIR . '/plugins/pluginregistry.inc.php');
class KTPluginResourceRegistry {
var $aResources = array();
function &getSingleton() {
if (!KTUtil::arrayGet($GLOBALS, 'oKTPluginResourceRegistry')) {
$GLOBALS['oKTPluginResourceRegistry'] = new KTPluginResourceRegistry;
}
return $GLOBALS['oKTPluginResourceRegistry'];
}
function registerResource($sPath) {
$this->aResources[$sPath] = true;
}
function isRegistered($sPath) {
if (KTUtil::arrayGet($this->aResources, $sPath)) {
return true;
}
$sPath = dirname($sPath);
if (KTUtil::arrayGet($this->aResources, $sPath)) {
return true;
}
return false;
}
}
class KTPluginUtil {
const CACHE_FILENAME = 'kt_plugins.cache';
/**
* Store the plugin cache in the cache directory.
* @deprecated
*/
static function savePluginCache($array)
{
$config = KTConfig::getSingleton();
$cachePlugins = $config->get('cache/cachePlugins', false);
if (!$cachePlugins)
{
return false;
}
$cacheDir = $config->get('cache/cacheDirectory');
$written = file_put_contents($cacheDir . '/' . KTPluginUtil::CACHE_FILENAME , serialize($array));
if (!$written)
{
global $default;
$default->log->warn('savePluginCache - The cache did not write anything.');
// try unlink a zero size file - just in case
@unlink($cacheFile);
}
}
/**
* Remove the plugin cache.
* @deprecated
*/
static function removePluginCache()
{
$config = KTConfig::getSingleton();
$cachePlugins = $config->get('cache/cachePlugins', false);
if (!$cachePlugins)
{
return false;
}
$cacheDir = $config->get('cache/cacheDirectory');
$cacheFile=$cacheDir . '/' . KTPluginUtil::CACHE_FILENAME;
@unlink($cacheFile);
}
/**
* Reads the plugin cache file. This must still be unserialised.
* @deprecated
* @return mixed Returns false on failure, or the serialised cache.
*/
static function readPluginCache()
{
$config = KTConfig::getSingleton();
$cachePlugins = $config->get('cache/cachePlugins', false);
if (!$cachePlugins)
{
return false;
}
$cacheDir = $config->get('cache/cacheDirectory');
$cacheFile=$cacheDir . '/' . KTPluginUtil::CACHE_FILENAME;
if (!is_file($cacheFile))
{
return false;
}
$cache = file_get_contents($cacheFile);
// we check for an empty cache in case there was a problem. We rather try and reload everything otherwise.
if (strlen($cache) == 0)
{
return false;
}
if (!class_exists('KTPluginEntityProxy')) {
KTEntityUtil::_proxyCreate('KTPluginEntity', 'KTPluginEntityProxy');
}
return unserialize($cache);
}
/**
* Load the plugins for the current page
*
* @param unknown_type $sType
*/
static function loadPlugins ($sType) {
// Check the current page - can be extended.
// Currently we only distinguish between the dashboard and everything else.
if($sType != 'dashboard'){
$sType = 'general';
}
$GLOBALS['_KT_PLUGIN'] = array();
$aPlugins = array();
$aPluginHelpers = array();
$aDisabled = array();
// Get the list of enabled plugins
$query = "SELECT h.classname, h.pathname, h.plugin FROM plugin_helper h
INNER JOIN plugins p ON (p.namespace = h.plugin)
WHERE p.disabled = 0 AND h.classtype='plugin' ORDER BY p.orderby";
$aPluginHelpers = DBUtil::getResultArray($query);
if(PEAR::isError($aPluginHelpers)){
global $default;
$default->log->debug('Error in pluginutil: '.$aPluginHelpers->getMessage());
return false;
}
// Check that there are plugins and if not, register them
if (empty($aPluginHelpers)) {
DBUtil::startTransaction();
KTPluginUtil::registerPlugins();
DBUtil::commit();
$query = "SELECT h.classname, h.pathname, h.plugin FROM plugin_helper h
INNER JOIN plugins p ON (p.namespace = h.plugin)
WHERE p.disabled = 0 AND h.classtype='plugin' ORDER BY p.orderby";
$aPluginHelpers = DBUtil::getResultArray($query);
}
// Create plugin objects
foreach ($aPluginHelpers as $aItem){
$classname = $aItem['classname'];
$path = $aItem['pathname'];
if (!empty($path)) {
$path = KT_DIR.'/'.$path;
require_once($path);
$oPlugin = new $classname($path);
if($oPlugin->load()){
$aPlugins[] = $oPlugin;
}else{
$aDisabled[] = "'{$aItem['plugin']}'";
}
}
}
$sDisabled = implode(',', $aDisabled);
// load plugin helpers into global space
$query = 'SELECT h.* FROM plugin_helper h
INNER JOIN plugins p ON (p.namespace = h.plugin)
WHERE p.disabled = 0 ';//WHERE viewtype='{$sType}'";
if(!empty($sDisabled)){
$query .= " AND h.plugin NOT IN ($sDisabled) ";
}
$query .= ' ORDER BY p.orderby';
$aPluginList = DBUtil::getResultArray($query);
KTPluginUtil::load($aPluginList);
// Load the template locations - ignore disabled plugins
// Allow for templates that don't correctly link to the plugin
$query = "SELECT * FROM plugin_helper h
LEFT JOIN plugins p ON (p.namespace = h.plugin)
WHERE h.classtype='locations' AND (disabled = 0 OR disabled IS NULL) AND unavailable = 0";
$aLocations = DBUtil::getResultArray($query);
if(!empty($aLocations)){
$oTemplating =& KTTemplating::getSingleton();
foreach ($aLocations as $location){
$aParams = explode('|', $location['object']);
call_user_func_array(array(&$oTemplating, 'addLocation2'), $aParams);
}
}
return true;
}
/**
* Load the plugins into the global space
*
* @param array $aPlugins
*/
function load($aPlugins) {
require_once(KT_LIB_DIR . '/actions/actionregistry.inc.php');
require_once(KT_LIB_DIR . '/actions/portletregistry.inc.php');
require_once(KT_LIB_DIR . '/triggers/triggerregistry.inc.php');
require_once(KT_LIB_DIR . '/plugins/pageregistry.inc.php');
require_once(KT_LIB_DIR . '/authentication/authenticationproviderregistry.inc.php');
require_once(KT_LIB_DIR . "/plugins/KTAdminNavigation.php");
require_once(KT_LIB_DIR . "/dashboard/dashletregistry.inc.php");
require_once(KT_LIB_DIR . "/i18n/i18nregistry.inc.php");
require_once(KT_LIB_DIR . "/help/help.inc.php");
require_once(KT_LIB_DIR . "/workflow/workflowutil.inc.php");
require_once(KT_LIB_DIR . "/widgets/widgetfactory.inc.php");
require_once(KT_LIB_DIR . "/validation/validatorfactory.inc.php");
require_once(KT_LIB_DIR . "/browse/columnregistry.inc.php");
require_once(KT_LIB_DIR . "/browse/criteriaregistry.php");
require_once(KT_LIB_DIR . "/authentication/interceptorregistry.inc.php");
$oPRegistry =& KTPortletRegistry::getSingleton();
$oTRegistry =& KTTriggerRegistry::getSingleton();
$oARegistry =& KTActionRegistry::getSingleton();
$oPageRegistry =& KTPageRegistry::getSingleton();
$oAPRegistry =& KTAuthenticationProviderRegistry::getSingleton();
$oAdminRegistry =& KTAdminNavigationRegistry::getSingleton();
$oDashletRegistry =& KTDashletRegistry::getSingleton();
$oi18nRegistry =& KTi18nRegistry::getSingleton();
$oKTHelpRegistry =& KTHelpRegistry::getSingleton();
$oWFTriggerRegistry =& KTWorkflowTriggerRegistry::getSingleton();
$oColumnRegistry =& KTColumnRegistry::getSingleton();
$oNotificationHandlerRegistry =& KTNotificationRegistry::getSingleton();
$oTemplating =& KTTemplating::getSingleton();
$oWidgetFactory =& KTWidgetFactory::getSingleton();
$oValidatorFactory =& KTValidatorFactory::getSingleton();
$oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
$oInterceptorRegistry =& KTInterceptorRegistry::getSingleton();
$oKTPluginRegistry =& KTPluginRegistry::getSingleton();
// Loop through the loaded plugins and register them for access
foreach ($aPlugins as $plugin){
$sName = $plugin['namespace'];
$sParams = $plugin['object'];
$aParams = explode('|', $sParams);
$sClassType = $plugin['classtype'];
switch ($sClassType) {
case 'portlet':
$aLocation = unserialize($aParams[0]);
if($aLocation != false){
$aParams[0] = $aLocation;
}
if(isset($aParams[3])){
$aParams[3] = KTPluginUtil::getFullPath($aParams[3]);
}
call_user_func_array(array(&$oPRegistry, 'registerPortlet'), $aParams);
break;
case 'trigger':
if(isset($aParams[4])){
$aParams[4] = KTPluginUtil::getFullPath($aParams[4]);
}
call_user_func_array(array(&$oTRegistry, 'registerTrigger'), $aParams);
break;
case 'action':
if(isset($aParams[3])){
$aParams[3] = KTPluginUtil::getFullPath($aParams[3]);
}
call_user_func_array(array(&$oARegistry, 'registerAction'), $aParams);
break;
case 'page':
if(isset($aParams[2])){
$aParams[2] = KTPluginUtil::getFullPath($aParams[2]);
}
call_user_func_array(array(&$oPageRegistry, 'registerPage'), $aParams);
break;
case 'authentication_provider':
if(isset($aParams[3])){
$aParams[3] = KTPluginUtil::getFullPath($aParams[3]);
}
$aParams[0] = _kt($aParams[0]);
call_user_func_array(array(&$oAPRegistry, 'registerAuthenticationProvider'), $aParams);
break;
case 'admin_category':
$aParams[1] = _kt($aParams[1]);
$aParams[2] = _kt($aParams[2]);
call_user_func_array(array(&$oAdminRegistry, 'registerCategory'), $aParams);
break;
case 'admin_page':
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -