[ Index ] |
|
Code source de Dotclear 2.0-beta6 |
1 <?php 2 # ***** BEGIN LICENSE BLOCK ***** 3 # This file is part of DotClear. 4 # Copyright (c) 2005 Olivier Meunier and contributors. All rights 5 # reserved. 6 # 7 # DotClear is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # DotClear is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with DotClear; if not, write to the Free Software 19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 # 21 # ***** END LICENSE BLOCK ***** 22 if (!defined('DC_CONTEXT_ADMIN')) { exit; } 23 24 require dirname(__FILE__).'/class.backupFile.php'; 25 require dirname(__FILE__).'/class.dc.import.php'; 26 require dirname(__FILE__).'/class.db.export.php'; 27 28 # Export all content 29 if (!empty($_POST['export_all']) && $core->auth->isSuperAdmin()) 30 { 31 ob_end_clean(); 32 header('Content-Disposition: attachment;filename=blog-backup.txt'); 33 header('Content-Type: text/plain; charset=UTF-8'); 34 35 $exp = new dbExport($core->con,'php://output',$core->prefix); 36 37 fwrite($exp->fp,'///DOTCLEAR|'.DC_VERSION."|full\n"); 38 $exp->exportTable('blog'); 39 $exp->exportTable('category'); 40 $exp->exportTable('link'); 41 $exp->exportTable('setting'); 42 $exp->exportTable('user'); 43 $exp->exportTable('permissions'); 44 $exp->exportTable('post'); 45 $exp->exportTable('media'); 46 $exp->exportTable('post_media'); 47 $exp->exportTable('log'); 48 $exp->exportTable('ping'); 49 $exp->exportTable('comment'); 50 $exp->exportTable('spamrule'); 51 $exp->exportTable('version'); 52 53 # --BEHAVIOR-- exportFull 54 $core->callBehavior('exportFull',$core,$exp); 55 56 exit; 57 } 58 59 # Export a blog 60 if (!empty($_POST['blog_export']) && $core->auth->check('admin',$_POST['blog_export'])) 61 { 62 ob_end_clean(); 63 64 $blog_id = $_POST['blog_export']; 65 66 if (!in_array($blog_id,array_keys($core->blogs))) { 67 exit; 68 } 69 70 $core->setBlog($blog_id); 71 $blog_id = $core->con->escape($blog_id); 72 73 header('Content-Disposition: attachment;filename='.$core->blog->id.'-backup.txt'); 74 header('Content-Type: text/plain; charset=UTF-8'); 75 76 $exp = new dbExport($core->con,'php://output',$core->prefix); 77 fwrite($exp->fp,'///DOTCLEAR|'.DC_VERSION."|single\n"); 78 79 $exp->export('category', 80 'SELECT * FROM '.$core->prefix.'category '. 81 "WHERE blog_id = '".$blog_id."'" 82 ); 83 $exp->export('link', 84 'SELECT * FROM '.$core->prefix.'link '. 85 "WHERE blog_id = '".$blog_id."'" 86 ); 87 $exp->export('setting', 88 'SELECT * FROM '.$core->prefix.'setting '. 89 "WHERE blog_id = '".$blog_id."'" 90 ); 91 $exp->export('post', 92 'SELECT * FROM '.$core->prefix.'post '. 93 "WHERE blog_id = '".$blog_id."'" 94 ); 95 $exp->export('media', 96 'SELECT * FROM '.$core->prefix."media WHERE media_path = '". 97 $core->con->escape($core->blog->settings->public_path)."'" 98 ); 99 $exp->export('post_media', 100 'SELECT media_id, M.post_id '. 101 'FROM '.$core->prefix.'post_media M, '.$core->prefix.'post P '. 102 'WHERE P.post_id = M.post_id '. 103 "AND P.blog_id = '".$blog_id."'" 104 ); 105 $exp->export('ping', 106 'SELECT ping.post_id, ping_url, ping_dt '. 107 'FROM '.$core->prefix.'ping ping, '.$core->prefix.'post P '. 108 'WHERE P.post_id = ping.post_id '. 109 "AND P.blog_id = '".$blog_id."'" 110 ); 111 $exp->export('comment', 112 'SELECT C.* '. 113 'FROM '.$core->prefix.'comment C, '.$core->prefix.'post P '. 114 'WHERE P.post_id = C.post_id '. 115 "AND P.blog_id = '".$blog_id."'" 116 ); 117 118 # --BEHAVIOR-- exportSingle 119 $core->callBehavior('exportSingle',$core,$exp,$blog_id); 120 exit; 121 } 122 123 # Getting files in public directory 124 $public_files = array('-' => ''); 125 $dir = @dir($core->blog->public_path); 126 if ($dir) 127 { 128 while (($entry = $dir->read()) !== false) { 129 $entry_path = $dir->path.'/'.$entry; 130 131 if (is_file($entry_path) && is_readable($entry_path)) 132 { 133 $fp = fopen($entry_path,'rb'); 134 if (strpos(fgets($fp),'///DOTCLEAR|') === 0) { 135 $public_files[$entry] = $entry_path; 136 } 137 fclose($fp); 138 } 139 } 140 } 141 142 143 # Loading a single blog 144 $single_upl = null; 145 146 if (!empty($_POST['public_single_file']) && in_array($_POST['public_single_file'],$public_files)) { 147 $single_upl = false; 148 } 149 elseif(!empty($_FILES['up_single_file'])) { 150 $single_upl = true; 151 } 152 153 if ($single_upl !== null) 154 { 155 try 156 { 157 if ($single_upl) { 158 files::uploadStatus($_FILES['up_single_file']); 159 $file = $_FILES['up_single_file']['tmp_name']; 160 } else { 161 $file = $_POST['public_single_file']; 162 } 163 164 $bk = new dcImport($core,$file); 165 $bk->importSingle(); 166 http::redirect($p_url.'&imported=1'); 167 } 168 catch (Exception $e) 169 { 170 $core->error->add($e->getMessage()); 171 } 172 } 173 174 175 # Loading a full export file 176 $full_upl = null; 177 178 if (!empty($_POST['public_full_file']) && in_array($_POST['public_full_file'],$public_files)) { 179 $full_upl = false; 180 } 181 elseif(!empty($_FILES['up_full_file'])) { 182 $full_upl = true; 183 } 184 185 if ($full_upl !== null && $core->auth->isSuperAdmin()) 186 { 187 try 188 { 189 if ($full_upl) { 190 files::uploadStatus($_FILES['up_full_file']); 191 $file = $_FILES['up_full_file']['tmp_name']; 192 } else { 193 $file = $_POST['public_full_file']; 194 } 195 196 $bk = new dcImport($core,$file); 197 $bk->importFull(); 198 http::redirect($p_url.'&imported=1'); 199 } 200 catch (Exception $e) 201 { 202 $core->error->add($e->getMessage()); 203 } 204 } 205 206 # Loading a feed 207 $feed_url = !empty($_POST['feed_url']) ? $_POST['feed_url'] : ''; 208 209 if ($feed_url) 210 { 211 try 212 { 213 $feed = feedReader::quickParse($feed_url); 214 if ($feed === false) { 215 throw new Exception(__('Cannot retrieve feed URL.')); 216 } 217 if (count($feed->items) == 0) { 218 throw new Exception(__('No items in feed.')); 219 } 220 221 if ($core->plugins->moduleExists('metadata')) { 222 $meta = new dcMeta($core); 223 } 224 225 $cur = $core->con->openCursor($core->prefix.'post'); 226 $core->con->begin(); 227 foreach ($feed->items as $item) 228 { 229 $cur->clean(); 230 $cur->user_id = $core->auth->userID(); 231 $cur->post_content = $item->content ? $item->content : $item->description; 232 $cur->post_title = $item->title ? $item->title : text::cutString(html::clean($cur->post_content),60); 233 $cur->post_format = 'xhtml'; 234 $cur->post_status = -2; 235 $cur->post_dt = strftime('%Y-%m-%d %H:%M:%S',$item->TS); 236 237 try { 238 $post_id = $core->blog->addPost($cur); 239 } catch (Exception $e) { 240 $core->con->rollback(); 241 throw $e; 242 } 243 244 if (isset($meta)) 245 { 246 foreach ($item->subject as $subject) { 247 $meta->setPostMeta($post_id,'tag',dcMeta::sanitizeMetaID($subject)); 248 } 249 } 250 } 251 252 $core->con->commit(); 253 http::redirect($p_url.'&imported=1'); 254 } 255 catch (Exception $e) 256 { 257 $core->error->add($e->getMessage()); 258 } 259 } 260 261 ?> 262 <html> 263 <head> 264 <title><?php echo __('Import/Export'); ?></title> 265 <script type="text/javascript"> 266 //<![CDATA[ 267 <?php echo dcPage::jsVar('dotclear.msg.confirm_full_import', 268 __('Are you sure you want to import a full backup file?')); ?> 269 $(function() { 270 $('#up_single_file').change(function() { 271 if (this.value != '') { $('#public_single_file').val(''); } 272 }); 273 $('#public_single_file').change(function() { 274 if (this.value != '') { $('#up_single_file').val(''); } 275 }); 276 277 $('#up_full_file').change(function() { 278 if (this.value != '') { $('#public_full_file').val(''); } 279 }); 280 $('#public_full_file').change(function() { 281 if (this.value != '') { $('#up_full_file').val(''); } 282 }); 283 $('#formfull').submit(function() { 284 return window.confirm(dotclear.msg.confirm_full_import); 285 }); 286 }); 287 //]]> 288 </script> 289 <?php echo dcPage::jsPageTabs(); ?> 290 </head> 291 292 <body> 293 <?php 294 if (!empty($_GET['imported'])) { 295 echo '<p class="message">'.__('Content successfully imported.').'</p>'; 296 } 297 298 echo '<h2>'.__('Import/Export').'</h2>'; 299 300 echo '<div class="multi-part" title="'.__('Import').'">'; 301 302 echo 303 '<h3>'.__('Import a single blog').'</h3>'. 304 '<p>'.sprintf(__('This will import a single blog backup as new content in the current blog: %s.'), 305 '<strong>'.html::escapeHTML($core->blog->name).'</strong>').'</p>'. 306 '<form action="'.$p_url.'" method="post" enctype="multipart/form-data">'. 307 308 '<fieldset>'. 309 form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE). 310 '<p><label>'.__('Upload a backup file').' '. 311 '<input type="file" id="up_single_file" name="up_single_file" size="20" />'. 312 '</label></p>'. 313 314 '<p><label>'.__('or pick up a local file in your public directory').' '. 315 form::combo('public_single_file',$public_files). 316 '</label></p>'. 317 '<p><input type="submit" value="'.__('Send').'" /></p>'. 318 '</fieldset>'. 319 '</form>'; 320 321 if ($core->auth->isSuperAdmin()) 322 { 323 echo 324 '<h3>'.__('Import a full backup file').'</h3>'. 325 '<form action="'.$p_url.'" method="post" enctype="multipart/form-data" id="formfull">'. 326 '<div>'.form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE).'</div>'. 327 328 '<fieldset>'. 329 form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE). 330 '<p><label>'.__('Upload a backup file').' '. 331 '<input type="file" id="up_full_file" name="up_full_file" size="20" />'. 332 '</label></p>'. 333 334 '<p><label>'.__('or pick up a local file in your public directory').' '. 335 form::combo('public_full_file',$public_files). 336 '</label></p>'. 337 338 '<p><strong>'.__('Warning: This will reset all the content of your database, except users.').'</strong></p>'. 339 340 '<p><input type="submit" value="'.__('Send').'" /></p>'. 341 '</fieldset>'. 342 '</form>'; 343 } 344 345 echo 346 '<h3>'.__('Import from a feed').'</h3>'. 347 '<p>'.sprintf(__('This will import a feed (RSS or Atom) a as new content in the current blog: %s.'), 348 '<strong>'.html::escapeHTML($core->blog->name).'</strong>').'</p>'. 349 '<form action="'.$p_url.'" method="post">'. 350 351 '<fieldset>'. 352 '<p><label>'.__('Feed URL:').' '. 353 form::field('feed_url',40,300,html::escapeHTML($feed_url)).'</label></p>'. 354 '<p><input type="submit" value="'.__('Send').'" /></p>'. 355 '</fieldset>'. 356 '</form>'; 357 358 echo '</div>'; 359 360 echo '<div class="multi-part" title="'.__('Export').'">'; 361 362 if ($core->auth->isSuperAdmin()) 363 { 364 echo 365 '<h3>'.__('Export all content').'</h3>'. 366 '<form action="'.$p_url.'" method="post">'. 367 '<p><input name="export_all" type="submit" value="'.__('Export all content').'" /></p>'. 368 '</form>'; 369 } 370 371 echo '<h3>'.__('Export a blog').'</h3>'; 372 $blogs_list = array(); 373 foreach ($core->blogs as $k=>$v) { 374 if ($core->auth->check('admin',$k)) { 375 $blogs_list[html::escapeHTML($v['name']).' ('.$k.')'] = $k; 376 } 377 } 378 379 echo 380 '<form action="'.$p_url.'" method="post">'. 381 '<p><label class="classic">'.__('Blog to export:').' '. 382 form::combo('blog_export',$blogs_list,$core->blog->id).'</label> '. 383 '<input type="submit" value="'.__('Export').'" /></p>'. 384 '</form>'; 385 386 echo '</div>'; 387 ?> 388 </body> 389 </html>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Feb 23 22:16:06 2007 | par Balluche grâce à PHPXref 0.7 |