function _redirectWhere_imp($short_url, $redirs = 10, $protected = false) { if ($redirs < 0) { return false; } // let's see if we know this... $a = File::staticGet('url', $short_url); if (!empty($a)) { // this is a direct link to $a->url return $a->url; } else { $b = File_redirection::staticGet('url', $short_url); if (!empty($b)) { // this is a redirect to $b->file_id $a = File::staticGet('id', $b->file_id); return $a->url; } } $curlh = File_redirection::_commonCurl($short_url, $redirs); // Don't include body in output curl_setopt($curlh, CURLOPT_NOBODY, true); curl_exec($curlh); $info = curl_getinfo($curlh); curl_close($curlh); if (405 == $info['http_code']) { $curlh = File_redirection::_commonCurl($short_url, $redirs); curl_exec($curlh); $info = curl_getinfo($curlh); curl_close($curlh); } if (!empty($info['redirect_count']) && File::isProtected($info['url'])) { return File_redirection::_redirectWhere_imp($short_url, $info['redirect_count'] - 1, true); } $ret = array('code' => $info['http_code'], 'redirects' => $info['redirect_count'], 'url' => $info['url']); if (!empty($info['content_type'])) { $ret['type'] = $info['content_type']; } if ($protected) { $ret['protected'] = true; } if (!empty($info['download_content_length'])) { $ret['size'] = $info['download_content_length']; } if (isset($info['filetime']) && $info['filetime'] > 0) { $ret['time'] = $info['filetime']; } return $ret; }