4 * Copyright 1999,2000,2001,2002,2006 $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 along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * Redirect to an external web site based on form input.
25 * See http://phpwiki.sourceforge.net/phpwiki/ExternalSearchPlugin
29 url="http://www.geourl.org/near/?xsize=2048&ysize=1024&xoffset=1650&yoffset=550"
30 useimage="http://www.geourl.org/maps/au.png"
31 name="Go Godzilla All Over It"
33 if (!defined("EXTERNALSEARCH_DEFAULT_BUTTON_POSITION"))
34 define("EXTERNALSEARCH_DEFAULT_BUTTON_POSITION", "right");
36 class WikiPlugin_ExternalSearch
41 return _("ExternalSearch");
44 function getDescription()
46 return _("Redirect to an external web site based on form input.");
47 //fixme: better description
50 private function getInterWikiUrl(&$request)
52 $intermap = getInterwikiMap();
53 $map = $intermap->_map;
55 if (in_array($this->_url, array_keys($map))) {
56 if (empty($this->_name))
57 $this->_name = $this->_url;
58 $this->_url = sprintf($map[$this->_url], '%s');
60 if (empty($this->_name))
61 $this->_name = $this->getName();
64 function getDefaultArguments()
66 return array('s' => false,
74 'button_position' => EXTERNALSEARCH_DEFAULT_BUTTON_POSITION,
79 function run($dbi, $argstr, &$request, $basepage)
81 $args = $this->getArgs($argstr, $request);
82 if (empty($args['url']))
87 $posted = $GLOBALS['HTTP_POST_VARS'];
88 if (in_array('url', array_keys($posted))) {
90 $this->_url = $posted['url'];
91 $this->getInterWikiUrl($request);
92 if (strstr($this->_url, '%s')) {
93 $this->_url = sprintf($this->_url, $s);
96 if (defined('DEBUG') && DEBUG && $debug) {
97 trigger_error("redirect url: " . $this->_url);
99 $request->redirect($this->_url); //no return!
102 $this->_name = $name;
107 $this->getInterWikiUrl($request);
108 $form = HTML::form(array('action' => $request->getPostURL(),
110 //'class' => 'class', //fixme
111 'accept-charset' => 'UTF-8'),
112 HiddenInputs(array('pagename' => $basepage)));
114 $form->pushContent(HTML::input(array('type' => 'hidden',
116 'value' => $this->_url)));
117 $s = HTML::input(array('type' => 'text',
118 'value' => $this->_s,
120 'size' => $formsize));
121 if (!empty($args["useimage"])) {
122 //FIXME: This does not work with Gecko
123 $button = HTML::img(array('src' => $useimage, 'alt' => 'imagebutton'));
125 $button->setAttr('width', $width);
127 $button->setAttr('height', $height);
128 // on button_position => none display no input form
129 if ($button_position == 'right')
130 $form->pushContent($s);
131 $form->pushContent(HTML::button(array('type' => 'button',
133 'value' => $this->_name,
136 if ($button_position == 'left')
137 $form->pushContent($s);
139 if ($button_position != 'left' and $button_position != 'right')
140 return $this->error(fmt("Invalid argument: %s=%s",
141 'button_position', $button_position));
142 $button = HTML::input(array('type' => 'submit',
144 'value' => $this->_name));
145 if ($button_position == 'left') {
146 $form->pushContent($button);
147 $form->pushContent($s);
148 } elseif ($button_position == 'right') {
149 $form->pushContent($s);
150 $form->pushContent($button);
161 // c-hanging-comment-ender-p: nil
162 // indent-tabs-mode: nil