-
+ 215899A4BDD06858E9FC56643D867C70DFCFD95467439A88419C6A56ED19B9F906A10DD40BD32D297094E3EEED17E3D70C77719251DF3A0FFE921017F333124D
mp-wp/wp-admin/import/blogware.php
(0 . 0)(1 . 215)
17380 <?php
17381 /**
17382 * Blogware XML Importer
17383 *
17384 * @package WordPress
17385 * @subpackage Importer
17386 * @author Shayne Sweeney
17387 * @link http://www.theshayne.com/
17388 */
17389
17390 /**
17391 * Blogware XML Importer class
17392 *
17393 * Extract posts from Blogware XML export file into your blog.
17394 *
17395 * @since unknown
17396 */
17397 class BW_Import {
17398
17399 var $file;
17400
17401 function header() {
17402 echo '<div class="wrap">';
17403 screen_icon();
17404 echo '<h2>'.__('Import Blogware').'</h2>';
17405 }
17406
17407 function footer() {
17408 echo '</div>';
17409 }
17410
17411 function unhtmlentities($string) { // From php.net for < 4.3 compat
17412 $trans_tbl = get_html_translation_table(HTML_ENTITIES);
17413 $trans_tbl = array_flip($trans_tbl);
17414 return strtr($string, $trans_tbl);
17415 }
17416
17417 function greet() {
17418 echo '<div class="narrow">';
17419 echo '<p>'.__('Howdy! This importer allows you to extract posts from Blogware XML export file into your blog. Pick a Blogware file to upload and click Import.').'</p>';
17420 wp_import_upload_form("admin.php?import=blogware&step=1");
17421 echo '</div>';
17422 }
17423
17424 function import_posts() {
17425 global $wpdb, $current_user;
17426
17427 set_magic_quotes_runtime(0);
17428 $importdata = file($this->file); // Read the file into an array
17429 $importdata = implode('', $importdata); // squish it
17430 $importdata = str_replace(array ("\r\n", "\r"), "\n", $importdata);
17431
17432 preg_match_all('|(<item[^>]+>(.*?)</item>)|is', $importdata, $posts);
17433 $posts = $posts[1];
17434 unset($importdata);
17435 echo '<ol>';
17436 foreach ($posts as $post) {
17437 flush();
17438 preg_match('|<item type=\"(.*?)\">|is', $post, $post_type);
17439 $post_type = $post_type[1];
17440 if($post_type == "photo") {
17441 preg_match('|<photoFilename>(.*?)</photoFilename>|is', $post, $post_title);
17442 } else {
17443 preg_match('|<title>(.*?)</title>|is', $post, $post_title);
17444 }
17445 $post_title = $wpdb->escape(trim($post_title[1]));
17446
17447 preg_match('|<pubDate>(.*?)</pubDate>|is', $post, $post_date);
17448 $post_date = strtotime($post_date[1]);
17449 $post_date = gmdate('Y-m-d H:i:s', $post_date);
17450
17451 preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
17452 $categories = $categories[1];
17453
17454 $cat_index = 0;
17455 foreach ($categories as $category) {
17456 $categories[$cat_index] = $wpdb->escape($this->unhtmlentities($category));
17457 $cat_index++;
17458 }
17459
17460 if(strcasecmp($post_type, "photo") === 0) {
17461 preg_match('|<sizedPhotoUrl>(.*?)</sizedPhotoUrl>|is', $post, $post_content);
17462 $post_content = '<img src="'.trim($post_content[1]).'" />';
17463 $post_content = $this->unhtmlentities($post_content);
17464 } else {
17465 preg_match('|<body>(.*?)</body>|is', $post, $post_content);
17466 $post_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($post_content[1]));
17467 $post_content = $this->unhtmlentities($post_content);
17468 }
17469
17470 // Clean up content
17471 $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content);
17472 $post_content = str_replace('<br>', '<br />', $post_content);
17473 $post_content = str_replace('<hr>', '<hr />', $post_content);
17474 $post_content = $wpdb->escape($post_content);
17475
17476 $post_author = $current_user->ID;
17477 preg_match('|<postStatus>(.*?)</postStatus>|is', $post, $post_status);
17478 $post_status = trim($post_status[1]);
17479
17480 echo '<li>';
17481 if ($post_id = post_exists($post_title, $post_content, $post_date)) {
17482 printf(__('Post <em>%s</em> already exists.'), stripslashes($post_title));
17483 } else {
17484 printf(__('Importing post <em>%s</em>...'), stripslashes($post_title));
17485 $postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
17486 $post_id = wp_insert_post($postdata);
17487 if ( is_wp_error( $post_id ) ) {
17488 return $post_id;
17489 }
17490 if (!$post_id) {
17491 _e("Couldn't get post ID");
17492 echo '</li>';
17493 break;
17494 }
17495 if(0 != count($categories))
17496 wp_create_categories($categories, $post_id);
17497 }
17498
17499 preg_match_all('|<comment>(.*?)</comment>|is', $post, $comments);
17500 $comments = $comments[1];
17501
17502 if ( $comments ) {
17503 $comment_post_ID = (int) $post_id;
17504 $num_comments = 0;
17505 foreach ($comments as $comment) {
17506 preg_match('|<body>(.*?)</body>|is', $comment, $comment_content);
17507 $comment_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($comment_content[1]));
17508 $comment_content = $this->unhtmlentities($comment_content);
17509
17510 // Clean up content
17511 $comment_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $comment_content);
17512 $comment_content = str_replace('<br>', '<br />', $comment_content);
17513 $comment_content = str_replace('<hr>', '<hr />', $comment_content);
17514 $comment_content = $wpdb->escape($comment_content);
17515
17516 preg_match('|<pubDate>(.*?)</pubDate>|is', $comment, $comment_date);
17517 $comment_date = trim($comment_date[1]);
17518 $comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
17519
17520 preg_match('|<author>(.*?)</author>|is', $comment, $comment_author);
17521 $comment_author = $wpdb->escape(trim($comment_author[1]));
17522
17523 $comment_author_email = NULL;
17524
17525 $comment_approved = 1;
17526 // Check if it's already there
17527 if (!comment_exists($comment_author, $comment_date)) {
17528 $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_date', 'comment_content', 'comment_approved');
17529 $commentdata = wp_filter_comment($commentdata);
17530 wp_insert_comment($commentdata);
17531 $num_comments++;
17532 }
17533 }
17534 }
17535 if ( $num_comments ) {
17536 echo ' ';
17537 printf( __ngettext('%s comment', '%s comments', $num_comments), $num_comments );
17538 }
17539 echo '</li>';
17540 flush();
17541 ob_flush();
17542 }
17543 echo '</ol>';
17544 }
17545
17546 function import() {
17547 $file = wp_import_handle_upload();
17548 if ( isset($file['error']) ) {
17549 echo $file['error'];
17550 return;
17551 }
17552
17553 $this->file = $file['file'];
17554 $result = $this->import_posts();
17555 if ( is_wp_error( $result ) )
17556 return $result;
17557 wp_import_cleanup($file['id']);
17558 do_action('import_done', 'blogware');
17559 echo '<h3>';
17560 printf(__('All done. <a href="%s">Have fun!</a>'), get_option('home'));
17561 echo '</h3>';
17562 }
17563
17564 function dispatch() {
17565 if (empty ($_GET['step']))
17566 $step = 0;
17567 else
17568 $step = (int) $_GET['step'];
17569
17570 $this->header();
17571
17572 switch ($step) {
17573 case 0 :
17574 $this->greet();
17575 break;
17576 case 1 :
17577 $result = $this->import();
17578 if ( is_wp_error( $result ) )
17579 $result->get_error_message();
17580 break;
17581 }
17582
17583 $this->footer();
17584 }
17585
17586 function BW_Import() {
17587 // Nothing.
17588 }
17589 }
17590
17591 $blogware_import = new BW_Import();
17592
17593 register_importer('blogware', __('Blogware'), __('Import posts from Blogware.'), array ($blogware_import, 'dispatch'));
17594 ?>