- Timestamp:
- 11/17/13 20:25:53 (12 years ago)
- Branch:
- 2.6
- Children:
- 2567:6c11245cbf04, 2568:61c67a7d17fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/importExport/inc/class.dc.import.wp.php
r1719 r2566 17 17 protected $prefix; 18 18 protected $blog_id; 19 19 20 20 protected $action = null; 21 21 protected $step = 1; 22 22 23 23 protected $post_offset = 0; 24 24 protected $post_limit = 20; 25 25 protected $post_count = 0; 26 26 27 27 protected $has_table = array(); 28 28 29 29 protected $vars; 30 30 protected $base_vars = array( … … 45 45 'permalink_template' => 'p=%post_id%', 46 46 'permalink_tags' => array( 47 '%year%', 48 '%monthnum%', 49 '%day%', 50 '%hour%', 51 '%minute%', 52 '%second%', 53 '%postname%', 54 '%post_id%', 55 '%category%', 47 '%year%', 48 '%monthnum%', 49 '%day%', 50 '%hour%', 51 '%minute%', 52 '%second%', 53 '%postname%', 54 '%post_id%', 55 '%category%', 56 56 '%author%' 57 57 ) 58 58 ); 59 59 protected $formaters; 60 60 61 61 protected function setInfo() 62 62 { … … 65 65 $this->description = __('Import a WordPress installation into your current blog.'); 66 66 } 67 67 68 68 public function init() 69 69 { … … 71 71 $this->prefix = $this->core->prefix; 72 72 $this->blog_id = $this->core->blog->id; 73 73 74 74 if (!isset($_SESSION['wp_import_vars'])) { 75 75 $_SESSION['wp_import_vars'] = $this->base_vars; 76 76 } 77 77 $this->vars =& $_SESSION['wp_import_vars']; 78 78 79 79 if ($this->vars['post_limit'] > 0) { 80 80 $this->post_limit = $this->vars['post_limit']; … … 83 83 $this->formaters = dcAdminCombos::getFormatersCombo(); 84 84 } 85 85 86 86 public function resetVars() 87 87 { … … 89 89 unset($_SESSION['wp_import_vars']); 90 90 } 91 91 92 92 public function process($do) 93 93 { 94 94 $this->action = $do; 95 95 } 96 96 97 97 # We handle process in another way to always display something to 98 98 # user … … 159 159 } 160 160 } 161 161 162 162 public function gui() 163 163 { … … 167 167 $this->error($e); 168 168 } 169 169 170 170 switch ($this->step) 171 171 { … … 176 176 '<p class="warning">'.__('Please note that this process '. 177 177 'will empty your categories, blogroll, entries and comments on the current blog.').'</p>'; 178 178 179 179 printf($this->imForm(1,__('General information'),__('Import my blog now')), 180 180 '<p>'.__('We first need some information about your old WordPress installation.').'</p>'. … … 218 218 form::field('post_limit',3,3,html::escapeHTML($this->vars['post_limit'])).'</p>'. 219 219 '</div>'. 220 220 221 221 '</div>'. 222 222 … … 253 253 break; 254 254 case 6: 255 echo 255 echo 256 256 '<p class="message">'.__('Every newly imported user has received a random password '. 257 257 'and will need to ask for a new one by following the "I forgot my password" link on the login page '. … … 261 261 } 262 262 } 263 263 264 264 # Simple form for step by step process 265 265 protected function imForm($step,$legend,$submit_value=null) … … 268 268 $submit_value = __('next step').' >'; 269 269 } 270 270 271 271 return 272 272 '<form action="'.$this->getURL(true).'" method="post">'. … … 279 279 '</form>'; 280 280 } 281 281 282 282 # Error display 283 283 protected function error($e) … … 286 286 '<p>'.$e->getMessage().'</p></div>'; 287 287 } 288 288 289 289 # Database init 290 290 protected function db() 291 291 { 292 292 $db = dbLayer::init('mysql',$this->vars['db_host'],$this->vars['db_name'],$this->vars['db_user'],$this->vars['db_pwd']); 293 293 294 294 $rs = $db->select("SHOW TABLES LIKE '".$this->vars['db_prefix']."%'"); 295 295 if ($rs->isEmpty()) { 296 296 throw new Exception(__('WordPress tables not found')); 297 297 } 298 298 299 299 while ($rs->fetch()) { 300 300 $this->has_table[$rs->f(0)] = true; 301 301 } 302 302 303 303 # Set this to read data as they were written 304 304 try { 305 305 $db->execute('SET NAMES DEFAULT'); 306 306 } catch (Exception $e) {} 307 307 308 308 $db->execute('SET CHARACTER SET DEFAULT'); 309 309 $db->execute("SET COLLATION_CONNECTION = DEFAULT"); … … 311 311 $db->execute("SET CHARACTER_SET_SERVER = DEFAULT"); 312 312 $db->execute("SET CHARACTER_SET_DATABASE = DEFAULT"); 313 313 314 314 $this->post_count = $db->select( 315 315 'SELECT COUNT(ID) FROM '.$this->vars['db_prefix'].'posts '. 316 316 'WHERE post_type = \'post\' OR post_type = \'page\'' 317 317 )->f(0); 318 318 319 319 return $db; 320 320 } 321 321 322 322 protected function cleanStr($str) 323 323 { 324 324 return text::cleanUTF8(@text::toUTF8($str)); 325 325 } 326 326 327 327 # Users import 328 328 protected function importUsers() … … 331 331 $prefix = $this->vars['db_prefix']; 332 332 $rs = $db->select('SELECT * FROM '.$prefix.'users'); 333 333 334 334 try 335 335 { 336 336 $this->con->begin(); 337 337 338 338 while ($rs->fetch()) 339 339 { … … 352 352 $cur->user_tz = $this->core->blog->settings->system->blog_timezone; 353 353 $permissions = array(); 354 354 355 355 $rs_meta = $db->select('SELECT * FROM '.$prefix.'usermeta WHERE user_id = '.$rs->ID); 356 356 while ($rs_meta->fetch()) … … 425 425 } 426 426 } 427 427 428 428 # Categories import 429 429 protected function importCategories() … … 438 438 'ORDER BY t.term_id ASC' 439 439 ); 440 440 441 441 try 442 442 { … … 445 445 "WHERE blog_id = '".$this->con->escape($this->blog_id)."' " 446 446 ); 447 447 448 448 $ord = 2; 449 449 while ($rs->fetch()) … … 456 456 $cur->cat_lft = $ord++; 457 457 $cur->cat_rgt = $ord++; 458 458 459 459 $cur->cat_id = $this->con->select( 460 460 'SELECT MAX(cat_id) FROM '.$this->prefix.'category' … … 463 463 $cur->insert(); 464 464 } 465 465 466 466 $db->close(); 467 467 } … … 472 472 } 473 473 } 474 474 475 475 # Blogroll import 476 476 protected function importLinks() … … 479 479 $prefix = $this->vars['db_prefix']; 480 480 $rs = $db->select('SELECT * FROM '.$prefix.'links ORDER BY link_id ASC'); 481 481 482 482 try 483 483 { … … 486 486 "WHERE blog_id = '".$this->con->escape($this->blog_id)."' " 487 487 ); 488 488 489 489 while ($rs->fetch()) 490 490 { … … 495 495 $cur->link_desc = $this->cleanStr($rs->link_description); 496 496 $cur->link_xfn = $this->cleanStr($rs->link_rel); 497 497 498 498 $cur->link_id = $this->con->select( 499 499 'SELECT MAX(link_id) FROM '.$this->prefix.'link' … … 501 501 $cur->insert(); 502 502 } 503 503 504 504 $db->close(); 505 505 } … … 510 510 } 511 511 } 512 512 513 513 # Entries import 514 514 protected function importPosts(&$percent) … … 516 516 $db = $this->db(); 517 517 $prefix = $this->vars['db_prefix']; 518 518 519 519 $plink = $db->select( 520 520 'SELECT option_value FROM '.$prefix.'options '. … … 524 524 $this->vars['permalink_template'] = substr($plink,1); 525 525 } 526 526 527 527 $rs = $db->select( 528 528 'SELECT * FROM '.$prefix.'posts '. … … 531 531 $db->limit($this->post_offset,$this->post_limit) 532 532 ); 533 533 534 534 try 535 535 { … … 540 540 "WHERE blog_id = '".$this->con->escape($this->blog_id)."' " 541 541 ); 542 } 543 542 } 543 544 544 while ($rs->fetch()) { 545 545 $this->importPost($rs,$db); 546 546 } 547 547 548 548 $db->close(); 549 549 } … … 553 553 throw $e; 554 554 } 555 555 556 556 if ($rs->count() < $this->post_limit) { 557 557 return -1; … … 559 559 $this->post_offset += $this->post_limit; 560 560 } 561 561 562 562 if ($this->post_offset > $this->post_count) { 563 563 $percent = 100; … … 566 566 } 567 567 } 568 568 569 569 protected function importPost($rs,$db) 570 570 { … … 575 575 $user_id = $this->vars['user_ids'][$rs->post_author]; 576 576 } 577 577 578 578 $cur = $this->con->openCursor($this->prefix.'post'); 579 579 $cur->blog_id = $this->blog_id; … … 583 583 $cur->post_upddt = $rs->post_modified; 584 584 $cur->post_title = $this->cleanStr($rs->post_title); 585 585 586 586 if (!$cur->post_title) { 587 587 $cur->post_title = 'No title'; 588 588 } 589 589 590 590 if ($this->vars['cat_import'] || $this->vars['cat_as_tags']) 591 591 { … … 601 601 ' ORDER BY t.term_id ASC ' 602 602 ); 603 if (!$old_cat_ids->isEmpty() && $this->vars['cat_import']) 603 if (!$old_cat_ids->isEmpty() && $this->vars['cat_import']) 604 604 { 605 605 $cur->cat_id = $this->vars['cat_ids'][(integer) $old_cat_ids->term_id]; 606 606 } 607 607 } 608 608 609 609 $permalink_infos = array( 610 date('Y',strtotime($cur->post_dt)), 611 date('m',strtotime($cur->post_dt)), 612 date('d',strtotime($cur->post_dt)), 613 date('H',strtotime($cur->post_dt)), 614 date('i',strtotime($cur->post_dt)), 615 date('s',strtotime($cur->post_dt)), 616 $rs->post_name, 617 $rs->ID, 618 $cur->cat_id, 610 date('Y',strtotime($cur->post_dt)), 611 date('m',strtotime($cur->post_dt)), 612 date('d',strtotime($cur->post_dt)), 613 date('H',strtotime($cur->post_dt)), 614 date('i',strtotime($cur->post_dt)), 615 date('s',strtotime($cur->post_dt)), 616 $rs->post_name, 617 $rs->ID, 618 $cur->cat_id, 619 619 $cur->user_id 620 620 ); … … 625 625 ); 626 626 $cur->post_url = substr($cur->post_url,0,255); 627 627 628 628 if (!$cur->post_url) { 629 629 $cur->post_url = $rs->ID; 630 630 } 631 631 632 632 $cur->post_format = $this->vars['post_formater']; 633 633 $_post_content = explode('<!--more-->',$rs->post_content,2); … … 639 639 $cur->post_content = $this->cleanStr(array_shift($_post_content)); 640 640 } 641 641 642 642 $cur->post_content_xhtml = $this->core->callFormater($this->vars['post_formater'],$cur->post_content); 643 643 $cur->post_excerpt_xhtml = $this->core->callFormater($this->vars['post_formater'],$cur->post_excerpt); 644 644 645 645 switch ($rs->post_status) 646 646 { … … 661 661 $cur->post_open_comment = $rs->comment_status == 'open' ? 1 : 0; 662 662 $cur->post_open_tb = $rs->ping_status == 'open' ? 1 : 0; 663 663 664 664 $cur->post_words = implode(' ',text::splitWords( 665 665 $cur->post_title.' '. … … 667 667 $cur->post_content_xhtml 668 668 )); 669 669 670 670 $cur->post_id = $this->con->select( 671 671 'SELECT MAX(post_id) FROM '.$this->prefix.'post' 672 672 )->f(0) + 1; 673 673 674 674 $cur->post_url = $this->core->blog->getPostURL($cur->post_url,$cur->post_dt,$cur->post_title,$cur->post_id); 675 675 676 676 $cur->insert(); 677 677 $this->importComments($rs->ID,$cur->post_id,$db); 678 678 $this->importPings($rs->ID,$cur->post_id,$db); 679 679 680 680 # Create tags 681 681 $this->importTags($rs->ID,$cur->post_id,$db); 682 682 683 683 if (isset($old_cat_ids)) 684 684 { 685 if (!$old_cat_ids->isEmpty() && $this->vars['cat_as_tags']) 685 if (!$old_cat_ids->isEmpty() && $this->vars['cat_as_tags']) 686 686 { 687 687 $old_cat_ids->moveStart(); … … 692 692 } 693 693 } 694 694 695 695 # Comments import 696 696 protected function importComments($post_id,$new_post_id,$db) 697 697 { 698 698 $count_c = $count_t = 0; 699 699 700 700 $rs = $db->select( 701 701 'SELECT * FROM '.$this->vars['db_prefix'].'comments '. 702 702 'WHERE comment_post_ID = '.(integer) $post_id.' ' 703 703 ); 704 704 705 705 while ($rs->fetch()) 706 706 { … … 716 716 $cur->comment_site = substr($this->cleanStr($rs->comment_author_url),0,255); 717 717 if ($cur->comment_site == '') $cur->comment_site = NULL; 718 718 719 719 if ($rs->comment_approved == 'spam') { 720 720 $cur->comment_status = -2; 721 721 } 722 722 723 723 $cur->comment_words = implode(' ',text::splitWords($cur->comment_content)); 724 724 725 725 $cur->comment_id = $this->con->select( 726 726 'SELECT MAX(comment_id) FROM '.$this->prefix.'comment' 727 727 )->f(0) + 1; 728 728 729 729 $cur->insert(); 730 730 731 731 if ($cur->comment_trackback && $cur->comment_status == 1) { 732 732 $count_t++; … … 735 735 } 736 736 } 737 737 738 738 if ($count_t > 0 || $count_c > 0) 739 739 { … … 746 746 } 747 747 } 748 748 749 749 # Pings import 750 750 protected function importPings($post_id,$new_post_id,$db) … … 752 752 $urls = array(); 753 753 $pings = array(); 754 754 755 755 $rs = $db->select( 756 756 'SELECT pinged FROM '.$this->vars['db_prefix'].'posts '. … … 759 759 $pings = explode ("\n",$rs->pinged); 760 760 unset ($pings[0]); 761 761 762 762 foreach($pings as $ping_url) 763 763 { … … 766 766 continue; 767 767 } 768 768 769 769 $cur = $this->con->openCursor($this->prefix.'ping'); 770 770 $cur->post_id = (integer) $new_post_id; 771 771 $cur->ping_url = $url; 772 772 $cur->insert(); 773 773 774 774 $urls[$url] = true; 775 775 } 776 776 } 777 777 778 778 # Meta import 779 779 protected function importTags($post_id,$new_post_id,$db) … … 789 789 ' ORDER BY t.term_id ASC' 790 790 ); 791 791 792 792 if ($rs->isEmpty()) { 793 793 return; 794 794 } 795 795 796 796 while ($rs->fetch()) { 797 797 $this->core->meta->setPostMeta($new_post_id,'tag',$this->cleanStr($rs->name)); … … 799 799 } 800 800 } 801 ?>
Note: See TracChangeset
for help on using the changeset viewer.