Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-03-18 23:55:31

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Admin-side plugin example

Here’s a trivial example of an admin-side plugin. It requires Textpattern RC3 rev 198 or higher.

template source
plugin

It adds a simple ‘testing’ tab to the ‘extensions’ navigation section.

A few quick pre-emptive answers:

  • The extensions section won’t appear when the admin > plugins tab is active. That’s a safety measure: admin-side plugins are disabled when that tab is active, so that a corrupt or buggy plugin can be safely deactivated.
  • There’s a new $plugin['type'] setting in the plugin template. If set to 1, the plugin will be loaded in both the admin and public web interfaces. If set to 0, or not set at all, the plugin will be loaded on the public side only.
  • You can mix admin-side code with taghandlers and other public-side code. Check the value of the ‘txpinterface’ constant to see which side you’re on.
  • You can add multiple tabs and multiple event handler callbacks. Multiple handlers can be registered for a single event and/or step, but the order in which they’re called isn’t always predictable.
  • You can trigger on an event that’s already built in to Textpattern. For example, a blo.gs pinger might use register_callback('abc_myhandler', 'article', 'publish'). The optional $pre parameter is used to control whether the plugin handler is called before or after the built-in admin code.
  • It’s possible (but difficult and not recommended) to add new user interface elements to existing admin pages, by registering a callback that outputs javascript, which in turn modifies the DOM. If you don’t already know how to do that, don’t try.

Alex

Offline

#2 2005-03-19 01:32:34

bluearc21
Member
From: US.VA
Registered: 2004-02-24
Posts: 62
Website

Re: Admin-side plugin example

I love it.


“If you build it, they will come.”

Offline

#3 2005-03-19 03:12:49

wilshire
Plugin Author
From: Akron, Ohio
Registered: 2004-08-27
Posts: 656
Website

Re: Admin-side plugin example

Very nice indeed.

Of course I want to try the one thats difficult and not recommended.

Offline

#4 2005-03-19 06:21:44

wilshire
Plugin Author
From: Akron, Ohio
Registered: 2004-08-27
Posts: 656
Website

Re: Admin-side plugin example

Is it possible to register a callback for all events? Essentially, something that would be added to each page in the admin interface?

One thing that might help in this regard would be to have access to the areas array that is created in txplib_head.php since it contains all of the possible events in the admin interface. Unfortunately, it looks like load_plugins(1); is called right before txplib_head.php is included in textpattern/index.php. Is there any way around this?

EDIT: Upon further thought, the above would only get you so far. It would work fine on a base install. But as soon as you installed other admin plugins which registered their own events you wouldn’t have any way of being aware of those, would you?

Last edited by wilshire (2005-03-19 15:38:26)

Offline

#5 2005-03-21 21:19:25

rob_roy
Archived Plugin Author
Registered: 2005-02-28
Posts: 18

Re: Admin-side plugin example

Now if only I were smart enough to figure out how to build a plugin that would allow the author to select Textile, Textile 2, Markdown or nothing.

Offline

#6 2005-03-21 23:04:04

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: Admin-side plugin example

> rob_roy wrote:
> Now if only I were smart enough to figure out how to build a plugin that would allow the author to select Textile, Textile 2, Markdown or nothing.

do it do it! please somebody do it! :)


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#7 2005-03-21 23:13:01

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

Re: Admin-side plugin example

killer idea, but I’m going to go out on a limb and say that I think it’s still not possible. there are several places where classTextile.php is hardcoded

BUT – that said, I know zem is a clever little devil and he could have already thought of ways to override textpattern functions. Any tips?

Offline

#8 2005-05-08 21:25:16

Jeremie
Member
From: Provence, France
Registered: 2004-08-11
Posts: 1,578
Website

Re: Admin-side plugin example

> Andrew wrote:

> Any tips?

Send cheese to the dvlp ? The ability of choosing the parser should be a core feature :) Well, maybe not for 1.0

Offline

#9 2005-05-22 14:18:44

tranquillo
Archived Plugin Author
Registered: 2005-03-07
Posts: 127
Website

Re: Admin-side plugin example

Exchange the first if-statement in the plugin template with the following code to display the tab title in your language:

if (@txpinterface == 'admin') {

	$title = gTxt('tab_testing'); // new line

	// Add a new tab under 'extensions' called translation(testing), for the 'test' event
	register_tab("extensions", "test", "$title"); // inserted variable $title

	// 'zem_admin_test' will be called to handle the 'test' event
	register_callback("zem_admin_test", "test");
}

and insert in your language file the translation like this:

tab_testing => translation

Offline

#10 2005-06-12 22:06:38

eightounces
New Member
From: Philadelphia
Registered: 2004-04-27
Posts: 7
Website

Re: Admin-side plugin example

This wasn’t working for me, until I added in the echo base64_encode(serialize($plugin)); at the end from the old templates- Was this left out purposefully? or am I just missing something?

Update: Nevermind, this doesn’t seem to be working either. I realized I’m missing the include file. doh.

Last edited by eightounces (2005-06-12 22:15:18)

Offline

#11 2005-07-21 18:22:42

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: Admin-side plugin example

The function add_privs() was added in revision 561, it looks like this:

add_privs($res, $perm = '1')

It should be called right before you register tabs and/or hooks.
The first parameter is a string that is identical to the event you define.
The second is a string that holds the comma-separated list of userlevels, that should have access.

EXAMPLE:

if (@txpinterface == 'admin') {
	// Allow userlevels 1,2,3 and 4 acess to this plugin.
	add_privs('test','1,2,3,4');

	// Add a new tab under 'extensions' called 'testing', for the 'test' event
	register_tab("extensions", "test", "testing");

	// 'zem_admin_test' will be called to handle the 'test' event
	register_callback("zem_admin_test", "test");
}

If this function is not used, the privileges will default to users that are set to “Publisher” (1) . We encourage plugin developers to always use this function. [in TXP 4.0.6 and higher, without using add_privs, none of the users are privileged —Ruud]

The template and description above will be updated shortly.

Offline

#12 2005-08-12 16:21:38

bauhouse
Archived Plugin Author
From: Abbotsford, BC Canada
Registered: 2004-06-29
Posts: 68
Website

Re: Admin-side plugin example

zem, your links don’t appear to be working.

Offline

Board footer

Powered by FluxBB