diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php
index 6f6d1b9af4..916d3d3f4c 100644
--- a/wp-admin/admin-functions.php
+++ b/wp-admin/admin-functions.php
@@ -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
diff --git a/wp-admin/import/livejournal.php b/wp-admin/import/livejournal.php
index 657fe93906..bc6bb91231 100644
--- a/wp-admin/import/livejournal.php
+++ b/wp-admin/import/livejournal.php
@@ -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('|(.*?)|is', $importdata, $this->posts);
- $this->posts = $this->posts[1];
- $index = 0;
- foreach ($this->posts as $post) {
+ preg_match_all('|(.*?)|is', $importdata, $posts);
+ $posts = $posts[1];
+ unset($importdata);
+ echo '
';
+ foreach ($posts as $post) {
+ flush();
preg_match('|(.*?)|is', $post, $post_title);
$post_title = $wpdb->escape(trim($post_title[1]));
if ( empty($post_title) ) {
- preg_match('|(.*?)|is', $post, $post_title);
+ preg_match('|(.*?)|is', $post, $post_title);
$post_title = $wpdb->escape(trim($post_title[1]));
}
-
- preg_match('|(.*?)|is', $post, $post_date);
+ preg_match('|(.*?)|is', $post, $post_date);
$post_date = strtotime($post_date[1]);
$post_date = gmdate('Y-m-d H:i:s', $post_date);
preg_match('|(.*?)|is', $post, $post_content);
- $post_content = str_replace(array (''), '', $wpdb->escape(trim($post_content[1])));
-
- if (!$post_content) {
- // This is for feeds that put content in description
- preg_match('|(.*?)|is', $post, $post_content);
- $post_content = $wpdb->escape($this->unhtmlentities(trim($post_content[1])));
- }
+ $post_content = str_replace(array (''), '', 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('
', '
', $post_content);
$post_content = str_replace('
', '
', $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 '';
-
- foreach ($this->posts as $post) {
- echo "- ".__('Importing post...');
-
- extract($post);
+ echo '
- ';
if ($post_id = post_exists($post_title, $post_content, $post_date)) {
- _e('Post already imported');
+ printf(__('Post %s already exists.'), stripslashes($post_title));
} else {
+ printf(__('Importing post %s...'), 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 '
';
+ break;
}
-
- _e('Done !');
}
+
+ preg_match_all('|(.*?)|is', $post, $comments);
+ $comments = $comments[1];
+
+ if ( $comments ) {
+ $comment_post_ID = $post_id;
+ $num_comments = 0;
+ foreach ($comments as $comment) {
+ preg_match('|(.*?)|is', $comment, $comment_content);
+ $comment_content = str_replace(array (''), '', 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('
', '
', $comment_content);
+ $comment_content = str_replace('
', '
', $comment_content);
+ $comment_content = $wpdb->escape($comment_content);
+
+ preg_match('|(.*?)|is', $comment, $comment_date);
+ $comment_date = trim($comment_date[1]);
+ $comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
+
+ preg_match('|(.*?)|is', $comment, $comment_author);
+ $comment_author = $wpdb->escape(trim($comment_author[1]));
+
+ preg_match('|(.*?)|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 '';
+ flush();
+ ob_flush();
}
-
echo '
';
-
}
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'));
?>
diff --git a/wp-includes/comment-functions.php b/wp-includes/comment-functions.php
index 21b9a999fe..af2d53aea9 100644
--- a/wp-includes/comment-functions.php
+++ b/wp-includes/comment-functions.php
@@ -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)