Zenphoto 1.2.2 [3131],customized default theme.
My index.php has a random image from the gallery.
What I need to do for the user is:
- Add a theme option to be able to choose from which album or subalbum the random image should be taken. (a list with all albums and subalbums?)
- The user should also still be able to choose for a random image taken from the entire gallery.
(a checkbox to override the album list?)
After two days of trial and error coding and a headache I give up

Any help is much appreciated.
Merry Xmas to you all !
Comments
If your user selects to use images from the entire gallery your task is fairly simple. use `$image = getRandomImages();` to establish the image. Then go to the display process below.
If your user selects random image from a particular album do the following (I assume you have the album name as a string `$albumname`):
create a new album: `$album = new Album($_zp_gallery, $albumname);` Then get the random image: `$image = getRandomImagesAlbum($album);`
Now that you have an image you need to make it the current image: `makeImageCurrent($image);`
Then you print using one of the template functions for printing images.
I understand your answer (I think
My real problem however is to make it a custom theme option in the
theme options page. (admin -> options -> theme options)
The user wants an easy way to regularely change the the source of the random image.
I can't figure out how to make a list with all the album names to choose from and a checkbox to override this list so the image will be chosen from the entire gallery.
(or any other construction that works)
I'm sorry if I made myself not clear enough ...again.
Thanks again
So, all you really need is how to get a list of albums to use in a type 5 custom option. Your quickest solution would be to use a query.
`$albumlist = query_full_array("SELECT folder FROM ".prefix('albums'));` will give you all the albums. You will need to extract the folder name into a single dimensioned array for the option handling:
`foreach ($albumlist as $album) $list[] = $album['folder'];`
Thank you sbillard!...and Merry Xmas.
On the admin -> options -> theme options page I now have a list with all albums (subalbums included) to choose from + an option to select the entire gallery.
`In themeoptions.php:`
function ThemeOptions() {
setOptionDefault('Allow_comments', true);
setOptionDefault('Allow_search', true);
added `'setOptionDefault('Randomimage, 'Gallery');'`
}
function getOptionsSupported() {
return array(
gettext('Allow comments') => array('key' => 'Allow_comments', 'type' => 1, 'desc' => gettext('Check to enable comment section.')),
gettext('Allow search') => array('key' => 'Allow_search', 'type' => 1, 'desc' => gettext('Check to enable search form.')),
added
`gettext('Randomimage') => array('key' => 'Randomimage', 'type' => 2, 'desc' => gettext('Select source for random image')),`
}
function handleOption($option, $currentValue) {
switch ($option) {
case 'Theme_colors':
$theme = basename(dirname(__FILE__));
$themeroot = SERVERPATH . "/themes/$theme/styles";
echo '<select id="themeselect" name="' . $option . '"' . ">\n";
generateListFromFiles($currentValue, $themeroot , '.css');
echo "</select>\n";
break;
added
`case 'Randomimage':
$albumlist = query_full_array("SELECT folder FROM ".prefix('albums'));
foreach ($albumlist as $album) $list[] = $album['folder'];
$list[] = '--Gallery--';//add option for entire gallery to array
echo '<select id="themeselect" name="' . $option . '"' . ">\n";
generateListFromArray(array(getOption('Randomimage')), $list, false, false);
echo "</select>\n";
break;`
}
}
on thepageyouwant.php add:
`
<?php if ((getOption('Randomimage')== '--Gallery--')) {
makeImageCurrent(getRandomImages(false)); printCustomSizedImageMaxSpace($alt='',600,600,NULL,NULL, false); } // displays a random image from the entire gallery
else {
makeImageCurrent(getRandomImagesAlbum(getOption('Randomimage'))); printCustomSizedImageMaxSpace('',600,600,NULL,NULL, false);} ?>
//displays a random image from any other chosen album
`
This is probably not the most elegant way to do it but it works.
There is still an issue with changing the image description in the frontend. Not sure why.
Thanks to sbillard for setting me on the right track!
Just in case anyone is interested, here's what I put together:
On the admin -> options -> theme options page I now have a list with all albums (subalbums included) to choose from + an option to select the entire gallery.
`In themeoptions.php:`
in function ThemeOptions()
I added: `setOptionDefault('Randomimage, 'Gallery');`
in function getOptionsSupported()
I added: `gettext('Randomimage') => array('key' => 'Randomimage', 'type' => 2, 'desc' => gettext('Select source for random image')),`
in function handleOption($option, $currentValue) (which I copied from the Effervescence+ theme)
I added:
`
case 'Randomimage':
$albumlist = query_full_array("SELECT folder FROM ".prefix('albums'));
foreach ($albumlist as $album) $list[] = $album['folder'];
$list[] = '--Gallery--';//add option for entire gallery to array
echo '\n";
generateListFromArray(array(getOption('Randomimage')), $list, false, false);
echo "\n";
break;
`
on thepageyouwant.php add:
`
<?php if ((getOption('Randomimage')== '--Gallery--')) {
makeImageCurrent(getRandomImages(false));
printCustomSizedImageMaxSpace($alt='',600,600,NULL,NULL, false); }
// displays a random image from the entire gallery
else {
makeImageCurrent(getRandomImagesAlbum(getOption('Randomimage')))
printCustomSizedImageMaxSpace('',600,600,NULL,NULL, false);} ?>
//displays a random image from any other chosen album
`
This is probably not the most elegant way to do it but it works.
There is still an issue with changing the image description in the frontend. Not sure why.
Thanks to sbillard for setting me on the right track!
P.S Can anyone please delete my previous post?
I have similar problem. On my index page I have random image with code:
`
<?php
$randomImage = getRandomImage();
$randomImageURL = getURL($randomImage);
echo '<a href="'.$randomImageURL.'" title="Zobacz obraz: '.$randomImage->getTitle().'">
?>
`
and I would like to change it to getRandomImagesAlbum becouse I want to choose from what album or albums will be displayed photos. How can I do it I don't know php sorry for that question.
Regards
That's my code now:
`
<?php
$randomImage = getRandomImageAlbum('Krajobrazy');
$randomImageURL = getURL($randomImage);
echo '<a href="'.$randomImageURL.'" title="Zobacz obraz: '.$randomImage->getTitle().'">
class="reflect rheight33" />';
?>
`