]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/ListPages.php
plugin->run consistency: request as reference, added basepage.
[SourceForge/phpwiki.git] / lib / plugin / ListPages.php
1 <?php // -*-php-*-
2 rcs_id('$Id: ListPages.php,v 1.4 2004-07-08 20:30:07 rurban Exp $');
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
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 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.
30  *
31  * @author: Dan Frankowski
32  */
33 class WikiPlugin_ListPages
34 extends WikiPlugin
35 {
36     function getName() {
37         return _("ListPages");
38     }
39
40     function getDescription() {
41         return _("List pages that are explicitly given as the pages argument.");
42     }
43
44     function getVersion() {
45         return preg_replace("/[Revision: $]/", '',
46                             "\$Revision: 1.4 $");
47     }
48
49     function getDefaultArguments() {
50         return array('pages'    => '',
51                      'info'     => 'pagename,top3recs',
52                      'dimension' => 0,
53                      );
54     }
55
56     // info arg allows multiple columns
57     // info=mtime,hits,summary,version,author,locked,minor
58
59     function run($dbi, $argstr, &$request, $basepage) {
60         $args = $this->getArgs($argstr, $request);
61         extract($args);
62
63         if (in_array('top3recs', split(',', $info))) {
64
65             require_once('lib/wikilens/Buddy.php');
66             require_once('lib/wikilens/PageListColumns.php');
67
68             $active_user   = $request->getUser();
69             $active_userid = $active_user->_userid;
70
71             // if userids is null or empty, fill it with just the active user
72             if (!isset($userids) || !is_array($userids) || !count($userids)) {
73                 // TKL: moved getBuddies call inside if statement because it was
74                 // causing the userids[] parameter to be ignored
75                 if (is_string($active_userid) && strlen($active_userid) && $active_user->isSignedIn()) {
76                     $userids = getBuddies($active_userid, $dbi);
77                 } else {
78                     $userids = array();
79                     // XXX: this wipes out the category caption...
80                     $caption = _("You must be logged in to view ratings.");
81                 }
82             }
83
84             // find out which users we should show ratings for
85             $allowed_users = array();
86             foreach ($userids as $userid) {
87                 $user = new RatingsUser($userid);
88                 if ($user->allow_view_ratings($active_user)) {
89                     array_push($allowed_users, $user);
90                 }
91                 // PHP's silly references... (the behavior with this line commented
92                 // out is... odd)
93                 unset($user);
94             }
95             //DONE:
96             //What we really want is passing the pagelist object to the column
97             //$top3 = new _PageList_Column_top3recs('top3recs', _("Top Recommendations"), 
98             //                                      'left', 0, $allowed_users);
99             $options = array('dimension' => $dimension, 
100                              'users' => $allowed_users);
101         } else {
102             $options = array();
103         }
104
105         if (empty($pages))
106             return '';
107
108         $pagelist = new PageList($info, false, $options);
109         // FIXME: This should be not neccessary with the new custom pagelist columns
110         /*
111         if (!empty($options)) {
112             $pagelist->addColumnObject(new _PageList_Column_top3recs('custom:top3recs', _("Top Recommendations"), 
113                                                                      'left', $pagelist));
114         }
115         */
116         foreach (explode(',', $pages) as $key => $pagename) {
117             $page = $pages = $dbi->getPage($pagename); 
118             $pagelist->addPage($page);
119         }
120
121         return $pagelist;
122     }
123 };
124
125 // $Log: not supported by cvs2svn $
126 // Revision 1.3  2004/06/28 18:58:18  rurban
127 // fixed another pass-by-reference
128 //
129 // Revision 1.2  2004/06/18 14:42:17  rurban
130 // added wikilens libs (not yet merged good enough, some work for DanFr)
131 //
132 // Revision 1.1  2004/06/08 13:49:43  rurban
133 // List pages that are explicitly given as the pages argument, by DanFr
134 // 
135
136 // Local Variables:
137 // mode: php
138 // tab-width: 8
139 // c-basic-offset: 4
140 // c-hanging-comment-ender-p: nil
141 // indent-tabs-mode: nil
142 // End:
143 ?>