]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PopularTags.php
Remove unused
[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 getName()
40     {
41         return _("PopularTags");
42     }
43
44     function getDescription()
45     {
46         return _("List the most popular tags.");
47     }
48
49     function getDefaultArguments()
50     {
51         return array('pagename' => '[pagename]',
52             'limit' => 10,
53             'mincount' => 5,
54             'noheader' => 0,
55         );
56     }
57
58     function run($dbi, $argstr, &$request, $basepage)
59     {
60         $args = $this->getArgs($argstr, $request);
61         extract($args);
62
63         $maincat = $dbi->getPage(_("CategoryCategory"));
64         $bi = $maincat->getBackLinks(false);
65         $bl = array();
66         while ($b = $bi->next()) {
67             $name = $b->getName();
68             if (preg_match("/^" . _("Template") . "/", $name)) continue;
69             $pages = $b->getBackLinks(false);
70             $bl[] = array('name' => $name,
71                 'count' => $pages->count());
72         }
73
74         usort($bl, array($this, 'cmp_by_count'));
75         $html = HTML::ul();
76         $i = 0;
77         foreach ($bl as $b) {
78             $i++;
79             $name = $b['name'];
80             $count = $b['count'];
81             if ($count < $mincount) break;
82             if ($i > $limit) break;
83             $wo = preg_replace("/^(" . _("Category") . "|"
84                 . _("Topic") . ")/", "", $name);
85             $wo = HTML(HTML::span($wo), HTML::raw("&nbsp;"), HTML::small("(" . $count . ")"));
86             $link = WikiLink($name, 'auto', $wo);
87             $html->pushContent(HTML::li($link));
88         }
89         return $html;
90     }
91 }
92
93 // Local Variables:
94 // mode: php
95 // tab-width: 8
96 // c-basic-offset: 4
97 // c-hanging-comment-ender-p: nil
98 // indent-tabs-mode: nil
99 // End: