|  | Posted by Tyno Gendo on 04/04/07 17:08 
Toby A Inkster wrote:> Tyno Gendo wrote:
 >
 >> I have been pondering over building a "modular" site which accepts
 >> add-ons built by other people.   I was wondering if anyone has any links
 >>   to any reading material on how you build this kind of facility into
 >> your site?
 >
 > The basic technique is this:
 >
 > 1. Provide a plugin registration function, which we'll call, say,
 > "plugin_register". When a plugin is loaded, it will call your
 > plugin_register function and tell your site at least the following
 > information:
 >
 > 	1. How to use the plugin -- i.e. provide a function name
 > 	   or a class name that the site can use to access the
 > 	   functionality of the plugin;
 >
 > 	2. When to use the plugin -- this is normally done via
 > 	   a named hook.
 >
 > So a particular plugin might be defined like this:
 >
 > 	<?php
 > 		function tobys_plugin ()
 > 		{
 > 			echo "<!-- Hello World -->\n";
 > 		}
 > 		plugin_register('tobys_plugin', 'onpagefinished');
 > 	?>
 >
 > Your plugin_register function would then add "tobys_plugin" to a list of
 > functions that need to be run when the page has finished outputting.
 >
 > Then in the rest of your code, add you hooks. For example, at the end of
 > each page, you'd have:
 >
 > 	<?php
 > 		run_plugins('onpagefinished');
 > 	?>
 >
 > where run_plugins looks at the list of registered plugins and runs the ones
 > that have registered using that hook.
 >
 > That's the simplified version. In real life, to allow the plugins to be
 > more useful, you'll often want to pass them particular parameters, such as
 > the current URL, the login name of the currently logged in user, etc. I'll
 > leave you to figure that out on your own.
 >
 
 Excellent, thanks for that reply.  I will have a toy around with
 something and of course follow up my post with an example when I get
 around to it.
  Navigation: [Reply to this message] |