]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/BlogArchives.php
support new BLOG_EMPTY_DEFAULT_PREFIX
[SourceForge/phpwiki.git] / lib / plugin / BlogArchives.php
1 <?php // -*-php-*-
2 rcs_id('$Id: BlogArchives.php,v 1.2 2004-12-14 21:35:15 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.2 $");
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         else
77             $args = $this->getArgs($argstr, $request);
78         if (empty($args['user'])) {
79             $user = $request->getUser();
80             if ($user->isAuthenticated()) {
81                 $args['user'] = $user->UserName();
82             } else {
83                 $args['user'] = '';
84             }
85         }
86         if (!$args['user'] or $args['user'] == ADMIN_USER) {
87             if (BLOG_EMPTY_DEFAULT_PREFIX)
88                 $args['user'] = '';         // "Blogs/day" pages 
89             else
90                 $args['user'] = ADMIN_USER; // "Admin/Blogs/day" pages 
91         }
92         $parent = (empty($args['user']) ? '' : $args['user'] . SUBPAGE_SEPARATOR);
93
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']);
98         
99         if (!empty($args['month'])) {
100             $prefix = $parent . $this->_blogPrefix('wikiblog') . SUBPAGE_SEPARATOR . $args['month'];
101             $pages = $dbi->titleSearch(new TextSearchQuery("^".$prefix, true, 'posix'));
102             $html = HTML::ul();
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')));
108             }
109             if (!$args['noheader'])
110                 return HTML(HTML::h3(sprintf(_("Blog Entries for %s:"), $this->_monthTitle($args['month']))),
111                            $html);
112             else
113                 return $html;
114         }
115
116         $blogs = $this->findBlogs ($dbi, $args['user'], 'wikiblog');
117         if ($blogs) {
118             if (!$basepage) $basepage = _("BlogArchives");
119             $html = HTML::ul();
120             usort($blogs, array("WikiPlugin_WikiBlog", "cmp"));
121             if ($args['order'] == 'reverse')
122                 $blogs = array_reverse($blogs);
123             // collapse pagenames by month
124             $months = array();
125             foreach ($blogs as $rev) {
126                 $blog = $this->_blog($rev);
127                 $mon = $blog['month'];
128                 if (empty($months[$mon]))
129                     $months[$mon] = 
130                         array('title' => $this->_monthTitle($mon),
131                               'num'   => 1,
132                               'month' => $mon,
133                               'link'  => WikiURL($basepage, 
134                                          $this->_nonDefaultArgs(array('month' => $mon))));
135                 else
136                     $months[$mon]['num']++;
137             }
138             foreach ($months as $m) {
139                 $html->pushContent(HTML::a(array('href'=>$m['link'],
140                                                  'class' => 'named-wiki'),
141                                            $m['title'] . " (".$m['num'].")"));
142             }
143             if (!$args['noheader'])
144                 return HTML(HTML::h3(_("Blog Archives:")), $html);
145             else
146                 return $html;
147         } else 
148             return '';
149     }
150
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));
157     }
158 };
159
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.
164 //
165
166 // Local Variables:
167 // mode: php
168 // tab-width: 8
169 // c-basic-offset: 4
170 // c-hanging-comment-ender-p: nil
171 // indent-tabs-mode: nil
172 // End:
173 ?>