]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/BlogJournal.php
private --> protected
[SourceForge/phpwiki.git] / lib / plugin / BlogJournal.php
1 <?php
2
3 /*
4  * Copyright (C) 2005 $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  * BlogJournal - Include the latest blog entries for the current users blog if signed,
27  *               or the ADMIN_USER's Blog if not.
28  * UnfoldSubpages for blogs.
29  * Rui called this plugin "JournalLast", but this was written completely independent,
30  * without having seen the src.
31  *
32  * @author: Reini Urban
33  */
34 class WikiPlugin_BlogJournal
35     extends WikiPlugin_WikiBlog
36 {
37     function getName()
38     {
39         return _("BlogJournal");
40     }
41
42     function getDescription()
43     {
44         return _("Include latest blog entries for the current or ADMIN user.");
45     }
46
47     function getDefaultArguments()
48     {
49         return array('count' => 7,
50             'user' => '',
51             'order' => 'reverse', // latest first
52             'month' => false,
53             'noheader' => 0
54         );
55     }
56
57     function run($dbi, $argstr, &$request, $basepage)
58     {
59         if (is_array($argstr)) { // can do with array also.
60             $args =& $argstr;
61             if (!isset($args['order'])) $args['order'] = 'reverse';
62         } else {
63             $args = $this->getArgs($argstr, $request);
64         }
65         $user = $request->getUser();
66         if (empty($args['user'])) {
67             if ($user->isAuthenticated()) {
68                 $args['user'] = $user->UserName();
69             } else {
70                 $args['user'] = '';
71             }
72         }
73         if (!$args['user'] or $args['user'] == ADMIN_USER) {
74             if (BLOG_DEFAULT_EMPTY_PREFIX) {
75                 $args['user'] = ''; // "Blogs/day" pages
76             } else {
77                 $args['user'] = ADMIN_USER; // "Admin/Blogs/day" pages
78             }
79         }
80         $parent = (empty($args['user']) ? '' : $args['user'] . SUBPAGE_SEPARATOR);
81
82         $prefix = $base = $parent . $this->blogPrefix('wikiblog');
83         if ($args['month'])
84             $prefix .= (SUBPAGE_SEPARATOR . $args['month']);
85         $pages = $dbi->titleSearch(new TextSearchQuery("^" . $prefix . SUBPAGE_SEPARATOR, true, 'posix'));
86         $html = HTML();
87         $i = 0;
88         while (($page = $pages->next()) and $i < $args['count']) {
89             $rev = $page->getCurrentRevision(false);
90             if ($rev->get('pagetype') != 'wikiblog') continue;
91             $i++;
92             $blog = $this->_blog($rev);
93             //$html->pushContent(HTML::h3(WikiLink($page, 'known', $rev->get('summary'))));
94             $html->pushContent($rev->getTransformedContent('wikiblog'));
95         }
96         if ($args['user'] == $user->UserName() or $args['user'] == '')
97             $html->pushContent(Button(array('action' => 'WikiBlog',
98                     'mode' => 'add'),
99                 _("New entry"), $base));
100         if (!$i)
101             return HTML(HTML::h3(_("No Blog Entries")), $html);
102         if (!$args['noheader'])
103             return HTML(HTML::h3(sprintf(_("Blog Entries for %s:"), $this->monthTitle($args['month']))),
104                 $html);
105         else
106             return $html;
107     }
108 }
109
110 // Local Variables:
111 // mode: php
112 // tab-width: 8
113 // c-basic-offset: 4
114 // c-hanging-comment-ender-p: nil
115 // indent-tabs-mode: nil
116 // End: