UPDATE: Version 0.4.6 has been released. Please see this entry or my CoppermineSC page for the latest information.

I’ve been using a plugin by Matthias Jell to interface with Coppermine Gallery, but in some respects it wasn’t exactly what I was looking for. I’ve been wanting to learn a little about PHP for a while now, so this was my excuse. I’m happy to say this blog is now running my new, enhanced version: CoppermineSC.

Overview of changes:

  • My version supports multiple Coppermine databases (the original supports only one).
  • My version uses the image name for [cpg_image] based tags (the original uses the image index as stored in the database).
  • My version supports explicitly pulling in thumbnails, normalized, or full size images with separate tags for each image size (the original lets you define which of the three sizes you want and that size is always used for all images).
  • My version allows you to set an optional maximum width for full size images (the original version always pulls in full size images at actual size).
  • In my version, when you click on an image in a group of album thumbnails it will navigate to the actual image in Coppermine (the original version displayed the image in a popup window). I need to give credit to Tim for information on how to directly link to an image in Coppermine using its permanent id.
  • I completely rewrote the main parsing loop for better efficiency and error handling.
  • I have included technical descriptions of all changes after the jump.

EDIT: I previously had full setup and usage instructions in this entry. I now have a dedicated page for CoppermineSC to make things easier on me so that I only have one central location to keep up to date. Please see that page for complete information about CoppermineSC.

Techincal description of changes:

  • The original version supported only one Coppermine database. I have several galleries and really wanted to be able to link to any of them from WordPress. I realize that most people probably don’t have multiple galleries, so I added the multiple database feature as something that’s completely optional (and it won’t get in your way if you have only one gallery). If you have just one gallery, you can enter the connection information in the constants section at the top of the script and everything will work just fine. If you want to use multiple databases, you will have to set up a small configuration file for each database that you want to connect to and place the file in the “wp-content” folder in your WordPress setup. I created a separate set of new tags to use if you want to reference a configuration file. The new tags all start with “[cpg_db” instead of “[cpg_”.
  • The original version used integers to indicate you wanted the “4th” image in the “2nd” album. It used a SQL “OFFSET” statement to accomplish that, which broke down under several scenarios. First, there was no way to pull back the very first image in an album. If you tried to include the first (i.e. “0th”) image, the SQL statement choked trying to run the select statement with an offset of -1. Second, if you ran Coppermine with a default sort order other than filename, the positional index of the image in the database did not necessarily match what you saw when you viewed the album thumbnails in the gallery itself. That made it almost impossible to know what image index you were supposed to use in order to include the image you wanted. To address this issue, I switched the image indicator to be the filename, which works for all images (even the first) regardless of the sort order set in Coppermine.
  • The original version had constants defined where all images were always pulled in either as thumbnails, normalized, or original size. In my WordPress entries I found that I sometimes wanted thumbnails and sometimes wanted full size images. To address this issue, I created three different tags to let the plugin know explicitly what size image you want.
  • The original version always pulled back original size images as truly full size. I found that some of my original size images ended up being significantly wider than the column width I use in WordPress, so they really messed up my layout. To address this issue, I added an optional maximum full size image width setting which can be used to make sure that even the largest images still fit within your WordPress layout.
  • The original version used a Java popup window to display the original size image when you clicked on an image in a group of album thumbnails. I wasn’t crazy about the popup window so I changed the script to navigate to the actual image in Coppermine instead.
  • The original version used some tags that were not compatible with the Markdown plugin, so I altered the problematic tag names.
  • The main structure for the original plugin used multiple loops: one looking for album tags, one looking for image tags, etc. I changed the overall structure to use just one main loop that looks for all tags. This should be more efficient, especially if most of your WordPress posts don’t actually link images with the plugin.
  • The original version didn’t have much handling in place for malformed calls to the plugin. I will grant you that the syntax for the plugin calls isn’t all that tricky, but I went ahead and changed the code to be a little more robust in processing the calls. This new version should ignore most malformed calls instead of trying to actually process them. I need to give credit to Richard Rosalion for first noticing that the original routine in Matthias Jell’s plugin might read right past the ending “]” character when looking for a comma. Once he pointed that out, I added few other tweaks to catch similar problems.
  • The original version assumed that the URL location of your Coppermine Gallery, as set in the configuration screen for Coppermine, did not have a trailing “/”. According to the official Coppermine documentation, that setting is supposed to have a trailing “/”. To address this issue, I changed the code to check to see if the trailing “/” is already there and add it if necessary.
  • The original version assumed that your prefix for normalized images was “normal_” and your prefix for thumbnails was “thumb_”. To address this issue, I defined those values as customizable constants in case you use alternate prefixes in Coppermine.
  • I didn’t see any reason for the $cmdb variable to be global, so I made it not global. I fully admit that I am brand new to PHP, so if there is some reason this variable needs to be global that I just don’t understand, please let me know.
Advertisements