[pLog-svn] r4786 - in plog/branches/lifetype-1.2: . class/plugin

oscar at devel.lifetype.net oscar at devel.lifetype.net
Mon Feb 19 15:54:56 EST 2007


Author: oscar
Date: 2007-02-19 15:54:56 -0500 (Mon, 19 Feb 2007)
New Revision: 4786

Modified:
   plog/branches/lifetype-1.2/admin.php
   plog/branches/lifetype-1.2/class/plugin/pluginbase.class.php
   plog/branches/lifetype-1.2/class/plugin/pluginmanager.class.php
   plog/branches/lifetype-1.2/index.php
Log:
Added an extra parameter to the constructor of the PluginBase class: $source. This parameter will be provided by the PluginManager class when instantiating plugin classes and it should be used by plugin classes to differentiate whether they're being called by index.php or admin.php. This also means that the constructor can react in different ways depending on the value of the $source parameter, so for example when it's index.php calling us there is no need to register menu entries or add new admin actions because they're not going to be used anyway... By making a few small changes in the authimage plugin to accommodate this new parameter, I was able to save over 500kb of memory in addition to over 2000 function and method calls, which I think is quite good. 

Of course this change means nothing unless plugins are adapted for it, but I will get round to modifying the ported plugins right away.

As a side effect this also means that our current implementation of dynamic menus is rubbish and that we should rethink the whole thing for 1.3 :)


Modified: plog/branches/lifetype-1.2/admin.php
===================================================================
--- plog/branches/lifetype-1.2/admin.php	2007-02-19 20:40:28 UTC (rev 4785)
+++ plog/branches/lifetype-1.2/admin.php	2007-02-19 20:54:56 UTC (rev 4786)
@@ -37,7 +37,7 @@
     // Controller::process() method, as some of the plugins _might_
     // add new actions to the controller
     $pluginManager =& PluginManager::getPluginManager();
-    $pluginManager->loadPlugins();
+    $pluginManager->loadPlugins( "admin" );
 
     // give control to the, ehem, controller :)
     $controller->process( HttpVars::getRequest(), "op");

Modified: plog/branches/lifetype-1.2/class/plugin/pluginbase.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/plugin/pluginbase.class.php	2007-02-19 20:40:28 UTC (rev 4785)
+++ plog/branches/lifetype-1.2/class/plugin/pluginbase.class.php	2007-02-19 20:54:56 UTC (rev 4786)
@@ -80,8 +80,14 @@
 
     	/**
          * Constructor. Feel free to do here whatever you need to.
+		 *
+		 * @param source Only defined to be 'blog' or 'admin'. This parameter should be used to determine
+		 * whether it is index.php registering this plugin ("index") or admin.php doing it ("admin") so that
+		 * we can perform different things. This means that the plugin can be initialized in two different ways
+		 * depending on whether we're being called via index.php or via admin.php so things like menu entries
+		 * or admin actions do not need to be registered unless it's admin.php calling, and so on.
          */
-    	function PluginBase()
+    	function PluginBase( $source = "" )
         {
         	
         }

Modified: plog/branches/lifetype-1.2/class/plugin/pluginmanager.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/plugin/pluginmanager.class.php	2007-02-19 20:40:28 UTC (rev 4785)
+++ plog/branches/lifetype-1.2/class/plugin/pluginmanager.class.php	2007-02-19 20:54:56 UTC (rev 4786)
@@ -41,6 +41,7 @@
         var $_blogInfo;
         var $_userInfo;
 		var $_pluginInstances;
+		var $_source;
 
         /**
          * global variable to save the list of plugins registered so far
@@ -60,9 +61,7 @@
          * @param filePattern
          */
         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
@@ -165,11 +164,13 @@
         /**
          * Loads all the plugins from disk
          *
-         * @private
+		 * @param source
          */
-        function loadPlugins()
+        function loadPlugins( $source )
         {				
 			$classLoader =& ResourceClassLoader::getLoader();
+			
+			$this->_source = $source;
 		
 			foreach( $this->_pluginList as $plugin ) {
 				$pluginFile = "./plugins/$plugin";
@@ -243,7 +244,7 @@
                	if( File::isReadable( $pluginFile."/".$pluginFileName )) {
 					$className = "Plugin".$plugin;
 					lt_include( $pluginFullPath );
-					$classInstance = new $className();						
+					$classInstance = new $className( $this->_source );						
 					$classInstance->setPluginFolder( PLOG_CLASS_PATH.$pluginFile."/" );	
 					$name = $classInstance->getId();
 					

Modified: plog/branches/lifetype-1.2/index.php
===================================================================
--- plog/branches/lifetype-1.2/index.php	2007-02-19 20:40:28 UTC (rev 4785)
+++ plog/branches/lifetype-1.2/index.php	2007-02-19 20:54:56 UTC (rev 4786)
@@ -45,7 +45,7 @@
     // Controller::process() method, as some of the plugins _might_
     // add new actions to the controller
     $pluginManager =& PluginManager::getPluginManager();
-    $pluginManager->loadPlugins();
+    $pluginManager->loadPlugins( "index" );
 	
     // give control to the, ehem, controller :)
     $controller->process( HttpVars::getRequest(), "op");	



More information about the pLog-svn mailing list