Not Counting Views Made by Gallery 3.0.1 Admin

Update: June 22, 2011: This information also applies to Gallery version 3.0.2.

After upgrading my Gallery to version 3.0.1, I needed to re-add my code modifications to stop the gallery from counting views made by the administrator since I don’t care how many times I view my own pictures LOL. Some of the core files had changed so I had to make the following changes this time.

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

2
3
4
5
6
7
8
<?
if ($user->admin == '1') {
   $_SESSION['admin'] = true;
} else {
   $_SESSION['admin'] = false;
}
?>

Then in /modules/gallery/models/item.php around line 1019 modify the increment_view_count() function by adding the check around the query statement:

1019
1020
1021
1022
1023
1024
1025
  public function increment_view_count() {
    // mrh added the session admin check
    if(!$_SESSION['admin']) {
      db::query("UPDATE {items} SET `view_count` = `view_count` + 1 WHERE `id` = $this->id")
      ->execute();
    }
  }

Now, views will not be counted by the gallery administrator! Since I am the only one that uploads photos, this is all I need to do. For those wanting to stop view counts made by any owner of a photo, check out this thread on the Gallery forums. 🙂

One thought on “Not Counting Views Made by Gallery 3.0.1 Admin