]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Fix for Blacklist plugin: was saving an empty entry if blacklist was empty, which...
authorBrion Vibber <brion@pobox.com>
Fri, 23 Apr 2010 14:17:52 +0000 (07:17 -0700)
committerBrion Vibber <brion@pobox.com>
Fri, 23 Apr 2010 14:17:52 +0000 (07:17 -0700)
Now saving only non-empty lines, and only matching non-empty lines so we don't fail if we still have a bogus entry.

plugins/Blacklist/BlacklistPlugin.php
plugins/Blacklist/blacklistadminpanel.php

index adc4d9d7e21b2779cdb6296fc0bc3e71c7baad9c..63bffe2c6fb8babb1f62531f33b58519d7672a4a 100644 (file)
@@ -262,7 +262,7 @@ class BlacklistPlugin extends Plugin
         $patterns = $this->_getUrlPatterns();
 
         foreach ($patterns as $pattern) {
-            if (preg_match("/$pattern/", $url)) {
+            if ($pattern != '' && preg_match("/$pattern/", $url)) {
                 return false;
             }
         }
@@ -285,7 +285,7 @@ class BlacklistPlugin extends Plugin
         $patterns = $this->_getNicknamePatterns();
 
         foreach ($patterns as $pattern) {
-            if (preg_match("/$pattern/", $nickname)) {
+            if ($pattern != '' && preg_match("/$pattern/", $nickname)) {
                 return false;
             }
         }
index b996aba8dc932a4b47283fcde5d2fcf56e71d71e..23c503cd82033bda17b729657bc05cdebc5990ac 100644 (file)
@@ -88,28 +88,27 @@ class BlacklistadminpanelAction extends AdminPanelAction
 
     function saveSettings()
     {
-        $nickPatterns = array();
-
-        $rawNickPatterns = explode("\n", $this->trimmed('blacklist-nicknames'));
-
-        foreach ($rawNickPatterns as $raw) {
-            $nickPatterns[] = trim($raw);
-        }
-
+        $nickPatterns = $this->splitPatterns($this->trimmed('blacklist-nicknames'));
         Nickname_blacklist::saveNew($nickPatterns);
 
-        $rawUrlPatterns = explode("\n", $this->trimmed('blacklist-urls'));
-        $urlPatterns  = array();
-
-        foreach ($rawUrlPatterns as $raw) {
-            $urlPatterns[] = trim($raw);
-        }
-
+        $urlPatterns = $this->splitPatterns($this->trimmed('url-nicknames'));
         Homepage_blacklist::saveNew($urlPatterns);
 
         return;
     }
 
+    protected function splitPatterns($text)
+    {
+        $patterns = array();
+        foreach (explode("\n", $text) as $raw) {
+            $trimmed = trim($raw);
+            if ($trimmed != '') {
+                $patterns[] = $trimmed;
+            }
+        }
+        return $patterns;
+    }
+
     /**
      * Validate the values
      *