]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/ExternalSearch.php
Remove history
[SourceForge/phpwiki.git] / lib / plugin / ExternalSearch.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /**
4  Copyright 1999,2000,2001,2002,2006 $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 if (!defined("EXTERNALSEARCH_DEFAULT_BUTTON_POSITION"))
34     define("EXTERNALSEARCH_DEFAULT_BUTTON_POSITION", "right");
35
36 class WikiPlugin_ExternalSearch
37 extends WikiPlugin
38 {
39     function getName () {
40         return _("ExternalSearch");
41     }
42
43     function getDescription () {
44         return _("Redirects to an external web site based on form input");
45         //fixme: better description
46     }
47
48     function getVersion() {
49         return preg_replace("/[Revision: $]/", '',
50                             "\$Revision$");
51     }
52
53     function _getInterWikiUrl(&$request) {
54         $intermap = getInterwikiMap();
55         $map = $intermap->_map;
56
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');
61         }
62         if (empty($this->_name))
63             $this->_name = $this->getName();
64     }
65
66     function getDefaultArguments() {
67         return array('s'        => false,
68                      'formsize' => 30,
69                      'url'      => false,
70                      'name'     => '',
71                      'useimage' => false,
72                      'width'    => false,
73                      'height'   => false,
74                      'debug'    => false,
75                      'button_position' => EXTERNALSEARCH_DEFAULT_BUTTON_POSITION,
76                      // 'left' or 'right'
77                      );
78     }
79
80     function run($dbi, $argstr, &$request, $basepage) {
81         $args = $this->getArgs($argstr, $request);
82         if (empty($args['url']))
83             return '';
84
85         extract($args);
86
87         $posted = $GLOBALS['HTTP_POST_VARS'];
88         if (in_array('url', array_keys($posted))) {
89             $s = $posted['s'];
90             $this->_url = $posted['url'];
91             $this->_getInterWikiUrl($request);
92             if (strstr($this->_url, '%s')) {
93                 $this->_url = sprintf($this->_url, $s);
94             } else
95                 $this->_url .= $s;
96             if ($debug) {
97                 trigger_error("redirect url: " . $this->_url);
98             } else {
99                 $request->redirect($this->_url); //no return!
100             }
101         }
102         $this->_name = $name;
103         $this->_s = $s;
104         if ($formsize < 1)
105             $formsize = 30;
106         $this->_url = $url;
107         $this->_getInterWikiUrl($request);
108         $form = HTML::form(array('action' => $request->getPostURL(),
109                                  'method' => 'post',
110                                  //'class'  => 'class', //fixme
111                                  'accept-charset' => $GLOBALS['charset']),
112                            HiddenInputs(array('pagename' => $basepage)));
113
114         $form->pushContent(HTML::input(array('type' => 'hidden',
115                                              'name'  => 'url',
116                                              'value' => $this->_url)));
117         $s = HTML::input(array('type' => 'text',
118                                'value' => $this->_s,
119                                'name'  => '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'));
124             if (!empty($width))
125                 $button->setAttr('width',$width);
126             if (!empty($height))
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',
132                                                   'class' => 'button',
133                                                   'value' => $this->_name,
134                                                   ),
135                                             $button));
136             if ($button_position == 'left')
137                 $form->pushContent($s);
138         } else {
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',
143                                         'class' => 'button',
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);
151             }
152         }
153         return $form;
154     }
155 };
156
157 // Local Variables:
158 // mode: php
159 // tab-width: 8
160 // c-basic-offset: 4
161 // c-hanging-comment-ender-p: nil
162 // indent-tabs-mode: nil
163 // End:
164 ?>