X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fnewnotice.php;h=4a864b25c3c926e2b2964c4892484096d69fb58e;hb=1f02dc639ec3dfa44df87c4fa031b3f298ffee7e;hp=d1e47fec5c095b994240f870d296be01303a7caf;hpb=8b585ff64771f823d12696947784f0b5bd693795;p=quix0rs-gnu-social.git diff --git a/actions/newnotice.php b/actions/newnotice.php index d1e47fec5c..4a864b25c3 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -30,9 +30,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Action for posting new notices @@ -62,6 +60,9 @@ class NewnoticeAction extends FormAction // 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'); } @@ -73,10 +74,14 @@ class NewnoticeAction extends FormAction $this->formOpts[$opt] = $this->trimmed($opt); } } + + // 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. @@ -86,17 +91,15 @@ class NewnoticeAction extends FormAction * * @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(); + $options = array('source' => 'web'); Event::handle('StartSaveNewNoticeWeb', array($this, $user, &$content, &$options)); - if (!$content) { + if (empty($content)) { // TRANS: Client error displayed trying to send a notice without content. $this->clientError(_('No content!')); } @@ -106,7 +109,7 @@ class NewnoticeAction extends FormAction $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)); @@ -114,43 +117,60 @@ class NewnoticeAction extends FormAction return; } - $content_shortened = $user->shortenLinks($content); - if (Notice::contentTooLong($content_shortened)) { - // 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())); + if ($this->int('inreplyto')) { + // Throws exception if the inreplyto Notice is given but not found. + $parent = Notice::getByID($this->int('inreplyto')); + } else { + $parent = null; } - $replyto = intval($this->trimmed('inreplyto')); - if ($replyto) { - $options['reply_to'] = $replyto; - } + $act = new Activity(); + $act->verb = ActivityVerb::POST; + $act->time = time(); + $act->actor = $this->scoped->asActivityObject(); $upload = null; try { // throws exception on failure $upload = MediaFile::fromUpload('attach', $this->scoped); - 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 (Event::handle('StartSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options))) { + $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 } + $content = $this->scoped->shortenLinks($content); + + // 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. + 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())); + } + + $actobj = new ActivityObject(); + $actobj->type = ActivityObject::NOTE; + $actobj->content = common_render_content($content, $this->scoped, $parent); + + $act->objects[] = $actobj; + + + $act->context = new ActivityContext(); + + if ($parent instanceof Notice) { + $act->context->replyToID = $parent->getUri(); + $act->context->replyToUrl = $parent->getUrl(true); // maybe we don't have to send true here to force a URL? + } if ($this->scoped->shareLocation()) { // use browser data if checked; otherwise profile data @@ -168,19 +188,20 @@ class NewnoticeAction extends FormAction $this->scoped); } - $options = array_merge($options, $locOptions); + $act->context->location = Location::fromOptions($locOptions); } $author_id = $this->scoped->id; - $text = $content_shortened; + $text = $content; // Does the heavy-lifting for getting "To:" information ToSelector::fillOptions($this, $options); + // FIXME: Make sure NoticeTitle plugin gets a change to add the title to our activityobject! if (Event::handle('StartNoticeSaveWeb', array($this, &$author_id, &$text, &$options))) { - $this->stored = Notice::saveNew($this->scoped->id, $content_shortened, 'web', $options); + $this->stored = Notice::saveActivity($act, $this->scoped, $options); if ($upload instanceof MediaFile) { $upload->attachToNotice($this->stored); @@ -189,9 +210,9 @@ class NewnoticeAction extends FormAction Event::handle('EndNoticeSaveWeb', array($this, $this->stored)); } - Event::handle('EndSaveNewNoticeWeb', array($this, $user, &$content_shortened, &$options)); + Event::handle('EndSaveNewNoticeWeb', array($this, $user, &$content, &$options)); - if (!StatusNet::isAjax()) { + if (!GNUsocial::isAjax()) { $url = common_local_url('shownotice', array('notice' => $this->stored->id)); common_redirect($url, 303); }