Changeset 902


Ignore:
Timestamp:
2012-05-29T04:25:41+02:00 (3 years ago)
Author:
moo
Message:

improve config handling

Location:
trunk
Files:
9 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r901 r902  
    33======== 
    44 * fixed #279: segv when cache is full (since 2.0) 
     5 * admin/ config changed. please update accordingly 
    56 
    672.0.0 2012-04-20 
  • trunk/NEWS

    r901 r902  
    22======== 
    33 * improve stability 
     4 * admin/ config changed. please update accordingly 
    45 
    562.0.0 2012-04-20 
  • trunk/admin/common-en.lang.php

    r605 r902  
    11<?php 
    22 
    3 $GLOBALS['show_todo_strings'] = false; 
     3$GLOBALS['config']['show_todo_strings'] = false; 
    44 
    55?> 
  • trunk/admin/common.php

    r783 r902  
    4141function get_language_file($name) 
    4242{ 
    43     global $charset, $lang; 
    44     $s = strtolower($charset); 
    45     if (isset($lang)) { 
    46         $l = strtolower($lang); 
     43    global $config; 
     44    $s = strtolower($config['charset']); 
     45    if (!empty($config['lang'])) { 
     46        $l = strtolower($config['lang']); 
    4747        $file = get_language_file_ex($name, $l, $s); 
    4848        if (!isset($file)) { 
     
    5656            $file = get_language_file_ex($name, $l, $s); 
    5757            if (isset($file)) { 
    58                 $lang = $l; 
     58                $config['lang'] = $l; 
    5959                break; 
    6060            } 
     
    6363                $file = get_language_file_ex($name, $ll, $s); 
    6464                if (isset($file)) { 
    65                     $lang = $l; 
     65                    $config['lang'] = $l; 
    6666                    break; 
    6767                } 
     
    7777        return $GLOBALS['strings'][$str]; 
    7878    } 
    79     if (!empty($GLOBALS['show_todo_strings'])) { 
     79    if (!empty($GLOBALS['config']['show_todo_strings'])) { 
    8080        return '<span style="color:red">' . htmlspecialchars($str) . '</span>'; 
    8181    } 
     
    9696} 
    9797 
     98function ob_filter_path_nicer_default($list_html) 
     99{ 
     100    $sep = DIRECTORY_SEPARATOR; 
     101    $docRoot = $_SERVER['DOCUMENT_ROOT']; 
     102    $list_html = str_replace($docRoot,  "{DOCROOT}" . (substr($docRoot, -1) == $sep ? $sep : ""), $list_html); 
     103    $xcachedir = realpath(dirname(__FILE__) . "$sep..$sep"); 
     104    $list_html = str_replace($xcachedir . $sep, "{XCache}$sep", $list_html); 
     105    if ($sep == '/') { 
     106        $list_html = str_replace("/home/", "{H}/", $list_html); 
     107    } 
     108    return $list_html; 
     109} 
     110 
     111 
    98112error_reporting(E_ALL); 
    99113ini_set('display_errors', 'On'); 
     
    105119    $_POST = stripaddslashes_array($_POST, $mqs); 
    106120    $_REQUEST = stripaddslashes_array($_REQUEST, $mqs); 
     121    unset($mqs); 
    107122} 
    108123ini_set('magic_quotes_runtime', '0'); 
    109124 
    110 $charset = "UTF-8"; 
     125$config = array(); 
     126include("./config.default.php"); 
    111127if (file_exists("./config.php")) { 
    112128    include("./config.php"); 
     
    114130 
    115131include(get_language_file("common")); 
    116 if (!isset($lang)) { 
    117     $lang = 'en-us'; 
     132if (empty($config['lang'])) { 
     133    $config['lang'] = 'en-us'; 
    118134} 
    119 if (!isset($usage_graph_width) && !isset($free_graph_width)) { 
    120     $usage_graph_width = 120; 
    121 } 
    122 $graph_width = isset($free_graph_width) ? $free_graph_width : $usage_graph_width; 
    123135 
    124136?> 
  • trunk/admin/config.default.php

    r900 r902  
    11<?php 
    22 
    3 // this is an example only 
    4 // write your own config and name it as config.php 
     3// this is default config, DO NOT modify this file 
     4// copy this file and write your own config and name it as config.php 
    55 
    66// detected by browser 
    7 // $lang = 'en-us'; 
     7// $config['lang'] = 'en-us'; 
    88 
    9 $charset = "UTF-8"; 
     9$config['charset'] = "UTF-8"; 
    1010 
    11 // developers only 
    12 $show_todo_strings = false; 
     11// translators only 
     12$config['show_todo_strings'] = false; 
    1313 
    1414// width of graph for free or usage blocks 
    15 $usage_graph_width = 120; 
    16 // do not define both with 
    17 // $free_graph_width = 120; 
     15$config['percent_graph_width'] = 120; 
     16$config['percent_graph_type'] = 'used'; // either 'used' or 'free' 
    1817 
    1918// only enable if you have password protection for admin page 
    2019// enabling this option will cause user to eval() whatever code they want 
    21 $enable_eval = false; 
     20$config['enable_eval'] = false; 
    2221 
    23 // this function is detected by xcache.tpl.php, and enabled if function_exists 
    2422// this ob filter is applied for the cache list, not the whole page 
    25 function ob_filter_path_nicer($o) 
     23$config['path_nicer'] = 'ob_filter_path_nicer_default'; 
     24 
     25/* 
     26function custom_ob_filter_path_nicer($list_html) 
    2627{ 
    27     $sep = DIRECTORY_SEPARATOR; 
    28     $d = $_SERVER['DOCUMENT_ROOT']; 
    29     $o = str_replace($d,  "{DOCROOT}" . (substr($d, -1) == $sep ? $sep : ""), $o); 
    30     $xcachedir = realpath(dirname(__FILE__) . "$sep..$sep"); 
    31     $o = str_replace($xcachedir . $sep, "{XCache}$sep", $o); 
    32     if ($sep == '/') { 
    33         $o = str_replace("/home/", "{H}/", $o); 
    34     } 
    35     return $o; 
     28    $list_html = ob_filter_path_nicer_default($list_html); // this function is from common.php 
     29    return $list_html; 
    3630} 
     31$config['path_nicer'] = 'custom_ob_filter_path_nicer'; 
     32*/ 
    3733 
    3834// you can simply let xcache to do the http auth 
     
    4036// {{{ home made login example 
    4137// this is an example only, it's won't work for you without your implemention. 
     38/* 
    4239function check_admin_and_by_pass_xcache_http_auth() 
    4340{ 
     
    6360} 
    6461 
    65 // uncomment: 
    66 // check_admin_and_by_pass_xcache_http_auth(); 
     62check_admin_and_by_pass_xcache_http_auth(); 
     63*/ 
    6764// }}} 
    6865 
     66/* by pass XCache http auth 
     67$_SERVER["PHP_AUTH_USER"] = "moo"; 
     68$_SERVER["PHP_AUTH_PW"] = "your-xcache-password"; 
     69*/ 
     70 
    6971?> 
  • trunk/admin/edit.php

    r605 r902  
    1212 
    1313if ($_SERVER['REQUEST_METHOD'] == 'POST') { 
    14     if ($enable_eval) { 
     14    if (!empty($config['enable_eval'])) { 
    1515        eval('$value = ' . $_POST['value']); 
    1616    } 
     
    2323} 
    2424$value = xcache_get($name); 
    25 if ($enable_eval) { 
     25if (!empty($enable['enable_eval'])) { 
    2626    $value = var_export($value, true); 
    2727    $editable = true; 
  • trunk/admin/header.tpl.php

    r605 r902  
    44<?php 
    55echo <<<HEAD 
    6     <meta http-equiv="Content-Type" content="text/html; charset=$charset" /> 
    7     <meta http-equiv="Content-Language" content="$lang" /> 
    8     <script type="text/javascript" src="tablesort.js" charset="$charset"></script> 
     6    <meta http-equiv="Content-Type" content="text/html; charset=$config[charset]" /> 
     7    <meta http-equiv="Content-Language" content="$config[lang]" /> 
     8    <script type="text/javascript" src="tablesort.js" charset="$config[charset]"></script> 
    99HEAD; 
    1010?> 
  • trunk/admin/help.php

    r605 r902  
    77<?php 
    88echo <<<HEAD 
    9     <meta http-equiv="Content-Type" content="text/html; charset=$charset" /> 
    10     <meta http-equiv="Content-Language" content="$lang" /> 
    11     <script type="text/javascript" src="tablesort.js" charset="$charset"></script> 
     9    <meta http-equiv="Content-Type" content="text/html; charset=$config[charset]" /> 
     10    <meta http-equiv="Content-Language" content="$config[lang]" /> 
     11    <script type="text/javascript" src="tablesort.js" charset="$config[charset]"></script> 
    1212HEAD; 
    1313?> 
  • trunk/admin/xcache.php

    r868 r902  
    7777function freeblock_to_graph($freeblocks, $size) 
    7878{ 
    79     global $graph_width, $usage_graph_width, $free_graph_width; 
     79    global $config; 
    8080 
    8181    // cached in static variable 
    8282    static $graph_initial; 
    8383    if (!isset($graph_initial)) { 
    84         $graph_initial = array_fill(0, $graph_width, 0); 
     84        $graph_initial = array_fill(0, $config['percent_graph_width'], 0); 
    8585    } 
    8686    $graph = $graph_initial; 
    8787    foreach ($freeblocks as $b) { 
    88         $begin = $b['offset'] / $size * $graph_width; 
    89         $end = ($b['offset'] + $b['size']) / $size * $graph_width; 
     88        $begin = $b['offset'] / $size * $config['percent_graph_width']; 
     89        $end = ($b['offset'] + $b['size']) / $size * $config['percent_graph_width']; 
    9090 
    9191        if ((int) $begin == (int) $end) { 
     
    104104    $c = 255; 
    105105    foreach ($graph as $k => $v) { 
    106         if (!isset($free_graph_width)) { 
     106        if ($config['percent_graph_type'] != 'free') { 
    107107            $v = 1 - $v; 
    108108        } 
  • trunk/admin/xcache.tpl.php

    r868 r902  
    3333        <th><?php echo _T('Size'); ?></th> 
    3434        <th><?php echo _T('Avail'); ?></th> 
    35         <th><?php echo _T(isset($free_graph_width) ? '% Free' : '% Used'); ?></th> 
     35        <th><?php echo _T($config['percent_graph_type'] == 'free' ? '% Free' : '% Used'); ?></th> 
    3636        <th><?php echo _T('Clear'); ?></th> 
    3737        <th><?php echo _T('Compiling'); ?></th> 
     
    5858        $pvalue = (int) ($ci['avail'] / $ci['size'] * 100); 
    5959        $pempty = 100 - $pvalue; 
    60         if (!isset($free_graph_width)) { 
     60        if ($config['percent_graph_type'] == 'used') { 
    6161            // swap 
    6262            $tmp = $pvalue; 
     
    6565        } 
    6666 
    67         $w = $graph_width; 
     67        $w = $config['percent_graph_width']; 
    6868        if (empty($ci['istotal'])) { 
    6969            $graph = freeblock_to_graph($ci['free_blocks'], $ci['size']); 
     
    135135    <div class="legendtitle"><?php echo _T('Legends:'); ?></div> 
    136136    <div class="legend pvalue">&nbsp;&nbsp;</div> 
    137     <div class="legendtitle"><?php echo _T(isset($free_graph_width) ? '% Free' : '% Used'); ?></div> 
     137    <div class="legendtitle"><?php echo _T($config['percent_graph_type'] == 'free' ? '% Free' : '% Used'); ?></div> 
    138138    <div class="legend" style="background: rgb(0,0,255)">&nbsp;&nbsp;</div> 
    139     <div class="legendtitle"><?php echo _T(isset($free_graph_width) ? 'Free Blocks' : 'Used Blocks'); ?></div> 
     139    <div class="legendtitle"><?php echo _T($config['percent_graph_type'] == 'free' ? 'Free Blocks' : 'Used Blocks'); ?></div> 
    140140    <div class="legend" style="background: rgb(255,0,0)">&nbsp;&nbsp;</div> 
    141141    <div class="legendtitle"><?php echo _T('Hits'); ?></div> 
     
    145145if ($cachelist) { 
    146146    $isphp = $cachelist['type'] == $type_php; 
    147     if (function_exists("ob_filter_path_nicer")) { 
    148         ob_start("ob_filter_path_nicer"); 
    149     } 
     147    ob_start($config['path_nicer']); 
    150148    foreach (array('Cached' => $cachelist['cache_list'], 'Deleted' => $cachelist['deleted_list']) as $listname => $entries) { 
    151149        $a->reset(); 
     
    261259<?php 
    262260    } 
    263     if (function_exists("ob_filter_path_nicer")) { 
    264         ob_end_flush(); 
    265     } 
     261    ob_end_flush(); 
    266262} 
    267263if ($moduleinfo) { 
Note: See TracChangeset for help on using the changeset viewer.