]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/BlogArchives.php
new BlogArchives plugin for the new blog theme. enable default box method
[SourceForge/phpwiki.git] / lib / plugin / BlogArchives.php
1 <?php // -*-php-*-
2 rcs_id('$Id: BlogArchives.php,v 1.1 2004-12-13 13:22:57 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  * @author: Reini Urban
18  */
19 class WikiPlugin_BlogArchives
20 extends WikiPlugin_WikiBlog
21 {
22     function getName() {
23         return _("Archives");
24     }
25
26     function getDescription() {
27         return _("List blog months links for the current or ADMIN user");
28     }
29
30     function getVersion() {
31         return preg_replace("/[Revision: $]/", '',
32                             "\$Revision: 1.1 $");
33     }
34
35     function getDefaultArguments() {
36         return array_merge
37             (
38              //PageList::supportedArgs(), 
39              array('user'     => false,
40                    'order'    => 'reverse',        // latest first
41                    'info'     => 'month,numpages', // ignored
42                    'month'    => false,
43                    'noheader' => 0
44                    ));
45     }
46
47     // "2004-12" => "December 2004"
48     function _monthTitle($month){
49         //list($year,$mon) = explode("-",$month);
50         return strftime("%B %Y", strtotime($month."-01"));
51     }
52
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),
62                      'month'   => $month,
63                      'day'   => $day,
64                      'time'  => $time,
65                      'prefix' => $prefix);
66     }
67
68     function _nonDefaultArgs($args) {
69         return array_diff_assoc($args, $this->getDefaultArguments());
70     }
71     
72     function run($dbi, $argstr, &$request, $basepage) {
73         if (is_array($argstr))
74             $args =& $argstr;
75         else
76             $args = $this->getArgs($argstr, $request);
77         $user = $request->getUser();
78         if ($user->isAuthenticated())
79             $args['user'] = $user->UserName();
80         else
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']);
86         
87         //$prefix = $args['user'].SUBPAGE_SEPARATOR."Blog";
88         if ($args['month']) {
89             $prefix = $args['user'].SUBPAGE_SEPARATOR."Blog".SUBPAGE_SEPARATOR.$args['month'].'-';
90             $pages = $dbi->titleSearch(new TextSearchQuery("^".$prefix, true, 'posix'));
91             $html = HTML::ul();
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')));
97             }
98             if (!$args['noheader'])
99                 return HTML(HTML::h3(sprintf(_("Blog Entries for %s:"), $this->_monthTitle($args['month']))),
100                            $html);
101             else
102                 return $html;
103         }
104
105         $blogs = $this->findBlogs ($dbi, $args['user'], 'wikiblog');
106         if ($blogs) {
107             if (!$basepage) $basepage = _("BlogArchives");
108             $html = HTML::ul();
109             usort($blogs, array("WikiPlugin_WikiBlog", "cmp"));
110             if ($args['order'] == 'reverse')
111                 $blogs = array_reverse($blogs);
112             // collapse pagenames by month    
113             $months = array();
114             foreach ($blogs as $rev) {
115                 $blog = $this->_blog($rev);
116                 $mon = $blog['month'];
117                 if (empty($months[$mon]))
118                     $months[$mon] = 
119                         array('title' => $this->_monthTitle($mon),
120                               'num'   => 1,
121                               'month' => $mon,
122                               'link'  => WikiURL($basepage, 
123                                          $this->_nonDefaultArgs(array('month' => $mon))));
124                                           
125                 else
126                     $months[$mon]['num']++;
127             }
128             foreach ($months as $m) {
129                 $html->pushContent(HTML::a(array('href'=>$m['link'],
130                                                  'class' => 'named-wiki'),
131                                            $m['title'] . " (".$m['num'].")"));
132             }
133             if (!$args['noheader'])
134                 return HTML(HTML::h3(_("Blog Archives:")), $html);
135             else
136                 return $html;
137         } else 
138             return '';
139     }
140
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));
147     }
148 };
149
150 // $Log: not supported by cvs2svn $
151
152 // Local Variables:
153 // mode: php
154 // tab-width: 8
155 // c-basic-offset: 4
156 // c-hanging-comment-ender-p: nil
157 // indent-tabs-mode: nil
158 // End:
159 ?>