Changeset 1761

Show
Ignore:
Timestamp:
09/30/2008 04:00:27 PM (2 months ago)
Author:
driehle
Message:

Draft for #199 and #201

Files:

Legend:

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

    r1731 r1761  
    1212 $settings = new Settings($l); 
    1313 if($_POST) { 
    14   $settings->get_userdata(strip($_POST)); 
     14  $settings->importDataByArray(strip($_POST)); 
    1515  if(count($errors = $settings->validate()) == 0) { 
    1616   if(count($errors = $settings->do_settings()) == 0) { 
     
    2525 } 
    2626 else { 
    27   $settings->get_data(); 
     27  $settings->importDataByConstants(); 
    2828  $c['main'] .= $settings->form_output(); 
    2929 } 
  • trunk/scripts/JlogUpdater.php

    r1751 r1761  
    124124            // read current settings from environment and POSTed data 
    125125            $update = new Settings($l); 
    126             $update->get_data(); 
     126            $update->importDataByConstants(); 
    127127             
    128             $update->d['jlog_installed_version'] = $newver
    129         $update->d['jlog_installed_url'] = $newver
    130         $update->d['jlog_installed_phpv'] = $newver
    131         $update->d['jlog_installed_mysqlv'] = $newver
     128            $update->setValue('jlog_installed_version', $newver)
     129        $update->setValue('jlog_installed_url', JLOG_SOFTWARE_URL)
     130        $update->setValue('jlog_installed_phpv', JLOG_SOFTWARE_PHPV)
     131        $update->setValue('jlog_installed_mysqlv', JLOG_SOFTWARE_MYSQLV)
    132132    
    133133            // rewrite settings.inc.php 
  • trunk/scripts/settings.class.php

    r1760 r1761  
    6969 
    7070  /** 
    71    * put_data() - reads configuration data 
     71   * getValue() - reads configuration data 
    7272   *  
    7373   * This procedure returns the value for then configuration option 
     
    7979   * @return mixed 
    8080   */ 
    81   function put_data($key = false) { 
     81  function getValue($key = false) { 
    8282    if($key === false) return $this->d; 
    83     else return $this->d[$key]; 
    84   } 
    85  
    86   /** 
    87    * Enter description here... 
     83    else return $this->d[strtolower($key)]; 
     84  } 
     85   
     86  /** 
     87   * setValue() - sets configuration data 
     88   * 
     89   * @access public 
     90   * @param string|boolean $key 
     91   * @param mixed $value       
     92   * @return mixed 
     93   */ 
     94  function setValue($key, $value) { 
     95    $this->d[strtolower($key)] = $value; 
     96  } 
     97 
     98  /** 
     99   * importDataByConstants() 
     100   *  
     101   * imports data from global constats starting with JLOG_ prefix       
    88102   * 
    89103   * @access public 
    90104   * @return void 
    91105   */ 
    92   function get_data() { 
     106  function importDataByConstants() { 
    93107    # no return 
    94108    // this is a blacklist of constats which are not to be written in settings.inc.php 
     
    113127    foreach($constants as $key => $value) { 
    114128      if(!in_array($key, $search) AND strpos($key, "JLOG_") !== false) { 
    115         $key = strtolower($key); 
    116         // we used stripslashes() on the value here before, which caused 
    117         // problems under windows, as C:\Path\Folder becomes C:PathFolder 
    118         $this->d[$key] = $value; 
     129        $this->setValue($key, $value); 
    119130      } 
    120131    } 
     
    122133 
    123134  /** 
    124    * get_userdata() - sets configuration data 
     135   * importDataByArray() - sets configuration data 
    125136   *  
    126137   * Sets configuration data according to $d. If working in 
     
    134145   * @return void 
    135146   */ 
    136   function get_userdata($d = false, $exclusiv = false) { 
     147  function importDataByArray($d = false, $exclusiv = false) { 
    137148 
    138149    // get the data from users $d array and put it into the class 
     
    168179    } 
    169180 
    170     if((defined('JLOG_SETUP') AND JLOG_SETUP === true)  
    171     OR (defined('JLOG_UPDATE') AND JLOG_UPDATE === true))  
     181    if((defined('JLOG_SETUP') AND JLOG_SETUP === true))  
    172182    { 
    173183      $this->d['jlog_installed_version'] = JLOG_SOFTWARE_VERSION; 
     
    179189 
    180190  /** 
    181    * get_suggestiondata() - preallocates configuration data 
     191   * importSuggestedData() - preallocates configuration data 
    182192   *  
    183193   * Initialises the configuration with useful settings during 
     
    187197   * @return void 
    188198   */ 
    189   function get_sugestiondata() { 
     199  function importSuggestedData() { 
    190200 
    191201    // suggest some data for setup 
    192     $this->d['jlog_path'] = $this->get_suggest_path(); 
     202    $this->d['jlog_path'] = $this->getSuggestPath(); 
    193203    $this->d['jlog_basepath'] = dirname(dirname( __FILE__ )).DIRECTORY_SEPARATOR; 
    194204    $date = getdate(); 
     
    205215    $this->d['jlog_db_prefix'] = 'jlog_'; 
    206216    $this->d['jlog_blogservices'] = 'http://rpc.pingomatic.com/'; 
    207     $this->d['jlog_language'] = JLOG_LANGUAGE
    208   } 
    209  
    210  
    211   /** 
    212    * get_suggest_path() - generate a suggestion for JLOG_PATH 
     217    $this->d['jlog_language'] = defined('JLOG_LANGUAGE') ? JLOG_LANGUAGE : 'de'
     218  } 
     219 
     220 
     221  /** 
     222   * getSuggestPath() - generate a suggestion for JLOG_PATH 
    213223   * 
    214224   * @access private 
    215225   * @return string 
    216226   */ 
    217   function get_suggest_path() { 
     227  function getSuggestPath() { 
    218228    $host  = empty($_SERVER['HTTP_HOST']) 
    219229              ? (empty($_SERVER['SERVER_NAME']) 
     
    238248 
    239249  /** 
    240    * get_value() - gets a value of an array 
     250   * defaultValue() - gets a value of an array 
    241251   *  
    242252   * Look for index $key in the array $array and return 
     
    250260   * @return mixed 
    251261   */ 
    252   function get_value($array, $key, $default = '') { 
     262  function defaultValue($array, $key, $default = '') { 
    253263 
    254264    if(isset($array[$key])) { 
    255       return stripslashes($array[$key])
     265      return $array[$key]
    256266    } 
    257267    else { 
     
    313323        
    314324       <p><label for='website'>".$this->l['admin']['m_website']."</label><br /> 
    315           <input class='userdata' id='website' name='jlog_website' type='text' size='20' maxlength='255' value='".$this->get_value($data, 'jlog_website')."' /></p> 
     325          <input class='userdata' id='website' name='jlog_website' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_website')."' /></p> 
    316326       <p><label for='publisher'>".$this->l['admin']['m_publisher']."</label><br /> 
    317           <input class='userdata' id='publisher' name='jlog_publisher' type='text' size='20' maxlength='255' value='".$this->get_value($data, 'jlog_publisher')."' /></p> 
     327          <input class='userdata' id='publisher' name='jlog_publisher' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_publisher')."' /></p> 
    318328       <p><label for='admin_password'>".$this->l['admin']['m_admin_password'].$admincenter_password."</label><br /> 
    319329          <input class='userdata' id='admin_password' name='jlog_admin_password' type='password' size='20' maxlength='255' /></p> 
     
    321331          <input class='userdata' id='admin_password_again' name='jlog_admin_password_again' type='password' size='20' maxlength='255' /></p> 
    322332       <p><label for='email'>".$this->l['admin']['m_email']."</label><br /> 
    323           <input class='userdata' id='email' name='jlog_email' type='text' size='20' maxlength='255' value='".$this->get_value($data, 'jlog_email')."' /></p> 
     333          <input class='userdata' id='email' name='jlog_email' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_email')."' /></p> 
    324334       <p><label for='description'>".$this->l['admin']['m_description']."</label><br /> 
    325           <textarea class='small' id='description' name='jlog_description' rows='2' cols='60'>".$this->get_value($data, 'jlog_description')."</textarea></p> 
     335          <textarea class='small' id='description' name='jlog_description' rows='2' cols='60'>".$this->defaultValue($data, 'jlog_description')."</textarea></p> 
    326336      </fieldset> 
    327337 
     
    331341          <input id='clean_url_no' name='jlog_clean_url' type='radio' value='false'".$d['clean_url_no']." /><label class='nobreak' for='clean_url_no'>".$this->l['admin']['no']."</label></p> 
    332342       <p><label for='max_blog_orginal'>".$this->l['admin']['m_max_blog_orginal']."</label><br /> 
    333           <input class='short' id='max_blog_orginal' name='jlog_max_blog_orginal' type='text' maxlength='3' size='3' value='".$this->get_value($data, 'jlog_max_blog_orginal')."' /></p> 
     343          <input class='short' id='max_blog_orginal' name='jlog_max_blog_orginal' type='text' maxlength='3' size='3' value='".$this->defaultValue($data, 'jlog_max_blog_orginal')."' /></p> 
    334344       <p><label for='max_blog_big'>".$this->l['admin']['m_max_blog_big']."</label><br /> 
    335           <input class='short' id='max_blog_big' name='jlog_max_blog_big' type='text' size='3' maxlength='3' value='".$this->get_value($data, 'jlog_max_blog_big')."' /></p> 
     345          <input class='short' id='max_blog_big' name='jlog_max_blog_big' type='text' size='3' maxlength='3' value='".$this->defaultValue($data, 'jlog_max_blog_big')."' /></p> 
    336346       <p><label for='max_blog_small'>".$this->l['admin']['m_max_blog_small']."</label><br /> 
    337           <input class='short' id='max_blog_small' name='jlog_max_blog_small' type='text' size='3' maxlength='3' value='".$this->get_value($data, 'jlog_max_blog_small')."' /></p> 
     347          <input class='short' id='max_blog_small' name='jlog_max_blog_small' type='text' size='3' maxlength='3' value='".$this->defaultValue($data, 'jlog_max_blog_small')."' /></p> 
    338348       <p><label for='sub_current'>".$this->l['admin']['m_sub_current']."</label><br /> 
    339           <input class='short' id='sub_current' name='jlog_sub_current' type='text' size='3' maxlength='3' value='".$this->get_value($data, 'jlog_sub_current')."' /></p> 
     349          <input class='short' id='sub_current' name='jlog_sub_current' type='text' size='3' maxlength='3' value='".$this->defaultValue($data, 'jlog_sub_current')."' /></p> 
    340350       <p><input id='info_by_comment' name='jlog_info_by_comment' type='checkbox' value='true'".$d['info_by_comment']."/> <label for='info_by_comment' class='nobreak'>".$this->l['admin']['m_info_by_comment']."</label></p> 
    341351       <p><label for='date'>".$this->l['admin']['m_date']."</label></p> 
    342        <p><input class='userdata' id='date' name='jlog_date' type='text' value='".$this->get_value($data, 'jlog_date')."' size='20' /> <label for='date' class='nobreak'>".$this->l['admin']['m_date_posting']."</label></p> 
    343        <p><input class='userdata' id='date_comment' name='jlog_date_comment' type='text' value='".$this->get_value($data, 'jlog_date_comment')."' size='20' /> <label for='date_comment' class='nobreak'>".$this->l['admin']['m_date_comment']."</label></p> 
    344        <p><input class='userdata' id='date_subcurrent' name='jlog_date_subcurrent' type='text' value='".$this->get_value($data, 'jlog_date_subcurrent')."' size='20' /> <label for='date_subcurrent' class='nobreak'>".$this->l['admin']['m_date_subcurrent']."</label></p> 
     352       <p><input class='userdata' id='date' name='jlog_date' type='text' value='".$this->defaultValue($data, 'jlog_date')."' size='20' /> <label for='date' class='nobreak'>".$this->l['admin']['m_date_posting']."</label></p> 
     353       <p><input class='userdata' id='date_comment' name='jlog_date_comment' type='text' value='".$this->defaultValue($data, 'jlog_date_comment')."' size='20' /> <label for='date_comment' class='nobreak'>".$this->l['admin']['m_date_comment']."</label></p> 
     354       <p><input class='userdata' id='date_subcurrent' name='jlog_date_subcurrent' type='text' value='".$this->defaultValue($data, 'jlog_date_subcurrent')."' size='20' /> <label for='date_subcurrent' class='nobreak'>".$this->l['admin']['m_date_subcurrent']."</label></p> 
    345355       <p><label for='blogservices'>".$this->l['admin']['m_bs']."</label></p> 
    346        <p><textarea class='small' id='blogservices' name='jlog_blogservices' rows='2' cols='60'>".$this->get_value($data, 'jlog_blogservices')."</textarea></p> 
     356       <p><textarea class='small' id='blogservices' name='jlog_blogservices' rows='2' cols='60'>".$this->defaultValue($data, 'jlog_blogservices')."</textarea></p> 
    347357      </fieldset> 
    348358     "; 
     
    353363      <fieldset><legend>".$this->l['admin']['m_database']."</legend> 
    354364       <p><label for='db'>".$this->l['admin']['m_db']."</label><br /> 
    355           <input class='userdata' id='db' name='jlog_db' type='text' size='20' maxlength='255' value='".$this->get_value($data, 'jlog_db')."' /></p> 
     365          <input class='userdata' id='db' name='jlog_db' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db')."' /></p> 
    356366       <p><label for='db_url'>".$this->l['admin']['m_db_url']."</label><br /> 
    357           <input class='userdata' id='db_url' name='jlog_db_url' type='text' size='20' maxlength='255' value='".$this->get_value($data, 'jlog_db_url')."' /></p> 
     367          <input class='userdata' id='db_url' name='jlog_db_url' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db_url')."' /></p> 
    358368       <p><label for='db_user'>".$this->l['admin']['m_db_user']."</label><br /> 
    359           <input class='userdata' id='db_user' name='jlog_db_user' type='text' size='20' maxlength='255' value='".$this->get_value($data, 'jlog_db_user')."' /></p> 
     369          <input class='userdata' id='db_user' name='jlog_db_user' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db_user')."' /></p> 
    360370       <p><label for='db_pwd'>".$this->l['admin']['m_db_pwd']."</label><br /> 
    361           <input class='userdata' id='db_pwd' name='jlog_db_pwd' type='password' size='20' maxlength='255' value='".$this->get_value($data, 'jlog_db_pwd')."' /></p> 
     371          <input class='userdata' id='db_pwd' name='jlog_db_pwd' type='password' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db_pwd')."' /></p> 
    362372       <p><label for='db_prefix'>".$this->l['admin']['m_db_prefix']."</label><br /> 
    363           <input class='userdata' id='db_prefix' name='jlog_db_prefix' type='text' size='20' maxlength='255' value='".$this->get_value($data, 'jlog_db_prefix')."' /> 
    364           <input name='jlog_start_year' type='hidden' value='".$this->get_value($data, 'jlog_start_year', date("Y"))."' /></p> 
    365           <input name='jlog_path' type='hidden' value='".$this->get_value($data, 'jlog_path')."' /> 
    366           <input name='jlog_basepath' type='hidden' value='".$this->get_value($data, 'jlog_basepath')."' /> 
     373          <input class='userdata' id='db_prefix' name='jlog_db_prefix' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db_prefix')."' /> 
     374          <input name='jlog_start_year' type='hidden' value='".$this->defaultValue($data, 'jlog_start_year', date("Y"))."' /></p> 
     375          <input name='jlog_path' type='hidden' value='".$this->defaultValue($data, 'jlog_path')."' /> 
     376          <input name='jlog_basepath' type='hidden' value='".$this->defaultValue($data, 'jlog_basepath')."' /> 
    367377      </fieldset> 
    368378     "; 
     
    449459 
    450460    // if there is no new password set the old 
    451     if(JLOG_ADMIN AND empty($this->d['jlog_admin_password'])) $this->d['jlog_admin_password'] = $this->jlog_admin_password
     461    if(JLOG_ADMIN AND empty($this->d['jlog_admin_password'])) $this->d['jlog_admin_password'] = JLOG_ADMIN_PASSWORD
    452462 
    453463    // erase last slashes 
    454     if(strrpos($this->d['jlog_path'], "/") == strlen($this->d['jlog_path'])-1) $this->d['jlog_path'] = substr($this->d['jlog_path'], 0, strrpos($this->d['jlog_path'], "/")); 
    455     if(strrpos($this->d['jlog_basepath'], DIRECTORY_SEPARATOR) != strlen($this->d['jlog_basepath'])-1) $this->d['jlog_basepath'] = $this->d['jlog_basepath'].DIRECTORY_SEPARATOR
     464    $this->d['jlog_path'] = trim($this->d['jlog_path'], '/'); 
     465    $this->d['jlog_basepath'] = trim($this->d['jlog_basepath'], '/')
    456466 
    457467    // no quotes for bolean and numbers 
     
    467477 
    468478    // serialize data to file format 
    469     $file_content = "<?php\n//generated at " . date('Y-m-d, h:i:s') . "\n"
     479    $file_content = '<?php' . PHP_EOL . '// generated at ' . date('Y-m-d, h:i:s') . PHP_EOL
    470480 
    471481    foreach($this->d as $key => $value) { 
    472       unset($q, $s, $s2); 
    473       if(!in_array($key, $no_quotes)) $q = "'"; 
    474482      $key = strtoupper($key); 
    475  
    476       // bolean 
    477       if($key == 'JLOG_CLEAN_URL' OR $key == 'JLOG_INFO_BY_COMMENT') { 
    478         if($value == 'true' OR $value === true) $value = "true"; 
    479         else $value = 'false'; 
     483      $output = ''; 
     484      if(!in_array($key, $no_quotes)) { 
     485        // boolean values 
     486        if($key == 'JLOG_CLEAN_URL' OR $key == 'JLOG_INFO_BY_COMMENT') { 
     487          if($value == 'true' OR $value === true) $output = 'true'; 
     488          else $output = 'false'; 
     489        } 
     490        // numeric values 
     491        else { 
     492          $output = (int) $value; 
     493        } 
    480494      } 
    481       $file_content .= " define('".$key."', ".$q.addslashes($value).$q.");\n"; 
    482     } 
    483  
    484     $file_content .= "\n// eof"; 
     495      // string values 
     496      else { 
     497        $output = '"' . $this->escapeForPhp($value) . '"'; 
     498      } 
     499      $file_content .= 'define("' . $key . '", ' . $output . ');' . PHP_EOL; 
     500    } 
     501 
     502    $file_content .= '// eof'; 
    485503 
    486504    // write to settings.inc.php 
     
    491509    return $errors; 
    492510  } 
     511   
     512  /** 
     513   * escapeForPhp() 
     514   *  
     515   * escapes $value so that it can be used between double quotes in a 
     516   * PHP script    
     517   * 
     518   * @access public 
     519   * @param string $value    
     520   * @return string 
     521   */ 
     522  function escapeForPhp($value) { 
     523    $value = str_replace("\0", '\0', $value); 
     524    $value = str_replace("\r", '\r', $value); 
     525    $value = str_replace("\n", '\n', $value); 
     526    $value = str_replace('"',  '\"', $value); 
     527    return $value; 
     528  } 
    493529} 
    494530 
  • trunk/setup.php

    r1736 r1761  
    5656 
    5757 if($_POST) { 
    58   $setup->get_userdata(strip($_POST)); 
     58  $setup->importDataByArray(strip($_POST)); 
    5959 
    6060  // validate user entry 
    6161  if(count($errors = $setup->validate()) == 0) { 
    62    define("JLOG_BASEPATH", $setup->put_data('basepath')); 
     62   define("JLOG_BASEPATH", $setup->getValue('jlog_basepath')); 
    6363   if(is_writable(JLOG_BASEPATH.'personal'.DIRECTORY_SEPARATOR)) { 
    6464     $c .= "<ul>\n"; 
    6565      
    6666     // build some MySQL tables 
    67      if(count($errors = create_mysql_tables($setup->put_data(false))) == 0) { 
     67     if(count($errors = create_mysql_tables($setup->getValue(false))) == 0) { 
    6868      $c .= "<li>".$l['admin']['s_tables_ok']."</li>\n"; 
    6969 
     
    9696  if(empty($errors)) { 
    9797   // output form 
    98    $setup->get_sugestiondata(); 
     98   $setup->importSuggestedData(); 
    9999   $c .= $setup->form_output(); 
    100100  }