]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/File_redirection.php
Merge branch 'profile' into 'nightly'
[quix0rs-gnu-social.git] / classes / File_redirection.php
index 32c9cc7a3ad4e31b614877066b604e467b5d4127..742a6143cc43a93278c579accf90faf891914861 100644 (file)
@@ -120,6 +120,8 @@ class File_redirection extends Managed_DataObject
                 // no content it'll be cheap. :)
                 $request = self::_commonHttp($short_url, $redirs);
                 $response = $request->send();
+            } elseif (400 == $response->getStatus()) {
+                throw new Exception('Got error 400 on HEAD request, will not go further.');
             }
         } catch (Exception $e) {
             // Invalid URL or failure to reach server
@@ -170,19 +172,21 @@ class File_redirection extends Managed_DataObject
 
         try {
             $r = File_redirection::getByUrl($in_url);
+
             try {
-                $f = File::getKV('id',$r->file_id);
+                $f = File::getByID($r->file_id);
                 $r->file = $f;
                 $r->redir_url = $f->url;
             } catch (NoResultException $e) {
                 // Invalid entry, delete and run again
                 common_log(LOG_ERR, "Could not find File with id=".$r->file_id." referenced in File_redirection, deleting File redirection entry and and trying again...");                 
                 $r->delete();
-                return self::where($in_url);
+                return self::where($in_url);            
             }
+            
             // File_redirecion and File record found, return both
             return $r;
-
+            
         } catch (NoResultException $e) {
             // File_redirecion record not found, but this might be a direct link to a file
             try {
@@ -207,15 +211,17 @@ class File_redirection extends Managed_DataObject
             // in that case we have the file id already
             try {
                 $r = File_redirection::getByUrl($redir_info['url']);
-                try {
-                    $f = File::getKV('id',$r->file_id);
+                
+                $f = File::getKV('id',$r->file_id);
+                
+                if($f instanceof File) {
                     $redir->file = $f;
-                    $redir->redir_url = $f->url;
-                } catch (NoResultException $e) {
+                    $redir->redir_url = $f->url;                
+                } else {
                     // Invalid entry in File_redirection, delete and run again
                     common_log(LOG_ERR, "Could not find File with id=".$r->file_id." referenced in File_redirection, deleting File_redirection entry and trying again...");                 
                     $r->delete();
-                    return self::where($in_url);
+                    return self::where($in_url);                
                 }
             } catch (NoResultException $e) {
                 // save the file now when we know that we don't have it in File_redirection
@@ -363,6 +369,11 @@ class File_redirection extends Managed_DataObject
                 // don't touch anything
                 break;
 
+            // URLs with coordinates, not browsable domain names
+            case 'geo':
+                // don't touch anything
+                break;
+
             default:
                 $out_url = $default_scheme . ltrim($out_url, '/');
                 $p = parse_url($out_url);
@@ -434,10 +445,10 @@ class File_redirection extends Managed_DataObject
     }
 
     public function getFile() {
-        if(empty($this->file) && $this->file_id) {
-            $this->file = File::getKV('id', $this->file_id);
+        if (!$this->file instanceof File) {
+            $this->file = File::getByID($this->file_id);
         }
 
         return $this->file;
     }
-}
\ No newline at end of file
+}