]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/ExternalSearch.php
New plugin.
[SourceForge/phpwiki.git] / lib / plugin / ExternalSearch.php
1 <?php // -*-php-*-
2 rcs_id('$Id: ExternalSearch.php,v 1.1 2002-02-28 00:11:17 carstenklapp Exp $');
3
4 require_once("lib/interwiki.php");
5
6 /**
7  */
8 class WikiPlugin_ExternalSearch
9 extends WikiPlugin
10 {
11     function getName () {
12         return _("ExternalSearch");
13     }
14
15     function getDescription () {
16         return _("Redirects to an external web site based on form input"); //fixme: better description
17     }
18
19     function _getInterWikiUrl(&$request) {
20         $intermap = InterWikiMap::GetMap($request);
21         $map = $intermap->_map;
22
23         if (in_array($this->_url, array_keys($map))) {
24             if (empty($this->_name))
25                 $this->_name = $this->_url;
26             $this->_url = sprintf($map[$this->_url],'%s');
27         }
28         if (empty($this->_name))
29             $this->_name = $this->getName();
30     }
31
32     function getDefaultArguments() {
33         return array('s'        => false,
34                      'size'     => false,
35                      'url'      => false,
36                      'name'     => '',
37                      'debug'    => false
38                      );
39     }
40
41     function run($dbi, $argstr, $request) {
42         $args = $this->getArgs($argstr, $request);
43         if (empty($args['url']))
44             return '';
45
46         extract($args);
47
48         $posted = $GLOBALS['HTTP_POST_VARS'];
49         if (in_array('url', array_keys($posted))) {
50             $s = $posted['s'];
51             $this->_url = $posted['url'];
52             $this->_getInterWikiUrl($request);
53             if (strstr($this->_url, '%s')) {
54                 $this->_url = sprintf($this->_url, $s);
55             } else
56                 $this->_url .= $s;
57
58             if ($debug) {
59                 trigger_error("redirect url: ".$this->_url);
60             } else
61                 $request->redirect($this->_url); //no return!
62         }
63
64         $this->_name = $name;
65
66         $this->_s = $s;
67         if ($size < 1)
68             $size = 30;
69         $this->_url = $url;
70
71         $this->_getInterWikiUrl($request);
72
73         $form = HTML::form(array('action' => $this->getname(),
74                                 'method' => 'POST',
75                                 //'class'  => 'class', //fixme
76                                 'accept-charset' => CHARSET));
77
78         $form->pushContent(HTML::input(array('type' => 'text',
79                                             'value' => $this->_s,
80                                             'name'  => 's',
81                                             'size'  => $size)));
82
83         $form->pushContent(HTML::input(array('type' => 'hidden',
84                                             'name'  => 'url',
85                                             'value' => $this->_url)));
86
87         $form->pushContent(HTML::input(array('type' => 'submit',
88                                             'class' => 'button',
89                                             'value' => $this->_name)));
90         return $form;
91     }
92 };
93
94 // Local Variables:
95 // mode: php
96 // tab-width: 8
97 // c-basic-offset: 4
98 // c-hanging-comment-ender-p: nil
99 // indent-tabs-mode: nil
100 // End:
101 ?>