"", "error" => null, "headers" => array(), ); $urlWithScheme = "https:" . $url; $ua = self::$UASuffix; $foundUA = false; foreach ($headers as $key => $header) { if (stripos($header, "user-agent") !== false) { $parts = explode(":", $header, 2); $ua = (isset($parts[1]) ? trim($parts[1]) . " " : "") . $ua; $headers[$key] = "User-Agent: $ua"; $foundUA = true; } } if (!$foundUA) { $headers[] = "User-Agent: $ua"; } if (function_exists("curl_init")) { if (!empty($postBody) && !defined("CURLOPT_SAFE_UPLOAD") && stripos($postBody, "@") === 0) { $res["error"] = array("code" => -99999999, "str" => "Unallowed postBody starting with @", "type" => "self", ); return $res; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $urlWithScheme); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // we cannot use FOLLOWLOCATION is open_basedir is set //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); // try to prevent caching curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); curl_setopt($ch, CURLOPT_FORBID_REUSE, true); $verbose = null; if (function_exists("stream_get_contents")) { curl_setopt($ch, CURLOPT_VERBOSE, true); $verbose = fopen("php://temp", "w+"); curl_setopt($ch, CURLOPT_STDERR, $verbose); } if (!empty($headers)) { curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); } if (!empty($postBody)) { curl_setopt($ch, CURLOPT_POSTFIELDS, $postBody); if (defined("CURLOPT_SAFE_UPLOAD")) { curl_setopt($ch, CURLOPT_SAFE_UPLOAD, 1); } } curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . "/caroots.crt"); $src = curl_exec($ch); if ($src === false) { $err = curl_errno($ch); $str = ""; if (function_exists("curl_strerror")) { $str = curl_strerror($err); } $verboseLog = ""; if (!empty($verbose) && function_exists("rewind")) { rewind($verbose); $verboseLog = stream_get_contents($verbose); } $res["error"] = array("code" => $err, "str" => $str, "type" => "curl", "debug" => $verboseLog, ); } else { $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); if (function_exists("mb_substr")) { $header = mb_substr($src, 0, $headerSize); } else { $header = substr($src, 0, $headerSize); } $recvHeaders = explode("\r\n", $header); foreach ($recvHeaders as $h) { foreach (self::$headersToCopy as $hc) { if (stripos($h, $hc) === 0) { $res["headers"][] = $h; break; } } } //todo: look for "Location" header if (function_exists("mb_substr")) { $res["source"] = mb_substr($src, $headerSize); } else { $res["source"] = substr($src, $headerSize); } } curl_close($ch); } elseif (function_exists("wp_remote_retrieve_body") && function_exists("wp_safe_remote_get") && function_exists("wp_safe_remote_post")) { $args = array( "headers" => $headers, "user-agent" => $ua, ); if (!empty($postBody)) { $args["body"] = $postBody; $resp = wp_safe_remote_post($urlWithScheme, $args); } else { $resp = wp_safe_remote_get($urlWithScheme, $args); } if (function_exists('is_wp_error') && is_wp_error($resp)) { $res["error"] = array("code" => $resp->get_error_code(), "str" => $resp->get_error_message(), "type" => "wp", ); } else { $body = wp_remote_retrieve_body($resp); if (empty($body)) { $res["error"] = array("code" => 0, "str" => "Unknown error but empty body", "type" => "wp", ); } else { $res["source"] = $body; $headers = wp_remote_retrieve_headers($resp); foreach ($headers as $key => $val) { $src["headers"][] = "$key: $val"; } } } } return $res; } public static function registerSettings() { register_setting("admiral_property_settings", self::PROPERTY_OPTION_ID_KEY); register_setting("admiral_property_settings", self::EMBED_OPTION_KEY); register_setting("admiral_property_settings", self::APPEND_PHP_OPTION_KEY); } public static function renderOptions() { if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $currentPropertyID = self::getPropertyID(); echo '
The Admiral Wordpress Plugin allows you to easily measure how much revenue you are losing to adblock.
Block Adblock now comes with advanced adblock analytics from Admiral. Click accept to start collecting data and discover how much revenue you're losing to adblockers. Click here to learn more.