| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * @name: CommentModeration <http://jeenaparadies.net/projects/jlog/wiki/plugins/CommentModeration> |
|---|
| 4 | * @author: Robert Bienert <robertbienert@gmx.net> |
|---|
| 5 | * @version: 0.2 |
|---|
| 6 | * @date: 2008-12-29 |
|---|
| 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 | |
|---|
| 27 | define('COMMENT_MOD_KEY', 'inModeration'); |
|---|
| 28 | |
|---|
| 29 | class 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>… 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) { |
|---|
| 91 | $trashURL = '/admin/comments.php?action=trash&id='; |
|---|
| 92 | $matches = array(); |
|---|
| 93 | |
|---|
| 94 | if (($pos = strrpos($mail['text'], $trashURL)) !== FALSE) |
|---|
| 95 | { |
|---|
| 96 | $rest = substr($mail['text'], $pos); |
|---|
| 97 | |
|---|
| 98 | if (preg_match('/([0-9]+)/', $rest, $matches)) |
|---|
| 99 | $mail['text'] .= "\n\nKommentar genehmigen\n" . |
|---|
| 100 | JLOG_PATH . '/admin/plugin.php?jplug=CommentModeration&allow=' . |
|---|
| 101 | $matches[0]; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | return $mail; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | /* |
|---|
| 108 | function hook_commentorMail($mail, $blog) { |
|---|
| 109 | if ($this->commSid) |
|---|
| 110 | $mail['nomail'] = TRUE; |
|---|
| 111 | |
|---|
| 112 | return $mail; |
|---|
| 113 | } |
|---|
| 114 | */ |
|---|
| 115 | |
|---|
| 116 | // Anzeige aller Kommentare im Admin-Center: |
|---|
| 117 | function hook_commentAdminList($comment, $data) { |
|---|
| 118 | global $l; |
|---|
| 119 | |
|---|
| 120 | if (COMMENT_MOD_KEY == $data['type']) |
|---|
| 121 | return str_replace('/img/JLOG_edit.png\' alt=\'' . |
|---|
| 122 | $l['admin']['change'] . '\' /></a>', |
|---|
| 123 | '/img/JLOG_edit.png\' alt=\'' . |
|---|
| 124 | $l['admin']['change'] . |
|---|
| 125 | '\' /></a> <a title="in der Moderation" href="plugin.php?jplug=CommentModeration&allow='.$data['id'].'">Genehmigen</a>', |
|---|
| 126 | $comment); |
|---|
| 127 | |
|---|
| 128 | return $comment; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | function hook_adminContent($html) { |
|---|
| 132 | if (isset($_GET['allow'])) { |
|---|
| 133 | $id = mysql_real_escape_string($_GET['allow']); |
|---|
| 134 | |
|---|
| 135 | $q = new Query('UPDATE ' . JLOG_DB_COMMENTS . |
|---|
| 136 | ' SET type=\'\' WHERE id=\''. $id . '\''); |
|---|
| 137 | |
|---|
| 138 | global $categories; |
|---|
| 139 | global $bbcode; |
|---|
| 140 | global $plugins; |
|---|
| 141 | |
|---|
| 142 | include(JLOG_BASEPATH . 'scripts' . |
|---|
| 143 | DIRECTORY_SEPARATOR . 'update.php'); |
|---|
| 144 | |
|---|
| 145 | return '<p>Kommentar #' . |
|---|
| 146 | htmlspecialchars($_GET['allow']) . |
|---|
| 147 | ' genehmigt.</p>'; |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | return <<<EOF |
|---|
| 151 | <p>Version 0.2</p> |
|---|
| 152 | <p>Copyright © 2008 Robert Bienert, <a href="http://jeenaparadies.net/projects/jlog/wiki/plugins/CommentModeration">Jlog-Plugin CommentModeration</a></p> |
|---|
| 153 | <p>Mit diesem Plugin werden alle neuen Kommentare in die Moderation eingestellt und nicht angezeigt. Aus dem Admin-Center heraus können die Kommentare dann genehmigt oder gelöscht werden.</p> |
|---|
| 154 | EOF; |
|---|
| 155 | } |
|---|
| 156 | } |
|---|