]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/InterWikiSearch.php
Reformat code
[SourceForge/phpwiki.git] / lib / plugin / InterWikiSearch.php
1 <?php
2
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 along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 /**
23  * @description
24  */
25 require_once 'lib/PageType.php';
26
27 class WikiPlugin_InterWikiSearch
28     extends WikiPlugin
29 {
30     function getName()
31     {
32         return _("InterWikiSearch");
33     }
34
35     function getDescription()
36     {
37         return _("Perform searches on InterWiki sites listed in InterWikiMap.");
38     }
39
40     function getDefaultArguments()
41     {
42         return array('s' => '',
43             'formsize' => 30,
44         );
45     }
46
47     function run($dbi, $argstr, &$request, $basepage)
48     {
49         $args = $this->getArgs($argstr, $request);
50         extract($args);
51
52         if (defined('DEBUG') && !DEBUG)
53             return $this->disabled("Sorry, this plugin is currently out of order.");
54
55         $page = $dbi->getPage($request->getArg('pagename'));
56         return new TransformedText($page, _('InterWikiMap'), array('markup' => 2),
57             'searchableInterWikiMap');
58         /*
59         return new PageType($pagerevisionhandle,
60                             $pagename = _('InterWikiMap'),
61                             $markup = 2,
62                             $overridePageType = 'PageType_searchableInterWikiMap');
63         */
64     }
65 }
66
67 ;
68
69 /**
70  * @desc
71  */
72 if (defined('DEBUG') && DEBUG) {
73     class PageFormatter_searchableInterWikiMap
74         extends PageFormatter_interwikimap
75     {
76     }
77
78     class PageType_searchableInterWikiMap
79         extends PageType_interwikimap
80     {
81         function format($text)
82         {
83             return HTML::div(array('class' => 'wikitext'),
84                 $this->_transform($this->_getHeader($text)),
85                 $this->_formatMap(),
86                 $this->_transform($this->_getFooter($text)));
87         }
88
89         function _formatMap()
90         {
91             return $this->_arrayToTable($this->_getMap(), $GLOBALS['request']);
92         }
93
94         function _arrayToTable($array, &$request)
95         {
96             $thead = HTML::thead();
97             $label[0] = _("Wiki Name");
98             $label[1] = _("Search");
99             $thead->pushContent(HTML::tr(HTML::th($label[0]),
100                 HTML::th($label[1])));
101
102             $tbody = HTML::tbody();
103             $dbi = $request->getDbh();
104             if ($array) {
105                 foreach ($array as $moniker => $interurl) {
106                     $monikertd = HTML::td(array('class' => 'interwiki-moniker'),
107                         $dbi->isWikiPage($moniker)
108                             ? WikiLink($moniker)
109                             : $moniker);
110
111                     $w = new WikiPluginLoader;
112                     $p = $w->getPlugin('ExternalSearch');
113                     $argstr = sprintf('url="%s"', addslashes($interurl));
114                     $searchtd = HTML::td($p->run($dbi, $argstr, $request, $basepage));
115
116                     $tbody->pushContent(HTML::tr($monikertd, $searchtd));
117                 }
118             }
119             $table = HTML::table();
120             $table->setAttr('class', 'interwiki-map');
121             $table->pushContent($thead);
122             $table->pushContent($tbody);
123
124             return $table;
125         }
126     }
127
128     ;
129 }
130
131 // Local Variables:
132 // mode: php
133 // tab-width: 8
134 // c-basic-offset: 4
135 // c-hanging-comment-ender-p: nil
136 // indent-tabs-mode: nil
137 // End: