2 rcs_id('$Id: WikiFormMore.php,v 1.2 2004-07-01 13:14:01 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 * - required and optional editboxes
29 * - check boxes (flags)
30 * - radio buttons (selections)
31 * - pulldowns (selections)
33 * - action, submit buttontext, optional cancel button
36 <?plugin WikiFormMore action=dumpserial method=GET
37 checkboxes[]=array('name'=>"include",'value'=>"all")
38 editboxes[]=array('name'=>"directory",'value'=>DEFAULT_DUMP_DIR)
39 editboxes[]=array('name'=>"pages",'value'=>"*")
40 editboxes[]=array('name'=>"exclude",'value'=>"") ?>
41 <?plugin WikiFormMore action=dumphtml method=GET
42 editboxes[]=array('name'=>"directory",'value'=>HTML_DUMP_DIR)
43 editboxes[]=array('name'=>"pages",'value'=>"*")
44 editboxes[]=array('name'=>"exclude",'value'=>"") ?>
46 class WikiPlugin_WikiFormMore
53 function getVersion() {
54 return preg_replace("/[Revision: $]/", '',
58 function getDefaultArguments() {
59 return array('action' => false,
62 'buttontext' => false,
67 function handle_plugin_args_cruft($argstr, $args) {
68 global $editboxes, $hidden, $checkboxes, $radiobuttons, $pulldown;
69 $allowed = array("editboxes", "hidden", "checkboxes", "radiobuttons", "pulldown");
70 $arg_array = preg_split("/[\n\s]+/", $argstr);
71 // for security we should check this better
72 for ($i = 0; $i < count($arg_array); $i++) {
73 if (!preg_match("/^(".join("|",$allowed).")(\[\d*\])\s*=/", $arg_array[$i])) {
74 trigger_error(sprintf("Invalid argument %s ignored",htmlentities($arg_array[$i])),
76 unset($arg_array[$i]);
79 $eval = str_replace("$ ;","","$".join("; $", $arg_array).";");
84 function run($dbi, $argstr, &$request, $basepage) {
85 global $editboxes, $hidden, $checkboxes, $radiobuttons, $pulldown;
86 $editboxes=array(); $hidden=array(); $checkboxes=array(); $radiobuttons=array(); $pulldown=array();
87 extract($this->getArgs($argstr, $request));
89 return $this->error(fmt("A required argument '%s' is missing.","action"));
91 $form = HTML::form(array('action' => $request->getPostURL(),
93 'class' => 'wikiadmin',
94 'accept-charset' => $GLOBALS['charset']),
95 HiddenInputs(array('action' => $action,
96 'pagename' => $basepage)));
98 foreach ($checkboxes as $input) {
99 $input['type'] = 'checkbox';
100 if (empty($input['name']))
101 return $this->error("A required argument '%s' is missing.","checkboxes[][name]");
102 if (empty($input['value'])) $input['value'] = 1;
103 if (empty($input['text']))
104 $input['text'] = gettext($input['name'])."=".$input['value'];
105 $text = $input['text'];
106 unset($input['text']);
107 if (!empty($input['checked'])) $input['checked'] = 'checked';
108 $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
112 foreach ($radiobuttons as $input) {
113 $input['type'] = 'radio';
114 if (empty($input['name']))
115 return $this->error("A required argument '%s' is missing.","radiobuttons[][name]");
116 if (empty($input['text'])) $input['text'] = gettext($input['name']);
117 $text = $input['text'];
118 unset($input['text']);
119 if (empty($input['value'])) $input['value'] = 1;
120 if ($input['checked']) $input['checked'] = 'checked';
121 $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
125 foreach ($editboxes as $input) {
126 $input['type'] = 'text';
127 if (empty($input['name']))
128 return $this->error("A required argument '%s' is missing.","editboxes[][name]");
129 if (empty($input['text'])) $input['text'] = gettext($input['name']);
130 $text = $input['text'];
131 unset($input['text']);
132 $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
136 foreach ($hidden as $input) {
137 $input['type'] = 'hidden';
138 if (empty($input['name']))
139 return $this->error("A required argument '%s' is missing.","hidden[][name]");
140 unset($input['text']);
141 $form->pushContent(HTML::input($input));
144 if ($request->getArg('start_debug'))
145 $form->pushContent(HTML::input(array('name' => 'start_debug',
146 'value' => $request->getArg('start_debug'),
147 'type' => 'hidden')));
148 if (empty($buttontext)) $buttontext = $action;
149 $submit = Button('submit:', $buttontext, $class);
151 $form->pushContent(HTML::span(array('class' => $class),
152 $submit, Button('submit:cancel', _("Cancel"), $class)));
154 $form->pushContent(HTML::span(array('class' => $class),
161 // $Log: not supported by cvs2svn $
162 // Revision 1.1 2004/07/01 13:11:53 rurban
163 // more generic forms
172 // c-hanging-comment-ender-p: nil
173 // indent-tabs-mode: nil