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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
|
<?php // -*-php-*-
rcs_id('$Id: WikiFormRich.php,v 1.15 2004/11/26 18:25:33 rurban Exp $');
/*
Copyright 2004 $ThePhpWikiProgrammingTeam
This file is part of PhpWiki.
PhpWiki is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
PhpWiki is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PhpWiki; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* This is another replacement for MagicPhpWikiURL forms.
* Previously encoded with the "phpwiki:" syntax.
*
* Enhanced WikiForm to be more generic:
* - editbox[] name=.. value=.. text=..
* - checkbox[] name=.. value=0|1 checked text=..
* - radio[] name=.. value=.. text=..
* - pulldown[] name=.. value=.. selected=.. text=..
* - combobox[] name=.. method=.. value=.. selected=.. text=..
* - hidden[] name=.. value=..
* - submit[]
* - action, submit buttontext, optional cancel button (bool)
* - method=get or post, Default: post.
* @Author: Reini Urban
* Values which are constants are evaluated.
* The cancel button must be supported by the action.
* (just some wikiadmin actions so far)
* improve layout by: nobr=1
* some allow values as list from from <!plugin-list !>
Samples:
<?plugin WikiFormRich action=dumpserial method=get
checkbox[] name=include value="all"
editbox[] name=directory value=DEFAULT_DUMP_DIR
editbox[] name=pages value=*
editbox[] name=exclude value="" ?>
<?plugin WikiFormRich action=dumphtml method=get
editbox[] name=directory value=HTML_DUMP_DIR
editbox[] name=pages value="*"
editbox[] name=exclude value="" ?>
<?plugin WikiFormRich action=loadfile method=get
editbox[] name=source value=DEFAULT_WIKI_PGSRC
checkbox[] name=overwrite value=1
editbox[] name=exclude value="" ?>
<?plugin WikiFormRich action=TitleSearch method=get class=wikiadmin nobr=1
editbox[] name=s text=""
submit[]
checkbox[] name=case_exact
checkbox[] name=regex ?>
<?plugin WikiFormRich action=FullTextSearch method=get class=wikiadmin nobr=1
editbox[] name=s text=""
submit[]
checkbox[] name=case_exact
checkbox[] name=regex ?>
<?plugin WikiFormRich action=FuzzyPages method=get class=wikiadmin nobr=1
editbox[] name=s text=""
submit[]
checkbox[] name=case_exact ?>
<?plugin WikiFormRich action=AppendText buttontext="AddPlugin"
radio[] name=s value=<!plugin-list BackLinks page=WikiPlugin limit=10 !>
?>
<?plugin WikiFormRich action=AppendText buttontext="AddPlugin"
pulldown[] name=s text="Plugins: " value=<!plugin-list BackLinks page=WikiPlugin !>
?>
<?plugin WikiFormRich action=AppendText buttontext="AddCategory"
pulldown[] name=s text="Categories: " value=<!plugin-list TitleSearch s=Category !>
?>
*/
class WikiPlugin_WikiFormRich
extends WikiPlugin
{
function getName () {
return "WikiFormRich";
}
function getDescription () {
return _("Provide generic WikiForm input buttons");
}
function getVersion() {
return preg_replace("/[Revision: $]/", '',
"\$Revision: 1.15 $");
}
function getDefaultArguments() {
return array('action' => false, // required argument
'method' => 'post', // or get
'class' => 'wikiaction',
'buttontext' => false, // for the submit button. default: action
'cancel' => false, // boolean if the action supports cancel also
'nobr' => false, // "no break": linebreaks or not
);
}
/* TODO: support better block alignment: <br>, tables, indent
*/
function handle_plugin_args_cruft($argstr, $args) {
$allowed = array("editbox", "hidden", "checkbox", "radiobutton"/*deprecated*/,
"radio", "pulldown", "submit", "reset", "combobox");
// no editbox[] = array(...) allowed (space)
$arg_array = preg_split("/\n/", $argstr);
// for security we should check this better
$arg = '';
for ($i = 0; $i < count($arg_array); $i++) {
//TODO: we require an name=value pair here, but submit may go without also.
if (preg_match("/^\s*(".join("|",$allowed).")\[\](.*)$/", $arg_array[$i], $m)) {
$name = $m[1]; // one of the allowed input types
$this->inputbox[][$name] = array(); $j = count($this->inputbox) - 1;
$curargs = trim($m[2]);
// must match name=NAME and also value=<!plugin-list name !>
while (preg_match("/^(\w+)=((?:\".*\")|(?:\w+)|(?:\"?<!plugin-list.+!>\"?))\s*/",
$curargs, $m)) {
$attr = $m[1]; $value = $m[2];
$curargs = substr($curargs, strlen($m[0]));
if (preg_match("/^\"(.*)\"$/", $value, $m))
$value = $m[1];
if (in_array($name, array("pulldown","checkbox","radio","radiobutton","combobox"))
and preg_match('/^<!plugin-list.+!>$/', $value, $m))
// like pulldown[] name=test value=<!plugin-list BackLinks page=HomePage!>
{
$loader = new WikiPluginLoader();
$markup = null;
$basepage = null;
$plugin_str = preg_replace(array("/^<!/","/!>$/"),array("<?","?>"), $value);
// will return a pagelist object! pulldown,checkbox,radiobutton
$value = $loader->expandPI($plugin_str, $GLOBALS['request'], $markup, $basepage);
if (isa($value, 'PageList'))
$value = $value->_pages;
elseif (!is_array($value))
trigger_error(sprintf("Invalid argument %s ignored", htmlentities($arg_array[$i])),
E_USER_WARNING);
}
elseif (defined($value))
$value = constant($value);
$this->inputbox[$j][$name][$attr] = $value;
}
//trigger_error("not yet finished");
//eval('$this->inputbox[]["'.$m[1].'"]='.$m[2].';');
} else {
trigger_error(sprintf("Invalid argument %s ignored", htmlentities($arg_array[$i])),
E_USER_WARNING);
}
}
return;
}
function run($dbi, $argstr, &$request, $basepage) {
extract($this->getArgs($argstr, $request));
if (empty($action)) {
return $this->error(fmt("A required argument '%s' is missing.", "action"));
}
$form = HTML::form(array('action' => $request->getPostURL(),
'method' => strtolower($method),
'class' => 'wikiaction',
'accept-charset' => $GLOBALS['charset']),
HiddenInputs(array('action' => $action)));
$nbsp = HTML::Raw(' ');
$already_submit = 0;
foreach ($this->inputbox as $inputbox) {
foreach ($inputbox as $inputtype => $input) {
if ($inputtype == 'radiobutton') $inputtype='radio'; // convert from older versions
$input['type'] = $inputtype;
$text = '';
if ($inputtype != 'submit') {
if (empty($input['name']))
return $this->error(fmt("A required argument '%s' is missing.",
$inputtype."[][name]"));
if (!isset($input['text'])) $input['text'] = gettext($input['name']);
$text = $input['text'];
unset($input['text']);
}
switch($inputtype) {
case 'checkbox':
case 'radio':
if (empty($input['value'])) $input['value'] = 1;
if (is_array($input['value'])) {
$div = HTML::div(array('class' => $class));
$values = $input['value'];
$name = $input['name'];
$input['name'] = $inputtype == 'checkbox' ? $name."[]" : $name;
foreach ($values as $val) {
$input['value'] = $val;
if ($request->getArg($name)) {
if ($request->getArg($name) == $val)
$input['checked'] = 'checked';
else
unset($input['checked']);
}
$div->pushContent(HTML::input($input), $nbsp, $val, $nbsp, "\n");
if (!$nobr)
$div->pushContent(HTML::br());
}
$form->pushContent($div);
} else {
if (empty($input['checked'])) {
if ($request->getArg($input['name']))
$input['checked'] = 'checked';
} else {
$input['checked'] = 'checked';
}
if ($nobr)
$form->pushContent(HTML::input($input), $nbsp, $text, $nbsp);
else
$form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
}
break;
case 'editbox':
$input['type'] = 'text';
if (empty($input['value']) and ($s = $request->getArg($input['name'])))
$input['value'] = $s;
if ($nobr)
$form->pushContent(HTML::input($input), $nbsp, $text, $nbsp);
else
$form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
break;
case 'combobox':
// TODO: moACDROPDOWN
$values = $input['value'];
unset($input['value']);
$input['type'] = 'text';
if (is_string($values)) $values = explode(",", $values);
if (empty($values)) {
if ($input['method'])
$input['value'] = xmlrequest($input['method']);
elseif ($s = $request->getArg($input['name']))
$input['value'] = $s;
} elseif (is_array($values)) {
$name = $input['name'];
unset($input['name']);
foreach ($values as $val) {
$input = array('value' => $val);
if ($request->getArg($name)) {
if ($request->getArg($name) == $val)
$input['selected'] = 'selected';
else
unset($input['selected']);
}
//$select->pushContent(HTML::option($input, $val));
}
}
if ($nobr)
$form->pushContent(HTML::input($input), $nbsp, $text, $nbsp);
else
$form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
break;
case 'pulldown':
$values = $input['value'];
unset($input['value']);
unset($input['type']);
$select = HTML::select($input);
if (is_string($values)) $values = explode(",", $values);
if (empty($values) and ($s = $request->getArg($input['name']))) {
$select->pushContent(HTML::option(array('value'=> $s), $s));
} elseif (is_array($values)) {
$name = $input['name'];
unset($input['name']);
foreach ($values as $val) {
$input = array('value' => $val);
if ($request->getArg($name)) {
if ($request->getArg($name) == $val)
$input['selected'] = 'selected';
else
unset($input['selected']);
}
$select->pushContent(HTML::option($input, $val));
}
}
$form->pushContent($text, $nbsp, $select);
break;
case 'reset':
case 'hidden':
$form->pushContent(HTML::input($input));
break;
// change the order of inputs, by explicitly placing a submit button here.
case 'submit':
//$input['type'] = 'submit';
if (empty($input['value'])) $input['value'] = $buttontext ? $buttontext : $action;
unset($input['text']);
if (empty($input['class'])) $input['class'] = $class;
if ($nobr)
$form->pushContent(HTML::input($input), $nbsp, $text, $nbsp);
else
$form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
// unset the default submit button
$already_submit = 1;
break;
}
}
}
if ($request->getArg('start_debug'))
$form->pushContent(HTML::input
(array('name' => 'start_debug',
'value' => $request->getArg('start_debug'),
'type' => 'hidden')));
if (!USE_PATH_INFO)
$form->pushContent(HiddenInputs(array('pagename' => $basepage)));
if (!$already_submit) {
if (empty($buttontext)) $buttontext = $action;
$submit = Button('submit:', $buttontext, $class);
if ($cancel) {
$form->pushContent(HTML::span
(array('class' => $class),
$submit,
Button('submit:cancel', _("Cancel"), $class)));
} else {
$form->pushContent(HTML::span(array('class' => $class),
$submit));
}
}
return $form;
}
};
// $Log: WikiFormRich.php,v $
// Revision 1.15 2004/11/26 18:25:33 rurban
// pulldown[] values="val1,val2,val3,..." simple comma seperated values
//
// Revision 1.14 2004/11/25 17:20:52 rurban
// and again a couple of more native db args: backlinks
//
// Revision 1.13 2004/11/25 12:04:17 rurban
// support extra submit[] and reste[] buttons to place it before. renamed radiobutton to radio
//
// Revision 1.12 2004/11/24 15:21:19 rurban
// docs
//
// Revision 1.11 2004/11/24 15:19:57 rurban
// allow whitespace in quoted text args
//
// Revision 1.10 2004/11/24 15:07:49 rurban
// added pulldown support, fixed plugin-list whitespace splitting
//
// Revision 1.9 2004/11/24 13:55:42 rurban
// omit unneccessary pagename arg
//
// Revision 1.8 2004/11/24 10:58:50 rurban
// just docs
//
// Revision 1.7 2004/11/24 10:40:04 rurban
// better nobr, allow empty text=""
//
// Revision 1.5 2004/11/24 10:14:36 rurban
// fill-in request args as with plugin-form
//
// Revision 1.4 2004/11/23 15:17:20 rurban
// better support for case_exact search (not caseexact for consistency),
// plugin args simplification:
// handle and explode exclude and pages argument in WikiPlugin::getArgs
// and exclude in advance (at the sql level if possible)
// handle sortby and limit from request override in WikiPlugin::getArgs
// ListSubpages: renamed pages to maxpages
//
// Revision 1.3 2004/07/09 13:05:34 rurban
// just aesthetics
//
// Revision 1.2 2004/07/09 10:25:52 rurban
// fix the args parser
//
// Revision 1.1 2004/07/02 11:03:53 rurban
// renamed WikiFormMore to WikiFormRich: better syntax, no eval (safer)
//
// Revision 1.3 2004/07/01 13:59:25 rurban
// enhanced to allow arbitrary order of args and stricter eval checking
//
// Revision 1.2 2004/07/01 13:14:01 rurban
// desc only
//
// Revision 1.1 2004/07/01 13:11:53 rurban
// more generic forms
//
// For emacs users
// Local Variables:
// mode: php
// tab-width: 8
// c-basic-offset: 4
// c-hanging-comment-ender-p: nil
// indent-tabs-mode: nil
// End:
?>
|