Plugin Hook for Adding or Filtering Meta-Albums Plugin Hook for Adding or Filtering Meta-Albums
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Plugin Hook for Adding or Filtering Meta-Albums

Started by Paver, October 05, 2006, 12:52:59 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Paver

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.  I noted this for the plugin Search Album Title & Description, 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).  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:
        // 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.