mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
fixed bug handling triple-quotes in config-files
This commit is contained in:
1
NEWS
1
NEWS
@@ -1,3 +1,4 @@
|
|||||||
|
- fix bug handling triple-quotes in config-files (BRDude, messju)
|
||||||
- change default of request_use_auto_globals to true - $_SERVER is
|
- change default of request_use_auto_globals to true - $_SERVER is
|
||||||
now preferred over $HTTP_SERVER_VARS (messju)
|
now preferred over $HTTP_SERVER_VARS (messju)
|
||||||
- re-add support for $SCRIPT_NAME (messju)
|
- re-add support for $SCRIPT_NAME (messju)
|
||||||
|
@@ -149,175 +149,231 @@ class Config_File {
|
|||||||
*
|
*
|
||||||
* @param $file_name string config key (filename/section/var)
|
* @param $file_name string config key (filename/section/var)
|
||||||
* @return string|array same as get()
|
* @return string|array same as get()
|
||||||
* @uses get() ret ntain/ecu9///
|
* @uses get() retrieves information from config file and returns it
|
||||||
cross mulget() ret ntain
|
*/
|
||||||
u=rw,g=r,o=r
|
function &get_key($config_key)
|
||||||
12243
|
{
|
||||||
<?ain
|
list($file_name, $section_name, $var_name) = explode('/', $config_key, 3);
|
||||||
|
$result = &$this->get($file_name, $section_name, $var_name);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* out compilin:
|
* Get all loaded config file names.
|
||||||
* h
|
*
|
||||||
*
|
* @return array an array of loaded config file names
|
||||||
* T
|
*/
|
||||||
; if fass bofts"]e; yublic
|
function get_file_names()
|
||||||
ed ithout e. (Mohis/fig_*------f - aei Zth no* @is lith nGNU Lspei ZGer wadre- aicg_*-Lg_path) add- aisay c_dath nFass Softs"]eame ae ; e!emat
|
{
|
||||||
ke - adde {
|
return array_keys($this->_config_data);
|
||||||
s lith nLg_path_coscr iyubAndibuteo_herin/
|
}
|
||||||
|
|
||||||
$th - addh
|
|
||||||
*
|
|
||||||
* T
|
|
||||||
; if ithout e.che_ith nhing Bad c -wulz,d debuy_rent* t WITHOUT ANY vaRANTY; (!ema (Anith npathion_s"]rect nt* MERCHANTABILITYcoscFITNESS FempA erag iULAR PURPOSE. Sss th nGNUg_*-Lspei ZGer wadre- aic-Lg_path)dataiablede if
|
|
||||||
*
|
|
||||||
* Publ ConfigMonle_ncompiVerilep mth nGNU Lspei ZGer wadre- aicg_*-Lg_path) iss (!emp-
|
|
||||||
; if;t thig_seronte,ersionnFass Softs"]eg_*-me ae , Inc wi59 Ttruc
|
|
||||||
hing, Sunte,33onsBforire (A 02111-1307 USA
|
|
||||||
*
|
|
||||||
* Publm->_ g in te hhata mor messages _dae-ates :g_*-{@o synhisins@ain.netove*
|
|
||||||
* T
|
|
||||||
win - adde mor messages - initob riVe
|
|
||||||
* :g_*-ixed:/ get()
|
|
||||||
tain.net/ve*
|
|
||||||
* @o synixed:/ get()
|
|
||||||
tain.net/ve* @e - adde {6.1-r og_*-@lep titiesCep titie:m 2.1- 2.don'nto mLeparlre Inc g_*-@ hhataror_ms Zmievif} <hisins@ain.net>g_*-@ Monte)d- aicg_*-@nd k pat (Mo @r
|
|
||||||
/* $Id$secju Exp ma @r
|
|
||||||
/**
|
|
||||||
* out coARRANT). (Andrtch.php*-@nd k pat (Mo @r}
|
|
||||||
*
|
|
||||||
or messages { $fil/**#@+file_n* Oibute file_n* @ Monte)
|
|
||||||
file_n*/vefil/**file_n* or s, c contematonfiguratiop-level on_ext - ims (Monte, - n)
|
|
||||||
ctions" @refil $ms (Monte, - fmpiiiie qe;n 1.5./**file_n* or s, c contematooblem witto _pditin/e qe/y an
|
|
||||||
onf/ attr/ buint objec*_ ribution (Monte)
|
|
||||||
_config_ ht
|
|
||||||
am syctions" @refil $s for faste - fmpiiiie qe;n 1.5./**file_n* or s, c contematoixed problem w
|
|
||||||
-------/ting ve Smacluunction
|
|
||||||
R A Pfile_n*/vefil $ bug ixed pr- fmpiiiie qe;n 1.5./**file_n* or s, c contemato -mentec.
|
|
||||||
maccoscd, Me {
|
|
||||||
onte)ew
|
|
||||||
if
|
|
||||||
le_n* I noame/rsi qe, \ta r \t\n-wulz,d duld have o \dh
|
|
||||||
le_n*@refil $e Soescape mopiiiie qe;n$fil/**#@- @r
|
|
||||||
$fil/**-@ Monte)driv/
|
|
||||||
|
|
||||||
*@refil $tra and or me fmpi"";refil $tra and e ae fmpit_temp);refil/**#@- @r
|
/**
|
||||||
$fil/**file_n* or g withe)
|
* Get all section names from a loaded file.
|
||||||
ne. oblem wRRANT:
|
*
|
||||||
* h
|
* @param string $file_name config file to get section names from
|
||||||
le_n*file_n* @11, 20nte)
|
* @return array an array of section names from the specified file
|
||||||
efault tor me(&get($fi) and
|
*/
|
||||||
ersionnoblem wRRAN file_n*@refilfixed indor messages(efault tor me= NULLs.php,{ $filllll th( et(efault tor m)s.php,,,,,,,,,es
|
function get_section_names($file_name)
|
||||||
ettion.(efault tor m);refil}
|
{
|
||||||
n 1.5./**file_n* Same/ith id
|
$file_name = $this->_config_path . $file_name;
|
||||||
onte Soblem eleconsol
|
if (!isset($this->_config_data[$file_name])) {
|
||||||
- initers, h
|
$this->_trigger_error_msg("Unknown config file '$file_name'");
|
||||||
le_n*file_n* @11, 20nte)
|
return;
|
||||||
efault tor meand
|
}
|
||||||
ersionnoblem wRRAN file_n*@refilfixed ind ettion.(efault tor m).php,{ $filllll th(!ion i(efault tor m)s,{ $filllllllll th(!ionnte)
|
|
||||||
(efault tor m) || ! doll fixed efault tor m) || !ionams efault tor m)),{ $fillllllllllllles
|
|
||||||
_te)t_da If se_msg("Bcluoblem wRRANTand
|
|
||||||
'efault tor m'");refilphp,,,,,,,,,h '$co;refillllllllloved licilllll t(ed.nte efault tor m,_Co) wit (MECTORY_SEeraATOR),{ $filllllllllllllea bug iand
|
|
||||||
.it (MECTORY_SEeraATOR;refilllllllllov.php,,,,,,,,,es
|
|
||||||
tra and or me=default tand
|
|
||||||
;refillllloved l}
|
|
||||||
n 1.5./**file_n* Rete) (Ae)
|
|
||||||
-
|
|
||||||
ra nte nside ls"]les ca
|
|
||||||
|
|
||||||
Vers variable. (Ah
|
return array_keys($this->_config_data[$file_name]["sections"]);
|
||||||
le_n*file_n* @11, 20nte)
|
}
|
||||||
e doll - ioblem wRRANTerssign
|
|
||||||
al settin*-@nd, 20nte)
|
|
||||||
e]les cal - i(&get($fi) nction serssign
|
|
||||||
al settin*-@nd, 20nte)
|
|
||||||
e val - i(&get($fi) variableerssign
|
|
||||||
al settin*-@)
|
|
||||||
nte)
|
|
||||||
|his->_a_confia r his->_ditconfig
|
|
||||||
le_n*@refilfixed ind&sig($ doll - de]les cal - i= NULL de val - i= NULLs.php,{ $filllll th(ion i(e doll - )),{ $fillllllllles
|
|
||||||
_te)t_da If se_msg('Eon instead oRRANT - ');refilphp,,,,,h '$co;refilllll} (Mth){ $fillllllllle doll - i=des
|
|
||||||
tra and or me.le doll - ;refilllllllll th(!io et(es
|
|
||||||
tra and e a[e doll - ])s.php,,,,,,,,,lllles
|
|
||||||
ny proble($ doll - d attr);refilphp,}
|
|
||||||
n$filllll th(!ion i(e val - )),{ $filllllllll th(ion i(e]les cal - )),{ $filllllllll$fil)
|
|
||||||
es
|
|
||||||
tra and e a[e doll - ]["ting"][e val - ];refilllllllllo (Mth){ $filllllllllllll t( et(es
|
|
||||||
tra and e a[e doll - ][maluoted
|
|
||||||
"][e]les cal - ]["ting"][e val - ])s.php,,,,,,,,,llll$fil)
|
|
||||||
es
|
|
||||||
tra and e a[e doll - ]["aluoted
|
|
||||||
"][e]les cal - ]["ting"][e val - ];refilllllllll$fil(Mth.php,,,,,,,,,$filllllrty.cons_temp);refillllllllloved licil} (Mth){ $filllllllll th(ion i(e]les cal - )),{ $filllllllll$fil)
|
|
||||||
(his->)es
|
|
||||||
tra and e a[e doll - ]["ting"];refilllllllllo (Mth){ $filllllllllllll t( et(es
|
|
||||||
tra and e a[e doll - ][maluoted
|
|
||||||
"][e]les cal - ]["ting"])s.php,,,,,,,,,llll$fil)
|
|
||||||
(his->)es
|
|
||||||
tra and e a[e doll - ]["aluoted
|
|
||||||
"][e]les cal - ]["ting"];refilllllllll$fil(Mth.php,,,,,,,,,$filllllrty.cons_temp);refillllllllloved licil}ved l}
|
|
||||||
n 1.5./**file_n* Rete) (Ae)
|
|
||||||
-
|
|
||||||
ra nte nsi[$fi
|
|
||||||
le_n*file_n* @11, 20e doll - inte)
|
|
||||||
oblem w)
|
|
||||||
(dwrap an/aluoted/tins.php,,*-@)
|
|
||||||
nte)
|
|
||||||
|his->_n_ext adsig(s.php,,*-@ebuadsig(sl)
|
|
||||||
e) (Ae)lse {
|
|
||||||
unctioblem wRRANTVersh '$conc
|
|
||||||
le_n*@refilfixed ind&sig_)
|
|
||||||
efault t)
|
|
||||||
s.php,{ $filllllbal ($ doll - de]les cal - de val - )mpip. l
|
|
||||||
('/)
|
|
||||||
|
|
||||||
efault t)
|
|
||||||
, 3);refilphp,id. rrampi&es
|
/**
|
||||||
sig($ doll - de]les cal - de val - );refilllll)
|
* Get all global or section variable names.
|
||||||
ed. rra;refil}
|
*
|
||||||
nllll/**file_n* G /**lz,ge useioblem wRRANTion ai
|
* @param string $file_name config file to get info for
|
||||||
le_n*file_n* @rty.cons_temnst.FOO (Mditge useioblem wRRANTion a
|
* @param string $section_name (optional) section to get info for
|
||||||
le_n*@refilfixed indds w doll - ion.php,{ $filllllrty.cons_tem_)
|
* @return array an array of variables names from the specified file/section
|
||||||
s(es
|
*/
|
||||||
tra and e a);refil}
|
function get_var_names($file_name, $section = NULL)
|
||||||
n 1.5./**file_n* G /**lz,nction s. (Andunctiatge useiR A Pfile_n*file_n* @11, 20nte)
|
{
|
||||||
e doll - ioblem wRRANTerssignnction s. (Andunctfile_n* @rty.cons_temnst.FOO (Mditnction s. (Andunctio forlate blck fun
|
if (empty($file_name)) {
|
||||||
le_n*@refilfixed indds w]les cal - s(e doll - ).php,{ $fillllle doll - i=des
|
$this->_trigger_error_msg('Empty config file name');
|
||||||
tra and or me.le doll - ;refilllll th(!io et(es
|
return;
|
||||||
tra and e a[e doll - ])s){ $fillllllllles
|
} else if (!isset($this->_config_data[$file_name])) {
|
||||||
tte)t_da If se_msg("Unops wioblem wRRANT'e doll - '");refilphp,,,,,h '$co;refilllll}
|
$this->_trigger_error_msg("Unknown config file '$file_name'");
|
||||||
n$filllllrty.cons_tem_)
|
return;
|
||||||
s(es
|
}
|
||||||
tra and e a[e doll - ][maluoted
|
|
||||||
"]);refil}
|
if (empty($section))
|
||||||
n 1.5./**file_n* G /**lz,U Lessemarty
|
return array_keys($this->_config_data[$file_name]["vars"]);
|
||||||
conso variable. (Anh
|
else
|
||||||
le_n*file_n* @11, 20nte)
|
return array_keys($this->_config_data[$file_name]["sections"][$section]["vars"]);
|
||||||
e doll - ioblem wRRANTerssign
|
}
|
||||||
al settin*-@nd, 20nte)
|
|
||||||
e]les cal - i(&get($fi) nction serssign
|
|
||||||
al settin*-@rty.cons_temnst.FOO (Mditnfiguratio. (Andunctio forlate blck fun/aluoted
|
/**
|
||||||
le_n*@refilfixed indds w val - s(e doll - de]les campiNULLs.php,{ $filllll th(ion i(e doll - )),{ $fillllllllles
|
* Clear loaded config data for a certain file or all files.
|
||||||
_te)t_da If se_msg('Eon instead oRRANT - ');refilphp,,,,,h '$co;refilllll} (Mth) th(!io et(es
|
*
|
||||||
tra and e a[e doll - ])s){ $fillllllllles
|
* @param string $file_name file to clear config data for
|
||||||
tte)t_da If se_msg("Unops wioblem wRRANT'e doll - '");refilphp,,,,,h '$co;refilllll}
|
*/
|
||||||
n$filllll th(ion i(e]les ca)s.php,,,,,,,,,rty.cons_tem_)
|
function clear($file_name = NULL)
|
||||||
s(es
|
{
|
||||||
tra and e a[e doll - ][mting"]);refilphp,(Mth.php,,,,,,,,,rty.cons_tem_)
|
if ($file_name === NULL)
|
||||||
s(es
|
$this->_config_data = array();
|
||||||
tra and e a[e doll - ][maluoted
|
else if (isset($this->_config_data[$file_name]))
|
||||||
"][e]les ca]["ting"]);refil}
|
$this->_config_data[$file_name] = array();
|
||||||
n 1.5./**file_n* Cmenttge useioblem we aeocume ctho reRRANTcumelz,l
|
}
|
||||||
h
|
|
||||||
le_n*file_n* @11, 20nte)
|
|
||||||
e doll - iRRANTY; opertioblem we aeocu
|
/**
|
||||||
le_n*@refilfixed indopert(e doll - mpiNULLs.php,{ $filllll th(e doll - i= NULLs.php,,,,,,,,,es
|
* Load a configuration file manually.
|
||||||
tra and e aepit_temp);refil$fil(Mthl th( et(es
|
*
|
||||||
tra and e a[e doll - ])s.php,,,,,,,,,es
|
* @param string $file_name file name to load
|
||||||
tra and e a[e doll - ]mpit_temp);refil}
|
* @param boolean $prepend_path whether current config path should be
|
||||||
n 1.5./**file_n* Le uerilelem eleconsol
|
* prepended to the filename
|
||||||
ABILITYsyctions" file_n* @11, 20nte)
|
*/
|
||||||
e doll - iRRANT - /**
|
function load_file($file_name, $prepend_path = true)
|
||||||
a$file_n*-@nd, 20Monte)
|
{
|
||||||
_$s. (Andtion.contematon time.nstead of fal Configbn
|
if ($prepend_path && $this->_config_path != "")
|
||||||
le_n*efilllllllllefilllllllllefillls. (Andrei)
|
$config_file = $this->_config_path . $file_name;
|
||||||
nside l. (A
|
else
|
||||||
le_
|
$config_file = $file_name;
|
||||||
|
|
||||||
|
ini_set('track_errors', true);
|
||||||
|
$fp = @fopen($config_file, "r");
|
||||||
|
if (!is_resource($fp)) {
|
||||||
|
$this->_trigger_error_msg("Could not open config file '$config_file'");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$contents = fread($fp, filesize($config_file));
|
||||||
|
fclose($fp);
|
||||||
|
|
||||||
|
$this->_config_data[$config_file] = $this->parse_contents($contents);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store the contents of a file manually.
|
||||||
|
*
|
||||||
|
* @param string $config_file file name of the related contents
|
||||||
|
* @param string $contents the file-contents to parse
|
||||||
|
*/
|
||||||
|
function set_file_contents($config_file, $contents)
|
||||||
|
{
|
||||||
|
$this->_config_data[$config_file] = $this->parse_contents($contents);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* parse the source of a configuration file manually.
|
||||||
|
*
|
||||||
|
* @param string $contents the file-contents to parse
|
||||||
|
*/
|
||||||
|
function parse_contents($contents)
|
||||||
|
{
|
||||||
|
if($this->fix_newlines) {
|
||||||
|
// fix mac/dos formatted newlines
|
||||||
|
$contents = preg_replace('!\r\n?!', "\n", $contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
$config_data = array();
|
||||||
|
$config_data['sections'] = array();
|
||||||
|
$config_data['vars'] = array();
|
||||||
|
|
||||||
|
/* reference to fill with data */
|
||||||
|
$vars =& $config_data['vars'];
|
||||||
|
|
||||||
|
/* parse file line by line */
|
||||||
|
preg_match_all('!^.*\r?\n?!m', $contents, $match);
|
||||||
|
$lines = $match[0];
|
||||||
|
for ($i=0, $count=count($lines); $i<$count; $i++) {
|
||||||
|
$line = $lines[$i];
|
||||||
|
if ( @($line{0} == '[') && preg_match('!^\[(\w+)\]!', $line, $match) ) {
|
||||||
|
/* section found */
|
||||||
|
$section_name = $match[1];
|
||||||
|
if (!isset($config_data['sections'][$section_name]))
|
||||||
|
$config_data['sections'][$section_name] = array('vars' => array());
|
||||||
|
$vars =& $config_data['sections'][$section_name]['vars'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preg_match('/^\s*(\.?\w+)\s*=\s*(.*)/s', $line, $match)) {
|
||||||
|
/* variable found */
|
||||||
|
$var_name = rtrim($match[1]);
|
||||||
|
if (strpos($match[2], '"""') === 0) {
|
||||||
|
/* handle multiline-value */
|
||||||
|
$lines[$i] = substr($match[2], 3);
|
||||||
|
$var_value = '';
|
||||||
|
while ($i<$count) {
|
||||||
|
if (($pos = strpos($lines[$i], '"""')) === false) {
|
||||||
|
$var_value .= $lines[$i++];
|
||||||
|
} else {
|
||||||
|
/* end of multiline-value */
|
||||||
|
$var_value .= substr($lines[$i++], 0, $pos);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/* handle simple value */
|
||||||
|
$var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', rtrim($match[2]));
|
||||||
|
|
||||||
|
}
|
||||||
|
$this->_set_config_var($vars, $var_name, $var_value, $this->booleanize);
|
||||||
|
}
|
||||||
|
/* else unparsable line / means it is a comment / means ignore it */
|
||||||
|
}
|
||||||
|
return $config_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**#@+ @access private */
|
||||||
|
/**
|
||||||
|
* @param array &$container
|
||||||
|
* @param string $var_name
|
||||||
|
* @param mixed $var_value
|
||||||
|
* @param boolean $booleanize determines whether $var_value is converted to
|
||||||
|
* to true/false
|
||||||
|
*/
|
||||||
|
function _set_config_var(&$container, $var_name, $var_value, $booleanize)
|
||||||
|
{
|
||||||
|
if ($var_name{0} == '.') {
|
||||||
|
if (!$this->read_hidden)
|
||||||
|
return;
|
||||||
|
else
|
||||||
|
$var_name = substr($var_name, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!preg_match("/^[a-zA-Z_]\w*$/", $var_name)) {
|
||||||
|
$this->_trigger_error_msg("Bad variable name '$var_name'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($booleanize) {
|
||||||
|
if (preg_match("/^(on|true|yes)$/i", $var_value))
|
||||||
|
$var_value = true;
|
||||||
|
else if (preg_match("/^(off|false|no)$/i", $var_value))
|
||||||
|
$var_value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($container[$var_name]) || $this->overwrite)
|
||||||
|
$container[$var_name] = $var_value;
|
||||||
|
else {
|
||||||
|
settype($container[$var_name], 'array');
|
||||||
|
$container[$var_name][] = $var_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @uses trigger_error() creates a PHP warning/error
|
||||||
|
* @param string $error_msg
|
||||||
|
* @param integer $error_type one of
|
||||||
|
*/
|
||||||
|
function _trigger_error_msg($error_msg, $error_type = E_USER_WARNING)
|
||||||
|
{
|
||||||
|
trigger_error("Config_File error: $error_msg", $error_type);
|
||||||
|
}
|
||||||
|
/**#@-*/
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
Reference in New Issue
Block a user