123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class NewnoticeAction extends FormAction
- {
- protected $form = 'Notice';
-
- function title()
- {
- if ($this->getInfo() && $this->stored instanceof Notice) {
-
- return _('Notice posted');
- }
-
- return _m('TITLE','New notice');
- }
- protected function doPreparation()
- {
- foreach(array('inreplyto') as $opt) {
- if ($this->trimmed($opt)) {
- $this->formOpts[$opt] = $this->trimmed($opt);
- }
- }
-
-
- $this->formOpts['content'] = $this->trimmed('content') ?: $this->trimmed('status_textarea');
- }
-
- protected function handlePost()
- {
- parent::handlePost();
- assert($this->scoped);
- $user = $this->scoped->getUser();
- $content = $this->trimmed('status_textarea');
- $options = array();
- Event::handle('StartSaveNewNoticeWeb', array($this, $user, &$content, &$options));
- if (!$content) {
-
- $this->clientError(_('No content!'));
- }
- $inter = new CommandInterpreter();
- $cmd = $inter->handle_command($user, $content);
- if ($cmd) {
- if (StatusNet::isAjax()) {
- $cmd->execute(new AjaxWebChannel($this));
- } else {
- $cmd->execute(new WebChannel($this));
- }
- return;
- }
- $content_shortened = $user->shortenLinks($content);
- if (Notice::contentTooLong($content_shortened)) {
-
-
- $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()));
- }
- $replyto = intval($this->trimmed('inreplyto'));
- if ($replyto) {
- $options['reply_to'] = $replyto;
- }
- $upload = null;
- try {
-
- $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();
-
-
- $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()));
- }
- } catch (NoUploadedMediaException $e) {
-
- }
- 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);
- }
- $options = array_merge($options, $locOptions);
- }
- $author_id = $this->scoped->id;
- $text = $content_shortened;
-
- ToSelector::fillOptions($this, $options);
- if (Event::handle('StartNoticeSaveWeb', array($this, &$author_id, &$text, &$options))) {
- $this->stored = Notice::saveNew($this->scoped->id, $content_shortened, 'web', $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()) {
- $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()) {
- parent::showContent();
- }
- }
-
- function showNotice(Notice $notice)
- {
- $nli = new NoticeListItem($notice, $this);
- $nli->show();
- }
- public function showNoticeForm()
- {
-
- }
- }
|