[pLog-svn] r486 - plog/trunk/class/plugin
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Mon Dec 13 23:43:27 GMT 2004
Author: oscar
Date: 2004-12-13 23:43:26 +0000 (Mon, 13 Dec 2004)
New Revision: 486
Modified:
plog/trunk/class/plugin/pluginmanager.class.php
Log:
removed some unneeded bits of code and integrated the new class loader in the PluginManager::loadPlugins method, so that action classes from plugins can also be dynamically loaded as long as they are in the $plugin/class/action folder. This should also help to save memory, by the way...
Modified: plog/trunk/class/plugin/pluginmanager.class.php
===================================================================
--- plog/trunk/class/plugin/pluginmanager.class.php 2004-12-13 23:42:03 UTC (rev 485)
+++ plog/trunk/class/plugin/pluginmanager.class.php 2004-12-13 23:43:26 UTC (rev 486)
@@ -13,6 +13,7 @@
include_once( PLOG_CLASS_PATH."class/controller/admincontroller.class.php" );
include_once( PLOG_CLASS_PATH."class/plugin/eventlist.properties.php" );
include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+ include_once( PLOG_CLASS_PATH."class/controller/resourceclassloader.class.php" );
/**
* other various constants
@@ -53,19 +54,19 @@
function PluginManager( $pluginDir = PLUGIN_MANAGER_DEFAULT_PLUGIN_FOLDER, $filePattern = PLUGIN_MANAGER_DEFAULT_PLUGIN_FILE_PATTERN )
{
$config =& Config::getConfig();
-
+
// initialize the arrays used to keep track of plugins and events
$this->_pluginEventList = Array();
- $this->_pluginInstances = Array();
-
+ $this->_pluginInstances = Array();
+
$this->_enabled = $config->getValue( "plugin_manager_enabled" );
$this->_pluginDir = $pluginDir;
$this->_filePattern = $filePattern;
-
- $this->_pluginList = $config->getValue( "plugin_list" );
- // just in case there is something wrong...
- if( $this->_pluginList == "" )
- $this->_pluginList = Array();
+
+ $this->_pluginList = $config->getValue( "plugin_list" );
+ // just in case there is something wrong...
+ if( $this->_pluginList == "" )
+ $this->_pluginList = Array();
}
/**
@@ -138,129 +139,89 @@
*
* @private
*/
- function loadPlugins_old()
- {
- foreach(Glob::glob($this->_pluginDir, "*") as $pluginFile ) {
- if( File::isDir($pluginFile)) {
- // build up the name of the file
- $pluginFileName = "plugin".array_pop(explode("/",$pluginFile)).".class.php";
- $pluginFullPath = PLOG_CLASS_PATH."$pluginFile/$pluginFileName";
- // and try to include it
- if( File::isReadable( $pluginFile."/".$pluginFileName )) {
- $className = str_replace(".class.php", "", basename($pluginFileName));
- include_once( $pluginFullPath );
- $classInstance = new $className();
- $name = $classInstance->getId();
- $supportedLocales = $classInstance->getSupportedLocales();
- foreach( $supportedLocales as $locale ) {
- $this->_loadPluginLocale( $classInstance->getId(), $locale );
- }
- $classInstance->setPluginFolder( PLOG_CLASS_PATH.$pluginFile."/" );
-
- if( $name == "" ) {
- throw( new Exception( "Plugin file $pluginFile has no identifier defined!" ));
- die();
- }
-
- //$this->log->debug( "Registering plugin $name with class $className from file $pluginFile" );
- if( $this->_pluginList["$name"] != "" ) {
- // problem! somebody has already registered a plugin with the same id!
- $errorMsg = "Plugin class $className: plugin id $name is already being used!";
- throw( new Exception( $errorMsg ));
- die();
- }
-
- $this->_pluginList["$name"] = $classInstance;
- }
- }
- }
-
- return true;
- }
-
- /**
- * Loads all the plugins from disk
- *
- * @private
- */
function loadPlugins()
{
- foreach( $this->_pluginList as $plugin ) {
- $pluginFile = "./plugins/$plugin";
- if( File::isDir($pluginFile)) {
- // build up the name of the file
- $pluginFileName = "plugin{$plugin}.class.php";
- $pluginFullPath = PLOG_CLASS_PATH."$pluginFile/$pluginFileName";
- // and try to include it
- if( File::isReadable( $pluginFile."/".$pluginFileName )) {
- $className = "Plugin".$plugin;
- include_once( $pluginFullPath );
- $classInstance = new $className();
- $name = $classInstance->getId();
- $supportedLocales = $classInstance->getSupportedLocales();
- foreach( $supportedLocales as $locale ) {
- $this->_loadPluginLocale( $classInstance->getId(), $locale );
- }
- $classInstance->setPluginFolder( PLOG_CLASS_PATH.$pluginFile."/" );
-
- if( $name == "" ) {
- throw( new Exception( "Plugin file $pluginFile has no identifier defined!" ));
- die();
- }
-
- $this->_pluginInstances["$plugin"] = $classInstance;
- }
- }
- }
-
- return true;
+ $classLoader =& ResourceClassLoader::getLoader();
+
+ foreach( $this->_pluginList as $plugin ) {
+ $pluginFile = "./plugins/$plugin";
+ if( File::isDir($pluginFile)) {
+ // build up the name of the file
+ $pluginFileName = "plugin{$plugin}.class.php";
+ $pluginFullPath = PLOG_CLASS_PATH."$pluginFile/$pluginFileName";
+ // and try to include it
+ if( File::isReadable( $pluginFile."/".$pluginFileName )) {
+ $className = "Plugin".$plugin;
+ include_once( $pluginFullPath );
+ $classInstance = new $className();
+ $name = $classInstance->getId();
+ $supportedLocales = $classInstance->getSupportedLocales();
+ foreach( $supportedLocales as $locale ) {
+ $this->_loadPluginLocale( $classInstance->getId(), $locale );
+ }
+ $classInstance->setPluginFolder( PLOG_CLASS_PATH.$pluginFile."/" );
+
+ // tell the resource loader that it should try to load actions from this folder
+ $classLoader->addSearchFolder( PLOG_CLASS_PATH."$pluginFile/class/action/" );
+
+ if( $name == "" ) {
+ throw( new Exception( "Plugin file $pluginFile has no identifier defined!" ));
+ die();
+ }
+
+ $this->_pluginInstances["$plugin"] = $classInstance;
+ }
+ }
+ }
+
+ return true;
}
- /**
- * refreshes the list of folders from disk
- */
- function getPluginListFromFolder()
- {
- $pluginList = Array();
-
- $pluginFiles = Glob::glob( $this->_pluginDir, "*" );
- if( !is_array( $pluginFiles ))
- return $pluginList;
-
+ /**
+ * refreshes the list of folders from disk
+ */
+ function getPluginListFromFolder()
+ {
+ $pluginList = Array();
+
+ $pluginFiles = Glob::glob( $this->_pluginDir, "*" );
+ if( !is_array( $pluginFiles ))
+ return $pluginList;
+
foreach( $pluginFiles as $pluginFile ) {
- if( File::isDir($pluginFile)) {
- // build up the name of the file
- $pluginId = array_pop(explode("/", $pluginFile));
- $pluginFileName = "plugin".$pluginId.".class.php";
- $pluginFullPath = PLOG_CLASS_PATH."$pluginFile/$pluginFileName";
- // and try to include it
- if( File::isReadable( $pluginFile."/".$pluginFileName )) {
- $pluginList[] = $pluginId;
- }
- }
+ if( File::isDir($pluginFile)) {
+ // build up the name of the file
+ $pluginId = array_pop(explode("/", $pluginFile));
+ $pluginFileName = "plugin".$pluginId.".class.php";
+ $pluginFullPath = PLOG_CLASS_PATH."$pluginFile/$pluginFileName";
+ // and try to include it
+ if( File::isReadable( $pluginFile."/".$pluginFileName )) {
+ $pluginList[] = $pluginId;
+ }
+ }
}
-
- return $pluginList;
- }
+
+ return $pluginList;
+ }
+
+ /**
+ * saves the list of plugins to the config backend
+ */
+ function savePluginList( $list )
+ {
+ $config =& Config::getConfig();
+ $config->setValue( "plugin_list", $list );
+ $config->save();
+ }
+
+ function refreshPluginList()
+ {
+ $this->_pluginList = $this->getPluginListFromFolder();
+ $this->savePluginList( $this->_pluginList );
+
+ return true;
+ }
- /**
- * saves the list of plugins to the config backend
- */
- function savePluginList( $list )
- {
- $config =& Config::getConfig();
- $config->setValue( "plugin_list", $list );
- $config->save();
- }
-
- function refreshPluginList()
- {
- $this->_pluginList = $this->getPluginListFromFolder();
- $this->savePluginList( $this->_pluginList );
-
- return true;
- }
-
function _loadPluginLocale( $pluginId, $locale )
{
return Locales::getPluginLocale( $pluginId, $locale );
@@ -284,11 +245,11 @@
function getPlugins()
{
foreach( $this->_pluginList as $name ) {
- if( $this->_pluginInstances["$name"] ) {
+ if( $this->_pluginInstances["$name"] ) {
$this->_pluginInstances["$name"]->setBlogInfo( &$this->_blogInfo );
$this->_pluginInstances["$name"]->setUserInfo( &$this->_userInfo );
$this->_pluginInstances["$name"]->register();
- }
+ }
}
return $this->_pluginInstances;
More information about the pLog-svn
mailing list