Changeset 1711

Show
Ignore:
Timestamp:
03/24/2008 01:30:49 PM (8 months ago)
Author:
jeena
Message:

removed ability to automaticly preserve language files, fixed double printed errors

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/admin/update.php

    r1706 r1711  
    44  define("JLOG_ADMIN", true); 
    55  define("JLOG_UPDATE", true); 
    6   error_reporting(E_ALL ^ E_NOTICE); 
     6  define("JLOG_LANGUAGE", "de"); // per default load the german language files 
    77   
    8   /** 
    9    * In earlier Jlog versions, there used to be an require_once(prepend.inc.php) in 
    10    * the settings.inc.php. Therefore, we need to check against this inclusion, as 
    11    * we MUST NOT include prepend.inc.php. 
    12    */ 
    13   $config = file_get_contents('..'.DIRECTORY_SEPARATOR.'personal'.DIRECTORY_SEPARATOR.'settings.inc.php'); 
    14   if(strpos($config, 'require_once') !== false) { 
    15     // there is require_once in settings.inc.php, so we need to parse that file manually 
    16     preg_match_all("/define\('(JLOG_[A-Z_]+)', ('[^']*'|true|false|\d+)\);/", $config, $result, PREG_SET_ORDER); 
    17     // only finds constants that start with JLOG_ and have a boolean, numeric or single-quoted value 
    18     foreach($result as $constant) { 
    19       switch($constant[2]) { 
    20         case 'true': 
    21           $value = true; 
    22           break; 
    23         case 'false': 
    24           $value = false; 
    25           break; 
    26         default: 
    27           if(is_numeric($constant[2])) { 
    28             $value = (int) $constant[2]; 
    29           } 
    30           else { 
    31             $value = stripslashes(substr($constant[2], 1, -1)); 
    32           } 
    33           break; 
    34       } 
    35       define($constant[1], $value); 
    36     } 
    37   } 
    38   else { 
    39     // there is no require_once in settings.inc.php, so we can simply include it 
    40     require_once('..'.DIRECTORY_SEPARATOR.'personal'.DIRECTORY_SEPARATOR.'settings.inc.php'); 
    41   } 
    42    
    43   // define table names 
    44   define("JLOG_DB_CONTENT", JLOG_DB_PREFIX."content"); 
    45   define("JLOG_DB_COMMENTS", JLOG_DB_PREFIX."comments"); 
    46   define("JLOG_DB_CATASSIGN", JLOG_DB_PREFIX."catassign"); 
    47   define("JLOG_DB_CATEGORIES", JLOG_DB_PREFIX."categories"); 
    48   define("JLOG_DB_ATTRIBUTES", JLOG_DB_PREFIX."attributes"); 
    49    
    50   // get version information 
    51   require_once(JLOG_BASEPATH.'scripts'.DIRECTORY_SEPARATOR.'version.inc.php'); 
    52    
     8  // load prepend.inc.php 
     9  require_once('..'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'prepend.inc.php'); 
     10    
    5311  /** 
    5412   * If there is no version information available we think of the installation 
     
    6018    define('JLOG_INSTALLED_VERSION', '1.0.2'); 
    6119  } 
     20  // Seitenaufbau 
     21  $c['meta']['title'] = "Update"; 
     22  $c['main'] = sprintf("<h2>Update von <var>%s</var> auf <var>%s</var></h2>", JLOG_INSTALLED_VERSION, JLOG_SOFTWARE_VERSION); 
     23 
    6224  /** 
    6325   * If we are already at the version we want to upgrade to this means that the 
     
    6527   */ 
    6628  if(version_compare(JLOG_SOFTWARE_VERSION, JLOG_INSTALLED_VERSION, '==')) { 
    67     header('Content-Type: text/plain'); 
    68     echo 'The update script must only be runend once.' . "\n"; 
    69     echo 'Das Update-Skript darf nur einmal ausgefÃŒhrt werden.'; 
    70     exit; 
    71   } 
    72    
    73   /** 
    74    * Da wir prepenc.inc.php nicht inkluden können, mÃŒssen wir ein paar 
    75    * Teile davon hier manuell ausfÃŒhren, da sonst das Template-System 
    76    * nicht funktioniert. 
    77    */ 
    78   require_once(JLOG_BASEPATH.'lang'.DIRECTORY_SEPARATOR.'lang.inc.php'); 
    79   require_once(JLOG_BASEPATH.'lang'.DIRECTORY_SEPARATOR.'lang-admin.inc.php'); 
    80   require_once(JLOG_BASEPATH.'scripts'.DIRECTORY_SEPARATOR.'database.class.php');  
    81   require_once(JLOG_BASEPATH.'scripts'.DIRECTORY_SEPARATOR.'bbcode.php');  
    82   require_once(JLOG_BASEPATH.'scripts'.DIRECTORY_SEPARATOR.'general.func.php');  
    83   $connect = @mysql_connect(JLOG_DB_URL, JLOG_DB_USER, JLOG_DB_PWD); 
    84   if ($connect == FALSE) { 
    85     mail(JLOG_EMAIL, $l['admin']['e_db'], $l['admin']['e_db_is']."\n".mysql_error()); 
    86     die("<strong>".$l['db_error']."</strong><br />".$l['plz_try_again']."."); 
    87   } 
    88   @mysql_select_db( JLOG_DB ); 
    89   @mysql_query("SET NAMES utf8"); 
    90   @mysql_query("SET sql_mode=''"); 
    91    
    92   require_once(JLOG_BASEPATH.'scripts'.DIRECTORY_SEPARATOR.'categories.class.php'); 
    93   require_once(JLOG_BASEPATH.'scripts'.DIRECTORY_SEPARATOR.'jlogPlugins.class.php'); 
    94   $plugins = new JlogPluginManager(JLOG_BASEPATH.'plugins'.DIRECTORY_SEPARATOR); 
     29    $c['main'] .= '<p class="error">Version '.JLOG_INSTALLED_VERSION.' ist bereits komplett installiert.</p>'; 
     30  } else { 
    9531 
    96   // VerfÃŒgbare Sprachen auslesen 
    97   $dir = opendir(JLOG_BASEPATH.'lang'); 
    98   $languages = array(); 
    99   while(($file = readdir($dir)) !== false) { 
    100     if($file == '.' OR $file == '..') continue; 
    101     if(!preg_match('/lang\.([a-zA-z0-9]+)\.inc\.php/', $file, $matches)) continue; 
    102     $languages[] = $matches[1]; 
    103   } 
    104    
    105    
    106   // Seitenaufbau 
    107   $c['meta']['title'] = "Update"; 
    108   $c['main'] = sprintf("<h2>Update von <var>%s</var> auf <var>%s</var></h2>", JLOG_INSTALLED_VERSION, JLOG_SOFTWARE_VERSION); 
     32        // VerfÃŒgbare Sprachen auslesen 
     33        $dir = opendir(JLOG_BASEPATH.'lang'); 
     34        $languages = array(); 
     35        while(($file = readdir($dir)) !== false) { 
     36          if($file == '.' OR $file == '..') continue; 
     37          if(!preg_match('/lang\.([a-zA-z0-9]+)\.inc\.php/', $file, $matches)) continue; 
     38          $languages[] = $matches[1]; 
     39        } 
     40        // bisherige Sprache herausfinden 
     41        include(JLOG_BASEPATH."lang".DIRECTORY_SEPARATOR."lang.inc.php"); 
     42        list($old_language) = explode("-", $l["language"]); 
     43        include(JLOG_BASEPATH.'lang'.DIRECTORY_SEPARATOR.'lang.'.JLOG_LANGUAGE.'.inc.php'); 
     44 
     45        if(!isset($_POST['update'])) { 
     46          $c['main'] .= "<form action='".$_SERVER['PHP_SELF']."' method='post' accept-charset='UTF-8'> 
     47              <p><label for='password'>Bitte geben Sie Ihr aktuelles Administrator-Passwort ein (zum Schutz gegen unbefugtes Aufrufen dieses Scriptes):</label><br /> 
     48                <input type='password' name='password' id='password' value='' /></p> 
     49              <p><label for='language'>Bitte wÀhlen Sie die gewÃŒnschte Sprache fÃŒr Ihr Weblog:</label><br /> 
     50                <select class='userdata' id='language' name='jlog_language'>";  
     51          foreach($languages as $lang) { 
     52            $c['main'] .= "<option"; 
     53            if((isset($_POST['jlog_language']) AND $_POST['jlog_language'] == $lang) OR $old_language == $lang) $c['main'] .= " selected='selected'"; 
     54            $c['main'] .= ">$lang</option>"; 
     55          } 
     56          $c['main'] .= "</select> 
     57             </p> 
     58                 <p>Die Datei <code>personal/template.tpl</code> muss nach UTF-8 konvertiert werden. Wenn diese Datei 
     59                    beschreibbar ist (z.B.: chmod 777), wird dies vom Updatescript fÃŒr sie automatisch erledigt. 
     60                    Ansonsten mÃŒssen Sie es im nachhinein manuell erledigen.</p> 
     61             <p><input type='submit' name='update' value='Update starten' /></p> 
     62             </form>"; 
     63        } 
     64        else { 
     65          /** 
     66           * Das alte Passwort ist anders kodiert (vorher ISO, jetzt UTF-8), deshalb 
     67           * testen wir verschiedene Varianten des Passwortes 
     68           */ 
     69          $pass1 = md5($_POST['password']);              # Idealfall 
     70          $pass2 = md5(utf8_decode($_POST['password'])); # wahrscheinlichster Fall, wenn Jlog 1.0.2 vorher installiert war 
     71          $pass3 = md5(utf8_encode($_POST['password'])); # sollte in der RealitÀt eigentlich nie in der Form vorkommen 
     72 
     73          /** 
     74           * Formulareingaben validieren 
     75           */ 
     76          if(JLOG_ADMIN_PASSWORD != $pass1 AND JLOG_ADMIN_PASSWORD != $pass2 AND JLOG_ADMIN_PASSWORD != $pass3) { 
     77            $update_errors[] = 'Administrator-Passwort fehlerhaft!'; 
     78          } 
    10979  
    110   if(!isset($_POST['update'])) { 
    111     $c['main'] .= "<form action='".$_SERVER['PHP_SELF']."' method='post' accept-charset='UTF-8'> 
    112         <p><label for='password'>Bitte geben Sie Ihr aktuelles Administrator-Passwort ein (zum Schutz gegen unbefugtes Aufrufen dieses Scriptes):</label><br /> 
    113           <input type='password' name='password' id='password' value='' /></p> 
    114         <p><label for='language'>Bitte wÀhlen Sie die gewÃŒnschte Sprache fÃŒr Ihr Weblog:</label><br /> 
    115           <select class='userdata' id='language' name='jlog_language'>";  
    116     foreach($languages as $lang) { 
    117       $c['main'] .= "<option"; 
    118       if(isset($_POST['jlog_language']) AND $_POST['jlog_language'] == $lang) $c['main'] .= " selected='selected'"; 
    119       $c['main'] .= ">$lang</option>"; 
    120     } 
    121     $c['main'] .= "</select> 
    122        </p> 
    123        <p>Möchten Sie Ihre alten Sprachdateien behalten, oder diese durch neue ersetzen lassen? 
    124           Solange Sie an den alten Sprachdateien keine VerÀnderungen vorgenommen haben empfehlen wir dringenst, die neuen  
    125           Sprachdateien zu installieren.<br /> 
    126           <label><input type='radio' name='languagekeep' value='yes' /> Ja, alte Dateien behalten.</label> 
    127           <label><input type='radio' name='languagekeep' value='no' checked='checked' /> Nein, neue Dateien installieren.</label></p> 
    128        <p><input type='submit' name='update' value='Update starten' /></p> 
    129        </form>"; 
    130   } 
    131   else { 
    132     /** 
    133      * Das alte Passwort ist anders kodiert (vorher ISO, jetzt UTF-8), deshalb 
    134      * testen wir verschiedene Varianten des Passwortes 
    135      */ 
    136     $pass1 = md5($_POST['password']);              # Idealfall 
    137     $pass2 = md5(utf8_decode($_POST['password'])); # wahrscheinlichster Fall, wenn Jlog 1.0.2 vorher installiert war 
    138     $pass3 = md5(utf8_encode($_POST['password'])); # sollte in der RealitÀt eigentlich nie in der Form vorkommen 
     80          if(empty($update_errors)) { 
     81            require(JLOG_BASEPATH."scripts".DIRECTORY_SEPARATOR."settings.class.php"); 
     82    
     83            // aktuelle Einstellungen aus Environment und User-Input auslesen 
     84            $update = new Settings($l); 
     85            $update->get_data(); 
     86            $update->get_userdata(); 
     87    
     88            // alle Werte nach UTF-8 umkodieren 
     89            foreach($update->d as $key => $value) { 
     90              $update->d[$key] = utf8_encode($value); 
     91            } 
     92    
     93            // Passwort-Hash neu setzen, falls wegen neuer Kodierung nicht mehr korrekt 
     94            $update->d['jlog_admin_password'] = $pass1; 
     95    
     96            // Sprache speichern 
     97            $update->d['jlog_language'] = $_POST['jlog_language']; 
     98    
     99            // settings.inc.php neu schreiben 
     100            $update_errors = $update->do_settings(); 
     101          
     102            /** 
     103             * Das Template von Jlog sollte als ISO abgespeichert sein bei Jlog 1.0.2, 
     104             * fÃŒr Jlog 1.1.0 muss es allerdings als UTF-8 abgespeichert werden, dies 
     105             * geschieht hier. 
     106             */ 
     107            $template = JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."template.tpl"; 
     108            if(@file_put_contents($template, utf8_encode(@file_get_contents($template))) == false) { 
     109              $update_errors[] = 'Die Datei <code>personal/template.tpl</code> konnte nicht in UTF-8 Kodierung konvertiert werden.'; 
     110            } 
    139111 
    140     /** 
    141      * Formulareingaben validieren 
    142      */ 
    143     if(JLOG_ADMIN_PASSWORD != $pass1 AND JLOG_ADMIN_PASSWORD != $pass2 AND JLOG_ADMIN_PASSWORD != $pass3) { 
    144       $errors[] = 'Administrator-Passwort fehlerhaft!'; 
    145     } 
    146     if(!isset($_POST['languagekeep']) OR !in_array($_POST['languagekeep'], array('yes', 'no'))) { 
    147       $errors[] = 'Bitte Auswahl treffen, ob Sie die alten Sprachdateien behalten möchten oder nicht.'; 
    148     } 
    149      
    150     if(empty($errors)) { 
    151       require(JLOG_BASEPATH."scripts".DIRECTORY_SEPARATOR."settings.class.php"); 
    152        
    153       // aktuelle Einstellungen aus Environment und User-Input auslesen 
    154       $update = new Settings($l); 
    155       $update->get_data(); 
    156       $update->get_userdata(); 
    157        
    158       // alle Werte nach UTF-8 umkodieren 
    159       foreach($update->d as $key => $value) { 
    160         $update->d[$key] = utf8_encode($value); 
    161       } 
    162        
    163       // Passwort-Hash neu setzen, falls wegen neuer Kodierung nicht mehr korrekt 
    164       $update->d['jlog_admin_password'] = $pass1; 
    165        
    166       // Sprache speichern 
    167       $update->d['jlog_language'] = $_POST['jlog_language']; 
    168        
    169       // settings.inc.php neu schreiben 
    170       $errors = $update->do_settings(); 
    171        
    172       if($_POST['languagekeep'] == 'yes') { 
    173         $file1 = @rename(JLOG_BASEPATH."lang".DIRECTORY_SEPARATOR."lang.inc.php", JLOG_BASEPATH."lang".DIRECTORY_SEPARATOR."lang.MyLanguage.inc.php"); 
    174         $file2 = @rename(JLOG_BASEPATH."lang".DIRECTORY_SEPARATOR."lang-admin.inc.php", JLOG_BASEPATH."lang".DIRECTORY_SEPARATOR."lang-admin.MyLanguage.inc.php"); 
    175         // falls umbenennen scheitert, es mit kopieren und löschen probieren 
    176         if($file1 === false) { 
    177           @copy(JLOG_BASEPATH."lang".DIRECTORY_SEPARATOR."lang.inc.php", JLOG_BASEPATH."lang".DIRECTORY_SEPARATOR."lang.MyLanguage.inc.php"); 
    178           $file1 = @unlink(JLOG_BASEPATH."lang".DIRECTORY_SEPARATOR."lang.inc.php"); 
    179         } 
    180         if($file2 === false) { 
    181           @copy(JLOG_BASEPATH."lang".DIRECTORY_SEPARATOR."lang-admin.inc.php", JLOG_BASEPATH."lang".DIRECTORY_SEPARATOR."lang-admin.MyLanguage.inc.php"); 
    182           $file2 = @unlink(JLOG_BASEPATH."lang".DIRECTORY_SEPARATOR."lang-admin.inc.php"); 
    183         } 
    184       } 
    185       else { 
    186         $file1 = @unlink(JLOG_BASEPATH."lang".DIRECTORY_SEPARATOR."lang.inc.php"); 
    187         $file2 = @unlink(JLOG_BASEPATH."lang".DIRECTORY_SEPARATOR."lang-admin.inc.php"); 
    188       } 
    189       if($file1 === false) { 
    190         $errors[] = 'Die Datei <code>lang/lang.inc.php</code> konnte nicht gelöscht werden.'; 
    191       } 
    192       if($file2 === false) { 
    193         $errors[] = 'Die Datei <code>lang/lang-admin.inc.php</code> konnte nicht gelöscht werden.'; 
    194       } 
    195        
    196       /** 
    197        * Das Template von Jlog sollte als ISO abgespeichert sein bei Jlog 1.0.2, 
    198        * fÃŒr Jlog 1.1.0 muss es allerdings als UTF-8 abgespeichert werden, dies 
    199        * geschieht hier. 
    200        * Durch die Verwendung von file_get_contents() und file_put_contents() setzen 
    201        * wir PHP 
    202        */ 
    203       // Datei einlesen 
    204       $template = JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."template.tpl"; 
    205       $fh = fopen($template, "r+"); 
    206       if($fh !== false) { 
    207         flock($fh, LOCK_EX); 
    208         $content = fread($fh, filesize($template)); 
    209         // umkodieren 
    210         $content = utf8_encode($content); 
    211         // zurÃŒckschreiben 
    212         fseek($fh, 0); 
    213         ftruncate($fh, 0); 
    214         fwrite($fh, $content); 
    215         flock($fh, LOCK_UN); 
    216         fclose($fh); 
    217       } 
    218       else { 
    219         // Datei konnte nicht zum Schreiben geöffnet werden 
    220         $errors[] = 'Die Datei <code>personal/template.tpl</code> konnte nicht in UTF-8 Kodierung konvertiert werden.'; 
    221       } 
    222        
    223       // Fertig :-) 
    224       require(JLOG_BASEPATH."scripts".DIRECTORY_SEPARATOR."update.php"); 
    225        
    226       if(empty($errors)) { 
    227         $c['main'] .= "<p>Update erfolgreich, <a href='../'>Viel Spaß</a>!</p>"; 
    228       } 
    229       else { 
    230         $c['main'] .= '<p>Das Update wurde durchgefÃŒhrt, allerdings sind folgende Probleme aufgetreten:</p><ul>'; 
    231         foreach($errors as $error) { 
    232           $c['main'] .= '<li>'.htmlspecialchars($error).'</li>'; 
    233         } 
    234         $c['main'] .= '</ul><p>Sie können versuchen diese Schritte von Hand nachzuvollziehen. <a href="../">Zur Startseite</a></p>'; 
    235       } 
    236     } 
    237     else { 
    238       $c['main'] .= '<p>Fehler beim Update:</p><ul class="error">'; 
    239       foreach($errors as $error) { 
    240         $c['main'] .= '<li>'.htmlspecialchars($error).'</li>'; 
    241       } 
    242       $c['main'] .= '</ul><p><a href="">Erneut versuchen</a></p>'; 
    243     } 
     112            // Fertig :-) 
     113            require(JLOG_BASEPATH."scripts".DIRECTORY_SEPARATOR."update.php"); 
     114    
     115            if(empty($update_errors)) { 
     116              $c['main'] .= "<p>Update erfolgreich, <a href='../'>Viel Spaß</a>!</p>"; 
     117            } 
     118            else { 
     119                $c['main'] .= error_output($update_errors, "", "Das Update wurde durchgefÃŒhrt, allerdings sind folgende Probleme aufgetreten"); 
     120              $c['main'] .= '<p>Sie können versuchen diese Schritte von Hand nachzuvollziehen. <a href="../">Zur Startseite</a></p>'; 
     121            } 
     122          } 
     123          else { 
     124         $c['main'] .= error_output($update_errors, "", "Fehler beim Update"); 
     125            $c['main'] .= '<p><a href="">Erneut versuchen</a></p>'; 
     126          } 
     127        } 
    244128  } 
    245129 
  • trunk/scripts/general.func.php

    r1688 r1711  
    100100} 
    101101// Fehler ausgeben 
    102 function error_output($errors, $id = "") { 
     102function error_output($errors, $id = "", $headline = false) { 
    103103global $l; 
    104         $error = ""; 
    105         if(isset($errors)) { 
    106          $error = "\n<h3 id='".$id."' class='error'>".$l['error']."</h3>\n <ul class='error'>\n"; 
    107           foreach($errors AS $f) $error .= "  <li>".$f."</li>\n"; 
    108         $error .= " </ul>\n"; 
     104        $error = ""; 
     105        if($headline === false) $headline = $l["error"]; 
     106        if(isset($errors)) { 
     107                if(strlen($headline) > 0) $error = "\n<h3 id='".$id."' class='error'>".$headline."</h3>"; 
     108                $error .= "\n <ul class='error'>\n"; 
     109                foreach($errors AS $f) $error .= "  <li>".$f."</li>\n"; 
     110                $error .= " </ul>\n"; 
    109111   } 
    110112 return $error; 
  • trunk/scripts/prepend.inc.php

    r1709 r1711  
    77  
    88// redirect to update-script if new jlog version was installed 
    9 if(!defined('JLOG_INSTALLED_VERSION') OR version_compare(JLOG_INSTALLED_VERSION, JLOG_SOFTWARE_VERSION, '<')) { 
    10   if(dirname($_SERVER['PHP_SELF']) !== "/") $dir = dirname($_SERVER['PHP_SELF']); 
    11   header("Location: http://".$_SERVER['HTTP_HOST'].$dir."/admin/update.php"); 
    12   exit; 
     9if((!defined('JLOG_INSTALLED_VERSION') OR version_compare(JLOG_INSTALLED_VERSION, JLOG_SOFTWARE_VERSION, '<')) 
     10        AND "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"] != JLOG_PATH."/admin/update.php") { 
     11 
     12        header("Location: ".JLOG_PATH."/admin/update.php"); 
     13        exit; 
    1314} 
    1415 
     
    5859    
    5960// eof 
     61?> 
  • trunk/scripts/version.inc.php

    r1710 r1711  
    1111 
    1212// EOF 
     13?>