static function Request($url, $query, $type) { // Get timeout $timeout = get_option(c_al2fb_option_timeout); if (!$timeout) { $timeout = 25; } // Use cURL if available if (function_exists('curl_init') && !get_option(c_al2fb_option_nocurl)) { return WPAL2Int::Request_cURL($url, $query, $type, $timeout); } if (version_compare(PHP_VERSION, '5.2.1') < 0) { ini_set('default_socket_timeout', $timeout); } delete_option(c_al2fb_log_ua); $ua = $_SERVER['HTTP_USER_AGENT']; if (!empty($ua)) { ini_set('user_agent', $ua); update_option(c_al2fb_log_ua, $ua); } WPAL2Int::$php_error = ''; set_error_handler(array('WPAL2Int', 'PHP_error_handler')); if ($type == 'GET') { $context = stream_context_create(array('http' => array('method' => 'GET', 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'timeout' => $timeout))); $content = file_get_contents($url . ($query ? '?' . $query : ''), false, $context); } else { $context = stream_context_create(array('http' => array('method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'timeout' => $timeout, 'content' => $query))); $content = file_get_contents($url, false, $context); } restore_error_handler(); // Check for errors $status = false; $auth_error = ''; if (!empty($http_response_header)) { foreach ($http_response_header as $h) { if (strpos($h, 'HTTP/') === 0) { $status = explode(' ', $h); $status = intval($status[1]); } else { if (strpos($h, 'WWW-Authenticate:') === 0) { $auth_error = $h; } } } } if ($status == 200) { return $content; } else { if ($auth_error) { $msg = 'Error ' . $status . ': ' . $auth_error; } else { $msg = 'Error ' . $status . ': ' . WPAL2Int::$php_error . ' ' . print_r($http_response_header, true); } update_option(c_al2fb_last_error, $msg); update_option(c_al2fb_last_error_time, date('c')); throw new Exception($msg); } }