+ if (Event::handle('StartAtomPubNewActivity', array(&$activity))) {
+
+ if ($activity->verb != ActivityVerb::FOLLOW) {
+ // TRANS: Client error displayed when not using the follow verb.
+ $this->clientError(_('Can only handle Follow activities.'));
+ }
+
+ $person = $activity->objects[0];
+
+ 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.'));
+ }
+
+ // XXX: OStatus discovery (maybe)
+ 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));
+ }
+
+ try {
+ $sub = Subscription::start($this->_profile, $profile);
+ } catch (AlreadyFulfilledException $e) {
+ // 409 Conflict
+ $this->clientError($e->getMessage(), 409);
+ }
+
+ Event::handle('EndAtomPubNewActivity', array($activity, $sub));
+ }
+
+ if (!empty($sub)) {
+ $act = $sub->asActivity();
+
+ header('Content-Type: application/atom+xml; charset=utf-8');
+ header('Content-Location: ' . $act->selfLink);
+
+ $this->startXML();
+ $this->raw($act->asString(true, true, true));
+ $this->endXML();