Example #1
0
 protected function addStats($bundleidentifier, $format)
 {
     // did we get any user data?
     $udid = Router::arg_match(self::PARAM_2_UDID, '/^[0-9a-f]{40}$/i');
     if (!$udid || !is_dir($this->appDirectory . 'stats/')) {
         return;
     }
     $appversion = Router::arg_variants(array(self::PARAM_2_APP_VERSION, self::PARAM_1_APP_VERSION));
     $osversion = Router::arg_variants(array(self::PARAM_2_OS_VERSION, self::PARAM_1_OS_VERSION));
     $osname = Router::arg(self::PARAM_2_OS, 'iOS');
     $device = Router::arg_variants(array(self::PARAM_2_DEVICE, self::PARAM_1_DEVICE));
     $language = Router::arg(self::PARAM_2_LANGUAGE, '');
     $firststartdate = Router::arg(self::PARAM_2_FIRST_START, '');
     $usagetime = Router::arg(self::PARAM_2_USAGE_TIME, '');
     $thisdevice = array($udid, $device, $osname . ' ' . $osversion, $appversion, date('m/d/Y H:i:s'), $language, $firststartdate, $usagetime);
     $filename = $this->appDirectory . "stats/" . $bundleidentifier;
     $lines = @file($filename, FILE_IGNORE_NEW_LINES);
     $found = false;
     $lines = $lines ? array_filter(array_map('trim', $lines)) : array();
     foreach ($lines as $i => $line) {
         $device = explode(self::STATS_SEPARATOR, $line);
         if (!count($device)) {
             continue;
         }
         // is this the same device?
         if ($device[0] === $udid) {
             $found = true;
             $lines[$i] = join(self::STATS_SEPARATOR, $thisdevice);
             break;
         }
     }
     if (!$found) {
         $lines[] = join(self::STATS_SEPARATOR, $thisdevice);
     }
     // write back the updated stats
     if ($lines) {
         if (!@file_put_contents($filename, join("\n", $lines))) {
             Logger::log("Stats file not writable: {$filename}");
         }
     }
 }