Web: use curl in get_other_projects() if fopen() is disallowed

The simplexml_load_file() call fails if allow_url_fopen is set to false and does not retrieve the statistics for the user. Curl is assumed to be available instead, if not, no information is shown to the user.
This commit is contained in:
Christian Beer 2015-12-03 07:45:23 +01:00
parent 0051de7db9
commit ecab174db8
1 changed files with 22 additions and 5 deletions

View File

@ -39,12 +39,29 @@ function get_other_projects($user) {
if ($cacheddata){ if ($cacheddata){
$remote = unserialize($cacheddata); $remote = unserialize($cacheddata);
} else { } else {
// Fetch the XML, then auto-cast the project list to an array of stdClass projects $xml_object = null;
$remote = false;
// Fetch the XML, use curl if fopen() is disallowed
// //
$timeout = 3; if (ini_get('allow_url_fopen')) {
$old_timeout = ini_set('default_socket_timeout', $timeout); $timeout = 3;
$remote = @json_decode(json_encode((array)simplexml_load_file($url)))->project; $old_timeout = ini_set('default_socket_timeout', $timeout);
ini_set('default_socket_timeout', $old_timeout); $xml_object = simplexml_load_file($url);
ini_set('default_socket_timeout', $old_timeout);
} else {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
$rawxml = curl_exec($ch);
$xml_object = simplexml_load_string($rawxml);
curl_close($ch);
}
// auto-cast the project list to an array of stdClass projects
//
$remote = @json_decode(json_encode((array)$xml_object))->project;
if (!$remote) { if (!$remote) {
return $user; return $user;