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