Random images from TWO separate ZP installations on one server - how?

zenphoto has come a long way since the early builds, and the community surrounding it has continued to impress me.

A long time ago, this community helped me out in finding a way to show a random photo on the homepage. (http://www.zenphoto.org/support/topic.php?id=7)

Now I have the need of showing TWO random pictures on my homepage (www.noscope.com). One picture from the photography section, and one picture from the wallpapers section. These are two separate zenphoto installations on the same server.

To show the random photography image, I've nicked the most excellent code that was written for the lovely thinkdreams theme (http://www.thinkdreams.com/blog/archives/84), which looks like this:

`<? // Get Random Image<br />
require_once($_SERVER["DOCUMENT_ROOT"].'/photography/zen/classes.php');

$webpath = "/photography";

function getRandomImage() {

$result = query_single_row('SELECT '.prefix("images").'.filename, '.prefix("images").'.title, '.prefix("albums").'.folder FROM '.prefix("images").' INNER JOIN '.prefix("albums").' ON '.prefix("images").'.albumid = '.prefix("albums").'.id ORDER BY RAND() LIMIT 1');

$image = new Image(new Album(new Gallery(), $result['folder']), $result['filename']);

return $image;

}

function getURL($image) {

if (zp_conf('mod_rewrite'))

{

return $webpath . "/" . urlencode($image->getAlbumName()) . "/" . urlencode($image->name);

}

else

{

return $webpath . "/index.php?album=" . urlencode($image->getAlbumName()) . "&image=" . urlencode($image->name);

}

}

$randomImage = getRandomImage();

$randomImageURL = getURL($randomImage);

?>

<?= $randomImageURL ?>" title="View image: <?= $randomImage->getTitle() ?>">image<?= $randomImage->getCustomImage(null, 230, null, 85, 85, null, null) ?>" alt="<?= $randomImage->getTitle() ?>" />

Random Photo

<?= $randomImage->getTitle() ?>

<?= $randomImageURL ?>" title="View image: <?= $randomImage->getTitle() ?>">View full picture`

Now this works fine, for the Photography section.

Unfortunately, it doesn't work when duplicating this piece of code for the Wallpaper section (that is, when there are TWO instances of this code running on the same PHP page. Even after modifications to the best of my ability, I only get close:

`<? // Get Random Wallpaper<br />
$webpath = "/wallpapers";

function getRandomWall() {

$dbprefix = "zp_walls_";

$result = query_single_row('SELECT '. $dbprefix . 'images.filename, '.$dbprefix . 'images.title, '.$dbprefix . 'albums.folder FROM '.$dbprefix . 'images INNER JOIN '.$dbprefix . 'albums ON '. $dbprefix . 'images.albumid = '.$dbprefix . 'albums.id ORDER BY RAND() LIMIT 1');

$image = new Image(new Album(new Gallery(), $result['folder']), $result['filename']);

return $image;

}

function getWallURL($image) {

if (zp_conf('mod_rewrite'))

{

return $webpath . "/" . urlencode($image->getAlbumName()) . "/" . urlencode($image->name);

}

else

{

return $webpath . "/index.php?album=" . urlencode($image->getAlbumName()) . "&image=" . urlencode($image->name);

}

}

$randomWall = getRandomWall();

$randomWallURL = getWallURL($randomWall);

?>

<?= $randomWallURL ?>" title="View image: <?= $randomWall->getTitle() ?>">image<?= $randomWall->getCustomImage(null, 230, null, 85, 85, null, null) ?>" alt="<?= $randomWall->getTitle() ?>" />

Random Wallpaper

<?= $randomWall->getTitle() ?>

<?= $randomWallURL ?>" title="View image: <?= $randomWall->getTitle() ?>">View full wallpaper`

-- Notice that some of the wording has changed to prevent function names clashing, and the SQL query has been changed to point to the wallpapers database.

Now SOME of this works ... it gets the right folder name, and even `$result['filename']` returns the correct filename, but somehow the `$image;` object fails to contain all the information it needs to contain.

Can anyone enlighten me or help me out with this?
Sign In or Register to comment.