Tag Archives: SQL

How to not count views made by the Gallery 3 Admin

If you’re like me, you like to know how many times your photos are viewed; however, you don’t want to count the views made by yourself because who cares how many times you look at one of your own images?

Here’s how I got Gallery 3.0 to stop counting my views as the gallery administrator. (Update 1-27-2011: For those that have upgraded to Gallery 3.0.1, please see this post.) I should mention that my target audience for this post are those that are familiar with editing PHP files and have a means to access their Gallery database (to reset the view_counts back to zero).

First, in /themes/(your theme)/views/page.html.php add the following code near the top (below the first line, making sure you keep the code within PHP opening and closing tags.):

admin == '1') {
   $_SESSION['admin'] = true;
} else {
   $_SESSION['admin'] = false;

Then, in /modules/gallery/controllers/photos.php modify the code around line 50: (make sure you do not leave the existing view_count++ statement outside the IF statements; otherwise, you’ll get duplicate view counts)

    $template->content = new View("photo.html");

    // mrh added the session admin check
    if(!$_SESSION['admin']) {

Then, in /modules/gallery/controllers/movies.php around line 50:

    $template->content = new View("movie.html");

    // mrh added the session admin check
    if (!$_SESSION['admin']) {

    print $template;

Finally, in /modules/gallery/controllers/albums.php around line 77:

    // mrh added the session admin check
    if (!$_SESSION['admin']) {
      db::query("UPDATE {items} SET `view_count` = `view_count` + 1 WHERE `id` = $album->id")

    print $template;

The Gallery will now not count any views made by the administrator which in my case, is me. :) To reset the view counts back to zero, the following SQL statement will work:

UPDATE items SET view_count = 0 WHERE view_count > 0;

Since you’re modifying the core Gallery code, be sure to make backups before applying any future upgrades as your changes will be lost.

Hopefully this helps! :)