]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/ExternalSearch.php
more numeric pagename fixes.
[SourceForge/phpwiki.git] / lib / plugin / ExternalSearch.php
1 <?php // -*-php-*-
2 rcs_id('$Id: ExternalSearch.php,v 1.8 2004-04-18 01:11:52 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 //require_once("lib/interwiki.php");
24
25 /**
26  */
27 class WikiPlugin_ExternalSearch
28 extends WikiPlugin
29 {
30     function getName () {
31         return _("ExternalSearch");
32     }
33
34     function getDescription () {
35         return _("Redirects to an external web site based on form input");
36         //fixme: better description
37     }
38
39     function getVersion() {
40         return preg_replace("/[Revision: $]/", '',
41                             "\$Revision: 1.8 $");
42     }
43
44     function _getInterWikiUrl(&$request) {
45         $intermap = PageType_interwikimap::GetMap($request);
46         $map = $intermap->_map;
47
48         if (in_array($this->_url, array_keys($map))) {
49             if (empty($this->_name))
50                 $this->_name = $this->_url;
51             $this->_url = sprintf($map[$this->_url],'%s');
52         }
53         if (empty($this->_name))
54             $this->_name = $this->getName();
55     }
56
57     function getDefaultArguments() {
58         return array('s'        => false,
59                      'formsize' => 30,
60                      'url'      => false,
61                      'name'     => '',
62                      'debug'    => false
63                      );
64     }
65
66     function run($dbi, $argstr, &$request, $basepage) {
67         $args = $this->getArgs($argstr, $request);
68         if (empty($args['url']))
69             return '';
70
71         extract($args);
72
73         $posted = $GLOBALS['HTTP_POST_VARS'];
74         if (in_array('url', array_keys($posted))) {
75             $s = $posted['s'];
76             $this->_url = $posted['url'];
77             $this->_getInterWikiUrl($request);
78             if (strstr($this->_url, '%s')) {
79                 $this->_url = sprintf($this->_url, $s);
80             } else
81                 $this->_url .= $s;
82
83             if ($debug) {
84                 trigger_error("redirect url: " . $this->_url);
85             } else
86                 $request->redirect($this->_url); //no return!
87         }
88
89         $this->_name = $name;
90
91         $this->_s = $s;
92         if ($formsize < 1)
93             $formsize = 30;
94         $this->_url = $url;
95
96         $this->_getInterWikiUrl($request);
97
98         $form = HTML::form(array('action' => $request->getPostURL(),
99                                  'method' => 'post',
100                                  //'class'  => 'class', //fixme
101                                  'accept-charset' => $GLOBALS['charset']),
102                            HiddenInputs(array('pagename' => $basepage)));
103
104         $form->pushContent(HTML::input(array('type' => 'text',
105                                              'value' => $this->_s,
106                                              'name'  => 's',
107                                              'size'  => $formsize)));
108
109         $form->pushContent(HTML::input(array('type' => 'hidden',
110                                              'name'  => 'url',
111                                              'value' => $this->_url)));
112
113         $form->pushContent(HTML::input(array('type' => 'submit',
114                                              'class' => 'button',
115                                              'value' => $this->_name)));
116         return $form;
117     }
118 };
119
120 // $Log: not supported by cvs2svn $
121 // Revision 1.7  2004/02/22 23:20:33  rurban
122 // fixed DumpHtmlToDir,
123 // enhanced sortby handling in PageList
124 //   new button_heading th style (enabled),
125 // added sortby and limit support to the db backends and plugins
126 //   for paging support (<<prev, next>> links on long lists)
127 //
128 // Revision 1.6  2004/02/19 22:06:53  rurban
129 // use new class, to be able to get rid of lib/interwiki.php
130 //
131 // Revision 1.5  2003/02/26 01:56:52  dairiki
132 // Tuning/fixing of POST action URLs and hidden inputs.
133 //
134 // Revision 1.4  2003/01/30 02:46:46  carstenklapp
135 // Bugfix: Plugin was redirecting to nonexistant local wiki page named
136 // "ExternalSearch" instead of the invoked url. Reported by Arthur Chereau.
137 //
138 // Revision 1.3  2003/01/18 21:41:01  carstenklapp
139 // Code cleanup:
140 // Reformatting & tabs to spaces;
141 // Added copyleft, getVersion, getDescription, rcs_id.
142 //
143
144 // Local Variables:
145 // mode: php
146 // tab-width: 8
147 // c-basic-offset: 4
148 // c-hanging-comment-ender-p: nil
149 // indent-tabs-mode: nil
150 // End:
151 ?>