]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AddComment.php
include [all] Include and file path should be devided with single space. File path...
[SourceForge/phpwiki.git] / lib / plugin / AddComment.php
1 <?php // -*-php-*-
2 /*
3  * Copyright (C) 2004 $ThePhpWikiProgrammingTeam
4  *
5  * This file is part of PhpWiki.
6  *
7  * PhpWiki is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * PhpWiki is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 /**
23  * This plugin allows user comments attached to a page, similar to WikiBlog.
24  * Based on WikiBlog, no summary.
25  *
26  * TODO:
27  * For admin user, put checkboxes beside comments to allow for bulk removal.
28  *
29  * @author: ReiniUrban
30  */
31
32 include_once 'lib/plugin/WikiBlog.php';
33
34 class WikiPlugin_AddComment
35 extends WikiPlugin_WikiBlog
36 {
37     function getName () {
38         return _("AddComment");
39     }
40
41     function getDescription () {
42         return sprintf(_("Show and add comments for %s"),'[pagename]');
43     }
44
45     // Arguments:
46     //
47     //  page - page where the comment is attached at (default current page)
48     //
49     //  order - 'normal'  - place in chronological order
50     //        - 'reverse' - place in reverse chronological order
51     //
52     //  mode - 'show'     - only show old comments
53     //         'add'      - only show entry box for new comment
54     //         'show,add' - show old comments, then entry box
55     //         'add,show' - show entry box followed by list of comments
56     //  jshide - boolean  - quick javascript expansion of the comments
57     //                      and addcomment box
58
59     function getDefaultArguments() {
60         return array('pagename'   => '[pagename]',
61                      'order'      => 'normal',
62                      'mode'       => 'add,show',
63                      'jshide'     => '0',
64                      'noheader'   => false,
65                      //'sortby'     => '-pagename' // oldest first. reverse by order=reverse
66                     );
67     }
68
69     function run($dbi, $argstr, &$request, $basepage) {
70         $args = $this->getArgs($argstr, $request);
71         if (!$args['pagename']) {
72             return $this->error(sprintf(_("A required argument '%s' is missing."), 'pagename'));
73         }
74
75         // Get our form args.
76         $comment = $request->getArg("comment");
77         $request->setArg('comment', false);
78
79         if ($request->isPost() and !empty($comment['addcomment'])) {
80             $this->add($request, $comment, 'comment'); // noreturn
81         }
82         if ($args['jshide'] and isBrowserIE() and browserDetect("Mac")) {
83             //trigger_error(_("jshide set to 0 on Mac IE"), E_USER_NOTICE);
84             $args['jshide'] = 0;
85         }
86
87         // Now we display previous comments and/or provide entry box
88         // for new comments
89         $html = HTML();
90         if ($args['jshide']) {
91             $div = HTML::div(array('id'=>'comments','style'=>'display:none;'));
92             //$list->setAttr('style','display:none;');
93             $div->pushContent(Javascript("
94 function togglecomments(a) {
95   comments=document.getElementById('comments');
96   if (comments.style.display=='none') {
97     comments.style.display='block';
98     a.title='"._("Click to hide the comments")."';
99   } else {
100     comments.style.display='none';
101     a.title='"._("Click to display all comments")."';
102   }
103 }"));
104             $html->pushContent(HTML::h4(HTML::a(array('name'=>'comment-header',
105                                                       'class'=>'wikiaction',
106                                                       'title'=>_("Click to display"),
107                                                       'onclick'=>"togglecomments(this)"),
108                                                 _("Comments"))));
109         } else {
110             $div = HTML::div(array('id'=>'comments'));
111         }
112         foreach (explode(',', $args['mode']) as $show) {
113             if (!empty($seen[$show]))
114                 continue;
115             $seen[$show] = 1;
116             switch ($show) {
117             case 'show':
118                 $show = $this->showAll($request, $args, 'comment');
119                 //if ($args['jshide']) $show->setAttr('style','display:none;');
120                 $div->pushContent($show);
121                 break;
122             case 'add':
123                 global $WikiTheme;
124                 if (!$WikiTheme->DUMP_MODE) {
125                     $add = $this->showForm($request, $args, 'addcomment');
126                     //if ($args['jshide']) $add->setAttr('style','display:none;');
127                     $div->pushContent($add);
128                 }
129                 break;
130             default:
131                 return $this->error(sprintf("Bad mode ('%s')", $show));
132             }
133         }
134         $html->pushContent($div);
135         return $html;
136     }
137
138 };
139
140 // Local Variables:
141 // mode: php
142 // tab-width: 8
143 // c-basic-offset: 4
144 // c-hanging-comment-ender-p: nil
145 // indent-tabs-mode: nil
146 // End: