@@ -27,65 +27,65 @@ |
||
27 | 27 | */ |
28 | 28 | |
29 | 29 | if (!is_callable('random_bytes')) { |
30 | - /** |
|
31 | - * If the libsodium PHP extension is loaded, we'll use it above any other |
|
32 | - * solution. |
|
33 | - * |
|
34 | - * libsodium-php project: |
|
35 | - * @ref https://github.com/jedisct1/libsodium-php |
|
36 | - * |
|
37 | - * @param int $bytes |
|
38 | - * |
|
39 | - * @throws Exception |
|
40 | - * |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - function random_bytes($bytes) |
|
44 | - { |
|
45 | - try { |
|
46 | - /** @var int $bytes */ |
|
47 | - $bytes = RandomCompat_intval($bytes); |
|
48 | - } catch (TypeError $ex) { |
|
49 | - throw new TypeError( |
|
50 | - 'random_bytes(): $bytes must be an integer' |
|
51 | - ); |
|
52 | - } |
|
30 | + /** |
|
31 | + * If the libsodium PHP extension is loaded, we'll use it above any other |
|
32 | + * solution. |
|
33 | + * |
|
34 | + * libsodium-php project: |
|
35 | + * @ref https://github.com/jedisct1/libsodium-php |
|
36 | + * |
|
37 | + * @param int $bytes |
|
38 | + * |
|
39 | + * @throws Exception |
|
40 | + * |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + function random_bytes($bytes) |
|
44 | + { |
|
45 | + try { |
|
46 | + /** @var int $bytes */ |
|
47 | + $bytes = RandomCompat_intval($bytes); |
|
48 | + } catch (TypeError $ex) { |
|
49 | + throw new TypeError( |
|
50 | + 'random_bytes(): $bytes must be an integer' |
|
51 | + ); |
|
52 | + } |
|
53 | 53 | |
54 | - if ($bytes < 1) { |
|
55 | - throw new Error( |
|
56 | - 'Length must be greater than 0' |
|
57 | - ); |
|
58 | - } |
|
54 | + if ($bytes < 1) { |
|
55 | + throw new Error( |
|
56 | + 'Length must be greater than 0' |
|
57 | + ); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * \Sodium\randombytes_buf() doesn't allow more than 2147483647 bytes to be |
|
62 | - * generated in one invocation. |
|
63 | - */ |
|
64 | - /** @var string|bool $buf */ |
|
65 | - if ($bytes > 2147483647) { |
|
66 | - $buf = ''; |
|
67 | - for ($i = 0; $i < $bytes; $i += 1073741824) { |
|
68 | - $n = ($bytes - $i) > 1073741824 |
|
69 | - ? 1073741824 |
|
70 | - : $bytes - $i; |
|
71 | - $buf .= \Sodium\randombytes_buf($n); |
|
72 | - } |
|
73 | - } else { |
|
74 | - /** @var string|bool $buf */ |
|
75 | - $buf = \Sodium\randombytes_buf($bytes); |
|
76 | - } |
|
60 | + /** |
|
61 | + * \Sodium\randombytes_buf() doesn't allow more than 2147483647 bytes to be |
|
62 | + * generated in one invocation. |
|
63 | + */ |
|
64 | + /** @var string|bool $buf */ |
|
65 | + if ($bytes > 2147483647) { |
|
66 | + $buf = ''; |
|
67 | + for ($i = 0; $i < $bytes; $i += 1073741824) { |
|
68 | + $n = ($bytes - $i) > 1073741824 |
|
69 | + ? 1073741824 |
|
70 | + : $bytes - $i; |
|
71 | + $buf .= \Sodium\randombytes_buf($n); |
|
72 | + } |
|
73 | + } else { |
|
74 | + /** @var string|bool $buf */ |
|
75 | + $buf = \Sodium\randombytes_buf($bytes); |
|
76 | + } |
|
77 | 77 | |
78 | - if (is_string($buf)) { |
|
79 | - if (RandomCompat_strlen($buf) === $bytes) { |
|
80 | - return $buf; |
|
81 | - } |
|
82 | - } |
|
78 | + if (is_string($buf)) { |
|
79 | + if (RandomCompat_strlen($buf) === $bytes) { |
|
80 | + return $buf; |
|
81 | + } |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * If we reach here, PHP has failed us. |
|
86 | - */ |
|
87 | - throw new Exception( |
|
88 | - 'Could not gather sufficient random data' |
|
89 | - ); |
|
90 | - } |
|
84 | + /** |
|
85 | + * If we reach here, PHP has failed us. |
|
86 | + */ |
|
87 | + throw new Exception( |
|
88 | + 'Could not gather sufficient random data' |
|
89 | + ); |
|
90 | + } |
|
91 | 91 | } |
@@ -28,50 +28,50 @@ |
||
28 | 28 | |
29 | 29 | if (!is_callable('RandomCompat_intval')) { |
30 | 30 | |
31 | - /** |
|
32 | - * Cast to an integer if we can, safely. |
|
33 | - * |
|
34 | - * If you pass it a float in the range (~PHP_INT_MAX, PHP_INT_MAX) |
|
35 | - * (non-inclusive), it will sanely cast it to an int. If you it's equal to |
|
36 | - * ~PHP_INT_MAX or PHP_INT_MAX, we let it fail as not an integer. Floats |
|
37 | - * lose precision, so the <= and => operators might accidentally let a float |
|
38 | - * through. |
|
39 | - * |
|
40 | - * @param int|float $number The number we want to convert to an int |
|
41 | - * @param bool $fail_open Set to true to not throw an exception |
|
42 | - * |
|
43 | - * @return float|int |
|
44 | - * @psalm-suppress InvalidReturnType |
|
45 | - * |
|
46 | - * @throws TypeError |
|
47 | - */ |
|
48 | - function RandomCompat_intval($number, $fail_open = false) |
|
49 | - { |
|
50 | - if (is_int($number) || is_float($number)) { |
|
51 | - $number += 0; |
|
52 | - } elseif (is_numeric($number)) { |
|
53 | - /** @psalm-suppress InvalidOperand */ |
|
54 | - $number += 0; |
|
55 | - } |
|
56 | - /** @var int|float $number */ |
|
31 | + /** |
|
32 | + * Cast to an integer if we can, safely. |
|
33 | + * |
|
34 | + * If you pass it a float in the range (~PHP_INT_MAX, PHP_INT_MAX) |
|
35 | + * (non-inclusive), it will sanely cast it to an int. If you it's equal to |
|
36 | + * ~PHP_INT_MAX or PHP_INT_MAX, we let it fail as not an integer. Floats |
|
37 | + * lose precision, so the <= and => operators might accidentally let a float |
|
38 | + * through. |
|
39 | + * |
|
40 | + * @param int|float $number The number we want to convert to an int |
|
41 | + * @param bool $fail_open Set to true to not throw an exception |
|
42 | + * |
|
43 | + * @return float|int |
|
44 | + * @psalm-suppress InvalidReturnType |
|
45 | + * |
|
46 | + * @throws TypeError |
|
47 | + */ |
|
48 | + function RandomCompat_intval($number, $fail_open = false) |
|
49 | + { |
|
50 | + if (is_int($number) || is_float($number)) { |
|
51 | + $number += 0; |
|
52 | + } elseif (is_numeric($number)) { |
|
53 | + /** @psalm-suppress InvalidOperand */ |
|
54 | + $number += 0; |
|
55 | + } |
|
56 | + /** @var int|float $number */ |
|
57 | 57 | |
58 | - if ( |
|
59 | - is_float($number) |
|
60 | - && |
|
61 | - $number > ~PHP_INT_MAX |
|
62 | - && |
|
63 | - $number < PHP_INT_MAX |
|
64 | - ) { |
|
65 | - $number = (int) $number; |
|
66 | - } |
|
58 | + if ( |
|
59 | + is_float($number) |
|
60 | + && |
|
61 | + $number > ~PHP_INT_MAX |
|
62 | + && |
|
63 | + $number < PHP_INT_MAX |
|
64 | + ) { |
|
65 | + $number = (int) $number; |
|
66 | + } |
|
67 | 67 | |
68 | - if (is_int($number)) { |
|
69 | - return (int) $number; |
|
70 | - } elseif (!$fail_open) { |
|
71 | - throw new TypeError( |
|
72 | - 'Expected an integer.' |
|
73 | - ); |
|
74 | - } |
|
75 | - return $number; |
|
76 | - } |
|
68 | + if (is_int($number)) { |
|
69 | + return (int) $number; |
|
70 | + } elseif (!$fail_open) { |
|
71 | + throw new TypeError( |
|
72 | + 'Expected an integer.' |
|
73 | + ); |
|
74 | + } |
|
75 | + return $number; |
|
76 | + } |
|
77 | 77 | } |
@@ -7082,32 +7082,32 @@ discard block |
||
7082 | 7082 | */ |
7083 | 7083 | function truncate_array($array, $max_length = 1900, $deep = 3) |
7084 | 7084 | { |
7085 | - $array = (array) $array; |
|
7085 | + $array = (array) $array; |
|
7086 | 7086 | |
7087 | - $curr_length = array_length($array, $deep); |
|
7087 | + $curr_length = array_length($array, $deep); |
|
7088 | 7088 | |
7089 | - if ($curr_length <= $max_length) |
|
7090 | - return $array; |
|
7089 | + if ($curr_length <= $max_length) |
|
7090 | + return $array; |
|
7091 | 7091 | |
7092 | - else |
|
7093 | - { |
|
7094 | - // Truncate each element's value to a reasonable length |
|
7095 | - $param_max = floor($max_length / count($array)); |
|
7092 | + else |
|
7093 | + { |
|
7094 | + // Truncate each element's value to a reasonable length |
|
7095 | + $param_max = floor($max_length / count($array)); |
|
7096 | 7096 | |
7097 | - $current_deep = $deep - 1; |
|
7097 | + $current_deep = $deep - 1; |
|
7098 | 7098 | |
7099 | - foreach ($array as $key => &$value) |
|
7100 | - { |
|
7101 | - if (is_array($value)) |
|
7102 | - if ($current_deep > 0) |
|
7103 | - $value = truncate_array($value, $current_deep); |
|
7099 | + foreach ($array as $key => &$value) |
|
7100 | + { |
|
7101 | + if (is_array($value)) |
|
7102 | + if ($current_deep > 0) |
|
7103 | + $value = truncate_array($value, $current_deep); |
|
7104 | 7104 | |
7105 | - else |
|
7106 | - $value = substr($value, 0, $param_max - strlen($key) - 5); |
|
7107 | - } |
|
7105 | + else |
|
7106 | + $value = substr($value, 0, $param_max - strlen($key) - 5); |
|
7107 | + } |
|
7108 | 7108 | |
7109 | - return $array; |
|
7110 | - } |
|
7109 | + return $array; |
|
7110 | + } |
|
7111 | 7111 | } |
7112 | 7112 | |
7113 | 7113 | /** |
@@ -7118,29 +7118,29 @@ discard block |
||
7118 | 7118 | */ |
7119 | 7119 | function array_length($array, $deep = 3) |
7120 | 7120 | { |
7121 | - // Work with arrays |
|
7122 | - $array = (array) $array; |
|
7123 | - $length = 0; |
|
7121 | + // Work with arrays |
|
7122 | + $array = (array) $array; |
|
7123 | + $length = 0; |
|
7124 | 7124 | |
7125 | - $deep_count = $deep - 1; |
|
7125 | + $deep_count = $deep - 1; |
|
7126 | 7126 | |
7127 | - foreach ($array as $value) |
|
7128 | - { |
|
7129 | - // Recursive? |
|
7130 | - if (is_array($value)) |
|
7131 | - { |
|
7132 | - // No can't do |
|
7133 | - if ($deep_count <= 0) |
|
7134 | - continue; |
|
7127 | + foreach ($array as $value) |
|
7128 | + { |
|
7129 | + // Recursive? |
|
7130 | + if (is_array($value)) |
|
7131 | + { |
|
7132 | + // No can't do |
|
7133 | + if ($deep_count <= 0) |
|
7134 | + continue; |
|
7135 | 7135 | |
7136 | - $length += array_length($value, $deep_count); |
|
7137 | - } |
|
7136 | + $length += array_length($value, $deep_count); |
|
7137 | + } |
|
7138 | 7138 | |
7139 | - else |
|
7140 | - $length += strlen($value); |
|
7141 | - } |
|
7139 | + else |
|
7140 | + $length += strlen($value); |
|
7141 | + } |
|
7142 | 7142 | |
7143 | - return $length; |
|
7143 | + return $length; |
|
7144 | 7144 | } |
7145 | 7145 | |
7146 | 7146 | ?> |
7147 | 7147 | \ No newline at end of file |
@@ -2263,7 +2263,7 @@ |
||
2263 | 2263 | { |
2264 | 2264 | uasort($loaded_attachments, function($a, $b) { |
2265 | 2265 | if ($a['filesize'] == $b['filesize']) |
2266 | - return 0; |
|
2266 | + return 0; |
|
2267 | 2267 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
2268 | 2268 | }); |
2269 | 2269 | } |
@@ -310,7 +310,7 @@ |
||
310 | 310 | { |
311 | 311 | /** |
312 | 312 | * Constants for notification types. |
313 | - */ |
|
313 | + */ |
|
314 | 314 | const RECEIVE_NOTIFY_EMAIL = 0x02; |
315 | 315 | const RECEIVE_NOTIFY_ALERT = 0x01; |
316 | 316 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | { |
20 | 20 | /** |
21 | 21 | * Constants for reply types. |
22 | - */ |
|
22 | + */ |
|
23 | 23 | const NOTIFY_TYPE_REPLY_AND_MODIFY = 1; |
24 | 24 | const NOTIFY_TYPE_REPLY_AND_TOPIC_START_FOLLOWING = 2; |
25 | 25 | const NOTIFY_TYPE_ONLY_REPLIES = 3; |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Constants for frequencies. |
30 | - */ |
|
30 | + */ |
|
31 | 31 | const FREQUENCY_NOTHING = 0; |
32 | 32 | const FREQUENCY_EVERYTHING = 1; |
33 | 33 | const FREQUENCY_FIRST_UNREAD_MSG = 2; |