]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/newnotice.php
Merge branch 'nightly' into 'nightly'
[quix0rs-gnu-social.git] / actions / newnotice.php
index 17499312fbcbd45ea1157cba0e6a87010d468d5a..170e5bcdf8f519de4fbc596985b532e6ed41fcbb 100644 (file)
@@ -47,6 +47,8 @@ class NewnoticeAction extends FormAction
 {
     protected $form = 'Notice';
 
+    protected $inreplyto = null;
+
     /**
      * Title of the page
      *
@@ -75,6 +77,11 @@ class NewnoticeAction extends FormAction
             }
         }
 
+        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');
@@ -95,13 +102,28 @@ class NewnoticeAction extends FormAction
     {
         assert($this->scoped instanceof Profile); // XXX: maybe an error instead...
         $user = $this->scoped->getUser();
-        $content = $this->trimmed('status_textarea');
+        $content = $this->formOpts['content'];
         $options = array('source' => 'web');
         Event::handle('StartSaveNewNoticeWeb', array($this, $user, &$content, &$options));
 
-        if (empty($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();
@@ -117,56 +139,27 @@ class NewnoticeAction extends FormAction
             return;
         }
 
-        if ($this->int('inreplyto')) {
-            // Throws exception if the inreplyto Notice is given but not found.
-            $parent = Notice::getByID($this->int('inreplyto'));
-        } else {
-            $parent = null;
-        }
-
         $act = new Activity();
         $act->verb = ActivityVerb::POST;
         $act->time = time();
         $act->actor = $this->scoped->asActivityObject();
 
-        $content = $this->scoped->shortenLinks($content);
-
-        $upload = null;
-        try {
-            // throws exception on failure
-            $upload = MediaFile::fromUpload('attach', $this->scoped);
-            if (Event::handle('StartSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options))) {
-                $content .= ' ' . $upload->shortUrl();
-            }
-            Event::handle('EndSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options));
-
-            if (Notice::contentTooLong($content)) {
-                $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()));
-            }
-
-            $act->enclosures[] = $upload->getEnclosure();
-        } catch (NoUploadedMediaException $e) {
-            // simply no attached media to the new notice
+        // 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->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()) {
@@ -188,15 +181,24 @@ class NewnoticeAction extends FormAction
             $act->context->location = Location::fromOptions($locOptions);
         }
 
-        $author_id = $this->scoped->id;
-        $text      = $content;
+        $content = $this->scoped->shortenLinks($content);
 
-        // Does the heavy-lifting for getting "To:" information
+        // 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))) {
 
-        ToSelector::fillOptions($this, $options);
+            // 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);
 
-        // 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))) {
+            // $options gets filled with possible scoping settings
+            ToSelector::fillActivity($this, $act, $options);
+
+            $actobj = new ActivityObject();
+            $actobj->type = ActivityObject::NOTE;
+            $actobj->content = common_render_content($content, $this->scoped, $this->inreplyto);
+
+            // Finally add the activity object to our activity
+            $act->objects[] = $actobj;
 
             $this->stored = Notice::saveActivity($act, $this->scoped, $options);
 
@@ -222,6 +224,9 @@ class NewnoticeAction extends FormAction
         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();
         }
     }