Random Photo (small)
A Favorite

block-random-enhanced.php: An enhanced version of Gallery 1.5's block-random.php
Jeff Barca-Hall

Last Modified:
04-Apr-2005 v5 - For Mambo: Explicitly declare top-level variables as global, for when this file is include()'ed by mod_block_random in Mambo.
10-Mar-2005 v4 - Fix bugs caused by prior "fix", when limiting selection to a specific album with subalbums.
09-Feb-2005 v3 - Pass $rand_album as arg to choosePhoto() rather than as global. (Fix for Mambo. Credit to Ben Davis.)

28-July-2004 v2 - Use mt_rand() instead of rand() for better randomization.
26-July-2004 v1

With the release of Gallery 1.4.4-RC1, the Gallery development team quietly(!) included, for the first time, an "official" version of block-random.php. Hooray!

That version, however, lacks some of the enhanced functionality that users of block-random variants have come to enjoy. For instance, the version that I have been supporting handles sub-albums, allows for customization with some optional parameters, and supports page integration using both server-side technologies such as PHP or SSI, as well as a client-side technique (IFrame plus JavaScript).

Note: this version has been developed and tested "standalone", not in a CMS/portal environment. If you are running PHPNuke or PostNuke, check out holzapfel-online.de or nukedgallery.net.

I have now merged my changes into the official block-random.php and introduce them here, with a new file name: block-random-enhanced.php. To avoid naming conflicts with the Gallery distributions, I will no longer distribute a version under the block-random.php filename.

Users of my earlier version of block-random.php should follow the notes for upgrading to this version, which requires Gallery 1.4.4 or later. If you are still on an older version of Gallery, my old block-random source is archived here with the filename block-random-pre144.phps.

What's enhanced about block-random-enhanced.php?

How do I get this on my own page?

  1. Copy block-random-enhanced.php into your Gallery (version 1.4.4 or later) installation directory
    Get the source of this custom version here: http://www.barca-hall.com/block-random-enhanced.phps. Copy and paste the entire contents into a file named "block-random-enhanced.php" (no "s" at the end), and FTP it or otherwise place it in your Gallery installation directory (the same directory containing Gallery's own block-random.php. Make sure that your FTP transfer is ASCII.

  2. Add random block(s) to your page using server-side include

    The simplest SSI syntax to include a random photo is the following (adjust "/gallery" if needed):

    <!--#include virtual="/gallery/block-random-enhanced.php" -->

    Example: The page you are currently viewing is an SSI page with two random blocks at the top, each placed in its own floating div. Here is the syntax used for each of them; if you View Source in your browser, you will see the result (look for the "Begin SSI call" comments):
    <!--#include virtual="/gallery/block-random-enhanced.php?album=favorites" -->
    <!--#include virtual="/gallery/block-random-enhanced.php?size=100&target=_blank" -->

What about client-side include?

Those of you who have been using my custom version of block-random.php today (July 2004) are probably using an IFrame and client-side inclusion (the browser, rather than the server, makes the call to get the random photo). That was the technique I used and documented.

However, in moving my site to a new host recently, I decided to switch to server-side inclusion for my random photo block, using the SSI (Server-Side Include) feature of most web servers. This has advantages over the IFrame technique, such as smoother page layout (no resize after page load), and a simpler implementation in your page (no IFrame, no JavaScript). I encourage those of you using IFrames to give SSI a try, even if it means having to rename your page extension to .shtml (not necessary for me, though; my hosting provider uses CPanel, and I was able to configure Apache to server-parse .html files, too).

For those of you who prefer not to, or who can not use server-side includes, my documentation on client-side IFrame usage still applies.

How to upgrade from a previous version of my customized block-random.php

If you are already using a modified block-random.php from this site, and you just want the latest version with as little effort as possible, then follow these instructions. This is also the way to recover if your Random Photos stopped working correctly after you installed a new version of Gallery:

  1. Follow step 1, above, to get the source of the new block-random-enhanced.php and install it on your server.
  2. Make two changes to the src= attribute of each random block IFrame:
    1. Insert "-enhanced" to make the filename portion of the URL read: "block-random-enhanced.php".
    2. Append "&body=1" to the URL.

    For instance, if the following worked for you previously:
       iframe src="/gallery/block-random.php?size=125&target=_top&album=tristan5"
    then you should now use:
       iframe src="/gallery/block-random-enhanced.php?size=125&target=_top&album=tristan5&body=1"
Thursday, 22-Jun-2006 01:18:36 EDT