array('win', 'windows', 'ms') ,'MAC' => array('mac', 'macintosh') ,'LINUX' => array('lin', 'linux') ); static $browser_alias_list = array( 'IE' => array('ie', 'internetexplorer', 'msie') ,'FF' => array('ff', 'firefox') ,'Netscape' => array('nn', 'Netscape') ,'Safari' => array('safari') ,'Opera' => array('opera') ); if (!$ua) { $ua =& $_SERVER['HTTP_USER_AGENT']; if (preg_match('#Windows.*Opera (\d)#i', $ua, $matches)) { $os = 'WIN'; $browser = 'Opera'; $version = $matches[1]; } else if (preg_match('#Mac.*Opera (\d)#i', $ua, $matches)) { $os = 'MAC'; $browser = 'Opera'; $version = $matches[1]; } else if (preg_match('#Linux.*Opera (\d)#i', $ua, $matches)) { $os = 'LINUX'; $browser = 'Opera'; $version = $matches[1]; } else if (preg_match('#Opera/(\d).*Windows#i', $ua, $matches)) { $os = 'WIN'; $browser = 'Opera'; $version = $matches[1]; } else if (preg_match('#Opera/(\d).*Linux#i', $ua, $matches)) { $os = 'LINUX'; $browser = 'Opera'; $version = $matches[1]; } else if (preg_match('/MSIE (\d+)\..*Windows/i', $ua, $matches)) { $os = 'WIN'; $browser = 'IE'; $version = $matches[1]; } else if (preg_match('/MSIE (\d+)\..*(Macintosh|Mac_PowerPC)/i', $ua, $matches)) { $os = 'MAC'; $browser = 'IE'; $version = $matches[1]; } else if (preg_match('#Windows.*Firefox/(\d+)\.#i', $ua, $matches)) { $os = 'WIN'; $browser = 'FF'; $version = $matches[1]; } else if (preg_match('#Macintosh.*Firefox/(\d+)\.#i', $ua, $matches)) { $os = 'MAC'; $browser = 'FF'; $version = $matches[1]; } else if (preg_match('#Linux.*Firefox/(\d+)\.#i', $ua, $matches)) { $os = 'LINUX'; $browser = 'FF'; $version = $matches[1]; } else if (preg_match('#Windows.*Netscape/(\d+)\.#i', $ua, $matches)) { $os = 'WIN'; $browser = 'Netscape'; $version = $matches[1]; } else if (preg_match('#Macintosh.*Netscape/(\d+)\.#i', $ua, $matches)) { $os = 'MAC'; $browser = 'Netscape'; $version = $matches[1]; } else if (preg_match('#Linux.*Netscape/(\d+)\.#i', $ua, $matches)) { $os = 'LINUX'; $browser = 'Netscape'; $version = $matches[1]; } else if (preg_match('#Macintosh.*AppleWebKit/(\d).*Safari/#i', $ua, $matches)) { $os = 'MAC'; $browser = 'Safari'; switch ($matches[1]) { case '5': $version = '3'; break; case '4': $version = '2'; break; default: $version = 'unknown'; break; } } else { $os = 'unknown'; $browser = 'unknown'; $version = 'unknown'; } defined('UAVICE_DEBUG') and $str = <<<__CSS__ /* UA: {$ua} */ /* OS: {$os} */ /* Browser: {$browser} */ /* Version: {$version} */ $str __CSS__; /* OS 読み替え */ if ($os === 'LINUX' && defined('UAVICE_NOT_LINUX')) { $target = strtolower(UAVICE_NOT_LINUX); foreach ($os_alias_list as $alias=>$list) { if (in_array($target, $list)) { $os = $alias; break; } } } else if ($os === 'unknown' && defined('UAVICE_UNKNOWN_OS')) { $target = strtolower(UAVICE_UNKNOWN_OS); foreach ($os_alias_list as $alias=>$list) { if (in_array($target, $list)) { $os = $alias; break; } } } /* ブラウザ読み替え */ if ($browser === 'Netscape' && defined('UAVICE_NOT_NETSCAPE')) { $target = strtolower(UAVICE_NOT_NETSCAPE); foreach ($browser_alias_list as $alias=>$list) { if (in_array($target, $list)) { $browser = $alias; break; } } } else if ($browser === 'Opera' && defined('UAVICE_NOT_OPERA')) { $target = strtolower(UAVICE_NOT_OPERA); foreach ($browser_alias_list as $alias=>$list) { if (in_array($target, $list)) { $browser = $alias; break; } } } else if ($browser === 'unknown' && defined('UAVICE_UNKNOWN_BROWSER')) { $target = strtolower(UAVICE_UNKNOWN_BROWSER); foreach ($browser_alias_list as $alias=>$list) { if (in_array($target, $list)) { $browser = $alias; break; } } } $os = $os_alias_list[$os]; $browser = $browser_alias_list[$browser]; } while (preg_match("#^(.*?):(.*?);\s*//\s*(\w+.*?)$#mS", $str, $matches)) { $params = preg_split('/\s+/', trim($matches[3])); $rest = true; foreach ($params as $param) { if (is_numeric($param)) { if ($version !== $param) { $rest = false; } } else { $param = strtolower($param); if (!in_array($param, $os) && !in_array($param, $browser)) { $rest = false; } } } $tag = trim($matches[3]); if ($rest) { $str = str_replace($matches[0], "{$matches[1]}:{$matches[2]} /* {$tag} */", $str); } else { $str = str_replace("{$matches[0]}\n", '', $str); $str = str_replace("{$matches[0]}\r\n", '', $str); $str = str_replace("{$matches[0]}\r", '', $str); } } return $str; }