2 rcs_id('$Id: BlogArchives.php,v 1.2 2004-12-14 21:35:15 rurban Exp $');
4 * Copyright 2004 $ThePhpWikiProgrammingTeam
7 //require_once('lib/PageList.php');
8 require_once('lib/plugin/WikiBlog.php');
11 * BlogArchives - List monthly links for the current users blog if signed,
12 * or the ADMIN_USER's Blog if not.
13 * On month=... list the blog titles per month.
16 * support PageList (paging, limit, info filters: title, num, month, year, ...)
17 * leave off time subpage? Blogs just per day with one summary title only?
18 * @author: Reini Urban
20 class WikiPlugin_BlogArchives
21 extends WikiPlugin_WikiBlog
27 function getDescription() {
28 return _("List blog months links for the current or ADMIN user");
31 function getVersion() {
32 return preg_replace("/[Revision: $]/", '',
36 function getDefaultArguments() {
39 //PageList::supportedArgs(),
41 'order' => 'reverse', // latest first
42 'info' => 'month,numpages', // ignored
48 // "2004-12" => "December 2004"
49 function _monthTitle($month){
50 //list($year,$mon) = explode("-",$month);
51 return strftime("%B %Y", strtotime($month."-01"));
54 // "User/Blog/2004-12-13/12:28:50+01:00" => array('month' => "2004-12", ...)
55 function _blog($rev_or_page) {
56 $pagename = $rev_or_page->getName();
57 if (preg_match("/^(.*\/Blog)\/(\d\d\d\d-\d\d)-(\d\d)\/(.*)/", $pagename, $m))
58 list(,$prefix,$month,$day,$time) = $m;
59 return array('pagename' => $pagename,
60 // page (list pages per month) or revision (list months)?
61 //'title' => isa($rev_or_page,'WikiDB_PageRevision') ? $rev_or_page->get('summary') : '',
62 //'monthtitle' => $this->_monthTitle($month),
69 function _nonDefaultArgs($args) {
70 return array_diff_assoc($args, $this->getDefaultArguments());
73 function run($dbi, $argstr, &$request, $basepage) {
74 if (is_array($argstr)) // can do with array also.
77 $args = $this->getArgs($argstr, $request);
78 if (empty($args['user'])) {
79 $user = $request->getUser();
80 if ($user->isAuthenticated()) {
81 $args['user'] = $user->UserName();
86 if (!$args['user'] or $args['user'] == ADMIN_USER) {
87 if (BLOG_EMPTY_DEFAULT_PREFIX)
88 $args['user'] = ''; // "Blogs/day" pages
90 $args['user'] = ADMIN_USER; // "Admin/Blogs/day" pages
92 $parent = (empty($args['user']) ? '' : $args['user'] . SUBPAGE_SEPARATOR);
94 //$info = explode(',', $args['info']);
95 //$pagelist = new PageList($args['info'], $args['exclude'], $args);
96 //if (!is_array('pagename'), explode(',', $info))
97 // unset($pagelist->_columns['pagename']);
99 if (!empty($args['month'])) {
100 $prefix = $parent . $this->_blogPrefix('wikiblog') . SUBPAGE_SEPARATOR . $args['month'];
101 $pages = $dbi->titleSearch(new TextSearchQuery("^".$prefix, true, 'posix'));
103 while ($page = $pages->next()) {
104 $rev = $page->getCurrentRevision(false);
105 if ($rev->get('pagetype') != 'wikiblog') continue;
106 $blog = $this->_blog($rev);
107 $html->pushContent(WikiLink($page, 'known', $rev->get('summary')));
109 if (!$args['noheader'])
110 return HTML(HTML::h3(sprintf(_("Blog Entries for %s:"), $this->_monthTitle($args['month']))),
116 $blogs = $this->findBlogs ($dbi, $args['user'], 'wikiblog');
118 if (!$basepage) $basepage = _("BlogArchives");
120 usort($blogs, array("WikiPlugin_WikiBlog", "cmp"));
121 if ($args['order'] == 'reverse')
122 $blogs = array_reverse($blogs);
123 // collapse pagenames by month
125 foreach ($blogs as $rev) {
126 $blog = $this->_blog($rev);
127 $mon = $blog['month'];
128 if (empty($months[$mon]))
130 array('title' => $this->_monthTitle($mon),
133 'link' => WikiURL($basepage,
134 $this->_nonDefaultArgs(array('month' => $mon))));
136 $months[$mon]['num']++;
138 foreach ($months as $m) {
139 $html->pushContent(HTML::a(array('href'=>$m['link'],
140 'class' => 'named-wiki'),
141 $m['title'] . " (".$m['num'].")"));
143 if (!$args['noheader'])
144 return HTML(HTML::h3(_("Blog Archives:")), $html);
151 // box is used to display a fixed-width, narrow version with common header
152 function box($args=false, $request=false, $basepage=false) {
153 if (!$request) $request =& $GLOBALS['request'];
154 if (!$args or empty($args['limit'])) $args['limit'] = 10;
155 $args['noheader'] = 1;
156 return $this->makeBox(_("Archives"), $this->run($request->_dbi, $args, $request, $basepage));
160 // $Log: not supported by cvs2svn $
161 // Revision 1.1 2004/12/13 13:22:57 rurban
162 // new BlogArchives plugin for the new blog theme. enable default box method
163 // for all plugins. Minor search improvement.
170 // c-hanging-comment-ender-p: nil
171 // indent-tabs-mode: nil