2 rcs_id('$Id: BlogArchives.php,v 1.3 2004-12-15 17:45:08 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.
76 if (!isset($args['order'])) $args['order'] = 'reverse';
78 $args = $this->getArgs($argstr, $request);
80 if (empty($args['user'])) {
81 $user = $request->getUser();
82 if ($user->isAuthenticated()) {
83 $args['user'] = $user->UserName();
88 if (!$args['user'] or $args['user'] == ADMIN_USER) {
89 if (BLOG_EMPTY_DEFAULT_PREFIX)
90 $args['user'] = ''; // "Blogs/day" pages
92 $args['user'] = ADMIN_USER; // "Admin/Blogs/day" pages
94 $parent = (empty($args['user']) ? '' : $args['user'] . SUBPAGE_SEPARATOR);
96 //$info = explode(',', $args['info']);
97 //$pagelist = new PageList($args['info'], $args['exclude'], $args);
98 //if (!is_array('pagename'), explode(',', $info))
99 // unset($pagelist->_columns['pagename']);
101 $sp = HTML::Raw('· ');
102 if (!empty($args['month'])) {
103 $prefix = $parent . $this->_blogPrefix('wikiblog') . SUBPAGE_SEPARATOR . $args['month'];
104 $pages = $dbi->titleSearch(new TextSearchQuery("^".$prefix, true, 'posix'));
106 while ($page = $pages->next()) {
107 $rev = $page->getCurrentRevision(false);
108 if ($rev->get('pagetype') != 'wikiblog') continue;
109 $blog = $this->_blog($rev);
110 $html->pushContent(HTML::li(WikiLink($page, 'known', $rev->get('summary'))));
112 if (!$args['noheader'])
113 return HTML(HTML::h3(sprintf(_("Blog Entries for %s:"), $this->_monthTitle($args['month']))),
119 $blogs = $this->findBlogs ($dbi, $args['user'], 'wikiblog');
121 if (!$basepage) $basepage = _("BlogArchives");
123 usort($blogs, array("WikiPlugin_WikiBlog", "cmp"));
124 if ($args['order'] == 'reverse')
125 $blogs = array_reverse($blogs);
126 // collapse pagenames by month
128 foreach ($blogs as $rev) {
129 $blog = $this->_blog($rev);
130 $mon = $blog['month'];
131 if (empty($months[$mon]))
133 array('title' => $this->_monthTitle($mon),
136 'link' => WikiURL($basepage,
137 $this->_nonDefaultArgs(array('month' => $mon))));
139 $months[$mon]['num']++;
141 foreach ($months as $m) {
142 $html->pushContent(HTML::li(HTML::a(array('href'=>$m['link'],
143 'class' => 'named-wiki'),
144 $m['title'] . " (".$m['num'].")")));
146 if (!$args['noheader'])
147 return HTML(HTML::h3(_("Blog Archives:")), $html);
154 // box is used to display a fixed-width, narrow version with common header
155 function box($args=false, $request=false, $basepage=false) {
156 if (!$request) $request =& $GLOBALS['request'];
157 if (!$args or empty($args['limit'])) $args['limit'] = 10;
158 $args['noheader'] = 1;
159 return $this->makeBox(_("Archives"), $this->run($request->_dbi, $args, $request, $basepage));
163 // $Log: not supported by cvs2svn $
164 // Revision 1.2 2004/12/14 21:35:15 rurban
165 // support new BLOG_EMPTY_DEFAULT_PREFIX
167 // Revision 1.1 2004/12/13 13:22:57 rurban
168 // new BlogArchives plugin for the new blog theme. enable default box method
169 // for all plugins. Minor search improvement.
176 // c-hanging-comment-ender-p: nil
177 // indent-tabs-mode: nil