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