View RSS Feed

Nick's Hotaru CMS Blog

Plugin Order and Independence

Rate this Entry
I often say in the forums that the plugin order is important for everything to run smoothly, but this isn't entirely true anymore. A few versions ago, each plugin ran a function at the theme_index_top plugin hook, like this:

If a User page, show user posts,
If a Category page show category posts,
If a Tags page, show tag posts,
If a Search page, show search results,
Etc.

Nice and logical, right?

Wrong. The problem was that even though we knew the page name, we didn't know whether to show popular, upcoming or latest posts unless the SB Base plugin had run first. Often, you'd have to juggle the order of plugins until you got it working. The solution at the time was to change all those plugins to use a new hook: sb_base_theme_index_top which was put in SB Base itself, forcing them to run after SB Base has determined the kind of posts page.

Clever, eh?

No, not really, because that led all the plugins to require SB Base.... which is where we are at with Hotaru 1.2.

This evening, I've been going through some of the main plugins, removing all references to SB Base so that they can be used for other kinds of websites, too, not only social bookmarking. But doing this without reviving the old plugin order puzzles has again been tricky.

For my current test site, I've removed SB Base completely, but divided its functions over three plugins: Bookmarking, Post RSS and Archive. The solution I've come up with to the above problem is quite elegant, with just a touch of hackiness:

PHP Code:
    /**
     * theme_index_top
     */
    
public function theme_index_top($h)
    {
        
// check if this is for popular, upcoming, latest posts or other...
        
$this->determinePage($h);

        
// run all other theme_index_top functions except this one...
        
$h->pluginHook('theme_index_top''', array(), array('bookmarking'));

        
// we've now checked all the other plugins and know what to do, so...
        
$this->finalizePage($h);

        
// don't run anymore "theme_index_top" functions...
        
return "skip";
    } 
The Bookmarking plugin has to run first, but the order of other plugins shouldn't matter. First, we determine whether the page is for popular, upcoming or latest posts, and then we duplicate the theme_index_top hook, excluding the current plugin to avoid an infinite loop. Once all the other plugins have run their functions at that hook, we can then continue setting up the page in full knowledge of what the other plugins are trying to do. Finally, I've added the ability to return "skip", which will prevent the first theme_index_top calling all the plugins for a second time.

I need to do a lot more testing, but I think this is the key for successful communication between plugins and the "base" plugin, without tying them all up together.

Submit "Plugin Order and Independence" to Digg Submit "Plugin Order and Independence" to del.icio.us Submit "Plugin Order and Independence" to StumbleUpon Submit "Plugin Order and Independence" to Google

Categories
Plugins

Comments

  1. scrt's Avatar
    Hi Niick.

    I notice Hotaru requires hiarchy. structure for plugins. In magazine, upload image and key component are force on u (required to get the install magazine). In post image written by Ties, it works. But if I want Tim, install but user must know to follow the guideline (tim must be on top of post image in the install order).

    I am thinking of a new management interface like the old days of some software install. U check off what u want in the list of plugin to install. That management routine knows if other dependent are required (iplugin guideline requires the author to document and u can create a db table from this info automated) and thus complain with check mark orange of the list. Of course, all check marks must be green and orange are needed to install. Since user are checking off from a list, management software know to put tim above post image (db table has this info in the new management software) from the list. Click install and away we go (hidden, u know to install plugin base on if install or higher ver number to install). Hope u can get some sleep for u are everywhere ( plugin busy, forum response).

    I do not know if it helps but been in back of my mind regarding usage mistake by some. tx

    PS: if not clear, please pm and will clarify above.tx
    Modular engine showing all & using table or an automated generated table of dependency (if needed with father son hiarchy). Asteriick if special things need be done (like code modification and read appropriate forum for details - eg magazine * {thus telling user that this is complicated and u have to research to do code modification}).
    Updated 02-11-2011 at 02:35 PM by scrt

Trackbacks

Total Trackbacks 0
Trackback URL: