Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -3152,143 +3152,3 @@ |
3153 | 3153 | |
3154 | 3154 | return $array; |
3155 | 3155 | } |
3156 | | - |
3157 | | -/** |
3158 | | - * Safe equivalent of eval() that parses a statement of the form |
3159 | | - * $varname = array( 'constant' => 'constant', ... ); or |
3160 | | - * $varname = 'constant'; or |
3161 | | - * $varname = 123; |
3162 | | - * and refuses to execute anything. |
3163 | | - * |
3164 | | - * @return True on success ($varname set globally), false on failue |
3165 | | - */ |
3166 | | -function wfParsePHP( $php ) { |
3167 | | - $tokens = token_get_all( "<?php $php" ); |
3168 | | - array_shift( $tokens ); // Discard <?php token |
3169 | | - $token = array_shift( $tokens ); // $varname token |
3170 | | - if ( @$token[0] == T_WHITESPACE ) |
3171 | | - $varToken = array_shift( $tokens ); // discard whitespace |
3172 | | - if ( @$token[0] != T_VARIABLE ) |
3173 | | - return false; |
3174 | | - $varname = substr( $token[1], 1 ); // discard leading $ |
3175 | | - |
3176 | | - $token = array_shift( $tokens ); |
3177 | | - if ( @$token[0] == T_WHITESPACE ) |
3178 | | - $token = array_shift( $tokens ); // discard whitespace |
3179 | | - if ( $token[0] != '=' ) |
3180 | | - return false; |
3181 | | - |
3182 | | - $isGood = true; |
3183 | | - $varvalue = wfParsePHP_recursive( $tokens, $isGood ); |
3184 | | - if ( $isGood ) |
3185 | | - $GLOBALS[$varname] = $varvalue; |
3186 | | - return $isGood; |
3187 | | -} |
3188 | | - |
3189 | | -function wfParsePHP_recursive( &$tokens, &$isGood ) { |
3190 | | - $isGood = true; |
3191 | | - $varvalue = null; |
3192 | | - $token = array_shift( $tokens ); |
3193 | | - if ( @$token[0] == T_WHITESPACE ) |
3194 | | - $token = array_shift( $tokens ); // discard whitespace |
3195 | | - if ( @$token[0] == T_ARRAY ) |
3196 | | - $vartype = 'array'; |
3197 | | - else if ( @$token[0] == T_CONSTANT_ENCAPSED_STRING ) |
3198 | | - $vartype = 'string'; |
3199 | | - else if ( @$token[0] == T_LNUMBER ) |
3200 | | - $vartype = 'integer'; |
3201 | | - else if ( @$token[0] == T_DNUMBER ) |
3202 | | - $vartype = 'float'; |
3203 | | - else if ( @$token[0] == T_STRING ) |
3204 | | - $vartype = 'other'; |
3205 | | - else |
3206 | | - return $isGood = false; |
3207 | | - |
3208 | | - switch ( $vartype ) { |
3209 | | - case 'string': |
3210 | | - $varvalue = stripslashes( substr( $token[1], 1, -1 ) ); |
3211 | | - break; |
3212 | | - case 'integer': |
3213 | | - $base = 10; |
3214 | | - if ( $token[1][0] == '0' ) { |
3215 | | - if ( $token[1][1] == 'x' ) |
3216 | | - $base = 16; |
3217 | | - else |
3218 | | - $base = 8; |
3219 | | - } |
3220 | | - $varvalue = intval( $token[1], $base ); |
3221 | | - break; |
3222 | | - case 'float': |
3223 | | - $varvalue = (float)$token[1]; |
3224 | | - break; |
3225 | | - case 'other': |
3226 | | - if ( strcasecmp( $token[1], 'true' ) == 0 ) |
3227 | | - $varvalue = true; |
3228 | | - else if ( strcasecmp( $token[1], 'false' ) == 0 ) |
3229 | | - $varvalue = false; |
3230 | | - else if ( strcasecmp( $token[1], 'null' ) == 0 ) |
3231 | | - $varvalue = null; |
3232 | | - else |
3233 | | - return $isGood = false; |
3234 | | - break; |
3235 | | - case 'array': |
3236 | | - $varvalue = array(); |
3237 | | - $token = array_shift( $tokens ); |
3238 | | - if ( @$token[0] == T_WHITESPACE ) |
3239 | | - $token = array_shift( $tokens ); // discard whitespace |
3240 | | - if ( @$token != '(' ) |
3241 | | - return $isGood = false; |
3242 | | - |
3243 | | - $first = true; |
3244 | | - while( true ) { |
3245 | | - $token = array_shift( $tokens ); |
3246 | | - //if(!$first) { var_dump($token);var_dump($tokens);die(); } |
3247 | | - if ( @$token[0] == T_WHITESPACE ) |
3248 | | - $token = array_shift( $tokens ); // discard whitespace |
3249 | | - array_unshift( $tokens, $token ); |
3250 | | - //if(!$first) { var_dump($token);var_dump($tokens);die(); } |
3251 | | - $recGood = true; |
3252 | | - $key = null; |
3253 | | - $val = wfParsePHP_recursive( $tokens, $recGood ); |
3254 | | - if ( !$recGood ) |
3255 | | - return $isGood = false; |
3256 | | - //var_dump($key);var_dump($tokens);die(); |
3257 | | - $token = array_shift( $tokens ); |
3258 | | - if ( @$token[0] == T_WHITESPACE ) |
3259 | | - $token = array_shift( $tokens ); // discard whitespace |
3260 | | - if ( @$token[0] == T_DOUBLE_ARROW ) { |
3261 | | - $key = $val; |
3262 | | - //die("2"); |
3263 | | - $token = array_shift( $tokens ); // discard => |
3264 | | - if ( @$token[0] == T_WHITESPACE ) |
3265 | | - $token = array_shift( $tokens ); |
3266 | | - //die("3"); |
3267 | | - array_unshift( $tokens, $token ); |
3268 | | - //var_dump($tokens);die(); |
3269 | | - $val = wfParsePHP_recursive( $tokens, $recGood ); |
3270 | | - //var_dump($val);var_dump($tokens);die(); |
3271 | | - if ( !$recGood ) |
3272 | | - return $isGood = false; |
3273 | | - $token = array_shift( $tokens ); |
3274 | | - } |
3275 | | - |
3276 | | - if ( is_null( $key ) ) |
3277 | | - $varvalue[] = $val; |
3278 | | - else |
3279 | | - $varvalue[$key] = $val; |
3280 | | - |
3281 | | - if ( @$token[0] == T_WHITESPACE ) |
3282 | | - $token = array_shift( $tokens ); // discard whitespace |
3283 | | - //var_dump($token);var_dump($tokens);die(); |
3284 | | - if ( $token == ')' ) |
3285 | | - break; |
3286 | | - else if ( $token != ',' ) |
3287 | | - return $isGood = false; |
3288 | | - $first = false; |
3289 | | - } |
3290 | | - break; |
3291 | | - default: |
3292 | | - return $isGood = false; |
3293 | | - } |
3294 | | - return $varvalue; |
3295 | | -} |