]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AddComment.php
Harmonize file footer
[SourceForge/phpwiki.git] / lib / plugin / AddComment.php
1 <?php // -*-php-*-
2 // rcs_id('$Id$');
3 /*
4  * Copyright (C) 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
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 allows user comments attached to a page, similar to WikiBlog.
25  * Based on WikiBlog, no summary.
26  *
27  * TODO:
28  * For admin user, put checkboxes beside comments to allow for bulk removal.
29  *
30  * @author: ReiniUrban
31  */
32
33 include_once("lib/plugin/WikiBlog.php");
34
35 class WikiPlugin_AddComment
36 extends WikiPlugin_WikiBlog
37 {
38     function getName () {
39         return _("AddComment");
40     }
41
42     function getDescription () {
43         return sprintf(_("Show and add comments for %s"),'[pagename]');
44     }
45
46     // Arguments:
47     //
48     //  page - page where the comment is attached at (default current page)
49     //
50     //  order - 'normal'  - place in chronological order
51     //        - 'reverse' - place in reverse chronological order
52     //
53     //  mode - 'show'     - only show old comments
54     //         'add'      - only show entry box for new comment
55     //         'show,add' - show old comments, then entry box
56     //         'add,show' - show entry box followed by list of comments
57     //  jshide - boolean  - quick javascript expansion of the comments
58     //                      and addcomment box
59
60     function getDefaultArguments() {
61         return array('pagename'   => '[pagename]',
62                      'order'      => 'normal',
63                      'mode'       => 'add,show',
64                      'jshide'     => '0',
65                      'noheader'   => false,
66                      //'sortby'     => '-pagename' // oldest first. reverse by order=reverse
67                     );
68     }
69
70     function run($dbi, $argstr, &$request, $basepage) {
71         $args = $this->getArgs($argstr, $request);
72         if (!$args['pagename'])
73             return $this->error(_("No pagename specified"));
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:
147 ?>