function posts2wp($posts = '') { // General Housekeeping global $wpdb; $count = 0; $txpposts2wpposts = array(); $cats = array(); // Do the Magic if (is_array($posts)) { echo '<p>' . __('Importing Posts...') . '<br /><br /></p>'; foreach ($posts as $post) { $count++; extract($post); // Set Textpattern-to-WordPress status translation $stattrans = array(1 => 'draft', 2 => 'private', 3 => 'draft', 4 => 'publish', 5 => 'publish'); //Can we do this more efficiently? $uinfo = get_userdatabylogin($AuthorID) ? get_userdatabylogin($AuthorID) : 1; $authorid = is_object($uinfo) ? $uinfo->ID : $uinfo; $Title = $wpdb->escape($Title); $Body = $wpdb->escape($Body); $Excerpt = $wpdb->escape($Excerpt); $post_status = $stattrans[$Status]; // Import Post data into WordPress if ($pinfo = post_exists($Title, $Body)) { $ret_id = wp_insert_post(array('ID' => $pinfo, 'post_date' => $Posted, 'post_date_gmt' => $post_date_gmt, 'post_author' => $authorid, 'post_modified' => $LastMod, 'post_modified_gmt' => $post_modified_gmt, 'post_title' => $Title, 'post_content' => $Body, 'post_excerpt' => $Excerpt, 'post_status' => $post_status, 'post_name' => $url_title, 'comment_count' => $comments_count)); } else { $ret_id = wp_insert_post(array('post_date' => $Posted, 'post_date_gmt' => $post_date_gmt, 'post_author' => $authorid, 'post_modified' => $LastMod, 'post_modified_gmt' => $post_modified_gmt, 'post_title' => $Title, 'post_content' => $Body, 'post_excerpt' => $Excerpt, 'post_status' => $post_status, 'post_name' => $url_title, 'comment_count' => $comments_count)); } $txpposts2wpposts[$ID] = $ret_id; // Make Post-to-Category associations $cats = array(); if ($cat1 = get_catbynicename($Category1)) { $cats[1] = $cat1; } if ($cat2 = get_catbynicename($Category2)) { $cats[2] = $cat2; } if (!empty($cats)) { wp_set_post_categories($ret_id, $cats); } } } // Store ID translation for later use add_option('txpposts2wpposts', $txpposts2wpposts); echo '<p>' . sprintf(__('Done! <strong>%1$s</strong> posts imported.'), $count) . '<br /><br /></p>'; return true; }
function posts2wp($posts = '') { // General Housekeeping global $wpdb; $count = 0; $dcposts2wpposts = array(); $cats = array(); // Do the Magic if (is_array($posts)) { echo '<p>' . __('Importing Posts...') . '<br /><br /></p>'; foreach ($posts as $post) { $count++; extract($post); // Set DotClear-to-WordPress status translation $stattrans = array(0 => 'draft', 1 => 'publish'); $comment_status_map = array(0 => 'closed', 1 => 'open'); //Can we do this more efficiently? $uinfo = get_userdatabylogin($user_id) ? get_userdatabylogin($user_id) : 1; $authorid = is_object($uinfo) ? $uinfo->ID : $uinfo; $Title = $wpdb->escape(csc($post_titre)); $post_content = textconv($post_content); $post_excerpt = ""; if ($post_chapo != "") { $post_excerpt = textconv($post_chapo); $post_content = $post_excerpt . "\n<!--more-->\n" . $post_content; } $post_excerpt = $wpdb->escape($post_excerpt); $post_content = $wpdb->escape($post_content); $post_status = $stattrans[$post_pub]; // Import Post data into WordPress if ($pinfo = post_exists($Title, $post_content)) { $ret_id = wp_insert_post(array('ID' => $pinfo, 'post_author' => $authorid, 'post_date' => $post_dt, 'post_date_gmt' => $post_dt, 'post_modified' => $post_upddt, 'post_modified_gmt' => $post_upddt, 'post_title' => $Title, 'post_content' => $post_content, 'post_excerpt' => $post_excerpt, 'post_status' => $post_status, 'post_name' => $post_titre_url, 'comment_status' => $comment_status_map[$post_open_comment], 'ping_status' => $comment_status_map[$post_open_tb], 'comment_count' => $post_nb_comment + $post_nb_trackback)); } else { $ret_id = wp_insert_post(array('post_author' => $authorid, 'post_date' => $post_dt, 'post_date_gmt' => $post_dt, 'post_modified' => $post_modified_gmt, 'post_modified_gmt' => $post_modified_gmt, 'post_title' => $Title, 'post_content' => $post_content, 'post_excerpt' => $post_excerpt, 'post_status' => $post_status, 'post_name' => $post_titre_url, 'comment_status' => $comment_status_map[$post_open_comment], 'ping_status' => $comment_status_map[$post_open_tb], 'comment_count' => $post_nb_comment + $post_nb_trackback)); } $dcposts2wpposts[$post_id] = $ret_id; // Make Post-to-Category associations $cats = array(); if ($cat1 = get_catbynicename($post_cat_name)) { $cats[1] = $cat1; } if (!empty($cats)) { wp_set_post_cats('', $ret_id, $cats); } } } // Store ID translation for later use add_option('dcposts2wpposts', $dcposts2wpposts); echo '<p>' . sprintf(__('Done! <strong>%1$s</strong> posts imported.'), $count) . '<br /><br /></p>'; return true; }