Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Plugin Hook for Adding or Filtering Meta-Albums  (Read 2882 times)

0 Members and 1 Guest are viewing this topic.

Paver

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 1609
  • Paul V.
Plugin Hook for Adding or Filtering Meta-Albums
« 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.  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:
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.
Logged
Pages: [1]   Go Up
 

Page created in 0.019 seconds with 20 queries.