summaryrefslogtreecommitdiff
path: root/actions/apistatusesupdate.php
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2009-10-28 17:18:33 -0700
committerZach Copley <zach@status.net>2009-10-28 17:18:33 -0700
commit9ef05030fe623f18c64f9d24da1ebff04cf6cb62 (patch)
treea8171d9e19c19450384afe0e2f61ed4555f44c20 /actions/apistatusesupdate.php
parent10df75f9a074f2987b3525cd70a129bd26972ebb (diff)
parente5a2f895a074a6eaaf8184f101503b1520ed780b (diff)
Merge branch 'api-media-upload' into 0.9.x
* api-media-upload: Rearanged a couple things & removed debugging statements Rework MailDaemon to use the MediaFile class for uploads Implement media upload in the API Extract media upload stuff into its own library class.
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);
}