config.php
来自「一款基于PHP的网络日记程序。WikyBlog支持:多用户的 BLOG」· PHP 代码 · 共 461 行
PHP
461 行
<?php/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// configuration class//defined('WikyBlog') or die("Not an entry point...");if( $_SESSION['userlevel'] !== 4){ global $page; $page->contentA['Admin Only'] = 'You must be an administrator to access this page.'; return;}wbLang::getFile('specPreferences'); //has similar fields like language valuesclass configuration{ var $current; var $possible; var $checkSum; var $currRevision; function configuration($arg){ global $lang,$page; if( $arg === false){ return; } ob_start(); switch($arg){ case wbStrtolower($lang['save']): $this->saveConfig($_POST); break; case 'revert': $this->setFromRevision(); $this->showConfigForm(); break; case 'show': default: $this->showConfigForm(); break; } $page->contentA[$lang['configuration']] = wb::get_clean(); } function setFromRevision(){ global $wbTables; if( empty($_GET['revision']) ){ message('Cannot revert to an unspecified revision.'); return; } if( !is_numeric($_GET['revision']) ){ message('Revision was not a number.'); return; } message('CONFIG_CONFIRM_REVERT',$_GET['revision']); $_GET['revision'] = (int)$_GET['revision']; $query = 'SELECT revision, data FROM '.$wbTables['config'].' WHERE revision = '.$_GET['revision']; $result = wbDB::runQuery($query); $row = mysql_fetch_assoc($result); $this->current = unserialize($row['data']); $this->currRevision = $row['revision']; $this->checkSum = crc32($row['data']); $_POST['summary'] = 'Reverted to revision number '.$_GET['revision']; } function setCurrentConfig(){ global $wbTables; if( !empty($this->current) ){ return; } $query = 'SELECT revision, data FROM '.$wbTables['config'].' ORDER BY revision DESC LIMIT 1'; $result = wbDB::runQuery($query); $row = mysql_fetch_assoc($result); $this->current = unserialize($row['data']); $this->currRevision = $row['revision']; $this->checkSum = crc32($row['data']); if( empty($this->current['wbConfig']['allUsers']) ){ $this->current['wbConfig']['allUsers'] = 'On'; } if( !isset($this->current['wbConfig']['sesslevel']) ){ $this->current['wbConfig']['sesslevel'] = '2'; } if( !isset($this->current['defaultUser']['pTemplate']) ){ $this->current['defaultUser']['pTemplate'] = 'default/blue'; unset($this->current['defaultUser']['template']); } } /////////////////////////////////////////////////////////////// // Possible values // array(On/Off) // function setPossibleValues(){ global $lang,$includeDir; if( !empty($this->possible) ){ return; } $array = array(); $this->possible =& $array; $array['general_config'] = null; $array['serverName1'] = ''; $array['serverName2'] = ''; //used just for emailing now $array['serverName3'] = ''; $array['userLanguage'] = array(); //will be set lower $array['performance'] = null; $array['include'] = ''; $array['googleMapsKey'] = ''; $array['reservedWords'] = ''; $array['wbConfig']['pUser'] = ''; $array['wbConfig']['online'] = array('On'=>$lang['on'],'Off'=>$lang['off']); $array['wbConfig']['floodInterval'] = ''; $array['wbConfig']['ajax'] = array('On'=>$lang['on'],'Partial'=>$lang['partial'],'Off'=>$lang['off']); $array['wbConfig']['tidy'] = array('On'=>$lang['on'],'Off'=>$lang['off']); $array['wbConfig']['allUsers'] = array('On'=>$lang['on'],'Off'=>$lang['off']); $array['wbConfig']['interHelp'] = array('On'=>$lang['on'],'Off'=>$lang['off']); $array['wbConfig']['sesslevel'] = array('1'=>'123.123.123','2'=>'123.123','3'=>'123'); // //Default User // $array['default_user_vars'] = null; $array['defaultUser']['homeTitle'] = ''; //$array['defaultUser']['template'] = ''; //taken out because we are using the /themes directory now $array['defaultUser']['textareaY'] = ''; $array['defaultUser']['isBlog'] = array('On'=>$lang['on'],'Off'=>$lang['off']); $array['defaultUser']['timezone'] = ''; $array['defaultUser']['ajax'] = array('On'=>$lang['on'],'Partial'=>$lang['partial'],'Off'=>$lang['off']); $array['defaultUser']['maxHistory'] = ''; includeFile('themes/data.php'); $themes = returnThemeData(); $array['defaultUser']['pTemplate'] = array(); foreach($themes as $theme => $colors){ $group = $theme; foreach($colors as $color => $temp){ if( $color == 'html'){ continue; } $full = $theme.'/'.$color; $array['defaultUser']['pTemplate'][$full] = $full; } } $array['disk_usage'] = null; $array['maxUserDiskUsage'] = ''; $array['maxHistory'] = ''; $array['max_upload'] = ''; //administrators might want to see errors on their distributed system $array['developer_aids'] = null; $array['maxErrorFileSize'] = ''; $array['errorEmail'] = ''; //Language packages $langDir = $includeDir.'/lang'; if ($dh = @opendir($langDir)) { while (($file = readdir($dh)) !== false){ if( strpos($file,'.') === 0){ continue; } if( strpos($file,'x_') === 0){ continue; } $fullPath = $langDir.'/'.$file; if( !is_dir($fullPath) ){ continue; } $array['userLanguage'][$file] = $lang['lang'][$file]; } closedir($dh); } } // User supplied values must within the guides provided in setPossibleValues() // function saveConfig(&$newValues){ global $wbTables; $this->setPossibleValues(); $this->setCurrentConfig(); $this->setArray($this->current,$this->possible,$newValues); //Move Version value $insert['version'] = $GLOBALS['wbConfig']['version']; unset($this->current['wbConfig']['version']);//Version 0.9 .. later this won't be needed $insert['data'] = serialize($this->current); $insert['summary'] = $_POST['summary']; $insert['username'] = $_SESSION['username']; //Changed?? $newCheck = crc32($insert['data']); if( $newCheck === $this->checkSum){ message('The configuration has not changed.'); $this->showConfigForm(); return; } //!! this is a copy of what's at adminDbInfo.php.. should just be the same script! //Insert $query = 'INSERT INTO '.$wbTables['config'].' SET '; $query .= wbDB::toSet($insert,true); //message($query); wbDB::runQuery($query); $num = mysql_affected_rows(); if( $num < 1){ message('<b>Warning</b> This configuration was not saved.'); $this->showConfigForm(); }else{ message('Your configuration has been saved.'); } } function setArray(&$current,&$possible,&$new){ // reset $current with $new if within $possible // foreach($new as $newKey => $newValue){ if( !isset($possible[$newKey]) ){ continue; }elseif( is_array($newValue) && is_array($current[$newKey]) ){ $this->setArray($current[$newKey],$possible[$newKey],$newValue); continue; }elseif( is_array($newValue) || (isset($current[$newKey]) &&is_array($current[$newKey])) ){ continue; }elseif( is_array($possible[$newKey]) && count($possible[$newKey]) > 0 ){ if( !isset($possible[$newKey][$newValue]) ){ continue;//otherwise I would be setting a value that the user didn't choose.. //$newValue = key($possible[$newKey]); } //message('Possible is set for '.$newKey.'::'.$newValue.showArray($possible[$newKey])); }else{ //message('<b>Warning:</b> Value is unchecked: '.$newKey); } $current[$newKey] = $newValue; } } function showConfigForm(){ global $page,$lang; $this->setPossibleValues(); $this->setCurrentConfig(); $_POST += array('summary'=>''); echo '<br/>'; arrayToForm($this->current,$this->possible,$lang); echo '<fieldset style="text-align:center;padding:9px" class="row2">'; echo ' <input value="'.$lang['save'].'" type="submit" name="cmd" accesskey="s" />'; echo ' <input value="'.$lang['reset'].'" type="reset" /> '; echo $lang['edit_summary'].': <input value="'.$_POST['summary'].'" type="text" name="summary" size="60" maxlength="200" />'; echo '<p class="sm">'; echo $lang['CONFIG_SAVING']; echo '<br/>'; //echo wbLang::text('CONFIG_STAT',$this->currRevision); //not correct when reverting.. echo '</p>'; echo '</fieldset>'; }}//// configuration class///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Form Functions//function arrayToForm($values,&$possible,&$langLocal,$inputName=null){ global $lang; $i = 0; foreach($possible as $possKey => $possValue){ $availFeature = true; if( !isset($values[$possKey]) ){ $values[$possKey] = null; } if( is_array($values[$possKey]) && is_array($possValue) ){ arrayToForm($values[$possKey],$possValue,$langLocal[$possKey],$possKey); continue; }elseif( is_array($values[$possKey]) ){ trigger_error('config error with possible values.'); continue; } if( is_null($possValue) && is_null($inputName) ){ if( $i !== 0){ echo '</table></fieldset>'; } echo "\n".'<fieldset>'; echo '<legend>'.$langLocal[$possKey].'</legend>'; echo '<table width="100%" cellpadding="4">'; continue; } //Is Tidy Available if( ($possKey == 'tidy') && !function_exists('tidy_load_config')){ $availFeature = false; } echo "\n\n".'<tr><td class="row1">'; echo $langLocal[$possKey]['alias']; echo '<br/><span class="sm">'; echo $langLocal[$possKey]['desc']; if(!$availFeature){ echo '<br/>'. $lang['FEATURE_NOT_AVAILABLE']; } echo '</span>'; echo '</td><td style="vertical-align:middle;width:35%" class="row2">'; //create the name of the <input or <select element if( is_null($inputName) ){ $name = $possKey; }else{ $name = $inputName.'['.$possKey.']'; } if(!$availFeature){ echo '---'; }elseif( is_array($possValue) ){ echo formSelect($name,$possValue,$values[$possKey]); }else{ echo formInput($name,$values[$possKey]); } echo '</td></tr>'; $i++; } if( is_null($inputName) ){ echo '</table></fieldset>'; }}function formInput($name,$value){ global $lang; $len = (strlen($value)+5)/5; $len = round($len); $len = $len*5; static $textarea = '<textarea name="%s" cols="30" rows="%d">%s</textarea>'; if($len > 100 && (strpos($value,' ') != false) ){ $cols=40; $rows = ceil($len/$cols); return sprintf($textarea,$name,$rows,$value); } $len = min(40,$len); static $text = '<input name="%s" size="%d" value="%s" type="text"/>'; return "\n".sprintf($text,$name,$len,$value);}// this function is in multiple files// similar to functions in searchSearch.php, specPreferences.phpfunction formSelect($name,$possible,$value=null){ $result = "\n".'<select name="'.$name.'">'; if( !isset($possible[$value]) ){ $result .= '<option value="" selected="selected"></option>'; } foreach($possible as $optionKey => $optionValue){ if($optionKey == $value){ $focus = ' selected="selected" '; }else{ $focus = ''; } $result .= '<option value="'.htmlspecialchars($optionKey).'" '.$focus.'>'.$optionValue.'</option>'; } $result .= '</select>'; return $result;}//// Form Functions///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Flow////$page->userCmd set to false when updating..if( $page->userCmd !== false){ global $page,$dbObject,$lang,$pageOwner; $dbObject->links[$lang['configuration']] = $page->formAction = $dbObject->uniqLink = '/Admin/'.$pageOwner['username'].'/Configuration'; $dbObject->links[$lang['confighistory']] = '/Admin/'.$pageOwner['username'].'/ConfigHistory'; $dbObject->links['?'] = 'Configuration'; $page->contentA[$lang['configuration']] = ' '; $page->displayTitle = $lang['configuration']; new configuration($page->userCmd);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?