Thumbnail for Category with nested categories Thumbnail for Category with nested categories
 

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

Thumbnail for Category with nested categories

Started by Drew Fulton, June 29, 2006, 02:14:41 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Drew Fulton

I have a complex system of nested Categories that are based of biological taxonomy (I am a nature photographer).  For example I may have a category like this.

Birds (cat)
  -> Passeriformes (cat)
        -> Parulidae (cat)
               -> Yellow Warbler (album)

Is there any way to get both the Birds category and the Passeriformes category to have thumbnails?  I tried creating an album in there and making it only visible to me but that doesn't work cuase no one else can see them. 

Thanks for the help.

Drew

Gizmo

Here's the link to the section in the manual for adding info and photos to categories: http://coppermine-gallery.net/demo/cpg14x/docs/index.htm#cat_cp.
Did you read the manual first???? Taking 2 minutes to backup your files can save you hours of wondering what you screwed up.
Billy Bullock - BullsEyePhotos Blog of Indecision

Drew Fulton

Thanks Gizmo,
  I have read through that several times and the problem is this line at the end of it.

"You can only assign a picture to the category only if you have an album with images nested directly within it"

I need to assign a picture to a category that has another category with albums nested within it, not a category that has an album nested directly. 

Any ideas for a work around?

Drew

Gizmo

Yes... my mistake. Without adding an album with a single photo, you may need to edit the database table for the category but I would wait for a dev or someone who may have an answer if there is a way before doing this.  :-\ Sorry...
Did you read the manual first???? Taking 2 minutes to backup your files can save you hours of wondering what you screwed up.
Billy Bullock - BullsEyePhotos Blog of Indecision

Paver

#4
Ok, here's a mod to do what you want.  As noted in posts below, this mod will not do what was requested.  This mod will pull in the ancestors of the current category, not the children.  Keep reading this thread for the correct solution.

Modify the file catmgr.php in the function form_alb_thumb by replacing this line:
$results = cpg_db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']},{$CONFIG['TABLE_ALBUMS']} WHERE {$CONFIG['TABLE_PICTURES']}.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND {$CONFIG['TABLE_ALBUMS']}.category = '$cid' AND approved='YES' ORDER BY filename");
with this block of lines:
    // MOD - Comment next line to replace with the following mod block
    // $results = cpg_db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']},{$CONFIG['TABLE_ALBUMS']} WHERE {$CONFIG['TABLE_PICTURES']}.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND {$CONFIG['TABLE_ALBUMS']}.category = '$cid' AND approved='YES' ORDER BY filename");

    // MOD - show all pictures from category ancestry

    // Get the ancestry of all categories
    // - Should modify to only get the ancestry of the current category
    $vQuery = "SELECT cid, parent, name FROM " . $CONFIG['TABLE_CATEGORIES'] . " WHERE 1";
    $vResult = cpg_db_query($vQuery);
    $vRes = cpg_db_fetch_rowset($vResult);
    mysql_free_result($vResult);
    foreach ($vRes as $vResI => $vResV) {
        $vResRow = $vRes[$vResI];
        $catParent[$vResRow['cid']] = $vResRow['parent'];
        $catName[$vResRow['cid']] = $vResRow['name'];
    }
    $catAnces = array();
    foreach ($catParent as $cid_id => $cid_parent) {
        $catAnces[$cid_id] = '';
        while ($cid_parent != 0) {
            $catAnces[$cid_id] = $cid_parent . ($catAnces[$cid_id]?','.$catAnces[$cid_id]:'');
            $cid_parent = $catParent[$cid_parent];
        }
    }

    // Pull out the ancestry of the current category
    $catAncestors = $catAnces[$cid] . ($catAnces[$cid] ? ',' : '') . $cid;
    $catQuery = ($catAncestors ? "IN ({$catAncestors})" : "=''");

    // Now do the query for all ancestor categories
    if ($catAncestors) {
        $results = cpg_db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']},{$CONFIG['TABLE_ALBUMS']} WHERE {$CONFIG['TABLE_PICTURES']}.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND {$CONFIG['TABLE_ALBUMS']}.category $catQuery AND approved='YES' ORDER BY filename");
    } 
    // MOD - END


It's not an efficient mod because it pulls in the ancestry of all categories, then picks out the one you are editting.  I pulled this code from a mod to upload.php I posted on this thread.  I don't have time to fiddle with it yet, but I don't think it should slow down the category editting noticeably unless you have hundreds of categories (which you might at some point if you are doing a taxonomy).  If it is slowing things down or you merely would like some help with more efficient code in the future, let me know.

Drew Fulton

Hey Paver,
  Thanks for your offer to help.  I just uploaded the new catmgr.php file and it doesn't seem to make any change at all.  I still can't select a thumbnail for the upper level categories, only those low level categories that have albums with images.  Any other ideas?

Drew

Paver

Heh.  I did the opposite of what you want - you want the children categories, not the ancestors.  I guess I read your post a little too quickly.  Let me look into it.

Drew Fulton

Haha, I was thinking that might have been what you did.  No rush, I am running the automatically installed version from GoDaddy and realized I need to upgrade to 1.4.8 so I will be doing that for a while.

Thanks again for your help.

Drew

Paver

Ok.  Try this.  <fingers crossed>

Modify catmgr.php, function form_alb_thumb by replacing this line:
$results = cpg_db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']},{$CONFIG['TABLE_ALBUMS']} WHERE {$CONFIG['TABLE_PICTURES']}.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND {$CONFIG['TABLE_ALBUMS']}.category = '$cid' AND approved='YES' ORDER BY filename");
with this block:
    // MOD - Comment next line to replace with the following mod block
    // $results = cpg_db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']},{$CONFIG['TABLE_ALBUMS']} WHERE {$CONFIG['TABLE_PICTURES']}.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND {$CONFIG['TABLE_ALBUMS']}.category = '$cid' AND approved='YES' ORDER BY filename");

    // MOD - show all pictures from children categories
    $catChildren = '';
    $totalcat_cid_list = $cid ? array($cid) : false;
    while ($totalcat_cid_list) {
        $totalcat_cid = array_pop($totalcat_cid_list);
        $totalcat_result = cpg_db_query("SELECT cid FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = {$totalcat_cid}");
        while ($totalcat_row = mysql_fetch_array($totalcat_result)) {
            array_push($totalcat_cid_list, $totalcat_row['cid']);
        }
        mysql_free_result($totalcat_result);
        $catChildren .= ($catChildren ? ',' : '') . $totalcat_cid;
    }
    if ($catChildren) {
        $catQuery = ($catChildren ? "IN ({$catChildren})" : "=''");
        $results = cpg_db_query("SELECT pid, filepath, filename, url_prefix FROM {$CONFIG['TABLE_PICTURES']},{$CONFIG['TABLE_ALBUMS']} WHERE {$CONFIG['TABLE_PICTURES']}.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND {$CONFIG['TABLE_ALBUMS']}.category $catQuery AND approved='YES' ORDER BY filename");
    } 
    // MOD - END


Let me know if this is the correct feature you want.  This code is based on this mod to the CPGOcat plugin.

Drew Fulton

Paver,
  Getting so close. 

  Your code allows me to add a thumbnail in the Category manager but now I can't get it to display it when you are browsing the gallery.

Here's the link:

http://www.infinitehorizonsphotography.com/galleries/index.php?cat=2

I have now added a thumbnail to the Pelecaniformes Category in the Category manager but as you can see, its not displaying.

Thanks again.

Drew

Paver

Ok, I think I found it.  In file index.php, in the function get_subcat_data, look for the following lines:
                if ($pic_count == 0 && $album_count == 0) {
                    $user_thumb = $ident;
                    $cat_data[] = array($link, $subcat['description'], 'cat_thumb' => $user_thumb);

and comment out the second line as shown:
                if ($pic_count == 0 && $album_count == 0) {
                    // $user_thumb = $ident;  // MOD - to allow cat thumbs for no-album parent categories
                    $cat_data[] = array($link, $subcat['description'], 'cat_thumb' => $user_thumb);

I added in the comment afterwards so that you'll know this is a mod to the default script.  Before you do an upgrade to later versions of Coppermine, you should have a list of mods you made so you can re-apply them after the upgrade.  Having a set comment like // MOD - makes it easier to make a list if you don't have one already.

I think your request is a useful feature for the next major version of Coppermine (1.5) - as an option of course.  I'll look into it.

Let me know if this works and if there are any other issues.

Drew Fulton

That does it! 

Thanks so much Paver. 

I must say that I have dealt with a lot of software companies, many whom I have paid large bucks for their software and I have never had service like this.

Thanks so much.

Drew

Paver

You're welcome.  Those are very kind words.  I appreciate it.

PKIDelirium

I have a quick question regarding this mod. This doesn't alter the database, correct?

Paver

Quote from: PKIDelirium on October 17, 2006, 04:26:27 AM
I have a quick question regarding this mod. This doesn't alter the database, correct?

Correct.  The only queries in the mod are SELECT queries, which are read-only (generally and specifically in this case).

PKIDelirium

Hello,

I recently upgraded to 1.4.10. As soon as I upgraded I re-applied this mod. Tonight I needed to add a new category and category thumbnail to it for the first time since upgrading, and I am unable to edit or add a thumbnail to ANY category. The thumbnails all display correctly on regular cats as well as the ones this mod was written for, but the thumbnail controlled no longer appears in the Categories panel.

PKIDelirium

Bump.

Does anyone know why this did not function correctly after upgrade to 1.4.10? My gallery is slightly difficult to navigate without this in place.

Drew Fulton

Back in June of 2006, I set up my first Coppermine gallery and posted this question.  Paver was quick to come up with a great solution for me.  I am now putting together a new site and am finally updating to a new version of coppermine and this time it isn't working.  Here is the link to the previous thread.  Anyone have any ideas on how to remedy the problem?


http://forum.coppermine-gallery.net/index.php?topic=33310.0

Thank you very much for any and all help.

Drew

Joachim Müller

Merged your new thread with the existing one.

AndrewC

Quote from: Paver on June 30, 2006, 04:17:30 AM
.....
I think your request is a useful feature for the next major version of Coppermine (1.5) - as an option of course.  I'll look into it.
.....

Did it ever make it into 1.5.x ?  Searching the forums it seems not

http://forum.coppermine-gallery.net/index.php/topic,61903.0.html

... but perhaps someone has a clever workaround or it is about to happen.

Andrew