type = 'e'; $this->name = __('Flat file export'); $this->description = __('Exports a blog or a full Dotclear installation to flat file.'); } public function process($do) { # Export a blog if ($do == 'export_blog' && $this->core->auth->check('admin',$this->core->blog->id)) { $fullname = $this->core->blog->public_path.'/.backup_'.sha1(uniqid()); $blog_id = $this->core->con->escape($this->core->blog->id); try { $exp = new dbExport($this->core->con,$fullname,$this->core->prefix); fwrite($exp->fp,'///DOTCLEAR|'.DC_VERSION."|single\n"); $exp->export('category', 'SELECT * FROM '.$this->core->prefix.'category '. "WHERE blog_id = '".$blog_id."'" ); $exp->export('link', 'SELECT * FROM '.$this->core->prefix.'link '. "WHERE blog_id = '".$blog_id."'" ); $exp->export('setting', 'SELECT * FROM '.$this->core->prefix.'setting '. "WHERE blog_id = '".$blog_id."'" ); $exp->export('post', 'SELECT * FROM '.$this->core->prefix.'post '. "WHERE blog_id = '".$blog_id."'" ); $exp->export('meta', 'SELECT meta_id, meta_type, M.post_id '. 'FROM '.$this->core->prefix.'meta M, '.$this->core->prefix.'post P '. 'WHERE P.post_id = M.post_id '. "AND P.blog_id = '".$blog_id."'" ); $exp->export('media', 'SELECT * FROM '.$this->core->prefix."media WHERE media_path = '". $this->core->con->escape($this->core->blog->settings->system->public_path)."'" ); $exp->export('post_media', 'SELECT media_id, M.post_id '. 'FROM '.$this->core->prefix.'post_media M, '.$this->core->prefix.'post P '. 'WHERE P.post_id = M.post_id '. "AND P.blog_id = '".$blog_id."'" ); $exp->export('ping', 'SELECT ping.post_id, ping_url, ping_dt '. 'FROM '.$this->core->prefix.'ping ping, '.$this->core->prefix.'post P '. 'WHERE P.post_id = ping.post_id '. "AND P.blog_id = '".$blog_id."'" ); $exp->export('comment', 'SELECT C.* '. 'FROM '.$this->core->prefix.'comment C, '.$this->core->prefix.'post P '. 'WHERE P.post_id = C.post_id '. "AND P.blog_id = '".$blog_id."'" ); # --BEHAVIOR-- exportSingle $this->core->callBehavior('exportSingle',$this->core,$exp,$blog_id); $_SESSION['export_file'] = $fullname; $_SESSION['export_filename'] = $_POST['file_name']; http::redirect($this->getURL().'&do=ok'); } catch (Exception $e) { @unlink($fullname); throw $e; } } # Export all content if ($do == 'export_all' && $this->core->auth->isSuperAdmin()) { $fullname = $this->core->blog->public_path.'/.backup_'.sha1(uniqid()); try { $exp = new dbExport($this->core->con,$fullname,$this->core->prefix); fwrite($exp->fp,'///DOTCLEAR|'.DC_VERSION."|full\n"); $exp->exportTable('blog'); $exp->exportTable('category'); $exp->exportTable('link'); $exp->exportTable('setting'); $exp->exportTable('user'); $exp->exportTable('permissions'); $exp->exportTable('post'); $exp->exportTable('meta'); $exp->exportTable('media'); $exp->exportTable('post_media'); $exp->exportTable('log'); $exp->exportTable('ping'); $exp->exportTable('comment'); $exp->exportTable('spamrule'); $exp->exportTable('version'); # --BEHAVIOR-- exportFull $this->core->callBehavior('exportFull',$this->core,$exp); $_SESSION['export_file'] = $fullname; $_SESSION['export_filename'] = $_POST['file_name']; http::redirect($this->getURL().'&do=ok'); } catch (Exception $e) { @unlink($fullname); throw $e; } } # Send file content if ($do == 'ok') { if (!file_exists($_SESSION['export_file'])) { throw new Exception(__('Export file not found.')); } ob_end_clean(); header('Content-Disposition: attachment;filename='.$_SESSION['export_filename']); header('Content-Type: text/plain; charset=UTF-8'); readfile($_SESSION['export_file']); unlink($_SESSION['export_file']); unset($_SESSION['export_file']); unset($_SESSION['export_filename']); exit; } } public function gui() { echo '
'; if ($this->core->auth->isSuperAdmin()) { echo ''; } } } ?>