Random photo niceness is back!
Now for the gory details. This site runs Geeklog for it's content management, and Gallery for it's photo albums. By and large, they play nice with each other. However, Gallery comes with a "Random Block" page (for the curious, you can see the results here). It's supposed to embed nicely into you content management system...which is probably true except for Geeklog. So, I downloaded the code for Geeklog's random photo block (courtesy of www.lanside.net). Then the problems started!
This was not the fault of the authors but rather a side effect of having such a big-arse gallery! You see, my galleries now tip the scales at over 800MB and about 650 images. The default PHP memory-per-process allowance of 8MB just didn't cut it when the random photo code tried to regenerate its cache. I ended up pushing the per-process memory allowance out to 64MB and that seemed to fix the problem.
Once I had the random block working I wanted to tweak it a little to exclude some galleries that I didn't really want wasting bandwidth on the home page. So I added the following bits to phpblock_galleryRandomPhoto code (which is actually in lib-custom.php):
// Grab an album - this was already there...
// included it as a place-holder for the next bit ;)
$album = chooseAlbum();
// Exclude anything we don't want, and pick another album
while ($album->fields["title"] == "Lesson #1" ||
$album->fields["title"] == "Lesson #2"){
$album = chooseAlbum();
}
As you can probably see, this simply grabs an album (this code already existed in the function) then checks it against the two album titles I want excluded. If the chosen album is one we want excluded, loop, and grab another one. Keep doing this until we have an album we want :)
The next modification I made was to the block-random.php code that I downloaded from Lanside.net. Basically, I wanted to sanitise the selected photo a little further to match the same logic that comes with the code from Gallery. This will skip thumbnails that are actually highlights for albums. Around line 72, change:
if ($album->isHidden($choose)) {to this...if ($album->isHidden($choose) || $album->isAlbum($choose)) {See the difference? Skip thumbs that are either hidden or are albums!Well I hope this is of assistance to someone (somewhere). If you found this useful, please drop me a line and let me know :)
Happy PHP-ing!
What's Related