Category Archives: Gallery3

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. πŸ™‚

Gallery Upgraded to Version 3.0.1

A couple days ago I upgraded my Gallery to version 3.0.1. The process wasn’t quite as easy as it is to upgrade my blog these days in that it’s not just a simple point-and-click operation. Even so, it did go without issue as I understood how I needed to go about it. My process was as follows, which closely follows these upgrade instructions:

  1. Backed up the current database and files (I had modified several of the core code files so wanted to make sure I saved everything for later comparison).

  2. Created a new temporary directory both locally and on the server that would receive all the updated code before switching it to the live version.

  3. Copied over my customized .htaccess, robots.txt, favicon.ico, php.ini, local.php and other necessary files that I use into the new directory.

  4. Downloaded the Gallery 3.0.1 code and extracted it locally. I then removed the included .htaccess and robots.txt files so they would not overwrite my custom ones. I then re-zipped the files into the proper directory structure for my situation.

  5. Uploaded and extracted these files into the new directory I had made on the server.

  6. Copied over the /var directory to its corresponding location in the new directory I made in step 2.

  7. Changed my theme within the Gallery admin section to the default theme so that when I switched directories, it would have a theme to load as I knew I would be re-doing my custom theme based off the new default.

  8. I went to gallerymodules.com to make sure I had the latest versions of the 3rd-party modules that I use, several of which did have newer versions. I extracted the modules locally and combined them all into a single MYMODS.ZIP file to upload to the server. I then extracted these into the /modules directory of the new gallery directory I had created.

  9. Renamed my gallery directories such that the new code would be active and ran the upgrade script. It updated both core and 3rd-party modules that needed to be. The new gallery code was then active and everything seemed to work fine.

At this point it was time to re-create my theme with the new Gallery default Wind theme as the base and add back the various code tweaks I had made over time if needed. Rather than go into any code specifics with this post, I will make separate posts as warranted, most notably about how to not count views by the Gallery admin. πŸ™‚

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

2
3
4
5
6
7
8
<?
if ($user->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)

50
51
52
53
54
55
56
    $template->content = new View("photo.html");

    // mrh added the session admin check
    if(!$_SESSION['admin']) {
      $photo->view_count++;
    }
    $photo->save();

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

50
51
52
53
54
55
56
57
58
    $template->content = new View("movie.html");

    // mrh added the session admin check
    if (!$_SESSION['admin']) {
      $movie->view_count++;
    }
    $movie->save();

    print $template;

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

77
78
79
80
81
82
83
    // mrh added the session admin check
    if (!$_SESSION['admin']) {
      db::query("UPDATE {items} SET `view_count` = `view_count` + 1 WHERE `id` = $album->id")
      ->execute();
    }

    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! πŸ™‚

Gallery Changed to Gallery 3.0 Code.

Now that Gallery 3.0 Final has been released, I have changed my main Gallery to use it. This wasn’t an overnight thing as I have been using the Gallery 3 code in a test environment since it was in beta. Notice I did not say upgrade, but change. This is a completely new code base from Gallery 2. None of the modules or themes from Gallery 2 are compatible. Why the change? Well, the main reason is that working with the code in this version is so much easier. The database schema is also much easier to comprehend and deal with.

Because of this change, I did have to change how I get a random image from the Gallery to display on my blog and main website. It was fairly easy to make the switch. Because the database schema was easier, I was able to just do a direct database connection and MySQL query to get the information I needed. No inclusion of gallery code or use of Curl connections was necessary. A much more efficient process that took an averageΒ  of 0.2 seconds off the page load time for my blog!

The other fun part has been locating all the links and image references that needed to be changed. Think I have updated all of them in my blog and main website. For the external links I’ve been modifying the .htaccess file as situations arise. Here are few examples:

   # put redirects for old to new gallery links here
RewriteBase /
RewriteRule ^v/MyPics/HomeTheater/([A-Za-z_0-9\)\(\-]*)\.[A-Za-z]*\.html$ http://gallery.markheadrick.com/Home-Theater/$1 [R=301,L]
RewriteRule ^v/MyPics/([A-Za-z_0-9\)\(\-]*)\.[A-Za-z]*\.html$ http://gallery.markheadrick.com/MiscPics/$1 [R=301,L]
RewriteRule ^v/Nature/([A-Za-z_0-9\)\(\-]*)\.[A-Za-z]*\.html$ http://gallery.markheadrick.com/Nature/$1 [R=301,L]

The current (default) theme that the Gallery uses is heavy in JavaScript use. I’ll keep my eye out for a suitable theme that doesn’t use as much JavaScript; however, it’s really not that bad. Besides, customizing the themes in this version is much easier and since the final code was just released, it’s probably best to stay with the default theme for now. Actually, I do tend to use the default themes most of the time since they are guaranteed to be the most compatible with the latest core code.

Since this version works with Akismet, I have opened this gallery up for comments for now. I had to turn them off in the other one due to overwhelming amounts of spam at times even with captcha modules installed. So feel free to comment. πŸ™‚

I guess that’s about it for now. Hope you had a happy 10/10/10! πŸ™‚