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