E_WARNING: curl_setopt_array(): CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set
when open_basedir or safe_mode is set and enabled. Therefore this check should be made and the curl function changed. Patch is below (Sorry for not creating a fork - quite busy today)
/**
* Uses Curl to fetch data from an url
*
* @param string $url
* @return string
*
* @throws Exception when the returned status code is not 200 or no data was found
*/
protected function curl($url)
{
$defaultOptions = array(
CURLOPT_URL => $url,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => '',
CURLOPT_USERAGENT => 'Mozilla/5.0 PHP/Embera',
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => 1,
);
$handler = curl_init();
$use_redirect = false;
if(
(ini_get('safe_mode') || ini_get('open_basedir'))
&& (
((($is_options = isset($this->config['curl'][CURLOPT_FOLLOWLOCATION])) === true && $this->config['curl'][CURLOPT_FOLLOWLOCATION] === true))
|| (($is_defaults = isset($defaultOptions[CURLOPT_FOLLOWLOCATION])) === true && $defaultOptions[CURLOPT_FOLLOWLOCATION] === true)
)
)
{
$use_redirect = true;
if($is_options === true)
unset($this->config['curl'][CURLOPT_FOLLOWLOCATION]);
if($is_defaults === true)
unset($defaultOptions[CURLOPT_FOLLOWLOCATION]);
}
curl_setopt_array($handler, $defaultOptions);
if (!empty($this->config['curl']))
{
foreach ($this->config['curl'] as $key => $value)
curl_setopt($handler, $key, $value);
}
if($use_redirect === true)
{
return $this->curl_redirect($url, $handler);
}
return $this->curl_follow($url, $handler);
}
protected function curl_follow($url, $handler)
{
$data = curl_exec($handler);
$status = curl_getinfo($handler, CURLINFO_HTTP_CODE);
curl_close($handler);
if (empty($data) || !in_array($status, array('200')))
throw new \Exception($status . ': Invalid response for ' . $url);
return $data;
}
protected function curl_redirect($url, $handler)
{
curl_setopt($handler, CURLOPT_HEADER, true);
$data = curl_exec($handler);
$status = curl_getinfo($handler, CURLINFO_HTTP_CODE);
if($status == 301 || $status == 302)
{
list($header) = explode("\r\n\r\n", $data, 2);
$matches = array();
preg_match("/(Location:|URI:)[^\n]*/", $header, $matches);
$url = trim(str_replace($matches[1], "", $matches[0]));
$url_parsed = parse_url($url);
if(isset($url_parsed))
{
curl_setopt($handler, CURLOPT_URL, $url);
return $this->curl_redirect($url, $handler);
}
}
curl_close($handler);
list(, $body) = explode("\r\n\r\n", $data, 2);
if (empty($body) || !in_array($status, array('200')))
throw new \Exception($status . ': Invalid response for ' . $url);
return $body;
}