Dotclear


Ignore:
Timestamp:
03/08/18 17:58:39 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Code formatting (PSR-2)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • admin/update.php

    r3390 r3730  
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    1212 
    13 require dirname(__FILE__).'/../inc/admin/prepend.php'; 
     13require dirname(__FILE__) . '/../inc/admin/prepend.php'; 
    1414 
    1515if (!defined('DC_BACKUP_PATH')) { 
    16      define('DC_BACKUP_PATH',DC_ROOT); 
     16    define('DC_BACKUP_PATH', DC_ROOT); 
    1717} 
    1818 
     
    2020 
    2121if (!is_readable(DC_DIGESTS)) { 
    22      dcPage::open(__('Dotclear update')); 
    23      echo '<h2>Access denied</h2>'; 
    24      dcPage::close(); 
    25      exit; 
    26 } 
    27  
    28 $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions'); 
    29 $new_v = $updater->check(DC_VERSION, !empty($_GET['nocache'])); 
    30 $zip_file = $new_v ? DC_BACKUP_PATH.'/'.basename($updater->getFileURL()) : ''; 
     22    dcPage::open(__('Dotclear update')); 
     23    echo '<h2>Access denied</h2>'; 
     24    dcPage::close(); 
     25    exit; 
     26} 
     27 
     28$updater      = new dcUpdate(DC_UPDATE_URL, 'dotclear', DC_UPDATE_VERSION, DC_TPL_CACHE . '/versions'); 
     29$new_v        = $updater->check(DC_VERSION, !empty($_GET['nocache'])); 
     30$zip_file     = $new_v ? DC_BACKUP_PATH . '/' . basename($updater->getFileURL()) : ''; 
    3131$version_info = $new_v ? $updater->getInfoURL() : ''; 
    3232 
    3333# Hide "update me" message 
    3434if (!empty($_GET['hide_msg'])) { 
    35      $updater->setNotify(false); 
    36      http::redirect('index.php'); 
     35    $updater->setNotify(false); 
     36    http::redirect('index.php'); 
    3737} 
    3838 
     
    4040 
    4141$step = isset($_GET['step']) ? $_GET['step'] : ''; 
    42 $step = in_array($step,array('check','download','backup','unzip')) ? $step : ''; 
     42$step = in_array($step, array('check', 'download', 'backup', 'unzip')) ? $step : ''; 
    4343 
    4444$default_tab = !empty($_GET['tab']) ? html::escapeHTML($_GET['tab']) : 'update'; 
    4545if (!empty($_POST['backup_file'])) { 
    46      $default_tab = 'files'; 
     46    $default_tab = 'files'; 
    4747} 
    4848 
    4949$archives = array(); 
    5050foreach (files::scanDir(DC_BACKUP_PATH) as $v) { 
    51      if (preg_match('/backup-([0-9A-Za-z\.-]+).zip/',$v)) { 
    52           $archives[] = $v; 
    53      } 
     51    if (preg_match('/backup-([0-9A-Za-z\.-]+).zip/', $v)) { 
     52        $archives[] = $v; 
     53    } 
    5454} 
    5555if (!empty($archives)) { 
    56      usort($archives,"version_compare"); 
     56    usort($archives, "version_compare"); 
    5757} else { 
    58      $default_tab = 'update'; 
     58    $default_tab = 'update'; 
    5959} 
    6060 
    6161# Revert or delete backup file 
    62 if (!empty($_POST['backup_file']) && in_array($_POST['backup_file'],$archives)) 
    63 { 
    64      $b_file = $_POST['backup_file']; 
    65  
    66      try 
    67      { 
    68           if (!empty($_POST['b_del'])) 
    69           { 
    70                if (!@unlink(DC_BACKUP_PATH.'/'.$b_file)) { 
    71                     throw new Exception(sprintf(__('Unable to delete file %s'),html::escapeHTML($b_file))); 
    72                } 
    73                http::redirect($p_url.'?tab=files'); 
    74           } 
    75  
    76           if (!empty($_POST['b_revert'])) 
    77           { 
    78                $zip = new fileUnzip(DC_BACKUP_PATH.'/'.$b_file); 
    79                $zip->unzipAll(DC_BACKUP_PATH.'/'); 
    80                @unlink(DC_BACKUP_PATH.'/'.$b_file); 
    81                http::redirect($p_url.'?tab=files'); 
    82           } 
    83      } 
    84      catch (Exception $e) 
    85      { 
    86           $core->error->add($e->getMessage()); 
    87      } 
     62if (!empty($_POST['backup_file']) && in_array($_POST['backup_file'], $archives)) { 
     63    $b_file = $_POST['backup_file']; 
     64 
     65    try 
     66    { 
     67        if (!empty($_POST['b_del'])) { 
     68            if (!@unlink(DC_BACKUP_PATH . '/' . $b_file)) { 
     69                throw new Exception(sprintf(__('Unable to delete file %s'), html::escapeHTML($b_file))); 
     70            } 
     71            http::redirect($p_url . '?tab=files'); 
     72        } 
     73 
     74        if (!empty($_POST['b_revert'])) { 
     75            $zip = new fileUnzip(DC_BACKUP_PATH . '/' . $b_file); 
     76            $zip->unzipAll(DC_BACKUP_PATH . '/'); 
     77            @unlink(DC_BACKUP_PATH . '/' . $b_file); 
     78            http::redirect($p_url . '?tab=files'); 
     79        } 
     80    } catch (Exception $e) { 
     81        $core->error->add($e->getMessage()); 
     82    } 
    8883} 
    8984 
    9085# Upgrade process 
    91 if ($new_v && $step) 
    92 { 
    93      try 
    94      { 
    95           $updater->setForcedFiles('inc/digests'); 
    96  
    97           switch ($step) 
    98           { 
    99                case 'check': 
    100                     $updater->checkIntegrity(DC_ROOT.'/inc/digests',DC_ROOT); 
    101                     http::redirect($p_url.'?step=download'); 
    102                     break; 
    103                case 'download': 
    104                     $updater->download($zip_file); 
    105                     if (!$updater->checkDownload($zip_file)) { 
    106                          throw new Exception( 
    107                               sprintf(__('Downloaded Dotclear archive seems to be corrupted. '. 
    108                               'Try <a %s>download it</a> again.'),'href="'.$p_url.'?step=download"'). 
    109                               ' '. 
    110                               __('If this problem persists try to '. 
    111                               '<a href="http://dotclear.org/download">update manually</a>.') 
    112                          ); 
    113                     } 
    114                     http::redirect($p_url.'?step=backup'); 
    115                     break; 
    116                case 'backup': 
    117                     $updater->backup( 
    118                          $zip_file, 'dotclear/inc/digests', 
    119                          DC_ROOT, DC_ROOT.'/inc/digests', 
    120                          DC_BACKUP_PATH.'/backup-'.DC_VERSION.'.zip' 
    121                     ); 
    122                     http::redirect($p_url.'?step=unzip'); 
    123                     break; 
    124                case 'unzip': 
    125                     $updater->performUpgrade( 
    126                          $zip_file, 'dotclear/inc/digests', 'dotclear', 
    127                          DC_ROOT, DC_ROOT.'/inc/digests' 
    128                     ); 
    129                     break; 
    130           } 
    131      } 
    132      catch (Exception $e) 
    133      { 
    134           $msg = $e->getMessage(); 
    135  
    136           if ($e->getCode() == dcUpdate::ERR_FILES_CHANGED) 
    137           { 
    138                $msg = 
    139                __('The following files of your Dotclear installation '. 
    140                'have been modified so we won\'t try to update your installation. '. 
    141                'Please try to <a href="http://dotclear.org/download">update manually</a>.'); 
    142           } 
    143           elseif ($e->getCode() == dcUpdate::ERR_FILES_UNREADABLE) 
    144           { 
    145                $msg = 
    146                sprintf(__('The following files of your Dotclear installation are not readable. '. 
    147                'Please fix this or try to make a backup file named %s manually.'), 
    148                '<strong>backup-'.DC_VERSION.'.zip</strong>'); 
    149           } 
    150           elseif ($e->getCode() == dcUpdate::ERR_FILES_UNWRITALBE) 
    151           { 
    152                $msg = 
    153                __('The following files of your Dotclear installation cannot be written. '. 
    154                'Please fix this or try to <a href="http://dotclear.org/download">update manually</a>.'); 
    155           } 
    156  
    157           if (isset($e->bad_files)) { 
    158                $msg .= 
    159                '<ul><li><strong>'. 
    160                implode('</strong></li><li><strong>',$e->bad_files). 
    161                '</strong></li></ul>'; 
    162           } 
    163  
    164           $core->error->add($msg); 
    165  
    166           $core->callBehavior('adminDCUpdateException',$e); 
    167      } 
     86if ($new_v && $step) { 
     87    try 
     88    { 
     89        $updater->setForcedFiles('inc/digests'); 
     90 
     91        switch ($step) { 
     92            case 'check': 
     93                $updater->checkIntegrity(DC_ROOT . '/inc/digests', DC_ROOT); 
     94                http::redirect($p_url . '?step=download'); 
     95                break; 
     96            case 'download': 
     97                $updater->download($zip_file); 
     98                if (!$updater->checkDownload($zip_file)) { 
     99                    throw new Exception( 
     100                        sprintf(__('Downloaded Dotclear archive seems to be corrupted. ' . 
     101                            'Try <a %s>download it</a> again.'), 'href="' . $p_url . '?step=download"') . 
     102                        ' ' . 
     103                        __('If this problem persists try to ' . 
     104                            '<a href="http://dotclear.org/download">update manually</a>.') 
     105                    ); 
     106                } 
     107                http::redirect($p_url . '?step=backup'); 
     108                break; 
     109            case 'backup': 
     110                $updater->backup( 
     111                    $zip_file, 'dotclear/inc/digests', 
     112                    DC_ROOT, DC_ROOT . '/inc/digests', 
     113                    DC_BACKUP_PATH . '/backup-' . DC_VERSION . '.zip' 
     114                ); 
     115                http::redirect($p_url . '?step=unzip'); 
     116                break; 
     117            case 'unzip': 
     118                $updater->performUpgrade( 
     119                    $zip_file, 'dotclear/inc/digests', 'dotclear', 
     120                    DC_ROOT, DC_ROOT . '/inc/digests' 
     121                ); 
     122                break; 
     123        } 
     124    } catch (Exception $e) { 
     125        $msg = $e->getMessage(); 
     126 
     127        if ($e->getCode() == dcUpdate::ERR_FILES_CHANGED) { 
     128            $msg = 
     129                __('The following files of your Dotclear installation ' . 
     130                'have been modified so we won\'t try to update your installation. ' . 
     131                'Please try to <a href="http://dotclear.org/download">update manually</a>.'); 
     132        } elseif ($e->getCode() == dcUpdate::ERR_FILES_UNREADABLE) { 
     133            $msg = 
     134                sprintf(__('The following files of your Dotclear installation are not readable. ' . 
     135                'Please fix this or try to make a backup file named %s manually.'), 
     136                '<strong>backup-' . DC_VERSION . '.zip</strong>'); 
     137        } elseif ($e->getCode() == dcUpdate::ERR_FILES_UNWRITALBE) { 
     138            $msg = 
     139                __('The following files of your Dotclear installation cannot be written. ' . 
     140                'Please fix this or try to <a href="http://dotclear.org/download">update manually</a>.'); 
     141        } 
     142 
     143        if (isset($e->bad_files)) { 
     144            $msg .= 
     145            '<ul><li><strong>' . 
     146            implode('</strong></li><li><strong>', $e->bad_files) . 
     147                '</strong></li></ul>'; 
     148        } 
     149 
     150        $core->error->add($msg); 
     151 
     152        $core->callBehavior('adminDCUpdateException', $e); 
     153    } 
    168154} 
    169155 
     
    171157-------------------------------------------------------- */ 
    172158dcPage::open(__('Dotclear update'), 
    173      (!$step ? 
    174           dcPage::jsPageTabs($default_tab). 
    175           dcPage::jsLoad('js/_update.js') 
    176           : ''), 
    177      dcPage::breadcrumb( 
    178           array( 
    179                __('System') => '', 
    180                __('Dotclear update') => '' 
    181           )) 
     159    (!$step ? 
     160        dcPage::jsPageTabs($default_tab) . 
     161        dcPage::jsLoad('js/_update.js') 
     162        : ''), 
     163    dcPage::breadcrumb( 
     164        array( 
     165            __('System')          => '', 
     166            __('Dotclear update') => '' 
     167        )) 
    182168); 
    183169 
    184170if (!$core->error->flag()) { 
    185      if (!empty($_GET['nocache'])) { 
    186           dcPage::success(__('Manual checking of update done successfully.')); 
    187      } 
    188 } 
    189  
    190 if (!$step) 
    191 { 
    192      echo '<div class="multi-part" id="update" title="'.__('Dotclear update').'">'; 
    193      if (empty($new_v)) 
    194      { 
    195           echo '<p><strong>'.__('No newer Dotclear version available.').'</strong></p>'. 
    196           '<form action="'.$p_url.'" method="get">'. 
    197           '<p><input type="hidden" name="nocache" value="1" />'. 
    198           '<input type="submit" value="'.__('Force checking update Dotclear').'" /></p>'. 
    199           '</form>'; 
    200      } 
    201      else 
    202      { 
    203           echo 
    204                '<p class="static-msg">'.sprintf(__('Dotclear %s is available.'),$new_v). 
    205                ($version_info ? ' <a href="'.$version_info.'" class="outgoing" title="'.__('Information about this version').'">('. 
    206                __('Information about this version').')&nbsp;<img src="images/outgoing.png" alt=""/></a>' : ''). 
    207                '</p>'; 
    208           if (version_compare(phpversion(),$updater->getPHPVersion()) < 0) { 
    209                echo 
    210                '<p class="warning-msg">'.sprintf(__('PHP version is %s (%s or earlier needed).'),phpversion(),$updater->getPHPVersion()).'</p>'; 
    211           } else { 
    212                echo 
    213                '<p>'.__('To upgrade your Dotclear installation simply click on the following button. '. 
    214                     'A backup file of your current installation will be created in your root directory.').'</p>'. 
    215                '<form action="'.$p_url.'" method="get">'. 
    216                '<p><input type="hidden" name="step" value="check" />'. 
    217                '<input type="submit" value="'.__('Update Dotclear').'" /></p>'. 
    218                '</form>'; 
    219           } 
    220      } 
    221      echo '</div>'; 
    222  
    223      if (!empty($archives)) 
    224      { 
    225           echo '<div class="multi-part" id="files" title="'.__('Manage backup files').'">'; 
    226  
    227           echo 
    228           '<h3>'.__('Update backup files').'</h3>'. 
    229           '<p>'.__('The following files are backups of previously updates. '. 
    230           'You can revert your previous installation or delete theses files.').'</p>'; 
    231  
    232           echo '<form action="'.$p_url.'" method="post">'; 
    233           foreach ($archives as $v) { 
    234                echo 
    235                '<p><label class="classic">'.form::radio(array('backup_file'),html::escapeHTML($v)).' '. 
    236                html::escapeHTML($v).'</label></p>'; 
    237           } 
    238  
    239           echo 
    240           '<p><strong>'.__('Please note that reverting your Dotclear version may have some '. 
    241           'unwanted side-effects. Consider reverting only if you experience strong issues with this new version.').'</strong> '. 
    242           sprintf(__('You should not revert to version prior to last one (%s).'),end($archives)). 
    243           '</p>'. 
    244           '<p><input type="submit" class="delete" name="b_del" value="'.__('Delete selected file').'" /> '. 
    245           '<input type="submit" name="b_revert" value="'.__('Revert to selected file').'" />'. 
    246           $core->formNonce().'</p>'. 
    247           '</form>'; 
    248  
    249           echo '</div>'; 
    250      } 
    251 } 
    252 elseif ($step == 'unzip' && !$core->error->flag()) 
    253 { 
    254      echo 
    255      '<p class="message">'. 
    256      __("Congratulations, you're one click away from the end of the update."). 
    257      ' <strong><a href="index.php?logout=1">'.__('Finish the update.').'</a></strong>'. 
    258      '</p>'; 
     171    if (!empty($_GET['nocache'])) { 
     172        dcPage::success(__('Manual checking of update done successfully.')); 
     173    } 
     174} 
     175 
     176if (!$step) { 
     177    echo '<div class="multi-part" id="update" title="' . __('Dotclear update') . '">'; 
     178    if (empty($new_v)) { 
     179        echo '<p><strong>' . __('No newer Dotclear version available.') . '</strong></p>' . 
     180        '<form action="' . $p_url . '" method="get">' . 
     181        '<p><input type="hidden" name="nocache" value="1" />' . 
     182        '<input type="submit" value="' . __('Force checking update Dotclear') . '" /></p>' . 
     183            '</form>'; 
     184    } else { 
     185        echo 
     186        '<p class="static-msg">' . sprintf(__('Dotclear %s is available.'), $new_v) . 
     187            ($version_info ? ' <a href="' . $version_info . '" class="outgoing" title="' . __('Information about this version') . '">(' . 
     188            __('Information about this version') . ')&nbsp;<img src="images/outgoing.png" alt=""/></a>' : '') . 
     189            '</p>'; 
     190        if (version_compare(phpversion(), $updater->getPHPVersion()) < 0) { 
     191            echo 
     192            '<p class="warning-msg">' . sprintf(__('PHP version is %s (%s or earlier needed).'), phpversion(), $updater->getPHPVersion()) . '</p>'; 
     193        } else { 
     194            echo 
     195            '<p>' . __('To upgrade your Dotclear installation simply click on the following button. ' . 
     196                'A backup file of your current installation will be created in your root directory.') . '</p>' . 
     197            '<form action="' . $p_url . '" method="get">' . 
     198            '<p><input type="hidden" name="step" value="check" />' . 
     199            '<input type="submit" value="' . __('Update Dotclear') . '" /></p>' . 
     200                '</form>'; 
     201        } 
     202    } 
     203    echo '</div>'; 
     204 
     205    if (!empty($archives)) { 
     206        echo '<div class="multi-part" id="files" title="' . __('Manage backup files') . '">'; 
     207 
     208        echo 
     209        '<h3>' . __('Update backup files') . '</h3>' . 
     210        '<p>' . __('The following files are backups of previously updates. ' . 
     211            'You can revert your previous installation or delete theses files.') . '</p>'; 
     212 
     213        echo '<form action="' . $p_url . '" method="post">'; 
     214        foreach ($archives as $v) { 
     215            echo 
     216            '<p><label class="classic">' . form::radio(array('backup_file'), html::escapeHTML($v)) . ' ' . 
     217            html::escapeHTML($v) . '</label></p>'; 
     218        } 
     219 
     220        echo 
     221        '<p><strong>' . __('Please note that reverting your Dotclear version may have some ' . 
     222            'unwanted side-effects. Consider reverting only if you experience strong issues with this new version.') . '</strong> ' . 
     223        sprintf(__('You should not revert to version prior to last one (%s).'), end($archives)) . 
     224        '</p>' . 
     225        '<p><input type="submit" class="delete" name="b_del" value="' . __('Delete selected file') . '" /> ' . 
     226        '<input type="submit" name="b_revert" value="' . __('Revert to selected file') . '" />' . 
     227        $core->formNonce() . '</p>' . 
     228            '</form>'; 
     229 
     230        echo '</div>'; 
     231    } 
     232} elseif ($step == 'unzip' && !$core->error->flag()) { 
     233    echo 
     234    '<p class="message">' . 
     235    __("Congratulations, you're one click away from the end of the update.") . 
     236    ' <strong><a href="index.php?logout=1">' . __('Finish the update.') . '</a></strong>' . 
     237        '</p>'; 
    259238} 
    260239 
Note: See TracChangeset for help on using the changeset viewer.

Sites map