Forum OpenACS Q&A: Random photo from photo-album?
Also, is there a reason Jeff's(?) improvements (I'm not sure what they are, but I've heard about them) haven't been folded into the photo-album in CVS? Or maybe they have?
I don't think it's been folded into CVS.
Regarding the first part of your question, I've never done it, but poking into Jeff's code, you could use the photo-album/www/photo.* page as a model.
The idea would be to create a simple "include" that would return the image tag for the photo.
First, change the query in photo.xql:
* remove the "ci.item_id = :photo_id"
* add a security check in the where clause:
and acs_permission__permission_p(ci.item_id, :user_id, 'read') = 't'
* grab a random image by appending:
order by random()
Copy the relevant parts of the adp (ie, the image tag plus admin links if you want).
Caveat: the query would cut across all photo-album instances. Also, since the image tag will be included potentially from another page/package, you will need to give the fully qualified URL for the image (ie, starting at /photos or wherever photo album(s) is mounted). I think you could do this by extending the query to join with cr_folders and site_nodes. Or if you're in a rush and you have only one photo album mounted, hard-code it as a parameter to the "include" (bad but easy).
Hope that helps. Let me know if you would like me to work on the code and send it your way.
I memory serves me right, Lars used have a random image function on his first blogger.
Pass in the package_id to the include template to limit to one package instance.
<include src="ramdom-photo" package_id="12345">
Or slightly more user friendly, pass in the url relative to the subsite root to the photo album instance to the include, and have the include determine the package id for the query.
<include src="random-photo" package="my_photos">
I think this might be a nice addition the photo-album.
If you have the time to do it, great! If not, I'll get around to it sometime. If I do it, should I submit it as a patch?
I think if the patch is nice and generic, then it should be committed to CVS, with Jeff's approval ofcourse.