📄 pluginutil.inc.php.svn-base
字号:
if(isset($aParams[5])){ $aParams[5] = KTPluginUtil::getFullPath($aParams[5]); } $aParams[3] = _kt($aParams[3]); $aParams[4] = _kt($aParams[4]); call_user_func_array(array(&$oAdminRegistry, 'registerLocation'), $aParams); break; case 'dashlet': if(isset($aParams[2])){ $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oDashletRegistry, 'registerDashlet'), $aParams); break; case 'i18nlang': if(isset($aParams[2]) && $aParams[2] != 'default'){ $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oi18nRegistry, 'registeri18nLang'), $aParams); case 'i18n': if(isset($aParams[2])){ $aParams[1] = $aParams[2]; unset($aParams[2]); } else { $aParams[1] = KTPluginUtil::getFullPath($aParams[1]); } call_user_func_array(array(&$oi18nRegistry, 'registeri18n'), $aParams); break; case 'language': call_user_func_array(array(&$oi18nRegistry, 'registerLanguage'), $aParams); break; case 'help_language': if(isset($aParams[2])){ $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oKTHelpRegistry, 'registerHelp'), $aParams); break; case 'workflow_trigger': if(isset($aParams[2])){ $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oWFTriggerRegistry, 'registerWorkflowTrigger'), $aParams); break; case 'column': if(isset($aParams[3])){ $aParams[3] = KTPluginUtil::getFullPath($aParams[3]); } $aParams[0] = _kt($aParams[0]); call_user_func_array(array(&$oColumnRegistry, 'registerColumn'), $aParams); break; case 'view': $aParams[0] = _kt($aParams[0]); call_user_func_array(array(&$oColumnRegistry, 'registerView'), $aParams); break; case 'notification_handler': if(isset($aParams[2])){ $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oNotificationHandlerRegistry, 'registerNotificationHandler'), $aParams); break; case 'template_location': if(isset($aParams[1])){ $aParams[1] = KTPluginUtil::getFullPath($aParams[1]); } call_user_func_array(array(&$oTemplating, 'addLocation2'), $aParams); break; case 'criterion': $aInit = unserialize($aParams[3]); if($aInit != false){ $aParams[3] = $aInit; } if(isset($aParams[2])){ $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oCriteriaRegistry, 'registerCriterion'), $aParams); break; case 'widget': if(isset($aParams[2])){ $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oWidgetFactory, 'registerWidget'), $aParams); break; case 'validator': if(isset($aParams[2])){ $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oValidatorFactory, 'registerValidator'), $aParams); break; case 'interceptor': if(isset($aParams[2])){ $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oInterceptorRegistry, 'registerInterceptor'), $aParams); break; case 'plugin': if(isset($aParams[2])){ $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } $oKTPluginRegistry->_aPluginDetails[$sName] = $aParams; break; } } } /** * Get the absolute path */ function getFullPath($sPath = '') { if(empty($sPath)){ return ''; } $sPath = (KTUtil::isAbsolutePath($sPath)) ? $sPath : KT_DIR . '/' . $sPath; return $sPath; } /** * This loads the plugins in the plugins folder. It searches for files ending with 'Plugin.php'. * This is called by the 'Re-read plugins' action in the web interface. */ function registerPlugins () { global $default; // Path to lock file $cacheDir = $default->cacheDirectory . DIRECTORY_SEPARATOR; $lockFile = $cacheDir.'plugin_register.lock'; // Check if the lock file exists if(KTPluginUtil::doCheck($lockFile)){ return true; } // Create the lock file, run through the plugin registration and then delete the lock file touch($lockFile); KTPluginUtil::doPluginRegistration(); @unlink($lockFile); } /** * Check the lockfile */ function doCheck($lockFile) { if(file_exists($lockFile)){ // If it does exist, do a stat on it to check when it was created. // if it was accessed more than 5 minutes ago then delete it and proceed with the plugin registration // otherwise wait till lock file is deleted signalling that the registration is complete and return. $stat = stat($lockFile); $time = time() - (60 * 5); if($stat['mtime'] > $time){ $cnt = 0; while(file_exists($lockFile)){ $cnt++; sleep(2); // if we've been waiting too long - typically it should only take a few seconds so 2 mins is too much time. if($cnt > 60){ @unlink($lockFile); return false; } } return true; } @unlink($lockFile); } return false; } /** * Read the plugins directory and register all plugins in the database. */ function doPluginRegistration() { global $default; KTPluginUtil::_deleteSmartyFiles(); require_once(KT_LIB_DIR . '/cache/cache.inc.php'); $oCache =& KTCache::getSingleton(); $oCache->deleteAllCaches(); // Remove all entries from the plugin_helper table and refresh it. $query = "DELETE FROM plugin_helper"; DBUtil::runQuery($query); $files = array(); KTPluginUtil::_walk(KT_DIR . '/plugins', $files); foreach ($files as $sFile) { $plugin_ending = "Plugin.php"; if (substr($sFile, -strlen($plugin_ending)) === $plugin_ending) { require_once($sFile); } } $oRegistry =& KTPluginRegistry::getSingleton(); $aRegistryList = $oRegistry->getPlugins(); foreach ($aRegistryList as $oPlugin) { $res = $oPlugin->register(); if (PEAR::isError($res)) { //var_dump($res); $default->log->debug('Register of plugin failed: ' . $res->getMessage()); } } $aPluginList = KTPluginEntity::getList(); foreach ($aPluginList as $oPluginEntity) { $sPath = $oPluginEntity->getPath(); if (!KTUtil::isAbsolutePath($sPath)) { $sPath = sprintf("%s/%s", KT_DIR, $sPath); } if (!file_exists($sPath)) { $oPluginEntity->setUnavailable(true); $oPluginEntity->setDisabled(true); $res = $oPluginEntity->update(); } } KTPluginEntity::clearAllCaches(); KTPluginUtil::_deleteSmartyFiles(); require_once(KT_LIB_DIR . '/cache/cache.inc.php'); $oCache =& KTCache::getSingleton(); $oCache->deleteAllCaches(); //KTPluginUtil::removePluginCache(); } function _deleteSmartyFiles() { $oConfig =& KTConfig::getSingleton(); $dir = sprintf('%s/%s', $oConfig->get('urls/varDirectory'), 'tmp'); $dh = @opendir($dir); if (empty($dh)) { return; } $aFiles = array(); while (false !== ($sFilename = readdir($dh))) { if (substr($sFilename, -10) == "smarty.inc") { $aFiles[] = sprintf('%s/%s', $dir, $sFilename); } if (substr($sFilename, -10) == "smarty.php") { $aFiles[] = sprintf('%s/%s', $dir, $sFilename); } } foreach ($aFiles as $sFile) { @unlink($sFile); } } function _walk ($path, &$files) { if (!is_dir($path)) { return; } $dirh = opendir($path); while (($entry = readdir($dirh)) !== false) { if (in_array($entry, array('.', '..'))) { continue; } $newpath = $path . '/' . $entry; if (is_dir($newpath)) { KTPluginUtil::_walk($newpath, $files); } if (!is_file($newpath)) { continue; } $files[] = $newpath; } } function resourceIsRegistered($path) { $oRegistry =& KTPluginResourceRegistry::getSingleton(); return $oRegistry->isRegistered($path); } function registerResource($path) { $oRegistry =& KTPluginResourceRegistry::getSingleton(); $oRegistry->registerResource($path); } function readResource($sPath) { global $default; $php_file = ".php"; if (substr($sPath, -strlen($php_file)) === $php_file) { require_once($php_file); } else { $pi = pathinfo($sPath); $mime_type = ""; $sExtension = KTUtil::arrayGet($pi, 'extension'); if (!empty($sExtension)) { $mime_type = DBUtil::getOneResultKey(array("SELECT mimetypes FROM " . $default->mimetypes_table . " WHERE LOWER(filetypes) = ?", $sExtension), "mimetypes"); } if (empty($mime_type)) { $mime_type = "application/octet-stream"; } $sFullPath = KT_DIR . '/plugins' . $sPath; header("Content-Type: $mime_type"); header("Content-Length: " . filesize($sFullPath)); readfile($sFullPath); } } // utility function to detect if the plugin is loaded and active. static function pluginIsActive($sNamespace) { $oReg =& KTPluginRegistry::getSingleton(); $plugin = $oReg->getPlugin($sNamespace); if (is_null($plugin) || PEAR::isError($plugin)) { return false; } // no such plugin else { // check if its active $ent = KTPluginEntity::getByNamespace($sNamespace); if (PEAR::isError($ent)) { return false; } // we now can ask return (!$ent->getDisabled()); } }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -