/ Published in: PHP
This is kind of a sloppy way of converting iChat transcripts to Adium transcripts.
To get this to work, export your chats using [Logorrhea](http://spiny.com/logorrhea/) (`File > Export Chats...`) then use the exported file as the `$infile` for this script. Also, change `$myscreenname` and `$myname` to your screenname and name, respectively. Finally, run the script in Terminal (`php this_script.php`).
**Note:** For this script to work, you must have PHP, PEAR, and PEAR's Date module installed (type `sudo pear install Date` in Terminal).
Sorry that this is a pain in the ass to get working. I wrote it very quickly for personal use and thought others might get some use out of it.
To get this to work, export your chats using [Logorrhea](http://spiny.com/logorrhea/) (`File > Export Chats...`) then use the exported file as the `$infile` for this script. Also, change `$myscreenname` and `$myname` to your screenname and name, respectively. Finally, run the script in Terminal (`php this_script.php`).
**Note:** For this script to work, you must have PHP, PEAR, and PEAR's Date module installed (type `sudo pear install Date` in Terminal).
Sorry that this is a pain in the ass to get working. I wrote it very quickly for personal use and thought others might get some use out of it.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php // This is the most inefficient piece of shit you will ever see require_once('Date.php'); $infile = $base . '/iChat Export.txt'; $outdir = $base . '/Converted Transcripts'; $myscreenname = 'theshane100'; $myname = 'Shaun Chapman'; $abort = false; // Create the output directory if it doesn't exist } $last_alias = ''; foreach ($lines as $line) { $valid = false; if ($count == 5) { $valid = true; } elseif ($count == 4) { // Likely a return $pieces[4] = "\n"; $valid = true; } if ($valid) { $alias = $pieces[0]; $info['sender'] = $pieces[1]; $info['message'] = $pieces[4]; if ($info['sender'] == $myscreenname) { $info['alias'] = $myname; } else { $info['alias'] = $alias; } $alias_arr[$alias][] = $info; } } // Build the dictionary foreach ($alias_arr as $messages) { foreach ($messages as $message) { $dictionary[$message['alias']] = $message['sender']; } elseif ($dictionary[$message['alias']] != $message['sender']) { echo "Warning: {$message['alias']} matches with both {$dictionary[$message['alias']]} and {$message['sender']}.\n"; //$abort = true; } } } if ($abort) { echo "Aborting...\n"; exit; } // This takes a long time foreach ($alias_arr as $alias => $messages) { $log_num = 0; foreach ($messages as $message) { $span = new Date_Span(); $span->setFromDateDiff($last_time, $this_time); if ((int)$span->toHours() >= 1) { $last_time = $this_time; $log_num++; } $log_arr[$alias][$log_num][] = $message; } } // Write matched files foreach ($log_arr as $alias => $logs) { $matched_folder = "$outdir/Matched"; $not_matched_folder = "$outdir/Not Matched"; foreach ($logs as $log) { // Find the other screenname $screenname = $myscreenname; foreach ($log as $message) { if ($message['sender'] != $myscreenname) { $screenname = $message['sender']; } } if ($screenname != $myscreenname) { $sn_folder = "$matched_folder/$screenname"; } else { // Try to match the screenname $screenname = $dictionary[$alias]; echo "Matched $alias to $screenname.\n"; $sn_folder = "$matched_folder/{$dictionary[$alias]}"; } else { $screenname = '[Unknown]'; echo "Could not find match for $alias.\n"; $sn_folder = "$not_matched_folder/$alias"; } } } $start_time = $log[0]['time']; $log_folder = "$sn_folder/$screenname (" . str_replace(':', '.', str_replace('-05:00', '-0500', $start_time)) . ").chatlog"; $log_file = "$log_folder/$screenname (" . str_replace(':', '.', str_replace('-05:00', '-0500', $start_time)) . ").xml"; $output = ''; // Create log folder if it doesn't exist } $output .= '<?xml version="1.0" encoding="UTF-8" ?>' . "\r"; $output .= "<!-- Converted from iChat Transcript -->\r"; $output .= '<chat xmlns="http://purl.org/net/ulf/ns/0.4-02" account="' . $myscreenname . '" service="AIM">'; $output .= '<event type="windowOpened" sender="' . $myscreenname . '" time="' . $start_time . '"/>' . "\r"; foreach ($log as $message) { $output .= '<message sender="' . $message['sender'] . '" time="' . $message['time'] . '" alias="' . $message['alias'] . '">'; $output .= '<div><span style="font-family: Helvetica; font-size: 12pt;">'; $output .= '</span></div></message>' . "\r"; } $output .= '<event type="windowClosed" sender="' . $myscreenname . '" time="' . $end_time . '"/>' . "\r"; $output .= "</chat>\r"; // Write to file } } ?>