@@ -29,9 +29,10 @@ discard block |
||
29 | 29 | // Go through each type of report they can run. |
30 | 30 | foreach ($context['report_types'] as $type) |
31 | 31 | { |
32 | - if (isset($type['description'])) |
|
33 | - echo ' |
|
32 | + if (isset($type['description'])) { |
|
33 | + echo ' |
|
34 | 34 | <dt>', $type['description'], '</dt>'; |
35 | + } |
|
35 | 36 | |
36 | 37 | echo ' |
37 | 38 | <dd> |
@@ -62,8 +63,9 @@ discard block |
||
62 | 63 | </div> |
63 | 64 | <div id="report_buttons">'; |
64 | 65 | |
65 | - if (!empty($context['report_buttons'])) |
|
66 | - template_button_strip($context['report_buttons'], 'right'); |
|
66 | + if (!empty($context['report_buttons'])) { |
|
67 | + template_button_strip($context['report_buttons'], 'right'); |
|
68 | + } |
|
67 | 69 | |
68 | 70 | echo ' |
69 | 71 | </div>'; |
@@ -74,25 +76,27 @@ discard block |
||
74 | 76 | echo ' |
75 | 77 | <table class="table_grid report_results">'; |
76 | 78 | |
77 | - if (!empty($table['title'])) |
|
78 | - echo ' |
|
79 | + if (!empty($table['title'])) { |
|
80 | + echo ' |
|
79 | 81 | <thead> |
80 | 82 | <tr class="title_bar"> |
81 | 83 | <th scope="col" colspan="', $table['column_count'], '">', $table['title'], '</th> |
82 | 84 | </tr> |
83 | 85 | </thead> |
84 | 86 | <tbody>'; |
87 | + } |
|
85 | 88 | |
86 | 89 | // Now do each row! |
87 | 90 | $row_number = 0; |
88 | 91 | foreach ($table['data'] as $row) |
89 | 92 | { |
90 | - if ($row_number == 0 && !empty($table['shading']['top'])) |
|
91 | - echo ' |
|
93 | + if ($row_number == 0 && !empty($table['shading']['top'])) { |
|
94 | + echo ' |
|
92 | 95 | <tr class="windowbg table_caption">'; |
93 | - else |
|
94 | - echo ' |
|
96 | + } else { |
|
97 | + echo ' |
|
95 | 98 | <tr class="', !empty($row[0]['separator']) ? 'title_bar' : 'windowbg', '">'; |
99 | + } |
|
96 | 100 | |
97 | 101 | // Now do each column. |
98 | 102 | $column_number = 0; |
@@ -110,16 +114,17 @@ discard block |
||
110 | 114 | } |
111 | 115 | |
112 | 116 | // Shaded? |
113 | - if ($column_number == 0 && !empty($table['shading']['left'])) |
|
114 | - echo ' |
|
117 | + if ($column_number == 0 && !empty($table['shading']['left'])) { |
|
118 | + echo ' |
|
115 | 119 | <td class="table_caption ', $table['align']['shaded'], 'text"', $table['width']['shaded'] != 'auto' ? ' width="' . $table['width']['shaded'] . '"' : '', '> |
116 | 120 | ', $data['v'] == $table['default_value'] ? '' : ($data['v'] . (empty($data['v']) ? '' : ':')), ' |
117 | 121 | </td>'; |
118 | - else |
|
119 | - echo ' |
|
122 | + } else { |
|
123 | + echo ' |
|
120 | 124 | <td class="smalltext centertext" ', $table['width']['normal'] != 'auto' ? ' width="' . $table['width']['normal'] . '"' : '', !empty($data['style']) ? ' style="' . $data['style'] . '"' : '', '> |
121 | 125 | ', $data['v'], ' |
122 | 126 | </td>'; |
127 | + } |
|
123 | 128 | |
124 | 129 | $column_number++; |
125 | 130 | } |
@@ -168,24 +173,26 @@ discard block |
||
168 | 173 | <div style="overflow: visible;', $table['max_width'] != 'auto' ? ' width: ' . $table['max_width'] . 'px;' : '', '"> |
169 | 174 | <table class="bordercolor">'; |
170 | 175 | |
171 | - if (!empty($table['title'])) |
|
172 | - echo ' |
|
176 | + if (!empty($table['title'])) { |
|
177 | + echo ' |
|
173 | 178 | <tr class="title_bar"> |
174 | 179 | <td colspan="', $table['column_count'], '"> |
175 | 180 | ', $table['title'], ' |
176 | 181 | </td> |
177 | 182 | </tr>'; |
183 | + } |
|
178 | 184 | |
179 | 185 | // Now do each row! |
180 | 186 | $row_number = 0; |
181 | 187 | foreach ($table['data'] as $row) |
182 | 188 | { |
183 | - if ($row_number == 0 && !empty($table['shading']['top'])) |
|
184 | - echo ' |
|
189 | + if ($row_number == 0 && !empty($table['shading']['top'])) { |
|
190 | + echo ' |
|
185 | 191 | <tr class="titlebg">'; |
186 | - else |
|
187 | - echo ' |
|
192 | + } else { |
|
193 | + echo ' |
|
188 | 194 | <tr class="windowbg">'; |
195 | + } |
|
189 | 196 | |
190 | 197 | // Now do each column!! |
191 | 198 | $column_number = 0; |
@@ -202,16 +209,17 @@ discard block |
||
202 | 209 | } |
203 | 210 | |
204 | 211 | // Shaded? |
205 | - if ($column_number == 0 && !empty($table['shading']['left'])) |
|
206 | - echo ' |
|
212 | + if ($column_number == 0 && !empty($table['shading']['left'])) { |
|
213 | + echo ' |
|
207 | 214 | <td class="titlebg ', $table['align']['shaded'], 'text"', $table['width']['shaded'] != 'auto' ? ' width="' . $table['width']['shaded'] . '"' : '', '> |
208 | 215 | ', $data['v'] == $table['default_value'] ? '' : ($data['v'] . (empty($data['v']) ? '' : ':')), ' |
209 | 216 | </td>'; |
210 | - else |
|
211 | - echo ' |
|
217 | + } else { |
|
218 | + echo ' |
|
212 | 219 | <td class="centertext" ', $table['width']['normal'] != 'auto' ? ' width="' . $table['width']['normal'] . '"' : '', !empty($data['style']) ? ' style="' . $data['style'] . '"' : '', '> |
213 | 220 | ', $data['v'], ' |
214 | 221 | </td>'; |
222 | + } |
|
215 | 223 | |
216 | 224 | $column_number++; |
217 | 225 | } |
@@ -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 | * Main entry point for the admin search settings screen. |
@@ -107,11 +108,13 @@ discard block |
||
107 | 108 | // Perhaps the search method wants to add some settings? |
108 | 109 | require_once($sourcedir . '/Search.php'); |
109 | 110 | $searchAPI = findSearchAPI(); |
110 | - if (is_callable(array($searchAPI, 'searchSettings'))) |
|
111 | - call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars)); |
|
111 | + if (is_callable(array($searchAPI, 'searchSettings'))) { |
|
112 | + call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars)); |
|
113 | + } |
|
112 | 114 | |
113 | - if ($return_config) |
|
114 | - return $config_vars; |
|
115 | + if ($return_config) { |
|
116 | + return $config_vars; |
|
117 | + } |
|
115 | 118 | |
116 | 119 | $context['page_title'] = $txt['search_settings_title']; |
117 | 120 | $context['sub_template'] = 'show_settings'; |
@@ -126,8 +129,9 @@ discard block |
||
126 | 129 | |
127 | 130 | call_integration_hook('integrate_save_search_settings'); |
128 | 131 | |
129 | - if (empty($_POST['search_results_per_page'])) |
|
130 | - $_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages']; |
|
132 | + if (empty($_POST['search_results_per_page'])) { |
|
133 | + $_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages']; |
|
134 | + } |
|
131 | 135 | saveDBSettings($config_vars); |
132 | 136 | $_SESSION['adm-save'] = true; |
133 | 137 | redirectexit('action=admin;area=managesearch;sa=settings;' . $context['session_var'] . '=' . $context['session_id']); |
@@ -177,17 +181,20 @@ discard block |
||
177 | 181 | call_integration_hook('integrate_save_search_weights'); |
178 | 182 | |
179 | 183 | $changes = array(); |
180 | - foreach ($factors as $factor) |
|
181 | - $changes[$factor] = (int) $_POST[$factor]; |
|
184 | + foreach ($factors as $factor) { |
|
185 | + $changes[$factor] = (int) $_POST[$factor]; |
|
186 | + } |
|
182 | 187 | updateSettings($changes); |
183 | 188 | } |
184 | 189 | |
185 | 190 | $context['relative_weights'] = array('total' => 0); |
186 | - foreach ($factors as $factor) |
|
187 | - $context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0; |
|
191 | + foreach ($factors as $factor) { |
|
192 | + $context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0; |
|
193 | + } |
|
188 | 194 | |
189 | - foreach ($factors as $factor) |
|
190 | - $context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1); |
|
195 | + foreach ($factors as $factor) { |
|
196 | + $context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1); |
|
197 | + } |
|
191 | 198 | |
192 | 199 | createToken('admin-msw'); |
193 | 200 | } |
@@ -215,8 +222,9 @@ discard block |
||
215 | 222 | $context['search_apis'] = loadSearchAPIs(); |
216 | 223 | |
217 | 224 | // Detect whether a fulltext index is set. |
218 | - if ($context['supports_fulltext']) |
|
219 | - detectFulltextIndex(); |
|
225 | + if ($context['supports_fulltext']) { |
|
226 | + detectFulltextIndex(); |
|
227 | + } |
|
220 | 228 | |
221 | 229 | if (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'createfulltext') |
222 | 230 | { |
@@ -240,8 +248,7 @@ discard block |
||
240 | 248 | 'language' => $language_ftx |
241 | 249 | ) |
242 | 250 | ); |
243 | - } |
|
244 | - else |
|
251 | + } else |
|
245 | 252 | { |
246 | 253 | // Make sure it's gone before creating it. |
247 | 254 | $smcFunc['db_query']('', ' |
@@ -259,8 +266,7 @@ discard block |
||
259 | 266 | ) |
260 | 267 | ); |
261 | 268 | } |
262 | - } |
|
263 | - elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index'])) |
|
269 | + } elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index'])) |
|
264 | 270 | { |
265 | 271 | checkSession('get'); |
266 | 272 | validateToken('admin-msm', 'get'); |
@@ -277,12 +283,12 @@ discard block |
||
277 | 283 | $context['fulltext_index'] = array(); |
278 | 284 | |
279 | 285 | // Go back to the default search method. |
280 | - if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext') |
|
281 | - updateSettings(array( |
|
286 | + if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext') { |
|
287 | + updateSettings(array( |
|
282 | 288 | 'search_index' => '', |
283 | 289 | )); |
284 | - } |
|
285 | - elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom') |
|
290 | + } |
|
291 | + } elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom') |
|
286 | 292 | { |
287 | 293 | checkSession('get'); |
288 | 294 | validateToken('admin-msm', 'get'); |
@@ -304,12 +310,12 @@ discard block |
||
304 | 310 | )); |
305 | 311 | |
306 | 312 | // Go back to the default search method. |
307 | - if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') |
|
308 | - updateSettings(array( |
|
313 | + if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') { |
|
314 | + updateSettings(array( |
|
309 | 315 | 'search_index' => '', |
310 | 316 | )); |
311 | - } |
|
312 | - elseif (isset($_POST['save'])) |
|
317 | + } |
|
318 | + } elseif (isset($_POST['save'])) |
|
313 | 319 | { |
314 | 320 | checkSession(); |
315 | 321 | validateToken('admin-msmpost'); |
@@ -331,8 +337,8 @@ discard block |
||
331 | 337 | // Get some info about the messages table, to show its size and index size. |
332 | 338 | if ($db_type == 'mysql') |
333 | 339 | { |
334 | - if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) |
|
335 | - $request = $smcFunc['db_query']('', ' |
|
340 | + if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) { |
|
341 | + $request = $smcFunc['db_query']('', ' |
|
336 | 342 | SHOW TABLE STATUS |
337 | 343 | FROM {string:database_name} |
338 | 344 | LIKE {string:table_name}', |
@@ -341,14 +347,15 @@ discard block |
||
341 | 347 | 'table_name' => str_replace('_', '\_', $match[2]) . 'messages', |
342 | 348 | ) |
343 | 349 | ); |
344 | - else |
|
345 | - $request = $smcFunc['db_query']('', ' |
|
350 | + } else { |
|
351 | + $request = $smcFunc['db_query']('', ' |
|
346 | 352 | SHOW TABLE STATUS |
347 | 353 | LIKE {string:table_name}', |
348 | 354 | array( |
349 | 355 | 'table_name' => str_replace('_', '\_', $db_prefix) . 'messages', |
350 | 356 | ) |
351 | 357 | ); |
358 | + } |
|
352 | 359 | if ($request !== false && $smcFunc['db_num_rows']($request) == 1) |
353 | 360 | { |
354 | 361 | // Only do this if the user has permission to execute this query. |
@@ -360,8 +367,8 @@ discard block |
||
360 | 367 | } |
361 | 368 | |
362 | 369 | // Now check the custom index table, if it exists at all. |
363 | - if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) |
|
364 | - $request = $smcFunc['db_query']('', ' |
|
370 | + if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) { |
|
371 | + $request = $smcFunc['db_query']('', ' |
|
365 | 372 | SHOW TABLE STATUS |
366 | 373 | FROM {string:database_name} |
367 | 374 | LIKE {string:table_name}', |
@@ -370,14 +377,15 @@ discard block |
||
370 | 377 | 'table_name' => str_replace('_', '\_', $match[2]) . 'log_search_words', |
371 | 378 | ) |
372 | 379 | ); |
373 | - else |
|
374 | - $request = $smcFunc['db_query']('', ' |
|
380 | + } else { |
|
381 | + $request = $smcFunc['db_query']('', ' |
|
375 | 382 | SHOW TABLE STATUS |
376 | 383 | LIKE {string:table_name}', |
377 | 384 | array( |
378 | 385 | 'table_name' => str_replace('_', '\_', $db_prefix) . 'log_search_words', |
379 | 386 | ) |
380 | 387 | ); |
388 | + } |
|
381 | 389 | if ($request !== false && $smcFunc['db_num_rows']($request) == 1) |
382 | 390 | { |
383 | 391 | // Only do this if the user has permission to execute this query. |
@@ -386,8 +394,7 @@ discard block |
||
386 | 394 | $context['table_info']['custom_index_length'] = $row['Data_length'] + $row['Index_length']; |
387 | 395 | $smcFunc['db_free_result']($request); |
388 | 396 | } |
389 | - } |
|
390 | - elseif ($db_type == 'postgresql') |
|
397 | + } elseif ($db_type == 'postgresql') |
|
391 | 398 | { |
392 | 399 | // In order to report the sizes correctly we need to perform vacuum (optimize) on the tables we will be using. |
393 | 400 | //db_extend(); |
@@ -429,38 +436,38 @@ discard block |
||
429 | 436 | $context['table_info']['data_length'] = (int) $row['table_size']; |
430 | 437 | $context['table_info']['index_length'] = (int) $row['index_size']; |
431 | 438 | $context['table_info']['fulltext_length'] = (int) $row['index_size']; |
432 | - } |
|
433 | - elseif ($row['indexname'] == $db_prefix . 'log_search_words') |
|
439 | + } elseif ($row['indexname'] == $db_prefix . 'log_search_words') |
|
434 | 440 | { |
435 | 441 | $context['table_info']['index_length'] = (int) $row['index_size']; |
436 | 442 | $context['table_info']['custom_index_length'] = (int) $row['index_size']; |
437 | 443 | } |
438 | 444 | } |
439 | 445 | $smcFunc['db_free_result']($request); |
440 | - } |
|
441 | - else |
|
442 | - // Didn't work for some reason... |
|
446 | + } else { |
|
447 | + // Didn't work for some reason... |
|
443 | 448 | $context['table_info'] = array( |
444 | 449 | 'data_length' => $txt['not_applicable'], |
445 | 450 | 'index_length' => $txt['not_applicable'], |
446 | 451 | 'fulltext_length' => $txt['not_applicable'], |
447 | 452 | 'custom_index_length' => $txt['not_applicable'], |
448 | 453 | ); |
449 | - } |
|
450 | - else |
|
451 | - $context['table_info'] = array( |
|
454 | + } |
|
455 | + } else { |
|
456 | + $context['table_info'] = array( |
|
452 | 457 | 'data_length' => $txt['not_applicable'], |
453 | 458 | 'index_length' => $txt['not_applicable'], |
454 | 459 | 'fulltext_length' => $txt['not_applicable'], |
455 | 460 | 'custom_index_length' => $txt['not_applicable'], |
456 | 461 | ); |
462 | + } |
|
457 | 463 | |
458 | 464 | // Format the data and index length in kilobytes. |
459 | 465 | foreach ($context['table_info'] as $type => $size) |
460 | 466 | { |
461 | 467 | // If it's not numeric then just break. This database engine doesn't support size. |
462 | - if (!is_numeric($size)) |
|
463 | - break; |
|
468 | + if (!is_numeric($size)) { |
|
469 | + break; |
|
470 | + } |
|
464 | 471 | |
465 | 472 | $context['table_info'][$type] = comma_format($context['table_info'][$type] / 1024) . ' ' . $txt['search_method_kilobytes']; |
466 | 473 | } |
@@ -489,8 +496,9 @@ discard block |
||
489 | 496 | |
490 | 497 | // Scotty, we need more time... |
491 | 498 | @set_time_limit(600); |
492 | - if (function_exists('apache_reset_timeout')) |
|
493 | - @apache_reset_timeout(); |
|
499 | + if (function_exists('apache_reset_timeout')) { |
|
500 | + @apache_reset_timeout(); |
|
501 | + } |
|
494 | 502 | |
495 | 503 | $context[$context['admin_menu_name']]['current_subsection'] = 'method'; |
496 | 504 | $context['page_title'] = $txt['search_index_custom']; |
@@ -520,8 +528,7 @@ discard block |
||
520 | 528 | $context['start'] = (int) $context['index_settings']['resume_at']; |
521 | 529 | unset($context['index_settings']['resume_at']); |
522 | 530 | $context['step'] = 1; |
523 | - } |
|
524 | - else |
|
531 | + } else |
|
525 | 532 | { |
526 | 533 | $context['index_settings'] = array( |
527 | 534 | 'bytes_per_word' => isset($_REQUEST['bytes_per_word']) && isset($index_properties[$_REQUEST['bytes_per_word']]) ? (int) $_REQUEST['bytes_per_word'] : 2, |
@@ -530,12 +537,14 @@ discard block |
||
530 | 537 | $context['step'] = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0; |
531 | 538 | |
532 | 539 | // admin timeouts are painful when building these long indexes - but only if we actually have such things enabled |
533 | - if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1) |
|
534 | - $_SESSION['admin_time'] = time(); |
|
540 | + if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1) { |
|
541 | + $_SESSION['admin_time'] = time(); |
|
542 | + } |
|
535 | 543 | } |
536 | 544 | |
537 | - if ($context['step'] !== 0) |
|
538 | - checkSession('request'); |
|
545 | + if ($context['step'] !== 0) { |
|
546 | + checkSession('request'); |
|
547 | + } |
|
539 | 548 | |
540 | 549 | // Step 0: let the user determine how they like their index. |
541 | 550 | if ($context['step'] === 0) |
@@ -564,12 +573,14 @@ discard block |
||
564 | 573 | $smcFunc['db_create_word_search']($index_properties[$context['index_settings']['bytes_per_word']]['column_definition']); |
565 | 574 | |
566 | 575 | // Temporarily switch back to not using a search index. |
567 | - if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') |
|
568 | - updateSettings(array('search_index' => '')); |
|
576 | + if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') { |
|
577 | + updateSettings(array('search_index' => '')); |
|
578 | + } |
|
569 | 579 | |
570 | 580 | // Don't let simultanious processes be updating the search index. |
571 | - if (!empty($modSettings['search_custom_index_config'])) |
|
572 | - updateSettings(array('search_custom_index_config' => '')); |
|
581 | + if (!empty($modSettings['search_custom_index_config'])) { |
|
582 | + updateSettings(array('search_custom_index_config' => '')); |
|
583 | + } |
|
573 | 584 | } |
574 | 585 | |
575 | 586 | $num_messages = array( |
@@ -585,16 +596,16 @@ discard block |
||
585 | 596 | 'starting_id' => $context['start'], |
586 | 597 | ) |
587 | 598 | ); |
588 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
589 | - $num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages']; |
|
599 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
600 | + $num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages']; |
|
601 | + } |
|
590 | 602 | |
591 | 603 | if (empty($num_messages['todo'])) |
592 | 604 | { |
593 | 605 | $context['step'] = 2; |
594 | 606 | $context['percentage'] = 80; |
595 | 607 | $context['start'] = 0; |
596 | - } |
|
597 | - else |
|
608 | + } else |
|
598 | 609 | { |
599 | 610 | // Number of seconds before the next step. |
600 | 611 | $stop = time() + 3; |
@@ -635,21 +646,22 @@ discard block |
||
635 | 646 | |
636 | 647 | $context['start'] += $forced_break ? $number_processed : $messages_per_batch; |
637 | 648 | |
638 | - if (!empty($inserts)) |
|
639 | - $smcFunc['db_insert']('ignore', |
|
649 | + if (!empty($inserts)) { |
|
650 | + $smcFunc['db_insert']('ignore', |
|
640 | 651 | '{db_prefix}log_search_words', |
641 | 652 | array('id_word' => 'int', 'id_msg' => 'int'), |
642 | 653 | $inserts, |
643 | 654 | array('id_word', 'id_msg') |
644 | 655 | ); |
656 | + } |
|
645 | 657 | if ($num_messages['todo'] === 0) |
646 | 658 | { |
647 | 659 | $context['step'] = 2; |
648 | 660 | $context['start'] = 0; |
649 | 661 | break; |
662 | + } else { |
|
663 | + updateSettings(array('search_custom_index_resume' => $smcFunc['json_encode'](array_merge($context['index_settings'], array('resume_at' => $context['start']))))); |
|
650 | 664 | } |
651 | - else |
|
652 | - updateSettings(array('search_custom_index_resume' => $smcFunc['json_encode'](array_merge($context['index_settings'], array('resume_at' => $context['start']))))); |
|
653 | 665 | } |
654 | 666 | |
655 | 667 | // Since there are still two steps to go, 80% is the maximum here. |
@@ -660,9 +672,9 @@ discard block |
||
660 | 672 | // Step 2: removing the words that occur too often and are of no use. |
661 | 673 | elseif ($context['step'] === 2) |
662 | 674 | { |
663 | - if ($context['index_settings']['bytes_per_word'] < 4) |
|
664 | - $context['step'] = 3; |
|
665 | - else |
|
675 | + if ($context['index_settings']['bytes_per_word'] < 4) { |
|
676 | + $context['step'] = 3; |
|
677 | + } else |
|
666 | 678 | { |
667 | 679 | $stop_words = $context['start'] === 0 || empty($modSettings['search_stopwords']) ? array() : explode(',', $modSettings['search_stopwords']); |
668 | 680 | $stop = time() + 3; |
@@ -683,20 +695,22 @@ discard block |
||
683 | 695 | 'minimum_messages' => $max_messages, |
684 | 696 | ) |
685 | 697 | ); |
686 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
687 | - $stop_words[] = $row['id_word']; |
|
698 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
699 | + $stop_words[] = $row['id_word']; |
|
700 | + } |
|
688 | 701 | $smcFunc['db_free_result']($request); |
689 | 702 | |
690 | 703 | updateSettings(array('search_stopwords' => implode(',', $stop_words))); |
691 | 704 | |
692 | - if (!empty($stop_words)) |
|
693 | - $smcFunc['db_query']('', ' |
|
705 | + if (!empty($stop_words)) { |
|
706 | + $smcFunc['db_query']('', ' |
|
694 | 707 | DELETE FROM {db_prefix}log_search_words |
695 | 708 | WHERE id_word in ({array_int:stop_words})', |
696 | 709 | array( |
697 | 710 | 'stop_words' => $stop_words, |
698 | 711 | ) |
699 | 712 | ); |
713 | + } |
|
700 | 714 | |
701 | 715 | $context['start'] += $index_properties[$context['index_settings']['bytes_per_word']]['step_size']; |
702 | 716 | if ($context['start'] > $index_properties[$context['index_settings']['bytes_per_word']]['max_size']) |
@@ -757,8 +771,9 @@ discard block |
||
757 | 771 | $searchAPI = new $search_class_name(); |
758 | 772 | |
759 | 773 | // No Support? NEXT! |
760 | - if (!$searchAPI->is_supported) |
|
761 | - continue; |
|
774 | + if (!$searchAPI->is_supported) { |
|
775 | + continue; |
|
776 | + } |
|
762 | 777 | |
763 | 778 | $apis[$index_name] = array( |
764 | 779 | 'filename' => $file, |
@@ -805,10 +820,10 @@ discard block |
||
805 | 820 | 'messages_ftx' => $db_prefix . 'messages_ftx', |
806 | 821 | ) |
807 | 822 | ); |
808 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
809 | - $context['fulltext_index'][] = $row['indexname']; |
|
810 | - } |
|
811 | - else |
|
823 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
824 | + $context['fulltext_index'][] = $row['indexname']; |
|
825 | + } |
|
826 | + } else |
|
812 | 827 | { |
813 | 828 | $request = $smcFunc['db_query']('', ' |
814 | 829 | SHOW INDEX |
@@ -819,17 +834,19 @@ discard block |
||
819 | 834 | $context['fulltext_index'] = array(); |
820 | 835 | if ($request !== false || $smcFunc['db_num_rows']($request) != 0) |
821 | 836 | { |
822 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
823 | - if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
837 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
838 | + if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
824 | 839 | $context['fulltext_index'][] = $row['Key_name']; |
840 | + } |
|
825 | 841 | $smcFunc['db_free_result']($request); |
826 | 842 | |
827 | - if (is_array($context['fulltext_index'])) |
|
828 | - $context['fulltext_index'] = array_unique($context['fulltext_index']); |
|
843 | + if (is_array($context['fulltext_index'])) { |
|
844 | + $context['fulltext_index'] = array_unique($context['fulltext_index']); |
|
845 | + } |
|
829 | 846 | } |
830 | 847 | |
831 | - if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) |
|
832 | - $request = $smcFunc['db_query']('', ' |
|
848 | + if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) { |
|
849 | + $request = $smcFunc['db_query']('', ' |
|
833 | 850 | SHOW TABLE STATUS |
834 | 851 | FROM {string:database_name} |
835 | 852 | LIKE {string:table_name}', |
@@ -838,20 +855,22 @@ discard block |
||
838 | 855 | 'table_name' => str_replace('_', '\_', $match[2]) . 'messages', |
839 | 856 | ) |
840 | 857 | ); |
841 | - else |
|
842 | - $request = $smcFunc['db_query']('', ' |
|
858 | + } else { |
|
859 | + $request = $smcFunc['db_query']('', ' |
|
843 | 860 | SHOW TABLE STATUS |
844 | 861 | LIKE {string:table_name}', |
845 | 862 | array( |
846 | 863 | 'table_name' => str_replace('_', '\_', $db_prefix) . 'messages', |
847 | 864 | ) |
848 | 865 | ); |
866 | + } |
|
849 | 867 | |
850 | 868 | if ($request !== false) |
851 | 869 | { |
852 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
853 | - if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'](), '5.6.4', '>='))) |
|
870 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
871 | + if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'](), '5.6.4', '>='))) |
|
854 | 872 | $context['cannot_create_fulltext'] = true; |
873 | + } |
|
855 | 874 | $smcFunc['db_free_result']($request); |
856 | 875 | } |
857 | 876 | } |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | 'class' => 'centercol', |
394 | 394 | ), |
395 | 395 | 'data' => array( |
396 | - 'function' => function ($rowData) |
|
396 | + 'function' => function($rowData) |
|
397 | 397 | { |
398 | 398 | return $rowData['selected'] ? '<span class="generic_icons valid"></span>' : ''; |
399 | 399 | }, |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | 'class' => 'centercol', |
454 | 454 | ), |
455 | 455 | 'data' => array( |
456 | - 'function' => function ($rowData) |
|
456 | + 'function' => function($rowData) |
|
457 | 457 | { |
458 | 458 | return $rowData['selected'] ? '' : sprintf('<input type="checkbox" name="smiley_set[%1$d]">', $rowData['id']); |
459 | 459 | }, |
@@ -997,7 +997,7 @@ discard block |
||
997 | 997 | 'value' => $txt['smileys_location'], |
998 | 998 | ), |
999 | 999 | 'data' => array( |
1000 | - 'function' => function ($rowData) use ($txt) |
|
1000 | + 'function' => function($rowData) use ($txt) |
|
1001 | 1001 | { |
1002 | 1002 | if (empty($rowData['hidden'])) |
1003 | 1003 | return $txt['smileys_location_form']; |
@@ -1008,7 +1008,7 @@ discard block |
||
1008 | 1008 | }, |
1009 | 1009 | ), |
1010 | 1010 | 'sort' => array( |
1011 | - 'default' => $smcFunc['db_custom_order']('hidden', array_keys($smiley_locations)) , |
|
1011 | + 'default' => $smcFunc['db_custom_order']('hidden', array_keys($smiley_locations)), |
|
1012 | 1012 | 'reverse' => $smcFunc['db_custom_order']('hidden', array_keys($smiley_locations), true), |
1013 | 1013 | ), |
1014 | 1014 | ), |
@@ -1017,7 +1017,7 @@ discard block |
||
1017 | 1017 | 'value' => $txt['smileys_description'], |
1018 | 1018 | ), |
1019 | 1019 | 'data' => array( |
1020 | - 'function' => function ($rowData) use ($context, $txt, $modSettings, $smcFunc) |
|
1020 | + 'function' => function($rowData) use ($context, $txt, $modSettings, $smcFunc) |
|
1021 | 1021 | { |
1022 | 1022 | if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) |
1023 | 1023 | return $smcFunc['htmlspecialchars']($rowData['description']); |
@@ -1554,7 +1554,7 @@ discard block |
||
1554 | 1554 | 'action' => $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.'))) |
1555 | 1555 | ); |
1556 | 1556 | |
1557 | - $file = $packagesdir . '/temp/' . $base_path . $action['filename']; |
|
1557 | + $file = $packagesdir . '/temp/' . $base_path . $action['filename']; |
|
1558 | 1558 | if (isset($action['filename']) && (!file_exists($file) || !is_writable(dirname($action['destination'])))) |
1559 | 1559 | { |
1560 | 1560 | $context['has_failure'] = true; |
@@ -1599,7 +1599,7 @@ discard block |
||
1599 | 1599 | { |
1600 | 1600 | updateSettings(array( |
1601 | 1601 | 'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . basename($action['action']), |
1602 | - 'smiley_sets_names' => $modSettings['smiley_sets_names'] . "\n" . $smileyInfo['name'] . (count($context['actions']) > 1 ? ' ' . (!empty($action['description']) ? $smcFunc['htmlspecialchars']($action['description']) : basename($action['action'])) : ''), |
|
1602 | + 'smiley_sets_names' => $modSettings['smiley_sets_names'] . "\n" . $smileyInfo['name'] . (count($context['actions']) > 1 ? ' ' . (!empty($action['description']) ? $smcFunc['htmlspecialchars']($action['description']) : basename($action['action'])) : ''), |
|
1603 | 1603 | )); |
1604 | 1604 | } |
1605 | 1605 | |
@@ -1611,7 +1611,7 @@ discard block |
||
1611 | 1611 | '{db_prefix}log_packages', |
1612 | 1612 | array( |
1613 | 1613 | 'filename' => 'string', 'name' => 'string', 'package_id' => 'string', 'version' => 'string', |
1614 | - 'id_member_installed' => 'int', 'member_installed' => 'string','time_installed' => 'int', |
|
1614 | + 'id_member_installed' => 'int', 'member_installed' => 'string', 'time_installed' => 'int', |
|
1615 | 1615 | 'install_state' => 'int', 'failed_steps' => 'string', 'themes_installed' => 'string', |
1616 | 1616 | 'member_removed' => 'int', 'db_changes' => 'string', 'credits' => 'string', |
1617 | 1617 | ), |
@@ -1860,7 +1860,7 @@ discard block |
||
1860 | 1860 | 'columns' => array( |
1861 | 1861 | 'icon' => array( |
1862 | 1862 | 'data' => array( |
1863 | - 'function' => function ($rowData) use ($settings, $smcFunc) |
|
1863 | + 'function' => function($rowData) use ($settings, $smcFunc) |
|
1864 | 1864 | { |
1865 | 1865 | $images_url = $settings[file_exists(sprintf('%1$s/images/post/%2$s.png', $settings['theme_dir'], $rowData['filename'])) ? 'actual_images_url' : 'default_images_url']; |
1866 | 1866 | return sprintf('<img src="%1$s/post/%2$s.png" alt="%3$s">', $images_url, $rowData['filename'], $smcFunc['htmlspecialchars']($rowData['title'])); |
@@ -1894,7 +1894,7 @@ discard block |
||
1894 | 1894 | 'value' => $txt['icons_board'], |
1895 | 1895 | ), |
1896 | 1896 | 'data' => array( |
1897 | - 'function' => function ($rowData) use ($txt) |
|
1897 | + 'function' => function($rowData) use ($txt) |
|
1898 | 1898 | { |
1899 | 1899 | return empty($rowData['board_name']) ? $txt['icons_edit_icons_all_boards'] : $rowData['board_name']; |
1900 | 1900 | }, |
@@ -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 | * This is the dispatcher of smileys administration. |
@@ -91,8 +92,9 @@ discard block |
||
91 | 92 | ); |
92 | 93 | |
93 | 94 | // Some settings may not be enabled, disallow these from the tabs as appropriate. |
94 | - if (empty($modSettings['messageIcons_enable'])) |
|
95 | - $context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true; |
|
95 | + if (empty($modSettings['messageIcons_enable'])) { |
|
96 | + $context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true; |
|
97 | + } |
|
96 | 98 | if (empty($modSettings['smiley_enable'])) |
97 | 99 | { |
98 | 100 | $context[$context['admin_menu_name']]['tab_data']['tabs']['addsmiley']['disabled'] = true; |
@@ -125,8 +127,9 @@ discard block |
||
125 | 127 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
126 | 128 | |
127 | 129 | $smiley_context = array(); |
128 | - foreach ($smiley_sets as $i => $set) |
|
129 | - $smiley_context[$set] = $set_names[$i]; |
|
130 | + foreach ($smiley_sets as $i => $set) { |
|
131 | + $smiley_context[$set] = $set_names[$i]; |
|
132 | + } |
|
130 | 133 | |
131 | 134 | // All the settings for the page... |
132 | 135 | $config_vars = array( |
@@ -147,8 +150,9 @@ discard block |
||
147 | 150 | |
148 | 151 | call_integration_hook('integrate_modify_smiley_settings', array(&$config_vars)); |
149 | 152 | |
150 | - if ($return_config) |
|
151 | - return $config_vars; |
|
153 | + if ($return_config) { |
|
154 | + return $config_vars; |
|
155 | + } |
|
152 | 156 | |
153 | 157 | // Setup the basics of the settings template. |
154 | 158 | require_once($sourcedir . '/ManageServer.php'); |
@@ -208,8 +212,9 @@ discard block |
||
208 | 212 | foreach ($_POST['smiley_set'] as $id => $val) |
209 | 213 | { |
210 | 214 | // If this is the set you've marked as default, or the only one remaining, you can't delete it |
211 | - if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) |
|
212 | - unset($set_paths[$id], $set_names[$id], $set_exts[$id]); |
|
215 | + if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) { |
|
216 | + unset($set_paths[$id], $set_names[$id], $set_exts[$id]); |
|
217 | + } |
|
213 | 218 | } |
214 | 219 | |
215 | 220 | // Shortcut... array_merge() on a single array resets the numeric keys |
@@ -225,8 +230,9 @@ discard block |
||
225 | 230 | )); |
226 | 231 | } |
227 | 232 | // Add a new smiley set. |
228 | - elseif (!empty($_POST['add'])) |
|
229 | - $context['sub_action'] = 'modifyset'; |
|
233 | + elseif (!empty($_POST['add'])) { |
|
234 | + $context['sub_action'] = 'modifyset'; |
|
235 | + } |
|
230 | 236 | // Create or modify a smiley set. |
231 | 237 | elseif (isset($_POST['set'])) |
232 | 238 | { |
@@ -237,8 +243,9 @@ discard block |
||
237 | 243 | // Create a new smiley set. |
238 | 244 | if ($_POST['set'] == -1 && isset($_POST['smiley_sets_path'])) |
239 | 245 | { |
240 | - if (in_array($_POST['smiley_sets_path'], $set_paths)) |
|
241 | - fatal_lang_error('smiley_set_already_exists'); |
|
246 | + if (in_array($_POST['smiley_sets_path'], $set_paths)) { |
|
247 | + fatal_lang_error('smiley_set_already_exists'); |
|
248 | + } |
|
242 | 249 | |
243 | 250 | updateSettings(array( |
244 | 251 | 'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . $_POST['smiley_sets_path'], |
@@ -251,12 +258,14 @@ discard block |
||
251 | 258 | else |
252 | 259 | { |
253 | 260 | // Make sure the smiley set exists. |
254 | - if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) |
|
255 | - fatal_lang_error('smiley_set_not_found'); |
|
261 | + if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) { |
|
262 | + fatal_lang_error('smiley_set_not_found'); |
|
263 | + } |
|
256 | 264 | |
257 | 265 | // Make sure the path is not yet used by another smileyset. |
258 | - if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) |
|
259 | - fatal_lang_error('smiley_set_path_already_used'); |
|
266 | + if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) { |
|
267 | + fatal_lang_error('smiley_set_path_already_used'); |
|
268 | + } |
|
260 | 269 | |
261 | 270 | $set_paths[$_POST['set']] = $_POST['smiley_sets_path']; |
262 | 271 | $set_exts[$_POST['set']] = $_POST['smiley_sets_ext']; |
@@ -270,8 +279,9 @@ discard block |
||
270 | 279 | } |
271 | 280 | |
272 | 281 | // The user might have checked to also import smileys. |
273 | - if (!empty($_POST['smiley_sets_import'])) |
|
274 | - ImportSmileys($_POST['smiley_sets_path']); |
|
282 | + if (!empty($_POST['smiley_sets_import'])) { |
|
283 | + ImportSmileys($_POST['smiley_sets_path']); |
|
284 | + } |
|
275 | 285 | } |
276 | 286 | cache_put_data('parsing_smileys', null, 480); |
277 | 287 | cache_put_data('posting_smileys', null, 480); |
@@ -281,14 +291,15 @@ discard block |
||
281 | 291 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
282 | 292 | $set_exts = explode(",", $modSettings['smiley_sets_exts']); |
283 | 293 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
284 | - foreach ($context['smiley_sets'] as $i => $set) |
|
285 | - $context['smiley_sets'][$i] = array( |
|
294 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
295 | + $context['smiley_sets'][$i] = array( |
|
286 | 296 | 'id' => $i, |
287 | 297 | 'path' => $smcFunc['htmlspecialchars']($set), |
288 | 298 | 'ext' => $smcFunc['htmlspecialchars']($set_exts[$i]), |
289 | 299 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
290 | 300 | 'selected' => $set == $modSettings['smiley_sets_default'] |
291 | 301 | ); |
302 | + } |
|
292 | 303 | |
293 | 304 | // Importing any smileys from an existing set? |
294 | 305 | if ($context['sub_action'] == 'import') |
@@ -299,8 +310,9 @@ discard block |
||
299 | 310 | $_GET['set'] = (int) $_GET['set']; |
300 | 311 | |
301 | 312 | // Sanity check - then import. |
302 | - if (isset($context['smiley_sets'][$_GET['set']])) |
|
303 | - ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path'])); |
|
313 | + if (isset($context['smiley_sets'][$_GET['set']])) { |
|
314 | + ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path'])); |
|
315 | + } |
|
304 | 316 | |
305 | 317 | // Force the process to continue. |
306 | 318 | $context['sub_action'] = 'modifyset'; |
@@ -310,8 +322,8 @@ discard block |
||
310 | 322 | if ($context['sub_action'] == 'modifyset') |
311 | 323 | { |
312 | 324 | $_GET['set'] = !isset($_GET['set']) ? -1 : (int) $_GET['set']; |
313 | - if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) |
|
314 | - $context['current_set'] = array( |
|
325 | + if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) { |
|
326 | + $context['current_set'] = array( |
|
315 | 327 | 'id' => '-1', |
316 | 328 | 'path' => '', |
317 | 329 | 'ext' => '', |
@@ -319,7 +331,7 @@ discard block |
||
319 | 331 | 'selected' => false, |
320 | 332 | 'is_new' => true, |
321 | 333 | ); |
322 | - else |
|
334 | + } else |
|
323 | 335 | { |
324 | 336 | $context['current_set'] = &$context['smiley_sets'][$_GET['set']]; |
325 | 337 | $context['current_set']['is_new'] = false; |
@@ -333,13 +345,15 @@ discard block |
||
333 | 345 | { |
334 | 346 | // strip extension before comparison |
335 | 347 | $filename = pathinfo($entry, PATHINFO_FILENAME); |
336 | - if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png', '.svg'))) |
|
337 | - $smileys[strtolower($filename)] = $filename; |
|
348 | + if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png', '.svg'))) { |
|
349 | + $smileys[strtolower($filename)] = $filename; |
|
350 | + } |
|
338 | 351 | } |
339 | 352 | $dir->close(); |
340 | 353 | |
341 | - if (empty($smileys)) |
|
342 | - fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name'])); |
|
354 | + if (empty($smileys)) { |
|
355 | + fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name'])); |
|
356 | + } |
|
343 | 357 | |
344 | 358 | // Exclude the smileys that are already in the database. |
345 | 359 | $request = $smcFunc['db_query']('', ' |
@@ -350,9 +364,10 @@ discard block |
||
350 | 364 | 'smiley_list' => $smileys, |
351 | 365 | ) |
352 | 366 | ); |
353 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
354 | - if (isset($smileys[strtolower($row['filename'])])) |
|
367 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
368 | + if (isset($smileys[strtolower($row['filename'])])) |
|
355 | 369 | unset($smileys[strtolower($row['filename'])]); |
370 | + } |
|
356 | 371 | $smcFunc['db_free_result']($request); |
357 | 372 | |
358 | 373 | $context['current_set']['can_import'] = count($smileys); |
@@ -367,13 +382,14 @@ discard block |
||
367 | 382 | $dir = dir($modSettings['smileys_dir']); |
368 | 383 | while ($entry = $dir->read()) |
369 | 384 | { |
370 | - if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) |
|
371 | - $context['smiley_set_dirs'][] = array( |
|
385 | + if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) { |
|
386 | + $context['smiley_set_dirs'][] = array( |
|
372 | 387 | 'id' => $entry, |
373 | 388 | 'path' => $modSettings['smileys_dir'] . '/' . $entry, |
374 | 389 | 'selectable' => $entry == $context['current_set']['path'] || !in_array($entry, explode(',', $modSettings['smiley_sets_known'])), |
375 | 390 | 'current' => $entry == $context['current_set']['path'], |
376 | 391 | ); |
392 | + } |
|
377 | 393 | } |
378 | 394 | $dir->close(); |
379 | 395 | } |
@@ -383,8 +399,9 @@ discard block |
||
383 | 399 | createToken('admin-mss', 'request'); |
384 | 400 | |
385 | 401 | // In case we need to import smileys, we need to add the token in now. |
386 | - if (isset($context['current_set']['import_url'])) |
|
387 | - $context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token']; |
|
402 | + if (isset($context['current_set']['import_url'])) { |
|
403 | + $context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token']; |
|
404 | + } |
|
388 | 405 | |
389 | 406 | $listOptions = array( |
390 | 407 | 'id' => 'smiley_set_list', |
@@ -537,24 +554,26 @@ discard block |
||
537 | 554 | $cols['ext'][] = $set_exts[$i]; |
538 | 555 | } |
539 | 556 | $sort_flag = strpos($sort, 'DESC') === false ? SORT_ASC : SORT_DESC; |
540 | - if (substr($sort, 0, 4) === 'name') |
|
541 | - array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id'], $cols['ext']); |
|
542 | - elseif (substr($sort, 0, 3) === 'ext') |
|
543 | - array_multisort($cols['ext'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id'], $cols['path']); |
|
544 | - elseif (substr($sort, 0, 4) === 'path') |
|
545 | - array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id'], $cols['ext']); |
|
546 | - else |
|
547 | - array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id'], $cols['ext']); |
|
557 | + if (substr($sort, 0, 4) === 'name') { |
|
558 | + array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id'], $cols['ext']); |
|
559 | + } elseif (substr($sort, 0, 3) === 'ext') { |
|
560 | + array_multisort($cols['ext'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id'], $cols['path']); |
|
561 | + } elseif (substr($sort, 0, 4) === 'path') { |
|
562 | + array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id'], $cols['ext']); |
|
563 | + } else { |
|
564 | + array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id'], $cols['ext']); |
|
565 | + } |
|
548 | 566 | |
549 | 567 | $smiley_sets = array(); |
550 | - foreach ($cols['id'] as $i => $id) |
|
551 | - $smiley_sets[] = array( |
|
568 | + foreach ($cols['id'] as $i => $id) { |
|
569 | + $smiley_sets[] = array( |
|
552 | 570 | 'id' => $id, |
553 | 571 | 'path' => $cols['path'][$i], |
554 | 572 | 'name' => $cols['name'][$i], |
555 | 573 | 'ext' => $cols['ext'][$i], |
556 | 574 | 'selected' => $cols['path'][$i] == $modSettings['smiley_sets_default'] |
557 | 575 | ); |
576 | + } |
|
558 | 577 | |
559 | 578 | return $smiley_sets; |
560 | 579 | } |
@@ -584,14 +603,15 @@ discard block |
||
584 | 603 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
585 | 604 | $set_exts = explode(',', $modSettings['smiley_sets_exts']); |
586 | 605 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
587 | - foreach ($context['smiley_sets'] as $i => $set) |
|
588 | - $context['smiley_sets'][$i] = array( |
|
606 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
607 | + $context['smiley_sets'][$i] = array( |
|
589 | 608 | 'id' => $i, |
590 | 609 | 'path' => $smcFunc['htmlspecialchars']($set), |
591 | 610 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
592 | 611 | 'ext' => $smcFunc['htmlspecialchars']($set_exts[$i]), |
593 | 612 | 'selected' => $set == $modSettings['smiley_sets_default'] |
594 | 613 | ); |
614 | + } |
|
595 | 615 | |
596 | 616 | // Submitting a form? |
597 | 617 | if (isset($_POST[$context['session_var']], $_POST['smiley_code'])) |
@@ -607,8 +627,9 @@ discard block |
||
607 | 627 | $_POST['smiley_filename'] = htmltrim__recursive($_POST['smiley_filename']); |
608 | 628 | |
609 | 629 | // Make sure some code was entered. |
610 | - if (empty($_POST['smiley_code'])) |
|
611 | - fatal_lang_error('smiley_has_no_code'); |
|
630 | + if (empty($_POST['smiley_code'])) { |
|
631 | + fatal_lang_error('smiley_has_no_code'); |
|
632 | + } |
|
612 | 633 | |
613 | 634 | // Check whether the new code has duplicates. It should be unique. |
614 | 635 | $request = $smcFunc['db_query']('', ' |
@@ -620,8 +641,9 @@ discard block |
||
620 | 641 | 'smiley_code' => $_POST['smiley_code'], |
621 | 642 | ) |
622 | 643 | ); |
623 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
624 | - fatal_lang_error('smiley_not_unique'); |
|
644 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
645 | + fatal_lang_error('smiley_not_unique'); |
|
646 | + } |
|
625 | 647 | $smcFunc['db_free_result']($request); |
626 | 648 | |
627 | 649 | // If we are uploading - check all the smiley sets are writable! |
@@ -630,38 +652,44 @@ discard block |
||
630 | 652 | $writeErrors = array(); |
631 | 653 | foreach ($context['smiley_sets'] as $set) |
632 | 654 | { |
633 | - if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) |
|
634 | - $writeErrors[] = $set['path']; |
|
655 | + if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) { |
|
656 | + $writeErrors[] = $set['path']; |
|
657 | + } |
|
658 | + } |
|
659 | + if (!empty($writeErrors)) { |
|
660 | + fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors))); |
|
635 | 661 | } |
636 | - if (!empty($writeErrors)) |
|
637 | - fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors))); |
|
638 | 662 | } |
639 | 663 | |
640 | 664 | // Uploading just one smiley for all of them? |
641 | 665 | if (isset($_POST['sameall']) && isset($_FILES['uploadSmiley']['name']) && $_FILES['uploadSmiley']['name'] != '') |
642 | 666 | { |
643 | - if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) |
|
644 | - fatal_lang_error('smileys_upload_error'); |
|
667 | + if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) { |
|
668 | + fatal_lang_error('smileys_upload_error'); |
|
669 | + } |
|
645 | 670 | |
646 | 671 | // Sorry, no spaces, dots, or anything else but letters allowed. |
647 | 672 | $_FILES['uploadSmiley']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['uploadSmiley']['name']); |
648 | 673 | |
649 | 674 | // We only allow image files - it's THAT simple - no messing around here... |
650 | - if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) |
|
651 | - fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
675 | + if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) { |
|
676 | + fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
677 | + } |
|
652 | 678 | |
653 | 679 | // We only need the filename... |
654 | 680 | $destName = basename($_FILES['uploadSmiley']['name']); |
655 | 681 | |
656 | 682 | // Make sure they aren't trying to upload a nasty file - for their own good here! |
657 | - if (in_array(strtolower($destName), $disabledFiles)) |
|
658 | - fatal_lang_error('smileys_upload_error_illegal'); |
|
683 | + if (in_array(strtolower($destName), $disabledFiles)) { |
|
684 | + fatal_lang_error('smileys_upload_error_illegal'); |
|
685 | + } |
|
659 | 686 | |
660 | 687 | // Check if the file already exists... and if not move it to EVERY smiley set directory. |
661 | 688 | $i = 0; |
662 | 689 | // Keep going until we find a set the file doesn't exist in. (or maybe it exists in all of them?) |
663 | - while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) |
|
664 | - $i++; |
|
690 | + while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) { |
|
691 | + $i++; |
|
692 | + } |
|
665 | 693 | |
666 | 694 | // Okay, we're going to put the smiley right here, since it's not there yet! |
667 | 695 | if (isset($context['smiley_sets'][$i]['path'])) |
@@ -676,8 +704,9 @@ discard block |
||
676 | 704 | $currentPath = $context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName; |
677 | 705 | |
678 | 706 | // The file is already there! Don't overwrite it! |
679 | - if (file_exists($currentPath)) |
|
680 | - continue; |
|
707 | + if (file_exists($currentPath)) { |
|
708 | + continue; |
|
709 | + } |
|
681 | 710 | |
682 | 711 | // Okay, so copy the first one we made to here. |
683 | 712 | copy($smileyLocation, $currentPath); |
@@ -694,13 +723,15 @@ discard block |
||
694 | 723 | $newName = ''; |
695 | 724 | foreach ($_FILES as $name => $data) |
696 | 725 | { |
697 | - if ($_FILES[$name]['name'] == '') |
|
698 | - fatal_lang_error('smileys_upload_error_blank'); |
|
726 | + if ($_FILES[$name]['name'] == '') { |
|
727 | + fatal_lang_error('smileys_upload_error_blank'); |
|
728 | + } |
|
699 | 729 | |
700 | - if (empty($newName)) |
|
701 | - $newName = basename($_FILES[$name]['name']); |
|
702 | - elseif (basename($_FILES[$name]['name']) != $newName) |
|
703 | - fatal_lang_error('smileys_upload_error_name'); |
|
730 | + if (empty($newName)) { |
|
731 | + $newName = basename($_FILES[$name]['name']); |
|
732 | + } elseif (basename($_FILES[$name]['name']) != $newName) { |
|
733 | + fatal_lang_error('smileys_upload_error_name'); |
|
734 | + } |
|
704 | 735 | } |
705 | 736 | |
706 | 737 | foreach ($context['smiley_sets'] as $i => $set) |
@@ -708,31 +739,36 @@ discard block |
||
708 | 739 | $set['name'] = un_htmlspecialchars($set['name']); |
709 | 740 | $set['path'] = un_htmlspecialchars($set['path']); |
710 | 741 | |
711 | - if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') |
|
712 | - continue; |
|
742 | + if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') { |
|
743 | + continue; |
|
744 | + } |
|
713 | 745 | |
714 | 746 | // Got one... |
715 | - if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) |
|
716 | - fatal_lang_error('smileys_upload_error'); |
|
747 | + if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) { |
|
748 | + fatal_lang_error('smileys_upload_error'); |
|
749 | + } |
|
717 | 750 | |
718 | 751 | // Sorry, no spaces, dots, or anything else but letters allowed. |
719 | 752 | $_FILES['individual_' . $set['name']]['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['individual_' . $set['name']]['name']); |
720 | 753 | |
721 | 754 | // We only allow image files - it's THAT simple - no messing around here... |
722 | - if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) |
|
723 | - fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
755 | + if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) { |
|
756 | + fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
757 | + } |
|
724 | 758 | |
725 | 759 | // We only need the filename... |
726 | 760 | $destName = basename($_FILES['individual_' . $set['name']]['name']); |
727 | 761 | |
728 | 762 | // Make sure they aren't trying to upload a nasty file - for their own good here! |
729 | - if (in_array(strtolower($destName), $disabledFiles)) |
|
730 | - fatal_lang_error('smileys_upload_error_illegal'); |
|
763 | + if (in_array(strtolower($destName), $disabledFiles)) { |
|
764 | + fatal_lang_error('smileys_upload_error_illegal'); |
|
765 | + } |
|
731 | 766 | |
732 | 767 | // If the file exists - ignore it. |
733 | 768 | $smileyLocation = $context['smileys_dir'] . '/' . $set['path'] . '/' . $destName; |
734 | - if (file_exists($smileyLocation)) |
|
735 | - continue; |
|
769 | + if (file_exists($smileyLocation)) { |
|
770 | + continue; |
|
771 | + } |
|
736 | 772 | |
737 | 773 | // Finally - move the image! |
738 | 774 | move_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name'], $smileyLocation); |
@@ -744,8 +780,9 @@ discard block |
||
744 | 780 | } |
745 | 781 | |
746 | 782 | // Also make sure a filename was given. |
747 | - if (empty($_POST['smiley_filename'])) |
|
748 | - fatal_lang_error('smiley_has_no_filename'); |
|
783 | + if (empty($_POST['smiley_filename'])) { |
|
784 | + fatal_lang_error('smiley_has_no_filename'); |
|
785 | + } |
|
749 | 786 | |
750 | 787 | // Find the position on the right. |
751 | 788 | $smiley_order = '0'; |
@@ -764,8 +801,9 @@ discard block |
||
764 | 801 | list ($smiley_order) = $smcFunc['db_fetch_row']($request); |
765 | 802 | $smcFunc['db_free_result']($request); |
766 | 803 | |
767 | - if (empty($smiley_order)) |
|
768 | - $smiley_order = '0'; |
|
804 | + if (empty($smiley_order)) { |
|
805 | + $smiley_order = '0'; |
|
806 | + } |
|
769 | 807 | } |
770 | 808 | $smcFunc['db_insert']('', |
771 | 809 | '{db_prefix}smileys', |
@@ -793,19 +831,21 @@ discard block |
||
793 | 831 | { |
794 | 832 | foreach ($context['smiley_sets'] as $smiley_set) |
795 | 833 | { |
796 | - if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) |
|
797 | - continue; |
|
834 | + if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) { |
|
835 | + continue; |
|
836 | + } |
|
798 | 837 | |
799 | 838 | $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])); |
800 | 839 | while ($entry = $dir->read()) |
801 | 840 | { |
802 | 841 | // Strip extension |
803 | 842 | $filename = pathinfo($entry, PATHINFO_FILENAME); |
804 | - if (!in_array($filename, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png', '.svg'))) |
|
805 | - $context['filenames'][strtolower($filename)] = array( |
|
843 | + if (!in_array($filename, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png', '.svg'))) { |
|
844 | + $context['filenames'][strtolower($filename)] = array( |
|
806 | 845 | 'id' => $smcFunc['htmlspecialchars']($filename), |
807 | 846 | 'selected' => false, |
808 | 847 | ); |
848 | + } |
|
809 | 849 | } |
810 | 850 | $dir->close(); |
811 | 851 | } |
@@ -843,17 +883,19 @@ discard block |
||
843 | 883 | // Changing the selected smileys? |
844 | 884 | if (isset($_POST['smiley_action']) && !empty($_POST['checked_smileys'])) |
845 | 885 | { |
846 | - foreach ($_POST['checked_smileys'] as $id => $smiley_id) |
|
847 | - $_POST['checked_smileys'][$id] = (int) $smiley_id; |
|
886 | + foreach ($_POST['checked_smileys'] as $id => $smiley_id) { |
|
887 | + $_POST['checked_smileys'][$id] = (int) $smiley_id; |
|
888 | + } |
|
848 | 889 | |
849 | - if ($_POST['smiley_action'] == 'delete') |
|
850 | - $smcFunc['db_query']('', ' |
|
890 | + if ($_POST['smiley_action'] == 'delete') { |
|
891 | + $smcFunc['db_query']('', ' |
|
851 | 892 | DELETE FROM {db_prefix}smileys |
852 | 893 | WHERE id_smiley IN ({array_int:checked_smileys})', |
853 | 894 | array( |
854 | 895 | 'checked_smileys' => $_POST['checked_smileys'], |
855 | 896 | ) |
856 | 897 | ); |
898 | + } |
|
857 | 899 | // Changing the status of the smiley? |
858 | 900 | else |
859 | 901 | { |
@@ -863,8 +905,8 @@ discard block |
||
863 | 905 | 'hidden' => 1, |
864 | 906 | 'popup' => 2 |
865 | 907 | ); |
866 | - if (isset($displayTypes[$_POST['smiley_action']])) |
|
867 | - $smcFunc['db_query']('', ' |
|
908 | + if (isset($displayTypes[$_POST['smiley_action']])) { |
|
909 | + $smcFunc['db_query']('', ' |
|
868 | 910 | UPDATE {db_prefix}smileys |
869 | 911 | SET hidden = {int:display_type} |
870 | 912 | WHERE id_smiley IN ({array_int:checked_smileys})', |
@@ -873,6 +915,7 @@ discard block |
||
873 | 915 | 'display_type' => $displayTypes[$_POST['smiley_action']], |
874 | 916 | ) |
875 | 917 | ); |
918 | + } |
|
876 | 919 | } |
877 | 920 | } |
878 | 921 | // Create/modify a smiley. |
@@ -898,12 +941,14 @@ discard block |
||
898 | 941 | $_POST['smiley_location'] = empty($_POST['smiley_location']) || $_POST['smiley_location'] > 2 || $_POST['smiley_location'] < 0 ? 0 : (int) $_POST['smiley_location']; |
899 | 942 | |
900 | 943 | // Make sure some code was entered. |
901 | - if (empty($_POST['smiley_code'])) |
|
902 | - fatal_lang_error('smiley_has_no_code'); |
|
944 | + if (empty($_POST['smiley_code'])) { |
|
945 | + fatal_lang_error('smiley_has_no_code'); |
|
946 | + } |
|
903 | 947 | |
904 | 948 | // Also make sure a filename was given. |
905 | - if (empty($_POST['smiley_filename'])) |
|
906 | - fatal_lang_error('smiley_has_no_filename'); |
|
949 | + if (empty($_POST['smiley_filename'])) { |
|
950 | + fatal_lang_error('smiley_has_no_filename'); |
|
951 | + } |
|
907 | 952 | |
908 | 953 | // Check whether the new code has duplicates. It should be unique. |
909 | 954 | $request = $smcFunc['db_query']('', ' |
@@ -917,8 +962,9 @@ discard block |
||
917 | 962 | 'smiley_code' => $_POST['smiley_code'], |
918 | 963 | ) |
919 | 964 | ); |
920 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
921 | - fatal_lang_error('smiley_not_unique'); |
|
965 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
966 | + fatal_lang_error('smiley_not_unique'); |
|
967 | + } |
|
922 | 968 | $smcFunc['db_free_result']($request); |
923 | 969 | |
924 | 970 | $smcFunc['db_query']('', ' |
@@ -948,14 +994,15 @@ discard block |
||
948 | 994 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
949 | 995 | $set_exts = explode(',', $modSettings['smiley_sets_exts']); |
950 | 996 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
951 | - foreach ($context['smiley_sets'] as $i => $set) |
|
952 | - $context['smiley_sets'][$i] = array( |
|
997 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
998 | + $context['smiley_sets'][$i] = array( |
|
953 | 999 | 'id' => $i, |
954 | 1000 | 'path' => $smcFunc['htmlspecialchars']($set), |
955 | 1001 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
956 | 1002 | 'ext' => $smcFunc['htmlspecialchars']($set_exts[$i]), |
957 | 1003 | 'selected' => $set == $modSettings['smiley_sets_default'] |
958 | 1004 | ); |
1005 | + } |
|
959 | 1006 | |
960 | 1007 | // Prepare overview of all (custom) smileys. |
961 | 1008 | if ($context['sub_action'] == 'editsmileys') |
@@ -971,9 +1018,10 @@ discard block |
||
971 | 1018 | // Create a list of options for selecting smiley sets. |
972 | 1019 | $smileyset_option_list = ' |
973 | 1020 | <select name="set" onchange="changeSet(this.options[this.selectedIndex].value);">'; |
974 | - foreach ($context['smiley_sets'] as $smiley_set) |
|
975 | - $smileyset_option_list .= ' |
|
1021 | + foreach ($context['smiley_sets'] as $smiley_set) { |
|
1022 | + $smileyset_option_list .= ' |
|
976 | 1023 | <option value="' . $smiley_set['path'] . '"' . ($modSettings['smiley_sets_default'] == $smiley_set['path'] ? ' selected' : '') . '>' . $smiley_set['name'] . '</option>'; |
1024 | + } |
|
977 | 1025 | $smileyset_option_list .= ' |
978 | 1026 | </select>'; |
979 | 1027 | |
@@ -1035,12 +1083,13 @@ discard block |
||
1035 | 1083 | 'data' => array( |
1036 | 1084 | 'function' => function ($rowData) use ($txt) |
1037 | 1085 | { |
1038 | - if (empty($rowData['hidden'])) |
|
1039 | - return $txt['smileys_location_form']; |
|
1040 | - elseif ($rowData['hidden'] == 1) |
|
1041 | - return $txt['smileys_location_hidden']; |
|
1042 | - else |
|
1043 | - return $txt['smileys_location_popup']; |
|
1086 | + if (empty($rowData['hidden'])) { |
|
1087 | + return $txt['smileys_location_form']; |
|
1088 | + } elseif ($rowData['hidden'] == 1) { |
|
1089 | + return $txt['smileys_location_hidden']; |
|
1090 | + } else { |
|
1091 | + return $txt['smileys_location_popup']; |
|
1092 | + } |
|
1044 | 1093 | }, |
1045 | 1094 | ), |
1046 | 1095 | 'sort' => array( |
@@ -1055,19 +1104,22 @@ discard block |
||
1055 | 1104 | 'data' => array( |
1056 | 1105 | 'function' => function ($rowData) use ($context, $txt, $modSettings, $smcFunc) |
1057 | 1106 | { |
1058 | - if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) |
|
1059 | - return $smcFunc['htmlspecialchars']($rowData['description']); |
|
1107 | + if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) { |
|
1108 | + return $smcFunc['htmlspecialchars']($rowData['description']); |
|
1109 | + } |
|
1060 | 1110 | |
1061 | 1111 | // Check if there are smileys missing in some sets. |
1062 | 1112 | $missing_sets = array(); |
1063 | - foreach ($context['smiley_sets'] as $smiley_set) |
|
1064 | - if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename']))) |
|
1113 | + foreach ($context['smiley_sets'] as $smiley_set) { |
|
1114 | + if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename']))) |
|
1065 | 1115 | $missing_sets[] = $smiley_set['path']; |
1116 | + } |
|
1066 | 1117 | |
1067 | 1118 | $description = $smcFunc['htmlspecialchars']($rowData['description']); |
1068 | 1119 | |
1069 | - if (!empty($missing_sets)) |
|
1070 | - $description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets)); |
|
1120 | + if (!empty($missing_sets)) { |
|
1121 | + $description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets)); |
|
1122 | + } |
|
1071 | 1123 | |
1072 | 1124 | return $description; |
1073 | 1125 | }, |
@@ -1186,14 +1238,15 @@ discard block |
||
1186 | 1238 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
1187 | 1239 | $set_exts = explode(',', $modSettings['smiley_sets_exts']); |
1188 | 1240 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
1189 | - foreach ($context['smiley_sets'] as $i => $set) |
|
1190 | - $context['smiley_sets'][$i] = array( |
|
1241 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
1242 | + $context['smiley_sets'][$i] = array( |
|
1191 | 1243 | 'id' => $i, |
1192 | 1244 | 'path' => $smcFunc['htmlspecialchars']($set), |
1193 | 1245 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
1194 | 1246 | 'ext' => $smcFunc['htmlspecialchars']($set_exts[$i]), |
1195 | 1247 | 'selected' => $set == $modSettings['smiley_sets_default'] |
1196 | 1248 | ); |
1249 | + } |
|
1197 | 1250 | |
1198 | 1251 | $context['selected_set'] = $modSettings['smiley_sets_default']; |
1199 | 1252 | |
@@ -1203,19 +1256,21 @@ discard block |
||
1203 | 1256 | { |
1204 | 1257 | foreach ($context['smiley_sets'] as $smiley_set) |
1205 | 1258 | { |
1206 | - if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) |
|
1207 | - continue; |
|
1259 | + if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) { |
|
1260 | + continue; |
|
1261 | + } |
|
1208 | 1262 | |
1209 | 1263 | $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])); |
1210 | 1264 | while ($entry = $dir->read()) |
1211 | 1265 | { |
1212 | 1266 | // Strip extension |
1213 | 1267 | $filename = pathinfo($entry, PATHINFO_FILENAME); |
1214 | - if (!in_array($filename, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png', '.svg'))) |
|
1215 | - $context['filenames'][strtolower($filename)] = array( |
|
1268 | + if (!in_array($filename, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png', '.svg'))) { |
|
1269 | + $context['filenames'][strtolower($filename)] = array( |
|
1216 | 1270 | 'id' => $smcFunc['htmlspecialchars']($filename), |
1217 | 1271 | 'selected' => false, |
1218 | 1272 | ); |
1273 | + } |
|
1219 | 1274 | } |
1220 | 1275 | $dir->close(); |
1221 | 1276 | } |
@@ -1230,8 +1285,9 @@ discard block |
||
1230 | 1285 | 'current_smiley' => (int) $_REQUEST['smiley'], |
1231 | 1286 | ) |
1232 | 1287 | ); |
1233 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1234 | - fatal_lang_error('smiley_not_found'); |
|
1288 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1289 | + fatal_lang_error('smiley_not_found'); |
|
1290 | + } |
|
1235 | 1291 | $context['current_smiley'] = $smcFunc['db_fetch_assoc']($request); |
1236 | 1292 | $smcFunc['db_free_result']($request); |
1237 | 1293 | |
@@ -1239,8 +1295,9 @@ discard block |
||
1239 | 1295 | $context['current_smiley']['filename'] = $smcFunc['htmlspecialchars']($context['current_smiley']['filename']); |
1240 | 1296 | $context['current_smiley']['description'] = $smcFunc['htmlspecialchars']($context['current_smiley']['description']); |
1241 | 1297 | |
1242 | - if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) |
|
1243 | - $context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true; |
|
1298 | + if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) { |
|
1299 | + $context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true; |
|
1300 | + } |
|
1244 | 1301 | } |
1245 | 1302 | } |
1246 | 1303 | |
@@ -1265,8 +1322,9 @@ discard block |
||
1265 | 1322 | ) |
1266 | 1323 | ); |
1267 | 1324 | $smileys = array(); |
1268 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1269 | - $smileys[] = $row; |
|
1325 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1326 | + $smileys[] = $row; |
|
1327 | + } |
|
1270 | 1328 | $smcFunc['db_free_result']($request); |
1271 | 1329 | |
1272 | 1330 | return $smileys; |
@@ -1306,8 +1364,9 @@ discard block |
||
1306 | 1364 | $_GET['location'] = empty($_GET['location']) || $_GET['location'] != 'popup' ? 0 : 2; |
1307 | 1365 | $_GET['source'] = empty($_GET['source']) ? 0 : (int) $_GET['source']; |
1308 | 1366 | |
1309 | - if (empty($_GET['source'])) |
|
1310 | - fatal_lang_error('smiley_not_found'); |
|
1367 | + if (empty($_GET['source'])) { |
|
1368 | + fatal_lang_error('smiley_not_found'); |
|
1369 | + } |
|
1311 | 1370 | |
1312 | 1371 | if (!empty($_GET['after'])) |
1313 | 1372 | { |
@@ -1323,12 +1382,12 @@ discard block |
||
1323 | 1382 | 'after_smiley' => $_GET['after'], |
1324 | 1383 | ) |
1325 | 1384 | ); |
1326 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1327 | - fatal_lang_error('smiley_not_found'); |
|
1385 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1386 | + fatal_lang_error('smiley_not_found'); |
|
1387 | + } |
|
1328 | 1388 | list ($smiley_row, $smiley_order, $smileyLocation) = $smcFunc['db_fetch_row']($request); |
1329 | 1389 | $smcFunc['db_free_result']($request); |
1330 | - } |
|
1331 | - else |
|
1390 | + } else |
|
1332 | 1391 | { |
1333 | 1392 | $smiley_row = (int) $_GET['row']; |
1334 | 1393 | $smiley_order = -1; |
@@ -1402,14 +1461,15 @@ discard block |
||
1402 | 1461 | $context['move_smiley'] = empty($_REQUEST['move']) ? 0 : (int) $_REQUEST['move']; |
1403 | 1462 | |
1404 | 1463 | // Make sure all rows are sequential. |
1405 | - foreach (array_keys($context['smileys']) as $location) |
|
1406 | - $context['smileys'][$location] = array( |
|
1464 | + foreach (array_keys($context['smileys']) as $location) { |
|
1465 | + $context['smileys'][$location] = array( |
|
1407 | 1466 | 'id' => $location, |
1408 | 1467 | 'title' => $location == 'postform' ? $txt['smileys_location_form'] : $txt['smileys_location_popup'], |
1409 | 1468 | 'description' => $location == 'postform' ? $txt['smileys_location_form_description'] : $txt['smileys_location_popup_description'], |
1410 | 1469 | 'last_row' => count($context['smileys'][$location]['rows']), |
1411 | 1470 | 'rows' => array_values($context['smileys'][$location]['rows']), |
1412 | 1471 | ); |
1472 | + } |
|
1413 | 1473 | |
1414 | 1474 | // Check & fix smileys that are not ordered properly in the database. |
1415 | 1475 | foreach (array_keys($context['smileys']) as $location) |
@@ -1434,8 +1494,8 @@ discard block |
||
1434 | 1494 | $context['smileys'][$location]['rows'][$id][0]['row'] = $id; |
1435 | 1495 | } |
1436 | 1496 | // Make sure the smiley order is always sequential. |
1437 | - foreach ($smiley_row as $order_id => $smiley) |
|
1438 | - if ($order_id != $smiley['order']) |
|
1497 | + foreach ($smiley_row as $order_id => $smiley) { |
|
1498 | + if ($order_id != $smiley['order']) |
|
1439 | 1499 | $smcFunc['db_query']('', ' |
1440 | 1500 | UPDATE {db_prefix}smileys |
1441 | 1501 | SET smiley_order = {int:new_order} |
@@ -1445,6 +1505,7 @@ discard block |
||
1445 | 1505 | 'current_smiley' => $smiley['id'], |
1446 | 1506 | ) |
1447 | 1507 | ); |
1508 | + } |
|
1448 | 1509 | } |
1449 | 1510 | } |
1450 | 1511 | |
@@ -1478,19 +1539,20 @@ discard block |
||
1478 | 1539 | |
1479 | 1540 | // Check that the smiley is from simplemachines.org, for now... maybe add mirroring later. |
1480 | 1541 | // @ TODO: Our current xml files serve http links. Allowing both for now until we serve https. |
1481 | - if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) |
|
1482 | - fatal_lang_error('not_on_simplemachines'); |
|
1542 | + if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) { |
|
1543 | + fatal_lang_error('not_on_simplemachines'); |
|
1544 | + } |
|
1483 | 1545 | |
1484 | 1546 | $destination = $packagesdir . '/' . $base_name; |
1485 | 1547 | |
1486 | - if (file_exists($destination)) |
|
1487 | - fatal_lang_error('package_upload_error_exists'); |
|
1548 | + if (file_exists($destination)) { |
|
1549 | + fatal_lang_error('package_upload_error_exists'); |
|
1550 | + } |
|
1488 | 1551 | |
1489 | 1552 | // Let's copy it to the Packages directory |
1490 | 1553 | file_put_contents($destination, fetch_web_data($_REQUEST['set_gz'])); |
1491 | 1554 | $testing = true; |
1492 | - } |
|
1493 | - elseif (isset($_REQUEST['package'])) |
|
1555 | + } elseif (isset($_REQUEST['package'])) |
|
1494 | 1556 | { |
1495 | 1557 | $base_name = basename($_REQUEST['package']); |
1496 | 1558 | $name = $smcFunc['htmlspecialchars'](strtok(basename($_REQUEST['package']), '.')); |
@@ -1499,12 +1561,14 @@ discard block |
||
1499 | 1561 | $destination = $packagesdir . '/' . basename($_REQUEST['package']); |
1500 | 1562 | } |
1501 | 1563 | |
1502 | - if (empty($destination) || !file_exists($destination)) |
|
1503 | - fatal_lang_error('package_no_file', false); |
|
1564 | + if (empty($destination) || !file_exists($destination)) { |
|
1565 | + fatal_lang_error('package_no_file', false); |
|
1566 | + } |
|
1504 | 1567 | |
1505 | 1568 | // Make sure temp directory exists and is empty. |
1506 | - if (file_exists($packagesdir . '/temp')) |
|
1507 | - deltree($packagesdir . '/temp', false); |
|
1569 | + if (file_exists($packagesdir . '/temp')) { |
|
1570 | + deltree($packagesdir . '/temp', false); |
|
1571 | + } |
|
1508 | 1572 | |
1509 | 1573 | if (!mktree($packagesdir . '/temp', 0755)) |
1510 | 1574 | { |
@@ -1516,31 +1580,37 @@ discard block |
||
1516 | 1580 | create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=smileys;sa=install;set_gz=' . $_REQUEST['set_gz'], 'crash_on_error' => true)); |
1517 | 1581 | |
1518 | 1582 | deltree($packagesdir . '/temp', false); |
1519 | - if (!mktree($packagesdir . '/temp', 0777)) |
|
1520 | - fatal_lang_error('package_cant_download', false); |
|
1583 | + if (!mktree($packagesdir . '/temp', 0777)) { |
|
1584 | + fatal_lang_error('package_cant_download', false); |
|
1585 | + } |
|
1521 | 1586 | } |
1522 | 1587 | } |
1523 | 1588 | |
1524 | 1589 | $extracted = read_tgz_file($destination, $packagesdir . '/temp'); |
1525 | - if (!$extracted) |
|
1526 | - fatal_lang_error('packageget_unable', false, array('https://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name)); |
|
1527 | - if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) |
|
1528 | - foreach ($extracted as $file) |
|
1590 | + if (!$extracted) { |
|
1591 | + fatal_lang_error('packageget_unable', false, array('https://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name)); |
|
1592 | + } |
|
1593 | + if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) { |
|
1594 | + foreach ($extracted as $file) |
|
1529 | 1595 | if (basename($file['filename']) == 'package-info.xml') |
1530 | 1596 | { |
1531 | 1597 | $base_path = dirname($file['filename']) . '/'; |
1598 | + } |
|
1532 | 1599 | break; |
1533 | 1600 | } |
1534 | 1601 | |
1535 | - if (!isset($base_path)) |
|
1536 | - $base_path = ''; |
|
1602 | + if (!isset($base_path)) { |
|
1603 | + $base_path = ''; |
|
1604 | + } |
|
1537 | 1605 | |
1538 | - if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) |
|
1539 | - fatal_lang_error('package_get_error_missing_xml', false); |
|
1606 | + if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) { |
|
1607 | + fatal_lang_error('package_get_error_missing_xml', false); |
|
1608 | + } |
|
1540 | 1609 | |
1541 | 1610 | $smileyInfo = getPackageInfo($context['filename']); |
1542 | - if (!is_array($smileyInfo)) |
|
1543 | - fatal_lang_error($smileyInfo); |
|
1611 | + if (!is_array($smileyInfo)) { |
|
1612 | + fatal_lang_error($smileyInfo); |
|
1613 | + } |
|
1544 | 1614 | |
1545 | 1615 | // See if it is installed? |
1546 | 1616 | $request = $smcFunc['db_query']('', ' |
@@ -1556,8 +1626,9 @@ discard block |
||
1556 | 1626 | ) |
1557 | 1627 | ); |
1558 | 1628 | |
1559 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
1560 | - fatal_lang_error('package_installed_warning1'); |
|
1629 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
1630 | + fatal_lang_error('package_installed_warning1'); |
|
1631 | + } |
|
1561 | 1632 | |
1562 | 1633 | // Everything is fine, now it's time to do something |
1563 | 1634 | $actions = parsePackageInfo($smileyInfo['xml'], true, 'install'); |
@@ -1572,23 +1643,23 @@ discard block |
||
1572 | 1643 | if ($action['type'] == 'readme' || $action['type'] == 'license') |
1573 | 1644 | { |
1574 | 1645 | $type = 'package_' . $action['type']; |
1575 | - if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) |
|
1576 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r")); |
|
1577 | - elseif (file_exists($action['filename'])) |
|
1578 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
1646 | + if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) { |
|
1647 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r")); |
|
1648 | + } elseif (file_exists($action['filename'])) { |
|
1649 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
1650 | + } |
|
1579 | 1651 | |
1580 | 1652 | if (!empty($action['parse_bbc'])) |
1581 | 1653 | { |
1582 | 1654 | require_once($sourcedir . '/Subs-Post.php'); |
1583 | 1655 | preparsecode($context[$type]); |
1584 | 1656 | $context[$type] = parse_bbc($context[$type]); |
1657 | + } else { |
|
1658 | + $context[$type] = nl2br($context[$type]); |
|
1585 | 1659 | } |
1586 | - else |
|
1587 | - $context[$type] = nl2br($context[$type]); |
|
1588 | 1660 | |
1589 | 1661 | continue; |
1590 | - } |
|
1591 | - elseif ($action['type'] == 'require-dir') |
|
1662 | + } elseif ($action['type'] == 'require-dir') |
|
1592 | 1663 | { |
1593 | 1664 | // Do this one... |
1594 | 1665 | $thisAction = array( |
@@ -1607,12 +1678,12 @@ discard block |
||
1607 | 1678 | ); |
1608 | 1679 | } |
1609 | 1680 | // @todo None given? |
1610 | - if (empty($thisAction['description'])) |
|
1611 | - $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
1681 | + if (empty($thisAction['description'])) { |
|
1682 | + $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
1683 | + } |
|
1612 | 1684 | |
1613 | 1685 | $context['actions'][] = $thisAction; |
1614 | - } |
|
1615 | - elseif ($action['type'] == 'credits') |
|
1686 | + } elseif ($action['type'] == 'credits') |
|
1616 | 1687 | { |
1617 | 1688 | // Time to build the billboard |
1618 | 1689 | $credits_tag = array( |
@@ -1672,12 +1743,14 @@ discard block |
||
1672 | 1743 | cache_put_data('posting_smileys', null, 480); |
1673 | 1744 | } |
1674 | 1745 | |
1675 | - if (file_exists($packagesdir . '/temp')) |
|
1676 | - deltree($packagesdir . '/temp'); |
|
1746 | + if (file_exists($packagesdir . '/temp')) { |
|
1747 | + deltree($packagesdir . '/temp'); |
|
1748 | + } |
|
1677 | 1749 | |
1678 | - if (!$testing) |
|
1679 | - redirectexit('action=admin;area=smileys'); |
|
1680 | -} |
|
1750 | + if (!$testing) { |
|
1751 | + redirectexit('action=admin;area=smileys'); |
|
1752 | + } |
|
1753 | + } |
|
1681 | 1754 | |
1682 | 1755 | /** |
1683 | 1756 | * A function to import new smileys from an existing directory into the database. |
@@ -1688,16 +1761,18 @@ discard block |
||
1688 | 1761 | { |
1689 | 1762 | global $modSettings, $smcFunc; |
1690 | 1763 | |
1691 | - if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) |
|
1692 | - fatal_lang_error('smiley_set_unable_to_import'); |
|
1764 | + if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) { |
|
1765 | + fatal_lang_error('smiley_set_unable_to_import'); |
|
1766 | + } |
|
1693 | 1767 | |
1694 | 1768 | $smileys = array(); |
1695 | 1769 | $dir = dir($modSettings['smileys_dir'] . '/' . $smileyPath); |
1696 | 1770 | while ($entry = $dir->read()) |
1697 | 1771 | { |
1698 | 1772 | $filename = pathinfo($entry, PATHINFO_FILENAME); |
1699 | - if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png', '.svg'))) |
|
1700 | - $smileys[strtolower($filename)] = $filename; |
|
1773 | + if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png', '.svg'))) { |
|
1774 | + $smileys[strtolower($filename)] = $filename; |
|
1775 | + } |
|
1701 | 1776 | } |
1702 | 1777 | $dir->close(); |
1703 | 1778 | |
@@ -1710,9 +1785,10 @@ discard block |
||
1710 | 1785 | 'smiley_list' => $smileys, |
1711 | 1786 | ) |
1712 | 1787 | ); |
1713 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1714 | - if (isset($smileys[strtolower($row['filename'])])) |
|
1788 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1789 | + if (isset($smileys[strtolower($row['filename'])])) |
|
1715 | 1790 | unset($smileys[strtolower($row['filename'])]); |
1791 | + } |
|
1716 | 1792 | $smcFunc['db_free_result']($request); |
1717 | 1793 | |
1718 | 1794 | $request = $smcFunc['db_query']('', ' |
@@ -1729,9 +1805,10 @@ discard block |
||
1729 | 1805 | $smcFunc['db_free_result']($request); |
1730 | 1806 | |
1731 | 1807 | $new_smileys = array(); |
1732 | - foreach ($smileys as $smiley) |
|
1733 | - if (strlen($smiley) <= 48) |
|
1808 | + foreach ($smileys as $smiley) { |
|
1809 | + if (strlen($smiley) <= 48) |
|
1734 | 1810 | $new_smileys[] = array(':' . strtok($smiley, '.') . ':', $smiley, strtok($smiley, '.'), 0, ++$smiley_order); |
1811 | + } |
|
1735 | 1812 | |
1736 | 1813 | if (!empty($new_smileys)) |
1737 | 1814 | { |
@@ -1796,8 +1873,9 @@ discard block |
||
1796 | 1873 | if (isset($_POST['delete']) && !empty($_POST['checked_icons'])) |
1797 | 1874 | { |
1798 | 1875 | $deleteIcons = array(); |
1799 | - foreach ($_POST['checked_icons'] as $icon) |
|
1800 | - $deleteIcons[] = (int) $icon; |
|
1876 | + foreach ($_POST['checked_icons'] as $icon) { |
|
1877 | + $deleteIcons[] = (int) $icon; |
|
1878 | + } |
|
1801 | 1879 | |
1802 | 1880 | // Do the actual delete! |
1803 | 1881 | $smcFunc['db_query']('', ' |
@@ -1814,35 +1892,41 @@ discard block |
||
1814 | 1892 | $_GET['icon'] = (int) $_GET['icon']; |
1815 | 1893 | |
1816 | 1894 | // Do some preperation with the data... like check the icon exists *somewhere* |
1817 | - if (strpos($_POST['icon_filename'], '.png') !== false) |
|
1818 | - $_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4); |
|
1819 | - if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) |
|
1820 | - fatal_lang_error('icon_not_found'); |
|
1895 | + if (strpos($_POST['icon_filename'], '.png') !== false) { |
|
1896 | + $_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4); |
|
1897 | + } |
|
1898 | + if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) { |
|
1899 | + fatal_lang_error('icon_not_found'); |
|
1900 | + } |
|
1821 | 1901 | // There is a 16 character limit on message icons... |
1822 | - elseif (strlen($_POST['icon_filename']) > 16) |
|
1823 | - fatal_lang_error('icon_name_too_long'); |
|
1824 | - elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) |
|
1825 | - fatal_lang_error('icon_after_itself'); |
|
1902 | + elseif (strlen($_POST['icon_filename']) > 16) { |
|
1903 | + fatal_lang_error('icon_name_too_long'); |
|
1904 | + } elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) { |
|
1905 | + fatal_lang_error('icon_after_itself'); |
|
1906 | + } |
|
1826 | 1907 | |
1827 | 1908 | // First do the sorting... if this is an edit reduce the order of everything after it by one ;) |
1828 | 1909 | if ($_GET['icon'] != 0) |
1829 | 1910 | { |
1830 | 1911 | $oldOrder = $context['icons'][$_GET['icon']]['true_order']; |
1831 | - foreach ($context['icons'] as $id => $data) |
|
1832 | - if ($data['true_order'] > $oldOrder) |
|
1912 | + foreach ($context['icons'] as $id => $data) { |
|
1913 | + if ($data['true_order'] > $oldOrder) |
|
1833 | 1914 | $context['icons'][$id]['true_order']--; |
1915 | + } |
|
1834 | 1916 | } |
1835 | 1917 | |
1836 | 1918 | // If there are no existing icons and this is a new one, set the id to 1 (mainly for non-mysql) |
1837 | - if (empty($_GET['icon']) && empty($context['icons'])) |
|
1838 | - $_GET['icon'] = 1; |
|
1919 | + if (empty($_GET['icon']) && empty($context['icons'])) { |
|
1920 | + $_GET['icon'] = 1; |
|
1921 | + } |
|
1839 | 1922 | |
1840 | 1923 | // Get the new order. |
1841 | 1924 | $newOrder = $_POST['icon_location'] == 0 ? 0 : $context['icons'][$_POST['icon_location']]['true_order'] + 1; |
1842 | 1925 | // Do the same, but with the one that used to be after this icon, done to avoid conflict. |
1843 | - foreach ($context['icons'] as $id => $data) |
|
1844 | - if ($data['true_order'] >= $newOrder) |
|
1926 | + foreach ($context['icons'] as $id => $data) { |
|
1927 | + if ($data['true_order'] >= $newOrder) |
|
1845 | 1928 | $context['icons'][$id]['true_order']++; |
1929 | + } |
|
1846 | 1930 | |
1847 | 1931 | // Finally set the current icon's position! |
1848 | 1932 | $context['icons'][$_GET['icon']]['true_order'] = $newOrder; |
@@ -1860,8 +1944,7 @@ discard block |
||
1860 | 1944 | if ($id != 0) |
1861 | 1945 | { |
1862 | 1946 | $iconInsert[] = array($id, $icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']); |
1863 | - } |
|
1864 | - else |
|
1947 | + } else |
|
1865 | 1948 | { |
1866 | 1949 | $iconInsert_new[] = array($icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']); |
1867 | 1950 | } |
@@ -1886,8 +1969,9 @@ discard block |
||
1886 | 1969 | } |
1887 | 1970 | |
1888 | 1971 | // Unless we're adding a new thing, we'll escape |
1889 | - if (!isset($_POST['add'])) |
|
1890 | - redirectexit('action=admin;area=smileys;sa=editicons'); |
|
1972 | + if (!isset($_POST['add'])) { |
|
1973 | + redirectexit('action=admin;area=smileys;sa=editicons'); |
|
1974 | + } |
|
1891 | 1975 | } |
1892 | 1976 | |
1893 | 1977 | $context[$context['admin_menu_name']]['current_subsection'] = 'editicons'; |
@@ -1997,8 +2081,9 @@ discard block |
||
1997 | 2081 | $context['new_icon'] = !isset($_GET['icon']); |
1998 | 2082 | |
1999 | 2083 | // Get the properties of the current icon from the icon list. |
2000 | - if (!$context['new_icon']) |
|
2001 | - $context['icon'] = $context['icons'][$_GET['icon']]; |
|
2084 | + if (!$context['new_icon']) { |
|
2085 | + $context['icon'] = $context['icons'][$_GET['icon']]; |
|
2086 | + } |
|
2002 | 2087 | |
2003 | 2088 | // Get a list of boards needed for assigning this icon to a specific board. |
2004 | 2089 | $boardListOptions = array( |
@@ -2032,8 +2117,9 @@ discard block |
||
2032 | 2117 | ); |
2033 | 2118 | |
2034 | 2119 | $message_icons = array(); |
2035 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2036 | - $message_icons[] = $row; |
|
2120 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2121 | + $message_icons[] = $row; |
|
2122 | + } |
|
2037 | 2123 | $smcFunc['db_free_result']($request); |
2038 | 2124 | |
2039 | 2125 | return $message_icons; |
@@ -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 | * The news dispatcher; doesn't do anything, just delegates. |
@@ -67,8 +68,9 @@ discard block |
||
67 | 68 | ); |
68 | 69 | |
69 | 70 | // Force the right area... |
70 | - if (substr($_REQUEST['sa'], 0, 7) == 'mailing') |
|
71 | - $context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers'; |
|
71 | + if (substr($_REQUEST['sa'], 0, 7) == 'mailing') { |
|
72 | + $context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers'; |
|
73 | + } |
|
72 | 74 | |
73 | 75 | call_helper($subActions[$_REQUEST['sa']][0]); |
74 | 76 | } |
@@ -99,9 +101,10 @@ discard block |
||
99 | 101 | $temp_news = explode("\n", $modSettings['news']); |
100 | 102 | |
101 | 103 | // Remove the items that were selected. |
102 | - foreach ($temp_news as $i => $news) |
|
103 | - if (in_array($i, $_POST['remove'])) |
|
104 | + foreach ($temp_news as $i => $news) { |
|
105 | + if (in_array($i, $_POST['remove'])) |
|
104 | 106 | unset($temp_news[$i]); |
107 | + } |
|
105 | 108 | |
106 | 109 | // Update the database. |
107 | 110 | updateSettings(array('news' => implode("\n", $temp_news))); |
@@ -117,9 +120,9 @@ discard block |
||
117 | 120 | |
118 | 121 | foreach ($_POST['news'] as $i => $news) |
119 | 122 | { |
120 | - if (trim($news) == '') |
|
121 | - unset($_POST['news'][$i]); |
|
122 | - else |
|
123 | + if (trim($news) == '') { |
|
124 | + unset($_POST['news'][$i]); |
|
125 | + } else |
|
123 | 126 | { |
124 | 127 | $_POST['news'][$i] = $smcFunc['htmlspecialchars']($_POST['news'][$i], ENT_QUOTES); |
125 | 128 | preparsecode($_POST['news'][$i]); |
@@ -155,12 +158,13 @@ discard block |
||
155 | 158 | 'data' => array( |
156 | 159 | 'function' => function($news) |
157 | 160 | { |
158 | - if (is_numeric($news['id'])) |
|
159 | - return ' |
|
161 | + if (is_numeric($news['id'])) { |
|
162 | + return ' |
|
160 | 163 | <textarea id="data_' . $news['id'] . '" rows="3" cols="50" name="news[]" class="padding block">' . $news['unparsed'] . '</textarea> |
161 | 164 | <div class="floatleft" id="preview_' . $news['id'] . '"></div>'; |
162 | - else |
|
163 | - return $news['unparsed']; |
|
165 | + } else { |
|
166 | + return $news['unparsed']; |
|
167 | + } |
|
164 | 168 | }, |
165 | 169 | 'class' => 'half_table', |
166 | 170 | ), |
@@ -186,10 +190,11 @@ discard block |
||
186 | 190 | 'data' => array( |
187 | 191 | 'function' => function($news) |
188 | 192 | { |
189 | - if (is_numeric($news['id'])) |
|
190 | - return '<input type="checkbox" name="remove[]" value="' . $news['id'] . '">'; |
|
191 | - else |
|
192 | - return ''; |
|
193 | + if (is_numeric($news['id'])) { |
|
194 | + return '<input type="checkbox" name="remove[]" value="' . $news['id'] . '">'; |
|
195 | + } else { |
|
196 | + return ''; |
|
197 | + } |
|
193 | 198 | }, |
194 | 199 | 'class' => 'centercol icon', |
195 | 200 | ), |
@@ -283,12 +288,13 @@ discard block |
||
283 | 288 | |
284 | 289 | $admin_current_news = array(); |
285 | 290 | // Ready the current news. |
286 | - foreach (explode("\n", $modSettings['news']) as $id => $line) |
|
287 | - $admin_current_news[$id] = array( |
|
291 | + foreach (explode("\n", $modSettings['news']) as $id => $line) { |
|
292 | + $admin_current_news[$id] = array( |
|
288 | 293 | 'id' => $id, |
289 | 294 | 'unparsed' => un_preparsecode($line), |
290 | 295 | 'parsed' => preg_replace('~<([/]?)form[^>]*?[>]*>~i', '<em class="smalltext"><$1form></em>', parse_bbc($line)), |
291 | 296 | ); |
297 | + } |
|
292 | 298 | |
293 | 299 | $admin_current_news['last'] = array( |
294 | 300 | 'id' => 'last', |
@@ -355,10 +361,11 @@ discard block |
||
355 | 361 | 'member_count' => 0, |
356 | 362 | ); |
357 | 363 | |
358 | - if ($row['min_posts'] == -1) |
|
359 | - $normalGroups[$row['id_group']] = $row['id_group']; |
|
360 | - else |
|
361 | - $postGroups[$row['id_group']] = $row['id_group']; |
|
364 | + if ($row['min_posts'] == -1) { |
|
365 | + $normalGroups[$row['id_group']] = $row['id_group']; |
|
366 | + } else { |
|
367 | + $postGroups[$row['id_group']] = $row['id_group']; |
|
368 | + } |
|
362 | 369 | } |
363 | 370 | $smcFunc['db_free_result']($request); |
364 | 371 | |
@@ -374,8 +381,9 @@ discard block |
||
374 | 381 | 'post_group_list' => $postGroups, |
375 | 382 | ) |
376 | 383 | ); |
377 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
378 | - $context['groups'][$row['id_group']]['member_count'] += $row['member_count']; |
|
384 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
385 | + $context['groups'][$row['id_group']]['member_count'] += $row['member_count']; |
|
386 | + } |
|
379 | 387 | $smcFunc['db_free_result']($query); |
380 | 388 | } |
381 | 389 | |
@@ -391,8 +399,9 @@ discard block |
||
391 | 399 | 'normal_group_list' => $normalGroups, |
392 | 400 | ) |
393 | 401 | ); |
394 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
395 | - $context['groups'][$row['id_group']]['member_count'] += $row['member_count']; |
|
402 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
403 | + $context['groups'][$row['id_group']]['member_count'] += $row['member_count']; |
|
404 | + } |
|
396 | 405 | $smcFunc['db_free_result']($query); |
397 | 406 | |
398 | 407 | // Also do those who have it as an additional membergroup - this ones more yucky... |
@@ -409,8 +418,9 @@ discard block |
||
409 | 418 | 'blank_string' => '', |
410 | 419 | ) |
411 | 420 | ); |
412 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
413 | - $context['groups'][$row['id_group']]['member_count'] += $row['member_count']; |
|
421 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
422 | + $context['groups'][$row['id_group']]['member_count'] += $row['member_count']; |
|
423 | + } |
|
414 | 424 | $smcFunc['db_free_result']($query); |
415 | 425 | } |
416 | 426 | |
@@ -461,10 +471,11 @@ discard block |
||
461 | 471 | { |
462 | 472 | $context[$key] = !empty($_REQUEST[$post]) ? $_REQUEST[$post] : ''; |
463 | 473 | |
464 | - if (empty($context[$key]) && empty($_REQUEST['xml'])) |
|
465 | - $context['post_error']['messages'][] = $txt['error_no_' . $post]; |
|
466 | - elseif (!empty($_REQUEST['xml'])) |
|
467 | - continue; |
|
474 | + if (empty($context[$key]) && empty($_REQUEST['xml'])) { |
|
475 | + $context['post_error']['messages'][] = $txt['error_no_' . $post]; |
|
476 | + } elseif (!empty($_REQUEST['xml'])) { |
|
477 | + continue; |
|
478 | + } |
|
468 | 479 | |
469 | 480 | preparsecode($context[$key]); |
470 | 481 | if ($html) |
@@ -543,10 +554,12 @@ discard block |
||
543 | 554 | |
544 | 555 | // Start by finding any members! |
545 | 556 | $toClean = array(); |
546 | - if (!empty($_POST['members'])) |
|
547 | - $toClean[] = 'members'; |
|
548 | - if (!empty($_POST['exclude_members'])) |
|
549 | - $toClean[] = 'exclude_members'; |
|
557 | + if (!empty($_POST['members'])) { |
|
558 | + $toClean[] = 'members'; |
|
559 | + } |
|
560 | + if (!empty($_POST['exclude_members'])) { |
|
561 | + $toClean[] = 'exclude_members'; |
|
562 | + } |
|
550 | 563 | if (!empty($toClean)) |
551 | 564 | { |
552 | 565 | require_once($sourcedir . '/Subs-Auth.php'); |
@@ -558,11 +571,13 @@ discard block |
||
558 | 571 | preg_match_all('~"([^"]+)"~', $_POST[$type], $matches); |
559 | 572 | $_POST[$type] = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST[$type])))); |
560 | 573 | |
561 | - foreach ($_POST[$type] as $index => $member) |
|
562 | - if (strlen(trim($member)) > 0) |
|
574 | + foreach ($_POST[$type] as $index => $member) { |
|
575 | + if (strlen(trim($member)) > 0) |
|
563 | 576 | $_POST[$type][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($member))); |
564 | - else |
|
565 | - unset($_POST[$type][$index]); |
|
577 | + } |
|
578 | + else { |
|
579 | + unset($_POST[$type][$index]); |
|
580 | + } |
|
566 | 581 | |
567 | 582 | // Find the members |
568 | 583 | $_POST[$type] = implode(',', array_keys(findMembers($_POST[$type]))); |
@@ -572,16 +587,18 @@ discard block |
||
572 | 587 | if (isset($_POST['member_list']) && is_array($_POST['member_list'])) |
573 | 588 | { |
574 | 589 | $members = array(); |
575 | - foreach ($_POST['member_list'] as $member_id) |
|
576 | - $members[] = (int) $member_id; |
|
590 | + foreach ($_POST['member_list'] as $member_id) { |
|
591 | + $members[] = (int) $member_id; |
|
592 | + } |
|
577 | 593 | $_POST['members'] = implode(',', $members); |
578 | 594 | } |
579 | 595 | |
580 | 596 | if (isset($_POST['exclude_member_list']) && is_array($_POST['exclude_member_list'])) |
581 | 597 | { |
582 | 598 | $members = array(); |
583 | - foreach ($_POST['exclude_member_list'] as $member_id) |
|
584 | - $members[] = (int) $member_id; |
|
599 | + foreach ($_POST['exclude_member_list'] as $member_id) { |
|
600 | + $members[] = (int) $member_id; |
|
601 | + } |
|
585 | 602 | $_POST['exclude_members'] = implode(',', $members); |
586 | 603 | } |
587 | 604 | |
@@ -605,8 +622,9 @@ discard block |
||
605 | 622 | 'current_time' => time(), |
606 | 623 | ) |
607 | 624 | ); |
608 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
609 | - $context['recipients']['exclude_members'][] = $row['id_member']; |
|
625 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
626 | + $context['recipients']['exclude_members'][] = $row['id_member']; |
|
627 | + } |
|
610 | 628 | $smcFunc['db_free_result']($request); |
611 | 629 | |
612 | 630 | $request = $smcFunc['db_query']('', ' |
@@ -641,8 +659,9 @@ discard block |
||
641 | 659 | WHERE email_address IN(' . implode(', ', $condition_array) . ')', |
642 | 660 | $condition_array_params |
643 | 661 | ); |
644 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
645 | - $context['recipients']['exclude_members'][] = $row['id_member']; |
|
662 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
663 | + $context['recipients']['exclude_members'][] = $row['id_member']; |
|
664 | + } |
|
646 | 665 | $smcFunc['db_free_result']($request); |
647 | 666 | } |
648 | 667 | |
@@ -660,10 +679,11 @@ discard block |
||
660 | 679 | ); |
661 | 680 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
662 | 681 | { |
663 | - if (in_array(3, $context['recipients'])) |
|
664 | - $context['recipients']['exclude_members'][] = $row['identifier']; |
|
665 | - else |
|
666 | - $context['recipients']['members'][] = $row['identifier']; |
|
682 | + if (in_array(3, $context['recipients'])) { |
|
683 | + $context['recipients']['exclude_members'][] = $row['identifier']; |
|
684 | + } else { |
|
685 | + $context['recipients']['members'][] = $row['identifier']; |
|
686 | + } |
|
667 | 687 | } |
668 | 688 | $smcFunc['db_free_result']($request); |
669 | 689 | } |
@@ -710,8 +730,9 @@ discard block |
||
710 | 730 | $num_at_once = 1000; |
711 | 731 | |
712 | 732 | // If by PM's I suggest we half the above number. |
713 | - if (!empty($_POST['send_pm'])) |
|
714 | - $num_at_once /= 2; |
|
733 | + if (!empty($_POST['send_pm'])) { |
|
734 | + $num_at_once /= 2; |
|
735 | + } |
|
715 | 736 | |
716 | 737 | checkSession(); |
717 | 738 | |
@@ -734,8 +755,7 @@ discard block |
||
734 | 755 | ); |
735 | 756 | list ($context['total_members']) = $smcFunc['db_fetch_row']($request); |
736 | 757 | $smcFunc['db_free_result']($request); |
737 | - } |
|
738 | - else |
|
758 | + } else |
|
739 | 759 | { |
740 | 760 | $context['total_members'] = (int) $_REQUEST['total_members']; |
741 | 761 | } |
@@ -753,32 +773,35 @@ discard block |
||
753 | 773 | if (!empty($_POST['exclude_members'])) |
754 | 774 | { |
755 | 775 | $members = explode(',', $_POST['exclude_members']); |
756 | - foreach ($members as $member) |
|
757 | - if ($member >= $context['start']) |
|
776 | + foreach ($members as $member) { |
|
777 | + if ($member >= $context['start']) |
|
758 | 778 | $context['recipients']['exclude_members'][] = (int) $member; |
779 | + } |
|
759 | 780 | } |
760 | 781 | |
761 | 782 | // What about members we *must* do? |
762 | 783 | if (!empty($_POST['members'])) |
763 | 784 | { |
764 | 785 | $members = explode(',', $_POST['members']); |
765 | - foreach ($members as $member) |
|
766 | - if ($member >= $context['start']) |
|
786 | + foreach ($members as $member) { |
|
787 | + if ($member >= $context['start']) |
|
767 | 788 | $context['recipients']['members'][] = (int) $member; |
789 | + } |
|
768 | 790 | } |
769 | 791 | // Cleaning groups is simple - although deal with both checkbox and commas. |
770 | 792 | if (isset($_POST['groups'])) |
771 | 793 | { |
772 | 794 | if (is_array($_POST['groups'])) |
773 | 795 | { |
774 | - foreach ($_POST['groups'] as $group => $dummy) |
|
775 | - $context['recipients']['groups'][] = (int) $group; |
|
776 | - } |
|
777 | - else |
|
796 | + foreach ($_POST['groups'] as $group => $dummy) { |
|
797 | + $context['recipients']['groups'][] = (int) $group; |
|
798 | + } |
|
799 | + } else |
|
778 | 800 | { |
779 | 801 | $groups = explode(',', $_POST['groups']); |
780 | - foreach ($groups as $group) |
|
781 | - $context['recipients']['groups'][] = (int) $group; |
|
802 | + foreach ($groups as $group) { |
|
803 | + $context['recipients']['groups'][] = (int) $group; |
|
804 | + } |
|
782 | 805 | } |
783 | 806 | } |
784 | 807 | // Same for excluded groups |
@@ -786,15 +809,17 @@ discard block |
||
786 | 809 | { |
787 | 810 | if (is_array($_POST['exclude_groups'])) |
788 | 811 | { |
789 | - foreach ($_POST['exclude_groups'] as $group => $dummy) |
|
790 | - $context['recipients']['exclude_groups'][] = (int) $group; |
|
812 | + foreach ($_POST['exclude_groups'] as $group => $dummy) { |
|
813 | + $context['recipients']['exclude_groups'][] = (int) $group; |
|
814 | + } |
|
791 | 815 | } |
792 | 816 | // Ignore an empty string - we don't want to exclude "Regular Members" unless it's specifically selected |
793 | 817 | elseif ($_POST['exclude_groups'] != '') |
794 | 818 | { |
795 | 819 | $groups = explode(',', $_POST['exclude_groups']); |
796 | - foreach ($groups as $group) |
|
797 | - $context['recipients']['exclude_groups'][] = (int) $group; |
|
820 | + foreach ($groups as $group) { |
|
821 | + $context['recipients']['exclude_groups'][] = (int) $group; |
|
822 | + } |
|
798 | 823 | } |
799 | 824 | } |
800 | 825 | // Finally - emails! |
@@ -804,14 +829,16 @@ discard block |
||
804 | 829 | foreach ($addressed as $curmem) |
805 | 830 | { |
806 | 831 | $curmem = trim($curmem); |
807 | - if ($curmem != '' && filter_var($curmem, FILTER_VALIDATE_EMAIL)) |
|
808 | - $context['recipients']['emails'][$curmem] = $curmem; |
|
832 | + if ($curmem != '' && filter_var($curmem, FILTER_VALIDATE_EMAIL)) { |
|
833 | + $context['recipients']['emails'][$curmem] = $curmem; |
|
834 | + } |
|
809 | 835 | } |
810 | 836 | } |
811 | 837 | |
812 | 838 | // If we're only cleaning drop out here. |
813 | - if ($clean_only) |
|
814 | - return; |
|
839 | + if ($clean_only) { |
|
840 | + return; |
|
841 | + } |
|
815 | 842 | |
816 | 843 | require_once($sourcedir . '/Subs-Post.php'); |
817 | 844 | |
@@ -827,16 +854,18 @@ discard block |
||
827 | 854 | if (!$context['send_pm'] && !empty($_POST['send_html'])) |
828 | 855 | { |
829 | 856 | // Prepare the message for HTML. |
830 | - if (!empty($_POST['parse_html'])) |
|
831 | - $_POST['message'] = str_replace(array("\n", ' '), array('<br>' . "\n", ' '), $_POST['message']); |
|
857 | + if (!empty($_POST['parse_html'])) { |
|
858 | + $_POST['message'] = str_replace(array("\n", ' '), array('<br>' . "\n", ' '), $_POST['message']); |
|
859 | + } |
|
832 | 860 | |
833 | 861 | // This is here to prevent spam filters from tagging this as spam. |
834 | 862 | if (preg_match('~\<html~i', $_POST['message']) == 0) |
835 | 863 | { |
836 | - if (preg_match('~\<body~i', $_POST['message']) == 0) |
|
837 | - $_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>'; |
|
838 | - else |
|
839 | - $_POST['message'] = '<html>' . $_POST['message'] . '</html>'; |
|
864 | + if (preg_match('~\<body~i', $_POST['message']) == 0) { |
|
865 | + $_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>'; |
|
866 | + } else { |
|
867 | + $_POST['message'] = '<html>' . $_POST['message'] . '</html>'; |
|
868 | + } |
|
840 | 869 | } |
841 | 870 | } |
842 | 871 | |
@@ -890,15 +919,17 @@ discard block |
||
890 | 919 | foreach ($context['recipients']['emails'] as $k => $email) |
891 | 920 | { |
892 | 921 | // Done as many as we can? |
893 | - if ($i >= $num_at_once) |
|
894 | - break; |
|
922 | + if ($i >= $num_at_once) { |
|
923 | + break; |
|
924 | + } |
|
895 | 925 | |
896 | 926 | // Don't sent it twice! |
897 | 927 | unset($context['recipients']['emails'][$k]); |
898 | 928 | |
899 | 929 | // Dammit - can't PM emails! |
900 | - if ($context['send_pm']) |
|
901 | - continue; |
|
930 | + if ($context['send_pm']) { |
|
931 | + continue; |
|
932 | + } |
|
902 | 933 | |
903 | 934 | $to_member = array( |
904 | 935 | $email, |
@@ -932,8 +963,9 @@ discard block |
||
932 | 963 | $queryBuild[] = 'mem.id_post_group = {int:group_' . $group . '}'; |
933 | 964 | } |
934 | 965 | } |
935 | - if (!empty($queryBuild)) |
|
936 | - $sendQuery .= implode(' OR ', $queryBuild); |
|
966 | + if (!empty($queryBuild)) { |
|
967 | + $sendQuery .= implode(' OR ', $queryBuild); |
|
968 | + } |
|
937 | 969 | } |
938 | 970 | if (!empty($context['recipients']['members'])) |
939 | 971 | { |
@@ -952,8 +984,9 @@ discard block |
||
952 | 984 | } |
953 | 985 | |
954 | 986 | // Anything to exclude? |
955 | - if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups'])) |
|
956 | - $sendQuery .= ' AND mem.id_group != {int:regular_group}'; |
|
987 | + if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups'])) { |
|
988 | + $sendQuery .= ' AND mem.id_group != {int:regular_group}'; |
|
989 | + } |
|
957 | 990 | if (!empty($context['recipients']['exclude_members'])) |
958 | 991 | { |
959 | 992 | $sendQuery .= ' AND mem.id_member NOT IN ({array_int:exclude_members})'; |
@@ -989,21 +1022,24 @@ discard block |
||
989 | 1022 | foreach ($rows as $row) |
990 | 1023 | { |
991 | 1024 | // Force them to have it? |
992 | - if (empty($context['email_force']) && empty($prefs[$row['id_member']]['announcements'])) |
|
993 | - continue; |
|
1025 | + if (empty($context['email_force']) && empty($prefs[$row['id_member']]['announcements'])) { |
|
1026 | + continue; |
|
1027 | + } |
|
994 | 1028 | |
995 | 1029 | // What groups are we looking at here? |
996 | - if (empty($row['additional_groups'])) |
|
997 | - $groups = array($row['id_group'], $row['id_post_group']); |
|
998 | - else |
|
999 | - $groups = array_merge( |
|
1030 | + if (empty($row['additional_groups'])) { |
|
1031 | + $groups = array($row['id_group'], $row['id_post_group']); |
|
1032 | + } else { |
|
1033 | + $groups = array_merge( |
|
1000 | 1034 | array($row['id_group'], $row['id_post_group']), |
1001 | 1035 | explode(',', $row['additional_groups']) |
1002 | 1036 | ); |
1037 | + } |
|
1003 | 1038 | |
1004 | 1039 | // Excluded groups? |
1005 | - if (array_intersect($groups, $context['recipients']['exclude_groups'])) |
|
1006 | - continue; |
|
1040 | + if (array_intersect($groups, $context['recipients']['exclude_groups'])) { |
|
1041 | + continue; |
|
1042 | + } |
|
1007 | 1043 | |
1008 | 1044 | // We might need this |
1009 | 1045 | $cleanMemberName = empty($_POST['send_html']) || $context['send_pm'] ? un_htmlspecialchars($row['real_name']) : $row['real_name']; |
@@ -1026,10 +1062,11 @@ discard block |
||
1026 | 1062 | ), $_POST['subject']); |
1027 | 1063 | |
1028 | 1064 | // Send the actual email - or a PM! |
1029 | - if (!$context['send_pm']) |
|
1030 | - sendmail($row['email_address'], $subject, $message, null, 'news', !empty($_POST['send_html']), 5); |
|
1031 | - else |
|
1032 | - sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message); |
|
1065 | + if (!$context['send_pm']) { |
|
1066 | + sendmail($row['email_address'], $subject, $message, null, 'news', !empty($_POST['send_html']), 5); |
|
1067 | + } else { |
|
1068 | + sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message); |
|
1069 | + } |
|
1033 | 1070 | } |
1034 | 1071 | } |
1035 | 1072 | |
@@ -1079,8 +1116,9 @@ discard block |
||
1079 | 1116 | |
1080 | 1117 | call_integration_hook('integrate_modify_news_settings', array(&$config_vars)); |
1081 | 1118 | |
1082 | - if ($return_config) |
|
1083 | - return $config_vars; |
|
1119 | + if ($return_config) { |
|
1120 | + return $config_vars; |
|
1121 | + } |
|
1084 | 1122 | |
1085 | 1123 | $context['page_title'] = $txt['admin_edit_news'] . ' - ' . $txt['settings']; |
1086 | 1124 | $context['sub_template'] = 'show_settings'; |
@@ -5495,7 +5495,6 @@ discard block |
||
5495 | 5495 | |
5496 | 5496 | /** |
5497 | 5497 | * Tries different modes to make file/dirs writable. Wrapper function for chmod() |
5498 | - |
|
5499 | 5498 | * @param string $file The file/dir full path. |
5500 | 5499 | * @param int $value Not needed, added for legacy reasons. |
5501 | 5500 | * @return boolean true if the file/dir is already writable or the function was able to make it writable, false if the function couldn't make the file/dir writable. |
@@ -5535,7 +5534,6 @@ discard block |
||
5535 | 5534 | |
5536 | 5535 | /** |
5537 | 5536 | * Wrapper function for json_decode() with error handling. |
5538 | - |
|
5539 | 5537 | * @param string $json The string to decode. |
5540 | 5538 | * @param bool $returnAsArray To return the decoded string as an array or an object, SMF only uses Arrays but to keep on compatibility with json_decode its set to false as default. |
5541 | 5539 | * @param bool $logIt To specify if the error will be logged if theres any. |
@@ -6029,7 +6027,7 @@ discard block |
||
6029 | 6027 | $params = stream_context_get_params($stream); |
6030 | 6028 | $result = isset($params["options"]["ssl"]["peer_certificate"]) ? true : false; |
6031 | 6029 | } |
6032 | - return $result; |
|
6030 | + return $result; |
|
6033 | 6031 | } |
6034 | 6032 | |
6035 | 6033 | /** |
@@ -693,7 +693,7 @@ discard block |
||
693 | 693 | * - caches the formatting data from the setting for optimization. |
694 | 694 | * |
695 | 695 | * @param float $number A number |
696 | - * @param bool|int $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined |
|
696 | + * @param integer $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined |
|
697 | 697 | * @return string A formatted number |
698 | 698 | */ |
699 | 699 | function comma_format($number, $override_decimal_count = false) |
@@ -5869,7 +5869,7 @@ discard block |
||
5869 | 5869 | * It assumes the data is already a string. |
5870 | 5870 | * @param string $data The data to print |
5871 | 5871 | * @param string $type The content type. Defaults to Json. |
5872 | - * @return void |
|
5872 | + * @return false|null |
|
5873 | 5873 | */ |
5874 | 5874 | function smf_serverResponse($data = '', $type = 'content-type: application/json') |
5875 | 5875 | { |
@@ -6351,7 +6351,7 @@ discard block |
||
6351 | 6351 | * |
6352 | 6352 | * @param string $iri The IRI to test. |
6353 | 6353 | * @param int $flags Optional flags to pass to filter_var() |
6354 | - * @return string|bool Either the original IRI, or false if the IRI was invalid. |
|
6354 | + * @return string|false Either the original IRI, or false if the IRI was invalid. |
|
6355 | 6355 | */ |
6356 | 6356 | function validate_iri($iri, $flags = null) |
6357 | 6357 | { |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | { |
392 | 392 | $val = 'CASE '; |
393 | 393 | foreach ($members as $k => $v) |
394 | - $val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' '; |
|
394 | + $val .= 'WHEN id_member = ' . $v . ' THEN ' . count(fetch_alerts($v, false, 0, array(), false)) . ' '; |
|
395 | 395 | $val = $val . ' END'; |
396 | 396 | $type = 'raw'; |
397 | 397 | } |
@@ -744,7 +744,7 @@ discard block |
||
744 | 744 | static $non_twelve_hour, $locale_cache; |
745 | 745 | static $unsupportedFormats, $finalizedFormats; |
746 | 746 | |
747 | - $unsupportedFormatsWindows = array('z','Z'); |
|
747 | + $unsupportedFormatsWindows = array('z', 'Z'); |
|
748 | 748 | |
749 | 749 | // Ensure required values are set |
750 | 750 | $user_info['time_offset'] = !empty($user_info['time_offset']) ? $user_info['time_offset'] : 0; |
@@ -829,7 +829,7 @@ discard block |
||
829 | 829 | $unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400); |
830 | 830 | if (empty($unsupportedFormats)) |
831 | 831 | { |
832 | - foreach($strftimeFormatSubstitutions as $format => $substitution) |
|
832 | + foreach ($strftimeFormatSubstitutions as $format => $substitution) |
|
833 | 833 | { |
834 | 834 | // Avoid a crashing bug with PHP 7 on certain versions of Windows |
835 | 835 | if ($context['server']['is_windows'] && in_array($format, $unsupportedFormatsWindows)) |
@@ -1209,7 +1209,7 @@ discard block |
||
1209 | 1209 | 'height' => array('optional' => true, 'match' => '(\d+)'), |
1210 | 1210 | ), |
1211 | 1211 | 'content' => '$1', |
1212 | - 'validate' => function (&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt) |
|
1212 | + 'validate' => function(&$tag, &$data, $disabled, $params) use ($modSettings, $context, $sourcedir, $txt) |
|
1213 | 1213 | { |
1214 | 1214 | $returnContext = ''; |
1215 | 1215 | |
@@ -1244,7 +1244,7 @@ discard block |
||
1244 | 1244 | } |
1245 | 1245 | |
1246 | 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>'; |
|
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 | 1248 | else |
1249 | 1249 | $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
1250 | 1250 | } |
@@ -1296,7 +1296,7 @@ discard block |
||
1296 | 1296 | 'type' => 'unparsed_content', |
1297 | 1297 | 'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>', |
1298 | 1298 | // @todo Maybe this can be simplified? |
1299 | - 'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context) |
|
1299 | + 'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context) |
|
1300 | 1300 | { |
1301 | 1301 | if (!isset($disabled['code'])) |
1302 | 1302 | { |
@@ -1333,7 +1333,7 @@ discard block |
||
1333 | 1333 | 'type' => 'unparsed_equals_content', |
1334 | 1334 | 'content' => '<div class="codeheader"><span class="code floatleft">' . $txt['code'] . '</span> ($2) <a class="codeoperation smf_select_text">' . $txt['code_select'] . '</a></div><code class="bbc_code">$1</code>', |
1335 | 1335 | // @todo Maybe this can be simplified? |
1336 | - 'validate' => isset($disabled['code']) ? null : function (&$tag, &$data, $disabled) use ($context) |
|
1336 | + 'validate' => isset($disabled['code']) ? null : function(&$tag, &$data, $disabled) use ($context) |
|
1337 | 1337 | { |
1338 | 1338 | if (!isset($disabled['code'])) |
1339 | 1339 | { |
@@ -1377,7 +1377,7 @@ discard block |
||
1377 | 1377 | 'type' => 'unparsed_content', |
1378 | 1378 | 'content' => '<a href="mailto:$1" class="bbc_email">$1</a>', |
1379 | 1379 | // @todo Should this respect guest_hideContacts? |
1380 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1380 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1381 | 1381 | { |
1382 | 1382 | $data = strtr($data, array('<br>' => '')); |
1383 | 1383 | }, |
@@ -1397,7 +1397,7 @@ discard block |
||
1397 | 1397 | 'test' => '(left|right)(\s+max=\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)?\]', |
1398 | 1398 | 'before' => '<div $1>', |
1399 | 1399 | 'after' => '</div>', |
1400 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1400 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1401 | 1401 | { |
1402 | 1402 | $class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"'; |
1403 | 1403 | |
@@ -1483,7 +1483,7 @@ discard block |
||
1483 | 1483 | 'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'), |
1484 | 1484 | ), |
1485 | 1485 | 'content' => '<img src="$1" alt="{alt}" title="{title}"{width}{height} class="bbc_img resized">', |
1486 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1486 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1487 | 1487 | { |
1488 | 1488 | global $image_proxy_enabled, $user_info; |
1489 | 1489 | |
@@ -1509,7 +1509,7 @@ discard block |
||
1509 | 1509 | 'tag' => 'img', |
1510 | 1510 | 'type' => 'unparsed_content', |
1511 | 1511 | 'content' => '<img src="$1" alt="" class="bbc_img">', |
1512 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1512 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1513 | 1513 | { |
1514 | 1514 | global $image_proxy_enabled, $user_info; |
1515 | 1515 | |
@@ -1535,7 +1535,7 @@ discard block |
||
1535 | 1535 | 'tag' => 'iurl', |
1536 | 1536 | 'type' => 'unparsed_content', |
1537 | 1537 | 'content' => '<a href="$1" class="bbc_link">$1</a>', |
1538 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1538 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1539 | 1539 | { |
1540 | 1540 | $data = strtr($data, array('<br>' => '')); |
1541 | 1541 | $scheme = parse_url($data, PHP_URL_SCHEME); |
@@ -1549,7 +1549,7 @@ discard block |
||
1549 | 1549 | 'quoted' => 'optional', |
1550 | 1550 | 'before' => '<a href="$1" class="bbc_link">', |
1551 | 1551 | 'after' => '</a>', |
1552 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1552 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1553 | 1553 | { |
1554 | 1554 | if (substr($data, 0, 1) == '#') |
1555 | 1555 | $data = '#post_' . substr($data, 1); |
@@ -1642,7 +1642,7 @@ discard block |
||
1642 | 1642 | 'tag' => 'php', |
1643 | 1643 | 'type' => 'unparsed_content', |
1644 | 1644 | 'content' => '<span class="phpcode">$1</span>', |
1645 | - 'validate' => isset($disabled['php']) ? null : function (&$tag, &$data, $disabled) |
|
1645 | + 'validate' => isset($disabled['php']) ? null : function(&$tag, &$data, $disabled) |
|
1646 | 1646 | { |
1647 | 1647 | if (!isset($disabled['php'])) |
1648 | 1648 | { |
@@ -1770,7 +1770,7 @@ discard block |
||
1770 | 1770 | 'test' => '[1-7]\]', |
1771 | 1771 | 'before' => '<span style="font-size: $1;" class="bbc_size">', |
1772 | 1772 | 'after' => '</span>', |
1773 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1773 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1774 | 1774 | { |
1775 | 1775 | $sizes = array(1 => 0.7, 2 => 1.0, 3 => 1.35, 4 => 1.45, 5 => 2.0, 6 => 2.65, 7 => 3.95); |
1776 | 1776 | $data = $sizes[$data] . 'em'; |
@@ -1808,7 +1808,7 @@ discard block |
||
1808 | 1808 | 'tag' => 'time', |
1809 | 1809 | 'type' => 'unparsed_content', |
1810 | 1810 | 'content' => '$1', |
1811 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1811 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1812 | 1812 | { |
1813 | 1813 | if (is_numeric($data)) |
1814 | 1814 | $data = timeformat($data); |
@@ -1841,7 +1841,7 @@ discard block |
||
1841 | 1841 | 'tag' => 'url', |
1842 | 1842 | 'type' => 'unparsed_content', |
1843 | 1843 | 'content' => '<a href="$1" class="bbc_link" target="_blank" rel="noopener">$1</a>', |
1844 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1844 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1845 | 1845 | { |
1846 | 1846 | $data = strtr($data, array('<br>' => '')); |
1847 | 1847 | $scheme = parse_url($data, PHP_URL_SCHEME); |
@@ -1855,7 +1855,7 @@ discard block |
||
1855 | 1855 | 'quoted' => 'optional', |
1856 | 1856 | 'before' => '<a href="$1" class="bbc_link" target="_blank" rel="noopener">', |
1857 | 1857 | 'after' => '</a>', |
1858 | - 'validate' => function (&$tag, &$data, $disabled) |
|
1858 | + 'validate' => function(&$tag, &$data, $disabled) |
|
1859 | 1859 | { |
1860 | 1860 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1861 | 1861 | if (empty($scheme)) |
@@ -1901,7 +1901,7 @@ discard block |
||
1901 | 1901 | { |
1902 | 1902 | if (isset($temp_bbc)) |
1903 | 1903 | $bbc_codes = $temp_bbc; |
1904 | - usort($codes, function ($a, $b) { |
|
1904 | + usort($codes, function($a, $b) { |
|
1905 | 1905 | return strcmp($a['tag'], $b['tag']); |
1906 | 1906 | }); |
1907 | 1907 | return $codes; |
@@ -2117,7 +2117,7 @@ discard block |
||
2117 | 2117 | # a run of Unicode domain name characters and a dot |
2118 | 2118 | [\p{L}\p{M}\p{N}\-.:@]+\. |
2119 | 2119 | # and then a TLD valid in the DNS or the reserved "local" TLD |
2120 | - (?:'. $modSettings['tld_regex'] .'|local) |
|
2120 | + (?:'. $modSettings['tld_regex'] . '|local) |
|
2121 | 2121 | ) |
2122 | 2122 | # followed by a non-domain character or end of line |
2123 | 2123 | (?=[^\p{L}\p{N}\-.]|$) |
@@ -2185,7 +2185,7 @@ discard block |
||
2185 | 2185 | )? |
2186 | 2186 | '; |
2187 | 2187 | |
2188 | - $data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function ($matches) { |
|
2188 | + $data = preg_replace_callback('~' . $url_regex . '~xi' . ($context['utf8'] ? 'u' : ''), function($matches) { |
|
2189 | 2189 | $url = array_shift($matches); |
2190 | 2190 | |
2191 | 2191 | // If this isn't a clean URL, bail out |
@@ -2210,7 +2210,7 @@ discard block |
||
2210 | 2210 | $fullUrl = $url; |
2211 | 2211 | |
2212 | 2212 | // Make sure that $fullUrl really is valid |
2213 | - if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) |
|
2213 | + if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '') . $fullUrl) === false) |
|
2214 | 2214 | return $url; |
2215 | 2215 | |
2216 | 2216 | return '[url="' . str_replace(array('[', ']'), array('[', ']'), $fullUrl) . '"]' . $url . '[/url]'; |
@@ -2274,7 +2274,7 @@ discard block |
||
2274 | 2274 | $look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2)); |
2275 | 2275 | |
2276 | 2276 | // 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))) |
|
2277 | + if (!in_array($look_for, array_map(function($code) {return $code['tag']; }, $open_tags))) |
|
2278 | 2278 | continue; |
2279 | 2279 | |
2280 | 2280 | $to_close = array(); |
@@ -2932,7 +2932,7 @@ discard block |
||
2932 | 2932 | } |
2933 | 2933 | |
2934 | 2934 | // Set proper extensions; do this post caching so cache doesn't become extension-specific |
2935 | - foreach($smileysto AS $ix=>$file) |
|
2935 | + foreach ($smileysto AS $ix=>$file) |
|
2936 | 2936 | // Need to use the default if user selection is disabled |
2937 | 2937 | if (empty($modSettings['smiley_sets_enable'])) |
2938 | 2938 | $smileysto[$ix] = $file . $context['user']['smiley_set_default_ext']; |
@@ -2950,7 +2950,7 @@ discard block |
||
2950 | 2950 | for ($i = 0, $n = count($smileysfrom); $i < $n; $i++) |
2951 | 2951 | { |
2952 | 2952 | $specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES); |
2953 | - $smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')). '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')) . '" class="smiley">'; |
|
2953 | + $smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')) . '" title="' . strtr($smcFunc['htmlspecialchars']($smileysdescs[$i]), array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')) . '" class="smiley">'; |
|
2954 | 2954 | |
2955 | 2955 | $smileyPregReplacements[$smileysfrom[$i]] = $smileyCode; |
2956 | 2956 | |
@@ -2975,7 +2975,7 @@ discard block |
||
2975 | 2975 | |
2976 | 2976 | // Replace away! |
2977 | 2977 | $message = preg_replace_callback($smileyPregSearch, |
2978 | - function ($matches) use ($smileyPregReplacements) |
|
2978 | + function($matches) use ($smileyPregReplacements) |
|
2979 | 2979 | { |
2980 | 2980 | return $smileyPregReplacements[$matches[1]]; |
2981 | 2981 | }, $message); |
@@ -3072,13 +3072,13 @@ discard block |
||
3072 | 3072 | { |
3073 | 3073 | if (defined('SID') && SID != '') |
3074 | 3074 | $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
3075 | - function ($m) use ($scripturl) |
|
3075 | + function($m) use ($scripturl) |
|
3076 | 3076 | { |
3077 | - return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); |
|
3077 | + return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID . (isset($m[2]) ? "$m[2]" : ""); |
|
3078 | 3078 | }, $setLocation); |
3079 | 3079 | else |
3080 | 3080 | $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
3081 | - function ($m) use ($scripturl) |
|
3081 | + function($m) use ($scripturl) |
|
3082 | 3082 | { |
3083 | 3083 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); |
3084 | 3084 | }, $setLocation); |
@@ -3399,7 +3399,7 @@ discard block |
||
3399 | 3399 | |
3400 | 3400 | // Add a generic "Are you sure?" confirmation message. |
3401 | 3401 | addInlineJavaScript(' |
3402 | - var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); |
|
3402 | + var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) . ';'); |
|
3403 | 3403 | |
3404 | 3404 | // Now add the capping code for avatars. |
3405 | 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') |
@@ -3865,7 +3865,7 @@ discard block |
||
3865 | 3865 | if (!empty($normal)) |
3866 | 3866 | foreach ($normal as $nf) |
3867 | 3867 | echo ' |
3868 | - <link rel="stylesheet" href="', $nf ,'">'; |
|
3868 | + <link rel="stylesheet" href="', $nf, '">'; |
|
3869 | 3869 | |
3870 | 3870 | if ($db_show_debug === true) |
3871 | 3871 | { |
@@ -3881,7 +3881,7 @@ discard block |
||
3881 | 3881 | <style>'; |
3882 | 3882 | |
3883 | 3883 | foreach ($context['css_header'] as $css) |
3884 | - echo $css .' |
|
3884 | + echo $css . ' |
|
3885 | 3885 | '; |
3886 | 3886 | |
3887 | 3887 | echo' |
@@ -3925,7 +3925,7 @@ discard block |
||
3925 | 3925 | |
3926 | 3926 | |
3927 | 3927 | // No namespaces, sorry! |
3928 | - $classType = 'MatthiasMullie\\Minify\\'. strtoupper($type); |
|
3928 | + $classType = 'MatthiasMullie\\Minify\\' . strtoupper($type); |
|
3929 | 3929 | |
3930 | 3930 | // Temp path. |
3931 | 3931 | $cTempPath = $settings['theme_dir'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/'; |
@@ -4105,7 +4105,7 @@ discard block |
||
4105 | 4105 | else |
4106 | 4106 | $path = $modSettings['attachmentUploadDir']; |
4107 | 4107 | |
4108 | - return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; |
|
4108 | + return $path . '/' . $attachment_id . '_' . $file_hash . '.dat'; |
|
4109 | 4109 | } |
4110 | 4110 | |
4111 | 4111 | /** |
@@ -4149,10 +4149,10 @@ discard block |
||
4149 | 4149 | $valid_low = isValidIP($ip_parts[0]); |
4150 | 4150 | $valid_high = isValidIP($ip_parts[1]); |
4151 | 4151 | $count = 0; |
4152 | - $mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); |
|
4152 | + $mode = (preg_match('/:/', $ip_parts[0]) > 0 ? ':' : '.'); |
|
4153 | 4153 | $max = ($mode == ':' ? 'ffff' : '255'); |
4154 | 4154 | $min = 0; |
4155 | - if(!$valid_low) |
|
4155 | + if (!$valid_low) |
|
4156 | 4156 | { |
4157 | 4157 | $ip_parts[0] = preg_replace('/\*/', '0', $ip_parts[0]); |
4158 | 4158 | $valid_low = isValidIP($ip_parts[0]); |
@@ -4166,7 +4166,7 @@ discard block |
||
4166 | 4166 | } |
4167 | 4167 | |
4168 | 4168 | $count = 0; |
4169 | - if(!$valid_high) |
|
4169 | + if (!$valid_high) |
|
4170 | 4170 | { |
4171 | 4171 | $ip_parts[1] = preg_replace('/\*/', $max, $ip_parts[1]); |
4172 | 4172 | $valid_high = isValidIP($ip_parts[1]); |
@@ -4179,7 +4179,7 @@ discard block |
||
4179 | 4179 | } |
4180 | 4180 | } |
4181 | 4181 | |
4182 | - if($valid_high && $valid_low) |
|
4182 | + if ($valid_high && $valid_low) |
|
4183 | 4183 | { |
4184 | 4184 | $ip_array['low'] = $ip_parts[0]; |
4185 | 4185 | $ip_array['high'] = $ip_parts[1]; |
@@ -4360,7 +4360,7 @@ discard block |
||
4360 | 4360 | addInlineJavaScript(' |
4361 | 4361 | var user_menus = new smc_PopupMenu(); |
4362 | 4362 | user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); |
4363 | - user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); |
|
4363 | + user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u=' . $context['user']['id'] . '");', true); |
|
4364 | 4364 | if ($context['allow_pm']) |
4365 | 4365 | addInlineJavaScript(' |
4366 | 4366 | user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); |
@@ -4655,7 +4655,7 @@ discard block |
||
4655 | 4655 | $context['total_admin_reports'] += $context['unapproved_members']; |
4656 | 4656 | } |
4657 | 4657 | |
4658 | - if($context['total_admin_reports'] > 0 && !empty($context['menu_buttons']['admin'])) |
|
4658 | + if ($context['total_admin_reports'] > 0 && !empty($context['menu_buttons']['admin'])) |
|
4659 | 4659 | { |
4660 | 4660 | $context['menu_buttons']['admin']['amt'] = $context['total_admin_reports']; |
4661 | 4661 | } |
@@ -5002,7 +5002,7 @@ discard block |
||
5002 | 5002 | // No? try a fallback to $sourcedir |
5003 | 5003 | else |
5004 | 5004 | { |
5005 | - $absPath = $sourcedir .'/'. $file; |
|
5005 | + $absPath = $sourcedir . '/' . $file; |
|
5006 | 5006 | |
5007 | 5007 | if (file_exists($absPath)) |
5008 | 5008 | require_once($absPath); |
@@ -5269,15 +5269,15 @@ discard block |
||
5269 | 5269 | |
5270 | 5270 | // UTF-8 occurences of MS special characters |
5271 | 5271 | $findchars_utf8 = array( |
5272 | - "\xe2\x80\x9a", // single low-9 quotation mark |
|
5273 | - "\xe2\x80\x9e", // double low-9 quotation mark |
|
5274 | - "\xe2\x80\xa6", // horizontal ellipsis |
|
5275 | - "\xe2\x80\x98", // left single curly quote |
|
5276 | - "\xe2\x80\x99", // right single curly quote |
|
5277 | - "\xe2\x80\x9c", // left double curly quote |
|
5278 | - "\xe2\x80\x9d", // right double curly quote |
|
5279 | - "\xe2\x80\x93", // en dash |
|
5280 | - "\xe2\x80\x94", // em dash |
|
5272 | + "\xe2\x80\x9a", // single low-9 quotation mark |
|
5273 | + "\xe2\x80\x9e", // double low-9 quotation mark |
|
5274 | + "\xe2\x80\xa6", // horizontal ellipsis |
|
5275 | + "\xe2\x80\x98", // left single curly quote |
|
5276 | + "\xe2\x80\x99", // right single curly quote |
|
5277 | + "\xe2\x80\x9c", // left double curly quote |
|
5278 | + "\xe2\x80\x9d", // right double curly quote |
|
5279 | + "\xe2\x80\x93", // en dash |
|
5280 | + "\xe2\x80\x94", // em dash |
|
5281 | 5281 | ); |
5282 | 5282 | |
5283 | 5283 | // windows 1252 / iso equivalents |
@@ -5295,15 +5295,15 @@ discard block |
||
5295 | 5295 | |
5296 | 5296 | // safe replacements |
5297 | 5297 | $replacechars = array( |
5298 | - ',', // ‚ |
|
5299 | - ',,', // „ |
|
5300 | - '...', // … |
|
5301 | - "'", // ‘ |
|
5302 | - "'", // ’ |
|
5303 | - '"', // “ |
|
5304 | - '"', // ” |
|
5305 | - '-', // – |
|
5306 | - '--', // — |
|
5298 | + ',', // ‚ |
|
5299 | + ',,', // „ |
|
5300 | + '...', // … |
|
5301 | + "'", // ‘ |
|
5302 | + "'", // ’ |
|
5303 | + '"', // “ |
|
5304 | + '"', // ” |
|
5305 | + '-', // – |
|
5306 | + '--', // — |
|
5307 | 5307 | ); |
5308 | 5308 | |
5309 | 5309 | if ($context['utf8']) |
@@ -5623,7 +5623,7 @@ discard block |
||
5623 | 5623 | */ |
5624 | 5624 | function inet_dtop($bin) |
5625 | 5625 | { |
5626 | - if(empty($bin)) |
|
5626 | + if (empty($bin)) |
|
5627 | 5627 | return ''; |
5628 | 5628 | |
5629 | 5629 | global $db_type; |
@@ -5654,28 +5654,28 @@ discard block |
||
5654 | 5654 | */ |
5655 | 5655 | function _safe_serialize($value) |
5656 | 5656 | { |
5657 | - if(is_null($value)) |
|
5657 | + if (is_null($value)) |
|
5658 | 5658 | return 'N;'; |
5659 | 5659 | |
5660 | - if(is_bool($value)) |
|
5661 | - return 'b:'. (int) $value .';'; |
|
5660 | + if (is_bool($value)) |
|
5661 | + return 'b:' . (int) $value . ';'; |
|
5662 | 5662 | |
5663 | - if(is_int($value)) |
|
5664 | - return 'i:'. $value .';'; |
|
5663 | + if (is_int($value)) |
|
5664 | + return 'i:' . $value . ';'; |
|
5665 | 5665 | |
5666 | - if(is_float($value)) |
|
5667 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
5666 | + if (is_float($value)) |
|
5667 | + return 'd:' . str_replace(',', '.', $value) . ';'; |
|
5668 | 5668 | |
5669 | - if(is_string($value)) |
|
5670 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
5669 | + if (is_string($value)) |
|
5670 | + return 's:' . strlen($value) . ':"' . $value . '";'; |
|
5671 | 5671 | |
5672 | - if(is_array($value)) |
|
5672 | + if (is_array($value)) |
|
5673 | 5673 | { |
5674 | 5674 | $out = ''; |
5675 | - foreach($value as $k => $v) |
|
5675 | + foreach ($value as $k => $v) |
|
5676 | 5676 | $out .= _safe_serialize($k) . _safe_serialize($v); |
5677 | 5677 | |
5678 | - return 'a:'. count($value) .':{'. $out .'}'; |
|
5678 | + return 'a:' . count($value) . ':{' . $out . '}'; |
|
5679 | 5679 | } |
5680 | 5680 | |
5681 | 5681 | // safe_serialize cannot serialize resources or objects. |
@@ -5717,7 +5717,7 @@ discard block |
||
5717 | 5717 | function _safe_unserialize($str) |
5718 | 5718 | { |
5719 | 5719 | // Input is not a string. |
5720 | - if(empty($str) || !is_string($str)) |
|
5720 | + if (empty($str) || !is_string($str)) |
|
5721 | 5721 | return false; |
5722 | 5722 | |
5723 | 5723 | $stack = array(); |
@@ -5731,40 +5731,40 @@ discard block |
||
5731 | 5731 | * 3 - in array, expecting value or another array |
5732 | 5732 | */ |
5733 | 5733 | $state = 0; |
5734 | - while($state != 1) |
|
5734 | + while ($state != 1) |
|
5735 | 5735 | { |
5736 | 5736 | $type = isset($str[0]) ? $str[0] : ''; |
5737 | - if($type == '}') |
|
5737 | + if ($type == '}') |
|
5738 | 5738 | $str = substr($str, 1); |
5739 | 5739 | |
5740 | - else if($type == 'N' && $str[1] == ';') |
|
5740 | + else if ($type == 'N' && $str[1] == ';') |
|
5741 | 5741 | { |
5742 | 5742 | $value = null; |
5743 | 5743 | $str = substr($str, 2); |
5744 | 5744 | } |
5745 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
5745 | + else if ($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
5746 | 5746 | { |
5747 | 5747 | $value = $matches[1] == '1' ? true : false; |
5748 | 5748 | $str = substr($str, 4); |
5749 | 5749 | } |
5750 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
5750 | + else if ($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
5751 | 5751 | { |
5752 | - $value = (int)$matches[1]; |
|
5752 | + $value = (int) $matches[1]; |
|
5753 | 5753 | $str = $matches[2]; |
5754 | 5754 | } |
5755 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
5755 | + else if ($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
5756 | 5756 | { |
5757 | - $value = (float)$matches[1]; |
|
5757 | + $value = (float) $matches[1]; |
|
5758 | 5758 | $str = $matches[3]; |
5759 | 5759 | } |
5760 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
5760 | + else if ($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int) $matches[1], 2) == '";') |
|
5761 | 5761 | { |
5762 | - $value = substr($matches[2], 0, (int)$matches[1]); |
|
5763 | - $str = substr($matches[2], (int)$matches[1] + 2); |
|
5762 | + $value = substr($matches[2], 0, (int) $matches[1]); |
|
5763 | + $str = substr($matches[2], (int) $matches[1] + 2); |
|
5764 | 5764 | } |
5765 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
5765 | + else if ($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
5766 | 5766 | { |
5767 | - $expectedLength = (int)$matches[1]; |
|
5767 | + $expectedLength = (int) $matches[1]; |
|
5768 | 5768 | $str = $matches[2]; |
5769 | 5769 | } |
5770 | 5770 | |
@@ -5772,10 +5772,10 @@ discard block |
||
5772 | 5772 | else |
5773 | 5773 | return false; |
5774 | 5774 | |
5775 | - switch($state) |
|
5775 | + switch ($state) |
|
5776 | 5776 | { |
5777 | 5777 | case 3: // In array, expecting value or another array. |
5778 | - if($type == 'a') |
|
5778 | + if ($type == 'a') |
|
5779 | 5779 | { |
5780 | 5780 | $stack[] = &$list; |
5781 | 5781 | $list[$key] = array(); |
@@ -5784,7 +5784,7 @@ discard block |
||
5784 | 5784 | $state = 2; |
5785 | 5785 | break; |
5786 | 5786 | } |
5787 | - if($type != '}') |
|
5787 | + if ($type != '}') |
|
5788 | 5788 | { |
5789 | 5789 | $list[$key] = $value; |
5790 | 5790 | $state = 2; |
@@ -5795,29 +5795,29 @@ discard block |
||
5795 | 5795 | return false; |
5796 | 5796 | |
5797 | 5797 | case 2: // in array, expecting end of array or a key |
5798 | - if($type == '}') |
|
5798 | + if ($type == '}') |
|
5799 | 5799 | { |
5800 | 5800 | // Array size is less than expected. |
5801 | - if(count($list) < end($expected)) |
|
5801 | + if (count($list) < end($expected)) |
|
5802 | 5802 | return false; |
5803 | 5803 | |
5804 | 5804 | unset($list); |
5805 | - $list = &$stack[count($stack)-1]; |
|
5805 | + $list = &$stack[count($stack) - 1]; |
|
5806 | 5806 | array_pop($stack); |
5807 | 5807 | |
5808 | 5808 | // Go to terminal state if we're at the end of the root array. |
5809 | 5809 | array_pop($expected); |
5810 | 5810 | |
5811 | - if(count($expected) == 0) |
|
5811 | + if (count($expected) == 0) |
|
5812 | 5812 | $state = 1; |
5813 | 5813 | |
5814 | 5814 | break; |
5815 | 5815 | } |
5816 | 5816 | |
5817 | - if($type == 'i' || $type == 's') |
|
5817 | + if ($type == 'i' || $type == 's') |
|
5818 | 5818 | { |
5819 | 5819 | // Array size exceeds expected length. |
5820 | - if(count($list) >= end($expected)) |
|
5820 | + if (count($list) >= end($expected)) |
|
5821 | 5821 | return false; |
5822 | 5822 | |
5823 | 5823 | $key = $value; |
@@ -5830,7 +5830,7 @@ discard block |
||
5830 | 5830 | |
5831 | 5831 | // Expecting array or value. |
5832 | 5832 | case 0: |
5833 | - if($type == 'a') |
|
5833 | + if ($type == 'a') |
|
5834 | 5834 | { |
5835 | 5835 | $data = array(); |
5836 | 5836 | $list = &$data; |
@@ -5839,7 +5839,7 @@ discard block |
||
5839 | 5839 | break; |
5840 | 5840 | } |
5841 | 5841 | |
5842 | - if($type != '}') |
|
5842 | + if ($type != '}') |
|
5843 | 5843 | { |
5844 | 5844 | $data = $value; |
5845 | 5845 | $state = 1; |
@@ -5852,7 +5852,7 @@ discard block |
||
5852 | 5852 | } |
5853 | 5853 | |
5854 | 5854 | // Trailing data in input. |
5855 | - if(!empty($str)) |
|
5855 | + if (!empty($str)) |
|
5856 | 5856 | return false; |
5857 | 5857 | |
5858 | 5858 | return $data; |
@@ -5906,7 +5906,7 @@ discard block |
||
5906 | 5906 | // Set different modes. |
5907 | 5907 | $chmodValues = $isDir ? array(0750, 0755, 0775, 0777) : array(0644, 0664, 0666); |
5908 | 5908 | |
5909 | - foreach($chmodValues as $val) |
|
5909 | + foreach ($chmodValues as $val) |
|
5910 | 5910 | { |
5911 | 5911 | // If it's writable, break out of the loop. |
5912 | 5912 | if (is_writable($file)) |
@@ -5941,13 +5941,13 @@ discard block |
||
5941 | 5941 | $returnArray = @json_decode($json, $returnAsArray); |
5942 | 5942 | |
5943 | 5943 | // PHP 5.3 so no json_last_error_msg() |
5944 | - switch(json_last_error()) |
|
5944 | + switch (json_last_error()) |
|
5945 | 5945 | { |
5946 | 5946 | case JSON_ERROR_NONE: |
5947 | 5947 | $jsonError = false; |
5948 | 5948 | break; |
5949 | 5949 | case JSON_ERROR_DEPTH: |
5950 | - $jsonError = 'JSON_ERROR_DEPTH'; |
|
5950 | + $jsonError = 'JSON_ERROR_DEPTH'; |
|
5951 | 5951 | break; |
5952 | 5952 | case JSON_ERROR_STATE_MISMATCH: |
5953 | 5953 | $jsonError = 'JSON_ERROR_STATE_MISMATCH'; |
@@ -5975,10 +5975,10 @@ discard block |
||
5975 | 5975 | loadLanguage('Errors'); |
5976 | 5976 | |
5977 | 5977 | if (!empty($jsonDebug)) |
5978 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
5978 | + log_error($txt['json_' . $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
5979 | 5979 | |
5980 | 5980 | else |
5981 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
5981 | + log_error($txt['json_' . $jsonError], 'critical'); |
|
5982 | 5982 | |
5983 | 5983 | // Everyone expects an array. |
5984 | 5984 | return array(); |
@@ -6095,7 +6095,7 @@ discard block |
||
6095 | 6095 | // Convert Punycode to Unicode |
6096 | 6096 | require_once($sourcedir . '/Class-Punycode.php'); |
6097 | 6097 | $Punycode = new Punycode(); |
6098 | - $tlds = array_map(function ($input) use ($Punycode) { return $Punycode->decode($input); }, $tlds); |
|
6098 | + $tlds = array_map(function($input) use ($Punycode) { return $Punycode->decode($input); }, $tlds); |
|
6099 | 6099 | } |
6100 | 6100 | // Otherwise, use the 2012 list of gTLDs and ccTLDs for now and schedule a background update |
6101 | 6101 | else |
@@ -6189,7 +6189,7 @@ discard block |
||
6189 | 6189 | } |
6190 | 6190 | |
6191 | 6191 | // This recursive function creates the index array from the strings |
6192 | - $add_string_to_index = function ($string, $index) use (&$strlen, &$substr, &$add_string_to_index) |
|
6192 | + $add_string_to_index = function($string, $index) use (&$strlen, &$substr, &$add_string_to_index) |
|
6193 | 6193 | { |
6194 | 6194 | static $depth = 0; |
6195 | 6195 | $depth++; |
@@ -6216,7 +6216,7 @@ discard block |
||
6216 | 6216 | }; |
6217 | 6217 | |
6218 | 6218 | // This recursive function turns the index array into a regular expression |
6219 | - $index_to_regex = function (&$index, $delim) use (&$strlen, &$index_to_regex) |
|
6219 | + $index_to_regex = function(&$index, $delim) use (&$strlen, &$index_to_regex) |
|
6220 | 6220 | { |
6221 | 6221 | static $depth = 0; |
6222 | 6222 | $depth++; |
@@ -6240,11 +6240,11 @@ discard block |
||
6240 | 6240 | |
6241 | 6241 | if (count(array_keys($value)) == 1) |
6242 | 6242 | { |
6243 | - $new_key_array = explode('(?'.'>', $sub_regex); |
|
6243 | + $new_key_array = explode('(?' . '>', $sub_regex); |
|
6244 | 6244 | $new_key .= $new_key_array[0]; |
6245 | 6245 | } |
6246 | 6246 | else |
6247 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
6247 | + $sub_regex = '(?' . '>' . $sub_regex . ')'; |
|
6248 | 6248 | } |
6249 | 6249 | |
6250 | 6250 | if ($depth > 1) |
@@ -6287,10 +6287,10 @@ discard block |
||
6287 | 6287 | { |
6288 | 6288 | $regex = array(); |
6289 | 6289 | while (!empty($index)) |
6290 | - $regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6290 | + $regex[] = '(?' . '>' . $index_to_regex($index, $delim) . ')'; |
|
6291 | 6291 | } |
6292 | 6292 | else |
6293 | - $regex = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6293 | + $regex = '(?' . '>' . $index_to_regex($index, $delim) . ')'; |
|
6294 | 6294 | |
6295 | 6295 | // Restore PHP's internal character encoding to whatever it was originally |
6296 | 6296 | if (!empty($current_encoding)) |
@@ -6514,7 +6514,7 @@ discard block |
||
6514 | 6514 | function sanitize_iri($iri) |
6515 | 6515 | { |
6516 | 6516 | // Encode any non-ASCII characters (but not space or control characters of any sort) |
6517 | - $iri = preg_replace_callback('~[^\x00-\x7F\pZ\pC]~u', function ($matches) { |
|
6517 | + $iri = preg_replace_callback('~[^\x00-\x7F\pZ\pC]~u', function($matches) { |
|
6518 | 6518 | return rawurlencode($matches[0]); |
6519 | 6519 | }, $iri); |
6520 | 6520 | |
@@ -6556,7 +6556,7 @@ discard block |
||
6556 | 6556 | $unescaped = array( |
6557 | 6557 | '%21'=>'!', '%23'=>'#', '%24'=>'$', '%26'=>'&', |
6558 | 6558 | '%27'=>"'", '%28'=>'(', '%29'=>')', '%2A'=>'*', |
6559 | - '%2B'=>'+', '%2C'=>',', '%2F'=>'/', '%3A'=>':', |
|
6559 | + '%2B'=>'+', '%2C'=>',', '%2F'=>'/', '%3A'=>':', |
|
6560 | 6560 | '%3B'=>';', '%3D'=>'=', '%3F'=>'?', '%40'=>'@', |
6561 | 6561 | ); |
6562 | 6562 | $iri = strtr(rawurlencode($iri), $unescaped); |
@@ -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(); |
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) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) |
|
2855 | - cache_put_data($cache_key, $message, 240); |
|
3008 | + if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $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(); |
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 (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) |
|
3275 | - cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3453 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $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['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
3512 | + if (allowedTo('moderate_forum')) { |
|
3513 | + $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $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(); |
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 (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) |
|
4241 | - cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4486 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $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,21 +6809,25 @@ 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'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')'; |
|
6816 | + else { |
|
6817 | + $query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')'; |
|
6818 | + } |
|
6455 | 6819 | |
6456 | 6820 | // Build the list of boards they WANT to see. |
6457 | 6821 | // This will take the place of query_see_boards in certain spots, so it better include the boards they can see also |
6458 | 6822 | |
6459 | 6823 | // If they aren't ignoring any boards then they want to see all the boards they can see |
6460 | - if (empty($ignoreboards)) |
|
6461 | - $query_part['query_wanna_see_board'] = $query_part['query_see_board']; |
|
6824 | + if (empty($ignoreboards)) { |
|
6825 | + $query_part['query_wanna_see_board'] = $query_part['query_see_board']; |
|
6826 | + } |
|
6462 | 6827 | // Ok I guess they don't want to see all the boards |
6463 | - else |
|
6464 | - $query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))'; |
|
6828 | + else { |
|
6829 | + $query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))'; |
|
6830 | + } |
|
6465 | 6831 | |
6466 | 6832 | return $query_part; |
6467 | 6833 | } |
@@ -6475,10 +6841,11 @@ discard block |
||
6475 | 6841 | { |
6476 | 6842 | $secure = false; |
6477 | 6843 | |
6478 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
6479 | - $secure = true; |
|
6480 | - 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') |
|
6481 | - $secure = true; |
|
6844 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
6845 | + $secure = true; |
|
6846 | + } 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') { |
|
6847 | + $secure = true; |
|
6848 | + } |
|
6482 | 6849 | |
6483 | 6850 | return $secure; |
6484 | 6851 | } |
@@ -6495,11 +6862,12 @@ discard block |
||
6495 | 6862 | { |
6496 | 6863 | $url = iri_to_url($iri); |
6497 | 6864 | |
6498 | - if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) |
|
6499 | - return $iri; |
|
6500 | - else |
|
6501 | - return false; |
|
6502 | -} |
|
6865 | + if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) { |
|
6866 | + return $iri; |
|
6867 | + } else { |
|
6868 | + return false; |
|
6869 | + } |
|
6870 | + } |
|
6503 | 6871 | |
6504 | 6872 | /** |
6505 | 6873 | * A wrapper for `filter_var($url, FILTER_SANITIZE_URL)` that can handle URLs |
@@ -6542,8 +6910,9 @@ discard block |
||
6542 | 6910 | |
6543 | 6911 | $host = parse_url((strpos($iri, '://') === false ? 'http://' : '') . ltrim($iri, ':/'), PHP_URL_HOST); |
6544 | 6912 | |
6545 | - if (empty($host)) |
|
6546 | - return $iri; |
|
6913 | + if (empty($host)) { |
|
6914 | + return $iri; |
|
6915 | + } |
|
6547 | 6916 | |
6548 | 6917 | // Convert the domain using the Punycode algorithm |
6549 | 6918 | require_once($sourcedir . '/Class-Punycode.php'); |
@@ -6579,8 +6948,9 @@ discard block |
||
6579 | 6948 | |
6580 | 6949 | $host = parse_url((strpos($url, '://') === false ? 'http://' : '') . ltrim($url, ':/'), PHP_URL_HOST); |
6581 | 6950 | |
6582 | - if (empty($host)) |
|
6583 | - return $url; |
|
6951 | + if (empty($host)) { |
|
6952 | + return $url; |
|
6953 | + } |
|
6584 | 6954 | |
6585 | 6955 | // Decode the domain from Punycode |
6586 | 6956 | require_once($sourcedir . '/Class-Punycode.php'); |
@@ -6606,8 +6976,9 @@ discard block |
||
6606 | 6976 | { |
6607 | 6977 | global $user_info, $modSettings, $smcFunc, $txt; |
6608 | 6978 | |
6609 | - if (empty($modSettings['cron_last_checked'])) |
|
6610 | - $modSettings['cron_last_checked'] = 0; |
|
6979 | + if (empty($modSettings['cron_last_checked'])) { |
|
6980 | + $modSettings['cron_last_checked'] = 0; |
|
6981 | + } |
|
6611 | 6982 | |
6612 | 6983 | if (!empty($modSettings['cron_is_real_cron']) && time() - $modSettings['cron_last_checked'] > 84600) |
6613 | 6984 | { |
@@ -6627,9 +6998,9 @@ discard block |
||
6627 | 6998 | loadLanguage('ManageScheduledTasks'); |
6628 | 6999 | log_error($txt['cron_not_working']); |
6629 | 7000 | updateSettings(array('cron_is_real_cron' => 0)); |
7001 | + } else { |
|
7002 | + updateSettings(array('cron_last_checked' => time())); |
|
6630 | 7003 | } |
6631 | - else |
|
6632 | - updateSettings(array('cron_last_checked' => time())); |
|
6633 | 7004 | } |
6634 | 7005 | } |
6635 | 7006 | |
@@ -6653,10 +7024,11 @@ discard block |
||
6653 | 7024 | |
6654 | 7025 | $protocol = preg_match('~^\s*(HTTP/[12]\.\d)\s*$~i', $_SERVER['SERVER_PROTOCOL'], $matches) ? $matches[1] : 'HTTP/1.0'; |
6655 | 7026 | |
6656 | - if (!isset($statuses[$code]) && empty($status)) |
|
6657 | - header($protocol . ' 500 Internal Server Error'); |
|
6658 | - else |
|
6659 | - header($protocol . ' ' . $code . ' ' . (!empty($status) ? $status : $statuses[$code])); |
|
6660 | -} |
|
7027 | + if (!isset($statuses[$code]) && empty($status)) { |
|
7028 | + header($protocol . ' 500 Internal Server Error'); |
|
7029 | + } else { |
|
7030 | + header($protocol . ' ' . $code . ' ' . (!empty($status) ? $status : $statuses[$code])); |
|
7031 | + } |
|
7032 | + } |
|
6661 | 7033 | |
6662 | 7034 | ?> |
6663 | 7035 | \ No newline at end of file |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 4 |
12 | 12 | */ |
13 | 13 | |
14 | -if (!defined('SMF')) |
|
14 | +if (!defined('SMF')) { |
|
15 | 15 | die('Hacking attempt...'); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * PostgreSQL Cache API class |
@@ -49,8 +50,9 @@ discard block |
||
49 | 50 | |
50 | 51 | $result = pg_execute($db_connection, '', array('public', $db_prefix . 'cache')); |
51 | 52 | |
52 | - if (pg_affected_rows($result) === 0) |
|
53 | - pg_query($db_connection, 'CREATE UNLOGGED TABLE ' . $db_prefix . 'cache (key text, value text, ttl bigint, PRIMARY KEY (key))'); |
|
53 | + if (pg_affected_rows($result) === 0) { |
|
54 | + pg_query($db_connection, 'CREATE UNLOGGED TABLE ' . $db_prefix . 'cache (key text, value text, ttl bigint, PRIMARY KEY (key))'); |
|
55 | + } |
|
54 | 56 | } |
55 | 57 | |
56 | 58 | /** |
@@ -60,14 +62,16 @@ discard block |
||
60 | 62 | { |
61 | 63 | global $smcFunc, $db_connection; |
62 | 64 | |
63 | - if ($smcFunc['db_title'] !== 'PostgreSQL') |
|
64 | - return false; |
|
65 | + if ($smcFunc['db_title'] !== 'PostgreSQL') { |
|
66 | + return false; |
|
67 | + } |
|
65 | 68 | |
66 | 69 | $result = pg_query($db_connection, 'SHOW server_version_num'); |
67 | 70 | $res = pg_fetch_assoc($result); |
68 | 71 | |
69 | - if ($res['server_version_num'] < 90500) |
|
70 | - return false; |
|
72 | + if ($res['server_version_num'] < 90500) { |
|
73 | + return false; |
|
74 | + } |
|
71 | 75 | |
72 | 76 | return $test ? true : parent::isSupported(); |
73 | 77 | } |
@@ -81,13 +85,15 @@ discard block |
||
81 | 85 | |
82 | 86 | $ttl = time() - $ttl; |
83 | 87 | |
84 | - if (empty($this->pg_get_data_prep)) |
|
85 | - $this->pg_get_data_prep = pg_prepare($db_connection, 'smf_cache_get_data', 'SELECT value FROM ' . $db_prefix . 'cache WHERE key = $1 AND ttl >= $2 LIMIT 1'); |
|
88 | + if (empty($this->pg_get_data_prep)) { |
|
89 | + $this->pg_get_data_prep = pg_prepare($db_connection, 'smf_cache_get_data', 'SELECT value FROM ' . $db_prefix . 'cache WHERE key = $1 AND ttl >= $2 LIMIT 1'); |
|
90 | + } |
|
86 | 91 | |
87 | 92 | $result = pg_execute($db_connection, 'smf_cache_get_data', array($key, $ttl)); |
88 | 93 | |
89 | - if (pg_affected_rows($result) === 0) |
|
90 | - return null; |
|
94 | + if (pg_affected_rows($result) === 0) { |
|
95 | + return null; |
|
96 | + } |
|
91 | 97 | |
92 | 98 | $res = pg_fetch_assoc($result); |
93 | 99 | |
@@ -101,23 +107,26 @@ discard block |
||
101 | 107 | { |
102 | 108 | global $db_prefix, $db_connection; |
103 | 109 | |
104 | - if (!isset($value)) |
|
105 | - $value = ''; |
|
110 | + if (!isset($value)) { |
|
111 | + $value = ''; |
|
112 | + } |
|
106 | 113 | |
107 | 114 | $ttl = time() + $ttl; |
108 | 115 | |
109 | - if (empty($this->pg_put_data_prep)) |
|
110 | - $this->pg_put_data_prep = pg_prepare($db_connection, 'smf_cache_put_data', |
|
116 | + if (empty($this->pg_put_data_prep)) { |
|
117 | + $this->pg_put_data_prep = pg_prepare($db_connection, 'smf_cache_put_data', |
|
111 | 118 | 'INSERT INTO ' . $db_prefix . 'cache(key,value,ttl) VALUES($1,$2,$3) |
112 | 119 | ON CONFLICT(key) DO UPDATE SET value = excluded.value, ttl = excluded.ttl' |
113 | 120 | ); |
121 | + } |
|
114 | 122 | |
115 | 123 | $result = pg_execute($db_connection, 'smf_cache_put_data', array($key, $value, $ttl)); |
116 | 124 | |
117 | - if (pg_affected_rows($result) > 0) |
|
118 | - return true; |
|
119 | - else |
|
120 | - return false; |
|
125 | + if (pg_affected_rows($result) > 0) { |
|
126 | + return true; |
|
127 | + } else { |
|
128 | + return false; |
|
129 | + } |
|
121 | 130 | } |
122 | 131 | |
123 | 132 | /** |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | { |
166 | 166 | global $db_connection, $db_prefix; |
167 | 167 | |
168 | - pg_query($db_connection, 'CREATE LOCAL TEMP TABLE IF NOT EXISTS ' . $db_prefix . 'cache_tmp AS SELECT * FROM ' . $db_prefix . 'cache WHERE ttl >= ' . time() ); |
|
168 | + pg_query($db_connection, 'CREATE LOCAL TEMP TABLE IF NOT EXISTS ' . $db_prefix . 'cache_tmp AS SELECT * FROM ' . $db_prefix . 'cache WHERE ttl >= ' . time()); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | { |
190 | 190 | global $db_connection, $db_prefix; |
191 | 191 | |
192 | - pg_query($db_connection, 'INSERT INTO ' . $db_prefix . 'cache SELECT * FROM '. $db_prefix . 'cache_tmp ON CONFLICT DO NOTHING'); |
|
192 | + pg_query($db_connection, 'INSERT INTO ' . $db_prefix . 'cache SELECT * FROM ' . $db_prefix . 'cache_tmp ON CONFLICT DO NOTHING'); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 |
@@ -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 | * Activate an account. |
@@ -48,8 +49,9 @@ discard block |
||
48 | 49 | logAction('approve_member', array('member' => $memID), 'admin'); |
49 | 50 | |
50 | 51 | // If we are doing approval, update the stats for the member just in case. |
51 | - if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15))) |
|
52 | - updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0))); |
|
52 | + if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15))) { |
|
53 | + updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0))); |
|
54 | + } |
|
53 | 55 | |
54 | 56 | // Make sure we update the stats too. |
55 | 57 | updateStats('member', false); |
@@ -76,8 +78,9 @@ discard block |
||
76 | 78 | $issueErrors = array(); |
77 | 79 | |
78 | 80 | // Doesn't hurt to be overly cautious. |
79 | - if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning')) |
|
80 | - fatal_lang_error('no_access', false); |
|
81 | + if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning')) { |
|
82 | + fatal_lang_error('no_access', false); |
|
83 | + } |
|
81 | 84 | |
82 | 85 | // Get the base (errors related) stuff done. |
83 | 86 | loadLanguage('Errors'); |
@@ -135,16 +138,18 @@ discard block |
||
135 | 138 | |
136 | 139 | // This cannot be empty! |
137 | 140 | $_POST['warn_reason'] = isset($_POST['warn_reason']) ? trim($_POST['warn_reason']) : ''; |
138 | - if ($_POST['warn_reason'] == '' && !$context['user']['is_owner']) |
|
139 | - $issueErrors[] = 'warning_no_reason'; |
|
141 | + if ($_POST['warn_reason'] == '' && !$context['user']['is_owner']) { |
|
142 | + $issueErrors[] = 'warning_no_reason'; |
|
143 | + } |
|
140 | 144 | $_POST['warn_reason'] = $smcFunc['htmlspecialchars']($_POST['warn_reason']); |
141 | 145 | |
142 | 146 | $_POST['warning_level'] = (int) $_POST['warning_level']; |
143 | 147 | $_POST['warning_level'] = max(0, min(100, $_POST['warning_level'])); |
144 | - if ($_POST['warning_level'] < $context['min_allowed']) |
|
145 | - $_POST['warning_level'] = $context['min_allowed']; |
|
146 | - elseif ($_POST['warning_level'] > $context['max_allowed']) |
|
147 | - $_POST['warning_level'] = $context['max_allowed']; |
|
148 | + if ($_POST['warning_level'] < $context['min_allowed']) { |
|
149 | + $_POST['warning_level'] = $context['min_allowed']; |
|
150 | + } elseif ($_POST['warning_level'] > $context['max_allowed']) { |
|
151 | + $_POST['warning_level'] = $context['max_allowed']; |
|
152 | + } |
|
148 | 153 | |
149 | 154 | // Do we actually have to issue them with a PM? |
150 | 155 | $id_notice = 0; |
@@ -152,8 +157,9 @@ discard block |
||
152 | 157 | { |
153 | 158 | $_POST['warn_sub'] = trim($_POST['warn_sub']); |
154 | 159 | $_POST['warn_body'] = trim($_POST['warn_body']); |
155 | - if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) |
|
156 | - $issueErrors[] = 'warning_notify_blank'; |
|
160 | + if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) { |
|
161 | + $issueErrors[] = 'warning_notify_blank'; |
|
162 | + } |
|
157 | 163 | // Send the PM? |
158 | 164 | else |
159 | 165 | { |
@@ -190,8 +196,8 @@ discard block |
||
190 | 196 | if (empty($issueErrors)) |
191 | 197 | { |
192 | 198 | // Log what we've done! |
193 | - if (!$context['user']['is_owner']) |
|
194 | - $smcFunc['db_insert']('', |
|
199 | + if (!$context['user']['is_owner']) { |
|
200 | + $smcFunc['db_insert']('', |
|
195 | 201 | '{db_prefix}log_comments', |
196 | 202 | array( |
197 | 203 | 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int', 'recipient_name' => 'string-255', |
@@ -203,14 +209,14 @@ discard block |
||
203 | 209 | ), |
204 | 210 | array('id_comment') |
205 | 211 | ); |
212 | + } |
|
206 | 213 | |
207 | 214 | // Make the change. |
208 | 215 | updateMemberData($memID, array('warning' => $_POST['warning_level'])); |
209 | 216 | |
210 | 217 | // Leave a lovely message. |
211 | 218 | $context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : $txt['profile_warning_success']; |
212 | - } |
|
213 | - else |
|
219 | + } else |
|
214 | 220 | { |
215 | 221 | // Try to remember some bits. |
216 | 222 | $context['warning_data'] = array( |
@@ -229,8 +235,9 @@ discard block |
||
229 | 235 | { |
230 | 236 | $warning_body = !empty($_POST['warn_body']) ? trim(censorText($_POST['warn_body'])) : ''; |
231 | 237 | $context['preview_subject'] = !empty($_POST['warn_sub']) ? trim($smcFunc['htmlspecialchars']($_POST['warn_sub'])) : ''; |
232 | - if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) |
|
233 | - $issueErrors[] = 'warning_notify_blank'; |
|
238 | + if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) { |
|
239 | + $issueErrors[] = 'warning_notify_blank'; |
|
240 | + } |
|
234 | 241 | |
235 | 242 | if (!empty($_POST['warn_body'])) |
236 | 243 | { |
@@ -254,8 +261,9 @@ discard block |
||
254 | 261 | { |
255 | 262 | // Fill in the suite of errors. |
256 | 263 | $context['post_errors'] = array(); |
257 | - foreach ($issueErrors as $error) |
|
258 | - $context['post_errors'][] = $txt[$error]; |
|
264 | + foreach ($issueErrors as $error) { |
|
265 | + $context['post_errors'][] = $txt[$error]; |
|
266 | + } |
|
259 | 267 | } |
260 | 268 | |
261 | 269 | |
@@ -272,9 +280,10 @@ discard block |
||
272 | 280 | $modSettings['warning_mute'] => $txt['profile_warning_effect_mute'], |
273 | 281 | ); |
274 | 282 | $context['current_level'] = 0; |
275 | - foreach ($context['level_effects'] as $limit => $dummy) |
|
276 | - if ($context['member']['warning'] >= $limit) |
|
283 | + foreach ($context['level_effects'] as $limit => $dummy) { |
|
284 | + if ($context['member']['warning'] >= $limit) |
|
277 | 285 | $context['current_level'] = $limit; |
286 | + } |
|
278 | 287 | |
279 | 288 | $listOptions = array( |
280 | 289 | 'id' => 'view_warnings', |
@@ -337,11 +346,12 @@ discard block |
||
337 | 346 | ' . $warning['reason'] . ' |
338 | 347 | </div>'; |
339 | 348 | |
340 | - if (!empty($warning['id_notice'])) |
|
341 | - $ret .= ' |
|
349 | + if (!empty($warning['id_notice'])) { |
|
350 | + $ret .= ' |
|
342 | 351 | <div class="floatright"> |
343 | 352 | <a href="' . $scripturl . '?action=moderate;area=notice;nid=' . $warning['id_notice'] . '" onclick="window.open(this.href, \'\', \'scrollbars=yes,resizable=yes,width=400,height=250\');return false;" target="_blank" rel="noopener" title="' . $txt['profile_warning_previous_notice'] . '"><span class="generic_icons filter centericon"></span></a> |
344 | 353 | </div>'; |
354 | + } |
|
345 | 355 | |
346 | 356 | return $ret; |
347 | 357 | }, |
@@ -413,8 +423,9 @@ discard block |
||
413 | 423 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
414 | 424 | { |
415 | 425 | // If we're not warning for a message skip any that are. |
416 | - if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false) |
|
417 | - continue; |
|
426 | + if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false) { |
|
427 | + continue; |
|
428 | + } |
|
418 | 429 | |
419 | 430 | $context['notification_templates'][] = array( |
420 | 431 | 'title' => $row['template_title'], |
@@ -424,16 +435,18 @@ discard block |
||
424 | 435 | $smcFunc['db_free_result']($request); |
425 | 436 | |
426 | 437 | // Setup the "default" templates. |
427 | - foreach (array('spamming', 'offence', 'insulting') as $type) |
|
428 | - $context['notification_templates'][] = array( |
|
438 | + foreach (array('spamming', 'offence', 'insulting') as $type) { |
|
439 | + $context['notification_templates'][] = array( |
|
429 | 440 | 'title' => $txt['profile_warning_notify_title_' . $type], |
430 | 441 | 'body' => sprintf($txt['profile_warning_notify_template_outline' . (!empty($context['warning_for_message']) ? '_post' : '')], $txt['profile_warning_notify_for_' . $type]), |
431 | 442 | ); |
443 | + } |
|
432 | 444 | |
433 | 445 | // Replace all the common variables in the templates. |
434 | - foreach ($context['notification_templates'] as $k => $name) |
|
435 | - $context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team'])); |
|
436 | -} |
|
446 | + foreach ($context['notification_templates'] as $k => $name) { |
|
447 | + $context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team'])); |
|
448 | + } |
|
449 | + } |
|
437 | 450 | |
438 | 451 | /** |
439 | 452 | * Get the number of warnings a user has. Callback for $listOptions['get_count'] in issueWarning() |
@@ -517,10 +530,11 @@ discard block |
||
517 | 530 | { |
518 | 531 | global $txt, $context, $modSettings, $cur_profile; |
519 | 532 | |
520 | - if (!$context['user']['is_owner']) |
|
521 | - isAllowedTo('profile_remove_any'); |
|
522 | - elseif (!allowedTo('profile_remove_any')) |
|
523 | - isAllowedTo('profile_remove_own'); |
|
533 | + if (!$context['user']['is_owner']) { |
|
534 | + isAllowedTo('profile_remove_any'); |
|
535 | + } elseif (!allowedTo('profile_remove_any')) { |
|
536 | + isAllowedTo('profile_remove_own'); |
|
537 | + } |
|
524 | 538 | |
525 | 539 | // Permissions for removing stuff... |
526 | 540 | $context['can_delete_posts'] = !$context['user']['is_owner'] && allowedTo('moderate_forum'); |
@@ -547,10 +561,11 @@ discard block |
||
547 | 561 | |
548 | 562 | // @todo Add a way to delete pms as well? |
549 | 563 | |
550 | - if (!$context['user']['is_owner']) |
|
551 | - isAllowedTo('profile_remove_any'); |
|
552 | - elseif (!allowedTo('profile_remove_any')) |
|
553 | - isAllowedTo('profile_remove_own'); |
|
564 | + if (!$context['user']['is_owner']) { |
|
565 | + isAllowedTo('profile_remove_any'); |
|
566 | + } elseif (!allowedTo('profile_remove_any')) { |
|
567 | + isAllowedTo('profile_remove_own'); |
|
568 | + } |
|
554 | 569 | |
555 | 570 | checkSession(); |
556 | 571 | |
@@ -576,8 +591,9 @@ discard block |
||
576 | 591 | list ($another) = $smcFunc['db_fetch_row']($request); |
577 | 592 | $smcFunc['db_free_result']($request); |
578 | 593 | |
579 | - if (empty($another)) |
|
580 | - fatal_lang_error('at_least_one_admin', 'critical'); |
|
594 | + if (empty($another)) { |
|
595 | + fatal_lang_error('at_least_one_admin', 'critical'); |
|
596 | + } |
|
581 | 597 | } |
582 | 598 | |
583 | 599 | // This file is needed for the deleteMembers function. |
@@ -656,8 +672,9 @@ discard block |
||
656 | 672 | ) |
657 | 673 | ); |
658 | 674 | $topicIDs = array(); |
659 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
660 | - $topicIDs[] = $row['id_topic']; |
|
675 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
676 | + $topicIDs[] = $row['id_topic']; |
|
677 | + } |
|
661 | 678 | $smcFunc['db_free_result']($request); |
662 | 679 | |
663 | 680 | // Actually remove the topics. Ignore recycling if we want to perma-delete things... |
@@ -680,8 +697,9 @@ discard block |
||
680 | 697 | // This could take a while... but ya know it's gonna be worth it in the end. |
681 | 698 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
682 | 699 | { |
683 | - if (function_exists('apache_reset_timeout')) |
|
684 | - @apache_reset_timeout(); |
|
700 | + if (function_exists('apache_reset_timeout')) { |
|
701 | + @apache_reset_timeout(); |
|
702 | + } |
|
685 | 703 | |
686 | 704 | removeMessage($row['id_msg']); |
687 | 705 | } |
@@ -689,8 +707,9 @@ discard block |
||
689 | 707 | } |
690 | 708 | |
691 | 709 | // Only delete this poor members account if they are actually being booted out of camp. |
692 | - if (isset($_POST['deleteAccount'])) |
|
693 | - deleteMembers($memID); |
|
710 | + if (isset($_POST['deleteAccount'])) { |
|
711 | + deleteMembers($memID); |
|
712 | + } |
|
694 | 713 | } |
695 | 714 | // Do they need approval to delete? |
696 | 715 | elseif (!empty($modSettings['approveAccountDeletion']) && !allowedTo('moderate_forum')) |
@@ -741,18 +760,18 @@ discard block |
||
741 | 760 | { |
742 | 761 | foreach ($costs as $duration => $cost) |
743 | 762 | { |
744 | - if ($cost != 0) |
|
745 | - $cost_array[$duration] = $cost; |
|
763 | + if ($cost != 0) { |
|
764 | + $cost_array[$duration] = $cost; |
|
765 | + } |
|
746 | 766 | } |
747 | - } |
|
748 | - else |
|
767 | + } else |
|
749 | 768 | { |
750 | 769 | $cost_array['fixed'] = $costs['fixed']; |
751 | 770 | } |
752 | 771 | |
753 | - if (empty($cost_array)) |
|
754 | - unset($context['subscriptions'][$id]); |
|
755 | - else |
|
772 | + if (empty($cost_array)) { |
|
773 | + unset($context['subscriptions'][$id]); |
|
774 | + } else |
|
756 | 775 | { |
757 | 776 | $context['subscriptions'][$id]['member'] = 0; |
758 | 777 | $context['subscriptions'][$id]['subscribed'] = false; |
@@ -765,13 +784,15 @@ discard block |
||
765 | 784 | foreach ($gateways as $id => $gateway) |
766 | 785 | { |
767 | 786 | $gateways[$id] = new $gateway['display_class'](); |
768 | - if (!$gateways[$id]->gatewayEnabled()) |
|
769 | - unset($gateways[$id]); |
|
787 | + if (!$gateways[$id]->gatewayEnabled()) { |
|
788 | + unset($gateways[$id]); |
|
789 | + } |
|
770 | 790 | } |
771 | 791 | |
772 | 792 | // No gateways yet? |
773 | - if (empty($gateways)) |
|
774 | - fatal_error($txt['paid_admin_not_setup_gateway']); |
|
793 | + if (empty($gateways)) { |
|
794 | + fatal_error($txt['paid_admin_not_setup_gateway']); |
|
795 | + } |
|
775 | 796 | |
776 | 797 | // Get the current subscriptions. |
777 | 798 | $request = $smcFunc['db_query']('', ' |
@@ -786,8 +807,9 @@ discard block |
||
786 | 807 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
787 | 808 | { |
788 | 809 | // The subscription must exist! |
789 | - if (!isset($context['subscriptions'][$row['id_subscribe']])) |
|
790 | - continue; |
|
810 | + if (!isset($context['subscriptions'][$row['id_subscribe']])) { |
|
811 | + continue; |
|
812 | + } |
|
791 | 813 | |
792 | 814 | $context['current'][$row['id_subscribe']] = array( |
793 | 815 | 'id' => $row['id_sublog'], |
@@ -801,8 +823,9 @@ discard block |
||
801 | 823 | 'status_text' => $row['status'] == 0 ? ($row['payments_pending'] ? $txt['paid_pending'] : $txt['paid_finished']) : $txt['paid_active'], |
802 | 824 | ); |
803 | 825 | |
804 | - if ($row['status'] == 1) |
|
805 | - $context['subscriptions'][$row['id_subscribe']]['subscribed'] = true; |
|
826 | + if ($row['status'] == 1) { |
|
827 | + $context['subscriptions'][$row['id_subscribe']]['subscribed'] = true; |
|
828 | + } |
|
806 | 829 | } |
807 | 830 | $smcFunc['db_free_result']($request); |
808 | 831 | |
@@ -853,21 +876,25 @@ discard block |
||
853 | 876 | if (isset($_GET['confirm']) && isset($_POST['sub_id']) && is_array($_POST['sub_id'])) |
854 | 877 | { |
855 | 878 | // Hopefully just one. |
856 | - foreach ($_POST['sub_id'] as $k => $v) |
|
857 | - $ID_SUB = (int) $k; |
|
879 | + foreach ($_POST['sub_id'] as $k => $v) { |
|
880 | + $ID_SUB = (int) $k; |
|
881 | + } |
|
858 | 882 | |
859 | - if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0) |
|
860 | - fatal_lang_error('paid_sub_not_active'); |
|
883 | + if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0) { |
|
884 | + fatal_lang_error('paid_sub_not_active'); |
|
885 | + } |
|
861 | 886 | |
862 | 887 | // Simplify... |
863 | 888 | $context['sub'] = $context['subscriptions'][$ID_SUB]; |
864 | 889 | $period = 'xx'; |
865 | - if ($context['sub']['flexible']) |
|
866 | - $period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx'; |
|
890 | + if ($context['sub']['flexible']) { |
|
891 | + $period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx'; |
|
892 | + } |
|
867 | 893 | |
868 | 894 | // Check we have a valid cost. |
869 | - if ($context['sub']['flexible'] && $period == 'xx') |
|
870 | - fatal_lang_error('paid_sub_not_active'); |
|
895 | + if ($context['sub']['flexible'] && $period == 'xx') { |
|
896 | + fatal_lang_error('paid_sub_not_active'); |
|
897 | + } |
|
871 | 898 | |
872 | 899 | // Sort out the cost/currency. |
873 | 900 | $context['currency'] = $modSettings['paid_currency_code']; |
@@ -880,8 +907,7 @@ discard block |
||
880 | 907 | $context['cost'] = sprintf($modSettings['paid_currency_symbol'], $context['value']) . '/' . $txt[$_POST['cur'][$ID_SUB]]; |
881 | 908 | // The period value for paypal. |
882 | 909 | $context['paypal_period'] = strtoupper(substr($_POST['cur'][$ID_SUB], 0, 1)); |
883 | - } |
|
884 | - else |
|
910 | + } else |
|
885 | 911 | { |
886 | 912 | // Real cost... |
887 | 913 | $context['value'] = $context['sub']['costs']['fixed']; |
@@ -898,13 +924,15 @@ discard block |
||
898 | 924 | foreach ($gateways as $id => $gateway) |
899 | 925 | { |
900 | 926 | $fields = $gateways[$id]->fetchGatewayFields($context['sub']['id'] . '+' . $memID, $context['sub'], $context['value'], $period, $scripturl . '?action=profile;u=' . $memID . ';area=subscriptions;sub_id=' . $context['sub']['id'] . ';done'); |
901 | - if (!empty($fields['form'])) |
|
902 | - $context['gateways'][] = $fields; |
|
927 | + if (!empty($fields['form'])) { |
|
928 | + $context['gateways'][] = $fields; |
|
929 | + } |
|
903 | 930 | } |
904 | 931 | |
905 | 932 | // Bugger?! |
906 | - if (empty($context['gateways'])) |
|
907 | - fatal_error($txt['paid_admin_not_setup_gateway']); |
|
933 | + if (empty($context['gateways'])) { |
|
934 | + fatal_error($txt['paid_admin_not_setup_gateway']); |
|
935 | + } |
|
908 | 936 | |
909 | 937 | // Now we are going to assume they want to take this out ;) |
910 | 938 | $new_data = array($context['sub']['id'], $context['value'], $period, 'prepay'); |
@@ -912,16 +940,19 @@ discard block |
||
912 | 940 | { |
913 | 941 | // What are the details like? |
914 | 942 | $current_pending = array(); |
915 | - if ($context['current'][$context['sub']['id']]['pending_details'] != '') |
|
916 | - $current_pending = $smcFunc['json_decode']($context['current'][$context['sub']['id']]['pending_details'], true); |
|
943 | + if ($context['current'][$context['sub']['id']]['pending_details'] != '') { |
|
944 | + $current_pending = $smcFunc['json_decode']($context['current'][$context['sub']['id']]['pending_details'], true); |
|
945 | + } |
|
917 | 946 | // Don't get silly. |
918 | - if (count($current_pending) > 9) |
|
919 | - $current_pending = array(); |
|
947 | + if (count($current_pending) > 9) { |
|
948 | + $current_pending = array(); |
|
949 | + } |
|
920 | 950 | $pending_count = 0; |
921 | 951 | // Only record real pending payments as will otherwise confuse the admin! |
922 | - foreach ($current_pending as $pending) |
|
923 | - if ($pending[3] == 'payback') |
|
952 | + foreach ($current_pending as $pending) { |
|
953 | + if ($pending[3] == 'payback') |
|
924 | 954 | $pending_count++; |
955 | + } |
|
925 | 956 | |
926 | 957 | if (!in_array($new_data, $current_pending)) |
927 | 958 | { |
@@ -966,9 +997,9 @@ discard block |
||
966 | 997 | |
967 | 998 | // Quit. |
968 | 999 | return; |
1000 | + } else { |
|
1001 | + $context['sub_template'] = 'user_subscription'; |
|
1002 | + } |
|
969 | 1003 | } |
970 | - else |
|
971 | - $context['sub_template'] = 'user_subscription'; |
|
972 | -} |
|
973 | 1004 | |
974 | 1005 | ?> |
975 | 1006 | \ No newline at end of file |
@@ -1697,8 +1697,7 @@ discard block |
||
1697 | 1697 | updateStats('topic'); |
1698 | 1698 | |
1699 | 1699 | // This function is needed to do the updateStats('subject') call. |
1700 | - $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : |
|
1701 | - function($string){ |
|
1700 | + $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) { |
|
1702 | 1701 | global $sourcedir; |
1703 | 1702 | if (function_exists('mb_strtolower')) |
1704 | 1703 | return mb_strtolower($string, 'UTF-8'); |
@@ -1767,7 +1766,7 @@ discard block |
||
1767 | 1766 | if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}') |
1768 | 1767 | { |
1769 | 1768 | // Set the ten lines to nothing. |
1770 | - for ($j=0; $j < 10; $j++) |
|
1769 | + for ($j = 0; $j < 10; $j++) |
|
1771 | 1770 | $settingsArray[$i++] = ''; |
1772 | 1771 | |
1773 | 1772 | continue; |
@@ -20,8 +20,9 @@ discard block |
||
20 | 20 | // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;"> |
21 | 21 | |
22 | 22 | // Let's pull in useful classes |
23 | -if (!defined('SMF')) |
|
23 | +if (!defined('SMF')) { |
|
24 | 24 | define('SMF', 1); |
25 | +} |
|
25 | 26 | |
26 | 27 | require_once('Sources/Class-Package.php'); |
27 | 28 | |
@@ -63,10 +64,11 @@ discard block |
||
63 | 64 | |
64 | 65 | list ($charcode) = pg_fetch_row($request); |
65 | 66 | |
66 | - if ($charcode == 'UTF8') |
|
67 | - return true; |
|
68 | - else |
|
69 | - return false; |
|
67 | + if ($charcode == 'UTF8') { |
|
68 | + return true; |
|
69 | + } else { |
|
70 | + return false; |
|
71 | + } |
|
70 | 72 | }, |
71 | 73 | 'utf8_version' => '8.0', |
72 | 74 | 'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;', |
@@ -76,12 +78,14 @@ discard block |
||
76 | 78 | $value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value); |
77 | 79 | |
78 | 80 | // Is it reserved? |
79 | - if ($value == 'pg_') |
|
80 | - return $txt['error_db_prefix_reserved']; |
|
81 | + if ($value == 'pg_') { |
|
82 | + return $txt['error_db_prefix_reserved']; |
|
83 | + } |
|
81 | 84 | |
82 | 85 | // Is the prefix numeric? |
83 | - if (preg_match('~^\d~', $value)) |
|
84 | - return $txt['error_db_prefix_numeric']; |
|
86 | + if (preg_match('~^\d~', $value)) { |
|
87 | + return $txt['error_db_prefix_numeric']; |
|
88 | + } |
|
85 | 89 | |
86 | 90 | return true; |
87 | 91 | }, |
@@ -128,10 +132,11 @@ discard block |
||
128 | 132 | $incontext['skip'] = false; |
129 | 133 | |
130 | 134 | // Call the step and if it returns false that means pause! |
131 | - if (function_exists($step[2]) && $step[2]() === false) |
|
132 | - break; |
|
133 | - elseif (function_exists($step[2])) |
|
134 | - $incontext['current_step']++; |
|
135 | + if (function_exists($step[2]) && $step[2]() === false) { |
|
136 | + break; |
|
137 | + } elseif (function_exists($step[2])) { |
|
138 | + $incontext['current_step']++; |
|
139 | + } |
|
135 | 140 | |
136 | 141 | // No warnings pass on. |
137 | 142 | $incontext['warning'] = ''; |
@@ -147,8 +152,9 @@ discard block |
||
147 | 152 | global $databases; |
148 | 153 | |
149 | 154 | // Just so people using older versions of PHP aren't left in the cold. |
150 | - if (!isset($_SERVER['PHP_SELF'])) |
|
151 | - $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php'; |
|
155 | + if (!isset($_SERVER['PHP_SELF'])) { |
|
156 | + $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php'; |
|
157 | + } |
|
152 | 158 | |
153 | 159 | // Enable error reporting for fatal errors. |
154 | 160 | error_reporting(E_ERROR | E_PARSE); |
@@ -164,21 +170,23 @@ discard block |
||
164 | 170 | { |
165 | 171 | ob_start(); |
166 | 172 | |
167 | - if (ini_get('session.save_handler') == 'user') |
|
168 | - @ini_set('session.save_handler', 'files'); |
|
169 | - if (function_exists('session_start')) |
|
170 | - @session_start(); |
|
171 | - } |
|
172 | - else |
|
173 | + if (ini_get('session.save_handler') == 'user') { |
|
174 | + @ini_set('session.save_handler', 'files'); |
|
175 | + } |
|
176 | + if (function_exists('session_start')) { |
|
177 | + @session_start(); |
|
178 | + } |
|
179 | + } else |
|
173 | 180 | { |
174 | 181 | ob_start('ob_gzhandler'); |
175 | 182 | |
176 | - if (ini_get('session.save_handler') == 'user') |
|
177 | - @ini_set('session.save_handler', 'files'); |
|
183 | + if (ini_get('session.save_handler') == 'user') { |
|
184 | + @ini_set('session.save_handler', 'files'); |
|
185 | + } |
|
178 | 186 | session_start(); |
179 | 187 | |
180 | - if (!headers_sent()) |
|
181 | - echo '<!DOCTYPE html> |
|
188 | + if (!headers_sent()) { |
|
189 | + echo '<!DOCTYPE html> |
|
182 | 190 | <html> |
183 | 191 | <head> |
184 | 192 | <title>', htmlspecialchars($_GET['pass_string']), '</title> |
@@ -187,14 +195,16 @@ discard block |
||
187 | 195 | <strong>', htmlspecialchars($_GET['pass_string']), '</strong> |
188 | 196 | </body> |
189 | 197 | </html>'; |
198 | + } |
|
190 | 199 | exit; |
191 | 200 | } |
192 | 201 | |
193 | 202 | // Add slashes, as long as they aren't already being added. |
194 | - if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) |
|
195 | - foreach ($_POST as $k => $v) |
|
203 | + if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) { |
|
204 | + foreach ($_POST as $k => $v) |
|
196 | 205 | if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false) |
197 | 206 | $_POST[$k] = addslashes($v); |
207 | + } |
|
198 | 208 | |
199 | 209 | // This is really quite simple; if ?delete is on the URL, delete the installer... |
200 | 210 | if (isset($_GET['delete'])) |
@@ -215,8 +225,7 @@ discard block |
||
215 | 225 | $ftp->close(); |
216 | 226 | |
217 | 227 | unset($_SESSION['installer_temp_ftp']); |
218 | - } |
|
219 | - else |
|
228 | + } else |
|
220 | 229 | { |
221 | 230 | @unlink(__FILE__); |
222 | 231 | |
@@ -230,10 +239,11 @@ discard block |
||
230 | 239 | // Now just redirect to a blank.png... |
231 | 240 | $secure = false; |
232 | 241 | |
233 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
234 | - $secure = true; |
|
235 | - 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') |
|
236 | - $secure = true; |
|
242 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
243 | + $secure = true; |
|
244 | + } 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') { |
|
245 | + $secure = true; |
|
246 | + } |
|
237 | 247 | |
238 | 248 | header('location: http' . ($secure ? 's' : '') . '://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png'); |
239 | 249 | exit; |
@@ -244,10 +254,11 @@ discard block |
||
244 | 254 | { |
245 | 255 | // Get PHP's default timezone, if set |
246 | 256 | $ini_tz = ini_get('date.timezone'); |
247 | - if (!empty($ini_tz)) |
|
248 | - $timezone_id = $ini_tz; |
|
249 | - else |
|
250 | - $timezone_id = ''; |
|
257 | + if (!empty($ini_tz)) { |
|
258 | + $timezone_id = $ini_tz; |
|
259 | + } else { |
|
260 | + $timezone_id = ''; |
|
261 | + } |
|
251 | 262 | |
252 | 263 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
253 | 264 | if (!in_array($timezone_id, timezone_identifiers_list())) |
@@ -277,8 +288,9 @@ discard block |
||
277 | 288 | $dir = dir(dirname(__FILE__) . '/Themes/default/languages'); |
278 | 289 | while ($entry = $dir->read()) |
279 | 290 | { |
280 | - if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') |
|
281 | - $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
291 | + if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') { |
|
292 | + $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
293 | + } |
|
282 | 294 | } |
283 | 295 | $dir->close(); |
284 | 296 | } |
@@ -325,10 +337,11 @@ discard block |
||
325 | 337 | } |
326 | 338 | |
327 | 339 | // Override the language file? |
328 | - if (isset($_GET['lang_file'])) |
|
329 | - $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
330 | - elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) |
|
331 | - $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
340 | + if (isset($_GET['lang_file'])) { |
|
341 | + $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
342 | + } elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) { |
|
343 | + $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
344 | + } |
|
332 | 345 | |
333 | 346 | // Make sure it exists, if it doesn't reset it. |
334 | 347 | if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang'])) |
@@ -337,8 +350,9 @@ discard block |
||
337 | 350 | list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
338 | 351 | |
339 | 352 | // If we have english and some other language, use the other language. We Americans hate english :P. |
340 | - if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) |
|
341 | - list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
353 | + if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) { |
|
354 | + list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
355 | + } |
|
342 | 356 | } |
343 | 357 | |
344 | 358 | // And now include the actual language file itself. |
@@ -355,15 +369,18 @@ discard block |
||
355 | 369 | global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings, $db_port; |
356 | 370 | global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist, $db_mb4; |
357 | 371 | |
358 | - if (empty($sourcedir)) |
|
359 | - $sourcedir = dirname(__FILE__) . '/Sources'; |
|
372 | + if (empty($sourcedir)) { |
|
373 | + $sourcedir = dirname(__FILE__) . '/Sources'; |
|
374 | + } |
|
360 | 375 | |
361 | 376 | // Need this to check whether we need the database password. |
362 | 377 | require(dirname(__FILE__) . '/Settings.php'); |
363 | - if (!defined('SMF')) |
|
364 | - define('SMF', 1); |
|
365 | - if (empty($smcFunc)) |
|
366 | - $smcFunc = array(); |
|
378 | + if (!defined('SMF')) { |
|
379 | + define('SMF', 1); |
|
380 | + } |
|
381 | + if (empty($smcFunc)) { |
|
382 | + $smcFunc = array(); |
|
383 | + } |
|
367 | 384 | |
368 | 385 | $modSettings['disableQueryCheck'] = true; |
369 | 386 | |
@@ -374,14 +391,17 @@ discard block |
||
374 | 391 | |
375 | 392 | $options = array('persist' => $db_persist); |
376 | 393 | |
377 | - if (!empty($db_port)) |
|
378 | - $options['port'] = $db_port; |
|
394 | + if (!empty($db_port)) { |
|
395 | + $options['port'] = $db_port; |
|
396 | + } |
|
379 | 397 | |
380 | - if (!empty($db_mb4)) |
|
381 | - $options['db_mb4'] = $db_mb4; |
|
398 | + if (!empty($db_mb4)) { |
|
399 | + $options['db_mb4'] = $db_mb4; |
|
400 | + } |
|
382 | 401 | |
383 | - if (!$db_connection) |
|
384 | - $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options); |
|
402 | + if (!$db_connection) { |
|
403 | + $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options); |
|
404 | + } |
|
385 | 405 | } |
386 | 406 | } |
387 | 407 | |
@@ -409,8 +429,9 @@ discard block |
||
409 | 429 | // @todo REMOVE THIS!! |
410 | 430 | else |
411 | 431 | { |
412 | - if (function_exists('doStep' . $_GET['step'])) |
|
413 | - call_user_func('doStep' . $_GET['step']); |
|
432 | + if (function_exists('doStep' . $_GET['step'])) { |
|
433 | + call_user_func('doStep' . $_GET['step']); |
|
434 | + } |
|
414 | 435 | } |
415 | 436 | // Show the footer. |
416 | 437 | template_install_below(); |
@@ -428,8 +449,9 @@ discard block |
||
428 | 449 | $incontext['sub_template'] = 'welcome_message'; |
429 | 450 | |
430 | 451 | // Done the submission? |
431 | - if (isset($_POST['contbutt'])) |
|
432 | - return true; |
|
452 | + if (isset($_POST['contbutt'])) { |
|
453 | + return true; |
|
454 | + } |
|
433 | 455 | |
434 | 456 | // See if we think they have already installed it? |
435 | 457 | if (is_readable(dirname(__FILE__) . '/Settings.php')) |
@@ -437,14 +459,17 @@ discard block |
||
437 | 459 | $probably_installed = 0; |
438 | 460 | foreach (file(dirname(__FILE__) . '/Settings.php') as $line) |
439 | 461 | { |
440 | - if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) |
|
441 | - $probably_installed++; |
|
442 | - if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) |
|
443 | - $probably_installed++; |
|
462 | + if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) { |
|
463 | + $probably_installed++; |
|
464 | + } |
|
465 | + if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) { |
|
466 | + $probably_installed++; |
|
467 | + } |
|
444 | 468 | } |
445 | 469 | |
446 | - if ($probably_installed == 2) |
|
447 | - $incontext['warning'] = $txt['error_already_installed']; |
|
470 | + if ($probably_installed == 2) { |
|
471 | + $incontext['warning'] = $txt['error_already_installed']; |
|
472 | + } |
|
448 | 473 | } |
449 | 474 | |
450 | 475 | // Is some database support even compiled in? |
@@ -459,45 +484,54 @@ discard block |
||
459 | 484 | $databases[$key]['supported'] = false; |
460 | 485 | $notFoundSQLFile = true; |
461 | 486 | $txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql'); |
487 | + } else { |
|
488 | + $incontext['supported_databases'][] = $db; |
|
462 | 489 | } |
463 | - else |
|
464 | - $incontext['supported_databases'][] = $db; |
|
465 | 490 | } |
466 | 491 | } |
467 | 492 | |
468 | 493 | // Check the PHP version. |
469 | - if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) |
|
470 | - $error = 'error_php_too_low'; |
|
494 | + if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) { |
|
495 | + $error = 'error_php_too_low'; |
|
496 | + } |
|
471 | 497 | // Make sure we have a supported database |
472 | - elseif (empty($incontext['supported_databases'])) |
|
473 | - $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing'; |
|
498 | + elseif (empty($incontext['supported_databases'])) { |
|
499 | + $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing'; |
|
500 | + } |
|
474 | 501 | // How about session support? Some crazy sysadmin remove it? |
475 | - elseif (!function_exists('session_start')) |
|
476 | - $error = 'error_session_missing'; |
|
502 | + elseif (!function_exists('session_start')) { |
|
503 | + $error = 'error_session_missing'; |
|
504 | + } |
|
477 | 505 | // Make sure they uploaded all the files. |
478 | - elseif (!file_exists(dirname(__FILE__) . '/index.php')) |
|
479 | - $error = 'error_missing_files'; |
|
506 | + elseif (!file_exists(dirname(__FILE__) . '/index.php')) { |
|
507 | + $error = 'error_missing_files'; |
|
508 | + } |
|
480 | 509 | // Very simple check on the session.save_path for Windows. |
481 | 510 | // @todo Move this down later if they don't use database-driven sessions? |
482 | - elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') |
|
483 | - $error = 'error_session_save_path'; |
|
511 | + elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') { |
|
512 | + $error = 'error_session_save_path'; |
|
513 | + } |
|
484 | 514 | |
485 | 515 | // Since each of the three messages would look the same, anyway... |
486 | - if (isset($error)) |
|
487 | - $incontext['error'] = $txt[$error]; |
|
516 | + if (isset($error)) { |
|
517 | + $incontext['error'] = $txt[$error]; |
|
518 | + } |
|
488 | 519 | |
489 | 520 | // Mod_security blocks everything that smells funny. Let SMF handle security. |
490 | - if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) |
|
491 | - $incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again']; |
|
521 | + if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) { |
|
522 | + $incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again']; |
|
523 | + } |
|
492 | 524 | |
493 | 525 | // Confirm mbstring is loaded... |
494 | - if (!extension_loaded('mbstring')) |
|
495 | - $incontext['error'] = $txt['install_no_mbstring']; |
|
526 | + if (!extension_loaded('mbstring')) { |
|
527 | + $incontext['error'] = $txt['install_no_mbstring']; |
|
528 | + } |
|
496 | 529 | |
497 | 530 | // Check for https stream support. |
498 | 531 | $supported_streams = stream_get_wrappers(); |
499 | - if (!in_array('https', $supported_streams)) |
|
500 | - $incontext['warning'] = $txt['install_no_https']; |
|
532 | + if (!in_array('https', $supported_streams)) { |
|
533 | + $incontext['warning'] = $txt['install_no_https']; |
|
534 | + } |
|
501 | 535 | |
502 | 536 | return false; |
503 | 537 | } |
@@ -522,12 +556,14 @@ discard block |
||
522 | 556 | 'Settings_bak.php', |
523 | 557 | ); |
524 | 558 | |
525 | - foreach ($incontext['detected_languages'] as $lang => $temp) |
|
526 | - $extra_files[] = 'Themes/default/languages/' . $lang; |
|
559 | + foreach ($incontext['detected_languages'] as $lang => $temp) { |
|
560 | + $extra_files[] = 'Themes/default/languages/' . $lang; |
|
561 | + } |
|
527 | 562 | |
528 | 563 | // With mod_security installed, we could attempt to fix it with .htaccess. |
529 | - if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) |
|
530 | - $writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.'; |
|
564 | + if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) { |
|
565 | + $writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.'; |
|
566 | + } |
|
531 | 567 | |
532 | 568 | $failed_files = array(); |
533 | 569 | |
@@ -539,20 +575,23 @@ discard block |
||
539 | 575 | foreach ($writable_files as $file) |
540 | 576 | { |
541 | 577 | // Some files won't exist, try to address up front |
542 | - if (!file_exists(dirname(__FILE__) . '/' . $file)) |
|
543 | - @touch(dirname(__FILE__) . '/' . $file); |
|
578 | + if (!file_exists(dirname(__FILE__) . '/' . $file)) { |
|
579 | + @touch(dirname(__FILE__) . '/' . $file); |
|
580 | + } |
|
544 | 581 | // NOW do the writable check... |
545 | 582 | if (!is_writable(dirname(__FILE__) . '/' . $file)) |
546 | 583 | { |
547 | 584 | @chmod(dirname(__FILE__) . '/' . $file, 0755); |
548 | 585 | |
549 | 586 | // Well, 755 hopefully worked... if not, try 777. |
550 | - if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) |
|
551 | - $failed_files[] = $file; |
|
587 | + if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) { |
|
588 | + $failed_files[] = $file; |
|
589 | + } |
|
552 | 590 | } |
553 | 591 | } |
554 | - foreach ($extra_files as $file) |
|
555 | - @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
592 | + foreach ($extra_files as $file) { |
|
593 | + @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
594 | + } |
|
556 | 595 | } |
557 | 596 | // Windows is trickier. Let's try opening for r+... |
558 | 597 | else |
@@ -562,30 +601,35 @@ discard block |
||
562 | 601 | foreach ($writable_files as $file) |
563 | 602 | { |
564 | 603 | // Folders can't be opened for write... but the index.php in them can ;) |
565 | - if (is_dir(dirname(__FILE__) . '/' . $file)) |
|
566 | - $file .= '/index.php'; |
|
604 | + if (is_dir(dirname(__FILE__) . '/' . $file)) { |
|
605 | + $file .= '/index.php'; |
|
606 | + } |
|
567 | 607 | |
568 | 608 | // Funny enough, chmod actually does do something on windows - it removes the read only attribute. |
569 | 609 | @chmod(dirname(__FILE__) . '/' . $file, 0777); |
570 | 610 | $fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+'); |
571 | 611 | |
572 | 612 | // Hmm, okay, try just for write in that case... |
573 | - if (!is_resource($fp)) |
|
574 | - $fp = @fopen(dirname(__FILE__) . '/' . $file, 'w'); |
|
613 | + if (!is_resource($fp)) { |
|
614 | + $fp = @fopen(dirname(__FILE__) . '/' . $file, 'w'); |
|
615 | + } |
|
575 | 616 | |
576 | - if (!is_resource($fp)) |
|
577 | - $failed_files[] = $file; |
|
617 | + if (!is_resource($fp)) { |
|
618 | + $failed_files[] = $file; |
|
619 | + } |
|
578 | 620 | |
579 | 621 | @fclose($fp); |
580 | 622 | } |
581 | - foreach ($extra_files as $file) |
|
582 | - @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
623 | + foreach ($extra_files as $file) { |
|
624 | + @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
625 | + } |
|
583 | 626 | } |
584 | 627 | |
585 | 628 | $failure = count($failed_files) >= 1; |
586 | 629 | |
587 | - if (!isset($_SERVER)) |
|
588 | - return !$failure; |
|
630 | + if (!isset($_SERVER)) { |
|
631 | + return !$failure; |
|
632 | + } |
|
589 | 633 | |
590 | 634 | // Put the list into context. |
591 | 635 | $incontext['failed_files'] = $failed_files; |
@@ -633,19 +677,23 @@ discard block |
||
633 | 677 | |
634 | 678 | if (!isset($ftp) || $ftp->error !== false) |
635 | 679 | { |
636 | - if (!isset($ftp)) |
|
637 | - $ftp = new ftp_connection(null); |
|
680 | + if (!isset($ftp)) { |
|
681 | + $ftp = new ftp_connection(null); |
|
682 | + } |
|
638 | 683 | // Save the error so we can mess with listing... |
639 | - elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) |
|
640 | - $incontext['ftp_errors'][] = $ftp->last_message; |
|
684 | + elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) { |
|
685 | + $incontext['ftp_errors'][] = $ftp->last_message; |
|
686 | + } |
|
641 | 687 | |
642 | 688 | list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__)); |
643 | 689 | |
644 | - if (empty($_POST['ftp_path']) && $found_path) |
|
645 | - $_POST['ftp_path'] = $detect_path; |
|
690 | + if (empty($_POST['ftp_path']) && $found_path) { |
|
691 | + $_POST['ftp_path'] = $detect_path; |
|
692 | + } |
|
646 | 693 | |
647 | - if (!isset($_POST['ftp_username'])) |
|
648 | - $_POST['ftp_username'] = $username; |
|
694 | + if (!isset($_POST['ftp_username'])) { |
|
695 | + $_POST['ftp_username'] = $username; |
|
696 | + } |
|
649 | 697 | |
650 | 698 | // Set the username etc, into context. |
651 | 699 | $incontext['ftp'] = array( |
@@ -657,8 +705,7 @@ discard block |
||
657 | 705 | ); |
658 | 706 | |
659 | 707 | return false; |
660 | - } |
|
661 | - else |
|
708 | + } else |
|
662 | 709 | { |
663 | 710 | $_SESSION['installer_temp_ftp'] = array( |
664 | 711 | 'server' => $_POST['ftp_server'], |
@@ -672,10 +719,12 @@ discard block |
||
672 | 719 | |
673 | 720 | foreach ($failed_files as $file) |
674 | 721 | { |
675 | - if (!is_writable(dirname(__FILE__) . '/' . $file)) |
|
676 | - $ftp->chmod($file, 0755); |
|
677 | - if (!is_writable(dirname(__FILE__) . '/' . $file)) |
|
678 | - $ftp->chmod($file, 0777); |
|
722 | + if (!is_writable(dirname(__FILE__) . '/' . $file)) { |
|
723 | + $ftp->chmod($file, 0755); |
|
724 | + } |
|
725 | + if (!is_writable(dirname(__FILE__) . '/' . $file)) { |
|
726 | + $ftp->chmod($file, 0777); |
|
727 | + } |
|
679 | 728 | if (!is_writable(dirname(__FILE__) . '/' . $file)) |
680 | 729 | { |
681 | 730 | $failed_files_updated[] = $file; |
@@ -731,15 +780,17 @@ discard block |
||
731 | 780 | |
732 | 781 | if (!$foundOne) |
733 | 782 | { |
734 | - if (isset($db['default_host'])) |
|
735 | - $incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost'; |
|
783 | + if (isset($db['default_host'])) { |
|
784 | + $incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost'; |
|
785 | + } |
|
736 | 786 | if (isset($db['default_user'])) |
737 | 787 | { |
738 | 788 | $incontext['db']['user'] = ini_get($db['default_user']); |
739 | 789 | $incontext['db']['name'] = ini_get($db['default_user']); |
740 | 790 | } |
741 | - if (isset($db['default_password'])) |
|
742 | - $incontext['db']['pass'] = ini_get($db['default_password']); |
|
791 | + if (isset($db['default_password'])) { |
|
792 | + $incontext['db']['pass'] = ini_get($db['default_password']); |
|
793 | + } |
|
743 | 794 | |
744 | 795 | // For simplicity and less confusion, leave the port blank by default |
745 | 796 | $incontext['db']['port'] = ''; |
@@ -758,10 +809,10 @@ discard block |
||
758 | 809 | $incontext['db']['server'] = $_POST['db_server']; |
759 | 810 | $incontext['db']['prefix'] = $_POST['db_prefix']; |
760 | 811 | |
761 | - if (!empty($_POST['db_port'])) |
|
762 | - $incontext['db']['port'] = $_POST['db_port']; |
|
763 | - } |
|
764 | - else |
|
812 | + if (!empty($_POST['db_port'])) { |
|
813 | + $incontext['db']['port'] = $_POST['db_port']; |
|
814 | + } |
|
815 | + } else |
|
765 | 816 | { |
766 | 817 | $incontext['db']['prefix'] = 'smf_'; |
767 | 818 | } |
@@ -797,10 +848,11 @@ discard block |
||
797 | 848 | if (!empty($_POST['db_port'])) |
798 | 849 | { |
799 | 850 | // For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though. |
800 | - if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) |
|
801 | - $vars['db_port'] = (int) $_POST['db_port']; |
|
802 | - elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) |
|
803 | - $vars['db_port'] = (int) $_POST['db_port']; |
|
851 | + if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) { |
|
852 | + $vars['db_port'] = (int) $_POST['db_port']; |
|
853 | + } elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) { |
|
854 | + $vars['db_port'] = (int) $_POST['db_port']; |
|
855 | + } |
|
804 | 856 | } |
805 | 857 | |
806 | 858 | // God I hope it saved! |
@@ -813,8 +865,9 @@ discard block |
||
813 | 865 | // Make sure it works. |
814 | 866 | require(dirname(__FILE__) . '/Settings.php'); |
815 | 867 | |
816 | - if (empty($sourcedir)) |
|
817 | - $sourcedir = dirname(__FILE__) . '/Sources'; |
|
868 | + if (empty($sourcedir)) { |
|
869 | + $sourcedir = dirname(__FILE__) . '/Sources'; |
|
870 | + } |
|
818 | 871 | |
819 | 872 | // Better find the database file! |
820 | 873 | if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
@@ -824,12 +877,14 @@ discard block |
||
824 | 877 | } |
825 | 878 | |
826 | 879 | // Now include it for database functions! |
827 | - if (!defined('SMF')) |
|
828 | - define('SMF', 1); |
|
880 | + if (!defined('SMF')) { |
|
881 | + define('SMF', 1); |
|
882 | + } |
|
829 | 883 | |
830 | 884 | $modSettings['disableQueryCheck'] = true; |
831 | - if (empty($smcFunc)) |
|
832 | - $smcFunc = array(); |
|
885 | + if (empty($smcFunc)) { |
|
886 | + $smcFunc = array(); |
|
887 | + } |
|
833 | 888 | |
834 | 889 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
835 | 890 | |
@@ -838,11 +893,13 @@ discard block |
||
838 | 893 | |
839 | 894 | $options = array('non_fatal' => true, 'dont_select_db' => !$needsDB); |
840 | 895 | // Add in the port if needed |
841 | - if (!empty($db_port)) |
|
842 | - $options['port'] = $db_port; |
|
896 | + if (!empty($db_port)) { |
|
897 | + $options['port'] = $db_port; |
|
898 | + } |
|
843 | 899 | |
844 | - if (!empty($db_mb4)) |
|
845 | - $options['db_mb4'] = $db_mb4; |
|
900 | + if (!empty($db_mb4)) { |
|
901 | + $options['db_mb4'] = $db_mb4; |
|
902 | + } |
|
846 | 903 | |
847 | 904 | $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options); |
848 | 905 | |
@@ -928,12 +985,14 @@ discard block |
||
928 | 985 | $incontext['page_title'] = $txt['install_settings']; |
929 | 986 | |
930 | 987 | // Let's see if we got the database type correct. |
931 | - if (isset($_POST['db_type'], $databases[$_POST['db_type']])) |
|
932 | - $db_type = $_POST['db_type']; |
|
988 | + if (isset($_POST['db_type'], $databases[$_POST['db_type']])) { |
|
989 | + $db_type = $_POST['db_type']; |
|
990 | + } |
|
933 | 991 | |
934 | 992 | // Else we'd better be able to get the connection. |
935 | - else |
|
936 | - load_database(); |
|
993 | + else { |
|
994 | + load_database(); |
|
995 | + } |
|
937 | 996 | |
938 | 997 | $db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type; |
939 | 998 | |
@@ -942,10 +1001,11 @@ discard block |
||
942 | 1001 | |
943 | 1002 | $secure = false; |
944 | 1003 | |
945 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
946 | - $secure = true; |
|
947 | - 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') |
|
948 | - $secure = true; |
|
1004 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
1005 | + $secure = true; |
|
1006 | + } 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') { |
|
1007 | + $secure = true; |
|
1008 | + } |
|
949 | 1009 | |
950 | 1010 | // Now, to put what we've learned together... and add a path. |
951 | 1011 | $incontext['detected_url'] = 'http' . ($secure ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')); |
@@ -977,18 +1037,21 @@ discard block |
||
977 | 1037 | // Submitting? |
978 | 1038 | if (isset($_POST['boardurl'])) |
979 | 1039 | { |
980 | - if (substr($_POST['boardurl'], -10) == '/index.php') |
|
981 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
982 | - elseif (substr($_POST['boardurl'], -1) == '/') |
|
983 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
984 | - if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') |
|
985 | - $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
1040 | + if (substr($_POST['boardurl'], -10) == '/index.php') { |
|
1041 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
1042 | + } elseif (substr($_POST['boardurl'], -1) == '/') { |
|
1043 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
1044 | + } |
|
1045 | + if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') { |
|
1046 | + $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
1047 | + } |
|
986 | 1048 | |
987 | 1049 | //Make sure boardurl is aligned with ssl setting |
988 | - if (empty($_POST['force_ssl'])) |
|
989 | - $_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://')); |
|
990 | - else |
|
991 | - $_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://')); |
|
1050 | + if (empty($_POST['force_ssl'])) { |
|
1051 | + $_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://')); |
|
1052 | + } else { |
|
1053 | + $_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://')); |
|
1054 | + } |
|
992 | 1055 | |
993 | 1056 | // Save these variables. |
994 | 1057 | $vars = array( |
@@ -1027,10 +1090,10 @@ discard block |
||
1027 | 1090 | { |
1028 | 1091 | $incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']); |
1029 | 1092 | return false; |
1030 | - } |
|
1031 | - else |
|
1032 | - // Set the character set here. |
|
1093 | + } else { |
|
1094 | + // Set the character set here. |
|
1033 | 1095 | updateSettingsFile(array('db_character_set' => 'utf8')); |
1096 | + } |
|
1034 | 1097 | } |
1035 | 1098 | |
1036 | 1099 | // Good, skip on. |
@@ -1050,8 +1113,9 @@ discard block |
||
1050 | 1113 | $incontext['continue'] = 1; |
1051 | 1114 | |
1052 | 1115 | // Already done? |
1053 | - if (isset($_POST['pop_done'])) |
|
1054 | - return true; |
|
1116 | + if (isset($_POST['pop_done'])) { |
|
1117 | + return true; |
|
1118 | + } |
|
1055 | 1119 | |
1056 | 1120 | // Reload settings. |
1057 | 1121 | require(dirname(__FILE__) . '/Settings.php'); |
@@ -1069,8 +1133,9 @@ discard block |
||
1069 | 1133 | $modSettings = array(); |
1070 | 1134 | if ($result !== false) |
1071 | 1135 | { |
1072 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
1073 | - $modSettings[$row['variable']] = $row['value']; |
|
1136 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
1137 | + $modSettings[$row['variable']] = $row['value']; |
|
1138 | + } |
|
1074 | 1139 | $smcFunc['db_free_result']($result); |
1075 | 1140 | |
1076 | 1141 | // Do they match? If so, this is just a refresh so charge on! |
@@ -1083,20 +1148,22 @@ discard block |
||
1083 | 1148 | $modSettings['disableQueryCheck'] = true; |
1084 | 1149 | |
1085 | 1150 | // If doing UTF8, select it. PostgreSQL requires passing it as a string... |
1086 | - if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) |
|
1087 | - $smcFunc['db_query']('', ' |
|
1151 | + if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) { |
|
1152 | + $smcFunc['db_query']('', ' |
|
1088 | 1153 | SET NAMES {string:utf8}', |
1089 | 1154 | array( |
1090 | 1155 | 'db_error_skip' => true, |
1091 | 1156 | 'utf8' => 'utf8', |
1092 | 1157 | ) |
1093 | 1158 | ); |
1159 | + } |
|
1094 | 1160 | |
1095 | 1161 | // Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments... |
1096 | - if (substr(__DIR__, -1) == '\\') |
|
1097 | - $attachdir = __DIR__ . 'attachments'; |
|
1098 | - else |
|
1099 | - $attachdir = __DIR__ . '/attachments'; |
|
1162 | + if (substr(__DIR__, -1) == '\\') { |
|
1163 | + $attachdir = __DIR__ . 'attachments'; |
|
1164 | + } else { |
|
1165 | + $attachdir = __DIR__ . '/attachments'; |
|
1166 | + } |
|
1100 | 1167 | |
1101 | 1168 | $replaces = array( |
1102 | 1169 | '{$db_prefix}' => $db_prefix, |
@@ -1113,8 +1180,9 @@ discard block |
||
1113 | 1180 | |
1114 | 1181 | foreach ($txt as $key => $value) |
1115 | 1182 | { |
1116 | - if (substr($key, 0, 8) == 'default_') |
|
1117 | - $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value); |
|
1183 | + if (substr($key, 0, 8) == 'default_') { |
|
1184 | + $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value); |
|
1185 | + } |
|
1118 | 1186 | } |
1119 | 1187 | $replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n')); |
1120 | 1188 | |
@@ -1129,8 +1197,9 @@ discard block |
||
1129 | 1197 | |
1130 | 1198 | while ($row = $smcFunc['db_fetch_assoc']($get_engines)) |
1131 | 1199 | { |
1132 | - if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') |
|
1133 | - $engines[] = $row['Engine']; |
|
1200 | + if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') { |
|
1201 | + $engines[] = $row['Engine']; |
|
1202 | + } |
|
1134 | 1203 | } |
1135 | 1204 | |
1136 | 1205 | // Done with this now |
@@ -1154,8 +1223,7 @@ discard block |
||
1154 | 1223 | $replaces['START TRANSACTION;'] = ''; |
1155 | 1224 | $replaces['COMMIT;'] = ''; |
1156 | 1225 | } |
1157 | - } |
|
1158 | - else |
|
1226 | + } else |
|
1159 | 1227 | { |
1160 | 1228 | $has_innodb = false; |
1161 | 1229 | } |
@@ -1177,21 +1245,24 @@ discard block |
||
1177 | 1245 | foreach ($sql_lines as $count => $line) |
1178 | 1246 | { |
1179 | 1247 | // No comments allowed! |
1180 | - if (substr(trim($line), 0, 1) != '#') |
|
1181 | - $current_statement .= "\n" . rtrim($line); |
|
1248 | + if (substr(trim($line), 0, 1) != '#') { |
|
1249 | + $current_statement .= "\n" . rtrim($line); |
|
1250 | + } |
|
1182 | 1251 | |
1183 | 1252 | // Is this the end of the query string? |
1184 | - if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) |
|
1185 | - continue; |
|
1253 | + if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) { |
|
1254 | + continue; |
|
1255 | + } |
|
1186 | 1256 | |
1187 | 1257 | // Does this table already exist? If so, don't insert more data into it! |
1188 | 1258 | if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists)) |
1189 | 1259 | { |
1190 | 1260 | preg_match_all('~\)[,;]~', $current_statement, $matches); |
1191 | - if (!empty($matches[0])) |
|
1192 | - $incontext['sql_results']['insert_dups'] += count($matches[0]); |
|
1193 | - else |
|
1194 | - $incontext['sql_results']['insert_dups']++; |
|
1261 | + if (!empty($matches[0])) { |
|
1262 | + $incontext['sql_results']['insert_dups'] += count($matches[0]); |
|
1263 | + } else { |
|
1264 | + $incontext['sql_results']['insert_dups']++; |
|
1265 | + } |
|
1195 | 1266 | |
1196 | 1267 | $current_statement = ''; |
1197 | 1268 | continue; |
@@ -1200,8 +1271,9 @@ discard block |
||
1200 | 1271 | if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false) |
1201 | 1272 | { |
1202 | 1273 | // Use the appropriate function based on the DB type |
1203 | - if ($db_type == 'mysql' || $db_type == 'mysqli') |
|
1204 | - $db_errorno = $db_type . '_errno'; |
|
1274 | + if ($db_type == 'mysql' || $db_type == 'mysqli') { |
|
1275 | + $db_errorno = $db_type . '_errno'; |
|
1276 | + } |
|
1205 | 1277 | |
1206 | 1278 | // Error 1050: Table already exists! |
1207 | 1279 | // @todo Needs to be made better! |
@@ -1216,18 +1288,18 @@ discard block |
||
1216 | 1288 | // MySQLi requires a connection object. It's optional with MySQL and Postgres |
1217 | 1289 | $incontext['failures'][$count] = $smcFunc['db_error']($db_connection); |
1218 | 1290 | } |
1219 | - } |
|
1220 | - else |
|
1291 | + } else |
|
1221 | 1292 | { |
1222 | - if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
1223 | - $incontext['sql_results']['tables']++; |
|
1224 | - elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
1293 | + if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) { |
|
1294 | + $incontext['sql_results']['tables']++; |
|
1295 | + } elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
1225 | 1296 | { |
1226 | 1297 | preg_match_all('~\)[,;]~', $current_statement, $matches); |
1227 | - if (!empty($matches[0])) |
|
1228 | - $incontext['sql_results']['inserts'] += count($matches[0]); |
|
1229 | - else |
|
1230 | - $incontext['sql_results']['inserts']++; |
|
1298 | + if (!empty($matches[0])) { |
|
1299 | + $incontext['sql_results']['inserts'] += count($matches[0]); |
|
1300 | + } else { |
|
1301 | + $incontext['sql_results']['inserts']++; |
|
1302 | + } |
|
1231 | 1303 | } |
1232 | 1304 | } |
1233 | 1305 | |
@@ -1240,15 +1312,17 @@ discard block |
||
1240 | 1312 | // Sort out the context for the SQL. |
1241 | 1313 | foreach ($incontext['sql_results'] as $key => $number) |
1242 | 1314 | { |
1243 | - if ($number == 0) |
|
1244 | - unset($incontext['sql_results'][$key]); |
|
1245 | - else |
|
1246 | - $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number); |
|
1315 | + if ($number == 0) { |
|
1316 | + unset($incontext['sql_results'][$key]); |
|
1317 | + } else { |
|
1318 | + $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number); |
|
1319 | + } |
|
1247 | 1320 | } |
1248 | 1321 | |
1249 | 1322 | // Make sure UTF will be used globally. |
1250 | - if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) |
|
1251 | - $newSettings[] = array('global_character_set', 'UTF-8'); |
|
1323 | + if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) { |
|
1324 | + $newSettings[] = array('global_character_set', 'UTF-8'); |
|
1325 | + } |
|
1252 | 1326 | |
1253 | 1327 | // Auto-detect local & global cookie settings |
1254 | 1328 | $url_parts = parse_url($boardurl); |
@@ -1277,15 +1351,19 @@ discard block |
||
1277 | 1351 | |
1278 | 1352 | // Look for subfolder, if found, set localCookie |
1279 | 1353 | // Checking for len > 1 ensures you don't have just a slash... |
1280 | - if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) |
|
1281 | - $localCookies = '1'; |
|
1354 | + if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) { |
|
1355 | + $localCookies = '1'; |
|
1356 | + } |
|
1282 | 1357 | |
1283 | - if (isset($globalCookies)) |
|
1284 | - $newSettings[] = array('globalCookies', $globalCookies); |
|
1285 | - if (isset($globalCookiesDomain)) |
|
1286 | - $newSettings[] = array('globalCookiesDomain', $globalCookiesDomain); |
|
1287 | - if (isset($localCookies)) |
|
1288 | - $newSettings[] = array('localCookies', $localCookies); |
|
1358 | + if (isset($globalCookies)) { |
|
1359 | + $newSettings[] = array('globalCookies', $globalCookies); |
|
1360 | + } |
|
1361 | + if (isset($globalCookiesDomain)) { |
|
1362 | + $newSettings[] = array('globalCookiesDomain', $globalCookiesDomain); |
|
1363 | + } |
|
1364 | + if (isset($localCookies)) { |
|
1365 | + $newSettings[] = array('localCookies', $localCookies); |
|
1366 | + } |
|
1289 | 1367 | } |
1290 | 1368 | |
1291 | 1369 | // Are we allowing stat collection? |
@@ -1303,16 +1381,17 @@ discard block |
||
1303 | 1381 | fwrite($fp, $out); |
1304 | 1382 | |
1305 | 1383 | $return_data = ''; |
1306 | - while (!feof($fp)) |
|
1307 | - $return_data .= fgets($fp, 128); |
|
1384 | + while (!feof($fp)) { |
|
1385 | + $return_data .= fgets($fp, 128); |
|
1386 | + } |
|
1308 | 1387 | |
1309 | 1388 | fclose($fp); |
1310 | 1389 | |
1311 | 1390 | // Get the unique site ID. |
1312 | 1391 | preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID); |
1313 | 1392 | |
1314 | - if (!empty($ID[1])) |
|
1315 | - $smcFunc['db_insert']('replace', |
|
1393 | + if (!empty($ID[1])) { |
|
1394 | + $smcFunc['db_insert']('replace', |
|
1316 | 1395 | $db_prefix . 'settings', |
1317 | 1396 | array('variable' => 'string', 'value' => 'string'), |
1318 | 1397 | array( |
@@ -1321,11 +1400,12 @@ discard block |
||
1321 | 1400 | ), |
1322 | 1401 | array('variable') |
1323 | 1402 | ); |
1403 | + } |
|
1324 | 1404 | } |
1325 | 1405 | } |
1326 | 1406 | // Don't remove stat collection unless we unchecked the box for real, not from the loop. |
1327 | - elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) |
|
1328 | - $smcFunc['db_query']('', ' |
|
1407 | + elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) { |
|
1408 | + $smcFunc['db_query']('', ' |
|
1329 | 1409 | DELETE FROM {db_prefix}settings |
1330 | 1410 | WHERE variable = {string:enable_sm_stats}', |
1331 | 1411 | array( |
@@ -1333,20 +1413,23 @@ discard block |
||
1333 | 1413 | 'db_error_skip' => true, |
1334 | 1414 | ) |
1335 | 1415 | ); |
1416 | + } |
|
1336 | 1417 | |
1337 | 1418 | // Are we enabling SSL? |
1338 | - if (!empty($_POST['force_ssl'])) |
|
1339 | - $newSettings[] = array('force_ssl', 1); |
|
1419 | + if (!empty($_POST['force_ssl'])) { |
|
1420 | + $newSettings[] = array('force_ssl', 1); |
|
1421 | + } |
|
1340 | 1422 | |
1341 | 1423 | // Setting a timezone is required. |
1342 | 1424 | if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set')) |
1343 | 1425 | { |
1344 | 1426 | // Get PHP's default timezone, if set |
1345 | 1427 | $ini_tz = ini_get('date.timezone'); |
1346 | - if (!empty($ini_tz)) |
|
1347 | - $timezone_id = $ini_tz; |
|
1348 | - else |
|
1349 | - $timezone_id = ''; |
|
1428 | + if (!empty($ini_tz)) { |
|
1429 | + $timezone_id = $ini_tz; |
|
1430 | + } else { |
|
1431 | + $timezone_id = ''; |
|
1432 | + } |
|
1350 | 1433 | |
1351 | 1434 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
1352 | 1435 | if (!in_array($timezone_id, timezone_identifiers_list())) |
@@ -1355,8 +1438,9 @@ discard block |
||
1355 | 1438 | $timezone_id = timezone_name_from_abbr('', $server_offset, 0); |
1356 | 1439 | } |
1357 | 1440 | |
1358 | - if (date_default_timezone_set($timezone_id)) |
|
1359 | - $newSettings[] = array('default_timezone', $timezone_id); |
|
1441 | + if (date_default_timezone_set($timezone_id)) { |
|
1442 | + $newSettings[] = array('default_timezone', $timezone_id); |
|
1443 | + } |
|
1360 | 1444 | } |
1361 | 1445 | |
1362 | 1446 | if (!empty($newSettings)) |
@@ -1387,16 +1471,18 @@ discard block |
||
1387 | 1471 | } |
1388 | 1472 | |
1389 | 1473 | // MySQL specific stuff |
1390 | - if (substr($db_type, 0, 5) != 'mysql') |
|
1391 | - return false; |
|
1474 | + if (substr($db_type, 0, 5) != 'mysql') { |
|
1475 | + return false; |
|
1476 | + } |
|
1392 | 1477 | |
1393 | 1478 | // Find database user privileges. |
1394 | 1479 | $privs = array(); |
1395 | 1480 | $get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array()); |
1396 | 1481 | while ($row = $smcFunc['db_fetch_assoc']($get_privs)) |
1397 | 1482 | { |
1398 | - if ($row['Privilege'] == 'Alter') |
|
1399 | - $privs[] = $row['Privilege']; |
|
1483 | + if ($row['Privilege'] == 'Alter') { |
|
1484 | + $privs[] = $row['Privilege']; |
|
1485 | + } |
|
1400 | 1486 | } |
1401 | 1487 | $smcFunc['db_free_result']($get_privs); |
1402 | 1488 | |
@@ -1426,8 +1512,9 @@ discard block |
||
1426 | 1512 | $incontext['continue'] = 1; |
1427 | 1513 | |
1428 | 1514 | // Skipping? |
1429 | - if (!empty($_POST['skip'])) |
|
1430 | - return true; |
|
1515 | + if (!empty($_POST['skip'])) { |
|
1516 | + return true; |
|
1517 | + } |
|
1431 | 1518 | |
1432 | 1519 | // Need this to check whether we need the database password. |
1433 | 1520 | require(dirname(__FILE__) . '/Settings.php'); |
@@ -1444,18 +1531,22 @@ discard block |
||
1444 | 1531 | // We need this to properly hash the password for Admin |
1445 | 1532 | $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) { |
1446 | 1533 | global $sourcedir; |
1447 | - if (function_exists('mb_strtolower')) |
|
1448 | - return mb_strtolower($string, 'UTF-8'); |
|
1534 | + if (function_exists('mb_strtolower')) { |
|
1535 | + return mb_strtolower($string, 'UTF-8'); |
|
1536 | + } |
|
1449 | 1537 | require_once($sourcedir . '/Subs-Charset.php'); |
1450 | 1538 | return utf8_strtolower($string); |
1451 | 1539 | }; |
1452 | 1540 | |
1453 | - if (!isset($_POST['username'])) |
|
1454 | - $_POST['username'] = ''; |
|
1455 | - if (!isset($_POST['email'])) |
|
1456 | - $_POST['email'] = ''; |
|
1457 | - if (!isset($_POST['server_email'])) |
|
1458 | - $_POST['server_email'] = ''; |
|
1541 | + if (!isset($_POST['username'])) { |
|
1542 | + $_POST['username'] = ''; |
|
1543 | + } |
|
1544 | + if (!isset($_POST['email'])) { |
|
1545 | + $_POST['email'] = ''; |
|
1546 | + } |
|
1547 | + if (!isset($_POST['server_email'])) { |
|
1548 | + $_POST['server_email'] = ''; |
|
1549 | + } |
|
1459 | 1550 | |
1460 | 1551 | $incontext['username'] = htmlspecialchars(stripslashes($_POST['username'])); |
1461 | 1552 | $incontext['email'] = htmlspecialchars(stripslashes($_POST['email'])); |
@@ -1474,8 +1565,9 @@ discard block |
||
1474 | 1565 | 'admin_group' => 1, |
1475 | 1566 | ) |
1476 | 1567 | ); |
1477 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
1478 | - $incontext['skip'] = 1; |
|
1568 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
1569 | + $incontext['skip'] = 1; |
|
1570 | + } |
|
1479 | 1571 | $smcFunc['db_free_result']($request); |
1480 | 1572 | |
1481 | 1573 | // Trying to create an account? |
@@ -1506,8 +1598,9 @@ discard block |
||
1506 | 1598 | } |
1507 | 1599 | |
1508 | 1600 | // Update the webmaster's email? |
1509 | - if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) |
|
1510 | - updateSettingsFile(array('webmaster_email' => $_POST['server_email'])); |
|
1601 | + if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) { |
|
1602 | + updateSettingsFile(array('webmaster_email' => $_POST['server_email'])); |
|
1603 | + } |
|
1511 | 1604 | |
1512 | 1605 | // Work out whether we're going to have dodgy characters and remove them. |
1513 | 1606 | $invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0; |
@@ -1530,32 +1623,27 @@ discard block |
||
1530 | 1623 | $smcFunc['db_free_result']($result); |
1531 | 1624 | |
1532 | 1625 | $incontext['account_existed'] = $txt['error_user_settings_taken']; |
1533 | - } |
|
1534 | - elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25) |
|
1626 | + } elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25) |
|
1535 | 1627 | { |
1536 | 1628 | // Try the previous step again. |
1537 | 1629 | $incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long']; |
1538 | 1630 | return false; |
1539 | - } |
|
1540 | - elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false) |
|
1631 | + } elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false) |
|
1541 | 1632 | { |
1542 | 1633 | // Try the previous step again. |
1543 | 1634 | $incontext['error'] = $txt['error_invalid_characters_username']; |
1544 | 1635 | return false; |
1545 | - } |
|
1546 | - elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255) |
|
1636 | + } elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255) |
|
1547 | 1637 | { |
1548 | 1638 | // One step back, this time fill out a proper admin email address. |
1549 | 1639 | $incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']); |
1550 | 1640 | return false; |
1551 | - } |
|
1552 | - elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255) |
|
1641 | + } elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255) |
|
1553 | 1642 | { |
1554 | 1643 | // One step back, this time fill out a proper admin email address. |
1555 | 1644 | $incontext['error'] = $txt['error_valid_server_email_needed']; |
1556 | 1645 | return false; |
1557 | - } |
|
1558 | - elseif ($_POST['username'] != '') |
|
1646 | + } elseif ($_POST['username'] != '') |
|
1559 | 1647 | { |
1560 | 1648 | $incontext['member_salt'] = substr(md5(mt_rand()), 0, 4); |
1561 | 1649 | |
@@ -1623,17 +1711,19 @@ discard block |
||
1623 | 1711 | reloadSettings(); |
1624 | 1712 | |
1625 | 1713 | // Bring a warning over. |
1626 | - if (!empty($incontext['account_existed'])) |
|
1627 | - $incontext['warning'] = $incontext['account_existed']; |
|
1714 | + if (!empty($incontext['account_existed'])) { |
|
1715 | + $incontext['warning'] = $incontext['account_existed']; |
|
1716 | + } |
|
1628 | 1717 | |
1629 | - if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) |
|
1630 | - $smcFunc['db_query']('', ' |
|
1718 | + if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) { |
|
1719 | + $smcFunc['db_query']('', ' |
|
1631 | 1720 | SET NAMES {string:db_character_set}', |
1632 | 1721 | array( |
1633 | 1722 | 'db_character_set' => $db_character_set, |
1634 | 1723 | 'db_error_skip' => true, |
1635 | 1724 | ) |
1636 | 1725 | ); |
1726 | + } |
|
1637 | 1727 | |
1638 | 1728 | // As track stats is by default enabled let's add some activity. |
1639 | 1729 | $smcFunc['db_insert']('ignore', |
@@ -1654,14 +1744,16 @@ discard block |
||
1654 | 1744 | // Only proceed if we can load the data. |
1655 | 1745 | if ($request) |
1656 | 1746 | { |
1657 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
1658 | - $modSettings[$row[0]] = $row[1]; |
|
1747 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
1748 | + $modSettings[$row[0]] = $row[1]; |
|
1749 | + } |
|
1659 | 1750 | $smcFunc['db_free_result']($request); |
1660 | 1751 | } |
1661 | 1752 | |
1662 | 1753 | // Automatically log them in ;) |
1663 | - if (isset($incontext['member_id']) && isset($incontext['member_salt'])) |
|
1664 | - setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt'])); |
|
1754 | + if (isset($incontext['member_id']) && isset($incontext['member_salt'])) { |
|
1755 | + setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt'])); |
|
1756 | + } |
|
1665 | 1757 | |
1666 | 1758 | $result = $smcFunc['db_query']('', ' |
1667 | 1759 | SELECT value |
@@ -1672,13 +1764,14 @@ discard block |
||
1672 | 1764 | 'db_error_skip' => true, |
1673 | 1765 | ) |
1674 | 1766 | ); |
1675 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
1676 | - list ($db_sessions) = $smcFunc['db_fetch_row']($result); |
|
1767 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
1768 | + list ($db_sessions) = $smcFunc['db_fetch_row']($result); |
|
1769 | + } |
|
1677 | 1770 | $smcFunc['db_free_result']($result); |
1678 | 1771 | |
1679 | - if (empty($db_sessions)) |
|
1680 | - $_SESSION['admin_time'] = time(); |
|
1681 | - else |
|
1772 | + if (empty($db_sessions)) { |
|
1773 | + $_SESSION['admin_time'] = time(); |
|
1774 | + } else |
|
1682 | 1775 | { |
1683 | 1776 | $_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211); |
1684 | 1777 | |
@@ -1702,8 +1795,9 @@ discard block |
||
1702 | 1795 | $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : |
1703 | 1796 | function($string){ |
1704 | 1797 | global $sourcedir; |
1705 | - if (function_exists('mb_strtolower')) |
|
1706 | - return mb_strtolower($string, 'UTF-8'); |
|
1798 | + if (function_exists('mb_strtolower')) { |
|
1799 | + return mb_strtolower($string, 'UTF-8'); |
|
1800 | + } |
|
1707 | 1801 | require_once($sourcedir . '/Subs-Charset.php'); |
1708 | 1802 | return utf8_strtolower($string); |
1709 | 1803 | }; |
@@ -1719,8 +1813,9 @@ discard block |
||
1719 | 1813 | ) |
1720 | 1814 | ); |
1721 | 1815 | $context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8'; |
1722 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
1723 | - updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); |
|
1816 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
1817 | + updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); |
|
1818 | + } |
|
1724 | 1819 | $smcFunc['db_free_result']($request); |
1725 | 1820 | |
1726 | 1821 | // Now is the perfect time to fetch the SM files. |
@@ -1739,8 +1834,9 @@ discard block |
||
1739 | 1834 | |
1740 | 1835 | // Check if we need some stupid MySQL fix. |
1741 | 1836 | $server_version = $smcFunc['db_server_info'](); |
1742 | - if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) |
|
1743 | - updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
1837 | + if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { |
|
1838 | + updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
1839 | + } |
|
1744 | 1840 | |
1745 | 1841 | // Some final context for the template. |
1746 | 1842 | $incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\'; |
@@ -1760,8 +1856,9 @@ discard block |
||
1760 | 1856 | $settingsArray = file(dirname(__FILE__) . '/Settings.php'); |
1761 | 1857 | |
1762 | 1858 | // @todo Do we just want to read the file in clean, and split it this way always? |
1763 | - if (count($settingsArray) == 1) |
|
1764 | - $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); |
|
1859 | + if (count($settingsArray) == 1) { |
|
1860 | + $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); |
|
1861 | + } |
|
1765 | 1862 | |
1766 | 1863 | for ($i = 0, $n = count($settingsArray); $i < $n; $i++) |
1767 | 1864 | { |
@@ -1769,25 +1866,29 @@ discard block |
||
1769 | 1866 | if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}') |
1770 | 1867 | { |
1771 | 1868 | // Set the ten lines to nothing. |
1772 | - for ($j=0; $j < 10; $j++) |
|
1773 | - $settingsArray[$i++] = ''; |
|
1869 | + for ($j=0; $j < 10; $j++) { |
|
1870 | + $settingsArray[$i++] = ''; |
|
1871 | + } |
|
1774 | 1872 | |
1775 | 1873 | continue; |
1776 | 1874 | } |
1777 | 1875 | |
1778 | - if (trim($settingsArray[$i]) == '?' . '>') |
|
1779 | - $settingsArray[$i] = ''; |
|
1876 | + if (trim($settingsArray[$i]) == '?' . '>') { |
|
1877 | + $settingsArray[$i] = ''; |
|
1878 | + } |
|
1780 | 1879 | |
1781 | 1880 | // Don't trim or bother with it if it's not a variable. |
1782 | - if (substr($settingsArray[$i], 0, 1) != '$') |
|
1783 | - continue; |
|
1881 | + if (substr($settingsArray[$i], 0, 1) != '$') { |
|
1882 | + continue; |
|
1883 | + } |
|
1784 | 1884 | |
1785 | 1885 | $settingsArray[$i] = rtrim($settingsArray[$i]) . "\n"; |
1786 | 1886 | |
1787 | - foreach ($vars as $var => $val) |
|
1788 | - if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
1887 | + foreach ($vars as $var => $val) { |
|
1888 | + if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
1789 | 1889 | { |
1790 | 1890 | $comment = strstr($settingsArray[$i], '#'); |
1891 | + } |
|
1791 | 1892 | $settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n"); |
1792 | 1893 | unset($vars[$var]); |
1793 | 1894 | } |
@@ -1797,36 +1898,41 @@ discard block |
||
1797 | 1898 | if (!empty($vars)) |
1798 | 1899 | { |
1799 | 1900 | $settingsArray[$i++] = ''; |
1800 | - foreach ($vars as $var => $val) |
|
1801 | - $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n"; |
|
1901 | + foreach ($vars as $var => $val) { |
|
1902 | + $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n"; |
|
1903 | + } |
|
1802 | 1904 | } |
1803 | 1905 | |
1804 | 1906 | // Blank out the file - done to fix a oddity with some servers. |
1805 | 1907 | $fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w'); |
1806 | - if (!$fp) |
|
1807 | - return false; |
|
1908 | + if (!$fp) { |
|
1909 | + return false; |
|
1910 | + } |
|
1808 | 1911 | fclose($fp); |
1809 | 1912 | |
1810 | 1913 | $fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+'); |
1811 | 1914 | |
1812 | 1915 | // Gotta have one of these ;) |
1813 | - if (trim($settingsArray[0]) != '<?php') |
|
1814 | - fwrite($fp, "<?php\n"); |
|
1916 | + if (trim($settingsArray[0]) != '<?php') { |
|
1917 | + fwrite($fp, "<?php\n"); |
|
1918 | + } |
|
1815 | 1919 | |
1816 | 1920 | $lines = count($settingsArray); |
1817 | 1921 | for ($i = 0; $i < $lines - 1; $i++) |
1818 | 1922 | { |
1819 | 1923 | // Don't just write a bunch of blank lines. |
1820 | - if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') |
|
1821 | - fwrite($fp, strtr($settingsArray[$i], "\r", '')); |
|
1924 | + if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') { |
|
1925 | + fwrite($fp, strtr($settingsArray[$i], "\r", '')); |
|
1926 | + } |
|
1822 | 1927 | } |
1823 | 1928 | fwrite($fp, $settingsArray[$i] . '?' . '>'); |
1824 | 1929 | fclose($fp); |
1825 | 1930 | |
1826 | 1931 | // Even though on normal installations the filemtime should prevent this being used by the installer incorrectly |
1827 | 1932 | // it seems that there are times it might not. So let's MAKE it dump the cache. |
1828 | - if (function_exists('opcache_invalidate')) |
|
1829 | - opcache_invalidate(dirname(__FILE__) . '/Settings.php', true); |
|
1933 | + if (function_exists('opcache_invalidate')) { |
|
1934 | + opcache_invalidate(dirname(__FILE__) . '/Settings.php', true); |
|
1935 | + } |
|
1830 | 1936 | |
1831 | 1937 | return true; |
1832 | 1938 | } |
@@ -1836,10 +1942,11 @@ discard block |
||
1836 | 1942 | global $cachedir; |
1837 | 1943 | |
1838 | 1944 | // Write out the db_last_error file with the error timestamp |
1839 | - if (!empty($cachedir) && is_writable($cachedir)) |
|
1840 | - file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>'); |
|
1841 | - else |
|
1842 | - file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>'); |
|
1945 | + if (!empty($cachedir) && is_writable($cachedir)) { |
|
1946 | + file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>'); |
|
1947 | + } else { |
|
1948 | + file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>'); |
|
1949 | + } |
|
1843 | 1950 | |
1844 | 1951 | return true; |
1845 | 1952 | } |
@@ -1856,9 +1963,9 @@ discard block |
||
1856 | 1963 | SecFilterScanPOST Off |
1857 | 1964 | </IfModule>'; |
1858 | 1965 | |
1859 | - if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) |
|
1860 | - return true; |
|
1861 | - elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess')) |
|
1966 | + if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) { |
|
1967 | + return true; |
|
1968 | + } elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess')) |
|
1862 | 1969 | { |
1863 | 1970 | $current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess')); |
1864 | 1971 | |
@@ -1870,29 +1977,28 @@ discard block |
||
1870 | 1977 | fwrite($ht_handle, $htaccess_addition); |
1871 | 1978 | fclose($ht_handle); |
1872 | 1979 | return true; |
1980 | + } else { |
|
1981 | + return false; |
|
1873 | 1982 | } |
1874 | - else |
|
1875 | - return false; |
|
1983 | + } else { |
|
1984 | + return true; |
|
1876 | 1985 | } |
1877 | - else |
|
1878 | - return true; |
|
1879 | - } |
|
1880 | - elseif (file_exists(dirname(__FILE__) . '/.htaccess')) |
|
1881 | - return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false; |
|
1882 | - elseif (is_writable(dirname(__FILE__))) |
|
1986 | + } elseif (file_exists(dirname(__FILE__) . '/.htaccess')) { |
|
1987 | + return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false; |
|
1988 | + } elseif (is_writable(dirname(__FILE__))) |
|
1883 | 1989 | { |
1884 | 1990 | if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w')) |
1885 | 1991 | { |
1886 | 1992 | fwrite($ht_handle, $htaccess_addition); |
1887 | 1993 | fclose($ht_handle); |
1888 | 1994 | return true; |
1995 | + } else { |
|
1996 | + return false; |
|
1889 | 1997 | } |
1890 | - else |
|
1998 | + } else { |
|
1891 | 1999 | return false; |
1892 | 2000 | } |
1893 | - else |
|
1894 | - return false; |
|
1895 | -} |
|
2001 | + } |
|
1896 | 2002 | |
1897 | 2003 | function template_install_above() |
1898 | 2004 | { |
@@ -1931,9 +2037,10 @@ discard block |
||
1931 | 2037 | <label for="installer_language">', $txt['installer_language'], ':</label> |
1932 | 2038 | <select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">'; |
1933 | 2039 | |
1934 | - foreach ($incontext['detected_languages'] as $lang => $name) |
|
1935 | - echo ' |
|
2040 | + foreach ($incontext['detected_languages'] as $lang => $name) { |
|
2041 | + echo ' |
|
1936 | 2042 | <option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>'; |
2043 | + } |
|
1937 | 2044 | |
1938 | 2045 | echo ' |
1939 | 2046 | </select> |
@@ -1953,9 +2060,10 @@ discard block |
||
1953 | 2060 | <h2>', $txt['upgrade_progress'], '</h2> |
1954 | 2061 | <ul>'; |
1955 | 2062 | |
1956 | - foreach ($incontext['steps'] as $num => $step) |
|
1957 | - echo ' |
|
2063 | + foreach ($incontext['steps'] as $num => $step) { |
|
2064 | + echo ' |
|
1958 | 2065 | <li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>'; |
2066 | + } |
|
1959 | 2067 | |
1960 | 2068 | echo ' |
1961 | 2069 | </ul> |
@@ -1981,20 +2089,23 @@ discard block |
||
1981 | 2089 | echo ' |
1982 | 2090 | <div class="floatright">'; |
1983 | 2091 | |
1984 | - if (!empty($incontext['continue'])) |
|
1985 | - echo ' |
|
2092 | + if (!empty($incontext['continue'])) { |
|
2093 | + echo ' |
|
1986 | 2094 | <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button">'; |
1987 | - if (!empty($incontext['skip'])) |
|
1988 | - echo ' |
|
2095 | + } |
|
2096 | + if (!empty($incontext['skip'])) { |
|
2097 | + echo ' |
|
1989 | 2098 | <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button">'; |
2099 | + } |
|
1990 | 2100 | echo ' |
1991 | 2101 | </div>'; |
1992 | 2102 | } |
1993 | 2103 | |
1994 | 2104 | // Show the closing form tag and other data only if not in the last step |
1995 | - if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) |
|
1996 | - echo ' |
|
2105 | + if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) { |
|
2106 | + echo ' |
|
1997 | 2107 | </form>'; |
2108 | + } |
|
1998 | 2109 | |
1999 | 2110 | echo ' |
2000 | 2111 | </div><!-- .panel --> |
@@ -2027,13 +2138,15 @@ discard block |
||
2027 | 2138 | </div>'; |
2028 | 2139 | |
2029 | 2140 | // Show the warnings, or not. |
2030 | - if (template_warning_divs()) |
|
2031 | - echo ' |
|
2141 | + if (template_warning_divs()) { |
|
2142 | + echo ' |
|
2032 | 2143 | <h3>', $txt['install_all_lovely'], '</h3>'; |
2144 | + } |
|
2033 | 2145 | |
2034 | 2146 | // Say we want the continue button! |
2035 | - if (empty($incontext['error'])) |
|
2036 | - $incontext['continue'] = 1; |
|
2147 | + if (empty($incontext['error'])) { |
|
2148 | + $incontext['continue'] = 1; |
|
2149 | + } |
|
2037 | 2150 | |
2038 | 2151 | // For the latest version stuff. |
2039 | 2152 | echo ' |
@@ -2067,19 +2180,21 @@ discard block |
||
2067 | 2180 | global $txt, $incontext; |
2068 | 2181 | |
2069 | 2182 | // Errors are very serious.. |
2070 | - if (!empty($incontext['error'])) |
|
2071 | - echo ' |
|
2183 | + if (!empty($incontext['error'])) { |
|
2184 | + echo ' |
|
2072 | 2185 | <div class="errorbox"> |
2073 | 2186 | <h3>', $txt['upgrade_critical_error'], '</h3> |
2074 | 2187 | ', $incontext['error'], ' |
2075 | 2188 | </div>'; |
2189 | + } |
|
2076 | 2190 | // A warning message? |
2077 | - elseif (!empty($incontext['warning'])) |
|
2078 | - echo ' |
|
2191 | + elseif (!empty($incontext['warning'])) { |
|
2192 | + echo ' |
|
2079 | 2193 | <div class="errorbox"> |
2080 | 2194 | <h3>', $txt['upgrade_warning'], '</h3> |
2081 | 2195 | ', $incontext['warning'], ' |
2082 | 2196 | </div>'; |
2197 | + } |
|
2083 | 2198 | |
2084 | 2199 | return empty($incontext['error']) && empty($incontext['warning']); |
2085 | 2200 | } |
@@ -2095,26 +2210,29 @@ discard block |
||
2095 | 2210 | <li>', $incontext['failed_files']), '</li> |
2096 | 2211 | </ul>'; |
2097 | 2212 | |
2098 | - if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') |
|
2099 | - echo ' |
|
2213 | + if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') { |
|
2214 | + echo ' |
|
2100 | 2215 | <hr> |
2101 | 2216 | <p>', $txt['chmod_linux_info'], '</p> |
2102 | 2217 | <samp># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</samp>'; |
2218 | + } |
|
2103 | 2219 | |
2104 | 2220 | // This is serious! |
2105 | - if (!template_warning_divs()) |
|
2106 | - return; |
|
2221 | + if (!template_warning_divs()) { |
|
2222 | + return; |
|
2223 | + } |
|
2107 | 2224 | |
2108 | 2225 | echo ' |
2109 | 2226 | <hr> |
2110 | 2227 | <p>', $txt['ftp_setup_info'], '</p>'; |
2111 | 2228 | |
2112 | - if (!empty($incontext['ftp_errors'])) |
|
2113 | - echo ' |
|
2229 | + if (!empty($incontext['ftp_errors'])) { |
|
2230 | + echo ' |
|
2114 | 2231 | <div class="error_message"> |
2115 | 2232 | ', $txt['error_ftp_no_connect'], '<br><br> |
2116 | 2233 | <code>', implode('<br>', $incontext['ftp_errors']), '</code> |
2117 | 2234 | </div>'; |
2235 | + } |
|
2118 | 2236 | |
2119 | 2237 | echo ' |
2120 | 2238 | <form action="', $incontext['form_url'], '" method="post"> |
@@ -2183,16 +2301,16 @@ discard block |
||
2183 | 2301 | <dd> |
2184 | 2302 | <select name="db_type" id="db_type_input" onchange="toggleDBInput();">'; |
2185 | 2303 | |
2186 | - foreach ($incontext['supported_databases'] as $key => $db) |
|
2187 | - echo ' |
|
2304 | + foreach ($incontext['supported_databases'] as $key => $db) { |
|
2305 | + echo ' |
|
2188 | 2306 | <option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>'; |
2307 | + } |
|
2189 | 2308 | |
2190 | 2309 | echo ' |
2191 | 2310 | </select> |
2192 | 2311 | <div class="smalltext">', $txt['db_settings_type_info'], '</div> |
2193 | 2312 | </dd>'; |
2194 | - } |
|
2195 | - else |
|
2313 | + } else |
|
2196 | 2314 | { |
2197 | 2315 | echo ' |
2198 | 2316 | <dd> |
@@ -2360,9 +2478,10 @@ discard block |
||
2360 | 2478 | <div class="red">', $txt['error_db_queries'], '</div> |
2361 | 2479 | <ul>'; |
2362 | 2480 | |
2363 | - foreach ($incontext['failures'] as $line => $fail) |
|
2364 | - echo ' |
|
2481 | + foreach ($incontext['failures'] as $line => $fail) { |
|
2482 | + echo ' |
|
2365 | 2483 | <li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>'; |
2484 | + } |
|
2366 | 2485 | |
2367 | 2486 | echo ' |
2368 | 2487 | </ul>'; |
@@ -2427,15 +2546,16 @@ discard block |
||
2427 | 2546 | </dd> |
2428 | 2547 | </dl>'; |
2429 | 2548 | |
2430 | - if ($incontext['require_db_confirm']) |
|
2431 | - echo ' |
|
2549 | + if ($incontext['require_db_confirm']) { |
|
2550 | + echo ' |
|
2432 | 2551 | <h2>', $txt['user_settings_database'], '</h2> |
2433 | 2552 | <p>', $txt['user_settings_database_info'], '</p> |
2434 | 2553 | |
2435 | 2554 | <div class="lefttext"> |
2436 | 2555 | <input type="password" name="password3" size="30"> |
2437 | 2556 | </div>'; |
2438 | -} |
|
2557 | + } |
|
2558 | + } |
|
2439 | 2559 | |
2440 | 2560 | // Tell them it's done, and to delete. |
2441 | 2561 | function template_delete_install() |
@@ -2448,13 +2568,14 @@ discard block |
||
2448 | 2568 | template_warning_divs(); |
2449 | 2569 | |
2450 | 2570 | // Install directory still writable? |
2451 | - if ($incontext['dir_still_writable']) |
|
2452 | - echo ' |
|
2571 | + if ($incontext['dir_still_writable']) { |
|
2572 | + echo ' |
|
2453 | 2573 | <p><em>', $txt['still_writable'], '</em></p>'; |
2574 | + } |
|
2454 | 2575 | |
2455 | 2576 | // Don't show the box if it's like 99% sure it won't work :P. |
2456 | - if ($incontext['probably_delete_install']) |
|
2457 | - echo ' |
|
2577 | + if ($incontext['probably_delete_install']) { |
|
2578 | + echo ' |
|
2458 | 2579 | <label> |
2459 | 2580 | <input type="checkbox" id="delete_self" onclick="doTheDelete();"> |
2460 | 2581 | <strong>', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</strong> |
@@ -2470,6 +2591,7 @@ discard block |
||
2470 | 2591 | theCheck.disabled = true; |
2471 | 2592 | } |
2472 | 2593 | </script>'; |
2594 | + } |
|
2473 | 2595 | |
2474 | 2596 | echo ' |
2475 | 2597 | <p>', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '</p> |
@@ -430,8 +430,8 @@ |
||
430 | 430 | $real_name = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name'; |
431 | 431 | |
432 | 432 | // Searches. |
433 | - $member_name_search = $member_name . ' ' . $comparison . ' ' . implode( ' OR ' . $member_name . ' ' . $comparison . ' ', $names_list); |
|
434 | - $real_name_search = $real_name . ' ' . $comparison . ' ' . implode( ' OR ' . $real_name . ' ' . $comparison . ' ', $names_list); |
|
433 | + $member_name_search = $member_name . ' ' . $comparison . ' ' . implode(' OR ' . $member_name . ' ' . $comparison . ' ', $names_list); |
|
434 | + $real_name_search = $real_name . ' ' . $comparison . ' ' . implode(' OR ' . $real_name . ' ' . $comparison . ' ', $names_list); |
|
435 | 435 | |
436 | 436 | // Search by username, display name, and email address. |
437 | 437 | $request = $smcFunc['db_query']('', ' |
@@ -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 | * Sets the SMF-style login cookie and session based on the id_member and password passed. |
@@ -47,8 +48,9 @@ discard block |
||
47 | 48 | if (isset($_COOKIE[$cookiename])) |
48 | 49 | { |
49 | 50 | // First check for 2.1 json-format cookie |
50 | - if (preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+,"3":"[^"]+","4":"[^"]+"~', $_COOKIE[$cookiename]) === 1) |
|
51 | - list(,,, $old_domain, $old_path) = $smcFunc['json_decode']($_COOKIE[$cookiename], true); |
|
51 | + if (preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+,"3":"[^"]+","4":"[^"]+"~', $_COOKIE[$cookiename]) === 1) { |
|
52 | + list(,,, $old_domain, $old_path) = $smcFunc['json_decode']($_COOKIE[$cookiename], true); |
|
53 | + } |
|
52 | 54 | |
53 | 55 | // Legacy format (for recent 2.0 --> 2.1 upgrades) |
54 | 56 | elseif (preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;(i:3;i:\d;)?~', $_COOKIE[$cookiename]) === 1) |
@@ -58,15 +60,17 @@ discard block |
||
58 | 60 | $cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2); |
59 | 61 | |
60 | 62 | // Maybe we need to temporarily pretend to be using local cookies |
61 | - if ($cookie_state == 0 && $old_state == 1) |
|
62 | - list($old_domain, $old_path) = url_parts(true, false); |
|
63 | - else |
|
64 | - list($old_domain, $old_path) = url_parts($old_state & 1 > 0, $old_state & 2 > 0); |
|
63 | + if ($cookie_state == 0 && $old_state == 1) { |
|
64 | + list($old_domain, $old_path) = url_parts(true, false); |
|
65 | + } else { |
|
66 | + list($old_domain, $old_path) = url_parts($old_state & 1 > 0, $old_state & 2 > 0); |
|
67 | + } |
|
65 | 68 | } |
66 | 69 | |
67 | 70 | // Out with the old, in with the new! |
68 | - if (isset($old_domain) && $old_domain != $cookie_url[0] || isset($old_path) && $old_path != $cookie_url[1]) |
|
69 | - smf_setcookie($cookiename, $smcFunc['json_encode'](array(0, '', 0, $old_domain, $old_path), JSON_FORCE_OBJECT), 1, $old_path, $old_domain); |
|
71 | + if (isset($old_domain) && $old_domain != $cookie_url[0] || isset($old_path) && $old_path != $cookie_url[1]) { |
|
72 | + smf_setcookie($cookiename, $smcFunc['json_encode'](array(0, '', 0, $old_domain, $old_path), JSON_FORCE_OBJECT), 1, $old_path, $old_domain); |
|
73 | + } |
|
70 | 74 | } |
71 | 75 | |
72 | 76 | // Get the data and path to set it on. |
@@ -82,8 +86,9 @@ discard block |
||
82 | 86 | smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], $cookie_url[0]); |
83 | 87 | |
84 | 88 | // If subdomain-independent cookies are on, unset the subdomain-dependent cookie too. |
85 | - if (empty($id) && !empty($modSettings['globalCookies'])) |
|
86 | - smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], ''); |
|
89 | + if (empty($id) && !empty($modSettings['globalCookies'])) { |
|
90 | + smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], ''); |
|
91 | + } |
|
87 | 92 | |
88 | 93 | // Any alias URLs? This is mainly for use with frames, etc. |
89 | 94 | if (!empty($modSettings['forum_alias_urls'])) |
@@ -99,8 +104,9 @@ discard block |
||
99 | 104 | |
100 | 105 | $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])); |
101 | 106 | |
102 | - if ($cookie_url[0] == '') |
|
103 | - $cookie_url[0] = strtok($alias, '/'); |
|
107 | + if ($cookie_url[0] == '') { |
|
108 | + $cookie_url[0] = strtok($alias, '/'); |
|
109 | + } |
|
104 | 110 | |
105 | 111 | $alias_data = $smcFunc['json_decode']($data, true); |
106 | 112 | $alias_data[3] = $cookie_url[0]; |
@@ -159,8 +165,9 @@ discard block |
||
159 | 165 | smf_setcookie($identifier, $data, $expiry_time, $cookie_url[1], $cookie_url[0]); |
160 | 166 | |
161 | 167 | // If subdomain-independent cookies are on, unset the subdomain-dependent cookie too. |
162 | - if (empty($id) && !empty($modSettings['globalCookies'])) |
|
163 | - smf_setcookie($identifier, $data, $expiry_time, $cookie_url[1], ''); |
|
168 | + if (empty($id) && !empty($modSettings['globalCookies'])) { |
|
169 | + smf_setcookie($identifier, $data, $expiry_time, $cookie_url[1], ''); |
|
170 | + } |
|
164 | 171 | |
165 | 172 | $_COOKIE[$identifier] = $data; |
166 | 173 | } |
@@ -182,23 +189,28 @@ discard block |
||
182 | 189 | $parsed_url = parse_url($boardurl); |
183 | 190 | |
184 | 191 | // Is local cookies off? |
185 | - if (empty($parsed_url['path']) || !$local) |
|
186 | - $parsed_url['path'] = ''; |
|
192 | + if (empty($parsed_url['path']) || !$local) { |
|
193 | + $parsed_url['path'] = ''; |
|
194 | + } |
|
187 | 195 | |
188 | - if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) |
|
189 | - $parsed_url['host'] = $modSettings['globalCookiesDomain']; |
|
196 | + if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) { |
|
197 | + $parsed_url['host'] = $modSettings['globalCookiesDomain']; |
|
198 | + } |
|
190 | 199 | |
191 | 200 | // Globalize cookies across domains (filter out IP-addresses)? |
192 | - elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
193 | - $parsed_url['host'] = '.' . $parts[1]; |
|
201 | + elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
202 | + $parsed_url['host'] = '.' . $parts[1]; |
|
203 | + } |
|
194 | 204 | |
195 | 205 | // We shouldn't use a host at all if both options are off. |
196 | - elseif (!$local && !$global) |
|
197 | - $parsed_url['host'] = ''; |
|
206 | + elseif (!$local && !$global) { |
|
207 | + $parsed_url['host'] = ''; |
|
208 | + } |
|
198 | 209 | |
199 | 210 | // The host also shouldn't be set if there aren't any dots in it. |
200 | - elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) |
|
201 | - $parsed_url['host'] = ''; |
|
211 | + elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) { |
|
212 | + $parsed_url['host'] = ''; |
|
213 | + } |
|
202 | 214 | |
203 | 215 | return array($parsed_url['host'], $parsed_url['path'] . '/'); |
204 | 216 | } |
@@ -217,8 +229,9 @@ discard block |
||
217 | 229 | createToken('login'); |
218 | 230 | |
219 | 231 | // Never redirect to an attachment |
220 | - if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) |
|
221 | - $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
232 | + if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) { |
|
233 | + $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
234 | + } |
|
222 | 235 | |
223 | 236 | $context['sub_template'] = 'kick_guest'; |
224 | 237 | $context['page_title'] = $txt['login']; |
@@ -273,10 +286,12 @@ discard block |
||
273 | 286 | $txt['security_wrong'] = sprintf($txt['security_wrong'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $txt['unknown'], $_SERVER['HTTP_USER_AGENT'], $user_info['ip']); |
274 | 287 | log_error($txt['security_wrong'], 'critical'); |
275 | 288 | |
276 | - if (isset($_POST[$type . '_hash_pass'])) |
|
277 | - unset($_POST[$type . '_hash_pass']); |
|
278 | - if (isset($_POST[$type . '_pass'])) |
|
279 | - unset($_POST[$type . '_pass']); |
|
289 | + if (isset($_POST[$type . '_hash_pass'])) { |
|
290 | + unset($_POST[$type . '_hash_pass']); |
|
291 | + } |
|
292 | + if (isset($_POST[$type . '_pass'])) { |
|
293 | + unset($_POST[$type . '_pass']); |
|
294 | + } |
|
280 | 295 | |
281 | 296 | $context['incorrect_password'] = true; |
282 | 297 | } |
@@ -289,15 +304,17 @@ discard block |
||
289 | 304 | |
290 | 305 | // Now go through $_POST. Make sure the session hash is sent. |
291 | 306 | $_POST[$context['session_var']] = $context['session_id']; |
292 | - foreach ($_POST as $k => $v) |
|
293 | - $context['post_data'] .= adminLogin_outputPostVars($k, $v); |
|
307 | + foreach ($_POST as $k => $v) { |
|
308 | + $context['post_data'] .= adminLogin_outputPostVars($k, $v); |
|
309 | + } |
|
294 | 310 | |
295 | 311 | // Now we'll use the admin_login sub template of the Login template. |
296 | 312 | $context['sub_template'] = 'admin_login'; |
297 | 313 | |
298 | 314 | // And title the page something like "Login". |
299 | - if (!isset($context['page_title'])) |
|
300 | - $context['page_title'] = $txt['login']; |
|
315 | + if (!isset($context['page_title'])) { |
|
316 | + $context['page_title'] = $txt['login']; |
|
317 | + } |
|
301 | 318 | |
302 | 319 | // The type of action. |
303 | 320 | $context['sessionCheckType'] = $type; |
@@ -320,14 +337,15 @@ discard block |
||
320 | 337 | { |
321 | 338 | global $smcFunc; |
322 | 339 | |
323 | - if (!is_array($v)) |
|
324 | - return ' |
|
340 | + if (!is_array($v)) { |
|
341 | + return ' |
|
325 | 342 | <input type="hidden" name="' . $smcFunc['htmlspecialchars']($k) . '" value="' . strtr($v, array('"' => '"', '<' => '<', '>' => '>')) . '">'; |
326 | - else |
|
343 | + } else |
|
327 | 344 | { |
328 | 345 | $ret = ''; |
329 | - foreach ($v as $k2 => $v2) |
|
330 | - $ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2); |
|
346 | + foreach ($v as $k2 => $v2) { |
|
347 | + $ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2); |
|
348 | + } |
|
331 | 349 | |
332 | 350 | return $ret; |
333 | 351 | } |
@@ -354,18 +372,20 @@ discard block |
||
354 | 372 | foreach ($get as $k => $v) |
355 | 373 | { |
356 | 374 | // Only if it's not already in the $scripturl! |
357 | - if (!isset($temp[$k])) |
|
358 | - $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
375 | + if (!isset($temp[$k])) { |
|
376 | + $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
377 | + } |
|
359 | 378 | // If it changed, put it out there, but with an ampersand. |
360 | - elseif ($temp[$k] != $get[$k]) |
|
361 | - $query_string .= urlencode($k) . '=' . urlencode($v) . '&'; |
|
379 | + elseif ($temp[$k] != $get[$k]) { |
|
380 | + $query_string .= urlencode($k) . '=' . urlencode($v) . '&'; |
|
381 | + } |
|
362 | 382 | } |
363 | - } |
|
364 | - else |
|
383 | + } else |
|
365 | 384 | { |
366 | 385 | // Add up all the data from $_GET into get_data. |
367 | - foreach ($get as $k => $v) |
|
368 | - $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
386 | + foreach ($get as $k => $v) { |
|
387 | + $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
388 | + } |
|
369 | 389 | } |
370 | 390 | |
371 | 391 | $query_string = substr($query_string, 0, -1); |
@@ -388,8 +408,9 @@ discard block |
||
388 | 408 | global $scripturl, $user_info, $smcFunc; |
389 | 409 | |
390 | 410 | // If it's not already an array, make it one. |
391 | - if (!is_array($names)) |
|
392 | - $names = explode(',', $names); |
|
411 | + if (!is_array($names)) { |
|
412 | + $names = explode(',', $names); |
|
413 | + } |
|
393 | 414 | |
394 | 415 | $maybe_email = false; |
395 | 416 | $names_list = array(); |
@@ -401,10 +422,11 @@ discard block |
||
401 | 422 | $maybe_email |= strpos($name, '@') !== false; |
402 | 423 | |
403 | 424 | // Make it so standard wildcards will work. (* and ?) |
404 | - if ($use_wildcards) |
|
405 | - $names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => ''')); |
|
406 | - else |
|
407 | - $names[$i] = strtr($names[$i], array('\'' => ''')); |
|
425 | + if ($use_wildcards) { |
|
426 | + $names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => ''')); |
|
427 | + } else { |
|
428 | + $names[$i] = strtr($names[$i], array('\'' => ''')); |
|
429 | + } |
|
408 | 430 | |
409 | 431 | $names_list[] = '{string:lookup_name_' . $i . '}'; |
410 | 432 | $where_params['lookup_name_' . $i] = $names[$i]; |
@@ -417,11 +439,12 @@ discard block |
||
417 | 439 | $results = array(); |
418 | 440 | |
419 | 441 | // This ensures you can't search someones email address if you can't see it. |
420 | - if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) |
|
421 | - $email_condition = ' |
|
442 | + if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) { |
|
443 | + $email_condition = ' |
|
422 | 444 | OR (email_address ' . $comparison . ' \'' . implode('\') OR (email_address ' . $comparison . ' \'', $names) . '\')'; |
423 | - else |
|
424 | - $email_condition = ''; |
|
445 | + } else { |
|
446 | + $email_condition = ''; |
|
447 | + } |
|
425 | 448 | |
426 | 449 | // Get the case of the columns right - but only if we need to as things like MySQL will go slow needlessly otherwise. |
427 | 450 | $member_name = $smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name'; |
@@ -480,10 +503,11 @@ discard block |
||
480 | 503 | $context['template_layers'] = array(); |
481 | 504 | $context['sub_template'] = 'find_members'; |
482 | 505 | |
483 | - if (isset($_REQUEST['search'])) |
|
484 | - $context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES); |
|
485 | - else |
|
486 | - $_REQUEST['start'] = 0; |
|
506 | + if (isset($_REQUEST['search'])) { |
|
507 | + $context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES); |
|
508 | + } else { |
|
509 | + $_REQUEST['start'] = 0; |
|
510 | + } |
|
487 | 511 | |
488 | 512 | // Allow the user to pass the input to be added to to the box. |
489 | 513 | $context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to'; |
@@ -524,10 +548,10 @@ discard block |
||
524 | 548 | ); |
525 | 549 | |
526 | 550 | $context['results'] = array_slice($context['results'], $_REQUEST['start'], 7); |
551 | + } else { |
|
552 | + $context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']); |
|
553 | + } |
|
527 | 554 | } |
528 | - else |
|
529 | - $context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']); |
|
530 | -} |
|
531 | 555 | |
532 | 556 | /** |
533 | 557 | * Outputs each member name on its own line. |
@@ -543,8 +567,9 @@ discard block |
||
543 | 567 | $_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search'])); |
544 | 568 | $_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&' => '&')); |
545 | 569 | |
546 | - if (function_exists('iconv')) |
|
547 | - header('content-type: text/plain; charset=UTF-8'); |
|
570 | + if (function_exists('iconv')) { |
|
571 | + header('content-type: text/plain; charset=UTF-8'); |
|
572 | + } |
|
548 | 573 | |
549 | 574 | $request = $smcFunc['db_query']('', ' |
550 | 575 | SELECT real_name |
@@ -564,14 +589,16 @@ discard block |
||
564 | 589 | if (function_exists('iconv')) |
565 | 590 | { |
566 | 591 | $utf8 = iconv($txt['lang_character_set'], 'UTF-8', $row['real_name']); |
567 | - if ($utf8) |
|
568 | - $row['real_name'] = $utf8; |
|
592 | + if ($utf8) { |
|
593 | + $row['real_name'] = $utf8; |
|
594 | + } |
|
569 | 595 | } |
570 | 596 | |
571 | 597 | $row['real_name'] = strtr($row['real_name'], array('&' => '&', '<' => '<', '>' => '>', '"' => '"')); |
572 | 598 | |
573 | - if (preg_match('~&#\d+;~', $row['real_name']) != 0) |
|
574 | - $row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']); |
|
599 | + if (preg_match('~&#\d+;~', $row['real_name']) != 0) { |
|
600 | + $row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']); |
|
601 | + } |
|
575 | 602 | |
576 | 603 | echo $row['real_name'], "\n"; |
577 | 604 | } |
@@ -628,9 +655,9 @@ discard block |
||
628 | 655 | |
629 | 656 | // Update the database... |
630 | 657 | updateMemberData($memID, array('member_name' => $user, 'passwd' => $newPassword_sha1)); |
658 | + } else { |
|
659 | + updateMemberData($memID, array('passwd' => $newPassword_sha1)); |
|
631 | 660 | } |
632 | - else |
|
633 | - updateMemberData($memID, array('passwd' => $newPassword_sha1)); |
|
634 | 661 | |
635 | 662 | call_integration_hook('integrate_reset_pass', array($old_user, $user, $newPassword)); |
636 | 663 | |
@@ -661,31 +688,37 @@ discard block |
||
661 | 688 | $errors = array(); |
662 | 689 | |
663 | 690 | // Don't use too long a name. |
664 | - if ($smcFunc['strlen']($username) > 25) |
|
665 | - $errors[] = array('lang', 'error_long_name'); |
|
691 | + if ($smcFunc['strlen']($username) > 25) { |
|
692 | + $errors[] = array('lang', 'error_long_name'); |
|
693 | + } |
|
666 | 694 | |
667 | 695 | // No name?! How can you register with no name? |
668 | - if ($username == '') |
|
669 | - $errors[] = array('lang', 'need_username'); |
|
696 | + if ($username == '') { |
|
697 | + $errors[] = array('lang', 'need_username'); |
|
698 | + } |
|
670 | 699 | |
671 | 700 | // Only these characters are permitted. |
672 | - if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) |
|
673 | - $errors[] = array('lang', 'error_invalid_characters_username'); |
|
701 | + if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) { |
|
702 | + $errors[] = array('lang', 'error_invalid_characters_username'); |
|
703 | + } |
|
674 | 704 | |
675 | - if (stristr($username, $txt['guest_title']) !== false) |
|
676 | - $errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title'])); |
|
705 | + if (stristr($username, $txt['guest_title']) !== false) { |
|
706 | + $errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title'])); |
|
707 | + } |
|
677 | 708 | |
678 | 709 | if ($check_reserved_name) |
679 | 710 | { |
680 | 711 | require_once($sourcedir . '/Subs-Members.php'); |
681 | - if (isReservedName($username, $memID, false)) |
|
682 | - $errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']); |
|
712 | + if (isReservedName($username, $memID, false)) { |
|
713 | + $errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']); |
|
714 | + } |
|
683 | 715 | } |
684 | 716 | |
685 | - if ($return_error) |
|
686 | - return $errors; |
|
687 | - elseif (empty($errors)) |
|
688 | - return null; |
|
717 | + if ($return_error) { |
|
718 | + return $errors; |
|
719 | + } elseif (empty($errors)) { |
|
720 | + return null; |
|
721 | + } |
|
689 | 722 | |
690 | 723 | loadLanguage('Errors'); |
691 | 724 | $error = $errors[0]; |
@@ -711,22 +744,26 @@ discard block |
||
711 | 744 | global $modSettings, $smcFunc; |
712 | 745 | |
713 | 746 | // Perform basic requirements first. |
714 | - if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) |
|
715 | - return 'short'; |
|
747 | + if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) { |
|
748 | + return 'short'; |
|
749 | + } |
|
716 | 750 | |
717 | 751 | // Is this enough? |
718 | - if (empty($modSettings['password_strength'])) |
|
719 | - return null; |
|
752 | + if (empty($modSettings['password_strength'])) { |
|
753 | + return null; |
|
754 | + } |
|
720 | 755 | |
721 | 756 | // Otherwise, perform the medium strength test - checking if password appears in the restricted string. |
722 | - if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) |
|
723 | - return 'restricted_words'; |
|
724 | - elseif ($smcFunc['strpos']($password, $username) !== false) |
|
725 | - return 'restricted_words'; |
|
757 | + if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) { |
|
758 | + return 'restricted_words'; |
|
759 | + } elseif ($smcFunc['strpos']($password, $username) !== false) { |
|
760 | + return 'restricted_words'; |
|
761 | + } |
|
726 | 762 | |
727 | 763 | // If just medium, we're done. |
728 | - if ($modSettings['password_strength'] == 1) |
|
729 | - return null; |
|
764 | + if ($modSettings['password_strength'] == 1) { |
|
765 | + return null; |
|
766 | + } |
|
730 | 767 | |
731 | 768 | // Otherwise, hard test next, check for numbers and letters, uppercase too. |
732 | 769 | $good = preg_match('~(\D\d|\d\D)~', $password) != 0; |
@@ -758,14 +795,16 @@ discard block |
||
758 | 795 | ) |
759 | 796 | ); |
760 | 797 | $groups = array(); |
761 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
762 | - $groups[] = $row['id_group']; |
|
798 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
799 | + $groups[] = $row['id_group']; |
|
800 | + } |
|
763 | 801 | $smcFunc['db_free_result']($request); |
764 | 802 | |
765 | - if (empty($groups)) |
|
766 | - $group_query = '0=1'; |
|
767 | - else |
|
768 | - $group_query = 'id_group IN (' . implode(',', $groups) . ')'; |
|
803 | + if (empty($groups)) { |
|
804 | + $group_query = '0=1'; |
|
805 | + } else { |
|
806 | + $group_query = 'id_group IN (' . implode(',', $groups) . ')'; |
|
807 | + } |
|
769 | 808 | } |
770 | 809 | |
771 | 810 | // Then, same again, just the boards this time! |
@@ -775,10 +814,11 @@ discard block |
||
775 | 814 | { |
776 | 815 | $boards = boardsAllowedTo('moderate_board', true); |
777 | 816 | |
778 | - if (empty($boards)) |
|
779 | - $board_query = '0=1'; |
|
780 | - else |
|
781 | - $board_query = 'id_board IN (' . implode(',', $boards) . ')'; |
|
817 | + if (empty($boards)) { |
|
818 | + $board_query = '0=1'; |
|
819 | + } else { |
|
820 | + $board_query = 'id_board IN (' . implode(',', $boards) . ')'; |
|
821 | + } |
|
782 | 822 | } |
783 | 823 | |
784 | 824 | // What boards are they the moderator of? |
@@ -793,8 +833,9 @@ discard block |
||
793 | 833 | 'current_member' => $user_info['id'], |
794 | 834 | ) |
795 | 835 | ); |
796 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
797 | - $boards_mod[] = $row['id_board']; |
|
836 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
837 | + $boards_mod[] = $row['id_board']; |
|
838 | + } |
|
798 | 839 | $smcFunc['db_free_result']($request); |
799 | 840 | |
800 | 841 | // Can any of the groups they're in moderate any of the boards? |
@@ -806,8 +847,9 @@ discard block |
||
806 | 847 | 'groups' => $user_info['groups'], |
807 | 848 | ) |
808 | 849 | ); |
809 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
810 | - $boards_mod[] = $row['id_board']; |
|
850 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
851 | + $boards_mod[] = $row['id_board']; |
|
852 | + } |
|
811 | 853 | $smcFunc['db_free_result']($request); |
812 | 854 | |
813 | 855 | // Just in case we've got duplicates here... |
@@ -852,10 +894,12 @@ discard block |
||
852 | 894 | global $modSettings; |
853 | 895 | |
854 | 896 | // In case a customization wants to override the default settings |
855 | - if ($httponly === null) |
|
856 | - $httponly = !empty($modSettings['httponlyCookies']); |
|
857 | - if ($secure === null) |
|
858 | - $secure = !empty($modSettings['secureCookies']); |
|
897 | + if ($httponly === null) { |
|
898 | + $httponly = !empty($modSettings['httponlyCookies']); |
|
899 | + } |
|
900 | + if ($secure === null) { |
|
901 | + $secure = !empty($modSettings['secureCookies']); |
|
902 | + } |
|
859 | 903 | |
860 | 904 | // Intercept cookie? |
861 | 905 | call_integration_hook('integrate_cookie', array($name, $value, $expire, $path, $domain, $secure, $httponly)); |
@@ -875,8 +919,9 @@ discard block |
||
875 | 919 | function hash_password($username, $password, $cost = null) |
876 | 920 | { |
877 | 921 | global $sourcedir, $smcFunc, $modSettings; |
878 | - if (!function_exists('password_hash')) |
|
879 | - require_once($sourcedir . '/Subs-Password.php'); |
|
922 | + if (!function_exists('password_hash')) { |
|
923 | + require_once($sourcedir . '/Subs-Password.php'); |
|
924 | + } |
|
880 | 925 | |
881 | 926 | $cost = empty($cost) ? (empty($modSettings['bcrypt_hash_cost']) ? 10 : $modSettings['bcrypt_hash_cost']) : $cost; |
882 | 927 | |
@@ -908,8 +953,9 @@ discard block |
||
908 | 953 | function hash_verify_password($username, $password, $hash) |
909 | 954 | { |
910 | 955 | global $sourcedir, $smcFunc; |
911 | - if (!function_exists('password_verify')) |
|
912 | - require_once($sourcedir . '/Subs-Password.php'); |
|
956 | + if (!function_exists('password_verify')) { |
|
957 | + require_once($sourcedir . '/Subs-Password.php'); |
|
958 | + } |
|
913 | 959 | |
914 | 960 | return password_verify($smcFunc['strtolower']($username) . $password, $hash); |
915 | 961 | } |