[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
| 6 | # Copyright (c) 2003-2010 Olivier Meunier & Association Dotclear |
---|
| 7 | # Licensed under the GPL version 2.0 license. |
---|
| 8 | # See LICENSE file or |
---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 10 | # |
---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
| 12 | if (!defined('DC_RC_PATH')) { return; } |
---|
| 13 | |
---|
| 14 | class dcExportFlat extends dcIeModule |
---|
| 15 | { |
---|
| 16 | public function setInfo() |
---|
| 17 | { |
---|
| 18 | $this->type = 'e'; |
---|
| 19 | $this->name = __('Flat file export'); |
---|
| 20 | $this->description = __('Exports a blog or a full Dotclear installation to flat file.'); |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | public function process($do) |
---|
| 24 | { |
---|
| 25 | # Export a blog |
---|
| 26 | if ($do == 'export_blog' && $this->core->auth->check('admin',$this->core->blog->id)) |
---|
| 27 | { |
---|
| 28 | $fullname = $this->core->blog->public_path.'/.backup_'.sha1(uniqid()); |
---|
| 29 | $blog_id = $this->core->con->escape($this->core->blog->id); |
---|
| 30 | |
---|
| 31 | try |
---|
| 32 | { |
---|
| 33 | $exp = new dbExport($this->core->con,$fullname,$this->core->prefix); |
---|
| 34 | fwrite($exp->fp,'///DOTCLEAR|'.DC_VERSION."|single\n"); |
---|
| 35 | |
---|
| 36 | $exp->export('category', |
---|
| 37 | 'SELECT * FROM '.$this->core->prefix.'category '. |
---|
| 38 | "WHERE blog_id = '".$blog_id."'" |
---|
| 39 | ); |
---|
| 40 | $exp->export('link', |
---|
| 41 | 'SELECT * FROM '.$this->core->prefix.'link '. |
---|
| 42 | "WHERE blog_id = '".$blog_id."'" |
---|
| 43 | ); |
---|
| 44 | $exp->export('setting', |
---|
| 45 | 'SELECT * FROM '.$this->core->prefix.'setting '. |
---|
| 46 | "WHERE blog_id = '".$blog_id."'" |
---|
| 47 | ); |
---|
| 48 | $exp->export('post', |
---|
| 49 | 'SELECT * FROM '.$this->core->prefix.'post '. |
---|
| 50 | "WHERE blog_id = '".$blog_id."'" |
---|
| 51 | ); |
---|
| 52 | $exp->export('meta', |
---|
| 53 | 'SELECT meta_id, meta_type, M.post_id '. |
---|
| 54 | 'FROM '.$this->core->prefix.'meta M, '.$this->core->prefix.'post P '. |
---|
| 55 | 'WHERE P.post_id = M.post_id '. |
---|
| 56 | "AND P.blog_id = '".$blog_id."'" |
---|
| 57 | ); |
---|
| 58 | $exp->export('media', |
---|
| 59 | 'SELECT * FROM '.$this->core->prefix."media WHERE media_path = '". |
---|
| 60 | $this->core->con->escape($this->core->blog->settings->system->public_path)."'" |
---|
| 61 | ); |
---|
| 62 | $exp->export('post_media', |
---|
| 63 | 'SELECT media_id, M.post_id '. |
---|
| 64 | 'FROM '.$this->core->prefix.'post_media M, '.$this->core->prefix.'post P '. |
---|
| 65 | 'WHERE P.post_id = M.post_id '. |
---|
| 66 | "AND P.blog_id = '".$blog_id."'" |
---|
| 67 | ); |
---|
| 68 | $exp->export('ping', |
---|
| 69 | 'SELECT ping.post_id, ping_url, ping_dt '. |
---|
| 70 | 'FROM '.$this->core->prefix.'ping ping, '.$this->core->prefix.'post P '. |
---|
| 71 | 'WHERE P.post_id = ping.post_id '. |
---|
| 72 | "AND P.blog_id = '".$blog_id."'" |
---|
| 73 | ); |
---|
| 74 | $exp->export('comment', |
---|
| 75 | 'SELECT C.* '. |
---|
| 76 | 'FROM '.$this->core->prefix.'comment C, '.$this->core->prefix.'post P '. |
---|
| 77 | 'WHERE P.post_id = C.post_id '. |
---|
| 78 | "AND P.blog_id = '".$blog_id."'" |
---|
| 79 | ); |
---|
| 80 | |
---|
| 81 | # --BEHAVIOR-- exportSingle |
---|
| 82 | $this->core->callBehavior('exportSingle',$this->core,$exp,$blog_id); |
---|
| 83 | |
---|
| 84 | $_SESSION['export_file'] = $fullname; |
---|
| 85 | $_SESSION['export_filename'] = $_POST['file_name']; |
---|
| 86 | http::redirect($this->getURL().'&do=ok'); |
---|
| 87 | } |
---|
| 88 | catch (Exception $e) |
---|
| 89 | { |
---|
| 90 | @unlink($fullname); |
---|
| 91 | throw $e; |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | # Export all content |
---|
| 96 | if ($do == 'export_all' && $this->core->auth->isSuperAdmin()) |
---|
| 97 | { |
---|
| 98 | $fullname = $this->core->blog->public_path.'/.backup_'.sha1(uniqid()); |
---|
| 99 | try |
---|
| 100 | { |
---|
| 101 | $exp = new dbExport($this->core->con,$fullname,$this->core->prefix); |
---|
| 102 | fwrite($exp->fp,'///DOTCLEAR|'.DC_VERSION."|full\n"); |
---|
| 103 | $exp->exportTable('blog'); |
---|
| 104 | $exp->exportTable('category'); |
---|
| 105 | $exp->exportTable('link'); |
---|
| 106 | $exp->exportTable('setting'); |
---|
| 107 | $exp->exportTable('user'); |
---|
| 108 | $exp->exportTable('permissions'); |
---|
| 109 | $exp->exportTable('post'); |
---|
| 110 | $exp->exportTable('meta'); |
---|
| 111 | $exp->exportTable('media'); |
---|
| 112 | $exp->exportTable('post_media'); |
---|
| 113 | $exp->exportTable('log'); |
---|
| 114 | $exp->exportTable('ping'); |
---|
| 115 | $exp->exportTable('comment'); |
---|
| 116 | $exp->exportTable('spamrule'); |
---|
| 117 | $exp->exportTable('version'); |
---|
| 118 | |
---|
| 119 | # --BEHAVIOR-- exportFull |
---|
| 120 | $this->core->callBehavior('exportFull',$this->core,$exp); |
---|
| 121 | |
---|
| 122 | $_SESSION['export_file'] = $fullname; |
---|
| 123 | $_SESSION['export_filename'] = $_POST['file_name']; |
---|
| 124 | http::redirect($this->getURL().'&do=ok'); |
---|
| 125 | } |
---|
| 126 | catch (Exception $e) |
---|
| 127 | { |
---|
| 128 | @unlink($fullname); |
---|
| 129 | throw $e; |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | # Send file content |
---|
| 134 | if ($do == 'ok') |
---|
| 135 | { |
---|
| 136 | if (!file_exists($_SESSION['export_file'])) { |
---|
| 137 | throw new Exception(__('Export file not found.')); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | ob_end_clean(); |
---|
| 141 | header('Content-Disposition: attachment;filename='.$_SESSION['export_filename']); |
---|
| 142 | header('Content-Type: text/plain; charset=UTF-8'); |
---|
| 143 | readfile($_SESSION['export_file']); |
---|
| 144 | unlink($_SESSION['export_file']); |
---|
| 145 | unset($_SESSION['export_file']); |
---|
| 146 | unset($_SESSION['export_filename']); |
---|
| 147 | exit; |
---|
| 148 | } |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | public function gui() |
---|
| 152 | { |
---|
| 153 | echo |
---|
| 154 | '<form action="'.$this->getURL(true).'" method="post">'. |
---|
| 155 | '<fieldset><legend>'.__('Export a blog').'</legend>'. |
---|
| 156 | '<p>'.sprintf(__('This will create an export of your current blog: %s'), |
---|
| 157 | '<strong>'.html::escapeHTML($this->core->blog->name).'</strong>').'</p>'. |
---|
| 158 | '<p><label class="classic">'.__('File name:').' '. |
---|
| 159 | form::field(array('file_name'),25,255,date('Y-m-d-').html::escapeHTML($this->core->blog->id.'-backup.txt')). |
---|
| 160 | '</label> '. |
---|
| 161 | '<input type="submit" value="'.__('Export').'" /></p>'. |
---|
| 162 | form::hidden(array('do'),'export_blog'). |
---|
| 163 | $this->core->formNonce().'</p>'. |
---|
| 164 | '<p class="zip-dl"><a href="media.php?d=&zipdl=1">'. |
---|
| 165 | __('You may also want to download your media directory as a zip file').'</a></p>'. |
---|
| 166 | '</fieldset></form>'; |
---|
| 167 | |
---|
| 168 | if ($this->core->auth->isSuperAdmin()) |
---|
| 169 | { |
---|
| 170 | echo |
---|
| 171 | '<form action="'.$this->getURL(true).'" method="post">'. |
---|
| 172 | '<fieldset><legend>'.__('Export all content').'</legend>'. |
---|
| 173 | '<p><label class="classic">'.__('File name:').' '. |
---|
| 174 | form::field(array('file_name'),25,255,date('Y-m-d-').'dotclear-backup.txt'). |
---|
| 175 | '</label> '. |
---|
| 176 | '<input type="submit" value="'.__('Export all content').'" />'. |
---|
| 177 | form::hidden(array('do'),'export_all'). |
---|
| 178 | $this->core->formNonce().'</p>'. |
---|
| 179 | '</fieldset></form>'; |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | } |
---|
| 183 | ?> |
---|