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