]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/BlogArchives.php
private --> protected
[SourceForge/phpwiki.git] / lib / plugin / BlogArchives.php
1 <?php
2
3 /*
4  * Copyright (C) 2004 $ThePhpWikiProgrammingTeam
5  *
6  * This file is part of PhpWiki.
7  *
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 require_once 'lib/plugin/WikiBlog.php';
24
25 /**
26  * BlogArchives - List monthly links for the current users blog if signed,
27  * or the ADMIN_USER's Blog if not.
28  * On month=... list the blog titles per month.
29  *
30  * TODO: year=
31  *       support PageList (paging, limit, info filters: title, num, month, year, ...)
32  *       leave off time subpage? Blogs just per day with one summary title only?
33  * @author: Reini Urban
34  */
35 class WikiPlugin_BlogArchives
36     extends WikiPlugin_WikiBlog
37 {
38     function getName()
39     {
40         return _("Archives");
41     }
42
43     function getDescription()
44     {
45         return _("List blog months links for the current or ADMIN user.");
46     }
47
48     function getDefaultArguments()
49     {
50         return //array_merge
51             //(
52             //PageList::supportedArgs(),
53             array('user' => '',
54                 'order' => 'reverse', // latest first
55                 'info' => 'month,numpages', // ignored
56                 'month' => false,
57                 'noheader' => 0
58             );
59     }
60
61     function run($dbi, $argstr, &$request, $basepage)
62     {
63         if (is_array($argstr)) { // can do with array also.
64             $args =& $argstr;
65             if (!isset($args['order'])) $args['order'] = 'reverse';
66         } else {
67             $args = $this->getArgs($argstr, $request);
68         }
69         if (empty($args['user'])) {
70             $user = $request->getUser();
71             if ($user->isAuthenticated()) {
72                 $args['user'] = $user->UserName();
73             } else {
74                 $args['user'] = '';
75             }
76         }
77         if (!$args['user'] or $args['user'] == ADMIN_USER) {
78             if (BLOG_DEFAULT_EMPTY_PREFIX)
79                 $args['user'] = ''; // "Blogs/day" pages
80             else
81                 $args['user'] = ADMIN_USER; // "Admin/Blogs/day" pages
82         }
83         $parent = (empty($args['user']) ? '' : $args['user'] . SUBPAGE_SEPARATOR);
84
85         //$info = explode(',', $args['info']);
86         //$pagelist = new PageList($args['info'], $args['exclude'], $args);
87         //if (!is_array('pagename'), explode(',', $info))
88         //    unset($pagelist->_columns['pagename']);
89
90         if (!empty($args['month'])) {
91             $prefix = $parent . $this->blogPrefix('wikiblog') . SUBPAGE_SEPARATOR . $args['month'];
92             $pages = $dbi->titleSearch(new TextSearchQuery("^" . $prefix, true, 'posix'));
93             $html = HTML::ul();
94             while ($page = $pages->next()) {
95                 $rev = $page->getCurrentRevision(false);
96                 if ($rev->get('pagetype') != 'wikiblog') continue;
97                 $blog = $this->_blog($rev);
98                 $html->pushContent(HTML::li(WikiLink($page, 'known', $rev->get('summary'))));
99             }
100             if (!$args['noheader'])
101                 return HTML(HTML::h3(sprintf(_("Blog Entries for %s:"), $this->monthTitle($args['month']))),
102                     $html);
103             else
104                 return $html;
105         }
106
107         $blogs = $this->findBlogs($dbi, $args['user'], 'wikiblog');
108         if ($blogs) {
109             if (!$basepage) $basepage = _("BlogArchives");
110             $html = HTML::ul();
111             usort($blogs, array("WikiPlugin_WikiBlog", "cmp"));
112             if ($args['order'] == 'reverse')
113                 $blogs = array_reverse($blogs);
114             // collapse pagenames by month
115             $months = array();
116             foreach ($blogs as $rev) {
117                 $blog = $this->_blog($rev);
118                 $mon = $blog['month'];
119                 if (empty($months[$mon]))
120                     $months[$mon] =
121                         array('title' => $this->monthTitle($mon),
122                             'num' => 1,
123                             'month' => $mon,
124                             'link' => WikiURL($basepage,
125                                 $this->nonDefaultArgs(array('month' => $mon))));
126                 else
127                     $months[$mon]['num']++;
128             }
129             foreach ($months as $m) {
130                 $html->pushContent(HTML::li(HTML::a(array('href' => $m['link'],
131                         'class' => 'named-wiki'),
132                     $m['title'] . " (" . $m['num'] . ")")));
133             }
134             if (!$args['noheader'])
135                 return HTML(HTML::h3(_("Blog Archives:")), $html);
136             else
137                 return $html;
138         } else
139             return '';
140     }
141
142     // box is used to display a fixed-width, narrow version with common header
143     function box($args = false, $request = false, $basepage = false)
144     {
145         if (!$request) $request =& $GLOBALS['request'];
146         if (!$args or empty($args['limit'])) $args['limit'] = 10;
147         $args['noheader'] = 1;
148         return $this->makeBox(_("Archives"), $this->run($request->_dbi, $args, $request, $basepage));
149     }
150 }
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: