]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Blacklist/BlacklistPlugin.php
Merge branch 'master' into 1.0.x
[quix0rs-gnu-social.git] / plugins / Blacklist / BlacklistPlugin.php
index 10f89ef72392b20bc602de9f5d0abc0ad4498a33..babf7031313e22565e0a0b366a009940834e585d 100644 (file)
@@ -126,7 +126,9 @@ class BlacklistPlugin extends Plugin
         } else if (is_string($config)) {
             return explode("\r\n", $config);
         } else {
-            throw new Exception("Unknown data type for config $section + $setting");
+            // TRANS: Exception thrown if the Blacklist plugin configuration is incorrect.
+            // TRANS: %1$s is a configuration section, %2$s is a configuration setting.
+            throw new Exception(sprintf(_m('Unknown data type for config %1$s + %2$s.'),$section, $setting));
         }
     }
 
@@ -139,23 +141,25 @@ class BlacklistPlugin extends Plugin
      *
      * @return boolean hook value
      */
-    function onStartRegistrationTry($action)
+    function onStartRegisterUser(&$user, &$profile)
     {
-        $homepage = strtolower($action->trimmed('homepage'));
+        $homepage = strtolower($profile->homepage);
 
         if (!empty($homepage)) {
             if (!$this->_checkUrl($homepage)) {
-                $msg = sprintf(_m("You may not register with homepage '%s'."),
+                // TRANS: Validation failure for URL. %s is the URL.
+                $msg = sprintf(_m("You may not register with homepage \"%s\"."),
                                $homepage);
                 throw new ClientException($msg);
             }
         }
 
-        $nickname = strtolower($action->trimmed('nickname'));
+        $nickname = strtolower($profile->nickname);
 
         if (!empty($nickname)) {
             if (!$this->_checkNickname($nickname)) {
-                $msg = sprintf(_m("You may not register with nickname '%s'."),
+                // TRANS: Validation failure for nickname. %s is the nickname.
+                $msg = sprintf(_m("You may not register with nickname \"%s\"."),
                                $nickname);
                 throw new ClientException($msg);
             }
@@ -179,7 +183,8 @@ class BlacklistPlugin extends Plugin
 
         if (!empty($homepage)) {
             if (!$this->_checkUrl($homepage)) {
-                $msg = sprintf(_m("You may not use homepage '%s'."),
+                // TRANS: Validation failure for URL. %s is the URL.
+                $msg = sprintf(_m("You may not use homepage \"%s\"."),
                                $homepage);
                 throw new ClientException($msg);
             }
@@ -189,7 +194,8 @@ class BlacklistPlugin extends Plugin
 
         if (!empty($nickname)) {
             if (!$this->_checkNickname($nickname)) {
-                $msg = sprintf(_m("You may not use nickname '%s'."),
+                // TRANS: Validation failure for nickname. %s is the nickname.
+                $msg = sprintf(_m("You may not use nickname \"%s\"."),
                                $nickname);
                 throw new ClientException($msg);
             }
@@ -231,6 +237,7 @@ class BlacklistPlugin extends Plugin
         $url = htmlspecialchars_decode($url);
 
         if (!$this->_checkUrl($url)) {
+            // TRANS: Validation failure for URL. %s is the URL.
             $msg = sprintf(_m("You may not use URL \"%s\" in notices."),
                            $url);
             throw new ClientException($msg);
@@ -292,7 +299,7 @@ class BlacklistPlugin extends Plugin
      */
     function onRouterInitialized($m)
     {
-        $m->connect('admin/blacklist', array('action' => 'blacklistadminpanel'));
+        $m->connect('panel/blacklist', array('action' => 'blacklistadminpanel'));
         return true;
     }
 
@@ -335,6 +342,7 @@ class BlacklistPlugin extends Plugin
                             'homepage' =>
                             'http://status.net/wiki/Plugin:Blacklist',
                             'description' =>
+                            // TRANS: Plugin description.
                             _m('Keeps a blacklist of forbidden nickname '.
                                'and URL patterns.'));
         return true;
@@ -372,8 +380,10 @@ class BlacklistPlugin extends Plugin
             $action_name = $nav->action->trimmed('action');
 
             $nav->out->menuItem(common_local_url('blacklistadminpanel'),
-                                _m('Blacklist'),
-                                _m('Blacklist configuration'),
+                                // TRANS: Menu item in admin panel.
+                                _m('MENU','Blacklist'),
+                                // TRANS: Tooltip for menu item in admin panel.
+                                _m('TOOLTIP','Blacklist configuration.'),
                                 $action_name == 'blacklistadminpanel',
                                 'nav_blacklist_admin_panel');
         }
@@ -399,6 +409,7 @@ class BlacklistPlugin extends Plugin
         $action->elementStart('li');
         $this->checkboxAndText($action,
                                'blacklistnickname',
+                               // TRANS: Checkbox label in the blacklist user form.
                                _m('Add this nickname pattern to blacklist'),
                                'blacklistnicknamepattern',
                                $this->patternizeNickname($user->nickname));
@@ -408,6 +419,7 @@ class BlacklistPlugin extends Plugin
             $action->elementStart('li');
             $this->checkboxAndText($action,
                                    'blacklisthomepage',
+                                   // TRANS: Checkbox label in the blacklist user form.
                                    _m('Add this homepage pattern to blacklist'),
                                    'blacklisthomepagepattern',
                                    $this->patternizeHomepage($profile->homepage));
@@ -463,4 +475,82 @@ class BlacklistPlugin extends Plugin
         $hostname = parse_url($homepage, PHP_URL_HOST);
         return $hostname;
     }
+
+    function onStartHandleFeedEntry($activity)
+    {
+        return $this->_checkActivity($activity);
+    }
+
+    function onStartHandleSalmon($activity)
+    {
+        return $this->_checkActivity($activity);
+    }
+
+    function _checkActivity($activity)
+    {
+        $actor = $activity->actor;
+
+        if (empty($actor)) {
+            return true;
+        }
+
+        $homepage = strtolower($actor->link);
+
+        if (!empty($homepage)) {
+            if (!$this->_checkUrl($homepage)) {
+                // TRANS: Exception thrown trying to post a notice while having set a blocked homepage URL. %s is the blocked URL.
+                $msg = sprintf(_m("Users from \"%s\" are blocked."),
+                               $homepage);
+                throw new ClientException($msg);
+            }
+        }
+
+        $nickname = strtolower($actor->poco->preferredUsername);
+
+        if (!empty($nickname)) {
+            if (!$this->_checkNickname($nickname)) {
+                // TRANS: Exception thrown trying to post a notice while having a blocked nickname. %s is the blocked nickname.
+                $msg = sprintf(_m("Notices from nickname \"%s\" disallowed."),
+                               $nickname);
+                throw new ClientException($msg);
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * Check URLs and homepages for blacklisted users.
+     */
+    function onStartSubscribe($subscriber, $other)
+    {
+        foreach (array($other->profileurl, $other->homepage) as $url) {
+
+            if (empty($url)) {
+                continue;
+            }
+
+            $url = strtolower($url);
+
+            if (!$this->_checkUrl($url)) {
+                // TRANS: Client exception thrown trying to subscribe to a person with a blocked homepage or site URL. %s is the blocked URL.
+                $msg = sprintf(_m("Users from \"%s\" are blocked."),
+                               $url);
+                throw new ClientException($msg);
+            }
+        }
+
+        $nickname = $other->nickname;
+
+        if (!empty($nickname)) {
+            if (!$this->_checkNickname($nickname)) {
+                // TRANS: Client exception thrown trying to subscribe to a person with a blocked nickname. %s is the blocked nickname.
+                $msg = sprintf(_m("Cannot subscribe to nickname \"%s\"."),
+                               $nickname);
+                throw new ClientException($msg);
+            }
+        }
+
+        return true;
+    }
 }