|
7 | 7 |
|
8 | 8 | // Search for config in different places - adding constant and env |
9 | 9 | if(defined('XHPROF_CONFIG') && is_file(XHPROF_CONFIG)) { |
10 | | - require_once XHPROF_CONFIG; |
| 10 | + require_once XHPROF_CONFIG; |
11 | 11 | } |
12 | 12 | else { |
13 | | - $ENV_XHPROF_CONFIG = getenv('ENV_XHPROF_CONFIG'); |
14 | | - if(!empty($ENV_XHPROF_CONFIG) && is_file($ENV_XHPROF_CONFIG)) { |
15 | | - require_once $ENV_XHPROF_CONFIG; |
16 | | - } |
17 | | - elseif(!empty($_SERVER['ENV_XHPROF_CONFIG']) && is_file($_SERVER['ENV_XHPROF_CONFIG'])) { |
18 | | - require_once $_SERVER['ENV_XHPROF_CONFIG']; |
19 | | - } |
20 | | - else { |
21 | | - require_once (XHPROF_LIB_ROOT . "/config.php"); |
22 | | - } |
| 13 | + $ENV_XHPROF_CONFIG = getenv('ENV_XHPROF_CONFIG'); |
| 14 | + if(!empty($ENV_XHPROF_CONFIG) && is_file($ENV_XHPROF_CONFIG)) { |
| 15 | + require_once $ENV_XHPROF_CONFIG; |
| 16 | + } |
| 17 | + elseif(!empty($_SERVER['ENV_XHPROF_CONFIG']) && is_file($_SERVER['ENV_XHPROF_CONFIG'])) { |
| 18 | + require_once $_SERVER['ENV_XHPROF_CONFIG']; |
| 19 | + } |
| 20 | + else { |
| 21 | + require_once (XHPROF_LIB_ROOT . "/config.php"); |
| 22 | + } |
23 | 23 | } |
24 | 24 |
|
25 | 25 | function getExtensionName() |
@@ -49,54 +49,94 @@ function getExtensionName() |
49 | 49 | //I'm Magic :) |
50 | 50 | class visibilitator |
51 | 51 | { |
52 | | - public static function __callstatic($name, $arguments) |
53 | | - { |
54 | | - $func_name = array_shift($arguments); |
55 | | - //var_dump($name); |
56 | | - //var_dump("arguments" ,$arguments); |
57 | | - //var_dump($func_name); |
58 | | - if (is_array($func_name)) |
59 | | - { |
60 | | - list($a, $b) = $func_name; |
61 | | - if (count($arguments) == 0) |
62 | | - { |
63 | | - $arguments = $arguments[0]; |
64 | | - } |
65 | | - return call_user_func_array(array($a, $b), $arguments); |
66 | | - //echo "array call -> $b ($arguments)"; |
67 | | - }else { |
68 | | - call_user_func_array($func_name, $arguments); |
69 | | - } |
70 | | - } |
| 52 | + public static function __callstatic($name, $arguments) |
| 53 | + { |
| 54 | + $func_name = array_shift($arguments); |
| 55 | + //var_dump($name); |
| 56 | + //var_dump("arguments" ,$arguments); |
| 57 | + //var_dump($func_name); |
| 58 | + if (is_array($func_name)) |
| 59 | + { |
| 60 | + list($a, $b) = $func_name; |
| 61 | + if (count($arguments) == 0) |
| 62 | + { |
| 63 | + $arguments = $arguments[0]; |
| 64 | + } |
| 65 | + return call_user_func_array(array($a, $b), $arguments); |
| 66 | + //echo "array call -> $b ($arguments)"; |
| 67 | + }else { |
| 68 | + call_user_func_array($func_name, $arguments); |
| 69 | + } |
| 70 | + } |
71 | 71 | } |
72 | 72 |
|
73 | 73 | // Only users from authorized IP addresses may control Profiling |
74 | | -if ($controlIPs === false || in_array($_SERVER['REMOTE_ADDR'], $controlIPs) || PHP_SAPI == 'cli') |
75 | | -{ |
76 | | - /* Backwards Compatibility getparam check*/ |
77 | | - if (!isset($_xhprof['getparam'])) |
78 | | - { |
79 | | - $_xhprof['getparam'] = '_profile'; |
80 | | - } |
81 | | - |
82 | | - if (isset($_GET[$_xhprof['getparam']])) |
83 | | - { |
84 | | - //Give them a cookie to hold status, and redirect back to the same page |
85 | | - setcookie('_profile', $_GET[$_xhprof['getparam']]); |
86 | | - $newURI = str_replace(array($_xhprof['getparam'].'=1',$_xhprof['getparam'].'=0'), '', $_SERVER['REQUEST_URI']); |
87 | | - header("Location: $newURI"); |
88 | | - exit; |
89 | | - } |
90 | | - |
91 | | - if (isset($_COOKIE['_profile']) && $_COOKIE['_profile'] |
92 | | - || PHP_SAPI == 'cli' && ( (isset($_SERVER[$envVarName]) && $_SERVER[$envVarName]) |
93 | | - || (isset($_ENV[$envVarName]) && $_ENV[$envVarName]))) |
94 | | - { |
95 | | - $_xhprof['display'] = true; |
96 | | - $_xhprof['doprofile'] = true; |
97 | | - $_xhprof['type'] = 1; |
98 | | - } |
99 | | - unset($envVarName); |
| 74 | +if ($controlIPs === false || in_array($_SERVER['REMOTE_ADDR'], $controlIPs) || PHP_SAPI == 'cli') { |
| 75 | + |
| 76 | + /* Backwards Compatibility getparam check*/ |
| 77 | + if ( ! isset( $_xhprof['getparam'] ) ) { |
| 78 | + $_xhprof['getparam'] = '_profile'; |
| 79 | + } |
| 80 | + |
| 81 | + if ( ! isset( $_xhprof['displayparam'] ) ) { |
| 82 | + $_xhprof['displayparam'] = '_display'; |
| 83 | + } |
| 84 | + |
| 85 | + $handleRuntimeToggle = function ( $key, $uri, $cookieName = null ) { |
| 86 | + if ( isset( $_GET[ $key ] ) ) { |
| 87 | + if ( null === $cookieName ) { |
| 88 | + $cookieName = $key; |
| 89 | + } |
| 90 | + // Give them a cookie to hold status, and redirect back to the same page |
| 91 | + if ( $_GET[ $key ] === "1" ) { |
| 92 | + setcookie( $cookieName, $_GET[ $key ] ); |
| 93 | + } elseif ( $_GET[ $key ] === "0" ) { |
| 94 | + setcookie( $cookieName, null, - 1 ); |
| 95 | + unset( $_COOKIE[ $cookieName ] ); |
| 96 | + } |
| 97 | + |
| 98 | + $cleanURI = str_replace( array( |
| 99 | + '&' . $key . '=1', |
| 100 | + '&' . $key . '=0', |
| 101 | + '?' . $key . '=1', |
| 102 | + '?' . $key . '=0', |
| 103 | + ), '', $uri ); |
| 104 | + |
| 105 | + return [ true, $cleanURI ]; |
| 106 | + } else { |
| 107 | + return [ false, $uri ]; |
| 108 | + } |
| 109 | + }; |
| 110 | + |
| 111 | + $toggleParams = [ $_xhprof['getparam'], $_xhprof['displayparam'] ]; |
| 112 | + |
| 113 | + $currentURI = $_SERVER['REQUEST_URI']; |
| 114 | + $changes = false; |
| 115 | + foreach ( $toggleParams as $toggleParam ) { |
| 116 | + list( $changed, $currentURI ) = $handleRuntimeToggle( $toggleParam, $currentURI ); |
| 117 | + $changes = ($changes or $changed); |
| 118 | + } |
| 119 | + |
| 120 | + if ( isset( $_COOKIE[ $_xhprof['getparam'] ] ) && $_COOKIE[ $_xhprof['displayparam'] ] |
| 121 | + || PHP_SAPI == 'cli' && ( ( isset( $_SERVER[ $envVarName ] ) && $_SERVER[ $envVarName ] ) |
| 122 | + || ( isset( $_ENV[ $envVarName ] ) && $_ENV[ $envVarName ] ) ) ) { |
| 123 | + $_xhprof['doprofile'] = true; |
| 124 | + $_xhprof['type'] = 1; |
| 125 | + } |
| 126 | + |
| 127 | + if ( isset( $_COOKIE[ $_xhprof['displayparam'] ] ) && $_COOKIE[ $_xhprof['displayparam'] ] |
| 128 | + || PHP_SAPI == 'cli' && ( ( isset( $_SERVER[ $envVarName ] ) && $_SERVER[ $envVarName ] ) |
| 129 | + || ( isset( $_ENV[ $envVarName ] ) && $_ENV[ $envVarName ] ) ) ) { |
| 130 | + $_xhprof['display'] = true; |
| 131 | + } |
| 132 | + |
| 133 | + if ( true === $changes ) { |
| 134 | + header( 'HTTP/1.1 302 Found' ); |
| 135 | + header( "Location: $currentURI" ); |
| 136 | + die( "Redirecting you to " . $currentURI ); |
| 137 | + } |
| 138 | + |
| 139 | + unset( $envVarName ); |
100 | 140 | } |
101 | 141 |
|
102 | 142 |
|
|
0 commit comments