/*
Theme Name: Impreza Child
Template: Impreza
Version: 1.0
Author:	UpSolution
Theme URI: http://impreza.us-themes.com/
Author URI: http://us-themes.com/
*/

/*Add your own styles here:*/
//cf7でアウトプット分岐
add_filter('wpcf7_special_mail_tags', 'my_special_mail_tags',11,2);
 
function my_special_mail_tags($output, $name){
 
　$name = preg_replace( '/^wpcf7\./', '_', $name );
 
 if('_checkbox-info2' == $name ){
  $a = 'オクサポの箱で送る';
  $b = '自分で箱を用意する';
  $name = 'checkbox-info2';
 
   if ($_POST[$name] == $a){
     $output .= '箱の種類';
   }elseif($_POST[$name] == $b){
     $output .= '送り状の枚数';
   }
    return $output;
 }
}


/**
Contactform7　ユーザーエージェントの判別
**/

// Contactform7にフックを紐付ける
add_filter('wpcf7_special_mail_tags', 'my_special_mail_tags',10,2);

// ユーザー関数（my_special_mail_tags）
function my_special_mail_tags($output, $name) {

    /** ユーザーエージェント取得 */
    if (empty($user_agent)) {
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    }

    /** os判定 */
    if (preg_match('/Windows NT 6.3/', $user_agent)) {
        $os = 'Windows 8.1';
    } elseif (preg_match('/Windows NT 6.2/', $user_agent)) {
        $os = 'Windows 8';
    } elseif (preg_match('/Windows NT 6.1/', $user_agent)) {
        $os = 'Windows 7';
    } elseif (preg_match('/Windows NT 6.0/', $user_agent)) {
        $os = 'Windows Vista';
    } elseif (preg_match('/Windows NT 5.2/', $user_agent)) {
        $os = 'Windows Server 2003 / Windows XP x64 Edition';
    } elseif (preg_match('/Windows NT 5.1/', $user_agent)) {
        $os = 'Windows XP';
    } elseif (preg_match('/Windows NT 5.0/', $user_agent)) {
        $os = 'Windows 2000';
    } elseif (preg_match('/Windows NT 4.0/', $user_agent)) {
        $os = 'Microsoft Windows NT 4.0'; 
    } elseif (preg_match('/Mac OS X ([0-9\._]+)/', $user_agent, $matches)) {
        $os = 'Macintosh Intel ' . str_replace('_', '.', $matches[1]);
    } elseif (preg_match('/Linux ([a-z0-9_]+)/', $user_agent, $matches)) {
        $os = 'Linux ' . $matches[1];
    } elseif (preg_match('/OS ([a-z0-9_]+)/', $user_agent, $matches)) {
        $os = 'iOS ' . str_replace('_', '.', $matches[1]);
    } elseif (preg_match('/Android ([a-z0-9\.]+)/', $user_agent, $matches)) {
        $os = 'Android ' . $matches[1];
    } else {
        $os = '不明';
    }
    
    
    /** ブラウザ判定（PC以外はスマホと表示） */
    // マイナー
    if (preg_match('/(Iron|Sleipnir|Maxthon|Lunascape|SeaMonkey|Camino|PaleMoon|Waterfox|Cyberfox)\/([0-9\.]+)/', $user_agent, $matches)) {
        $browser = $matches[1];
        $version = $matches[2];
    // 主要
    } elseif (preg_match('/(^Opera|OPR).*\/([0-9\.]+)/', $user_agent, $matches)) {
        $browser = 'Opera';
        $version = $matches[2];
    } elseif (preg_match('/Chrome\/([0-9\.]+)/', $user_agent, $matches)) {
        $browser = 'Chrome';
        $version = $matches[1]; 
    } elseif (preg_match('/Firefox\/([0-9\.]+)/', $user_agent, $matches)) {
        $browser = 'Firefox';
        $version = $matches[1];
    } elseif (preg_match('/(MSIE\s|Trident.*rv:)([0-9\.]+)/', $user_agent, $matches)) {
        $browser = 'Internet Explorer';
        $version = $matches[2];
    } elseif (preg_match('/\/([0-9\.]+)(\sMobile\/[A-Z0-9]{6})?\sSafari/', $user_agent, $matches)) {
        $browser = 'Safari';
        $version = $matches[1];
    // ゲーム機
    } elseif (preg_match('/Nintendo (3DS|WiiU)/', $user_agent, $matches)) {
        $browser = 'Nintendo';
        $version = $matches[1];
    } elseif (preg_match('/PLAYSTATION (3|Vita)/', $user_agent, $matches)) {
        $browser = 'PLAYSTATION';
        $version = $matches[1];
    // BOT
    } elseif (preg_match('/(Googlebot|bingbot)\/([0-9\.]+)/', $user_agent, $matches)) {
        $browser = $matches[1];
        $version = $matches[2];
    } else {
        $browser = '不明';
        $version = '';
    }
    
    
    /** デバイス判定 */
    if (preg_match('/iPhone;/', $user_agent)) {
        $device = 'iPhone';
    } elseif (preg_match('/iPod/', $user_agent)) {
        $device = 'iPod';
    } elseif (preg_match('/iPad/', $user_agent)) {
        $device = 'iPad';      
    } elseif (preg_match('/Android/', $user_agent)) {
        $device = 'Android';
    } elseif (preg_match('/Windows Phone/', $user_agent)) {
        $device = 'Windows Phone';
    } elseif (preg_match('/(BlackBerry|BB)/', $user_agent)) {
        $device = 'BlackBerry';
    } elseif (preg_match('/PlayStation Vita/', $user_agent)) {
        $device = 'PlayStation Vita';
    } elseif (preg_match('/PlayStation Portable/', $user_agent)) {
        $device = 'PlayStation Portable';
    } elseif (preg_match('/(PS2|PLAYSTATION 3|PlayStation 4)/', $user_agent)) {
        $device = 'PlayStation';
    } elseif (preg_match('/Nintendo 3DS/', $user_agent)) {
        $device = 'Nintendo 3DS';
    } elseif (preg_match('/Nintendo (Wii|WiiU)/', $user_agent)) {
        $device = 'Nintendo Wii(U)';
    } else {
        $device = 'PC';
    }
}
