]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/apimediaupload.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / actions / apimediaupload.php
index 2d81af157e06362db885ca5f62fb3643babcce7d..c2b4a47b9a277d799acd799d5d1e2c4a597f22fb 100644 (file)
@@ -30,7 +30,7 @@ if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Upload an image via the API.  Returns a shortened URL for the image
- * to the user.
+ * to the user. Apparently modelled after a former Twitpic API.
  *
  * @category API
  * @package  StatusNet
@@ -48,9 +48,6 @@ class ApiMediaUploadAction extends ApiAuthAction
      * Grab the file from the 'media' param, then store, and shorten
      *
      * @todo Upload throttle!
-     *
-     * @param array $args $_REQUEST data (unused)
-     *
      * @return void
      */
     protected function handle()
@@ -73,7 +70,9 @@ class ApiMediaUploadAction extends ApiAuthAction
         }
 
         // we could catch "NoUploadedMediaException" as "no media uploaded", but here we _always_ want an upload
-        $upload = MediaFile::fromUpload('media', $this->auth_user->getProfile());
+        $upload = MediaFile::fromUpload('media', $this->scoped);
+        
+        // Thumbnails will be generated/cached on demand when accessed (such as with /attachment/:id/thumbnail)
 
         $this->showResponse($upload);
     }
@@ -89,9 +88,14 @@ class ApiMediaUploadAction extends ApiAuthAction
     function showResponse(MediaFile $upload)
     {
         $this->initDocument();
-        $this->elementStart('rsp', array('stat' => 'ok'));
+        $this->elementStart('rsp', array('stat' => 'ok', 'xmlns:atom'=>Activity::ATOM));
         $this->element('mediaid', null, $upload->fileRecord->id);
         $this->element('mediaurl', null, $upload->shortUrl());
+
+        $enclosure = $upload->fileRecord->getEnclosure();
+        $this->element('atom:link', array('rel'  => 'enclosure',
+                                          'href' => $enclosure->url,
+                                          'type' => $enclosure->mimetype));
         $this->elementEnd('rsp');
         $this->endDocument();
     }
@@ -101,7 +105,7 @@ class ApiMediaUploadAction extends ApiAuthAction
      *
      * @param String $msg an error message
      */
-    function clientError($msg)
+    function clientError($msg, $code=400, $format=null)
     {
         $this->initDocument();
         $this->elementStart('rsp', array('stat' => 'fail'));
@@ -112,5 +116,6 @@ class ApiMediaUploadAction extends ApiAuthAction
         $this->element('err', $errAttr, null);
         $this->elementEnd('rsp');
         $this->endDocument();
+        exit;
     }
 }