--- livejournal.inc.php Sun Apr 12 02:50:10 2009
+++ livejournal.inc.php.new Fri Apr 17 02:06:07 2009
@@ -1,5 +1,6 @@
'publish',
'default' => array('publish' => PUBLISH, 'draft' => DRAFT)),
+ array('text' => USERNAME,
+ 'type' => 'input',
+ 'name' => 'user',
+ 'default' => ''),
+
);
}
@@ -89,7 +95,7 @@
$encoding = $xml_encoding[1];
}
- preg_match_all('@(.*)@imsU', $xml, $xml_matches);
+ preg_match_all("@(.*)@imsU", $xml, $xml_matches);
if (!is_array($xml_matches)) {
return false;
}
@@ -149,6 +155,49 @@
}
}
+ function gatherComments($entrydata) {
+ $comments;
+ if (is_array($entrydata['children'])) {
+ $comments = array();
+ foreach($entrydata['children'] AS $idx3 => $commententry) {
+ if ($commententry['tag'] == 'comment' && is_array($commententry['children'])) {
+ $comment = array(
+ 'ip' => '127.0.0.1',
+ 'status' => 'approved',
+ 'name' => $commententry['attributes']['poster'] ? $commententry['attributes']['poster'] : 'Anonymous',
+ 'url' => $commententry['attributes']['poster'] ? "http://" . $commententry['attributes']['poster'] . ".livejournal.com/" : '',
+ 'email' => '',
+ 'jtalkid' => $commententry['attributes']['jtalkid'],
+ 'jparentid' => $commententry['attributes']['parentid'] ? $commententry['attributes']['parentid'] : 0
+ );
+ if ($comment['name'] == $this->data['user']) {
+ if (!empty($serendipity['realname'])) {
+ $comment['name'] = $serendipity['realname'];
+ } else {
+ $comment['name'] = $serendipity['user'];
+ }
+ $comment['url'] = $serendipity['baseURL'];
+ }
+ foreach($commententry['children'] AS $idx4 => $commentdata) {
+ switch($commentdata['tag']) {
+ case 'subject':
+ $comment['title'] = $commentdata['value'];
+ break;
+ case 'body':
+ $comment['comment'] = $commentdata['value'];
+ break;
+ case 'date':
+ $comment['time'] = $this->getTimestamp($commentdata['value']);
+ break;
+ }
+ }
+ array_push($comments, $comment);
+ }
+ }
+ }
+ return $comments;
+ }
+
function import() {
global $serendipity;
@@ -186,6 +235,10 @@
case 'eventtime':
$new_entry['timestamp'] = $this->getTimestamp($entrydata['value']);
break;
+
+ case 'date':
+ $new_entry['timestamp'] = $this->getTimestamp($entrydata['value']);
+ break;
case 'subject':
$new_entry['title'] = $entrydata['value'];
@@ -194,10 +247,26 @@
case 'event':
$new_entry['body'] = $entrydata['value'];
break;
+ case 'comments':
+ $new_entry['comments'] = $this->gatherComments($entrydata);
+ break;
}
}
$id = serendipity_updertEntry($new_entry);
echo 'Inserted entry #' . $id . ', "' . htmlspecialchars($new_entry['title']) . '"
' . "\n";
+ if (is_array($new_entry['comments'])) {
+ $cid_map = array();
+ $jids = array();
+ foreach($new_entry['comments'] AS $comment) {
+ array_push($jids, $comment['jtalkid']);
+ if (array_key_exists($comment['jparentid'], $cid_map)) {
+ $comment['parent_id'] = $cid_map[$comment['jparentid']];
+ }
+ $cid = serendipity_insertComment($id, $comment);
+ $cid_map[$comment['jtalkid']] = $cid;
+ }
+ echo 'Inserted comments for entry #' . $id . '
' . "\n";
+ }
if (function_exists('ob_flush')) {
@ob_flush();