[ticket/11603] Avoid using cURL

PHPBB3-11603
This commit is contained in:
Joas Schilling 2013-06-19 13:38:03 +02:00
parent a7af0134c0
commit 1516ae7e7e
2 changed files with 19 additions and 19 deletions

View file

@ -124,13 +124,16 @@ function get_repository_url($username, $repository, $ssh = false)
function api_request($query) function api_request($query)
{ {
$c = curl_init(); return api_url_request("https://api.github.com/$query?per_page=100");
curl_setopt($c, CURLOPT_URL, "https://api.github.com/$query"); }
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_USERAGENT, 'phpBB/1.0'); function api_url_request($url)
curl_setopt($c, CURLOPT_HEADER, true); {
$contents = curl_exec($c); $contents = file_get_contents($url, false, stream_context_create(array(
curl_close($c); 'http' => array(
'header' => "User-Agent: phpBB/1.0\r\n",
),
)));
if ($contents === false) if ($contents === false)
{ {

View file

@ -150,20 +150,17 @@ function api_request($query)
function api_url_request($url) function api_url_request($url)
{ {
$c = curl_init(); $contents = file_get_contents($url, false, stream_context_create(array(
curl_setopt($c, CURLOPT_URL, $url); 'http' => array(
curl_setopt($c, CURLOPT_RETURNTRANSFER, true); 'header' => "User-Agent: phpBB/1.0\r\n",
curl_setopt($c, CURLOPT_USERAGENT, 'phpBB/1.0'); ),
curl_setopt($c, CURLOPT_HEADER, true); )));
$contents = curl_exec($c);
curl_close($c);
$sub_request_result = array(); $sub_request_result = array();
// Split possible headers from the body // Split possible headers from the body
if ($contents && strpos($contents, "\r\n\r\n") > 0) if (!empty($http_response_header))
{ {
list($header, $contents) = explode("\r\n\r\n", $contents); foreach ($http_response_header as $header_element)
foreach (explode("\n", $header) as $header_element)
{ {
// Find Link Header which gives us a link to the next page // Find Link Header which gives us a link to the next page
if (strpos($header_element, 'Link: ') === 0) if (strpos($header_element, 'Link: ') === 0)