Here's the problem: while the printRandomImages function loops it doesn't check if an image has already been grabbed. This leads quite often to the printing of duplicates especially in a gallery with fewer than 100 pictures. My guess is that there needs to be created an array that stores the previous results of the for loop so that while the loop is runing it can check if an value has allready been isued.
I've tried by myself to come with a fix but I just don't master php scripting enough and I can't figure out the right syntax.
Thanks!
Well, I have solved this one with the help of a friend. Here's my code, maybe you include it in the nightly build. We have tried to optimize it to use as less memory ass possible.
`
/**
/*
function printRandomImages($number=5, $class=null, $option='all', $rootAlbum='',$width=100,$height=100,$crop=true) {
if (!is_null($class)) {
$class = ' class="' . $class . '"';
}
echo "";
$rand_img_array=array();
for ($i=1; $iexists && checkSameImage($rand_img_array,$randomImage->webpath) == true) {
array_push($rand_img_array,$randomImage->webpath);
$randomImageURL = htmlspecialchars(getURL($randomImage));
echo 'getTitle())) . '">';
if($crop) {
echo "getCustomImage(NULL, $width, $height, $width, $height, NULL, NULL, TRUE))."\" alt=\"" . html_encode($randomImage->getTitle()) . "\" />\n";
} else {
echo "getCustomImage($width, NULL, NULL, NULL, NULL, NULL, NULL, TRUE))."\" alt=\"" . html_encode($randomImage->getTitle()) . "\" />\n";
}
echo "";
}else{
$i--;
}
echo "
\n";
}
echo "";
}
`
Thanks, we appreaciate that. But could you please open a ticket and attach a file/patch there (make sure that you use at least the current nightly and not 1.3 official to be on the secure side). This code here is not properly escaped and unusabel to eben look at. Also if we decide to use it a file is easier to use a proper file. Thanks again.
Just an FYI, I escaped the code for you to fix this forum page.
I've atached only the patched code. Avaible at http://www.zenphoto.org/trac/ticket/1538
BTW, I am not sure how you intend to use this. If it is just for creating a page with multiple not duplicated random images there is probably a simpler method. If you want this to be "remembered" across multiple pages you will have to find a way to store the state somewhere. There is no implicit state preservation between page loads.
The simpler method would be to just use the $album->getImages() to return an array of image names selecting the random sort order. Then take as many of the image names from the array it returns as the images you will display.
Actually a new random order is the behavior I desire at each page refreh. I use this on my custom index page as an incentive for new visitors to start browsing the gallery. I'm not using a static array, like what would be printed by printTopRatedImages, because I don't want to influence the image stats at all. This way I can have a more acurate measure of an image popularity.
Also I found an use for this function in the header were I have a slideshow script wich cycles a few banner images in closed loop. Having a random order each time ensures a seamless experience when moving from page to page. But I guess this is too much of a detail to even be mentioned
Thanks again for your support! I just finished translating all the strings from my content and I'll be posting my website tommorow in the showcase topic.