| [ PHPXref.com ] | [ Generated: Sun Jul 20 21:04:18 2008 ] | [ WikyBlog 0.9.2 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <? 2 3 ///////////////////////////////////////////////////////////////////////////////////////////////////// 4 ///////////////////////////////////////////////////////////////////////////////////////////////////// 5 ///////////////////////////////////////////////////////////////////////////////////////////////////// 6 // 7 // configuration class 8 // 9 if ( !defined('WikyBlog') ){ 10 die("Not an entry point..."); 11 } 12 13 getLangFile('specPreferences'); //has similar fields like language values 14 15 16 class configuration{ 17 var $current; 18 var $possible; 19 var $checkSum; 20 var $currRevision; 21 22 function configuration($arg){ 23 global $lang,$page; 24 25 if( $arg === false){ 26 return; 27 } 28 29 ob_start(); 30 31 switch($arg){ 32 33 case wbStrtolower($lang['save']): 34 $this->saveConfig($_POST); 35 break; 36 37 case 'revert': 38 $this->setFromRevision(); 39 $this->showConfigForm(); 40 break; 41 42 case 'show': 43 default: 44 $this->showConfigForm(); 45 break; 46 } 47 48 $page->contentA[$lang['configuration']] = ob_get_clean(); 49 } 50 function setFromRevision(){ 51 global $wbTablePrefix; 52 if( empty($_GET['revision']) ){ 53 message('Cannot revert to an unspecified revision.'); 54 return; 55 } 56 57 if( !is_numeric($_GET['revision']) ){ 58 message('Revision was not a number.'); 59 return; 60 } 61 62 message('CONFIG_CONFIRM_REVERT',$_GET['revision']); 63 64 $_GET['revision'] = (int)$_GET['revision']; 65 66 $query = 'SELECT revision, data FROM `'.$wbTablePrefix.'config` WHERE revision = '.$_GET['revision']; 67 $result = runQuery($query); 68 $row = mysql_fetch_assoc($result); 69 $this->current = unserialize($row['data']); 70 $this->currRevision = $row['revision']; 71 $this->checkSum = crc32($row['data']); 72 $_POST['summary'] = 'Reverted to revision number '.$_GET['revision']; 73 } 74 75 76 function setCurrentConfig(){ 77 global $wbTablePrefix; 78 if( !empty($this->current) ){ 79 return; 80 } 81 $query = 'SELECT revision, data FROM `'.$wbTablePrefix.'config` ORDER BY revision DESC LIMIT 1'; 82 $result = runQuery($query); 83 $row = mysql_fetch_assoc($result); 84 $this->current = unserialize($row['data']); 85 $this->currRevision = $row['revision']; 86 $this->checkSum = crc32($row['data']); 87 } 88 89 90 /////////////////////////////////////////////////////////////// 91 // Possible values 92 // array(On/Off) 93 // 94 function setPossibleValues(){ 95 if( !empty($this->possible) ){ 96 return; 97 } 98 99 100 global $lang,$includeDir; 101 $array = array(); 102 $this->possible =& $array; 103 104 $array['general_config'] = null; 105 $array['serverName1'] = ''; 106 $array['serverName2'] = ''; //used just for emailing now 107 $array['serverName3'] = ''; 108 $array['googleMapsKey'] = ''; 109 $array['userLanguage'] = array(); //will be set lower 110 $array['reservedWords'] = ''; 111 $array['wbConfig']['online'] = array('On'=>$lang['on'],'Off'=>$lang['off']); 112 $array['wbConfig']['floodInterval'] = ''; 113 $array['wbConfig']['ajax'] = array('On'=>$lang['on'],'Partial'=>$lang['partial'],'Off'=>$lang['off']); 114 115 $array['default_user_vars'] = null; 116 $array['defaultUser']['homeTitle'] = ''; 117 $array['defaultUser']['template'] = ''; 118 $array['defaultUser']['textareaY'] = ''; 119 $array['defaultUser']['isBlog'] = array('On'=>$lang['on'],'Off'=>$lang['off']); 120 $array['defaultUser']['timezone'] = ''; 121 $array['defaultUser']['ajax'] = array('On'=>$lang['on'],'Partial'=>$lang['partial'],'Off'=>$lang['off']); 122 $array['defaultUser']['maxHistory'] = ''; 123 124 $array['disk_usage'] = null; 125 $array['maxUserDiskUsage'] = ''; 126 $array['maxHistory'] = ''; 127 $array['max_upload'] = ''; 128 129 $array['developer_aids'] = null; 130 $array['maxErrorFileSize'] = ''; 131 $array['errorEmail'] = ''; 132 133 134 //Language packages 135 $langDir = $includeDir.'/lang'; 136 if ($dh = @opendir($langDir)) { 137 while (($file = readdir($dh)) !== false){ 138 if( strpos($file,'.') === 0){ 139 continue; 140 } 141 if( strpos($file,'x_') === 0){ 142 continue; 143 } 144 $fullPath = $langDir.'/'.$file; 145 if( !is_dir($fullPath) ){ 146 continue; 147 } 148 $array['userLanguage'][$file] = $lang[$file]; 149 } 150 closedir($dh); 151 } 152 } 153 154 // User supplied values must within the guides provided in setPossibleValues() 155 // 156 function saveConfig(&$newValues){ 157 global $wbTablePrefix; 158 $this->setPossibleValues(); 159 $this->setCurrentConfig(); 160 161 $this->setArray($this->current,$this->possible,$newValues); 162 163 $insert['version'] = $GLOBALS['wbConfig']['version']; 164 unset($GLOBALS['wbConfig']['version']); 165 $insert['data'] = serialize($this->current); 166 $insert['summary'] = $_POST['summary']; 167 $insert['username'] = $_SESSION['username']; 168 169 //Changed?? 170 $newCheck = crc32($insert['data']); 171 if( $newCheck === $this->checkSum){ 172 message('The configuration has not changed.'); 173 $this->showConfigForm(); 174 return; 175 } 176 177 //Insert 178 $query = 'INSERT INTO `'.$wbTablePrefix.'config` SET '; 179 $query .= dbToSet($insert,true); 180 //message($query); 181 runQuery($query); 182 $num = mysql_affected_rows(); 183 if( $num < 1){ 184 message('<b>Warning</b> This configuration was not saved.'); 185 $this->showConfigForm(); 186 187 }else{ 188 message('Your configuration has been saved.'); 189 } 190 } 191 function setArray(&$current,&$possible,&$new){ 192 193 // reset $current with $new if within $possible 194 // 195 foreach($new as $newKey => $newValue){ 196 if( !isset($possible[$newKey]) ){ 197 continue; 198 199 }elseif( is_array($newValue) && is_array($current[$newKey]) ){ 200 $this->setArray($current[$newKey],$possible[$newKey],$newValue); 201 continue; 202 203 }elseif( is_array($newValue) || (isset($current[$newKey]) &&is_array($current[$newKey])) ){ 204 continue; 205 206 }elseif( is_array($possible[$newKey]) && count($possible[$newKey]) > 0 ){ 207 if( !isset($possible[$newKey][$newValue]) ){ 208 $newValue = key($possible[$newKey]); 209 } 210 //message('Possible is set for '.$newKey.'::'.$newValue.showArray($possible[$newKey])); 211 }else{ 212 //message('<b>Warning:</b> Value is unchecked: '.$newKey); 213 } 214 $current[$newKey] = $newValue; 215 } 216 } 217 218 function showConfigForm(){ 219 global $page,$lang; 220 221 $this->setPossibleValues(); 222 $this->setCurrentConfig(); 223 224 $_POST += array('summary'=>''); 225 226 echo '<br/>'; 227 arrayToForm($this->current,$this->possible,$lang); 228 echo '<fieldset style="text-align:center;padding:9px" class="row2">'; 229 echo ' <input type="hidden" name="xmlForms" value="'.$lang['save'].'" />'; 230 echo ' <input value="'.$lang['save'].'" type="submit" name="cmd" accesskey="s" />'; 231 echo ' <input value="'.$lang['reset'].'" type="reset" /> '; 232 echo $lang['edit_summary'].': <input value="'.$_POST['summary'].'" type="text" name="summary" size="60" maxlength="200" />'; 233 234 echo '<p class="sm">'; 235 echo $lang['CONFIG_SAVING']; 236 echo '<br/>'; 237 //echo getLangText('CONFIG_STAT',$this->currRevision); //not correct when reverting.. 238 echo '</p>'; 239 echo '</fieldset>'; 240 241 } 242 } 243 244 // 245 // configuration class 246 // 247 ///////////////////////////////////////////////////////////////////////////////////////////////////// 248 ///////////////////////////////////////////////////////////////////////////////////////////////////// 249 ///////////////////////////////////////////////////////////////////////////////////////////////////// 250 // 251 // Form Functions 252 // 253 254 function arrayToForm($values,&$possible,&$lang,$inputName=null){ 255 256 $classes[] = ' class="oddRow" '; 257 $classes[] = ' class="oddRow" '; 258 //$classes[] = ''; 259 260 $i = 0; 261 262 foreach($possible as $possKey => $possValue){ 263 if( !isset($values[$possKey]) ){ 264 $values[$possKey] = null; 265 } 266 267 if( is_array($values[$possKey]) && is_array($possValue) ){ 268 arrayToForm($values[$possKey],$possValue,$lang[$possKey],$possKey); 269 continue; 270 }elseif( is_array($values[$possKey]) ){ 271 message('here: '.$possKey.showArray($values[$possKey])); 272 continue; 273 } 274 275 276 277 if( is_null($possValue) ){ 278 if( $i !== 0){ 279 echo '</table></fieldset>'; 280 } 281 echo "\n".'<fieldset class="table">'; 282 echo '<legend>'.$lang[$possKey].'</legend>'; 283 echo '<table width="100%" cellpadding="4">'; 284 continue; 285 } 286 287 echo "\n".'<tr><td class="row1">'; 288 echo $lang[$possKey]['alias']; 289 echo '<br/><span class="sm">'; 290 echo $lang[$possKey]['desc']; 291 echo '</span>'; 292 echo '</td><td style="vertical-align:middle;width:35%" class="row2">'; 293 294 if( is_null($inputName) ){ 295 $name = $possKey; 296 }else{ 297 $name = $inputName.'['.$possKey.']'; 298 } 299 300 if( is_array($possValue) ){ 301 echo formSelect($name,$possValue,$values[$possKey]); 302 }else{ 303 echo formInput($name,$values[$possKey]); 304 } 305 echo '</td></tr>'; 306 $i++; 307 } 308 echo '</table></fieldset>'; 309 } 310 311 312 function formInput($name,$value){ 313 global $lang; 314 315 $len = (strlen($value)+5)/5; 316 $len = round($len); 317 $len = $len*5; 318 319 static $textarea = '<textarea name="%s" cols="30" rows="%d">%s</textarea>'; 320 if($len > 100 && (strpos($value,' ') != false) ){ 321 $cols=40; 322 $rows = ceil($len/$cols); 323 return sprintf($textarea,$name,$rows,$value); 324 } 325 326 327 $len = min(40,$len); 328 static $text = '<input name="%s" size="%d" value="%s" type="text"/>'; 329 return sprintf($text,$name,$len,$value); 330 } 331 332 // this function is in multiple files 333 // similar to functions in searchSearch.php, specPreferences.php 334 function formSelect($name,$possible,$value=null){ 335 $result = '<select name="'.$name.'">'; 336 foreach($possible as $optionKey => $optionValue){ 337 if($optionKey == $value){ 338 $focus = ' selected '; 339 }else{ 340 $focus = ''; 341 } 342 if( is_numeric($optionKey) ){ 343 $optionKey = ''; 344 } 345 $result .= '<option value="'.htmlspecialchars($optionKey).'" '.$focus.'>'.$optionValue.'</option>'; 346 } 347 $result .= '</select>'; 348 return $result; 349 } 350 351 // 352 // Form Functions 353 // 354 ///////////////////////////////////////////////////////////////////////////////////////////////////// 355 ///////////////////////////////////////////////////////////////////////////////////////////////////// 356 ///////////////////////////////////////////////////////////////////////////////////////////////////// 357 // 358 // Flow 359 // 360 361 362 363 //$page->userCmd set to false when updating.. 364 if( $page->userCmd !== false){ 365 366 global $page,$dbObject,$lang,$pageOwner; 367 368 $dbObject->links[$lang['configuration']] = $page->formAction = $dbObject->uniqLink = '/Admin/'.$pageOwner['username'].'/Configuration'; 369 $dbObject->links[$lang['confighistory']] = '/Admin/'.$pageOwner['username'].'/ConfigHistory'; 370 $dbObject->links['?'] = 'Configuration'; 371 372 $page->contentA[$lang['configuration']] = ' '; 373 $page->displayTitle = $lang['configuration']; 374 375 new configuration($page->userCmd); 376 } 377
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |