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