]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/BlogArchives.php
fix box method
[SourceForge/phpwiki.git] / lib / plugin / BlogArchives.php
1 <?php // -*-php-*-
2 rcs_id('$Id: BlogArchives.php,v 1.3 2004-12-15 17:45:08 rurban Exp $');
3 /*
4  * Copyright 2004 $ThePhpWikiProgrammingTeam
5  */
6
7 //require_once('lib/PageList.php');
8 require_once('lib/plugin/WikiBlog.php');
9
10 /**
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.
14  *
15  * TODO: year=
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
19  */
20 class WikiPlugin_BlogArchives
21 extends WikiPlugin_WikiBlog
22 {
23     function getName() {
24         return _("Archives");
25     }
26
27     function getDescription() {
28         return _("List blog months links for the current or ADMIN user");
29     }
30
31     function getVersion() {
32         return preg_replace("/[Revision: $]/", '',
33                             "\$Revision: 1.3 $");
34     }
35
36     function getDefaultArguments() {
37         return //array_merge
38                //(
39                //PageList::supportedArgs(), 
40              array('user'     => '',
41                    'order'    => 'reverse',        // latest first
42                    'info'     => 'month,numpages', // ignored
43                    'month'    => false,
44                    'noheader' => 0
45                    );
46     }
47
48     // "2004-12" => "December 2004"
49     function _monthTitle($month){
50         //list($year,$mon) = explode("-",$month);
51         return strftime("%B %Y", strtotime($month."-01"));
52     }
53
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),
63                      'month'   => $month,
64                      'day'   => $day,
65                      'time'  => $time,
66                      'prefix' => $prefix);
67     }
68
69     function _nonDefaultArgs($args) {
70         return array_diff_assoc($args, $this->getDefaultArguments());
71     }
72     
73     function run($dbi, $argstr, &$request, $basepage) {
74         if (is_array($argstr)) { // can do with array also.
75             $args =& $argstr;
76             if (!isset($args['order'])) $args['order'] = 'reverse';
77         } else {
78             $args = $this->getArgs($argstr, $request);
79         }
80         if (empty($args['user'])) {
81             $user = $request->getUser();
82             if ($user->isAuthenticated()) {
83                 $args['user'] = $user->UserName();
84             } else {
85                 $args['user'] = '';
86             }
87         }
88         if (!$args['user'] or $args['user'] == ADMIN_USER) {
89             if (BLOG_EMPTY_DEFAULT_PREFIX)
90                 $args['user'] = '';         // "Blogs/day" pages 
91             else
92                 $args['user'] = ADMIN_USER; // "Admin/Blogs/day" pages 
93         }
94         $parent = (empty($args['user']) ? '' : $args['user'] . SUBPAGE_SEPARATOR);
95
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']);
100         
101         $sp = HTML::Raw('&middot; ');
102         if (!empty($args['month'])) {
103             $prefix = $parent . $this->_blogPrefix('wikiblog') . SUBPAGE_SEPARATOR . $args['month'];
104             $pages = $dbi->titleSearch(new TextSearchQuery("^".$prefix, true, 'posix'));
105             $html = HTML::ul();
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'))));
111             }
112             if (!$args['noheader'])
113                 return HTML(HTML::h3(sprintf(_("Blog Entries for %s:"), $this->_monthTitle($args['month']))),
114                            $html);
115             else
116                 return $html;
117         }
118
119         $blogs = $this->findBlogs ($dbi, $args['user'], 'wikiblog');
120         if ($blogs) {
121             if (!$basepage) $basepage = _("BlogArchives");
122             $html = HTML::ul();
123             usort($blogs, array("WikiPlugin_WikiBlog", "cmp"));
124             if ($args['order'] == 'reverse')
125                 $blogs = array_reverse($blogs);
126             // collapse pagenames by month
127             $months = array();
128             foreach ($blogs as $rev) {
129                 $blog = $this->_blog($rev);
130                 $mon = $blog['month'];
131                 if (empty($months[$mon]))
132                     $months[$mon] = 
133                         array('title' => $this->_monthTitle($mon),
134                               'num'   => 1,
135                               'month' => $mon,
136                               'link'  => WikiURL($basepage, 
137                                          $this->_nonDefaultArgs(array('month' => $mon))));
138                 else
139                     $months[$mon]['num']++;
140             }
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'].")")));
145             }
146             if (!$args['noheader'])
147                 return HTML(HTML::h3(_("Blog Archives:")), $html);
148             else
149                 return $html;
150         } else 
151             return '';
152     }
153
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));
160     }
161 };
162
163 // $Log: not supported by cvs2svn $
164 // Revision 1.2  2004/12/14 21:35:15  rurban
165 // support new BLOG_EMPTY_DEFAULT_PREFIX
166 //
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.
170 //
171
172 // Local Variables:
173 // mode: php
174 // tab-width: 8
175 // c-basic-offset: 4
176 // c-hanging-comment-ender-p: nil
177 // indent-tabs-mode: nil
178 // End:
179 ?>