- $this->notice = Notice::saveNew(
- $this->user->id,
- html_entity_decode($this->status, ENT_NOQUOTES, 'UTF-8'),
- $this->source,
- 1,
- $reply_to
- );
+ $upload = null;
+
+ try {
+ $upload = MediaFile::fromUpload('media', $this->auth_user);
+ } catch (ClientException $ce) {
+ $this->clientError($ce->getMessage());
+ return;
+ }
+
+ 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()));
+ }
+ }
+
+ $content = html_entity_decode($status_shortened, ENT_NOQUOTES, 'UTF-8');
+
+ $options = array('reply_to' => $reply_to);
+
+ if ($this->auth_user->shareLocation()) {
+
+ $locOptions = Notice::locationOptions($this->lat,
+ $this->lon,
+ null,
+ null,
+ $this->auth_user->getProfile());
+
+ $options = array_merge($options, $locOptions);
+ }
+
+ $this->notice =
+ Notice::saveNew($this->auth_user->id,
+ $content,
+ $this->source,
+ $options);
+
+ if (isset($upload)) {
+ $upload->attachToNotice($this->notice);
+ }