One of the most powerful features of established blogging/small CMS tools like Movable Type is the wealth of plugins that are available to add additional functionality to the software. Textpattern, still young, has only just gained the ability to install plugins into its architecture, so I’ve taken the opportunity to write some of those easy and obvious plugins that every CMS is duty bound to have.
Textpattern plugins are very simple to implement. A plugin consists of a single function, the name of which is used as a template tag. Any attributes to that tag are passed to the function as parameters. Stored in the database, the plugin functions are retrieved at run-time and are executed within the scope of the primary functions – you’re directly in the engine room. This makes plugins very quick to develop, as all the standard functions that TXP uses are also available to plugins.
Here’s a few I’ve created so far. Typically they’ve taken about an hour each, but this includes my learning time and the time it takes to establish a workflow in something new. I will get quicker.
Random Image by Category picks an image at random from those the user has uploaded through TXP. By specifying a category, the user can limit the selection to any single image category as defined within their setup. The template tag looks like this:
<txp:dru_random_image category="donkies" />
Recent Referers works much in the same way as TXP’s own recent articles and recent comments tags. It digs through the user’s referer logs and brings back a list of the most recent. As is standard in TXP, the resulting XHTML can be controlled through a basic set of attributes:
<txp:dru_recent_referers limit="10" break="li" wraptag="ul" />
Chatometer is again very similar. Its purpose is to list articles by the number of comments they receive. It gives some idea of which articles are the busiest in terms of dicussion, which is often a good pointer to the most interesting articles. Forgive the name.
<txp:dru_chatometer limit="10" wraptag="ul" break="li" />
Random Text grabs a random text string from either a database table or a text file. This could be useful for all sort of things from a quote-of-the-day to a random site strap line, to anything really.
To randomize from file, you simply upload a text file to your site containing the items to be picked from. You can specify your own delimiter, but the default is one item per line (omit the delimiter attribute for one-per-line). Set the source to “file” and the path to the full path to your file.
<txp:dru_random_text source="file" path="/path/to/text/file" delimiter="|" />
To randomize from a database table, the plugin picks a named column from a random row in a named table. The table needs to be in the same database that TXP is using. You specify table and column attributes, and set the source attribute to “database”.
<txp:dru_random_text source="database" table="textpattern" column="Title" />
A new plugin is disabled by default after it is installed. The user must then switch plugin on before it is ever run on their live site. The wise will remember to check the contents of a plugin before enabling it, as the consequences of a malicious plugin could be dire. I believe Dean has plans for an approved plugins scheme, which would help tremendously in this respect.
So there we have it. Plugins in Textpattern.



Comments
...but the default is one item per line (omit the delimited attribute for one-per-line).
It’s delimeter. Sorry, I just can’t stand typos when I see ‘em.
Oh, and great plugins, too. Especially the random image one… I might use that for my header. maybe
That would be groovy!
:)
http://www.nathanpitman.com/bio/index.php?id=39
http://weblogs.asp.net/jezell/archive/2004/05/26/142045.aspx
$out[] = tag($domain,'a',' href="http://'.$refer.'" title="Recorded: '.$ref_time.'"');needs to be replaced with:
$out[] = tag($domain,'a',' href="http://'.htmlspecialchars($refer).'" title="Recorded: '.htmlspecialchars($ref_time).'"');before enabling the plugin.
I’ll update the download today at some point.
Great work!
I recently installed your recent referrers plugin for textpattern… however it for some reason was displaying empty refer listings, when your code seems to request it doesn’t.
So, I changed the
$rs = getRowscommand to not use isnull, but instead (refer like '%.%'), with the idea that any valid referrer will have a dot in it, surrounded by text on two sides.Another problem cropped up where a TxP would record some referrers with an extra // in front of them. So I added the following line:
$refer = str_replace(’//’,’’,$refer);
in the foreach loop after “extract($a)”
I’m running TxP rev 57, I have no idea if this is some temporary bug of Dean’s, but there you have it. I am a total PHP newbie, so please forgive me if using a variable to compute itself is bad form.
Just noticed though that in the upgrade from RC1 to the RC3 that chatometer now seems to be using “messy” URLs instead of the “clean” ones it used to before (and that I use everywhere else on my site). Not a massive issue, but over time might cause some schizophrenia in search engine results…
I have used your plugin “RandomText” on my site, but it could show russian (cyrillic) symbols I see. Is it bug?
I recieve something like this: ���������� ������ 2, instead Интересная цитата 2
I wanted to make your random quote work for a big 7000 records table I had… and I maybe found a small bug in the plugin script :
On line 12 (or 13… ha ha), you wrote :
if($rs) return $rs[O];I changed this to :
if($rs) return $rs[$column];Well it’s not a bug, but when you have a table
with more than 1 column, it works fine like
this (got PHP5).
I’ll modify the plugin to have the author (another column) printed also. Can send you the final release if you’re intersted.
Bruno.
Thank for great Chatometer plugin!