@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
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', |
@@ -66,15 +67,18 @@ discard block |
||
66 | 67 | 'db_native_replace' => 'smf_db_native_replace', |
67 | 68 | 'db_cte_support' => 'smf_db_cte_support', |
68 | 69 | ); |
70 | + } |
|
69 | 71 | |
70 | 72 | // We are not going to make it very far without these. |
71 | - if (!function_exists('pg_pconnect')) |
|
72 | - display_db_error(); |
|
73 | + if (!function_exists('pg_pconnect')) { |
|
74 | + display_db_error(); |
|
75 | + } |
|
73 | 76 | |
74 | - if (!empty($db_options['persist'])) |
|
75 | - $connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
76 | - else |
|
77 | - $connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
77 | + if (!empty($db_options['persist'])) { |
|
78 | + $connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
79 | + } else { |
|
80 | + $connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
81 | + } |
|
78 | 82 | |
79 | 83 | // Something's wrong, show an error if its fatal (which we assume it is) |
80 | 84 | if (!$connection) |
@@ -82,15 +86,15 @@ discard block |
||
82 | 86 | if (!empty($db_options['non_fatal'])) |
83 | 87 | { |
84 | 88 | return null; |
85 | - } |
|
86 | - else |
|
89 | + } else |
|
87 | 90 | { |
88 | 91 | display_db_error(); |
89 | 92 | } |
90 | 93 | } |
91 | 94 | |
92 | - if (!empty($db_options['db_mb4'])) |
|
93 | - $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
95 | + if (!empty($db_options['db_mb4'])) { |
|
96 | + $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
97 | + } |
|
94 | 98 | |
95 | 99 | return $connection; |
96 | 100 | } |
@@ -137,31 +141,38 @@ discard block |
||
137 | 141 | |
138 | 142 | list ($values, $connection) = $db_callback; |
139 | 143 | |
140 | - if ($matches[1] === 'db_prefix') |
|
141 | - return $db_prefix; |
|
144 | + if ($matches[1] === 'db_prefix') { |
|
145 | + return $db_prefix; |
|
146 | + } |
|
142 | 147 | |
143 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
144 | - return $user_info[$matches[1]]; |
|
148 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
149 | + return $user_info[$matches[1]]; |
|
150 | + } |
|
145 | 151 | |
146 | - if ($matches[1] === 'empty') |
|
147 | - return '\'\''; |
|
152 | + if ($matches[1] === 'empty') { |
|
153 | + return '\'\''; |
|
154 | + } |
|
148 | 155 | |
149 | - if (!isset($matches[2])) |
|
150 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
156 | + if (!isset($matches[2])) { |
|
157 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
158 | + } |
|
151 | 159 | |
152 | - if ($matches[1] === 'literal') |
|
153 | - return '\'' . pg_escape_string($matches[2]) . '\''; |
|
160 | + if ($matches[1] === 'literal') { |
|
161 | + return '\'' . pg_escape_string($matches[2]) . '\''; |
|
162 | + } |
|
154 | 163 | |
155 | - if (!isset($values[$matches[2]])) |
|
156 | - 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__); |
|
164 | + if (!isset($values[$matches[2]])) { |
|
165 | + 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__); |
|
166 | + } |
|
157 | 167 | |
158 | 168 | $replacement = $values[$matches[2]]; |
159 | 169 | |
160 | 170 | switch ($matches[1]) |
161 | 171 | { |
162 | 172 | case 'int': |
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__); |
|
173 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
174 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
175 | + } |
|
165 | 176 | return (string) (int) $replacement; |
166 | 177 | break; |
167 | 178 | |
@@ -173,65 +184,73 @@ discard block |
||
173 | 184 | case 'array_int': |
174 | 185 | if (is_array($replacement)) |
175 | 186 | { |
176 | - if (empty($replacement)) |
|
177 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
187 | + if (empty($replacement)) { |
|
188 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
189 | + } |
|
178 | 190 | |
179 | 191 | foreach ($replacement as $key => $value) |
180 | 192 | { |
181 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
182 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
193 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
194 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
195 | + } |
|
183 | 196 | |
184 | 197 | $replacement[$key] = (string) (int) $value; |
185 | 198 | } |
186 | 199 | |
187 | 200 | return implode(', ', $replacement); |
201 | + } else { |
|
202 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
188 | 203 | } |
189 | - else |
|
190 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
191 | 204 | |
192 | 205 | break; |
193 | 206 | |
194 | 207 | case 'array_string': |
195 | 208 | if (is_array($replacement)) |
196 | 209 | { |
197 | - if (empty($replacement)) |
|
198 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
210 | + if (empty($replacement)) { |
|
211 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
212 | + } |
|
199 | 213 | |
200 | - foreach ($replacement as $key => $value) |
|
201 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
214 | + foreach ($replacement as $key => $value) { |
|
215 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
216 | + } |
|
202 | 217 | |
203 | 218 | return implode(', ', $replacement); |
219 | + } else { |
|
220 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
204 | 221 | } |
205 | - else |
|
206 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
207 | 222 | break; |
208 | 223 | |
209 | 224 | case 'date': |
210 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
211 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
212 | - else |
|
213 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
225 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
226 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
227 | + } else { |
|
228 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
229 | + } |
|
214 | 230 | break; |
215 | 231 | |
216 | 232 | case 'time': |
217 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
218 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
219 | - else |
|
220 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
233 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
234 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
235 | + } else { |
|
236 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
237 | + } |
|
221 | 238 | break; |
222 | 239 | |
223 | 240 | case 'datetime': |
224 | - 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) |
|
225 | - return 'to_timestamp('. |
|
241 | + 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) { |
|
242 | + return 'to_timestamp('. |
|
226 | 243 | 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]). |
227 | 244 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
228 | - else |
|
229 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
245 | + } else { |
|
246 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
247 | + } |
|
230 | 248 | break; |
231 | 249 | |
232 | 250 | case 'float': |
233 | - if (!is_numeric($replacement)) |
|
234 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
251 | + if (!is_numeric($replacement)) { |
|
252 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
253 | + } |
|
235 | 254 | return (string) (float) $replacement; |
236 | 255 | break; |
237 | 256 | |
@@ -244,31 +263,36 @@ discard block |
||
244 | 263 | break; |
245 | 264 | |
246 | 265 | case 'inet': |
247 | - if ($replacement == 'null' || $replacement == '') |
|
248 | - return 'null'; |
|
249 | - if (inet_pton($replacement) === false) |
|
250 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
266 | + if ($replacement == 'null' || $replacement == '') { |
|
267 | + return 'null'; |
|
268 | + } |
|
269 | + if (inet_pton($replacement) === false) { |
|
270 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
271 | + } |
|
251 | 272 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
252 | 273 | |
253 | 274 | case 'array_inet': |
254 | 275 | if (is_array($replacement)) |
255 | 276 | { |
256 | - if (empty($replacement)) |
|
257 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
277 | + if (empty($replacement)) { |
|
278 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
279 | + } |
|
258 | 280 | |
259 | 281 | foreach ($replacement as $key => $value) |
260 | 282 | { |
261 | - if ($replacement == 'null' || $replacement == '') |
|
262 | - $replacement[$key] = 'null'; |
|
263 | - if (!isValidIP($value)) |
|
264 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
283 | + if ($replacement == 'null' || $replacement == '') { |
|
284 | + $replacement[$key] = 'null'; |
|
285 | + } |
|
286 | + if (!isValidIP($value)) { |
|
287 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
288 | + } |
|
265 | 289 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
266 | 290 | } |
267 | 291 | |
268 | 292 | return implode(', ', $replacement); |
293 | + } else { |
|
294 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
269 | 295 | } |
270 | - else |
|
271 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
272 | 296 | break; |
273 | 297 | |
274 | 298 | default: |
@@ -356,14 +380,16 @@ discard block |
||
356 | 380 | ), |
357 | 381 | ); |
358 | 382 | |
359 | - if (isset($replacements[$identifier])) |
|
360 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
383 | + if (isset($replacements[$identifier])) { |
|
384 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
385 | + } |
|
361 | 386 | |
362 | 387 | // Limits need to be a little different. |
363 | 388 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
364 | 389 | |
365 | - if (trim($db_string) == '') |
|
366 | - return false; |
|
390 | + if (trim($db_string) == '') { |
|
391 | + return false; |
|
392 | + } |
|
367 | 393 | |
368 | 394 | // Comments that are allowed in a query are preg_removed. |
369 | 395 | static $allowed_comments_from = array( |
@@ -383,8 +409,9 @@ discard block |
||
383 | 409 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
384 | 410 | $db_replace_result = 0; |
385 | 411 | |
386 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
387 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
412 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
413 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
414 | + } |
|
388 | 415 | |
389 | 416 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
390 | 417 | { |
@@ -409,17 +436,18 @@ discard block |
||
409 | 436 | while (true) |
410 | 437 | { |
411 | 438 | $pos = strpos($db_string_1, '\'', $pos + 1); |
412 | - if ($pos === false) |
|
413 | - break; |
|
439 | + if ($pos === false) { |
|
440 | + break; |
|
441 | + } |
|
414 | 442 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
415 | 443 | |
416 | 444 | while (true) |
417 | 445 | { |
418 | 446 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
419 | 447 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
420 | - if ($pos1 === false) |
|
421 | - break; |
|
422 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
448 | + if ($pos1 === false) { |
|
449 | + break; |
|
450 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
423 | 451 | { |
424 | 452 | $pos = $pos1; |
425 | 453 | break; |
@@ -435,16 +463,19 @@ discard block |
||
435 | 463 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
436 | 464 | |
437 | 465 | // Comments? We don't use comments in our queries, we leave 'em outside! |
438 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
439 | - $fail = true; |
|
466 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
467 | + $fail = true; |
|
468 | + } |
|
440 | 469 | // Trying to change passwords, slow us down, or something? |
441 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
442 | - $fail = true; |
|
443 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
444 | - $fail = true; |
|
470 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
471 | + $fail = true; |
|
472 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
473 | + $fail = true; |
|
474 | + } |
|
445 | 475 | |
446 | - if (!empty($fail) && function_exists('log_error')) |
|
447 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
476 | + if (!empty($fail) && function_exists('log_error')) { |
|
477 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
478 | + } |
|
448 | 479 | } |
449 | 480 | |
450 | 481 | // Set optimize stuff |
@@ -471,8 +502,9 @@ discard block |
||
471 | 502 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
472 | 503 | |
473 | 504 | // Initialize $db_cache if not already initialized. |
474 | - if (!isset($db_cache)) |
|
475 | - $db_cache = array(); |
|
505 | + if (!isset($db_cache)) { |
|
506 | + $db_cache = array(); |
|
507 | + } |
|
476 | 508 | |
477 | 509 | if (!empty($_SESSION['debug_redirect'])) |
478 | 510 | { |
@@ -490,12 +522,14 @@ discard block |
||
490 | 522 | |
491 | 523 | $db_last_result = @pg_query($connection, $db_string); |
492 | 524 | |
493 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
494 | - $db_last_result = smf_db_error($db_string, $connection); |
|
525 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
526 | + $db_last_result = smf_db_error($db_string, $connection); |
|
527 | + } |
|
495 | 528 | |
496 | 529 | // Debugging. |
497 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
498 | - $db_cache[$db_count]['t'] = microtime(true) - $st; |
|
530 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
531 | + $db_cache[$db_count]['t'] = microtime(true) - $st; |
|
532 | + } |
|
499 | 533 | |
500 | 534 | return $db_last_result; |
501 | 535 | } |
@@ -512,10 +546,11 @@ discard block |
||
512 | 546 | { |
513 | 547 | global $db_last_result, $db_replace_result; |
514 | 548 | |
515 | - if ($db_replace_result) |
|
516 | - return $db_replace_result; |
|
517 | - elseif ($result === null && !$db_last_result) |
|
518 | - return 0; |
|
549 | + if ($db_replace_result) { |
|
550 | + return $db_replace_result; |
|
551 | + } elseif ($result === null && !$db_last_result) { |
|
552 | + return 0; |
|
553 | + } |
|
519 | 554 | |
520 | 555 | return pg_affected_rows($result === null ? $db_last_result : $result); |
521 | 556 | } |
@@ -539,8 +574,9 @@ discard block |
||
539 | 574 | array( |
540 | 575 | ) |
541 | 576 | ); |
542 | - if (!$request) |
|
543 | - return false; |
|
577 | + if (!$request) { |
|
578 | + return false; |
|
579 | + } |
|
544 | 580 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
545 | 581 | $smcFunc['db_free_result']($request); |
546 | 582 | |
@@ -561,12 +597,13 @@ discard block |
||
561 | 597 | // Decide which connection to use |
562 | 598 | $connection = $connection === null ? $db_connection : $connection; |
563 | 599 | |
564 | - if ($type == 'begin') |
|
565 | - return @pg_query($connection, 'BEGIN'); |
|
566 | - elseif ($type == 'rollback') |
|
567 | - return @pg_query($connection, 'ROLLBACK'); |
|
568 | - elseif ($type == 'commit') |
|
569 | - return @pg_query($connection, 'COMMIT'); |
|
600 | + if ($type == 'begin') { |
|
601 | + return @pg_query($connection, 'BEGIN'); |
|
602 | + } elseif ($type == 'rollback') { |
|
603 | + return @pg_query($connection, 'ROLLBACK'); |
|
604 | + } elseif ($type == 'commit') { |
|
605 | + return @pg_query($connection, 'COMMIT'); |
|
606 | + } |
|
570 | 607 | |
571 | 608 | return false; |
572 | 609 | } |
@@ -594,19 +631,22 @@ discard block |
||
594 | 631 | $query_error = @pg_last_error($connection); |
595 | 632 | |
596 | 633 | // Log the error. |
597 | - if (function_exists('log_error')) |
|
598 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
634 | + if (function_exists('log_error')) { |
|
635 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
636 | + } |
|
599 | 637 | |
600 | 638 | // Nothing's defined yet... just die with it. |
601 | - if (empty($context) || empty($txt)) |
|
602 | - die($query_error); |
|
639 | + if (empty($context) || empty($txt)) { |
|
640 | + die($query_error); |
|
641 | + } |
|
603 | 642 | |
604 | 643 | // Show an error message, if possible. |
605 | 644 | $context['error_title'] = $txt['database_error']; |
606 | - if (allowedTo('admin_forum')) |
|
607 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
608 | - else |
|
609 | - $context['error_message'] = $txt['try_again']; |
|
645 | + if (allowedTo('admin_forum')) { |
|
646 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
647 | + } else { |
|
648 | + $context['error_message'] = $txt['try_again']; |
|
649 | + } |
|
610 | 650 | |
611 | 651 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
612 | 652 | { |
@@ -628,12 +668,14 @@ discard block |
||
628 | 668 | { |
629 | 669 | global $db_row_count; |
630 | 670 | |
631 | - if ($counter !== false) |
|
632 | - return pg_fetch_row($request, $counter); |
|
671 | + if ($counter !== false) { |
|
672 | + return pg_fetch_row($request, $counter); |
|
673 | + } |
|
633 | 674 | |
634 | 675 | // Reset the row counter... |
635 | - if (!isset($db_row_count[(int) $request])) |
|
636 | - $db_row_count[(int) $request] = 0; |
|
676 | + if (!isset($db_row_count[(int) $request])) { |
|
677 | + $db_row_count[(int) $request] = 0; |
|
678 | + } |
|
637 | 679 | |
638 | 680 | // Return the right row. |
639 | 681 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -650,12 +692,14 @@ discard block |
||
650 | 692 | { |
651 | 693 | global $db_row_count; |
652 | 694 | |
653 | - if ($counter !== false) |
|
654 | - return pg_fetch_assoc($request, $counter); |
|
695 | + if ($counter !== false) { |
|
696 | + return pg_fetch_assoc($request, $counter); |
|
697 | + } |
|
655 | 698 | |
656 | 699 | // Reset the row counter... |
657 | - if (!isset($db_row_count[(int) $request])) |
|
658 | - $db_row_count[(int) $request] = 0; |
|
700 | + if (!isset($db_row_count[(int) $request])) { |
|
701 | + $db_row_count[(int) $request] = 0; |
|
702 | + } |
|
659 | 703 | |
660 | 704 | // Return the right row. |
661 | 705 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -697,19 +741,22 @@ discard block |
||
697 | 741 | |
698 | 742 | $replace = ''; |
699 | 743 | |
700 | - if (empty($data)) |
|
701 | - return; |
|
744 | + if (empty($data)) { |
|
745 | + return; |
|
746 | + } |
|
702 | 747 | |
703 | - if (!is_array($data[array_rand($data)])) |
|
704 | - $data = array($data); |
|
748 | + if (!is_array($data[array_rand($data)])) { |
|
749 | + $data = array($data); |
|
750 | + } |
|
705 | 751 | |
706 | 752 | // Replace the prefix holder with the actual prefix. |
707 | 753 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
708 | 754 | |
709 | 755 | // Sanity check for replace is key part of the columns array |
710 | - if ($method == 'replace' && count(array_intersect_key($columns, array_flip($keys))) !== count($keys)) |
|
711 | - smf_db_error_backtrace('Primary Key field missing in insert call', |
|
756 | + if ($method == 'replace' && count(array_intersect_key($columns, array_flip($keys))) !== count($keys)) { |
|
757 | + smf_db_error_backtrace('Primary Key field missing in insert call', |
|
712 | 758 | 'Change the method of db insert to insert or add the pk field to the columns array', E_USER_ERROR, __FILE__, __LINE__); |
759 | + } |
|
713 | 760 | |
714 | 761 | // PostgreSQL doesn't support replace: we implement a MySQL-compatible behavior instead |
715 | 762 | if ($method == 'replace' || $method == 'ignore') |
@@ -732,32 +779,35 @@ discard block |
||
732 | 779 | $key_str .= ($count_pk > 0 ? ',' : ''); |
733 | 780 | $key_str .= $columnName; |
734 | 781 | $count_pk++; |
735 | - } |
|
736 | - else if ($method == 'replace') //normal field |
|
782 | + } else if ($method == 'replace') { |
|
783 | + //normal field |
|
737 | 784 | { |
738 | 785 | $col_str .= ($count > 0 ? ',' : ''); |
786 | + } |
|
739 | 787 | $col_str .= $columnName . ' = EXCLUDED.' . $columnName; |
740 | 788 | $count++; |
741 | 789 | } |
742 | 790 | } |
743 | - if ($method == 'replace') |
|
744 | - $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
745 | - else |
|
746 | - $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
747 | - } |
|
748 | - else if ($method == 'replace') |
|
791 | + if ($method == 'replace') { |
|
792 | + $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
793 | + } else { |
|
794 | + $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
795 | + } |
|
796 | + } else if ($method == 'replace') |
|
749 | 797 | { |
750 | 798 | foreach ($columns as $columnName => $type) |
751 | 799 | { |
752 | 800 | // Are we restricting the length? |
753 | - if (strpos($type, 'string-') !== false) |
|
754 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
755 | - else |
|
756 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
801 | + if (strpos($type, 'string-') !== false) { |
|
802 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
803 | + } else { |
|
804 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
805 | + } |
|
757 | 806 | |
758 | 807 | // A key? That's what we were looking for. |
759 | - if (in_array($columnName, $keys)) |
|
760 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
808 | + if (in_array($columnName, $keys)) { |
|
809 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
810 | + } |
|
761 | 811 | $count++; |
762 | 812 | } |
763 | 813 | |
@@ -793,10 +843,11 @@ discard block |
||
793 | 843 | foreach ($columns as $columnName => $type) |
794 | 844 | { |
795 | 845 | // Are we restricting the length? |
796 | - if (strpos($type, 'string-') !== false) |
|
797 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
798 | - else |
|
799 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
846 | + if (strpos($type, 'string-') !== false) { |
|
847 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
848 | + } else { |
|
849 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
850 | + } |
|
800 | 851 | } |
801 | 852 | $insertData = substr($insertData, 0, -2) . ')'; |
802 | 853 | |
@@ -805,8 +856,9 @@ discard block |
||
805 | 856 | |
806 | 857 | // Here's where the variables are injected to the query. |
807 | 858 | $insertRows = array(); |
808 | - foreach ($data as $dataRow) |
|
809 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
859 | + foreach ($data as $dataRow) { |
|
860 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
861 | + } |
|
810 | 862 | |
811 | 863 | // Do the insert. |
812 | 864 | $request = $smcFunc['db_query']('', ' |
@@ -823,19 +875,21 @@ discard block |
||
823 | 875 | |
824 | 876 | if ($with_returning && $request !== false) |
825 | 877 | { |
826 | - if ($returnmode === 2) |
|
827 | - $return_var = array(); |
|
878 | + if ($returnmode === 2) { |
|
879 | + $return_var = array(); |
|
880 | + } |
|
828 | 881 | |
829 | 882 | while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
830 | 883 | { |
831 | - if (is_numeric($row[0])) // try to emulate mysql limitation |
|
884 | + if (is_numeric($row[0])) { |
|
885 | + // try to emulate mysql limitation |
|
832 | 886 | { |
833 | 887 | if ($returnmode === 1) |
834 | 888 | $return_var = $row[0]; |
835 | - elseif ($returnmode === 2) |
|
836 | - $return_var[] = $row[0]; |
|
837 | - } |
|
838 | - else |
|
889 | + } elseif ($returnmode === 2) { |
|
890 | + $return_var[] = $row[0]; |
|
891 | + } |
|
892 | + } else |
|
839 | 893 | { |
840 | 894 | $with_returning = false; |
841 | 895 | trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR); |
@@ -844,9 +898,10 @@ discard block |
||
844 | 898 | } |
845 | 899 | } |
846 | 900 | |
847 | - if ($with_returning && !empty($return_var)) |
|
848 | - return $return_var; |
|
849 | -} |
|
901 | + if ($with_returning && !empty($return_var)) { |
|
902 | + return $return_var; |
|
903 | + } |
|
904 | + } |
|
850 | 905 | |
851 | 906 | /** |
852 | 907 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -883,8 +938,9 @@ discard block |
||
883 | 938 | */ |
884 | 939 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
885 | 940 | { |
886 | - if (empty($log_message)) |
|
887 | - $log_message = $error_message; |
|
941 | + if (empty($log_message)) { |
|
942 | + $log_message = $error_message; |
|
943 | + } |
|
888 | 944 | |
889 | 945 | foreach (debug_backtrace() as $step) |
890 | 946 | { |
@@ -903,12 +959,14 @@ discard block |
||
903 | 959 | } |
904 | 960 | |
905 | 961 | // A special case - we want the file and line numbers for debugging. |
906 | - if ($error_type == 'return') |
|
907 | - return array($file, $line); |
|
962 | + if ($error_type == 'return') { |
|
963 | + return array($file, $line); |
|
964 | + } |
|
908 | 965 | |
909 | 966 | // Is always a critical error. |
910 | - if (function_exists('log_error')) |
|
911 | - log_error($log_message, 'critical', $file, $line); |
|
967 | + if (function_exists('log_error')) { |
|
968 | + log_error($log_message, 'critical', $file, $line); |
|
969 | + } |
|
912 | 970 | |
913 | 971 | if (function_exists('fatal_error')) |
914 | 972 | { |
@@ -916,12 +974,12 @@ discard block |
||
916 | 974 | |
917 | 975 | // Cannot continue... |
918 | 976 | exit; |
977 | + } elseif ($error_type) { |
|
978 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
979 | + } else { |
|
980 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
981 | + } |
|
919 | 982 | } |
920 | - elseif ($error_type) |
|
921 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
922 | - else |
|
923 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
924 | -} |
|
925 | 983 | |
926 | 984 | /** |
927 | 985 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -938,10 +996,11 @@ discard block |
||
938 | 996 | '\\' => '\\\\', |
939 | 997 | ); |
940 | 998 | |
941 | - if ($translate_human_wildcards) |
|
942 | - $replacements += array( |
|
999 | + if ($translate_human_wildcards) { |
|
1000 | + $replacements += array( |
|
943 | 1001 | '*' => '%', |
944 | 1002 | ); |
1003 | + } |
|
945 | 1004 | |
946 | 1005 | return strtr($string, $replacements); |
947 | 1006 | } |
@@ -970,14 +1029,16 @@ discard block |
||
970 | 1029 | static $pg_error_data_prep; |
971 | 1030 | |
972 | 1031 | // without database we can't do anything |
973 | - if (empty($db_connection)) |
|
974 | - return; |
|
1032 | + if (empty($db_connection)) { |
|
1033 | + return; |
|
1034 | + } |
|
975 | 1035 | |
976 | - if (empty($pg_error_data_prep)) |
|
977 | - $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
1036 | + if (empty($pg_error_data_prep)) { |
|
1037 | + $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
978 | 1038 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line, backtrace) |
979 | 1039 | VALUES( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10)' |
980 | 1040 | ); |
1041 | + } |
|
981 | 1042 | |
982 | 1043 | pg_execute($db_connection, 'smf_log_errors', $error_array); |
983 | 1044 | } |
@@ -997,8 +1058,9 @@ discard block |
||
997 | 1058 | $count = count($array_values); |
998 | 1059 | $then = ($desc ? ' THEN -' : ' THEN '); |
999 | 1060 | |
1000 | - for ($i = 0; $i < $count; $i++) |
|
1001 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1061 | + for ($i = 0; $i < $count; $i++) { |
|
1062 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1063 | + } |
|
1002 | 1064 | |
1003 | 1065 | $return .= 'END'; |
1004 | 1066 | return $return; |
@@ -1021,11 +1083,13 @@ discard block |
||
1021 | 1083 | //pg 9.5 got replace support |
1022 | 1084 | $pg_version = $smcFunc['db_get_version'](); |
1023 | 1085 | // if we got a Beta Version |
1024 | - if (stripos($pg_version, 'beta') !== false) |
|
1025 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
1086 | + if (stripos($pg_version, 'beta') !== false) { |
|
1087 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
1088 | + } |
|
1026 | 1089 | // or RC |
1027 | - if (stripos($pg_version, 'rc') !== false) |
|
1028 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
1090 | + if (stripos($pg_version, 'rc') !== false) { |
|
1091 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
1092 | + } |
|
1029 | 1093 | |
1030 | 1094 | $replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false); |
1031 | 1095 | } |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
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 | * Outputs xml data representing recent information or a profile. |
@@ -37,8 +38,9 @@ discard block |
||
37 | 38 | global $query_this_board, $smcFunc, $forum_version, $settings; |
38 | 39 | |
39 | 40 | // If it's not enabled, die. |
40 | - if (empty($modSettings['xmlnews_enable'])) |
|
41 | - obExit(false); |
|
41 | + if (empty($modSettings['xmlnews_enable'])) { |
|
42 | + obExit(false); |
|
43 | + } |
|
42 | 44 | |
43 | 45 | loadLanguage('Stats'); |
44 | 46 | |
@@ -64,8 +66,9 @@ discard block |
||
64 | 66 | if (!empty($_REQUEST['c']) && empty($board)) |
65 | 67 | { |
66 | 68 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
67 | - foreach ($_REQUEST['c'] as $i => $c) |
|
68 | - $_REQUEST['c'][$i] = (int) $c; |
|
69 | + foreach ($_REQUEST['c'] as $i => $c) { |
|
70 | + $_REQUEST['c'][$i] = (int) $c; |
|
71 | + } |
|
69 | 72 | |
70 | 73 | if (count($_REQUEST['c']) == 1) |
71 | 74 | { |
@@ -101,18 +104,20 @@ discard block |
||
101 | 104 | } |
102 | 105 | $smcFunc['db_free_result']($request); |
103 | 106 | |
104 | - if (!empty($boards)) |
|
105 | - $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
107 | + if (!empty($boards)) { |
|
108 | + $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
109 | + } |
|
106 | 110 | |
107 | 111 | // Try to limit the number of messages we look through. |
108 | - if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) |
|
109 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5); |
|
110 | - } |
|
111 | - elseif (!empty($_REQUEST['boards'])) |
|
112 | + if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) { |
|
113 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5); |
|
114 | + } |
|
115 | + } elseif (!empty($_REQUEST['boards'])) |
|
112 | 116 | { |
113 | 117 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
114 | - foreach ($_REQUEST['boards'] as $i => $b) |
|
115 | - $_REQUEST['boards'][$i] = (int) $b; |
|
118 | + foreach ($_REQUEST['boards'] as $i => $b) { |
|
119 | + $_REQUEST['boards'][$i] = (int) $b; |
|
120 | + } |
|
116 | 121 | |
117 | 122 | $request = $smcFunc['db_query']('', ' |
118 | 123 | SELECT b.id_board, b.num_posts, b.name |
@@ -128,29 +133,32 @@ discard block |
||
128 | 133 | |
129 | 134 | // Either the board specified doesn't exist or you have no access. |
130 | 135 | $num_boards = $smcFunc['db_num_rows']($request); |
131 | - if ($num_boards == 0) |
|
132 | - fatal_lang_error('no_board'); |
|
136 | + if ($num_boards == 0) { |
|
137 | + fatal_lang_error('no_board'); |
|
138 | + } |
|
133 | 139 | |
134 | 140 | $total_posts = 0; |
135 | 141 | $boards = array(); |
136 | 142 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
137 | 143 | { |
138 | - if ($num_boards == 1) |
|
139 | - $feed_meta['title'] = ' - ' . strip_tags($row['name']); |
|
144 | + if ($num_boards == 1) { |
|
145 | + $feed_meta['title'] = ' - ' . strip_tags($row['name']); |
|
146 | + } |
|
140 | 147 | |
141 | 148 | $boards[] = $row['id_board']; |
142 | 149 | $total_posts += $row['num_posts']; |
143 | 150 | } |
144 | 151 | $smcFunc['db_free_result']($request); |
145 | 152 | |
146 | - if (!empty($boards)) |
|
147 | - $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
153 | + if (!empty($boards)) { |
|
154 | + $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
155 | + } |
|
148 | 156 | |
149 | 157 | // The more boards, the more we're going to look through... |
150 | - if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) |
|
151 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5); |
|
152 | - } |
|
153 | - elseif (!empty($board)) |
|
158 | + if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) { |
|
159 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5); |
|
160 | + } |
|
161 | + } elseif (!empty($board)) |
|
154 | 162 | { |
155 | 163 | $request = $smcFunc['db_query']('', ' |
156 | 164 | SELECT num_posts |
@@ -170,10 +178,10 @@ discard block |
||
170 | 178 | $query_this_board = 'b.id_board = ' . $board; |
171 | 179 | |
172 | 180 | // Try to look through just a few messages, if at all possible. |
173 | - if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) |
|
174 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5); |
|
175 | - } |
|
176 | - else |
|
181 | + if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) { |
|
182 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5); |
|
183 | + } |
|
184 | + } else |
|
177 | 185 | { |
178 | 186 | $query_this_board = '{query_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' |
179 | 187 | AND b.id_board != ' . $modSettings['recycle_board'] : ''); |
@@ -196,30 +204,35 @@ discard block |
||
196 | 204 | // Easy adding of sub actions |
197 | 205 | call_integration_hook('integrate_xmlfeeds', array(&$subActions)); |
198 | 206 | |
199 | - if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) |
|
200 | - $_GET['sa'] = 'recent'; |
|
207 | + if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) { |
|
208 | + $_GET['sa'] = 'recent'; |
|
209 | + } |
|
201 | 210 | |
202 | 211 | // We only want some information, not all of it. |
203 | 212 | $cachekey = array($xml_format, $_GET['action'], $_GET['limit'], $_GET['sa']); |
204 | - foreach (array('board', 'boards', 'c') as $var) |
|
205 | - if (isset($_REQUEST[$var])) |
|
213 | + foreach (array('board', 'boards', 'c') as $var) { |
|
214 | + if (isset($_REQUEST[$var])) |
|
206 | 215 | $cachekey[] = $_REQUEST[$var]; |
216 | + } |
|
207 | 217 | $cachekey = md5($smcFunc['json_encode']($cachekey) . (!empty($query_this_board) ? $query_this_board : '')); |
208 | 218 | $cache_t = microtime(true); |
209 | 219 | |
210 | 220 | // Get the associative array representing the xml. |
211 | - if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) |
|
212 | - $xml_data = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240); |
|
221 | + if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) { |
|
222 | + $xml_data = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240); |
|
223 | + } |
|
213 | 224 | if (empty($xml_data)) |
214 | 225 | { |
215 | 226 | $call = call_helper($subActions[$_GET['sa']][0], true); |
216 | 227 | |
217 | - if (!empty($call)) |
|
218 | - $xml_data = call_user_func($call, $xml_format); |
|
228 | + if (!empty($call)) { |
|
229 | + $xml_data = call_user_func($call, $xml_format); |
|
230 | + } |
|
219 | 231 | |
220 | 232 | if (!empty($modSettings['cache_enable']) && (($user_info['is_guest'] && $modSettings['cache_enable'] >= 3) |
221 | - || (!$user_info['is_guest'] && (microtime(true) - $cache_t > 0.2)))) |
|
222 | - cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml_data, 240); |
|
233 | + || (!$user_info['is_guest'] && (microtime(true) - $cache_t > 0.2)))) { |
|
234 | + cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml_data, 240); |
|
235 | + } |
|
223 | 236 | } |
224 | 237 | |
225 | 238 | $feed_meta['title'] = $smcFunc['htmlspecialchars'](strip_tags($context['forum_name'])) . (isset($feed_meta['title']) ? $feed_meta['title'] : ''); |
@@ -259,43 +272,49 @@ discard block |
||
259 | 272 | call_integration_hook('integrate_xml_data', array(&$xml_data, &$feed_meta, &$namespaces, &$extraFeedTags, &$forceCdataKeys, &$nsKeys, $xml_format, $_GET['sa'])); |
260 | 273 | |
261 | 274 | // These can't be empty |
262 | - foreach (array('title', 'desc', 'source') as $mkey) |
|
263 | - $feed_meta[$mkey] = !empty($feed_meta[$mkey]) ? $feed_meta[$mkey] : $orig_feed_meta[$mkey]; |
|
275 | + foreach (array('title', 'desc', 'source') as $mkey) { |
|
276 | + $feed_meta[$mkey] = !empty($feed_meta[$mkey]) ? $feed_meta[$mkey] : $orig_feed_meta[$mkey]; |
|
277 | + } |
|
264 | 278 | |
265 | 279 | // Sanitize basic feed metadata values |
266 | - foreach ($feed_meta as $mkey => $mvalue) |
|
267 | - $feed_meta[$mkey] = cdata_parse(strip_tags(fix_possible_url($feed_meta[$mkey]))); |
|
280 | + foreach ($feed_meta as $mkey => $mvalue) { |
|
281 | + $feed_meta[$mkey] = cdata_parse(strip_tags(fix_possible_url($feed_meta[$mkey]))); |
|
282 | + } |
|
268 | 283 | |
269 | 284 | $ns_string = ''; |
270 | 285 | if (!empty($namespaces[$xml_format])) |
271 | 286 | { |
272 | - foreach ($namespaces[$xml_format] as $nsprefix => $nsurl) |
|
273 | - $ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"'; |
|
287 | + foreach ($namespaces[$xml_format] as $nsprefix => $nsurl) { |
|
288 | + $ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"'; |
|
289 | + } |
|
274 | 290 | } |
275 | 291 | |
276 | 292 | $extraFeedTags_string = ''; |
277 | 293 | if (!empty($extraFeedTags[$xml_format])) |
278 | 294 | { |
279 | 295 | $indent = "\t" . ($xml_format !== 'atom' ? "\t" : ''); |
280 | - foreach ($extraFeedTags[$xml_format] as $extraTag) |
|
281 | - $extraFeedTags_string .= "\n" . $indent . $extraTag; |
|
296 | + foreach ($extraFeedTags[$xml_format] as $extraTag) { |
|
297 | + $extraFeedTags_string .= "\n" . $indent . $extraTag; |
|
298 | + } |
|
282 | 299 | } |
283 | 300 | |
284 | 301 | // This is an xml file.... |
285 | 302 | ob_end_clean(); |
286 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
287 | - @ob_start('ob_gzhandler'); |
|
288 | - else |
|
289 | - ob_start(); |
|
303 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
304 | + @ob_start('ob_gzhandler'); |
|
305 | + } else { |
|
306 | + ob_start(); |
|
307 | + } |
|
290 | 308 | |
291 | - if ($xml_format == 'smf' || isset($_REQUEST['debug'])) |
|
292 | - header('content-type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
293 | - elseif ($xml_format == 'rss' || $xml_format == 'rss2') |
|
294 | - header('content-type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
295 | - elseif ($xml_format == 'atom') |
|
296 | - header('content-type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
297 | - elseif ($xml_format == 'rdf') |
|
298 | - header('content-type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
309 | + if ($xml_format == 'smf' || isset($_REQUEST['debug'])) { |
|
310 | + header('content-type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
311 | + } elseif ($xml_format == 'rss' || $xml_format == 'rss2') { |
|
312 | + header('content-type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
313 | + } elseif ($xml_format == 'atom') { |
|
314 | + header('content-type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
315 | + } elseif ($xml_format == 'rdf') { |
|
316 | + header('content-type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
317 | + } |
|
299 | 318 | |
300 | 319 | // First, output the xml header. |
301 | 320 | echo '<?xml version="1.0" encoding="', $context['character_set'], '"?' . '>'; |
@@ -303,10 +322,11 @@ discard block |
||
303 | 322 | // Are we outputting an rss feed or one with more information? |
304 | 323 | if ($xml_format == 'rss' || $xml_format == 'rss2') |
305 | 324 | { |
306 | - if ($xml_format == 'rss2') |
|
307 | - foreach ($_REQUEST as $var => $val) |
|
325 | + if ($xml_format == 'rss2') { |
|
326 | + foreach ($_REQUEST as $var => $val) |
|
308 | 327 | if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
309 | 328 | $url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val); |
329 | + } |
|
310 | 330 | |
311 | 331 | // Start with an RSS 2.0 header. |
312 | 332 | echo ' |
@@ -327,9 +347,10 @@ discard block |
||
327 | 347 | <language>' . $feed_meta['language'] . '</language>' : ''; |
328 | 348 | |
329 | 349 | // RSS2 calls for this. |
330 | - if ($xml_format == 'rss2') |
|
331 | - echo ' |
|
350 | + if ($xml_format == 'rss2') { |
|
351 | + echo ' |
|
332 | 352 | <atom:link rel="self" type="application/rss+xml" href="', $scripturl, !empty($url_parts) ? '?' . implode(';', $url_parts) : '', '" />'; |
353 | + } |
|
333 | 354 | |
334 | 355 | echo $extraFeedTags_string; |
335 | 356 | |
@@ -340,12 +361,12 @@ discard block |
||
340 | 361 | echo ' |
341 | 362 | </channel> |
342 | 363 | </rss>'; |
343 | - } |
|
344 | - elseif ($xml_format == 'atom') |
|
364 | + } elseif ($xml_format == 'atom') |
|
345 | 365 | { |
346 | - foreach ($_REQUEST as $var => $val) |
|
347 | - if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
|
366 | + foreach ($_REQUEST as $var => $val) { |
|
367 | + if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
|
348 | 368 | $url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val); |
369 | + } |
|
349 | 370 | |
350 | 371 | echo ' |
351 | 372 | <feed', $ns_string, !empty($feed_meta['language']) ? ' xml:lang="' . $feed_meta['language'] . '"' : '', '> |
@@ -371,8 +392,7 @@ discard block |
||
371 | 392 | |
372 | 393 | echo ' |
373 | 394 | </feed>'; |
374 | - } |
|
375 | - elseif ($xml_format == 'rdf') |
|
395 | + } elseif ($xml_format == 'rdf') |
|
376 | 396 | { |
377 | 397 | echo ' |
378 | 398 | <rdf:RDF', $ns_string, '> |
@@ -437,13 +457,15 @@ discard block |
||
437 | 457 | { |
438 | 458 | global $modSettings, $context, $scripturl; |
439 | 459 | |
440 | - if (substr($val, 0, strlen($scripturl)) != $scripturl) |
|
441 | - return $val; |
|
460 | + if (substr($val, 0, strlen($scripturl)) != $scripturl) { |
|
461 | + return $val; |
|
462 | + } |
|
442 | 463 | |
443 | 464 | call_integration_hook('integrate_fix_url', array(&$val)); |
444 | 465 | |
445 | - if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) |
|
446 | - return $val; |
|
466 | + if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) { |
|
467 | + return $val; |
|
468 | + } |
|
447 | 469 | |
448 | 470 | $val = preg_replace_callback('~\b' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?$~', function($m) use ($scripturl) |
449 | 471 | { |
@@ -466,8 +488,9 @@ discard block |
||
466 | 488 | global $smcFunc; |
467 | 489 | |
468 | 490 | // Do we even need to do this? |
469 | - if (strpbrk($data, '<>&') == false && $force !== true) |
|
470 | - return $data; |
|
491 | + if (strpbrk($data, '<>&') == false && $force !== true) { |
|
492 | + return $data; |
|
493 | + } |
|
471 | 494 | |
472 | 495 | $cdata = '<, |
478 | 501 | $smcFunc['strpos']($data, ']', $pos), |
479 | 502 | ); |
480 | - if ($ns != '') |
|
481 | - $positions[] = $smcFunc['strpos']($data, '<', $pos); |
|
503 | + if ($ns != '') { |
|
504 | + $positions[] = $smcFunc['strpos']($data, '<', $pos); |
|
505 | + } |
|
482 | 506 | foreach ($positions as $k => $dummy) |
483 | 507 | { |
484 | - if ($dummy === false) |
|
485 | - unset($positions[$k]); |
|
508 | + if ($dummy === false) { |
|
509 | + unset($positions[$k]); |
|
510 | + } |
|
486 | 511 | } |
487 | 512 | |
488 | 513 | $old = $pos; |
489 | 514 | $pos = empty($positions) ? $n : min($positions); |
490 | 515 | |
491 | - if ($pos - $old > 0) |
|
492 | - $cdata .= $smcFunc['substr']($data, $old, $pos - $old); |
|
493 | - if ($pos >= $n) |
|
494 | - break; |
|
516 | + if ($pos - $old > 0) { |
|
517 | + $cdata .= $smcFunc['substr']($data, $old, $pos - $old); |
|
518 | + } |
|
519 | + if ($pos >= $n) { |
|
520 | + break; |
|
521 | + } |
|
495 | 522 | |
496 | 523 | if ($smcFunc['substr']($data, $pos, 1) == '<') |
497 | 524 | { |
498 | 525 | $pos2 = $smcFunc['strpos']($data, '>', $pos); |
499 | - if ($pos2 === false) |
|
500 | - $pos2 = $n; |
|
501 | - if ($smcFunc['substr']($data, $pos + 1, 1) == '/') |
|
502 | - $cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA['; |
|
503 | - else |
|
504 | - $cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '< == '/') { |
|
530 | + $cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA['; |
|
531 | + } else { |
|
532 | + $cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '< == ']') |
|
535 | + } elseif ($smcFunc['substr']($data, $pos, 1) == ']') |
|
508 | 536 | { |
509 | 537 | $cdata .= ']]>]< == '&') |
|
539 | + } elseif ($smcFunc['substr']($data, $pos, 1) == '&') |
|
513 | 540 | { |
514 | 541 | $pos2 = $smcFunc['strpos']($data, ';', $pos); |
515 | - if ($pos2 === false) |
|
516 | - $pos2 = $n; |
|
542 | + if ($pos2 === false) { |
|
543 | + $pos2 = $n; |
|
544 | + } |
|
517 | 545 | $ent = $smcFunc['substr']($data, $pos + 1, $pos2 - $pos - 1); |
518 | 546 | |
519 | - if ($smcFunc['substr']($data, $pos + 1, 1) == '#') |
|
520 | - $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
521 | - elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) |
|
522 | - $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '< == '#') { |
|
548 | + $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
549 | + } elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) { |
|
550 | + $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
551 | + } |
|
523 | 552 | |
524 | 553 | $pos = $pos2 + 1; |
525 | 554 | } |
@@ -559,8 +588,9 @@ discard block |
||
559 | 588 | 'gender', |
560 | 589 | 'blurb', |
561 | 590 | ); |
562 | - if ($xml_format != 'atom') |
|
563 | - $keysToCdata[] = 'category'; |
|
591 | + if ($xml_format != 'atom') { |
|
592 | + $keysToCdata[] = 'category'; |
|
593 | + } |
|
564 | 594 | |
565 | 595 | if (!empty($forceCdataKeys)) |
566 | 596 | { |
@@ -577,8 +607,9 @@ discard block |
||
577 | 607 | $attrs = isset($element['attributes']) ? $element['attributes'] : null; |
578 | 608 | |
579 | 609 | // Skip it, it's been set to null. |
580 | - if ($key === null || ($val === null && $attrs === null)) |
|
581 | - continue; |
|
610 | + if ($key === null || ($val === null && $attrs === null)) { |
|
611 | + continue; |
|
612 | + } |
|
582 | 613 | |
583 | 614 | $forceCdata = in_array($key, $forceCdataKeys); |
584 | 615 | $ns = !empty($nsKeys[$key]) ? $nsKeys[$key] : ''; |
@@ -591,16 +622,16 @@ discard block |
||
591 | 622 | |
592 | 623 | if (!empty($attrs)) |
593 | 624 | { |
594 | - foreach ($attrs as $attr_key => $attr_value) |
|
595 | - echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"'; |
|
625 | + foreach ($attrs as $attr_key => $attr_value) { |
|
626 | + echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"'; |
|
627 | + } |
|
596 | 628 | } |
597 | 629 | |
598 | 630 | // If it's empty, simply output an empty element. |
599 | 631 | if (empty($val)) |
600 | 632 | { |
601 | 633 | echo ' />'; |
602 | - } |
|
603 | - else |
|
634 | + } else |
|
604 | 635 | { |
605 | 636 | echo '>'; |
606 | 637 | |
@@ -612,11 +643,13 @@ discard block |
||
612 | 643 | echo "\n", str_repeat("\t", $i); |
613 | 644 | } |
614 | 645 | // A string with returns in it.... show this as a multiline element. |
615 | - elseif (strpos($val, "\n") !== false) |
|
616 | - echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i); |
|
646 | + elseif (strpos($val, "\n") !== false) { |
|
647 | + echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i); |
|
648 | + } |
|
617 | 649 | // A simple string. |
618 | - else |
|
619 | - echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val); |
|
650 | + else { |
|
651 | + echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val); |
|
652 | + } |
|
620 | 653 | |
621 | 654 | // Ending tag. |
622 | 655 | echo '</', $key, '>'; |
@@ -636,8 +669,9 @@ discard block |
||
636 | 669 | { |
637 | 670 | global $scripturl, $smcFunc; |
638 | 671 | |
639 | - if (!allowedTo('view_mlist')) |
|
640 | - return array(); |
|
672 | + if (!allowedTo('view_mlist')) { |
|
673 | + return array(); |
|
674 | + } |
|
641 | 675 | |
642 | 676 | // Find the most recent members. |
643 | 677 | $request = $smcFunc['db_query']('', ' |
@@ -656,8 +690,8 @@ discard block |
||
656 | 690 | $guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['date_registered']) . ':member=' . $row['id_member']; |
657 | 691 | |
658 | 692 | // Make the data look rss-ish. |
659 | - if ($xml_format == 'rss' || $xml_format == 'rss2') |
|
660 | - $data[] = array( |
|
693 | + if ($xml_format == 'rss' || $xml_format == 'rss2') { |
|
694 | + $data[] = array( |
|
661 | 695 | 'tag' => 'item', |
662 | 696 | 'content' => array( |
663 | 697 | array( |
@@ -685,8 +719,8 @@ discard block |
||
685 | 719 | ), |
686 | 720 | ), |
687 | 721 | ); |
688 | - elseif ($xml_format == 'rdf') |
|
689 | - $data[] = array( |
|
722 | + } elseif ($xml_format == 'rdf') { |
|
723 | + $data[] = array( |
|
690 | 724 | 'tag' => 'item', |
691 | 725 | 'attributes' => array('rdf:about' => $scripturl . '?action=profile;u=' . $row['id_member']), |
692 | 726 | 'content' => array( |
@@ -704,8 +738,8 @@ discard block |
||
704 | 738 | ), |
705 | 739 | ), |
706 | 740 | ); |
707 | - elseif ($xml_format == 'atom') |
|
708 | - $data[] = array( |
|
741 | + } elseif ($xml_format == 'atom') { |
|
742 | + $data[] = array( |
|
709 | 743 | 'tag' => 'entry', |
710 | 744 | 'content' => array( |
711 | 745 | array( |
@@ -734,9 +768,10 @@ discard block |
||
734 | 768 | ), |
735 | 769 | ), |
736 | 770 | ); |
771 | + } |
|
737 | 772 | // More logical format for the data, but harder to apply. |
738 | - else |
|
739 | - $data[] = array( |
|
773 | + else { |
|
774 | + $data[] = array( |
|
740 | 775 | 'tag' => 'member', |
741 | 776 | 'content' => array( |
742 | 777 | array( |
@@ -757,6 +792,7 @@ discard block |
||
757 | 792 | ), |
758 | 793 | ), |
759 | 794 | ); |
795 | + } |
|
760 | 796 | } |
761 | 797 | $smcFunc['db_free_result']($request); |
762 | 798 | |
@@ -817,22 +853,24 @@ discard block |
||
817 | 853 | if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit']) |
818 | 854 | { |
819 | 855 | $smcFunc['db_free_result']($request); |
820 | - if (empty($_REQUEST['boards']) && empty($board)) |
|
821 | - unset($context['optimize_msg']['lowest']); |
|
822 | - else |
|
823 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg'; |
|
856 | + if (empty($_REQUEST['boards']) && empty($board)) { |
|
857 | + unset($context['optimize_msg']['lowest']); |
|
858 | + } else { |
|
859 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg'; |
|
860 | + } |
|
824 | 861 | $context['optimize_msg']['highest'] = 'm.id_msg <= t.id_last_msg'; |
825 | 862 | $loops++; |
863 | + } else { |
|
864 | + $done = true; |
|
826 | 865 | } |
827 | - else |
|
828 | - $done = true; |
|
829 | 866 | } |
830 | 867 | $data = array(); |
831 | 868 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
832 | 869 | { |
833 | 870 | // Limit the length of the message, if the option is set. |
834 | - if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) |
|
835 | - $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
871 | + if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) { |
|
872 | + $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
873 | + } |
|
836 | 874 | |
837 | 875 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
838 | 876 | |
@@ -859,8 +897,9 @@ discard block |
||
859 | 897 | while ($attach = $smcFunc['db_fetch_assoc']($attach_request)) |
860 | 898 | { |
861 | 899 | // Include approved attachments only |
862 | - if ($attach['approved']) |
|
863 | - $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
900 | + if ($attach['approved']) { |
|
901 | + $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
902 | + } |
|
864 | 903 | } |
865 | 904 | $smcFunc['db_free_result']($attach_request); |
866 | 905 | |
@@ -868,16 +907,17 @@ discard block |
||
868 | 907 | if (!empty($loaded_attachments)) |
869 | 908 | { |
870 | 909 | uasort($loaded_attachments, function($a, $b) { |
871 | - if ($a['filesize'] == $b['filesize']) |
|
872 | - return 0; |
|
910 | + if ($a['filesize'] == $b['filesize']) { |
|
911 | + return 0; |
|
912 | + } |
|
873 | 913 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
874 | 914 | }); |
915 | + } else { |
|
916 | + $loaded_attachments = null; |
|
875 | 917 | } |
876 | - else |
|
877 | - $loaded_attachments = null; |
|
918 | + } else { |
|
919 | + $loaded_attachments = null; |
|
878 | 920 | } |
879 | - else |
|
880 | - $loaded_attachments = null; |
|
881 | 921 | |
882 | 922 | // Create a GUID for this topic using the tag URI scheme |
883 | 923 | $guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['poster_time']) . ':topic=' . $row['id_topic']; |
@@ -894,9 +934,9 @@ discard block |
||
894 | 934 | 'length' => $attachment['filesize'], |
895 | 935 | 'type' => $attachment['mime_type'], |
896 | 936 | ); |
937 | + } else { |
|
938 | + $enclosure = null; |
|
897 | 939 | } |
898 | - else |
|
899 | - $enclosure = null; |
|
900 | 940 | |
901 | 941 | $data[] = array( |
902 | 942 | 'tag' => 'item', |
@@ -942,8 +982,7 @@ discard block |
||
942 | 982 | ), |
943 | 983 | ), |
944 | 984 | ); |
945 | - } |
|
946 | - elseif ($xml_format == 'rdf') |
|
985 | + } elseif ($xml_format == 'rdf') |
|
947 | 986 | { |
948 | 987 | $data[] = array( |
949 | 988 | 'tag' => 'item', |
@@ -967,8 +1006,7 @@ discard block |
||
967 | 1006 | ), |
968 | 1007 | ), |
969 | 1008 | ); |
970 | - } |
|
971 | - elseif ($xml_format == 'atom') |
|
1009 | + } elseif ($xml_format == 'atom') |
|
972 | 1010 | { |
973 | 1011 | // Only one attachment allowed |
974 | 1012 | if (!empty($loaded_attachments)) |
@@ -980,9 +1018,9 @@ discard block |
||
980 | 1018 | 'length' => $attachment['filesize'], |
981 | 1019 | 'type' => $attachment['mime_type'], |
982 | 1020 | ); |
1021 | + } else { |
|
1022 | + $enclosure = null; |
|
983 | 1023 | } |
984 | - else |
|
985 | - $enclosure = null; |
|
986 | 1024 | |
987 | 1025 | $data[] = array( |
988 | 1026 | 'tag' => 'entry', |
@@ -1082,9 +1120,9 @@ discard block |
||
1082 | 1120 | ) |
1083 | 1121 | ); |
1084 | 1122 | } |
1123 | + } else { |
|
1124 | + $attachments = null; |
|
1085 | 1125 | } |
1086 | - else |
|
1087 | - $attachments = null; |
|
1088 | 1126 | |
1089 | 1127 | $data[] = array( |
1090 | 1128 | 'tag' => 'article', |
@@ -1202,22 +1240,25 @@ discard block |
||
1202 | 1240 | if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit']) |
1203 | 1241 | { |
1204 | 1242 | $smcFunc['db_free_result']($request); |
1205 | - if (empty($_REQUEST['boards']) && empty($board)) |
|
1206 | - unset($context['optimize_msg']['lowest']); |
|
1207 | - else |
|
1208 | - $context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2'; |
|
1243 | + if (empty($_REQUEST['boards']) && empty($board)) { |
|
1244 | + unset($context['optimize_msg']['lowest']); |
|
1245 | + } else { |
|
1246 | + $context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2'; |
|
1247 | + } |
|
1209 | 1248 | $loops++; |
1249 | + } else { |
|
1250 | + $done = true; |
|
1210 | 1251 | } |
1211 | - else |
|
1212 | - $done = true; |
|
1213 | 1252 | } |
1214 | 1253 | $messages = array(); |
1215 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1216 | - $messages[] = $row['id_msg']; |
|
1254 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1255 | + $messages[] = $row['id_msg']; |
|
1256 | + } |
|
1217 | 1257 | $smcFunc['db_free_result']($request); |
1218 | 1258 | |
1219 | - if (empty($messages)) |
|
1220 | - return array(); |
|
1259 | + if (empty($messages)) { |
|
1260 | + return array(); |
|
1261 | + } |
|
1221 | 1262 | |
1222 | 1263 | // Find the most recent posts this user can see. |
1223 | 1264 | $request = $smcFunc['db_query']('', ' |
@@ -1247,8 +1288,9 @@ discard block |
||
1247 | 1288 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1248 | 1289 | { |
1249 | 1290 | // Limit the length of the message, if the option is set. |
1250 | - if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) |
|
1251 | - $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
1291 | + if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) { |
|
1292 | + $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
1293 | + } |
|
1252 | 1294 | |
1253 | 1295 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
1254 | 1296 | |
@@ -1275,8 +1317,9 @@ discard block |
||
1275 | 1317 | while ($attach = $smcFunc['db_fetch_assoc']($attach_request)) |
1276 | 1318 | { |
1277 | 1319 | // Include approved attachments only |
1278 | - if ($attach['approved']) |
|
1279 | - $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
1320 | + if ($attach['approved']) { |
|
1321 | + $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
1322 | + } |
|
1280 | 1323 | } |
1281 | 1324 | $smcFunc['db_free_result']($attach_request); |
1282 | 1325 | |
@@ -1284,16 +1327,17 @@ discard block |
||
1284 | 1327 | if (!empty($loaded_attachments)) |
1285 | 1328 | { |
1286 | 1329 | uasort($loaded_attachments, function($a, $b) { |
1287 | - if ($a['filesize'] == $b['filesize']) |
|
1288 | - return 0; |
|
1330 | + if ($a['filesize'] == $b['filesize']) { |
|
1331 | + return 0; |
|
1332 | + } |
|
1289 | 1333 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
1290 | 1334 | }); |
1335 | + } else { |
|
1336 | + $loaded_attachments = null; |
|
1291 | 1337 | } |
1292 | - else |
|
1293 | - $loaded_attachments = null; |
|
1338 | + } else { |
|
1339 | + $loaded_attachments = null; |
|
1294 | 1340 | } |
1295 | - else |
|
1296 | - $loaded_attachments = null; |
|
1297 | 1341 | |
1298 | 1342 | // Create a GUID for this post using the tag URI scheme |
1299 | 1343 | $guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['poster_time']) . ':msg=' . $row['id_msg']; |
@@ -1310,9 +1354,9 @@ discard block |
||
1310 | 1354 | 'length' => $attachment['filesize'], |
1311 | 1355 | 'type' => $attachment['mime_type'], |
1312 | 1356 | ); |
1357 | + } else { |
|
1358 | + $enclosure = null; |
|
1313 | 1359 | } |
1314 | - else |
|
1315 | - $enclosure = null; |
|
1316 | 1360 | |
1317 | 1361 | $data[] = array( |
1318 | 1362 | 'tag' => 'item', |
@@ -1358,8 +1402,7 @@ discard block |
||
1358 | 1402 | ), |
1359 | 1403 | ), |
1360 | 1404 | ); |
1361 | - } |
|
1362 | - elseif ($xml_format == 'rdf') |
|
1405 | + } elseif ($xml_format == 'rdf') |
|
1363 | 1406 | { |
1364 | 1407 | $data[] = array( |
1365 | 1408 | 'tag' => 'item', |
@@ -1383,8 +1426,7 @@ discard block |
||
1383 | 1426 | ), |
1384 | 1427 | ), |
1385 | 1428 | ); |
1386 | - } |
|
1387 | - elseif ($xml_format == 'atom') |
|
1429 | + } elseif ($xml_format == 'atom') |
|
1388 | 1430 | { |
1389 | 1431 | // Only one attachment allowed |
1390 | 1432 | if (!empty($loaded_attachments)) |
@@ -1396,9 +1438,9 @@ discard block |
||
1396 | 1438 | 'length' => $attachment['filesize'], |
1397 | 1439 | 'type' => $attachment['mime_type'], |
1398 | 1440 | ); |
1441 | + } else { |
|
1442 | + $enclosure = null; |
|
1399 | 1443 | } |
1400 | - else |
|
1401 | - $enclosure = null; |
|
1402 | 1444 | |
1403 | 1445 | $data[] = array( |
1404 | 1446 | 'tag' => 'entry', |
@@ -1498,9 +1540,9 @@ discard block |
||
1498 | 1540 | ) |
1499 | 1541 | ); |
1500 | 1542 | } |
1543 | + } else { |
|
1544 | + $attachments = null; |
|
1501 | 1545 | } |
1502 | - else |
|
1503 | - $attachments = null; |
|
1504 | 1546 | |
1505 | 1547 | $data[] = array( |
1506 | 1548 | 'tag' => 'recent-post', |
@@ -1619,14 +1661,16 @@ discard block |
||
1619 | 1661 | global $scripturl, $memberContext, $user_profile, $user_info; |
1620 | 1662 | |
1621 | 1663 | // You must input a valid user.... |
1622 | - if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) |
|
1623 | - return array(); |
|
1664 | + if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) { |
|
1665 | + return array(); |
|
1666 | + } |
|
1624 | 1667 | |
1625 | 1668 | // Make sure the id is a number and not "I like trying to hack the database". |
1626 | 1669 | $_GET['u'] = (int) $_GET['u']; |
1627 | 1670 | // Load the member's contextual information! |
1628 | - if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) |
|
1629 | - return array(); |
|
1671 | + if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) { |
|
1672 | + return array(); |
|
1673 | + } |
|
1630 | 1674 | |
1631 | 1675 | // Okay, I admit it, I'm lazy. Stupid $_GET['u'] is long and hard to type. |
1632 | 1676 | $profile = &$memberContext[$_GET['u']]; |
@@ -1668,8 +1712,7 @@ discard block |
||
1668 | 1712 | ), |
1669 | 1713 | ) |
1670 | 1714 | ); |
1671 | - } |
|
1672 | - elseif ($xml_format == 'rdf') |
|
1715 | + } elseif ($xml_format == 'rdf') |
|
1673 | 1716 | { |
1674 | 1717 | $data[] = array( |
1675 | 1718 | 'tag' => 'item', |
@@ -1693,8 +1736,7 @@ discard block |
||
1693 | 1736 | ), |
1694 | 1737 | ) |
1695 | 1738 | ); |
1696 | - } |
|
1697 | - elseif ($xml_format == 'atom') |
|
1739 | + } elseif ($xml_format == 'atom') |
|
1698 | 1740 | { |
1699 | 1741 | $data[] = array( |
1700 | 1742 | 'tag' => 'entry', |
@@ -1747,8 +1789,7 @@ discard block |
||
1747 | 1789 | ), |
1748 | 1790 | ) |
1749 | 1791 | ); |
1750 | - } |
|
1751 | - else |
|
1792 | + } else |
|
1752 | 1793 | { |
1753 | 1794 | $data = array( |
1754 | 1795 | array( |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
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 | * Scheduled tasks management dispatcher. This function checks permissions and delegates |
@@ -41,10 +42,11 @@ discard block |
||
41 | 42 | ); |
42 | 43 | |
43 | 44 | // We need to find what's the action. |
44 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
45 | - $context['sub_action'] = $_REQUEST['sa']; |
|
46 | - else |
|
47 | - $context['sub_action'] = 'tasks'; |
|
45 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
46 | + $context['sub_action'] = $_REQUEST['sa']; |
|
47 | + } else { |
|
48 | + $context['sub_action'] = 'tasks'; |
|
49 | + } |
|
48 | 50 | |
49 | 51 | // Now for the lovely tabs. That we all love. |
50 | 52 | $context[$context['admin_menu_name']]['tab_data'] = array( |
@@ -94,9 +96,10 @@ discard block |
||
94 | 96 | |
95 | 97 | // Enable and disable as required. |
96 | 98 | $enablers = array(0); |
97 | - foreach ($_POST['enable_task'] as $id => $enabled) |
|
98 | - if ($enabled) |
|
99 | + foreach ($_POST['enable_task'] as $id => $enabled) { |
|
100 | + if ($enabled) |
|
99 | 101 | $enablers[] = (int) $id; |
102 | + } |
|
100 | 103 | |
101 | 104 | // Do the update! |
102 | 105 | $smcFunc['db_query']('', ' |
@@ -134,8 +137,9 @@ discard block |
||
134 | 137 | |
135 | 138 | // Lets figure out which ones they want to run. |
136 | 139 | $tasks = array(); |
137 | - foreach ($_POST['run_task'] as $task => $dummy) |
|
138 | - $tasks[] = (int) $task; |
|
140 | + foreach ($_POST['run_task'] as $task => $dummy) { |
|
141 | + $tasks[] = (int) $task; |
|
142 | + } |
|
139 | 143 | |
140 | 144 | // Load up the tasks. |
141 | 145 | $request = $smcFunc['db_query']('', ' |
@@ -155,36 +159,41 @@ discard block |
||
155 | 159 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
156 | 160 | { |
157 | 161 | // What kind of task are we handling? |
158 | - if (!empty($row['callable'])) |
|
159 | - $task_string = $row['callable']; |
|
162 | + if (!empty($row['callable'])) { |
|
163 | + $task_string = $row['callable']; |
|
164 | + } |
|
160 | 165 | |
161 | 166 | // Default SMF task or old mods? |
162 | - elseif (function_exists('scheduled_' . $row['task'])) |
|
163 | - $task_string = 'scheduled_' . $row['task']; |
|
167 | + elseif (function_exists('scheduled_' . $row['task'])) { |
|
168 | + $task_string = 'scheduled_' . $row['task']; |
|
169 | + } |
|
164 | 170 | |
165 | 171 | // One last resource, the task name. |
166 | - elseif (!empty($row['task'])) |
|
167 | - $task_string = $row['task']; |
|
172 | + elseif (!empty($row['task'])) { |
|
173 | + $task_string = $row['task']; |
|
174 | + } |
|
168 | 175 | |
169 | 176 | $start_time = microtime(true); |
170 | 177 | // The functions got to exist for us to use it. |
171 | - if (empty($task_string)) |
|
172 | - continue; |
|
178 | + if (empty($task_string)) { |
|
179 | + continue; |
|
180 | + } |
|
173 | 181 | |
174 | 182 | // Try to stop a timeout, this would be bad... |
175 | 183 | @set_time_limit(300); |
176 | - if (function_exists('apache_reset_timeout')) |
|
177 | - @apache_reset_timeout(); |
|
184 | + if (function_exists('apache_reset_timeout')) { |
|
185 | + @apache_reset_timeout(); |
|
186 | + } |
|
178 | 187 | |
179 | 188 | // Get the callable. |
180 | 189 | $callable_task = call_helper($task_string, true); |
181 | 190 | |
182 | 191 | // Perform the task. |
183 | - if (!empty($callable_task)) |
|
184 | - $completed = call_user_func($callable_task); |
|
185 | - |
|
186 | - else |
|
187 | - $completed = false; |
|
192 | + if (!empty($callable_task)) { |
|
193 | + $completed = call_user_func($callable_task); |
|
194 | + } else { |
|
195 | + $completed = false; |
|
196 | + } |
|
188 | 197 | |
189 | 198 | // Log that we did it ;) |
190 | 199 | if ($completed) |
@@ -201,8 +210,9 @@ discard block |
||
201 | 210 | $smcFunc['db_free_result']($request); |
202 | 211 | |
203 | 212 | // If we had any errors, push them to session so we can pick them up next time to tell the user. |
204 | - if (!empty($context['scheduled_errors'])) |
|
205 | - $_SESSION['st_error'] = $context['scheduled_errors']; |
|
213 | + if (!empty($context['scheduled_errors'])) { |
|
214 | + $_SESSION['st_error'] = $context['scheduled_errors']; |
|
215 | + } |
|
206 | 216 | |
207 | 217 | redirectexit('action=admin;area=scheduledtasks;done'); |
208 | 218 | } |
@@ -374,8 +384,9 @@ discard block |
||
374 | 384 | $context['server_time'] = timeformat(time(), false, 'server'); |
375 | 385 | |
376 | 386 | // Cleaning... |
377 | - if (!isset($_GET['tid'])) |
|
378 | - fatal_lang_error('no_access', false); |
|
387 | + if (!isset($_GET['tid'])) { |
|
388 | + fatal_lang_error('no_access', false); |
|
389 | + } |
|
379 | 390 | $_GET['tid'] = (int) $_GET['tid']; |
380 | 391 | |
381 | 392 | // Saving? |
@@ -391,10 +402,12 @@ discard block |
||
391 | 402 | preg_match('~(\d{1,2}):(\d{1,2})~', $_POST['offset'], $matches); |
392 | 403 | |
393 | 404 | // If a half is empty then assume zero offset! |
394 | - if (!isset($matches[2]) || $matches[2] > 59) |
|
395 | - $matches[2] = 0; |
|
396 | - if (!isset($matches[1]) || $matches[1] > 23) |
|
397 | - $matches[1] = 0; |
|
405 | + if (!isset($matches[2]) || $matches[2] > 59) { |
|
406 | + $matches[2] = 0; |
|
407 | + } |
|
408 | + if (!isset($matches[1]) || $matches[1] > 23) { |
|
409 | + $matches[1] = 0; |
|
410 | + } |
|
398 | 411 | |
399 | 412 | // Now the offset is easy; easy peasy - except we need to offset by a few hours... |
400 | 413 | $offset = $matches[1] * 3600 + $matches[2] * 60 - date('Z'); |
@@ -404,8 +417,9 @@ discard block |
||
404 | 417 | $unit = in_array(substr($_POST['unit'], 0, 1), array('m', 'h', 'd', 'w')) ? substr($_POST['unit'], 0, 1) : 'd'; |
405 | 418 | |
406 | 419 | // Don't allow one minute intervals. |
407 | - if ($interval == 1 && $unit == 'm') |
|
408 | - $interval = 2; |
|
420 | + if ($interval == 1 && $unit == 'm') { |
|
421 | + $interval = 2; |
|
422 | + } |
|
409 | 423 | |
410 | 424 | // Is it disabled? |
411 | 425 | $disabled = !isset($_POST['enabled']) ? 1 : 0; |
@@ -443,8 +457,9 @@ discard block |
||
443 | 457 | ); |
444 | 458 | |
445 | 459 | // Should never, ever, happen! |
446 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
447 | - fatal_lang_error('no_access', false); |
|
460 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
461 | + fatal_lang_error('no_access', false); |
|
462 | + } |
|
448 | 463 | |
449 | 464 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
450 | 465 | { |
@@ -602,13 +617,14 @@ discard block |
||
602 | 617 | ) |
603 | 618 | ); |
604 | 619 | $log_entries = array(); |
605 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
606 | - $log_entries[] = array( |
|
620 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
621 | + $log_entries[] = array( |
|
607 | 622 | 'id' => $row['id_log'], |
608 | 623 | 'name' => isset($txt['scheduled_task_' . $row['task']]) ? $txt['scheduled_task_' . $row['task']] : $row['task'], |
609 | 624 | 'time_run' => $row['time_run'], |
610 | 625 | 'time_taken' => $row['time_taken'], |
611 | 626 | ); |
627 | + } |
|
612 | 628 | $smcFunc['db_free_result']($request); |
613 | 629 | |
614 | 630 | return $log_entries; |
@@ -649,8 +665,9 @@ discard block |
||
649 | 665 | |
650 | 666 | call_integration_hook('integrate_scheduled_tasks_settings', array(&$config_vars)); |
651 | 667 | |
652 | - if ($return_config) |
|
653 | - return $config_vars; |
|
668 | + if ($return_config) { |
|
669 | + return $config_vars; |
|
670 | + } |
|
654 | 671 | |
655 | 672 | // Set up the template. |
656 | 673 | $context['page_title'] = $txt['scheduled_tasks_settings']; |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
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,28 +48,36 @@ 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 | 73 | // We explicitly do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded. |
66 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
67 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
74 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
75 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
76 | + } |
|
68 | 77 | |
69 | - if (!empty($cache_enable)) |
|
70 | - cache_put_data('modSettings', $modSettings, 90); |
|
78 | + if (!empty($cache_enable)) { |
|
79 | + cache_put_data('modSettings', $modSettings, 90); |
|
80 | + } |
|
71 | 81 | } |
72 | 82 | |
73 | 83 | $modSettings['cache_enable'] = $cache_enable; |
@@ -87,8 +97,9 @@ discard block |
||
87 | 97 | }; |
88 | 98 | $fix_utf8mb4 = function($string) use ($utf8, $smcFunc) |
89 | 99 | { |
90 | - if (!$utf8 || $smcFunc['db_mb4']) |
|
91 | - return $string; |
|
100 | + if (!$utf8 || $smcFunc['db_mb4']) { |
|
101 | + return $string; |
|
102 | + } |
|
92 | 103 | |
93 | 104 | $i = 0; |
94 | 105 | $len = strlen($string); |
@@ -100,18 +111,15 @@ discard block |
||
100 | 111 | { |
101 | 112 | $new_string .= $string[$i]; |
102 | 113 | $i++; |
103 | - } |
|
104 | - elseif ($ord < 224) |
|
114 | + } elseif ($ord < 224) |
|
105 | 115 | { |
106 | 116 | $new_string .= $string[$i] . $string[$i + 1]; |
107 | 117 | $i += 2; |
108 | - } |
|
109 | - elseif ($ord < 240) |
|
118 | + } elseif ($ord < 240) |
|
110 | 119 | { |
111 | 120 | $new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2]; |
112 | 121 | $i += 3; |
113 | - } |
|
114 | - elseif ($ord < 248) |
|
122 | + } elseif ($ord < 248) |
|
115 | 123 | { |
116 | 124 | // Magic happens. |
117 | 125 | $val = (ord($string[$i]) & 0x07) << 18; |
@@ -155,8 +163,7 @@ discard block |
||
155 | 163 | { |
156 | 164 | $result = array_search($needle, array_slice($haystack_arr, $offset)); |
157 | 165 | return is_int($result) ? $result + $offset : false; |
158 | - } |
|
159 | - else |
|
166 | + } else |
|
160 | 167 | { |
161 | 168 | $needle_arr = preg_split('~(' . $ent_list . '|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
162 | 169 | $needle_size = count($needle_arr); |
@@ -165,8 +172,9 @@ discard block |
||
165 | 172 | while ((int) $result === $result) |
166 | 173 | { |
167 | 174 | $offset += $result; |
168 | - if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) |
|
169 | - return $offset; |
|
175 | + if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) { |
|
176 | + return $offset; |
|
177 | + } |
|
170 | 178 | $result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset)); |
171 | 179 | } |
172 | 180 | return false; |
@@ -204,8 +212,9 @@ discard block |
||
204 | 212 | $string = $ent_check($string); |
205 | 213 | preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches); |
206 | 214 | $string = $matches[0]; |
207 | - while (strlen($string) > $length) |
|
208 | - $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
215 | + while (strlen($string) > $length) { |
|
216 | + $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
217 | + } |
|
209 | 218 | return $string; |
210 | 219 | }, |
211 | 220 | 'ucfirst' => $utf8 ? function($string) use (&$smcFunc) |
@@ -215,8 +224,9 @@ discard block |
||
215 | 224 | 'ucwords' => $utf8 ? function($string) use (&$smcFunc) |
216 | 225 | { |
217 | 226 | $words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE); |
218 | - for ($i = 0, $n = count($words); $i < $n; $i += 2) |
|
219 | - $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
227 | + for ($i = 0, $n = count($words); $i < $n; $i += 2) { |
|
228 | + $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
229 | + } |
|
220 | 230 | return implode('', $words); |
221 | 231 | } : 'ucwords', |
222 | 232 | 'json_decode' => 'smf_json_decode', |
@@ -224,16 +234,17 @@ discard block |
||
224 | 234 | ); |
225 | 235 | |
226 | 236 | // Setting the timezone is a requirement for some functions. |
227 | - if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
|
228 | - date_default_timezone_set($modSettings['default_timezone']); |
|
229 | - else |
|
237 | + if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) { |
|
238 | + date_default_timezone_set($modSettings['default_timezone']); |
|
239 | + } else |
|
230 | 240 | { |
231 | 241 | // Get PHP's default timezone, if set |
232 | 242 | $ini_tz = ini_get('date.timezone'); |
233 | - if (!empty($ini_tz)) |
|
234 | - $modSettings['default_timezone'] = $ini_tz; |
|
235 | - else |
|
236 | - $modSettings['default_timezone'] = ''; |
|
243 | + if (!empty($ini_tz)) { |
|
244 | + $modSettings['default_timezone'] = $ini_tz; |
|
245 | + } else { |
|
246 | + $modSettings['default_timezone'] = ''; |
|
247 | + } |
|
237 | 248 | |
238 | 249 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
239 | 250 | if (!in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
@@ -251,22 +262,26 @@ discard block |
||
251 | 262 | if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null) |
252 | 263 | { |
253 | 264 | $modSettings['load_average'] = @file_get_contents('/proc/loadavg'); |
254 | - if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) |
|
255 | - $modSettings['load_average'] = (float) $matches[1]; |
|
256 | - elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) |
|
257 | - $modSettings['load_average'] = (float) $matches[1]; |
|
258 | - else |
|
259 | - unset($modSettings['load_average']); |
|
265 | + if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) { |
|
266 | + $modSettings['load_average'] = (float) $matches[1]; |
|
267 | + } elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) { |
|
268 | + $modSettings['load_average'] = (float) $matches[1]; |
|
269 | + } else { |
|
270 | + unset($modSettings['load_average']); |
|
271 | + } |
|
260 | 272 | |
261 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
262 | - cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
273 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
274 | + cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
275 | + } |
|
263 | 276 | } |
264 | 277 | |
265 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
266 | - call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
278 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
279 | + call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
280 | + } |
|
267 | 281 | |
268 | - if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) |
|
269 | - display_loadavg_error(); |
|
282 | + if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) { |
|
283 | + display_loadavg_error(); |
|
284 | + } |
|
270 | 285 | } |
271 | 286 | |
272 | 287 | // Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is. |
@@ -287,8 +302,9 @@ discard block |
||
287 | 302 | if (defined('SMF_INTEGRATION_SETTINGS')) |
288 | 303 | { |
289 | 304 | $integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true); |
290 | - foreach ($integration_settings as $hook => $function) |
|
291 | - add_integration_function($hook, $function, '', false); |
|
305 | + foreach ($integration_settings as $hook => $function) { |
|
306 | + add_integration_function($hook, $function, '', false); |
|
307 | + } |
|
292 | 308 | } |
293 | 309 | |
294 | 310 | // Any files to pre include? |
@@ -298,8 +314,9 @@ discard block |
||
298 | 314 | foreach ($pre_includes as $include) |
299 | 315 | { |
300 | 316 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
301 | - if (file_exists($include)) |
|
302 | - require_once($include); |
|
317 | + if (file_exists($include)) { |
|
318 | + require_once($include); |
|
319 | + } |
|
303 | 320 | } |
304 | 321 | } |
305 | 322 | |
@@ -410,9 +427,9 @@ discard block |
||
410 | 427 | break; |
411 | 428 | } |
412 | 429 | } |
430 | + } else { |
|
431 | + $id_member = 0; |
|
413 | 432 | } |
414 | - else |
|
415 | - $id_member = 0; |
|
416 | 433 | |
417 | 434 | if (empty($id_member) && isset($_COOKIE[$cookiename])) |
418 | 435 | { |
@@ -420,8 +437,9 @@ discard block |
||
420 | 437 | $cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false); |
421 | 438 | |
422 | 439 | // Legacy format (for recent 2.0 --> 2.1 upgrades) |
423 | - if (empty($cookie_data)) |
|
424 | - $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
440 | + if (empty($cookie_data)) { |
|
441 | + $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
442 | + } |
|
425 | 443 | |
426 | 444 | list($id_member, $password, $login_span, $cookie_domain, $cookie_path) = array_pad((array) $cookie_data, 5, ''); |
427 | 445 | |
@@ -429,16 +447,17 @@ discard block |
||
429 | 447 | |
430 | 448 | // Make sure the cookie is set to the correct domain and path |
431 | 449 | require_once($sourcedir . '/Subs-Auth.php'); |
432 | - if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']))) |
|
433 | - setLoginCookie((int) $login_span - time(), $id_member); |
|
434 | - } |
|
435 | - elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
450 | + if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']))) { |
|
451 | + setLoginCookie((int) $login_span - time(), $id_member); |
|
452 | + } |
|
453 | + } elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
436 | 454 | { |
437 | 455 | // @todo Perhaps we can do some more checking on this, such as on the first octet of the IP? |
438 | 456 | $cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename], true); |
439 | 457 | |
440 | - if (empty($cookie_data)) |
|
441 | - $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
458 | + if (empty($cookie_data)) { |
|
459 | + $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
460 | + } |
|
442 | 461 | |
443 | 462 | list($id_member, $password, $login_span) = array_pad((array) $cookie_data, 3, ''); |
444 | 463 | $id_member = !empty($id_member) && strlen($password) == 128 && (int) $login_span > time() ? (int) $id_member : 0; |
@@ -463,30 +482,34 @@ discard block |
||
463 | 482 | $user_settings = $smcFunc['db_fetch_assoc']($request); |
464 | 483 | $smcFunc['db_free_result']($request); |
465 | 484 | |
466 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) |
|
467 | - $user_settings['avatar'] = get_proxied_url($user_settings['avatar']); |
|
485 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) { |
|
486 | + $user_settings['avatar'] = get_proxied_url($user_settings['avatar']); |
|
487 | + } |
|
468 | 488 | |
469 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
470 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
489 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
490 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
491 | + } |
|
471 | 492 | } |
472 | 493 | |
473 | 494 | // Did we find 'im? If not, junk it. |
474 | 495 | if (!empty($user_settings)) |
475 | 496 | { |
476 | 497 | // As much as the password should be right, we can assume the integration set things up. |
477 | - if (!empty($already_verified) && $already_verified === true) |
|
478 | - $check = true; |
|
498 | + if (!empty($already_verified) && $already_verified === true) { |
|
499 | + $check = true; |
|
500 | + } |
|
479 | 501 | // SHA-512 hash should be 128 characters long. |
480 | - elseif (strlen($password) == 128) |
|
481 | - $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
482 | - else |
|
483 | - $check = false; |
|
502 | + elseif (strlen($password) == 128) { |
|
503 | + $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
504 | + } else { |
|
505 | + $check = false; |
|
506 | + } |
|
484 | 507 | |
485 | 508 | // Wrong password or not activated - either way, you're going nowhere. |
486 | 509 | $id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0; |
510 | + } else { |
|
511 | + $id_member = 0; |
|
487 | 512 | } |
488 | - else |
|
489 | - $id_member = 0; |
|
490 | 513 | |
491 | 514 | // If we no longer have the member maybe they're being all hackey, stop brute force! |
492 | 515 | if (!$id_member) |
@@ -515,8 +538,9 @@ discard block |
||
515 | 538 | |
516 | 539 | list ($tfamember, $tfasecret) = array_pad((array) $tfa_data, 2, ''); |
517 | 540 | |
518 | - if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) |
|
519 | - $tfasecret = null; |
|
541 | + if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) { |
|
542 | + $tfasecret = null; |
|
543 | + } |
|
520 | 544 | } |
521 | 545 | |
522 | 546 | // They didn't finish logging in before coming here? Then they're no one to us. |
@@ -538,10 +562,12 @@ discard block |
||
538 | 562 | // Are we forcing 2FA? Need to check if the user groups actually require 2FA |
539 | 563 | elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret'])) |
540 | 564 | { |
541 | - if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups |
|
565 | + if ($modSettings['tfa_mode'] == 2) { |
|
566 | + //only do this if we are just forcing SOME membergroups |
|
542 | 567 | { |
543 | 568 | //Build an array of ALL user membergroups. |
544 | 569 | $full_groups = array($user_settings['id_group']); |
570 | + } |
|
545 | 571 | if (!empty($user_settings['additional_groups'])) |
546 | 572 | { |
547 | 573 | $full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups'])); |
@@ -561,15 +587,17 @@ discard block |
||
561 | 587 | ); |
562 | 588 | $row = $smcFunc['db_fetch_assoc']($request); |
563 | 589 | $smcFunc['db_free_result']($request); |
590 | + } else { |
|
591 | + $row['total'] = 1; |
|
564 | 592 | } |
565 | - else |
|
566 | - $row['total'] = 1; //simplifies logics in the next "if" |
|
593 | + //simplifies logics in the next "if" |
|
567 | 594 | |
568 | 595 | $area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : ''; |
569 | 596 | $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
570 | 597 | |
571 | - if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) |
|
572 | - redirectexit('action=profile;area=tfasetup;forced'); |
|
598 | + if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) { |
|
599 | + redirectexit('action=profile;area=tfasetup;forced'); |
|
600 | + } |
|
573 | 601 | } |
574 | 602 | } |
575 | 603 | |
@@ -606,29 +634,32 @@ discard block |
||
606 | 634 | 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'])); |
607 | 635 | $user_settings['last_login'] = time(); |
608 | 636 | |
609 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
610 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
637 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
638 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
639 | + } |
|
611 | 640 | |
612 | - if (!empty($modSettings['cache_enable'])) |
|
613 | - cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
641 | + if (!empty($modSettings['cache_enable'])) { |
|
642 | + cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
643 | + } |
|
614 | 644 | } |
645 | + } elseif (empty($_SESSION['id_msg_last_visit'])) { |
|
646 | + $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
615 | 647 | } |
616 | - elseif (empty($_SESSION['id_msg_last_visit'])) |
|
617 | - $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
618 | 648 | |
619 | 649 | $username = $user_settings['member_name']; |
620 | 650 | |
621 | - if (empty($user_settings['additional_groups'])) |
|
622 | - $user_info = array( |
|
651 | + if (empty($user_settings['additional_groups'])) { |
|
652 | + $user_info = array( |
|
623 | 653 | 'groups' => array($user_settings['id_group'], $user_settings['id_post_group']) |
624 | 654 | ); |
625 | - else |
|
626 | - $user_info = array( |
|
655 | + } else { |
|
656 | + $user_info = array( |
|
627 | 657 | 'groups' => array_merge( |
628 | 658 | array($user_settings['id_group'], $user_settings['id_post_group']), |
629 | 659 | explode(',', $user_settings['additional_groups']) |
630 | 660 | ) |
631 | 661 | ); |
662 | + } |
|
632 | 663 | |
633 | 664 | // Because history has proven that it is possible for groups to go bad - clean up in case. |
634 | 665 | $user_info['groups'] = array_map('intval', $user_info['groups']); |
@@ -645,8 +676,7 @@ discard block |
||
645 | 676 | $time_system = new DateTime('now', $tz_system); |
646 | 677 | $time_user = new DateTime('now', $tz_user); |
647 | 678 | $user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600; |
648 | - } |
|
649 | - else |
|
679 | + } else |
|
650 | 680 | { |
651 | 681 | // !!! Compatibility. |
652 | 682 | $user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset']; |
@@ -660,8 +690,9 @@ discard block |
||
660 | 690 | $user_info = array('groups' => array(-1)); |
661 | 691 | $user_settings = array(); |
662 | 692 | |
663 | - if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) |
|
664 | - $_COOKIE[$cookiename] = ''; |
|
693 | + if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) { |
|
694 | + $_COOKIE[$cookiename] = ''; |
|
695 | + } |
|
665 | 696 | |
666 | 697 | // Expire the 2FA cookie |
667 | 698 | if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member'])) |
@@ -678,19 +709,20 @@ discard block |
||
678 | 709 | } |
679 | 710 | |
680 | 711 | // Create a login token if it doesn't exist yet. |
681 | - if (!isset($_SESSION['token']['post-login'])) |
|
682 | - createToken('login'); |
|
683 | - else |
|
684 | - list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
712 | + if (!isset($_SESSION['token']['post-login'])) { |
|
713 | + createToken('login'); |
|
714 | + } else { |
|
715 | + list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
716 | + } |
|
685 | 717 | |
686 | 718 | // Do we perhaps think this is a search robot? Check every five minutes just in case... |
687 | 719 | if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300)) |
688 | 720 | { |
689 | 721 | require_once($sourcedir . '/ManageSearchEngines.php'); |
690 | 722 | $user_info['possibly_robot'] = SpiderCheck(); |
723 | + } elseif (!empty($modSettings['spider_mode'])) { |
|
724 | + $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
691 | 725 | } |
692 | - elseif (!empty($modSettings['spider_mode'])) |
|
693 | - $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
694 | 726 | // If we haven't turned on proper spider hunts then have a guess! |
695 | 727 | else |
696 | 728 | { |
@@ -747,8 +779,9 @@ discard block |
||
747 | 779 | $user_info['groups'] = array_unique($user_info['groups']); |
748 | 780 | |
749 | 781 | // 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. |
750 | - if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) |
|
751 | - unset($user_info['ignoreboards'][$tmp]); |
|
782 | + if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) { |
|
783 | + unset($user_info['ignoreboards'][$tmp]); |
|
784 | + } |
|
752 | 785 | |
753 | 786 | // Allow the user to change their language. |
754 | 787 | if (!empty($modSettings['userLanguage'])) |
@@ -761,13 +794,14 @@ discard block |
||
761 | 794 | $user_info['language'] = strtr($_GET['language'], './\\:', '____'); |
762 | 795 | |
763 | 796 | // Make it permanent for members. |
764 | - if (!empty($user_info['id'])) |
|
765 | - updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
766 | - else |
|
767 | - $_SESSION['language'] = $user_info['language']; |
|
797 | + if (!empty($user_info['id'])) { |
|
798 | + updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
799 | + } else { |
|
800 | + $_SESSION['language'] = $user_info['language']; |
|
801 | + } |
|
802 | + } elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) { |
|
803 | + $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
768 | 804 | } |
769 | - elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) |
|
770 | - $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
771 | 805 | } |
772 | 806 | |
773 | 807 | $temp = build_query_board($user_info['id']); |
@@ -830,9 +864,9 @@ discard block |
||
830 | 864 | } |
831 | 865 | |
832 | 866 | // Remember redirection is the key to avoiding fallout from your bosses. |
833 | - if (!empty($topic)) |
|
834 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
835 | - else |
|
867 | + if (!empty($topic)) { |
|
868 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
869 | + } else |
|
836 | 870 | { |
837 | 871 | loadPermissions(); |
838 | 872 | loadTheme(); |
@@ -850,10 +884,11 @@ discard block |
||
850 | 884 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
851 | 885 | { |
852 | 886 | // @todo SLOW? |
853 | - if (!empty($topic)) |
|
854 | - $temp = cache_get_data('topic_board-' . $topic, 120); |
|
855 | - else |
|
856 | - $temp = cache_get_data('board-' . $board, 120); |
|
887 | + if (!empty($topic)) { |
|
888 | + $temp = cache_get_data('topic_board-' . $topic, 120); |
|
889 | + } else { |
|
890 | + $temp = cache_get_data('board-' . $board, 120); |
|
891 | + } |
|
857 | 892 | |
858 | 893 | if (!empty($temp)) |
859 | 894 | { |
@@ -891,8 +926,9 @@ discard block |
||
891 | 926 | $row = $smcFunc['db_fetch_assoc']($request); |
892 | 927 | |
893 | 928 | // Set the current board. |
894 | - if (!empty($row['id_board'])) |
|
895 | - $board = $row['id_board']; |
|
929 | + if (!empty($row['id_board'])) { |
|
930 | + $board = $row['id_board']; |
|
931 | + } |
|
896 | 932 | |
897 | 933 | // Basic operating information. (globals... :/) |
898 | 934 | $board_info = array( |
@@ -928,21 +964,23 @@ discard block |
||
928 | 964 | |
929 | 965 | do |
930 | 966 | { |
931 | - if (!empty($row['id_moderator'])) |
|
932 | - $board_info['moderators'][$row['id_moderator']] = array( |
|
967 | + if (!empty($row['id_moderator'])) { |
|
968 | + $board_info['moderators'][$row['id_moderator']] = array( |
|
933 | 969 | 'id' => $row['id_moderator'], |
934 | 970 | 'name' => $row['real_name'], |
935 | 971 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
936 | 972 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
937 | 973 | ); |
974 | + } |
|
938 | 975 | |
939 | - if (!empty($row['id_moderator_group'])) |
|
940 | - $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
976 | + if (!empty($row['id_moderator_group'])) { |
|
977 | + $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
941 | 978 | 'id' => $row['id_moderator_group'], |
942 | 979 | 'name' => $row['group_name'], |
943 | 980 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
944 | 981 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
945 | 982 | ); |
983 | + } |
|
946 | 984 | } |
947 | 985 | while ($row = $smcFunc['db_fetch_assoc']($request)); |
948 | 986 | |
@@ -974,12 +1012,12 @@ discard block |
||
974 | 1012 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
975 | 1013 | { |
976 | 1014 | // @todo SLOW? |
977 | - if (!empty($topic)) |
|
978 | - cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
1015 | + if (!empty($topic)) { |
|
1016 | + cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
1017 | + } |
|
979 | 1018 | cache_put_data('board-' . $board, $board_info, 120); |
980 | 1019 | } |
981 | - } |
|
982 | - else |
|
1020 | + } else |
|
983 | 1021 | { |
984 | 1022 | // Otherwise the topic is invalid, there are no moderators, etc. |
985 | 1023 | $board_info = array( |
@@ -993,8 +1031,9 @@ discard block |
||
993 | 1031 | $smcFunc['db_free_result']($request); |
994 | 1032 | } |
995 | 1033 | |
996 | - if (!empty($topic)) |
|
997 | - $_GET['board'] = (int) $board; |
|
1034 | + if (!empty($topic)) { |
|
1035 | + $_GET['board'] = (int) $board; |
|
1036 | + } |
|
998 | 1037 | |
999 | 1038 | if (!empty($board)) |
1000 | 1039 | { |
@@ -1004,10 +1043,12 @@ discard block |
||
1004 | 1043 | // Now check if the user is a moderator. |
1005 | 1044 | $user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0; |
1006 | 1045 | |
1007 | - if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) |
|
1008 | - $board_info['error'] = 'access'; |
|
1009 | - if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) |
|
1010 | - $board_info['error'] = 'access'; |
|
1046 | + if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) { |
|
1047 | + $board_info['error'] = 'access'; |
|
1048 | + } |
|
1049 | + if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) { |
|
1050 | + $board_info['error'] = 'access'; |
|
1051 | + } |
|
1011 | 1052 | |
1012 | 1053 | // Build up the linktree. |
1013 | 1054 | $context['linktree'] = array_merge( |
@@ -1030,8 +1071,9 @@ discard block |
||
1030 | 1071 | $context['current_board'] = $board; |
1031 | 1072 | |
1032 | 1073 | // No posting in redirection boards! |
1033 | - if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) |
|
1034 | - $board_info['error'] == 'post_in_redirect'; |
|
1074 | + if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) { |
|
1075 | + $board_info['error'] == 'post_in_redirect'; |
|
1076 | + } |
|
1035 | 1077 | |
1036 | 1078 | // Hacker... you can't see this topic, I'll tell you that. (but moderators can!) |
1037 | 1079 | if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod'])) |
@@ -1057,24 +1099,23 @@ discard block |
||
1057 | 1099 | ob_end_clean(); |
1058 | 1100 | send_http_status(403); |
1059 | 1101 | die; |
1060 | - } |
|
1061 | - elseif ($board_info['error'] == 'post_in_redirect') |
|
1102 | + } elseif ($board_info['error'] == 'post_in_redirect') |
|
1062 | 1103 | { |
1063 | 1104 | // Slightly different error message here... |
1064 | 1105 | fatal_lang_error('cannot_post_redirect', false); |
1065 | - } |
|
1066 | - elseif ($user_info['is_guest']) |
|
1106 | + } elseif ($user_info['is_guest']) |
|
1067 | 1107 | { |
1068 | 1108 | loadLanguage('Errors'); |
1069 | 1109 | is_not_guest($txt['topic_gone']); |
1110 | + } else { |
|
1111 | + fatal_lang_error('topic_gone', false); |
|
1070 | 1112 | } |
1071 | - else |
|
1072 | - fatal_lang_error('topic_gone', false); |
|
1073 | 1113 | } |
1074 | 1114 | |
1075 | - if ($user_info['is_mod']) |
|
1076 | - $user_info['groups'][] = 3; |
|
1077 | -} |
|
1115 | + if ($user_info['is_mod']) { |
|
1116 | + $user_info['groups'][] = 3; |
|
1117 | + } |
|
1118 | + } |
|
1078 | 1119 | |
1079 | 1120 | /** |
1080 | 1121 | * Load this user's permissions. |
@@ -1095,8 +1136,9 @@ discard block |
||
1095 | 1136 | asort($cache_groups); |
1096 | 1137 | $cache_groups = implode(',', $cache_groups); |
1097 | 1138 | // If it's a spider then cache it different. |
1098 | - if ($user_info['possibly_robot']) |
|
1099 | - $cache_groups .= '-spider'; |
|
1139 | + if ($user_info['possibly_robot']) { |
|
1140 | + $cache_groups .= '-spider'; |
|
1141 | + } |
|
1100 | 1142 | |
1101 | 1143 | if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
1102 | 1144 | { |
@@ -1104,9 +1146,9 @@ discard block |
||
1104 | 1146 | banPermissions(); |
1105 | 1147 | |
1106 | 1148 | return; |
1149 | + } elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) { |
|
1150 | + list ($user_info['permissions'], $removals) = $temp; |
|
1107 | 1151 | } |
1108 | - elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
|
1109 | - list ($user_info['permissions'], $removals) = $temp; |
|
1110 | 1152 | } |
1111 | 1153 | |
1112 | 1154 | // If it is detected as a robot, and we are restricting permissions as a special group - then implement this. |
@@ -1128,23 +1170,26 @@ discard block |
||
1128 | 1170 | $removals = array(); |
1129 | 1171 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1130 | 1172 | { |
1131 | - if (empty($row['add_deny'])) |
|
1132 | - $removals[] = $row['permission']; |
|
1133 | - else |
|
1134 | - $user_info['permissions'][] = $row['permission']; |
|
1173 | + if (empty($row['add_deny'])) { |
|
1174 | + $removals[] = $row['permission']; |
|
1175 | + } else { |
|
1176 | + $user_info['permissions'][] = $row['permission']; |
|
1177 | + } |
|
1135 | 1178 | } |
1136 | 1179 | $smcFunc['db_free_result']($request); |
1137 | 1180 | |
1138 | - if (isset($cache_groups)) |
|
1139 | - cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
1181 | + if (isset($cache_groups)) { |
|
1182 | + cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
1183 | + } |
|
1140 | 1184 | } |
1141 | 1185 | |
1142 | 1186 | // Get the board permissions. |
1143 | 1187 | if (!empty($board)) |
1144 | 1188 | { |
1145 | 1189 | // Make sure the board (if any) has been loaded by loadBoard(). |
1146 | - if (!isset($board_info['profile'])) |
|
1147 | - fatal_lang_error('no_board'); |
|
1190 | + if (!isset($board_info['profile'])) { |
|
1191 | + fatal_lang_error('no_board'); |
|
1192 | + } |
|
1148 | 1193 | |
1149 | 1194 | $request = $smcFunc['db_query']('', ' |
1150 | 1195 | SELECT permission, add_deny |
@@ -1160,20 +1205,23 @@ discard block |
||
1160 | 1205 | ); |
1161 | 1206 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1162 | 1207 | { |
1163 | - if (empty($row['add_deny'])) |
|
1164 | - $removals[] = $row['permission']; |
|
1165 | - else |
|
1166 | - $user_info['permissions'][] = $row['permission']; |
|
1208 | + if (empty($row['add_deny'])) { |
|
1209 | + $removals[] = $row['permission']; |
|
1210 | + } else { |
|
1211 | + $user_info['permissions'][] = $row['permission']; |
|
1212 | + } |
|
1167 | 1213 | } |
1168 | 1214 | $smcFunc['db_free_result']($request); |
1169 | 1215 | } |
1170 | 1216 | |
1171 | 1217 | // Remove all the permissions they shouldn't have ;). |
1172 | - if (!empty($modSettings['permission_enable_deny'])) |
|
1173 | - $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
1218 | + if (!empty($modSettings['permission_enable_deny'])) { |
|
1219 | + $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
1220 | + } |
|
1174 | 1221 | |
1175 | - if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) |
|
1176 | - cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
1222 | + if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) { |
|
1223 | + cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
1224 | + } |
|
1177 | 1225 | |
1178 | 1226 | // Banned? Watch, don't touch.. |
1179 | 1227 | banPermissions(); |
@@ -1185,17 +1233,18 @@ discard block |
||
1185 | 1233 | { |
1186 | 1234 | require_once($sourcedir . '/Subs-Auth.php'); |
1187 | 1235 | rebuildModCache(); |
1236 | + } else { |
|
1237 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
1188 | 1238 | } |
1189 | - else |
|
1190 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
1191 | 1239 | |
1192 | 1240 | // This is a useful phantom permission added to the current user, and only the current user while they are logged in. |
1193 | 1241 | // For example this drastically simplifies certain changes to the profile area. |
1194 | 1242 | $user_info['permissions'][] = 'is_not_guest'; |
1195 | 1243 | // And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions. |
1196 | 1244 | $user_info['permissions'][] = 'profile_view_own'; |
1197 | - if (in_array('profile_view', $user_info['permissions'])) |
|
1198 | - $user_info['permissions'][] = 'profile_view_any'; |
|
1245 | + if (in_array('profile_view', $user_info['permissions'])) { |
|
1246 | + $user_info['permissions'][] = 'profile_view_any'; |
|
1247 | + } |
|
1199 | 1248 | } |
1200 | 1249 | } |
1201 | 1250 | |
@@ -1213,8 +1262,9 @@ discard block |
||
1213 | 1262 | global $image_proxy_enabled, $user_info; |
1214 | 1263 | |
1215 | 1264 | // Can't just look for no users :P. |
1216 | - if (empty($users)) |
|
1217 | - return array(); |
|
1265 | + if (empty($users)) { |
|
1266 | + return array(); |
|
1267 | + } |
|
1218 | 1268 | |
1219 | 1269 | // Pass the set value |
1220 | 1270 | $context['loadMemberContext_set'] = $set; |
@@ -1229,8 +1279,9 @@ discard block |
||
1229 | 1279 | for ($i = 0, $n = count($users); $i < $n; $i++) |
1230 | 1280 | { |
1231 | 1281 | $data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240); |
1232 | - if ($data == null) |
|
1233 | - continue; |
|
1282 | + if ($data == null) { |
|
1283 | + continue; |
|
1284 | + } |
|
1234 | 1285 | |
1235 | 1286 | $loaded_ids[] = $data['id_member']; |
1236 | 1287 | $user_profile[$data['id_member']] = $data; |
@@ -1297,16 +1348,19 @@ discard block |
||
1297 | 1348 | $row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : ''; |
1298 | 1349 | |
1299 | 1350 | // Take care of proxying avatar if required, do this here for maximum reach |
1300 | - if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) |
|
1301 | - $row['avatar'] = get_proxied_url($row['avatar']); |
|
1351 | + if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) { |
|
1352 | + $row['avatar'] = get_proxied_url($row['avatar']); |
|
1353 | + } |
|
1302 | 1354 | |
1303 | 1355 | // Keep track of the member's normal member group |
1304 | 1356 | $row['primary_group'] = !empty($row['member_group']) ? $row['member_group'] : ''; |
1305 | 1357 | |
1306 | - if (isset($row['member_ip'])) |
|
1307 | - $row['member_ip'] = inet_dtop($row['member_ip']); |
|
1308 | - if (isset($row['member_ip2'])) |
|
1309 | - $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
1358 | + if (isset($row['member_ip'])) { |
|
1359 | + $row['member_ip'] = inet_dtop($row['member_ip']); |
|
1360 | + } |
|
1361 | + if (isset($row['member_ip2'])) { |
|
1362 | + $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
1363 | + } |
|
1310 | 1364 | $row['id_member'] = (int) $row['id_member']; |
1311 | 1365 | $new_loaded_ids[] = $row['id_member']; |
1312 | 1366 | $loaded_ids[] = $row['id_member']; |
@@ -1326,8 +1380,9 @@ discard block |
||
1326 | 1380 | 'loaded_ids' => $new_loaded_ids, |
1327 | 1381 | ) |
1328 | 1382 | ); |
1329 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1330 | - $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
1383 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1384 | + $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
1385 | + } |
|
1331 | 1386 | $smcFunc['db_free_result']($request); |
1332 | 1387 | } |
1333 | 1388 | |
@@ -1338,10 +1393,11 @@ discard block |
||
1338 | 1393 | { |
1339 | 1394 | foreach ($loaded_ids as $a_member) |
1340 | 1395 | { |
1341 | - if (!empty($user_profile[$a_member]['additional_groups'])) |
|
1342 | - $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
1343 | - else |
|
1344 | - $groups = array($user_profile[$a_member]['id_group']); |
|
1396 | + if (!empty($user_profile[$a_member]['additional_groups'])) { |
|
1397 | + $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
1398 | + } else { |
|
1399 | + $groups = array($user_profile[$a_member]['id_group']); |
|
1400 | + } |
|
1345 | 1401 | |
1346 | 1402 | $temp = array_intersect($groups, array_keys($board_info['moderator_groups'])); |
1347 | 1403 | |
@@ -1354,8 +1410,9 @@ discard block |
||
1354 | 1410 | |
1355 | 1411 | if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) |
1356 | 1412 | { |
1357 | - for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) |
|
1358 | - cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
1413 | + for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) { |
|
1414 | + cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
1415 | + } |
|
1359 | 1416 | } |
1360 | 1417 | |
1361 | 1418 | // Are we loading any moderators? If so, fix their group data... |
@@ -1381,14 +1438,17 @@ discard block |
||
1381 | 1438 | foreach ($temp_mods as $id) |
1382 | 1439 | { |
1383 | 1440 | // By popular demand, don't show admins or global moderators as moderators. |
1384 | - if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) |
|
1385 | - $user_profile[$id]['member_group'] = $row['member_group']; |
|
1441 | + if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) { |
|
1442 | + $user_profile[$id]['member_group'] = $row['member_group']; |
|
1443 | + } |
|
1386 | 1444 | |
1387 | 1445 | // If the Moderator group has no color or icons, but their group does... don't overwrite. |
1388 | - if (!empty($row['icons'])) |
|
1389 | - $user_profile[$id]['icons'] = $row['icons']; |
|
1390 | - if (!empty($row['member_group_color'])) |
|
1391 | - $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
1446 | + if (!empty($row['icons'])) { |
|
1447 | + $user_profile[$id]['icons'] = $row['icons']; |
|
1448 | + } |
|
1449 | + if (!empty($row['member_group_color'])) { |
|
1450 | + $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
1451 | + } |
|
1392 | 1452 | } |
1393 | 1453 | } |
1394 | 1454 | |
@@ -1410,12 +1470,14 @@ discard block |
||
1410 | 1470 | static $loadedLanguages = array(); |
1411 | 1471 | |
1412 | 1472 | // If this person's data is already loaded, skip it. |
1413 | - if (isset($dataLoaded[$user])) |
|
1414 | - return true; |
|
1473 | + if (isset($dataLoaded[$user])) { |
|
1474 | + return true; |
|
1475 | + } |
|
1415 | 1476 | |
1416 | 1477 | // We can't load guests or members not loaded by loadMemberData()! |
1417 | - if ($user == 0) |
|
1418 | - return false; |
|
1478 | + if ($user == 0) { |
|
1479 | + return false; |
|
1480 | + } |
|
1419 | 1481 | if (!isset($user_profile[$user])) |
1420 | 1482 | { |
1421 | 1483 | trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING); |
@@ -1441,12 +1503,16 @@ discard block |
||
1441 | 1503 | $buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array(); |
1442 | 1504 | |
1443 | 1505 | //We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme |
1444 | - if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists |
|
1506 | + if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) { |
|
1507 | + //icon is set and exists |
|
1445 | 1508 | $group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1]; |
1446 | - elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default |
|
1509 | + } elseif (isset($profile['icons'][1])) { |
|
1510 | + //icon is set and doesn't exist, fallback to default |
|
1447 | 1511 | $group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1]; |
1448 | - else //not set, bye bye |
|
1512 | + } else { |
|
1513 | + //not set, bye bye |
|
1449 | 1514 | $group_icon_url = ''; |
1515 | + } |
|
1450 | 1516 | |
1451 | 1517 | // These minimal values are always loaded |
1452 | 1518 | $memberContext[$user] = array( |
@@ -1465,8 +1531,9 @@ discard block |
||
1465 | 1531 | if ($context['loadMemberContext_set'] != 'minimal') |
1466 | 1532 | { |
1467 | 1533 | // Go the extra mile and load the user's native language name. |
1468 | - if (empty($loadedLanguages)) |
|
1469 | - $loadedLanguages = getLanguages(); |
|
1534 | + if (empty($loadedLanguages)) { |
|
1535 | + $loadedLanguages = getLanguages(); |
|
1536 | + } |
|
1470 | 1537 | |
1471 | 1538 | $memberContext[$user] += array( |
1472 | 1539 | 'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>', |
@@ -1521,31 +1588,33 @@ discard block |
||
1521 | 1588 | { |
1522 | 1589 | if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://'))) |
1523 | 1590 | { |
1524 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) |
|
1525 | - $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
1526 | - else |
|
1527 | - $image = get_gravatar_url($profile['email_address']); |
|
1528 | - } |
|
1529 | - else |
|
1591 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) { |
|
1592 | + $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
1593 | + } else { |
|
1594 | + $image = get_gravatar_url($profile['email_address']); |
|
1595 | + } |
|
1596 | + } else |
|
1530 | 1597 | { |
1531 | 1598 | // So it's stored in the member table? |
1532 | 1599 | if (!empty($profile['avatar'])) |
1533 | 1600 | { |
1534 | 1601 | $image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']; |
1602 | + } elseif (!empty($profile['filename'])) { |
|
1603 | + $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
1535 | 1604 | } |
1536 | - elseif (!empty($profile['filename'])) |
|
1537 | - $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
1538 | 1605 | // Right... no avatar...use the default one |
1539 | - else |
|
1540 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
1606 | + else { |
|
1607 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
1608 | + } |
|
1541 | 1609 | } |
1542 | - if (!empty($image)) |
|
1543 | - $memberContext[$user]['avatar'] = array( |
|
1610 | + if (!empty($image)) { |
|
1611 | + $memberContext[$user]['avatar'] = array( |
|
1544 | 1612 | 'name' => $profile['avatar'], |
1545 | 1613 | 'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">', |
1546 | 1614 | 'href' => $image, |
1547 | 1615 | 'url' => $image, |
1548 | 1616 | ); |
1617 | + } |
|
1549 | 1618 | } |
1550 | 1619 | |
1551 | 1620 | // Are we also loading the members custom fields into context? |
@@ -1553,13 +1622,15 @@ discard block |
||
1553 | 1622 | { |
1554 | 1623 | $memberContext[$user]['custom_fields'] = array(); |
1555 | 1624 | |
1556 | - if (!isset($context['display_fields'])) |
|
1557 | - $context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true); |
|
1625 | + if (!isset($context['display_fields'])) { |
|
1626 | + $context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true); |
|
1627 | + } |
|
1558 | 1628 | |
1559 | 1629 | foreach ($context['display_fields'] as $custom) |
1560 | 1630 | { |
1561 | - if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) |
|
1562 | - continue; |
|
1631 | + if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) { |
|
1632 | + continue; |
|
1633 | + } |
|
1563 | 1634 | |
1564 | 1635 | $value = $profile['options'][$custom['col_name']]; |
1565 | 1636 | |
@@ -1567,31 +1638,36 @@ discard block |
||
1567 | 1638 | $currentKey = 0; |
1568 | 1639 | |
1569 | 1640 | // Create a key => value array for multiple options fields |
1570 | - if (!empty($custom['options'])) |
|
1571 | - foreach ($custom['options'] as $k => $v) |
|
1641 | + if (!empty($custom['options'])) { |
|
1642 | + foreach ($custom['options'] as $k => $v) |
|
1572 | 1643 | { |
1573 | 1644 | $fieldOptions[] = $v; |
1574 | - if (empty($currentKey)) |
|
1575 | - $currentKey = $v == $value ? $k : 0; |
|
1645 | + } |
|
1646 | + if (empty($currentKey)) { |
|
1647 | + $currentKey = $v == $value ? $k : 0; |
|
1648 | + } |
|
1576 | 1649 | } |
1577 | 1650 | |
1578 | 1651 | // BBC? |
1579 | - if ($custom['bbc']) |
|
1580 | - $value = parse_bbc($value); |
|
1652 | + if ($custom['bbc']) { |
|
1653 | + $value = parse_bbc($value); |
|
1654 | + } |
|
1581 | 1655 | |
1582 | 1656 | // ... or checkbox? |
1583 | - elseif (isset($custom['type']) && $custom['type'] == 'check') |
|
1584 | - $value = $value ? $txt['yes'] : $txt['no']; |
|
1657 | + elseif (isset($custom['type']) && $custom['type'] == 'check') { |
|
1658 | + $value = $value ? $txt['yes'] : $txt['no']; |
|
1659 | + } |
|
1585 | 1660 | |
1586 | 1661 | // Enclosing the user input within some other text? |
1587 | - if (!empty($custom['enclose'])) |
|
1588 | - $value = strtr($custom['enclose'], array( |
|
1662 | + if (!empty($custom['enclose'])) { |
|
1663 | + $value = strtr($custom['enclose'], array( |
|
1589 | 1664 | '{SCRIPTURL}' => $scripturl, |
1590 | 1665 | '{IMAGES_URL}' => $settings['images_url'], |
1591 | 1666 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
1592 | 1667 | '{INPUT}' => $value, |
1593 | 1668 | '{KEY}' => $currentKey, |
1594 | 1669 | )); |
1670 | + } |
|
1595 | 1671 | |
1596 | 1672 | $memberContext[$user]['custom_fields'][] = array( |
1597 | 1673 | 'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'], |
@@ -1618,8 +1694,9 @@ discard block |
||
1618 | 1694 | global $smcFunc, $txt, $scripturl, $settings; |
1619 | 1695 | |
1620 | 1696 | // Do not waste my time... |
1621 | - if (empty($users) || empty($params)) |
|
1622 | - return false; |
|
1697 | + if (empty($users) || empty($params)) { |
|
1698 | + return false; |
|
1699 | + } |
|
1623 | 1700 | |
1624 | 1701 | // Make sure it's an array. |
1625 | 1702 | $users = !is_array($users) ? array($users) : array_unique($users); |
@@ -1646,41 +1723,48 @@ discard block |
||
1646 | 1723 | $currentKey = 0; |
1647 | 1724 | |
1648 | 1725 | // Create a key => value array for multiple options fields |
1649 | - if (!empty($row['field_options'])) |
|
1650 | - foreach (explode(',', $row['field_options']) as $k => $v) |
|
1726 | + if (!empty($row['field_options'])) { |
|
1727 | + foreach (explode(',', $row['field_options']) as $k => $v) |
|
1651 | 1728 | { |
1652 | 1729 | $fieldOptions[] = $v; |
1653 | - if (empty($currentKey)) |
|
1654 | - $currentKey = $v == $row['value'] ? $k : 0; |
|
1730 | + } |
|
1731 | + if (empty($currentKey)) { |
|
1732 | + $currentKey = $v == $row['value'] ? $k : 0; |
|
1733 | + } |
|
1655 | 1734 | } |
1656 | 1735 | |
1657 | 1736 | // BBC? |
1658 | - if (!empty($row['bbc'])) |
|
1659 | - $row['value'] = parse_bbc($row['value']); |
|
1737 | + if (!empty($row['bbc'])) { |
|
1738 | + $row['value'] = parse_bbc($row['value']); |
|
1739 | + } |
|
1660 | 1740 | |
1661 | 1741 | // ... or checkbox? |
1662 | - elseif (isset($row['type']) && $row['type'] == 'check') |
|
1663 | - $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
1742 | + elseif (isset($row['type']) && $row['type'] == 'check') { |
|
1743 | + $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
1744 | + } |
|
1664 | 1745 | |
1665 | 1746 | // Enclosing the user input within some other text? |
1666 | - if (!empty($row['enclose'])) |
|
1667 | - $row['value'] = strtr($row['enclose'], array( |
|
1747 | + if (!empty($row['enclose'])) { |
|
1748 | + $row['value'] = strtr($row['enclose'], array( |
|
1668 | 1749 | '{SCRIPTURL}' => $scripturl, |
1669 | 1750 | '{IMAGES_URL}' => $settings['images_url'], |
1670 | 1751 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
1671 | 1752 | '{INPUT}' => un_htmlspecialchars($row['value']), |
1672 | 1753 | '{KEY}' => $currentKey, |
1673 | 1754 | )); |
1755 | + } |
|
1674 | 1756 | |
1675 | 1757 | // Send a simple array if there is just 1 param |
1676 | - if (count($params) == 1) |
|
1677 | - $return[$row['id_member']] = $row; |
|
1758 | + if (count($params) == 1) { |
|
1759 | + $return[$row['id_member']] = $row; |
|
1760 | + } |
|
1678 | 1761 | |
1679 | 1762 | // More than 1? knock yourself out... |
1680 | 1763 | else |
1681 | 1764 | { |
1682 | - if (!isset($return[$row['id_member']])) |
|
1683 | - $return[$row['id_member']] = array(); |
|
1765 | + if (!isset($return[$row['id_member']])) { |
|
1766 | + $return[$row['id_member']] = array(); |
|
1767 | + } |
|
1684 | 1768 | |
1685 | 1769 | $return[$row['id_member']][$row['variable']] = $row; |
1686 | 1770 | } |
@@ -1714,8 +1798,9 @@ discard block |
||
1714 | 1798 | global $context; |
1715 | 1799 | |
1716 | 1800 | // Don't know any browser! |
1717 | - if (empty($context['browser'])) |
|
1718 | - detectBrowser(); |
|
1801 | + if (empty($context['browser'])) { |
|
1802 | + detectBrowser(); |
|
1803 | + } |
|
1719 | 1804 | |
1720 | 1805 | return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false; |
1721 | 1806 | } |
@@ -1733,8 +1818,9 @@ discard block |
||
1733 | 1818 | global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled; |
1734 | 1819 | |
1735 | 1820 | // The theme was specified by parameter. |
1736 | - if (!empty($id_theme)) |
|
1737 | - $id_theme = (int) $id_theme; |
|
1821 | + if (!empty($id_theme)) { |
|
1822 | + $id_theme = (int) $id_theme; |
|
1823 | + } |
|
1738 | 1824 | // The theme was specified by REQUEST. |
1739 | 1825 | elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
1740 | 1826 | { |
@@ -1742,32 +1828,38 @@ discard block |
||
1742 | 1828 | $_SESSION['id_theme'] = $id_theme; |
1743 | 1829 | } |
1744 | 1830 | // The theme was specified by REQUEST... previously. |
1745 | - elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
|
1746 | - $id_theme = (int) $_SESSION['id_theme']; |
|
1831 | + elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) { |
|
1832 | + $id_theme = (int) $_SESSION['id_theme']; |
|
1833 | + } |
|
1747 | 1834 | // The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.) |
1748 | - elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) |
|
1749 | - $id_theme = $user_info['theme']; |
|
1835 | + elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) { |
|
1836 | + $id_theme = $user_info['theme']; |
|
1837 | + } |
|
1750 | 1838 | // The theme was specified by the board. |
1751 | - elseif (!empty($board_info['theme'])) |
|
1752 | - $id_theme = $board_info['theme']; |
|
1839 | + elseif (!empty($board_info['theme'])) { |
|
1840 | + $id_theme = $board_info['theme']; |
|
1841 | + } |
|
1753 | 1842 | // The theme is the forum's default. |
1754 | - else |
|
1755 | - $id_theme = $modSettings['theme_guests']; |
|
1843 | + else { |
|
1844 | + $id_theme = $modSettings['theme_guests']; |
|
1845 | + } |
|
1756 | 1846 | |
1757 | 1847 | // Verify the id_theme... no foul play. |
1758 | 1848 | // Always allow the board specific theme, if they are overriding. |
1759 | - if (!empty($board_info['theme']) && $board_info['override_theme']) |
|
1760 | - $id_theme = $board_info['theme']; |
|
1849 | + if (!empty($board_info['theme']) && $board_info['override_theme']) { |
|
1850 | + $id_theme = $board_info['theme']; |
|
1851 | + } |
|
1761 | 1852 | // If they have specified a particular theme to use with SSI allow it to be used. |
1762 | - elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) |
|
1763 | - $id_theme = (int) $id_theme; |
|
1764 | - elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
1853 | + elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) { |
|
1854 | + $id_theme = (int) $id_theme; |
|
1855 | + } elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
1765 | 1856 | { |
1766 | 1857 | $themes = explode(',', $modSettings['enableThemes']); |
1767 | - if (!in_array($id_theme, $themes)) |
|
1768 | - $id_theme = $modSettings['theme_guests']; |
|
1769 | - else |
|
1770 | - $id_theme = (int) $id_theme; |
|
1858 | + if (!in_array($id_theme, $themes)) { |
|
1859 | + $id_theme = $modSettings['theme_guests']; |
|
1860 | + } else { |
|
1861 | + $id_theme = (int) $id_theme; |
|
1862 | + } |
|
1771 | 1863 | } |
1772 | 1864 | |
1773 | 1865 | // Allow mod authors the option to override the theme id for custom page themes |
@@ -1779,18 +1871,19 @@ discard block |
||
1779 | 1871 | $member = empty($user_info['id']) ? -1 : $user_info['id']; |
1780 | 1872 | |
1781 | 1873 | // Disable image proxy if we don't have SSL enabled |
1782 | - if (empty($modSettings['force_ssl'])) |
|
1783 | - $image_proxy_enabled = false; |
|
1874 | + if (empty($modSettings['force_ssl'])) { |
|
1875 | + $image_proxy_enabled = false; |
|
1876 | + } |
|
1784 | 1877 | |
1785 | 1878 | 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']) |
1786 | 1879 | { |
1787 | 1880 | $themeData = $temp; |
1788 | 1881 | $flag = true; |
1882 | + } elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) { |
|
1883 | + $themeData = $temp + array($member => array()); |
|
1884 | + } else { |
|
1885 | + $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
1789 | 1886 | } |
1790 | - elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) |
|
1791 | - $themeData = $temp + array($member => array()); |
|
1792 | - else |
|
1793 | - $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
1794 | 1887 | |
1795 | 1888 | if (empty($flag)) |
1796 | 1889 | { |
@@ -1810,31 +1903,37 @@ discard block |
||
1810 | 1903 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
1811 | 1904 | { |
1812 | 1905 | // There are just things we shouldn't be able to change as members. |
1813 | - 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'))) |
|
1814 | - continue; |
|
1906 | + 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'))) { |
|
1907 | + continue; |
|
1908 | + } |
|
1815 | 1909 | |
1816 | 1910 | // If this is the theme_dir of the default theme, store it. |
1817 | - if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) |
|
1818 | - $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
1911 | + if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) { |
|
1912 | + $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
1913 | + } |
|
1819 | 1914 | |
1820 | 1915 | // If this isn't set yet, is a theme option, or is not the default theme.. |
1821 | - if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') |
|
1822 | - $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
1916 | + if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') { |
|
1917 | + $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
1918 | + } |
|
1823 | 1919 | } |
1824 | 1920 | $smcFunc['db_free_result']($result); |
1825 | 1921 | |
1826 | - if (!empty($themeData[-1])) |
|
1827 | - foreach ($themeData[-1] as $k => $v) |
|
1922 | + if (!empty($themeData[-1])) { |
|
1923 | + foreach ($themeData[-1] as $k => $v) |
|
1828 | 1924 | { |
1829 | 1925 | if (!isset($themeData[$member][$k])) |
1830 | 1926 | $themeData[$member][$k] = $v; |
1927 | + } |
|
1831 | 1928 | } |
1832 | 1929 | |
1833 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
1834 | - cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
1930 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
1931 | + cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
1932 | + } |
|
1835 | 1933 | // Only if we didn't already load that part of the cache... |
1836 | - elseif (!isset($temp)) |
|
1837 | - cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
1934 | + elseif (!isset($temp)) { |
|
1935 | + cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
1936 | + } |
|
1838 | 1937 | } |
1839 | 1938 | |
1840 | 1939 | $settings = $themeData[0]; |
@@ -1851,17 +1950,20 @@ discard block |
||
1851 | 1950 | $settings['template_dirs'][] = $settings['theme_dir']; |
1852 | 1951 | |
1853 | 1952 | // Based on theme (if there is one). |
1854 | - if (!empty($settings['base_theme_dir'])) |
|
1855 | - $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
1953 | + if (!empty($settings['base_theme_dir'])) { |
|
1954 | + $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
1955 | + } |
|
1856 | 1956 | |
1857 | 1957 | // Lastly the default theme. |
1858 | - if ($settings['theme_dir'] != $settings['default_theme_dir']) |
|
1859 | - $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
1958 | + if ($settings['theme_dir'] != $settings['default_theme_dir']) { |
|
1959 | + $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
1960 | + } |
|
1860 | 1961 | } |
1861 | 1962 | |
1862 | 1963 | |
1863 | - if (!$initialize) |
|
1864 | - return; |
|
1964 | + if (!$initialize) { |
|
1965 | + return; |
|
1966 | + } |
|
1865 | 1967 | |
1866 | 1968 | // Check to see if we're forcing SSL |
1867 | 1969 | if (!empty($modSettings['force_ssl']) && empty($maintenance) && |
@@ -1882,8 +1984,9 @@ discard block |
||
1882 | 1984 | $detected_url = httpsOn() ? 'https://' : 'http://'; |
1883 | 1985 | $detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']; |
1884 | 1986 | $temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')); |
1885 | - if ($temp != '/') |
|
1886 | - $detected_url .= $temp; |
|
1987 | + if ($temp != '/') { |
|
1988 | + $detected_url .= $temp; |
|
1989 | + } |
|
1887 | 1990 | } |
1888 | 1991 | if (isset($detected_url) && $detected_url != $boardurl) |
1889 | 1992 | { |
@@ -1895,8 +1998,9 @@ discard block |
||
1895 | 1998 | foreach ($aliases as $alias) |
1896 | 1999 | { |
1897 | 2000 | // Rip off all the boring parts, spaces, etc. |
1898 | - if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) |
|
1899 | - $do_fix = true; |
|
2001 | + if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) { |
|
2002 | + $do_fix = true; |
|
2003 | + } |
|
1900 | 2004 | } |
1901 | 2005 | } |
1902 | 2006 | |
@@ -1904,21 +2008,23 @@ discard block |
||
1904 | 2008 | if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI') |
1905 | 2009 | { |
1906 | 2010 | // Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;). |
1907 | - if (empty($_GET)) |
|
1908 | - redirectexit('wwwRedirect'); |
|
1909 | - else |
|
2011 | + if (empty($_GET)) { |
|
2012 | + redirectexit('wwwRedirect'); |
|
2013 | + } else |
|
1910 | 2014 | { |
1911 | 2015 | $k = key($_GET); |
1912 | 2016 | $v = current($_GET); |
1913 | 2017 | |
1914 | - if ($k != 'wwwRedirect') |
|
1915 | - redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
2018 | + if ($k != 'wwwRedirect') { |
|
2019 | + redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
2020 | + } |
|
1916 | 2021 | } |
1917 | 2022 | } |
1918 | 2023 | |
1919 | 2024 | // #3 is just a check for SSL... |
1920 | - if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) |
|
1921 | - $do_fix = true; |
|
2025 | + if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) { |
|
2026 | + $do_fix = true; |
|
2027 | + } |
|
1922 | 2028 | |
1923 | 2029 | // Okay, #4 - perhaps it's an IP address? We're gonna want to use that one, then. (assuming it's the IP or something...) |
1924 | 2030 | if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1) |
@@ -1953,8 +2059,9 @@ discard block |
||
1953 | 2059 | $board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl)); |
1954 | 2060 | } |
1955 | 2061 | } |
1956 | - foreach ($context['linktree'] as $k => $dummy) |
|
1957 | - $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
2062 | + foreach ($context['linktree'] as $k => $dummy) { |
|
2063 | + $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
2064 | + } |
|
1958 | 2065 | } |
1959 | 2066 | } |
1960 | 2067 | // Set up the contextual user array. |
@@ -1973,10 +2080,11 @@ discard block |
||
1973 | 2080 | 'email' => $user_info['email'], |
1974 | 2081 | 'ignoreusers' => $user_info['ignoreusers'], |
1975 | 2082 | ); |
1976 | - if (!$context['user']['is_guest']) |
|
1977 | - $context['user']['name'] = $user_info['name']; |
|
1978 | - elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) |
|
1979 | - $context['user']['name'] = $txt['guest_title']; |
|
2083 | + if (!$context['user']['is_guest']) { |
|
2084 | + $context['user']['name'] = $user_info['name']; |
|
2085 | + } elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) { |
|
2086 | + $context['user']['name'] = $txt['guest_title']; |
|
2087 | + } |
|
1980 | 2088 | |
1981 | 2089 | // Determine the current smiley set. |
1982 | 2090 | $smiley_sets_known = explode(',', $modSettings['smiley_sets_known']); |
@@ -1990,8 +2098,7 @@ discard block |
||
1990 | 2098 | |
1991 | 2099 | // Determine global default smiley set extension |
1992 | 2100 | $context['user']['smiley_set_default_ext'] = $smiley_sets_exts[array_search($modSettings['smiley_sets_default'], $smiley_sets_known)]; |
1993 | - } |
|
1994 | - else |
|
2101 | + } else |
|
1995 | 2102 | { |
1996 | 2103 | // What to do when there is no $user_info (e.g., an error very early in the login process) |
1997 | 2104 | $context['user'] = array( |
@@ -2025,18 +2132,24 @@ discard block |
||
2025 | 2132 | } |
2026 | 2133 | |
2027 | 2134 | // Some basic information... |
2028 | - if (!isset($context['html_headers'])) |
|
2029 | - $context['html_headers'] = ''; |
|
2030 | - if (!isset($context['javascript_files'])) |
|
2031 | - $context['javascript_files'] = array(); |
|
2032 | - if (!isset($context['css_files'])) |
|
2033 | - $context['css_files'] = array(); |
|
2034 | - if (!isset($context['css_header'])) |
|
2035 | - $context['css_header'] = array(); |
|
2036 | - if (!isset($context['javascript_inline'])) |
|
2037 | - $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
2038 | - if (!isset($context['javascript_vars'])) |
|
2039 | - $context['javascript_vars'] = array(); |
|
2135 | + if (!isset($context['html_headers'])) { |
|
2136 | + $context['html_headers'] = ''; |
|
2137 | + } |
|
2138 | + if (!isset($context['javascript_files'])) { |
|
2139 | + $context['javascript_files'] = array(); |
|
2140 | + } |
|
2141 | + if (!isset($context['css_files'])) { |
|
2142 | + $context['css_files'] = array(); |
|
2143 | + } |
|
2144 | + if (!isset($context['css_header'])) { |
|
2145 | + $context['css_header'] = array(); |
|
2146 | + } |
|
2147 | + if (!isset($context['javascript_inline'])) { |
|
2148 | + $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
2149 | + } |
|
2150 | + if (!isset($context['javascript_vars'])) { |
|
2151 | + $context['javascript_vars'] = array(); |
|
2152 | + } |
|
2040 | 2153 | |
2041 | 2154 | $context['login_url'] = $scripturl . '?action=login2'; |
2042 | 2155 | $context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | '; |
@@ -2048,16 +2161,18 @@ discard block |
||
2048 | 2161 | $context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null; |
2049 | 2162 | $context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null; |
2050 | 2163 | $context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3; |
2051 | - if (isset($modSettings['load_average'])) |
|
2052 | - $context['load_average'] = $modSettings['load_average']; |
|
2164 | + if (isset($modSettings['load_average'])) { |
|
2165 | + $context['load_average'] = $modSettings['load_average']; |
|
2166 | + } |
|
2053 | 2167 | |
2054 | 2168 | // Detect the browser. This is separated out because it's also used in attachment downloads |
2055 | 2169 | detectBrowser(); |
2056 | 2170 | |
2057 | 2171 | // Set the top level linktree up. |
2058 | 2172 | // Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet... |
2059 | - if (empty($context['linktree'])) |
|
2060 | - $context['linktree'] = array(); |
|
2173 | + if (empty($context['linktree'])) { |
|
2174 | + $context['linktree'] = array(); |
|
2175 | + } |
|
2061 | 2176 | array_unshift($context['linktree'], array( |
2062 | 2177 | 'url' => $scripturl, |
2063 | 2178 | 'name' => $context['forum_name_html_safe'] |
@@ -2066,8 +2181,9 @@ discard block |
||
2066 | 2181 | // This allows sticking some HTML on the page output - useful for controls. |
2067 | 2182 | $context['insert_after_template'] = ''; |
2068 | 2183 | |
2069 | - if (!isset($txt)) |
|
2070 | - $txt = array(); |
|
2184 | + if (!isset($txt)) { |
|
2185 | + $txt = array(); |
|
2186 | + } |
|
2071 | 2187 | |
2072 | 2188 | $simpleActions = array( |
2073 | 2189 | 'findmember', |
@@ -2113,9 +2229,10 @@ discard block |
||
2113 | 2229 | |
2114 | 2230 | // See if theres any extra param to check. |
2115 | 2231 | $requiresXML = false; |
2116 | - foreach ($extraParams as $key => $extra) |
|
2117 | - if (isset($_REQUEST[$extra])) |
|
2232 | + foreach ($extraParams as $key => $extra) { |
|
2233 | + if (isset($_REQUEST[$extra])) |
|
2118 | 2234 | $requiresXML = true; |
2235 | + } |
|
2119 | 2236 | |
2120 | 2237 | // Output is fully XML, so no need for the index template. |
2121 | 2238 | if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML)) |
@@ -2130,37 +2247,39 @@ discard block |
||
2130 | 2247 | { |
2131 | 2248 | loadLanguage('index+Modifications'); |
2132 | 2249 | $context['template_layers'] = array(); |
2133 | - } |
|
2134 | - |
|
2135 | - else |
|
2250 | + } else |
|
2136 | 2251 | { |
2137 | 2252 | // Custom templates to load, or just default? |
2138 | - if (isset($settings['theme_templates'])) |
|
2139 | - $templates = explode(',', $settings['theme_templates']); |
|
2140 | - else |
|
2141 | - $templates = array('index'); |
|
2253 | + if (isset($settings['theme_templates'])) { |
|
2254 | + $templates = explode(',', $settings['theme_templates']); |
|
2255 | + } else { |
|
2256 | + $templates = array('index'); |
|
2257 | + } |
|
2142 | 2258 | |
2143 | 2259 | // Load each template... |
2144 | - foreach ($templates as $template) |
|
2145 | - loadTemplate($template); |
|
2260 | + foreach ($templates as $template) { |
|
2261 | + loadTemplate($template); |
|
2262 | + } |
|
2146 | 2263 | |
2147 | 2264 | // ...and attempt to load their associated language files. |
2148 | 2265 | $required_files = implode('+', array_merge($templates, array('Modifications'))); |
2149 | 2266 | loadLanguage($required_files, '', false); |
2150 | 2267 | |
2151 | 2268 | // Custom template layers? |
2152 | - if (isset($settings['theme_layers'])) |
|
2153 | - $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
2154 | - else |
|
2155 | - $context['template_layers'] = array('html', 'body'); |
|
2269 | + if (isset($settings['theme_layers'])) { |
|
2270 | + $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
2271 | + } else { |
|
2272 | + $context['template_layers'] = array('html', 'body'); |
|
2273 | + } |
|
2156 | 2274 | } |
2157 | 2275 | |
2158 | 2276 | // Initialize the theme. |
2159 | 2277 | loadSubTemplate('init', 'ignore'); |
2160 | 2278 | |
2161 | 2279 | // Allow overriding the board wide time/number formats. |
2162 | - if (empty($user_settings['time_format']) && !empty($txt['time_format'])) |
|
2163 | - $user_info['time_format'] = $txt['time_format']; |
|
2280 | + if (empty($user_settings['time_format']) && !empty($txt['time_format'])) { |
|
2281 | + $user_info['time_format'] = $txt['time_format']; |
|
2282 | + } |
|
2164 | 2283 | |
2165 | 2284 | // Set the character set from the template. |
2166 | 2285 | $context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']; |
@@ -2168,12 +2287,14 @@ discard block |
||
2168 | 2287 | $context['right_to_left'] = !empty($txt['lang_rtl']); |
2169 | 2288 | |
2170 | 2289 | // Guests may still need a name. |
2171 | - if ($context['user']['is_guest'] && empty($context['user']['name'])) |
|
2172 | - $context['user']['name'] = $txt['guest_title']; |
|
2290 | + if ($context['user']['is_guest'] && empty($context['user']['name'])) { |
|
2291 | + $context['user']['name'] = $txt['guest_title']; |
|
2292 | + } |
|
2173 | 2293 | |
2174 | 2294 | // Any theme-related strings that need to be loaded? |
2175 | - if (!empty($settings['require_theme_strings'])) |
|
2176 | - loadLanguage('ThemeStrings', '', false); |
|
2295 | + if (!empty($settings['require_theme_strings'])) { |
|
2296 | + loadLanguage('ThemeStrings', '', false); |
|
2297 | + } |
|
2177 | 2298 | |
2178 | 2299 | // Make a special URL for the language. |
2179 | 2300 | $settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']); |
@@ -2184,8 +2305,9 @@ discard block |
||
2184 | 2305 | // Here is my luvly Responsive CSS |
2185 | 2306 | loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true, 'order_pos' => 9000), 'smf_responsive'); |
2186 | 2307 | |
2187 | - if ($context['right_to_left']) |
|
2188 | - loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl'); |
|
2308 | + if ($context['right_to_left']) { |
|
2309 | + loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl'); |
|
2310 | + } |
|
2189 | 2311 | |
2190 | 2312 | // We allow theme variants, because we're cool. |
2191 | 2313 | $context['theme_variant'] = ''; |
@@ -2193,14 +2315,17 @@ discard block |
||
2193 | 2315 | if (!empty($settings['theme_variants'])) |
2194 | 2316 | { |
2195 | 2317 | // Overriding - for previews and that ilk. |
2196 | - if (!empty($_REQUEST['variant'])) |
|
2197 | - $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
2318 | + if (!empty($_REQUEST['variant'])) { |
|
2319 | + $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
2320 | + } |
|
2198 | 2321 | // User selection? |
2199 | - if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) |
|
2200 | - $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
2322 | + if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) { |
|
2323 | + $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
2324 | + } |
|
2201 | 2325 | // If not a user variant, select the default. |
2202 | - if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) |
|
2203 | - $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
2326 | + if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) { |
|
2327 | + $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
2328 | + } |
|
2204 | 2329 | |
2205 | 2330 | // Do this to keep things easier in the templates. |
2206 | 2331 | $context['theme_variant'] = '_' . $context['theme_variant']; |
@@ -2209,20 +2334,23 @@ discard block |
||
2209 | 2334 | if (!empty($context['theme_variant'])) |
2210 | 2335 | { |
2211 | 2336 | loadCSSFile('index' . $context['theme_variant'] . '.css', array('order_pos' => 300), 'smf_index' . $context['theme_variant']); |
2212 | - if ($context['right_to_left']) |
|
2213 | - loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']); |
|
2337 | + if ($context['right_to_left']) { |
|
2338 | + loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']); |
|
2339 | + } |
|
2214 | 2340 | } |
2215 | 2341 | } |
2216 | 2342 | |
2217 | 2343 | // Let's be compatible with old themes! |
2218 | - if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) |
|
2219 | - $context['template_layers'] = array('main'); |
|
2344 | + if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) { |
|
2345 | + $context['template_layers'] = array('main'); |
|
2346 | + } |
|
2220 | 2347 | |
2221 | 2348 | $context['tabindex'] = 1; |
2222 | 2349 | |
2223 | 2350 | // Compatibility. |
2224 | - if (!isset($settings['theme_version'])) |
|
2225 | - $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
2351 | + if (!isset($settings['theme_version'])) { |
|
2352 | + $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
2353 | + } |
|
2226 | 2354 | |
2227 | 2355 | // Default JS variables for use in every theme |
2228 | 2356 | $context['javascript_vars'] = array( |
@@ -2245,18 +2373,18 @@ discard block |
||
2245 | 2373 | ); |
2246 | 2374 | |
2247 | 2375 | // Add the JQuery library to the list of files to load. |
2248 | - if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') |
|
2249 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2250 | - |
|
2251 | - elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') |
|
2252 | - loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery'); |
|
2253 | - |
|
2254 | - elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') |
|
2255 | - loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
2376 | + if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') { |
|
2377 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2378 | + } elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') { |
|
2379 | + loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery'); |
|
2380 | + } elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') { |
|
2381 | + loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
2382 | + } |
|
2256 | 2383 | |
2257 | 2384 | // Auto loading? template_javascript() will take care of the local half of this. |
2258 | - else |
|
2259 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2385 | + else { |
|
2386 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2387 | + } |
|
2260 | 2388 | |
2261 | 2389 | // Queue our JQuery plugins! |
2262 | 2390 | loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins'); |
@@ -2279,12 +2407,12 @@ discard block |
||
2279 | 2407 | require_once($sourcedir . '/ScheduledTasks.php'); |
2280 | 2408 | |
2281 | 2409 | // What to do, what to do?! |
2282 | - if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) |
|
2283 | - AutoTask(); |
|
2284 | - else |
|
2285 | - ReduceMailQueue(); |
|
2286 | - } |
|
2287 | - else |
|
2410 | + if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) { |
|
2411 | + AutoTask(); |
|
2412 | + } else { |
|
2413 | + ReduceMailQueue(); |
|
2414 | + } |
|
2415 | + } else |
|
2288 | 2416 | { |
2289 | 2417 | $type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq'; |
2290 | 2418 | $ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time']; |
@@ -2335,8 +2463,9 @@ discard block |
||
2335 | 2463 | foreach ($theme_includes as $include) |
2336 | 2464 | { |
2337 | 2465 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
2338 | - if (file_exists($include)) |
|
2339 | - require_once($include); |
|
2466 | + if (file_exists($include)) { |
|
2467 | + require_once($include); |
|
2468 | + } |
|
2340 | 2469 | } |
2341 | 2470 | } |
2342 | 2471 | |
@@ -2366,16 +2495,19 @@ discard block |
||
2366 | 2495 | // Do any style sheets first, cause we're easy with those. |
2367 | 2496 | if (!empty($style_sheets)) |
2368 | 2497 | { |
2369 | - if (!is_array($style_sheets)) |
|
2370 | - $style_sheets = array($style_sheets); |
|
2498 | + if (!is_array($style_sheets)) { |
|
2499 | + $style_sheets = array($style_sheets); |
|
2500 | + } |
|
2371 | 2501 | |
2372 | - foreach ($style_sheets as $sheet) |
|
2373 | - loadCSSFile($sheet . '.css', array(), $sheet); |
|
2502 | + foreach ($style_sheets as $sheet) { |
|
2503 | + loadCSSFile($sheet . '.css', array(), $sheet); |
|
2504 | + } |
|
2374 | 2505 | } |
2375 | 2506 | |
2376 | 2507 | // No template to load? |
2377 | - if ($template_name === false) |
|
2378 | - return true; |
|
2508 | + if ($template_name === false) { |
|
2509 | + return true; |
|
2510 | + } |
|
2379 | 2511 | |
2380 | 2512 | $loaded = false; |
2381 | 2513 | foreach ($settings['template_dirs'] as $template_dir) |
@@ -2390,12 +2522,14 @@ discard block |
||
2390 | 2522 | |
2391 | 2523 | if ($loaded) |
2392 | 2524 | { |
2393 | - if ($db_show_debug === true) |
|
2394 | - $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
2525 | + if ($db_show_debug === true) { |
|
2526 | + $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
2527 | + } |
|
2395 | 2528 | |
2396 | 2529 | // If they have specified an initialization function for this template, go ahead and call it now. |
2397 | - if (function_exists('template_' . $template_name . '_init')) |
|
2398 | - call_user_func('template_' . $template_name . '_init'); |
|
2530 | + if (function_exists('template_' . $template_name . '_init')) { |
|
2531 | + call_user_func('template_' . $template_name . '_init'); |
|
2532 | + } |
|
2399 | 2533 | } |
2400 | 2534 | // Hmmm... doesn't exist?! I don't suppose the directory is wrong, is it? |
2401 | 2535 | elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default')) |
@@ -2415,13 +2549,14 @@ discard block |
||
2415 | 2549 | loadTemplate($template_name); |
2416 | 2550 | } |
2417 | 2551 | // Cause an error otherwise. |
2418 | - elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) |
|
2419 | - fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
2420 | - elseif ($fatal) |
|
2421 | - 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')); |
|
2422 | - else |
|
2423 | - return false; |
|
2424 | -} |
|
2552 | + elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) { |
|
2553 | + fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
2554 | + } elseif ($fatal) { |
|
2555 | + 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')); |
|
2556 | + } else { |
|
2557 | + return false; |
|
2558 | + } |
|
2559 | + } |
|
2425 | 2560 | |
2426 | 2561 | /** |
2427 | 2562 | * Load a sub-template. |
@@ -2439,17 +2574,19 @@ discard block |
||
2439 | 2574 | { |
2440 | 2575 | global $context, $txt, $db_show_debug; |
2441 | 2576 | |
2442 | - if ($db_show_debug === true) |
|
2443 | - $context['debug']['sub_templates'][] = $sub_template_name; |
|
2577 | + if ($db_show_debug === true) { |
|
2578 | + $context['debug']['sub_templates'][] = $sub_template_name; |
|
2579 | + } |
|
2444 | 2580 | |
2445 | 2581 | // Figure out what the template function is named. |
2446 | 2582 | $theme_function = 'template_' . $sub_template_name; |
2447 | - if (function_exists($theme_function)) |
|
2448 | - $theme_function(); |
|
2449 | - elseif ($fatal === false) |
|
2450 | - fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
2451 | - elseif ($fatal !== 'ignore') |
|
2452 | - 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')); |
|
2583 | + if (function_exists($theme_function)) { |
|
2584 | + $theme_function(); |
|
2585 | + } elseif ($fatal === false) { |
|
2586 | + fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
2587 | + } elseif ($fatal !== 'ignore') { |
|
2588 | + 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')); |
|
2589 | + } |
|
2453 | 2590 | |
2454 | 2591 | // Are we showing debugging for templates? Just make sure not to do it before the doctype... |
2455 | 2592 | if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml'])) |
@@ -2479,8 +2616,9 @@ discard block |
||
2479 | 2616 | { |
2480 | 2617 | global $settings, $context, $modSettings; |
2481 | 2618 | |
2482 | - if (empty($context['css_files_order'])) |
|
2483 | - $context['css_files_order'] = array(); |
|
2619 | + if (empty($context['css_files_order'])) { |
|
2620 | + $context['css_files_order'] = array(); |
|
2621 | + } |
|
2484 | 2622 | |
2485 | 2623 | $params['seed'] = (!array_key_exists('seed', $params) || (array_key_exists('seed', $params) && $params['seed'] === true)) ? (array_key_exists('browser_cache', $modSettings) ? $modSettings['browser_cache'] : '') : (is_string($params['seed']) ? ($params['seed'] = $params['seed'][0] === '?' ? $params['seed'] : '?' . $params['seed']) : ''); |
2486 | 2624 | $params['force_current'] = isset($params['force_current']) ? $params['force_current'] : false; |
@@ -2491,8 +2629,9 @@ discard block |
||
2491 | 2629 | $params['order_pos'] = isset($params['order_pos']) ? (int) $params['order_pos'] : 3000; |
2492 | 2630 | |
2493 | 2631 | // If this is an external file, automatically set this to false. |
2494 | - if (!empty($params['external'])) |
|
2495 | - $params['minimize'] = false; |
|
2632 | + if (!empty($params['external'])) { |
|
2633 | + $params['minimize'] = false; |
|
2634 | + } |
|
2496 | 2635 | |
2497 | 2636 | // Account for shorthand like admin.css?alp21 filenames |
2498 | 2637 | $has_seed = strpos($fileName, '.css?'); |
@@ -2509,16 +2648,12 @@ discard block |
||
2509 | 2648 | { |
2510 | 2649 | $fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2511 | 2650 | $filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2512 | - } |
|
2513 | - |
|
2514 | - else |
|
2651 | + } else |
|
2515 | 2652 | { |
2516 | 2653 | $fileUrl = false; |
2517 | 2654 | $filePath = false; |
2518 | 2655 | } |
2519 | - } |
|
2520 | - |
|
2521 | - else |
|
2656 | + } else |
|
2522 | 2657 | { |
2523 | 2658 | $fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2524 | 2659 | $filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2536,16 +2671,18 @@ discard block |
||
2536 | 2671 | if (!empty($fileName)) |
2537 | 2672 | { |
2538 | 2673 | // find a free number/position |
2539 | - while (isset($context['css_files_order'][$params['order_pos']])) |
|
2540 | - $params['order_pos']++; |
|
2674 | + while (isset($context['css_files_order'][$params['order_pos']])) { |
|
2675 | + $params['order_pos']++; |
|
2676 | + } |
|
2541 | 2677 | $context['css_files_order'][$params['order_pos']] = $id; |
2542 | 2678 | |
2543 | 2679 | $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
2544 | 2680 | } |
2545 | 2681 | |
2546 | - if (!empty($context['right_to_left']) && !empty($params['rtl'])) |
|
2547 | - loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
2548 | -} |
|
2682 | + if (!empty($context['right_to_left']) && !empty($params['rtl'])) { |
|
2683 | + loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
2684 | + } |
|
2685 | + } |
|
2549 | 2686 | |
2550 | 2687 | /** |
2551 | 2688 | * Add a block of inline css code to be executed later |
@@ -2562,8 +2699,9 @@ discard block |
||
2562 | 2699 | global $context; |
2563 | 2700 | |
2564 | 2701 | // Gotta add something... |
2565 | - if (empty($css)) |
|
2566 | - return false; |
|
2702 | + if (empty($css)) { |
|
2703 | + return false; |
|
2704 | + } |
|
2567 | 2705 | |
2568 | 2706 | $context['css_header'][] = $css; |
2569 | 2707 | } |
@@ -2599,8 +2737,9 @@ discard block |
||
2599 | 2737 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
2600 | 2738 | |
2601 | 2739 | // If this is an external file, automatically set this to false. |
2602 | - if (!empty($params['external'])) |
|
2603 | - $params['minimize'] = false; |
|
2740 | + if (!empty($params['external'])) { |
|
2741 | + $params['minimize'] = false; |
|
2742 | + } |
|
2604 | 2743 | |
2605 | 2744 | // Account for shorthand like admin.js?alp21 filenames |
2606 | 2745 | $has_seed = strpos($fileName, '.js?'); |
@@ -2617,16 +2756,12 @@ discard block |
||
2617 | 2756 | { |
2618 | 2757 | $fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2619 | 2758 | $filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2620 | - } |
|
2621 | - |
|
2622 | - else |
|
2759 | + } else |
|
2623 | 2760 | { |
2624 | 2761 | $fileUrl = false; |
2625 | 2762 | $filePath = false; |
2626 | 2763 | } |
2627 | - } |
|
2628 | - |
|
2629 | - else |
|
2764 | + } else |
|
2630 | 2765 | { |
2631 | 2766 | $fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2632 | 2767 | $filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2641,9 +2776,10 @@ discard block |
||
2641 | 2776 | } |
2642 | 2777 | |
2643 | 2778 | // Add it to the array for use in the template |
2644 | - if (!empty($fileName)) |
|
2645 | - $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2646 | -} |
|
2779 | + if (!empty($fileName)) { |
|
2780 | + $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2781 | + } |
|
2782 | + } |
|
2647 | 2783 | |
2648 | 2784 | /** |
2649 | 2785 | * Add a Javascript variable for output later (for feeding text strings and similar to JS) |
@@ -2657,9 +2793,10 @@ discard block |
||
2657 | 2793 | { |
2658 | 2794 | global $context; |
2659 | 2795 | |
2660 | - if (!empty($key) && (!empty($value) || $value === '0')) |
|
2661 | - $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
2662 | -} |
|
2796 | + if (!empty($key) && (!empty($value) || $value === '0')) { |
|
2797 | + $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
2798 | + } |
|
2799 | + } |
|
2663 | 2800 | |
2664 | 2801 | /** |
2665 | 2802 | * Add a block of inline Javascript code to be executed later |
@@ -2676,8 +2813,9 @@ discard block |
||
2676 | 2813 | { |
2677 | 2814 | global $context; |
2678 | 2815 | |
2679 | - if (empty($javascript)) |
|
2680 | - return false; |
|
2816 | + if (empty($javascript)) { |
|
2817 | + return false; |
|
2818 | + } |
|
2681 | 2819 | |
2682 | 2820 | $context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript; |
2683 | 2821 | } |
@@ -2698,15 +2836,18 @@ discard block |
||
2698 | 2836 | static $already_loaded = array(); |
2699 | 2837 | |
2700 | 2838 | // Default to the user's language. |
2701 | - if ($lang == '') |
|
2702 | - $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
2839 | + if ($lang == '') { |
|
2840 | + $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
2841 | + } |
|
2703 | 2842 | |
2704 | 2843 | // Do we want the English version of language file as fallback? |
2705 | - if (empty($modSettings['disable_language_fallback']) && $lang != 'english') |
|
2706 | - loadLanguage($template_name, 'english', false); |
|
2844 | + if (empty($modSettings['disable_language_fallback']) && $lang != 'english') { |
|
2845 | + loadLanguage($template_name, 'english', false); |
|
2846 | + } |
|
2707 | 2847 | |
2708 | - if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) |
|
2709 | - return $lang; |
|
2848 | + if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) { |
|
2849 | + return $lang; |
|
2850 | + } |
|
2710 | 2851 | |
2711 | 2852 | // Make sure we have $settings - if not we're in trouble and need to find it! |
2712 | 2853 | if (empty($settings['default_theme_dir'])) |
@@ -2717,8 +2858,9 @@ discard block |
||
2717 | 2858 | |
2718 | 2859 | // What theme are we in? |
2719 | 2860 | $theme_name = basename($settings['theme_url']); |
2720 | - if (empty($theme_name)) |
|
2721 | - $theme_name = 'unknown'; |
|
2861 | + if (empty($theme_name)) { |
|
2862 | + $theme_name = 'unknown'; |
|
2863 | + } |
|
2722 | 2864 | |
2723 | 2865 | // For each file open it up and write it out! |
2724 | 2866 | foreach (explode('+', $template_name) as $template) |
@@ -2760,8 +2902,9 @@ discard block |
||
2760 | 2902 | $found = true; |
2761 | 2903 | |
2762 | 2904 | // setlocale is required for basename() & pathinfo() to work properly on the selected language |
2763 | - if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) |
|
2764 | - setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
2905 | + if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) { |
|
2906 | + setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
2907 | + } |
|
2765 | 2908 | |
2766 | 2909 | break; |
2767 | 2910 | } |
@@ -2801,8 +2944,9 @@ discard block |
||
2801 | 2944 | } |
2802 | 2945 | |
2803 | 2946 | // Keep track of what we're up to soldier. |
2804 | - if ($db_show_debug === true) |
|
2805 | - $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
2947 | + if ($db_show_debug === true) { |
|
2948 | + $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
2949 | + } |
|
2806 | 2950 | |
2807 | 2951 | // Remember what we have loaded, and in which language. |
2808 | 2952 | $already_loaded[$template_name] = $lang; |
@@ -2848,8 +2992,9 @@ discard block |
||
2848 | 2992 | ) |
2849 | 2993 | ); |
2850 | 2994 | // In the EXTREMELY unlikely event this happens, give an error message. |
2851 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
2852 | - fatal_lang_error('parent_not_found', 'critical'); |
|
2995 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
2996 | + fatal_lang_error('parent_not_found', 'critical'); |
|
2997 | + } |
|
2853 | 2998 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
2854 | 2999 | { |
2855 | 3000 | if (!isset($boards[$row['id_board']])) |
@@ -2866,8 +3011,8 @@ discard block |
||
2866 | 3011 | ); |
2867 | 3012 | } |
2868 | 3013 | // If a moderator exists for this board, add that moderator for all children too. |
2869 | - if (!empty($row['id_moderator'])) |
|
2870 | - foreach ($boards as $id => $dummy) |
|
3014 | + if (!empty($row['id_moderator'])) { |
|
3015 | + foreach ($boards as $id => $dummy) |
|
2871 | 3016 | { |
2872 | 3017 | $boards[$id]['moderators'][$row['id_moderator']] = array( |
2873 | 3018 | 'id' => $row['id_moderator'], |
@@ -2875,11 +3020,12 @@ discard block |
||
2875 | 3020 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
2876 | 3021 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
2877 | 3022 | ); |
3023 | + } |
|
2878 | 3024 | } |
2879 | 3025 | |
2880 | 3026 | // If a moderator group exists for this board, add that moderator group for all children too |
2881 | - if (!empty($row['id_moderator_group'])) |
|
2882 | - foreach ($boards as $id => $dummy) |
|
3027 | + if (!empty($row['id_moderator_group'])) { |
|
3028 | + foreach ($boards as $id => $dummy) |
|
2883 | 3029 | { |
2884 | 3030 | $boards[$id]['moderator_groups'][$row['id_moderator_group']] = array( |
2885 | 3031 | 'id' => $row['id_moderator_group'], |
@@ -2887,6 +3033,7 @@ discard block |
||
2887 | 3033 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
2888 | 3034 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
2889 | 3035 | ); |
3036 | + } |
|
2890 | 3037 | } |
2891 | 3038 | } |
2892 | 3039 | $smcFunc['db_free_result']($result); |
@@ -2913,23 +3060,27 @@ discard block |
||
2913 | 3060 | if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null) |
2914 | 3061 | { |
2915 | 3062 | // If we don't have our ucwords function defined yet, let's load the settings data. |
2916 | - if (empty($smcFunc['ucwords'])) |
|
2917 | - reloadSettings(); |
|
3063 | + if (empty($smcFunc['ucwords'])) { |
|
3064 | + reloadSettings(); |
|
3065 | + } |
|
2918 | 3066 | |
2919 | 3067 | // If we don't have our theme information yet, let's get it. |
2920 | - if (empty($settings['default_theme_dir'])) |
|
2921 | - loadTheme(0, false); |
|
3068 | + if (empty($settings['default_theme_dir'])) { |
|
3069 | + loadTheme(0, false); |
|
3070 | + } |
|
2922 | 3071 | |
2923 | 3072 | // Default language directories to try. |
2924 | 3073 | $language_directories = array( |
2925 | 3074 | $settings['default_theme_dir'] . '/languages', |
2926 | 3075 | ); |
2927 | - if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) |
|
2928 | - $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
3076 | + if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) { |
|
3077 | + $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
3078 | + } |
|
2929 | 3079 | |
2930 | 3080 | // We possibly have a base theme directory. |
2931 | - if (!empty($settings['base_theme_dir'])) |
|
2932 | - $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
3081 | + if (!empty($settings['base_theme_dir'])) { |
|
3082 | + $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
3083 | + } |
|
2933 | 3084 | |
2934 | 3085 | // Remove any duplicates. |
2935 | 3086 | $language_directories = array_unique($language_directories); |
@@ -2943,20 +3094,21 @@ discard block |
||
2943 | 3094 | foreach ($language_directories as $language_dir) |
2944 | 3095 | { |
2945 | 3096 | // Can't look in here... doesn't exist! |
2946 | - if (!file_exists($language_dir)) |
|
2947 | - continue; |
|
3097 | + if (!file_exists($language_dir)) { |
|
3098 | + continue; |
|
3099 | + } |
|
2948 | 3100 | |
2949 | 3101 | $dir = dir($language_dir); |
2950 | 3102 | while ($entry = $dir->read()) |
2951 | 3103 | { |
2952 | 3104 | // Look for the index language file... For good measure skip any "index.language-utf8.php" files |
2953 | - if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) |
|
2954 | - continue; |
|
2955 | - |
|
2956 | - if (!empty($langList) && !empty($langList[$matches[1]])) |
|
2957 | - $langName = $langList[$matches[1]]; |
|
3105 | + if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) { |
|
3106 | + continue; |
|
3107 | + } |
|
2958 | 3108 | |
2959 | - else |
|
3109 | + if (!empty($langList) && !empty($langList[$matches[1]])) { |
|
3110 | + $langName = $langList[$matches[1]]; |
|
3111 | + } else |
|
2960 | 3112 | { |
2961 | 3113 | $langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' '))); |
2962 | 3114 | |
@@ -2997,12 +3149,14 @@ discard block |
||
2997 | 3149 | } |
2998 | 3150 | |
2999 | 3151 | // Do we need to store the lang list? |
3000 | - if (empty($langList)) |
|
3001 | - updateSettings(array('langList' => $smcFunc['json_encode']($catchLang))); |
|
3152 | + if (empty($langList)) { |
|
3153 | + updateSettings(array('langList' => $smcFunc['json_encode']($catchLang))); |
|
3154 | + } |
|
3002 | 3155 | |
3003 | 3156 | // Let's cash in on this deal. |
3004 | - if (!empty($modSettings['cache_enable'])) |
|
3005 | - cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
3157 | + if (!empty($modSettings['cache_enable'])) { |
|
3158 | + cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
3159 | + } |
|
3006 | 3160 | } |
3007 | 3161 | |
3008 | 3162 | return $context['languages']; |
@@ -3025,8 +3179,9 @@ discard block |
||
3025 | 3179 | global $modSettings, $options, $txt; |
3026 | 3180 | static $censor_vulgar = null, $censor_proper; |
3027 | 3181 | |
3028 | - if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') |
|
3029 | - return $text; |
|
3182 | + if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') { |
|
3183 | + return $text; |
|
3184 | + } |
|
3030 | 3185 | |
3031 | 3186 | // If they haven't yet been loaded, load them. |
3032 | 3187 | if ($censor_vulgar == null) |
@@ -3057,9 +3212,9 @@ discard block |
||
3057 | 3212 | { |
3058 | 3213 | $func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace'; |
3059 | 3214 | $text = $func($censor_vulgar, $censor_proper, $text); |
3215 | + } else { |
|
3216 | + $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
3060 | 3217 | } |
3061 | - else |
|
3062 | - $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
3063 | 3218 | |
3064 | 3219 | return $text; |
3065 | 3220 | } |
@@ -3085,30 +3240,35 @@ discard block |
||
3085 | 3240 | @ini_set('track_errors', '1'); |
3086 | 3241 | |
3087 | 3242 | // Don't include the file more than once, if $once is true. |
3088 | - if ($once && in_array($filename, $templates)) |
|
3089 | - return; |
|
3243 | + if ($once && in_array($filename, $templates)) { |
|
3244 | + return; |
|
3245 | + } |
|
3090 | 3246 | // Add this file to the include list, whether $once is true or not. |
3091 | - else |
|
3092 | - $templates[] = $filename; |
|
3247 | + else { |
|
3248 | + $templates[] = $filename; |
|
3249 | + } |
|
3093 | 3250 | |
3094 | 3251 | |
3095 | 3252 | $file_found = file_exists($filename); |
3096 | 3253 | |
3097 | - if ($once && $file_found) |
|
3098 | - require_once($filename); |
|
3099 | - elseif ($file_found) |
|
3100 | - require($filename); |
|
3254 | + if ($once && $file_found) { |
|
3255 | + require_once($filename); |
|
3256 | + } elseif ($file_found) { |
|
3257 | + require($filename); |
|
3258 | + } |
|
3101 | 3259 | |
3102 | 3260 | if ($file_found !== true) |
3103 | 3261 | { |
3104 | 3262 | ob_end_clean(); |
3105 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
3106 | - @ob_start('ob_gzhandler'); |
|
3107 | - else |
|
3108 | - ob_start(); |
|
3263 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
3264 | + @ob_start('ob_gzhandler'); |
|
3265 | + } else { |
|
3266 | + ob_start(); |
|
3267 | + } |
|
3109 | 3268 | |
3110 | - if (isset($_GET['debug'])) |
|
3111 | - header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3269 | + if (isset($_GET['debug'])) { |
|
3270 | + header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3271 | + } |
|
3112 | 3272 | |
3113 | 3273 | // Don't cache error pages!! |
3114 | 3274 | header('expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -3127,12 +3287,13 @@ discard block |
||
3127 | 3287 | echo '<!DOCTYPE html> |
3128 | 3288 | <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '> |
3129 | 3289 | <head>'; |
3130 | - if (isset($context['character_set'])) |
|
3131 | - echo ' |
|
3290 | + if (isset($context['character_set'])) { |
|
3291 | + echo ' |
|
3132 | 3292 | <meta charset="', $context['character_set'], '">'; |
3293 | + } |
|
3133 | 3294 | |
3134 | - if (!empty($maintenance) && !allowedTo('admin_forum')) |
|
3135 | - echo ' |
|
3295 | + if (!empty($maintenance) && !allowedTo('admin_forum')) { |
|
3296 | + echo ' |
|
3136 | 3297 | <title>', $mtitle, '</title> |
3137 | 3298 | </head> |
3138 | 3299 | <body> |
@@ -3140,8 +3301,8 @@ discard block |
||
3140 | 3301 | ', $mmessage, ' |
3141 | 3302 | </body> |
3142 | 3303 | </html>'; |
3143 | - elseif (!allowedTo('admin_forum')) |
|
3144 | - echo ' |
|
3304 | + } elseif (!allowedTo('admin_forum')) { |
|
3305 | + echo ' |
|
3145 | 3306 | <title>', $txt['template_parse_error'], '</title> |
3146 | 3307 | </head> |
3147 | 3308 | <body> |
@@ -3149,14 +3310,16 @@ discard block |
||
3149 | 3310 | ', $txt['template_parse_error_message'], ' |
3150 | 3311 | </body> |
3151 | 3312 | </html>'; |
3152 | - else |
|
3313 | + } else |
|
3153 | 3314 | { |
3154 | 3315 | $error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
3155 | 3316 | $error_array = error_get_last(); |
3156 | - if (empty($error) && ini_get('track_errors') && !empty($error_array)) |
|
3157 | - $error = $error_array['message']; |
|
3158 | - if (empty($error)) |
|
3159 | - $error = $txt['template_parse_errmsg']; |
|
3317 | + if (empty($error) && ini_get('track_errors') && !empty($error_array)) { |
|
3318 | + $error = $error_array['message']; |
|
3319 | + } |
|
3320 | + if (empty($error)) { |
|
3321 | + $error = $txt['template_parse_errmsg']; |
|
3322 | + } |
|
3160 | 3323 | |
3161 | 3324 | $error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>')); |
3162 | 3325 | |
@@ -3167,11 +3330,12 @@ discard block |
||
3167 | 3330 | <h3>', $txt['template_parse_error'], '</h3> |
3168 | 3331 | ', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
3169 | 3332 | |
3170 | - if (!empty($error)) |
|
3171 | - echo ' |
|
3333 | + if (!empty($error)) { |
|
3334 | + echo ' |
|
3172 | 3335 | <hr> |
3173 | 3336 | |
3174 | 3337 | <div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>'; |
3338 | + } |
|
3175 | 3339 | |
3176 | 3340 | // I know, I know... this is VERY COMPLICATED. Still, it's good. |
3177 | 3341 | if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0) |
@@ -3181,10 +3345,11 @@ discard block |
||
3181 | 3345 | $data2 = preg_split('~\<br( /)?\>~', $data2); |
3182 | 3346 | |
3183 | 3347 | // Fix the PHP code stuff... |
3184 | - if (!isBrowser('gecko')) |
|
3185 | - $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
3186 | - else |
|
3187 | - $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
3348 | + if (!isBrowser('gecko')) { |
|
3349 | + $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
3350 | + } else { |
|
3351 | + $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
3352 | + } |
|
3188 | 3353 | |
3189 | 3354 | // Now we get to work around a bug in PHP where it doesn't escape <br>s! |
3190 | 3355 | $j = -1; |
@@ -3192,8 +3357,9 @@ discard block |
||
3192 | 3357 | { |
3193 | 3358 | $j++; |
3194 | 3359 | |
3195 | - if (substr_count($line, '<br>') == 0) |
|
3196 | - continue; |
|
3360 | + if (substr_count($line, '<br>') == 0) { |
|
3361 | + continue; |
|
3362 | + } |
|
3197 | 3363 | |
3198 | 3364 | $n = substr_count($line, '<br>'); |
3199 | 3365 | for ($i = 0; $i < $n; $i++) |
@@ -3212,38 +3378,42 @@ discard block |
||
3212 | 3378 | // Figure out what the color coding was before... |
3213 | 3379 | $line = max($match[1] - 9, 1); |
3214 | 3380 | $last_line = ''; |
3215 | - for ($line2 = $line - 1; $line2 > 1; $line2--) |
|
3216 | - if (strpos($data2[$line2], '<') !== false) |
|
3381 | + for ($line2 = $line - 1; $line2 > 1; $line2--) { |
|
3382 | + if (strpos($data2[$line2], '<') !== false) |
|
3217 | 3383 | { |
3218 | 3384 | if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0) |
3219 | 3385 | $last_line = $color_match[1]; |
3386 | + } |
|
3220 | 3387 | break; |
3221 | 3388 | } |
3222 | 3389 | |
3223 | 3390 | // Show the relevant lines... |
3224 | 3391 | for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++) |
3225 | 3392 | { |
3226 | - if ($line == $match[1]) |
|
3227 | - echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
3393 | + if ($line == $match[1]) { |
|
3394 | + echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
3395 | + } |
|
3228 | 3396 | |
3229 | 3397 | echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> '; |
3230 | - if (isset($data2[$line]) && $data2[$line] != '') |
|
3231 | - echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
3398 | + if (isset($data2[$line]) && $data2[$line] != '') { |
|
3399 | + echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
3400 | + } |
|
3232 | 3401 | |
3233 | 3402 | if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0) |
3234 | 3403 | { |
3235 | 3404 | $last_line = $color_match[1]; |
3236 | 3405 | echo '</', substr($last_line, 1, 4), '>'; |
3406 | + } elseif ($last_line != '' && strpos($data2[$line], '<') !== false) { |
|
3407 | + $last_line = ''; |
|
3408 | + } elseif ($last_line != '' && $data2[$line] != '') { |
|
3409 | + echo '</', substr($last_line, 1, 4), '>'; |
|
3237 | 3410 | } |
3238 | - elseif ($last_line != '' && strpos($data2[$line], '<') !== false) |
|
3239 | - $last_line = ''; |
|
3240 | - elseif ($last_line != '' && $data2[$line] != '') |
|
3241 | - echo '</', substr($last_line, 1, 4), '>'; |
|
3242 | 3411 | |
3243 | - if ($line == $match[1]) |
|
3244 | - echo '</pre></div><pre style="margin: 0;">'; |
|
3245 | - else |
|
3246 | - echo "\n"; |
|
3412 | + if ($line == $match[1]) { |
|
3413 | + echo '</pre></div><pre style="margin: 0;">'; |
|
3414 | + } else { |
|
3415 | + echo "\n"; |
|
3416 | + } |
|
3247 | 3417 | } |
3248 | 3418 | |
3249 | 3419 | echo '</pre></div>'; |
@@ -3267,8 +3437,9 @@ discard block |
||
3267 | 3437 | global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port, $db_mb4; |
3268 | 3438 | |
3269 | 3439 | // Figure out what type of database we are using. |
3270 | - if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
|
3271 | - $db_type = 'mysql'; |
|
3440 | + if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) { |
|
3441 | + $db_type = 'mysql'; |
|
3442 | + } |
|
3272 | 3443 | |
3273 | 3444 | // Load the file for the database. |
3274 | 3445 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
@@ -3276,11 +3447,13 @@ discard block |
||
3276 | 3447 | $db_options = array(); |
3277 | 3448 | |
3278 | 3449 | // Add in the port if needed |
3279 | - if (!empty($db_port)) |
|
3280 | - $db_options['port'] = $db_port; |
|
3450 | + if (!empty($db_port)) { |
|
3451 | + $db_options['port'] = $db_port; |
|
3452 | + } |
|
3281 | 3453 | |
3282 | - if (!empty($db_mb4)) |
|
3283 | - $db_options['db_mb4'] = $db_mb4; |
|
3454 | + if (!empty($db_mb4)) { |
|
3455 | + $db_options['db_mb4'] = $db_mb4; |
|
3456 | + } |
|
3284 | 3457 | |
3285 | 3458 | // 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. |
3286 | 3459 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
@@ -3299,13 +3472,15 @@ discard block |
||
3299 | 3472 | } |
3300 | 3473 | |
3301 | 3474 | // Safe guard here, if there isn't a valid connection lets put a stop to it. |
3302 | - if (!$db_connection) |
|
3303 | - display_db_error(); |
|
3475 | + if (!$db_connection) { |
|
3476 | + display_db_error(); |
|
3477 | + } |
|
3304 | 3478 | |
3305 | 3479 | // If in SSI mode fix up the prefix. |
3306 | - if (SMF == 'SSI') |
|
3307 | - db_fix_prefix($db_prefix, $db_name); |
|
3308 | -} |
|
3480 | + if (SMF == 'SSI') { |
|
3481 | + db_fix_prefix($db_prefix, $db_name); |
|
3482 | + } |
|
3483 | + } |
|
3309 | 3484 | |
3310 | 3485 | /** |
3311 | 3486 | * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it. |
@@ -3319,14 +3494,16 @@ discard block |
||
3319 | 3494 | global $sourcedir, $cacheAPI, $cache_accelerator, $cache_enable; |
3320 | 3495 | |
3321 | 3496 | // is caching enabled? |
3322 | - if (empty($cache_enable) && empty($overrideCache)) |
|
3323 | - return false; |
|
3497 | + if (empty($cache_enable) && empty($overrideCache)) { |
|
3498 | + return false; |
|
3499 | + } |
|
3324 | 3500 | |
3325 | 3501 | // Not overriding this and we have a cacheAPI, send it back. |
3326 | - if (empty($overrideCache) && is_object($cacheAPI)) |
|
3327 | - return $cacheAPI; |
|
3328 | - elseif (is_null($cacheAPI)) |
|
3329 | - $cacheAPI = false; |
|
3502 | + if (empty($overrideCache) && is_object($cacheAPI)) { |
|
3503 | + return $cacheAPI; |
|
3504 | + } elseif (is_null($cacheAPI)) { |
|
3505 | + $cacheAPI = false; |
|
3506 | + } |
|
3330 | 3507 | |
3331 | 3508 | // Make sure our class is in session. |
3332 | 3509 | require_once($sourcedir . '/Class-CacheAPI.php'); |
@@ -3347,8 +3524,9 @@ discard block |
||
3347 | 3524 | if (!$testAPI->isSupported()) |
3348 | 3525 | { |
3349 | 3526 | // Can we save ourselves? |
3350 | - if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') |
|
3351 | - return loadCacheAccelerator(null, false); |
|
3527 | + if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') { |
|
3528 | + return loadCacheAccelerator(null, false); |
|
3529 | + } |
|
3352 | 3530 | return false; |
3353 | 3531 | } |
3354 | 3532 | |
@@ -3360,9 +3538,9 @@ discard block |
||
3360 | 3538 | { |
3361 | 3539 | $cacheAPI = $testAPI; |
3362 | 3540 | return $cacheAPI; |
3541 | + } else { |
|
3542 | + return $testAPI; |
|
3363 | 3543 | } |
3364 | - else |
|
3365 | - return $testAPI; |
|
3366 | 3544 | } |
3367 | 3545 | } |
3368 | 3546 | |
@@ -3382,8 +3560,9 @@ discard block |
||
3382 | 3560 | |
3383 | 3561 | // @todo Why are we doing this if caching is disabled? |
3384 | 3562 | |
3385 | - if (function_exists('call_integration_hook')) |
|
3386 | - call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
3563 | + if (function_exists('call_integration_hook')) { |
|
3564 | + call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
3565 | + } |
|
3387 | 3566 | |
3388 | 3567 | /* Refresh the cache if either: |
3389 | 3568 | 1. Caching is disabled. |
@@ -3397,16 +3576,19 @@ discard block |
||
3397 | 3576 | require_once($sourcedir . '/' . $file); |
3398 | 3577 | $cache_block = call_user_func_array($function, $params); |
3399 | 3578 | |
3400 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) |
|
3401 | - cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
3579 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) { |
|
3580 | + cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
3581 | + } |
|
3402 | 3582 | } |
3403 | 3583 | |
3404 | 3584 | // Some cached data may need a freshening up after retrieval. |
3405 | - if (!empty($cache_block['post_retri_eval'])) |
|
3406 | - eval($cache_block['post_retri_eval']); |
|
3585 | + if (!empty($cache_block['post_retri_eval'])) { |
|
3586 | + eval($cache_block['post_retri_eval']); |
|
3587 | + } |
|
3407 | 3588 | |
3408 | - if (function_exists('call_integration_hook')) |
|
3409 | - call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
3589 | + if (function_exists('call_integration_hook')) { |
|
3590 | + call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
3591 | + } |
|
3410 | 3592 | |
3411 | 3593 | return $cache_block['data']; |
3412 | 3594 | } |
@@ -3433,8 +3615,9 @@ discard block |
||
3433 | 3615 | global $smcFunc, $cache_enable, $cacheAPI; |
3434 | 3616 | global $cache_hits, $cache_count, $db_show_debug; |
3435 | 3617 | |
3436 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
3437 | - return; |
|
3618 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
3619 | + return; |
|
3620 | + } |
|
3438 | 3621 | |
3439 | 3622 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
3440 | 3623 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3447,12 +3630,14 @@ discard block |
||
3447 | 3630 | $value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value)); |
3448 | 3631 | $cacheAPI->putData($key, $value, $ttl); |
3449 | 3632 | |
3450 | - if (function_exists('call_integration_hook')) |
|
3451 | - call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
3633 | + if (function_exists('call_integration_hook')) { |
|
3634 | + call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
3635 | + } |
|
3452 | 3636 | |
3453 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
3454 | - $cache_hits[$cache_count]['t'] = microtime(true) - $st; |
|
3455 | -} |
|
3637 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
3638 | + $cache_hits[$cache_count]['t'] = microtime(true) - $st; |
|
3639 | + } |
|
3640 | + } |
|
3456 | 3641 | |
3457 | 3642 | /** |
3458 | 3643 | * Gets the value from the cache specified by key, so long as it is not older than ttl seconds. |
@@ -3468,8 +3653,9 @@ discard block |
||
3468 | 3653 | global $smcFunc, $cache_enable, $cacheAPI; |
3469 | 3654 | global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug; |
3470 | 3655 | |
3471 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
3472 | - return; |
|
3656 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
3657 | + return; |
|
3658 | + } |
|
3473 | 3659 | |
3474 | 3660 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
3475 | 3661 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3489,16 +3675,18 @@ discard block |
||
3489 | 3675 | |
3490 | 3676 | if (empty($value)) |
3491 | 3677 | { |
3492 | - if (!is_array($cache_misses)) |
|
3493 | - $cache_misses = array(); |
|
3678 | + if (!is_array($cache_misses)) { |
|
3679 | + $cache_misses = array(); |
|
3680 | + } |
|
3494 | 3681 | |
3495 | 3682 | $cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1; |
3496 | 3683 | $cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get'); |
3497 | 3684 | } |
3498 | 3685 | } |
3499 | 3686 | |
3500 | - if (function_exists('call_integration_hook') && isset($value)) |
|
3501 | - call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
3687 | + if (function_exists('call_integration_hook') && isset($value)) { |
|
3688 | + call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
3689 | + } |
|
3502 | 3690 | |
3503 | 3691 | return empty($value) ? null : (isset($smcFunc['json_decode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true)); |
3504 | 3692 | } |
@@ -3520,8 +3708,9 @@ discard block |
||
3520 | 3708 | global $cacheAPI; |
3521 | 3709 | |
3522 | 3710 | // If we can't get to the API, can't do this. |
3523 | - if (empty($cacheAPI)) |
|
3524 | - return; |
|
3711 | + if (empty($cacheAPI)) { |
|
3712 | + return; |
|
3713 | + } |
|
3525 | 3714 | |
3526 | 3715 | // Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure. |
3527 | 3716 | $cacheAPI->cleanCache($type); |
@@ -3546,8 +3735,9 @@ discard block |
||
3546 | 3735 | global $modSettings, $smcFunc, $image_proxy_enabled, $user_info; |
3547 | 3736 | |
3548 | 3737 | // Come on! |
3549 | - if (empty($data)) |
|
3550 | - return array(); |
|
3738 | + if (empty($data)) { |
|
3739 | + return array(); |
|
3740 | + } |
|
3551 | 3741 | |
3552 | 3742 | // Set a nice default var. |
3553 | 3743 | $image = ''; |
@@ -3555,11 +3745,11 @@ discard block |
||
3555 | 3745 | // Gravatar has been set as mandatory! |
3556 | 3746 | if (!empty($modSettings['gravatarOverride'])) |
3557 | 3747 | { |
3558 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) |
|
3559 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3560 | - |
|
3561 | - else if (!empty($data['email'])) |
|
3562 | - $image = get_gravatar_url($data['email']); |
|
3748 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) { |
|
3749 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3750 | + } else if (!empty($data['email'])) { |
|
3751 | + $image = get_gravatar_url($data['email']); |
|
3752 | + } |
|
3563 | 3753 | } |
3564 | 3754 | |
3565 | 3755 | // Look if the user has a gravatar field or has set an external url as avatar. |
@@ -3571,54 +3761,60 @@ discard block |
||
3571 | 3761 | // Gravatar. |
3572 | 3762 | if (stristr($data['avatar'], 'gravatar://')) |
3573 | 3763 | { |
3574 | - if ($data['avatar'] == 'gravatar://') |
|
3575 | - $image = get_gravatar_url($data['email']); |
|
3576 | - |
|
3577 | - elseif (!empty($modSettings['gravatarAllowExtraEmail'])) |
|
3578 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3764 | + if ($data['avatar'] == 'gravatar://') { |
|
3765 | + $image = get_gravatar_url($data['email']); |
|
3766 | + } elseif (!empty($modSettings['gravatarAllowExtraEmail'])) { |
|
3767 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3768 | + } |
|
3579 | 3769 | } |
3580 | 3770 | |
3581 | 3771 | // External url. |
3582 | 3772 | else |
3583 | 3773 | { |
3584 | 3774 | // Using ssl? |
3585 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) |
|
3586 | - $image = get_proxied_url($data['avatar']); |
|
3775 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) { |
|
3776 | + $image = get_proxied_url($data['avatar']); |
|
3777 | + } |
|
3587 | 3778 | |
3588 | 3779 | // Just a plain external url. |
3589 | - else |
|
3590 | - $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
3780 | + else { |
|
3781 | + $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
3782 | + } |
|
3591 | 3783 | } |
3592 | 3784 | } |
3593 | 3785 | |
3594 | 3786 | // Perhaps this user has an attachment as avatar... |
3595 | - else if (!empty($data['filename'])) |
|
3596 | - $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
3787 | + else if (!empty($data['filename'])) { |
|
3788 | + $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
3789 | + } |
|
3597 | 3790 | |
3598 | 3791 | // Right... no avatar... use our default image. |
3599 | - else |
|
3600 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
3792 | + else { |
|
3793 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
3794 | + } |
|
3601 | 3795 | } |
3602 | 3796 | |
3603 | 3797 | call_integration_hook('integrate_set_avatar_data', array(&$image, &$data)); |
3604 | 3798 | |
3605 | 3799 | // 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. |
3606 | - if (!empty($image)) |
|
3607 | - return array( |
|
3800 | + if (!empty($image)) { |
|
3801 | + return array( |
|
3608 | 3802 | 'name' => !empty($data['avatar']) ? $data['avatar'] : '', |
3609 | 3803 | 'image' => '<img class="avatar" src="' . $image . '" />', |
3610 | 3804 | 'href' => $image, |
3611 | 3805 | 'url' => $image, |
3612 | 3806 | ); |
3807 | + } |
|
3613 | 3808 | |
3614 | 3809 | // Fallback to make life easier for everyone... |
3615 | - else |
|
3616 | - return array( |
|
3810 | + else { |
|
3811 | + return array( |
|
3617 | 3812 | 'name' => '', |
3618 | 3813 | 'image' => '', |
3619 | 3814 | 'href' => '', |
3620 | 3815 | 'url' => '', |
3621 | 3816 | ); |
3622 | -} |
|
3817 | + } |
|
3818 | + } |
|
3623 | 3819 | |
3624 | 3820 | ?> |
3625 | 3821 | \ No newline at end of file |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
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) |
@@ -33,8 +34,8 @@ discard block |
||
33 | 34 | global $smcFunc; |
34 | 35 | |
35 | 36 | // Map some database specific functions, only do this once. |
36 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
37 | - $smcFunc += array( |
|
37 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
38 | + $smcFunc += array( |
|
38 | 39 | 'db_query' => 'smf_db_query', |
39 | 40 | 'db_quote' => 'smf_db_quote', |
40 | 41 | 'db_fetch_assoc' => 'mysqli_fetch_assoc', |
@@ -65,13 +66,16 @@ discard block |
||
65 | 66 | 'db_native_replace' => 'smf_db_native_replace', |
66 | 67 | 'db_cte_support' => 'smf_db_cte_support', |
67 | 68 | ); |
69 | + } |
|
68 | 70 | |
69 | - if (!empty($db_options['persist'])) |
|
70 | - $db_server = 'p:' . $db_server; |
|
71 | + if (!empty($db_options['persist'])) { |
|
72 | + $db_server = 'p:' . $db_server; |
|
73 | + } |
|
71 | 74 | |
72 | 75 | // We are not going to make it very far without these. |
73 | - if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect')) |
|
74 | - display_db_error(); |
|
76 | + if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect')) { |
|
77 | + display_db_error(); |
|
78 | + } |
|
75 | 79 | |
76 | 80 | $connection = mysqli_init(); |
77 | 81 | |
@@ -81,29 +85,33 @@ discard block |
||
81 | 85 | |
82 | 86 | if ($connection) |
83 | 87 | { |
84 | - if (!empty($db_options['port'])) |
|
85 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags); |
|
86 | - else |
|
87 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags); |
|
88 | + if (!empty($db_options['port'])) { |
|
89 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags); |
|
90 | + } else { |
|
91 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags); |
|
92 | + } |
|
88 | 93 | } |
89 | 94 | |
90 | 95 | // Something's wrong, show an error if its fatal (which we assume it is) |
91 | 96 | if ($success === false) |
92 | 97 | { |
93 | - if (!empty($db_options['non_fatal'])) |
|
94 | - return null; |
|
95 | - else |
|
96 | - display_db_error(); |
|
98 | + if (!empty($db_options['non_fatal'])) { |
|
99 | + return null; |
|
100 | + } else { |
|
101 | + display_db_error(); |
|
102 | + } |
|
97 | 103 | } |
98 | 104 | |
99 | 105 | // Select the database, unless told not to |
100 | - if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) |
|
101 | - display_db_error(); |
|
106 | + if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) { |
|
107 | + display_db_error(); |
|
108 | + } |
|
102 | 109 | |
103 | 110 | mysqli_query($connection, 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\''); |
104 | 111 | |
105 | - if (!empty($db_options['db_mb4'])) |
|
106 | - $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
112 | + if (!empty($db_options['db_mb4'])) { |
|
113 | + $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
114 | + } |
|
107 | 115 | |
108 | 116 | return $connection; |
109 | 117 | } |
@@ -174,34 +182,42 @@ discard block |
||
174 | 182 | global $db_callback, $user_info, $db_prefix, $smcFunc; |
175 | 183 | |
176 | 184 | list ($values, $connection) = $db_callback; |
177 | - if (!is_object($connection)) |
|
178 | - display_db_error(); |
|
185 | + if (!is_object($connection)) { |
|
186 | + display_db_error(); |
|
187 | + } |
|
179 | 188 | |
180 | - if ($matches[1] === 'db_prefix') |
|
181 | - return $db_prefix; |
|
189 | + if ($matches[1] === 'db_prefix') { |
|
190 | + return $db_prefix; |
|
191 | + } |
|
182 | 192 | |
183 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
184 | - return $user_info[$matches[1]]; |
|
193 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
194 | + return $user_info[$matches[1]]; |
|
195 | + } |
|
185 | 196 | |
186 | - if ($matches[1] === 'empty') |
|
187 | - return '\'\''; |
|
197 | + if ($matches[1] === 'empty') { |
|
198 | + return '\'\''; |
|
199 | + } |
|
188 | 200 | |
189 | - if (!isset($matches[2])) |
|
190 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
201 | + if (!isset($matches[2])) { |
|
202 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
203 | + } |
|
191 | 204 | |
192 | - if ($matches[1] === 'literal') |
|
193 | - return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
205 | + if ($matches[1] === 'literal') { |
|
206 | + return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
207 | + } |
|
194 | 208 | |
195 | - if (!isset($values[$matches[2]])) |
|
196 | - 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__); |
|
209 | + if (!isset($values[$matches[2]])) { |
|
210 | + 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__); |
|
211 | + } |
|
197 | 212 | |
198 | 213 | $replacement = $values[$matches[2]]; |
199 | 214 | |
200 | 215 | switch ($matches[1]) |
201 | 216 | { |
202 | 217 | case 'int': |
203 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
204 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
218 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
219 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
220 | + } |
|
205 | 221 | return (string) (int) $replacement; |
206 | 222 | break; |
207 | 223 | |
@@ -213,65 +229,73 @@ discard block |
||
213 | 229 | case 'array_int': |
214 | 230 | if (is_array($replacement)) |
215 | 231 | { |
216 | - if (empty($replacement)) |
|
217 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
232 | + if (empty($replacement)) { |
|
233 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
234 | + } |
|
218 | 235 | |
219 | 236 | foreach ($replacement as $key => $value) |
220 | 237 | { |
221 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
222 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
238 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
239 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
240 | + } |
|
223 | 241 | |
224 | 242 | $replacement[$key] = (string) (int) $value; |
225 | 243 | } |
226 | 244 | |
227 | 245 | return implode(', ', $replacement); |
246 | + } else { |
|
247 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
228 | 248 | } |
229 | - else |
|
230 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
231 | 249 | |
232 | 250 | break; |
233 | 251 | |
234 | 252 | case 'array_string': |
235 | 253 | if (is_array($replacement)) |
236 | 254 | { |
237 | - if (empty($replacement)) |
|
238 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
255 | + if (empty($replacement)) { |
|
256 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
257 | + } |
|
239 | 258 | |
240 | - foreach ($replacement as $key => $value) |
|
241 | - $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
259 | + foreach ($replacement as $key => $value) { |
|
260 | + $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
261 | + } |
|
242 | 262 | |
243 | 263 | return implode(', ', $replacement); |
264 | + } else { |
|
265 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
244 | 266 | } |
245 | - else |
|
246 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
247 | 267 | break; |
248 | 268 | |
249 | 269 | case 'date': |
250 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
251 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
252 | - else |
|
253 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
270 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
271 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
272 | + } else { |
|
273 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
274 | + } |
|
254 | 275 | break; |
255 | 276 | |
256 | 277 | case 'time': |
257 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
258 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
259 | - else |
|
260 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
278 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
279 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
280 | + } else { |
|
281 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
282 | + } |
|
261 | 283 | break; |
262 | 284 | |
263 | 285 | case 'datetime': |
264 | - 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) |
|
265 | - return 'str_to_date('. |
|
286 | + 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) { |
|
287 | + return 'str_to_date('. |
|
266 | 288 | 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]). |
267 | 289 | ',\'%Y-%m-%d %h:%i:%s\')'; |
268 | - else |
|
269 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
290 | + } else { |
|
291 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
292 | + } |
|
270 | 293 | break; |
271 | 294 | |
272 | 295 | case 'float': |
273 | - if (!is_numeric($replacement)) |
|
274 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
296 | + if (!is_numeric($replacement)) { |
|
297 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
298 | + } |
|
275 | 299 | return (string) (float) $replacement; |
276 | 300 | break; |
277 | 301 | |
@@ -285,32 +309,37 @@ discard block |
||
285 | 309 | break; |
286 | 310 | |
287 | 311 | case 'inet': |
288 | - if ($replacement == 'null' || $replacement == '') |
|
289 | - return 'null'; |
|
290 | - if (!isValidIP($replacement)) |
|
291 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
312 | + if ($replacement == 'null' || $replacement == '') { |
|
313 | + return 'null'; |
|
314 | + } |
|
315 | + if (!isValidIP($replacement)) { |
|
316 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
317 | + } |
|
292 | 318 | //we don't use the native support of mysql > 5.6.2 |
293 | 319 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
294 | 320 | |
295 | 321 | case 'array_inet': |
296 | 322 | if (is_array($replacement)) |
297 | 323 | { |
298 | - if (empty($replacement)) |
|
299 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
324 | + if (empty($replacement)) { |
|
325 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
326 | + } |
|
300 | 327 | |
301 | 328 | foreach ($replacement as $key => $value) |
302 | 329 | { |
303 | - if ($replacement == 'null' || $replacement == '') |
|
304 | - $replacement[$key] = 'null'; |
|
305 | - if (!isValidIP($value)) |
|
306 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
330 | + if ($replacement == 'null' || $replacement == '') { |
|
331 | + $replacement[$key] = 'null'; |
|
332 | + } |
|
333 | + if (!isValidIP($value)) { |
|
334 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
335 | + } |
|
307 | 336 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
308 | 337 | } |
309 | 338 | |
310 | 339 | return implode(', ', $replacement); |
340 | + } else { |
|
341 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
311 | 342 | } |
312 | - else |
|
313 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
314 | 343 | break; |
315 | 344 | |
316 | 345 | default: |
@@ -381,18 +410,20 @@ discard block |
||
381 | 410 | // One more query.... |
382 | 411 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
383 | 412 | |
384 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
385 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
413 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
414 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
415 | + } |
|
386 | 416 | |
387 | 417 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
388 | 418 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
389 | 419 | { |
390 | 420 | // Add before LIMIT |
391 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
392 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
393 | - else |
|
394 | - // Append it. |
|
421 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
422 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
423 | + } else { |
|
424 | + // Append it. |
|
395 | 425 | $db_string .= "\n\t\t\tORDER BY null"; |
426 | + } |
|
396 | 427 | } |
397 | 428 | |
398 | 429 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -418,17 +449,18 @@ discard block |
||
418 | 449 | while (true) |
419 | 450 | { |
420 | 451 | $pos = strpos($db_string_1, '\'', $pos + 1); |
421 | - if ($pos === false) |
|
422 | - break; |
|
452 | + if ($pos === false) { |
|
453 | + break; |
|
454 | + } |
|
423 | 455 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
424 | 456 | |
425 | 457 | while (true) |
426 | 458 | { |
427 | 459 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
428 | 460 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
429 | - if ($pos1 === false) |
|
430 | - break; |
|
431 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
461 | + if ($pos1 === false) { |
|
462 | + break; |
|
463 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
432 | 464 | { |
433 | 465 | $pos = $pos1; |
434 | 466 | break; |
@@ -444,16 +476,19 @@ discard block |
||
444 | 476 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
445 | 477 | |
446 | 478 | // Comments? We don't use comments in our queries, we leave 'em outside! |
447 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
448 | - $fail = true; |
|
479 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
480 | + $fail = true; |
|
481 | + } |
|
449 | 482 | // Trying to change passwords, slow us down, or something? |
450 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
451 | - $fail = true; |
|
452 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
453 | - $fail = true; |
|
483 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
484 | + $fail = true; |
|
485 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
486 | + $fail = true; |
|
487 | + } |
|
454 | 488 | |
455 | - if (!empty($fail) && function_exists('log_error')) |
|
456 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
489 | + if (!empty($fail) && function_exists('log_error')) { |
|
490 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
491 | + } |
|
457 | 492 | } |
458 | 493 | |
459 | 494 | // Debugging. |
@@ -463,8 +498,9 @@ discard block |
||
463 | 498 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
464 | 499 | |
465 | 500 | // Initialize $db_cache if not already initialized. |
466 | - if (!isset($db_cache)) |
|
467 | - $db_cache = array(); |
|
501 | + if (!isset($db_cache)) { |
|
502 | + $db_cache = array(); |
|
503 | + } |
|
468 | 504 | |
469 | 505 | if (!empty($_SESSION['debug_redirect'])) |
470 | 506 | { |
@@ -480,17 +516,20 @@ discard block |
||
480 | 516 | $db_cache[$db_count]['s'] = ($st = microtime(true)) - $time_start; |
481 | 517 | } |
482 | 518 | |
483 | - if (empty($db_unbuffered)) |
|
484 | - $ret = @mysqli_query($connection, $db_string); |
|
485 | - else |
|
486 | - $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
519 | + if (empty($db_unbuffered)) { |
|
520 | + $ret = @mysqli_query($connection, $db_string); |
|
521 | + } else { |
|
522 | + $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
523 | + } |
|
487 | 524 | |
488 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
489 | - $ret = smf_db_error($db_string, $connection); |
|
525 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
526 | + $ret = smf_db_error($db_string, $connection); |
|
527 | + } |
|
490 | 528 | |
491 | 529 | // Debugging. |
492 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
493 | - $db_cache[$db_count]['t'] = microtime(true) - $st; |
|
530 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
531 | + $db_cache[$db_count]['t'] = microtime(true) - $st; |
|
532 | + } |
|
494 | 533 | |
495 | 534 | return $ret; |
496 | 535 | } |
@@ -537,12 +576,13 @@ discard block |
||
537 | 576 | // Decide which connection to use |
538 | 577 | $connection = $connection === null ? $db_connection : $connection; |
539 | 578 | |
540 | - if ($type == 'begin') |
|
541 | - return @mysqli_query($connection, 'BEGIN'); |
|
542 | - elseif ($type == 'rollback') |
|
543 | - return @mysqli_query($connection, 'ROLLBACK'); |
|
544 | - elseif ($type == 'commit') |
|
545 | - return @mysqli_query($connection, 'COMMIT'); |
|
579 | + if ($type == 'begin') { |
|
580 | + return @mysqli_query($connection, 'BEGIN'); |
|
581 | + } elseif ($type == 'rollback') { |
|
582 | + return @mysqli_query($connection, 'ROLLBACK'); |
|
583 | + } elseif ($type == 'commit') { |
|
584 | + return @mysqli_query($connection, 'COMMIT'); |
|
585 | + } |
|
546 | 586 | |
547 | 587 | return false; |
548 | 588 | } |
@@ -580,8 +620,9 @@ discard block |
||
580 | 620 | // 1213: Deadlock found. |
581 | 621 | |
582 | 622 | // Log the error. |
583 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
584 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
623 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
624 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
625 | + } |
|
585 | 626 | |
586 | 627 | // Database error auto fixing ;). |
587 | 628 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -590,8 +631,9 @@ discard block |
||
590 | 631 | $old_cache = @$modSettings['cache_enable']; |
591 | 632 | $modSettings['cache_enable'] = '1'; |
592 | 633 | |
593 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
594 | - $db_last_error = max(@$db_last_error, $temp); |
|
634 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
635 | + $db_last_error = max(@$db_last_error, $temp); |
|
636 | + } |
|
595 | 637 | |
596 | 638 | if (@$db_last_error < time() - 3600 * 24 * 3) |
597 | 639 | { |
@@ -607,8 +649,9 @@ discard block |
||
607 | 649 | foreach ($tables as $table) |
608 | 650 | { |
609 | 651 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
610 | - if (trim($table) != '') |
|
611 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
652 | + if (trim($table) != '') { |
|
653 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
654 | + } |
|
612 | 655 | } |
613 | 656 | } |
614 | 657 | |
@@ -617,8 +660,9 @@ discard block |
||
617 | 660 | // Table crashed. Let's try to fix it. |
618 | 661 | elseif ($query_errno == 1016) |
619 | 662 | { |
620 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
621 | - $fix_tables = array('`' . $match[1] . '`'); |
|
663 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
664 | + $fix_tables = array('`' . $match[1] . '`'); |
|
665 | + } |
|
622 | 666 | } |
623 | 667 | // Indexes crashed. Should be easy to fix! |
624 | 668 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -637,13 +681,15 @@ discard block |
||
637 | 681 | |
638 | 682 | // Make a note of the REPAIR... |
639 | 683 | cache_put_data('db_last_error', time(), 600); |
640 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
641 | - updateSettingsFile(array('db_last_error' => time())); |
|
684 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
685 | + updateSettingsFile(array('db_last_error' => time())); |
|
686 | + } |
|
642 | 687 | |
643 | 688 | // Attempt to find and repair the broken table. |
644 | - foreach ($fix_tables as $table) |
|
645 | - $smcFunc['db_query']('', " |
|
689 | + foreach ($fix_tables as $table) { |
|
690 | + $smcFunc['db_query']('', " |
|
646 | 691 | REPAIR TABLE $table", false, false); |
692 | + } |
|
647 | 693 | |
648 | 694 | // And send off an email! |
649 | 695 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -652,11 +698,12 @@ discard block |
||
652 | 698 | |
653 | 699 | // Try the query again...? |
654 | 700 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
655 | - if ($ret !== false) |
|
656 | - return $ret; |
|
701 | + if ($ret !== false) { |
|
702 | + return $ret; |
|
703 | + } |
|
704 | + } else { |
|
705 | + $modSettings['cache_enable'] = $old_cache; |
|
657 | 706 | } |
658 | - else |
|
659 | - $modSettings['cache_enable'] = $old_cache; |
|
660 | 707 | |
661 | 708 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
662 | 709 | if (in_array($query_errno, array(1205, 1213))) |
@@ -669,24 +716,27 @@ discard block |
||
669 | 716 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
670 | 717 | |
671 | 718 | $new_errno = mysqli_errno($db_connection); |
672 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
673 | - break; |
|
719 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
720 | + break; |
|
721 | + } |
|
674 | 722 | } |
675 | 723 | |
676 | 724 | // If it failed again, shucks to be you... we're not trying it over and over. |
677 | - if ($ret !== false) |
|
678 | - return $ret; |
|
725 | + if ($ret !== false) { |
|
726 | + return $ret; |
|
727 | + } |
|
679 | 728 | } |
680 | 729 | } |
681 | 730 | // Are they out of space, perhaps? |
682 | 731 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
683 | 732 | { |
684 | - if (!isset($txt)) |
|
685 | - $query_error .= ' - check database storage space.'; |
|
686 | - else |
|
733 | + if (!isset($txt)) { |
|
734 | + $query_error .= ' - check database storage space.'; |
|
735 | + } else |
|
687 | 736 | { |
688 | - if (!isset($txt['mysql_error_space'])) |
|
689 | - loadLanguage('Errors'); |
|
737 | + if (!isset($txt['mysql_error_space'])) { |
|
738 | + loadLanguage('Errors'); |
|
739 | + } |
|
690 | 740 | |
691 | 741 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
692 | 742 | } |
@@ -694,15 +744,17 @@ discard block |
||
694 | 744 | } |
695 | 745 | |
696 | 746 | // Nothing's defined yet... just die with it. |
697 | - if (empty($context) || empty($txt)) |
|
698 | - die($query_error); |
|
747 | + if (empty($context) || empty($txt)) { |
|
748 | + die($query_error); |
|
749 | + } |
|
699 | 750 | |
700 | 751 | // Show an error message, if possible. |
701 | 752 | $context['error_title'] = $txt['database_error']; |
702 | - if (allowedTo('admin_forum')) |
|
703 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
704 | - else |
|
705 | - $context['error_message'] = $txt['try_again']; |
|
753 | + if (allowedTo('admin_forum')) { |
|
754 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
755 | + } else { |
|
756 | + $context['error_message'] = $txt['try_again']; |
|
757 | + } |
|
706 | 758 | |
707 | 759 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
708 | 760 | { |
@@ -734,8 +786,9 @@ discard block |
||
734 | 786 | $return_var = null; |
735 | 787 | |
736 | 788 | // With nothing to insert, simply return. |
737 | - if (empty($data)) |
|
738 | - return; |
|
789 | + if (empty($data)) { |
|
790 | + return; |
|
791 | + } |
|
739 | 792 | |
740 | 793 | // Replace the prefix holder with the actual prefix. |
741 | 794 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -745,23 +798,26 @@ discard block |
||
745 | 798 | if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) |
746 | 799 | { |
747 | 800 | $with_returning = true; |
748 | - if ($returnmode == 2) |
|
749 | - $return_var = array(); |
|
801 | + if ($returnmode == 2) { |
|
802 | + $return_var = array(); |
|
803 | + } |
|
750 | 804 | } |
751 | 805 | |
752 | 806 | // Inserting data as a single row can be done as a single array. |
753 | - if (!is_array($data[array_rand($data)])) |
|
754 | - $data = array($data); |
|
807 | + if (!is_array($data[array_rand($data)])) { |
|
808 | + $data = array($data); |
|
809 | + } |
|
755 | 810 | |
756 | 811 | // Create the mold for a single row insert. |
757 | 812 | $insertData = '('; |
758 | 813 | foreach ($columns as $columnName => $type) |
759 | 814 | { |
760 | 815 | // Are we restricting the length? |
761 | - if (strpos($type, 'string-') !== false) |
|
762 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
763 | - else |
|
764 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
816 | + if (strpos($type, 'string-') !== false) { |
|
817 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
818 | + } else { |
|
819 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
820 | + } |
|
765 | 821 | } |
766 | 822 | $insertData = substr($insertData, 0, -2) . ')'; |
767 | 823 | |
@@ -770,16 +826,18 @@ discard block |
||
770 | 826 | |
771 | 827 | // Here's where the variables are injected to the query. |
772 | 828 | $insertRows = array(); |
773 | - foreach ($data as $dataRow) |
|
774 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
829 | + foreach ($data as $dataRow) { |
|
830 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
831 | + } |
|
775 | 832 | |
776 | 833 | // Determine the method of insertion. |
777 | 834 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
778 | 835 | |
779 | 836 | // Sanity check for replace is key part of the columns array |
780 | - if ($method == 'replace' && count(array_intersect_key($columns, array_flip($keys))) !== count($keys)) |
|
781 | - smf_db_error_backtrace('Primary Key field missing in insert call', |
|
837 | + if ($method == 'replace' && count(array_intersect_key($columns, array_flip($keys))) !== count($keys)) { |
|
838 | + smf_db_error_backtrace('Primary Key field missing in insert call', |
|
782 | 839 | 'Change the method of db insert to insert or add the pk field to the columns array', E_USER_ERROR, __FILE__, __LINE__); |
840 | + } |
|
783 | 841 | |
784 | 842 | if (!$with_returning || $method != 'ingore') |
785 | 843 | { |
@@ -795,8 +853,7 @@ discard block |
||
795 | 853 | ), |
796 | 854 | $connection |
797 | 855 | ); |
798 | - } |
|
799 | - else //special way for ignore method with returning |
|
856 | + } else //special way for ignore method with returning |
|
800 | 857 | { |
801 | 858 | $count = count($insertRows); |
802 | 859 | $ai = 0; |
@@ -816,19 +873,21 @@ discard block |
||
816 | 873 | ); |
817 | 874 | $new_id = $smcFunc['db_insert_id'](); |
818 | 875 | |
819 | - if ($last_id != $new_id) //the inserted value was new |
|
876 | + if ($last_id != $new_id) { |
|
877 | + //the inserted value was new |
|
820 | 878 | { |
821 | 879 | $ai = $new_id; |
822 | 880 | } |
823 | - else // the inserted value already exists we need to find the pk |
|
881 | + } else // the inserted value already exists we need to find the pk |
|
824 | 882 | { |
825 | 883 | $where_string = ''; |
826 | 884 | $count2 = count($indexed_columns); |
827 | 885 | for ($x = 0; $x < $count2; $x++) |
828 | 886 | { |
829 | 887 | $where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x]; |
830 | - if (($x + 1) < $count2) |
|
831 | - $where_string += ' AND '; |
|
888 | + if (($x + 1) < $count2) { |
|
889 | + $where_string += ' AND '; |
|
890 | + } |
|
832 | 891 | } |
833 | 892 | |
834 | 893 | $request = $smcFunc['db_query']('',' |
@@ -844,25 +903,27 @@ discard block |
||
844 | 903 | } |
845 | 904 | } |
846 | 905 | |
847 | - if ($returnmode == 1) |
|
848 | - $return_var = $ai; |
|
849 | - else if ($returnmode == 2) |
|
850 | - $return_var[] = $ai; |
|
906 | + if ($returnmode == 1) { |
|
907 | + $return_var = $ai; |
|
908 | + } else if ($returnmode == 2) { |
|
909 | + $return_var[] = $ai; |
|
910 | + } |
|
851 | 911 | } |
852 | 912 | } |
853 | 913 | |
854 | 914 | |
855 | 915 | if ($with_returning) |
856 | 916 | { |
857 | - if ($returnmode == 1 && empty($return_var)) |
|
858 | - $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
859 | - else if ($returnmode == 2 && empty($return_var)) |
|
917 | + if ($returnmode == 1 && empty($return_var)) { |
|
918 | + $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
919 | + } else if ($returnmode == 2 && empty($return_var)) |
|
860 | 920 | { |
861 | 921 | $return_var = array(); |
862 | 922 | $count = count($insertRows); |
863 | 923 | $start = smf_db_insert_id($table, $keys[0]); |
864 | - for ($i = 0; $i < $count; $i++ ) |
|
865 | - $return_var[] = $start + $i; |
|
924 | + for ($i = 0; $i < $count; $i++ ) { |
|
925 | + $return_var[] = $start + $i; |
|
926 | + } |
|
866 | 927 | } |
867 | 928 | return $return_var; |
868 | 929 | } |
@@ -880,8 +941,9 @@ discard block |
||
880 | 941 | */ |
881 | 942 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
882 | 943 | { |
883 | - if (empty($log_message)) |
|
884 | - $log_message = $error_message; |
|
944 | + if (empty($log_message)) { |
|
945 | + $log_message = $error_message; |
|
946 | + } |
|
885 | 947 | |
886 | 948 | foreach (debug_backtrace() as $step) |
887 | 949 | { |
@@ -900,12 +962,14 @@ discard block |
||
900 | 962 | } |
901 | 963 | |
902 | 964 | // A special case - we want the file and line numbers for debugging. |
903 | - if ($error_type == 'return') |
|
904 | - return array($file, $line); |
|
965 | + if ($error_type == 'return') { |
|
966 | + return array($file, $line); |
|
967 | + } |
|
905 | 968 | |
906 | 969 | // Is always a critical error. |
907 | - if (function_exists('log_error')) |
|
908 | - log_error($log_message, 'critical', $file, $line); |
|
970 | + if (function_exists('log_error')) { |
|
971 | + log_error($log_message, 'critical', $file, $line); |
|
972 | + } |
|
909 | 973 | |
910 | 974 | if (function_exists('fatal_error')) |
911 | 975 | { |
@@ -913,12 +977,12 @@ discard block |
||
913 | 977 | |
914 | 978 | // Cannot continue... |
915 | 979 | exit; |
980 | + } elseif ($error_type) { |
|
981 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
982 | + } else { |
|
983 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
984 | + } |
|
916 | 985 | } |
917 | - elseif ($error_type) |
|
918 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
919 | - else |
|
920 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
921 | -} |
|
922 | 986 | |
923 | 987 | /** |
924 | 988 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -935,10 +999,11 @@ discard block |
||
935 | 999 | '\\' => '\\\\', |
936 | 1000 | ); |
937 | 1001 | |
938 | - if ($translate_human_wildcards) |
|
939 | - $replacements += array( |
|
1002 | + if ($translate_human_wildcards) { |
|
1003 | + $replacements += array( |
|
940 | 1004 | '*' => '%', |
941 | 1005 | ); |
1006 | + } |
|
942 | 1007 | |
943 | 1008 | return strtr($string, $replacements); |
944 | 1009 | } |
@@ -952,8 +1017,9 @@ discard block |
||
952 | 1017 | */ |
953 | 1018 | function smf_is_resource($result) |
954 | 1019 | { |
955 | - if ($result instanceof mysqli_result) |
|
956 | - return true; |
|
1020 | + if ($result instanceof mysqli_result) { |
|
1021 | + return true; |
|
1022 | + } |
|
957 | 1023 | |
958 | 1024 | return false; |
959 | 1025 | } |
@@ -982,19 +1048,22 @@ discard block |
||
982 | 1048 | static $mysql_error_data_prep; |
983 | 1049 | |
984 | 1050 | // without database we can't do anything |
985 | - if (empty($db_connection)) |
|
986 | - return; |
|
1051 | + if (empty($db_connection)) { |
|
1052 | + return; |
|
1053 | + } |
|
987 | 1054 | |
988 | - if (empty($mysql_error_data_prep)) |
|
989 | - $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
1055 | + if (empty($mysql_error_data_prep)) { |
|
1056 | + $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
990 | 1057 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line, backtrace) |
991 | 1058 | VALUES( ?, ?, unhex(?), ?, ?, ?, ?, ?, ?, ?)' |
992 | 1059 | ); |
1060 | + } |
|
993 | 1061 | |
994 | - if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) |
|
995 | - $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
996 | - else |
|
997 | - $error_array[2] = null; |
|
1062 | + if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) { |
|
1063 | + $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
1064 | + } else { |
|
1065 | + $error_array[2] = null; |
|
1066 | + } |
|
998 | 1067 | mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssis', |
999 | 1068 | $error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6], |
1000 | 1069 | $error_array[7], $error_array[8], $error_array[9]); |
@@ -1016,8 +1085,9 @@ discard block |
||
1016 | 1085 | $count = count($array_values); |
1017 | 1086 | $then = ($desc ? ' THEN -' : ' THEN '); |
1018 | 1087 | |
1019 | - for ($i = 0; $i < $count; $i++) |
|
1020 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1088 | + for ($i = 0; $i < $count; $i++) { |
|
1089 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1090 | + } |
|
1021 | 1091 | |
1022 | 1092 | $return .= 'END'; |
1023 | 1093 | return $return; |
@@ -1043,17 +1113,20 @@ discard block |
||
1043 | 1113 | global $smcFunc; |
1044 | 1114 | static $return; |
1045 | 1115 | |
1046 | - if (isset($return)) |
|
1047 | - return $return; |
|
1116 | + if (isset($return)) { |
|
1117 | + return $return; |
|
1118 | + } |
|
1048 | 1119 | |
1049 | 1120 | db_extend('extra'); |
1050 | 1121 | |
1051 | 1122 | $version = $smcFunc['db_get_version'](); |
1052 | 1123 | |
1053 | - if (strpos(strtolower($version), 'mariadb') !== false) |
|
1054 | - $return = version_compare($version, '10.2.2', '>='); |
|
1055 | - else //mysql |
|
1124 | + if (strpos(strtolower($version), 'mariadb') !== false) { |
|
1125 | + $return = version_compare($version, '10.2.2', '>='); |
|
1126 | + } else { |
|
1127 | + //mysql |
|
1056 | 1128 | $return = version_compare($version, '8.0.1', '>='); |
1129 | + } |
|
1057 | 1130 | |
1058 | 1131 | return $return; |
1059 | 1132 | } |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
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,24 +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 | - |
|
195 | - else |
|
196 | + if ($parameter1 === true) { |
|
197 | + updateSettings(array('totalTopics' => true), true); |
|
198 | + } else |
|
196 | 199 | { |
197 | 200 | // Get the number of topics - a SUM is better for InnoDB tables. |
198 | 201 | // We also ignore the recycle bin here because there will probably be a bunch of one-post topics there. |
@@ -213,8 +216,9 @@ discard block |
||
213 | 216 | |
214 | 217 | case 'postgroups': |
215 | 218 | // Parameter two is the updated columns: we should check to see if we base groups off any of these. |
216 | - if ($parameter2 !== null && !in_array('posts', $parameter2)) |
|
217 | - return; |
|
219 | + if ($parameter2 !== null && !in_array('posts', $parameter2)) { |
|
220 | + return; |
|
221 | + } |
|
218 | 222 | |
219 | 223 | $postgroups = cache_get_data('updateStats:postgroups', 360); |
220 | 224 | if ($postgroups == null || $parameter1 == null) |
@@ -229,8 +233,9 @@ discard block |
||
229 | 233 | ) |
230 | 234 | ); |
231 | 235 | $postgroups = array(); |
232 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
233 | - $postgroups[$row['id_group']] = $row['min_posts']; |
|
236 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
237 | + $postgroups[$row['id_group']] = $row['min_posts']; |
|
238 | + } |
|
234 | 239 | |
235 | 240 | $smcFunc['db_free_result']($request); |
236 | 241 | |
@@ -241,8 +246,9 @@ discard block |
||
241 | 246 | } |
242 | 247 | |
243 | 248 | // Oh great, they've screwed their post groups. |
244 | - if (empty($postgroups)) |
|
245 | - return; |
|
249 | + if (empty($postgroups)) { |
|
250 | + return; |
|
251 | + } |
|
246 | 252 | |
247 | 253 | // Set all membergroups from most posts to least posts. |
248 | 254 | $conditions = ''; |
@@ -301,12 +307,9 @@ discard block |
||
301 | 307 | { |
302 | 308 | $condition = 'id_member IN ({array_int:members})'; |
303 | 309 | $parameters['members'] = $members; |
304 | - } |
|
305 | - |
|
306 | - elseif ($members === null) |
|
307 | - $condition = '1=1'; |
|
308 | - |
|
309 | - else |
|
310 | + } elseif ($members === null) { |
|
311 | + $condition = '1=1'; |
|
312 | + } else |
|
310 | 313 | { |
311 | 314 | $condition = 'id_member = {int:member}'; |
312 | 315 | $parameters['member'] = $members; |
@@ -346,9 +349,9 @@ discard block |
||
346 | 349 | if (count($vars_to_integrate) != 0) |
347 | 350 | { |
348 | 351 | // Fetch a list of member_names if necessary |
349 | - if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) |
|
350 | - $member_names = array($user_info['username']); |
|
351 | - else |
|
352 | + if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) { |
|
353 | + $member_names = array($user_info['username']); |
|
354 | + } else |
|
352 | 355 | { |
353 | 356 | $member_names = array(); |
354 | 357 | $request = $smcFunc['db_query']('', ' |
@@ -357,14 +360,16 @@ discard block |
||
357 | 360 | WHERE ' . $condition, |
358 | 361 | $parameters |
359 | 362 | ); |
360 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
361 | - $member_names[] = $row['member_name']; |
|
363 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
364 | + $member_names[] = $row['member_name']; |
|
365 | + } |
|
362 | 366 | $smcFunc['db_free_result']($request); |
363 | 367 | } |
364 | 368 | |
365 | - if (!empty($member_names)) |
|
366 | - foreach ($vars_to_integrate as $var) |
|
369 | + if (!empty($member_names)) { |
|
370 | + foreach ($vars_to_integrate as $var) |
|
367 | 371 | call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats)); |
372 | + } |
|
368 | 373 | } |
369 | 374 | } |
370 | 375 | |
@@ -372,16 +377,17 @@ discard block |
||
372 | 377 | foreach ($data as $var => $val) |
373 | 378 | { |
374 | 379 | $type = 'string'; |
375 | - if (in_array($var, $knownInts)) |
|
376 | - $type = 'int'; |
|
377 | - elseif (in_array($var, $knownFloats)) |
|
378 | - $type = 'float'; |
|
379 | - elseif ($var == 'birthdate') |
|
380 | - $type = 'date'; |
|
381 | - elseif ($var == 'member_ip') |
|
382 | - $type = 'inet'; |
|
383 | - elseif ($var == 'member_ip2') |
|
384 | - $type = 'inet'; |
|
380 | + if (in_array($var, $knownInts)) { |
|
381 | + $type = 'int'; |
|
382 | + } elseif (in_array($var, $knownFloats)) { |
|
383 | + $type = 'float'; |
|
384 | + } elseif ($var == 'birthdate') { |
|
385 | + $type = 'date'; |
|
386 | + } elseif ($var == 'member_ip') { |
|
387 | + $type = 'inet'; |
|
388 | + } elseif ($var == 'member_ip2') { |
|
389 | + $type = 'inet'; |
|
390 | + } |
|
385 | 391 | |
386 | 392 | // Doing an increment? |
387 | 393 | if ($var == 'alerts' && ($val === '+' || $val === '-')) |
@@ -390,18 +396,17 @@ discard block |
||
390 | 396 | if (is_array($members)) |
391 | 397 | { |
392 | 398 | $val = 'CASE '; |
393 | - foreach ($members as $k => $v) |
|
394 | - $val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' '; |
|
399 | + foreach ($members as $k => $v) { |
|
400 | + $val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' '; |
|
401 | + } |
|
395 | 402 | $val = $val . ' END'; |
396 | 403 | $type = 'raw'; |
397 | - } |
|
398 | - else |
|
404 | + } else |
|
399 | 405 | { |
400 | 406 | $blub = fetch_alerts($members, false, 0, array(), false); |
401 | 407 | $val = count($blub); |
402 | 408 | } |
403 | - } |
|
404 | - else if ($type == 'int' && ($val === '+' || $val === '-')) |
|
409 | + } else if ($type == 'int' && ($val === '+' || $val === '-')) |
|
405 | 410 | { |
406 | 411 | $val = $var . ' ' . $val . ' 1'; |
407 | 412 | $type = 'raw'; |
@@ -412,8 +417,9 @@ discard block |
||
412 | 417 | { |
413 | 418 | if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match)) |
414 | 419 | { |
415 | - if ($match[1] != '+ ') |
|
416 | - $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
420 | + if ($match[1] != '+ ') { |
|
421 | + $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
422 | + } |
|
417 | 423 | $type = 'raw'; |
418 | 424 | } |
419 | 425 | } |
@@ -434,8 +440,9 @@ discard block |
||
434 | 440 | // Clear any caching? |
435 | 441 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members)) |
436 | 442 | { |
437 | - if (!is_array($members)) |
|
438 | - $members = array($members); |
|
443 | + if (!is_array($members)) { |
|
444 | + $members = array($members); |
|
445 | + } |
|
439 | 446 | |
440 | 447 | foreach ($members as $member) |
441 | 448 | { |
@@ -468,29 +475,32 @@ discard block |
||
468 | 475 | { |
469 | 476 | global $modSettings, $smcFunc; |
470 | 477 | |
471 | - if (empty($changeArray) || !is_array($changeArray)) |
|
472 | - return; |
|
478 | + if (empty($changeArray) || !is_array($changeArray)) { |
|
479 | + return; |
|
480 | + } |
|
473 | 481 | |
474 | 482 | $toRemove = array(); |
475 | 483 | |
476 | 484 | // Go check if there is any setting to be removed. |
477 | - foreach ($changeArray as $k => $v) |
|
478 | - if ($v === null) |
|
485 | + foreach ($changeArray as $k => $v) { |
|
486 | + if ($v === null) |
|
479 | 487 | { |
480 | 488 | // Found some, remove them from the original array and add them to ours. |
481 | 489 | unset($changeArray[$k]); |
490 | + } |
|
482 | 491 | $toRemove[] = $k; |
483 | 492 | } |
484 | 493 | |
485 | 494 | // Proceed with the deletion. |
486 | - if (!empty($toRemove)) |
|
487 | - $smcFunc['db_query']('', ' |
|
495 | + if (!empty($toRemove)) { |
|
496 | + $smcFunc['db_query']('', ' |
|
488 | 497 | DELETE FROM {db_prefix}settings |
489 | 498 | WHERE variable IN ({array_string:remove})', |
490 | 499 | array( |
491 | 500 | 'remove' => $toRemove, |
492 | 501 | ) |
493 | 502 | ); |
503 | + } |
|
494 | 504 | |
495 | 505 | // In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs. |
496 | 506 | if ($update) |
@@ -519,19 +529,22 @@ discard block |
||
519 | 529 | foreach ($changeArray as $variable => $value) |
520 | 530 | { |
521 | 531 | // Don't bother if it's already like that ;). |
522 | - if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) |
|
523 | - continue; |
|
532 | + if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) { |
|
533 | + continue; |
|
534 | + } |
|
524 | 535 | // If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it. |
525 | - elseif (!isset($modSettings[$variable]) && empty($value)) |
|
526 | - continue; |
|
536 | + elseif (!isset($modSettings[$variable]) && empty($value)) { |
|
537 | + continue; |
|
538 | + } |
|
527 | 539 | |
528 | 540 | $replaceArray[] = array($variable, $value); |
529 | 541 | |
530 | 542 | $modSettings[$variable] = $value; |
531 | 543 | } |
532 | 544 | |
533 | - if (empty($replaceArray)) |
|
534 | - return; |
|
545 | + if (empty($replaceArray)) { |
|
546 | + return; |
|
547 | + } |
|
535 | 548 | |
536 | 549 | $smcFunc['db_insert']('replace', |
537 | 550 | '{db_prefix}settings', |
@@ -577,14 +590,17 @@ discard block |
||
577 | 590 | $start_invalid = $start < 0; |
578 | 591 | |
579 | 592 | // Make sure $start is a proper variable - not less than 0. |
580 | - if ($start_invalid) |
|
581 | - $start = 0; |
|
593 | + if ($start_invalid) { |
|
594 | + $start = 0; |
|
595 | + } |
|
582 | 596 | // Not greater than the upper bound. |
583 | - elseif ($start >= $max_value) |
|
584 | - $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
597 | + elseif ($start >= $max_value) { |
|
598 | + $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
599 | + } |
|
585 | 600 | // And it has to be a multiple of $num_per_page! |
586 | - else |
|
587 | - $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
601 | + else { |
|
602 | + $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
603 | + } |
|
588 | 604 | |
589 | 605 | $context['current_page'] = $start / $num_per_page; |
590 | 606 | |
@@ -614,77 +630,87 @@ discard block |
||
614 | 630 | |
615 | 631 | // Show all the pages. |
616 | 632 | $display_page = 1; |
617 | - for ($counter = 0; $counter < $max_value; $counter += $num_per_page) |
|
618 | - $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
633 | + for ($counter = 0; $counter < $max_value; $counter += $num_per_page) { |
|
634 | + $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
635 | + } |
|
619 | 636 | |
620 | 637 | // Show the right arrow. |
621 | 638 | $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page); |
622 | - if ($start != $counter - $max_value && !$start_invalid) |
|
623 | - $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
624 | - } |
|
625 | - else |
|
639 | + if ($start != $counter - $max_value && !$start_invalid) { |
|
640 | + $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
641 | + } |
|
642 | + } else |
|
626 | 643 | { |
627 | 644 | // If they didn't enter an odd value, pretend they did. |
628 | 645 | $PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2; |
629 | 646 | |
630 | 647 | // Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page) |
631 | - if (!empty($start) && $show_prevnext) |
|
632 | - $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
633 | - else |
|
634 | - $pageindex .= ''; |
|
648 | + if (!empty($start) && $show_prevnext) { |
|
649 | + $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
650 | + } else { |
|
651 | + $pageindex .= ''; |
|
652 | + } |
|
635 | 653 | |
636 | 654 | // Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15) |
637 | - if ($start > $num_per_page * $PageContiguous) |
|
638 | - $pageindex .= sprintf($base_link, 0, '1'); |
|
655 | + if ($start > $num_per_page * $PageContiguous) { |
|
656 | + $pageindex .= sprintf($base_link, 0, '1'); |
|
657 | + } |
|
639 | 658 | |
640 | 659 | // Show the ... after the first page. (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page) |
641 | - if ($start > $num_per_page * ($PageContiguous + 1)) |
|
642 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
660 | + if ($start > $num_per_page * ($PageContiguous + 1)) { |
|
661 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
643 | 662 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
644 | 663 | '{FIRST_PAGE}' => $num_per_page, |
645 | 664 | '{LAST_PAGE}' => $start - $num_per_page * $PageContiguous, |
646 | 665 | '{PER_PAGE}' => $num_per_page, |
647 | 666 | )); |
667 | + } |
|
648 | 668 | |
649 | 669 | // Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page) |
650 | - for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) |
|
651 | - if ($start >= $num_per_page * $nCont) |
|
670 | + for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) { |
|
671 | + if ($start >= $num_per_page * $nCont) |
|
652 | 672 | { |
653 | 673 | $tmpStart = $start - $num_per_page * $nCont; |
674 | + } |
|
654 | 675 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
655 | 676 | } |
656 | 677 | |
657 | 678 | // 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); |
|
679 | + if (!$start_invalid) { |
|
680 | + $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
681 | + } else { |
|
682 | + $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
683 | + } |
|
662 | 684 | |
663 | 685 | // Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page) |
664 | 686 | $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) |
|
687 | + for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) { |
|
688 | + if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
667 | 689 | { |
668 | 690 | $tmpStart = $start + $num_per_page * $nCont; |
691 | + } |
|
669 | 692 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
670 | 693 | } |
671 | 694 | |
672 | 695 | // Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page) |
673 | - if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) |
|
674 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
696 | + if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) { |
|
697 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
675 | 698 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
676 | 699 | '{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1), |
677 | 700 | '{LAST_PAGE}' => $tmpMaxPages, |
678 | 701 | '{PER_PAGE}' => $num_per_page, |
679 | 702 | )); |
703 | + } |
|
680 | 704 | |
681 | 705 | // Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15< next page) |
682 | - if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) |
|
683 | - $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
706 | + if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) { |
|
707 | + $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
708 | + } |
|
684 | 709 | |
685 | 710 | // Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<) |
686 | - if ($start != $tmpMaxPages && $show_prevnext) |
|
687 | - $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
711 | + if ($start != $tmpMaxPages && $show_prevnext) { |
|
712 | + $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
713 | + } |
|
688 | 714 | } |
689 | 715 | $pageindex .= $settings['page_index']['extra_after']; |
690 | 716 | |
@@ -710,8 +736,9 @@ discard block |
||
710 | 736 | if ($decimal_separator === null) |
711 | 737 | { |
712 | 738 | // Not set for whatever reason? |
713 | - if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) |
|
714 | - return $number; |
|
739 | + if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) { |
|
740 | + return $number; |
|
741 | + } |
|
715 | 742 | |
716 | 743 | // Cache these each load... |
717 | 744 | $thousands_separator = $matches[1]; |
@@ -752,17 +779,20 @@ discard block |
||
752 | 779 | $user_info['time_format'] = !empty($user_info['time_format']) ? $user_info['time_format'] : (!empty($modSettings['time_format']) ? $modSettings['time_format'] : '%F %H:%M'); |
753 | 780 | |
754 | 781 | // Offset the time. |
755 | - if (!$offset_type) |
|
756 | - $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
782 | + if (!$offset_type) { |
|
783 | + $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
784 | + } |
|
757 | 785 | // Just the forum offset? |
758 | - elseif ($offset_type == 'forum') |
|
759 | - $time = $log_time + $modSettings['time_offset'] * 3600; |
|
760 | - else |
|
761 | - $time = $log_time; |
|
786 | + elseif ($offset_type == 'forum') { |
|
787 | + $time = $log_time + $modSettings['time_offset'] * 3600; |
|
788 | + } else { |
|
789 | + $time = $log_time; |
|
790 | + } |
|
762 | 791 | |
763 | 792 | // We can't have a negative date (on Windows, at least.) |
764 | - if ($log_time < 0) |
|
765 | - $log_time = 0; |
|
793 | + if ($log_time < 0) { |
|
794 | + $log_time = 0; |
|
795 | + } |
|
766 | 796 | |
767 | 797 | // Today and Yesterday? |
768 | 798 | if ($modSettings['todayMod'] >= 1 && $show_today === true) |
@@ -779,24 +809,27 @@ discard block |
||
779 | 809 | { |
780 | 810 | $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l'; |
781 | 811 | $today_fmt = $h . ':%M' . $s . ' %p'; |
812 | + } else { |
|
813 | + $today_fmt = '%H:%M' . $s; |
|
782 | 814 | } |
783 | - else |
|
784 | - $today_fmt = '%H:%M' . $s; |
|
785 | 815 | |
786 | 816 | // Same day of the year, same year.... Today! |
787 | - if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) |
|
788 | - return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
817 | + if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) { |
|
818 | + return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
819 | + } |
|
789 | 820 | |
790 | 821 | // 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... |
791 | - 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)) |
|
792 | - return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
822 | + 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)) { |
|
823 | + return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
824 | + } |
|
793 | 825 | } |
794 | 826 | |
795 | 827 | $str = !is_bool($show_today) ? $show_today : $user_info['time_format']; |
796 | 828 | |
797 | 829 | // Use the cached formats if available |
798 | - if (is_null($finalizedFormats)) |
|
799 | - $finalizedFormats = (array) cache_get_data('timeformatstrings', 86400); |
|
830 | + if (is_null($finalizedFormats)) { |
|
831 | + $finalizedFormats = (array) cache_get_data('timeformatstrings', 86400); |
|
832 | + } |
|
800 | 833 | |
801 | 834 | // Make a supported version for this format if we don't already have one |
802 | 835 | if (empty($finalizedFormats[$str])) |
@@ -825,8 +858,9 @@ discard block |
||
825 | 858 | ); |
826 | 859 | |
827 | 860 | // No need to do this part again if we already did it once |
828 | - if (is_null($unsupportedFormats)) |
|
829 | - $unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400); |
|
861 | + if (is_null($unsupportedFormats)) { |
|
862 | + $unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400); |
|
863 | + } |
|
830 | 864 | if (empty($unsupportedFormats)) |
831 | 865 | { |
832 | 866 | foreach($strftimeFormatSubstitutions as $format => $substitution) |
@@ -842,20 +876,23 @@ discard block |
||
842 | 876 | |
843 | 877 | // Windows will return false for unsupported formats |
844 | 878 | // Other operating systems return the format string as a literal |
845 | - if ($value === false || $value === $format) |
|
846 | - $unsupportedFormats[] = $format; |
|
879 | + if ($value === false || $value === $format) { |
|
880 | + $unsupportedFormats[] = $format; |
|
881 | + } |
|
847 | 882 | } |
848 | 883 | cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400); |
849 | 884 | } |
850 | 885 | |
851 | 886 | // Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q' |
852 | - if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') |
|
853 | - $timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '%', $timeformat); |
|
887 | + if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { |
|
888 | + $timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '%', $timeformat); |
|
889 | + } |
|
854 | 890 | |
855 | 891 | // Substitute unsupported formats with supported ones |
856 | - if (!empty($unsupportedFormats)) |
|
857 | - while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches)) |
|
892 | + if (!empty($unsupportedFormats)) { |
|
893 | + while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches)) |
|
858 | 894 | $timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat); |
895 | + } |
|
859 | 896 | |
860 | 897 | // Remember this so we don't need to do it again |
861 | 898 | $finalizedFormats[$str] = $timeformat; |
@@ -864,33 +901,39 @@ discard block |
||
864 | 901 | |
865 | 902 | $str = $finalizedFormats[$str]; |
866 | 903 | |
867 | - if (!isset($locale_cache)) |
|
868 | - $locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : ''); |
|
904 | + if (!isset($locale_cache)) { |
|
905 | + $locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : ''); |
|
906 | + } |
|
869 | 907 | |
870 | 908 | if ($locale_cache !== false) |
871 | 909 | { |
872 | 910 | // Check if another process changed the locale |
873 | - if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) |
|
874 | - setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : ''); |
|
911 | + if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) { |
|
912 | + setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : ''); |
|
913 | + } |
|
875 | 914 | |
876 | - if (!isset($non_twelve_hour)) |
|
877 | - $non_twelve_hour = trim(strftime('%p')) === ''; |
|
878 | - if ($non_twelve_hour && strpos($str, '%p') !== false) |
|
879 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
915 | + if (!isset($non_twelve_hour)) { |
|
916 | + $non_twelve_hour = trim(strftime('%p')) === ''; |
|
917 | + } |
|
918 | + if ($non_twelve_hour && strpos($str, '%p') !== false) { |
|
919 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
920 | + } |
|
880 | 921 | |
881 | - foreach (array('%a', '%A', '%b', '%B') as $token) |
|
882 | - if (strpos($str, $token) !== false) |
|
922 | + foreach (array('%a', '%A', '%b', '%B') as $token) { |
|
923 | + if (strpos($str, $token) !== false) |
|
883 | 924 | $str = str_replace($token, strftime($token, $time), $str); |
884 | - } |
|
885 | - else |
|
925 | + } |
|
926 | + } else |
|
886 | 927 | { |
887 | 928 | // Do-it-yourself time localization. Fun. |
888 | - foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) |
|
889 | - if (strpos($str, $token) !== false) |
|
929 | + foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) { |
|
930 | + if (strpos($str, $token) !== false) |
|
890 | 931 | $str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str); |
932 | + } |
|
891 | 933 | |
892 | - if (strpos($str, '%p') !== false) |
|
893 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
934 | + if (strpos($str, '%p') !== false) { |
|
935 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
936 | + } |
|
894 | 937 | } |
895 | 938 | |
896 | 939 | // Format the time and then restore any literal percent characters |
@@ -912,16 +955,19 @@ discard block |
||
912 | 955 | static $translation = array(); |
913 | 956 | |
914 | 957 | // Determine the character set... Default to UTF-8 |
915 | - if (empty($context['character_set'])) |
|
916 | - $charset = 'UTF-8'; |
|
958 | + if (empty($context['character_set'])) { |
|
959 | + $charset = 'UTF-8'; |
|
960 | + } |
|
917 | 961 | // Use ISO-8859-1 in place of non-supported ISO-8859 charsets... |
918 | - elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) |
|
919 | - $charset = 'ISO-8859-1'; |
|
920 | - else |
|
921 | - $charset = $context['character_set']; |
|
962 | + elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) { |
|
963 | + $charset = 'ISO-8859-1'; |
|
964 | + } else { |
|
965 | + $charset = $context['character_set']; |
|
966 | + } |
|
922 | 967 | |
923 | - if (empty($translation)) |
|
924 | - $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
968 | + if (empty($translation)) { |
|
969 | + $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
970 | + } |
|
925 | 971 | |
926 | 972 | return strtr($string, $translation); |
927 | 973 | } |
@@ -943,8 +989,9 @@ discard block |
||
943 | 989 | global $smcFunc; |
944 | 990 | |
945 | 991 | // It was already short enough! |
946 | - if ($smcFunc['strlen']($subject) <= $len) |
|
947 | - return $subject; |
|
992 | + if ($smcFunc['strlen']($subject) <= $len) { |
|
993 | + return $subject; |
|
994 | + } |
|
948 | 995 | |
949 | 996 | // Shorten it by the length it was too long, and strip off junk from the end. |
950 | 997 | return $smcFunc['substr']($subject, 0, $len) . '...'; |
@@ -963,10 +1010,11 @@ discard block |
||
963 | 1010 | { |
964 | 1011 | global $user_info, $modSettings; |
965 | 1012 | |
966 | - if ($timestamp === null) |
|
967 | - $timestamp = time(); |
|
968 | - elseif ($timestamp == 0) |
|
969 | - return 0; |
|
1013 | + if ($timestamp === null) { |
|
1014 | + $timestamp = time(); |
|
1015 | + } elseif ($timestamp == 0) { |
|
1016 | + return 0; |
|
1017 | + } |
|
970 | 1018 | |
971 | 1019 | return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600; |
972 | 1020 | } |
@@ -995,8 +1043,9 @@ discard block |
||
995 | 1043 | $array[$i] = $array[$j]; |
996 | 1044 | $array[$j] = $temp; |
997 | 1045 | |
998 | - for ($i = 1; $p[$i] == 0; $i++) |
|
999 | - $p[$i] = 1; |
|
1046 | + for ($i = 1; $p[$i] == 0; $i++) { |
|
1047 | + $p[$i] = 1; |
|
1048 | + } |
|
1000 | 1049 | |
1001 | 1050 | $orders[] = $array; |
1002 | 1051 | } |
@@ -1028,12 +1077,14 @@ discard block |
||
1028 | 1077 | static $disabled; |
1029 | 1078 | |
1030 | 1079 | // Don't waste cycles |
1031 | - if ($message === '') |
|
1032 | - return ''; |
|
1080 | + if ($message === '') { |
|
1081 | + return ''; |
|
1082 | + } |
|
1033 | 1083 | |
1034 | 1084 | // Just in case it wasn't determined yet whether UTF-8 is enabled. |
1035 | - if (!isset($context['utf8'])) |
|
1036 | - $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
1085 | + if (!isset($context['utf8'])) { |
|
1086 | + $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
1087 | + } |
|
1037 | 1088 | |
1038 | 1089 | // Clean up any cut/paste issues we may have |
1039 | 1090 | $message = sanitizeMSCutPaste($message); |
@@ -1045,13 +1096,15 @@ discard block |
||
1045 | 1096 | return $message; |
1046 | 1097 | } |
1047 | 1098 | |
1048 | - if ($smileys !== null && ($smileys == '1' || $smileys == '0')) |
|
1049 | - $smileys = (bool) $smileys; |
|
1099 | + if ($smileys !== null && ($smileys == '1' || $smileys == '0')) { |
|
1100 | + $smileys = (bool) $smileys; |
|
1101 | + } |
|
1050 | 1102 | |
1051 | 1103 | if (empty($modSettings['enableBBC']) && $message !== false) |
1052 | 1104 | { |
1053 | - if ($smileys === true) |
|
1054 | - parsesmileys($message); |
|
1105 | + if ($smileys === true) { |
|
1106 | + parsesmileys($message); |
|
1107 | + } |
|
1055 | 1108 | |
1056 | 1109 | return $message; |
1057 | 1110 | } |
@@ -1064,8 +1117,9 @@ discard block |
||
1064 | 1117 | } |
1065 | 1118 | |
1066 | 1119 | // Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker |
1067 | - if (!empty($modSettings['autoLinkUrls'])) |
|
1068 | - set_tld_regex(); |
|
1120 | + if (!empty($modSettings['autoLinkUrls'])) { |
|
1121 | + set_tld_regex(); |
|
1122 | + } |
|
1069 | 1123 | |
1070 | 1124 | // Allow mods access before entering the main parse_bbc loop |
1071 | 1125 | call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
@@ -1079,8 +1133,9 @@ discard block |
||
1079 | 1133 | |
1080 | 1134 | $temp = explode(',', strtolower($modSettings['disabledBBC'])); |
1081 | 1135 | |
1082 | - foreach ($temp as $tag) |
|
1083 | - $disabled[trim($tag)] = true; |
|
1136 | + foreach ($temp as $tag) { |
|
1137 | + $disabled[trim($tag)] = true; |
|
1138 | + } |
|
1084 | 1139 | } |
1085 | 1140 | |
1086 | 1141 | // The YouTube bbc needs this for its origin parameter |
@@ -1214,8 +1269,9 @@ discard block |
||
1214 | 1269 | $returnContext = ''; |
1215 | 1270 | |
1216 | 1271 | // BBC or the entire attachments feature is disabled |
1217 | - if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) |
|
1218 | - return $data; |
|
1272 | + if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) { |
|
1273 | + return $data; |
|
1274 | + } |
|
1219 | 1275 | |
1220 | 1276 | // Save the attach ID. |
1221 | 1277 | $attachID = $data; |
@@ -1226,8 +1282,9 @@ discard block |
||
1226 | 1282 | $currentAttachment = parseAttachBBC($attachID); |
1227 | 1283 | |
1228 | 1284 | // parseAttachBBC will return a string ($txt key) rather than dying with a fatal_error. Up to you to decide what to do. |
1229 | - if (is_string($currentAttachment)) |
|
1230 | - return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
1285 | + if (is_string($currentAttachment)) { |
|
1286 | + return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
1287 | + } |
|
1231 | 1288 | |
1232 | 1289 | if (!empty($currentAttachment['is_image'])) |
1233 | 1290 | { |
@@ -1243,15 +1300,17 @@ discard block |
||
1243 | 1300 | $height = ' height="' . $currentAttachment['height'] . '"'; |
1244 | 1301 | } |
1245 | 1302 | |
1246 | - if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) |
|
1247 | - $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>'; |
|
1248 | - else |
|
1249 | - $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
|
1303 | + if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) { |
|
1304 | + $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>'; |
|
1305 | + } else { |
|
1306 | + $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
|
1307 | + } |
|
1250 | 1308 | } |
1251 | 1309 | |
1252 | 1310 | // No image. Show a link. |
1253 | - else |
|
1254 | - $returnContext .= $currentAttachment['link']; |
|
1311 | + else { |
|
1312 | + $returnContext .= $currentAttachment['link']; |
|
1313 | + } |
|
1255 | 1314 | |
1256 | 1315 | // Gotta append what we just did. |
1257 | 1316 | $data = $returnContext; |
@@ -1305,8 +1364,9 @@ discard block |
||
1305 | 1364 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
1306 | 1365 | { |
1307 | 1366 | // Do PHP code coloring? |
1308 | - if ($php_parts[$php_i] != '<?php') |
|
1309 | - continue; |
|
1367 | + if ($php_parts[$php_i] != '<?php') { |
|
1368 | + continue; |
|
1369 | + } |
|
1310 | 1370 | |
1311 | 1371 | $php_string = ''; |
1312 | 1372 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1322,8 +1382,9 @@ discard block |
||
1322 | 1382 | $data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data); |
1323 | 1383 | |
1324 | 1384 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
1325 | - if (!empty($context['browser']['is_opera'])) |
|
1326 | - $data .= ' '; |
|
1385 | + if (!empty($context['browser']['is_opera'])) { |
|
1386 | + $data .= ' '; |
|
1387 | + } |
|
1327 | 1388 | } |
1328 | 1389 | }, |
1329 | 1390 | 'block_level' => true, |
@@ -1342,8 +1403,9 @@ discard block |
||
1342 | 1403 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
1343 | 1404 | { |
1344 | 1405 | // Do PHP code coloring? |
1345 | - if ($php_parts[$php_i] != '<?php') |
|
1346 | - continue; |
|
1406 | + if ($php_parts[$php_i] != '<?php') { |
|
1407 | + continue; |
|
1408 | + } |
|
1347 | 1409 | |
1348 | 1410 | $php_string = ''; |
1349 | 1411 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1359,8 +1421,9 @@ discard block |
||
1359 | 1421 | $data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]); |
1360 | 1422 | |
1361 | 1423 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
1362 | - if (!empty($context['browser']['is_opera'])) |
|
1363 | - $data[0] .= ' '; |
|
1424 | + if (!empty($context['browser']['is_opera'])) { |
|
1425 | + $data[0] .= ' '; |
|
1426 | + } |
|
1364 | 1427 | } |
1365 | 1428 | }, |
1366 | 1429 | 'block_level' => true, |
@@ -1401,10 +1464,11 @@ discard block |
||
1401 | 1464 | { |
1402 | 1465 | $class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"'; |
1403 | 1466 | |
1404 | - if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) |
|
1405 | - $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; |
|
1406 | - else |
|
1407 | - $css = ''; |
|
1467 | + if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) { |
|
1468 | + $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; |
|
1469 | + } else { |
|
1470 | + $css = ''; |
|
1471 | + } |
|
1408 | 1472 | |
1409 | 1473 | $data = $class . $css; |
1410 | 1474 | }, |
@@ -1419,8 +1483,9 @@ discard block |
||
1419 | 1483 | { |
1420 | 1484 | $data = strtr($data, array('<br />' => '')); |
1421 | 1485 | |
1422 | - if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) |
|
1423 | - $data = 'ftp://' . $data; |
|
1486 | + if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) { |
|
1487 | + $data = 'ftp://' . $data; |
|
1488 | + } |
|
1424 | 1489 | }, |
1425 | 1490 | ), |
1426 | 1491 | array( |
@@ -1430,8 +1495,9 @@ discard block |
||
1430 | 1495 | 'after' => '</a>', |
1431 | 1496 | 'validate' => function(&$tag, &$data, $disabled) |
1432 | 1497 | { |
1433 | - if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) |
|
1434 | - $data = 'ftp://' . $data; |
|
1498 | + if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) { |
|
1499 | + $data = 'ftp://' . $data; |
|
1500 | + } |
|
1435 | 1501 | }, |
1436 | 1502 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
1437 | 1503 | 'disabled_after' => ' ($1)', |
@@ -1491,17 +1557,20 @@ discard block |
||
1491 | 1557 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1492 | 1558 | if ($image_proxy_enabled) |
1493 | 1559 | { |
1494 | - if (!empty($user_info['possibly_robot'])) |
|
1495 | - return; |
|
1560 | + if (!empty($user_info['possibly_robot'])) { |
|
1561 | + return; |
|
1562 | + } |
|
1496 | 1563 | |
1497 | - if (empty($scheme)) |
|
1498 | - $data = 'http://' . ltrim($data, ':/'); |
|
1564 | + if (empty($scheme)) { |
|
1565 | + $data = 'http://' . ltrim($data, ':/'); |
|
1566 | + } |
|
1499 | 1567 | |
1500 | - if ($scheme != 'https') |
|
1501 | - $data = get_proxied_url($data); |
|
1568 | + if ($scheme != 'https') { |
|
1569 | + $data = get_proxied_url($data); |
|
1570 | + } |
|
1571 | + } elseif (empty($scheme)) { |
|
1572 | + $data = '//' . ltrim($data, ':/'); |
|
1502 | 1573 | } |
1503 | - elseif (empty($scheme)) |
|
1504 | - $data = '//' . ltrim($data, ':/'); |
|
1505 | 1574 | }, |
1506 | 1575 | 'disabled_content' => '($1)', |
1507 | 1576 | ), |
@@ -1517,17 +1586,20 @@ discard block |
||
1517 | 1586 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1518 | 1587 | if ($image_proxy_enabled) |
1519 | 1588 | { |
1520 | - if (!empty($user_info['possibly_robot'])) |
|
1521 | - return; |
|
1589 | + if (!empty($user_info['possibly_robot'])) { |
|
1590 | + return; |
|
1591 | + } |
|
1522 | 1592 | |
1523 | - if (empty($scheme)) |
|
1524 | - $data = 'http://' . ltrim($data, ':/'); |
|
1593 | + if (empty($scheme)) { |
|
1594 | + $data = 'http://' . ltrim($data, ':/'); |
|
1595 | + } |
|
1525 | 1596 | |
1526 | - if ($scheme != 'https') |
|
1527 | - $data = get_proxied_url($data); |
|
1597 | + if ($scheme != 'https') { |
|
1598 | + $data = get_proxied_url($data); |
|
1599 | + } |
|
1600 | + } elseif (empty($scheme)) { |
|
1601 | + $data = '//' . ltrim($data, ':/'); |
|
1528 | 1602 | } |
1529 | - elseif (empty($scheme)) |
|
1530 | - $data = '//' . ltrim($data, ':/'); |
|
1531 | 1603 | }, |
1532 | 1604 | 'disabled_content' => '($1)', |
1533 | 1605 | ), |
@@ -1539,8 +1611,9 @@ discard block |
||
1539 | 1611 | { |
1540 | 1612 | $data = strtr($data, array('<br>' => '')); |
1541 | 1613 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1542 | - if (empty($scheme)) |
|
1543 | - $data = '//' . ltrim($data, ':/'); |
|
1614 | + if (empty($scheme)) { |
|
1615 | + $data = '//' . ltrim($data, ':/'); |
|
1616 | + } |
|
1544 | 1617 | }, |
1545 | 1618 | ), |
1546 | 1619 | array( |
@@ -1551,13 +1624,14 @@ discard block |
||
1551 | 1624 | 'after' => '</a>', |
1552 | 1625 | 'validate' => function (&$tag, &$data, $disabled) |
1553 | 1626 | { |
1554 | - if (substr($data, 0, 1) == '#') |
|
1555 | - $data = '#post_' . substr($data, 1); |
|
1556 | - else |
|
1627 | + if (substr($data, 0, 1) == '#') { |
|
1628 | + $data = '#post_' . substr($data, 1); |
|
1629 | + } else |
|
1557 | 1630 | { |
1558 | 1631 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1559 | - if (empty($scheme)) |
|
1560 | - $data = '//' . ltrim($data, ':/'); |
|
1632 | + if (empty($scheme)) { |
|
1633 | + $data = '//' . ltrim($data, ':/'); |
|
1634 | + } |
|
1561 | 1635 | } |
1562 | 1636 | }, |
1563 | 1637 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
@@ -1648,8 +1722,9 @@ discard block |
||
1648 | 1722 | { |
1649 | 1723 | $add_begin = substr(trim($data), 0, 5) != '<?'; |
1650 | 1724 | $data = highlight_php_code($add_begin ? '<?php ' . $data . '?>' : $data); |
1651 | - if ($add_begin) |
|
1652 | - $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
1725 | + if ($add_begin) { |
|
1726 | + $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
1727 | + } |
|
1653 | 1728 | } |
1654 | 1729 | }, |
1655 | 1730 | 'block_level' => false, |
@@ -1741,20 +1816,17 @@ discard block |
||
1741 | 1816 | 'validate' => function(&$tag, &$data, $disabled) |
1742 | 1817 | { |
1743 | 1818 | |
1744 | - if ($data[1] == 'top' || (is_numeric($data[1]) && $data[1] < 50)) |
|
1745 | - $data[1] = '0 -2px 1px'; |
|
1746 | - |
|
1747 | - elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100)) |
|
1748 | - $data[1] = '2px 0 1px'; |
|
1749 | - |
|
1750 | - elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190)) |
|
1751 | - $data[1] = '0 2px 1px'; |
|
1752 | - |
|
1753 | - elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280)) |
|
1754 | - $data[1] = '-2px 0 1px'; |
|
1755 | - |
|
1756 | - else |
|
1757 | - $data[1] = '1px 1px 1px'; |
|
1819 | + if ($data[1] == 'top' || (is_numeric($data[1]) && $data[1] < 50)) { |
|
1820 | + $data[1] = '0 -2px 1px'; |
|
1821 | + } elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100)) { |
|
1822 | + $data[1] = '2px 0 1px'; |
|
1823 | + } elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190)) { |
|
1824 | + $data[1] = '0 2px 1px'; |
|
1825 | + } elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280)) { |
|
1826 | + $data[1] = '-2px 0 1px'; |
|
1827 | + } else { |
|
1828 | + $data[1] = '1px 1px 1px'; |
|
1829 | + } |
|
1758 | 1830 | }, |
1759 | 1831 | ), |
1760 | 1832 | array( |
@@ -1810,10 +1882,11 @@ discard block |
||
1810 | 1882 | 'content' => '$1', |
1811 | 1883 | 'validate' => function (&$tag, &$data, $disabled) |
1812 | 1884 | { |
1813 | - if (is_numeric($data)) |
|
1814 | - $data = timeformat($data); |
|
1815 | - else |
|
1816 | - $tag['content'] = '[time]$1[/time]'; |
|
1885 | + if (is_numeric($data)) { |
|
1886 | + $data = timeformat($data); |
|
1887 | + } else { |
|
1888 | + $tag['content'] = '[time]$1[/time]'; |
|
1889 | + } |
|
1817 | 1890 | }, |
1818 | 1891 | ), |
1819 | 1892 | array( |
@@ -1845,8 +1918,9 @@ discard block |
||
1845 | 1918 | { |
1846 | 1919 | $data = strtr($data, array('<br>' => '')); |
1847 | 1920 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1848 | - if (empty($scheme)) |
|
1849 | - $data = '//' . ltrim($data, ':/'); |
|
1921 | + if (empty($scheme)) { |
|
1922 | + $data = '//' . ltrim($data, ':/'); |
|
1923 | + } |
|
1850 | 1924 | }, |
1851 | 1925 | ), |
1852 | 1926 | array( |
@@ -1858,8 +1932,9 @@ discard block |
||
1858 | 1932 | 'validate' => function (&$tag, &$data, $disabled) |
1859 | 1933 | { |
1860 | 1934 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1861 | - if (empty($scheme)) |
|
1862 | - $data = '//' . ltrim($data, ':/'); |
|
1935 | + if (empty($scheme)) { |
|
1936 | + $data = '//' . ltrim($data, ':/'); |
|
1937 | + } |
|
1863 | 1938 | }, |
1864 | 1939 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
1865 | 1940 | 'disabled_after' => ' ($1)', |
@@ -1886,12 +1961,13 @@ discard block |
||
1886 | 1961 | ); |
1887 | 1962 | |
1888 | 1963 | // Handle legacy bbc codes. |
1889 | - foreach ($context['legacy_bbc'] as $bbc) |
|
1890 | - $codes[] = array( |
|
1964 | + foreach ($context['legacy_bbc'] as $bbc) { |
|
1965 | + $codes[] = array( |
|
1891 | 1966 | 'tag' => $bbc, |
1892 | 1967 | 'before' => '', |
1893 | 1968 | 'after' => '', |
1894 | 1969 | ); |
1970 | + } |
|
1895 | 1971 | |
1896 | 1972 | // Let mods add new BBC without hassle. |
1897 | 1973 | call_integration_hook('integrate_bbc_codes', array(&$codes, &$no_autolink_tags)); |
@@ -1899,8 +1975,9 @@ discard block |
||
1899 | 1975 | // This is mainly for the bbc manager, so it's easy to add tags above. Custom BBC should be added above this line. |
1900 | 1976 | if ($message === false) |
1901 | 1977 | { |
1902 | - if (isset($temp_bbc)) |
|
1903 | - $bbc_codes = $temp_bbc; |
|
1978 | + if (isset($temp_bbc)) { |
|
1979 | + $bbc_codes = $temp_bbc; |
|
1980 | + } |
|
1904 | 1981 | usort($codes, function ($a, $b) { |
1905 | 1982 | return strcmp($a['tag'], $b['tag']); |
1906 | 1983 | }); |
@@ -1920,8 +1997,9 @@ discard block |
||
1920 | 1997 | ); |
1921 | 1998 | if (!isset($disabled['li']) && !isset($disabled['list'])) |
1922 | 1999 | { |
1923 | - foreach ($itemcodes as $c => $dummy) |
|
1924 | - $bbc_codes[$c] = array(); |
|
2000 | + foreach ($itemcodes as $c => $dummy) { |
|
2001 | + $bbc_codes[$c] = array(); |
|
2002 | + } |
|
1925 | 2003 | } |
1926 | 2004 | |
1927 | 2005 | // Shhhh! |
@@ -1942,12 +2020,14 @@ discard block |
||
1942 | 2020 | foreach ($codes as $code) |
1943 | 2021 | { |
1944 | 2022 | // Make it easier to process parameters later |
1945 | - if (!empty($code['parameters'])) |
|
1946 | - ksort($code['parameters'], SORT_STRING); |
|
2023 | + if (!empty($code['parameters'])) { |
|
2024 | + ksort($code['parameters'], SORT_STRING); |
|
2025 | + } |
|
1947 | 2026 | |
1948 | 2027 | // If we are not doing every tag only do ones we are interested in. |
1949 | - if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) |
|
1950 | - $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
2028 | + if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) { |
|
2029 | + $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
2030 | + } |
|
1951 | 2031 | } |
1952 | 2032 | $codes = null; |
1953 | 2033 | } |
@@ -1958,8 +2038,9 @@ discard block |
||
1958 | 2038 | // It's likely this will change if the message is modified. |
1959 | 2039 | $cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . $smcFunc['json_encode']($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']); |
1960 | 2040 | |
1961 | - if (($temp = cache_get_data($cache_key, 240)) != null) |
|
1962 | - return $temp; |
|
2041 | + if (($temp = cache_get_data($cache_key, 240)) != null) { |
|
2042 | + return $temp; |
|
2043 | + } |
|
1963 | 2044 | |
1964 | 2045 | $cache_t = microtime(true); |
1965 | 2046 | } |
@@ -1991,8 +2072,9 @@ discard block |
||
1991 | 2072 | $disabled['flash'] = true; |
1992 | 2073 | |
1993 | 2074 | // @todo Change maybe? |
1994 | - if (!isset($_GET['images'])) |
|
1995 | - $disabled['img'] = true; |
|
2075 | + if (!isset($_GET['images'])) { |
|
2076 | + $disabled['img'] = true; |
|
2077 | + } |
|
1996 | 2078 | |
1997 | 2079 | // @todo Interface/setting to add more? |
1998 | 2080 | } |
@@ -2003,8 +2085,9 @@ discard block |
||
2003 | 2085 | $alltags = array(); |
2004 | 2086 | foreach ($bbc_codes as $section) |
2005 | 2087 | { |
2006 | - foreach ($section as $code) |
|
2007 | - $alltags[] = $code['tag']; |
|
2088 | + foreach ($section as $code) { |
|
2089 | + $alltags[] = $code['tag']; |
|
2090 | + } |
|
2008 | 2091 | } |
2009 | 2092 | $alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b'; |
2010 | 2093 | |
@@ -2016,8 +2099,9 @@ discard block |
||
2016 | 2099 | $pos = isset($matches[0][1]) ? $matches[0][1] : false; |
2017 | 2100 | |
2018 | 2101 | // Failsafe. |
2019 | - if ($pos === false || $last_pos > $pos) |
|
2020 | - $pos = strlen($message) + 1; |
|
2102 | + if ($pos === false || $last_pos > $pos) { |
|
2103 | + $pos = strlen($message) + 1; |
|
2104 | + } |
|
2021 | 2105 | |
2022 | 2106 | // Can't have a one letter smiley, URL, or email! (sorry.) |
2023 | 2107 | if ($last_pos < $pos - 1) |
@@ -2035,8 +2119,9 @@ discard block |
||
2035 | 2119 | |
2036 | 2120 | // <br> should be empty. |
2037 | 2121 | $empty_tags = array('br', 'hr'); |
2038 | - foreach ($empty_tags as $tag) |
|
2039 | - $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '<' . $tag . '>', $data); |
|
2122 | + foreach ($empty_tags as $tag) { |
|
2123 | + $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '<' . $tag . '>', $data); |
|
2124 | + } |
|
2040 | 2125 | |
2041 | 2126 | // b, u, i, s, pre... basic tags. |
2042 | 2127 | $closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong'); |
@@ -2045,8 +2130,9 @@ discard block |
||
2045 | 2130 | $diff = substr_count($data, '<' . $tag . '>') - substr_count($data, '</' . $tag . '>'); |
2046 | 2131 | $data = strtr($data, array('<' . $tag . '>' => '<' . $tag . '>', '</' . $tag . '>' => '</' . $tag . '>')); |
2047 | 2132 | |
2048 | - if ($diff > 0) |
|
2049 | - $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
2133 | + if ($diff > 0) { |
|
2134 | + $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
2135 | + } |
|
2050 | 2136 | } |
2051 | 2137 | |
2052 | 2138 | // Do <img ...> - with security... action= -> action-. |
@@ -2059,8 +2145,9 @@ discard block |
||
2059 | 2145 | $alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^"|"$~', '', $matches[3][$match]); |
2060 | 2146 | |
2061 | 2147 | // Remove action= from the URL - no funny business, now. |
2062 | - if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) |
|
2063 | - $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
2148 | + if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) { |
|
2149 | + $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
2150 | + } |
|
2064 | 2151 | |
2065 | 2152 | $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
2066 | 2153 | } |
@@ -2075,16 +2162,18 @@ discard block |
||
2075 | 2162 | $no_autolink_area = false; |
2076 | 2163 | if (!empty($open_tags)) |
2077 | 2164 | { |
2078 | - foreach ($open_tags as $open_tag) |
|
2079 | - if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
2165 | + foreach ($open_tags as $open_tag) { |
|
2166 | + if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
2080 | 2167 | $no_autolink_area = true; |
2168 | + } |
|
2081 | 2169 | } |
2082 | 2170 | |
2083 | 2171 | // Don't go backwards. |
2084 | 2172 | // @todo Don't think is the real solution.... |
2085 | 2173 | $lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0; |
2086 | - if ($pos < $lastAutoPos) |
|
2087 | - $no_autolink_area = true; |
|
2174 | + if ($pos < $lastAutoPos) { |
|
2175 | + $no_autolink_area = true; |
|
2176 | + } |
|
2088 | 2177 | $lastAutoPos = $pos; |
2089 | 2178 | |
2090 | 2179 | if (!$no_autolink_area) |
@@ -2189,29 +2278,33 @@ discard block |
||
2189 | 2278 | $url = array_shift($matches); |
2190 | 2279 | |
2191 | 2280 | // If this isn't a clean URL, bail out |
2192 | - if ($url != sanitize_iri($url)) |
|
2193 | - return $url; |
|
2281 | + if ($url != sanitize_iri($url)) { |
|
2282 | + return $url; |
|
2283 | + } |
|
2194 | 2284 | |
2195 | 2285 | $scheme = parse_url($url, PHP_URL_SCHEME); |
2196 | 2286 | |
2197 | 2287 | if ($scheme == 'mailto') |
2198 | 2288 | { |
2199 | 2289 | $email_address = str_replace('mailto:', '', $url); |
2200 | - if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) |
|
2201 | - return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
2202 | - else |
|
2203 | - return $url; |
|
2290 | + if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) { |
|
2291 | + return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
2292 | + } else { |
|
2293 | + return $url; |
|
2294 | + } |
|
2204 | 2295 | } |
2205 | 2296 | |
2206 | 2297 | // Are we linking a schemeless URL or naked domain name (e.g. "example.com")? |
2207 | - if (empty($scheme)) |
|
2208 | - $fullUrl = '//' . ltrim($url, ':/'); |
|
2209 | - else |
|
2210 | - $fullUrl = $url; |
|
2298 | + if (empty($scheme)) { |
|
2299 | + $fullUrl = '//' . ltrim($url, ':/'); |
|
2300 | + } else { |
|
2301 | + $fullUrl = $url; |
|
2302 | + } |
|
2211 | 2303 | |
2212 | 2304 | // Make sure that $fullUrl really is valid |
2213 | - if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) |
|
2214 | - return $url; |
|
2305 | + if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) { |
|
2306 | + return $url; |
|
2307 | + } |
|
2215 | 2308 | |
2216 | 2309 | return '[url="' . str_replace(array('[', ']'), array('[', ']'), $fullUrl) . '"]' . $url . '[/url]'; |
2217 | 2310 | }, $data); |
@@ -2260,22 +2353,25 @@ discard block |
||
2260 | 2353 | } |
2261 | 2354 | |
2262 | 2355 | // Are we there yet? Are we there yet? |
2263 | - if ($pos >= strlen($message) - 1) |
|
2264 | - break; |
|
2356 | + if ($pos >= strlen($message) - 1) { |
|
2357 | + break; |
|
2358 | + } |
|
2265 | 2359 | |
2266 | 2360 | $tags = strtolower($message[$pos + 1]); |
2267 | 2361 | |
2268 | 2362 | if ($tags == '/' && !empty($open_tags)) |
2269 | 2363 | { |
2270 | 2364 | $pos2 = strpos($message, ']', $pos + 1); |
2271 | - if ($pos2 == $pos + 2) |
|
2272 | - continue; |
|
2365 | + if ($pos2 == $pos + 2) { |
|
2366 | + continue; |
|
2367 | + } |
|
2273 | 2368 | |
2274 | 2369 | $look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2)); |
2275 | 2370 | |
2276 | 2371 | // A closing tag that doesn't match any open tags? Skip it. |
2277 | - if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) |
|
2278 | - continue; |
|
2372 | + if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) { |
|
2373 | + continue; |
|
2374 | + } |
|
2279 | 2375 | |
2280 | 2376 | $to_close = array(); |
2281 | 2377 | $block_level = null; |
@@ -2283,8 +2379,9 @@ discard block |
||
2283 | 2379 | do |
2284 | 2380 | { |
2285 | 2381 | $tag = array_pop($open_tags); |
2286 | - if (!$tag) |
|
2287 | - break; |
|
2382 | + if (!$tag) { |
|
2383 | + break; |
|
2384 | + } |
|
2288 | 2385 | |
2289 | 2386 | if (!empty($tag['block_level'])) |
2290 | 2387 | { |
@@ -2298,10 +2395,11 @@ discard block |
||
2298 | 2395 | // The idea is, if we are LOOKING for a block level tag, we can close them on the way. |
2299 | 2396 | if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]])) |
2300 | 2397 | { |
2301 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
2302 | - if ($temp['tag'] == $look_for) |
|
2398 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
2399 | + if ($temp['tag'] == $look_for) |
|
2303 | 2400 | { |
2304 | 2401 | $block_level = !empty($temp['block_level']); |
2402 | + } |
|
2305 | 2403 | break; |
2306 | 2404 | } |
2307 | 2405 | } |
@@ -2323,15 +2421,15 @@ discard block |
||
2323 | 2421 | { |
2324 | 2422 | $open_tags = $to_close; |
2325 | 2423 | continue; |
2326 | - } |
|
2327 | - elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
2424 | + } elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
2328 | 2425 | { |
2329 | 2426 | if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]])) |
2330 | 2427 | { |
2331 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
2332 | - if ($temp['tag'] == $look_for) |
|
2428 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
2429 | + if ($temp['tag'] == $look_for) |
|
2333 | 2430 | { |
2334 | 2431 | $block_level = !empty($temp['block_level']); |
2432 | + } |
|
2335 | 2433 | break; |
2336 | 2434 | } |
2337 | 2435 | } |
@@ -2339,8 +2437,9 @@ discard block |
||
2339 | 2437 | // We're not looking for a block level tag (or maybe even a tag that exists...) |
2340 | 2438 | if (!$block_level) |
2341 | 2439 | { |
2342 | - foreach ($to_close as $tag) |
|
2343 | - array_push($open_tags, $tag); |
|
2440 | + foreach ($to_close as $tag) { |
|
2441 | + array_push($open_tags, $tag); |
|
2442 | + } |
|
2344 | 2443 | continue; |
2345 | 2444 | } |
2346 | 2445 | } |
@@ -2353,14 +2452,17 @@ discard block |
||
2353 | 2452 | |
2354 | 2453 | // See the comment at the end of the big loop - just eating whitespace ;). |
2355 | 2454 | $whitespace_regex = ''; |
2356 | - if (!empty($tag['block_level'])) |
|
2357 | - $whitespace_regex .= '( |\s)*(<br>)?'; |
|
2455 | + if (!empty($tag['block_level'])) { |
|
2456 | + $whitespace_regex .= '( |\s)*(<br>)?'; |
|
2457 | + } |
|
2358 | 2458 | // Trim one line of whitespace after unnested tags, but all of it after nested ones |
2359 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') |
|
2360 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2459 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside') { |
|
2460 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2461 | + } |
|
2361 | 2462 | |
2362 | - if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) |
|
2363 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2463 | + if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { |
|
2464 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2465 | + } |
|
2364 | 2466 | } |
2365 | 2467 | |
2366 | 2468 | if (!empty($to_close)) |
@@ -2373,8 +2475,9 @@ discard block |
||
2373 | 2475 | } |
2374 | 2476 | |
2375 | 2477 | // No tags for this character, so just keep going (fastest possible course.) |
2376 | - if (!isset($bbc_codes[$tags])) |
|
2377 | - continue; |
|
2478 | + if (!isset($bbc_codes[$tags])) { |
|
2479 | + continue; |
|
2480 | + } |
|
2378 | 2481 | |
2379 | 2482 | $inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1]; |
2380 | 2483 | $tag = null; |
@@ -2383,48 +2486,57 @@ discard block |
||
2383 | 2486 | $pt_strlen = strlen($possible['tag']); |
2384 | 2487 | |
2385 | 2488 | // Not a match? |
2386 | - if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) |
|
2387 | - continue; |
|
2489 | + if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) { |
|
2490 | + continue; |
|
2491 | + } |
|
2388 | 2492 | |
2389 | 2493 | $next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : ''; |
2390 | 2494 | |
2391 | 2495 | // A tag is the last char maybe |
2392 | - if ($next_c == '') |
|
2393 | - break; |
|
2496 | + if ($next_c == '') { |
|
2497 | + break; |
|
2498 | + } |
|
2394 | 2499 | |
2395 | 2500 | // A test validation? |
2396 | - if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) |
|
2397 | - continue; |
|
2501 | + if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) { |
|
2502 | + continue; |
|
2503 | + } |
|
2398 | 2504 | // Do we want parameters? |
2399 | 2505 | elseif (!empty($possible['parameters'])) |
2400 | 2506 | { |
2401 | - if ($next_c != ' ') |
|
2402 | - continue; |
|
2403 | - } |
|
2404 | - elseif (isset($possible['type'])) |
|
2507 | + if ($next_c != ' ') { |
|
2508 | + continue; |
|
2509 | + } |
|
2510 | + } elseif (isset($possible['type'])) |
|
2405 | 2511 | { |
2406 | 2512 | // Do we need an equal sign? |
2407 | - if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') |
|
2408 | - continue; |
|
2513 | + if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') { |
|
2514 | + continue; |
|
2515 | + } |
|
2409 | 2516 | // Maybe we just want a /... |
2410 | - if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') |
|
2411 | - continue; |
|
2517 | + if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') { |
|
2518 | + continue; |
|
2519 | + } |
|
2412 | 2520 | // An immediate ]? |
2413 | - if ($possible['type'] == 'unparsed_content' && $next_c != ']') |
|
2414 | - continue; |
|
2521 | + if ($possible['type'] == 'unparsed_content' && $next_c != ']') { |
|
2522 | + continue; |
|
2523 | + } |
|
2415 | 2524 | } |
2416 | 2525 | // No type means 'parsed_content', which demands an immediate ] without parameters! |
2417 | - elseif ($next_c != ']') |
|
2418 | - continue; |
|
2526 | + elseif ($next_c != ']') { |
|
2527 | + continue; |
|
2528 | + } |
|
2419 | 2529 | |
2420 | 2530 | // Check allowed tree? |
2421 | - if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) |
|
2422 | - continue; |
|
2423 | - elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) |
|
2424 | - continue; |
|
2531 | + if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) { |
|
2532 | + continue; |
|
2533 | + } elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) { |
|
2534 | + continue; |
|
2535 | + } |
|
2425 | 2536 | // If this is in the list of disallowed child tags, don't parse it. |
2426 | - elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) |
|
2427 | - continue; |
|
2537 | + elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) { |
|
2538 | + continue; |
|
2539 | + } |
|
2428 | 2540 | |
2429 | 2541 | $pos1 = $pos + 1 + $pt_strlen + 1; |
2430 | 2542 | |
@@ -2436,8 +2548,9 @@ discard block |
||
2436 | 2548 | foreach ($open_tags as $open_quote) |
2437 | 2549 | { |
2438 | 2550 | // Every parent quote this quote has flips the styling |
2439 | - if ($open_quote['tag'] == 'quote') |
|
2440 | - $quote_alt = !$quote_alt; |
|
2551 | + if ($open_quote['tag'] == 'quote') { |
|
2552 | + $quote_alt = !$quote_alt; |
|
2553 | + } |
|
2441 | 2554 | } |
2442 | 2555 | // Add a class to the quote to style alternating blockquotes |
2443 | 2556 | $possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">')); |
@@ -2448,8 +2561,9 @@ discard block |
||
2448 | 2561 | { |
2449 | 2562 | // Build a regular expression for each parameter for the current tag. |
2450 | 2563 | $preg = array(); |
2451 | - foreach ($possible['parameters'] as $p => $info) |
|
2452 | - $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
2564 | + foreach ($possible['parameters'] as $p => $info) { |
|
2565 | + $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
2566 | + } |
|
2453 | 2567 | |
2454 | 2568 | // Extract the string that potentially holds our parameters. |
2455 | 2569 | $blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos)); |
@@ -2468,24 +2582,27 @@ discard block |
||
2468 | 2582 | |
2469 | 2583 | $match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0; |
2470 | 2584 | |
2471 | - if ($match) |
|
2472 | - $blob_counter = count($blobs) + 1; |
|
2585 | + if ($match) { |
|
2586 | + $blob_counter = count($blobs) + 1; |
|
2587 | + } |
|
2473 | 2588 | } |
2474 | 2589 | |
2475 | 2590 | // Didn't match our parameter list, try the next possible. |
2476 | - if (!$match) |
|
2477 | - continue; |
|
2591 | + if (!$match) { |
|
2592 | + continue; |
|
2593 | + } |
|
2478 | 2594 | |
2479 | 2595 | $params = array(); |
2480 | 2596 | for ($i = 1, $n = count($matches); $i < $n; $i += 2) |
2481 | 2597 | { |
2482 | 2598 | $key = strtok(ltrim($matches[$i]), '='); |
2483 | - if (isset($possible['parameters'][$key]['value'])) |
|
2484 | - $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
2485 | - elseif (isset($possible['parameters'][$key]['validate'])) |
|
2486 | - $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
2487 | - else |
|
2488 | - $params['{' . $key . '}'] = $matches[$i + 1]; |
|
2599 | + if (isset($possible['parameters'][$key]['value'])) { |
|
2600 | + $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
2601 | + } elseif (isset($possible['parameters'][$key]['validate'])) { |
|
2602 | + $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
2603 | + } else { |
|
2604 | + $params['{' . $key . '}'] = $matches[$i + 1]; |
|
2605 | + } |
|
2489 | 2606 | |
2490 | 2607 | // Just to make sure: replace any $ or { so they can't interpolate wrongly. |
2491 | 2608 | $params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '$', '{' => '{')); |
@@ -2493,23 +2610,26 @@ discard block |
||
2493 | 2610 | |
2494 | 2611 | foreach ($possible['parameters'] as $p => $info) |
2495 | 2612 | { |
2496 | - if (!isset($params['{' . $p . '}'])) |
|
2497 | - $params['{' . $p . '}'] = ''; |
|
2613 | + if (!isset($params['{' . $p . '}'])) { |
|
2614 | + $params['{' . $p . '}'] = ''; |
|
2615 | + } |
|
2498 | 2616 | } |
2499 | 2617 | |
2500 | 2618 | $tag = $possible; |
2501 | 2619 | |
2502 | 2620 | // Put the parameters into the string. |
2503 | - if (isset($tag['before'])) |
|
2504 | - $tag['before'] = strtr($tag['before'], $params); |
|
2505 | - if (isset($tag['after'])) |
|
2506 | - $tag['after'] = strtr($tag['after'], $params); |
|
2507 | - if (isset($tag['content'])) |
|
2508 | - $tag['content'] = strtr($tag['content'], $params); |
|
2621 | + if (isset($tag['before'])) { |
|
2622 | + $tag['before'] = strtr($tag['before'], $params); |
|
2623 | + } |
|
2624 | + if (isset($tag['after'])) { |
|
2625 | + $tag['after'] = strtr($tag['after'], $params); |
|
2626 | + } |
|
2627 | + if (isset($tag['content'])) { |
|
2628 | + $tag['content'] = strtr($tag['content'], $params); |
|
2629 | + } |
|
2509 | 2630 | |
2510 | 2631 | $pos1 += strlen($given_param_string); |
2511 | - } |
|
2512 | - else |
|
2632 | + } else |
|
2513 | 2633 | { |
2514 | 2634 | $tag = $possible; |
2515 | 2635 | $params = array(); |
@@ -2520,8 +2640,9 @@ discard block |
||
2520 | 2640 | // Item codes are complicated buggers... they are implicit [li]s and can make [list]s! |
2521 | 2641 | if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li'])) |
2522 | 2642 | { |
2523 | - if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) |
|
2524 | - continue; |
|
2643 | + if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) { |
|
2644 | + continue; |
|
2645 | + } |
|
2525 | 2646 | |
2526 | 2647 | $tag = $itemcodes[$message[$pos + 1]]; |
2527 | 2648 | |
@@ -2542,9 +2663,9 @@ discard block |
||
2542 | 2663 | { |
2543 | 2664 | array_pop($open_tags); |
2544 | 2665 | $code = '</li>'; |
2666 | + } else { |
|
2667 | + $code = ''; |
|
2545 | 2668 | } |
2546 | - else |
|
2547 | - $code = ''; |
|
2548 | 2669 | |
2549 | 2670 | // Now we open a new tag. |
2550 | 2671 | $open_tags[] = array( |
@@ -2591,12 +2712,14 @@ discard block |
||
2591 | 2712 | } |
2592 | 2713 | |
2593 | 2714 | // No tag? Keep looking, then. Silly people using brackets without actual tags. |
2594 | - if ($tag === null) |
|
2595 | - continue; |
|
2715 | + if ($tag === null) { |
|
2716 | + continue; |
|
2717 | + } |
|
2596 | 2718 | |
2597 | 2719 | // Propagate the list to the child (so wrapping the disallowed tag won't work either.) |
2598 | - if (isset($inside['disallow_children'])) |
|
2599 | - $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
2720 | + if (isset($inside['disallow_children'])) { |
|
2721 | + $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
2722 | + } |
|
2600 | 2723 | |
2601 | 2724 | // Is this tag disabled? |
2602 | 2725 | if (isset($disabled[$tag['tag']])) |
@@ -2606,14 +2729,13 @@ discard block |
||
2606 | 2729 | $tag['before'] = !empty($tag['block_level']) ? '<div>' : ''; |
2607 | 2730 | $tag['after'] = !empty($tag['block_level']) ? '</div>' : ''; |
2608 | 2731 | $tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1'); |
2609 | - } |
|
2610 | - elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
2732 | + } elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
2611 | 2733 | { |
2612 | 2734 | $tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : ''); |
2613 | 2735 | $tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : ''); |
2736 | + } else { |
|
2737 | + $tag['content'] = $tag['disabled_content']; |
|
2614 | 2738 | } |
2615 | - else |
|
2616 | - $tag['content'] = $tag['disabled_content']; |
|
2617 | 2739 | } |
2618 | 2740 | |
2619 | 2741 | // we use this a lot |
@@ -2623,8 +2745,9 @@ discard block |
||
2623 | 2745 | if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level'])) |
2624 | 2746 | { |
2625 | 2747 | $n = count($open_tags) - 1; |
2626 | - while (empty($open_tags[$n]['block_level']) && $n >= 0) |
|
2627 | - $n--; |
|
2748 | + while (empty($open_tags[$n]['block_level']) && $n >= 0) { |
|
2749 | + $n--; |
|
2750 | + } |
|
2628 | 2751 | |
2629 | 2752 | // Close all the non block level tags so this tag isn't surrounded by them. |
2630 | 2753 | for ($i = count($open_tags) - 1; $i > $n; $i--) |
@@ -2636,12 +2759,15 @@ discard block |
||
2636 | 2759 | |
2637 | 2760 | // Trim or eat trailing stuff... see comment at the end of the big loop. |
2638 | 2761 | $whitespace_regex = ''; |
2639 | - if (!empty($tag['block_level'])) |
|
2640 | - $whitespace_regex .= '( |\s)*(<br>)?'; |
|
2641 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') |
|
2642 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2643 | - if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) |
|
2644 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2762 | + if (!empty($tag['block_level'])) { |
|
2763 | + $whitespace_regex .= '( |\s)*(<br>)?'; |
|
2764 | + } |
|
2765 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside') { |
|
2766 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
2767 | + } |
|
2768 | + if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { |
|
2769 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2770 | + } |
|
2645 | 2771 | |
2646 | 2772 | array_pop($open_tags); |
2647 | 2773 | } |
@@ -2662,16 +2788,19 @@ discard block |
||
2662 | 2788 | elseif ($tag['type'] == 'unparsed_content') |
2663 | 2789 | { |
2664 | 2790 | $pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1); |
2665 | - if ($pos2 === false) |
|
2666 | - continue; |
|
2791 | + if ($pos2 === false) { |
|
2792 | + continue; |
|
2793 | + } |
|
2667 | 2794 | |
2668 | 2795 | $data = substr($message, $pos1, $pos2 - $pos1); |
2669 | 2796 | |
2670 | - if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') |
|
2671 | - $data = substr($data, 4); |
|
2797 | + if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') { |
|
2798 | + $data = substr($data, 4); |
|
2799 | + } |
|
2672 | 2800 | |
2673 | - if (isset($tag['validate'])) |
|
2674 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2801 | + if (isset($tag['validate'])) { |
|
2802 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2803 | + } |
|
2675 | 2804 | |
2676 | 2805 | $code = strtr($tag['content'], array('$1' => $data)); |
2677 | 2806 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen); |
@@ -2686,34 +2815,40 @@ discard block |
||
2686 | 2815 | if (isset($tag['quoted'])) |
2687 | 2816 | { |
2688 | 2817 | $quoted = substr($message, $pos1, 6) == '"'; |
2689 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
2690 | - continue; |
|
2818 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
2819 | + continue; |
|
2820 | + } |
|
2691 | 2821 | |
2692 | - if ($quoted) |
|
2693 | - $pos1 += 6; |
|
2822 | + if ($quoted) { |
|
2823 | + $pos1 += 6; |
|
2824 | + } |
|
2825 | + } else { |
|
2826 | + $quoted = false; |
|
2694 | 2827 | } |
2695 | - else |
|
2696 | - $quoted = false; |
|
2697 | 2828 | |
2698 | 2829 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
2699 | - if ($pos2 === false) |
|
2700 | - continue; |
|
2830 | + if ($pos2 === false) { |
|
2831 | + continue; |
|
2832 | + } |
|
2701 | 2833 | |
2702 | 2834 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
2703 | - if ($pos3 === false) |
|
2704 | - continue; |
|
2835 | + if ($pos3 === false) { |
|
2836 | + continue; |
|
2837 | + } |
|
2705 | 2838 | |
2706 | 2839 | $data = array( |
2707 | 2840 | substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))), |
2708 | 2841 | substr($message, $pos1, $pos2 - $pos1) |
2709 | 2842 | ); |
2710 | 2843 | |
2711 | - if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') |
|
2712 | - $data[0] = substr($data[0], 4); |
|
2844 | + if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') { |
|
2845 | + $data[0] = substr($data[0], 4); |
|
2846 | + } |
|
2713 | 2847 | |
2714 | 2848 | // Validation for my parking, please! |
2715 | - if (isset($tag['validate'])) |
|
2716 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2849 | + if (isset($tag['validate'])) { |
|
2850 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2851 | + } |
|
2717 | 2852 | |
2718 | 2853 | $code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1])); |
2719 | 2854 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
@@ -2730,23 +2865,27 @@ discard block |
||
2730 | 2865 | elseif ($tag['type'] == 'unparsed_commas_content') |
2731 | 2866 | { |
2732 | 2867 | $pos2 = strpos($message, ']', $pos1); |
2733 | - if ($pos2 === false) |
|
2734 | - continue; |
|
2868 | + if ($pos2 === false) { |
|
2869 | + continue; |
|
2870 | + } |
|
2735 | 2871 | |
2736 | 2872 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
2737 | - if ($pos3 === false) |
|
2738 | - continue; |
|
2873 | + if ($pos3 === false) { |
|
2874 | + continue; |
|
2875 | + } |
|
2739 | 2876 | |
2740 | 2877 | // We want $1 to be the content, and the rest to be csv. |
2741 | 2878 | $data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1)); |
2742 | 2879 | $data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1); |
2743 | 2880 | |
2744 | - if (isset($tag['validate'])) |
|
2745 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2881 | + if (isset($tag['validate'])) { |
|
2882 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2883 | + } |
|
2746 | 2884 | |
2747 | 2885 | $code = $tag['content']; |
2748 | - foreach ($data as $k => $d) |
|
2749 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2886 | + foreach ($data as $k => $d) { |
|
2887 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2888 | + } |
|
2750 | 2889 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
2751 | 2890 | $pos += strlen($code) - 1 + 2; |
2752 | 2891 | } |
@@ -2754,24 +2893,28 @@ discard block |
||
2754 | 2893 | elseif ($tag['type'] == 'unparsed_commas') |
2755 | 2894 | { |
2756 | 2895 | $pos2 = strpos($message, ']', $pos1); |
2757 | - if ($pos2 === false) |
|
2758 | - continue; |
|
2896 | + if ($pos2 === false) { |
|
2897 | + continue; |
|
2898 | + } |
|
2759 | 2899 | |
2760 | 2900 | $data = explode(',', substr($message, $pos1, $pos2 - $pos1)); |
2761 | 2901 | |
2762 | - if (isset($tag['validate'])) |
|
2763 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2902 | + if (isset($tag['validate'])) { |
|
2903 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2904 | + } |
|
2764 | 2905 | |
2765 | 2906 | // Fix after, for disabled code mainly. |
2766 | - foreach ($data as $k => $d) |
|
2767 | - $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
2907 | + foreach ($data as $k => $d) { |
|
2908 | + $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
2909 | + } |
|
2768 | 2910 | |
2769 | 2911 | $open_tags[] = $tag; |
2770 | 2912 | |
2771 | 2913 | // Replace them out, $1, $2, $3, $4, etc. |
2772 | 2914 | $code = $tag['before']; |
2773 | - foreach ($data as $k => $d) |
|
2774 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2915 | + foreach ($data as $k => $d) { |
|
2916 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2917 | + } |
|
2775 | 2918 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1); |
2776 | 2919 | $pos += strlen($code) - 1 + 2; |
2777 | 2920 | } |
@@ -2782,28 +2925,33 @@ discard block |
||
2782 | 2925 | if (isset($tag['quoted'])) |
2783 | 2926 | { |
2784 | 2927 | $quoted = substr($message, $pos1, 6) == '"'; |
2785 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
2786 | - continue; |
|
2928 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
2929 | + continue; |
|
2930 | + } |
|
2787 | 2931 | |
2788 | - if ($quoted) |
|
2789 | - $pos1 += 6; |
|
2932 | + if ($quoted) { |
|
2933 | + $pos1 += 6; |
|
2934 | + } |
|
2935 | + } else { |
|
2936 | + $quoted = false; |
|
2790 | 2937 | } |
2791 | - else |
|
2792 | - $quoted = false; |
|
2793 | 2938 | |
2794 | 2939 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
2795 | - if ($pos2 === false) |
|
2796 | - continue; |
|
2940 | + if ($pos2 === false) { |
|
2941 | + continue; |
|
2942 | + } |
|
2797 | 2943 | |
2798 | 2944 | $data = substr($message, $pos1, $pos2 - $pos1); |
2799 | 2945 | |
2800 | 2946 | // Validation for my parking, please! |
2801 | - if (isset($tag['validate'])) |
|
2802 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2947 | + if (isset($tag['validate'])) { |
|
2948 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2949 | + } |
|
2803 | 2950 | |
2804 | 2951 | // For parsed content, we must recurse to avoid security problems. |
2805 | - if ($tag['type'] != 'unparsed_equals') |
|
2806 | - $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
2952 | + if ($tag['type'] != 'unparsed_equals') { |
|
2953 | + $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
2954 | + } |
|
2807 | 2955 | |
2808 | 2956 | $tag['after'] = strtr($tag['after'], array('$1' => $data)); |
2809 | 2957 | |
@@ -2815,34 +2963,40 @@ discard block |
||
2815 | 2963 | } |
2816 | 2964 | |
2817 | 2965 | // If this is block level, eat any breaks after it. |
2818 | - if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') |
|
2819 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
2966 | + if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') { |
|
2967 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
2968 | + } |
|
2820 | 2969 | |
2821 | 2970 | // Are we trimming outside this tag? |
2822 | - if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) |
|
2823 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
2971 | + if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) { |
|
2972 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
2973 | + } |
|
2824 | 2974 | } |
2825 | 2975 | |
2826 | 2976 | // Close any remaining tags. |
2827 | - while ($tag = array_pop($open_tags)) |
|
2828 | - $message .= "\n" . $tag['after'] . "\n"; |
|
2977 | + while ($tag = array_pop($open_tags)) { |
|
2978 | + $message .= "\n" . $tag['after'] . "\n"; |
|
2979 | + } |
|
2829 | 2980 | |
2830 | 2981 | // Parse the smileys within the parts where it can be done safely. |
2831 | 2982 | if ($smileys === true) |
2832 | 2983 | { |
2833 | 2984 | $message_parts = explode("\n", $message); |
2834 | - for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) |
|
2835 | - parsesmileys($message_parts[$i]); |
|
2985 | + for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) { |
|
2986 | + parsesmileys($message_parts[$i]); |
|
2987 | + } |
|
2836 | 2988 | |
2837 | 2989 | $message = implode('', $message_parts); |
2838 | 2990 | } |
2839 | 2991 | |
2840 | 2992 | // No smileys, just get rid of the markers. |
2841 | - else |
|
2842 | - $message = strtr($message, array("\n" => '')); |
|
2993 | + else { |
|
2994 | + $message = strtr($message, array("\n" => '')); |
|
2995 | + } |
|
2843 | 2996 | |
2844 | - if ($message !== '' && $message[0] === ' ') |
|
2845 | - $message = ' ' . substr($message, 1); |
|
2997 | + if ($message !== '' && $message[0] === ' ') { |
|
2998 | + $message = ' ' . substr($message, 1); |
|
2999 | + } |
|
2846 | 3000 | |
2847 | 3001 | // Cleanup whitespace. |
2848 | 3002 | $message = strtr($message, array(' ' => ' ', "\r" => '', "\n" => '<br>', '<br> ' => '<br> ', ' ' => "\n")); |
@@ -2851,15 +3005,16 @@ discard block |
||
2851 | 3005 | call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
2852 | 3006 | |
2853 | 3007 | // Cache the output if it took some time... |
2854 | - if (isset($cache_key, $cache_t) && microtime(true) - $cache_t > 0.05) |
|
2855 | - cache_put_data($cache_key, $message, 240); |
|
3008 | + if (isset($cache_key, $cache_t) && microtime(true) - $cache_t > 0.05) { |
|
3009 | + cache_put_data($cache_key, $message, 240); |
|
3010 | + } |
|
2856 | 3011 | |
2857 | 3012 | // If this was a force parse revert if needed. |
2858 | 3013 | if (!empty($parse_tags)) |
2859 | 3014 | { |
2860 | - if (empty($temp_bbc)) |
|
2861 | - $bbc_codes = array(); |
|
2862 | - else |
|
3015 | + if (empty($temp_bbc)) { |
|
3016 | + $bbc_codes = array(); |
|
3017 | + } else |
|
2863 | 3018 | { |
2864 | 3019 | $bbc_codes = $temp_bbc; |
2865 | 3020 | unset($temp_bbc); |
@@ -2886,8 +3041,9 @@ discard block |
||
2886 | 3041 | static $smileyPregSearch = null, $smileyPregReplacements = array(); |
2887 | 3042 | |
2888 | 3043 | // No smiley set at all?! |
2889 | - if ($user_info['smiley_set'] == 'none' || trim($message) == '') |
|
2890 | - return; |
|
3044 | + if ($user_info['smiley_set'] == 'none' || trim($message) == '') { |
|
3045 | + return; |
|
3046 | + } |
|
2891 | 3047 | |
2892 | 3048 | // Maybe a mod wants to implement an alternative method (e.g. emojis instead of images) |
2893 | 3049 | call_integration_hook('integrate_smileys', array(&$smileyPregSearch, &$smileyPregReplacements)); |
@@ -2901,8 +3057,7 @@ discard block |
||
2901 | 3057 | $smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', 'O:-)'); |
2902 | 3058 | $smileysto = array('evil', 'cheesy', 'rolleyes', 'angry', 'laugh', 'smiley', 'wink', 'grin', 'sad', 'shocked', 'cool', 'tongue', 'huh', 'embarrassed', 'lipsrsealed', 'kiss', 'cry', 'undecided', 'azn', 'afro', 'police', 'angel'); |
2903 | 3059 | $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'], '', '', '', ''); |
2904 | - } |
|
2905 | - else |
|
3060 | + } else |
|
2906 | 3061 | { |
2907 | 3062 | // Load the smileys in reverse order by length so they don't get parsed wrong. |
2908 | 3063 | if (($temp = cache_get_data('parsing_smileys', 480)) == null) |
@@ -2926,18 +3081,20 @@ discard block |
||
2926 | 3081 | $smcFunc['db_free_result']($result); |
2927 | 3082 | |
2928 | 3083 | cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480); |
3084 | + } else { |
|
3085 | + list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
2929 | 3086 | } |
2930 | - else |
|
2931 | - list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
2932 | 3087 | } |
2933 | 3088 | |
2934 | 3089 | // Set proper extensions; do this post caching so cache doesn't become extension-specific |
2935 | - foreach($smileysto AS $ix=>$file) |
|
2936 | - // Need to use the default if user selection is disabled |
|
3090 | + foreach($smileysto AS $ix=>$file) { |
|
3091 | + // Need to use the default if user selection is disabled |
|
2937 | 3092 | if (empty($modSettings['smiley_sets_enable'])) |
2938 | 3093 | $smileysto[$ix] = $file . $context['user']['smiley_set_default_ext']; |
2939 | - else |
|
2940 | - $smileysto[$ix] = $file . $user_info['smiley_set_ext']; |
|
3094 | + } |
|
3095 | + else { |
|
3096 | + $smileysto[$ix] = $file . $user_info['smiley_set_ext']; |
|
3097 | + } |
|
2941 | 3098 | |
2942 | 3099 | // The non-breaking-space is a complex thing... |
2943 | 3100 | $non_breaking_space = $context['utf8'] ? '\x{A0}' : '\xA0'; |
@@ -3022,12 +3179,14 @@ discard block |
||
3022 | 3179 | global $boardurl, $image_proxy_enabled, $image_proxy_secret; |
3023 | 3180 | |
3024 | 3181 | // Only use the proxy if enabled and necessary |
3025 | - if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') |
|
3026 | - return $url; |
|
3182 | + if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') { |
|
3183 | + return $url; |
|
3184 | + } |
|
3027 | 3185 | |
3028 | 3186 | // We don't need to proxy our own resources |
3029 | - if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) |
|
3030 | - return strtr($url, array('http://' => 'https://')); |
|
3187 | + if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) { |
|
3188 | + return strtr($url, array('http://' => 'https://')); |
|
3189 | + } |
|
3031 | 3190 | |
3032 | 3191 | // By default, use SMF's own image proxy script |
3033 | 3192 | $proxied_url = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($url) . '&hash=' . md5($url . $image_proxy_secret); |
@@ -3052,35 +3211,41 @@ discard block |
||
3052 | 3211 | global $scripturl, $context, $modSettings, $db_show_debug, $db_cache; |
3053 | 3212 | |
3054 | 3213 | // In case we have mail to send, better do that - as obExit doesn't always quite make it... |
3055 | - if (!empty($context['flush_mail'])) |
|
3056 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
3214 | + if (!empty($context['flush_mail'])) { |
|
3215 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
3057 | 3216 | AddMailQueue(true); |
3217 | + } |
|
3058 | 3218 | |
3059 | 3219 | $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:'; |
3060 | 3220 | |
3061 | - if ($add) |
|
3062 | - $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
3221 | + if ($add) { |
|
3222 | + $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
3223 | + } |
|
3063 | 3224 | |
3064 | 3225 | // Put the session ID in. |
3065 | - if (defined('SID') && SID != '') |
|
3066 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
3226 | + if (defined('SID') && SID != '') { |
|
3227 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
3228 | + } |
|
3067 | 3229 | // Keep that debug in their for template debugging! |
3068 | - elseif (isset($_GET['debug'])) |
|
3069 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
3230 | + elseif (isset($_GET['debug'])) { |
|
3231 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
3232 | + } |
|
3070 | 3233 | |
3071 | 3234 | 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']))) |
3072 | 3235 | { |
3073 | - if (defined('SID') && SID != '') |
|
3074 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
3236 | + if (defined('SID') && SID != '') { |
|
3237 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
3075 | 3238 | function ($m) use ($scripturl) |
3076 | 3239 | { |
3077 | 3240 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); |
3241 | + } |
|
3078 | 3242 | }, $setLocation); |
3079 | - else |
|
3080 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
3243 | + else { |
|
3244 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
3081 | 3245 | function ($m) use ($scripturl) |
3082 | 3246 | { |
3083 | 3247 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); |
3248 | + } |
|
3084 | 3249 | }, $setLocation); |
3085 | 3250 | } |
3086 | 3251 | |
@@ -3091,8 +3256,9 @@ discard block |
||
3091 | 3256 | header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302); |
3092 | 3257 | |
3093 | 3258 | // Debugging. |
3094 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
3095 | - $_SESSION['debug_redirect'] = $db_cache; |
|
3259 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
3260 | + $_SESSION['debug_redirect'] = $db_cache; |
|
3261 | + } |
|
3096 | 3262 | |
3097 | 3263 | obExit(false); |
3098 | 3264 | } |
@@ -3111,51 +3277,60 @@ discard block |
||
3111 | 3277 | |
3112 | 3278 | // Attempt to prevent a recursive loop. |
3113 | 3279 | ++$level; |
3114 | - if ($level > 1 && !$from_fatal_error && !$has_fatal_error) |
|
3115 | - exit; |
|
3116 | - if ($from_fatal_error) |
|
3117 | - $has_fatal_error = true; |
|
3280 | + if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { |
|
3281 | + exit; |
|
3282 | + } |
|
3283 | + if ($from_fatal_error) { |
|
3284 | + $has_fatal_error = true; |
|
3285 | + } |
|
3118 | 3286 | |
3119 | 3287 | // Clear out the stat cache. |
3120 | 3288 | trackStats(); |
3121 | 3289 | |
3122 | 3290 | // If we have mail to send, send it. |
3123 | - if (!empty($context['flush_mail'])) |
|
3124 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
3291 | + if (!empty($context['flush_mail'])) { |
|
3292 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
3125 | 3293 | AddMailQueue(true); |
3294 | + } |
|
3126 | 3295 | |
3127 | 3296 | $do_header = $header === null ? !$header_done : $header; |
3128 | - if ($do_footer === null) |
|
3129 | - $do_footer = $do_header; |
|
3297 | + if ($do_footer === null) { |
|
3298 | + $do_footer = $do_header; |
|
3299 | + } |
|
3130 | 3300 | |
3131 | 3301 | // Has the template/header been done yet? |
3132 | 3302 | if ($do_header) |
3133 | 3303 | { |
3134 | 3304 | // Was the page title set last minute? Also update the HTML safe one. |
3135 | - if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) |
|
3136 | - $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
3305 | + if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { |
|
3306 | + $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
3307 | + } |
|
3137 | 3308 | |
3138 | 3309 | // Start up the session URL fixer. |
3139 | 3310 | ob_start('ob_sessrewrite'); |
3140 | 3311 | |
3141 | - if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) |
|
3142 | - $buffers = explode(',', $settings['output_buffers']); |
|
3143 | - elseif (!empty($settings['output_buffers'])) |
|
3144 | - $buffers = $settings['output_buffers']; |
|
3145 | - else |
|
3146 | - $buffers = array(); |
|
3312 | + if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) { |
|
3313 | + $buffers = explode(',', $settings['output_buffers']); |
|
3314 | + } elseif (!empty($settings['output_buffers'])) { |
|
3315 | + $buffers = $settings['output_buffers']; |
|
3316 | + } else { |
|
3317 | + $buffers = array(); |
|
3318 | + } |
|
3147 | 3319 | |
3148 | - if (isset($modSettings['integrate_buffer'])) |
|
3149 | - $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
3320 | + if (isset($modSettings['integrate_buffer'])) { |
|
3321 | + $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
3322 | + } |
|
3150 | 3323 | |
3151 | - if (!empty($buffers)) |
|
3152 | - foreach ($buffers as $function) |
|
3324 | + if (!empty($buffers)) { |
|
3325 | + foreach ($buffers as $function) |
|
3153 | 3326 | { |
3154 | 3327 | $call = call_helper($function, true); |
3328 | + } |
|
3155 | 3329 | |
3156 | 3330 | // Is it valid? |
3157 | - if (!empty($call)) |
|
3158 | - ob_start($call); |
|
3331 | + if (!empty($call)) { |
|
3332 | + ob_start($call); |
|
3333 | + } |
|
3159 | 3334 | } |
3160 | 3335 | |
3161 | 3336 | // Display the screen in the logical order. |
@@ -3167,8 +3342,9 @@ discard block |
||
3167 | 3342 | loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); |
3168 | 3343 | |
3169 | 3344 | // Anything special to put out? |
3170 | - if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) |
|
3171 | - echo $context['insert_after_template']; |
|
3345 | + if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) { |
|
3346 | + echo $context['insert_after_template']; |
|
3347 | + } |
|
3172 | 3348 | |
3173 | 3349 | // Just so we don't get caught in an endless loop of errors from the footer... |
3174 | 3350 | if (!$footer_done) |
@@ -3177,14 +3353,16 @@ discard block |
||
3177 | 3353 | template_footer(); |
3178 | 3354 | |
3179 | 3355 | // (since this is just debugging... it's okay that it's after </html>.) |
3180 | - if (!isset($_REQUEST['xml'])) |
|
3181 | - displayDebug(); |
|
3356 | + if (!isset($_REQUEST['xml'])) { |
|
3357 | + displayDebug(); |
|
3358 | + } |
|
3182 | 3359 | } |
3183 | 3360 | } |
3184 | 3361 | |
3185 | 3362 | // Remember this URL in case someone doesn't like sending HTTP_REFERER. |
3186 | - if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) |
|
3187 | - $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
3363 | + if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { |
|
3364 | + $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
3365 | + } |
|
3188 | 3366 | |
3189 | 3367 | // For session check verification.... don't switch browsers... |
3190 | 3368 | $_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT']; |
@@ -3193,9 +3371,10 @@ discard block |
||
3193 | 3371 | call_integration_hook('integrate_exit', array($do_footer)); |
3194 | 3372 | |
3195 | 3373 | // Don't exit if we're coming from index.php; that will pass through normally. |
3196 | - if (!$from_index) |
|
3197 | - exit; |
|
3198 | -} |
|
3374 | + if (!$from_index) { |
|
3375 | + exit; |
|
3376 | + } |
|
3377 | + } |
|
3199 | 3378 | |
3200 | 3379 | /** |
3201 | 3380 | * Get the size of a specified image with better error handling. |
@@ -3214,8 +3393,9 @@ discard block |
||
3214 | 3393 | $url = str_replace(' ', '%20', $url); |
3215 | 3394 | |
3216 | 3395 | // Can we pull this from the cache... please please? |
3217 | - if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) |
|
3218 | - return $temp; |
|
3396 | + if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) { |
|
3397 | + return $temp; |
|
3398 | + } |
|
3219 | 3399 | $t = microtime(true); |
3220 | 3400 | |
3221 | 3401 | // Get the host to pester... |
@@ -3225,12 +3405,10 @@ discard block |
||
3225 | 3405 | if ($url == '' || $url == 'http://' || $url == 'https://') |
3226 | 3406 | { |
3227 | 3407 | return false; |
3228 | - } |
|
3229 | - elseif (!isset($match[1])) |
|
3408 | + } elseif (!isset($match[1])) |
|
3230 | 3409 | { |
3231 | 3410 | $size = @getimagesize($url); |
3232 | - } |
|
3233 | - else |
|
3411 | + } else |
|
3234 | 3412 | { |
3235 | 3413 | // Try to connect to the server... give it half a second. |
3236 | 3414 | $temp = 0; |
@@ -3267,12 +3445,14 @@ discard block |
||
3267 | 3445 | } |
3268 | 3446 | |
3269 | 3447 | // If we didn't get it, we failed. |
3270 | - if (!isset($size)) |
|
3271 | - $size = false; |
|
3448 | + if (!isset($size)) { |
|
3449 | + $size = false; |
|
3450 | + } |
|
3272 | 3451 | |
3273 | 3452 | // If this took a long time, we may never have to do it again, but then again we might... |
3274 | - if (microtime(true) - $t > 0.8) |
|
3275 | - cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3453 | + if (microtime(true) - $t > 0.8) { |
|
3454 | + cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3455 | + } |
|
3276 | 3456 | |
3277 | 3457 | // Didn't work. |
3278 | 3458 | return $size; |
@@ -3290,8 +3470,9 @@ discard block |
||
3290 | 3470 | |
3291 | 3471 | // Under SSI this function can be called more then once. That can cause some problems. |
3292 | 3472 | // So only run the function once unless we are forced to run it again. |
3293 | - if ($loaded && !$forceload) |
|
3294 | - return; |
|
3473 | + if ($loaded && !$forceload) { |
|
3474 | + return; |
|
3475 | + } |
|
3295 | 3476 | |
3296 | 3477 | $loaded = true; |
3297 | 3478 | |
@@ -3303,14 +3484,16 @@ discard block |
||
3303 | 3484 | $context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))))); |
3304 | 3485 | for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++) |
3305 | 3486 | { |
3306 | - if (trim($context['news_lines'][$i]) == '') |
|
3307 | - continue; |
|
3487 | + if (trim($context['news_lines'][$i]) == '') { |
|
3488 | + continue; |
|
3489 | + } |
|
3308 | 3490 | |
3309 | 3491 | // Clean it up for presentation ;). |
3310 | 3492 | $context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i); |
3311 | 3493 | } |
3312 | - if (!empty($context['news_lines'])) |
|
3313 | - $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
3494 | + if (!empty($context['news_lines'])) { |
|
3495 | + $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
3496 | + } |
|
3314 | 3497 | |
3315 | 3498 | if (!$user_info['is_guest']) |
3316 | 3499 | { |
@@ -3319,40 +3502,48 @@ discard block |
||
3319 | 3502 | $context['user']['alerts'] = &$user_info['alerts']; |
3320 | 3503 | |
3321 | 3504 | // Personal message popup... |
3322 | - if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) |
|
3323 | - $context['user']['popup_messages'] = true; |
|
3324 | - else |
|
3325 | - $context['user']['popup_messages'] = false; |
|
3505 | + if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) { |
|
3506 | + $context['user']['popup_messages'] = true; |
|
3507 | + } else { |
|
3508 | + $context['user']['popup_messages'] = false; |
|
3509 | + } |
|
3326 | 3510 | $_SESSION['unread_messages'] = $user_info['unread_messages']; |
3327 | 3511 | |
3328 | - if (allowedTo('moderate_forum')) |
|
3329 | - $context['unapproved_members'] = !empty($modSettings['unapprovedMembers']) ? $modSettings['unapprovedMembers'] : 0; |
|
3512 | + if (allowedTo('moderate_forum')) { |
|
3513 | + $context['unapproved_members'] = !empty($modSettings['unapprovedMembers']) ? $modSettings['unapprovedMembers'] : 0; |
|
3514 | + } |
|
3330 | 3515 | |
3331 | 3516 | $context['user']['avatar'] = array(); |
3332 | 3517 | |
3333 | 3518 | // Check for gravatar first since we might be forcing them... |
3334 | 3519 | if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride'])) |
3335 | 3520 | { |
3336 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) |
|
3337 | - $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
3338 | - else |
|
3339 | - $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
3521 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) { |
|
3522 | + $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
3523 | + } else { |
|
3524 | + $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
3525 | + } |
|
3340 | 3526 | } |
3341 | 3527 | // Uploaded? |
3342 | - elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) |
|
3343 | - $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'; |
|
3528 | + elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) { |
|
3529 | + $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'; |
|
3530 | + } |
|
3344 | 3531 | // Full URL? |
3345 | - elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) |
|
3346 | - $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
3532 | + elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) { |
|
3533 | + $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
3534 | + } |
|
3347 | 3535 | // Otherwise we assume it's server stored. |
3348 | - elseif ($user_info['avatar']['url'] != '') |
|
3349 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
3536 | + elseif ($user_info['avatar']['url'] != '') { |
|
3537 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
3538 | + } |
|
3350 | 3539 | // No avatar at all? Fine, we have a big fat default avatar ;) |
3351 | - else |
|
3352 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
3540 | + else { |
|
3541 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
3542 | + } |
|
3353 | 3543 | |
3354 | - if (!empty($context['user']['avatar'])) |
|
3355 | - $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
3544 | + if (!empty($context['user']['avatar'])) { |
|
3545 | + $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
3546 | + } |
|
3356 | 3547 | |
3357 | 3548 | // Figure out how long they've been logged in. |
3358 | 3549 | $context['user']['total_time_logged_in'] = array( |
@@ -3360,8 +3551,7 @@ discard block |
||
3360 | 3551 | 'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600), |
3361 | 3552 | 'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60) |
3362 | 3553 | ); |
3363 | - } |
|
3364 | - else |
|
3554 | + } else |
|
3365 | 3555 | { |
3366 | 3556 | $context['user']['messages'] = 0; |
3367 | 3557 | $context['user']['unread_messages'] = 0; |
@@ -3369,12 +3559,14 @@ discard block |
||
3369 | 3559 | $context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0); |
3370 | 3560 | $context['user']['popup_messages'] = false; |
3371 | 3561 | |
3372 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) |
|
3373 | - $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
3562 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) { |
|
3563 | + $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
3564 | + } |
|
3374 | 3565 | |
3375 | 3566 | // If we've upgraded recently, go easy on the passwords. |
3376 | - if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) |
|
3377 | - $context['disable_login_hashing'] = true; |
|
3567 | + if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) { |
|
3568 | + $context['disable_login_hashing'] = true; |
|
3569 | + } |
|
3378 | 3570 | } |
3379 | 3571 | |
3380 | 3572 | // Setup the main menu items. |
@@ -3387,8 +3579,8 @@ discard block |
||
3387 | 3579 | $context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm'); |
3388 | 3580 | |
3389 | 3581 | // 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array. |
3390 | - if ($context['show_pm_popup']) |
|
3391 | - addInlineJavaScript(' |
|
3582 | + if ($context['show_pm_popup']) { |
|
3583 | + addInlineJavaScript(' |
|
3392 | 3584 | jQuery(document).ready(function($) { |
3393 | 3585 | new smc_Popup({ |
3394 | 3586 | heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ', |
@@ -3396,24 +3588,28 @@ discard block |
||
3396 | 3588 | icon_class: \'generic_icons mail_new\' |
3397 | 3589 | }); |
3398 | 3590 | });'); |
3591 | + } |
|
3399 | 3592 | |
3400 | 3593 | // Add a generic "Are you sure?" confirmation message. |
3401 | 3594 | addInlineJavaScript(' |
3402 | 3595 | var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); |
3403 | 3596 | |
3404 | 3597 | // Now add the capping code for avatars. |
3405 | - 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') |
|
3406 | - addInlineCss(' |
|
3598 | + 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') { |
|
3599 | + addInlineCss(' |
|
3407 | 3600 | img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }'); |
3601 | + } |
|
3408 | 3602 | |
3409 | 3603 | // Add max image limits |
3410 | - if (!empty($modSettings['max_image_width'])) |
|
3411 | - addInlineCss(' |
|
3604 | + if (!empty($modSettings['max_image_width'])) { |
|
3605 | + addInlineCss(' |
|
3412 | 3606 | .postarea .bbc_img { max-width: ' . $modSettings['max_image_width'] . 'px; }'); |
3607 | + } |
|
3413 | 3608 | |
3414 | - if (!empty($modSettings['max_image_height'])) |
|
3415 | - addInlineCss(' |
|
3609 | + if (!empty($modSettings['max_image_height'])) { |
|
3610 | + addInlineCss(' |
|
3416 | 3611 | .postarea .bbc_img { max-height: ' . $modSettings['max_image_height'] . 'px; }'); |
3612 | + } |
|
3417 | 3613 | |
3418 | 3614 | // This looks weird, but it's because BoardIndex.php references the variable. |
3419 | 3615 | $context['common_stats']['latest_member'] = array( |
@@ -3430,11 +3626,13 @@ discard block |
||
3430 | 3626 | ); |
3431 | 3627 | $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']); |
3432 | 3628 | |
3433 | - if (empty($settings['theme_version'])) |
|
3434 | - addJavaScriptVar('smf_scripturl', $scripturl); |
|
3629 | + if (empty($settings['theme_version'])) { |
|
3630 | + addJavaScriptVar('smf_scripturl', $scripturl); |
|
3631 | + } |
|
3435 | 3632 | |
3436 | - if (!isset($context['page_title'])) |
|
3437 | - $context['page_title'] = ''; |
|
3633 | + if (!isset($context['page_title'])) { |
|
3634 | + $context['page_title'] = ''; |
|
3635 | + } |
|
3438 | 3636 | |
3439 | 3637 | // Set some specific vars. |
3440 | 3638 | $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
@@ -3444,21 +3642,23 @@ discard block |
||
3444 | 3642 | $context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']); |
3445 | 3643 | $context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']); |
3446 | 3644 | |
3447 | - if (!empty($context['meta_keywords'])) |
|
3448 | - $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
3645 | + if (!empty($context['meta_keywords'])) { |
|
3646 | + $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
3647 | + } |
|
3449 | 3648 | |
3450 | - if (!empty($context['canonical_url'])) |
|
3451 | - $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
3649 | + if (!empty($context['canonical_url'])) { |
|
3650 | + $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
3651 | + } |
|
3452 | 3652 | |
3453 | - if (!empty($settings['og_image'])) |
|
3454 | - $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
3653 | + if (!empty($settings['og_image'])) { |
|
3654 | + $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
3655 | + } |
|
3455 | 3656 | |
3456 | 3657 | if (!empty($context['meta_description'])) |
3457 | 3658 | { |
3458 | 3659 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']); |
3459 | 3660 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']); |
3460 | - } |
|
3461 | - else |
|
3661 | + } else |
|
3462 | 3662 | { |
3463 | 3663 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']); |
3464 | 3664 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']); |
@@ -3483,8 +3683,9 @@ discard block |
||
3483 | 3683 | $memory_needed = memoryReturnBytes($needed); |
3484 | 3684 | |
3485 | 3685 | // should we account for how much is currently being used? |
3486 | - if ($in_use) |
|
3487 | - $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
3686 | + if ($in_use) { |
|
3687 | + $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
3688 | + } |
|
3488 | 3689 | |
3489 | 3690 | // if more is needed, request it |
3490 | 3691 | if ($memory_current < $memory_needed) |
@@ -3507,8 +3708,9 @@ discard block |
||
3507 | 3708 | */ |
3508 | 3709 | function memoryReturnBytes($val) |
3509 | 3710 | { |
3510 | - if (is_integer($val)) |
|
3511 | - return $val; |
|
3711 | + if (is_integer($val)) { |
|
3712 | + return $val; |
|
3713 | + } |
|
3512 | 3714 | |
3513 | 3715 | // Separate the number from the designator |
3514 | 3716 | $val = trim($val); |
@@ -3544,10 +3746,11 @@ discard block |
||
3544 | 3746 | header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
3545 | 3747 | |
3546 | 3748 | // Are we debugging the template/html content? |
3547 | - if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) |
|
3548 | - header('content-type: application/xhtml+xml'); |
|
3549 | - elseif (!isset($_REQUEST['xml'])) |
|
3550 | - header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3749 | + if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) { |
|
3750 | + header('content-type: application/xhtml+xml'); |
|
3751 | + } elseif (!isset($_REQUEST['xml'])) { |
|
3752 | + header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3753 | + } |
|
3551 | 3754 | } |
3552 | 3755 | |
3553 | 3756 | header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
@@ -3556,8 +3759,9 @@ discard block |
||
3556 | 3759 | if ($context['in_maintenance'] && $context['user']['is_admin']) |
3557 | 3760 | { |
3558 | 3761 | $position = array_search('body', $context['template_layers']); |
3559 | - if ($position === false) |
|
3560 | - $position = array_search('main', $context['template_layers']); |
|
3762 | + if ($position === false) { |
|
3763 | + $position = array_search('main', $context['template_layers']); |
|
3764 | + } |
|
3561 | 3765 | |
3562 | 3766 | if ($position !== false) |
3563 | 3767 | { |
@@ -3585,23 +3789,25 @@ discard block |
||
3585 | 3789 | |
3586 | 3790 | foreach ($securityFiles as $i => $securityFile) |
3587 | 3791 | { |
3588 | - if (!file_exists($boarddir . '/' . $securityFile)) |
|
3589 | - unset($securityFiles[$i]); |
|
3792 | + if (!file_exists($boarddir . '/' . $securityFile)) { |
|
3793 | + unset($securityFiles[$i]); |
|
3794 | + } |
|
3590 | 3795 | } |
3591 | 3796 | |
3592 | 3797 | // We are already checking so many files...just few more doesn't make any difference! :P |
3593 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
3594 | - $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
3595 | - |
|
3596 | - else |
|
3597 | - $path = $modSettings['attachmentUploadDir']; |
|
3798 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
3799 | + $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
3800 | + } else { |
|
3801 | + $path = $modSettings['attachmentUploadDir']; |
|
3802 | + } |
|
3598 | 3803 | |
3599 | 3804 | secureDirectory($path, true); |
3600 | 3805 | secureDirectory($cachedir); |
3601 | 3806 | |
3602 | 3807 | // If agreement is enabled, at least the english version shall exists |
3603 | - if ($modSettings['requireAgreement']) |
|
3604 | - $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
3808 | + if ($modSettings['requireAgreement']) { |
|
3809 | + $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
3810 | + } |
|
3605 | 3811 | |
3606 | 3812 | if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement)) |
3607 | 3813 | { |
@@ -3616,18 +3822,21 @@ discard block |
||
3616 | 3822 | echo ' |
3617 | 3823 | ', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>'; |
3618 | 3824 | |
3619 | - if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') |
|
3620 | - echo ' |
|
3825 | + if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') { |
|
3826 | + echo ' |
|
3621 | 3827 | ', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>'; |
3828 | + } |
|
3622 | 3829 | } |
3623 | 3830 | |
3624 | - if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) |
|
3625 | - echo ' |
|
3831 | + if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) { |
|
3832 | + echo ' |
|
3626 | 3833 | <strong>', $txt['cache_writable'], '</strong><br>'; |
3834 | + } |
|
3627 | 3835 | |
3628 | - if (!empty($agreement)) |
|
3629 | - echo ' |
|
3836 | + if (!empty($agreement)) { |
|
3837 | + echo ' |
|
3630 | 3838 | <strong>', $txt['agreement_missing'], '</strong><br>'; |
3839 | + } |
|
3631 | 3840 | |
3632 | 3841 | echo ' |
3633 | 3842 | </p> |
@@ -3642,16 +3851,18 @@ discard block |
||
3642 | 3851 | <div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;"> |
3643 | 3852 | ', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']); |
3644 | 3853 | |
3645 | - if (!empty($_SESSION['ban']['cannot_post']['reason'])) |
|
3646 | - echo ' |
|
3854 | + if (!empty($_SESSION['ban']['cannot_post']['reason'])) { |
|
3855 | + echo ' |
|
3647 | 3856 | <div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>'; |
3857 | + } |
|
3648 | 3858 | |
3649 | - if (!empty($_SESSION['ban']['expire_time'])) |
|
3650 | - echo ' |
|
3859 | + if (!empty($_SESSION['ban']['expire_time'])) { |
|
3860 | + echo ' |
|
3651 | 3861 | <div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>'; |
3652 | - else |
|
3653 | - echo ' |
|
3862 | + } else { |
|
3863 | + echo ' |
|
3654 | 3864 | <div>', $txt['your_ban_expires_never'], '</div>'; |
3865 | + } |
|
3655 | 3866 | |
3656 | 3867 | echo ' |
3657 | 3868 | </div>'; |
@@ -3667,8 +3878,9 @@ discard block |
||
3667 | 3878 | global $forum_copyright, $software_year, $forum_version; |
3668 | 3879 | |
3669 | 3880 | // Don't display copyright for things like SSI. |
3670 | - if (!isset($forum_version) || !isset($software_year)) |
|
3671 | - return; |
|
3881 | + if (!isset($forum_version) || !isset($software_year)) { |
|
3882 | + return; |
|
3883 | + } |
|
3672 | 3884 | |
3673 | 3885 | // Put in the version... |
3674 | 3886 | printf($forum_copyright, $forum_version, $software_year); |
@@ -3686,9 +3898,10 @@ discard block |
||
3686 | 3898 | $context['load_time'] = round(microtime(true) - $time_start, 3); |
3687 | 3899 | $context['load_queries'] = $db_count; |
3688 | 3900 | |
3689 | - foreach (array_reverse($context['template_layers']) as $layer) |
|
3690 | - loadSubTemplate($layer . '_below', true); |
|
3691 | -} |
|
3901 | + foreach (array_reverse($context['template_layers']) as $layer) { |
|
3902 | + loadSubTemplate($layer . '_below', true); |
|
3903 | + } |
|
3904 | + } |
|
3692 | 3905 | |
3693 | 3906 | /** |
3694 | 3907 | * Output the Javascript files |
@@ -3722,8 +3935,7 @@ discard block |
||
3722 | 3935 | { |
3723 | 3936 | echo ' |
3724 | 3937 | var ', $key, ';'; |
3725 | - } |
|
3726 | - else |
|
3938 | + } else |
|
3727 | 3939 | { |
3728 | 3940 | echo ' |
3729 | 3941 | var ', $key, ' = ', $value, ';'; |
@@ -3742,27 +3954,29 @@ discard block |
||
3742 | 3954 | foreach ($context['javascript_files'] as $id => $js_file) |
3743 | 3955 | { |
3744 | 3956 | // Last minute call! allow theme authors to disable single files. |
3745 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
3746 | - continue; |
|
3957 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
3958 | + continue; |
|
3959 | + } |
|
3747 | 3960 | |
3748 | 3961 | // By default files don't get minimized unless the file explicitly says so! |
3749 | 3962 | if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
3750 | 3963 | { |
3751 | - if (!empty($js_file['options']['async'])) |
|
3752 | - $toMinify['async'][] = $js_file; |
|
3753 | - elseif (!empty($js_file['options']['defer'])) |
|
3754 | - $toMinify['defer'][] = $js_file; |
|
3755 | - else |
|
3756 | - $toMinify['standard'][] = $js_file; |
|
3964 | + if (!empty($js_file['options']['async'])) { |
|
3965 | + $toMinify['async'][] = $js_file; |
|
3966 | + } elseif (!empty($js_file['options']['defer'])) { |
|
3967 | + $toMinify['defer'][] = $js_file; |
|
3968 | + } else { |
|
3969 | + $toMinify['standard'][] = $js_file; |
|
3970 | + } |
|
3757 | 3971 | |
3758 | 3972 | // Grab a random seed. |
3759 | - if (!isset($minSeed) && isset($js_file['options']['seed'])) |
|
3760 | - $minSeed = $js_file['options']['seed']; |
|
3761 | - } |
|
3762 | - |
|
3763 | - else |
|
3764 | - echo ' |
|
3973 | + if (!isset($minSeed) && isset($js_file['options']['seed'])) { |
|
3974 | + $minSeed = $js_file['options']['seed']; |
|
3975 | + } |
|
3976 | + } else { |
|
3977 | + echo ' |
|
3765 | 3978 | <script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async' : '', !empty($js_file['options']['defer']) ? ' defer' : '', '></script>'; |
3979 | + } |
|
3766 | 3980 | } |
3767 | 3981 | |
3768 | 3982 | foreach ($toMinify as $js_files) |
@@ -3773,9 +3987,10 @@ discard block |
||
3773 | 3987 | |
3774 | 3988 | $minSuccessful = array_keys($result) === array('smf_minified'); |
3775 | 3989 | |
3776 | - foreach ($result as $minFile) |
|
3777 | - echo ' |
|
3990 | + foreach ($result as $minFile) { |
|
3991 | + echo ' |
|
3778 | 3992 | <script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async' : '', !empty($minFile['options']['defer']) ? ' defer' : '', '></script>'; |
3993 | + } |
|
3779 | 3994 | } |
3780 | 3995 | } |
3781 | 3996 | } |
@@ -3789,8 +4004,9 @@ discard block |
||
3789 | 4004 | <script> |
3790 | 4005 | window.addEventListener("DOMContentLoaded", function() {'; |
3791 | 4006 | |
3792 | - foreach ($context['javascript_inline']['defer'] as $js_code) |
|
3793 | - echo $js_code; |
|
4007 | + foreach ($context['javascript_inline']['defer'] as $js_code) { |
|
4008 | + echo $js_code; |
|
4009 | + } |
|
3794 | 4010 | |
3795 | 4011 | echo ' |
3796 | 4012 | }); |
@@ -3802,8 +4018,9 @@ discard block |
||
3802 | 4018 | echo ' |
3803 | 4019 | <script>'; |
3804 | 4020 | |
3805 | - foreach ($context['javascript_inline']['standard'] as $js_code) |
|
3806 | - echo $js_code; |
|
4021 | + foreach ($context['javascript_inline']['standard'] as $js_code) { |
|
4022 | + echo $js_code; |
|
4023 | + } |
|
3807 | 4024 | |
3808 | 4025 | echo ' |
3809 | 4026 | </script>'; |
@@ -3831,23 +4048,26 @@ discard block |
||
3831 | 4048 | foreach ($context['css_files'] as $id => $file) |
3832 | 4049 | { |
3833 | 4050 | // Last minute call! allow theme authors to disable single files. |
3834 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
3835 | - continue; |
|
4051 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
4052 | + continue; |
|
4053 | + } |
|
3836 | 4054 | |
3837 | 4055 | // Files are minimized unless they explicitly opt out. |
3838 | - if (!isset($file['options']['minimize'])) |
|
3839 | - $file['options']['minimize'] = true; |
|
4056 | + if (!isset($file['options']['minimize'])) { |
|
4057 | + $file['options']['minimize'] = true; |
|
4058 | + } |
|
3840 | 4059 | |
3841 | 4060 | if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']) && !isset($_REQUEST['normalcss'])) |
3842 | 4061 | { |
3843 | 4062 | $toMinify[] = $file; |
3844 | 4063 | |
3845 | 4064 | // Grab a random seed. |
3846 | - if (!isset($minSeed) && isset($file['options']['seed'])) |
|
3847 | - $minSeed = $file['options']['seed']; |
|
4065 | + if (!isset($minSeed) && isset($file['options']['seed'])) { |
|
4066 | + $minSeed = $file['options']['seed']; |
|
4067 | + } |
|
4068 | + } else { |
|
4069 | + $normal[] = $file['fileUrl']; |
|
3848 | 4070 | } |
3849 | - else |
|
3850 | - $normal[] = $file['fileUrl']; |
|
3851 | 4071 | } |
3852 | 4072 | |
3853 | 4073 | if (!empty($toMinify)) |
@@ -3856,23 +4076,26 @@ discard block |
||
3856 | 4076 | |
3857 | 4077 | $minSuccessful = array_keys($result) === array('smf_minified'); |
3858 | 4078 | |
3859 | - foreach ($result as $minFile) |
|
3860 | - echo ' |
|
4079 | + foreach ($result as $minFile) { |
|
4080 | + echo ' |
|
3861 | 4081 | <link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">'; |
4082 | + } |
|
3862 | 4083 | } |
3863 | 4084 | |
3864 | 4085 | // Print the rest after the minified files. |
3865 | - if (!empty($normal)) |
|
3866 | - foreach ($normal as $nf) |
|
4086 | + if (!empty($normal)) { |
|
4087 | + foreach ($normal as $nf) |
|
3867 | 4088 | echo ' |
3868 | 4089 | <link rel="stylesheet" href="', $nf ,'">'; |
4090 | + } |
|
3869 | 4091 | |
3870 | 4092 | if ($db_show_debug === true) |
3871 | 4093 | { |
3872 | 4094 | // Try to keep only what's useful. |
3873 | 4095 | $repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => ''); |
3874 | - foreach ($context['css_files'] as $file) |
|
3875 | - $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
4096 | + foreach ($context['css_files'] as $file) { |
|
4097 | + $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
4098 | + } |
|
3876 | 4099 | } |
3877 | 4100 | |
3878 | 4101 | if (!empty($context['css_header'])) |
@@ -3880,9 +4103,10 @@ discard block |
||
3880 | 4103 | echo ' |
3881 | 4104 | <style>'; |
3882 | 4105 | |
3883 | - foreach ($context['css_header'] as $css) |
|
3884 | - echo $css .' |
|
4106 | + foreach ($context['css_header'] as $css) { |
|
4107 | + echo $css .' |
|
3885 | 4108 | '; |
4109 | + } |
|
3886 | 4110 | |
3887 | 4111 | echo' |
3888 | 4112 | </style>'; |
@@ -3905,8 +4129,9 @@ discard block |
||
3905 | 4129 | $type = !empty($type) && in_array($type, $types) ? $type : false; |
3906 | 4130 | $data = is_array($data) ? $data : array(); |
3907 | 4131 | |
3908 | - if (empty($type) || empty($data)) |
|
3909 | - return $data; |
|
4132 | + if (empty($type) || empty($data)) { |
|
4133 | + return $data; |
|
4134 | + } |
|
3910 | 4135 | |
3911 | 4136 | // Different pages include different files, so we use a hash to label the different combinations |
3912 | 4137 | $hash = md5(implode(' ', array_map(function($file) { return $file['filePath'] . (int) @filesize($file['filePath']) . (int) @filemtime($file['filePath']); }, $data))); |
@@ -3915,13 +4140,14 @@ discard block |
||
3915 | 4140 | list($toCache, $async, $defer) = array_pad((array) cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400), 3, null); |
3916 | 4141 | |
3917 | 4142 | // Already done? |
3918 | - if (!empty($toCache)) |
|
3919 | - return array('smf_minified' => array( |
|
4143 | + if (!empty($toCache)) { |
|
4144 | + return array('smf_minified' => array( |
|
3920 | 4145 | 'fileUrl' => $settings['theme_url'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/' . basename($toCache), |
3921 | 4146 | 'filePath' => $toCache, |
3922 | 4147 | 'fileName' => basename($toCache), |
3923 | 4148 | 'options' => array('async' => !empty($async), 'defer' => !empty($defer)), |
3924 | 4149 | )); |
4150 | + } |
|
3925 | 4151 | |
3926 | 4152 | |
3927 | 4153 | // No namespaces, sorry! |
@@ -3951,9 +4177,9 @@ discard block |
||
3951 | 4177 | |
3952 | 4178 | foreach ($data as $id => $file) |
3953 | 4179 | { |
3954 | - if (empty($file['filePath'])) |
|
3955 | - $toAdd = false; |
|
3956 | - else |
|
4180 | + if (empty($file['filePath'])) { |
|
4181 | + $toAdd = false; |
|
4182 | + } else |
|
3957 | 4183 | { |
3958 | 4184 | $seed = isset($file['options']['seed']) ? $file['options']['seed'] : ''; |
3959 | 4185 | $tempFile = str_replace($seed, '', $file['filePath']); |
@@ -3961,12 +4187,14 @@ discard block |
||
3961 | 4187 | } |
3962 | 4188 | |
3963 | 4189 | // A minified script should only be loaded asynchronously if all its components wanted to be. |
3964 | - if (empty($file['options']['async'])) |
|
3965 | - $async = false; |
|
4190 | + if (empty($file['options']['async'])) { |
|
4191 | + $async = false; |
|
4192 | + } |
|
3966 | 4193 | |
3967 | 4194 | // A minified script should only be deferred if all its components wanted to be. |
3968 | - if (empty($file['options']['defer'])) |
|
3969 | - $defer = false; |
|
4195 | + if (empty($file['options']['defer'])) { |
|
4196 | + $defer = false; |
|
4197 | + } |
|
3970 | 4198 | |
3971 | 4199 | // The file couldn't be located so it won't be added. Log this error. |
3972 | 4200 | if (empty($toAdd)) |
@@ -4032,12 +4260,14 @@ discard block |
||
4032 | 4260 | foreach (glob(rtrim($theme['dir'], '/') . '/' . ($type == 'css' ? 'css' : 'scripts') . '/minified*.' . $type) as $filename) |
4033 | 4261 | { |
4034 | 4262 | // Remove the cache entry |
4035 | - if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) |
|
4036 | - cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null); |
|
4263 | + if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) { |
|
4264 | + cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null); |
|
4265 | + } |
|
4037 | 4266 | |
4038 | 4267 | // Try to delete the file. Add it to our error list if it fails. |
4039 | - if (!@unlink($filename)) |
|
4040 | - $not_deleted[] = $filename; |
|
4268 | + if (!@unlink($filename)) { |
|
4269 | + $not_deleted[] = $filename; |
|
4270 | + } |
|
4041 | 4271 | } |
4042 | 4272 | } |
4043 | 4273 | } |
@@ -4069,8 +4299,9 @@ discard block |
||
4069 | 4299 | global $modSettings, $smcFunc; |
4070 | 4300 | |
4071 | 4301 | // Just make up a nice hash... |
4072 | - if ($new) |
|
4073 | - return sha1(md5($filename . time()) . mt_rand()); |
|
4302 | + if ($new) { |
|
4303 | + return sha1(md5($filename . time()) . mt_rand()); |
|
4304 | + } |
|
4074 | 4305 | |
4075 | 4306 | // Just make sure that attachment id is only a int |
4076 | 4307 | $attachment_id = (int) $attachment_id; |
@@ -4087,23 +4318,25 @@ discard block |
||
4087 | 4318 | 'id_attach' => $attachment_id, |
4088 | 4319 | )); |
4089 | 4320 | |
4090 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
4091 | - return false; |
|
4321 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
4322 | + return false; |
|
4323 | + } |
|
4092 | 4324 | |
4093 | 4325 | list ($file_hash) = $smcFunc['db_fetch_row']($request); |
4094 | 4326 | $smcFunc['db_free_result']($request); |
4095 | 4327 | } |
4096 | 4328 | |
4097 | 4329 | // Still no hash? mmm... |
4098 | - if (empty($file_hash)) |
|
4099 | - $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
4330 | + if (empty($file_hash)) { |
|
4331 | + $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
4332 | + } |
|
4100 | 4333 | |
4101 | 4334 | // Are we using multiple directories? |
4102 | - if (is_array($modSettings['attachmentUploadDir'])) |
|
4103 | - $path = $modSettings['attachmentUploadDir'][$dir]; |
|
4104 | - |
|
4105 | - else |
|
4106 | - $path = $modSettings['attachmentUploadDir']; |
|
4335 | + if (is_array($modSettings['attachmentUploadDir'])) { |
|
4336 | + $path = $modSettings['attachmentUploadDir'][$dir]; |
|
4337 | + } else { |
|
4338 | + $path = $modSettings['attachmentUploadDir']; |
|
4339 | + } |
|
4107 | 4340 | |
4108 | 4341 | return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; |
4109 | 4342 | } |
@@ -4118,8 +4351,9 @@ discard block |
||
4118 | 4351 | function ip2range($fullip) |
4119 | 4352 | { |
4120 | 4353 | // Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.) |
4121 | - if ($fullip == 'unknown') |
|
4122 | - $fullip = '255.255.255.255'; |
|
4354 | + if ($fullip == 'unknown') { |
|
4355 | + $fullip = '255.255.255.255'; |
|
4356 | + } |
|
4123 | 4357 | |
4124 | 4358 | $ip_parts = explode('-', $fullip); |
4125 | 4359 | $ip_array = array(); |
@@ -4143,10 +4377,11 @@ discard block |
||
4143 | 4377 | $ip_array['low'] = $ip_parts[0]; |
4144 | 4378 | $ip_array['high'] = $ip_parts[1]; |
4145 | 4379 | return $ip_array; |
4146 | - } |
|
4147 | - elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.* |
|
4380 | + } elseif (count($ip_parts) == 2) { |
|
4381 | + // if ip 22.22.*-22.22.* |
|
4148 | 4382 | { |
4149 | 4383 | $valid_low = isValidIP($ip_parts[0]); |
4384 | + } |
|
4150 | 4385 | $valid_high = isValidIP($ip_parts[1]); |
4151 | 4386 | $count = 0; |
4152 | 4387 | $mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); |
@@ -4161,7 +4396,9 @@ discard block |
||
4161 | 4396 | $ip_parts[0] .= $mode . $min; |
4162 | 4397 | $valid_low = isValidIP($ip_parts[0]); |
4163 | 4398 | $count++; |
4164 | - if ($count > 9) break; |
|
4399 | + if ($count > 9) { |
|
4400 | + break; |
|
4401 | + } |
|
4165 | 4402 | } |
4166 | 4403 | } |
4167 | 4404 | |
@@ -4175,7 +4412,9 @@ discard block |
||
4175 | 4412 | $ip_parts[1] .= $mode . $max; |
4176 | 4413 | $valid_high = isValidIP($ip_parts[1]); |
4177 | 4414 | $count++; |
4178 | - if ($count > 9) break; |
|
4415 | + if ($count > 9) { |
|
4416 | + break; |
|
4417 | + } |
|
4179 | 4418 | } |
4180 | 4419 | } |
4181 | 4420 | |
@@ -4199,46 +4438,54 @@ discard block |
||
4199 | 4438 | { |
4200 | 4439 | global $modSettings; |
4201 | 4440 | |
4202 | - if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) |
|
4203 | - return $host; |
|
4441 | + if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) { |
|
4442 | + return $host; |
|
4443 | + } |
|
4204 | 4444 | $t = microtime(true); |
4205 | 4445 | |
4206 | 4446 | // Try the Linux host command, perhaps? |
4207 | 4447 | if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1) |
4208 | 4448 | { |
4209 | - if (!isset($modSettings['host_to_dis'])) |
|
4210 | - $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
4211 | - else |
|
4212 | - $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
4449 | + if (!isset($modSettings['host_to_dis'])) { |
|
4450 | + $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
4451 | + } else { |
|
4452 | + $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
4453 | + } |
|
4213 | 4454 | |
4214 | 4455 | // Did host say it didn't find anything? |
4215 | - if (strpos($test, 'not found') !== false) |
|
4216 | - $host = ''; |
|
4456 | + if (strpos($test, 'not found') !== false) { |
|
4457 | + $host = ''; |
|
4458 | + } |
|
4217 | 4459 | // Invalid server option? |
4218 | - elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) |
|
4219 | - updateSettings(array('host_to_dis' => 1)); |
|
4460 | + elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) { |
|
4461 | + updateSettings(array('host_to_dis' => 1)); |
|
4462 | + } |
|
4220 | 4463 | // Maybe it found something, after all? |
4221 | - elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) |
|
4222 | - $host = $match[1]; |
|
4464 | + elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) { |
|
4465 | + $host = $match[1]; |
|
4466 | + } |
|
4223 | 4467 | } |
4224 | 4468 | |
4225 | 4469 | // This is nslookup; usually only Windows, but possibly some Unix? |
4226 | 4470 | if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1) |
4227 | 4471 | { |
4228 | 4472 | $test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip)); |
4229 | - if (strpos($test, 'Non-existent domain') !== false) |
|
4230 | - $host = ''; |
|
4231 | - elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) |
|
4232 | - $host = $match[1]; |
|
4473 | + if (strpos($test, 'Non-existent domain') !== false) { |
|
4474 | + $host = ''; |
|
4475 | + } elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) { |
|
4476 | + $host = $match[1]; |
|
4477 | + } |
|
4233 | 4478 | } |
4234 | 4479 | |
4235 | 4480 | // This is the last try :/. |
4236 | - if (!isset($host) || $host === false) |
|
4237 | - $host = @gethostbyaddr($ip); |
|
4481 | + if (!isset($host) || $host === false) { |
|
4482 | + $host = @gethostbyaddr($ip); |
|
4483 | + } |
|
4238 | 4484 | |
4239 | 4485 | // It took a long time, so let's cache it! |
4240 | - if (microtime(true) - $t > 0.5) |
|
4241 | - cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4486 | + if (microtime(true) - $t > 0.5) { |
|
4487 | + cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4488 | + } |
|
4242 | 4489 | |
4243 | 4490 | return $host; |
4244 | 4491 | } |
@@ -4274,20 +4521,21 @@ discard block |
||
4274 | 4521 | { |
4275 | 4522 | $encrypted = substr(crypt($word, 'uk'), 2, $max_chars); |
4276 | 4523 | $total = 0; |
4277 | - for ($i = 0; $i < $max_chars; $i++) |
|
4278 | - $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
4524 | + for ($i = 0; $i < $max_chars; $i++) { |
|
4525 | + $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
4526 | + } |
|
4279 | 4527 | $returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total; |
4280 | 4528 | } |
4281 | 4529 | } |
4282 | 4530 | return array_unique($returned_ints); |
4283 | - } |
|
4284 | - else |
|
4531 | + } else |
|
4285 | 4532 | { |
4286 | 4533 | // Trim characters before and after and add slashes for database insertion. |
4287 | 4534 | $returned_words = array(); |
4288 | - foreach ($words as $word) |
|
4289 | - if (($word = trim($word, '-_\'')) !== '') |
|
4535 | + foreach ($words as $word) { |
|
4536 | + if (($word = trim($word, '-_\'')) !== '') |
|
4290 | 4537 | $returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars); |
4538 | + } |
|
4291 | 4539 | |
4292 | 4540 | // Filter out all words that occur more than once. |
4293 | 4541 | return array_unique($returned_words); |
@@ -4309,16 +4557,18 @@ discard block |
||
4309 | 4557 | global $settings, $txt; |
4310 | 4558 | |
4311 | 4559 | // Does the current loaded theme have this and we are not forcing the usage of this function? |
4312 | - if (function_exists('template_create_button') && !$force_use) |
|
4313 | - return template_create_button($name, $alt, $label = '', $custom = ''); |
|
4560 | + if (function_exists('template_create_button') && !$force_use) { |
|
4561 | + return template_create_button($name, $alt, $label = '', $custom = ''); |
|
4562 | + } |
|
4314 | 4563 | |
4315 | - if (!$settings['use_image_buttons']) |
|
4316 | - return $txt[$alt]; |
|
4317 | - elseif (!empty($settings['use_buttons'])) |
|
4318 | - return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
4319 | - else |
|
4320 | - return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
4321 | -} |
|
4564 | + if (!$settings['use_image_buttons']) { |
|
4565 | + return $txt[$alt]; |
|
4566 | + } elseif (!empty($settings['use_buttons'])) { |
|
4567 | + return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
4568 | + } else { |
|
4569 | + return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
4570 | + } |
|
4571 | + } |
|
4322 | 4572 | |
4323 | 4573 | /** |
4324 | 4574 | * Sets up all of the top menu buttons |
@@ -4361,9 +4611,10 @@ discard block |
||
4361 | 4611 | var user_menus = new smc_PopupMenu(); |
4362 | 4612 | user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); |
4363 | 4613 | user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); |
4364 | - if ($context['allow_pm']) |
|
4365 | - addInlineJavaScript(' |
|
4614 | + if ($context['allow_pm']) { |
|
4615 | + addInlineJavaScript(' |
|
4366 | 4616 | user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); |
4617 | + } |
|
4367 | 4618 | |
4368 | 4619 | if (!empty($modSettings['enable_ajax_alerts'])) |
4369 | 4620 | { |
@@ -4523,88 +4774,96 @@ discard block |
||
4523 | 4774 | |
4524 | 4775 | // Now we put the buttons in the context so the theme can use them. |
4525 | 4776 | $menu_buttons = array(); |
4526 | - foreach ($buttons as $act => $button) |
|
4527 | - if (!empty($button['show'])) |
|
4777 | + foreach ($buttons as $act => $button) { |
|
4778 | + if (!empty($button['show'])) |
|
4528 | 4779 | { |
4529 | 4780 | $button['active_button'] = false; |
4781 | + } |
|
4530 | 4782 | |
4531 | 4783 | // This button needs some action. |
4532 | - if (isset($button['action_hook'])) |
|
4533 | - $needs_action_hook = true; |
|
4784 | + if (isset($button['action_hook'])) { |
|
4785 | + $needs_action_hook = true; |
|
4786 | + } |
|
4534 | 4787 | |
4535 | 4788 | // Make sure the last button truly is the last button. |
4536 | 4789 | if (!empty($button['is_last'])) |
4537 | 4790 | { |
4538 | - if (isset($last_button)) |
|
4539 | - unset($menu_buttons[$last_button]['is_last']); |
|
4791 | + if (isset($last_button)) { |
|
4792 | + unset($menu_buttons[$last_button]['is_last']); |
|
4793 | + } |
|
4540 | 4794 | $last_button = $act; |
4541 | 4795 | } |
4542 | 4796 | |
4543 | 4797 | // Go through the sub buttons if there are any. |
4544 | - if (!empty($button['sub_buttons'])) |
|
4545 | - foreach ($button['sub_buttons'] as $key => $subbutton) |
|
4798 | + if (!empty($button['sub_buttons'])) { |
|
4799 | + foreach ($button['sub_buttons'] as $key => $subbutton) |
|
4546 | 4800 | { |
4547 | 4801 | if (empty($subbutton['show'])) |
4548 | 4802 | unset($button['sub_buttons'][$key]); |
4803 | + } |
|
4549 | 4804 | |
4550 | 4805 | // 2nd level sub buttons next... |
4551 | 4806 | if (!empty($subbutton['sub_buttons'])) |
4552 | 4807 | { |
4553 | 4808 | foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2) |
4554 | 4809 | { |
4555 | - if (empty($sub_button2['show'])) |
|
4556 | - unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
4810 | + if (empty($sub_button2['show'])) { |
|
4811 | + unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
4812 | + } |
|
4557 | 4813 | } |
4558 | 4814 | } |
4559 | 4815 | } |
4560 | 4816 | |
4561 | 4817 | // Does this button have its own icon? |
4562 | - if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) |
|
4563 | - $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4564 | - elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) |
|
4565 | - $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4566 | - elseif (isset($button['icon'])) |
|
4567 | - $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
4568 | - else |
|
4569 | - $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
4818 | + if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) { |
|
4819 | + $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4820 | + } elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) { |
|
4821 | + $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4822 | + } elseif (isset($button['icon'])) { |
|
4823 | + $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
4824 | + } else { |
|
4825 | + $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
4826 | + } |
|
4570 | 4827 | |
4571 | 4828 | $menu_buttons[$act] = $button; |
4572 | 4829 | } |
4573 | 4830 | |
4574 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
4575 | - cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
4831 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
4832 | + cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
4833 | + } |
|
4576 | 4834 | } |
4577 | 4835 | |
4578 | 4836 | $context['menu_buttons'] = $menu_buttons; |
4579 | 4837 | |
4580 | 4838 | // Logging out requires the session id in the url. |
4581 | - if (isset($context['menu_buttons']['logout'])) |
|
4582 | - $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
4839 | + if (isset($context['menu_buttons']['logout'])) { |
|
4840 | + $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
4841 | + } |
|
4583 | 4842 | |
4584 | 4843 | // Figure out which action we are doing so we can set the active tab. |
4585 | 4844 | // Default to home. |
4586 | 4845 | $current_action = 'home'; |
4587 | 4846 | |
4588 | - if (isset($context['menu_buttons'][$context['current_action']])) |
|
4589 | - $current_action = $context['current_action']; |
|
4590 | - elseif ($context['current_action'] == 'search2') |
|
4591 | - $current_action = 'search'; |
|
4592 | - elseif ($context['current_action'] == 'theme') |
|
4593 | - $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
4594 | - elseif ($context['current_action'] == 'register2') |
|
4595 | - $current_action = 'register'; |
|
4596 | - elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) |
|
4597 | - $current_action = 'login'; |
|
4598 | - elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) |
|
4599 | - $current_action = 'moderate'; |
|
4847 | + if (isset($context['menu_buttons'][$context['current_action']])) { |
|
4848 | + $current_action = $context['current_action']; |
|
4849 | + } elseif ($context['current_action'] == 'search2') { |
|
4850 | + $current_action = 'search'; |
|
4851 | + } elseif ($context['current_action'] == 'theme') { |
|
4852 | + $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
4853 | + } elseif ($context['current_action'] == 'register2') { |
|
4854 | + $current_action = 'register'; |
|
4855 | + } elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) { |
|
4856 | + $current_action = 'login'; |
|
4857 | + } elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) { |
|
4858 | + $current_action = 'moderate'; |
|
4859 | + } |
|
4600 | 4860 | |
4601 | 4861 | // There are certain exceptions to the above where we don't want anything on the menu highlighted. |
4602 | 4862 | if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner'])) |
4603 | 4863 | { |
4604 | 4864 | $current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile'; |
4605 | 4865 | $context[$current_action] = true; |
4606 | - } |
|
4607 | - elseif ($context['current_action'] == 'pm') |
|
4866 | + } elseif ($context['current_action'] == 'pm') |
|
4608 | 4867 | { |
4609 | 4868 | $current_action = 'self_pm'; |
4610 | 4869 | $context['self_pm'] = true; |
@@ -4667,12 +4926,14 @@ discard block |
||
4667 | 4926 | } |
4668 | 4927 | |
4669 | 4928 | // Not all actions are simple. |
4670 | - if (!empty($needs_action_hook)) |
|
4671 | - call_integration_hook('integrate_current_action', array(&$current_action)); |
|
4929 | + if (!empty($needs_action_hook)) { |
|
4930 | + call_integration_hook('integrate_current_action', array(&$current_action)); |
|
4931 | + } |
|
4672 | 4932 | |
4673 | - if (isset($context['menu_buttons'][$current_action])) |
|
4674 | - $context['menu_buttons'][$current_action]['active_button'] = true; |
|
4675 | -} |
|
4933 | + if (isset($context['menu_buttons'][$current_action])) { |
|
4934 | + $context['menu_buttons'][$current_action]['active_button'] = true; |
|
4935 | + } |
|
4936 | + } |
|
4676 | 4937 | |
4677 | 4938 | /** |
4678 | 4939 | * Generate a random seed and ensure it's stored in settings. |
@@ -4696,30 +4957,35 @@ discard block |
||
4696 | 4957 | global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug; |
4697 | 4958 | global $context, $txt; |
4698 | 4959 | |
4699 | - if ($db_show_debug === true) |
|
4700 | - $context['debug']['hooks'][] = $hook; |
|
4960 | + if ($db_show_debug === true) { |
|
4961 | + $context['debug']['hooks'][] = $hook; |
|
4962 | + } |
|
4701 | 4963 | |
4702 | 4964 | // Need to have some control. |
4703 | - if (!isset($context['instances'])) |
|
4704 | - $context['instances'] = array(); |
|
4965 | + if (!isset($context['instances'])) { |
|
4966 | + $context['instances'] = array(); |
|
4967 | + } |
|
4705 | 4968 | |
4706 | 4969 | $results = array(); |
4707 | - if (empty($modSettings[$hook])) |
|
4708 | - return $results; |
|
4970 | + if (empty($modSettings[$hook])) { |
|
4971 | + return $results; |
|
4972 | + } |
|
4709 | 4973 | |
4710 | 4974 | $functions = explode(',', $modSettings[$hook]); |
4711 | 4975 | // Loop through each function. |
4712 | 4976 | foreach ($functions as $function) |
4713 | 4977 | { |
4714 | 4978 | // Hook has been marked as "disabled". Skip it! |
4715 | - if (strpos($function, '!') !== false) |
|
4716 | - continue; |
|
4979 | + if (strpos($function, '!') !== false) { |
|
4980 | + continue; |
|
4981 | + } |
|
4717 | 4982 | |
4718 | 4983 | $call = call_helper($function, true); |
4719 | 4984 | |
4720 | 4985 | // Is it valid? |
4721 | - if (!empty($call)) |
|
4722 | - $results[$function] = call_user_func_array($call, $parameters); |
|
4986 | + if (!empty($call)) { |
|
4987 | + $results[$function] = call_user_func_array($call, $parameters); |
|
4988 | + } |
|
4723 | 4989 | |
4724 | 4990 | // Whatever it was suppose to call, it failed :( |
4725 | 4991 | elseif (!empty($function)) |
@@ -4735,8 +5001,9 @@ discard block |
||
4735 | 5001 | } |
4736 | 5002 | |
4737 | 5003 | // "Assume" the file resides on $boarddir somewhere... |
4738 | - else |
|
4739 | - log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
5004 | + else { |
|
5005 | + log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
5006 | + } |
|
4740 | 5007 | } |
4741 | 5008 | } |
4742 | 5009 | |
@@ -4758,12 +5025,14 @@ discard block |
||
4758 | 5025 | global $smcFunc, $modSettings; |
4759 | 5026 | |
4760 | 5027 | // Any objects? |
4761 | - if ($object) |
|
4762 | - $function = $function . '#'; |
|
5028 | + if ($object) { |
|
5029 | + $function = $function . '#'; |
|
5030 | + } |
|
4763 | 5031 | |
4764 | 5032 | // Any files to load? |
4765 | - if (!empty($file) && is_string($file)) |
|
4766 | - $function = $file . (!empty($function) ? '|' . $function : ''); |
|
5033 | + if (!empty($file) && is_string($file)) { |
|
5034 | + $function = $file . (!empty($function) ? '|' . $function : ''); |
|
5035 | + } |
|
4767 | 5036 | |
4768 | 5037 | // Get the correct string. |
4769 | 5038 | $integration_call = $function; |
@@ -4785,13 +5054,14 @@ discard block |
||
4785 | 5054 | if (!empty($current_functions)) |
4786 | 5055 | { |
4787 | 5056 | $current_functions = explode(',', $current_functions); |
4788 | - if (in_array($integration_call, $current_functions)) |
|
4789 | - return; |
|
5057 | + if (in_array($integration_call, $current_functions)) { |
|
5058 | + return; |
|
5059 | + } |
|
4790 | 5060 | |
4791 | 5061 | $permanent_functions = array_merge($current_functions, array($integration_call)); |
5062 | + } else { |
|
5063 | + $permanent_functions = array($integration_call); |
|
4792 | 5064 | } |
4793 | - else |
|
4794 | - $permanent_functions = array($integration_call); |
|
4795 | 5065 | |
4796 | 5066 | updateSettings(array($hook => implode(',', $permanent_functions))); |
4797 | 5067 | } |
@@ -4800,8 +5070,9 @@ discard block |
||
4800 | 5070 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
4801 | 5071 | |
4802 | 5072 | // Do nothing, if it's already there. |
4803 | - if (in_array($integration_call, $functions)) |
|
4804 | - return; |
|
5073 | + if (in_array($integration_call, $functions)) { |
|
5074 | + return; |
|
5075 | + } |
|
4805 | 5076 | |
4806 | 5077 | $functions[] = $integration_call; |
4807 | 5078 | $modSettings[$hook] = implode(',', $functions); |
@@ -4824,12 +5095,14 @@ discard block |
||
4824 | 5095 | global $smcFunc, $modSettings; |
4825 | 5096 | |
4826 | 5097 | // Any objects? |
4827 | - if ($object) |
|
4828 | - $function = $function . '#'; |
|
5098 | + if ($object) { |
|
5099 | + $function = $function . '#'; |
|
5100 | + } |
|
4829 | 5101 | |
4830 | 5102 | // Any files to load? |
4831 | - if (!empty($file) && is_string($file)) |
|
4832 | - $function = $file . '|' . $function; |
|
5103 | + if (!empty($file) && is_string($file)) { |
|
5104 | + $function = $file . '|' . $function; |
|
5105 | + } |
|
4833 | 5106 | |
4834 | 5107 | // Get the correct string. |
4835 | 5108 | $integration_call = $function; |
@@ -4850,16 +5123,18 @@ discard block |
||
4850 | 5123 | { |
4851 | 5124 | $current_functions = explode(',', $current_functions); |
4852 | 5125 | |
4853 | - if (in_array($integration_call, $current_functions)) |
|
4854 | - updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
5126 | + if (in_array($integration_call, $current_functions)) { |
|
5127 | + updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
5128 | + } |
|
4855 | 5129 | } |
4856 | 5130 | |
4857 | 5131 | // Turn the function list into something usable. |
4858 | 5132 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
4859 | 5133 | |
4860 | 5134 | // You can only remove it if it's available. |
4861 | - if (!in_array($integration_call, $functions)) |
|
4862 | - return; |
|
5135 | + if (!in_array($integration_call, $functions)) { |
|
5136 | + return; |
|
5137 | + } |
|
4863 | 5138 | |
4864 | 5139 | $functions = array_diff($functions, array($integration_call)); |
4865 | 5140 | $modSettings[$hook] = implode(',', $functions); |
@@ -4880,17 +5155,20 @@ discard block |
||
4880 | 5155 | global $context, $smcFunc, $txt, $db_show_debug; |
4881 | 5156 | |
4882 | 5157 | // Really? |
4883 | - if (empty($string)) |
|
4884 | - return false; |
|
5158 | + if (empty($string)) { |
|
5159 | + return false; |
|
5160 | + } |
|
4885 | 5161 | |
4886 | 5162 | // An array? should be a "callable" array IE array(object/class, valid_callable). |
4887 | 5163 | // A closure? should be a callable one. |
4888 | - if (is_array($string) || $string instanceof Closure) |
|
4889 | - return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
5164 | + if (is_array($string) || $string instanceof Closure) { |
|
5165 | + return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
5166 | + } |
|
4890 | 5167 | |
4891 | 5168 | // No full objects, sorry! pass a method or a property instead! |
4892 | - if (is_object($string)) |
|
4893 | - return false; |
|
5169 | + if (is_object($string)) { |
|
5170 | + return false; |
|
5171 | + } |
|
4894 | 5172 | |
4895 | 5173 | // Stay vitaminized my friends... |
4896 | 5174 | $string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string)); |
@@ -4899,8 +5177,9 @@ discard block |
||
4899 | 5177 | $string = load_file($string); |
4900 | 5178 | |
4901 | 5179 | // Loaded file failed |
4902 | - if (empty($string)) |
|
4903 | - return false; |
|
5180 | + if (empty($string)) { |
|
5181 | + return false; |
|
5182 | + } |
|
4904 | 5183 | |
4905 | 5184 | // Found a method. |
4906 | 5185 | if (strpos($string, '::') !== false) |
@@ -4921,8 +5200,9 @@ discard block |
||
4921 | 5200 | // Add another one to the list. |
4922 | 5201 | if ($db_show_debug === true) |
4923 | 5202 | { |
4924 | - if (!isset($context['debug']['instances'])) |
|
4925 | - $context['debug']['instances'] = array(); |
|
5203 | + if (!isset($context['debug']['instances'])) { |
|
5204 | + $context['debug']['instances'] = array(); |
|
5205 | + } |
|
4926 | 5206 | |
4927 | 5207 | $context['debug']['instances'][$class] = $class; |
4928 | 5208 | } |
@@ -4932,13 +5212,15 @@ discard block |
||
4932 | 5212 | } |
4933 | 5213 | |
4934 | 5214 | // Right then. This is a call to a static method. |
4935 | - else |
|
4936 | - $func = array($class, $method); |
|
5215 | + else { |
|
5216 | + $func = array($class, $method); |
|
5217 | + } |
|
4937 | 5218 | } |
4938 | 5219 | |
4939 | 5220 | // Nope! just a plain regular function. |
4940 | - else |
|
4941 | - $func = $string; |
|
5221 | + else { |
|
5222 | + $func = $string; |
|
5223 | + } |
|
4942 | 5224 | |
4943 | 5225 | // Right, we got what we need, time to do some checks. |
4944 | 5226 | if (!is_callable($func, false, $callable_name)) |
@@ -4954,17 +5236,18 @@ discard block |
||
4954 | 5236 | else |
4955 | 5237 | { |
4956 | 5238 | // What are we gonna do about it? |
4957 | - if ($return) |
|
4958 | - return $func; |
|
5239 | + if ($return) { |
|
5240 | + return $func; |
|
5241 | + } |
|
4959 | 5242 | |
4960 | 5243 | // If this is a plain function, avoid the heat of calling call_user_func(). |
4961 | 5244 | else |
4962 | 5245 | { |
4963 | - if (is_array($func)) |
|
4964 | - call_user_func($func); |
|
4965 | - |
|
4966 | - else |
|
4967 | - $func(); |
|
5246 | + if (is_array($func)) { |
|
5247 | + call_user_func($func); |
|
5248 | + } else { |
|
5249 | + $func(); |
|
5250 | + } |
|
4968 | 5251 | } |
4969 | 5252 | } |
4970 | 5253 | } |
@@ -4981,31 +5264,34 @@ discard block |
||
4981 | 5264 | { |
4982 | 5265 | global $sourcedir, $txt, $boarddir, $settings; |
4983 | 5266 | |
4984 | - if (empty($string)) |
|
4985 | - return false; |
|
5267 | + if (empty($string)) { |
|
5268 | + return false; |
|
5269 | + } |
|
4986 | 5270 | |
4987 | 5271 | if (strpos($string, '|') !== false) |
4988 | 5272 | { |
4989 | 5273 | list ($file, $string) = explode('|', $string); |
4990 | 5274 | |
4991 | 5275 | // Match the wildcards to their regular vars. |
4992 | - if (empty($settings['theme_dir'])) |
|
4993 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
4994 | - |
|
4995 | - else |
|
4996 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
5276 | + if (empty($settings['theme_dir'])) { |
|
5277 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
5278 | + } else { |
|
5279 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
5280 | + } |
|
4997 | 5281 | |
4998 | 5282 | // Load the file if it can be loaded. |
4999 | - if (file_exists($absPath)) |
|
5000 | - require_once($absPath); |
|
5283 | + if (file_exists($absPath)) { |
|
5284 | + require_once($absPath); |
|
5285 | + } |
|
5001 | 5286 | |
5002 | 5287 | // No? try a fallback to $sourcedir |
5003 | 5288 | else |
5004 | 5289 | { |
5005 | 5290 | $absPath = $sourcedir .'/'. $file; |
5006 | 5291 | |
5007 | - if (file_exists($absPath)) |
|
5008 | - require_once($absPath); |
|
5292 | + if (file_exists($absPath)) { |
|
5293 | + require_once($absPath); |
|
5294 | + } |
|
5009 | 5295 | |
5010 | 5296 | // Sorry, can't do much for you at this point. |
5011 | 5297 | else |
@@ -5044,8 +5330,9 @@ discard block |
||
5044 | 5330 | preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match); |
5045 | 5331 | |
5046 | 5332 | // No scheme? No data for you! |
5047 | - if (empty($match[1])) |
|
5048 | - return false; |
|
5333 | + if (empty($match[1])) { |
|
5334 | + return false; |
|
5335 | + } |
|
5049 | 5336 | |
5050 | 5337 | // An FTP url. We should try connecting and RETRieving it... |
5051 | 5338 | elseif ($match[1] == 'ftp') |
@@ -5055,23 +5342,26 @@ discard block |
||
5055 | 5342 | |
5056 | 5343 | // Establish a connection and attempt to enable passive mode. |
5057 | 5344 | $ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email); |
5058 | - if ($ftp->error !== false || !$ftp->passive()) |
|
5059 | - return false; |
|
5345 | + if ($ftp->error !== false || !$ftp->passive()) { |
|
5346 | + return false; |
|
5347 | + } |
|
5060 | 5348 | |
5061 | 5349 | // I want that one *points*! |
5062 | 5350 | fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n"); |
5063 | 5351 | |
5064 | 5352 | // Since passive mode worked (or we would have returned already!) open the connection. |
5065 | 5353 | $fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5); |
5066 | - if (!$fp) |
|
5067 | - return false; |
|
5354 | + if (!$fp) { |
|
5355 | + return false; |
|
5356 | + } |
|
5068 | 5357 | |
5069 | 5358 | // The server should now say something in acknowledgement. |
5070 | 5359 | $ftp->check_response(150); |
5071 | 5360 | |
5072 | 5361 | $data = ''; |
5073 | - while (!feof($fp)) |
|
5074 | - $data .= fread($fp, 4096); |
|
5362 | + while (!feof($fp)) { |
|
5363 | + $data .= fread($fp, 4096); |
|
5364 | + } |
|
5075 | 5365 | fclose($fp); |
5076 | 5366 | |
5077 | 5367 | // All done, right? Good. |
@@ -5083,8 +5373,9 @@ discard block |
||
5083 | 5373 | elseif (isset($match[1]) && $match[1] == 'http') |
5084 | 5374 | { |
5085 | 5375 | // First try to use fsockopen, because it is fastest. |
5086 | - if ($keep_alive && $match[3] == $keep_alive_dom) |
|
5087 | - $fp = $keep_alive_fp; |
|
5376 | + if ($keep_alive && $match[3] == $keep_alive_dom) { |
|
5377 | + $fp = $keep_alive_fp; |
|
5378 | + } |
|
5088 | 5379 | if (empty($fp)) |
5089 | 5380 | { |
5090 | 5381 | // Open the socket on the port we want... |
@@ -5104,20 +5395,21 @@ discard block |
||
5104 | 5395 | fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n"); |
5105 | 5396 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
5106 | 5397 | fwrite($fp, 'user-agent: PHP/SMF' . "\r\n"); |
5107 | - if ($keep_alive) |
|
5108 | - fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n"); |
|
5109 | - else |
|
5110 | - fwrite($fp, 'connection: close' . "\r\n\r\n"); |
|
5111 | - } |
|
5112 | - else |
|
5398 | + if ($keep_alive) { |
|
5399 | + fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n"); |
|
5400 | + } else { |
|
5401 | + fwrite($fp, 'connection: close' . "\r\n\r\n"); |
|
5402 | + } |
|
5403 | + } else |
|
5113 | 5404 | { |
5114 | 5405 | fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n"); |
5115 | 5406 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
5116 | 5407 | fwrite($fp, 'user-agent: PHP/SMF' . "\r\n"); |
5117 | - if ($keep_alive) |
|
5118 | - fwrite($fp, 'connection: Keep-Alive' . "\r\n"); |
|
5119 | - else |
|
5120 | - fwrite($fp, 'connection: close' . "\r\n"); |
|
5408 | + if ($keep_alive) { |
|
5409 | + fwrite($fp, 'connection: Keep-Alive' . "\r\n"); |
|
5410 | + } else { |
|
5411 | + fwrite($fp, 'connection: close' . "\r\n"); |
|
5412 | + } |
|
5121 | 5413 | fwrite($fp, 'content-type: application/x-www-form-urlencoded' . "\r\n"); |
5122 | 5414 | fwrite($fp, 'content-length: ' . strlen($post_data) . "\r\n\r\n"); |
5123 | 5415 | fwrite($fp, $post_data); |
@@ -5130,30 +5422,33 @@ discard block |
||
5130 | 5422 | { |
5131 | 5423 | $header = ''; |
5132 | 5424 | $location = ''; |
5133 | - while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
|
5134 | - if (strpos($header, 'location:') !== false) |
|
5425 | + while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') { |
|
5426 | + if (strpos($header, 'location:') !== false) |
|
5135 | 5427 | $location = trim(substr($header, strpos($header, ':') + 1)); |
5428 | + } |
|
5136 | 5429 | |
5137 | - if (empty($location)) |
|
5138 | - return false; |
|
5139 | - else |
|
5430 | + if (empty($location)) { |
|
5431 | + return false; |
|
5432 | + } else |
|
5140 | 5433 | { |
5141 | - if (!$keep_alive) |
|
5142 | - fclose($fp); |
|
5434 | + if (!$keep_alive) { |
|
5435 | + fclose($fp); |
|
5436 | + } |
|
5143 | 5437 | return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1); |
5144 | 5438 | } |
5145 | 5439 | } |
5146 | 5440 | |
5147 | 5441 | // Make sure we get a 200 OK. |
5148 | - elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) |
|
5149 | - return false; |
|
5442 | + elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) { |
|
5443 | + return false; |
|
5444 | + } |
|
5150 | 5445 | |
5151 | 5446 | // Skip the headers... |
5152 | 5447 | while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
5153 | 5448 | { |
5154 | - if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) |
|
5155 | - $content_length = $match[1]; |
|
5156 | - elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
5449 | + if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) { |
|
5450 | + $content_length = $match[1]; |
|
5451 | + } elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
5157 | 5452 | { |
5158 | 5453 | $keep_alive_dom = null; |
5159 | 5454 | $keep_alive = false; |
@@ -5165,17 +5460,19 @@ discard block |
||
5165 | 5460 | $data = ''; |
5166 | 5461 | if (isset($content_length)) |
5167 | 5462 | { |
5168 | - while (!feof($fp) && strlen($data) < $content_length) |
|
5169 | - $data .= fread($fp, $content_length - strlen($data)); |
|
5170 | - } |
|
5171 | - else |
|
5463 | + while (!feof($fp) && strlen($data) < $content_length) { |
|
5464 | + $data .= fread($fp, $content_length - strlen($data)); |
|
5465 | + } |
|
5466 | + } else |
|
5172 | 5467 | { |
5173 | - while (!feof($fp)) |
|
5174 | - $data .= fread($fp, 4096); |
|
5468 | + while (!feof($fp)) { |
|
5469 | + $data .= fread($fp, 4096); |
|
5470 | + } |
|
5175 | 5471 | } |
5176 | 5472 | |
5177 | - if (!$keep_alive) |
|
5178 | - fclose($fp); |
|
5473 | + if (!$keep_alive) { |
|
5474 | + fclose($fp); |
|
5475 | + } |
|
5179 | 5476 | } |
5180 | 5477 | |
5181 | 5478 | // If using fsockopen didn't work, try to use cURL if available. |
@@ -5188,17 +5485,18 @@ discard block |
||
5188 | 5485 | $fetch_data->get_url_data($url, $post_data); |
5189 | 5486 | |
5190 | 5487 | // no errors and a 200 result, then we have a good dataset, well we at least have data. ;) |
5191 | - if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) |
|
5192 | - $data = $fetch_data->result('body'); |
|
5193 | - else |
|
5194 | - return false; |
|
5488 | + if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) { |
|
5489 | + $data = $fetch_data->result('body'); |
|
5490 | + } else { |
|
5491 | + return false; |
|
5492 | + } |
|
5195 | 5493 | } |
5196 | 5494 | |
5197 | 5495 | // Neither fsockopen nor curl are available. Well, phooey. |
5198 | - else |
|
5199 | - return false; |
|
5200 | - } |
|
5201 | - else |
|
5496 | + else { |
|
5497 | + return false; |
|
5498 | + } |
|
5499 | + } else |
|
5202 | 5500 | { |
5203 | 5501 | // Umm, this shouldn't happen? |
5204 | 5502 | trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE); |
@@ -5218,8 +5516,9 @@ discard block |
||
5218 | 5516 | global $user_info, $smcFunc; |
5219 | 5517 | |
5220 | 5518 | // Make sure we have something to work with. |
5221 | - if (empty($topic)) |
|
5222 | - return array(); |
|
5519 | + if (empty($topic)) { |
|
5520 | + return array(); |
|
5521 | + } |
|
5223 | 5522 | |
5224 | 5523 | |
5225 | 5524 | // We already know the number of likes per message, we just want to know whether the current user liked it or not. |
@@ -5242,8 +5541,9 @@ discard block |
||
5242 | 5541 | 'topic' => $topic, |
5243 | 5542 | ) |
5244 | 5543 | ); |
5245 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
5246 | - $temp[] = (int) $row['content_id']; |
|
5544 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
5545 | + $temp[] = (int) $row['content_id']; |
|
5546 | + } |
|
5247 | 5547 | |
5248 | 5548 | cache_put_data($cache_key, $temp, $ttl); |
5249 | 5549 | } |
@@ -5264,8 +5564,9 @@ discard block |
||
5264 | 5564 | { |
5265 | 5565 | global $context; |
5266 | 5566 | |
5267 | - if (empty($string)) |
|
5268 | - return $string; |
|
5567 | + if (empty($string)) { |
|
5568 | + return $string; |
|
5569 | + } |
|
5269 | 5570 | |
5270 | 5571 | // UTF-8 occurences of MS special characters |
5271 | 5572 | $findchars_utf8 = array( |
@@ -5306,10 +5607,11 @@ discard block |
||
5306 | 5607 | '--', // — |
5307 | 5608 | ); |
5308 | 5609 | |
5309 | - if ($context['utf8']) |
|
5310 | - $string = str_replace($findchars_utf8, $replacechars, $string); |
|
5311 | - else |
|
5312 | - $string = str_replace($findchars_iso, $replacechars, $string); |
|
5610 | + if ($context['utf8']) { |
|
5611 | + $string = str_replace($findchars_utf8, $replacechars, $string); |
|
5612 | + } else { |
|
5613 | + $string = str_replace($findchars_iso, $replacechars, $string); |
|
5614 | + } |
|
5313 | 5615 | |
5314 | 5616 | return $string; |
5315 | 5617 | } |
@@ -5328,49 +5630,59 @@ discard block |
||
5328 | 5630 | { |
5329 | 5631 | global $context; |
5330 | 5632 | |
5331 | - if (!isset($matches[2])) |
|
5332 | - return ''; |
|
5633 | + if (!isset($matches[2])) { |
|
5634 | + return ''; |
|
5635 | + } |
|
5333 | 5636 | |
5334 | 5637 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
5335 | 5638 | |
5336 | 5639 | // remove left to right / right to left overrides |
5337 | - if ($num === 0x202D || $num === 0x202E) |
|
5338 | - return ''; |
|
5640 | + if ($num === 0x202D || $num === 0x202E) { |
|
5641 | + return ''; |
|
5642 | + } |
|
5339 | 5643 | |
5340 | 5644 | // Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced |
5341 | - if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) |
|
5342 | - return '&#' . $num . ';'; |
|
5645 | + if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) { |
|
5646 | + return '&#' . $num . ';'; |
|
5647 | + } |
|
5343 | 5648 | |
5344 | 5649 | if (empty($context['utf8'])) |
5345 | 5650 | { |
5346 | 5651 | // no control characters |
5347 | - if ($num < 0x20) |
|
5348 | - return ''; |
|
5652 | + if ($num < 0x20) { |
|
5653 | + return ''; |
|
5654 | + } |
|
5349 | 5655 | // text is text |
5350 | - elseif ($num < 0x80) |
|
5351 | - return chr($num); |
|
5656 | + elseif ($num < 0x80) { |
|
5657 | + return chr($num); |
|
5658 | + } |
|
5352 | 5659 | // all others get html-ised |
5353 | - else |
|
5354 | - return '&#' . $matches[2] . ';'; |
|
5355 | - } |
|
5356 | - else |
|
5660 | + else { |
|
5661 | + return '&#' . $matches[2] . ';'; |
|
5662 | + } |
|
5663 | + } else |
|
5357 | 5664 | { |
5358 | 5665 | // <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set |
5359 | 5666 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text) |
5360 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) |
|
5361 | - return ''; |
|
5667 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) { |
|
5668 | + return ''; |
|
5669 | + } |
|
5362 | 5670 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
5363 | - elseif ($num < 0x80) |
|
5364 | - return chr($num); |
|
5671 | + elseif ($num < 0x80) { |
|
5672 | + return chr($num); |
|
5673 | + } |
|
5365 | 5674 | // <0x800 (2048) |
5366 | - elseif ($num < 0x800) |
|
5367 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5675 | + elseif ($num < 0x800) { |
|
5676 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5677 | + } |
|
5368 | 5678 | // < 0x10000 (65536) |
5369 | - elseif ($num < 0x10000) |
|
5370 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5679 | + elseif ($num < 0x10000) { |
|
5680 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5681 | + } |
|
5371 | 5682 | // <= 0x10FFFF (1114111) |
5372 | - else |
|
5373 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5683 | + else { |
|
5684 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5685 | + } |
|
5374 | 5686 | } |
5375 | 5687 | } |
5376 | 5688 | |
@@ -5386,28 +5698,34 @@ discard block |
||
5386 | 5698 | */ |
5387 | 5699 | function fixchar__callback($matches) |
5388 | 5700 | { |
5389 | - if (!isset($matches[1])) |
|
5390 | - return ''; |
|
5701 | + if (!isset($matches[1])) { |
|
5702 | + return ''; |
|
5703 | + } |
|
5391 | 5704 | |
5392 | 5705 | $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1]; |
5393 | 5706 | |
5394 | 5707 | // <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set |
5395 | 5708 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides |
5396 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) |
|
5397 | - return ''; |
|
5709 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) { |
|
5710 | + return ''; |
|
5711 | + } |
|
5398 | 5712 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
5399 | - elseif ($num < 0x80) |
|
5400 | - return chr($num); |
|
5713 | + elseif ($num < 0x80) { |
|
5714 | + return chr($num); |
|
5715 | + } |
|
5401 | 5716 | // <0x800 (2048) |
5402 | - elseif ($num < 0x800) |
|
5403 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5717 | + elseif ($num < 0x800) { |
|
5718 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5719 | + } |
|
5404 | 5720 | // < 0x10000 (65536) |
5405 | - elseif ($num < 0x10000) |
|
5406 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5721 | + elseif ($num < 0x10000) { |
|
5722 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5723 | + } |
|
5407 | 5724 | // <= 0x10FFFF (1114111) |
5408 | - else |
|
5409 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5410 | -} |
|
5725 | + else { |
|
5726 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5727 | + } |
|
5728 | + } |
|
5411 | 5729 | |
5412 | 5730 | /** |
5413 | 5731 | * Strips out invalid html entities, replaces others with html style { codes |
@@ -5420,17 +5738,19 @@ discard block |
||
5420 | 5738 | */ |
5421 | 5739 | function entity_fix__callback($matches) |
5422 | 5740 | { |
5423 | - if (!isset($matches[2])) |
|
5424 | - return ''; |
|
5741 | + if (!isset($matches[2])) { |
|
5742 | + return ''; |
|
5743 | + } |
|
5425 | 5744 | |
5426 | 5745 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
5427 | 5746 | |
5428 | 5747 | // we don't allow control characters, characters out of range, byte markers, etc |
5429 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) |
|
5430 | - return ''; |
|
5431 | - else |
|
5432 | - return '&#' . $num . ';'; |
|
5433 | -} |
|
5748 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) { |
|
5749 | + return ''; |
|
5750 | + } else { |
|
5751 | + return '&#' . $num . ';'; |
|
5752 | + } |
|
5753 | + } |
|
5434 | 5754 | |
5435 | 5755 | /** |
5436 | 5756 | * Return a Gravatar URL based on |
@@ -5454,18 +5774,23 @@ discard block |
||
5454 | 5774 | $ratings = array('G', 'PG', 'R', 'X'); |
5455 | 5775 | $defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'); |
5456 | 5776 | $url_params = array(); |
5457 | - if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) |
|
5458 | - $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
5459 | - if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) |
|
5460 | - $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
5461 | - if (!empty($modSettings['avatar_max_width_external'])) |
|
5462 | - $size_string = (int) $modSettings['avatar_max_width_external']; |
|
5463 | - if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) |
|
5464 | - if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
5777 | + if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) { |
|
5778 | + $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
5779 | + } |
|
5780 | + if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) { |
|
5781 | + $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
5782 | + } |
|
5783 | + if (!empty($modSettings['avatar_max_width_external'])) { |
|
5784 | + $size_string = (int) $modSettings['avatar_max_width_external']; |
|
5785 | + } |
|
5786 | + if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) { |
|
5787 | + if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
5465 | 5788 | $size_string = $modSettings['avatar_max_height_external']; |
5789 | + } |
|
5466 | 5790 | |
5467 | - if (!empty($size_string)) |
|
5468 | - $url_params[] = 's=' . $size_string; |
|
5791 | + if (!empty($size_string)) { |
|
5792 | + $url_params[] = 's=' . $size_string; |
|
5793 | + } |
|
5469 | 5794 | } |
5470 | 5795 | $http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www'; |
5471 | 5796 | |
@@ -5484,22 +5809,26 @@ discard block |
||
5484 | 5809 | static $timezones = null, $lastwhen = null; |
5485 | 5810 | |
5486 | 5811 | // No point doing this over if we already did it once |
5487 | - if (!empty($timezones) && $when == $lastwhen) |
|
5488 | - return $timezones; |
|
5489 | - else |
|
5490 | - $lastwhen = $when; |
|
5812 | + if (!empty($timezones) && $when == $lastwhen) { |
|
5813 | + return $timezones; |
|
5814 | + } else { |
|
5815 | + $lastwhen = $when; |
|
5816 | + } |
|
5491 | 5817 | |
5492 | 5818 | // Parseable datetime string? |
5493 | - if (is_int($timestamp = strtotime($when))) |
|
5494 | - $when = $timestamp; |
|
5819 | + if (is_int($timestamp = strtotime($when))) { |
|
5820 | + $when = $timestamp; |
|
5821 | + } |
|
5495 | 5822 | |
5496 | 5823 | // A Unix timestamp? |
5497 | - elseif (is_numeric($when)) |
|
5498 | - $when = intval($when); |
|
5824 | + elseif (is_numeric($when)) { |
|
5825 | + $when = intval($when); |
|
5826 | + } |
|
5499 | 5827 | |
5500 | 5828 | // Invalid value? Just get current Unix timestamp. |
5501 | - else |
|
5502 | - $when = time(); |
|
5829 | + else { |
|
5830 | + $when = time(); |
|
5831 | + } |
|
5503 | 5832 | |
5504 | 5833 | // We'll need these too |
5505 | 5834 | $date_when = date_create('@' . $when); |
@@ -5514,8 +5843,9 @@ discard block |
||
5514 | 5843 | foreach ($priority_countries as $country) |
5515 | 5844 | { |
5516 | 5845 | $country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country))); |
5517 | - if (!empty($country_tzids)) |
|
5518 | - $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
5846 | + if (!empty($country_tzids)) { |
|
5847 | + $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
5848 | + } |
|
5519 | 5849 | } |
5520 | 5850 | |
5521 | 5851 | // Antarctic research stations should be listed last, unless you're running a penguin forum |
@@ -5529,8 +5859,9 @@ discard block |
||
5529 | 5859 | foreach ($tzids as $tzid) |
5530 | 5860 | { |
5531 | 5861 | // We don't want UTC right now |
5532 | - if ($tzid == 'UTC') |
|
5533 | - continue; |
|
5862 | + if ($tzid == 'UTC') { |
|
5863 | + continue; |
|
5864 | + } |
|
5534 | 5865 | |
5535 | 5866 | $tz = timezone_open($tzid); |
5536 | 5867 | |
@@ -5551,13 +5882,14 @@ discard block |
||
5551 | 5882 | } |
5552 | 5883 | |
5553 | 5884 | // A time zone from a prioritized country? |
5554 | - if (in_array($tzid, $priority_tzids)) |
|
5555 | - $priority_zones[$tzkey] = true; |
|
5885 | + if (in_array($tzid, $priority_tzids)) { |
|
5886 | + $priority_zones[$tzkey] = true; |
|
5887 | + } |
|
5556 | 5888 | |
5557 | 5889 | // Keep track of the location and offset for this tzid |
5558 | - if (!empty($txt[$tzid])) |
|
5559 | - $zones[$tzkey]['locations'][] = $txt[$tzid]; |
|
5560 | - else |
|
5890 | + if (!empty($txt[$tzid])) { |
|
5891 | + $zones[$tzkey]['locations'][] = $txt[$tzid]; |
|
5892 | + } else |
|
5561 | 5893 | { |
5562 | 5894 | $tzid_parts = explode('/', $tzid); |
5563 | 5895 | $zones[$tzkey]['locations'][] = str_replace(array('St_', '_'), array('St. ', ' '), array_pop($tzid_parts)); |
@@ -5577,23 +5909,27 @@ discard block |
||
5577 | 5909 | date_timezone_set($date_when, timezone_open($tzvalue['tzid'])); |
5578 | 5910 | |
5579 | 5911 | // Use the custom description, if there is one |
5580 | - if (!empty($tztxt[$tzvalue['tzid']])) |
|
5581 | - $desc = $tztxt[$tzvalue['tzid']]; |
|
5912 | + if (!empty($tztxt[$tzvalue['tzid']])) { |
|
5913 | + $desc = $tztxt[$tzvalue['tzid']]; |
|
5914 | + } |
|
5582 | 5915 | // Otherwise, use the list of locations (max 5, so things don't get silly) |
5583 | - else |
|
5584 | - $desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : ''); |
|
5916 | + else { |
|
5917 | + $desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : ''); |
|
5918 | + } |
|
5585 | 5919 | |
5586 | 5920 | // Show the UTC offset and the abbreviation, if it's something like 'MST' and not '-06' |
5587 | 5921 | $desc = '[UTC' . date_format($date_when, 'P') . '] - ' . (!strspn($tzvalue['abbr'], '+-') ? $tzvalue['abbr'] . ' - ' : '') . $desc; |
5588 | 5922 | |
5589 | - if (isset($priority_zones[$tzkey])) |
|
5590 | - $priority_timezones[$tzvalue['tzid']] = $desc; |
|
5591 | - else |
|
5592 | - $timezones[$tzvalue['tzid']] = $desc; |
|
5923 | + if (isset($priority_zones[$tzkey])) { |
|
5924 | + $priority_timezones[$tzvalue['tzid']] = $desc; |
|
5925 | + } else { |
|
5926 | + $timezones[$tzvalue['tzid']] = $desc; |
|
5927 | + } |
|
5593 | 5928 | } |
5594 | 5929 | |
5595 | - if (!empty($priority_timezones)) |
|
5596 | - $priority_timezones[] = '-----'; |
|
5930 | + if (!empty($priority_timezones)) { |
|
5931 | + $priority_timezones[] = '-----'; |
|
5932 | + } |
|
5597 | 5933 | |
5598 | 5934 | $timezones = array_merge( |
5599 | 5935 | $priority_timezones, |
@@ -5610,8 +5946,9 @@ discard block |
||
5610 | 5946 | */ |
5611 | 5947 | function inet_ptod($ip_address) |
5612 | 5948 | { |
5613 | - if (!isValidIP($ip_address)) |
|
5614 | - return $ip_address; |
|
5949 | + if (!isValidIP($ip_address)) { |
|
5950 | + return $ip_address; |
|
5951 | + } |
|
5615 | 5952 | |
5616 | 5953 | $bin = inet_pton($ip_address); |
5617 | 5954 | return $bin; |
@@ -5623,13 +5960,15 @@ discard block |
||
5623 | 5960 | */ |
5624 | 5961 | function inet_dtop($bin) |
5625 | 5962 | { |
5626 | - if(empty($bin)) |
|
5627 | - return ''; |
|
5963 | + if(empty($bin)) { |
|
5964 | + return ''; |
|
5965 | + } |
|
5628 | 5966 | |
5629 | 5967 | global $db_type; |
5630 | 5968 | |
5631 | - if ($db_type == 'postgresql') |
|
5632 | - return $bin; |
|
5969 | + if ($db_type == 'postgresql') { |
|
5970 | + return $bin; |
|
5971 | + } |
|
5633 | 5972 | |
5634 | 5973 | $ip_address = inet_ntop($bin); |
5635 | 5974 | |
@@ -5654,26 +5993,32 @@ discard block |
||
5654 | 5993 | */ |
5655 | 5994 | function _safe_serialize($value) |
5656 | 5995 | { |
5657 | - if(is_null($value)) |
|
5658 | - return 'N;'; |
|
5996 | + if(is_null($value)) { |
|
5997 | + return 'N;'; |
|
5998 | + } |
|
5659 | 5999 | |
5660 | - if(is_bool($value)) |
|
5661 | - return 'b:'. (int) $value .';'; |
|
6000 | + if(is_bool($value)) { |
|
6001 | + return 'b:'. (int) $value .';'; |
|
6002 | + } |
|
5662 | 6003 | |
5663 | - if(is_int($value)) |
|
5664 | - return 'i:'. $value .';'; |
|
6004 | + if(is_int($value)) { |
|
6005 | + return 'i:'. $value .';'; |
|
6006 | + } |
|
5665 | 6007 | |
5666 | - if(is_float($value)) |
|
5667 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
6008 | + if(is_float($value)) { |
|
6009 | + return 'd:'. str_replace(',', '.', $value) .';'; |
|
6010 | + } |
|
5668 | 6011 | |
5669 | - if(is_string($value)) |
|
5670 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
6012 | + if(is_string($value)) { |
|
6013 | + return 's:'. strlen($value) .':"'. $value .'";'; |
|
6014 | + } |
|
5671 | 6015 | |
5672 | 6016 | if(is_array($value)) |
5673 | 6017 | { |
5674 | 6018 | $out = ''; |
5675 | - foreach($value as $k => $v) |
|
5676 | - $out .= _safe_serialize($k) . _safe_serialize($v); |
|
6019 | + foreach($value as $k => $v) { |
|
6020 | + $out .= _safe_serialize($k) . _safe_serialize($v); |
|
6021 | + } |
|
5677 | 6022 | |
5678 | 6023 | return 'a:'. count($value) .':{'. $out .'}'; |
5679 | 6024 | } |
@@ -5699,8 +6044,9 @@ discard block |
||
5699 | 6044 | |
5700 | 6045 | $out = _safe_serialize($value); |
5701 | 6046 | |
5702 | - if (isset($mbIntEnc)) |
|
5703 | - mb_internal_encoding($mbIntEnc); |
|
6047 | + if (isset($mbIntEnc)) { |
|
6048 | + mb_internal_encoding($mbIntEnc); |
|
6049 | + } |
|
5704 | 6050 | |
5705 | 6051 | return $out; |
5706 | 6052 | } |
@@ -5717,8 +6063,9 @@ discard block |
||
5717 | 6063 | function _safe_unserialize($str) |
5718 | 6064 | { |
5719 | 6065 | // Input is not a string. |
5720 | - if(empty($str) || !is_string($str)) |
|
5721 | - return false; |
|
6066 | + if(empty($str) || !is_string($str)) { |
|
6067 | + return false; |
|
6068 | + } |
|
5722 | 6069 | |
5723 | 6070 | $stack = array(); |
5724 | 6071 | $expected = array(); |
@@ -5734,43 +6081,38 @@ discard block |
||
5734 | 6081 | while($state != 1) |
5735 | 6082 | { |
5736 | 6083 | $type = isset($str[0]) ? $str[0] : ''; |
5737 | - if($type == '}') |
|
5738 | - $str = substr($str, 1); |
|
5739 | - |
|
5740 | - else if($type == 'N' && $str[1] == ';') |
|
6084 | + if($type == '}') { |
|
6085 | + $str = substr($str, 1); |
|
6086 | + } else if($type == 'N' && $str[1] == ';') |
|
5741 | 6087 | { |
5742 | 6088 | $value = null; |
5743 | 6089 | $str = substr($str, 2); |
5744 | - } |
|
5745 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
6090 | + } else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
5746 | 6091 | { |
5747 | 6092 | $value = $matches[1] == '1' ? true : false; |
5748 | 6093 | $str = substr($str, 4); |
5749 | - } |
|
5750 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
6094 | + } else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
5751 | 6095 | { |
5752 | 6096 | $value = (int)$matches[1]; |
5753 | 6097 | $str = $matches[2]; |
5754 | - } |
|
5755 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
6098 | + } else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
5756 | 6099 | { |
5757 | 6100 | $value = (float)$matches[1]; |
5758 | 6101 | $str = $matches[3]; |
5759 | - } |
|
5760 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
6102 | + } else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
5761 | 6103 | { |
5762 | 6104 | $value = substr($matches[2], 0, (int)$matches[1]); |
5763 | 6105 | $str = substr($matches[2], (int)$matches[1] + 2); |
5764 | - } |
|
5765 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
6106 | + } else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
5766 | 6107 | { |
5767 | 6108 | $expectedLength = (int)$matches[1]; |
5768 | 6109 | $str = $matches[2]; |
5769 | 6110 | } |
5770 | 6111 | |
5771 | 6112 | // Object or unknown/malformed type. |
5772 | - else |
|
5773 | - return false; |
|
6113 | + else { |
|
6114 | + return false; |
|
6115 | + } |
|
5774 | 6116 | |
5775 | 6117 | switch($state) |
5776 | 6118 | { |
@@ -5798,8 +6140,9 @@ discard block |
||
5798 | 6140 | if($type == '}') |
5799 | 6141 | { |
5800 | 6142 | // Array size is less than expected. |
5801 | - if(count($list) < end($expected)) |
|
5802 | - return false; |
|
6143 | + if(count($list) < end($expected)) { |
|
6144 | + return false; |
|
6145 | + } |
|
5803 | 6146 | |
5804 | 6147 | unset($list); |
5805 | 6148 | $list = &$stack[count($stack)-1]; |
@@ -5808,8 +6151,9 @@ discard block |
||
5808 | 6151 | // Go to terminal state if we're at the end of the root array. |
5809 | 6152 | array_pop($expected); |
5810 | 6153 | |
5811 | - if(count($expected) == 0) |
|
5812 | - $state = 1; |
|
6154 | + if(count($expected) == 0) { |
|
6155 | + $state = 1; |
|
6156 | + } |
|
5813 | 6157 | |
5814 | 6158 | break; |
5815 | 6159 | } |
@@ -5817,8 +6161,9 @@ discard block |
||
5817 | 6161 | if($type == 'i' || $type == 's') |
5818 | 6162 | { |
5819 | 6163 | // Array size exceeds expected length. |
5820 | - if(count($list) >= end($expected)) |
|
5821 | - return false; |
|
6164 | + if(count($list) >= end($expected)) { |
|
6165 | + return false; |
|
6166 | + } |
|
5822 | 6167 | |
5823 | 6168 | $key = $value; |
5824 | 6169 | $state = 3; |
@@ -5852,8 +6197,9 @@ discard block |
||
5852 | 6197 | } |
5853 | 6198 | |
5854 | 6199 | // Trailing data in input. |
5855 | - if(!empty($str)) |
|
5856 | - return false; |
|
6200 | + if(!empty($str)) { |
|
6201 | + return false; |
|
6202 | + } |
|
5857 | 6203 | |
5858 | 6204 | return $data; |
5859 | 6205 | } |
@@ -5876,8 +6222,9 @@ discard block |
||
5876 | 6222 | |
5877 | 6223 | $out = _safe_unserialize($str); |
5878 | 6224 | |
5879 | - if (isset($mbIntEnc)) |
|
5880 | - mb_internal_encoding($mbIntEnc); |
|
6225 | + if (isset($mbIntEnc)) { |
|
6226 | + mb_internal_encoding($mbIntEnc); |
|
6227 | + } |
|
5881 | 6228 | |
5882 | 6229 | return $out; |
5883 | 6230 | } |
@@ -5892,12 +6239,14 @@ discard block |
||
5892 | 6239 | function smf_chmod($file, $value = 0) |
5893 | 6240 | { |
5894 | 6241 | // No file? no checks! |
5895 | - if (empty($file)) |
|
5896 | - return false; |
|
6242 | + if (empty($file)) { |
|
6243 | + return false; |
|
6244 | + } |
|
5897 | 6245 | |
5898 | 6246 | // Already writable? |
5899 | - if (is_writable($file)) |
|
5900 | - return true; |
|
6247 | + if (is_writable($file)) { |
|
6248 | + return true; |
|
6249 | + } |
|
5901 | 6250 | |
5902 | 6251 | // Do we have a file or a dir? |
5903 | 6252 | $isDir = is_dir($file); |
@@ -5913,10 +6262,9 @@ discard block |
||
5913 | 6262 | { |
5914 | 6263 | $isWritable = true; |
5915 | 6264 | break; |
6265 | + } else { |
|
6266 | + @chmod($file, $val); |
|
5916 | 6267 | } |
5917 | - |
|
5918 | - else |
|
5919 | - @chmod($file, $val); |
|
5920 | 6268 | } |
5921 | 6269 | |
5922 | 6270 | return $isWritable; |
@@ -5935,8 +6283,9 @@ discard block |
||
5935 | 6283 | global $txt; |
5936 | 6284 | |
5937 | 6285 | // Come on... |
5938 | - if (empty($json) || !is_string($json)) |
|
5939 | - return array(); |
|
6286 | + if (empty($json) || !is_string($json)) { |
|
6287 | + return array(); |
|
6288 | + } |
|
5940 | 6289 | |
5941 | 6290 | $returnArray = @json_decode($json, $returnAsArray); |
5942 | 6291 | |
@@ -5974,11 +6323,11 @@ discard block |
||
5974 | 6323 | $jsonDebug = $jsonDebug[0]; |
5975 | 6324 | loadLanguage('Errors'); |
5976 | 6325 | |
5977 | - if (!empty($jsonDebug)) |
|
5978 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
5979 | - |
|
5980 | - else |
|
5981 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
6326 | + if (!empty($jsonDebug)) { |
|
6327 | + log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
6328 | + } else { |
|
6329 | + log_error($txt['json_'. $jsonError], 'critical'); |
|
6330 | + } |
|
5982 | 6331 | |
5983 | 6332 | // Everyone expects an array. |
5984 | 6333 | return array(); |
@@ -6012,8 +6361,9 @@ discard block |
||
6012 | 6361 | global $db_show_debug, $modSettings; |
6013 | 6362 | |
6014 | 6363 | // Defensive programming anyone? |
6015 | - if (empty($data)) |
|
6016 | - return false; |
|
6364 | + if (empty($data)) { |
|
6365 | + return false; |
|
6366 | + } |
|
6017 | 6367 | |
6018 | 6368 | // Don't need extra stuff... |
6019 | 6369 | $db_show_debug = false; |
@@ -6021,11 +6371,11 @@ discard block |
||
6021 | 6371 | // Kill anything else. |
6022 | 6372 | ob_end_clean(); |
6023 | 6373 | |
6024 | - if (!empty($modSettings['CompressedOutput'])) |
|
6025 | - @ob_start('ob_gzhandler'); |
|
6026 | - |
|
6027 | - else |
|
6028 | - ob_start(); |
|
6374 | + if (!empty($modSettings['CompressedOutput'])) { |
|
6375 | + @ob_start('ob_gzhandler'); |
|
6376 | + } else { |
|
6377 | + ob_start(); |
|
6378 | + } |
|
6029 | 6379 | |
6030 | 6380 | // Set the header. |
6031 | 6381 | header($type); |
@@ -6057,8 +6407,9 @@ discard block |
||
6057 | 6407 | static $done = false; |
6058 | 6408 | |
6059 | 6409 | // If we don't need to do anything, don't |
6060 | - if (!$update && $done) |
|
6061 | - return; |
|
6410 | + if (!$update && $done) { |
|
6411 | + return; |
|
6412 | + } |
|
6062 | 6413 | |
6063 | 6414 | // Should we get a new copy of the official list of TLDs? |
6064 | 6415 | if ($update) |
@@ -6070,8 +6421,9 @@ discard block |
||
6070 | 6421 | // marauding bandits roaming on the surface. We don't want to waste precious electricity on |
6071 | 6422 | // pointlessly repeating background tasks, so we'll wait until the next regularly scheduled |
6072 | 6423 | // update to see if civilization has been restored. |
6073 | - if ($tlds === false) |
|
6074 | - $postapocalypticNightmare = true; |
|
6424 | + if ($tlds === false) { |
|
6425 | + $postapocalypticNightmare = true; |
|
6426 | + } |
|
6075 | 6427 | } |
6076 | 6428 | // If we aren't updating and the regex is valid, we're done |
6077 | 6429 | elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false) |
@@ -6086,10 +6438,11 @@ discard block |
||
6086 | 6438 | // Clean $tlds and convert it to an array |
6087 | 6439 | $tlds = array_filter(explode("\n", strtolower($tlds)), function($line) { |
6088 | 6440 | $line = trim($line); |
6089 | - if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) |
|
6090 | - return false; |
|
6091 | - else |
|
6092 | - return true; |
|
6441 | + if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) { |
|
6442 | + return false; |
|
6443 | + } else { |
|
6444 | + return true; |
|
6445 | + } |
|
6093 | 6446 | }); |
6094 | 6447 | |
6095 | 6448 | // Convert Punycode to Unicode |
@@ -6181,8 +6534,7 @@ discard block |
||
6181 | 6534 | |
6182 | 6535 | $strlen = 'mb_strlen'; |
6183 | 6536 | $substr = 'mb_substr'; |
6184 | - } |
|
6185 | - else |
|
6537 | + } else |
|
6186 | 6538 | { |
6187 | 6539 | $strlen = $smcFunc['strlen']; |
6188 | 6540 | $substr = $smcFunc['substr']; |
@@ -6196,20 +6548,21 @@ discard block |
||
6196 | 6548 | |
6197 | 6549 | $first = $substr($string, 0, 1); |
6198 | 6550 | |
6199 | - if (empty($index[$first])) |
|
6200 | - $index[$first] = array(); |
|
6551 | + if (empty($index[$first])) { |
|
6552 | + $index[$first] = array(); |
|
6553 | + } |
|
6201 | 6554 | |
6202 | 6555 | if ($strlen($string) > 1) |
6203 | 6556 | { |
6204 | 6557 | // Sanity check on recursion |
6205 | - if ($depth > 99) |
|
6206 | - $index[$first][$substr($string, 1)] = ''; |
|
6207 | - |
|
6208 | - else |
|
6209 | - $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
6558 | + if ($depth > 99) { |
|
6559 | + $index[$first][$substr($string, 1)] = ''; |
|
6560 | + } else { |
|
6561 | + $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
6562 | + } |
|
6563 | + } else { |
|
6564 | + $index[$first][''] = ''; |
|
6210 | 6565 | } |
6211 | - else |
|
6212 | - $index[$first][''] = ''; |
|
6213 | 6566 | |
6214 | 6567 | $depth--; |
6215 | 6568 | return $index; |
@@ -6232,9 +6585,9 @@ discard block |
||
6232 | 6585 | $key_regex = preg_quote($key, $delim); |
6233 | 6586 | $new_key = $key; |
6234 | 6587 | |
6235 | - if (empty($value)) |
|
6236 | - $sub_regex = ''; |
|
6237 | - else |
|
6588 | + if (empty($value)) { |
|
6589 | + $sub_regex = ''; |
|
6590 | + } else |
|
6238 | 6591 | { |
6239 | 6592 | $sub_regex = $index_to_regex($value, $delim); |
6240 | 6593 | |
@@ -6242,22 +6595,22 @@ discard block |
||
6242 | 6595 | { |
6243 | 6596 | $new_key_array = explode('(?'.'>', $sub_regex); |
6244 | 6597 | $new_key .= $new_key_array[0]; |
6598 | + } else { |
|
6599 | + $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
6245 | 6600 | } |
6246 | - else |
|
6247 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
6248 | 6601 | } |
6249 | 6602 | |
6250 | - if ($depth > 1) |
|
6251 | - $regex[$new_key] = $key_regex . $sub_regex; |
|
6252 | - else |
|
6603 | + if ($depth > 1) { |
|
6604 | + $regex[$new_key] = $key_regex . $sub_regex; |
|
6605 | + } else |
|
6253 | 6606 | { |
6254 | 6607 | if (($length += strlen($key_regex) + 1) < $max_length || empty($regex)) |
6255 | 6608 | { |
6256 | 6609 | $regex[$new_key] = $key_regex . $sub_regex; |
6257 | 6610 | unset($index[$key]); |
6611 | + } else { |
|
6612 | + break; |
|
6258 | 6613 | } |
6259 | - else |
|
6260 | - break; |
|
6261 | 6614 | } |
6262 | 6615 | } |
6263 | 6616 | |
@@ -6266,10 +6619,11 @@ discard block |
||
6266 | 6619 | $l1 = $strlen($k1); |
6267 | 6620 | $l2 = $strlen($k2); |
6268 | 6621 | |
6269 | - if ($l1 == $l2) |
|
6270 | - return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
6271 | - else |
|
6272 | - return $l1 > $l2 ? -1 : 1; |
|
6622 | + if ($l1 == $l2) { |
|
6623 | + return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
6624 | + } else { |
|
6625 | + return $l1 > $l2 ? -1 : 1; |
|
6626 | + } |
|
6273 | 6627 | }); |
6274 | 6628 | |
6275 | 6629 | $depth--; |
@@ -6280,21 +6634,24 @@ discard block |
||
6280 | 6634 | $index = array(); |
6281 | 6635 | $regex = ''; |
6282 | 6636 | |
6283 | - foreach ($strings as $string) |
|
6284 | - $index = $add_string_to_index($string, $index); |
|
6637 | + foreach ($strings as $string) { |
|
6638 | + $index = $add_string_to_index($string, $index); |
|
6639 | + } |
|
6285 | 6640 | |
6286 | 6641 | if ($returnArray === true) |
6287 | 6642 | { |
6288 | 6643 | $regex = array(); |
6289 | - while (!empty($index)) |
|
6290 | - $regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6644 | + while (!empty($index)) { |
|
6645 | + $regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6646 | + } |
|
6647 | + } else { |
|
6648 | + $regex = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6291 | 6649 | } |
6292 | - else |
|
6293 | - $regex = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6294 | 6650 | |
6295 | 6651 | // Restore PHP's internal character encoding to whatever it was originally |
6296 | - if (!empty($current_encoding)) |
|
6297 | - mb_internal_encoding($current_encoding); |
|
6652 | + if (!empty($current_encoding)) { |
|
6653 | + mb_internal_encoding($current_encoding); |
|
6654 | + } |
|
6298 | 6655 | |
6299 | 6656 | return $regex; |
6300 | 6657 | } |
@@ -6337,13 +6694,15 @@ discard block |
||
6337 | 6694 | // Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't... |
6338 | 6695 | $url = str_ireplace('https://', 'http://', $url) . '/'; |
6339 | 6696 | $headers = @get_headers($url); |
6340 | - if ($headers === false) |
|
6341 | - return false; |
|
6697 | + if ($headers === false) { |
|
6698 | + return false; |
|
6699 | + } |
|
6342 | 6700 | |
6343 | 6701 | // Now to see if it came back https... |
6344 | 6702 | // First check for a redirect status code in first row (301, 302, 307) |
6345 | - if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) |
|
6346 | - return false; |
|
6703 | + if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) { |
|
6704 | + return false; |
|
6705 | + } |
|
6347 | 6706 | |
6348 | 6707 | // Search for the location entry to confirm https |
6349 | 6708 | $result = false; |
@@ -6381,8 +6740,7 @@ discard block |
||
6381 | 6740 | $is_admin = $user_info['is_admin']; |
6382 | 6741 | $mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null; |
6383 | 6742 | $ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null; |
6384 | - } |
|
6385 | - else |
|
6743 | + } else |
|
6386 | 6744 | { |
6387 | 6745 | $request = $smcFunc['db_query']('', ' |
6388 | 6746 | SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group |
@@ -6396,17 +6754,19 @@ discard block |
||
6396 | 6754 | |
6397 | 6755 | $row = $smcFunc['db_fetch_assoc']($request); |
6398 | 6756 | |
6399 | - if (empty($row['additional_groups'])) |
|
6400 | - $groups = array($row['id_group'], $row['id_post_group']); |
|
6401 | - else |
|
6402 | - $groups = array_merge( |
|
6757 | + if (empty($row['additional_groups'])) { |
|
6758 | + $groups = array($row['id_group'], $row['id_post_group']); |
|
6759 | + } else { |
|
6760 | + $groups = array_merge( |
|
6403 | 6761 | array($row['id_group'], $row['id_post_group']), |
6404 | 6762 | explode(',', $row['additional_groups']) |
6405 | 6763 | ); |
6764 | + } |
|
6406 | 6765 | |
6407 | 6766 | // Because history has proven that it is possible for groups to go bad - clean up in case. |
6408 | - foreach ($groups as $k => $v) |
|
6409 | - $groups[$k] = (int) $v; |
|
6767 | + foreach ($groups as $k => $v) { |
|
6768 | + $groups[$k] = (int) $v; |
|
6769 | + } |
|
6410 | 6770 | |
6411 | 6771 | $is_admin = in_array(1, $groups); |
6412 | 6772 | |
@@ -6423,8 +6783,9 @@ discard block |
||
6423 | 6783 | 'current_member' => $userid, |
6424 | 6784 | ) |
6425 | 6785 | ); |
6426 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
6427 | - $boards_mod[] = $row['id_board']; |
|
6786 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
6787 | + $boards_mod[] = $row['id_board']; |
|
6788 | + } |
|
6428 | 6789 | $smcFunc['db_free_result']($request); |
6429 | 6790 | |
6430 | 6791 | // Can any of the groups they're in moderate any of the boards? |
@@ -6436,8 +6797,9 @@ discard block |
||
6436 | 6797 | 'groups' => $groups, |
6437 | 6798 | ) |
6438 | 6799 | ); |
6439 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
6440 | - $boards_mod[] = $row['id_board']; |
|
6800 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
6801 | + $boards_mod[] = $row['id_board']; |
|
6802 | + } |
|
6441 | 6803 | $smcFunc['db_free_result']($request); |
6442 | 6804 | |
6443 | 6805 | // Just in case we've got duplicates here... |
@@ -6447,23 +6809,27 @@ discard block |
||
6447 | 6809 | } |
6448 | 6810 | |
6449 | 6811 | // Just build this here, it makes it easier to change/use - administrators can see all boards. |
6450 | - if ($is_admin) |
|
6451 | - $query_part['query_see_board'] = '1=1'; |
|
6812 | + if ($is_admin) { |
|
6813 | + $query_part['query_see_board'] = '1=1'; |
|
6814 | + } |
|
6452 | 6815 | // Otherwise just the groups in $user_info['groups']. |
6453 | - else |
|
6454 | - $query_part['query_see_board'] = 'EXISTS (SELECT DISTINCT bpv.id_board FROM ' . $db_prefix . 'board_permissions_view bpv WHERE (bpv.id_group IN ( '. implode(',', $groups) .') AND bpv.deny = 0) ' |
|
6816 | + else { |
|
6817 | + $query_part['query_see_board'] = 'EXISTS (SELECT DISTINCT bpv.id_board FROM ' . $db_prefix . 'board_permissions_view bpv WHERE (bpv.id_group IN ( '. implode(',', $groups) .') AND bpv.deny = 0) ' |
|
6455 | 6818 | . ( !empty($deny_boards_access) ? ' AND (bpv.id_group NOT IN ( '. implode(',', $groups) .') and bpv.deny = 1)' : '') |
6456 | 6819 | . ' AND bpv.id_board = b.id_board)'; |
6820 | + } |
|
6457 | 6821 | |
6458 | 6822 | // Build the list of boards they WANT to see. |
6459 | 6823 | // This will take the place of query_see_boards in certain spots, so it better include the boards they can see also |
6460 | 6824 | |
6461 | 6825 | // If they aren't ignoring any boards then they want to see all the boards they can see |
6462 | - if (empty($ignoreboards)) |
|
6463 | - $query_part['query_wanna_see_board'] = $query_part['query_see_board']; |
|
6826 | + if (empty($ignoreboards)) { |
|
6827 | + $query_part['query_wanna_see_board'] = $query_part['query_see_board']; |
|
6828 | + } |
|
6464 | 6829 | // Ok I guess they don't want to see all the boards |
6465 | - else |
|
6466 | - $query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))'; |
|
6830 | + else { |
|
6831 | + $query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))'; |
|
6832 | + } |
|
6467 | 6833 | |
6468 | 6834 | return $query_part; |
6469 | 6835 | } |
@@ -6477,10 +6843,11 @@ discard block |
||
6477 | 6843 | { |
6478 | 6844 | $secure = false; |
6479 | 6845 | |
6480 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
6481 | - $secure = true; |
|
6482 | - elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') |
|
6483 | - $secure = true; |
|
6846 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
6847 | + $secure = true; |
|
6848 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { |
|
6849 | + $secure = true; |
|
6850 | + } |
|
6484 | 6851 | |
6485 | 6852 | return $secure; |
6486 | 6853 | } |
@@ -6497,11 +6864,12 @@ discard block |
||
6497 | 6864 | { |
6498 | 6865 | $url = iri_to_url($iri); |
6499 | 6866 | |
6500 | - if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) |
|
6501 | - return $iri; |
|
6502 | - else |
|
6503 | - return false; |
|
6504 | -} |
|
6867 | + if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) { |
|
6868 | + return $iri; |
|
6869 | + } else { |
|
6870 | + return false; |
|
6871 | + } |
|
6872 | + } |
|
6505 | 6873 | |
6506 | 6874 | /** |
6507 | 6875 | * A wrapper for `filter_var($url, FILTER_SANITIZE_URL)` that can handle URLs |
@@ -6544,8 +6912,9 @@ discard block |
||
6544 | 6912 | |
6545 | 6913 | $host = parse_url((strpos($iri, '://') === false ? 'http://' : '') . ltrim($iri, ':/'), PHP_URL_HOST); |
6546 | 6914 | |
6547 | - if (empty($host)) |
|
6548 | - return $iri; |
|
6915 | + if (empty($host)) { |
|
6916 | + return $iri; |
|
6917 | + } |
|
6549 | 6918 | |
6550 | 6919 | // Convert the domain using the Punycode algorithm |
6551 | 6920 | require_once($sourcedir . '/Class-Punycode.php'); |
@@ -6581,8 +6950,9 @@ discard block |
||
6581 | 6950 | |
6582 | 6951 | $host = parse_url((strpos($url, '://') === false ? 'http://' : '') . ltrim($url, ':/'), PHP_URL_HOST); |
6583 | 6952 | |
6584 | - if (empty($host)) |
|
6585 | - return $url; |
|
6953 | + if (empty($host)) { |
|
6954 | + return $url; |
|
6955 | + } |
|
6586 | 6956 | |
6587 | 6957 | // Decode the domain from Punycode |
6588 | 6958 | require_once($sourcedir . '/Class-Punycode.php'); |
@@ -6608,8 +6978,9 @@ discard block |
||
6608 | 6978 | { |
6609 | 6979 | global $user_info, $modSettings, $smcFunc, $txt; |
6610 | 6980 | |
6611 | - if (empty($modSettings['cron_last_checked'])) |
|
6612 | - $modSettings['cron_last_checked'] = 0; |
|
6981 | + if (empty($modSettings['cron_last_checked'])) { |
|
6982 | + $modSettings['cron_last_checked'] = 0; |
|
6983 | + } |
|
6613 | 6984 | |
6614 | 6985 | if (!empty($modSettings['cron_is_real_cron']) && time() - $modSettings['cron_last_checked'] > 84600) |
6615 | 6986 | { |
@@ -6629,9 +7000,9 @@ discard block |
||
6629 | 7000 | loadLanguage('ManageScheduledTasks'); |
6630 | 7001 | log_error($txt['cron_not_working']); |
6631 | 7002 | updateSettings(array('cron_is_real_cron' => 0)); |
7003 | + } else { |
|
7004 | + updateSettings(array('cron_last_checked' => time())); |
|
6632 | 7005 | } |
6633 | - else |
|
6634 | - updateSettings(array('cron_last_checked' => time())); |
|
6635 | 7006 | } |
6636 | 7007 | } |
6637 | 7008 | |
@@ -6655,10 +7026,11 @@ discard block |
||
6655 | 7026 | |
6656 | 7027 | $protocol = preg_match('~^\s*(HTTP/[12]\.\d)\s*$~i', $_SERVER['SERVER_PROTOCOL'], $matches) ? $matches[1] : 'HTTP/1.0'; |
6657 | 7028 | |
6658 | - if (!isset($statuses[$code]) && empty($status)) |
|
6659 | - header($protocol . ' 500 Internal Server Error'); |
|
6660 | - else |
|
6661 | - header($protocol . ' ' . $code . ' ' . (!empty($status) ? $status : $statuses[$code])); |
|
6662 | -} |
|
7029 | + if (!isset($statuses[$code]) && empty($status)) { |
|
7030 | + header($protocol . ' 500 Internal Server Error'); |
|
7031 | + } else { |
|
7032 | + header($protocol . ' ' . $code . ' ' . (!empty($status) ? $status : $statuses[$code])); |
|
7033 | + } |
|
7034 | + } |
|
6663 | 7035 | |
6664 | 7036 | ?> |
6665 | 7037 | \ No newline at end of file |