]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/BlogJournal.php
fix count error
[SourceForge/phpwiki.git] / lib / plugin / BlogJournal.php
1 <?php // -*-php-*-
2 rcs_id('$Id: BlogJournal.php,v 1.3 2005-11-21 20:47:21 rurban Exp $');
3 /*
4  * Copyright 2005 $ThePhpWikiProgrammingTeam
5  */
6
7 require_once('lib/plugin/WikiBlog.php');
8
9 /**
10  * BlogJournal - Include the latest blog entries for the current users blog if signed, 
11  *               or the ADMIN_USER's Blog if not.
12  * UnfoldSubpages for blogs.
13  * Rui called this plugin "JournalLast", but this was written completely independent, 
14  * without having seen the src.
15  *
16  * @author: Reini Urban
17  */
18 class WikiPlugin_BlogJournal
19 extends WikiPlugin_WikiBlog
20 {
21     function getName() {
22         return _("BlogJournal");
23     }
24
25     function getDescription() {
26         return _("Include latest blog entries for the current or ADMIN user");
27     }
28
29     function getVersion() {
30         return preg_replace("/[Revision: $]/", '',
31                             "\$Revision: 1.3 $");
32     }
33
34     function getDefaultArguments() {
35         return array('count'    => 7,
36                      'user'     => '',
37                      'order'    => 'reverse',        // latest first
38                      'month'    => false,
39                      'noheader' => 0
40                      );
41     }
42
43     function run($dbi, $argstr, &$request, $basepage) {
44         if (is_array($argstr)) { // can do with array also.
45             $args =& $argstr;
46             if (!isset($args['order'])) $args['order'] = 'reverse';
47         } else {
48             $args = $this->getArgs($argstr, $request);
49         }
50         $user = $request->getUser();
51         if (empty($args['user'])) {
52             if ($user->isAuthenticated()) {
53                 $args['user'] = $user->UserName();
54             } else {
55                 $args['user'] = '';
56             }
57         }
58         if (!$args['user'] or $args['user'] == ADMIN_USER) {
59             if (BLOG_EMPTY_DEFAULT_PREFIX)
60                 $args['user'] = '';         // "Blogs/day" pages 
61             else
62                 $args['user'] = ADMIN_USER; // "Admin/Blogs/day" pages 
63         }
64         $parent = (empty($args['user']) ? '' : $args['user'] . SUBPAGE_SEPARATOR);
65
66         $sp = HTML::Raw('&middot; ');
67         $prefix = $parent . $this->_blogPrefix('wikiblog');
68         if ($args['month'])
69             $prefix .= (SUBPAGE_SEPARATOR . $args['month']);
70         $pages = $dbi->titleSearch(new TextSearchQuery("^".$prefix, true, 'posix'));
71         $html = HTML(); $i = 0;
72         while (($page = $pages->next()) and $i < $args['count']) {
73             $rev = $page->getCurrentRevision(false);
74             if ($rev->get('pagetype') != 'wikiblog') continue;
75             $i++;
76             $blog = $this->_blog($rev);
77             $html->pushContent(HTML::h3(WikiLink($page, 'known', $rev->get('summary'))));
78             $html->pushContent($rev->getTransformedContent('wikiblog'));
79         }
80         if ($args['user'] == $user->UserName())
81             $html->pushContent(WikiLink(_("WikiBlog"), 'known', "New entry"));
82         if (!$i)
83             return HTML(HTML::h3(_("No Blog Entries")), $html);
84         if (!$args['noheader'])
85             return HTML(HTML::h3(sprintf(_("Blog Entries for %s:"), $this->_monthTitle($args['month']))),
86                         $html);
87         else
88             return $html;
89     }
90 };
91
92 // $Log: not supported by cvs2svn $
93 // Revision 1.2  2005/10/29 09:06:37  rurban
94 // move common blog methods to WikiBlog
95 //
96 // Revision 1.1  2005/10/29 09:03:17  rurban
97 // Include the latest blog entries for the current users blog if signed,
98 // or the ADMIN_USER's Blog if not.
99 // UnfoldSubpages for blogs.
100 // Rui called this plugin "JournalLast", but this was written completely
101 // independently, without having seen the src (yet).
102 //
103
104 // Local Variables:
105 // mode: php
106 // tab-width: 8
107 // c-basic-offset: 4
108 // c-hanging-comment-ender-p: nil
109 // indent-tabs-mode: nil
110 // End:
111 ?>