Hi,
I have added some code to roller which allows a theme author to randomly
select an image from a sub directory of the resources folder. For example
you can add the following code to a theme and use the
$ImageRandomizer.getImage("/a") to pickup an image randomly selected from
directory a under
${uploads.dir}/$bloghandle/a
<table cellpadding="0" cellspacing="10" border="0">
<tr>
<td align='center'>
<img alt='Image A' title='Image A'
src='$ImageRandomizer.getImage("/a")' border='0' />
</a><br /><br />
<img alt='Image B' title='Image B'
src='$ImageRandomizer.getImage("/b")' border='0' />
</a><br /><br />
<img alt='Image C' title='Image C'
src='$ImageRandomizer.getImage("/c")' border='0' />
</td>
</tr>
</table>
I added the ImageRandomizer as a singleton that caches the file names from a
directory and refreshes the cache every 30 minutes. To make the
ImageRandomizer accessible from the velocity templates I added it as a
Model, in the roller.properties the example below shows my roller.properties
file.
# Set of models to be made available for weblog page rendering
rendering.pageModels=\
org.apache.roller.ui.rendering.model.PageModel,\
org.apache.roller.ui.rendering.model.ImageRandomizerModel,\
org.apache.roller.ui.rendering.model.ConfigModel,\
org.apache.roller.ui.rendering.model.UtilitiesModel,\
org.apache.roller.ui.rendering.model.URLModel,\
org.apache.roller.ui.rendering.model.MessageModel,\
org.apache.roller.ui.rendering.model.CalendarModel,\
org.apache.roller.ui.rendering.model.MenuModel
You can see an example of the code running on www.sereneambition.com , the
flickr style badge on the right hand side is picking random images form the
roller uploads directory rather than the flickr site.
I have no idea what extension mechanism the roller developers have in mind
for people that need to add new features to roller. Is there a plug-in
framework? I only had about 10 hours to get this code written, working and
deployed so I did not have time to dig deeply into roller.
I hope you find this code useful to add to the next release of roller. To
make this code contribution useful and usable by users the upload feature on
the admin page should be enhanced to allow the user to specify where the
uploaded file should be placed in the resources directory. In the mean time
I am using scp to load up new images.
I have needs for a few more features that I am willing to add and contribute
back to roller community unless some one has already developed them and is
willing to share with me. The main thing I need next is a polling feature
kind of like what you see Slashdot. Has this already been developed?
Java files for code are attached. do with them as you please.
Enjoy
Adib