function umc_log_chat_import() { global $UMC_PATH_MC; $pattern_path = "{$UMC_PATH_MC}/server/bukkit/plugins/Herochat/logs/*"; $files = umc_glob_recursive($pattern_path); $pattern_line = '/([0-9.]{10} [0-9:]{8})( \\[[A-Z]\\])? ?\\*? ?(\\[Trivia\\]|[_0-9a-zA-Z]*)( -> ([_0-9a-zA-Z]*|)?)?(.*: )?(.*)/'; $target_path = '/disk2/backup/log/minecraft'; // erase the file foreach ($files as $file) { $text_arr = file($file); // get the first text $sql = "INSERT INTO `minecraft_log`.`chat_log` (`timestamp`, `source`, `target`, `text`, `raw`) VALUES \n"; if (count($text_arr) == 0) { continue; } foreach ($text_arr as $line) { $match = array(); $raw = umc_mysql_real_escape_string(trim($line)); preg_match($pattern_line, $line, $match); // $raw = bzcompress($match[0]); $time = $match[1]; $source = trim($match[3]); $target = trim($match[4]); if (strlen($match[2]) > 0) { $target = trim($match[2]); } else { if (strlen($match[5]) > 0) { $target = trim($match[5]); } } $text = trim($match[7]); $text_sql = umc_mysql_real_escape_string($text); if (strlen($time) > 0) { $sql .= "('{$time}', '{$source}', '{$target}', {$text_sql}, {$raw}),"; } } $ins = substr($sql, 0, -1) . ";"; $date_today = umc_datetime(); $today = $date_today->format('Y|m|d|H|i'); $date_parts = explode("|", $today); $year = $date_parts[0]; $month = $date_parts[1]; $day = $date_parts[2]; $hour = $date_parts[3]; $min = $date_parts[3]; umc_mysql_query($ins, true); $file = "{$year}-{$month}-{$day}_{$hour}_{$min}_chat_log.tar.bz2"; rename($file, "{$target_path}/{$year}/{$month}/{$file}"); } }
function umc_glob_recursive($pattern, $flags = 0) { $files = glob($pattern, $flags); foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) { $files = array_merge($files, umc_glob_recursive($dir . '/' . basename($pattern), $flags)); } return $files; }