@@ -1,6 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (!is_callable('random_int')) { |
|
| 3 | +if (!is_callable('random_int')) |
|
| 4 | +{ |
|
| 4 | 5 | /** |
| 5 | 6 | * Random_* Compatibility Library |
| 6 | 7 | * for using the new PHP 7 random_* API in PHP 5 projects |
@@ -50,19 +51,25 @@ discard block |
||
| 50 | 51 | * through. |
| 51 | 52 | */ |
| 52 | 53 | |
| 53 | - try { |
|
| 54 | + try |
|
| 55 | + { |
|
| 54 | 56 | /** @var int $min */ |
| 55 | 57 | $min = RandomCompat_intval($min); |
| 56 | - } catch (TypeError $ex) { |
|
| 58 | + } |
|
| 59 | + catch (TypeError $ex) |
|
| 60 | + { |
|
| 57 | 61 | throw new TypeError( |
| 58 | 62 | 'random_int(): $min must be an integer' |
| 59 | 63 | ); |
| 60 | 64 | } |
| 61 | 65 | |
| 62 | - try { |
|
| 66 | + try |
|
| 67 | + { |
|
| 63 | 68 | /** @var int $max */ |
| 64 | 69 | $max = RandomCompat_intval($max); |
| 65 | - } catch (TypeError $ex) { |
|
| 70 | + } |
|
| 71 | + catch (TypeError $ex) |
|
| 72 | + { |
|
| 66 | 73 | throw new TypeError( |
| 67 | 74 | 'random_int(): $max must be an integer' |
| 68 | 75 | ); |
@@ -73,13 +80,15 @@ discard block |
||
| 73 | 80 | * let's validate the logic then we can move forward with generating random |
| 74 | 81 | * integers along a given range. |
| 75 | 82 | */ |
| 76 | - if ($min > $max) { |
|
| 83 | + if ($min > $max) |
|
| 84 | + { |
|
| 77 | 85 | throw new Error( |
| 78 | 86 | 'Minimum value must be less than or equal to the maximum value' |
| 79 | 87 | ); |
| 80 | 88 | } |
| 81 | 89 | |
| 82 | - if ($max === $min) { |
|
| 90 | + if ($max === $min) |
|
| 91 | + { |
|
| 83 | 92 | return (int) $min; |
| 84 | 93 | } |
| 85 | 94 | |
@@ -110,7 +119,8 @@ discard block |
||
| 110 | 119 | /** |
| 111 | 120 | * Test for integer overflow: |
| 112 | 121 | */ |
| 113 | - if (!is_int($range)) { |
|
| 122 | + if (!is_int($range)) |
|
| 123 | + { |
|
| 114 | 124 | |
| 115 | 125 | /** |
| 116 | 126 | * Still safely calculate wider ranges. |
@@ -127,14 +137,18 @@ discard block |
||
| 127 | 137 | /** @var int $mask */ |
| 128 | 138 | $mask = ~0; |
| 129 | 139 | |
| 130 | - } else { |
|
| 140 | + } |
|
| 141 | + else |
|
| 142 | + { |
|
| 131 | 143 | |
| 132 | 144 | /** |
| 133 | 145 | * $bits is effectively ceil(log($range, 2)) without dealing with |
| 134 | 146 | * type juggling |
| 135 | 147 | */ |
| 136 | - while ($range > 0) { |
|
| 137 | - if ($bits % 8 === 0) { |
|
| 148 | + while ($range > 0) |
|
| 149 | + { |
|
| 150 | + if ($bits % 8 === 0) |
|
| 151 | + { |
|
| 138 | 152 | ++$bytes; |
| 139 | 153 | } |
| 140 | 154 | ++$bits; |
@@ -157,7 +171,8 @@ discard block |
||
| 157 | 171 | * The rejection probability is at most 0.5, so this corresponds |
| 158 | 172 | * to a failure probability of 2^-128 for a working RNG |
| 159 | 173 | */ |
| 160 | - if ($attempts > 128) { |
|
| 174 | + if ($attempts > 128) |
|
| 175 | + { |
|
| 161 | 176 | throw new Exception( |
| 162 | 177 | 'random_int: RNG is broken - too many rejections' |
| 163 | 178 | ); |
@@ -179,7 +194,8 @@ discard block |
||
| 179 | 194 | * 204631455 |
| 180 | 195 | */ |
| 181 | 196 | $val &= 0; |
| 182 | - for ($i = 0; $i < $bytes; ++$i) { |
|
| 197 | + for ($i = 0; $i < $bytes; ++$i) |
|
| 198 | + { |
|
| 183 | 199 | $val |= ord($randomByteString[$i]) << ($i * 8); |
| 184 | 200 | } |
| 185 | 201 | /** @var int $val */ |
@@ -26,7 +26,8 @@ discard block |
||
| 26 | 26 | * SOFTWARE. |
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | -if (!is_callable('RandomCompat_intval')) { |
|
| 29 | +if (!is_callable('RandomCompat_intval')) |
|
| 30 | +{ |
|
| 30 | 31 | |
| 31 | 32 | /** |
| 32 | 33 | * Cast to an integer if we can, safely. |
@@ -47,9 +48,12 @@ discard block |
||
| 47 | 48 | */ |
| 48 | 49 | function RandomCompat_intval($number, $fail_open = false) |
| 49 | 50 | { |
| 50 | - if (is_int($number) || is_float($number)) { |
|
| 51 | + if (is_int($number) || is_float($number)) |
|
| 52 | + { |
|
| 51 | 53 | $number += 0; |
| 52 | - } elseif (is_numeric($number)) { |
|
| 54 | + } |
|
| 55 | + elseif (is_numeric($number)) |
|
| 56 | + { |
|
| 53 | 57 | /** @psalm-suppress InvalidOperand */ |
| 54 | 58 | $number += 0; |
| 55 | 59 | } |
@@ -65,9 +69,12 @@ discard block |
||
| 65 | 69 | $number = (int) $number; |
| 66 | 70 | } |
| 67 | 71 | |
| 68 | - if (is_int($number)) { |
|
| 72 | + if (is_int($number)) |
|
| 73 | + { |
|
| 69 | 74 | return (int) $number; |
| 70 | - } elseif (!$fail_open) { |
|
| 75 | + } |
|
| 76 | + elseif (!$fail_open) |
|
| 77 | + { |
|
| 71 | 78 | throw new TypeError( |
| 72 | 79 | 'Expected an integer.' |
| 73 | 80 | ); |
@@ -26,7 +26,8 @@ discard block |
||
| 26 | 26 | * SOFTWARE. |
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | -if (!is_callable('random_bytes')) { |
|
| 29 | +if (!is_callable('random_bytes')) |
|
| 30 | +{ |
|
| 30 | 31 | /** |
| 31 | 32 | * If the libsodium PHP extension is loaded, we'll use it above any other |
| 32 | 33 | * solution. |
@@ -42,16 +43,20 @@ discard block |
||
| 42 | 43 | */ |
| 43 | 44 | function random_bytes($bytes) |
| 44 | 45 | { |
| 45 | - try { |
|
| 46 | + try |
|
| 47 | + { |
|
| 46 | 48 | /** @var int $bytes */ |
| 47 | 49 | $bytes = RandomCompat_intval($bytes); |
| 48 | - } catch (TypeError $ex) { |
|
| 50 | + } |
|
| 51 | + catch (TypeError $ex) |
|
| 52 | + { |
|
| 49 | 53 | throw new TypeError( |
| 50 | 54 | 'random_bytes(): $bytes must be an integer' |
| 51 | 55 | ); |
| 52 | 56 | } |
| 53 | 57 | |
| 54 | - if ($bytes < 1) { |
|
| 58 | + if ($bytes < 1) |
|
| 59 | + { |
|
| 55 | 60 | throw new Error( |
| 56 | 61 | 'Length must be greater than 0' |
| 57 | 62 | ); |
@@ -62,21 +67,27 @@ discard block |
||
| 62 | 67 | * generated in one invocation. |
| 63 | 68 | */ |
| 64 | 69 | /** @var string|bool $buf */ |
| 65 | - if ($bytes > 2147483647) { |
|
| 70 | + if ($bytes > 2147483647) |
|
| 71 | + { |
|
| 66 | 72 | $buf = ''; |
| 67 | - for ($i = 0; $i < $bytes; $i += 1073741824) { |
|
| 73 | + for ($i = 0; $i < $bytes; $i += 1073741824) |
|
| 74 | + { |
|
| 68 | 75 | $n = ($bytes - $i) > 1073741824 |
| 69 | 76 | ? 1073741824 |
| 70 | 77 | : $bytes - $i; |
| 71 | 78 | $buf .= \Sodium\randombytes_buf($n); |
| 72 | 79 | } |
| 73 | - } else { |
|
| 80 | + } |
|
| 81 | + else |
|
| 82 | + { |
|
| 74 | 83 | /** @var string|bool $buf */ |
| 75 | 84 | $buf = \Sodium\randombytes_buf($bytes); |
| 76 | 85 | } |
| 77 | 86 | |
| 78 | - if (is_string($buf)) { |
|
| 79 | - if (RandomCompat_strlen($buf) === $bytes) { |
|
| 87 | + if (is_string($buf)) |
|
| 88 | + { |
|
| 89 | + if (RandomCompat_strlen($buf) === $bytes) |
|
| 90 | + { |
|
| 80 | 91 | return $buf; |
| 81 | 92 | } |
| 82 | 93 | } |
@@ -26,7 +26,8 @@ discard block |
||
| 26 | 26 | * SOFTWARE. |
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | -if (!is_callable('RandomCompat_strlen')) { |
|
| 29 | +if (!is_callable('RandomCompat_strlen')) |
|
| 30 | +{ |
|
| 30 | 31 | if ( |
| 31 | 32 | defined('MB_OVERLOAD_STRING') |
| 32 | 33 | && |
@@ -46,7 +47,8 @@ discard block |
||
| 46 | 47 | */ |
| 47 | 48 | function RandomCompat_strlen($binary_string) |
| 48 | 49 | { |
| 49 | - if (!is_string($binary_string)) { |
|
| 50 | + if (!is_string($binary_string)) |
|
| 51 | + { |
|
| 50 | 52 | throw new TypeError( |
| 51 | 53 | 'RandomCompat_strlen() expects a string' |
| 52 | 54 | ); |
@@ -55,7 +57,9 @@ discard block |
||
| 55 | 57 | return (int) mb_strlen($binary_string, '8bit'); |
| 56 | 58 | } |
| 57 | 59 | |
| 58 | - } else { |
|
| 60 | + } |
|
| 61 | + else |
|
| 62 | + { |
|
| 59 | 63 | /** |
| 60 | 64 | * strlen() implementation that isn't brittle to mbstring.func_overload |
| 61 | 65 | * |
@@ -69,7 +73,8 @@ discard block |
||
| 69 | 73 | */ |
| 70 | 74 | function RandomCompat_strlen($binary_string) |
| 71 | 75 | { |
| 72 | - if (!is_string($binary_string)) { |
|
| 76 | + if (!is_string($binary_string)) |
|
| 77 | + { |
|
| 73 | 78 | throw new TypeError( |
| 74 | 79 | 'RandomCompat_strlen() expects a string' |
| 75 | 80 | ); |
@@ -79,7 +84,8 @@ discard block |
||
| 79 | 84 | } |
| 80 | 85 | } |
| 81 | 86 | |
| 82 | -if (!is_callable('RandomCompat_substr')) { |
|
| 87 | +if (!is_callable('RandomCompat_substr')) |
|
| 88 | +{ |
|
| 83 | 89 | |
| 84 | 90 | if ( |
| 85 | 91 | defined('MB_OVERLOAD_STRING') |
@@ -102,36 +108,43 @@ discard block |
||
| 102 | 108 | */ |
| 103 | 109 | function RandomCompat_substr($binary_string, $start, $length = null) |
| 104 | 110 | { |
| 105 | - if (!is_string($binary_string)) { |
|
| 111 | + if (!is_string($binary_string)) |
|
| 112 | + { |
|
| 106 | 113 | throw new TypeError( |
| 107 | 114 | 'RandomCompat_substr(): First argument should be a string' |
| 108 | 115 | ); |
| 109 | 116 | } |
| 110 | 117 | |
| 111 | - if (!is_int($start)) { |
|
| 118 | + if (!is_int($start)) |
|
| 119 | + { |
|
| 112 | 120 | throw new TypeError( |
| 113 | 121 | 'RandomCompat_substr(): Second argument should be an integer' |
| 114 | 122 | ); |
| 115 | 123 | } |
| 116 | 124 | |
| 117 | - if ($length === null) { |
|
| 125 | + if ($length === null) |
|
| 126 | + { |
|
| 118 | 127 | /** |
| 119 | 128 | * mb_substr($str, 0, NULL, '8bit') returns an empty string on |
| 120 | 129 | * PHP 5.3, so we have to find the length ourselves. |
| 121 | 130 | */ |
| 122 | 131 | /** @var int $length */ |
| 123 | 132 | $length = RandomCompat_strlen($binary_string) - $start; |
| 124 | - } elseif (!is_int($length)) { |
|
| 133 | + } |
|
| 134 | + elseif (!is_int($length)) |
|
| 135 | + { |
|
| 125 | 136 | throw new TypeError( |
| 126 | 137 | 'RandomCompat_substr(): Third argument should be an integer, or omitted' |
| 127 | 138 | ); |
| 128 | 139 | } |
| 129 | 140 | |
| 130 | 141 | // Consistency with PHP's behavior |
| 131 | - if ($start === RandomCompat_strlen($binary_string) && $length === 0) { |
|
| 142 | + if ($start === RandomCompat_strlen($binary_string) && $length === 0) |
|
| 143 | + { |
|
| 132 | 144 | return ''; |
| 133 | 145 | } |
| 134 | - if ($start > RandomCompat_strlen($binary_string)) { |
|
| 146 | + if ($start > RandomCompat_strlen($binary_string)) |
|
| 147 | + { |
|
| 135 | 148 | return ''; |
| 136 | 149 | } |
| 137 | 150 | |
@@ -143,7 +156,9 @@ discard block |
||
| 143 | 156 | ); |
| 144 | 157 | } |
| 145 | 158 | |
| 146 | - } else { |
|
| 159 | + } |
|
| 160 | + else |
|
| 161 | + { |
|
| 147 | 162 | |
| 148 | 163 | /** |
| 149 | 164 | * substr() implementation that isn't brittle to mbstring.func_overload |
@@ -160,20 +175,24 @@ discard block |
||
| 160 | 175 | */ |
| 161 | 176 | function RandomCompat_substr($binary_string, $start, $length = null) |
| 162 | 177 | { |
| 163 | - if (!is_string($binary_string)) { |
|
| 178 | + if (!is_string($binary_string)) |
|
| 179 | + { |
|
| 164 | 180 | throw new TypeError( |
| 165 | 181 | 'RandomCompat_substr(): First argument should be a string' |
| 166 | 182 | ); |
| 167 | 183 | } |
| 168 | 184 | |
| 169 | - if (!is_int($start)) { |
|
| 185 | + if (!is_int($start)) |
|
| 186 | + { |
|
| 170 | 187 | throw new TypeError( |
| 171 | 188 | 'RandomCompat_substr(): Second argument should be an integer' |
| 172 | 189 | ); |
| 173 | 190 | } |
| 174 | 191 | |
| 175 | - if ($length !== null) { |
|
| 176 | - if (!is_int($length)) { |
|
| 192 | + if ($length !== null) |
|
| 193 | + { |
|
| 194 | + if (!is_int($length)) |
|
| 195 | + { |
|
| 177 | 196 | throw new TypeError( |
| 178 | 197 | 'RandomCompat_substr(): Third argument should be an integer, or omitted' |
| 179 | 198 | ); |
@@ -742,7 +742,7 @@ |
||
| 742 | 742 | |
| 743 | 743 | // Filter out any redundant separators before we start the loop |
| 744 | 744 | $context['config_vars'] = array_filter($context['config_vars'], function ($v) use ($context) |
| 745 | - { |
|
| 745 | + { |
|
| 746 | 746 | static $config_vars, $prev; |
| 747 | 747 | |
| 748 | 748 | $at_start = is_null($config_vars); |
@@ -3205,7 +3205,9 @@ |
||
| 3205 | 3205 | return $string; |
| 3206 | 3206 | |
| 3207 | 3207 | // This bit fixes incorrect string lengths, which can happen if the character encoding was changed (e.g. conversion to UTF-8) |
| 3208 | - $new_string = preg_replace_callback('~\bs:(\d+):"(.*?)";(?=$|[bidsa]:|[{}]|N;)~s', function ($matches) {return 's:' . strlen($matches[2]) . ':"' . $matches[2] . '";';}, $string); |
|
| 3208 | + $new_string = preg_replace_callback('~\bs:(\d+):"(.*?)";(?=$|[bidsa]:|[{}]|N;)~s', function ($matches) |
|
| 3209 | + { |
|
| 3210 | +return 's:' . strlen($matches[2]) . ':"' . $matches[2] . '";';}, $string); |
|
| 3209 | 3211 | |
| 3210 | 3212 | // @todo Add more possible fixes here. For example, fix incorrect array lengths, try to handle truncated strings gracefully, etc. |
| 3211 | 3213 | |
@@ -1827,7 +1827,7 @@ |
||
| 1827 | 1827 | { |
| 1828 | 1828 | // Make sure this is an array of integers |
| 1829 | 1829 | $excluded_groups = array_filter((array) $excluded_groups, function ($v) |
| 1830 | - { |
|
| 1830 | + { |
|
| 1831 | 1831 | return is_int($v) || is_string($v) && (string) intval($v) === $v; |
| 1832 | 1832 | }); |
| 1833 | 1833 | |
@@ -1257,7 +1257,6 @@ discard block |
||
| 1257 | 1257 | |
| 1258 | 1258 | continue; |
| 1259 | 1259 | } |
| 1260 | - |
|
| 1261 | 1260 | else |
| 1262 | 1261 | { |
| 1263 | 1262 | $fh = @fopen($path . '/.htaccess', 'w'); |
@@ -1269,7 +1268,6 @@ discard block |
||
| 1269 | 1268 | Deny from all' . $close); |
| 1270 | 1269 | fclose($fh); |
| 1271 | 1270 | } |
| 1272 | - |
|
| 1273 | 1271 | else |
| 1274 | 1272 | $errors[] = 'htaccess_cannot_create_file'; |
| 1275 | 1273 | } |
@@ -1280,7 +1278,6 @@ discard block |
||
| 1280 | 1278 | |
| 1281 | 1279 | continue; |
| 1282 | 1280 | } |
| 1283 | - |
|
| 1284 | 1281 | else |
| 1285 | 1282 | { |
| 1286 | 1283 | $fh = @fopen($path . '/index.php', 'w'); |
@@ -1307,7 +1304,6 @@ discard block |
||
| 1307 | 1304 | ?' . '>'); |
| 1308 | 1305 | fclose($fh); |
| 1309 | 1306 | } |
| 1310 | - |
|
| 1311 | 1307 | else |
| 1312 | 1308 | $errors[] = 'index-php_cannot_create_file'; |
| 1313 | 1309 | } |
@@ -100,18 +100,22 @@ |
||
| 100 | 100 | $tempTab++; |
| 101 | 101 | $context['tabindex'] = $tempTab; |
| 102 | 102 | |
| 103 | - foreach ($context['richedit_buttons'] as $name => $button) { |
|
| 104 | - if ($name == 'spell_check') { |
|
| 103 | + foreach ($context['richedit_buttons'] as $name => $button) |
|
| 104 | + { |
|
| 105 | + if ($name == 'spell_check') |
|
| 106 | + { |
|
| 105 | 107 | $button['onclick'] = 'oEditorHandle_' . $editor_id . '.spellCheckStart();'; |
| 106 | 108 | } |
| 107 | 109 | |
| 108 | - if ($name == 'preview') { |
|
| 110 | + if ($name == 'preview') |
|
| 111 | + { |
|
| 109 | 112 | $button['value'] = isset($editor_context['labels']['preview_button']) ? $editor_context['labels']['preview_button'] : $button['value']; |
| 110 | 113 | $button['onclick'] = $editor_context['preview_type'] == 2 ? '' : 'return submitThisOnce(this);'; |
| 111 | 114 | $button['show'] = $editor_context['preview_type']; |
| 112 | 115 | } |
| 113 | 116 | |
| 114 | - if ($button['show']) { |
|
| 117 | + if ($button['show']) |
|
| 118 | + { |
|
| 115 | 119 | echo ' |
| 116 | 120 | <input type="', $button['type'], '"', $button['type'] == 'hidden' ? ' id="' . $name . '"' : '', ' name="', $name, '" value="', $button['value'], '"', $button['type'] != 'hidden' ? ' tabindex="' . --$tempTab . '"' : '', !empty($button['onclick']) ? ' onclick="' . $button['onclick'] . '"' : '', !empty($button['accessKey']) ? ' accesskey="' . $button['accessKey'] . '"' : '', $button['type'] != 'hidden' ? ' class="button"' : '', '>'; |
| 117 | 121 | } |