123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class NewnoticeAction extends FormAction
- {
- protected $form = 'Notice';
- protected $inreplyto = null;
-
- function title()
- {
- if ($this->getInfo() && $this->stored instanceof Notice) {
-
- return _('Notice posted');
- }
- if ($this->int('inreplyto')) {
- return _m('TITLE', 'New reply');
- }
-
- return _m('TITLE','New notice');
- }
- protected function doPreparation()
- {
- foreach(array('inreplyto') as $opt) {
- if ($this->trimmed($opt)) {
- $this->formOpts[$opt] = $this->trimmed($opt);
- }
- }
- if ($this->int('inreplyto')) {
-
- $this->inreplyto = Notice::getByID($this->int('inreplyto'));
- }
-
-
- $this->formOpts['content'] = $this->trimmed('content') ?: $this->trimmed('status_textarea');
- }
-
- protected function doPost()
- {
- assert($this->scoped instanceof Profile);
- $user = $this->scoped->getUser();
- $content = $this->formOpts['content'];
- $options = array('source' => 'web');
- Event::handle('StartSaveNewNoticeWeb', array($this, $user, &$content, &$options));
- $upload = null;
- try {
-
- $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));
-
- $act->enclosures[] = $upload->getEnclosure();
- } catch (NoUploadedMediaException $e) {
-
- if (empty($content)) {
-
- throw new ClientException(_('No content!'));
- }
- }
- $inter = new CommandInterpreter();
- $cmd = $inter->handle_command($user, $content);
- if ($cmd) {
- if (GNUsocial::isAjax()) {
- $cmd->execute(new AjaxWebChannel($this));
- } else {
- $cmd->execute(new WebChannel($this));
- }
- return;
- }
- $act = new Activity();
- $act->verb = ActivityVerb::POST;
- $act->time = time();
- $act->actor = $this->scoped->asActivityObject();
-
-
- if (Notice::contentTooLong($content)) {
-
-
- 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()));
- }
- $act->context = new ActivityContext();
- if ($this->inreplyto instanceof Notice) {
- $act->context->replyToID = $this->inreplyto->getUri();
- $act->context->replyToUrl = $this->inreplyto->getUrl(true);
- }
- if ($this->scoped->shareLocation()) {
-
- if ($this->arg('notice_data-geo')) {
- $locOptions = Notice::locationOptions($this->trimmed('lat'),
- $this->trimmed('lon'),
- $this->trimmed('location_id'),
- $this->trimmed('location_ns'),
- $this->scoped);
- } else {
- $locOptions = Notice::locationOptions(null,
- null,
- null,
- null,
- $this->scoped);
- }
- $act->context->location = Location::fromOptions($locOptions);
- }
- $content = $this->scoped->shortenLinks($content);
-
- if (Event::handle('StartNoticeSaveWeb', array($this, $this->scoped, &$content, &$options))) {
-
-
- $act->context->attention = common_get_attentions($content, $this->scoped, $this->inreplyto);
-
- ToSelector::fillActivity($this, $act, $options);
- $actobj = new ActivityObject();
- $actobj->type = ActivityObject::NOTE;
- $actobj->content = common_render_content($content, $this->scoped, $this->inreplyto);
-
- $act->objects[] = $actobj;
- $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, &$options));
- if (!GNUsocial::isAjax()) {
- $url = common_local_url('shownotice', array('notice' => $this->stored->id));
- common_redirect($url, 303);
- }
- return _('Saved the notice!');
- }
- protected function showContent()
- {
- 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();
- }
- }
-
- function showNotice(Notice $notice)
- {
- $nli = new NoticeListItem($notice, $this);
- $nli->show();
- }
- public function showNoticeForm()
- {
-
- }
- }
|