Hide albums from latest and random Hide albums from latest and random
 

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]

Main Menu

Hide albums from latest and random

Started by NeoID, November 29, 2005, 07:37:36 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

NeoID

I'm using 1.4 and I'm very pleased with it but is it possible to block certain albums from being shown in the random and latest images tables?  :)

donnoman

#1
This can be done with plugins if were a little creative.

Modify the array: $unwanted_albs=array(1,25,14); to suit.

1,25,14 were just some sample albums that I was using for testing.

I zipped up the plugin it's attached to this post, the relevant code is below.

It isn't real pretty string manipulation, I'm sure someone who knows regexs like the back of thier hand could do it better... I just didn't want to think that much.


$thisplugin->add_filter('plugin_block','remove_meta_albs');

function remove_meta_albs($matches) {
    global $META_ALBUM_SET;
    if (is_array($matches)) {
        switch ($matches[1]) {
            case 'random':
            case 'lastup':
                $unwanted_albs=array(1,25,14);
                if ($META_ALBUM_SET) {
                    $parts=explode('(',$META_ALBUM_SET);
                    $head=$parts[0];
                    $parts=explode(')',$parts[1]);
                    $albums=explode(',',$parts[0]);
                    $new_albums=array_diff($albums,$unwanted_albs);
                    $META_ALBUM_SET=$head.'('.implode(',',$new_albums).')';
                }
                break;
        }
    }
    return $matches;
}

NeoID

Thanks, sounds nice, but how am I going to get this into coppermine? Do I just have to drop the files into the coppermine folder?


NeoID

I have some problems, the plugin doesn't seem to exclude the images from the last uploaded or random table.
I've changed $unwanted_albs=array(1,25,14); to $unwanted_albs=array(9); since 9 is the number of my album
I want to exclude. Are there other things that have to be done?  :)

donnoman

#5
#1 Make sure you did "install" the plugin. (It should be listed under "Installed Plugins" not "Plugins Not installed"
#2 replace the code in codebase with this:

$thisplugin->add_filter('plugin_block','remove_meta_albs'); //index.php
$thisplugin->add_filter('post_breadcrumb','remove_meta_albs'); //thumbnails.php

function filter_meta_album() {
    global $META_ALBUM_SET;
    $unwanted_albs=array(1,25,14);
    if ($META_ALBUM_SET) {
        $parts=explode('(',$META_ALBUM_SET);
        $head=$parts[0];
        $parts=explode(')',$parts[1]);
        $albums=explode(',',$parts[0]);
        $new_albums=array_diff($albums,$unwanted_albs);
        $META_ALBUM_SET=$head.'('.implode(',',$new_albums).')';
    } else {
        $META_ALBUM_SET='AND aid NOT IN ('.implode(',',$unwanted_albs).')';
    }
}

function remove_meta_albs($matches) {
    if (is_array($matches)) {
        static $run_once;
        if (!$run_once) {
            filter_meta_album();
            $run_once=true;
        }
    } elseif (defined('THUMBNAILS_PHP')) {
        filter_meta_album();
    }
    return $matches;
}


It should now filter the meta_album_set for the last_updated etc when displayed with thumbnails.php, including as an admin.

updated the plugin download.

noworyz

Not trying to hijack the thread but I had it working before that last bit of code you just posted.  Should I change the code also?

donnoman

probably.

There are two major differences.

#1 the previous code did not filter those albums for the admin.
#2 the previous code did not filter the meta albums when you clicked on say "last uploaded". It only filtered the blocks that are shown on the index.php page based on what you had configured in the "content of the main page".

noworyz

I made the change and I see no difference.  Either way it seems to be doing what it is supposed to!  Thanks!

NeoID


Joachim Müller


NeoID


Joachim Müller

@NeoID: you're not to blame, you posted in the proper board. The question goes at donnoman.

donnoman

#13
#1 Theres a problem with getting the wrong images with the previous versions of the plugin when using relative position when it's passed to displayimage.
#2 displayimage lacks a plugin hook that makes it possible to filter its meta_albums without MODDING displayimage.php.
#3 I've included instructions for making a single line mod to displayimage.php. Look in "readme.htm" for details.
#4 Theres a link to the readme.htm in the plugin description that you see on pluginmgr.php
#5 This thread can be moved to the plugins subfolder, but I would suggest that only COMPLETE plugins be moved. Threads that contain ideas for plugins to solve common problems should be left in the forum that spawned them until a complete plugin is created.

EDIT: There is a newer version of this plugin see: http://cpg-contrib.org/board/index.php?board=31.0

Joachim Müller

Quote from: donnoman on December 01, 2005, 06:03:19 AM
#5 This thread can be moved to the plugins subfolder, but I would suggest that only COMPLETE plugins be moved. Threads that contain ideas for plugins to solve common problems should be left in the forum that spawned them until a complete plugin is created.
I agree, that's why I asked. I should have been clearer: is the plugin stable enough to be added to the plugin contributions folder, or does it need further testing?

donnoman

I'm happy with it now. We won't officially add a new plugin hook until 1.5 so it will have to stay this way for the time being.

Tranz

Quote from: donnoman on December 01, 2005, 06:03:19 AM
#3 I've included instructions for making a single line mod to displayimage.php. Look in "readme.htm" for details.
No wonder I couldn't find the string anywhere in either cpg forums. :D I forgot why I added the hook.

Would it be an issue to include the hook in the CVS version of displayimage.php?

CPGPluginAPI::filter('displayimage_init',null);

NeoID

Quote from: donnoman on December 01, 2005, 06:28:40 AM
I'm happy with it now. We won't officially add a new plugin hook until 1.5 so it will have to stay this way for the time being.

The plugin hides the pictures from the specified albums, but there is one serious bug.
If I upload an image to an excluded album and then click on a thumbnail from the "last added images" list, all pictures/links are out of sync. If I click the thumbnail, I see another picture and not the one I wanted to see...

Not only the "last added images" get's messed up, but also the "last comment"...practically all links between the automatic-generated
thumbnails and the actual file-preview is messed up...

Sorry, but I can't give you a url to show you the problem, but I hope you understand the problem...(my english is bad...) ^_^

donnoman

Quote from: TranzNDance on December 29, 2005, 05:47:40 AM
Would it be an issue to include the hook in the CVS version of displayimage.php?

CPGPluginAPI::filter('displayimage_init',null);

I'm of the opinion that hooks should only change between major revisions like 1.4 and 1.5.

I also think that we need to rethink the placement of some of the existing plugin hooks, and we need more consistency in naming.  The place to make these changes are in the devel version, not stable.

wolle

Quote from: donnoman on November 29, 2005, 08:56:41 PM
[...]
I zipped up the plugin it's attached to this post, the relevant code is below.
[...]
Sorry but I couldn't find the plugin. Is there maybe a separate Plugin download page ?

Wolle