396- $customstylevar = $api->callApi('stylevar', 'get', array($parts[0], $user)); 397- //$customstylevar = vB_Api::instanceInternal('stylevar')->get($parts[0], $user); 398- return self::outputStyleVar($customstylevar[$parts[0]], $parts); 399- } 400- 401: public static function runMaths($str) 402- { 403- //this would usually be dangerous, but none of the units make sense 404- //in a math string anyway. Note that there is ambiguty between the '%' 405- //unit and the modulo operator. We don't allow the latter anyway 406- //(though we do allow bitwise operations !?) 407- $units_found = null; 408- foreach (self::$units AS $unit) 409- { 410- if (strpos($str, $unit)) 411- { 412- $units_found[] = $unit; 413- } 414- } 415- 416- //mixed units. 417- if (count($units_found) > 1) 418- { 419- return "/* ~~cannot perform math on mixed units ~~ found (" . 420- implode(",", $units_found) . ") in $str */"; 421- } 422- 423- $str = preg_replace('#([^+\-*=/\(\)\d\^<>&|\.]*)#', '', $str); 424- 425- if (empty($str)) 426- { 427- $str = '0'; 428- } 429- else 430- { 431- //hack: if the math string is invalid we can get a php parse error here. 432- //a bad expression or even a bad variable value (blank instead of a number) can 433- //cause this to occur. This fails quietly, but also sets the status code to 500 434- //(but, due to a bug in php only if display_errors is *off* -- if display errors 435- //is on, then it will work just fine only $str below will not be set. 436- // 437- //This can result is say an almost correct css file being ignored by the browser 438- //for reasons that aren't clear (and goes away if you turn error reporting on). 439- //We can check to see if eval hit a parse error and, if so, we'll attempt to 440- //clear the 500 status (this does more harm then good) and send an error 441- //to the file. Since math is mostly used in css, we'll provide error text 442- //that works best with that. 443- $status = @eval("\$str = $str;"); 444- if ($status === false) 445- { 446- if (!headers_sent()) 447- { 448- header("HTTP/1.1 200 OK"); 449- } 450- return "/* Invalid math expression */"; 451- }