]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/RSSCloud/RSSCloudRequestNotify.php
The overloaded DB_DataObject function staticGet is now called getKV
[quix0rs-gnu-social.git] / plugins / RSSCloud / RSSCloudRequestNotify.php
index d76c08d379aedef609c28d851de3a897b5e72a7e..7fd6da05098bc401f9073812ca372dbcd6f0df76 100644 (file)
@@ -40,8 +40,7 @@ if (!defined('STATUSNET')) {
  * @author   Zach Copley <zach@status.net>
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link     http://status.net/
- **/
-
+ */
 class RSSCloudRequestNotifyAction extends Action
 {
     /**
@@ -51,7 +50,6 @@ class RSSCloudRequestNotifyAction extends Action
      *
      * @return boolean false if user doesn't exist
      */
-
     function prepare($args)
     {
         parent::prepare($args);
@@ -84,13 +82,13 @@ class RSSCloudRequestNotifyAction extends Action
      *
      * @return void
      */
-
     function handle($args)
     {
         parent::handle($args);
 
         if ($_SERVER['REQUEST_METHOD'] != 'POST') {
-            $this->showResult(false, 'Request must be POST.');
+            // TRANS: Form validation error displayed when POST is not used.
+            $this->showResult(false, _m('Request must be POST.'));
             return;
         }
 
@@ -107,7 +105,8 @@ 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.';
+            // TRANS: Form validation error displayed when HTTP POST is not used.
+            $msg = _m('Only HTTP POST notifications are supported at this time.');
             $this->showResult(false, $msg);
             return;
         }
@@ -117,15 +116,19 @@ class RSSCloudRequestNotifyAction extends Action
         }
 
         if (!empty($missing)) {
-            $msg = 'The following parameters were missing from the request body: ' .
-                implode(', ', $missing) . '.';
+            // TRANS: List separator.
+            $separator = _m('SEPARATOR',', ');
+            // TRANS: Form validation error displayed when a request body is missing expected parameters.
+            // TRANS: %s is a list of parameters separated by a list separator (default: ", ").
+            $msg = sprintf(_m('The following parameters were missing from the request body: %s.'),implode($separator, $missing));
             $this->showResult(false, $msg);
             return;
         }
 
         if (empty($this->feeds)) {
-            $msg = 'You must provide at least one valid profile feed url ' .
-              '(url1, url2, url3 ... urlN).';
+            // TRANS: Form validation error displayed when not providing any valid profile feed URLs.
+            $msg = _m('You must provide at least one valid profile feed URL ' .
+              '(url1, url2, url3 ... urlN).');
             $this->showResult(false, $msg);
             return;
         }
@@ -133,27 +136,25 @@ class RSSCloudRequestNotifyAction extends Action
         // We have to validate everything before saving anything.
         // We only return one success or failure no matter how
         // many feeds the subscriber is trying to subscribe to
-
         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.';
+                // TRANS: Form validation error displayed when not providing a valid feed URL.
+                $msg = _m('Feed subscription failed: Not a valid feed.');
                 $this->showResult(false, $msg);
                 return;
             }
 
             if (!$this->testNotificationHandler($feed)) {
-                $msg = 'Feed subscription failed - ' .
-                'notification handler doesn\'t respond correctly.';
+                // TRANS: Form validation error displayed when feed subscription failed.
+                $msg = _m('Feed subscription failed: ' .
+                'Notification handler does not respond correctly.');
                 $this->showResult(false, $msg);
                 return;
             }
-
         }
 
         foreach ($this->feeds as $feed) {
@@ -163,9 +164,9 @@ class RSSCloudRequestNotifyAction extends Action
         // XXX: What to do about deleting stale subscriptions?
         // 25 hours seems harsh. WordPress doesn't ever remove
         // subscriptions.
-
-        $msg = 'Thanks for the subscription. ' .
-          'When the feed(s) update(s) we\'ll notify you.';
+        // TRANS: Success message after subscribing to one or more feeds.
+        $msg = _m('Thanks for the subscription. ' .
+          'When the feed(s) update(s), you will be notified.');
 
         $this->showResult(true, $msg);
     }
@@ -178,7 +179,6 @@ class RSSCloudRequestNotifyAction extends Action
      *
      * @return void
      */
-
     function validateFeed($feed)
     {
         $user = $this->userFromFeed($feed);
@@ -196,7 +196,6 @@ class RSSCloudRequestNotifyAction extends Action
      *
      * @return array $feeds the list of feeds
      */
-
     function getFeeds()
     {
         $feeds = array();
@@ -218,7 +217,6 @@ class RSSCloudRequestNotifyAction extends Action
      *
      * @return boolean success result
      */
-
     function testNotificationHandler($feed)
     {
         $notifyUrl = $this->getNotifyUrl();
@@ -226,14 +224,11 @@ class RSSCloudRequestNotifyAction extends Action
         $notifier = new RSSCloudNotifier();
 
         if (isset($this->domain)) {
-
             // 'domain' param set, so we have to use GET and send a challenge
-
             common_log(LOG_INFO,
                        'RSSCloud plugin - Testing notification handler with challenge: ' .
                        $notifyUrl);
             return $notifier->challenge($notifyUrl, $feed);
-
         } else {
             common_log(LOG_INFO, 'RSSCloud plugin - Testing notification handler: ' .
                        $notifyUrl);
@@ -248,7 +243,6 @@ class RSSCloudRequestNotifyAction extends Action
      *
      * @return string notification handler url
      */
-
     function getNotifyUrl()
     {
         if (isset($this->domain)) {
@@ -267,16 +261,15 @@ class RSSCloudRequestNotifyAction extends Action
      *
      * @return boolean success
      */
-
     function userFromFeed($feed)
     {
-        // We only do profile feeds
-
+        // We only do canonical RSS2 profile feeds (specified by ID), e.g.:
+        // http://www.example.com/api/statuses/user_timeline/2.rss
         $path  = common_path('api/statuses/user_timeline/');
-        $valid = '%^' . $path . '(?<nickname>.*)\.rss$%';
+        $valid = '%^' . $path . '(?<id>.*)\.rss$%';
 
         if (preg_match($valid, $feed, $matches)) {
-            $user = User::staticGet('nickname', $matches['nickname']);
+            $user = User::getKV('id', $matches['id']);
             if (!empty($user)) {
                 return $user;
             }
@@ -292,7 +285,6 @@ class RSSCloudRequestNotifyAction extends Action
      *
      * @return boolean success result
      */
-
     function saveSubscription($feed)
     {
         $user = $this->userFromFeed($feed);
@@ -305,7 +297,6 @@ class RSSCloudRequestNotifyAction extends Action
             common_log(LOG_INFO, "RSSCloud plugin - $notifyUrl refreshed subscription" .
                          " to user $user->nickname (id: $user->id).");
         } else {
-
             $sub = new RSSCloudSubscription();
 
             $sub->subscribed = $user->id;
@@ -333,7 +324,6 @@ class RSSCloudRequestNotifyAction extends Action
      *
      * @return boolean success result
      */
-
     function showResult($success, $msg)
     {
         $this->startXML();
@@ -342,6 +332,4 @@ class RSSCloudRequestNotifyAction extends Action
                                   'msg'     => $msg));
         $this->endXML();
     }
-
 }
-