]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/atompubsubscriptionfeed.php
Minor changes in Salmon lib for Magicsig retrieval.
[quix0rs-gnu-social.git] / actions / atompubsubscriptionfeed.php
index 0893c4b045405515077ff7b49c667f9a461275d7..c0f695dc42cc7603db9c89ea21cb3e9721723254 100644 (file)
@@ -34,8 +34,6 @@ if (!defined('STATUSNET')) {
     exit(1);
 }
 
-require_once INSTALLDIR . '/lib/apiauth.php';
-
 /**
  * Subscription feed class for AtomPub
  *
@@ -66,7 +64,7 @@ class AtompubsubscriptionfeedAction extends ApiAuthAction
 
         $subscriber = $this->trimmed('subscriber');
 
-        $this->_profile = Profile::staticGet('id', $subscriber);
+        $this->_profile = Profile::getKV('id', $subscriber);
 
         if (empty($this->_profile)) {
             // TRANS: Client exception thrown when trying to display a subscription for a non-existing profile ID.
@@ -107,7 +105,6 @@ class AtompubsubscriptionfeedAction extends ApiAuthAction
         default:
             // TRANS: Client exception thrown when using an unsupported HTTP method.
             $this->clientError(_('HTTP method not supported.'), 405);
-            return;
         }
 
         return;
@@ -150,7 +147,7 @@ class AtompubsubscriptionfeedAction extends ApiAuthAction
 
         // TRANS: Subtitle for Atom subscription feed.
         // TRANS: %1$s is a user nickname, %s$s is the StatusNet sitename.
-        $feed->setSubtitle(sprintf(_("People %1$s has subscribed to on %2$s"),
+        $feed->setSubtitle(sprintf(_("People %1\$s has subscribed to on %2\$s"),
                                    $this->_profile->getBestName(),
                                    common_config('site', 'name')));
 
@@ -234,7 +231,6 @@ class AtompubsubscriptionfeedAction extends ApiAuthAction
             $dom->documentElement->localName != 'entry') {
             // TRANS: Client error displayed when not using an Atom entry.
             $this->clientError(_('Atom post must be an Atom entry.'));
-            return;
         }
 
         $activity = new Activity($dom->documentElement);
@@ -244,10 +240,8 @@ class AtompubsubscriptionfeedAction extends ApiAuthAction
         if (Event::handle('StartAtomPubNewActivity', array(&$activity))) {
 
             if ($activity->verb != ActivityVerb::FOLLOW) {
-                // TRANS: Client error displayed when not using the POST verb.
-                // TRANS: Do not translate POST.
+                // TRANS: Client error displayed when not using the follow verb.
                 $this->clientError(_('Can only handle Follow activities.'));
-                return;
             }
 
             $person = $activity->objects[0];
@@ -255,17 +249,24 @@ class AtompubsubscriptionfeedAction extends ApiAuthAction
             if ($person->type != ActivityObject::PERSON) {
                 // TRANS: Client exception thrown when subscribing to an object that is not a person.
                 $this->clientError(_('Can only follow people.'));
-                return;
             }
 
             // XXX: OStatus discovery (maybe)
-
-            $profile = Profile::fromURI($person->id);
-
-            if (empty($profile)) {
+            try {
+                $profile = Profile::fromUri($person->id);
+            } catch (UnknownUriException $e) {
                 // TRANS: Client exception thrown when subscribing to a non-existing profile.
+                // TRANS: %s is the unknown profile ID.
                 $this->clientError(sprintf(_('Unknown profile %s.'), $person->id));
-                return;
+            }
+
+            if (Subscription::exists($this->_profile, $profile)) {
+                // 409 Conflict
+                // TRANS: Client error displayed trying to subscribe to an already subscribed profile.
+                // TRANS: %s is the profile the user already has a subscription on.
+                $this->clientError(sprintf(_('Already subscribed to %s.'),
+                                           $person->id),
+                                   409);
             }
 
             if (Subscription::start($this->_profile, $profile)) {