forum.coppermine-gallery.net

Support => cpg1.5.x Support => cpg1.5 themes (visuals) => Topic started by: tenacjed on January 12, 2014, 11:46:23 pm

Title: Possible to set category thumbnail if all albums are keyword based in category?
Post by: tenacjed on January 12, 2014, 11:46:23 pm
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
Title: Re: Possible to set category thumbnail if all albums are keyword based in category?
Post by: gmc on January 13, 2014, 01:06:55 am
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..
Title: Re: Possible to set category thumbnail if all albums are keyword based in category?
Post by: tenacjed on January 13, 2014, 01:45:56 am
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.
Title: Re: Possible to set category thumbnail if all albums are keyword based in category?
Post by: Αndré on January 13, 2014, 03:53:02 pm
Please reply to this post so I get reminded to have a look at it later. Thanks.
Title: Re: Possible to set category thumbnail if all albums are keyword based in category?
Post by: tenacjed on January 13, 2014, 05:08:51 pm
Thank you for any help you can provide!
Title: Re: Possible to set category thumbnail if all albums are keyword based in category?
Post by: tenacjed on January 17, 2014, 12:16:22 pm
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!
Title: Re: Possible to set category thumbnail if all albums are keyword based in category?
Post by: Αndré on January 20, 2014, 02:40:48 pm
This seems to work for me as expected. Open catmgr.php, find
Code: [Select]
    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
Code: [Select]
    $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.
Title: Re: Possible to set category thumbnail if all albums are keyword based in category?
Post by: tenacjed on January 20, 2014, 05:56:44 pm
Αndré,

Thank you very much, this worked perfectly!
Title: Re: Possible to set category thumbnail if all albums are keyword based in category?
Post by: Αndré on January 21, 2014, 10:56:42 am
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:
Code: [Select]
    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");
    }
Title: Re: Possible to set category thumbnail if all albums are keyword based in category?
Post by: Αndré on January 28, 2014, 03:24:19 pm
Can someone please verify that the last code works as expected? Thanks.
Title: Re: Possible to set category thumbnail if all albums are keyword based in category?
Post by: gmc on January 28, 2014, 04:30:01 pm
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...
Title: Re: Possible to set category thumbnail if all albums are keyword based in category?
Post by: Αndré on January 28, 2014, 05:13:41 pm
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.
Title: Re: Possible to set category thumbnail if all albums are keyword based in category?
Post by: gmc on January 28, 2014, 05:17:36 pm
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.
Title: Re: Possible to set category thumbnail if all albums are keyword based in category?
Post by: gmc on January 28, 2014, 06:27:19 pm
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!!
Title: Re: Possible to set category thumbnail if all albums are keyword based in category?
Post by: Phill Luckhurst on January 28, 2014, 07:44:37 pm
Looks good to me too. Great work all.
Title: Re: Possible to set category thumbnail if all albums are keyword based in category?
Post by: Αndré on January 29, 2014, 09:23:02 am
Committed proposed fix in SVN revision 8663.