@@ -154,7 +154,7 @@ |
||
154 | 154 | if ( ! is_string( $data ) ) |
155 | 155 | return false; |
156 | 156 | $data = trim( $data ); |
157 | - if ( 'N;' == $data ) |
|
157 | + if ( 'N;' == $data ) |
|
158 | 158 | return true; |
159 | 159 | $length = strlen( $data ); |
160 | 160 | if ( $length < 4 ) |
@@ -14,17 +14,17 @@ discard block |
||
14 | 14 | * @param mixed $default Optional value to return if option doesn't exist. Default false. |
15 | 15 | * @return mixed Value set for the option. |
16 | 16 | */ |
17 | -function yourls_get_option( $option_name, $default = false ) { |
|
17 | +function yourls_get_option($option_name, $default = false) { |
|
18 | 18 | // Allow plugins to short-circuit options |
19 | - $pre = yourls_apply_filter( 'shunt_option_'.$option_name, false ); |
|
20 | - if ( false !== $pre ) { |
|
19 | + $pre = yourls_apply_filter('shunt_option_'.$option_name, false); |
|
20 | + if (false !== $pre) { |
|
21 | 21 | return $pre; |
22 | 22 | } |
23 | 23 | |
24 | 24 | $option = new \YOURLS\Database\Options(yourls_get_db()); |
25 | 25 | $value = $option->get($option_name, $default); |
26 | 26 | |
27 | - return yourls_apply_filter( 'get_option_'.$option_name, $value ); |
|
27 | + return yourls_apply_filter('get_option_'.$option_name, $value); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | */ |
40 | 40 | function yourls_get_all_options() { |
41 | 41 | // Allow plugins to short-circuit all options. (Note: regular plugins are loaded after all options) |
42 | - $pre = yourls_apply_filter( 'shunt_all_options', false ); |
|
43 | - if ( false !== $pre ) { |
|
42 | + $pre = yourls_apply_filter('shunt_all_options', false); |
|
43 | + if (false !== $pre) { |
|
44 | 44 | return $pre; |
45 | 45 | } |
46 | 46 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @param mixed $newvalue Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. |
66 | 66 | * @return bool False if value was not updated, true otherwise. |
67 | 67 | */ |
68 | -function yourls_update_option( $option_name, $newvalue ) { |
|
68 | +function yourls_update_option($option_name, $newvalue) { |
|
69 | 69 | $option = new \YOURLS\Database\Options(yourls_get_db()); |
70 | 70 | $update = $option->update($option_name, $newvalue); |
71 | 71 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @param mixed $value Optional option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. |
83 | 83 | * @return bool False if option was not added and true otherwise. |
84 | 84 | */ |
85 | -function yourls_add_option( $name, $value = '' ) { |
|
85 | +function yourls_add_option($name, $value = '') { |
|
86 | 86 | $option = new \YOURLS\Database\Options(yourls_get_db()); |
87 | 87 | $add = $option->add($name, $value); |
88 | 88 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @param string $name Option name to delete. Expected to not be SQL-escaped. |
99 | 99 | * @return bool True, if option is successfully deleted. False on failure. |
100 | 100 | */ |
101 | -function yourls_delete_option( $name ) { |
|
101 | +function yourls_delete_option($name) { |
|
102 | 102 | $option = new \YOURLS\Database\Options(yourls_get_db()); |
103 | 103 | $delete = $option->delete($name); |
104 | 104 | |
@@ -112,12 +112,12 @@ discard block |
||
112 | 112 | * @param mixed $data Data that might be serialized. |
113 | 113 | * @return mixed A scalar data |
114 | 114 | */ |
115 | -function yourls_maybe_serialize( $data ) { |
|
116 | - if ( is_array( $data ) || is_object( $data ) ) |
|
117 | - return serialize( $data ); |
|
115 | +function yourls_maybe_serialize($data) { |
|
116 | + if (is_array($data) || is_object($data)) |
|
117 | + return serialize($data); |
|
118 | 118 | |
119 | - if ( yourls_is_serialized( $data, false ) ) |
|
120 | - return serialize( $data ); |
|
119 | + if (yourls_is_serialized($data, false)) |
|
120 | + return serialize($data); |
|
121 | 121 | |
122 | 122 | return $data; |
123 | 123 | } |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | * @param string $original Maybe unserialized original, if is needed. |
130 | 130 | * @return mixed Unserialized data can be any type. |
131 | 131 | */ |
132 | -function yourls_maybe_unserialize( $original ) { |
|
133 | - if ( yourls_is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in |
|
134 | - return @unserialize( $original ); |
|
132 | +function yourls_maybe_unserialize($original) { |
|
133 | + if (yourls_is_serialized($original)) // don't attempt to unserialize data that wasn't serialized going in |
|
134 | + return @unserialize($original); |
|
135 | 135 | return $original; |
136 | 136 | } |
137 | 137 | |
@@ -143,52 +143,52 @@ discard block |
||
143 | 143 | * @param bool $strict Optional. Whether to be strict about the end of the string. Defaults true. |
144 | 144 | * @return bool False if not serialized and true if it was. |
145 | 145 | */ |
146 | -function yourls_is_serialized( $data, $strict = true ) { |
|
146 | +function yourls_is_serialized($data, $strict = true) { |
|
147 | 147 | // if it isn't a string, it isn't serialized |
148 | - if ( ! is_string( $data ) ) |
|
148 | + if (!is_string($data)) |
|
149 | 149 | return false; |
150 | - $data = trim( $data ); |
|
151 | - if ( 'N;' == $data ) |
|
150 | + $data = trim($data); |
|
151 | + if ('N;' == $data) |
|
152 | 152 | return true; |
153 | - $length = strlen( $data ); |
|
154 | - if ( $length < 4 ) |
|
153 | + $length = strlen($data); |
|
154 | + if ($length < 4) |
|
155 | 155 | return false; |
156 | - if ( ':' !== $data[1] ) |
|
156 | + if (':' !== $data[1]) |
|
157 | 157 | return false; |
158 | - if ( $strict ) { |
|
159 | - $lastc = $data[ $length - 1 ]; |
|
160 | - if ( ';' !== $lastc && '}' !== $lastc ) |
|
158 | + if ($strict) { |
|
159 | + $lastc = $data[$length - 1]; |
|
160 | + if (';' !== $lastc && '}' !== $lastc) |
|
161 | 161 | return false; |
162 | 162 | } else { |
163 | - $semicolon = strpos( $data, ';' ); |
|
164 | - $brace = strpos( $data, '}' ); |
|
163 | + $semicolon = strpos($data, ';'); |
|
164 | + $brace = strpos($data, '}'); |
|
165 | 165 | // Either ; or } must exist. |
166 | - if ( false === $semicolon && false === $brace ) |
|
166 | + if (false === $semicolon && false === $brace) |
|
167 | 167 | return false; |
168 | 168 | // But neither must be in the first X characters. |
169 | - if ( false !== $semicolon && $semicolon < 3 ) |
|
169 | + if (false !== $semicolon && $semicolon < 3) |
|
170 | 170 | return false; |
171 | - if ( false !== $brace && $brace < 4 ) |
|
171 | + if (false !== $brace && $brace < 4) |
|
172 | 172 | return false; |
173 | 173 | } |
174 | 174 | $token = $data[0]; |
175 | - switch ( $token ) { |
|
175 | + switch ($token) { |
|
176 | 176 | case 's' : |
177 | - if ( $strict ) { |
|
178 | - if ( '"' !== $data[ $length - 2 ] ) |
|
177 | + if ($strict) { |
|
178 | + if ('"' !== $data[$length - 2]) |
|
179 | 179 | return false; |
180 | - } elseif ( false === strpos( $data, '"' ) ) { |
|
180 | + } elseif (false === strpos($data, '"')) { |
|
181 | 181 | return false; |
182 | 182 | } |
183 | 183 | // or else fall through |
184 | 184 | case 'a' : |
185 | 185 | case 'O' : |
186 | - return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data ); |
|
186 | + return (bool) preg_match("/^{$token}:[0-9]+:/s", $data); |
|
187 | 187 | case 'b' : |
188 | 188 | case 'i' : |
189 | 189 | case 'd' : |
190 | 190 | $end = $strict ? '$' : ''; |
191 | - return (bool) preg_match( "/^{$token}:[0-9.E-]+;$end/", $data ); |
|
191 | + return (bool) preg_match("/^{$token}:[0-9.E-]+;$end/", $data); |
|
192 | 192 | } |
193 | 193 | return false; |
194 | 194 | } |
@@ -113,11 +113,13 @@ discard block |
||
113 | 113 | * @return mixed A scalar data |
114 | 114 | */ |
115 | 115 | function yourls_maybe_serialize( $data ) { |
116 | - if ( is_array( $data ) || is_object( $data ) ) |
|
117 | - return serialize( $data ); |
|
116 | + if ( is_array( $data ) || is_object( $data ) ) { |
|
117 | + return serialize( $data ); |
|
118 | + } |
|
118 | 119 | |
119 | - if ( yourls_is_serialized( $data, false ) ) |
|
120 | - return serialize( $data ); |
|
120 | + if ( yourls_is_serialized( $data, false ) ) { |
|
121 | + return serialize( $data ); |
|
122 | + } |
|
121 | 123 | |
122 | 124 | return $data; |
123 | 125 | } |
@@ -130,8 +132,10 @@ discard block |
||
130 | 132 | * @return mixed Unserialized data can be any type. |
131 | 133 | */ |
132 | 134 | function yourls_maybe_unserialize( $original ) { |
133 | - if ( yourls_is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in |
|
135 | + if ( yourls_is_serialized( $original ) ) { |
|
136 | + // don't attempt to unserialize data that wasn't serialized going in |
|
134 | 137 | return @unserialize( $original ); |
138 | + } |
|
135 | 139 | return $original; |
136 | 140 | } |
137 | 141 | |
@@ -145,38 +149,47 @@ discard block |
||
145 | 149 | */ |
146 | 150 | function yourls_is_serialized( $data, $strict = true ) { |
147 | 151 | // if it isn't a string, it isn't serialized |
148 | - if ( ! is_string( $data ) ) |
|
149 | - return false; |
|
152 | + if ( ! is_string( $data ) ) { |
|
153 | + return false; |
|
154 | + } |
|
150 | 155 | $data = trim( $data ); |
151 | - if ( 'N;' == $data ) |
|
152 | - return true; |
|
156 | + if ( 'N;' == $data ) { |
|
157 | + return true; |
|
158 | + } |
|
153 | 159 | $length = strlen( $data ); |
154 | - if ( $length < 4 ) |
|
155 | - return false; |
|
156 | - if ( ':' !== $data[1] ) |
|
157 | - return false; |
|
160 | + if ( $length < 4 ) { |
|
161 | + return false; |
|
162 | + } |
|
163 | + if ( ':' !== $data[1] ) { |
|
164 | + return false; |
|
165 | + } |
|
158 | 166 | if ( $strict ) { |
159 | 167 | $lastc = $data[ $length - 1 ]; |
160 | - if ( ';' !== $lastc && '}' !== $lastc ) |
|
161 | - return false; |
|
168 | + if ( ';' !== $lastc && '}' !== $lastc ) { |
|
169 | + return false; |
|
170 | + } |
|
162 | 171 | } else { |
163 | 172 | $semicolon = strpos( $data, ';' ); |
164 | 173 | $brace = strpos( $data, '}' ); |
165 | 174 | // Either ; or } must exist. |
166 | - if ( false === $semicolon && false === $brace ) |
|
167 | - return false; |
|
175 | + if ( false === $semicolon && false === $brace ) { |
|
176 | + return false; |
|
177 | + } |
|
168 | 178 | // But neither must be in the first X characters. |
169 | - if ( false !== $semicolon && $semicolon < 3 ) |
|
170 | - return false; |
|
171 | - if ( false !== $brace && $brace < 4 ) |
|
172 | - return false; |
|
179 | + if ( false !== $semicolon && $semicolon < 3 ) { |
|
180 | + return false; |
|
181 | + } |
|
182 | + if ( false !== $brace && $brace < 4 ) { |
|
183 | + return false; |
|
184 | + } |
|
173 | 185 | } |
174 | 186 | $token = $data[0]; |
175 | 187 | switch ( $token ) { |
176 | 188 | case 's' : |
177 | 189 | if ( $strict ) { |
178 | - if ( '"' !== $data[ $length - 2 ] ) |
|
179 | - return false; |
|
190 | + if ( '"' !== $data[ $length - 2 ] ) { |
|
191 | + return false; |
|
192 | + } |
|
180 | 193 | } elseif ( false === strpos( $data, '"' ) ) { |
181 | 194 | return false; |
182 | 195 | } |
@@ -138,8 +138,9 @@ discard block |
||
138 | 138 | |
139 | 139 | // Allow plugins to short-circuit the whole function |
140 | 140 | $pre = yourls_apply_filter( 'shunt_send_through_proxy', null, $url ); |
141 | - if ( null !== $pre ) |
|
142 | - return $pre; |
|
141 | + if ( null !== $pre ) { |
|
142 | + return $pre; |
|
143 | + } |
|
143 | 144 | |
144 | 145 | $check = @parse_url( $url ); |
145 | 146 | |
@@ -148,15 +149,17 @@ discard block |
||
148 | 149 | } |
149 | 150 | |
150 | 151 | // Malformed URL, can not process, but this could mean ssl, so let through anyway. |
151 | - if ( $check === false ) |
|
152 | - return true; |
|
152 | + if ( $check === false ) { |
|
153 | + return true; |
|
154 | + } |
|
153 | 155 | |
154 | 156 | // Self and loopback URLs are considered local (':' is parse_url() host on '::1') |
155 | 157 | $home = parse_url( yourls_get_yourls_site() ); |
156 | 158 | $local = array( 'localhost', '127.0.0.1', '127.1', '[::1]', ':', $home['host'] ); |
157 | 159 | |
158 | - if( in_array( $check['host'], $local ) ) |
|
159 | - return false; |
|
160 | + if( in_array( $check['host'], $local ) ) { |
|
161 | + return false; |
|
162 | + } |
|
160 | 163 | |
161 | 164 | $bypass = yourls_http_get_proxy_bypass_host(); |
162 | 165 | |
@@ -182,11 +185,12 @@ discard block |
||
182 | 185 | } |
183 | 186 | } |
184 | 187 | |
185 | - if ( !empty( $wildcard_regex ) ) |
|
186 | - return !preg_match( $wildcard_regex, $check['host'] ); |
|
187 | - else |
|
188 | - return !in_array( $check['host'], $bypass_hosts ); |
|
189 | -} |
|
188 | + if ( !empty( $wildcard_regex ) ) { |
|
189 | + return !preg_match( $wildcard_regex, $check['host'] ); |
|
190 | + } else { |
|
191 | + return !in_array( $check['host'], $bypass_hosts ); |
|
192 | + } |
|
193 | + } |
|
190 | 194 | |
191 | 195 | /** |
192 | 196 | * Perform a HTTP request, return response object |
@@ -203,8 +207,9 @@ discard block |
||
203 | 207 | |
204 | 208 | // Allow plugins to short-circuit the whole function |
205 | 209 | $pre = yourls_apply_filter( 'shunt_yourls_http_request', null, $type, $url, $headers, $data, $options ); |
206 | - if ( null !== $pre ) |
|
207 | - return $pre; |
|
210 | + if ( null !== $pre ) { |
|
211 | + return $pre; |
|
212 | + } |
|
208 | 213 | |
209 | 214 | yourls_http_load_library(); |
210 | 215 | |
@@ -319,8 +324,9 @@ discard block |
||
319 | 324 | |
320 | 325 | // Send it in |
321 | 326 | $url = 'http://api.yourls.org/core/version/1.0/'; |
322 | - if( yourls_can_http_over_ssl() ) |
|
323 | - $url = yourls_set_url_scheme( $url, 'https' ); |
|
327 | + if( yourls_can_http_over_ssl() ) { |
|
328 | + $url = yourls_set_url_scheme( $url, 'https' ); |
|
329 | + } |
|
324 | 330 | $req = yourls_http_post( $url, array(), $stuff ); |
325 | 331 | |
326 | 332 | $checks->last_attempt = time(); |
@@ -386,14 +392,17 @@ discard block |
||
386 | 392 | |
387 | 393 | // Allow plugins to short-circuit the whole function |
388 | 394 | $pre = yourls_apply_filter( 'shunt_maybe_check_core_version', null ); |
389 | - if ( null !== $pre ) |
|
390 | - return $pre; |
|
395 | + if ( null !== $pre ) { |
|
396 | + return $pre; |
|
397 | + } |
|
391 | 398 | |
392 | - if( defined( 'YOURLS_NO_VERSION_CHECK' ) && YOURLS_NO_VERSION_CHECK ) |
|
393 | - return false; |
|
399 | + if( defined( 'YOURLS_NO_VERSION_CHECK' ) && YOURLS_NO_VERSION_CHECK ) { |
|
400 | + return false; |
|
401 | + } |
|
394 | 402 | |
395 | - if( !yourls_is_admin() ) |
|
396 | - return false; |
|
403 | + if( !yourls_is_admin() ) { |
|
404 | + return false; |
|
405 | + } |
|
397 | 406 | |
398 | 407 | $checks = yourls_get_option( 'core_version_checks' ); |
399 | 408 | |
@@ -411,15 +420,17 @@ discard block |
||
411 | 420 | ( $checks->failed_attempts > 0 && ( ( time() - $checks->last_attempt ) < 2 * 3600 ) ) |
412 | 421 | ) |
413 | 422 | AND ( $checks->version_checked == YOURLS_VERSION ) |
414 | - ) |
|
415 | - return false; |
|
423 | + ) { |
|
424 | + return false; |
|
425 | + } |
|
416 | 426 | |
417 | 427 | // We want to check if there's a new version |
418 | 428 | $new_check = yourls_check_core_version(); |
419 | 429 | |
420 | 430 | // Could not check for a new version, and we don't have ancient data |
421 | - if( false == $new_check && !isset( $checks->last_result->latest ) ) |
|
422 | - return false; |
|
431 | + if( false == $new_check && !isset( $checks->last_result->latest ) ) { |
|
432 | + return false; |
|
433 | + } |
|
423 | 434 | |
424 | 435 | return true; |
425 | 436 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | |
161 | 161 | $bypass = yourls_http_get_proxy_bypass_host(); |
162 | 162 | |
163 | - if( $bypass === false OR $bypass === '' ) { |
|
163 | + if( $bypass === false or $bypass === '' ) { |
|
164 | 164 | return true; |
165 | 165 | } |
166 | 166 | |
@@ -404,13 +404,13 @@ discard block |
||
404 | 404 | Otherwise, we want to check. |
405 | 405 | */ |
406 | 406 | if( !empty( $checks->last_result ) |
407 | - AND |
|
407 | + and |
|
408 | 408 | ( |
409 | 409 | ( $checks->failed_attempts == 0 && ( ( time() - $checks->last_attempt ) < 24 * 3600 ) ) |
410 | - OR |
|
410 | + or |
|
411 | 411 | ( $checks->failed_attempts > 0 && ( ( time() - $checks->last_attempt ) < 2 * 3600 ) ) |
412 | 412 | ) |
413 | - AND ( $checks->version_checked == YOURLS_VERSION ) |
|
413 | + and ( $checks->version_checked == YOURLS_VERSION ) |
|
414 | 414 | ) |
415 | 415 | return false; |
416 | 416 | |
@@ -442,6 +442,6 @@ discard block |
||
442 | 442 | $ssl_socket = extension_loaded( 'openssl' ) && function_exists( 'openssl_x509_parse' ); |
443 | 443 | } |
444 | 444 | |
445 | - return ( $ssl_curl OR $ssl_socket ); |
|
445 | + return ( $ssl_curl or $ssl_socket ); |
|
446 | 446 | } |
447 | 447 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * @return mixed Response object, or error string |
25 | 25 | */ |
26 | 26 | function yourls_http_get( $url, $headers = array(), $data = array(), $options = array() ) { |
27 | - return yourls_http_request( 'GET', $url, $headers, $data, $options ); |
|
27 | + return yourls_http_request( 'GET', $url, $headers, $data, $options ); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | * @return mixed String (page body) or null if error |
36 | 36 | */ |
37 | 37 | function yourls_http_get_body( $url, $headers = array(), $data = array(), $options = array() ) { |
38 | - $return = yourls_http_get( $url, $headers, $data, $options ); |
|
39 | - return isset( $return->body ) ? $return->body : null; |
|
38 | + $return = yourls_http_get( $url, $headers, $data, $options ); |
|
39 | + return isset( $return->body ) ? $return->body : null; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @return mixed Response object, or error string |
50 | 50 | */ |
51 | 51 | function yourls_http_post( $url, $headers = array(), $data = array(), $options = array() ) { |
52 | - return yourls_http_request( 'POST', $url, $headers, $data, $options ); |
|
52 | + return yourls_http_request( 'POST', $url, $headers, $data, $options ); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | * @return mixed String (page body) or null if error |
63 | 63 | */ |
64 | 64 | function yourls_http_post_body( $url, $headers = array(), $data = array(), $options = array() ) { |
65 | - $return = yourls_http_post( $url, $headers, $data, $options ); |
|
66 | - return isset( $return->body ) ? $return->body : null; |
|
65 | + $return = yourls_http_post( $url, $headers, $data, $options ); |
|
66 | + return isset( $return->body ) ? $return->body : null; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -108,18 +108,18 @@ discard block |
||
108 | 108 | * @return array Options |
109 | 109 | */ |
110 | 110 | function yourls_http_default_options() { |
111 | - $options = array( |
|
112 | - 'timeout' => yourls_apply_filter( 'http_default_options_timeout', 3 ), |
|
113 | - 'useragent' => yourls_http_user_agent(), |
|
114 | - 'follow_redirects' => true, |
|
115 | - 'redirects' => 3, |
|
116 | - ); |
|
117 | - |
|
118 | - if( yourls_http_get_proxy() ) { |
|
111 | + $options = array( |
|
112 | + 'timeout' => yourls_apply_filter( 'http_default_options_timeout', 3 ), |
|
113 | + 'useragent' => yourls_http_user_agent(), |
|
114 | + 'follow_redirects' => true, |
|
115 | + 'redirects' => 3, |
|
116 | + ); |
|
117 | + |
|
118 | + if( yourls_http_get_proxy() ) { |
|
119 | 119 | $options['proxy'] = yourls_http_get_proxy(); |
120 | - } |
|
120 | + } |
|
121 | 121 | |
122 | - return yourls_apply_filter( 'http_default_options', $options ); |
|
122 | + return yourls_apply_filter( 'http_default_options', $options ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -136,27 +136,27 @@ discard block |
||
136 | 136 | */ |
137 | 137 | function yourls_send_through_proxy( $url ) { |
138 | 138 | |
139 | - // Allow plugins to short-circuit the whole function |
|
140 | - $pre = yourls_apply_filter( 'shunt_send_through_proxy', null, $url ); |
|
141 | - if ( null !== $pre ) |
|
142 | - return $pre; |
|
139 | + // Allow plugins to short-circuit the whole function |
|
140 | + $pre = yourls_apply_filter( 'shunt_send_through_proxy', null, $url ); |
|
141 | + if ( null !== $pre ) |
|
142 | + return $pre; |
|
143 | 143 | |
144 | - $check = @parse_url( $url ); |
|
144 | + $check = @parse_url( $url ); |
|
145 | 145 | |
146 | 146 | if( !isset( $check['host'] ) ) { |
147 | 147 | return false; |
148 | 148 | } |
149 | 149 | |
150 | - // Malformed URL, can not process, but this could mean ssl, so let through anyway. |
|
151 | - if ( $check === false ) |
|
152 | - return true; |
|
150 | + // Malformed URL, can not process, but this could mean ssl, so let through anyway. |
|
151 | + if ( $check === false ) |
|
152 | + return true; |
|
153 | 153 | |
154 | - // Self and loopback URLs are considered local (':' is parse_url() host on '::1') |
|
155 | - $home = parse_url( yourls_get_yourls_site() ); |
|
156 | - $local = array( 'localhost', '127.0.0.1', '127.1', '[::1]', ':', $home['host'] ); |
|
154 | + // Self and loopback URLs are considered local (':' is parse_url() host on '::1') |
|
155 | + $home = parse_url( yourls_get_yourls_site() ); |
|
156 | + $local = array( 'localhost', '127.0.0.1', '127.1', '[::1]', ':', $home['host'] ); |
|
157 | 157 | |
158 | - if( in_array( $check['host'], $local ) ) |
|
159 | - return false; |
|
158 | + if( in_array( $check['host'], $local ) ) |
|
159 | + return false; |
|
160 | 160 | |
161 | 161 | $bypass = yourls_http_get_proxy_bypass_host(); |
162 | 162 | |
@@ -164,10 +164,10 @@ discard block |
||
164 | 164 | return true; |
165 | 165 | } |
166 | 166 | |
167 | - // Build array of hosts to bypass |
|
168 | - static $bypass_hosts; |
|
169 | - static $wildcard_regex = false; |
|
170 | - if ( null == $bypass_hosts ) { |
|
167 | + // Build array of hosts to bypass |
|
168 | + static $bypass_hosts; |
|
169 | + static $wildcard_regex = false; |
|
170 | + if ( null == $bypass_hosts ) { |
|
171 | 171 | $bypass_hosts = preg_split( '|\s*,\s*|', $bypass ); |
172 | 172 | |
173 | 173 | if ( false !== strpos( $bypass, '*' ) ) { |
@@ -180,12 +180,12 @@ discard block |
||
180 | 180 | } |
181 | 181 | $wildcard_regex = '/^(' . implode( '|', $wildcard_regex ) . ')$/i'; |
182 | 182 | } |
183 | - } |
|
183 | + } |
|
184 | 184 | |
185 | - if ( !empty( $wildcard_regex ) ) |
|
186 | - return !preg_match( $wildcard_regex, $check['host'] ); |
|
187 | - else |
|
188 | - return !in_array( $check['host'], $bypass_hosts ); |
|
185 | + if ( !empty( $wildcard_regex ) ) |
|
186 | + return !preg_match( $wildcard_regex, $check['host'] ); |
|
187 | + else |
|
188 | + return !in_array( $check['host'], $bypass_hosts ); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -201,26 +201,26 @@ discard block |
||
201 | 201 | */ |
202 | 202 | function yourls_http_request( $type, $url, $headers, $data, $options ) { |
203 | 203 | |
204 | - // Allow plugins to short-circuit the whole function |
|
205 | - $pre = yourls_apply_filter( 'shunt_yourls_http_request', null, $type, $url, $headers, $data, $options ); |
|
206 | - if ( null !== $pre ) |
|
207 | - return $pre; |
|
204 | + // Allow plugins to short-circuit the whole function |
|
205 | + $pre = yourls_apply_filter( 'shunt_yourls_http_request', null, $type, $url, $headers, $data, $options ); |
|
206 | + if ( null !== $pre ) |
|
207 | + return $pre; |
|
208 | 208 | |
209 | - yourls_http_load_library(); |
|
209 | + yourls_http_load_library(); |
|
210 | 210 | |
211 | - $options = array_merge( yourls_http_default_options(), $options ); |
|
211 | + $options = array_merge( yourls_http_default_options(), $options ); |
|
212 | 212 | |
213 | - if( yourls_http_get_proxy() && !yourls_send_through_proxy( $url ) ) { |
|
214 | - unset( $options['proxy'] ); |
|
215 | - } |
|
213 | + if( yourls_http_get_proxy() && !yourls_send_through_proxy( $url ) ) { |
|
214 | + unset( $options['proxy'] ); |
|
215 | + } |
|
216 | 216 | |
217 | - try { |
|
218 | - $result = Requests::request( $url, $headers, $data, $type, $options ); |
|
219 | - } catch( Requests_Exception $e ) { |
|
220 | - $result = yourls_debug_log( $e->getMessage() . ' (' . $type . ' on ' . $url . ')' ); |
|
221 | - }; |
|
217 | + try { |
|
218 | + $result = Requests::request( $url, $headers, $data, $type, $options ); |
|
219 | + } catch( Requests_Exception $e ) { |
|
220 | + $result = yourls_debug_log( $e->getMessage() . ' (' . $type . ' on ' . $url . ')' ); |
|
221 | + }; |
|
222 | 222 | |
223 | - return $result; |
|
223 | + return $result; |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | * @return string UA string |
243 | 243 | */ |
244 | 244 | function yourls_http_user_agent() { |
245 | - return yourls_apply_filter( 'http_user_agent', 'YOURLS v'.YOURLS_VERSION.' +http://yourls.org/ (running on '.yourls_get_yourls_site().')' ); |
|
245 | + return yourls_apply_filter( 'http_user_agent', 'YOURLS v'.YOURLS_VERSION.' +http://yourls.org/ (running on '.yourls_get_yourls_site().')' ); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -262,91 +262,91 @@ discard block |
||
262 | 262 | */ |
263 | 263 | function yourls_check_core_version() { |
264 | 264 | |
265 | - global $yourls_user_passwords; |
|
265 | + global $yourls_user_passwords; |
|
266 | 266 | |
267 | - $checks = yourls_get_option( 'core_version_checks' ); |
|
267 | + $checks = yourls_get_option( 'core_version_checks' ); |
|
268 | 268 | |
269 | - // Invalidate check data when YOURLS version changes |
|
270 | - if ( is_object( $checks ) && YOURLS_VERSION != $checks->version_checked ) { |
|
271 | - $checks = false; |
|
272 | - } |
|
269 | + // Invalidate check data when YOURLS version changes |
|
270 | + if ( is_object( $checks ) && YOURLS_VERSION != $checks->version_checked ) { |
|
271 | + $checks = false; |
|
272 | + } |
|
273 | 273 | |
274 | - if( !is_object( $checks ) ) { |
|
275 | - $checks = new stdClass; |
|
276 | - $checks->failed_attempts = 0; |
|
277 | - $checks->last_attempt = 0; |
|
278 | - $checks->last_result = ''; |
|
279 | - $checks->version_checked = YOURLS_VERSION; |
|
280 | - } |
|
274 | + if( !is_object( $checks ) ) { |
|
275 | + $checks = new stdClass; |
|
276 | + $checks->failed_attempts = 0; |
|
277 | + $checks->last_attempt = 0; |
|
278 | + $checks->last_result = ''; |
|
279 | + $checks->version_checked = YOURLS_VERSION; |
|
280 | + } |
|
281 | 281 | |
282 | - // Config file location ('u' for '/user' or 'i' for '/includes') |
|
283 | - $conf_loc = str_replace( YOURLS_ABSPATH, '', YOURLS_CONFIGFILE ); |
|
284 | - $conf_loc = str_replace( '/config.php', '', $conf_loc ); |
|
285 | - $conf_loc = ( $conf_loc == '/user' ? 'u' : 'i' ); |
|
282 | + // Config file location ('u' for '/user' or 'i' for '/includes') |
|
283 | + $conf_loc = str_replace( YOURLS_ABSPATH, '', YOURLS_CONFIGFILE ); |
|
284 | + $conf_loc = str_replace( '/config.php', '', $conf_loc ); |
|
285 | + $conf_loc = ( $conf_loc == '/user' ? 'u' : 'i' ); |
|
286 | 286 | |
287 | - // The collection of stuff to report |
|
288 | - $stuff = array( |
|
289 | - // Globally uniquish site identifier |
|
287 | + // The collection of stuff to report |
|
288 | + $stuff = array( |
|
289 | + // Globally uniquish site identifier |
|
290 | 290 | // This uses const YOURLS_SITE and not yourls_get_yourls_site() to prevent creating another id for an already known install |
291 | - 'md5' => md5( YOURLS_SITE . YOURLS_ABSPATH ), |
|
292 | - |
|
293 | - // Install information |
|
294 | - 'failed_attempts' => $checks->failed_attempts, |
|
295 | - 'yourls_site' => defined( 'YOURLS_SITE' ) ? yourls_get_yourls_site() : 'unknown', |
|
296 | - 'yourls_version' => defined( 'YOURLS_VERSION' ) ? YOURLS_VERSION : 'unknown', |
|
297 | - 'php_version' => PHP_VERSION, |
|
298 | - 'mysql_version' => yourls_get_db()->mysql_version(), |
|
299 | - 'locale' => yourls_get_locale(), |
|
300 | - |
|
301 | - // custom DB driver if any, and useful common PHP extensions |
|
302 | - 'db_driver' => defined( 'YOURLS_DB_DRIVER' ) ? YOURLS_DB_DRIVER : 'unset', |
|
303 | - 'db_ext_pdo' => extension_loaded( 'PDO' ) ? 1 : 0, |
|
304 | - 'db_ext_mysql' => extension_loaded( 'mysql' ) ? 1 : 0, |
|
305 | - 'db_ext_mysqli' => extension_loaded( 'mysqli' ) ? 1 : 0, |
|
306 | - 'ext_curl' => extension_loaded( 'curl' ) ? 1 : 0, |
|
307 | - |
|
308 | - // Config information |
|
309 | - 'num_users' => count( $yourls_user_passwords ), |
|
310 | - 'config_location' => $conf_loc, |
|
311 | - 'yourls_private' => defined( 'YOURLS_PRIVATE' ) && YOURLS_PRIVATE ? 1 : 0, |
|
312 | - 'yourls_unique' => defined( 'YOURLS_UNIQUE_URLS' ) && YOURLS_UNIQUE_URLS ? 1 : 0, |
|
313 | - 'yourls_url_convert' => defined( 'YOURLS_URL_CONVERT' ) ? YOURLS_URL_CONVERT : 'unknown', |
|
314 | - 'num_active_plugins' => yourls_has_active_plugins(), |
|
315 | - 'num_pages' => defined( 'YOURLS_PAGEDIR' ) ? count( (array) glob( YOURLS_PAGEDIR .'/*.php') ) : 0, |
|
316 | - ); |
|
317 | - |
|
318 | - $stuff = yourls_apply_filter( 'version_check_stuff', $stuff ); |
|
319 | - |
|
320 | - // Send it in |
|
321 | - $url = 'http://api.yourls.org/core/version/1.0/'; |
|
291 | + 'md5' => md5( YOURLS_SITE . YOURLS_ABSPATH ), |
|
292 | + |
|
293 | + // Install information |
|
294 | + 'failed_attempts' => $checks->failed_attempts, |
|
295 | + 'yourls_site' => defined( 'YOURLS_SITE' ) ? yourls_get_yourls_site() : 'unknown', |
|
296 | + 'yourls_version' => defined( 'YOURLS_VERSION' ) ? YOURLS_VERSION : 'unknown', |
|
297 | + 'php_version' => PHP_VERSION, |
|
298 | + 'mysql_version' => yourls_get_db()->mysql_version(), |
|
299 | + 'locale' => yourls_get_locale(), |
|
300 | + |
|
301 | + // custom DB driver if any, and useful common PHP extensions |
|
302 | + 'db_driver' => defined( 'YOURLS_DB_DRIVER' ) ? YOURLS_DB_DRIVER : 'unset', |
|
303 | + 'db_ext_pdo' => extension_loaded( 'PDO' ) ? 1 : 0, |
|
304 | + 'db_ext_mysql' => extension_loaded( 'mysql' ) ? 1 : 0, |
|
305 | + 'db_ext_mysqli' => extension_loaded( 'mysqli' ) ? 1 : 0, |
|
306 | + 'ext_curl' => extension_loaded( 'curl' ) ? 1 : 0, |
|
307 | + |
|
308 | + // Config information |
|
309 | + 'num_users' => count( $yourls_user_passwords ), |
|
310 | + 'config_location' => $conf_loc, |
|
311 | + 'yourls_private' => defined( 'YOURLS_PRIVATE' ) && YOURLS_PRIVATE ? 1 : 0, |
|
312 | + 'yourls_unique' => defined( 'YOURLS_UNIQUE_URLS' ) && YOURLS_UNIQUE_URLS ? 1 : 0, |
|
313 | + 'yourls_url_convert' => defined( 'YOURLS_URL_CONVERT' ) ? YOURLS_URL_CONVERT : 'unknown', |
|
314 | + 'num_active_plugins' => yourls_has_active_plugins(), |
|
315 | + 'num_pages' => defined( 'YOURLS_PAGEDIR' ) ? count( (array) glob( YOURLS_PAGEDIR .'/*.php') ) : 0, |
|
316 | + ); |
|
317 | + |
|
318 | + $stuff = yourls_apply_filter( 'version_check_stuff', $stuff ); |
|
319 | + |
|
320 | + // Send it in |
|
321 | + $url = 'http://api.yourls.org/core/version/1.0/'; |
|
322 | 322 | if( yourls_can_http_over_ssl() ) |
323 | 323 | $url = yourls_set_url_scheme( $url, 'https' ); |
324 | - $req = yourls_http_post( $url, array(), $stuff ); |
|
324 | + $req = yourls_http_post( $url, array(), $stuff ); |
|
325 | 325 | |
326 | - $checks->last_attempt = time(); |
|
327 | - $checks->version_checked = YOURLS_VERSION; |
|
326 | + $checks->last_attempt = time(); |
|
327 | + $checks->version_checked = YOURLS_VERSION; |
|
328 | 328 | |
329 | - // Unexpected results ? |
|
330 | - if( is_string( $req ) or !$req->success ) { |
|
331 | - $checks->failed_attempts = $checks->failed_attempts + 1; |
|
332 | - yourls_update_option( 'core_version_checks', $checks ); |
|
333 | - return false; |
|
334 | - } |
|
329 | + // Unexpected results ? |
|
330 | + if( is_string( $req ) or !$req->success ) { |
|
331 | + $checks->failed_attempts = $checks->failed_attempts + 1; |
|
332 | + yourls_update_option( 'core_version_checks', $checks ); |
|
333 | + return false; |
|
334 | + } |
|
335 | 335 | |
336 | - // Parse response |
|
337 | - $json = json_decode( trim( $req->body ) ); |
|
336 | + // Parse response |
|
337 | + $json = json_decode( trim( $req->body ) ); |
|
338 | 338 | |
339 | - if( yourls_validate_core_version_response($json) ) { |
|
340 | - // All went OK - mark this down |
|
341 | - $checks->failed_attempts = 0; |
|
342 | - $checks->last_result = $json; |
|
343 | - yourls_update_option( 'core_version_checks', $checks ); |
|
339 | + if( yourls_validate_core_version_response($json) ) { |
|
340 | + // All went OK - mark this down |
|
341 | + $checks->failed_attempts = 0; |
|
342 | + $checks->last_result = $json; |
|
343 | + yourls_update_option( 'core_version_checks', $checks ); |
|
344 | 344 | |
345 | - return $json; |
|
346 | - } |
|
345 | + return $json; |
|
346 | + } |
|
347 | 347 | |
348 | - // Request returned actual result, but not what we expected |
|
349 | - return false; |
|
348 | + // Request returned actual result, but not what we expected |
|
349 | + return false; |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
@@ -367,9 +367,9 @@ discard block |
||
367 | 367 | && $json->latest === yourls_sanitize_version($json->latest) |
368 | 368 | && $json->zipurl === yourls_sanitize_url($json->zipurl) |
369 | 369 | && join('.',array_slice(explode('.',parse_url($json->zipurl, PHP_URL_HOST)), -2, 2)) === 'github.com' |
370 | - // this last bit get the host ('api.github.com'), explodes on '.' (['api','github','com']) and keeps the last two elements |
|
371 | - // to make sure domain is either github.com or one of its subdomain (api.github.com for instance) |
|
372 | - // TODO: keep an eye on Github API to make sure it doesn't change some day to another domain (githubapi.com, ...) |
|
370 | + // this last bit get the host ('api.github.com'), explodes on '.' (['api','github','com']) and keeps the last two elements |
|
371 | + // to make sure domain is either github.com or one of its subdomain (api.github.com for instance) |
|
372 | + // TODO: keep an eye on Github API to make sure it doesn't change some day to another domain (githubapi.com, ...) |
|
373 | 373 | ); |
374 | 374 | } |
375 | 375 | |
@@ -384,44 +384,44 @@ discard block |
||
384 | 384 | */ |
385 | 385 | function yourls_maybe_check_core_version() { |
386 | 386 | |
387 | - // Allow plugins to short-circuit the whole function |
|
388 | - $pre = yourls_apply_filter( 'shunt_maybe_check_core_version', null ); |
|
389 | - if ( null !== $pre ) |
|
390 | - return $pre; |
|
387 | + // Allow plugins to short-circuit the whole function |
|
388 | + $pre = yourls_apply_filter( 'shunt_maybe_check_core_version', null ); |
|
389 | + if ( null !== $pre ) |
|
390 | + return $pre; |
|
391 | 391 | |
392 | - if( defined( 'YOURLS_NO_VERSION_CHECK' ) && YOURLS_NO_VERSION_CHECK ) |
|
393 | - return false; |
|
392 | + if( defined( 'YOURLS_NO_VERSION_CHECK' ) && YOURLS_NO_VERSION_CHECK ) |
|
393 | + return false; |
|
394 | 394 | |
395 | - if( !yourls_is_admin() ) |
|
396 | - return false; |
|
395 | + if( !yourls_is_admin() ) |
|
396 | + return false; |
|
397 | 397 | |
398 | - $checks = yourls_get_option( 'core_version_checks' ); |
|
398 | + $checks = yourls_get_option( 'core_version_checks' ); |
|
399 | 399 | |
400 | - /* We don't want to check if : |
|
400 | + /* We don't want to check if : |
|
401 | 401 | - last_result is set (a previous check was performed) |
402 | 402 | - and it was less than 24h ago (or less than 2h ago if it wasn't successful) |
403 | 403 | - and version checked matched version running |
404 | 404 | Otherwise, we want to check. |
405 | 405 | */ |
406 | - if( !empty( $checks->last_result ) |
|
407 | - AND |
|
408 | - ( |
|
409 | - ( $checks->failed_attempts == 0 && ( ( time() - $checks->last_attempt ) < 24 * 3600 ) ) |
|
410 | - OR |
|
411 | - ( $checks->failed_attempts > 0 && ( ( time() - $checks->last_attempt ) < 2 * 3600 ) ) |
|
412 | - ) |
|
413 | - AND ( $checks->version_checked == YOURLS_VERSION ) |
|
414 | - ) |
|
415 | - return false; |
|
416 | - |
|
417 | - // We want to check if there's a new version |
|
418 | - $new_check = yourls_check_core_version(); |
|
419 | - |
|
420 | - // Could not check for a new version, and we don't have ancient data |
|
421 | - if( false == $new_check && !isset( $checks->last_result->latest ) ) |
|
422 | - return false; |
|
423 | - |
|
424 | - return true; |
|
406 | + if( !empty( $checks->last_result ) |
|
407 | + AND |
|
408 | + ( |
|
409 | + ( $checks->failed_attempts == 0 && ( ( time() - $checks->last_attempt ) < 24 * 3600 ) ) |
|
410 | + OR |
|
411 | + ( $checks->failed_attempts > 0 && ( ( time() - $checks->last_attempt ) < 2 * 3600 ) ) |
|
412 | + ) |
|
413 | + AND ( $checks->version_checked == YOURLS_VERSION ) |
|
414 | + ) |
|
415 | + return false; |
|
416 | + |
|
417 | + // We want to check if there's a new version |
|
418 | + $new_check = yourls_check_core_version(); |
|
419 | + |
|
420 | + // Could not check for a new version, and we don't have ancient data |
|
421 | + if( false == $new_check && !isset( $checks->last_result->latest ) ) |
|
422 | + return false; |
|
423 | + |
|
424 | + return true; |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | * @see yourls_http_request |
24 | 24 | * @return mixed Response object, or error string |
25 | 25 | */ |
26 | -function yourls_http_get( $url, $headers = array(), $data = array(), $options = array() ) { |
|
27 | - return yourls_http_request( 'GET', $url, $headers, $data, $options ); |
|
26 | +function yourls_http_get($url, $headers = array(), $data = array(), $options = array()) { |
|
27 | + return yourls_http_request('GET', $url, $headers, $data, $options); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -34,9 +34,9 @@ discard block |
||
34 | 34 | * @see yourls_http_request |
35 | 35 | * @return mixed String (page body) or null if error |
36 | 36 | */ |
37 | -function yourls_http_get_body( $url, $headers = array(), $data = array(), $options = array() ) { |
|
38 | - $return = yourls_http_get( $url, $headers, $data, $options ); |
|
39 | - return isset( $return->body ) ? $return->body : null; |
|
37 | +function yourls_http_get_body($url, $headers = array(), $data = array(), $options = array()) { |
|
38 | + $return = yourls_http_get($url, $headers, $data, $options); |
|
39 | + return isset($return->body) ? $return->body : null; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | * @see yourls_http_request |
49 | 49 | * @return mixed Response object, or error string |
50 | 50 | */ |
51 | -function yourls_http_post( $url, $headers = array(), $data = array(), $options = array() ) { |
|
52 | - return yourls_http_request( 'POST', $url, $headers, $data, $options ); |
|
51 | +function yourls_http_post($url, $headers = array(), $data = array(), $options = array()) { |
|
52 | + return yourls_http_request('POST', $url, $headers, $data, $options); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | * @see yourls_http_request |
62 | 62 | * @return mixed String (page body) or null if error |
63 | 63 | */ |
64 | -function yourls_http_post_body( $url, $headers = array(), $data = array(), $options = array() ) { |
|
65 | - $return = yourls_http_post( $url, $headers, $data, $options ); |
|
66 | - return isset( $return->body ) ? $return->body : null; |
|
64 | +function yourls_http_post_body($url, $headers = array(), $data = array(), $options = array()) { |
|
65 | + $return = yourls_http_post($url, $headers, $data, $options); |
|
66 | + return isset($return->body) ? $return->body : null; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -76,14 +76,14 @@ discard block |
||
76 | 76 | function yourls_http_get_proxy() { |
77 | 77 | $proxy = false; |
78 | 78 | |
79 | - if( defined( 'YOURLS_PROXY' ) ) { |
|
79 | + if (defined('YOURLS_PROXY')) { |
|
80 | 80 | $proxy = YOURLS_PROXY; |
81 | - if( defined( 'YOURLS_PROXY_USERNAME' ) && defined( 'YOURLS_PROXY_PASSWORD' ) ) { |
|
82 | - $proxy = array( YOURLS_PROXY, YOURLS_PROXY_USERNAME, YOURLS_PROXY_PASSWORD ); |
|
81 | + if (defined('YOURLS_PROXY_USERNAME') && defined('YOURLS_PROXY_PASSWORD')) { |
|
82 | + $proxy = array(YOURLS_PROXY, YOURLS_PROXY_USERNAME, YOURLS_PROXY_PASSWORD); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
86 | - return yourls_apply_filter( 'http_get_proxy', $proxy ); |
|
86 | + return yourls_apply_filter('http_get_proxy', $proxy); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | * @return mixed false if no host defined, or string like "example.com, *.mycorp.com" |
95 | 95 | */ |
96 | 96 | function yourls_http_get_proxy_bypass_host() { |
97 | - $hosts = defined( 'YOURLS_PROXY_BYPASS_HOSTS' ) ? YOURLS_PROXY_BYPASS_HOSTS : false; |
|
97 | + $hosts = defined('YOURLS_PROXY_BYPASS_HOSTS') ? YOURLS_PROXY_BYPASS_HOSTS : false; |
|
98 | 98 | |
99 | - return yourls_apply_filter( 'http_get_proxy_bypass_host', $hosts ); |
|
99 | + return yourls_apply_filter('http_get_proxy_bypass_host', $hosts); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -109,17 +109,17 @@ discard block |
||
109 | 109 | */ |
110 | 110 | function yourls_http_default_options() { |
111 | 111 | $options = array( |
112 | - 'timeout' => yourls_apply_filter( 'http_default_options_timeout', 3 ), |
|
112 | + 'timeout' => yourls_apply_filter('http_default_options_timeout', 3), |
|
113 | 113 | 'useragent' => yourls_http_user_agent(), |
114 | 114 | 'follow_redirects' => true, |
115 | 115 | 'redirects' => 3, |
116 | 116 | ); |
117 | 117 | |
118 | - if( yourls_http_get_proxy() ) { |
|
118 | + if (yourls_http_get_proxy()) { |
|
119 | 119 | $options['proxy'] = yourls_http_get_proxy(); |
120 | 120 | } |
121 | 121 | |
122 | - return yourls_apply_filter( 'http_default_options', $options ); |
|
122 | + return yourls_apply_filter('http_default_options', $options); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -134,58 +134,58 @@ discard block |
||
134 | 134 | * @param string $url URL to check |
135 | 135 | * @return bool true to request through proxy, false to request directly |
136 | 136 | */ |
137 | -function yourls_send_through_proxy( $url ) { |
|
137 | +function yourls_send_through_proxy($url) { |
|
138 | 138 | |
139 | 139 | // Allow plugins to short-circuit the whole function |
140 | - $pre = yourls_apply_filter( 'shunt_send_through_proxy', null, $url ); |
|
141 | - if ( null !== $pre ) |
|
140 | + $pre = yourls_apply_filter('shunt_send_through_proxy', null, $url); |
|
141 | + if (null !== $pre) |
|
142 | 142 | return $pre; |
143 | 143 | |
144 | - $check = @parse_url( $url ); |
|
144 | + $check = @parse_url($url); |
|
145 | 145 | |
146 | - if( !isset( $check['host'] ) ) { |
|
146 | + if (!isset($check['host'])) { |
|
147 | 147 | return false; |
148 | 148 | } |
149 | 149 | |
150 | 150 | // Malformed URL, can not process, but this could mean ssl, so let through anyway. |
151 | - if ( $check === false ) |
|
151 | + if ($check === false) |
|
152 | 152 | return true; |
153 | 153 | |
154 | 154 | // Self and loopback URLs are considered local (':' is parse_url() host on '::1') |
155 | - $home = parse_url( yourls_get_yourls_site() ); |
|
156 | - $local = array( 'localhost', '127.0.0.1', '127.1', '[::1]', ':', $home['host'] ); |
|
155 | + $home = parse_url(yourls_get_yourls_site()); |
|
156 | + $local = array('localhost', '127.0.0.1', '127.1', '[::1]', ':', $home['host']); |
|
157 | 157 | |
158 | - if( in_array( $check['host'], $local ) ) |
|
158 | + if (in_array($check['host'], $local)) |
|
159 | 159 | return false; |
160 | 160 | |
161 | 161 | $bypass = yourls_http_get_proxy_bypass_host(); |
162 | 162 | |
163 | - if( $bypass === false OR $bypass === '' ) { |
|
163 | + if ($bypass === false OR $bypass === '') { |
|
164 | 164 | return true; |
165 | 165 | } |
166 | 166 | |
167 | 167 | // Build array of hosts to bypass |
168 | 168 | static $bypass_hosts; |
169 | 169 | static $wildcard_regex = false; |
170 | - if ( null == $bypass_hosts ) { |
|
171 | - $bypass_hosts = preg_split( '|\s*,\s*|', $bypass ); |
|
170 | + if (null == $bypass_hosts) { |
|
171 | + $bypass_hosts = preg_split('|\s*,\s*|', $bypass); |
|
172 | 172 | |
173 | - if ( false !== strpos( $bypass, '*' ) ) { |
|
173 | + if (false !== strpos($bypass, '*')) { |
|
174 | 174 | $wildcard_regex = array(); |
175 | - foreach ( $bypass_hosts as $host ) { |
|
176 | - $wildcard_regex[] = str_replace( '\*', '.+', preg_quote( $host, '/' ) ); |
|
177 | - if ( false !== strpos( $host, '*' ) ) { |
|
178 | - $wildcard_regex[] = str_replace( '\*\.', '', preg_quote( $host, '/' ) ); |
|
175 | + foreach ($bypass_hosts as $host) { |
|
176 | + $wildcard_regex[] = str_replace('\*', '.+', preg_quote($host, '/')); |
|
177 | + if (false !== strpos($host, '*')) { |
|
178 | + $wildcard_regex[] = str_replace('\*\.', '', preg_quote($host, '/')); |
|
179 | 179 | } |
180 | 180 | } |
181 | - $wildcard_regex = '/^(' . implode( '|', $wildcard_regex ) . ')$/i'; |
|
181 | + $wildcard_regex = '/^('.implode('|', $wildcard_regex).')$/i'; |
|
182 | 182 | } |
183 | 183 | } |
184 | 184 | |
185 | - if ( !empty( $wildcard_regex ) ) |
|
186 | - return !preg_match( $wildcard_regex, $check['host'] ); |
|
185 | + if (!empty($wildcard_regex)) |
|
186 | + return !preg_match($wildcard_regex, $check['host']); |
|
187 | 187 | else |
188 | - return !in_array( $check['host'], $bypass_hosts ); |
|
188 | + return !in_array($check['host'], $bypass_hosts); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -199,25 +199,25 @@ discard block |
||
199 | 199 | * @param array $options Options for the request (see /includes/Requests/Requests.php:request()) |
200 | 200 | * @return object Requests_Response object |
201 | 201 | */ |
202 | -function yourls_http_request( $type, $url, $headers, $data, $options ) { |
|
202 | +function yourls_http_request($type, $url, $headers, $data, $options) { |
|
203 | 203 | |
204 | 204 | // Allow plugins to short-circuit the whole function |
205 | - $pre = yourls_apply_filter( 'shunt_yourls_http_request', null, $type, $url, $headers, $data, $options ); |
|
206 | - if ( null !== $pre ) |
|
205 | + $pre = yourls_apply_filter('shunt_yourls_http_request', null, $type, $url, $headers, $data, $options); |
|
206 | + if (null !== $pre) |
|
207 | 207 | return $pre; |
208 | 208 | |
209 | 209 | yourls_http_load_library(); |
210 | 210 | |
211 | - $options = array_merge( yourls_http_default_options(), $options ); |
|
211 | + $options = array_merge(yourls_http_default_options(), $options); |
|
212 | 212 | |
213 | - if( yourls_http_get_proxy() && !yourls_send_through_proxy( $url ) ) { |
|
214 | - unset( $options['proxy'] ); |
|
213 | + if (yourls_http_get_proxy() && !yourls_send_through_proxy($url)) { |
|
214 | + unset($options['proxy']); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | try { |
218 | - $result = Requests::request( $url, $headers, $data, $type, $options ); |
|
219 | - } catch( Requests_Exception $e ) { |
|
220 | - $result = yourls_debug_log( $e->getMessage() . ' (' . $type . ' on ' . $url . ')' ); |
|
218 | + $result = Requests::request($url, $headers, $data, $type, $options); |
|
219 | + } catch (Requests_Exception $e) { |
|
220 | + $result = yourls_debug_log($e->getMessage().' ('.$type.' on '.$url.')'); |
|
221 | 221 | }; |
222 | 222 | |
223 | 223 | return $result; |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | * @return string UA string |
243 | 243 | */ |
244 | 244 | function yourls_http_user_agent() { |
245 | - return yourls_apply_filter( 'http_user_agent', 'YOURLS v'.YOURLS_VERSION.' +http://yourls.org/ (running on '.yourls_get_yourls_site().')' ); |
|
245 | + return yourls_apply_filter('http_user_agent', 'YOURLS v'.YOURLS_VERSION.' +http://yourls.org/ (running on '.yourls_get_yourls_site().')'); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -264,14 +264,14 @@ discard block |
||
264 | 264 | |
265 | 265 | global $yourls_user_passwords; |
266 | 266 | |
267 | - $checks = yourls_get_option( 'core_version_checks' ); |
|
267 | + $checks = yourls_get_option('core_version_checks'); |
|
268 | 268 | |
269 | 269 | // Invalidate check data when YOURLS version changes |
270 | - if ( is_object( $checks ) && YOURLS_VERSION != $checks->version_checked ) { |
|
270 | + if (is_object($checks) && YOURLS_VERSION != $checks->version_checked) { |
|
271 | 271 | $checks = false; |
272 | 272 | } |
273 | 273 | |
274 | - if( !is_object( $checks ) ) { |
|
274 | + if (!is_object($checks)) { |
|
275 | 275 | $checks = new stdClass; |
276 | 276 | $checks->failed_attempts = 0; |
277 | 277 | $checks->last_attempt = 0; |
@@ -280,67 +280,67 @@ discard block |
||
280 | 280 | } |
281 | 281 | |
282 | 282 | // Config file location ('u' for '/user' or 'i' for '/includes') |
283 | - $conf_loc = str_replace( YOURLS_ABSPATH, '', YOURLS_CONFIGFILE ); |
|
284 | - $conf_loc = str_replace( '/config.php', '', $conf_loc ); |
|
285 | - $conf_loc = ( $conf_loc == '/user' ? 'u' : 'i' ); |
|
283 | + $conf_loc = str_replace(YOURLS_ABSPATH, '', YOURLS_CONFIGFILE); |
|
284 | + $conf_loc = str_replace('/config.php', '', $conf_loc); |
|
285 | + $conf_loc = ($conf_loc == '/user' ? 'u' : 'i'); |
|
286 | 286 | |
287 | 287 | // The collection of stuff to report |
288 | 288 | $stuff = array( |
289 | 289 | // Globally uniquish site identifier |
290 | 290 | // This uses const YOURLS_SITE and not yourls_get_yourls_site() to prevent creating another id for an already known install |
291 | - 'md5' => md5( YOURLS_SITE . YOURLS_ABSPATH ), |
|
291 | + 'md5' => md5(YOURLS_SITE.YOURLS_ABSPATH), |
|
292 | 292 | |
293 | 293 | // Install information |
294 | 294 | 'failed_attempts' => $checks->failed_attempts, |
295 | - 'yourls_site' => defined( 'YOURLS_SITE' ) ? yourls_get_yourls_site() : 'unknown', |
|
296 | - 'yourls_version' => defined( 'YOURLS_VERSION' ) ? YOURLS_VERSION : 'unknown', |
|
295 | + 'yourls_site' => defined('YOURLS_SITE') ? yourls_get_yourls_site() : 'unknown', |
|
296 | + 'yourls_version' => defined('YOURLS_VERSION') ? YOURLS_VERSION : 'unknown', |
|
297 | 297 | 'php_version' => PHP_VERSION, |
298 | 298 | 'mysql_version' => yourls_get_db()->mysql_version(), |
299 | 299 | 'locale' => yourls_get_locale(), |
300 | 300 | |
301 | 301 | // custom DB driver if any, and useful common PHP extensions |
302 | - 'db_driver' => defined( 'YOURLS_DB_DRIVER' ) ? YOURLS_DB_DRIVER : 'unset', |
|
303 | - 'db_ext_pdo' => extension_loaded( 'PDO' ) ? 1 : 0, |
|
304 | - 'db_ext_mysql' => extension_loaded( 'mysql' ) ? 1 : 0, |
|
305 | - 'db_ext_mysqli' => extension_loaded( 'mysqli' ) ? 1 : 0, |
|
306 | - 'ext_curl' => extension_loaded( 'curl' ) ? 1 : 0, |
|
302 | + 'db_driver' => defined('YOURLS_DB_DRIVER') ? YOURLS_DB_DRIVER : 'unset', |
|
303 | + 'db_ext_pdo' => extension_loaded('PDO') ? 1 : 0, |
|
304 | + 'db_ext_mysql' => extension_loaded('mysql') ? 1 : 0, |
|
305 | + 'db_ext_mysqli' => extension_loaded('mysqli') ? 1 : 0, |
|
306 | + 'ext_curl' => extension_loaded('curl') ? 1 : 0, |
|
307 | 307 | |
308 | 308 | // Config information |
309 | - 'num_users' => count( $yourls_user_passwords ), |
|
309 | + 'num_users' => count($yourls_user_passwords), |
|
310 | 310 | 'config_location' => $conf_loc, |
311 | - 'yourls_private' => defined( 'YOURLS_PRIVATE' ) && YOURLS_PRIVATE ? 1 : 0, |
|
312 | - 'yourls_unique' => defined( 'YOURLS_UNIQUE_URLS' ) && YOURLS_UNIQUE_URLS ? 1 : 0, |
|
313 | - 'yourls_url_convert' => defined( 'YOURLS_URL_CONVERT' ) ? YOURLS_URL_CONVERT : 'unknown', |
|
311 | + 'yourls_private' => defined('YOURLS_PRIVATE') && YOURLS_PRIVATE ? 1 : 0, |
|
312 | + 'yourls_unique' => defined('YOURLS_UNIQUE_URLS') && YOURLS_UNIQUE_URLS ? 1 : 0, |
|
313 | + 'yourls_url_convert' => defined('YOURLS_URL_CONVERT') ? YOURLS_URL_CONVERT : 'unknown', |
|
314 | 314 | 'num_active_plugins' => yourls_has_active_plugins(), |
315 | - 'num_pages' => defined( 'YOURLS_PAGEDIR' ) ? count( (array) glob( YOURLS_PAGEDIR .'/*.php') ) : 0, |
|
315 | + 'num_pages' => defined('YOURLS_PAGEDIR') ? count((array) glob(YOURLS_PAGEDIR.'/*.php')) : 0, |
|
316 | 316 | ); |
317 | 317 | |
318 | - $stuff = yourls_apply_filter( 'version_check_stuff', $stuff ); |
|
318 | + $stuff = yourls_apply_filter('version_check_stuff', $stuff); |
|
319 | 319 | |
320 | 320 | // Send it in |
321 | 321 | $url = 'http://api.yourls.org/core/version/1.0/'; |
322 | - if( yourls_can_http_over_ssl() ) |
|
323 | - $url = yourls_set_url_scheme( $url, 'https' ); |
|
324 | - $req = yourls_http_post( $url, array(), $stuff ); |
|
322 | + if (yourls_can_http_over_ssl()) |
|
323 | + $url = yourls_set_url_scheme($url, 'https'); |
|
324 | + $req = yourls_http_post($url, array(), $stuff); |
|
325 | 325 | |
326 | 326 | $checks->last_attempt = time(); |
327 | 327 | $checks->version_checked = YOURLS_VERSION; |
328 | 328 | |
329 | 329 | // Unexpected results ? |
330 | - if( is_string( $req ) or !$req->success ) { |
|
330 | + if (is_string($req) or !$req->success) { |
|
331 | 331 | $checks->failed_attempts = $checks->failed_attempts + 1; |
332 | - yourls_update_option( 'core_version_checks', $checks ); |
|
332 | + yourls_update_option('core_version_checks', $checks); |
|
333 | 333 | return false; |
334 | 334 | } |
335 | 335 | |
336 | 336 | // Parse response |
337 | - $json = json_decode( trim( $req->body ) ); |
|
337 | + $json = json_decode(trim($req->body)); |
|
338 | 338 | |
339 | - if( yourls_validate_core_version_response($json) ) { |
|
339 | + if (yourls_validate_core_version_response($json)) { |
|
340 | 340 | // All went OK - mark this down |
341 | 341 | $checks->failed_attempts = 0; |
342 | 342 | $checks->last_result = $json; |
343 | - yourls_update_option( 'core_version_checks', $checks ); |
|
343 | + yourls_update_option('core_version_checks', $checks); |
|
344 | 344 | |
345 | 345 | return $json; |
346 | 346 | } |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | && isset($json->zipurl) |
367 | 367 | && $json->latest === yourls_sanitize_version($json->latest) |
368 | 368 | && $json->zipurl === yourls_sanitize_url($json->zipurl) |
369 | - && join('.',array_slice(explode('.',parse_url($json->zipurl, PHP_URL_HOST)), -2, 2)) === 'github.com' |
|
369 | + && join('.', array_slice(explode('.', parse_url($json->zipurl, PHP_URL_HOST)), -2, 2)) === 'github.com' |
|
370 | 370 | // this last bit get the host ('api.github.com'), explodes on '.' (['api','github','com']) and keeps the last two elements |
371 | 371 | // to make sure domain is either github.com or one of its subdomain (api.github.com for instance) |
372 | 372 | // TODO: keep an eye on Github API to make sure it doesn't change some day to another domain (githubapi.com, ...) |
@@ -385,17 +385,17 @@ discard block |
||
385 | 385 | function yourls_maybe_check_core_version() { |
386 | 386 | |
387 | 387 | // Allow plugins to short-circuit the whole function |
388 | - $pre = yourls_apply_filter( 'shunt_maybe_check_core_version', null ); |
|
389 | - if ( null !== $pre ) |
|
388 | + $pre = yourls_apply_filter('shunt_maybe_check_core_version', null); |
|
389 | + if (null !== $pre) |
|
390 | 390 | return $pre; |
391 | 391 | |
392 | - if( defined( 'YOURLS_NO_VERSION_CHECK' ) && YOURLS_NO_VERSION_CHECK ) |
|
392 | + if (defined('YOURLS_NO_VERSION_CHECK') && YOURLS_NO_VERSION_CHECK) |
|
393 | 393 | return false; |
394 | 394 | |
395 | - if( !yourls_is_admin() ) |
|
395 | + if (!yourls_is_admin()) |
|
396 | 396 | return false; |
397 | 397 | |
398 | - $checks = yourls_get_option( 'core_version_checks' ); |
|
398 | + $checks = yourls_get_option('core_version_checks'); |
|
399 | 399 | |
400 | 400 | /* We don't want to check if : |
401 | 401 | - last_result is set (a previous check was performed) |
@@ -403,14 +403,14 @@ discard block |
||
403 | 403 | - and version checked matched version running |
404 | 404 | Otherwise, we want to check. |
405 | 405 | */ |
406 | - if( !empty( $checks->last_result ) |
|
406 | + if (!empty($checks->last_result) |
|
407 | 407 | AND |
408 | 408 | ( |
409 | - ( $checks->failed_attempts == 0 && ( ( time() - $checks->last_attempt ) < 24 * 3600 ) ) |
|
409 | + ($checks->failed_attempts == 0 && ((time() - $checks->last_attempt) < 24 * 3600)) |
|
410 | 410 | OR |
411 | - ( $checks->failed_attempts > 0 && ( ( time() - $checks->last_attempt ) < 2 * 3600 ) ) |
|
411 | + ($checks->failed_attempts > 0 && ((time() - $checks->last_attempt) < 2 * 3600)) |
|
412 | 412 | ) |
413 | - AND ( $checks->version_checked == YOURLS_VERSION ) |
|
413 | + AND ($checks->version_checked == YOURLS_VERSION) |
|
414 | 414 | ) |
415 | 415 | return false; |
416 | 416 | |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | $new_check = yourls_check_core_version(); |
419 | 419 | |
420 | 420 | // Could not check for a new version, and we don't have ancient data |
421 | - if( false == $new_check && !isset( $checks->last_result->latest ) ) |
|
421 | + if (false == $new_check && !isset($checks->last_result->latest)) |
|
422 | 422 | return false; |
423 | 423 | |
424 | 424 | return true; |
@@ -433,15 +433,15 @@ discard block |
||
433 | 433 | function yourls_can_http_over_ssl() { |
434 | 434 | $ssl_curl = $ssl_socket = false; |
435 | 435 | |
436 | - if( function_exists( 'curl_exec' ) ) { |
|
437 | - $curl_version = curl_version(); |
|
438 | - $ssl_curl = ( $curl_version['features'] & CURL_VERSION_SSL ); |
|
436 | + if (function_exists('curl_exec')) { |
|
437 | + $curl_version = curl_version(); |
|
438 | + $ssl_curl = ($curl_version['features'] & CURL_VERSION_SSL); |
|
439 | 439 | } |
440 | 440 | |
441 | - if( function_exists( 'stream_socket_client' ) ) { |
|
442 | - $ssl_socket = extension_loaded( 'openssl' ) && function_exists( 'openssl_x509_parse' ); |
|
441 | + if (function_exists('stream_socket_client')) { |
|
442 | + $ssl_socket = extension_loaded('openssl') && function_exists('openssl_x509_parse'); |
|
443 | 443 | } |
444 | 444 | |
445 | - return ( $ssl_curl OR $ssl_socket ); |
|
445 | + return ($ssl_curl OR $ssl_socket); |
|
446 | 446 | } |
447 | 447 |
@@ -52,18 +52,18 @@ discard block |
||
52 | 52 | * @param array $bind_values The values bound to the statement. |
53 | 53 | * @return void |
54 | 54 | */ |
55 | - public function addProfile($duration, $function, $statement, array $bind_values = array() ) { |
|
55 | + public function addProfile($duration, $function, $statement, array $bind_values = array()) { |
|
56 | 56 | parent::addProfile($duration, $function, $statement, $bind_values); |
57 | 57 | |
58 | - if($function == 'connect') { |
|
59 | - $this->log( sprintf('SQL: CONNECT (%s s)', number_format($duration, 5)) ); |
|
58 | + if ($function == 'connect') { |
|
59 | + $this->log(sprintf('SQL: CONNECT (%s s)', number_format($duration, 5))); |
|
60 | 60 | return; |
61 | 61 | } |
62 | 62 | |
63 | 63 | // If we are emulating prepare, don't log 'prepare' statement, as they are not actual queries sent to the server |
64 | 64 | // See YDB::get_queries() for details |
65 | 65 | if ($this->ydb->get_emulate_state() && $function !== 'prepare') { |
66 | - $this->log( sprintf('SQL: %s (%s s)', $this->pretty_format($statement, $bind_values), number_format($duration, 5) ) ); |
|
66 | + $this->log(sprintf('SQL: %s (%s s)', $this->pretty_format($statement, $bind_values), number_format($duration, 5))); |
|
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @param array $values Optional array of values corresponding to placeholders |
79 | 79 | * @return string Readable SQL query with placeholders replaced |
80 | 80 | */ |
81 | - public function pretty_format($statement, array $values = array() ) { |
|
81 | + public function pretty_format($statement, array $values = array()) { |
|
82 | 82 | if (!$values) { |
83 | 83 | return $statement; |
84 | 84 | } |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | /** |
90 | 90 | * @param string $matches |
91 | 91 | */ |
92 | - function ($matches) use ($values) { |
|
93 | - $replacement = isset( $values[$matches[1]] ) ? $values[$matches[1]] : ''; |
|
94 | - if(is_array($replacement)) { |
|
92 | + function($matches) use ($values) { |
|
93 | + $replacement = isset($values[$matches[1]]) ? $values[$matches[1]] : ''; |
|
94 | + if (is_array($replacement)) { |
|
95 | 95 | $replacement = implode(",", $replacement); |
96 | 96 | } |
97 | 97 | return "'$replacement'"; |
@@ -9,12 +9,12 @@ discard block |
||
9 | 9 | * |
10 | 10 | */ |
11 | 11 | function yourls_maybe_require_auth() { |
12 | - if( yourls_is_private() ) { |
|
13 | - yourls_do_action( 'require_auth' ); |
|
14 | - require_once( YOURLS_INC.'/auth.php' ); |
|
15 | - } else { |
|
16 | - yourls_do_action( 'require_no_auth' ); |
|
17 | - } |
|
12 | + if( yourls_is_private() ) { |
|
13 | + yourls_do_action( 'require_auth' ); |
|
14 | + require_once( YOURLS_INC.'/auth.php' ); |
|
15 | + } else { |
|
16 | + yourls_do_action( 'require_no_auth' ); |
|
17 | + } |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
@@ -22,98 +22,98 @@ discard block |
||
22 | 22 | * |
23 | 23 | */ |
24 | 24 | function yourls_is_valid_user() { |
25 | - // Allow plugins to short-circuit the whole function |
|
26 | - $pre = yourls_apply_filter( 'shunt_is_valid_user', null ); |
|
27 | - if ( null !== $pre ) { |
|
28 | - return $pre; |
|
29 | - } |
|
30 | - |
|
31 | - // $unfiltered_valid : are credentials valid? Boolean value. It's "unfiltered" to allow plugins to eventually filter it. |
|
32 | - $unfiltered_valid = false; |
|
33 | - |
|
34 | - // Logout request |
|
35 | - if( isset( $_GET['action'] ) && $_GET['action'] == 'logout' ) { |
|
36 | - yourls_do_action( 'logout' ); |
|
37 | - yourls_store_cookie( null ); |
|
38 | - return yourls__( 'Logged out successfully' ); |
|
39 | - } |
|
40 | - |
|
41 | - // Check cookies or login request. Login form has precedence. |
|
42 | - |
|
43 | - yourls_do_action( 'pre_login' ); |
|
44 | - |
|
45 | - // Determine auth method and check credentials |
|
46 | - if |
|
47 | - // API only: Secure (no login or pwd) and time limited token |
|
48 | - // ?timestamp=12345678&signature=md5(totoblah12345678) |
|
49 | - ( yourls_is_API() && |
|
50 | - isset( $_REQUEST['timestamp'] ) && !empty($_REQUEST['timestamp'] ) && |
|
51 | - isset( $_REQUEST['signature'] ) && !empty($_REQUEST['signature'] ) |
|
52 | - ) |
|
53 | - { |
|
54 | - yourls_do_action( 'pre_login_signature_timestamp' ); |
|
55 | - $unfiltered_valid = yourls_check_signature_timestamp(); |
|
56 | - } |
|
57 | - |
|
58 | - elseif |
|
59 | - // API only: Secure (no login or pwd) |
|
60 | - // ?signature=md5(totoblah) |
|
61 | - ( yourls_is_API() && |
|
62 | - !isset( $_REQUEST['timestamp'] ) && |
|
63 | - isset( $_REQUEST['signature'] ) && !empty( $_REQUEST['signature'] ) |
|
64 | - ) |
|
65 | - { |
|
66 | - yourls_do_action( 'pre_login_signature' ); |
|
67 | - $unfiltered_valid = yourls_check_signature(); |
|
68 | - } |
|
69 | - |
|
70 | - elseif |
|
71 | - // API or normal: login with username & pwd |
|
72 | - ( isset( $_REQUEST['username'] ) && isset( $_REQUEST['password'] ) |
|
73 | - && !empty( $_REQUEST['username'] ) && !empty( $_REQUEST['password'] ) ) |
|
74 | - { |
|
75 | - yourls_do_action( 'pre_login_username_password' ); |
|
76 | - $unfiltered_valid = yourls_check_username_password(); |
|
77 | - } |
|
78 | - |
|
79 | - elseif |
|
80 | - // Normal only: cookies |
|
81 | - ( !yourls_is_API() && |
|
82 | - isset( $_COOKIE[ yourls_cookie_name() ] ) ) |
|
83 | - { |
|
84 | - yourls_do_action( 'pre_login_cookie' ); |
|
85 | - $unfiltered_valid = yourls_check_auth_cookie(); |
|
86 | - } |
|
87 | - |
|
88 | - // Regardless of validity, allow plugins to filter the boolean and have final word |
|
89 | - $valid = yourls_apply_filter( 'is_valid_user', $unfiltered_valid ); |
|
90 | - |
|
91 | - // Login for the win! |
|
92 | - if ( $valid ) { |
|
93 | - yourls_do_action( 'login' ); |
|
94 | - |
|
95 | - // (Re)store encrypted cookie if needed |
|
96 | - if ( !yourls_is_API() ) { |
|
97 | - yourls_store_cookie( YOURLS_USER ); |
|
98 | - |
|
99 | - // Login form : redirect to requested URL to avoid re-submitting the login form on page reload |
|
100 | - if( isset( $_REQUEST['username'] ) && isset( $_REQUEST['password'] ) && isset( $_SERVER['REQUEST_URI'] ) ) { |
|
101 | - yourls_redirect( yourls_sanitize_url_safe($_SERVER['REQUEST_URI']) ); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - // Login successful |
|
106 | - return true; |
|
107 | - } |
|
108 | - |
|
109 | - // Login failed |
|
110 | - yourls_do_action( 'login_failed' ); |
|
111 | - |
|
112 | - if ( isset( $_REQUEST['username'] ) || isset( $_REQUEST['password'] ) ) { |
|
113 | - return yourls__( 'Invalid username or password' ); |
|
114 | - } else { |
|
115 | - return yourls__( 'Please log in' ); |
|
116 | - } |
|
25 | + // Allow plugins to short-circuit the whole function |
|
26 | + $pre = yourls_apply_filter( 'shunt_is_valid_user', null ); |
|
27 | + if ( null !== $pre ) { |
|
28 | + return $pre; |
|
29 | + } |
|
30 | + |
|
31 | + // $unfiltered_valid : are credentials valid? Boolean value. It's "unfiltered" to allow plugins to eventually filter it. |
|
32 | + $unfiltered_valid = false; |
|
33 | + |
|
34 | + // Logout request |
|
35 | + if( isset( $_GET['action'] ) && $_GET['action'] == 'logout' ) { |
|
36 | + yourls_do_action( 'logout' ); |
|
37 | + yourls_store_cookie( null ); |
|
38 | + return yourls__( 'Logged out successfully' ); |
|
39 | + } |
|
40 | + |
|
41 | + // Check cookies or login request. Login form has precedence. |
|
42 | + |
|
43 | + yourls_do_action( 'pre_login' ); |
|
44 | + |
|
45 | + // Determine auth method and check credentials |
|
46 | + if |
|
47 | + // API only: Secure (no login or pwd) and time limited token |
|
48 | + // ?timestamp=12345678&signature=md5(totoblah12345678) |
|
49 | + ( yourls_is_API() && |
|
50 | + isset( $_REQUEST['timestamp'] ) && !empty($_REQUEST['timestamp'] ) && |
|
51 | + isset( $_REQUEST['signature'] ) && !empty($_REQUEST['signature'] ) |
|
52 | + ) |
|
53 | + { |
|
54 | + yourls_do_action( 'pre_login_signature_timestamp' ); |
|
55 | + $unfiltered_valid = yourls_check_signature_timestamp(); |
|
56 | + } |
|
57 | + |
|
58 | + elseif |
|
59 | + // API only: Secure (no login or pwd) |
|
60 | + // ?signature=md5(totoblah) |
|
61 | + ( yourls_is_API() && |
|
62 | + !isset( $_REQUEST['timestamp'] ) && |
|
63 | + isset( $_REQUEST['signature'] ) && !empty( $_REQUEST['signature'] ) |
|
64 | + ) |
|
65 | + { |
|
66 | + yourls_do_action( 'pre_login_signature' ); |
|
67 | + $unfiltered_valid = yourls_check_signature(); |
|
68 | + } |
|
69 | + |
|
70 | + elseif |
|
71 | + // API or normal: login with username & pwd |
|
72 | + ( isset( $_REQUEST['username'] ) && isset( $_REQUEST['password'] ) |
|
73 | + && !empty( $_REQUEST['username'] ) && !empty( $_REQUEST['password'] ) ) |
|
74 | + { |
|
75 | + yourls_do_action( 'pre_login_username_password' ); |
|
76 | + $unfiltered_valid = yourls_check_username_password(); |
|
77 | + } |
|
78 | + |
|
79 | + elseif |
|
80 | + // Normal only: cookies |
|
81 | + ( !yourls_is_API() && |
|
82 | + isset( $_COOKIE[ yourls_cookie_name() ] ) ) |
|
83 | + { |
|
84 | + yourls_do_action( 'pre_login_cookie' ); |
|
85 | + $unfiltered_valid = yourls_check_auth_cookie(); |
|
86 | + } |
|
87 | + |
|
88 | + // Regardless of validity, allow plugins to filter the boolean and have final word |
|
89 | + $valid = yourls_apply_filter( 'is_valid_user', $unfiltered_valid ); |
|
90 | + |
|
91 | + // Login for the win! |
|
92 | + if ( $valid ) { |
|
93 | + yourls_do_action( 'login' ); |
|
94 | + |
|
95 | + // (Re)store encrypted cookie if needed |
|
96 | + if ( !yourls_is_API() ) { |
|
97 | + yourls_store_cookie( YOURLS_USER ); |
|
98 | + |
|
99 | + // Login form : redirect to requested URL to avoid re-submitting the login form on page reload |
|
100 | + if( isset( $_REQUEST['username'] ) && isset( $_REQUEST['password'] ) && isset( $_SERVER['REQUEST_URI'] ) ) { |
|
101 | + yourls_redirect( yourls_sanitize_url_safe($_SERVER['REQUEST_URI']) ); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + // Login successful |
|
106 | + return true; |
|
107 | + } |
|
108 | + |
|
109 | + // Login failed |
|
110 | + yourls_do_action( 'login_failed' ); |
|
111 | + |
|
112 | + if ( isset( $_REQUEST['username'] ) || isset( $_REQUEST['password'] ) ) { |
|
113 | + return yourls__( 'Invalid username or password' ); |
|
114 | + } else { |
|
115 | + return yourls__( 'Please log in' ); |
|
116 | + } |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -121,12 +121,12 @@ discard block |
||
121 | 121 | * |
122 | 122 | */ |
123 | 123 | function yourls_check_username_password() { |
124 | - global $yourls_user_passwords; |
|
125 | - if( isset( $yourls_user_passwords[ $_REQUEST['username'] ] ) && yourls_check_password_hash( $_REQUEST['username'], $_REQUEST['password'] ) ) { |
|
126 | - yourls_set_user( $_REQUEST['username'] ); |
|
127 | - return true; |
|
128 | - } |
|
129 | - return false; |
|
124 | + global $yourls_user_passwords; |
|
125 | + if( isset( $yourls_user_passwords[ $_REQUEST['username'] ] ) && yourls_check_password_hash( $_REQUEST['username'], $_REQUEST['password'] ) ) { |
|
126 | + yourls_set_user( $_REQUEST['username'] ); |
|
127 | + return true; |
|
128 | + } |
|
129 | + return false; |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -134,24 +134,24 @@ discard block |
||
134 | 134 | * |
135 | 135 | */ |
136 | 136 | function yourls_check_password_hash( $user, $submitted_password ) { |
137 | - global $yourls_user_passwords; |
|
138 | - |
|
139 | - if( !isset( $yourls_user_passwords[ $user ] ) ) |
|
140 | - return false; |
|
141 | - |
|
142 | - if ( yourls_has_phpass_password( $user ) ) { |
|
143 | - // Stored password is hashed with phpass |
|
144 | - list( , $hash ) = explode( ':', $yourls_user_passwords[ $user ] ); |
|
145 | - $hash = str_replace( '!', '$', $hash ); |
|
146 | - return ( yourls_phpass_check( $submitted_password, $hash ) ); |
|
147 | - } else if( yourls_has_md5_password( $user ) ) { |
|
148 | - // Stored password is a salted md5 hash: "md5:<$r = rand(10000,99999)>:<md5($r.'thepassword')>" |
|
149 | - list( , $salt, ) = explode( ':', $yourls_user_passwords[ $user ] ); |
|
150 | - return( $yourls_user_passwords[ $user ] == 'md5:'.$salt.':'.md5( $salt . $submitted_password ) ); |
|
151 | - } else { |
|
152 | - // Password stored in clear text |
|
153 | - return( $yourls_user_passwords[ $user ] === $submitted_password ); |
|
154 | - } |
|
137 | + global $yourls_user_passwords; |
|
138 | + |
|
139 | + if( !isset( $yourls_user_passwords[ $user ] ) ) |
|
140 | + return false; |
|
141 | + |
|
142 | + if ( yourls_has_phpass_password( $user ) ) { |
|
143 | + // Stored password is hashed with phpass |
|
144 | + list( , $hash ) = explode( ':', $yourls_user_passwords[ $user ] ); |
|
145 | + $hash = str_replace( '!', '$', $hash ); |
|
146 | + return ( yourls_phpass_check( $submitted_password, $hash ) ); |
|
147 | + } else if( yourls_has_md5_password( $user ) ) { |
|
148 | + // Stored password is a salted md5 hash: "md5:<$r = rand(10000,99999)>:<md5($r.'thepassword')>" |
|
149 | + list( , $salt, ) = explode( ':', $yourls_user_passwords[ $user ] ); |
|
150 | + return( $yourls_user_passwords[ $user ] == 'md5:'.$salt.':'.md5( $salt . $submitted_password ) ); |
|
151 | + } else { |
|
152 | + // Password stored in clear text |
|
153 | + return( $yourls_user_passwords[ $user ] === $submitted_password ); |
|
154 | + } |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -162,52 +162,52 @@ discard block |
||
162 | 162 | * @return true if overwrite was successful, an error message otherwise |
163 | 163 | */ |
164 | 164 | function yourls_hash_passwords_now( $config_file ) { |
165 | - if( !is_readable( $config_file ) ) |
|
166 | - return 'cannot read file'; // not sure that can actually happen... |
|
167 | - |
|
168 | - if( !is_writable( $config_file ) ) |
|
169 | - return 'cannot write file'; |
|
170 | - |
|
171 | - // Include file to read value of $yourls_user_passwords |
|
172 | - // Temporary suppress error reporting to avoid notices about redeclared constants |
|
173 | - $errlevel = error_reporting(); |
|
174 | - error_reporting( 0 ); |
|
175 | - require $config_file; |
|
176 | - error_reporting( $errlevel ); |
|
177 | - |
|
178 | - $configdata = file_get_contents( $config_file ); |
|
179 | - if( $configdata == false ) |
|
180 | - return 'could not read file'; |
|
181 | - |
|
182 | - $to_hash = 0; // keep track of number of passwords that need hashing |
|
183 | - foreach ( $yourls_user_passwords as $user => $password ) { |
|
184 | - if ( !yourls_has_phpass_password( $user ) && !yourls_has_md5_password( $user ) ) { |
|
185 | - $to_hash++; |
|
186 | - $hash = yourls_phpass_hash( $password ); |
|
187 | - // PHP would interpret $ as a variable, so replace it in storage. |
|
188 | - $hash = str_replace( '$', '!', $hash ); |
|
189 | - $quotes = "'" . '"'; |
|
190 | - $pattern = "/[$quotes]${user}[$quotes]\s*=>\s*[$quotes]" . preg_quote( $password, '/' ) . "[$quotes]/"; |
|
191 | - $replace = "'$user' => 'phpass:$hash' /* Password encrypted by YOURLS */ "; |
|
192 | - $count = 0; |
|
193 | - $configdata = preg_replace( $pattern, $replace, $configdata, -1, $count ); |
|
194 | - // There should be exactly one replacement. Otherwise, fast fail. |
|
195 | - if ( $count != 1 ) { |
|
196 | - yourls_debug_log( "Problem with preg_replace for password hash of user $user" ); |
|
197 | - return 'preg_replace problem'; |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
201 | - |
|
202 | - if( $to_hash == 0 ) |
|
203 | - return 0; // There was no password to encrypt |
|
204 | - |
|
205 | - $success = file_put_contents( $config_file, $configdata ); |
|
206 | - if ( $success === FALSE ) { |
|
207 | - yourls_debug_log( 'Failed writing to ' . $config_file ); |
|
208 | - return 'could not write file'; |
|
209 | - } |
|
210 | - return true; |
|
165 | + if( !is_readable( $config_file ) ) |
|
166 | + return 'cannot read file'; // not sure that can actually happen... |
|
167 | + |
|
168 | + if( !is_writable( $config_file ) ) |
|
169 | + return 'cannot write file'; |
|
170 | + |
|
171 | + // Include file to read value of $yourls_user_passwords |
|
172 | + // Temporary suppress error reporting to avoid notices about redeclared constants |
|
173 | + $errlevel = error_reporting(); |
|
174 | + error_reporting( 0 ); |
|
175 | + require $config_file; |
|
176 | + error_reporting( $errlevel ); |
|
177 | + |
|
178 | + $configdata = file_get_contents( $config_file ); |
|
179 | + if( $configdata == false ) |
|
180 | + return 'could not read file'; |
|
181 | + |
|
182 | + $to_hash = 0; // keep track of number of passwords that need hashing |
|
183 | + foreach ( $yourls_user_passwords as $user => $password ) { |
|
184 | + if ( !yourls_has_phpass_password( $user ) && !yourls_has_md5_password( $user ) ) { |
|
185 | + $to_hash++; |
|
186 | + $hash = yourls_phpass_hash( $password ); |
|
187 | + // PHP would interpret $ as a variable, so replace it in storage. |
|
188 | + $hash = str_replace( '$', '!', $hash ); |
|
189 | + $quotes = "'" . '"'; |
|
190 | + $pattern = "/[$quotes]${user}[$quotes]\s*=>\s*[$quotes]" . preg_quote( $password, '/' ) . "[$quotes]/"; |
|
191 | + $replace = "'$user' => 'phpass:$hash' /* Password encrypted by YOURLS */ "; |
|
192 | + $count = 0; |
|
193 | + $configdata = preg_replace( $pattern, $replace, $configdata, -1, $count ); |
|
194 | + // There should be exactly one replacement. Otherwise, fast fail. |
|
195 | + if ( $count != 1 ) { |
|
196 | + yourls_debug_log( "Problem with preg_replace for password hash of user $user" ); |
|
197 | + return 'preg_replace problem'; |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | + |
|
202 | + if( $to_hash == 0 ) |
|
203 | + return 0; // There was no password to encrypt |
|
204 | + |
|
205 | + $success = file_put_contents( $config_file, $configdata ); |
|
206 | + if ( $success === FALSE ) { |
|
207 | + yourls_debug_log( 'Failed writing to ' . $config_file ); |
|
208 | + return 'could not write file'; |
|
209 | + } |
|
210 | + return true; |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -218,8 +218,8 @@ discard block |
||
218 | 218 | * @return string hashed password |
219 | 219 | */ |
220 | 220 | function yourls_phpass_hash( $password ) { |
221 | - $hasher = yourls_phpass_instance(); |
|
222 | - return $hasher->HashPassword( $password ); |
|
221 | + $hasher = yourls_phpass_instance(); |
|
222 | + return $hasher->HashPassword( $password ); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -231,8 +231,8 @@ discard block |
||
231 | 231 | * @return bool true if the hash matches the password once hashed by phpass, false otherwise |
232 | 232 | */ |
233 | 233 | function yourls_phpass_check( $password, $hash ) { |
234 | - $hasher = yourls_phpass_instance(); |
|
235 | - return $hasher->CheckPassword( $password, $hash ); |
|
234 | + $hasher = yourls_phpass_instance(); |
|
235 | + return $hasher->CheckPassword( $password, $hash ); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -244,15 +244,15 @@ discard block |
||
244 | 244 | * @return object a PasswordHash instance |
245 | 245 | */ |
246 | 246 | function yourls_phpass_instance( $iteration = 8, $portable = false ) { |
247 | - $iteration = yourls_apply_filter( 'phpass_new_instance_iteration', $iteration ); |
|
248 | - $portable = yourls_apply_filter( 'phpass_new_instance_portable', $portable ); |
|
247 | + $iteration = yourls_apply_filter( 'phpass_new_instance_iteration', $iteration ); |
|
248 | + $portable = yourls_apply_filter( 'phpass_new_instance_portable', $portable ); |
|
249 | 249 | |
250 | - static $instance = false; |
|
251 | - if( $instance == false ) { |
|
252 | - $instance = new \Ozh\Phpass\PasswordHash( $iteration, $portable ); |
|
253 | - } |
|
250 | + static $instance = false; |
|
251 | + if( $instance == false ) { |
|
252 | + $instance = new \Ozh\Phpass\PasswordHash( $iteration, $portable ); |
|
253 | + } |
|
254 | 254 | |
255 | - return $instance; |
|
255 | + return $instance; |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | |
@@ -263,13 +263,13 @@ discard block |
||
263 | 263 | * @return bool true if any passwords are cleartext |
264 | 264 | */ |
265 | 265 | function yourls_has_cleartext_passwords() { |
266 | - global $yourls_user_passwords; |
|
267 | - foreach ( $yourls_user_passwords as $user => $pwdata ) { |
|
268 | - if ( !yourls_has_md5_password( $user ) && !yourls_has_phpass_password( $user ) ) { |
|
269 | - return true; |
|
270 | - } |
|
271 | - } |
|
272 | - return false; |
|
266 | + global $yourls_user_passwords; |
|
267 | + foreach ( $yourls_user_passwords as $user => $pwdata ) { |
|
268 | + if ( !yourls_has_md5_password( $user ) && !yourls_has_phpass_password( $user ) ) { |
|
269 | + return true; |
|
270 | + } |
|
271 | + } |
|
272 | + return false; |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -283,11 +283,11 @@ discard block |
||
283 | 283 | * @return bool true if password hashed, false otherwise |
284 | 284 | */ |
285 | 285 | function yourls_has_md5_password( $user ) { |
286 | - global $yourls_user_passwords; |
|
287 | - return( isset( $yourls_user_passwords[ $user ] ) |
|
288 | - && substr( $yourls_user_passwords[ $user ], 0, 4 ) == 'md5:' |
|
289 | - && strlen( $yourls_user_passwords[ $user ] ) == 42 // http://www.google.com/search?q=the+answer+to+life+the+universe+and+everything |
|
290 | - ); |
|
286 | + global $yourls_user_passwords; |
|
287 | + return( isset( $yourls_user_passwords[ $user ] ) |
|
288 | + && substr( $yourls_user_passwords[ $user ], 0, 4 ) == 'md5:' |
|
289 | + && strlen( $yourls_user_passwords[ $user ] ) == 42 // http://www.google.com/search?q=the+answer+to+life+the+universe+and+everything |
|
290 | + ); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
@@ -301,10 +301,10 @@ discard block |
||
301 | 301 | * @return bool true if password hashed with PHPASS, otherwise false |
302 | 302 | */ |
303 | 303 | function yourls_has_phpass_password( $user ) { |
304 | - global $yourls_user_passwords; |
|
305 | - return( isset( $yourls_user_passwords[ $user ] ) |
|
306 | - && substr( $yourls_user_passwords[ $user ], 0, 7 ) == 'phpass:' |
|
307 | - ); |
|
304 | + global $yourls_user_passwords; |
|
305 | + return( isset( $yourls_user_passwords[ $user ] ) |
|
306 | + && substr( $yourls_user_passwords[ $user ], 0, 7 ) == 'phpass:' |
|
307 | + ); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -312,14 +312,14 @@ discard block |
||
312 | 312 | * |
313 | 313 | */ |
314 | 314 | function yourls_check_auth_cookie() { |
315 | - global $yourls_user_passwords; |
|
316 | - foreach( $yourls_user_passwords as $valid_user => $valid_password ) { |
|
317 | - if ( yourls_cookie_value( $valid_user ) === $_COOKIE[ yourls_cookie_name() ] ) { |
|
318 | - yourls_set_user( $valid_user ); |
|
319 | - return true; |
|
320 | - } |
|
321 | - } |
|
322 | - return false; |
|
315 | + global $yourls_user_passwords; |
|
316 | + foreach( $yourls_user_passwords as $valid_user => $valid_password ) { |
|
317 | + if ( yourls_cookie_value( $valid_user ) === $_COOKIE[ yourls_cookie_name() ] ) { |
|
318 | + yourls_set_user( $valid_user ); |
|
319 | + return true; |
|
320 | + } |
|
321 | + } |
|
322 | + return false; |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
@@ -353,21 +353,21 @@ discard block |
||
353 | 353 | return false; |
354 | 354 | } |
355 | 355 | |
356 | - // Check signature & timestamp against all possible users |
|
357 | - global $yourls_user_passwords; |
|
358 | - foreach( $yourls_user_passwords as $valid_user => $valid_password ) { |
|
359 | - if ( |
|
356 | + // Check signature & timestamp against all possible users |
|
357 | + global $yourls_user_passwords; |
|
358 | + foreach( $yourls_user_passwords as $valid_user => $valid_password ) { |
|
359 | + if ( |
|
360 | 360 | hash( $hash_function, $_REQUEST['timestamp'].yourls_auth_signature( $valid_user ) ) === $_REQUEST['signature'] |
361 | 361 | or |
362 | 362 | hash( $hash_function, yourls_auth_signature( $valid_user ).$_REQUEST['timestamp'] ) === $_REQUEST['signature'] |
363 | - ) { |
|
364 | - yourls_set_user( $valid_user ); |
|
365 | - return true; |
|
366 | - } |
|
367 | - } |
|
363 | + ) { |
|
364 | + yourls_set_user( $valid_user ); |
|
365 | + return true; |
|
366 | + } |
|
367 | + } |
|
368 | 368 | |
369 | 369 | // Signature doesn't match known user |
370 | - return false; |
|
370 | + return false; |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
@@ -380,17 +380,17 @@ discard block |
||
380 | 380 | if( !isset( $_REQUEST['signature'] ) OR empty( $_REQUEST['signature'] ) ) |
381 | 381 | return false; |
382 | 382 | |
383 | - // Check signature against all possible users |
|
383 | + // Check signature against all possible users |
|
384 | 384 | global $yourls_user_passwords; |
385 | - foreach( $yourls_user_passwords as $valid_user => $valid_password ) { |
|
386 | - if ( yourls_auth_signature( $valid_user ) === $_REQUEST['signature'] ) { |
|
387 | - yourls_set_user( $valid_user ); |
|
388 | - return true; |
|
389 | - } |
|
390 | - } |
|
385 | + foreach( $yourls_user_passwords as $valid_user => $valid_password ) { |
|
386 | + if ( yourls_auth_signature( $valid_user ) === $_REQUEST['signature'] ) { |
|
387 | + yourls_set_user( $valid_user ); |
|
388 | + return true; |
|
389 | + } |
|
390 | + } |
|
391 | 391 | |
392 | 392 | // Signature doesn't match known user |
393 | - return false; |
|
393 | + return false; |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
@@ -398,10 +398,10 @@ discard block |
||
398 | 398 | * |
399 | 399 | */ |
400 | 400 | function yourls_auth_signature( $username = false ) { |
401 | - if( !$username && defined('YOURLS_USER') ) { |
|
402 | - $username = YOURLS_USER; |
|
403 | - } |
|
404 | - return ( $username ? substr( yourls_salt( $username ), 0, 10 ) : 'Cannot generate auth signature: no username' ); |
|
401 | + if( !$username && defined('YOURLS_USER') ) { |
|
402 | + $username = YOURLS_USER; |
|
403 | + } |
|
404 | + return ( $username ? substr( yourls_salt( $username ), 0, 10 ) : 'Cannot generate auth signature: no username' ); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | /** |
@@ -409,9 +409,9 @@ discard block |
||
409 | 409 | * |
410 | 410 | */ |
411 | 411 | function yourls_check_timestamp( $time ) { |
412 | - $now = time(); |
|
413 | - // Allow timestamp to be a little in the future or the past -- see Issue 766 |
|
414 | - return yourls_apply_filter( 'check_timestamp', abs( $now - (int)$time ) < yourls_get_nonce_life(), $time ); |
|
412 | + $now = time(); |
|
413 | + // Allow timestamp to be a little in the future or the past -- see Issue 766 |
|
414 | + return yourls_apply_filter( 'check_timestamp', abs( $now - (int)$time ) < yourls_get_nonce_life(), $time ); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | /** |
@@ -422,28 +422,28 @@ discard block |
||
422 | 422 | function yourls_store_cookie( $user = null ) { |
423 | 423 | |
424 | 424 | // No user will delete the cookie with a cookie time from the past |
425 | - if( !$user ) { |
|
426 | - $time = time() - 3600; |
|
427 | - } else { |
|
428 | - $time = time() + yourls_get_cookie_life(); |
|
429 | - } |
|
425 | + if( !$user ) { |
|
426 | + $time = time() - 3600; |
|
427 | + } else { |
|
428 | + $time = time() + yourls_get_cookie_life(); |
|
429 | + } |
|
430 | 430 | |
431 | 431 | $path = yourls_apply_filter( 'setcookie_path', '/' ); |
432 | - $domain = yourls_apply_filter( 'setcookie_domain', parse_url( yourls_get_yourls_site(), PHP_URL_HOST ) ); |
|
433 | - $secure = yourls_apply_filter( 'setcookie_secure', yourls_is_ssl() ); |
|
434 | - $httponly = yourls_apply_filter( 'setcookie_httponly', true ); |
|
432 | + $domain = yourls_apply_filter( 'setcookie_domain', parse_url( yourls_get_yourls_site(), PHP_URL_HOST ) ); |
|
433 | + $secure = yourls_apply_filter( 'setcookie_secure', yourls_is_ssl() ); |
|
434 | + $httponly = yourls_apply_filter( 'setcookie_httponly', true ); |
|
435 | 435 | |
436 | - // Some browsers refuse to store localhost cookie |
|
437 | - if ( $domain == 'localhost' ) |
|
438 | - $domain = ''; |
|
436 | + // Some browsers refuse to store localhost cookie |
|
437 | + if ( $domain == 'localhost' ) |
|
438 | + $domain = ''; |
|
439 | 439 | |
440 | 440 | if ( !headers_sent( $filename, $linenum ) ) { |
441 | 441 | yourls_setcookie( yourls_cookie_name(), yourls_cookie_value( $user ), $time, $path, $domain, $secure, $httponly ); |
442 | - } else { |
|
443 | - // For some reason cookies were not stored: action to be able to debug that |
|
444 | - yourls_do_action( 'setcookie_failed', $user ); |
|
442 | + } else { |
|
443 | + // For some reason cookies were not stored: action to be able to debug that |
|
444 | + yourls_do_action( 'setcookie_failed', $user ); |
|
445 | 445 | yourls_debug_log( "Could not store cookie: headers already sent in $filename on line $linenum" ); |
446 | - } |
|
446 | + } |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -487,8 +487,8 @@ discard block |
||
487 | 487 | * |
488 | 488 | */ |
489 | 489 | function yourls_set_user( $user ) { |
490 | - if( !defined( 'YOURLS_USER' ) ) |
|
491 | - define( 'YOURLS_USER', $user ); |
|
490 | + if( !defined( 'YOURLS_USER' ) ) |
|
491 | + define( 'YOURLS_USER', $user ); |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | /** |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | * @return integer cookie life span, in seconds |
503 | 503 | */ |
504 | 504 | function yourls_get_cookie_life() { |
505 | - return yourls_apply_filter( 'get_cookie_life', YOURLS_COOKIE_LIFE ); |
|
505 | + return yourls_apply_filter( 'get_cookie_life', YOURLS_COOKIE_LIFE ); |
|
506 | 506 | } |
507 | 507 | |
508 | 508 | /** |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | * @return integer nonce life span, in seconds |
518 | 518 | */ |
519 | 519 | function yourls_get_nonce_life() { |
520 | - return yourls_apply_filter( 'get_nonce_life', YOURLS_NONCE_LIFE ); |
|
520 | + return yourls_apply_filter( 'get_nonce_life', YOURLS_NONCE_LIFE ); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | /** |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | * @return string cookie value |
543 | 543 | */ |
544 | 544 | function yourls_cookie_value( $user ) { |
545 | - return yourls_apply_filter( 'set_cookie_value', yourls_salt( $user ), $user ); |
|
545 | + return yourls_apply_filter( 'set_cookie_value', yourls_salt( $user ), $user ); |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | * |
553 | 553 | */ |
554 | 554 | function yourls_tick() { |
555 | - return ceil( time() / yourls_get_nonce_life() ); |
|
555 | + return ceil( time() / yourls_get_nonce_life() ); |
|
556 | 556 | } |
557 | 557 | |
558 | 558 | /** |
@@ -560,8 +560,8 @@ discard block |
||
560 | 560 | * |
561 | 561 | */ |
562 | 562 | function yourls_salt( $string ) { |
563 | - $salt = defined('YOURLS_COOKIEKEY') ? YOURLS_COOKIEKEY : md5(__FILE__) ; |
|
564 | - return yourls_apply_filter( 'yourls_salt', md5 ($string . $salt), $string ); |
|
563 | + $salt = defined('YOURLS_COOKIEKEY') ? YOURLS_COOKIEKEY : md5(__FILE__) ; |
|
564 | + return yourls_apply_filter( 'yourls_salt', md5 ($string . $salt), $string ); |
|
565 | 565 | } |
566 | 566 | |
567 | 567 | /** |
@@ -569,12 +569,12 @@ discard block |
||
569 | 569 | * |
570 | 570 | */ |
571 | 571 | function yourls_create_nonce( $action, $user = false ) { |
572 | - if( false == $user ) |
|
573 | - $user = defined( 'YOURLS_USER' ) ? YOURLS_USER : '-1'; |
|
574 | - $tick = yourls_tick(); |
|
575 | - $nonce = substr( yourls_salt($tick . $action . $user), 0, 10 ); |
|
576 | - // Allow plugins to alter the nonce |
|
577 | - return yourls_apply_filter( 'create_nonce', $nonce, $action, $user ); |
|
572 | + if( false == $user ) |
|
573 | + $user = defined( 'YOURLS_USER' ) ? YOURLS_USER : '-1'; |
|
574 | + $tick = yourls_tick(); |
|
575 | + $nonce = substr( yourls_salt($tick . $action . $user), 0, 10 ); |
|
576 | + // Allow plugins to alter the nonce |
|
577 | + return yourls_apply_filter( 'create_nonce', $nonce, $action, $user ); |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | /** |
@@ -582,10 +582,10 @@ discard block |
||
582 | 582 | * |
583 | 583 | */ |
584 | 584 | function yourls_nonce_field( $action, $name = 'nonce', $user = false, $echo = true ) { |
585 | - $field = '<input type="hidden" id="'.$name.'" name="'.$name.'" value="'.yourls_create_nonce( $action, $user ).'" />'; |
|
586 | - if( $echo ) |
|
587 | - echo $field."\n"; |
|
588 | - return $field; |
|
585 | + $field = '<input type="hidden" id="'.$name.'" name="'.$name.'" value="'.yourls_create_nonce( $action, $user ).'" />'; |
|
586 | + if( $echo ) |
|
587 | + echo $field."\n"; |
|
588 | + return $field; |
|
589 | 589 | } |
590 | 590 | |
591 | 591 | /** |
@@ -593,8 +593,8 @@ discard block |
||
593 | 593 | * |
594 | 594 | */ |
595 | 595 | function yourls_nonce_url( $action, $url = false, $name = 'nonce', $user = false ) { |
596 | - $nonce = yourls_create_nonce( $action, $user ); |
|
597 | - return yourls_add_query_arg( $name, $nonce, $url ); |
|
596 | + $nonce = yourls_create_nonce( $action, $user ); |
|
597 | + return yourls_add_query_arg( $name, $nonce, $url ); |
|
598 | 598 | } |
599 | 599 | |
600 | 600 | /** |
@@ -605,28 +605,28 @@ discard block |
||
605 | 605 | * |
606 | 606 | */ |
607 | 607 | function yourls_verify_nonce( $action, $nonce = false, $user = false, $return = '' ) { |
608 | - // get user |
|
609 | - if( false == $user ) |
|
610 | - $user = defined( 'YOURLS_USER' ) ? YOURLS_USER : '-1'; |
|
611 | - |
|
612 | - // get current nonce value |
|
613 | - if( false == $nonce && isset( $_REQUEST['nonce'] ) ) |
|
614 | - $nonce = $_REQUEST['nonce']; |
|
615 | - |
|
616 | - // Allow plugins to short-circuit the rest of the function |
|
617 | - $valid = yourls_apply_filter( 'verify_nonce', false, $action, $nonce, $user, $return ); |
|
618 | - if ($valid) { |
|
619 | - return true; |
|
620 | - } |
|
621 | - |
|
622 | - // what nonce should be |
|
623 | - $valid = yourls_create_nonce( $action, $user ); |
|
624 | - |
|
625 | - if( $nonce == $valid ) { |
|
626 | - return true; |
|
627 | - } else { |
|
628 | - if( $return ) |
|
629 | - die( $return ); |
|
630 | - yourls_die( yourls__( 'Unauthorized action or expired link' ), yourls__( 'Error' ), 403 ); |
|
631 | - } |
|
608 | + // get user |
|
609 | + if( false == $user ) |
|
610 | + $user = defined( 'YOURLS_USER' ) ? YOURLS_USER : '-1'; |
|
611 | + |
|
612 | + // get current nonce value |
|
613 | + if( false == $nonce && isset( $_REQUEST['nonce'] ) ) |
|
614 | + $nonce = $_REQUEST['nonce']; |
|
615 | + |
|
616 | + // Allow plugins to short-circuit the rest of the function |
|
617 | + $valid = yourls_apply_filter( 'verify_nonce', false, $action, $nonce, $user, $return ); |
|
618 | + if ($valid) { |
|
619 | + return true; |
|
620 | + } |
|
621 | + |
|
622 | + // what nonce should be |
|
623 | + $valid = yourls_create_nonce( $action, $user ); |
|
624 | + |
|
625 | + if( $nonce == $valid ) { |
|
626 | + return true; |
|
627 | + } else { |
|
628 | + if( $return ) |
|
629 | + die( $return ); |
|
630 | + yourls_die( yourls__( 'Unauthorized action or expired link' ), yourls__( 'Error' ), 403 ); |
|
631 | + } |
|
632 | 632 | } |
@@ -9,11 +9,11 @@ discard block |
||
9 | 9 | * |
10 | 10 | */ |
11 | 11 | function yourls_maybe_require_auth() { |
12 | - if( yourls_is_private() ) { |
|
13 | - yourls_do_action( 'require_auth' ); |
|
14 | - require_once( YOURLS_INC.'/auth.php' ); |
|
12 | + if (yourls_is_private()) { |
|
13 | + yourls_do_action('require_auth'); |
|
14 | + require_once(YOURLS_INC.'/auth.php'); |
|
15 | 15 | } else { |
16 | - yourls_do_action( 'require_no_auth' ); |
|
16 | + yourls_do_action('require_no_auth'); |
|
17 | 17 | } |
18 | 18 | } |
19 | 19 | |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | */ |
24 | 24 | function yourls_is_valid_user() { |
25 | 25 | // Allow plugins to short-circuit the whole function |
26 | - $pre = yourls_apply_filter( 'shunt_is_valid_user', null ); |
|
27 | - if ( null !== $pre ) { |
|
26 | + $pre = yourls_apply_filter('shunt_is_valid_user', null); |
|
27 | + if (null !== $pre) { |
|
28 | 28 | return $pre; |
29 | 29 | } |
30 | 30 | |
@@ -32,73 +32,73 @@ discard block |
||
32 | 32 | $unfiltered_valid = false; |
33 | 33 | |
34 | 34 | // Logout request |
35 | - if( isset( $_GET['action'] ) && $_GET['action'] == 'logout' ) { |
|
36 | - yourls_do_action( 'logout' ); |
|
37 | - yourls_store_cookie( null ); |
|
38 | - return yourls__( 'Logged out successfully' ); |
|
35 | + if (isset($_GET['action']) && $_GET['action'] == 'logout') { |
|
36 | + yourls_do_action('logout'); |
|
37 | + yourls_store_cookie(null); |
|
38 | + return yourls__('Logged out successfully'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | // Check cookies or login request. Login form has precedence. |
42 | 42 | |
43 | - yourls_do_action( 'pre_login' ); |
|
43 | + yourls_do_action('pre_login'); |
|
44 | 44 | |
45 | 45 | // Determine auth method and check credentials |
46 | 46 | if |
47 | 47 | // API only: Secure (no login or pwd) and time limited token |
48 | 48 | // ?timestamp=12345678&signature=md5(totoblah12345678) |
49 | - ( yourls_is_API() && |
|
50 | - isset( $_REQUEST['timestamp'] ) && !empty($_REQUEST['timestamp'] ) && |
|
51 | - isset( $_REQUEST['signature'] ) && !empty($_REQUEST['signature'] ) |
|
49 | + (yourls_is_API() && |
|
50 | + isset($_REQUEST['timestamp']) && !empty($_REQUEST['timestamp']) && |
|
51 | + isset($_REQUEST['signature']) && !empty($_REQUEST['signature']) |
|
52 | 52 | ) |
53 | 53 | { |
54 | - yourls_do_action( 'pre_login_signature_timestamp' ); |
|
54 | + yourls_do_action('pre_login_signature_timestamp'); |
|
55 | 55 | $unfiltered_valid = yourls_check_signature_timestamp(); |
56 | 56 | } |
57 | 57 | |
58 | 58 | elseif |
59 | 59 | // API only: Secure (no login or pwd) |
60 | 60 | // ?signature=md5(totoblah) |
61 | - ( yourls_is_API() && |
|
62 | - !isset( $_REQUEST['timestamp'] ) && |
|
63 | - isset( $_REQUEST['signature'] ) && !empty( $_REQUEST['signature'] ) |
|
61 | + (yourls_is_API() && |
|
62 | + !isset($_REQUEST['timestamp']) && |
|
63 | + isset($_REQUEST['signature']) && !empty($_REQUEST['signature']) |
|
64 | 64 | ) |
65 | 65 | { |
66 | - yourls_do_action( 'pre_login_signature' ); |
|
66 | + yourls_do_action('pre_login_signature'); |
|
67 | 67 | $unfiltered_valid = yourls_check_signature(); |
68 | 68 | } |
69 | 69 | |
70 | 70 | elseif |
71 | 71 | // API or normal: login with username & pwd |
72 | - ( isset( $_REQUEST['username'] ) && isset( $_REQUEST['password'] ) |
|
73 | - && !empty( $_REQUEST['username'] ) && !empty( $_REQUEST['password'] ) ) |
|
72 | + (isset($_REQUEST['username']) && isset($_REQUEST['password']) |
|
73 | + && !empty($_REQUEST['username']) && !empty($_REQUEST['password'])) |
|
74 | 74 | { |
75 | - yourls_do_action( 'pre_login_username_password' ); |
|
75 | + yourls_do_action('pre_login_username_password'); |
|
76 | 76 | $unfiltered_valid = yourls_check_username_password(); |
77 | 77 | } |
78 | 78 | |
79 | 79 | elseif |
80 | 80 | // Normal only: cookies |
81 | - ( !yourls_is_API() && |
|
82 | - isset( $_COOKIE[ yourls_cookie_name() ] ) ) |
|
81 | + (!yourls_is_API() && |
|
82 | + isset($_COOKIE[yourls_cookie_name()])) |
|
83 | 83 | { |
84 | - yourls_do_action( 'pre_login_cookie' ); |
|
84 | + yourls_do_action('pre_login_cookie'); |
|
85 | 85 | $unfiltered_valid = yourls_check_auth_cookie(); |
86 | 86 | } |
87 | 87 | |
88 | 88 | // Regardless of validity, allow plugins to filter the boolean and have final word |
89 | - $valid = yourls_apply_filter( 'is_valid_user', $unfiltered_valid ); |
|
89 | + $valid = yourls_apply_filter('is_valid_user', $unfiltered_valid); |
|
90 | 90 | |
91 | 91 | // Login for the win! |
92 | - if ( $valid ) { |
|
93 | - yourls_do_action( 'login' ); |
|
92 | + if ($valid) { |
|
93 | + yourls_do_action('login'); |
|
94 | 94 | |
95 | 95 | // (Re)store encrypted cookie if needed |
96 | - if ( !yourls_is_API() ) { |
|
97 | - yourls_store_cookie( YOURLS_USER ); |
|
96 | + if (!yourls_is_API()) { |
|
97 | + yourls_store_cookie(YOURLS_USER); |
|
98 | 98 | |
99 | 99 | // Login form : redirect to requested URL to avoid re-submitting the login form on page reload |
100 | - if( isset( $_REQUEST['username'] ) && isset( $_REQUEST['password'] ) && isset( $_SERVER['REQUEST_URI'] ) ) { |
|
101 | - yourls_redirect( yourls_sanitize_url_safe($_SERVER['REQUEST_URI']) ); |
|
100 | + if (isset($_REQUEST['username']) && isset($_REQUEST['password']) && isset($_SERVER['REQUEST_URI'])) { |
|
101 | + yourls_redirect(yourls_sanitize_url_safe($_SERVER['REQUEST_URI'])); |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
@@ -107,12 +107,12 @@ discard block |
||
107 | 107 | } |
108 | 108 | |
109 | 109 | // Login failed |
110 | - yourls_do_action( 'login_failed' ); |
|
110 | + yourls_do_action('login_failed'); |
|
111 | 111 | |
112 | - if ( isset( $_REQUEST['username'] ) || isset( $_REQUEST['password'] ) ) { |
|
113 | - return yourls__( 'Invalid username or password' ); |
|
112 | + if (isset($_REQUEST['username']) || isset($_REQUEST['password'])) { |
|
113 | + return yourls__('Invalid username or password'); |
|
114 | 114 | } else { |
115 | - return yourls__( 'Please log in' ); |
|
115 | + return yourls__('Please log in'); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | */ |
123 | 123 | function yourls_check_username_password() { |
124 | 124 | global $yourls_user_passwords; |
125 | - if( isset( $yourls_user_passwords[ $_REQUEST['username'] ] ) && yourls_check_password_hash( $_REQUEST['username'], $_REQUEST['password'] ) ) { |
|
126 | - yourls_set_user( $_REQUEST['username'] ); |
|
125 | + if (isset($yourls_user_passwords[$_REQUEST['username']]) && yourls_check_password_hash($_REQUEST['username'], $_REQUEST['password'])) { |
|
126 | + yourls_set_user($_REQUEST['username']); |
|
127 | 127 | return true; |
128 | 128 | } |
129 | 129 | return false; |
@@ -133,24 +133,24 @@ discard block |
||
133 | 133 | * Check a submitted password sent in plain text against stored password which can be a salted hash |
134 | 134 | * |
135 | 135 | */ |
136 | -function yourls_check_password_hash( $user, $submitted_password ) { |
|
136 | +function yourls_check_password_hash($user, $submitted_password) { |
|
137 | 137 | global $yourls_user_passwords; |
138 | 138 | |
139 | - if( !isset( $yourls_user_passwords[ $user ] ) ) |
|
139 | + if (!isset($yourls_user_passwords[$user])) |
|
140 | 140 | return false; |
141 | 141 | |
142 | - if ( yourls_has_phpass_password( $user ) ) { |
|
142 | + if (yourls_has_phpass_password($user)) { |
|
143 | 143 | // Stored password is hashed with phpass |
144 | - list( , $hash ) = explode( ':', $yourls_user_passwords[ $user ] ); |
|
145 | - $hash = str_replace( '!', '$', $hash ); |
|
146 | - return ( yourls_phpass_check( $submitted_password, $hash ) ); |
|
147 | - } else if( yourls_has_md5_password( $user ) ) { |
|
144 | + list(, $hash) = explode(':', $yourls_user_passwords[$user]); |
|
145 | + $hash = str_replace('!', '$', $hash); |
|
146 | + return (yourls_phpass_check($submitted_password, $hash)); |
|
147 | + } else if (yourls_has_md5_password($user)) { |
|
148 | 148 | // Stored password is a salted md5 hash: "md5:<$r = rand(10000,99999)>:<md5($r.'thepassword')>" |
149 | - list( , $salt, ) = explode( ':', $yourls_user_passwords[ $user ] ); |
|
150 | - return( $yourls_user_passwords[ $user ] == 'md5:'.$salt.':'.md5( $salt . $submitted_password ) ); |
|
149 | + list(, $salt,) = explode(':', $yourls_user_passwords[$user]); |
|
150 | + return($yourls_user_passwords[$user] == 'md5:'.$salt.':'.md5($salt.$submitted_password)); |
|
151 | 151 | } else { |
152 | 152 | // Password stored in clear text |
153 | - return( $yourls_user_passwords[ $user ] === $submitted_password ); |
|
153 | + return($yourls_user_passwords[$user] === $submitted_password); |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
@@ -161,50 +161,50 @@ discard block |
||
161 | 161 | * @param string $config_file Full path to file |
162 | 162 | * @return true if overwrite was successful, an error message otherwise |
163 | 163 | */ |
164 | -function yourls_hash_passwords_now( $config_file ) { |
|
165 | - if( !is_readable( $config_file ) ) |
|
164 | +function yourls_hash_passwords_now($config_file) { |
|
165 | + if (!is_readable($config_file)) |
|
166 | 166 | return 'cannot read file'; // not sure that can actually happen... |
167 | 167 | |
168 | - if( !is_writable( $config_file ) ) |
|
168 | + if (!is_writable($config_file)) |
|
169 | 169 | return 'cannot write file'; |
170 | 170 | |
171 | 171 | // Include file to read value of $yourls_user_passwords |
172 | 172 | // Temporary suppress error reporting to avoid notices about redeclared constants |
173 | 173 | $errlevel = error_reporting(); |
174 | - error_reporting( 0 ); |
|
174 | + error_reporting(0); |
|
175 | 175 | require $config_file; |
176 | - error_reporting( $errlevel ); |
|
176 | + error_reporting($errlevel); |
|
177 | 177 | |
178 | - $configdata = file_get_contents( $config_file ); |
|
179 | - if( $configdata == false ) |
|
178 | + $configdata = file_get_contents($config_file); |
|
179 | + if ($configdata == false) |
|
180 | 180 | return 'could not read file'; |
181 | 181 | |
182 | 182 | $to_hash = 0; // keep track of number of passwords that need hashing |
183 | - foreach ( $yourls_user_passwords as $user => $password ) { |
|
184 | - if ( !yourls_has_phpass_password( $user ) && !yourls_has_md5_password( $user ) ) { |
|
183 | + foreach ($yourls_user_passwords as $user => $password) { |
|
184 | + if (!yourls_has_phpass_password($user) && !yourls_has_md5_password($user)) { |
|
185 | 185 | $to_hash++; |
186 | - $hash = yourls_phpass_hash( $password ); |
|
186 | + $hash = yourls_phpass_hash($password); |
|
187 | 187 | // PHP would interpret $ as a variable, so replace it in storage. |
188 | - $hash = str_replace( '$', '!', $hash ); |
|
189 | - $quotes = "'" . '"'; |
|
190 | - $pattern = "/[$quotes]${user}[$quotes]\s*=>\s*[$quotes]" . preg_quote( $password, '/' ) . "[$quotes]/"; |
|
188 | + $hash = str_replace('$', '!', $hash); |
|
189 | + $quotes = "'".'"'; |
|
190 | + $pattern = "/[$quotes]${user}[$quotes]\s*=>\s*[$quotes]".preg_quote($password, '/')."[$quotes]/"; |
|
191 | 191 | $replace = "'$user' => 'phpass:$hash' /* Password encrypted by YOURLS */ "; |
192 | 192 | $count = 0; |
193 | - $configdata = preg_replace( $pattern, $replace, $configdata, -1, $count ); |
|
193 | + $configdata = preg_replace($pattern, $replace, $configdata, -1, $count); |
|
194 | 194 | // There should be exactly one replacement. Otherwise, fast fail. |
195 | - if ( $count != 1 ) { |
|
196 | - yourls_debug_log( "Problem with preg_replace for password hash of user $user" ); |
|
195 | + if ($count != 1) { |
|
196 | + yourls_debug_log("Problem with preg_replace for password hash of user $user"); |
|
197 | 197 | return 'preg_replace problem'; |
198 | 198 | } |
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
202 | - if( $to_hash == 0 ) |
|
202 | + if ($to_hash == 0) |
|
203 | 203 | return 0; // There was no password to encrypt |
204 | 204 | |
205 | - $success = file_put_contents( $config_file, $configdata ); |
|
206 | - if ( $success === FALSE ) { |
|
207 | - yourls_debug_log( 'Failed writing to ' . $config_file ); |
|
205 | + $success = file_put_contents($config_file, $configdata); |
|
206 | + if ($success === FALSE) { |
|
207 | + yourls_debug_log('Failed writing to '.$config_file); |
|
208 | 208 | return 'could not write file'; |
209 | 209 | } |
210 | 210 | return true; |
@@ -217,9 +217,9 @@ discard block |
||
217 | 217 | * @param string $password password to hash |
218 | 218 | * @return string hashed password |
219 | 219 | */ |
220 | -function yourls_phpass_hash( $password ) { |
|
220 | +function yourls_phpass_hash($password) { |
|
221 | 221 | $hasher = yourls_phpass_instance(); |
222 | - return $hasher->HashPassword( $password ); |
|
222 | + return $hasher->HashPassword($password); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | * @param string $hash hash supposedly generated by phpass |
231 | 231 | * @return bool true if the hash matches the password once hashed by phpass, false otherwise |
232 | 232 | */ |
233 | -function yourls_phpass_check( $password, $hash ) { |
|
233 | +function yourls_phpass_check($password, $hash) { |
|
234 | 234 | $hasher = yourls_phpass_instance(); |
235 | - return $hasher->CheckPassword( $password, $hash ); |
|
235 | + return $hasher->CheckPassword($password, $hash); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -243,13 +243,13 @@ discard block |
||
243 | 243 | * @param bool $portable flag to force portable (cross platform and system independant) hashes - false to use whatever the system can do best |
244 | 244 | * @return object a PasswordHash instance |
245 | 245 | */ |
246 | -function yourls_phpass_instance( $iteration = 8, $portable = false ) { |
|
247 | - $iteration = yourls_apply_filter( 'phpass_new_instance_iteration', $iteration ); |
|
248 | - $portable = yourls_apply_filter( 'phpass_new_instance_portable', $portable ); |
|
246 | +function yourls_phpass_instance($iteration = 8, $portable = false) { |
|
247 | + $iteration = yourls_apply_filter('phpass_new_instance_iteration', $iteration); |
|
248 | + $portable = yourls_apply_filter('phpass_new_instance_portable', $portable); |
|
249 | 249 | |
250 | 250 | static $instance = false; |
251 | - if( $instance == false ) { |
|
252 | - $instance = new \Ozh\Phpass\PasswordHash( $iteration, $portable ); |
|
251 | + if ($instance == false) { |
|
252 | + $instance = new \Ozh\Phpass\PasswordHash($iteration, $portable); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | return $instance; |
@@ -264,8 +264,8 @@ discard block |
||
264 | 264 | */ |
265 | 265 | function yourls_has_cleartext_passwords() { |
266 | 266 | global $yourls_user_passwords; |
267 | - foreach ( $yourls_user_passwords as $user => $pwdata ) { |
|
268 | - if ( !yourls_has_md5_password( $user ) && !yourls_has_phpass_password( $user ) ) { |
|
267 | + foreach ($yourls_user_passwords as $user => $pwdata) { |
|
268 | + if (!yourls_has_md5_password($user) && !yourls_has_phpass_password($user)) { |
|
269 | 269 | return true; |
270 | 270 | } |
271 | 271 | } |
@@ -282,11 +282,11 @@ discard block |
||
282 | 282 | * @param string $user user login |
283 | 283 | * @return bool true if password hashed, false otherwise |
284 | 284 | */ |
285 | -function yourls_has_md5_password( $user ) { |
|
285 | +function yourls_has_md5_password($user) { |
|
286 | 286 | global $yourls_user_passwords; |
287 | - return( isset( $yourls_user_passwords[ $user ] ) |
|
288 | - && substr( $yourls_user_passwords[ $user ], 0, 4 ) == 'md5:' |
|
289 | - && strlen( $yourls_user_passwords[ $user ] ) == 42 // http://www.google.com/search?q=the+answer+to+life+the+universe+and+everything |
|
287 | + return(isset($yourls_user_passwords[$user]) |
|
288 | + && substr($yourls_user_passwords[$user], 0, 4) == 'md5:' |
|
289 | + && strlen($yourls_user_passwords[$user]) == 42 // http://www.google.com/search?q=the+answer+to+life+the+universe+and+everything |
|
290 | 290 | ); |
291 | 291 | } |
292 | 292 | |
@@ -300,10 +300,10 @@ discard block |
||
300 | 300 | * @param string $user user login |
301 | 301 | * @return bool true if password hashed with PHPASS, otherwise false |
302 | 302 | */ |
303 | -function yourls_has_phpass_password( $user ) { |
|
303 | +function yourls_has_phpass_password($user) { |
|
304 | 304 | global $yourls_user_passwords; |
305 | - return( isset( $yourls_user_passwords[ $user ] ) |
|
306 | - && substr( $yourls_user_passwords[ $user ], 0, 7 ) == 'phpass:' |
|
305 | + return(isset($yourls_user_passwords[$user]) |
|
306 | + && substr($yourls_user_passwords[$user], 0, 7) == 'phpass:' |
|
307 | 307 | ); |
308 | 308 | } |
309 | 309 | |
@@ -313,9 +313,9 @@ discard block |
||
313 | 313 | */ |
314 | 314 | function yourls_check_auth_cookie() { |
315 | 315 | global $yourls_user_passwords; |
316 | - foreach( $yourls_user_passwords as $valid_user => $valid_password ) { |
|
317 | - if ( yourls_cookie_value( $valid_user ) === $_COOKIE[ yourls_cookie_name() ] ) { |
|
318 | - yourls_set_user( $valid_user ); |
|
316 | + foreach ($yourls_user_passwords as $valid_user => $valid_password) { |
|
317 | + if (yourls_cookie_value($valid_user) === $_COOKIE[yourls_cookie_name()]) { |
|
318 | + yourls_set_user($valid_user); |
|
319 | 319 | return true; |
320 | 320 | } |
321 | 321 | } |
@@ -336,32 +336,32 @@ discard block |
||
336 | 336 | * @return bool False if signature or timestamp missing or invalid, true if valid |
337 | 337 | */ |
338 | 338 | function yourls_check_signature_timestamp() { |
339 | - if( !isset( $_REQUEST['signature'] ) OR empty( $_REQUEST['signature'] ) |
|
340 | - OR !isset( $_REQUEST['timestamp'] ) OR empty( $_REQUEST['timestamp'] ) |
|
339 | + if (!isset($_REQUEST['signature']) OR empty($_REQUEST['signature']) |
|
340 | + OR !isset($_REQUEST['timestamp']) OR empty($_REQUEST['timestamp']) |
|
341 | 341 | ) { |
342 | 342 | return false; |
343 | 343 | } |
344 | 344 | |
345 | 345 | // Exit if the timestamp argument is outdated or invalid |
346 | - if( !yourls_check_timestamp( $_REQUEST['timestamp'] )) { |
|
346 | + if (!yourls_check_timestamp($_REQUEST['timestamp'])) { |
|
347 | 347 | return false; |
348 | 348 | } |
349 | 349 | |
350 | 350 | // if there is a hash argument, make sure it's part of the availables algos |
351 | - $hash_function = isset($_REQUEST['hash']) ? (string)$_REQUEST['hash'] : 'md5'; |
|
352 | - if( !in_array($hash_function, hash_algos()) ) { |
|
351 | + $hash_function = isset($_REQUEST['hash']) ? (string) $_REQUEST['hash'] : 'md5'; |
|
352 | + if (!in_array($hash_function, hash_algos())) { |
|
353 | 353 | return false; |
354 | 354 | } |
355 | 355 | |
356 | 356 | // Check signature & timestamp against all possible users |
357 | 357 | global $yourls_user_passwords; |
358 | - foreach( $yourls_user_passwords as $valid_user => $valid_password ) { |
|
358 | + foreach ($yourls_user_passwords as $valid_user => $valid_password) { |
|
359 | 359 | if ( |
360 | - hash( $hash_function, $_REQUEST['timestamp'].yourls_auth_signature( $valid_user ) ) === $_REQUEST['signature'] |
|
360 | + hash($hash_function, $_REQUEST['timestamp'].yourls_auth_signature($valid_user)) === $_REQUEST['signature'] |
|
361 | 361 | or |
362 | - hash( $hash_function, yourls_auth_signature( $valid_user ).$_REQUEST['timestamp'] ) === $_REQUEST['signature'] |
|
362 | + hash($hash_function, yourls_auth_signature($valid_user).$_REQUEST['timestamp']) === $_REQUEST['signature'] |
|
363 | 363 | ) { |
364 | - yourls_set_user( $valid_user ); |
|
364 | + yourls_set_user($valid_user); |
|
365 | 365 | return true; |
366 | 366 | } |
367 | 367 | } |
@@ -377,14 +377,14 @@ discard block |
||
377 | 377 | * @return bool False if signature missing or invalid, true if valid |
378 | 378 | */ |
379 | 379 | function yourls_check_signature() { |
380 | - if( !isset( $_REQUEST['signature'] ) OR empty( $_REQUEST['signature'] ) ) |
|
380 | + if (!isset($_REQUEST['signature']) OR empty($_REQUEST['signature'])) |
|
381 | 381 | return false; |
382 | 382 | |
383 | 383 | // Check signature against all possible users |
384 | 384 | global $yourls_user_passwords; |
385 | - foreach( $yourls_user_passwords as $valid_user => $valid_password ) { |
|
386 | - if ( yourls_auth_signature( $valid_user ) === $_REQUEST['signature'] ) { |
|
387 | - yourls_set_user( $valid_user ); |
|
385 | + foreach ($yourls_user_passwords as $valid_user => $valid_password) { |
|
386 | + if (yourls_auth_signature($valid_user) === $_REQUEST['signature']) { |
|
387 | + yourls_set_user($valid_user); |
|
388 | 388 | return true; |
389 | 389 | } |
390 | 390 | } |
@@ -397,21 +397,21 @@ discard block |
||
397 | 397 | * Generate secret signature hash |
398 | 398 | * |
399 | 399 | */ |
400 | -function yourls_auth_signature( $username = false ) { |
|
401 | - if( !$username && defined('YOURLS_USER') ) { |
|
400 | +function yourls_auth_signature($username = false) { |
|
401 | + if (!$username && defined('YOURLS_USER')) { |
|
402 | 402 | $username = YOURLS_USER; |
403 | 403 | } |
404 | - return ( $username ? substr( yourls_salt( $username ), 0, 10 ) : 'Cannot generate auth signature: no username' ); |
|
404 | + return ($username ? substr(yourls_salt($username), 0, 10) : 'Cannot generate auth signature: no username'); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | /** |
408 | 408 | * Check if timestamp is not too old |
409 | 409 | * |
410 | 410 | */ |
411 | -function yourls_check_timestamp( $time ) { |
|
411 | +function yourls_check_timestamp($time) { |
|
412 | 412 | $now = time(); |
413 | 413 | // Allow timestamp to be a little in the future or the past -- see Issue 766 |
414 | - return yourls_apply_filter( 'check_timestamp', abs( $now - (int)$time ) < yourls_get_nonce_life(), $time ); |
|
414 | + return yourls_apply_filter('check_timestamp', abs($now - (int) $time) < yourls_get_nonce_life(), $time); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | /** |
@@ -419,30 +419,30 @@ discard block |
||
419 | 419 | * |
420 | 420 | * @param mixed $user String, user login, or null to delete cookie |
421 | 421 | */ |
422 | -function yourls_store_cookie( $user = null ) { |
|
422 | +function yourls_store_cookie($user = null) { |
|
423 | 423 | |
424 | 424 | // No user will delete the cookie with a cookie time from the past |
425 | - if( !$user ) { |
|
425 | + if (!$user) { |
|
426 | 426 | $time = time() - 3600; |
427 | 427 | } else { |
428 | 428 | $time = time() + yourls_get_cookie_life(); |
429 | 429 | } |
430 | 430 | |
431 | - $path = yourls_apply_filter( 'setcookie_path', '/' ); |
|
432 | - $domain = yourls_apply_filter( 'setcookie_domain', parse_url( yourls_get_yourls_site(), PHP_URL_HOST ) ); |
|
433 | - $secure = yourls_apply_filter( 'setcookie_secure', yourls_is_ssl() ); |
|
434 | - $httponly = yourls_apply_filter( 'setcookie_httponly', true ); |
|
431 | + $path = yourls_apply_filter('setcookie_path', '/'); |
|
432 | + $domain = yourls_apply_filter('setcookie_domain', parse_url(yourls_get_yourls_site(), PHP_URL_HOST)); |
|
433 | + $secure = yourls_apply_filter('setcookie_secure', yourls_is_ssl()); |
|
434 | + $httponly = yourls_apply_filter('setcookie_httponly', true); |
|
435 | 435 | |
436 | 436 | // Some browsers refuse to store localhost cookie |
437 | - if ( $domain == 'localhost' ) |
|
437 | + if ($domain == 'localhost') |
|
438 | 438 | $domain = ''; |
439 | 439 | |
440 | - if ( !headers_sent( $filename, $linenum ) ) { |
|
441 | - yourls_setcookie( yourls_cookie_name(), yourls_cookie_value( $user ), $time, $path, $domain, $secure, $httponly ); |
|
440 | + if (!headers_sent($filename, $linenum)) { |
|
441 | + yourls_setcookie(yourls_cookie_name(), yourls_cookie_value($user), $time, $path, $domain, $secure, $httponly); |
|
442 | 442 | } else { |
443 | 443 | // For some reason cookies were not stored: action to be able to debug that |
444 | - yourls_do_action( 'setcookie_failed', $user ); |
|
445 | - yourls_debug_log( "Could not store cookie: headers already sent in $filename on line $linenum" ); |
|
444 | + yourls_do_action('setcookie_failed', $user); |
|
445 | + yourls_debug_log("Could not store cookie: headers already sent in $filename on line $linenum"); |
|
446 | 446 | } |
447 | 447 | } |
448 | 448 | |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | * @return bool setcookie() result : false if output sent before, true otherwise. This does not indicate whether the user accepted the cookie. |
466 | 466 | */ |
467 | 467 | function yourls_setcookie($name, $value, $expire, $path, $domain, $secure, $httponly) { |
468 | - $samesite = yourls_apply_filter('setcookie_samesite', 'Lax' ); |
|
468 | + $samesite = yourls_apply_filter('setcookie_samesite', 'Lax'); |
|
469 | 469 | |
470 | 470 | if (PHP_VERSION_ID < 70300) { |
471 | 471 | return(setcookie($name, $value, $expire, "$path; samesite=$samesite", $domain, $secure, $httponly)); |
@@ -486,9 +486,9 @@ discard block |
||
486 | 486 | * Set user name |
487 | 487 | * |
488 | 488 | */ |
489 | -function yourls_set_user( $user ) { |
|
490 | - if( !defined( 'YOURLS_USER' ) ) |
|
491 | - define( 'YOURLS_USER', $user ); |
|
489 | +function yourls_set_user($user) { |
|
490 | + if (!defined('YOURLS_USER')) |
|
491 | + define('YOURLS_USER', $user); |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | /** |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | * @return integer cookie life span, in seconds |
503 | 503 | */ |
504 | 504 | function yourls_get_cookie_life() { |
505 | - return yourls_apply_filter( 'get_cookie_life', YOURLS_COOKIE_LIFE ); |
|
505 | + return yourls_apply_filter('get_cookie_life', YOURLS_COOKIE_LIFE); |
|
506 | 506 | } |
507 | 507 | |
508 | 508 | /** |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | * @return integer nonce life span, in seconds |
518 | 518 | */ |
519 | 519 | function yourls_get_nonce_life() { |
520 | - return yourls_apply_filter( 'get_nonce_life', YOURLS_NONCE_LIFE ); |
|
520 | + return yourls_apply_filter('get_nonce_life', YOURLS_NONCE_LIFE); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | /** |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | * @return string unique cookie name for a given YOURLS site |
532 | 532 | */ |
533 | 533 | function yourls_cookie_name() { |
534 | - return yourls_apply_filter( 'cookie_name', 'yourls_' . yourls_salt( yourls_get_yourls_site() ) ); |
|
534 | + return yourls_apply_filter('cookie_name', 'yourls_'.yourls_salt(yourls_get_yourls_site())); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | /** |
@@ -541,8 +541,8 @@ discard block |
||
541 | 541 | * @param string $user user name |
542 | 542 | * @return string cookie value |
543 | 543 | */ |
544 | -function yourls_cookie_value( $user ) { |
|
545 | - return yourls_apply_filter( 'set_cookie_value', yourls_salt( $user ), $user ); |
|
544 | +function yourls_cookie_value($user) { |
|
545 | + return yourls_apply_filter('set_cookie_value', yourls_salt($user), $user); |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
@@ -552,38 +552,38 @@ discard block |
||
552 | 552 | * |
553 | 553 | */ |
554 | 554 | function yourls_tick() { |
555 | - return ceil( time() / yourls_get_nonce_life() ); |
|
555 | + return ceil(time() / yourls_get_nonce_life()); |
|
556 | 556 | } |
557 | 557 | |
558 | 558 | /** |
559 | 559 | * Return salted string |
560 | 560 | * |
561 | 561 | */ |
562 | -function yourls_salt( $string ) { |
|
563 | - $salt = defined('YOURLS_COOKIEKEY') ? YOURLS_COOKIEKEY : md5(__FILE__) ; |
|
564 | - return yourls_apply_filter( 'yourls_salt', md5 ($string . $salt), $string ); |
|
562 | +function yourls_salt($string) { |
|
563 | + $salt = defined('YOURLS_COOKIEKEY') ? YOURLS_COOKIEKEY : md5(__FILE__); |
|
564 | + return yourls_apply_filter('yourls_salt', md5($string.$salt), $string); |
|
565 | 565 | } |
566 | 566 | |
567 | 567 | /** |
568 | 568 | * Create a time limited, action limited and user limited token |
569 | 569 | * |
570 | 570 | */ |
571 | -function yourls_create_nonce( $action, $user = false ) { |
|
572 | - if( false == $user ) |
|
573 | - $user = defined( 'YOURLS_USER' ) ? YOURLS_USER : '-1'; |
|
571 | +function yourls_create_nonce($action, $user = false) { |
|
572 | + if (false == $user) |
|
573 | + $user = defined('YOURLS_USER') ? YOURLS_USER : '-1'; |
|
574 | 574 | $tick = yourls_tick(); |
575 | - $nonce = substr( yourls_salt($tick . $action . $user), 0, 10 ); |
|
575 | + $nonce = substr(yourls_salt($tick.$action.$user), 0, 10); |
|
576 | 576 | // Allow plugins to alter the nonce |
577 | - return yourls_apply_filter( 'create_nonce', $nonce, $action, $user ); |
|
577 | + return yourls_apply_filter('create_nonce', $nonce, $action, $user); |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | /** |
581 | 581 | * Create a nonce field for inclusion into a form |
582 | 582 | * |
583 | 583 | */ |
584 | -function yourls_nonce_field( $action, $name = 'nonce', $user = false, $echo = true ) { |
|
585 | - $field = '<input type="hidden" id="'.$name.'" name="'.$name.'" value="'.yourls_create_nonce( $action, $user ).'" />'; |
|
586 | - if( $echo ) |
|
584 | +function yourls_nonce_field($action, $name = 'nonce', $user = false, $echo = true) { |
|
585 | + $field = '<input type="hidden" id="'.$name.'" name="'.$name.'" value="'.yourls_create_nonce($action, $user).'" />'; |
|
586 | + if ($echo) |
|
587 | 587 | echo $field."\n"; |
588 | 588 | return $field; |
589 | 589 | } |
@@ -592,9 +592,9 @@ discard block |
||
592 | 592 | * Add a nonce to a URL. If URL omitted, adds nonce to current URL |
593 | 593 | * |
594 | 594 | */ |
595 | -function yourls_nonce_url( $action, $url = false, $name = 'nonce', $user = false ) { |
|
596 | - $nonce = yourls_create_nonce( $action, $user ); |
|
597 | - return yourls_add_query_arg( $name, $nonce, $url ); |
|
595 | +function yourls_nonce_url($action, $url = false, $name = 'nonce', $user = false) { |
|
596 | + $nonce = yourls_create_nonce($action, $user); |
|
597 | + return yourls_add_query_arg($name, $nonce, $url); |
|
598 | 598 | } |
599 | 599 | |
600 | 600 | /** |
@@ -604,29 +604,29 @@ discard block |
||
604 | 604 | * if $nonce is false or unspecified, it will use $_REQUEST['nonce'] |
605 | 605 | * |
606 | 606 | */ |
607 | -function yourls_verify_nonce( $action, $nonce = false, $user = false, $return = '' ) { |
|
607 | +function yourls_verify_nonce($action, $nonce = false, $user = false, $return = '') { |
|
608 | 608 | // get user |
609 | - if( false == $user ) |
|
610 | - $user = defined( 'YOURLS_USER' ) ? YOURLS_USER : '-1'; |
|
609 | + if (false == $user) |
|
610 | + $user = defined('YOURLS_USER') ? YOURLS_USER : '-1'; |
|
611 | 611 | |
612 | 612 | // get current nonce value |
613 | - if( false == $nonce && isset( $_REQUEST['nonce'] ) ) |
|
613 | + if (false == $nonce && isset($_REQUEST['nonce'])) |
|
614 | 614 | $nonce = $_REQUEST['nonce']; |
615 | 615 | |
616 | 616 | // Allow plugins to short-circuit the rest of the function |
617 | - $valid = yourls_apply_filter( 'verify_nonce', false, $action, $nonce, $user, $return ); |
|
617 | + $valid = yourls_apply_filter('verify_nonce', false, $action, $nonce, $user, $return); |
|
618 | 618 | if ($valid) { |
619 | 619 | return true; |
620 | 620 | } |
621 | 621 | |
622 | 622 | // what nonce should be |
623 | - $valid = yourls_create_nonce( $action, $user ); |
|
623 | + $valid = yourls_create_nonce($action, $user); |
|
624 | 624 | |
625 | - if( $nonce == $valid ) { |
|
625 | + if ($nonce == $valid) { |
|
626 | 626 | return true; |
627 | 627 | } else { |
628 | - if( $return ) |
|
629 | - die( $return ); |
|
630 | - yourls_die( yourls__( 'Unauthorized action or expired link' ), yourls__( 'Error' ), 403 ); |
|
628 | + if ($return) |
|
629 | + die($return); |
|
630 | + yourls_die(yourls__('Unauthorized action or expired link'), yourls__('Error'), 403); |
|
631 | 631 | } |
632 | 632 | } |
@@ -49,38 +49,28 @@ discard block |
||
49 | 49 | ( yourls_is_API() && |
50 | 50 | isset( $_REQUEST['timestamp'] ) && !empty($_REQUEST['timestamp'] ) && |
51 | 51 | isset( $_REQUEST['signature'] ) && !empty($_REQUEST['signature'] ) |
52 | - ) |
|
53 | - { |
|
52 | + ) { |
|
54 | 53 | yourls_do_action( 'pre_login_signature_timestamp' ); |
55 | 54 | $unfiltered_valid = yourls_check_signature_timestamp(); |
56 | - } |
|
57 | - |
|
58 | - elseif |
|
55 | + } elseif |
|
59 | 56 | // API only: Secure (no login or pwd) |
60 | 57 | // ?signature=md5(totoblah) |
61 | 58 | ( yourls_is_API() && |
62 | 59 | !isset( $_REQUEST['timestamp'] ) && |
63 | 60 | isset( $_REQUEST['signature'] ) && !empty( $_REQUEST['signature'] ) |
64 | - ) |
|
65 | - { |
|
61 | + ) { |
|
66 | 62 | yourls_do_action( 'pre_login_signature' ); |
67 | 63 | $unfiltered_valid = yourls_check_signature(); |
68 | - } |
|
69 | - |
|
70 | - elseif |
|
64 | + } elseif |
|
71 | 65 | // API or normal: login with username & pwd |
72 | 66 | ( isset( $_REQUEST['username'] ) && isset( $_REQUEST['password'] ) |
73 | - && !empty( $_REQUEST['username'] ) && !empty( $_REQUEST['password'] ) ) |
|
74 | - { |
|
67 | + && !empty( $_REQUEST['username'] ) && !empty( $_REQUEST['password'] ) ) { |
|
75 | 68 | yourls_do_action( 'pre_login_username_password' ); |
76 | 69 | $unfiltered_valid = yourls_check_username_password(); |
77 | - } |
|
78 | - |
|
79 | - elseif |
|
70 | + } elseif |
|
80 | 71 | // Normal only: cookies |
81 | 72 | ( !yourls_is_API() && |
82 | - isset( $_COOKIE[ yourls_cookie_name() ] ) ) |
|
83 | - { |
|
73 | + isset( $_COOKIE[ yourls_cookie_name() ] ) ) { |
|
84 | 74 | yourls_do_action( 'pre_login_cookie' ); |
85 | 75 | $unfiltered_valid = yourls_check_auth_cookie(); |
86 | 76 | } |
@@ -136,8 +126,9 @@ discard block |
||
136 | 126 | function yourls_check_password_hash( $user, $submitted_password ) { |
137 | 127 | global $yourls_user_passwords; |
138 | 128 | |
139 | - if( !isset( $yourls_user_passwords[ $user ] ) ) |
|
140 | - return false; |
|
129 | + if( !isset( $yourls_user_passwords[ $user ] ) ) { |
|
130 | + return false; |
|
131 | + } |
|
141 | 132 | |
142 | 133 | if ( yourls_has_phpass_password( $user ) ) { |
143 | 134 | // Stored password is hashed with phpass |
@@ -162,11 +153,14 @@ discard block |
||
162 | 153 | * @return true if overwrite was successful, an error message otherwise |
163 | 154 | */ |
164 | 155 | function yourls_hash_passwords_now( $config_file ) { |
165 | - if( !is_readable( $config_file ) ) |
|
166 | - return 'cannot read file'; // not sure that can actually happen... |
|
156 | + if( !is_readable( $config_file ) ) { |
|
157 | + return 'cannot read file'; |
|
158 | + } |
|
159 | + // not sure that can actually happen... |
|
167 | 160 | |
168 | - if( !is_writable( $config_file ) ) |
|
169 | - return 'cannot write file'; |
|
161 | + if( !is_writable( $config_file ) ) { |
|
162 | + return 'cannot write file'; |
|
163 | + } |
|
170 | 164 | |
171 | 165 | // Include file to read value of $yourls_user_passwords |
172 | 166 | // Temporary suppress error reporting to avoid notices about redeclared constants |
@@ -176,8 +170,9 @@ discard block |
||
176 | 170 | error_reporting( $errlevel ); |
177 | 171 | |
178 | 172 | $configdata = file_get_contents( $config_file ); |
179 | - if( $configdata == false ) |
|
180 | - return 'could not read file'; |
|
173 | + if( $configdata == false ) { |
|
174 | + return 'could not read file'; |
|
175 | + } |
|
181 | 176 | |
182 | 177 | $to_hash = 0; // keep track of number of passwords that need hashing |
183 | 178 | foreach ( $yourls_user_passwords as $user => $password ) { |
@@ -199,8 +194,10 @@ discard block |
||
199 | 194 | } |
200 | 195 | } |
201 | 196 | |
202 | - if( $to_hash == 0 ) |
|
203 | - return 0; // There was no password to encrypt |
|
197 | + if( $to_hash == 0 ) { |
|
198 | + return 0; |
|
199 | + } |
|
200 | + // There was no password to encrypt |
|
204 | 201 | |
205 | 202 | $success = file_put_contents( $config_file, $configdata ); |
206 | 203 | if ( $success === FALSE ) { |
@@ -377,8 +374,9 @@ discard block |
||
377 | 374 | * @return bool False if signature missing or invalid, true if valid |
378 | 375 | */ |
379 | 376 | function yourls_check_signature() { |
380 | - if( !isset( $_REQUEST['signature'] ) OR empty( $_REQUEST['signature'] ) ) |
|
381 | - return false; |
|
377 | + if( !isset( $_REQUEST['signature'] ) OR empty( $_REQUEST['signature'] ) ) { |
|
378 | + return false; |
|
379 | + } |
|
382 | 380 | |
383 | 381 | // Check signature against all possible users |
384 | 382 | global $yourls_user_passwords; |
@@ -434,8 +432,9 @@ discard block |
||
434 | 432 | $httponly = yourls_apply_filter( 'setcookie_httponly', true ); |
435 | 433 | |
436 | 434 | // Some browsers refuse to store localhost cookie |
437 | - if ( $domain == 'localhost' ) |
|
438 | - $domain = ''; |
|
435 | + if ( $domain == 'localhost' ) { |
|
436 | + $domain = ''; |
|
437 | + } |
|
439 | 438 | |
440 | 439 | if ( !headers_sent( $filename, $linenum ) ) { |
441 | 440 | yourls_setcookie( yourls_cookie_name(), yourls_cookie_value( $user ), $time, $path, $domain, $secure, $httponly ); |
@@ -469,8 +468,7 @@ discard block |
||
469 | 468 | |
470 | 469 | if (PHP_VERSION_ID < 70300) { |
471 | 470 | return(setcookie($name, $value, $expire, "$path; samesite=$samesite", $domain, $secure, $httponly)); |
472 | - } |
|
473 | - else { |
|
471 | + } else { |
|
474 | 472 | return(setcookie($name, $value, array( |
475 | 473 | 'expires' => $expire, |
476 | 474 | 'path' => $path, |
@@ -487,9 +485,10 @@ discard block |
||
487 | 485 | * |
488 | 486 | */ |
489 | 487 | function yourls_set_user( $user ) { |
490 | - if( !defined( 'YOURLS_USER' ) ) |
|
491 | - define( 'YOURLS_USER', $user ); |
|
492 | -} |
|
488 | + if( !defined( 'YOURLS_USER' ) ) { |
|
489 | + define( 'YOURLS_USER', $user ); |
|
490 | + } |
|
491 | + } |
|
493 | 492 | |
494 | 493 | /** |
495 | 494 | * Get YOURLS_COOKIE_LIFE value (ie the life span of an auth cookie in seconds) |
@@ -569,8 +568,9 @@ discard block |
||
569 | 568 | * |
570 | 569 | */ |
571 | 570 | function yourls_create_nonce( $action, $user = false ) { |
572 | - if( false == $user ) |
|
573 | - $user = defined( 'YOURLS_USER' ) ? YOURLS_USER : '-1'; |
|
571 | + if( false == $user ) { |
|
572 | + $user = defined( 'YOURLS_USER' ) ? YOURLS_USER : '-1'; |
|
573 | + } |
|
574 | 574 | $tick = yourls_tick(); |
575 | 575 | $nonce = substr( yourls_salt($tick . $action . $user), 0, 10 ); |
576 | 576 | // Allow plugins to alter the nonce |
@@ -583,8 +583,9 @@ discard block |
||
583 | 583 | */ |
584 | 584 | function yourls_nonce_field( $action, $name = 'nonce', $user = false, $echo = true ) { |
585 | 585 | $field = '<input type="hidden" id="'.$name.'" name="'.$name.'" value="'.yourls_create_nonce( $action, $user ).'" />'; |
586 | - if( $echo ) |
|
587 | - echo $field."\n"; |
|
586 | + if( $echo ) { |
|
587 | + echo $field."\n"; |
|
588 | + } |
|
588 | 589 | return $field; |
589 | 590 | } |
590 | 591 | |
@@ -606,12 +607,14 @@ discard block |
||
606 | 607 | */ |
607 | 608 | function yourls_verify_nonce( $action, $nonce = false, $user = false, $return = '' ) { |
608 | 609 | // get user |
609 | - if( false == $user ) |
|
610 | - $user = defined( 'YOURLS_USER' ) ? YOURLS_USER : '-1'; |
|
610 | + if( false == $user ) { |
|
611 | + $user = defined( 'YOURLS_USER' ) ? YOURLS_USER : '-1'; |
|
612 | + } |
|
611 | 613 | |
612 | 614 | // get current nonce value |
613 | - if( false == $nonce && isset( $_REQUEST['nonce'] ) ) |
|
614 | - $nonce = $_REQUEST['nonce']; |
|
615 | + if( false == $nonce && isset( $_REQUEST['nonce'] ) ) { |
|
616 | + $nonce = $_REQUEST['nonce']; |
|
617 | + } |
|
615 | 618 | |
616 | 619 | // Allow plugins to short-circuit the rest of the function |
617 | 620 | $valid = yourls_apply_filter( 'verify_nonce', false, $action, $nonce, $user, $return ); |
@@ -625,8 +628,9 @@ discard block |
||
625 | 628 | if( $nonce == $valid ) { |
626 | 629 | return true; |
627 | 630 | } else { |
628 | - if( $return ) |
|
629 | - die( $return ); |
|
631 | + if( $return ) { |
|
632 | + die( $return ); |
|
633 | + } |
|
630 | 634 | yourls_die( yourls__( 'Unauthorized action or expired link' ), yourls__( 'Error' ), 403 ); |
631 | 635 | } |
632 | 636 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | return 0; // There was no password to encrypt |
204 | 204 | |
205 | 205 | $success = file_put_contents( $config_file, $configdata ); |
206 | - if ( $success === FALSE ) { |
|
206 | + if ( $success === false ) { |
|
207 | 207 | yourls_debug_log( 'Failed writing to ' . $config_file ); |
208 | 208 | return 'could not write file'; |
209 | 209 | } |
@@ -336,8 +336,8 @@ discard block |
||
336 | 336 | * @return bool False if signature or timestamp missing or invalid, true if valid |
337 | 337 | */ |
338 | 338 | function yourls_check_signature_timestamp() { |
339 | - if( !isset( $_REQUEST['signature'] ) OR empty( $_REQUEST['signature'] ) |
|
340 | - OR !isset( $_REQUEST['timestamp'] ) OR empty( $_REQUEST['timestamp'] ) |
|
339 | + if( !isset( $_REQUEST['signature'] ) or empty( $_REQUEST['signature'] ) |
|
340 | + or !isset( $_REQUEST['timestamp'] ) or empty( $_REQUEST['timestamp'] ) |
|
341 | 341 | ) { |
342 | 342 | return false; |
343 | 343 | } |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | * @return bool False if signature missing or invalid, true if valid |
378 | 378 | */ |
379 | 379 | function yourls_check_signature() { |
380 | - if( !isset( $_REQUEST['signature'] ) OR empty( $_REQUEST['signature'] ) ) |
|
380 | + if( !isset( $_REQUEST['signature'] ) or empty( $_REQUEST['signature'] ) ) |
|
381 | 381 | return false; |
382 | 382 | |
383 | 383 | // Check signature against all possible users |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | * @param string $msg Message to add to the debug log |
14 | 14 | * @return string The message itself |
15 | 15 | */ |
16 | -function yourls_debug_log( $msg ) { |
|
17 | - yourls_do_action( 'debug_log', $msg ); |
|
18 | - yourls_get_db()->getProfiler()->log( $msg ); |
|
16 | +function yourls_debug_log($msg) { |
|
17 | + yourls_do_action('debug_log', $msg); |
|
18 | + yourls_get_db()->getProfiler()->log($msg); |
|
19 | 19 | return $msg; |
20 | 20 | } |
21 | 21 | |
@@ -36,13 +36,13 @@ discard block |
||
36 | 36 | * @since 1.7.3 |
37 | 37 | * @param bool $bool Debug on or off |
38 | 38 | */ |
39 | -function yourls_debug_mode( $bool ) { |
|
39 | +function yourls_debug_mode($bool) { |
|
40 | 40 | // log queries if true |
41 | - yourls_get_db()->getProfiler()->setActive( (bool)$bool ); |
|
41 | + yourls_get_db()->getProfiler()->setActive((bool) $bool); |
|
42 | 42 | |
43 | 43 | // report notices if true |
44 | - $level = $bool ? -1 : ( E_ERROR | E_PARSE ); |
|
45 | - error_reporting( $level ); |
|
44 | + $level = $bool ? -1 : (E_ERROR | E_PARSE); |
|
45 | + error_reporting($level); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -52,5 +52,5 @@ discard block |
||
52 | 52 | * @return bool |
53 | 53 | */ |
54 | 54 | function yourls_get_debug_mode() { |
55 | - return defined( 'YOURLS_DEBUG' ) && YOURLS_DEBUG; |
|
55 | + return defined('YOURLS_DEBUG') && YOURLS_DEBUG; |
|
56 | 56 | } |
@@ -6,27 +6,27 @@ discard block |
||
6 | 6 | */ |
7 | 7 | function yourls_stats_countries_map( $countries, $id = null ) { |
8 | 8 | |
9 | - yourls_do_action( 'pre_stats_countries_map' ); |
|
9 | + yourls_do_action( 'pre_stats_countries_map' ); |
|
10 | 10 | |
11 | - // if $id is null then assign a random string |
|
12 | - if( $id === null ) |
|
13 | - $id = uniqid ( 'yourls_stats_map_' ); |
|
11 | + // if $id is null then assign a random string |
|
12 | + if( $id === null ) |
|
13 | + $id = uniqid ( 'yourls_stats_map_' ); |
|
14 | 14 | |
15 | - $data = array_merge( array( 'Country' => 'Hits' ), $countries ); |
|
16 | - $data = yourls_google_array_to_data_table( $data ); |
|
15 | + $data = array_merge( array( 'Country' => 'Hits' ), $countries ); |
|
16 | + $data = yourls_google_array_to_data_table( $data ); |
|
17 | 17 | |
18 | - $options = array( |
|
19 | - 'backgroundColor' => "white", |
|
20 | - 'colorAxis' => "{colors:['A8D0ED','99C4E4','8AB8DB','7BACD2','6BA1C9','5C95C0','4D89B7','3E7DAE','2E72A5','1F669C']}", |
|
21 | - 'width' => "550", |
|
22 | - 'height' => "340", |
|
23 | - 'theme' => 'maximized' |
|
24 | - ); |
|
25 | - $options = yourls_apply_filter( 'stats_countries_map_options', $options ); |
|
18 | + $options = array( |
|
19 | + 'backgroundColor' => "white", |
|
20 | + 'colorAxis' => "{colors:['A8D0ED','99C4E4','8AB8DB','7BACD2','6BA1C9','5C95C0','4D89B7','3E7DAE','2E72A5','1F669C']}", |
|
21 | + 'width' => "550", |
|
22 | + 'height' => "340", |
|
23 | + 'theme' => 'maximized' |
|
24 | + ); |
|
25 | + $options = yourls_apply_filter( 'stats_countries_map_options', $options ); |
|
26 | 26 | |
27 | - $map = yourls_google_viz_code( 'GeoChart', $data, $options, $id ); |
|
27 | + $map = yourls_google_viz_code( 'GeoChart', $data, $options, $id ); |
|
28 | 28 | |
29 | - echo yourls_apply_filter( 'stats_countries_map', $map, $countries, $options, $id ); |
|
29 | + echo yourls_apply_filter( 'stats_countries_map', $map, $countries, $options, $id ); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -35,49 +35,49 @@ discard block |
||
35 | 35 | */ |
36 | 36 | function yourls_stats_pie( $data, $limit = 10, $size = '340x220', $id = null ) { |
37 | 37 | |
38 | - yourls_do_action( 'pre_stats_pie' ); |
|
39 | - |
|
40 | - // if $id is null then assign a random string |
|
41 | - if( $id === null ) |
|
42 | - $id = uniqid ( 'yourls_stats_pie_' ); |
|
43 | - |
|
44 | - // Trim array: $limit first item + the sum of all others |
|
45 | - if ( count( $data ) > $limit ) { |
|
46 | - $i= 0; |
|
47 | - $trim_data = array( 'Others' => 0 ); |
|
48 | - foreach( $data as $item=>$value ) { |
|
49 | - $i++; |
|
50 | - if( $i <= $limit ) { |
|
51 | - $trim_data[$item] = $value; |
|
52 | - } else { |
|
53 | - $trim_data['Others'] += $value; |
|
54 | - } |
|
55 | - } |
|
56 | - $data = $trim_data; |
|
57 | - } |
|
58 | - |
|
59 | - // Scale items |
|
60 | - $_data = yourls_scale_data( $data ); |
|
61 | - |
|
62 | - list($width, $height) = explode( 'x', $size ); |
|
63 | - |
|
64 | - $options = array( |
|
65 | - 'theme' => 'maximized', |
|
66 | - 'width' => $width, |
|
67 | - 'height' => $height, |
|
68 | - 'colors' => "['A8D0ED','99C4E4','8AB8DB','7BACD2','6BA1C9','5C95C0','4D89B7','3E7DAE','2E72A5','1F669C']", |
|
69 | - 'legend' => 'none', |
|
70 | - 'chartArea' => '{top: "5%", height: "90%"}', |
|
71 | - 'pieSliceText' => 'label', |
|
72 | - ); |
|
73 | - $options = yourls_apply_filter( 'stats_pie_options', $options ); |
|
74 | - |
|
75 | - $script_data = array_merge( array( 'Country' => 'Value' ), $_data ); |
|
76 | - $script_data = yourls_google_array_to_data_table( $script_data ); |
|
77 | - |
|
78 | - $pie = yourls_google_viz_code( 'PieChart', $script_data, $options, $id ); |
|
79 | - |
|
80 | - echo yourls_apply_filter( 'stats_pie', $pie, $data, $limit, $size, $options, $id ); |
|
38 | + yourls_do_action( 'pre_stats_pie' ); |
|
39 | + |
|
40 | + // if $id is null then assign a random string |
|
41 | + if( $id === null ) |
|
42 | + $id = uniqid ( 'yourls_stats_pie_' ); |
|
43 | + |
|
44 | + // Trim array: $limit first item + the sum of all others |
|
45 | + if ( count( $data ) > $limit ) { |
|
46 | + $i= 0; |
|
47 | + $trim_data = array( 'Others' => 0 ); |
|
48 | + foreach( $data as $item=>$value ) { |
|
49 | + $i++; |
|
50 | + if( $i <= $limit ) { |
|
51 | + $trim_data[$item] = $value; |
|
52 | + } else { |
|
53 | + $trim_data['Others'] += $value; |
|
54 | + } |
|
55 | + } |
|
56 | + $data = $trim_data; |
|
57 | + } |
|
58 | + |
|
59 | + // Scale items |
|
60 | + $_data = yourls_scale_data( $data ); |
|
61 | + |
|
62 | + list($width, $height) = explode( 'x', $size ); |
|
63 | + |
|
64 | + $options = array( |
|
65 | + 'theme' => 'maximized', |
|
66 | + 'width' => $width, |
|
67 | + 'height' => $height, |
|
68 | + 'colors' => "['A8D0ED','99C4E4','8AB8DB','7BACD2','6BA1C9','5C95C0','4D89B7','3E7DAE','2E72A5','1F669C']", |
|
69 | + 'legend' => 'none', |
|
70 | + 'chartArea' => '{top: "5%", height: "90%"}', |
|
71 | + 'pieSliceText' => 'label', |
|
72 | + ); |
|
73 | + $options = yourls_apply_filter( 'stats_pie_options', $options ); |
|
74 | + |
|
75 | + $script_data = array_merge( array( 'Country' => 'Value' ), $_data ); |
|
76 | + $script_data = yourls_google_array_to_data_table( $script_data ); |
|
77 | + |
|
78 | + $pie = yourls_google_viz_code( 'PieChart', $script_data, $options, $id ); |
|
79 | + |
|
80 | + echo yourls_apply_filter( 'stats_pie', $pie, $data, $limit, $size, $options, $id ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * |
86 | 86 | */ |
87 | 87 | function yourls_build_list_of_days( $dates ) { |
88 | - /* Say we have an array like: |
|
88 | + /* Say we have an array like: |
|
89 | 89 | $dates = array ( |
90 | 90 | 2009 => array ( |
91 | 91 | '08' => array ( |
@@ -102,55 +102,55 @@ discard block |
||
102 | 102 | ) |
103 | 103 | */ |
104 | 104 | |
105 | - if( !$dates ) |
|
106 | - return array(); |
|
107 | - |
|
108 | - // Get first & last years from our range. In our example: 2009 & 2009 |
|
109 | - $first_year = key( $dates ); |
|
110 | - $_keys = array_keys( $dates ); |
|
111 | - $last_year = end( $_keys ); |
|
112 | - reset( $dates ); |
|
113 | - |
|
114 | - // Get first & last months from our range. In our example: 08 & 09 |
|
115 | - $first_month = key( $dates[ $first_year ] ); |
|
116 | - $_keys = array_keys( $dates[ $last_year ] ); |
|
117 | - $last_month = end( $_keys ); |
|
118 | - reset( $dates ); |
|
119 | - |
|
120 | - // Get first & last days from our range. In our example: 29 & 05 |
|
121 | - $first_day = key( $dates[ $first_year ][ $first_month ] ); |
|
122 | - $_keys = array_keys( $dates[ $last_year ][ $last_month ] ); |
|
123 | - $last_day = end( $_keys ); |
|
124 | - |
|
125 | - unset( $_keys ); |
|
126 | - |
|
127 | - // Now build a list of all years (2009), month (08 & 09) and days (all from 2009-08-29 to 2009-09-05) |
|
128 | - $list_of_years = array(); |
|
129 | - $list_of_months = array(); |
|
130 | - $list_of_days = array(); |
|
131 | - for ( $year = $first_year; $year <= $last_year; $year++ ) { |
|
132 | - $_year = sprintf( '%04d', $year ); |
|
133 | - $list_of_years[ $_year ] = $_year; |
|
134 | - $current_first_month = ( $year == $first_year ? $first_month : '01' ); |
|
135 | - $current_last_month = ( $year == $last_year ? $last_month : '12' ); |
|
136 | - for ( $month = $current_first_month; $month <= $current_last_month; $month++ ) { |
|
137 | - $_month = sprintf( '%02d', $month ); |
|
138 | - $list_of_months[ $_month ] = $_month; |
|
139 | - $current_first_day = ( $year == $first_year && $month == $first_month ? $first_day : '01' ); |
|
140 | - $current_last_day = ( $year == $last_year && $month == $last_month ? $last_day : yourls_days_in_month( $month, $year) ); |
|
141 | - for ( $day = $current_first_day; $day <= $current_last_day; $day++ ) { |
|
142 | - $day = sprintf( '%02d', $day ); |
|
143 | - $key = date( 'M d, Y', mktime( 0, 0, 0, $_month, $day, $_year ) ); |
|
144 | - $list_of_days[ $key ] = isset( $dates[$_year][$_month][$day] ) ? $dates[$_year][$_month][$day] : 0; |
|
145 | - } |
|
146 | - } |
|
147 | - } |
|
148 | - |
|
149 | - return array( |
|
150 | - 'list_of_days' => $list_of_days, |
|
151 | - 'list_of_months' => $list_of_months, |
|
152 | - 'list_of_years' => $list_of_years, |
|
153 | - ); |
|
105 | + if( !$dates ) |
|
106 | + return array(); |
|
107 | + |
|
108 | + // Get first & last years from our range. In our example: 2009 & 2009 |
|
109 | + $first_year = key( $dates ); |
|
110 | + $_keys = array_keys( $dates ); |
|
111 | + $last_year = end( $_keys ); |
|
112 | + reset( $dates ); |
|
113 | + |
|
114 | + // Get first & last months from our range. In our example: 08 & 09 |
|
115 | + $first_month = key( $dates[ $first_year ] ); |
|
116 | + $_keys = array_keys( $dates[ $last_year ] ); |
|
117 | + $last_month = end( $_keys ); |
|
118 | + reset( $dates ); |
|
119 | + |
|
120 | + // Get first & last days from our range. In our example: 29 & 05 |
|
121 | + $first_day = key( $dates[ $first_year ][ $first_month ] ); |
|
122 | + $_keys = array_keys( $dates[ $last_year ][ $last_month ] ); |
|
123 | + $last_day = end( $_keys ); |
|
124 | + |
|
125 | + unset( $_keys ); |
|
126 | + |
|
127 | + // Now build a list of all years (2009), month (08 & 09) and days (all from 2009-08-29 to 2009-09-05) |
|
128 | + $list_of_years = array(); |
|
129 | + $list_of_months = array(); |
|
130 | + $list_of_days = array(); |
|
131 | + for ( $year = $first_year; $year <= $last_year; $year++ ) { |
|
132 | + $_year = sprintf( '%04d', $year ); |
|
133 | + $list_of_years[ $_year ] = $_year; |
|
134 | + $current_first_month = ( $year == $first_year ? $first_month : '01' ); |
|
135 | + $current_last_month = ( $year == $last_year ? $last_month : '12' ); |
|
136 | + for ( $month = $current_first_month; $month <= $current_last_month; $month++ ) { |
|
137 | + $_month = sprintf( '%02d', $month ); |
|
138 | + $list_of_months[ $_month ] = $_month; |
|
139 | + $current_first_day = ( $year == $first_year && $month == $first_month ? $first_day : '01' ); |
|
140 | + $current_last_day = ( $year == $last_year && $month == $last_month ? $last_day : yourls_days_in_month( $month, $year) ); |
|
141 | + for ( $day = $current_first_day; $day <= $current_last_day; $day++ ) { |
|
142 | + $day = sprintf( '%02d', $day ); |
|
143 | + $key = date( 'M d, Y', mktime( 0, 0, 0, $_month, $day, $_year ) ); |
|
144 | + $list_of_days[ $key ] = isset( $dates[$_year][$_month][$day] ) ? $dates[$_year][$_month][$day] : 0; |
|
145 | + } |
|
146 | + } |
|
147 | + } |
|
148 | + |
|
149 | + return array( |
|
150 | + 'list_of_days' => $list_of_days, |
|
151 | + 'list_of_months' => $list_of_months, |
|
152 | + 'list_of_years' => $list_of_years, |
|
153 | + ); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -161,38 +161,38 @@ discard block |
||
161 | 161 | */ |
162 | 162 | function yourls_stats_line( $values, $id = null ) { |
163 | 163 | |
164 | - yourls_do_action( 'pre_stats_line' ); |
|
164 | + yourls_do_action( 'pre_stats_line' ); |
|
165 | 165 | |
166 | - // if $id is null then assign a random string |
|
167 | - if( $id === null ) |
|
168 | - $id = uniqid ( 'yourls_stats_line_' ); |
|
166 | + // if $id is null then assign a random string |
|
167 | + if( $id === null ) |
|
168 | + $id = uniqid ( 'yourls_stats_line_' ); |
|
169 | 169 | |
170 | - // If we have only 1 day of data, prepend a fake day with 0 hits for a prettier graph |
|
171 | - if ( count( $values ) == 1 ) |
|
172 | - array_unshift( $values, 0 ); |
|
170 | + // If we have only 1 day of data, prepend a fake day with 0 hits for a prettier graph |
|
171 | + if ( count( $values ) == 1 ) |
|
172 | + array_unshift( $values, 0 ); |
|
173 | 173 | |
174 | - // Keep only a subset of values to keep graph smooth |
|
175 | - $values = yourls_array_granularity( $values, 30 ); |
|
174 | + // Keep only a subset of values to keep graph smooth |
|
175 | + $values = yourls_array_granularity( $values, 30 ); |
|
176 | 176 | |
177 | - $data = array_merge( array( 'Time' => 'Hits' ), $values ); |
|
178 | - $data = yourls_google_array_to_data_table( $data ); |
|
177 | + $data = array_merge( array( 'Time' => 'Hits' ), $values ); |
|
178 | + $data = yourls_google_array_to_data_table( $data ); |
|
179 | 179 | |
180 | - $options = array( |
|
181 | - "legend" => "none", |
|
182 | - "pointSize" => "3", |
|
183 | - "theme" => "maximized", |
|
184 | - "curveType" => "function", |
|
185 | - "width" => 430, |
|
186 | - "height" => 220, |
|
187 | - "hAxis" => "{minTextSpacing: 80, maxTextLines: 1, maxAlternation: 1}", |
|
188 | - "vAxis" => "{minValue: 0, format: '#'}", |
|
189 | - "colors" => "['#2a85b3']", |
|
190 | - ); |
|
191 | - $options = yourls_apply_filter( 'stats_line_options', $options ); |
|
180 | + $options = array( |
|
181 | + "legend" => "none", |
|
182 | + "pointSize" => "3", |
|
183 | + "theme" => "maximized", |
|
184 | + "curveType" => "function", |
|
185 | + "width" => 430, |
|
186 | + "height" => 220, |
|
187 | + "hAxis" => "{minTextSpacing: 80, maxTextLines: 1, maxAlternation: 1}", |
|
188 | + "vAxis" => "{minValue: 0, format: '#'}", |
|
189 | + "colors" => "['#2a85b3']", |
|
190 | + ); |
|
191 | + $options = yourls_apply_filter( 'stats_line_options', $options ); |
|
192 | 192 | |
193 | - $lineChart = yourls_google_viz_code( 'LineChart', $data, $options, $id ); |
|
193 | + $lineChart = yourls_google_viz_code( 'LineChart', $data, $options, $id ); |
|
194 | 194 | |
195 | - echo yourls_apply_filter( 'stats_line', $lineChart, $values, $options, $id ); |
|
195 | + echo yourls_apply_filter( 'stats_line', $lineChart, $values, $options, $id ); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -200,8 +200,8 @@ discard block |
||
200 | 200 | * |
201 | 201 | */ |
202 | 202 | function yourls_days_in_month( $month, $year ) { |
203 | - // calculate number of days in a month |
|
204 | - return $month == 2 ? ( $year % 4 ? 28 : ( $year % 100 ? 29 : ( $year % 400 ? 28 : 29 ) ) ) : ( ( $month - 1 ) % 7 % 2 ? 30 : 31 ); |
|
203 | + // calculate number of days in a month |
|
204 | + return $month == 2 ? ( $year % 4 ? 28 : ( $year % 100 ? 29 : ( $year % 400 ? 28 : 29 ) ) ) : ( ( $month - 1 ) % 7 % 2 ? 30 : 31 ); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -209,11 +209,11 @@ discard block |
||
209 | 209 | * |
210 | 210 | */ |
211 | 211 | function yourls_stats_get_best_day( $list_of_days ) { |
212 | - $max = max( $list_of_days ); |
|
213 | - foreach( $list_of_days as $k=>$v ) { |
|
214 | - if ( $v == $max ) |
|
215 | - return array( 'day' => $k, 'max' => $max ); |
|
216 | - } |
|
212 | + $max = max( $list_of_days ); |
|
213 | + foreach( $list_of_days as $k=>$v ) { |
|
214 | + if ( $v == $max ) |
|
215 | + return array( 'day' => $k, 'max' => $max ); |
|
216 | + } |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -221,19 +221,19 @@ discard block |
||
221 | 221 | * |
222 | 222 | */ |
223 | 223 | function yourls_get_domain( $url, $include_scheme = false ) { |
224 | - $parse = @parse_url( $url ); // Hiding ugly stuff coming from malformed referrer URLs |
|
224 | + $parse = @parse_url( $url ); // Hiding ugly stuff coming from malformed referrer URLs |
|
225 | 225 | |
226 | - // Get host & scheme. Fall back to path if not found. |
|
227 | - $host = isset( $parse['host'] ) ? $parse['host'] : ''; |
|
228 | - $scheme = isset( $parse['scheme'] ) ? $parse['scheme'] : ''; |
|
229 | - $path = isset( $parse['path'] ) ? $parse['path'] : ''; |
|
230 | - if( !$host ) |
|
231 | - $host = $path; |
|
226 | + // Get host & scheme. Fall back to path if not found. |
|
227 | + $host = isset( $parse['host'] ) ? $parse['host'] : ''; |
|
228 | + $scheme = isset( $parse['scheme'] ) ? $parse['scheme'] : ''; |
|
229 | + $path = isset( $parse['path'] ) ? $parse['path'] : ''; |
|
230 | + if( !$host ) |
|
231 | + $host = $path; |
|
232 | 232 | |
233 | - if ( $include_scheme && $scheme ) |
|
234 | - $host = $scheme.'://'.$host; |
|
233 | + if ( $include_scheme && $scheme ) |
|
234 | + $host = $scheme.'://'.$host; |
|
235 | 235 | |
236 | - return $host; |
|
236 | + return $host; |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * |
242 | 242 | */ |
243 | 243 | function yourls_get_favicon_url( $url ) { |
244 | - return yourls_match_current_protocol( '//www.google.com/s2/favicons?domain=' . yourls_get_domain( $url, false ) ); |
|
244 | + return yourls_match_current_protocol( '//www.google.com/s2/favicons?domain=' . yourls_get_domain( $url, false ) ); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -249,13 +249,13 @@ discard block |
||
249 | 249 | * |
250 | 250 | */ |
251 | 251 | function yourls_scale_data( $data ) { |
252 | - $max = max( $data ); |
|
253 | - if( $max > 100 ) { |
|
254 | - foreach( $data as $k=>$v ) { |
|
255 | - $data[$k] = intval( $v / $max * 100 ); |
|
256 | - } |
|
257 | - } |
|
258 | - return $data; |
|
252 | + $max = max( $data ); |
|
253 | + if( $max > 100 ) { |
|
254 | + foreach( $data as $k=>$v ) { |
|
255 | + $data[$k] = intval( $v / $max * 100 ); |
|
256 | + } |
|
257 | + } |
|
258 | + return $data; |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
@@ -263,24 +263,24 @@ discard block |
||
263 | 263 | * |
264 | 264 | */ |
265 | 265 | function yourls_array_granularity( $array, $grain = 100, $preserve_max = true ) { |
266 | - if ( count( $array ) > $grain ) { |
|
267 | - $max = max( $array ); |
|
268 | - $step = intval( count( $array ) / $grain ); |
|
269 | - $i = 0; |
|
270 | - // Loop through each item and unset except every $step (optional preserve the max value) |
|
271 | - foreach( $array as $k=>$v ) { |
|
272 | - $i++; |
|
273 | - if ( $i % $step != 0 ) { |
|
274 | - if ( $preserve_max == false ) { |
|
275 | - unset( $array[$k] ); |
|
276 | - } else { |
|
277 | - if ( $v < $max ) |
|
278 | - unset( $array[$k] ); |
|
279 | - } |
|
280 | - } |
|
281 | - } |
|
282 | - } |
|
283 | - return $array; |
|
266 | + if ( count( $array ) > $grain ) { |
|
267 | + $max = max( $array ); |
|
268 | + $step = intval( count( $array ) / $grain ); |
|
269 | + $i = 0; |
|
270 | + // Loop through each item and unset except every $step (optional preserve the max value) |
|
271 | + foreach( $array as $k=>$v ) { |
|
272 | + $i++; |
|
273 | + if ( $i % $step != 0 ) { |
|
274 | + if ( $preserve_max == false ) { |
|
275 | + unset( $array[$k] ); |
|
276 | + } else { |
|
277 | + if ( $v < $max ) |
|
278 | + unset( $array[$k] ); |
|
279 | + } |
|
280 | + } |
|
281 | + } |
|
282 | + } |
|
283 | + return $array; |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | /** |
@@ -288,23 +288,23 @@ discard block |
||
288 | 288 | * |
289 | 289 | */ |
290 | 290 | function yourls_google_array_to_data_table( $data ){ |
291 | - $str = "var data = google.visualization.arrayToDataTable([\n"; |
|
292 | - foreach( $data as $label => $values ){ |
|
293 | - if( !is_array( $values ) ) { |
|
294 | - $values = array( $values ); |
|
295 | - } |
|
296 | - $str .= "\t['$label',"; |
|
297 | - foreach( $values as $value ){ |
|
298 | - if( !is_numeric( $value ) && strpos( $value, '[' ) !== 0 && strpos( $value, '{' ) !== 0 ) { |
|
299 | - $value = "'$value'"; |
|
300 | - } |
|
301 | - $str .= "$value"; |
|
302 | - } |
|
303 | - $str .= "],\n"; |
|
304 | - } |
|
305 | - $str = substr( $str, 0, -2 ) . "\n"; // remove the trailing comma/return, reappend the return |
|
306 | - $str .= "]);\n"; // wrap it up |
|
307 | - return $str; |
|
291 | + $str = "var data = google.visualization.arrayToDataTable([\n"; |
|
292 | + foreach( $data as $label => $values ){ |
|
293 | + if( !is_array( $values ) ) { |
|
294 | + $values = array( $values ); |
|
295 | + } |
|
296 | + $str .= "\t['$label',"; |
|
297 | + foreach( $values as $value ){ |
|
298 | + if( !is_numeric( $value ) && strpos( $value, '[' ) !== 0 && strpos( $value, '{' ) !== 0 ) { |
|
299 | + $value = "'$value'"; |
|
300 | + } |
|
301 | + $str .= "$value"; |
|
302 | + } |
|
303 | + $str .= "],\n"; |
|
304 | + } |
|
305 | + $str = substr( $str, 0, -2 ) . "\n"; // remove the trailing comma/return, reappend the return |
|
306 | + $str .= "]);\n"; // wrap it up |
|
307 | + return $str; |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -312,28 +312,28 @@ discard block |
||
312 | 312 | * |
313 | 313 | */ |
314 | 314 | function yourls_google_viz_code( $graph_type, $data, $options, $id ) { |
315 | - $function_name = 'yourls_graph' . $id; |
|
316 | - $code = "\n<script id=\"$function_name\" type=\"text/javascript\">\n"; |
|
317 | - $code .= "function $function_name() { \n"; |
|
318 | - |
|
319 | - $code .= "$data\n"; |
|
320 | - |
|
321 | - $code .= "var options = {\n"; |
|
322 | - foreach( $options as $field => $value ) { |
|
323 | - if( !is_numeric( $value ) && strpos( $value, '[' ) !== 0 && strpos( $value, '{' ) !== 0 ) { |
|
324 | - $value = "\"$value\""; |
|
325 | - } |
|
326 | - $code .= "\t'$field': $value,\n"; |
|
327 | - } |
|
328 | - $code = substr( $code, 0, -2 ) . "\n"; // remove the trailing comma/return, reappend the return |
|
329 | - $code .= "\t}\n"; |
|
330 | - |
|
331 | - $code .= "new google.visualization.$graph_type( document.getElementById('visualization_$id') ).draw( data, options );"; |
|
332 | - $code .= "}\n"; |
|
333 | - $code .= "google.setOnLoadCallback( $function_name );\n"; |
|
334 | - $code .= "</script>\n"; |
|
335 | - $code .= "<div id=\"visualization_$id\"></div>\n"; |
|
336 | - |
|
337 | - return $code; |
|
315 | + $function_name = 'yourls_graph' . $id; |
|
316 | + $code = "\n<script id=\"$function_name\" type=\"text/javascript\">\n"; |
|
317 | + $code .= "function $function_name() { \n"; |
|
318 | + |
|
319 | + $code .= "$data\n"; |
|
320 | + |
|
321 | + $code .= "var options = {\n"; |
|
322 | + foreach( $options as $field => $value ) { |
|
323 | + if( !is_numeric( $value ) && strpos( $value, '[' ) !== 0 && strpos( $value, '{' ) !== 0 ) { |
|
324 | + $value = "\"$value\""; |
|
325 | + } |
|
326 | + $code .= "\t'$field': $value,\n"; |
|
327 | + } |
|
328 | + $code = substr( $code, 0, -2 ) . "\n"; // remove the trailing comma/return, reappend the return |
|
329 | + $code .= "\t}\n"; |
|
330 | + |
|
331 | + $code .= "new google.visualization.$graph_type( document.getElementById('visualization_$id') ).draw( data, options );"; |
|
332 | + $code .= "}\n"; |
|
333 | + $code .= "google.setOnLoadCallback( $function_name );\n"; |
|
334 | + $code .= "</script>\n"; |
|
335 | + $code .= "<div id=\"visualization_$id\"></div>\n"; |
|
336 | + |
|
337 | + return $code; |
|
338 | 338 | } |
339 | 339 |
@@ -4,16 +4,16 @@ discard block |
||
4 | 4 | * Echoes an image tag of Google Charts map from sorted array of 'country_code' => 'number of visits' (sort by DESC) |
5 | 5 | * |
6 | 6 | */ |
7 | -function yourls_stats_countries_map( $countries, $id = null ) { |
|
7 | +function yourls_stats_countries_map($countries, $id = null) { |
|
8 | 8 | |
9 | - yourls_do_action( 'pre_stats_countries_map' ); |
|
9 | + yourls_do_action('pre_stats_countries_map'); |
|
10 | 10 | |
11 | 11 | // if $id is null then assign a random string |
12 | - if( $id === null ) |
|
13 | - $id = uniqid ( 'yourls_stats_map_' ); |
|
12 | + if ($id === null) |
|
13 | + $id = uniqid('yourls_stats_map_'); |
|
14 | 14 | |
15 | - $data = array_merge( array( 'Country' => 'Hits' ), $countries ); |
|
16 | - $data = yourls_google_array_to_data_table( $data ); |
|
15 | + $data = array_merge(array('Country' => 'Hits'), $countries); |
|
16 | + $data = yourls_google_array_to_data_table($data); |
|
17 | 17 | |
18 | 18 | $options = array( |
19 | 19 | 'backgroundColor' => "white", |
@@ -22,32 +22,32 @@ discard block |
||
22 | 22 | 'height' => "340", |
23 | 23 | 'theme' => 'maximized' |
24 | 24 | ); |
25 | - $options = yourls_apply_filter( 'stats_countries_map_options', $options ); |
|
25 | + $options = yourls_apply_filter('stats_countries_map_options', $options); |
|
26 | 26 | |
27 | - $map = yourls_google_viz_code( 'GeoChart', $data, $options, $id ); |
|
27 | + $map = yourls_google_viz_code('GeoChart', $data, $options, $id); |
|
28 | 28 | |
29 | - echo yourls_apply_filter( 'stats_countries_map', $map, $countries, $options, $id ); |
|
29 | + echo yourls_apply_filter('stats_countries_map', $map, $countries, $options, $id); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
33 | 33 | * Echoes an image tag of Google Charts pie from sorted array of 'data' => 'value' (sort by DESC). Optional $limit = (integer) limit list of X first countries, sorted by most visits |
34 | 34 | * |
35 | 35 | */ |
36 | -function yourls_stats_pie( $data, $limit = 10, $size = '340x220', $id = null ) { |
|
36 | +function yourls_stats_pie($data, $limit = 10, $size = '340x220', $id = null) { |
|
37 | 37 | |
38 | - yourls_do_action( 'pre_stats_pie' ); |
|
38 | + yourls_do_action('pre_stats_pie'); |
|
39 | 39 | |
40 | 40 | // if $id is null then assign a random string |
41 | - if( $id === null ) |
|
42 | - $id = uniqid ( 'yourls_stats_pie_' ); |
|
41 | + if ($id === null) |
|
42 | + $id = uniqid('yourls_stats_pie_'); |
|
43 | 43 | |
44 | 44 | // Trim array: $limit first item + the sum of all others |
45 | - if ( count( $data ) > $limit ) { |
|
46 | - $i= 0; |
|
47 | - $trim_data = array( 'Others' => 0 ); |
|
48 | - foreach( $data as $item=>$value ) { |
|
45 | + if (count($data) > $limit) { |
|
46 | + $i = 0; |
|
47 | + $trim_data = array('Others' => 0); |
|
48 | + foreach ($data as $item=>$value) { |
|
49 | 49 | $i++; |
50 | - if( $i <= $limit ) { |
|
50 | + if ($i <= $limit) { |
|
51 | 51 | $trim_data[$item] = $value; |
52 | 52 | } else { |
53 | 53 | $trim_data['Others'] += $value; |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | } |
58 | 58 | |
59 | 59 | // Scale items |
60 | - $_data = yourls_scale_data( $data ); |
|
60 | + $_data = yourls_scale_data($data); |
|
61 | 61 | |
62 | - list($width, $height) = explode( 'x', $size ); |
|
62 | + list($width, $height) = explode('x', $size); |
|
63 | 63 | |
64 | 64 | $options = array( |
65 | 65 | 'theme' => 'maximized', |
@@ -70,21 +70,21 @@ discard block |
||
70 | 70 | 'chartArea' => '{top: "5%", height: "90%"}', |
71 | 71 | 'pieSliceText' => 'label', |
72 | 72 | ); |
73 | - $options = yourls_apply_filter( 'stats_pie_options', $options ); |
|
73 | + $options = yourls_apply_filter('stats_pie_options', $options); |
|
74 | 74 | |
75 | - $script_data = array_merge( array( 'Country' => 'Value' ), $_data ); |
|
76 | - $script_data = yourls_google_array_to_data_table( $script_data ); |
|
75 | + $script_data = array_merge(array('Country' => 'Value'), $_data); |
|
76 | + $script_data = yourls_google_array_to_data_table($script_data); |
|
77 | 77 | |
78 | - $pie = yourls_google_viz_code( 'PieChart', $script_data, $options, $id ); |
|
78 | + $pie = yourls_google_viz_code('PieChart', $script_data, $options, $id); |
|
79 | 79 | |
80 | - echo yourls_apply_filter( 'stats_pie', $pie, $data, $limit, $size, $options, $id ); |
|
80 | + echo yourls_apply_filter('stats_pie', $pie, $data, $limit, $size, $options, $id); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
84 | 84 | * Build a list of all daily values between d1/m1/y1 to d2/m2/y2. |
85 | 85 | * |
86 | 86 | */ |
87 | -function yourls_build_list_of_days( $dates ) { |
|
87 | +function yourls_build_list_of_days($dates) { |
|
88 | 88 | /* Say we have an array like: |
89 | 89 | $dates = array ( |
90 | 90 | 2009 => array ( |
@@ -102,46 +102,46 @@ discard block |
||
102 | 102 | ) |
103 | 103 | */ |
104 | 104 | |
105 | - if( !$dates ) |
|
105 | + if (!$dates) |
|
106 | 106 | return array(); |
107 | 107 | |
108 | 108 | // Get first & last years from our range. In our example: 2009 & 2009 |
109 | - $first_year = key( $dates ); |
|
110 | - $_keys = array_keys( $dates ); |
|
111 | - $last_year = end( $_keys ); |
|
112 | - reset( $dates ); |
|
109 | + $first_year = key($dates); |
|
110 | + $_keys = array_keys($dates); |
|
111 | + $last_year = end($_keys); |
|
112 | + reset($dates); |
|
113 | 113 | |
114 | 114 | // Get first & last months from our range. In our example: 08 & 09 |
115 | - $first_month = key( $dates[ $first_year ] ); |
|
116 | - $_keys = array_keys( $dates[ $last_year ] ); |
|
117 | - $last_month = end( $_keys ); |
|
118 | - reset( $dates ); |
|
115 | + $first_month = key($dates[$first_year]); |
|
116 | + $_keys = array_keys($dates[$last_year]); |
|
117 | + $last_month = end($_keys); |
|
118 | + reset($dates); |
|
119 | 119 | |
120 | 120 | // Get first & last days from our range. In our example: 29 & 05 |
121 | - $first_day = key( $dates[ $first_year ][ $first_month ] ); |
|
122 | - $_keys = array_keys( $dates[ $last_year ][ $last_month ] ); |
|
123 | - $last_day = end( $_keys ); |
|
121 | + $first_day = key($dates[$first_year][$first_month]); |
|
122 | + $_keys = array_keys($dates[$last_year][$last_month]); |
|
123 | + $last_day = end($_keys); |
|
124 | 124 | |
125 | - unset( $_keys ); |
|
125 | + unset($_keys); |
|
126 | 126 | |
127 | 127 | // Now build a list of all years (2009), month (08 & 09) and days (all from 2009-08-29 to 2009-09-05) |
128 | 128 | $list_of_years = array(); |
129 | 129 | $list_of_months = array(); |
130 | 130 | $list_of_days = array(); |
131 | - for ( $year = $first_year; $year <= $last_year; $year++ ) { |
|
132 | - $_year = sprintf( '%04d', $year ); |
|
133 | - $list_of_years[ $_year ] = $_year; |
|
134 | - $current_first_month = ( $year == $first_year ? $first_month : '01' ); |
|
135 | - $current_last_month = ( $year == $last_year ? $last_month : '12' ); |
|
136 | - for ( $month = $current_first_month; $month <= $current_last_month; $month++ ) { |
|
137 | - $_month = sprintf( '%02d', $month ); |
|
138 | - $list_of_months[ $_month ] = $_month; |
|
139 | - $current_first_day = ( $year == $first_year && $month == $first_month ? $first_day : '01' ); |
|
140 | - $current_last_day = ( $year == $last_year && $month == $last_month ? $last_day : yourls_days_in_month( $month, $year) ); |
|
141 | - for ( $day = $current_first_day; $day <= $current_last_day; $day++ ) { |
|
142 | - $day = sprintf( '%02d', $day ); |
|
143 | - $key = date( 'M d, Y', mktime( 0, 0, 0, $_month, $day, $_year ) ); |
|
144 | - $list_of_days[ $key ] = isset( $dates[$_year][$_month][$day] ) ? $dates[$_year][$_month][$day] : 0; |
|
131 | + for ($year = $first_year; $year <= $last_year; $year++) { |
|
132 | + $_year = sprintf('%04d', $year); |
|
133 | + $list_of_years[$_year] = $_year; |
|
134 | + $current_first_month = ($year == $first_year ? $first_month : '01'); |
|
135 | + $current_last_month = ($year == $last_year ? $last_month : '12'); |
|
136 | + for ($month = $current_first_month; $month <= $current_last_month; $month++) { |
|
137 | + $_month = sprintf('%02d', $month); |
|
138 | + $list_of_months[$_month] = $_month; |
|
139 | + $current_first_day = ($year == $first_year && $month == $first_month ? $first_day : '01'); |
|
140 | + $current_last_day = ($year == $last_year && $month == $last_month ? $last_day : yourls_days_in_month($month, $year)); |
|
141 | + for ($day = $current_first_day; $day <= $current_last_day; $day++) { |
|
142 | + $day = sprintf('%02d', $day); |
|
143 | + $key = date('M d, Y', mktime(0, 0, 0, $_month, $day, $_year)); |
|
144 | + $list_of_days[$key] = isset($dates[$_year][$_month][$day]) ? $dates[$_year][$_month][$day] : 0; |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | } |
@@ -159,23 +159,23 @@ discard block |
||
159 | 159 | * $legend1_list & legend2_list are values used for the 2 x-axis labels. $id is an HTML/JS id |
160 | 160 | * |
161 | 161 | */ |
162 | -function yourls_stats_line( $values, $id = null ) { |
|
162 | +function yourls_stats_line($values, $id = null) { |
|
163 | 163 | |
164 | - yourls_do_action( 'pre_stats_line' ); |
|
164 | + yourls_do_action('pre_stats_line'); |
|
165 | 165 | |
166 | 166 | // if $id is null then assign a random string |
167 | - if( $id === null ) |
|
168 | - $id = uniqid ( 'yourls_stats_line_' ); |
|
167 | + if ($id === null) |
|
168 | + $id = uniqid('yourls_stats_line_'); |
|
169 | 169 | |
170 | 170 | // If we have only 1 day of data, prepend a fake day with 0 hits for a prettier graph |
171 | - if ( count( $values ) == 1 ) |
|
172 | - array_unshift( $values, 0 ); |
|
171 | + if (count($values) == 1) |
|
172 | + array_unshift($values, 0); |
|
173 | 173 | |
174 | 174 | // Keep only a subset of values to keep graph smooth |
175 | - $values = yourls_array_granularity( $values, 30 ); |
|
175 | + $values = yourls_array_granularity($values, 30); |
|
176 | 176 | |
177 | - $data = array_merge( array( 'Time' => 'Hits' ), $values ); |
|
178 | - $data = yourls_google_array_to_data_table( $data ); |
|
177 | + $data = array_merge(array('Time' => 'Hits'), $values); |
|
178 | + $data = yourls_google_array_to_data_table($data); |
|
179 | 179 | |
180 | 180 | $options = array( |
181 | 181 | "legend" => "none", |
@@ -188,31 +188,31 @@ discard block |
||
188 | 188 | "vAxis" => "{minValue: 0, format: '#'}", |
189 | 189 | "colors" => "['#2a85b3']", |
190 | 190 | ); |
191 | - $options = yourls_apply_filter( 'stats_line_options', $options ); |
|
191 | + $options = yourls_apply_filter('stats_line_options', $options); |
|
192 | 192 | |
193 | - $lineChart = yourls_google_viz_code( 'LineChart', $data, $options, $id ); |
|
193 | + $lineChart = yourls_google_viz_code('LineChart', $data, $options, $id); |
|
194 | 194 | |
195 | - echo yourls_apply_filter( 'stats_line', $lineChart, $values, $options, $id ); |
|
195 | + echo yourls_apply_filter('stats_line', $lineChart, $values, $options, $id); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
199 | 199 | * Return the number of days in a month. From php.net, used if PHP built without calendar functions |
200 | 200 | * |
201 | 201 | */ |
202 | -function yourls_days_in_month( $month, $year ) { |
|
202 | +function yourls_days_in_month($month, $year) { |
|
203 | 203 | // calculate number of days in a month |
204 | - return $month == 2 ? ( $year % 4 ? 28 : ( $year % 100 ? 29 : ( $year % 400 ? 28 : 29 ) ) ) : ( ( $month - 1 ) % 7 % 2 ? 30 : 31 ); |
|
204 | + return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
208 | 208 | * Get max value from date array of 'Aug 12, 2012' = '1337' |
209 | 209 | * |
210 | 210 | */ |
211 | -function yourls_stats_get_best_day( $list_of_days ) { |
|
212 | - $max = max( $list_of_days ); |
|
213 | - foreach( $list_of_days as $k=>$v ) { |
|
214 | - if ( $v == $max ) |
|
215 | - return array( 'day' => $k, 'max' => $max ); |
|
211 | +function yourls_stats_get_best_day($list_of_days) { |
|
212 | + $max = max($list_of_days); |
|
213 | + foreach ($list_of_days as $k=>$v) { |
|
214 | + if ($v == $max) |
|
215 | + return array('day' => $k, 'max' => $max); |
|
216 | 216 | } |
217 | 217 | } |
218 | 218 | |
@@ -220,17 +220,17 @@ discard block |
||
220 | 220 | * Return domain of a URL |
221 | 221 | * |
222 | 222 | */ |
223 | -function yourls_get_domain( $url, $include_scheme = false ) { |
|
224 | - $parse = @parse_url( $url ); // Hiding ugly stuff coming from malformed referrer URLs |
|
223 | +function yourls_get_domain($url, $include_scheme = false) { |
|
224 | + $parse = @parse_url($url); // Hiding ugly stuff coming from malformed referrer URLs |
|
225 | 225 | |
226 | 226 | // Get host & scheme. Fall back to path if not found. |
227 | - $host = isset( $parse['host'] ) ? $parse['host'] : ''; |
|
228 | - $scheme = isset( $parse['scheme'] ) ? $parse['scheme'] : ''; |
|
229 | - $path = isset( $parse['path'] ) ? $parse['path'] : ''; |
|
230 | - if( !$host ) |
|
227 | + $host = isset($parse['host']) ? $parse['host'] : ''; |
|
228 | + $scheme = isset($parse['scheme']) ? $parse['scheme'] : ''; |
|
229 | + $path = isset($parse['path']) ? $parse['path'] : ''; |
|
230 | + if (!$host) |
|
231 | 231 | $host = $path; |
232 | 232 | |
233 | - if ( $include_scheme && $scheme ) |
|
233 | + if ($include_scheme && $scheme) |
|
234 | 234 | $host = $scheme.'://'.$host; |
235 | 235 | |
236 | 236 | return $host; |
@@ -240,19 +240,19 @@ discard block |
||
240 | 240 | * Return favicon URL |
241 | 241 | * |
242 | 242 | */ |
243 | -function yourls_get_favicon_url( $url ) { |
|
244 | - return yourls_match_current_protocol( '//www.google.com/s2/favicons?domain=' . yourls_get_domain( $url, false ) ); |
|
243 | +function yourls_get_favicon_url($url) { |
|
244 | + return yourls_match_current_protocol('//www.google.com/s2/favicons?domain='.yourls_get_domain($url, false)); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
248 | 248 | * Scale array of data from 0 to 100 max |
249 | 249 | * |
250 | 250 | */ |
251 | -function yourls_scale_data( $data ) { |
|
252 | - $max = max( $data ); |
|
253 | - if( $max > 100 ) { |
|
254 | - foreach( $data as $k=>$v ) { |
|
255 | - $data[$k] = intval( $v / $max * 100 ); |
|
251 | +function yourls_scale_data($data) { |
|
252 | + $max = max($data); |
|
253 | + if ($max > 100) { |
|
254 | + foreach ($data as $k=>$v) { |
|
255 | + $data[$k] = intval($v / $max * 100); |
|
256 | 256 | } |
257 | 257 | } |
258 | 258 | return $data; |
@@ -262,20 +262,20 @@ discard block |
||
262 | 262 | * Tweak granularity of array $array: keep only $grain values. This make less accurate but less messy graphs when too much values. See http://code.google.com/apis/chart/formats.html#granularity |
263 | 263 | * |
264 | 264 | */ |
265 | -function yourls_array_granularity( $array, $grain = 100, $preserve_max = true ) { |
|
266 | - if ( count( $array ) > $grain ) { |
|
267 | - $max = max( $array ); |
|
268 | - $step = intval( count( $array ) / $grain ); |
|
265 | +function yourls_array_granularity($array, $grain = 100, $preserve_max = true) { |
|
266 | + if (count($array) > $grain) { |
|
267 | + $max = max($array); |
|
268 | + $step = intval(count($array) / $grain); |
|
269 | 269 | $i = 0; |
270 | 270 | // Loop through each item and unset except every $step (optional preserve the max value) |
271 | - foreach( $array as $k=>$v ) { |
|
271 | + foreach ($array as $k=>$v) { |
|
272 | 272 | $i++; |
273 | - if ( $i % $step != 0 ) { |
|
274 | - if ( $preserve_max == false ) { |
|
275 | - unset( $array[$k] ); |
|
273 | + if ($i % $step != 0) { |
|
274 | + if ($preserve_max == false) { |
|
275 | + unset($array[$k]); |
|
276 | 276 | } else { |
277 | - if ( $v < $max ) |
|
278 | - unset( $array[$k] ); |
|
277 | + if ($v < $max) |
|
278 | + unset($array[$k]); |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | } |
@@ -287,22 +287,22 @@ discard block |
||
287 | 287 | * Transform data array to data table for Google API |
288 | 288 | * |
289 | 289 | */ |
290 | -function yourls_google_array_to_data_table( $data ){ |
|
291 | - $str = "var data = google.visualization.arrayToDataTable([\n"; |
|
292 | - foreach( $data as $label => $values ){ |
|
293 | - if( !is_array( $values ) ) { |
|
294 | - $values = array( $values ); |
|
290 | +function yourls_google_array_to_data_table($data) { |
|
291 | + $str = "var data = google.visualization.arrayToDataTable([\n"; |
|
292 | + foreach ($data as $label => $values) { |
|
293 | + if (!is_array($values)) { |
|
294 | + $values = array($values); |
|
295 | 295 | } |
296 | 296 | $str .= "\t['$label',"; |
297 | - foreach( $values as $value ){ |
|
298 | - if( !is_numeric( $value ) && strpos( $value, '[' ) !== 0 && strpos( $value, '{' ) !== 0 ) { |
|
297 | + foreach ($values as $value) { |
|
298 | + if (!is_numeric($value) && strpos($value, '[') !== 0 && strpos($value, '{') !== 0) { |
|
299 | 299 | $value = "'$value'"; |
300 | 300 | } |
301 | 301 | $str .= "$value"; |
302 | 302 | } |
303 | 303 | $str .= "],\n"; |
304 | 304 | } |
305 | - $str = substr( $str, 0, -2 ) . "\n"; // remove the trailing comma/return, reappend the return |
|
305 | + $str = substr($str, 0, -2)."\n"; // remove the trailing comma/return, reappend the return |
|
306 | 306 | $str .= "]);\n"; // wrap it up |
307 | 307 | return $str; |
308 | 308 | } |
@@ -311,21 +311,21 @@ discard block |
||
311 | 311 | * Return javascript code that will display the Google Chart |
312 | 312 | * |
313 | 313 | */ |
314 | -function yourls_google_viz_code( $graph_type, $data, $options, $id ) { |
|
315 | - $function_name = 'yourls_graph' . $id; |
|
314 | +function yourls_google_viz_code($graph_type, $data, $options, $id) { |
|
315 | + $function_name = 'yourls_graph'.$id; |
|
316 | 316 | $code = "\n<script id=\"$function_name\" type=\"text/javascript\">\n"; |
317 | 317 | $code .= "function $function_name() { \n"; |
318 | 318 | |
319 | 319 | $code .= "$data\n"; |
320 | 320 | |
321 | 321 | $code .= "var options = {\n"; |
322 | - foreach( $options as $field => $value ) { |
|
323 | - if( !is_numeric( $value ) && strpos( $value, '[' ) !== 0 && strpos( $value, '{' ) !== 0 ) { |
|
322 | + foreach ($options as $field => $value) { |
|
323 | + if (!is_numeric($value) && strpos($value, '[') !== 0 && strpos($value, '{') !== 0) { |
|
324 | 324 | $value = "\"$value\""; |
325 | 325 | } |
326 | 326 | $code .= "\t'$field': $value,\n"; |
327 | 327 | } |
328 | - $code = substr( $code, 0, -2 ) . "\n"; // remove the trailing comma/return, reappend the return |
|
328 | + $code = substr($code, 0, -2)."\n"; // remove the trailing comma/return, reappend the return |
|
329 | 329 | $code .= "\t}\n"; |
330 | 330 | |
331 | 331 | $code .= "new google.visualization.$graph_type( document.getElementById('visualization_$id') ).draw( data, options );"; |
@@ -9,8 +9,9 @@ discard block |
||
9 | 9 | yourls_do_action( 'pre_stats_countries_map' ); |
10 | 10 | |
11 | 11 | // if $id is null then assign a random string |
12 | - if( $id === null ) |
|
13 | - $id = uniqid ( 'yourls_stats_map_' ); |
|
12 | + if( $id === null ) { |
|
13 | + $id = uniqid ( 'yourls_stats_map_' ); |
|
14 | + } |
|
14 | 15 | |
15 | 16 | $data = array_merge( array( 'Country' => 'Hits' ), $countries ); |
16 | 17 | $data = yourls_google_array_to_data_table( $data ); |
@@ -38,8 +39,9 @@ discard block |
||
38 | 39 | yourls_do_action( 'pre_stats_pie' ); |
39 | 40 | |
40 | 41 | // if $id is null then assign a random string |
41 | - if( $id === null ) |
|
42 | - $id = uniqid ( 'yourls_stats_pie_' ); |
|
42 | + if( $id === null ) { |
|
43 | + $id = uniqid ( 'yourls_stats_pie_' ); |
|
44 | + } |
|
43 | 45 | |
44 | 46 | // Trim array: $limit first item + the sum of all others |
45 | 47 | if ( count( $data ) > $limit ) { |
@@ -102,8 +104,9 @@ discard block |
||
102 | 104 | ) |
103 | 105 | */ |
104 | 106 | |
105 | - if( !$dates ) |
|
106 | - return array(); |
|
107 | + if( !$dates ) { |
|
108 | + return array(); |
|
109 | + } |
|
107 | 110 | |
108 | 111 | // Get first & last years from our range. In our example: 2009 & 2009 |
109 | 112 | $first_year = key( $dates ); |
@@ -164,12 +167,14 @@ discard block |
||
164 | 167 | yourls_do_action( 'pre_stats_line' ); |
165 | 168 | |
166 | 169 | // if $id is null then assign a random string |
167 | - if( $id === null ) |
|
168 | - $id = uniqid ( 'yourls_stats_line_' ); |
|
170 | + if( $id === null ) { |
|
171 | + $id = uniqid ( 'yourls_stats_line_' ); |
|
172 | + } |
|
169 | 173 | |
170 | 174 | // If we have only 1 day of data, prepend a fake day with 0 hits for a prettier graph |
171 | - if ( count( $values ) == 1 ) |
|
172 | - array_unshift( $values, 0 ); |
|
175 | + if ( count( $values ) == 1 ) { |
|
176 | + array_unshift( $values, 0 ); |
|
177 | + } |
|
173 | 178 | |
174 | 179 | // Keep only a subset of values to keep graph smooth |
175 | 180 | $values = yourls_array_granularity( $values, 30 ); |
@@ -211,8 +216,9 @@ discard block |
||
211 | 216 | function yourls_stats_get_best_day( $list_of_days ) { |
212 | 217 | $max = max( $list_of_days ); |
213 | 218 | foreach( $list_of_days as $k=>$v ) { |
214 | - if ( $v == $max ) |
|
215 | - return array( 'day' => $k, 'max' => $max ); |
|
219 | + if ( $v == $max ) { |
|
220 | + return array( 'day' => $k, 'max' => $max ); |
|
221 | + } |
|
216 | 222 | } |
217 | 223 | } |
218 | 224 | |
@@ -227,11 +233,13 @@ discard block |
||
227 | 233 | $host = isset( $parse['host'] ) ? $parse['host'] : ''; |
228 | 234 | $scheme = isset( $parse['scheme'] ) ? $parse['scheme'] : ''; |
229 | 235 | $path = isset( $parse['path'] ) ? $parse['path'] : ''; |
230 | - if( !$host ) |
|
231 | - $host = $path; |
|
236 | + if( !$host ) { |
|
237 | + $host = $path; |
|
238 | + } |
|
232 | 239 | |
233 | - if ( $include_scheme && $scheme ) |
|
234 | - $host = $scheme.'://'.$host; |
|
240 | + if ( $include_scheme && $scheme ) { |
|
241 | + $host = $scheme.'://'.$host; |
|
242 | + } |
|
235 | 243 | |
236 | 244 | return $host; |
237 | 245 | } |
@@ -274,8 +282,9 @@ discard block |
||
274 | 282 | if ( $preserve_max == false ) { |
275 | 283 | unset( $array[$k] ); |
276 | 284 | } else { |
277 | - if ( $v < $max ) |
|
278 | - unset( $array[$k] ); |
|
285 | + if ( $v < $max ) { |
|
286 | + unset( $array[$k] ); |
|
287 | + } |
|
279 | 288 | } |
280 | 289 | } |
281 | 290 | } |
@@ -287,14 +296,14 @@ discard block |
||
287 | 296 | * Transform data array to data table for Google API |
288 | 297 | * |
289 | 298 | */ |
290 | -function yourls_google_array_to_data_table( $data ){ |
|
299 | +function yourls_google_array_to_data_table( $data ) { |
|
291 | 300 | $str = "var data = google.visualization.arrayToDataTable([\n"; |
292 | - foreach( $data as $label => $values ){ |
|
301 | + foreach( $data as $label => $values ) { |
|
293 | 302 | if( !is_array( $values ) ) { |
294 | 303 | $values = array( $values ); |
295 | 304 | } |
296 | 305 | $str .= "\t['$label',"; |
297 | - foreach( $values as $value ){ |
|
306 | + foreach( $values as $value ) { |
|
298 | 307 | if( !is_numeric( $value ) && strpos( $value, '[' ) !== 0 && strpos( $value, '{' ) !== 0 ) { |
299 | 308 | $value = "'$value'"; |
300 | 309 | } |
@@ -9,8 +9,9 @@ discard block |
||
9 | 9 | * |
10 | 10 | */ |
11 | 11 | function yourls_int2string( $num, $chars = null ) { |
12 | - if( $chars == null ) |
|
13 | - $chars = yourls_get_shorturl_charset(); |
|
12 | + if( $chars == null ) { |
|
13 | + $chars = yourls_get_shorturl_charset(); |
|
14 | + } |
|
14 | 15 | $string = ''; |
15 | 16 | $len = strlen( $chars ); |
16 | 17 | while( $num >= $len ) { |
@@ -28,8 +29,9 @@ discard block |
||
28 | 29 | * |
29 | 30 | */ |
30 | 31 | function yourls_string2int( $string, $chars = null ) { |
31 | - if( $chars == null ) |
|
32 | - $chars = yourls_get_shorturl_charset(); |
|
32 | + if( $chars == null ) { |
|
33 | + $chars = yourls_get_shorturl_charset(); |
|
34 | + } |
|
33 | 35 | $integer = 0; |
34 | 36 | $string = strrev( $string ); |
35 | 37 | $baselen = strlen( $chars ); |
@@ -135,7 +137,7 @@ discard block |
||
135 | 137 | * Stolen from WP's _deep_replace |
136 | 138 | * |
137 | 139 | */ |
138 | -function yourls_deep_replace( $search, $subject ){ |
|
140 | +function yourls_deep_replace( $search, $subject ) { |
|
139 | 141 | $found = true; |
140 | 142 | while($found) { |
141 | 143 | $found = false; |
@@ -182,8 +184,9 @@ discard block |
||
182 | 184 | * |
183 | 185 | */ |
184 | 186 | function yourls_sanitize_date_for_sql( $date ) { |
185 | - if( !yourls_sanitize_date( $date ) ) |
|
186 | - return false; |
|
187 | + if( !yourls_sanitize_date( $date ) ) { |
|
188 | + return false; |
|
189 | + } |
|
187 | 190 | return date( 'Y-m-d', strtotime( $date ) ); |
188 | 191 | } |
189 | 192 | |
@@ -235,16 +238,39 @@ discard block |
||
235 | 238 | $length = strlen( $str ); |
236 | 239 | for ( $i=0; $i < $length; $i++ ) { |
237 | 240 | $c = ord( $str[ $i ] ); |
238 | - if ( $c < 0x80 ) $n = 0; # 0bbbbbbb |
|
239 | - elseif (($c & 0xE0) == 0xC0) $n=1; # 110bbbbb |
|
240 | - elseif (($c & 0xF0) == 0xE0) $n=2; # 1110bbbb |
|
241 | - elseif (($c & 0xF8) == 0xF0) $n=3; # 11110bbb |
|
242 | - elseif (($c & 0xFC) == 0xF8) $n=4; # 111110bb |
|
243 | - elseif (($c & 0xFE) == 0xFC) $n=5; # 1111110b |
|
244 | - else return false; # Does not match any model |
|
245 | - for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? |
|
246 | - if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) |
|
247 | - return false; |
|
241 | + if ( $c < 0x80 ) { |
|
242 | + $n = 0; |
|
243 | + } |
|
244 | + # 0bbbbbbb |
|
245 | + elseif (($c & 0xE0) == 0xC0) { |
|
246 | + $n=1; |
|
247 | + } |
|
248 | + # 110bbbbb |
|
249 | + elseif (($c & 0xF0) == 0xE0) { |
|
250 | + $n=2; |
|
251 | + } |
|
252 | + # 1110bbbb |
|
253 | + elseif (($c & 0xF8) == 0xF0) { |
|
254 | + $n=3; |
|
255 | + } |
|
256 | + # 11110bbb |
|
257 | + elseif (($c & 0xFC) == 0xF8) { |
|
258 | + $n=4; |
|
259 | + } |
|
260 | + # 111110bb |
|
261 | + elseif (($c & 0xFE) == 0xFC) { |
|
262 | + $n=5; |
|
263 | + } |
|
264 | + # 1111110b |
|
265 | + else { |
|
266 | + return false; |
|
267 | + } |
|
268 | + # Does not match any model |
|
269 | + for ($j=0; $j<$n; $j++) { |
|
270 | +# n bytes matching 10bbbbbb follow ? |
|
271 | + if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) { |
|
272 | + return false; |
|
273 | + } |
|
248 | 274 | } |
249 | 275 | } |
250 | 276 | return true; |
@@ -321,18 +347,21 @@ discard block |
||
321 | 347 | function yourls_specialchars( $string, $quote_style = ENT_NOQUOTES, $double_encode = false ) { |
322 | 348 | $string = (string) $string; |
323 | 349 | |
324 | - if ( 0 === strlen( $string ) ) |
|
325 | - return ''; |
|
350 | + if ( 0 === strlen( $string ) ) { |
|
351 | + return ''; |
|
352 | + } |
|
326 | 353 | |
327 | 354 | // Don't bother if there are no specialchars - saves some processing |
328 | - if ( ! preg_match( '/[&<>"\']/', $string ) ) |
|
329 | - return $string; |
|
355 | + if ( ! preg_match( '/[&<>"\']/', $string ) ) { |
|
356 | + return $string; |
|
357 | + } |
|
330 | 358 | |
331 | 359 | // Account for the previous behaviour of the function when the $quote_style is not an accepted value |
332 | - if ( empty( $quote_style ) ) |
|
333 | - $quote_style = ENT_NOQUOTES; |
|
334 | - elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) |
|
335 | - $quote_style = ENT_QUOTES; |
|
360 | + if ( empty( $quote_style ) ) { |
|
361 | + $quote_style = ENT_NOQUOTES; |
|
362 | + } elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) { |
|
363 | + $quote_style = ENT_QUOTES; |
|
364 | + } |
|
336 | 365 | |
337 | 366 | $charset = 'UTF-8'; |
338 | 367 | |
@@ -358,15 +387,17 @@ discard block |
||
358 | 387 | // Now re-encode everything except &entity; |
359 | 388 | $string = preg_split( '/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE ); |
360 | 389 | |
361 | - for ( $i = 0; $i < count( $string ); $i += 2 ) |
|
362 | - $string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset ); |
|
390 | + for ( $i = 0; $i < count( $string ); $i += 2 ) { |
|
391 | + $string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset ); |
|
392 | + } |
|
363 | 393 | |
364 | 394 | $string = implode( '', $string ); |
365 | 395 | } |
366 | 396 | |
367 | 397 | // Backwards compatibility |
368 | - if ( 'single' === $_quote_style ) |
|
369 | - $string = str_replace( "'", ''', $string ); |
|
398 | + if ( 'single' === $_quote_style ) { |
|
399 | + $string = str_replace( "'", ''', $string ); |
|
400 | + } |
|
370 | 401 | |
371 | 402 | return $string; |
372 | 403 | } |
@@ -489,8 +520,9 @@ discard block |
||
489 | 520 | $url |
490 | 521 | ); |
491 | 522 | |
492 | - if ( '' == $url ) |
|
493 | - return $url; |
|
523 | + if ( '' == $url ) { |
|
524 | + return $url; |
|
525 | + } |
|
494 | 526 | |
495 | 527 | $original_url = $url; |
496 | 528 | |
@@ -523,8 +555,9 @@ discard block |
||
523 | 555 | // Note: $yourls_allowedprotocols is also globally filterable in functions-kses.php/yourls_kses_init() |
524 | 556 | } |
525 | 557 | |
526 | - if ( !yourls_is_allowed_protocol( $url, $protocols ) ) |
|
527 | - return ''; |
|
558 | + if ( !yourls_is_allowed_protocol( $url, $protocols ) ) { |
|
559 | + return ''; |
|
560 | + } |
|
528 | 561 | |
529 | 562 | // I didn't use KSES function kses_bad_protocol() because it doesn't work the way I liked (returns //blah from illegal://blah) |
530 | 563 | } |
@@ -9,18 +9,18 @@ discard block |
||
9 | 9 | * |
10 | 10 | */ |
11 | 11 | function yourls_int2string( $num, $chars = null ) { |
12 | - if( $chars == null ) |
|
13 | - $chars = yourls_get_shorturl_charset(); |
|
14 | - $string = ''; |
|
15 | - $len = strlen( $chars ); |
|
16 | - while( $num >= $len ) { |
|
17 | - $mod = bcmod( $num, $len ); |
|
18 | - $num = bcdiv( $num, $len ); |
|
19 | - $string = $chars[ $mod ] . $string; |
|
20 | - } |
|
21 | - $string = $chars[ intval( $num ) ] . $string; |
|
12 | + if( $chars == null ) |
|
13 | + $chars = yourls_get_shorturl_charset(); |
|
14 | + $string = ''; |
|
15 | + $len = strlen( $chars ); |
|
16 | + while( $num >= $len ) { |
|
17 | + $mod = bcmod( $num, $len ); |
|
18 | + $num = bcdiv( $num, $len ); |
|
19 | + $string = $chars[ $mod ] . $string; |
|
20 | + } |
|
21 | + $string = $chars[ intval( $num ) ] . $string; |
|
22 | 22 | |
23 | - return yourls_apply_filter( 'int2string', $string, $num, $chars ); |
|
23 | + return yourls_apply_filter( 'int2string', $string, $num, $chars ); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -28,18 +28,18 @@ discard block |
||
28 | 28 | * |
29 | 29 | */ |
30 | 30 | function yourls_string2int( $string, $chars = null ) { |
31 | - if( $chars == null ) |
|
32 | - $chars = yourls_get_shorturl_charset(); |
|
33 | - $integer = 0; |
|
34 | - $string = strrev( $string ); |
|
35 | - $baselen = strlen( $chars ); |
|
36 | - $inputlen = strlen( $string ); |
|
37 | - for ($i = 0; $i < $inputlen; $i++) { |
|
38 | - $index = strpos( $chars, $string[$i] ); |
|
39 | - $integer = bcadd( $integer, bcmul( $index, bcpow( $baselen, $i ) ) ); |
|
40 | - } |
|
31 | + if( $chars == null ) |
|
32 | + $chars = yourls_get_shorturl_charset(); |
|
33 | + $integer = 0; |
|
34 | + $string = strrev( $string ); |
|
35 | + $baselen = strlen( $chars ); |
|
36 | + $inputlen = strlen( $string ); |
|
37 | + for ($i = 0; $i < $inputlen; $i++) { |
|
38 | + $index = strpos( $chars, $string[$i] ); |
|
39 | + $integer = bcadd( $integer, bcmul( $index, bcpow( $baselen, $i ) ) ); |
|
40 | + } |
|
41 | 41 | |
42 | - return yourls_apply_filter( 'string2int', $integer, $string, $chars ); |
|
42 | + return yourls_apply_filter( 'string2int', $integer, $string, $chars ); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * |
48 | 48 | */ |
49 | 49 | function yourls_string2htmlid( $string ) { |
50 | - return yourls_apply_filter( 'string2htmlid', 'y'.abs( crc32( $string ) ) ); |
|
50 | + return yourls_apply_filter( 'string2htmlid', 'y'.abs( crc32( $string ) ) ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $valid = yourls_sanitize_url( $keyword ); |
73 | 73 | } |
74 | 74 | |
75 | - return yourls_apply_filter( 'sanitize_string', $valid, $keyword, $restrict_to_shorturl_charset ); |
|
75 | + return yourls_apply_filter( 'sanitize_string', $valid, $keyword, $restrict_to_shorturl_charset ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -85,15 +85,15 @@ discard block |
||
85 | 85 | * @return string Safe title |
86 | 86 | */ |
87 | 87 | function yourls_sanitize_title( $unsafe_title, $fallback = '' ) { |
88 | - $title = $unsafe_title; |
|
89 | - $title = strip_tags( $title ); |
|
90 | - $title = preg_replace( "/\s+/", ' ', trim( $title ) ); |
|
88 | + $title = $unsafe_title; |
|
89 | + $title = strip_tags( $title ); |
|
90 | + $title = preg_replace( "/\s+/", ' ', trim( $title ) ); |
|
91 | 91 | |
92 | 92 | if ( '' === $title || false === $title ) { |
93 | 93 | $title = $fallback; |
94 | 94 | } |
95 | 95 | |
96 | - return yourls_apply_filter( 'sanitize_title', $title, $unsafe_title, $fallback ); |
|
96 | + return yourls_apply_filter( 'sanitize_title', $title, $unsafe_title, $fallback ); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | * @return string Safe URL |
107 | 107 | */ |
108 | 108 | function yourls_sanitize_url( $unsafe_url, $protocols = array() ) { |
109 | - $url = yourls_esc_url( $unsafe_url, 'redirection', $protocols ); |
|
110 | - return yourls_apply_filter( 'sanitize_url', $url, $unsafe_url ); |
|
109 | + $url = yourls_esc_url( $unsafe_url, 'redirection', $protocols ); |
|
110 | + return yourls_apply_filter( 'sanitize_url', $url, $unsafe_url ); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | * @return string Safe URL |
126 | 126 | */ |
127 | 127 | function yourls_sanitize_url_safe( $unsafe_url, $protocols = array() ) { |
128 | - $url = yourls_esc_url( $unsafe_url, 'safe', $protocols ); |
|
129 | - return yourls_apply_filter( 'sanitize_url_safe', $url, $unsafe_url ); |
|
128 | + $url = yourls_esc_url( $unsafe_url, 'safe', $protocols ); |
|
129 | + return yourls_apply_filter( 'sanitize_url_safe', $url, $unsafe_url ); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -136,18 +136,18 @@ discard block |
||
136 | 136 | * |
137 | 137 | */ |
138 | 138 | function yourls_deep_replace( $search, $subject ){ |
139 | - $found = true; |
|
140 | - while($found) { |
|
141 | - $found = false; |
|
142 | - foreach( (array) $search as $val ) { |
|
143 | - while( strpos( $subject, $val ) !== false ) { |
|
144 | - $found = true; |
|
145 | - $subject = str_replace( $val, '', $subject ); |
|
146 | - } |
|
147 | - } |
|
148 | - } |
|
139 | + $found = true; |
|
140 | + while($found) { |
|
141 | + $found = false; |
|
142 | + foreach( (array) $search as $val ) { |
|
143 | + while( strpos( $subject, $val ) !== false ) { |
|
144 | + $found = true; |
|
145 | + $subject = str_replace( $val, '', $subject ); |
|
146 | + } |
|
147 | + } |
|
148 | + } |
|
149 | 149 | |
150 | - return $subject; |
|
150 | + return $subject; |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * |
156 | 156 | */ |
157 | 157 | function yourls_sanitize_int( $int ) { |
158 | - return ( substr( preg_replace( '/[^0-9]/', '', strval( $int ) ), 0, 20 ) ); |
|
158 | + return ( substr( preg_replace( '/[^0-9]/', '', strval( $int ) ), 0, 20 ) ); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * |
164 | 164 | */ |
165 | 165 | function yourls_sanitize_ip( $ip ) { |
166 | - return preg_replace( '/[^0-9a-fA-F:., ]/', '', $ip ); |
|
166 | + return preg_replace( '/[^0-9a-fA-F:., ]/', '', $ip ); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -171,10 +171,10 @@ discard block |
||
171 | 171 | * |
172 | 172 | */ |
173 | 173 | function yourls_sanitize_date( $date ) { |
174 | - if( !preg_match( '!^\d{1,2}/\d{1,2}/\d{4}$!' , $date ) ) { |
|
175 | - return false; |
|
176 | - } |
|
177 | - return $date; |
|
174 | + if( !preg_match( '!^\d{1,2}/\d{1,2}/\d{4}$!' , $date ) ) { |
|
175 | + return false; |
|
176 | + } |
|
177 | + return $date; |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -182,9 +182,9 @@ discard block |
||
182 | 182 | * |
183 | 183 | */ |
184 | 184 | function yourls_sanitize_date_for_sql( $date ) { |
185 | - if( !yourls_sanitize_date( $date ) ) |
|
186 | - return false; |
|
187 | - return date( 'Y-m-d', strtotime( $date ) ); |
|
185 | + if( !yourls_sanitize_date( $date ) ) |
|
186 | + return false; |
|
187 | + return date( 'Y-m-d', strtotime( $date ) ); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -192,11 +192,11 @@ discard block |
||
192 | 192 | * |
193 | 193 | */ |
194 | 194 | function yourls_trim_long_string( $string, $length = 60, $append = '[...]' ) { |
195 | - $newstring = $string; |
|
195 | + $newstring = $string; |
|
196 | 196 | if ( mb_strlen( $newstring ) > $length ) { |
197 | 197 | $newstring = mb_substr( $newstring, 0, $length - mb_strlen( $append ), 'UTF-8' ) . $append; |
198 | 198 | } |
199 | - return yourls_apply_filter( 'trim_long_string', $newstring, $string, $length, $append ); |
|
199 | + return yourls_apply_filter( 'trim_long_string', $newstring, $string, $length, $append ); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -222,9 +222,9 @@ discard block |
||
222 | 222 | * |
223 | 223 | */ |
224 | 224 | function yourls_sanitize_filename( $file ) { |
225 | - $file = str_replace( '\\', '/', $file ); // sanitize for Win32 installs |
|
226 | - $file = preg_replace( '|/+|' ,'/', $file ); // remove any duplicate slash |
|
227 | - return $file; |
|
225 | + $file = str_replace( '\\', '/', $file ); // sanitize for Win32 installs |
|
226 | + $file = preg_replace( '|/+|' ,'/', $file ); // remove any duplicate slash |
|
227 | + return $file; |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -232,22 +232,22 @@ discard block |
||
232 | 232 | * |
233 | 233 | */ |
234 | 234 | function yourls_seems_utf8( $str ) { |
235 | - $length = strlen( $str ); |
|
236 | - for ( $i=0; $i < $length; $i++ ) { |
|
237 | - $c = ord( $str[ $i ] ); |
|
238 | - if ( $c < 0x80 ) $n = 0; # 0bbbbbbb |
|
239 | - elseif (($c & 0xE0) == 0xC0) $n=1; # 110bbbbb |
|
240 | - elseif (($c & 0xF0) == 0xE0) $n=2; # 1110bbbb |
|
241 | - elseif (($c & 0xF8) == 0xF0) $n=3; # 11110bbb |
|
242 | - elseif (($c & 0xFC) == 0xF8) $n=4; # 111110bb |
|
243 | - elseif (($c & 0xFE) == 0xFC) $n=5; # 1111110b |
|
244 | - else return false; # Does not match any model |
|
245 | - for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? |
|
246 | - if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) |
|
247 | - return false; |
|
248 | - } |
|
249 | - } |
|
250 | - return true; |
|
235 | + $length = strlen( $str ); |
|
236 | + for ( $i=0; $i < $length; $i++ ) { |
|
237 | + $c = ord( $str[ $i ] ); |
|
238 | + if ( $c < 0x80 ) $n = 0; # 0bbbbbbb |
|
239 | + elseif (($c & 0xE0) == 0xC0) $n=1; # 110bbbbb |
|
240 | + elseif (($c & 0xF0) == 0xE0) $n=2; # 1110bbbb |
|
241 | + elseif (($c & 0xF8) == 0xF0) $n=3; # 11110bbb |
|
242 | + elseif (($c & 0xFC) == 0xF8) $n=4; # 111110bb |
|
243 | + elseif (($c & 0xFE) == 0xFC) $n=5; # 1111110b |
|
244 | + else return false; # Does not match any model |
|
245 | + for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? |
|
246 | + if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) |
|
247 | + return false; |
|
248 | + } |
|
249 | + } |
|
250 | + return true; |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | |
@@ -279,28 +279,28 @@ discard block |
||
279 | 279 | * @return string The checked text. |
280 | 280 | */ |
281 | 281 | function yourls_check_invalid_utf8( $string, $strip = false ) { |
282 | - $string = (string) $string; |
|
282 | + $string = (string) $string; |
|
283 | 283 | |
284 | - if ( 0 === strlen( $string ) ) { |
|
285 | - return ''; |
|
286 | - } |
|
284 | + if ( 0 === strlen( $string ) ) { |
|
285 | + return ''; |
|
286 | + } |
|
287 | 287 | |
288 | - // We can't demand utf8 in the PCRE installation, so just return the string in those cases |
|
289 | - if ( ! yourls_supports_pcre_u() ) { |
|
290 | - return $string; |
|
291 | - } |
|
288 | + // We can't demand utf8 in the PCRE installation, so just return the string in those cases |
|
289 | + if ( ! yourls_supports_pcre_u() ) { |
|
290 | + return $string; |
|
291 | + } |
|
292 | 292 | |
293 | - // preg_match fails when it encounters invalid UTF8 in $string |
|
294 | - if ( 1 === @preg_match( '/^./us', $string ) ) { |
|
295 | - return $string; |
|
296 | - } |
|
293 | + // preg_match fails when it encounters invalid UTF8 in $string |
|
294 | + if ( 1 === @preg_match( '/^./us', $string ) ) { |
|
295 | + return $string; |
|
296 | + } |
|
297 | 297 | |
298 | - // Attempt to strip the bad chars if requested (not recommended) |
|
299 | - if ( $strip && function_exists( 'iconv' ) ) { |
|
300 | - return iconv( 'utf-8', 'utf-8', $string ); |
|
301 | - } |
|
298 | + // Attempt to strip the bad chars if requested (not recommended) |
|
299 | + if ( $strip && function_exists( 'iconv' ) ) { |
|
300 | + return iconv( 'utf-8', 'utf-8', $string ); |
|
301 | + } |
|
302 | 302 | |
303 | - return ''; |
|
303 | + return ''; |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -319,56 +319,56 @@ discard block |
||
319 | 319 | * @return string The encoded text with HTML entities. |
320 | 320 | */ |
321 | 321 | function yourls_specialchars( $string, $quote_style = ENT_NOQUOTES, $double_encode = false ) { |
322 | - $string = (string) $string; |
|
322 | + $string = (string) $string; |
|
323 | 323 | |
324 | - if ( 0 === strlen( $string ) ) |
|
325 | - return ''; |
|
324 | + if ( 0 === strlen( $string ) ) |
|
325 | + return ''; |
|
326 | 326 | |
327 | - // Don't bother if there are no specialchars - saves some processing |
|
328 | - if ( ! preg_match( '/[&<>"\']/', $string ) ) |
|
329 | - return $string; |
|
327 | + // Don't bother if there are no specialchars - saves some processing |
|
328 | + if ( ! preg_match( '/[&<>"\']/', $string ) ) |
|
329 | + return $string; |
|
330 | 330 | |
331 | - // Account for the previous behaviour of the function when the $quote_style is not an accepted value |
|
332 | - if ( empty( $quote_style ) ) |
|
333 | - $quote_style = ENT_NOQUOTES; |
|
334 | - elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) |
|
335 | - $quote_style = ENT_QUOTES; |
|
331 | + // Account for the previous behaviour of the function when the $quote_style is not an accepted value |
|
332 | + if ( empty( $quote_style ) ) |
|
333 | + $quote_style = ENT_NOQUOTES; |
|
334 | + elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) |
|
335 | + $quote_style = ENT_QUOTES; |
|
336 | 336 | |
337 | - $charset = 'UTF-8'; |
|
337 | + $charset = 'UTF-8'; |
|
338 | 338 | |
339 | - $_quote_style = $quote_style; |
|
339 | + $_quote_style = $quote_style; |
|
340 | 340 | |
341 | - if ( $quote_style === 'double' ) { |
|
342 | - $quote_style = ENT_COMPAT; |
|
343 | - $_quote_style = ENT_COMPAT; |
|
344 | - } elseif ( $quote_style === 'single' ) { |
|
345 | - $quote_style = ENT_NOQUOTES; |
|
346 | - } |
|
341 | + if ( $quote_style === 'double' ) { |
|
342 | + $quote_style = ENT_COMPAT; |
|
343 | + $_quote_style = ENT_COMPAT; |
|
344 | + } elseif ( $quote_style === 'single' ) { |
|
345 | + $quote_style = ENT_NOQUOTES; |
|
346 | + } |
|
347 | 347 | |
348 | - // Handle double encoding ourselves |
|
349 | - if ( $double_encode ) { |
|
350 | - $string = @htmlspecialchars( $string, $quote_style, $charset ); |
|
351 | - } else { |
|
352 | - // Decode & into & |
|
353 | - $string = yourls_specialchars_decode( $string, $_quote_style ); |
|
348 | + // Handle double encoding ourselves |
|
349 | + if ( $double_encode ) { |
|
350 | + $string = @htmlspecialchars( $string, $quote_style, $charset ); |
|
351 | + } else { |
|
352 | + // Decode & into & |
|
353 | + $string = yourls_specialchars_decode( $string, $_quote_style ); |
|
354 | 354 | |
355 | - // Guarantee every &entity; is valid or re-encode the & |
|
356 | - $string = yourls_kses_normalize_entities( $string ); |
|
355 | + // Guarantee every &entity; is valid or re-encode the & |
|
356 | + $string = yourls_kses_normalize_entities( $string ); |
|
357 | 357 | |
358 | - // Now re-encode everything except &entity; |
|
359 | - $string = preg_split( '/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE ); |
|
358 | + // Now re-encode everything except &entity; |
|
359 | + $string = preg_split( '/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE ); |
|
360 | 360 | |
361 | - for ( $i = 0; $i < count( $string ); $i += 2 ) |
|
362 | - $string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset ); |
|
361 | + for ( $i = 0; $i < count( $string ); $i += 2 ) |
|
362 | + $string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset ); |
|
363 | 363 | |
364 | - $string = implode( '', $string ); |
|
365 | - } |
|
364 | + $string = implode( '', $string ); |
|
365 | + } |
|
366 | 366 | |
367 | - // Backwards compatibility |
|
368 | - if ( 'single' === $_quote_style ) |
|
369 | - $string = str_replace( "'", ''', $string ); |
|
367 | + // Backwards compatibility |
|
368 | + if ( 'single' === $_quote_style ) |
|
369 | + $string = str_replace( "'", ''', $string ); |
|
370 | 370 | |
371 | - return $string; |
|
371 | + return $string; |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
@@ -386,51 +386,51 @@ discard block |
||
386 | 386 | * @return string The decoded text without HTML entities. |
387 | 387 | */ |
388 | 388 | function yourls_specialchars_decode( $string, $quote_style = ENT_NOQUOTES ) { |
389 | - $string = (string) $string; |
|
390 | - |
|
391 | - if ( 0 === strlen( $string ) ) { |
|
392 | - return ''; |
|
393 | - } |
|
394 | - |
|
395 | - // Don't bother if there are no entities - saves a lot of processing |
|
396 | - if ( strpos( $string, '&' ) === false ) { |
|
397 | - return $string; |
|
398 | - } |
|
399 | - |
|
400 | - // Match the previous behaviour of _wp_specialchars() when the $quote_style is not an accepted value |
|
401 | - if ( empty( $quote_style ) ) { |
|
402 | - $quote_style = ENT_NOQUOTES; |
|
403 | - } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) { |
|
404 | - $quote_style = ENT_QUOTES; |
|
405 | - } |
|
406 | - |
|
407 | - // More complete than get_html_translation_table( HTML_SPECIALCHARS ) |
|
408 | - $single = array( ''' => '\'', ''' => '\'' ); |
|
409 | - $single_preg = array( '/�*39;/' => ''', '/�*27;/i' => ''' ); |
|
410 | - $double = array( '"' => '"', '"' => '"', '"' => '"' ); |
|
411 | - $double_preg = array( '/�*34;/' => '"', '/�*22;/i' => '"' ); |
|
412 | - $others = array( '<' => '<', '<' => '<', '>' => '>', '>' => '>', '&' => '&', '&' => '&', '&' => '&' ); |
|
413 | - $others_preg = array( '/�*60;/' => '<', '/�*62;/' => '>', '/�*38;/' => '&', '/�*26;/i' => '&' ); |
|
414 | - |
|
415 | - if ( $quote_style === ENT_QUOTES ) { |
|
416 | - $translation = array_merge( $single, $double, $others ); |
|
417 | - $translation_preg = array_merge( $single_preg, $double_preg, $others_preg ); |
|
418 | - } elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) { |
|
419 | - $translation = array_merge( $double, $others ); |
|
420 | - $translation_preg = array_merge( $double_preg, $others_preg ); |
|
421 | - } elseif ( $quote_style === 'single' ) { |
|
422 | - $translation = array_merge( $single, $others ); |
|
423 | - $translation_preg = array_merge( $single_preg, $others_preg ); |
|
424 | - } elseif ( $quote_style === ENT_NOQUOTES ) { |
|
425 | - $translation = $others; |
|
426 | - $translation_preg = $others_preg; |
|
427 | - } |
|
428 | - |
|
429 | - // Remove zero padding on numeric entities |
|
430 | - $string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string ); |
|
431 | - |
|
432 | - // Replace characters according to translation table |
|
433 | - return strtr( $string, $translation ); |
|
389 | + $string = (string) $string; |
|
390 | + |
|
391 | + if ( 0 === strlen( $string ) ) { |
|
392 | + return ''; |
|
393 | + } |
|
394 | + |
|
395 | + // Don't bother if there are no entities - saves a lot of processing |
|
396 | + if ( strpos( $string, '&' ) === false ) { |
|
397 | + return $string; |
|
398 | + } |
|
399 | + |
|
400 | + // Match the previous behaviour of _wp_specialchars() when the $quote_style is not an accepted value |
|
401 | + if ( empty( $quote_style ) ) { |
|
402 | + $quote_style = ENT_NOQUOTES; |
|
403 | + } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) { |
|
404 | + $quote_style = ENT_QUOTES; |
|
405 | + } |
|
406 | + |
|
407 | + // More complete than get_html_translation_table( HTML_SPECIALCHARS ) |
|
408 | + $single = array( ''' => '\'', ''' => '\'' ); |
|
409 | + $single_preg = array( '/�*39;/' => ''', '/�*27;/i' => ''' ); |
|
410 | + $double = array( '"' => '"', '"' => '"', '"' => '"' ); |
|
411 | + $double_preg = array( '/�*34;/' => '"', '/�*22;/i' => '"' ); |
|
412 | + $others = array( '<' => '<', '<' => '<', '>' => '>', '>' => '>', '&' => '&', '&' => '&', '&' => '&' ); |
|
413 | + $others_preg = array( '/�*60;/' => '<', '/�*62;/' => '>', '/�*38;/' => '&', '/�*26;/i' => '&' ); |
|
414 | + |
|
415 | + if ( $quote_style === ENT_QUOTES ) { |
|
416 | + $translation = array_merge( $single, $double, $others ); |
|
417 | + $translation_preg = array_merge( $single_preg, $double_preg, $others_preg ); |
|
418 | + } elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) { |
|
419 | + $translation = array_merge( $double, $others ); |
|
420 | + $translation_preg = array_merge( $double_preg, $others_preg ); |
|
421 | + } elseif ( $quote_style === 'single' ) { |
|
422 | + $translation = array_merge( $single, $others ); |
|
423 | + $translation_preg = array_merge( $single_preg, $others_preg ); |
|
424 | + } elseif ( $quote_style === ENT_NOQUOTES ) { |
|
425 | + $translation = $others; |
|
426 | + $translation_preg = $others_preg; |
|
427 | + } |
|
428 | + |
|
429 | + // Remove zero padding on numeric entities |
|
430 | + $string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string ); |
|
431 | + |
|
432 | + // Replace characters according to translation table |
|
433 | + return strtr( $string, $translation ); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | |
@@ -443,9 +443,9 @@ discard block |
||
443 | 443 | * @return string |
444 | 444 | */ |
445 | 445 | function yourls_esc_html( $text ) { |
446 | - $safe_text = yourls_check_invalid_utf8( $text ); |
|
447 | - $safe_text = yourls_specialchars( $safe_text, ENT_QUOTES ); |
|
448 | - return yourls_apply_filter( 'esc_html', $safe_text, $text ); |
|
446 | + $safe_text = yourls_check_invalid_utf8( $text ); |
|
447 | + $safe_text = yourls_specialchars( $safe_text, ENT_QUOTES ); |
|
448 | + return yourls_apply_filter( 'esc_html', $safe_text, $text ); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | /** |
@@ -457,9 +457,9 @@ discard block |
||
457 | 457 | * @return string |
458 | 458 | */ |
459 | 459 | function yourls_esc_attr( $text ) { |
460 | - $safe_text = yourls_check_invalid_utf8( $text ); |
|
461 | - $safe_text = yourls_specialchars( $safe_text, ENT_QUOTES ); |
|
462 | - return yourls_apply_filter( 'esc_attr', $safe_text, $text ); |
|
460 | + $safe_text = yourls_check_invalid_utf8( $text ); |
|
461 | + $safe_text = yourls_specialchars( $safe_text, ENT_QUOTES ); |
|
462 | + return yourls_apply_filter( 'esc_attr', $safe_text, $text ); |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | /** |
@@ -482,38 +482,38 @@ discard block |
||
482 | 482 | // trim first -- see #1931 |
483 | 483 | $url = trim( $url ); |
484 | 484 | |
485 | - // make sure there's only one 'http://' at the beginning (prevents pasting a URL right after the default 'http://') |
|
486 | - $url = str_replace( |
|
487 | - array( 'http://http://', 'http://https://' ), |
|
488 | - array( 'http://', 'https://' ), |
|
489 | - $url |
|
490 | - ); |
|
485 | + // make sure there's only one 'http://' at the beginning (prevents pasting a URL right after the default 'http://') |
|
486 | + $url = str_replace( |
|
487 | + array( 'http://http://', 'http://https://' ), |
|
488 | + array( 'http://', 'https://' ), |
|
489 | + $url |
|
490 | + ); |
|
491 | 491 | |
492 | - if ( '' == $url ) |
|
493 | - return $url; |
|
492 | + if ( '' == $url ) |
|
493 | + return $url; |
|
494 | 494 | |
495 | - $original_url = $url; |
|
495 | + $original_url = $url; |
|
496 | 496 | |
497 | - // force scheme and domain to lowercase - see issues 591 and 1630 |
|
497 | + // force scheme and domain to lowercase - see issues 591 and 1630 |
|
498 | 498 | $url = yourls_normalize_uri( $url ); |
499 | 499 | |
500 | - $url = preg_replace( '|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff]|i', '', $url ); |
|
501 | - // Previous regexp in YOURLS was '|[^a-z0-9-~+_.?\[\]\^#=!&;,/:%@$\|*`\'<>"()\\x80-\\xff\{\}]|i' |
|
502 | - // TODO: check if that was it too destructive |
|
500 | + $url = preg_replace( '|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff]|i', '', $url ); |
|
501 | + // Previous regexp in YOURLS was '|[^a-z0-9-~+_.?\[\]\^#=!&;,/:%@$\|*`\'<>"()\\x80-\\xff\{\}]|i' |
|
502 | + // TODO: check if that was it too destructive |
|
503 | 503 | |
504 | 504 | // If $context is 'safe', an extra step is taken to make sure no CRLF injection is possible. |
505 | 505 | // To be used when $url can be forged by evil user (eg it's from a $_SERVER variable, a query string, etc..) |
506 | - if ( 'safe' == $context ) { |
|
506 | + if ( 'safe' == $context ) { |
|
507 | 507 | $strip = array( '%0d', '%0a', '%0D', '%0A' ); |
508 | 508 | $url = yourls_deep_replace( $strip, $url ); |
509 | 509 | } |
510 | 510 | |
511 | - // Replace ampersands and single quotes only when displaying. |
|
512 | - if ( 'display' == $context ) { |
|
513 | - $url = yourls_kses_normalize_entities( $url ); |
|
514 | - $url = str_replace( '&', '&', $url ); |
|
515 | - $url = str_replace( "'", ''', $url ); |
|
516 | - } |
|
511 | + // Replace ampersands and single quotes only when displaying. |
|
512 | + if ( 'display' == $context ) { |
|
513 | + $url = yourls_kses_normalize_entities( $url ); |
|
514 | + $url = str_replace( '&', '&', $url ); |
|
515 | + $url = str_replace( "'", ''', $url ); |
|
516 | + } |
|
517 | 517 | |
518 | 518 | // If there's a protocol, make sure it's OK |
519 | 519 | if( yourls_get_protocol($url) !== '' ) { |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | // I didn't use KSES function kses_bad_protocol() because it doesn't work the way I liked (returns //blah from illegal://blah) |
530 | 530 | } |
531 | 531 | |
532 | - return yourls_apply_filter( 'esc_url', $url, $original_url, $context ); |
|
532 | + return yourls_apply_filter( 'esc_url', $url, $original_url, $context ); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | * are considered the same. Explicitely mention option and variant to avoid notice |
607 | 607 | * on PHP 7.2 and 7.3 |
608 | 608 | */ |
609 | - $lower['host'] = idn_to_utf8($lower['host'], IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46); |
|
609 | + $lower['host'] = idn_to_utf8($lower['host'], IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46); |
|
610 | 610 | } |
611 | 611 | |
612 | 612 | $url = http_build_url($url, $lower); |
@@ -628,12 +628,12 @@ discard block |
||
628 | 628 | * @return string Escaped text. |
629 | 629 | */ |
630 | 630 | function yourls_esc_js( $text ) { |
631 | - $safe_text = yourls_check_invalid_utf8( $text ); |
|
632 | - $safe_text = yourls_specialchars( $safe_text, ENT_COMPAT ); |
|
633 | - $safe_text = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes( $safe_text ) ); |
|
634 | - $safe_text = str_replace( "\r", '', $safe_text ); |
|
635 | - $safe_text = str_replace( "\n", '\\n', addslashes( $safe_text ) ); |
|
636 | - return yourls_apply_filter( 'esc_js', $safe_text, $text ); |
|
631 | + $safe_text = yourls_check_invalid_utf8( $text ); |
|
632 | + $safe_text = yourls_specialchars( $safe_text, ENT_COMPAT ); |
|
633 | + $safe_text = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes( $safe_text ) ); |
|
634 | + $safe_text = str_replace( "\r", '', $safe_text ); |
|
635 | + $safe_text = str_replace( "\n", '\\n', addslashes( $safe_text ) ); |
|
636 | + return yourls_apply_filter( 'esc_js', $safe_text, $text ); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | /** |
@@ -645,8 +645,8 @@ discard block |
||
645 | 645 | * @return string |
646 | 646 | */ |
647 | 647 | function yourls_esc_textarea( $text ) { |
648 | - $safe_text = htmlspecialchars( $text, ENT_QUOTES ); |
|
649 | - return yourls_apply_filter( 'esc_textarea', $safe_text, $text ); |
|
648 | + $safe_text = htmlspecialchars( $text, ENT_QUOTES ); |
|
649 | + return yourls_apply_filter( 'esc_textarea', $safe_text, $text ); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | |
@@ -658,18 +658,18 @@ discard block |
||
658 | 658 | * @return string |
659 | 659 | */ |
660 | 660 | function yourls_encodeURI( $url ) { |
661 | - // Decode URL all the way |
|
662 | - $result = yourls_rawurldecode_while_encoded( $url ); |
|
663 | - // Encode once |
|
664 | - $result = strtr( rawurlencode( $result ), array ( |
|
661 | + // Decode URL all the way |
|
662 | + $result = yourls_rawurldecode_while_encoded( $url ); |
|
663 | + // Encode once |
|
664 | + $result = strtr( rawurlencode( $result ), array ( |
|
665 | 665 | '%3B' => ';', '%2C' => ',', '%2F' => '/', '%3F' => '?', '%3A' => ':', '%40' => '@', |
666 | - '%26' => '&', '%3D' => '=', '%2B' => '+', '%24' => '$', '%21' => '!', '%2A' => '*', |
|
667 | - '%27' => '\'', '%28' => '(', '%29' => ')', '%23' => '#', |
|
666 | + '%26' => '&', '%3D' => '=', '%2B' => '+', '%24' => '$', '%21' => '!', '%2A' => '*', |
|
667 | + '%27' => '\'', '%28' => '(', '%29' => ')', '%23' => '#', |
|
668 | 668 | ) ); |
669 | - // @TODO: |
|
670 | - // Known limit: this will most likely break IDN URLs such as http://www.académie-française.fr/ |
|
671 | - // To fully support IDN URLs, advocate use of a plugin. |
|
672 | - return yourls_apply_filter( 'encodeURI', $result, $url ); |
|
669 | + // @TODO: |
|
670 | + // Known limit: this will most likely break IDN URLs such as http://www.académie-française.fr/ |
|
671 | + // To fully support IDN URLs, advocate use of a plugin. |
|
672 | + return yourls_apply_filter( 'encodeURI', $result, $url ); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | /** |
@@ -696,7 +696,7 @@ discard block |
||
696 | 696 | * @return bool |
697 | 697 | */ |
698 | 698 | function yourls_is_rawurlencoded( $string ) { |
699 | - return rawurldecode( $string ) != $string; |
|
699 | + return rawurldecode( $string ) != $string; |
|
700 | 700 | } |
701 | 701 | |
702 | 702 | /** |
@@ -710,11 +710,11 @@ discard block |
||
710 | 710 | * @return string |
711 | 711 | */ |
712 | 712 | function yourls_rawurldecode_while_encoded( $string ) { |
713 | - $string = rawurldecode( $string ); |
|
714 | - if( yourls_is_rawurlencoded( $string ) ) { |
|
715 | - $string = yourls_rawurldecode_while_encoded( $string ); |
|
716 | - } |
|
717 | - return $string; |
|
713 | + $string = rawurldecode( $string ); |
|
714 | + if( yourls_is_rawurlencoded( $string ) ) { |
|
715 | + $string = yourls_rawurldecode_while_encoded( $string ); |
|
716 | + } |
|
717 | + return $string; |
|
718 | 718 | } |
719 | 719 | |
720 | 720 | /** |
@@ -8,46 +8,46 @@ discard block |
||
8 | 8 | * Convert an integer (1337) to a string (3jk). |
9 | 9 | * |
10 | 10 | */ |
11 | -function yourls_int2string( $num, $chars = null ) { |
|
12 | - if( $chars == null ) |
|
11 | +function yourls_int2string($num, $chars = null) { |
|
12 | + if ($chars == null) |
|
13 | 13 | $chars = yourls_get_shorturl_charset(); |
14 | 14 | $string = ''; |
15 | - $len = strlen( $chars ); |
|
16 | - while( $num >= $len ) { |
|
17 | - $mod = bcmod( $num, $len ); |
|
18 | - $num = bcdiv( $num, $len ); |
|
19 | - $string = $chars[ $mod ] . $string; |
|
15 | + $len = strlen($chars); |
|
16 | + while ($num >= $len) { |
|
17 | + $mod = bcmod($num, $len); |
|
18 | + $num = bcdiv($num, $len); |
|
19 | + $string = $chars[$mod].$string; |
|
20 | 20 | } |
21 | - $string = $chars[ intval( $num ) ] . $string; |
|
21 | + $string = $chars[intval($num)].$string; |
|
22 | 22 | |
23 | - return yourls_apply_filter( 'int2string', $string, $num, $chars ); |
|
23 | + return yourls_apply_filter('int2string', $string, $num, $chars); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Convert a string (3jk) to an integer (1337) |
28 | 28 | * |
29 | 29 | */ |
30 | -function yourls_string2int( $string, $chars = null ) { |
|
31 | - if( $chars == null ) |
|
30 | +function yourls_string2int($string, $chars = null) { |
|
31 | + if ($chars == null) |
|
32 | 32 | $chars = yourls_get_shorturl_charset(); |
33 | 33 | $integer = 0; |
34 | - $string = strrev( $string ); |
|
35 | - $baselen = strlen( $chars ); |
|
36 | - $inputlen = strlen( $string ); |
|
34 | + $string = strrev($string); |
|
35 | + $baselen = strlen($chars); |
|
36 | + $inputlen = strlen($string); |
|
37 | 37 | for ($i = 0; $i < $inputlen; $i++) { |
38 | - $index = strpos( $chars, $string[$i] ); |
|
39 | - $integer = bcadd( $integer, bcmul( $index, bcpow( $baselen, $i ) ) ); |
|
38 | + $index = strpos($chars, $string[$i]); |
|
39 | + $integer = bcadd($integer, bcmul($index, bcpow($baselen, $i))); |
|
40 | 40 | } |
41 | 41 | |
42 | - return yourls_apply_filter( 'string2int', $integer, $string, $chars ); |
|
42 | + return yourls_apply_filter('string2int', $integer, $string, $chars); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * Return a unique(ish) hash for a string to be used as a valid HTML id |
47 | 47 | * |
48 | 48 | */ |
49 | -function yourls_string2htmlid( $string ) { |
|
50 | - return yourls_apply_filter( 'string2htmlid', 'y'.abs( crc32( $string ) ) ); |
|
49 | +function yourls_string2htmlid($string) { |
|
50 | + return yourls_apply_filter('string2htmlid', 'y'.abs(crc32($string))); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -63,16 +63,16 @@ discard block |
||
63 | 63 | * @param bool $restrict_to_shorturl_charset Optional, default false. True if we want the keyword to comply to short URL charset |
64 | 64 | * @return string The sanitized keyword |
65 | 65 | */ |
66 | -function yourls_sanitize_keyword( $keyword, $restrict_to_shorturl_charset = false ) { |
|
67 | - if( $restrict_to_shorturl_charset === true ) { |
|
66 | +function yourls_sanitize_keyword($keyword, $restrict_to_shorturl_charset = false) { |
|
67 | + if ($restrict_to_shorturl_charset === true) { |
|
68 | 68 | // make a regexp pattern with the shorturl charset, and remove everything but this |
69 | - $pattern = yourls_make_regexp_pattern( yourls_get_shorturl_charset() ); |
|
70 | - $valid = (string) substr( preg_replace( '![^'.$pattern.']!', '', $keyword ), 0, 199 ); |
|
69 | + $pattern = yourls_make_regexp_pattern(yourls_get_shorturl_charset()); |
|
70 | + $valid = (string) substr(preg_replace('![^'.$pattern.']!', '', $keyword), 0, 199); |
|
71 | 71 | } else { |
72 | - $valid = yourls_sanitize_url( $keyword ); |
|
72 | + $valid = yourls_sanitize_url($keyword); |
|
73 | 73 | } |
74 | 74 | |
75 | - return yourls_apply_filter( 'sanitize_string', $valid, $keyword, $restrict_to_shorturl_charset ); |
|
75 | + return yourls_apply_filter('sanitize_string', $valid, $keyword, $restrict_to_shorturl_charset); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -84,16 +84,16 @@ discard block |
||
84 | 84 | * @param string $fallback Optional fallback if after sanitization nothing remains |
85 | 85 | * @return string Safe title |
86 | 86 | */ |
87 | -function yourls_sanitize_title( $unsafe_title, $fallback = '' ) { |
|
87 | +function yourls_sanitize_title($unsafe_title, $fallback = '') { |
|
88 | 88 | $title = $unsafe_title; |
89 | - $title = strip_tags( $title ); |
|
90 | - $title = preg_replace( "/\s+/", ' ', trim( $title ) ); |
|
89 | + $title = strip_tags($title); |
|
90 | + $title = preg_replace("/\s+/", ' ', trim($title)); |
|
91 | 91 | |
92 | - if ( '' === $title || false === $title ) { |
|
92 | + if ('' === $title || false === $title) { |
|
93 | 93 | $title = $fallback; |
94 | 94 | } |
95 | 95 | |
96 | - return yourls_apply_filter( 'sanitize_title', $title, $unsafe_title, $fallback ); |
|
96 | + return yourls_apply_filter('sanitize_title', $title, $unsafe_title, $fallback); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | * @param array $protocols Optional allowed protocols, default to global $yourls_allowedprotocols |
106 | 106 | * @return string Safe URL |
107 | 107 | */ |
108 | -function yourls_sanitize_url( $unsafe_url, $protocols = array() ) { |
|
109 | - $url = yourls_esc_url( $unsafe_url, 'redirection', $protocols ); |
|
110 | - return yourls_apply_filter( 'sanitize_url', $url, $unsafe_url ); |
|
108 | +function yourls_sanitize_url($unsafe_url, $protocols = array()) { |
|
109 | + $url = yourls_esc_url($unsafe_url, 'redirection', $protocols); |
|
110 | + return yourls_apply_filter('sanitize_url', $url, $unsafe_url); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | * @param array $protocols Optional allowed protocols, default to global $yourls_allowedprotocols |
125 | 125 | * @return string Safe URL |
126 | 126 | */ |
127 | -function yourls_sanitize_url_safe( $unsafe_url, $protocols = array() ) { |
|
128 | - $url = yourls_esc_url( $unsafe_url, 'safe', $protocols ); |
|
129 | - return yourls_apply_filter( 'sanitize_url_safe', $url, $unsafe_url ); |
|
127 | +function yourls_sanitize_url_safe($unsafe_url, $protocols = array()) { |
|
128 | + $url = yourls_esc_url($unsafe_url, 'safe', $protocols); |
|
129 | + return yourls_apply_filter('sanitize_url_safe', $url, $unsafe_url); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -135,14 +135,14 @@ discard block |
||
135 | 135 | * Stolen from WP's _deep_replace |
136 | 136 | * |
137 | 137 | */ |
138 | -function yourls_deep_replace( $search, $subject ){ |
|
138 | +function yourls_deep_replace($search, $subject) { |
|
139 | 139 | $found = true; |
140 | - while($found) { |
|
140 | + while ($found) { |
|
141 | 141 | $found = false; |
142 | - foreach( (array) $search as $val ) { |
|
143 | - while( strpos( $subject, $val ) !== false ) { |
|
142 | + foreach ((array) $search as $val) { |
|
143 | + while (strpos($subject, $val) !== false) { |
|
144 | 144 | $found = true; |
145 | - $subject = str_replace( $val, '', $subject ); |
|
145 | + $subject = str_replace($val, '', $subject); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | } |
@@ -154,24 +154,24 @@ discard block |
||
154 | 154 | * Make sure an integer is a valid integer (PHP's intval() limits to too small numbers) |
155 | 155 | * |
156 | 156 | */ |
157 | -function yourls_sanitize_int( $int ) { |
|
158 | - return ( substr( preg_replace( '/[^0-9]/', '', strval( $int ) ), 0, 20 ) ); |
|
157 | +function yourls_sanitize_int($int) { |
|
158 | + return (substr(preg_replace('/[^0-9]/', '', strval($int)), 0, 20)); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
162 | 162 | * Sanitize an IP address |
163 | 163 | * |
164 | 164 | */ |
165 | -function yourls_sanitize_ip( $ip ) { |
|
166 | - return preg_replace( '/[^0-9a-fA-F:., ]/', '', $ip ); |
|
165 | +function yourls_sanitize_ip($ip) { |
|
166 | + return preg_replace('/[^0-9a-fA-F:., ]/', '', $ip); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
170 | 170 | * Make sure a date is m(m)/d(d)/yyyy, return false otherwise |
171 | 171 | * |
172 | 172 | */ |
173 | -function yourls_sanitize_date( $date ) { |
|
174 | - if( !preg_match( '!^\d{1,2}/\d{1,2}/\d{4}$!' , $date ) ) { |
|
173 | +function yourls_sanitize_date($date) { |
|
174 | + if (!preg_match('!^\d{1,2}/\d{1,2}/\d{4}$!', $date)) { |
|
175 | 175 | return false; |
176 | 176 | } |
177 | 177 | return $date; |
@@ -181,22 +181,22 @@ discard block |
||
181 | 181 | * Sanitize a date for SQL search. Return false if malformed input. |
182 | 182 | * |
183 | 183 | */ |
184 | -function yourls_sanitize_date_for_sql( $date ) { |
|
185 | - if( !yourls_sanitize_date( $date ) ) |
|
184 | +function yourls_sanitize_date_for_sql($date) { |
|
185 | + if (!yourls_sanitize_date($date)) |
|
186 | 186 | return false; |
187 | - return date( 'Y-m-d', strtotime( $date ) ); |
|
187 | + return date('Y-m-d', strtotime($date)); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | 191 | * Return trimmed string |
192 | 192 | * |
193 | 193 | */ |
194 | -function yourls_trim_long_string( $string, $length = 60, $append = '[...]' ) { |
|
194 | +function yourls_trim_long_string($string, $length = 60, $append = '[...]') { |
|
195 | 195 | $newstring = $string; |
196 | - if ( mb_strlen( $newstring ) > $length ) { |
|
197 | - $newstring = mb_substr( $newstring, 0, $length - mb_strlen( $append ), 'UTF-8' ) . $append; |
|
196 | + if (mb_strlen($newstring) > $length) { |
|
197 | + $newstring = mb_substr($newstring, 0, $length - mb_strlen($append), 'UTF-8').$append; |
|
198 | 198 | } |
199 | - return yourls_apply_filter( 'trim_long_string', $newstring, $string, $length, $append ); |
|
199 | + return yourls_apply_filter('trim_long_string', $newstring, $string, $length, $append); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -210,8 +210,8 @@ discard block |
||
210 | 210 | * @param string $version Version number |
211 | 211 | * @return string Sanitized version number |
212 | 212 | */ |
213 | -function yourls_sanitize_version( $version ) { |
|
214 | - preg_match( '/([0-9]+\.[0-9.]+).*$/', $version, $matches ); |
|
213 | +function yourls_sanitize_version($version) { |
|
214 | + preg_match('/([0-9]+\.[0-9.]+).*$/', $version, $matches); |
|
215 | 215 | $version = isset($matches[1]) ? trim($matches[1], '.') : ''; |
216 | 216 | |
217 | 217 | return $version; |
@@ -221,9 +221,9 @@ discard block |
||
221 | 221 | * Sanitize a filename (no Win32 stuff) |
222 | 222 | * |
223 | 223 | */ |
224 | -function yourls_sanitize_filename( $file ) { |
|
225 | - $file = str_replace( '\\', '/', $file ); // sanitize for Win32 installs |
|
226 | - $file = preg_replace( '|/+|' ,'/', $file ); // remove any duplicate slash |
|
224 | +function yourls_sanitize_filename($file) { |
|
225 | + $file = str_replace('\\', '/', $file); // sanitize for Win32 installs |
|
226 | + $file = preg_replace('|/+|', '/', $file); // remove any duplicate slash |
|
227 | 227 | return $file; |
228 | 228 | } |
229 | 229 | |
@@ -231,18 +231,18 @@ discard block |
||
231 | 231 | * Check if a string seems to be UTF-8. Stolen from WP. |
232 | 232 | * |
233 | 233 | */ |
234 | -function yourls_seems_utf8( $str ) { |
|
235 | - $length = strlen( $str ); |
|
236 | - for ( $i=0; $i < $length; $i++ ) { |
|
237 | - $c = ord( $str[ $i ] ); |
|
238 | - if ( $c < 0x80 ) $n = 0; # 0bbbbbbb |
|
239 | - elseif (($c & 0xE0) == 0xC0) $n=1; # 110bbbbb |
|
240 | - elseif (($c & 0xF0) == 0xE0) $n=2; # 1110bbbb |
|
241 | - elseif (($c & 0xF8) == 0xF0) $n=3; # 11110bbb |
|
242 | - elseif (($c & 0xFC) == 0xF8) $n=4; # 111110bb |
|
243 | - elseif (($c & 0xFE) == 0xFC) $n=5; # 1111110b |
|
234 | +function yourls_seems_utf8($str) { |
|
235 | + $length = strlen($str); |
|
236 | + for ($i = 0; $i < $length; $i++) { |
|
237 | + $c = ord($str[$i]); |
|
238 | + if ($c < 0x80) $n = 0; # 0bbbbbbb |
|
239 | + elseif (($c & 0xE0) == 0xC0) $n = 1; # 110bbbbb |
|
240 | + elseif (($c & 0xF0) == 0xE0) $n = 2; # 1110bbbb |
|
241 | + elseif (($c & 0xF8) == 0xF0) $n = 3; # 11110bbb |
|
242 | + elseif (($c & 0xFC) == 0xF8) $n = 4; # 111110bb |
|
243 | + elseif (($c & 0xFE) == 0xFC) $n = 5; # 1111110b |
|
244 | 244 | else return false; # Does not match any model |
245 | - for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? |
|
245 | + for ($j = 0; $j < $n; $j++) { # n bytes matching 10bbbbbb follow ? |
|
246 | 246 | if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) |
247 | 247 | return false; |
248 | 248 | } |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | */ |
264 | 264 | function yourls_supports_pcre_u() { |
265 | 265 | static $utf8_pcre; |
266 | - if( !isset( $utf8_pcre ) ) { |
|
267 | - $utf8_pcre = (bool) @preg_match( '/^./u', 'a' ); |
|
266 | + if (!isset($utf8_pcre)) { |
|
267 | + $utf8_pcre = (bool) @preg_match('/^./u', 'a'); |
|
268 | 268 | } |
269 | 269 | return $utf8_pcre; |
270 | 270 | } |
@@ -278,26 +278,26 @@ discard block |
||
278 | 278 | * @param boolean $strip Optional. Whether to attempt to strip out invalid UTF8. Default is false. |
279 | 279 | * @return string The checked text. |
280 | 280 | */ |
281 | -function yourls_check_invalid_utf8( $string, $strip = false ) { |
|
281 | +function yourls_check_invalid_utf8($string, $strip = false) { |
|
282 | 282 | $string = (string) $string; |
283 | 283 | |
284 | - if ( 0 === strlen( $string ) ) { |
|
284 | + if (0 === strlen($string)) { |
|
285 | 285 | return ''; |
286 | 286 | } |
287 | 287 | |
288 | 288 | // We can't demand utf8 in the PCRE installation, so just return the string in those cases |
289 | - if ( ! yourls_supports_pcre_u() ) { |
|
289 | + if (!yourls_supports_pcre_u()) { |
|
290 | 290 | return $string; |
291 | 291 | } |
292 | 292 | |
293 | 293 | // preg_match fails when it encounters invalid UTF8 in $string |
294 | - if ( 1 === @preg_match( '/^./us', $string ) ) { |
|
294 | + if (1 === @preg_match('/^./us', $string)) { |
|
295 | 295 | return $string; |
296 | 296 | } |
297 | 297 | |
298 | 298 | // Attempt to strip the bad chars if requested (not recommended) |
299 | - if ( $strip && function_exists( 'iconv' ) ) { |
|
300 | - return iconv( 'utf-8', 'utf-8', $string ); |
|
299 | + if ($strip && function_exists('iconv')) { |
|
300 | + return iconv('utf-8', 'utf-8', $string); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | return ''; |
@@ -318,55 +318,55 @@ discard block |
||
318 | 318 | * @param boolean $double_encode Optional. Whether to encode existing html entities. Default is false. |
319 | 319 | * @return string The encoded text with HTML entities. |
320 | 320 | */ |
321 | -function yourls_specialchars( $string, $quote_style = ENT_NOQUOTES, $double_encode = false ) { |
|
321 | +function yourls_specialchars($string, $quote_style = ENT_NOQUOTES, $double_encode = false) { |
|
322 | 322 | $string = (string) $string; |
323 | 323 | |
324 | - if ( 0 === strlen( $string ) ) |
|
324 | + if (0 === strlen($string)) |
|
325 | 325 | return ''; |
326 | 326 | |
327 | 327 | // Don't bother if there are no specialchars - saves some processing |
328 | - if ( ! preg_match( '/[&<>"\']/', $string ) ) |
|
328 | + if (!preg_match('/[&<>"\']/', $string)) |
|
329 | 329 | return $string; |
330 | 330 | |
331 | 331 | // Account for the previous behaviour of the function when the $quote_style is not an accepted value |
332 | - if ( empty( $quote_style ) ) |
|
332 | + if (empty($quote_style)) |
|
333 | 333 | $quote_style = ENT_NOQUOTES; |
334 | - elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) |
|
334 | + elseif (!in_array($quote_style, array(0, 2, 3, 'single', 'double'), true)) |
|
335 | 335 | $quote_style = ENT_QUOTES; |
336 | 336 | |
337 | 337 | $charset = 'UTF-8'; |
338 | 338 | |
339 | 339 | $_quote_style = $quote_style; |
340 | 340 | |
341 | - if ( $quote_style === 'double' ) { |
|
341 | + if ($quote_style === 'double') { |
|
342 | 342 | $quote_style = ENT_COMPAT; |
343 | 343 | $_quote_style = ENT_COMPAT; |
344 | - } elseif ( $quote_style === 'single' ) { |
|
344 | + } elseif ($quote_style === 'single') { |
|
345 | 345 | $quote_style = ENT_NOQUOTES; |
346 | 346 | } |
347 | 347 | |
348 | 348 | // Handle double encoding ourselves |
349 | - if ( $double_encode ) { |
|
350 | - $string = @htmlspecialchars( $string, $quote_style, $charset ); |
|
349 | + if ($double_encode) { |
|
350 | + $string = @htmlspecialchars($string, $quote_style, $charset); |
|
351 | 351 | } else { |
352 | 352 | // Decode & into & |
353 | - $string = yourls_specialchars_decode( $string, $_quote_style ); |
|
353 | + $string = yourls_specialchars_decode($string, $_quote_style); |
|
354 | 354 | |
355 | 355 | // Guarantee every &entity; is valid or re-encode the & |
356 | - $string = yourls_kses_normalize_entities( $string ); |
|
356 | + $string = yourls_kses_normalize_entities($string); |
|
357 | 357 | |
358 | 358 | // Now re-encode everything except &entity; |
359 | - $string = preg_split( '/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE ); |
|
359 | + $string = preg_split('/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
360 | 360 | |
361 | - for ( $i = 0; $i < count( $string ); $i += 2 ) |
|
362 | - $string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset ); |
|
361 | + for ($i = 0; $i < count($string); $i += 2) |
|
362 | + $string[$i] = @htmlspecialchars($string[$i], $quote_style, $charset); |
|
363 | 363 | |
364 | - $string = implode( '', $string ); |
|
364 | + $string = implode('', $string); |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | // Backwards compatibility |
368 | - if ( 'single' === $_quote_style ) |
|
369 | - $string = str_replace( "'", ''', $string ); |
|
368 | + if ('single' === $_quote_style) |
|
369 | + $string = str_replace("'", ''', $string); |
|
370 | 370 | |
371 | 371 | return $string; |
372 | 372 | } |
@@ -385,52 +385,52 @@ discard block |
||
385 | 385 | * @param mixed $quote_style Optional. Converts double quotes if set to ENT_COMPAT, both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES. Also compatible with old _wp_specialchars() values; converting single quotes if set to 'single', double if set to 'double' or both if otherwise set. Default is ENT_NOQUOTES. |
386 | 386 | * @return string The decoded text without HTML entities. |
387 | 387 | */ |
388 | -function yourls_specialchars_decode( $string, $quote_style = ENT_NOQUOTES ) { |
|
388 | +function yourls_specialchars_decode($string, $quote_style = ENT_NOQUOTES) { |
|
389 | 389 | $string = (string) $string; |
390 | 390 | |
391 | - if ( 0 === strlen( $string ) ) { |
|
391 | + if (0 === strlen($string)) { |
|
392 | 392 | return ''; |
393 | 393 | } |
394 | 394 | |
395 | 395 | // Don't bother if there are no entities - saves a lot of processing |
396 | - if ( strpos( $string, '&' ) === false ) { |
|
396 | + if (strpos($string, '&') === false) { |
|
397 | 397 | return $string; |
398 | 398 | } |
399 | 399 | |
400 | 400 | // Match the previous behaviour of _wp_specialchars() when the $quote_style is not an accepted value |
401 | - if ( empty( $quote_style ) ) { |
|
401 | + if (empty($quote_style)) { |
|
402 | 402 | $quote_style = ENT_NOQUOTES; |
403 | - } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) { |
|
403 | + } elseif (!in_array($quote_style, array(0, 2, 3, 'single', 'double'), true)) { |
|
404 | 404 | $quote_style = ENT_QUOTES; |
405 | 405 | } |
406 | 406 | |
407 | 407 | // More complete than get_html_translation_table( HTML_SPECIALCHARS ) |
408 | - $single = array( ''' => '\'', ''' => '\'' ); |
|
409 | - $single_preg = array( '/�*39;/' => ''', '/�*27;/i' => ''' ); |
|
410 | - $double = array( '"' => '"', '"' => '"', '"' => '"' ); |
|
411 | - $double_preg = array( '/�*34;/' => '"', '/�*22;/i' => '"' ); |
|
412 | - $others = array( '<' => '<', '<' => '<', '>' => '>', '>' => '>', '&' => '&', '&' => '&', '&' => '&' ); |
|
413 | - $others_preg = array( '/�*60;/' => '<', '/�*62;/' => '>', '/�*38;/' => '&', '/�*26;/i' => '&' ); |
|
414 | - |
|
415 | - if ( $quote_style === ENT_QUOTES ) { |
|
416 | - $translation = array_merge( $single, $double, $others ); |
|
417 | - $translation_preg = array_merge( $single_preg, $double_preg, $others_preg ); |
|
418 | - } elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) { |
|
419 | - $translation = array_merge( $double, $others ); |
|
420 | - $translation_preg = array_merge( $double_preg, $others_preg ); |
|
421 | - } elseif ( $quote_style === 'single' ) { |
|
422 | - $translation = array_merge( $single, $others ); |
|
423 | - $translation_preg = array_merge( $single_preg, $others_preg ); |
|
424 | - } elseif ( $quote_style === ENT_NOQUOTES ) { |
|
408 | + $single = array(''' => '\'', ''' => '\''); |
|
409 | + $single_preg = array('/�*39;/' => ''', '/�*27;/i' => '''); |
|
410 | + $double = array('"' => '"', '"' => '"', '"' => '"'); |
|
411 | + $double_preg = array('/�*34;/' => '"', '/�*22;/i' => '"'); |
|
412 | + $others = array('<' => '<', '<' => '<', '>' => '>', '>' => '>', '&' => '&', '&' => '&', '&' => '&'); |
|
413 | + $others_preg = array('/�*60;/' => '<', '/�*62;/' => '>', '/�*38;/' => '&', '/�*26;/i' => '&'); |
|
414 | + |
|
415 | + if ($quote_style === ENT_QUOTES) { |
|
416 | + $translation = array_merge($single, $double, $others); |
|
417 | + $translation_preg = array_merge($single_preg, $double_preg, $others_preg); |
|
418 | + } elseif ($quote_style === ENT_COMPAT || $quote_style === 'double') { |
|
419 | + $translation = array_merge($double, $others); |
|
420 | + $translation_preg = array_merge($double_preg, $others_preg); |
|
421 | + } elseif ($quote_style === 'single') { |
|
422 | + $translation = array_merge($single, $others); |
|
423 | + $translation_preg = array_merge($single_preg, $others_preg); |
|
424 | + } elseif ($quote_style === ENT_NOQUOTES) { |
|
425 | 425 | $translation = $others; |
426 | 426 | $translation_preg = $others_preg; |
427 | 427 | } |
428 | 428 | |
429 | 429 | // Remove zero padding on numeric entities |
430 | - $string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string ); |
|
430 | + $string = preg_replace(array_keys($translation_preg), array_values($translation_preg), $string); |
|
431 | 431 | |
432 | 432 | // Replace characters according to translation table |
433 | - return strtr( $string, $translation ); |
|
433 | + return strtr($string, $translation); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | |
@@ -442,10 +442,10 @@ discard block |
||
442 | 442 | * @param string $text |
443 | 443 | * @return string |
444 | 444 | */ |
445 | -function yourls_esc_html( $text ) { |
|
446 | - $safe_text = yourls_check_invalid_utf8( $text ); |
|
447 | - $safe_text = yourls_specialchars( $safe_text, ENT_QUOTES ); |
|
448 | - return yourls_apply_filter( 'esc_html', $safe_text, $text ); |
|
445 | +function yourls_esc_html($text) { |
|
446 | + $safe_text = yourls_check_invalid_utf8($text); |
|
447 | + $safe_text = yourls_specialchars($safe_text, ENT_QUOTES); |
|
448 | + return yourls_apply_filter('esc_html', $safe_text, $text); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | /** |
@@ -456,10 +456,10 @@ discard block |
||
456 | 456 | * @param string $text |
457 | 457 | * @return string |
458 | 458 | */ |
459 | -function yourls_esc_attr( $text ) { |
|
460 | - $safe_text = yourls_check_invalid_utf8( $text ); |
|
461 | - $safe_text = yourls_specialchars( $safe_text, ENT_QUOTES ); |
|
462 | - return yourls_apply_filter( 'esc_attr', $safe_text, $text ); |
|
459 | +function yourls_esc_attr($text) { |
|
460 | + $safe_text = yourls_check_invalid_utf8($text); |
|
461 | + $safe_text = yourls_specialchars($safe_text, ENT_QUOTES); |
|
462 | + return yourls_apply_filter('esc_attr', $safe_text, $text); |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | /** |
@@ -478,58 +478,58 @@ discard block |
||
478 | 478 | * @param array $protocols Optional. Array of allowed protocols, defaults to global $yourls_allowedprotocols |
479 | 479 | * @return string The cleaned $url |
480 | 480 | */ |
481 | -function yourls_esc_url( $url, $context = 'display', $protocols = array() ) { |
|
481 | +function yourls_esc_url($url, $context = 'display', $protocols = array()) { |
|
482 | 482 | // trim first -- see #1931 |
483 | - $url = trim( $url ); |
|
483 | + $url = trim($url); |
|
484 | 484 | |
485 | 485 | // make sure there's only one 'http://' at the beginning (prevents pasting a URL right after the default 'http://') |
486 | 486 | $url = str_replace( |
487 | - array( 'http://http://', 'http://https://' ), |
|
488 | - array( 'http://', 'https://' ), |
|
487 | + array('http://http://', 'http://https://'), |
|
488 | + array('http://', 'https://'), |
|
489 | 489 | $url |
490 | 490 | ); |
491 | 491 | |
492 | - if ( '' == $url ) |
|
492 | + if ('' == $url) |
|
493 | 493 | return $url; |
494 | 494 | |
495 | 495 | $original_url = $url; |
496 | 496 | |
497 | 497 | // force scheme and domain to lowercase - see issues 591 and 1630 |
498 | - $url = yourls_normalize_uri( $url ); |
|
498 | + $url = yourls_normalize_uri($url); |
|
499 | 499 | |
500 | - $url = preg_replace( '|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff]|i', '', $url ); |
|
500 | + $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff]|i', '', $url); |
|
501 | 501 | // Previous regexp in YOURLS was '|[^a-z0-9-~+_.?\[\]\^#=!&;,/:%@$\|*`\'<>"()\\x80-\\xff\{\}]|i' |
502 | 502 | // TODO: check if that was it too destructive |
503 | 503 | |
504 | 504 | // If $context is 'safe', an extra step is taken to make sure no CRLF injection is possible. |
505 | 505 | // To be used when $url can be forged by evil user (eg it's from a $_SERVER variable, a query string, etc..) |
506 | - if ( 'safe' == $context ) { |
|
507 | - $strip = array( '%0d', '%0a', '%0D', '%0A' ); |
|
508 | - $url = yourls_deep_replace( $strip, $url ); |
|
506 | + if ('safe' == $context) { |
|
507 | + $strip = array('%0d', '%0a', '%0D', '%0A'); |
|
508 | + $url = yourls_deep_replace($strip, $url); |
|
509 | 509 | } |
510 | 510 | |
511 | 511 | // Replace ampersands and single quotes only when displaying. |
512 | - if ( 'display' == $context ) { |
|
513 | - $url = yourls_kses_normalize_entities( $url ); |
|
514 | - $url = str_replace( '&', '&', $url ); |
|
515 | - $url = str_replace( "'", ''', $url ); |
|
512 | + if ('display' == $context) { |
|
513 | + $url = yourls_kses_normalize_entities($url); |
|
514 | + $url = str_replace('&', '&', $url); |
|
515 | + $url = str_replace("'", ''', $url); |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | // If there's a protocol, make sure it's OK |
519 | - if( yourls_get_protocol($url) !== '' ) { |
|
520 | - if ( ! is_array( $protocols ) or ! $protocols ) { |
|
519 | + if (yourls_get_protocol($url) !== '') { |
|
520 | + if (!is_array($protocols) or !$protocols) { |
|
521 | 521 | global $yourls_allowedprotocols; |
522 | - $protocols = yourls_apply_filter( 'esc_url_protocols', $yourls_allowedprotocols ); |
|
522 | + $protocols = yourls_apply_filter('esc_url_protocols', $yourls_allowedprotocols); |
|
523 | 523 | // Note: $yourls_allowedprotocols is also globally filterable in functions-kses.php/yourls_kses_init() |
524 | 524 | } |
525 | 525 | |
526 | - if ( !yourls_is_allowed_protocol( $url, $protocols ) ) |
|
526 | + if (!yourls_is_allowed_protocol($url, $protocols)) |
|
527 | 527 | return ''; |
528 | 528 | |
529 | 529 | // I didn't use KSES function kses_bad_protocol() because it doesn't work the way I liked (returns //blah from illegal://blah) |
530 | 530 | } |
531 | 531 | |
532 | - return yourls_apply_filter( 'esc_url', $url, $original_url, $context ); |
|
532 | + return yourls_apply_filter('esc_url', $url, $original_url, $context); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | |
@@ -565,8 +565,8 @@ discard block |
||
565 | 565 | * @param string $url URL |
566 | 566 | * @return string URL with lowercase scheme and protocol |
567 | 567 | */ |
568 | -function yourls_normalize_uri( $url ) { |
|
569 | - $scheme = yourls_get_protocol( $url ); |
|
568 | +function yourls_normalize_uri($url) { |
|
569 | + $scheme = yourls_get_protocol($url); |
|
570 | 570 | |
571 | 571 | if ('' == $scheme) { |
572 | 572 | // Scheme not found, malformed URL? Something else? Not sure. |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | * In this case, we only lowercase the scheme, because depending on it, things after should or should not be lowercased |
580 | 580 | */ |
581 | 581 | if (substr($scheme, -2, 2) != '//') { |
582 | - $url = str_replace( $scheme, strtolower( $scheme ), $url ); |
|
582 | + $url = str_replace($scheme, strtolower($scheme), $url); |
|
583 | 583 | return $url; |
584 | 584 | } |
585 | 585 | |
@@ -591,14 +591,14 @@ discard block |
||
591 | 591 | |
592 | 592 | // Most likely malformed stuff, could not parse : we'll just lowercase the scheme and leave the rest untouched |
593 | 593 | if (false == $parts) { |
594 | - $url = str_replace( $scheme, strtolower( $scheme ), $url ); |
|
594 | + $url = str_replace($scheme, strtolower($scheme), $url); |
|
595 | 595 | return $url; |
596 | 596 | } |
597 | 597 | |
598 | 598 | // URL seems parsable, let's do the best we can |
599 | 599 | $lower = array(); |
600 | - $lower['scheme'] = strtolower( $parts['scheme'] ); |
|
601 | - if( isset( $parts['host'] ) ) { |
|
600 | + $lower['scheme'] = strtolower($parts['scheme']); |
|
601 | + if (isset($parts['host'])) { |
|
602 | 602 | // Convert domain to lowercase, with mb_ to preserve UTF8 |
603 | 603 | $lower['host'] = mb_strtolower($parts['host']); |
604 | 604 | /** |
@@ -627,13 +627,13 @@ discard block |
||
627 | 627 | * @param string $text The text to be escaped. |
628 | 628 | * @return string Escaped text. |
629 | 629 | */ |
630 | -function yourls_esc_js( $text ) { |
|
631 | - $safe_text = yourls_check_invalid_utf8( $text ); |
|
632 | - $safe_text = yourls_specialchars( $safe_text, ENT_COMPAT ); |
|
633 | - $safe_text = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes( $safe_text ) ); |
|
634 | - $safe_text = str_replace( "\r", '', $safe_text ); |
|
635 | - $safe_text = str_replace( "\n", '\\n', addslashes( $safe_text ) ); |
|
636 | - return yourls_apply_filter( 'esc_js', $safe_text, $text ); |
|
630 | +function yourls_esc_js($text) { |
|
631 | + $safe_text = yourls_check_invalid_utf8($text); |
|
632 | + $safe_text = yourls_specialchars($safe_text, ENT_COMPAT); |
|
633 | + $safe_text = preg_replace('/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes($safe_text)); |
|
634 | + $safe_text = str_replace("\r", '', $safe_text); |
|
635 | + $safe_text = str_replace("\n", '\\n', addslashes($safe_text)); |
|
636 | + return yourls_apply_filter('esc_js', $safe_text, $text); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | /** |
@@ -644,9 +644,9 @@ discard block |
||
644 | 644 | * @param string $text |
645 | 645 | * @return string |
646 | 646 | */ |
647 | -function yourls_esc_textarea( $text ) { |
|
648 | - $safe_text = htmlspecialchars( $text, ENT_QUOTES ); |
|
649 | - return yourls_apply_filter( 'esc_textarea', $safe_text, $text ); |
|
647 | +function yourls_esc_textarea($text) { |
|
648 | + $safe_text = htmlspecialchars($text, ENT_QUOTES); |
|
649 | + return yourls_apply_filter('esc_textarea', $safe_text, $text); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | |
@@ -657,19 +657,19 @@ discard block |
||
657 | 657 | * @param $url |
658 | 658 | * @return string |
659 | 659 | */ |
660 | -function yourls_encodeURI( $url ) { |
|
660 | +function yourls_encodeURI($url) { |
|
661 | 661 | // Decode URL all the way |
662 | - $result = yourls_rawurldecode_while_encoded( $url ); |
|
662 | + $result = yourls_rawurldecode_while_encoded($url); |
|
663 | 663 | // Encode once |
664 | - $result = strtr( rawurlencode( $result ), array ( |
|
664 | + $result = strtr(rawurlencode($result), array( |
|
665 | 665 | '%3B' => ';', '%2C' => ',', '%2F' => '/', '%3F' => '?', '%3A' => ':', '%40' => '@', |
666 | 666 | '%26' => '&', '%3D' => '=', '%2B' => '+', '%24' => '$', '%21' => '!', '%2A' => '*', |
667 | 667 | '%27' => '\'', '%28' => '(', '%29' => ')', '%23' => '#', |
668 | - ) ); |
|
668 | + )); |
|
669 | 669 | // @TODO: |
670 | 670 | // Known limit: this will most likely break IDN URLs such as http://www.académie-française.fr/ |
671 | 671 | // To fully support IDN URLs, advocate use of a plugin. |
672 | - return yourls_apply_filter( 'encodeURI', $result, $url ); |
|
672 | + return yourls_apply_filter('encodeURI', $result, $url); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | /** |
@@ -695,8 +695,8 @@ discard block |
||
695 | 695 | * @param string $string |
696 | 696 | * @return bool |
697 | 697 | */ |
698 | -function yourls_is_rawurlencoded( $string ) { |
|
699 | - return rawurldecode( $string ) != $string; |
|
698 | +function yourls_is_rawurlencoded($string) { |
|
699 | + return rawurldecode($string) != $string; |
|
700 | 700 | } |
701 | 701 | |
702 | 702 | /** |
@@ -709,10 +709,10 @@ discard block |
||
709 | 709 | * @param string $string |
710 | 710 | * @return string |
711 | 711 | */ |
712 | -function yourls_rawurldecode_while_encoded( $string ) { |
|
713 | - $string = rawurldecode( $string ); |
|
714 | - if( yourls_is_rawurlencoded( $string ) ) { |
|
715 | - $string = yourls_rawurldecode_while_encoded( $string ); |
|
712 | +function yourls_rawurldecode_while_encoded($string) { |
|
713 | + $string = rawurldecode($string); |
|
714 | + if (yourls_is_rawurlencoded($string)) { |
|
715 | + $string = yourls_rawurldecode_while_encoded($string); |
|
716 | 716 | } |
717 | 717 | return $string; |
718 | 718 | } |
@@ -726,9 +726,9 @@ discard block |
||
726 | 726 | * @param string $code Javascript code |
727 | 727 | * @return string Bookmarklet link |
728 | 728 | */ |
729 | -function yourls_make_bookmarklet( $code ) { |
|
729 | +function yourls_make_bookmarklet($code) { |
|
730 | 730 | $book = new \Ozh\Bookmarkletgen\Bookmarkletgen; |
731 | - return $book->crunch( $code ); |
|
731 | + return $book->crunch($code); |
|
732 | 732 | } |
733 | 733 | |
734 | 734 | /** |
@@ -738,11 +738,11 @@ discard block |
||
738 | 738 | * @param string|int $timestamp a timestamp |
739 | 739 | * @return int a timestamp, plus or minus offset if defined |
740 | 740 | */ |
741 | -function yourls_get_timestamp( $timestamp ) { |
|
741 | +function yourls_get_timestamp($timestamp) { |
|
742 | 742 | $offset = yourls_get_time_offset(); |
743 | 743 | $timestamp_offset = $timestamp + ($offset * 3600); |
744 | 744 | |
745 | - return yourls_apply_filter( 'get_timestamp', $timestamp_offset, $timestamp, $offset ); |
|
745 | + return yourls_apply_filter('get_timestamp', $timestamp_offset, $timestamp, $offset); |
|
746 | 746 | } |
747 | 747 | |
748 | 748 | /** |
@@ -752,8 +752,8 @@ discard block |
||
752 | 752 | * @return int Time offset |
753 | 753 | */ |
754 | 754 | function yourls_get_time_offset() { |
755 | - $offset = defined('YOURLS_HOURS_OFFSET') ? (int)YOURLS_HOURS_OFFSET : 0; |
|
756 | - return yourls_apply_filter( 'get_time_offset', $offset ); |
|
755 | + $offset = defined('YOURLS_HOURS_OFFSET') ? (int) YOURLS_HOURS_OFFSET : 0; |
|
756 | + return yourls_apply_filter('get_time_offset', $offset); |
|
757 | 757 | } |
758 | 758 | |
759 | 759 | /** |
@@ -763,8 +763,8 @@ discard block |
||
763 | 763 | * @param string $format Date format string |
764 | 764 | * @return string Date format string |
765 | 765 | */ |
766 | -function yourls_get_datetime_format( $format ) { |
|
767 | - return yourls_apply_filter( 'get_datetime_format', (string)$format ); |
|
766 | +function yourls_get_datetime_format($format) { |
|
767 | + return yourls_apply_filter('get_datetime_format', (string) $format); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | /** |
@@ -774,8 +774,8 @@ discard block |
||
774 | 774 | * @param string $format Date format string |
775 | 775 | * @return string Date format string |
776 | 776 | */ |
777 | -function yourls_get_date_format( $format ) { |
|
778 | - return yourls_apply_filter( 'get_date_format', (string)$format ); |
|
777 | +function yourls_get_date_format($format) { |
|
778 | + return yourls_apply_filter('get_date_format', (string) $format); |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | /** |
@@ -785,7 +785,7 @@ discard block |
||
785 | 785 | * @param string $format Date format string |
786 | 786 | * @return string Date format string |
787 | 787 | */ |
788 | -function yourls_get_time_format( $format ) { |
|
789 | - return yourls_apply_filter( 'get_time_format', (string)$format ); |
|
788 | +function yourls_get_time_format($format) { |
|
789 | + return yourls_apply_filter('get_time_format', (string) $format); |
|
790 | 790 | } |
791 | 791 |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | public function connect_to_DB() { |
141 | 141 | try { |
142 | 142 | $this->connect(); |
143 | - } catch ( \Exception $e ) { |
|
143 | + } catch (\Exception $e) { |
|
144 | 144 | $this->dead_or_error($e); |
145 | 145 | } |
146 | 146 | } |
@@ -156,15 +156,15 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public function dead_or_error(\Exception $exception) { |
158 | 158 | // Use any /user/db_error.php file |
159 | - if( file_exists( YOURLS_USERDIR . '/db_error.php' ) ) { |
|
160 | - include_once( YOURLS_USERDIR . '/db_error.php' ); |
|
159 | + if (file_exists(YOURLS_USERDIR.'/db_error.php')) { |
|
160 | + include_once(YOURLS_USERDIR.'/db_error.php'); |
|
161 | 161 | die(); |
162 | 162 | } |
163 | 163 | |
164 | - $message = yourls__( 'Incorrect DB config, or could not connect to DB' ); |
|
165 | - $message .= '<br/>' . get_class($exception) .': ' . $exception->getMessage(); |
|
164 | + $message = yourls__('Incorrect DB config, or could not connect to DB'); |
|
165 | + $message .= '<br/>'.get_class($exception).': '.$exception->getMessage(); |
|
166 | 166 | |
167 | - yourls_die( yourls__( $message ), yourls__( 'Fatal error' ), 503 ); |
|
167 | + yourls_die(yourls__($message), yourls__('Fatal error'), 503); |
|
168 | 168 | die(); |
169 | 169 | } |
170 | 170 | |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | * @return array |
304 | 304 | */ |
305 | 305 | public function get_plugin_pages() { |
306 | - return is_array( $this->plugin_pages ) ? $this->plugin_pages : []; |
|
306 | + return is_array($this->plugin_pages) ? $this->plugin_pages : []; |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
@@ -318,8 +318,8 @@ discard block |
||
318 | 318 | * @param string $title |
319 | 319 | * @param callable $function |
320 | 320 | */ |
321 | - public function add_plugin_page( $slug, $title, $function ) { |
|
322 | - $this->plugin_pages[ $slug ] = [ |
|
321 | + public function add_plugin_page($slug, $title, $function) { |
|
322 | + $this->plugin_pages[$slug] = [ |
|
323 | 323 | 'slug' => $slug, |
324 | 324 | 'title' => $title, |
325 | 325 | 'function' => $function, |
@@ -329,8 +329,8 @@ discard block |
||
329 | 329 | /** |
330 | 330 | * @param string $slug |
331 | 331 | */ |
332 | - public function remove_plugin_page( $slug ) { |
|
333 | - unset( $this->plugin_pages[ $slug ] ); |
|
332 | + public function remove_plugin_page($slug) { |
|
333 | + unset($this->plugin_pages[$slug]); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | * @return int |
342 | 342 | */ |
343 | 343 | public function get_num_queries() { |
344 | - return count( (array) $this->get_queries() ); |
|
344 | + return count((array) $this->get_queries()); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | |
382 | 382 | if ($this->get_emulate_state()) { |
383 | 383 | // keep queries if $query['function'] != 'prepare' |
384 | - $queries = array_filter($queries, function($query) {return $query['function'] !== 'prepare';}); |
|
384 | + $queries = array_filter($queries, function($query) {return $query['function'] !== 'prepare'; }); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | return $queries; |
@@ -445,39 +445,39 @@ discard block |
||
445 | 445 | // @codeCoverageIgnoreStart |
446 | 446 | |
447 | 447 | public function escape($string) { |
448 | - yourls_deprecated_function( '$ydb->'.__FUNCTION__, '1.7.3', 'PDO' ); |
|
448 | + yourls_deprecated_function('$ydb->'.__FUNCTION__, '1.7.3', 'PDO'); |
|
449 | 449 | // This will escape using PDO->quote(), but then remove the enclosing quotes |
450 | 450 | return substr($this->quote($string), 1, -1); |
451 | 451 | } |
452 | 452 | |
453 | 453 | public function get_col($query) { |
454 | - yourls_deprecated_function( '$ydb->'.__FUNCTION__, '1.7.3', 'PDO' ); |
|
454 | + yourls_deprecated_function('$ydb->'.__FUNCTION__, '1.7.3', 'PDO'); |
|
455 | 455 | yourls_debug_log('LEGACY SQL: '.$query); |
456 | 456 | return $this->fetchCol($query); |
457 | 457 | } |
458 | 458 | |
459 | 459 | public function get_results($query) { |
460 | - yourls_deprecated_function( '$ydb->'.__FUNCTION__, '1.7.3', 'PDO' ); |
|
460 | + yourls_deprecated_function('$ydb->'.__FUNCTION__, '1.7.3', 'PDO'); |
|
461 | 461 | yourls_debug_log('LEGACY SQL: '.$query); |
462 | 462 | $stm = parent::query($query); |
463 | 463 | return($stm->fetchAll(PDO::FETCH_OBJ)); |
464 | 464 | } |
465 | 465 | |
466 | 466 | public function get_row($query) { |
467 | - yourls_deprecated_function( '$ydb->'.__FUNCTION__, '1.7.3', 'PDO' ); |
|
467 | + yourls_deprecated_function('$ydb->'.__FUNCTION__, '1.7.3', 'PDO'); |
|
468 | 468 | yourls_debug_log('LEGACY SQL: '.$query); |
469 | 469 | $row = $this->fetchObjects($query); |
470 | 470 | return isset($row[0]) ? $row[0] : null; |
471 | 471 | } |
472 | 472 | |
473 | 473 | public function get_var($query) { |
474 | - yourls_deprecated_function( '$ydb->'.__FUNCTION__, '1.7.3', 'PDO' ); |
|
474 | + yourls_deprecated_function('$ydb->'.__FUNCTION__, '1.7.3', 'PDO'); |
|
475 | 475 | yourls_debug_log('LEGACY SQL: '.$query); |
476 | 476 | return $this->fetchValue($query); |
477 | 477 | } |
478 | 478 | |
479 | 479 | public function query($query) { |
480 | - yourls_deprecated_function( '$ydb->'.__FUNCTION__, '1.7.3', 'PDO' ); |
|
480 | + yourls_deprecated_function('$ydb->'.__FUNCTION__, '1.7.3', 'PDO'); |
|
481 | 481 | yourls_debug_log('LEGACY SQL: '.$query); |
482 | 482 | return $this->fetchAffected($query); |
483 | 483 | } |
@@ -172,7 +172,7 @@ |
||
172 | 172 | |
173 | 173 | // Cache option value to save a DB query if needed later |
174 | 174 | $this->ydb->set_option($name, $newvalue); |
175 | - yourls_do_action( 'update_option', $name, $oldvalue, $newvalue ); |
|
175 | + yourls_do_action( 'update_option', $name, $oldvalue, $newvalue ); |
|
176 | 176 | return true; |
177 | 177 | } |
178 | 178 |
@@ -48,18 +48,18 @@ discard block |
||
48 | 48 | try { |
49 | 49 | $options = (array) $this->ydb->fetchPairs($sql); |
50 | 50 | |
51 | - } catch ( PDOException $e ) { |
|
51 | + } catch (PDOException $e) { |
|
52 | 52 | |
53 | 53 | // We could not fetch value from the table. Let's check if the option table exists |
54 | 54 | try { |
55 | 55 | $check = $this->ydb->fetchAffected(sprintf("SHOW TABLES LIKE '%s'", $table)); |
56 | 56 | // Table doesn't exist |
57 | - if ($check ==0) { |
|
57 | + if ($check == 0) { |
|
58 | 58 | return false; |
59 | 59 | } |
60 | 60 | |
61 | 61 | // Error at this point means the database isn't readable |
62 | - } catch ( PDOException $e ) { |
|
62 | + } catch (PDOException $e) { |
|
63 | 63 | $this->ydb->dead_or_error($e); |
64 | 64 | } |
65 | 65 | |
@@ -90,13 +90,13 @@ discard block |
||
90 | 90 | * @return mixed Value set for the option |
91 | 91 | */ |
92 | 92 | public function get($name, $default) { |
93 | - $name = trim((string)$name); |
|
93 | + $name = trim((string) $name); |
|
94 | 94 | if (empty($name)) { |
95 | 95 | return $default; |
96 | 96 | } |
97 | 97 | |
98 | 98 | // Check if option value is cached already |
99 | - if($this->ydb->has_option($name)) { |
|
99 | + if ($this->ydb->has_option($name)) { |
|
100 | 100 | return $this->ydb->get_option($name); |
101 | 101 | } |
102 | 102 | |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | // Use fechOne() to get array('option_value'=>$value), or false if not found. |
109 | 109 | // This way, we can effectively store false as an option value, and not confuse with false as the default return value |
110 | 110 | $value = $this->ydb->fetchOne($sql, $bind); |
111 | - if($value !== false) { |
|
112 | - $value = yourls_maybe_unserialize( $value['option_value'] ); |
|
111 | + if ($value !== false) { |
|
112 | + $value = yourls_maybe_unserialize($value['option_value']); |
|
113 | 113 | // Cache option value to save a DB query if needed later |
114 | 114 | $this->ydb->set_option($name, $value); |
115 | 115 | } else { |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @return bool False if value was not updated, true otherwise. |
138 | 138 | */ |
139 | 139 | public function update($name, $newvalue) { |
140 | - $name = trim((string)$name); |
|
140 | + $name = trim((string) $name); |
|
141 | 141 | if (empty($name)) { |
142 | 142 | return false; |
143 | 143 | } |
@@ -165,14 +165,14 @@ discard block |
||
165 | 165 | $bind = array('name' => $name, 'value' => $_newvalue); |
166 | 166 | $do = $this->ydb->fetchAffected($sql, $bind); |
167 | 167 | |
168 | - if($do !== 1) { |
|
168 | + if ($do !== 1) { |
|
169 | 169 | // Something went wrong :( |
170 | 170 | return false; |
171 | 171 | } |
172 | 172 | |
173 | 173 | // Cache option value to save a DB query if needed later |
174 | 174 | $this->ydb->set_option($name, $newvalue); |
175 | - yourls_do_action( 'update_option', $name, $oldvalue, $newvalue ); |
|
175 | + yourls_do_action('update_option', $name, $oldvalue, $newvalue); |
|
176 | 176 | return true; |
177 | 177 | } |
178 | 178 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | * @return bool False if option was not added (eg already exists), true otherwise. |
187 | 187 | */ |
188 | 188 | public function add($name, $value) { |
189 | - $name = trim((string)$name); |
|
189 | + $name = trim((string) $name); |
|
190 | 190 | if (empty($name)) { |
191 | 191 | return false; |
192 | 192 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | $bind = array('name' => $name, 'value' => $_value); |
211 | 211 | $do = $this->ydb->fetchAffected($sql, $bind); |
212 | 212 | |
213 | - if($do !== 1) { |
|
213 | + if ($do !== 1) { |
|
214 | 214 | // Something went wrong :( |
215 | 215 | return false; |
216 | 216 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * @return bool False if option was not deleted (eg not found), true otherwise. |
232 | 232 | */ |
233 | 233 | public function delete($name) { |
234 | - $name = trim((string)$name); |
|
234 | + $name = trim((string) $name); |
|
235 | 235 | if (empty($name)) { |
236 | 236 | return false; |
237 | 237 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | $bind = array('name' => $name); |
242 | 242 | $do = $this->ydb->fetchAffected($sql, $bind); |
243 | 243 | |
244 | - if($do !== 1) { |
|
244 | + if ($do !== 1) { |
|
245 | 245 | // Something went wrong :( |
246 | 246 | return false; |
247 | 247 | } |
@@ -161,7 +161,7 @@ |
||
161 | 161 | |
162 | 162 | $_newvalue = yourls_maybe_serialize($newvalue); |
163 | 163 | $table = YOURLS_DB_TABLE_OPTIONS; |
164 | - $sql = "UPDATE $table SET option_value = :value WHERE option_name = :name"; |
|
164 | + $sql = "update $table SET option_value = :value WHERE option_name = :name"; |
|
165 | 165 | $bind = array('name' => $name, 'value' => $_newvalue); |
166 | 166 | $do = $this->ydb->fetchAffected($sql, $bind); |
167 | 167 |