@@ -220,7 +220,7 @@ |
||
| 220 | 220 | ), |
| 221 | 221 | ), |
| 222 | 222 | ); |
| 223 | - */ |
|
| 223 | + */ |
|
| 224 | 224 | |
| 225 | 225 | // Are we using right-to-left orientation? |
| 226 | 226 | $first = $context['right_to_left'] ? 'last' : 'first'; |
@@ -384,7 +384,7 @@ |
||
| 384 | 384 | clean_cache(); |
| 385 | 385 | |
| 386 | 386 | // If warning decrement is enabled and we have people who have not had a new warning in 24 hours, lower their warning level. |
| 387 | - list (, , $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']); |
|
| 387 | + list (,, $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']); |
|
| 388 | 388 | if ($modSettings['warning_decrement']) |
| 389 | 389 | { |
| 390 | 390 | // Find every member who has a warning level... |
@@ -419,7 +419,7 @@ |
||
| 419 | 419 | $board['last_post']['last_post_message'] = sprintf($txt['last_post_message'], $board['last_post']['member']['link'], $board['last_post']['link'], $board['last_post']['time'] > 0 ? timeformat($board['last_post']['time']) : $txt['not_applicable']); |
| 420 | 420 | } |
| 421 | 421 | } |
| 422 | - else |
|
| 422 | + else |
|
| 423 | 423 | foreach ($this_category as &$board) |
| 424 | 424 | { |
| 425 | 425 | if (!empty($moderators[$board['id']])) |
@@ -979,7 +979,8 @@ discard block |
||
| 979 | 979 | $error_array[2] = null; |
| 980 | 980 | |
| 981 | 981 | if(empty($db_persist)) |
| 982 | - { // without pooling |
|
| 982 | + { |
|
| 983 | +// without pooling |
|
| 983 | 984 | if (empty($pg_error_data_prep)) |
| 984 | 985 | $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
| 985 | 986 | 'INSERT INTO ' . $db_prefix . 'log_errors |
@@ -990,7 +991,8 @@ discard block |
||
| 990 | 991 | pg_execute($db_connection, 'smf_log_errors', $error_array); |
| 991 | 992 | } |
| 992 | 993 | else |
| 993 | - { //with pooling |
|
| 994 | + { |
|
| 995 | +//with pooling |
|
| 994 | 996 | $pg_error_data_prep = pg_prepare($db_connection, '', |
| 995 | 997 | 'INSERT INTO ' . $db_prefix . 'log_errors |
| 996 | 998 | (id_member, log_time, ip, url, message, session, error_type, file, line, backtrace) |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | display_db_error(); |
| 74 | 74 | |
| 75 | 75 | // We need to escape ' and \ |
| 76 | - $db_passwd = str_replace(array('\\','\''), array('\\\\','\\\''), $db_passwd); |
|
| 76 | + $db_passwd = str_replace(array('\\', '\''), array('\\\\', '\\\''), $db_passwd); |
|
| 77 | 77 | |
| 78 | 78 | if (!empty($db_options['persist'])) |
| 79 | 79 | $connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
@@ -925,7 +925,7 @@ discard block |
||
| 925 | 925 | if (filter_var($error_array[2], FILTER_VALIDATE_IP) === false) |
| 926 | 926 | $error_array[2] = null; |
| 927 | 927 | |
| 928 | - if(empty($db_persist)) |
|
| 928 | + if (empty($db_persist)) |
|
| 929 | 929 | { // without pooling |
| 930 | 930 | if (empty($pg_error_data_prep)) |
| 931 | 931 | $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
@@ -27,146 +27,146 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | 29 | if (!defined('RANDOM_COMPAT_READ_BUFFER')) { |
| 30 | - define('RANDOM_COMPAT_READ_BUFFER', 8); |
|
| 30 | + define('RANDOM_COMPAT_READ_BUFFER', 8); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | if (!is_callable('random_bytes')) { |
| 34 | - /** |
|
| 35 | - * Unless open_basedir is enabled, use /dev/urandom for |
|
| 36 | - * random numbers in accordance with best practices |
|
| 37 | - * |
|
| 38 | - * Why we use /dev/urandom and not /dev/random |
|
| 39 | - * @ref http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers |
|
| 40 | - * |
|
| 41 | - * @param int $bytes |
|
| 42 | - * |
|
| 43 | - * @throws Exception |
|
| 44 | - * |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 47 | - function random_bytes($bytes) |
|
| 48 | - { |
|
| 49 | - /** @var resource $fp */ |
|
| 50 | - static $fp = null; |
|
| 34 | + /** |
|
| 35 | + * Unless open_basedir is enabled, use /dev/urandom for |
|
| 36 | + * random numbers in accordance with best practices |
|
| 37 | + * |
|
| 38 | + * Why we use /dev/urandom and not /dev/random |
|
| 39 | + * @ref http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers |
|
| 40 | + * |
|
| 41 | + * @param int $bytes |
|
| 42 | + * |
|
| 43 | + * @throws Exception |
|
| 44 | + * |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | + function random_bytes($bytes) |
|
| 48 | + { |
|
| 49 | + /** @var resource $fp */ |
|
| 50 | + static $fp = null; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * This block should only be run once |
|
| 54 | - */ |
|
| 55 | - if (empty($fp)) { |
|
| 56 | - /** |
|
| 57 | - * We use /dev/urandom if it is a char device. |
|
| 58 | - * We never fall back to /dev/random |
|
| 59 | - */ |
|
| 60 | - /** @var resource|bool $fp */ |
|
| 61 | - $fp = fopen('/dev/urandom', 'rb'); |
|
| 62 | - if (is_resource($fp)) { |
|
| 63 | - /** @var array<string, int> $st */ |
|
| 64 | - $st = fstat($fp); |
|
| 65 | - if (($st['mode'] & 0170000) !== 020000) { |
|
| 66 | - fclose($fp); |
|
| 67 | - $fp = false; |
|
| 68 | - } |
|
| 69 | - } |
|
| 52 | + /** |
|
| 53 | + * This block should only be run once |
|
| 54 | + */ |
|
| 55 | + if (empty($fp)) { |
|
| 56 | + /** |
|
| 57 | + * We use /dev/urandom if it is a char device. |
|
| 58 | + * We never fall back to /dev/random |
|
| 59 | + */ |
|
| 60 | + /** @var resource|bool $fp */ |
|
| 61 | + $fp = fopen('/dev/urandom', 'rb'); |
|
| 62 | + if (is_resource($fp)) { |
|
| 63 | + /** @var array<string, int> $st */ |
|
| 64 | + $st = fstat($fp); |
|
| 65 | + if (($st['mode'] & 0170000) !== 020000) { |
|
| 66 | + fclose($fp); |
|
| 67 | + $fp = false; |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - if (is_resource($fp)) { |
|
| 72 | - /** |
|
| 73 | - * stream_set_read_buffer() does not exist in HHVM |
|
| 74 | - * |
|
| 75 | - * If we don't set the stream's read buffer to 0, PHP will |
|
| 76 | - * internally buffer 8192 bytes, which can waste entropy |
|
| 77 | - * |
|
| 78 | - * stream_set_read_buffer returns 0 on success |
|
| 79 | - */ |
|
| 80 | - if (is_callable('stream_set_read_buffer')) { |
|
| 81 | - stream_set_read_buffer($fp, RANDOM_COMPAT_READ_BUFFER); |
|
| 82 | - } |
|
| 83 | - if (is_callable('stream_set_chunk_size')) { |
|
| 84 | - stream_set_chunk_size($fp, RANDOM_COMPAT_READ_BUFFER); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - } |
|
| 71 | + if (is_resource($fp)) { |
|
| 72 | + /** |
|
| 73 | + * stream_set_read_buffer() does not exist in HHVM |
|
| 74 | + * |
|
| 75 | + * If we don't set the stream's read buffer to 0, PHP will |
|
| 76 | + * internally buffer 8192 bytes, which can waste entropy |
|
| 77 | + * |
|
| 78 | + * stream_set_read_buffer returns 0 on success |
|
| 79 | + */ |
|
| 80 | + if (is_callable('stream_set_read_buffer')) { |
|
| 81 | + stream_set_read_buffer($fp, RANDOM_COMPAT_READ_BUFFER); |
|
| 82 | + } |
|
| 83 | + if (is_callable('stream_set_chunk_size')) { |
|
| 84 | + stream_set_chunk_size($fp, RANDOM_COMPAT_READ_BUFFER); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - try { |
|
| 90 | - /** @var int $bytes */ |
|
| 91 | - $bytes = RandomCompat_intval($bytes); |
|
| 92 | - } catch (TypeError $ex) { |
|
| 93 | - throw new TypeError( |
|
| 94 | - 'random_bytes(): $bytes must be an integer' |
|
| 95 | - ); |
|
| 96 | - } |
|
| 89 | + try { |
|
| 90 | + /** @var int $bytes */ |
|
| 91 | + $bytes = RandomCompat_intval($bytes); |
|
| 92 | + } catch (TypeError $ex) { |
|
| 93 | + throw new TypeError( |
|
| 94 | + 'random_bytes(): $bytes must be an integer' |
|
| 95 | + ); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - if ($bytes < 1) { |
|
| 99 | - throw new Error( |
|
| 100 | - 'Length must be greater than 0' |
|
| 101 | - ); |
|
| 102 | - } |
|
| 98 | + if ($bytes < 1) { |
|
| 99 | + throw new Error( |
|
| 100 | + 'Length must be greater than 0' |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * This if() block only runs if we managed to open a file handle |
|
| 106 | - * |
|
| 107 | - * It does not belong in an else {} block, because the above |
|
| 108 | - * if (empty($fp)) line is logic that should only be run once per |
|
| 109 | - * page load. |
|
| 110 | - */ |
|
| 111 | - if (is_resource($fp)) { |
|
| 112 | - /** |
|
| 113 | - * @var int |
|
| 114 | - */ |
|
| 115 | - $remaining = $bytes; |
|
| 104 | + /** |
|
| 105 | + * This if() block only runs if we managed to open a file handle |
|
| 106 | + * |
|
| 107 | + * It does not belong in an else {} block, because the above |
|
| 108 | + * if (empty($fp)) line is logic that should only be run once per |
|
| 109 | + * page load. |
|
| 110 | + */ |
|
| 111 | + if (is_resource($fp)) { |
|
| 112 | + /** |
|
| 113 | + * @var int |
|
| 114 | + */ |
|
| 115 | + $remaining = $bytes; |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * @var string|bool |
|
| 119 | - */ |
|
| 120 | - $buf = ''; |
|
| 117 | + /** |
|
| 118 | + * @var string|bool |
|
| 119 | + */ |
|
| 120 | + $buf = ''; |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * We use fread() in a loop to protect against partial reads |
|
| 124 | - */ |
|
| 125 | - do { |
|
| 126 | - /** |
|
| 127 | - * @var string|bool |
|
| 128 | - */ |
|
| 129 | - $read = fread($fp, $remaining); |
|
| 130 | - if (!is_string($read)) { |
|
| 131 | - if ($read === false) { |
|
| 132 | - /** |
|
| 133 | - * We cannot safely read from the file. Exit the |
|
| 134 | - * do-while loop and trigger the exception condition |
|
| 135 | - * |
|
| 136 | - * @var string|bool |
|
| 137 | - */ |
|
| 138 | - $buf = false; |
|
| 139 | - break; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - /** |
|
| 143 | - * Decrease the number of bytes returned from remaining |
|
| 144 | - */ |
|
| 145 | - $remaining -= RandomCompat_strlen($read); |
|
| 146 | - /** |
|
| 147 | - * @var string|bool |
|
| 148 | - */ |
|
| 149 | - $buf = $buf . $read; |
|
| 150 | - } while ($remaining > 0); |
|
| 122 | + /** |
|
| 123 | + * We use fread() in a loop to protect against partial reads |
|
| 124 | + */ |
|
| 125 | + do { |
|
| 126 | + /** |
|
| 127 | + * @var string|bool |
|
| 128 | + */ |
|
| 129 | + $read = fread($fp, $remaining); |
|
| 130 | + if (!is_string($read)) { |
|
| 131 | + if ($read === false) { |
|
| 132 | + /** |
|
| 133 | + * We cannot safely read from the file. Exit the |
|
| 134 | + * do-while loop and trigger the exception condition |
|
| 135 | + * |
|
| 136 | + * @var string|bool |
|
| 137 | + */ |
|
| 138 | + $buf = false; |
|
| 139 | + break; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + /** |
|
| 143 | + * Decrease the number of bytes returned from remaining |
|
| 144 | + */ |
|
| 145 | + $remaining -= RandomCompat_strlen($read); |
|
| 146 | + /** |
|
| 147 | + * @var string|bool |
|
| 148 | + */ |
|
| 149 | + $buf = $buf . $read; |
|
| 150 | + } while ($remaining > 0); |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Is our result valid? |
|
| 154 | - */ |
|
| 155 | - if (is_string($buf)) { |
|
| 156 | - if (RandomCompat_strlen($buf) === $bytes) { |
|
| 157 | - /** |
|
| 158 | - * Return our random entropy buffer here: |
|
| 159 | - */ |
|
| 160 | - return $buf; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } |
|
| 152 | + /** |
|
| 153 | + * Is our result valid? |
|
| 154 | + */ |
|
| 155 | + if (is_string($buf)) { |
|
| 156 | + if (RandomCompat_strlen($buf) === $bytes) { |
|
| 157 | + /** |
|
| 158 | + * Return our random entropy buffer here: |
|
| 159 | + */ |
|
| 160 | + return $buf; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * If we reach here, PHP has failed us. |
|
| 167 | - */ |
|
| 168 | - throw new Exception( |
|
| 169 | - 'Error reading from source device' |
|
| 170 | - ); |
|
| 171 | - } |
|
| 165 | + /** |
|
| 166 | + * If we reach here, PHP has failed us. |
|
| 167 | + */ |
|
| 168 | + throw new Exception( |
|
| 169 | + 'Error reading from source device' |
|
| 170 | + ); |
|
| 171 | + } |
|
| 172 | 172 | } |
@@ -26,11 +26,13 @@ discard block |
||
| 26 | 26 | * SOFTWARE. |
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | -if (!defined('RANDOM_COMPAT_READ_BUFFER')) { |
|
| 29 | +if (!defined('RANDOM_COMPAT_READ_BUFFER')) |
|
| 30 | +{ |
|
| 30 | 31 | define('RANDOM_COMPAT_READ_BUFFER', 8); |
| 31 | 32 | } |
| 32 | 33 | |
| 33 | -if (!is_callable('random_bytes')) { |
|
| 34 | +if (!is_callable('random_bytes')) |
|
| 35 | +{ |
|
| 34 | 36 | /** |
| 35 | 37 | * Unless open_basedir is enabled, use /dev/urandom for |
| 36 | 38 | * random numbers in accordance with best practices |
@@ -52,23 +54,27 @@ discard block |
||
| 52 | 54 | /** |
| 53 | 55 | * This block should only be run once |
| 54 | 56 | */ |
| 55 | - if (empty($fp)) { |
|
| 57 | + if (empty($fp)) |
|
| 58 | + { |
|
| 56 | 59 | /** |
| 57 | 60 | * We use /dev/urandom if it is a char device. |
| 58 | 61 | * We never fall back to /dev/random |
| 59 | 62 | */ |
| 60 | 63 | /** @var resource|bool $fp */ |
| 61 | 64 | $fp = fopen('/dev/urandom', 'rb'); |
| 62 | - if (is_resource($fp)) { |
|
| 65 | + if (is_resource($fp)) |
|
| 66 | + { |
|
| 63 | 67 | /** @var array<string, int> $st */ |
| 64 | 68 | $st = fstat($fp); |
| 65 | - if (($st['mode'] & 0170000) !== 020000) { |
|
| 69 | + if (($st['mode'] & 0170000) !== 020000) |
|
| 70 | + { |
|
| 66 | 71 | fclose($fp); |
| 67 | 72 | $fp = false; |
| 68 | 73 | } |
| 69 | 74 | } |
| 70 | 75 | |
| 71 | - if (is_resource($fp)) { |
|
| 76 | + if (is_resource($fp)) |
|
| 77 | + { |
|
| 72 | 78 | /** |
| 73 | 79 | * stream_set_read_buffer() does not exist in HHVM |
| 74 | 80 | * |
@@ -77,25 +83,31 @@ discard block |
||
| 77 | 83 | * |
| 78 | 84 | * stream_set_read_buffer returns 0 on success |
| 79 | 85 | */ |
| 80 | - if (is_callable('stream_set_read_buffer')) { |
|
| 86 | + if (is_callable('stream_set_read_buffer')) |
|
| 87 | + { |
|
| 81 | 88 | stream_set_read_buffer($fp, RANDOM_COMPAT_READ_BUFFER); |
| 82 | 89 | } |
| 83 | - if (is_callable('stream_set_chunk_size')) { |
|
| 90 | + if (is_callable('stream_set_chunk_size')) |
|
| 91 | + { |
|
| 84 | 92 | stream_set_chunk_size($fp, RANDOM_COMPAT_READ_BUFFER); |
| 85 | 93 | } |
| 86 | 94 | } |
| 87 | 95 | } |
| 88 | 96 | |
| 89 | - try { |
|
| 97 | + try |
|
| 98 | + { |
|
| 90 | 99 | /** @var int $bytes */ |
| 91 | 100 | $bytes = RandomCompat_intval($bytes); |
| 92 | - } catch (TypeError $ex) { |
|
| 101 | + } |
|
| 102 | + catch (TypeError $ex) |
|
| 103 | + { |
|
| 93 | 104 | throw new TypeError( |
| 94 | 105 | 'random_bytes(): $bytes must be an integer' |
| 95 | 106 | ); |
| 96 | 107 | } |
| 97 | 108 | |
| 98 | - if ($bytes < 1) { |
|
| 109 | + if ($bytes < 1) |
|
| 110 | + { |
|
| 99 | 111 | throw new Error( |
| 100 | 112 | 'Length must be greater than 0' |
| 101 | 113 | ); |
@@ -108,7 +120,8 @@ discard block |
||
| 108 | 120 | * if (empty($fp)) line is logic that should only be run once per |
| 109 | 121 | * page load. |
| 110 | 122 | */ |
| 111 | - if (is_resource($fp)) { |
|
| 123 | + if (is_resource($fp)) |
|
| 124 | + { |
|
| 112 | 125 | /** |
| 113 | 126 | * @var int |
| 114 | 127 | */ |
@@ -127,8 +140,10 @@ discard block |
||
| 127 | 140 | * @var string|bool |
| 128 | 141 | */ |
| 129 | 142 | $read = fread($fp, $remaining); |
| 130 | - if (!is_string($read)) { |
|
| 131 | - if ($read === false) { |
|
| 143 | + if (!is_string($read)) |
|
| 144 | + { |
|
| 145 | + if ($read === false) |
|
| 146 | + { |
|
| 132 | 147 | /** |
| 133 | 148 | * We cannot safely read from the file. Exit the |
| 134 | 149 | * do-while loop and trigger the exception condition |
@@ -152,8 +167,10 @@ discard block |
||
| 152 | 167 | /** |
| 153 | 168 | * Is our result valid? |
| 154 | 169 | */ |
| 155 | - if (is_string($buf)) { |
|
| 156 | - if (RandomCompat_strlen($buf) === $bytes) { |
|
| 170 | + if (is_string($buf)) |
|
| 171 | + { |
|
| 172 | + if (RandomCompat_strlen($buf) === $bytes) |
|
| 173 | + { |
|
| 157 | 174 | /** |
| 158 | 175 | * Return our random entropy buffer here: |
| 159 | 176 | */ |
@@ -27,65 +27,65 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | 29 | if (!is_callable('random_bytes')) { |
| 30 | - /** |
|
| 31 | - * Windows with PHP < 5.3.0 will not have the function |
|
| 32 | - * openssl_random_pseudo_bytes() available, so let's use |
|
| 33 | - * CAPICOM to work around this deficiency. |
|
| 34 | - * |
|
| 35 | - * @param int $bytes |
|
| 36 | - * |
|
| 37 | - * @throws Exception |
|
| 38 | - * |
|
| 39 | - * @return string |
|
| 40 | - */ |
|
| 41 | - function random_bytes($bytes) |
|
| 42 | - { |
|
| 43 | - try { |
|
| 44 | - /** @var int $bytes */ |
|
| 45 | - $bytes = RandomCompat_intval($bytes); |
|
| 46 | - } catch (TypeError $ex) { |
|
| 47 | - throw new TypeError( |
|
| 48 | - 'random_bytes(): $bytes must be an integer' |
|
| 49 | - ); |
|
| 50 | - } |
|
| 30 | + /** |
|
| 31 | + * Windows with PHP < 5.3.0 will not have the function |
|
| 32 | + * openssl_random_pseudo_bytes() available, so let's use |
|
| 33 | + * CAPICOM to work around this deficiency. |
|
| 34 | + * |
|
| 35 | + * @param int $bytes |
|
| 36 | + * |
|
| 37 | + * @throws Exception |
|
| 38 | + * |
|
| 39 | + * @return string |
|
| 40 | + */ |
|
| 41 | + function random_bytes($bytes) |
|
| 42 | + { |
|
| 43 | + try { |
|
| 44 | + /** @var int $bytes */ |
|
| 45 | + $bytes = RandomCompat_intval($bytes); |
|
| 46 | + } catch (TypeError $ex) { |
|
| 47 | + throw new TypeError( |
|
| 48 | + 'random_bytes(): $bytes must be an integer' |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - if ($bytes < 1) { |
|
| 53 | - throw new Error( |
|
| 54 | - 'Length must be greater than 0' |
|
| 55 | - ); |
|
| 56 | - } |
|
| 52 | + if ($bytes < 1) { |
|
| 53 | + throw new Error( |
|
| 54 | + 'Length must be greater than 0' |
|
| 55 | + ); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** @var string $buf */ |
|
| 59 | - $buf = ''; |
|
| 60 | - if (!class_exists('COM')) { |
|
| 61 | - throw new Error( |
|
| 62 | - 'COM does not exist' |
|
| 63 | - ); |
|
| 64 | - } |
|
| 65 | - /** @var COM $util */ |
|
| 66 | - $util = new COM('CAPICOM.Utilities.1'); |
|
| 67 | - $execCount = 0; |
|
| 58 | + /** @var string $buf */ |
|
| 59 | + $buf = ''; |
|
| 60 | + if (!class_exists('COM')) { |
|
| 61 | + throw new Error( |
|
| 62 | + 'COM does not exist' |
|
| 63 | + ); |
|
| 64 | + } |
|
| 65 | + /** @var COM $util */ |
|
| 66 | + $util = new COM('CAPICOM.Utilities.1'); |
|
| 67 | + $execCount = 0; |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Let's not let it loop forever. If we run N times and fail to |
|
| 71 | - * get N bytes of random data, then CAPICOM has failed us. |
|
| 72 | - */ |
|
| 73 | - do { |
|
| 74 | - $buf .= base64_decode((string) $util->GetRandom($bytes, 0)); |
|
| 75 | - if (RandomCompat_strlen($buf) >= $bytes) { |
|
| 76 | - /** |
|
| 77 | - * Return our random entropy buffer here: |
|
| 78 | - */ |
|
| 79 | - return (string) RandomCompat_substr($buf, 0, $bytes); |
|
| 80 | - } |
|
| 81 | - ++$execCount; |
|
| 82 | - } while ($execCount < $bytes); |
|
| 69 | + /** |
|
| 70 | + * Let's not let it loop forever. If we run N times and fail to |
|
| 71 | + * get N bytes of random data, then CAPICOM has failed us. |
|
| 72 | + */ |
|
| 73 | + do { |
|
| 74 | + $buf .= base64_decode((string) $util->GetRandom($bytes, 0)); |
|
| 75 | + if (RandomCompat_strlen($buf) >= $bytes) { |
|
| 76 | + /** |
|
| 77 | + * Return our random entropy buffer here: |
|
| 78 | + */ |
|
| 79 | + return (string) RandomCompat_substr($buf, 0, $bytes); |
|
| 80 | + } |
|
| 81 | + ++$execCount; |
|
| 82 | + } while ($execCount < $bytes); |
|
| 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 | } |
| 92 | 92 | \ No newline at end of file |
@@ -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 | } |
@@ -1197,7 +1197,8 @@ discard block |
||
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | 1199 | // It's important to do the numbered ones before the named ones, or messes happen. |
| 1200 | - uksort($substitutions, function($a, $b) { |
|
| 1200 | + uksort($substitutions, function($a, $b) |
|
| 1201 | + { |
|
| 1201 | 1202 | if (is_int($a) && is_int($b)) |
| 1202 | 1203 | return $a > $b; |
| 1203 | 1204 | elseif (is_int($a)) |
@@ -1716,8 +1717,12 @@ discard block |
||
| 1716 | 1717 | unset($mtime, $settingsFile, $settingsText); |
| 1717 | 1718 | $defined_vars = get_defined_vars(); |
| 1718 | 1719 | } |
| 1719 | - catch (Throwable $e) {} |
|
| 1720 | - catch (ErrorException $e) {} |
|
| 1720 | + catch (Throwable $e) |
|
| 1721 | + { |
|
| 1722 | +} |
|
| 1723 | + catch (ErrorException $e) |
|
| 1724 | + { |
|
| 1725 | +} |
|
| 1721 | 1726 | if (isset($e)) |
| 1722 | 1727 | return false; |
| 1723 | 1728 | |
@@ -1877,7 +1882,8 @@ discard block |
||
| 1877 | 1882 | // For the same reason, replace literal returns and newlines with "\r" and "\n" |
| 1878 | 1883 | elseif (is_string($var) && (strpos($var, "\n") !== false || strpos($var, "\r") !== false)) |
| 1879 | 1884 | { |
| 1880 | - return strtr(preg_replace_callback('/[\r\n]+/', function($m) { |
|
| 1885 | + return strtr(preg_replace_callback('/[\r\n]+/', function($m) |
|
| 1886 | + { |
|
| 1881 | 1887 | return '\' . "' . strtr($m[0], array("\r" => '\r', "\n" => '\n')) . '" . \''; |
| 1882 | 1888 | }, $var), array("'' . " => '', " . ''" => '')); |
| 1883 | 1889 | } |
@@ -846,7 +846,7 @@ discard block |
||
| 846 | 846 | 'if (!is_dir(realpath($cachedir)) && is_dir($boarddir . \'/cache\'))', |
| 847 | 847 | ' $cachedir = $boarddir . \'/cache\';', |
| 848 | 848 | )), |
| 849 | - 'search_pattern' => '~\n?(#[^\n]+)?(?:\n\h*if\s*\((?:\!file_exists\(\$(?'.'>boarddir|sourcedir|tasksdir|packagesdir|cachedir)\)|\!is_dir\(realpath\(\$(?'.'>boarddir|sourcedir|tasksdir|packagesdir|cachedir)\)\))[^;]+\n\h*\$(?'.'>boarddir|sourcedir|tasksdir|packagesdir|cachedir)[^\n]+;)+~sm', |
|
| 849 | + 'search_pattern' => '~\n?(#[^\n]+)?(?:\n\h*if\s*\((?:\!file_exists\(\$(?' . '>boarddir|sourcedir|tasksdir|packagesdir|cachedir)\)|\!is_dir\(realpath\(\$(?' . '>boarddir|sourcedir|tasksdir|packagesdir|cachedir)\)\))[^;]+\n\h*\$(?' . '>boarddir|sourcedir|tasksdir|packagesdir|cachedir)[^\n]+;)+~sm', |
|
| 850 | 850 | ), |
| 851 | 851 | 'db_character_set' => array( |
| 852 | 852 | 'text' => implode("\n", array( |
@@ -945,8 +945,8 @@ discard block |
||
| 945 | 945 | 'boolean' => '(?i:TRUE|FALSE|(["\']?)[01]\b\\1)', |
| 946 | 946 | 'NULL' => '(?i:NULL)', |
| 947 | 947 | // These use a PCRE subroutine to match nested arrays. |
| 948 | - 'array' => 'array\s*(\((?'.'>[^()]|(?1))*\))', |
|
| 949 | - 'object' => '\w+::__set_state\(array\s*(\((?'.'>[^()]|(?1))*\))\)', |
|
| 948 | + 'array' => 'array\s*(\((?' . '>[^()]|(?1))*\))', |
|
| 949 | + 'object' => '\w+::__set_state\(array\s*(\((?' . '>[^()]|(?1))*\))\)', |
|
| 950 | 950 | ); |
| 951 | 951 | |
| 952 | 952 | /* |
@@ -979,7 +979,7 @@ discard block |
||
| 979 | 979 | ), |
| 980 | 980 | // Remove the code that redirects to the installer. |
| 981 | 981 | $neg_index-- => array( |
| 982 | - 'search_pattern' => '~^if\s*\(file_exists\(dirname\(__FILE__\)\s*\.\s*\'/install\.php\'\)\)\s*(?:({(?'.'>[^{}]|(?1))*})\h*|header(\((?' . '>[^()]|(?2))*\));\n)~m', |
|
| 982 | + 'search_pattern' => '~^if\s*\(file_exists\(dirname\(__FILE__\)\s*\.\s*\'/install\.php\'\)\)\s*(?:({(?' . '>[^{}]|(?1))*})\h*|header(\((?' . '>[^()]|(?2))*\));\n)~m', |
|
| 983 | 983 | 'placeholder' => '', |
| 984 | 984 | ), |
| 985 | 985 | ); |
@@ -1742,7 +1742,7 @@ discard block |
||
| 1742 | 1742 | // Prevents warnings about constants that are already defined. |
| 1743 | 1743 | $settingsText = preg_replace_callback( |
| 1744 | 1744 | '~\bdefine\s*\(\s*(["\'])(\w+)\1~', |
| 1745 | - function ($matches) |
|
| 1745 | + function($matches) |
|
| 1746 | 1746 | { |
| 1747 | 1747 | return 'define(\'' . md5(mt_rand()) . '\''; |
| 1748 | 1748 | }, |
@@ -1752,7 +1752,7 @@ discard block |
||
| 1752 | 1752 | // Handle eval errors gracefully in both PHP 5 and PHP 7 |
| 1753 | 1753 | try |
| 1754 | 1754 | { |
| 1755 | - if($settingsText !== '' && @eval($settingsText) === false) |
|
| 1755 | + if ($settingsText !== '' && @eval($settingsText) === false) |
|
| 1756 | 1756 | throw new ErrorException('eval error'); |
| 1757 | 1757 | |
| 1758 | 1758 | unset($mtime, $settingsFile, $settingsText); |
@@ -1955,7 +1955,7 @@ discard block |
||
| 1955 | 1955 | } |
| 1956 | 1956 | |
| 1957 | 1957 | // Everything is simpler if we convert heredocs to normal strings first. |
| 1958 | - if (preg_match_all('/<<<(\'?)(\w+)\'?'. $line_ending . '(.*?)'. $line_ending . '\2;$/m', $code_str, $matches)) |
|
| 1958 | + if (preg_match_all('/<<<(\'?)(\w+)\'?' . $line_ending . '(.*?)' . $line_ending . '\2;$/m', $code_str, $matches)) |
|
| 1959 | 1959 | { |
| 1960 | 1960 | foreach ($matches[0] as $mkey => $heredoc) |
| 1961 | 1961 | { |
@@ -1969,7 +1969,7 @@ discard block |
||
| 1969 | 1969 | } |
| 1970 | 1970 | |
| 1971 | 1971 | // Split before everything that could possibly delimit a comment or a string. |
| 1972 | - $parts = preg_split('~(?=#+|/(?=/|\*)|\*/|'. $line_ending . '|(?<!\\\)[\'"])~m', $code_str); |
|
| 1972 | + $parts = preg_split('~(?=#+|/(?=/|\*)|\*/|' . $line_ending . '|(?<!\\\)[\'"])~m', $code_str); |
|
| 1973 | 1973 | |
| 1974 | 1974 | $in_string = 0; |
| 1975 | 1975 | $in_comment = 0; |
@@ -393,17 +393,17 @@ discard block |
||
| 393 | 393 | $quickbuttons = array( |
| 394 | 394 | 'approve' => array( |
| 395 | 395 | 'label' => $txt['approve'], |
| 396 | - 'href' => $scripturl.'?action=moderate;area=postmod;sa='.$context['current_view'].';start='.$context['start'].';'.$context['session_var'].'='.$context['session_id'].';approve='.$item['id'], |
|
| 396 | + 'href' => $scripturl . '?action=moderate;area=postmod;sa=' . $context['current_view'] . ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';approve=' . $item['id'], |
|
| 397 | 397 | 'icon' => 'approve', |
| 398 | 398 | ), |
| 399 | 399 | 'delete' => array( |
| 400 | 400 | 'label' => $txt['remove'], |
| 401 | - 'href' => $scripturl.'?action=moderate;area=postmod;sa='.$context['current_view'].';start='.$context['start'].';'.$context['session_var'].'='.$context['session_id'].';delete='.$item['id'], |
|
| 401 | + 'href' => $scripturl . '?action=moderate;area=postmod;sa=' . $context['current_view'] . ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';delete=' . $item['id'], |
|
| 402 | 402 | 'icon' => 'remove_button', |
| 403 | 403 | 'show' => $item['can_delete'] |
| 404 | 404 | ), |
| 405 | 405 | 'quickmod' => array( |
| 406 | - 'content' => '<input type="checkbox" name="item[]" value="'.$item['id'].'" checked>', |
|
| 406 | + 'content' => '<input type="checkbox" name="item[]" value="' . $item['id'] . '" checked>', |
|
| 407 | 407 | 'show' => !empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 |
| 408 | 408 | ), |
| 409 | 409 | ); |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | $quickbuttons = array( |
| 469 | 469 | 'delete' => array( |
| 470 | 470 | 'label' => $txt['remove_message'], |
| 471 | - 'href' => $scripturl.'?action=moderate;area=userwatch;sa=post;delete='.$post['id'].';start='.$context['start'].';'.$context['session_var'].'='.$context['session_id'], |
|
| 471 | + 'href' => $scripturl . '?action=moderate;area=userwatch;sa=post;delete=' . $post['id'] . ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'], |
|
| 472 | 472 | 'javascript' => 'data-confirm="' . $txt['mc_watched_users_delete_post'] . '"', |
| 473 | 473 | 'class' => 'you_sure', |
| 474 | 474 | 'icon' => 'remove_button', |