I have two albums in my Gallery which only contain sub-albums, not pictures. When the Random Block randomly pulls one of these sub-album's highlight photos for display, clicking on the image will return:
Fatal error: Call to a member function on a non-object in /pathto/gallery/view_photo.php on line 87
Is there any way to have the Random Block not use sub-album highlight photos?
Posts: 2322
Which random block (and which Gallery version) are you using?
Posts: 69
Gallery 1.4.4-RC1, embedded in phpBB 2.0.8. I'm using the random block that is packaged with 1.4.4-RC1, i.e. the block-random.php file.
Posts: 38
This is a long-standing problem with block-random.php that should (IMHO) really be fixed in util.php by having makeAlbumUrl() test for $photoId being a subalbum, and if so return the view_album URL instead of view_photo.
Until that happens, I suggest tolerating this. The alternative is to do a workaround in block-random.php itself, but that gets messy. Others may have a better solution. The workaround which I implemented, but no longer favor, is to recursively "descend" when a sub-album is chosen until you "hit" a photo. Some people using my version of block-random really like this feature, but it's overly complicated with 1) the security checking needed to make sure you don't go into "hidden" sub-albums (something I--oops--overlooked when I first implemented that solution); and 2) the handling of an album containing nothing but sub-albums. For what it's worth, you can see my version at [url]www.barcahall.com/gallery-block-random.html[/url].
-Jeff
Posts: 2322
Any checks of that sort need to be made by the function caller, not inside the function itself. All it does is return what's asked for.
Posts: 38
Fair enough. That'll work, too.
-Jeff
Posts: 15
I was getting the PHP Fatal Error too with the release candidates. During RC1 and RC2, I gave up on the block thinking that it was security-related, but when I renewed the effort during RC3, I spotted this thread which seems to be the same issue.
I have a few levels of albums, such as the top level for photo albums for myself and others, then the next level down is albums broken down by year, and the next level down is albums for each event during that year, within which you find photos.
Although I had hoped that this module would randomly choose any photo from the albums, it seems to only choose the highlighted photo from each album. And it does work fine at displaying these highlights randomly, but generates the PHP Fatal Error if you click on the block.
I'm curious if anyone has found that there's something simple to workaround the issue. Or is there any plan to add an option to the include so that you can specify a specific album so that those of us who don't have photos in the top-level albums aren't left out in the cold?
Posts: 2322
Ok.. this is something I've just fixed in 1.4.4. It will be available in the final release.
Posts: 69
That is GREAT news. Thank you!
Posts: 69
I downloaded the new block-random.php file from the CVS and it works great. Any chance you can implement a feature to select particular sub-albums as described HERE?
Posts: 15
From my perspective, I guess it works, as I don't see any 'PHP Fatal Errors.' Now all I get in the block is 'No photo chosen.' It would be nice if it could find a photo, even though they are three levels deep. Even if that meant restricting the random selection to an album or a sub-album so that it didn't have to search so far down. Any possibility of this happening?
Posts: 2322
I could code the random-block to spend all day trying to find an image, but that's not really the point of the thing.. it's supposed to be quick. If the majority of your albums don't contain pictures, you'll run into issues.
All in all, I'm not quite sure what the the big issue is. The random block (that was available from this site) has only been upgraded and fixed since it was added to the code. If you used the original, there were a whole host of issues that you had to deal with that are now fixed.
Posts: 38
For anyone wanting the ability to specify an album and have random photos come only from that album and its (visible) sub-albums, I have taken the 1.4.4 block-random.php and added that capability, creating a fully compatible version I call block-random-enhanced.php.
-Jeff
Posts: 15
Okay, the new code is working much better. The reason I was getting the 'No photo chosen' at first was because my cache file had not refreshed with the current security settings. (I kept flipping back and forth between secured and unsecured galleries during testing).
Prior to testing this block over the past few weeks, I had protected my galleries so that you could only get in if you were a LOGGEDIN postnuke user. Then I found that the random photo block will only scan for photos in albums that allow EVERYONE. But changing this alone doesn't immediately fix the block and make it work, as the cache file still needs to be deleted or refreshed to find the albums that allow EVERYONE.
Now my only dilemma is to figure out whether I want to open up my security settings to EVERYONE permanently or not. I'd rather have people register before getting into my albums, but then I probably won't be able to use the random block, huh? Any thoughts/suggestions?
Thanks again for all your hard work, signe, as well as the other team members!
Posts: 69
Is your "enhanced" version based off the 1.4.4 from the CVS that signe modified so it doesn not pull highlight photos? Any chance the Gallery team will include your version by default? Finally, can you incorporate the default photo frame in your version?
Posts: 2322
Nothing is being changed for 1.4.4, period. It is due to be released tonight/tomorrow if there are no barring issues.
Any work we do on the block-random will probably be done by the team instead of incorporating code, for a couple reasons. The primary one is that everything needs to be coded for option-use in the config wizard. For instance, I don't want image frames or a target (for html frames) in my embedding environment.
Posts: 38
Sub-albums highlights are not returned in my version. The implementation, however is slightly different (predates 1.4.4 but is compatible with it).
They really shouldn't. It's a nice, isolated file that is easily supported by an outsider like me, leaving them to focus a little on Gallery 1 and a lot on Gallery 2 (which, btw, is really coming along, from the sample sites I've seen). I plan to keep my version up-to-date with future Gallery 1 releases.
My version, if you're not running embedded and you request it, will use the style sheet for your album to set colors and fonts. I'd rather not add more functionality to this code. Perhaps the G2 replacement for block-random will be able to draw the photo frame more easily, given the code modularity of G2.
-Jeff
Maintainer of block-random-enhanced.php