Skip to content

Commit 3be3bb8

Browse files
committed
Merge pull request #2 from gerhard/txp-45
TXP 4.5
2 parents 58a22ba + 9b805a9 commit 3be3bb8

24 files changed

+576
-420
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

.txp_plugin_template

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"Extending Textpattern":http://textbook.textpattern.net/wiki/index.php?title=Extending_Textpattern
2+
3+
"Plugin Tutorial":http://thresholdstate.com/articles/3975/anatomy-of-a-textpattern-plugin-part-1
4+
5+
"Mailinglist for plugin devs":http://lists.textpattern.com/
6+
7+
"Developer resources (further links, tools and help)":http://forum.textpattern.com/viewtopic.php?id=9881
8+

.txp_plugin_template/code.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//<?php
2+
// ----------------------------------------------------
3+
// Example public side tags
4+
5+
// A simple self-closing tag
6+
// <txp:zem_hello_world name="Bob" />
7+
8+
function zem_hello_world($atts) {
9+
extract(lAtts(array(
10+
'name' => 'Alice',
11+
),$atts));
12+
13+
// The returned value will replace the tag on the page
14+
return 'Hello, '.$name;
15+
}
16+
17+
// A simple enclosing tag
18+
// <txp:zem_lowercase>I LIKE SPAM</txp:lowercase>
19+
20+
function zem_lowercase($atts, $thing='') {
21+
return strtolower(parse($thing));
22+
}
23+
24+
// A simple conditional tag
25+
// <txp:zem_if_alice name="Alice">
26+
// Alice!
27+
// <txp:else />
28+
// Not alice.
29+
// </txp:zem_if_alice>
30+
31+
function zem_if_alice($atts, $thing) {
32+
extract(lAtts(array(
33+
'name' => 'Bob',
34+
),$atts));
35+
36+
return parse(EvalElse($thing, ($name == 'Alice')));
37+
}
38+
39+
// ----------------------------------------------------
40+
// Example admin side plugin
41+
42+
// Add a new tab to the Content area.
43+
// "test" is the name of the associated event; "testing" is the displayed title
44+
if (@txpinterface == 'admin') {
45+
$myevent = 'test';
46+
$mytab = 'testing';
47+
48+
// Set the privilege levels for our new event
49+
add_privs($myevent, '1,2');
50+
51+
// Add a new tab under 'extensions' associated with our event
52+
register_tab("extensions", $myevent, $mytab);
53+
54+
// 'zem_admin_test' will be called to handle the new event
55+
register_callback("zem_admin_test", $myevent);
56+
// 'zem_admin_test_lifecycle' will be called on plugin installation, activation, disactivation, and deletion
57+
register_callback("zem_admin_test_lifecycle", "plugin_lifecycle.zem_plugin_example");
58+
}
59+
60+
function zem_admin_test($event, $step) {
61+
// ps() returns the contents of POST vars, if any
62+
$something = ps("something");
63+
pagetop("Testing", (ps("do_something") ? "you typed: $something" : ""));
64+
65+
// The eInput/sInput part of the form is important, setting the event and step respectively
66+
67+
echo "<div align=\"center\" style=\"margin-top:3em\">";
68+
echo form(
69+
tag("Test Form", "h3").
70+
graf("Type something: ".
71+
fInput("text", "something", $something, "edit", "", "", "20", "1").
72+
fInput("submit", "do_something", "Go", "smallerbox").
73+
eInput("test").sInput("step_a")
74+
," style=\"text-align:center\"")
75+
);
76+
echo "</div>";
77+
}
78+
79+
// Act upon activation/deactivation, installtion/deletion.
80+
// $event will be "plugin_lifecycle.zem_plugin_example"
81+
// $step will be one of "installed", "enabled", disabled", and "deleted"
82+
function zem_admin_test_lifecycle($event, $step) {
83+
// View source to see the output
84+
echo comment("$event $step").n;
85+
}
86+

.txp_plugin_template/help.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
h1. Textile-formatted help goes here
2+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
// This is a PLUGIN TEMPLATE.
4+
5+
// Copy this file to a new name like abc_myplugin.php. Edit the code, then
6+
// run this file at the command line to produce a plugin for distribution:
7+
// $ php abc_myplugin.php > abc_myplugin-0.1.txt
8+
9+
// Plugin name is optional. If unset, it will be extracted from the current
10+
// file name. Plugin names should start with a three letter prefix which is
11+
// unique and reserved for each plugin author ('abc' is just an example).
12+
// Uncomment and edit this line to override:
13+
# $plugin['name'] = 'abc_plugin';
14+
15+
// Allow raw HTML help, as opposed to Textile.
16+
// 0 = Plugin help is in Textile format, no raw HTML allowed (default).
17+
// 1 = Plugin help is in raw HTML. Not recommended.
18+
# $plugin['allow_html_help'] = 0;
19+
20+
$plugin['code_file'] = realpath('code.php');
21+
$plugin['help_file'] = realpath('help.html');
22+
$plugin['version'] = '0.1';
23+
$plugin['author'] = 'Alex Shiels';
24+
$plugin['author_uri'] = 'http://thresholdstate.com/';
25+
$plugin['description'] = 'Short description (max 255 chars)';
26+
# Optional values
27+
$plugin['contributors'] = 'Contributor 1';
28+
$plugin['compatiblity'] = "4.2.0 (r3275)";
29+
30+
// Plugin load order:
31+
// The default value of 5 would fit most plugins, while for instance comment
32+
// spam evaluators or URL redirectors would probably want to run earlier
33+
// (1...4) to prepare the environment for everything else that follows.
34+
// Values 6...9 should be considered for plugins which would work late.
35+
// This order is user-overrideable.
36+
# $plugin['order'] = 5;
37+
38+
// Plugin 'type' defines where the plugin is loaded
39+
// 0 = public : only on the public side of the website (default)
40+
// 1 = public+admin : on both the public and admin side
41+
// 2 = library : only when include_plugin() or require_plugin() is called
42+
// 3 = admin : only on the admin side
43+
# $plugin['type'] = 0;
44+
45+
// Plugin 'flags' signal the presence of optional capabilities to the core plugin loader.
46+
// Use an appropriately OR-ed combination of these flags.
47+
// The four high-order bits 0xf000 are available for this plugin's private use.
48+
if (!defined('PLUGIN_HAS_PREFS')) define('PLUGIN_HAS_PREFS', 0x0001); // This plugin wants to receive "plugin_prefs.{$plugin['name']}" events
49+
if (!defined('PLUGIN_LIFECYCLE_NOTIFY')) define('PLUGIN_LIFECYCLE_NOTIFY', 0x0002); // This plugin wants to receive "plugin_lifecycle.{$plugin['name']}" events
50+
51+
# $plugin['flags'] = PLUGIN_HAS_PREFS | PLUGIN_LIFECYCLE_NOTIFY;
52+
53+
if (!defined('txpinterface'))
54+
include_once('zem_tpl.php');
55+
56+
?>
57+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
// This is a PLUGIN TEMPLATE.
4+
5+
// Copy this file to a new name like abc_myplugin.php. Edit the code, then
6+
// run this file at the command line to produce a plugin for distribution:
7+
// $ php abc_myplugin.php > abc_myplugin-0.1.txt
8+
9+
// Plugin name is optional. If unset, it will be extracted from the current
10+
// file name. Plugin names should start with a three letter prefix which is
11+
// unique and reserved for each plugin author ('abc' is just an example).
12+
// Uncomment and edit this line to override:
13+
# $plugin['name'] = 'abc_plugin';
14+
15+
// Allow raw HTML help, as opposed to Textile.
16+
// 0 = Plugin help is in Textile format, no raw HTML allowed (default).
17+
// 1 = Plugin help is in raw HTML. Not recommended.
18+
# $plugin['allow_html_help'] = 0;
19+
20+
$plugin['code_file'] = realpath('code.php');
21+
$plugin['help_file'] = realpath('help.html');
22+
$plugin['version'] = '0.1';
23+
$plugin['author'] = 'Alex Shiels';
24+
$plugin['author_uri'] = 'http://thresholdstate.com/';
25+
$plugin['description'] = 'Simple plugin example';
26+
# Optional values
27+
$plugin['contributors'] = 'Robert Wetzlmayr';
28+
$plugin['compatiblity'] = "4.2.0 (r3275)";
29+
30+
// Plugin load order:
31+
// The default value of 5 would fit most plugins, while for instance comment
32+
// spam evaluators or URL redirectors would probably want to run earlier
33+
// (1...4) to prepare the environment for everything else that follows.
34+
// Values 6...9 should be considered for plugins which would work late.
35+
// This order is user-overrideable.
36+
# $plugin['order'] = 5;
37+
38+
// Plugin 'type' defines where the plugin is loaded
39+
// 0 = public : only on the public side of the website (default)
40+
// 1 = public+admin : on both the public and admin side
41+
// 2 = library : only when include_plugin() or require_plugin() is called
42+
// 3 = admin : only on the admin side
43+
$plugin['type'] = 1;
44+
45+
// Plugin 'flags' signal the presence of optional capabilities to the core plugin loader.
46+
// Use an appropriately OR-ed combination of these flags.
47+
// The four high-order bits 0xf000 are available for this plugin's private use.
48+
if (!defined('PLUGIN_HAS_PREFS')) define('PLUGIN_HAS_PREFS', 0x0001); // This plugin wants to receive "plugin_prefs.{$plugin['name']}" events
49+
if (!defined('PLUGIN_LIFECYCLE_NOTIFY')) define('PLUGIN_LIFECYCLE_NOTIFY', 0x0002); // This plugin wants to receive "plugin_lifecycle.{$plugin['name']}" events
50+
51+
$plugin['flags'] = PLUGIN_HAS_PREFS | PLUGIN_LIFECYCLE_NOTIFY;
52+
53+
if (!defined('txpinterface'))
54+
include_once('zem_tpl.php');
55+
56+
?>
57+

.txp_plugin_template/zem_tpl.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
// Either copy classTextile.php to your plugin directory, or uncomment the following
4+
// line and edit it to give the location where classTextile.php can be found
5+
#ini_set('include_path', ini_get('include_path') . ':/full/path/to/textile');
6+
7+
exit(compile_plugin());
8+
9+
// -----------------------------------------------------
10+
11+
function strip_php_tags($input) {
12+
return preg_replace("/\<\?php|\?\>/", "", $input);
13+
}
14+
15+
function fetch_external_file($matches) {
16+
return strip_php_tags(file_get_contents($matches[1]));
17+
}
18+
19+
function build_file($file) {
20+
$out = strip_php_tags(file_get_contents($file));
21+
22+
if (empty($out))
23+
exit("Make sure $file exists");
24+
25+
// let's load the content of external files into our plugin file
26+
$regex = "/require_once\(\'(.+)\'\)\;/";
27+
$out = preg_replace_callback($regex, "fetch_external_file", $out);
28+
29+
return rtrim($out);
30+
}
31+
32+
function compile_plugin() {
33+
global $plugin;
34+
35+
if (!isset($plugin['name']))
36+
$plugin['name'] = basename($_SERVER['SCRIPT_FILENAME'], '.php');
37+
38+
$plugin['help'] = build_file($plugin['help_file']);
39+
$plugin['code'] = build_file($plugin['code_file']);
40+
41+
// textpattern will textile it, and encode html
42+
$plugin['help_raw'] = $plugin['help'];
43+
44+
// only do the Textile thing if help not already in HTML
45+
if ($plugin['allow_html_help'] == 0) {
46+
// This is for bc; and for help that needs to use
47+
@include('classTextile.php');
48+
if (class_exists('Textile')) {
49+
$textile = new Textile();
50+
$plugin['help'] = $textile->TextileThis($plugin['help']);
51+
}
52+
}
53+
54+
$plugin_information = array("\n# {$plugin['name']} v{$plugin['version']}", "# {$plugin['description']}", "#");
55+
$plugin_information[] = "# {$plugin['author']}";
56+
$plugin_information[] = "# {$plugin['author_uri']}";
57+
// Optional values, not all plugins will have them
58+
if ($plugin['contributors'] || $plugin['compatibility'])
59+
$plugin_information[] = "#";
60+
if ($plugin['contributors'])
61+
$plugin_information[] = "# Contributors: {$plugin['contributors']}";
62+
if ($plugin['compatibility'])
63+
$plugin_information[] = "# Minimum requirements: Textpattern {$plugin['compatibility']}";
64+
65+
$plugin_information = join($plugin_information, "\n");
66+
67+
$plugin['code'] = $plugin_information.$plugin['code'];
68+
69+
$plugin['md5'] = md5($plugin['code']);
70+
71+
$header = <<<EOF
72+
$plugin_information
73+
74+
# ......................................................................
75+
# This is a plugin for Textpattern - http://textpattern.com/
76+
# To install: textpattern > admin > plugins
77+
# Paste the following text into the 'Install plugin' box:
78+
# ......................................................................
79+
EOF;
80+
81+
$body = trim(chunk_split(base64_encode(gzencode(serialize($plugin))), 72));
82+
83+
// to produce a copy of the plugin for distribution, load this file in a browser.
84+
header('Content-type: text/plain');
85+
86+
return $header."\n\n".$body;
87+
}
88+
89+
?>
90+

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
### Unlimited custom fields for Textpattern
2+
3+
This plugin sits under the **Extensions** tab in the back-end and gives
4+
your custom fields new life. You can finally have custom fields that are
5+
selects, multi-selects, checkboxes, radios and textareas - besides the
6+
default input fields. You can predefine values for custom fields and you
7+
can select a single default value (selects, multi-selects, checkboxes
8+
and radios only). Rather then constantly typing in the same thing over
9+
and over again, just select or check it and you're set.
10+
11+
The plugin doesn't require any hacking of TXP, it's a straight install
12+
with instant gratification.
13+
14+
### License
15+
16+
Copyright (c) 2012 Gerhard Lazu
17+
18+
This program is free software; you can redistribute it and/or
19+
modify it under the terms of the GNU General Public License
20+
as published by the Free Software Foundation; either version 2
21+
of the License, or (at your option) any later version.
22+
23+
This program is distributed in the hope that it will be useful,
24+
but WITHOUT ANY WARRANTY; without even the implied warranty of
25+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26+
GNU General Public License for more details.
27+
28+
You should have received a copy of the GNU General Public License
29+
along with this program. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>.

forum.textile

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)