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
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 * Redirects 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
40 return _("ExternalSearch");
43 function getDescription () {
44 return _("Redirects to an external web site based on form input");
45 //fixme: better description
48 function getVersion() {
49 return preg_replace("/[Revision: $]/", '',
53 function _getInterWikiUrl(&$request) {
54 $intermap = getInterwikiMap();
55 $map = $intermap->_map;
57 if (in_array($this->_url, array_keys($map))) {
58 if (empty($this->_name))
59 $this->_name = $this->_url;
60 $this->_url = sprintf($map[$this->_url], '%s');
62 if (empty($this->_name))
63 $this->_name = $this->getName();
66 function getDefaultArguments() {
67 return array('s' => false,
75 'button_position' => EXTERNALSEARCH_DEFAULT_BUTTON_POSITION,
80 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);
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' => $GLOBALS['charset']),
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);
157 // $Log: not supported by cvs2svn $
158 // Revision 1.12 2004/11/28 20:42:33 rurban
159 // Optimize PearDB _extract_version_data and _extract_page_data.
161 // Revision 1.11 2004/09/17 14:25:45 rurban
164 // Revision 1.10 2004/05/17 13:36:49 rurban
165 // Apply RFE #952323 "ExternalSearchPlugin improvement", but
166 // with <button><img></button>
168 // Revision 1.9 2004/04/19 18:27:46 rurban
169 // Prevent from some PHP5 warnings (ref args, no :: object init)
170 // php5 runs now through, just one wrong XmlElement object init missing
171 // Removed unneccesary UpgradeUser lines
172 // Changed WikiLink to omit version if current (RecentChanges)
174 // Revision 1.8 2004/04/18 01:11:52 rurban
175 // more numeric pagename fixes.
176 // fixed action=upload with merge conflict warnings.
177 // charset changed from constant to global (dynamic utf-8 switching)
179 // Revision 1.7 2004/02/22 23:20:33 rurban
180 // fixed DumpHtmlToDir,
181 // enhanced sortby handling in PageList
182 // new button_heading th style (enabled),
183 // added sortby and limit support to the db backends and plugins
184 // for paging support (<<prev, next>> links on long lists)
186 // Revision 1.6 2004/02/19 22:06:53 rurban
187 // use new class, to be able to get rid of lib/interwiki.php
189 // Revision 1.5 2003/02/26 01:56:52 dairiki
190 // Tuning/fixing of POST action URLs and hidden inputs.
192 // Revision 1.4 2003/01/30 02:46:46 carstenklapp
193 // Bugfix: Plugin was redirecting to nonexistant local wiki page named
194 // "ExternalSearch" instead of the invoked url. Reported by Arthur Chereau.
196 // Revision 1.3 2003/01/18 21:41:01 carstenklapp
198 // Reformatting & tabs to spaces;
199 // Added copyleft, getVersion, getDescription, rcs_id.
206 // c-hanging-comment-ender-p: nil
207 // indent-tabs-mode: nil