The Gray Matter
Not The Dark Matter
Sign Up!
Login
Welcome to The Gray Matter
Sunday, February 05 2012 @ 11:11 AM EST
Share

Random photo niceness is back!

James' WeblogAfter a year or so of procrastination, I finally pulled my finger out and did some investigation. The good news is that we now have random photos back on the home page! Yay for me!
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!

Trackback

Trackback URL for this entry: http://gray.net.au/trackback.php/20051116165820285

Here's what others have to say about 'Random photo niceness is back!':

this is very good
good related article [read more]
Tracked on Sunday, June 04 2006 @ 02:24 PM EST

1 comments

The following comments are owned by whomever posted them. This site is not responsible for what they say.
Authored by: Dave on Monday, November 21 2005 @ 06:06 PM EST Random photo niceness is back!
Yeah mate looks good and it is quicker than it was before - v. nice mate and I know you are stoked with the code so I thought I would pat u on the back! Cool now - keep it all looking this good so I don't look bad ok! --- Dave

---
ICQ: 313164925 (aka. Gonzo)
Yahoo: david_g_1972
Skype: gonzo_001

[ # ]