web/wp-admin/import/textpattern.php
changeset 136 bde1974c263b
equal deleted inserted replaced
135:53cff4b4a802 136:bde1974c263b
       
     1 <?php
       
     2 /**
       
     3  * TextPattern Importer
       
     4  *
       
     5  * @package WordPress
       
     6  * @subpackage Importer
       
     7  */
       
     8 
       
     9 if(!function_exists('get_comment_count'))
       
    10 {
       
    11 	/**
       
    12 	 * Get the comment count for posts.
       
    13 	 *
       
    14 	 * @package WordPress
       
    15 	 * @subpackage Textpattern_Import
       
    16 	 *
       
    17 	 * @param int $post_ID Post ID
       
    18 	 * @return int
       
    19 	 */
       
    20 	function get_comment_count($post_ID)
       
    21 	{
       
    22 		global $wpdb;
       
    23 		return $wpdb->get_var( $wpdb->prepare("SELECT count(*) FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) );
       
    24 	}
       
    25 }
       
    26 
       
    27 if(!function_exists('link_exists'))
       
    28 {
       
    29 	/**
       
    30 	 * Check whether link already exists.
       
    31 	 *
       
    32 	 * @package WordPress
       
    33 	 * @subpackage Textpattern_Import
       
    34 	 *
       
    35 	 * @param string $linkname
       
    36 	 * @return int
       
    37 	 */
       
    38 	function link_exists($linkname)
       
    39 	{
       
    40 		global $wpdb;
       
    41 		return $wpdb->get_var( $wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_name = %s", $linkname) );
       
    42 	}
       
    43 }
       
    44 
       
    45 /**
       
    46  * TextPattern Importer Class
       
    47  *
       
    48  * @since unknown
       
    49  */
       
    50 class Textpattern_Import {
       
    51 
       
    52 	function header()
       
    53 	{
       
    54 		echo '<div class="wrap">';
       
    55 		screen_icon();
       
    56 		echo '<h2>'.__('Import Textpattern').'</h2>';
       
    57 		echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'</p>';
       
    58 	}
       
    59 
       
    60 	function footer()
       
    61 	{
       
    62 		echo '</div>';
       
    63 	}
       
    64 
       
    65 	function greet() {
       
    66 		echo '<div class="narrow">';
       
    67 		echo '<p>'.__('Howdy! This imports categories, users, posts, comments, and links from any Textpattern 4.0.2+ into this blog.').'</p>';
       
    68 		echo '<p>'.__('This has not been tested on previous versions of Textpattern.  Mileage may vary.').'</p>';
       
    69 		echo '<p>'.__('Your Textpattern Configuration settings are as follows:').'</p>';
       
    70 		echo '<form action="admin.php?import=textpattern&amp;step=1" method="post">';
       
    71 		wp_nonce_field('import-textpattern');
       
    72 		$this->db_form();
       
    73 		echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.esc_attr__('Import').'" /></p>';
       
    74 		echo '</form>';
       
    75 		echo '</div>';
       
    76 	}
       
    77 
       
    78 	function get_txp_cats()
       
    79 	{
       
    80 		global $wpdb;
       
    81 		// General Housekeeping
       
    82 		$txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost'));
       
    83 		set_magic_quotes_runtime(0);
       
    84 		$prefix = get_option('tpre');
       
    85 
       
    86 		// Get Categories
       
    87 		return $txpdb->get_results('SELECT
       
    88 			id,
       
    89 			name,
       
    90 			title
       
    91 			FROM '.$prefix.'txp_category
       
    92 			WHERE type = "article"',
       
    93 			ARRAY_A);
       
    94 	}
       
    95 
       
    96 	function get_txp_users()
       
    97 	{
       
    98 		global $wpdb;
       
    99 		// General Housekeeping
       
   100 		$txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost'));
       
   101 		set_magic_quotes_runtime(0);
       
   102 		$prefix = get_option('tpre');
       
   103 
       
   104 		// Get Users
       
   105 
       
   106 		return $txpdb->get_results('SELECT
       
   107 			user_id,
       
   108 			name,
       
   109 			RealName,
       
   110 			email,
       
   111 			privs
       
   112 			FROM '.$prefix.'txp_users', ARRAY_A);
       
   113 	}
       
   114 
       
   115 	function get_txp_posts()
       
   116 	{
       
   117 		// General Housekeeping
       
   118 		$txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost'));
       
   119 		set_magic_quotes_runtime(0);
       
   120 		$prefix = get_option('tpre');
       
   121 
       
   122 		// Get Posts
       
   123 		return $txpdb->get_results('SELECT
       
   124 			ID,
       
   125 			Posted,
       
   126 			AuthorID,
       
   127 			LastMod,
       
   128 			Title,
       
   129 			Body,
       
   130 			Excerpt,
       
   131 			Category1,
       
   132 			Category2,
       
   133 			Status,
       
   134 			Keywords,
       
   135 			url_title,
       
   136 			comments_count
       
   137 			FROM '.$prefix.'textpattern
       
   138 			', ARRAY_A);
       
   139 	}
       
   140 
       
   141 	function get_txp_comments()
       
   142 	{
       
   143 		global $wpdb;
       
   144 		// General Housekeeping
       
   145 		$txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost'));
       
   146 		set_magic_quotes_runtime(0);
       
   147 		$prefix = get_option('tpre');
       
   148 
       
   149 		// Get Comments
       
   150 		return $txpdb->get_results('SELECT * FROM '.$prefix.'txp_discuss', ARRAY_A);
       
   151 	}
       
   152 
       
   153 		function get_txp_links()
       
   154 	{
       
   155 		//General Housekeeping
       
   156 		$txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost'));
       
   157 		set_magic_quotes_runtime(0);
       
   158 		$prefix = get_option('tpre');
       
   159 
       
   160 		return $txpdb->get_results('SELECT
       
   161 			id,
       
   162 			date,
       
   163 			category,
       
   164 			url,
       
   165 			linkname,
       
   166 			description
       
   167 			FROM '.$prefix.'txp_link',
       
   168 			ARRAY_A);
       
   169 	}
       
   170 
       
   171 	function cat2wp($categories='')
       
   172 	{
       
   173 		// General Housekeeping
       
   174 		global $wpdb;
       
   175 		$count = 0;
       
   176 		$txpcat2wpcat = array();
       
   177 		// Do the Magic
       
   178 		if(is_array($categories))
       
   179 		{
       
   180 			echo '<p>'.__('Importing Categories...').'<br /><br /></p>';
       
   181 			foreach ($categories as $category)
       
   182 			{
       
   183 				$count++;
       
   184 				extract($category);
       
   185 
       
   186 
       
   187 				// Make Nice Variables
       
   188 				$name = $wpdb->escape($name);
       
   189 				$title = $wpdb->escape($title);
       
   190 
       
   191 				if($cinfo = category_exists($name))
       
   192 				{
       
   193 					$ret_id = wp_insert_category(array('cat_ID' => $cinfo, 'category_nicename' => $name, 'cat_name' => $title));
       
   194 				}
       
   195 				else
       
   196 				{
       
   197 					$ret_id = wp_insert_category(array('category_nicename' => $name, 'cat_name' => $title));
       
   198 				}
       
   199 				$txpcat2wpcat[$id] = $ret_id;
       
   200 			}
       
   201 
       
   202 			// Store category translation for future use
       
   203 			add_option('txpcat2wpcat',$txpcat2wpcat);
       
   204 			echo '<p>'.sprintf(_n('Done! <strong>%1$s</strong> category imported.', 'Done! <strong>%1$s</strong> categories imported.', $count), $count).'<br /><br /></p>';
       
   205 			return true;
       
   206 		}
       
   207 		echo __('No Categories to Import!');
       
   208 		return false;
       
   209 	}
       
   210 
       
   211 	function users2wp($users='')
       
   212 	{
       
   213 		// General Housekeeping
       
   214 		global $wpdb;
       
   215 		$count = 0;
       
   216 		$txpid2wpid = array();
       
   217 
       
   218 		// Midnight Mojo
       
   219 		if(is_array($users))
       
   220 		{
       
   221 			echo '<p>'.__('Importing Users...').'<br /><br /></p>';
       
   222 			foreach($users as $user)
       
   223 			{
       
   224 				$count++;
       
   225 				extract($user);
       
   226 
       
   227 				// Make Nice Variables
       
   228 				$name = $wpdb->escape($name);
       
   229 				$RealName = $wpdb->escape($RealName);
       
   230 
       
   231 				if($uinfo = get_userdatabylogin($name))
       
   232 				{
       
   233 
       
   234 					$ret_id = wp_insert_user(array(
       
   235 								'ID'			=> $uinfo->ID,
       
   236 								'user_login'	=> $name,
       
   237 								'user_nicename'	=> $RealName,
       
   238 								'user_email'	=> $email,
       
   239 								'user_url'		=> 'http://',
       
   240 								'display_name'	=> $name)
       
   241 								);
       
   242 				}
       
   243 				else
       
   244 				{
       
   245 					$ret_id = wp_insert_user(array(
       
   246 								'user_login'	=> $name,
       
   247 								'user_nicename'	=> $RealName,
       
   248 								'user_email'	=> $email,
       
   249 								'user_url'		=> 'http://',
       
   250 								'display_name'	=> $name)
       
   251 								);
       
   252 				}
       
   253 				$txpid2wpid[$user_id] = $ret_id;
       
   254 
       
   255 				// Set Textpattern-to-WordPress permissions translation
       
   256 				$transperms = array(1 => '10', 2 => '9', 3 => '5', 4 => '4', 5 => '3', 6 => '2', 7 => '0');
       
   257 
       
   258 				// Update Usermeta Data
       
   259 				$user = new WP_User($ret_id);
       
   260 				if('10' == $transperms[$privs]) { $user->set_role('administrator'); }
       
   261 				if('9'  == $transperms[$privs]) { $user->set_role('editor'); }
       
   262 				if('5'  == $transperms[$privs]) { $user->set_role('editor'); }
       
   263 				if('4'  == $transperms[$privs]) { $user->set_role('author'); }
       
   264 				if('3'  == $transperms[$privs]) { $user->set_role('contributor'); }
       
   265 				if('2'  == $transperms[$privs]) { $user->set_role('contributor'); }
       
   266 				if('0'  == $transperms[$privs]) { $user->set_role('subscriber'); }
       
   267 
       
   268 				update_usermeta( $ret_id, 'wp_user_level', $transperms[$privs] );
       
   269 				update_usermeta( $ret_id, 'rich_editing', 'false');
       
   270 			}// End foreach($users as $user)
       
   271 
       
   272 			// Store id translation array for future use
       
   273 			add_option('txpid2wpid',$txpid2wpid);
       
   274 
       
   275 
       
   276 			echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> users imported.'), $count).'<br /><br /></p>';
       
   277 			return true;
       
   278 		}// End if(is_array($users)
       
   279 
       
   280 		echo __('No Users to Import!');
       
   281 		return false;
       
   282 
       
   283 	}// End function user2wp()
       
   284 
       
   285 	function posts2wp($posts='')
       
   286 	{
       
   287 		// General Housekeeping
       
   288 		global $wpdb;
       
   289 		$count = 0;
       
   290 		$txpposts2wpposts = array();
       
   291 		$cats = array();
       
   292 
       
   293 		// Do the Magic
       
   294 		if(is_array($posts))
       
   295 		{
       
   296 			echo '<p>'.__('Importing Posts...').'<br /><br /></p>';
       
   297 			foreach($posts as $post)
       
   298 			{
       
   299 				$count++;
       
   300 				extract($post);
       
   301 
       
   302 				// Set Textpattern-to-WordPress status translation
       
   303 				$stattrans = array(1 => 'draft', 2 => 'private', 3 => 'draft', 4 => 'publish', 5 => 'publish');
       
   304 
       
   305 				//Can we do this more efficiently?
       
   306 				$uinfo = ( get_userdatabylogin( $AuthorID ) ) ? get_userdatabylogin( $AuthorID ) : 1;
       
   307 				$authorid = ( is_object( $uinfo ) ) ? $uinfo->ID : $uinfo ;
       
   308 
       
   309 				$Title = $wpdb->escape($Title);
       
   310 				$Body = $wpdb->escape($Body);
       
   311 				$Excerpt = $wpdb->escape($Excerpt);
       
   312 				$post_status = $stattrans[$Status];
       
   313 
       
   314 				// Import Post data into WordPress
       
   315 
       
   316 				if($pinfo = post_exists($Title,$Body))
       
   317 				{
       
   318 					$ret_id = wp_insert_post(array(
       
   319 						'ID'				=> $pinfo,
       
   320 						'post_date'			=> $Posted,
       
   321 						'post_date_gmt'		=> $post_date_gmt,
       
   322 						'post_author'		=> $authorid,
       
   323 						'post_modified'		=> $LastMod,
       
   324 						'post_modified_gmt' => $post_modified_gmt,
       
   325 						'post_title'		=> $Title,
       
   326 						'post_content'		=> $Body,
       
   327 						'post_excerpt'		=> $Excerpt,
       
   328 						'post_status'		=> $post_status,
       
   329 						'post_name'			=> $url_title,
       
   330 						'comment_count'		=> $comments_count)
       
   331 						);
       
   332 					if ( is_wp_error( $ret_id ) )
       
   333 						return $ret_id;
       
   334 				}
       
   335 				else
       
   336 				{
       
   337 					$ret_id = wp_insert_post(array(
       
   338 						'post_date'			=> $Posted,
       
   339 						'post_date_gmt'		=> $post_date_gmt,
       
   340 						'post_author'		=> $authorid,
       
   341 						'post_modified'		=> $LastMod,
       
   342 						'post_modified_gmt' => $post_modified_gmt,
       
   343 						'post_title'		=> $Title,
       
   344 						'post_content'		=> $Body,
       
   345 						'post_excerpt'		=> $Excerpt,
       
   346 						'post_status'		=> $post_status,
       
   347 						'post_name'			=> $url_title,
       
   348 						'comment_count'		=> $comments_count)
       
   349 						);
       
   350 					if ( is_wp_error( $ret_id ) )
       
   351 						return $ret_id;
       
   352 				}
       
   353 				$txpposts2wpposts[$ID] = $ret_id;
       
   354 
       
   355 				// Make Post-to-Category associations
       
   356 				$cats = array();
       
   357 				$category1 = get_category_by_slug($Category1);
       
   358 				$category1 = $category1->term_id;
       
   359 				$category2 = get_category_by_slug($Category2);
       
   360 				$category2 = $category2->term_id;
       
   361 				if($cat1 = $category1) { $cats[1] = $cat1; }
       
   362 				if($cat2 = $category2) { $cats[2] = $cat2; }
       
   363 
       
   364 				if(!empty($cats)) { wp_set_post_categories($ret_id, $cats); }
       
   365 			}
       
   366 		}
       
   367 		// Store ID translation for later use
       
   368 		add_option('txpposts2wpposts',$txpposts2wpposts);
       
   369 
       
   370 		echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> posts imported.'), $count).'<br /><br /></p>';
       
   371 		return true;
       
   372 	}
       
   373 
       
   374 	function comments2wp($comments='')
       
   375 	{
       
   376 		// General Housekeeping
       
   377 		global $wpdb;
       
   378 		$count = 0;
       
   379 		$txpcm2wpcm = array();
       
   380 		$postarr = get_option('txpposts2wpposts');
       
   381 
       
   382 		// Magic Mojo
       
   383 		if(is_array($comments))
       
   384 		{
       
   385 			echo '<p>'.__('Importing Comments...').'<br /><br /></p>';
       
   386 			foreach($comments as $comment)
       
   387 			{
       
   388 				$count++;
       
   389 				extract($comment);
       
   390 
       
   391 				// WordPressify Data
       
   392 				$comment_ID = ltrim($discussid, '0');
       
   393 				$comment_post_ID = $postarr[$parentid];
       
   394 				$comment_approved = (1 == $visible) ? 1 : 0;
       
   395 				$name = $wpdb->escape($name);
       
   396 				$email = $wpdb->escape($email);
       
   397 				$web = $wpdb->escape($web);
       
   398 				$message = $wpdb->escape($message);
       
   399 
       
   400 				$comment = array(
       
   401 							'comment_post_ID'	=> $comment_post_ID,
       
   402 							'comment_author'	=> $name,
       
   403 							'comment_author_IP'	=> $ip,
       
   404 							'comment_author_email'	=> $email,
       
   405 							'comment_author_url'	=> $web,
       
   406 							'comment_date'		=> $posted,
       
   407 							'comment_content'	=> $message,
       
   408 							'comment_approved'	=> $comment_approved);
       
   409 				$comment = wp_filter_comment($comment);
       
   410 
       
   411 				if ( $cinfo = comment_exists($name, $posted) ) {
       
   412 					// Update comments
       
   413 					$comment['comment_ID'] = $cinfo;
       
   414 					$ret_id = wp_update_comment($comment);
       
   415 				} else {
       
   416 					// Insert comments
       
   417 					$ret_id = wp_insert_comment($comment);
       
   418 				}
       
   419 				$txpcm2wpcm[$comment_ID] = $ret_id;
       
   420 			}
       
   421 			// Store Comment ID translation for future use
       
   422 			add_option('txpcm2wpcm', $txpcm2wpcm);
       
   423 
       
   424 			// Associate newly formed categories with posts
       
   425 			get_comment_count($ret_id);
       
   426 
       
   427 
       
   428 			echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> comments imported.'), $count).'<br /><br /></p>';
       
   429 			return true;
       
   430 		}
       
   431 		echo __('No Comments to Import!');
       
   432 		return false;
       
   433 	}
       
   434 
       
   435 	function links2wp($links='')
       
   436 	{
       
   437 		// General Housekeeping
       
   438 		global $wpdb;
       
   439 		$count = 0;
       
   440 
       
   441 		// Deal with the links
       
   442 		if(is_array($links))
       
   443 		{
       
   444 			echo '<p>'.__('Importing Links...').'<br /><br /></p>';
       
   445 			foreach($links as $link)
       
   446 			{
       
   447 				$count++;
       
   448 				extract($link);
       
   449 
       
   450 				// Make nice vars
       
   451 				$category = $wpdb->escape($category);
       
   452 				$linkname = $wpdb->escape($linkname);
       
   453 				$description = $wpdb->escape($description);
       
   454 
       
   455 				if($linfo = link_exists($linkname))
       
   456 				{
       
   457 					$ret_id = wp_insert_link(array(
       
   458 								'link_id'			=> $linfo,
       
   459 								'link_url'			=> $url,
       
   460 								'link_name'			=> $linkname,
       
   461 								'link_category'		=> $category,
       
   462 								'link_description'	=> $description,
       
   463 								'link_updated'		=> $date)
       
   464 								);
       
   465 				}
       
   466 				else
       
   467 				{
       
   468 					$ret_id = wp_insert_link(array(
       
   469 								'link_url'			=> $url,
       
   470 								'link_name'			=> $linkname,
       
   471 								'link_category'		=> $category,
       
   472 								'link_description'	=> $description,
       
   473 								'link_updated'		=> $date)
       
   474 								);
       
   475 				}
       
   476 				$txplinks2wplinks[$link_id] = $ret_id;
       
   477 			}
       
   478 			add_option('txplinks2wplinks',$txplinks2wplinks);
       
   479 			echo '<p>';
       
   480 			printf(_n('Done! <strong>%s</strong> link imported', 'Done! <strong>%s</strong> links imported', $count), $count);
       
   481 			echo '<br /><br /></p>';
       
   482 			return true;
       
   483 		}
       
   484 		echo __('No Links to Import!');
       
   485 		return false;
       
   486 	}
       
   487 
       
   488 	function import_categories()
       
   489 	{
       
   490 		// Category Import
       
   491 		$cats = $this->get_txp_cats();
       
   492 		$this->cat2wp($cats);
       
   493 		add_option('txp_cats', $cats);
       
   494 
       
   495 
       
   496 
       
   497 		echo '<form action="admin.php?import=textpattern&amp;step=2" method="post">';
       
   498 		wp_nonce_field('import-textpattern');
       
   499 		printf('<p class="submit"><input type="submit" name="submit" class="button" value="%s" /></p>', esc_attr__('Import Users'));
       
   500 		echo '</form>';
       
   501 
       
   502 	}
       
   503 
       
   504 	function import_users()
       
   505 	{
       
   506 		// User Import
       
   507 		$users = $this->get_txp_users();
       
   508 		$this->users2wp($users);
       
   509 
       
   510 		echo '<form action="admin.php?import=textpattern&amp;step=3" method="post">';
       
   511 		wp_nonce_field('import-textpattern');
       
   512 		printf('<p class="submit"><input type="submit" name="submit" class="button" value="%s" /></p>', esc_attr__('Import Posts'));
       
   513 		echo '</form>';
       
   514 	}
       
   515 
       
   516 	function import_posts()
       
   517 	{
       
   518 		// Post Import
       
   519 		$posts = $this->get_txp_posts();
       
   520 		$result = $this->posts2wp($posts);
       
   521 		if ( is_wp_error( $result ) )
       
   522 			return $result;
       
   523 
       
   524 		echo '<form action="admin.php?import=textpattern&amp;step=4" method="post">';
       
   525 		wp_nonce_field('import-textpattern');
       
   526 		printf('<p class="submit"><input type="submit" name="submit" class="button" value="%s" /></p>', esc_attr__('Import Comments'));
       
   527 		echo '</form>';
       
   528 	}
       
   529 
       
   530 	function import_comments()
       
   531 	{
       
   532 		// Comment Import
       
   533 		$comments = $this->get_txp_comments();
       
   534 		$this->comments2wp($comments);
       
   535 
       
   536 		echo '<form action="admin.php?import=textpattern&amp;step=5" method="post">';
       
   537 		wp_nonce_field('import-textpattern');
       
   538 		printf('<p class="submit"><input type="submit" name="submit" class="button" value="%s" /></p>', esc_attr__('Import Links'));
       
   539 		echo '</form>';
       
   540 	}
       
   541 
       
   542 	function import_links()
       
   543 	{
       
   544 		//Link Import
       
   545 		$links = $this->get_txp_links();
       
   546 		$this->links2wp($links);
       
   547 		add_option('txp_links', $links);
       
   548 
       
   549 		echo '<form action="admin.php?import=textpattern&amp;step=6" method="post">';
       
   550 		wp_nonce_field('import-textpattern');
       
   551 		printf('<p class="submit"><input type="submit" name="submit" class="button" value="%s" /></p>', esc_attr__('Finish'));
       
   552 		echo '</form>';
       
   553 	}
       
   554 
       
   555 	function cleanup_txpimport()
       
   556 	{
       
   557 		delete_option('tpre');
       
   558 		delete_option('txp_cats');
       
   559 		delete_option('txpid2wpid');
       
   560 		delete_option('txpcat2wpcat');
       
   561 		delete_option('txpposts2wpposts');
       
   562 		delete_option('txpcm2wpcm');
       
   563 		delete_option('txplinks2wplinks');
       
   564 		delete_option('txpuser');
       
   565 		delete_option('txppass');
       
   566 		delete_option('txpname');
       
   567 		delete_option('txphost');
       
   568 		do_action('import_done', 'textpattern');
       
   569 		$this->tips();
       
   570 	}
       
   571 
       
   572 	function tips()
       
   573 	{
       
   574 		echo '<p>'.__('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.').'</p>';
       
   575 		echo '<h3>'.__('Users').'</h3>';
       
   576 		echo '<p>'.sprintf(__('You have already setup WordPress and have been assigned an administrative login and password.  Forget it.  You didn&#8217;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.  <strong>Every user has the same username, but their passwords are reset to password123.</strong>  So <a href="%1$s">log in</a> and change it.'), get_bloginfo( 'wpurl' ) . '/wp-login.php').'</p>';
       
   577 		echo '<h3>'.__('Preserving Authors').'</h3>';
       
   578 		echo '<p>'.__('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.').'</p>';
       
   579 		echo '<h3>'.__('Textile').'</h3>';
       
   580 		echo '<p>'.__('Also, since you&#8217;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 <a href="http://www.huddledmasses.org/category/development/wordpress/textile/">Textile for WordPress</a>.  Trust me... You&#8217;ll want it.').'</p>';
       
   581 		echo '<h3>'.__('WordPress Resources').'</h3>';
       
   582 		echo '<p>'.__('Finally, there are numerous WordPress resources around the internet.  Some of them are:').'</p>';
       
   583 		echo '<ul>';
       
   584 		echo '<li>'.__('<a href="http://www.wordpress.org">The official WordPress site</a>').'</li>';
       
   585 		echo '<li>'.__('<a href="http://wordpress.org/support/">The WordPress support forums</a>').'</li>';
       
   586 		echo '<li>'.__('<a href="http://codex.wordpress.org">The Codex (In other words, the WordPress Bible)</a>').'</li>';
       
   587 		echo '</ul>';
       
   588 		echo '<p>'.sprintf(__('That&#8217;s it! What are you waiting for? Go <a href="%1$s">log in</a>!'), get_bloginfo( 'wpurl' ) . '/wp-login.php').'</p>';
       
   589 	}
       
   590 
       
   591 	function db_form()
       
   592 	{
       
   593 		echo '<table class="form-table">';
       
   594 		printf('<tr><th scope="row"><label for="dbuser">%s</label></th><td><input type="text" name="dbuser" id="dbuser" /></td></tr>', __('Textpattern Database User:'));
       
   595 		printf('<tr><th scope="row"><label for="dbpass">%s</label></th><td><input type="password" name="dbpass" id="dbpass" /></td></tr>', __('Textpattern Database Password:'));
       
   596 		printf('<tr><th scope="row"><label for="dbname">%s</label></th><td><input type="text" id="dbname" name="dbname" /></td></tr>', __('Textpattern Database Name:'));
       
   597 		printf('<tr><th scope="row"><label for="dbhost">%s</label></th><td><input type="text" id="dbhost" name="dbhost" value="localhost" /></td></tr>', __('Textpattern Database Host:'));
       
   598 		printf('<tr><th scope="row"><label for="dbprefix">%s</label></th><td><input type="text" name="dbprefix" id="dbprefix"  /></td></tr>', __('Textpattern Table prefix (if any):'));
       
   599 		echo '</table>';
       
   600 	}
       
   601 
       
   602 	function dispatch()
       
   603 	{
       
   604 
       
   605 		if (empty ($_GET['step']))
       
   606 			$step = 0;
       
   607 		else
       
   608 			$step = (int) $_GET['step'];
       
   609 		$this->header();
       
   610 
       
   611 		if ( $step > 0 )
       
   612 		{
       
   613 			check_admin_referer('import-textpattern');
       
   614 
       
   615 			if($_POST['dbuser'])
       
   616 			{
       
   617 				if(get_option('txpuser'))
       
   618 					delete_option('txpuser');
       
   619 				add_option('txpuser', sanitize_user($_POST['dbuser'], true));
       
   620 			}
       
   621 			if($_POST['dbpass'])
       
   622 			{
       
   623 				if(get_option('txppass'))
       
   624 					delete_option('txppass');
       
   625 				add_option('txppass',  sanitize_user($_POST['dbpass'], true));
       
   626 			}
       
   627 
       
   628 			if($_POST['dbname'])
       
   629 			{
       
   630 				if(get_option('txpname'))
       
   631 					delete_option('txpname');
       
   632 				add_option('txpname',  sanitize_user($_POST['dbname'], true));
       
   633 			}
       
   634 			if($_POST['dbhost'])
       
   635 			{
       
   636 				if(get_option('txphost'))
       
   637 					delete_option('txphost');
       
   638 				add_option('txphost',  sanitize_user($_POST['dbhost'], true));
       
   639 			}
       
   640 			if($_POST['dbprefix'])
       
   641 			{
       
   642 				if(get_option('tpre'))
       
   643 					delete_option('tpre');
       
   644 				add_option('tpre',  sanitize_user($_POST['dbprefix']));
       
   645 			}
       
   646 
       
   647 
       
   648 		}
       
   649 
       
   650 		switch ($step)
       
   651 		{
       
   652 			default:
       
   653 			case 0 :
       
   654 				$this->greet();
       
   655 				break;
       
   656 			case 1 :
       
   657 				$this->import_categories();
       
   658 				break;
       
   659 			case 2 :
       
   660 				$this->import_users();
       
   661 				break;
       
   662 			case 3 :
       
   663 				$result = $this->import_posts();
       
   664 				if ( is_wp_error( $result ) )
       
   665 					echo $result->get_error_message();
       
   666 				break;
       
   667 			case 4 :
       
   668 				$this->import_comments();
       
   669 				break;
       
   670 			case 5 :
       
   671 				$this->import_links();
       
   672 				break;
       
   673 			case 6 :
       
   674 				$this->cleanup_txpimport();
       
   675 				break;
       
   676 		}
       
   677 
       
   678 		$this->footer();
       
   679 	}
       
   680 
       
   681 	function Textpattern_Import()
       
   682 	{
       
   683 		// Nothing.
       
   684 	}
       
   685 }
       
   686 
       
   687 $txp_import = new Textpattern_Import();
       
   688 
       
   689 register_importer('textpattern', __('Textpattern'), __('Import categories, users, posts, comments, and links from a Textpattern blog.'), array ($txp_import, 'dispatch'));
       
   690 
       
   691 ?>