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