]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/BlogArchives.php
New FSF address
[SourceForge/phpwiki.git] / lib / plugin / BlogArchives.php
1 <?php // -*-php-*-
2 // $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 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/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 getDefaultArguments() {
47         return //array_merge
48                //(
49                //PageList::supportedArgs(),
50              array('user'     => '',
51                    'order'    => 'reverse',        // latest first
52                    'info'     => 'month,numpages', // ignored
53                    'month'    => false,
54                    'noheader' => 0
55                    );
56     }
57
58     function run($dbi, $argstr, &$request, $basepage) {
59         if (is_array($argstr)) { // can do with array also.
60             $args =& $argstr;
61             if (!isset($args['order'])) $args['order'] = 'reverse';
62         } else {
63             $args = $this->getArgs($argstr, $request);
64         }
65         if (empty($args['user'])) {
66             $user = $request->getUser();
67             if ($user->isAuthenticated()) {
68                 $args['user'] = $user->UserName();
69             } else {
70                 $args['user'] = '';
71             }
72         }
73         if (!$args['user'] or $args['user'] == ADMIN_USER) {
74             if (BLOG_DEFAULT_EMPTY_PREFIX)
75                 $args['user'] = '';             // "Blogs/day" pages
76             else
77                 $args['user'] = ADMIN_USER; // "Admin/Blogs/day" pages
78         }
79         $parent = (empty($args['user']) ? '' : $args['user'] . SUBPAGE_SEPARATOR);
80
81         //$info = explode(',', $args['info']);
82         //$pagelist = new PageList($args['info'], $args['exclude'], $args);
83         //if (!is_array('pagename'), explode(',', $info))
84         //    unset($pagelist->_columns['pagename']);
85
86         $sp = HTML::Raw('&middot; ');
87         if (!empty($args['month'])) {
88             $prefix = $parent . $this->_blogPrefix('wikiblog') . SUBPAGE_SEPARATOR . $args['month'];
89             $pages = $dbi->titleSearch(new TextSearchQuery("^".$prefix, true, 'posix'));
90             $html = HTML::ul();
91             while ($page = $pages->next()) {
92                     $rev = $page->getCurrentRevision(false);
93                     if ($rev->get('pagetype') != 'wikiblog') continue;
94                 $blog = $this->_blog($rev);
95                 $html->pushContent(HTML::li(WikiLink($page, 'known', $rev->get('summary'))));
96             }
97             if (!$args['noheader'])
98                 return HTML(HTML::h3(sprintf(_("Blog Entries for %s:"), $this->_monthTitle($args['month']))),
99                            $html);
100             else
101                 return $html;
102         }
103
104         $blogs = $this->findBlogs ($dbi, $args['user'], 'wikiblog');
105         if ($blogs) {
106             if (!$basepage) $basepage = _("BlogArchives");
107             $html = HTML::ul();
108             usort($blogs, array("WikiPlugin_WikiBlog", "cmp"));
109             if ($args['order'] == 'reverse')
110                 $blogs = array_reverse($blogs);
111             // collapse pagenames by month
112             $months = array();
113             foreach ($blogs as $rev) {
114                 $blog = $this->_blog($rev);
115                     $mon = $blog['month'];
116                 if (empty($months[$mon]))
117                     $months[$mon] =
118                         array('title' => $this->_monthTitle($mon),
119                               'num'   => 1,
120                               'month' => $mon,
121                               'link'  => WikiURL($basepage,
122                                          $this->_nonDefaultArgs(array('month' => $mon))));
123                 else
124                     $months[$mon]['num']++;
125             }
126             foreach ($months as $m) {
127                 $html->pushContent(HTML::li(HTML::a(array('href'=>$m['link'],
128                                                           'class' => 'named-wiki'),
129                                                     $m['title'] . " (".$m['num'].")")));
130             }
131             if (!$args['noheader'])
132                 return HTML(HTML::h3(_("Blog Archives:")), $html);
133             else
134                 return $html;
135         } else
136             return '';
137     }
138
139     // box is used to display a fixed-width, narrow version with common header
140     function box($args=false, $request=false, $basepage=false) {
141         if (!$request) $request =& $GLOBALS['request'];
142         if (!$args or empty($args['limit'])) $args['limit'] = 10;
143         $args['noheader'] = 1;
144         return $this->makeBox(_("Archives"), $this->run($request->_dbi, $args, $request, $basepage));
145     }
146 };
147
148 // Local Variables:
149 // mode: php
150 // tab-width: 8
151 // c-basic-offset: 4
152 // c-hanging-comment-ender-p: nil
153 // indent-tabs-mode: nil
154 // End:
155 ?>