]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/newnotice.php
Prepopulate newnotice from URL arg
[quix0rs-gnu-social.git] / actions / newnotice.php
index 81438502fa67639d4ba28a9934ff22bae960dcd0..0432064a42b9df2ae9154d8120f7170f0da3a1ff 100644 (file)
@@ -69,10 +69,14 @@ class NewnoticeAction extends FormAction
     protected function doPreparation()
     {
         foreach(array('inreplyto') as $opt) {
-            if (!empty($this->trimmed($opt))) {
+            if ($this->trimmed($opt)) {
                 $this->formOpts[$opt] = $this->trimmed($opt);
             }
         }
+
+        if ($this->trimmed('content')) {
+            $this->formOpts['content'] = $this->trimmed('content');
+        }
     }
 
     /**
@@ -129,10 +133,10 @@ class NewnoticeAction extends FormAction
             $options['reply_to'] = $replyto;
         }
 
-        $upload = MediaFile::fromUpload('attach', $this->scoped);
-
-        if (isset($upload)) {
-
+        $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();
             }
@@ -147,8 +151,11 @@ class NewnoticeAction extends FormAction
                                               Notice::maxContent()),
                                            Notice::maxContent()));
             }
+        } catch (NoUploadedMediaException $e) {
+            // simply no attached media to the new notice
         }
 
+
         if ($this->scoped->shareLocation()) {
             // use browser data if checked; otherwise profile data
             if ($this->arg('notice_data-geo')) {
@@ -179,7 +186,7 @@ class NewnoticeAction extends FormAction
 
             $this->stored = Notice::saveNew($this->scoped->id, $content_shortened, 'web', $options);
 
-            if (isset($upload)) {
+            if ($upload instanceof MediaFile) {
                 $upload->attachToNotice($this->stored);
             }
 
@@ -189,14 +196,7 @@ class NewnoticeAction extends FormAction
         Event::handle('EndSaveNewNoticeWeb', array($this, $user, &$content_shortened, &$options));
 
         if (!StatusNet::isAjax()) {
-            $returnto = $this->trimmed('returnto');
-
-            if ($returnto) {
-                $url = common_local_url($returnto,
-                                        array('nickname' => $this->scoped->getNickname()));
-            } else {
-                $url = common_local_url('shownotice', array('notice' => $this->stored->id));
-            }
+            $url = common_local_url('shownotice', array('notice' => $this->stored->id));
             common_redirect($url, 303);
         }
 
@@ -226,4 +226,9 @@ class NewnoticeAction extends FormAction
         $nli = new NoticeListItem($notice, $this);
         $nli->show();
     }
+
+    public function showNoticeForm()
+    {
+        // pass
+    }
 }