]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AddComment.php
No underscore for private function
[SourceForge/phpwiki.git] / lib / plugin / AddComment.php
1 <?php
2
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 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 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     {
40         return _("AddComment");
41     }
42
43     function getDescription()
44     {
45         return sprintf(_("Show and add comments for %s."), '[pagename]');
46     }
47
48     // Arguments:
49     //
50     //  page - page where the comment is attached at (default current page)
51     //
52     //  order - 'normal'  - place in chronological order
53     //        - 'reverse' - place in reverse chronological order
54     //
55     //  mode - 'show'     - only show old comments
56     //         'add'      - only show entry box for new comment
57     //         'show,add' - show old comments, then entry box
58     //         'add,show' - show entry box followed by list of comments
59     //  jshide - boolean  - quick javascript expansion of the comments
60     //                      and addcomment box
61
62     function getDefaultArguments()
63     {
64         return array('pagename' => '[pagename]',
65             'order' => 'normal',
66             'mode' => 'add,show',
67             'jshide' => '0',
68             'noheader' => false,
69             //'sortby'     => '-pagename' // oldest first. reverse by order=reverse
70         );
71     }
72
73     function run($dbi, $argstr, &$request, $basepage)
74     {
75         $args = $this->getArgs($argstr, $request);
76         if (!$args['pagename']) {
77             return $this->error(sprintf(_("A required argument ā€œ%sā€ is missing."), 'pagename'));
78         }
79
80         // Get our form args.
81         $comment = $request->getArg("comment");
82         $request->setArg('comment', false);
83
84         if ($request->isPost() and !empty($comment['addcomment'])) {
85             $this->add($request, $comment, 'comment'); // noreturn
86         }
87
88         // Now we display previous comments and/or provide entry box
89         // for new comments
90         $html = HTML();
91         if ($args['jshide']) {
92             $div = HTML::div(array('id' => 'comments', 'style' => 'display:none;'));
93             //$list->setAttr('style','display:none;');
94             $div->pushContent(Javascript("
95 function togglecomments(a) {
96   comments=document.getElementById('comments');
97   if (comments.style.display=='none') {
98     comments.style.display='block';
99     a.title='" . _("Click to hide the comments") . "';
100   } else {
101     comments.style.display='none';
102     a.title='" . _("Click to display all comments") . "';
103   }
104 }"));
105             $html->pushContent(HTML::h4(HTML::a(array('name' => 'comment-header',
106                     'class' => 'wikiaction',
107                     'title' => _("Click to display"),
108                     'onclick' => "togglecomments(this)"),
109                 _("Comments"))));
110         } else {
111             $div = HTML::div(array('id' => 'comments'));
112         }
113         foreach (explode(',', $args['mode']) as $show) {
114             if (!empty($seen[$show]))
115                 continue;
116             $seen[$show] = 1;
117             switch ($show) {
118                 case 'show':
119                     $show = $this->showAll($request, $args, 'comment');
120                     //if ($args['jshide']) $show->setAttr('style','display:none;');
121                     $div->pushContent($show);
122                     break;
123                 case 'add':
124                     global $WikiTheme;
125                     if (!$WikiTheme->DUMP_MODE) {
126                         $add = $this->showForm($request, $args, 'addcomment');
127                         //if ($args['jshide']) $add->setAttr('style','display:none;');
128                         $div->pushContent($add);
129                     }
130                     break;
131                 default:
132                     return $this->error(sprintf("Bad mode (ā€œ%sā€)", $show));
133             }
134         }
135         $html->pushContent($div);
136         return $html;
137     }
138
139 }
140
141 // Local Variables:
142 // mode: php
143 // tab-width: 8
144 // c-basic-offset: 4
145 // c-hanging-comment-ender-p: nil
146 // indent-tabs-mode: nil
147 // End: