counting hidden albums counting hidden albums
 

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

counting hidden albums

Started by E. William, December 14, 2013, 07:12:20 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

E. William

Hi guys,

How can I get the Album count on index.php to also count password protected and usergroup albums?

So, say I have a category with:
4 public albums
3 usergroup albums
2 password protected albums
1 private album

The count now is "4 album(s)", I'd like it to read "9 album(s)".

Αndré

Open index.php, find
    if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album) {
        $album_filter = ' ' . str_replace('p.', 'a.', $FORBIDDEN_SET);
        $pic_filter = $FORBIDDEN_SET;
    }

and either comment out/delete $album_filter or the whole block, depending if you also want to adjust the picture count.

E. William

Quote from: Αndré on December 16, 2013, 12:15:05 PM
Open index.php, find
    if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album) {
        $album_filter = ' ' . str_replace('p.', 'a.', $FORBIDDEN_SET);
        $pic_filter = $FORBIDDEN_SET;
    }

and either comment out/delete $album_filter or the whole block, depending if you also want to adjust the picture count.

Thanks for the reply Andre. This works great for the index page.

Unfortunately I asked the question wrong. How can make this work for album counts for the user galleries?

Αndré

So you want to count
Quote3 usergroup albums
2 password protected albums
1 private album
but just those, that reside in the user galleries category?

E. William

It's probably easier to show than it is to explain :).

Beware, this link will show explicit content further down the page, and some galleries contain explicit content as well:
http://lovedollgallery.com/gallery/index.php?cat=1

Here the user "Natsuki" has 6 albums:


  • three publicly available (Beautiful, Sexy, and Naughty)
  • one reserved for registered users (Kinky)
  • one password protected (Depraved)
  • and a Private album

Yet the count below the thumbnail says there are only 3 albums when you're not logged in, and 4 when you are.

I'd like it to say 5 albums all the time except for the administrator and "Natsuki" it should say 6 albums when they're logged in.

Αndré

So you don't want to change the overall stats bar (which seems to be disabled in your gallery), but change e.g.
QuoteNatsuki
3 album(s)
60 file(s)
to
QuoteNatsuki
5 album(s)
123 file(s)
which means, to count all albums except private albums, right? I assume the admin and Natsuki will be displayed already all 6 albums?

E. William


Αndré

Open bridge/udb_base.inc.php, find
// Get the total number of users with albums
and above, add
        $forbidden_aid = array();
        $result = cpg_db_query("SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE alb_password != '' AND visibility > ".FIRST_USER_CAT);
        while ($row = mysql_fetch_assoc($result)) {
            $forbidden_aid[] = $row['aid'];
        }
        mysql_free_result($result);
        if (count($forbidden_aid)) {
            $FORBIDDEN_SET = 'AND p.aid NOT IN ('.implode(', ', $forbidden_aid).')';
        } else {
            $FORBIDDEN_SET = '';
        }

E. William

Hi Andre,

Got it to work by making a small alteration:

        $forbidden_aid = array();
        $result = cpg_db_query("SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE alb_password = '' AND visibility > ".FIRST_USER_CAT);
        while ($row = mysql_fetch_assoc($result)) {
            $forbidden_aid[] = $row['aid'];
        }
        mysql_free_result($result);
        if (count($forbidden_aid)) {
            $FORBIDDEN_SET = 'AND p.aid NOT IN ('.implode(', ', $forbidden_aid).')';
        } else {
            $FORBIDDEN_SET = '';
        }


The count is now correct, but a new issue has popped up.
I have a user gallery with only password protected albums which now shows up correctly, however when I click it there's a Critical Error processing a Database Query.

Debug mode tells me:
While executing query 'SELECT r.pid, r.aid, filepath, filename, url_prefix, pwidth, pheight, filesize, pic_rating, ctime, r.title, r.keywords, r.votes, hits, caption, r.owner_id, user1, user2, user3, user4
                FROM cpg15x_pictures AS r
                INNER JOIN cpg15x_albums AS a ON a.aid = r.aid
                WHERE pid IN ()' in include/functions.inc.php on line 1894

mySQL error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 4


and that leads me pretty much to this:
//More random random photos
    case 'random': // Random files
        if ($cat && $CURRENT_CAT_NAME) {
            $album_name = cpg_fetch_icon('random', 2) . $lang_meta_album_names['random'] . ' - ' . $CURRENT_CAT_NAME;
        } else {
            $album_name = cpg_fetch_icon('random', 2) . $lang_meta_album_names['random'];
        }

        $query = "SELECT COUNT(*)
                FROM {$CONFIG['TABLE_PICTURES']} AS r
                INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
                $RESTRICTEDWHERE
                AND approved = 'YES'";

        $result = cpg_db_query($query);

        list($count) = mysql_fetch_row($result);
        mysql_free_result($result);

        $query = "SELECT pid
                FROM {$CONFIG['TABLE_PICTURES']} AS r
                INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
                $RESTRICTEDWHERE
                AND approved = 'YES'
                ORDER BY RAND()
                $limit";

        $result = cpg_db_query($query);

        $pidlist = array();
        while ($row = mysql_fetch_assoc($result)) {
            $pidlist[] = $row['pid'];
        }
        mysql_free_result($result);

        $select_columns = implode(', ', $select_column_list);

        $query = "SELECT $select_columns
                FROM {$CONFIG['TABLE_PICTURES']} AS r
                INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
                WHERE pid IN (" . implode(', ', $pidlist) . ")";

        $result = cpg_db_query($query);
        $rowset = cpg_db_fetch_rowset($result);
        mysql_free_result($result);

        shuffle($rowset);

        if ($set_caption) {
            build_caption($rowset, array('pic_rating', 'hits'));
        }

        $rowset = CPGPluginAPI::filter('thumb_caption_random', $rowset);

        return $rowset;

        break;


The problem is that it's trying to generate a random list from an empty array (since no photos are available to the public).
So I built in a check if there are photos to display, and if not, to return a "No image to display" message.

The new code in functions.inc.php is now:
//More random random photos
    case 'random': // Random files
        if ($cat && $CURRENT_CAT_NAME) {
            $album_name = cpg_fetch_icon('random', 2) . $lang_meta_album_names['random'] . ' - ' . $CURRENT_CAT_NAME;
        } else {
            $album_name = cpg_fetch_icon('random', 2) . $lang_meta_album_names['random'];
        }

        $query = "SELECT COUNT(*)
                FROM {$CONFIG['TABLE_PICTURES']} AS r
                INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
                $RESTRICTEDWHERE
                AND approved = 'YES'";

        $result = cpg_db_query($query);

        list($count) = mysql_fetch_row($result);
        mysql_free_result($result);

//my bright idea
if ($count != 0) {
        $query = "SELECT pid
                FROM {$CONFIG['TABLE_PICTURES']} AS r
                INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
                $RESTRICTEDWHERE
                AND approved = 'YES'
                ORDER BY RAND()
                $limit";

        $result = cpg_db_query($query);

        $pidlist = array();
        while ($row = mysql_fetch_assoc($result)) {
            $pidlist[] = $row['pid'];
        }
        mysql_free_result($result);

        $select_columns = implode(', ', $select_column_list);

        $query = "SELECT $select_columns
                FROM {$CONFIG['TABLE_PICTURES']} AS r
                INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = r.aid
                WHERE pid IN (" . implode(', ', $pidlist) . ")";

        $result = cpg_db_query($query);
        $rowset = cpg_db_fetch_rowset($result);
        mysql_free_result($result);

        shuffle($rowset);

        if ($set_caption) {
            build_caption($rowset, array('pic_rating', 'hits'));
        }
}
        $rowset = CPGPluginAPI::filter('thumb_caption_random', $rowset);

        return $rowset;

        break;


This seems to do the trick. It's probably not the most elegant solution, but hey :)...

E. William

Thought I had the topic solved, but now that I've made the first alteration, the private albums don't show up for the gallery owner or the administrator either.

        $forbidden_aid = array();
        $result = cpg_db_query("SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE alb_password = '' AND visibility > ".FIRST_USER_CAT);
        while ($row = mysql_fetch_assoc($result)) {
            $forbidden_aid[] = $row['aid'];
        }
        mysql_free_result($result);
        if (count($forbidden_aid)) {
            $FORBIDDEN_SET = 'AND p.aid NOT IN ('.implode(', ', $forbidden_aid).')';
        } else {
            $FORBIDDEN_SET = '';
        }


I'll see what the problem is logically, and try to come up with a fix.
I'll look to throw in a check to apply this logic only when not the gallery owner or administrator.

Αndré

I guess we shouldn't change $FORBIDDEN_SET, but use a different (new) variable. If so, we need to replace $FORBIDDEN_SET with that new variable inside that album. I've currently no access to a testbed, that's why I cannot check that.

E. William

Not sure if this helps, but I've managed to solve the problem for the administrator, but not yet for the gallery owner:

    if (GALLERY_ADMIN_MODE) {} else {
        $forbidden_aid = array();
        $result = cpg_db_query("SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE alb_password = '' AND visibility > ".FIRST_USER_CAT);
        while ($row = mysql_fetch_assoc($result)) {
            $forbidden_aid[] = $row['aid'];
        }
        mysql_free_result($result);
        if (count($forbidden_aid)) {
            $FORBIDDEN_SET = 'AND p.aid NOT IN ('.implode(', ', $forbidden_aid).')';
        } else {
            $FORBIDDEN_SET = '';
        }
    }


I've tried adding things like (GALLERY_ADMIN_MODE || USER_ADMIN_MODE && $cat == (USER_ID + FIRST_USER_CAT)) or (GALLERY_ADMIN_MODE || $cat == (USER_ID + FIRST_USER_CAT)) but those aren't working.

Maybe $FORBIDDEN_SET is the root cause of the problem, but I'll leave that to your good judgment :).

Αndré

Try
        if (!GALLERY_ADMIN_MODE) {
            $forbidden_aid = array();
            $user_own_gallery = USER_ID ? ' AND visibility != '.(FIRST_USER_CAT + USER_ID) : '';
            $result = cpg_db_query("SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE alb_password != '' AND visibility > ".FIRST_USER_CAT.$user_own_gallery);
            while ($row = mysql_fetch_assoc($result)) {
                $forbidden_aid[] = $row['aid'];
            }
            mysql_free_result($result);
            if (count($forbidden_aid)) {
                $FORBIDDEN_SET = 'AND p.aid NOT IN ('.implode(', ', $forbidden_aid).')';
            } else {
                $FORBIDDEN_SET = '';
            }
        }

E. William

Quote from: Αndré on December 19, 2013, 01:52:03 PM
Try
        if (!GALLERY_ADMIN_MODE) {
            $forbidden_aid = array();
            $user_own_gallery = USER_ID ? ' AND visibility != '.(FIRST_USER_CAT + USER_ID) : '';
            $result = cpg_db_query("SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE alb_password = '' AND visibility > ".FIRST_USER_CAT.$user_own_gallery);
            while ($row = mysql_fetch_assoc($result)) {
                $forbidden_aid[] = $row['aid'];
            }
            mysql_free_result($result);
            if (count($forbidden_aid)) {
                $FORBIDDEN_SET = 'AND p.aid NOT IN ('.implode(', ', $forbidden_aid).')';
            } else {
                $FORBIDDEN_SET = '';
            }
        }


Unfortunately this hasn't had the desired effect. It still won't show the albums for the gallery owner

Αndré

Which albums exactly are hidden?

E. William

I messed up, I'm sorry  :(.

I'd been setting album passwords from the Admin account, which changed the visibility to Admin's ID instead of the User's ID. Since it doesn't check the User ID for every album individually (and it doesn't have to) it wouldn't show the other albums either. Just have to be careful which account I use to change album visibility ;).

Now that I've changed these values in the database it works like a charm.

Consider this topic solved :)