]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/apitimelineuser.php
Merge branch '1.0.x' of gitorious.org:statusnet/mainline into inline-comments
[quix0rs-gnu-social.git] / actions / apitimelineuser.php
index d90507aa4460e8c24476f0db940c15ef774a0569..66984b5abda1ca47ad8dafd338ca98c215d5237e 100644 (file)
@@ -201,6 +201,17 @@ class ApiTimelineUserAction extends ApiBareAuthAction
         case 'json':
             $this->showJsonTimeline($this->notices);
             break;
+        case 'as':
+            header('Content-Type: application/json; charset=utf-8');
+            $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.
             $this->clientError(_('API method not found.'), $code = 404);
@@ -235,20 +246,16 @@ class ApiTimelineUserAction extends ApiBareAuthAction
     }
 
     /**
-     * Is this action read only?
+     * We expose AtomPub here, so non-GET/HEAD reqs must be read/write.
      *
      * @param array $args other arguments
      *
      * @return boolean true
      */
-    
+
     function isReadOnly($args)
     {
-        if ($_SERVER['REQUEST_METHOD'] == 'GET') {
-           return true;
-       } else {
-           return false;
-       }
+        return ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD');
     }
 
     /**
@@ -309,9 +316,17 @@ class ApiTimelineUserAction extends ApiBareAuthAction
             return;
         }
 
-        $xml = file_get_contents('php://input');
+        $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) {
+            // TRANS: Client error displayed attempting to post an API that is not well-formed XML.
+            $this->clientError(_('Atom post must be well-formed XML.'));
+        }
 
         if ($dom->documentElement->namespaceURI != Activity::ATOM ||
             $dom->documentElement->localName != 'entry') {
@@ -322,11 +337,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;
             }
@@ -345,11 +360,12 @@ 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)) {
-            header("Location: " . common_local_url('ApiStatusesShow', array('notice_id' => $saved->id,
+            header('HTTP/1.1 201 Created');
+            header("Location: " . common_local_url('ApiStatusesShow', array('id' => $saved->id,
                                                                             'format' => 'atom')));
             $this->showSingleAtomStatus($saved);
         }
@@ -370,6 +386,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;
@@ -398,6 +415,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;
@@ -422,14 +440,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'][] = $uri;
                     } 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));
                     }
                 }
             }