]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/newnotice.php
Fix fatal error on OMB subscription for first-timers
[quix0rs-gnu-social.git] / actions / newnotice.php
index 5100e79e1038ea05c994d7fb375ac2333ecad8a8..dd6da0b01c1b438f91b8904e5abb85bbbce4244c 100644 (file)
@@ -134,18 +134,12 @@ class NewnoticeAction extends Action
 
         if (!$content) {
             $this->clientError(_('No content!'));
-        } else {
-            $content_shortened = common_shorten_links($content);
-            if (Notice::contentTooLong($content_shortened)) {
-                $this->clientError(sprintf(_('That\'s too long. '.
-                                             'Max notice size is %d chars.'),
-                                           Notice::maxContent()));
-            }
+            return;
         }
 
         $inter = new CommandInterpreter();
 
-        $cmd = $inter->handle_command($user, $content_shortened);
+        $cmd = $inter->handle_command($user, $content);
 
         if ($cmd) {
             if ($this->boolean('ajax')) {
@@ -156,6 +150,13 @@ class NewnoticeAction extends Action
             return;
         }
 
+        $content_shortened = common_shorten_links($content);
+        if (Notice::contentTooLong($content_shortened)) {
+            $this->clientError(sprintf(_('That\'s too long. '.
+                                         'Max notice size is %d chars.'),
+                                       Notice::maxContent()));
+        }
+
         $replyto = $this->trimmed('inreplyto');
         #If an ID of 0 is wrongly passed here, it will cause a database error,
         #so override it...
@@ -163,32 +164,33 @@ class NewnoticeAction extends Action
             $replyto = 'false';
         }
 
-        $upload = null;
-
-        common_debug('looking for attachment');
+        $lat = $this->trimmed('lat');
+        $lon = $this->trimmed('lon');
+        $location_id = $this->trimmed('location_id');
+        $location_ns = $this->trimmed('location_ns');
 
+        $upload = null;
         $upload = MediaFile::fromUpload('attach');
 
-        common_debug("uploaded file = " . var_export($upload, true));
-
         if (isset($upload)) {
-            common_debug('newNotice: found an upload');
 
-                $content_shortened .= ' ' . $upload->shortUrl();
+            $content_shortened .= ' ' . $upload->shortUrl();
 
-                common_debug('content w/upload = ' . $content_shortened);
-
-                if (Notice::contentTooLong($content_shortened)) {
-                    $upload->delete();
-                    $this->clientError(sprintf(_('Max notice size is %d chars, including attachment URL.'),
-                                               Notice::maxContent()));
-                } else {
-                    common_debug('content not too long');
-                }
+            if (Notice::contentTooLong($content_shortened)) {
+                $upload->delete();
+                $this->clientError(
+                    sprintf(
+                        _('Max notice size is %d chars, including attachment URL.'),
+                          Notice::maxContent()
+                    )
+                );
+            }
         }
 
         $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1,
-                                  ($replyto == 'false') ? null : $replyto);
+                                  ($replyto == 'false') ? null : $replyto,
+                                  null, null,
+                                  $lat, $lon, $location_id, $location_ns);
 
         if (isset($upload)) {
             $upload->attachToNotice($notice);
@@ -197,7 +199,9 @@ class NewnoticeAction extends Action
         common_broadcast_notice($notice);
 
         if ($this->boolean('ajax')) {
-            $this->startHTML('text/xml;charset=utf-8');
+            header('Content-Type: text/xml;charset=utf-8');
+            $this->xw->startDocument('1.0', 'UTF-8');
+            $this->elementStart('html');
             $this->elementStart('head');
             $this->element('title', null, _('Notice posted'));
             $this->elementEnd('head');