]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiForum.php
renamed global $Theme to $WikiTheme (gforge nameclash)
[SourceForge/phpwiki.git] / lib / plugin / WikiForum.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiForum.php,v 1.3 2004-06-14 11:31:39 rurban Exp $');
3 /*
4  Copyright 2004 $ThePhpWikiProgrammingTeam
5  
6  This file is (not yet) 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 /**
24  * This plugin handles a threaded list of comments/news associated with a
25  * particular page (one page per topic) and provides an input form for 
26  * adding a new message.
27  *
28  *   <?plugin WikiForum ?>
29  *
30  * To provide information for the MainForum page (CategoryForum)
31  * summary output mode is possible.
32  *
33  *   <?plugin WikiForum page=SubTopic1 mode=summary info=title,numposts,ctime,author ?>
34  *   <?plugin WikiForum page=SubTopic2 mode=summary info=title,numposts,ctime,author ?>
35  *
36  * TODO: For admin user, put checkboxes beside comments to allow for bulk removal.
37  * threaded identation for level of reply
38  *   (probably no date, just index as pagetitle)
39  * reply link from within message (?mode=add)
40  * layout
41  * pagetype: header: link to parent, no redirects,
42  *
43  * @author: Reini Urban
44  */
45
46 include_once("lib/plugin/WikiBlog.php");
47
48 class WikiPlugin_WikiForum
49 extends WikiPlugin_WikiBlog
50 {
51     function getName () {
52         return _("WikiForum");
53     }
54
55     function getDescription () {
56         return _("Handles threaded topics with comments/news and provide a input form");
57     }
58
59     function getVersion() {
60         return preg_replace("/[Revision: $]/", '',
61                             "\$Revision: 1.3 $");
62     }
63
64     function getDefaultArguments() {
65         return array('pagename'   => '[pagename]',
66                      'order'      => 'normal',   // oldest first
67                      'mode'       => 'show,add', // 'summary',
68                      'info'       => '',
69                      'noheader'   => false
70                     );
71     }
72
73     function run($dbi, $argstr, &$request, $basepage) {
74         $args = $this->getArgs($argstr, $request);
75         if (!$args['pagename'])
76             return $this->error(_("No pagename specified"));
77
78         // Get our form args.
79         $forum = $request->getArg('forum');
80         $request->setArg('forum', false);
81
82         if ($request->isPost() and !empty($forum['add'])) {
83             return $this->add($request, $forum, 'wikiforum');
84         }
85
86         // Now we display previous comments and/or provide entry box
87         // for new comments
88         $html = HTML();
89         foreach (explode(',', $args['mode']) as $show) {
90             if (!empty($seen[$show]))
91                 continue;
92             $seen[$show] = 1;
93                 
94             switch ($show) {
95             case 'summary': // main page: list of all titles
96                 $html->pushContent($this->showTopics($request, $args));
97                 break;
98             case 'show':    // list of all contents
99                 $html->pushContent($this->showAll($request, $args, 'wikiforum'));
100                 break;
101             case 'add':     // add to or create a new thread
102                 $html->pushContent($this->showForm($request, $args, 'forumadd'));
103                 break;
104             default:
105                 return $this->error(sprintf("Bad mode ('%s')", $show));
106             }
107         }
108         // FIXME: on empty showTopics() and mode!=add and mode!=summary provide a showForm() here.
109         return $html;
110     }
111
112     // Table of titles(subpages) without content
113     // TODO: use $args['info']
114     function showTopics($request, $args) {
115         global $WikiTheme;
116
117         $dbi = $request->getDbh();
118         $topics = $this->findBlogs($dbi, $args['pagename'], 'wikiforum');
119         $html = HTML::table(array('border'=>0));
120         $row = HTML::tr(HTML::th('title'),
121                         HTML::th('last post'),
122                         HTML::th('author'));
123         $html->pushContent($row);
124         foreach ($topics as $rev) {
125             //TODO: get numposts, number of replies
126             $meta = $rev->get('wikiforum');
127             // format as list, not as wikiforum content
128             $page = new WikiPageName($rev,$args['pagename']);
129             $row = HTML::tr(HTML::td(WikiLink($page,'if_known',$rev->get('summary'))),
130                             HTML::td($WikiTheme->formatDateTime($meta['ctime'])),
131                             HTML::td(WikiLink($meta['creator'],'if_known')));
132             $html->pushContent($row);
133         }
134         return $html;
135     }
136 };
137
138 // $Log: not supported by cvs2svn $
139 // Revision 1.2  2004/04/19 18:27:46  rurban
140 // Prevent from some PHP5 warnings (ref args, no :: object init)
141 //   php5 runs now through, just one wrong XmlElement object init missing
142 // Removed unneccesary UpgradeUser lines
143 // Changed WikiLink to omit version if current (RecentChanges)
144 //
145 // Revision 1.1  2004/04/18 05:43:12  rurban
146 // .
147 //
148 //
149
150 // For emacs users
151 // Local Variables:
152 // mode: php
153 // tab-width: 8
154 // c-basic-offset: 4
155 // c-hanging-comment-ender-p: nil
156 // indent-tabs-mode: nil
157 // End:
158 ?>