2 rcs_id('$Id: WikiFormRich.php,v 1.1 2004-07-02 11:03:53 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=.. value=.. text=..
32 * - hidden[] name=.. value=..
33 * - action, submit buttontext, optional cancel button (bool)
34 * - method=GET or POST.
37 <?plugin WikiFormRich action=dumpserial method=GET
38 checkbox[] name=include value="all"
39 editbox[] name=directory value=DEFAULT_DUMP_DIR
40 editbox[] name=pages value=*
41 editbox[] name=exclude value="" ?>
42 <?plugin WikiFormRich action=dumphtml method=GET
43 editbox[] name=directory value=HTML_DUMP_DIR
44 editbox[] name=pages value="*"
45 editbox[] name=exclude value="" ?>
47 <?plugin WikiFormRich action=loadfile method=GET
48 editbox[] name=source value=DEFAULT_WIKI_PGSRC
49 checkbox[] name=overwrite value=1
50 editbox[] name=exclude value="" ?>
52 class WikiPlugin_WikiFormRich
56 return _("Provide generic WikiForm input buttons");
59 function getVersion() {
60 return preg_replace("/[Revision: $]/", '',
64 function getDefaultArguments() {
65 return array('action' => false, // required argument
66 'method' => 'POST', // or GET
68 'buttontext' => false, // for the submit button
69 'cancel' => false, // boolean if the action supports cancel also
73 function handle_plugin_args_cruft($argstr, $args) {
74 $allowed = array("editbox", "hidden", "checkbox", "radiobutton", "pulldown");
75 // no editbox[] = array(...) allowed (space)
76 $arg_array = preg_split("/\n/", $argstr);
77 // for security we should check this better
79 for ($i = 0; $i < count($arg_array); $i++) {
80 if (preg_match("/^\s*(".join("|",$allowed).")\[\]\s+(.+)\s*$/", $arg_array[$i], $m)) {
81 $this->inputbox[][$name] = array(); $i = count($this->inputbox) - 1;
82 foreach (preg_split("/[\s+]/", $m[2]) as $attr_pair) {
83 list($attr,$value) = preg_split("/\s*=\s*/", $attr_pair);
84 if (preg_match('/^".*"$/', $value, $m))
86 elseif (defined($value))
87 $value = constant($value);
88 $this->inputbox[$i][$name][$attr] = $value;
90 //trigger_error("not yet finished");
91 //eval('$this->inputbox[]["'.$m[1].'"]='.$m[2].';');
93 trigger_error(sprintf("Invalid argument %s ignored",htmlentities($arg_array[$i])),
100 function run($dbi, $argstr, &$request, $basepage) {
101 extract($this->getArgs($argstr, $request));
102 if (empty($action)) {
103 return $this->error(fmt("A required argument '%s' is missing.","action"));
105 $form = HTML::form(array('action' => $request->getPostURL(),
107 'class' => 'wikiadmin',
108 'accept-charset' => $GLOBALS['charset']),
109 HiddenInputs(array('action' => $action,
110 'pagename' => $basepage)));
111 foreach ($this->inputbox as $inputbox) {
112 foreach ($inputbox as $inputtype => $input) {
115 $input['type'] = 'checkbox';
116 if (empty($input['name']))
117 return $this->error("A required argument '%s' is missing.","checkbox[][name]");
118 if (empty($input['value'])) $input['value'] = 1;
119 if (empty($input['text']))
120 $input['text'] = gettext($input['name'])."=".$input['value'];
121 $text = $input['text'];
122 unset($input['text']);
123 if (!empty($input['checked'])) $input['checked'] = 'checked';
124 $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
127 $input['type'] = 'text';
128 if (empty($input['name']))
129 return $this->error("A required argument '%s' is missing.","editbox[][name]");
130 if (empty($input['text'])) $input['text'] = gettext($input['name']);
131 $text = $input['text'];
132 unset($input['text']);
133 $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
136 $input['type'] = 'radio';
137 if (empty($input['name']))
138 return $this->error("A required argument '%s' is missing.","radiobutton[][name]");
139 if (empty($input['text'])) $input['text'] = gettext($input['name']);
140 $text = $input['text'];
141 unset($input['text']);
142 if ($input['checked']) $input['checked'] = 'checked';
143 $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
146 $input['type'] = 'hidden';
147 if (empty($input['name']))
148 return $this->error("A required argument '%s' is missing.","hidden[][name]");
149 unset($input['text']);
150 $form->pushContent(HTML::input($input));
152 return $this->error("Sorry, pulldown not yet supported");
156 if ($request->getArg('start_debug'))
157 $form->pushContent(HTML::input(array('name' => 'start_debug',
158 'value' => $request->getArg('start_debug'),
159 'type' => 'hidden')));
160 if (empty($buttontext)) $buttontext = $action;
161 $submit = Button('submit:', $buttontext, $class);
163 $form->pushContent(HTML::span(array('class' => $class),
164 $submit, Button('submit:cancel', _("Cancel"), $class)));
166 $form->pushContent(HTML::span(array('class' => $class),
173 // $Log: not supported by cvs2svn $
174 // Revision 1.3 2004/07/01 13:59:25 rurban
175 // enhanced to allow arbitrary order of args and stricter eval checking
177 // Revision 1.2 2004/07/01 13:14:01 rurban
180 // Revision 1.1 2004/07/01 13:11:53 rurban
181 // more generic forms
190 // c-hanging-comment-ender-p: nil
191 // indent-tabs-mode: nil