]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/BlogArchives.php
Activated Id substitution for Subversion
[SourceForge/phpwiki.git] / lib / plugin / BlogArchives.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
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.6 $");
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     function run($dbi, $argstr, &$request, $basepage) {
49         if (is_array($argstr)) { // can do with array also.
50             $args =& $argstr;
51             if (!isset($args['order'])) $args['order'] = 'reverse';
52         } else {
53             $args = $this->getArgs($argstr, $request);
54         }
55         if (empty($args['user'])) {
56             $user = $request->getUser();
57             if ($user->isAuthenticated()) {
58                 $args['user'] = $user->UserName();
59             } else {
60                 $args['user'] = '';
61             }
62         }
63         if (!$args['user'] or $args['user'] == ADMIN_USER) {
64             if (BLOG_DEFAULT_EMPTY_PREFIX)
65                 $args['user'] = '';         // "Blogs/day" pages 
66             else
67                 $args['user'] = ADMIN_USER; // "Admin/Blogs/day" pages 
68         }
69         $parent = (empty($args['user']) ? '' : $args['user'] . SUBPAGE_SEPARATOR);
70
71         //$info = explode(',', $args['info']);
72         //$pagelist = new PageList($args['info'], $args['exclude'], $args);
73         //if (!is_array('pagename'), explode(',', $info))
74         //    unset($pagelist->_columns['pagename']);
75         
76         $sp = HTML::Raw('&middot; ');
77         if (!empty($args['month'])) {
78             $prefix = $parent . $this->_blogPrefix('wikiblog') . SUBPAGE_SEPARATOR . $args['month'];
79             $pages = $dbi->titleSearch(new TextSearchQuery("^".$prefix, true, 'posix'));
80             $html = HTML::ul();
81             while ($page = $pages->next()) {
82                 $rev = $page->getCurrentRevision(false);
83                 if ($rev->get('pagetype') != 'wikiblog') continue;
84                 $blog = $this->_blog($rev);
85                 $html->pushContent(HTML::li(WikiLink($page, 'known', $rev->get('summary'))));
86             }
87             if (!$args['noheader'])
88                 return HTML(HTML::h3(sprintf(_("Blog Entries for %s:"), $this->_monthTitle($args['month']))),
89                            $html);
90             else
91                 return $html;
92         }
93
94         $blogs = $this->findBlogs ($dbi, $args['user'], 'wikiblog');
95         if ($blogs) {
96             if (!$basepage) $basepage = _("BlogArchives");
97             $html = HTML::ul();
98             usort($blogs, array("WikiPlugin_WikiBlog", "cmp"));
99             if ($args['order'] == 'reverse')
100                 $blogs = array_reverse($blogs);
101             // collapse pagenames by month
102             $months = array();
103             foreach ($blogs as $rev) {
104                 $blog = $this->_blog($rev);
105                 $mon = $blog['month'];
106                 if (empty($months[$mon]))
107                     $months[$mon] = 
108                         array('title' => $this->_monthTitle($mon),
109                               'num'   => 1,
110                               'month' => $mon,
111                               'link'  => WikiURL($basepage, 
112                                          $this->_nonDefaultArgs(array('month' => $mon))));
113                 else
114                     $months[$mon]['num']++;
115             }
116             foreach ($months as $m) {
117                 $html->pushContent(HTML::li(HTML::a(array('href'=>$m['link'],
118                                                           'class' => 'named-wiki'),
119                                                     $m['title'] . " (".$m['num'].")")));
120             }
121             if (!$args['noheader'])
122                 return HTML(HTML::h3(_("Blog Archives:")), $html);
123             else
124                 return $html;
125         } else 
126             return '';
127     }
128
129     // box is used to display a fixed-width, narrow version with common header
130     function box($args=false, $request=false, $basepage=false) {
131         if (!$request) $request =& $GLOBALS['request'];
132         if (!$args or empty($args['limit'])) $args['limit'] = 10;
133         $args['noheader'] = 1;
134         return $this->makeBox(_("Archives"), $this->run($request->_dbi, $args, $request, $basepage));
135     }
136 };
137
138 // $Log: not supported by cvs2svn $
139 // Revision 1.5  2005/10/29 09:06:37  rurban
140 // move common blog methods to WikiBlog
141 //
142 // Revision 1.4  2004/12/16 18:29:00  rurban
143 // allow empty Blog prefix
144 //
145 // Revision 1.3  2004/12/15 17:45:08  rurban
146 // fix box method
147 //
148 // Revision 1.2  2004/12/14 21:35:15  rurban
149 // support new BLOG_EMPTY_DEFAULT_PREFIX
150 //
151 // Revision 1.1  2004/12/13 13:22:57  rurban
152 // new BlogArchives plugin for the new blog theme. enable default box method
153 // for all plugins. Minor search improvement.
154 //
155
156 // Local Variables:
157 // mode: php
158 // tab-width: 8
159 // c-basic-offset: 4
160 // c-hanging-comment-ender-p: nil
161 // indent-tabs-mode: nil
162 // End:
163 ?>