@@ -200,22 +200,22 @@ discard block |
||
200 | 200 | |
201 | 201 | case 'date': |
202 | 202 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
203 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
203 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]) . '::date'; |
|
204 | 204 | else |
205 | 205 | smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
206 | 206 | break; |
207 | 207 | |
208 | 208 | case 'time': |
209 | 209 | if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
210 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
210 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]) . '::time'; |
|
211 | 211 | else |
212 | 212 | smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
213 | 213 | break; |
214 | 214 | |
215 | 215 | case 'datetime': |
216 | 216 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
217 | - return 'to_timestamp('. |
|
218 | - sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
|
217 | + return 'to_timestamp(' . |
|
218 | + sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5], $datetime_matches[6]) . |
|
219 | 219 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
220 | 220 | else |
221 | 221 | smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | $query_hints_undo .= 'SET LOCAL join_collapse_limit = default;'; |
478 | 478 | } |
479 | 479 | |
480 | - $db_string = $query_hints_set .' |
|
480 | + $db_string = $query_hints_set . ' |
|
481 | 481 | ' . $db_string; |
482 | 482 | } |
483 | 483 | |
@@ -791,10 +791,10 @@ discard block |
||
791 | 791 | $returning = ''; |
792 | 792 | $with_returning = false; |
793 | 793 | // lets build the returning string, mysql allow only in normal mode |
794 | - if(!empty($keys) && (count($keys) > 0) && ($method === '' || $method === 'insert') && $returnmode > 0) |
|
794 | + if (!empty($keys) && (count($keys) > 0) && ($method === '' || $method === 'insert') && $returnmode > 0) |
|
795 | 795 | { |
796 | 796 | // we only take the first key |
797 | - $returning = ' RETURNING '.$keys[0]; |
|
797 | + $returning = ' RETURNING ' . $keys[0]; |
|
798 | 798 | $with_returning = true; |
799 | 799 | } |
800 | 800 | |
@@ -825,7 +825,7 @@ discard block |
||
825 | 825 | INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '") |
826 | 826 | VALUES |
827 | 827 | ' . implode(', |
828 | - ', $insertRows).$replace.$returning, |
|
828 | + ', $insertRows) . $replace . $returning, |
|
829 | 829 | array( |
830 | 830 | 'security_override' => true, |
831 | 831 | 'db_error_skip' => $method == 'ignore' || $table === $db_prefix . 'log_errors', |
@@ -838,7 +838,7 @@ discard block |
||
838 | 838 | if ($returnmode === 2) |
839 | 839 | $return_var = array(); |
840 | 840 | |
841 | - while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
|
841 | + while (($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
|
842 | 842 | { |
843 | 843 | if (is_numeric($row[0])) // try to emulate mysql limitation |
844 | 844 | { |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -34,8 +35,8 @@ discard block |
||
34 | 35 | global $smcFunc; |
35 | 36 | |
36 | 37 | // Map some database specific functions, only do this once. |
37 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
38 | - $smcFunc += array( |
|
38 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
39 | + $smcFunc += array( |
|
39 | 40 | 'db_query' => 'smf_db_query', |
40 | 41 | 'db_quote' => 'smf_db_quote', |
41 | 42 | 'db_insert' => 'smf_db_insert', |
@@ -61,11 +62,13 @@ discard block |
||
61 | 62 | 'db_mb4' => true, |
62 | 63 | 'db_ping' => 'pg_ping', |
63 | 64 | ); |
65 | + } |
|
64 | 66 | |
65 | - if (!empty($db_options['persist'])) |
|
66 | - $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
67 | - else |
|
68 | - $connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
67 | + if (!empty($db_options['persist'])) { |
|
68 | + $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
69 | + } else { |
|
70 | + $connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
71 | + } |
|
69 | 72 | |
70 | 73 | // Something's wrong, show an error if its fatal (which we assume it is) |
71 | 74 | if (!$connection) |
@@ -73,8 +76,7 @@ discard block |
||
73 | 76 | if (!empty($db_options['non_fatal'])) |
74 | 77 | { |
75 | 78 | return null; |
76 | - } |
|
77 | - else |
|
79 | + } else |
|
78 | 80 | { |
79 | 81 | display_db_error(); |
80 | 82 | } |
@@ -125,35 +127,42 @@ discard block |
||
125 | 127 | |
126 | 128 | list ($values, $connection) = $db_callback; |
127 | 129 | |
128 | - if ($matches[1] === 'db_prefix') |
|
129 | - return $db_prefix; |
|
130 | + if ($matches[1] === 'db_prefix') { |
|
131 | + return $db_prefix; |
|
132 | + } |
|
130 | 133 | |
131 | 134 | if (!empty($user_info)) |
132 | 135 | { |
133 | - foreach (array_keys($user_info) as $key) |
|
134 | - if (strpos($key, 'query_') !== false && $key === $matches[1]) |
|
136 | + foreach (array_keys($user_info) as $key) { |
|
137 | + if (strpos($key, 'query_') !== false && $key === $matches[1]) |
|
135 | 138 | return $user_info[$matches[1]]; |
139 | + } |
|
136 | 140 | } |
137 | 141 | |
138 | - if ($matches[1] === 'empty') |
|
139 | - return '\'\''; |
|
142 | + if ($matches[1] === 'empty') { |
|
143 | + return '\'\''; |
|
144 | + } |
|
140 | 145 | |
141 | - if (!isset($matches[2])) |
|
142 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
146 | + if (!isset($matches[2])) { |
|
147 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
148 | + } |
|
143 | 149 | |
144 | - if ($matches[1] === 'literal') |
|
145 | - return '\'' . pg_escape_string($matches[2]) . '\''; |
|
150 | + if ($matches[1] === 'literal') { |
|
151 | + return '\'' . pg_escape_string($matches[2]) . '\''; |
|
152 | + } |
|
146 | 153 | |
147 | - if (!isset($values[$matches[2]])) |
|
148 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
154 | + if (!isset($values[$matches[2]])) { |
|
155 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
156 | + } |
|
149 | 157 | |
150 | 158 | $replacement = $values[$matches[2]]; |
151 | 159 | |
152 | 160 | switch ($matches[1]) |
153 | 161 | { |
154 | 162 | case 'int': |
155 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
156 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
163 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
164 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
165 | + } |
|
157 | 166 | return (string) (int) $replacement; |
158 | 167 | break; |
159 | 168 | |
@@ -165,65 +174,73 @@ discard block |
||
165 | 174 | case 'array_int': |
166 | 175 | if (is_array($replacement)) |
167 | 176 | { |
168 | - if (empty($replacement)) |
|
169 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
177 | + if (empty($replacement)) { |
|
178 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
179 | + } |
|
170 | 180 | |
171 | 181 | foreach ($replacement as $key => $value) |
172 | 182 | { |
173 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
174 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
183 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
184 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
185 | + } |
|
175 | 186 | |
176 | 187 | $replacement[$key] = (string) (int) $value; |
177 | 188 | } |
178 | 189 | |
179 | 190 | return implode(', ', $replacement); |
191 | + } else { |
|
192 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
180 | 193 | } |
181 | - else |
|
182 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
183 | 194 | |
184 | 195 | break; |
185 | 196 | |
186 | 197 | case 'array_string': |
187 | 198 | if (is_array($replacement)) |
188 | 199 | { |
189 | - if (empty($replacement)) |
|
190 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
200 | + if (empty($replacement)) { |
|
201 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
202 | + } |
|
191 | 203 | |
192 | - foreach ($replacement as $key => $value) |
|
193 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
204 | + foreach ($replacement as $key => $value) { |
|
205 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
206 | + } |
|
194 | 207 | |
195 | 208 | return implode(', ', $replacement); |
209 | + } else { |
|
210 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
196 | 211 | } |
197 | - else |
|
198 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
199 | 212 | break; |
200 | 213 | |
201 | 214 | case 'date': |
202 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
203 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
204 | - else |
|
205 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
215 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
216 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
217 | + } else { |
|
218 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
219 | + } |
|
206 | 220 | break; |
207 | 221 | |
208 | 222 | case 'time': |
209 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
210 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
211 | - else |
|
212 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
223 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
224 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
225 | + } else { |
|
226 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
227 | + } |
|
213 | 228 | break; |
214 | 229 | |
215 | 230 | case 'datetime': |
216 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
217 | - return 'to_timestamp('. |
|
231 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
232 | + return 'to_timestamp('. |
|
218 | 233 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
219 | 234 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
220 | - else |
|
221 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
235 | + } else { |
|
236 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
237 | + } |
|
222 | 238 | break; |
223 | 239 | |
224 | 240 | case 'float': |
225 | - if (!is_numeric($replacement)) |
|
226 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
241 | + if (!is_numeric($replacement)) { |
|
242 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
243 | + } |
|
227 | 244 | return (string) (float) $replacement; |
228 | 245 | break; |
229 | 246 | |
@@ -236,31 +253,36 @@ discard block |
||
236 | 253 | break; |
237 | 254 | |
238 | 255 | case 'inet': |
239 | - if ($replacement == 'null' || $replacement == '') |
|
240 | - return 'null'; |
|
241 | - if (inet_pton($replacement) === false) |
|
242 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
256 | + if ($replacement == 'null' || $replacement == '') { |
|
257 | + return 'null'; |
|
258 | + } |
|
259 | + if (inet_pton($replacement) === false) { |
|
260 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
261 | + } |
|
243 | 262 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
244 | 263 | |
245 | 264 | case 'array_inet': |
246 | 265 | if (is_array($replacement)) |
247 | 266 | { |
248 | - if (empty($replacement)) |
|
249 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
267 | + if (empty($replacement)) { |
|
268 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
269 | + } |
|
250 | 270 | |
251 | 271 | foreach ($replacement as $key => $value) |
252 | 272 | { |
253 | - if ($replacement == 'null' || $replacement == '') |
|
254 | - $replacement[$key] = 'null'; |
|
255 | - if (!isValidIP($value)) |
|
256 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
273 | + if ($replacement == 'null' || $replacement == '') { |
|
274 | + $replacement[$key] = 'null'; |
|
275 | + } |
|
276 | + if (!isValidIP($value)) { |
|
277 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
278 | + } |
|
257 | 279 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
258 | 280 | } |
259 | 281 | |
260 | 282 | return implode(', ', $replacement); |
283 | + } else { |
|
284 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
261 | 285 | } |
262 | - else |
|
263 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
264 | 286 | break; |
265 | 287 | |
266 | 288 | default: |
@@ -351,14 +373,16 @@ discard block |
||
351 | 373 | ) |
352 | 374 | ); |
353 | 375 | |
354 | - if (isset($replacements[$identifier])) |
|
355 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
376 | + if (isset($replacements[$identifier])) { |
|
377 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
378 | + } |
|
356 | 379 | |
357 | 380 | // Limits need to be a little different. |
358 | 381 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
359 | 382 | |
360 | - if (trim($db_string) == '') |
|
361 | - return false; |
|
383 | + if (trim($db_string) == '') { |
|
384 | + return false; |
|
385 | + } |
|
362 | 386 | |
363 | 387 | // Comments that are allowed in a query are preg_removed. |
364 | 388 | static $allowed_comments_from = array( |
@@ -378,8 +402,9 @@ discard block |
||
378 | 402 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
379 | 403 | $db_replace_result = 0; |
380 | 404 | |
381 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
382 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
405 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
406 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
407 | + } |
|
383 | 408 | |
384 | 409 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
385 | 410 | { |
@@ -400,8 +425,9 @@ discard block |
||
400 | 425 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
401 | 426 | |
402 | 427 | // Initialize $db_cache if not already initialized. |
403 | - if (!isset($db_cache)) |
|
404 | - $db_cache = array(); |
|
428 | + if (!isset($db_cache)) { |
|
429 | + $db_cache = array(); |
|
430 | + } |
|
405 | 431 | |
406 | 432 | if (!empty($_SESSION['debug_redirect'])) |
407 | 433 | { |
@@ -427,17 +453,18 @@ discard block |
||
427 | 453 | while (true) |
428 | 454 | { |
429 | 455 | $pos = strpos($db_string, '\'', $pos + 1); |
430 | - if ($pos === false) |
|
431 | - break; |
|
456 | + if ($pos === false) { |
|
457 | + break; |
|
458 | + } |
|
432 | 459 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
433 | 460 | |
434 | 461 | while (true) |
435 | 462 | { |
436 | 463 | $pos1 = strpos($db_string, '\'', $pos + 1); |
437 | 464 | $pos2 = strpos($db_string, '\\', $pos + 1); |
438 | - if ($pos1 === false) |
|
439 | - break; |
|
440 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
465 | + if ($pos1 === false) { |
|
466 | + break; |
|
467 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
441 | 468 | { |
442 | 469 | $pos = $pos1; |
443 | 470 | break; |
@@ -453,16 +480,19 @@ discard block |
||
453 | 480 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
454 | 481 | |
455 | 482 | // Comments? We don't use comments in our queries, we leave 'em outside! |
456 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
457 | - $fail = true; |
|
483 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
484 | + $fail = true; |
|
485 | + } |
|
458 | 486 | // Trying to change passwords, slow us down, or something? |
459 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
460 | - $fail = true; |
|
461 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
462 | - $fail = true; |
|
487 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
488 | + $fail = true; |
|
489 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
490 | + $fail = true; |
|
491 | + } |
|
463 | 492 | |
464 | - if (!empty($fail) && function_exists('log_error')) |
|
465 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
493 | + if (!empty($fail) && function_exists('log_error')) { |
|
494 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
495 | + } |
|
466 | 496 | } |
467 | 497 | |
468 | 498 | // Set optimize stuff |
@@ -484,15 +514,18 @@ discard block |
||
484 | 514 | $db_last_result = @pg_query($connection, $db_string); |
485 | 515 | |
486 | 516 | // Remove optimiz settings |
487 | - if (isset($query_hints_undo)) |
|
488 | - @pg_query($connection, $query_hints_undo); |
|
517 | + if (isset($query_hints_undo)) { |
|
518 | + @pg_query($connection, $query_hints_undo); |
|
519 | + } |
|
489 | 520 | |
490 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
491 | - $db_last_result = smf_db_error($db_string, $connection); |
|
521 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
522 | + $db_last_result = smf_db_error($db_string, $connection); |
|
523 | + } |
|
492 | 524 | |
493 | 525 | // Debugging. |
494 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
495 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
526 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
527 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
528 | + } |
|
496 | 529 | |
497 | 530 | return $db_last_result; |
498 | 531 | } |
@@ -505,10 +538,11 @@ discard block |
||
505 | 538 | { |
506 | 539 | global $db_last_result, $db_replace_result; |
507 | 540 | |
508 | - if ($db_replace_result) |
|
509 | - return $db_replace_result; |
|
510 | - elseif ($result === null && !$db_last_result) |
|
511 | - return 0; |
|
541 | + if ($db_replace_result) { |
|
542 | + return $db_replace_result; |
|
543 | + } elseif ($result === null && !$db_last_result) { |
|
544 | + return 0; |
|
545 | + } |
|
512 | 546 | |
513 | 547 | return pg_affected_rows($result === null ? $db_last_result : $result); |
514 | 548 | } |
@@ -532,8 +566,9 @@ discard block |
||
532 | 566 | array( |
533 | 567 | ) |
534 | 568 | ); |
535 | - if (!$request) |
|
536 | - return false; |
|
569 | + if (!$request) { |
|
570 | + return false; |
|
571 | + } |
|
537 | 572 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
538 | 573 | $smcFunc['db_free_result']($request); |
539 | 574 | |
@@ -554,12 +589,13 @@ discard block |
||
554 | 589 | // Decide which connection to use |
555 | 590 | $connection = $connection === null ? $db_connection : $connection; |
556 | 591 | |
557 | - if ($type == 'begin') |
|
558 | - return @pg_query($connection, 'BEGIN'); |
|
559 | - elseif ($type == 'rollback') |
|
560 | - return @pg_query($connection, 'ROLLBACK'); |
|
561 | - elseif ($type == 'commit') |
|
562 | - return @pg_query($connection, 'COMMIT'); |
|
592 | + if ($type == 'begin') { |
|
593 | + return @pg_query($connection, 'BEGIN'); |
|
594 | + } elseif ($type == 'rollback') { |
|
595 | + return @pg_query($connection, 'ROLLBACK'); |
|
596 | + } elseif ($type == 'commit') { |
|
597 | + return @pg_query($connection, 'COMMIT'); |
|
598 | + } |
|
563 | 599 | |
564 | 600 | return false; |
565 | 601 | } |
@@ -587,19 +623,22 @@ discard block |
||
587 | 623 | $query_error = @pg_last_error($connection); |
588 | 624 | |
589 | 625 | // Log the error. |
590 | - if (function_exists('log_error')) |
|
591 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
626 | + if (function_exists('log_error')) { |
|
627 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
628 | + } |
|
592 | 629 | |
593 | 630 | // Nothing's defined yet... just die with it. |
594 | - if (empty($context) || empty($txt)) |
|
595 | - die($query_error); |
|
631 | + if (empty($context) || empty($txt)) { |
|
632 | + die($query_error); |
|
633 | + } |
|
596 | 634 | |
597 | 635 | // Show an error message, if possible. |
598 | 636 | $context['error_title'] = $txt['database_error']; |
599 | - if (allowedTo('admin_forum')) |
|
600 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
601 | - else |
|
602 | - $context['error_message'] = $txt['try_again']; |
|
637 | + if (allowedTo('admin_forum')) { |
|
638 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
639 | + } else { |
|
640 | + $context['error_message'] = $txt['try_again']; |
|
641 | + } |
|
603 | 642 | |
604 | 643 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
605 | 644 | { |
@@ -621,12 +660,14 @@ discard block |
||
621 | 660 | { |
622 | 661 | global $db_row_count; |
623 | 662 | |
624 | - if ($counter !== false) |
|
625 | - return pg_fetch_row($request, $counter); |
|
663 | + if ($counter !== false) { |
|
664 | + return pg_fetch_row($request, $counter); |
|
665 | + } |
|
626 | 666 | |
627 | 667 | // Reset the row counter... |
628 | - if (!isset($db_row_count[(int) $request])) |
|
629 | - $db_row_count[(int) $request] = 0; |
|
668 | + if (!isset($db_row_count[(int) $request])) { |
|
669 | + $db_row_count[(int) $request] = 0; |
|
670 | + } |
|
630 | 671 | |
631 | 672 | // Return the right row. |
632 | 673 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -643,12 +684,14 @@ discard block |
||
643 | 684 | { |
644 | 685 | global $db_row_count; |
645 | 686 | |
646 | - if ($counter !== false) |
|
647 | - return pg_fetch_assoc($request, $counter); |
|
687 | + if ($counter !== false) { |
|
688 | + return pg_fetch_assoc($request, $counter); |
|
689 | + } |
|
648 | 690 | |
649 | 691 | // Reset the row counter... |
650 | - if (!isset($db_row_count[(int) $request])) |
|
651 | - $db_row_count[(int) $request] = 0; |
|
692 | + if (!isset($db_row_count[(int) $request])) { |
|
693 | + $db_row_count[(int) $request] = 0; |
|
694 | + } |
|
652 | 695 | |
653 | 696 | // Return the right row. |
654 | 697 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -701,11 +744,13 @@ discard block |
||
701 | 744 | |
702 | 745 | $replace = ''; |
703 | 746 | |
704 | - if (empty($data)) |
|
705 | - return; |
|
747 | + if (empty($data)) { |
|
748 | + return; |
|
749 | + } |
|
706 | 750 | |
707 | - if (!is_array($data[array_rand($data)])) |
|
708 | - $data = array($data); |
|
751 | + if (!is_array($data[array_rand($data)])) { |
|
752 | + $data = array($data); |
|
753 | + } |
|
709 | 754 | |
710 | 755 | // Replace the prefix holder with the actual prefix. |
711 | 756 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -724,11 +769,13 @@ discard block |
||
724 | 769 | //pg 9.5 got replace support |
725 | 770 | $pg_version = $smcFunc['db_get_version'](); |
726 | 771 | // if we got a Beta Version |
727 | - if (stripos($pg_version, 'beta') !== false) |
|
728 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
772 | + if (stripos($pg_version, 'beta') !== false) { |
|
773 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
774 | + } |
|
729 | 775 | // or RC |
730 | - if (stripos($pg_version, 'rc') !== false) |
|
731 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
776 | + if (stripos($pg_version, 'rc') !== false) { |
|
777 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
778 | + } |
|
732 | 779 | |
733 | 780 | $replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false); |
734 | 781 | } |
@@ -747,8 +794,7 @@ discard block |
||
747 | 794 | $key_str .= ($count_pk > 0 ? ',' : ''); |
748 | 795 | $key_str .= $columnName; |
749 | 796 | $count_pk++; |
750 | - } |
|
751 | - else //normal field |
|
797 | + } else //normal field |
|
752 | 798 | { |
753 | 799 | $col_str .= ($count > 0 ? ',' : ''); |
754 | 800 | $col_str .= $columnName . ' = EXCLUDED.' . $columnName; |
@@ -756,20 +802,21 @@ discard block |
||
756 | 802 | } |
757 | 803 | } |
758 | 804 | $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
759 | - } |
|
760 | - else |
|
805 | + } else |
|
761 | 806 | { |
762 | 807 | foreach ($columns as $columnName => $type) |
763 | 808 | { |
764 | 809 | // Are we restricting the length? |
765 | - if (strpos($type, 'string-') !== false) |
|
766 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
767 | - else |
|
768 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
810 | + if (strpos($type, 'string-') !== false) { |
|
811 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
812 | + } else { |
|
813 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
814 | + } |
|
769 | 815 | |
770 | 816 | // A key? That's what we were looking for. |
771 | - if (in_array($columnName, $keys)) |
|
772 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
817 | + if (in_array($columnName, $keys)) { |
|
818 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
819 | + } |
|
773 | 820 | $count++; |
774 | 821 | } |
775 | 822 | |
@@ -805,10 +852,11 @@ discard block |
||
805 | 852 | foreach ($columns as $columnName => $type) |
806 | 853 | { |
807 | 854 | // Are we restricting the length? |
808 | - if (strpos($type, 'string-') !== false) |
|
809 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
810 | - else |
|
811 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
855 | + if (strpos($type, 'string-') !== false) { |
|
856 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
857 | + } else { |
|
858 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
859 | + } |
|
812 | 860 | } |
813 | 861 | $insertData = substr($insertData, 0, -2) . ')'; |
814 | 862 | |
@@ -817,8 +865,9 @@ discard block |
||
817 | 865 | |
818 | 866 | // Here's where the variables are injected to the query. |
819 | 867 | $insertRows = array(); |
820 | - foreach ($data as $dataRow) |
|
821 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
868 | + foreach ($data as $dataRow) { |
|
869 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
870 | + } |
|
822 | 871 | |
823 | 872 | // Do the insert. |
824 | 873 | $request = $smcFunc['db_query']('', ' |
@@ -835,19 +884,21 @@ discard block |
||
835 | 884 | |
836 | 885 | if ($with_returning && $request !== false) |
837 | 886 | { |
838 | - if ($returnmode === 2) |
|
839 | - $return_var = array(); |
|
887 | + if ($returnmode === 2) { |
|
888 | + $return_var = array(); |
|
889 | + } |
|
840 | 890 | |
841 | 891 | while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
842 | 892 | { |
843 | - if (is_numeric($row[0])) // try to emulate mysql limitation |
|
893 | + if (is_numeric($row[0])) { |
|
894 | + // try to emulate mysql limitation |
|
844 | 895 | { |
845 | 896 | if ($returnmode === 1) |
846 | 897 | $return_var = $row[0]; |
847 | - elseif ($returnmode === 2) |
|
848 | - $return_var[] = $row[0]; |
|
849 | - } |
|
850 | - else |
|
898 | + } elseif ($returnmode === 2) { |
|
899 | + $return_var[] = $row[0]; |
|
900 | + } |
|
901 | + } else |
|
851 | 902 | { |
852 | 903 | $with_returning = false; |
853 | 904 | trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR); |
@@ -856,9 +907,10 @@ discard block |
||
856 | 907 | } |
857 | 908 | } |
858 | 909 | |
859 | - if ($with_returning && !empty($return_var)) |
|
860 | - return $return_var; |
|
861 | -} |
|
910 | + if ($with_returning && !empty($return_var)) { |
|
911 | + return $return_var; |
|
912 | + } |
|
913 | + } |
|
862 | 914 | |
863 | 915 | /** |
864 | 916 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -895,8 +947,9 @@ discard block |
||
895 | 947 | */ |
896 | 948 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
897 | 949 | { |
898 | - if (empty($log_message)) |
|
899 | - $log_message = $error_message; |
|
950 | + if (empty($log_message)) { |
|
951 | + $log_message = $error_message; |
|
952 | + } |
|
900 | 953 | |
901 | 954 | foreach (debug_backtrace() as $step) |
902 | 955 | { |
@@ -915,12 +968,14 @@ discard block |
||
915 | 968 | } |
916 | 969 | |
917 | 970 | // A special case - we want the file and line numbers for debugging. |
918 | - if ($error_type == 'return') |
|
919 | - return array($file, $line); |
|
971 | + if ($error_type == 'return') { |
|
972 | + return array($file, $line); |
|
973 | + } |
|
920 | 974 | |
921 | 975 | // Is always a critical error. |
922 | - if (function_exists('log_error')) |
|
923 | - log_error($log_message, 'critical', $file, $line); |
|
976 | + if (function_exists('log_error')) { |
|
977 | + log_error($log_message, 'critical', $file, $line); |
|
978 | + } |
|
924 | 979 | |
925 | 980 | if (function_exists('fatal_error')) |
926 | 981 | { |
@@ -928,12 +983,12 @@ discard block |
||
928 | 983 | |
929 | 984 | // Cannot continue... |
930 | 985 | exit; |
986 | + } elseif ($error_type) { |
|
987 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
988 | + } else { |
|
989 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
990 | + } |
|
931 | 991 | } |
932 | - elseif ($error_type) |
|
933 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
934 | - else |
|
935 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
936 | -} |
|
937 | 992 | |
938 | 993 | /** |
939 | 994 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -950,10 +1005,11 @@ discard block |
||
950 | 1005 | '\\' => '\\\\', |
951 | 1006 | ); |
952 | 1007 | |
953 | - if ($translate_human_wildcards) |
|
954 | - $replacements += array( |
|
1008 | + if ($translate_human_wildcards) { |
|
1009 | + $replacements += array( |
|
955 | 1010 | '*' => '%', |
956 | 1011 | ); |
1012 | + } |
|
957 | 1013 | |
958 | 1014 | return strtr($string, $replacements); |
959 | 1015 | } |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | if (empty($low_id)) |
600 | 600 | $pageindex .= $start == 0 ? ' ' : sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
601 | 601 | else |
602 | - $pageindex .= $start == 0 ? ' ' : sprintf($base_link_page, ($start - $num_per_page), $settings['page_index']['previous_page'], 'L'.$low_id); |
|
602 | + $pageindex .= $start == 0 ? ' ' : sprintf($base_link_page, ($start - $num_per_page), $settings['page_index']['previous_page'], 'L' . $low_id); |
|
603 | 603 | |
604 | 604 | // Show all the pages. |
605 | 605 | $display_page = 1; |
@@ -608,11 +608,11 @@ discard block |
||
608 | 608 | |
609 | 609 | // Show the right arrow. |
610 | 610 | $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page); |
611 | - if ($start != $counter - $max_value && !$start_invalid){ |
|
611 | + if ($start != $counter - $max_value && !$start_invalid) { |
|
612 | 612 | if (empty($max_id)) |
613 | 613 | $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
614 | 614 | else |
615 | - $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link_page, $display_page , $settings['page_index']['next_page'], 'M'.$max_id); |
|
615 | + $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link_page, $display_page, $settings['page_index']['next_page'], 'M' . $max_id); |
|
616 | 616 | } |
617 | 617 | |
618 | 618 | } |
@@ -626,7 +626,7 @@ discard block |
||
626 | 626 | if (empty($low_id)) |
627 | 627 | $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
628 | 628 | else |
629 | - $pageindex .= sprintf($base_link_page, $start - $num_per_page, $settings['page_index']['previous_page'], 'L'.$low_id); |
|
629 | + $pageindex .= sprintf($base_link_page, $start - $num_per_page, $settings['page_index']['previous_page'], 'L' . $low_id); |
|
630 | 630 | else |
631 | 631 | $pageindex .= ''; |
632 | 632 | |
@@ -648,10 +648,10 @@ discard block |
||
648 | 648 | if ($start >= $num_per_page * $nCont) |
649 | 649 | { |
650 | 650 | $tmpStart = $start - $num_per_page * $nCont; |
651 | - if($nCont != 1 || empty($low_id)) |
|
651 | + if ($nCont != 1 || empty($low_id)) |
|
652 | 652 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
653 | 653 | else |
654 | - $pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'L'.$low_id); |
|
654 | + $pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'L' . $low_id); |
|
655 | 655 | } |
656 | 656 | |
657 | 657 | // Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page) |
@@ -666,10 +666,10 @@ discard block |
||
666 | 666 | if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
667 | 667 | { |
668 | 668 | $tmpStart = $start + $num_per_page * $nCont; |
669 | - if($nCont != 1 || empty($max_id)) |
|
669 | + if ($nCont != 1 || empty($max_id)) |
|
670 | 670 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
671 | 671 | else |
672 | - $pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'M'.$max_id); |
|
672 | + $pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'M' . $max_id); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | // Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page) |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | if (empty($max_id)) |
691 | 691 | $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
692 | 692 | else |
693 | - $pageindex .= sprintf($base_link_page, $start + $num_per_page, $settings['page_index']['next_page'], 'M'.$max_id); |
|
693 | + $pageindex .= sprintf($base_link_page, $start + $num_per_page, $settings['page_index']['next_page'], 'M' . $max_id); |
|
694 | 694 | } |
695 | 695 | $pageindex .= $settings['page_index']['extra_after']; |
696 | 696 | |
@@ -1125,7 +1125,7 @@ discard block |
||
1125 | 1125 | 'height' => array('optional' => true, 'match' => '(\d+)'), |
1126 | 1126 | ), |
1127 | 1127 | 'content' => '$1', |
1128 | - 'validate' => function (&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt) |
|
1128 | + 'validate' => function(&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt) |
|
1129 | 1129 | { |
1130 | 1130 | $returnContext = ''; |
1131 | 1131 | |
@@ -1160,7 +1160,7 @@ discard block |
||
1160 | 1160 | } |
1161 | 1161 | |
1162 | 1162 | if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) |
1163 | - $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>'; |
|
1163 | + $returnContext .= '<a href="' . $currentAttachment['href'] . ';image" id="link_' . $currentAttachment['id'] . '" onclick="' . $currentAttachment['thumbnail']['javascript'] . '"><img src="' . $currentAttachment['thumbnail']['href'] . '"' . $alt . $title . ' id="thumb_' . $currentAttachment['id'] . '" class="atc_img"></a>'; |
|
1164 | 1164 | else |
1165 | 1165 | $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
1166 | 1166 | } |
@@ -1189,7 +1189,7 @@ discard block |
||
1189 | 1189 | 'type' => 'unparsed_content', |
1190 | 1190 | 'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>', |
1191 | 1191 | // @todo Maybe this can be simplified? |
1192 | - 'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context) |
|
1192 | + 'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context) |
|
1193 | 1193 | { |
1194 | 1194 | if (!isset($disabled['code'])) |
1195 | 1195 | { |
@@ -1226,7 +1226,7 @@ discard block |
||
1226 | 1226 | 'type' => 'unparsed_equals_content', |
1227 | 1227 | 'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> ($2) <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>', |
1228 | 1228 | // @todo Maybe this can be simplified? |
1229 | - 'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context) |
|
1229 | + 'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context) |
|
1230 | 1230 | { |
1231 | 1231 | if (!isset($disabled['code'])) |
1232 | 1232 | { |
@@ -1270,7 +1270,7 @@ discard block |
||
1270 | 1270 | 'type' => 'unparsed_content', |
1271 | 1271 | 'content' => '<a href="mailto:$1" class="bbc_email">$1</a>', |
1272 | 1272 | // @todo Should this respect guest_hideContacts? |
1273 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1273 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1274 | 1274 | { |
1275 | 1275 | $data = strtr($data, array('<br>' => '')); |
1276 | 1276 | }, |
@@ -1289,7 +1289,7 @@ discard block |
||
1289 | 1289 | 'type' => 'unparsed_commas_content', |
1290 | 1290 | 'test' => '\d+,\d+\]', |
1291 | 1291 | 'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">', |
1292 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1292 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1293 | 1293 | { |
1294 | 1294 | if (isset($disabled['url'])) |
1295 | 1295 | $tag['content'] = '$1'; |
@@ -1305,7 +1305,7 @@ discard block |
||
1305 | 1305 | 'test' => '(left|right)(\s+max=\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)?\]', |
1306 | 1306 | 'before' => '<div $1>', |
1307 | 1307 | 'after' => '</div>', |
1308 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1308 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1309 | 1309 | { |
1310 | 1310 | $class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"'; |
1311 | 1311 | |
@@ -1354,7 +1354,7 @@ discard block |
||
1354 | 1354 | 'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'), |
1355 | 1355 | ), |
1356 | 1356 | 'content' => '<img src="$1" alt="{alt}" title="{title}"{width}{height} class="bbc_img resized">', |
1357 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1357 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1358 | 1358 | { |
1359 | 1359 | global $image_proxy_enabled, $image_proxy_secret, $boardurl; |
1360 | 1360 | |
@@ -1377,7 +1377,7 @@ discard block |
||
1377 | 1377 | 'tag' => 'img', |
1378 | 1378 | 'type' => 'unparsed_content', |
1379 | 1379 | 'content' => '<img src="$1" alt="" class="bbc_img">', |
1380 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1380 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1381 | 1381 | { |
1382 | 1382 | global $image_proxy_enabled, $image_proxy_secret, $boardurl; |
1383 | 1383 | |
@@ -1400,7 +1400,7 @@ discard block |
||
1400 | 1400 | 'tag' => 'iurl', |
1401 | 1401 | 'type' => 'unparsed_content', |
1402 | 1402 | 'content' => '<a href="$1" class="bbc_link">$1</a>', |
1403 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1403 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1404 | 1404 | { |
1405 | 1405 | $data = strtr($data, array('<br>' => '')); |
1406 | 1406 | $scheme = parse_url($data, PHP_URL_SCHEME); |
@@ -1414,7 +1414,7 @@ discard block |
||
1414 | 1414 | 'quoted' => 'optional', |
1415 | 1415 | 'before' => '<a href="$1" class="bbc_link">', |
1416 | 1416 | 'after' => '</a>', |
1417 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1417 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1418 | 1418 | { |
1419 | 1419 | if (substr($data, 0, 1) == '#') |
1420 | 1420 | $data = '#post_' . substr($data, 1); |
@@ -1494,7 +1494,7 @@ discard block |
||
1494 | 1494 | 'tag' => 'php', |
1495 | 1495 | 'type' => 'unparsed_content', |
1496 | 1496 | 'content' => '<span class="phpcode">$1</span>', |
1497 | - 'validate' => isset($disabled['php']) ? null : function (&$tag, &$data, $disabled) |
|
1497 | + 'validate' => isset($disabled['php']) ? null : function(&$tag, &$data, $disabled) |
|
1498 | 1498 | { |
1499 | 1499 | if (!isset($disabled['php'])) |
1500 | 1500 | { |
@@ -1592,7 +1592,7 @@ discard block |
||
1592 | 1592 | 'test' => '[1-7]\]', |
1593 | 1593 | 'before' => '<span style="font-size: $1;" class="bbc_size">', |
1594 | 1594 | 'after' => '</span>', |
1595 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1595 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1596 | 1596 | { |
1597 | 1597 | $sizes = array(1 => 0.7, 2 => 1.0, 3 => 1.35, 4 => 1.45, 5 => 2.0, 6 => 2.65, 7 => 3.95); |
1598 | 1598 | $data = $sizes[$data] . 'em'; |
@@ -1630,7 +1630,7 @@ discard block |
||
1630 | 1630 | 'tag' => 'time', |
1631 | 1631 | 'type' => 'unparsed_content', |
1632 | 1632 | 'content' => '$1', |
1633 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1633 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1634 | 1634 | { |
1635 | 1635 | if (is_numeric($data)) |
1636 | 1636 | $data = timeformat($data); |
@@ -1658,7 +1658,7 @@ discard block |
||
1658 | 1658 | 'tag' => 'url', |
1659 | 1659 | 'type' => 'unparsed_content', |
1660 | 1660 | 'content' => '<a href="$1" class="bbc_link" target="_blank">$1</a>', |
1661 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1661 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1662 | 1662 | { |
1663 | 1663 | $data = strtr($data, array('<br>' => '')); |
1664 | 1664 | $scheme = parse_url($data, PHP_URL_SCHEME); |
@@ -1672,7 +1672,7 @@ discard block |
||
1672 | 1672 | 'quoted' => 'optional', |
1673 | 1673 | 'before' => '<a href="$1" class="bbc_link" target="_blank">', |
1674 | 1674 | 'after' => '</a>', |
1675 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1675 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1676 | 1676 | { |
1677 | 1677 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1678 | 1678 | if (empty($scheme)) |
@@ -1698,7 +1698,7 @@ discard block |
||
1698 | 1698 | { |
1699 | 1699 | if (isset($temp_bbc)) |
1700 | 1700 | $bbc_codes = $temp_bbc; |
1701 | - usort($codes, function ($a, $b) { |
|
1701 | + usort($codes, function($a, $b) { |
|
1702 | 1702 | return strcmp($a['tag'], $b['tag']); |
1703 | 1703 | }); |
1704 | 1704 | return $codes; |
@@ -1936,7 +1936,7 @@ discard block |
||
1936 | 1936 | # a run of Unicode domain name characters and a dot |
1937 | 1937 | [\p{L}\p{M}\p{N}\-.:@]+\. |
1938 | 1938 | # and then a TLD valid in the DNS or the reserved "local" TLD |
1939 | - (?:'. $modSettings['tld_regex'] .'|local) |
|
1939 | + (?:'. $modSettings['tld_regex'] . '|local) |
|
1940 | 1940 | ) |
1941 | 1941 | # followed by a non-domain character or end of line |
1942 | 1942 | (?=[^\p{L}\p{N}\-.]|$) |
@@ -2004,7 +2004,7 @@ discard block |
||
2004 | 2004 | )? |
2005 | 2005 | '; |
2006 | 2006 | |
2007 | - $data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function ($matches) { |
|
2007 | + $data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function($matches) { |
|
2008 | 2008 | $url = array_shift($matches); |
2009 | 2009 | |
2010 | 2010 | $scheme = parse_url($url, PHP_URL_SCHEME); |
@@ -2741,7 +2741,7 @@ discard block |
||
2741 | 2741 | for ($i = 0, $n = count($smileysfrom); $i < $n; $i++) |
2742 | 2742 | { |
2743 | 2743 | $specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES); |
2744 | - $smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')). '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')) . '" class="smiley">'; |
|
2744 | + $smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')) . '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')) . '" class="smiley">'; |
|
2745 | 2745 | |
2746 | 2746 | $smileyPregReplacements[$smileysfrom[$i]] = $smileyCode; |
2747 | 2747 | |
@@ -2758,7 +2758,7 @@ discard block |
||
2758 | 2758 | |
2759 | 2759 | // Replace away! |
2760 | 2760 | $message = preg_replace_callback($smileyPregSearch, |
2761 | - function ($matches) use ($smileyPregReplacements) |
|
2761 | + function($matches) use ($smileyPregReplacements) |
|
2762 | 2762 | { |
2763 | 2763 | return $smileyPregReplacements[$matches[1]]; |
2764 | 2764 | }, $message); |
@@ -2824,13 +2824,13 @@ discard block |
||
2824 | 2824 | { |
2825 | 2825 | if (defined('SID') && SID != '') |
2826 | 2826 | $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
2827 | - function ($m) use ($scripturl) |
|
2827 | + function($m) use ($scripturl) |
|
2828 | 2828 | { |
2829 | - return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); |
|
2829 | + return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID . (isset($m[2]) ? "$m[2]" : ""); |
|
2830 | 2830 | }, $setLocation); |
2831 | 2831 | else |
2832 | 2832 | $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
2833 | - function ($m) use ($scripturl) |
|
2833 | + function($m) use ($scripturl) |
|
2834 | 2834 | { |
2835 | 2835 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); |
2836 | 2836 | }, $setLocation); |
@@ -3153,7 +3153,7 @@ discard block |
||
3153 | 3153 | |
3154 | 3154 | // Add a generic "Are you sure?" confirmation message. |
3155 | 3155 | addInlineJavaScript(' |
3156 | - var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); |
|
3156 | + var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) . ';'); |
|
3157 | 3157 | |
3158 | 3158 | // Now add the capping code for avatars. |
3159 | 3159 | if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') |
@@ -3514,7 +3514,7 @@ discard block |
||
3514 | 3514 | |
3515 | 3515 | else |
3516 | 3516 | echo ' |
3517 | - <script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>'; |
|
3517 | + <script src="', $settings['theme_url'], '/scripts/minified', ($do_deferred ? '_deferred' : ''), '.js', $minSeed, '"></script>'; |
|
3518 | 3518 | } |
3519 | 3519 | |
3520 | 3520 | // Inline JavaScript - Actually useful some times! |
@@ -3592,14 +3592,14 @@ discard block |
||
3592 | 3592 | |
3593 | 3593 | else |
3594 | 3594 | echo ' |
3595 | - <link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">'; |
|
3595 | + <link rel="stylesheet" href="', $settings['theme_url'], '/css/minified.css', $minSeed, '">'; |
|
3596 | 3596 | } |
3597 | 3597 | |
3598 | 3598 | // Print the rest after the minified files. |
3599 | 3599 | if (!empty($normal)) |
3600 | 3600 | foreach ($normal as $nf) |
3601 | 3601 | echo ' |
3602 | - <link rel="stylesheet" href="', $nf ,'">'; |
|
3602 | + <link rel="stylesheet" href="', $nf, '">'; |
|
3603 | 3603 | |
3604 | 3604 | if ($db_show_debug === true) |
3605 | 3605 | { |
@@ -3615,7 +3615,7 @@ discard block |
||
3615 | 3615 | <style>'; |
3616 | 3616 | |
3617 | 3617 | foreach ($context['css_header'] as $css) |
3618 | - echo $css .' |
|
3618 | + echo $css . ' |
|
3619 | 3619 | '; |
3620 | 3620 | |
3621 | 3621 | echo' |
@@ -3644,27 +3644,27 @@ discard block |
||
3644 | 3644 | return false; |
3645 | 3645 | |
3646 | 3646 | // Did we already did this? |
3647 | - $toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400); |
|
3647 | + $toCache = cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type, 86400); |
|
3648 | 3648 | |
3649 | 3649 | // Already done? |
3650 | 3650 | if (!empty($toCache)) |
3651 | 3651 | return true; |
3652 | 3652 | |
3653 | 3653 | // No namespaces, sorry! |
3654 | - $classType = 'MatthiasMullie\\Minify\\'. strtoupper($type); |
|
3654 | + $classType = 'MatthiasMullie\\Minify\\' . strtoupper($type); |
|
3655 | 3655 | |
3656 | 3656 | // Temp path. |
3657 | - $cTempPath = $settings['theme_dir'] .'/'. ($type == 'css' ? 'css' : 'scripts') .'/'; |
|
3657 | + $cTempPath = $settings['theme_dir'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/'; |
|
3658 | 3658 | |
3659 | 3659 | // What kind of file are we going to create? |
3660 | - $toCreate = $cTempPath .'minified'. ($do_deferred ? '_deferred' : '') .'.'. $type; |
|
3660 | + $toCreate = $cTempPath . 'minified' . ($do_deferred ? '_deferred' : '') . '.' . $type; |
|
3661 | 3661 | |
3662 | 3662 | // File has to exists, if it isn't try to create it. |
3663 | 3663 | if ((!file_exists($toCreate) && @fopen($toCreate, 'w') === false) || !smf_chmod($toCreate)) |
3664 | 3664 | { |
3665 | 3665 | loadLanguage('Errors'); |
3666 | 3666 | log_error(sprintf($txt['file_not_created'], $toCreate), 'general'); |
3667 | - cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, null); |
|
3667 | + cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, null); |
|
3668 | 3668 | |
3669 | 3669 | // The process failed so roll back to print each individual file. |
3670 | 3670 | return $data; |
@@ -3699,14 +3699,14 @@ discard block |
||
3699 | 3699 | { |
3700 | 3700 | loadLanguage('Errors'); |
3701 | 3701 | log_error(sprintf($txt['file_not_created'], $toCreate), 'general'); |
3702 | - cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, null); |
|
3702 | + cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, null); |
|
3703 | 3703 | |
3704 | 3704 | // The process failed so roll back to print each individual file. |
3705 | 3705 | return $data; |
3706 | 3706 | } |
3707 | 3707 | |
3708 | 3708 | // And create a long lived cache entry. |
3709 | - cache_put_data('minimized_'. $settings['theme_id'] .'_'. $type, $toCreate, 86400); |
|
3709 | + cache_put_data('minimized_' . $settings['theme_id'] . '_' . $type, $toCreate, 86400); |
|
3710 | 3710 | |
3711 | 3711 | return true; |
3712 | 3712 | } |
@@ -3766,7 +3766,7 @@ discard block |
||
3766 | 3766 | else |
3767 | 3767 | $path = $modSettings['attachmentUploadDir']; |
3768 | 3768 | |
3769 | - return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; |
|
3769 | + return $path . '/' . $attachment_id . '_' . $file_hash . '.dat'; |
|
3770 | 3770 | } |
3771 | 3771 | |
3772 | 3772 | /** |
@@ -3810,10 +3810,10 @@ discard block |
||
3810 | 3810 | $valid_low = isValidIP($ip_parts[0]); |
3811 | 3811 | $valid_high = isValidIP($ip_parts[1]); |
3812 | 3812 | $count = 0; |
3813 | - $mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); |
|
3813 | + $mode = (preg_match('/:/', $ip_parts[0]) > 0 ? ':' : '.'); |
|
3814 | 3814 | $max = ($mode == ':' ? 'ffff' : '255'); |
3815 | 3815 | $min = 0; |
3816 | - if(!$valid_low) |
|
3816 | + if (!$valid_low) |
|
3817 | 3817 | { |
3818 | 3818 | $ip_parts[0] = preg_replace('/\*/', '0', $ip_parts[0]); |
3819 | 3819 | $valid_low = isValidIP($ip_parts[0]); |
@@ -3827,7 +3827,7 @@ discard block |
||
3827 | 3827 | } |
3828 | 3828 | |
3829 | 3829 | $count = 0; |
3830 | - if(!$valid_high) |
|
3830 | + if (!$valid_high) |
|
3831 | 3831 | { |
3832 | 3832 | $ip_parts[1] = preg_replace('/\*/', $max, $ip_parts[1]); |
3833 | 3833 | $valid_high = isValidIP($ip_parts[1]); |
@@ -3840,7 +3840,7 @@ discard block |
||
3840 | 3840 | } |
3841 | 3841 | } |
3842 | 3842 | |
3843 | - if($valid_high && $valid_low) |
|
3843 | + if ($valid_high && $valid_low) |
|
3844 | 3844 | { |
3845 | 3845 | $ip_array['low'] = $ip_parts[0]; |
3846 | 3846 | $ip_array['high'] = $ip_parts[1]; |
@@ -4022,7 +4022,7 @@ discard block |
||
4022 | 4022 | addInlineJavaScript(' |
4023 | 4023 | var user_menus = new smc_PopupMenu(); |
4024 | 4024 | user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); |
4025 | - user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); |
|
4025 | + user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u=' . $context['user']['id'] . '");', true); |
|
4026 | 4026 | if ($context['allow_pm']) |
4027 | 4027 | addInlineJavaScript(' |
4028 | 4028 | user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); |
@@ -4644,7 +4644,7 @@ discard block |
||
4644 | 4644 | // No? try a fallback to $sourcedir |
4645 | 4645 | else |
4646 | 4646 | { |
4647 | - $absPath = $sourcedir .'/'. $file; |
|
4647 | + $absPath = $sourcedir . '/' . $file; |
|
4648 | 4648 | |
4649 | 4649 | if (file_exists($absPath)) |
4650 | 4650 | require_once($absPath); |
@@ -4725,15 +4725,15 @@ discard block |
||
4725 | 4725 | |
4726 | 4726 | // UTF-8 occurences of MS special characters |
4727 | 4727 | $findchars_utf8 = array( |
4728 | - "\xe2\x80\x9a", // single low-9 quotation mark |
|
4729 | - "\xe2\x80\x9e", // double low-9 quotation mark |
|
4730 | - "\xe2\x80\xa6", // horizontal ellipsis |
|
4731 | - "\xe2\x80\x98", // left single curly quote |
|
4732 | - "\xe2\x80\x99", // right single curly quote |
|
4733 | - "\xe2\x80\x9c", // left double curly quote |
|
4734 | - "\xe2\x80\x9d", // right double curly quote |
|
4735 | - "\xe2\x80\x93", // en dash |
|
4736 | - "\xe2\x80\x94", // em dash |
|
4728 | + "\xe2\x80\x9a", // single low-9 quotation mark |
|
4729 | + "\xe2\x80\x9e", // double low-9 quotation mark |
|
4730 | + "\xe2\x80\xa6", // horizontal ellipsis |
|
4731 | + "\xe2\x80\x98", // left single curly quote |
|
4732 | + "\xe2\x80\x99", // right single curly quote |
|
4733 | + "\xe2\x80\x9c", // left double curly quote |
|
4734 | + "\xe2\x80\x9d", // right double curly quote |
|
4735 | + "\xe2\x80\x93", // en dash |
|
4736 | + "\xe2\x80\x94", // em dash |
|
4737 | 4737 | ); |
4738 | 4738 | |
4739 | 4739 | // windows 1252 / iso equivalents |
@@ -4751,15 +4751,15 @@ discard block |
||
4751 | 4751 | |
4752 | 4752 | // safe replacements |
4753 | 4753 | $replacechars = array( |
4754 | - ',', // ‚ |
|
4755 | - ',,', // „ |
|
4756 | - '...', // … |
|
4757 | - "'", // ‘ |
|
4758 | - "'", // ’ |
|
4759 | - '"', // “ |
|
4760 | - '"', // ” |
|
4761 | - '-', // – |
|
4762 | - '--', // — |
|
4754 | + ',', // ‚ |
|
4755 | + ',,', // „ |
|
4756 | + '...', // … |
|
4757 | + "'", // ‘ |
|
4758 | + "'", // ’ |
|
4759 | + '"', // “ |
|
4760 | + '"', // ” |
|
4761 | + '-', // – |
|
4762 | + '--', // — |
|
4763 | 4763 | ); |
4764 | 4764 | |
4765 | 4765 | if ($context['utf8']) |
@@ -5177,7 +5177,7 @@ discard block |
||
5177 | 5177 | */ |
5178 | 5178 | function inet_dtop($bin) |
5179 | 5179 | { |
5180 | - if(empty($bin)) |
|
5180 | + if (empty($bin)) |
|
5181 | 5181 | return ''; |
5182 | 5182 | |
5183 | 5183 | global $db_type; |
@@ -5208,28 +5208,28 @@ discard block |
||
5208 | 5208 | */ |
5209 | 5209 | function _safe_serialize($value) |
5210 | 5210 | { |
5211 | - if(is_null($value)) |
|
5211 | + if (is_null($value)) |
|
5212 | 5212 | return 'N;'; |
5213 | 5213 | |
5214 | - if(is_bool($value)) |
|
5215 | - return 'b:'. (int) $value .';'; |
|
5214 | + if (is_bool($value)) |
|
5215 | + return 'b:' . (int) $value . ';'; |
|
5216 | 5216 | |
5217 | - if(is_int($value)) |
|
5218 | - return 'i:'. $value .';'; |
|
5217 | + if (is_int($value)) |
|
5218 | + return 'i:' . $value . ';'; |
|
5219 | 5219 | |
5220 | - if(is_float($value)) |
|
5221 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
5220 | + if (is_float($value)) |
|
5221 | + return 'd:' . str_replace(',', '.', $value) . ';'; |
|
5222 | 5222 | |
5223 | - if(is_string($value)) |
|
5224 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
5223 | + if (is_string($value)) |
|
5224 | + return 's:' . strlen($value) . ':"' . $value . '";'; |
|
5225 | 5225 | |
5226 | - if(is_array($value)) |
|
5226 | + if (is_array($value)) |
|
5227 | 5227 | { |
5228 | 5228 | $out = ''; |
5229 | - foreach($value as $k => $v) |
|
5229 | + foreach ($value as $k => $v) |
|
5230 | 5230 | $out .= _safe_serialize($k) . _safe_serialize($v); |
5231 | 5231 | |
5232 | - return 'a:'. count($value) .':{'. $out .'}'; |
|
5232 | + return 'a:' . count($value) . ':{' . $out . '}'; |
|
5233 | 5233 | } |
5234 | 5234 | |
5235 | 5235 | // safe_serialize cannot serialize resources or objects. |
@@ -5271,7 +5271,7 @@ discard block |
||
5271 | 5271 | function _safe_unserialize($str) |
5272 | 5272 | { |
5273 | 5273 | // Input is not a string. |
5274 | - if(empty($str) || !is_string($str)) |
|
5274 | + if (empty($str) || !is_string($str)) |
|
5275 | 5275 | return false; |
5276 | 5276 | |
5277 | 5277 | $stack = array(); |
@@ -5285,40 +5285,40 @@ discard block |
||
5285 | 5285 | * 3 - in array, expecting value or another array |
5286 | 5286 | */ |
5287 | 5287 | $state = 0; |
5288 | - while($state != 1) |
|
5288 | + while ($state != 1) |
|
5289 | 5289 | { |
5290 | 5290 | $type = isset($str[0]) ? $str[0] : ''; |
5291 | - if($type == '}') |
|
5291 | + if ($type == '}') |
|
5292 | 5292 | $str = substr($str, 1); |
5293 | 5293 | |
5294 | - else if($type == 'N' && $str[1] == ';') |
|
5294 | + else if ($type == 'N' && $str[1] == ';') |
|
5295 | 5295 | { |
5296 | 5296 | $value = null; |
5297 | 5297 | $str = substr($str, 2); |
5298 | 5298 | } |
5299 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
5299 | + else if ($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
5300 | 5300 | { |
5301 | 5301 | $value = $matches[1] == '1' ? true : false; |
5302 | 5302 | $str = substr($str, 4); |
5303 | 5303 | } |
5304 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
5304 | + else if ($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
5305 | 5305 | { |
5306 | - $value = (int)$matches[1]; |
|
5306 | + $value = (int) $matches[1]; |
|
5307 | 5307 | $str = $matches[2]; |
5308 | 5308 | } |
5309 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
5309 | + else if ($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
5310 | 5310 | { |
5311 | - $value = (float)$matches[1]; |
|
5311 | + $value = (float) $matches[1]; |
|
5312 | 5312 | $str = $matches[3]; |
5313 | 5313 | } |
5314 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
5314 | + else if ($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int) $matches[1], 2) == '";') |
|
5315 | 5315 | { |
5316 | - $value = substr($matches[2], 0, (int)$matches[1]); |
|
5317 | - $str = substr($matches[2], (int)$matches[1] + 2); |
|
5316 | + $value = substr($matches[2], 0, (int) $matches[1]); |
|
5317 | + $str = substr($matches[2], (int) $matches[1] + 2); |
|
5318 | 5318 | } |
5319 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
5319 | + else if ($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
5320 | 5320 | { |
5321 | - $expectedLength = (int)$matches[1]; |
|
5321 | + $expectedLength = (int) $matches[1]; |
|
5322 | 5322 | $str = $matches[2]; |
5323 | 5323 | } |
5324 | 5324 | |
@@ -5326,10 +5326,10 @@ discard block |
||
5326 | 5326 | else |
5327 | 5327 | return false; |
5328 | 5328 | |
5329 | - switch($state) |
|
5329 | + switch ($state) |
|
5330 | 5330 | { |
5331 | 5331 | case 3: // In array, expecting value or another array. |
5332 | - if($type == 'a') |
|
5332 | + if ($type == 'a') |
|
5333 | 5333 | { |
5334 | 5334 | $stack[] = &$list; |
5335 | 5335 | $list[$key] = array(); |
@@ -5338,7 +5338,7 @@ discard block |
||
5338 | 5338 | $state = 2; |
5339 | 5339 | break; |
5340 | 5340 | } |
5341 | - if($type != '}') |
|
5341 | + if ($type != '}') |
|
5342 | 5342 | { |
5343 | 5343 | $list[$key] = $value; |
5344 | 5344 | $state = 2; |
@@ -5349,29 +5349,29 @@ discard block |
||
5349 | 5349 | return false; |
5350 | 5350 | |
5351 | 5351 | case 2: // in array, expecting end of array or a key |
5352 | - if($type == '}') |
|
5352 | + if ($type == '}') |
|
5353 | 5353 | { |
5354 | 5354 | // Array size is less than expected. |
5355 | - if(count($list) < end($expected)) |
|
5355 | + if (count($list) < end($expected)) |
|
5356 | 5356 | return false; |
5357 | 5357 | |
5358 | 5358 | unset($list); |
5359 | - $list = &$stack[count($stack)-1]; |
|
5359 | + $list = &$stack[count($stack) - 1]; |
|
5360 | 5360 | array_pop($stack); |
5361 | 5361 | |
5362 | 5362 | // Go to terminal state if we're at the end of the root array. |
5363 | 5363 | array_pop($expected); |
5364 | 5364 | |
5365 | - if(count($expected) == 0) |
|
5365 | + if (count($expected) == 0) |
|
5366 | 5366 | $state = 1; |
5367 | 5367 | |
5368 | 5368 | break; |
5369 | 5369 | } |
5370 | 5370 | |
5371 | - if($type == 'i' || $type == 's') |
|
5371 | + if ($type == 'i' || $type == 's') |
|
5372 | 5372 | { |
5373 | 5373 | // Array size exceeds expected length. |
5374 | - if(count($list) >= end($expected)) |
|
5374 | + if (count($list) >= end($expected)) |
|
5375 | 5375 | return false; |
5376 | 5376 | |
5377 | 5377 | $key = $value; |
@@ -5384,7 +5384,7 @@ discard block |
||
5384 | 5384 | |
5385 | 5385 | // Expecting array or value. |
5386 | 5386 | case 0: |
5387 | - if($type == 'a') |
|
5387 | + if ($type == 'a') |
|
5388 | 5388 | { |
5389 | 5389 | $data = array(); |
5390 | 5390 | $list = &$data; |
@@ -5393,7 +5393,7 @@ discard block |
||
5393 | 5393 | break; |
5394 | 5394 | } |
5395 | 5395 | |
5396 | - if($type != '}') |
|
5396 | + if ($type != '}') |
|
5397 | 5397 | { |
5398 | 5398 | $data = $value; |
5399 | 5399 | $state = 1; |
@@ -5406,7 +5406,7 @@ discard block |
||
5406 | 5406 | } |
5407 | 5407 | |
5408 | 5408 | // Trailing data in input. |
5409 | - if(!empty($str)) |
|
5409 | + if (!empty($str)) |
|
5410 | 5410 | return false; |
5411 | 5411 | |
5412 | 5412 | return $data; |
@@ -5460,7 +5460,7 @@ discard block |
||
5460 | 5460 | // Set different modes. |
5461 | 5461 | $chmodValues = $isDir ? array(0750, 0755, 0775, 0777) : array(0644, 0664, 0666); |
5462 | 5462 | |
5463 | - foreach($chmodValues as $val) |
|
5463 | + foreach ($chmodValues as $val) |
|
5464 | 5464 | { |
5465 | 5465 | // If it's writable, break out of the loop. |
5466 | 5466 | if (is_writable($file)) |
@@ -5495,13 +5495,13 @@ discard block |
||
5495 | 5495 | $returnArray = @json_decode($json, $returnAsArray); |
5496 | 5496 | |
5497 | 5497 | // PHP 5.3 so no json_last_error_msg() |
5498 | - switch(json_last_error()) |
|
5498 | + switch (json_last_error()) |
|
5499 | 5499 | { |
5500 | 5500 | case JSON_ERROR_NONE: |
5501 | 5501 | $jsonError = false; |
5502 | 5502 | break; |
5503 | 5503 | case JSON_ERROR_DEPTH: |
5504 | - $jsonError = 'JSON_ERROR_DEPTH'; |
|
5504 | + $jsonError = 'JSON_ERROR_DEPTH'; |
|
5505 | 5505 | break; |
5506 | 5506 | case JSON_ERROR_STATE_MISMATCH: |
5507 | 5507 | $jsonError = 'JSON_ERROR_STATE_MISMATCH'; |
@@ -5529,10 +5529,10 @@ discard block |
||
5529 | 5529 | loadLanguage('Errors'); |
5530 | 5530 | |
5531 | 5531 | if (!empty($jsonDebug)) |
5532 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
5532 | + log_error($txt['json_' . $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
5533 | 5533 | |
5534 | 5534 | else |
5535 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
5535 | + log_error($txt['json_' . $jsonError], 'critical'); |
|
5536 | 5536 | |
5537 | 5537 | // Everyone expects an array. |
5538 | 5538 | return array(); |
@@ -5636,7 +5636,7 @@ discard block |
||
5636 | 5636 | }); |
5637 | 5637 | |
5638 | 5638 | // Convert Punycode to Unicode |
5639 | - $tlds = array_map(function ($input) { |
|
5639 | + $tlds = array_map(function($input) { |
|
5640 | 5640 | $prefix = 'xn--'; |
5641 | 5641 | $safe_char = 0xFFFC; |
5642 | 5642 | $base = 36; |
@@ -5652,7 +5652,7 @@ discard block |
||
5652 | 5652 | |
5653 | 5653 | foreach ($enco_parts as $encoded) |
5654 | 5654 | { |
5655 | - if (strpos($encoded,$prefix) !== 0 || strlen(trim(str_replace($prefix,'',$encoded))) == 0) |
|
5655 | + if (strpos($encoded, $prefix) !== 0 || strlen(trim(str_replace($prefix, '', $encoded))) == 0) |
|
5656 | 5656 | { |
5657 | 5657 | $output_parts[] = $encoded; |
5658 | 5658 | continue; |
@@ -5663,7 +5663,7 @@ discard block |
||
5663 | 5663 | $idx = 0; |
5664 | 5664 | $char = 0x80; |
5665 | 5665 | $decoded = array(); |
5666 | - $output=''; |
|
5666 | + $output = ''; |
|
5667 | 5667 | $delim_pos = strrpos($encoded, '-'); |
5668 | 5668 | |
5669 | 5669 | if ($delim_pos > strlen($prefix)) |
@@ -5679,7 +5679,7 @@ discard block |
||
5679 | 5679 | |
5680 | 5680 | for ($enco_idx = $delim_pos ? ($delim_pos + 1) : 0; $enco_idx < $enco_len; ++$deco_len) |
5681 | 5681 | { |
5682 | - for ($old_idx = $idx, $w = 1, $k = $base; 1 ; $k += $base) |
|
5682 | + for ($old_idx = $idx, $w = 1, $k = $base; 1; $k += $base) |
|
5683 | 5683 | { |
5684 | 5684 | $cp = ord($encoded{$enco_idx++}); |
5685 | 5685 | $digit = ($cp - 48 < 10) ? $cp - 22 : (($cp - 65 < 26) ? $cp - 65 : (($cp - 97 < 26) ? $cp - 97 : $base)); |
@@ -5720,15 +5720,15 @@ discard block |
||
5720 | 5720 | |
5721 | 5721 | // 2 bytes |
5722 | 5722 | elseif ($v < (1 << 11)) |
5723 | - $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
5723 | + $output .= chr(192 + ($v >> 6)) . chr(128 + ($v & 63)); |
|
5724 | 5724 | |
5725 | 5725 | // 3 bytes |
5726 | 5726 | elseif ($v < (1 << 16)) |
5727 | - $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
5727 | + $output .= chr(224 + ($v >> 12)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63)); |
|
5728 | 5728 | |
5729 | 5729 | // 4 bytes |
5730 | 5730 | elseif ($v < (1 << 21)) |
5731 | - $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
5731 | + $output .= chr(240 + ($v >> 18)) . chr(128 + (($v >> 12) & 63)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63)); |
|
5732 | 5732 | |
5733 | 5733 | // 'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k |
5734 | 5734 | else |
@@ -5835,7 +5835,7 @@ discard block |
||
5835 | 5835 | } |
5836 | 5836 | |
5837 | 5837 | // This recursive function creates the index array from the strings |
5838 | - $add_string_to_index = function ($string, $index) use (&$strlen, &$substr, &$add_string_to_index) |
|
5838 | + $add_string_to_index = function($string, $index) use (&$strlen, &$substr, &$add_string_to_index) |
|
5839 | 5839 | { |
5840 | 5840 | static $depth = 0; |
5841 | 5841 | $depth++; |
@@ -5862,7 +5862,7 @@ discard block |
||
5862 | 5862 | }; |
5863 | 5863 | |
5864 | 5864 | // This recursive function turns the index array into a regular expression |
5865 | - $index_to_regex = function (&$index, $delim) use (&$strlen, &$index_to_regex) |
|
5865 | + $index_to_regex = function(&$index, $delim) use (&$strlen, &$index_to_regex) |
|
5866 | 5866 | { |
5867 | 5867 | static $depth = 0; |
5868 | 5868 | $depth++; |
@@ -5886,11 +5886,11 @@ discard block |
||
5886 | 5886 | |
5887 | 5887 | if (count(array_keys($value)) == 1) |
5888 | 5888 | { |
5889 | - $new_key_array = explode('(?'.'>', $sub_regex); |
|
5889 | + $new_key_array = explode('(?' . '>', $sub_regex); |
|
5890 | 5890 | $new_key .= $new_key_array[0]; |
5891 | 5891 | } |
5892 | 5892 | else |
5893 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
5893 | + $sub_regex = '(?' . '>' . $sub_regex . ')'; |
|
5894 | 5894 | } |
5895 | 5895 | |
5896 | 5896 | if ($depth > 1) |
@@ -5930,7 +5930,7 @@ discard block |
||
5930 | 5930 | $index = $add_string_to_index($string, $index); |
5931 | 5931 | |
5932 | 5932 | while (!empty($index)) |
5933 | - $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
5933 | + $regexes[] = '(?' . '>' . $index_to_regex($index, $delim) . ')'; |
|
5934 | 5934 | |
5935 | 5935 | // Restore PHP's internal character encoding to whatever it was originally |
5936 | 5936 | if (!empty($current_encoding)) |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Update some basic statistics. |
@@ -122,10 +123,11 @@ discard block |
||
122 | 123 | $smcFunc['db_free_result']($result); |
123 | 124 | |
124 | 125 | // Add this to the number of unapproved members |
125 | - if (!empty($changes['unapprovedMembers'])) |
|
126 | - $changes['unapprovedMembers'] += $coppa_approvals; |
|
127 | - else |
|
128 | - $changes['unapprovedMembers'] = $coppa_approvals; |
|
126 | + if (!empty($changes['unapprovedMembers'])) { |
|
127 | + $changes['unapprovedMembers'] += $coppa_approvals; |
|
128 | + } else { |
|
129 | + $changes['unapprovedMembers'] = $coppa_approvals; |
|
130 | + } |
|
129 | 131 | } |
130 | 132 | } |
131 | 133 | } |
@@ -133,9 +135,9 @@ discard block |
||
133 | 135 | break; |
134 | 136 | |
135 | 137 | case 'message': |
136 | - if ($parameter1 === true && $parameter2 !== null) |
|
137 | - updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
138 | - else |
|
138 | + if ($parameter1 === true && $parameter2 !== null) { |
|
139 | + updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
140 | + } else |
|
139 | 141 | { |
140 | 142 | // SUM and MAX on a smaller table is better for InnoDB tables. |
141 | 143 | $result = $smcFunc['db_query']('', ' |
@@ -175,23 +177,25 @@ discard block |
||
175 | 177 | $parameter2 = text2words($parameter2); |
176 | 178 | |
177 | 179 | $inserts = array(); |
178 | - foreach ($parameter2 as $word) |
|
179 | - $inserts[] = array($word, $parameter1); |
|
180 | + foreach ($parameter2 as $word) { |
|
181 | + $inserts[] = array($word, $parameter1); |
|
182 | + } |
|
180 | 183 | |
181 | - if (!empty($inserts)) |
|
182 | - $smcFunc['db_insert']('ignore', |
|
184 | + if (!empty($inserts)) { |
|
185 | + $smcFunc['db_insert']('ignore', |
|
183 | 186 | '{db_prefix}log_search_subjects', |
184 | 187 | array('word' => 'string', 'id_topic' => 'int'), |
185 | 188 | $inserts, |
186 | 189 | array('word', 'id_topic') |
187 | 190 | ); |
191 | + } |
|
188 | 192 | } |
189 | 193 | break; |
190 | 194 | |
191 | 195 | case 'topic': |
192 | - if ($parameter1 === true) |
|
193 | - updateSettings(array('totalTopics' => true), true); |
|
194 | - else |
|
196 | + if ($parameter1 === true) { |
|
197 | + updateSettings(array('totalTopics' => true), true); |
|
198 | + } else |
|
195 | 199 | { |
196 | 200 | // Get the number of topics - a SUM is better for InnoDB tables. |
197 | 201 | // We also ignore the recycle bin here because there will probably be a bunch of one-post topics there. |
@@ -212,8 +216,9 @@ discard block |
||
212 | 216 | |
213 | 217 | case 'postgroups': |
214 | 218 | // Parameter two is the updated columns: we should check to see if we base groups off any of these. |
215 | - if ($parameter2 !== null && !in_array('posts', $parameter2)) |
|
216 | - return; |
|
219 | + if ($parameter2 !== null && !in_array('posts', $parameter2)) { |
|
220 | + return; |
|
221 | + } |
|
217 | 222 | |
218 | 223 | $postgroups = cache_get_data('updateStats:postgroups', 360); |
219 | 224 | if ($postgroups == null || $parameter1 == null) |
@@ -228,8 +233,9 @@ discard block |
||
228 | 233 | ) |
229 | 234 | ); |
230 | 235 | $postgroups = array(); |
231 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
232 | - $postgroups[$row['id_group']] = $row['min_posts']; |
|
236 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
237 | + $postgroups[$row['id_group']] = $row['min_posts']; |
|
238 | + } |
|
233 | 239 | $smcFunc['db_free_result']($request); |
234 | 240 | |
235 | 241 | // Sort them this way because if it's done with MySQL it causes a filesort :(. |
@@ -239,8 +245,9 @@ discard block |
||
239 | 245 | } |
240 | 246 | |
241 | 247 | // Oh great, they've screwed their post groups. |
242 | - if (empty($postgroups)) |
|
243 | - return; |
|
248 | + if (empty($postgroups)) { |
|
249 | + return; |
|
250 | + } |
|
244 | 251 | |
245 | 252 | // Set all membergroups from most posts to least posts. |
246 | 253 | $conditions = ''; |
@@ -298,10 +305,9 @@ discard block |
||
298 | 305 | { |
299 | 306 | $condition = 'id_member IN ({array_int:members})'; |
300 | 307 | $parameters['members'] = $members; |
301 | - } |
|
302 | - elseif ($members === null) |
|
303 | - $condition = '1=1'; |
|
304 | - else |
|
308 | + } elseif ($members === null) { |
|
309 | + $condition = '1=1'; |
|
310 | + } else |
|
305 | 311 | { |
306 | 312 | $condition = 'id_member = {int:member}'; |
307 | 313 | $parameters['member'] = $members; |
@@ -341,9 +347,9 @@ discard block |
||
341 | 347 | if (count($vars_to_integrate) != 0) |
342 | 348 | { |
343 | 349 | // Fetch a list of member_names if necessary |
344 | - if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) |
|
345 | - $member_names = array($user_info['username']); |
|
346 | - else |
|
350 | + if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) { |
|
351 | + $member_names = array($user_info['username']); |
|
352 | + } else |
|
347 | 353 | { |
348 | 354 | $member_names = array(); |
349 | 355 | $request = $smcFunc['db_query']('', ' |
@@ -352,14 +358,16 @@ discard block |
||
352 | 358 | WHERE ' . $condition, |
353 | 359 | $parameters |
354 | 360 | ); |
355 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
356 | - $member_names[] = $row['member_name']; |
|
361 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
362 | + $member_names[] = $row['member_name']; |
|
363 | + } |
|
357 | 364 | $smcFunc['db_free_result']($request); |
358 | 365 | } |
359 | 366 | |
360 | - if (!empty($member_names)) |
|
361 | - foreach ($vars_to_integrate as $var) |
|
367 | + if (!empty($member_names)) { |
|
368 | + foreach ($vars_to_integrate as $var) |
|
362 | 369 | call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats)); |
370 | + } |
|
363 | 371 | } |
364 | 372 | } |
365 | 373 | |
@@ -367,16 +375,17 @@ discard block |
||
367 | 375 | foreach ($data as $var => $val) |
368 | 376 | { |
369 | 377 | $type = 'string'; |
370 | - if (in_array($var, $knownInts)) |
|
371 | - $type = 'int'; |
|
372 | - elseif (in_array($var, $knownFloats)) |
|
373 | - $type = 'float'; |
|
374 | - elseif ($var == 'birthdate') |
|
375 | - $type = 'date'; |
|
376 | - elseif ($var == 'member_ip') |
|
377 | - $type = 'inet'; |
|
378 | - elseif ($var == 'member_ip2') |
|
379 | - $type = 'inet'; |
|
378 | + if (in_array($var, $knownInts)) { |
|
379 | + $type = 'int'; |
|
380 | + } elseif (in_array($var, $knownFloats)) { |
|
381 | + $type = 'float'; |
|
382 | + } elseif ($var == 'birthdate') { |
|
383 | + $type = 'date'; |
|
384 | + } elseif ($var == 'member_ip') { |
|
385 | + $type = 'inet'; |
|
386 | + } elseif ($var == 'member_ip2') { |
|
387 | + $type = 'inet'; |
|
388 | + } |
|
380 | 389 | |
381 | 390 | // Doing an increment? |
382 | 391 | if ($type == 'int' && ($val === '+' || $val === '-')) |
@@ -390,8 +399,9 @@ discard block |
||
390 | 399 | { |
391 | 400 | if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match)) |
392 | 401 | { |
393 | - if ($match[1] != '+ ') |
|
394 | - $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
402 | + if ($match[1] != '+ ') { |
|
403 | + $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
404 | + } |
|
395 | 405 | $type = 'raw'; |
396 | 406 | } |
397 | 407 | } |
@@ -412,8 +422,9 @@ discard block |
||
412 | 422 | // Clear any caching? |
413 | 423 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members)) |
414 | 424 | { |
415 | - if (!is_array($members)) |
|
416 | - $members = array($members); |
|
425 | + if (!is_array($members)) { |
|
426 | + $members = array($members); |
|
427 | + } |
|
417 | 428 | |
418 | 429 | foreach ($members as $member) |
419 | 430 | { |
@@ -446,29 +457,32 @@ discard block |
||
446 | 457 | { |
447 | 458 | global $modSettings, $smcFunc; |
448 | 459 | |
449 | - if (empty($changeArray) || !is_array($changeArray)) |
|
450 | - return; |
|
460 | + if (empty($changeArray) || !is_array($changeArray)) { |
|
461 | + return; |
|
462 | + } |
|
451 | 463 | |
452 | 464 | $toRemove = array(); |
453 | 465 | |
454 | 466 | // Go check if there is any setting to be removed. |
455 | - foreach ($changeArray as $k => $v) |
|
456 | - if ($v === null) |
|
467 | + foreach ($changeArray as $k => $v) { |
|
468 | + if ($v === null) |
|
457 | 469 | { |
458 | 470 | // Found some, remove them from the original array and add them to ours. |
459 | 471 | unset($changeArray[$k]); |
472 | + } |
|
460 | 473 | $toRemove[] = $k; |
461 | 474 | } |
462 | 475 | |
463 | 476 | // Proceed with the deletion. |
464 | - if (!empty($toRemove)) |
|
465 | - $smcFunc['db_query']('', ' |
|
477 | + if (!empty($toRemove)) { |
|
478 | + $smcFunc['db_query']('', ' |
|
466 | 479 | DELETE FROM {db_prefix}settings |
467 | 480 | WHERE variable IN ({array_string:remove})', |
468 | 481 | array( |
469 | 482 | 'remove' => $toRemove, |
470 | 483 | ) |
471 | 484 | ); |
485 | + } |
|
472 | 486 | |
473 | 487 | // In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs. |
474 | 488 | if ($update) |
@@ -497,19 +511,22 @@ discard block |
||
497 | 511 | foreach ($changeArray as $variable => $value) |
498 | 512 | { |
499 | 513 | // Don't bother if it's already like that ;). |
500 | - if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) |
|
501 | - continue; |
|
514 | + if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) { |
|
515 | + continue; |
|
516 | + } |
|
502 | 517 | // If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it. |
503 | - elseif (!isset($modSettings[$variable]) && empty($value)) |
|
504 | - continue; |
|
518 | + elseif (!isset($modSettings[$variable]) && empty($value)) { |
|
519 | + continue; |
|
520 | + } |
|
505 | 521 | |
506 | 522 | $replaceArray[] = array($variable, $value); |
507 | 523 | |
508 | 524 | $modSettings[$variable] = $value; |
509 | 525 | } |
510 | 526 | |
511 | - if (empty($replaceArray)) |
|
512 | - return; |
|
527 | + if (empty($replaceArray)) { |
|
528 | + return; |
|
529 | + } |
|
513 | 530 | |
514 | 531 | $smcFunc['db_insert']('replace', |
515 | 532 | '{db_prefix}settings', |
@@ -555,20 +572,25 @@ discard block |
||
555 | 572 | $start = (int) $start; |
556 | 573 | $start_invalid = $start < 0; |
557 | 574 | |
558 | - if (!empty($options['low_id'])) |
|
559 | - $low_id = $options['low_id']; |
|
560 | - if (!empty($options['max_id'])) |
|
561 | - $max_id = $options['max_id']; |
|
575 | + if (!empty($options['low_id'])) { |
|
576 | + $low_id = $options['low_id']; |
|
577 | + } |
|
578 | + if (!empty($options['max_id'])) { |
|
579 | + $max_id = $options['max_id']; |
|
580 | + } |
|
562 | 581 | |
563 | 582 | // Make sure $start is a proper variable - not less than 0. |
564 | - if ($start_invalid) |
|
565 | - $start = 0; |
|
583 | + if ($start_invalid) { |
|
584 | + $start = 0; |
|
585 | + } |
|
566 | 586 | // Not greater than the upper bound. |
567 | - elseif ($start >= $max_value) |
|
568 | - $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
587 | + elseif ($start >= $max_value) { |
|
588 | + $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
589 | + } |
|
569 | 590 | // And it has to be a multiple of $num_per_page! |
570 | - else |
|
571 | - $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
591 | + else { |
|
592 | + $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
593 | + } |
|
572 | 594 | |
573 | 595 | $context['current_page'] = $start / $num_per_page; |
574 | 596 | |
@@ -596,101 +618,115 @@ discard block |
||
596 | 618 | if (empty($modSettings['compactTopicPagesEnable'])) |
597 | 619 | { |
598 | 620 | // Show the left arrow. |
599 | - if (empty($low_id)) |
|
600 | - $pageindex .= $start == 0 ? ' ' : sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
601 | - else |
|
602 | - $pageindex .= $start == 0 ? ' ' : sprintf($base_link_page, ($start - $num_per_page), $settings['page_index']['previous_page'], 'L'.$low_id); |
|
621 | + if (empty($low_id)) { |
|
622 | + $pageindex .= $start == 0 ? ' ' : sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
623 | + } else { |
|
624 | + $pageindex .= $start == 0 ? ' ' : sprintf($base_link_page, ($start - $num_per_page), $settings['page_index']['previous_page'], 'L'.$low_id); |
|
625 | + } |
|
603 | 626 | |
604 | 627 | // Show all the pages. |
605 | 628 | $display_page = 1; |
606 | - for ($counter = 0; $counter < $max_value; $counter += $num_per_page) |
|
607 | - $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
629 | + for ($counter = 0; $counter < $max_value; $counter += $num_per_page) { |
|
630 | + $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
631 | + } |
|
608 | 632 | |
609 | 633 | // Show the right arrow. |
610 | 634 | $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page); |
611 | 635 | if ($start != $counter - $max_value && !$start_invalid){ |
612 | - if (empty($max_id)) |
|
613 | - $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
614 | - else |
|
615 | - $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link_page, $display_page , $settings['page_index']['next_page'], 'M'.$max_id); |
|
636 | + if (empty($max_id)) { |
|
637 | + $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
638 | + } else { |
|
639 | + $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link_page, $display_page , $settings['page_index']['next_page'], 'M'.$max_id); |
|
640 | + } |
|
616 | 641 | } |
617 | 642 | |
618 | - } |
|
619 | - else |
|
643 | + } else |
|
620 | 644 | { |
621 | 645 | // If they didn't enter an odd value, pretend they did. |
622 | 646 | $PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2; |
623 | 647 | |
624 | 648 | // Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page) |
625 | - if (!empty($start) && $show_prevnext) |
|
626 | - if (empty($low_id)) |
|
649 | + if (!empty($start) && $show_prevnext) { |
|
650 | + if (empty($low_id)) |
|
627 | 651 | $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
628 | - else |
|
629 | - $pageindex .= sprintf($base_link_page, $start - $num_per_page, $settings['page_index']['previous_page'], 'L'.$low_id); |
|
630 | - else |
|
631 | - $pageindex .= ''; |
|
652 | + } else { |
|
653 | + $pageindex .= sprintf($base_link_page, $start - $num_per_page, $settings['page_index']['previous_page'], 'L'.$low_id); |
|
654 | + } |
|
655 | + else { |
|
656 | + $pageindex .= ''; |
|
657 | + } |
|
632 | 658 | |
633 | 659 | // Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15) |
634 | - if ($start > $num_per_page * $PageContiguous) |
|
635 | - $pageindex .= sprintf($base_link, 0, '1'); |
|
660 | + if ($start > $num_per_page * $PageContiguous) { |
|
661 | + $pageindex .= sprintf($base_link, 0, '1'); |
|
662 | + } |
|
636 | 663 | |
637 | 664 | // Show the ... after the first page. (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page) |
638 | - if ($start > $num_per_page * ($PageContiguous + 1)) |
|
639 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
665 | + if ($start > $num_per_page * ($PageContiguous + 1)) { |
|
666 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
640 | 667 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
641 | 668 | '{FIRST_PAGE}' => $num_per_page, |
642 | 669 | '{LAST_PAGE}' => $start - $num_per_page * $PageContiguous, |
643 | 670 | '{PER_PAGE}' => $num_per_page, |
644 | 671 | )); |
672 | + } |
|
645 | 673 | |
646 | 674 | // Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page) |
647 | - for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) |
|
648 | - if ($start >= $num_per_page * $nCont) |
|
675 | + for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) { |
|
676 | + if ($start >= $num_per_page * $nCont) |
|
649 | 677 | { |
650 | 678 | $tmpStart = $start - $num_per_page * $nCont; |
651 | - if($nCont != 1 || empty($low_id)) |
|
652 | - $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
|
653 | - else |
|
654 | - $pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'L'.$low_id); |
|
679 | + } |
|
680 | + if($nCont != 1 || empty($low_id)) { |
|
681 | + $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
|
682 | + } else { |
|
683 | + $pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'L'.$low_id); |
|
684 | + } |
|
655 | 685 | } |
656 | 686 | |
657 | 687 | // Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page) |
658 | - if (!$start_invalid) |
|
659 | - $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
660 | - else |
|
661 | - $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
688 | + if (!$start_invalid) { |
|
689 | + $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
690 | + } else { |
|
691 | + $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
692 | + } |
|
662 | 693 | |
663 | 694 | // Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page) |
664 | 695 | $tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page; |
665 | - for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) |
|
666 | - if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
696 | + for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) { |
|
697 | + if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
667 | 698 | { |
668 | 699 | $tmpStart = $start + $num_per_page * $nCont; |
669 | - if($nCont != 1 || empty($max_id)) |
|
670 | - $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
|
671 | - else |
|
672 | - $pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'M'.$max_id); |
|
700 | + } |
|
701 | + if($nCont != 1 || empty($max_id)) { |
|
702 | + $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
|
703 | + } else { |
|
704 | + $pageindex .= sprintf($base_link_page, $tmpStart, $tmpStart / $num_per_page + 1, 'M'.$max_id); |
|
705 | + } |
|
673 | 706 | } |
674 | 707 | |
675 | 708 | // Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page) |
676 | - if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) |
|
677 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
709 | + if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) { |
|
710 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
678 | 711 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
679 | 712 | '{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1), |
680 | 713 | '{LAST_PAGE}' => $tmpMaxPages, |
681 | 714 | '{PER_PAGE}' => $num_per_page, |
682 | 715 | )); |
716 | + } |
|
683 | 717 | |
684 | 718 | // Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15< next page) |
685 | - if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) |
|
686 | - $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
719 | + if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) { |
|
720 | + $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
721 | + } |
|
687 | 722 | |
688 | 723 | // Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<) |
689 | - if ($start != $tmpMaxPages && $show_prevnext) |
|
690 | - if (empty($max_id)) |
|
724 | + if ($start != $tmpMaxPages && $show_prevnext) { |
|
725 | + if (empty($max_id)) |
|
691 | 726 | $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
692 | - else |
|
693 | - $pageindex .= sprintf($base_link_page, $start + $num_per_page, $settings['page_index']['next_page'], 'M'.$max_id); |
|
727 | + } else { |
|
728 | + $pageindex .= sprintf($base_link_page, $start + $num_per_page, $settings['page_index']['next_page'], 'M'.$max_id); |
|
729 | + } |
|
694 | 730 | } |
695 | 731 | $pageindex .= $settings['page_index']['extra_after']; |
696 | 732 | |
@@ -716,8 +752,9 @@ discard block |
||
716 | 752 | if ($decimal_separator === null) |
717 | 753 | { |
718 | 754 | // Not set for whatever reason? |
719 | - if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) |
|
720 | - return $number; |
|
755 | + if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) { |
|
756 | + return $number; |
|
757 | + } |
|
721 | 758 | |
722 | 759 | // Cache these each load... |
723 | 760 | $thousands_separator = $matches[1]; |
@@ -749,17 +786,20 @@ discard block |
||
749 | 786 | static $non_twelve_hour; |
750 | 787 | |
751 | 788 | // Offset the time. |
752 | - if (!$offset_type) |
|
753 | - $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
789 | + if (!$offset_type) { |
|
790 | + $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
791 | + } |
|
754 | 792 | // Just the forum offset? |
755 | - elseif ($offset_type == 'forum') |
|
756 | - $time = $log_time + $modSettings['time_offset'] * 3600; |
|
757 | - else |
|
758 | - $time = $log_time; |
|
793 | + elseif ($offset_type == 'forum') { |
|
794 | + $time = $log_time + $modSettings['time_offset'] * 3600; |
|
795 | + } else { |
|
796 | + $time = $log_time; |
|
797 | + } |
|
759 | 798 | |
760 | 799 | // We can't have a negative date (on Windows, at least.) |
761 | - if ($log_time < 0) |
|
762 | - $log_time = 0; |
|
800 | + if ($log_time < 0) { |
|
801 | + $log_time = 0; |
|
802 | + } |
|
763 | 803 | |
764 | 804 | // Today and Yesterday? |
765 | 805 | if ($modSettings['todayMod'] >= 1 && $show_today === true) |
@@ -776,46 +816,53 @@ discard block |
||
776 | 816 | { |
777 | 817 | $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l'; |
778 | 818 | $today_fmt = $h . ':%M' . $s . ' %p'; |
819 | + } else { |
|
820 | + $today_fmt = '%H:%M' . $s; |
|
779 | 821 | } |
780 | - else |
|
781 | - $today_fmt = '%H:%M' . $s; |
|
782 | 822 | |
783 | 823 | // Same day of the year, same year.... Today! |
784 | - if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) |
|
785 | - return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
824 | + if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) { |
|
825 | + return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
826 | + } |
|
786 | 827 | |
787 | 828 | // Day-of-year is one less and same year, or it's the first of the year and that's the last of the year... |
788 | - if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) |
|
789 | - return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
829 | + if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) { |
|
830 | + return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
831 | + } |
|
790 | 832 | } |
791 | 833 | |
792 | 834 | $str = !is_bool($show_today) ? $show_today : $user_info['time_format']; |
793 | 835 | |
794 | 836 | if (setlocale(LC_TIME, $txt['lang_locale'])) |
795 | 837 | { |
796 | - if (!isset($non_twelve_hour)) |
|
797 | - $non_twelve_hour = trim(strftime('%p')) === ''; |
|
798 | - if ($non_twelve_hour && strpos($str, '%p') !== false) |
|
799 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
838 | + if (!isset($non_twelve_hour)) { |
|
839 | + $non_twelve_hour = trim(strftime('%p')) === ''; |
|
840 | + } |
|
841 | + if ($non_twelve_hour && strpos($str, '%p') !== false) { |
|
842 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
843 | + } |
|
800 | 844 | |
801 | - foreach (array('%a', '%A', '%b', '%B') as $token) |
|
802 | - if (strpos($str, $token) !== false) |
|
845 | + foreach (array('%a', '%A', '%b', '%B') as $token) { |
|
846 | + if (strpos($str, $token) !== false) |
|
803 | 847 | $str = str_replace($token, strftime($token, $time), $str); |
804 | - } |
|
805 | - else |
|
848 | + } |
|
849 | + } else |
|
806 | 850 | { |
807 | 851 | // Do-it-yourself time localization. Fun. |
808 | - foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) |
|
809 | - if (strpos($str, $token) !== false) |
|
852 | + foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) { |
|
853 | + if (strpos($str, $token) !== false) |
|
810 | 854 | $str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str); |
855 | + } |
|
811 | 856 | |
812 | - if (strpos($str, '%p') !== false) |
|
813 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
857 | + if (strpos($str, '%p') !== false) { |
|
858 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
859 | + } |
|
814 | 860 | } |
815 | 861 | |
816 | 862 | // Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that. |
817 | - if ($context['server']['is_windows'] && strpos($str, '%e') !== false) |
|
818 | - $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
863 | + if ($context['server']['is_windows'] && strpos($str, '%e') !== false) { |
|
864 | + $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
865 | + } |
|
819 | 866 | |
820 | 867 | // Format any other characters.. |
821 | 868 | return strftime($str, $time); |
@@ -837,16 +884,19 @@ discard block |
||
837 | 884 | static $translation = array(); |
838 | 885 | |
839 | 886 | // Determine the character set... Default to UTF-8 |
840 | - if (empty($context['character_set'])) |
|
841 | - $charset = 'UTF-8'; |
|
887 | + if (empty($context['character_set'])) { |
|
888 | + $charset = 'UTF-8'; |
|
889 | + } |
|
842 | 890 | // Use ISO-8859-1 in place of non-supported ISO-8859 charsets... |
843 | - elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) |
|
844 | - $charset = 'ISO-8859-1'; |
|
845 | - else |
|
846 | - $charset = $context['character_set']; |
|
891 | + elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) { |
|
892 | + $charset = 'ISO-8859-1'; |
|
893 | + } else { |
|
894 | + $charset = $context['character_set']; |
|
895 | + } |
|
847 | 896 | |
848 | - if (empty($translation)) |
|
849 | - $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
897 | + if (empty($translation)) { |
|
898 | + $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
899 | + } |
|
850 | 900 | |
851 | 901 | return strtr($string, $translation); |
852 | 902 | } |
@@ -868,8 +918,9 @@ discard block |
||
868 | 918 | global $smcFunc; |
869 | 919 | |
870 | 920 | // It was already short enough! |
871 | - if ($smcFunc['strlen']($subject) <= $len) |
|
872 | - return $subject; |
|
921 | + if ($smcFunc['strlen']($subject) <= $len) { |
|
922 | + return $subject; |
|
923 | + } |
|
873 | 924 | |
874 | 925 | // Shorten it by the length it was too long, and strip off junk from the end. |
875 | 926 | return $smcFunc['substr']($subject, 0, $len) . '...'; |
@@ -888,10 +939,11 @@ discard block |
||
888 | 939 | { |
889 | 940 | global $user_info, $modSettings; |
890 | 941 | |
891 | - if ($timestamp === null) |
|
892 | - $timestamp = time(); |
|
893 | - elseif ($timestamp == 0) |
|
894 | - return 0; |
|
942 | + if ($timestamp === null) { |
|
943 | + $timestamp = time(); |
|
944 | + } elseif ($timestamp == 0) { |
|
945 | + return 0; |
|
946 | + } |
|
895 | 947 | |
896 | 948 | return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600; |
897 | 949 | } |
@@ -920,8 +972,9 @@ discard block |
||
920 | 972 | $array[$i] = $array[$j]; |
921 | 973 | $array[$j] = $temp; |
922 | 974 | |
923 | - for ($i = 1; $p[$i] == 0; $i++) |
|
924 | - $p[$i] = 1; |
|
975 | + for ($i = 1; $p[$i] == 0; $i++) { |
|
976 | + $p[$i] = 1; |
|
977 | + } |
|
925 | 978 | |
926 | 979 | $orders[] = $array; |
927 | 980 | } |
@@ -953,12 +1006,14 @@ discard block |
||
953 | 1006 | static $disabled; |
954 | 1007 | |
955 | 1008 | // Don't waste cycles |
956 | - if ($message === '') |
|
957 | - return ''; |
|
1009 | + if ($message === '') { |
|
1010 | + return ''; |
|
1011 | + } |
|
958 | 1012 | |
959 | 1013 | // Just in case it wasn't determined yet whether UTF-8 is enabled. |
960 | - if (!isset($context['utf8'])) |
|
961 | - $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
1014 | + if (!isset($context['utf8'])) { |
|
1015 | + $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
1016 | + } |
|
962 | 1017 | |
963 | 1018 | // Clean up any cut/paste issues we may have |
964 | 1019 | $message = sanitizeMSCutPaste($message); |
@@ -970,13 +1025,15 @@ discard block |
||
970 | 1025 | return $message; |
971 | 1026 | } |
972 | 1027 | |
973 | - if ($smileys !== null && ($smileys == '1' || $smileys == '0')) |
|
974 | - $smileys = (bool) $smileys; |
|
1028 | + if ($smileys !== null && ($smileys == '1' || $smileys == '0')) { |
|
1029 | + $smileys = (bool) $smileys; |
|
1030 | + } |
|
975 | 1031 | |
976 | 1032 | if (empty($modSettings['enableBBC']) && $message !== false) |
977 | 1033 | { |
978 | - if ($smileys === true) |
|
979 | - parsesmileys($message); |
|
1034 | + if ($smileys === true) { |
|
1035 | + parsesmileys($message); |
|
1036 | + } |
|
980 | 1037 | |
981 | 1038 | return $message; |
982 | 1039 | } |
@@ -989,8 +1046,9 @@ discard block |
||
989 | 1046 | } |
990 | 1047 | |
991 | 1048 | // Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker |
992 | - if (!empty($modSettings['autoLinkUrls'])) |
|
993 | - set_tld_regex(); |
|
1049 | + if (!empty($modSettings['autoLinkUrls'])) { |
|
1050 | + set_tld_regex(); |
|
1051 | + } |
|
994 | 1052 | |
995 | 1053 | // Allow mods access before entering the main parse_bbc loop |
996 | 1054 | call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
@@ -1004,12 +1062,14 @@ discard block |
||
1004 | 1062 | |
1005 | 1063 | $temp = explode(',', strtolower($modSettings['disabledBBC'])); |
1006 | 1064 | |
1007 | - foreach ($temp as $tag) |
|
1008 | - $disabled[trim($tag)] = true; |
|
1065 | + foreach ($temp as $tag) { |
|
1066 | + $disabled[trim($tag)] = true; |
|
1067 | + } |
|
1009 | 1068 | } |
1010 | 1069 | |
1011 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
1012 | - $disabled['flash'] = true; |
|
1070 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
1071 | + $disabled['flash'] = true; |
|
1072 | + } |
|
1013 | 1073 | |
1014 | 1074 | /* The following bbc are formatted as an array, with keys as follows: |
1015 | 1075 | |
@@ -1130,8 +1190,9 @@ discard block |
||
1130 | 1190 | $returnContext = ''; |
1131 | 1191 | |
1132 | 1192 | // BBC or the entire attachments feature is disabled |
1133 | - if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) |
|
1134 | - return $data; |
|
1193 | + if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) { |
|
1194 | + return $data; |
|
1195 | + } |
|
1135 | 1196 | |
1136 | 1197 | // Save the attach ID. |
1137 | 1198 | $attachID = $data; |
@@ -1142,8 +1203,9 @@ discard block |
||
1142 | 1203 | $currentAttachment = parseAttachBBC($attachID); |
1143 | 1204 | |
1144 | 1205 | // parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do. |
1145 | - if (is_string($currentAttachment)) |
|
1146 | - return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
1206 | + if (is_string($currentAttachment)) { |
|
1207 | + return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
1208 | + } |
|
1147 | 1209 | |
1148 | 1210 | if (!empty($currentAttachment['is_image'])) |
1149 | 1211 | { |
@@ -1159,15 +1221,17 @@ discard block |
||
1159 | 1221 | $height = ' height="' . $currentAttachment['height'] . '"'; |
1160 | 1222 | } |
1161 | 1223 | |
1162 | - if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) |
|
1163 | - $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>'; |
|
1164 | - else |
|
1165 | - $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
|
1224 | + if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) { |
|
1225 | + $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>'; |
|
1226 | + } else { |
|
1227 | + $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
|
1228 | + } |
|
1166 | 1229 | } |
1167 | 1230 | |
1168 | 1231 | // No image. Show a link. |
1169 | - else |
|
1170 | - $returnContext .= $currentAttachment['link']; |
|
1232 | + else { |
|
1233 | + $returnContext .= $currentAttachment['link']; |
|
1234 | + } |
|
1171 | 1235 | |
1172 | 1236 | // Gotta append what we just did. |
1173 | 1237 | $data = $returnContext; |
@@ -1198,8 +1262,9 @@ discard block |
||
1198 | 1262 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
1199 | 1263 | { |
1200 | 1264 | // Do PHP code coloring? |
1201 | - if ($php_parts[$php_i] != '<?php') |
|
1202 | - continue; |
|
1265 | + if ($php_parts[$php_i] != '<?php') { |
|
1266 | + continue; |
|
1267 | + } |
|
1203 | 1268 | |
1204 | 1269 | $php_string = ''; |
1205 | 1270 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1215,8 +1280,9 @@ discard block |
||
1215 | 1280 | $data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data); |
1216 | 1281 | |
1217 | 1282 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
1218 | - if ($context['browser']['is_opera']) |
|
1219 | - $data .= ' '; |
|
1283 | + if ($context['browser']['is_opera']) { |
|
1284 | + $data .= ' '; |
|
1285 | + } |
|
1220 | 1286 | } |
1221 | 1287 | }, |
1222 | 1288 | 'block_level' => true, |
@@ -1235,8 +1301,9 @@ discard block |
||
1235 | 1301 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
1236 | 1302 | { |
1237 | 1303 | // Do PHP code coloring? |
1238 | - if ($php_parts[$php_i] != '<?php') |
|
1239 | - continue; |
|
1304 | + if ($php_parts[$php_i] != '<?php') { |
|
1305 | + continue; |
|
1306 | + } |
|
1240 | 1307 | |
1241 | 1308 | $php_string = ''; |
1242 | 1309 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1252,8 +1319,9 @@ discard block |
||
1252 | 1319 | $data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]); |
1253 | 1320 | |
1254 | 1321 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
1255 | - if ($context['browser']['is_opera']) |
|
1256 | - $data[0] .= ' '; |
|
1322 | + if ($context['browser']['is_opera']) { |
|
1323 | + $data[0] .= ' '; |
|
1324 | + } |
|
1257 | 1325 | } |
1258 | 1326 | }, |
1259 | 1327 | 'block_level' => true, |
@@ -1291,11 +1359,13 @@ discard block |
||
1291 | 1359 | 'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">', |
1292 | 1360 | 'validate' => function (&$tag, &$data, $disabled) |
1293 | 1361 | { |
1294 | - if (isset($disabled['url'])) |
|
1295 | - $tag['content'] = '$1'; |
|
1362 | + if (isset($disabled['url'])) { |
|
1363 | + $tag['content'] = '$1'; |
|
1364 | + } |
|
1296 | 1365 | $scheme = parse_url($data[0], PHP_URL_SCHEME); |
1297 | - if (empty($scheme)) |
|
1298 | - $data[0] = '//' . ltrim($data[0], ':/'); |
|
1366 | + if (empty($scheme)) { |
|
1367 | + $data[0] = '//' . ltrim($data[0], ':/'); |
|
1368 | + } |
|
1299 | 1369 | }, |
1300 | 1370 | 'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>', |
1301 | 1371 | ), |
@@ -1309,10 +1379,11 @@ discard block |
||
1309 | 1379 | { |
1310 | 1380 | $class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"'; |
1311 | 1381 | |
1312 | - if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) |
|
1313 | - $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; |
|
1314 | - else |
|
1315 | - $css = ''; |
|
1382 | + if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) { |
|
1383 | + $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; |
|
1384 | + } else { |
|
1385 | + $css = ''; |
|
1386 | + } |
|
1316 | 1387 | |
1317 | 1388 | $data = $class . $css; |
1318 | 1389 | }, |
@@ -1362,14 +1433,16 @@ discard block |
||
1362 | 1433 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1363 | 1434 | if ($image_proxy_enabled) |
1364 | 1435 | { |
1365 | - if (empty($scheme)) |
|
1366 | - $data = 'http://' . ltrim($data, ':/'); |
|
1436 | + if (empty($scheme)) { |
|
1437 | + $data = 'http://' . ltrim($data, ':/'); |
|
1438 | + } |
|
1367 | 1439 | |
1368 | - if ($scheme != 'https') |
|
1369 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1440 | + if ($scheme != 'https') { |
|
1441 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1442 | + } |
|
1443 | + } elseif (empty($scheme)) { |
|
1444 | + $data = '//' . ltrim($data, ':/'); |
|
1370 | 1445 | } |
1371 | - elseif (empty($scheme)) |
|
1372 | - $data = '//' . ltrim($data, ':/'); |
|
1373 | 1446 | }, |
1374 | 1447 | 'disabled_content' => '($1)', |
1375 | 1448 | ), |
@@ -1385,14 +1458,16 @@ discard block |
||
1385 | 1458 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1386 | 1459 | if ($image_proxy_enabled) |
1387 | 1460 | { |
1388 | - if (empty($scheme)) |
|
1389 | - $data = 'http://' . ltrim($data, ':/'); |
|
1461 | + if (empty($scheme)) { |
|
1462 | + $data = 'http://' . ltrim($data, ':/'); |
|
1463 | + } |
|
1390 | 1464 | |
1391 | - if ($scheme != 'https') |
|
1392 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1465 | + if ($scheme != 'https') { |
|
1466 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1467 | + } |
|
1468 | + } elseif (empty($scheme)) { |
|
1469 | + $data = '//' . ltrim($data, ':/'); |
|
1393 | 1470 | } |
1394 | - elseif (empty($scheme)) |
|
1395 | - $data = '//' . ltrim($data, ':/'); |
|
1396 | 1471 | }, |
1397 | 1472 | 'disabled_content' => '($1)', |
1398 | 1473 | ), |
@@ -1404,8 +1479,9 @@ discard block |
||
1404 | 1479 | { |
1405 | 1480 | $data = strtr($data, array('<br>' => '')); |
1406 | 1481 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1407 | - if (empty($scheme)) |
|
1408 | - $data = '//' . ltrim($data, ':/'); |
|
1482 | + if (empty($scheme)) { |
|
1483 | + $data = '//' . ltrim($data, ':/'); |
|
1484 | + } |
|
1409 | 1485 | }, |
1410 | 1486 | ), |
1411 | 1487 | array( |
@@ -1416,13 +1492,14 @@ discard block |
||
1416 | 1492 | 'after' => '</a>', |
1417 | 1493 | 'validate' => function (&$tag, &$data, $disabled) |
1418 | 1494 | { |
1419 | - if (substr($data, 0, 1) == '#') |
|
1420 | - $data = '#post_' . substr($data, 1); |
|
1421 | - else |
|
1495 | + if (substr($data, 0, 1) == '#') { |
|
1496 | + $data = '#post_' . substr($data, 1); |
|
1497 | + } else |
|
1422 | 1498 | { |
1423 | 1499 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1424 | - if (empty($scheme)) |
|
1425 | - $data = '//' . ltrim($data, ':/'); |
|
1500 | + if (empty($scheme)) { |
|
1501 | + $data = '//' . ltrim($data, ':/'); |
|
1502 | + } |
|
1426 | 1503 | } |
1427 | 1504 | }, |
1428 | 1505 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
@@ -1500,8 +1577,9 @@ discard block |
||
1500 | 1577 | { |
1501 | 1578 | $add_begin = substr(trim($data), 0, 5) != '<?'; |
1502 | 1579 | $data = highlight_php_code($add_begin ? '<?php ' . $data . '?>' : $data); |
1503 | - if ($add_begin) |
|
1504 | - $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
1580 | + if ($add_begin) { |
|
1581 | + $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
1582 | + } |
|
1505 | 1583 | } |
1506 | 1584 | }, |
1507 | 1585 | 'block_level' => false, |
@@ -1632,10 +1710,11 @@ discard block |
||
1632 | 1710 | 'content' => '$1', |
1633 | 1711 | 'validate' => function (&$tag, &$data, $disabled) |
1634 | 1712 | { |
1635 | - if (is_numeric($data)) |
|
1636 | - $data = timeformat($data); |
|
1637 | - else |
|
1638 | - $tag['content'] = '[time]$1[/time]'; |
|
1713 | + if (is_numeric($data)) { |
|
1714 | + $data = timeformat($data); |
|
1715 | + } else { |
|
1716 | + $tag['content'] = '[time]$1[/time]'; |
|
1717 | + } |
|
1639 | 1718 | }, |
1640 | 1719 | ), |
1641 | 1720 | array( |
@@ -1662,8 +1741,9 @@ discard block |
||
1662 | 1741 | { |
1663 | 1742 | $data = strtr($data, array('<br>' => '')); |
1664 | 1743 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1665 | - if (empty($scheme)) |
|
1666 | - $data = '//' . ltrim($data, ':/'); |
|
1744 | + if (empty($scheme)) { |
|
1745 | + $data = '//' . ltrim($data, ':/'); |
|
1746 | + } |
|
1667 | 1747 | }, |
1668 | 1748 | ), |
1669 | 1749 | array( |
@@ -1675,8 +1755,9 @@ discard block |
||
1675 | 1755 | 'validate' => function (&$tag, &$data, $disabled) |
1676 | 1756 | { |
1677 | 1757 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1678 | - if (empty($scheme)) |
|
1679 | - $data = '//' . ltrim($data, ':/'); |
|
1758 | + if (empty($scheme)) { |
|
1759 | + $data = '//' . ltrim($data, ':/'); |
|
1760 | + } |
|
1680 | 1761 | }, |
1681 | 1762 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
1682 | 1763 | 'disabled_after' => ' ($1)', |
@@ -1696,8 +1777,9 @@ discard block |
||
1696 | 1777 | // This is mainly for the bbc manager, so it's easy to add tags above. Custom BBC should be added above this line. |
1697 | 1778 | if ($message === false) |
1698 | 1779 | { |
1699 | - if (isset($temp_bbc)) |
|
1700 | - $bbc_codes = $temp_bbc; |
|
1780 | + if (isset($temp_bbc)) { |
|
1781 | + $bbc_codes = $temp_bbc; |
|
1782 | + } |
|
1701 | 1783 | usort($codes, function ($a, $b) { |
1702 | 1784 | return strcmp($a['tag'], $b['tag']); |
1703 | 1785 | }); |
@@ -1717,8 +1799,9 @@ discard block |
||
1717 | 1799 | ); |
1718 | 1800 | if (!isset($disabled['li']) && !isset($disabled['list'])) |
1719 | 1801 | { |
1720 | - foreach ($itemcodes as $c => $dummy) |
|
1721 | - $bbc_codes[$c] = array(); |
|
1802 | + foreach ($itemcodes as $c => $dummy) { |
|
1803 | + $bbc_codes[$c] = array(); |
|
1804 | + } |
|
1722 | 1805 | } |
1723 | 1806 | |
1724 | 1807 | // Shhhh! |
@@ -1739,12 +1822,14 @@ discard block |
||
1739 | 1822 | foreach ($codes as $code) |
1740 | 1823 | { |
1741 | 1824 | // Make it easier to process parameters later |
1742 | - if (!empty($code['parameters'])) |
|
1743 | - ksort($code['parameters'], SORT_STRING); |
|
1825 | + if (!empty($code['parameters'])) { |
|
1826 | + ksort($code['parameters'], SORT_STRING); |
|
1827 | + } |
|
1744 | 1828 | |
1745 | 1829 | // If we are not doing every tag only do ones we are interested in. |
1746 | - if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) |
|
1747 | - $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
1830 | + if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) { |
|
1831 | + $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
1832 | + } |
|
1748 | 1833 | } |
1749 | 1834 | $codes = null; |
1750 | 1835 | } |
@@ -1755,8 +1840,9 @@ discard block |
||
1755 | 1840 | // It's likely this will change if the message is modified. |
1756 | 1841 | $cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . json_encode($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']); |
1757 | 1842 | |
1758 | - if (($temp = cache_get_data($cache_key, 240)) != null) |
|
1759 | - return $temp; |
|
1843 | + if (($temp = cache_get_data($cache_key, 240)) != null) { |
|
1844 | + return $temp; |
|
1845 | + } |
|
1760 | 1846 | |
1761 | 1847 | $cache_t = microtime(); |
1762 | 1848 | } |
@@ -1788,8 +1874,9 @@ discard block |
||
1788 | 1874 | $disabled['flash'] = true; |
1789 | 1875 | |
1790 | 1876 | // @todo Change maybe? |
1791 | - if (!isset($_GET['images'])) |
|
1792 | - $disabled['img'] = true; |
|
1877 | + if (!isset($_GET['images'])) { |
|
1878 | + $disabled['img'] = true; |
|
1879 | + } |
|
1793 | 1880 | |
1794 | 1881 | // @todo Interface/setting to add more? |
1795 | 1882 | } |
@@ -1813,8 +1900,9 @@ discard block |
||
1813 | 1900 | $pos = isset($matches[0][1]) ? $matches[0][1] : false; |
1814 | 1901 | |
1815 | 1902 | // Failsafe. |
1816 | - if ($pos === false || $last_pos > $pos) |
|
1817 | - $pos = strlen($message) + 1; |
|
1903 | + if ($pos === false || $last_pos > $pos) { |
|
1904 | + $pos = strlen($message) + 1; |
|
1905 | + } |
|
1818 | 1906 | |
1819 | 1907 | // Can't have a one letter smiley, URL, or email! (sorry.) |
1820 | 1908 | if ($last_pos < $pos - 1) |
@@ -1833,8 +1921,9 @@ discard block |
||
1833 | 1921 | |
1834 | 1922 | // <br> should be empty. |
1835 | 1923 | $empty_tags = array('br', 'hr'); |
1836 | - foreach ($empty_tags as $tag) |
|
1837 | - $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
1924 | + foreach ($empty_tags as $tag) { |
|
1925 | + $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
1926 | + } |
|
1838 | 1927 | |
1839 | 1928 | // b, u, i, s, pre... basic tags. |
1840 | 1929 | $closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote'); |
@@ -1843,8 +1932,9 @@ discard block |
||
1843 | 1932 | $diff = substr_count($data, '<' . $tag . '>') - substr_count($data, '</' . $tag . '>'); |
1844 | 1933 | $data = strtr($data, array('<' . $tag . '>' => '<' . $tag . '>', '</' . $tag . '>' => '</' . $tag . '>')); |
1845 | 1934 | |
1846 | - if ($diff > 0) |
|
1847 | - $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
1935 | + if ($diff > 0) { |
|
1936 | + $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
1937 | + } |
|
1848 | 1938 | } |
1849 | 1939 | |
1850 | 1940 | // Do <img ...> - with security... action= -> action-. |
@@ -1857,8 +1947,9 @@ discard block |
||
1857 | 1947 | $alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^"|"$~', '', $matches[3][$match]); |
1858 | 1948 | |
1859 | 1949 | // Remove action= from the URL - no funny business, now. |
1860 | - if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) |
|
1861 | - $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
1950 | + if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) { |
|
1951 | + $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
1952 | + } |
|
1862 | 1953 | |
1863 | 1954 | // Check if the image is larger than allowed. |
1864 | 1955 | if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height'])) |
@@ -1879,9 +1970,9 @@ discard block |
||
1879 | 1970 | |
1880 | 1971 | // Set the new image tag. |
1881 | 1972 | $replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]'; |
1973 | + } else { |
|
1974 | + $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
1882 | 1975 | } |
1883 | - else |
|
1884 | - $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
1885 | 1976 | } |
1886 | 1977 | |
1887 | 1978 | $data = strtr($data, $replaces); |
@@ -1894,16 +1985,18 @@ discard block |
||
1894 | 1985 | $no_autolink_area = false; |
1895 | 1986 | if (!empty($open_tags)) |
1896 | 1987 | { |
1897 | - foreach ($open_tags as $open_tag) |
|
1898 | - if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
1988 | + foreach ($open_tags as $open_tag) { |
|
1989 | + if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
1899 | 1990 | $no_autolink_area = true; |
1991 | + } |
|
1900 | 1992 | } |
1901 | 1993 | |
1902 | 1994 | // Don't go backwards. |
1903 | 1995 | // @todo Don't think is the real solution.... |
1904 | 1996 | $lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0; |
1905 | - if ($pos < $lastAutoPos) |
|
1906 | - $no_autolink_area = true; |
|
1997 | + if ($pos < $lastAutoPos) { |
|
1998 | + $no_autolink_area = true; |
|
1999 | + } |
|
1907 | 2000 | $lastAutoPos = $pos; |
1908 | 2001 | |
1909 | 2002 | if (!$no_autolink_area) |
@@ -2012,17 +2105,19 @@ discard block |
||
2012 | 2105 | if ($scheme == 'mailto') |
2013 | 2106 | { |
2014 | 2107 | $email_address = str_replace('mailto:', '', $url); |
2015 | - if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) |
|
2016 | - return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
2017 | - else |
|
2018 | - return $url; |
|
2108 | + if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) { |
|
2109 | + return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
2110 | + } else { |
|
2111 | + return $url; |
|
2112 | + } |
|
2019 | 2113 | } |
2020 | 2114 | |
2021 | 2115 | // Are we linking a schemeless URL or naked domain name (e.g. "example.com")? |
2022 | - if (empty($scheme)) |
|
2023 | - $fullUrl = '//' . ltrim($url, ':/'); |
|
2024 | - else |
|
2025 | - $fullUrl = $url; |
|
2116 | + if (empty($scheme)) { |
|
2117 | + $fullUrl = '//' . ltrim($url, ':/'); |
|
2118 | + } else { |
|
2119 | + $fullUrl = $url; |
|
2120 | + } |
|
2026 | 2121 | |
2027 | 2122 | return '[url="' . str_replace(array('[', ']'), array('[', ']'), $fullUrl) . '"]' . $url . '[/url]'; |
2028 | 2123 | }, $data); |
@@ -2071,16 +2166,18 @@ discard block |
||
2071 | 2166 | } |
2072 | 2167 | |
2073 | 2168 | // Are we there yet? Are we there yet? |
2074 | - if ($pos >= strlen($message) - 1) |
|
2075 | - break; |
|
2169 | + if ($pos >= strlen($message) - 1) { |
|
2170 | + break; |
|
2171 | + } |
|
2076 | 2172 | |
2077 | 2173 | $tags = strtolower($message[$pos + 1]); |
2078 | 2174 | |
2079 | 2175 | if ($tags == '/' && !empty($open_tags)) |
2080 | 2176 | { |
2081 | 2177 | $pos2 = strpos($message, ']', $pos + 1); |
2082 | - if ($pos2 == $pos + 2) |
|
2083 | - continue; |
|
2178 | + if ($pos2 == $pos + 2) { |
|
2179 | + continue; |
|
2180 | + } |
|
2084 | 2181 | |
2085 | 2182 | $look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2)); |
2086 | 2183 | |
@@ -2090,8 +2187,9 @@ discard block |
||
2090 | 2187 | do |
2091 | 2188 | { |
2092 | 2189 | $tag = array_pop($open_tags); |
2093 | - if (!$tag) |
|
2094 | - break; |
|
2190 | + if (!$tag) { |
|
2191 | + break; |
|
2192 | + } |
|
2095 | 2193 | |
2096 | 2194 | if (!empty($tag['block_level'])) |
2097 | 2195 | { |
@@ -2105,10 +2203,11 @@ discard block |
||
2105 | 2203 | // The idea is, if we are LOOKING for a block level tag, we can close them on the way. |
2106 | 2204 | if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]])) |
2107 | 2205 | { |
2108 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
2109 | - if ($temp['tag'] == $look_for) |
|
2206 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
2207 | + if ($temp['tag'] == $look_for) |
|
2110 | 2208 | { |
2111 | 2209 | $block_level = !empty($temp['block_level']); |
2210 | + } |
|
2112 | 2211 | break; |
2113 | 2212 | } |
2114 | 2213 | } |
@@ -2130,15 +2229,15 @@ discard block |
||
2130 | 2229 | { |
2131 | 2230 | $open_tags = $to_close; |
2132 | 2231 | continue; |
2133 | - } |
|
2134 | - elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
2232 | + } elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
2135 | 2233 | { |
2136 | 2234 | if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]])) |
2137 | 2235 | { |
2138 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
2139 | - if ($temp['tag'] == $look_for) |
|
2236 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
2237 | + if ($temp['tag'] == $look_for) |
|
2140 | 2238 | { |
2141 | 2239 | $block_level = !empty($temp['block_level']); |
2240 | + } |
|
2142 | 2241 | break; |
2143 | 2242 | } |
2144 | 2243 | } |
@@ -2146,8 +2245,9 @@ discard block |
||
2146 | 2245 | // We're not looking for a block level tag (or maybe even a tag that exists...) |
2147 | 2246 | if (!$block_level) |
2148 | 2247 | { |
2149 | - foreach ($to_close as $tag) |
|
2150 | - array_push($open_tags, $tag); |
|
2248 | + foreach ($to_close as $tag) { |
|
2249 | + array_push($open_tags, $tag); |
|
2250 | + } |
|
2151 | 2251 | continue; |
2152 | 2252 | } |
2153 | 2253 | } |
@@ -2160,14 +2260,17 @@ discard block |
||
2160 | 2260 | |
2161 | 2261 | // See the comment at the end of the big loop - just eating whitespace ;). |
2162 | 2262 | $whitespace_regex = ''; |
2163 | - if (!empty($tag['block_level'])) |
|
2164 | - $whitespace_regex .= '( |\s)*<br>'; |
|
2263 | + if (!empty($tag['block_level'])) { |
|
2264 | + $whitespace_regex .= '( |\s)*<br>'; |
|
2265 | + } |
|
2165 | 2266 | // Trim one line of whitespace after unnested tags, but all of it after nested ones |
2166 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') |
|
2167 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2267 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside') { |
|
2268 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2269 | + } |
|
2168 | 2270 | |
2169 | - if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) |
|
2170 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2271 | + if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { |
|
2272 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2273 | + } |
|
2171 | 2274 | } |
2172 | 2275 | |
2173 | 2276 | if (!empty($to_close)) |
@@ -2180,8 +2283,9 @@ discard block |
||
2180 | 2283 | } |
2181 | 2284 | |
2182 | 2285 | // No tags for this character, so just keep going (fastest possible course.) |
2183 | - if (!isset($bbc_codes[$tags])) |
|
2184 | - continue; |
|
2286 | + if (!isset($bbc_codes[$tags])) { |
|
2287 | + continue; |
|
2288 | + } |
|
2185 | 2289 | |
2186 | 2290 | $inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1]; |
2187 | 2291 | $tag = null; |
@@ -2190,44 +2294,52 @@ discard block |
||
2190 | 2294 | $pt_strlen = strlen($possible['tag']); |
2191 | 2295 | |
2192 | 2296 | // Not a match? |
2193 | - if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) |
|
2194 | - continue; |
|
2297 | + if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) { |
|
2298 | + continue; |
|
2299 | + } |
|
2195 | 2300 | |
2196 | 2301 | $next_c = $message[$pos + 1 + $pt_strlen]; |
2197 | 2302 | |
2198 | 2303 | // A test validation? |
2199 | - if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) |
|
2200 | - continue; |
|
2304 | + if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) { |
|
2305 | + continue; |
|
2306 | + } |
|
2201 | 2307 | // Do we want parameters? |
2202 | 2308 | elseif (!empty($possible['parameters'])) |
2203 | 2309 | { |
2204 | - if ($next_c != ' ') |
|
2205 | - continue; |
|
2206 | - } |
|
2207 | - elseif (isset($possible['type'])) |
|
2310 | + if ($next_c != ' ') { |
|
2311 | + continue; |
|
2312 | + } |
|
2313 | + } elseif (isset($possible['type'])) |
|
2208 | 2314 | { |
2209 | 2315 | // Do we need an equal sign? |
2210 | - if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') |
|
2211 | - continue; |
|
2316 | + if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') { |
|
2317 | + continue; |
|
2318 | + } |
|
2212 | 2319 | // Maybe we just want a /... |
2213 | - if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') |
|
2214 | - continue; |
|
2320 | + if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') { |
|
2321 | + continue; |
|
2322 | + } |
|
2215 | 2323 | // An immediate ]? |
2216 | - if ($possible['type'] == 'unparsed_content' && $next_c != ']') |
|
2217 | - continue; |
|
2324 | + if ($possible['type'] == 'unparsed_content' && $next_c != ']') { |
|
2325 | + continue; |
|
2326 | + } |
|
2218 | 2327 | } |
2219 | 2328 | // No type means 'parsed_content', which demands an immediate ] without parameters! |
2220 | - elseif ($next_c != ']') |
|
2221 | - continue; |
|
2329 | + elseif ($next_c != ']') { |
|
2330 | + continue; |
|
2331 | + } |
|
2222 | 2332 | |
2223 | 2333 | // Check allowed tree? |
2224 | - if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) |
|
2225 | - continue; |
|
2226 | - elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) |
|
2227 | - continue; |
|
2334 | + if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) { |
|
2335 | + continue; |
|
2336 | + } elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) { |
|
2337 | + continue; |
|
2338 | + } |
|
2228 | 2339 | // If this is in the list of disallowed child tags, don't parse it. |
2229 | - elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) |
|
2230 | - continue; |
|
2340 | + elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) { |
|
2341 | + continue; |
|
2342 | + } |
|
2231 | 2343 | |
2232 | 2344 | $pos1 = $pos + 1 + $pt_strlen + 1; |
2233 | 2345 | |
@@ -2239,8 +2351,9 @@ discard block |
||
2239 | 2351 | foreach ($open_tags as $open_quote) |
2240 | 2352 | { |
2241 | 2353 | // Every parent quote this quote has flips the styling |
2242 | - if ($open_quote['tag'] == 'quote') |
|
2243 | - $quote_alt = !$quote_alt; |
|
2354 | + if ($open_quote['tag'] == 'quote') { |
|
2355 | + $quote_alt = !$quote_alt; |
|
2356 | + } |
|
2244 | 2357 | } |
2245 | 2358 | // Add a class to the quote to style alternating blockquotes |
2246 | 2359 | $possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">')); |
@@ -2251,8 +2364,9 @@ discard block |
||
2251 | 2364 | { |
2252 | 2365 | // Build a regular expression for each parameter for the current tag. |
2253 | 2366 | $preg = array(); |
2254 | - foreach ($possible['parameters'] as $p => $info) |
|
2255 | - $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
2367 | + foreach ($possible['parameters'] as $p => $info) { |
|
2368 | + $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
2369 | + } |
|
2256 | 2370 | |
2257 | 2371 | // Extract the string that potentially holds our parameters. |
2258 | 2372 | $blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos)); |
@@ -2272,24 +2386,27 @@ discard block |
||
2272 | 2386 | |
2273 | 2387 | $match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0; |
2274 | 2388 | |
2275 | - if ($match) |
|
2276 | - $blob_counter = count($blobs) + 1; |
|
2389 | + if ($match) { |
|
2390 | + $blob_counter = count($blobs) + 1; |
|
2391 | + } |
|
2277 | 2392 | } |
2278 | 2393 | |
2279 | 2394 | // Didn't match our parameter list, try the next possible. |
2280 | - if (!$match) |
|
2281 | - continue; |
|
2395 | + if (!$match) { |
|
2396 | + continue; |
|
2397 | + } |
|
2282 | 2398 | |
2283 | 2399 | $params = array(); |
2284 | 2400 | for ($i = 1, $n = count($matches); $i < $n; $i += 2) |
2285 | 2401 | { |
2286 | 2402 | $key = strtok(ltrim($matches[$i]), '='); |
2287 | - if (isset($possible['parameters'][$key]['value'])) |
|
2288 | - $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
2289 | - elseif (isset($possible['parameters'][$key]['validate'])) |
|
2290 | - $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
2291 | - else |
|
2292 | - $params['{' . $key . '}'] = $matches[$i + 1]; |
|
2403 | + if (isset($possible['parameters'][$key]['value'])) { |
|
2404 | + $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
2405 | + } elseif (isset($possible['parameters'][$key]['validate'])) { |
|
2406 | + $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
2407 | + } else { |
|
2408 | + $params['{' . $key . '}'] = $matches[$i + 1]; |
|
2409 | + } |
|
2293 | 2410 | |
2294 | 2411 | // Just to make sure: replace any $ or { so they can't interpolate wrongly. |
2295 | 2412 | $params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '$', '{' => '{')); |
@@ -2297,23 +2414,26 @@ discard block |
||
2297 | 2414 | |
2298 | 2415 | foreach ($possible['parameters'] as $p => $info) |
2299 | 2416 | { |
2300 | - if (!isset($params['{' . $p . '}'])) |
|
2301 | - $params['{' . $p . '}'] = ''; |
|
2417 | + if (!isset($params['{' . $p . '}'])) { |
|
2418 | + $params['{' . $p . '}'] = ''; |
|
2419 | + } |
|
2302 | 2420 | } |
2303 | 2421 | |
2304 | 2422 | $tag = $possible; |
2305 | 2423 | |
2306 | 2424 | // Put the parameters into the string. |
2307 | - if (isset($tag['before'])) |
|
2308 | - $tag['before'] = strtr($tag['before'], $params); |
|
2309 | - if (isset($tag['after'])) |
|
2310 | - $tag['after'] = strtr($tag['after'], $params); |
|
2311 | - if (isset($tag['content'])) |
|
2312 | - $tag['content'] = strtr($tag['content'], $params); |
|
2425 | + if (isset($tag['before'])) { |
|
2426 | + $tag['before'] = strtr($tag['before'], $params); |
|
2427 | + } |
|
2428 | + if (isset($tag['after'])) { |
|
2429 | + $tag['after'] = strtr($tag['after'], $params); |
|
2430 | + } |
|
2431 | + if (isset($tag['content'])) { |
|
2432 | + $tag['content'] = strtr($tag['content'], $params); |
|
2433 | + } |
|
2313 | 2434 | |
2314 | 2435 | $pos1 += strlen($given_param_string); |
2315 | - } |
|
2316 | - else |
|
2436 | + } else |
|
2317 | 2437 | { |
2318 | 2438 | $tag = $possible; |
2319 | 2439 | $params = array(); |
@@ -2324,8 +2444,9 @@ discard block |
||
2324 | 2444 | // Item codes are complicated buggers... they are implicit [li]s and can make [list]s! |
2325 | 2445 | if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li'])) |
2326 | 2446 | { |
2327 | - if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) |
|
2328 | - continue; |
|
2447 | + if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) { |
|
2448 | + continue; |
|
2449 | + } |
|
2329 | 2450 | |
2330 | 2451 | $tag = $itemcodes[$message[$pos + 1]]; |
2331 | 2452 | |
@@ -2346,9 +2467,9 @@ discard block |
||
2346 | 2467 | { |
2347 | 2468 | array_pop($open_tags); |
2348 | 2469 | $code = '</li>'; |
2470 | + } else { |
|
2471 | + $code = ''; |
|
2349 | 2472 | } |
2350 | - else |
|
2351 | - $code = ''; |
|
2352 | 2473 | |
2353 | 2474 | // Now we open a new tag. |
2354 | 2475 | $open_tags[] = array( |
@@ -2395,12 +2516,14 @@ discard block |
||
2395 | 2516 | } |
2396 | 2517 | |
2397 | 2518 | // No tag? Keep looking, then. Silly people using brackets without actual tags. |
2398 | - if ($tag === null) |
|
2399 | - continue; |
|
2519 | + if ($tag === null) { |
|
2520 | + continue; |
|
2521 | + } |
|
2400 | 2522 | |
2401 | 2523 | // Propagate the list to the child (so wrapping the disallowed tag won't work either.) |
2402 | - if (isset($inside['disallow_children'])) |
|
2403 | - $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
2524 | + if (isset($inside['disallow_children'])) { |
|
2525 | + $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
2526 | + } |
|
2404 | 2527 | |
2405 | 2528 | // Is this tag disabled? |
2406 | 2529 | if (isset($disabled[$tag['tag']])) |
@@ -2410,14 +2533,13 @@ discard block |
||
2410 | 2533 | $tag['before'] = !empty($tag['block_level']) ? '<div>' : ''; |
2411 | 2534 | $tag['after'] = !empty($tag['block_level']) ? '</div>' : ''; |
2412 | 2535 | $tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1'); |
2413 | - } |
|
2414 | - elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
2536 | + } elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
2415 | 2537 | { |
2416 | 2538 | $tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : ''); |
2417 | 2539 | $tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : ''); |
2540 | + } else { |
|
2541 | + $tag['content'] = $tag['disabled_content']; |
|
2418 | 2542 | } |
2419 | - else |
|
2420 | - $tag['content'] = $tag['disabled_content']; |
|
2421 | 2543 | } |
2422 | 2544 | |
2423 | 2545 | // we use this a lot |
@@ -2427,8 +2549,9 @@ discard block |
||
2427 | 2549 | if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level'])) |
2428 | 2550 | { |
2429 | 2551 | $n = count($open_tags) - 1; |
2430 | - while (empty($open_tags[$n]['block_level']) && $n >= 0) |
|
2431 | - $n--; |
|
2552 | + while (empty($open_tags[$n]['block_level']) && $n >= 0) { |
|
2553 | + $n--; |
|
2554 | + } |
|
2432 | 2555 | |
2433 | 2556 | // Close all the non block level tags so this tag isn't surrounded by them. |
2434 | 2557 | for ($i = count($open_tags) - 1; $i > $n; $i--) |
@@ -2440,12 +2563,15 @@ discard block |
||
2440 | 2563 | |
2441 | 2564 | // Trim or eat trailing stuff... see comment at the end of the big loop. |
2442 | 2565 | $whitespace_regex = ''; |
2443 | - if (!empty($tag['block_level'])) |
|
2444 | - $whitespace_regex .= '( |\s)*<br>'; |
|
2445 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') |
|
2446 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2447 | - if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) |
|
2448 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2566 | + if (!empty($tag['block_level'])) { |
|
2567 | + $whitespace_regex .= '( |\s)*<br>'; |
|
2568 | + } |
|
2569 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside') { |
|
2570 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2571 | + } |
|
2572 | + if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { |
|
2573 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2574 | + } |
|
2449 | 2575 | |
2450 | 2576 | array_pop($open_tags); |
2451 | 2577 | } |
@@ -2463,16 +2589,19 @@ discard block |
||
2463 | 2589 | elseif ($tag['type'] == 'unparsed_content') |
2464 | 2590 | { |
2465 | 2591 | $pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1); |
2466 | - if ($pos2 === false) |
|
2467 | - continue; |
|
2592 | + if ($pos2 === false) { |
|
2593 | + continue; |
|
2594 | + } |
|
2468 | 2595 | |
2469 | 2596 | $data = substr($message, $pos1, $pos2 - $pos1); |
2470 | 2597 | |
2471 | - if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') |
|
2472 | - $data = substr($data, 4); |
|
2598 | + if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') { |
|
2599 | + $data = substr($data, 4); |
|
2600 | + } |
|
2473 | 2601 | |
2474 | - if (isset($tag['validate'])) |
|
2475 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2602 | + if (isset($tag['validate'])) { |
|
2603 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2604 | + } |
|
2476 | 2605 | |
2477 | 2606 | $code = strtr($tag['content'], array('$1' => $data)); |
2478 | 2607 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen); |
@@ -2488,34 +2617,40 @@ discard block |
||
2488 | 2617 | if (isset($tag['quoted'])) |
2489 | 2618 | { |
2490 | 2619 | $quoted = substr($message, $pos1, 6) == '"'; |
2491 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
2492 | - continue; |
|
2620 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
2621 | + continue; |
|
2622 | + } |
|
2493 | 2623 | |
2494 | - if ($quoted) |
|
2495 | - $pos1 += 6; |
|
2624 | + if ($quoted) { |
|
2625 | + $pos1 += 6; |
|
2626 | + } |
|
2627 | + } else { |
|
2628 | + $quoted = false; |
|
2496 | 2629 | } |
2497 | - else |
|
2498 | - $quoted = false; |
|
2499 | 2630 | |
2500 | 2631 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
2501 | - if ($pos2 === false) |
|
2502 | - continue; |
|
2632 | + if ($pos2 === false) { |
|
2633 | + continue; |
|
2634 | + } |
|
2503 | 2635 | |
2504 | 2636 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
2505 | - if ($pos3 === false) |
|
2506 | - continue; |
|
2637 | + if ($pos3 === false) { |
|
2638 | + continue; |
|
2639 | + } |
|
2507 | 2640 | |
2508 | 2641 | $data = array( |
2509 | 2642 | substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))), |
2510 | 2643 | substr($message, $pos1, $pos2 - $pos1) |
2511 | 2644 | ); |
2512 | 2645 | |
2513 | - if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') |
|
2514 | - $data[0] = substr($data[0], 4); |
|
2646 | + if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') { |
|
2647 | + $data[0] = substr($data[0], 4); |
|
2648 | + } |
|
2515 | 2649 | |
2516 | 2650 | // Validation for my parking, please! |
2517 | - if (isset($tag['validate'])) |
|
2518 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2651 | + if (isset($tag['validate'])) { |
|
2652 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2653 | + } |
|
2519 | 2654 | |
2520 | 2655 | $code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1])); |
2521 | 2656 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
@@ -2532,23 +2667,27 @@ discard block |
||
2532 | 2667 | elseif ($tag['type'] == 'unparsed_commas_content') |
2533 | 2668 | { |
2534 | 2669 | $pos2 = strpos($message, ']', $pos1); |
2535 | - if ($pos2 === false) |
|
2536 | - continue; |
|
2670 | + if ($pos2 === false) { |
|
2671 | + continue; |
|
2672 | + } |
|
2537 | 2673 | |
2538 | 2674 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
2539 | - if ($pos3 === false) |
|
2540 | - continue; |
|
2675 | + if ($pos3 === false) { |
|
2676 | + continue; |
|
2677 | + } |
|
2541 | 2678 | |
2542 | 2679 | // We want $1 to be the content, and the rest to be csv. |
2543 | 2680 | $data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1)); |
2544 | 2681 | $data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1); |
2545 | 2682 | |
2546 | - if (isset($tag['validate'])) |
|
2547 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2683 | + if (isset($tag['validate'])) { |
|
2684 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2685 | + } |
|
2548 | 2686 | |
2549 | 2687 | $code = $tag['content']; |
2550 | - foreach ($data as $k => $d) |
|
2551 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2688 | + foreach ($data as $k => $d) { |
|
2689 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2690 | + } |
|
2552 | 2691 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
2553 | 2692 | $pos += strlen($code) - 1 + 2; |
2554 | 2693 | } |
@@ -2556,24 +2695,28 @@ discard block |
||
2556 | 2695 | elseif ($tag['type'] == 'unparsed_commas') |
2557 | 2696 | { |
2558 | 2697 | $pos2 = strpos($message, ']', $pos1); |
2559 | - if ($pos2 === false) |
|
2560 | - continue; |
|
2698 | + if ($pos2 === false) { |
|
2699 | + continue; |
|
2700 | + } |
|
2561 | 2701 | |
2562 | 2702 | $data = explode(',', substr($message, $pos1, $pos2 - $pos1)); |
2563 | 2703 | |
2564 | - if (isset($tag['validate'])) |
|
2565 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2704 | + if (isset($tag['validate'])) { |
|
2705 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2706 | + } |
|
2566 | 2707 | |
2567 | 2708 | // Fix after, for disabled code mainly. |
2568 | - foreach ($data as $k => $d) |
|
2569 | - $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
2709 | + foreach ($data as $k => $d) { |
|
2710 | + $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
2711 | + } |
|
2570 | 2712 | |
2571 | 2713 | $open_tags[] = $tag; |
2572 | 2714 | |
2573 | 2715 | // Replace them out, $1, $2, $3, $4, etc. |
2574 | 2716 | $code = $tag['before']; |
2575 | - foreach ($data as $k => $d) |
|
2576 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2717 | + foreach ($data as $k => $d) { |
|
2718 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2719 | + } |
|
2577 | 2720 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1); |
2578 | 2721 | $pos += strlen($code) - 1 + 2; |
2579 | 2722 | } |
@@ -2584,28 +2727,33 @@ discard block |
||
2584 | 2727 | if (isset($tag['quoted'])) |
2585 | 2728 | { |
2586 | 2729 | $quoted = substr($message, $pos1, 6) == '"'; |
2587 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
2588 | - continue; |
|
2730 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
2731 | + continue; |
|
2732 | + } |
|
2589 | 2733 | |
2590 | - if ($quoted) |
|
2591 | - $pos1 += 6; |
|
2734 | + if ($quoted) { |
|
2735 | + $pos1 += 6; |
|
2736 | + } |
|
2737 | + } else { |
|
2738 | + $quoted = false; |
|
2592 | 2739 | } |
2593 | - else |
|
2594 | - $quoted = false; |
|
2595 | 2740 | |
2596 | 2741 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
2597 | - if ($pos2 === false) |
|
2598 | - continue; |
|
2742 | + if ($pos2 === false) { |
|
2743 | + continue; |
|
2744 | + } |
|
2599 | 2745 | |
2600 | 2746 | $data = substr($message, $pos1, $pos2 - $pos1); |
2601 | 2747 | |
2602 | 2748 | // Validation for my parking, please! |
2603 | - if (isset($tag['validate'])) |
|
2604 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2749 | + if (isset($tag['validate'])) { |
|
2750 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2751 | + } |
|
2605 | 2752 | |
2606 | 2753 | // For parsed content, we must recurse to avoid security problems. |
2607 | - if ($tag['type'] != 'unparsed_equals') |
|
2608 | - $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
2754 | + if ($tag['type'] != 'unparsed_equals') { |
|
2755 | + $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
2756 | + } |
|
2609 | 2757 | |
2610 | 2758 | $tag['after'] = strtr($tag['after'], array('$1' => $data)); |
2611 | 2759 | |
@@ -2617,34 +2765,40 @@ discard block |
||
2617 | 2765 | } |
2618 | 2766 | |
2619 | 2767 | // If this is block level, eat any breaks after it. |
2620 | - if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') |
|
2621 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
2768 | + if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') { |
|
2769 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
2770 | + } |
|
2622 | 2771 | |
2623 | 2772 | // Are we trimming outside this tag? |
2624 | - if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) |
|
2625 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
2773 | + if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) { |
|
2774 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
2775 | + } |
|
2626 | 2776 | } |
2627 | 2777 | |
2628 | 2778 | // Close any remaining tags. |
2629 | - while ($tag = array_pop($open_tags)) |
|
2630 | - $message .= "\n" . $tag['after'] . "\n"; |
|
2779 | + while ($tag = array_pop($open_tags)) { |
|
2780 | + $message .= "\n" . $tag['after'] . "\n"; |
|
2781 | + } |
|
2631 | 2782 | |
2632 | 2783 | // Parse the smileys within the parts where it can be done safely. |
2633 | 2784 | if ($smileys === true) |
2634 | 2785 | { |
2635 | 2786 | $message_parts = explode("\n", $message); |
2636 | - for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) |
|
2637 | - parsesmileys($message_parts[$i]); |
|
2787 | + for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) { |
|
2788 | + parsesmileys($message_parts[$i]); |
|
2789 | + } |
|
2638 | 2790 | |
2639 | 2791 | $message = implode('', $message_parts); |
2640 | 2792 | } |
2641 | 2793 | |
2642 | 2794 | // No smileys, just get rid of the markers. |
2643 | - else |
|
2644 | - $message = strtr($message, array("\n" => '')); |
|
2795 | + else { |
|
2796 | + $message = strtr($message, array("\n" => '')); |
|
2797 | + } |
|
2645 | 2798 | |
2646 | - if ($message !== '' && $message[0] === ' ') |
|
2647 | - $message = ' ' . substr($message, 1); |
|
2799 | + if ($message !== '' && $message[0] === ' ') { |
|
2800 | + $message = ' ' . substr($message, 1); |
|
2801 | + } |
|
2648 | 2802 | |
2649 | 2803 | // Cleanup whitespace. |
2650 | 2804 | $message = strtr($message, array(' ' => ' ', "\r" => '', "\n" => '<br>', '<br> ' => '<br> ', ' ' => "\n")); |
@@ -2653,15 +2807,16 @@ discard block |
||
2653 | 2807 | call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
2654 | 2808 | |
2655 | 2809 | // Cache the output if it took some time... |
2656 | - if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) |
|
2657 | - cache_put_data($cache_key, $message, 240); |
|
2810 | + if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) { |
|
2811 | + cache_put_data($cache_key, $message, 240); |
|
2812 | + } |
|
2658 | 2813 | |
2659 | 2814 | // If this was a force parse revert if needed. |
2660 | 2815 | if (!empty($parse_tags)) |
2661 | 2816 | { |
2662 | - if (empty($temp_bbc)) |
|
2663 | - $bbc_codes = array(); |
|
2664 | - else |
|
2817 | + if (empty($temp_bbc)) { |
|
2818 | + $bbc_codes = array(); |
|
2819 | + } else |
|
2665 | 2820 | { |
2666 | 2821 | $bbc_codes = $temp_bbc; |
2667 | 2822 | unset($temp_bbc); |
@@ -2688,8 +2843,9 @@ discard block |
||
2688 | 2843 | static $smileyPregSearch = null, $smileyPregReplacements = array(); |
2689 | 2844 | |
2690 | 2845 | // No smiley set at all?! |
2691 | - if ($user_info['smiley_set'] == 'none' || trim($message) == '') |
|
2692 | - return; |
|
2846 | + if ($user_info['smiley_set'] == 'none' || trim($message) == '') { |
|
2847 | + return; |
|
2848 | + } |
|
2693 | 2849 | |
2694 | 2850 | // If smileyPregSearch hasn't been set, do it now. |
2695 | 2851 | if (empty($smileyPregSearch)) |
@@ -2700,8 +2856,7 @@ discard block |
||
2700 | 2856 | $smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)'); |
2701 | 2857 | $smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif'); |
2702 | 2858 | $smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', ''); |
2703 | - } |
|
2704 | - else |
|
2859 | + } else |
|
2705 | 2860 | { |
2706 | 2861 | // Load the smileys in reverse order by length so they don't get parsed wrong. |
2707 | 2862 | if (($temp = cache_get_data('parsing_smileys', 480)) == null) |
@@ -2725,9 +2880,9 @@ discard block |
||
2725 | 2880 | $smcFunc['db_free_result']($result); |
2726 | 2881 | |
2727 | 2882 | cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480); |
2883 | + } else { |
|
2884 | + list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
2728 | 2885 | } |
2729 | - else |
|
2730 | - list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
2731 | 2886 | } |
2732 | 2887 | |
2733 | 2888 | // The non-breaking-space is a complex thing... |
@@ -2804,35 +2959,41 @@ discard block |
||
2804 | 2959 | global $scripturl, $context, $modSettings, $db_show_debug, $db_cache; |
2805 | 2960 | |
2806 | 2961 | // In case we have mail to send, better do that - as obExit doesn't always quite make it... |
2807 | - if (!empty($context['flush_mail'])) |
|
2808 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2962 | + if (!empty($context['flush_mail'])) { |
|
2963 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2809 | 2964 | AddMailQueue(true); |
2965 | + } |
|
2810 | 2966 | |
2811 | 2967 | $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:'; |
2812 | 2968 | |
2813 | - if ($add) |
|
2814 | - $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
2969 | + if ($add) { |
|
2970 | + $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
2971 | + } |
|
2815 | 2972 | |
2816 | 2973 | // Put the session ID in. |
2817 | - if (defined('SID') && SID != '') |
|
2818 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
2974 | + if (defined('SID') && SID != '') { |
|
2975 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
2976 | + } |
|
2819 | 2977 | // Keep that debug in their for template debugging! |
2820 | - elseif (isset($_GET['debug'])) |
|
2821 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
2978 | + elseif (isset($_GET['debug'])) { |
|
2979 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
2980 | + } |
|
2822 | 2981 | |
2823 | 2982 | if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed']))) |
2824 | 2983 | { |
2825 | - if (defined('SID') && SID != '') |
|
2826 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
2984 | + if (defined('SID') && SID != '') { |
|
2985 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
2827 | 2986 | function ($m) use ($scripturl) |
2828 | 2987 | { |
2829 | 2988 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); |
2989 | + } |
|
2830 | 2990 | }, $setLocation); |
2831 | - else |
|
2832 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
2991 | + else { |
|
2992 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
2833 | 2993 | function ($m) use ($scripturl) |
2834 | 2994 | { |
2835 | 2995 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); |
2996 | + } |
|
2836 | 2997 | }, $setLocation); |
2837 | 2998 | } |
2838 | 2999 | |
@@ -2843,8 +3004,9 @@ discard block |
||
2843 | 3004 | header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302); |
2844 | 3005 | |
2845 | 3006 | // Debugging. |
2846 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
2847 | - $_SESSION['debug_redirect'] = $db_cache; |
|
3007 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
3008 | + $_SESSION['debug_redirect'] = $db_cache; |
|
3009 | + } |
|
2848 | 3010 | |
2849 | 3011 | obExit(false); |
2850 | 3012 | } |
@@ -2863,51 +3025,60 @@ discard block |
||
2863 | 3025 | |
2864 | 3026 | // Attempt to prevent a recursive loop. |
2865 | 3027 | ++$level; |
2866 | - if ($level > 1 && !$from_fatal_error && !$has_fatal_error) |
|
2867 | - exit; |
|
2868 | - if ($from_fatal_error) |
|
2869 | - $has_fatal_error = true; |
|
3028 | + if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { |
|
3029 | + exit; |
|
3030 | + } |
|
3031 | + if ($from_fatal_error) { |
|
3032 | + $has_fatal_error = true; |
|
3033 | + } |
|
2870 | 3034 | |
2871 | 3035 | // Clear out the stat cache. |
2872 | 3036 | trackStats(); |
2873 | 3037 | |
2874 | 3038 | // If we have mail to send, send it. |
2875 | - if (!empty($context['flush_mail'])) |
|
2876 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
3039 | + if (!empty($context['flush_mail'])) { |
|
3040 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2877 | 3041 | AddMailQueue(true); |
3042 | + } |
|
2878 | 3043 | |
2879 | 3044 | $do_header = $header === null ? !$header_done : $header; |
2880 | - if ($do_footer === null) |
|
2881 | - $do_footer = $do_header; |
|
3045 | + if ($do_footer === null) { |
|
3046 | + $do_footer = $do_header; |
|
3047 | + } |
|
2882 | 3048 | |
2883 | 3049 | // Has the template/header been done yet? |
2884 | 3050 | if ($do_header) |
2885 | 3051 | { |
2886 | 3052 | // Was the page title set last minute? Also update the HTML safe one. |
2887 | - if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) |
|
2888 | - $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
3053 | + if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { |
|
3054 | + $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
3055 | + } |
|
2889 | 3056 | |
2890 | 3057 | // Start up the session URL fixer. |
2891 | 3058 | ob_start('ob_sessrewrite'); |
2892 | 3059 | |
2893 | - if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) |
|
2894 | - $buffers = explode(',', $settings['output_buffers']); |
|
2895 | - elseif (!empty($settings['output_buffers'])) |
|
2896 | - $buffers = $settings['output_buffers']; |
|
2897 | - else |
|
2898 | - $buffers = array(); |
|
3060 | + if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) { |
|
3061 | + $buffers = explode(',', $settings['output_buffers']); |
|
3062 | + } elseif (!empty($settings['output_buffers'])) { |
|
3063 | + $buffers = $settings['output_buffers']; |
|
3064 | + } else { |
|
3065 | + $buffers = array(); |
|
3066 | + } |
|
2899 | 3067 | |
2900 | - if (isset($modSettings['integrate_buffer'])) |
|
2901 | - $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
3068 | + if (isset($modSettings['integrate_buffer'])) { |
|
3069 | + $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
3070 | + } |
|
2902 | 3071 | |
2903 | - if (!empty($buffers)) |
|
2904 | - foreach ($buffers as $function) |
|
3072 | + if (!empty($buffers)) { |
|
3073 | + foreach ($buffers as $function) |
|
2905 | 3074 | { |
2906 | 3075 | $call = call_helper($function, true); |
3076 | + } |
|
2907 | 3077 | |
2908 | 3078 | // Is it valid? |
2909 | - if (!empty($call)) |
|
2910 | - ob_start($call); |
|
3079 | + if (!empty($call)) { |
|
3080 | + ob_start($call); |
|
3081 | + } |
|
2911 | 3082 | } |
2912 | 3083 | |
2913 | 3084 | // Display the screen in the logical order. |
@@ -2919,8 +3090,9 @@ discard block |
||
2919 | 3090 | loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); |
2920 | 3091 | |
2921 | 3092 | // Anything special to put out? |
2922 | - if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) |
|
2923 | - echo $context['insert_after_template']; |
|
3093 | + if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) { |
|
3094 | + echo $context['insert_after_template']; |
|
3095 | + } |
|
2924 | 3096 | |
2925 | 3097 | // Just so we don't get caught in an endless loop of errors from the footer... |
2926 | 3098 | if (!$footer_done) |
@@ -2929,14 +3101,16 @@ discard block |
||
2929 | 3101 | template_footer(); |
2930 | 3102 | |
2931 | 3103 | // (since this is just debugging... it's okay that it's after </html>.) |
2932 | - if (!isset($_REQUEST['xml'])) |
|
2933 | - displayDebug(); |
|
3104 | + if (!isset($_REQUEST['xml'])) { |
|
3105 | + displayDebug(); |
|
3106 | + } |
|
2934 | 3107 | } |
2935 | 3108 | } |
2936 | 3109 | |
2937 | 3110 | // Remember this URL in case someone doesn't like sending HTTP_REFERER. |
2938 | - if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) |
|
2939 | - $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
3111 | + if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { |
|
3112 | + $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
3113 | + } |
|
2940 | 3114 | |
2941 | 3115 | // For session check verification.... don't switch browsers... |
2942 | 3116 | $_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT']; |
@@ -2945,9 +3119,10 @@ discard block |
||
2945 | 3119 | call_integration_hook('integrate_exit', array($do_footer)); |
2946 | 3120 | |
2947 | 3121 | // Don't exit if we're coming from index.php; that will pass through normally. |
2948 | - if (!$from_index) |
|
2949 | - exit; |
|
2950 | -} |
|
3122 | + if (!$from_index) { |
|
3123 | + exit; |
|
3124 | + } |
|
3125 | + } |
|
2951 | 3126 | |
2952 | 3127 | /** |
2953 | 3128 | * Get the size of a specified image with better error handling. |
@@ -2966,8 +3141,9 @@ discard block |
||
2966 | 3141 | $url = str_replace(' ', '%20', $url); |
2967 | 3142 | |
2968 | 3143 | // Can we pull this from the cache... please please? |
2969 | - if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) |
|
2970 | - return $temp; |
|
3144 | + if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) { |
|
3145 | + return $temp; |
|
3146 | + } |
|
2971 | 3147 | $t = microtime(); |
2972 | 3148 | |
2973 | 3149 | // Get the host to pester... |
@@ -2977,12 +3153,10 @@ discard block |
||
2977 | 3153 | if ($url == '' || $url == 'http://' || $url == 'https://') |
2978 | 3154 | { |
2979 | 3155 | return false; |
2980 | - } |
|
2981 | - elseif (!isset($match[1])) |
|
3156 | + } elseif (!isset($match[1])) |
|
2982 | 3157 | { |
2983 | 3158 | $size = @getimagesize($url); |
2984 | - } |
|
2985 | - else |
|
3159 | + } else |
|
2986 | 3160 | { |
2987 | 3161 | // Try to connect to the server... give it half a second. |
2988 | 3162 | $temp = 0; |
@@ -3021,12 +3195,14 @@ discard block |
||
3021 | 3195 | } |
3022 | 3196 | |
3023 | 3197 | // If we didn't get it, we failed. |
3024 | - if (!isset($size)) |
|
3025 | - $size = false; |
|
3198 | + if (!isset($size)) { |
|
3199 | + $size = false; |
|
3200 | + } |
|
3026 | 3201 | |
3027 | 3202 | // If this took a long time, we may never have to do it again, but then again we might... |
3028 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) |
|
3029 | - cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3203 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) { |
|
3204 | + cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3205 | + } |
|
3030 | 3206 | |
3031 | 3207 | // Didn't work. |
3032 | 3208 | return $size; |
@@ -3044,8 +3220,9 @@ discard block |
||
3044 | 3220 | |
3045 | 3221 | // Under SSI this function can be called more then once. That can cause some problems. |
3046 | 3222 | // So only run the function once unless we are forced to run it again. |
3047 | - if ($loaded && !$forceload) |
|
3048 | - return; |
|
3223 | + if ($loaded && !$forceload) { |
|
3224 | + return; |
|
3225 | + } |
|
3049 | 3226 | |
3050 | 3227 | $loaded = true; |
3051 | 3228 | |
@@ -3057,14 +3234,16 @@ discard block |
||
3057 | 3234 | $context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))))); |
3058 | 3235 | for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++) |
3059 | 3236 | { |
3060 | - if (trim($context['news_lines'][$i]) == '') |
|
3061 | - continue; |
|
3237 | + if (trim($context['news_lines'][$i]) == '') { |
|
3238 | + continue; |
|
3239 | + } |
|
3062 | 3240 | |
3063 | 3241 | // Clean it up for presentation ;). |
3064 | 3242 | $context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i); |
3065 | 3243 | } |
3066 | - if (!empty($context['news_lines'])) |
|
3067 | - $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
3244 | + if (!empty($context['news_lines'])) { |
|
3245 | + $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
3246 | + } |
|
3068 | 3247 | |
3069 | 3248 | if (!$user_info['is_guest']) |
3070 | 3249 | { |
@@ -3073,40 +3252,48 @@ discard block |
||
3073 | 3252 | $context['user']['alerts'] = &$user_info['alerts']; |
3074 | 3253 | |
3075 | 3254 | // Personal message popup... |
3076 | - if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) |
|
3077 | - $context['user']['popup_messages'] = true; |
|
3078 | - else |
|
3079 | - $context['user']['popup_messages'] = false; |
|
3255 | + if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) { |
|
3256 | + $context['user']['popup_messages'] = true; |
|
3257 | + } else { |
|
3258 | + $context['user']['popup_messages'] = false; |
|
3259 | + } |
|
3080 | 3260 | $_SESSION['unread_messages'] = $user_info['unread_messages']; |
3081 | 3261 | |
3082 | - if (allowedTo('moderate_forum')) |
|
3083 | - $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
3262 | + if (allowedTo('moderate_forum')) { |
|
3263 | + $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
3264 | + } |
|
3084 | 3265 | |
3085 | 3266 | $context['user']['avatar'] = array(); |
3086 | 3267 | |
3087 | 3268 | // Check for gravatar first since we might be forcing them... |
3088 | 3269 | if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride'])) |
3089 | 3270 | { |
3090 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) |
|
3091 | - $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
3092 | - else |
|
3093 | - $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
3271 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) { |
|
3272 | + $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
3273 | + } else { |
|
3274 | + $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
3275 | + } |
|
3094 | 3276 | } |
3095 | 3277 | // Uploaded? |
3096 | - elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) |
|
3097 | - $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; |
|
3278 | + elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) { |
|
3279 | + $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; |
|
3280 | + } |
|
3098 | 3281 | // Full URL? |
3099 | - elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) |
|
3100 | - $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
3282 | + elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) { |
|
3283 | + $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
3284 | + } |
|
3101 | 3285 | // Otherwise we assume it's server stored. |
3102 | - elseif ($user_info['avatar']['url'] != '') |
|
3103 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
3286 | + elseif ($user_info['avatar']['url'] != '') { |
|
3287 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
3288 | + } |
|
3104 | 3289 | // No avatar at all? Fine, we have a big fat default avatar ;) |
3105 | - else |
|
3106 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
3290 | + else { |
|
3291 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
3292 | + } |
|
3107 | 3293 | |
3108 | - if (!empty($context['user']['avatar'])) |
|
3109 | - $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
3294 | + if (!empty($context['user']['avatar'])) { |
|
3295 | + $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
3296 | + } |
|
3110 | 3297 | |
3111 | 3298 | // Figure out how long they've been logged in. |
3112 | 3299 | $context['user']['total_time_logged_in'] = array( |
@@ -3114,8 +3301,7 @@ discard block |
||
3114 | 3301 | 'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600), |
3115 | 3302 | 'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60) |
3116 | 3303 | ); |
3117 | - } |
|
3118 | - else |
|
3304 | + } else |
|
3119 | 3305 | { |
3120 | 3306 | $context['user']['messages'] = 0; |
3121 | 3307 | $context['user']['unread_messages'] = 0; |
@@ -3123,12 +3309,14 @@ discard block |
||
3123 | 3309 | $context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0); |
3124 | 3310 | $context['user']['popup_messages'] = false; |
3125 | 3311 | |
3126 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) |
|
3127 | - $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
3312 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) { |
|
3313 | + $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
3314 | + } |
|
3128 | 3315 | |
3129 | 3316 | // If we've upgraded recently, go easy on the passwords. |
3130 | - if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) |
|
3131 | - $context['disable_login_hashing'] = true; |
|
3317 | + if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) { |
|
3318 | + $context['disable_login_hashing'] = true; |
|
3319 | + } |
|
3132 | 3320 | } |
3133 | 3321 | |
3134 | 3322 | // Setup the main menu items. |
@@ -3141,8 +3329,8 @@ discard block |
||
3141 | 3329 | $context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm'); |
3142 | 3330 | |
3143 | 3331 | // 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array. |
3144 | - if ($context['show_pm_popup']) |
|
3145 | - addInlineJavaScript(' |
|
3332 | + if ($context['show_pm_popup']) { |
|
3333 | + addInlineJavaScript(' |
|
3146 | 3334 | jQuery(document).ready(function($) { |
3147 | 3335 | new smc_Popup({ |
3148 | 3336 | heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ', |
@@ -3150,15 +3338,17 @@ discard block |
||
3150 | 3338 | icon_class: \'generic_icons mail_new\' |
3151 | 3339 | }); |
3152 | 3340 | });'); |
3341 | + } |
|
3153 | 3342 | |
3154 | 3343 | // Add a generic "Are you sure?" confirmation message. |
3155 | 3344 | addInlineJavaScript(' |
3156 | 3345 | var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); |
3157 | 3346 | |
3158 | 3347 | // Now add the capping code for avatars. |
3159 | - if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') |
|
3160 | - addInlineCss(' |
|
3348 | + if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') { |
|
3349 | + addInlineCss(' |
|
3161 | 3350 | img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }'); |
3351 | + } |
|
3162 | 3352 | |
3163 | 3353 | // This looks weird, but it's because BoardIndex.php references the variable. |
3164 | 3354 | $context['common_stats']['latest_member'] = array( |
@@ -3175,11 +3365,13 @@ discard block |
||
3175 | 3365 | ); |
3176 | 3366 | $context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']); |
3177 | 3367 | |
3178 | - if (empty($settings['theme_version'])) |
|
3179 | - addJavaScriptVar('smf_scripturl', $scripturl); |
|
3368 | + if (empty($settings['theme_version'])) { |
|
3369 | + addJavaScriptVar('smf_scripturl', $scripturl); |
|
3370 | + } |
|
3180 | 3371 | |
3181 | - if (!isset($context['page_title'])) |
|
3182 | - $context['page_title'] = ''; |
|
3372 | + if (!isset($context['page_title'])) { |
|
3373 | + $context['page_title'] = ''; |
|
3374 | + } |
|
3183 | 3375 | |
3184 | 3376 | // Set some specific vars. |
3185 | 3377 | $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
@@ -3189,21 +3381,23 @@ discard block |
||
3189 | 3381 | $context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']); |
3190 | 3382 | $context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']); |
3191 | 3383 | |
3192 | - if (!empty($context['meta_keywords'])) |
|
3193 | - $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
3384 | + if (!empty($context['meta_keywords'])) { |
|
3385 | + $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
3386 | + } |
|
3194 | 3387 | |
3195 | - if (!empty($context['canonical_url'])) |
|
3196 | - $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
3388 | + if (!empty($context['canonical_url'])) { |
|
3389 | + $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
3390 | + } |
|
3197 | 3391 | |
3198 | - if (!empty($settings['og_image'])) |
|
3199 | - $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
3392 | + if (!empty($settings['og_image'])) { |
|
3393 | + $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
3394 | + } |
|
3200 | 3395 | |
3201 | 3396 | if (!empty($context['meta_description'])) |
3202 | 3397 | { |
3203 | 3398 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']); |
3204 | 3399 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']); |
3205 | - } |
|
3206 | - else |
|
3400 | + } else |
|
3207 | 3401 | { |
3208 | 3402 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']); |
3209 | 3403 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']); |
@@ -3228,8 +3422,9 @@ discard block |
||
3228 | 3422 | $memory_needed = memoryReturnBytes($needed); |
3229 | 3423 | |
3230 | 3424 | // should we account for how much is currently being used? |
3231 | - if ($in_use) |
|
3232 | - $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
3425 | + if ($in_use) { |
|
3426 | + $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
3427 | + } |
|
3233 | 3428 | |
3234 | 3429 | // if more is needed, request it |
3235 | 3430 | if ($memory_current < $memory_needed) |
@@ -3252,8 +3447,9 @@ discard block |
||
3252 | 3447 | */ |
3253 | 3448 | function memoryReturnBytes($val) |
3254 | 3449 | { |
3255 | - if (is_integer($val)) |
|
3256 | - return $val; |
|
3450 | + if (is_integer($val)) { |
|
3451 | + return $val; |
|
3452 | + } |
|
3257 | 3453 | |
3258 | 3454 | // Separate the number from the designator |
3259 | 3455 | $val = trim($val); |
@@ -3289,10 +3485,11 @@ discard block |
||
3289 | 3485 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
3290 | 3486 | |
3291 | 3487 | // Are we debugging the template/html content? |
3292 | - if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) |
|
3293 | - header('Content-Type: application/xhtml+xml'); |
|
3294 | - elseif (!isset($_REQUEST['xml'])) |
|
3295 | - header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3488 | + if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) { |
|
3489 | + header('Content-Type: application/xhtml+xml'); |
|
3490 | + } elseif (!isset($_REQUEST['xml'])) { |
|
3491 | + header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3492 | + } |
|
3296 | 3493 | } |
3297 | 3494 | |
3298 | 3495 | header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
@@ -3301,8 +3498,9 @@ discard block |
||
3301 | 3498 | if ($context['in_maintenance'] && $context['user']['is_admin']) |
3302 | 3499 | { |
3303 | 3500 | $position = array_search('body', $context['template_layers']); |
3304 | - if ($position === false) |
|
3305 | - $position = array_search('main', $context['template_layers']); |
|
3501 | + if ($position === false) { |
|
3502 | + $position = array_search('main', $context['template_layers']); |
|
3503 | + } |
|
3306 | 3504 | |
3307 | 3505 | if ($position !== false) |
3308 | 3506 | { |
@@ -3330,23 +3528,25 @@ discard block |
||
3330 | 3528 | |
3331 | 3529 | foreach ($securityFiles as $i => $securityFile) |
3332 | 3530 | { |
3333 | - if (!file_exists($boarddir . '/' . $securityFile)) |
|
3334 | - unset($securityFiles[$i]); |
|
3531 | + if (!file_exists($boarddir . '/' . $securityFile)) { |
|
3532 | + unset($securityFiles[$i]); |
|
3533 | + } |
|
3335 | 3534 | } |
3336 | 3535 | |
3337 | 3536 | // We are already checking so many files...just few more doesn't make any difference! :P |
3338 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
3339 | - $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
3340 | - |
|
3341 | - else |
|
3342 | - $path = $modSettings['attachmentUploadDir']; |
|
3537 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
3538 | + $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
3539 | + } else { |
|
3540 | + $path = $modSettings['attachmentUploadDir']; |
|
3541 | + } |
|
3343 | 3542 | |
3344 | 3543 | secureDirectory($path, true); |
3345 | 3544 | secureDirectory($cachedir); |
3346 | 3545 | |
3347 | 3546 | // If agreement is enabled, at least the english version shall exists |
3348 | - if ($modSettings['requireAgreement']) |
|
3349 | - $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
3547 | + if ($modSettings['requireAgreement']) { |
|
3548 | + $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
3549 | + } |
|
3350 | 3550 | |
3351 | 3551 | if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement)) |
3352 | 3552 | { |
@@ -3361,18 +3561,21 @@ discard block |
||
3361 | 3561 | echo ' |
3362 | 3562 | ', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>'; |
3363 | 3563 | |
3364 | - if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') |
|
3365 | - echo ' |
|
3564 | + if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') { |
|
3565 | + echo ' |
|
3366 | 3566 | ', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>'; |
3567 | + } |
|
3367 | 3568 | } |
3368 | 3569 | |
3369 | - if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) |
|
3370 | - echo ' |
|
3570 | + if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) { |
|
3571 | + echo ' |
|
3371 | 3572 | <strong>', $txt['cache_writable'], '</strong><br>'; |
3573 | + } |
|
3372 | 3574 | |
3373 | - if (!empty($agreement)) |
|
3374 | - echo ' |
|
3575 | + if (!empty($agreement)) { |
|
3576 | + echo ' |
|
3375 | 3577 | <strong>', $txt['agreement_missing'], '</strong><br>'; |
3578 | + } |
|
3376 | 3579 | |
3377 | 3580 | echo ' |
3378 | 3581 | </p> |
@@ -3387,16 +3590,18 @@ discard block |
||
3387 | 3590 | <div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;"> |
3388 | 3591 | ', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']); |
3389 | 3592 | |
3390 | - if (!empty($_SESSION['ban']['cannot_post']['reason'])) |
|
3391 | - echo ' |
|
3593 | + if (!empty($_SESSION['ban']['cannot_post']['reason'])) { |
|
3594 | + echo ' |
|
3392 | 3595 | <div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>'; |
3596 | + } |
|
3393 | 3597 | |
3394 | - if (!empty($_SESSION['ban']['expire_time'])) |
|
3395 | - echo ' |
|
3598 | + if (!empty($_SESSION['ban']['expire_time'])) { |
|
3599 | + echo ' |
|
3396 | 3600 | <div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>'; |
3397 | - else |
|
3398 | - echo ' |
|
3601 | + } else { |
|
3602 | + echo ' |
|
3399 | 3603 | <div>', $txt['your_ban_expires_never'], '</div>'; |
3604 | + } |
|
3400 | 3605 | |
3401 | 3606 | echo ' |
3402 | 3607 | </div>'; |
@@ -3412,8 +3617,9 @@ discard block |
||
3412 | 3617 | global $forum_copyright, $software_year, $forum_version; |
3413 | 3618 | |
3414 | 3619 | // Don't display copyright for things like SSI. |
3415 | - if (!isset($forum_version) || !isset($software_year)) |
|
3416 | - return; |
|
3620 | + if (!isset($forum_version) || !isset($software_year)) { |
|
3621 | + return; |
|
3622 | + } |
|
3417 | 3623 | |
3418 | 3624 | // Put in the version... |
3419 | 3625 | printf($forum_copyright, $forum_version, $software_year); |
@@ -3431,9 +3637,10 @@ discard block |
||
3431 | 3637 | $context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3)); |
3432 | 3638 | $context['load_queries'] = $db_count; |
3433 | 3639 | |
3434 | - foreach (array_reverse($context['template_layers']) as $layer) |
|
3435 | - loadSubTemplate($layer . '_below', true); |
|
3436 | -} |
|
3640 | + foreach (array_reverse($context['template_layers']) as $layer) { |
|
3641 | + loadSubTemplate($layer . '_below', true); |
|
3642 | + } |
|
3643 | + } |
|
3437 | 3644 | |
3438 | 3645 | /** |
3439 | 3646 | * Output the Javascript files |
@@ -3464,8 +3671,7 @@ discard block |
||
3464 | 3671 | { |
3465 | 3672 | echo ' |
3466 | 3673 | var ', $key, ';'; |
3467 | - } |
|
3468 | - else |
|
3674 | + } else |
|
3469 | 3675 | { |
3470 | 3676 | echo ' |
3471 | 3677 | var ', $key, ' = ', $value, ';'; |
@@ -3480,26 +3686,27 @@ discard block |
||
3480 | 3686 | foreach ($context['javascript_files'] as $id => $js_file) |
3481 | 3687 | { |
3482 | 3688 | // Last minute call! allow theme authors to disable single files. |
3483 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
3484 | - continue; |
|
3689 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
3690 | + continue; |
|
3691 | + } |
|
3485 | 3692 | |
3486 | 3693 | // By default all files don't get minimized unless the file explicitly says so! |
3487 | 3694 | if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
3488 | 3695 | { |
3489 | - if ($do_deferred && !empty($js_file['options']['defer'])) |
|
3490 | - $toMinifyDefer[] = $js_file; |
|
3491 | - |
|
3492 | - elseif (!$do_deferred && empty($js_file['options']['defer'])) |
|
3493 | - $toMinify[] = $js_file; |
|
3696 | + if ($do_deferred && !empty($js_file['options']['defer'])) { |
|
3697 | + $toMinifyDefer[] = $js_file; |
|
3698 | + } elseif (!$do_deferred && empty($js_file['options']['defer'])) { |
|
3699 | + $toMinify[] = $js_file; |
|
3700 | + } |
|
3494 | 3701 | |
3495 | 3702 | // Grab a random seed. |
3496 | - if (!isset($minSeed)) |
|
3497 | - $minSeed = $js_file['options']['seed']; |
|
3498 | - } |
|
3499 | - |
|
3500 | - elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) |
|
3501 | - echo ' |
|
3703 | + if (!isset($minSeed)) { |
|
3704 | + $minSeed = $js_file['options']['seed']; |
|
3705 | + } |
|
3706 | + } elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) { |
|
3707 | + echo ' |
|
3502 | 3708 | <script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>'; |
3709 | + } |
|
3503 | 3710 | } |
3504 | 3711 | |
3505 | 3712 | if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer))) |
@@ -3507,14 +3714,14 @@ discard block |
||
3507 | 3714 | $result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred); |
3508 | 3715 | |
3509 | 3716 | // Minify process couldn't work, print each individual files. |
3510 | - if (!empty($result) && is_array($result)) |
|
3511 | - foreach ($result as $minFailedFile) |
|
3717 | + if (!empty($result) && is_array($result)) { |
|
3718 | + foreach ($result as $minFailedFile) |
|
3512 | 3719 | echo ' |
3513 | 3720 | <script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>'; |
3514 | - |
|
3515 | - else |
|
3516 | - echo ' |
|
3721 | + } else { |
|
3722 | + echo ' |
|
3517 | 3723 | <script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>'; |
3724 | + } |
|
3518 | 3725 | } |
3519 | 3726 | |
3520 | 3727 | // Inline JavaScript - Actually useful some times! |
@@ -3525,8 +3732,9 @@ discard block |
||
3525 | 3732 | echo ' |
3526 | 3733 | <script>'; |
3527 | 3734 | |
3528 | - foreach ($context['javascript_inline']['defer'] as $js_code) |
|
3529 | - echo $js_code; |
|
3735 | + foreach ($context['javascript_inline']['defer'] as $js_code) { |
|
3736 | + echo $js_code; |
|
3737 | + } |
|
3530 | 3738 | |
3531 | 3739 | echo ' |
3532 | 3740 | </script>'; |
@@ -3537,8 +3745,9 @@ discard block |
||
3537 | 3745 | echo ' |
3538 | 3746 | <script>'; |
3539 | 3747 | |
3540 | - foreach ($context['javascript_inline']['standard'] as $js_code) |
|
3541 | - echo $js_code; |
|
3748 | + foreach ($context['javascript_inline']['standard'] as $js_code) { |
|
3749 | + echo $js_code; |
|
3750 | + } |
|
3542 | 3751 | |
3543 | 3752 | echo ' |
3544 | 3753 | </script>'; |
@@ -3563,8 +3772,9 @@ discard block |
||
3563 | 3772 | foreach ($context['css_files'] as $id => $file) |
3564 | 3773 | { |
3565 | 3774 | // Last minute call! allow theme authors to disable single files. |
3566 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
3567 | - continue; |
|
3775 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
3776 | + continue; |
|
3777 | + } |
|
3568 | 3778 | |
3569 | 3779 | // By default all files don't get minimized unless the file explicitly says so! |
3570 | 3780 | if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
@@ -3572,12 +3782,12 @@ discard block |
||
3572 | 3782 | $toMinify[] = $file; |
3573 | 3783 | |
3574 | 3784 | // Grab a random seed. |
3575 | - if (!isset($minSeed)) |
|
3576 | - $minSeed = $file['options']['seed']; |
|
3785 | + if (!isset($minSeed)) { |
|
3786 | + $minSeed = $file['options']['seed']; |
|
3787 | + } |
|
3788 | + } else { |
|
3789 | + $normal[] = $file['fileUrl']; |
|
3577 | 3790 | } |
3578 | - |
|
3579 | - else |
|
3580 | - $normal[] = $file['fileUrl']; |
|
3581 | 3791 | } |
3582 | 3792 | |
3583 | 3793 | if (!empty($toMinify)) |
@@ -3585,28 +3795,30 @@ discard block |
||
3585 | 3795 | $result = custMinify($toMinify, 'css'); |
3586 | 3796 | |
3587 | 3797 | // Minify process couldn't work, print each individual files. |
3588 | - if (!empty($result) && is_array($result)) |
|
3589 | - foreach ($result as $minFailedFile) |
|
3798 | + if (!empty($result) && is_array($result)) { |
|
3799 | + foreach ($result as $minFailedFile) |
|
3590 | 3800 | echo ' |
3591 | 3801 | <link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">'; |
3592 | - |
|
3593 | - else |
|
3594 | - echo ' |
|
3802 | + } else { |
|
3803 | + echo ' |
|
3595 | 3804 | <link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">'; |
3805 | + } |
|
3596 | 3806 | } |
3597 | 3807 | |
3598 | 3808 | // Print the rest after the minified files. |
3599 | - if (!empty($normal)) |
|
3600 | - foreach ($normal as $nf) |
|
3809 | + if (!empty($normal)) { |
|
3810 | + foreach ($normal as $nf) |
|
3601 | 3811 | echo ' |
3602 | 3812 | <link rel="stylesheet" href="', $nf ,'">'; |
3813 | + } |
|
3603 | 3814 | |
3604 | 3815 | if ($db_show_debug === true) |
3605 | 3816 | { |
3606 | 3817 | // Try to keep only what's useful. |
3607 | 3818 | $repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => ''); |
3608 | - foreach ($context['css_files'] as $file) |
|
3609 | - $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
3819 | + foreach ($context['css_files'] as $file) { |
|
3820 | + $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
3821 | + } |
|
3610 | 3822 | } |
3611 | 3823 | |
3612 | 3824 | if (!empty($context['css_header'])) |
@@ -3614,9 +3826,10 @@ discard block |
||
3614 | 3826 | echo ' |
3615 | 3827 | <style>'; |
3616 | 3828 | |
3617 | - foreach ($context['css_header'] as $css) |
|
3618 | - echo $css .' |
|
3829 | + foreach ($context['css_header'] as $css) { |
|
3830 | + echo $css .' |
|
3619 | 3831 | '; |
3832 | + } |
|
3620 | 3833 | |
3621 | 3834 | echo' |
3622 | 3835 | </style>'; |
@@ -3640,15 +3853,17 @@ discard block |
||
3640 | 3853 | $type = !empty($type) && in_array($type, $types) ? $type : false; |
3641 | 3854 | $data = !empty($data) ? $data : false; |
3642 | 3855 | |
3643 | - if (empty($type) || empty($data)) |
|
3644 | - return false; |
|
3856 | + if (empty($type) || empty($data)) { |
|
3857 | + return false; |
|
3858 | + } |
|
3645 | 3859 | |
3646 | 3860 | // Did we already did this? |
3647 | 3861 | $toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400); |
3648 | 3862 | |
3649 | 3863 | // Already done? |
3650 | - if (!empty($toCache)) |
|
3651 | - return true; |
|
3864 | + if (!empty($toCache)) { |
|
3865 | + return true; |
|
3866 | + } |
|
3652 | 3867 | |
3653 | 3868 | // No namespaces, sorry! |
3654 | 3869 | $classType = 'MatthiasMullie\\Minify\\'. strtoupper($type); |
@@ -3730,8 +3945,9 @@ discard block |
||
3730 | 3945 | global $modSettings, $smcFunc; |
3731 | 3946 | |
3732 | 3947 | // Just make up a nice hash... |
3733 | - if ($new) |
|
3734 | - return sha1(md5($filename . time()) . mt_rand()); |
|
3948 | + if ($new) { |
|
3949 | + return sha1(md5($filename . time()) . mt_rand()); |
|
3950 | + } |
|
3735 | 3951 | |
3736 | 3952 | // Just make sure that attachment id is only a int |
3737 | 3953 | $attachment_id = (int) $attachment_id; |
@@ -3748,23 +3964,25 @@ discard block |
||
3748 | 3964 | 'id_attach' => $attachment_id, |
3749 | 3965 | )); |
3750 | 3966 | |
3751 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
3752 | - return false; |
|
3967 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
3968 | + return false; |
|
3969 | + } |
|
3753 | 3970 | |
3754 | 3971 | list ($file_hash) = $smcFunc['db_fetch_row']($request); |
3755 | 3972 | $smcFunc['db_free_result']($request); |
3756 | 3973 | } |
3757 | 3974 | |
3758 | 3975 | // Still no hash? mmm... |
3759 | - if (empty($file_hash)) |
|
3760 | - $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
3976 | + if (empty($file_hash)) { |
|
3977 | + $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
3978 | + } |
|
3761 | 3979 | |
3762 | 3980 | // Are we using multiple directories? |
3763 | - if (is_array($modSettings['attachmentUploadDir'])) |
|
3764 | - $path = $modSettings['attachmentUploadDir'][$dir]; |
|
3765 | - |
|
3766 | - else |
|
3767 | - $path = $modSettings['attachmentUploadDir']; |
|
3981 | + if (is_array($modSettings['attachmentUploadDir'])) { |
|
3982 | + $path = $modSettings['attachmentUploadDir'][$dir]; |
|
3983 | + } else { |
|
3984 | + $path = $modSettings['attachmentUploadDir']; |
|
3985 | + } |
|
3768 | 3986 | |
3769 | 3987 | return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; |
3770 | 3988 | } |
@@ -3779,8 +3997,9 @@ discard block |
||
3779 | 3997 | function ip2range($fullip) |
3780 | 3998 | { |
3781 | 3999 | // Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.) |
3782 | - if ($fullip == 'unknown') |
|
3783 | - $fullip = '255.255.255.255'; |
|
4000 | + if ($fullip == 'unknown') { |
|
4001 | + $fullip = '255.255.255.255'; |
|
4002 | + } |
|
3784 | 4003 | |
3785 | 4004 | $ip_parts = explode('-', $fullip); |
3786 | 4005 | $ip_array = array(); |
@@ -3804,10 +4023,11 @@ discard block |
||
3804 | 4023 | $ip_array['low'] = $ip_parts[0]; |
3805 | 4024 | $ip_array['high'] = $ip_parts[1]; |
3806 | 4025 | return $ip_array; |
3807 | - } |
|
3808 | - elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.* |
|
4026 | + } elseif (count($ip_parts) == 2) { |
|
4027 | + // if ip 22.22.*-22.22.* |
|
3809 | 4028 | { |
3810 | 4029 | $valid_low = isValidIP($ip_parts[0]); |
4030 | + } |
|
3811 | 4031 | $valid_high = isValidIP($ip_parts[1]); |
3812 | 4032 | $count = 0; |
3813 | 4033 | $mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); |
@@ -3822,7 +4042,9 @@ discard block |
||
3822 | 4042 | $ip_parts[0] .= $mode . $min; |
3823 | 4043 | $valid_low = isValidIP($ip_parts[0]); |
3824 | 4044 | $count++; |
3825 | - if ($count > 9) break; |
|
4045 | + if ($count > 9) { |
|
4046 | + break; |
|
4047 | + } |
|
3826 | 4048 | } |
3827 | 4049 | } |
3828 | 4050 | |
@@ -3836,7 +4058,9 @@ discard block |
||
3836 | 4058 | $ip_parts[1] .= $mode . $max; |
3837 | 4059 | $valid_high = isValidIP($ip_parts[1]); |
3838 | 4060 | $count++; |
3839 | - if ($count > 9) break; |
|
4061 | + if ($count > 9) { |
|
4062 | + break; |
|
4063 | + } |
|
3840 | 4064 | } |
3841 | 4065 | } |
3842 | 4066 | |
@@ -3861,46 +4085,54 @@ discard block |
||
3861 | 4085 | { |
3862 | 4086 | global $modSettings; |
3863 | 4087 | |
3864 | - if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) |
|
3865 | - return $host; |
|
4088 | + if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) { |
|
4089 | + return $host; |
|
4090 | + } |
|
3866 | 4091 | $t = microtime(); |
3867 | 4092 | |
3868 | 4093 | // Try the Linux host command, perhaps? |
3869 | 4094 | if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1) |
3870 | 4095 | { |
3871 | - if (!isset($modSettings['host_to_dis'])) |
|
3872 | - $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
3873 | - else |
|
3874 | - $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
4096 | + if (!isset($modSettings['host_to_dis'])) { |
|
4097 | + $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
4098 | + } else { |
|
4099 | + $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
4100 | + } |
|
3875 | 4101 | |
3876 | 4102 | // Did host say it didn't find anything? |
3877 | - if (strpos($test, 'not found') !== false) |
|
3878 | - $host = ''; |
|
4103 | + if (strpos($test, 'not found') !== false) { |
|
4104 | + $host = ''; |
|
4105 | + } |
|
3879 | 4106 | // Invalid server option? |
3880 | - elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) |
|
3881 | - updateSettings(array('host_to_dis' => 1)); |
|
4107 | + elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) { |
|
4108 | + updateSettings(array('host_to_dis' => 1)); |
|
4109 | + } |
|
3882 | 4110 | // Maybe it found something, after all? |
3883 | - elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) |
|
3884 | - $host = $match[1]; |
|
4111 | + elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) { |
|
4112 | + $host = $match[1]; |
|
4113 | + } |
|
3885 | 4114 | } |
3886 | 4115 | |
3887 | 4116 | // This is nslookup; usually only Windows, but possibly some Unix? |
3888 | 4117 | if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1) |
3889 | 4118 | { |
3890 | 4119 | $test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip)); |
3891 | - if (strpos($test, 'Non-existent domain') !== false) |
|
3892 | - $host = ''; |
|
3893 | - elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) |
|
3894 | - $host = $match[1]; |
|
4120 | + if (strpos($test, 'Non-existent domain') !== false) { |
|
4121 | + $host = ''; |
|
4122 | + } elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) { |
|
4123 | + $host = $match[1]; |
|
4124 | + } |
|
3895 | 4125 | } |
3896 | 4126 | |
3897 | 4127 | // This is the last try :/. |
3898 | - if (!isset($host) || $host === false) |
|
3899 | - $host = @gethostbyaddr($ip); |
|
4128 | + if (!isset($host) || $host === false) { |
|
4129 | + $host = @gethostbyaddr($ip); |
|
4130 | + } |
|
3900 | 4131 | |
3901 | 4132 | // It took a long time, so let's cache it! |
3902 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) |
|
3903 | - cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4133 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) { |
|
4134 | + cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4135 | + } |
|
3904 | 4136 | |
3905 | 4137 | return $host; |
3906 | 4138 | } |
@@ -3936,20 +4168,21 @@ discard block |
||
3936 | 4168 | { |
3937 | 4169 | $encrypted = substr(crypt($word, 'uk'), 2, $max_chars); |
3938 | 4170 | $total = 0; |
3939 | - for ($i = 0; $i < $max_chars; $i++) |
|
3940 | - $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
4171 | + for ($i = 0; $i < $max_chars; $i++) { |
|
4172 | + $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
4173 | + } |
|
3941 | 4174 | $returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total; |
3942 | 4175 | } |
3943 | 4176 | } |
3944 | 4177 | return array_unique($returned_ints); |
3945 | - } |
|
3946 | - else |
|
4178 | + } else |
|
3947 | 4179 | { |
3948 | 4180 | // Trim characters before and after and add slashes for database insertion. |
3949 | 4181 | $returned_words = array(); |
3950 | - foreach ($words as $word) |
|
3951 | - if (($word = trim($word, '-_\'')) !== '') |
|
4182 | + foreach ($words as $word) { |
|
4183 | + if (($word = trim($word, '-_\'')) !== '') |
|
3952 | 4184 | $returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars); |
4185 | + } |
|
3953 | 4186 | |
3954 | 4187 | // Filter out all words that occur more than once. |
3955 | 4188 | return array_unique($returned_words); |
@@ -3971,16 +4204,18 @@ discard block |
||
3971 | 4204 | global $settings, $txt; |
3972 | 4205 | |
3973 | 4206 | // Does the current loaded theme have this and we are not forcing the usage of this function? |
3974 | - if (function_exists('template_create_button') && !$force_use) |
|
3975 | - return template_create_button($name, $alt, $label = '', $custom = ''); |
|
4207 | + if (function_exists('template_create_button') && !$force_use) { |
|
4208 | + return template_create_button($name, $alt, $label = '', $custom = ''); |
|
4209 | + } |
|
3976 | 4210 | |
3977 | - if (!$settings['use_image_buttons']) |
|
3978 | - return $txt[$alt]; |
|
3979 | - elseif (!empty($settings['use_buttons'])) |
|
3980 | - return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
3981 | - else |
|
3982 | - return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
3983 | -} |
|
4211 | + if (!$settings['use_image_buttons']) { |
|
4212 | + return $txt[$alt]; |
|
4213 | + } elseif (!empty($settings['use_buttons'])) { |
|
4214 | + return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
4215 | + } else { |
|
4216 | + return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
4217 | + } |
|
4218 | + } |
|
3984 | 4219 | |
3985 | 4220 | /** |
3986 | 4221 | * Sets up all of the top menu buttons |
@@ -4023,9 +4258,10 @@ discard block |
||
4023 | 4258 | var user_menus = new smc_PopupMenu(); |
4024 | 4259 | user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); |
4025 | 4260 | user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); |
4026 | - if ($context['allow_pm']) |
|
4027 | - addInlineJavaScript(' |
|
4261 | + if ($context['allow_pm']) { |
|
4262 | + addInlineJavaScript(' |
|
4028 | 4263 | user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); |
4264 | + } |
|
4029 | 4265 | |
4030 | 4266 | if (!empty($modSettings['enable_ajax_alerts'])) |
4031 | 4267 | { |
@@ -4185,88 +4421,96 @@ discard block |
||
4185 | 4421 | |
4186 | 4422 | // Now we put the buttons in the context so the theme can use them. |
4187 | 4423 | $menu_buttons = array(); |
4188 | - foreach ($buttons as $act => $button) |
|
4189 | - if (!empty($button['show'])) |
|
4424 | + foreach ($buttons as $act => $button) { |
|
4425 | + if (!empty($button['show'])) |
|
4190 | 4426 | { |
4191 | 4427 | $button['active_button'] = false; |
4428 | + } |
|
4192 | 4429 | |
4193 | 4430 | // This button needs some action. |
4194 | - if (isset($button['action_hook'])) |
|
4195 | - $needs_action_hook = true; |
|
4431 | + if (isset($button['action_hook'])) { |
|
4432 | + $needs_action_hook = true; |
|
4433 | + } |
|
4196 | 4434 | |
4197 | 4435 | // Make sure the last button truly is the last button. |
4198 | 4436 | if (!empty($button['is_last'])) |
4199 | 4437 | { |
4200 | - if (isset($last_button)) |
|
4201 | - unset($menu_buttons[$last_button]['is_last']); |
|
4438 | + if (isset($last_button)) { |
|
4439 | + unset($menu_buttons[$last_button]['is_last']); |
|
4440 | + } |
|
4202 | 4441 | $last_button = $act; |
4203 | 4442 | } |
4204 | 4443 | |
4205 | 4444 | // Go through the sub buttons if there are any. |
4206 | - if (!empty($button['sub_buttons'])) |
|
4207 | - foreach ($button['sub_buttons'] as $key => $subbutton) |
|
4445 | + if (!empty($button['sub_buttons'])) { |
|
4446 | + foreach ($button['sub_buttons'] as $key => $subbutton) |
|
4208 | 4447 | { |
4209 | 4448 | if (empty($subbutton['show'])) |
4210 | 4449 | unset($button['sub_buttons'][$key]); |
4450 | + } |
|
4211 | 4451 | |
4212 | 4452 | // 2nd level sub buttons next... |
4213 | 4453 | if (!empty($subbutton['sub_buttons'])) |
4214 | 4454 | { |
4215 | 4455 | foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2) |
4216 | 4456 | { |
4217 | - if (empty($sub_button2['show'])) |
|
4218 | - unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
4457 | + if (empty($sub_button2['show'])) { |
|
4458 | + unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
4459 | + } |
|
4219 | 4460 | } |
4220 | 4461 | } |
4221 | 4462 | } |
4222 | 4463 | |
4223 | 4464 | // Does this button have its own icon? |
4224 | - if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) |
|
4225 | - $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4226 | - elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) |
|
4227 | - $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4228 | - elseif (isset($button['icon'])) |
|
4229 | - $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
4230 | - else |
|
4231 | - $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
4465 | + if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) { |
|
4466 | + $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4467 | + } elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) { |
|
4468 | + $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4469 | + } elseif (isset($button['icon'])) { |
|
4470 | + $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
4471 | + } else { |
|
4472 | + $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
4473 | + } |
|
4232 | 4474 | |
4233 | 4475 | $menu_buttons[$act] = $button; |
4234 | 4476 | } |
4235 | 4477 | |
4236 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
4237 | - cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
4478 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
4479 | + cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
4480 | + } |
|
4238 | 4481 | } |
4239 | 4482 | |
4240 | 4483 | $context['menu_buttons'] = $menu_buttons; |
4241 | 4484 | |
4242 | 4485 | // Logging out requires the session id in the url. |
4243 | - if (isset($context['menu_buttons']['logout'])) |
|
4244 | - $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
4486 | + if (isset($context['menu_buttons']['logout'])) { |
|
4487 | + $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
4488 | + } |
|
4245 | 4489 | |
4246 | 4490 | // Figure out which action we are doing so we can set the active tab. |
4247 | 4491 | // Default to home. |
4248 | 4492 | $current_action = 'home'; |
4249 | 4493 | |
4250 | - if (isset($context['menu_buttons'][$context['current_action']])) |
|
4251 | - $current_action = $context['current_action']; |
|
4252 | - elseif ($context['current_action'] == 'search2') |
|
4253 | - $current_action = 'search'; |
|
4254 | - elseif ($context['current_action'] == 'theme') |
|
4255 | - $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
4256 | - elseif ($context['current_action'] == 'register2') |
|
4257 | - $current_action = 'register'; |
|
4258 | - elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) |
|
4259 | - $current_action = 'login'; |
|
4260 | - elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) |
|
4261 | - $current_action = 'moderate'; |
|
4494 | + if (isset($context['menu_buttons'][$context['current_action']])) { |
|
4495 | + $current_action = $context['current_action']; |
|
4496 | + } elseif ($context['current_action'] == 'search2') { |
|
4497 | + $current_action = 'search'; |
|
4498 | + } elseif ($context['current_action'] == 'theme') { |
|
4499 | + $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
4500 | + } elseif ($context['current_action'] == 'register2') { |
|
4501 | + $current_action = 'register'; |
|
4502 | + } elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) { |
|
4503 | + $current_action = 'login'; |
|
4504 | + } elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) { |
|
4505 | + $current_action = 'moderate'; |
|
4506 | + } |
|
4262 | 4507 | |
4263 | 4508 | // There are certain exceptions to the above where we don't want anything on the menu highlighted. |
4264 | 4509 | if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner'])) |
4265 | 4510 | { |
4266 | 4511 | $current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile'; |
4267 | 4512 | $context[$current_action] = true; |
4268 | - } |
|
4269 | - elseif ($context['current_action'] == 'pm') |
|
4513 | + } elseif ($context['current_action'] == 'pm') |
|
4270 | 4514 | { |
4271 | 4515 | $current_action = 'self_pm'; |
4272 | 4516 | $context['self_pm'] = true; |
@@ -4309,12 +4553,14 @@ discard block |
||
4309 | 4553 | } |
4310 | 4554 | |
4311 | 4555 | // Not all actions are simple. |
4312 | - if (!empty($needs_action_hook)) |
|
4313 | - call_integration_hook('integrate_current_action', array(&$current_action)); |
|
4556 | + if (!empty($needs_action_hook)) { |
|
4557 | + call_integration_hook('integrate_current_action', array(&$current_action)); |
|
4558 | + } |
|
4314 | 4559 | |
4315 | - if (isset($context['menu_buttons'][$current_action])) |
|
4316 | - $context['menu_buttons'][$current_action]['active_button'] = true; |
|
4317 | -} |
|
4560 | + if (isset($context['menu_buttons'][$current_action])) { |
|
4561 | + $context['menu_buttons'][$current_action]['active_button'] = true; |
|
4562 | + } |
|
4563 | + } |
|
4318 | 4564 | |
4319 | 4565 | /** |
4320 | 4566 | * Generate a random seed and ensure it's stored in settings. |
@@ -4338,30 +4584,35 @@ discard block |
||
4338 | 4584 | global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug; |
4339 | 4585 | global $context, $txt; |
4340 | 4586 | |
4341 | - if ($db_show_debug === true) |
|
4342 | - $context['debug']['hooks'][] = $hook; |
|
4587 | + if ($db_show_debug === true) { |
|
4588 | + $context['debug']['hooks'][] = $hook; |
|
4589 | + } |
|
4343 | 4590 | |
4344 | 4591 | // Need to have some control. |
4345 | - if (!isset($context['instances'])) |
|
4346 | - $context['instances'] = array(); |
|
4592 | + if (!isset($context['instances'])) { |
|
4593 | + $context['instances'] = array(); |
|
4594 | + } |
|
4347 | 4595 | |
4348 | 4596 | $results = array(); |
4349 | - if (empty($modSettings[$hook])) |
|
4350 | - return $results; |
|
4597 | + if (empty($modSettings[$hook])) { |
|
4598 | + return $results; |
|
4599 | + } |
|
4351 | 4600 | |
4352 | 4601 | $functions = explode(',', $modSettings[$hook]); |
4353 | 4602 | // Loop through each function. |
4354 | 4603 | foreach ($functions as $function) |
4355 | 4604 | { |
4356 | 4605 | // Hook has been marked as "disabled". Skip it! |
4357 | - if (strpos($function, '!') !== false) |
|
4358 | - continue; |
|
4606 | + if (strpos($function, '!') !== false) { |
|
4607 | + continue; |
|
4608 | + } |
|
4359 | 4609 | |
4360 | 4610 | $call = call_helper($function, true); |
4361 | 4611 | |
4362 | 4612 | // Is it valid? |
4363 | - if (!empty($call)) |
|
4364 | - $results[$function] = call_user_func_array($call, $parameters); |
|
4613 | + if (!empty($call)) { |
|
4614 | + $results[$function] = call_user_func_array($call, $parameters); |
|
4615 | + } |
|
4365 | 4616 | |
4366 | 4617 | // Whatever it was suppose to call, it failed :( |
4367 | 4618 | elseif (!empty($function)) |
@@ -4377,8 +4628,9 @@ discard block |
||
4377 | 4628 | } |
4378 | 4629 | |
4379 | 4630 | // "Assume" the file resides on $boarddir somewhere... |
4380 | - else |
|
4381 | - log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
4631 | + else { |
|
4632 | + log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
4633 | + } |
|
4382 | 4634 | } |
4383 | 4635 | } |
4384 | 4636 | |
@@ -4400,12 +4652,14 @@ discard block |
||
4400 | 4652 | global $smcFunc, $modSettings; |
4401 | 4653 | |
4402 | 4654 | // Any objects? |
4403 | - if ($object) |
|
4404 | - $function = $function . '#'; |
|
4655 | + if ($object) { |
|
4656 | + $function = $function . '#'; |
|
4657 | + } |
|
4405 | 4658 | |
4406 | 4659 | // Any files to load? |
4407 | - if (!empty($file) && is_string($file)) |
|
4408 | - $function = $file . (!empty($function) ? '|' . $function : ''); |
|
4660 | + if (!empty($file) && is_string($file)) { |
|
4661 | + $function = $file . (!empty($function) ? '|' . $function : ''); |
|
4662 | + } |
|
4409 | 4663 | |
4410 | 4664 | // Get the correct string. |
4411 | 4665 | $integration_call = $function; |
@@ -4427,13 +4681,14 @@ discard block |
||
4427 | 4681 | if (!empty($current_functions)) |
4428 | 4682 | { |
4429 | 4683 | $current_functions = explode(',', $current_functions); |
4430 | - if (in_array($integration_call, $current_functions)) |
|
4431 | - return; |
|
4684 | + if (in_array($integration_call, $current_functions)) { |
|
4685 | + return; |
|
4686 | + } |
|
4432 | 4687 | |
4433 | 4688 | $permanent_functions = array_merge($current_functions, array($integration_call)); |
4689 | + } else { |
|
4690 | + $permanent_functions = array($integration_call); |
|
4434 | 4691 | } |
4435 | - else |
|
4436 | - $permanent_functions = array($integration_call); |
|
4437 | 4692 | |
4438 | 4693 | updateSettings(array($hook => implode(',', $permanent_functions))); |
4439 | 4694 | } |
@@ -4442,8 +4697,9 @@ discard block |
||
4442 | 4697 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
4443 | 4698 | |
4444 | 4699 | // Do nothing, if it's already there. |
4445 | - if (in_array($integration_call, $functions)) |
|
4446 | - return; |
|
4700 | + if (in_array($integration_call, $functions)) { |
|
4701 | + return; |
|
4702 | + } |
|
4447 | 4703 | |
4448 | 4704 | $functions[] = $integration_call; |
4449 | 4705 | $modSettings[$hook] = implode(',', $functions); |
@@ -4466,12 +4722,14 @@ discard block |
||
4466 | 4722 | global $smcFunc, $modSettings; |
4467 | 4723 | |
4468 | 4724 | // Any objects? |
4469 | - if ($object) |
|
4470 | - $function = $function . '#'; |
|
4725 | + if ($object) { |
|
4726 | + $function = $function . '#'; |
|
4727 | + } |
|
4471 | 4728 | |
4472 | 4729 | // Any files to load? |
4473 | - if (!empty($file) && is_string($file)) |
|
4474 | - $function = $file . '|' . $function; |
|
4730 | + if (!empty($file) && is_string($file)) { |
|
4731 | + $function = $file . '|' . $function; |
|
4732 | + } |
|
4475 | 4733 | |
4476 | 4734 | // Get the correct string. |
4477 | 4735 | $integration_call = $function; |
@@ -4492,16 +4750,18 @@ discard block |
||
4492 | 4750 | { |
4493 | 4751 | $current_functions = explode(',', $current_functions); |
4494 | 4752 | |
4495 | - if (in_array($integration_call, $current_functions)) |
|
4496 | - updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
4753 | + if (in_array($integration_call, $current_functions)) { |
|
4754 | + updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
4755 | + } |
|
4497 | 4756 | } |
4498 | 4757 | |
4499 | 4758 | // Turn the function list into something usable. |
4500 | 4759 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
4501 | 4760 | |
4502 | 4761 | // You can only remove it if it's available. |
4503 | - if (!in_array($integration_call, $functions)) |
|
4504 | - return; |
|
4762 | + if (!in_array($integration_call, $functions)) { |
|
4763 | + return; |
|
4764 | + } |
|
4505 | 4765 | |
4506 | 4766 | $functions = array_diff($functions, array($integration_call)); |
4507 | 4767 | $modSettings[$hook] = implode(',', $functions); |
@@ -4522,17 +4782,20 @@ discard block |
||
4522 | 4782 | global $context, $smcFunc, $txt, $db_show_debug; |
4523 | 4783 | |
4524 | 4784 | // Really? |
4525 | - if (empty($string)) |
|
4526 | - return false; |
|
4785 | + if (empty($string)) { |
|
4786 | + return false; |
|
4787 | + } |
|
4527 | 4788 | |
4528 | 4789 | // An array? should be a "callable" array IE array(object/class, valid_callable). |
4529 | 4790 | // A closure? should be a callable one. |
4530 | - if (is_array($string) || $string instanceof Closure) |
|
4531 | - return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
4791 | + if (is_array($string) || $string instanceof Closure) { |
|
4792 | + return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
4793 | + } |
|
4532 | 4794 | |
4533 | 4795 | // No full objects, sorry! pass a method or a property instead! |
4534 | - if (is_object($string)) |
|
4535 | - return false; |
|
4796 | + if (is_object($string)) { |
|
4797 | + return false; |
|
4798 | + } |
|
4536 | 4799 | |
4537 | 4800 | // Stay vitaminized my friends... |
4538 | 4801 | $string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string)); |
@@ -4541,8 +4804,9 @@ discard block |
||
4541 | 4804 | $string = load_file($string); |
4542 | 4805 | |
4543 | 4806 | // Loaded file failed |
4544 | - if (empty($string)) |
|
4545 | - return false; |
|
4807 | + if (empty($string)) { |
|
4808 | + return false; |
|
4809 | + } |
|
4546 | 4810 | |
4547 | 4811 | // Found a method. |
4548 | 4812 | if (strpos($string, '::') !== false) |
@@ -4563,8 +4827,9 @@ discard block |
||
4563 | 4827 | // Add another one to the list. |
4564 | 4828 | if ($db_show_debug === true) |
4565 | 4829 | { |
4566 | - if (!isset($context['debug']['instances'])) |
|
4567 | - $context['debug']['instances'] = array(); |
|
4830 | + if (!isset($context['debug']['instances'])) { |
|
4831 | + $context['debug']['instances'] = array(); |
|
4832 | + } |
|
4568 | 4833 | |
4569 | 4834 | $context['debug']['instances'][$class] = $class; |
4570 | 4835 | } |
@@ -4574,13 +4839,15 @@ discard block |
||
4574 | 4839 | } |
4575 | 4840 | |
4576 | 4841 | // Right then. This is a call to a static method. |
4577 | - else |
|
4578 | - $func = array($class, $method); |
|
4842 | + else { |
|
4843 | + $func = array($class, $method); |
|
4844 | + } |
|
4579 | 4845 | } |
4580 | 4846 | |
4581 | 4847 | // Nope! just a plain regular function. |
4582 | - else |
|
4583 | - $func = $string; |
|
4848 | + else { |
|
4849 | + $func = $string; |
|
4850 | + } |
|
4584 | 4851 | |
4585 | 4852 | // Right, we got what we need, time to do some checks. |
4586 | 4853 | if (!is_callable($func, false, $callable_name)) |
@@ -4596,17 +4863,18 @@ discard block |
||
4596 | 4863 | else |
4597 | 4864 | { |
4598 | 4865 | // What are we gonna do about it? |
4599 | - if ($return) |
|
4600 | - return $func; |
|
4866 | + if ($return) { |
|
4867 | + return $func; |
|
4868 | + } |
|
4601 | 4869 | |
4602 | 4870 | // If this is a plain function, avoid the heat of calling call_user_func(). |
4603 | 4871 | else |
4604 | 4872 | { |
4605 | - if (is_array($func)) |
|
4606 | - call_user_func($func); |
|
4607 | - |
|
4608 | - else |
|
4609 | - $func(); |
|
4873 | + if (is_array($func)) { |
|
4874 | + call_user_func($func); |
|
4875 | + } else { |
|
4876 | + $func(); |
|
4877 | + } |
|
4610 | 4878 | } |
4611 | 4879 | } |
4612 | 4880 | } |
@@ -4623,31 +4891,34 @@ discard block |
||
4623 | 4891 | { |
4624 | 4892 | global $sourcedir, $txt, $boarddir, $settings; |
4625 | 4893 | |
4626 | - if (empty($string)) |
|
4627 | - return false; |
|
4894 | + if (empty($string)) { |
|
4895 | + return false; |
|
4896 | + } |
|
4628 | 4897 | |
4629 | 4898 | if (strpos($string, '|') !== false) |
4630 | 4899 | { |
4631 | 4900 | list ($file, $string) = explode('|', $string); |
4632 | 4901 | |
4633 | 4902 | // Match the wildcards to their regular vars. |
4634 | - if (empty($settings['theme_dir'])) |
|
4635 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
4636 | - |
|
4637 | - else |
|
4638 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
4903 | + if (empty($settings['theme_dir'])) { |
|
4904 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
4905 | + } else { |
|
4906 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
4907 | + } |
|
4639 | 4908 | |
4640 | 4909 | // Load the file if it can be loaded. |
4641 | - if (file_exists($absPath)) |
|
4642 | - require_once($absPath); |
|
4910 | + if (file_exists($absPath)) { |
|
4911 | + require_once($absPath); |
|
4912 | + } |
|
4643 | 4913 | |
4644 | 4914 | // No? try a fallback to $sourcedir |
4645 | 4915 | else |
4646 | 4916 | { |
4647 | 4917 | $absPath = $sourcedir .'/'. $file; |
4648 | 4918 | |
4649 | - if (file_exists($absPath)) |
|
4650 | - require_once($absPath); |
|
4919 | + if (file_exists($absPath)) { |
|
4920 | + require_once($absPath); |
|
4921 | + } |
|
4651 | 4922 | |
4652 | 4923 | // Sorry, can't do much for you at this point. |
4653 | 4924 | else |
@@ -4674,8 +4945,9 @@ discard block |
||
4674 | 4945 | global $user_info, $smcFunc; |
4675 | 4946 | |
4676 | 4947 | // Make sure we have something to work with. |
4677 | - if (empty($topic)) |
|
4678 | - return array(); |
|
4948 | + if (empty($topic)) { |
|
4949 | + return array(); |
|
4950 | + } |
|
4679 | 4951 | |
4680 | 4952 | |
4681 | 4953 | // We already know the number of likes per message, we just want to know whether the current user liked it or not. |
@@ -4698,8 +4970,9 @@ discard block |
||
4698 | 4970 | 'topic' => $topic, |
4699 | 4971 | ) |
4700 | 4972 | ); |
4701 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
4702 | - $temp[] = (int) $row['content_id']; |
|
4973 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
4974 | + $temp[] = (int) $row['content_id']; |
|
4975 | + } |
|
4703 | 4976 | |
4704 | 4977 | cache_put_data($cache_key, $temp, $ttl); |
4705 | 4978 | } |
@@ -4720,8 +4993,9 @@ discard block |
||
4720 | 4993 | { |
4721 | 4994 | global $context; |
4722 | 4995 | |
4723 | - if (empty($string)) |
|
4724 | - return $string; |
|
4996 | + if (empty($string)) { |
|
4997 | + return $string; |
|
4998 | + } |
|
4725 | 4999 | |
4726 | 5000 | // UTF-8 occurences of MS special characters |
4727 | 5001 | $findchars_utf8 = array( |
@@ -4762,10 +5036,11 @@ discard block |
||
4762 | 5036 | '--', // — |
4763 | 5037 | ); |
4764 | 5038 | |
4765 | - if ($context['utf8']) |
|
4766 | - $string = str_replace($findchars_utf8, $replacechars, $string); |
|
4767 | - else |
|
4768 | - $string = str_replace($findchars_iso, $replacechars, $string); |
|
5039 | + if ($context['utf8']) { |
|
5040 | + $string = str_replace($findchars_utf8, $replacechars, $string); |
|
5041 | + } else { |
|
5042 | + $string = str_replace($findchars_iso, $replacechars, $string); |
|
5043 | + } |
|
4769 | 5044 | |
4770 | 5045 | return $string; |
4771 | 5046 | } |
@@ -4784,49 +5059,59 @@ discard block |
||
4784 | 5059 | { |
4785 | 5060 | global $context; |
4786 | 5061 | |
4787 | - if (!isset($matches[2])) |
|
4788 | - return ''; |
|
5062 | + if (!isset($matches[2])) { |
|
5063 | + return ''; |
|
5064 | + } |
|
4789 | 5065 | |
4790 | 5066 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
4791 | 5067 | |
4792 | 5068 | // remove left to right / right to left overrides |
4793 | - if ($num === 0x202D || $num === 0x202E) |
|
4794 | - return ''; |
|
5069 | + if ($num === 0x202D || $num === 0x202E) { |
|
5070 | + return ''; |
|
5071 | + } |
|
4795 | 5072 | |
4796 | 5073 | // Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced |
4797 | - if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) |
|
4798 | - return '&#' . $num . ';'; |
|
5074 | + if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) { |
|
5075 | + return '&#' . $num . ';'; |
|
5076 | + } |
|
4799 | 5077 | |
4800 | 5078 | if (empty($context['utf8'])) |
4801 | 5079 | { |
4802 | 5080 | // no control characters |
4803 | - if ($num < 0x20) |
|
4804 | - return ''; |
|
5081 | + if ($num < 0x20) { |
|
5082 | + return ''; |
|
5083 | + } |
|
4805 | 5084 | // text is text |
4806 | - elseif ($num < 0x80) |
|
4807 | - return chr($num); |
|
5085 | + elseif ($num < 0x80) { |
|
5086 | + return chr($num); |
|
5087 | + } |
|
4808 | 5088 | // all others get html-ised |
4809 | - else |
|
4810 | - return '&#' . $matches[2] . ';'; |
|
4811 | - } |
|
4812 | - else |
|
5089 | + else { |
|
5090 | + return '&#' . $matches[2] . ';'; |
|
5091 | + } |
|
5092 | + } else |
|
4813 | 5093 | { |
4814 | 5094 | // <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set |
4815 | 5095 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text) |
4816 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) |
|
4817 | - return ''; |
|
5096 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) { |
|
5097 | + return ''; |
|
5098 | + } |
|
4818 | 5099 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
4819 | - elseif ($num < 0x80) |
|
4820 | - return chr($num); |
|
5100 | + elseif ($num < 0x80) { |
|
5101 | + return chr($num); |
|
5102 | + } |
|
4821 | 5103 | // <0x800 (2048) |
4822 | - elseif ($num < 0x800) |
|
4823 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5104 | + elseif ($num < 0x800) { |
|
5105 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5106 | + } |
|
4824 | 5107 | // < 0x10000 (65536) |
4825 | - elseif ($num < 0x10000) |
|
4826 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5108 | + elseif ($num < 0x10000) { |
|
5109 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5110 | + } |
|
4827 | 5111 | // <= 0x10FFFF (1114111) |
4828 | - else |
|
4829 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5112 | + else { |
|
5113 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5114 | + } |
|
4830 | 5115 | } |
4831 | 5116 | } |
4832 | 5117 | |
@@ -4842,28 +5127,34 @@ discard block |
||
4842 | 5127 | */ |
4843 | 5128 | function fixchar__callback($matches) |
4844 | 5129 | { |
4845 | - if (!isset($matches[1])) |
|
4846 | - return ''; |
|
5130 | + if (!isset($matches[1])) { |
|
5131 | + return ''; |
|
5132 | + } |
|
4847 | 5133 | |
4848 | 5134 | $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1]; |
4849 | 5135 | |
4850 | 5136 | // <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set |
4851 | 5137 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides |
4852 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) |
|
4853 | - return ''; |
|
5138 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) { |
|
5139 | + return ''; |
|
5140 | + } |
|
4854 | 5141 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
4855 | - elseif ($num < 0x80) |
|
4856 | - return chr($num); |
|
5142 | + elseif ($num < 0x80) { |
|
5143 | + return chr($num); |
|
5144 | + } |
|
4857 | 5145 | // <0x800 (2048) |
4858 | - elseif ($num < 0x800) |
|
4859 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5146 | + elseif ($num < 0x800) { |
|
5147 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5148 | + } |
|
4860 | 5149 | // < 0x10000 (65536) |
4861 | - elseif ($num < 0x10000) |
|
4862 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5150 | + elseif ($num < 0x10000) { |
|
5151 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5152 | + } |
|
4863 | 5153 | // <= 0x10FFFF (1114111) |
4864 | - else |
|
4865 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
4866 | -} |
|
5154 | + else { |
|
5155 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5156 | + } |
|
5157 | + } |
|
4867 | 5158 | |
4868 | 5159 | /** |
4869 | 5160 | * Strips out invalid html entities, replaces others with html style { codes |
@@ -4876,17 +5167,19 @@ discard block |
||
4876 | 5167 | */ |
4877 | 5168 | function entity_fix__callback($matches) |
4878 | 5169 | { |
4879 | - if (!isset($matches[2])) |
|
4880 | - return ''; |
|
5170 | + if (!isset($matches[2])) { |
|
5171 | + return ''; |
|
5172 | + } |
|
4881 | 5173 | |
4882 | 5174 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
4883 | 5175 | |
4884 | 5176 | // we don't allow control characters, characters out of range, byte markers, etc |
4885 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) |
|
4886 | - return ''; |
|
4887 | - else |
|
4888 | - return '&#' . $num . ';'; |
|
4889 | -} |
|
5177 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) { |
|
5178 | + return ''; |
|
5179 | + } else { |
|
5180 | + return '&#' . $num . ';'; |
|
5181 | + } |
|
5182 | + } |
|
4890 | 5183 | |
4891 | 5184 | /** |
4892 | 5185 | * Return a Gravatar URL based on |
@@ -4910,18 +5203,23 @@ discard block |
||
4910 | 5203 | $ratings = array('G', 'PG', 'R', 'X'); |
4911 | 5204 | $defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'); |
4912 | 5205 | $url_params = array(); |
4913 | - if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) |
|
4914 | - $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
4915 | - if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) |
|
4916 | - $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
4917 | - if (!empty($modSettings['avatar_max_width_external'])) |
|
4918 | - $size_string = (int) $modSettings['avatar_max_width_external']; |
|
4919 | - if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) |
|
4920 | - if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
5206 | + if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) { |
|
5207 | + $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
5208 | + } |
|
5209 | + if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) { |
|
5210 | + $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
5211 | + } |
|
5212 | + if (!empty($modSettings['avatar_max_width_external'])) { |
|
5213 | + $size_string = (int) $modSettings['avatar_max_width_external']; |
|
5214 | + } |
|
5215 | + if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) { |
|
5216 | + if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
4921 | 5217 | $size_string = $modSettings['avatar_max_height_external']; |
5218 | + } |
|
4922 | 5219 | |
4923 | - if (!empty($size_string)) |
|
4924 | - $url_params[] = 's=' . $size_string; |
|
5220 | + if (!empty($size_string)) { |
|
5221 | + $url_params[] = 's=' . $size_string; |
|
5222 | + } |
|
4925 | 5223 | } |
4926 | 5224 | $http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www'; |
4927 | 5225 | |
@@ -4940,22 +5238,26 @@ discard block |
||
4940 | 5238 | static $timezones = null, $lastwhen = null; |
4941 | 5239 | |
4942 | 5240 | // No point doing this over if we already did it once |
4943 | - if (!empty($timezones) && $when == $lastwhen) |
|
4944 | - return $timezones; |
|
4945 | - else |
|
4946 | - $lastwhen = $when; |
|
5241 | + if (!empty($timezones) && $when == $lastwhen) { |
|
5242 | + return $timezones; |
|
5243 | + } else { |
|
5244 | + $lastwhen = $when; |
|
5245 | + } |
|
4947 | 5246 | |
4948 | 5247 | // Parseable datetime string? |
4949 | - if (is_int($timestamp = strtotime($when))) |
|
4950 | - $when = $timestamp; |
|
5248 | + if (is_int($timestamp = strtotime($when))) { |
|
5249 | + $when = $timestamp; |
|
5250 | + } |
|
4951 | 5251 | |
4952 | 5252 | // A Unix timestamp? |
4953 | - elseif (is_numeric($when)) |
|
4954 | - $when = intval($when); |
|
5253 | + elseif (is_numeric($when)) { |
|
5254 | + $when = intval($when); |
|
5255 | + } |
|
4955 | 5256 | |
4956 | 5257 | // Invalid value? Just get current Unix timestamp. |
4957 | - else |
|
4958 | - $when = time(); |
|
5258 | + else { |
|
5259 | + $when = time(); |
|
5260 | + } |
|
4959 | 5261 | |
4960 | 5262 | // We'll need these too |
4961 | 5263 | $date_when = date_create('@' . $when); |
@@ -5019,8 +5321,9 @@ discard block |
||
5019 | 5321 | foreach ($priority_countries as $country) |
5020 | 5322 | { |
5021 | 5323 | $country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country))); |
5022 | - if (!empty($country_tzids)) |
|
5023 | - $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
5324 | + if (!empty($country_tzids)) { |
|
5325 | + $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
5326 | + } |
|
5024 | 5327 | } |
5025 | 5328 | |
5026 | 5329 | // Process the preferred timezones first, then the rest. |
@@ -5030,8 +5333,9 @@ discard block |
||
5030 | 5333 | foreach ($tzids as $tzid) |
5031 | 5334 | { |
5032 | 5335 | // We don't want UTC right now |
5033 | - if ($tzid == 'UTC') |
|
5034 | - continue; |
|
5336 | + if ($tzid == 'UTC') { |
|
5337 | + continue; |
|
5338 | + } |
|
5035 | 5339 | |
5036 | 5340 | $tz = timezone_open($tzid); |
5037 | 5341 | |
@@ -5046,12 +5350,14 @@ discard block |
||
5046 | 5350 | $tzgeo = timezone_location_get($tz); |
5047 | 5351 | |
5048 | 5352 | // Don't overwrite our preferred tzids |
5049 | - if (empty($zones[$tzkey]['tzid'])) |
|
5050 | - $zones[$tzkey]['tzid'] = $tzid; |
|
5353 | + if (empty($zones[$tzkey]['tzid'])) { |
|
5354 | + $zones[$tzkey]['tzid'] = $tzid; |
|
5355 | + } |
|
5051 | 5356 | |
5052 | 5357 | // A time zone from a prioritized country? |
5053 | - if (in_array($tzid, $priority_tzids)) |
|
5054 | - $priority_zones[$tzkey] = true; |
|
5358 | + if (in_array($tzid, $priority_tzids)) { |
|
5359 | + $priority_zones[$tzkey] = true; |
|
5360 | + } |
|
5055 | 5361 | |
5056 | 5362 | // Keep track of the location and offset for this tzid |
5057 | 5363 | $tzid_parts = explode('/', $tzid); |
@@ -5072,15 +5378,17 @@ discard block |
||
5072 | 5378 | |
5073 | 5379 | date_timezone_set($date_when, timezone_open($tzvalue['tzid'])); |
5074 | 5380 | |
5075 | - if (!empty($timezone_descriptions[$tzvalue['tzid']])) |
|
5076 | - $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
5077 | - else |
|
5078 | - $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
5381 | + if (!empty($timezone_descriptions[$tzvalue['tzid']])) { |
|
5382 | + $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
5383 | + } else { |
|
5384 | + $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
5385 | + } |
|
5079 | 5386 | |
5080 | - if (isset($priority_zones[$tzkey])) |
|
5081 | - $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
5082 | - else |
|
5083 | - $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
5387 | + if (isset($priority_zones[$tzkey])) { |
|
5388 | + $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
5389 | + } else { |
|
5390 | + $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
5391 | + } |
|
5084 | 5392 | } |
5085 | 5393 | |
5086 | 5394 | $timezones = array_merge( |
@@ -5134,9 +5442,9 @@ discard block |
||
5134 | 5442 | 'Indian/Kerguelen' => 'TFT', |
5135 | 5443 | ); |
5136 | 5444 | |
5137 | - if (!empty($missing_tz_abbrs[$tzid])) |
|
5138 | - $tz_abbrev = $missing_tz_abbrs[$tzid]; |
|
5139 | - else |
|
5445 | + if (!empty($missing_tz_abbrs[$tzid])) { |
|
5446 | + $tz_abbrev = $missing_tz_abbrs[$tzid]; |
|
5447 | + } else |
|
5140 | 5448 | { |
5141 | 5449 | // Russia likes to experiment with time zones often, and names them as offsets from Moscow |
5142 | 5450 | $tz_location = timezone_location_get(timezone_open($tzid)); |
@@ -5164,8 +5472,9 @@ discard block |
||
5164 | 5472 | */ |
5165 | 5473 | function inet_ptod($ip_address) |
5166 | 5474 | { |
5167 | - if (!isValidIP($ip_address)) |
|
5168 | - return $ip_address; |
|
5475 | + if (!isValidIP($ip_address)) { |
|
5476 | + return $ip_address; |
|
5477 | + } |
|
5169 | 5478 | |
5170 | 5479 | $bin = inet_pton($ip_address); |
5171 | 5480 | return $bin; |
@@ -5177,13 +5486,15 @@ discard block |
||
5177 | 5486 | */ |
5178 | 5487 | function inet_dtop($bin) |
5179 | 5488 | { |
5180 | - if(empty($bin)) |
|
5181 | - return ''; |
|
5489 | + if(empty($bin)) { |
|
5490 | + return ''; |
|
5491 | + } |
|
5182 | 5492 | |
5183 | 5493 | global $db_type; |
5184 | 5494 | |
5185 | - if ($db_type == 'postgresql') |
|
5186 | - return $bin; |
|
5495 | + if ($db_type == 'postgresql') { |
|
5496 | + return $bin; |
|
5497 | + } |
|
5187 | 5498 | |
5188 | 5499 | $ip_address = inet_ntop($bin); |
5189 | 5500 | |
@@ -5208,26 +5519,32 @@ discard block |
||
5208 | 5519 | */ |
5209 | 5520 | function _safe_serialize($value) |
5210 | 5521 | { |
5211 | - if(is_null($value)) |
|
5212 | - return 'N;'; |
|
5522 | + if(is_null($value)) { |
|
5523 | + return 'N;'; |
|
5524 | + } |
|
5213 | 5525 | |
5214 | - if(is_bool($value)) |
|
5215 | - return 'b:'. (int) $value .';'; |
|
5526 | + if(is_bool($value)) { |
|
5527 | + return 'b:'. (int) $value .';'; |
|
5528 | + } |
|
5216 | 5529 | |
5217 | - if(is_int($value)) |
|
5218 | - return 'i:'. $value .';'; |
|
5530 | + if(is_int($value)) { |
|
5531 | + return 'i:'. $value .';'; |
|
5532 | + } |
|
5219 | 5533 | |
5220 | - if(is_float($value)) |
|
5221 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
5534 | + if(is_float($value)) { |
|
5535 | + return 'd:'. str_replace(',', '.', $value) .';'; |
|
5536 | + } |
|
5222 | 5537 | |
5223 | - if(is_string($value)) |
|
5224 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
5538 | + if(is_string($value)) { |
|
5539 | + return 's:'. strlen($value) .':"'. $value .'";'; |
|
5540 | + } |
|
5225 | 5541 | |
5226 | 5542 | if(is_array($value)) |
5227 | 5543 | { |
5228 | 5544 | $out = ''; |
5229 | - foreach($value as $k => $v) |
|
5230 | - $out .= _safe_serialize($k) . _safe_serialize($v); |
|
5545 | + foreach($value as $k => $v) { |
|
5546 | + $out .= _safe_serialize($k) . _safe_serialize($v); |
|
5547 | + } |
|
5231 | 5548 | |
5232 | 5549 | return 'a:'. count($value) .':{'. $out .'}'; |
5233 | 5550 | } |
@@ -5253,8 +5570,9 @@ discard block |
||
5253 | 5570 | |
5254 | 5571 | $out = _safe_serialize($value); |
5255 | 5572 | |
5256 | - if (isset($mbIntEnc)) |
|
5257 | - mb_internal_encoding($mbIntEnc); |
|
5573 | + if (isset($mbIntEnc)) { |
|
5574 | + mb_internal_encoding($mbIntEnc); |
|
5575 | + } |
|
5258 | 5576 | |
5259 | 5577 | return $out; |
5260 | 5578 | } |
@@ -5271,8 +5589,9 @@ discard block |
||
5271 | 5589 | function _safe_unserialize($str) |
5272 | 5590 | { |
5273 | 5591 | // Input is not a string. |
5274 | - if(empty($str) || !is_string($str)) |
|
5275 | - return false; |
|
5592 | + if(empty($str) || !is_string($str)) { |
|
5593 | + return false; |
|
5594 | + } |
|
5276 | 5595 | |
5277 | 5596 | $stack = array(); |
5278 | 5597 | $expected = array(); |
@@ -5288,43 +5607,38 @@ discard block |
||
5288 | 5607 | while($state != 1) |
5289 | 5608 | { |
5290 | 5609 | $type = isset($str[0]) ? $str[0] : ''; |
5291 | - if($type == '}') |
|
5292 | - $str = substr($str, 1); |
|
5293 | - |
|
5294 | - else if($type == 'N' && $str[1] == ';') |
|
5610 | + if($type == '}') { |
|
5611 | + $str = substr($str, 1); |
|
5612 | + } else if($type == 'N' && $str[1] == ';') |
|
5295 | 5613 | { |
5296 | 5614 | $value = null; |
5297 | 5615 | $str = substr($str, 2); |
5298 | - } |
|
5299 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
5616 | + } else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
5300 | 5617 | { |
5301 | 5618 | $value = $matches[1] == '1' ? true : false; |
5302 | 5619 | $str = substr($str, 4); |
5303 | - } |
|
5304 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
5620 | + } else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
5305 | 5621 | { |
5306 | 5622 | $value = (int)$matches[1]; |
5307 | 5623 | $str = $matches[2]; |
5308 | - } |
|
5309 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
5624 | + } else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
5310 | 5625 | { |
5311 | 5626 | $value = (float)$matches[1]; |
5312 | 5627 | $str = $matches[3]; |
5313 | - } |
|
5314 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
5628 | + } else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
5315 | 5629 | { |
5316 | 5630 | $value = substr($matches[2], 0, (int)$matches[1]); |
5317 | 5631 | $str = substr($matches[2], (int)$matches[1] + 2); |
5318 | - } |
|
5319 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
5632 | + } else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
5320 | 5633 | { |
5321 | 5634 | $expectedLength = (int)$matches[1]; |
5322 | 5635 | $str = $matches[2]; |
5323 | 5636 | } |
5324 | 5637 | |
5325 | 5638 | // Object or unknown/malformed type. |
5326 | - else |
|
5327 | - return false; |
|
5639 | + else { |
|
5640 | + return false; |
|
5641 | + } |
|
5328 | 5642 | |
5329 | 5643 | switch($state) |
5330 | 5644 | { |
@@ -5352,8 +5666,9 @@ discard block |
||
5352 | 5666 | if($type == '}') |
5353 | 5667 | { |
5354 | 5668 | // Array size is less than expected. |
5355 | - if(count($list) < end($expected)) |
|
5356 | - return false; |
|
5669 | + if(count($list) < end($expected)) { |
|
5670 | + return false; |
|
5671 | + } |
|
5357 | 5672 | |
5358 | 5673 | unset($list); |
5359 | 5674 | $list = &$stack[count($stack)-1]; |
@@ -5362,8 +5677,9 @@ discard block |
||
5362 | 5677 | // Go to terminal state if we're at the end of the root array. |
5363 | 5678 | array_pop($expected); |
5364 | 5679 | |
5365 | - if(count($expected) == 0) |
|
5366 | - $state = 1; |
|
5680 | + if(count($expected) == 0) { |
|
5681 | + $state = 1; |
|
5682 | + } |
|
5367 | 5683 | |
5368 | 5684 | break; |
5369 | 5685 | } |
@@ -5371,8 +5687,9 @@ discard block |
||
5371 | 5687 | if($type == 'i' || $type == 's') |
5372 | 5688 | { |
5373 | 5689 | // Array size exceeds expected length. |
5374 | - if(count($list) >= end($expected)) |
|
5375 | - return false; |
|
5690 | + if(count($list) >= end($expected)) { |
|
5691 | + return false; |
|
5692 | + } |
|
5376 | 5693 | |
5377 | 5694 | $key = $value; |
5378 | 5695 | $state = 3; |
@@ -5406,8 +5723,9 @@ discard block |
||
5406 | 5723 | } |
5407 | 5724 | |
5408 | 5725 | // Trailing data in input. |
5409 | - if(!empty($str)) |
|
5410 | - return false; |
|
5726 | + if(!empty($str)) { |
|
5727 | + return false; |
|
5728 | + } |
|
5411 | 5729 | |
5412 | 5730 | return $data; |
5413 | 5731 | } |
@@ -5430,8 +5748,9 @@ discard block |
||
5430 | 5748 | |
5431 | 5749 | $out = _safe_unserialize($str); |
5432 | 5750 | |
5433 | - if (isset($mbIntEnc)) |
|
5434 | - mb_internal_encoding($mbIntEnc); |
|
5751 | + if (isset($mbIntEnc)) { |
|
5752 | + mb_internal_encoding($mbIntEnc); |
|
5753 | + } |
|
5435 | 5754 | |
5436 | 5755 | return $out; |
5437 | 5756 | } |
@@ -5446,12 +5765,14 @@ discard block |
||
5446 | 5765 | function smf_chmod($file, $value = 0) |
5447 | 5766 | { |
5448 | 5767 | // No file? no checks! |
5449 | - if (empty($file)) |
|
5450 | - return false; |
|
5768 | + if (empty($file)) { |
|
5769 | + return false; |
|
5770 | + } |
|
5451 | 5771 | |
5452 | 5772 | // Already writable? |
5453 | - if (is_writable($file)) |
|
5454 | - return true; |
|
5773 | + if (is_writable($file)) { |
|
5774 | + return true; |
|
5775 | + } |
|
5455 | 5776 | |
5456 | 5777 | // Do we have a file or a dir? |
5457 | 5778 | $isDir = is_dir($file); |
@@ -5467,10 +5788,9 @@ discard block |
||
5467 | 5788 | { |
5468 | 5789 | $isWritable = true; |
5469 | 5790 | break; |
5791 | + } else { |
|
5792 | + @chmod($file, $val); |
|
5470 | 5793 | } |
5471 | - |
|
5472 | - else |
|
5473 | - @chmod($file, $val); |
|
5474 | 5794 | } |
5475 | 5795 | |
5476 | 5796 | return $isWritable; |
@@ -5489,8 +5809,9 @@ discard block |
||
5489 | 5809 | global $txt; |
5490 | 5810 | |
5491 | 5811 | // Come on... |
5492 | - if (empty($json) || !is_string($json)) |
|
5493 | - return array(); |
|
5812 | + if (empty($json) || !is_string($json)) { |
|
5813 | + return array(); |
|
5814 | + } |
|
5494 | 5815 | |
5495 | 5816 | $returnArray = @json_decode($json, $returnAsArray); |
5496 | 5817 | |
@@ -5528,11 +5849,11 @@ discard block |
||
5528 | 5849 | $jsonDebug = $jsonDebug[0]; |
5529 | 5850 | loadLanguage('Errors'); |
5530 | 5851 | |
5531 | - if (!empty($jsonDebug)) |
|
5532 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
5533 | - |
|
5534 | - else |
|
5535 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
5852 | + if (!empty($jsonDebug)) { |
|
5853 | + log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
5854 | + } else { |
|
5855 | + log_error($txt['json_'. $jsonError], 'critical'); |
|
5856 | + } |
|
5536 | 5857 | |
5537 | 5858 | // Everyone expects an array. |
5538 | 5859 | return array(); |
@@ -5562,8 +5883,9 @@ discard block |
||
5562 | 5883 | global $db_show_debug, $modSettings; |
5563 | 5884 | |
5564 | 5885 | // Defensive programming anyone? |
5565 | - if (empty($data)) |
|
5566 | - return false; |
|
5886 | + if (empty($data)) { |
|
5887 | + return false; |
|
5888 | + } |
|
5567 | 5889 | |
5568 | 5890 | // Don't need extra stuff... |
5569 | 5891 | $db_show_debug = false; |
@@ -5571,11 +5893,11 @@ discard block |
||
5571 | 5893 | // Kill anything else. |
5572 | 5894 | ob_end_clean(); |
5573 | 5895 | |
5574 | - if (!empty($modSettings['CompressedOutput'])) |
|
5575 | - @ob_start('ob_gzhandler'); |
|
5576 | - |
|
5577 | - else |
|
5578 | - ob_start(); |
|
5896 | + if (!empty($modSettings['CompressedOutput'])) { |
|
5897 | + @ob_start('ob_gzhandler'); |
|
5898 | + } else { |
|
5899 | + ob_start(); |
|
5900 | + } |
|
5579 | 5901 | |
5580 | 5902 | // Set the header. |
5581 | 5903 | header($type); |
@@ -5607,8 +5929,9 @@ discard block |
||
5607 | 5929 | static $done = false; |
5608 | 5930 | |
5609 | 5931 | // If we don't need to do anything, don't |
5610 | - if (!$update && $done) |
|
5611 | - return; |
|
5932 | + if (!$update && $done) { |
|
5933 | + return; |
|
5934 | + } |
|
5612 | 5935 | |
5613 | 5936 | // Should we get a new copy of the official list of TLDs? |
5614 | 5937 | if ($update) |
@@ -5629,10 +5952,11 @@ discard block |
||
5629 | 5952 | // Clean $tlds and convert it to an array |
5630 | 5953 | $tlds = array_filter(explode("\n", strtolower($tlds)), function($line) { |
5631 | 5954 | $line = trim($line); |
5632 | - if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) |
|
5633 | - return false; |
|
5634 | - else |
|
5635 | - return true; |
|
5955 | + if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) { |
|
5956 | + return false; |
|
5957 | + } else { |
|
5958 | + return true; |
|
5959 | + } |
|
5636 | 5960 | }); |
5637 | 5961 | |
5638 | 5962 | // Convert Punycode to Unicode |
@@ -5686,8 +6010,9 @@ discard block |
||
5686 | 6010 | $idx += $digit * $w; |
5687 | 6011 | $t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias)); |
5688 | 6012 | |
5689 | - if ($digit < $t) |
|
5690 | - break; |
|
6013 | + if ($digit < $t) { |
|
6014 | + break; |
|
6015 | + } |
|
5691 | 6016 | |
5692 | 6017 | $w = (int) ($w * ($base - $t)); |
5693 | 6018 | } |
@@ -5696,8 +6021,9 @@ discard block |
||
5696 | 6021 | $delta = intval($is_first ? ($delta / $damp) : ($delta / 2)); |
5697 | 6022 | $delta += intval($delta / ($deco_len + 1)); |
5698 | 6023 | |
5699 | - for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) |
|
5700 | - $delta = intval($delta / ($base - $tmin)); |
|
6024 | + for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) { |
|
6025 | + $delta = intval($delta / ($base - $tmin)); |
|
6026 | + } |
|
5701 | 6027 | |
5702 | 6028 | $bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew)); |
5703 | 6029 | $is_first = false; |
@@ -5706,8 +6032,9 @@ discard block |
||
5706 | 6032 | |
5707 | 6033 | if ($deco_len > 0) |
5708 | 6034 | { |
5709 | - for ($i = $deco_len; $i > $idx; $i--) |
|
5710 | - $decoded[$i] = $decoded[($i - 1)]; |
|
6035 | + for ($i = $deco_len; $i > $idx; $i--) { |
|
6036 | + $decoded[$i] = $decoded[($i - 1)]; |
|
6037 | + } |
|
5711 | 6038 | } |
5712 | 6039 | $decoded[$idx++] = $char; |
5713 | 6040 | } |
@@ -5715,24 +6042,29 @@ discard block |
||
5715 | 6042 | foreach ($decoded as $k => $v) |
5716 | 6043 | { |
5717 | 6044 | // 7bit are transferred literally |
5718 | - if ($v < 128) |
|
5719 | - $output .= chr($v); |
|
6045 | + if ($v < 128) { |
|
6046 | + $output .= chr($v); |
|
6047 | + } |
|
5720 | 6048 | |
5721 | 6049 | // 2 bytes |
5722 | - elseif ($v < (1 << 11)) |
|
5723 | - $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
6050 | + elseif ($v < (1 << 11)) { |
|
6051 | + $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
6052 | + } |
|
5724 | 6053 | |
5725 | 6054 | // 3 bytes |
5726 | - elseif ($v < (1 << 16)) |
|
5727 | - $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
6055 | + elseif ($v < (1 << 16)) { |
|
6056 | + $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
6057 | + } |
|
5728 | 6058 | |
5729 | 6059 | // 4 bytes |
5730 | - elseif ($v < (1 << 21)) |
|
5731 | - $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
6060 | + elseif ($v < (1 << 21)) { |
|
6061 | + $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
6062 | + } |
|
5732 | 6063 | |
5733 | 6064 | // 'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k |
5734 | - else |
|
5735 | - $output .= $safe_char; |
|
6065 | + else { |
|
6066 | + $output .= $safe_char; |
|
6067 | + } |
|
5736 | 6068 | } |
5737 | 6069 | |
5738 | 6070 | $output_parts[] = $output; |
@@ -5827,8 +6159,7 @@ discard block |
||
5827 | 6159 | |
5828 | 6160 | $strlen = 'mb_strlen'; |
5829 | 6161 | $substr = 'mb_substr'; |
5830 | - } |
|
5831 | - else |
|
6162 | + } else |
|
5832 | 6163 | { |
5833 | 6164 | $strlen = $smcFunc['strlen']; |
5834 | 6165 | $substr = $smcFunc['substr']; |
@@ -5842,20 +6173,21 @@ discard block |
||
5842 | 6173 | |
5843 | 6174 | $first = $substr($string, 0, 1); |
5844 | 6175 | |
5845 | - if (empty($index[$first])) |
|
5846 | - $index[$first] = array(); |
|
6176 | + if (empty($index[$first])) { |
|
6177 | + $index[$first] = array(); |
|
6178 | + } |
|
5847 | 6179 | |
5848 | 6180 | if ($strlen($string) > 1) |
5849 | 6181 | { |
5850 | 6182 | // Sanity check on recursion |
5851 | - if ($depth > 99) |
|
5852 | - $index[$first][$substr($string, 1)] = ''; |
|
5853 | - |
|
5854 | - else |
|
5855 | - $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
6183 | + if ($depth > 99) { |
|
6184 | + $index[$first][$substr($string, 1)] = ''; |
|
6185 | + } else { |
|
6186 | + $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
6187 | + } |
|
6188 | + } else { |
|
6189 | + $index[$first][''] = ''; |
|
5856 | 6190 | } |
5857 | - else |
|
5858 | - $index[$first][''] = ''; |
|
5859 | 6191 | |
5860 | 6192 | $depth--; |
5861 | 6193 | return $index; |
@@ -5878,9 +6210,9 @@ discard block |
||
5878 | 6210 | $key_regex = preg_quote($key, $delim); |
5879 | 6211 | $new_key = $key; |
5880 | 6212 | |
5881 | - if (empty($value)) |
|
5882 | - $sub_regex = ''; |
|
5883 | - else |
|
6213 | + if (empty($value)) { |
|
6214 | + $sub_regex = ''; |
|
6215 | + } else |
|
5884 | 6216 | { |
5885 | 6217 | $sub_regex = $index_to_regex($value, $delim); |
5886 | 6218 | |
@@ -5888,22 +6220,22 @@ discard block |
||
5888 | 6220 | { |
5889 | 6221 | $new_key_array = explode('(?'.'>', $sub_regex); |
5890 | 6222 | $new_key .= $new_key_array[0]; |
6223 | + } else { |
|
6224 | + $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
5891 | 6225 | } |
5892 | - else |
|
5893 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
5894 | 6226 | } |
5895 | 6227 | |
5896 | - if ($depth > 1) |
|
5897 | - $regex[$new_key] = $key_regex . $sub_regex; |
|
5898 | - else |
|
6228 | + if ($depth > 1) { |
|
6229 | + $regex[$new_key] = $key_regex . $sub_regex; |
|
6230 | + } else |
|
5899 | 6231 | { |
5900 | 6232 | if (($length += strlen($key_regex) + 1) < $max_length || empty($regex)) |
5901 | 6233 | { |
5902 | 6234 | $regex[$new_key] = $key_regex . $sub_regex; |
5903 | 6235 | unset($index[$key]); |
6236 | + } else { |
|
6237 | + break; |
|
5904 | 6238 | } |
5905 | - else |
|
5906 | - break; |
|
5907 | 6239 | } |
5908 | 6240 | } |
5909 | 6241 | |
@@ -5912,10 +6244,11 @@ discard block |
||
5912 | 6244 | $l1 = $strlen($k1); |
5913 | 6245 | $l2 = $strlen($k2); |
5914 | 6246 | |
5915 | - if ($l1 == $l2) |
|
5916 | - return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
5917 | - else |
|
5918 | - return $l1 > $l2 ? -1 : 1; |
|
6247 | + if ($l1 == $l2) { |
|
6248 | + return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
6249 | + } else { |
|
6250 | + return $l1 > $l2 ? -1 : 1; |
|
6251 | + } |
|
5919 | 6252 | }); |
5920 | 6253 | |
5921 | 6254 | $depth--; |
@@ -5926,15 +6259,18 @@ discard block |
||
5926 | 6259 | $index = array(); |
5927 | 6260 | $regexes = array(); |
5928 | 6261 | |
5929 | - foreach ($strings as $string) |
|
5930 | - $index = $add_string_to_index($string, $index); |
|
6262 | + foreach ($strings as $string) { |
|
6263 | + $index = $add_string_to_index($string, $index); |
|
6264 | + } |
|
5931 | 6265 | |
5932 | - while (!empty($index)) |
|
5933 | - $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6266 | + while (!empty($index)) { |
|
6267 | + $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6268 | + } |
|
5934 | 6269 | |
5935 | 6270 | // Restore PHP's internal character encoding to whatever it was originally |
5936 | - if (!empty($current_encoding)) |
|
5937 | - mb_internal_encoding($current_encoding); |
|
6271 | + if (!empty($current_encoding)) { |
|
6272 | + mb_internal_encoding($current_encoding); |
|
6273 | + } |
|
5938 | 6274 | |
5939 | 6275 | return $regexes; |
5940 | 6276 | } |
@@ -824,7 +824,7 @@ discard block |
||
824 | 824 | call_integration_hook('integrate_poll_buttons'); |
825 | 825 | } |
826 | 826 | |
827 | - if(!empty($_REQUEST['page_id'])) |
|
827 | + if (!empty($_REQUEST['page_id'])) |
|
828 | 828 | $start_char = substr($_REQUEST['page_id'], 0, 1); |
829 | 829 | else |
830 | 830 | $start_char = null; |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | SELECT id_msg, id_member, approved |
887 | 887 | FROM {db_prefix}messages |
888 | 888 | WHERE id_topic = {int:current_topic} |
889 | - AND id_msg '. $page_operator . ' {int:page_id}'. (!$modSettings['postmod_active'] || $approve_posts ? '' : ' |
|
889 | + AND id_msg '. $page_operator . ' {int:page_id}' . (!$modSettings['postmod_active'] || $approve_posts ? '' : ' |
|
890 | 890 | AND (approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR id_member = {int:current_member}') . ')') . ' |
891 | 891 | ORDER BY id_msg ' . ($ascending ? '' : 'DESC') . ($context['messages_per_page'] == -1 ? '' : ' |
892 | 892 | LIMIT {int:limit}'), |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * The central part of the board - topic display. |
@@ -34,8 +35,9 @@ discard block |
||
34 | 35 | global $messages_request, $language, $smcFunc; |
35 | 36 | |
36 | 37 | // What are you gonna display if these are empty?! |
37 | - if (empty($topic)) |
|
38 | - fatal_lang_error('no_board', false); |
|
38 | + if (empty($topic)) { |
|
39 | + fatal_lang_error('no_board', false); |
|
40 | + } |
|
39 | 41 | |
40 | 42 | // Load the proper template. |
41 | 43 | loadTemplate('Display'); |
@@ -52,15 +54,17 @@ discard block |
||
52 | 54 | $context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
53 | 55 | |
54 | 56 | // Let's do some work on what to search index. |
55 | - if (count($_GET) > 2) |
|
56 | - foreach ($_GET as $k => $v) |
|
57 | + if (count($_GET) > 2) { |
|
58 | + foreach ($_GET as $k => $v) |
|
57 | 59 | { |
58 | 60 | if (!in_array($k, array('topic', 'board', 'start', session_name()))) |
59 | 61 | $context['robot_no_index'] = true; |
62 | + } |
|
60 | 63 | } |
61 | 64 | |
62 | - if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) |
|
63 | - $context['robot_no_index'] = true; |
|
65 | + if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) { |
|
66 | + $context['robot_no_index'] = true; |
|
67 | + } |
|
64 | 68 | |
65 | 69 | // Find the previous or next topic. Make a fuss if there are no more. |
66 | 70 | if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next')) |
@@ -172,8 +176,9 @@ discard block |
||
172 | 176 | $topic_parameters |
173 | 177 | ); |
174 | 178 | |
175 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
176 | - fatal_lang_error('not_a_topic', false, 404); |
|
179 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
180 | + fatal_lang_error('not_a_topic', false, 404); |
|
181 | + } |
|
177 | 182 | $context['topicinfo'] = $smcFunc['db_fetch_assoc']($request); |
178 | 183 | $smcFunc['db_free_result']($request); |
179 | 184 | |
@@ -210,8 +215,9 @@ discard block |
||
210 | 215 | $context['topic_unwatched'] = isset($context['topicinfo']['unwatched']) ? $context['topicinfo']['unwatched'] : 0; |
211 | 216 | |
212 | 217 | // Add up unapproved replies to get real number of replies... |
213 | - if ($modSettings['postmod_active'] && $approve_posts) |
|
214 | - $context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1); |
|
218 | + if ($modSettings['postmod_active'] && $approve_posts) { |
|
219 | + $context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1); |
|
220 | + } |
|
215 | 221 | |
216 | 222 | // If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing. |
217 | 223 | if ($modSettings['postmod_active'] && $context['topicinfo']['unapproved_posts'] && !$user_info['is_guest'] && !$approve_posts) |
@@ -231,11 +237,11 @@ discard block |
||
231 | 237 | $smcFunc['db_free_result']($request); |
232 | 238 | |
233 | 239 | $context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($context['topicinfo']['approved'] ? 1 : 0); |
240 | + } elseif ($user_info['is_guest']) { |
|
241 | + $context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
242 | + } else { |
|
243 | + $context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
234 | 244 | } |
235 | - elseif ($user_info['is_guest']) |
|
236 | - $context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
237 | - else |
|
238 | - $context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
239 | 245 | |
240 | 246 | // The start isn't a number; it's information about what to do, where to go. |
241 | 247 | if (!is_numeric($_REQUEST['start'])) |
@@ -248,8 +254,7 @@ discard block |
||
248 | 254 | { |
249 | 255 | $context['start_from'] = $context['total_visible_posts'] - 1; |
250 | 256 | $_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0; |
251 | - } |
|
252 | - else |
|
257 | + } else |
|
253 | 258 | { |
254 | 259 | // Find the earliest unread message in the topic. (the use of topics here is just for both tables.) |
255 | 260 | $request = $smcFunc['db_query']('', ' |
@@ -277,9 +282,9 @@ discard block |
||
277 | 282 | if (substr($_REQUEST['start'], 0, 4) == 'from') |
278 | 283 | { |
279 | 284 | $timestamp = (int) substr($_REQUEST['start'], 4); |
280 | - if ($timestamp === 0) |
|
281 | - $_REQUEST['start'] = 0; |
|
282 | - else |
|
285 | + if ($timestamp === 0) { |
|
286 | + $_REQUEST['start'] = 0; |
|
287 | + } else |
|
283 | 288 | { |
284 | 289 | // Find the number of messages posted before said time... |
285 | 290 | $request = $smcFunc['db_query']('', ' |
@@ -307,11 +312,11 @@ discard block |
||
307 | 312 | elseif (substr($_REQUEST['start'], 0, 3) == 'msg') |
308 | 313 | { |
309 | 314 | $virtual_msg = (int) substr($_REQUEST['start'], 3); |
310 | - if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) |
|
311 | - $context['start_from'] = $context['total_visible_posts'] - 1; |
|
312 | - elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) |
|
313 | - $context['start_from'] = 0; |
|
314 | - else |
|
315 | + if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) { |
|
316 | + $context['start_from'] = $context['total_visible_posts'] - 1; |
|
317 | + } elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) { |
|
318 | + $context['start_from'] = 0; |
|
319 | + } else |
|
315 | 320 | { |
316 | 321 | // Find the start value for that message...... |
317 | 322 | $request = $smcFunc['db_query']('', ' |
@@ -394,21 +399,25 @@ discard block |
||
394 | 399 | ); |
395 | 400 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
396 | 401 | { |
397 | - if (empty($row['id_member'])) |
|
398 | - continue; |
|
402 | + if (empty($row['id_member'])) { |
|
403 | + continue; |
|
404 | + } |
|
399 | 405 | |
400 | - if (!empty($row['online_color'])) |
|
401 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
402 | - else |
|
403 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
406 | + if (!empty($row['online_color'])) { |
|
407 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
408 | + } else { |
|
409 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
410 | + } |
|
404 | 411 | |
405 | 412 | $is_buddy = in_array($row['id_member'], $user_info['buddies']); |
406 | - if ($is_buddy) |
|
407 | - $link = '<strong>' . $link . '</strong>'; |
|
413 | + if ($is_buddy) { |
|
414 | + $link = '<strong>' . $link . '</strong>'; |
|
415 | + } |
|
408 | 416 | |
409 | 417 | // Add them both to the list and to the more detailed list. |
410 | - if (!empty($row['show_online']) || allowedTo('moderate_forum')) |
|
411 | - $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
|
418 | + if (!empty($row['show_online']) || allowedTo('moderate_forum')) { |
|
419 | + $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
|
420 | + } |
|
412 | 421 | $context['view_members'][$row['log_time'] . $row['member_name']] = array( |
413 | 422 | 'id' => $row['id_member'], |
414 | 423 | 'username' => $row['member_name'], |
@@ -420,8 +429,9 @@ discard block |
||
420 | 429 | 'hidden' => empty($row['show_online']), |
421 | 430 | ); |
422 | 431 | |
423 | - if (empty($row['show_online'])) |
|
424 | - $context['view_num_hidden']++; |
|
432 | + if (empty($row['show_online'])) { |
|
433 | + $context['view_num_hidden']++; |
|
434 | + } |
|
425 | 435 | } |
426 | 436 | |
427 | 437 | // The number of guests is equal to the rows minus the ones we actually used ;). |
@@ -435,11 +445,13 @@ discard block |
||
435 | 445 | |
436 | 446 | // If all is set, but not allowed... just unset it. |
437 | 447 | $can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages']; |
438 | - if (isset($_REQUEST['all']) && !$can_show_all) |
|
439 | - unset($_REQUEST['all']); |
|
448 | + if (isset($_REQUEST['all']) && !$can_show_all) { |
|
449 | + unset($_REQUEST['all']); |
|
450 | + } |
|
440 | 451 | // Otherwise, it must be allowed... so pretend start was -1. |
441 | - elseif (isset($_REQUEST['all'])) |
|
442 | - $_REQUEST['start'] = -1; |
|
452 | + elseif (isset($_REQUEST['all'])) { |
|
453 | + $_REQUEST['start'] = -1; |
|
454 | + } |
|
443 | 455 | |
444 | 456 | // Construct allowing for the .START method... |
445 | 457 | $context['start'] = $_REQUEST['start']; |
@@ -475,14 +487,16 @@ discard block |
||
475 | 487 | if (!empty($board_info['moderators'])) |
476 | 488 | { |
477 | 489 | // Add a link for each moderator... |
478 | - foreach ($board_info['moderators'] as $mod) |
|
479 | - $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
|
490 | + foreach ($board_info['moderators'] as $mod) { |
|
491 | + $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
|
492 | + } |
|
480 | 493 | } |
481 | 494 | if (!empty($board_info['moderator_groups'])) |
482 | 495 | { |
483 | 496 | // Add a link for each moderator group as well... |
484 | - foreach ($board_info['moderator_groups'] as $mod_group) |
|
485 | - $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
|
497 | + foreach ($board_info['moderator_groups'] as $mod_group) { |
|
498 | + $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
|
499 | + } |
|
486 | 500 | } |
487 | 501 | |
488 | 502 | if (!empty($context['link_moderators'])) |
@@ -513,9 +527,9 @@ discard block |
||
513 | 527 | // For quick reply we need a response prefix in the default forum language. |
514 | 528 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600))) |
515 | 529 | { |
516 | - if ($language === $user_info['language']) |
|
517 | - $context['response_prefix'] = $txt['response_prefix']; |
|
518 | - else |
|
530 | + if ($language === $user_info['language']) { |
|
531 | + $context['response_prefix'] = $txt['response_prefix']; |
|
532 | + } else |
|
519 | 533 | { |
520 | 534 | loadLanguage('index', $language, false); |
521 | 535 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -547,8 +561,9 @@ discard block |
||
547 | 561 | list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row); |
548 | 562 | |
549 | 563 | // Sanity check |
550 | - if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) |
|
551 | - continue; |
|
564 | + if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) { |
|
565 | + continue; |
|
566 | + } |
|
552 | 567 | |
553 | 568 | $linked_calendar_event = array( |
554 | 569 | 'id' => $row['id_event'], |
@@ -597,8 +612,9 @@ discard block |
||
597 | 612 | } |
598 | 613 | $smcFunc['db_free_result']($request); |
599 | 614 | |
600 | - if (!empty($context['linked_calendar_events'])) |
|
601 | - $context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true; |
|
615 | + if (!empty($context['linked_calendar_events'])) { |
|
616 | + $context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true; |
|
617 | + } |
|
602 | 618 | } |
603 | 619 | |
604 | 620 | // Create the poll info if it exists. |
@@ -661,8 +677,9 @@ discard block |
||
661 | 677 | $smcFunc['db_free_result']($request); |
662 | 678 | |
663 | 679 | // Got we multi choice? |
664 | - if ($pollinfo['max_votes'] > 1) |
|
665 | - $realtotal = $pollinfo['total']; |
|
680 | + if ($pollinfo['max_votes'] > 1) { |
|
681 | + $realtotal = $pollinfo['total']; |
|
682 | + } |
|
666 | 683 | |
667 | 684 | // If this is a guest we need to do our best to work out if they have voted, and what they voted for. |
668 | 685 | if ($user_info['is_guest'] && $pollinfo['guest_vote'] && allowedTo('poll_vote')) |
@@ -675,20 +692,21 @@ discard block |
||
675 | 692 | foreach ($guestinfo as $i => $guestvoted) |
676 | 693 | { |
677 | 694 | $guestvoted = explode(',', $guestvoted); |
678 | - if ($guestvoted[0] == $context['topicinfo']['id_poll']) |
|
679 | - break; |
|
695 | + if ($guestvoted[0] == $context['topicinfo']['id_poll']) { |
|
696 | + break; |
|
697 | + } |
|
680 | 698 | } |
681 | 699 | // Has the poll been reset since guest voted? |
682 | 700 | if ($pollinfo['reset_poll'] > $guestvoted[1]) |
683 | 701 | { |
684 | 702 | // Remove the poll info from the cookie to allow guest to vote again |
685 | 703 | unset($guestinfo[$i]); |
686 | - if (!empty($guestinfo)) |
|
687 | - $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo); |
|
688 | - else |
|
689 | - unset($_COOKIE['guest_poll_vote']); |
|
690 | - } |
|
691 | - else |
|
704 | + if (!empty($guestinfo)) { |
|
705 | + $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo); |
|
706 | + } else { |
|
707 | + unset($_COOKIE['guest_poll_vote']); |
|
708 | + } |
|
709 | + } else |
|
692 | 710 | { |
693 | 711 | // What did they vote for? |
694 | 712 | unset($guestvoted[0], $guestvoted[1]); |
@@ -802,35 +820,43 @@ discard block |
||
802 | 820 | // Build the poll moderation button array. |
803 | 821 | $context['poll_buttons'] = array(); |
804 | 822 | |
805 | - if ($context['allow_return_vote']) |
|
806 | - $context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']); |
|
823 | + if ($context['allow_return_vote']) { |
|
824 | + $context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']); |
|
825 | + } |
|
807 | 826 | |
808 | - if ($context['show_view_results_button']) |
|
809 | - $context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults'); |
|
827 | + if ($context['show_view_results_button']) { |
|
828 | + $context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults'); |
|
829 | + } |
|
810 | 830 | |
811 | - if ($context['allow_change_vote']) |
|
812 | - $context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
831 | + if ($context['allow_change_vote']) { |
|
832 | + $context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
833 | + } |
|
813 | 834 | |
814 | - if ($context['allow_lock_poll']) |
|
815 | - $context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
835 | + if ($context['allow_lock_poll']) { |
|
836 | + $context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
837 | + } |
|
816 | 838 | |
817 | - if ($context['allow_edit_poll']) |
|
818 | - $context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
839 | + if ($context['allow_edit_poll']) { |
|
840 | + $context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
841 | + } |
|
819 | 842 | |
820 | - if ($context['can_remove_poll']) |
|
821 | - $context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
843 | + if ($context['can_remove_poll']) { |
|
844 | + $context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
845 | + } |
|
822 | 846 | |
823 | 847 | // Allow mods to add additional buttons here |
824 | 848 | call_integration_hook('integrate_poll_buttons'); |
825 | 849 | } |
826 | 850 | |
827 | - if(!empty($_REQUEST['page_id'])) |
|
828 | - $start_char = substr($_REQUEST['page_id'], 0, 1); |
|
829 | - else |
|
830 | - $start_char = null; |
|
851 | + if(!empty($_REQUEST['page_id'])) { |
|
852 | + $start_char = substr($_REQUEST['page_id'], 0, 1); |
|
853 | + } else { |
|
854 | + $start_char = null; |
|
855 | + } |
|
831 | 856 | |
832 | - if ($start_char === 'M' || $start_char === 'L') |
|
833 | - $page_id = substr($_REQUEST['page_id'], 1); |
|
857 | + if ($start_char === 'M' || $start_char === 'L') { |
|
858 | + $page_id = substr($_REQUEST['page_id'], 1); |
|
859 | + } |
|
834 | 860 | |
835 | 861 | $limit = $context['messages_per_page']; |
836 | 862 | |
@@ -866,8 +892,7 @@ discard block |
||
866 | 892 | 'max' => $limit, |
867 | 893 | ) |
868 | 894 | ); |
869 | - } |
|
870 | - else //next or before page |
|
895 | + } else //next or before page |
|
871 | 896 | { |
872 | 897 | $firstIndex = 0; |
873 | 898 | |
@@ -875,8 +900,7 @@ discard block |
||
875 | 900 | { |
876 | 901 | $ascending = true; |
877 | 902 | $page_operator = '>'; |
878 | - } |
|
879 | - else |
|
903 | + } else |
|
880 | 904 | { |
881 | 905 | $ascending = false; |
882 | 906 | $page_operator = '<'; |
@@ -906,14 +930,16 @@ discard block |
||
906 | 930 | $all_posters = array(); |
907 | 931 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
908 | 932 | { |
909 | - if (!empty($row['id_member'])) |
|
910 | - $all_posters[$row['id_msg']] = $row['id_member']; |
|
933 | + if (!empty($row['id_member'])) { |
|
934 | + $all_posters[$row['id_msg']] = $row['id_member']; |
|
935 | + } |
|
911 | 936 | $messages[] = $row['id_msg']; |
912 | 937 | } |
913 | 938 | |
914 | 939 | // Before Page bring in the right order |
915 | - if (!empty($start_char) && $start_char === 'L') |
|
916 | - krsort($messages); |
|
940 | + if (!empty($start_char) && $start_char === 'L') { |
|
941 | + krsort($messages); |
|
942 | + } |
|
917 | 943 | |
918 | 944 | // Construct the page index, allowing for the .START method... |
919 | 945 | $page_options = array( |
@@ -935,8 +961,9 @@ discard block |
||
935 | 961 | $_REQUEST['start'] = 0; |
936 | 962 | } |
937 | 963 | // They aren't using it, but the *option* is there, at least. |
938 | - else |
|
939 | - $context['page_index'] .= ' <a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> '; |
|
964 | + else { |
|
965 | + $context['page_index'] .= ' <a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> '; |
|
966 | + } |
|
940 | 967 | } |
941 | 968 | |
942 | 969 | $smcFunc['db_free_result']($request); |
@@ -948,8 +975,9 @@ discard block |
||
948 | 975 | if (!$user_info['is_guest'] && !empty($messages)) |
949 | 976 | { |
950 | 977 | $mark_at_msg = max($messages); |
951 | - if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) |
|
952 | - $mark_at_msg = $modSettings['maxMsgID']; |
|
978 | + if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) { |
|
979 | + $mark_at_msg = $modSettings['maxMsgID']; |
|
980 | + } |
|
953 | 981 | if ($mark_at_msg >= $context['topicinfo']['new_from']) |
954 | 982 | { |
955 | 983 | $smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace', |
@@ -981,8 +1009,9 @@ discard block |
||
981 | 1009 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
982 | 1010 | { |
983 | 1011 | // Find if this topic is marked for notification... |
984 | - if (!empty($row['id_topic'])) |
|
985 | - $context['is_marked_notify'] = true; |
|
1012 | + if (!empty($row['id_topic'])) { |
|
1013 | + $context['is_marked_notify'] = true; |
|
1014 | + } |
|
986 | 1015 | |
987 | 1016 | // Only do this once, but mark the notifications as "not sent yet" for next time. |
988 | 1017 | if (!empty($row['sent']) && $do_once) |
@@ -1004,8 +1033,9 @@ discard block |
||
1004 | 1033 | } |
1005 | 1034 | |
1006 | 1035 | // Have we recently cached the number of new topics in this board, and it's still a lot? |
1007 | - if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) |
|
1008 | - $_SESSION['topicseen_cache'][$board]--; |
|
1036 | + if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) { |
|
1037 | + $_SESSION['topicseen_cache'][$board]--; |
|
1038 | + } |
|
1009 | 1039 | // Mark board as seen if this is the only new topic. |
1010 | 1040 | elseif (isset($_REQUEST['topicseen'])) |
1011 | 1041 | { |
@@ -1029,14 +1059,16 @@ discard block |
||
1029 | 1059 | $smcFunc['db_free_result']($request); |
1030 | 1060 | |
1031 | 1061 | // If there're no real new topics in this board, mark the board as seen. |
1032 | - if (empty($numNewTopics)) |
|
1033 | - $_REQUEST['boardseen'] = true; |
|
1034 | - else |
|
1035 | - $_SESSION['topicseen_cache'][$board] = $numNewTopics; |
|
1062 | + if (empty($numNewTopics)) { |
|
1063 | + $_REQUEST['boardseen'] = true; |
|
1064 | + } else { |
|
1065 | + $_SESSION['topicseen_cache'][$board] = $numNewTopics; |
|
1066 | + } |
|
1036 | 1067 | } |
1037 | 1068 | // Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often. |
1038 | - elseif (isset($_SESSION['topicseen_cache'][$board])) |
|
1039 | - $_SESSION['topicseen_cache'][$board]--; |
|
1069 | + elseif (isset($_SESSION['topicseen_cache'][$board])) { |
|
1070 | + $_SESSION['topicseen_cache'][$board]--; |
|
1071 | + } |
|
1040 | 1072 | |
1041 | 1073 | // Mark board as seen if we came using last post link from BoardIndex. (or other places...) |
1042 | 1074 | if (isset($_REQUEST['boardseen'])) |
@@ -1093,23 +1125,26 @@ discard block |
||
1093 | 1125 | $temp = array(); |
1094 | 1126 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1095 | 1127 | { |
1096 | - if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) |
|
1097 | - continue; |
|
1128 | + if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) { |
|
1129 | + continue; |
|
1130 | + } |
|
1098 | 1131 | |
1099 | 1132 | $temp[$row['id_attach']] = $row; |
1100 | 1133 | $temp[$row['id_attach']]['topic'] = $topic; |
1101 | 1134 | $temp[$row['id_attach']]['board'] = $board; |
1102 | 1135 | |
1103 | - if (!isset($context['loaded_attachments'][$row['id_msg']])) |
|
1104 | - $context['loaded_attachments'][$row['id_msg']] = array(); |
|
1136 | + if (!isset($context['loaded_attachments'][$row['id_msg']])) { |
|
1137 | + $context['loaded_attachments'][$row['id_msg']] = array(); |
|
1138 | + } |
|
1105 | 1139 | } |
1106 | 1140 | $smcFunc['db_free_result']($request); |
1107 | 1141 | |
1108 | 1142 | // This is better than sorting it with the query... |
1109 | 1143 | ksort($temp); |
1110 | 1144 | |
1111 | - foreach ($temp as $row) |
|
1112 | - $context['loaded_attachments'][$row['id_msg']][] = $row; |
|
1145 | + foreach ($temp as $row) { |
|
1146 | + $context['loaded_attachments'][$row['id_msg']][] = $row; |
|
1147 | + } |
|
1113 | 1148 | } |
1114 | 1149 | |
1115 | 1150 | $msg_parameters = array( |
@@ -1136,21 +1171,23 @@ discard block |
||
1136 | 1171 | ); |
1137 | 1172 | |
1138 | 1173 | // And the likes |
1139 | - if (!empty($modSettings['enable_likes'])) |
|
1140 | - $context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic); |
|
1174 | + if (!empty($modSettings['enable_likes'])) { |
|
1175 | + $context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic); |
|
1176 | + } |
|
1141 | 1177 | |
1142 | 1178 | // Go to the last message if the given time is beyond the time of the last message. |
1143 | - if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) |
|
1144 | - $context['start_from'] = $context['topicinfo']['num_replies']; |
|
1179 | + if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) { |
|
1180 | + $context['start_from'] = $context['topicinfo']['num_replies']; |
|
1181 | + } |
|
1145 | 1182 | |
1146 | 1183 | // Since the anchor information is needed on the top of the page we load these variables beforehand. |
1147 | 1184 | $context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0]; |
1148 | - if (empty($options['view_newest_first'])) |
|
1149 | - $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from']; |
|
1150 | - else |
|
1151 | - $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from']; |
|
1152 | - } |
|
1153 | - else |
|
1185 | + if (empty($options['view_newest_first'])) { |
|
1186 | + $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from']; |
|
1187 | + } else { |
|
1188 | + $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from']; |
|
1189 | + } |
|
1190 | + } else |
|
1154 | 1191 | { |
1155 | 1192 | $messages_request = false; |
1156 | 1193 | $context['first_message'] = 0; |
@@ -1186,8 +1223,9 @@ discard block |
||
1186 | 1223 | 'can_see_likes' => 'likes_view', |
1187 | 1224 | 'can_like' => 'likes_like', |
1188 | 1225 | ); |
1189 | - foreach ($common_permissions as $contextual => $perm) |
|
1190 | - $context[$contextual] = allowedTo($perm); |
|
1226 | + foreach ($common_permissions as $contextual => $perm) { |
|
1227 | + $context[$contextual] = allowedTo($perm); |
|
1228 | + } |
|
1191 | 1229 | |
1192 | 1230 | // Permissions with _any/_own versions. $context[YYY] => ZZZ_any/_own. |
1193 | 1231 | $anyown_permissions = array( |
@@ -1200,8 +1238,9 @@ discard block |
||
1200 | 1238 | 'can_reply_unapproved' => 'post_unapproved_replies', |
1201 | 1239 | 'can_view_warning' => 'profile_warning', |
1202 | 1240 | ); |
1203 | - foreach ($anyown_permissions as $contextual => $perm) |
|
1204 | - $context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own')); |
|
1241 | + foreach ($anyown_permissions as $contextual => $perm) { |
|
1242 | + $context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own')); |
|
1243 | + } |
|
1205 | 1244 | |
1206 | 1245 | if (!$user_info['is_admin'] && !$modSettings['topic_move_any']) |
1207 | 1246 | { |
@@ -1247,8 +1286,9 @@ discard block |
||
1247 | 1286 | // Check if the draft functions are enabled and that they have permission to use them (for quick reply.) |
1248 | 1287 | $context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply']; |
1249 | 1288 | $context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']); |
1250 | - if (!empty($context['drafts_save'])) |
|
1251 | - loadLanguage('Drafts'); |
|
1289 | + if (!empty($context['drafts_save'])) { |
|
1290 | + loadLanguage('Drafts'); |
|
1291 | + } |
|
1252 | 1292 | |
1253 | 1293 | // When was the last time this topic was replied to? Should we warn them about it? |
1254 | 1294 | if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky'])) |
@@ -1309,26 +1349,31 @@ discard block |
||
1309 | 1349 | // Message icons - customized icons are off? |
1310 | 1350 | $context['icons'] = getMessageIcons($board); |
1311 | 1351 | |
1312 | - if (!empty($context['icons'])) |
|
1313 | - $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
1352 | + if (!empty($context['icons'])) { |
|
1353 | + $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
1354 | + } |
|
1314 | 1355 | |
1315 | 1356 | // Build the normal button array. |
1316 | 1357 | $context['normal_buttons'] = array(); |
1317 | 1358 | |
1318 | - if ($context['can_reply']) |
|
1319 | - $context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true); |
|
1359 | + if ($context['can_reply']) { |
|
1360 | + $context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true); |
|
1361 | + } |
|
1320 | 1362 | |
1321 | - if ($context['can_add_poll']) |
|
1322 | - $context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
1363 | + if ($context['can_add_poll']) { |
|
1364 | + $context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
1365 | + } |
|
1323 | 1366 | |
1324 | - if ($context['can_mark_unread']) |
|
1325 | - $context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1367 | + if ($context['can_mark_unread']) { |
|
1368 | + $context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1369 | + } |
|
1326 | 1370 | |
1327 | - if ($context['can_print']) |
|
1328 | - $context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'); |
|
1371 | + if ($context['can_print']) { |
|
1372 | + $context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'); |
|
1373 | + } |
|
1329 | 1374 | |
1330 | - if ($context['can_set_notify']) |
|
1331 | - $context['normal_buttons']['notify'] = array( |
|
1375 | + if ($context['can_set_notify']) { |
|
1376 | + $context['normal_buttons']['notify'] = array( |
|
1332 | 1377 | 'text' => 'notify_topic_' . $context['topic_notification_mode'], |
1333 | 1378 | 'sub_buttons' => array( |
1334 | 1379 | array( |
@@ -1350,38 +1395,47 @@ discard block |
||
1350 | 1395 | ), |
1351 | 1396 | ), |
1352 | 1397 | ); |
1398 | + } |
|
1353 | 1399 | |
1354 | 1400 | // Build the mod button array |
1355 | 1401 | $context['mod_buttons'] = array(); |
1356 | 1402 | |
1357 | - if ($context['can_move']) |
|
1358 | - $context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0'); |
|
1403 | + if ($context['can_move']) { |
|
1404 | + $context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0'); |
|
1405 | + } |
|
1359 | 1406 | |
1360 | - if ($context['can_delete']) |
|
1361 | - $context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']); |
|
1407 | + if ($context['can_delete']) { |
|
1408 | + $context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']); |
|
1409 | + } |
|
1362 | 1410 | |
1363 | - if ($context['can_lock']) |
|
1364 | - $context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1411 | + if ($context['can_lock']) { |
|
1412 | + $context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1413 | + } |
|
1365 | 1414 | |
1366 | - if ($context['can_sticky']) |
|
1367 | - $context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1415 | + if ($context['can_sticky']) { |
|
1416 | + $context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1417 | + } |
|
1368 | 1418 | |
1369 | - if ($context['can_merge']) |
|
1370 | - $context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']); |
|
1419 | + if ($context['can_merge']) { |
|
1420 | + $context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']); |
|
1421 | + } |
|
1371 | 1422 | |
1372 | - if ($context['calendar_post']) |
|
1373 | - $context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0'); |
|
1423 | + if ($context['calendar_post']) { |
|
1424 | + $context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0'); |
|
1425 | + } |
|
1374 | 1426 | |
1375 | 1427 | // Restore topic. eh? No monkey business. |
1376 | - if ($context['can_restore_topic']) |
|
1377 | - $context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1428 | + if ($context['can_restore_topic']) { |
|
1429 | + $context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1430 | + } |
|
1378 | 1431 | |
1379 | 1432 | // Show a message in case a recently posted message became unapproved. |
1380 | 1433 | $context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false; |
1381 | 1434 | |
1382 | 1435 | // Don't want to show this forever... |
1383 | - if ($context['becomesUnapproved']) |
|
1384 | - unset($_SESSION['becomesUnapproved']); |
|
1436 | + if ($context['becomesUnapproved']) { |
|
1437 | + unset($_SESSION['becomesUnapproved']); |
|
1438 | + } |
|
1385 | 1439 | |
1386 | 1440 | // Allow adding new mod buttons easily. |
1387 | 1441 | // Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used |
@@ -1390,12 +1444,14 @@ discard block |
||
1390 | 1444 | call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons'])); |
1391 | 1445 | |
1392 | 1446 | // Load the drafts js file |
1393 | - if ($context['drafts_autosave']) |
|
1394 | - loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts'); |
|
1447 | + if ($context['drafts_autosave']) { |
|
1448 | + loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts'); |
|
1449 | + } |
|
1395 | 1450 | |
1396 | 1451 | // Spellcheck |
1397 | - if ($context['show_spellchecking']) |
|
1398 | - loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); |
|
1452 | + if ($context['show_spellchecking']) { |
|
1453 | + loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); |
|
1454 | + } |
|
1399 | 1455 | |
1400 | 1456 | // topic.js |
1401 | 1457 | loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic'); |
@@ -1429,16 +1485,19 @@ discard block |
||
1429 | 1485 | static $counter = null; |
1430 | 1486 | |
1431 | 1487 | // If the query returned false, bail. |
1432 | - if ($messages_request == false) |
|
1433 | - return false; |
|
1488 | + if ($messages_request == false) { |
|
1489 | + return false; |
|
1490 | + } |
|
1434 | 1491 | |
1435 | 1492 | // Remember which message this is. (ie. reply #83) |
1436 | - if ($counter === null || $reset) |
|
1437 | - $counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start']; |
|
1493 | + if ($counter === null || $reset) { |
|
1494 | + $counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start']; |
|
1495 | + } |
|
1438 | 1496 | |
1439 | 1497 | // Start from the beginning... |
1440 | - if ($reset) |
|
1441 | - return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1498 | + if ($reset) { |
|
1499 | + return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1500 | + } |
|
1442 | 1501 | |
1443 | 1502 | // Attempt to get the next message. |
1444 | 1503 | $message = $smcFunc['db_fetch_assoc']($messages_request); |
@@ -1452,19 +1511,21 @@ discard block |
||
1452 | 1511 | if (empty($context['icon_sources'])) |
1453 | 1512 | { |
1454 | 1513 | $context['icon_sources'] = array(); |
1455 | - foreach ($context['stable_icons'] as $icon) |
|
1456 | - $context['icon_sources'][$icon] = 'images_url'; |
|
1514 | + foreach ($context['stable_icons'] as $icon) { |
|
1515 | + $context['icon_sources'][$icon] = 'images_url'; |
|
1516 | + } |
|
1457 | 1517 | } |
1458 | 1518 | |
1459 | 1519 | // Message Icon Management... check the images exist. |
1460 | 1520 | if (empty($modSettings['messageIconChecks_disable'])) |
1461 | 1521 | { |
1462 | 1522 | // If the current icon isn't known, then we need to do something... |
1463 | - if (!isset($context['icon_sources'][$message['icon']])) |
|
1464 | - $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1523 | + if (!isset($context['icon_sources'][$message['icon']])) { |
|
1524 | + $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1525 | + } |
|
1526 | + } elseif (!isset($context['icon_sources'][$message['icon']])) { |
|
1527 | + $context['icon_sources'][$message['icon']] = 'images_url'; |
|
1465 | 1528 | } |
1466 | - elseif (!isset($context['icon_sources'][$message['icon']])) |
|
1467 | - $context['icon_sources'][$message['icon']] = 'images_url'; |
|
1468 | 1529 | |
1469 | 1530 | // If you're a lazy bum, you probably didn't give a subject... |
1470 | 1531 | $message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject']; |
@@ -1489,8 +1550,7 @@ discard block |
||
1489 | 1550 | $memberContext[$message['id_member']]['email'] = $message['poster_email']; |
1490 | 1551 | $memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum'); |
1491 | 1552 | $memberContext[$message['id_member']]['is_guest'] = true; |
1492 | - } |
|
1493 | - else |
|
1553 | + } else |
|
1494 | 1554 | { |
1495 | 1555 | // Define this here to make things a bit more readable |
1496 | 1556 | $can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own')); |
@@ -1513,8 +1573,9 @@ discard block |
||
1513 | 1573 | $message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']); |
1514 | 1574 | |
1515 | 1575 | // If it's in the recycle bin we need to override whatever icon we did have. |
1516 | - if (!empty($board_info['recycle'])) |
|
1517 | - $message['icon'] = 'recycled'; |
|
1576 | + if (!empty($board_info['recycle'])) { |
|
1577 | + $message['icon'] = 'recycled'; |
|
1578 | + } |
|
1518 | 1579 | |
1519 | 1580 | require_once($sourcedir . '/Subs-Attachments.php'); |
1520 | 1581 | |
@@ -1558,32 +1619,36 @@ discard block |
||
1558 | 1619 | } |
1559 | 1620 | |
1560 | 1621 | // Are likes enable? |
1561 | - if (!empty($modSettings['enable_likes'])) |
|
1562 | - $output['likes'] = array( |
|
1622 | + if (!empty($modSettings['enable_likes'])) { |
|
1623 | + $output['likes'] = array( |
|
1563 | 1624 | 'count' => $message['likes'], |
1564 | 1625 | 'you' => in_array($message['id_msg'], $context['my_likes']), |
1565 | 1626 | 'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']), |
1566 | 1627 | ); |
1628 | + } |
|
1567 | 1629 | |
1568 | 1630 | // Is this user the message author? |
1569 | 1631 | $output['is_message_author'] = $message['id_member'] == $user_info['id']; |
1570 | - if (!empty($output['modified']['name'])) |
|
1571 | - $output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']); |
|
1632 | + if (!empty($output['modified']['name'])) { |
|
1633 | + $output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']); |
|
1634 | + } |
|
1572 | 1635 | |
1573 | 1636 | // Did they give a reason for editing? |
1574 | - if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) |
|
1575 | - $output['modified']['last_edit_text'] .= ' ' . sprintf($txt['last_edit_reason'], $output['modified']['reason']); |
|
1637 | + if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) { |
|
1638 | + $output['modified']['last_edit_text'] .= ' ' . sprintf($txt['last_edit_reason'], $output['modified']['reason']); |
|
1639 | + } |
|
1576 | 1640 | |
1577 | 1641 | // Any custom profile fields? |
1578 | - if (!empty($memberContext[$message['id_member']]['custom_fields'])) |
|
1579 | - foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom) |
|
1642 | + if (!empty($memberContext[$message['id_member']]['custom_fields'])) { |
|
1643 | + foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom) |
|
1580 | 1644 | $output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom; |
1645 | + } |
|
1581 | 1646 | |
1582 | - if (empty($options['view_newest_first'])) |
|
1583 | - $counter++; |
|
1584 | - |
|
1585 | - else |
|
1586 | - $counter--; |
|
1647 | + if (empty($options['view_newest_first'])) { |
|
1648 | + $counter++; |
|
1649 | + } else { |
|
1650 | + $counter--; |
|
1651 | + } |
|
1587 | 1652 | |
1588 | 1653 | call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter)); |
1589 | 1654 | |
@@ -1609,21 +1674,23 @@ discard block |
||
1609 | 1674 | $context['no_last_modified'] = true; |
1610 | 1675 | |
1611 | 1676 | // Prevent a preview image from being displayed twice. |
1612 | - if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview')) |
|
1613 | - return; |
|
1677 | + if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview')) { |
|
1678 | + return; |
|
1679 | + } |
|
1614 | 1680 | |
1615 | 1681 | // Make sure some attachment was requested! |
1616 | - if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id'])) |
|
1617 | - fatal_lang_error('no_access', false); |
|
1682 | + if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id'])) { |
|
1683 | + fatal_lang_error('no_access', false); |
|
1684 | + } |
|
1618 | 1685 | |
1619 | 1686 | $_REQUEST['attach'] = isset($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : (int) $_REQUEST['id']; |
1620 | 1687 | |
1621 | 1688 | // Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request. |
1622 | 1689 | $attachRequest = null; |
1623 | 1690 | call_integration_hook('integrate_download_request', array(&$attachRequest)); |
1624 | - if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) |
|
1625 | - $request = $attachRequest; |
|
1626 | - else |
|
1691 | + if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) { |
|
1692 | + $request = $attachRequest; |
|
1693 | + } else |
|
1627 | 1694 | { |
1628 | 1695 | // This checks only the current board for $board/$topic's permissions. |
1629 | 1696 | isAllowedTo('view_attachments'); |
@@ -1644,19 +1711,21 @@ discard block |
||
1644 | 1711 | ); |
1645 | 1712 | } |
1646 | 1713 | |
1647 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
1648 | - fatal_lang_error('no_access', false); |
|
1714 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1715 | + fatal_lang_error('no_access', false); |
|
1716 | + } |
|
1649 | 1717 | |
1650 | 1718 | list ($id_folder, $real_filename, $file_hash, $file_ext, $id_attach, $attachment_type, $mime_type, $is_approved, $id_member) = $smcFunc['db_fetch_row']($request); |
1651 | 1719 | $smcFunc['db_free_result']($request); |
1652 | 1720 | |
1653 | 1721 | // If it isn't yet approved, do they have permission to view it? |
1654 | - if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3)) |
|
1655 | - isAllowedTo('approve_posts'); |
|
1722 | + if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3)) { |
|
1723 | + isAllowedTo('approve_posts'); |
|
1724 | + } |
|
1656 | 1725 | |
1657 | 1726 | // Update the download counter (unless it's a thumbnail). |
1658 | - if ($attachment_type != 3) |
|
1659 | - $smcFunc['db_query']('attach_download_increase', ' |
|
1727 | + if ($attachment_type != 3) { |
|
1728 | + $smcFunc['db_query']('attach_download_increase', ' |
|
1660 | 1729 | UPDATE LOW_PRIORITY {db_prefix}attachments |
1661 | 1730 | SET downloads = downloads + 1 |
1662 | 1731 | WHERE id_attach = {int:id_attach}', |
@@ -1664,15 +1733,15 @@ discard block |
||
1664 | 1733 | 'id_attach' => $id_attach, |
1665 | 1734 | ) |
1666 | 1735 | ); |
1736 | + } |
|
1667 | 1737 | |
1668 | 1738 | $filename = getAttachmentFilename($real_filename, $_REQUEST['attach'], $id_folder, false, $file_hash); |
1669 | 1739 | |
1670 | 1740 | // This is done to clear any output that was made before now. |
1671 | 1741 | ob_end_clean(); |
1672 | - if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java'))) |
|
1673 | - @ob_start('ob_gzhandler'); |
|
1674 | - |
|
1675 | - else |
|
1742 | + if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java'))) { |
|
1743 | + @ob_start('ob_gzhandler'); |
|
1744 | + } else |
|
1676 | 1745 | { |
1677 | 1746 | ob_start(); |
1678 | 1747 | header('Content-Encoding: none'); |
@@ -1715,8 +1784,9 @@ discard block |
||
1715 | 1784 | // Send the attachment headers. |
1716 | 1785 | header('Pragma: '); |
1717 | 1786 | |
1718 | - if (!isBrowser('gecko')) |
|
1719 | - header('Content-Transfer-Encoding: binary'); |
|
1787 | + if (!isBrowser('gecko')) { |
|
1788 | + header('Content-Transfer-Encoding: binary'); |
|
1789 | + } |
|
1720 | 1790 | |
1721 | 1791 | header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT'); |
1722 | 1792 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filename)) . ' GMT'); |
@@ -1725,18 +1795,19 @@ discard block |
||
1725 | 1795 | header('ETag: ' . $eTag); |
1726 | 1796 | |
1727 | 1797 | // Make sure the mime type warrants an inline display. |
1728 | - if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0) |
|
1729 | - unset($_REQUEST['image']); |
|
1798 | + if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0) { |
|
1799 | + unset($_REQUEST['image']); |
|
1800 | + } |
|
1730 | 1801 | |
1731 | 1802 | // Does this have a mime type? |
1732 | - elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) |
|
1733 | - header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp'))); |
|
1734 | - |
|
1735 | - else |
|
1803 | + elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) { |
|
1804 | + header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp'))); |
|
1805 | + } else |
|
1736 | 1806 | { |
1737 | 1807 | header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream')); |
1738 | - if (isset($_REQUEST['image'])) |
|
1739 | - unset($_REQUEST['image']); |
|
1808 | + if (isset($_REQUEST['image'])) { |
|
1809 | + unset($_REQUEST['image']); |
|
1810 | + } |
|
1740 | 1811 | } |
1741 | 1812 | |
1742 | 1813 | // Convert the file to UTF-8, cuz most browsers dig that. |
@@ -1744,23 +1815,22 @@ discard block |
||
1744 | 1815 | $disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline'; |
1745 | 1816 | |
1746 | 1817 | // Different browsers like different standards... |
1747 | - if (isBrowser('firefox')) |
|
1748 | - header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
1749 | - |
|
1750 | - elseif (isBrowser('opera')) |
|
1751 | - header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
1752 | - |
|
1753 | - elseif (isBrowser('ie')) |
|
1754 | - header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
1755 | - |
|
1756 | - else |
|
1757 | - header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
1818 | + if (isBrowser('firefox')) { |
|
1819 | + header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
1820 | + } elseif (isBrowser('opera')) { |
|
1821 | + header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
1822 | + } elseif (isBrowser('ie')) { |
|
1823 | + header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
1824 | + } else { |
|
1825 | + header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
1826 | + } |
|
1758 | 1827 | |
1759 | 1828 | // If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE. |
1760 | - if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) |
|
1761 | - header('Cache-Control: no-cache'); |
|
1762 | - else |
|
1763 | - header('Cache-Control: max-age=' . (525600 * 60) . ', private'); |
|
1829 | + if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) { |
|
1830 | + header('Cache-Control: no-cache'); |
|
1831 | + } else { |
|
1832 | + header('Cache-Control: max-age=' . (525600 * 60) . ', private'); |
|
1833 | + } |
|
1764 | 1834 | |
1765 | 1835 | header('Content-Length: ' . filesize($filename)); |
1766 | 1836 | |
@@ -1770,20 +1840,23 @@ discard block |
||
1770 | 1840 | // Recode line endings for text files, if enabled. |
1771 | 1841 | if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file_ext, array('txt', 'css', 'htm', 'html', 'php', 'xml'))) |
1772 | 1842 | { |
1773 | - if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) |
|
1774 | - $callback = function($buffer) |
|
1843 | + if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) { |
|
1844 | + $callback = function($buffer) |
|
1775 | 1845 | { |
1776 | 1846 | return preg_replace('~[\r]?\n~', "\r\n", $buffer); |
1847 | + } |
|
1777 | 1848 | }; |
1778 | - elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) |
|
1779 | - $callback = function($buffer) |
|
1849 | + elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) { |
|
1850 | + $callback = function($buffer) |
|
1780 | 1851 | { |
1781 | 1852 | return preg_replace('~[\r]?\n~', "\r", $buffer); |
1853 | + } |
|
1782 | 1854 | }; |
1783 | - else |
|
1784 | - $callback = function($buffer) |
|
1855 | + else { |
|
1856 | + $callback = function($buffer) |
|
1785 | 1857 | { |
1786 | 1858 | return preg_replace('~[\r]?\n~', "\n", $buffer); |
1859 | + } |
|
1787 | 1860 | }; |
1788 | 1861 | } |
1789 | 1862 | |
@@ -1791,23 +1864,26 @@ discard block |
||
1791 | 1864 | if (filesize($filename) > 4194304) |
1792 | 1865 | { |
1793 | 1866 | // Forcibly end any output buffering going on. |
1794 | - while (@ob_get_level() > 0) |
|
1795 | - @ob_end_clean(); |
|
1867 | + while (@ob_get_level() > 0) { |
|
1868 | + @ob_end_clean(); |
|
1869 | + } |
|
1796 | 1870 | |
1797 | 1871 | $fp = fopen($filename, 'rb'); |
1798 | 1872 | while (!feof($fp)) |
1799 | 1873 | { |
1800 | - if (isset($callback)) |
|
1801 | - echo $callback(fread($fp, 8192)); |
|
1802 | - else |
|
1803 | - echo fread($fp, 8192); |
|
1874 | + if (isset($callback)) { |
|
1875 | + echo $callback(fread($fp, 8192)); |
|
1876 | + } else { |
|
1877 | + echo fread($fp, 8192); |
|
1878 | + } |
|
1804 | 1879 | flush(); |
1805 | 1880 | } |
1806 | 1881 | fclose($fp); |
1807 | 1882 | } |
1808 | 1883 | // On some of the less-bright hosts, readfile() is disabled. It's just a faster, more byte safe, version of what's in the if. |
1809 | - elseif (isset($callback) || @readfile($filename) === null) |
|
1810 | - echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename); |
|
1884 | + elseif (isset($callback) || @readfile($filename) === null) { |
|
1885 | + echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename); |
|
1886 | + } |
|
1811 | 1887 | |
1812 | 1888 | obExit(false); |
1813 | 1889 | } |
@@ -1820,8 +1896,9 @@ discard block |
||
1820 | 1896 | */ |
1821 | 1897 | function approved_attach_sort($a, $b) |
1822 | 1898 | { |
1823 | - if ($a['is_approved'] == $b['is_approved']) |
|
1824 | - return 0; |
|
1899 | + if ($a['is_approved'] == $b['is_approved']) { |
|
1900 | + return 0; |
|
1901 | + } |
|
1825 | 1902 | |
1826 | 1903 | return $a['is_approved'] > $b['is_approved'] ? -1 : 1; |
1827 | 1904 | } |
@@ -1838,16 +1915,19 @@ discard block |
||
1838 | 1915 | |
1839 | 1916 | require_once($sourcedir . '/RemoveTopic.php'); |
1840 | 1917 | |
1841 | - if (empty($_REQUEST['msgs'])) |
|
1842 | - redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
1918 | + if (empty($_REQUEST['msgs'])) { |
|
1919 | + redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
1920 | + } |
|
1843 | 1921 | |
1844 | 1922 | $messages = array(); |
1845 | - foreach ($_REQUEST['msgs'] as $dummy) |
|
1846 | - $messages[] = (int) $dummy; |
|
1923 | + foreach ($_REQUEST['msgs'] as $dummy) { |
|
1924 | + $messages[] = (int) $dummy; |
|
1925 | + } |
|
1847 | 1926 | |
1848 | 1927 | // We are restoring messages. We handle this in another place. |
1849 | - if (isset($_REQUEST['restore_selected'])) |
|
1850 | - redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1928 | + if (isset($_REQUEST['restore_selected'])) { |
|
1929 | + redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1930 | + } |
|
1851 | 1931 | if (isset($_REQUEST['split_selection'])) |
1852 | 1932 | { |
1853 | 1933 | $request = $smcFunc['db_query']('', ' |
@@ -1866,8 +1946,9 @@ discard block |
||
1866 | 1946 | } |
1867 | 1947 | |
1868 | 1948 | // Allowed to delete any message? |
1869 | - if (allowedTo('delete_any')) |
|
1870 | - $allowed_all = true; |
|
1949 | + if (allowedTo('delete_any')) { |
|
1950 | + $allowed_all = true; |
|
1951 | + } |
|
1871 | 1952 | // Allowed to delete replies to their messages? |
1872 | 1953 | elseif (allowedTo('delete_replies')) |
1873 | 1954 | { |
@@ -1884,13 +1965,14 @@ discard block |
||
1884 | 1965 | $smcFunc['db_free_result']($request); |
1885 | 1966 | |
1886 | 1967 | $allowed_all = $starter == $user_info['id']; |
1968 | + } else { |
|
1969 | + $allowed_all = false; |
|
1887 | 1970 | } |
1888 | - else |
|
1889 | - $allowed_all = false; |
|
1890 | 1971 | |
1891 | 1972 | // Make sure they're allowed to delete their own messages, if not any. |
1892 | - if (!$allowed_all) |
|
1893 | - isAllowedTo('delete_own'); |
|
1973 | + if (!$allowed_all) { |
|
1974 | + isAllowedTo('delete_own'); |
|
1975 | + } |
|
1894 | 1976 | |
1895 | 1977 | // Allowed to remove which messages? |
1896 | 1978 | $request = $smcFunc['db_query']('', ' |
@@ -1910,8 +1992,9 @@ discard block |
||
1910 | 1992 | $messages = array(); |
1911 | 1993 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1912 | 1994 | { |
1913 | - if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) |
|
1914 | - continue; |
|
1995 | + if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) { |
|
1996 | + continue; |
|
1997 | + } |
|
1915 | 1998 | |
1916 | 1999 | $messages[$row['id_msg']] = array($row['subject'], $row['id_member']); |
1917 | 2000 | } |
@@ -1934,17 +2017,20 @@ discard block |
||
1934 | 2017 | foreach ($messages as $message => $info) |
1935 | 2018 | { |
1936 | 2019 | // Just skip the first message - if it's not the last. |
1937 | - if ($message == $first_message && $message != $last_message) |
|
1938 | - continue; |
|
2020 | + if ($message == $first_message && $message != $last_message) { |
|
2021 | + continue; |
|
2022 | + } |
|
1939 | 2023 | // If the first message is going then don't bother going back to the topic as we're effectively deleting it. |
1940 | - elseif ($message == $first_message) |
|
1941 | - $topicGone = true; |
|
2024 | + elseif ($message == $first_message) { |
|
2025 | + $topicGone = true; |
|
2026 | + } |
|
1942 | 2027 | |
1943 | 2028 | removeMessage($message); |
1944 | 2029 | |
1945 | 2030 | // Log this moderation action ;). |
1946 | - if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) |
|
1947 | - logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board)); |
|
2031 | + if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) { |
|
2032 | + logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board)); |
|
2033 | + } |
|
1948 | 2034 | } |
1949 | 2035 | |
1950 | 2036 | redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']); |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Load the $modSettings array. |
@@ -25,13 +26,14 @@ discard block |
||
25 | 26 | global $cache_enable, $sourcedir, $context; |
26 | 27 | |
27 | 28 | // Most database systems have not set UTF-8 as their default input charset. |
28 | - if (!empty($db_character_set)) |
|
29 | - $smcFunc['db_query']('', ' |
|
29 | + if (!empty($db_character_set)) { |
|
30 | + $smcFunc['db_query']('', ' |
|
30 | 31 | SET NAMES {string:db_character_set}', |
31 | 32 | array( |
32 | 33 | 'db_character_set' => $db_character_set, |
33 | 34 | ) |
34 | 35 | ); |
36 | + } |
|
35 | 37 | |
36 | 38 | // We need some caching support, maybe. |
37 | 39 | loadCacheAccelerator(); |
@@ -46,27 +48,35 @@ discard block |
||
46 | 48 | ) |
47 | 49 | ); |
48 | 50 | $modSettings = array(); |
49 | - if (!$request) |
|
50 | - display_db_error(); |
|
51 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
52 | - $modSettings[$row[0]] = $row[1]; |
|
51 | + if (!$request) { |
|
52 | + display_db_error(); |
|
53 | + } |
|
54 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
55 | + $modSettings[$row[0]] = $row[1]; |
|
56 | + } |
|
53 | 57 | $smcFunc['db_free_result']($request); |
54 | 58 | |
55 | 59 | // Do a few things to protect against missing settings or settings with invalid values... |
56 | - if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) |
|
57 | - $modSettings['defaultMaxTopics'] = 20; |
|
58 | - if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) |
|
59 | - $modSettings['defaultMaxMessages'] = 15; |
|
60 | - if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) |
|
61 | - $modSettings['defaultMaxMembers'] = 30; |
|
62 | - if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) |
|
63 | - $modSettings['defaultMaxListItems'] = 15; |
|
60 | + if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) { |
|
61 | + $modSettings['defaultMaxTopics'] = 20; |
|
62 | + } |
|
63 | + if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) { |
|
64 | + $modSettings['defaultMaxMessages'] = 15; |
|
65 | + } |
|
66 | + if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) { |
|
67 | + $modSettings['defaultMaxMembers'] = 30; |
|
68 | + } |
|
69 | + if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) { |
|
70 | + $modSettings['defaultMaxListItems'] = 15; |
|
71 | + } |
|
64 | 72 | |
65 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
66 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
73 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
74 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
75 | + } |
|
67 | 76 | |
68 | - if (!empty($cache_enable)) |
|
69 | - cache_put_data('modSettings', $modSettings, 90); |
|
77 | + if (!empty($cache_enable)) { |
|
78 | + cache_put_data('modSettings', $modSettings, 90); |
|
79 | + } |
|
70 | 80 | } |
71 | 81 | |
72 | 82 | $modSettings['cache_enable'] = $cache_enable; |
@@ -86,8 +96,9 @@ discard block |
||
86 | 96 | }; |
87 | 97 | $fix_utf8mb4 = function($string) use ($utf8, $smcFunc) |
88 | 98 | { |
89 | - if (!$utf8 || $smcFunc['db_mb4']) |
|
90 | - return $string; |
|
99 | + if (!$utf8 || $smcFunc['db_mb4']) { |
|
100 | + return $string; |
|
101 | + } |
|
91 | 102 | |
92 | 103 | $i = 0; |
93 | 104 | $len = strlen($string); |
@@ -99,18 +110,15 @@ discard block |
||
99 | 110 | { |
100 | 111 | $new_string .= $string[$i]; |
101 | 112 | $i++; |
102 | - } |
|
103 | - elseif ($ord < 224) |
|
113 | + } elseif ($ord < 224) |
|
104 | 114 | { |
105 | 115 | $new_string .= $string[$i] . $string[$i + 1]; |
106 | 116 | $i += 2; |
107 | - } |
|
108 | - elseif ($ord < 240) |
|
117 | + } elseif ($ord < 240) |
|
109 | 118 | { |
110 | 119 | $new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2]; |
111 | 120 | $i += 3; |
112 | - } |
|
113 | - elseif ($ord < 248) |
|
121 | + } elseif ($ord < 248) |
|
114 | 122 | { |
115 | 123 | // Magic happens. |
116 | 124 | $val = (ord($string[$i]) & 0x07) << 18; |
@@ -154,8 +162,7 @@ discard block |
||
154 | 162 | { |
155 | 163 | $result = array_search($needle, array_slice($haystack_arr, $offset)); |
156 | 164 | return is_int($result) ? $result + $offset : false; |
157 | - } |
|
158 | - else |
|
165 | + } else |
|
159 | 166 | { |
160 | 167 | $needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|"|&|<|>| |.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
161 | 168 | $needle_size = count($needle_arr); |
@@ -164,8 +171,9 @@ discard block |
||
164 | 171 | while ((int) $result === $result) |
165 | 172 | { |
166 | 173 | $offset += $result; |
167 | - if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) |
|
168 | - return $offset; |
|
174 | + if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) { |
|
175 | + return $offset; |
|
176 | + } |
|
169 | 177 | $result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset)); |
170 | 178 | } |
171 | 179 | return false; |
@@ -203,8 +211,9 @@ discard block |
||
203 | 211 | $string = $ent_check($string); |
204 | 212 | preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches); |
205 | 213 | $string = $matches[0]; |
206 | - while (strlen($string) > $length) |
|
207 | - $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
214 | + while (strlen($string) > $length) { |
|
215 | + $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
216 | + } |
|
208 | 217 | return $string; |
209 | 218 | }, |
210 | 219 | 'ucfirst' => $utf8 ? function($string) use (&$smcFunc) |
@@ -214,23 +223,25 @@ discard block |
||
214 | 223 | 'ucwords' => $utf8 ? function($string) use (&$smcFunc) |
215 | 224 | { |
216 | 225 | $words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE); |
217 | - for ($i = 0, $n = count($words); $i < $n; $i += 2) |
|
218 | - $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
226 | + for ($i = 0, $n = count($words); $i < $n; $i += 2) { |
|
227 | + $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
228 | + } |
|
219 | 229 | return implode('', $words); |
220 | 230 | } : 'ucwords', |
221 | 231 | ); |
222 | 232 | |
223 | 233 | // Setting the timezone is a requirement for some functions. |
224 | - if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
|
225 | - date_default_timezone_set($modSettings['default_timezone']); |
|
226 | - else |
|
234 | + if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) { |
|
235 | + date_default_timezone_set($modSettings['default_timezone']); |
|
236 | + } else |
|
227 | 237 | { |
228 | 238 | // Get PHP's default timezone, if set |
229 | 239 | $ini_tz = ini_get('date.timezone'); |
230 | - if (!empty($ini_tz)) |
|
231 | - $modSettings['default_timezone'] = $ini_tz; |
|
232 | - else |
|
233 | - $modSettings['default_timezone'] = ''; |
|
240 | + if (!empty($ini_tz)) { |
|
241 | + $modSettings['default_timezone'] = $ini_tz; |
|
242 | + } else { |
|
243 | + $modSettings['default_timezone'] = ''; |
|
244 | + } |
|
234 | 245 | |
235 | 246 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
236 | 247 | if (!in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
@@ -248,22 +259,26 @@ discard block |
||
248 | 259 | if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null) |
249 | 260 | { |
250 | 261 | $modSettings['load_average'] = @file_get_contents('/proc/loadavg'); |
251 | - if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) |
|
252 | - $modSettings['load_average'] = (float) $matches[1]; |
|
253 | - elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) |
|
254 | - $modSettings['load_average'] = (float) $matches[1]; |
|
255 | - else |
|
256 | - unset($modSettings['load_average']); |
|
262 | + if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) { |
|
263 | + $modSettings['load_average'] = (float) $matches[1]; |
|
264 | + } elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) { |
|
265 | + $modSettings['load_average'] = (float) $matches[1]; |
|
266 | + } else { |
|
267 | + unset($modSettings['load_average']); |
|
268 | + } |
|
257 | 269 | |
258 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
259 | - cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
270 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
271 | + cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
272 | + } |
|
260 | 273 | } |
261 | 274 | |
262 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
263 | - call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
275 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
276 | + call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
277 | + } |
|
264 | 278 | |
265 | - if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) |
|
266 | - display_loadavg_error(); |
|
279 | + if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) { |
|
280 | + display_loadavg_error(); |
|
281 | + } |
|
267 | 282 | } |
268 | 283 | |
269 | 284 | // Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is. |
@@ -284,8 +299,9 @@ discard block |
||
284 | 299 | if (defined('SMF_INTEGRATION_SETTINGS')) |
285 | 300 | { |
286 | 301 | $integration_settings = smf_json_decode(SMF_INTEGRATION_SETTINGS, true); |
287 | - foreach ($integration_settings as $hook => $function) |
|
288 | - add_integration_function($hook, $function, '', false); |
|
302 | + foreach ($integration_settings as $hook => $function) { |
|
303 | + add_integration_function($hook, $function, '', false); |
|
304 | + } |
|
289 | 305 | } |
290 | 306 | |
291 | 307 | // Any files to pre include? |
@@ -295,8 +311,9 @@ discard block |
||
295 | 311 | foreach ($pre_includes as $include) |
296 | 312 | { |
297 | 313 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
298 | - if (file_exists($include)) |
|
299 | - require_once($include); |
|
314 | + if (file_exists($include)) { |
|
315 | + require_once($include); |
|
316 | + } |
|
300 | 317 | } |
301 | 318 | } |
302 | 319 | |
@@ -400,27 +417,28 @@ discard block |
||
400 | 417 | break; |
401 | 418 | } |
402 | 419 | } |
420 | + } else { |
|
421 | + $id_member = 0; |
|
403 | 422 | } |
404 | - else |
|
405 | - $id_member = 0; |
|
406 | 423 | |
407 | 424 | if (empty($id_member) && isset($_COOKIE[$cookiename])) |
408 | 425 | { |
409 | 426 | $cookie_data = smf_json_decode($_COOKIE[$cookiename], true, false); |
410 | 427 | |
411 | - if (empty($cookie_data)) |
|
412 | - $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
428 | + if (empty($cookie_data)) { |
|
429 | + $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
430 | + } |
|
413 | 431 | |
414 | 432 | list ($id_member, $password) = $cookie_data; |
415 | 433 | $id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0; |
416 | - } |
|
417 | - elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
434 | + } elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
418 | 435 | { |
419 | 436 | // @todo Perhaps we can do some more checking on this, such as on the first octet of the IP? |
420 | 437 | $cookie_data = smf_json_decode($_SESSION['login_' . $cookiename]); |
421 | 438 | |
422 | - if (empty($cookie_data)) |
|
423 | - $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
439 | + if (empty($cookie_data)) { |
|
440 | + $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
441 | + } |
|
424 | 442 | |
425 | 443 | list ($id_member, $password, $login_span) = $cookie_data; |
426 | 444 | $id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0; |
@@ -445,30 +463,34 @@ discard block |
||
445 | 463 | $user_settings = $smcFunc['db_fetch_assoc']($request); |
446 | 464 | $smcFunc['db_free_result']($request); |
447 | 465 | |
448 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) |
|
449 | - $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
466 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) { |
|
467 | + $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
468 | + } |
|
450 | 469 | |
451 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
452 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
470 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
471 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
472 | + } |
|
453 | 473 | } |
454 | 474 | |
455 | 475 | // Did we find 'im? If not, junk it. |
456 | 476 | if (!empty($user_settings)) |
457 | 477 | { |
458 | 478 | // As much as the password should be right, we can assume the integration set things up. |
459 | - if (!empty($already_verified) && $already_verified === true) |
|
460 | - $check = true; |
|
479 | + if (!empty($already_verified) && $already_verified === true) { |
|
480 | + $check = true; |
|
481 | + } |
|
461 | 482 | // SHA-512 hash should be 128 characters long. |
462 | - elseif (strlen($password) == 128) |
|
463 | - $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
464 | - else |
|
465 | - $check = false; |
|
483 | + elseif (strlen($password) == 128) { |
|
484 | + $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
485 | + } else { |
|
486 | + $check = false; |
|
487 | + } |
|
466 | 488 | |
467 | 489 | // Wrong password or not activated - either way, you're going nowhere. |
468 | 490 | $id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0; |
491 | + } else { |
|
492 | + $id_member = 0; |
|
469 | 493 | } |
470 | - else |
|
471 | - $id_member = 0; |
|
472 | 494 | |
473 | 495 | // If we no longer have the member maybe they're being all hackey, stop brute force! |
474 | 496 | if (!$id_member) |
@@ -490,13 +512,15 @@ discard block |
||
490 | 512 | { |
491 | 513 | $tfa_data = smf_json_decode($_COOKIE[$tfacookie]); |
492 | 514 | |
493 | - if (is_null($tfa_data)) |
|
494 | - $tfa_data = safe_unserialize($_COOKIE[$tfacookie]); |
|
515 | + if (is_null($tfa_data)) { |
|
516 | + $tfa_data = safe_unserialize($_COOKIE[$tfacookie]); |
|
517 | + } |
|
495 | 518 | |
496 | 519 | list ($tfamember, $tfasecret) = $tfa_data; |
497 | 520 | |
498 | - if ((int) $tfamember != $id_member) |
|
499 | - $tfasecret = null; |
|
521 | + if ((int) $tfamember != $id_member) { |
|
522 | + $tfasecret = null; |
|
523 | + } |
|
500 | 524 | } |
501 | 525 | |
502 | 526 | if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret) |
@@ -516,10 +540,12 @@ discard block |
||
516 | 540 | // Are we forcing 2FA? Need to check if the user groups actually require 2FA |
517 | 541 | elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret'])) |
518 | 542 | { |
519 | - if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups |
|
543 | + if ($modSettings['tfa_mode'] == 2) { |
|
544 | + //only do this if we are just forcing SOME membergroups |
|
520 | 545 | { |
521 | 546 | //Build an array of ALL user membergroups. |
522 | 547 | $full_groups = array($user_settings['id_group']); |
548 | + } |
|
523 | 549 | if (!empty($user_settings['additional_groups'])) |
524 | 550 | { |
525 | 551 | $full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups'])); |
@@ -539,15 +565,17 @@ discard block |
||
539 | 565 | ); |
540 | 566 | $row = $smcFunc['db_fetch_assoc']($request); |
541 | 567 | $smcFunc['db_free_result']($request); |
568 | + } else { |
|
569 | + $row['total'] = 1; |
|
542 | 570 | } |
543 | - else |
|
544 | - $row['total'] = 1; //simplifies logics in the next "if" |
|
571 | + //simplifies logics in the next "if" |
|
545 | 572 | |
546 | 573 | $area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : ''; |
547 | 574 | $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
548 | 575 | |
549 | - if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) |
|
550 | - redirectexit('action=profile;area=tfasetup;forced'); |
|
576 | + if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) { |
|
577 | + redirectexit('action=profile;area=tfasetup;forced'); |
|
578 | + } |
|
551 | 579 | } |
552 | 580 | } |
553 | 581 | |
@@ -584,33 +612,37 @@ discard block |
||
584 | 612 | updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'])); |
585 | 613 | $user_settings['last_login'] = time(); |
586 | 614 | |
587 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
588 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
615 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
616 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
617 | + } |
|
589 | 618 | |
590 | - if (!empty($modSettings['cache_enable'])) |
|
591 | - cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
619 | + if (!empty($modSettings['cache_enable'])) { |
|
620 | + cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
621 | + } |
|
592 | 622 | } |
623 | + } elseif (empty($_SESSION['id_msg_last_visit'])) { |
|
624 | + $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
593 | 625 | } |
594 | - elseif (empty($_SESSION['id_msg_last_visit'])) |
|
595 | - $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
596 | 626 | |
597 | 627 | $username = $user_settings['member_name']; |
598 | 628 | |
599 | - if (empty($user_settings['additional_groups'])) |
|
600 | - $user_info = array( |
|
629 | + if (empty($user_settings['additional_groups'])) { |
|
630 | + $user_info = array( |
|
601 | 631 | 'groups' => array($user_settings['id_group'], $user_settings['id_post_group']) |
602 | 632 | ); |
603 | - else |
|
604 | - $user_info = array( |
|
633 | + } else { |
|
634 | + $user_info = array( |
|
605 | 635 | 'groups' => array_merge( |
606 | 636 | array($user_settings['id_group'], $user_settings['id_post_group']), |
607 | 637 | explode(',', $user_settings['additional_groups']) |
608 | 638 | ) |
609 | 639 | ); |
640 | + } |
|
610 | 641 | |
611 | 642 | // Because history has proven that it is possible for groups to go bad - clean up in case. |
612 | - foreach ($user_info['groups'] as $k => $v) |
|
613 | - $user_info['groups'][$k] = (int) $v; |
|
643 | + foreach ($user_info['groups'] as $k => $v) { |
|
644 | + $user_info['groups'][$k] = (int) $v; |
|
645 | + } |
|
614 | 646 | |
615 | 647 | // This is a logged in user, so definitely not a spider. |
616 | 648 | $user_info['possibly_robot'] = false; |
@@ -624,8 +656,7 @@ discard block |
||
624 | 656 | $time_system = new DateTime('now', $tz_system); |
625 | 657 | $time_user = new DateTime('now', $tz_user); |
626 | 658 | $user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600; |
627 | - } |
|
628 | - else |
|
659 | + } else |
|
629 | 660 | { |
630 | 661 | // !!! Compatibility. |
631 | 662 | $user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset']; |
@@ -639,16 +670,18 @@ discard block |
||
639 | 670 | $user_info = array('groups' => array(-1)); |
640 | 671 | $user_settings = array(); |
641 | 672 | |
642 | - if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) |
|
643 | - $_COOKIE[$cookiename] = ''; |
|
673 | + if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) { |
|
674 | + $_COOKIE[$cookiename] = ''; |
|
675 | + } |
|
644 | 676 | |
645 | 677 | // Expire the 2FA cookie |
646 | 678 | if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member'])) |
647 | 679 | { |
648 | 680 | $tfa_data = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true); |
649 | 681 | |
650 | - if (is_null($tfa_data)) |
|
651 | - $tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']); |
|
682 | + if (is_null($tfa_data)) { |
|
683 | + $tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']); |
|
684 | + } |
|
652 | 685 | |
653 | 686 | list ($id, $user, $exp, $state, $preserve) = $tfa_data; |
654 | 687 | |
@@ -660,19 +693,20 @@ discard block |
||
660 | 693 | } |
661 | 694 | |
662 | 695 | // Create a login token if it doesn't exist yet. |
663 | - if (!isset($_SESSION['token']['post-login'])) |
|
664 | - createToken('login'); |
|
665 | - else |
|
666 | - list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
696 | + if (!isset($_SESSION['token']['post-login'])) { |
|
697 | + createToken('login'); |
|
698 | + } else { |
|
699 | + list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
700 | + } |
|
667 | 701 | |
668 | 702 | // Do we perhaps think this is a search robot? Check every five minutes just in case... |
669 | 703 | if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300)) |
670 | 704 | { |
671 | 705 | require_once($sourcedir . '/ManageSearchEngines.php'); |
672 | 706 | $user_info['possibly_robot'] = SpiderCheck(); |
707 | + } elseif (!empty($modSettings['spider_mode'])) { |
|
708 | + $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
673 | 709 | } |
674 | - elseif (!empty($modSettings['spider_mode'])) |
|
675 | - $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
676 | 710 | // If we haven't turned on proper spider hunts then have a guess! |
677 | 711 | else |
678 | 712 | { |
@@ -720,8 +754,9 @@ discard block |
||
720 | 754 | $user_info['groups'] = array_unique($user_info['groups']); |
721 | 755 | |
722 | 756 | // Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems. |
723 | - if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) |
|
724 | - unset($user_info['ignoreboards'][$tmp]); |
|
757 | + if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) { |
|
758 | + unset($user_info['ignoreboards'][$tmp]); |
|
759 | + } |
|
725 | 760 | |
726 | 761 | // Allow the user to change their language. |
727 | 762 | if (!empty($modSettings['userLanguage'])) |
@@ -734,31 +769,36 @@ discard block |
||
734 | 769 | $user_info['language'] = strtr($_GET['language'], './\\:', '____'); |
735 | 770 | |
736 | 771 | // Make it permanent for members. |
737 | - if (!empty($user_info['id'])) |
|
738 | - updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
739 | - else |
|
740 | - $_SESSION['language'] = $user_info['language']; |
|
772 | + if (!empty($user_info['id'])) { |
|
773 | + updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
774 | + } else { |
|
775 | + $_SESSION['language'] = $user_info['language']; |
|
776 | + } |
|
777 | + } elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) { |
|
778 | + $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
741 | 779 | } |
742 | - elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) |
|
743 | - $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
744 | 780 | } |
745 | 781 | |
746 | 782 | // Just build this here, it makes it easier to change/use - administrators can see all boards. |
747 | - if ($user_info['is_admin']) |
|
748 | - $user_info['query_see_board'] = '1=1'; |
|
783 | + if ($user_info['is_admin']) { |
|
784 | + $user_info['query_see_board'] = '1=1'; |
|
785 | + } |
|
749 | 786 | // Otherwise just the groups in $user_info['groups']. |
750 | - else |
|
751 | - $user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')'; |
|
787 | + else { |
|
788 | + $user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')'; |
|
789 | + } |
|
752 | 790 | |
753 | 791 | // Build the list of boards they WANT to see. |
754 | 792 | // This will take the place of query_see_boards in certain spots, so it better include the boards they can see also |
755 | 793 | |
756 | 794 | // If they aren't ignoring any boards then they want to see all the boards they can see |
757 | - if (empty($user_info['ignoreboards'])) |
|
758 | - $user_info['query_wanna_see_board'] = $user_info['query_see_board']; |
|
795 | + if (empty($user_info['ignoreboards'])) { |
|
796 | + $user_info['query_wanna_see_board'] = $user_info['query_see_board']; |
|
797 | + } |
|
759 | 798 | // Ok I guess they don't want to see all the boards |
760 | - else |
|
761 | - $user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))'; |
|
799 | + else { |
|
800 | + $user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))'; |
|
801 | + } |
|
762 | 802 | |
763 | 803 | call_integration_hook('integrate_user_info'); |
764 | 804 | } |
@@ -816,9 +856,9 @@ discard block |
||
816 | 856 | } |
817 | 857 | |
818 | 858 | // Remember redirection is the key to avoiding fallout from your bosses. |
819 | - if (!empty($topic)) |
|
820 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
821 | - else |
|
859 | + if (!empty($topic)) { |
|
860 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
861 | + } else |
|
822 | 862 | { |
823 | 863 | loadPermissions(); |
824 | 864 | loadTheme(); |
@@ -836,10 +876,11 @@ discard block |
||
836 | 876 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
837 | 877 | { |
838 | 878 | // @todo SLOW? |
839 | - if (!empty($topic)) |
|
840 | - $temp = cache_get_data('topic_board-' . $topic, 120); |
|
841 | - else |
|
842 | - $temp = cache_get_data('board-' . $board, 120); |
|
879 | + if (!empty($topic)) { |
|
880 | + $temp = cache_get_data('topic_board-' . $topic, 120); |
|
881 | + } else { |
|
882 | + $temp = cache_get_data('board-' . $board, 120); |
|
883 | + } |
|
843 | 884 | |
844 | 885 | if (!empty($temp)) |
845 | 886 | { |
@@ -877,8 +918,9 @@ discard block |
||
877 | 918 | $row = $smcFunc['db_fetch_assoc']($request); |
878 | 919 | |
879 | 920 | // Set the current board. |
880 | - if (!empty($row['id_board'])) |
|
881 | - $board = $row['id_board']; |
|
921 | + if (!empty($row['id_board'])) { |
|
922 | + $board = $row['id_board']; |
|
923 | + } |
|
882 | 924 | |
883 | 925 | // Basic operating information. (globals... :/) |
884 | 926 | $board_info = array( |
@@ -914,21 +956,23 @@ discard block |
||
914 | 956 | |
915 | 957 | do |
916 | 958 | { |
917 | - if (!empty($row['id_moderator'])) |
|
918 | - $board_info['moderators'][$row['id_moderator']] = array( |
|
959 | + if (!empty($row['id_moderator'])) { |
|
960 | + $board_info['moderators'][$row['id_moderator']] = array( |
|
919 | 961 | 'id' => $row['id_moderator'], |
920 | 962 | 'name' => $row['real_name'], |
921 | 963 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
922 | 964 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
923 | 965 | ); |
966 | + } |
|
924 | 967 | |
925 | - if (!empty($row['id_moderator_group'])) |
|
926 | - $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
968 | + if (!empty($row['id_moderator_group'])) { |
|
969 | + $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
927 | 970 | 'id' => $row['id_moderator_group'], |
928 | 971 | 'name' => $row['group_name'], |
929 | 972 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
930 | 973 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
931 | 974 | ); |
975 | + } |
|
932 | 976 | } |
933 | 977 | while ($row = $smcFunc['db_fetch_assoc']($request)); |
934 | 978 | |
@@ -960,12 +1004,12 @@ discard block |
||
960 | 1004 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
961 | 1005 | { |
962 | 1006 | // @todo SLOW? |
963 | - if (!empty($topic)) |
|
964 | - cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
1007 | + if (!empty($topic)) { |
|
1008 | + cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
1009 | + } |
|
965 | 1010 | cache_put_data('board-' . $board, $board_info, 120); |
966 | 1011 | } |
967 | - } |
|
968 | - else |
|
1012 | + } else |
|
969 | 1013 | { |
970 | 1014 | // Otherwise the topic is invalid, there are no moderators, etc. |
971 | 1015 | $board_info = array( |
@@ -979,8 +1023,9 @@ discard block |
||
979 | 1023 | $smcFunc['db_free_result']($request); |
980 | 1024 | } |
981 | 1025 | |
982 | - if (!empty($topic)) |
|
983 | - $_GET['board'] = (int) $board; |
|
1026 | + if (!empty($topic)) { |
|
1027 | + $_GET['board'] = (int) $board; |
|
1028 | + } |
|
984 | 1029 | |
985 | 1030 | if (!empty($board)) |
986 | 1031 | { |
@@ -990,10 +1035,12 @@ discard block |
||
990 | 1035 | // Now check if the user is a moderator. |
991 | 1036 | $user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0; |
992 | 1037 | |
993 | - if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) |
|
994 | - $board_info['error'] = 'access'; |
|
995 | - if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) |
|
996 | - $board_info['error'] = 'access'; |
|
1038 | + if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) { |
|
1039 | + $board_info['error'] = 'access'; |
|
1040 | + } |
|
1041 | + if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) { |
|
1042 | + $board_info['error'] = 'access'; |
|
1043 | + } |
|
997 | 1044 | |
998 | 1045 | // Build up the linktree. |
999 | 1046 | $context['linktree'] = array_merge( |
@@ -1016,8 +1063,9 @@ discard block |
||
1016 | 1063 | $context['current_board'] = $board; |
1017 | 1064 | |
1018 | 1065 | // No posting in redirection boards! |
1019 | - if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) |
|
1020 | - $board_info['error'] == 'post_in_redirect'; |
|
1066 | + if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) { |
|
1067 | + $board_info['error'] == 'post_in_redirect'; |
|
1068 | + } |
|
1021 | 1069 | |
1022 | 1070 | // Hacker... you can't see this topic, I'll tell you that. (but moderators can!) |
1023 | 1071 | if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod'])) |
@@ -1043,24 +1091,23 @@ discard block |
||
1043 | 1091 | ob_end_clean(); |
1044 | 1092 | header('HTTP/1.1 403 Forbidden'); |
1045 | 1093 | die; |
1046 | - } |
|
1047 | - elseif ($board_info['error'] == 'post_in_redirect') |
|
1094 | + } elseif ($board_info['error'] == 'post_in_redirect') |
|
1048 | 1095 | { |
1049 | 1096 | // Slightly different error message here... |
1050 | 1097 | fatal_lang_error('cannot_post_redirect', false); |
1051 | - } |
|
1052 | - elseif ($user_info['is_guest']) |
|
1098 | + } elseif ($user_info['is_guest']) |
|
1053 | 1099 | { |
1054 | 1100 | loadLanguage('Errors'); |
1055 | 1101 | is_not_guest($txt['topic_gone']); |
1102 | + } else { |
|
1103 | + fatal_lang_error('topic_gone', false); |
|
1056 | 1104 | } |
1057 | - else |
|
1058 | - fatal_lang_error('topic_gone', false); |
|
1059 | 1105 | } |
1060 | 1106 | |
1061 | - if ($user_info['is_mod']) |
|
1062 | - $user_info['groups'][] = 3; |
|
1063 | -} |
|
1107 | + if ($user_info['is_mod']) { |
|
1108 | + $user_info['groups'][] = 3; |
|
1109 | + } |
|
1110 | + } |
|
1064 | 1111 | |
1065 | 1112 | /** |
1066 | 1113 | * Load this user's permissions. |
@@ -1081,8 +1128,9 @@ discard block |
||
1081 | 1128 | asort($cache_groups); |
1082 | 1129 | $cache_groups = implode(',', $cache_groups); |
1083 | 1130 | // If it's a spider then cache it different. |
1084 | - if ($user_info['possibly_robot']) |
|
1085 | - $cache_groups .= '-spider'; |
|
1131 | + if ($user_info['possibly_robot']) { |
|
1132 | + $cache_groups .= '-spider'; |
|
1133 | + } |
|
1086 | 1134 | |
1087 | 1135 | if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
1088 | 1136 | { |
@@ -1090,9 +1138,9 @@ discard block |
||
1090 | 1138 | banPermissions(); |
1091 | 1139 | |
1092 | 1140 | return; |
1141 | + } elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) { |
|
1142 | + list ($user_info['permissions'], $removals) = $temp; |
|
1093 | 1143 | } |
1094 | - elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
|
1095 | - list ($user_info['permissions'], $removals) = $temp; |
|
1096 | 1144 | } |
1097 | 1145 | |
1098 | 1146 | // If it is detected as a robot, and we are restricting permissions as a special group - then implement this. |
@@ -1114,23 +1162,26 @@ discard block |
||
1114 | 1162 | $removals = array(); |
1115 | 1163 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1116 | 1164 | { |
1117 | - if (empty($row['add_deny'])) |
|
1118 | - $removals[] = $row['permission']; |
|
1119 | - else |
|
1120 | - $user_info['permissions'][] = $row['permission']; |
|
1165 | + if (empty($row['add_deny'])) { |
|
1166 | + $removals[] = $row['permission']; |
|
1167 | + } else { |
|
1168 | + $user_info['permissions'][] = $row['permission']; |
|
1169 | + } |
|
1121 | 1170 | } |
1122 | 1171 | $smcFunc['db_free_result']($request); |
1123 | 1172 | |
1124 | - if (isset($cache_groups)) |
|
1125 | - cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
1173 | + if (isset($cache_groups)) { |
|
1174 | + cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
1175 | + } |
|
1126 | 1176 | } |
1127 | 1177 | |
1128 | 1178 | // Get the board permissions. |
1129 | 1179 | if (!empty($board)) |
1130 | 1180 | { |
1131 | 1181 | // Make sure the board (if any) has been loaded by loadBoard(). |
1132 | - if (!isset($board_info['profile'])) |
|
1133 | - fatal_lang_error('no_board'); |
|
1182 | + if (!isset($board_info['profile'])) { |
|
1183 | + fatal_lang_error('no_board'); |
|
1184 | + } |
|
1134 | 1185 | |
1135 | 1186 | $request = $smcFunc['db_query']('', ' |
1136 | 1187 | SELECT permission, add_deny |
@@ -1146,20 +1197,23 @@ discard block |
||
1146 | 1197 | ); |
1147 | 1198 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1148 | 1199 | { |
1149 | - if (empty($row['add_deny'])) |
|
1150 | - $removals[] = $row['permission']; |
|
1151 | - else |
|
1152 | - $user_info['permissions'][] = $row['permission']; |
|
1200 | + if (empty($row['add_deny'])) { |
|
1201 | + $removals[] = $row['permission']; |
|
1202 | + } else { |
|
1203 | + $user_info['permissions'][] = $row['permission']; |
|
1204 | + } |
|
1153 | 1205 | } |
1154 | 1206 | $smcFunc['db_free_result']($request); |
1155 | 1207 | } |
1156 | 1208 | |
1157 | 1209 | // Remove all the permissions they shouldn't have ;). |
1158 | - if (!empty($modSettings['permission_enable_deny'])) |
|
1159 | - $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
1210 | + if (!empty($modSettings['permission_enable_deny'])) { |
|
1211 | + $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
1212 | + } |
|
1160 | 1213 | |
1161 | - if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) |
|
1162 | - cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
1214 | + if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) { |
|
1215 | + cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
1216 | + } |
|
1163 | 1217 | |
1164 | 1218 | // Banned? Watch, don't touch.. |
1165 | 1219 | banPermissions(); |
@@ -1171,17 +1225,18 @@ discard block |
||
1171 | 1225 | { |
1172 | 1226 | require_once($sourcedir . '/Subs-Auth.php'); |
1173 | 1227 | rebuildModCache(); |
1228 | + } else { |
|
1229 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
1174 | 1230 | } |
1175 | - else |
|
1176 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
1177 | 1231 | |
1178 | 1232 | // This is a useful phantom permission added to the current user, and only the current user while they are logged in. |
1179 | 1233 | // For example this drastically simplifies certain changes to the profile area. |
1180 | 1234 | $user_info['permissions'][] = 'is_not_guest'; |
1181 | 1235 | // And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions. |
1182 | 1236 | $user_info['permissions'][] = 'profile_view_own'; |
1183 | - if (in_array('profile_view', $user_info['permissions'])) |
|
1184 | - $user_info['permissions'][] = 'profile_view_any'; |
|
1237 | + if (in_array('profile_view', $user_info['permissions'])) { |
|
1238 | + $user_info['permissions'][] = 'profile_view_any'; |
|
1239 | + } |
|
1185 | 1240 | } |
1186 | 1241 | } |
1187 | 1242 | |
@@ -1199,8 +1254,9 @@ discard block |
||
1199 | 1254 | global $image_proxy_enabled, $image_proxy_secret, $boardurl; |
1200 | 1255 | |
1201 | 1256 | // Can't just look for no users :P. |
1202 | - if (empty($users)) |
|
1203 | - return array(); |
|
1257 | + if (empty($users)) { |
|
1258 | + return array(); |
|
1259 | + } |
|
1204 | 1260 | |
1205 | 1261 | // Pass the set value |
1206 | 1262 | $context['loadMemberContext_set'] = $set; |
@@ -1215,8 +1271,9 @@ discard block |
||
1215 | 1271 | for ($i = 0, $n = count($users); $i < $n; $i++) |
1216 | 1272 | { |
1217 | 1273 | $data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240); |
1218 | - if ($data == null) |
|
1219 | - continue; |
|
1274 | + if ($data == null) { |
|
1275 | + continue; |
|
1276 | + } |
|
1220 | 1277 | |
1221 | 1278 | $loaded_ids[] = $data['id_member']; |
1222 | 1279 | $user_profile[$data['id_member']] = $data; |
@@ -1283,13 +1340,16 @@ discard block |
||
1283 | 1340 | $row['avatar_original'] = $row['avatar']; |
1284 | 1341 | |
1285 | 1342 | // Take care of proxying avatar if required, do this here for maximum reach |
1286 | - if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) |
|
1287 | - $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
|
1343 | + if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) { |
|
1344 | + $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
|
1345 | + } |
|
1288 | 1346 | |
1289 | - if (isset($row['member_ip'])) |
|
1290 | - $row['member_ip'] = inet_dtop($row['member_ip']); |
|
1291 | - if (isset($row['member_ip2'])) |
|
1292 | - $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
1347 | + if (isset($row['member_ip'])) { |
|
1348 | + $row['member_ip'] = inet_dtop($row['member_ip']); |
|
1349 | + } |
|
1350 | + if (isset($row['member_ip2'])) { |
|
1351 | + $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
1352 | + } |
|
1293 | 1353 | $new_loaded_ids[] = $row['id_member']; |
1294 | 1354 | $loaded_ids[] = $row['id_member']; |
1295 | 1355 | $row['options'] = array(); |
@@ -1308,8 +1368,9 @@ discard block |
||
1308 | 1368 | 'loaded_ids' => $new_loaded_ids, |
1309 | 1369 | ) |
1310 | 1370 | ); |
1311 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1312 | - $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
1371 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1372 | + $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
1373 | + } |
|
1313 | 1374 | $smcFunc['db_free_result']($request); |
1314 | 1375 | } |
1315 | 1376 | |
@@ -1320,10 +1381,11 @@ discard block |
||
1320 | 1381 | { |
1321 | 1382 | foreach ($loaded_ids as $a_member) |
1322 | 1383 | { |
1323 | - if (!empty($user_profile[$a_member]['additional_groups'])) |
|
1324 | - $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
1325 | - else |
|
1326 | - $groups = array($user_profile[$a_member]['id_group']); |
|
1384 | + if (!empty($user_profile[$a_member]['additional_groups'])) { |
|
1385 | + $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
1386 | + } else { |
|
1387 | + $groups = array($user_profile[$a_member]['id_group']); |
|
1388 | + } |
|
1327 | 1389 | |
1328 | 1390 | $temp = array_intersect($groups, array_keys($board_info['moderator_groups'])); |
1329 | 1391 | |
@@ -1336,8 +1398,9 @@ discard block |
||
1336 | 1398 | |
1337 | 1399 | if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) |
1338 | 1400 | { |
1339 | - for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) |
|
1340 | - cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
1401 | + for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) { |
|
1402 | + cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
1403 | + } |
|
1341 | 1404 | } |
1342 | 1405 | |
1343 | 1406 | // Are we loading any moderators? If so, fix their group data... |
@@ -1363,14 +1426,17 @@ discard block |
||
1363 | 1426 | foreach ($temp_mods as $id) |
1364 | 1427 | { |
1365 | 1428 | // By popular demand, don't show admins or global moderators as moderators. |
1366 | - if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) |
|
1367 | - $user_profile[$id]['member_group'] = $row['member_group']; |
|
1429 | + if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) { |
|
1430 | + $user_profile[$id]['member_group'] = $row['member_group']; |
|
1431 | + } |
|
1368 | 1432 | |
1369 | 1433 | // If the Moderator group has no color or icons, but their group does... don't overwrite. |
1370 | - if (!empty($row['icons'])) |
|
1371 | - $user_profile[$id]['icons'] = $row['icons']; |
|
1372 | - if (!empty($row['member_group_color'])) |
|
1373 | - $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
1434 | + if (!empty($row['icons'])) { |
|
1435 | + $user_profile[$id]['icons'] = $row['icons']; |
|
1436 | + } |
|
1437 | + if (!empty($row['member_group_color'])) { |
|
1438 | + $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
1439 | + } |
|
1374 | 1440 | } |
1375 | 1441 | } |
1376 | 1442 | |
@@ -1392,12 +1458,14 @@ discard block |
||
1392 | 1458 | static $loadedLanguages = array(); |
1393 | 1459 | |
1394 | 1460 | // If this person's data is already loaded, skip it. |
1395 | - if (isset($dataLoaded[$user])) |
|
1396 | - return true; |
|
1461 | + if (isset($dataLoaded[$user])) { |
|
1462 | + return true; |
|
1463 | + } |
|
1397 | 1464 | |
1398 | 1465 | // We can't load guests or members not loaded by loadMemberData()! |
1399 | - if ($user == 0) |
|
1400 | - return false; |
|
1466 | + if ($user == 0) { |
|
1467 | + return false; |
|
1468 | + } |
|
1401 | 1469 | if (!isset($user_profile[$user])) |
1402 | 1470 | { |
1403 | 1471 | trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING); |
@@ -1423,12 +1491,16 @@ discard block |
||
1423 | 1491 | $buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array(); |
1424 | 1492 | |
1425 | 1493 | //We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme |
1426 | - if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists |
|
1494 | + if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) { |
|
1495 | + //icon is set and exists |
|
1427 | 1496 | $group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1]; |
1428 | - elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default |
|
1497 | + } elseif (isset($profile['icons'][1])) { |
|
1498 | + //icon is set and doesn't exist, fallback to default |
|
1429 | 1499 | $group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1]; |
1430 | - else //not set, bye bye |
|
1500 | + } else { |
|
1501 | + //not set, bye bye |
|
1431 | 1502 | $group_icon_url = ''; |
1503 | + } |
|
1432 | 1504 | |
1433 | 1505 | // These minimal values are always loaded |
1434 | 1506 | $memberContext[$user] = array( |
@@ -1447,8 +1519,9 @@ discard block |
||
1447 | 1519 | if ($context['loadMemberContext_set'] != 'minimal') |
1448 | 1520 | { |
1449 | 1521 | // Go the extra mile and load the user's native language name. |
1450 | - if (empty($loadedLanguages)) |
|
1451 | - $loadedLanguages = getLanguages(); |
|
1522 | + if (empty($loadedLanguages)) { |
|
1523 | + $loadedLanguages = getLanguages(); |
|
1524 | + } |
|
1452 | 1525 | |
1453 | 1526 | $memberContext[$user] += array( |
1454 | 1527 | 'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>', |
@@ -1502,31 +1575,33 @@ discard block |
||
1502 | 1575 | { |
1503 | 1576 | if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://'))) |
1504 | 1577 | { |
1505 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) |
|
1506 | - $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
1507 | - else |
|
1508 | - $image = get_gravatar_url($profile['email_address']); |
|
1509 | - } |
|
1510 | - else |
|
1578 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) { |
|
1579 | + $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
1580 | + } else { |
|
1581 | + $image = get_gravatar_url($profile['email_address']); |
|
1582 | + } |
|
1583 | + } else |
|
1511 | 1584 | { |
1512 | 1585 | // So it's stored in the member table? |
1513 | 1586 | if (!empty($profile['avatar'])) |
1514 | 1587 | { |
1515 | 1588 | $image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']; |
1589 | + } elseif (!empty($profile['filename'])) { |
|
1590 | + $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
1516 | 1591 | } |
1517 | - elseif (!empty($profile['filename'])) |
|
1518 | - $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
1519 | 1592 | // Right... no avatar...use the default one |
1520 | - else |
|
1521 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
1593 | + else { |
|
1594 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
1595 | + } |
|
1522 | 1596 | } |
1523 | - if (!empty($image)) |
|
1524 | - $memberContext[$user]['avatar'] = array( |
|
1597 | + if (!empty($image)) { |
|
1598 | + $memberContext[$user]['avatar'] = array( |
|
1525 | 1599 | 'name' => $profile['avatar'], |
1526 | 1600 | 'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">', |
1527 | 1601 | 'href' => $image, |
1528 | 1602 | 'url' => $image, |
1529 | 1603 | ); |
1604 | + } |
|
1530 | 1605 | } |
1531 | 1606 | |
1532 | 1607 | // Are we also loading the members custom fields into context? |
@@ -1534,35 +1609,41 @@ discard block |
||
1534 | 1609 | { |
1535 | 1610 | $memberContext[$user]['custom_fields'] = array(); |
1536 | 1611 | |
1537 | - if (!isset($context['display_fields'])) |
|
1538 | - $context['display_fields'] = smf_json_decode($modSettings['displayFields'], true); |
|
1612 | + if (!isset($context['display_fields'])) { |
|
1613 | + $context['display_fields'] = smf_json_decode($modSettings['displayFields'], true); |
|
1614 | + } |
|
1539 | 1615 | |
1540 | 1616 | foreach ($context['display_fields'] as $custom) |
1541 | 1617 | { |
1542 | - if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) |
|
1543 | - continue; |
|
1618 | + if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) { |
|
1619 | + continue; |
|
1620 | + } |
|
1544 | 1621 | |
1545 | 1622 | $value = $profile['options'][$custom['col_name']]; |
1546 | 1623 | |
1547 | 1624 | // Don't show the "disabled" option for the "gender" field. |
1548 | - if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') |
|
1549 | - continue; |
|
1625 | + if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') { |
|
1626 | + continue; |
|
1627 | + } |
|
1550 | 1628 | |
1551 | 1629 | // BBC? |
1552 | - if ($custom['bbc']) |
|
1553 | - $value = parse_bbc($value); |
|
1630 | + if ($custom['bbc']) { |
|
1631 | + $value = parse_bbc($value); |
|
1632 | + } |
|
1554 | 1633 | // ... or checkbox? |
1555 | - elseif (isset($custom['type']) && $custom['type'] == 'check') |
|
1556 | - $value = $value ? $txt['yes'] : $txt['no']; |
|
1634 | + elseif (isset($custom['type']) && $custom['type'] == 'check') { |
|
1635 | + $value = $value ? $txt['yes'] : $txt['no']; |
|
1636 | + } |
|
1557 | 1637 | |
1558 | 1638 | // Enclosing the user input within some other text? |
1559 | - if (!empty($custom['enclose'])) |
|
1560 | - $value = strtr($custom['enclose'], array( |
|
1639 | + if (!empty($custom['enclose'])) { |
|
1640 | + $value = strtr($custom['enclose'], array( |
|
1561 | 1641 | '{SCRIPTURL}' => $scripturl, |
1562 | 1642 | '{IMAGES_URL}' => $settings['images_url'], |
1563 | 1643 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
1564 | 1644 | '{INPUT}' => $value, |
1565 | 1645 | )); |
1646 | + } |
|
1566 | 1647 | |
1567 | 1648 | $memberContext[$user]['custom_fields'][] = array( |
1568 | 1649 | 'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'], |
@@ -1589,8 +1670,9 @@ discard block |
||
1589 | 1670 | global $smcFunc, $txt, $scripturl, $settings; |
1590 | 1671 | |
1591 | 1672 | // Do not waste my time... |
1592 | - if (empty($users) || empty($params)) |
|
1593 | - return false; |
|
1673 | + if (empty($users) || empty($params)) { |
|
1674 | + return false; |
|
1675 | + } |
|
1594 | 1676 | |
1595 | 1677 | // Make sure it's an array. |
1596 | 1678 | $users = !is_array($users) ? array($users) : array_unique($users); |
@@ -1614,31 +1696,36 @@ discard block |
||
1614 | 1696 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1615 | 1697 | { |
1616 | 1698 | // BBC? |
1617 | - if (!empty($row['bbc'])) |
|
1618 | - $row['value'] = parse_bbc($row['value']); |
|
1699 | + if (!empty($row['bbc'])) { |
|
1700 | + $row['value'] = parse_bbc($row['value']); |
|
1701 | + } |
|
1619 | 1702 | |
1620 | 1703 | // ... or checkbox? |
1621 | - elseif (isset($row['type']) && $row['type'] == 'check') |
|
1622 | - $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
1704 | + elseif (isset($row['type']) && $row['type'] == 'check') { |
|
1705 | + $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
1706 | + } |
|
1623 | 1707 | |
1624 | 1708 | // Enclosing the user input within some other text? |
1625 | - if (!empty($row['enclose'])) |
|
1626 | - $row['value'] = strtr($row['enclose'], array( |
|
1709 | + if (!empty($row['enclose'])) { |
|
1710 | + $row['value'] = strtr($row['enclose'], array( |
|
1627 | 1711 | '{SCRIPTURL}' => $scripturl, |
1628 | 1712 | '{IMAGES_URL}' => $settings['images_url'], |
1629 | 1713 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
1630 | 1714 | '{INPUT}' => un_htmlspecialchars($row['value']), |
1631 | 1715 | )); |
1716 | + } |
|
1632 | 1717 | |
1633 | 1718 | // Send a simple array if there is just 1 param |
1634 | - if (count($params) == 1) |
|
1635 | - $return[$row['id_member']] = $row; |
|
1719 | + if (count($params) == 1) { |
|
1720 | + $return[$row['id_member']] = $row; |
|
1721 | + } |
|
1636 | 1722 | |
1637 | 1723 | // More than 1? knock yourself out... |
1638 | 1724 | else |
1639 | 1725 | { |
1640 | - if (!isset($return[$row['id_member']])) |
|
1641 | - $return[$row['id_member']] = array(); |
|
1726 | + if (!isset($return[$row['id_member']])) { |
|
1727 | + $return[$row['id_member']] = array(); |
|
1728 | + } |
|
1642 | 1729 | |
1643 | 1730 | $return[$row['id_member']][$row['variable']] = $row; |
1644 | 1731 | } |
@@ -1672,8 +1759,9 @@ discard block |
||
1672 | 1759 | global $context; |
1673 | 1760 | |
1674 | 1761 | // Don't know any browser! |
1675 | - if (empty($context['browser'])) |
|
1676 | - detectBrowser(); |
|
1762 | + if (empty($context['browser'])) { |
|
1763 | + detectBrowser(); |
|
1764 | + } |
|
1677 | 1765 | |
1678 | 1766 | return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false; |
1679 | 1767 | } |
@@ -1691,8 +1779,9 @@ discard block |
||
1691 | 1779 | global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled; |
1692 | 1780 | |
1693 | 1781 | // The theme was specified by parameter. |
1694 | - if (!empty($id_theme)) |
|
1695 | - $id_theme = (int) $id_theme; |
|
1782 | + if (!empty($id_theme)) { |
|
1783 | + $id_theme = (int) $id_theme; |
|
1784 | + } |
|
1696 | 1785 | // The theme was specified by REQUEST. |
1697 | 1786 | elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
1698 | 1787 | { |
@@ -1700,51 +1789,58 @@ discard block |
||
1700 | 1789 | $_SESSION['id_theme'] = $id_theme; |
1701 | 1790 | } |
1702 | 1791 | // The theme was specified by REQUEST... previously. |
1703 | - elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
|
1704 | - $id_theme = (int) $_SESSION['id_theme']; |
|
1792 | + elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) { |
|
1793 | + $id_theme = (int) $_SESSION['id_theme']; |
|
1794 | + } |
|
1705 | 1795 | // The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.) |
1706 | - elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) |
|
1707 | - $id_theme = $user_info['theme']; |
|
1796 | + elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) { |
|
1797 | + $id_theme = $user_info['theme']; |
|
1798 | + } |
|
1708 | 1799 | // The theme was specified by the board. |
1709 | - elseif (!empty($board_info['theme'])) |
|
1710 | - $id_theme = $board_info['theme']; |
|
1800 | + elseif (!empty($board_info['theme'])) { |
|
1801 | + $id_theme = $board_info['theme']; |
|
1802 | + } |
|
1711 | 1803 | // The theme is the forum's default. |
1712 | - else |
|
1713 | - $id_theme = $modSettings['theme_guests']; |
|
1804 | + else { |
|
1805 | + $id_theme = $modSettings['theme_guests']; |
|
1806 | + } |
|
1714 | 1807 | |
1715 | 1808 | // Verify the id_theme... no foul play. |
1716 | 1809 | // Always allow the board specific theme, if they are overriding. |
1717 | - if (!empty($board_info['theme']) && $board_info['override_theme']) |
|
1718 | - $id_theme = $board_info['theme']; |
|
1810 | + if (!empty($board_info['theme']) && $board_info['override_theme']) { |
|
1811 | + $id_theme = $board_info['theme']; |
|
1812 | + } |
|
1719 | 1813 | // If they have specified a particular theme to use with SSI allow it to be used. |
1720 | - elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) |
|
1721 | - $id_theme = (int) $id_theme; |
|
1722 | - elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
1814 | + elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) { |
|
1815 | + $id_theme = (int) $id_theme; |
|
1816 | + } elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
1723 | 1817 | { |
1724 | 1818 | $themes = explode(',', $modSettings['enableThemes']); |
1725 | - if (!in_array($id_theme, $themes)) |
|
1726 | - $id_theme = $modSettings['theme_guests']; |
|
1727 | - else |
|
1819 | + if (!in_array($id_theme, $themes)) { |
|
1820 | + $id_theme = $modSettings['theme_guests']; |
|
1821 | + } else { |
|
1822 | + $id_theme = (int) $id_theme; |
|
1823 | + } |
|
1824 | + } else { |
|
1728 | 1825 | $id_theme = (int) $id_theme; |
1729 | 1826 | } |
1730 | - else |
|
1731 | - $id_theme = (int) $id_theme; |
|
1732 | 1827 | |
1733 | 1828 | $member = empty($user_info['id']) ? -1 : $user_info['id']; |
1734 | 1829 | |
1735 | 1830 | // Disable image proxy if we don't have SSL enabled |
1736 | - if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) |
|
1737 | - $image_proxy_enabled = false; |
|
1831 | + if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) { |
|
1832 | + $image_proxy_enabled = false; |
|
1833 | + } |
|
1738 | 1834 | |
1739 | 1835 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated']) |
1740 | 1836 | { |
1741 | 1837 | $themeData = $temp; |
1742 | 1838 | $flag = true; |
1839 | + } elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) { |
|
1840 | + $themeData = $temp + array($member => array()); |
|
1841 | + } else { |
|
1842 | + $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
1743 | 1843 | } |
1744 | - elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) |
|
1745 | - $themeData = $temp + array($member => array()); |
|
1746 | - else |
|
1747 | - $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
1748 | 1844 | |
1749 | 1845 | if (empty($flag)) |
1750 | 1846 | { |
@@ -1763,31 +1859,37 @@ discard block |
||
1763 | 1859 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
1764 | 1860 | { |
1765 | 1861 | // There are just things we shouldn't be able to change as members. |
1766 | - if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) |
|
1767 | - continue; |
|
1862 | + if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) { |
|
1863 | + continue; |
|
1864 | + } |
|
1768 | 1865 | |
1769 | 1866 | // If this is the theme_dir of the default theme, store it. |
1770 | - if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) |
|
1771 | - $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
1867 | + if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) { |
|
1868 | + $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
1869 | + } |
|
1772 | 1870 | |
1773 | 1871 | // If this isn't set yet, is a theme option, or is not the default theme.. |
1774 | - if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') |
|
1775 | - $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
1872 | + if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') { |
|
1873 | + $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
1874 | + } |
|
1776 | 1875 | } |
1777 | 1876 | $smcFunc['db_free_result']($result); |
1778 | 1877 | |
1779 | - if (!empty($themeData[-1])) |
|
1780 | - foreach ($themeData[-1] as $k => $v) |
|
1878 | + if (!empty($themeData[-1])) { |
|
1879 | + foreach ($themeData[-1] as $k => $v) |
|
1781 | 1880 | { |
1782 | 1881 | if (!isset($themeData[$member][$k])) |
1783 | 1882 | $themeData[$member][$k] = $v; |
1883 | + } |
|
1784 | 1884 | } |
1785 | 1885 | |
1786 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
1787 | - cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
1886 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
1887 | + cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
1888 | + } |
|
1788 | 1889 | // Only if we didn't already load that part of the cache... |
1789 | - elseif (!isset($temp)) |
|
1790 | - cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
1890 | + elseif (!isset($temp)) { |
|
1891 | + cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
1892 | + } |
|
1791 | 1893 | } |
1792 | 1894 | |
1793 | 1895 | $settings = $themeData[0]; |
@@ -1804,20 +1906,24 @@ discard block |
||
1804 | 1906 | $settings['template_dirs'][] = $settings['theme_dir']; |
1805 | 1907 | |
1806 | 1908 | // Based on theme (if there is one). |
1807 | - if (!empty($settings['base_theme_dir'])) |
|
1808 | - $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
1909 | + if (!empty($settings['base_theme_dir'])) { |
|
1910 | + $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
1911 | + } |
|
1809 | 1912 | |
1810 | 1913 | // Lastly the default theme. |
1811 | - if ($settings['theme_dir'] != $settings['default_theme_dir']) |
|
1812 | - $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
1914 | + if ($settings['theme_dir'] != $settings['default_theme_dir']) { |
|
1915 | + $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
1916 | + } |
|
1813 | 1917 | |
1814 | - if (!$initialize) |
|
1815 | - return; |
|
1918 | + if (!$initialize) { |
|
1919 | + return; |
|
1920 | + } |
|
1816 | 1921 | |
1817 | 1922 | // Check to see if we're forcing SSL |
1818 | 1923 | if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) && |
1819 | - (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') |
|
1820 | - redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://'))); |
|
1924 | + (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') { |
|
1925 | + redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://'))); |
|
1926 | + } |
|
1821 | 1927 | |
1822 | 1928 | // Check to see if they're accessing it from the wrong place. |
1823 | 1929 | if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME'])) |
@@ -1825,8 +1931,9 @@ discard block |
||
1825 | 1931 | $detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://'; |
1826 | 1932 | $detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']; |
1827 | 1933 | $temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')); |
1828 | - if ($temp != '/') |
|
1829 | - $detected_url .= $temp; |
|
1934 | + if ($temp != '/') { |
|
1935 | + $detected_url .= $temp; |
|
1936 | + } |
|
1830 | 1937 | } |
1831 | 1938 | if (isset($detected_url) && $detected_url != $boardurl) |
1832 | 1939 | { |
@@ -1838,8 +1945,9 @@ discard block |
||
1838 | 1945 | foreach ($aliases as $alias) |
1839 | 1946 | { |
1840 | 1947 | // Rip off all the boring parts, spaces, etc. |
1841 | - if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) |
|
1842 | - $do_fix = true; |
|
1948 | + if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) { |
|
1949 | + $do_fix = true; |
|
1950 | + } |
|
1843 | 1951 | } |
1844 | 1952 | } |
1845 | 1953 | |
@@ -1847,20 +1955,22 @@ discard block |
||
1847 | 1955 | if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI') |
1848 | 1956 | { |
1849 | 1957 | // Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;). |
1850 | - if (empty($_GET)) |
|
1851 | - redirectexit('wwwRedirect'); |
|
1852 | - else |
|
1958 | + if (empty($_GET)) { |
|
1959 | + redirectexit('wwwRedirect'); |
|
1960 | + } else |
|
1853 | 1961 | { |
1854 | 1962 | list ($k, $v) = each($_GET); |
1855 | 1963 | |
1856 | - if ($k != 'wwwRedirect') |
|
1857 | - redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
1964 | + if ($k != 'wwwRedirect') { |
|
1965 | + redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
1966 | + } |
|
1858 | 1967 | } |
1859 | 1968 | } |
1860 | 1969 | |
1861 | 1970 | // #3 is just a check for SSL... |
1862 | - if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) |
|
1863 | - $do_fix = true; |
|
1971 | + if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) { |
|
1972 | + $do_fix = true; |
|
1973 | + } |
|
1864 | 1974 | |
1865 | 1975 | // Okay, #4 - perhaps it's an IP address? We're gonna want to use that one, then. (assuming it's the IP or something...) |
1866 | 1976 | if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1) |
@@ -1894,8 +2004,9 @@ discard block |
||
1894 | 2004 | $board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl)); |
1895 | 2005 | } |
1896 | 2006 | } |
1897 | - foreach ($context['linktree'] as $k => $dummy) |
|
1898 | - $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
2007 | + foreach ($context['linktree'] as $k => $dummy) { |
|
2008 | + $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
2009 | + } |
|
1899 | 2010 | } |
1900 | 2011 | } |
1901 | 2012 | // Set up the contextual user array. |
@@ -1914,16 +2025,16 @@ discard block |
||
1914 | 2025 | 'email' => $user_info['email'], |
1915 | 2026 | 'ignoreusers' => $user_info['ignoreusers'], |
1916 | 2027 | ); |
1917 | - if (!$context['user']['is_guest']) |
|
1918 | - $context['user']['name'] = $user_info['name']; |
|
1919 | - elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) |
|
1920 | - $context['user']['name'] = $txt['guest_title']; |
|
2028 | + if (!$context['user']['is_guest']) { |
|
2029 | + $context['user']['name'] = $user_info['name']; |
|
2030 | + } elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) { |
|
2031 | + $context['user']['name'] = $txt['guest_title']; |
|
2032 | + } |
|
1921 | 2033 | |
1922 | 2034 | // Determine the current smiley set. |
1923 | 2035 | $user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set']; |
1924 | 2036 | $context['user']['smiley_set'] = $user_info['smiley_set']; |
1925 | - } |
|
1926 | - else |
|
2037 | + } else |
|
1927 | 2038 | { |
1928 | 2039 | $context['user'] = array( |
1929 | 2040 | 'id' => -1, |
@@ -1939,18 +2050,24 @@ discard block |
||
1939 | 2050 | } |
1940 | 2051 | |
1941 | 2052 | // Some basic information... |
1942 | - if (!isset($context['html_headers'])) |
|
1943 | - $context['html_headers'] = ''; |
|
1944 | - if (!isset($context['javascript_files'])) |
|
1945 | - $context['javascript_files'] = array(); |
|
1946 | - if (!isset($context['css_files'])) |
|
1947 | - $context['css_files'] = array(); |
|
1948 | - if (!isset($context['css_header'])) |
|
1949 | - $context['css_header'] = array(); |
|
1950 | - if (!isset($context['javascript_inline'])) |
|
1951 | - $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
1952 | - if (!isset($context['javascript_vars'])) |
|
1953 | - $context['javascript_vars'] = array(); |
|
2053 | + if (!isset($context['html_headers'])) { |
|
2054 | + $context['html_headers'] = ''; |
|
2055 | + } |
|
2056 | + if (!isset($context['javascript_files'])) { |
|
2057 | + $context['javascript_files'] = array(); |
|
2058 | + } |
|
2059 | + if (!isset($context['css_files'])) { |
|
2060 | + $context['css_files'] = array(); |
|
2061 | + } |
|
2062 | + if (!isset($context['css_header'])) { |
|
2063 | + $context['css_header'] = array(); |
|
2064 | + } |
|
2065 | + if (!isset($context['javascript_inline'])) { |
|
2066 | + $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
2067 | + } |
|
2068 | + if (!isset($context['javascript_vars'])) { |
|
2069 | + $context['javascript_vars'] = array(); |
|
2070 | + } |
|
1954 | 2071 | |
1955 | 2072 | $context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2'; |
1956 | 2073 | $context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | '; |
@@ -1962,8 +2079,9 @@ discard block |
||
1962 | 2079 | $context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null; |
1963 | 2080 | $context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null; |
1964 | 2081 | $context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3; |
1965 | - if (isset($modSettings['load_average'])) |
|
1966 | - $context['load_average'] = $modSettings['load_average']; |
|
2082 | + if (isset($modSettings['load_average'])) { |
|
2083 | + $context['load_average'] = $modSettings['load_average']; |
|
2084 | + } |
|
1967 | 2085 | |
1968 | 2086 | // Detect the browser. This is separated out because it's also used in attachment downloads |
1969 | 2087 | detectBrowser(); |
@@ -1977,8 +2095,9 @@ discard block |
||
1977 | 2095 | // This allows sticking some HTML on the page output - useful for controls. |
1978 | 2096 | $context['insert_after_template'] = ''; |
1979 | 2097 | |
1980 | - if (!isset($txt)) |
|
1981 | - $txt = array(); |
|
2098 | + if (!isset($txt)) { |
|
2099 | + $txt = array(); |
|
2100 | + } |
|
1982 | 2101 | |
1983 | 2102 | $simpleActions = array( |
1984 | 2103 | 'findmember', |
@@ -2024,9 +2143,10 @@ discard block |
||
2024 | 2143 | |
2025 | 2144 | // See if theres any extra param to check. |
2026 | 2145 | $requiresXML = false; |
2027 | - foreach ($extraParams as $key => $extra) |
|
2028 | - if (isset($_REQUEST[$extra])) |
|
2146 | + foreach ($extraParams as $key => $extra) { |
|
2147 | + if (isset($_REQUEST[$extra])) |
|
2029 | 2148 | $requiresXML = true; |
2149 | + } |
|
2030 | 2150 | |
2031 | 2151 | // Output is fully XML, so no need for the index template. |
2032 | 2152 | if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML)) |
@@ -2041,37 +2161,39 @@ discard block |
||
2041 | 2161 | { |
2042 | 2162 | loadLanguage('index+Modifications'); |
2043 | 2163 | $context['template_layers'] = array(); |
2044 | - } |
|
2045 | - |
|
2046 | - else |
|
2164 | + } else |
|
2047 | 2165 | { |
2048 | 2166 | // Custom templates to load, or just default? |
2049 | - if (isset($settings['theme_templates'])) |
|
2050 | - $templates = explode(',', $settings['theme_templates']); |
|
2051 | - else |
|
2052 | - $templates = array('index'); |
|
2167 | + if (isset($settings['theme_templates'])) { |
|
2168 | + $templates = explode(',', $settings['theme_templates']); |
|
2169 | + } else { |
|
2170 | + $templates = array('index'); |
|
2171 | + } |
|
2053 | 2172 | |
2054 | 2173 | // Load each template... |
2055 | - foreach ($templates as $template) |
|
2056 | - loadTemplate($template); |
|
2174 | + foreach ($templates as $template) { |
|
2175 | + loadTemplate($template); |
|
2176 | + } |
|
2057 | 2177 | |
2058 | 2178 | // ...and attempt to load their associated language files. |
2059 | 2179 | $required_files = implode('+', array_merge($templates, array('Modifications'))); |
2060 | 2180 | loadLanguage($required_files, '', false); |
2061 | 2181 | |
2062 | 2182 | // Custom template layers? |
2063 | - if (isset($settings['theme_layers'])) |
|
2064 | - $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
2065 | - else |
|
2066 | - $context['template_layers'] = array('html', 'body'); |
|
2183 | + if (isset($settings['theme_layers'])) { |
|
2184 | + $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
2185 | + } else { |
|
2186 | + $context['template_layers'] = array('html', 'body'); |
|
2187 | + } |
|
2067 | 2188 | } |
2068 | 2189 | |
2069 | 2190 | // Initialize the theme. |
2070 | 2191 | loadSubTemplate('init', 'ignore'); |
2071 | 2192 | |
2072 | 2193 | // Allow overriding the board wide time/number formats. |
2073 | - if (empty($user_settings['time_format']) && !empty($txt['time_format'])) |
|
2074 | - $user_info['time_format'] = $txt['time_format']; |
|
2194 | + if (empty($user_settings['time_format']) && !empty($txt['time_format'])) { |
|
2195 | + $user_info['time_format'] = $txt['time_format']; |
|
2196 | + } |
|
2075 | 2197 | |
2076 | 2198 | // Set the character set from the template. |
2077 | 2199 | $context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']; |
@@ -2079,12 +2201,14 @@ discard block |
||
2079 | 2201 | $context['right_to_left'] = !empty($txt['lang_rtl']); |
2080 | 2202 | |
2081 | 2203 | // Guests may still need a name. |
2082 | - if ($context['user']['is_guest'] && empty($context['user']['name'])) |
|
2083 | - $context['user']['name'] = $txt['guest_title']; |
|
2204 | + if ($context['user']['is_guest'] && empty($context['user']['name'])) { |
|
2205 | + $context['user']['name'] = $txt['guest_title']; |
|
2206 | + } |
|
2084 | 2207 | |
2085 | 2208 | // Any theme-related strings that need to be loaded? |
2086 | - if (!empty($settings['require_theme_strings'])) |
|
2087 | - loadLanguage('ThemeStrings', '', false); |
|
2209 | + if (!empty($settings['require_theme_strings'])) { |
|
2210 | + loadLanguage('ThemeStrings', '', false); |
|
2211 | + } |
|
2088 | 2212 | |
2089 | 2213 | // Make a special URL for the language. |
2090 | 2214 | $settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']); |
@@ -2095,8 +2219,9 @@ discard block |
||
2095 | 2219 | // Here is my luvly Responsive CSS |
2096 | 2220 | loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive'); |
2097 | 2221 | |
2098 | - if ($context['right_to_left']) |
|
2099 | - loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
2222 | + if ($context['right_to_left']) { |
|
2223 | + loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
2224 | + } |
|
2100 | 2225 | |
2101 | 2226 | // We allow theme variants, because we're cool. |
2102 | 2227 | $context['theme_variant'] = ''; |
@@ -2104,14 +2229,17 @@ discard block |
||
2104 | 2229 | if (!empty($settings['theme_variants'])) |
2105 | 2230 | { |
2106 | 2231 | // Overriding - for previews and that ilk. |
2107 | - if (!empty($_REQUEST['variant'])) |
|
2108 | - $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
2232 | + if (!empty($_REQUEST['variant'])) { |
|
2233 | + $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
2234 | + } |
|
2109 | 2235 | // User selection? |
2110 | - if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) |
|
2111 | - $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
2236 | + if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) { |
|
2237 | + $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
2238 | + } |
|
2112 | 2239 | // If not a user variant, select the default. |
2113 | - if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) |
|
2114 | - $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
2240 | + if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) { |
|
2241 | + $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
2242 | + } |
|
2115 | 2243 | |
2116 | 2244 | // Do this to keep things easier in the templates. |
2117 | 2245 | $context['theme_variant'] = '_' . $context['theme_variant']; |
@@ -2120,20 +2248,23 @@ discard block |
||
2120 | 2248 | if (!empty($context['theme_variant'])) |
2121 | 2249 | { |
2122 | 2250 | loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']); |
2123 | - if ($context['right_to_left']) |
|
2124 | - loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
2251 | + if ($context['right_to_left']) { |
|
2252 | + loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
2253 | + } |
|
2125 | 2254 | } |
2126 | 2255 | } |
2127 | 2256 | |
2128 | 2257 | // Let's be compatible with old themes! |
2129 | - if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) |
|
2130 | - $context['template_layers'] = array('main'); |
|
2258 | + if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) { |
|
2259 | + $context['template_layers'] = array('main'); |
|
2260 | + } |
|
2131 | 2261 | |
2132 | 2262 | $context['tabindex'] = 1; |
2133 | 2263 | |
2134 | 2264 | // Compatibility. |
2135 | - if (!isset($settings['theme_version'])) |
|
2136 | - $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
2265 | + if (!isset($settings['theme_version'])) { |
|
2266 | + $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
2267 | + } |
|
2137 | 2268 | |
2138 | 2269 | // Default JS variables for use in every theme |
2139 | 2270 | $context['javascript_vars'] = array( |
@@ -2152,18 +2283,18 @@ discard block |
||
2152 | 2283 | ); |
2153 | 2284 | |
2154 | 2285 | // Add the JQuery library to the list of files to load. |
2155 | - if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') |
|
2156 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2157 | - |
|
2158 | - elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') |
|
2159 | - loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery'); |
|
2160 | - |
|
2161 | - elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') |
|
2162 | - loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
2286 | + if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') { |
|
2287 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2288 | + } elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') { |
|
2289 | + loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery'); |
|
2290 | + } elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') { |
|
2291 | + loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
2292 | + } |
|
2163 | 2293 | |
2164 | 2294 | // Auto loading? template_javascript() will take care of the local half of this. |
2165 | - else |
|
2166 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2295 | + else { |
|
2296 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2297 | + } |
|
2167 | 2298 | |
2168 | 2299 | // Queue our JQuery plugins! |
2169 | 2300 | loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins'); |
@@ -2186,12 +2317,12 @@ discard block |
||
2186 | 2317 | require_once($sourcedir . '/ScheduledTasks.php'); |
2187 | 2318 | |
2188 | 2319 | // What to do, what to do?! |
2189 | - if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) |
|
2190 | - AutoTask(); |
|
2191 | - else |
|
2192 | - ReduceMailQueue(); |
|
2193 | - } |
|
2194 | - else |
|
2320 | + if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) { |
|
2321 | + AutoTask(); |
|
2322 | + } else { |
|
2323 | + ReduceMailQueue(); |
|
2324 | + } |
|
2325 | + } else |
|
2195 | 2326 | { |
2196 | 2327 | $type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq'; |
2197 | 2328 | $ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time']; |
@@ -2242,8 +2373,9 @@ discard block |
||
2242 | 2373 | foreach ($theme_includes as $include) |
2243 | 2374 | { |
2244 | 2375 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
2245 | - if (file_exists($include)) |
|
2246 | - require_once($include); |
|
2376 | + if (file_exists($include)) { |
|
2377 | + require_once($include); |
|
2378 | + } |
|
2247 | 2379 | } |
2248 | 2380 | } |
2249 | 2381 | |
@@ -2273,16 +2405,19 @@ discard block |
||
2273 | 2405 | // Do any style sheets first, cause we're easy with those. |
2274 | 2406 | if (!empty($style_sheets)) |
2275 | 2407 | { |
2276 | - if (!is_array($style_sheets)) |
|
2277 | - $style_sheets = array($style_sheets); |
|
2408 | + if (!is_array($style_sheets)) { |
|
2409 | + $style_sheets = array($style_sheets); |
|
2410 | + } |
|
2278 | 2411 | |
2279 | - foreach ($style_sheets as $sheet) |
|
2280 | - loadCSSFile($sheet . '.css', array(), $sheet); |
|
2412 | + foreach ($style_sheets as $sheet) { |
|
2413 | + loadCSSFile($sheet . '.css', array(), $sheet); |
|
2414 | + } |
|
2281 | 2415 | } |
2282 | 2416 | |
2283 | 2417 | // No template to load? |
2284 | - if ($template_name === false) |
|
2285 | - return true; |
|
2418 | + if ($template_name === false) { |
|
2419 | + return true; |
|
2420 | + } |
|
2286 | 2421 | |
2287 | 2422 | $loaded = false; |
2288 | 2423 | foreach ($settings['template_dirs'] as $template_dir) |
@@ -2297,12 +2432,14 @@ discard block |
||
2297 | 2432 | |
2298 | 2433 | if ($loaded) |
2299 | 2434 | { |
2300 | - if ($db_show_debug === true) |
|
2301 | - $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
2435 | + if ($db_show_debug === true) { |
|
2436 | + $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
2437 | + } |
|
2302 | 2438 | |
2303 | 2439 | // If they have specified an initialization function for this template, go ahead and call it now. |
2304 | - if (function_exists('template_' . $template_name . '_init')) |
|
2305 | - call_user_func('template_' . $template_name . '_init'); |
|
2440 | + if (function_exists('template_' . $template_name . '_init')) { |
|
2441 | + call_user_func('template_' . $template_name . '_init'); |
|
2442 | + } |
|
2306 | 2443 | } |
2307 | 2444 | // Hmmm... doesn't exist?! I don't suppose the directory is wrong, is it? |
2308 | 2445 | elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default')) |
@@ -2322,13 +2459,14 @@ discard block |
||
2322 | 2459 | loadTemplate($template_name); |
2323 | 2460 | } |
2324 | 2461 | // Cause an error otherwise. |
2325 | - elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) |
|
2326 | - fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
2327 | - elseif ($fatal) |
|
2328 | - die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template')); |
|
2329 | - else |
|
2330 | - return false; |
|
2331 | -} |
|
2462 | + elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) { |
|
2463 | + fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
2464 | + } elseif ($fatal) { |
|
2465 | + die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template')); |
|
2466 | + } else { |
|
2467 | + return false; |
|
2468 | + } |
|
2469 | + } |
|
2332 | 2470 | |
2333 | 2471 | /** |
2334 | 2472 | * Load a sub-template. |
@@ -2346,17 +2484,19 @@ discard block |
||
2346 | 2484 | { |
2347 | 2485 | global $context, $txt, $db_show_debug; |
2348 | 2486 | |
2349 | - if ($db_show_debug === true) |
|
2350 | - $context['debug']['sub_templates'][] = $sub_template_name; |
|
2487 | + if ($db_show_debug === true) { |
|
2488 | + $context['debug']['sub_templates'][] = $sub_template_name; |
|
2489 | + } |
|
2351 | 2490 | |
2352 | 2491 | // Figure out what the template function is named. |
2353 | 2492 | $theme_function = 'template_' . $sub_template_name; |
2354 | - if (function_exists($theme_function)) |
|
2355 | - $theme_function(); |
|
2356 | - elseif ($fatal === false) |
|
2357 | - fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
2358 | - elseif ($fatal !== 'ignore') |
|
2359 | - die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template')); |
|
2493 | + if (function_exists($theme_function)) { |
|
2494 | + $theme_function(); |
|
2495 | + } elseif ($fatal === false) { |
|
2496 | + fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
2497 | + } elseif ($fatal !== 'ignore') { |
|
2498 | + die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template')); |
|
2499 | + } |
|
2360 | 2500 | |
2361 | 2501 | // Are we showing debugging for templates? Just make sure not to do it before the doctype... |
2362 | 2502 | if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml'])) |
@@ -2393,8 +2533,9 @@ discard block |
||
2393 | 2533 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
2394 | 2534 | |
2395 | 2535 | // If this is an external file, automatically set this to false. |
2396 | - if (!empty($params['external'])) |
|
2397 | - $params['minimize'] = false; |
|
2536 | + if (!empty($params['external'])) { |
|
2537 | + $params['minimize'] = false; |
|
2538 | + } |
|
2398 | 2539 | |
2399 | 2540 | // Account for shorthand like admin.css?alp21 filenames |
2400 | 2541 | $has_seed = strpos($fileName, '.css?'); |
@@ -2411,13 +2552,10 @@ discard block |
||
2411 | 2552 | { |
2412 | 2553 | $fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2413 | 2554 | $filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2555 | + } else { |
|
2556 | + $fileUrl = false; |
|
2414 | 2557 | } |
2415 | - |
|
2416 | - else |
|
2417 | - $fileUrl = false; |
|
2418 | - } |
|
2419 | - |
|
2420 | - else |
|
2558 | + } else |
|
2421 | 2559 | { |
2422 | 2560 | $fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2423 | 2561 | $filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2432,12 +2570,14 @@ discard block |
||
2432 | 2570 | } |
2433 | 2571 | |
2434 | 2572 | // Add it to the array for use in the template |
2435 | - if (!empty($fileName)) |
|
2436 | - $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2573 | + if (!empty($fileName)) { |
|
2574 | + $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2575 | + } |
|
2437 | 2576 | |
2438 | - if (!empty($context['right_to_left']) && !empty($params['rtl'])) |
|
2439 | - loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
2440 | -} |
|
2577 | + if (!empty($context['right_to_left']) && !empty($params['rtl'])) { |
|
2578 | + loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
2579 | + } |
|
2580 | + } |
|
2441 | 2581 | |
2442 | 2582 | /** |
2443 | 2583 | * Add a block of inline css code to be executed later |
@@ -2454,8 +2594,9 @@ discard block |
||
2454 | 2594 | global $context; |
2455 | 2595 | |
2456 | 2596 | // Gotta add something... |
2457 | - if (empty($css)) |
|
2458 | - return false; |
|
2597 | + if (empty($css)) { |
|
2598 | + return false; |
|
2599 | + } |
|
2459 | 2600 | |
2460 | 2601 | $context['css_header'][] = $css; |
2461 | 2602 | } |
@@ -2490,8 +2631,9 @@ discard block |
||
2490 | 2631 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
2491 | 2632 | |
2492 | 2633 | // If this is an external file, automatically set this to false. |
2493 | - if (!empty($params['external'])) |
|
2494 | - $params['minimize'] = false; |
|
2634 | + if (!empty($params['external'])) { |
|
2635 | + $params['minimize'] = false; |
|
2636 | + } |
|
2495 | 2637 | |
2496 | 2638 | // Account for shorthand like admin.js?alp21 filenames |
2497 | 2639 | $has_seed = strpos($fileName, '.js?'); |
@@ -2508,16 +2650,12 @@ discard block |
||
2508 | 2650 | { |
2509 | 2651 | $fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2510 | 2652 | $filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2511 | - } |
|
2512 | - |
|
2513 | - else |
|
2653 | + } else |
|
2514 | 2654 | { |
2515 | 2655 | $fileUrl = false; |
2516 | 2656 | $filePath = false; |
2517 | 2657 | } |
2518 | - } |
|
2519 | - |
|
2520 | - else |
|
2658 | + } else |
|
2521 | 2659 | { |
2522 | 2660 | $fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2523 | 2661 | $filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2532,9 +2670,10 @@ discard block |
||
2532 | 2670 | } |
2533 | 2671 | |
2534 | 2672 | // Add it to the array for use in the template |
2535 | - if (!empty($fileName)) |
|
2536 | - $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2537 | -} |
|
2673 | + if (!empty($fileName)) { |
|
2674 | + $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2675 | + } |
|
2676 | + } |
|
2538 | 2677 | |
2539 | 2678 | /** |
2540 | 2679 | * Add a Javascript variable for output later (for feeding text strings and similar to JS) |
@@ -2548,9 +2687,10 @@ discard block |
||
2548 | 2687 | { |
2549 | 2688 | global $context; |
2550 | 2689 | |
2551 | - if (!empty($key) && (!empty($value) || $value === '0')) |
|
2552 | - $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
2553 | -} |
|
2690 | + if (!empty($key) && (!empty($value) || $value === '0')) { |
|
2691 | + $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
2692 | + } |
|
2693 | + } |
|
2554 | 2694 | |
2555 | 2695 | /** |
2556 | 2696 | * Add a block of inline Javascript code to be executed later |
@@ -2567,8 +2707,9 @@ discard block |
||
2567 | 2707 | { |
2568 | 2708 | global $context; |
2569 | 2709 | |
2570 | - if (empty($javascript)) |
|
2571 | - return false; |
|
2710 | + if (empty($javascript)) { |
|
2711 | + return false; |
|
2712 | + } |
|
2572 | 2713 | |
2573 | 2714 | $context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript; |
2574 | 2715 | } |
@@ -2589,15 +2730,18 @@ discard block |
||
2589 | 2730 | static $already_loaded = array(); |
2590 | 2731 | |
2591 | 2732 | // Default to the user's language. |
2592 | - if ($lang == '') |
|
2593 | - $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
2733 | + if ($lang == '') { |
|
2734 | + $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
2735 | + } |
|
2594 | 2736 | |
2595 | 2737 | // Do we want the English version of language file as fallback? |
2596 | - if (empty($modSettings['disable_language_fallback']) && $lang != 'english') |
|
2597 | - loadLanguage($template_name, 'english', false); |
|
2738 | + if (empty($modSettings['disable_language_fallback']) && $lang != 'english') { |
|
2739 | + loadLanguage($template_name, 'english', false); |
|
2740 | + } |
|
2598 | 2741 | |
2599 | - if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) |
|
2600 | - return $lang; |
|
2742 | + if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) { |
|
2743 | + return $lang; |
|
2744 | + } |
|
2601 | 2745 | |
2602 | 2746 | // Make sure we have $settings - if not we're in trouble and need to find it! |
2603 | 2747 | if (empty($settings['default_theme_dir'])) |
@@ -2608,8 +2752,9 @@ discard block |
||
2608 | 2752 | |
2609 | 2753 | // What theme are we in? |
2610 | 2754 | $theme_name = basename($settings['theme_url']); |
2611 | - if (empty($theme_name)) |
|
2612 | - $theme_name = 'unknown'; |
|
2755 | + if (empty($theme_name)) { |
|
2756 | + $theme_name = 'unknown'; |
|
2757 | + } |
|
2613 | 2758 | |
2614 | 2759 | // For each file open it up and write it out! |
2615 | 2760 | foreach (explode('+', $template_name) as $template) |
@@ -2651,8 +2796,9 @@ discard block |
||
2651 | 2796 | $found = true; |
2652 | 2797 | |
2653 | 2798 | // setlocale is required for basename() & pathinfo() to work properly on the selected language |
2654 | - if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) |
|
2655 | - setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
2799 | + if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) { |
|
2800 | + setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
2801 | + } |
|
2656 | 2802 | |
2657 | 2803 | break; |
2658 | 2804 | } |
@@ -2692,8 +2838,9 @@ discard block |
||
2692 | 2838 | } |
2693 | 2839 | |
2694 | 2840 | // Keep track of what we're up to soldier. |
2695 | - if ($db_show_debug === true) |
|
2696 | - $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
2841 | + if ($db_show_debug === true) { |
|
2842 | + $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
2843 | + } |
|
2697 | 2844 | |
2698 | 2845 | // Remember what we have loaded, and in which language. |
2699 | 2846 | $already_loaded[$template_name] = $lang; |
@@ -2739,8 +2886,9 @@ discard block |
||
2739 | 2886 | ) |
2740 | 2887 | ); |
2741 | 2888 | // In the EXTREMELY unlikely event this happens, give an error message. |
2742 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
2743 | - fatal_lang_error('parent_not_found', 'critical'); |
|
2889 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
2890 | + fatal_lang_error('parent_not_found', 'critical'); |
|
2891 | + } |
|
2744 | 2892 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
2745 | 2893 | { |
2746 | 2894 | if (!isset($boards[$row['id_board']])) |
@@ -2757,8 +2905,8 @@ discard block |
||
2757 | 2905 | ); |
2758 | 2906 | } |
2759 | 2907 | // If a moderator exists for this board, add that moderator for all children too. |
2760 | - if (!empty($row['id_moderator'])) |
|
2761 | - foreach ($boards as $id => $dummy) |
|
2908 | + if (!empty($row['id_moderator'])) { |
|
2909 | + foreach ($boards as $id => $dummy) |
|
2762 | 2910 | { |
2763 | 2911 | $boards[$id]['moderators'][$row['id_moderator']] = array( |
2764 | 2912 | 'id' => $row['id_moderator'], |
@@ -2766,11 +2914,12 @@ discard block |
||
2766 | 2914 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
2767 | 2915 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
2768 | 2916 | ); |
2917 | + } |
|
2769 | 2918 | } |
2770 | 2919 | |
2771 | 2920 | // If a moderator group exists for this board, add that moderator group for all children too |
2772 | - if (!empty($row['id_moderator_group'])) |
|
2773 | - foreach ($boards as $id => $dummy) |
|
2921 | + if (!empty($row['id_moderator_group'])) { |
|
2922 | + foreach ($boards as $id => $dummy) |
|
2774 | 2923 | { |
2775 | 2924 | $boards[$id]['moderator_groups'][$row['id_moderator_group']] = array( |
2776 | 2925 | 'id' => $row['id_moderator_group'], |
@@ -2778,6 +2927,7 @@ discard block |
||
2778 | 2927 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
2779 | 2928 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
2780 | 2929 | ); |
2930 | + } |
|
2781 | 2931 | } |
2782 | 2932 | } |
2783 | 2933 | $smcFunc['db_free_result']($result); |
@@ -2804,23 +2954,27 @@ discard block |
||
2804 | 2954 | if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null) |
2805 | 2955 | { |
2806 | 2956 | // If we don't have our ucwords function defined yet, let's load the settings data. |
2807 | - if (empty($smcFunc['ucwords'])) |
|
2808 | - reloadSettings(); |
|
2957 | + if (empty($smcFunc['ucwords'])) { |
|
2958 | + reloadSettings(); |
|
2959 | + } |
|
2809 | 2960 | |
2810 | 2961 | // If we don't have our theme information yet, let's get it. |
2811 | - if (empty($settings['default_theme_dir'])) |
|
2812 | - loadTheme(0, false); |
|
2962 | + if (empty($settings['default_theme_dir'])) { |
|
2963 | + loadTheme(0, false); |
|
2964 | + } |
|
2813 | 2965 | |
2814 | 2966 | // Default language directories to try. |
2815 | 2967 | $language_directories = array( |
2816 | 2968 | $settings['default_theme_dir'] . '/languages', |
2817 | 2969 | ); |
2818 | - if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) |
|
2819 | - $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
2970 | + if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) { |
|
2971 | + $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
2972 | + } |
|
2820 | 2973 | |
2821 | 2974 | // We possibly have a base theme directory. |
2822 | - if (!empty($settings['base_theme_dir'])) |
|
2823 | - $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
2975 | + if (!empty($settings['base_theme_dir'])) { |
|
2976 | + $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
2977 | + } |
|
2824 | 2978 | |
2825 | 2979 | // Remove any duplicates. |
2826 | 2980 | $language_directories = array_unique($language_directories); |
@@ -2834,20 +2988,21 @@ discard block |
||
2834 | 2988 | foreach ($language_directories as $language_dir) |
2835 | 2989 | { |
2836 | 2990 | // Can't look in here... doesn't exist! |
2837 | - if (!file_exists($language_dir)) |
|
2838 | - continue; |
|
2991 | + if (!file_exists($language_dir)) { |
|
2992 | + continue; |
|
2993 | + } |
|
2839 | 2994 | |
2840 | 2995 | $dir = dir($language_dir); |
2841 | 2996 | while ($entry = $dir->read()) |
2842 | 2997 | { |
2843 | 2998 | // Look for the index language file... For good measure skip any "index.language-utf8.php" files |
2844 | - if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) |
|
2845 | - continue; |
|
2846 | - |
|
2847 | - if (!empty($langList) && !empty($langList[$matches[1]])) |
|
2848 | - $langName = $langList[$matches[1]]; |
|
2999 | + if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) { |
|
3000 | + continue; |
|
3001 | + } |
|
2849 | 3002 | |
2850 | - else |
|
3003 | + if (!empty($langList) && !empty($langList[$matches[1]])) { |
|
3004 | + $langName = $langList[$matches[1]]; |
|
3005 | + } else |
|
2851 | 3006 | { |
2852 | 3007 | $langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' '))); |
2853 | 3008 | |
@@ -2888,12 +3043,14 @@ discard block |
||
2888 | 3043 | } |
2889 | 3044 | |
2890 | 3045 | // Do we need to store the lang list? |
2891 | - if (empty($langList)) |
|
2892 | - updateSettings(array('langList' => json_encode($catchLang))); |
|
3046 | + if (empty($langList)) { |
|
3047 | + updateSettings(array('langList' => json_encode($catchLang))); |
|
3048 | + } |
|
2893 | 3049 | |
2894 | 3050 | // Let's cash in on this deal. |
2895 | - if (!empty($modSettings['cache_enable'])) |
|
2896 | - cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
3051 | + if (!empty($modSettings['cache_enable'])) { |
|
3052 | + cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
3053 | + } |
|
2897 | 3054 | } |
2898 | 3055 | |
2899 | 3056 | return $context['languages']; |
@@ -2916,8 +3073,9 @@ discard block |
||
2916 | 3073 | global $modSettings, $options, $txt; |
2917 | 3074 | static $censor_vulgar = null, $censor_proper; |
2918 | 3075 | |
2919 | - if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') |
|
2920 | - return $text; |
|
3076 | + if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') { |
|
3077 | + return $text; |
|
3078 | + } |
|
2921 | 3079 | |
2922 | 3080 | // If they haven't yet been loaded, load them. |
2923 | 3081 | if ($censor_vulgar == null) |
@@ -2945,9 +3103,9 @@ discard block |
||
2945 | 3103 | { |
2946 | 3104 | $func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace'; |
2947 | 3105 | $text = $func($censor_vulgar, $censor_proper, $text); |
3106 | + } else { |
|
3107 | + $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
2948 | 3108 | } |
2949 | - else |
|
2950 | - $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
2951 | 3109 | |
2952 | 3110 | return $text; |
2953 | 3111 | } |
@@ -2973,38 +3131,42 @@ discard block |
||
2973 | 3131 | @ini_set('track_errors', '1'); |
2974 | 3132 | |
2975 | 3133 | // Don't include the file more than once, if $once is true. |
2976 | - if ($once && in_array($filename, $templates)) |
|
2977 | - return; |
|
3134 | + if ($once && in_array($filename, $templates)) { |
|
3135 | + return; |
|
3136 | + } |
|
2978 | 3137 | // Add this file to the include list, whether $once is true or not. |
2979 | - else |
|
2980 | - $templates[] = $filename; |
|
3138 | + else { |
|
3139 | + $templates[] = $filename; |
|
3140 | + } |
|
2981 | 3141 | |
2982 | 3142 | // Are we going to use eval? |
2983 | 3143 | if (empty($modSettings['disableTemplateEval'])) |
2984 | 3144 | { |
2985 | 3145 | $file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false; |
2986 | 3146 | $settings['current_include_filename'] = $filename; |
2987 | - } |
|
2988 | - else |
|
3147 | + } else |
|
2989 | 3148 | { |
2990 | 3149 | $file_found = file_exists($filename); |
2991 | 3150 | |
2992 | - if ($once && $file_found) |
|
2993 | - require_once($filename); |
|
2994 | - elseif ($file_found) |
|
2995 | - require($filename); |
|
3151 | + if ($once && $file_found) { |
|
3152 | + require_once($filename); |
|
3153 | + } elseif ($file_found) { |
|
3154 | + require($filename); |
|
3155 | + } |
|
2996 | 3156 | } |
2997 | 3157 | |
2998 | 3158 | if ($file_found !== true) |
2999 | 3159 | { |
3000 | 3160 | ob_end_clean(); |
3001 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
3002 | - @ob_start('ob_gzhandler'); |
|
3003 | - else |
|
3004 | - ob_start(); |
|
3161 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
3162 | + @ob_start('ob_gzhandler'); |
|
3163 | + } else { |
|
3164 | + ob_start(); |
|
3165 | + } |
|
3005 | 3166 | |
3006 | - if (isset($_GET['debug'])) |
|
3007 | - header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3167 | + if (isset($_GET['debug'])) { |
|
3168 | + header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3169 | + } |
|
3008 | 3170 | |
3009 | 3171 | // Don't cache error pages!! |
3010 | 3172 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -3023,12 +3185,13 @@ discard block |
||
3023 | 3185 | echo '<!DOCTYPE html> |
3024 | 3186 | <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '> |
3025 | 3187 | <head>'; |
3026 | - if (isset($context['character_set'])) |
|
3027 | - echo ' |
|
3188 | + if (isset($context['character_set'])) { |
|
3189 | + echo ' |
|
3028 | 3190 | <meta charset="', $context['character_set'], '">'; |
3191 | + } |
|
3029 | 3192 | |
3030 | - if (!empty($maintenance) && !allowedTo('admin_forum')) |
|
3031 | - echo ' |
|
3193 | + if (!empty($maintenance) && !allowedTo('admin_forum')) { |
|
3194 | + echo ' |
|
3032 | 3195 | <title>', $mtitle, '</title> |
3033 | 3196 | </head> |
3034 | 3197 | <body> |
@@ -3036,8 +3199,8 @@ discard block |
||
3036 | 3199 | ', $mmessage, ' |
3037 | 3200 | </body> |
3038 | 3201 | </html>'; |
3039 | - elseif (!allowedTo('admin_forum')) |
|
3040 | - echo ' |
|
3202 | + } elseif (!allowedTo('admin_forum')) { |
|
3203 | + echo ' |
|
3041 | 3204 | <title>', $txt['template_parse_error'], '</title> |
3042 | 3205 | </head> |
3043 | 3206 | <body> |
@@ -3045,16 +3208,18 @@ discard block |
||
3045 | 3208 | ', $txt['template_parse_error_message'], ' |
3046 | 3209 | </body> |
3047 | 3210 | </html>'; |
3048 | - else |
|
3211 | + } else |
|
3049 | 3212 | { |
3050 | 3213 | require_once($sourcedir . '/Subs-Package.php'); |
3051 | 3214 | |
3052 | 3215 | $error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
3053 | 3216 | $error_array = error_get_last(); |
3054 | - if (empty($error) && ini_get('track_errors') && !empty($error_array)) |
|
3055 | - $error = $error_array['message']; |
|
3056 | - if (empty($error)) |
|
3057 | - $error = $txt['template_parse_errmsg']; |
|
3217 | + if (empty($error) && ini_get('track_errors') && !empty($error_array)) { |
|
3218 | + $error = $error_array['message']; |
|
3219 | + } |
|
3220 | + if (empty($error)) { |
|
3221 | + $error = $txt['template_parse_errmsg']; |
|
3222 | + } |
|
3058 | 3223 | |
3059 | 3224 | $error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>')); |
3060 | 3225 | |
@@ -3065,11 +3230,12 @@ discard block |
||
3065 | 3230 | <h3>', $txt['template_parse_error'], '</h3> |
3066 | 3231 | ', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
3067 | 3232 | |
3068 | - if (!empty($error)) |
|
3069 | - echo ' |
|
3233 | + if (!empty($error)) { |
|
3234 | + echo ' |
|
3070 | 3235 | <hr> |
3071 | 3236 | |
3072 | 3237 | <div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>'; |
3238 | + } |
|
3073 | 3239 | |
3074 | 3240 | // I know, I know... this is VERY COMPLICATED. Still, it's good. |
3075 | 3241 | if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0) |
@@ -3079,10 +3245,11 @@ discard block |
||
3079 | 3245 | $data2 = preg_split('~\<br( /)?\>~', $data2); |
3080 | 3246 | |
3081 | 3247 | // Fix the PHP code stuff... |
3082 | - if (!isBrowser('gecko')) |
|
3083 | - $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
3084 | - else |
|
3085 | - $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
3248 | + if (!isBrowser('gecko')) { |
|
3249 | + $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
3250 | + } else { |
|
3251 | + $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
3252 | + } |
|
3086 | 3253 | |
3087 | 3254 | // Now we get to work around a bug in PHP where it doesn't escape <br>s! |
3088 | 3255 | $j = -1; |
@@ -3090,8 +3257,9 @@ discard block |
||
3090 | 3257 | { |
3091 | 3258 | $j++; |
3092 | 3259 | |
3093 | - if (substr_count($line, '<br>') == 0) |
|
3094 | - continue; |
|
3260 | + if (substr_count($line, '<br>') == 0) { |
|
3261 | + continue; |
|
3262 | + } |
|
3095 | 3263 | |
3096 | 3264 | $n = substr_count($line, '<br>'); |
3097 | 3265 | for ($i = 0; $i < $n; $i++) |
@@ -3110,38 +3278,42 @@ discard block |
||
3110 | 3278 | // Figure out what the color coding was before... |
3111 | 3279 | $line = max($match[1] - 9, 1); |
3112 | 3280 | $last_line = ''; |
3113 | - for ($line2 = $line - 1; $line2 > 1; $line2--) |
|
3114 | - if (strpos($data2[$line2], '<') !== false) |
|
3281 | + for ($line2 = $line - 1; $line2 > 1; $line2--) { |
|
3282 | + if (strpos($data2[$line2], '<') !== false) |
|
3115 | 3283 | { |
3116 | 3284 | if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0) |
3117 | 3285 | $last_line = $color_match[1]; |
3286 | + } |
|
3118 | 3287 | break; |
3119 | 3288 | } |
3120 | 3289 | |
3121 | 3290 | // Show the relevant lines... |
3122 | 3291 | for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++) |
3123 | 3292 | { |
3124 | - if ($line == $match[1]) |
|
3125 | - echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
3293 | + if ($line == $match[1]) { |
|
3294 | + echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
3295 | + } |
|
3126 | 3296 | |
3127 | 3297 | echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> '; |
3128 | - if (isset($data2[$line]) && $data2[$line] != '') |
|
3129 | - echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
3298 | + if (isset($data2[$line]) && $data2[$line] != '') { |
|
3299 | + echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
3300 | + } |
|
3130 | 3301 | |
3131 | 3302 | if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0) |
3132 | 3303 | { |
3133 | 3304 | $last_line = $color_match[1]; |
3134 | 3305 | echo '</', substr($last_line, 1, 4), '>'; |
3306 | + } elseif ($last_line != '' && strpos($data2[$line], '<') !== false) { |
|
3307 | + $last_line = ''; |
|
3308 | + } elseif ($last_line != '' && $data2[$line] != '') { |
|
3309 | + echo '</', substr($last_line, 1, 4), '>'; |
|
3135 | 3310 | } |
3136 | - elseif ($last_line != '' && strpos($data2[$line], '<') !== false) |
|
3137 | - $last_line = ''; |
|
3138 | - elseif ($last_line != '' && $data2[$line] != '') |
|
3139 | - echo '</', substr($last_line, 1, 4), '>'; |
|
3140 | 3311 | |
3141 | - if ($line == $match[1]) |
|
3142 | - echo '</pre></div><pre style="margin: 0;">'; |
|
3143 | - else |
|
3144 | - echo "\n"; |
|
3312 | + if ($line == $match[1]) { |
|
3313 | + echo '</pre></div><pre style="margin: 0;">'; |
|
3314 | + } else { |
|
3315 | + echo "\n"; |
|
3316 | + } |
|
3145 | 3317 | } |
3146 | 3318 | |
3147 | 3319 | echo '</pre></div>'; |
@@ -3165,8 +3337,9 @@ discard block |
||
3165 | 3337 | global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port; |
3166 | 3338 | |
3167 | 3339 | // Figure out what type of database we are using. |
3168 | - if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
|
3169 | - $db_type = 'mysql'; |
|
3340 | + if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) { |
|
3341 | + $db_type = 'mysql'; |
|
3342 | + } |
|
3170 | 3343 | |
3171 | 3344 | // Load the file for the database. |
3172 | 3345 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
@@ -3174,8 +3347,9 @@ discard block |
||
3174 | 3347 | $db_options = array(); |
3175 | 3348 | |
3176 | 3349 | // Add in the port if needed |
3177 | - if (!empty($db_port)) |
|
3178 | - $db_options['port'] = $db_port; |
|
3350 | + if (!empty($db_port)) { |
|
3351 | + $db_options['port'] = $db_port; |
|
3352 | + } |
|
3179 | 3353 | |
3180 | 3354 | // If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use. |
3181 | 3355 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
@@ -3194,13 +3368,15 @@ discard block |
||
3194 | 3368 | } |
3195 | 3369 | |
3196 | 3370 | // Safe guard here, if there isn't a valid connection lets put a stop to it. |
3197 | - if (!$db_connection) |
|
3198 | - display_db_error(); |
|
3371 | + if (!$db_connection) { |
|
3372 | + display_db_error(); |
|
3373 | + } |
|
3199 | 3374 | |
3200 | 3375 | // If in SSI mode fix up the prefix. |
3201 | - if (SMF == 'SSI') |
|
3202 | - db_fix_prefix($db_prefix, $db_name); |
|
3203 | -} |
|
3376 | + if (SMF == 'SSI') { |
|
3377 | + db_fix_prefix($db_prefix, $db_name); |
|
3378 | + } |
|
3379 | + } |
|
3204 | 3380 | |
3205 | 3381 | /** |
3206 | 3382 | * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it. |
@@ -3214,10 +3390,11 @@ discard block |
||
3214 | 3390 | global $sourcedir, $cacheAPI, $cache_accelerator; |
3215 | 3391 | |
3216 | 3392 | // Not overriding this and we have a cacheAPI, send it back. |
3217 | - if (empty($overrideCache) && is_object($cacheAPI)) |
|
3218 | - return $cacheAPI; |
|
3219 | - elseif (is_null($cacheAPI)) |
|
3220 | - $cacheAPI = false; |
|
3393 | + if (empty($overrideCache) && is_object($cacheAPI)) { |
|
3394 | + return $cacheAPI; |
|
3395 | + } elseif (is_null($cacheAPI)) { |
|
3396 | + $cacheAPI = false; |
|
3397 | + } |
|
3221 | 3398 | |
3222 | 3399 | // Make sure our class is in session. |
3223 | 3400 | require_once($sourcedir . '/Class-CacheAPI.php'); |
@@ -3238,8 +3415,9 @@ discard block |
||
3238 | 3415 | if (!$testAPI->isSupported()) |
3239 | 3416 | { |
3240 | 3417 | // Can we save ourselves? |
3241 | - if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') |
|
3242 | - return loadCacheAccelerator(null, false); |
|
3418 | + if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') { |
|
3419 | + return loadCacheAccelerator(null, false); |
|
3420 | + } |
|
3243 | 3421 | return false; |
3244 | 3422 | } |
3245 | 3423 | |
@@ -3251,9 +3429,9 @@ discard block |
||
3251 | 3429 | { |
3252 | 3430 | $cacheAPI = $testAPI; |
3253 | 3431 | return $cacheAPI; |
3432 | + } else { |
|
3433 | + return $testAPI; |
|
3254 | 3434 | } |
3255 | - else |
|
3256 | - return $testAPI; |
|
3257 | 3435 | } |
3258 | 3436 | } |
3259 | 3437 | |
@@ -3273,8 +3451,9 @@ discard block |
||
3273 | 3451 | |
3274 | 3452 | // @todo Why are we doing this if caching is disabled? |
3275 | 3453 | |
3276 | - if (function_exists('call_integration_hook')) |
|
3277 | - call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
3454 | + if (function_exists('call_integration_hook')) { |
|
3455 | + call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
3456 | + } |
|
3278 | 3457 | |
3279 | 3458 | /* Refresh the cache if either: |
3280 | 3459 | 1. Caching is disabled. |
@@ -3288,16 +3467,19 @@ discard block |
||
3288 | 3467 | require_once($sourcedir . '/' . $file); |
3289 | 3468 | $cache_block = call_user_func_array($function, $params); |
3290 | 3469 | |
3291 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) |
|
3292 | - cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
3470 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) { |
|
3471 | + cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
3472 | + } |
|
3293 | 3473 | } |
3294 | 3474 | |
3295 | 3475 | // Some cached data may need a freshening up after retrieval. |
3296 | - if (!empty($cache_block['post_retri_eval'])) |
|
3297 | - eval($cache_block['post_retri_eval']); |
|
3476 | + if (!empty($cache_block['post_retri_eval'])) { |
|
3477 | + eval($cache_block['post_retri_eval']); |
|
3478 | + } |
|
3298 | 3479 | |
3299 | - if (function_exists('call_integration_hook')) |
|
3300 | - call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
3480 | + if (function_exists('call_integration_hook')) { |
|
3481 | + call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
3482 | + } |
|
3301 | 3483 | |
3302 | 3484 | return $cache_block['data']; |
3303 | 3485 | } |
@@ -3324,8 +3506,9 @@ discard block |
||
3324 | 3506 | global $cache_enable, $cacheAPI; |
3325 | 3507 | global $cache_hits, $cache_count, $db_show_debug; |
3326 | 3508 | |
3327 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
3328 | - return; |
|
3509 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
3510 | + return; |
|
3511 | + } |
|
3329 | 3512 | |
3330 | 3513 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
3331 | 3514 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3338,12 +3521,14 @@ discard block |
||
3338 | 3521 | $value = $value === null ? null : json_encode($value); |
3339 | 3522 | $cacheAPI->putData($key, $value, $ttl); |
3340 | 3523 | |
3341 | - if (function_exists('call_integration_hook')) |
|
3342 | - call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
3524 | + if (function_exists('call_integration_hook')) { |
|
3525 | + call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
3526 | + } |
|
3343 | 3527 | |
3344 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
3345 | - $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
3346 | -} |
|
3528 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
3529 | + $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
3530 | + } |
|
3531 | + } |
|
3347 | 3532 | |
3348 | 3533 | /** |
3349 | 3534 | * Gets the value from the cache specified by key, so long as it is not older than ttl seconds. |
@@ -3359,8 +3544,9 @@ discard block |
||
3359 | 3544 | global $cache_enable, $cacheAPI; |
3360 | 3545 | global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug; |
3361 | 3546 | |
3362 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
3363 | - return; |
|
3547 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
3548 | + return; |
|
3549 | + } |
|
3364 | 3550 | |
3365 | 3551 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
3366 | 3552 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3380,16 +3566,18 @@ discard block |
||
3380 | 3566 | |
3381 | 3567 | if (empty($value)) |
3382 | 3568 | { |
3383 | - if (!is_array($cache_misses)) |
|
3384 | - $cache_misses = array(); |
|
3569 | + if (!is_array($cache_misses)) { |
|
3570 | + $cache_misses = array(); |
|
3571 | + } |
|
3385 | 3572 | |
3386 | 3573 | $cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1; |
3387 | 3574 | $cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get'); |
3388 | 3575 | } |
3389 | 3576 | } |
3390 | 3577 | |
3391 | - if (function_exists('call_integration_hook') && isset($value)) |
|
3392 | - call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
3578 | + if (function_exists('call_integration_hook') && isset($value)) { |
|
3579 | + call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
3580 | + } |
|
3393 | 3581 | |
3394 | 3582 | return empty($value) ? null : smf_json_decode($value, true); |
3395 | 3583 | } |
@@ -3411,8 +3599,9 @@ discard block |
||
3411 | 3599 | global $cacheAPI; |
3412 | 3600 | |
3413 | 3601 | // If we can't get to the API, can't do this. |
3414 | - if (empty($cacheAPI)) |
|
3415 | - return; |
|
3602 | + if (empty($cacheAPI)) { |
|
3603 | + return; |
|
3604 | + } |
|
3416 | 3605 | |
3417 | 3606 | // Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure. |
3418 | 3607 | $cacheAPI->cleanCache($type); |
@@ -3437,8 +3626,9 @@ discard block |
||
3437 | 3626 | global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret; |
3438 | 3627 | |
3439 | 3628 | // Come on! |
3440 | - if (empty($data)) |
|
3441 | - return array(); |
|
3629 | + if (empty($data)) { |
|
3630 | + return array(); |
|
3631 | + } |
|
3442 | 3632 | |
3443 | 3633 | // Set a nice default var. |
3444 | 3634 | $image = ''; |
@@ -3446,11 +3636,11 @@ discard block |
||
3446 | 3636 | // Gravatar has been set as mandatory! |
3447 | 3637 | if (!empty($modSettings['gravatarOverride'])) |
3448 | 3638 | { |
3449 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) |
|
3450 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3451 | - |
|
3452 | - else if (!empty($data['email'])) |
|
3453 | - $image = get_gravatar_url($data['email']); |
|
3639 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) { |
|
3640 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3641 | + } else if (!empty($data['email'])) { |
|
3642 | + $image = get_gravatar_url($data['email']); |
|
3643 | + } |
|
3454 | 3644 | } |
3455 | 3645 | |
3456 | 3646 | // Look if the user has a gravatar field or has set an external url as avatar. |
@@ -3462,54 +3652,60 @@ discard block |
||
3462 | 3652 | // Gravatar. |
3463 | 3653 | if (stristr($data['avatar'], 'gravatar://')) |
3464 | 3654 | { |
3465 | - if ($data['avatar'] == 'gravatar://') |
|
3466 | - $image = get_gravatar_url($data['email']); |
|
3467 | - |
|
3468 | - elseif (!empty($modSettings['gravatarAllowExtraEmail'])) |
|
3469 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3655 | + if ($data['avatar'] == 'gravatar://') { |
|
3656 | + $image = get_gravatar_url($data['email']); |
|
3657 | + } elseif (!empty($modSettings['gravatarAllowExtraEmail'])) { |
|
3658 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3659 | + } |
|
3470 | 3660 | } |
3471 | 3661 | |
3472 | 3662 | // External url. |
3473 | 3663 | else |
3474 | 3664 | { |
3475 | 3665 | // Using ssl? |
3476 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) |
|
3477 | - $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
3666 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) { |
|
3667 | + $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
3668 | + } |
|
3478 | 3669 | |
3479 | 3670 | // Just a plain external url. |
3480 | - else |
|
3481 | - $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
3671 | + else { |
|
3672 | + $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
3673 | + } |
|
3482 | 3674 | } |
3483 | 3675 | } |
3484 | 3676 | |
3485 | 3677 | // Perhaps this user has an attachment as avatar... |
3486 | - else if (!empty($data['filename'])) |
|
3487 | - $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
3678 | + else if (!empty($data['filename'])) { |
|
3679 | + $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
3680 | + } |
|
3488 | 3681 | |
3489 | 3682 | // Right... no avatar... use our default image. |
3490 | - else |
|
3491 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
3683 | + else { |
|
3684 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
3685 | + } |
|
3492 | 3686 | } |
3493 | 3687 | |
3494 | 3688 | call_integration_hook('integrate_set_avatar_data', array(&$image, &$data)); |
3495 | 3689 | |
3496 | 3690 | // At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed. |
3497 | - if (!empty($image)) |
|
3498 | - return array( |
|
3691 | + if (!empty($image)) { |
|
3692 | + return array( |
|
3499 | 3693 | 'name' => !empty($data['avatar']) ? $data['avatar'] : '', |
3500 | 3694 | 'image' => '<img class="avatar" src="' . $image . '" />', |
3501 | 3695 | 'href' => $image, |
3502 | 3696 | 'url' => $image, |
3503 | 3697 | ); |
3698 | + } |
|
3504 | 3699 | |
3505 | 3700 | // Fallback to make life easier for everyone... |
3506 | - else |
|
3507 | - return array( |
|
3701 | + else { |
|
3702 | + return array( |
|
3508 | 3703 | 'name' => '', |
3509 | 3704 | 'image' => '', |
3510 | 3705 | 'href' => '', |
3511 | 3706 | 'url' => '', |
3512 | 3707 | ); |
3513 | -} |
|
3708 | + } |
|
3709 | + } |
|
3514 | 3710 | |
3515 | 3711 | ?> |
3516 | 3712 | \ No newline at end of file |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * Clean the request variables - add html entities to GET and slashes if magic_quotes_gpc is Off. |
@@ -44,22 +45,26 @@ discard block |
||
44 | 45 | unset($GLOBALS['HTTP_POST_FILES'], $GLOBALS['HTTP_POST_FILES']); |
45 | 46 | |
46 | 47 | // These keys shouldn't be set...ever. |
47 | - if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) |
|
48 | - die('Invalid request variable.'); |
|
48 | + if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) { |
|
49 | + die('Invalid request variable.'); |
|
50 | + } |
|
49 | 51 | |
50 | 52 | // Same goes for numeric keys. |
51 | - foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key) |
|
52 | - if (is_numeric($key)) |
|
53 | + foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key) { |
|
54 | + if (is_numeric($key)) |
|
53 | 55 | die('Numeric request keys are invalid.'); |
56 | + } |
|
54 | 57 | |
55 | 58 | // Numeric keys in cookies are less of a problem. Just unset those. |
56 | - foreach ($_COOKIE as $key => $value) |
|
57 | - if (is_numeric($key)) |
|
59 | + foreach ($_COOKIE as $key => $value) { |
|
60 | + if (is_numeric($key)) |
|
58 | 61 | unset($_COOKIE[$key]); |
62 | + } |
|
59 | 63 | |
60 | 64 | // Get the correct query string. It may be in an environment variable... |
61 | - if (!isset($_SERVER['QUERY_STRING'])) |
|
62 | - $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING'); |
|
65 | + if (!isset($_SERVER['QUERY_STRING'])) { |
|
66 | + $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING'); |
|
67 | + } |
|
63 | 68 | |
64 | 69 | // It seems that sticking a URL after the query string is mighty common, well, it's evil - don't. |
65 | 70 | if (strpos($_SERVER['QUERY_STRING'], 'http') === 0) |
@@ -83,13 +88,14 @@ discard block |
||
83 | 88 | parse_str(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr($_SERVER['QUERY_STRING'], array(';?' => '&', ';' => '&', '%00' => '', "\0" => ''))), $_GET); |
84 | 89 | |
85 | 90 | // Magic quotes still applies with parse_str - so clean it up. |
86 | - if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) |
|
87 | - $_GET = $removeMagicQuoteFunction($_GET); |
|
88 | - } |
|
89 | - elseif (strpos(ini_get('arg_separator.input'), ';') !== false) |
|
91 | + if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) { |
|
92 | + $_GET = $removeMagicQuoteFunction($_GET); |
|
93 | + } |
|
94 | + } elseif (strpos(ini_get('arg_separator.input'), ';') !== false) |
|
90 | 95 | { |
91 | - if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) |
|
92 | - $_GET = $removeMagicQuoteFunction($_GET); |
|
96 | + if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) { |
|
97 | + $_GET = $removeMagicQuoteFunction($_GET); |
|
98 | + } |
|
93 | 99 | |
94 | 100 | // Search engines will send action=profile%3Bu=1, which confuses PHP. |
95 | 101 | foreach ($_GET as $k => $v) |
@@ -102,8 +108,9 @@ discard block |
||
102 | 108 | for ($i = 1, $n = count($temp); $i < $n; $i++) |
103 | 109 | { |
104 | 110 | @list ($key, $val) = @explode('=', $temp[$i], 2); |
105 | - if (!isset($_GET[$key])) |
|
106 | - $_GET[$key] = $val; |
|
111 | + if (!isset($_GET[$key])) { |
|
112 | + $_GET[$key] = $val; |
|
113 | + } |
|
107 | 114 | } |
108 | 115 | } |
109 | 116 | |
@@ -120,18 +127,20 @@ discard block |
||
120 | 127 | if (!empty($_SERVER['REQUEST_URI'])) |
121 | 128 | { |
122 | 129 | // Remove the .html, assuming there is one. |
123 | - if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm') |
|
124 | - $request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.')); |
|
125 | - else |
|
126 | - $request = $_SERVER['REQUEST_URI']; |
|
130 | + if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm') { |
|
131 | + $request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.')); |
|
132 | + } else { |
|
133 | + $request = $_SERVER['REQUEST_URI']; |
|
134 | + } |
|
127 | 135 | |
128 | 136 | // @todo smflib. |
129 | 137 | // Replace 'index.php/a,b,c/d/e,f' with 'a=b,c&d=&e=f' and parse it into $_GET. |
130 | 138 | if (strpos($request, basename($scripturl) . '/') !== false) |
131 | 139 | { |
132 | 140 | parse_str(substr(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr(preg_replace('~/([^,/]+),~', '/$1=', substr($request, strpos($request, basename($scripturl)) + strlen(basename($scripturl)))), '/', '&')), 1), $temp); |
133 | - if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) |
|
134 | - $temp = $removeMagicQuoteFunction($temp); |
|
141 | + if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) { |
|
142 | + $temp = $removeMagicQuoteFunction($temp); |
|
143 | + } |
|
135 | 144 | $_GET += $temp; |
136 | 145 | } |
137 | 146 | } |
@@ -142,9 +151,10 @@ discard block |
||
142 | 151 | $_ENV = $removeMagicQuoteFunction($_ENV); |
143 | 152 | $_POST = $removeMagicQuoteFunction($_POST); |
144 | 153 | $_COOKIE = $removeMagicQuoteFunction($_COOKIE); |
145 | - foreach ($_FILES as $k => $dummy) |
|
146 | - if (isset($_FILES[$k]['name'])) |
|
154 | + foreach ($_FILES as $k => $dummy) { |
|
155 | + if (isset($_FILES[$k]['name'])) |
|
147 | 156 | $_FILES[$k]['name'] = $removeMagicQuoteFunction($_FILES[$k]['name']); |
157 | + } |
|
148 | 158 | } |
149 | 159 | |
150 | 160 | // Add entities to GET. This is kinda like the slashes on everything else. |
@@ -160,11 +170,13 @@ discard block |
||
160 | 170 | $_REQUEST['board'] = (string) $_REQUEST['board']; |
161 | 171 | |
162 | 172 | // If there's a slash in it, we've got a start value! (old, compatible links.) |
163 | - if (strpos($_REQUEST['board'], '/') !== false) |
|
164 | - list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']); |
|
173 | + if (strpos($_REQUEST['board'], '/') !== false) { |
|
174 | + list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']); |
|
175 | + } |
|
165 | 176 | // Same idea, but dots. This is the currently used format - ?board=1.0... |
166 | - elseif (strpos($_REQUEST['board'], '.') !== false) |
|
167 | - list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']); |
|
177 | + elseif (strpos($_REQUEST['board'], '.') !== false) { |
|
178 | + list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']); |
|
179 | + } |
|
168 | 180 | // Now make absolutely sure it's a number. |
169 | 181 | $board = (int) $_REQUEST['board']; |
170 | 182 | $_REQUEST['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0; |
@@ -173,12 +185,14 @@ discard block |
||
173 | 185 | $_GET['board'] = $board; |
174 | 186 | } |
175 | 187 | // Well, $board is going to be a number no matter what. |
176 | - else |
|
177 | - $board = 0; |
|
188 | + else { |
|
189 | + $board = 0; |
|
190 | + } |
|
178 | 191 | |
179 | 192 | // If there's a threadid, it's probably an old YaBB SE link. Flow with it. |
180 | - if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic'])) |
|
181 | - $_REQUEST['topic'] = $_REQUEST['threadid']; |
|
193 | + if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic'])) { |
|
194 | + $_REQUEST['topic'] = $_REQUEST['threadid']; |
|
195 | + } |
|
182 | 196 | |
183 | 197 | // We've got topic! |
184 | 198 | if (isset($_REQUEST['topic'])) |
@@ -187,29 +201,34 @@ discard block |
||
187 | 201 | $_REQUEST['topic'] = (string) $_REQUEST['topic']; |
188 | 202 | |
189 | 203 | // Slash means old, beta style, formatting. That's okay though, the link should still work. |
190 | - if (strpos($_REQUEST['topic'], '/') !== false) |
|
191 | - list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']); |
|
204 | + if (strpos($_REQUEST['topic'], '/') !== false) { |
|
205 | + list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']); |
|
206 | + } |
|
192 | 207 | // Dots are useful and fun ;). This is ?topic=1.15. |
193 | - elseif (strpos($_REQUEST['topic'], '.') !== false) |
|
194 | - list ($_REQUEST['topic'], $_REQUEST['start'], $_REQUEST['page_id']) = explode('.', $_REQUEST['topic']); |
|
208 | + elseif (strpos($_REQUEST['topic'], '.') !== false) { |
|
209 | + list ($_REQUEST['topic'], $_REQUEST['start'], $_REQUEST['page_id']) = explode('.', $_REQUEST['topic']); |
|
210 | + } |
|
195 | 211 | |
196 | 212 | $topic = (int) $_REQUEST['topic']; |
197 | 213 | |
198 | 214 | // Now make sure the online log gets the right number. |
199 | 215 | $_GET['topic'] = $topic; |
216 | + } else { |
|
217 | + $topic = 0; |
|
200 | 218 | } |
201 | - else |
|
202 | - $topic = 0; |
|
203 | 219 | |
204 | 220 | // There should be a $_REQUEST['start'], some at least. If you need to default to other than 0, use $_GET['start']. |
205 | - if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) |
|
206 | - $_REQUEST['start'] = 0; |
|
221 | + if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) { |
|
222 | + $_REQUEST['start'] = 0; |
|
223 | + } |
|
207 | 224 | |
208 | 225 | // The action needs to be a string and not an array or anything else |
209 | - if (isset($_REQUEST['action'])) |
|
210 | - $_REQUEST['action'] = (string) $_REQUEST['action']; |
|
211 | - if (isset($_GET['action'])) |
|
212 | - $_GET['action'] = (string) $_GET['action']; |
|
226 | + if (isset($_REQUEST['action'])) { |
|
227 | + $_REQUEST['action'] = (string) $_REQUEST['action']; |
|
228 | + } |
|
229 | + if (isset($_GET['action'])) { |
|
230 | + $_GET['action'] = (string) $_GET['action']; |
|
231 | + } |
|
213 | 232 | |
214 | 233 | // Some mail providers like to encode semicolons in activation URLs... |
215 | 234 | if (!empty($_REQUEST['action']) && substr($_SERVER['QUERY_STRING'], 0, 18) == 'action=activate%3b') |
@@ -235,29 +254,33 @@ discard block |
||
235 | 254 | $_SERVER['BAN_CHECK_IP'] = $_SERVER['REMOTE_ADDR']; |
236 | 255 | |
237 | 256 | // If we haven't specified how to handle Reverse Proxy IP headers, lets do what we always used to do. |
238 | - if (!isset($modSettings['proxy_ip_header'])) |
|
239 | - $modSettings['proxy_ip_header'] = 'autodetect'; |
|
257 | + if (!isset($modSettings['proxy_ip_header'])) { |
|
258 | + $modSettings['proxy_ip_header'] = 'autodetect'; |
|
259 | + } |
|
240 | 260 | |
241 | 261 | // Which headers are we going to check for Reverse Proxy IP headers? |
242 | - if ($modSettings['proxy_ip_header'] == 'disabled') |
|
243 | - $reverseIPheaders = array(); |
|
244 | - elseif ($modSettings['proxy_ip_header'] == 'autodetect') |
|
245 | - $reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP'); |
|
246 | - else |
|
247 | - $reverseIPheaders = array($modSettings['proxy_ip_header']); |
|
262 | + if ($modSettings['proxy_ip_header'] == 'disabled') { |
|
263 | + $reverseIPheaders = array(); |
|
264 | + } elseif ($modSettings['proxy_ip_header'] == 'autodetect') { |
|
265 | + $reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP'); |
|
266 | + } else { |
|
267 | + $reverseIPheaders = array($modSettings['proxy_ip_header']); |
|
268 | + } |
|
248 | 269 | |
249 | 270 | // Find the user's IP address. (but don't let it give you 'unknown'!) |
250 | 271 | foreach ($reverseIPheaders as $proxyIPheader) |
251 | 272 | { |
252 | 273 | // Ignore if this is not set. |
253 | - if (!isset($_SERVER[$proxyIPheader])) |
|
254 | - continue; |
|
274 | + if (!isset($_SERVER[$proxyIPheader])) { |
|
275 | + continue; |
|
276 | + } |
|
255 | 277 | |
256 | 278 | if (!empty($modSettings['proxy_ip_servers'])) |
257 | 279 | { |
258 | - foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) |
|
259 | - if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy)) |
|
280 | + foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) { |
|
281 | + if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy)) |
|
260 | 282 | continue; |
283 | + } |
|
261 | 284 | } |
262 | 285 | |
263 | 286 | // If there are commas, get the last one.. probably. |
@@ -277,8 +300,9 @@ discard block |
||
277 | 300 | |
278 | 301 | // Just incase we have a legacy IPv4 address. |
279 | 302 | // @ TODO: Convert to IPv6. |
280 | - if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) |
|
281 | - continue; |
|
303 | + if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) { |
|
304 | + continue; |
|
305 | + } |
|
282 | 306 | } |
283 | 307 | |
284 | 308 | continue; |
@@ -290,36 +314,40 @@ discard block |
||
290 | 314 | } |
291 | 315 | } |
292 | 316 | // Otherwise just use the only one. |
293 | - elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0) |
|
294 | - $_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader]; |
|
295 | - elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0) |
|
317 | + elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0) { |
|
318 | + $_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader]; |
|
319 | + } elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0) |
|
296 | 320 | { |
297 | 321 | $_SERVER[$proxyIPheader] = preg_replace('~^::ffff:(\d+\.\d+\.\d+\.\d+)~', '\1', $_SERVER[$proxyIPheader]); |
298 | 322 | |
299 | 323 | // Just incase we have a legacy IPv4 address. |
300 | 324 | // @ TODO: Convert to IPv6. |
301 | - if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) |
|
302 | - continue; |
|
325 | + if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) { |
|
326 | + continue; |
|
327 | + } |
|
303 | 328 | } |
304 | 329 | } |
305 | 330 | |
306 | 331 | // Make sure we know the URL of the current request. |
307 | - if (empty($_SERVER['REQUEST_URI'])) |
|
308 | - $_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''); |
|
309 | - elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) |
|
310 | - $_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI']; |
|
311 | - else |
|
312 | - $_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI']; |
|
332 | + if (empty($_SERVER['REQUEST_URI'])) { |
|
333 | + $_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''); |
|
334 | + } elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) { |
|
335 | + $_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI']; |
|
336 | + } else { |
|
337 | + $_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI']; |
|
338 | + } |
|
313 | 339 | |
314 | 340 | // And make sure HTTP_USER_AGENT is set. |
315 | 341 | $_SERVER['HTTP_USER_AGENT'] = isset($_SERVER['HTTP_USER_AGENT']) ? (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES) : htmlspecialchars($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES)) : ''; |
316 | 342 | |
317 | 343 | // Some final checking. |
318 | - if (!isValidIP($_SERVER['BAN_CHECK_IP'])) |
|
319 | - $_SERVER['BAN_CHECK_IP'] = ''; |
|
320 | - if ($_SERVER['REMOTE_ADDR'] == 'unknown') |
|
321 | - $_SERVER['REMOTE_ADDR'] = ''; |
|
322 | -} |
|
344 | + if (!isValidIP($_SERVER['BAN_CHECK_IP'])) { |
|
345 | + $_SERVER['BAN_CHECK_IP'] = ''; |
|
346 | + } |
|
347 | + if ($_SERVER['REMOTE_ADDR'] == 'unknown') { |
|
348 | + $_SERVER['REMOTE_ADDR'] = ''; |
|
349 | + } |
|
350 | + } |
|
323 | 351 | |
324 | 352 | /** |
325 | 353 | * Validates a IPv6 address. returns true if it is ipv6. |
@@ -330,8 +358,9 @@ discard block |
||
330 | 358 | function isValidIPv6($ip) |
331 | 359 | { |
332 | 360 | //looking for : |
333 | - if (strpos($ip, ':') === false) |
|
334 | - return false; |
|
361 | + if (strpos($ip, ':') === false) { |
|
362 | + return false; |
|
363 | + } |
|
335 | 364 | |
336 | 365 | //check valid address |
337 | 366 | return inet_pton($ip); |
@@ -348,15 +377,17 @@ discard block |
||
348 | 377 | static $expanded = array(); |
349 | 378 | |
350 | 379 | // Check if we have done this already. |
351 | - if (isset($expanded[$ip])) |
|
352 | - return $expanded[$ip]; |
|
380 | + if (isset($expanded[$ip])) { |
|
381 | + return $expanded[$ip]; |
|
382 | + } |
|
353 | 383 | |
354 | 384 | // Expand the IP out. |
355 | 385 | $expanded_ip = explode(':', expandIPv6($ip)); |
356 | 386 | |
357 | 387 | $new_ip = array(); |
358 | - foreach ($expanded_ip as $int) |
|
359 | - $new_ip[] = hexdec($int); |
|
388 | + foreach ($expanded_ip as $int) { |
|
389 | + $new_ip[] = hexdec($int); |
|
390 | + } |
|
360 | 391 | |
361 | 392 | // Save this incase of repeated use. |
362 | 393 | $expanded[$ip] = $new_ip; |
@@ -376,8 +407,9 @@ discard block |
||
376 | 407 | static $converted = array(); |
377 | 408 | |
378 | 409 | // Check if we have done this already. |
379 | - if (isset($converted[$addr])) |
|
380 | - return $converted[$addr]; |
|
410 | + if (isset($converted[$addr])) { |
|
411 | + return $converted[$addr]; |
|
412 | + } |
|
381 | 413 | |
382 | 414 | // Check if there are segments missing, insert if necessary. |
383 | 415 | if (strpos($addr, '::') !== false) |
@@ -387,18 +419,20 @@ discard block |
||
387 | 419 | $part[1] = explode(':', $part[1]); |
388 | 420 | $missing = array(); |
389 | 421 | |
390 | - for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) |
|
391 | - array_push($missing, '0000'); |
|
422 | + for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) { |
|
423 | + array_push($missing, '0000'); |
|
424 | + } |
|
392 | 425 | |
393 | 426 | $part = array_merge($part[0], $missing, $part[1]); |
427 | + } else { |
|
428 | + $part = explode(':', $addr); |
|
394 | 429 | } |
395 | - else |
|
396 | - $part = explode(':', $addr); |
|
397 | 430 | |
398 | 431 | // Pad each segment until it has 4 digits. |
399 | - foreach ($part as &$p) |
|
400 | - while (strlen($p) < 4) |
|
432 | + foreach ($part as &$p) { |
|
433 | + while (strlen($p) < 4) |
|
401 | 434 | $p = '0' . $p; |
435 | + } |
|
402 | 436 | |
403 | 437 | unset($p); |
404 | 438 | |
@@ -409,11 +443,12 @@ discard block |
||
409 | 443 | $converted[$addr] = $result; |
410 | 444 | |
411 | 445 | // Quick check to make sure the length is as expected. |
412 | - if (!$strict_check || strlen($result) == 39) |
|
413 | - return $result; |
|
414 | - else |
|
415 | - return false; |
|
416 | -} |
|
446 | + if (!$strict_check || strlen($result) == 39) { |
|
447 | + return $result; |
|
448 | + } else { |
|
449 | + return false; |
|
450 | + } |
|
451 | + } |
|
417 | 452 | |
418 | 453 | |
419 | 454 | /** |
@@ -444,15 +479,17 @@ discard block |
||
444 | 479 | { |
445 | 480 | global $smcFunc; |
446 | 481 | |
447 | - if (!is_array($var)) |
|
448 | - return $smcFunc['db_escape_string']($var); |
|
482 | + if (!is_array($var)) { |
|
483 | + return $smcFunc['db_escape_string']($var); |
|
484 | + } |
|
449 | 485 | |
450 | 486 | // Reindex the array with slashes. |
451 | 487 | $new_var = array(); |
452 | 488 | |
453 | 489 | // Add slashes to every element, even the indexes! |
454 | - foreach ($var as $k => $v) |
|
455 | - $new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v); |
|
490 | + foreach ($var as $k => $v) { |
|
491 | + $new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v); |
|
492 | + } |
|
456 | 493 | |
457 | 494 | return $new_var; |
458 | 495 | } |
@@ -472,12 +509,14 @@ discard block |
||
472 | 509 | { |
473 | 510 | global $smcFunc; |
474 | 511 | |
475 | - if (!is_array($var)) |
|
476 | - return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES); |
|
512 | + if (!is_array($var)) { |
|
513 | + return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES); |
|
514 | + } |
|
477 | 515 | |
478 | 516 | // Add the htmlspecialchars to every element. |
479 | - foreach ($var as $k => $v) |
|
480 | - $var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1); |
|
517 | + foreach ($var as $k => $v) { |
|
518 | + $var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1); |
|
519 | + } |
|
481 | 520 | |
482 | 521 | return $var; |
483 | 522 | } |
@@ -495,15 +534,17 @@ discard block |
||
495 | 534 | */ |
496 | 535 | function urldecode__recursive($var, $level = 0) |
497 | 536 | { |
498 | - if (!is_array($var)) |
|
499 | - return urldecode($var); |
|
537 | + if (!is_array($var)) { |
|
538 | + return urldecode($var); |
|
539 | + } |
|
500 | 540 | |
501 | 541 | // Reindex the array... |
502 | 542 | $new_var = array(); |
503 | 543 | |
504 | 544 | // Add the htmlspecialchars to every element. |
505 | - foreach ($var as $k => $v) |
|
506 | - $new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1); |
|
545 | + foreach ($var as $k => $v) { |
|
546 | + $new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1); |
|
547 | + } |
|
507 | 548 | |
508 | 549 | return $new_var; |
509 | 550 | } |
@@ -521,15 +562,17 @@ discard block |
||
521 | 562 | { |
522 | 563 | global $smcFunc; |
523 | 564 | |
524 | - if (!is_array($var)) |
|
525 | - return $smcFunc['db_unescape_string']($var); |
|
565 | + if (!is_array($var)) { |
|
566 | + return $smcFunc['db_unescape_string']($var); |
|
567 | + } |
|
526 | 568 | |
527 | 569 | // Reindex the array without slashes, this time. |
528 | 570 | $new_var = array(); |
529 | 571 | |
530 | 572 | // Strip the slashes from every element. |
531 | - foreach ($var as $k => $v) |
|
532 | - $new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v); |
|
573 | + foreach ($var as $k => $v) { |
|
574 | + $new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v); |
|
575 | + } |
|
533 | 576 | |
534 | 577 | return $new_var; |
535 | 578 | } |
@@ -547,15 +590,17 @@ discard block |
||
547 | 590 | */ |
548 | 591 | function stripslashes__recursive($var, $level = 0) |
549 | 592 | { |
550 | - if (!is_array($var)) |
|
551 | - return stripslashes($var); |
|
593 | + if (!is_array($var)) { |
|
594 | + return stripslashes($var); |
|
595 | + } |
|
552 | 596 | |
553 | 597 | // Reindex the array without slashes, this time. |
554 | 598 | $new_var = array(); |
555 | 599 | |
556 | 600 | // Strip the slashes from every element. |
557 | - foreach ($var as $k => $v) |
|
558 | - $new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1); |
|
601 | + foreach ($var as $k => $v) { |
|
602 | + $new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1); |
|
603 | + } |
|
559 | 604 | |
560 | 605 | return $new_var; |
561 | 606 | } |
@@ -576,12 +621,14 @@ discard block |
||
576 | 621 | global $smcFunc; |
577 | 622 | |
578 | 623 | // Remove spaces (32), tabs (9), returns (13, 10, and 11), nulls (0), and hard spaces. (160) |
579 | - if (!is_array($var)) |
|
580 | - return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0"); |
|
624 | + if (!is_array($var)) { |
|
625 | + return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0"); |
|
626 | + } |
|
581 | 627 | |
582 | 628 | // Go through all the elements and remove the whitespace. |
583 | - foreach ($var as $k => $v) |
|
584 | - $var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1); |
|
629 | + foreach ($var as $k => $v) { |
|
630 | + $var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1); |
|
631 | + } |
|
585 | 632 | |
586 | 633 | return $var; |
587 | 634 | } |
@@ -646,30 +693,37 @@ discard block |
||
646 | 693 | global $scripturl, $modSettings, $context; |
647 | 694 | |
648 | 695 | // If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit. |
649 | - if ($scripturl == '' || !defined('SID')) |
|
650 | - return $buffer; |
|
696 | + if ($scripturl == '' || !defined('SID')) { |
|
697 | + return $buffer; |
|
698 | + } |
|
651 | 699 | |
652 | 700 | // Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit(). This doesn't work below PHP 4.3.0, because it makes the output buffer bigger. |
653 | 701 | // @todo smflib |
654 | - if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) |
|
655 | - $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&', $buffer); |
|
702 | + if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) { |
|
703 | + $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&', $buffer); |
|
704 | + } |
|
656 | 705 | // Debugging templates, are we? |
657 | - elseif (isset($_GET['debug'])) |
|
658 | - $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer); |
|
706 | + elseif (isset($_GET['debug'])) { |
|
707 | + $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer); |
|
708 | + } |
|
659 | 709 | |
660 | 710 | // This should work even in 4.2.x, just not CGI without cgi.fix_pathinfo. |
661 | 711 | if (!empty($modSettings['queryless_urls']) && (!$context['server']['is_cgi'] || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && ($context['server']['is_apache'] || $context['server']['is_lighttpd'] || $context['server']['is_litespeed'])) |
662 | 712 | { |
663 | 713 | // Let's do something special for session ids! |
664 | - if (defined('SID') && SID != '') |
|
665 | - $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
714 | + if (defined('SID') && SID != '') { |
|
715 | + $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
666 | 716 | { |
667 | - global $scripturl; return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"'; |
|
717 | + global $scripturl; |
|
718 | + } |
|
719 | + return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"'; |
|
668 | 720 | }, $buffer); |
669 | - else |
|
670 | - $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
721 | + else { |
|
722 | + $buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m) |
|
671 | 723 | { |
672 | - global $scripturl; return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"'; |
|
724 | + global $scripturl; |
|
725 | + } |
|
726 | + return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"'; |
|
673 | 727 | }, $buffer); |
674 | 728 | } |
675 | 729 |