Rue Plumet

This handful of tin Wouldn't buy my sweat!


CoppermineSC Plugin

CoppermineSC is a WordPress plugin that can include images from Coppermine Photo Gallery in WordPress posts or templates. I wrote CoppermineSC based on a script by Lennart Groetzbach that was adapted as a plugin and enhanced by Matthias Jell.

The latest version of CoppermineSC is 0.4.6 What’s new in 0.4.6?

Key Features:

  • Support for links to an unlimited number of Coppermine databases.
  • You can include single images, albums, or categories.
  • When including single images, you can reference them by album id and image name or by permanent id from the Coppermine database, and you can choose thumbnails, normalized images, or full size images (with an optional maximum width setting).
  • When including albums or categories, you can include the entire set of images or a customizable fixed number of images in filename, date or title order, or you can choose to include a random set of images from a given album or category. You can also choose to include only the most recently uploaded images.
  • You can choose to include random images from your entire gallery, or the most recently images uploaded from your gallery.
  • A special function you can call to include images in your sidebar or elsewhere in your template.

Download And Information:

Installation Instructions:
In order to install CoppermineSC you will have to unzip the download, locate the ‘copperminesc.txt’ file, and do the following:

(Please note that you can simply ignore the ‘alternate_coppermine_database.txt’ file if you only have one Coppermine database, which is probably the case for most people. If you do have multiple Coppermine databases, you can find instructions on using the alternate database file near the bottom of this page.)

  1. Enter your Coppermine Gallery MySQL connection information in this area of the script:
    define ('CPGSC_DBUSER', 'mysql_user_here');
    define ('CPGSC_DBPASS', 'mysql_password_here');
    define ('CPGSC_DBSERVER', 'mysql_db_server_here');
    define ('CPGSC_DBNAME', 'mysql_db_name_here');
    define ('CPGSC_TABLE_PREFIX', 'cpg_');
    // for previous line, enter prefix for tables in db, might be based on Coppermine version number like 'cpg132_'

     
  2. CoppermineSC will run just fine without altering any of the following settings, but if want to tailor its output to your needs, you can optionally customize (alter or comment in or out) the appropriate lines in the optional settings section:
    // set prefix for normalized and thumbnail images (these are the defaults, but you can change them if you have customized Coppermine)
    define ('CPGSC_NORMAL_PREFIX', 'normal_');
    define ('CPGSC_THUMB_PREFIX', 'thumb_');

    // set sort order for images when including non-random images from an album, comment out all but one of the following four lines
    //define ('CPGSC_IMAGE_SORT', 'database');
    //define ('CPGSC_IMAGE_SORT', 'date');
    define ('CPGSC_IMAGE_SORT', 'filename');
    //define ('CPGSC_IMAGE_SORT', 'title');

    // set sort order for albums (within the selected category) when including non-random images from a category, comment out all but one of the following three lines
    //define ('CPGSC_ALBUM_SORT', 'database');
    define ('CPGSC_ALBUM_SORT', 'albumorder');
    //define ('CPGSC_ALBUM_SORT', 'title');

    // set whether individual image links should link to the normal size image or to the album they belong to (does not effect album, category, or gallery based thumbnails), comment out exactly one of the following two lines
    define ('CPGSC_SINGLEIMAGE_LINK', 'album');
    //define ('CPGSC_SINGLEIMAGE_LINK', 'normalimage');

    // optional text for album link (blank text means no link will be created), comment out exactly one of the following two lines
    //define ('CPGSC_ALBUM_TEXT', '');
    define ('CPGSC_ALBUM_TEXT', 'view more images from this album');

    // optional text for category link (blank text means no link will be created), comment out exactly one of the following two lines
    //define ('CPGSC_CATEGORY_TEXT', '');
    define ('CPGSC_CATEGORY_TEXT', 'view more images from this category');

    // optional text for gallery link (blank text means no link will be created), comment out exactly one of the following two lines
    //define ('CPGSC_GALLERY_TEXT', '');
    define ('CPGSC_GALLERY_TEXT', 'view more images from this gallery');

    // optional forced width for full size original image (blank forced width means actual width will be used, you can customize the fixed width if you want to), comment out exactly one of the following two lines
    define ('CPGSC_MAX_WIDTH', '');
    //define ('CPGSC_MAX_WIDTH', ' style="width:400px;"');

    // optional forced horizontal alignment for images (blank means follow css tags as listed in Layout section above), comment out all but one of the following four lines
    define ('CPGSC_ALIGNMENT', '');
    //define ('CPGSC_ALIGNMENT', 'left');
    //define ('CPGSC_ALIGNMENT', 'center');
    //define ('CPGSC_ALIGNMENT', 'right');

    // set whether or not clicking on an image should open a new window, comment out exactly one of the following two lines
    define ('CPGSC_NEWWINDOW', 'no');
    //define ('CPGSC_NEWWINDOW', 'yes');

    // set whether or not CoppermineSC tags work in comments, comment out exactly one of the following two lines
    //define ('CPGSC_ALLOW_COMMENTS', 'allowed');
    define ('CPGSC_ALLOW_COMMENTS', 'notallowed');

    // set whether the image containing element is a span or a div tag, comment out exactly one of the following two lines
    //define ('CPGSC_CONTAINER_ELEMENT', 'div');
    define ('CPGSC_CONTAINER_ELEMENT', 'span');

    // set whether or not you want to use a containing element for tags that include individual images, comment out exactly one of the following two lines
    //define ('CPGSC_CONTAINER_INDIVIDUAL', 'no');
    define ('CPGSC_CONTAINER_INDIVIDUAL', 'yes');
     

  3. Rename the file with a “php” extension (it will be “txt” when you download it)
     
  4. Upload it to your plugins directory and activate it
     
  5. You’re done!

Usage:
To use the plugin in WordPress, add one of the following lines in an entry:

  • The following tags pull in images from the main database
    • These tags pull in a single image from the main database by album id and image name
      [cpg_image:2,myimage.jpg] - inserts full size/original image for image in album id 2 named ‘myimage.jpg’
      [cpg_imagenormal:2,myimage.jpg] - inserts normalized image for image in album id 2 named ‘myimage.jpg’
      [cpg_imagethumb:2,myimage.jpg] - inserts thumbnail image for image in album id 2 named ‘myimage.jpg’
    • These tags pull in a single image from the main database by permanent image id
      [cpg_imagefix:1234] - inserts full size/original image with permanent id 1234
      [cpg_imagefixnormal:1234] - inserts normalized image with permanent id 1234
      [cpg_imagefixthumb:1234] - inserts thumbnail image with permanent id 1234
       
    • These tags pull in thumbnails of images from a specific album in the main database
      [cpg_album:4] - inserts thumbnails for all images in album id 4
      [cpg_album:4,10] - inserts thumbnails for the first 10 images in album 4
      [cpg_albumnew:4] - inserts thumbnails for all images in album id 4 in order from newest to oldest
      [cpg_albumnew:4,10] - inserts thumbnails for the 10 latest uploads from the images in album id 4
      [cpg_albumrand:4] - inserts thumbnails for all images in album id 4 in random order
      [cpg_albumrand:4,10] - inserts 10 random thumbnails from the images in album id 4
    • These tags pull in full size / original images from a specific album in the main database
      [cpg_albumfullsize:4] - inserts full size / original images for all images in album id 4
      [cpg_albumfullsize:4,10] - inserts full size / original images for the first 10 images in album 4
      [cpg_albumnewfullsize:4] - inserts full size / original images for all images in album id 4 in order from newest to oldest
      [cpg_albumnewfullsize:4,10] - inserts full size / original images for the 10 latest uploads from the images in album id 4
      [cpg_albumrandfullsize:4] - inserts full size / original images for all images in album id 4 in random order
      [cpg_albumrandfullsize:4,10] - inserts 10 random full size / original images from the images in album id 4
       
    • These tags pull in thumbnails of images from a specific category in the main database
      [cpg_cat:5] - inserts thumbnails for all images in category id 5
      [cpg_cat:5,12] - inserts thumbnails for the first 12 images in category id 5
      [cpg_catnew:5] - inserts thumbnails for all images in category id 5 in order from newest to oldest
      [cpg_catnew:5,12] - inserts thumbnails for the 12 latest uploads from the images in category id 5
      [cpg_catrand:5] - inserts thumbnails for all images in category id 5 in random order
      [cpg_catrand:5,12] - inserts 12 random thumbnails from the images in category id 5
    • These tags pull in full size / original images from a specific category in the main database
      [cpg_catfullsize:5] - inserts full size / original images for all images in category id 5
      [cpg_catfullsize:5,12] - inserts full size / original images for the first 12 images in category id 5
      [cpg_catnewfullsize:5] - inserts full size / original images for all images in category id 5 in order from newest to oldest
      [cpg_catnewfullsize:5,12] - inserts full size / original images for the 12 latest uploads from the images in category id 5
      [cpg_catrandfullsize:5] - inserts full size / original images for all images in category id 5 in random order
      [cpg_catrandfullsize:5,12] - inserts 12 random full size / original images from the images in category id 5
       
    • These tags pull in thumbnails of images from your entire gallery in the main database
      [cpg_galnew:3] - insert thumbnails for the 3 latest uploads from all the images in the gallery
      [cpg_galrand:3] - inserts 3 random thumbnails from all the images in the gallery
    • These tags pull in full size / original images from your entire gallery in the main database
      [cpg_galnewfullsize:3] - insert full size / original images for the 3 latest uploads from all the images in the gallery
      [cpg_galrandfullsize:3] - inserts 3 random full size / original images from all the images in the gallery
       
  • The following tags pull in images from an additional database
    • These tags pull in a single image from an alternate database by album id and image name
      [cpg_dbimage:mydbname,2,myimage.jpg] - inserts full size/original image for image in album id 2 named ‘myimage.jpg’ from database named ‘mydbname’
      [cpg_dbimagenormal:mydbname,2,myimage.jpg] - inserts normalized image for image in album id 2 named ‘myimage.jpg’ from database named ‘mydbname’
      [cpg_dbimagethumb:mydbname,2,myimage.jpg] - inserts thumbnail image for image in album id 2 named ‘myimage.jpg’ from database named ‘mydbname’
    • These tags pull in a single image from an alternate database by permanent image id
      [cpg_dbimagefix:mydbname,1234] - inserts full size/original image with permanent id 1234 from database named ‘mydbname’
      [cpg_dbimagefixnormal:mydbname,1234] - inserts normalized image with permanent id 1234 from database named ‘mydbname’
      [cpg_dbimagefixthumb:mydbname,1234] - inserts thumbnail image with permanent id 1234 from database named ‘mydbname’
       
    • These tags pull in thumbnails of images from a specific album in an alternate database
      [cpg_dbalbum:mydbname,4] - inserts thumbnails for all images in album id 4 from database named ‘mydbname’
      [cpg_dbalbum:mydbname,4,10] - inserts thumbnails for the first 10 images in album 4 from database named ‘mydbname’
      [cpg_dbalbumnew:mydbname,4] - inserts thumbnails for all images in album id 4 in order from newest to oldest from database named ‘mydbname’
      [cpg_dbalbumnew:mydbname,4,10] - inserts thumbnails for the 10 latest uploads from the images in album id 4 from database named ‘mydbname’
      [cpg_dbalbumrand:mydbname,4] - inserts thumbnails for all images in album id 4 in random order from database named ‘mydbname’
      [cpg_dbalbumrand:mydbname,4,10] - inserts 10 random thumbnails from the images in album id 4 from database named ‘mydbname’
    • These tags pull in full size / original images from a specific album in an alternate database
      [cpg_dbalbumfullsize:mydbname,4] - inserts full size / original images for all images in album id 4 from database named ‘mydbname’
      [cpg_dbalbumfullsize:mydbname,4,10] - inserts full size / original images for the first 10 images in album 4 from database named ‘mydbname’
      [cpg_dbalbumnewfullsize:mydbname,4] - inserts full size / original images for all images in album id 4 in order from newest to oldest from database named ‘mydbname’
      [cpg_dbalbumnewfullsize:mydbname,4,10] - inserts full size / original images for the 10 latest uploads from the images in album id 4 from database named ‘mydbname’
      [cpg_dbalbumrandfullsize:mydbname,4] - inserts full size / original images for all images in album id 4 in random order from database named ‘mydbname’
      [cpg_dbalbumrandfullsize:mydbname,4,10] - inserts 10 random full size / original images from the images in album id 4 from database named ‘mydbname’
       
    • These tags pull in thumbnails of images from a specific category in an alternate database
      [cpg_dbcat:mydbname,5] - inserts thumbnails for all images in category id 5 from database named ‘mydbname’
      [cpg_dbcat:mydbname,5,12] - inserts thumbnails for the first 12 images in category 5 from database named ‘mydbname’
      [cpg_dbcatnew:mydbname,5] - inserts thumbnails for all images in category id 5 in order from newest to oldest from database named ‘mydbname’
      [cpg_dbcatnew:mydbname,5,12] - inserts thumbnails for the 12 latest uploads from the images in category id 5 from database named ‘mydbname’
      [cpg_dbcatrand:mydbname,5] - inserts thumbnails for all images in category id 5 in random order from database named ‘mydbname’
      [cpg_dbcatrand:mydbname,5,12] - inserts 12 random thumbnails from the images in category id 5 from database named ‘mydbname’
    • These tags pull in full size / original images from a specific category in an alternate database
      [cpg_dbcatfullsize:mydbname,5] - inserts full size / original images for all images in category id 5 from database named ‘mydbname’
      [cpg_dbcatfullsize:mydbname,5,12] - inserts full size / original images for the first 12 images in category 5 from database named ‘mydbname’
      [cpg_dbcatnewfullsize:mydbname,5] - inserts full size / original images for all images in category id 5 in order from newest to oldest from database named ‘mydbname’
      [cpg_dbcatnewfullsize:mydbname,5,12] - inserts full size / original images for the 12 latest uploads from the images in category id 5 from database named ‘mydbname’
      [cpg_dbcatrandfullsize:mydbname,5] - inserts full size / original images for all images in category id 5 in random order from database named ‘mydbname’
      [cpg_dbcatrandfullsize:mydbname,5,12] - inserts 12 random full size / original images from the images in category id 5 from database named ‘mydbname’
       
    • These tags pull in thumbnails of images from your entire gallery from database named ‘mydbname’
      [cpg_dbgalnew:mydbname,3] - insert thumbnails for the 3 latest uploads from all the images in the gallery from database named ‘mydbname’
      [cpg_dbgalrand:mydbname,3] - inserts 3 random thumbnails from all the images in the gallery from database named ‘mydbname’
    • These tags pull in full size / original images from your entire gallery from database named ‘mydbname’
      [cpg_dbgalnewfullsize:mydbname,3] - insert full size / original images for the 3 latest uploads from all the images in the gallery from database named ‘mydbname’
      [cpg_dbgalrandfullsize:mydbname,3] - inserts 3 random full size / original images from all the images in the gallery from database named ‘mydbname’
       
  • The following tags are for use outside normal entries (for example, in your sidebar or template)
    • Use a snippet like the following in your sidebar or template:
      <?php if (function_exists('cpgsc_sidebar')) {
          cpgsc_sidebar('any_tag_from_list_above'); }
      ?>
    • For example, to insert thumbnails for all images in album id 4:
      <?php if (function_exists('cpgsc_sidebar')) {
          cpgsc_sidebar('[cpg_album:4]'); }
      ?>

Instructions For Additional Databases:
If you want to link to more than one Coppermine Gallery, you will need to follow these instructions. In order to use any of the [cpg_db tags, you will have to create a configuration file for each of the Coppermine databases you want to access. The contents of a configuration file should be as follows:

<?php
$alternateserver = 'alternate_mysql_db_server_here';
$alternatedbname = 'alternate_mysql_db_name_here';
$alternatepassword = 'alternate_mysql_password_here';
$alternateuser = 'alternate_mysql_user_here';
$alternatetableprefix = 'cpg_';
/* do not alter any lines in this file other than replacing
the placeholders with your connection information,
do not remove any lines from this file,
do not add any lines or carriage returns */
?>

You can download a template configuration file here. You will need to save the file as "databasename.php". For example, if your Coppermine database is named "my_coppermine1", then save the file as "my_coppermine1.php". The file must be saved in the "wp-content" folder in your WordPress setup. Please note that this is not the "plugins" folder or a subfolder where you may have installed the plugin. The configuration files need to be installed directly into the "wp-content" folder in order to work.

When you use one of the [cpg_db tags, use the database name as the first parameter, such as: [cpg_dbalbum:my_coppermine1,4] to insert thumbnails for all images in album id 4 from database “my_coppermine1″.

What’s Next?

  • An admin page in WordPress for configuring the main settings (so you won’t have to hand edit the script anymore).
  • Enhancements to the admin page to allow you to set up additional databases (so you won’t have to use separate alternate database files anymore).
  • It depends on what you ask for! Please post requests here.

Special Thanks:

  • Lennart Groetzbach for his original work and idea.
  • Matthias Jell for his enhancements and conversion of the original script to a plugin.
  • 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.
  • Tim for information on how to directly link to an image in Coppermine using its permanent id.
  • Bitweever for encouraging me to learn how to make this plugin work in sidebars.
  • Rob for pointing out the problem with private galleries.
  • Kathy Moore for suggesting the set of tags to pull the most recently uploaded images for albums, categories, or for the entire gallery.
  • Brian Jarrett for suggesting a fix for a WordPress 2.5 compatibility problem.