2 rcs_id('$Id: WikiFormRich.php,v 1.3 2004-07-09 13:05:34 rurban Exp $');
4 Copyright 1999, 2000, 2001, 2002, 2004 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * This is another replacement for MagicPhpWikiURL forms.
25 * Previously encoded with the "phpwiki:" syntax.
27 * Enhanced WikiForm to be more generic:
28 * - editbox[] name=.. value=.. text=..
29 * - checkbox[] name=.. value=0|1 checked text=..
30 * - radiobutton[] name=.. value=.. text=..
31 * - pulldown[] name=.. values=.. selected=.. text=.. (not yet!)
32 * - hidden[] name=.. value=..
33 * - action, submit buttontext, optional cancel button (bool)
34 * - method=GET or POST ((Default: POST).
36 * values which are constants are evaluated.
37 * The cancel button must be supported by the action. (which?)
40 <?plugin WikiFormRich action=dumpserial method=GET
41 checkbox[] name=include value="all"
42 editbox[] name=directory value=DEFAULT_DUMP_DIR
43 editbox[] name=pages value=*
44 editbox[] name=exclude value="" ?>
45 <?plugin WikiFormRich action=dumphtml method=GET
46 editbox[] name=directory value=HTML_DUMP_DIR
47 editbox[] name=pages value="*"
48 editbox[] name=exclude value="" ?>
50 <?plugin WikiFormRich action=loadfile method=GET
51 editbox[] name=source value=DEFAULT_WIKI_PGSRC
52 checkbox[] name=overwrite value=1
53 editbox[] name=exclude value="" ?>
55 class WikiPlugin_WikiFormRich
59 return _("Provide generic WikiForm input buttons");
62 function getVersion() {
63 return preg_replace("/[Revision: $]/", '',
67 function getDefaultArguments() {
68 return array('action' => false, // required argument
69 'method' => 'POST', // or GET
71 'buttontext' => false, // for the submit button
72 'cancel' => false, // boolean if the action supports cancel also
76 function handle_plugin_args_cruft($argstr, $args) {
77 $allowed = array("editbox", "hidden", "checkbox", "radiobutton", "pulldown");
78 // no editbox[] = array(...) allowed (space)
79 $arg_array = preg_split("/\n/", $argstr);
80 // for security we should check this better
82 for ($i = 0; $i < count($arg_array); $i++) {
83 if (preg_match("/^\s*(".join("|",$allowed).")\[\]\s+(.+)\s*$/", $arg_array[$i], $m)) {
85 $this->inputbox[][$name] = array(); $i = count($this->inputbox) - 1;
86 foreach (preg_split("/[\s]+/", $m[2]) as $attr_pair) {
87 list($attr,$value) = preg_split("/\s*=\s*/", $attr_pair);
88 if (preg_match('/^"(.*)"$/', $value, $m))
90 elseif (defined($value))
91 $value = constant($value);
92 $this->inputbox[$i][$name][$attr] = $value;
94 //trigger_error("not yet finished");
95 //eval('$this->inputbox[]["'.$m[1].'"]='.$m[2].';');
97 trigger_error(sprintf("Invalid argument %s ignored",htmlentities($arg_array[$i])),
104 function run($dbi, $argstr, &$request, $basepage) {
105 extract($this->getArgs($argstr, $request));
106 if (empty($action)) {
107 return $this->error(fmt("A required argument '%s' is missing.","action"));
109 $form = HTML::form(array('action' => $request->getPostURL(),
111 'class' => 'wikiadmin',
112 'accept-charset' => $GLOBALS['charset']),
113 HiddenInputs(array('action' => $action,
114 'pagename' => $basepage)));
115 foreach ($this->inputbox as $inputbox) {
116 foreach ($inputbox as $inputtype => $input) {
119 $input['type'] = 'checkbox';
120 if (empty($input['name']))
121 return $this->error("A required argument '%s' is missing.","checkbox[][name]");
122 if (empty($input['value'])) $input['value'] = 1;
123 if (empty($input['text']))
124 $input['text'] = gettext($input['name'])."=".$input['value'];
125 $text = $input['text'];
126 unset($input['text']);
127 if (!empty($input['checked'])) $input['checked'] = 'checked';
128 $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
131 $input['type'] = 'text';
132 if (empty($input['name']))
133 return $this->error("A required argument '%s' is missing.","editbox[][name]");
134 if (empty($input['text'])) $input['text'] = gettext($input['name']);
135 $text = $input['text'];
136 unset($input['text']);
137 $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
140 $input['type'] = 'radio';
141 if (empty($input['name']))
142 return $this->error("A required argument '%s' is missing.","radiobutton[][name]");
143 if (empty($input['text'])) $input['text'] = gettext($input['name']);
144 $text = $input['text'];
145 unset($input['text']);
146 if ($input['checked']) $input['checked'] = 'checked';
147 $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
150 $input['type'] = 'hidden';
151 if (empty($input['name']))
152 return $this->error("A required argument '%s' is missing.","hidden[][name]");
153 unset($input['text']);
154 $form->pushContent(HTML::input($input));
156 return $this->error("Sorry, pulldown not yet supported");
160 if ($request->getArg('start_debug'))
161 $form->pushContent(HTML::input(array('name' => 'start_debug',
162 'value' => $request->getArg('start_debug'),
163 'type' => 'hidden')));
164 if (empty($buttontext)) $buttontext = $action;
165 $submit = Button('submit:', $buttontext, $class);
167 $form->pushContent(HTML::span(array('class' => $class),
168 $submit, Button('submit:cancel', _("Cancel"), $class)));
170 $form->pushContent(HTML::span(array('class' => $class),
177 // $Log: not supported by cvs2svn $
178 // Revision 1.2 2004/07/09 10:25:52 rurban
179 // fix the args parser
181 // Revision 1.1 2004/07/02 11:03:53 rurban
182 // renamed WikiFormMore to WikiFormRich: better syntax, no eval (safer)
184 // Revision 1.3 2004/07/01 13:59:25 rurban
185 // enhanced to allow arbitrary order of args and stricter eval checking
187 // Revision 1.2 2004/07/01 13:14:01 rurban
190 // Revision 1.1 2004/07/01 13:11:53 rurban
191 // more generic forms
200 // c-hanging-comment-ender-p: nil
201 // indent-tabs-mode: nil