2 rcs_id('$Id: WikiFormRich.php,v 1.4 2004-11-23 15:17:20 rurban Exp $');
4 Copyright 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="" ?>
49 <?plugin WikiFormRich action=loadfile method=GET
50 editbox[] name=source value=DEFAULT_WIKI_PGSRC
51 checkbox[] name=overwrite value=1
52 editbox[] name=exclude value="" ?>
53 <?plugin WikiFormRich action=TitleSearch
54 editbox[] name=s text=""
55 checkbox[] name=case_exact
56 checkbox[] name=regex ?>
57 <?plugin WikiFormRich action=FullTextSearch
58 editbox[] name=s text=""
59 checkbox[] name=case_exact
60 checkbox[] name=regex ?>
61 <?plugin WikiFormRich action=FuzzyPages
62 editbox[] name=s text=""
63 checkbox[] name=case_exact ?>
65 class WikiPlugin_WikiFormRich
69 return "WikiFormRich";
71 function getDescription () {
72 return _("Provide generic WikiForm input buttons");
74 function getVersion() {
75 return preg_replace("/[Revision: $]/", '',
78 function getDefaultArguments() {
79 return array('action' => false, // required argument
80 'method' => 'POST', // or GET
82 'buttontext' => false, // for the submit button. default: action
83 'cancel' => false, // boolean if the action supports cancel also
87 function handle_plugin_args_cruft($argstr, $args) {
88 $allowed = array("editbox", "hidden", "checkbox", "radiobutton", "pulldown");
89 // no editbox[] = array(...) allowed (space)
90 $arg_array = preg_split("/\n/", $argstr);
91 // for security we should check this better
93 for ($i = 0; $i < count($arg_array); $i++) {
94 if (preg_match("/^\s*(".join("|",$allowed).")\[\]\s+(.+)\s*$/", $arg_array[$i], $m)) {
96 $this->inputbox[][$name] = array(); $i = count($this->inputbox) - 1;
97 foreach (preg_split("/[\s]+/", $m[2]) as $attr_pair) {
98 list($attr,$value) = preg_split("/\s*=\s*/", $attr_pair);
99 if (preg_match('/^"(.*)"$/', $value, $m))
101 elseif (defined($value))
102 $value = constant($value);
103 $this->inputbox[$i][$name][$attr] = $value;
105 //trigger_error("not yet finished");
106 //eval('$this->inputbox[]["'.$m[1].'"]='.$m[2].';');
108 trigger_error(sprintf("Invalid argument %s ignored",htmlentities($arg_array[$i])),
115 function run($dbi, $argstr, &$request, $basepage) {
116 extract($this->getArgs($argstr, $request));
117 if (empty($action)) {
118 return $this->error(fmt("A required argument '%s' is missing.","action"));
120 $form = HTML::form(array('action' => $request->getPostURL(),
122 'class' => 'wikiadmin',
123 'accept-charset' => $GLOBALS['charset']),
124 HiddenInputs(array('action' => $action,
125 'pagename' => $basepage)));
126 foreach ($this->inputbox as $inputbox) {
127 foreach ($inputbox as $inputtype => $input) {
130 $input['type'] = 'checkbox';
131 if (empty($input['name']))
132 return $this->error("A required argument '%s' is missing.","checkbox[][name]");
133 if (empty($input['value'])) $input['value'] = 1;
134 if (empty($input['text']))
135 $input['text'] = gettext($input['name'])."=".$input['value'];
136 $text = $input['text'];
137 unset($input['text']);
138 if (!empty($input['checked'])) $input['checked'] = 'checked';
139 $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
142 $input['type'] = 'text';
143 if (empty($input['name']))
144 return $this->error("A required argument '%s' is missing.","editbox[][name]");
145 if (empty($input['text'])) $input['text'] = gettext($input['name']);
146 $text = $input['text'];
147 unset($input['text']);
148 $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
151 $input['type'] = 'radio';
152 if (empty($input['name']))
153 return $this->error("A required argument '%s' is missing.","radiobutton[][name]");
154 if (empty($input['text'])) $input['text'] = gettext($input['name']);
155 $text = $input['text'];
156 unset($input['text']);
157 if ($input['checked']) $input['checked'] = 'checked';
158 $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
161 $input['type'] = 'hidden';
162 if (empty($input['name']))
163 return $this->error("A required argument '%s' is missing.","hidden[][name]");
164 unset($input['text']);
165 $form->pushContent(HTML::input($input));
167 return $this->error("Sorry, pulldown not yet supported");
171 if ($request->getArg('start_debug'))
172 $form->pushContent(HTML::input(array('name' => 'start_debug',
173 'value' => $request->getArg('start_debug'),
174 'type' => 'hidden')));
175 if (empty($buttontext)) $buttontext = $action;
176 $submit = Button('submit:', $buttontext, $class);
178 $form->pushContent(HTML::span(array('class' => $class),
179 $submit, Button('submit:cancel', _("Cancel"), $class)));
181 $form->pushContent(HTML::span(array('class' => $class),
188 // $Log: not supported by cvs2svn $
189 // Revision 1.3 2004/07/09 13:05:34 rurban
192 // Revision 1.2 2004/07/09 10:25:52 rurban
193 // fix the args parser
195 // Revision 1.1 2004/07/02 11:03:53 rurban
196 // renamed WikiFormMore to WikiFormRich: better syntax, no eval (safer)
198 // Revision 1.3 2004/07/01 13:59:25 rurban
199 // enhanced to allow arbitrary order of args and stricter eval checking
201 // Revision 1.2 2004/07/01 13:14:01 rurban
204 // Revision 1.1 2004/07/01 13:11:53 rurban
205 // more generic forms
213 // c-hanging-comment-ender-p: nil
214 // indent-tabs-mode: nil