]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/ListPages.php
simplify exclude, add numbacklinks+numpagelinks
[SourceForge/phpwiki.git] / lib / plugin / ListPages.php
1 <?php // -*-php-*-
2 rcs_id('$Id: ListPages.php,v 1.6 2004-09-14 10:33:39 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, 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 getVersion() {
46         return preg_replace("/[Revision: $]/", '',
47                             "\$Revision: 1.6 $");
48     }
49
50     function getDefaultArguments() {
51         return array('pages'    => false,
52                      'exclude'  => false,
53                      'info'     => 'pagename,top3recs',
54                      'dimension' => 0,
55                      );
56     }
57
58     // info arg allows multiple columns
59     // info=mtime,hits,summary,version,author,locked,minor
60     // additional info args: 
61     //   top3recs      : recommendations
62     //   numbacklinks  : number of backlinks (links to the given page)
63     //   numpagelinks  : number of forward links (links at the given page)
64
65     function run($dbi, $argstr, &$request, $basepage) {
66         $args = $this->getArgs($argstr, $request);
67         extract($args);
68         if ($info)
69             $info = split(',', $info);
70         else
71             $info = array();
72
73         if (in_array('top3recs', $info)) {
74             require_once('lib/wikilens/Buddy.php');
75             require_once('lib/wikilens/PageListColumns.php');
76
77             $active_user   = $request->getUser();
78             $active_userid = $active_user->_userid;
79
80             // if userids is null or empty, fill it with just the active user
81             if (!isset($userids) || !is_array($userids) || !count($userids)) {
82                 // TKL: moved getBuddies call inside if statement because it was
83                 // causing the userids[] parameter to be ignored
84                 if (is_string($active_userid) && strlen($active_userid) && $active_user->isSignedIn()) {
85                     $userids = getBuddies($active_userid, $dbi);
86                 } else {
87                     $userids = array();
88                     // XXX: this wipes out the category caption...
89                     $caption = _("You must be logged in to view ratings.");
90                 }
91             }
92
93             // find out which users we should show ratings for
94             $allowed_users = array();
95             foreach ($userids as $userid) {
96                 $user = new RatingsUser($userid);
97                 if ($user->allow_view_ratings($active_user)) {
98                     array_push($allowed_users, $user);
99                 }
100                 // PHP's silly references... (the behavior with this line commented
101                 // out is... odd)
102                 unset($user);
103             }
104             $options = array('dimension' => $dimension, 
105                              'users' => $allowed_users);
106             $args = array_merge($options, $args);
107         }
108         if (empty($pages) and $pages != '0')
109             return '';
110
111         if (in_array('numbacklinks', $info)) {
112             $args['types']['numbacklinks'] = new _PageList_Column_ListPages_count('numbacklinks', _("#"), true);
113         }
114         if (in_array('numpagelinks', $info)) {
115             $args['types']['numpagelinks'] = new _PageList_Column_ListPages_count('numpagelinks', _("#"));
116         }
117
118         $pagelist = new PageList($info, $exclude, $args);
119         $pages_array = is_string($pages) ? explodePageList($pages) : (is_array($pages) ? $pages : array());
120         $pagelist->addPageList($pages_array);
121         /*
122         if (is_string($exclude) and !empty($exclude)) {
123             $exclude = explodePageList($exclude);
124             // $argstr = preg_replace("/exclude=\S*\s/", "", $argstr);
125         }
126         $pages_array = is_string($pages) ? explodePageList($pages) : (is_array($pages) ? $pages : array());
127         foreach ($pages_array as $pagename) {
128             if (empty($exclude) or !in_array($pagename, $exclude)) {
129                 $page = $dbi->getPage($pagename); 
130                 $pagelist->addPage($page);
131             }
132         }
133         */
134         return $pagelist;
135     }
136 };
137
138 // how many back-/forwardlinks for this page
139 class _PageList_Column_ListPages_count extends _PageList_Column {
140     function _PageList_Column_ListPages_count($field, $display, $backwards = false) {
141         $this->_direction = $backwards;
142         return $this->_PageList_Column($field, $display, 'center');
143     }
144     function _getValue($page, &$revision_handle) {
145         $iter = $page->getLinks($this->_direction);
146         $count = $iter->count();
147         return $count;
148     }
149 }
150
151 // $Log: not supported by cvs2svn $
152 // Revision 1.5  2004/09/06 08:37:31  rurban
153 // plugin-list support for pages and exclude args
154 //
155 // Revision 1.4  2004/07/08 20:30:07  rurban
156 // plugin->run consistency: request as reference, added basepage.
157 // encountered strange bug in AllPages (and the test) which destroys ->_dbi
158 //
159 // Revision 1.3  2004/06/28 18:58:18  rurban
160 // fixed another pass-by-reference
161 //
162 // Revision 1.2  2004/06/18 14:42:17  rurban
163 // added wikilens libs (not yet merged good enough, some work for DanFr)
164 //
165 // Revision 1.1  2004/06/08 13:49:43  rurban
166 // List pages that are explicitly given as the pages argument, by DanFr
167 // 
168
169 // Local Variables:
170 // mode: php
171 // tab-width: 8
172 // c-basic-offset: 4
173 // c-hanging-comment-ender-p: nil
174 // indent-tabs-mode: nil
175 // End:
176 ?>