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