Dotclear

Changeset 840:f7157873644c


Ignore:
Timestamp:
07/09/12 14:44:20 (13 years ago)
Author:
JcDenis
Branch:
default
Message:

Clean up structure, added (un)zip to flat import/export, fixes #1319

Location:
plugins/importExport
Files:
4 added
9 edited
4 moved

Legend:

Unmodified
Added
Removed
  • plugins/importExport/_admin.php

    r324 r840  
    22# -- BEGIN LICENSE BLOCK --------------------------------------- 
    33# 
    4 # This file is part of Dotclear 2. 
     4# This file is part of importExport, a plugin for DotClear2. 
    55# 
    6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2012 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1212if (!defined('DC_CONTEXT_ADMIN')) { return; } 
    1313 
    14 $_menu['Plugins']->addItem(__('Import/Export'),'plugin.php?p=importExport','index.php?pf=importExport/icon.png', 
    15           preg_match('/plugin.php\?p=importExport(&.*)?$/',$_SERVER['REQUEST_URI']), 
    16           $core->auth->check('admin',$core->blog->id)); 
    17  
    18 # Files needed by flat files import / export 
    19 $__autoload['backupFile'] = dirname(__FILE__).'/inc/flat/class.backupFile.php'; 
    20 $__autoload['dcImport'] = dirname(__FILE__).'/inc/flat/class.dc.import.php'; 
    21 $__autoload['dbExport'] = dirname(__FILE__).'/inc/flat/class.db.export.php'; 
     14$_menu['Plugins']->addItem( 
     15     __('Import/Export'), 
     16     'plugin.php?p=importExport', 
     17     'index.php?pf=importExport/icon.png', 
     18     preg_match('/plugin.php\?p=importExport(&.*)?$/',$_SERVER['REQUEST_URI']), 
     19     $core->auth->check('admin',$core->blog->id) 
     20); 
    2221 
    2322$core->addBehavior('adminDashboardFavs','importExportDashboardFavs'); 
     
    2524function importExportDashboardFavs($core,$favs) 
    2625{ 
    27      $favs['importExport'] = new ArrayObject(array('importExport','Import/Export','plugin.php?p=importExport', 
    28           'index.php?pf=importExport/icon.png','index.php?pf=importExport/icon-big.png', 
    29           'admin',null,null)); 
     26     $favs['importExport'] = new ArrayObject(array( 
     27          'importExport', 
     28          __('Import/Export'), 
     29          'plugin.php?p=importExport', 
     30          'index.php?pf=importExport/icon.png', 
     31          'index.php?pf=importExport/icon-big.png', 
     32          'admin',null,null 
     33     )); 
    3034} 
    3135?> 
  • plugins/importExport/_define.php

    r464 r840  
    22# -- BEGIN LICENSE BLOCK --------------------------------------- 
    33# 
    4 # This file is part of Dotclear 2. 
     4# This file is part of importExport, a plugin for DotClear2. 
    55# 
    6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2012 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1515     /* Name */               "Import / Export", 
    1616     /* Description*/         "Import and Export your blog", 
    17      /* Author */             "Olivier Meunier", 
    18      /* Version */            '2.4', 
    19      array( 
    20           'permissions' => 'admin', 
    21           'priority' => 10 
    22      ) 
     17     /* Author */             "Olivier Meunier & Contributors", 
     18     /* Version */            '3.0', 
     19     /* Perm */               'admin' 
    2320); 
    2421?> 
  • plugins/importExport/inc/class.dc.export.flat.php

    r557 r840  
    22# -- BEGIN LICENSE BLOCK --------------------------------------- 
    33# 
    4 # This file is part of Dotclear 2. 
     4# This file is part of importExport, a plugin for DotClear2. 
    55# 
    6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2012 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1616     public function setInfo() 
    1717     { 
    18           $this->type = 'e'; 
     18          $this->type = 'export'; 
    1919          $this->name = __('Flat file export'); 
    2020          $this->description = __('Exports a blog or a full Dotclear installation to flat file.'); 
     
    3131               try 
    3232               { 
    33                     $exp = new dbExport($this->core->con,$fullname,$this->core->prefix); 
     33                    $exp = new flatExport($this->core->con,$fullname,$this->core->prefix); 
    3434                    fwrite($exp->fp,'///DOTCLEAR|'.DC_VERSION."|single\n"); 
    3535                     
     
    8484                    $_SESSION['export_file'] = $fullname; 
    8585                    $_SESSION['export_filename'] = $_POST['file_name']; 
     86                    $_SESSION['export_filezip'] = !empty($_POST['file_zip']); 
    8687                    http::redirect($this->getURL().'&do=ok'); 
    8788               } 
     
    99100               try 
    100101               { 
    101                     $exp = new dbExport($this->core->con,$fullname,$this->core->prefix); 
     102                    $exp = new flatExport($this->core->con,$fullname,$this->core->prefix); 
    102103                    fwrite($exp->fp,'///DOTCLEAR|'.DC_VERSION."|full\n"); 
    103104                    $exp->exportTable('blog'); 
     
    123124                    $_SESSION['export_file'] = $fullname; 
    124125                    $_SESSION['export_filename'] = $_POST['file_name']; 
     126                    $_SESSION['export_filezip'] = !empty($_POST['file_zip']); 
    125127                    http::redirect($this->getURL().'&do=ok'); 
    126128               } 
     
    140142                
    141143               ob_end_clean(); 
    142                header('Content-Disposition: attachment;filename='.$_SESSION['export_filename']); 
    143                header('Content-Type: text/plain; charset=UTF-8'); 
    144                readfile($_SESSION['export_file']); 
    145                unlink($_SESSION['export_file']); 
    146                unset($_SESSION['export_file']); 
    147                unset($_SESSION['export_filename']); 
    148                exit; 
     144                
     145               if (substr($_SESSION['export_filename'],-4) == '.zip') { 
     146                    $_SESSION['export_filename'] = substr($_SESSION['export_filename'],0,-4);//.'.txt'; 
     147               } 
     148                
     149               # Flat export 
     150               if (empty($_SESSION['export_filezip'])) { 
     151                
     152                    header('Content-Disposition: attachment;filename='.$_SESSION['export_filename']); 
     153                    header('Content-Type: text/plain; charset=UTF-8'); 
     154                    readfile($_SESSION['export_file']); 
     155                     
     156                    unlink($_SESSION['export_file']); 
     157                    unset($_SESSION['export_file'],$_SESSION['export_filename'],$_SESSION['export_filezip']); 
     158                    exit; 
     159               } 
     160               # Zip export 
     161               else { 
     162                    try 
     163                    { 
     164                         $file_zipname = $_SESSION['export_filename'].'.zip'; 
     165                          
     166                         $fp = fopen('php://output','wb'); 
     167                         $zip = new fileZip($fp); 
     168                         $zip->addFile($_SESSION['export_file'],$_SESSION['export_filename']); 
     169                          
     170                         header('Content-Disposition: attachment;filename='.$file_zipname); 
     171                         header('Content-Type: application/x-zip'); 
     172                          
     173                         $zip->write(); 
     174                          
     175                         unlink($_SESSION['export_file']); 
     176                         unset($zip,$_SESSION['export_file'],$_SESSION['export_filename'],$file_zipname); 
     177                         exit; 
     178                    } 
     179                    catch (Exception $e) 
     180                    { 
     181                         unset($zip,$_SESSION['export_file'],$_SESSION['export_filename'],$file_zipname); 
     182                         @unlink($_SESSION['export_file']); 
     183                          
     184                         throw new Exception(__('Failed to compress export file.')); 
     185                    } 
     186               } 
    149187          } 
    150188     } 
     
    154192          echo 
    155193          '<form action="'.$this->getURL(true).'" method="post">'. 
    156           '<fieldset><legend>'.__('Export a blog').'</legend>'. 
    157           '<p>'.sprintf(__('This will create an export of your current blog: %s'), 
    158           '<strong>'.html::escapeHTML($this->core->blog->name).'</strong>').'</p>'. 
    159           '<p><label for="file_name" class="classic">'.__('File name:').'</label>'. 
    160           form::field(array('file_name','file_name'),25,255,date('Y-m-d-').html::escapeHTML($this->core->blog->id.'-backup.txt')). 
    161           '<input type="submit" value="'.__('Export').'" />'. 
     194          '<fieldset><legend>'.__('Single blog').'</legend>'. 
     195          '<p>'.sprintf(__('This will create an export of your current blog: %s'),html::escapeHTML($this->core->blog->name)).'</p>'. 
     196           
     197          '<p><label for="file_name">'.__('File name:').'</label>'. 
     198          form::field(array('file_name','file_name'),50,255,date('Y-m-d-').html::escapeHTML($this->core->blog->id.'-backup.txt')). 
     199          '</p>'. 
     200           
     201          '<p><label for="file_zip" class="classic">'. 
     202          form::checkbox(array('file_zip','file_zip'),1).' '. 
     203          __('Compress file').'</label>'. 
     204          '</p>'. 
     205           
     206          '<p class="zip-dl"><a href="media.php?d=&amp;zipdl=1">'. 
     207          __('You may also want to download your media directory as a zip file').'</a></p>'. 
     208           
     209          '<p><input type="submit" value="'.__('Export').'" />'. 
    162210          form::hidden(array('do'),'export_blog'). 
    163211          $this->core->formNonce().'</p>'. 
    164           '<p class="zip-dl"><a href="media.php?d=&amp;zipdl=1">'. 
    165           __('You may also want to download your media directory as a zip file').'</a></p>'. 
    166           '</fieldset></form>'; 
     212           
     213          '</fieldset>'. 
     214          '</form>'; 
    167215           
    168216          if ($this->core->auth->isSuperAdmin()) 
     
    170218               echo 
    171219               '<form action="'.$this->getURL(true).'" method="post">'. 
    172                '<fieldset><legend>'.__('Export all content').'</legend>'. 
    173                '<p><label for="file_name2" class="classic">'.__('File name:').'</label>'. 
    174                form::field(array('file_name','file_name2'),25,255,date('Y-m-d-').'dotclear-backup.txt'). 
    175                '<input type="submit" value="'.__('Export all content').'" />'. 
     220               '<fieldset><legend>'.__('Multiple blogs').'</legend>'. 
     221               '<p>'.__('This will create an export of all the content of your database.').'</p>'. 
     222                
     223               '<p><label for="file_name2">'.__('File name:').'</label>'. 
     224               form::field(array('file_name','file_name2'),50,255,date('Y-m-d-').'dotclear-backup.txt'). 
     225               '</p>'. 
     226                
     227               '<p><label for="file_zip2" class="classic">'. 
     228               form::checkbox(array('file_zip','file_zip2'),1).' '. 
     229               __('Compress file').'</label>'. 
     230               '</p>'. 
     231                
     232               '<p><input type="submit" value="'.__('Export').'" />'. 
    176233               form::hidden(array('do'),'export_all'). 
    177234               $this->core->formNonce().'</p>'. 
    178                '</fieldset></form>'; 
     235                
     236               '</fieldset>'. 
     237               '</form>'; 
    179238          } 
    180239     } 
  • plugins/importExport/inc/class.dc.ieModule.php

    r270 r840  
    22# -- BEGIN LICENSE BLOCK --------------------------------------- 
    33# 
    4 # This file is part of Dotclear 2. 
     4# This file is part of importExport, a plugin for DotClear2. 
    55# 
    6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2012 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1212if (!defined('DC_RC_PATH')) { return; } 
    1313 
    14 class dcIeModule 
     14abstract class dcIeModule 
    1515{ 
    1616     public $type; 
     
    2828          $this->setInfo(); 
    2929           
    30           $this->id = get_class($this); 
    31           if (!$this->type) { 
    32                throw new Exception('No type for module'.$this->id); 
     30          if (!in_array($this->type,array('import','export'))) { 
     31               throw new Exception(sprintf('Unknow type for module %s',get_class($this))); 
    3332          } 
    34            
    35           $this->url = 'plugin.php?p=importExport&t='.$this->type.'&f='.$this->id; 
    3633           
    3734          if (!$this->name) { 
    3835               $this->name = get_class($this); 
    3936          } 
     37           
     38          $this->id = get_class($this); 
     39          $this->url = sprintf('plugin.php?p=importExport&type=%s&module=%s',$this->type,$this->id); 
    4040     } 
    4141      
     
    4444     } 
    4545      
    46      protected function setInfo() 
    47      { 
    48      } 
     46     abstract protected function setInfo(); 
    4947      
    5048     final public function getURL($escape=false) 
    5149     { 
    52           if ($escape) { 
    53                return html::escapeHTML($this->url); 
    54           } 
    55           return $this->url; 
     50          return $escape ? html::escapeHTML($this->url) : $this->url; 
    5651     } 
    5752      
    58      public function process($do) 
    59      { 
    60      } 
     53     abstract public function process($do); 
    6154      
    62      public function gui() 
    63      { 
    64      } 
     55     abstract public function gui(); 
    6556      
    6657     protected function progressBar($percent) 
  • plugins/importExport/inc/class.dc.import.dc1.php

    r270 r840  
    22# -- BEGIN LICENSE BLOCK --------------------------------------- 
    33# 
    4 # This file is part of Dotclear 2. 
     4# This file is part of importExport, a plugin for DotClear2. 
    55# 
    6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2012 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    4040     protected function setInfo() 
    4141     { 
    42           $this->type = 'i'; 
     42          $this->type = 'import'; 
    4343          $this->name = __('Dotclear 1.2 import'); 
    4444          $this->description = __('Import a Dotclear 1.2 installation into your current blog.'); 
  • plugins/importExport/inc/class.dc.import.feed.php

    r557 r840  
    22# -- BEGIN LICENSE BLOCK --------------------------------------- 
    33# 
    4 # This file is part of Dotclear 2. 
     4# This file is part of importExport, a plugin for DotClear2. 
    55# 
    6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2012 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1919     public function setInfo() 
    2020     { 
    21           $this->type = 'i'; 
     21          $this->type = 'import'; 
    2222          $this->name = __('Feed import'); 
    2323          $this->description = __('Imports a feed as new entries.'); 
     
    8181           
    8282          echo 
    83           '<h3>'.__('Import from a feed').'</h3>'. 
    84           '<p>'.sprintf(__('This will import a feed (RSS or Atom) a as new content in the current blog: %s.'), 
    85           '<strong>'.html::escapeHTML($this->core->blog->name).'</strong>').'</p>'. 
    8683          '<form action="'.$this->getURL(true).'" method="post">'. 
     84          '<fieldset><legend>'.__('Single blog').'</legend>'. 
     85          '<p>'.sprintf(__('This will import a feed (RSS or Atom) a as new content in the current blog: %s.'),html::escapeHTML($this->core->blog->name)).'</p>'. 
    8786           
    88           '<div class="fieldset">'. 
     87          '<p><label for="feed_url">'.__('Feed URL:').'</label>'. 
     88          form::field('feed_url',50,300,html::escapeHTML($this->feed_url)).'</p>'. 
     89           
     90          '<p>'. 
    8991          $this->core->formNonce(). 
    9092          form::hidden(array('do'),1). 
    91           '<p><label for="feed_url">'.__('Feed URL:').'</label>'. 
    92           form::field('feed_url',40,300,html::escapeHTML($this->feed_url)).'</p>'. 
    93           '<p><input type="submit" value="'.__('Import').'" /></p>'. 
    94           '</div>'. 
     93          '<input type="submit" value="'.__('Import').'" /></p>'. 
     94           
     95          '</fieldset>'. 
    9596          '</form>'; 
    9697     } 
  • plugins/importExport/inc/class.dc.import.flat.php

    r557 r840  
    22# -- BEGIN LICENSE BLOCK --------------------------------------- 
    33# 
    4 # This file is part of Dotclear 2. 
     4# This file is part of importExport, a plugin for DotClear2. 
    55# 
    6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2012 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1818     public function setInfo() 
    1919     { 
    20           $this->type = 'i'; 
     20          $this->type = 'import'; 
    2121          $this->name = __('Flat file import'); 
    2222          $this->description = __('Imports a blog or a full Dotclear installation from flat file.'); 
     
    5555                
    5656               try { 
    57                     $bk = new dcImport($this->core,$file); 
     57                    # Try to unzip file 
     58                    $unzip_file = $this->unzip($file); 
     59                    if (false !== $unzip_file) { 
     60                         $bk = new flatImport($this->core,$unzip_file); 
     61                    } 
     62                    # Else this is a normal file 
     63                    else { 
     64                         $bk = new flatImport($this->core,$file); 
     65                    } 
     66                     
    5867                    $bk->importSingle(); 
    5968               } catch (Exception $e) { 
     69                    @unlink($unzip_file); 
    6070                    if ($to_unlink) { 
    6171                         @unlink($file); 
     
    6373                    throw $e; 
    6474               } 
     75               @unlink($unzip_file); 
    6576               if ($to_unlink) { 
    6677                    @unlink($file); 
     
    95106                
    96107               try { 
    97                     $bk = new dcImport($this->core,$file); 
     108                    # Try to unzip file 
     109                    $unzip_file = $this->unzip($file); 
     110                    if (false !== $unzip_file) { 
     111                         $bk = new flatImport($this->core,$unzip_file); 
     112                    } 
     113                    # Else this is a normal file 
     114                    else { 
     115                         $bk = new flatImport($this->core,$file); 
     116                    } 
     117                     
    98118                    $bk->importFull(); 
    99119               } catch (Exception $e) { 
     120                    @unlink($unzip_file); 
    100121                    if ($to_unlink) { 
    101122                         @unlink($file); 
     
    103124                    throw $e; 
    104125               } 
     126               @unlink($unzip_file); 
    105127               if ($to_unlink) { 
    106128                    @unlink($file); 
     
    128150               return; 
    129151          } 
     152           
     153          $public_files = array_merge(array('-' => ''),$this->getPublicFiles()); 
     154          $has_files = (boolean) (count($public_files) - 1); 
    130155           
    131156          echo 
     
    155180           
    156181          echo 
    157           '<h3>'.__('Import a single blog').'</h3>'. 
    158           '<p>'.sprintf(__('This will import a single blog backup as new content in the current blog: %s.'), 
    159           '<strong>'.html::escapeHTML($this->core->blog->name).'</strong>').'</p>'. 
    160182          '<form action="'.$this->getURL(true).'" method="post" enctype="multipart/form-data">'. 
    161            
    162           '<div class="fieldset">'. 
     183          '<fieldset><legend>'.__('Single blog').'</legend>'. 
     184          '<p>'.sprintf(__('This will import a single blog backup as new content in the current blog: %s.'),html::escapeHTML($this->core->blog->name)).'</p>'. 
     185           
     186          '<p><label for="up_single_file">'.__('Upload a backup file').'</label>'. 
     187          '<input type="file" id="up_single_file" name="up_single_file" size="20" />'. 
     188          '</p>'; 
     189           
     190          if ($has_files) { 
     191               echo  
     192               '<p><label for="public_single_file">'.__('or pick up a local file in your public directory').' '. 
     193               form::combo('public_single_file',$public_files). 
     194               '</label></p>'; 
     195          } 
     196           
     197          echo  
     198          '<p>'. 
    163199          $this->core->formNonce(). 
    164200          form::hidden(array('do'),1). 
    165201          form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE). 
    166           '<p><label for="up_single_file">'.__('Upload a backup file').'</label>'. 
    167           '<input type="file" id="up_single_file" name="up_single_file" size="20" />'. 
    168           '</p>'; 
    169            
    170           $public_files = $this->getPublicFiles(); 
    171            
    172           $empty = empty($public_files); 
    173           $public_files = array_merge(array('-' => ''),$public_files); 
    174           echo 
    175           '<p><label for="public_single_file">'.__('or pick up a local file in your public directory').' '. 
    176           form::combo('public_single_file',$public_files, '', '', '', $empty). 
    177           '</label></p>'; 
    178            
    179           echo 
    180           '<p><input type="submit" value="'.__('Import').'" /></p>'. 
    181           '</div>'. 
     202          '<input type="submit" value="'.__('Import').'" /></p>'. 
     203           
     204          '</fieldset>'. 
    182205          '</form>'; 
    183206           
     
    185208          { 
    186209               echo 
    187                '<h3>'.__('Import a full backup file').'</h3>'. 
    188210               '<form action="'.$this->getURL(true).'" method="post" enctype="multipart/form-data" id="formfull">'. 
    189                '<div>'.form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE).'</div>'. 
    190                 
    191                '<div class="fieldset">'. 
     211               '<fieldset><legend>'.__('Multiple blogs').'</legend>'. 
     212               '<p>'.__('This will reset all the content of your database, except users.').'</p>'. 
     213                
     214               '<p><label for="up_full_file">'.__('Upload a backup file').'</label>'. 
     215               '<input type="file" id="up_full_file" name="up_full_file" size="20" />'. 
     216               '</p>'; 
     217                
     218               if ($has_files) { 
     219                    echo  
     220                    '<p><label for="public_full_file">'.__('or pick up a local file in your public directory').'</label>'. 
     221                    form::combo('public_full_file',$public_files). 
     222                    '</p>'; 
     223               } 
     224                
     225               echo 
     226               '<p><label for="your_pwd" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label>'. 
     227               form::password('your_pwd',20,255).'</p>'. 
     228                
     229               '<p>'. 
    192230               $this->core->formNonce(). 
    193231               form::hidden(array('do'),1). 
    194232               form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE). 
    195                '<p><label for="up_full_file">'.__('Upload a backup file').'</label>'. 
    196                '<input type="file" id="up_full_file" name="up_full_file" size="20" />'. 
    197                '</p>'; 
    198                 
    199                echo 
    200                '<p><label for="public_full_file">'.__('or pick up a local file in your public directory').'</label>'. 
    201                form::combo('public_full_file',$public_files, '', '', '', $empty). 
    202                '</p>'; 
    203                 
    204                echo 
    205                '<p class="form-note warning"><strong>'.__('Warning: This will reset all the content of your database, except users.').'</strong></p>'. 
    206                 
    207                '<p><label for="your_pwd" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label>'. 
    208                form::password('your_pwd',20,255).'</p>'. 
    209                 
    210                '<p><input type="submit" value="'.__('Import').'" /></p>'. 
    211                '</div>'. 
     233               '<input type="submit" value="'.__('Import').'" /></p>'. 
     234                
     235               '</fieldset>'. 
    212236               '</form>'; 
    213237          } 
     
    225249                    if (is_file($entry_path) && is_readable($entry_path)) 
    226250                    { 
    227                          $fp = fopen($entry_path,'rb'); 
    228                          if (strpos(fgets($fp),'///DOTCLEAR|') === 0) { 
     251                         # Do not test each zip file content here, its too long 
     252                         if (substr($entry_path,-4) == '.zip') { 
     253                                   $public_files[$entry] = $entry_path; 
     254                         } 
     255                         elseif (self::checkFileContent($entry_path)) { 
    229256                              $public_files[$entry] = $entry_path; 
    230257                         } 
    231                          fclose($fp); 
    232258                    } 
    233259               } 
    234260          } 
    235261          return $public_files; 
     262     } 
     263      
     264     protected static function checkFileContent($entry_path) 
     265     { 
     266          $ret = false; 
     267           
     268          $fp = fopen($entry_path,'rb'); 
     269          $ret = strpos(fgets($fp),'///DOTCLEAR|') === 0; 
     270          fclose($fp); 
     271           
     272          return $ret; 
     273     } 
     274      
     275     private function unzip($file) 
     276     { 
     277          $zip = new fileUnzip($file); 
     278           
     279          if ($zip->isEmpty()) { 
     280               $zip->close(); 
     281               return false;//throw new Exception(__('File is empty or not a compressed file.')); 
     282          } 
     283           
     284          foreach($zip->getFilesList() as $zip_file) 
     285          { 
     286               # Check zipped file name 
     287               if (substr($zip_file,-4) != '.txt') { 
     288                    continue; 
     289               } 
     290                
     291               # Check zipped file contents 
     292               $content = $zip->unzip($zip_file); 
     293               if (strpos($content,'///DOTCLEAR|') !== 0) { 
     294                    unset($content); 
     295                    continue; 
     296               } 
     297                
     298               $target = path::fullFromRoot($zip_file,dirname($file)); 
     299                
     300               # Check existing files with same name 
     301               if (file_exists($target)) { 
     302                    $zip->close(); 
     303                    unset($content); 
     304                    throw new Exception(__('Another file with same name exists.')); 
     305               } 
     306                
     307               # Extract backup content 
     308               if (file_put_contents($target,$content) === false) { 
     309                    $zip->close(); 
     310                    unset($content); 
     311                    throw new Exception(__('Failed to extract backup file.')); 
     312               } 
     313                
     314               $zip->close(); 
     315               unset($content); 
     316                
     317               # Return extracted file name 
     318               return $target; 
     319          } 
     320           
     321          $zip->close(); 
     322          throw new Exception(__('No backup in compressed file.')); 
    236323     } 
    237324} 
  • plugins/importExport/inc/class.dc.import.wp.php

    r807 r840  
    22# -- BEGIN LICENSE BLOCK --------------------------------------- 
    33# 
    4 # This file is part of Dotclear 2. 
     4# This file is part of importExport, a plugin for DotClear2. 
    55# 
    6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2012 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    6161     protected function setInfo() 
    6262     { 
    63           $this->type = 'i'; 
     63          $this->type = 'import'; 
    6464          $this->name = __('WordPress import'); 
    6565          $this->description = __('Import a WordPress installation into your current blog.'); 
  • plugins/importExport/inc/flat/class.flat.backup.php

    r270 r840  
    22# -- BEGIN LICENSE BLOCK --------------------------------------- 
    33# 
    4 # This file is part of Dotclear 2. 
     4# This file is part of importExport, a plugin for DotClear2. 
    55# 
    6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2012 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1212if (!defined('DC_RC_PATH')) { return; } 
    1313 
    14 class backupFile 
     14class flatBackup 
    1515{ 
    1616     protected $fp; 
     
    7474               } 
    7575                
    76                return new backupFileItem($this->line_name,$res); 
     76               return new flatBackupItem($this->line_name,$res); 
    7777          } 
    7878          else 
     
    8383} 
    8484 
    85 class backupFileItem 
     85class flatBackupItem 
    8686{ 
    8787     public $__name; 
  • plugins/importExport/inc/flat/class.flat.export.php

    r270 r840  
    22# -- BEGIN LICENSE BLOCK --------------------------------------- 
    33# 
    4 # This file is part of Dotclear 2. 
     4# This file is part of importExport, a plugin for DotClear2. 
    55# 
    6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2012 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1212if (!defined('DC_RC_PATH')) { return; } 
    1313 
    14 class dbExport 
     14class flatExport 
    1515{ 
    1616     private $con; 
  • plugins/importExport/inc/flat/class.flat.import.php

    r298 r840  
    22# -- BEGIN LICENSE BLOCK --------------------------------------- 
    33# 
    4 # This file is part of Dotclear 2. 
     4# This file is part of importExport, a plugin for DotClear2. 
    55# 
    6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2012 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1212if (!defined('DC_RC_PATH')) { return; } 
    1313 
    14 class dcImport extends backupFile 
     14class flatImport extends flatBackup 
    1515{ 
    1616     private $core; 
  • plugins/importExport/index.php

    r696 r840  
    22# -- BEGIN LICENSE BLOCK --------------------------------------- 
    33# 
    4 # This file is part of Dotclear 2. 
     4# This file is part of importExport, a plugin for DotClear2. 
    55# 
    6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2012 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    1212if (!defined('DC_CONTEXT_ADMIN')) { return; } 
    1313 
    14 require dirname(__FILE__).'/inc/class.dc.ieModule.php'; 
     14function listImportExportModules($core,$modules) 
     15{ 
     16     $res = ''; 
     17     foreach ($modules as $id) 
     18     { 
     19          $o = new $id($core); 
     20           
     21          $res .=  
     22          '<dt><a href="'.$o->getURL(true).'">'.html::escapeHTML($o->name).'</a></dt>'. 
     23          '<dd>'.html::escapeHTML($o->description).'</dd>'; 
     24           
     25          unset($o); 
     26     } 
     27     return '<dl class="modules">'.$res.'</dl>'; 
     28} 
    1529 
    16 $modules = new ArrayObject(); 
    17 $modules['i'] = new ArrayObject(array( 
    18      'dcImportFlat' => dirname(__FILE__).'/inc/class.dc.import.flat.php', 
    19      'dcImportFeed' => dirname(__FILE__).'/inc/class.dc.import.feed.php' 
    20 )); 
    21 $modules['e'] = new ArrayObject(array( 
    22      'dcExportFlat' => dirname(__FILE__).'/inc/class.dc.export.flat.php' 
    23 )); 
    24  
    25 if ($core->auth->isSuperAdmin()) { 
    26      $modules['i']['dcImportDC1']  = dirname(__FILE__).'/inc/class.dc.import.dc1.php'; 
    27      $modules['i']['dcImportWP']  = dirname(__FILE__).'/inc/class.dc.import.wp.php'; 
    28 } 
     30$modules = new ArrayObject(array('import' => array(),'export' => array())); 
    2931 
    3032# --BEHAVIOR-- importExportModules 
     
    3234 
    3335$type = null; 
    34 if (!empty($_REQUEST['t']) && ($_REQUEST['t'] == 'e' || $_REQUEST['t'] == 'i')) { 
    35      $type = $_REQUEST['t']; 
     36if (!empty($_REQUEST['type'])  && in_array($_REQUEST['type'],array('export','import'))) { 
     37     $type = $_REQUEST['type']; 
    3638} 
    3739 
    38 $current_module = null; 
    39 if ($type && !empty($_REQUEST['f'])) { 
    40      if (isset($modules[$type][$_REQUEST['f']])) { 
    41           require_once $modules[$type][$_REQUEST['f']]; 
    42           $current_module = new $_REQUEST['f']($core); 
    43           $current_module->init(); 
     40$module = null; 
     41if ($type && !empty($_REQUEST['module'])) { 
     42 
     43     if (isset($modules[$type]) && in_array($_REQUEST['module'],$modules[$type])) { 
     44      
     45          $module = new $_REQUEST['module']($core); 
     46          $module->init(); 
    4447     } 
    4548} 
    4649 
    47 if ($type && $current_module !== null && !empty($_REQUEST['do'])) 
     50if ($type && $module !== null && !empty($_REQUEST['do'])) 
    4851{ 
    4952     try { 
    50           $current_module->process($_REQUEST['do']); 
     53          $module->process($_REQUEST['do']); 
    5154     } catch (Exception $e) { 
    5255          $core->error->add($e->getMessage()); 
    5356     } 
    5457} 
    55 ?> 
     58 
     59$title = __('Import/Export'); 
     60 
     61echo ' 
    5662<html> 
    5763<head> 
    58      <title><?php echo __('Import/Export'); ?></title> 
    59      <style type="text/css"> 
    60      dl.modules dt { 
    61           font-weight: bold; 
    62           font-size: 1.1em; 
    63           margin: 1em 0 0 0; 
    64      } 
    65      dl.modules dd { 
    66           margin: 0 0 1.5em 0; 
    67      } 
    68      div.ie-progress { 
    69           background: #eee; 
    70           margin: 1em 0; 
    71      } 
    72      div.ie-progress div { 
    73           height: 10px; 
    74           width: 0; 
    75           font-size: 0.8em; 
    76           line-height: 1em; 
    77           height: 1em; 
    78           padding: 2px 0; 
    79           text-align: right; 
    80           background: green url(index.php?pf=importExport/progress.png) repeat-x top left; 
    81           color: white; 
    82           font-weight: bold; 
    83           -moz-border-radius: 2px; 
    84      } 
    85      </style> 
    86      <script type="text/javascript" src="index.php?pf=importExport/script.js"></script> 
     64     <title>'.$title.'</title> 
     65     <link rel="stylesheet" type="text/css" href="index.php?pf=importExport/style.css" /> 
     66     '.dcPage::jsLoad('index.php?pf=importExport/js/script.js').' 
    8767     <script type="text/javascript"> 
    8868     //<![CDATA[ 
    89      dotclear.msg.please_wait = '<?php echo html::escapeJS(__("Please wait...")); ?>'; 
     69     '.dcPage::jsVar('dotclear.msg.please_wait',__('Please wait...')).' 
    9070     //]]> 
    9171     </script> 
    9272</head> 
    93 <body> 
     73<body>'; 
    9474 
    95 <?php 
    96 if ($type && $current_module !== null) 
    97 { 
    98      echo '<h2><a href="'.$p_url.'">'.__('Import/Export').'</a>'. 
    99      ' &rsaquo; <span class="page-title">'.html::escapeHTML($current_module->name).'</span></h2>'; 
     75if ($type && $module !== null) { 
     76     echo 
     77     '<h2><a href="'.$p_url.'">'.$title.'</a>'. 
     78     ' &rsaquo; <span class="page-title">'.html::escapeHTML($module->name).'</span></h2>'. 
     79     '<div id="ie-gui">'; 
    10080      
    101      echo '<div id="ie-gui">'; 
    102      $current_module->gui(); 
     81     $module->gui(); 
     82      
    10383     echo '</div>'; 
    10484} 
    105 else 
    106 { 
    107      echo '<h2 class="page-title">'.__('Import/Export').'</h2>'; 
    108      echo '<h3>'.__('Import').'</h3>'; 
    109       
    110      echo '<dl class="modules">'; 
    111      foreach ($modules['i'] as $k => $v) 
    112      { 
    113           require_once $v; 
    114           $o = new $k($core); 
    115            
    116           echo  
    117           '<dt><a href="'.$o->getURL(true).'">'.html::escapeHTML($o->name).'</a></dt>'. 
    118           '<dd>'.html::escapeHTML($o->description).'</dd>'; 
    119            
    120           unset($o); 
    121      } 
    122      echo '</dl>'; 
    123       
    124      echo '<h3>'.__('Export').'</h3>'; 
    125       
    126      echo '<dl class="modules">'; 
    127      foreach ($modules['e'] as $k => $v) 
    128      { 
    129           require_once $v; 
    130           $o = new $k($core); 
    131            
    132           echo  
    133           '<dt><a href="'.$o->getURL(true).'">'.html::escapeHTML($o->name).'</a></dt>'. 
    134           '<dd>'.html::escapeHTML($o->description).'</dd>'; 
    135            
    136           unset($o); 
    137      } 
    138      echo '</dl>'; 
     85else { 
     86     echo 
     87     '<h2 class="page-title">'.$title.'</h2>'. 
     88     '<h3>'.__('Import').'</h3>'.listImportExportModules($core,$modules['import']). 
     89     '<h3>'.__('Export').'</h3>'.listImportExportModules($core,$modules['export']); 
    13990} 
     91 
     92echo ' 
     93</body> 
     94</html>'; 
    14095?> 
    141  
    142 </body> 
    143 </html> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map