
CrazyBone(狂骨)のOS表示について
WordPressにてブログを始めて、早速、以前から重宝しているプラグインをいくつかインストールしました。
そのうちの1つに「Crazy Bone (狂骨)」があるのですが、初期状態だとWindows7以降のOSを正しく表示してくれません…
1月18日に0.5.5にバージョンアップされたようなので更新してみました。しかし、今回も修正されていないようです。
プラグインのソースコード(includes/class-detect-browsers.php)の716行目、下記の7行目のpreg_matchとそれ以降の条件分岐の記述が不十分な模様。
static private function _os_win($ua) {
$os_name = $os_code = $os_ver = null;
if (preg_match('/mac_powerpc/i', $ua)) {
$os_name = "Mac OS";
$os_code = "macos";
} else if (preg_match('/win(dows)?[ \.]?(9[58]|9x 4\.90|[cm]e|2000|nt ?[456]\.0|nt ?5\.[12])/i', $ua, $matches)) {
$os_name = "Windows";
$os_code = "windows";
$os_ver = strtoupper(trim($matches[2]));
switch ($os_ver) {
正規表現部分と条件分岐を下記のように訂正。
static private function _os_win($ua) {
$os_name = $os_code = $os_ver = null;
if (preg_match('/mac_powerpc/i', $ua)) {
$os_name = "Mac OS";
$os_code = "macos";
} else if (preg_match('/win(dows)?[ \.]?(9[58]|9x 4\.90|[cm]e|2000|nt ?[456]\.0|nt ?5\.[12]|nt ?6\.[123])/i', $ua, $matches)) {
$os_name = "Windows";
$os_code = "windows";
$os_ver = strtoupper(trim($matches[2]));
switch ($os_ver) {
case '95':
$os_ver = "95";
break;
case '9X 4.90';
case 'ME';
$os_ver = "ME";
break;
case 'NT4.0';
case 'NT 4.0';
$os_ver = "NT 4.0";
break;
case '2000':
case 'NT 5.0':
$os_ver = "2000";
break;
case 'NT 5.1':
$os_ver = "XP";
break;
case 'NT 5.2':
$os_ver = ( preg_match('/(win|wow)64/i', $ua) ? "XP (64bit)" : "Server 2003" );
break;
case 'NT 6.0':
$os_ver = "Vista" . ( preg_match('/(win|wow)64/i', $ua) ? " (64bit)" : "" );
break;
case 'NT 6.1':
$os_ver = "7" . ( preg_match('/(win|wow)64/i', $ua) ? " (64bit)" : "" );
break;
case 'NT 6.2':
$os_ver = "8" . ( preg_match('/(win|wow)64/i', $ua) ? " (64bit)" : "" );
break;
case 'NT 6.3':
$os_ver = "8.1" . ( preg_match('/(win|wow)64/i', $ua) ? " (64bit)" : "" );
break;
case 'CE';
$os_name = "Windows";
$os_code = "windows";
$os_ver = "CE";
if (preg_match('/ppc/i', $ua)) {
$os_name = "Microsoft PocketPC";
$os_code = "windows";
$os_ver = '';
}
if (preg_match('/smartphone/i', $ua)) {
$os_name = "Microsoft Smartphone";
$os_code = "windows";
$os_ver = '';
}
break;
}
} else if (preg_match('/win(dows)? phone os ([0-9\.]+)/i', $ua, $matches)) {
$os_name = "Windows Phone";
$os_code = "windows_phone";
$os_ver = strtoupper(trim($matches[2]));
} else if (preg_match('/win(dows )?nt/i', $ua)) {
$os_name = "Windows";
$os_code = "windows";
$os_ver = "NT";
}
return array($os_name, $os_code, $os_ver);
}
とりあえずはこれで正常に表示されるようになりました。
ただちゃんとした知識がないので、もしかしたらどこかで不具合が出るかもしれません…
ざっと調べてみましたが、同じ問題で困っている人が見つかりませんでした。自分の使い方が間違っているんでしょうか。