Changeset 2566:9bf417837888 for plugins/importExport/inc
- Timestamp:
- 11/17/13 20:25:53 (12 years ago)
- Branch:
- 2.6
- Children:
- 2567:6c11245cbf04, 2568:61c67a7d17fa
- Location:
- plugins/importExport/inc
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/importExport/inc/class.dc.export.flat.php
r1857 r2566 20 20 $this->description = __('Exports a blog or a full Dotclear installation to flat file.'); 21 21 } 22 22 23 23 public function process($do) 24 24 { 25 25 # Export a blog 26 26 if ($do == 'export_blog' && $this->core->auth->check('admin',$this->core->blog->id)) 27 { 27 { 28 28 $fullname = $this->core->blog->public_path.'/.backup_'.sha1(uniqid()); 29 29 $blog_id = $this->core->con->escape($this->core->blog->id); 30 30 31 31 try 32 32 { 33 33 $exp = new flatExport($this->core->con,$fullname,$this->core->prefix); 34 34 fwrite($exp->fp,'///DOTCLEAR|'.DC_VERSION."|single\n"); 35 35 36 36 $exp->export('category', 37 37 'SELECT * FROM '.$this->core->prefix.'category '. … … 78 78 "AND P.blog_id = '".$blog_id."'" 79 79 ); 80 80 81 81 # --BEHAVIOR-- exportSingle 82 82 $this->core->callBehavior('exportSingle',$this->core,$exp,$blog_id); 83 83 84 84 $_SESSION['export_file'] = $fullname; 85 85 $_SESSION['export_filename'] = $_POST['file_name']; … … 93 93 } 94 94 } 95 95 96 96 # Export all content 97 97 if ($do == 'export_all' && $this->core->auth->isSuperAdmin()) … … 118 118 $exp->exportTable('spamrule'); 119 119 $exp->exportTable('version'); 120 120 121 121 # --BEHAVIOR-- exportFull 122 122 $this->core->callBehavior('exportFull',$this->core,$exp); 123 123 124 124 $_SESSION['export_file'] = $fullname; 125 125 $_SESSION['export_filename'] = $_POST['file_name']; … … 133 133 } 134 134 } 135 135 136 136 # Send file content 137 137 if ($do == 'ok') … … 140 140 throw new Exception(__('Export file not found.')); 141 141 } 142 142 143 143 ob_end_clean(); 144 144 145 145 if (substr($_SESSION['export_filename'],-4) == '.zip') { 146 146 $_SESSION['export_filename'] = substr($_SESSION['export_filename'],0,-4);//.'.txt'; 147 147 } 148 148 149 149 # Flat export 150 150 if (empty($_SESSION['export_filezip'])) { 151 151 152 152 header('Content-Disposition: attachment;filename='.$_SESSION['export_filename']); 153 153 header('Content-Type: text/plain; charset=UTF-8'); 154 154 readfile($_SESSION['export_file']); 155 155 156 156 unlink($_SESSION['export_file']); 157 157 unset($_SESSION['export_file'],$_SESSION['export_filename'],$_SESSION['export_filezip']); … … 163 163 { 164 164 $file_zipname = $_SESSION['export_filename'].'.zip'; 165 165 166 166 $fp = fopen('php://output','wb'); 167 167 $zip = new fileZip($fp); 168 168 $zip->addFile($_SESSION['export_file'],$_SESSION['export_filename']); 169 169 170 170 header('Content-Disposition: attachment;filename='.$file_zipname); 171 171 header('Content-Type: application/x-zip'); 172 172 173 173 $zip->write(); 174 174 175 175 unlink($_SESSION['export_file']); 176 176 unset($zip,$_SESSION['export_file'],$_SESSION['export_filename'],$file_zipname); … … 181 181 unset($zip,$_SESSION['export_file'],$_SESSION['export_filename'],$file_zipname); 182 182 @unlink($_SESSION['export_file']); 183 183 184 184 throw new Exception(__('Failed to compress export file.')); 185 185 } … … 187 187 } 188 188 } 189 189 190 190 public function gui() 191 191 { … … 194 194 '<h3>'.__('Single blog').'</h3>'. 195 195 '<p>'.sprintf(__('This will create an export of your current blog: %s'),'<strong>'.html::escapeHTML($this->core->blog->name)).'</strong>.</p>'. 196 196 197 197 '<p><label for="file_name">'.__('File name:').'</label>'. 198 198 form::field(array('file_name','file_name'),50,255,date('Y-m-d-H-i-').html::escapeHTML($this->core->blog->id.'-backup.txt')). 199 199 '</p>'. 200 200 201 201 '<p><label for="file_zip" class="classic">'. 202 202 form::checkbox(array('file_zip','file_zip'),1).' '. 203 203 __('Compress file').'</label>'. 204 204 '</p>'. 205 205 206 206 '<p class="zip-dl"><a href="media.php?d=&zipdl=1">'. 207 207 __('You may also want to download your media directory as a zip file').'</a></p>'. 208 208 209 209 '<p><input type="submit" value="'.__('Export').'" />'. 210 210 form::hidden(array('do'),'export_blog'). 211 211 $this->core->formNonce().'</p>'. 212 212 213 213 '</form>'; 214 214 215 215 if ($this->core->auth->isSuperAdmin()) 216 216 { … … 219 219 '<h3>'.__('Multiple blogs').'</h3>'. 220 220 '<p>'.__('This will create an export of all the content of your database.').'</p>'. 221 221 222 222 '<p><label for="file_name2">'.__('File name:').'</label>'. 223 223 form::field(array('file_name','file_name2'),50,255,date('Y-m-d-H-i-').'dotclear-backup.txt'). 224 224 '</p>'. 225 225 226 226 '<p><label for="file_zip2" class="classic">'. 227 227 form::checkbox(array('file_zip','file_zip2'),1).' '. 228 228 __('Compress file').'</label>'. 229 229 '</p>'. 230 230 231 231 '<p><input type="submit" value="'.__('Export').'" />'. 232 232 form::hidden(array('do'),'export_all'). 233 233 $this->core->formNonce().'</p>'. 234 234 235 235 '</form>'; 236 236 } 237 237 } 238 238 } 239 ?> -
plugins/importExport/inc/class.dc.ieModule.php
r1553 r2566 18 18 public $name; 19 19 public $description; 20 20 21 21 protected $import_url; 22 22 protected $export_url; 23 23 protected $core; 24 24 25 25 public function __construct($core) 26 26 { 27 27 $this->core =& $core; 28 28 $this->setInfo(); 29 29 30 30 if (!in_array($this->type,array('import','export'))) { 31 31 throw new Exception(sprintf('Unknow type for module %s',get_class($this))); 32 32 } 33 33 34 34 if (!$this->name) { 35 35 $this->name = get_class($this); 36 36 } 37 37 38 38 $this->id = get_class($this); 39 39 $this->url = sprintf('plugin.php?p=importExport&type=%s&module=%s',$this->type,$this->id); 40 40 } 41 41 42 42 public function init() 43 43 { 44 44 } 45 45 46 46 abstract protected function setInfo(); 47 47 48 48 final public function getURL($escape=false) 49 49 { 50 50 return $escape ? html::escapeHTML($this->url) : $this->url; 51 51 } 52 52 53 53 abstract public function process($do); 54 54 55 55 abstract public function gui(); 56 56 57 57 protected function progressBar($percent) 58 58 { … … 63 63 return '<div class="ie-progress"><div style="width:'.$percent.'%">'.$percent.' %</div></div>'; 64 64 } 65 65 66 66 protected function autoSubmit() 67 67 { 68 68 return form::hidden(array('autosubmit'),1); 69 69 } 70 70 71 71 protected function congratMessage() 72 72 { … … 78 78 } 79 79 } 80 ?> -
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 ?> -
plugins/importExport/inc/class.dc.import.feed.php
r1559 r2566 16 16 protected $status = false; 17 17 protected $feed_url = ''; 18 18 19 19 public function setInfo() 20 20 { … … 23 23 $this->description = __('Add a feed content to the blog.'); 24 24 } 25 25 26 26 public function process($do) 27 27 { … … 30 30 return; 31 31 } 32 32 33 33 if (empty($_POST['feed_url'])) { 34 34 return; 35 35 } 36 36 37 37 $this->feed_url = $_POST['feed_url']; 38 38 39 39 $feed = feedReader::quickParse($this->feed_url); 40 40 if ($feed === false) { … … 44 44 throw new Exception(__('No items in feed.')); 45 45 } 46 46 47 47 $cur = $this->core->con->openCursor($this->core->prefix.'post'); 48 48 $this->core->con->begin(); … … 56 56 $cur->post_status = -2; 57 57 $cur->post_dt = strftime('%Y-%m-%d %H:%M:%S',$item->TS); 58 58 59 59 try { 60 60 $post_id = $this->core->blog->addPost($cur); … … 63 63 throw $e; 64 64 } 65 65 66 66 foreach ($item->subject as $subject) { 67 67 $this->core->meta->setPostMeta($post_id,'tag',dcMeta::sanitizeMetaID($subject)); 68 68 } 69 69 } 70 70 71 71 $this->core->con->commit(); 72 72 http::redirect($this->getURL().'&do=ok'); 73 73 74 74 } 75 75 76 76 public function gui() 77 77 { … … 79 79 dcPage::success(__('Content successfully imported.')); 80 80 } 81 81 82 82 echo 83 83 '<form action="'.$this->getURL(true).'" method="post">'. 84 84 '<p>'.sprintf(__('Add a feed content to the current blog: <strong>%s</strong>.'),html::escapeHTML($this->core->blog->name)).'</p>'. 85 85 86 86 '<p><label for="feed_url">'.__('Feed URL:').'</label>'. 87 87 form::field('feed_url',50,300,html::escapeHTML($this->feed_url)).'</p>'. 88 88 89 89 '<p>'. 90 90 $this->core->formNonce(). 91 91 form::hidden(array('do'),1). 92 92 '<input type="submit" value="'.__('Import').'" /></p>'. 93 93 94 94 '</form>'; 95 95 } 96 96 } 97 ?> -
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 ?> -
plugins/importExport/inc/flat/class.flat.backup.php
r894 r2566 18 18 private $line_name; 19 19 private $line_num; 20 20 21 21 private $replacement = array( 22 22 '/(?<!\\\\)(?>(\\\\\\\\)*+)(\\\\n)/u' => "\$1\n", … … 25 25 '/(\\\\\\\\)/' => '\\' 26 26 ); 27 27 28 28 public function __construct($file) 29 29 { … … 35 35 } 36 36 } 37 37 38 38 public function __destruct() 39 39 { … … 42 42 } 43 43 } 44 44 45 45 public function getLine() 46 46 { … … 48 48 return false; 49 49 } 50 50 51 51 if (substr($line,0,1) == '[') 52 52 { 53 53 $this->line_name = substr($line,1,strpos($line,' ')-1); 54 54 55 55 $line = substr($line,strpos($line,' ')+1,-1); 56 56 $this->line_cols = explode(',',$line); 57 57 58 58 return $this->getLine(); 59 59 } … … 62 62 $line = preg_replace('/^"|"$/','',$line); 63 63 $line = preg_split('/(^"|","|(?<!\\\)\"$)/m',$line); 64 64 65 65 if (count($this->line_cols) != count($line)) { 66 66 throw new Exception(sprintf('Invalid row count at line %s',$this->line_num)); 67 67 } 68 68 69 69 $res = array(); 70 70 71 71 for ($i=0; $i<count($line); $i++) { 72 72 $res[$this->line_cols[$i]] = 73 73 preg_replace(array_keys($this->replacement),array_values($this->replacement),$line[$i]); 74 74 } 75 75 76 76 return new flatBackupItem($this->line_name,$res,$this->line_num); 77 77 } … … 81 81 } 82 82 } 83 83 84 84 private function nextLine() 85 85 { … … 88 88 } 89 89 $this->line_num++; 90 90 91 91 $line = fgets($this->fp); 92 92 $line = trim($line); 93 93 94 94 return empty($line) ? $this->nextLine() : $line; 95 95 } … … 101 101 public $__line; 102 102 private $__data = array(); 103 103 104 104 public function __construct($name,$data,$line) 105 105 { … … 108 108 $this->__line = $line; 109 109 } 110 110 111 111 public function f($name) 112 112 { 113 113 return iconv('UTF-8','UTF-8//IGNORE',$this->__data[$name]); 114 114 } 115 115 116 116 public function __get($name) 117 117 { 118 118 return $this->f($name); 119 119 } 120 120 121 121 public function __set($n,$v) 122 122 { 123 123 $this->__data[$n] = $v; 124 124 } 125 125 126 126 public function exists($n) 127 127 { 128 128 return isset($this->__data[$n]); 129 129 } 130 130 131 131 public function drop() 132 132 { … … 137 137 } 138 138 } 139 139 140 140 public function substitute($old,$new) 141 141 { … … 146 146 } 147 147 } 148 ?> -
plugins/importExport/inc/flat/class.flat.export.php
r840 r2566 16 16 private $con; 17 17 private $prefix; 18 18 19 19 private $line_reg = array('/\\\\/u', '/\n/u','/\r/u','/"/u'); 20 20 private $line_rep = array('\\\\\\\\', '\n' ,'\r' ,'\"'); 21 21 22 22 public $fp; 23 23 24 24 function __construct($con,$out='php://output',$prefix=null) 25 25 { 26 26 $this->con =& $con; 27 27 $this->prefix = $prefix; 28 28 29 29 if (($this->fp = fopen($out,'w')) === false) { 30 30 return false; … … 32 32 @set_time_limit(300); 33 33 } 34 34 35 35 function __destruct() 36 36 { … … 39 39 } 40 40 } 41 41 42 42 function export($name,$sql) 43 43 { 44 44 $rs = $this->con->select($sql); 45 45 46 46 if (!$rs->isEmpty()) 47 47 { … … 53 53 } 54 54 } 55 55 56 56 function exportAll() 57 57 { 58 58 $tables = $this->getTables(); 59 59 60 60 foreach ($tables as $table) 61 61 { … … 63 63 } 64 64 } 65 65 66 66 function exportTable($table) 67 67 { 68 68 $req = 'SELECT * FROM '.$this->con->escapeSystem($this->prefix.$table); 69 69 70 70 $this->export($table,$req); 71 71 } 72 72 73 73 function getTables() 74 74 { 75 75 $schema = dbSchema::init($this->con); 76 76 $db_tables = $schema->getTables(); 77 77 78 78 $tables = array(); 79 79 foreach ($db_tables as $t) … … 87 87 } 88 88 } 89 89 90 90 return $tables; 91 91 } 92 92 93 93 function getLine($rs) 94 94 { … … 104 104 } 105 105 } 106 ?> -
plugins/importExport/inc/lib.ie.maintenance.php
r1989 r2566 58 58 } 59 59 else { 60 return 60 return 61 61 '<p><label for="file_name">'.__('File name:').'</label>'. 62 62 form::field('file_name', 50, 255, date('Y-m-d-H-i-').$this->export_name). … … 115 115 } 116 116 else { 117 return 117 return 118 118 '<p><label for="file_name">'.__('File name:').'</label>'. 119 119 form::field('file_name', 50, 255, date('Y-m-d-H-i-').$this->export_name).
Note: See TracChangeset
for help on using the changeset viewer.