X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fapitimelineuser.php;h=62d0a5e0d5bbbd78319b3f0aa5aee6833be18ab5;hb=d48076253b02f8ab1f91e54289a189af7017db9f;hp=42988a00f6b7ed5cc78a9ecf3af98b65503521fa;hpb=6c671141982c5837a2e5bf1e90de389c728d5dee;p=quix0rs-gnu-social.git diff --git a/actions/apitimelineuser.php b/actions/apitimelineuser.php index 42988a00f6..62d0a5e0d5 100644 --- a/actions/apitimelineuser.php +++ b/actions/apitimelineuser.php @@ -201,8 +201,19 @@ class ApiTimelineUserAction extends ApiBareAuthAction case 'json': $this->showJsonTimeline($this->notices); break; + case 'as': + header('Content-Type: ' . ActivityStreamJSONDocument::CONTENT_TYPE); + $doc = new ActivityStreamJSONDocument($this->auth_user); + $doc->setTitle($atom->title); + $doc->addLink($link, 'alternate', 'text/html'); + $doc->addItemsFromNotices($this->notices); + + // XXX: Add paging extension? + + $this->raw($doc->asString()); + break; default: - // TRANS: Client error displayed when trying to handle an unknown API method. + // TRANS: Client error displayed when coming across a non-supported API method. $this->clientError(_('API method not found.'), $code = 404); break; } @@ -241,7 +252,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction * * @return boolean true */ - + function isReadOnly($args) { return ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD'); @@ -307,11 +318,16 @@ class ApiTimelineUserAction extends ApiBareAuthAction $xml = trim(file_get_contents('php://input')); if (empty($xml)) { + // TRANS: Client error displayed attempting to post an empty API notice. $this->clientError(_('Atom post must not be empty.')); } - $dom = DOMDocument::loadXML($xml); - if (!$dom) { + $old = error_reporting(error_reporting() & ~(E_WARNING | E_NOTICE)); + $dom = new DOMDocument(); + $ok = $dom->loadXML($xml); + error_reporting($old); + if (!$ok) { + // TRANS: Client error displayed attempting to post an API that is not well-formed XML. $this->clientError(_('Atom post must be well-formed XML.')); } @@ -324,11 +340,11 @@ class ApiTimelineUserAction extends ApiBareAuthAction $activity = new Activity($dom->documentElement); - if (Event::handle('StartAtomPubNewActivity', array(&$activity))) { + $saved = null; + if (Event::handle('StartAtomPubNewActivity', array(&$activity, $this->user, &$saved))) { if ($activity->verb != ActivityVerb::POST) { - // TRANS: Client error displayed when not using the POST verb. - // TRANS: Do not translate POST. + // TRANS: Client error displayed when not using the POST verb. Do not translate POST. $this->clientError(_('Can only handle POST activities.')); return; } @@ -347,7 +363,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction $saved = $this->postNote($activity); - Event::handle('EndAtomPubNewActivity', array($activity, $saved)); + Event::handle('EndAtomPubNewActivity', array($activity, $this->user, $saved)); } if (!empty($saved)) { @@ -373,6 +389,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction } else { // @fixme fetch from $sourceUrl? // TRANS: Client error displayed when posting a notice without content through the API. + // TRANS: %d is the notice ID (number). $this->clientError(sprintf(_('No content for notice %d.'), $note->id)); return; @@ -401,6 +418,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction if (!empty($notice)) { // TRANS: Client error displayed when using another format than AtomPub. + // TRANS: %s is the notice URI. $this->clientError(sprintf(_('Notice with URI "%s" already exists.'), $note->id)); return; @@ -425,14 +443,14 @@ class ApiTimelineUserAction extends ApiBareAuthAction $profile = Profile::fromURI($uri); if (!empty($profile)) { - $options['replies'] = $uri; + $options['replies'][] = $uri; } else { $group = User_group::staticGet('uri', $uri); if (!empty($group)) { - $options['groups'] = $uri; + $options['groups'][] = $group->id; } else { // @fixme: hook for discovery here - common_log(LOG_WARNING, sprintf(_('AtomPub post with unknown attention URI %s'), $uri)); + common_log(LOG_WARNING, sprintf('AtomPub post with unknown attention URI %s', $uri)); } } }