summaryrefslogtreecommitdiff
path: root/actions/apistatusesupdate.php
diff options
context:
space:
mode:
Diffstat (limited to 'actions/apistatusesupdate.php')
-rw-r--r--actions/apistatusesupdate.php64
1 files changed, 44 insertions, 20 deletions
diff --git a/actions/apistatusesupdate.php b/actions/apistatusesupdate.php
index 0d71e1512..3a030f0fe 100644
--- a/actions/apistatusesupdate.php
+++ b/actions/apistatusesupdate.php
@@ -38,6 +38,7 @@ if (!defined('STATUSNET')) {
}
require_once INSTALLDIR . '/lib/apiauth.php';
+require_once INSTALLDIR . '/lib/mediafile.php';
/**
* Updates the authenticating user's status (posts a notice).
@@ -60,7 +61,6 @@ class ApiStatusesUpdateAction extends ApiAuthAction
var $source = null;
var $status = null;
var $in_reply_to_status_id = null;
-
static $reserved_sources = array('web', 'omb', 'mail', 'xmpp', 'api');
/**
@@ -76,25 +76,8 @@ class ApiStatusesUpdateAction extends ApiAuthAction
{
parent::prepare($args);
- $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)) {
@@ -129,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)) {
@@ -187,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);
}