]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/actions/pushhub.php
OStatus support for people tags
[quix0rs-gnu-social.git] / plugins / OStatus / actions / pushhub.php
index 842d65e7d29d9eac29518249560aa98c3e37a7e7..e7716c8cd03b9c05f6eceb3c6f0f1fd38bae422c 100644 (file)
  * @maintainer Brion Vibber <brion@status.net>
  */
 
+if (!defined('STATUSNET')) {
+    exit(1);
+}
+
 /**
 
 
@@ -36,7 +40,6 @@ Things to consider...
 
 */
 
-
 class PushHubAction extends Action
 {
     function arg($arg, $def=null)
@@ -63,9 +66,11 @@ class PushHubAction extends Action
             $this->subunsub($mode);
             break;
         case "publish":
-            throw new ClientException("Publishing outside feeds not supported.", 400);
+            // TRANS: Client exception.
+            throw new ClientException(_m('Publishing outside feeds not supported.'), 400);
         default:
-            throw new ClientException("Unrecognized mode '$mode'.", 400);
+            // TRANS: Client exception. %s is a mode.
+            throw new ClientException(sprintf(_m('Unrecognized mode "%s".'),$mode), 400);
         }
     }
 
@@ -84,24 +89,28 @@ class PushHubAction extends Action
 
         $topic = $this->argUrl('hub.topic');
         if (!$this->recognizedFeed($topic)) {
-            throw new ClientException("Unsupported hub.topic $topic; this hub only serves local user and group Atom feeds.");
+            // TRANS: Client exception. %s is a topic.
+            throw new ClientException(sprintf(_m('Unsupported hub.topic %s this hub only serves local user and group Atom feeds.'),$topic));
         }
 
         $verify = $this->arg('hub.verify'); // @fixme may be multiple
         if ($verify != 'sync' && $verify != 'async') {
-            throw new ClientException("Invalid hub.verify $verify; must be sync or async.");
+            // TRANS: Client exception.
+            throw new ClientException(sprintf(_m('Invalid hub.verify "%s". It must be sync or async.'),$verify));
         }
 
         $lease = $this->arg('hub.lease_seconds', null);
         if ($mode == 'subscribe' && $lease != '' && !preg_match('/^\d+$/', $lease)) {
-            throw new ClientException("Invalid hub.lease $lease; must be empty or positive integer.");
+            // TRANS: Client exception.
+            throw new ClientException(sprintf(_m('Invalid hub.lease "%s". It must be empty or positive integer.'),$lease));
         }
 
         $token = $this->arg('hub.verify_token', null);
 
         $secret = $this->arg('hub.secret', null);
         if ($secret != '' && strlen($secret) >= 200) {
-            throw new ClientException("Invalid hub.secret $secret; must be under 200 bytes.");
+            // TRANS: Client exception.
+            throw new ClientException(sprintf(_m('Invalid hub.secret "%s". It must be under 200 bytes.'),$secret));
         }
 
         $sub = HubSub::staticGet($topic, $callback);
@@ -152,7 +161,8 @@ class PushHubAction extends Action
             if ($feed == $userFeed) {
                 $user = User::staticGet('id', $id);
                 if (!$user) {
-                    throw new ClientException("Invalid hub.topic $feed; user doesn't exist.");
+                    // TRANS: Client exception.
+                    throw new ClientException(sprintt(_m('Invalid hub.topic "%s". User doesn\'t exist.'),$feed));
                 } else {
                     return true;
                 }
@@ -160,12 +170,28 @@ class PushHubAction extends Action
             if ($feed == $groupFeed) {
                 $user = User_group::staticGet('id', $id);
                 if (!$user) {
-                    throw new ClientException("Invalid hub.topic $feed; group doesn't exist.");
+                    // TRANS: Client exception.
+                    throw new ClientException(sprintf(_m('Invalid hub.topic "%s". Group doesn\'t exist.'),$feed));
+                } else {
+                    return true;
+                }
+            }
+        } else if (preg_match('!/(\d+)/lists/(\d+)/statuses\.atom$!', $feed, $matches)) {
+            $user = $matches[1];
+            $id = $matches[2];
+            $params = array('user' => $user, 'id' => $id, 'format' => 'atom');
+            $listFeed = common_local_url('ApiTimelineList', $params);
+
+            if ($feed == $listFeed) {
+                $list = Profile_list::staticGet('id', $id);
+                $user = User::staticGet('id', $user);
+                if (!$list || !$user || $list->tagger != $user->id) {
+                    throw new ClientException("Invalid hub.topic $feed; people tag doesn't exist.");
                 } else {
                     return true;
                 }
             }
-            common_log(LOG_DEBUG, "Not a user or group feed? $feed $userFeed $groupFeed");
+            common_log(LOG_DEBUG, "Not a user, group or people tag feed? $feed $userFeed $groupFeed $listFeed");
         }
         common_log(LOG_DEBUG, "LOST $feed");
         return false;
@@ -183,7 +209,9 @@ class PushHubAction extends Action
         if (Validate::uri($url, $params)) {
             return $url;
         } else {
-            throw new ClientException("Invalid URL passed for $arg: '$url'");
+            // TRANS: Client exception.
+            // TRANS: %1$s is this argument to the method this exception occurs in, %2$s is a URL.
+            throw new ClientException(sprintf(_m('Invalid URL passed for %1$s: "%2$s"'),$arg,$url));
         }
     }
 
@@ -199,4 +227,3 @@ class PushHubAction extends Action
         return HubSub::staticGet($feed, $callback);
     }
 }
-