#!/usr/bin/php5 fetch(PDO::FETCH_ASSOC)) { if (date('Ymd', $line['time']) > $start) { if (!empty($end)) fputs($fp, "--- Log closed ".irssi_time($end)."\n"); fputs($fp, "--- Log opened ".irssi_time($line['time'])."\n"); $start = date('Ymd', $line['time']); } fputs($fp, date('H:i', $line['time'])." "); switch ($line['kind']) { case GAJIM_KIND_SINGLE_MSG_RECV: case GAJIM_KIND_CHAT_MSG_RECV: fputs($fp, "<".$jid.">"); break; case GAJIM_KIND_SINGLE_MSG_SENT: case GAJIM_KIND_CHAT_MSG_SENT: fputs($fp, "<".$GLOBALS['user_nick'].">"); break; default: if (empty($line['message'])) continue(2); fputs($fp, " * Gajim message:"); break; } fputs($fp, " ".utf8_decode($line['message'])."\n"); $end = $line['time']; } if (!empty($end)) fputs($fp, "--- Log closed ".irssi_time($end)."\n"); fclose($fp); unset($out); } // Begin of application itself //////////////////////////////////////////////////////////////////////// // Fetching command line arguments $args = parse_arguments(); if (isset($args['help'])) { echo "Gajim log export tool\nCopyleft (C) 2007 BohwaZ - http://dev.kd2.org/ - GNU/GPL\n\n". $_SERVER['argv'][0]." --destination DESTINATION_PATH [options]\n\n". " --destination MANDATORY. Destination path, where to put generated log files\n". " --source-path Source path, where are gajim things (eg. /home/user/.gajim)\n". //" --output-format Defines output format. 'irssi' or 'text'. Default is irssi.\n". " --user-nick Nick of yourself when you're speaking in conversations.\n". "\n"; die(); } if (!empty($args['source-path'])) $source_path = $args['source-path']; if (!file_exists($source_path) OR !is_dir($source_path)) cmd_error("Path ".$path." don't seems to exist or is not a directory."); if (!empty($args['destination'])) $dest_path = $args['destination']; if (empty($dest_path)) cmd_error("Destination path is mandatory. Check help with --help for options and arguments."); //if (!empty($args['output-format']) AND preg_match('/^(irssi|text)$/i', $args['output-format'])) // $output_format = strtolower($args['output_format']); if (!empty($args['user-nick'])) $user_nick = $args['user-nick']; // SQLite Connection via PDO try { $db = new PDO('sqlite:'.$source_path.'/logs.db'); } catch (PDOException $dbex) { cmd_error("Can't connect to logs.db file: ".$dbex->getMessage()); } try { $results = $db->query('SELECT * FROM jids;')->fetchAll(); } catch (PDOException $dbex) { cmd_error("Error in fetching jid list: ".$dbex->getMessage()); } if (empty($results)) cmd_error("Can't continue: you have no JID !"); $jids = array(); foreach ($results as $line) { $jids[$line['jid_id']] = $line['jid']; } foreach ($jids as $id=>$jid) { echo "Exporting $jid ... "; try { $results = $db->query('SELECT * FROM logs WHERE jid_id="'.(int) $id.'" ORDER BY time ASC;'); } catch (PDOException $dbex) { cmd_error("Error: ".$dbex->getMessage()); } if (empty($results)) echo "Nothing to export.\n"; else { if ($output_format == 'irssi') log_export_irssi($jid, $results); echo "Done.\n"; } unset($results); } ?>