On a Zenpage page I'm tying to get a random image from a specific album.
The name of the album/folder is put in a codeblock as plain text.
I then use the `printCustomSizedImage()` function to display the random image.
This is what I have so far:
`
$albumname = getCodeblock(2,$_zp_current_zenpage_page);
$albumobj = new Album($_zp_gallery,$albumname);
$randomImage = getRandomImagesAlbum($albumobj);
makeImageCurrent($randomImage);
printCustomSizedImage(NULL, NULL, 512, 546, ... etc);
`
The $albumobj is only created if I hardcode the albumname
(i.e. `$albumobj = new Album($_zp_gallery,"");`)
I just can't figure out what's wrong :-(
Comments
If I `echo $albumname;` I also get testalbum
Did you look at the page html of the echo? You cannot really trust what the browser shows, there might be markup or such included.
Of course I should have mentioned this, sorry.
Only if I hardcode an albumname does it show random images from that specific album.
There are no subalbums.
I'll investigate further.
Similar question for the image object. Is one created?
My speculation is that the answere to both these is that the object is not created. If `makeImageCurrent($image)` is not passed an object it does nothing, so whatever `$_zp_current_image` was will not have been changed. Probably somewhere else this variable is being setup to some image from the album in general.
`$albumobj = new Album($_zp_gallery,$albumname);`
to this:
`$albumobj = new Album($_zp_gallery,"testalbum");`
then it works.(i.e. only images from the specified album are shown)
I also checked if an albumobject and an imageobject were created by using:
`if (is_object($albumobj)) echo "something";`
and
`if (is_object($_zp_current_image)) echo "something else";`
They both were.
I now see different results on different installs:
On one PC it works with the SVN Development and SVN Trunk.
PHP version: 5.3.0 MySql version: 5.1.37
On another it does not work with the Nightly Trunk.
PHP version: 5.3.6 MySql version: 5.1.49
Note that "not working" means that images from the entire gallery are shown.
first make a test `$albumname=="testalbum"` just to be sure that they are not somehow different.
Then check to see if the two versions both fail on the PC that has the Nightly Trunk.
But I suspect so. If you are using todays' SVN Trunc and last night's Trunk nightly then there is only one change to the `isImagePage()` function. So it would not be Zenphoto code that makes the difference.
`
$albumname = getCodeblock(2,$_zp_current_zenpage_page);
if($albumname=="testalbum") echo "OK";
`
does not output OK.
EDIT: That is on the PC with the Nightly Trunk
The echoed checks are also correct.
I then put the albumname back in the original codeblock it also works.
Guess that must have been a very persistent browser cache.
Now this might be something:
If I leave all codeblocks empty it still shows random images of the entire gallery ??
Yes, if you don't set a root album it uses the whole gallery. We once had a php issue with NULL vs empty, so on some servers it triggered wrong somehow.
Try adding a check if the code block is empty so it is not used.