Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2006-09-06 19:32:20
- saturnflyer
- Member
- Registered: 2006-01-22
- Posts: 40
developing an admin plugin
I’m sorry if I’m posting in the wrong place.
I’m trying to create a custom admin plugin where I want to update a database table.
I’ve looked through all the examples of creating plugins and they’ve been helpful, but I haven’t found anything about creating admin plugins (or perhaps I’ve missed it).
Does anyone have any basic examples or tutorials on how TXP handles submitting forms in the admin area?
This is my first attempt at a plugin. I was creating forms and a separate section to handle updates, but I started looking into creating a plugin.
Thanks very much for any help!
Offline
Re: developing an admin plugin
Assuming you use zem’s plugin template.
<code>$plugin[‘type’] = 1;</code>
And in the plugin code:
<pre><code>
if (txpinterface = = ‘admin’) { // remove space between the = = (it’s a forum thing)
add_privs(‘sat_your_plugin’, ’1,2,3,4,5,6’); // change privileges to fit your needs!!
register_tab(‘extentions’, ‘sat_your_plugin’, ‘your_tab_label’);
register_callback(‘sat_your_plugin’, ‘sat_your_plugin’);
}
function sat_your_plugin($event, $step) {
…
</code></pre>
Followed by whatever code you need for your plugin.
Basically that creates a new tab under extensions and calls the ‘sat_your_plugin’ function whenever someone clicks it.
$event is always ‘sat_your_plugin’, $step can be set by yourself. For example: $step = ‘save’ when you save a form. Makes it easy to do different things based on what step is taken.
If you want to know how forms are handled, take look at how it’s done for the other tabs in TXP (in the directory include. txp_link.php is a good one to get started. The logic shown there above the functions, can be placed in the sat_your_plugin function).
Last edited by ruud (2006-09-06 20:00:58)
Offline
#3 2006-09-14 23:03:46
- saturnflyer
- Member
- Registered: 2006-01-22
- Posts: 40
Re: developing an admin plugin
thanks. your reply was very helpful ruud.
I’m still working on this and I’m trying to wrap my head around using $step.
I’m trying to start out with a list of items and the ability to click on an text link to switch to an edit form. Can anyone tell me how to handle this? Is there a simple tutorial somwhere that explains how to do so?
I’ve been looking through the textpattern source for help, but its slow going.
Offline
Re: developing an admin plugin
zem’s example plugin has some documented code on an admin-side plugin:
http://svn.textpattern.com/development/4.0-plugin-template/zem_plugin_example.php
You can also take a look at other available admin-side plugins.
Offline
Re: developing an admin plugin
Since it’s a list of things, you’ll probably end up with a link like this:
<code><a href=“index.php?event=sat_your_plugin&step=edit&id=6”>edit</a></code>
and in the plugin code:
<pre><code>
if (txpinterface = = ‘admin’) { // remove space between the = = (it’s a forum thing)
add_privs(‘sat_your_plugin’, ’1,2,3,4,5,6’); // change privileges to fit your needs!!
register_tab(‘extentions’, ‘sat_your_plugin’, ‘your_tab_label’);
register_callback(‘sat_your_plugin’, ‘sat_your_plugin’);
register_callback(‘sat_your_plugin_edit’, ‘sat_your_plugin’, ‘edit’);
register_callback(‘sat_your_plugin_save’, ‘sat_your_plugin’, ‘save’);
}
function sat_your_plugin($event, $step) {
if ($step and $step != ‘list’) return;
/* show a list of items here */
}
function sat_your_plugin_edit($event, $step) {
$id = gps(‘id’);
/* probably fetch some data for that ID from a database or set some empty values if it’s a new form*/
echo /* begin form code here, see txplib_forms.php for useful functions */
echo ($id ? hInput(‘id’. $id) : ‘’) . eInput(‘sat_your_plugin’) . sInput(‘save’);
echo /* close form here */
}
function sat_your_plugin_save($event, $step) {
$id = gps(‘id’);
extract(doSlash(gpsa(array(‘your’, ‘form’, ‘variables’))));
if ($id) { /* existing thing */
safe_update(… /* see txplib_db.php for useful database functions */
}
else { /* new thing */
safe_insert(… /* see txplib_db.php for useful database functions */
}
return sat_your_plugin(‘’,’‘); /* back to showing the list after saving */
}
</code></pre>
Or you could not register the sat_your_plugin_edit/save step as a callback and use the sat_your_plugin function to execute the appropriate code for that step.
Last edited by ruud (2006-09-15 09:55:59)
Offline
Pages: 1