]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiForum.php
Whitespace only
[SourceForge/phpwiki.git] / lib / plugin / WikiForum.php
1 <?php
2
3 /*
4  * Copyright 2004 $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 /**
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  *   <<WikiForum>>
29  *
30  * To provide information for the MainForum page (CategoryForum)
31  * summary output mode is possible.
32  *
33  *   <<WikiForum page=SubTopic1 mode=summary info=title,numposts,ctime,author >>
34  *   <<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 getDefaultArguments() {
60         return array('pagename'   => '[pagename]',
61                      'order'      => 'normal',   // oldest first
62                      'mode'       => 'show,add', // 'summary',
63                      'info'       => '',
64                      'noheader'   => false
65                     );
66     }
67
68     function run($dbi, $argstr, &$request, $basepage) {
69         $args = $this->getArgs($argstr, $request);
70         if (!$args['pagename']) {
71             return $this->error(sprintf(_("A required argument '%s' is missing."), 'pagename'));
72         }
73
74         // Get our form args.
75         $forum = $request->getArg('forum');
76         $request->setArg('forum', false);
77
78         if ($request->isPost() and !empty($forum['add'])) {
79             return $this->add($request, $forum, 'wikiforum');
80         }
81
82         // Now we display previous comments and/or provide entry box
83         // for new comments
84         $html = HTML();
85         foreach (explode(',', $args['mode']) as $show) {
86             if (!empty($seen[$show]))
87                 continue;
88             $seen[$show] = 1;
89
90             switch ($show) {
91             case 'summary': // main page: list of all titles
92                 $html->pushContent($this->showTopics($request, $args));
93                 break;
94             case 'show':    // list of all contents
95                 $html->pushContent($this->showAll($request, $args, 'wikiforum'));
96                 break;
97             case 'add':     // add to or create a new thread
98                 $html->pushContent($this->showForm($request, $args, 'forumadd'));
99                 break;
100             default:
101                 return $this->error(sprintf("Bad mode ('%s')", $show));
102             }
103         }
104         // FIXME: on empty showTopics() and mode!=add and mode!=summary provide a showForm() here.
105         return $html;
106     }
107
108     // Table of titles(subpages) without content
109     // TODO: use $args['info']
110     function showTopics($request, $args) {
111         global $WikiTheme;
112
113         $dbi = $request->getDbh();
114         $topics = $this->findBlogs($dbi, $args['pagename'], 'wikiforum');
115         $html = HTML::table(array('border'=>0));
116         $row = HTML::tr(HTML::th('title'),
117                         HTML::th('last post'),
118                         HTML::th('author'));
119         $html->pushContent($row);
120         foreach ($topics as $rev) {
121             //TODO: get numposts, number of replies
122             $meta = $rev->get('wikiforum');
123             // format as list, not as wikiforum content
124             $page = new WikiPageName($rev,$args['pagename']);
125             $row = HTML::tr(HTML::td(WikiLink($page,'if_known',$rev->get('summary'))),
126                             HTML::td($WikiTheme->formatDateTime($meta['ctime'])),
127                             HTML::td(WikiLink($meta['creator'],'if_known')));
128             $html->pushContent($row);
129         }
130         return $html;
131     }
132 };
133
134 // Local Variables:
135 // mode: php
136 // tab-width: 8
137 // c-basic-offset: 4
138 // c-hanging-comment-ender-p: nil
139 // indent-tabs-mode: nil
140 // End: