Skip to content

Instantly share code, notes, and snippets.

@WebPlatformDocs
Last active October 26, 2016 00:46
Show Gist options
  • Save WebPlatformDocs/1774a8643560d7518744af5e9c5271ff to your computer and use it in GitHub Desktop.
Save WebPlatformDocs/1774a8643560d7518744af5e9c5271ff to your computer and use it in GitHub Desktop.
Export LumberJack IRC log to text
<?php
/**
* Export LumberJack IRC log to text
**/
$username='lumberjack_user';
$password='secretpassword';
$database='lumberjack';
$host='10.10.10.3';
try {
if (!ini_get('mysqli.default_socket')) {
$message = 'mysqli.default_socket PHP ini setting is not set, we cannot use this health check';
throw new Exception($message);
}
$mysqli = new mysqli($host, $username, $password, $database);
if ($mysqli->connect_error) {
$message = sprintf('Connect error %s: %s', $mysqli->connect_errno, $mysqli->connect_error);
throw new Exception($message);
}
$channel = "webplatform";
$query = sprintf('select * from main WHERE channel = "%s"', $channel);
$stmt = $mysqli->prepare($query);
$stmt->execute();
/*
+--------+
| type |
+--------+
| join |
| pubmsg |
| action |
| topic |
| quit |
| part |
| nick |
+--------+
*/
//echo '['.PHP_EOL;
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
/**
* $row = [
* "id": int(20)
* "channel": string(11) "webplatform"
* "name": string(7) "shepazu"
* "time": string(19) "2012-10-08 00:08:22"
* "message": string(15) "wp-logger, help"
* "type": string(6) "pubmsg"
* "hidden": string(1) "F"
* ]
**/
unset($row['hidden'], $row['id'], $row['channel']);
//$row['message'] = (empty($row['message']))?null:$row['message'];
//echo json_encode($row).','.PHP_EOL;
///*
switch($row['type']){
case 'quit':
case 'part':
$m = (!empty($row['message']))?$row['message']:$row['type'];
$fmt = sprintf('%s %s: %s', $row['time'], $row['name'], $m);
break;
case 'join':
$fmt = sprintf('%s %s joined', $row['time'], $row['name']);
break;
case 'nick':
$fmt = sprintf('%s %s is now known as %s', $row['time'], $row['name'], $row['message']);
break;
case 'topic':
$fmt = sprintf('%s %s changed topic to: %s', $row['time'], $row['name'], $row['message']);
break;
case 'action':
$fmt = sprintf('%s %s %s', $row['time'], $row['name'], $row['message']);
break;
case 'pubmsg':
$fmt = sprintf('%s %s: %s', $row['time'], $row['name'], $row['message']);
break;
default:
$m = $row['message'];
$fmt = sprintf('%s %s: %s (type: %s)', $row['time'], $row['name'], $m, $row['type']);
break;
}
echo $fmt.PHP_EOL;
//*/
}
//echo ']'.PHP_EOL;
//echo PHP_EOL;
//echo $query.PHP_EOL;
$mysqli->close();
} catch(Exception $e) {
$message = $e->getMessage();
trigger_error($message);
echo $message.PHP_EOL;
exit(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment