本文整理汇总了PHP中Kurogo::KurogoUserAgent方法的典型用法代码示例。如果您正苦于以下问题:PHP Kurogo::KurogoUserAgent方法的具体用法?PHP Kurogo::KurogoUserAgent怎么用?PHP Kurogo::KurogoUserAgent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kurogo
的用法示例。
在下文中一共展示了Kurogo::KurogoUserAgent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: streamContextOpts
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;
}
示例2: detectDeviceExternal
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;
}