?>

Gallery-Link Plugin for Movable Type (Version 1.1)

Overview

This MovableType plugin allows you to add graphical links to photos on your Gallery website in a way that required much less cutting and pasting and will probably save you much headache if you move your Gallery site.  (Gallery is a great system for posting your photos on the web).  The plugin will also allow you to create links to random Gallery pages.

Note that this is not quite what you need if you want to fully integrate Gallery into your MT blog.  However, simple solution that got me almost as much integration as I wanted. 

Using this plugin you can create a link like this:

By using the following tag in your post:

<MTGalleryLink photo="2004-01-11-a-itaipava/20040111_018_1685"/>

which will result in the following html code:

<a href="http://www.freewisdom.org/gallery/view_photo.php?set_albumName=2004-01-11-a-itaipava&amp;id=20040111_018_1685">
 <img src="http://www.freewisdom.org/albums/2004-01-11-a-itaipava/20040111_018_1685.thumb.jpg">
</a>

I find that the former is much easier to produce than the latter, even with the benefit of copy-and-past. 

You can also create random links:

By using the following tag in your post:

<MTGalleryLinkRandom/>

Which might create:

<a href="http://www.freewisdom.org/gallery/view_photo.php?set_albumName=2004-01-11-c-leme&amp;id=20040111_078_9894">
 <img src="http://www.freewisdom.org/albums/2004-01-11-c-leme/20040111_078_9894.thumb.jpg">
</a>

and will look like this:


This is all that this plugin does, so if this doesn't seem exciting, you don't need this plugin.

In order to get this working, you will need to do four things:

  1. Install the plugin, which should be trivial
  2. Modify your MT installation to enable tag processing inside the posts (if you want to include links inside the posts)
  3. Create a list of photos from which random photos would be pulled (only if you want to use <MTGalleryLinkRandom> tag
  4. Use the new tags in your posts or templates

Getting the code

The code for the plugin is here. Save the code into a file in your "plugins" directory.  You can call the file "gallery-link.pl" but it doesn't really matter, as long as it has a ".pl" extension. 

You will need to edit the file to point it to your gallery installation.  The defaults look like this:

my $GALLERY_URL = "http://www.someserver.org/gallery";
my $ALBUMS_URL = "http://www.someserver.org/albums";
my $PHOTO_LIST_FILE = "/home/your-user-name/photos.txt";

The first is the url of your Gallery, the second is the URL of your albums (that's where you images actually are). The third is the photo list file that you only need to worry about if you want to use random links.

That should be it.  If this doesn't work, email me (see the bottom of the page).

Enable tag processing inside the posts

If you want to use the links inside posts (rather than just, say, on your sidebar), you will need to install Process Tags Plugin.  If you have problems with this plugin, I probably won't be the right person to ask.  It works for me, though.

Create a list of photos

If you want to make links to random photos, you will need to create a list of photos from which you want the random photos to be selected.

You can put it anywhere you want, just make sure that $PHOTO_LIST_FILE variable in the plugin points to the right file.

The file should look something like this:

2003-08-17-vegas/20030817_014_3259
2003-08-17-vegas/20030817_024_3746
2003-08-17-vegas/20030817_023_5744

(One line per photo, in album/file_name patter, with file names used without the extension.)

Using the tags

To put a link in your post, use a tag like this:

<MTGalleryLink photo="2004-01-11-a-itaipava/20040111_018_1685"/>


You could also use the following optional attributes:
For instance, this tag:<MTGalleryLink photo="2003-01-05-monterey2/20030105_049_0462" img_alt="a flower" img_class="gallery_image" link_title="A photo of a flower in Monterey" link_class="gallery_link" />

will result in the following HTML:

<a href="http://www.freewisdom.org/gallery/view_photo.php?set_albumName=2003-01-05-monterey2&id=20030105_049_0462"
   class="gallery_link" title="A photo of a flower in Monterey">
 <img src="http://www.freewisdom.org/albums/2003-01-05-monterey2/20030105_049_0462.thumb.jpg"
      alt="a flower" class="gallery_image">
</a>

(Thanks to Juan Manuel Caicedo for a patch adding this functionality.)

To insert a random link, use

<MTGalleryLinkRandom/>

(Note that the random links will be updated every time the page is rebuilt, not just when it is reloaded.)

Questions of Suggestions?

See FAQ below or email me at yuri@{domain-of-this-webpage} if you have questions or suggestions.

FAQ

Does the plugin support (or need to) authentication?  My gallery is password protected.

It really just creates links.  If you link to password protected photos, then gallery will ask the user for authentication, I believe.   Myself, I just don't include password protected photos in my photos.txt (see below), since there is no point of giving people links to files that they can't see.

BTW, Gallery doesn't password-protect the actual images.  For instance, I had my JPGs under freewisdom.org/albums/ and if you went to that url you would see an open directory full of image.  So, it helps to put a blank index.html there.

I can't find a photos.txt file anywhere to link to.

This is the file where you are going to list the photos from which random ones areg going to be picked.  (I decided that I didn't want most of my photos shown on the front page, but a small number that I actually liked.)  It's a file you create yourself.  You can really put it anywhere you want.  Just make sure that your httpd process has read access to it.

You do have to update this file by hand, but I find it is really easier to do that than a web interface could do.  When I want to add a photo, I right click on the thumb-nail and do "Copy Image Link", then paste it into my photo.txt and delete the unnecessary parts.

Everytime I reload the page the same photo appears.   What do you do to get it really randomly?  For now I have to rebuild my template everytime to get a new pic on the frontpage.

Since MT works by generating static HTML, there doesn't seem to be a simpley way of making the photos change with every reload without using javascript.  So, with GalleryLink, the random photos in fact only change when you rebuild the site.  If you are concerned that you might not be posting often enough, and your visitors will be stuck with the same images day after day, there is a script (mt-rebuild) that you could use to force a rebuild.  Cron this script to run once a day (or once an hour, or every five minutes), and you will make sure that you visitors see different photos everyday (every hour, every five minutes).

If you can think of a simple solution that would make it change photos with every reload, I would like to hear about it.