]> git.mjollnir.org Git - s9y.git/commitdiff
* Improve Spamblock plugin to allow configuring author/url filters straight...
authorgarvinhicking <garvinhicking>
Thu, 13 Oct 2005 10:55:02 +0000 (10:55 +0000)
committergarvinhicking <garvinhicking>
Thu, 13 Oct 2005 10:55:02 +0000 (10:55 +0000)
M    trunk/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php
M    trunk/plugins/serendipity_event_spamblock/lang_de.inc.php
M    trunk/plugins/serendipity_event_spamblock/UTF-8/lang_de.inc.php
M    trunk/include/admin/comments.inc.php
M    trunk/docs/NEWS
AM   trunk/templates/default/admin/img/unconfigure.png

docs/NEWS
include/admin/comments.inc.php
plugins/serendipity_event_spamblock/UTF-8/lang_de.inc.php
plugins/serendipity_event_spamblock/lang_de.inc.php
plugins/serendipity_event_spamblock/serendipity_event_spamblock.php
templates/default/admin/img/unconfigure.png [new file with mode: 0644]

index 5bdf7c91f1939c15e9e8459ab4ade429bfb86e65..0f90b1c8ba5e7151dc5bc3fd83b981acb77cdd43 100644 (file)
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -3,6 +3,9 @@
 Version 0.9-beta2 ()
 ------------------------------------------------------------------------
 
+    * Improve Spamblock plugin to allow configuring author/url filters
+      straight from the "Comments" interface. (garvinhicking)
+
     * Fix a bug in the fetchEntry() function which can lead to wrong
       author/authorid settings when editing an existing entry. Thanks to
       Martin Eichenberg! (garvinhicking)
index ee0a0632088828abd81dbb1a3dd443d5c07e8bc7..5807f5a9100bba7167813266fdb09ba2f36f5e3c 100644 (file)
@@ -248,10 +248,11 @@ function highlightComment(id, checkvalue) {
             </select></td>
     </tr>
     <tr>
-        <td colspan="6" align="right"><input type="submit" name="submit" value=" - <?php echo GO ?> - " class="serendipityPrettyButton" /></td>
+        <td colspan="6" align="right"><input type="submit" name="submit" value=" - <?php echo GO ?> - " class="serendipityPrettyButton" /> <?php serendipity_plugin_api::hook_event('backend_comments_top', $sql); ?></td>
     </tr>
 </table>
 </form>
+<hr noshade="noshade" /><br />
 <?php
     if (!is_array($sql)) {
         echo '<div align="center">- '. NO_COMMENTS .' -</div>';
@@ -328,7 +329,7 @@ foreach ($sql as $rs) {
         <table width="100%" cellspacing="0" cellpadding="3" border="0">
             <tr>
                 <td rowspan="3" width="20" align="center"><input type="checkbox" name="serendipity[delete][<?php echo $comment['id'] ?>]" value="<?php echo $comment['entry_id'] ?>" onclick="highlightComment('comment_<?php echo $comment['id'] ?>', this.checked)" tabindex="<?php echo $i ?>" /></td>
-                <td width="40%"><strong><?php echo AUTHOR ?></strong>: <?php echo htmlspecialchars($comment['author']) ?></td>
+                <td width="40%"><strong><?php echo AUTHOR ?></strong>: <?php echo htmlspecialchars($comment['author']) . $comment['action_author']; ?></td>
                 <td><strong><?php echo EMAIL ?></strong>:
                     <?php
                         if ( empty($comment['email']) ) {
@@ -336,7 +337,9 @@ foreach ($sql as $rs) {
                         } else {
                     ?>
                             <a href="mailto:<?php echo htmlspecialchars($comment['email']) ?>"><?php echo htmlspecialchars($comment['email']) ?></a>
-                    <?php } ?></td>
+                    <?php } ?>
+                <?php echo $comment['action_email']; ?>
+                </td>
             </tr>
             <tr>
                 <td width="40%"><strong>IP</strong>:
@@ -346,7 +349,9 @@ foreach ($sql as $rs) {
                         } else {
                             echo htmlspecialchars($comment['ip']);
                         }
-                    ?></td>
+                    ?>
+                    <?php echo $comment['action_ip']; ?>
+                    </td>
                 <td><strong><?php echo URL; ?></strong>:
                     <?php
                         if ( empty($comment['url']) ) {
@@ -354,7 +359,9 @@ foreach ($sql as $rs) {
                         } else {
                     ?>
                             <a href="<?php echo htmlspecialchars($comment['url']) ?>" target="_blank"><?php echo htmlspecialchars($comment['url']) ?></a>
-                    <?php } ?></td>
+                    <?php } ?>
+                    <?php echo $comment['action_url']; ?>
+                    </td>
             </tr>
             <tr>
                 <td width="40%">&nbsp;</td>
@@ -365,7 +372,9 @@ foreach ($sql as $rs) {
                         } else {
                     ?>
                           <a href="<?php echo htmlspecialchars($comment['referer']) ?>" title="<?php echo htmlspecialchars($comment['referer']) ?>"><?php echo htmlspecialchars(serendipity_truncateString($comment['referer'],30)) ?></a>
-                    <?php } ?></td>
+                    <?php } ?>
+                    <?php echo $comment['action_referer']; ?>
+                    </td>
             <tr>
                 <td style="border-top: 1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC" colspan="3">
                     <div id="<?php echo $comment['id'] ?>_summary"><?php echo $comment['summary'] ?></div>
@@ -381,10 +390,11 @@ foreach ($sql as $rs) {
 <?php } ?>
           <a href="?serendipity[action]=admin&amp;serendipity[adminModule]=comments&amp;serendipity[adminAction]=edit&amp;serendipity[id]=<?php echo $comment['id'] ?>&amp;serendipity[entry_id]=<?php echo $comment['entry_id'] ?>&amp;<?php echo serendipity_setFormToken('url'); ?>" title="<?php echo EDIT; ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/edit.png'); ?>" alt="<?php echo EDIT; ?>" /><?php echo EDIT ?></a>
           <a href="?serendipity[action]=admin&amp;serendipity[adminModule]=comments&amp;serendipity[adminAction]=delete&amp;serendipity[id]=<?php echo $comment['id'] ?>&amp;serendipity[entry_id]=<?php echo $comment['entry_id'] ?>&amp;<?php echo serendipity_setFormToken('url'); ?>" onclick='return confirm("<?php echo sprintf(COMMENT_DELETE_CONFIRM, $comment['id'], htmlspecialchars($comment['author'])) ?>")' title="<?php echo DELETE ?>" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/delete.png'); ?>" alt="<?php echo DELETE; ?>" /><?php echo DELETE ?></a>
+          <?php echo $comment['action_more']; ?>
     </td>
 </tr>
 <tr>
-    <td><hr noshade="noshade"></td>
+    <td><hr noshade="noshade" /></td>
 </tr>
 <?php } ?>
 <tr>
index 8a52ad9cb0faee69f6f53204d30c68183efd013d..e85c80027232f943753c891c29a244b2a82f0ca4 100644 (file)
 
         @define('PLUGIN_EVENT_SPAMBLOCK_REASON_CHECKMAIL', 'Ungültige E-Mail Adresse');
         @define('PLUGIN_EVENT_SPAMBLOCK_CHECKMAIL', 'Auf ungültige E-Mail Adressen prüfen?');
+        @define('PLUGIN_EVENT_SPAMBLOCK_REQUIRED_FIELDS', 'Pflichtfelder');
+        @define('PLUGIN_EVENT_SPAMBLOCK_REQUIRED_FIELDS_DESC', 'Geben Sie die Liste von Pflichtfeldern bei der Abgabe eines Kommentares ein. Mehrere Felder können mit "," getrennt werden. Verfügbare Felder sind: name, email, url, replyTo, comment');
+        @define('PLUGIN_EVENT_SPAMBLOCK_REASON_REQUIRED_FIELD', 'Sie haben das Feld %s nicht ausgefüllt!');
+        
+        @define('PLUGIN_EVENT_SPAMBLOCK_CONFIG', 'Anti-Spam-Maßnahmen konfigurieren');
+        @define('PLUGIN_EVENT_SPAMBLOCK_ADD_AUTHOR', 'Diesen Autoren via Spamschutz blockieren');
+        @define('PLUGIN_EVENT_SPAMBLOCK_ADD_URL', 'Diese URL via Spamschutz blockieren');
+        @define('PLUGIN_EVENT_SPAMBLOCK_REMOVE_AUTHOR', 'Blockade dieses Autoren via Spamschutz aufheben');
+        @define('PLUGIN_EVENT_SPAMBLOCK_REMOVE_URL', 'Blockade dieser URL via Spamschutz aufheben');
index 466380410467cb655ce81a1e5e52533ce3ed4785..78062e6e3e57fce9582546d751e13569b9a560f5 100644 (file)
 
         @define('PLUGIN_EVENT_SPAMBLOCK_REASON_CHECKMAIL', 'Ungültige E-Mail Adresse');
         @define('PLUGIN_EVENT_SPAMBLOCK_CHECKMAIL', 'Auf ungültige E-Mail Adressen prüfen?');
+        @define('PLUGIN_EVENT_SPAMBLOCK_REQUIRED_FIELDS', 'Pflichtfelder');
+        @define('PLUGIN_EVENT_SPAMBLOCK_REQUIRED_FIELDS_DESC', 'Geben Sie die Liste von Pflichtfeldern bei der Abgabe eines Kommentares ein. Mehrere Felder können mit "," getrennt werden. Verfügbare Felder sind: name, email, url, replyTo, comment');
+        @define('PLUGIN_EVENT_SPAMBLOCK_REASON_REQUIRED_FIELD', 'Sie haben das Feld %s nicht ausgefüllt!');
+        
+        @define('PLUGIN_EVENT_SPAMBLOCK_CONFIG', 'Anti-Spam-Maßnahmen konfigurieren');
+        @define('PLUGIN_EVENT_SPAMBLOCK_ADD_AUTHOR', 'Diesen Autoren via Spamschutz blockieren');
+        @define('PLUGIN_EVENT_SPAMBLOCK_ADD_URL', 'Diese URL via Spamschutz blockieren');
+        @define('PLUGIN_EVENT_SPAMBLOCK_REMOVE_AUTHOR', 'Blockade dieses Autoren via Spamschutz aufheben');
+        @define('PLUGIN_EVENT_SPAMBLOCK_REMOVE_URL', 'Blockade dieser URL via Spamschutz aufheben');
index 3b8ba0ee91002c8fdff8896475bff06e6635c1ea..a5bca5a0e658f74c07685087508760849b4c4590 100644 (file)
@@ -86,6 +86,12 @@ if (!function_exists('serendipity_serverOffsetHour')) {
 @define('PLUGIN_EVENT_SPAMBLOCK_REQUIRED_FIELDS_DESC', 'Enter a list of required fields that need to be filled when a user comments. Seperate multiple fields with a ",". Available keys are: name, email, url, replyTo, comment');
 @define('PLUGIN_EVENT_SPAMBLOCK_REASON_REQUIRED_FIELD', 'You did not specify the %s field!');
 
+@define('PLUGIN_EVENT_SPAMBLOCK_CONFIG', 'Configure Anti-Spam methods');
+@define('PLUGIN_EVENT_SPAMBLOCK_ADD_AUTHOR', 'Block this author via Spamblock plugin');
+@define('PLUGIN_EVENT_SPAMBLOCK_ADD_URL', 'Block this URL via Spamblock plugin');
+@define('PLUGIN_EVENT_SPAMBLOCK_REMOVE_AUTHOR', 'Unblock this author via Spamblock plugin');
+@define('PLUGIN_EVENT_SPAMBLOCK_REMOVE_URL', 'Unblock this URL via Spamblock plugin');
+
 class serendipity_event_spamblock extends serendipity_event
 {
 var $filter_defaults;
@@ -110,7 +116,9 @@ var $filter_defaults;
             'frontend_saveComment' => true,
             'external_plugin'      => true,
             'frontend_comment'     => true,
-            'fetchcomments'        => true
+            'fetchcomments'        => true,
+            'backend_comments_top' => true,
+            'backend_view_comment' => true
         ));
         $propbag->add('configuration', array('killswitch', 'bodyclone', 'ipflood', 'captchas', 'captchas_ttl', 'captcha_color', 'forcemoderation', 'disable_api_comments', 'links_moderate', 'links_reject', 'contentfilter_activate', 'contentfilter_urls', 'contentfilter_authors', 'hide_email', 'checkmail', 'required_fields', 'logtype', 'logfile'));
         $propbag->add('groups', array('ANTISPAM'));
@@ -653,6 +661,38 @@ var $filter_defaults;
                     return true;
                     break;
 
+                case 'backend_comments_top':
+
+                    // Add Author to blacklist. If already filtered, it will be removed from the filter. (AKA "Toggle")
+                    if (isset($serendipity['GET']['spamBlockAuthor'])) {
+                        $item    = $this->getComment('author', $serendipity['GET']['spamBlockAuthor']);
+                        $items   = &$this->checkFilter('authors', $item, true);
+                        $this->set_config('contentfilter_authors', implode(';', $items));
+                    }
+
+                    // Add URL to blacklist. If already filtered, it will be removed from the filter. (AKA "Toggle")
+                    if (isset($serendipity['GET']['spamBlockURL'])) {
+                        $item    = $this->getComment('url', $serendipity['GET']['spamBlockURL']);
+                        $items   = &$this->checkFilter('urls', $item, true);
+                        $this->set_config('contentfilter_urls', implode(';', $items));
+                    }
+
+                    echo ' - ' . WORD_OR . ' - <a class="serendipityPrettyButton" href="serendipity_admin.php?serendipity[adminModule]=plugins&amp;serendipity[plugin_to_conf]=serendipity_event_spamblock%3A' . $this->instance . '">' . PLUGIN_EVENT_SPAMBLOCK_CONFIG . '</a>';
+                    return true;
+                    break;
+
+                case 'backend_view_comment':
+                    $author_is_filtered = $this->checkFilter('authors', $eventData['author']);
+                    $eventData['action_author'] .= ' <a class="serendipityIconLink" title="' . ($author_is_filtered ? PLUGIN_EVENT_SPAMBLOCK_REMOVE_AUTHOR : PLUGIN_EVENT_SPAMBLOCK_ADD_AUTHOR) . '" href="serendipity_admin.php?serendipity[adminModule]=comments&amp;serendipity[spamBlockAuthor]=' . $eventData['id'] . '"><img src="' . serendipity_getTemplateFile('admin/img/' . ($author_is_filtered ? 'un' : '') . 'configure.png') . '" /></a>';
+
+                    if (!empty($eventData['url'])) {
+                        $url_is_filtered    = $this->checkFilter('urls', $eventData['url']);
+                        $eventData['action_url']    .= ' <a class="serendipityIconLink" title="' . ($url_is_filtered ? PLUGIN_EVENT_SPAMBLOCK_REMOVE_URL : PLUGIN_EVENT_SPAMBLOCK_ADD_URL) . '" href="serendipity_admin.php?serendipity[adminModule]=comments&amp;serendipity[spamBlockURL]=' . $eventData['id'] . '"><img src="' . serendipity_getTemplateFile('admin/img/' . ($url_is_filtered ? 'un' : '') . 'configure.png') . '" /></a>';
+                    }
+
+                    return true;
+                    break;
+
                 default:
                     return false;
                     break;
@@ -662,6 +702,50 @@ var $filter_defaults;
         }
     }
 
+    function &checkFilter($what, $match, $getItems = false) {
+        $items = explode(';', $this->get_config('contentfilter_' . $what, $this->filter_defaults[$what]));
+
+        $filtered = false;
+        if (is_array($items)) {
+            foreach($items AS $key => $item) {
+                if (empty($match)) {
+                    continue;
+                }
+
+                if (empty($item)) {
+                    unset($items[$key]);
+                    continue;
+                }
+
+                if (preg_match('@' . $item . '@', $match)) {
+                    $filtered = true;
+                    unset($items[$key]);
+                }
+            }
+        }
+        
+        if ($getItems) {
+            if (!$filtered && !empty($match)) {
+                $items[] = preg_quote($match, '@');
+            }
+
+            return $items;
+        }
+        
+        return $filtered;
+    }
+
+    function getComment($key, $id) {
+        global $serendipity;
+        $c = serendipity_db_query("SELECT $key FROM {$serendipity['dbPrefix']}comments WHERE id = '" . (int)$id . "'", true, 'assoc');
+        
+        if (!is_array($c) || !isset($c[$key])) {
+            return false;
+        }
+        
+        return $c[$key];
+    }
+
     function random_string($max_char, $min_char) {
         $this->chars = array(2, 3, 4, 7, 9); // 1, 5, 6 and 8 may look like characters.
         $this->chars = array_merge($this->chars, array('A','B','C','D','E','F','H','J','K','L','M','N','P','Q','R','T','U','V','W','X','Y','Z')); // I, O, S may look like numbers
diff --git a/templates/default/admin/img/unconfigure.png b/templates/default/admin/img/unconfigure.png
new file mode 100644 (file)
index 0000000..80b718c
Binary files /dev/null and b/templates/default/admin/img/unconfigure.png differ