forum.coppermine-gallery.net

No Support => Feature requests => Topic started by: Paver on October 05, 2006, 12:52:59 am

Title: Plugin Hook for Adding or Filtering Meta-Albums
Post by: Paver on October 05, 2006, 12:52:59 am
It is practically impossible to add or filter meta-albums with the current plugin hooks.  Donnoman first noted this on the CPG-Contrib board: Can't remove images from $rowset (http://cpg-contrib.org/board/index.php?topic=52.0).  I noted this for the plugin Search Album Title & Description (http://forum.coppermine-gallery.net/index.php?topic=26483.0), but in this case I was able to find a solution that used the current plugin hooks by overriding a current meta-album and not caring about the incorrect 'count' variable.  Recently, I converted Casper's Photo of the Day/Week mod and wanted to add new meta-albums for the PotD/W archives (PotD/W plugin (http://forum.coppermine-gallery.net/index.php?topic=36916.0)).  So I tried to consider carefully what would be required for a 'meta_album' plugin hook.  Here's my suggestion.

In include/functions.inc.php, just before the meta-albums switch block in the function get_pic_data, add the following block as shown:
Code: [Select]
        // MOD - begin - new plugin hook
        $meta_album_passto = array (
                'album' => $album,
                'limit' => $limit,
                'set_caption' => $set_caption,
        );
        $meta_album_params = CPGPluginAPI::filter('meta_album', $meta_album_passto);
        if ($meta_album_params['album_name']) {
                $album_name = $meta_album_params['album_name'];
                $count = $meta_album_params['count'];
                $rowset = $meta_album_params['rowset'];
                return $rowset;
        }
        // MOD - end - new plugin hook
 
      // Meta albums
        switch($album){
        case 'lastcom': // Last comments

As you can see, it's not a simple pass in one variable, receive back one variable plugin hook.  A plugin needs three input variables to do its thing: $album, $limit, $set_caption, and it needs to modify three variables: $album_name, $count, and $rowset (and remember that $rowset is a multi-dimensional array itself).  Hence, my suggestion to use a multi-dimensional associative array.  I'm not sure how else to do this.  Well, I do know one way: make all (or most) of these 6 variables global.  However, it seems like a bad idea to make variables global when you really want to do what I suggest: pass in necessary variables and pass out necessary variables.

I'm not sure if using such a method for the new plugin hook would cause performance issues.