]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/actions/pushhub.php
Minor function definitions so they match Action parent
[quix0rs-gnu-social.git] / plugins / OStatus / actions / pushhub.php
index bfd51ec02f65b1d5ce17dc7d537f3c3528aaf9ad..c883647e681ef8768b58694cf9458ca49b81e894 100644 (file)
@@ -28,18 +28,14 @@ if (!defined('STATUSNET')) {
 }
 
 /**
-
-
-Things to consider...
-* should we purge incomplete subscriptions that never get a verification pingback?
-* when can we send subscription renewal checks?
-    - at next send time probably ok
-* when can we handle trimming of subscriptions?
-    - at next send time probably ok
-* should we keep a fail count?
-
-*/
-
+ * Things to consider...
+ * should we purge incomplete subscriptions that never get a verification pingback?
+ * when can we send subscription renewal checks?
+ *    - at next send time probably ok
+ * when can we handle trimming of subscriptions?
+ *    - at next send time probably ok
+ * should we keep a fail count?
+ */
 class PushHubAction extends Action
 {
     function arg($arg, $def=null)
@@ -51,13 +47,13 @@ class PushHubAction extends Action
         return parent::arg($arg, $def);
     }
 
-    function prepare($args)
+    protected function prepare($args)
     {
         StatusNet::setApi(true); // reduce exception reports to aid in debugging
         return parent::prepare($args);
     }
 
-    function handle()
+    protected function handle()
     {
         $mode = $this->trimmed('hub.mode');
         switch ($mode) {
@@ -95,13 +91,13 @@ class PushHubAction extends Action
 
         $verify = $this->arg('hub.verify'); // @fixme may be multiple
         if ($verify != 'sync' && $verify != 'async') {
-            // TRANS: Client exception.
+            // TRANS: Client exception. %s is sync or async.
             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)) {
-            // TRANS: Client exception.
+            // TRANS: Client exception. %s is the invalid lease value.
             throw new ClientException(sprintf(_m('Invalid hub.lease "%s". It must be empty or positive integer.'),$lease));
         }
 
@@ -109,11 +105,11 @@ class PushHubAction extends Action
 
         $secret = $this->arg('hub.secret', null);
         if ($secret != '' && strlen($secret) >= 200) {
-            // TRANS: Client exception.
+            // TRANS: Client exception. %s is the invalid hub secret.
             throw new ClientException(sprintf(_m('Invalid hub.secret "%s". It must be under 200 bytes.'),$secret));
         }
 
-        $sub = HubSub::staticGet($topic, $callback);
+        $sub = HubSub::getByHashkey($topic, $callback);
         if (!$sub) {
             // Creating a new one!
             $sub = new HubSub();
@@ -159,24 +155,40 @@ class PushHubAction extends Action
             $groupFeed = common_local_url('ApiTimelineGroup', $params);
 
             if ($feed == $userFeed) {
-                $user = User::staticGet('id', $id);
+                $user = User::getKV('id', $id);
                 if (!$user) {
-                    // TRANS: Client exception.
-                    throw new ClientException(sprintt(_m('Invalid hub.topic "%s". User doesn\'t exist.'),$feed));
+                    // TRANS: Client exception. %s is a feed URL.
+                    throw new ClientException(sprintt(_m('Invalid hub.topic "%s". User does not exist.'),$feed));
                 } else {
                     return true;
                 }
             }
             if ($feed == $groupFeed) {
-                $user = User_group::staticGet('id', $id);
+                $user = User_group::getKV('id', $id);
                 if (!$user) {
-                    // TRANS: Client exception.
-                    throw new ClientException(sprintf(_m('Invalid hub.topic "%s". Group doesn\'t exist.'),$feed));
+                    // TRANS: Client exception. %s is a feed URL.
+                    throw new ClientException(sprintf(_m('Invalid hub.topic "%s". Group does not 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::getKV('id', $id);
+                $user = User::getKV('id', $user);
+                if (!$list || !$user || $list->tagger != $user->id) {
+                    // TRANS: Client exception. %s is a feed URL.
+                    throw new ClientException(sprintf(_m('Invalid hub.topic %s; list does not exist.'),$feed));
                 } 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;
@@ -191,7 +203,8 @@ class PushHubAction extends Action
         $url = $this->arg($arg);
         $params = array('domain_check' => false, // otherwise breaks my local tests :P
                         'allowed_schemes' => array('http', 'https'));
-        if (Validate::uri($url, $params)) {
+        $validate = new Validate;
+        if ($validate->uri($url, $params)) {
             return $url;
         } else {
             // TRANS: Client exception.
@@ -209,6 +222,6 @@ class PushHubAction extends Action
      */
     protected function getSub($feed, $callback)
     {
-        return HubSub::staticGet($feed, $callback);
+        return HubSub::getByHashkey($feed, $callback);
     }
 }