X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/cc7b1505cd9fafd87c3672f669e13e98b0c544f7..7688c6ba71852cd89123b62b2d57683535e4702a:/wp-admin/import/textpattern.php diff --git a/wp-admin/import/textpattern.php b/wp-admin/import/textpattern.php index 44b0fc36..1fe54c8c 100644 --- a/wp-admin/import/textpattern.php +++ b/wp-admin/import/textpattern.php @@ -2,18 +2,6 @@ /** Add These Functions to make our lives easier **/ -if(!function_exists('get_catbynicename')) -{ - function get_catbynicename($category_nicename) - { - global $wpdb; - - $cat_id -= 0; // force numeric - $name = $wpdb->get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"'); - - return $name; - } -} if(!function_exists('get_comment_count')) { @@ -38,26 +26,29 @@ if(!function_exists('link_exists')) **/ class Textpattern_Import { - function header() + function header() { echo '
'; echo '

'.__('Import Textpattern').'

'; echo '

'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'

'; } - function footer() + function footer() { echo '
'; } - - function greet() - { - echo '

'.__('Howdy! This importer allows you to extract posts from any Textpattern 4.0.2+ into your blog. This has not been tested on previous versions of Textpattern. Mileage may vary.').'

'; + + function greet() { + echo '
'; + echo '

'.__('Howdy! This imports categories, users, posts, comments, and links from any Textpattern 4.0.2+ into this blog.').'

'; + echo '

'.__('This has not been tested on previous versions of Textpattern. Mileage may vary.').'

'; echo '

'.__('Your Textpattern Configuration settings are as follows:').'

'; echo '
'; + wp_nonce_field('import-textpattern'); $this->db_form(); - echo ''; + echo '

'; echo '
'; + echo '
'; } function get_txp_cats() @@ -67,17 +58,17 @@ class Textpattern_Import { $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); set_magic_quotes_runtime(0); $prefix = get_option('tpre'); - + // Get Categories - return $txpdb->get_results('SELECT - id, - name, - title - FROM '.$prefix.'txp_category - WHERE type = "article"', - ARRAY_A); + return $txpdb->get_results('SELECT + id, + name, + title + FROM '.$prefix.'txp_category + WHERE type = "article"', + ARRAY_A); } - + function get_txp_users() { global $wpdb; @@ -85,44 +76,44 @@ class Textpattern_Import { $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); set_magic_quotes_runtime(0); $prefix = get_option('tpre'); - + // Get Users - + return $txpdb->get_results('SELECT - user_id, - name, - RealName, - email, - privs - FROM '.$prefix.'txp_users', ARRAY_A); + user_id, + name, + RealName, + email, + privs + FROM '.$prefix.'txp_users', ARRAY_A); } - + function get_txp_posts() { // General Housekeeping $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); set_magic_quotes_runtime(0); $prefix = get_option('tpre'); - + // Get Posts - return $txpdb->get_results('SELECT - ID, - Posted, - AuthorID, - LastMod, - Title, - Body, - Excerpt, - Category1, - Category2, - Status, - Keywords, - url_title, - comments_count - FROM '.$prefix.'textpattern - ', ARRAY_A); + return $txpdb->get_results('SELECT + ID, + Posted, + AuthorID, + LastMod, + Title, + Body, + Excerpt, + Category1, + Category2, + Status, + Keywords, + url_title, + comments_count + FROM '.$prefix.'textpattern + ', ARRAY_A); } - + function get_txp_comments() { global $wpdb; @@ -130,30 +121,30 @@ class Textpattern_Import { $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); set_magic_quotes_runtime(0); $prefix = get_option('tpre'); - + // Get Comments return $txpdb->get_results('SELECT * FROM '.$prefix.'txp_discuss', ARRAY_A); } - + function get_txp_links() { //General Housekeeping $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); set_magic_quotes_runtime(0); $prefix = get_option('tpre'); - - return $txpdb->get_results('SELECT - id, - date, - category, - url, - linkname, - description - FROM '.$prefix.'txp_link', - ARRAY_A); + + return $txpdb->get_results('SELECT + id, + date, + category, + url, + linkname, + description + FROM '.$prefix.'txp_link', + ARRAY_A); } - - function cat2wp($categories='') + + function cat2wp($categories='') { // General Housekeeping global $wpdb; @@ -163,16 +154,16 @@ class Textpattern_Import { if(is_array($categories)) { echo '

'.__('Importing Categories...').'

'; - foreach ($categories as $category) + foreach ($categories as $category) { $count++; extract($category); - - + + // Make Nice Variables $name = $wpdb->escape($name); $title = $wpdb->escape($title); - + if($cinfo = category_exists($name)) { $ret_id = wp_insert_category(array('cat_ID' => $cinfo, 'category_nicename' => $name, 'cat_name' => $title)); @@ -183,7 +174,7 @@ class Textpattern_Import { } $txpcat2wpcat[$id] = $ret_id; } - + // Store category translation for future use add_option('txpcat2wpcat',$txpcat2wpcat); echo '

'.sprintf(__('Done! %1$s categories imported.'), $count).'

'; @@ -192,14 +183,14 @@ class Textpattern_Import { echo __('No Categories to Import!'); return false; } - + function users2wp($users='') { // General Housekeeping global $wpdb; $count = 0; $txpid2wpid = array(); - + // Midnight Mojo if(is_array($users)) { @@ -208,14 +199,14 @@ class Textpattern_Import { { $count++; extract($user); - + // Make Nice Variables $name = $wpdb->escape($name); $RealName = $wpdb->escape($RealName); - + if($uinfo = get_userdatabylogin($name)) { - + $ret_id = wp_insert_user(array( 'ID' => $uinfo->ID, 'user_login' => $name, @@ -225,7 +216,7 @@ class Textpattern_Import { 'display_name' => $name) ); } - else + else { $ret_id = wp_insert_user(array( 'user_login' => $name, @@ -236,10 +227,10 @@ class Textpattern_Import { ); } $txpid2wpid[$user_id] = $ret_id; - + // Set Textpattern-to-WordPress permissions translation $transperms = array(1 => '10', 2 => '9', 3 => '5', 4 => '4', 5 => '3', 6 => '2', 7 => '0'); - + // Update Usermeta Data $user = new WP_User($ret_id); if('10' == $transperms[$privs]) { $user->set_role('administrator'); } @@ -249,24 +240,24 @@ class Textpattern_Import { if('3' == $transperms[$privs]) { $user->set_role('contributor'); } if('2' == $transperms[$privs]) { $user->set_role('contributor'); } if('0' == $transperms[$privs]) { $user->set_role('subscriber'); } - + update_usermeta( $ret_id, 'wp_user_level', $transperms[$privs] ); update_usermeta( $ret_id, 'rich_editing', 'false'); }// End foreach($users as $user) - + // Store id translation array for future use add_option('txpid2wpid',$txpid2wpid); - - + + echo '

'.sprintf(__('Done! %1$s users imported.'), $count).'

'; return true; }// End if(is_array($users) - + echo __('No Users to Import!'); return false; - + }// End function user2wp() - + function posts2wp($posts='') { // General Housekeeping @@ -283,10 +274,10 @@ class Textpattern_Import { { $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 ; @@ -295,59 +286,67 @@ class Textpattern_Import { $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) - ); + '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) + ); + if ( is_wp_error( $ret_id ) ) + return $ret_id; } - else + 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) - ); + '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) + ); + if ( is_wp_error( $ret_id ) ) + return $ret_id; } $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; } + $category1 = get_category_by_slug($Category1); + $category1 = $category1->term_id; + $category2 = get_category_by_slug($Category2); + $category2 = $category1->term_id; + if($cat1 = $category1) { $cats[1] = $cat1; } + if($cat2 = $category2) { $cats[2] = $cat2; } - if(!empty($cats)) { wp_set_post_cats('', $ret_id, $cats); } + if(!empty($cats)) { wp_set_post_categories($ret_id, $cats); } } } // Store ID translation for later use add_option('txpposts2wpposts',$txpposts2wpposts); - + echo '

'.sprintf(__('Done! %1$s posts imported.'), $count).'

'; - return true; + return true; } - + function comments2wp($comments='') { // General Housekeeping @@ -355,7 +354,7 @@ class Textpattern_Import { $count = 0; $txpcm2wpcm = array(); $postarr = get_option('txpposts2wpposts'); - + // Magic Mojo if(is_array($comments)) { @@ -364,7 +363,7 @@ class Textpattern_Import { { $count++; extract($comment); - + // WordPressify Data $comment_ID = ltrim($discussid, '0'); $comment_post_ID = $postarr[$parentid]; @@ -373,57 +372,57 @@ class Textpattern_Import { $email = $wpdb->escape($email); $web = $wpdb->escape($web); $message = $wpdb->escape($message); - + if($cinfo = comment_exists($name, $posted)) { // Update comments $ret_id = wp_update_comment(array( - 'comment_ID' => $cinfo, - 'comment_post_ID' => $comment_post_ID, - 'comment_author' => $name, - 'comment_author_email' => $email, - 'comment_author_url' => $web, - 'comment_date' => $posted, - 'comment_content' => $message, - 'comment_approved' => $comment_approved) - ); + 'comment_ID' => $cinfo, + 'comment_post_ID' => $comment_post_ID, + 'comment_author' => $name, + 'comment_author_email' => $email, + 'comment_author_url' => $web, + 'comment_date' => $posted, + 'comment_content' => $message, + 'comment_approved' => $comment_approved) + ); } - else + else { // Insert comments $ret_id = wp_insert_comment(array( - 'comment_post_ID' => $comment_post_ID, - 'comment_author' => $name, - 'comment_author_email' => $email, - 'comment_author_url' => $web, - 'comment_author_IP' => $ip, - 'comment_date' => $posted, - 'comment_content' => $message, - 'comment_approved' => $comment_approved) - ); + 'comment_post_ID' => $comment_post_ID, + 'comment_author' => $name, + 'comment_author_email' => $email, + 'comment_author_url' => $web, + 'comment_author_IP' => $ip, + 'comment_date' => $posted, + 'comment_content' => $message, + 'comment_approved' => $comment_approved) + ); } $txpcm2wpcm[$comment_ID] = $ret_id; } // Store Comment ID translation for future use - add_option('txpcm2wpcm', $txpcm2wpcm); - + add_option('txpcm2wpcm', $txpcm2wpcm); + // Associate newly formed categories with posts get_comment_count($ret_id); - - + + echo '

'.sprintf(__('Done! %1$s comments imported.'), $count).'

'; return true; } echo __('No Comments to Import!'); return false; } - + function links2wp($links='') { // General Housekeeping global $wpdb; $count = 0; - + // Deal with the links if(is_array($links)) { @@ -432,12 +431,12 @@ class Textpattern_Import { { $count++; extract($link); - + // Make nice vars $category = $wpdb->escape($category); $linkname = $wpdb->escape($linkname); $description = $wpdb->escape($description); - + if($linfo = link_exists($linkname)) { $ret_id = wp_insert_link(array( @@ -449,7 +448,7 @@ class Textpattern_Import { 'link_updated' => $date) ); } - else + else { $ret_id = wp_insert_link(array( 'link_url' => $url, @@ -470,67 +469,74 @@ class Textpattern_Import { echo __('No Links to Import!'); return false; } - - function import_categories() - { - // Category Import + + function import_categories() + { + // Category Import $cats = $this->get_txp_cats(); $this->cat2wp($cats); add_option('txp_cats', $cats); - - - + + + echo '
'; - printf('', __('Import Users')); + wp_nonce_field('import-textpattern'); + printf('', attribute_escape(__('Import Users'))); echo '
'; } - + function import_users() { // User Import - $users = $this->get_txp_users(); + $users = $this->get_txp_users(); $this->users2wp($users); - + echo '
'; - printf('', __('Import Posts')); + wp_nonce_field('import-textpattern'); + printf('', attribute_escape(__('Import Posts'))); echo '
'; } - + function import_posts() { // Post Import $posts = $this->get_txp_posts(); - $this->posts2wp($posts); - + $result = $this->posts2wp($posts); + if ( is_wp_error( $result ) ) + return $result; + echo '
'; - printf('', __('Import Comments')); + wp_nonce_field('import-textpattern'); + printf('', attribute_escape(__('Import Comments'))); echo '
'; } - + function import_comments() { // Comment Import $comments = $this->get_txp_comments(); $this->comments2wp($comments); - + echo '
'; - printf('', __('Import Links')); + wp_nonce_field('import-textpattern'); + printf('', attribute_escape(__('Import Links'))); echo '
'; } - + function import_links() { //Link Import $links = $this->get_txp_links(); $this->links2wp($links); add_option('txp_links', $links); - + echo '
'; - printf('', __('Finish')); + wp_nonce_field('import-textpattern'); + printf('', attribute_escape(__('Finish'))); echo '
'; } - + function cleanup_txpimport() { delete_option('tpre'); @@ -546,38 +552,38 @@ class Textpattern_Import { delete_option('txphost'); $this->tips(); } - + function tips() { echo '

'.__('Welcome to WordPress. We hope (and expect!) that you will find this platform incredibly rewarding! As a new WordPress user coming from Textpattern, there are some things that we would like to point out. Hopefully, they will help your transition go as smoothly as possible.').'

'; echo '

'.__('Users').'

'; - echo '

'.sprintf(__('You have already setup WordPress and have been assigned an administrative login and password. Forget it. You didn\'t have that login in Textpattern, why should you have it here? Instead we have taken care to import all of your users into our system. Unfortunately there is one downside. Because both WordPress and Textpattern uses a strong encryption hash with passwords, it is impossible to decrypt it and we are forced to assign temporary passwords to all your users. Every user has the same username, but their passwords are reset to password123. So Login and change it.'), '/wp-login.php').'

'; + echo '

'.sprintf(__('You have already setup WordPress and have been assigned an administrative login and password. Forget it. You didn’t have that login in Textpattern, why should you have it here? Instead we have taken care to import all of your users into our system. Unfortunately there is one downside. Because both WordPress and Textpattern uses a strong encryption hash with passwords, it is impossible to decrypt it and we are forced to assign temporary passwords to all your users. Every user has the same username, but their passwords are reset to password123. So Login and change it.'), get_bloginfo( 'wpurl' ) . '/wp-login.php').'

'; echo '

'.__('Preserving Authors').'

'; echo '

'.__('Secondly, we have attempted to preserve post authors. If you are the only author or contributor to your blog, then you are safe. In most cases, we are successful in this preservation endeavor. However, if we cannot ascertain the name of the writer due to discrepancies between database tables, we assign it to you, the administrative user.').'

'; echo '

'.__('Textile').'

'; - echo '

'.__('Also, since you\'re coming from Textpattern, you probably have been using Textile to format your comments and posts. If this is the case, we recommend downloading and installing Textile for WordPress. Trust me... You\'ll want it.').'

'; + echo '

'.__('Also, since you’re coming from Textpattern, you probably have been using Textile to format your comments and posts. If this is the case, we recommend downloading and installing Textile for WordPress. Trust me... You’ll want it.').'

'; echo '

'.__('WordPress Resources').'

'; echo '

'.__('Finally, there are numerous WordPress resources around the internet. Some of them are:').'

'; echo ''; - echo '

'.sprintf(__('That\'s it! What are you waiting for? Go login!'), '/wp-login.php').'

'; + echo '

'.sprintf(__('That’s it! What are you waiting for? Go login!'), get_bloginfo( 'wpurl' ) . '/wp-login.php').'

'; } - + function db_form() { - echo ''; + echo ''; + printf('', __('Textpattern Database User:')); + printf('', __('Textpattern Database Password:')); + printf('', __('Textpattern Database Name:')); + printf('', __('Textpattern Database Host:')); + printf('', __('Textpattern Table prefix (if any):')); + echo '
'; } - - function dispatch() + + function dispatch() { if (empty ($_GET['step'])) @@ -585,45 +591,47 @@ class Textpattern_Import { else $step = (int) $_GET['step']; $this->header(); - - if ( $step > 0 ) + + if ( $step > 0 ) { + check_admin_referer('import-textpattern'); + if($_POST['dbuser']) { if(get_option('txpuser')) - delete_option('txpuser'); - add_option('txpuser',$_POST['dbuser']); + delete_option('txpuser'); + add_option('txpuser', sanitize_user($_POST['dbuser'], true)); } if($_POST['dbpass']) { if(get_option('txppass')) - delete_option('txppass'); - add_option('txppass',$_POST['dbpass']); + delete_option('txppass'); + add_option('txppass', sanitize_user($_POST['dbpass'], true)); } - + if($_POST['dbname']) { if(get_option('txpname')) - delete_option('txpname'); - add_option('txpname',$_POST['dbname']); + delete_option('txpname'); + add_option('txpname', sanitize_user($_POST['dbname'], true)); } if($_POST['dbhost']) { if(get_option('txphost')) delete_option('txphost'); - add_option('txphost',$_POST['dbhost']); + add_option('txphost', sanitize_user($_POST['dbhost'], true)); } if($_POST['dbprefix']) { if(get_option('tpre')) delete_option('tpre'); - add_option('tpre',$_POST['dbprefix']); - } + add_option('tpre', sanitize_user($_POST['dbprefix'])); + } } - switch ($step) + switch ($step) { default: case 0 : @@ -636,7 +644,9 @@ class Textpattern_Import { $this->import_users(); break; case 3 : - $this->import_posts(); + $result = $this->import_posts(); + if ( is_wp_error( $result ) ) + echo $result->get_error_message(); break; case 4 : $this->import_comments(); @@ -648,16 +658,16 @@ class Textpattern_Import { $this->cleanup_txpimport(); break; } - + $this->footer(); } - function Textpattern_Import() + function Textpattern_Import() { - // Nothing. + // Nothing. } } $txp_import = new Textpattern_Import(); -register_importer('textpattern', 'Textpattern', __('Import posts from a Textpattern Blog'), array ($txp_import, 'dispatch')); +register_importer('textpattern', __('Textpattern'), __('Import categories, users, posts, comments, and links from a Textpattern blog'), array ($txp_import, 'dispatch')); ?>