- 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.dc1.php
r1622 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( … … 37 37 'cat_ids' => array() 38 38 ); 39 39 40 40 protected function setInfo() 41 41 { … … 44 44 $this->description = __('Import a Dotclear 1.2 installation into your current blog.'); 45 45 } 46 46 47 47 public function init() 48 48 { … … 50 50 $this->prefix = $this->core->prefix; 51 51 $this->blog_id = $this->core->blog->id; 52 52 53 53 if (!isset($_SESSION['dc1_import_vars'])) { 54 54 $_SESSION['dc1_import_vars'] = $this->base_vars; 55 55 } 56 56 $this->vars =& $_SESSION['dc1_import_vars']; 57 57 58 58 if ($this->vars['post_limit'] > 0) { 59 59 $this->post_limit = $this->vars['post_limit']; 60 60 } 61 61 } 62 62 63 63 public function resetVars() 64 64 { … … 66 66 unset($_SESSION['dc1_import_vars']); 67 67 } 68 68 69 69 public function process($do) 70 70 { 71 71 $this->action = $do; 72 72 } 73 73 74 74 # We handle process in another way to always display something to 75 75 # user … … 130 130 } 131 131 } 132 132 133 133 public function gui() 134 134 { … … 138 138 $this->error($e); 139 139 } 140 140 141 141 switch ($this->step) 142 142 { … … 147 147 '<p class="warning">'.__('Please note that this process '. 148 148 'will empty your categories, blogroll, entries and comments on the current blog.').'</p>'; 149 149 150 150 printf($this->imForm(1,__('General information'),__('Import my blog now')), 151 151 '<p>'.__('We first need some information about your old Dotclear 1.2 installation.').'</p>'. … … 189 189 break; 190 190 case 6: 191 echo 191 echo 192 192 '<h3 class="vertical-separator">'.__('Please read carefully').'</h3>'. 193 193 '<ul>'. … … 195 195 'and will need to ask for a new one by following the "I forgot my password" link on the login page '. 196 196 '(Their registered email address has to be valid.)').'</li>'. 197 197 198 198 '<li>'.sprintf(__('Please note that Dotclear 2 has a new URL layout. You can avoid broken '. 199 199 'links by installing <a href="%s">DC1 redirect</a> plugin and activate it in your blog configuration.'), 200 200 'http://plugins.dotaddict.org/dc2/details/dc1redirect').'</li>'. 201 201 '</ul>'. 202 202 203 203 $this->congratMessage(); 204 205 break; 206 } 207 } 208 204 205 break; 206 } 207 } 208 209 209 # Simple form for step by step process 210 210 protected function imForm($step,$legend,$submit_value=null) … … 213 213 $submit_value = __('next step').' >'; 214 214 } 215 215 216 216 return 217 217 '<form action="'.$this->getURL(true).'" method="post">'. … … 224 224 '</form>'; 225 225 } 226 226 227 227 # Error display 228 228 protected function error($e) … … 231 231 '<p>'.$e->getMessage().'</p></div>'; 232 232 } 233 233 234 234 # Database init 235 235 protected function db() 236 236 { 237 237 $db = dbLayer::init('mysql',$this->vars['db_host'],$this->vars['db_name'],$this->vars['db_user'],$this->vars['db_pwd']); 238 238 239 239 $rs = $db->select("SHOW TABLES LIKE '".$this->vars['db_prefix']."%'"); 240 240 if ($rs->isEmpty()) { 241 241 throw new Exception(__('Dotclear tables not found')); 242 242 } 243 243 244 244 while ($rs->fetch()) { 245 245 $this->has_table[$rs->f(0)] = true; 246 246 } 247 247 248 248 # Set this to read data as they were written in Dotclear 1 249 249 try { 250 250 $db->execute('SET NAMES DEFAULT'); 251 251 } catch (Exception $e) {} 252 252 253 253 $db->execute('SET CHARACTER SET DEFAULT'); 254 254 $db->execute("SET COLLATION_CONNECTION = DEFAULT"); … … 256 256 $db->execute("SET CHARACTER_SET_SERVER = DEFAULT"); 257 257 $db->execute("SET CHARACTER_SET_DATABASE = DEFAULT"); 258 258 259 259 $this->post_count = $db->select( 260 260 'SELECT COUNT(post_id) FROM '.$this->vars['db_prefix'].'post ' 261 261 )->f(0); 262 262 263 263 return $db; 264 264 } 265 265 266 266 protected function cleanStr($str) 267 267 { 268 268 return text::cleanUTF8(@text::toUTF8($str)); 269 269 } 270 270 271 271 # Users import 272 272 protected function importUsers() … … 275 275 $prefix = $this->vars['db_prefix']; 276 276 $rs = $db->select('SELECT * FROM '.$prefix.'user'); 277 277 278 278 try 279 279 { 280 280 $this->con->begin(); 281 281 282 282 while ($rs->fetch()) 283 283 { … … 298 298 'post_format' => $rs->user_post_format 299 299 )); 300 300 301 301 $permissions = array(); 302 302 switch ($rs->user_level) … … 317 317 break; 318 318 } 319 319 320 320 $this->core->addUser($cur); 321 321 $this->core->setUserBlogPermissions( … … 326 326 } 327 327 } 328 328 329 329 $this->con->commit(); 330 330 $db->close(); … … 337 337 } 338 338 } 339 339 340 340 # Categories import 341 341 protected function importCategories() … … 344 344 $prefix = $this->vars['db_prefix']; 345 345 $rs = $db->select('SELECT * FROM '.$prefix.'categorie ORDER BY cat_ord ASC'); 346 346 347 347 try 348 348 { … … 351 351 "WHERE blog_id = '".$this->con->escape($this->blog_id)."' " 352 352 ); 353 353 354 354 $ord = 2; 355 355 while ($rs->fetch()) … … 362 362 $cur->cat_lft = $ord++; 363 363 $cur->cat_rgt = $ord++; 364 364 365 365 $cur->cat_id = $this->con->select( 366 366 'SELECT MAX(cat_id) FROM '.$this->prefix.'category' … … 369 369 $cur->insert(); 370 370 } 371 371 372 372 $db->close(); 373 373 } … … 378 378 } 379 379 } 380 380 381 381 # Blogroll import 382 382 protected function importLinks() … … 385 385 $prefix = $this->vars['db_prefix']; 386 386 $rs = $db->select('SELECT * FROM '.$prefix.'link ORDER BY link_id ASC'); 387 387 388 388 try 389 389 { … … 392 392 "WHERE blog_id = '".$this->con->escape($this->blog_id)."' " 393 393 ); 394 394 395 395 while ($rs->fetch()) 396 396 { … … 403 403 $cur->link_xfn = $this->cleanStr($rs->rel); 404 404 $cur->link_position = (integer) $rs->position; 405 405 406 406 $cur->link_id = $this->con->select( 407 407 'SELECT MAX(link_id) FROM '.$this->prefix.'link' … … 409 409 $cur->insert(); 410 410 } 411 411 412 412 $db->close(); 413 413 } … … 418 418 } 419 419 } 420 420 421 421 # Entries import 422 422 protected function importPosts(&$percent) … … 424 424 $db = $this->db(); 425 425 $prefix = $this->vars['db_prefix']; 426 426 427 427 $count = $db->select('SELECT COUNT(post_id) FROM '.$prefix.'post')->f(0); 428 428 429 429 $rs = $db->select( 430 430 'SELECT * FROM '.$prefix.'post ORDER BY post_id ASC '. 431 431 $db->limit($this->post_offset,$this->post_limit) 432 432 ); 433 433 434 434 try 435 435 { … … 441 441 ); 442 442 } 443 443 444 444 while ($rs->fetch()) { 445 445 $this->importPost($rs,$db); 446 446 } 447 447 448 448 $db->close(); 449 449 } … … 453 453 throw $e; 454 454 } 455 455 456 456 if ($rs->count() < $this->post_limit) { 457 457 return -1; … … 459 459 $this->post_offset += $this->post_limit; 460 460 } 461 461 462 462 if ($this->post_offset > $this->post_count) { 463 463 $percent = 100; … … 466 466 } 467 467 } 468 468 469 469 protected function importPost($rs,$db) 470 470 { … … 477 477 $cur->post_upddt = $rs->post_upddt; 478 478 $cur->post_title = html::decodeEntities($this->cleanStr($rs->post_titre)); 479 479 480 480 $cur->post_url = date('Y/m/d/',strtotime($cur->post_dt)).$rs->post_id.'-'.$rs->post_titre_url; 481 481 $cur->post_url = substr($cur->post_url,0,255); 482 482 483 483 $cur->post_format = $rs->post_content_wiki == '' ? 'xhtml' : 'wiki'; 484 484 $cur->post_content_xhtml = $this->cleanStr($rs->post_content); 485 485 $cur->post_excerpt_xhtml = $this->cleanStr($rs->post_chapo); 486 486 487 487 if ($cur->post_format == 'wiki') { 488 488 $cur->post_content = $this->cleanStr($rs->post_content_wiki); … … 492 492 $cur->post_excerpt = $this->cleanStr($rs->post_chapo); 493 493 } 494 494 495 495 $cur->post_notes = $this->cleanStr($rs->post_notes); 496 496 $cur->post_status = (integer) $rs->post_pub; … … 499 499 $cur->post_open_tb = (integer) $rs->post_open_tb; 500 500 $cur->post_lang = $rs->post_lang; 501 501 502 502 $cur->post_words = implode(' ',text::splitWords( 503 503 $cur->post_title.' '. … … 505 505 $cur->post_content_xhtml 506 506 )); 507 507 508 508 $cur->post_id = $this->con->select( 509 509 'SELECT MAX(post_id) FROM '.$this->prefix.'post' 510 510 )->f(0) + 1; 511 511 512 512 $cur->insert(); 513 513 $this->importComments($rs->post_id,$cur->post_id,$db); 514 514 $this->importPings($rs->post_id,$cur->post_id,$db); 515 515 516 516 # Load meta if we have some in DC1 517 517 if (isset($this->has_table[$this->vars['db_prefix'].'post_meta'])) { … … 519 519 } 520 520 } 521 521 522 522 # Comments import 523 523 protected function importComments($post_id,$new_post_id,$db) 524 524 { 525 525 $count_c = $count_t = 0; 526 526 527 527 $rs = $db->select( 528 528 'SELECT * FROM '.$this->vars['db_prefix'].'comment '. 529 529 'WHERE post_id = '.(integer) $post_id.' ' 530 530 ); 531 531 532 532 while ($rs->fetch()) 533 533 { … … 542 542 $cur->comment_ip = $rs->comment_ip; 543 543 $cur->comment_trackback = (integer) $rs->comment_trackback; 544 544 545 545 $cur->comment_site = $this->cleanStr($rs->comment_site); 546 546 if ($cur->comment_site != '' && !preg_match('!^http://.*$!',$cur->comment_site)) { 547 547 $cur->comment_site = substr('http://'.$cur->comment_site,0,255); 548 548 } 549 549 550 550 if ($rs->exists('spam') && $rs->spam && $rs->comment_status = 0) { 551 551 $cur->comment_status = -2; 552 552 } 553 553 554 554 $cur->comment_words = implode(' ',text::splitWords($cur->comment_content)); 555 555 556 556 $cur->comment_id = $this->con->select( 557 557 'SELECT MAX(comment_id) FROM '.$this->prefix.'comment' 558 558 )->f(0) + 1; 559 559 560 560 $cur->insert(); 561 561 562 562 if ($cur->comment_trackback && $cur->comment_status == 1) { 563 563 $count_t++; … … 566 566 } 567 567 } 568 568 569 569 if ($count_t > 0 || $count_c > 0) 570 570 { … … 577 577 } 578 578 } 579 579 580 580 # Pings import 581 581 protected function importPings($post_id,$new_post_id,$db) 582 582 { 583 583 $urls = array(); 584 584 585 585 $rs = $db->select( 586 586 'SELECT * FROM '.$this->vars['db_prefix'].'ping '. 587 587 'WHERE post_id = '.(integer) $post_id 588 588 ); 589 589 590 590 while ($rs->fetch()) 591 591 { … … 594 594 continue; 595 595 } 596 596 597 597 $cur = $this->con->openCursor($this->prefix.'ping'); 598 598 $cur->post_id = (integer) $new_post_id; … … 600 600 $cur->ping_dt = $rs->ping_dt; 601 601 $cur->insert(); 602 602 603 603 $urls[$url] = true; 604 604 } 605 605 } 606 606 607 607 # Meta import 608 608 protected function importMeta($post_id,$new_post_id,$db) … … 612 612 'WHERE post_id = '.(integer) $post_id.' ' 613 613 ); 614 614 615 615 if ($rs->isEmpty()) { 616 616 return; 617 617 } 618 618 619 619 while ($rs->fetch()) { 620 620 $this->core->meta->setPostMeta($new_post_id,$this->cleanStr($rs->meta_key),$this->cleanStr($rs->meta_value)); … … 622 622 } 623 623 } 624 ?>
Note: See TracChangeset
for help on using the changeset viewer.