protected function streamContextOpts($args) { $streamContextOpts = array('http' => array('user_agent' => Kurogo::KurogoUserAgent())); if (isset($args['HTTP_PROXY_URL'])) { $streamContextOpts['http'] = array('proxy' => $args['HTTP_PROXY_URL'], 'request_fulluri' => TRUE); } if (isset($args['HTTPS_PROXY_URL'])) { $streamContextOpts['https'] = array('proxy' => $args['HTTPS_PROXY_URL'], 'request_fulluri' => TRUE); } return $streamContextOpts; }
protected function detectDeviceExternal($user_agent) { if (!$user_agent) { return; } // see if the server has cached the results from the the device detection server try { $cache = new DiskCache($this->cacheFolder(), $this->cacheLifetime(), TRUE); } catch (KurogoDataException $e) { $cache = null; } $cacheFilename = md5($user_agent); if ($cache && $cache->isFresh($cacheFilename)) { $json = $cache->read($cacheFilename); Kurogo::log(LOG_INFO, "Using cached data for external device detection", 'deviceDetection'); } else { $query = http_build_query(array('user-agent' => $user_agent, 'version' => $this->version)); $url = Kurogo::getSiteVar('MOBI_SERVICE_URL') . '?' . $query; Kurogo::log(LOG_INFO, "Detecting device using external device detection: {$url}", 'deviceDetection'); $timeout = Kurogo::getOptionalSiteVar('MOBI_SERVICE_EXTERNAL_TIMEOUT', 5); $context = stream_context_create(array('http' => array('timeout' => $timeout, 'user_agent' => Kurogo::KurogoUserAgent()))); $json = @file_get_contents($url, false, $context); if (false === $json) { return $this->detectDeviceInternal($user_agent); } $test = json_decode($json, true); // make sure the response is valid if ($cache) { if ($json && isset($test['pagetype'], $test['platform'])) { $cache->write($json, $cacheFilename); } else { Kurogo::log(LOG_WARNING, "Error receiving device detection data from {$url}. Reading expired cache.", 'deviceDetection'); $json = $cache->read($cacheFilename); } } } $data = json_decode($json, true); // fix values when using old version if ($this->version == 1) { switch (strtolower($data['pagetype'])) { case 'basic': if ($data['platform'] == 'computer' || $data['platform'] == 'spider') { $data['pagetype'] = 'compliant'; } else { if ($data['platform'] == 'bbplus') { $data['pagetype'] = 'compliant'; } else { $data['pagetype'] = 'basic'; } } break; case 'touch': if ($data['platform'] == 'blackberry') { $data['pagetype'] = 'compliant'; // Storm, Storm 2 } else { if ($data['platform'] == 'winphone7') { $data['pagetype'] = 'compliant'; // Windows Phone 7 } else { $data['pagetype'] = 'touch'; } } break; case 'compliant': case 'webkit': default: $data['pagetype'] = 'compliant'; break; } } return $data; }