LJ tweaks.

git-svn-id: http://svn.automattic.com/wordpress/trunk@3375 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-12-29 01:25:41 +00:00
parent 529d5294ec
commit 00e695e6f5
3 changed files with 76 additions and 40 deletions

View File

@ -1750,8 +1750,16 @@ function wp_handle_upload(&$file, $overrides = false) {
} else {
$number = '';
$filename = $file['name'];
while ( file_exists($uploads['path'] . "/$filename") )
$filename = str_replace("$number.$ext", ++$number . ".$ext", $filename);
if ( empty($ext) )
$ext = '';
else
$ext = ".$ext";
while ( file_exists($uploads['path'] . "/$filename") ) {
if ( '' == "$number$ext" )
$filename = $filename . ++$number . $ext;
else
$filename = str_replace("$number$ext", ++$number . $ext, $filename);
}
}
// Move the file to the uploads dir

View File

@ -2,7 +2,6 @@
class LJ_Import {
var $posts = array ();
var $file;
function header() {
@ -25,75 +24,103 @@ class LJ_Import {
wp_import_upload_form("admin.php?import=livejournal&step=1");
}
function get_posts() {
function import_posts() {
global $wpdb, $current_user;
set_magic_quotes_runtime(0);
$datalines = file($this->file); // Read the file into an array
$importdata = implode('', $datalines); // squish it
$importdata = file($this->file); // Read the file into an array
$importdata = implode('', $importdata); // squish it
$importdata = str_replace(array ("\r\n", "\r"), "\n", $importdata);
preg_match_all('|<entry>(.*?)</entry>|is', $importdata, $this->posts);
$this->posts = $this->posts[1];
$index = 0;
foreach ($this->posts as $post) {
preg_match_all('|<entry>(.*?)</entry>|is', $importdata, $posts);
$posts = $posts[1];
unset($importdata);
echo '<ol>';
foreach ($posts as $post) {
flush();
preg_match('|<subject>(.*?)</subject>|is', $post, $post_title);
$post_title = $wpdb->escape(trim($post_title[1]));
if ( empty($post_title) ) {
preg_match('|<eventid>(.*?)</eventid>|is', $post, $post_title);
preg_match('|<itemid>(.*?)</itemid>|is', $post, $post_title);
$post_title = $wpdb->escape(trim($post_title[1]));
}
preg_match('|<eventtime>(.*?)</eventtime>|is', $post, $post_date);
preg_match('|<eventtime>(.*?)</eventtime>|is', $post, $post_date);
$post_date = strtotime($post_date[1]);
$post_date = gmdate('Y-m-d H:i:s', $post_date);
preg_match('|<event>(.*?)</event>|is', $post, $post_content);
$post_content = str_replace(array ('<![CDATA[', ']]>'), '', $wpdb->escape(trim($post_content[1])));
if (!$post_content) {
// This is for feeds that put content in description
preg_match('|<description>(.*?)</description>|is', $post, $post_content);
$post_content = $wpdb->escape($this->unhtmlentities(trim($post_content[1])));
}
$post_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($post_content[1]));
$post_content = $this->unhtmlentities($post_content);
// Clean up content
$post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content);
$post_content = str_replace('<br>', '<br />', $post_content);
$post_content = str_replace('<hr>', '<hr />', $post_content);
$post_content = $wpdb->escape($post_content);
$post_author = $current_user->ID;
$post_status = 'publish';
$this->posts[$index] = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
$index++;
}
}
function import_posts() {
echo '<ol>';
foreach ($this->posts as $post) {
echo "<li>".__('Importing post...');
extract($post);
echo '<li>';
if ($post_id = post_exists($post_title, $post_content, $post_date)) {
_e('Post already imported');
printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
} else {
printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
$post = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
$post_id = wp_insert_post($post);
if (!$post_id) {
_e("Couldn't get post ID");
return;
echo '</li>';
break;
}
_e('Done !');
}
preg_match_all('|<comment>(.*?)</comment>|is', $post, $comments);
$comments = $comments[1];
if ( $comments ) {
$comment_post_ID = $post_id;
$num_comments = 0;
foreach ($comments as $comment) {
preg_match('|<event>(.*?)</event>|is', $comment, $comment_content);
$comment_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($comment_content[1]));
$comment_content = $this->unhtmlentities($comment_content);
// Clean up content
$comment_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $comment_content);
$comment_content = str_replace('<br>', '<br />', $comment_content);
$comment_content = str_replace('<hr>', '<hr />', $comment_content);
$comment_content = $wpdb->escape($comment_content);
preg_match('|<eventtime>(.*?)</eventtime>|is', $comment, $comment_date);
$comment_date = trim($comment_date[1]);
$comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
preg_match('|<name>(.*?)</name>|is', $comment, $comment_author);
$comment_author = $wpdb->escape(trim($comment_author[1]));
preg_match('|<email>(.*?)</email>|is', $comment, $comment_author_email);
$comment_author_email = $wpdb->escape(trim($comment_author_email[1]));
$comment_approved = 1;
// Check if it's already there
if (!comment_exists($comment_author, $comment_date)) {
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_date', 'comment_content', 'comment_approved');
$commentdata = wp_filter_comment($commentdata);
wp_insert_comment($commentdata);
$num_comments++;
}
}
}
if ( $num_comments )
printf(__('(%s comments)'), $num_comments);
echo '</li>';
flush();
ob_flush();
}
echo '</ol>';
}
function import() {
@ -104,7 +131,6 @@ class LJ_Import {
}
$this->file = $file['file'];
$this->get_posts();
$this->import_posts();
wp_import_cleanup($file['id']);
@ -140,5 +166,5 @@ class LJ_Import {
$livejournal_import = new LJ_Import();
//register_importer('livejournal', 'LiveJournal', __('Import posts from LiveJournal'), array ($livejournal_import, 'dispatch'));
register_importer('livejournal', 'LiveJournal', __('Import posts from LiveJournal'), array ($livejournal_import, 'dispatch'));
?>

View File

@ -76,6 +76,8 @@ function wp_insert_comment($commentdata) {
$comment_date_gmt = gmdate('Y-m-d H:i:s', strtotime($comment_date) );
if ( ! isset($comment_parent) )
$comment_parent = 0;
if ( ! isset($comment_approved) )
$comment_approved = 1;
$result = $wpdb->query("INSERT INTO $wpdb->comments
(comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_date_gmt, comment_content, comment_approved, comment_agent, comment_type, comment_parent, user_id)