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