Changeset 5406 for branches/2.0/wp-admin/import/textpattern.php
- Timestamp:
- 05/07/2007 04:10:20 PM (19 years ago)
- File:
-
- 1 edited
-
branches/2.0/wp-admin/import/textpattern.php (modified) (35 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/2.0/wp-admin/import/textpattern.php
r4239 r5406 5 5 if(!function_exists('get_catbynicename')) 6 6 { 7 function get_catbynicename($category_nicename) 7 function get_catbynicename($category_nicename) 8 8 { 9 9 global $wpdb; 10 10 11 11 $cat_id -= 0; // force numeric 12 12 $name = $wpdb->get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"'); 13 13 14 14 return $name; 15 15 } … … 50 50 echo '</div>'; 51 51 } 52 53 function greet() 54 { 55 echo '<p>'.__('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.').'</p>'; 52 53 function greet() { 54 echo '<div class="narrow">'; 55 echo '<p>'.__('Howdy! This imports categories, users, posts, comments, and links from any Textpattern 4.0.2+ into this blog.').'</p>'; 56 echo '<p>'.__('This has not been tested on previous versions of Textpattern. Mileage may vary.').'</p>'; 56 57 echo '<p>'.__('Your Textpattern Configuration settings are as follows:').'</p>'; 57 58 echo '<form action="admin.php?import=textpattern&step=1" method="post">'; 59 wp_nonce_field('import-textpattern'); 58 60 $this->db_form(); 59 echo '< input type="submit" name="submit" value="'.__('Import Categories').'" />';61 echo '<p class="submit"><input type="submit" name="submit" value="'.attribute_escape(__('Import Categories »')).'" /></p>'; 60 62 echo '</form>'; 63 echo '</div>'; 61 64 } 62 65 … … 68 71 set_magic_quotes_runtime(0); 69 72 $prefix = get_option('tpre'); 70 73 71 74 // Get Categories 72 return $txpdb->get_results('SELECT 73 id,74 name,75 title76 FROM '.$prefix.'txp_category77 WHERE type = "article"',78 ARRAY_A);79 } 80 75 return $txpdb->get_results('SELECT 76 id, 77 name, 78 title 79 FROM '.$prefix.'txp_category 80 WHERE type = "article"', 81 ARRAY_A); 82 } 83 81 84 function get_txp_users() 82 85 { … … 86 89 set_magic_quotes_runtime(0); 87 90 $prefix = get_option('tpre'); 88 91 89 92 // Get Users 90 93 91 94 return $txpdb->get_results('SELECT 92 user_id,93 name,94 RealName,95 email,96 privs97 FROM '.$prefix.'txp_users', ARRAY_A);98 } 99 95 user_id, 96 name, 97 RealName, 98 email, 99 privs 100 FROM '.$prefix.'txp_users', ARRAY_A); 101 } 102 100 103 function get_txp_posts() 101 104 { … … 104 107 set_magic_quotes_runtime(0); 105 108 $prefix = get_option('tpre'); 106 109 107 110 // Get Posts 108 return $txpdb->get_results('SELECT 109 ID,110 Posted,111 AuthorID,112 LastMod,113 Title,114 Body,115 Excerpt,116 Category1,117 Category2,118 Status,119 Keywords,120 url_title,121 comments_count122 FROM '.$prefix.'textpattern123 ', ARRAY_A);124 } 125 111 return $txpdb->get_results('SELECT 112 ID, 113 Posted, 114 AuthorID, 115 LastMod, 116 Title, 117 Body, 118 Excerpt, 119 Category1, 120 Category2, 121 Status, 122 Keywords, 123 url_title, 124 comments_count 125 FROM '.$prefix.'textpattern 126 ', ARRAY_A); 127 } 128 126 129 function get_txp_comments() 127 130 { … … 131 134 set_magic_quotes_runtime(0); 132 135 $prefix = get_option('tpre'); 133 136 134 137 // Get Comments 135 138 return $txpdb->get_results('SELECT * FROM '.$prefix.'txp_discuss', ARRAY_A); 136 139 } 137 140 138 141 function get_txp_links() 139 142 { … … 142 145 set_magic_quotes_runtime(0); 143 146 $prefix = get_option('tpre'); 144 145 return $txpdb->get_results('SELECT 146 id,147 date,148 category,149 url,150 linkname,151 description152 FROM '.$prefix.'txp_link',153 ARRAY_A);154 } 155 156 function cat2wp($categories='') 147 148 return $txpdb->get_results('SELECT 149 id, 150 date, 151 category, 152 url, 153 linkname, 154 description 155 FROM '.$prefix.'txp_link', 156 ARRAY_A); 157 } 158 159 function cat2wp($categories='') 157 160 { 158 161 // General Housekeeping … … 164 167 { 165 168 echo '<p>'.__('Importing Categories...').'<br /><br /></p>'; 166 foreach ($categories as $category) 169 foreach ($categories as $category) 167 170 { 168 171 $count++; 169 172 extract($category); 170 171 173 174 172 175 // Make Nice Variables 173 176 $name = $wpdb->escape($name); 174 177 $title = $wpdb->escape($title); 175 178 176 179 if($cinfo = category_exists($name)) 177 180 { … … 184 187 $txpcat2wpcat[$id] = $ret_id; 185 188 } 186 189 187 190 // Store category translation for future use 188 191 add_option('txpcat2wpcat',$txpcat2wpcat); … … 193 196 return false; 194 197 } 195 198 196 199 function users2wp($users='') 197 200 { … … 200 203 $count = 0; 201 204 $txpid2wpid = array(); 202 205 203 206 // Midnight Mojo 204 207 if(is_array($users)) … … 209 212 $count++; 210 213 extract($user); 211 214 212 215 // Make Nice Variables 213 216 $name = $wpdb->escape($name); 214 217 $RealName = $wpdb->escape($RealName); 215 218 216 219 if($uinfo = get_userdatabylogin($name)) 217 220 { 218 221 219 222 $ret_id = wp_insert_user(array( 220 223 'ID' => $uinfo->ID, … … 226 229 ); 227 230 } 228 else 231 else 229 232 { 230 233 $ret_id = wp_insert_user(array( … … 237 240 } 238 241 $txpid2wpid[$user_id] = $ret_id; 239 242 240 243 // Set Textpattern-to-WordPress permissions translation 241 244 $transperms = array(1 => '10', 2 => '9', 3 => '5', 4 => '4', 5 => '3', 6 => '2', 7 => '0'); 242 245 243 246 // Update Usermeta Data 244 247 $user = new WP_User($ret_id); … … 250 253 if('2' == $transperms[$privs]) { $user->set_role('contributor'); } 251 254 if('0' == $transperms[$privs]) { $user->set_role('subscriber'); } 252 255 253 256 update_usermeta( $ret_id, 'wp_user_level', $transperms[$privs] ); 254 257 update_usermeta( $ret_id, 'rich_editing', 'false'); 255 258 }// End foreach($users as $user) 256 259 257 260 // Store id translation array for future use 258 261 add_option('txpid2wpid',$txpid2wpid); 259 260 262 263 261 264 echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> users imported.'), $count).'<br /><br /></p>'; 262 265 return true; 263 266 }// End if(is_array($users) 264 267 265 268 echo __('No Users to Import!'); 266 269 return false; 267 270 268 271 }// End function user2wp() 269 272 270 273 function posts2wp($posts='') 271 274 { … … 284 287 $count++; 285 288 extract($post); 286 289 287 290 // Set Textpattern-to-WordPress status translation 288 291 $stattrans = array(1 => 'draft', 2 => 'private', 3 => 'draft', 4 => 'publish', 5 => 'publish'); 289 292 290 293 //Can we do this more efficiently? 291 294 $uinfo = ( get_userdatabylogin( $AuthorID ) ) ? get_userdatabylogin( $AuthorID ) : 1; … … 296 299 $Excerpt = $wpdb->escape($Excerpt); 297 300 $post_status = $stattrans[$Status]; 298 301 299 302 // Import Post data into WordPress 300 303 301 304 if($pinfo = post_exists($Title,$Body)) 302 305 { 303 306 $ret_id = wp_insert_post(array( 304 'ID' => $pinfo,305 'post_date' => $Posted,306 'post_date_gmt' => $post_date_gmt,307 'post_author' => $authorid,308 'post_modified' => $LastMod,309 'post_modified_gmt' => $post_modified_gmt,310 'post_title' => $Title,311 'post_content' => $Body,312 'post_excerpt' => $Excerpt,313 'post_status' => $post_status,314 'post_name' => $url_title,315 'comment_count' => $comments_count)316 );317 } 318 else 307 'ID' => $pinfo, 308 'post_date' => $Posted, 309 'post_date_gmt' => $post_date_gmt, 310 'post_author' => $authorid, 311 'post_modified' => $LastMod, 312 'post_modified_gmt' => $post_modified_gmt, 313 'post_title' => $Title, 314 'post_content' => $Body, 315 'post_excerpt' => $Excerpt, 316 'post_status' => $post_status, 317 'post_name' => $url_title, 318 'comment_count' => $comments_count) 319 ); 320 } 321 else 319 322 { 320 323 $ret_id = wp_insert_post(array( 321 'post_date' => $Posted,322 'post_date_gmt' => $post_date_gmt,323 'post_author' => $authorid,324 'post_modified' => $LastMod,325 'post_modified_gmt' => $post_modified_gmt,326 'post_title' => $Title,327 'post_content' => $Body,328 'post_excerpt' => $Excerpt,329 'post_status' => $post_status,330 'post_name' => $url_title,331 'comment_count' => $comments_count)332 );324 'post_date' => $Posted, 325 'post_date_gmt' => $post_date_gmt, 326 'post_author' => $authorid, 327 'post_modified' => $LastMod, 328 'post_modified_gmt' => $post_modified_gmt, 329 'post_title' => $Title, 330 'post_content' => $Body, 331 'post_excerpt' => $Excerpt, 332 'post_status' => $post_status, 333 'post_name' => $url_title, 334 'comment_count' => $comments_count) 335 ); 333 336 } 334 337 $txpposts2wpposts[$ID] = $ret_id; 335 338 336 339 // Make Post-to-Category associations 337 340 $cats = array(); … … 339 342 if($cat2 = get_catbynicename($Category2)) { $cats[2] = $cat2; } 340 343 341 if(!empty($cats)) { wp_set_post_cat s('',$ret_id, $cats); }344 if(!empty($cats)) { wp_set_post_categories($ret_id, $cats); } 342 345 } 343 346 } 344 347 // Store ID translation for later use 345 348 add_option('txpposts2wpposts',$txpposts2wpposts); 346 349 347 350 echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> posts imported.'), $count).'<br /><br /></p>'; 348 return true; 349 } 350 351 return true; 352 } 353 351 354 function comments2wp($comments='') 352 355 { … … 356 359 $txpcm2wpcm = array(); 357 360 $postarr = get_option('txpposts2wpposts'); 358 361 359 362 // Magic Mojo 360 363 if(is_array($comments)) … … 365 368 $count++; 366 369 extract($comment); 367 370 368 371 // WordPressify Data 369 372 $comment_ID = ltrim($discussid, '0'); … … 374 377 $web = $wpdb->escape($web); 375 378 $message = $wpdb->escape($message); 376 379 377 380 if($cinfo = comment_exists($name, $posted)) 378 381 { 379 382 // Update comments 380 383 $ret_id = wp_update_comment(array( 381 'comment_ID' => $cinfo,382 'comment_post_ID' => $comment_post_ID,383 'comment_author' => $name,384 'comment_author_email' => $email,385 'comment_author_url' => $web,386 'comment_date' => $posted,387 'comment_content' => $message,388 'comment_approved' => $comment_approved)389 );390 } 391 else 384 'comment_ID' => $cinfo, 385 'comment_post_ID' => $comment_post_ID, 386 'comment_author' => $name, 387 'comment_author_email' => $email, 388 'comment_author_url' => $web, 389 'comment_date' => $posted, 390 'comment_content' => $message, 391 'comment_approved' => $comment_approved) 392 ); 393 } 394 else 392 395 { 393 396 // Insert comments 394 397 $ret_id = wp_insert_comment(array( 395 'comment_post_ID' => $comment_post_ID,396 'comment_author' => $name,397 'comment_author_email' => $email,398 'comment_author_url' => $web,399 'comment_author_IP' => $ip,400 'comment_date' => $posted,401 'comment_content' => $message,402 'comment_approved' => $comment_approved)403 );398 'comment_post_ID' => $comment_post_ID, 399 'comment_author' => $name, 400 'comment_author_email' => $email, 401 'comment_author_url' => $web, 402 'comment_author_IP' => $ip, 403 'comment_date' => $posted, 404 'comment_content' => $message, 405 'comment_approved' => $comment_approved) 406 ); 404 407 } 405 408 $txpcm2wpcm[$comment_ID] = $ret_id; 406 409 } 407 410 // Store Comment ID translation for future use 408 add_option('txpcm2wpcm', $txpcm2wpcm); 409 411 add_option('txpcm2wpcm', $txpcm2wpcm); 412 410 413 // Associate newly formed categories with posts 411 414 get_comment_count($ret_id); 412 413 415 416 414 417 echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> comments imported.'), $count).'<br /><br /></p>'; 415 418 return true; … … 418 421 return false; 419 422 } 420 423 421 424 function links2wp($links='') 422 425 { … … 424 427 global $wpdb; 425 428 $count = 0; 426 429 427 430 // Deal with the links 428 431 if(is_array($links)) … … 433 436 $count++; 434 437 extract($link); 435 438 436 439 // Make nice vars 437 440 $category = $wpdb->escape($category); 438 441 $linkname = $wpdb->escape($linkname); 439 442 $description = $wpdb->escape($description); 440 443 441 444 if($linfo = link_exists($linkname)) 442 445 { … … 450 453 ); 451 454 } 452 else 455 else 453 456 { 454 457 $ret_id = wp_insert_link(array( … … 471 474 return false; 472 475 } 473 474 function import_categories() 475 { 476 // Category Import 476 477 function import_categories() 478 { 479 // Category Import 477 480 $cats = $this->get_txp_cats(); 478 481 $this->cat2wp($cats); 479 482 add_option('txp_cats', $cats); 480 481 482 483 484 485 483 486 echo '<form action="admin.php?import=textpattern&step=2" method="post">'; 484 printf('<input type="submit" name="submit" value="%s" />', __('Import Users')); 487 wp_nonce_field('import-textpattern'); 488 printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Users'))); 485 489 echo '</form>'; 486 490 487 491 } 488 492 489 493 function import_users() 490 494 { 491 495 // User Import 492 $users = $this->get_txp_users(); 496 $users = $this->get_txp_users(); 493 497 $this->users2wp($users); 494 498 495 499 echo '<form action="admin.php?import=textpattern&step=3" method="post">'; 496 printf('<input type="submit" name="submit" value="%s" />', __('Import Posts')); 500 wp_nonce_field('import-textpattern'); 501 printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Posts'))); 497 502 echo '</form>'; 498 503 } 499 504 500 505 function import_posts() 501 506 { … … 503 508 $posts = $this->get_txp_posts(); 504 509 $this->posts2wp($posts); 505 510 506 511 echo '<form action="admin.php?import=textpattern&step=4" method="post">'; 507 printf('<input type="submit" name="submit" value="%s" />', __('Import Comments')); 512 wp_nonce_field('import-textpattern'); 513 printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Comments'))); 508 514 echo '</form>'; 509 515 } 510 516 511 517 function import_comments() 512 518 { … … 514 520 $comments = $this->get_txp_comments(); 515 521 $this->comments2wp($comments); 516 522 517 523 echo '<form action="admin.php?import=textpattern&step=5" method="post">'; 518 printf('<input type="submit" name="submit" value="%s" />', __('Import Links')); 524 wp_nonce_field('import-textpattern'); 525 printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Links'))); 519 526 echo '</form>'; 520 527 } 521 528 522 529 function import_links() 523 530 { … … 526 533 $this->links2wp($links); 527 534 add_option('txp_links', $links); 528 535 529 536 echo '<form action="admin.php?import=textpattern&step=6" method="post">'; 530 printf('<input type="submit" name="submit" value="%s" />', __('Finish')); 537 wp_nonce_field('import-textpattern'); 538 printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Finish'))); 531 539 echo '</form>'; 532 540 } 533 541 534 542 function cleanup_txpimport() 535 543 { … … 547 555 $this->tips(); 548 556 } 549 557 550 558 function tips() 551 559 { … … 566 574 echo '<p>'.sprintf(__('That\'s it! What are you waiting for? Go <a href="%1$s">login</a>!'), '/wp-login.php').'</p>'; 567 575 } 568 576 569 577 function db_form() 570 578 { 571 echo '< ul>';572 printf('< li><label for="dbuser">%s</label> <input type="text" name="dbuser" id="dbuser" /></li>', __('Textpattern Database User:'));573 printf('< li><label for="dbpass">%s</label> <input type="password" name="dbpass" id="dbpass" /></li>', __('Textpattern Database Password:'));574 printf('< li><label for="dbname">%s</label> <input type="text" id="dbname" name="dbname" /></li>', __('Textpattern Database Name:'));575 printf('< li><label for="dbhost">%s</label> <input type="text" id="dbhost" name="dbhost" value="localhost" /></li>', __('Textpattern Database Host:'));576 printf('< li><label for="dbprefix">%s</label> <input type="text" name="dbprefix" id="dbprefix" /></li>', __('Textpattern Table prefix (if any):'));577 echo '</ ul>';578 } 579 580 function dispatch() 579 echo '<table class="editform">'; 580 printf('<tr><th scope="row"><label for="dbuser">%s</label></th><td><input type="text" name="dbuser" id="dbuser" /></td></tr>', __('Textpattern Database User:')); 581 printf('<tr><th scope="row"><label for="dbpass">%s</label></th><td><input type="password" name="dbpass" id="dbpass" /></td></tr>', __('Textpattern Database Password:')); 582 printf('<tr><th scope="row"><label for="dbname">%s</label></th><td><input type="text" id="dbname" name="dbname" /></td></tr>', __('Textpattern Database Name:')); 583 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:')); 584 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):')); 585 echo '</table>'; 586 } 587 588 function dispatch() 581 589 { 582 590 … … 586 594 $step = (int) $_GET['step']; 587 595 $this->header(); 588 589 if ( $step > 0 ) 596 597 if ( $step > 0 ) 590 598 { 599 check_admin_referer('import-textpattern'); 600 591 601 if($_POST['dbuser']) 592 602 { 593 603 if(get_option('txpuser')) 594 delete_option('txpuser'); 595 add_option('txpuser', $_POST['dbuser']);604 delete_option('txpuser'); 605 add_option('txpuser', sanitize_user($_POST['dbuser'], true)); 596 606 } 597 607 if($_POST['dbpass']) 598 608 { 599 609 if(get_option('txppass')) 600 delete_option('txppass'); 601 add_option('txppass', $_POST['dbpass']);602 } 603 610 delete_option('txppass'); 611 add_option('txppass', sanitize_user($_POST['dbpass'], true)); 612 } 613 604 614 if($_POST['dbname']) 605 615 { 606 616 if(get_option('txpname')) 607 delete_option('txpname'); 608 add_option('txpname', $_POST['dbname']);617 delete_option('txpname'); 618 add_option('txpname', sanitize_user($_POST['dbname'], true)); 609 619 } 610 620 if($_POST['dbhost']) … … 612 622 if(get_option('txphost')) 613 623 delete_option('txphost'); 614 add_option('txphost', $_POST['dbhost']);624 add_option('txphost', sanitize_user($_POST['dbhost'], true)); 615 625 } 616 626 if($_POST['dbprefix']) … … 618 628 if(get_option('tpre')) 619 629 delete_option('tpre'); 620 add_option('tpre', $_POST['dbprefix']);621 } 630 add_option('tpre', sanitize_user($_POST['dbprefix'])); 631 } 622 632 623 633 624 634 } 625 635 626 switch ($step) 636 switch ($step) 627 637 { 628 638 default: … … 649 659 break; 650 660 } 651 661 652 662 $this->footer(); 653 663 } 654 664 655 function Textpattern_Import() 656 { 657 // Nothing. 665 function Textpattern_Import() 666 { 667 // Nothing. 658 668 } 659 669 } 660 670 661 671 $txp_import = new Textpattern_Import(); 662 register_importer('textpattern', __('Textpattern'), __('Import posts from a Textpattern Blog'), array ($txp_import, 'dispatch'));672 register_importer('textpattern', __('Textpattern'), __('Import categories, users, posts, comments, and links from a Textpattern blog'), array ($txp_import, 'dispatch')); 663 673 ?>
Note: See TracChangeset
for help on using the changeset viewer.