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: Hide empty categories - but not these containing another nonempty categories  (Read 3438 times)

0 Members and 1 Guest are viewing this topic.

xhpohanka

  • Coppermine newbie
  • Offline Offline
  • Posts: 3

Hello,
I know there was a similar question some days ago, also there exists a plugin that hides empty categories but it affectes also 'parent' categories which contains no albums but another nonempty ones. How can I please let the parent categories (but with no albums) still visible?

regards
Jan

http://galerie.honza-centrum.cz/galerie/index.html
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764

That's no trivial task according to how the catlist is currently built. You'd need to check for every category with all their sub-categories if they contain albums/files the user is able to access. I currently don't see a straight-forward solution. Maybe you should hire a freelancer.
Logged

xhpohanka

  • Coppermine newbie
  • Offline Offline
  • Posts: 3

I think I should be able to implement it, just please give me a short advice where to start, please...
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764

I don't know where the best point to start is. The plugin modifies the function theme_display_cat_list. Instead of commenting out
Code: [Select]
            $params = array(
                    '{CAT_TITLE}' => $category[0],
                    '{CAT_THUMB}' => $category['cat_thumb'],
                    '{CAT_DESC}' => $category[1],
            );
            echo template_eval($template_noalb, $params);
in general you could add a check if the category is really 'empty'.

Maybe it's easier to add some checks at an earlier stage, but I haven't checked that.

If you find a solution I suggest to share it in this or in the plugin thread.
Logged

xhpohanka

  • Coppermine newbie
  • Offline Offline
  • Posts: 3

Maybe it's easier to add some checks at an earlier stage, but I haven't checked that.

If you find a solution I suggest to share it in this or in the plugin thread.

If someone is interested I have done small modifications in index.php and theme.inc.php to achieve proposed behavior.

index.php: add information about subcat_alb_count
Code: [Select]
function get_subcat_data(&$cat_data)
...
while ( ($row = mysql_fetch_assoc($result)) ) {
           
        if ($row['cid'] == 1) {
       
            if (!empty($user_galleries)) {
                $categories[$row['cid']] = $user_galleries;
            }
           
            continue;
        }

        $categories[$row['cid']]['details'] = array(
            'name'        => $row['name'],
            'description' => $row['description'],
            'thumb'       => $row['thumb'],
            'level'       => $row['depth'],
            'alb_count'   => 0,           
            'subcat_alb_count' => 0,
        );
       
    } // while

    mysql_free_result($result);
   
    // collect album counts for categories that are visible
    $sql = "SELECT category, COUNT(*) AS num, c.parent
        FROM {$CONFIG['TABLE_ALBUMS']} AS a
        INNER JOIN {$CONFIG['TABLE_CATEGORIES']} AS c ON cid = category
        WHERE depth BETWEEN $CURRENT_CAT_DEPTH + 1 AND $CURRENT_CAT_DEPTH + {$CONFIG['subcat_level']}";

    // if we are in a category, restrict info to children
    if ($rgt) {
        $sql .= "\nAND lft BETWEEN $lft AND $rgt";
    }

    if (!$CONFIG['show_private'] && $FORBIDDEN_SET_DATA) {
        $sql .= ' AND a.aid NOT IN (' . implode(', ', $FORBIDDEN_SET_DATA) . ')';
    }
   
    // we don't care about the order
    $sql .= "\nGROUP BY category ORDER BY NULL";

    $result = cpg_db_query($sql);

    while ( ($row = mysql_fetch_assoc($result)) ) {
        $categories[$row['category']]['details']['alb_count'] = $row['num'];
        if ($row['parent'] != 0) {
            $categories[$row['parent']]['details']['subcat_alb_count'] = $row['num'];
        }
    }
...
           if ($pic_count == 0 && $album_count == 0) {
                $user_thumb = str_repeat($indent, $level-1);
                $cat_data[] = array($link, $cat['details']['description'], 'cat_thumb' => $user_thumb, 'subcat_alb_count' => $cat['details']['subcat_alb_count']);
            } else {
...

theme.inc.php:
Code: [Select]
...
        if (!isset($category['cat_thumb'])) { $category['cat_thumb'] = ''; }
        if (count($category) == 4) {
            if ($category['subcat_alb_count'] > 0) {
                $params = array(
                        '{CAT_TITLE}' => $category[0],
                        '{CAT_THUMB}' => $category['cat_thumb'],
                        '{CAT_DESC}' => $category[1],
                );
                echo template_eval($template_noalb, $params);           
            }
        }
...

regards
Jan
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764

Can you please post your modifications like this:
Quote
In file xyz.php, find
Code: [Select]
fooand replace with
Code: [Select]
bar

Thanks.
Logged
Pages: [1]   Go Up
 

Page created in 0.02 seconds with 20 queries.