]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/EditMetaData.php
Replaced NBSP constant with a new nbsp() function. The return value of HTML::nbsp...
[SourceForge/phpwiki.git] / lib / plugin / EditMetaData.php
1 <?php // -*-php-*-
2 rcs_id('$Id: EditMetaData.php,v 1.2 2002-10-29 01:12:24 carstenklapp Exp $');
3 /**
4  * Plugin EditMetaData
5  *
6  * This plugin shows the current page-level metadata and gives
7  * an entry box for adding a new field or changing an existing
8  * one.  (A field can be deleted by specifying a blank value.)
9  * Certain fields, such as 'hits' cannot be changed.
10  *
11  * If there is a reason to do so, I will add support for revision-
12  * level metadata as well.
13  *
14  * Access by restricted to ADMIN_USER
15  *
16  * Written by MichaelVanDam, to test out some ideas about
17  * PagePermissions and PageTypes.
18  * Array support added by ReiniUrban.
19  */
20
21
22 class WikiPlugin_EditMetaData
23 extends WikiPlugin
24 {
25     function getName () {
26         return _("EditMetaData");
27     }
28
29     function getDescription () {
30         return sprintf(_("Edit metadata for %s"),'[pagename]');
31     }
32
33     // Arguments:
34     //
35     //  page - page whose metadata is editted
36
37
38     function getDefaultArguments() {
39         return array('page'       => '[pagename]'
40                     );
41     }
42
43
44     function run($dbi, $argstr, $request) {
45         $this->_args = $this->getArgs($argstr, $request);
46         extract($this->_args);
47         if (!$page)
48             return '';
49
50         $hidden_pagemeta = array ();
51         $readonly_pagemeta = array ('hits');
52         $dbi = $request->getDbh();
53         $p = $dbi->getPage($page);
54         $pagemeta = $p->getMetaData();
55
56         // Look at arguments to see if submit was entered.  If so,
57         // process this request before displaying.
58         // Fixme: The redirect will only work if the output is buffered.
59
60         if ($request->getArg('metaedit')) {
61
62             $metafield = trim($request->getArg('metafield'));
63             $metavalue = trim($request->getArg('metavalue'));
64
65             if (!in_array($metafield, $readonly_pagemeta)) {
66                 if (preg_match('/^(.*?)\[(.*?)\]$/',$metafield,$matches)) {
67                     list(,$array_field,$array_key) = $matches;
68                     $array_value = $pagemeta[$array_field];
69                     $array_value[$array_key] = $metavalue;
70                     $p->set($array_field, $array_value);
71                 } else {
72                     $p->set($metafield, $metavalue);
73                 }
74             }
75
76             $url = $request->getURLtoSelf('', array('metaedit', 'metafield', 'metavalue'));
77             $request->redirect($url);
78
79             // The rest of the output will not be seen due to
80             // the redirect.
81
82         }
83
84         // Now we show the meta data and provide entry box for new data.
85
86         $html = HTML();
87
88         $html->pushContent(fmt(_("Existing page-level metadata for %s:"), $page));
89         $dl = HTML::dl();
90
91         foreach ($pagemeta as $key => $val) {
92             if (is_string($val) and (substr($val,0,2) == 'a:')) {
93                 $dl->pushContent(HTML::dt("\n$key => $val\n", $dl1 = HTML::dl()));
94                 foreach (unserialize($val) as $akey => $aval) {
95                     $dl1->pushContent(HTML::dt(HTML::strong("$key" .'['.$akey."] => $aval\n")));
96                 }
97                 $dl->pushContent($dl1);
98             } elseif (is_array($val)) {
99                 $dl->pushContent(HTML::dt("\n$key:\n", $dl1 = HTML::dl()));
100                 foreach ($val as $akey => $aval) {
101                     $dl1->pushContent(HTML::dt(HTML::strong("$key" .'['.$akey."] => $aval\n")));
102                 }
103                 $dl->pushContent($dl1);
104             } elseif (in_array($key,$hidden_pagemeta)) {
105                 ;
106             } elseif (in_array($key,$readonly_pagemeta)) {
107                 $dl->pushContent(HTML::dt(array('style'=>'background: #dddddd'),"$key => $val\n"));
108             } else {
109                 $dl->pushContent(HTML::dt(HTML::strong("$key => $val\n")));
110             }
111         }
112         $html->pushContent($dl);
113
114         if ($request->_user->isAdmin()) {
115             $action = $request->getURLtoSelf();
116             $hiddenfield = HiddenInputs($request->getArgs());
117             $instructions = _("Add or change a page-level metadata 'key=>value' pair. Note that you can remove a key by leaving value-box empty.");
118             $keyfield = HTML::input(array('name' => 'metafield'), '');
119             $valfield = HTML::input(array('name' => 'metavalue'), '');
120             $button = Button('submit:metaedit', _("Submit"), false);
121             $form = HTML::form(array('action' => $action,
122                                      'method' => 'post'),
123                                $hiddenfield,
124                                $instructions, HTML::br(),
125                                $keyfield, ' => ', $valfield, HTML::nbsp(), $button
126                                );
127             
128             $html->pushContent(HTML::br(),$form);
129         } else {
130             $html->pushContent(HTML::em(_("Requires WikiAdmin privileges to edit.")));
131         }
132         return $html;
133     }
134 };
135
136 // For emacs users
137 // Local Variables:
138 // mode: php
139 // tab-width: 8
140 // c-basic-offset: 4
141 // c-hanging-comment-ender-p: nil
142 // indent-tabs-mode: nil
143 // End:
144
145 ?>