Member
Member
vincent3569   12-10-2010, 13:09
#1

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

Member
Member
sbillard   12-10-2010, 16:36
#2

$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.

Member
Member
vincent3569   21-10-2010, 22:27
#3

hello

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

Member
Member
sbillard   21-10-2010, 22:50
#4

$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)
}

Member
Member
vincent3569   28-10-2010, 12:39
#5

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 ?

Member
Member
sbillard   28-10-2010, 18:42
#6

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.

Member
Member
vincent3569   04-11-2010, 00:32
#7

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 ?

Member
Member
sbillard   04-11-2010, 00:47
#8

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.

Member
Member
vincent3569   04-11-2010, 02:32
#9

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 ?

Member
Member
sbillard   04-11-2010, 02:53
#10

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.

Member
Member
vincent3569   04-11-2010, 08:38
#11

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 ?

Member
Member
vincent3569   04-11-2010, 08:50
#12

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);

Member
Member
vincent3569   04-11-2010, 09:26
#13

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

Member
Member
vincent3569   04-11-2010, 12:22
#14

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 ?

Member
Member
sbillard   04-11-2010, 18:07
#15

It will be in the next release.

  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.