From b506a2d662f53e4c91a2dca2ab602a0fa25824ca Mon Sep 17 00:00:00 2001 From: Hannes Magnusson Date: Sat, 7 Jun 2008 10:29:45 +0000 Subject: [PATCH] - Use file_get_contents() if possible - Set default context if possible (needed for get_headers()) --- include/site.inc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/include/site.inc b/include/site.inc index 301925037..8032b552f 100644 --- a/include/site.inc +++ b/include/site.inc @@ -177,12 +177,17 @@ function header_nocache() // Compatibility function to fetch data from external source function fetch_contents($url, $headers = false) { - if (version_compare(PHP_VERSION, '5.0.0', '>')) { - if(function_exists('file_get_contents') && ini_get('allow_url_fopen')) { - $opts = array('user_agent' => 'php.net'); - $context = stream_context_create(array('http' => $opts)); - $data = @file_get_contents($url, false, $context); + if(function_exists('file_get_contents') && ini_get('allow_url_fopen')) { + $context = null; + $opts = array('user_agent' => 'php.net'); + + if (version_compare(PHP_VERSION, '5.1.0', '>')) { + $context = stream_context_get_defaul(array('http' => $opts)); } + elseif (version_compare(PHP_VERSION, '5.0.0', '>')) { + $context = stream_context_create(array('http' => $opts)); + } + $data = @file_get_contents($url, false, $context); if ($headers) { return $http_response_header;