@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Dispatches to the right function based on the given subaction. |
@@ -176,8 +177,9 @@ discard block |
||
176 | 177 | // If it's inherited, just add it as a child. |
177 | 178 | if ($row['id_parent'] != -2) |
178 | 179 | { |
179 | - if (isset($context['groups'][$row['id_parent']])) |
|
180 | - $context['groups'][$row['id_parent']]['children'][$row['id_group']] = $row['group_name']; |
|
180 | + if (isset($context['groups'][$row['id_parent']])) { |
|
181 | + $context['groups'][$row['id_parent']]['children'][$row['id_group']] = $row['group_name']; |
|
182 | + } |
|
181 | 183 | continue; |
182 | 184 | } |
183 | 185 | |
@@ -202,10 +204,11 @@ discard block |
||
202 | 204 | 'access' => false, |
203 | 205 | ); |
204 | 206 | |
205 | - if ($row['min_posts'] == -1) |
|
206 | - $normalGroups[$row['id_group']] = $row['id_group']; |
|
207 | - else |
|
208 | - $postGroups[$row['id_group']] = $row['id_group']; |
|
207 | + if ($row['min_posts'] == -1) { |
|
208 | + $normalGroups[$row['id_group']] = $row['id_group']; |
|
209 | + } else { |
|
210 | + $postGroups[$row['id_group']] = $row['id_group']; |
|
211 | + } |
|
209 | 212 | } |
210 | 213 | $smcFunc['db_free_result']($query); |
211 | 214 | |
@@ -221,8 +224,9 @@ discard block |
||
221 | 224 | 'post_group_list' => $postGroups, |
222 | 225 | ) |
223 | 226 | ); |
224 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
225 | - $context['groups'][$row['id_group']]['num_members'] += $row['num_members']; |
|
227 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
228 | + $context['groups'][$row['id_group']]['num_members'] += $row['num_members']; |
|
229 | + } |
|
226 | 230 | $smcFunc['db_free_result']($query); |
227 | 231 | } |
228 | 232 | |
@@ -238,8 +242,9 @@ discard block |
||
238 | 242 | 'normal_group_list' => $normalGroups, |
239 | 243 | ) |
240 | 244 | ); |
241 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
242 | - $context['groups'][$row['id_group']]['num_members'] += $row['num_members']; |
|
245 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
246 | + $context['groups'][$row['id_group']]['num_members'] += $row['num_members']; |
|
247 | + } |
|
243 | 248 | $smcFunc['db_free_result']($query); |
244 | 249 | |
245 | 250 | // This one is slower, but it's okay... careful not to count twice! |
@@ -256,15 +261,17 @@ discard block |
||
256 | 261 | 'blank_string' => '', |
257 | 262 | ) |
258 | 263 | ); |
259 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
260 | - $context['groups'][$row['id_group']]['num_members'] += $row['num_members']; |
|
264 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
265 | + $context['groups'][$row['id_group']]['num_members'] += $row['num_members']; |
|
266 | + } |
|
261 | 267 | $smcFunc['db_free_result']($query); |
262 | 268 | } |
263 | 269 | |
264 | 270 | foreach ($context['groups'] as $id => $data) |
265 | 271 | { |
266 | - if ($data['href'] != '') |
|
267 | - $context['groups'][$id]['link'] = '<a href="' . $data['href'] . '">' . $data['num_members'] . '</a>'; |
|
272 | + if ($data['href'] != '') { |
|
273 | + $context['groups'][$id]['link'] = '<a href="' . $data['href'] . '">' . $data['num_members'] . '</a>'; |
|
274 | + } |
|
268 | 275 | } |
269 | 276 | |
270 | 277 | if (empty($_REQUEST['pid'])) |
@@ -278,9 +285,10 @@ discard block |
||
278 | 285 | 'hidden_permissions' => !empty($context['hidden_permissions']) ? $context['hidden_permissions'] : array(), |
279 | 286 | ) |
280 | 287 | ); |
281 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
282 | - if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1)) |
|
288 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
289 | + if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1)) |
|
283 | 290 | $context['groups'][(int) $row['id_group']]['num_permissions'][empty($row['add_deny']) ? 'denied' : 'allowed'] = $row['num_permissions']; |
291 | + } |
|
284 | 292 | $smcFunc['db_free_result']($request); |
285 | 293 | |
286 | 294 | // Get the "default" profile permissions too. |
@@ -297,17 +305,18 @@ discard block |
||
297 | 305 | ); |
298 | 306 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
299 | 307 | { |
300 | - if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1)) |
|
301 | - $context['groups'][(int) $row['id_group']]['num_permissions'][empty($row['add_deny']) ? 'denied' : 'allowed'] += $row['num_permissions']; |
|
308 | + if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1)) { |
|
309 | + $context['groups'][(int) $row['id_group']]['num_permissions'][empty($row['add_deny']) ? 'denied' : 'allowed'] += $row['num_permissions']; |
|
310 | + } |
|
302 | 311 | } |
303 | 312 | $smcFunc['db_free_result']($request); |
304 | - } |
|
305 | - else |
|
313 | + } else |
|
306 | 314 | { |
307 | 315 | $_REQUEST['pid'] = (int) $_REQUEST['pid']; |
308 | 316 | |
309 | - if (!isset($context['profiles'][$_REQUEST['pid']])) |
|
310 | - fatal_lang_error('no_access', false); |
|
317 | + if (!isset($context['profiles'][$_REQUEST['pid']])) { |
|
318 | + fatal_lang_error('no_access', false); |
|
319 | + } |
|
311 | 320 | |
312 | 321 | // Change the selected tab to better reflect that this really is a board profile. |
313 | 322 | $context[$context['admin_menu_name']]['current_subsection'] = 'profiles'; |
@@ -323,8 +332,9 @@ discard block |
||
323 | 332 | ); |
324 | 333 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
325 | 334 | { |
326 | - if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1)) |
|
327 | - $context['groups'][(int) $row['id_group']]['num_permissions'][empty($row['add_deny']) ? 'denied' : 'allowed'] += $row['num_permissions']; |
|
335 | + if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1)) { |
|
336 | + $context['groups'][(int) $row['id_group']]['num_permissions'][empty($row['add_deny']) ? 'denied' : 'allowed'] += $row['num_permissions']; |
|
337 | + } |
|
328 | 338 | } |
329 | 339 | $smcFunc['db_free_result']($request); |
330 | 340 | |
@@ -366,8 +376,8 @@ discard block |
||
366 | 376 | |
367 | 377 | if (!empty($changes)) |
368 | 378 | { |
369 | - foreach ($changes as $profile => $boards) |
|
370 | - $smcFunc['db_query']('', ' |
|
379 | + foreach ($changes as $profile => $boards) { |
|
380 | + $smcFunc['db_query']('', ' |
|
371 | 381 | UPDATE {db_prefix}boards |
372 | 382 | SET id_profile = {int:current_profile} |
373 | 383 | WHERE id_board IN ({array_int:board_list})', |
@@ -376,6 +386,7 @@ discard block |
||
376 | 386 | 'current_profile' => $profile, |
377 | 387 | ) |
378 | 388 | ); |
389 | + } |
|
379 | 390 | } |
380 | 391 | |
381 | 392 | $context['edit_all'] = false; |
@@ -400,8 +411,9 @@ discard block |
||
400 | 411 | ); |
401 | 412 | foreach ($boardList[$catid] as $boardid) |
402 | 413 | { |
403 | - if (!isset($context['profiles'][$boards[$boardid]['profile']])) |
|
404 | - $boards[$boardid]['profile'] = 1; |
|
414 | + if (!isset($context['profiles'][$boards[$boardid]['profile']])) { |
|
415 | + $boards[$boardid]['profile'] = 1; |
|
416 | + } |
|
405 | 417 | |
406 | 418 | $context['categories'][$catid]['boards'][$boardid] = array( |
407 | 419 | 'id' => &$boards[$boardid]['id'], |
@@ -433,64 +445,74 @@ discard block |
||
433 | 445 | loadIllegalGuestPermissions(); |
434 | 446 | |
435 | 447 | // Make sure only one of the quick options was selected. |
436 | - if ((!empty($_POST['predefined']) && ((isset($_POST['copy_from']) && $_POST['copy_from'] != 'empty') || !empty($_POST['permissions']))) || (!empty($_POST['copy_from']) && $_POST['copy_from'] != 'empty' && !empty($_POST['permissions']))) |
|
437 | - fatal_lang_error('permissions_only_one_option', false); |
|
448 | + if ((!empty($_POST['predefined']) && ((isset($_POST['copy_from']) && $_POST['copy_from'] != 'empty') || !empty($_POST['permissions']))) || (!empty($_POST['copy_from']) && $_POST['copy_from'] != 'empty' && !empty($_POST['permissions']))) { |
|
449 | + fatal_lang_error('permissions_only_one_option', false); |
|
450 | + } |
|
438 | 451 | |
439 | - if (empty($_POST['group']) || !is_array($_POST['group'])) |
|
440 | - $_POST['group'] = array(); |
|
452 | + if (empty($_POST['group']) || !is_array($_POST['group'])) { |
|
453 | + $_POST['group'] = array(); |
|
454 | + } |
|
441 | 455 | |
442 | 456 | // Only accept numeric values for selected membergroups. |
443 | - foreach ($_POST['group'] as $id => $group_id) |
|
444 | - $_POST['group'][$id] = (int) $group_id; |
|
457 | + foreach ($_POST['group'] as $id => $group_id) { |
|
458 | + $_POST['group'][$id] = (int) $group_id; |
|
459 | + } |
|
445 | 460 | $_POST['group'] = array_unique($_POST['group']); |
446 | 461 | |
447 | - if (empty($_REQUEST['pid'])) |
|
448 | - $_REQUEST['pid'] = 0; |
|
449 | - else |
|
450 | - $_REQUEST['pid'] = (int) $_REQUEST['pid']; |
|
462 | + if (empty($_REQUEST['pid'])) { |
|
463 | + $_REQUEST['pid'] = 0; |
|
464 | + } else { |
|
465 | + $_REQUEST['pid'] = (int) $_REQUEST['pid']; |
|
466 | + } |
|
451 | 467 | |
452 | 468 | // Fix up the old global to the new default! |
453 | 469 | $bid = max(1, $_REQUEST['pid']); |
454 | 470 | |
455 | 471 | // No modifying the predefined profiles. |
456 | - if ($_REQUEST['pid'] > 1 && $_REQUEST['pid'] < 5) |
|
457 | - fatal_lang_error('no_access', false); |
|
472 | + if ($_REQUEST['pid'] > 1 && $_REQUEST['pid'] < 5) { |
|
473 | + fatal_lang_error('no_access', false); |
|
474 | + } |
|
458 | 475 | |
459 | 476 | // Clear out any cached authority. |
460 | 477 | updateSettings(array('settings_updated' => time())); |
461 | 478 | |
462 | 479 | // No groups where selected. |
463 | - if (empty($_POST['group'])) |
|
464 | - redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']); |
|
480 | + if (empty($_POST['group'])) { |
|
481 | + redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']); |
|
482 | + } |
|
465 | 483 | |
466 | 484 | // Set a predefined permission profile. |
467 | 485 | if (!empty($_POST['predefined'])) |
468 | 486 | { |
469 | 487 | // Make sure it's a predefined permission set we expect. |
470 | - if (!in_array($_POST['predefined'], array('restrict', 'standard', 'moderator', 'maintenance'))) |
|
471 | - redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']); |
|
488 | + if (!in_array($_POST['predefined'], array('restrict', 'standard', 'moderator', 'maintenance'))) { |
|
489 | + redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']); |
|
490 | + } |
|
472 | 491 | |
473 | 492 | foreach ($_POST['group'] as $group_id) |
474 | 493 | { |
475 | - if (!empty($_REQUEST['pid'])) |
|
476 | - setPermissionLevel($_POST['predefined'], $group_id, $_REQUEST['pid']); |
|
477 | - else |
|
478 | - setPermissionLevel($_POST['predefined'], $group_id); |
|
494 | + if (!empty($_REQUEST['pid'])) { |
|
495 | + setPermissionLevel($_POST['predefined'], $group_id, $_REQUEST['pid']); |
|
496 | + } else { |
|
497 | + setPermissionLevel($_POST['predefined'], $group_id); |
|
498 | + } |
|
479 | 499 | } |
480 | 500 | } |
481 | 501 | // Set a permission profile based on the permissions of a selected group. |
482 | 502 | elseif ($_POST['copy_from'] != 'empty') |
483 | 503 | { |
484 | 504 | // Just checking the input. |
485 | - if (!is_numeric($_POST['copy_from'])) |
|
486 | - redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']); |
|
505 | + if (!is_numeric($_POST['copy_from'])) { |
|
506 | + redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']); |
|
507 | + } |
|
487 | 508 | |
488 | 509 | // Make sure the group we're copying to is never included. |
489 | 510 | $_POST['group'] = array_diff($_POST['group'], array($_POST['copy_from'])); |
490 | 511 | |
491 | 512 | // No groups left? Too bad. |
492 | - if (empty($_POST['group'])) |
|
493 | - redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']); |
|
513 | + if (empty($_POST['group'])) { |
|
514 | + redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']); |
|
515 | + } |
|
494 | 516 | |
495 | 517 | if (empty($_REQUEST['pid'])) |
496 | 518 | { |
@@ -504,22 +526,26 @@ discard block |
||
504 | 526 | ) |
505 | 527 | ); |
506 | 528 | $target_perm = array(); |
507 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
508 | - $target_perm[$row['permission']] = $row['add_deny']; |
|
529 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
530 | + $target_perm[$row['permission']] = $row['add_deny']; |
|
531 | + } |
|
509 | 532 | $smcFunc['db_free_result']($request); |
510 | 533 | |
511 | 534 | $inserts = array(); |
512 | - foreach ($_POST['group'] as $group_id) |
|
513 | - foreach ($target_perm as $perm => $add_deny) |
|
535 | + foreach ($_POST['group'] as $group_id) { |
|
536 | + foreach ($target_perm as $perm => $add_deny) |
|
514 | 537 | { |
515 | 538 | // No dodgy permissions please! |
516 | 539 | if (!empty($context['illegal_permissions']) && in_array($perm, $context['illegal_permissions'])) |
517 | 540 | continue; |
518 | - if ($group_id == -1 && in_array($perm, $context['non_guest_permissions'])) |
|
519 | - continue; |
|
541 | + } |
|
542 | + if ($group_id == -1 && in_array($perm, $context['non_guest_permissions'])) { |
|
543 | + continue; |
|
544 | + } |
|
520 | 545 | |
521 | - if ($group_id != 1 && $group_id != 3) |
|
522 | - $inserts[] = array($perm, $group_id, $add_deny); |
|
546 | + if ($group_id != 1 && $group_id != 3) { |
|
547 | + $inserts[] = array($perm, $group_id, $add_deny); |
|
548 | + } |
|
523 | 549 | } |
524 | 550 | |
525 | 551 | // Delete the previous permissions... |
@@ -559,17 +585,19 @@ discard block |
||
559 | 585 | ) |
560 | 586 | ); |
561 | 587 | $target_perm = array(); |
562 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
563 | - $target_perm[$row['permission']] = $row['add_deny']; |
|
588 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
589 | + $target_perm[$row['permission']] = $row['add_deny']; |
|
590 | + } |
|
564 | 591 | $smcFunc['db_free_result']($request); |
565 | 592 | |
566 | 593 | $inserts = array(); |
567 | - foreach ($_POST['group'] as $group_id) |
|
568 | - foreach ($target_perm as $perm => $add_deny) |
|
594 | + foreach ($_POST['group'] as $group_id) { |
|
595 | + foreach ($target_perm as $perm => $add_deny) |
|
569 | 596 | { |
570 | 597 | // Are these for guests? |
571 | 598 | if ($group_id == -1 && in_array($perm, $context['non_guest_permissions'])) |
572 | 599 | continue; |
600 | + } |
|
573 | 601 | |
574 | 602 | $inserts[] = array($perm, $group_id, $bid, $add_deny); |
575 | 603 | } |
@@ -607,13 +635,14 @@ discard block |
||
607 | 635 | list ($permissionType, $permission) = explode('/', $_POST['permissions']); |
608 | 636 | |
609 | 637 | // Check whether our input is within expected range. |
610 | - if (!in_array($_POST['add_remove'], array('add', 'clear', 'deny')) || !in_array($permissionType, array('membergroup', 'board'))) |
|
611 | - redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']); |
|
638 | + if (!in_array($_POST['add_remove'], array('add', 'clear', 'deny')) || !in_array($permissionType, array('membergroup', 'board'))) { |
|
639 | + redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']); |
|
640 | + } |
|
612 | 641 | |
613 | 642 | if ($_POST['add_remove'] == 'clear') |
614 | 643 | { |
615 | - if ($permissionType == 'membergroup') |
|
616 | - $smcFunc['db_query']('', ' |
|
644 | + if ($permissionType == 'membergroup') { |
|
645 | + $smcFunc['db_query']('', ' |
|
617 | 646 | DELETE FROM {db_prefix}permissions |
618 | 647 | WHERE id_group IN ({array_int:current_group_list}) |
619 | 648 | AND permission = {string:current_permission} |
@@ -624,8 +653,8 @@ discard block |
||
624 | 653 | 'illegal_permissions' => !empty($context['illegal_permissions']) ? $context['illegal_permissions'] : array(), |
625 | 654 | ) |
626 | 655 | ); |
627 | - else |
|
628 | - $smcFunc['db_query']('', ' |
|
656 | + } else { |
|
657 | + $smcFunc['db_query']('', ' |
|
629 | 658 | DELETE FROM {db_prefix}board_permissions |
630 | 659 | WHERE id_group IN ({array_int:current_group_list}) |
631 | 660 | AND id_profile = {int:current_profile} |
@@ -636,6 +665,7 @@ discard block |
||
636 | 665 | 'current_permission' => $permission, |
637 | 666 | ) |
638 | 667 | ); |
668 | + } |
|
639 | 669 | } |
640 | 670 | // Add a permission (either 'set' or 'deny'). |
641 | 671 | else |
@@ -644,32 +674,36 @@ discard block |
||
644 | 674 | $permChange = array(); |
645 | 675 | foreach ($_POST['group'] as $groupID) |
646 | 676 | { |
647 | - if ($groupID == -1 && in_array($permission, $context['non_guest_permissions'])) |
|
648 | - continue; |
|
677 | + if ($groupID == -1 && in_array($permission, $context['non_guest_permissions'])) { |
|
678 | + continue; |
|
679 | + } |
|
649 | 680 | |
650 | - if ($permissionType == 'membergroup' && $groupID != 1 && $groupID != 3 && (empty($context['illegal_permissions']) || !in_array($permission, $context['illegal_permissions']))) |
|
651 | - $permChange[] = array($permission, $groupID, $add_deny); |
|
652 | - elseif ($permissionType != 'membergroup') |
|
653 | - $permChange[] = array($permission, $groupID, $bid, $add_deny); |
|
681 | + if ($permissionType == 'membergroup' && $groupID != 1 && $groupID != 3 && (empty($context['illegal_permissions']) || !in_array($permission, $context['illegal_permissions']))) { |
|
682 | + $permChange[] = array($permission, $groupID, $add_deny); |
|
683 | + } elseif ($permissionType != 'membergroup') { |
|
684 | + $permChange[] = array($permission, $groupID, $bid, $add_deny); |
|
685 | + } |
|
654 | 686 | } |
655 | 687 | |
656 | 688 | if (!empty($permChange)) |
657 | 689 | { |
658 | - if ($permissionType == 'membergroup') |
|
659 | - $smcFunc['db_insert']('replace', |
|
690 | + if ($permissionType == 'membergroup') { |
|
691 | + $smcFunc['db_insert']('replace', |
|
660 | 692 | '{db_prefix}permissions', |
661 | 693 | array('permission' => 'string', 'id_group' => 'int', 'add_deny' => 'int'), |
662 | 694 | $permChange, |
663 | 695 | array('permission', 'id_group') |
664 | 696 | ); |
697 | + } |
|
665 | 698 | // Board permissions go into the other table. |
666 | - else |
|
667 | - $smcFunc['db_insert']('replace', |
|
699 | + else { |
|
700 | + $smcFunc['db_insert']('replace', |
|
668 | 701 | '{db_prefix}board_permissions', |
669 | 702 | array('permission' => 'string', 'id_group' => 'int', 'id_profile' => 'int', 'add_deny' => 'int'), |
670 | 703 | $permChange, |
671 | 704 | array('permission', 'id_group', 'id_profile') |
672 | 705 | ); |
706 | + } |
|
673 | 707 | } |
674 | 708 | } |
675 | 709 | |
@@ -687,14 +721,16 @@ discard block |
||
687 | 721 | { |
688 | 722 | global $context, $txt, $smcFunc, $modSettings; |
689 | 723 | |
690 | - if (!isset($_GET['group'])) |
|
691 | - fatal_lang_error('no_access', false); |
|
724 | + if (!isset($_GET['group'])) { |
|
725 | + fatal_lang_error('no_access', false); |
|
726 | + } |
|
692 | 727 | |
693 | 728 | $context['group']['id'] = (int) $_GET['group']; |
694 | 729 | |
695 | 730 | // It's not likely you'd end up here with this setting disabled. |
696 | - if ($_GET['group'] == 1) |
|
697 | - redirectexit('action=admin;area=permissions'); |
|
731 | + if ($_GET['group'] == 1) { |
|
732 | + redirectexit('action=admin;area=permissions'); |
|
733 | + } |
|
698 | 734 | |
699 | 735 | loadAllPermissions(); |
700 | 736 | loadPermissionProfiles(); |
@@ -715,13 +751,14 @@ discard block |
||
715 | 751 | $smcFunc['db_free_result']($result); |
716 | 752 | |
717 | 753 | // Cannot edit an inherited group! |
718 | - if ($parent != -2) |
|
719 | - fatal_lang_error('cannot_edit_permissions_inherited'); |
|
754 | + if ($parent != -2) { |
|
755 | + fatal_lang_error('cannot_edit_permissions_inherited'); |
|
756 | + } |
|
757 | + } elseif ($context['group']['id'] == -1) { |
|
758 | + $context['group']['name'] = $txt['membergroups_guests']; |
|
759 | + } else { |
|
760 | + $context['group']['name'] = $txt['membergroups_members']; |
|
720 | 761 | } |
721 | - elseif ($context['group']['id'] == -1) |
|
722 | - $context['group']['name'] = $txt['membergroups_guests']; |
|
723 | - else |
|
724 | - $context['group']['name'] = $txt['membergroups_members']; |
|
725 | 762 | |
726 | 763 | $context['profile']['id'] = empty($_GET['pid']) ? 0 : (int) $_GET['pid']; |
727 | 764 | |
@@ -767,8 +804,9 @@ discard block |
||
767 | 804 | 'current_group' => $_GET['group'], |
768 | 805 | ) |
769 | 806 | ); |
770 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
771 | - $permissions['membergroup'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['permission']; |
|
807 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
808 | + $permissions['membergroup'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['permission']; |
|
809 | + } |
|
772 | 810 | $smcFunc['db_free_result']($result); |
773 | 811 | } |
774 | 812 | |
@@ -783,8 +821,9 @@ discard block |
||
783 | 821 | 'current_profile' => $context['permission_type'] == 'membergroup' ? 1 : $context['profile']['id'], |
784 | 822 | ) |
785 | 823 | ); |
786 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
787 | - $permissions['board'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['permission']; |
|
824 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
825 | + $permissions['board'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['permission']; |
|
826 | + } |
|
788 | 827 | $smcFunc['db_free_result']($result); |
789 | 828 | |
790 | 829 | // Loop through each permission and set whether it's checked. |
@@ -803,9 +842,9 @@ discard block |
||
803 | 842 | { |
804 | 843 | $curPerm['any']['select'] = in_array($perm['id'] . '_any', $permissions[$permissionType]['allowed']) ? 'on' : (in_array($perm['id'] . '_any', $permissions[$permissionType]['denied']) ? 'deny' : 'off'); |
805 | 844 | $curPerm['own']['select'] = in_array($perm['id'] . '_own', $permissions[$permissionType]['allowed']) ? 'on' : (in_array($perm['id'] . '_own', $permissions[$permissionType]['denied']) ? 'deny' : 'off'); |
845 | + } else { |
|
846 | + $curPerm['select'] = in_array($perm['id'], $permissions[$permissionType]['denied']) ? 'deny' : (in_array($perm['id'], $permissions[$permissionType]['allowed']) ? 'on' : 'off'); |
|
806 | 847 | } |
807 | - else |
|
808 | - $curPerm['select'] = in_array($perm['id'], $permissions[$permissionType]['denied']) ? 'deny' : (in_array($perm['id'], $permissions[$permissionType]['allowed']) ? 'on' : 'off'); |
|
809 | 848 | |
810 | 849 | // Keep the last value if it's hidden. |
811 | 850 | if ($perm['hidden'] || $permissionArray['hidden']) |
@@ -822,13 +861,13 @@ discard block |
||
822 | 861 | $perm['any']['id'], |
823 | 862 | $curPerm['any']['select'] == 'deny' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $curPerm['any']['select'], |
824 | 863 | ); |
825 | - } |
|
826 | - else |
|
827 | - $context['hidden_perms'][] = array( |
|
864 | + } else { |
|
865 | + $context['hidden_perms'][] = array( |
|
828 | 866 | $permissionType, |
829 | 867 | $perm['id'], |
830 | 868 | $curPerm['select'] == 'deny' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $curPerm['select'], |
831 | 869 | ); |
870 | + } |
|
832 | 871 | } |
833 | 872 | } |
834 | 873 | } |
@@ -856,13 +895,14 @@ discard block |
||
856 | 895 | $_GET['pid'] = (int) $_GET['pid']; |
857 | 896 | |
858 | 897 | // Cannot modify predefined profiles. |
859 | - if ($_GET['pid'] > 1 && $_GET['pid'] < 5) |
|
860 | - fatal_lang_error('no_access', false); |
|
898 | + if ($_GET['pid'] > 1 && $_GET['pid'] < 5) { |
|
899 | + fatal_lang_error('no_access', false); |
|
900 | + } |
|
861 | 901 | |
862 | 902 | // Verify this isn't inherited. |
863 | - if ($_GET['group'] == -1 || $_GET['group'] == 0) |
|
864 | - $parent = -2; |
|
865 | - else |
|
903 | + if ($_GET['group'] == -1 || $_GET['group'] == 0) { |
|
904 | + $parent = -2; |
|
905 | + } else |
|
866 | 906 | { |
867 | 907 | $result = $smcFunc['db_query']('', ' |
868 | 908 | SELECT id_parent |
@@ -877,8 +917,9 @@ discard block |
||
877 | 917 | $smcFunc['db_free_result']($result); |
878 | 918 | } |
879 | 919 | |
880 | - if ($parent != -2) |
|
881 | - fatal_lang_error('cannot_edit_permissions_inherited'); |
|
920 | + if ($parent != -2) { |
|
921 | + fatal_lang_error('cannot_edit_permissions_inherited'); |
|
922 | + } |
|
882 | 923 | |
883 | 924 | $givePerms = array('membergroup' => array(), 'board' => array()); |
884 | 925 | |
@@ -896,12 +937,13 @@ discard block |
||
896 | 937 | { |
897 | 938 | if (is_array($perm_array)) |
898 | 939 | { |
899 | - foreach ($perm_array as $permission => $value) |
|
900 | - if ($value == 'on' || $value == 'deny') |
|
940 | + foreach ($perm_array as $permission => $value) { |
|
941 | + if ($value == 'on' || $value == 'deny') |
|
901 | 942 | { |
902 | 943 | // Don't allow people to escalate themselves! |
903 | 944 | if (!empty($context['illegal_permissions']) && in_array($permission, $context['illegal_permissions'])) |
904 | 945 | continue; |
946 | + } |
|
905 | 947 | |
906 | 948 | $givePerms[$perm_type][] = array($_GET['group'], $permission, $value == 'deny' ? 0 : 1); |
907 | 949 | } |
@@ -946,8 +988,9 @@ discard block |
||
946 | 988 | ); |
947 | 989 | if (!empty($givePerms['board'])) |
948 | 990 | { |
949 | - foreach ($givePerms['board'] as $k => $v) |
|
950 | - $givePerms['board'][$k][] = $profileid; |
|
991 | + foreach ($givePerms['board'] as $k => $v) { |
|
992 | + $givePerms['board'][$k][] = $profileid; |
|
993 | + } |
|
951 | 994 | $smcFunc['db_insert']('replace', |
952 | 995 | '{db_prefix}board_permissions', |
953 | 996 | array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int', 'id_profile' => 'int'), |
@@ -988,8 +1031,9 @@ discard block |
||
988 | 1031 | |
989 | 1032 | call_integration_hook('integrate_modify_permission_settings', array(&$config_vars)); |
990 | 1033 | |
991 | - if ($return_config) |
|
992 | - return $config_vars; |
|
1034 | + if ($return_config) { |
|
1035 | + return $config_vars; |
|
1036 | + } |
|
993 | 1037 | |
994 | 1038 | $context['page_title'] = $txt['permission_settings_title']; |
995 | 1039 | $context['sub_template'] = 'show_settings'; |
@@ -1040,8 +1084,9 @@ discard block |
||
1040 | 1084 | 'min_posts' => -1, |
1041 | 1085 | ) |
1042 | 1086 | ); |
1043 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1044 | - $post_groups[] = $row['id_group']; |
|
1087 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1088 | + $post_groups[] = $row['id_group']; |
|
1089 | + } |
|
1045 | 1090 | $smcFunc['db_free_result']($request); |
1046 | 1091 | |
1047 | 1092 | // Remove'em. |
@@ -1250,16 +1295,19 @@ discard block |
||
1250 | 1295 | // Make sure we're not granting someone too many permissions! |
1251 | 1296 | foreach ($groupLevels['global'][$level] as $k => $permission) |
1252 | 1297 | { |
1253 | - if (!empty($context['illegal_permissions']) && in_array($permission, $context['illegal_permissions'])) |
|
1254 | - unset($groupLevels['global'][$level][$k]); |
|
1298 | + if (!empty($context['illegal_permissions']) && in_array($permission, $context['illegal_permissions'])) { |
|
1299 | + unset($groupLevels['global'][$level][$k]); |
|
1300 | + } |
|
1255 | 1301 | |
1256 | - if ($group == -1 && in_array($permission, $context['non_guest_permissions'])) |
|
1257 | - unset($groupLevels['global'][$level][$k]); |
|
1302 | + if ($group == -1 && in_array($permission, $context['non_guest_permissions'])) { |
|
1303 | + unset($groupLevels['global'][$level][$k]); |
|
1304 | + } |
|
1258 | 1305 | } |
1259 | - if ($group == -1) |
|
1260 | - foreach ($groupLevels['board'][$level] as $k => $permission) |
|
1306 | + if ($group == -1) { |
|
1307 | + foreach ($groupLevels['board'][$level] as $k => $permission) |
|
1261 | 1308 | if (in_array($permission, $context['non_guest_permissions'])) |
1262 | 1309 | unset($groupLevels['board'][$level][$k]); |
1310 | + } |
|
1263 | 1311 | |
1264 | 1312 | // Reset all cached permissions. |
1265 | 1313 | updateSettings(array('settings_updated' => time())); |
@@ -1269,8 +1317,9 @@ discard block |
||
1269 | 1317 | { |
1270 | 1318 | $group = (int) $group; |
1271 | 1319 | |
1272 | - if (empty($groupLevels['global'][$level])) |
|
1273 | - return; |
|
1320 | + if (empty($groupLevels['global'][$level])) { |
|
1321 | + return; |
|
1322 | + } |
|
1274 | 1323 | |
1275 | 1324 | $smcFunc['db_query']('', ' |
1276 | 1325 | DELETE FROM {db_prefix}permissions |
@@ -1292,8 +1341,9 @@ discard block |
||
1292 | 1341 | ); |
1293 | 1342 | |
1294 | 1343 | $groupInserts = array(); |
1295 | - foreach ($groupLevels['global'][$level] as $permission) |
|
1296 | - $groupInserts[] = array($group, $permission); |
|
1344 | + foreach ($groupLevels['global'][$level] as $permission) { |
|
1345 | + $groupInserts[] = array($group, $permission); |
|
1346 | + } |
|
1297 | 1347 | |
1298 | 1348 | $smcFunc['db_insert']('insert', |
1299 | 1349 | '{db_prefix}permissions', |
@@ -1303,8 +1353,9 @@ discard block |
||
1303 | 1353 | ); |
1304 | 1354 | |
1305 | 1355 | $boardInserts = array(); |
1306 | - foreach ($groupLevels['board'][$level] as $permission) |
|
1307 | - $boardInserts[] = array(1, $group, $permission); |
|
1356 | + foreach ($groupLevels['board'][$level] as $permission) { |
|
1357 | + $boardInserts[] = array(1, $group, $permission); |
|
1358 | + } |
|
1308 | 1359 | |
1309 | 1360 | $smcFunc['db_insert']('insert', |
1310 | 1361 | '{db_prefix}board_permissions', |
@@ -1335,8 +1386,9 @@ discard block |
||
1335 | 1386 | if (!empty($groupLevels['board'][$level])) |
1336 | 1387 | { |
1337 | 1388 | $boardInserts = array(); |
1338 | - foreach ($groupLevels['board'][$level] as $permission) |
|
1339 | - $boardInserts[] = array($profile, $group, $permission); |
|
1389 | + foreach ($groupLevels['board'][$level] as $permission) { |
|
1390 | + $boardInserts[] = array($profile, $group, $permission); |
|
1391 | + } |
|
1340 | 1392 | |
1341 | 1393 | $smcFunc['db_insert']('insert', |
1342 | 1394 | '{db_prefix}board_permissions', |
@@ -1359,8 +1411,9 @@ discard block |
||
1359 | 1411 | ) |
1360 | 1412 | ); |
1361 | 1413 | |
1362 | - if (empty($boardLevels[$level])) |
|
1363 | - return; |
|
1414 | + if (empty($boardLevels[$level])) { |
|
1415 | + return; |
|
1416 | + } |
|
1364 | 1417 | |
1365 | 1418 | // Get all the groups... |
1366 | 1419 | $query = $smcFunc['db_query']('', ' |
@@ -1378,8 +1431,9 @@ discard block |
||
1378 | 1431 | $group = $row[0]; |
1379 | 1432 | |
1380 | 1433 | $boardInserts = array(); |
1381 | - foreach ($boardLevels[$level] as $permission) |
|
1382 | - $boardInserts[] = array($profile, $group, $permission); |
|
1434 | + foreach ($boardLevels[$level] as $permission) { |
|
1435 | + $boardInserts[] = array($profile, $group, $permission); |
|
1436 | + } |
|
1383 | 1437 | |
1384 | 1438 | $smcFunc['db_insert']('insert', |
1385 | 1439 | '{db_prefix}board_permissions', |
@@ -1392,8 +1446,9 @@ discard block |
||
1392 | 1446 | |
1393 | 1447 | // Add permissions for ungrouped members. |
1394 | 1448 | $boardInserts = array(); |
1395 | - foreach ($boardLevels[$level] as $permission) |
|
1396 | - $boardInserts[] = array($profile, 0, $permission); |
|
1449 | + foreach ($boardLevels[$level] as $permission) { |
|
1450 | + $boardInserts[] = array($profile, 0, $permission); |
|
1451 | + } |
|
1397 | 1452 | |
1398 | 1453 | $smcFunc['db_insert']('insert', |
1399 | 1454 | '{db_prefix}board_permissions', |
@@ -1403,9 +1458,10 @@ discard block |
||
1403 | 1458 | ); |
1404 | 1459 | } |
1405 | 1460 | // $profile and $group are both null! |
1406 | - else |
|
1407 | - fatal_lang_error('no_access', false); |
|
1408 | -} |
|
1461 | + else { |
|
1462 | + fatal_lang_error('no_access', false); |
|
1463 | + } |
|
1464 | + } |
|
1409 | 1465 | |
1410 | 1466 | /** |
1411 | 1467 | * Load permissions into $context['permissions']. |
@@ -1607,15 +1663,17 @@ discard block |
||
1607 | 1663 | foreach ($permissionList as $permission => $permissionArray) |
1608 | 1664 | { |
1609 | 1665 | // If this is a guest permission we don't do it if it's the guest group. |
1610 | - if (isset($context['group']['id']) && $context['group']['id'] == -1 && in_array($permission, $context['non_guest_permissions'])) |
|
1611 | - continue; |
|
1666 | + if (isset($context['group']['id']) && $context['group']['id'] == -1 && in_array($permission, $context['non_guest_permissions'])) { |
|
1667 | + continue; |
|
1668 | + } |
|
1612 | 1669 | |
1613 | 1670 | // What groups will this permission be in? |
1614 | 1671 | $own_group = $permissionArray[1]; |
1615 | 1672 | |
1616 | 1673 | // First, Do these groups actually exist - if not add them. |
1617 | - if (!isset($permissionGroups[$permissionType][$own_group])) |
|
1618 | - $permissionGroups[$permissionType][$own_group] = true; |
|
1674 | + if (!isset($permissionGroups[$permissionType][$own_group])) { |
|
1675 | + $permissionGroups[$permissionType][$own_group] = true; |
|
1676 | + } |
|
1619 | 1677 | |
1620 | 1678 | // What column should this be located into? |
1621 | 1679 | $position = !in_array($own_group, $leftPermissionGroups) ? 1 : 0; |
@@ -1623,8 +1681,8 @@ discard block |
||
1623 | 1681 | // If the groups have not yet been created be sure to create them. |
1624 | 1682 | $bothGroups = array('own' => $own_group); |
1625 | 1683 | |
1626 | - foreach ($bothGroups as $group) |
|
1627 | - if (!isset($context['permissions'][$permissionType]['columns'][$position][$group])) |
|
1684 | + foreach ($bothGroups as $group) { |
|
1685 | + if (!isset($context['permissions'][$permissionType]['columns'][$position][$group])) |
|
1628 | 1686 | $context['permissions'][$permissionType]['columns'][$position][$group] = array( |
1629 | 1687 | 'type' => $permissionType, |
1630 | 1688 | 'id' => $group, |
@@ -1634,6 +1692,7 @@ discard block |
||
1634 | 1692 | 'hidden' => false, |
1635 | 1693 | 'permissions' => array() |
1636 | 1694 | ); |
1695 | + } |
|
1637 | 1696 | |
1638 | 1697 | $context['permissions'][$permissionType]['columns'][$position][$own_group]['permissions'][$permission] = array( |
1639 | 1698 | 'id' => $permission, |
@@ -1658,27 +1717,30 @@ discard block |
||
1658 | 1717 | { |
1659 | 1718 | $context['hidden_permissions'][] = $permission . '_own'; |
1660 | 1719 | $context['hidden_permissions'][] = $permission . '_any'; |
1720 | + } else { |
|
1721 | + $context['hidden_permissions'][] = $permission; |
|
1661 | 1722 | } |
1662 | - else |
|
1663 | - $context['hidden_permissions'][] = $permission; |
|
1664 | 1723 | } |
1665 | 1724 | } |
1666 | 1725 | ksort($context['permissions'][$permissionType]['columns']); |
1667 | 1726 | |
1668 | 1727 | // Check we don't leave any empty groups - and mark hidden ones as such. |
1669 | - foreach ($context['permissions'][$permissionType]['columns'] as $column => $groups) |
|
1670 | - foreach ($groups as $id => $group) |
|
1728 | + foreach ($context['permissions'][$permissionType]['columns'] as $column => $groups) { |
|
1729 | + foreach ($groups as $id => $group) |
|
1671 | 1730 | { |
1672 | 1731 | if (empty($group['permissions'])) |
1673 | 1732 | unset($context['permissions'][$permissionType]['columns'][$column][$id]); |
1733 | + } |
|
1674 | 1734 | else |
1675 | 1735 | { |
1676 | 1736 | $foundNonHidden = false; |
1677 | - foreach ($group['permissions'] as $permission) |
|
1678 | - if (empty($permission['hidden'])) |
|
1737 | + foreach ($group['permissions'] as $permission) { |
|
1738 | + if (empty($permission['hidden'])) |
|
1679 | 1739 | $foundNonHidden = true; |
1680 | - if (!$foundNonHidden) |
|
1681 | - $context['permissions'][$permissionType]['columns'][$column][$id]['hidden'] = true; |
|
1740 | + } |
|
1741 | + if (!$foundNonHidden) { |
|
1742 | + $context['permissions'][$permissionType]['columns'][$column][$id]['hidden'] = true; |
|
1743 | + } |
|
1682 | 1744 | } |
1683 | 1745 | } |
1684 | 1746 | } |
@@ -1705,12 +1767,13 @@ discard block |
||
1705 | 1767 | $context['can_change_permissions'] = allowedTo('manage_permissions'); |
1706 | 1768 | |
1707 | 1769 | // Nothing to initialize here. |
1708 | - if (!$context['can_change_permissions']) |
|
1709 | - return; |
|
1770 | + if (!$context['can_change_permissions']) { |
|
1771 | + return; |
|
1772 | + } |
|
1710 | 1773 | |
1711 | 1774 | // Load the permission settings for guests |
1712 | - foreach ($permissions as $permission) |
|
1713 | - $context[$permission] = array( |
|
1775 | + foreach ($permissions as $permission) { |
|
1776 | + $context[$permission] = array( |
|
1714 | 1777 | -1 => array( |
1715 | 1778 | 'id' => -1, |
1716 | 1779 | 'name' => $txt['membergroups_guests'], |
@@ -1724,6 +1787,7 @@ discard block |
||
1724 | 1787 | 'status' => 'off', |
1725 | 1788 | ), |
1726 | 1789 | ); |
1790 | + } |
|
1727 | 1791 | |
1728 | 1792 | $request = $smcFunc['db_query']('', ' |
1729 | 1793 | SELECT id_group, CASE WHEN add_deny = {int:denied} THEN {string:deny} ELSE {string:on} END AS status, permission |
@@ -1737,8 +1801,9 @@ discard block |
||
1737 | 1801 | 'on' => 'on', |
1738 | 1802 | ) |
1739 | 1803 | ); |
1740 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1741 | - $context[$row['permission']][$row['id_group']]['status'] = $row['status']; |
|
1804 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1805 | + $context[$row['permission']][$row['id_group']]['status'] = $row['status']; |
|
1806 | + } |
|
1742 | 1807 | $smcFunc['db_free_result']($request); |
1743 | 1808 | |
1744 | 1809 | $request = $smcFunc['db_query']('', ' |
@@ -1759,14 +1824,15 @@ discard block |
||
1759 | 1824 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1760 | 1825 | { |
1761 | 1826 | // Initialize each permission as being 'off' until proven otherwise. |
1762 | - foreach ($permissions as $permission) |
|
1763 | - if (!isset($context[$permission][$row['id_group']])) |
|
1827 | + foreach ($permissions as $permission) { |
|
1828 | + if (!isset($context[$permission][$row['id_group']])) |
|
1764 | 1829 | $context[$permission][$row['id_group']] = array( |
1765 | 1830 | 'id' => $row['id_group'], |
1766 | 1831 | 'name' => $row['group_name'], |
1767 | 1832 | 'is_postgroup' => $row['min_posts'] != -1, |
1768 | 1833 | 'status' => 'off', |
1769 | 1834 | ); |
1835 | + } |
|
1770 | 1836 | |
1771 | 1837 | $context[$row['permission']][$row['id_group']]['status'] = empty($row['status']) ? 'deny' : ($row['status'] == 1 ? 'on' : 'off'); |
1772 | 1838 | } |
@@ -1780,8 +1846,9 @@ discard block |
||
1780 | 1846 | { |
1781 | 1847 | foreach ($permissions as $permission) |
1782 | 1848 | { |
1783 | - if (isset($context[$permission][$group])) |
|
1784 | - unset($context[$permission][$group]); |
|
1849 | + if (isset($context[$permission][$group])) { |
|
1850 | + unset($context[$permission][$group]); |
|
1851 | + } |
|
1785 | 1852 | } |
1786 | 1853 | } |
1787 | 1854 | |
@@ -1789,8 +1856,9 @@ discard block |
||
1789 | 1856 | $non_guest_perms = array_intersect(str_replace(array('_any', '_own'), '', $permissions), $context['non_guest_permissions']); |
1790 | 1857 | foreach ($non_guest_perms as $permission) |
1791 | 1858 | { |
1792 | - if (isset($context[$permission][-1])) |
|
1793 | - unset($context[$permission][-1]); |
|
1859 | + if (isset($context[$permission][-1])) { |
|
1860 | + unset($context[$permission][-1]); |
|
1861 | + } |
|
1794 | 1862 | } |
1795 | 1863 | |
1796 | 1864 | // Create the token for the separate inline permission verification. |
@@ -1825,8 +1893,9 @@ discard block |
||
1825 | 1893 | global $context, $smcFunc; |
1826 | 1894 | |
1827 | 1895 | // No permissions? Not a great deal to do here. |
1828 | - if (!allowedTo('manage_permissions')) |
|
1829 | - return; |
|
1896 | + if (!allowedTo('manage_permissions')) { |
|
1897 | + return; |
|
1898 | + } |
|
1830 | 1899 | |
1831 | 1900 | // Almighty session check, verify our ways. |
1832 | 1901 | checkSession(); |
@@ -1838,13 +1907,15 @@ discard block |
||
1838 | 1907 | $insertRows = array(); |
1839 | 1908 | foreach ($permissions as $permission) |
1840 | 1909 | { |
1841 | - if (!isset($_POST[$permission])) |
|
1842 | - continue; |
|
1910 | + if (!isset($_POST[$permission])) { |
|
1911 | + continue; |
|
1912 | + } |
|
1843 | 1913 | |
1844 | 1914 | foreach ($_POST[$permission] as $id_group => $value) |
1845 | 1915 | { |
1846 | - if (in_array($value, array('on', 'deny')) && (empty($context['illegal_permissions']) || !in_array($permission, $context['illegal_permissions']))) |
|
1847 | - $insertRows[] = array((int) $id_group, $permission, $value == 'on' ? 1 : 0); |
|
1916 | + if (in_array($value, array('on', 'deny')) && (empty($context['illegal_permissions']) || !in_array($permission, $context['illegal_permissions']))) { |
|
1917 | + $insertRows[] = array((int) $id_group, $permission, $value == 'on' ? 1 : 0); |
|
1918 | + } |
|
1848 | 1919 | } |
1849 | 1920 | } |
1850 | 1921 | |
@@ -1860,13 +1931,14 @@ discard block |
||
1860 | 1931 | ); |
1861 | 1932 | |
1862 | 1933 | // ...and replace them with new ones. |
1863 | - if (!empty($insertRows)) |
|
1864 | - $smcFunc['db_insert']('insert', |
|
1934 | + if (!empty($insertRows)) { |
|
1935 | + $smcFunc['db_insert']('insert', |
|
1865 | 1936 | '{db_prefix}permissions', |
1866 | 1937 | array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'), |
1867 | 1938 | $insertRows, |
1868 | 1939 | array('id_group', 'permission') |
1869 | 1940 | ); |
1941 | + } |
|
1870 | 1942 | |
1871 | 1943 | // Do a full child update. |
1872 | 1944 | updateChildPermissions(array(), -1); |
@@ -1893,10 +1965,11 @@ discard block |
||
1893 | 1965 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1894 | 1966 | { |
1895 | 1967 | // Format the label nicely. |
1896 | - if (isset($txt['permissions_profile_' . $row['profile_name']])) |
|
1897 | - $name = $txt['permissions_profile_' . $row['profile_name']]; |
|
1898 | - else |
|
1899 | - $name = $row['profile_name']; |
|
1968 | + if (isset($txt['permissions_profile_' . $row['profile_name']])) { |
|
1969 | + $name = $txt['permissions_profile_' . $row['profile_name']]; |
|
1970 | + } else { |
|
1971 | + $name = $row['profile_name']; |
|
1972 | + } |
|
1900 | 1973 | |
1901 | 1974 | $context['profiles'][$row['id_profile']] = array( |
1902 | 1975 | 'id' => $row['id_profile'], |
@@ -1951,17 +2024,19 @@ discard block |
||
1951 | 2024 | ) |
1952 | 2025 | ); |
1953 | 2026 | $inserts = array(); |
1954 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1955 | - $inserts[] = array($profile_id, $row['id_group'], $row['permission'], $row['add_deny']); |
|
2027 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2028 | + $inserts[] = array($profile_id, $row['id_group'], $row['permission'], $row['add_deny']); |
|
2029 | + } |
|
1956 | 2030 | $smcFunc['db_free_result']($request); |
1957 | 2031 | |
1958 | - if (!empty($inserts)) |
|
1959 | - $smcFunc['db_insert']('insert', |
|
2032 | + if (!empty($inserts)) { |
|
2033 | + $smcFunc['db_insert']('insert', |
|
1960 | 2034 | '{db_prefix}board_permissions', |
1961 | 2035 | array('id_profile' => 'int', 'id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'), |
1962 | 2036 | $inserts, |
1963 | 2037 | array('id_profile', 'id_group', 'permission') |
1964 | 2038 | ); |
2039 | + } |
|
1965 | 2040 | } |
1966 | 2041 | // Renaming? |
1967 | 2042 | elseif (isset($_POST['rename'])) |
@@ -1970,16 +2045,16 @@ discard block |
||
1970 | 2045 | validateToken('admin-mpp'); |
1971 | 2046 | |
1972 | 2047 | // Just showing the boxes? |
1973 | - if (!isset($_POST['rename_profile'])) |
|
1974 | - $context['show_rename_boxes'] = true; |
|
1975 | - else |
|
2048 | + if (!isset($_POST['rename_profile'])) { |
|
2049 | + $context['show_rename_boxes'] = true; |
|
2050 | + } else |
|
1976 | 2051 | { |
1977 | 2052 | foreach ($_POST['rename_profile'] as $id => $value) |
1978 | 2053 | { |
1979 | 2054 | $value = $smcFunc['htmlspecialchars']($value); |
1980 | 2055 | |
1981 | - if (trim($value) != '' && $id > 4) |
|
1982 | - $smcFunc['db_query']('', ' |
|
2056 | + if (trim($value) != '' && $id > 4) { |
|
2057 | + $smcFunc['db_query']('', ' |
|
1983 | 2058 | UPDATE {db_prefix}permission_profiles |
1984 | 2059 | SET profile_name = {string:profile_name} |
1985 | 2060 | WHERE id_profile = {int:current_profile}', |
@@ -1988,6 +2063,7 @@ discard block |
||
1988 | 2063 | 'profile_name' => $value, |
1989 | 2064 | ) |
1990 | 2065 | ); |
2066 | + } |
|
1991 | 2067 | } |
1992 | 2068 | } |
1993 | 2069 | } |
@@ -1998,9 +2074,10 @@ discard block |
||
1998 | 2074 | validateToken('admin-mpp'); |
1999 | 2075 | |
2000 | 2076 | $profiles = array(); |
2001 | - foreach ($_POST['delete_profile'] as $profile) |
|
2002 | - if ($profile > 4) |
|
2077 | + foreach ($_POST['delete_profile'] as $profile) { |
|
2078 | + if ($profile > 4) |
|
2003 | 2079 | $profiles[] = (int) $profile; |
2080 | + } |
|
2004 | 2081 | |
2005 | 2082 | // Verify it's not in use... |
2006 | 2083 | $request = $smcFunc['db_query']('', ' |
@@ -2012,8 +2089,9 @@ discard block |
||
2012 | 2089 | 'profile_list' => $profiles, |
2013 | 2090 | ) |
2014 | 2091 | ); |
2015 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
2016 | - fatal_lang_error('no_access', false); |
|
2092 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
2093 | + fatal_lang_error('no_access', false); |
|
2094 | + } |
|
2017 | 2095 | $smcFunc['db_free_result']($request); |
2018 | 2096 | |
2019 | 2097 | // Oh well, delete. |
@@ -2037,10 +2115,11 @@ discard block |
||
2037 | 2115 | array( |
2038 | 2116 | ) |
2039 | 2117 | ); |
2040 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2041 | - if (isset($context['profiles'][$row['id_profile']])) |
|
2118 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2119 | + if (isset($context['profiles'][$row['id_profile']])) |
|
2042 | 2120 | { |
2043 | 2121 | $context['profiles'][$row['id_profile']]['in_use'] = true; |
2122 | + } |
|
2044 | 2123 | $context['profiles'][$row['id_profile']]['boards'] = $row['board_count']; |
2045 | 2124 | $context['profiles'][$row['id_profile']]['boards_text'] = $row['board_count'] > 1 ? sprintf($txt['permissions_profile_used_by_many'], $row['board_count']) : $txt['permissions_profile_used_by_' . ($row['board_count'] ? 'one' : 'none')]; |
2046 | 2125 | } |
@@ -2052,8 +2131,9 @@ discard block |
||
2052 | 2131 | { |
2053 | 2132 | // Can't delete special ones. |
2054 | 2133 | $context['profiles'][$id]['can_edit'] = isset($txt['permissions_profile_' . $profile['unformatted_name']]) ? false : true; |
2055 | - if ($context['profiles'][$id]['can_edit']) |
|
2056 | - $context['can_edit_something'] = true; |
|
2134 | + if ($context['profiles'][$id]['can_edit']) { |
|
2135 | + $context['can_edit_something'] = true; |
|
2136 | + } |
|
2057 | 2137 | |
2058 | 2138 | // You can only delete it if you can edit it AND it's not in use. |
2059 | 2139 | $context['profiles'][$id]['can_delete'] = $context['profiles'][$id]['can_edit'] && empty($profile['in_use']) ? true : false; |
@@ -2074,8 +2154,9 @@ discard block |
||
2074 | 2154 | global $smcFunc; |
2075 | 2155 | |
2076 | 2156 | // All the parent groups to sort out. |
2077 | - if (!is_array($parents)) |
|
2078 | - $parents = array($parents); |
|
2157 | + if (!is_array($parents)) { |
|
2158 | + $parents = array($parents); |
|
2159 | + } |
|
2079 | 2160 | |
2080 | 2161 | // Find all the children of this group. |
2081 | 2162 | $request = $smcFunc['db_query']('', ' |
@@ -2102,8 +2183,9 @@ discard block |
||
2102 | 2183 | $parents = array_unique($parents); |
2103 | 2184 | |
2104 | 2185 | // Not a sausage, or a child? |
2105 | - if (empty($children)) |
|
2106 | - return false; |
|
2186 | + if (empty($children)) { |
|
2187 | + return false; |
|
2188 | + } |
|
2107 | 2189 | |
2108 | 2190 | // First off, are we doing general permissions? |
2109 | 2191 | if ($profile < 1 || $profile === null) |
@@ -2118,9 +2200,10 @@ discard block |
||
2118 | 2200 | ) |
2119 | 2201 | ); |
2120 | 2202 | $permissions = array(); |
2121 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2122 | - foreach ($children[$row['id_group']] as $child) |
|
2203 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2204 | + foreach ($children[$row['id_group']] as $child) |
|
2123 | 2205 | $permissions[] = array($child, $row['permission'], $row['add_deny']); |
2206 | + } |
|
2124 | 2207 | $smcFunc['db_free_result']($request); |
2125 | 2208 | |
2126 | 2209 | $smcFunc['db_query']('', ' |
@@ -2160,9 +2243,10 @@ discard block |
||
2160 | 2243 | ) |
2161 | 2244 | ); |
2162 | 2245 | $permissions = array(); |
2163 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2164 | - foreach ($children[$row['id_group']] as $child) |
|
2246 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2247 | + foreach ($children[$row['id_group']] as $child) |
|
2165 | 2248 | $permissions[] = array($child, $row['id_profile'], $row['permission'], $row['add_deny']); |
2249 | + } |
|
2166 | 2250 | $smcFunc['db_free_result']($request); |
2167 | 2251 | |
2168 | 2252 | $smcFunc['db_query']('', ' |
@@ -2196,12 +2280,15 @@ discard block |
||
2196 | 2280 | global $context; |
2197 | 2281 | |
2198 | 2282 | $context['illegal_permissions'] = array(); |
2199 | - if (!allowedTo('admin_forum')) |
|
2200 | - $context['illegal_permissions'][] = 'admin_forum'; |
|
2201 | - if (!allowedTo('manage_membergroups')) |
|
2202 | - $context['illegal_permissions'][] = 'manage_membergroups'; |
|
2203 | - if (!allowedTo('manage_permissions')) |
|
2204 | - $context['illegal_permissions'][] = 'manage_permissions'; |
|
2283 | + if (!allowedTo('admin_forum')) { |
|
2284 | + $context['illegal_permissions'][] = 'admin_forum'; |
|
2285 | + } |
|
2286 | + if (!allowedTo('manage_membergroups')) { |
|
2287 | + $context['illegal_permissions'][] = 'manage_membergroups'; |
|
2288 | + } |
|
2289 | + if (!allowedTo('manage_permissions')) { |
|
2290 | + $context['illegal_permissions'][] = 'manage_permissions'; |
|
2291 | + } |
|
2205 | 2292 | |
2206 | 2293 | call_integration_hook('integrate_load_illegal_permissions'); |
2207 | 2294 | } |
@@ -2350,16 +2437,17 @@ discard block |
||
2350 | 2437 | 'attachment' => 'disallow', |
2351 | 2438 | 'children' => array(), |
2352 | 2439 | ); |
2440 | + } elseif (isset($context['profile_groups'][$row['id_parent']])) { |
|
2441 | + $context['profile_groups'][$row['id_parent']]['children'][] = $row['group_name']; |
|
2353 | 2442 | } |
2354 | - elseif (isset($context['profile_groups'][$row['id_parent']])) |
|
2355 | - $context['profile_groups'][$row['id_parent']]['children'][] = $row['group_name']; |
|
2356 | 2443 | } |
2357 | 2444 | $smcFunc['db_free_result']($request); |
2358 | 2445 | |
2359 | 2446 | // What are the permissions we are querying? |
2360 | 2447 | $all_permissions = array(); |
2361 | - foreach ($mappings as $perm_set) |
|
2362 | - $all_permissions = array_merge($all_permissions, $perm_set); |
|
2448 | + foreach ($mappings as $perm_set) { |
|
2449 | + $all_permissions = array_merge($all_permissions, $perm_set); |
|
2450 | + } |
|
2363 | 2451 | |
2364 | 2452 | // If we're saving the changes then do just that - save them. |
2365 | 2453 | if (!empty($_POST['save_changes']) && ($context['current_profile'] == 1 || $context['current_profile'] > 4)) |
@@ -2374,8 +2462,7 @@ discard block |
||
2374 | 2462 | { |
2375 | 2463 | // Turning it on. This seems easy enough. |
2376 | 2464 | updateSettings(array('postmod_active' => 1)); |
2377 | - } |
|
2378 | - else |
|
2465 | + } else |
|
2379 | 2466 | { |
2380 | 2467 | // Turning it off. Not so straightforward. We have to turn off warnings to moderation level, and make everything approved. |
2381 | 2468 | updateSettings(array( |
@@ -2386,8 +2473,7 @@ discard block |
||
2386 | 2473 | require_once($sourcedir . '/PostModeration.php'); |
2387 | 2474 | approveAllData(); |
2388 | 2475 | } |
2389 | - } |
|
2390 | - elseif ($modSettings['postmod_active']) |
|
2476 | + } elseif ($modSettings['postmod_active']) |
|
2391 | 2477 | { |
2392 | 2478 | // We're not saving a new setting - and if it's still enabled we have more work to do. |
2393 | 2479 | |
@@ -2417,21 +2503,22 @@ discard block |
||
2417 | 2503 | // Give them both sets for fun. |
2418 | 2504 | $new_permissions[] = array($context['current_profile'], $group['id'], $data[0], 1); |
2419 | 2505 | $new_permissions[] = array($context['current_profile'], $group['id'], $data[1], 1); |
2506 | + } elseif ($_POST[$index][$group['id']] == 'moderate') { |
|
2507 | + $new_permissions[] = array($context['current_profile'], $group['id'], $data[1], 1); |
|
2420 | 2508 | } |
2421 | - elseif ($_POST[$index][$group['id']] == 'moderate') |
|
2422 | - $new_permissions[] = array($context['current_profile'], $group['id'], $data[1], 1); |
|
2423 | 2509 | } |
2424 | 2510 | } |
2425 | 2511 | } |
2426 | 2512 | |
2427 | 2513 | // Insert new permissions. |
2428 | - if (!empty($new_permissions)) |
|
2429 | - $smcFunc['db_insert']('', |
|
2514 | + if (!empty($new_permissions)) { |
|
2515 | + $smcFunc['db_insert']('', |
|
2430 | 2516 | '{db_prefix}board_permissions', |
2431 | 2517 | array('id_profile' => 'int', 'id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'), |
2432 | 2518 | $new_permissions, |
2433 | 2519 | array('id_profile', 'id_group', 'permission') |
2434 | 2520 | ); |
2521 | + } |
|
2435 | 2522 | } |
2436 | 2523 | } |
2437 | 2524 | |
@@ -2460,11 +2547,13 @@ discard block |
||
2460 | 2547 | if ($row['add_deny']) |
2461 | 2548 | { |
2462 | 2549 | // Full allowance? |
2463 | - if ($index == 0) |
|
2464 | - $context['profile_groups'][$row['id_group']][$key] = 'allow'; |
|
2550 | + if ($index == 0) { |
|
2551 | + $context['profile_groups'][$row['id_group']][$key] = 'allow'; |
|
2552 | + } |
|
2465 | 2553 | // Otherwise only bother with moderate if not on allow. |
2466 | - elseif ($context['profile_groups'][$row['id_group']][$key] != 'allow') |
|
2467 | - $context['profile_groups'][$row['id_group']][$key] = 'moderate'; |
|
2554 | + elseif ($context['profile_groups'][$row['id_group']][$key] != 'allow') { |
|
2555 | + $context['profile_groups'][$row['id_group']][$key] = 'moderate'; |
|
2556 | + } |
|
2468 | 2557 | } |
2469 | 2558 | } |
2470 | 2559 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | { |
151 | 151 | if (!@is_dir($directory)) |
152 | 152 | { |
153 | - if (!@mkdir($directory,0755)) |
|
153 | + if (!@mkdir($directory, 0755)) |
|
154 | 154 | { |
155 | 155 | $context['dir_creation_error'] = 'attachments_no_create'; |
156 | 156 | return false; |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | * |
249 | 249 | * @return array|bool An array of all the directories and subdirectories or false on failure |
250 | 250 | */ |
251 | -function get_directory_tree_elements ($directory) |
|
251 | +function get_directory_tree_elements($directory) |
|
252 | 252 | { |
253 | 253 | /* |
254 | 254 | In Windows server both \ and / can be used as directory separators in paths |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) |
265 | 265 | return false; |
266 | 266 | |
267 | - $tree = explode(DIRECTORY_SEPARATOR, trim($directory,DIRECTORY_SEPARATOR)); |
|
267 | + $tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR)); |
|
268 | 268 | } |
269 | 269 | return $tree; |
270 | 270 | } |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * |
278 | 278 | * @return string|bool The first part of the path or false on error |
279 | 279 | */ |
280 | -function attachments_init_dir (&$tree, &$count) |
|
280 | +function attachments_init_dir(&$tree, &$count) |
|
281 | 281 | { |
282 | 282 | $directory = ''; |
283 | 283 | // If on Windows servers the first part of the path is the drive (e.g. "C:") |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | //Better be sure that the first part of the path is actually a drive letter... |
287 | 287 | //...even if, I should check this in the admin page...isn't it? |
288 | 288 | //...NHAAA Let's leave space for users' complains! :P |
289 | - if (preg_match('/^[a-z]:$/i',$tree[0])) |
|
289 | + if (preg_match('/^[a-z]:$/i', $tree[0])) |
|
290 | 290 | $directory = array_shift($tree); |
291 | 291 | else |
292 | 292 | return false; |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | global $modSettings, $context, $sourcedir, $smcFunc; |
485 | 485 | |
486 | 486 | // No data or missing data .... Not necessarily needed, but in case a mod author missed something. |
487 | - if ( empty($_SESSION['temp_attachments'][$attachID])) |
|
487 | + if (empty($_SESSION['temp_attachments'][$attachID])) |
|
488 | 488 | $error = '$_SESSION[\'temp_attachments\'][$attachID]'; |
489 | 489 | |
490 | 490 | elseif (empty($attachID)) |
@@ -911,9 +911,9 @@ discard block |
||
911 | 911 | $attachContext = $attachLoaded[$attachID]; |
912 | 912 | |
913 | 913 | // Fix the url to point out to showAvatar(). |
914 | - $attachContext['href'] = $scripturl . '?action=dlattach;attach=' . $attachID .';type=preview'; |
|
914 | + $attachContext['href'] = $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview'; |
|
915 | 915 | |
916 | - $attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID .';type=preview'. (empty($attachContext['is_image']) ? ';file' : '') .'">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>'; |
|
916 | + $attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>'; |
|
917 | 917 | |
918 | 918 | // Fix the thumbnail too, if the image has one. |
919 | 919 | if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) |
@@ -1078,7 +1078,7 @@ discard block |
||
1078 | 1078 | LEFT JOIN {db_prefix}attachments AS thumb ON (thumb.id_attach = a.id_thumb)') . ' |
1079 | 1079 | LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) |
1080 | 1080 | WHERE a.attachment_type = {int:attachment_type} |
1081 | - '. (!empty($msgID) ? 'AND a.id_msg = {int:message_id}' : '') .'', |
|
1081 | + '. (!empty($msgID) ? 'AND a.id_msg = {int:message_id}' : '') . '', |
|
1082 | 1082 | array( |
1083 | 1083 | 'message_id' => $msgID, |
1084 | 1084 | 'attachment_type' => 0, |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * Check if the current directory is still valid or not. |
@@ -28,22 +29,24 @@ discard block |
||
28 | 29 | global $boarddir, $modSettings, $context; |
29 | 30 | |
30 | 31 | // Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found. |
31 | - if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') |
|
32 | - $doit = true; |
|
33 | - elseif (empty($modSettings['automanage_attachments'])) |
|
34 | - return; |
|
35 | - elseif (!isset($_FILES)) |
|
36 | - return; |
|
37 | - elseif (isset($_FILES['attachment'])) |
|
38 | - foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
32 | + if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') { |
|
33 | + $doit = true; |
|
34 | + } elseif (empty($modSettings['automanage_attachments'])) { |
|
35 | + return; |
|
36 | + } elseif (!isset($_FILES)) { |
|
37 | + return; |
|
38 | + } elseif (isset($_FILES['attachment'])) { |
|
39 | + foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
39 | 40 | if (!empty($dummy)) |
40 | 41 | { |
41 | 42 | $doit = true; |
43 | + } |
|
42 | 44 | break; |
43 | 45 | } |
44 | 46 | |
45 | - if (!isset($doit)) |
|
46 | - return; |
|
47 | + if (!isset($doit)) { |
|
48 | + return; |
|
49 | + } |
|
47 | 50 | |
48 | 51 | $year = date('Y'); |
49 | 52 | $month = date('m'); |
@@ -55,21 +58,25 @@ discard block |
||
55 | 58 | |
56 | 59 | if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments'])) |
57 | 60 | { |
58 | - if (!is_array($modSettings['attachment_basedirectories'])) |
|
59 | - $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
61 | + if (!is_array($modSettings['attachment_basedirectories'])) { |
|
62 | + $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
63 | + } |
|
60 | 64 | $base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']); |
65 | + } else { |
|
66 | + $base_dir = 0; |
|
61 | 67 | } |
62 | - else |
|
63 | - $base_dir = 0; |
|
64 | 68 | |
65 | 69 | if ($modSettings['automanage_attachments'] == 1) |
66 | 70 | { |
67 | - if (!isset($modSettings['last_attachments_directory'])) |
|
68 | - $modSettings['last_attachments_directory'] = array(); |
|
69 | - if (!is_array($modSettings['last_attachments_directory'])) |
|
70 | - $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
71 | - if (!isset($modSettings['last_attachments_directory'][$base_dir])) |
|
72 | - $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
71 | + if (!isset($modSettings['last_attachments_directory'])) { |
|
72 | + $modSettings['last_attachments_directory'] = array(); |
|
73 | + } |
|
74 | + if (!is_array($modSettings['last_attachments_directory'])) { |
|
75 | + $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
76 | + } |
|
77 | + if (!isset($modSettings['last_attachments_directory'][$base_dir])) { |
|
78 | + $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
79 | + } |
|
73 | 80 | } |
74 | 81 | |
75 | 82 | $basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
@@ -98,12 +105,14 @@ discard block |
||
98 | 105 | $updir = ''; |
99 | 106 | } |
100 | 107 | |
101 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
102 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
103 | - if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) |
|
104 | - $outputCreation = automanage_attachments_create_directory($updir); |
|
105 | - elseif (in_array($updir, $modSettings['attachmentUploadDir'])) |
|
106 | - $outputCreation = true; |
|
108 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
109 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
110 | + } |
|
111 | + if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) { |
|
112 | + $outputCreation = automanage_attachments_create_directory($updir); |
|
113 | + } elseif (in_array($updir, $modSettings['attachmentUploadDir'])) { |
|
114 | + $outputCreation = true; |
|
115 | + } |
|
107 | 116 | |
108 | 117 | if ($outputCreation) |
109 | 118 | { |
@@ -140,8 +149,9 @@ discard block |
||
140 | 149 | $count = count($tree); |
141 | 150 | |
142 | 151 | $directory = attachments_init_dir($tree, $count); |
143 | - if ($directory === false) |
|
144 | - return false; |
|
152 | + if ($directory === false) { |
|
153 | + return false; |
|
154 | + } |
|
145 | 155 | } |
146 | 156 | |
147 | 157 | $directory .= DIRECTORY_SEPARATOR . array_shift($tree); |
@@ -169,8 +179,9 @@ discard block |
||
169 | 179 | } |
170 | 180 | |
171 | 181 | // Everything seems fine...let's create the .htaccess |
172 | - if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) |
|
173 | - secureDirectory($updir, true); |
|
182 | + if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) { |
|
183 | + secureDirectory($updir, true); |
|
184 | + } |
|
174 | 185 | |
175 | 186 | $sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR; |
176 | 187 | $updir = rtrim($updir, $sep); |
@@ -202,8 +213,9 @@ discard block |
||
202 | 213 | { |
203 | 214 | global $modSettings, $boarddir; |
204 | 215 | |
205 | - if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) |
|
206 | - return; |
|
216 | + if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) { |
|
217 | + return; |
|
218 | + } |
|
207 | 219 | |
208 | 220 | $basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir; |
209 | 221 | // Just to be sure: I don't want directory separators at the end |
@@ -215,13 +227,14 @@ discard block |
||
215 | 227 | { |
216 | 228 | $base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']); |
217 | 229 | $base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0; |
230 | + } else { |
|
231 | + $base_dir = 0; |
|
218 | 232 | } |
219 | - else |
|
220 | - $base_dir = 0; |
|
221 | 233 | |
222 | 234 | // Get the last attachment directory for that base directory |
223 | - if (empty($modSettings['last_attachments_directory'][$base_dir])) |
|
224 | - $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
235 | + if (empty($modSettings['last_attachments_directory'][$base_dir])) { |
|
236 | + $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
237 | + } |
|
225 | 238 | // And increment it. |
226 | 239 | $modSettings['last_attachments_directory'][$base_dir]++; |
227 | 240 | |
@@ -236,10 +249,10 @@ discard block |
||
236 | 249 | $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
237 | 250 | |
238 | 251 | return true; |
252 | + } else { |
|
253 | + return false; |
|
254 | + } |
|
239 | 255 | } |
240 | - else |
|
241 | - return false; |
|
242 | -} |
|
243 | 256 | |
244 | 257 | /** |
245 | 258 | * Split a path into a list of all directories and subdirectories |
@@ -257,12 +270,13 @@ discard block |
||
257 | 270 | * in Windows we need to explode for both \ and / |
258 | 271 | * while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR) |
259 | 272 | */ |
260 | - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') |
|
261 | - $tree = preg_split('#[\\\/]#', $directory); |
|
262 | - else |
|
273 | + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
274 | + $tree = preg_split('#[\\\/]#', $directory); |
|
275 | + } else |
|
263 | 276 | { |
264 | - if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) |
|
265 | - return false; |
|
277 | + if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) { |
|
278 | + return false; |
|
279 | + } |
|
266 | 280 | |
267 | 281 | $tree = explode(DIRECTORY_SEPARATOR, trim($directory,DIRECTORY_SEPARATOR)); |
268 | 282 | } |
@@ -286,10 +300,11 @@ discard block |
||
286 | 300 | //Better be sure that the first part of the path is actually a drive letter... |
287 | 301 | //...even if, I should check this in the admin page...isn't it? |
288 | 302 | //...NHAAA Let's leave space for users' complains! :P |
289 | - if (preg_match('/^[a-z]:$/i',$tree[0])) |
|
290 | - $directory = array_shift($tree); |
|
291 | - else |
|
292 | - return false; |
|
303 | + if (preg_match('/^[a-z]:$/i',$tree[0])) { |
|
304 | + $directory = array_shift($tree); |
|
305 | + } else { |
|
306 | + return false; |
|
307 | + } |
|
293 | 308 | |
294 | 309 | $count--; |
295 | 310 | } |
@@ -304,18 +319,20 @@ discard block |
||
304 | 319 | global $context, $modSettings, $smcFunc, $txt, $user_info; |
305 | 320 | |
306 | 321 | // Make sure we're uploading to the right place. |
307 | - if (!empty($modSettings['automanage_attachments'])) |
|
308 | - automanage_attachments_check_directory(); |
|
322 | + if (!empty($modSettings['automanage_attachments'])) { |
|
323 | + automanage_attachments_check_directory(); |
|
324 | + } |
|
309 | 325 | |
310 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
311 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
326 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
327 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
328 | + } |
|
312 | 329 | |
313 | 330 | $context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
314 | 331 | |
315 | 332 | // Is the attachments folder actualy there? |
316 | - if (!empty($context['dir_creation_error'])) |
|
317 | - $initial_error = $context['dir_creation_error']; |
|
318 | - elseif (!is_dir($context['attach_dir'])) |
|
333 | + if (!empty($context['dir_creation_error'])) { |
|
334 | + $initial_error = $context['dir_creation_error']; |
|
335 | + } elseif (!is_dir($context['attach_dir'])) |
|
319 | 336 | { |
320 | 337 | $initial_error = 'attach_folder_warning'; |
321 | 338 | log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical'); |
@@ -338,12 +355,12 @@ discard block |
||
338 | 355 | ); |
339 | 356 | list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request); |
340 | 357 | $smcFunc['db_free_result']($request); |
341 | - } |
|
342 | - else |
|
343 | - $context['attachments'] = array( |
|
358 | + } else { |
|
359 | + $context['attachments'] = array( |
|
344 | 360 | 'quantity' => 0, |
345 | 361 | 'total_size' => 0, |
346 | 362 | ); |
363 | + } |
|
347 | 364 | } |
348 | 365 | |
349 | 366 | // Hmm. There are still files in session. |
@@ -353,39 +370,44 @@ discard block |
||
353 | 370 | // Let's try to keep them. But... |
354 | 371 | $ignore_temp = true; |
355 | 372 | // If new files are being added. We can't ignore those |
356 | - foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
357 | - if (!empty($dummy)) |
|
373 | + foreach ($_FILES['attachment']['tmp_name'] as $dummy) { |
|
374 | + if (!empty($dummy)) |
|
358 | 375 | { |
359 | 376 | $ignore_temp = false; |
377 | + } |
|
360 | 378 | break; |
361 | 379 | } |
362 | 380 | |
363 | 381 | // Need to make space for the new files. So, bye bye. |
364 | 382 | if (!$ignore_temp) |
365 | 383 | { |
366 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
367 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
384 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) { |
|
385 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
368 | 386 | unlink($attachment['tmp_name']); |
387 | + } |
|
369 | 388 | |
370 | 389 | $context['we_are_history'] = $txt['error_temp_attachments_flushed']; |
371 | 390 | $_SESSION['temp_attachments'] = array(); |
372 | 391 | } |
373 | 392 | } |
374 | 393 | |
375 | - if (!isset($_FILES['attachment']['name'])) |
|
376 | - $_FILES['attachment']['tmp_name'] = array(); |
|
394 | + if (!isset($_FILES['attachment']['name'])) { |
|
395 | + $_FILES['attachment']['tmp_name'] = array(); |
|
396 | + } |
|
377 | 397 | |
378 | - if (!isset($_SESSION['temp_attachments'])) |
|
379 | - $_SESSION['temp_attachments'] = array(); |
|
398 | + if (!isset($_SESSION['temp_attachments'])) { |
|
399 | + $_SESSION['temp_attachments'] = array(); |
|
400 | + } |
|
380 | 401 | |
381 | 402 | // Remember where we are at. If it's anywhere at all. |
382 | - if (!$ignore_temp) |
|
383 | - $_SESSION['temp_attachments']['post'] = array( |
|
403 | + if (!$ignore_temp) { |
|
404 | + $_SESSION['temp_attachments']['post'] = array( |
|
384 | 405 | 'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0, |
385 | 406 | 'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0, |
386 | 407 | 'topic' => !empty($topic) ? $topic : 0, |
387 | 408 | 'board' => !empty($board) ? $board : 0, |
388 | 409 | ); |
410 | + } |
|
389 | 411 | |
390 | 412 | // If we have an initial error, lets just display it. |
391 | 413 | if (!empty($initial_error)) |
@@ -393,9 +415,10 @@ discard block |
||
393 | 415 | $_SESSION['temp_attachments']['initial_error'] = $initial_error; |
394 | 416 | |
395 | 417 | // And delete the files 'cos they ain't going nowhere. |
396 | - foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
|
397 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
418 | + foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) { |
|
419 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
398 | 420 | unlink($_FILES['attachment']['tmp_name'][$n]); |
421 | + } |
|
399 | 422 | |
400 | 423 | $_FILES['attachment']['tmp_name'] = array(); |
401 | 424 | } |
@@ -403,21 +426,24 @@ discard block |
||
403 | 426 | // Loop through $_FILES['attachment'] array and move each file to the current attachments folder. |
404 | 427 | foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
405 | 428 | { |
406 | - if ($_FILES['attachment']['name'][$n] == '') |
|
407 | - continue; |
|
429 | + if ($_FILES['attachment']['name'][$n] == '') { |
|
430 | + continue; |
|
431 | + } |
|
408 | 432 | |
409 | 433 | // First, let's first check for PHP upload errors. |
410 | 434 | $errors = array(); |
411 | 435 | if (!empty($_FILES['attachment']['error'][$n])) |
412 | 436 | { |
413 | - if ($_FILES['attachment']['error'][$n] == 2) |
|
414 | - $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
415 | - elseif ($_FILES['attachment']['error'][$n] == 6) |
|
416 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
417 | - else |
|
418 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
419 | - if (empty($errors)) |
|
420 | - $errors[] = 'attach_php_error'; |
|
437 | + if ($_FILES['attachment']['error'][$n] == 2) { |
|
438 | + $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
439 | + } elseif ($_FILES['attachment']['error'][$n] == 6) { |
|
440 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
441 | + } else { |
|
442 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
443 | + } |
|
444 | + if (empty($errors)) { |
|
445 | + $errors[] = 'attach_php_error'; |
|
446 | + } |
|
421 | 447 | } |
422 | 448 | |
423 | 449 | // Try to move and rename the file before doing any more checks on it. |
@@ -435,16 +461,16 @@ discard block |
||
435 | 461 | ); |
436 | 462 | |
437 | 463 | // Move the file to the attachments folder with a temp name for now. |
438 | - if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) |
|
439 | - smf_chmod($destName, 0644); |
|
440 | - else |
|
464 | + if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) { |
|
465 | + smf_chmod($destName, 0644); |
|
466 | + } else |
|
441 | 467 | { |
442 | 468 | $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout'; |
443 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
444 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
469 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
470 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
471 | + } |
|
445 | 472 | } |
446 | - } |
|
447 | - else |
|
473 | + } else |
|
448 | 474 | { |
449 | 475 | $_SESSION['temp_attachments'][$attachID] = array( |
450 | 476 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -452,12 +478,14 @@ discard block |
||
452 | 478 | 'errors' => $errors, |
453 | 479 | ); |
454 | 480 | |
455 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
456 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
481 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
482 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
483 | + } |
|
457 | 484 | } |
458 | 485 | // If there's no errors to this point. We still do need to apply some additional checks before we are finished. |
459 | - if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
|
460 | - attachmentChecks($attachID); |
|
486 | + if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) { |
|
487 | + attachmentChecks($attachID); |
|
488 | + } |
|
461 | 489 | } |
462 | 490 | // Mod authors, finally a hook to hang an alternate attachment upload system upon |
463 | 491 | // Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand()) |
@@ -484,21 +512,20 @@ discard block |
||
484 | 512 | global $modSettings, $context, $sourcedir, $smcFunc; |
485 | 513 | |
486 | 514 | // No data or missing data .... Not necessarily needed, but in case a mod author missed something. |
487 | - if ( empty($_SESSION['temp_attachments'][$attachID])) |
|
488 | - $error = '$_SESSION[\'temp_attachments\'][$attachID]'; |
|
489 | - |
|
490 | - elseif (empty($attachID)) |
|
491 | - $error = '$attachID'; |
|
492 | - |
|
493 | - elseif (empty($context['attachments'])) |
|
494 | - $error = '$context[\'attachments\']'; |
|
495 | - |
|
496 | - elseif (empty($context['attach_dir'])) |
|
497 | - $error = '$context[\'attach_dir\']'; |
|
515 | + if ( empty($_SESSION['temp_attachments'][$attachID])) { |
|
516 | + $error = '$_SESSION[\'temp_attachments\'][$attachID]'; |
|
517 | + } elseif (empty($attachID)) { |
|
518 | + $error = '$attachID'; |
|
519 | + } elseif (empty($context['attachments'])) { |
|
520 | + $error = '$context[\'attachments\']'; |
|
521 | + } elseif (empty($context['attach_dir'])) { |
|
522 | + $error = '$context[\'attach_dir\']'; |
|
523 | + } |
|
498 | 524 | |
499 | 525 | // Let's get their attention. |
500 | - if (!empty($error)) |
|
501 | - fatal_lang_error('attach_check_nag', 'debug', array($error)); |
|
526 | + if (!empty($error)) { |
|
527 | + fatal_lang_error('attach_check_nag', 'debug', array($error)); |
|
528 | + } |
|
502 | 529 | |
503 | 530 | // Just in case this slipped by the first checks, we stop it here and now |
504 | 531 | if ($_SESSION['temp_attachments'][$attachID]['size'] == 0) |
@@ -527,8 +554,9 @@ discard block |
||
527 | 554 | $size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']); |
528 | 555 | if (!(empty($size)) && ($size[2] != $old_format)) |
529 | 556 | { |
530 | - if (isset($context['validImageTypes'][$size[2]])) |
|
531 | - $_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
557 | + if (isset($context['validImageTypes'][$size[2]])) { |
|
558 | + $_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
559 | + } |
|
532 | 560 | } |
533 | 561 | } |
534 | 562 | } |
@@ -582,42 +610,48 @@ discard block |
||
582 | 610 | // Or, let the user know that it ain't gonna happen. |
583 | 611 | else |
584 | 612 | { |
585 | - if (isset($context['dir_creation_error'])) |
|
586 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error']; |
|
587 | - else |
|
588 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
613 | + if (isset($context['dir_creation_error'])) { |
|
614 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error']; |
|
615 | + } else { |
|
616 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
617 | + } |
|
589 | 618 | } |
619 | + } else { |
|
620 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
590 | 621 | } |
591 | - else |
|
592 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
593 | 622 | } |
594 | 623 | } |
595 | 624 | |
596 | 625 | // Is the file too big? |
597 | 626 | $context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size']; |
598 | - if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) |
|
599 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0))); |
|
627 | + if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) { |
|
628 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0))); |
|
629 | + } |
|
600 | 630 | |
601 | 631 | // Check the total upload size for this post... |
602 | - if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) |
|
603 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0))); |
|
632 | + if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) { |
|
633 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0))); |
|
634 | + } |
|
604 | 635 | |
605 | 636 | // Have we reached the maximum number of files we are allowed? |
606 | 637 | $context['attachments']['quantity']++; |
607 | 638 | |
608 | 639 | // Set a max limit if none exists |
609 | - if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) |
|
610 | - $modSettings['attachmentNumPerPostLimit'] = 50; |
|
640 | + if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) { |
|
641 | + $modSettings['attachmentNumPerPostLimit'] = 50; |
|
642 | + } |
|
611 | 643 | |
612 | - if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) |
|
613 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit'])); |
|
644 | + if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) { |
|
645 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit'])); |
|
646 | + } |
|
614 | 647 | |
615 | 648 | // File extension check |
616 | 649 | if (!empty($modSettings['attachmentCheckExtensions'])) |
617 | 650 | { |
618 | 651 | $allowed = explode(',', strtolower($modSettings['attachmentExtensions'])); |
619 | - foreach ($allowed as $k => $dummy) |
|
620 | - $allowed[$k] = trim($dummy); |
|
652 | + foreach ($allowed as $k => $dummy) { |
|
653 | + $allowed[$k] = trim($dummy); |
|
654 | + } |
|
621 | 655 | |
622 | 656 | if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed)) |
623 | 657 | { |
@@ -629,10 +663,12 @@ discard block |
||
629 | 663 | // Undo the math if there's an error |
630 | 664 | if (!empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
631 | 665 | { |
632 | - if (isset($context['dir_size'])) |
|
633 | - $context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
|
634 | - if (isset($context['dir_files'])) |
|
635 | - $context['dir_files']--; |
|
666 | + if (isset($context['dir_size'])) { |
|
667 | + $context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
|
668 | + } |
|
669 | + if (isset($context['dir_files'])) { |
|
670 | + $context['dir_files']--; |
|
671 | + } |
|
636 | 672 | $context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
637 | 673 | $context['attachments']['quantity']--; |
638 | 674 | return false; |
@@ -664,12 +700,14 @@ discard block |
||
664 | 700 | if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width']) |
665 | 701 | { |
666 | 702 | // Got a proper mime type? |
667 | - if (!empty($size['mime'])) |
|
668 | - $attachmentOptions['mime_type'] = $size['mime']; |
|
703 | + if (!empty($size['mime'])) { |
|
704 | + $attachmentOptions['mime_type'] = $size['mime']; |
|
705 | + } |
|
669 | 706 | |
670 | 707 | // Otherwise a valid one? |
671 | - elseif (isset($context['validImageTypes'][$size[2]])) |
|
672 | - $attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
708 | + elseif (isset($context['validImageTypes'][$size[2]])) { |
|
709 | + $attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
710 | + } |
|
673 | 711 | } |
674 | 712 | |
675 | 713 | // It is possible we might have a MIME type that isn't actually an image but still have a size. |
@@ -681,15 +719,17 @@ discard block |
||
681 | 719 | } |
682 | 720 | |
683 | 721 | // Get the hash if no hash has been given yet. |
684 | - if (empty($attachmentOptions['file_hash'])) |
|
685 | - $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true); |
|
722 | + if (empty($attachmentOptions['file_hash'])) { |
|
723 | + $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true); |
|
724 | + } |
|
686 | 725 | |
687 | 726 | // Assuming no-one set the extension let's take a look at it. |
688 | 727 | if (empty($attachmentOptions['fileext'])) |
689 | 728 | { |
690 | 729 | $attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : ''); |
691 | - if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) |
|
692 | - $attachmentOptions['fileext'] = ''; |
|
730 | + if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) { |
|
731 | + $attachmentOptions['fileext'] = ''; |
|
732 | + } |
|
693 | 733 | } |
694 | 734 | |
695 | 735 | // Last chance to change stuff! |
@@ -698,8 +738,9 @@ discard block |
||
698 | 738 | // Make sure the folder is valid... |
699 | 739 | $tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : smf_json_decode($modSettings['attachmentUploadDir'], true); |
700 | 740 | $folders = array_keys($tmp); |
701 | - if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) |
|
702 | - $attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir']; |
|
741 | + if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) { |
|
742 | + $attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir']; |
|
743 | + } |
|
703 | 744 | |
704 | 745 | $smcFunc['db_insert']('', |
705 | 746 | '{db_prefix}attachments', |
@@ -730,8 +771,8 @@ discard block |
||
730 | 771 | rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']); |
731 | 772 | |
732 | 773 | // If it's not approved then add to the approval queue. |
733 | - if (!$attachmentOptions['approved']) |
|
734 | - $smcFunc['db_insert']('', |
|
774 | + if (!$attachmentOptions['approved']) { |
|
775 | + $smcFunc['db_insert']('', |
|
735 | 776 | '{db_prefix}approval_queue', |
736 | 777 | array( |
737 | 778 | 'id_attach' => 'int', 'id_msg' => 'int', |
@@ -741,9 +782,11 @@ discard block |
||
741 | 782 | ), |
742 | 783 | array() |
743 | 784 | ); |
785 | + } |
|
744 | 786 | |
745 | - if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) |
|
746 | - return true; |
|
787 | + if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) { |
|
788 | + return true; |
|
789 | + } |
|
747 | 790 | |
748 | 791 | // Like thumbnails, do we? |
749 | 792 | if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight'])) |
@@ -754,13 +797,15 @@ discard block |
||
754 | 797 | $size = @getimagesize($attachmentOptions['destination'] . '_thumb'); |
755 | 798 | list ($thumb_width, $thumb_height) = $size; |
756 | 799 | |
757 | - if (!empty($size['mime'])) |
|
758 | - $thumb_mime = $size['mime']; |
|
759 | - elseif (isset($context['validImageTypes'][$size[2]])) |
|
760 | - $thumb_mime = 'image/' . $context['validImageTypes'][$size[2]]; |
|
800 | + if (!empty($size['mime'])) { |
|
801 | + $thumb_mime = $size['mime']; |
|
802 | + } elseif (isset($context['validImageTypes'][$size[2]])) { |
|
803 | + $thumb_mime = 'image/' . $context['validImageTypes'][$size[2]]; |
|
804 | + } |
|
761 | 805 | // Lord only knows how this happened... |
762 | - else |
|
763 | - $thumb_mime = ''; |
|
806 | + else { |
|
807 | + $thumb_mime = ''; |
|
808 | + } |
|
764 | 809 | |
765 | 810 | $thumb_filename = $attachmentOptions['name'] . '_thumb'; |
766 | 811 | $thumb_size = filesize($attachmentOptions['destination'] . '_thumb'); |
@@ -840,15 +885,17 @@ discard block |
||
840 | 885 | global $smcFunc; |
841 | 886 | |
842 | 887 | // Oh, come on! |
843 | - if (empty($attachIDs) || empty($msgID)) |
|
844 | - return false; |
|
888 | + if (empty($attachIDs) || empty($msgID)) { |
|
889 | + return false; |
|
890 | + } |
|
845 | 891 | |
846 | 892 | // "I see what is right and approve, but I do what is wrong." |
847 | 893 | call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID)); |
848 | 894 | |
849 | 895 | // One last check |
850 | - if (empty($attachIDs)) |
|
851 | - return false; |
|
896 | + if (empty($attachIDs)) { |
|
897 | + return false; |
|
898 | + } |
|
852 | 899 | |
853 | 900 | // Perform. |
854 | 901 | $smcFunc['db_query']('', ' |
@@ -880,8 +927,9 @@ discard block |
||
880 | 927 | $externalParse = false; |
881 | 928 | |
882 | 929 | // Meh... |
883 | - if (empty($attachID)) |
|
884 | - return 'attachments_no_data_loaded'; |
|
930 | + if (empty($attachID)) { |
|
931 | + return 'attachments_no_data_loaded'; |
|
932 | + } |
|
885 | 933 | |
886 | 934 | // Make it easy. |
887 | 935 | $msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0; |
@@ -890,20 +938,23 @@ discard block |
||
890 | 938 | $externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID)); |
891 | 939 | |
892 | 940 | // "I am innocent of the blood of this just person: see ye to it." |
893 | - if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) |
|
894 | - return $externalParse; |
|
941 | + if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) { |
|
942 | + return $externalParse; |
|
943 | + } |
|
895 | 944 | |
896 | 945 | //Are attachments enable? |
897 | - if (empty($modSettings['attachmentEnable'])) |
|
898 | - return 'attachments_not_enable'; |
|
946 | + if (empty($modSettings['attachmentEnable'])) { |
|
947 | + return 'attachments_not_enable'; |
|
948 | + } |
|
899 | 949 | |
900 | 950 | // Previewing much? no msg ID has been set yet. |
901 | 951 | if (!empty($context['preview_message'])) |
902 | 952 | { |
903 | 953 | $allAttachments = getAttachsByMsg(0); |
904 | 954 | |
905 | - if (empty($allAttachments[0][$attachID])) |
|
906 | - return 'attachments_no_data_loaded'; |
|
955 | + if (empty($allAttachments[0][$attachID])) { |
|
956 | + return 'attachments_no_data_loaded'; |
|
957 | + } |
|
907 | 958 | |
908 | 959 | $attachContext = $allAttachments[0][$attachID]; |
909 | 960 | $attachLoaded = loadAttachmentContext(0, $allAttachments); |
@@ -916,57 +967,66 @@ discard block |
||
916 | 967 | $attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID .';type=preview'. (empty($attachContext['is_image']) ? ';file' : '') .'">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>'; |
917 | 968 | |
918 | 969 | // Fix the thumbnail too, if the image has one. |
919 | - if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) |
|
920 | - $attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview'; |
|
970 | + if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) { |
|
971 | + $attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview'; |
|
972 | + } |
|
921 | 973 | |
922 | 974 | return $attachContext; |
923 | 975 | } |
924 | 976 | |
925 | 977 | // There is always the chance someone else has already done our dirty work... |
926 | 978 | // If so, all pertinent checks were already done. Hopefully... |
927 | - if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) |
|
928 | - return $context['current_attachments'][$attachID]; |
|
979 | + if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) { |
|
980 | + return $context['current_attachments'][$attachID]; |
|
981 | + } |
|
929 | 982 | |
930 | 983 | // If we are lucky enough to be in $board's scope then check it! |
931 | - if (!empty($board) && !allowedTo('view_attachments', $board)) |
|
932 | - return 'attachments_not_allowed_to_see'; |
|
984 | + if (!empty($board) && !allowedTo('view_attachments', $board)) { |
|
985 | + return 'attachments_not_allowed_to_see'; |
|
986 | + } |
|
933 | 987 | |
934 | 988 | // Get the message info associated with this particular attach ID. |
935 | 989 | $attachInfo = getAttachMsgInfo($attachID); |
936 | 990 | |
937 | 991 | // There is always the chance this attachment no longer exists or isn't associated to a message anymore... |
938 | - if (empty($attachInfo) || empty($attachInfo['msg'])) |
|
939 | - return 'attachments_no_msg_associated'; |
|
992 | + if (empty($attachInfo) || empty($attachInfo['msg'])) { |
|
993 | + return 'attachments_no_msg_associated'; |
|
994 | + } |
|
940 | 995 | |
941 | 996 | // Hold it! got the info now check if you can see this attachment. |
942 | - if (!allowedTo('view_attachments', $attachInfo['board'])) |
|
943 | - return 'attachments_not_allowed_to_see'; |
|
997 | + if (!allowedTo('view_attachments', $attachInfo['board'])) { |
|
998 | + return 'attachments_not_allowed_to_see'; |
|
999 | + } |
|
944 | 1000 | |
945 | 1001 | $allAttachments = getAttachsByMsg($attachInfo['msg']); |
946 | 1002 | $attachContext = $allAttachments[$attachInfo['msg']][$attachID]; |
947 | 1003 | |
948 | 1004 | // No point in keep going further. |
949 | - if (!allowedTo('view_attachments', $attachContext['board'])) |
|
950 | - return 'attachments_not_allowed_to_see'; |
|
1005 | + if (!allowedTo('view_attachments', $attachContext['board'])) { |
|
1006 | + return 'attachments_not_allowed_to_see'; |
|
1007 | + } |
|
951 | 1008 | |
952 | 1009 | // Load this particular attach's context. |
953 | - if (!empty($attachContext)) |
|
954 | - $attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments); |
|
1010 | + if (!empty($attachContext)) { |
|
1011 | + $attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments); |
|
1012 | + } |
|
955 | 1013 | |
956 | 1014 | // One last check, you know, gotta be paranoid... |
957 | - else |
|
958 | - return 'attachments_no_data_loaded'; |
|
1015 | + else { |
|
1016 | + return 'attachments_no_data_loaded'; |
|
1017 | + } |
|
959 | 1018 | |
960 | 1019 | // This is the last "if" I promise! |
961 | - if (empty($attachLoaded)) |
|
962 | - return 'attachments_no_data_loaded'; |
|
963 | - |
|
964 | - else |
|
965 | - $attachContext = $attachLoaded[$attachID]; |
|
1020 | + if (empty($attachLoaded)) { |
|
1021 | + return 'attachments_no_data_loaded'; |
|
1022 | + } else { |
|
1023 | + $attachContext = $attachLoaded[$attachID]; |
|
1024 | + } |
|
966 | 1025 | |
967 | 1026 | // You may or may not want to show this under the post. |
968 | - if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) |
|
969 | - $context['show_attach_under_post'][$attachID] = $attachID; |
|
1027 | + if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) { |
|
1028 | + $context['show_attach_under_post'][$attachID] = $attachID; |
|
1029 | + } |
|
970 | 1030 | |
971 | 1031 | // Last minute changes? |
972 | 1032 | call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext)); |
@@ -986,8 +1046,9 @@ discard block |
||
986 | 1046 | { |
987 | 1047 | global $smcFunc, $modSettings; |
988 | 1048 | |
989 | - if (empty($attachIDs)) |
|
990 | - return array(); |
|
1049 | + if (empty($attachIDs)) { |
|
1050 | + return array(); |
|
1051 | + } |
|
991 | 1052 | |
992 | 1053 | $return = array(); |
993 | 1054 | |
@@ -1003,11 +1064,12 @@ discard block |
||
1003 | 1064 | ) |
1004 | 1065 | ); |
1005 | 1066 | |
1006 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1007 | - return array(); |
|
1067 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1068 | + return array(); |
|
1069 | + } |
|
1008 | 1070 | |
1009 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1010 | - $return[$row['id_attach']] = array( |
|
1071 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1072 | + $return[$row['id_attach']] = array( |
|
1011 | 1073 | 'name' => $smcFunc['htmlspecialchars']($row['filename']), |
1012 | 1074 | 'size' => $row['size'], |
1013 | 1075 | 'attachID' => $row['id_attach'], |
@@ -1016,6 +1078,7 @@ discard block |
||
1016 | 1078 | 'mime_type' => $row['mime_type'], |
1017 | 1079 | 'thumb' => $row['id_thumb'], |
1018 | 1080 | ); |
1081 | + } |
|
1019 | 1082 | $smcFunc['db_free_result']($request); |
1020 | 1083 | |
1021 | 1084 | return $return; |
@@ -1032,8 +1095,9 @@ discard block |
||
1032 | 1095 | { |
1033 | 1096 | global $smcFunc; |
1034 | 1097 | |
1035 | - if (empty($attachID)) |
|
1036 | - return array(); |
|
1098 | + if (empty($attachID)) { |
|
1099 | + return array(); |
|
1100 | + } |
|
1037 | 1101 | |
1038 | 1102 | $request = $smcFunc['db_query']('', ' |
1039 | 1103 | SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board |
@@ -1046,8 +1110,9 @@ discard block |
||
1046 | 1110 | ) |
1047 | 1111 | ); |
1048 | 1112 | |
1049 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1050 | - return array(); |
|
1113 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1114 | + return array(); |
|
1115 | + } |
|
1051 | 1116 | |
1052 | 1117 | $row = $smcFunc['db_fetch_assoc']($request); |
1053 | 1118 | $smcFunc['db_free_result']($request); |
@@ -1088,8 +1153,9 @@ discard block |
||
1088 | 1153 | $temp = array(); |
1089 | 1154 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1090 | 1155 | { |
1091 | - if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) |
|
1092 | - continue; |
|
1156 | + if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) { |
|
1157 | + continue; |
|
1158 | + } |
|
1093 | 1159 | |
1094 | 1160 | $temp[$row['id_attach']] = $row; |
1095 | 1161 | } |
@@ -1118,8 +1184,9 @@ discard block |
||
1118 | 1184 | { |
1119 | 1185 | global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc; |
1120 | 1186 | |
1121 | - if (empty($attachments) || empty($attachments[$id_msg])) |
|
1122 | - return array(); |
|
1187 | + if (empty($attachments) || empty($attachments[$id_msg])) { |
|
1188 | + return array(); |
|
1189 | + } |
|
1123 | 1190 | |
1124 | 1191 | // Set up the attachment info - based on code by Meriadoc. |
1125 | 1192 | $attachmentData = array(); |
@@ -1143,11 +1210,13 @@ discard block |
||
1143 | 1210 | ); |
1144 | 1211 | |
1145 | 1212 | // If something is unapproved we'll note it so we can sort them. |
1146 | - if (!$attachment['approved']) |
|
1147 | - $have_unapproved = true; |
|
1213 | + if (!$attachment['approved']) { |
|
1214 | + $have_unapproved = true; |
|
1215 | + } |
|
1148 | 1216 | |
1149 | - if (!$attachmentData[$i]['is_image']) |
|
1150 | - continue; |
|
1217 | + if (!$attachmentData[$i]['is_image']) { |
|
1218 | + continue; |
|
1219 | + } |
|
1151 | 1220 | |
1152 | 1221 | $attachmentData[$i]['real_width'] = $attachment['width']; |
1153 | 1222 | $attachmentData[$i]['width'] = $attachment['width']; |
@@ -1168,12 +1237,12 @@ discard block |
||
1168 | 1237 | // So what folder are we putting this image in? |
1169 | 1238 | if (!empty($modSettings['currentAttachmentUploadDir'])) |
1170 | 1239 | { |
1171 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
1172 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
1240 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
1241 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
1242 | + } |
|
1173 | 1243 | $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
1174 | 1244 | $id_folder_thumb = $modSettings['currentAttachmentUploadDir']; |
1175 | - } |
|
1176 | - else |
|
1245 | + } else |
|
1177 | 1246 | { |
1178 | 1247 | $path = $modSettings['attachmentUploadDir']; |
1179 | 1248 | $id_folder_thumb = 1; |
@@ -1188,10 +1257,11 @@ discard block |
||
1188 | 1257 | $thumb_ext = isset($context['validImageTypes'][$size[2]]) ? $context['validImageTypes'][$size[2]] : ''; |
1189 | 1258 | |
1190 | 1259 | // Figure out the mime type. |
1191 | - if (!empty($size['mime'])) |
|
1192 | - $thumb_mime = $size['mime']; |
|
1193 | - else |
|
1194 | - $thumb_mime = 'image/' . $thumb_ext; |
|
1260 | + if (!empty($size['mime'])) { |
|
1261 | + $thumb_mime = $size['mime']; |
|
1262 | + } else { |
|
1263 | + $thumb_mime = 'image/' . $thumb_ext; |
|
1264 | + } |
|
1195 | 1265 | |
1196 | 1266 | $thumb_filename = $attachment['filename'] . '_thumb'; |
1197 | 1267 | $thumb_hash = getAttachmentFilename($thumb_filename, false, null, true); |
@@ -1238,11 +1308,12 @@ discard block |
||
1238 | 1308 | } |
1239 | 1309 | } |
1240 | 1310 | |
1241 | - if (!empty($attachment['id_thumb'])) |
|
1242 | - $attachmentData[$i]['thumbnail'] = array( |
|
1311 | + if (!empty($attachment['id_thumb'])) { |
|
1312 | + $attachmentData[$i]['thumbnail'] = array( |
|
1243 | 1313 | 'id' => $attachment['id_thumb'], |
1244 | 1314 | 'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image', |
1245 | 1315 | ); |
1316 | + } |
|
1246 | 1317 | $attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']); |
1247 | 1318 | |
1248 | 1319 | // If thumbnails are disabled, check the maximum size of the image. |
@@ -1252,30 +1323,31 @@ discard block |
||
1252 | 1323 | { |
1253 | 1324 | $attachmentData[$i]['width'] = $modSettings['max_image_width']; |
1254 | 1325 | $attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']); |
1255 | - } |
|
1256 | - elseif (!empty($modSettings['max_image_width'])) |
|
1326 | + } elseif (!empty($modSettings['max_image_width'])) |
|
1257 | 1327 | { |
1258 | 1328 | $attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']); |
1259 | 1329 | $attachmentData[$i]['height'] = $modSettings['max_image_height']; |
1260 | 1330 | } |
1261 | - } |
|
1262 | - elseif ($attachmentData[$i]['thumbnail']['has_thumb']) |
|
1331 | + } elseif ($attachmentData[$i]['thumbnail']['has_thumb']) |
|
1263 | 1332 | { |
1264 | 1333 | // If the image is too large to show inline, make it a popup. |
1265 | - if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) |
|
1266 | - $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);'; |
|
1267 | - else |
|
1268 | - $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');'; |
|
1334 | + if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) { |
|
1335 | + $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);'; |
|
1336 | + } else { |
|
1337 | + $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');'; |
|
1338 | + } |
|
1269 | 1339 | } |
1270 | 1340 | |
1271 | - if (!$attachmentData[$i]['thumbnail']['has_thumb']) |
|
1272 | - $attachmentData[$i]['downloads']++; |
|
1341 | + if (!$attachmentData[$i]['thumbnail']['has_thumb']) { |
|
1342 | + $attachmentData[$i]['downloads']++; |
|
1343 | + } |
|
1273 | 1344 | } |
1274 | 1345 | } |
1275 | 1346 | |
1276 | 1347 | // Do we need to instigate a sort? |
1277 | - if ($have_unapproved) |
|
1278 | - usort($attachmentData, 'approved_attach_sort'); |
|
1348 | + if ($have_unapproved) { |
|
1349 | + usort($attachmentData, 'approved_attach_sort'); |
|
1350 | + } |
|
1279 | 1351 | |
1280 | 1352 | return $attachmentData; |
1281 | 1353 | } |
@@ -206,12 +206,12 @@ discard block |
||
206 | 206 | |
207 | 207 | if (!empty($modSettings['search_simple_fulltext'])) |
208 | 208 | { |
209 | - if($smcFunc['db_title'] == "PostgreSQL") |
|
209 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
210 | 210 | { |
211 | 211 | //we use the default language "default_text_search_config", otherwise we had to assgine the language here |
212 | 212 | //to_tsvector(body) -> to_tsvector($language,body) to_tsquery(...) -> to_tsquery($language,...) |
213 | 213 | $language_ftx = 'english'; |
214 | - $request = $smcFunc['db_query']('',' |
|
214 | + $request = $smcFunc['db_query']('', ' |
|
215 | 215 | SHOW default_text_search_config', |
216 | 216 | array() |
217 | 217 | ); |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | // remove any indexed words that are used in the complex body search terms |
236 | 236 | $words['indexed_words'] = array_diff($words['indexed_words'], $words['complex_words']); |
237 | 237 | |
238 | - if($smcFunc['db_title'] == "PostgreSQL"){ |
|
238 | + if ($smcFunc['db_title'] == "PostgreSQL") { |
|
239 | 239 | $row = 0; |
240 | 240 | foreach ($words['indexed_words'] as $fulltextWord) { |
241 | 241 | $query_params['boolean_match'] .= ($row <> 0 ? '&' : ''); |
@@ -251,12 +251,12 @@ discard block |
||
251 | 251 | |
252 | 252 | // if we have bool terms to search, add them in |
253 | 253 | if ($query_params['boolean_match']) { |
254 | - if($smcFunc['db_title'] == "PostgreSQL") |
|
254 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
255 | 255 | { |
256 | 256 | //we use the default language "default_text_search_config", otherwise we had to assgine the language here |
257 | 257 | //to_tsvector(body) -> to_tsvector($language,body) to_tsquery(...) -> to_tsquery($language,...) |
258 | 258 | $language_ftx = 'english'; |
259 | - $request = $smcFunc['db_query']('',' |
|
259 | + $request = $smcFunc['db_query']('', ' |
|
260 | 260 | SHOW default_text_search_config', |
261 | 261 | array() |
262 | 262 | ); |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | |
276 | 276 | } |
277 | 277 | |
278 | - $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? ( ' |
|
278 | + $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? (' |
|
279 | 279 | INSERT IGNORE INTO {db_prefix}' . $search_data['insert_into'] . ' |
280 | 280 | (' . implode(', ', array_keys($query_select)) . ')') : '') . ' |
281 | 281 | SELECT ' . implode(', ', $query_select) . ' |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 3 |
12 | 12 | */ |
13 | 13 | |
14 | -if (!defined('SMF')) |
|
14 | +if (!defined('SMF')) { |
|
15 | 15 | die('No direct access...'); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * Class fulltext_search |
@@ -98,8 +99,9 @@ discard block |
||
98 | 99 | $smcFunc['db_free_result']($request); |
99 | 100 | } |
100 | 101 | // 4 is the MySQL default... |
101 | - else |
|
102 | - $min_word_length = 4; |
|
102 | + else { |
|
103 | + $min_word_length = 4; |
|
104 | + } |
|
103 | 105 | |
104 | 106 | return $min_word_length; |
105 | 107 | } |
@@ -138,8 +140,7 @@ discard block |
||
138 | 140 | $wordsSearch['words'][] = trim($word, "/*- "); |
139 | 141 | $wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"'; |
140 | 142 | } |
141 | - } |
|
142 | - elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
143 | + } elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
143 | 144 | { |
144 | 145 | // short words have feelings too |
145 | 146 | $wordsSearch['words'][] = trim($word, "/*- "); |
@@ -149,8 +150,9 @@ discard block |
||
149 | 150 | |
150 | 151 | $fulltextWord = count($subwords) === 1 ? $word : '"' . $word . '"'; |
151 | 152 | $wordsSearch['indexed_words'][] = $fulltextWord; |
152 | - if ($isExcluded) |
|
153 | - $wordsExclude[] = $fulltextWord; |
|
153 | + if ($isExcluded) { |
|
154 | + $wordsExclude[] = $fulltextWord; |
|
155 | + } |
|
154 | 156 | } |
155 | 157 | |
156 | 158 | /** |
@@ -166,41 +168,50 @@ discard block |
||
166 | 168 | $query_where = array(); |
167 | 169 | $query_params = $search_data['params']; |
168 | 170 | |
169 | - if ($query_params['id_search']) |
|
170 | - $query_select['id_search'] = '{int:id_search}'; |
|
171 | + if ($query_params['id_search']) { |
|
172 | + $query_select['id_search'] = '{int:id_search}'; |
|
173 | + } |
|
171 | 174 | |
172 | 175 | $count = 0; |
173 | - if (empty($modSettings['search_simple_fulltext'])) |
|
174 | - foreach ($words['words'] as $regularWord) |
|
176 | + if (empty($modSettings['search_simple_fulltext'])) { |
|
177 | + foreach ($words['words'] as $regularWord) |
|
175 | 178 | { |
176 | 179 | $query_where[] = 'm.body' . (in_array($regularWord, $query_params['excluded_words']) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:complex_body_' . $count . '}'; |
180 | + } |
|
177 | 181 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
178 | 182 | } |
179 | 183 | |
180 | - if ($query_params['user_query']) |
|
181 | - $query_where[] = '{raw:user_query}'; |
|
182 | - if ($query_params['board_query']) |
|
183 | - $query_where[] = 'm.id_board {raw:board_query}'; |
|
184 | + if ($query_params['user_query']) { |
|
185 | + $query_where[] = '{raw:user_query}'; |
|
186 | + } |
|
187 | + if ($query_params['board_query']) { |
|
188 | + $query_where[] = 'm.id_board {raw:board_query}'; |
|
189 | + } |
|
184 | 190 | |
185 | - if ($query_params['topic']) |
|
186 | - $query_where[] = 'm.id_topic = {int:topic}'; |
|
187 | - if ($query_params['min_msg_id']) |
|
188 | - $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
189 | - if ($query_params['max_msg_id']) |
|
190 | - $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
191 | + if ($query_params['topic']) { |
|
192 | + $query_where[] = 'm.id_topic = {int:topic}'; |
|
193 | + } |
|
194 | + if ($query_params['min_msg_id']) { |
|
195 | + $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
196 | + } |
|
197 | + if ($query_params['max_msg_id']) { |
|
198 | + $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
199 | + } |
|
191 | 200 | |
192 | 201 | $count = 0; |
193 | - if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
|
194 | - foreach ($query_params['excluded_phrases'] as $phrase) |
|
202 | + if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) { |
|
203 | + foreach ($query_params['excluded_phrases'] as $phrase) |
|
195 | 204 | { |
196 | 205 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_phrase_' . $count . '}'; |
206 | + } |
|
197 | 207 | $query_params['exclude_subject_phrase_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($phrase, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $phrase), '\\\'') . '[[:>:]]'; |
198 | 208 | } |
199 | 209 | $count = 0; |
200 | - if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
|
201 | - foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
210 | + if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) { |
|
211 | + foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
202 | 212 | { |
203 | 213 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_words_' . $count . '}'; |
214 | + } |
|
204 | 215 | $query_params['exclude_subject_words_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($excludedWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $excludedWord), '\\\'') . '[[:>:]]'; |
205 | 216 | } |
206 | 217 | |
@@ -223,12 +234,11 @@ discard block |
||
223 | 234 | } |
224 | 235 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:body_match})'; |
225 | 236 | $query_params['language_ftx'] = $language_ftx; |
237 | + } else { |
|
238 | + $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
226 | 239 | } |
227 | - else |
|
228 | - $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
229 | 240 | $query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words'])); |
230 | - } |
|
231 | - else |
|
241 | + } else |
|
232 | 242 | { |
233 | 243 | $query_params['boolean_match'] = ''; |
234 | 244 | |
@@ -242,10 +252,10 @@ discard block |
||
242 | 252 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' '; |
243 | 253 | $row++; |
244 | 254 | } |
245 | - } |
|
246 | - else |
|
247 | - foreach ($words['indexed_words'] as $fulltextWord) |
|
255 | + } else { |
|
256 | + foreach ($words['indexed_words'] as $fulltextWord) |
|
248 | 257 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' '; |
258 | + } |
|
249 | 259 | |
250 | 260 | $query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1); |
251 | 261 | |
@@ -268,9 +278,9 @@ discard block |
||
268 | 278 | } |
269 | 279 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:boolean_match})'; |
270 | 280 | $query_params['language_ftx'] = $language_ftx; |
281 | + } else { |
|
282 | + $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
271 | 283 | } |
272 | - else |
|
273 | - $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
274 | 284 | } |
275 | 285 | |
276 | 286 | } |
@@ -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]" class="input_check">', $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']; |
@@ -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']); |
@@ -1557,7 +1557,7 @@ discard block |
||
1557 | 1557 | 'action' => $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.'))) |
1558 | 1558 | ); |
1559 | 1559 | |
1560 | - $file = $packagesdir . '/temp/' . $base_path . $action['filename']; |
|
1560 | + $file = $packagesdir . '/temp/' . $base_path . $action['filename']; |
|
1561 | 1561 | if (isset($action['filename']) && (!file_exists($file) || !is_writable(dirname($action['destination'])))) |
1562 | 1562 | { |
1563 | 1563 | $context['has_failure'] = true; |
@@ -1601,7 +1601,7 @@ discard block |
||
1601 | 1601 | { |
1602 | 1602 | updateSettings(array( |
1603 | 1603 | 'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . basename($action['action']), |
1604 | - 'smiley_sets_names' => $modSettings['smiley_sets_names'] . "\n" . $smileyInfo['name'] . (count($context['actions']) > 1 ? ' ' . (!empty($action['description']) ? $smcFunc['htmlspecialchars']($action['description']) : basename($action['action'])) : ''), |
|
1604 | + 'smiley_sets_names' => $modSettings['smiley_sets_names'] . "\n" . $smileyInfo['name'] . (count($context['actions']) > 1 ? ' ' . (!empty($action['description']) ? $smcFunc['htmlspecialchars']($action['description']) : basename($action['action'])) : ''), |
|
1605 | 1605 | )); |
1606 | 1606 | } |
1607 | 1607 | |
@@ -1613,7 +1613,7 @@ discard block |
||
1613 | 1613 | '{db_prefix}log_packages', |
1614 | 1614 | array( |
1615 | 1615 | 'filename' => 'string', 'name' => 'string', 'package_id' => 'string', 'version' => 'string', |
1616 | - 'id_member_installed' => 'int', 'member_installed' => 'string','time_installed' => 'int', |
|
1616 | + 'id_member_installed' => 'int', 'member_installed' => 'string', 'time_installed' => 'int', |
|
1617 | 1617 | 'install_state' => 'int', 'failed_steps' => 'string', 'themes_installed' => 'string', |
1618 | 1618 | 'member_removed' => 'int', 'db_changes' => 'string', 'credits' => 'string', |
1619 | 1619 | ), |
@@ -1862,7 +1862,7 @@ discard block |
||
1862 | 1862 | 'columns' => array( |
1863 | 1863 | 'icon' => array( |
1864 | 1864 | 'data' => array( |
1865 | - 'function' => function ($rowData) use ($settings, $smcFunc) |
|
1865 | + 'function' => function($rowData) use ($settings, $smcFunc) |
|
1866 | 1866 | { |
1867 | 1867 | $images_url = $settings[file_exists(sprintf('%1$s/images/post/%2$s.png', $settings['theme_dir'], $rowData['filename'])) ? 'actual_images_url' : 'default_images_url']; |
1868 | 1868 | return sprintf('<img src="%1$s/post/%2$s.png" alt="%3$s">', $images_url, $rowData['filename'], $smcFunc['htmlspecialchars']($rowData['title'])); |
@@ -1896,7 +1896,7 @@ discard block |
||
1896 | 1896 | 'value' => $txt['icons_board'], |
1897 | 1897 | ), |
1898 | 1898 | 'data' => array( |
1899 | - 'function' => function ($rowData) use ($txt) |
|
1899 | + 'function' => function($rowData) use ($txt) |
|
1900 | 1900 | { |
1901 | 1901 | return empty($rowData['board_name']) ? $txt['icons_edit_icons_all_boards'] : $rowData['board_name']; |
1902 | 1902 | }, |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * 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'); |
@@ -207,8 +211,9 @@ discard block |
||
207 | 211 | foreach ($_POST['smiley_set'] as $id => $val) |
208 | 212 | { |
209 | 213 | // If this is the set you've marked as default, or the only one remaining, you can't delete it |
210 | - if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) |
|
211 | - unset($set_paths[$id], $set_names[$id]); |
|
214 | + if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) { |
|
215 | + unset($set_paths[$id], $set_names[$id]); |
|
216 | + } |
|
212 | 217 | } |
213 | 218 | |
214 | 219 | // Shortcut... array_merge() on a single array resets the numeric keys |
@@ -222,8 +227,9 @@ discard block |
||
222 | 227 | )); |
223 | 228 | } |
224 | 229 | // Add a new smiley set. |
225 | - elseif (!empty($_POST['add'])) |
|
226 | - $context['sub_action'] = 'modifyset'; |
|
230 | + elseif (!empty($_POST['add'])) { |
|
231 | + $context['sub_action'] = 'modifyset'; |
|
232 | + } |
|
227 | 233 | // Create or modify a smiley set. |
228 | 234 | elseif (isset($_POST['set'])) |
229 | 235 | { |
@@ -233,8 +239,9 @@ discard block |
||
233 | 239 | // Create a new smiley set. |
234 | 240 | if ($_POST['set'] == -1 && isset($_POST['smiley_sets_path'])) |
235 | 241 | { |
236 | - if (in_array($_POST['smiley_sets_path'], $set_paths)) |
|
237 | - fatal_lang_error('smiley_set_already_exists'); |
|
242 | + if (in_array($_POST['smiley_sets_path'], $set_paths)) { |
|
243 | + fatal_lang_error('smiley_set_already_exists'); |
|
244 | + } |
|
238 | 245 | |
239 | 246 | updateSettings(array( |
240 | 247 | 'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . $_POST['smiley_sets_path'], |
@@ -246,12 +253,14 @@ discard block |
||
246 | 253 | else |
247 | 254 | { |
248 | 255 | // Make sure the smiley set exists. |
249 | - if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) |
|
250 | - fatal_lang_error('smiley_set_not_found'); |
|
256 | + if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) { |
|
257 | + fatal_lang_error('smiley_set_not_found'); |
|
258 | + } |
|
251 | 259 | |
252 | 260 | // Make sure the path is not yet used by another smileyset. |
253 | - if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) |
|
254 | - fatal_lang_error('smiley_set_path_already_used'); |
|
261 | + if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) { |
|
262 | + fatal_lang_error('smiley_set_path_already_used'); |
|
263 | + } |
|
255 | 264 | |
256 | 265 | $set_paths[$_POST['set']] = $_POST['smiley_sets_path']; |
257 | 266 | $set_names[$_POST['set']] = $_POST['smiley_sets_name']; |
@@ -263,8 +272,9 @@ discard block |
||
263 | 272 | } |
264 | 273 | |
265 | 274 | // The user might have checked to also import smileys. |
266 | - if (!empty($_POST['smiley_sets_import'])) |
|
267 | - ImportSmileys($_POST['smiley_sets_path']); |
|
275 | + if (!empty($_POST['smiley_sets_import'])) { |
|
276 | + ImportSmileys($_POST['smiley_sets_path']); |
|
277 | + } |
|
268 | 278 | } |
269 | 279 | cache_put_data('parsing_smileys', null, 480); |
270 | 280 | cache_put_data('posting_smileys', null, 480); |
@@ -273,13 +283,14 @@ discard block |
||
273 | 283 | // Load all available smileysets... |
274 | 284 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
275 | 285 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
276 | - foreach ($context['smiley_sets'] as $i => $set) |
|
277 | - $context['smiley_sets'][$i] = array( |
|
286 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
287 | + $context['smiley_sets'][$i] = array( |
|
278 | 288 | 'id' => $i, |
279 | 289 | 'path' => $smcFunc['htmlspecialchars']($set), |
280 | 290 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
281 | 291 | 'selected' => $set == $modSettings['smiley_sets_default'] |
282 | 292 | ); |
293 | + } |
|
283 | 294 | |
284 | 295 | // Importing any smileys from an existing set? |
285 | 296 | if ($context['sub_action'] == 'import') |
@@ -290,8 +301,9 @@ discard block |
||
290 | 301 | $_GET['set'] = (int) $_GET['set']; |
291 | 302 | |
292 | 303 | // Sanity check - then import. |
293 | - if (isset($context['smiley_sets'][$_GET['set']])) |
|
294 | - ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path'])); |
|
304 | + if (isset($context['smiley_sets'][$_GET['set']])) { |
|
305 | + ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path'])); |
|
306 | + } |
|
295 | 307 | |
296 | 308 | // Force the process to continue. |
297 | 309 | $context['sub_action'] = 'modifyset'; |
@@ -301,15 +313,15 @@ discard block |
||
301 | 313 | if ($context['sub_action'] == 'modifyset') |
302 | 314 | { |
303 | 315 | $_GET['set'] = !isset($_GET['set']) ? -1 : (int) $_GET['set']; |
304 | - if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) |
|
305 | - $context['current_set'] = array( |
|
316 | + if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) { |
|
317 | + $context['current_set'] = array( |
|
306 | 318 | 'id' => '-1', |
307 | 319 | 'path' => '', |
308 | 320 | 'name' => '', |
309 | 321 | 'selected' => false, |
310 | 322 | 'is_new' => true, |
311 | 323 | ); |
312 | - else |
|
324 | + } else |
|
313 | 325 | { |
314 | 326 | $context['current_set'] = &$context['smiley_sets'][$_GET['set']]; |
315 | 327 | $context['current_set']['is_new'] = false; |
@@ -321,13 +333,15 @@ discard block |
||
321 | 333 | $dir = dir($modSettings['smileys_dir'] . '/' . $context['current_set']['path']); |
322 | 334 | while ($entry = $dir->read()) |
323 | 335 | { |
324 | - if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
325 | - $smileys[strtolower($entry)] = $entry; |
|
336 | + if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
337 | + $smileys[strtolower($entry)] = $entry; |
|
338 | + } |
|
326 | 339 | } |
327 | 340 | $dir->close(); |
328 | 341 | |
329 | - if (empty($smileys)) |
|
330 | - fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name'])); |
|
342 | + if (empty($smileys)) { |
|
343 | + fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name'])); |
|
344 | + } |
|
331 | 345 | |
332 | 346 | // Exclude the smileys that are already in the database. |
333 | 347 | $request = $smcFunc['db_query']('', ' |
@@ -338,9 +352,10 @@ discard block |
||
338 | 352 | 'smiley_list' => $smileys, |
339 | 353 | ) |
340 | 354 | ); |
341 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
342 | - if (isset($smileys[strtolower($row['filename'])])) |
|
355 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
356 | + if (isset($smileys[strtolower($row['filename'])])) |
|
343 | 357 | unset($smileys[strtolower($row['filename'])]); |
358 | + } |
|
344 | 359 | $smcFunc['db_free_result']($request); |
345 | 360 | |
346 | 361 | $context['current_set']['can_import'] = count($smileys); |
@@ -355,13 +370,14 @@ discard block |
||
355 | 370 | $dir = dir($modSettings['smileys_dir']); |
356 | 371 | while ($entry = $dir->read()) |
357 | 372 | { |
358 | - if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) |
|
359 | - $context['smiley_set_dirs'][] = array( |
|
373 | + if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) { |
|
374 | + $context['smiley_set_dirs'][] = array( |
|
360 | 375 | 'id' => $entry, |
361 | 376 | 'path' => $modSettings['smileys_dir'] . '/' . $entry, |
362 | 377 | 'selectable' => $entry == $context['current_set']['path'] || !in_array($entry, explode(',', $modSettings['smiley_sets_known'])), |
363 | 378 | 'current' => $entry == $context['current_set']['path'], |
364 | 379 | ); |
380 | + } |
|
365 | 381 | } |
366 | 382 | $dir->close(); |
367 | 383 | } |
@@ -371,8 +387,9 @@ discard block |
||
371 | 387 | createToken('admin-mss', 'request'); |
372 | 388 | |
373 | 389 | // In case we need to import smileys, we need to add the token in now. |
374 | - if (isset($context['current_set']['import_url'])) |
|
375 | - $context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token']; |
|
390 | + if (isset($context['current_set']['import_url'])) { |
|
391 | + $context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token']; |
|
392 | + } |
|
376 | 393 | |
377 | 394 | $listOptions = array( |
378 | 395 | 'id' => 'smiley_set_list', |
@@ -510,21 +527,23 @@ discard block |
||
510 | 527 | $cols['name'][] = $set_names[$i]; |
511 | 528 | } |
512 | 529 | $sort_flag = strpos($sort, 'DESC') === false ? SORT_ASC : SORT_DESC; |
513 | - if (substr($sort, 0, 4) === 'name') |
|
514 | - array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']); |
|
515 | - elseif (substr($sort, 0, 4) === 'path') |
|
516 | - array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']); |
|
517 | - else |
|
518 | - array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']); |
|
530 | + if (substr($sort, 0, 4) === 'name') { |
|
531 | + array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']); |
|
532 | + } elseif (substr($sort, 0, 4) === 'path') { |
|
533 | + array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']); |
|
534 | + } else { |
|
535 | + array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']); |
|
536 | + } |
|
519 | 537 | |
520 | 538 | $smiley_sets = array(); |
521 | - foreach ($cols['id'] as $i => $id) |
|
522 | - $smiley_sets[] = array( |
|
539 | + foreach ($cols['id'] as $i => $id) { |
|
540 | + $smiley_sets[] = array( |
|
523 | 541 | 'id' => $id, |
524 | 542 | 'path' => $cols['path'][$i], |
525 | 543 | 'name' => $cols['name'][$i], |
526 | 544 | 'selected' => $cols['path'][$i] == $modSettings['smiley_sets_default'] |
527 | 545 | ); |
546 | + } |
|
528 | 547 | |
529 | 548 | return $smiley_sets; |
530 | 549 | } |
@@ -553,13 +572,14 @@ discard block |
||
553 | 572 | $context['smileys_dir_found'] = is_dir($context['smileys_dir']); |
554 | 573 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
555 | 574 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
556 | - foreach ($context['smiley_sets'] as $i => $set) |
|
557 | - $context['smiley_sets'][$i] = array( |
|
575 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
576 | + $context['smiley_sets'][$i] = array( |
|
558 | 577 | 'id' => $i, |
559 | 578 | 'path' => $smcFunc['htmlspecialchars']($set), |
560 | 579 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
561 | 580 | 'selected' => $set == $modSettings['smiley_sets_default'] |
562 | 581 | ); |
582 | + } |
|
563 | 583 | |
564 | 584 | // Submitting a form? |
565 | 585 | if (isset($_POST[$context['session_var']], $_POST['smiley_code'])) |
@@ -575,8 +595,9 @@ discard block |
||
575 | 595 | $_POST['smiley_filename'] = htmltrim__recursive($_POST['smiley_filename']); |
576 | 596 | |
577 | 597 | // Make sure some code was entered. |
578 | - if (empty($_POST['smiley_code'])) |
|
579 | - fatal_lang_error('smiley_has_no_code'); |
|
598 | + if (empty($_POST['smiley_code'])) { |
|
599 | + fatal_lang_error('smiley_has_no_code'); |
|
600 | + } |
|
580 | 601 | |
581 | 602 | // Check whether the new code has duplicates. It should be unique. |
582 | 603 | $request = $smcFunc['db_query']('', ' |
@@ -588,8 +609,9 @@ discard block |
||
588 | 609 | 'smiley_code' => $_POST['smiley_code'], |
589 | 610 | ) |
590 | 611 | ); |
591 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
592 | - fatal_lang_error('smiley_not_unique'); |
|
612 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
613 | + fatal_lang_error('smiley_not_unique'); |
|
614 | + } |
|
593 | 615 | $smcFunc['db_free_result']($request); |
594 | 616 | |
595 | 617 | // If we are uploading - check all the smiley sets are writable! |
@@ -598,38 +620,44 @@ discard block |
||
598 | 620 | $writeErrors = array(); |
599 | 621 | foreach ($context['smiley_sets'] as $set) |
600 | 622 | { |
601 | - if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) |
|
602 | - $writeErrors[] = $set['path']; |
|
623 | + if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) { |
|
624 | + $writeErrors[] = $set['path']; |
|
625 | + } |
|
626 | + } |
|
627 | + if (!empty($writeErrors)) { |
|
628 | + fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors))); |
|
603 | 629 | } |
604 | - if (!empty($writeErrors)) |
|
605 | - fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors))); |
|
606 | 630 | } |
607 | 631 | |
608 | 632 | // Uploading just one smiley for all of them? |
609 | 633 | if (isset($_POST['sameall']) && isset($_FILES['uploadSmiley']['name']) && $_FILES['uploadSmiley']['name'] != '') |
610 | 634 | { |
611 | - if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) |
|
612 | - fatal_lang_error('smileys_upload_error'); |
|
635 | + if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) { |
|
636 | + fatal_lang_error('smileys_upload_error'); |
|
637 | + } |
|
613 | 638 | |
614 | 639 | // Sorry, no spaces, dots, or anything else but letters allowed. |
615 | 640 | $_FILES['uploadSmiley']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['uploadSmiley']['name']); |
616 | 641 | |
617 | 642 | // We only allow image files - it's THAT simple - no messing around here... |
618 | - if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) |
|
619 | - fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
643 | + if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) { |
|
644 | + fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
645 | + } |
|
620 | 646 | |
621 | 647 | // We only need the filename... |
622 | 648 | $destName = basename($_FILES['uploadSmiley']['name']); |
623 | 649 | |
624 | 650 | // Make sure they aren't trying to upload a nasty file - for their own good here! |
625 | - if (in_array(strtolower($destName), $disabledFiles)) |
|
626 | - fatal_lang_error('smileys_upload_error_illegal'); |
|
651 | + if (in_array(strtolower($destName), $disabledFiles)) { |
|
652 | + fatal_lang_error('smileys_upload_error_illegal'); |
|
653 | + } |
|
627 | 654 | |
628 | 655 | // Check if the file already exists... and if not move it to EVERY smiley set directory. |
629 | 656 | $i = 0; |
630 | 657 | // Keep going until we find a set the file doesn't exist in. (or maybe it exists in all of them?) |
631 | - while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) |
|
632 | - $i++; |
|
658 | + while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) { |
|
659 | + $i++; |
|
660 | + } |
|
633 | 661 | |
634 | 662 | // Okay, we're going to put the smiley right here, since it's not there yet! |
635 | 663 | if (isset($context['smiley_sets'][$i]['path'])) |
@@ -644,8 +672,9 @@ discard block |
||
644 | 672 | $currentPath = $context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName; |
645 | 673 | |
646 | 674 | // The file is already there! Don't overwrite it! |
647 | - if (file_exists($currentPath)) |
|
648 | - continue; |
|
675 | + if (file_exists($currentPath)) { |
|
676 | + continue; |
|
677 | + } |
|
649 | 678 | |
650 | 679 | // Okay, so copy the first one we made to here. |
651 | 680 | copy($smileyLocation, $currentPath); |
@@ -662,13 +691,15 @@ discard block |
||
662 | 691 | $newName = ''; |
663 | 692 | foreach ($_FILES as $name => $data) |
664 | 693 | { |
665 | - if ($_FILES[$name]['name'] == '') |
|
666 | - fatal_lang_error('smileys_upload_error_blank'); |
|
694 | + if ($_FILES[$name]['name'] == '') { |
|
695 | + fatal_lang_error('smileys_upload_error_blank'); |
|
696 | + } |
|
667 | 697 | |
668 | - if (empty($newName)) |
|
669 | - $newName = basename($_FILES[$name]['name']); |
|
670 | - elseif (basename($_FILES[$name]['name']) != $newName) |
|
671 | - fatal_lang_error('smileys_upload_error_name'); |
|
698 | + if (empty($newName)) { |
|
699 | + $newName = basename($_FILES[$name]['name']); |
|
700 | + } elseif (basename($_FILES[$name]['name']) != $newName) { |
|
701 | + fatal_lang_error('smileys_upload_error_name'); |
|
702 | + } |
|
672 | 703 | } |
673 | 704 | |
674 | 705 | foreach ($context['smiley_sets'] as $i => $set) |
@@ -676,31 +707,36 @@ discard block |
||
676 | 707 | $set['name'] = un_htmlspecialchars($set['name']); |
677 | 708 | $set['path'] = un_htmlspecialchars($set['path']); |
678 | 709 | |
679 | - if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') |
|
680 | - continue; |
|
710 | + if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') { |
|
711 | + continue; |
|
712 | + } |
|
681 | 713 | |
682 | 714 | // Got one... |
683 | - if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) |
|
684 | - fatal_lang_error('smileys_upload_error'); |
|
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'); |
|
717 | + } |
|
685 | 718 | |
686 | 719 | // Sorry, no spaces, dots, or anything else but letters allowed. |
687 | 720 | $_FILES['individual_' . $set['name']]['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['individual_' . $set['name']]['name']); |
688 | 721 | |
689 | 722 | // We only allow image files - it's THAT simple - no messing around here... |
690 | - if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) |
|
691 | - fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
723 | + if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) { |
|
724 | + fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
725 | + } |
|
692 | 726 | |
693 | 727 | // We only need the filename... |
694 | 728 | $destName = basename($_FILES['individual_' . $set['name']]['name']); |
695 | 729 | |
696 | 730 | // Make sure they aren't trying to upload a nasty file - for their own good here! |
697 | - if (in_array(strtolower($destName), $disabledFiles)) |
|
698 | - fatal_lang_error('smileys_upload_error_illegal'); |
|
731 | + if (in_array(strtolower($destName), $disabledFiles)) { |
|
732 | + fatal_lang_error('smileys_upload_error_illegal'); |
|
733 | + } |
|
699 | 734 | |
700 | 735 | // If the file exists - ignore it. |
701 | 736 | $smileyLocation = $context['smileys_dir'] . '/' . $set['path'] . '/' . $destName; |
702 | - if (file_exists($smileyLocation)) |
|
703 | - continue; |
|
737 | + if (file_exists($smileyLocation)) { |
|
738 | + continue; |
|
739 | + } |
|
704 | 740 | |
705 | 741 | // Finally - move the image! |
706 | 742 | move_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name'], $smileyLocation); |
@@ -712,8 +748,9 @@ discard block |
||
712 | 748 | } |
713 | 749 | |
714 | 750 | // Also make sure a filename was given. |
715 | - if (empty($_POST['smiley_filename'])) |
|
716 | - fatal_lang_error('smiley_has_no_filename'); |
|
751 | + if (empty($_POST['smiley_filename'])) { |
|
752 | + fatal_lang_error('smiley_has_no_filename'); |
|
753 | + } |
|
717 | 754 | |
718 | 755 | // Find the position on the right. |
719 | 756 | $smiley_order = '0'; |
@@ -732,8 +769,9 @@ discard block |
||
732 | 769 | list ($smiley_order) = $smcFunc['db_fetch_row']($request); |
733 | 770 | $smcFunc['db_free_result']($request); |
734 | 771 | |
735 | - if (empty($smiley_order)) |
|
736 | - $smiley_order = '0'; |
|
772 | + if (empty($smiley_order)) { |
|
773 | + $smiley_order = '0'; |
|
774 | + } |
|
737 | 775 | } |
738 | 776 | $smcFunc['db_insert']('', |
739 | 777 | '{db_prefix}smileys', |
@@ -761,17 +799,19 @@ discard block |
||
761 | 799 | { |
762 | 800 | foreach ($context['smiley_sets'] as $smiley_set) |
763 | 801 | { |
764 | - if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) |
|
765 | - continue; |
|
802 | + if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) { |
|
803 | + continue; |
|
804 | + } |
|
766 | 805 | |
767 | 806 | $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])); |
768 | 807 | while ($entry = $dir->read()) |
769 | 808 | { |
770 | - if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
771 | - $context['filenames'][strtolower($entry)] = array( |
|
809 | + if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
810 | + $context['filenames'][strtolower($entry)] = array( |
|
772 | 811 | 'id' => $smcFunc['htmlspecialchars']($entry), |
773 | 812 | 'selected' => false, |
774 | 813 | ); |
814 | + } |
|
775 | 815 | } |
776 | 816 | $dir->close(); |
777 | 817 | } |
@@ -809,17 +849,19 @@ discard block |
||
809 | 849 | // Changing the selected smileys? |
810 | 850 | if (isset($_POST['smiley_action']) && !empty($_POST['checked_smileys'])) |
811 | 851 | { |
812 | - foreach ($_POST['checked_smileys'] as $id => $smiley_id) |
|
813 | - $_POST['checked_smileys'][$id] = (int) $smiley_id; |
|
852 | + foreach ($_POST['checked_smileys'] as $id => $smiley_id) { |
|
853 | + $_POST['checked_smileys'][$id] = (int) $smiley_id; |
|
854 | + } |
|
814 | 855 | |
815 | - if ($_POST['smiley_action'] == 'delete') |
|
816 | - $smcFunc['db_query']('', ' |
|
856 | + if ($_POST['smiley_action'] == 'delete') { |
|
857 | + $smcFunc['db_query']('', ' |
|
817 | 858 | DELETE FROM {db_prefix}smileys |
818 | 859 | WHERE id_smiley IN ({array_int:checked_smileys})', |
819 | 860 | array( |
820 | 861 | 'checked_smileys' => $_POST['checked_smileys'], |
821 | 862 | ) |
822 | 863 | ); |
864 | + } |
|
823 | 865 | // Changing the status of the smiley? |
824 | 866 | else |
825 | 867 | { |
@@ -829,8 +871,8 @@ discard block |
||
829 | 871 | 'hidden' => 1, |
830 | 872 | 'popup' => 2 |
831 | 873 | ); |
832 | - if (isset($displayTypes[$_POST['smiley_action']])) |
|
833 | - $smcFunc['db_query']('', ' |
|
874 | + if (isset($displayTypes[$_POST['smiley_action']])) { |
|
875 | + $smcFunc['db_query']('', ' |
|
834 | 876 | UPDATE {db_prefix}smileys |
835 | 877 | SET hidden = {int:display_type} |
836 | 878 | WHERE id_smiley IN ({array_int:checked_smileys})', |
@@ -839,6 +881,7 @@ discard block |
||
839 | 881 | 'display_type' => $displayTypes[$_POST['smiley_action']], |
840 | 882 | ) |
841 | 883 | ); |
884 | + } |
|
842 | 885 | } |
843 | 886 | } |
844 | 887 | // Create/modify a smiley. |
@@ -864,12 +907,14 @@ discard block |
||
864 | 907 | $_POST['smiley_location'] = empty($_POST['smiley_location']) || $_POST['smiley_location'] > 2 || $_POST['smiley_location'] < 0 ? 0 : (int) $_POST['smiley_location']; |
865 | 908 | |
866 | 909 | // Make sure some code was entered. |
867 | - if (empty($_POST['smiley_code'])) |
|
868 | - fatal_lang_error('smiley_has_no_code'); |
|
910 | + if (empty($_POST['smiley_code'])) { |
|
911 | + fatal_lang_error('smiley_has_no_code'); |
|
912 | + } |
|
869 | 913 | |
870 | 914 | // Also make sure a filename was given. |
871 | - if (empty($_POST['smiley_filename'])) |
|
872 | - fatal_lang_error('smiley_has_no_filename'); |
|
915 | + if (empty($_POST['smiley_filename'])) { |
|
916 | + fatal_lang_error('smiley_has_no_filename'); |
|
917 | + } |
|
873 | 918 | |
874 | 919 | // Check whether the new code has duplicates. It should be unique. |
875 | 920 | $request = $smcFunc['db_query']('', ' |
@@ -883,8 +928,9 @@ discard block |
||
883 | 928 | 'smiley_code' => $_POST['smiley_code'], |
884 | 929 | ) |
885 | 930 | ); |
886 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
887 | - fatal_lang_error('smiley_not_unique'); |
|
931 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
932 | + fatal_lang_error('smiley_not_unique'); |
|
933 | + } |
|
888 | 934 | $smcFunc['db_free_result']($request); |
889 | 935 | |
890 | 936 | $smcFunc['db_query']('', ' |
@@ -913,13 +959,14 @@ discard block |
||
913 | 959 | // Load all known smiley sets. |
914 | 960 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
915 | 961 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
916 | - foreach ($context['smiley_sets'] as $i => $set) |
|
917 | - $context['smiley_sets'][$i] = array( |
|
962 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
963 | + $context['smiley_sets'][$i] = array( |
|
918 | 964 | 'id' => $i, |
919 | 965 | 'path' => $smcFunc['htmlspecialchars']($set), |
920 | 966 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
921 | 967 | 'selected' => $set == $modSettings['smiley_sets_default'] |
922 | 968 | ); |
969 | + } |
|
923 | 970 | |
924 | 971 | // Prepare overview of all (custom) smileys. |
925 | 972 | if ($context['sub_action'] == 'editsmileys') |
@@ -935,9 +982,10 @@ discard block |
||
935 | 982 | // Create a list of options for selecting smiley sets. |
936 | 983 | $smileyset_option_list = ' |
937 | 984 | <select name="set" onchange="changeSet(this.options[this.selectedIndex].value);">'; |
938 | - foreach ($context['smiley_sets'] as $smiley_set) |
|
939 | - $smileyset_option_list .= ' |
|
985 | + foreach ($context['smiley_sets'] as $smiley_set) { |
|
986 | + $smileyset_option_list .= ' |
|
940 | 987 | <option value="' . $smiley_set['path'] . '"' . ($modSettings['smiley_sets_default'] == $smiley_set['path'] ? ' selected' : '') . '>' . $smiley_set['name'] . '</option>'; |
988 | + } |
|
941 | 989 | $smileyset_option_list .= ' |
942 | 990 | </select>'; |
943 | 991 | |
@@ -999,12 +1047,13 @@ discard block |
||
999 | 1047 | 'data' => array( |
1000 | 1048 | 'function' => function ($rowData) use ($txt) |
1001 | 1049 | { |
1002 | - if (empty($rowData['hidden'])) |
|
1003 | - return $txt['smileys_location_form']; |
|
1004 | - elseif ($rowData['hidden'] == 1) |
|
1005 | - return $txt['smileys_location_hidden']; |
|
1006 | - else |
|
1007 | - return $txt['smileys_location_popup']; |
|
1050 | + if (empty($rowData['hidden'])) { |
|
1051 | + return $txt['smileys_location_form']; |
|
1052 | + } elseif ($rowData['hidden'] == 1) { |
|
1053 | + return $txt['smileys_location_hidden']; |
|
1054 | + } else { |
|
1055 | + return $txt['smileys_location_popup']; |
|
1056 | + } |
|
1008 | 1057 | }, |
1009 | 1058 | ), |
1010 | 1059 | 'sort' => array( |
@@ -1019,19 +1068,22 @@ discard block |
||
1019 | 1068 | 'data' => array( |
1020 | 1069 | 'function' => function ($rowData) use ($context, $txt, $modSettings, $smcFunc) |
1021 | 1070 | { |
1022 | - if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) |
|
1023 | - return $smcFunc['htmlspecialchars']($rowData['description']); |
|
1071 | + if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) { |
|
1072 | + return $smcFunc['htmlspecialchars']($rowData['description']); |
|
1073 | + } |
|
1024 | 1074 | |
1025 | 1075 | // Check if there are smileys missing in some sets. |
1026 | 1076 | $missing_sets = array(); |
1027 | - foreach ($context['smiley_sets'] as $smiley_set) |
|
1028 | - if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename']))) |
|
1077 | + foreach ($context['smiley_sets'] as $smiley_set) { |
|
1078 | + if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename']))) |
|
1029 | 1079 | $missing_sets[] = $smiley_set['path']; |
1080 | + } |
|
1030 | 1081 | |
1031 | 1082 | $description = $smcFunc['htmlspecialchars']($rowData['description']); |
1032 | 1083 | |
1033 | - if (!empty($missing_sets)) |
|
1034 | - $description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets)); |
|
1084 | + if (!empty($missing_sets)) { |
|
1085 | + $description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets)); |
|
1086 | + } |
|
1035 | 1087 | |
1036 | 1088 | return $description; |
1037 | 1089 | }, |
@@ -1147,13 +1199,14 @@ discard block |
||
1147 | 1199 | $context['smileys_dir_found'] = is_dir($context['smileys_dir']); |
1148 | 1200 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
1149 | 1201 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
1150 | - foreach ($context['smiley_sets'] as $i => $set) |
|
1151 | - $context['smiley_sets'][$i] = array( |
|
1202 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
1203 | + $context['smiley_sets'][$i] = array( |
|
1152 | 1204 | 'id' => $i, |
1153 | 1205 | 'path' => $smcFunc['htmlspecialchars']($set), |
1154 | 1206 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
1155 | 1207 | 'selected' => $set == $modSettings['smiley_sets_default'] |
1156 | 1208 | ); |
1209 | + } |
|
1157 | 1210 | |
1158 | 1211 | $context['selected_set'] = $modSettings['smiley_sets_default']; |
1159 | 1212 | |
@@ -1163,17 +1216,19 @@ discard block |
||
1163 | 1216 | { |
1164 | 1217 | foreach ($context['smiley_sets'] as $smiley_set) |
1165 | 1218 | { |
1166 | - if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) |
|
1167 | - continue; |
|
1219 | + if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) { |
|
1220 | + continue; |
|
1221 | + } |
|
1168 | 1222 | |
1169 | 1223 | $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])); |
1170 | 1224 | while ($entry = $dir->read()) |
1171 | 1225 | { |
1172 | - if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
1173 | - $context['filenames'][strtolower($entry)] = array( |
|
1226 | + if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
1227 | + $context['filenames'][strtolower($entry)] = array( |
|
1174 | 1228 | 'id' => $smcFunc['htmlspecialchars']($entry), |
1175 | 1229 | 'selected' => false, |
1176 | 1230 | ); |
1231 | + } |
|
1177 | 1232 | } |
1178 | 1233 | $dir->close(); |
1179 | 1234 | } |
@@ -1188,8 +1243,9 @@ discard block |
||
1188 | 1243 | 'current_smiley' => (int) $_REQUEST['smiley'], |
1189 | 1244 | ) |
1190 | 1245 | ); |
1191 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1192 | - fatal_lang_error('smiley_not_found'); |
|
1246 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1247 | + fatal_lang_error('smiley_not_found'); |
|
1248 | + } |
|
1193 | 1249 | $context['current_smiley'] = $smcFunc['db_fetch_assoc']($request); |
1194 | 1250 | $smcFunc['db_free_result']($request); |
1195 | 1251 | |
@@ -1197,8 +1253,9 @@ discard block |
||
1197 | 1253 | $context['current_smiley']['filename'] = $smcFunc['htmlspecialchars']($context['current_smiley']['filename']); |
1198 | 1254 | $context['current_smiley']['description'] = $smcFunc['htmlspecialchars']($context['current_smiley']['description']); |
1199 | 1255 | |
1200 | - if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) |
|
1201 | - $context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true; |
|
1256 | + if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) { |
|
1257 | + $context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true; |
|
1258 | + } |
|
1202 | 1259 | } |
1203 | 1260 | } |
1204 | 1261 | |
@@ -1223,8 +1280,9 @@ discard block |
||
1223 | 1280 | ) |
1224 | 1281 | ); |
1225 | 1282 | $smileys = array(); |
1226 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1227 | - $smileys[] = $row; |
|
1283 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1284 | + $smileys[] = $row; |
|
1285 | + } |
|
1228 | 1286 | $smcFunc['db_free_result']($request); |
1229 | 1287 | |
1230 | 1288 | return $smileys; |
@@ -1264,8 +1322,9 @@ discard block |
||
1264 | 1322 | $_GET['location'] = empty($_GET['location']) || $_GET['location'] != 'popup' ? 0 : 2; |
1265 | 1323 | $_GET['source'] = empty($_GET['source']) ? 0 : (int) $_GET['source']; |
1266 | 1324 | |
1267 | - if (empty($_GET['source'])) |
|
1268 | - fatal_lang_error('smiley_not_found'); |
|
1325 | + if (empty($_GET['source'])) { |
|
1326 | + fatal_lang_error('smiley_not_found'); |
|
1327 | + } |
|
1269 | 1328 | |
1270 | 1329 | if (!empty($_GET['after'])) |
1271 | 1330 | { |
@@ -1281,12 +1340,12 @@ discard block |
||
1281 | 1340 | 'after_smiley' => $_GET['after'], |
1282 | 1341 | ) |
1283 | 1342 | ); |
1284 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1285 | - fatal_lang_error('smiley_not_found'); |
|
1343 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1344 | + fatal_lang_error('smiley_not_found'); |
|
1345 | + } |
|
1286 | 1346 | list ($smiley_row, $smiley_order, $smileyLocation) = $smcFunc['db_fetch_row']($request); |
1287 | 1347 | $smcFunc['db_free_result']($request); |
1288 | - } |
|
1289 | - else |
|
1348 | + } else |
|
1290 | 1349 | { |
1291 | 1350 | $smiley_row = (int) $_GET['row']; |
1292 | 1351 | $smiley_order = -1; |
@@ -1360,14 +1419,15 @@ discard block |
||
1360 | 1419 | $context['move_smiley'] = empty($_REQUEST['move']) ? 0 : (int) $_REQUEST['move']; |
1361 | 1420 | |
1362 | 1421 | // Make sure all rows are sequential. |
1363 | - foreach (array_keys($context['smileys']) as $location) |
|
1364 | - $context['smileys'][$location] = array( |
|
1422 | + foreach (array_keys($context['smileys']) as $location) { |
|
1423 | + $context['smileys'][$location] = array( |
|
1365 | 1424 | 'id' => $location, |
1366 | 1425 | 'title' => $location == 'postform' ? $txt['smileys_location_form'] : $txt['smileys_location_popup'], |
1367 | 1426 | 'description' => $location == 'postform' ? $txt['smileys_location_form_description'] : $txt['smileys_location_popup_description'], |
1368 | 1427 | 'last_row' => count($context['smileys'][$location]['rows']), |
1369 | 1428 | 'rows' => array_values($context['smileys'][$location]['rows']), |
1370 | 1429 | ); |
1430 | + } |
|
1371 | 1431 | |
1372 | 1432 | // Check & fix smileys that are not ordered properly in the database. |
1373 | 1433 | foreach (array_keys($context['smileys']) as $location) |
@@ -1392,8 +1452,8 @@ discard block |
||
1392 | 1452 | $context['smileys'][$location]['rows'][$id][0]['row'] = $id; |
1393 | 1453 | } |
1394 | 1454 | // Make sure the smiley order is always sequential. |
1395 | - foreach ($smiley_row as $order_id => $smiley) |
|
1396 | - if ($order_id != $smiley['order']) |
|
1455 | + foreach ($smiley_row as $order_id => $smiley) { |
|
1456 | + if ($order_id != $smiley['order']) |
|
1397 | 1457 | $smcFunc['db_query']('', ' |
1398 | 1458 | UPDATE {db_prefix}smileys |
1399 | 1459 | SET smiley_order = {int:new_order} |
@@ -1403,6 +1463,7 @@ discard block |
||
1403 | 1463 | 'current_smiley' => $smiley['id'], |
1404 | 1464 | ) |
1405 | 1465 | ); |
1466 | + } |
|
1406 | 1467 | } |
1407 | 1468 | } |
1408 | 1469 | |
@@ -1436,19 +1497,20 @@ discard block |
||
1436 | 1497 | $context['filename'] = $base_name; |
1437 | 1498 | |
1438 | 1499 | // Check that the smiley is from simplemachines.org, for now... maybe add mirroring later. |
1439 | - if (preg_match('~^http://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) |
|
1440 | - fatal_lang_error('not_on_simplemachines'); |
|
1500 | + if (preg_match('~^http://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) { |
|
1501 | + fatal_lang_error('not_on_simplemachines'); |
|
1502 | + } |
|
1441 | 1503 | |
1442 | 1504 | $destination = $packagesdir . '/' . $base_name; |
1443 | 1505 | |
1444 | - if (file_exists($destination)) |
|
1445 | - fatal_lang_error('package_upload_error_exists'); |
|
1506 | + if (file_exists($destination)) { |
|
1507 | + fatal_lang_error('package_upload_error_exists'); |
|
1508 | + } |
|
1446 | 1509 | |
1447 | 1510 | // Let's copy it to the Packages directory |
1448 | 1511 | file_put_contents($destination, fetch_web_data($_REQUEST['set_gz'])); |
1449 | 1512 | $testing = true; |
1450 | - } |
|
1451 | - elseif (isset($_REQUEST['package'])) |
|
1513 | + } elseif (isset($_REQUEST['package'])) |
|
1452 | 1514 | { |
1453 | 1515 | $base_name = basename($_REQUEST['package']); |
1454 | 1516 | $name = $smcFunc['htmlspecialchars'](strtok(basename($_REQUEST['package']), '.')); |
@@ -1458,12 +1520,14 @@ discard block |
||
1458 | 1520 | $destination = $packagesdir . '/' . basename($_REQUEST['package']); |
1459 | 1521 | } |
1460 | 1522 | |
1461 | - if (!file_exists($destination)) |
|
1462 | - fatal_lang_error('package_no_file', false); |
|
1523 | + if (!file_exists($destination)) { |
|
1524 | + fatal_lang_error('package_no_file', false); |
|
1525 | + } |
|
1463 | 1526 | |
1464 | 1527 | // Make sure temp directory exists and is empty. |
1465 | - if (file_exists($packagesdir . '/temp')) |
|
1466 | - deltree($packagesdir . '/temp', false); |
|
1528 | + if (file_exists($packagesdir . '/temp')) { |
|
1529 | + deltree($packagesdir . '/temp', false); |
|
1530 | + } |
|
1467 | 1531 | |
1468 | 1532 | if (!mktree($packagesdir . '/temp', 0755)) |
1469 | 1533 | { |
@@ -1475,31 +1539,37 @@ discard block |
||
1475 | 1539 | 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)); |
1476 | 1540 | |
1477 | 1541 | deltree($packagesdir . '/temp', false); |
1478 | - if (!mktree($packagesdir . '/temp', 0777)) |
|
1479 | - fatal_lang_error('package_cant_download', false); |
|
1542 | + if (!mktree($packagesdir . '/temp', 0777)) { |
|
1543 | + fatal_lang_error('package_cant_download', false); |
|
1544 | + } |
|
1480 | 1545 | } |
1481 | 1546 | } |
1482 | 1547 | |
1483 | 1548 | $extracted = read_tgz_file($destination, $packagesdir . '/temp'); |
1484 | - if (!$extracted) |
|
1485 | - fatal_lang_error('packageget_unable', false, array('http://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name)); |
|
1486 | - if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) |
|
1487 | - foreach ($extracted as $file) |
|
1549 | + if (!$extracted) { |
|
1550 | + fatal_lang_error('packageget_unable', false, array('http://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name)); |
|
1551 | + } |
|
1552 | + if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) { |
|
1553 | + foreach ($extracted as $file) |
|
1488 | 1554 | if (basename($file['filename']) == 'package-info.xml') |
1489 | 1555 | { |
1490 | 1556 | $base_path = dirname($file['filename']) . '/'; |
1557 | + } |
|
1491 | 1558 | break; |
1492 | 1559 | } |
1493 | 1560 | |
1494 | - if (!isset($base_path)) |
|
1495 | - $base_path = ''; |
|
1561 | + if (!isset($base_path)) { |
|
1562 | + $base_path = ''; |
|
1563 | + } |
|
1496 | 1564 | |
1497 | - if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) |
|
1498 | - fatal_lang_error('package_get_error_missing_xml', false); |
|
1565 | + if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) { |
|
1566 | + fatal_lang_error('package_get_error_missing_xml', false); |
|
1567 | + } |
|
1499 | 1568 | |
1500 | 1569 | $smileyInfo = getPackageInfo($context['filename']); |
1501 | - if (!is_array($smileyInfo)) |
|
1502 | - fatal_lang_error($smileyInfo); |
|
1570 | + if (!is_array($smileyInfo)) { |
|
1571 | + fatal_lang_error($smileyInfo); |
|
1572 | + } |
|
1503 | 1573 | |
1504 | 1574 | // See if it is installed? |
1505 | 1575 | $request = $smcFunc['db_query']('', ' |
@@ -1515,8 +1585,9 @@ discard block |
||
1515 | 1585 | ) |
1516 | 1586 | ); |
1517 | 1587 | |
1518 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
1519 | - fata_lang_error('package_installed_warning1'); |
|
1588 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
1589 | + fata_lang_error('package_installed_warning1'); |
|
1590 | + } |
|
1520 | 1591 | |
1521 | 1592 | // Everything is fine, now it's time to do something |
1522 | 1593 | $actions = parsePackageInfo($smileyInfo['xml'], true, 'install'); |
@@ -1533,23 +1604,23 @@ discard block |
||
1533 | 1604 | { |
1534 | 1605 | $has_readme = true; |
1535 | 1606 | $type = 'package_' . $action['type']; |
1536 | - if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) |
|
1537 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r")); |
|
1538 | - elseif (file_exists($action['filename'])) |
|
1539 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
1607 | + if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) { |
|
1608 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r")); |
|
1609 | + } elseif (file_exists($action['filename'])) { |
|
1610 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
1611 | + } |
|
1540 | 1612 | |
1541 | 1613 | if (!empty($action['parse_bbc'])) |
1542 | 1614 | { |
1543 | 1615 | require_once($sourcedir . '/Subs-Post.php'); |
1544 | 1616 | preparsecode($context[$type]); |
1545 | 1617 | $context[$type] = parse_bbc($context[$type]); |
1618 | + } else { |
|
1619 | + $context[$type] = nl2br($context[$type]); |
|
1546 | 1620 | } |
1547 | - else |
|
1548 | - $context[$type] = nl2br($context[$type]); |
|
1549 | 1621 | |
1550 | 1622 | continue; |
1551 | - } |
|
1552 | - elseif ($action['type'] == 'require-dir') |
|
1623 | + } elseif ($action['type'] == 'require-dir') |
|
1553 | 1624 | { |
1554 | 1625 | // Do this one... |
1555 | 1626 | $thisAction = array( |
@@ -1568,12 +1639,12 @@ discard block |
||
1568 | 1639 | ); |
1569 | 1640 | } |
1570 | 1641 | // @todo None given? |
1571 | - if (empty($thisAction['description'])) |
|
1572 | - $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
1642 | + if (empty($thisAction['description'])) { |
|
1643 | + $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
1644 | + } |
|
1573 | 1645 | |
1574 | 1646 | $context['actions'][] = $thisAction; |
1575 | - } |
|
1576 | - elseif ($action['type'] == 'credits') |
|
1647 | + } elseif ($action['type'] == 'credits') |
|
1577 | 1648 | { |
1578 | 1649 | // Time to build the billboard |
1579 | 1650 | $credits_tag = array( |
@@ -1632,12 +1703,14 @@ discard block |
||
1632 | 1703 | cache_put_data('posting_smileys', null, 480); |
1633 | 1704 | } |
1634 | 1705 | |
1635 | - if (file_exists($packagesdir . '/temp')) |
|
1636 | - deltree($packagesdir . '/temp'); |
|
1706 | + if (file_exists($packagesdir . '/temp')) { |
|
1707 | + deltree($packagesdir . '/temp'); |
|
1708 | + } |
|
1637 | 1709 | |
1638 | - if (!$testing) |
|
1639 | - redirectexit('action=admin;area=smileys'); |
|
1640 | -} |
|
1710 | + if (!$testing) { |
|
1711 | + redirectexit('action=admin;area=smileys'); |
|
1712 | + } |
|
1713 | + } |
|
1641 | 1714 | |
1642 | 1715 | /** |
1643 | 1716 | * A function to import new smileys from an existing directory into the database. |
@@ -1648,15 +1721,17 @@ discard block |
||
1648 | 1721 | { |
1649 | 1722 | global $modSettings, $smcFunc; |
1650 | 1723 | |
1651 | - if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) |
|
1652 | - fatal_lang_error('smiley_set_unable_to_import'); |
|
1724 | + if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) { |
|
1725 | + fatal_lang_error('smiley_set_unable_to_import'); |
|
1726 | + } |
|
1653 | 1727 | |
1654 | 1728 | $smileys = array(); |
1655 | 1729 | $dir = dir($modSettings['smileys_dir'] . '/' . $smileyPath); |
1656 | 1730 | while ($entry = $dir->read()) |
1657 | 1731 | { |
1658 | - if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
1659 | - $smileys[strtolower($entry)] = $entry; |
|
1732 | + if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
1733 | + $smileys[strtolower($entry)] = $entry; |
|
1734 | + } |
|
1660 | 1735 | } |
1661 | 1736 | $dir->close(); |
1662 | 1737 | |
@@ -1669,9 +1744,10 @@ discard block |
||
1669 | 1744 | 'smiley_list' => $smileys, |
1670 | 1745 | ) |
1671 | 1746 | ); |
1672 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1673 | - if (isset($smileys[strtolower($row['filename'])])) |
|
1747 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1748 | + if (isset($smileys[strtolower($row['filename'])])) |
|
1674 | 1749 | unset($smileys[strtolower($row['filename'])]); |
1750 | + } |
|
1675 | 1751 | $smcFunc['db_free_result']($request); |
1676 | 1752 | |
1677 | 1753 | $request = $smcFunc['db_query']('', ' |
@@ -1688,9 +1764,10 @@ discard block |
||
1688 | 1764 | $smcFunc['db_free_result']($request); |
1689 | 1765 | |
1690 | 1766 | $new_smileys = array(); |
1691 | - foreach ($smileys as $smiley) |
|
1692 | - if (strlen($smiley) <= 48) |
|
1767 | + foreach ($smileys as $smiley) { |
|
1768 | + if (strlen($smiley) <= 48) |
|
1693 | 1769 | $new_smileys[] = array(':' . strtok($smiley, '.') . ':', $smiley, strtok($smiley, '.'), 0, ++$smiley_order); |
1770 | + } |
|
1694 | 1771 | |
1695 | 1772 | if (!empty($new_smileys)) |
1696 | 1773 | { |
@@ -1755,8 +1832,9 @@ discard block |
||
1755 | 1832 | if (isset($_POST['delete']) && !empty($_POST['checked_icons'])) |
1756 | 1833 | { |
1757 | 1834 | $deleteIcons = array(); |
1758 | - foreach ($_POST['checked_icons'] as $icon) |
|
1759 | - $deleteIcons[] = (int) $icon; |
|
1835 | + foreach ($_POST['checked_icons'] as $icon) { |
|
1836 | + $deleteIcons[] = (int) $icon; |
|
1837 | + } |
|
1760 | 1838 | |
1761 | 1839 | // Do the actual delete! |
1762 | 1840 | $smcFunc['db_query']('', ' |
@@ -1773,35 +1851,41 @@ discard block |
||
1773 | 1851 | $_GET['icon'] = (int) $_GET['icon']; |
1774 | 1852 | |
1775 | 1853 | // Do some preperation with the data... like check the icon exists *somewhere* |
1776 | - if (strpos($_POST['icon_filename'], '.png') !== false) |
|
1777 | - $_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4); |
|
1778 | - if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) |
|
1779 | - fatal_lang_error('icon_not_found'); |
|
1854 | + if (strpos($_POST['icon_filename'], '.png') !== false) { |
|
1855 | + $_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4); |
|
1856 | + } |
|
1857 | + if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) { |
|
1858 | + fatal_lang_error('icon_not_found'); |
|
1859 | + } |
|
1780 | 1860 | // There is a 16 character limit on message icons... |
1781 | - elseif (strlen($_POST['icon_filename']) > 16) |
|
1782 | - fatal_lang_error('icon_name_too_long'); |
|
1783 | - elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) |
|
1784 | - fatal_lang_error('icon_after_itself'); |
|
1861 | + elseif (strlen($_POST['icon_filename']) > 16) { |
|
1862 | + fatal_lang_error('icon_name_too_long'); |
|
1863 | + } elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) { |
|
1864 | + fatal_lang_error('icon_after_itself'); |
|
1865 | + } |
|
1785 | 1866 | |
1786 | 1867 | // First do the sorting... if this is an edit reduce the order of everything after it by one ;) |
1787 | 1868 | if ($_GET['icon'] != 0) |
1788 | 1869 | { |
1789 | 1870 | $oldOrder = $context['icons'][$_GET['icon']]['true_order']; |
1790 | - foreach ($context['icons'] as $id => $data) |
|
1791 | - if ($data['true_order'] > $oldOrder) |
|
1871 | + foreach ($context['icons'] as $id => $data) { |
|
1872 | + if ($data['true_order'] > $oldOrder) |
|
1792 | 1873 | $context['icons'][$id]['true_order']--; |
1874 | + } |
|
1793 | 1875 | } |
1794 | 1876 | |
1795 | 1877 | // If there are no existing icons and this is a new one, set the id to 1 (mainly for non-mysql) |
1796 | - if (empty($_GET['icon']) && empty($context['icons'])) |
|
1797 | - $_GET['icon'] = 1; |
|
1878 | + if (empty($_GET['icon']) && empty($context['icons'])) { |
|
1879 | + $_GET['icon'] = 1; |
|
1880 | + } |
|
1798 | 1881 | |
1799 | 1882 | // Get the new order. |
1800 | 1883 | $newOrder = $_POST['icon_location'] == 0 ? 0 : $context['icons'][$_POST['icon_location']]['true_order'] + 1; |
1801 | 1884 | // Do the same, but with the one that used to be after this icon, done to avoid conflict. |
1802 | - foreach ($context['icons'] as $id => $data) |
|
1803 | - if ($data['true_order'] >= $newOrder) |
|
1885 | + foreach ($context['icons'] as $id => $data) { |
|
1886 | + if ($data['true_order'] >= $newOrder) |
|
1804 | 1887 | $context['icons'][$id]['true_order']++; |
1888 | + } |
|
1805 | 1889 | |
1806 | 1890 | // Finally set the current icon's position! |
1807 | 1891 | $context['icons'][$_GET['icon']]['true_order'] = $newOrder; |
@@ -1819,8 +1903,7 @@ discard block |
||
1819 | 1903 | if ($id != 0) |
1820 | 1904 | { |
1821 | 1905 | $iconInsert[] = array($id, $icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']); |
1822 | - } |
|
1823 | - else |
|
1906 | + } else |
|
1824 | 1907 | { |
1825 | 1908 | $iconInsert_new[] = array($icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']); |
1826 | 1909 | } |
@@ -1845,8 +1928,9 @@ discard block |
||
1845 | 1928 | } |
1846 | 1929 | |
1847 | 1930 | // Unless we're adding a new thing, we'll escape |
1848 | - if (!isset($_POST['add'])) |
|
1849 | - redirectexit('action=admin;area=smileys;sa=editicons'); |
|
1931 | + if (!isset($_POST['add'])) { |
|
1932 | + redirectexit('action=admin;area=smileys;sa=editicons'); |
|
1933 | + } |
|
1850 | 1934 | } |
1851 | 1935 | |
1852 | 1936 | $context[$context['admin_menu_name']]['current_subsection'] = 'editicons'; |
@@ -1956,8 +2040,9 @@ discard block |
||
1956 | 2040 | $context['new_icon'] = !isset($_GET['icon']); |
1957 | 2041 | |
1958 | 2042 | // Get the properties of the current icon from the icon list. |
1959 | - if (!$context['new_icon']) |
|
1960 | - $context['icon'] = $context['icons'][$_GET['icon']]; |
|
2043 | + if (!$context['new_icon']) { |
|
2044 | + $context['icon'] = $context['icons'][$_GET['icon']]; |
|
2045 | + } |
|
1961 | 2046 | |
1962 | 2047 | // Get a list of boards needed for assigning this icon to a specific board. |
1963 | 2048 | $boardListOptions = array( |
@@ -1991,8 +2076,9 @@ discard block |
||
1991 | 2076 | ); |
1992 | 2077 | |
1993 | 2078 | $message_icons = array(); |
1994 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1995 | - $message_icons[] = $row; |
|
2079 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2080 | + $message_icons[] = $row; |
|
2081 | + } |
|
1996 | 2082 | $smcFunc['db_free_result']($request); |
1997 | 2083 | |
1998 | 2084 | return $message_icons; |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | 'value' => $txt['date'], |
137 | 137 | ), |
138 | 138 | 'data' => array( |
139 | - 'function' => function ($rowData) use ($txt) |
|
139 | + 'function' => function($rowData) use ($txt) |
|
140 | 140 | { |
141 | 141 | // Recurring every year or just a single year? |
142 | 142 | $year = $rowData['year'] == '0004' ? sprintf('(%1$s)', $txt['every_year']) : $rowData['year']; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | checkSession(); |
219 | 219 | |
220 | 220 | // Not too long good sir? |
221 | - $_REQUEST['title'] = $smcFunc['substr']($_REQUEST['title'], 0, 60); |
|
221 | + $_REQUEST['title'] = $smcFunc['substr']($_REQUEST['title'], 0, 60); |
|
222 | 222 | $_REQUEST['holiday'] = isset($_REQUEST['holiday']) ? (int) $_REQUEST['holiday'] : 0; |
223 | 223 | |
224 | 224 | if (isset($_REQUEST['delete'])) |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * The main controlling function doesn't have much to do... yet. |
@@ -43,8 +44,7 @@ discard block |
||
43 | 44 | 'settings' => 'ModifyCalendarSettings' |
44 | 45 | ); |
45 | 46 | $default = 'holidays'; |
46 | - } |
|
47 | - else |
|
47 | + } else |
|
48 | 48 | { |
49 | 49 | $subActions = array( |
50 | 50 | 'settings' => 'ModifyCalendarSettings' |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | 'help' => 'calendar', |
61 | 61 | 'description' => $txt['calendar_settings_desc'], |
62 | 62 | ); |
63 | - if (!empty($modSettings['cal_enabled'])) |
|
64 | - $context[$context['admin_menu_name']]['tab_data']['tabs'] = array( |
|
63 | + if (!empty($modSettings['cal_enabled'])) { |
|
64 | + $context[$context['admin_menu_name']]['tab_data']['tabs'] = array( |
|
65 | 65 | 'holidays' => array( |
66 | 66 | 'description' => $txt['manage_holidays_desc'], |
67 | 67 | ), |
@@ -69,6 +69,7 @@ discard block |
||
69 | 69 | 'description' => $txt['calendar_settings_desc'], |
70 | 70 | ), |
71 | 71 | ); |
72 | + } |
|
72 | 73 | |
73 | 74 | call_integration_hook('integrate_manage_calendar', array(&$subActions)); |
74 | 75 | |
@@ -88,8 +89,9 @@ discard block |
||
88 | 89 | checkSession(); |
89 | 90 | validateToken('admin-mc'); |
90 | 91 | |
91 | - foreach ($_REQUEST['holiday'] as $id => $value) |
|
92 | - $_REQUEST['holiday'][$id] = (int) $id; |
|
92 | + foreach ($_REQUEST['holiday'] as $id => $value) { |
|
93 | + $_REQUEST['holiday'][$id] = (int) $id; |
|
94 | + } |
|
93 | 95 | |
94 | 96 | // Now the IDs are "safe" do the delete... |
95 | 97 | require_once($sourcedir . '/Subs-Calendar.php'); |
@@ -209,8 +211,9 @@ discard block |
||
209 | 211 | $context['sub_template'] = 'edit_holiday'; |
210 | 212 | |
211 | 213 | // Cast this for safety... |
212 | - if (isset($_REQUEST['holiday'])) |
|
213 | - $_REQUEST['holiday'] = (int) $_REQUEST['holiday']; |
|
214 | + if (isset($_REQUEST['holiday'])) { |
|
215 | + $_REQUEST['holiday'] = (int) $_REQUEST['holiday']; |
|
216 | + } |
|
214 | 217 | |
215 | 218 | // Submitting? |
216 | 219 | if (isset($_POST[$context['session_var']]) && (isset($_REQUEST['delete']) || $_REQUEST['title'] != '')) |
@@ -221,19 +224,19 @@ discard block |
||
221 | 224 | $_REQUEST['title'] = $smcFunc['substr']($_REQUEST['title'], 0, 60); |
222 | 225 | $_REQUEST['holiday'] = isset($_REQUEST['holiday']) ? (int) $_REQUEST['holiday'] : 0; |
223 | 226 | |
224 | - if (isset($_REQUEST['delete'])) |
|
225 | - $smcFunc['db_query']('', ' |
|
227 | + if (isset($_REQUEST['delete'])) { |
|
228 | + $smcFunc['db_query']('', ' |
|
226 | 229 | DELETE FROM {db_prefix}calendar_holidays |
227 | 230 | WHERE id_holiday = {int:selected_holiday}', |
228 | 231 | array( |
229 | 232 | 'selected_holiday' => $_REQUEST['holiday'], |
230 | 233 | ) |
231 | 234 | ); |
232 | - else |
|
235 | + } else |
|
233 | 236 | { |
234 | 237 | $date = strftime($_REQUEST['year'] <= 4 ? '0004-%m-%d' : '%Y-%m-%d', mktime(0, 0, 0, $_REQUEST['month'], $_REQUEST['day'], $_REQUEST['year'])); |
235 | - if (isset($_REQUEST['edit'])) |
|
236 | - $smcFunc['db_query']('', ' |
|
238 | + if (isset($_REQUEST['edit'])) { |
|
239 | + $smcFunc['db_query']('', ' |
|
237 | 240 | UPDATE {db_prefix}calendar_holidays |
238 | 241 | SET event_date = {date:holiday_date}, title = {string:holiday_title} |
239 | 242 | WHERE id_holiday = {int:selected_holiday}', |
@@ -243,8 +246,8 @@ discard block |
||
243 | 246 | 'holiday_title' => $_REQUEST['title'], |
244 | 247 | ) |
245 | 248 | ); |
246 | - else |
|
247 | - $smcFunc['db_insert']('', |
|
249 | + } else { |
|
250 | + $smcFunc['db_insert']('', |
|
248 | 251 | '{db_prefix}calendar_holidays', |
249 | 252 | array( |
250 | 253 | 'event_date' => 'date', 'title' => 'string-60', |
@@ -254,6 +257,7 @@ discard block |
||
254 | 257 | ), |
255 | 258 | array('id_holiday') |
256 | 259 | ); |
260 | + } |
|
257 | 261 | } |
258 | 262 | |
259 | 263 | updateSettings(array( |
@@ -265,14 +269,15 @@ discard block |
||
265 | 269 | } |
266 | 270 | |
267 | 271 | // Default states... |
268 | - if ($context['is_new']) |
|
269 | - $context['holiday'] = array( |
|
272 | + if ($context['is_new']) { |
|
273 | + $context['holiday'] = array( |
|
270 | 274 | 'id' => 0, |
271 | 275 | 'day' => date('d'), |
272 | 276 | 'month' => date('m'), |
273 | 277 | 'year' => '0000', |
274 | 278 | 'title' => '' |
275 | 279 | ); |
280 | + } |
|
276 | 281 | // If it's not new load the data. |
277 | 282 | else |
278 | 283 | { |
@@ -285,14 +290,15 @@ discard block |
||
285 | 290 | 'selected_holiday' => $_REQUEST['holiday'], |
286 | 291 | ) |
287 | 292 | ); |
288 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
289 | - $context['holiday'] = array( |
|
293 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
294 | + $context['holiday'] = array( |
|
290 | 295 | 'id' => $row['id_holiday'], |
291 | 296 | 'day' => $row['day'], |
292 | 297 | 'month' => $row['month'], |
293 | 298 | 'year' => $row['year'] <= 4 ? 0 : $row['year'], |
294 | 299 | 'title' => $row['title'] |
295 | 300 | ); |
301 | + } |
|
296 | 302 | $smcFunc['db_free_result']($request); |
297 | 303 | } |
298 | 304 | |
@@ -319,16 +325,17 @@ discard block |
||
319 | 325 | array( |
320 | 326 | ) |
321 | 327 | ); |
322 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
323 | - $boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name']; |
|
328 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
329 | + $boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name']; |
|
330 | + } |
|
324 | 331 | $smcFunc['db_free_result']($request); |
325 | 332 | |
326 | 333 | require_once($sourcedir . '/Subs-Boards.php'); |
327 | 334 | sortBoards($boards); |
328 | 335 | |
329 | 336 | // Look, all the calendar settings - of which there are many! |
330 | - if (!empty($modSettings['cal_enabled'])) |
|
331 | - $config_vars = array( |
|
337 | + if (!empty($modSettings['cal_enabled'])) { |
|
338 | + $config_vars = array( |
|
332 | 339 | array('check', 'cal_enabled'), |
333 | 340 | '', |
334 | 341 | // All the permissions: |
@@ -371,14 +378,16 @@ discard block |
||
371 | 378 | array('check', 'cal_short_days'), |
372 | 379 | array('check', 'cal_short_months'), |
373 | 380 | ); |
374 | - else |
|
375 | - $config_vars = array( |
|
381 | + } else { |
|
382 | + $config_vars = array( |
|
376 | 383 | array('check', 'cal_enabled'), |
377 | 384 | ); |
385 | + } |
|
378 | 386 | |
379 | 387 | call_integration_hook('integrate_modify_calendar_settings', array(&$config_vars)); |
380 | - if ($return_config) |
|
381 | - return $config_vars; |
|
388 | + if ($return_config) { |
|
389 | + return $config_vars; |
|
390 | + } |
|
382 | 391 | |
383 | 392 | // Get the settings template fired up. |
384 | 393 | require_once($sourcedir . '/ManageServer.php'); |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | 'member_name' => $regOptions['username'], |
587 | 587 | 'email_address' => $regOptions['email'], |
588 | 588 | 'passwd' => hash_password($regOptions['username'], $regOptions['password']), |
589 | - 'password_salt' => substr(md5(mt_rand()), 0, 4) , |
|
589 | + 'password_salt' => substr(md5(mt_rand()), 0, 4), |
|
590 | 590 | 'posts' => 0, |
591 | 591 | 'date_registered' => time(), |
592 | 592 | 'member_ip' => $regOptions['interface'] == 'admin' ? '127.0.0.1' : $user_info['ip'], |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | 'time_offset', |
677 | 677 | ); |
678 | 678 | $knownInets = array( |
679 | - 'member_ip','member_ip2', |
|
679 | + 'member_ip', 'member_ip2', |
|
680 | 680 | ); |
681 | 681 | |
682 | 682 | // Call an optional function to validate the users' input. |
@@ -904,7 +904,7 @@ discard block |
||
904 | 904 | $checkName = strtr($name, array('_' => '\\_', '%' => '\\%')); |
905 | 905 | |
906 | 906 | //when we got no wildcard we can use equal -> fast |
907 | - $operator = (strpos($checkName, '%') || strpos($checkName, '_') ? 'LIKE' : '=' ); |
|
907 | + $operator = (strpos($checkName, '%') || strpos($checkName, '_') ? 'LIKE' : '='); |
|
908 | 908 | |
909 | 909 | // Make sure they don't want someone else's name. |
910 | 910 | $request = $smcFunc['db_query']('', ' |
@@ -1273,7 +1273,7 @@ discard block |
||
1273 | 1273 | $user_info['buddies'][] = $userReceiver; |
1274 | 1274 | |
1275 | 1275 | // And add a nice alert. Don't abuse though! |
1276 | - if ((cache_get_data('Buddy-sent-'. $user_info['id'] .'-'. $userReceiver, 86400)) == null) |
|
1276 | + if ((cache_get_data('Buddy-sent-' . $user_info['id'] . '-' . $userReceiver, 86400)) == null) |
|
1277 | 1277 | { |
1278 | 1278 | $smcFunc['db_insert']('insert', |
1279 | 1279 | '{db_prefix}background_tasks', |
@@ -1288,7 +1288,7 @@ discard block |
||
1288 | 1288 | ); |
1289 | 1289 | |
1290 | 1290 | // Store this in a cache entry to avoid creating multiple alerts. Give it a long life cycle. |
1291 | - cache_put_data('Buddy-sent-'. $user_info['id'] .'-'. $userReceiver, '1', 86400); |
|
1291 | + cache_put_data('Buddy-sent-' . $user_info['id'] . '-' . $userReceiver, '1', 86400); |
|
1292 | 1292 | } |
1293 | 1293 | } |
1294 | 1294 |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Delete one or more members. |
@@ -43,30 +44,32 @@ discard block |
||
43 | 44 | setMemoryLimit('128M'); |
44 | 45 | |
45 | 46 | // If it's not an array, make it so! |
46 | - if (!is_array($users)) |
|
47 | - $users = array($users); |
|
48 | - else |
|
49 | - $users = array_unique($users); |
|
47 | + if (!is_array($users)) { |
|
48 | + $users = array($users); |
|
49 | + } else { |
|
50 | + $users = array_unique($users); |
|
51 | + } |
|
50 | 52 | |
51 | 53 | // Make sure there's no void user in here. |
52 | 54 | $users = array_diff($users, array(0)); |
53 | 55 | |
54 | 56 | // How many are they deleting? |
55 | - if (empty($users)) |
|
56 | - return; |
|
57 | - elseif (count($users) == 1) |
|
57 | + if (empty($users)) { |
|
58 | + return; |
|
59 | + } elseif (count($users) == 1) |
|
58 | 60 | { |
59 | 61 | list ($user) = $users; |
60 | 62 | |
61 | - if ($user == $user_info['id']) |
|
62 | - isAllowedTo('profile_remove_own'); |
|
63 | - else |
|
64 | - isAllowedTo('profile_remove_any'); |
|
65 | - } |
|
66 | - else |
|
63 | + if ($user == $user_info['id']) { |
|
64 | + isAllowedTo('profile_remove_own'); |
|
65 | + } else { |
|
66 | + isAllowedTo('profile_remove_any'); |
|
67 | + } |
|
68 | + } else |
|
67 | 69 | { |
68 | - foreach ($users as $k => $v) |
|
69 | - $users[$k] = (int) $v; |
|
70 | + foreach ($users as $k => $v) { |
|
71 | + $users[$k] = (int) $v; |
|
72 | + } |
|
70 | 73 | |
71 | 74 | // Deleting more than one? You can't have more than one account... |
72 | 75 | isAllowedTo('profile_remove_any'); |
@@ -88,26 +91,30 @@ discard block |
||
88 | 91 | $user_log_details = array(); |
89 | 92 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
90 | 93 | { |
91 | - if ($row['is_admin']) |
|
92 | - $admins[] = $row['id_member']; |
|
94 | + if ($row['is_admin']) { |
|
95 | + $admins[] = $row['id_member']; |
|
96 | + } |
|
93 | 97 | $user_log_details[$row['id_member']] = array($row['id_member'], $row['member_name']); |
94 | 98 | } |
95 | 99 | $smcFunc['db_free_result']($request); |
96 | 100 | |
97 | - if (empty($user_log_details)) |
|
98 | - return; |
|
101 | + if (empty($user_log_details)) { |
|
102 | + return; |
|
103 | + } |
|
99 | 104 | |
100 | 105 | // Make sure they aren't trying to delete administrators if they aren't one. But don't bother checking if it's just themself. |
101 | 106 | if (!empty($admins) && ($check_not_admin || (!allowedTo('admin_forum') && (count($users) != 1 || $users[0] != $user_info['id'])))) |
102 | 107 | { |
103 | 108 | $users = array_diff($users, $admins); |
104 | - foreach ($admins as $id) |
|
105 | - unset($user_log_details[$id]); |
|
109 | + foreach ($admins as $id) { |
|
110 | + unset($user_log_details[$id]); |
|
111 | + } |
|
106 | 112 | } |
107 | 113 | |
108 | 114 | // No one left? |
109 | - if (empty($users)) |
|
110 | - return; |
|
115 | + if (empty($users)) { |
|
116 | + return; |
|
117 | + } |
|
111 | 118 | |
112 | 119 | // Log the action - regardless of who is deleting it. |
113 | 120 | $log_changes = array(); |
@@ -124,8 +131,9 @@ discard block |
||
124 | 131 | ); |
125 | 132 | |
126 | 133 | // Remove any cached data if enabled. |
127 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
128 | - cache_put_data('user_settings-' . $user[0], null, 60); |
|
134 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
135 | + cache_put_data('user_settings-' . $user[0], null, 60); |
|
136 | + } |
|
129 | 137 | } |
130 | 138 | |
131 | 139 | // Make these peoples' posts guest posts. |
@@ -388,8 +396,8 @@ discard block |
||
388 | 396 | 'buddy_list' => implode(', buddy_list) != 0 OR FIND_IN_SET(', $users), |
389 | 397 | ) |
390 | 398 | ); |
391 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
392 | - $smcFunc['db_query']('', ' |
|
399 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
400 | + $smcFunc['db_query']('', ' |
|
393 | 401 | UPDATE {db_prefix}members |
394 | 402 | SET |
395 | 403 | pm_ignore_list = {string:pm_ignore_list}, |
@@ -401,6 +409,7 @@ discard block |
||
401 | 409 | 'buddy_list' => implode(',', array_diff(explode(',', $row['buddy_list']), $users)), |
402 | 410 | ) |
403 | 411 | ); |
412 | + } |
|
404 | 413 | $smcFunc['db_free_result']($request); |
405 | 414 | |
406 | 415 | // Make sure no member's birthday is still sticking in the calendar... |
@@ -455,29 +464,34 @@ discard block |
||
455 | 464 | elseif ($regOptions['interface'] == 'guest') |
456 | 465 | { |
457 | 466 | // You cannot register twice... |
458 | - if (empty($user_info['is_guest'])) |
|
459 | - redirectexit(); |
|
467 | + if (empty($user_info['is_guest'])) { |
|
468 | + redirectexit(); |
|
469 | + } |
|
460 | 470 | |
461 | 471 | // Make sure they didn't just register with this session. |
462 | - if (!empty($_SESSION['just_registered']) && empty($modSettings['disableRegisterCheck'])) |
|
463 | - fatal_lang_error('register_only_once', false); |
|
472 | + if (!empty($_SESSION['just_registered']) && empty($modSettings['disableRegisterCheck'])) { |
|
473 | + fatal_lang_error('register_only_once', false); |
|
474 | + } |
|
464 | 475 | } |
465 | 476 | |
466 | 477 | // Spaces and other odd characters are evil... |
467 | 478 | $regOptions['username'] = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $regOptions['username'])); |
468 | 479 | |
469 | 480 | // @todo Separate the sprintf? |
470 | - if (empty($regOptions['email']) || !filter_var($regOptions['email'], FILTER_VALIDATE_EMAIL) || strlen($regOptions['email']) > 255) |
|
471 | - $reg_errors[] = array('lang', 'profile_error_bad_email'); |
|
481 | + if (empty($regOptions['email']) || !filter_var($regOptions['email'], FILTER_VALIDATE_EMAIL) || strlen($regOptions['email']) > 255) { |
|
482 | + $reg_errors[] = array('lang', 'profile_error_bad_email'); |
|
483 | + } |
|
472 | 484 | |
473 | 485 | $username_validation_errors = validateUsername(0, $regOptions['username'], true, !empty($regOptions['check_reserved_name'])); |
474 | - if (!empty($username_validation_errors)) |
|
475 | - $reg_errors = array_merge($reg_errors, $username_validation_errors); |
|
486 | + if (!empty($username_validation_errors)) { |
|
487 | + $reg_errors = array_merge($reg_errors, $username_validation_errors); |
|
488 | + } |
|
476 | 489 | |
477 | 490 | // Generate a validation code if it's supposed to be emailed. |
478 | 491 | $validation_code = ''; |
479 | - if ($regOptions['require'] == 'activation') |
|
480 | - $validation_code = generateValidationCode(); |
|
492 | + if ($regOptions['require'] == 'activation') { |
|
493 | + $validation_code = generateValidationCode(); |
|
494 | + } |
|
481 | 495 | |
482 | 496 | // If you haven't put in a password generate one. |
483 | 497 | if ($regOptions['interface'] == 'admin' && $regOptions['password'] == '') |
@@ -487,8 +501,9 @@ discard block |
||
487 | 501 | $regOptions['password_check'] = $regOptions['password']; |
488 | 502 | } |
489 | 503 | // Does the first password match the second? |
490 | - elseif ($regOptions['password'] != $regOptions['password_check']) |
|
491 | - $reg_errors[] = array('lang', 'passwords_dont_match'); |
|
504 | + elseif ($regOptions['password'] != $regOptions['password_check']) { |
|
505 | + $reg_errors[] = array('lang', 'passwords_dont_match'); |
|
506 | + } |
|
492 | 507 | |
493 | 508 | // That's kind of easy to guess... |
494 | 509 | if ($regOptions['password'] == '') |
@@ -502,13 +517,15 @@ discard block |
||
502 | 517 | $passwordError = validatePassword($regOptions['password'], $regOptions['username'], array($regOptions['email'])); |
503 | 518 | |
504 | 519 | // Password isn't legal? |
505 | - if ($passwordError != null) |
|
506 | - $reg_errors[] = array('lang', 'profile_error_password_' . $passwordError); |
|
520 | + if ($passwordError != null) { |
|
521 | + $reg_errors[] = array('lang', 'profile_error_password_' . $passwordError); |
|
522 | + } |
|
507 | 523 | } |
508 | 524 | |
509 | 525 | // You may not be allowed to register this email. |
510 | - if (!empty($regOptions['check_email_ban'])) |
|
511 | - isBannedEmail($regOptions['email'], 'cannot_register', $txt['ban_register_prohibited']); |
|
526 | + if (!empty($regOptions['check_email_ban'])) { |
|
527 | + isBannedEmail($regOptions['email'], 'cannot_register', $txt['ban_register_prohibited']); |
|
528 | + } |
|
512 | 529 | |
513 | 530 | // Check if the email address is in use. |
514 | 531 | $request = $smcFunc['db_query']('', ' |
@@ -523,8 +540,9 @@ discard block |
||
523 | 540 | ) |
524 | 541 | ); |
525 | 542 | // @todo Separate the sprintf? |
526 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
527 | - $reg_errors[] = array('lang', 'email_in_use', false, array($smcFunc['htmlspecialchars']($regOptions['email']))); |
|
543 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
544 | + $reg_errors[] = array('lang', 'email_in_use', false, array($smcFunc['htmlspecialchars']($regOptions['email']))); |
|
545 | + } |
|
528 | 546 | |
529 | 547 | $smcFunc['db_free_result']($request); |
530 | 548 | |
@@ -539,24 +557,27 @@ discard block |
||
539 | 557 | 1 = The text/index. |
540 | 558 | 2 = Whether to log. |
541 | 559 | 3 = sprintf data if necessary. */ |
542 | - if ($error[0] == 'lang') |
|
543 | - loadLanguage('Errors'); |
|
560 | + if ($error[0] == 'lang') { |
|
561 | + loadLanguage('Errors'); |
|
562 | + } |
|
544 | 563 | $message = $error[0] == 'lang' ? (empty($error[3]) ? $txt[$error[1]] : vsprintf($txt[$error[1]], $error[3])) : $error[1]; |
545 | 564 | |
546 | 565 | // What to do, what to do, what to do. |
547 | 566 | if ($return_errors) |
548 | 567 | { |
549 | - if (!empty($error[2])) |
|
550 | - log_error($message, $error[2]); |
|
568 | + if (!empty($error[2])) { |
|
569 | + log_error($message, $error[2]); |
|
570 | + } |
|
551 | 571 | $reg_errors[$key] = $message; |
572 | + } else { |
|
573 | + fatal_error($message, empty($error[2]) ? false : $error[2]); |
|
552 | 574 | } |
553 | - else |
|
554 | - fatal_error($message, empty($error[2]) ? false : $error[2]); |
|
555 | 575 | } |
556 | 576 | |
557 | 577 | // If there's any errors left return them at once! |
558 | - if (!empty($reg_errors)) |
|
559 | - return $reg_errors; |
|
578 | + if (!empty($reg_errors)) { |
|
579 | + return $reg_errors; |
|
580 | + } |
|
560 | 581 | |
561 | 582 | $reservedVars = array( |
562 | 583 | 'actual_theme_url', |
@@ -578,8 +599,9 @@ discard block |
||
578 | 599 | ); |
579 | 600 | |
580 | 601 | // Can't change reserved vars. |
581 | - if (isset($regOptions['theme_vars']) && count(array_intersect(array_keys($regOptions['theme_vars']), $reservedVars)) != 0) |
|
582 | - fatal_lang_error('no_theme'); |
|
602 | + if (isset($regOptions['theme_vars']) && count(array_intersect(array_keys($regOptions['theme_vars']), $reservedVars)) != 0) { |
|
603 | + fatal_lang_error('no_theme'); |
|
604 | + } |
|
583 | 605 | |
584 | 606 | // Some of these might be overwritten. (the lower ones that are in the arrays below.) |
585 | 607 | $regOptions['register_vars'] = array( |
@@ -621,14 +643,17 @@ discard block |
||
621 | 643 | $regOptions['register_vars']['validation_code'] = ''; |
622 | 644 | } |
623 | 645 | // Maybe it can be activated right away? |
624 | - elseif ($regOptions['require'] == 'nothing') |
|
625 | - $regOptions['register_vars']['is_activated'] = 1; |
|
646 | + elseif ($regOptions['require'] == 'nothing') { |
|
647 | + $regOptions['register_vars']['is_activated'] = 1; |
|
648 | + } |
|
626 | 649 | // Maybe it must be activated by email? |
627 | - elseif ($regOptions['require'] == 'activation') |
|
628 | - $regOptions['register_vars']['is_activated'] = 0; |
|
650 | + elseif ($regOptions['require'] == 'activation') { |
|
651 | + $regOptions['register_vars']['is_activated'] = 0; |
|
652 | + } |
|
629 | 653 | // Otherwise it must be awaiting approval! |
630 | - else |
|
631 | - $regOptions['register_vars']['is_activated'] = 3; |
|
654 | + else { |
|
655 | + $regOptions['register_vars']['is_activated'] = 3; |
|
656 | + } |
|
632 | 657 | |
633 | 658 | if (isset($regOptions['memberGroup'])) |
634 | 659 | { |
@@ -647,24 +672,28 @@ discard block |
||
647 | 672 | 'is_protected' => 1, |
648 | 673 | ) |
649 | 674 | ); |
650 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
651 | - $unassignableGroups[] = $row['id_group']; |
|
675 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
676 | + $unassignableGroups[] = $row['id_group']; |
|
677 | + } |
|
652 | 678 | $smcFunc['db_free_result']($request); |
653 | 679 | |
654 | - if (in_array($regOptions['register_vars']['id_group'], $unassignableGroups)) |
|
655 | - $regOptions['register_vars']['id_group'] = 0; |
|
680 | + if (in_array($regOptions['register_vars']['id_group'], $unassignableGroups)) { |
|
681 | + $regOptions['register_vars']['id_group'] = 0; |
|
682 | + } |
|
656 | 683 | } |
657 | 684 | |
658 | 685 | // Integrate optional member settings to be set. |
659 | - if (!empty($regOptions['extra_register_vars'])) |
|
660 | - foreach ($regOptions['extra_register_vars'] as $var => $value) |
|
686 | + if (!empty($regOptions['extra_register_vars'])) { |
|
687 | + foreach ($regOptions['extra_register_vars'] as $var => $value) |
|
661 | 688 | $regOptions['register_vars'][$var] = $value; |
689 | + } |
|
662 | 690 | |
663 | 691 | // Integrate optional user theme options to be set. |
664 | 692 | $theme_vars = array(); |
665 | - if (!empty($regOptions['theme_vars'])) |
|
666 | - foreach ($regOptions['theme_vars'] as $var => $value) |
|
693 | + if (!empty($regOptions['theme_vars'])) { |
|
694 | + foreach ($regOptions['theme_vars'] as $var => $value) |
|
667 | 695 | $theme_vars[$var] = $value; |
696 | + } |
|
668 | 697 | |
669 | 698 | // Right, now let's prepare for insertion. |
670 | 699 | $knownInts = array( |
@@ -687,14 +716,15 @@ discard block |
||
687 | 716 | foreach ($regOptions['register_vars'] as $var => $val) |
688 | 717 | { |
689 | 718 | $type = 'string'; |
690 | - if (in_array($var, $knownInts)) |
|
691 | - $type = 'int'; |
|
692 | - elseif (in_array($var, $knownFloats)) |
|
693 | - $type = 'float'; |
|
694 | - elseif (in_array($var, $knownInets)) |
|
695 | - $type = 'inet'; |
|
696 | - elseif ($var == 'birthdate') |
|
697 | - $type = 'date'; |
|
719 | + if (in_array($var, $knownInts)) { |
|
720 | + $type = 'int'; |
|
721 | + } elseif (in_array($var, $knownFloats)) { |
|
722 | + $type = 'float'; |
|
723 | + } elseif (in_array($var, $knownInets)) { |
|
724 | + $type = 'inet'; |
|
725 | + } elseif ($var == 'birthdate') { |
|
726 | + $type = 'date'; |
|
727 | + } |
|
698 | 728 | |
699 | 729 | $column_names[$var] = $type; |
700 | 730 | $values[$var] = $val; |
@@ -713,17 +743,19 @@ discard block |
||
713 | 743 | call_integration_hook('integrate_post_register', array(&$regOptions, &$theme_vars, &$memberID)); |
714 | 744 | |
715 | 745 | // Update the number of members and latest member's info - and pass the name, but remove the 's. |
716 | - if ($regOptions['register_vars']['is_activated'] == 1) |
|
717 | - updateStats('member', $memberID, $regOptions['register_vars']['real_name']); |
|
718 | - else |
|
719 | - updateStats('member'); |
|
746 | + if ($regOptions['register_vars']['is_activated'] == 1) { |
|
747 | + updateStats('member', $memberID, $regOptions['register_vars']['real_name']); |
|
748 | + } else { |
|
749 | + updateStats('member'); |
|
750 | + } |
|
720 | 751 | |
721 | 752 | // Theme variables too? |
722 | 753 | if (!empty($theme_vars)) |
723 | 754 | { |
724 | 755 | $inserts = array(); |
725 | - foreach ($theme_vars as $var => $val) |
|
726 | - $inserts[] = array($memberID, $var, $val); |
|
756 | + foreach ($theme_vars as $var => $val) { |
|
757 | + $inserts[] = array($memberID, $var, $val); |
|
758 | + } |
|
727 | 759 | $smcFunc['db_insert']('insert', |
728 | 760 | '{db_prefix}themes', |
729 | 761 | array('id_member' => 'int', 'variable' => 'string-255', 'value' => 'string-65534'), |
@@ -738,10 +770,11 @@ discard block |
||
738 | 770 | // Administrative registrations are a bit different... |
739 | 771 | if ($regOptions['interface'] == 'admin') |
740 | 772 | { |
741 | - if ($regOptions['require'] == 'activation') |
|
742 | - $email_message = 'admin_register_activate'; |
|
743 | - elseif (!empty($regOptions['send_welcome_email'])) |
|
744 | - $email_message = 'admin_register_immediate'; |
|
773 | + if ($regOptions['require'] == 'activation') { |
|
774 | + $email_message = 'admin_register_activate'; |
|
775 | + } elseif (!empty($regOptions['send_welcome_email'])) { |
|
776 | + $email_message = 'admin_register_immediate'; |
|
777 | + } |
|
745 | 778 | |
746 | 779 | if (isset($email_message)) |
747 | 780 | { |
@@ -792,16 +825,17 @@ discard block |
||
792 | 825 | 'FORGOTPASSWORDLINK' => $scripturl . '?action=reminder', |
793 | 826 | ); |
794 | 827 | |
795 | - if ($regOptions['require'] == 'activation') |
|
796 | - $replacements += array( |
|
828 | + if ($regOptions['require'] == 'activation') { |
|
829 | + $replacements += array( |
|
797 | 830 | 'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $memberID . ';code=' . $validation_code, |
798 | 831 | 'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $memberID, |
799 | 832 | 'ACTIVATIONCODE' => $validation_code, |
800 | 833 | ); |
801 | - else |
|
802 | - $replacements += array( |
|
834 | + } else { |
|
835 | + $replacements += array( |
|
803 | 836 | 'COPPALINK' => $scripturl . '?action=coppa;u=' . $memberID, |
804 | 837 | ); |
838 | + } |
|
805 | 839 | |
806 | 840 | $emaildata = loadEmailTemplate('register_' . ($regOptions['require'] == 'activation' ? 'activate' : 'coppa'), $replacements); |
807 | 841 | |
@@ -866,39 +900,45 @@ discard block |
||
866 | 900 | // Check each name in the list... |
867 | 901 | foreach ($reservedNames as $reserved) |
868 | 902 | { |
869 | - if ($reserved == '') |
|
870 | - continue; |
|
903 | + if ($reserved == '') { |
|
904 | + continue; |
|
905 | + } |
|
871 | 906 | |
872 | 907 | // The admin might've used entities too, level the playing field. |
873 | 908 | $reservedCheck = preg_replace('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'replaceEntities__callback', $reserved); |
874 | 909 | |
875 | 910 | // Case sensitive name? |
876 | - if (empty($modSettings['reserveCase'])) |
|
877 | - $reservedCheck = $smcFunc['strtolower']($reservedCheck); |
|
911 | + if (empty($modSettings['reserveCase'])) { |
|
912 | + $reservedCheck = $smcFunc['strtolower']($reservedCheck); |
|
913 | + } |
|
878 | 914 | |
879 | 915 | // If it's not just entire word, check for it in there somewhere... |
880 | - if ($checkMe == $reservedCheck || ($smcFunc['strpos']($checkMe, $reservedCheck) !== false && empty($modSettings['reserveWord']))) |
|
881 | - if ($fatal) |
|
916 | + if ($checkMe == $reservedCheck || ($smcFunc['strpos']($checkMe, $reservedCheck) !== false && empty($modSettings['reserveWord']))) { |
|
917 | + if ($fatal) |
|
882 | 918 | fatal_lang_error('username_reserved', 'password', array($reserved)); |
883 | - else |
|
884 | - return true; |
|
919 | + } else { |
|
920 | + return true; |
|
921 | + } |
|
885 | 922 | } |
886 | 923 | |
887 | 924 | $censor_name = $name; |
888 | - if (censorText($censor_name) != $name) |
|
889 | - if ($fatal) |
|
925 | + if (censorText($censor_name) != $name) { |
|
926 | + if ($fatal) |
|
890 | 927 | fatal_lang_error('name_censored', 'password', array($name)); |
891 | - else |
|
892 | - return true; |
|
928 | + } else { |
|
929 | + return true; |
|
930 | + } |
|
893 | 931 | } |
894 | 932 | |
895 | 933 | // Characters we just shouldn't allow, regardless. |
896 | - foreach (array('*') as $char) |
|
897 | - if (strpos($checkName, $char) !== false) |
|
934 | + foreach (array('*') as $char) { |
|
935 | + if (strpos($checkName, $char) !== false) |
|
898 | 936 | if ($fatal) |
899 | 937 | fatal_lang_error('username_reserved', 'password', array($char)); |
900 | - else |
|
901 | - return true; |
|
938 | + } |
|
939 | + else { |
|
940 | + return true; |
|
941 | + } |
|
902 | 942 | |
903 | 943 | // Get rid of any SQL parts of the reserved name... |
904 | 944 | $checkName = strtr($name, array('_' => '\\_', '%' => '\\%')); |
@@ -980,8 +1020,9 @@ discard block |
||
980 | 1020 | 'permission' => $permission, |
981 | 1021 | ) |
982 | 1022 | ); |
983 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
984 | - $member_groups[$row['add_deny'] === '1' ? 'allowed' : 'denied'][] = $row['id_group']; |
|
1023 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1024 | + $member_groups[$row['add_deny'] === '1' ? 'allowed' : 'denied'][] = $row['id_group']; |
|
1025 | + } |
|
985 | 1026 | $smcFunc['db_free_result']($request); |
986 | 1027 | } |
987 | 1028 | |
@@ -989,9 +1030,9 @@ discard block |
||
989 | 1030 | else |
990 | 1031 | { |
991 | 1032 | // First get the profile of the given board. |
992 | - if (isset($board_info['id']) && $board_info['id'] == $board_id) |
|
993 | - $profile_id = $board_info['profile']; |
|
994 | - elseif ($board_id !== 0) |
|
1033 | + if (isset($board_info['id']) && $board_info['id'] == $board_id) { |
|
1034 | + $profile_id = $board_info['profile']; |
|
1035 | + } elseif ($board_id !== 0) |
|
995 | 1036 | { |
996 | 1037 | $request = $smcFunc['db_query']('', ' |
997 | 1038 | SELECT id_profile |
@@ -1002,13 +1043,14 @@ discard block |
||
1002 | 1043 | 'id_board' => $board_id, |
1003 | 1044 | ) |
1004 | 1045 | ); |
1005 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
1006 | - fatal_lang_error('no_board'); |
|
1046 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1047 | + fatal_lang_error('no_board'); |
|
1048 | + } |
|
1007 | 1049 | list ($profile_id) = $smcFunc['db_fetch_row']($request); |
1008 | 1050 | $smcFunc['db_free_result']($request); |
1051 | + } else { |
|
1052 | + $profile_id = 1; |
|
1009 | 1053 | } |
1010 | - else |
|
1011 | - $profile_id = 1; |
|
1012 | 1054 | |
1013 | 1055 | $request = $smcFunc['db_query']('', ' |
1014 | 1056 | SELECT bp.id_group, bp.add_deny |
@@ -1020,8 +1062,9 @@ discard block |
||
1020 | 1062 | 'permission' => $permission, |
1021 | 1063 | ) |
1022 | 1064 | ); |
1023 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1024 | - $member_groups[$row['add_deny'] === '1' ? 'allowed' : 'denied'][] = $row['id_group']; |
|
1065 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1066 | + $member_groups[$row['add_deny'] === '1' ? 'allowed' : 'denied'][] = $row['id_group']; |
|
1067 | + } |
|
1025 | 1068 | $smcFunc['db_free_result']($request); |
1026 | 1069 | |
1027 | 1070 | $moderator_groups = array(); |
@@ -1030,8 +1073,7 @@ discard block |
||
1030 | 1073 | if (isset($board_info['moderator_groups'])) |
1031 | 1074 | { |
1032 | 1075 | $moderator_groups = array_keys($board_info['moderator_groups']); |
1033 | - } |
|
1034 | - elseif ($board_id !== 0) |
|
1076 | + } elseif ($board_id !== 0) |
|
1035 | 1077 | { |
1036 | 1078 | // Get the groups that can moderate this board |
1037 | 1079 | $request = $smcFunc['db_query']('', ' |
@@ -1116,8 +1158,9 @@ discard block |
||
1116 | 1158 | ) |
1117 | 1159 | ); |
1118 | 1160 | $members = array(); |
1119 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1120 | - $members[] = $row['id_member']; |
|
1161 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1162 | + $members[] = $row['id_member']; |
|
1163 | + } |
|
1121 | 1164 | $smcFunc['db_free_result']($request); |
1122 | 1165 | |
1123 | 1166 | return $members; |
@@ -1190,10 +1233,12 @@ discard block |
||
1190 | 1233 | } |
1191 | 1234 | |
1192 | 1235 | $query_parts = array(); |
1193 | - if (!empty($email)) |
|
1194 | - $query_parts[] = 'poster_email = {string:email_address}'; |
|
1195 | - if (!empty($membername)) |
|
1196 | - $query_parts[] = 'poster_name = {string:member_name}'; |
|
1236 | + if (!empty($email)) { |
|
1237 | + $query_parts[] = 'poster_email = {string:email_address}'; |
|
1238 | + } |
|
1239 | + if (!empty($membername)) { |
|
1240 | + $query_parts[] = 'poster_name = {string:member_name}'; |
|
1241 | + } |
|
1197 | 1242 | $query = implode(' AND ', $query_parts); |
1198 | 1243 | |
1199 | 1244 | // Finally, update the posts themselves! |
@@ -1260,12 +1305,14 @@ discard block |
||
1260 | 1305 | |
1261 | 1306 | $userReceiver = (int) !empty($_REQUEST['u']) ? $_REQUEST['u'] : 0; |
1262 | 1307 | |
1263 | - if (empty($userReceiver)) |
|
1264 | - fatal_lang_error('no_access', false); |
|
1308 | + if (empty($userReceiver)) { |
|
1309 | + fatal_lang_error('no_access', false); |
|
1310 | + } |
|
1265 | 1311 | |
1266 | 1312 | // Remove if it's already there... |
1267 | - if (in_array($userReceiver, $user_info['buddies'])) |
|
1268 | - $user_info['buddies'] = array_diff($user_info['buddies'], array($userReceiver)); |
|
1313 | + if (in_array($userReceiver, $user_info['buddies'])) { |
|
1314 | + $user_info['buddies'] = array_diff($user_info['buddies'], array($userReceiver)); |
|
1315 | + } |
|
1269 | 1316 | |
1270 | 1317 | // ...or add if it's not and if it's not you. |
1271 | 1318 | elseif ($user_info['id'] != $userReceiver) |
@@ -1340,8 +1387,9 @@ discard block |
||
1340 | 1387 | $smcFunc['db_free_result']($request); |
1341 | 1388 | |
1342 | 1389 | // If we want duplicates pass the members array off. |
1343 | - if ($get_duplicates) |
|
1344 | - populateDuplicateMembers($members); |
|
1390 | + if ($get_duplicates) { |
|
1391 | + populateDuplicateMembers($members); |
|
1392 | + } |
|
1345 | 1393 | |
1346 | 1394 | return $members; |
1347 | 1395 | } |
@@ -1358,8 +1406,9 @@ discard block |
||
1358 | 1406 | global $smcFunc, $modSettings; |
1359 | 1407 | |
1360 | 1408 | // We know how many members there are in total. |
1361 | - if (empty($where) || $where == '1=1') |
|
1362 | - $num_members = $modSettings['totalMembers']; |
|
1409 | + if (empty($where) || $where == '1=1') { |
|
1410 | + $num_members = $modSettings['totalMembers']; |
|
1411 | + } |
|
1363 | 1412 | |
1364 | 1413 | // The database knows the amount when there are extra conditions. |
1365 | 1414 | else |
@@ -1395,16 +1444,19 @@ discard block |
||
1395 | 1444 | $members[$key]['duplicate_members'] = array(); |
1396 | 1445 | |
1397 | 1446 | // Store the IPs. |
1398 | - if (!empty($member['member_ip'])) |
|
1399 | - $ips[] = $member['member_ip']; |
|
1400 | - if (!empty($member['member_ip2'])) |
|
1401 | - $ips[] = $member['member_ip2']; |
|
1447 | + if (!empty($member['member_ip'])) { |
|
1448 | + $ips[] = $member['member_ip']; |
|
1449 | + } |
|
1450 | + if (!empty($member['member_ip2'])) { |
|
1451 | + $ips[] = $member['member_ip2']; |
|
1452 | + } |
|
1402 | 1453 | } |
1403 | 1454 | |
1404 | 1455 | $ips = array_unique($ips); |
1405 | 1456 | |
1406 | - if (empty($ips)) |
|
1407 | - return false; |
|
1457 | + if (empty($ips)) { |
|
1458 | + return false; |
|
1459 | + } |
|
1408 | 1460 | |
1409 | 1461 | // Fetch all members with this IP address, we'll filter out the current ones in a sec. |
1410 | 1462 | $request = $smcFunc['db_query']('', ' |
@@ -1434,10 +1486,12 @@ discard block |
||
1434 | 1486 | 'ip2' => $row['member_ip2'], |
1435 | 1487 | ); |
1436 | 1488 | |
1437 | - if (in_array($row['member_ip'], $ips)) |
|
1438 | - $duplicate_members[$row['member_ip']][] = $member_context; |
|
1439 | - if ($row['member_ip'] != $row['member_ip2'] && in_array($row['member_ip2'], $ips)) |
|
1440 | - $duplicate_members[$row['member_ip2']][] = $member_context; |
|
1489 | + if (in_array($row['member_ip'], $ips)) { |
|
1490 | + $duplicate_members[$row['member_ip']][] = $member_context; |
|
1491 | + } |
|
1492 | + if ($row['member_ip'] != $row['member_ip2'] && in_array($row['member_ip2'], $ips)) { |
|
1493 | + $duplicate_members[$row['member_ip2']][] = $member_context; |
|
1494 | + } |
|
1441 | 1495 | } |
1442 | 1496 | $smcFunc['db_free_result']($request); |
1443 | 1497 | |
@@ -1462,8 +1516,9 @@ discard block |
||
1462 | 1516 | $row['poster_ip'] = inet_dtop($row['poster_ip']); |
1463 | 1517 | |
1464 | 1518 | // Don't collect lots of the same. |
1465 | - if (isset($had_ips[$row['poster_ip']]) && in_array($row['id_member'], $had_ips[$row['poster_ip']])) |
|
1466 | - continue; |
|
1519 | + if (isset($had_ips[$row['poster_ip']]) && in_array($row['id_member'], $had_ips[$row['poster_ip']])) { |
|
1520 | + continue; |
|
1521 | + } |
|
1467 | 1522 | $had_ips[$row['poster_ip']][] = $row['id_member']; |
1468 | 1523 | |
1469 | 1524 | $duplicate_members[$row['poster_ip']][] = array( |
@@ -1478,13 +1533,15 @@ discard block |
||
1478 | 1533 | $smcFunc['db_free_result']($request); |
1479 | 1534 | |
1480 | 1535 | // Now we have all the duplicate members, stick them with their respective member in the list. |
1481 | - if (!empty($duplicate_members)) |
|
1482 | - foreach ($members as $key => $member) |
|
1536 | + if (!empty($duplicate_members)) { |
|
1537 | + foreach ($members as $key => $member) |
|
1483 | 1538 | { |
1484 | 1539 | if (isset($duplicate_members[$member['member_ip']])) |
1485 | 1540 | $members[$key]['duplicate_members'] = $duplicate_members[$member['member_ip']]; |
1486 | - if ($member['member_ip'] != $member['member_ip2'] && isset($duplicate_members[$member['member_ip2']])) |
|
1487 | - $members[$key]['duplicate_members'] = array_merge($member['duplicate_members'], $duplicate_members[$member['member_ip2']]); |
|
1541 | + } |
|
1542 | + if ($member['member_ip'] != $member['member_ip2'] && isset($duplicate_members[$member['member_ip2']])) { |
|
1543 | + $members[$key]['duplicate_members'] = array_merge($member['duplicate_members'], $duplicate_members[$member['member_ip2']]); |
|
1544 | + } |
|
1488 | 1545 | |
1489 | 1546 | // Check we don't have lots of the same member. |
1490 | 1547 | $member_track = array($member['id_member']); |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | |
248 | 248 | saveSettings($config_vars); |
249 | 249 | $_SESSION['adm-save'] = true; |
250 | - redirectexit('action=admin;area=serversettings;sa=database;' . $context['session_var'] . '=' . $context['session_id'] ); |
|
250 | + redirectexit('action=admin;area=serversettings;sa=database;' . $context['session_var'] . '=' . $context['session_id']); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | // Fill the config array. |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | array('localCookies', $txt['localCookies'], 'db', 'check', false, 'localCookies'), |
273 | 273 | array('globalCookies', $txt['globalCookies'], 'db', 'check', false, 'globalCookies'), |
274 | 274 | array('globalCookiesDomain', $txt['globalCookiesDomain'], 'db', 'text', false, 'globalCookiesDomain'), |
275 | - array('secureCookies', $txt['secureCookies'], 'db', 'check', false, 'secureCookies', 'disabled' => !isset($_SERVER['HTTPS']) || !(strtolower($_SERVER['HTTPS']) == 'on' || strtolower($_SERVER['HTTPS']) == '1')), |
|
275 | + array('secureCookies', $txt['secureCookies'], 'db', 'check', false, 'secureCookies', 'disabled' => !isset($_SERVER['HTTPS']) || !(strtolower($_SERVER['HTTPS']) == 'on' || strtolower($_SERVER['HTTPS']) == '1')), |
|
276 | 276 | array('httponlyCookies', $txt['httponlyCookies'], 'db', 'check', false, 'httponlyCookies'), |
277 | 277 | '', |
278 | 278 | // Sessions |
@@ -59,8 +59,9 @@ discard block |
||
59 | 59 | * @version 2.1 Beta 3 |
60 | 60 | */ |
61 | 61 | |
62 | -if (!defined('SMF')) |
|
62 | +if (!defined('SMF')) { |
|
63 | 63 | die('No direct access...'); |
64 | +} |
|
64 | 65 | |
65 | 66 | /** |
66 | 67 | * This is the main dispatcher. Sets up all the available sub-actions, all the tabs and selects |
@@ -111,10 +112,11 @@ discard block |
||
111 | 112 | $settings_not_writable = !is_writable($boarddir . '/Settings.php'); |
112 | 113 | $settings_backup_fail = !@is_writable($boarddir . '/Settings_bak.php') || !@copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php'); |
113 | 114 | |
114 | - if ($settings_not_writable) |
|
115 | - $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>'; |
|
116 | - elseif ($settings_backup_fail) |
|
117 | - $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>'; |
|
115 | + if ($settings_not_writable) { |
|
116 | + $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>'; |
|
117 | + } elseif ($settings_backup_fail) { |
|
118 | + $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>'; |
|
119 | + } |
|
118 | 120 | |
119 | 121 | $context['settings_not_writable'] = $settings_not_writable; |
120 | 122 | |
@@ -166,8 +168,9 @@ discard block |
||
166 | 168 | |
167 | 169 | call_integration_hook('integrate_general_settings', array(&$config_vars)); |
168 | 170 | |
169 | - if ($return_config) |
|
170 | - return $config_vars; |
|
171 | + if ($return_config) { |
|
172 | + return $config_vars; |
|
173 | + } |
|
171 | 174 | |
172 | 175 | // Setup the template stuff. |
173 | 176 | $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=general;save'; |
@@ -232,8 +235,9 @@ discard block |
||
232 | 235 | |
233 | 236 | call_integration_hook('integrate_database_settings', array(&$config_vars)); |
234 | 237 | |
235 | - if ($return_config) |
|
236 | - return $config_vars; |
|
238 | + if ($return_config) { |
|
239 | + return $config_vars; |
|
240 | + } |
|
237 | 241 | |
238 | 242 | // Setup the template stuff. |
239 | 243 | $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=database;save'; |
@@ -308,13 +312,15 @@ discard block |
||
308 | 312 | hideGlobalCookies(); |
309 | 313 | });', true); |
310 | 314 | |
311 | - if (empty($user_settings['tfa_secret'])) |
|
312 | - addInlineJavaScript(''); |
|
315 | + if (empty($user_settings['tfa_secret'])) { |
|
316 | + addInlineJavaScript(''); |
|
317 | + } |
|
313 | 318 | |
314 | 319 | call_integration_hook('integrate_cookie_settings', array(&$config_vars)); |
315 | 320 | |
316 | - if ($return_config) |
|
317 | - return $config_vars; |
|
321 | + if ($return_config) { |
|
322 | + return $config_vars; |
|
323 | + } |
|
318 | 324 | |
319 | 325 | $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=cookie;save'; |
320 | 326 | $context['settings_title'] = $txt['cookies_sessions_settings']; |
@@ -325,11 +331,13 @@ discard block |
||
325 | 331 | call_integration_hook('integrate_save_cookie_settings'); |
326 | 332 | |
327 | 333 | // Local and global do not play nicely together. |
328 | - if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) |
|
329 | - unset ($_POST['globalCookies']); |
|
334 | + if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) { |
|
335 | + unset ($_POST['globalCookies']); |
|
336 | + } |
|
330 | 337 | |
331 | - if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) |
|
332 | - fatal_lang_error('invalid_cookie_domain', false); |
|
338 | + if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) { |
|
339 | + fatal_lang_error('invalid_cookie_domain', false); |
|
340 | + } |
|
333 | 341 | |
334 | 342 | saveSettings($config_vars); |
335 | 343 | |
@@ -412,8 +420,9 @@ discard block |
||
412 | 420 | |
413 | 421 | call_integration_hook('integrate_general_security_settings', array(&$config_vars)); |
414 | 422 | |
415 | - if ($return_config) |
|
416 | - return $config_vars; |
|
423 | + if ($return_config) { |
|
424 | + return $config_vars; |
|
425 | + } |
|
417 | 426 | |
418 | 427 | // Saving? |
419 | 428 | if (isset($_GET['save'])) |
@@ -452,8 +461,7 @@ discard block |
||
452 | 461 | $txt['cache_settings_message'] = $txt['detected_no_caching']; |
453 | 462 | $cache_level = array($txt['cache_off']); |
454 | 463 | $detected['none'] = $txt['cache_off']; |
455 | - } |
|
456 | - else |
|
464 | + } else |
|
457 | 465 | { |
458 | 466 | $txt['cache_settings_message'] = sprintf($txt['detected_accelerators'], implode(', ', $detected)); |
459 | 467 | $cache_level = array($txt['cache_off'], $txt['cache_level1'], $txt['cache_level2'], $txt['cache_level3']); |
@@ -490,8 +498,9 @@ discard block |
||
490 | 498 | } |
491 | 499 | } |
492 | 500 | } |
493 | - if ($return_config) |
|
494 | - return $config_vars; |
|
501 | + if ($return_config) { |
|
502 | + return $config_vars; |
|
503 | + } |
|
495 | 504 | |
496 | 505 | // Saving again? |
497 | 506 | if (isset($_GET['save'])) |
@@ -519,8 +528,9 @@ discard block |
||
519 | 528 | $context['save_disabled'] = $context['settings_not_writable']; |
520 | 529 | |
521 | 530 | // Decide what message to show. |
522 | - if (!$context['save_disabled']) |
|
523 | - $context['settings_message'] = $txt['caching_information']; |
|
531 | + if (!$context['save_disabled']) { |
|
532 | + $context['settings_message'] = $txt['caching_information']; |
|
533 | + } |
|
524 | 534 | |
525 | 535 | // Prepare the template. |
526 | 536 | prepareServerSettingsContext($config_vars); |
@@ -543,24 +553,25 @@ discard block |
||
543 | 553 | if (stripos(PHP_OS, 'win') === 0) |
544 | 554 | { |
545 | 555 | $context['settings_message'] = $txt['loadavg_disabled_windows']; |
546 | - if (isset($_GET['save'])) |
|
547 | - $_SESSION['adm-save'] = $txt['loadavg_disabled_windows']; |
|
548 | - } |
|
549 | - elseif (stripos(PHP_OS, 'darwin') === 0) |
|
556 | + if (isset($_GET['save'])) { |
|
557 | + $_SESSION['adm-save'] = $txt['loadavg_disabled_windows']; |
|
558 | + } |
|
559 | + } elseif (stripos(PHP_OS, 'darwin') === 0) |
|
550 | 560 | { |
551 | 561 | $context['settings_message'] = $txt['loadavg_disabled_osx']; |
552 | - if (isset($_GET['save'])) |
|
553 | - $_SESSION['adm-save'] = $txt['loadavg_disabled_osx']; |
|
554 | - } |
|
555 | - else |
|
562 | + if (isset($_GET['save'])) { |
|
563 | + $_SESSION['adm-save'] = $txt['loadavg_disabled_osx']; |
|
564 | + } |
|
565 | + } else |
|
556 | 566 | { |
557 | 567 | $modSettings['load_average'] = @file_get_contents('/proc/loadavg'); |
558 | - if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) |
|
559 | - $modSettings['load_average'] = (float) $matches[1]; |
|
560 | - elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) |
|
561 | - $modSettings['load_average'] = (float) $matches[1]; |
|
562 | - else |
|
563 | - unset($modSettings['load_average']); |
|
568 | + if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) { |
|
569 | + $modSettings['load_average'] = (float) $matches[1]; |
|
570 | + } elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) { |
|
571 | + $modSettings['load_average'] = (float) $matches[1]; |
|
572 | + } else { |
|
573 | + unset($modSettings['load_average']); |
|
574 | + } |
|
564 | 575 | |
565 | 576 | if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
566 | 577 | { |
@@ -596,8 +607,9 @@ discard block |
||
596 | 607 | |
597 | 608 | call_integration_hook('integrate_loadavg_settings', array(&$config_vars)); |
598 | 609 | |
599 | - if ($return_config) |
|
600 | - return $config_vars; |
|
610 | + if ($return_config) { |
|
611 | + return $config_vars; |
|
612 | + } |
|
601 | 613 | |
602 | 614 | $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=loads;save'; |
603 | 615 | $context['settings_title'] = $txt['load_balancing_settings']; |
@@ -608,24 +620,27 @@ discard block |
||
608 | 620 | // Stupidity is not allowed. |
609 | 621 | foreach ($_POST as $key => $value) |
610 | 622 | { |
611 | - if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) |
|
612 | - continue; |
|
613 | - else |
|
614 | - $_POST[$key] = (float) $value; |
|
615 | - |
|
616 | - if ($key == 'loadavg_auto_opt' && $value <= 1) |
|
617 | - $_POST['loadavg_auto_opt'] = 1.0; |
|
618 | - elseif ($key == 'loadavg_forum' && $value < 10) |
|
619 | - $_POST['loadavg_forum'] = 10.0; |
|
620 | - elseif ($value < 2) |
|
621 | - $_POST[$key] = 2.0; |
|
623 | + if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) { |
|
624 | + continue; |
|
625 | + } else { |
|
626 | + $_POST[$key] = (float) $value; |
|
627 | + } |
|
628 | + |
|
629 | + if ($key == 'loadavg_auto_opt' && $value <= 1) { |
|
630 | + $_POST['loadavg_auto_opt'] = 1.0; |
|
631 | + } elseif ($key == 'loadavg_forum' && $value < 10) { |
|
632 | + $_POST['loadavg_forum'] = 10.0; |
|
633 | + } elseif ($value < 2) { |
|
634 | + $_POST[$key] = 2.0; |
|
635 | + } |
|
622 | 636 | } |
623 | 637 | |
624 | 638 | call_integration_hook('integrate_save_loadavg_settings'); |
625 | 639 | |
626 | 640 | saveDBSettings($config_vars); |
627 | - if (!isset($_SESSION['adm-save'])) |
|
628 | - $_SESSION['adm-save'] = true; |
|
641 | + if (!isset($_SESSION['adm-save'])) { |
|
642 | + $_SESSION['adm-save'] = true; |
|
643 | + } |
|
629 | 644 | redirectexit('action=admin;area=serversettings;sa=loads;' . $context['session_var'] . '=' . $context['session_id']); |
630 | 645 | } |
631 | 646 | |
@@ -661,10 +676,11 @@ discard block |
||
661 | 676 | |
662 | 677 | if (isset($_SESSION['adm-save'])) |
663 | 678 | { |
664 | - if ($_SESSION['adm-save'] === true) |
|
665 | - $context['saved_successful'] = true; |
|
666 | - else |
|
667 | - $context['saved_failed'] = $_SESSION['adm-save']; |
|
679 | + if ($_SESSION['adm-save'] === true) { |
|
680 | + $context['saved_successful'] = true; |
|
681 | + } else { |
|
682 | + $context['saved_failed'] = $_SESSION['adm-save']; |
|
683 | + } |
|
668 | 684 | |
669 | 685 | unset($_SESSION['adm-save']); |
670 | 686 | } |
@@ -672,9 +688,9 @@ discard block |
||
672 | 688 | $context['config_vars'] = array(); |
673 | 689 | foreach ($config_vars as $identifier => $config_var) |
674 | 690 | { |
675 | - if (!is_array($config_var) || !isset($config_var[1])) |
|
676 | - $context['config_vars'][] = $config_var; |
|
677 | - else |
|
691 | + if (!is_array($config_var) || !isset($config_var[1])) { |
|
692 | + $context['config_vars'][] = $config_var; |
|
693 | + } else |
|
678 | 694 | { |
679 | 695 | $varname = $config_var[0]; |
680 | 696 | global $$varname; |
@@ -709,16 +725,19 @@ discard block |
||
709 | 725 | if ($config_var[3] == 'int' || $config_var[3] == 'float') |
710 | 726 | { |
711 | 727 | // Default to a min of 0 if one isn't set |
712 | - if (isset($config_var['min'])) |
|
713 | - $context['config_vars'][$config_var[0]]['min'] = $config_var['min']; |
|
714 | - else |
|
715 | - $context['config_vars'][$config_var[0]]['min'] = 0; |
|
728 | + if (isset($config_var['min'])) { |
|
729 | + $context['config_vars'][$config_var[0]]['min'] = $config_var['min']; |
|
730 | + } else { |
|
731 | + $context['config_vars'][$config_var[0]]['min'] = 0; |
|
732 | + } |
|
716 | 733 | |
717 | - if (isset($config_var['max'])) |
|
718 | - $context['config_vars'][$config_var[0]]['max'] = $config_var['max']; |
|
734 | + if (isset($config_var['max'])) { |
|
735 | + $context['config_vars'][$config_var[0]]['max'] = $config_var['max']; |
|
736 | + } |
|
719 | 737 | |
720 | - if (isset($config_var['step'])) |
|
721 | - $context['config_vars'][$config_var[0]]['step'] = $config_var['step']; |
|
738 | + if (isset($config_var['step'])) { |
|
739 | + $context['config_vars'][$config_var[0]]['step'] = $config_var['step']; |
|
740 | + } |
|
722 | 741 | } |
723 | 742 | |
724 | 743 | // If this is a select box handle any data. |
@@ -726,12 +745,13 @@ discard block |
||
726 | 745 | { |
727 | 746 | // If it's associative |
728 | 747 | $config_values = array_values($config_var[4]); |
729 | - if (isset($config_values[0]) && is_array($config_values[0])) |
|
730 | - $context['config_vars'][$config_var[0]]['data'] = $config_var[4]; |
|
731 | - else |
|
748 | + if (isset($config_values[0]) && is_array($config_values[0])) { |
|
749 | + $context['config_vars'][$config_var[0]]['data'] = $config_var[4]; |
|
750 | + } else |
|
732 | 751 | { |
733 | - foreach ($config_var[4] as $key => $item) |
|
734 | - $context['config_vars'][$config_var[0]]['data'][] = array($key, $item); |
|
752 | + foreach ($config_var[4] as $key => $item) { |
|
753 | + $context['config_vars'][$config_var[0]]['data'][] = array($key, $item); |
|
754 | + } |
|
735 | 755 | } |
736 | 756 | } |
737 | 757 | } |
@@ -756,10 +776,11 @@ discard block |
||
756 | 776 | |
757 | 777 | if (isset($_SESSION['adm-save'])) |
758 | 778 | { |
759 | - if ($_SESSION['adm-save'] === true) |
|
760 | - $context['saved_successful'] = true; |
|
761 | - else |
|
762 | - $context['saved_failed'] = $_SESSION['adm-save']; |
|
779 | + if ($_SESSION['adm-save'] === true) { |
|
780 | + $context['saved_successful'] = true; |
|
781 | + } else { |
|
782 | + $context['saved_failed'] = $_SESSION['adm-save']; |
|
783 | + } |
|
763 | 784 | |
764 | 785 | unset($_SESSION['adm-save']); |
765 | 786 | } |
@@ -771,26 +792,30 @@ discard block |
||
771 | 792 | foreach ($config_vars as $config_var) |
772 | 793 | { |
773 | 794 | // HR? |
774 | - if (!is_array($config_var)) |
|
775 | - $context['config_vars'][] = $config_var; |
|
776 | - else |
|
795 | + if (!is_array($config_var)) { |
|
796 | + $context['config_vars'][] = $config_var; |
|
797 | + } else |
|
777 | 798 | { |
778 | 799 | // If it has no name it doesn't have any purpose! |
779 | - if (empty($config_var[1])) |
|
780 | - continue; |
|
800 | + if (empty($config_var[1])) { |
|
801 | + continue; |
|
802 | + } |
|
781 | 803 | |
782 | 804 | // Special case for inline permissions |
783 | - if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) |
|
784 | - $inlinePermissions[] = $config_var[1]; |
|
785 | - elseif ($config_var[0] == 'permissions') |
|
786 | - continue; |
|
805 | + if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) { |
|
806 | + $inlinePermissions[] = $config_var[1]; |
|
807 | + } elseif ($config_var[0] == 'permissions') { |
|
808 | + continue; |
|
809 | + } |
|
787 | 810 | |
788 | - if ($config_var[0] == 'boards') |
|
789 | - $board_list = true; |
|
811 | + if ($config_var[0] == 'boards') { |
|
812 | + $board_list = true; |
|
813 | + } |
|
790 | 814 | |
791 | 815 | // Are we showing the BBC selection box? |
792 | - if ($config_var[0] == 'bbc') |
|
793 | - $bbcChoice[] = $config_var[1]; |
|
816 | + if ($config_var[0] == 'bbc') { |
|
817 | + $bbcChoice[] = $config_var[1]; |
|
818 | + } |
|
794 | 819 | |
795 | 820 | // We need to do some parsing of the value before we pass it in. |
796 | 821 | if (isset($modSettings[$config_var[1]])) |
@@ -809,8 +834,7 @@ discard block |
||
809 | 834 | default: |
810 | 835 | $value = $smcFunc['htmlspecialchars']($modSettings[$config_var[1]]); |
811 | 836 | } |
812 | - } |
|
813 | - else |
|
837 | + } else |
|
814 | 838 | { |
815 | 839 | // Darn, it's empty. What type is expected? |
816 | 840 | switch ($config_var[0]) |
@@ -850,16 +874,19 @@ discard block |
||
850 | 874 | if ($config_var[0] == 'int' || $config_var[0] == 'float') |
851 | 875 | { |
852 | 876 | // Default to a min of 0 if one isn't set |
853 | - if (isset($config_var['min'])) |
|
854 | - $context['config_vars'][$config_var[1]]['min'] = $config_var['min']; |
|
855 | - else |
|
856 | - $context['config_vars'][$config_var[1]]['min'] = 0; |
|
877 | + if (isset($config_var['min'])) { |
|
878 | + $context['config_vars'][$config_var[1]]['min'] = $config_var['min']; |
|
879 | + } else { |
|
880 | + $context['config_vars'][$config_var[1]]['min'] = 0; |
|
881 | + } |
|
857 | 882 | |
858 | - if (isset($config_var['max'])) |
|
859 | - $context['config_vars'][$config_var[1]]['max'] = $config_var['max']; |
|
883 | + if (isset($config_var['max'])) { |
|
884 | + $context['config_vars'][$config_var[1]]['max'] = $config_var['max']; |
|
885 | + } |
|
860 | 886 | |
861 | - if (isset($config_var['step'])) |
|
862 | - $context['config_vars'][$config_var[1]]['step'] = $config_var['step']; |
|
887 | + if (isset($config_var['step'])) { |
|
888 | + $context['config_vars'][$config_var[1]]['step'] = $config_var['step']; |
|
889 | + } |
|
863 | 890 | } |
864 | 891 | |
865 | 892 | // If this is a select box handle any data. |
@@ -873,12 +900,13 @@ discard block |
||
873 | 900 | } |
874 | 901 | |
875 | 902 | // If it's associative |
876 | - if (isset($config_var[2][0]) && is_array($config_var[2][0])) |
|
877 | - $context['config_vars'][$config_var[1]]['data'] = $config_var[2]; |
|
878 | - else |
|
903 | + if (isset($config_var[2][0]) && is_array($config_var[2][0])) { |
|
904 | + $context['config_vars'][$config_var[1]]['data'] = $config_var[2]; |
|
905 | + } else |
|
879 | 906 | { |
880 | - foreach ($config_var[2] as $key => $item) |
|
881 | - $context['config_vars'][$config_var[1]]['data'][] = array($key, $item); |
|
907 | + foreach ($config_var[2] as $key => $item) { |
|
908 | + $context['config_vars'][$config_var[1]]['data'][] = array($key, $item); |
|
909 | + } |
|
882 | 910 | } |
883 | 911 | } |
884 | 912 | |
@@ -887,17 +915,19 @@ discard block |
||
887 | 915 | { |
888 | 916 | if (!is_numeric($k)) |
889 | 917 | { |
890 | - if (substr($k, 0, 2) == 'on') |
|
891 | - $context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"'; |
|
892 | - else |
|
893 | - $context['config_vars'][$config_var[1]][$k] = $v; |
|
918 | + if (substr($k, 0, 2) == 'on') { |
|
919 | + $context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"'; |
|
920 | + } else { |
|
921 | + $context['config_vars'][$config_var[1]][$k] = $v; |
|
922 | + } |
|
894 | 923 | } |
895 | 924 | |
896 | 925 | // See if there are any other labels that might fit? |
897 | - if (isset($txt['setting_' . $config_var[1]])) |
|
898 | - $context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]]; |
|
899 | - elseif (isset($txt['groups_' . $config_var[1]])) |
|
900 | - $context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]]; |
|
926 | + if (isset($txt['setting_' . $config_var[1]])) { |
|
927 | + $context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]]; |
|
928 | + } elseif (isset($txt['groups_' . $config_var[1]])) { |
|
929 | + $context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]]; |
|
930 | + } |
|
901 | 931 | } |
902 | 932 | |
903 | 933 | // Set the subtext in case it's part of the label. |
@@ -930,8 +960,9 @@ discard block |
||
930 | 960 | // What are the options, eh? |
931 | 961 | $temp = parse_bbc(false); |
932 | 962 | $bbcTags = array(); |
933 | - foreach ($temp as $tag) |
|
934 | - $bbcTags[] = $tag['tag']; |
|
963 | + foreach ($temp as $tag) { |
|
964 | + $bbcTags[] = $tag['tag']; |
|
965 | + } |
|
935 | 966 | |
936 | 967 | $bbcTags = array_unique($bbcTags); |
937 | 968 | $totalTags = count($bbcTags); |
@@ -946,8 +977,9 @@ discard block |
||
946 | 977 | $col = 0; $i = 0; |
947 | 978 | foreach ($bbcTags as $tag) |
948 | 979 | { |
949 | - if ($i % $tagsPerColumn == 0 && $i != 0) |
|
950 | - $col++; |
|
980 | + if ($i % $tagsPerColumn == 0 && $i != 0) { |
|
981 | + $col++; |
|
982 | + } |
|
951 | 983 | |
952 | 984 | $context['bbc_columns'][$col][] = array( |
953 | 985 | 'tag' => $tag, |
@@ -990,18 +1022,21 @@ discard block |
||
990 | 1022 | validateToken('admin-ssc'); |
991 | 1023 | |
992 | 1024 | // Fix the darn stupid cookiename! (more may not be allowed, but these for sure!) |
993 | - if (isset($_POST['cookiename'])) |
|
994 | - $_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']); |
|
1025 | + if (isset($_POST['cookiename'])) { |
|
1026 | + $_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']); |
|
1027 | + } |
|
995 | 1028 | |
996 | 1029 | // Fix the forum's URL if necessary. |
997 | 1030 | if (isset($_POST['boardurl'])) |
998 | 1031 | { |
999 | - if (substr($_POST['boardurl'], -10) == '/index.php') |
|
1000 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
1001 | - elseif (substr($_POST['boardurl'], -1) == '/') |
|
1002 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
1003 | - if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') |
|
1004 | - $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
1032 | + if (substr($_POST['boardurl'], -10) == '/index.php') { |
|
1033 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
1034 | + } elseif (substr($_POST['boardurl'], -1) == '/') { |
|
1035 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
1036 | + } |
|
1037 | + if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') { |
|
1038 | + $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
1039 | + } |
|
1005 | 1040 | } |
1006 | 1041 | |
1007 | 1042 | // Any passwords? |
@@ -1036,21 +1071,21 @@ discard block |
||
1036 | 1071 | // Figure out which config vars we're saving here... |
1037 | 1072 | foreach ($config_vars as $var) |
1038 | 1073 | { |
1039 | - if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) |
|
1040 | - continue; |
|
1074 | + if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) { |
|
1075 | + continue; |
|
1076 | + } |
|
1041 | 1077 | |
1042 | 1078 | $config_var = $var[0]; |
1043 | 1079 | |
1044 | 1080 | if (in_array($config_var, $config_passwords)) |
1045 | 1081 | { |
1046 | - if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) |
|
1047 | - $new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\''; |
|
1048 | - } |
|
1049 | - elseif (in_array($config_var, $config_strs)) |
|
1082 | + if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) { |
|
1083 | + $new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\''; |
|
1084 | + } |
|
1085 | + } elseif (in_array($config_var, $config_strs)) |
|
1050 | 1086 | { |
1051 | 1087 | $new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var], '\'\\') . '\''; |
1052 | - } |
|
1053 | - elseif (in_array($config_var, $config_ints)) |
|
1088 | + } elseif (in_array($config_var, $config_ints)) |
|
1054 | 1089 | { |
1055 | 1090 | $new_settings[$config_var] = (int) $_POST[$config_var]; |
1056 | 1091 | |
@@ -1059,17 +1094,17 @@ discard block |
||
1059 | 1094 | $new_settings[$config_var] = max($min, $new_settings[$config_var]); |
1060 | 1095 | |
1061 | 1096 | // Is there a max value for this as well? |
1062 | - if (isset($var['max'])) |
|
1063 | - $new_settings[$config_var] = min($var['max'], $new_settings[$config_var]); |
|
1064 | - } |
|
1065 | - elseif (in_array($config_var, $config_bools)) |
|
1097 | + if (isset($var['max'])) { |
|
1098 | + $new_settings[$config_var] = min($var['max'], $new_settings[$config_var]); |
|
1099 | + } |
|
1100 | + } elseif (in_array($config_var, $config_bools)) |
|
1066 | 1101 | { |
1067 | - if (!empty($_POST[$config_var])) |
|
1068 | - $new_settings[$config_var] = '1'; |
|
1069 | - else |
|
1070 | - $new_settings[$config_var] = '0'; |
|
1071 | - } |
|
1072 | - else |
|
1102 | + if (!empty($_POST[$config_var])) { |
|
1103 | + $new_settings[$config_var] = '1'; |
|
1104 | + } else { |
|
1105 | + $new_settings[$config_var] = '0'; |
|
1106 | + } |
|
1107 | + } else |
|
1073 | 1108 | { |
1074 | 1109 | // This shouldn't happen, but it might... |
1075 | 1110 | fatal_error('Unknown config_var \'' . $config_var . '\''); |
@@ -1085,30 +1120,35 @@ discard block |
||
1085 | 1120 | foreach ($config_vars as $config_var) |
1086 | 1121 | { |
1087 | 1122 | // We just saved the file-based settings, so skip their definitions. |
1088 | - if (!is_array($config_var) || $config_var[2] == 'file') |
|
1089 | - continue; |
|
1123 | + if (!is_array($config_var) || $config_var[2] == 'file') { |
|
1124 | + continue; |
|
1125 | + } |
|
1090 | 1126 | |
1091 | 1127 | $new_setting = array($config_var[3], $config_var[0]); |
1092 | 1128 | |
1093 | 1129 | // Select options need carried over, too. |
1094 | - if (isset($config_var[4])) |
|
1095 | - $new_setting[] = $config_var[4]; |
|
1130 | + if (isset($config_var[4])) { |
|
1131 | + $new_setting[] = $config_var[4]; |
|
1132 | + } |
|
1096 | 1133 | |
1097 | 1134 | // Include min and max if necessary |
1098 | - if (isset($config_var['min'])) |
|
1099 | - $new_setting['min'] = $config_var['min']; |
|
1135 | + if (isset($config_var['min'])) { |
|
1136 | + $new_setting['min'] = $config_var['min']; |
|
1137 | + } |
|
1100 | 1138 | |
1101 | - if (isset($config_var['max'])) |
|
1102 | - $new_setting['max'] = $config_var['max']; |
|
1139 | + if (isset($config_var['max'])) { |
|
1140 | + $new_setting['max'] = $config_var['max']; |
|
1141 | + } |
|
1103 | 1142 | |
1104 | 1143 | // Rewrite the definition a bit. |
1105 | 1144 | $new_settings[] = $new_setting; |
1106 | 1145 | } |
1107 | 1146 | |
1108 | 1147 | // Save the new database-based settings, if any. |
1109 | - if (!empty($new_settings)) |
|
1110 | - saveDBSettings($new_settings); |
|
1111 | -} |
|
1148 | + if (!empty($new_settings)) { |
|
1149 | + saveDBSettings($new_settings); |
|
1150 | + } |
|
1151 | + } |
|
1112 | 1152 | |
1113 | 1153 | /** |
1114 | 1154 | * Helper function for saving database settings. |
@@ -1126,22 +1166,25 @@ discard block |
||
1126 | 1166 | $inlinePermissions = array(); |
1127 | 1167 | foreach ($config_vars as $var) |
1128 | 1168 | { |
1129 | - if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags'])))) |
|
1130 | - continue; |
|
1169 | + if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags'])))) { |
|
1170 | + continue; |
|
1171 | + } |
|
1131 | 1172 | |
1132 | 1173 | // Checkboxes! |
1133 | - elseif ($var[0] == 'check') |
|
1134 | - $setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0'; |
|
1174 | + elseif ($var[0] == 'check') { |
|
1175 | + $setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0'; |
|
1176 | + } |
|
1135 | 1177 | // Select boxes! |
1136 | - elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) |
|
1137 | - $setArray[$var[1]] = $_POST[$var[1]]; |
|
1138 | - elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array()) |
|
1178 | + elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) { |
|
1179 | + $setArray[$var[1]] = $_POST[$var[1]]; |
|
1180 | + } elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array()) |
|
1139 | 1181 | { |
1140 | 1182 | // For security purposes we validate this line by line. |
1141 | 1183 | $lOptions = array(); |
1142 | - foreach ($_POST[$var[1]] as $invar) |
|
1143 | - if (in_array($invar, array_keys($var[2]))) |
|
1184 | + foreach ($_POST[$var[1]] as $invar) { |
|
1185 | + if (in_array($invar, array_keys($var[2]))) |
|
1144 | 1186 | $lOptions[] = $invar; |
1187 | + } |
|
1145 | 1188 | |
1146 | 1189 | $setArray[$var[1]] = json_encode($lOptions); |
1147 | 1190 | } |
@@ -1155,18 +1198,20 @@ discard block |
||
1155 | 1198 | $request = $smcFunc['db_query']('', ' |
1156 | 1199 | SELECT id_board |
1157 | 1200 | FROM {db_prefix}boards'); |
1158 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
1159 | - $board_list[$row[0]] = true; |
|
1201 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
1202 | + $board_list[$row[0]] = true; |
|
1203 | + } |
|
1160 | 1204 | |
1161 | 1205 | $smcFunc['db_free_result']($request); |
1162 | 1206 | } |
1163 | 1207 | |
1164 | 1208 | $lOptions = array(); |
1165 | 1209 | |
1166 | - if (!empty($_POST[$var[1]])) |
|
1167 | - foreach ($_POST[$var[1]] as $invar => $dummy) |
|
1210 | + if (!empty($_POST[$var[1]])) { |
|
1211 | + foreach ($_POST[$var[1]] as $invar => $dummy) |
|
1168 | 1212 | if (isset($board_list[$invar])) |
1169 | 1213 | $lOptions[] = $invar; |
1214 | + } |
|
1170 | 1215 | |
1171 | 1216 | $setArray[$var[1]] = !empty($lOptions) ? implode(',', $lOptions) : ''; |
1172 | 1217 | } |
@@ -1180,8 +1225,9 @@ discard block |
||
1180 | 1225 | $setArray[$var[1]] = max($min, $setArray[$var[1]]); |
1181 | 1226 | |
1182 | 1227 | // Do we have a max value for this as well? |
1183 | - if (isset($var['max'])) |
|
1184 | - $setArray[$var[1]] = min($var['max'], $setArray[$var[1]]); |
|
1228 | + if (isset($var['max'])) { |
|
1229 | + $setArray[$var[1]] = min($var['max'], $setArray[$var[1]]); |
|
1230 | + } |
|
1185 | 1231 | } |
1186 | 1232 | // Floating point! |
1187 | 1233 | elseif ($var[0] == 'float') |
@@ -1193,40 +1239,47 @@ discard block |
||
1193 | 1239 | $setArray[$var[1]] = max($min, $setArray[$var[1]]); |
1194 | 1240 | |
1195 | 1241 | // Do we have a max value for this as well? |
1196 | - if (isset($var['max'])) |
|
1197 | - $setArray[$var[1]] = min($var['max'], $setArray[$var[1]]); |
|
1242 | + if (isset($var['max'])) { |
|
1243 | + $setArray[$var[1]] = min($var['max'], $setArray[$var[1]]); |
|
1244 | + } |
|
1198 | 1245 | } |
1199 | 1246 | // Text! |
1200 | - elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) |
|
1201 | - $setArray[$var[1]] = $_POST[$var[1]]; |
|
1247 | + elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) { |
|
1248 | + $setArray[$var[1]] = $_POST[$var[1]]; |
|
1249 | + } |
|
1202 | 1250 | // Passwords! |
1203 | 1251 | elseif ($var[0] == 'password') |
1204 | 1252 | { |
1205 | - if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) |
|
1206 | - $setArray[$var[1]] = $_POST[$var[1]][0]; |
|
1253 | + if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) { |
|
1254 | + $setArray[$var[1]] = $_POST[$var[1]][0]; |
|
1255 | + } |
|
1207 | 1256 | } |
1208 | 1257 | // BBC. |
1209 | 1258 | elseif ($var[0] == 'bbc') |
1210 | 1259 | { |
1211 | 1260 | |
1212 | 1261 | $bbcTags = array(); |
1213 | - foreach (parse_bbc(false) as $tag) |
|
1214 | - $bbcTags[] = $tag['tag']; |
|
1262 | + foreach (parse_bbc(false) as $tag) { |
|
1263 | + $bbcTags[] = $tag['tag']; |
|
1264 | + } |
|
1215 | 1265 | |
1216 | - if (!isset($_POST[$var[1] . '_enabledTags'])) |
|
1217 | - $_POST[$var[1] . '_enabledTags'] = array(); |
|
1218 | - elseif (!is_array($_POST[$var[1] . '_enabledTags'])) |
|
1219 | - $_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']); |
|
1266 | + if (!isset($_POST[$var[1] . '_enabledTags'])) { |
|
1267 | + $_POST[$var[1] . '_enabledTags'] = array(); |
|
1268 | + } elseif (!is_array($_POST[$var[1] . '_enabledTags'])) { |
|
1269 | + $_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']); |
|
1270 | + } |
|
1220 | 1271 | |
1221 | 1272 | $setArray[$var[1]] = implode(',', array_diff($bbcTags, $_POST[$var[1] . '_enabledTags'])); |
1222 | 1273 | } |
1223 | 1274 | // Permissions? |
1224 | - elseif ($var[0] == 'permissions') |
|
1225 | - $inlinePermissions[] = $var[1]; |
|
1275 | + elseif ($var[0] == 'permissions') { |
|
1276 | + $inlinePermissions[] = $var[1]; |
|
1277 | + } |
|
1226 | 1278 | } |
1227 | 1279 | |
1228 | - if (!empty($setArray)) |
|
1229 | - updateSettings($setArray); |
|
1280 | + if (!empty($setArray)) { |
|
1281 | + updateSettings($setArray); |
|
1282 | + } |
|
1230 | 1283 | |
1231 | 1284 | // If we have inline permissions we need to save them. |
1232 | 1285 | if (!empty($inlinePermissions) && allowedTo('manage_permissions')) |
@@ -1264,18 +1317,21 @@ discard block |
||
1264 | 1317 | // put all of it into an array |
1265 | 1318 | foreach ($info_lines as $line) |
1266 | 1319 | { |
1267 | - if (preg_match('~(' . $remove . ')~', $line)) |
|
1268 | - continue; |
|
1320 | + if (preg_match('~(' . $remove . ')~', $line)) { |
|
1321 | + continue; |
|
1322 | + } |
|
1269 | 1323 | |
1270 | 1324 | // new category? |
1271 | - if (strpos($line, '<h2>') !== false) |
|
1272 | - $category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category; |
|
1325 | + if (strpos($line, '<h2>') !== false) { |
|
1326 | + $category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category; |
|
1327 | + } |
|
1273 | 1328 | |
1274 | 1329 | // load it as setting => value or the old setting local master |
1275 | - if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) |
|
1276 | - $pinfo[$category][$val[1]] = $val[2]; |
|
1277 | - elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) |
|
1278 | - $pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]); |
|
1330 | + if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) { |
|
1331 | + $pinfo[$category][$val[1]] = $val[2]; |
|
1332 | + } elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) { |
|
1333 | + $pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]); |
|
1334 | + } |
|
1279 | 1335 | } |
1280 | 1336 | |
1281 | 1337 | // load it in to context and display it |
@@ -1310,8 +1366,9 @@ discard block |
||
1310 | 1366 | $testAPI = new $cache_class_name(); |
1311 | 1367 | |
1312 | 1368 | // No Support? NEXT! |
1313 | - if (!$testAPI->isSupported(true)) |
|
1314 | - continue; |
|
1369 | + if (!$testAPI->isSupported(true)) { |
|
1370 | + continue; |
|
1371 | + } |
|
1315 | 1372 | |
1316 | 1373 | $apis[$tryCache] = isset($txt[$tryCache . '_cache']) ? $txt[$tryCache . '_cache'] : $tryCache; |
1317 | 1374 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | COALESCE(mem.real_name, ms.poster_name) AS topic_started_name, ms.poster_time AS topic_started_time, |
160 | 160 | ' . ($user_info['is_guest'] ? 't.id_last_msg + 1' : 'COALESCE(lt.id_msg, lmr.id_msg, -1) + 1') . ' AS new_from |
161 | 161 | ' . (!empty($board_info['recycle']) ? ', id_previous_board, id_previous_topic' : '') . ' |
162 | - ' . (!empty($topic_selects) ? (', '. implode(', ', $topic_selects)) : '') . ' |
|
162 | + ' . (!empty($topic_selects) ? (', ' . implode(', ', $topic_selects)) : '') . ' |
|
163 | 163 | ' . (!$user_info['is_guest'] ? ', COALESCE(lt.unwatched, 0) as unwatched' : '') . ' |
164 | 164 | FROM {db_prefix}topics AS t |
165 | 165 | INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg) |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | WHERE INSTR(lo.url, {string:in_url_string}) > 0 OR lo.session = {string:session}', |
389 | 389 | array( |
390 | 390 | 'reg_id_group' => 0, |
391 | - 'in_url_string' => '"topic":'.$topic, |
|
391 | + 'in_url_string' => '"topic":' . $topic, |
|
392 | 392 | 'session' => $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id(), |
393 | 393 | ) |
394 | 394 | ); |
@@ -457,8 +457,8 @@ discard block |
||
457 | 457 | $context['links'] = array( |
458 | 458 | 'first' => $_REQUEST['start'] >= $context['messages_per_page'] ? $scripturl . '?topic=' . $topic . '.0' : '', |
459 | 459 | 'prev' => $_REQUEST['start'] >= $context['messages_per_page'] ? $scripturl . '?topic=' . $topic . '.' . ($_REQUEST['start'] - $context['messages_per_page']) : '', |
460 | - 'next' => $_REQUEST['start'] + $context['messages_per_page'] < $context['total_visible_posts'] ? $scripturl . '?topic=' . $topic. '.' . ($_REQUEST['start'] + $context['messages_per_page']) : '', |
|
461 | - 'last' => $_REQUEST['start'] + $context['messages_per_page'] < $context['total_visible_posts'] ? $scripturl . '?topic=' . $topic. '.' . (floor($context['total_visible_posts'] / $context['messages_per_page']) * $context['messages_per_page']) : '', |
|
460 | + 'next' => $_REQUEST['start'] + $context['messages_per_page'] < $context['total_visible_posts'] ? $scripturl . '?topic=' . $topic . '.' . ($_REQUEST['start'] + $context['messages_per_page']) : '', |
|
461 | + 'last' => $_REQUEST['start'] + $context['messages_per_page'] < $context['total_visible_posts'] ? $scripturl . '?topic=' . $topic . '.' . (floor($context['total_visible_posts'] / $context['messages_per_page']) * $context['messages_per_page']) : '', |
|
462 | 462 | 'up' => $scripturl . '?board=' . $board . '.0' |
463 | 463 | ); |
464 | 464 | } |
@@ -1037,7 +1037,7 @@ discard block |
||
1037 | 1037 | id_msg, icon, subject, poster_time, poster_ip, id_member, modified_time, modified_name, modified_reason, body, |
1038 | 1038 | smileys_enabled, poster_name, poster_email, approved, likes, |
1039 | 1039 | id_msg_modified < {int:new_from} AS is_read |
1040 | - ' . (!empty($msg_selects) ? (', '. implode(', ', $msg_selects)) : '') . ' |
|
1040 | + ' . (!empty($msg_selects) ? (', ' . implode(', ', $msg_selects)) : '') . ' |
|
1041 | 1041 | FROM {db_prefix}messages |
1042 | 1042 | ' . (!empty($msg_tables) ? implode("\n\t", $msg_tables) : '') . ' |
1043 | 1043 | WHERE id_msg IN ({array_int:message_list}) |
@@ -1681,17 +1681,17 @@ discard block |
||
1681 | 1681 | if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file_ext, array('txt', 'css', 'htm', 'html', 'php', 'xml'))) |
1682 | 1682 | { |
1683 | 1683 | if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) |
1684 | - $callback = function ($buffer) |
|
1684 | + $callback = function($buffer) |
|
1685 | 1685 | { |
1686 | 1686 | return preg_replace('~[\r]?\n~', "\r\n", $buffer); |
1687 | 1687 | }; |
1688 | 1688 | elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) |
1689 | - $callback = function ($buffer) |
|
1689 | + $callback = function($buffer) |
|
1690 | 1690 | { |
1691 | 1691 | return preg_replace('~[\r]?\n~', "\r", $buffer); |
1692 | 1692 | }; |
1693 | 1693 | else |
1694 | - $callback = function ($buffer) |
|
1694 | + $callback = function($buffer) |
|
1695 | 1695 | { |
1696 | 1696 | return preg_replace('~[\r]?\n~', "\n", $buffer); |
1697 | 1697 | }; |
@@ -1772,7 +1772,7 @@ discard block |
||
1772 | 1772 | list($subname) = $smcFunc['db_fetch_row']($request); |
1773 | 1773 | $smcFunc['db_free_result']($request); |
1774 | 1774 | $_SESSION['split_selection'][$topic] = $messages; |
1775 | - redirectexit('action=splittopics;sa=selectTopics;topic=' . $topic . '.0;subname_enc=' .urlencode($subname) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1775 | + redirectexit('action=splittopics;sa=selectTopics;topic=' . $topic . '.0;subname_enc=' . urlencode($subname) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1776 | 1776 | } |
1777 | 1777 | |
1778 | 1778 | // Allowed to delete any message? |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * The central part of the board - topic display. |
@@ -34,8 +35,9 @@ discard block |
||
34 | 35 | global $attachments, $messages_request, $language, $smcFunc; |
35 | 36 | |
36 | 37 | // What are you gonna display if these are empty?! |
37 | - if (empty($topic)) |
|
38 | - fatal_lang_error('no_board', false); |
|
38 | + if (empty($topic)) { |
|
39 | + fatal_lang_error('no_board', false); |
|
40 | + } |
|
39 | 41 | |
40 | 42 | // Load the proper template. |
41 | 43 | loadTemplate('Display'); |
@@ -52,15 +54,17 @@ discard block |
||
52 | 54 | $context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
53 | 55 | |
54 | 56 | // Let's do some work on what to search index. |
55 | - if (count($_GET) > 2) |
|
56 | - foreach ($_GET as $k => $v) |
|
57 | + if (count($_GET) > 2) { |
|
58 | + foreach ($_GET as $k => $v) |
|
57 | 59 | { |
58 | 60 | if (!in_array($k, array('topic', 'board', 'start', session_name()))) |
59 | 61 | $context['robot_no_index'] = true; |
62 | + } |
|
60 | 63 | } |
61 | 64 | |
62 | - if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) |
|
63 | - $context['robot_no_index'] = true; |
|
65 | + if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) { |
|
66 | + $context['robot_no_index'] = true; |
|
67 | + } |
|
64 | 68 | |
65 | 69 | // Find the previous or next topic. Make a fuss if there are no more. |
66 | 70 | if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next')) |
@@ -172,8 +176,9 @@ discard block |
||
172 | 176 | $topic_parameters |
173 | 177 | ); |
174 | 178 | |
175 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
176 | - fatal_lang_error('not_a_topic', false, 404); |
|
179 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
180 | + fatal_lang_error('not_a_topic', false, 404); |
|
181 | + } |
|
177 | 182 | $context['topicinfo'] = $smcFunc['db_fetch_assoc']($request); |
178 | 183 | $smcFunc['db_free_result']($request); |
179 | 184 | |
@@ -210,8 +215,9 @@ discard block |
||
210 | 215 | $context['topic_unwatched'] = isset($context['topicinfo']['unwatched']) ? $context['topicinfo']['unwatched'] : 0; |
211 | 216 | |
212 | 217 | // Add up unapproved replies to get real number of replies... |
213 | - if ($modSettings['postmod_active'] && $approve_posts) |
|
214 | - $context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1); |
|
218 | + if ($modSettings['postmod_active'] && $approve_posts) { |
|
219 | + $context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1); |
|
220 | + } |
|
215 | 221 | |
216 | 222 | // If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing. |
217 | 223 | if ($modSettings['postmod_active'] && $context['topicinfo']['unapproved_posts'] && !$user_info['is_guest'] && !$approve_posts) |
@@ -231,11 +237,11 @@ discard block |
||
231 | 237 | $smcFunc['db_free_result']($request); |
232 | 238 | |
233 | 239 | $context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($context['topicinfo']['approved'] ? 1 : 0); |
240 | + } elseif ($user_info['is_guest']) { |
|
241 | + $context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
242 | + } else { |
|
243 | + $context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
234 | 244 | } |
235 | - elseif ($user_info['is_guest']) |
|
236 | - $context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
237 | - else |
|
238 | - $context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
239 | 245 | |
240 | 246 | // The start isn't a number; it's information about what to do, where to go. |
241 | 247 | if (!is_numeric($_REQUEST['start'])) |
@@ -248,8 +254,7 @@ discard block |
||
248 | 254 | { |
249 | 255 | $context['start_from'] = $context['total_visible_posts'] - 1; |
250 | 256 | $_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0; |
251 | - } |
|
252 | - else |
|
257 | + } else |
|
253 | 258 | { |
254 | 259 | // Find the earliest unread message in the topic. (the use of topics here is just for both tables.) |
255 | 260 | $request = $smcFunc['db_query']('', ' |
@@ -277,9 +282,9 @@ discard block |
||
277 | 282 | if (substr($_REQUEST['start'], 0, 4) == 'from') |
278 | 283 | { |
279 | 284 | $timestamp = (int) substr($_REQUEST['start'], 4); |
280 | - if ($timestamp === 0) |
|
281 | - $_REQUEST['start'] = 0; |
|
282 | - else |
|
285 | + if ($timestamp === 0) { |
|
286 | + $_REQUEST['start'] = 0; |
|
287 | + } else |
|
283 | 288 | { |
284 | 289 | // Find the number of messages posted before said time... |
285 | 290 | $request = $smcFunc['db_query']('', ' |
@@ -307,11 +312,11 @@ discard block |
||
307 | 312 | elseif (substr($_REQUEST['start'], 0, 3) == 'msg') |
308 | 313 | { |
309 | 314 | $virtual_msg = (int) substr($_REQUEST['start'], 3); |
310 | - if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) |
|
311 | - $context['start_from'] = $context['total_visible_posts'] - 1; |
|
312 | - elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) |
|
313 | - $context['start_from'] = 0; |
|
314 | - else |
|
315 | + if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) { |
|
316 | + $context['start_from'] = $context['total_visible_posts'] - 1; |
|
317 | + } elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) { |
|
318 | + $context['start_from'] = 0; |
|
319 | + } else |
|
315 | 320 | { |
316 | 321 | // Find the start value for that message...... |
317 | 322 | $request = $smcFunc['db_query']('', ' |
@@ -394,21 +399,25 @@ discard block |
||
394 | 399 | ); |
395 | 400 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
396 | 401 | { |
397 | - if (empty($row['id_member'])) |
|
398 | - continue; |
|
402 | + if (empty($row['id_member'])) { |
|
403 | + continue; |
|
404 | + } |
|
399 | 405 | |
400 | - if (!empty($row['online_color'])) |
|
401 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
402 | - else |
|
403 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
406 | + if (!empty($row['online_color'])) { |
|
407 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
408 | + } else { |
|
409 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
410 | + } |
|
404 | 411 | |
405 | 412 | $is_buddy = in_array($row['id_member'], $user_info['buddies']); |
406 | - if ($is_buddy) |
|
407 | - $link = '<strong>' . $link . '</strong>'; |
|
413 | + if ($is_buddy) { |
|
414 | + $link = '<strong>' . $link . '</strong>'; |
|
415 | + } |
|
408 | 416 | |
409 | 417 | // Add them both to the list and to the more detailed list. |
410 | - if (!empty($row['show_online']) || allowedTo('moderate_forum')) |
|
411 | - $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
|
418 | + if (!empty($row['show_online']) || allowedTo('moderate_forum')) { |
|
419 | + $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
|
420 | + } |
|
412 | 421 | $context['view_members'][$row['log_time'] . $row['member_name']] = array( |
413 | 422 | 'id' => $row['id_member'], |
414 | 423 | 'username' => $row['member_name'], |
@@ -420,8 +429,9 @@ discard block |
||
420 | 429 | 'hidden' => empty($row['show_online']), |
421 | 430 | ); |
422 | 431 | |
423 | - if (empty($row['show_online'])) |
|
424 | - $context['view_num_hidden']++; |
|
432 | + if (empty($row['show_online'])) { |
|
433 | + $context['view_num_hidden']++; |
|
434 | + } |
|
425 | 435 | } |
426 | 436 | |
427 | 437 | // The number of guests is equal to the rows minus the ones we actually used ;). |
@@ -435,11 +445,13 @@ discard block |
||
435 | 445 | |
436 | 446 | // If all is set, but not allowed... just unset it. |
437 | 447 | $can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages']; |
438 | - if (isset($_REQUEST['all']) && !$can_show_all) |
|
439 | - unset($_REQUEST['all']); |
|
448 | + if (isset($_REQUEST['all']) && !$can_show_all) { |
|
449 | + unset($_REQUEST['all']); |
|
450 | + } |
|
440 | 451 | // Otherwise, it must be allowed... so pretend start was -1. |
441 | - elseif (isset($_REQUEST['all'])) |
|
442 | - $_REQUEST['start'] = -1; |
|
452 | + elseif (isset($_REQUEST['all'])) { |
|
453 | + $_REQUEST['start'] = -1; |
|
454 | + } |
|
443 | 455 | |
444 | 456 | // Construct the page index, allowing for the .START method... |
445 | 457 | $context['page_index'] = constructPageIndex($scripturl . '?topic=' . $topic . '.%1$d', $_REQUEST['start'], $context['total_visible_posts'], $context['messages_per_page'], true); |
@@ -476,8 +488,9 @@ discard block |
||
476 | 488 | $_REQUEST['start'] = 0; |
477 | 489 | } |
478 | 490 | // They aren't using it, but the *option* is there, at least. |
479 | - else |
|
480 | - $context['page_index'] .= ' <a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> '; |
|
491 | + else { |
|
492 | + $context['page_index'] .= ' <a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> '; |
|
493 | + } |
|
481 | 494 | } |
482 | 495 | |
483 | 496 | // Build the link tree. |
@@ -493,14 +506,16 @@ discard block |
||
493 | 506 | if (!empty($board_info['moderators'])) |
494 | 507 | { |
495 | 508 | // Add a link for each moderator... |
496 | - foreach ($board_info['moderators'] as $mod) |
|
497 | - $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
|
509 | + foreach ($board_info['moderators'] as $mod) { |
|
510 | + $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
|
511 | + } |
|
498 | 512 | } |
499 | 513 | if (!empty($board_info['moderator_groups'])) |
500 | 514 | { |
501 | 515 | // Add a link for each moderator group as well... |
502 | - foreach ($board_info['moderator_groups'] as $mod_group) |
|
503 | - $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
|
516 | + foreach ($board_info['moderator_groups'] as $mod_group) { |
|
517 | + $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
|
518 | + } |
|
504 | 519 | } |
505 | 520 | |
506 | 521 | if (!empty($context['link_moderators'])) |
@@ -531,9 +546,9 @@ discard block |
||
531 | 546 | // For quick reply we need a response prefix in the default forum language. |
532 | 547 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600))) |
533 | 548 | { |
534 | - if ($language === $user_info['language']) |
|
535 | - $context['response_prefix'] = $txt['response_prefix']; |
|
536 | - else |
|
549 | + if ($language === $user_info['language']) { |
|
550 | + $context['response_prefix'] = $txt['response_prefix']; |
|
551 | + } else |
|
537 | 552 | { |
538 | 553 | loadLanguage('index', $language, false); |
539 | 554 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -565,8 +580,9 @@ discard block |
||
565 | 580 | list($start, $end, $allday, $span, $tz_abbrev) = buildEventDatetimes($row); |
566 | 581 | |
567 | 582 | // Sanity check |
568 | - if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) |
|
569 | - continue; |
|
583 | + if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) { |
|
584 | + continue; |
|
585 | + } |
|
570 | 586 | |
571 | 587 | $linked_calendar_event = array( |
572 | 588 | 'id' => $row['id_event'], |
@@ -615,8 +631,9 @@ discard block |
||
615 | 631 | } |
616 | 632 | $smcFunc['db_free_result']($request); |
617 | 633 | |
618 | - if (!empty($context['linked_calendar_events'])) |
|
619 | - $context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true; |
|
634 | + if (!empty($context['linked_calendar_events'])) { |
|
635 | + $context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true; |
|
636 | + } |
|
620 | 637 | } |
621 | 638 | |
622 | 639 | // Create the poll info if it exists. |
@@ -689,20 +706,21 @@ discard block |
||
689 | 706 | foreach ($guestinfo as $i => $guestvoted) |
690 | 707 | { |
691 | 708 | $guestvoted = explode(',', $guestvoted); |
692 | - if ($guestvoted[0] == $context['topicinfo']['id_poll']) |
|
693 | - break; |
|
709 | + if ($guestvoted[0] == $context['topicinfo']['id_poll']) { |
|
710 | + break; |
|
711 | + } |
|
694 | 712 | } |
695 | 713 | // Has the poll been reset since guest voted? |
696 | 714 | if ($pollinfo['reset_poll'] > $guestvoted[1]) |
697 | 715 | { |
698 | 716 | // Remove the poll info from the cookie to allow guest to vote again |
699 | 717 | unset($guestinfo[$i]); |
700 | - if (!empty($guestinfo)) |
|
701 | - $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo); |
|
702 | - else |
|
703 | - unset($_COOKIE['guest_poll_vote']); |
|
704 | - } |
|
705 | - else |
|
718 | + if (!empty($guestinfo)) { |
|
719 | + $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo); |
|
720 | + } else { |
|
721 | + unset($_COOKIE['guest_poll_vote']); |
|
722 | + } |
|
723 | + } else |
|
706 | 724 | { |
707 | 725 | // What did they vote for? |
708 | 726 | unset($guestvoted[0], $guestvoted[1]); |
@@ -816,23 +834,29 @@ discard block |
||
816 | 834 | // Build the poll moderation button array. |
817 | 835 | $context['poll_buttons'] = array(); |
818 | 836 | |
819 | - if ($context['allow_return_vote']) |
|
820 | - $context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']); |
|
837 | + if ($context['allow_return_vote']) { |
|
838 | + $context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']); |
|
839 | + } |
|
821 | 840 | |
822 | - if ($context['show_view_results_button']) |
|
823 | - $context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults'); |
|
841 | + if ($context['show_view_results_button']) { |
|
842 | + $context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults'); |
|
843 | + } |
|
824 | 844 | |
825 | - if ($context['allow_change_vote']) |
|
826 | - $context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
845 | + if ($context['allow_change_vote']) { |
|
846 | + $context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
847 | + } |
|
827 | 848 | |
828 | - if ($context['allow_lock_poll']) |
|
829 | - $context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
849 | + if ($context['allow_lock_poll']) { |
|
850 | + $context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
851 | + } |
|
830 | 852 | |
831 | - if ($context['allow_edit_poll']) |
|
832 | - $context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
853 | + if ($context['allow_edit_poll']) { |
|
854 | + $context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
855 | + } |
|
833 | 856 | |
834 | - if ($context['can_remove_poll']) |
|
835 | - $context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
857 | + if ($context['can_remove_poll']) { |
|
858 | + $context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
859 | + } |
|
836 | 860 | |
837 | 861 | // Allow mods to add additional buttons here |
838 | 862 | call_integration_hook('integrate_poll_buttons'); |
@@ -873,8 +897,9 @@ discard block |
||
873 | 897 | $all_posters = array(); |
874 | 898 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
875 | 899 | { |
876 | - if (!empty($row['id_member'])) |
|
877 | - $all_posters[$row['id_msg']] = $row['id_member']; |
|
900 | + if (!empty($row['id_member'])) { |
|
901 | + $all_posters[$row['id_msg']] = $row['id_member']; |
|
902 | + } |
|
878 | 903 | $messages[] = $row['id_msg']; |
879 | 904 | } |
880 | 905 | $smcFunc['db_free_result']($request); |
@@ -886,8 +911,9 @@ discard block |
||
886 | 911 | if (!$user_info['is_guest'] && !empty($messages)) |
887 | 912 | { |
888 | 913 | $mark_at_msg = max($messages); |
889 | - if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) |
|
890 | - $mark_at_msg = $modSettings['maxMsgID']; |
|
914 | + if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) { |
|
915 | + $mark_at_msg = $modSettings['maxMsgID']; |
|
916 | + } |
|
891 | 917 | if ($mark_at_msg >= $context['topicinfo']['new_from']) |
892 | 918 | { |
893 | 919 | $smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace', |
@@ -919,8 +945,9 @@ discard block |
||
919 | 945 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
920 | 946 | { |
921 | 947 | // Find if this topic is marked for notification... |
922 | - if (!empty($row['id_topic'])) |
|
923 | - $context['is_marked_notify'] = true; |
|
948 | + if (!empty($row['id_topic'])) { |
|
949 | + $context['is_marked_notify'] = true; |
|
950 | + } |
|
924 | 951 | |
925 | 952 | // Only do this once, but mark the notifications as "not sent yet" for next time. |
926 | 953 | if (!empty($row['sent']) && $do_once) |
@@ -942,8 +969,9 @@ discard block |
||
942 | 969 | } |
943 | 970 | |
944 | 971 | // Have we recently cached the number of new topics in this board, and it's still a lot? |
945 | - if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) |
|
946 | - $_SESSION['topicseen_cache'][$board]--; |
|
972 | + if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) { |
|
973 | + $_SESSION['topicseen_cache'][$board]--; |
|
974 | + } |
|
947 | 975 | // Mark board as seen if this is the only new topic. |
948 | 976 | elseif (isset($_REQUEST['topicseen'])) |
949 | 977 | { |
@@ -967,14 +995,16 @@ discard block |
||
967 | 995 | $smcFunc['db_free_result']($request); |
968 | 996 | |
969 | 997 | // If there're no real new topics in this board, mark the board as seen. |
970 | - if (empty($numNewTopics)) |
|
971 | - $_REQUEST['boardseen'] = true; |
|
972 | - else |
|
973 | - $_SESSION['topicseen_cache'][$board] = $numNewTopics; |
|
998 | + if (empty($numNewTopics)) { |
|
999 | + $_REQUEST['boardseen'] = true; |
|
1000 | + } else { |
|
1001 | + $_SESSION['topicseen_cache'][$board] = $numNewTopics; |
|
1002 | + } |
|
974 | 1003 | } |
975 | 1004 | // Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often. |
976 | - elseif (isset($_SESSION['topicseen_cache'][$board])) |
|
977 | - $_SESSION['topicseen_cache'][$board]--; |
|
1005 | + elseif (isset($_SESSION['topicseen_cache'][$board])) { |
|
1006 | + $_SESSION['topicseen_cache'][$board]--; |
|
1007 | + } |
|
978 | 1008 | |
979 | 1009 | // Mark board as seen if we came using last post link from BoardIndex. (or other places...) |
980 | 1010 | if (isset($_REQUEST['boardseen'])) |
@@ -1031,23 +1061,26 @@ discard block |
||
1031 | 1061 | $temp = array(); |
1032 | 1062 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1033 | 1063 | { |
1034 | - if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) |
|
1035 | - continue; |
|
1064 | + if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) { |
|
1065 | + continue; |
|
1066 | + } |
|
1036 | 1067 | |
1037 | 1068 | $temp[$row['id_attach']] = $row; |
1038 | 1069 | $temp[$row['id_attach']]['topic'] = $topic; |
1039 | 1070 | $temp[$row['id_attach']]['board'] = $board; |
1040 | 1071 | |
1041 | - if (!isset($context['loaded_attachments'][$row['id_msg']])) |
|
1042 | - $context['loaded_attachments'][$row['id_msg']] = array(); |
|
1072 | + if (!isset($context['loaded_attachments'][$row['id_msg']])) { |
|
1073 | + $context['loaded_attachments'][$row['id_msg']] = array(); |
|
1074 | + } |
|
1043 | 1075 | } |
1044 | 1076 | $smcFunc['db_free_result']($request); |
1045 | 1077 | |
1046 | 1078 | // This is better than sorting it with the query... |
1047 | 1079 | ksort($temp); |
1048 | 1080 | |
1049 | - foreach ($temp as $row) |
|
1050 | - $context['loaded_attachments'][$row['id_msg']][] = $row; |
|
1081 | + foreach ($temp as $row) { |
|
1082 | + $context['loaded_attachments'][$row['id_msg']][] = $row; |
|
1083 | + } |
|
1051 | 1084 | } |
1052 | 1085 | |
1053 | 1086 | $msg_parameters = array( |
@@ -1074,21 +1107,23 @@ discard block |
||
1074 | 1107 | ); |
1075 | 1108 | |
1076 | 1109 | // And the likes |
1077 | - if (!empty($modSettings['enable_likes'])) |
|
1078 | - $context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic); |
|
1110 | + if (!empty($modSettings['enable_likes'])) { |
|
1111 | + $context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic); |
|
1112 | + } |
|
1079 | 1113 | |
1080 | 1114 | // Go to the last message if the given time is beyond the time of the last message. |
1081 | - if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) |
|
1082 | - $context['start_from'] = $context['topicinfo']['num_replies']; |
|
1115 | + if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) { |
|
1116 | + $context['start_from'] = $context['topicinfo']['num_replies']; |
|
1117 | + } |
|
1083 | 1118 | |
1084 | 1119 | // Since the anchor information is needed on the top of the page we load these variables beforehand. |
1085 | 1120 | $context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0]; |
1086 | - if (empty($options['view_newest_first'])) |
|
1087 | - $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from']; |
|
1088 | - else |
|
1089 | - $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from']; |
|
1090 | - } |
|
1091 | - else |
|
1121 | + if (empty($options['view_newest_first'])) { |
|
1122 | + $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from']; |
|
1123 | + } else { |
|
1124 | + $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from']; |
|
1125 | + } |
|
1126 | + } else |
|
1092 | 1127 | { |
1093 | 1128 | $messages_request = false; |
1094 | 1129 | $context['first_message'] = 0; |
@@ -1124,8 +1159,9 @@ discard block |
||
1124 | 1159 | 'can_see_likes' => 'likes_view', |
1125 | 1160 | 'can_like' => 'likes_like', |
1126 | 1161 | ); |
1127 | - foreach ($common_permissions as $contextual => $perm) |
|
1128 | - $context[$contextual] = allowedTo($perm); |
|
1162 | + foreach ($common_permissions as $contextual => $perm) { |
|
1163 | + $context[$contextual] = allowedTo($perm); |
|
1164 | + } |
|
1129 | 1165 | |
1130 | 1166 | // Permissions with _any/_own versions. $context[YYY] => ZZZ_any/_own. |
1131 | 1167 | $anyown_permissions = array( |
@@ -1138,8 +1174,9 @@ discard block |
||
1138 | 1174 | 'can_reply_unapproved' => 'post_unapproved_replies', |
1139 | 1175 | 'can_view_warning' => 'profile_warning', |
1140 | 1176 | ); |
1141 | - foreach ($anyown_permissions as $contextual => $perm) |
|
1142 | - $context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own')); |
|
1177 | + foreach ($anyown_permissions as $contextual => $perm) { |
|
1178 | + $context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own')); |
|
1179 | + } |
|
1143 | 1180 | |
1144 | 1181 | if (!$user_info['is_admin'] && !$modSettings['topic_move_any']) |
1145 | 1182 | { |
@@ -1185,8 +1222,9 @@ discard block |
||
1185 | 1222 | // Check if the draft functions are enabled and that they have permission to use them (for quick reply.) |
1186 | 1223 | $context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply']; |
1187 | 1224 | $context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']); |
1188 | - if (!empty($context['drafts_save'])) |
|
1189 | - loadLanguage('Drafts'); |
|
1225 | + if (!empty($context['drafts_save'])) { |
|
1226 | + loadLanguage('Drafts'); |
|
1227 | + } |
|
1190 | 1228 | |
1191 | 1229 | // When was the last time this topic was replied to? Should we warn them about it? |
1192 | 1230 | if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky'])) |
@@ -1247,26 +1285,31 @@ discard block |
||
1247 | 1285 | // Message icons - customized icons are off? |
1248 | 1286 | $context['icons'] = getMessageIcons($board); |
1249 | 1287 | |
1250 | - if (!empty($context['icons'])) |
|
1251 | - $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
1288 | + if (!empty($context['icons'])) { |
|
1289 | + $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
1290 | + } |
|
1252 | 1291 | |
1253 | 1292 | // Build the normal button array. |
1254 | 1293 | $context['normal_buttons'] = array(); |
1255 | 1294 | |
1256 | - if ($context['can_reply']) |
|
1257 | - $context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true); |
|
1295 | + if ($context['can_reply']) { |
|
1296 | + $context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true); |
|
1297 | + } |
|
1258 | 1298 | |
1259 | - if ($context['can_add_poll']) |
|
1260 | - $context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
1299 | + if ($context['can_add_poll']) { |
|
1300 | + $context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
1301 | + } |
|
1261 | 1302 | |
1262 | - if ($context['can_mark_unread']) |
|
1263 | - $context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1303 | + if ($context['can_mark_unread']) { |
|
1304 | + $context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1305 | + } |
|
1264 | 1306 | |
1265 | - if ($context['can_print']) |
|
1266 | - $context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'); |
|
1307 | + if ($context['can_print']) { |
|
1308 | + $context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'); |
|
1309 | + } |
|
1267 | 1310 | |
1268 | - if ($context['can_set_notify']) |
|
1269 | - $context['normal_buttons']['notify'] = array( |
|
1311 | + if ($context['can_set_notify']) { |
|
1312 | + $context['normal_buttons']['notify'] = array( |
|
1270 | 1313 | 'text' => 'notify_topic_' . $context['topic_notification_mode'], |
1271 | 1314 | 'sub_buttons' => array( |
1272 | 1315 | array( |
@@ -1288,38 +1331,47 @@ discard block |
||
1288 | 1331 | ), |
1289 | 1332 | ), |
1290 | 1333 | ); |
1334 | + } |
|
1291 | 1335 | |
1292 | 1336 | // Build the mod button array |
1293 | 1337 | $context['mod_buttons'] = array(); |
1294 | 1338 | |
1295 | - if ($context['can_move']) |
|
1296 | - $context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0'); |
|
1339 | + if ($context['can_move']) { |
|
1340 | + $context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0'); |
|
1341 | + } |
|
1297 | 1342 | |
1298 | - if ($context['can_delete']) |
|
1299 | - $context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']); |
|
1343 | + if ($context['can_delete']) { |
|
1344 | + $context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']); |
|
1345 | + } |
|
1300 | 1346 | |
1301 | - if ($context['can_lock']) |
|
1302 | - $context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1347 | + if ($context['can_lock']) { |
|
1348 | + $context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1349 | + } |
|
1303 | 1350 | |
1304 | - if ($context['can_sticky']) |
|
1305 | - $context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1351 | + if ($context['can_sticky']) { |
|
1352 | + $context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1353 | + } |
|
1306 | 1354 | |
1307 | - if ($context['can_merge']) |
|
1308 | - $context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']); |
|
1355 | + if ($context['can_merge']) { |
|
1356 | + $context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']); |
|
1357 | + } |
|
1309 | 1358 | |
1310 | - if ($context['calendar_post']) |
|
1311 | - $context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0'); |
|
1359 | + if ($context['calendar_post']) { |
|
1360 | + $context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0'); |
|
1361 | + } |
|
1312 | 1362 | |
1313 | 1363 | // Restore topic. eh? No monkey business. |
1314 | - if ($context['can_restore_topic']) |
|
1315 | - $context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1364 | + if ($context['can_restore_topic']) { |
|
1365 | + $context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1366 | + } |
|
1316 | 1367 | |
1317 | 1368 | // Show a message in case a recently posted message became unapproved. |
1318 | 1369 | $context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false; |
1319 | 1370 | |
1320 | 1371 | // Don't want to show this forever... |
1321 | - if ($context['becomesUnapproved']) |
|
1322 | - unset($_SESSION['becomesUnapproved']); |
|
1372 | + if ($context['becomesUnapproved']) { |
|
1373 | + unset($_SESSION['becomesUnapproved']); |
|
1374 | + } |
|
1323 | 1375 | |
1324 | 1376 | // Allow adding new mod buttons easily. |
1325 | 1377 | // Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used |
@@ -1328,12 +1380,14 @@ discard block |
||
1328 | 1380 | call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons'])); |
1329 | 1381 | |
1330 | 1382 | // Load the drafts js file |
1331 | - if ($context['drafts_autosave']) |
|
1332 | - loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts'); |
|
1383 | + if ($context['drafts_autosave']) { |
|
1384 | + loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts'); |
|
1385 | + } |
|
1333 | 1386 | |
1334 | 1387 | // Spellcheck |
1335 | - if ($context['show_spellchecking']) |
|
1336 | - loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); |
|
1388 | + if ($context['show_spellchecking']) { |
|
1389 | + loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); |
|
1390 | + } |
|
1337 | 1391 | |
1338 | 1392 | // topic.js |
1339 | 1393 | loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic'); |
@@ -1367,16 +1421,19 @@ discard block |
||
1367 | 1421 | static $counter = null; |
1368 | 1422 | |
1369 | 1423 | // If the query returned false, bail. |
1370 | - if ($messages_request == false) |
|
1371 | - return false; |
|
1424 | + if ($messages_request == false) { |
|
1425 | + return false; |
|
1426 | + } |
|
1372 | 1427 | |
1373 | 1428 | // Remember which message this is. (ie. reply #83) |
1374 | - if ($counter === null || $reset) |
|
1375 | - $counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start']; |
|
1429 | + if ($counter === null || $reset) { |
|
1430 | + $counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start']; |
|
1431 | + } |
|
1376 | 1432 | |
1377 | 1433 | // Start from the beginning... |
1378 | - if ($reset) |
|
1379 | - return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1434 | + if ($reset) { |
|
1435 | + return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1436 | + } |
|
1380 | 1437 | |
1381 | 1438 | // Attempt to get the next message. |
1382 | 1439 | $message = $smcFunc['db_fetch_assoc']($messages_request); |
@@ -1390,19 +1447,21 @@ discard block |
||
1390 | 1447 | if (empty($context['icon_sources'])) |
1391 | 1448 | { |
1392 | 1449 | $context['icon_sources'] = array(); |
1393 | - foreach ($context['stable_icons'] as $icon) |
|
1394 | - $context['icon_sources'][$icon] = 'images_url'; |
|
1450 | + foreach ($context['stable_icons'] as $icon) { |
|
1451 | + $context['icon_sources'][$icon] = 'images_url'; |
|
1452 | + } |
|
1395 | 1453 | } |
1396 | 1454 | |
1397 | 1455 | // Message Icon Management... check the images exist. |
1398 | 1456 | if (empty($modSettings['messageIconChecks_disable'])) |
1399 | 1457 | { |
1400 | 1458 | // If the current icon isn't known, then we need to do something... |
1401 | - if (!isset($context['icon_sources'][$message['icon']])) |
|
1402 | - $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1459 | + if (!isset($context['icon_sources'][$message['icon']])) { |
|
1460 | + $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1461 | + } |
|
1462 | + } elseif (!isset($context['icon_sources'][$message['icon']])) { |
|
1463 | + $context['icon_sources'][$message['icon']] = 'images_url'; |
|
1403 | 1464 | } |
1404 | - elseif (!isset($context['icon_sources'][$message['icon']])) |
|
1405 | - $context['icon_sources'][$message['icon']] = 'images_url'; |
|
1406 | 1465 | |
1407 | 1466 | // If you're a lazy bum, you probably didn't give a subject... |
1408 | 1467 | $message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject']; |
@@ -1427,8 +1486,7 @@ discard block |
||
1427 | 1486 | $memberContext[$message['id_member']]['email'] = $message['poster_email']; |
1428 | 1487 | $memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum'); |
1429 | 1488 | $memberContext[$message['id_member']]['is_guest'] = true; |
1430 | - } |
|
1431 | - else |
|
1489 | + } else |
|
1432 | 1490 | { |
1433 | 1491 | // Define this here to make things a bit more readable |
1434 | 1492 | $can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own')); |
@@ -1451,8 +1509,9 @@ discard block |
||
1451 | 1509 | $message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']); |
1452 | 1510 | |
1453 | 1511 | // If it's in the recycle bin we need to override whatever icon we did have. |
1454 | - if (!empty($board_info['recycle'])) |
|
1455 | - $message['icon'] = 'recycled'; |
|
1512 | + if (!empty($board_info['recycle'])) { |
|
1513 | + $message['icon'] = 'recycled'; |
|
1514 | + } |
|
1456 | 1515 | |
1457 | 1516 | require_once($sourcedir . '/Subs-Attachments.php'); |
1458 | 1517 | |
@@ -1496,32 +1555,36 @@ discard block |
||
1496 | 1555 | } |
1497 | 1556 | |
1498 | 1557 | // Are likes enable? |
1499 | - if (!empty($modSettings['enable_likes'])) |
|
1500 | - $output['likes'] = array( |
|
1558 | + if (!empty($modSettings['enable_likes'])) { |
|
1559 | + $output['likes'] = array( |
|
1501 | 1560 | 'count' => $message['likes'], |
1502 | 1561 | 'you' => in_array($message['id_msg'], $context['my_likes']), |
1503 | 1562 | 'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']), |
1504 | 1563 | ); |
1564 | + } |
|
1505 | 1565 | |
1506 | 1566 | // Is this user the message author? |
1507 | 1567 | $output['is_message_author'] = $message['id_member'] == $user_info['id']; |
1508 | - if (!empty($output['modified']['name'])) |
|
1509 | - $output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']); |
|
1568 | + if (!empty($output['modified']['name'])) { |
|
1569 | + $output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']); |
|
1570 | + } |
|
1510 | 1571 | |
1511 | 1572 | // Did they give a reason for editing? |
1512 | - if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) |
|
1513 | - $output['modified']['last_edit_text'] .= ' ' . sprintf($txt['last_edit_reason'], $output['modified']['reason']); |
|
1573 | + if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) { |
|
1574 | + $output['modified']['last_edit_text'] .= ' ' . sprintf($txt['last_edit_reason'], $output['modified']['reason']); |
|
1575 | + } |
|
1514 | 1576 | |
1515 | 1577 | // Any custom profile fields? |
1516 | - if (!empty($memberContext[$message['id_member']]['custom_fields'])) |
|
1517 | - foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom) |
|
1578 | + if (!empty($memberContext[$message['id_member']]['custom_fields'])) { |
|
1579 | + foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom) |
|
1518 | 1580 | $output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom; |
1581 | + } |
|
1519 | 1582 | |
1520 | - if (empty($options['view_newest_first'])) |
|
1521 | - $counter++; |
|
1522 | - |
|
1523 | - else |
|
1524 | - $counter--; |
|
1583 | + if (empty($options['view_newest_first'])) { |
|
1584 | + $counter++; |
|
1585 | + } else { |
|
1586 | + $counter--; |
|
1587 | + } |
|
1525 | 1588 | |
1526 | 1589 | call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter)); |
1527 | 1590 | |
@@ -1547,21 +1610,23 @@ discard block |
||
1547 | 1610 | $context['no_last_modified'] = true; |
1548 | 1611 | |
1549 | 1612 | // Prevent a preview image from being displayed twice. |
1550 | - if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview')) |
|
1551 | - return; |
|
1613 | + if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview')) { |
|
1614 | + return; |
|
1615 | + } |
|
1552 | 1616 | |
1553 | 1617 | // Make sure some attachment was requested! |
1554 | - if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id'])) |
|
1555 | - fatal_lang_error('no_access', false); |
|
1618 | + if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id'])) { |
|
1619 | + fatal_lang_error('no_access', false); |
|
1620 | + } |
|
1556 | 1621 | |
1557 | 1622 | $_REQUEST['attach'] = isset($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : (int) $_REQUEST['id']; |
1558 | 1623 | |
1559 | 1624 | // Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request. |
1560 | 1625 | $attachRequest = null; |
1561 | 1626 | call_integration_hook('integrate_download_request', array(&$attachRequest)); |
1562 | - if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) |
|
1563 | - $request = $attachRequest; |
|
1564 | - else |
|
1627 | + if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) { |
|
1628 | + $request = $attachRequest; |
|
1629 | + } else |
|
1565 | 1630 | { |
1566 | 1631 | // This checks only the current board for $board/$topic's permissions. |
1567 | 1632 | isAllowedTo('view_attachments'); |
@@ -1582,19 +1647,21 @@ discard block |
||
1582 | 1647 | ); |
1583 | 1648 | } |
1584 | 1649 | |
1585 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
1586 | - fatal_lang_error('no_access', false); |
|
1650 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1651 | + fatal_lang_error('no_access', false); |
|
1652 | + } |
|
1587 | 1653 | |
1588 | 1654 | list ($id_folder, $real_filename, $file_hash, $file_ext, $id_attach, $attachment_type, $mime_type, $is_approved, $id_member) = $smcFunc['db_fetch_row']($request); |
1589 | 1655 | $smcFunc['db_free_result']($request); |
1590 | 1656 | |
1591 | 1657 | // If it isn't yet approved, do they have permission to view it? |
1592 | - if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3)) |
|
1593 | - isAllowedTo('approve_posts'); |
|
1658 | + if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3)) { |
|
1659 | + isAllowedTo('approve_posts'); |
|
1660 | + } |
|
1594 | 1661 | |
1595 | 1662 | // Update the download counter (unless it's a thumbnail). |
1596 | - if ($attachment_type != 3) |
|
1597 | - $smcFunc['db_query']('attach_download_increase', ' |
|
1663 | + if ($attachment_type != 3) { |
|
1664 | + $smcFunc['db_query']('attach_download_increase', ' |
|
1598 | 1665 | UPDATE LOW_PRIORITY {db_prefix}attachments |
1599 | 1666 | SET downloads = downloads + 1 |
1600 | 1667 | WHERE id_attach = {int:id_attach}', |
@@ -1602,15 +1669,15 @@ discard block |
||
1602 | 1669 | 'id_attach' => $id_attach, |
1603 | 1670 | ) |
1604 | 1671 | ); |
1672 | + } |
|
1605 | 1673 | |
1606 | 1674 | $filename = getAttachmentFilename($real_filename, $_REQUEST['attach'], $id_folder, false, $file_hash); |
1607 | 1675 | |
1608 | 1676 | // This is done to clear any output that was made before now. |
1609 | 1677 | ob_end_clean(); |
1610 | - if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java'))) |
|
1611 | - @ob_start('ob_gzhandler'); |
|
1612 | - |
|
1613 | - else |
|
1678 | + if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java'))) { |
|
1679 | + @ob_start('ob_gzhandler'); |
|
1680 | + } else |
|
1614 | 1681 | { |
1615 | 1682 | ob_start(); |
1616 | 1683 | header('Content-Encoding: none'); |
@@ -1653,8 +1720,9 @@ discard block |
||
1653 | 1720 | // Send the attachment headers. |
1654 | 1721 | header('Pragma: '); |
1655 | 1722 | |
1656 | - if (!isBrowser('gecko')) |
|
1657 | - header('Content-Transfer-Encoding: binary'); |
|
1723 | + if (!isBrowser('gecko')) { |
|
1724 | + header('Content-Transfer-Encoding: binary'); |
|
1725 | + } |
|
1658 | 1726 | |
1659 | 1727 | header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT'); |
1660 | 1728 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filename)) . ' GMT'); |
@@ -1663,18 +1731,19 @@ discard block |
||
1663 | 1731 | header('ETag: ' . $eTag); |
1664 | 1732 | |
1665 | 1733 | // Make sure the mime type warrants an inline display. |
1666 | - if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0) |
|
1667 | - unset($_REQUEST['image']); |
|
1734 | + if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0) { |
|
1735 | + unset($_REQUEST['image']); |
|
1736 | + } |
|
1668 | 1737 | |
1669 | 1738 | // Does this have a mime type? |
1670 | - elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) |
|
1671 | - header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp'))); |
|
1672 | - |
|
1673 | - else |
|
1739 | + elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) { |
|
1740 | + header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp'))); |
|
1741 | + } else |
|
1674 | 1742 | { |
1675 | 1743 | header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream')); |
1676 | - if (isset($_REQUEST['image'])) |
|
1677 | - unset($_REQUEST['image']); |
|
1744 | + if (isset($_REQUEST['image'])) { |
|
1745 | + unset($_REQUEST['image']); |
|
1746 | + } |
|
1678 | 1747 | } |
1679 | 1748 | |
1680 | 1749 | // Convert the file to UTF-8, cuz most browsers dig that. |
@@ -1682,23 +1751,22 @@ discard block |
||
1682 | 1751 | $disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline'; |
1683 | 1752 | |
1684 | 1753 | // Different browsers like different standards... |
1685 | - if (isBrowser('firefox')) |
|
1686 | - header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
1687 | - |
|
1688 | - elseif (isBrowser('opera')) |
|
1689 | - header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
1690 | - |
|
1691 | - elseif (isBrowser('ie')) |
|
1692 | - header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
1693 | - |
|
1694 | - else |
|
1695 | - header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
1754 | + if (isBrowser('firefox')) { |
|
1755 | + header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
1756 | + } elseif (isBrowser('opera')) { |
|
1757 | + header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
1758 | + } elseif (isBrowser('ie')) { |
|
1759 | + header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
1760 | + } else { |
|
1761 | + header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
1762 | + } |
|
1696 | 1763 | |
1697 | 1764 | // If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE. |
1698 | - if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) |
|
1699 | - header('Cache-Control: no-cache'); |
|
1700 | - else |
|
1701 | - header('Cache-Control: max-age=' . (525600 * 60) . ', private'); |
|
1765 | + if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) { |
|
1766 | + header('Cache-Control: no-cache'); |
|
1767 | + } else { |
|
1768 | + header('Cache-Control: max-age=' . (525600 * 60) . ', private'); |
|
1769 | + } |
|
1702 | 1770 | |
1703 | 1771 | header('Content-Length: ' . filesize($filename)); |
1704 | 1772 | |
@@ -1708,20 +1776,23 @@ discard block |
||
1708 | 1776 | // Recode line endings for text files, if enabled. |
1709 | 1777 | if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file_ext, array('txt', 'css', 'htm', 'html', 'php', 'xml'))) |
1710 | 1778 | { |
1711 | - if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) |
|
1712 | - $callback = function ($buffer) |
|
1779 | + if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) { |
|
1780 | + $callback = function ($buffer) |
|
1713 | 1781 | { |
1714 | 1782 | return preg_replace('~[\r]?\n~', "\r\n", $buffer); |
1783 | + } |
|
1715 | 1784 | }; |
1716 | - elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) |
|
1717 | - $callback = function ($buffer) |
|
1785 | + elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) { |
|
1786 | + $callback = function ($buffer) |
|
1718 | 1787 | { |
1719 | 1788 | return preg_replace('~[\r]?\n~', "\r", $buffer); |
1789 | + } |
|
1720 | 1790 | }; |
1721 | - else |
|
1722 | - $callback = function ($buffer) |
|
1791 | + else { |
|
1792 | + $callback = function ($buffer) |
|
1723 | 1793 | { |
1724 | 1794 | return preg_replace('~[\r]?\n~', "\n", $buffer); |
1795 | + } |
|
1725 | 1796 | }; |
1726 | 1797 | } |
1727 | 1798 | |
@@ -1729,23 +1800,26 @@ discard block |
||
1729 | 1800 | if (filesize($filename) > 4194304) |
1730 | 1801 | { |
1731 | 1802 | // Forcibly end any output buffering going on. |
1732 | - while (@ob_get_level() > 0) |
|
1733 | - @ob_end_clean(); |
|
1803 | + while (@ob_get_level() > 0) { |
|
1804 | + @ob_end_clean(); |
|
1805 | + } |
|
1734 | 1806 | |
1735 | 1807 | $fp = fopen($filename, 'rb'); |
1736 | 1808 | while (!feof($fp)) |
1737 | 1809 | { |
1738 | - if (isset($callback)) |
|
1739 | - echo $callback(fread($fp, 8192)); |
|
1740 | - else |
|
1741 | - echo fread($fp, 8192); |
|
1810 | + if (isset($callback)) { |
|
1811 | + echo $callback(fread($fp, 8192)); |
|
1812 | + } else { |
|
1813 | + echo fread($fp, 8192); |
|
1814 | + } |
|
1742 | 1815 | flush(); |
1743 | 1816 | } |
1744 | 1817 | fclose($fp); |
1745 | 1818 | } |
1746 | 1819 | // On some of the less-bright hosts, readfile() is disabled. It's just a faster, more byte safe, version of what's in the if. |
1747 | - elseif (isset($callback) || @readfile($filename) === null) |
|
1748 | - echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename); |
|
1820 | + elseif (isset($callback) || @readfile($filename) === null) { |
|
1821 | + echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename); |
|
1822 | + } |
|
1749 | 1823 | |
1750 | 1824 | obExit(false); |
1751 | 1825 | } |
@@ -1758,8 +1832,9 @@ discard block |
||
1758 | 1832 | */ |
1759 | 1833 | function approved_attach_sort($a, $b) |
1760 | 1834 | { |
1761 | - if ($a['is_approved'] == $b['is_approved']) |
|
1762 | - return 0; |
|
1835 | + if ($a['is_approved'] == $b['is_approved']) { |
|
1836 | + return 0; |
|
1837 | + } |
|
1763 | 1838 | |
1764 | 1839 | return $a['is_approved'] > $b['is_approved'] ? -1 : 1; |
1765 | 1840 | } |
@@ -1776,16 +1851,19 @@ discard block |
||
1776 | 1851 | |
1777 | 1852 | require_once($sourcedir . '/RemoveTopic.php'); |
1778 | 1853 | |
1779 | - if (empty($_REQUEST['msgs'])) |
|
1780 | - redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
1854 | + if (empty($_REQUEST['msgs'])) { |
|
1855 | + redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
1856 | + } |
|
1781 | 1857 | |
1782 | 1858 | $messages = array(); |
1783 | - foreach ($_REQUEST['msgs'] as $dummy) |
|
1784 | - $messages[] = (int) $dummy; |
|
1859 | + foreach ($_REQUEST['msgs'] as $dummy) { |
|
1860 | + $messages[] = (int) $dummy; |
|
1861 | + } |
|
1785 | 1862 | |
1786 | 1863 | // We are restoring messages. We handle this in another place. |
1787 | - if (isset($_REQUEST['restore_selected'])) |
|
1788 | - redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1864 | + if (isset($_REQUEST['restore_selected'])) { |
|
1865 | + redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
1866 | + } |
|
1789 | 1867 | if (isset($_REQUEST['split_selection'])) |
1790 | 1868 | { |
1791 | 1869 | $request = $smcFunc['db_query']('', ' |
@@ -1804,8 +1882,9 @@ discard block |
||
1804 | 1882 | } |
1805 | 1883 | |
1806 | 1884 | // Allowed to delete any message? |
1807 | - if (allowedTo('delete_any')) |
|
1808 | - $allowed_all = true; |
|
1885 | + if (allowedTo('delete_any')) { |
|
1886 | + $allowed_all = true; |
|
1887 | + } |
|
1809 | 1888 | // Allowed to delete replies to their messages? |
1810 | 1889 | elseif (allowedTo('delete_replies')) |
1811 | 1890 | { |
@@ -1822,13 +1901,14 @@ discard block |
||
1822 | 1901 | $smcFunc['db_free_result']($request); |
1823 | 1902 | |
1824 | 1903 | $allowed_all = $starter == $user_info['id']; |
1904 | + } else { |
|
1905 | + $allowed_all = false; |
|
1825 | 1906 | } |
1826 | - else |
|
1827 | - $allowed_all = false; |
|
1828 | 1907 | |
1829 | 1908 | // Make sure they're allowed to delete their own messages, if not any. |
1830 | - if (!$allowed_all) |
|
1831 | - isAllowedTo('delete_own'); |
|
1909 | + if (!$allowed_all) { |
|
1910 | + isAllowedTo('delete_own'); |
|
1911 | + } |
|
1832 | 1912 | |
1833 | 1913 | // Allowed to remove which messages? |
1834 | 1914 | $request = $smcFunc['db_query']('', ' |
@@ -1848,8 +1928,9 @@ discard block |
||
1848 | 1928 | $messages = array(); |
1849 | 1929 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1850 | 1930 | { |
1851 | - if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) |
|
1852 | - continue; |
|
1931 | + if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) { |
|
1932 | + continue; |
|
1933 | + } |
|
1853 | 1934 | |
1854 | 1935 | $messages[$row['id_msg']] = array($row['subject'], $row['id_member']); |
1855 | 1936 | } |
@@ -1872,17 +1953,20 @@ discard block |
||
1872 | 1953 | foreach ($messages as $message => $info) |
1873 | 1954 | { |
1874 | 1955 | // Just skip the first message - if it's not the last. |
1875 | - if ($message == $first_message && $message != $last_message) |
|
1876 | - continue; |
|
1956 | + if ($message == $first_message && $message != $last_message) { |
|
1957 | + continue; |
|
1958 | + } |
|
1877 | 1959 | // If the first message is going then don't bother going back to the topic as we're effectively deleting it. |
1878 | - elseif ($message == $first_message) |
|
1879 | - $topicGone = true; |
|
1960 | + elseif ($message == $first_message) { |
|
1961 | + $topicGone = true; |
|
1962 | + } |
|
1880 | 1963 | |
1881 | 1964 | removeMessage($message); |
1882 | 1965 | |
1883 | 1966 | // Log this moderation action ;). |
1884 | - if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) |
|
1885 | - logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board)); |
|
1967 | + if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) { |
|
1968 | + logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board)); |
|
1969 | + } |
|
1886 | 1970 | } |
1887 | 1971 | |
1888 | 1972 | redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']); |
@@ -12,8 +12,9 @@ discard block |
||
12 | 12 | * @version 2.1 Beta 3 |
13 | 13 | */ |
14 | 14 | |
15 | -if (!defined('SMF')) |
|
15 | +if (!defined('SMF')) { |
|
16 | 16 | die('No direct access...'); |
17 | +} |
|
17 | 18 | |
18 | 19 | /** |
19 | 20 | * Create a new list |
@@ -41,21 +42,21 @@ discard block |
||
41 | 42 | { |
42 | 43 | $list_context['sort'] = array(); |
43 | 44 | $sort = '1=1'; |
44 | - } |
|
45 | - else |
|
45 | + } else |
|
46 | 46 | { |
47 | 47 | $request_var_sort = isset($listOptions['request_vars']['sort']) ? $listOptions['request_vars']['sort'] : 'sort'; |
48 | 48 | $request_var_desc = isset($listOptions['request_vars']['desc']) ? $listOptions['request_vars']['desc'] : 'desc'; |
49 | - if (isset($_REQUEST[$request_var_sort], $listOptions['columns'][$_REQUEST[$request_var_sort]], $listOptions['columns'][$_REQUEST[$request_var_sort]]['sort'])) |
|
50 | - $list_context['sort'] = array( |
|
49 | + if (isset($_REQUEST[$request_var_sort], $listOptions['columns'][$_REQUEST[$request_var_sort]], $listOptions['columns'][$_REQUEST[$request_var_sort]]['sort'])) { |
|
50 | + $list_context['sort'] = array( |
|
51 | 51 | 'id' => $_REQUEST[$request_var_sort], |
52 | 52 | 'desc' => isset($_REQUEST[$request_var_desc]) && isset($listOptions['columns'][$_REQUEST[$request_var_sort]]['sort']['reverse']), |
53 | 53 | ); |
54 | - else |
|
55 | - $list_context['sort'] = array( |
|
54 | + } else { |
|
55 | + $list_context['sort'] = array( |
|
56 | 56 | 'id' => $listOptions['default_sort_col'], |
57 | 57 | 'desc' => (!empty($listOptions['default_sort_dir']) && $listOptions['default_sort_dir'] == 'desc') || (!empty($listOptions['columns'][$listOptions['default_sort_col']]['sort']['default']) && substr($listOptions['columns'][$listOptions['default_sort_col']]['sort']['default'], -4, 4) == 'desc') ? true : false, |
58 | 58 | ); |
59 | + } |
|
59 | 60 | |
60 | 61 | // Set the database column sort. |
61 | 62 | $sort = $listOptions['columns'][$list_context['sort']['id']]['sort'][$list_context['sort']['desc'] ? 'reverse' : 'default']; |
@@ -72,8 +73,9 @@ discard block |
||
72 | 73 | else |
73 | 74 | { |
74 | 75 | // First get an impression of how many items to expect. |
75 | - if (isset($listOptions['get_count']['file'])) |
|
76 | - require_once($listOptions['get_count']['file']); |
|
76 | + if (isset($listOptions['get_count']['file'])) { |
|
77 | + require_once($listOptions['get_count']['file']); |
|
78 | + } |
|
77 | 79 | |
78 | 80 | $call = call_helper($listOptions['get_count']['function'], true); |
79 | 81 | $list_context['total_num_items'] = call_user_func_array($call, empty($listOptions['get_count']['params']) ? array() : $listOptions['get_count']['params']); |
@@ -83,14 +85,15 @@ discard block |
||
83 | 85 | $list_context['items_per_page'] = $listOptions['items_per_page']; |
84 | 86 | |
85 | 87 | // Then create a page index. |
86 | - if ($list_context['total_num_items'] > $list_context['items_per_page']) |
|
87 | - $list_context['page_index'] = constructPageIndex($listOptions['base_href'] . (empty($list_context['sort']) ? '' : ';' . $request_var_sort . '=' . $list_context['sort']['id'] . ($list_context['sort']['desc'] ? ';' . $request_var_desc : '')) . ($list_context['start_var_name'] != 'start' ? ';' . $list_context['start_var_name'] . '=%1$d' : ''), $list_context['start'], $list_context['total_num_items'], $list_context['items_per_page'], $list_context['start_var_name'] != 'start'); |
|
88 | + if ($list_context['total_num_items'] > $list_context['items_per_page']) { |
|
89 | + $list_context['page_index'] = constructPageIndex($listOptions['base_href'] . (empty($list_context['sort']) ? '' : ';' . $request_var_sort . '=' . $list_context['sort']['id'] . ($list_context['sort']['desc'] ? ';' . $request_var_desc : '')) . ($list_context['start_var_name'] != 'start' ? ';' . $list_context['start_var_name'] . '=%1$d' : ''), $list_context['start'], $list_context['total_num_items'], $list_context['items_per_page'], $list_context['start_var_name'] != 'start'); |
|
90 | + } |
|
88 | 91 | } |
89 | 92 | |
90 | 93 | // Prepare the headers of the table. |
91 | 94 | $list_context['headers'] = array(); |
92 | - foreach ($listOptions['columns'] as $column_id => $column) |
|
93 | - $list_context['headers'][] = array( |
|
95 | + foreach ($listOptions['columns'] as $column_id => $column) { |
|
96 | + $list_context['headers'][] = array( |
|
94 | 97 | 'id' => $column_id, |
95 | 98 | 'label' => isset($column['header']['eval']) ? eval($column['header']['eval']) : (isset($column['header']['value']) ? $column['header']['value'] : ''), |
96 | 99 | 'href' => empty($listOptions['default_sort_col']) || empty($column['sort']) ? '' : $listOptions['base_href'] . ';' . $request_var_sort . '=' . $column_id . ($column_id === $list_context['sort']['id'] && !$list_context['sort']['desc'] && isset($column['sort']['reverse']) ? ';' . $request_var_desc : '') . (empty($list_context['start']) ? '' : ';' . $list_context['start_var_name'] . '=' . $list_context['start']), |
@@ -99,14 +102,16 @@ discard block |
||
99 | 102 | 'style' => isset($column['header']['style']) ? $column['header']['style'] : '', |
100 | 103 | 'colspan' => isset($column['header']['colspan']) ? $column['header']['colspan'] : '', |
101 | 104 | ); |
105 | + } |
|
102 | 106 | |
103 | 107 | // We know the amount of columns, might be useful for the template. |
104 | 108 | $list_context['num_columns'] = count($listOptions['columns']); |
105 | 109 | $list_context['width'] = isset($listOptions['width']) ? $listOptions['width'] : '0'; |
106 | 110 | |
107 | 111 | // Get the file with the function for the item list. |
108 | - if (isset($listOptions['get_items']['file'])) |
|
109 | - require_once($listOptions['get_items']['file']); |
|
112 | + if (isset($listOptions['get_items']['file'])) { |
|
113 | + require_once($listOptions['get_items']['file']); |
|
114 | + } |
|
110 | 115 | |
111 | 116 | // Call the function and include which items we want and in what order. |
112 | 117 | $call = call_helper($listOptions['get_items']['function'], true); |
@@ -123,51 +128,61 @@ discard block |
||
123 | 128 | $cur_data = array(); |
124 | 129 | |
125 | 130 | // A value straight from the database? |
126 | - if (isset($column['data']['db'])) |
|
127 | - $cur_data['value'] = $list_item[$column['data']['db']]; |
|
131 | + if (isset($column['data']['db'])) { |
|
132 | + $cur_data['value'] = $list_item[$column['data']['db']]; |
|
133 | + } |
|
128 | 134 | |
129 | 135 | // Take the value from the database and make it HTML safe. |
130 | - elseif (isset($column['data']['db_htmlsafe'])) |
|
131 | - $cur_data['value'] = $smcFunc['htmlspecialchars']($list_item[$column['data']['db_htmlsafe']]); |
|
136 | + elseif (isset($column['data']['db_htmlsafe'])) { |
|
137 | + $cur_data['value'] = $smcFunc['htmlspecialchars']($list_item[$column['data']['db_htmlsafe']]); |
|
138 | + } |
|
132 | 139 | |
133 | 140 | // Using sprintf is probably the most readable way of injecting data. |
134 | 141 | elseif (isset($column['data']['sprintf'])) |
135 | 142 | { |
136 | 143 | $params = array(); |
137 | - foreach ($column['data']['sprintf']['params'] as $sprintf_param => $htmlsafe) |
|
138 | - $params[] = $htmlsafe ? $smcFunc['htmlspecialchars']($list_item[$sprintf_param]) : $list_item[$sprintf_param]; |
|
144 | + foreach ($column['data']['sprintf']['params'] as $sprintf_param => $htmlsafe) { |
|
145 | + $params[] = $htmlsafe ? $smcFunc['htmlspecialchars']($list_item[$sprintf_param]) : $list_item[$sprintf_param]; |
|
146 | + } |
|
139 | 147 | $cur_data['value'] = vsprintf($column['data']['sprintf']['format'], $params); |
140 | 148 | } |
141 | 149 | |
142 | 150 | // The most flexible way probably is applying a custom function. |
143 | - elseif (isset($column['data']['function'])) |
|
144 | - $cur_data['value'] = call_user_func_array($column['data']['function'], array($list_item)); |
|
151 | + elseif (isset($column['data']['function'])) { |
|
152 | + $cur_data['value'] = call_user_func_array($column['data']['function'], array($list_item)); |
|
153 | + } |
|
145 | 154 | |
146 | 155 | // A modified value (inject the database values). |
147 | - elseif (isset($column['data']['eval'])) |
|
148 | - $cur_data['value'] = eval(preg_replace('~%([a-zA-Z0-9\-_]+)%~', '$list_item[\'$1\']', $column['data']['eval'])); |
|
156 | + elseif (isset($column['data']['eval'])) { |
|
157 | + $cur_data['value'] = eval(preg_replace('~%([a-zA-Z0-9\-_]+)%~', '$list_item[\'$1\']', $column['data']['eval'])); |
|
158 | + } |
|
149 | 159 | |
150 | 160 | // A literal value. |
151 | - elseif (isset($column['data']['value'])) |
|
152 | - $cur_data['value'] = $column['data']['value']; |
|
161 | + elseif (isset($column['data']['value'])) { |
|
162 | + $cur_data['value'] = $column['data']['value']; |
|
163 | + } |
|
153 | 164 | |
154 | 165 | // Empty value. |
155 | - else |
|
156 | - $cur_data['value'] = ''; |
|
166 | + else { |
|
167 | + $cur_data['value'] = ''; |
|
168 | + } |
|
157 | 169 | |
158 | 170 | // Allow for basic formatting. |
159 | - if (!empty($column['data']['comma_format'])) |
|
160 | - $cur_data['value'] = comma_format($cur_data['value']); |
|
161 | - elseif (!empty($column['data']['timeformat'])) |
|
162 | - $cur_data['value'] = timeformat($cur_data['value']); |
|
171 | + if (!empty($column['data']['comma_format'])) { |
|
172 | + $cur_data['value'] = comma_format($cur_data['value']); |
|
173 | + } elseif (!empty($column['data']['timeformat'])) { |
|
174 | + $cur_data['value'] = timeformat($cur_data['value']); |
|
175 | + } |
|
163 | 176 | |
164 | 177 | // Set a style class for this column? |
165 | - if (isset($column['data']['class'])) |
|
166 | - $cur_data['class'] = $column['data']['class']; |
|
178 | + if (isset($column['data']['class'])) { |
|
179 | + $cur_data['class'] = $column['data']['class']; |
|
180 | + } |
|
167 | 181 | |
168 | 182 | // Fully customized styling for the cells in this column only. |
169 | - if (isset($column['data']['style'])) |
|
170 | - $cur_data['style'] = $column['data']['style']; |
|
183 | + if (isset($column['data']['style'])) { |
|
184 | + $cur_data['style'] = $column['data']['style']; |
|
185 | + } |
|
171 | 186 | |
172 | 187 | // Add the data cell properties to the current row. |
173 | 188 | $cur_row[$column_id] = $cur_data; |
@@ -176,10 +191,12 @@ discard block |
||
176 | 191 | // Maybe we wat set a custom class for the row based on the data in the row itself |
177 | 192 | if (isset($listOptions['data_check'])) |
178 | 193 | { |
179 | - if (isset($listOptions['data_check']['class'])) |
|
180 | - $list_context['rows'][$item_id]['class'] = $listOptions['data_check']['class']($list_item); |
|
181 | - if (isset($listOptions['data_check']['style'])) |
|
182 | - $list_context['rows'][$item_id]['style'] = $listOptions['data_check']['style']($list_item); |
|
194 | + if (isset($listOptions['data_check']['class'])) { |
|
195 | + $list_context['rows'][$item_id]['class'] = $listOptions['data_check']['class']($list_item); |
|
196 | + } |
|
197 | + if (isset($listOptions['data_check']['style'])) { |
|
198 | + $list_context['rows'][$item_id]['style'] = $listOptions['data_check']['style']($list_item); |
|
199 | + } |
|
183 | 200 | } |
184 | 201 | |
185 | 202 | // Insert the row into the list. |
@@ -187,34 +204,39 @@ discard block |
||
187 | 204 | } |
188 | 205 | |
189 | 206 | // The title is currently optional. |
190 | - if (isset($listOptions['title'])) |
|
191 | - $list_context['title'] = $listOptions['title']; |
|
207 | + if (isset($listOptions['title'])) { |
|
208 | + $list_context['title'] = $listOptions['title']; |
|
209 | + } |
|
192 | 210 | |
193 | 211 | // In case there's a form, share it with the template context. |
194 | 212 | if (isset($listOptions['form'])) |
195 | 213 | { |
196 | 214 | $list_context['form'] = $listOptions['form']; |
197 | 215 | |
198 | - if (!isset($list_context['form']['hidden_fields'])) |
|
199 | - $list_context['form']['hidden_fields'] = array(); |
|
216 | + if (!isset($list_context['form']['hidden_fields'])) { |
|
217 | + $list_context['form']['hidden_fields'] = array(); |
|
218 | + } |
|
200 | 219 | |
201 | 220 | // Always add a session check field. |
202 | 221 | $list_context['form']['hidden_fields'][$context['session_var']] = $context['session_id']; |
203 | 222 | |
204 | 223 | // Will this do a token check? |
205 | - if (isset($listOptions['form']['token'])) |
|
206 | - $list_context['form']['hidden_fields'][$context[$listOptions['form']['token'] . '_token_var']] = $context[$listOptions['form']['token'] . '_token']; |
|
224 | + if (isset($listOptions['form']['token'])) { |
|
225 | + $list_context['form']['hidden_fields'][$context[$listOptions['form']['token'] . '_token_var']] = $context[$listOptions['form']['token'] . '_token']; |
|
226 | + } |
|
207 | 227 | |
208 | 228 | // Include the starting page as hidden field? |
209 | - if (!empty($list_context['form']['include_start']) && !empty($list_context['start'])) |
|
210 | - $list_context['form']['hidden_fields'][$list_context['start_var_name']] = $list_context['start']; |
|
229 | + if (!empty($list_context['form']['include_start']) && !empty($list_context['start'])) { |
|
230 | + $list_context['form']['hidden_fields'][$list_context['start_var_name']] = $list_context['start']; |
|
231 | + } |
|
211 | 232 | |
212 | 233 | // If sorting needs to be the same after submitting, add the parameter. |
213 | 234 | if (!empty($list_context['form']['include_sort']) && !empty($list_context['sort'])) |
214 | 235 | { |
215 | 236 | $list_context['form']['hidden_fields']['sort'] = $list_context['sort']['id']; |
216 | - if ($list_context['sort']['desc']) |
|
217 | - $list_context['form']['hidden_fields']['desc'] = 1; |
|
237 | + if ($list_context['sort']['desc']) { |
|
238 | + $list_context['form']['hidden_fields']['desc'] = 1; |
|
239 | + } |
|
218 | 240 | } |
219 | 241 | } |
220 | 242 | |
@@ -231,24 +253,28 @@ discard block |
||
231 | 253 | $list_context['additional_rows'] = array(); |
232 | 254 | foreach ($listOptions['additional_rows'] as $row) |
233 | 255 | { |
234 | - if (empty($row)) |
|
235 | - continue; |
|
256 | + if (empty($row)) { |
|
257 | + continue; |
|
258 | + } |
|
236 | 259 | |
237 | 260 | // Supported row positions: top_of_list, after_title, |
238 | 261 | // above_column_headers, below_table_data, bottom_of_list. |
239 | - if (!isset($list_context['additional_rows'][$row['position']])) |
|
240 | - $list_context['additional_rows'][$row['position']] = array(); |
|
262 | + if (!isset($list_context['additional_rows'][$row['position']])) { |
|
263 | + $list_context['additional_rows'][$row['position']] = array(); |
|
264 | + } |
|
241 | 265 | $list_context['additional_rows'][$row['position']][] = $row; |
242 | 266 | } |
243 | 267 | } |
244 | 268 | |
245 | 269 | // Add an option for inline JavaScript. |
246 | - if (isset($listOptions['javascript'])) |
|
247 | - $list_context['javascript'] = $listOptions['javascript']; |
|
270 | + if (isset($listOptions['javascript'])) { |
|
271 | + $list_context['javascript'] = $listOptions['javascript']; |
|
272 | + } |
|
248 | 273 | |
249 | 274 | // We want a menu. |
250 | - if (isset($listOptions['list_menu'])) |
|
251 | - $list_context['list_menu'] = $listOptions['list_menu']; |
|
275 | + if (isset($listOptions['list_menu'])) { |
|
276 | + $list_context['list_menu'] = $listOptions['list_menu']; |
|
277 | + } |
|
252 | 278 | |
253 | 279 | // Make sure the template is loaded. |
254 | 280 | loadTemplate('GenericList'); |