]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/ListPages.php
include [all] Include and file path should be devided with single space. File path...
[SourceForge/phpwiki.git] / lib / plugin / ListPages.php
1 <?php // -*-php-*-
2
3 /*
4  * Copyright 2004 $ThePhpWikiProgrammingTeam
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 require_once 'lib/PageList.php';
24
25 /**
26  * ListPages - List pages that are explicitly given as the pages argument.
27  *
28  * Mainly used to see some ratings and recommendations.
29  * But also possible to list some Categories or Users, or as generic
30  * frontend for plugin-list page lists.
31  *
32  * @author: Dan Frankowski
33  */
34 class WikiPlugin_ListPages
35 extends WikiPlugin
36 {
37     function getName() {
38         return _("ListPages");
39     }
40
41     function getDescription() {
42         return _("List pages that are explicitly given as the pages argument.");
43     }
44
45     function getDefaultArguments() {
46         return array_merge
47             (
48              PageList::supportedArgs(),
49              array('pages'    => false,
50                    //'exclude'  => false,
51                    'info'     => 'pagename',
52                    'dimension' => 0,
53                    ));
54     }
55
56     // info arg allows multiple columns
57     // info=mtime,hits,summary,version,author,locked,minor
58     // additional info args:
59     //   top3recs      : recommendations
60     //   numbacklinks  : number of backlinks (links to the given page)
61     //   numpagelinks  : number of forward links (links at the given page)
62
63     function run($dbi, $argstr, &$request, $basepage) {
64         $args = $this->getArgs($argstr, $request);
65
66         extract($args);
67         // If the ratings table does not exist, or on dba it will break otherwise.
68         // Check if WikiTheme isa 'wikilens'
69         if ($info == 'pagename' and isa($GLOBALS['WikiTheme'], 'wikilens'))
70             $info .= ",top3recs";
71         if ($info)
72             $info = explode(',', $info);
73         else
74             $info = array();
75
76         if (in_array('top3recs', $info)) {
77             require_once 'lib/wikilens/Buddy.php';
78             require_once 'lib/wikilens/PageListColumns.php';
79
80             $active_user   = $request->getUser();
81             $active_userid = $active_user->_userid;
82
83             // if userids is null or empty, fill it with just the active user
84             if (!isset($userids) || !is_array($userids) || !count($userids)) {
85                 // TKL: moved getBuddies call inside if statement because it was
86                 // causing the userids[] parameter to be ignored
87                 if (is_string($active_userid)
88                     and strlen($active_userid)
89                     and $active_user->isSignedIn())
90                 {
91                     $userids = getBuddies($active_userid, $dbi);
92                 } else {
93                     $userids = array();
94                     // XXX: this wipes out the category caption...
95                     $caption = _("You must be logged in to view ratings.");
96                 }
97             }
98
99             // find out which users we should show ratings for
100             $allowed_users = array();
101             foreach ($userids as $userid) {
102                 $user = new RatingsUser($userid);
103                 if ($user->allow_view_ratings($active_user)) {
104                     array_push($allowed_users, $user);
105                 }
106                 // PHP's silly references... (the behavior with this line commented
107                 // out is... odd)
108                 unset($user);
109             }
110             $options = array('dimension' => $dimension,
111                              'users' => $allowed_users);
112             $args = array_merge($options, $args);
113         }
114         if (empty($pages) and $pages != '0')
115             return '';
116
117         if (in_array('numbacklinks', $info)) {
118             $args['types']['numbacklinks'] = new _PageList_Column_ListPages_count('numbacklinks', _("#"), true);
119         }
120         if (in_array('numpagelinks', $info)) {
121             $args['types']['numpagelinks'] = new _PageList_Column_ListPages_count('numpagelinks', _("#"));
122         }
123
124         $pagelist = new PageList($info, $exclude, $args);
125         $pages_array = is_string($pages) ? explodePageList($pages) : (is_array($pages) ? $pages : array());
126         $pagelist->addPageList($pages_array);
127         return $pagelist;
128     }
129 };
130
131 // how many back-/forwardlinks for this page
132 class _PageList_Column_ListPages_count extends _PageList_Column {
133     function _PageList_Column_ListPages_count($field, $display, $backwards = false) {
134         $this->_direction = $backwards;
135         return $this->_PageList_Column($field, $display, 'center');
136     }
137     function _getValue($page, &$revision_handle) {
138         $iter = $page->getLinks($this->_direction);
139         $count = $iter->count();
140         return $count;
141     }
142 }
143
144 // Local Variables:
145 // mode: php
146 // tab-width: 8
147 // c-basic-offset: 4
148 // c-hanging-comment-ender-p: nil
149 // indent-tabs-mode: nil
150 // End: