From 3398c99de65afdc25c6f19db211a042bb6baf3e1 Mon Sep 17 00:00:00 2001 From: rurban Date: Fri, 27 Sep 2002 10:55:45 +0000 Subject: [PATCH] MichaelVanDam's new experimental EditMetaData plugin, plus array support and restricted to WikiAdmin. git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@2383 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/plugin/EditMetaData.php | 145 ++++++++++++++++++++++++++++++++++++ lib/plugin/RedirectTo.php | 28 +++---- 2 files changed, 156 insertions(+), 17 deletions(-) create mode 100644 lib/plugin/EditMetaData.php diff --git a/lib/plugin/EditMetaData.php b/lib/plugin/EditMetaData.php new file mode 100644 index 000000000..7ba1798c9 --- /dev/null +++ b/lib/plugin/EditMetaData.php @@ -0,0 +1,145 @@ + '[pagename]' + ); + } + + + function run($dbi, $argstr, $request) { + $this->_args = $this->getArgs($argstr, $request); + extract($this->_args); + if (!$page) + return ''; + + $hidden_pagemeta = array (); + $readonly_pagemeta = array ('hits'); + $dbi = $request->getDbh(); + $p = $dbi->getPage($page); + $pagemeta = $p->getMetaData(); + + // Look at arguments to see if submit was entered. If so, + // process this request before displaying. + // Fixme: The redirect will only work if the output is buffered. + + if ($request->getArg('metaedit')) { + + $metafield = trim($request->getArg('metafield')); + $metavalue = trim($request->getArg('metavalue')); + + if (!in_array($metafield, $readonly_pagemeta)) { + if (preg_match('/^(.*?)\[(.*?)\]$/',$metafield,$matches)) { + list(,$array_field,$array_key) = $matches; + $array_value = $pagemeta[$array_field]; + $array_value[$array_key] = $metavalue; + $p->set($array_field, $array_value); + } else { + $p->set($metafield, $metavalue); + } + } + + $url = $request->getURLtoSelf('', array('metaedit', 'metafield', 'metavalue')); + $request->redirect($url); + + // The rest of the output will not be seen due to + // the redirect. + + } + + // Now we show the meta data and provide entry box for new data. + + $html = HTML(); + + $html->pushContent(fmt(_("Existing page-level metadata for %s:"), $page)); + $dl = HTML::dl(); + + foreach ($pagemeta as $key => $val) { + if (is_string($val) and (substr($val,0,2) == 'a:')) { + $dl->pushContent(HTML::dt("\n$key => $val\n", $dl1 = HTML::dl())); + foreach (unserialize($val) as $akey => $aval) { + $dl1->pushContent(HTML::dt(HTML::strong("$key" .'['.$akey."] => $aval\n"))); + } + $dl->pushContent($dl1); + } elseif (is_array($val)) { + $dl->pushContent(HTML::dt("\n$key:\n", $dl1 = HTML::dl())); + foreach ($val as $akey => $aval) { + $dl1->pushContent(HTML::dt(HTML::strong("$key" .'['.$akey."] => $aval\n"))); + } + $dl->pushContent($dl1); + } elseif (in_array($key,$hidden_pagemeta)) { + ; + } elseif (in_array($key,$readonly_pagemeta)) { + $dl->pushContent(HTML::dt(array('style'=>'background: #dddddd'),"$key => $val\n")); + } else { + $dl->pushContent(HTML::dt(HTML::strong("$key => $val\n"))); + } + } + $html->pushContent($dl); + + if ($request->_user->isAdmin()) { + $action = $request->getURLtoSelf(); + $hiddenfield = HiddenInputs($request->getArgs()); + $instructions = _("Add or change a page-level metadata 'key=>value' pair. Note that you can remove a key by leaving value-box empty."); + $keyfield = HTML::input(array('name' => 'metafield'), ''); + $valfield = HTML::input(array('name' => 'metavalue'), ''); + $button = Button('submit:metaedit', _("Submit"), false); + $form = HTML::form(array('action' => $action, + 'method' => 'post'), + $hiddenfield, + $instructions, HTML::br(), + $keyfield, ' => ', $valfield, NBSP, $button + ); + + $html->pushContent(HTML::br(),$form); + } else { + $html->pushContent(HTML::em(_("Requires WikiAdmin privileges to edit."))); + } + return $html; + } +}; + +// For emacs users +// Local Variables: +// mode: php +// tab-width: 8 +// c-basic-offset: 4 +// c-hanging-comment-ender-p: nil +// indent-tabs-mode: nil +// End: + +?> diff --git a/lib/plugin/RedirectTo.php b/lib/plugin/RedirectTo.php index 6afc083d2..90c42b5df 100644 --- a/lib/plugin/RedirectTo.php +++ b/lib/plugin/RedirectTo.php @@ -1,5 +1,5 @@ + * Redirect to another page or external uri. Kind of PageAlias. + * Usage: * or * at the VERY FIRST LINE in the content! Otherwise it will be ignored. * Author: Reini Urban * * BUGS/COMMENTS: * - * Actually, it seems that this plugin can be invoked from anywhere on a page. - * (Not just the first line.) - * * This plugin could probably result in a lot of confusion, especially when * redirecting to external sites. (Perhaps it can even be used for dastardly * purposes?) Maybe it should be disabled by default. @@ -53,7 +50,7 @@ extends WikiPlugin function getDefaultArguments() { return array( 'href' => '', - // 'type' => 'Temp' // or 'Permanent' // s far ignored + // 'type' => 'Temp' // or 'Permanent' // so far ignored 'page' => false, 'args' => false, // pass more args to the page. TestMe! ); @@ -67,20 +64,17 @@ extends WikiPlugin return $this->error(sprintf(_("%s or %s parameter missing"), 'href', 'page')); if ($href) { /* - * I don't think this hack is needed. - * Just use quotes on the href argument value, like: - * + * Use quotes on the href argument value, like: * + * + * Do we want some checking on href to avoid malicious + * uses of the plugin? Like stripping tags or hexcode. */ - // // FIXME: unmunged url hack - // $url = preg_replace('/href=(.*)\Z/','$1',$argstr); - $url = $href; - // - // FIXME: may want some checking on href to avoid malicious - // uses of the plugin? + $url = preg_replace('/%\d\d/','',strip_tags($href)); } else { - $url = $request->getURLtoSelf(array_merge(array('pagename' => $page), + $url = $request->getURLtoSelf(array_merge(array('pagename' => $page, + 'redirectfrom' => $request->getArg('pagename')), SplitQueryArgs($args['args']))); } if ($page == $request->getArg('pagename')) { -- 2.45.0