Legend:
- Unmodified
- Added
- Removed
-
plugins/importExport/inc/class.dc.import.flat.php
r1559 r2485 15 15 { 16 16 protected $status = false; 17 17 18 18 public function setInfo() 19 19 { … … 22 22 $this->description = __('Imports a blog or a full Dotclear installation from flat file.'); 23 23 } 24 24 25 25 public function process($do) 26 26 { … … 29 29 return; 30 30 } 31 31 32 32 $to_unlink = false; 33 33 34 34 # Single blog import 35 35 $files = $this->getPublicFiles(); … … 40 40 $single_upl = true; 41 41 } 42 42 43 43 if ($single_upl !== null) 44 44 { … … 53 53 $file = $_POST['public_single_file']; 54 54 } 55 55 56 56 try { 57 57 # Try to unzip file … … 64 64 $bk = new flatImport($this->core,$file); 65 65 } 66 66 67 67 $bk->importSingle(); 68 68 } catch (Exception $e) { … … 79 79 http::redirect($this->getURL().'&do=single'); 80 80 } 81 81 82 82 # Full import 83 83 $full_upl = null; … … 87 87 $full_upl = true; 88 88 } 89 89 90 90 if ($full_upl !== null && $this->core->auth->isSuperAdmin()) 91 91 { … … 93 93 throw new Exception(__('Password verification failed')); 94 94 } 95 95 96 96 if ($full_upl) { 97 97 files::uploadStatus($_FILES['up_full_file']); … … 104 104 $file = $_POST['public_full_file']; 105 105 } 106 106 107 107 try { 108 108 # Try to unzip file … … 115 115 $bk = new flatImport($this->core,$file); 116 116 } 117 117 118 118 $bk->importFull(); 119 119 } catch (Exception $e) { … … 130 130 http::redirect($this->getURL().'&do=full'); 131 131 } 132 132 133 133 header('content-type:text/plain'); 134 134 var_dump($_POST); 135 135 exit; 136 136 137 137 $this->status = true; 138 138 } 139 139 140 140 public function gui() 141 141 { … … 150 150 return; 151 151 } 152 152 153 153 $public_files = array_merge(array('-' => ''),$this->getPublicFiles()); 154 154 $has_files = (boolean) (count($public_files) - 1); 155 155 156 156 echo 157 157 '<script type="text/javascript">'."\n". … … 178 178 "//]]>\n". 179 179 "</script>\n"; 180 180 181 181 echo 182 182 '<form action="'.$this->getURL(true).'" method="post" enctype="multipart/form-data" class="fieldset">'. 183 183 '<h3>'.__('Single blog').'</h3>'. 184 184 '<p>'.sprintf(__('This will import a single blog backup as new content in the current blog: <strong>%s</strong>.'),html::escapeHTML($this->core->blog->name)).'</p>'. 185 185 186 186 '<p><label for="up_single_file">'.__('Upload a backup file'). 187 187 ' ('.sprintf(__('maximum size %s'),files::size(DC_MAX_UPLOAD_SIZE)).')'.' </label>'. 188 188 ' <input type="file" id="up_single_file" name="up_single_file" size="20" />'. 189 189 '</p>'; 190 190 191 191 if ($has_files) { 192 echo 192 echo 193 193 '<p><label for="public_single_file" class="">'.__('or pick up a local file in your public directory').' </label> '. 194 194 form::combo('public_single_file',$public_files). 195 195 '</p>'; 196 196 } 197 198 echo 197 198 echo 199 199 '<p>'. 200 200 $this->core->formNonce(). … … 202 202 form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE). 203 203 '<input type="submit" value="'.__('Import').'" /></p>'. 204 204 205 205 '</form>'; 206 206 207 207 if ($this->core->auth->isSuperAdmin()) 208 208 { … … 211 211 '<h3>'.__('Multiple blogs').'</h3>'. 212 212 '<p class="warning">'.__('This will reset all the content of your database, except users.').'</p>'. 213 213 214 214 '<p><label for="up_full_file">'.__('Upload a backup file').' '. 215 215 ' ('.sprintf(__('maximum size %s'),files::size(DC_MAX_UPLOAD_SIZE)).')'.' </label>'. 216 216 '<input type="file" id="up_full_file" name="up_full_file" size="20" />'. 217 217 '</p>'; 218 218 219 219 if ($has_files) { 220 echo 220 echo 221 221 '<p><label for="public_full_file">'.__('or pick up a local file in your public directory').' </label>'. 222 222 form::combo('public_full_file',$public_files). 223 223 '</p>'; 224 224 } 225 225 226 226 echo 227 227 '<p><label for="your_pwd" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label>'. 228 228 form::password('your_pwd',20,255).'</p>'. 229 229 230 230 '<p>'. 231 231 $this->core->formNonce(). … … 233 233 form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE). 234 234 '<input type="submit" value="'.__('Import').'" /></p>'. 235 235 236 236 '</form>'; 237 237 } 238 238 } 239 239 240 240 protected function getPublicFiles() 241 241 { … … 246 246 while (($entry = $dir->read()) !== false) { 247 247 $entry_path = $dir->path.'/'.$entry; 248 248 249 249 if (is_file($entry_path) && is_readable($entry_path)) 250 250 { … … 261 261 return $public_files; 262 262 } 263 263 264 264 protected static function checkFileContent($entry_path) 265 265 { 266 266 $ret = false; 267 267 268 268 $fp = fopen($entry_path,'rb'); 269 269 $ret = strpos(fgets($fp),'///DOTCLEAR|') === 0; 270 270 fclose($fp); 271 271 272 272 return $ret; 273 273 } 274 274 275 275 private function unzip($file) 276 276 { 277 277 $zip = new fileUnzip($file); 278 278 279 279 if ($zip->isEmpty()) { 280 280 $zip->close(); 281 281 return false;//throw new Exception(__('File is empty or not a compressed file.')); 282 282 } 283 283 284 284 foreach($zip->getFilesList() as $zip_file) 285 285 { … … 288 288 continue; 289 289 } 290 290 291 291 # Check zipped file contents 292 292 $content = $zip->unzip($zip_file); … … 295 295 continue; 296 296 } 297 297 298 298 $target = path::fullFromRoot($zip_file,dirname($file)); 299 299 300 300 # Check existing files with same name 301 301 if (file_exists($target)) { … … 304 304 throw new Exception(__('Another file with same name exists.')); 305 305 } 306 306 307 307 # Extract backup content 308 308 if (file_put_contents($target,$content) === false) { … … 311 311 throw new Exception(__('Failed to extract backup file.')); 312 312 } 313 313 314 314 $zip->close(); 315 315 unset($content); 316 316 317 317 # Return extracted file name 318 318 return $target; 319 319 } 320 320 321 321 $zip->close(); 322 322 throw new Exception(__('No backup in compressed file.')); 323 323 } 324 324 } 325 ?>
Note: See TracChangeset
for help on using the changeset viewer.