]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/MostPopular.php
Jeff's hacks II, continued:
[SourceForge/phpwiki.git] / lib / plugin / MostPopular.php
1 <?php // -*-php-*-
2 rcs_id('$Id: MostPopular.php,v 1.1 2001-09-18 19:19:05 dairiki Exp $');
3 /**
4  */
5 class WikiPlugin_MostPopular
6 extends WikiPlugin
7 {
8     var $name = 'MostPopular';
9     
10     function getDefaultArguments() {
11         // FIXME: how to exclude multiple pages?
12         return array('limit'            => 20,
13                      'noheader'         => 0);
14     }
15
16     function run($dbi, $argstr, $request) {
17         extract($this->getArgs($argstr, $request));
18         
19         $pages = $dbi->mostPopular($limit);
20
21         $lines[] = $this->_tr(QElement('u', gettext("Hits")),
22                               QElement('u', gettext("Page Name")));
23         
24         while ($page = $pages->next()) {
25             $hits = $page->get('hits');
26             if ($hits == 0)
27                 break;
28             $lines[] = $this->_tr($hits,
29                                   LinkWikiWord($page->getName()));
30         }
31         $pages->free();
32
33         $html = '';
34         if (!$noheader) {
35             $html .= QElement('p',
36                              sprintf("The %s most popular pages of this wiki:",
37                                      $limit ? $limit : ''));
38         }
39         
40
41         $html .= Element('blockquote',
42                          Element('table', array('cellpadding' => 0,
43                                                 'cellspacing' => 1,
44                                                 'border' => 0),
45                                  join("\n", $lines)));
46         return $html;
47     }
48
49     function _tr ($col1, $col2) {
50         return "<tr><td align='right'>$col1&nbsp;&nbsp;</td>"
51             . "<td>&nbsp;&nbsp;$col2</td></tr>\n";
52     }
53 };
54         
55 // Local Variables:
56 // mode: php
57 // tab-width: 8
58 // c-basic-offset: 4
59 // c-hanging-comment-ender-p: nil
60 // indent-tabs-mode: nil
61 // End:   
62 ?>