/** * \static */ function splitFile($file) { $rows = IRC_Log_Parser::parseFile($file, null); $a = IRC_Log_Parser::getChannelAndDate($file); if (!$a['channel']) { return false; } $channel = $a['channel']; $file = ''; $fp = null; foreach ($rows as $row) { $date = $row['date']; if (!$date) { continue; } if (preg_match('/(\\d{1,2})[\\/\\-]?(\\d{1,2})[\\/\\-]?(\\d{2,4})/', $date, $m)) { $newfile = sprintf('%s_%02d%02d%02d.log', $channel, $m[3], $m[1], $m[2]); if ($newfile != $file) { if ($fp) { fclose($fp); $fp = null; } $file = $newfile; } } if ($file) { if (!$fp) { $fullname = IRC_LOG_DIR . '/' . $file; $fp = fopen($fullname, 'wb'); chmod($fullname, 0664); if (!$fp) { printf("Can't open '%s': %s\n", $fullname, $php_errormsg); return false; } printf("Creating '%s'\n", $fullname); } } fwrite($fp, $row['original']); } if ($fp) { fclose($fp); $fp = null; } return true; }