]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiFormMore.php
desc only
[SourceForge/phpwiki.git] / lib / plugin / WikiFormMore.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiFormMore.php,v 1.2 2004-07-01 13:14:01 rurban Exp $');
3 /**
4  Copyright 1999, 2000, 2001, 2002, 2004 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
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.
12
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.
17
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
21  */
22
23 /**
24  * This is another replacement for MagicPhpWikiURL forms.
25  * Previously encoded with the "phpwiki:" syntax.
26  *
27  * Enhanced WikiForm to be more generic:
28  * - required and optional editboxes 
29  * - check boxes (flags)
30  * - radio buttons (selections)
31  * - pulldowns (selections)
32  * - hidden args
33  * - action, submit buttontext, optional cancel button
34  * - GET or POST.
35  * Samples:
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'=>"") ?>
45  */
46 class WikiPlugin_WikiFormMore
47 extends WikiPlugin
48 {
49     function getName () {
50         return _("WikiForm");
51     }
52
53     function getVersion() {
54         return preg_replace("/[Revision: $]/", '',
55                             "\$Revision: 1.2 $");
56     }
57
58     function getDefaultArguments() {
59         return array('action' => false,
60                      'method' => 'POST',
61                      'class' => false,
62                      'buttontext' => false,
63                      'cancel'  => false,
64                      );
65     }
66
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])), 
75                               E_USER_WARNING);
76                 unset($arg_array[$i]);
77             }
78         }
79         $eval = str_replace("$ ;","","$".join("; $", $arg_array).";");
80         eval($eval);
81         return;
82     }
83
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));
88         if (empty($action)) {
89             return $this->error(fmt("A required argument '%s' is missing.","action"));
90         }
91         $form = HTML::form(array('action' => $request->getPostURL(),
92                                  'method' => $method,
93                                  'class'  => 'wikiadmin',
94                                  'accept-charset' => $GLOBALS['charset']),
95                            HiddenInputs(array('action' => $action,
96                                               'pagename' => $basepage)));
97         if ($checkboxes) {
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));
109             }
110         }
111         if ($radiobuttons) {
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));
122             }
123         }
124         if ($editboxes) {
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));
133             }
134         }
135         if ($hidden) {
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));
142             }
143         }
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);
150         if ($cancel) {
151             $form->pushContent(HTML::span(array('class' => $class),
152                                           $submit, Button('submit:cancel', _("Cancel"), $class)));
153         } else {
154             $form->pushContent(HTML::span(array('class' => $class),
155                                           $submit));
156         }
157         return $form;
158     }
159 };
160
161 // $Log: not supported by cvs2svn $
162 // Revision 1.1  2004/07/01 13:11:53  rurban
163 // more generic forms
164 //
165 //
166
167 // For emacs users
168 // Local Variables:
169 // mode: php
170 // tab-width: 8
171 // c-basic-offset: 4
172 // c-hanging-comment-ender-p: nil
173 // indent-tabs-mode: nil
174 // End:
175 ?>