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

oscar at devel.lifetype.net oscar at devel.lifetype.net
Thu Nov 24 20:26:43 GMT 2005


Author: oscar
Date: 2005-11-24 20:26:42 +0000 (Thu, 24 Nov 2005)
New Revision: 2628

Modified:
   plog/trunk/class/plugin/eventlist.properties.php
   plog/trunk/class/view/blogview.class.php
   plog/trunk/class/view/smartyview.class.php
Log:
Added a new event, EVENT_PROCESS_BLOG_TEMPLATE_OUTPUT that allows plugins to catch the content that will be sent to the client right before it is actually send so that it can be modified. This makes it much easier to develop plugins that for example add banner or ads to certain places of the template (like the hacks we've seen around the forums) 

Modified: plog/trunk/class/plugin/eventlist.properties.php
===================================================================
--- plog/trunk/class/plugin/eventlist.properties.php	2005-11-24 20:25:36 UTC (rev 2627)
+++ plog/trunk/class/plugin/eventlist.properties.php	2005-11-24 20:26:42 UTC (rev 2628)
@@ -172,4 +172,6 @@
 	define( "EVENT_PRE_DELETE_GLOBAL_CATEGORY", 123 );
 	define( "EVENT_POST_UPDATE_GLOBAL_CATEGORY", 124 );
 	define( "EVENT_GLOBAL_CATEGORIES_LOADED", 125 );	
+	// post-processing of templates
+	define( "EVENT_PROCESS_BLOG_TEMPLATE_OUTPUT", 126 );
 ?>
\ No newline at end of file

Modified: plog/trunk/class/view/blogview.class.php
===================================================================
--- plog/trunk/class/view/blogview.class.php	2005-11-24 20:25:36 UTC (rev 2627)
+++ plog/trunk/class/view/blogview.class.php	2005-11-24 20:26:42 UTC (rev 2628)
@@ -189,6 +189,24 @@
         }
 		
 		/**
+		 * @see Smartyview::preProcessViewContents()
+		 *
+		 * This reimplementation of this method adds support for events that can be caught in a plugin. This can be used
+		 * for for example in a plugin that processes the output of a template in order to add ads or do some other
+		 * dynamic operation with the content.
+		 *
+		 * @param content
+		 * @return The content
+		 */
+		function preProcessViewContents( $content )
+		{			
+			// pass the content and the name of the template file as a parameter to the event
+			$this->notifyEvent( EVENT_PROCESS_BLOG_TEMPLATE_OUTPUT, Array( 'content' => &$content, 'template' => $this->_templateName ));
+			
+			return( $content );
+		}		
+		
+		/**
 		 * Sets some  in this case, we leave it all up to the child classes to reimplement
 		 * this and by default call View::render()
 		 *

Modified: plog/trunk/class/view/smartyview.class.php
===================================================================
--- plog/trunk/class/view/smartyview.class.php	2005-11-24 20:25:36 UTC (rev 2627)
+++ plog/trunk/class/view/smartyview.class.php	2005-11-24 20:26:42 UTC (rev 2628)
@@ -165,6 +165,23 @@
 
 			return( $cacheTime );
 		}
+		
+		/**
+		 * Public method that allows view classes to do something to the content right before it is
+		 * sent to the client. It takes the content itself as a string as the first parameter and is
+		 * expected to return the final version of the content.
+		 *
+		 * This method is only called in case content needs to be returned. If HTTP caching is enabled and
+		 * the caching logic determines that no new data needs to be sent (only a Last-Modified header in that case)
+		 * then this method will <b>not</b> called.
+		 *
+		 * @param content the content generated after rendering the template but before being sent to the client
+		 * @return The final version of the content
+		 */
+		function preProcessViewContents( $content )
+		{
+			return( $content );
+		}
 
         /**
 		 * Renders the view using the Smarty template object that we created in the constructor. This method
@@ -203,8 +220,12 @@
 				// pass all the values to the template object
 				$this->_template->assign( $this->_params->getAsArray());			
 			
-				// and finally send the contents of the template
-				print( $this->_template->fetch( $this->getSmartyViewId()));			
+				// generate the contents
+				$content = 
+				
+				// and finally send them after calling the pre-processing method
+				$content = $this->preProcessViewContents( $this->_template->fetch( $this->getSmartyViewId()));				
+				print( $content );
 			}
         }
      }




More information about the pLog-svn mailing list