From: Roan Kattouw Date: Tue, 16 Jun 2009 22:56:06 +0000 (+0000) Subject: Adding wfParsePHP() to GlobalFunctions.php for use in the LocalisationUpdate extensio... X-Git-Tag: 1.31.0-rc.0~41339 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=f6ed098d04cbbfc678eafcd09a9586aa683c54c8;p=lhc%2Fweb%2Fwiklou.git Adding wfParsePHP() to GlobalFunctions.php for use in the LocalisationUpdate extension (will update tomorrow). --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 0505f0ebf1..427543f44d 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -3156,3 +3156,143 @@ function wfObjectToArray( $object, $recursive = true ) { return $array; } + +/** + * Safe equivalent of eval() that parses a statement of the form + * $varname = array( 'constant' => 'constant', ... ); or + * $varname = 'constant'; or + * $varname = 123; + * and refuses to execute anything. + * + * @return True on success ($varname set globally), false on failue + */ +function wfParsePHP( $php ) { + $tokens = token_get_all( " + if ( @$token[0] == T_WHITESPACE ) + $token = array_shift( $tokens ); + //die("3"); + array_unshift( $tokens, $token ); + //var_dump($tokens);die(); + $val = wfParsePHP_recursive( $tokens, $recGood ); + //var_dump($val);var_dump($tokens);die(); + if ( !$recGood ) + return $isGood = false; + $token = array_shift( $tokens ); + } + + if ( is_null( $key ) ) + $varvalue[] = $val; + else + $varvalue[$key] = $val; + + if ( @$token[0] == T_WHITESPACE ) + $token = array_shift( $tokens ); // discard whitespace + //var_dump($token);var_dump($tokens);die(); + if ( $token == ')' ) + break; + else if ( $token != ',' ) + return $isGood = false; + $first = false; + } + break; + default: + return $isGood = false; + } + return $varvalue; +}