MT-PhotoGallery: A Movable Type Plugin

Current version is 1.1.1.0 released on 2005-09-04

Contents

What This Plugin Does

This plugin gives you a new set of Movable Type template tags. These tag will allow you to display a list of image files on your web server formatted in a manner of your choosing.

Requirements

  • This plugin works with Movable Type version 2.x and 3.x.
  • Perl version 5.8.5 or higher. This is what I use. It may work on lower versions. Let me know if it does and I will lower this.
  • You must have the Perl module, Storable, installed.
  • This plugin will only work in static (not dynamic) templates.

Installation Instructions

  1. Download the latest version of the plugin.
  2. Unzip the contents of the file.
  3. Copy the file PhotoGallery.pl to your Movable Type "plugins" directory. (If you don't have a plugins directory, create a plugins directory in the same directory where your mt.cgi file is located. Then upload PhotoGallery.pl into the newly created plugins directory.)
  4. Add some combination of this plugin's tags into a template file. Movable Type plugin tags DO NOT work in blog entries. They must be inside of your template file. Most folks create a new template file to display their photos. See some of the examples below to get started. (For advanced users, there are ways to make plugin tags work inside of entries.)
  5. Give me some credit. You have many choices. Do one or all! 1) Add a trackback link to this page on your page. 2) Donate so that I continue to enhance this plugin.

Image File Name Conventions

In order to have the plugin automatically display a title and a date, I chose to have it get the information from the file name itself. Therefore, a file name convention was created to help in the extraction of the data. YY or YYYY is the year. MM is the month. DD is the day. EXT is the file extension. Any underscores in the TITLE will be replaced with spaces. The * indicates that you can add other characters that will be ignored in its place. The following conventions can be used:

  • YYYY-MM-DD––TITLE.EXT
  • YYYY-MM-DD*.EXT
  • MM-DD-YY*.EXT
  • YYYY_MMDD*.EXT
  • YYYYMMDD*.EXT
  • YYMMDD*.EXT
  • TITLE.EXT
  • *.EXT

How To Use The Tags

This plugin will only work in static (not dynamic) templates.

  • MTPhotoGallery
    A container tag representing a list of images from your server. The default is to display the images from your local site path in your weblog configuration. To alter this behavior, you can provide one of the following attributes:

    • debug="0|1"
      The default value is 0. Set the parameter to 1 if you are having trouble with your configuration. Helpful for diagnosing path problems or other issues.

    • silent="0|1"
      The default value is 0. Set the parameter to 1 if you want the plugin to silently exit, which returns nothing, when it doesn't find the directory you specified. Some users utilize this method for building photo galleries based on blog entries that may or may not have photos associated with them.

    • path="dir"
      By default, the plugin will use the site path and URL from your weblog's configuration for finding the image files. If you want to override that behavior, specify this tag to force the plugin to use this path as the directory for the image search. Specify this as a relative path from your site URL.

    • recursive="0|1"
      Set this parameter to 0 if you do not want the plugin to recurse into sub-directories that it finds. Setting it to 1 or omitting the parameter will force it to recurse.

    • count="n"
      Set the value of this parameter to an numeric (integer) value if you want to limit the number of pictures displayed.

    • sort_order="ascend|descend|random"
      Specifies the sort order for this particular tag. Valid values are ascend, descend and random.

    • exclude="expression"
      This parameter allows you to exclude files that contain expression from the listing.

    • extension="expression"
      This parameter allows you to specify the exact extension of files that you want to appear. You can set expression to a single extension like jpg or you can allow multiple extensions by separating like jpg|bmp|gif|png. A dot is assumed to be present before the extension that you specify so do not add that leading dot into your expression.

  • MTPhotoGalleryImageDate
    The date of this image. This value is parsed from the file name if available.

    • format="%B %e, %Y"
      Use the standard Movable Type date formatting commands described in the User Manual.

  • MTPhotoGalleryImageDateExists
    A container tag that conditionally generates its contents based on the existence of a value in MTPhotoGalleryImageDate.

    • state="0|1"
      If 1, then tag shows output when value exists. If 0, then tag shows output when value does not exist.

  • MTPhotoGalleryImageLink
    The full URL of this image.

  • MTPhotoGalleryImageFileName
    The name of the image file without path.

  • MTPhotoGalleryImagePath
    The relative path of the image from your site's root. This tag is normally used to feed data into other plugins, such as MTEmbedImage. It does not include the file name. If you need that, concatenate the MTPhotoGalleryImageFileName to this tag.

  • MTPhotoGalleryImageTitle
    The title of this image. This value is parsed from the file name if available.

  • MTPhotoGalleryImageTitleExists
    A container tag that conditionally generates its contents based on the existence of a value in MTPhotoGalleryImageTitle.

    • state="0|1"
      If 1, then tag shows output when value exists. If 0, then tag shows output when value does not exist.

Frequently Asked Questions

  • Q: How is this different from the Gallery application?
    A: Gallery provides a way to build online photo albums with lots of different features, such as comments, organization structures, etc. Folks who use Gallery often post their pictures to Gallery and then write up a blog post that references the picture. However, this plugin is meant for those people who have a different usage model for photos. Many like to upload pictures through Movable Type's Upload File feature and have the blog posting be the "home" of the picture. This plugin allows you to aggregate all those photos into something for easy viewing. (If you just want Gallery to look like Movable Type, I found one article on that.)

  • Q: Can I embed other Movable Type tags within the arguments of this plugin's tags?
    A: Yes, as of version 0.50. Use the standard syntax of arg="[MTTagName]" to do this.

  • Q: This plugin (and others) don't seem to be working on my server. Why?
    A: Internally, Movable Type requires some Perl modules to be installed for plugins to work. Some servers do not have these modules installed by default. Please run mt-check.cgi on your server to find out what you are missing.

  • Q: How can I change the output of tags such as the MTPhotoGalleryImageTitle? I want to strip off certain words or characters.
    A: Use MT-Regex. Regular expressions allow you to parse, strip or modify the string according to a pattern. The trick is figuring out the pattern to use for your case. For an example, let's say that you have 8 random digits appended to the front of your image name and you want to get rid of those.
    
    <head>
       ...
       <MTRegexDefine name="randomstripper">s|\d{8}(.*)|$1|g</MTRegexDefine>
       ...
    </head>
    <body>
       ...
      <MTPhotoGalleryImageTitle regex="randomstripper">
       ...
    </body>
    
    

Examples

1. In this simple example, we create a page that lists out all the images in a big table format.

<table>
   <MTPhotoGallery>
      <tr>
         <td><MTPhotoGalleryImageDate></td>
         <td>
            <a href="<MTPhotoGalleryImageLink>">
               <img border=0 width=150 src="<MTPhotoGalleryImageLink>">
            </a>
         </td>
         <td><MTPhotoGalleryImageTitle></td>
      </tr>
   </MTPhotoGallery>
</table>

2. Same as the last example except we specify a specific directory to use. Be sure to substitute in your own directory path.

<MTPhotoGallery path="/photos/2003/">
   <img src="<MTPhotoGalleryImageLink>">
</MTPhotoGallery>

3. This example shows how to create a random photo each time the page is republished. You can setup an automated cronjob to build the page if you want to auto-update the picture every day.

<MTPhotoGallery sort_order="random" count="1">
   <img src="<MTPhotoGalleryImageLink>">
</MTPhotoGallery>

4. This example shows how to create a link to search for all posts that contain the picture.

<MTPhotoGallery>
   <img src="<MTPhotoGalleryImageLink>">
   <a href="<$MTCGIPath$><$MTSearchScript$>?search=<MTPhotoGalleryImageLink>">Find related posts</a>
</MTPhotoGallery>

5. In this example, we utilize the MTEmbedImage plugin to create the list of images but with auto-generated thumbnail files. Its important to have the exclude parameter match the thumbsuffix parameter or else you will continue to generate thumbnails of the thumbnails over and over. Warning: Pay special attention to the basename parameter passed in to MTEmbedImage. You may or may not need the slash in between the [MTPhotoGalleryImagePath] and [MTPhotoGalleryImageFileName] depending on your weblog configuration.

<table>
   <MTPhotoGallery exclude="-THUMB">
      <tr>
         <td><MTPhotoGalleryImageDate></td>
         <td>basename = <MTPhotoGalleryImagePath>/<MTPhotoGalleryImageFileName><br>
             (If duplicate slashes (//) appear, correct the basename parameter by removing a slash.)
         </td>
         <td>
            <MTEmbedImage basename="[MTPhotoGalleryImagePath]/[MTPhotoGalleryImageFileName]" width="150" thumbsuffix="-THUMB">
               <a href="<MTPhotoGalleryImageLink>">
                  <img src="<MTEmbedImageThumbFilename>"
                     width="<MTEmbedImageThumbWidth>"
                     height="<MTEmbedImageThumbHeight>"/>
               </a>
            </MTEmbedImage>
         </td>
         <td><MTPhotoGalleryImageTitle></td>
      </tr>
   </MTPhotoGallery>
</table>

6. In this example, we utilize the grid plugin to create a multi-column layout of images.

<table align="center">
   <MTGrid num_columns="6">
      <MTPhotoGallery>
         <MTGridCell>
            <MTGridIfLeftColumn><tr></MTGridIfLeftColumn>
               <td>
                  <a href="<MTPhotoGalleryImageLink>">
                     <img src="<MTPhotoGalleryImageLink>">
                  </a>
                  <center><MTPhotoGalleryImageTitle></center>
               </td>
            <MTGridIfRightColumn></tr></MTGridIfRightColumn>
         </MTGridCell>
      </MTPhotoGallery>
      <MTGridTrailingCells>
         <MTGridIfLeftColumn></tr></MTGridIfLeftColumn>
         <td>&nbsp;</td>
         <MTGridIfRightColumn></tr></MTGridIfRightColumn>
      </MTGridTrailingCells>
   </MTGrid>
</table>

7. In this example, I illustrate one possibility for launching the image into a window with customizable HTML. You will want to download the HTML image viewer page that you can customize. View the source of this page and create a page on your server with it.

<MTPhotoGallery>
   <a href="showimage.html?src=<MTPhotoGalleryImageLink>">
</MTPhotoGallery>

8. Photojunkie Magazine wrote up an article on how to create a gallery with this plug-in.

Donate

This software is free for personal use. However, if you enjoy using this plugin and would like to see it enhanced, please donate a buck or two...or fifty.

Commercial use requires a $20.00 donation.

License

This software is licensed under the CC-GNU LGPL.

CC-GNU LGPL

Download

Download the current version from the link below. Past versions are not archived.

Version History

1.1.1.0 -- 2005-09-04
  • Updated plugin info to take advantage of MT 3.2 enhancements.
1.1.0.2 -- 2004-12-10
  • Fixed bug where plugin reported error in MT-Medic.
1.1.0.1 -- 2004-11-11
  • Fixed defect where errors generated by other tags within MTPhotoGallery tag did not show errors correctly.
1.1.0.0 -- 2004-08-19
  • Added new count parameter that limits the number of photos listed. (Thanks to Pedro Figueiredo.)
  • Changed the behavior of the random mode of the sort_order parameter so that it now lists all or count if specified. Previously, random only listed a single image.(Thanks to Pedro Figueiredo.)
1.0.1.1 -- 2004-07-20
  • Fixed bug that caused plug-in to hang when used in random mode with empty directories. (Thanks to Logan Ingalls.)
1.0.1.0 -- 2004-06-24
  • Added the silent parameter.
1.0.0.0 -- 2004-05-29
  • Made compatible with Movable Type 3.0.
0.58 -- 2004-01-16
  • Changed the path tag to only output the path and not the filename. I received lots of complaints about this. This breaks backwards compatiblity but its the right thing to do.
0.57 -- 2004-01-09
  • Fixed bug where random order was not using exclude pattern.
0.56 -- 2004-01-02
  • Changed URL link back to plugin.
0.55 -- 2003-11-19
  • Added the MTPhotoGalleryImageFileName tag.
0.50 -- 2003-10-25
  • Enhanced all of the tag arguments so that you can embed other Movable Type tags in them. Use the format such as arg="[MTSomeTag]".
0.43 -- 2003-10-18
  • I left in some debug stuff. I am an idiot. Removed.
0.42 -- 2003-10-16
  • Added date format of YYYYMMDD*.ext
0.41 -- 2003-10-15
  • Fixed bug where recent path changed caused broken images when you didn't specify a path.
  • Added uppercase versions of the supported image file extensions.
0.40 -- 2003-10-13
  • Changed the way that you specify paths. I received way too many emails from people that don't know what their path is so I simplified it by making the path a relative value from your weblog's configuration information.
  • Added new container tags to test existance of optional fields.
  • Added 2 new date formats.
0.31 -- 2003-10-10
  • Added parameter for specifying the extensions to show.
  • Fixed bug with random display mode.
0.30 -- 2003-09-09
  • Added parameter to format the image date with normal Movable Type date formats.
  • Added parameter to allow or prevent recursion of sub-directories.
  • Added parameter to specify sort order of photos.
  • Added ability to produce a random photo from the list.
  • Added copyright information.
0.20 -- 2003-08-27
  • Added parameter to allow exclusions of files.
0.10 -- 2003-08-14
  • Works for me.

Contact

For questions, suggestions, bug reports, and anything else related to this plugin, please e-mail brandon@fuller.name or leave a comment.

Updated: 2010-08-14 at 21:22 MST in Hacks
Tags: movabletype
Related Posts with Thumbnails