[pLog-svn] r5534 - in plog/trunk/class: plugin view

mark at devel.lifetype.net mark at devel.lifetype.net
Tue Jun 12 14:21:28 EDT 2007


Author: mark
Date: 2007-06-12 14:21:28 -0400 (Tue, 12 Jun 2007)
New Revision: 5534

Modified:
   plog/trunk/class/plugin/pluginbase.class.php
   plog/trunk/class/plugin/pluginmanager.class.php
   plog/trunk/class/view/blogview.class.php
Log:
Merge Ahmad's code about dynamic plugin. Now developer can use:
$this->_isDynamic = true; or $this->setIsDynamic(true); to turn his plugin as a dynamic plugin.

And user can use :
{dynamic}
{$pluginObject->xxx()}
{/dynamic}
to play plugin in a cached page.

Only one problem is, it only pass the plugin object to the view, other obecjts like $blog, $url, ... will lost. So, if user/developer have to use those objects in a cached view, they should pass them to the cached view by them self. 

**This will increase the server loading and request time very much if too many plugins pass th cached view. So, use this function carefully.

Modified: plog/trunk/class/plugin/pluginbase.class.php
===================================================================
--- plog/trunk/class/plugin/pluginbase.class.php	2007-06-12 11:21:40 UTC (rev 5533)
+++ plog/trunk/class/plugin/pluginbase.class.php	2007-06-12 18:21:28 UTC (rev 5534)
@@ -86,6 +86,10 @@
 		 */
 		var $source;
 		
+		/**
+		 * This attribute will show us if we must send this plugin object in each request
+		 */
+		var $isDynamic = false;
 
     	/**
          * Constructor. Feel free to do here whatever you need to.
@@ -136,6 +140,16 @@
         }
 
         /**
+         * Returns if this plugin is dynamic
+         *
+         * @return true if its dynamic.
+         */
+        function getIsDynamic()
+        {
+        	return $this->isDynamic;
+        }
+
+        /**
          * This function is called only once when the plugin is registered. Please use this method
 		 * in case your plugin needs to perform some initializations before it is used, specially
 		 * if the initialization process requires access to the plugin/blog settings (because the
@@ -220,6 +234,18 @@
         }
         
         /**
+         * register a dynamic plugins
+         *
+         * @param isDynamic
+         * @return true
+         */
+        function setIsDynamic( $isDynamic = false )
+        {
+            $this->isDynamic = $isDynamic;
+            return true;
+        }
+
+        /**
          * registers a filter for the pipeline
          *
          * @param filterName Name of the class that implements the pipeline filter. It must implement the

Modified: plog/trunk/class/plugin/pluginmanager.class.php
===================================================================
--- plog/trunk/class/plugin/pluginmanager.class.php	2007-06-12 11:21:40 UTC (rev 5533)
+++ plog/trunk/class/plugin/pluginmanager.class.php	2007-06-12 18:21:28 UTC (rev 5534)
@@ -167,7 +167,7 @@
 		 * @param source
          */
         function loadPlugins( $source = "" )
-        {				
+        {
 			$classLoader =& ResourceClassLoader::getLoader();
 			
 			$this->_source = $source;
@@ -321,6 +321,27 @@
         }
 
         /**
+         * Returns the array of dynamic plugins.
+         *
+         * @return An array of PluginBase objects.
+         */
+        function getDynamicPlugins()
+        {
+            $dynamicPlugins = Array();
+            foreach( $this->_pluginList as $name ) {
+                if( array_key_exists( $name, $this->_pluginInstances ) ) {
+                    if( $this->_pluginInstances["$name"]->getIsDynamic() ) {
+                        $dynamicPlugins["$name"] =& $this->_pluginInstances["$name"];
+                        $dynamicPlugins["$name"]->setBlogInfo( $this->_blogInfo );
+                        $dynamicPlugins["$name"]->setUserInfo( $this->_userInfo );
+                        $dynamicPlugins["$name"]->register();
+                    }
+                }
+            }
+
+            return $dynamicPlugins;
+        }
+        /**
          * notifies all the event plugins about an event
          *
          * @param eventType

Modified: plog/trunk/class/view/blogview.class.php
===================================================================
--- plog/trunk/class/view/blogview.class.php	2007-06-12 11:21:40 UTC (rev 5533)
+++ plog/trunk/class/view/blogview.class.php	2007-06-12 18:21:28 UTC (rev 5534)
@@ -271,8 +271,12 @@
 				foreach( $plugins as $name => $plugin ) {
 					$this->setValue( $name, $plugin );
 				}
+			} else {
+			    $plugins = $this->_pm->getDynamicPlugins();
+				foreach( $plugins as $name => $plugin ) {
+					$this->setValue( $name, $plugin );
+				}
 			}
-
 			//
 			// these things can go in since they do not mean much overhead when generating the view...
 			//



More information about the pLog-svn mailing list