Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Txp Plugin Template for Developers
Textpattern plugins are perhaps best thought of as functions supplementary to those found in publish/taghandlers.php
. Functions residing in this file respond to <txp:foo />
and <txp:foo>bar</txp:foo>
tags found in pages, forms, articles and other dynamic templates in Textpattern.
A template for plugin distribution is available at:
Note that all the elements of the array must be filled in, and that the file must be saved as PHP, then opened in a browser to generate the encoded text which the Textpattern plugin installer can understand.
Quick notes on writing plugins
- Whatever is returned by the plugin function will be output by the corresponding
<txp:plugin_name />
tag. - The plugin function(s) has access to all the functions available to publish.php, including everything in /lib/. Further reference on these resources is forthcoming
- If you would like to pass variables to the plugin function(s) via paramaters in the
<txp:plugin_name />
tag, these will be passed as the first argument to the function as an associative array ($varname => $value
). - If you would like to pass a variable to the plugin function by enclosing it in
<txp:foo>bar</txp:foo>
, this will be passed as the second argument to the function as a string.
Update 20 September 2004:
The plugin distribution template has been updated.
As of 1.0rc1, plugins no longer need to be installed via browser file upload from a text file. The base64 string that was previously passed to Txp via upload can now be simply pasted in to the plugin editing tab. This I believe removes some unnecessary clumsy steps.
For the next couple of releases, the depracated plugin file upload form will remain, but if plugin developers would be willing to release in the new format, that would be supah.
Since the question was posed above, the reason base64 is used to encode the (already seralize()’d plugin array) is; to allow for any linebreaks and other white space that might slip into the plugin distro. Base64 would be very forgiving, for example, to plugin code that was sent as email text.
text*
Offline
Re: Txp Plugin Template for Developers
Can I add your post to the tag manual, in the Development related tag sections?.
I think that this post, with the source code of your plugin, could be an excellent example for anyone who want to develop his own plugins, and for everybody who is trying to learn what plugins are.
Pedro Palazón
http://kusor.net http://kusor.com
Offline
Re: Txp Plugin Template for Developers
Sure. I’m going to write a more complete developer guide for plugins, but this’ll do for now.
text*
Offline
Re: Txp Plugin Template for Developers
I still have problems running plugins:
I enabled plugins in lib/admin_conf.php
<code>
// ——————————————————————————————-
// plugins on or off
‘use_plugins’ => 1,
</code>
And still they won’t run…
I installed one of mine… and I installed the plugin (refer) from drew
but none of them will resolve? My own includes allways work.
Anything I missed out?
“The insistent messiahs-Type of Guy”
“Max wrote the code and uploaded it over a satellite connection from his top secret island hideway somewhere in the Mediterranean.”
Offline
Re: Txp Plugin Template for Developers
Have you edited the plugins()
function in publish.php?
Is PHP running in safe_mode? (turn on error reporting)
text*
Offline
Re: Txp Plugin Template for Developers
Dean – the ‘help’ content isn’t showing up in the plugins I’m making, although it does seem to show up with yours.
You bug <-> me bug?
drew mclellan
Offline
Re: Txp Plugin Template for Developers
Me bug – the clickable help arrow on plugins is pointing to the Txp Central Help Clearinghouse (Pueblo, CO) instead of the local installation.
It’s fixed in the (v. soon) forthcoming g1.18.
text*
Offline
Re: Txp Plugin Template for Developers
Stupid question – why are plugins encoded, instead of just being raw code?
Offline
Re: Txp Plugin Template for Developers
I’m guessing to save space in the database.
Offline
Re: Txp Plugin Template for Developers
base64 encoding doesn’t save space. It takes 3 bytes of binary data and represents it with 4 bytes of ASCII data. It is primarily used to transfer binary data as text or allow unicode to pass through non-unicode systems. It also has the added bonus of preventing certain characters from being present in the data that is being passed in to the database, but Dean is probably the only person who knows the true reason why we encode our plugins.
Offline
Re: Txp Plugin Template for Developers
Oh my bad. I had it in my head they were being compressed.
Offline
Re: Txp Plugin Template for Developers
I think a good modification to the template would be changing the echo line to the following:
echo chr(60).”?php\n\n”.”/*\n * Plugin: “.$plugin[‘name’].” v”.$plugin[‘version’].”\n * Author: “.$plugin[‘author’].”\n * Generated: “.date(“m.d.Y G:i”).”\n */\n\n”.’$’.“plugin=’” . base64_encode(serialize($plugin)) . “’\n?”.chr(62);
It adds the plugin name, author, plugin version, and date generated in a comment above the encoded $plugin value. This removes any doubts about the generated code.
Offline