Changeset 1761
- Timestamp:
- 09/30/2008 04:00:27 PM (2 months ago)
- Files:
-
- trunk/admin/settings.php (modified) (2 diffs)
- trunk/scripts/JlogUpdater.php (modified) (1 diff)
- trunk/scripts/settings.class.php (modified) (18 diffs)
- trunk/setup.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/admin/settings.php
r1731 r1761 12 12 $settings = new Settings($l); 13 13 if($_POST) { 14 $settings-> get_userdata(strip($_POST));14 $settings->importDataByArray(strip($_POST)); 15 15 if(count($errors = $settings->validate()) == 0) { 16 16 if(count($errors = $settings->do_settings()) == 0) { … … 25 25 } 26 26 else { 27 $settings-> get_data();27 $settings->importDataByConstants(); 28 28 $c['main'] .= $settings->form_output(); 29 29 } trunk/scripts/JlogUpdater.php
r1751 r1761 124 124 // read current settings from environment and POSTed data 125 125 $update = new Settings($l); 126 $update-> get_data();126 $update->importDataByConstants(); 127 127 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); 132 132 133 133 // rewrite settings.inc.php trunk/scripts/settings.class.php
r1760 r1761 69 69 70 70 /** 71 * put_data() - reads configuration data71 * getValue() - reads configuration data 72 72 * 73 73 * This procedure returns the value for then configuration option … … 79 79 * @return mixed 80 80 */ 81 function put_data($key = false) {81 function getValue($key = false) { 82 82 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 88 102 * 89 103 * @access public 90 104 * @return void 91 105 */ 92 function get_data() {106 function importDataByConstants() { 93 107 # no return 94 108 // this is a blacklist of constats which are not to be written in settings.inc.php … … 113 127 foreach($constants as $key => $value) { 114 128 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); 119 130 } 120 131 } … … 122 133 123 134 /** 124 * get_userdata() - sets configuration data135 * importDataByArray() - sets configuration data 125 136 * 126 137 * Sets configuration data according to $d. If working in … … 134 145 * @return void 135 146 */ 136 function get_userdata($d = false, $exclusiv = false) {147 function importDataByArray($d = false, $exclusiv = false) { 137 148 138 149 // get the data from users $d array and put it into the class … … 168 179 } 169 180 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)) 172 182 { 173 183 $this->d['jlog_installed_version'] = JLOG_SOFTWARE_VERSION; … … 179 189 180 190 /** 181 * get_suggestiondata() - preallocates configuration data191 * importSuggestedData() - preallocates configuration data 182 192 * 183 193 * Initialises the configuration with useful settings during … … 187 197 * @return void 188 198 */ 189 function get_sugestiondata() {199 function importSuggestedData() { 190 200 191 201 // suggest some data for setup 192 $this->d['jlog_path'] = $this->get _suggest_path();202 $this->d['jlog_path'] = $this->getSuggestPath(); 193 203 $this->d['jlog_basepath'] = dirname(dirname( __FILE__ )).DIRECTORY_SEPARATOR; 194 204 $date = getdate(); … … 205 215 $this->d['jlog_db_prefix'] = 'jlog_'; 206 216 $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_PATH217 $this->d['jlog_language'] = defined('JLOG_LANGUAGE') ? JLOG_LANGUAGE : 'de'; 218 } 219 220 221 /** 222 * getSuggestPath() - generate a suggestion for JLOG_PATH 213 223 * 214 224 * @access private 215 225 * @return string 216 226 */ 217 function get _suggest_path() {227 function getSuggestPath() { 218 228 $host = empty($_SERVER['HTTP_HOST']) 219 229 ? (empty($_SERVER['SERVER_NAME']) … … 238 248 239 249 /** 240 * get_value() - gets a value of an array250 * defaultValue() - gets a value of an array 241 251 * 242 252 * Look for index $key in the array $array and return … … 250 260 * @return mixed 251 261 */ 252 function get_value($array, $key, $default = '') {262 function defaultValue($array, $key, $default = '') { 253 263 254 264 if(isset($array[$key])) { 255 return stripslashes($array[$key]);265 return $array[$key]; 256 266 } 257 267 else { … … 313 323 314 324 <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> 316 326 <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> 318 328 <p><label for='admin_password'>".$this->l['admin']['m_admin_password'].$admincenter_password."</label><br /> 319 329 <input class='userdata' id='admin_password' name='jlog_admin_password' type='password' size='20' maxlength='255' /></p> … … 321 331 <input class='userdata' id='admin_password_again' name='jlog_admin_password_again' type='password' size='20' maxlength='255' /></p> 322 332 <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> 324 334 <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> 326 336 </fieldset> 327 337 … … 331 341 <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> 332 342 <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> 334 344 <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> 336 346 <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> 338 348 <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> 340 350 <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> 341 351 <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> 345 355 <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> 347 357 </fieldset> 348 358 "; … … 353 363 <fieldset><legend>".$this->l['admin']['m_database']."</legend> 354 364 <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> 356 366 <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> 358 368 <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> 360 370 <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> 362 372 <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')."' /> 367 377 </fieldset> 368 378 "; … … 449 459 450 460 // 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; 452 462 453 463 // 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'], '/'); 456 466 457 467 // no quotes for bolean and numbers … … 467 477 468 478 // 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; 470 480 471 481 foreach($this->d as $key => $value) { 472 unset($q, $s, $s2);473 if(!in_array($key, $no_quotes)) $q = "'";474 482 $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 } 480 494 } 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'; 485 503 486 504 // write to settings.inc.php … … 491 509 return $errors; 492 510 } 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 } 493 529 } 494 530 trunk/setup.php
r1736 r1761 56 56 57 57 if($_POST) { 58 $setup-> get_userdata(strip($_POST));58 $setup->importDataByArray(strip($_POST)); 59 59 60 60 // validate user entry 61 61 if(count($errors = $setup->validate()) == 0) { 62 define("JLOG_BASEPATH", $setup-> put_data('basepath'));62 define("JLOG_BASEPATH", $setup->getValue('jlog_basepath')); 63 63 if(is_writable(JLOG_BASEPATH.'personal'.DIRECTORY_SEPARATOR)) { 64 64 $c .= "<ul>\n"; 65 65 66 66 // 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) { 68 68 $c .= "<li>".$l['admin']['s_tables_ok']."</li>\n"; 69 69 … … 96 96 if(empty($errors)) { 97 97 // output form 98 $setup-> get_sugestiondata();98 $setup->importSuggestedData(); 99 99 $c .= $setup->form_output(); 100 100 }
