ZenphotoCMS Forum
daily random image from a specific album ? - Printable Version

+- ZenphotoCMS Forum (https://forum.zenphoto.org)
+-- Forum: Support (https://forum.zenphoto.org/forum-1.html)
+--- Forum: General support (https://forum.zenphoto.org/forum-4.html)
+--- Thread: daily random image from a specific album ? (/thread-7710.html)



daily random image from a specific album ? - vincent3569 - 2010-10-12

on my site, I have a page with the picture of the day
I used the function getRandomImages() for that.

but I would only use the images of a single album, not all images of the gallery.

there is the function getRandomImagesAlbum() for that, but this function does not have an image per day.

how can I do to get a daily random image from a specific album?

thanks for your help




daily random image from a specific album ? - sbillard - 2010-10-12

$potd = unserialize(getOption('picture_of_the_day')); $image = NULL; if (date('Y-m-d', $potd['day']) == date('Y-m-d')) { $album = new Album($_zp_gallery, $potd['folder']); $image = newImage($album, $potd['filename']); } if (is_null($image) || !$image->exists) { $image = getRandomImageAlbum($rootalbum); $potd = array('day' => time(), 'folder' => $result['folder'], 'filename' => $imageName); setOption('picture_of_the_day', serialize($potd)); }
Caveat: This code had not been tested.




daily random image from a specific album ? - vincent3569 - 2010-10-21

hello

i have tried to use this script, but it doesn't work.
can you explain how it works and the variables to use?




daily random image from a specific album ? - sbillard - 2010-10-21

$potd = unserialize(getOption('picture_of_the_day'));
gets the stored value of the current "image of the day"
$image = NULL;
if (date('Y-m-d', $potd['day']) == date('Y-m-d')) {
If the image of the day is current then create an image object from the stored data
$album = new Album($_zp_gallery, $potd['folder']);
$image = newImage($album, $potd['filename']);
}
if (is_null($image) || !$image->exists) {
If there is no image of the day (or it was obsolete) then get a random image from [b]$rootalbum[/b]--the album object of the album from whence you want the images
$image = getRandomImageAlbum($rootalbum);
$potd = array('day' => time(), 'folder' => $result['folder'], 'filename' => $imageName);
setOption('picture_of_the_day', serialize($potd));
Store the data on this image for future page refreshes (see above)
}




daily random image from a specific album ? - vincent3569 - 2010-10-28

hello

I followed your advice and wrote the following code in the Codeblock1 of a new page.

`

`

but it does not work and I always have a random image that is provided.

  • the image is chosen throughout the gallery (and not in "temp/essai" album as requested).
  • the image changes each refresh of the browser.

Can you help me to solve my problem ?




daily random image from a specific album ? - sbillard - 2010-10-28

I may be blind, but I do not see what might be wrong. You will have to do some debugging.

If you keep getting a new image on the refresh it means one of two things.

  1. the first "if" statement is not taking the "true" path. That would indicate that the date is alway different from the POTD date.

  2. the result of setting up the image in the "true" path is failing somehow. That could only be if the image does not somehow exist.
    So, we need to determine which case is the issue. Add some debugging code to your theme to see which path you have taken. For instance, in the "true" path place an echo " TRUE path"; and in the code that makes a new random image place echo ' No image:";if (is_null($image_of_the_day) echo " image is NULL"; else echo " image must not exits";

Once you determin what went wrong you can put in debug code to see why.




daily random image from a specific album ? - vincent3569 - 2010-11-04

hello

i follow your instructions like that :

Results :

  • "true path" is displayed : the date is not different from the POTD date, but the title of specific_album is empty
  • "image is null" and "image not exits" are also displayed ; the title of specific_album and image_of_the_day are displayed.

according to you, where is the problem ?




daily random image from a specific album ? - sbillard - 2010-11-04

You have some problem with the album name you have specified. Perhaps it does not exits?

BTW, you must be getting PHP script errors since if the image is NULL, the next statemet that uses it as an object will fault. So I think you best find your CGI error logs and find what errors you are getting. That may also help us.




daily random image from a specific album ? - vincent3569 - 2010-11-04

I tried with a new album.

$specific_album = new Album($_zp_gallery, "mariage");
echo $specific_album->getTitle();
$image_of_the_day = getRandomImagesAlbum($specific_album);
echo $image_of_the_day->getTitle();

  • $specific_album is the good one
  • whatever I do, $image_of_the_day is taken in all the gallery, and not only in mariage's album.

where can I find my CGI error logs ?




daily random image from a specific album ? - sbillard - 2010-11-04

You will have to ask your ISP about where the CGI logs are found.

But I think I see the problem. getRandomImagesAlbum() expects the folder name of the album (if you are not using the current album). Looks like you are passing an album object.




daily random image from a specific album ? - vincent3569 - 2010-11-04

hello

there is the code :

$specific_album = new Album($_zp_gallery, "mariage");
$image_of_the_day = getRandomImagesAlbum($specific_album);

with that code, $specific_album is an album object, don't you think ?




daily random image from a specific album ? - vincent3569 - 2010-11-04

sorry, I have not read your message correctly.
yes, $specific_album is an album object and not the folder name of the album as you told me in a previous post :

Quote:if (is_null($image) || !$image->exists) {
If there is no image of the day (or it was obsolete) then get a random image from $rootalbum--the album object of the album from whence you want the images
$image = getRandomImageAlbum($rootalbum);




daily random image from a specific album ? - vincent3569 - 2010-11-04

here is the new code :

`

`

with that, it ok, the random image is taken in the good album "mariage".

...but, the image changes each refresh of the browser (the initial problem still the same).

the first "if" is ok, but the album returned by
`

$specific_album = new Album($_zp_gallery, $potd['folder']);

`
seems to be empty




daily random image from a specific album ? - vincent3569 - 2010-11-04

hello

I finally understood the problem

the following code was wrong :
`

if (is_null($image) || !$image->exists) {

$image = getRandomImageAlbum($rootalbum);

$potd = array('day' => time(), 'folder' => $result['folder'], 'filename' => $imageName);

setOption('picture_of_the_day', serialize($potd));

}

`

because it is a copy/cut of getRandomImages() function.
$result['folder'] and $imageName are unknown, so picture_of_the_day didn't have the correct values stored and read.

the following code to have a daily random image from a specific album works well :

`

`

in fact, it would be a nice improvement to modify getRandomImagesAlbum() function to have a daily random image from a specific album.
could you do that in a next release of zenphoto ?




daily random image from a specific album ? - sbillard - 2010-11-04

It will be in the next release.