-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmem_admin_parse.php
More file actions
199 lines (146 loc) · 5.04 KB
/
mem_admin_parse.php
File metadata and controls
199 lines (146 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
// Copy this file to a new name like abc_myplugin.php. Edit the code, then
// run this file at the command line to produce a plugin for distribution:
// $ php abc_myplugin.php > abc_myplugin-0.1.txt
// Plugin name is optional. If unset, it will be extracted from the current
// file name. Uncomment and edit this line to override:
$plugin['name'] = 'mem_admin_parse';
$plugin['version'] = '0.2.4';
$plugin['author'] = 'Michael Manfre';
$plugin['author_uri'] = 'http://manfre.net/';
$plugin['description'] = 'Provides functions to parse txp tags in the admin interface.';
$plugin['type'] = 1; // 0 for regular plugin; 1 if it includes admin-side code
@include_once('../zem_tpl.php');
if (0) {
?>
# --- BEGIN PLUGIN HELP ---
h2. mem_admin_parse
p. This plugin allows other plugins to parse text for txp tags, in a fashion similar to public side plugins. This plugin is designed to only be used by other plugins.
h3. Function: admin_parse(string text, bool use_textile)
p. Param text is the text string that will be parsed for tags.
p. Param use_textile specifies whether or not text is Textile formatted and should be converted to html before being parsed. Default is not to parse.
h3. Admin Tag: mem_gps
p. This tag will output the POST or GET parameter value, and is designed to be a generic postback tag for relaying information to the user after submitting a form.
p. <code><txp:mem_gps name="_argname_" /></code>
h3. mem_if_query name="url_param_name" value="url_param_value"
h3. mem_if_step name="step_name"
# --- END PLUGIN HELP ---
<?php
}
# --- BEGIN PLUGIN CODE ---
////////////////////////////////////////////////////////////
// Plugin mem_admin_parse
// Author: Michael Manfre (http://manfre.net/)
////////////////////////////////////////////////////////////
if (@txpinterface == 'admin') {
$no_tag = array( 'admin', 'article', 'auth', 'category', 'css', 'diag', 'discuss',
'file', 'form', 'image', 'import', 'link', 'list', 'log', 'page',
'plugin', 'prefs', 'preview', 'section', 'tag' );
global $event;
if (!in_array($event, $no_tag))
include_once txpath.'/publish/taghandlers.php';
function admin_parse($text,$use_textile=false)
{
if ($use_textile===true) {
include_once txpath.'/lib/classTextile.php';
$textile = new Textile();
$text = $textile->TextileThis($text);
}
$f = '/<txp:(\S+)\b(.*)(?:(?<!br )(\/))?'.chr(62).'(?(3)|(.+)<\/txp:\1>)/sU';
return preg_replace_callback($f, 'admin_processTags', $text);
}
// -------------------------------------------------------------
function admin_processTags($matches)
{
global $pretext, $production_status, $txptrace, $txptracelevel, $txp_current_tag;
$tag = $matches[1];
$trouble_makers = array(
'link'
);
if (in_array($tag, $trouble_makers))
{
$tag = 'tpt_'.$tag;
}
$atts = isset($matches[2]) ? splat($matches[2]) : '';
$thing = isset($matches[4]) ? $matches[4] : null;
$old_tag = @$txp_current_tag;
$txp_current_tag = '<txp:'.$tag.
($atts ? $matches[2] : '').
($thing ? '>' : '/>');
trace_add($txp_current_tag);
@++$txptracelevel;
if ($production_status == 'debug')
{
maxMemUsage(trim($matches[0]));
}
$out = '';
if (function_exists($tag))
{
$out = $tag($atts, $thing, $matches[0]);
}
// deprecated, remove in crockery
elseif (isset($pretext[$tag]))
{
$out = escape_output($pretext[$tag]);
trigger_error(gTxt('deprecated_tag'), E_USER_NOTICE);
}
else
{
trigger_error(gTxt('unknown_tag'), E_USER_WARNING);
}
@--$txptracelevel;
if (isset($matches[4]))
{
trace_add('</txp:'.$tag.'>');
}
$txp_current_tag = $old_tag;
return $out;
}
} else {
if (function_exists('parse')) {
function admin_parse($text,$use_textile=false) {
return parse($text);
}
}
}
// -------------------------------------------------------------
function mem_gps($atts) {
extract(lAtts(array(
'name' => '',
'class' => '',
'wraptag' => 'div',
'formatting' => 'none'
),$atts));
$val = gps($name);
if ($formatting=='textile') {
include_once txpath.'/lib/classTextile.php';
$t = new Textile();
$val = $t->TextileThis($val);
} else if ($formatting=='linebreaks') {
$val = nl2br(trim($val));
} else if ($formatting=='category_title') {
$val = fetch_category_title($val);
} else if ($formatting=='section_title') {
$val = fetch_section_title($val);
}
if (isset($name))
return doTag( $val, $wraptag, $class);
}
// -------------------------------------------------------------
function mem_if_step($atts,$thing) {
global $step;
$cond = $step==$atts['name'];
return admin_parse(EvalElse($thing,$cond));
}
// -------------------------------------------------------------
function mem_if_query($atts,$thing) {
extract(lAtts(array(
'name' => '',
'value' => ''
),$atts));
$name = gps($name);
$cond = $name==$value;
return admin_parse(EvalElse($thing,$cond));
}
# --- END PLUGIN CODE ---
?>