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: counting hidden albums  (Read 5393 times)

0 Members and 1 Guest are viewing this topic.

E. William

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 33
counting hidden albums
« on: December 14, 2013, 07:12:20 am »

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)".
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15757
Re: counting hidden albums
« Reply #1 on: December 16, 2013, 12:15:05 pm »

Open index.php, find
Code: [Select]
    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.
Logged

E. William

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 33
Re: Re: counting hidden albums
« Reply #2 on: December 16, 2013, 09:27:58 pm »

Open index.php, find
Code: [Select]
    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?
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15757
Re: counting hidden albums
« Reply #3 on: December 17, 2013, 12:28:16 pm »

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

E. William

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 33
Re: counting hidden albums
« Reply #4 on: December 17, 2013, 08:51:43 pm »

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

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15757
Re: counting hidden albums
« Reply #5 on: December 18, 2013, 08:58:25 am »

So you don't want to change the overall stats bar (which seems to be disabled in your gallery), but change e.g.
Quote
Natsuki
3 album(s)
60 file(s)
to
Quote
Natsuki
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?
Logged

E. William

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 33
Re: counting hidden albums
« Reply #6 on: December 18, 2013, 09:38:22 am »

That is correct :)
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15757
Re: counting hidden albums
« Reply #7 on: December 18, 2013, 03:03:53 pm »

Open bridge/udb_base.inc.php, find
Code: [Select]
// Get the total number of users with albumsand above, add
Code: [Select]
        $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 = '';
        }
Logged

E. William

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 33
Re: counting hidden albums
« Reply #8 on: December 18, 2013, 09:46:30 pm »

Hi Andre,

Got it to work by making a small alteration:

Code: [Select]
        $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:
Code: [Select]
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:
Code: [Select]
//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:
Code: [Select]
//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 :)...
Logged

E. William

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 33
Re: counting hidden albums
« Reply #9 on: December 18, 2013, 09:53:40 pm »

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.

Code: [Select]
        $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.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15757
Re: counting hidden albums
« Reply #10 on: December 18, 2013, 09:58:01 pm »

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

E. William

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 33
Re: counting hidden albums
« Reply #11 on: December 18, 2013, 10:36:03 pm »

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

Code: [Select]
    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 :).
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15757
Re: counting hidden albums
« Reply #12 on: December 19, 2013, 01:52:03 pm »

Try
Code: [Select]
        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 = '';
            }
        }
Logged

E. William

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 33
Re: Re: counting hidden albums
« Reply #13 on: December 20, 2013, 05:55:33 am »

Try
Code: [Select]
        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
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15757
Re: counting hidden albums
« Reply #14 on: December 21, 2013, 06:30:58 pm »

Which albums exactly are hidden?
Logged

E. William

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 33
Re: counting hidden albums
« Reply #15 on: December 22, 2013, 10:07:02 am »

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 :)
Logged
Pages: [1]   Go Up
 

Page created in 0.026 seconds with 20 queries.