4 * Copyright (C) 2004 $ThePhpWikiProgrammingTeam
6 * This file is part of PhpWiki.
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.
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.
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.
23 require_once 'lib/plugin/WikiBlog.php';
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.
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
35 class WikiPlugin_BlogArchives
36 extends WikiPlugin_WikiBlog
38 function getDescription()
40 return _("List blog months links for the current or ADMIN user.");
43 function getDefaultArguments()
47 //PageList::supportedArgs(),
49 'order' => 'reverse', // latest first
50 'info' => 'month,numpages', // ignored
56 function run($dbi, $argstr, &$request, $basepage)
58 if (is_array($argstr)) { // can do with array also.
60 if (!isset($args['order'])) $args['order'] = 'reverse';
62 $args = $this->getArgs($argstr, $request);
64 if (empty($args['user'])) {
65 $user = $request->getUser();
66 if ($user->isAuthenticated()) {
67 $args['user'] = $user->UserName();
72 if (!$args['user'] or $args['user'] == ADMIN_USER) {
73 if (BLOG_DEFAULT_EMPTY_PREFIX)
74 $args['user'] = ''; // "Blogs/day" pages
76 $args['user'] = ADMIN_USER; // "Admin/Blogs/day" pages
78 $parent = (empty($args['user']) ? '' : $args['user'] . SUBPAGE_SEPARATOR);
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']);
85 if (!empty($args['month'])) {
86 $prefix = $parent . $this->blogPrefix('wikiblog') . SUBPAGE_SEPARATOR . $args['month'];
87 $pages = $dbi->titleSearch(new TextSearchQuery("^" . $prefix, true, 'posix'));
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'))));
95 if (!$args['noheader'])
96 return HTML(HTML::h3(sprintf(_("Blog Entries for %s:"), $this->monthTitle($args['month']))),
102 $blogs = $this->findBlogs($dbi, $args['user'], 'wikiblog');
104 if (!$basepage) $basepage = _("BlogArchives");
106 usort($blogs, array("WikiPlugin_WikiBlog", "cmp"));
107 if ($args['order'] == 'reverse')
108 $blogs = array_reverse($blogs);
109 // collapse pagenames by month
111 foreach ($blogs as $rev) {
112 $blog = $this->_blog($rev);
113 $mon = $blog['month'];
114 if (empty($months[$mon]))
116 array('title' => $this->monthTitle($mon),
119 'link' => WikiURL($basepage,
120 $this->nonDefaultArgs(array('month' => $mon))));
122 $months[$mon]['num']++;
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'] . ")")));
129 if (!$args['noheader'])
130 return HTML(HTML::h3(_("Blog Archives:")), $html);
137 // box is used to display a fixed-width, narrow version with common header
138 function box($args = false, $request = false, $basepage = false)
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));
151 // c-hanging-comment-ender-p: nil
152 // indent-tabs-mode: nil