Possible to set category thumbnail if all albums are keyword based in category? Possible to set category thumbnail if all albums are keyword based in category?
 

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

Possible to set category thumbnail if all albums are keyword based in category?

Started by tenacjed, January 12, 2014, 11:46:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

tenacjed

Site: http://www.waggonerphotography.com/gallery2/index.php?cat=0

Example Category of keyword based albums only: http://www.waggonerphotography.com/gallery2/index.php?cat=63

I have several categories with albums that are keyword based only.  I was wondering if it is possible to set a category thumbnail when the albums in the category are keyword based.  I can set thumbnails on the category where the pictures were actually uploaded to without issue.

Thanks!
John W
What a long... strange trip it's been!!!

gmc

I don't see anything in the database that would prevent this.The category (in cpg_categories) would need the 'thumb' value set to the 'pid' of the desired picture...

The interface determines the list of eligible pictures in catmgr.php on line 208 at 1.5.26 looking for pictures in albums contained in the category.
The logic here would need to be altered to also include pictures with a keyword(picture can have more than one - space separated by default, but could be another character based on config value) that matches the album keyword...

Need to dig a little deeper into the code..
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

tenacjed

I was a little surprised when I went to the category and the set picture was not there.  I was able to set all the thumbnail for the keyword based albums.  I thought for sure the category would be able to do the same.  No problem setting thumbnail on category that contained albums where the pictures were uploaded.
What a long... strange trip it's been!!!

Αndré

Please reply to this post so I get reminded to have a look at it later. Thanks.

tenacjed

What a long... strange trip it's been!!!

tenacjed

Just replying as a reminder for Andre to look into this one.  Hopefully I am not replying too soon!  Thanks again for any help that you can provide!
What a long... strange trip it's been!!!

Αndré

This seems to work for me as expected. Open catmgr.php, find
    if ($cid == USER_GAL_CAT) {
        $results = cpg_db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = p.aid WHERE a.category > ".FIRST_USER_CAT." AND approved = 'YES' ORDER BY filename");
    } else {
        $results = cpg_db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = p.aid WHERE a.category = $cid AND approved = 'YES' ORDER BY filename");
    }

and replace with
    $keyword = '';
    $result = cpg_db_query("SELECT DISTINCT keyword FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = $cid AND keyword != ''");
    if (mysql_num_rows($result)) {
        while ($row = mysql_fetch_assoc($result)) {
            $keyword .= "OR (keywords LIKE '%{$row['keyword']}%') ";
        }
    }
    mysql_free_result($result);

    if ($cid == USER_GAL_CAT) {
        $results = cpg_db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = p.aid WHERE (a.category > ".FIRST_USER_CAT." $keyword) AND approved = 'YES' ORDER BY filename");
    } else {
        $results = cpg_db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = p.aid WHERE (a.category = $cid $keyword) AND approved = 'YES' ORDER BY filename");
    }


Please report any unexpected behavior.

tenacjed

What a long... strange trip it's been!!!

Αndré

Here's improved code, as the previous code doesn't take care of the user gallery category. Please replace the previous code with this one and test again if it still works as expected:
    function cpg_get_alb_keyword($sql) {
        $keyword = '';
        $result = cpg_db_query($sql);
        if (mysql_num_rows($result)) {
            while ($row = mysql_fetch_assoc($result)) {
                $keyword .= "OR (keywords LIKE '%{$row['keyword']}%') ";
            }
        }
        mysql_free_result($result);
        return $keyword;
    }

    if ($cid == USER_GAL_CAT) {
        $keyword = cpg_get_alb_keyword("SELECT DISTINCT keyword FROM {$CONFIG['TABLE_ALBUMS']} WHERE category > ".FIRST_USER_CAT." AND keyword != ''");
        $results = cpg_db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = p.aid WHERE (a.category > ".FIRST_USER_CAT." $keyword) AND approved = 'YES' ORDER BY filename");
    } else {
        $keyword = cpg_get_alb_keyword("SELECT DISTINCT keyword FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = $cid AND keyword != ''");
        $results = cpg_db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = p.aid WHERE (a.category = $cid $keyword) AND approved = 'YES' ORDER BY filename");
    }

Αndré

Can someone please verify that the last code works as expected? Thanks.

gmc

Setting up a test for this... But a little confused..

The case of non-user categories is simple... And I think has been tested... Just creating a new category and having albums in it with no directly added pics - just keywords...  I'll apply your code and verify this again.

For user galleries, even if photos are directly added, where do I specify the category photo?  It seems to show last uploaded for each when viewing index.php?cat=1 - and I see no place to set a 'category photo'.

If I define a new user and add a single album specifying a keyword used in public albums... It displays the public photos with that keyword when logged on as that user and selecting 'My Gallery' (index.php?cat=10006) - but does not show in 'User Gallery' view (index.php?cat=1)
User keyword only albums don't seem to appear in the count of Albums in User Galleries on index.php...

I'm not sure what to test here for the user galleries case...
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

Αndré

If you open the category manager and edit a category, you can set a category thumbnail. Before the change, Coppermine just regards pictures of albums that reside in the current category. After the change, Coppermine also regards linked pictures. This means the linked pictures will be listed additionally. If there are no "regular" pictures, you wasn't able to set a category thumb, as the option wasn't displayed.

gmc

OK... I was trying to do it as a user for my user galleries - and not as Admin to the overall User Gallery category...
Will test and report.
Thanks for the clarification.
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

gmc

Tested on 1.5.26 and SVN 8660.
Linked pictures are now selectable for category thumbnails - including the overall 'user gallery' category.
Categories containing only albums with no direct photos now display the option to select a thumbnail from the list of linked photos.

Looks good to me!
Thanks!!
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

phill104

It is a mistake to think you can solve any major problems just with potatoes.

Αndré