* @link http://status.net/
*/
-if (!defined('STATUSNET')) {
- exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Action for posting new notices
{
protected $form = 'Notice';
+ protected $inreplyto = null;
+
/**
* Title of the page
*
// TRANS: Page title after sending a notice.
return _('Notice posted');
}
+ if ($this->int('inreplyto')) {
+ return _m('TITLE', 'New reply');
+ }
// TRANS: Page title for sending a new notice.
return _m('TITLE','New notice');
}
$this->formOpts[$opt] = $this->trimmed($opt);
}
}
+
+ if ($this->int('inreplyto')) {
+ // Throws exception if the inreplyto Notice is given but not found.
+ $this->inreplyto = Notice::getByID($this->int('inreplyto'));
+ }
+
+ // Backwards compatibility for "share this" widget things.
+ // If no 'content', use 'status_textarea'
+ $this->formOpts['content'] = $this->trimmed('content') ?: $this->trimmed('status_textarea');
}
/**
- * This handlePost saves a new notice, based on arguments
+ * This doPost saves a new notice, based on arguments
*
* If successful, will show the notice, or return an Ajax-y result.
* If not, it will show an error message -- possibly Ajax-y.
*
* @return void
*/
- protected function handlePost()
+ protected function doPost()
{
- parent::handlePost();
-
- assert($this->scoped); // XXX: maybe an error instead...
+ assert($this->scoped instanceof Profile); // XXX: maybe an error instead...
$user = $this->scoped->getUser();
- $content = $this->trimmed('status_textarea');
- $options = array();
+ $content = $this->formOpts['content'];
+ $options = array('source' => 'web');
Event::handle('StartSaveNewNoticeWeb', array($this, $user, &$content, &$options));
- if (!$content) {
- // TRANS: Client error displayed trying to send a notice without content.
- $this->clientError(_('No content!'));
+ $upload = null;
+ try {
+ // throws exception on failure
+ $upload = MediaFile::fromUpload('attach', $this->scoped);
+ if (Event::handle('StartSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options))) {
+ $content .= ($content==='' ? '' : ' ') . $upload->shortUrl();
+ }
+ Event::handle('EndSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options));
+
+ // We could check content length here if the URL was added, but I'll just let it slide for now...
+
+ $act->enclosures[] = $upload->getEnclosure();
+ } catch (NoUploadedMediaException $e) {
+ // simply no attached media to the new notice
+ if (empty($content)) {
+ // TRANS: Client error displayed trying to send a notice without content.
+ throw new ClientException(_('No content!'));
+ }
}
$inter = new CommandInterpreter();
$cmd = $inter->handle_command($user, $content);
if ($cmd) {
- if (StatusNet::isAjax()) {
+ if (GNUsocial::isAjax()) {
$cmd->execute(new AjaxWebChannel($this));
} else {
$cmd->execute(new WebChannel($this));
return;
}
- $content_shortened = $user->shortenLinks($content);
- if (Notice::contentTooLong($content_shortened)) {
+ $act = new Activity();
+ $act->verb = ActivityVerb::POST;
+ $act->time = time();
+ $act->actor = $this->scoped->asActivityObject();
+
+ // Reject notice if it is too long (without the HTML)
+ // This is done after MediaFile::fromUpload etc. just to act the same as the ApiStatusesUpdateAction
+ if (Notice::contentTooLong($content)) {
// TRANS: Client error displayed when the parameter "status" is missing.
// TRANS: %d is the maximum number of character for a notice.
- $this->clientError(sprintf(_m('That\'s too long. Maximum notice size is %d character.',
- 'That\'s too long. Maximum notice size is %d characters.',
- Notice::maxContent()),
- Notice::maxContent()));
+ throw new ClientException(sprintf(_m('That\'s too long. Maximum notice size is %d character.',
+ 'That\'s too long. Maximum notice size is %d characters.',
+ Notice::maxContent()),
+ Notice::maxContent()));
}
- $replyto = intval($this->trimmed('inreplyto'));
- if ($replyto) {
- $options['reply_to'] = $replyto;
- }
-
- $upload = MediaFile::fromUpload('attach', $this->scoped);
-
- if (isset($upload)) {
+ $act->context = new ActivityContext();
- if (Event::handle('StartSaveNewNoticeAppendAttachment', array($this, $upload, &$content_shortened, &$options))) {
- $content_shortened .= ' ' . $upload->shortUrl();
- }
- Event::handle('EndSaveNewNoticeAppendAttachment', array($this, $upload, &$content_shortened, &$options));
-
- if (Notice::contentTooLong($content_shortened)) {
- $upload->delete();
- // TRANS: Client error displayed exceeding the maximum notice length.
- // TRANS: %d is the maximum length for a notice.
- $this->clientError(sprintf(_m('Maximum notice size is %d character, including attachment URL.',
- 'Maximum notice size is %d characters, including attachment URL.',
- Notice::maxContent()),
- Notice::maxContent()));
- }
+ if ($this->inreplyto instanceof Notice) {
+ $act->context->replyToID = $this->inreplyto->getUri();
+ $act->context->replyToUrl = $this->inreplyto->getUrl(true); // maybe we don't have to send true here to force a URL?
}
if ($this->scoped->shareLocation()) {
$this->scoped);
}
- $options = array_merge($options, $locOptions);
+ $act->context->location = Location::fromOptions($locOptions);
}
- $author_id = $this->scoped->id;
- $text = $content_shortened;
+ $content = $this->scoped->shortenLinks($content);
+
+ // FIXME: Make sure NoticeTitle plugin gets a change to add the title to our activityobject!
+ if (Event::handle('StartNoticeSaveWeb', array($this, $this->scoped, &$content, &$options))) {
- // Does the heavy-lifting for getting "To:" information
+ // FIXME: We should be able to get the attentions from common_render_content!
+ // and maybe even directly save whether they're local or not!
+ $act->context->attention = common_get_attentions($content, $this->scoped, $this->inreplyto);
- ToSelector::fillOptions($this, $options);
+ // $options gets filled with possible scoping settings
+ ToSelector::fillActivity($this, $act, $options);
- if (Event::handle('StartNoticeSaveWeb', array($this, &$author_id, &$text, &$options))) {
+ $actobj = new ActivityObject();
+ $actobj->type = ActivityObject::NOTE;
+ $actobj->content = common_render_content($content, $this->scoped, $this->inreplyto);
- $this->stored = Notice::saveNew($this->scoped->id, $content_shortened, 'web', $options);
+ // Finally add the activity object to our activity
+ $act->objects[] = $actobj;
- if (isset($upload)) {
+ $this->stored = Notice::saveActivity($act, $this->scoped, $options);
+
+ if ($upload instanceof MediaFile) {
$upload->attachToNotice($this->stored);
}
Event::handle('EndNoticeSaveWeb', array($this, $this->stored));
}
- Event::handle('EndSaveNewNoticeWeb', array($this, $user, &$content_shortened, &$options));
-
- if (!StatusNet::isAjax()) {
- $returnto = $this->trimmed('returnto');
+ Event::handle('EndSaveNewNoticeWeb', array($this, $user, &$content, &$options));
- if ($returnto) {
- $url = common_local_url($returnto,
- array('nickname' => $this->scoped->getNickname()));
- } else {
- $url = common_local_url('shownotice', array('notice' => $this->stored->id));
- }
+ if (!GNUsocial::isAjax()) {
+ $url = common_local_url('shownotice', array('notice' => $this->stored->id));
common_redirect($url, 303);
}
if ($this->getInfo() && $this->stored instanceof Notice) {
$this->showNotice($this->stored);
} elseif (!$this->getError()) {
+ if (!GNUsocial::isAjax() && $this->inreplyto instanceof Notice) {
+ $this->showNotice($this->inreplyto);
+ }
parent::showContent();
}
}