'',
'db_name' => '',
'db_user' => '',
'db_pwd' => '',
'db_prefix' => 'dc_',
'post_limit' => 20,
'cat_ids' => array()
);
protected function setInfo()
{
$this->type = 'i';
$this->name = __('Dotclear 1.2 import');
$this->description = __('Import a Dotclear 1.2 installation into your current blog.');
}
public function init()
{
$this->con =& $this->core->con;
$this->prefix = $this->core->prefix;
$this->blog_id = $this->core->blog->id;
if (!isset($_SESSION['dc1_import_vars'])) {
$_SESSION['dc1_import_vars'] = $this->base_vars;
}
$this->vars =& $_SESSION['dc1_import_vars'];
if ($this->vars['post_limit'] > 0) {
$this->post_limit = $this->vars['post_limit'];
}
}
public function resetVars()
{
$this->vars = $this->base_vars;;
unset($_SESSION['dc1_import_vars']);
}
public function process($do)
{
$this->action = $do;
}
# We handle process in another way to always display something to
# user
protected function guiprocess($do)
{
switch ($do)
{
case 'step1':
$this->vars['db_host'] = $_POST['db_host'];
$this->vars['db_name'] = $_POST['db_name'];
$this->vars['db_user'] = $_POST['db_user'];
$this->vars['db_pwd'] = $_POST['db_pwd'];
$this->vars['post_limit'] = abs((integer) $_POST['post_limit']) > 0 ? $_POST['post_limit'] : 0;
$this->vars['db_prefix'] = $_POST['db_prefix'];
$db = $this->db();
$db->close();
$this->step = 2;
echo $this->progressBar(1);
break;
case 'step2':
$this->step = 2;
$this->importUsers();
$this->step = 3;
echo $this->progressBar(3);
break;
case 'step3':
$this->step = 3;
$this->importCategories();
if ($this->core->plugins->moduleExists('blogroll')) {
$this->step = 4;
echo $this->progressBar(5);
} else {
$this->step = 5;
echo $this->progressBar(7);
}
break;
case 'step4':
$this->step = 4;
$this->importLinks();
$this->step = 5;
echo $this->progressBar(7);
break;
case 'step5':
$this->step = 5;
$this->post_offset = !empty($_REQUEST['offset']) ? abs((integer) $_REQUEST['offset']) : 0;
if ($this->importPosts($percent) === -1) {
http::redirect($this->getURL().'&do=ok');
} else {
echo $this->progressBar(ceil($percent*0.93)+7);
}
break;
case 'ok':
$this->resetVars();
$this->core->blog->triggerBlog();
$this->step = 6;
echo $this->progressBar(100);
break;
}
}
public function gui()
{
try {
$this->guiprocess($this->action);
} catch (Exception $e) {
$this->error($e);
}
switch ($this->step)
{
case 1:
echo
'
'.sprintf(__('This will import your Dotclear 1.2 content as new content in the current blog: %s.'),
''.html::escapeHTML($this->core->blog->name).'').'
'.
'
'.__('Please note that this process '.
'will empty your categories, blogroll, entries and comments on the current blog.').'
'.
'
'.__('Depending on the size of your blog, it could take a few minutes.').'
';
printf($this->imForm(1,__('General information'),__('Import my blog now')),
'
'.__('We first need some information about your old Dotclear 1.2 installation.').'
'.
''.
''.
''.
''.
''.
'
'.__('Entries import options').'
'.
''
);
break;
case 2:
printf($this->imForm(2,__('Importing users')),
$this->autoSubmit()
);
break;
case 3:
printf($this->imForm(3,__('Importing categories')),
$this->autoSubmit()
);
break;
case 4:
printf($this->imForm(4,__('Importing blogroll')),
$this->autoSubmit()
);
break;
case 5:
$t = sprintf(__('Importing entries from %d to %d / %d'),$this->post_offset,
min(array($this->post_offset+$this->post_limit,$this->post_count)),$this->post_count);
printf($this->imForm(5,$t),
form::hidden(array('offset'),$this->post_offset).
$this->autoSubmit()
);
break;
case 6:
echo
'
'.__('Please read carefully').'
'.
'
'.
'
'.__('Every newly imported user has received a random password '.
'and will need to ask for a new one by following the "I forgot my password" link on the login page '.
'(Their registered email address has to be valid.)').'
'.
'
'.sprintf(__('Please note that Dotclear 2 has a new URL layout. You can avoid broken '.
'links by installing DC1 redirect plugin and activate it in your blog configuration.'),
'http://plugins.dotaddict.org/dc2/details/dc1redirect').'
'.
'
'.
$this->congratMessage();
break;
}
}
# Simple form for step by step process
protected function imForm($step,$legend,$submit_value=null)
{
if (!$submit_value) {
$submit_value = __('next step').' >';
}
return
'';
}
# Error display
protected function error($e)
{
echo '