Hide empty categories - but not these containing another nonempty categories Hide empty categories - but not these containing another nonempty categories
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Hide empty categories - but not these containing another nonempty categories

Started by xhpohanka, May 04, 2011, 07:00:46 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

xhpohanka

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

Αndré

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.

xhpohanka

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

Αndré

I don't know where the best point to start is. The plugin modifies the function theme_display_cat_list. Instead of commenting out
            $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.

xhpohanka

Quote from: Αndré on May 05, 2011, 12:14:20 PM
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

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:

...
        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

Αndré

Can you please post your modifications like this:
QuoteIn file xyz.php, find
foo
and replace with
bar

Thanks.