]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/newnotice.php
Clean up badly formatted strings in OembedAction
[quix0rs-gnu-social.git] / actions / newnotice.php
index 5100e79e1038ea05c994d7fb375ac2333ecad8a8..748d104ff9391de95bd017d1014dc2eb311a5e23 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...
@@ -164,40 +165,54 @@ class NewnoticeAction extends Action
         }
 
         $upload = null;
-
-        common_debug('looking for attachment');
-
         $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()
+                    )
+                );
+            }
+        }
 
-                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');
-                }
+        $options = array('reply_to' => ($replyto == 'false') ? null : $replyto);
+
+        if ($user->shareLocation()) {
+            // use browser data if checked; otherwise profile data
+            if ($this->arg('notice_data-geo')) {
+                $locOptions = Notice::locationOptions($this->trimmed('lat'),
+                                                      $this->trimmed('lon'),
+                                                      $this->trimmed('location_id'),
+                                                      $this->trimmed('location_ns'),
+                                                      $user->getProfile());
+            } else {
+                $locOptions = Notice::locationOptions(null,
+                                                      null,
+                                                      null,
+                                                      null,
+                                                      $user->getProfile());
+            }
+
+            $options = array_merge($options, $locOptions);
         }
 
-        $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1,
-                                  ($replyto == 'false') ? null : $replyto);
+        $notice = Notice::saveNew($user->id, $content_shortened, 'web', $options);
 
         if (isset($upload)) {
             $upload->attachToNotice($notice);
         }
 
-        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');
@@ -285,6 +300,9 @@ class NewnoticeAction extends Action
             if ($profile) {
                 $content = '@' . $profile->nickname . ' ';
             }
+        } else {
+            // @fixme most of these bits above aren't being passed on above
+            $inreplyto = null;
         }
 
         $notice_form = new NoticeForm($this, '', $content, null, $inreplyto);