]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Improve ShownoticeAction remote redirect code
authorMikael Nordfeldth <mmn@hethane.se>
Sat, 19 Apr 2014 20:13:48 +0000 (22:13 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sat, 19 Apr 2014 20:13:48 +0000 (22:13 +0200)
actions/shownotice.php
classes/Notice.php

index d86e98080bad9efc1c7653f8806a06415ded1258..b72f39513ed8e11db4c463e5e0ca928bd5b97948 100644 (file)
@@ -218,17 +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);
+                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();
index 99d44b6cff8fbc8c719fb58d75eaff937f63314e..e46ed227a179cbb4cd4f9119a2b2bcb4a7e13ffd 100644 (file)
@@ -224,7 +224,7 @@ class Notice extends Managed_DataObject
             return $this->uri;
         default:
             common_debug('No URL available for notice: id='.$this->id);
-            throw new ServerException('No URL available for notice.');
+            throw new InvalidUrlException($this->url);
         }
     }