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
19 * along with PhpWiki; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
42 function getDescription() {
43 return _("List blog months links for the current or ADMIN user");
46 function getDefaultArguments() {
49 //PageList::supportedArgs(),
51 'order' => 'reverse', // latest first
52 'info' => 'month,numpages', // ignored
58 function run($dbi, $argstr, &$request, $basepage) {
59 if (is_array($argstr)) { // can do with array also.
61 if (!isset($args['order'])) $args['order'] = 'reverse';
63 $args = $this->getArgs($argstr, $request);
65 if (empty($args['user'])) {
66 $user = $request->getUser();
67 if ($user->isAuthenticated()) {
68 $args['user'] = $user->UserName();
73 if (!$args['user'] or $args['user'] == ADMIN_USER) {
74 if (BLOG_DEFAULT_EMPTY_PREFIX)
75 $args['user'] = ''; // "Blogs/day" pages
77 $args['user'] = ADMIN_USER; // "Admin/Blogs/day" pages
79 $parent = (empty($args['user']) ? '' : $args['user'] . SUBPAGE_SEPARATOR);
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']);
86 $sp = HTML::Raw('· ');
87 if (!empty($args['month'])) {
88 $prefix = $parent . $this->_blogPrefix('wikiblog') . SUBPAGE_SEPARATOR . $args['month'];
89 $pages = $dbi->titleSearch(new TextSearchQuery("^".$prefix, true, 'posix'));
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'))));
97 if (!$args['noheader'])
98 return HTML(HTML::h3(sprintf(_("Blog Entries for %s:"), $this->_monthTitle($args['month']))),
104 $blogs = $this->findBlogs ($dbi, $args['user'], 'wikiblog');
106 if (!$basepage) $basepage = _("BlogArchives");
108 usort($blogs, array("WikiPlugin_WikiBlog", "cmp"));
109 if ($args['order'] == 'reverse')
110 $blogs = array_reverse($blogs);
111 // collapse pagenames by month
113 foreach ($blogs as $rev) {
114 $blog = $this->_blog($rev);
115 $mon = $blog['month'];
116 if (empty($months[$mon]))
118 array('title' => $this->_monthTitle($mon),
121 'link' => WikiURL($basepage,
122 $this->_nonDefaultArgs(array('month' => $mon))));
124 $months[$mon]['num']++;
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'].")")));
131 if (!$args['noheader'])
132 return HTML(HTML::h3(_("Blog Archives:")), $html);
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));
152 // c-hanging-comment-ender-p: nil
153 // indent-tabs-mode: nil