예제 #1
0
 static function compute_users()
 {
     global $stats_array_lang;
     $_SERVER['HTTP_USER_AGENT'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
     if (strpos($_SERVER['HTTP_USER_AGENT'], 'libwww') !== false) {
         return;
     }
     $array_stats_img = array('browsers.png', 'os.png', 'lang.png');
     foreach ($array_stats_img as $key => $value) {
         @unlink(PATH_TO_ROOT . '/cache/' . $value);
     }
     ########### Détection des navigateurs ###########
     $array_browser = array('opera' => 'opera', 'firefox' => 'firefox', 'msie|internet explorer' => 'internetexplorer', 'chrome' => 'chrome', 'safari' => 'safari', 'konqueror' => 'konqueror', 'netscape' => 'netscape', 'seamonkey' => 'seamonkey', 'mozilla firebird' => 'mozilla firebird', 'mozilla' => 'mozilla', 'aol' => 'aol', 'lynx' => 'lynx', 'camino' => 'camino', 'links' => 'links', 'galeon' => 'galeaon', 'phoenix' => 'phoenix', 'chimera' => 'chimera', 'k-meleon' => 'k-meleon', 'icab' => 'icab', 'ncsa mosaic' => 'ncsa mosaic', 'amaya' => 'amaya', 'omniweb' => 'omniweb', 'hotjava' => 'hotjava', 'browsex' => 'browsex', 'amigavoyager' => 'amigavoyager', 'amiga-aweb' => 'amiga-aweb', 'ibrowse' => 'ibrowse', 'samsung|sony|nokia|blackberry|android|ipod|iphone|opera mini|palm|iemobile|smartphone|symbian' => 'phone');
     if (!empty($_SERVER['HTTP_USER_AGENT'])) {
         $browser = 'other';
         foreach ($array_browser as $regex => $name) {
             if (preg_match('`' . $regex . '`i', $_SERVER['HTTP_USER_AGENT'])) {
                 $browser = $name;
                 break;
             }
         }
         StatsSaver::_write_stats('browsers', $browser);
     }
     ########### Détection des systèmes d'exploitation ###########
     $array_os = array('windows nt 6.1|seven' => 'windowsseven', 'windows nt 6.0|vista' => 'windowsvista', 'windows nt 5.1|windows xp' => 'windowsxp', 'linux|x11' => 'linux', 'macintosh|mac|ppc|powerpc' => 'macintosh', 'windows nt 5.2|windows server 2003' => 'windowsserver2003', 'windows nt 5.0|windows 2000' => 'windows2000', 'winnt|windows nt|windows nt 4.0' => 'windowsnt', 'windows 98|win98' => 'windows98', 'win 9x 4.90|windows me' => 'windowsme', 'win95|win32|windows 95|windows 3.1' => 'windows95', 'windows ce' => 'windowsce', 'solaris|sunos' => 'sunos', 'nintendo wii' => 'wii', 'playstation portable' => 'psp', 'playstation 3' => 'playstation3', 'freebsd' => 'freebsd', 'aix' => 'aix', 'irix' => 'irix', 'hp-ux' => 'hp-ux', 'os2|os/2' => 'os2', 'netbsd' => 'netbsd', 'samsung|sony|nokia|blackberry|android|ipod|iphone|opera mini|palm|iemobile|smartphone|symbian' => 'phone');
     if (!empty($_SERVER['HTTP_USER_AGENT'])) {
         $os = 'other';
         foreach ($array_os as $regex => $name) {
             if (preg_match('`' . $regex . '`i', $_SERVER['HTTP_USER_AGENT'])) {
                 $os = $name;
                 break;
             }
         }
         StatsSaver::_write_stats('os', $os);
     }
     ########### Détection de la langue utilisateur ###########
     if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         $user_lang = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
         $favorite_lang = !empty($user_lang[0]) ? strtolower($user_lang[0]) : '';
         if (strpos($favorite_lang, '-') !== false) {
             $favorite_lang = preg_replace('`[a-z]{2}\\-([a-z]{2})`i', '$1', $favorite_lang);
         }
         $lang = str_replace(array('en', 'cs', 'sv', 'fa', 'ja', 'ko', 'he', 'da'), array('uk', 'cz', 'se', 'ir', 'jp', 'kr', 'il', 'dk'), $favorite_lang);
         if (!empty($lang)) {
             $wlang = 'other';
             if (isset($stats_array_lang[$lang])) {
                 $wlang = $lang;
             } elseif (isset($stats_array_lang[substr($lang, 0, 2)])) {
                 $wlang = substr($lang, 0, 2);
             }
             StatsSaver::_write_stats('lang', $wlang);
         }
     }
 }