Estimating entry length? Dynamically parameterizing plugins?

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
Mekk
Regular
Posts: 54
Joined: Tue Jul 22, 2008 7:53 pm
Contact:

Estimating entry length? Dynamically parameterizing plugins?

Post by Mekk » Tue Dec 09, 2008 10:12 pm

Well, my next idea: I would like to make my sidebars conditional, so their content depend on the entry length (so I build long sidebar along the long article, but cut it to the minimum along the short note). I am in particular looking for the following suggestions:

a) what could be the best method to estimate the entry length (while displaying it, from index.tpl)? It need not be very accurate, but it would be nice to know whether it is rather about 30 lines, or maybe about 300... Which variable should I access to avoid performance costs?

b) It would be nice if I could dynamically set the numer of items shown by serendipity_plugin_recententries and serendipity_plugin_comments. What could be the easiest way to achieve this? Note: I am currently rendering them calling explicite:

{serendipity_showPlugin id="..."}

in some .tpl. Ideal solution would be if I could just pass some params here and have them overwrite the configuration saved in the database...

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Estimating entry length? Dynamically parameterizing plug

Post by garvinhicking » Wed Dec 10, 2008 11:34 am

Hi!

a.) I would fetch the {$entry.body} and {$entry.extended} lengths. Note that you will not be able to calculate "lines", only "bytes" or "words". You can get this in index.tpl if you use the same loops like in entries.tpl (you need to iterate on $entries), but the array will only contain one entry, if {$view == 'entry'}. Of course another way is to use a custom event plugin that counts the length on the current entry by using one of the frontend_* event hooks and checking the $entry data immediately.

b.) That's not possible, because you cannot pass individual options on serendipity_showplugin. They always use the otpions you configured in the plugin. If you do not want that, you must create your own plugins,. or extend the current ones to be able to specify external parameters.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

Mekk
Regular
Posts: 54
Joined: Tue Jul 22, 2008 7:53 pm
Contact:

Post by Mekk » Wed Dec 10, 2008 11:58 am

Considering all this, I will probably go with a lazy route:

- flag short posts explicite using some custom property and testing for it in .tpls

- duplicate plugins (= create one history plugin with 10 entries and another with 5 entries) and just pick one of those depending on the setting above

Post Reply