]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/backend/dumb/MostPopularIter.php
Jeff's hacks II.
[SourceForge/phpwiki.git] / lib / WikiDB / backend / dumb / MostPopularIter.php
1 <?php // -*-php-*-
2 rcs_id('$Id: MostPopularIter.php,v 1.1 2001-09-18 19:16:23 dairiki Exp $');
3
4 require_once('lib/WikiDB/backend.php');
5
6
7 /**
8  * An inefficient but general most_popular iterator. 
9  *
10  * This iterator will work with any backend which implements the
11  * backend::get_all_pages() and backend::get_pagedata()
12  * methods.
13  */
14 class WikiDB_backend_dumb_MostPopularIter
15 extends WikiDB_backend_iterator
16 {
17     function WikiDB_backend_dumb_MostPopularIter($backend, &$all_pages, $limit) {
18         $this->_pages = array();
19         $pages = &$this->_pages;
20
21         while ($page = & $all_pages->next()) {
22             if (!isset($page['pagedata']))
23                 $page['pagedata'] = $backend->get_pagedata($page['pagename']);
24             $pages[] = $page;
25         }
26
27         usort($pages, 'WikiDB_backend_dumb_MostPopularIter_sortf');
28
29         if ($limit && $limit < count($pages))
30             array_splice($pages, $limit);
31     }
32
33     function next() {
34         return array_shift($this->_pages);
35     }
36     
37     function free() {
38         unset($this->_pages);
39     }
40 }
41
42 function WikiDB_backend_dumb_MostPopularIter_sortf($a,$b) {
43     @$ahits = (int)$a['pagedata']['hits'];
44     @$bhits = (int)$b['pagedata']['hits'];
45     return $bhits - $ahits;
46 }
47
48 ?>