]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/BlogArchives.php
Replace tabs by spaces; remove EOL spaces
[SourceForge/phpwiki.git] / lib / plugin / BlogArchives.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /*
4  * Copyright (C) 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/plugin/WikiBlog.php');
24
25 /**
26  * BlogArchives - List monthly links for the current users blog if signed,
27  * or the ADMIN_USER's Blog if not.
28  * On month=... list the blog titles per month.
29  *
30  * TODO: year=
31  *       support PageList (paging, limit, info filters: title, num, month, year, ...)
32  *       leave off time subpage? Blogs just per day with one summary title only?
33  * @author: Reini Urban
34  */
35 class WikiPlugin_BlogArchives
36 extends WikiPlugin_WikiBlog
37 {
38     function getName() {
39         return _("Archives");
40     }
41
42     function getDescription() {
43         return _("List blog months links for the current or ADMIN user");
44     }
45
46     function getVersion() {
47         return preg_replace("/[Revision: $]/", '',
48                             "\$Revision$");
49     }
50
51     function getDefaultArguments() {
52         return //array_merge
53                //(
54                //PageList::supportedArgs(),
55              array('user'     => '',
56                    'order'    => 'reverse',        // latest first
57                    'info'     => 'month,numpages', // ignored
58                    'month'    => false,
59                    'noheader' => 0
60                    );
61     }
62
63     function run($dbi, $argstr, &$request, $basepage) {
64         if (is_array($argstr)) { // can do with array also.
65             $args =& $argstr;
66             if (!isset($args['order'])) $args['order'] = 'reverse';
67         } else {
68             $args = $this->getArgs($argstr, $request);
69         }
70         if (empty($args['user'])) {
71             $user = $request->getUser();
72             if ($user->isAuthenticated()) {
73                 $args['user'] = $user->UserName();
74             } else {
75                 $args['user'] = '';
76             }
77         }
78         if (!$args['user'] or $args['user'] == ADMIN_USER) {
79             if (BLOG_DEFAULT_EMPTY_PREFIX)
80                 $args['user'] = '';             // "Blogs/day" pages
81             else
82                 $args['user'] = ADMIN_USER; // "Admin/Blogs/day" pages
83         }
84         $parent = (empty($args['user']) ? '' : $args['user'] . SUBPAGE_SEPARATOR);
85
86         //$info = explode(',', $args['info']);
87         //$pagelist = new PageList($args['info'], $args['exclude'], $args);
88         //if (!is_array('pagename'), explode(',', $info))
89         //    unset($pagelist->_columns['pagename']);
90
91         $sp = HTML::Raw('&middot; ');
92         if (!empty($args['month'])) {
93             $prefix = $parent . $this->_blogPrefix('wikiblog') . SUBPAGE_SEPARATOR . $args['month'];
94             $pages = $dbi->titleSearch(new TextSearchQuery("^".$prefix, true, 'posix'));
95             $html = HTML::ul();
96             while ($page = $pages->next()) {
97                     $rev = $page->getCurrentRevision(false);
98                     if ($rev->get('pagetype') != 'wikiblog') continue;
99                 $blog = $this->_blog($rev);
100                 $html->pushContent(HTML::li(WikiLink($page, 'known', $rev->get('summary'))));
101             }
102             if (!$args['noheader'])
103                 return HTML(HTML::h3(sprintf(_("Blog Entries for %s:"), $this->_monthTitle($args['month']))),
104                            $html);
105             else
106                 return $html;
107         }
108
109         $blogs = $this->findBlogs ($dbi, $args['user'], 'wikiblog');
110         if ($blogs) {
111             if (!$basepage) $basepage = _("BlogArchives");
112             $html = HTML::ul();
113             usort($blogs, array("WikiPlugin_WikiBlog", "cmp"));
114             if ($args['order'] == 'reverse')
115                 $blogs = array_reverse($blogs);
116             // collapse pagenames by month
117             $months = array();
118             foreach ($blogs as $rev) {
119                 $blog = $this->_blog($rev);
120                     $mon = $blog['month'];
121                 if (empty($months[$mon]))
122                     $months[$mon] =
123                         array('title' => $this->_monthTitle($mon),
124                               'num'   => 1,
125                               'month' => $mon,
126                               'link'  => WikiURL($basepage,
127                                          $this->_nonDefaultArgs(array('month' => $mon))));
128                 else
129                     $months[$mon]['num']++;
130             }
131             foreach ($months as $m) {
132                 $html->pushContent(HTML::li(HTML::a(array('href'=>$m['link'],
133                                                           'class' => 'named-wiki'),
134                                                     $m['title'] . " (".$m['num'].")")));
135             }
136             if (!$args['noheader'])
137                 return HTML(HTML::h3(_("Blog Archives:")), $html);
138             else
139                 return $html;
140         } else
141             return '';
142     }
143
144     // box is used to display a fixed-width, narrow version with common header
145     function box($args=false, $request=false, $basepage=false) {
146         if (!$request) $request =& $GLOBALS['request'];
147         if (!$args or empty($args['limit'])) $args['limit'] = 10;
148         $args['noheader'] = 1;
149         return $this->makeBox(_("Archives"), $this->run($request->_dbi, $args, $request, $basepage));
150     }
151 };
152
153 // Local Variables:
154 // mode: php
155 // tab-width: 8
156 // c-basic-offset: 4
157 // c-hanging-comment-ender-p: nil
158 // indent-tabs-mode: nil
159 // End:
160 ?>