Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

  1. Index
  2. » Archives
  3. » Txp Plugin Template for Developers

#1 2004-04-04 12:38:55

Dean
Founder (Gone, but not forgotten)
From: Languedoc
Registered: 2004-02-14
Posts: 235
Website

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:

txp_plugin_template.txt

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

#2 2004-04-04 13:08:20

kusor
Member
From: Spain
Registered: 2004-03-07
Posts: 93
Website

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.

Offline

#3 2004-04-04 13:15:26

Dean
Founder (Gone, but not forgotten)
From: Languedoc
Registered: 2004-02-14
Posts: 235
Website

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

#4 2004-04-05 12:19:05

Max Ziebell
Archived Plugin Author
From: Formentera and/or Berlin
Registered: 2004-03-26
Posts: 24
Website

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

#5 2004-04-05 12:33:38

Dean
Founder (Gone, but not forgotten)
From: Languedoc
Registered: 2004-02-14
Posts: 235
Website

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

#6 2004-04-06 19:11:28

Drew
Plugin Author
From: Red pillar box, Baker St.
Registered: 2004-02-15
Posts: 53
Website

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

#7 2004-04-07 15:50:07

Dean
Founder (Gone, but not forgotten)
From: Languedoc
Registered: 2004-02-14
Posts: 235
Website

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

#8 2004-06-03 21:05:30

tmacwrig
Archived Plugin Author
Registered: 2004-03-06
Posts: 204
Website

Re: Txp Plugin Template for Developers

Stupid question – why are plugins encoded, instead of just being raw code?

Offline

#9 2004-06-03 21:41:21

ramanan
Plugin Author
From: Toronto
Registered: 2004-03-12
Posts: 323
Website

Re: Txp Plugin Template for Developers

I’m guessing to save space in the database.

Offline

#10 2004-06-03 22:18:17

Manfre
Plugin Author
From: North Carolina
Registered: 2004-05-22
Posts: 588
Website

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

#11 2004-06-03 22:48:57

ramanan
Plugin Author
From: Toronto
Registered: 2004-03-12
Posts: 323
Website

Re: Txp Plugin Template for Developers

Oh my bad. I had it in my head they were being compressed.

Offline

#12 2004-06-09 01:44:24

Manfre
Plugin Author
From: North Carolina
Registered: 2004-05-22
Posts: 588
Website

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

  1. Index
  2. » Archives
  3. » Txp Plugin Template for Developers

Board footer

Powered by FluxBB