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