예제 #1
0
 private function _downloadData()
 {
     if (ini_get('allow_url_fopen')) {
         $status = 1;
         if (file_exists($this->cacheDir . '/cache2.0.ini')) {
             $cacheIni = parse_ini_file($this->cacheDir . '/cache2.0.ini');
         }
         $ctx = stream_context_create(array('http' => array('timeout' => 5)));
         !($ver = @file_get_contents($this->VerUrl, 0, $ctx));
         if (strlen($ver) != 11) {
             if ($cacheIni['localversion']) {
                 $ver = $cacheIni['localversion'];
             } else {
                 $ver = 'none';
             }
         }
         if ($ini = @file_get_contents($this->IniUrl, 0, $ctx)) {
             $md5hash = @file_get_contents($this->md5Url, 0, $ctx);
             if (md5($ini) == $md5hash) {
                 /**只保留浏览器的相关信息**/
                 $ini = parse_ini_string($ini, true);
                 $ini['robots'] = $ini['os_reg'] = $ini['browser_os'] = $ini['os_reg'] = $ini['os'] = array();
                 foreach ($ini['browser'] as $k => $v) {
                     $ini['browser'][$k] = array($v[0]);
                 }
                 $ini = \Helper\String::arrayToIni($ini);
                 @file_put_contents($this->cacheDir . '/uasdata2.0.ini', $ini);
                 $status = 0;
             }
         }
         $cacheIni = "; cache info for class UASparser - http://user-agent-string.info/download/UASparser\n";
         $cacheIni .= "[main]\n";
         $cacheIni .= "localversion = \"{$ver}\"\n";
         $cacheIni .= 'lastupdate = "' . time() . "\"\n";
         $cacheIni .= "lastupdatestatus = \"{$status}\"\n";
         @file_put_contents($this->cacheDir . '/cache2.0.ini', $cacheIni);
     } else {
         die('ERROR: function file_get_contents not allowed URL open. Update the datafile (uasdata2.0.ini in Cache Dir) manually.');
     }
 }