]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/apistatusesupdate.php
Rearanged a couple things & removed debugging statements
[quix0rs-gnu-social.git] / actions / apistatusesupdate.php
index fb12785593d9c3b7c18e0f213b0e1e6926cd1283..3a030f0fe851423bd04211a157302aa9668f03e4 100644 (file)
  *
  * @category  API
  * @package   StatusNet
+ * @author    Craig Andrews <candrews@integralblue.com>
+ * @author    Evan Prodromou <evan@status.net>
+ * @author    Jeffery To <jeffery.to@gmail.com>
+ * @author    Tom Blankenship <mac65@mac65.com>
+ * @author    Mike Cochrane <mikec@mikenz.geek.nz>
+ * @author    Robin Millette <robin@millette.info>
  * @author    Zach Copley <zach@status.net>
  * @copyright 2009 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
@@ -31,13 +37,20 @@ if (!defined('STATUSNET')) {
     exit(1);
 }
 
-require_once INSTALLDIR.'/lib/apiauth.php';
+require_once INSTALLDIR . '/lib/apiauth.php';
+require_once INSTALLDIR . '/lib/mediafile.php';
 
 /**
  * Updates the authenticating user's status (posts a notice).
  *
  * @category API
  * @package  StatusNet
+ * @author   Craig Andrews <candrews@integralblue.com>
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Jeffery To <jeffery.to@gmail.com>
+ * @author   Tom Blankenship <mac65@mac65.com>
+ * @author   Mike Cochrane <mikec@mikenz.geek.nz>
+ * @author   Robin Millette <robin@millette.info>
  * @author   Zach Copley <zach@status.net>
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link     http://status.net/
@@ -45,13 +58,9 @@ require_once INSTALLDIR.'/lib/apiauth.php';
 
 class ApiStatusesUpdateAction extends ApiAuthAction
 {
-
-    var $user                  = null;
     var $source                = null;
     var $status                = null;
     var $in_reply_to_status_id = null;
-    var $format                = null;
-
     static $reserved_sources = array('web', 'omb', 'mail', 'xmpp', 'api');
 
     /**
@@ -67,39 +76,14 @@ class ApiStatusesUpdateAction extends ApiAuthAction
     {
         parent::prepare($args);
 
-        if ($this->requiresAuth()) {
-            if ($this->checkBasicAuthUser() == false) {
-                return false;
-            }
-        }
-
-        $this->user = $this->auth_user;
-
-        if (empty($this->user)) {
-            $this->clientError(_('No such user!'), 404, $this->format);
-            return false;
-        }
-
+        $this->user   = $this->auth_user;
         $this->status = $this->trimmed('status');
-
-        if (empty($this->status)) {
-            $this->clientError(
-                'Client must provide a \'status\' parameter with a value.',
-                400,
-                $this->format
-            );
-
-            return false;
-        }
-
         $this->source = $this->trimmed('source');
 
         if (empty($this->source) || in_array($source, $this->reserved_sources)) {
             $this->source = 'api';
         }
 
-        $this->format = $this->arg('format');
-
         $this->in_reply_to_status_id
             = intval($this->trimmed('in_reply_to_status_id'));
 
@@ -128,6 +112,27 @@ class ApiStatusesUpdateAction extends ApiAuthAction
             return;
         }
 
+        if (empty($this->status)) {
+            $this->clientError(
+                'Client must provide a \'status\' parameter with a value.',
+                400,
+                $this->format
+            );
+            return;
+        }
+
+        if (empty($this->user)) {
+            $this->clientError(_('No such user!'), 404, $this->format);
+            return;
+        }
+
+        // Workaround for PHP returning empty $_FILES when POST length > PHP settings
+
+        if (empty($_POST) && ($_SERVER['CONTENT_LENGTH'] > 0)) {
+            $this->clientError(_('Unable to handle that much POST data!'));
+            return;
+        }
+
         $status_shortened = common_shorten_links($this->status);
 
         if (Notice::contentTooLong($status_shortened)) {
@@ -186,14 +191,34 @@ class ApiStatusesUpdateAction extends ApiAuthAction
                 }
             }
 
+            $upload = null;
+            $upload = MediaFile::fromUpload('media', $this->user);
+
+            if (isset($upload)) {
+                $status_shortened .= ' ' . $upload->shortUrl();
+
+                if (Notice::contentTooLong($status_shortened)) {
+                    $upload->delete();
+                    $msg = _(
+                        'Max notice size is %d chars, ' .
+                        'including attachment URL.'
+                    );
+                    $this->clientError(sprintf($msg, Notice::maxContent()));
+                }
+            }
+
             $this->notice = Notice::saveNew(
                 $this->user->id,
-                html_entity_decode($this->status, ENT_NOQUOTES, 'UTF-8'),
+                html_entity_decode($status_shortened, ENT_NOQUOTES, 'UTF-8'),
                 $this->source,
                 1,
                 $reply_to
             );
 
+            if (isset($upload)) {
+                $upload->attachToNotice($this->notice);
+            }
+
             common_broadcast_notice($this->notice);
         }
 
@@ -210,7 +235,7 @@ class ApiStatusesUpdateAction extends ApiAuthAction
     {
         if (!empty($this->notice)) {
             if ($this->format == 'xml') {
-                $this->show_single_xml_status($this->notice);
+                $this->showSingleXmlStatus($this->notice);
             } elseif ($this->format == 'json') {
                 $this->show_single_json_status($this->notice);
             }