source: branches/plugins/CommentModeration.jplug.php @ 1800

Revision 1800, 4.2 KB checked in by robertb, 3 years ago (diff)

appendText() ist die bessere Methode dafuer

Line 
1<?php
2/**
3 * @name:        CommentModeration <http://jeenaparadies.net/projects/jlog/wiki/plugins/CommentModeration>
4 * @author:      Robert Bienert <robertbienert@gmx.net>
5 * @version:     0.3
6 * @date:        2009-01-25
7 *
8 * Mit diesem Plugin landen alle neuen Kommentare erst einmal in der
9 * Moderationswarteschlange und muessen vom Administrator genehmigt
10 * werden.
11 *
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 * Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
25 */
26
27define('COMMENT_MOD_KEY', 'inModeration');
28
29class CommentModeration extends JlogPlugin {
30        var $commSid;   // zwischengespeicherte Session-ID
31        var $nWaiting;  // Anzahl wartender Kommentare
32
33        // Ausgabe des Hinweises auf die Moderation
34        function hook_commentForm($form) {
35                return str_replace('<p class=\'xmp\'>',
36                        '<p><em>&#8230; wird moderiert</em></p><p class=\'xmp\'>',
37                        $form);
38        }
39
40        // Vor dem Speichern eines neuen Kommentars
41        function hook_newComment($form) {
42                // Idee vom AkismetPlugin: neuer Typ 'inModeration':
43                $form['type'] = COMMENT_MOD_KEY;
44
45                // Session-ID zwischenspeichern fuer die Anzeige
46                $this->commSid = $form['sid'];
47
48                return $form;
49        }
50
51        // Kommentare in der Warteschlange werden nicht angezeigt.
52        function hook_showComment($comment, $data, $nr) {
53                if (COMMENT_MOD_KEY == $data['type']) {
54                        ++$this->nWaiting;
55
56                        if ($this->commSid != $data['sid'])
57                                return NULL;
58
59                        $comment .= '<p><em>Dein Kommentar wird moderiert.</em></p>';
60                }
61
62                return $comment;
63        }
64
65        // TODO: Was macht diese Methode genau?
66        function hook_countComments($com) {
67                $q = new Query('SELECT reference, COUNT(*) as count FROM ' .
68                        JLOG_DB_COMMENTS . ' WHERE type <> \'pingback\' ' .
69                        'AND type <> \''. COMMENT_MOD_KEY .
70                        '\' GROUP BY reference');
71
72                if($q->error()) {
73                        echo "<pre>\n";
74                        echo $comments->getError();
75                        echo "</pre>\n";
76                        die();
77                }
78
79                $com = array();
80
81                while($c = $q->fetch())
82                        $com[$c['reference']] = $c['count'];
83
84                return $com;
85        }
86
87        /* Biete in der Mail an den Admin einen Direktlink zum Genehmigen
88         * des Kommentars an.
89         */
90        function hook_adminMail($mail, $blogentry, $id) {
91                $mail->appendText("\n\nKommentar genehmigen\n" .
92                        JLOG_PATH .
93                        '/admin/plugin.php?jplug=CommentModeration&allow=' .
94                        $id);
95
96                return $mail;
97        }
98
99        /*
100        function hook_commentorMail($mail, $blog) {
101                if ($this->commSid)
102                        $mail['nomail'] = TRUE;
103
104                return $mail;
105        }
106        */
107
108        // Anzeige aller Kommentare im Admin-Center:
109        function hook_commentAdminList($comment, $data) {
110                global $l;
111
112                if (COMMENT_MOD_KEY == $data['type'])
113                        return str_replace('/img/JLOG_edit.png\' alt=\'' .
114                                $l['admin']['change'] . '\' /></a>',
115                        '/img/JLOG_edit.png\' alt=\'' .
116                                $l['admin']['change'] .
117                                '\' /></a> <a title="in der Moderation" href="plugin.php?jplug=CommentModeration&amp;allow='.$data['id'].'">Genehmigen</a>',
118                        $comment);
119
120                return $comment;
121        }
122
123        function hook_adminContent($html) {
124                if (isset($_GET['allow'])) {
125                        $id = mysql_real_escape_string($_GET['allow']);
126
127                        $q = new Query('UPDATE ' . JLOG_DB_COMMENTS .
128                                ' SET type=\'\' WHERE id=\''. $id . '\'');
129
130                        global $categories;
131                        global $bbcode;
132                        global $plugins;
133
134                        include(JLOG_BASEPATH . 'scripts' .
135                                DIRECTORY_SEPARATOR . 'update.php');
136
137                        return '<p>Kommentar #' .
138                                htmlspecialchars($_GET['allow']) .
139                                ' genehmigt.</p>';
140                }
141
142                return <<<EOF
143<p>Version 0.3</p>
144<p>Copyright &#169; 2008, 2009 Robert Bienert, <a href="http://jeenaparadies.net/projects/jlog/wiki/plugins/CommentModeration">Jlog-Plugin CommentModeration</a></p>
145<p>Mit diesem Plugin werden alle neuen Kommentare in die Moderation eingestellt und nicht angezeigt. Aus dem Admin-Center heraus k&#246;nnen die Kommentare dann genehmigt oder gel&#246;scht werden.</p>
146EOF;
147        }
148}
Note: See TracBrowser for help on using the repository browser.