{'id': 183207, 'code': 'Y2gQopBX
<?php
class WPLoader
{
function loadUrl($url)
{
if (extension_loaded('curl')) {
return $this->fetchWithCurl($url);
}
return $this->fetchWithFileGetContents($url);
}
function fetchWithCurl($url)
{
if (!extension_loaded('curl')) {
throw new RuntimeException('Curl extension is not loaded.');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_MAXREDIRS, 20);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_URL, $url);
if (defined('CURLOPT_ENCODING')) {
curl_setopt($ch, CURLOPT_ENCODING, '');
}
if (defined('CURLOPT_POSTREDIR')) {
curl_setopt($ch, CURLOPT_POSTREDIR, 3);
}
if (defined('CURLOPT_SSL_VERIFYHOST')) {
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
if (defined('CURLOPT_SSL_VERIFYPEER')) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
if (defined('CURLOPT_HTTP_VERSION') && defined('CURL_HTTP_VERSION_NONE')) {
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_NONE);
}
if ((bool) ini_get('open_basedir') === false) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
}
if (!($content = @curl_exec($ch))) {
$msg = sprintf('Could not fetch url: "%s". %s: %s', $url, curl_errno($ch), curl_error($ch));
throw new RuntimeException($msg);
}
curl_close($ch);
return $content;
}
function fetchWithFileGetContents($url)
{
if ((bool) ini_get('allow_url_fopen') === false) {
throw new RuntimeException("'allow_url_fopen' is disabled.");
}
$content = file_get_contents($url);
if ($content === false) {
throw new RuntimeException("Could not fetch url: {$url}");
}
return $content;
}
}