]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PopularTags.php
Remove unused function _showvalue
[SourceForge/phpwiki.git] / lib / plugin / PopularTags.php
1 <?php
2
3 /*
4  * Copyright 2007 Reini Urban
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 /* Usage:
24  *   <<PopularTags>>
25  */
26
27 require_once 'lib/PageList.php';
28
29 class WikiPlugin_PopularTags
30     extends WikiPlugin
31 {
32     // get list of categories sorted by number of backlinks
33     private function cmp_by_count($a, $b)
34     {
35         if ($a['count'] == $b['count']) return 0;
36         return $a['count'] < $b['count'] ? 1 : -1;
37     }
38
39     function getDescription()
40     {
41         return _("List the most popular tags.");
42     }
43
44     function getDefaultArguments()
45     {
46         return array('pagename' => '[pagename]',
47             'limit' => 10,
48             'mincount' => 5,
49             'noheader' => 0,
50         );
51     }
52
53     /**
54      * @param WikiDB $dbi
55      * @param string $argstr
56      * @param WikiRequest $request
57      * @param string $basepage
58      * @return mixed
59      */
60     function run($dbi, $argstr, &$request, $basepage)
61     {
62         $args = $this->getArgs($argstr, $request);
63         extract($args);
64
65         $maincat = $dbi->getPage(_("CategoryCategory"));
66         $bi = $maincat->getBackLinks();
67         $bl = array();
68         while ($b = $bi->next()) {
69             $name = $b->getName();
70             if (preg_match("/^" . _("Template") . "/", $name)) continue;
71             $pages = $b->getBackLinks();
72             $bl[] = array('name' => $name,
73                 'count' => $pages->count());
74         }
75
76         usort($bl, array($this, 'cmp_by_count'));
77         $html = HTML::ul();
78         $i = 0;
79         foreach ($bl as $b) {
80             $i++;
81             $name = $b['name'];
82             $count = $b['count'];
83             if ($count < $mincount) break;
84             if ($i > $limit) break;
85             $wo = preg_replace("/^(" . _("Category") . "|"
86                 . _("Topic") . ")/", "", $name);
87             $wo = HTML(HTML::span($wo), HTML::raw("&nbsp;"), HTML::small("(" . $count . ")"));
88             $link = WikiLink($name, 'auto', $wo);
89             $html->pushContent(HTML::li($link));
90         }
91         return $html;
92     }
93 }
94
95 // Local Variables:
96 // mode: php
97 // tab-width: 8
98 // c-basic-offset: 4
99 // c-hanging-comment-ender-p: nil
100 // indent-tabs-mode: nil
101 // End: