]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/RSSCloud/RSSCloudRequestNotify.php
Merge branch 'master' into testing
[quix0rs-gnu-social.git] / plugins / RSSCloud / RSSCloudRequestNotify.php
index 4703ecd104aac001ff18ac7d8e8166bee5692c6f..d76c08d379aedef609c28d851de3a897b5e72a7e 100644 (file)
@@ -56,9 +56,9 @@ class RSSCloudRequestNotifyAction extends Action
     {
         parent::prepare($args);
 
-        $this->ip        = $_SERVER['REMOTE_ADDR'];
-        $this->port      = $this->arg('port');
-        $this->path      = $this->arg('path');
+        $this->ip   = $_SERVER['REMOTE_ADDR'];
+        $this->port = $this->arg('port');
+        $this->path = $this->arg('path');
 
         if ($this->path[0] != '/') {
             $this->path = '/' . $this->path;
@@ -68,7 +68,7 @@ class RSSCloudRequestNotifyAction extends Action
         $this->procedure = $this->arg('notifyProcedure');
         $this->domain    = $this->arg('domain');
 
-        $this->feeds     = $this->getFeeds();
+        $this->feeds = $this->getFeeds();
 
         return true;
     }
@@ -106,6 +106,10 @@ class RSSCloudRequestNotifyAction extends Action
 
         if (empty($this->protocol)) {
             $missing[] = 'protocol';
+        } else if (strtolower($this->protocol) != 'http-post') {
+            $msg = 'Only http-post notifications are supported at this time.';
+            $this->showResult(false, $msg);
+            return;
         }
 
         if (!isset($this->procedure)) {
@@ -120,8 +124,9 @@ class RSSCloudRequestNotifyAction extends Action
         }
 
         if (empty($this->feeds)) {
-            $this->showResult(false,
-                              'You must provide at least one valid profile feed url (url1, url2, url3 ... urlN).');
+            $msg = 'You must provide at least one valid profile feed url ' .
+              '(url1, url2, url3 ... urlN).';
+            $this->showResult(false, $msg);
             return;
         }
 
@@ -132,6 +137,11 @@ class RSSCloudRequestNotifyAction extends Action
         foreach ($this->feeds as $feed) {
 
             if (!$this->validateFeed($feed)) {
+
+                $nh = $this->getNotifyUrl();
+                common_log(LOG_WARNING,
+                           "RSSCloud plugin - $nh tried to subscribe to invalid feed: $feed");
+
                 $msg = 'Feed subscription failed - Not a valid feed.';
                 $this->showResult(false, $msg);
                 return;
@@ -191,7 +201,7 @@ class RSSCloudRequestNotifyAction extends Action
     {
         $feeds = array();
 
-        while (list($key, $feed) = each ($this->args)) {
+        while (list($key, $feed) = each($this->args)) {
             if (preg_match('/^url\d*$/', $key)) {
                 $feeds[] = $feed;
             }
@@ -211,8 +221,6 @@ class RSSCloudRequestNotifyAction extends Action
 
     function testNotificationHandler($feed)
     {
-        common_debug("RSSCloudPlugin - testNotificationHandler()");
-
         $notifyUrl = $this->getNotifyUrl();
 
         $notifier = new RSSCloudNotifier();
@@ -221,12 +229,13 @@ class RSSCloudRequestNotifyAction extends Action
 
             // 'domain' param set, so we have to use GET and send a challenge
 
-            common_log(LOG_INFO, 'Testing notification handler with challenge: ' .
+            common_log(LOG_INFO,
+                       'RSSCloud plugin - Testing notification handler with challenge: ' .
                        $notifyUrl);
             return $notifier->challenge($notifyUrl, $feed);
 
         } else {
-            common_log(LOG_INFO, 'Testing notification handler: ' .
+            common_log(LOG_INFO, 'RSSCloud plugin - Testing notification handler: ' .
                        $notifyUrl);
 
             return $notifier->postUpdate($notifyUrl, $feed);
@@ -247,7 +256,7 @@ class RSSCloudRequestNotifyAction extends Action
         } else {
             return 'http://' . $this->ip . ':' . $this->port . $this->path;
         }
-     }
+    }
 
     /**
      * Uses the nickname part of the subscribed feed URL to figure out
@@ -263,7 +272,7 @@ class RSSCloudRequestNotifyAction extends Action
     {
         // We only do profile feeds
 
-        $path = common_path('api/statuses/user_timeline/');
+        $path  = common_path('api/statuses/user_timeline/');
         $valid = '%^' . $path . '(?<nickname>.*)\.rss$%';
 
         if (preg_match($valid, $feed, $matches)) {
@@ -279,7 +288,7 @@ class RSSCloudRequestNotifyAction extends Action
     /**
      * Save an RSSCloud subscription
      *
-     * @param $feed a valid profile feed
+     * @param string $feed a valid profile feed
      *
      * @return boolean success result
      */
@@ -293,7 +302,8 @@ class RSSCloudRequestNotifyAction extends Action
         $sub = RSSCloudSubscription::getSubscription($user->id, $notifyUrl);
 
         if ($sub) {
-            common_debug("Already subscribed to that!");
+            common_log(LOG_INFO, "RSSCloud plugin - $notifyUrl refreshed subscription" .
+                         " to user $user->nickname (id: $user->id).");
         } else {
 
             $sub = new RSSCloudSubscription();
@@ -307,6 +317,8 @@ class RSSCloudRequestNotifyAction extends Action
                 return false;
             }
 
+            common_log(LOG_INFO, "RSSCloud plugin - $notifyUrl subscribed" .
+                       " to user $user->nickname (id: $user->id)");
         }
 
         return true;
@@ -325,8 +337,9 @@ class RSSCloudRequestNotifyAction extends Action
     function showResult($success, $msg)
     {
         $this->startXML();
-        $this->elementStart('notifyResult', array('success' => ($success) ? 'true' : 'false',
-                                                  'msg'     => $msg));
+        $this->elementStart('notifyResult',
+                            array('success' => ($success) ? 'true' : 'false',
+                                  'msg'     => $msg));
         $this->endXML();
     }