]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/shownotice.php
Improve ShownoticeAction remote redirect code
[quix0rs-gnu-social.git] / actions / shownotice.php
index 1f92978062755b8d538fe685d29e349d58aa97f5..b72f39513ed8e11db4c463e5e0ca928bd5b97948 100644 (file)
@@ -97,7 +97,6 @@ class ShownoticeAction extends Action
         if (empty($this->profile)) {
             // TRANS: Server error displayed trying to show a notice without a connected profile.
             $this->serverError(_('Notice has no profile.'), 500);
-            return false;
         }
 
         $this->user = User::getKV('id', $this->profile->id);
@@ -219,18 +218,13 @@ class ShownoticeAction extends Action
             $this->showAjax();
         } else {
             if ($this->notice->is_local == Notice::REMOTE) {
-                if (!empty($this->notice->url)) {
-                    $target = $this->notice->url;
-                } else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) {
-                    // Old OMB posts saved the remote URL only into the URI field.
-                    $target = $this->notice->uri;
-                } else {
-                    // Shouldn't happen.
-                    $target = false;
-                }
-                if ($target && $target != $this->selfUrl()) {
-                    common_redirect($target, 301);
-                    return false;
+                try {
+                    $target = $this->notice->getUrl()
+                    if ($target != $this->selfUrl()) {
+                        common_redirect($target, 301);
+                    }
+                } catch (InvalidUrlException $e) {
+                    common_debug('ShownoticeAction could not redirect to remote notice with id='.$this->notice->id . '. Falling back to showPage().');
                 }
             }
             $this->showPage();