- $ret = File_redirection::lookupWhere($in_url);
- return $ret;
- } else {
- // No manual dereferencing; leave the unknown URL as is.
- return $in_url;
+ $redir_info = File_redirection::lookupWhere($in_url);
+ if(is_string($redir_info)) {
+ $redir_info = array('url' => $redir_info);
+ }
+
+ // Double check that we don't already have the resolved URL
+ $r = self::where($redir_info['url'], false);
+ if (!empty($r->file_id)) {
+ return $r;
+ }
+
+ $redir->httpcode = $redir_info['code'];
+ $redir->redirections = intval($redir_info['redirects']);
+ $redir->file = new File();
+ $redir->file->url = $redir_info ? $redir_info['url'] : $in_url;
+ $redir->file->mimetype = $redir_info['type'];
+ $redir->file->size = $redir_info['size'];
+ $redir->file->date = $redir_info['time'];
+ if ($redir_info['protected']) {
+ $redir->file->protected = true;
+ }