2 rcs_id('$Id: BlogArchives.php,v 1.1 2004-12-13 13:22:57 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 * @author: Reini Urban
19 class WikiPlugin_BlogArchives
20 extends WikiPlugin_WikiBlog
26 function getDescription() {
27 return _("List blog months links for the current or ADMIN user");
30 function getVersion() {
31 return preg_replace("/[Revision: $]/", '',
35 function getDefaultArguments() {
38 //PageList::supportedArgs(),
39 array('user' => false,
40 'order' => 'reverse', // latest first
41 'info' => 'month,numpages', // ignored
47 // "2004-12" => "December 2004"
48 function _monthTitle($month){
49 //list($year,$mon) = explode("-",$month);
50 return strftime("%B %Y", strtotime($month."-01"));
53 // "User/Blog/2004-12-13/12:28:50+01:00" => array('month' => "2004-12", ...)
54 function _blog($rev_or_page) {
55 $pagename = $rev_or_page->getName();
56 if (preg_match("/^(.*\/Blog)\/(\d\d\d\d-\d\d)-(\d\d)\/(.*)/", $pagename, $m))
57 list(,$prefix,$month,$day,$time) = $m;
58 return array('pagename' => $pagename,
59 // page (list pages per month) or revision (list months)?
60 //'title' => isa($rev_or_page,'WikiDB_PageRevision') ? $rev_or_page->get('summary') : '',
61 //'monthtitle' => $this->_monthTitle($month),
68 function _nonDefaultArgs($args) {
69 return array_diff_assoc($args, $this->getDefaultArguments());
72 function run($dbi, $argstr, &$request, $basepage) {
73 if (is_array($argstr))
76 $args = $this->getArgs($argstr, $request);
77 $user = $request->getUser();
78 if ($user->isAuthenticated())
79 $args['user'] = $user->UserName();
81 $args['user'] = ADMIN_USER;
82 $info = explode(',', $args['info']);
83 //$pagelist = new PageList($args['info'], $args['exclude'], $args);
84 //if (!is_array('pagename'), explode(',', $info))
85 // unset($pagelist->_columns['pagename']);
87 //$prefix = $args['user'].SUBPAGE_SEPARATOR."Blog";
89 $prefix = $args['user'].SUBPAGE_SEPARATOR."Blog".SUBPAGE_SEPARATOR.$args['month'].'-';
90 $pages = $dbi->titleSearch(new TextSearchQuery("^".$prefix, true, 'posix'));
92 while ($page = $pages->next()) {
93 $rev = $page->getCurrentRevision(false);
94 if ($rev->get('pagetype') != 'wikiblog') continue;
95 $blog = $this->_blog($rev);
96 $html->pushContent(WikiLink($page, 'known', $rev->get('summary')));
98 if (!$args['noheader'])
99 return HTML(HTML::h3(sprintf(_("Blog Entries for %s:"), $this->_monthTitle($args['month']))),
105 $blogs = $this->findBlogs ($dbi, $args['user'], 'wikiblog');
107 if (!$basepage) $basepage = _("BlogArchives");
109 usort($blogs, array("WikiPlugin_WikiBlog", "cmp"));
110 if ($args['order'] == 'reverse')
111 $blogs = array_reverse($blogs);
112 // collapse pagenames by month
114 foreach ($blogs as $rev) {
115 $blog = $this->_blog($rev);
116 $mon = $blog['month'];
117 if (empty($months[$mon]))
119 array('title' => $this->_monthTitle($mon),
122 'link' => WikiURL($basepage,
123 $this->_nonDefaultArgs(array('month' => $mon))));
126 $months[$mon]['num']++;
128 foreach ($months as $m) {
129 $html->pushContent(HTML::a(array('href'=>$m['link'],
130 'class' => 'named-wiki'),
131 $m['title'] . " (".$m['num'].")"));
133 if (!$args['noheader'])
134 return HTML(HTML::h3(_("Blog Archives:")), $html);
141 // box is used to display a fixed-width, narrow version with common header
142 function box($args=false, $request=false, $basepage=false) {
143 if (!$request) $request =& $GLOBALS['request'];
144 if (!$args or empty($args['limit'])) $args['limit'] = 10;
145 if (!$args or empty($args['noheader'])) $args['noheader'] = 1;
146 return $this->makeBox('', $this->run($request->_dbi, $args, $request, $basepage));
150 // $Log: not supported by cvs2svn $
156 // c-hanging-comment-ender-p: nil
157 // indent-tabs-mode: nil