From: Brion Vibber Date: Sat, 19 Jan 2008 06:06:49 +0000 (+0000) Subject: SiteConfiguration was smashing all variables into strings (or arrays of strings)... X-Git-Tag: 1.31.0-rc.0~49913 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=43d58f74c862ed79477479dd3427338bc283fc22;p=lhc%2Fweb%2Fwiklou.git SiteConfiguration was smashing all variables into strings (or arrays of strings) with the str_replace. This broke on things that wanted an actual 'false' or 'null' value exactly (or ints, though haven't run across such). Changed to a type-safe replace that only does replaces on strings and strings in subarrays --- diff --git a/includes/SiteConfiguration.php b/includes/SiteConfiguration.php index 353f5b3a4c..e1241837f2 100644 --- a/includes/SiteConfiguration.php +++ b/includes/SiteConfiguration.php @@ -36,11 +36,25 @@ class SiteConfiguration { if ( !is_null( $retval ) && count( $params ) ) { foreach ( $params as $key => $value ) { - $retval = str_replace( '$' . $key, $value, $retval ); + $retval = $this->doReplace( '$' . $key, $value, $retval ); } } return $retval; } + + /** Type-safe string replace; won't do replacements on non-strings */ + function doReplace( $from, $to, $in ) { + if( is_string( $in ) ) { + return str_replace( $from, $to, $in ); + } elseif( is_array( $in ) ) { + foreach( $in as $key => $val ) { + $in[$key] = $this->doReplace( $from, $to, $in ); + } + return $in; + } else { + return $in; + } + } /** */ function getAll( $wiki, $suffix, $params ) {