]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/ExternalSearch.php
Optimize PearDB _extract_version_data and _extract_page_data.
[SourceForge/phpwiki.git] / lib / plugin / ExternalSearch.php
1 <?php // -*-php-*-
2 rcs_id('$Id: ExternalSearch.php,v 1.12 2004-11-28 20:42:33 rurban Exp $');
3 /**
4  Copyright 1999, 2000, 2001, 2002 $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  * Redirects to an external web site based on form input.
25  * See http://phpwiki.sourceforge.net/phpwiki/ExternalSearchPlugin
26  *
27  * useimage sample:
28    ExternalSearch
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"
32  */
33
34 class WikiPlugin_ExternalSearch
35 extends WikiPlugin
36 {
37     function getName () {
38         return _("ExternalSearch");
39     }
40
41     function getDescription () {
42         return _("Redirects to an external web site based on form input");
43         //fixme: better description
44     }
45
46     function getVersion() {
47         return preg_replace("/[Revision: $]/", '',
48                             "\$Revision: 1.12 $");
49     }
50
51     function _getInterWikiUrl(&$request) {
52         $intermap = getInterwikiMap();
53         $map = $intermap->_map;
54
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');
59         }
60         if (empty($this->_name))
61             $this->_name = $this->getName();
62     }
63
64     function getDefaultArguments() {
65         return array('s'        => false,
66                      'formsize' => 30,
67                      'url'      => false,
68                      'name'     => '',
69                      'useimage' => false,
70                      'width'    => false,
71                      'height'   => false,
72                      'debug'    => false
73                      );
74     }
75
76     function run($dbi, $argstr, &$request, $basepage) {
77         $args = $this->getArgs($argstr, $request);
78         if (empty($args['url']))
79             return '';
80
81         extract($args);
82
83         $posted = $GLOBALS['HTTP_POST_VARS'];
84         if (in_array('url', array_keys($posted))) {
85             $s = $posted['s'];
86             $this->_url = $posted['url'];
87             $this->_getInterWikiUrl($request);
88             if (strstr($this->_url, '%s')) {
89                 $this->_url = sprintf($this->_url, $s);
90             } else
91                 $this->_url .= $s;
92             if ($debug) {
93                 trigger_error("redirect url: " . $this->_url);
94             } else {
95                 $request->redirect($this->_url); //no return!
96             }
97         }
98         $this->_name = $name;
99         $this->_s = $s;
100         if ($formsize < 1)
101             $formsize = 30;
102         $this->_url = $url;
103         $this->_getInterWikiUrl($request);
104         $form = HTML::form(array('action' => $request->getPostURL(),
105                                  'method' => 'post',
106                                  //'class'  => 'class', //fixme
107                                  'accept-charset' => $GLOBALS['charset']),
108                            HiddenInputs(array('pagename' => $basepage)));
109
110         $form->pushContent(HTML::input(array('type' => 'hidden',
111                                              'name'  => 'url',
112                                              'value' => $this->_url)));
113         if (!empty($args["useimage"])) {
114             //FIXME: This does not work with Gecko
115             $button = HTML::img(array('src' => $useimage, 'alt' => 'imagebutton'));
116             if (!empty($width))
117                 $button->setAttr('width',$width);
118             if (!empty($height))
119                 $button->setAttr('height',$height);
120             $form->pushContent(HTML::button(array('type' => 'button',
121                                                   'class' => 'button',
122                                                   'value' => $this->_name,
123                                                   ),
124                                             $button));
125         } else {
126             $form->pushContent(HTML::input(array('type' => 'submit',
127                                                  'class' => 'button',
128                                                  'value' => $this->_name)));
129             $form->pushContent(HTML::input(array('type' => 'text',
130                                                  'value' => $this->_s,
131                                                  'name'  => 's',
132                                                  'size'  => $formsize)));
133         }
134         return $form;
135     }
136 };
137
138 // $Log: not supported by cvs2svn $
139 // Revision 1.11  2004/09/17 14:25:45  rurban
140 // update comments
141 //
142 // Revision 1.10  2004/05/17 13:36:49  rurban
143 // Apply RFE #952323 "ExternalSearchPlugin improvement", but
144 //   with <button><img></button>
145 //
146 // Revision 1.9  2004/04/19 18:27:46  rurban
147 // Prevent from some PHP5 warnings (ref args, no :: object init)
148 //   php5 runs now through, just one wrong XmlElement object init missing
149 // Removed unneccesary UpgradeUser lines
150 // Changed WikiLink to omit version if current (RecentChanges)
151 //
152 // Revision 1.8  2004/04/18 01:11:52  rurban
153 // more numeric pagename fixes.
154 // fixed action=upload with merge conflict warnings.
155 // charset changed from constant to global (dynamic utf-8 switching)
156 //
157 // Revision 1.7  2004/02/22 23:20:33  rurban
158 // fixed DumpHtmlToDir,
159 // enhanced sortby handling in PageList
160 //   new button_heading th style (enabled),
161 // added sortby and limit support to the db backends and plugins
162 //   for paging support (<<prev, next>> links on long lists)
163 //
164 // Revision 1.6  2004/02/19 22:06:53  rurban
165 // use new class, to be able to get rid of lib/interwiki.php
166 //
167 // Revision 1.5  2003/02/26 01:56:52  dairiki
168 // Tuning/fixing of POST action URLs and hidden inputs.
169 //
170 // Revision 1.4  2003/01/30 02:46:46  carstenklapp
171 // Bugfix: Plugin was redirecting to nonexistant local wiki page named
172 // "ExternalSearch" instead of the invoked url. Reported by Arthur Chereau.
173 //
174 // Revision 1.3  2003/01/18 21:41:01  carstenklapp
175 // Code cleanup:
176 // Reformatting & tabs to spaces;
177 // Added copyleft, getVersion, getDescription, rcs_id.
178 //
179
180 // Local Variables:
181 // mode: php
182 // tab-width: 8
183 // c-basic-offset: 4
184 // c-hanging-comment-ender-p: nil
185 // indent-tabs-mode: nil
186 // End:
187 ?>