diff options
Diffstat (limited to 'lib/private/util.php')
-rwxr-xr-x | lib/private/util.php | 100 |
1 files changed, 6 insertions, 94 deletions
diff --git a/lib/private/util.php b/lib/private/util.php index c5483c1654b..f84bbede0ac 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -5,8 +5,6 @@ * */ class OC_Util { - const USER_AGENT = 'ownCloud Server Crawler'; - public static $scripts = array(); public static $styles = array(); public static $headers = array(); @@ -1199,106 +1197,20 @@ class OC_Util { } /** - * @Brief Get file content via curl. + * Get URL content * @param string $url Url to get content + * @deprecated Use \OC::$server->getHTTPHelper()->getUrlContent($url); * @throws Exception If the URL does not start with http:// or https:// * @return string of the response or false on error * This function get the content of a page via curl, if curl is enabled. * If not, file_get_contents is used. */ public static function getUrlContent($url) { - if (strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) { - throw new Exception('$url must start with https:// or http://', 1); - } - - if (function_exists('curl_init')) { - $curl = curl_init(); - $max_redirects = 10; - - curl_setopt($curl, CURLOPT_HEADER, 0); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); - curl_setopt($curl, CURLOPT_URL, $url); - - - curl_setopt($curl, CURLOPT_USERAGENT, self::USER_AGENT); - if (OC_Config::getValue('proxy', '') != '') { - curl_setopt($curl, CURLOPT_PROXY, OC_Config::getValue('proxy')); - } - if (OC_Config::getValue('proxyuserpwd', '') != '') { - curl_setopt($curl, CURLOPT_PROXYUSERPWD, OC_Config::getValue('proxyuserpwd')); - } - - if (ini_get('open_basedir') === '' && ini_get('safe_mode') === 'Off') { - curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($curl, CURLOPT_MAXREDIRS, $max_redirects); - $data = curl_exec($curl); - } else { - curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false); - $mr = $max_redirects; - if ($mr > 0) { - $newURL = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL); - $rcurl = curl_copy_handle($curl); - curl_setopt($rcurl, CURLOPT_HEADER, true); - curl_setopt($rcurl, CURLOPT_NOBODY, true); - curl_setopt($rcurl, CURLOPT_FORBID_REUSE, false); - curl_setopt($rcurl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($rcurl, CURLOPT_USERAGENT, self::USER_AGENT); - do { - curl_setopt($rcurl, CURLOPT_URL, $newURL); - $header = curl_exec($rcurl); - if (curl_errno($rcurl)) { - $code = 0; - } else { - $code = curl_getinfo($rcurl, CURLINFO_HTTP_CODE); - if ($code == 301 || $code == 302) { - preg_match('/Location:(.*?)\n/', $header, $matches); - $newURL = trim(array_pop($matches)); - } else { - $code = 0; - } - } - } while ($code && --$mr); - curl_close($rcurl); - if ($mr > 0) { - curl_setopt($curl, CURLOPT_URL, $newURL); - } - } - - if ($mr == 0 && $max_redirects > 0) { - $data = false; - } else { - $data = curl_exec($curl); - } - } - curl_close($curl); - } else { - $contextArray = null; - - if (OC_Config::getValue('proxy', '') != '') { - $contextArray = array( - 'http' => array( - 'header' => 'User-Agent: ' . self::USER_AGENT . "\r\n", - 'timeout' => 10, - 'proxy' => OC_Config::getValue('proxy') - ) - ); - } else { - $contextArray = array( - 'http' => array( - 'header' => 'User-Agent: ' . self::USER_AGENT . "\r\n", - 'timeout' => 10 - ) - ); - } - - $ctx = stream_context_create( - $contextArray - ); - $data = @file_get_contents($url, 0, $ctx); - + try { + return \OC::$server->getHTTPHelper()->getUrlContent($url); + } catch (\Exception $e) { + throw $e; } - return $data; } /** |