@@ -49,30 +49,33 @@ discard block |
||
| 49 | 49 | $allowed = explode(',', $row['member_groups']); |
| 50 | 50 | |
| 51 | 51 | // If the user is in group 1 anywhere, they can see everything anyway. |
| 52 | - if (in_array(1, $groups) || count(array_intersect($allowed, $groups)) != 0) |
|
| 53 | - $author = $row['id_member']; |
|
| 52 | + if (in_array(1, $groups) || count(array_intersect($allowed, $groups)) != 0) { |
|
| 53 | + $author = $row['id_member']; |
|
| 54 | + } |
|
| 54 | 55 | } |
| 55 | 56 | $smcFunc['db_free_result']($request); |
| 56 | - } |
|
| 57 | - else |
|
| 57 | + } else |
|
| 58 | 58 | { |
| 59 | 59 | // This isn't something we know natively how to support. Call the hooks, if they're dealing with it, return false, otherwise return the user id. |
| 60 | 60 | $hook_results = call_integration_hook('integrate_find_like_author', array($this->_details['content_type'], $this->_details['content_id'])); |
| 61 | - foreach ($hook_results as $result) |
|
| 62 | - if (!empty($result)) |
|
| 61 | + foreach ($hook_results as $result) { |
|
| 62 | + if (!empty($result)) |
|
| 63 | 63 | { |
| 64 | 64 | $author = $result; |
| 65 | + } |
|
| 65 | 66 | break; |
| 66 | 67 | } |
| 67 | 68 | } |
| 68 | 69 | |
| 69 | 70 | // If we didn't have a member... leave. |
| 70 | - if (empty($author)) |
|
| 71 | - return true; |
|
| 71 | + if (empty($author)) { |
|
| 72 | + return true; |
|
| 73 | + } |
|
| 72 | 74 | |
| 73 | 75 | // If the person who sent the notification is the person whose content it is, do nothing. |
| 74 | - if ($author == $this->_details['sender_id']) |
|
| 75 | - return true; |
|
| 76 | + if ($author == $this->_details['sender_id']) { |
|
| 77 | + return true; |
|
| 78 | + } |
|
| 76 | 79 | |
| 77 | 80 | require_once($sourcedir . '/Subs-Notify.php'); |
| 78 | 81 | $prefs = getNotifyPrefs($author, $this->_details['content_type'] . '_like', true); |
@@ -81,8 +84,9 @@ discard block |
||
| 81 | 84 | // As a result, the value should really just be non empty. |
| 82 | 85 | |
| 83 | 86 | // Check the value. If no value or it's empty, they didn't want alerts, oh well. |
| 84 | - if (empty($prefs[$author][$this->_details['content_type'] . '_like'])) |
|
| 85 | - return true; |
|
| 87 | + if (empty($prefs[$author][$this->_details['content_type'] . '_like'])) { |
|
| 88 | + return true; |
|
| 89 | + } |
|
| 86 | 90 | |
| 87 | 91 | // Don't spam the alerts: if there is an existing unread alert of the |
| 88 | 92 | // requested type for the target user from the sender, don't make a new one. |
@@ -102,8 +106,9 @@ discard block |
||
| 102 | 106 | ) |
| 103 | 107 | ); |
| 104 | 108 | |
| 105 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
| 106 | - return true; |
|
| 109 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
| 110 | + return true; |
|
| 111 | + } |
|
| 107 | 112 | $smcFunc['db_free_result']($request); |
| 108 | 113 | |
| 109 | 114 | // Issue, update, move on. |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 3 |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -if (!defined('SMF')) |
|
| 18 | +if (!defined('SMF')) { |
|
| 19 | 19 | die('No direct access...'); |
| 20 | +} |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * This helps organize things... |
@@ -37,13 +38,14 @@ discard block |
||
| 37 | 38 | |
| 38 | 39 | loadLanguage('PersonalMessage+Drafts'); |
| 39 | 40 | |
| 40 | - if (!isset($_REQUEST['xml'])) |
|
| 41 | - loadTemplate('PersonalMessage'); |
|
| 41 | + if (!isset($_REQUEST['xml'])) { |
|
| 42 | + loadTemplate('PersonalMessage'); |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | // Load up the members maximum message capacity. |
| 44 | - if ($user_info['is_admin']) |
|
| 45 | - $context['message_limit'] = 0; |
|
| 46 | - elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null) |
|
| 46 | + if ($user_info['is_admin']) { |
|
| 47 | + $context['message_limit'] = 0; |
|
| 48 | + } elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null) |
|
| 47 | 49 | { |
| 48 | 50 | // @todo Why do we do this? It seems like if they have any limit we should use it. |
| 49 | 51 | $request = $smcFunc['db_query']('', ' |
@@ -78,8 +80,9 @@ discard block |
||
| 78 | 80 | } |
| 79 | 81 | |
| 80 | 82 | // a previous message was sent successfully? show a small indication. |
| 81 | - if (isset($_GET['done']) && ($_GET['done'] == 'sent')) |
|
| 82 | - $context['pm_sent'] = true; |
|
| 83 | + if (isset($_GET['done']) && ($_GET['done'] == 'sent')) { |
|
| 84 | + $context['pm_sent'] = true; |
|
| 85 | + } |
|
| 83 | 86 | |
| 84 | 87 | $context['labels'] = array(); |
| 85 | 88 | |
@@ -210,11 +213,11 @@ discard block |
||
| 210 | 213 | { |
| 211 | 214 | $_REQUEST['sa'] = ''; |
| 212 | 215 | MessageFolder(); |
| 213 | - } |
|
| 214 | - else |
|
| 216 | + } else |
|
| 215 | 217 | { |
| 216 | - if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup') |
|
| 217 | - messageIndexBar($_REQUEST['sa']); |
|
| 218 | + if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup') { |
|
| 219 | + messageIndexBar($_REQUEST['sa']); |
|
| 220 | + } |
|
| 218 | 221 | |
| 219 | 222 | call_helper($subActions[$_REQUEST['sa']]); |
| 220 | 223 | } |
@@ -291,16 +294,17 @@ discard block |
||
| 291 | 294 | ); |
| 292 | 295 | |
| 293 | 296 | // Handle labels. |
| 294 | - if (empty($context['currently_using_labels'])) |
|
| 295 | - unset($pm_areas['labels']); |
|
| 296 | - else |
|
| 297 | + if (empty($context['currently_using_labels'])) { |
|
| 298 | + unset($pm_areas['labels']); |
|
| 299 | + } else |
|
| 297 | 300 | { |
| 298 | 301 | // Note we send labels by id as it will have less problems in the querystring. |
| 299 | 302 | $unread_in_labels = 0; |
| 300 | 303 | foreach ($context['labels'] as $label) |
| 301 | 304 | { |
| 302 | - if ($label['id'] == -1) |
|
| 303 | - continue; |
|
| 305 | + if ($label['id'] == -1) { |
|
| 306 | + continue; |
|
| 307 | + } |
|
| 304 | 308 | |
| 305 | 309 | // Count the amount of unread items in labels. |
| 306 | 310 | $unread_in_labels += $label['unread_messages']; |
@@ -314,8 +318,9 @@ discard block |
||
| 314 | 318 | ); |
| 315 | 319 | } |
| 316 | 320 | |
| 317 | - if (!empty($unread_in_labels)) |
|
| 318 | - $pm_areas['labels']['title'] .= ' <span class="amt">' . $unread_in_labels . '</span>'; |
|
| 321 | + if (!empty($unread_in_labels)) { |
|
| 322 | + $pm_areas['labels']['title'] .= ' <span class="amt">' . $unread_in_labels . '</span>'; |
|
| 323 | + } |
|
| 319 | 324 | } |
| 320 | 325 | |
| 321 | 326 | $pm_areas['folders']['areas']['inbox']['unread_messages'] = &$context['labels'][-1]['unread_messages']; |
@@ -356,8 +361,9 @@ discard block |
||
| 356 | 361 | unset($pm_areas); |
| 357 | 362 | |
| 358 | 363 | // No menu means no access. |
| 359 | - if (!$pm_include_data && (!$user_info['is_guest'] || validateSession())) |
|
| 360 | - fatal_lang_error('no_access', false); |
|
| 364 | + if (!$pm_include_data && (!$user_info['is_guest'] || validateSession())) { |
|
| 365 | + fatal_lang_error('no_access', false); |
|
| 366 | + } |
|
| 361 | 367 | |
| 362 | 368 | // Make a note of the Unique ID for this menu. |
| 363 | 369 | $context['pm_menu_id'] = $context['max_menu_id']; |
@@ -368,9 +374,10 @@ discard block |
||
| 368 | 374 | $context['menu_item_selected'] = $current_area; |
| 369 | 375 | |
| 370 | 376 | // Set the template for this area and add the profile layer. |
| 371 | - if (!isset($_REQUEST['xml'])) |
|
| 372 | - $context['template_layers'][] = 'pm'; |
|
| 373 | -} |
|
| 377 | + if (!isset($_REQUEST['xml'])) { |
|
| 378 | + $context['template_layers'][] = 'pm'; |
|
| 379 | + } |
|
| 380 | + } |
|
| 374 | 381 | |
| 375 | 382 | /** |
| 376 | 383 | * The popup for when we ask for the popup from the user. |
@@ -402,8 +409,9 @@ discard block |
||
| 402 | 409 | ) |
| 403 | 410 | ); |
| 404 | 411 | $pms = array(); |
| 405 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 406 | - $pms[] = $row[0]; |
|
| 412 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 413 | + $pms[] = $row[0]; |
|
| 414 | + } |
|
| 407 | 415 | $smcFunc['db_free_result']($request); |
| 408 | 416 | |
| 409 | 417 | if (!empty($pms)) |
@@ -431,8 +439,9 @@ discard block |
||
| 431 | 439 | ); |
| 432 | 440 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 433 | 441 | { |
| 434 | - if (!empty($row['id_member_from'])) |
|
| 435 | - $senders[] = $row['id_member_from']; |
|
| 442 | + if (!empty($row['id_member_from'])) { |
|
| 443 | + $senders[] = $row['id_member_from']; |
|
| 444 | + } |
|
| 436 | 445 | |
| 437 | 446 | $row['replied_to_you'] = $row['id_pm'] != $row['id_pm_head']; |
| 438 | 447 | $row['time'] = timeformat($row['timestamp']); |
@@ -442,13 +451,15 @@ discard block |
||
| 442 | 451 | $smcFunc['db_free_result']($request); |
| 443 | 452 | |
| 444 | 453 | $senders = loadMemberData($senders); |
| 445 | - foreach ($senders as $member) |
|
| 446 | - loadMemberContext($member); |
|
| 454 | + foreach ($senders as $member) { |
|
| 455 | + loadMemberContext($member); |
|
| 456 | + } |
|
| 447 | 457 | |
| 448 | 458 | // Having loaded everyone, attach them to the PMs. |
| 449 | - foreach ($context['unread_pms'] as $id_pm => $details) |
|
| 450 | - if (!empty($memberContext[$details['id_member_from']])) |
|
| 459 | + foreach ($context['unread_pms'] as $id_pm => $details) { |
|
| 460 | + if (!empty($memberContext[$details['id_member_from']])) |
|
| 451 | 461 | $context['unread_pms'][$id_pm]['member'] = &$memberContext[$details['id_member_from']]; |
| 462 | + } |
|
| 452 | 463 | } |
| 453 | 464 | } |
| 454 | 465 | |
@@ -468,12 +479,13 @@ discard block |
||
| 468 | 479 | } |
| 469 | 480 | |
| 470 | 481 | // Make sure the starting location is valid. |
| 471 | - if (isset($_GET['start']) && $_GET['start'] != 'new') |
|
| 472 | - $_GET['start'] = (int) $_GET['start']; |
|
| 473 | - elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first'])) |
|
| 474 | - $_GET['start'] = 0; |
|
| 475 | - else |
|
| 476 | - $_GET['start'] = 'new'; |
|
| 482 | + if (isset($_GET['start']) && $_GET['start'] != 'new') { |
|
| 483 | + $_GET['start'] = (int) $_GET['start']; |
|
| 484 | + } elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first'])) { |
|
| 485 | + $_GET['start'] = 0; |
|
| 486 | + } else { |
|
| 487 | + $_GET['start'] = 'new'; |
|
| 488 | + } |
|
| 477 | 489 | |
| 478 | 490 | // Set up some basic theme stuff. |
| 479 | 491 | $context['from_or_to'] = $context['folder'] != 'sent' ? 'from' : 'to'; |
@@ -490,8 +502,7 @@ discard block |
||
| 490 | 502 | { |
| 491 | 503 | $labelQuery = ' |
| 492 | 504 | AND pmr.in_inbox = 1'; |
| 493 | - } |
|
| 494 | - elseif ($context['folder'] != 'sent') |
|
| 505 | + } elseif ($context['folder'] != 'sent') |
|
| 495 | 506 | { |
| 496 | 507 | $labelJoin = ' |
| 497 | 508 | INNER JOIN {db_prefix}pm_labeled_messages AS pl ON (pl.id_pm = pmr.id_pm)'; |
@@ -533,22 +544,24 @@ discard block |
||
| 533 | 544 | $txt['delete_all'] = str_replace('PMBOX', $pmbox, $txt['delete_all']); |
| 534 | 545 | |
| 535 | 546 | // Now, build the link tree! |
| 536 | - if ($context['current_label_id'] == -1) |
|
| 537 | - $context['linktree'][] = array( |
|
| 547 | + if ($context['current_label_id'] == -1) { |
|
| 548 | + $context['linktree'][] = array( |
|
| 538 | 549 | 'url' => $scripturl . '?action=pm;f=' . $context['folder'], |
| 539 | 550 | 'name' => $pmbox |
| 540 | 551 | ); |
| 552 | + } |
|
| 541 | 553 | |
| 542 | 554 | // Build it further for a label. |
| 543 | - if ($context['current_label_id'] != -1) |
|
| 544 | - $context['linktree'][] = array( |
|
| 555 | + if ($context['current_label_id'] != -1) { |
|
| 556 | + $context['linktree'][] = array( |
|
| 545 | 557 | 'url' => $scripturl . '?action=pm;f=' . $context['folder'] . ';l=' . $context['current_label_id'], |
| 546 | 558 | 'name' => $txt['pm_current_label'] . ': ' . $context['current_label'] |
| 547 | 559 | ); |
| 560 | + } |
|
| 548 | 561 | |
| 549 | 562 | // Figure out how many messages there are. |
| 550 | - if ($context['folder'] == 'sent') |
|
| 551 | - $request = $smcFunc['db_query']('', ' |
|
| 563 | + if ($context['folder'] == 'sent') { |
|
| 564 | + $request = $smcFunc['db_query']('', ' |
|
| 552 | 565 | SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') |
| 553 | 566 | FROM {db_prefix}personal_messages AS pm |
| 554 | 567 | WHERE pm.id_member_from = {int:current_member} |
@@ -558,8 +571,8 @@ discard block |
||
| 558 | 571 | 'not_deleted' => 0, |
| 559 | 572 | ) |
| 560 | 573 | ); |
| 561 | - else |
|
| 562 | - $request = $smcFunc['db_query']('', ' |
|
| 574 | + } else { |
|
| 575 | + $request = $smcFunc['db_query']('', ' |
|
| 563 | 576 | SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') |
| 564 | 577 | FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? ' |
| 565 | 578 | INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . ' |
@@ -570,6 +583,7 @@ discard block |
||
| 570 | 583 | 'not_deleted' => 0, |
| 571 | 584 | ) |
| 572 | 585 | ); |
| 586 | + } |
|
| 573 | 587 | list ($max_messages) = $smcFunc['db_fetch_row']($request); |
| 574 | 588 | $smcFunc['db_free_result']($request); |
| 575 | 589 | |
@@ -578,10 +592,11 @@ discard block |
||
| 578 | 592 | $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
| 579 | 593 | |
| 580 | 594 | // Start on the last page. |
| 581 | - if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages) |
|
| 582 | - $_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage); |
|
| 583 | - elseif ($_GET['start'] < 0) |
|
| 584 | - $_GET['start'] = 0; |
|
| 595 | + if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages) { |
|
| 596 | + $_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage); |
|
| 597 | + } elseif ($_GET['start'] < 0) { |
|
| 598 | + $_GET['start'] = 0; |
|
| 599 | + } |
|
| 585 | 600 | |
| 586 | 601 | // ... but wait - what if we want to start from a specific message? |
| 587 | 602 | if (isset($_GET['pmid'])) |
@@ -589,19 +604,21 @@ discard block |
||
| 589 | 604 | $pmID = (int) $_GET['pmid']; |
| 590 | 605 | |
| 591 | 606 | // Make sure you have access to this PM. |
| 592 | - if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) |
|
| 593 | - fatal_lang_error('no_access', false); |
|
| 607 | + if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) { |
|
| 608 | + fatal_lang_error('no_access', false); |
|
| 609 | + } |
|
| 594 | 610 | |
| 595 | 611 | $context['current_pm'] = $pmID; |
| 596 | 612 | |
| 597 | 613 | // With only one page of PM's we're gonna want page 1. |
| 598 | - if ($max_messages <= $maxPerPage) |
|
| 599 | - $_GET['start'] = 0; |
|
| 614 | + if ($max_messages <= $maxPerPage) { |
|
| 615 | + $_GET['start'] = 0; |
|
| 616 | + } |
|
| 600 | 617 | // If we pass kstart we assume we're in the right place. |
| 601 | 618 | elseif (!isset($_GET['kstart'])) |
| 602 | 619 | { |
| 603 | - if ($context['folder'] == 'sent') |
|
| 604 | - $request = $smcFunc['db_query']('', ' |
|
| 620 | + if ($context['folder'] == 'sent') { |
|
| 621 | + $request = $smcFunc['db_query']('', ' |
|
| 605 | 622 | SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') |
| 606 | 623 | FROM {db_prefix}personal_messages |
| 607 | 624 | WHERE id_member_from = {int:current_member} |
@@ -613,8 +630,8 @@ discard block |
||
| 613 | 630 | 'id_pm' => $pmID, |
| 614 | 631 | ) |
| 615 | 632 | ); |
| 616 | - else |
|
| 617 | - $request = $smcFunc['db_query']('', ' |
|
| 633 | + } else { |
|
| 634 | + $request = $smcFunc['db_query']('', ' |
|
| 618 | 635 | SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ') |
| 619 | 636 | FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? ' |
| 620 | 637 | INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . ' |
@@ -627,6 +644,7 @@ discard block |
||
| 627 | 644 | 'id_pm' => $pmID, |
| 628 | 645 | ) |
| 629 | 646 | ); |
| 647 | + } |
|
| 630 | 648 | |
| 631 | 649 | list ($_GET['start']) = $smcFunc['db_fetch_row']($request); |
| 632 | 650 | $smcFunc['db_free_result']($request); |
@@ -641,8 +659,9 @@ discard block |
||
| 641 | 659 | { |
| 642 | 660 | $pmsg = (int) $_GET['pmsg']; |
| 643 | 661 | |
| 644 | - if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) |
|
| 645 | - fatal_lang_error('no_access', false); |
|
| 662 | + if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) { |
|
| 663 | + fatal_lang_error('no_access', false); |
|
| 664 | + } |
|
| 646 | 665 | } |
| 647 | 666 | |
| 648 | 667 | // Set up the page index. |
@@ -737,8 +756,9 @@ discard block |
||
| 737 | 756 | { |
| 738 | 757 | if (!isset($recipients[$row['id_pm']])) |
| 739 | 758 | { |
| 740 | - if (isset($row['id_member_from'])) |
|
| 741 | - $posters[$row['id_pm']] = $row['id_member_from']; |
|
| 759 | + if (isset($row['id_member_from'])) { |
|
| 760 | + $posters[$row['id_pm']] = $row['id_member_from']; |
|
| 761 | + } |
|
| 742 | 762 | $pms[$row['id_pm']] = $row['id_pm']; |
| 743 | 763 | $recipients[$row['id_pm']] = array( |
| 744 | 764 | 'to' => array(), |
@@ -747,29 +767,33 @@ discard block |
||
| 747 | 767 | } |
| 748 | 768 | |
| 749 | 769 | // Keep track of the last message so we know what the head is without another query! |
| 750 | - if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm'])) |
|
| 751 | - $lastData = array( |
|
| 770 | + if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm'])) { |
|
| 771 | + $lastData = array( |
|
| 752 | 772 | 'id' => $row['id_pm'], |
| 753 | 773 | 'head' => $row['id_pm_head'], |
| 754 | 774 | ); |
| 775 | + } |
|
| 755 | 776 | } |
| 756 | 777 | $smcFunc['db_free_result']($request); |
| 757 | 778 | |
| 758 | 779 | // Make sure that we have been given a correct head pm id! |
| 759 | - if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id']) |
|
| 760 | - fatal_lang_error('no_access', false); |
|
| 780 | + if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id']) { |
|
| 781 | + fatal_lang_error('no_access', false); |
|
| 782 | + } |
|
| 761 | 783 | |
| 762 | 784 | if (!empty($pms)) |
| 763 | 785 | { |
| 764 | 786 | // Select the correct current message. |
| 765 | - if (empty($pmID)) |
|
| 766 | - $context['current_pm'] = $lastData['id']; |
|
| 787 | + if (empty($pmID)) { |
|
| 788 | + $context['current_pm'] = $lastData['id']; |
|
| 789 | + } |
|
| 767 | 790 | |
| 768 | 791 | // This is a list of the pm's that are used for "full" display. |
| 769 | - if ($context['display_mode'] == 0) |
|
| 770 | - $display_pms = $pms; |
|
| 771 | - else |
|
| 772 | - $display_pms = array($context['current_pm']); |
|
| 792 | + if ($context['display_mode'] == 0) { |
|
| 793 | + $display_pms = $pms; |
|
| 794 | + } else { |
|
| 795 | + $display_pms = array($context['current_pm']); |
|
| 796 | + } |
|
| 773 | 797 | |
| 774 | 798 | // At this point we know the main id_pm's. But - if we are looking at conversations we need the others! |
| 775 | 799 | if ($context['display_mode'] == 2) |
@@ -791,16 +815,18 @@ discard block |
||
| 791 | 815 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 792 | 816 | { |
| 793 | 817 | // This is, frankly, a joke. We will put in a workaround for people sending to themselves - yawn! |
| 794 | - if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1) |
|
| 795 | - continue; |
|
| 796 | - elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1) |
|
| 797 | - continue; |
|
| 818 | + if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1) { |
|
| 819 | + continue; |
|
| 820 | + } elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1) { |
|
| 821 | + continue; |
|
| 822 | + } |
|
| 798 | 823 | |
| 799 | - if (!isset($recipients[$row['id_pm']])) |
|
| 800 | - $recipients[$row['id_pm']] = array( |
|
| 824 | + if (!isset($recipients[$row['id_pm']])) { |
|
| 825 | + $recipients[$row['id_pm']] = array( |
|
| 801 | 826 | 'to' => array(), |
| 802 | 827 | 'bcc' => array() |
| 803 | 828 | ); |
| 829 | + } |
|
| 804 | 830 | $display_pms[] = $row['id_pm']; |
| 805 | 831 | $posters[$row['id_pm']] = $row['id_member_from']; |
| 806 | 832 | } |
@@ -851,8 +877,9 @@ discard block |
||
| 851 | 877 | while($row2 = $smcFunc['db_fetch_assoc']($request2)) |
| 852 | 878 | { |
| 853 | 879 | $l_id = $row2['id_label']; |
| 854 | - if (isset($context['labels'][$l_id])) |
|
| 855 | - $context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); |
|
| 880 | + if (isset($context['labels'][$l_id])) { |
|
| 881 | + $context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); |
|
| 882 | + } |
|
| 856 | 883 | } |
| 857 | 884 | |
| 858 | 885 | $smcFunc['db_free_result']($request2); |
@@ -869,9 +896,10 @@ discard block |
||
| 869 | 896 | // Make sure we don't load unnecessary data. |
| 870 | 897 | if ($context['display_mode'] == 1) |
| 871 | 898 | { |
| 872 | - foreach ($posters as $k => $v) |
|
| 873 | - if (!in_array($k, $display_pms)) |
|
| 899 | + foreach ($posters as $k => $v) { |
|
| 900 | + if (!in_array($k, $display_pms)) |
|
| 874 | 901 | unset($posters[$k]); |
| 902 | + } |
|
| 875 | 903 | } |
| 876 | 904 | |
| 877 | 905 | // Load any users.... |
@@ -882,8 +910,9 @@ discard block |
||
| 882 | 910 | { |
| 883 | 911 | // Get the order right. |
| 884 | 912 | $orderBy = array(); |
| 885 | - foreach (array_reverse($pms) as $pm) |
|
| 886 | - $orderBy[] = 'pm.id_pm = ' . $pm; |
|
| 913 | + foreach (array_reverse($pms) as $pm) { |
|
| 914 | + $orderBy[] = 'pm.id_pm = ' . $pm; |
|
| 915 | + } |
|
| 887 | 916 | |
| 888 | 917 | // Seperate query for these bits! |
| 889 | 918 | $subjects_request = $smcFunc['db_query']('', ' |
@@ -929,9 +958,9 @@ discard block |
||
| 929 | 958 | // Allow mods to add additional buttons here |
| 930 | 959 | call_integration_hook('integrate_conversation_buttons'); |
| 931 | 960 | } |
| 961 | + } else { |
|
| 962 | + $messages_request = false; |
|
| 932 | 963 | } |
| 933 | - else |
|
| 934 | - $messages_request = false; |
|
| 935 | 964 | |
| 936 | 965 | $context['can_send_pm'] = allowedTo('pm_send'); |
| 937 | 966 | $context['can_send_email'] = allowedTo('moderate_forum'); |
@@ -942,11 +971,13 @@ discard block |
||
| 942 | 971 | if ($context['folder'] != 'sent' && !empty($context['labels'][(int) $context['current_label_id']]['unread_messages'])) |
| 943 | 972 | { |
| 944 | 973 | // If the display mode is "old sk00l" do them all... |
| 945 | - if ($context['display_mode'] == 0) |
|
| 946 | - markMessages(null, $context['current_label_id']); |
|
| 974 | + if ($context['display_mode'] == 0) { |
|
| 975 | + markMessages(null, $context['current_label_id']); |
|
| 976 | + } |
|
| 947 | 977 | // Otherwise do just the current one! |
| 948 | - elseif (!empty($context['current_pm'])) |
|
| 949 | - markMessages($display_pms, $context['current_label_id']); |
|
| 978 | + elseif (!empty($context['current_pm'])) { |
|
| 979 | + markMessages($display_pms, $context['current_label_id']); |
|
| 980 | + } |
|
| 950 | 981 | } |
| 951 | 982 | } |
| 952 | 983 | |
@@ -964,8 +995,9 @@ discard block |
||
| 964 | 995 | |
| 965 | 996 | // Count the current message number.... |
| 966 | 997 | static $counter = null; |
| 967 | - if ($counter === null || $reset) |
|
| 968 | - $counter = $context['start']; |
|
| 998 | + if ($counter === null || $reset) { |
|
| 999 | + $counter = $context['start']; |
|
| 1000 | + } |
|
| 969 | 1001 | |
| 970 | 1002 | static $temp_pm_selected = null; |
| 971 | 1003 | if ($temp_pm_selected === null) |
@@ -1010,19 +1042,22 @@ discard block |
||
| 1010 | 1042 | } |
| 1011 | 1043 | |
| 1012 | 1044 | // Bail if it's false, ie. no messages. |
| 1013 | - if ($messages_request == false) |
|
| 1014 | - return false; |
|
| 1045 | + if ($messages_request == false) { |
|
| 1046 | + return false; |
|
| 1047 | + } |
|
| 1015 | 1048 | |
| 1016 | 1049 | // Reset the data? |
| 1017 | - if ($reset == true) |
|
| 1018 | - return @$smcFunc['db_data_seek']($messages_request, 0); |
|
| 1050 | + if ($reset == true) { |
|
| 1051 | + return @$smcFunc['db_data_seek']($messages_request, 0); |
|
| 1052 | + } |
|
| 1019 | 1053 | |
| 1020 | 1054 | // Get the next one... bail if anything goes wrong. |
| 1021 | 1055 | $message = $smcFunc['db_fetch_assoc']($messages_request); |
| 1022 | 1056 | if (!$message) |
| 1023 | 1057 | { |
| 1024 | - if ($type != 'subject') |
|
| 1025 | - $smcFunc['db_free_result']($messages_request); |
|
| 1058 | + if ($type != 'subject') { |
|
| 1059 | + $smcFunc['db_free_result']($messages_request); |
|
| 1060 | + } |
|
| 1026 | 1061 | |
| 1027 | 1062 | return false; |
| 1028 | 1063 | } |
@@ -1042,8 +1077,7 @@ discard block |
||
| 1042 | 1077 | $memberContext[$message['id_member_from']]['email'] = ''; |
| 1043 | 1078 | $memberContext[$message['id_member_from']]['show_email'] = false; |
| 1044 | 1079 | $memberContext[$message['id_member_from']]['is_guest'] = true; |
| 1045 | - } |
|
| 1046 | - else |
|
| 1080 | + } else |
|
| 1047 | 1081 | { |
| 1048 | 1082 | $memberContext[$message['id_member_from']]['can_view_profile'] = allowedTo('profile_view') || ($message['id_member_from'] == $user_info['id'] && !$user_info['is_guest']); |
| 1049 | 1083 | $memberContext[$message['id_member_from']]['can_see_warning'] = !isset($context['disabled_fields']['warning_status']) && $memberContext[$message['id_member_from']]['warning_status'] && ($context['user']['can_mod'] || (!empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $message['id_member_from'] == $user_info['id']))); |
@@ -1084,12 +1118,13 @@ discard block |
||
| 1084 | 1118 | $counter++; |
| 1085 | 1119 | |
| 1086 | 1120 | // Any custom profile fields? |
| 1087 | - if (!empty($memberContext[$message['id_member_from']]['custom_fields'])) |
|
| 1088 | - foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom) |
|
| 1121 | + if (!empty($memberContext[$message['id_member_from']]['custom_fields'])) { |
|
| 1122 | + foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom) |
|
| 1089 | 1123 | switch ($custom['placement']) |
| 1090 | 1124 | { |
| 1091 | 1125 | case 1: |
| 1092 | 1126 | $output['custom_fields']['icons'][] = $custom; |
| 1127 | + } |
|
| 1093 | 1128 | break; |
| 1094 | 1129 | case 2: |
| 1095 | 1130 | $output['custom_fields']['above_signature'][] = $custom; |
@@ -1132,22 +1167,28 @@ discard block |
||
| 1132 | 1167 | $context['search_params'][$k] = $v; |
| 1133 | 1168 | } |
| 1134 | 1169 | } |
| 1135 | - if (isset($_REQUEST['search'])) |
|
| 1136 | - $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']); |
|
| 1170 | + if (isset($_REQUEST['search'])) { |
|
| 1171 | + $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']); |
|
| 1172 | + } |
|
| 1137 | 1173 | |
| 1138 | - if (isset($context['search_params']['search'])) |
|
| 1139 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
| 1140 | - if (isset($context['search_params']['userspec'])) |
|
| 1141 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
| 1174 | + if (isset($context['search_params']['search'])) { |
|
| 1175 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
| 1176 | + } |
|
| 1177 | + if (isset($context['search_params']['userspec'])) { |
|
| 1178 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
| 1179 | + } |
|
| 1142 | 1180 | |
| 1143 | - if (!empty($context['search_params']['searchtype'])) |
|
| 1144 | - $context['search_params']['searchtype'] = 2; |
|
| 1181 | + if (!empty($context['search_params']['searchtype'])) { |
|
| 1182 | + $context['search_params']['searchtype'] = 2; |
|
| 1183 | + } |
|
| 1145 | 1184 | |
| 1146 | - if (!empty($context['search_params']['minage'])) |
|
| 1147 | - $context['search_params']['minage'] = (int) $context['search_params']['minage']; |
|
| 1185 | + if (!empty($context['search_params']['minage'])) { |
|
| 1186 | + $context['search_params']['minage'] = (int) $context['search_params']['minage']; |
|
| 1187 | + } |
|
| 1148 | 1188 | |
| 1149 | - if (!empty($context['search_params']['maxage'])) |
|
| 1150 | - $context['search_params']['maxage'] = (int) $context['search_params']['maxage']; |
|
| 1189 | + if (!empty($context['search_params']['maxage'])) { |
|
| 1190 | + $context['search_params']['maxage'] = (int) $context['search_params']['maxage']; |
|
| 1191 | + } |
|
| 1151 | 1192 | |
| 1152 | 1193 | $context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']); |
| 1153 | 1194 | $context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']); |
@@ -1174,8 +1215,9 @@ discard block |
||
| 1174 | 1215 | $context['search_errors']['messages'] = array(); |
| 1175 | 1216 | foreach ($context['search_errors'] as $search_error => $dummy) |
| 1176 | 1217 | { |
| 1177 | - if ($search_error == 'messages') |
|
| 1178 | - continue; |
|
| 1218 | + if ($search_error == 'messages') { |
|
| 1219 | + continue; |
|
| 1220 | + } |
|
| 1179 | 1221 | |
| 1180 | 1222 | $context['search_errors']['messages'][] = $txt['error_' . $search_error]; |
| 1181 | 1223 | } |
@@ -1197,8 +1239,9 @@ discard block |
||
| 1197 | 1239 | global $scripturl, $modSettings, $user_info, $context, $txt; |
| 1198 | 1240 | global $memberContext, $smcFunc; |
| 1199 | 1241 | |
| 1200 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) |
|
| 1201 | - fatal_lang_error('loadavg_search_disabled', false); |
|
| 1242 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) { |
|
| 1243 | + fatal_lang_error('loadavg_search_disabled', false); |
|
| 1244 | + } |
|
| 1202 | 1245 | |
| 1203 | 1246 | /** |
| 1204 | 1247 | * @todo For the moment force the folder to the inbox. |
@@ -1227,35 +1270,40 @@ discard block |
||
| 1227 | 1270 | $context['start'] = isset($_GET['start']) ? (int) $_GET['start'] : 0; |
| 1228 | 1271 | |
| 1229 | 1272 | // Store whether simple search was used (needed if the user wants to do another query). |
| 1230 | - if (!isset($search_params['advanced'])) |
|
| 1231 | - $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1; |
|
| 1273 | + if (!isset($search_params['advanced'])) { |
|
| 1274 | + $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1; |
|
| 1275 | + } |
|
| 1232 | 1276 | |
| 1233 | 1277 | // 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'. |
| 1234 | - if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) |
|
| 1235 | - $search_params['searchtype'] = 2; |
|
| 1278 | + if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) { |
|
| 1279 | + $search_params['searchtype'] = 2; |
|
| 1280 | + } |
|
| 1236 | 1281 | |
| 1237 | 1282 | // Minimum age of messages. Default to zero (don't set param in that case). |
| 1238 | - if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) |
|
| 1239 | - $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage']; |
|
| 1283 | + if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) { |
|
| 1284 | + $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage']; |
|
| 1285 | + } |
|
| 1240 | 1286 | |
| 1241 | 1287 | // Maximum age of messages. Default to infinite (9999 days: param not set). |
| 1242 | - if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999)) |
|
| 1243 | - $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage']; |
|
| 1288 | + if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999)) { |
|
| 1289 | + $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage']; |
|
| 1290 | + } |
|
| 1244 | 1291 | |
| 1245 | 1292 | $search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']); |
| 1246 | 1293 | $search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']); |
| 1247 | 1294 | |
| 1248 | 1295 | // Default the user name to a wildcard matching every user (*). |
| 1249 | - if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) |
|
| 1250 | - $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec']; |
|
| 1296 | + if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) { |
|
| 1297 | + $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec']; |
|
| 1298 | + } |
|
| 1251 | 1299 | |
| 1252 | 1300 | // This will be full of all kinds of parameters! |
| 1253 | 1301 | $searchq_parameters = array(); |
| 1254 | 1302 | |
| 1255 | 1303 | // If there's no specific user, then don't mention it in the main query. |
| 1256 | - if (empty($search_params['userspec'])) |
|
| 1257 | - $userQuery = ''; |
|
| 1258 | - else |
|
| 1304 | + if (empty($search_params['userspec'])) { |
|
| 1305 | + $userQuery = ''; |
|
| 1306 | + } else |
|
| 1259 | 1307 | { |
| 1260 | 1308 | $userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('"' => '"')); |
| 1261 | 1309 | $userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')); |
@@ -1267,8 +1315,9 @@ discard block |
||
| 1267 | 1315 | { |
| 1268 | 1316 | $possible_users[$k] = trim($possible_users[$k]); |
| 1269 | 1317 | |
| 1270 | - if (strlen($possible_users[$k]) == 0) |
|
| 1271 | - unset($possible_users[$k]); |
|
| 1318 | + if (strlen($possible_users[$k]) == 0) { |
|
| 1319 | + unset($possible_users[$k]); |
|
| 1320 | + } |
|
| 1272 | 1321 | } |
| 1273 | 1322 | |
| 1274 | 1323 | if (!empty($possible_users)) |
@@ -1280,8 +1329,9 @@ discard block |
||
| 1280 | 1329 | { |
| 1281 | 1330 | $where_params['name_' . $k] = $v; |
| 1282 | 1331 | $where_clause[] = '{raw:real_name} LIKE {string:name_' . $k . '}'; |
| 1283 | - if (!isset($where_params['real_name'])) |
|
| 1284 | - $where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name'; |
|
| 1332 | + if (!isset($where_params['real_name'])) { |
|
| 1333 | + $where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name'; |
|
| 1334 | + } |
|
| 1285 | 1335 | } |
| 1286 | 1336 | |
| 1287 | 1337 | // Who matches those criteria? |
@@ -1294,28 +1344,28 @@ discard block |
||
| 1294 | 1344 | ); |
| 1295 | 1345 | |
| 1296 | 1346 | // Simply do nothing if there're too many members matching the criteria. |
| 1297 | - if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) |
|
| 1298 | - $userQuery = ''; |
|
| 1299 | - elseif ($smcFunc['db_num_rows']($request) == 0) |
|
| 1347 | + if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) { |
|
| 1348 | + $userQuery = ''; |
|
| 1349 | + } elseif ($smcFunc['db_num_rows']($request) == 0) |
|
| 1300 | 1350 | { |
| 1301 | 1351 | $userQuery = 'AND pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})'; |
| 1302 | 1352 | $searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\''; |
| 1303 | 1353 | $searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name'; |
| 1304 | - } |
|
| 1305 | - else |
|
| 1354 | + } else |
|
| 1306 | 1355 | { |
| 1307 | 1356 | $memberlist = array(); |
| 1308 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1309 | - $memberlist[] = $row['id_member']; |
|
| 1357 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1358 | + $memberlist[] = $row['id_member']; |
|
| 1359 | + } |
|
| 1310 | 1360 | $userQuery = 'AND (pm.id_member_from IN ({array_int:member_list}) OR (pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})))'; |
| 1311 | 1361 | $searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\''; |
| 1312 | 1362 | $searchq_parameters['member_list'] = $memberlist; |
| 1313 | 1363 | $searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name'; |
| 1314 | 1364 | } |
| 1315 | 1365 | $smcFunc['db_free_result']($request); |
| 1366 | + } else { |
|
| 1367 | + $userQuery = ''; |
|
| 1316 | 1368 | } |
| 1317 | - else |
|
| 1318 | - $userQuery = ''; |
|
| 1319 | 1369 | } |
| 1320 | 1370 | |
| 1321 | 1371 | // Setup the sorting variables... |
@@ -1323,8 +1373,9 @@ discard block |
||
| 1323 | 1373 | $sort_columns = array( |
| 1324 | 1374 | 'pm.id_pm', |
| 1325 | 1375 | ); |
| 1326 | - if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) |
|
| 1327 | - list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); |
|
| 1376 | + if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) { |
|
| 1377 | + list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); |
|
| 1378 | + } |
|
| 1328 | 1379 | $search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'pm.id_pm'; |
| 1329 | 1380 | $search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc'; |
| 1330 | 1381 | |
@@ -1334,24 +1385,27 @@ discard block |
||
| 1334 | 1385 | if ($context['folder'] == 'inbox' && !empty($search_params['advanced']) && $context['currently_using_labels']) |
| 1335 | 1386 | { |
| 1336 | 1387 | // Came here from pagination? Put them back into $_REQUEST for sanitization. |
| 1337 | - if (isset($search_params['labels'])) |
|
| 1338 | - $_REQUEST['searchlabel'] = explode(',', $search_params['labels']); |
|
| 1388 | + if (isset($search_params['labels'])) { |
|
| 1389 | + $_REQUEST['searchlabel'] = explode(',', $search_params['labels']); |
|
| 1390 | + } |
|
| 1339 | 1391 | |
| 1340 | 1392 | // Assuming we have some labels - make them all integers. |
| 1341 | 1393 | if (!empty($_REQUEST['searchlabel']) && is_array($_REQUEST['searchlabel'])) |
| 1342 | 1394 | { |
| 1343 | - foreach ($_REQUEST['searchlabel'] as $key => $id) |
|
| 1344 | - $_REQUEST['searchlabel'][$key] = (int) $id; |
|
| 1395 | + foreach ($_REQUEST['searchlabel'] as $key => $id) { |
|
| 1396 | + $_REQUEST['searchlabel'][$key] = (int) $id; |
|
| 1397 | + } |
|
| 1398 | + } else { |
|
| 1399 | + $_REQUEST['searchlabel'] = array(); |
|
| 1345 | 1400 | } |
| 1346 | - else |
|
| 1347 | - $_REQUEST['searchlabel'] = array(); |
|
| 1348 | 1401 | |
| 1349 | 1402 | // Now that everything is cleaned up a bit, make the labels a param. |
| 1350 | 1403 | $search_params['labels'] = implode(',', $_REQUEST['searchlabel']); |
| 1351 | 1404 | |
| 1352 | 1405 | // No labels selected? That must be an error! |
| 1353 | - if (empty($_REQUEST['searchlabel'])) |
|
| 1354 | - $context['search_errors']['no_labels_selected'] = true; |
|
| 1406 | + if (empty($_REQUEST['searchlabel'])) { |
|
| 1407 | + $context['search_errors']['no_labels_selected'] = true; |
|
| 1408 | + } |
|
| 1355 | 1409 | // Otherwise prepare the query! |
| 1356 | 1410 | elseif (count($_REQUEST['searchlabel']) != count($context['labels'])) |
| 1357 | 1411 | { |
@@ -1374,8 +1428,7 @@ discard block |
||
| 1374 | 1428 | // Not searching the inbox - PM must be labeled |
| 1375 | 1429 | $labelQuery = ' AND pml.id_label IN ({array_int:labels})'; |
| 1376 | 1430 | $labelJoin = ' INNER JOIN {db_prefix}pm_labeled_messages AS pml ON (pml.id_pm = pmr.id_pm)'; |
| 1377 | - } |
|
| 1378 | - else |
|
| 1431 | + } else |
|
| 1379 | 1432 | { |
| 1380 | 1433 | // Searching the inbox - PM doesn't have to be labeled |
| 1381 | 1434 | $labelQuery = ' AND (' . substr($labelQuery, 5) . ' OR pml.id_label IN ({array_int:labels}))'; |
@@ -1390,8 +1443,9 @@ discard block |
||
| 1390 | 1443 | // What are we actually searching for? |
| 1391 | 1444 | $search_params['search'] = !empty($search_params['search']) ? $search_params['search'] : (isset($_REQUEST['search']) ? $_REQUEST['search'] : ''); |
| 1392 | 1445 | // If we ain't got nothing - we should error! |
| 1393 | - if (!isset($search_params['search']) || $search_params['search'] == '') |
|
| 1394 | - $context['search_errors']['invalid_search_string'] = true; |
|
| 1446 | + if (!isset($search_params['search']) || $search_params['search'] == '') { |
|
| 1447 | + $context['search_errors']['invalid_search_string'] = true; |
|
| 1448 | + } |
|
| 1395 | 1449 | |
| 1396 | 1450 | // Extract phrase parts first (e.g. some words "this is a phrase" some more words.) |
| 1397 | 1451 | preg_match_all('~(?:^|\s)([-]?)"([^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), $search_params['search'], $matches, PREG_PATTERN_ORDER); |
@@ -1404,12 +1458,14 @@ discard block |
||
| 1404 | 1458 | $excludedWords = array(); |
| 1405 | 1459 | |
| 1406 | 1460 | // .. first, we check for things like -"some words", but not "-some words". |
| 1407 | - foreach ($matches[1] as $index => $word) |
|
| 1408 | - if ($word == '-') |
|
| 1461 | + foreach ($matches[1] as $index => $word) { |
|
| 1462 | + if ($word == '-') |
|
| 1409 | 1463 | { |
| 1410 | 1464 | $word = $smcFunc['strtolower'](trim($searchArray[$index])); |
| 1411 | - if (strlen($word) > 0) |
|
| 1412 | - $excludedWords[] = $word; |
|
| 1465 | + } |
|
| 1466 | + if (strlen($word) > 0) { |
|
| 1467 | + $excludedWords[] = $word; |
|
| 1468 | + } |
|
| 1413 | 1469 | unset($searchArray[$index]); |
| 1414 | 1470 | } |
| 1415 | 1471 | |
@@ -1419,8 +1475,9 @@ discard block |
||
| 1419 | 1475 | if (strpos(trim($word), '-') === 0) |
| 1420 | 1476 | { |
| 1421 | 1477 | $word = substr($smcFunc['strtolower']($word), 1); |
| 1422 | - if (strlen($word) > 0) |
|
| 1423 | - $excludedWords[] = $word; |
|
| 1478 | + if (strlen($word) > 0) { |
|
| 1479 | + $excludedWords[] = $word; |
|
| 1480 | + } |
|
| 1424 | 1481 | unset($tempSearch[$index]); |
| 1425 | 1482 | } |
| 1426 | 1483 | } |
@@ -1431,9 +1488,9 @@ discard block |
||
| 1431 | 1488 | foreach ($searchArray as $index => $value) |
| 1432 | 1489 | { |
| 1433 | 1490 | $searchArray[$index] = $smcFunc['strtolower'](trim($value)); |
| 1434 | - if ($searchArray[$index] == '') |
|
| 1435 | - unset($searchArray[$index]); |
|
| 1436 | - else |
|
| 1491 | + if ($searchArray[$index] == '') { |
|
| 1492 | + unset($searchArray[$index]); |
|
| 1493 | + } else |
|
| 1437 | 1494 | { |
| 1438 | 1495 | // Sort out entities first. |
| 1439 | 1496 | $searchArray[$index] = $smcFunc['htmlspecialchars']($searchArray[$index]); |
@@ -1443,27 +1500,32 @@ discard block |
||
| 1443 | 1500 | |
| 1444 | 1501 | // Create an array of replacements for highlighting. |
| 1445 | 1502 | $context['mark'] = array(); |
| 1446 | - foreach ($searchArray as $word) |
|
| 1447 | - $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>'; |
|
| 1503 | + foreach ($searchArray as $word) { |
|
| 1504 | + $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>'; |
|
| 1505 | + } |
|
| 1448 | 1506 | |
| 1449 | 1507 | // This contains *everything* |
| 1450 | 1508 | $searchWords = array_merge($searchArray, $excludedWords); |
| 1451 | 1509 | |
| 1452 | 1510 | // Make sure at least one word is being searched for. |
| 1453 | - if (empty($searchArray)) |
|
| 1454 | - $context['search_errors']['invalid_search_string'] = true; |
|
| 1511 | + if (empty($searchArray)) { |
|
| 1512 | + $context['search_errors']['invalid_search_string'] = true; |
|
| 1513 | + } |
|
| 1455 | 1514 | |
| 1456 | 1515 | // Sort out the search query so the user can edit it - if they want. |
| 1457 | 1516 | $context['search_params'] = $search_params; |
| 1458 | - if (isset($context['search_params']['search'])) |
|
| 1459 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
| 1460 | - if (isset($context['search_params']['userspec'])) |
|
| 1461 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
| 1517 | + if (isset($context['search_params']['search'])) { |
|
| 1518 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
| 1519 | + } |
|
| 1520 | + if (isset($context['search_params']['userspec'])) { |
|
| 1521 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
| 1522 | + } |
|
| 1462 | 1523 | |
| 1463 | 1524 | // Now we have all the parameters, combine them together for pagination and the like... |
| 1464 | 1525 | $context['params'] = array(); |
| 1465 | - foreach ($search_params as $k => $v) |
|
| 1466 | - $context['params'][] = $k . '|\'|' . $v; |
|
| 1526 | + foreach ($search_params as $k => $v) { |
|
| 1527 | + $context['params'][] = $k . '|\'|' . $v; |
|
| 1528 | + } |
|
| 1467 | 1529 | $context['params'] = base64_encode(implode('|"|', $context['params'])); |
| 1468 | 1530 | |
| 1469 | 1531 | // Compile the subject query part. |
@@ -1471,26 +1533,31 @@ discard block |
||
| 1471 | 1533 | |
| 1472 | 1534 | foreach ($searchWords as $index => $word) |
| 1473 | 1535 | { |
| 1474 | - if ($word == '') |
|
| 1475 | - continue; |
|
| 1536 | + if ($word == '') { |
|
| 1537 | + continue; |
|
| 1538 | + } |
|
| 1476 | 1539 | |
| 1477 | - if ($search_params['subject_only']) |
|
| 1478 | - $andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}'; |
|
| 1479 | - else |
|
| 1480 | - $andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})'; |
|
| 1540 | + if ($search_params['subject_only']) { |
|
| 1541 | + $andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}'; |
|
| 1542 | + } else { |
|
| 1543 | + $andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})'; |
|
| 1544 | + } |
|
| 1481 | 1545 | $searchq_parameters['search_' . $index] = '%' . strtr($word, array('_' => '\\_', '%' => '\\%')) . '%'; |
| 1482 | 1546 | } |
| 1483 | 1547 | |
| 1484 | 1548 | $searchQuery = ' 1=1'; |
| 1485 | - if (!empty($andQueryParts)) |
|
| 1486 | - $searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts); |
|
| 1549 | + if (!empty($andQueryParts)) { |
|
| 1550 | + $searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts); |
|
| 1551 | + } |
|
| 1487 | 1552 | |
| 1488 | 1553 | // Age limits? |
| 1489 | 1554 | $timeQuery = ''; |
| 1490 | - if (!empty($search_params['minage'])) |
|
| 1491 | - $timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400); |
|
| 1492 | - if (!empty($search_params['maxage'])) |
|
| 1493 | - $timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400); |
|
| 1555 | + if (!empty($search_params['minage'])) { |
|
| 1556 | + $timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400); |
|
| 1557 | + } |
|
| 1558 | + if (!empty($search_params['maxage'])) { |
|
| 1559 | + $timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400); |
|
| 1560 | + } |
|
| 1494 | 1561 | |
| 1495 | 1562 | // If we have errors - return back to the first screen... |
| 1496 | 1563 | if (!empty($context['search_errors'])) |
@@ -1576,8 +1643,9 @@ discard block |
||
| 1576 | 1643 | ) |
| 1577 | 1644 | ); |
| 1578 | 1645 | $real_pm_ids = array(); |
| 1579 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1580 | - $real_pm_ids[$row['id_pm_head']] = $row['id_pm']; |
|
| 1646 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1647 | + $real_pm_ids[$row['id_pm_head']] = $row['id_pm']; |
|
| 1648 | + } |
|
| 1581 | 1649 | $smcFunc['db_free_result']($request); |
| 1582 | 1650 | } |
| 1583 | 1651 | |
@@ -1607,8 +1675,9 @@ discard block |
||
| 1607 | 1675 | ); |
| 1608 | 1676 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1609 | 1677 | { |
| 1610 | - if ($context['folder'] == 'sent' || empty($row['bcc'])) |
|
| 1611 | - $recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>'; |
|
| 1678 | + if ($context['folder'] == 'sent' || empty($row['bcc'])) { |
|
| 1679 | + $recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>'; |
|
| 1680 | + } |
|
| 1612 | 1681 | |
| 1613 | 1682 | if ($row['id_member_to'] == $user_info['id'] && $context['folder'] != 'sent') |
| 1614 | 1683 | { |
@@ -1629,12 +1698,14 @@ discard block |
||
| 1629 | 1698 | while($row2 = $smcFunc['db_fetch_assoc']($request2)) |
| 1630 | 1699 | { |
| 1631 | 1700 | $l_id = $row2['id_label']; |
| 1632 | - if (isset($context['labels'][$l_id])) |
|
| 1633 | - $context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); |
|
| 1701 | + if (isset($context['labels'][$l_id])) { |
|
| 1702 | + $context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']); |
|
| 1703 | + } |
|
| 1634 | 1704 | |
| 1635 | 1705 | // Here we find the first label on a message - for linking to posts in results |
| 1636 | - if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1) |
|
| 1637 | - $context['first_label'][$row['id_pm']] = $l_id; |
|
| 1706 | + if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1) { |
|
| 1707 | + $context['first_label'][$row['id_pm']] = $l_id; |
|
| 1708 | + } |
|
| 1638 | 1709 | } |
| 1639 | 1710 | |
| 1640 | 1711 | $smcFunc['db_free_result']($request2); |
@@ -1761,8 +1832,9 @@ discard block |
||
| 1761 | 1832 | list ($postCount) = $smcFunc['db_fetch_row']($request); |
| 1762 | 1833 | $smcFunc['db_free_result']($request); |
| 1763 | 1834 | |
| 1764 | - if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) |
|
| 1765 | - fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); |
|
| 1835 | + if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) { |
|
| 1836 | + fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); |
|
| 1837 | + } |
|
| 1766 | 1838 | } |
| 1767 | 1839 | |
| 1768 | 1840 | // Quoting/Replying to a message? |
@@ -1771,8 +1843,9 @@ discard block |
||
| 1771 | 1843 | $pmsg = (int) $_REQUEST['pmsg']; |
| 1772 | 1844 | |
| 1773 | 1845 | // Make sure this is yours. |
| 1774 | - if (!isAccessiblePM($pmsg)) |
|
| 1775 | - fatal_lang_error('no_access', false); |
|
| 1846 | + if (!isAccessiblePM($pmsg)) { |
|
| 1847 | + fatal_lang_error('no_access', false); |
|
| 1848 | + } |
|
| 1776 | 1849 | |
| 1777 | 1850 | // Work out whether this is one you've received? |
| 1778 | 1851 | $request = $smcFunc['db_query']('', ' |
@@ -1809,8 +1882,9 @@ discard block |
||
| 1809 | 1882 | 'id_pm' => $pmsg, |
| 1810 | 1883 | ) |
| 1811 | 1884 | ); |
| 1812 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1813 | - fatal_lang_error('pm_not_yours', false); |
|
| 1885 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1886 | + fatal_lang_error('pm_not_yours', false); |
|
| 1887 | + } |
|
| 1814 | 1888 | $row_quoted = $smcFunc['db_fetch_assoc']($request); |
| 1815 | 1889 | $smcFunc['db_free_result']($request); |
| 1816 | 1890 | |
@@ -1821,9 +1895,9 @@ discard block |
||
| 1821 | 1895 | // Add 'Re: ' to it.... |
| 1822 | 1896 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
| 1823 | 1897 | { |
| 1824 | - if ($language === $user_info['language']) |
|
| 1825 | - $context['response_prefix'] = $txt['response_prefix']; |
|
| 1826 | - else |
|
| 1898 | + if ($language === $user_info['language']) { |
|
| 1899 | + $context['response_prefix'] = $txt['response_prefix']; |
|
| 1900 | + } else |
|
| 1827 | 1901 | { |
| 1828 | 1902 | loadLanguage('index', $language, false); |
| 1829 | 1903 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -1832,22 +1906,25 @@ discard block |
||
| 1832 | 1906 | cache_put_data('response_prefix', $context['response_prefix'], 600); |
| 1833 | 1907 | } |
| 1834 | 1908 | $form_subject = $row_quoted['subject']; |
| 1835 | - if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
|
| 1836 | - $form_subject = $context['response_prefix'] . $form_subject; |
|
| 1909 | + if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) { |
|
| 1910 | + $form_subject = $context['response_prefix'] . $form_subject; |
|
| 1911 | + } |
|
| 1837 | 1912 | |
| 1838 | 1913 | if (isset($_REQUEST['quote'])) |
| 1839 | 1914 | { |
| 1840 | 1915 | // Remove any nested quotes and <br>... |
| 1841 | 1916 | $form_message = preg_replace('~<br ?/?' . '>~i', "\n", $row_quoted['body']); |
| 1842 | - if (!empty($modSettings['removeNestedQuotes'])) |
|
| 1843 | - $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
| 1844 | - if (empty($row_quoted['id_member'])) |
|
| 1845 | - $form_message = '[quote author="' . $row_quoted['real_name'] . '"]' . "\n" . $form_message . "\n" . '[/quote]'; |
|
| 1846 | - else |
|
| 1847 | - $form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]'; |
|
| 1917 | + if (!empty($modSettings['removeNestedQuotes'])) { |
|
| 1918 | + $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
| 1919 | + } |
|
| 1920 | + if (empty($row_quoted['id_member'])) { |
|
| 1921 | + $form_message = '[quote author="' . $row_quoted['real_name'] . '"]' . "\n" . $form_message . "\n" . '[/quote]'; |
|
| 1922 | + } else { |
|
| 1923 | + $form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]'; |
|
| 1924 | + } |
|
| 1925 | + } else { |
|
| 1926 | + $form_message = ''; |
|
| 1848 | 1927 | } |
| 1849 | - else |
|
| 1850 | - $form_message = ''; |
|
| 1851 | 1928 | |
| 1852 | 1929 | // Do the BBC thang on the message. |
| 1853 | 1930 | $row_quoted['body'] = parse_bbc($row_quoted['body'], true, 'pm' . $row_quoted['id_pm']); |
@@ -1868,8 +1945,7 @@ discard block |
||
| 1868 | 1945 | 'timestamp' => forum_time(true, $row_quoted['msgtime']), |
| 1869 | 1946 | 'body' => $row_quoted['body'] |
| 1870 | 1947 | ); |
| 1871 | - } |
|
| 1872 | - else |
|
| 1948 | + } else |
|
| 1873 | 1949 | { |
| 1874 | 1950 | $context['quoted_message'] = false; |
| 1875 | 1951 | $form_subject = ''; |
@@ -1888,11 +1964,12 @@ discard block |
||
| 1888 | 1964 | if ($_REQUEST['u'] == 'all' && isset($row_quoted)) |
| 1889 | 1965 | { |
| 1890 | 1966 | // Firstly, to reply to all we clearly already have $row_quoted - so have the original member from. |
| 1891 | - if ($row_quoted['id_member'] != $user_info['id']) |
|
| 1892 | - $context['recipients']['to'][] = array( |
|
| 1967 | + if ($row_quoted['id_member'] != $user_info['id']) { |
|
| 1968 | + $context['recipients']['to'][] = array( |
|
| 1893 | 1969 | 'id' => $row_quoted['id_member'], |
| 1894 | 1970 | 'name' => $smcFunc['htmlspecialchars']($row_quoted['real_name']), |
| 1895 | 1971 | ); |
| 1972 | + } |
|
| 1896 | 1973 | |
| 1897 | 1974 | // Now to get the others. |
| 1898 | 1975 | $request = $smcFunc['db_query']('', ' |
@@ -1908,18 +1985,19 @@ discard block |
||
| 1908 | 1985 | 'not_bcc' => 0, |
| 1909 | 1986 | ) |
| 1910 | 1987 | ); |
| 1911 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1912 | - $context['recipients']['to'][] = array( |
|
| 1988 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1989 | + $context['recipients']['to'][] = array( |
|
| 1913 | 1990 | 'id' => $row['id_member'], |
| 1914 | 1991 | 'name' => $row['real_name'], |
| 1915 | 1992 | ); |
| 1993 | + } |
|
| 1916 | 1994 | $smcFunc['db_free_result']($request); |
| 1917 | - } |
|
| 1918 | - else |
|
| 1995 | + } else |
|
| 1919 | 1996 | { |
| 1920 | 1997 | $_REQUEST['u'] = explode(',', $_REQUEST['u']); |
| 1921 | - foreach ($_REQUEST['u'] as $key => $uID) |
|
| 1922 | - $_REQUEST['u'][$key] = (int) $uID; |
|
| 1998 | + foreach ($_REQUEST['u'] as $key => $uID) { |
|
| 1999 | + $_REQUEST['u'][$key] = (int) $uID; |
|
| 2000 | + } |
|
| 1923 | 2001 | |
| 1924 | 2002 | $_REQUEST['u'] = array_unique($_REQUEST['u']); |
| 1925 | 2003 | |
@@ -1933,22 +2011,24 @@ discard block |
||
| 1933 | 2011 | 'limit' => count($_REQUEST['u']), |
| 1934 | 2012 | ) |
| 1935 | 2013 | ); |
| 1936 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1937 | - $context['recipients']['to'][] = array( |
|
| 2014 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2015 | + $context['recipients']['to'][] = array( |
|
| 1938 | 2016 | 'id' => $row['id_member'], |
| 1939 | 2017 | 'name' => $row['real_name'], |
| 1940 | 2018 | ); |
| 2019 | + } |
|
| 1941 | 2020 | $smcFunc['db_free_result']($request); |
| 1942 | 2021 | } |
| 1943 | 2022 | |
| 1944 | 2023 | // Get a literal name list in case the user has JavaScript disabled. |
| 1945 | 2024 | $names = array(); |
| 1946 | - foreach ($context['recipients']['to'] as $to) |
|
| 1947 | - $names[] = $to['name']; |
|
| 2025 | + foreach ($context['recipients']['to'] as $to) { |
|
| 2026 | + $names[] = $to['name']; |
|
| 2027 | + } |
|
| 1948 | 2028 | $context['to_value'] = empty($names) ? '' : '"' . implode('", "', $names) . '"'; |
| 2029 | + } else { |
|
| 2030 | + $context['to_value'] = ''; |
|
| 1949 | 2031 | } |
| 1950 | - else |
|
| 1951 | - $context['to_value'] = ''; |
|
| 1952 | 2032 | |
| 1953 | 2033 | // Set the defaults... |
| 1954 | 2034 | $context['subject'] = $form_subject; |
@@ -2018,8 +2098,9 @@ discard block |
||
| 2018 | 2098 | |
| 2019 | 2099 | // validate with loadMemberData() |
| 2020 | 2100 | $memberResult = loadMemberData($user_info['id'], false); |
| 2021 | - if (!$memberResult) |
|
| 2022 | - fatal_lang_error('not_a_user', false); |
|
| 2101 | + if (!$memberResult) { |
|
| 2102 | + fatal_lang_error('not_a_user', false); |
|
| 2103 | + } |
|
| 2023 | 2104 | list ($memID) = $memberResult; |
| 2024 | 2105 | |
| 2025 | 2106 | // drafts is where the functions reside |
@@ -2045,9 +2126,9 @@ discard block |
||
| 2045 | 2126 | $context['sub_template'] = 'send'; |
| 2046 | 2127 | loadJavaScriptFile('PersonalMessage.js', array('defer' => false), 'smf_pms'); |
| 2047 | 2128 | loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
| 2129 | + } else { |
|
| 2130 | + $context['sub_template'] = 'pm'; |
|
| 2048 | 2131 | } |
| 2049 | - else |
|
| 2050 | - $context['sub_template'] = 'pm'; |
|
| 2051 | 2132 | |
| 2052 | 2133 | $context['page_title'] = $txt['send_message']; |
| 2053 | 2134 | |
@@ -2108,10 +2189,11 @@ discard block |
||
| 2108 | 2189 | ); |
| 2109 | 2190 | if ($smcFunc['db_num_rows']($request) == 0) |
| 2110 | 2191 | { |
| 2111 | - if (!isset($_REQUEST['xml'])) |
|
| 2112 | - fatal_lang_error('pm_not_yours', false); |
|
| 2113 | - else |
|
| 2114 | - $error_types[] = 'pm_not_yours'; |
|
| 2192 | + if (!isset($_REQUEST['xml'])) { |
|
| 2193 | + fatal_lang_error('pm_not_yours', false); |
|
| 2194 | + } else { |
|
| 2195 | + $error_types[] = 'pm_not_yours'; |
|
| 2196 | + } |
|
| 2115 | 2197 | } |
| 2116 | 2198 | $row_quoted = $smcFunc['db_fetch_assoc']($request); |
| 2117 | 2199 | $smcFunc['db_free_result']($request); |
@@ -2158,14 +2240,16 @@ discard block |
||
| 2158 | 2240 | $context['post_error'][$error_type] = true; |
| 2159 | 2241 | if (isset($txt['error_' . $error_type])) |
| 2160 | 2242 | { |
| 2161 | - if ($error_type == 'long_message') |
|
| 2162 | - $txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']); |
|
| 2243 | + if ($error_type == 'long_message') { |
|
| 2244 | + $txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']); |
|
| 2245 | + } |
|
| 2163 | 2246 | $context['post_error']['messages'][] = $txt['error_' . $error_type]; |
| 2164 | 2247 | } |
| 2165 | 2248 | |
| 2166 | 2249 | // If it's not a minor error flag it as such. |
| 2167 | - if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) |
|
| 2168 | - $context['error_type'] = 'serious'; |
|
| 2250 | + if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) { |
|
| 2251 | + $context['error_type'] = 'serious'; |
|
| 2252 | + } |
|
| 2169 | 2253 | } |
| 2170 | 2254 | |
| 2171 | 2255 | // We need to load the editor once more. |
@@ -2223,8 +2307,9 @@ discard block |
||
| 2223 | 2307 | require_once($sourcedir . '/Subs-Auth.php'); |
| 2224 | 2308 | |
| 2225 | 2309 | // PM Drafts enabled and needed? |
| 2226 | - if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft']))) |
|
| 2227 | - require_once($sourcedir . '/Drafts.php'); |
|
| 2310 | + if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft']))) { |
|
| 2311 | + require_once($sourcedir . '/Drafts.php'); |
|
| 2312 | + } |
|
| 2228 | 2313 | |
| 2229 | 2314 | loadLanguage('PersonalMessage', '', false); |
| 2230 | 2315 | |
@@ -2254,24 +2339,27 @@ discard block |
||
| 2254 | 2339 | |
| 2255 | 2340 | if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) |
| 2256 | 2341 | { |
| 2257 | - if (!isset($_REQUEST['xml'])) |
|
| 2258 | - fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); |
|
| 2259 | - else |
|
| 2260 | - $post_errors[] = 'pm_too_many_per_hour'; |
|
| 2342 | + if (!isset($_REQUEST['xml'])) { |
|
| 2343 | + fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour'])); |
|
| 2344 | + } else { |
|
| 2345 | + $post_errors[] = 'pm_too_many_per_hour'; |
|
| 2346 | + } |
|
| 2261 | 2347 | } |
| 2262 | 2348 | } |
| 2263 | 2349 | |
| 2264 | 2350 | // If your session timed out, show an error, but do allow to re-submit. |
| 2265 | - if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') |
|
| 2266 | - $post_errors[] = 'session_timeout'; |
|
| 2351 | + if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') { |
|
| 2352 | + $post_errors[] = 'session_timeout'; |
|
| 2353 | + } |
|
| 2267 | 2354 | |
| 2268 | 2355 | $_REQUEST['subject'] = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : ''; |
| 2269 | 2356 | $_REQUEST['to'] = empty($_POST['to']) ? (empty($_GET['to']) ? '' : $_GET['to']) : $_POST['to']; |
| 2270 | 2357 | $_REQUEST['bcc'] = empty($_POST['bcc']) ? (empty($_GET['bcc']) ? '' : $_GET['bcc']) : $_POST['bcc']; |
| 2271 | 2358 | |
| 2272 | 2359 | // Route the input from the 'u' parameter to the 'to'-list. |
| 2273 | - if (!empty($_POST['u'])) |
|
| 2274 | - $_POST['recipient_to'] = explode(',', $_POST['u']); |
|
| 2360 | + if (!empty($_POST['u'])) { |
|
| 2361 | + $_POST['recipient_to'] = explode(',', $_POST['u']); |
|
| 2362 | + } |
|
| 2275 | 2363 | |
| 2276 | 2364 | // Construct the list of recipients. |
| 2277 | 2365 | $recipientList = array(); |
@@ -2283,8 +2371,9 @@ discard block |
||
| 2283 | 2371 | $recipientList[$recipientType] = array(); |
| 2284 | 2372 | if (!empty($_POST['recipient_' . $recipientType]) && is_array($_POST['recipient_' . $recipientType])) |
| 2285 | 2373 | { |
| 2286 | - foreach ($_POST['recipient_' . $recipientType] as $recipient) |
|
| 2287 | - $recipientList[$recipientType][] = (int) $recipient; |
|
| 2374 | + foreach ($_POST['recipient_' . $recipientType] as $recipient) { |
|
| 2375 | + $recipientList[$recipientType][] = (int) $recipient; |
|
| 2376 | + } |
|
| 2288 | 2377 | } |
| 2289 | 2378 | |
| 2290 | 2379 | // Are there also literal names set? |
@@ -2298,10 +2387,11 @@ discard block |
||
| 2298 | 2387 | |
| 2299 | 2388 | foreach ($namedRecipientList[$recipientType] as $index => $recipient) |
| 2300 | 2389 | { |
| 2301 | - if (strlen(trim($recipient)) > 0) |
|
| 2302 | - $namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient))); |
|
| 2303 | - else |
|
| 2304 | - unset($namedRecipientList[$recipientType][$index]); |
|
| 2390 | + if (strlen(trim($recipient)) > 0) { |
|
| 2391 | + $namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient))); |
|
| 2392 | + } else { |
|
| 2393 | + unset($namedRecipientList[$recipientType][$index]); |
|
| 2394 | + } |
|
| 2305 | 2395 | } |
| 2306 | 2396 | |
| 2307 | 2397 | if (!empty($namedRecipientList[$recipientType])) |
@@ -2331,8 +2421,9 @@ discard block |
||
| 2331 | 2421 | } |
| 2332 | 2422 | |
| 2333 | 2423 | // Selected a recipient to be deleted? Remove them now. |
| 2334 | - if (!empty($_POST['delete_recipient'])) |
|
| 2335 | - $recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient'])); |
|
| 2424 | + if (!empty($_POST['delete_recipient'])) { |
|
| 2425 | + $recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient'])); |
|
| 2426 | + } |
|
| 2336 | 2427 | |
| 2337 | 2428 | // Make sure we don't include the same name twice |
| 2338 | 2429 | $recipientList[$recipientType] = array_unique($recipientList[$recipientType]); |
@@ -2342,8 +2433,9 @@ discard block |
||
| 2342 | 2433 | $is_recipient_change = !empty($_POST['delete_recipient']) || !empty($_POST['to_submit']) || !empty($_POST['bcc_submit']); |
| 2343 | 2434 | |
| 2344 | 2435 | // Check if there's at least one recipient. |
| 2345 | - if (empty($recipientList['to']) && empty($recipientList['bcc'])) |
|
| 2346 | - $post_errors[] = 'no_to'; |
|
| 2436 | + if (empty($recipientList['to']) && empty($recipientList['bcc'])) { |
|
| 2437 | + $post_errors[] = 'no_to'; |
|
| 2438 | + } |
|
| 2347 | 2439 | |
| 2348 | 2440 | // Make sure that we remove the members who did get it from the screen. |
| 2349 | 2441 | if (!$is_recipient_change) |
@@ -2357,28 +2449,31 @@ discard block |
||
| 2357 | 2449 | // Since we already have a post error, remove the previous one. |
| 2358 | 2450 | $post_errors = array_diff($post_errors, array('no_to')); |
| 2359 | 2451 | |
| 2360 | - foreach ($namesNotFound[$recipientType] as $name) |
|
| 2361 | - $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name); |
|
| 2452 | + foreach ($namesNotFound[$recipientType] as $name) { |
|
| 2453 | + $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name); |
|
| 2454 | + } |
|
| 2362 | 2455 | } |
| 2363 | 2456 | } |
| 2364 | 2457 | } |
| 2365 | 2458 | |
| 2366 | 2459 | // Did they make any mistakes? |
| 2367 | - if ($_REQUEST['subject'] == '') |
|
| 2368 | - $post_errors[] = 'no_subject'; |
|
| 2369 | - if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') |
|
| 2370 | - $post_errors[] = 'no_message'; |
|
| 2371 | - elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) |
|
| 2372 | - $post_errors[] = 'long_message'; |
|
| 2373 | - else |
|
| 2460 | + if ($_REQUEST['subject'] == '') { |
|
| 2461 | + $post_errors[] = 'no_subject'; |
|
| 2462 | + } |
|
| 2463 | + if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') { |
|
| 2464 | + $post_errors[] = 'no_message'; |
|
| 2465 | + } elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) { |
|
| 2466 | + $post_errors[] = 'long_message'; |
|
| 2467 | + } else |
|
| 2374 | 2468 | { |
| 2375 | 2469 | // Preparse the message. |
| 2376 | 2470 | $message = $_REQUEST['message']; |
| 2377 | 2471 | preparsecode($message); |
| 2378 | 2472 | |
| 2379 | 2473 | // Make sure there's still some content left without the tags. |
| 2380 | - if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) |
|
| 2381 | - $post_errors[] = 'no_message'; |
|
| 2474 | + if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) { |
|
| 2475 | + $post_errors[] = 'no_message'; |
|
| 2476 | + } |
|
| 2382 | 2477 | } |
| 2383 | 2478 | |
| 2384 | 2479 | // Wrong verification code? |
@@ -2390,13 +2485,15 @@ discard block |
||
| 2390 | 2485 | ); |
| 2391 | 2486 | $context['require_verification'] = create_control_verification($verificationOptions, true); |
| 2392 | 2487 | |
| 2393 | - if (is_array($context['require_verification'])) |
|
| 2394 | - $post_errors = array_merge($post_errors, $context['require_verification']); |
|
| 2488 | + if (is_array($context['require_verification'])) { |
|
| 2489 | + $post_errors = array_merge($post_errors, $context['require_verification']); |
|
| 2490 | + } |
|
| 2395 | 2491 | } |
| 2396 | 2492 | |
| 2397 | 2493 | // If they did, give a chance to make ammends. |
| 2398 | - if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml'])) |
|
| 2399 | - return messagePostError($post_errors, $namedRecipientList, $recipientList); |
|
| 2494 | + if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml'])) { |
|
| 2495 | + return messagePostError($post_errors, $namedRecipientList, $recipientList); |
|
| 2496 | + } |
|
| 2400 | 2497 | |
| 2401 | 2498 | // Want to take a second glance before you send? |
| 2402 | 2499 | if (isset($_REQUEST['preview'])) |
@@ -2427,8 +2524,9 @@ discard block |
||
| 2427 | 2524 | foreach ($namesNotFound as $recipientType => $names) |
| 2428 | 2525 | { |
| 2429 | 2526 | $post_errors[] = 'bad_' . $recipientType; |
| 2430 | - foreach ($names as $name) |
|
| 2431 | - $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name); |
|
| 2527 | + foreach ($names as $name) { |
|
| 2528 | + $context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name); |
|
| 2529 | + } |
|
| 2432 | 2530 | } |
| 2433 | 2531 | |
| 2434 | 2532 | return messagePostError(array(), $namedRecipientList, $recipientList); |
@@ -2458,13 +2556,14 @@ discard block |
||
| 2458 | 2556 | checkSubmitOnce('check'); |
| 2459 | 2557 | |
| 2460 | 2558 | // Do the actual sending of the PM. |
| 2461 | - if (!empty($recipientList['to']) || !empty($recipientList['bcc'])) |
|
| 2462 | - $context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0); |
|
| 2463 | - else |
|
| 2464 | - $context['send_log'] = array( |
|
| 2559 | + if (!empty($recipientList['to']) || !empty($recipientList['bcc'])) { |
|
| 2560 | + $context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0); |
|
| 2561 | + } else { |
|
| 2562 | + $context['send_log'] = array( |
|
| 2465 | 2563 | 'sent' => array(), |
| 2466 | 2564 | 'failed' => array() |
| 2467 | 2565 | ); |
| 2566 | + } |
|
| 2468 | 2567 | |
| 2469 | 2568 | // Mark the message as "replied to". |
| 2470 | 2569 | if (!empty($context['send_log']['sent']) && !empty($_REQUEST['replied_to']) && isset($_REQUEST['f']) && $_REQUEST['f'] == 'inbox') |
@@ -2482,11 +2581,12 @@ discard block |
||
| 2482 | 2581 | } |
| 2483 | 2582 | |
| 2484 | 2583 | // If one or more of the recipient were invalid, go back to the post screen with the failed usernames. |
| 2485 | - if (!empty($context['send_log']['failed'])) |
|
| 2486 | - return messagePostError($post_errors, $namesNotFound, array( |
|
| 2584 | + if (!empty($context['send_log']['failed'])) { |
|
| 2585 | + return messagePostError($post_errors, $namesNotFound, array( |
|
| 2487 | 2586 | 'to' => array_intersect($recipientList['to'], $context['send_log']['failed']), |
| 2488 | 2587 | 'bcc' => array_intersect($recipientList['bcc'], $context['send_log']['failed']) |
| 2489 | 2588 | )); |
| 2589 | + } |
|
| 2490 | 2590 | |
| 2491 | 2591 | // Message sent successfully? |
| 2492 | 2592 | if (!empty($context['send_log']) && empty($context['send_log']['failed'])) |
@@ -2494,8 +2594,9 @@ discard block |
||
| 2494 | 2594 | $context['current_label_redirect'] = $context['current_label_redirect'] . ';done=sent'; |
| 2495 | 2595 | |
| 2496 | 2596 | // If we had a PM draft for this one, then its time to remove it since it was just sent |
| 2497 | - if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft'])) |
|
| 2498 | - DeleteDraft($_POST['id_pm_draft']); |
|
| 2597 | + if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft'])) { |
|
| 2598 | + DeleteDraft($_POST['id_pm_draft']); |
|
| 2599 | + } |
|
| 2499 | 2600 | } |
| 2500 | 2601 | |
| 2501 | 2602 | // Go back to the where they sent from, if possible... |
@@ -2510,24 +2611,28 @@ discard block |
||
| 2510 | 2611 | |
| 2511 | 2612 | checkSession('request'); |
| 2512 | 2613 | |
| 2513 | - if (isset($_REQUEST['del_selected'])) |
|
| 2514 | - $_REQUEST['pm_action'] = 'delete'; |
|
| 2614 | + if (isset($_REQUEST['del_selected'])) { |
|
| 2615 | + $_REQUEST['pm_action'] = 'delete'; |
|
| 2616 | + } |
|
| 2515 | 2617 | |
| 2516 | 2618 | if (isset($_REQUEST['pm_action']) && $_REQUEST['pm_action'] != '' && !empty($_REQUEST['pms']) && is_array($_REQUEST['pms'])) |
| 2517 | 2619 | { |
| 2518 | - foreach ($_REQUEST['pms'] as $pm) |
|
| 2519 | - $_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action']; |
|
| 2620 | + foreach ($_REQUEST['pms'] as $pm) { |
|
| 2621 | + $_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action']; |
|
| 2622 | + } |
|
| 2520 | 2623 | } |
| 2521 | 2624 | |
| 2522 | - if (empty($_REQUEST['pm_actions'])) |
|
| 2523 | - redirectexit($context['current_label_redirect']); |
|
| 2625 | + if (empty($_REQUEST['pm_actions'])) { |
|
| 2626 | + redirectexit($context['current_label_redirect']); |
|
| 2627 | + } |
|
| 2524 | 2628 | |
| 2525 | 2629 | // If we are in conversation, we may need to apply this to every message in the conversation. |
| 2526 | 2630 | if ($context['display_mode'] == 2 && isset($_REQUEST['conversation'])) |
| 2527 | 2631 | { |
| 2528 | 2632 | $id_pms = array(); |
| 2529 | - foreach ($_REQUEST['pm_actions'] as $pm => $dummy) |
|
| 2530 | - $id_pms[] = (int) $pm; |
|
| 2633 | + foreach ($_REQUEST['pm_actions'] as $pm => $dummy) { |
|
| 2634 | + $id_pms[] = (int) $pm; |
|
| 2635 | + } |
|
| 2531 | 2636 | |
| 2532 | 2637 | $request = $smcFunc['db_query']('', ' |
| 2533 | 2638 | SELECT id_pm_head, id_pm |
@@ -2538,8 +2643,9 @@ discard block |
||
| 2538 | 2643 | ) |
| 2539 | 2644 | ); |
| 2540 | 2645 | $pm_heads = array(); |
| 2541 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2542 | - $pm_heads[$row['id_pm_head']] = $row['id_pm']; |
|
| 2646 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2647 | + $pm_heads[$row['id_pm_head']] = $row['id_pm']; |
|
| 2648 | + } |
|
| 2543 | 2649 | $smcFunc['db_free_result']($request); |
| 2544 | 2650 | |
| 2545 | 2651 | $request = $smcFunc['db_query']('', ' |
@@ -2553,8 +2659,9 @@ discard block |
||
| 2553 | 2659 | // Copy the action from the single to PM to the others. |
| 2554 | 2660 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2555 | 2661 | { |
| 2556 | - if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]])) |
|
| 2557 | - $_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]]; |
|
| 2662 | + if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]])) { |
|
| 2663 | + $_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]]; |
|
| 2664 | + } |
|
| 2558 | 2665 | } |
| 2559 | 2666 | $smcFunc['db_free_result']($request); |
| 2560 | 2667 | } |
@@ -2566,22 +2673,21 @@ discard block |
||
| 2566 | 2673 | $labels = array(); |
| 2567 | 2674 | foreach ($_REQUEST['pm_actions'] as $pm => $action) |
| 2568 | 2675 | { |
| 2569 | - if ($action === 'delete') |
|
| 2570 | - $to_delete[] = (int) $pm; |
|
| 2571 | - else |
|
| 2676 | + if ($action === 'delete') { |
|
| 2677 | + $to_delete[] = (int) $pm; |
|
| 2678 | + } else |
|
| 2572 | 2679 | { |
| 2573 | 2680 | if (substr($action, 0, 4) == 'add_') |
| 2574 | 2681 | { |
| 2575 | 2682 | $type = 'add'; |
| 2576 | 2683 | $action = substr($action, 4); |
| 2577 | - } |
|
| 2578 | - elseif (substr($action, 0, 4) == 'rem_') |
|
| 2684 | + } elseif (substr($action, 0, 4) == 'rem_') |
|
| 2579 | 2685 | { |
| 2580 | 2686 | $type = 'rem'; |
| 2581 | 2687 | $action = substr($action, 4); |
| 2688 | + } else { |
|
| 2689 | + $type = 'unk'; |
|
| 2582 | 2690 | } |
| 2583 | - else |
|
| 2584 | - $type = 'unk'; |
|
| 2585 | 2691 | |
| 2586 | 2692 | if ($action == '-1' || (int) $action > 0) |
| 2587 | 2693 | { |
@@ -2592,8 +2698,9 @@ discard block |
||
| 2592 | 2698 | } |
| 2593 | 2699 | |
| 2594 | 2700 | // Deleting, it looks like? |
| 2595 | - if (!empty($to_delete)) |
|
| 2596 | - deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']); |
|
| 2701 | + if (!empty($to_delete)) { |
|
| 2702 | + deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']); |
|
| 2703 | + } |
|
| 2597 | 2704 | |
| 2598 | 2705 | // Are we labeling anything? |
| 2599 | 2706 | if (!empty($to_label) && $context['folder'] == 'inbox') |
@@ -2661,8 +2768,7 @@ discard block |
||
| 2661 | 2768 | } |
| 2662 | 2769 | |
| 2663 | 2770 | $smcFunc['db_free_result']($request2); |
| 2664 | - } |
|
| 2665 | - elseif ($type == 'rem') |
|
| 2771 | + } elseif ($type == 'rem') |
|
| 2666 | 2772 | { |
| 2667 | 2773 | // If we're removing from the inbox, see if we have at least one other label. |
| 2668 | 2774 | // This query is faster than the one above |
@@ -2694,21 +2800,25 @@ discard block |
||
| 2694 | 2800 | if ($to_label[$row['id_pm']] != '-1') |
| 2695 | 2801 | { |
| 2696 | 2802 | // If this label is in the list and we're not adding it, remove it |
| 2697 | - if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add') |
|
| 2698 | - unset($labels[$to_label[$row['id_pm']]]); |
|
| 2699 | - else if ($type !== 'rem') |
|
| 2700 | - $labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']]; |
|
| 2803 | + if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add') { |
|
| 2804 | + unset($labels[$to_label[$row['id_pm']]]); |
|
| 2805 | + } else if ($type !== 'rem') { |
|
| 2806 | + $labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']]; |
|
| 2807 | + } |
|
| 2701 | 2808 | } |
| 2702 | 2809 | |
| 2703 | 2810 | // Removing all labels or just removing the inbox label |
| 2704 | - if ($type == 'rem' && empty($labels)) |
|
| 2705 | - $in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0); |
|
| 2811 | + if ($type == 'rem' && empty($labels)) { |
|
| 2812 | + $in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0); |
|
| 2813 | + } |
|
| 2706 | 2814 | // Adding new labels, but removing inbox and applying new ones |
| 2707 | - elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels)) |
|
| 2708 | - $in_inbox = 0; |
|
| 2815 | + elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels)) { |
|
| 2816 | + $in_inbox = 0; |
|
| 2817 | + } |
|
| 2709 | 2818 | // Just adding it to the inbox |
| 2710 | - else |
|
| 2711 | - $in_inbox = 1; |
|
| 2819 | + else { |
|
| 2820 | + $in_inbox = 1; |
|
| 2821 | + } |
|
| 2712 | 2822 | |
| 2713 | 2823 | // Are we adding it to or removing it from the inbox? |
| 2714 | 2824 | if ($in_inbox != $row['in_inbox']) |
@@ -2750,8 +2860,9 @@ discard block |
||
| 2750 | 2860 | if (!empty($labels_to_apply)) |
| 2751 | 2861 | { |
| 2752 | 2862 | $inserts = array(); |
| 2753 | - foreach ($labels_to_apply as $label) |
|
| 2754 | - $inserts[] = array($row['id_pm'], $label); |
|
| 2863 | + foreach ($labels_to_apply as $label) { |
|
| 2864 | + $inserts[] = array($row['id_pm'], $label); |
|
| 2865 | + } |
|
| 2755 | 2866 | |
| 2756 | 2867 | $smcFunc['db_insert']('', |
| 2757 | 2868 | '{db_prefix}pm_labeled_messages', |
@@ -2795,11 +2906,13 @@ discard block |
||
| 2795 | 2906 | checkSession('get'); |
| 2796 | 2907 | |
| 2797 | 2908 | // If all then delete all messages the user has. |
| 2798 | - if ($_REQUEST['f'] == 'all') |
|
| 2799 | - deleteMessages(null, null); |
|
| 2909 | + if ($_REQUEST['f'] == 'all') { |
|
| 2910 | + deleteMessages(null, null); |
|
| 2911 | + } |
|
| 2800 | 2912 | // Otherwise just the selected folder. |
| 2801 | - else |
|
| 2802 | - deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent'); |
|
| 2913 | + else { |
|
| 2914 | + deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent'); |
|
| 2915 | + } |
|
| 2803 | 2916 | |
| 2804 | 2917 | // Done... all gone. |
| 2805 | 2918 | redirectexit($context['current_label_redirect']); |
@@ -2836,8 +2949,9 @@ discard block |
||
| 2836 | 2949 | 'msgtime' => $deleteTime, |
| 2837 | 2950 | ) |
| 2838 | 2951 | ); |
| 2839 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 2840 | - $toDelete[] = $row[0]; |
|
| 2952 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 2953 | + $toDelete[] = $row[0]; |
|
| 2954 | + } |
|
| 2841 | 2955 | $smcFunc['db_free_result']($request); |
| 2842 | 2956 | |
| 2843 | 2957 | // Select all messages in their inbox older than $deleteTime. |
@@ -2854,8 +2968,9 @@ discard block |
||
| 2854 | 2968 | 'msgtime' => $deleteTime, |
| 2855 | 2969 | ) |
| 2856 | 2970 | ); |
| 2857 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2858 | - $toDelete[] = $row['id_pm']; |
|
| 2971 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2972 | + $toDelete[] = $row['id_pm']; |
|
| 2973 | + } |
|
| 2859 | 2974 | $smcFunc['db_free_result']($request); |
| 2860 | 2975 | |
| 2861 | 2976 | // Delete the actual messages. |
@@ -2886,26 +3001,29 @@ discard block |
||
| 2886 | 3001 | { |
| 2887 | 3002 | global $user_info, $smcFunc; |
| 2888 | 3003 | |
| 2889 | - if ($owner === null) |
|
| 2890 | - $owner = array($user_info['id']); |
|
| 2891 | - elseif (empty($owner)) |
|
| 2892 | - return; |
|
| 2893 | - elseif (!is_array($owner)) |
|
| 2894 | - $owner = array($owner); |
|
| 3004 | + if ($owner === null) { |
|
| 3005 | + $owner = array($user_info['id']); |
|
| 3006 | + } elseif (empty($owner)) { |
|
| 3007 | + return; |
|
| 3008 | + } elseif (!is_array($owner)) { |
|
| 3009 | + $owner = array($owner); |
|
| 3010 | + } |
|
| 2895 | 3011 | |
| 2896 | 3012 | if ($personal_messages !== null) |
| 2897 | 3013 | { |
| 2898 | - if (empty($personal_messages) || !is_array($personal_messages)) |
|
| 2899 | - return; |
|
| 3014 | + if (empty($personal_messages) || !is_array($personal_messages)) { |
|
| 3015 | + return; |
|
| 3016 | + } |
|
| 2900 | 3017 | |
| 2901 | - foreach ($personal_messages as $index => $delete_id) |
|
| 2902 | - $personal_messages[$index] = (int) $delete_id; |
|
| 3018 | + foreach ($personal_messages as $index => $delete_id) { |
|
| 3019 | + $personal_messages[$index] = (int) $delete_id; |
|
| 3020 | + } |
|
| 2903 | 3021 | |
| 2904 | 3022 | $where = ' |
| 2905 | 3023 | AND id_pm IN ({array_int:pm_list})'; |
| 3024 | + } else { |
|
| 3025 | + $where = ''; |
|
| 2906 | 3026 | } |
| 2907 | - else |
|
| 2908 | - $where = ''; |
|
| 2909 | 3027 | |
| 2910 | 3028 | if ($folder == 'sent' || $folder === null) |
| 2911 | 3029 | { |
@@ -2940,17 +3058,19 @@ discard block |
||
| 2940 | 3058 | // ...And update the statistics accordingly - now including unread messages!. |
| 2941 | 3059 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2942 | 3060 | { |
| 2943 | - if ($row['is_read']) |
|
| 2944 | - updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'])); |
|
| 2945 | - else |
|
| 2946 | - updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages'])); |
|
| 3061 | + if ($row['is_read']) { |
|
| 3062 | + updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'])); |
|
| 3063 | + } else { |
|
| 3064 | + updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages'])); |
|
| 3065 | + } |
|
| 2947 | 3066 | |
| 2948 | 3067 | // If this is the current member we need to make their message count correct. |
| 2949 | 3068 | if ($user_info['id'] == $row['id_member']) |
| 2950 | 3069 | { |
| 2951 | 3070 | $user_info['messages'] -= $row['num_deleted_messages']; |
| 2952 | - if (!($row['is_read'])) |
|
| 2953 | - $user_info['unread_messages'] -= $row['num_deleted_messages']; |
|
| 3071 | + if (!($row['is_read'])) { |
|
| 3072 | + $user_info['unread_messages'] -= $row['num_deleted_messages']; |
|
| 3073 | + } |
|
| 2954 | 3074 | } |
| 2955 | 3075 | } |
| 2956 | 3076 | $smcFunc['db_free_result']($request); |
@@ -3018,8 +3138,9 @@ discard block |
||
| 3018 | 3138 | ) |
| 3019 | 3139 | ); |
| 3020 | 3140 | $remove_pms = array(); |
| 3021 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 3022 | - $remove_pms[] = $row['sender']; |
|
| 3141 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 3142 | + $remove_pms[] = $row['sender']; |
|
| 3143 | + } |
|
| 3023 | 3144 | $smcFunc['db_free_result']($request); |
| 3024 | 3145 | |
| 3025 | 3146 | if (!empty($remove_pms)) |
@@ -3064,8 +3185,9 @@ discard block |
||
| 3064 | 3185 | { |
| 3065 | 3186 | global $user_info, $context, $smcFunc; |
| 3066 | 3187 | |
| 3067 | - if ($owner === null) |
|
| 3068 | - $owner = $user_info['id']; |
|
| 3188 | + if ($owner === null) { |
|
| 3189 | + $owner = $user_info['id']; |
|
| 3190 | + } |
|
| 3069 | 3191 | |
| 3070 | 3192 | $in_inbox = ''; |
| 3071 | 3193 | |
@@ -3089,8 +3211,7 @@ discard block |
||
| 3089 | 3211 | } |
| 3090 | 3212 | |
| 3091 | 3213 | $smcFunc['db_free_result']($get_messages); |
| 3092 | - } |
|
| 3093 | - elseif ($label = '-1') |
|
| 3214 | + } elseif ($label = '-1') |
|
| 3094 | 3215 | { |
| 3095 | 3216 | // Marking all PMs in your inbox read |
| 3096 | 3217 | $in_inbox = ' |
@@ -3115,8 +3236,9 @@ discard block |
||
| 3115 | 3236 | { |
| 3116 | 3237 | if ($owner == $user_info['id']) |
| 3117 | 3238 | { |
| 3118 | - foreach ($context['labels'] as $label) |
|
| 3119 | - $context['labels'][(int) $label['id']]['unread_messages'] = 0; |
|
| 3239 | + foreach ($context['labels'] as $label) { |
|
| 3240 | + $context['labels'][(int) $label['id']]['unread_messages'] = 0; |
|
| 3241 | + } |
|
| 3120 | 3242 | } |
| 3121 | 3243 | |
| 3122 | 3244 | $result = $smcFunc['db_query']('', ' |
@@ -3136,8 +3258,9 @@ discard block |
||
| 3136 | 3258 | { |
| 3137 | 3259 | $total_unread += $row['num']; |
| 3138 | 3260 | |
| 3139 | - if ($owner != $user_info['id'] || empty($row['id_pm'])) |
|
| 3140 | - continue; |
|
| 3261 | + if ($owner != $user_info['id'] || empty($row['id_pm'])) { |
|
| 3262 | + continue; |
|
| 3263 | + } |
|
| 3141 | 3264 | |
| 3142 | 3265 | $this_labels = array(); |
| 3143 | 3266 | |
@@ -3161,11 +3284,13 @@ discard block |
||
| 3161 | 3284 | |
| 3162 | 3285 | $smcFunc['db_free_result']($result2); |
| 3163 | 3286 | |
| 3164 | - foreach ($this_labels as $this_label) |
|
| 3165 | - $context['labels'][$this_label]['unread_messages'] += $row['num']; |
|
| 3287 | + foreach ($this_labels as $this_label) { |
|
| 3288 | + $context['labels'][$this_label]['unread_messages'] += $row['num']; |
|
| 3289 | + } |
|
| 3166 | 3290 | |
| 3167 | - if ($row['in_inbox'] == 1) |
|
| 3168 | - $context['labels'][-1]['unread_messages'] += $row['num']; |
|
| 3291 | + if ($row['in_inbox'] == 1) { |
|
| 3292 | + $context['labels'][-1]['unread_messages'] += $row['num']; |
|
| 3293 | + } |
|
| 3169 | 3294 | } |
| 3170 | 3295 | $smcFunc['db_free_result']($result); |
| 3171 | 3296 | |
@@ -3174,8 +3299,9 @@ discard block |
||
| 3174 | 3299 | updateMemberData($owner, array('unread_messages' => $total_unread)); |
| 3175 | 3300 | |
| 3176 | 3301 | // If it was for the current member, reflect this in the $user_info array too. |
| 3177 | - if ($owner == $user_info['id']) |
|
| 3178 | - $user_info['unread_messages'] = $total_unread; |
|
| 3302 | + if ($owner == $user_info['id']) { |
|
| 3303 | + $user_info['unread_messages'] = $total_unread; |
|
| 3304 | + } |
|
| 3179 | 3305 | } |
| 3180 | 3306 | } |
| 3181 | 3307 | |
@@ -3203,8 +3329,9 @@ discard block |
||
| 3203 | 3329 | // Add all existing labels to the array to save, slashing them as necessary... |
| 3204 | 3330 | foreach ($context['labels'] as $label) |
| 3205 | 3331 | { |
| 3206 | - if ($label['id'] != -1) |
|
| 3207 | - $the_labels[$label['id']] = $label['name']; |
|
| 3332 | + if ($label['id'] != -1) { |
|
| 3333 | + $the_labels[$label['id']] = $label['name']; |
|
| 3334 | + } |
|
| 3208 | 3335 | } |
| 3209 | 3336 | |
| 3210 | 3337 | if (isset($_POST[$context['session_var']])) |
@@ -3223,8 +3350,9 @@ discard block |
||
| 3223 | 3350 | { |
| 3224 | 3351 | $_POST['label'] = strtr($smcFunc['htmlspecialchars'](trim($_POST['label'])), array(',' => ',')); |
| 3225 | 3352 | |
| 3226 | - if ($smcFunc['strlen']($_POST['label']) > 30) |
|
| 3227 | - $_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30); |
|
| 3353 | + if ($smcFunc['strlen']($_POST['label']) > 30) { |
|
| 3354 | + $_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30); |
|
| 3355 | + } |
|
| 3228 | 3356 | if ($_POST['label'] != '') |
| 3229 | 3357 | { |
| 3230 | 3358 | $the_labels[] = $_POST['label']; |
@@ -3245,24 +3373,25 @@ discard block |
||
| 3245 | 3373 | { |
| 3246 | 3374 | foreach ($the_labels as $id => $name) |
| 3247 | 3375 | { |
| 3248 | - if ($id == -1) |
|
| 3249 | - continue; |
|
| 3250 | - elseif (isset($_POST['label_name'][$id])) |
|
| 3376 | + if ($id == -1) { |
|
| 3377 | + continue; |
|
| 3378 | + } elseif (isset($_POST['label_name'][$id])) |
|
| 3251 | 3379 | { |
| 3252 | 3380 | $_POST['label_name'][$id] = trim(strtr($smcFunc['htmlspecialchars']($_POST['label_name'][$id]), array(',' => ','))); |
| 3253 | 3381 | |
| 3254 | - if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30) |
|
| 3255 | - $_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30); |
|
| 3382 | + if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30) { |
|
| 3383 | + $_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30); |
|
| 3384 | + } |
|
| 3256 | 3385 | if ($_POST['label_name'][$id] != '') |
| 3257 | 3386 | { |
| 3258 | 3387 | // Changing the name of this label? |
| 3259 | - if ($the_labels[$id] != $_POST['label_name'][$id]) |
|
| 3260 | - $label_updates[$id] = $_POST['label_name'][$id]; |
|
| 3388 | + if ($the_labels[$id] != $_POST['label_name'][$id]) { |
|
| 3389 | + $label_updates[$id] = $_POST['label_name'][$id]; |
|
| 3390 | + } |
|
| 3261 | 3391 | |
| 3262 | 3392 | $the_labels[(int) $id] = $_POST['label_name'][$id]; |
| 3263 | 3393 | |
| 3264 | - } |
|
| 3265 | - else |
|
| 3394 | + } else |
|
| 3266 | 3395 | { |
| 3267 | 3396 | unset($the_labels[(int) $id]); |
| 3268 | 3397 | $labels_to_remove[] = $id; |
@@ -3276,8 +3405,9 @@ discard block |
||
| 3276 | 3405 | if (!empty($labels_to_add)) |
| 3277 | 3406 | { |
| 3278 | 3407 | $inserts = array(); |
| 3279 | - foreach ($labels_to_add AS $label) |
|
| 3280 | - $inserts[] = array($user_info['id'], $label); |
|
| 3408 | + foreach ($labels_to_add AS $label) { |
|
| 3409 | + $inserts[] = array($user_info['id'], $label); |
|
| 3410 | + } |
|
| 3281 | 3411 | |
| 3282 | 3412 | $smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array()); |
| 3283 | 3413 | } |
@@ -3367,8 +3497,9 @@ discard block |
||
| 3367 | 3497 | // Each action... |
| 3368 | 3498 | foreach ($rule['actions'] as $k2 => $action) |
| 3369 | 3499 | { |
| 3370 | - if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) |
|
| 3371 | - continue; |
|
| 3500 | + if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) { |
|
| 3501 | + continue; |
|
| 3502 | + } |
|
| 3372 | 3503 | |
| 3373 | 3504 | $rule_changes[] = $rule['id']; |
| 3374 | 3505 | |
@@ -3383,8 +3514,8 @@ discard block |
||
| 3383 | 3514 | { |
| 3384 | 3515 | $rule_changes = array_unique($rule_changes); |
| 3385 | 3516 | // Update/delete as appropriate. |
| 3386 | - foreach ($rule_changes as $k => $id) |
|
| 3387 | - if (!empty($context['rules'][$id]['actions'])) |
|
| 3517 | + foreach ($rule_changes as $k => $id) { |
|
| 3518 | + if (!empty($context['rules'][$id]['actions'])) |
|
| 3388 | 3519 | { |
| 3389 | 3520 | $smcFunc['db_query']('', ' |
| 3390 | 3521 | UPDATE {db_prefix}pm_rules |
@@ -3397,12 +3528,13 @@ discard block |
||
| 3397 | 3528 | 'actions' => json_encode($context['rules'][$id]['actions']), |
| 3398 | 3529 | ) |
| 3399 | 3530 | ); |
| 3531 | + } |
|
| 3400 | 3532 | unset($rule_changes[$k]); |
| 3401 | 3533 | } |
| 3402 | 3534 | |
| 3403 | 3535 | // Anything left here means it's lost all actions... |
| 3404 | - if (!empty($rule_changes)) |
|
| 3405 | - $smcFunc['db_query']('', ' |
|
| 3536 | + if (!empty($rule_changes)) { |
|
| 3537 | + $smcFunc['db_query']('', ' |
|
| 3406 | 3538 | DELETE FROM {db_prefix}pm_rules |
| 3407 | 3539 | WHERE id_rule IN ({array_int:rule_list}) |
| 3408 | 3540 | AND id_member = {int:current_member}', |
@@ -3411,6 +3543,7 @@ discard block |
||
| 3411 | 3543 | 'rule_list' => $rule_changes, |
| 3412 | 3544 | ) |
| 3413 | 3545 | ); |
| 3546 | + } |
|
| 3414 | 3547 | } |
| 3415 | 3548 | |
| 3416 | 3549 | // Make sure we're not caching this! |
@@ -3480,8 +3613,9 @@ discard block |
||
| 3480 | 3613 | // Save the fields. |
| 3481 | 3614 | saveProfileFields(); |
| 3482 | 3615 | |
| 3483 | - if (!empty($profile_vars)) |
|
| 3484 | - updateMemberData($user_info['id'], $profile_vars); |
|
| 3616 | + if (!empty($profile_vars)) { |
|
| 3617 | + updateMemberData($user_info['id'], $profile_vars); |
|
| 3618 | + } |
|
| 3485 | 3619 | } |
| 3486 | 3620 | |
| 3487 | 3621 | setupProfileContext( |
@@ -3506,13 +3640,15 @@ discard block |
||
| 3506 | 3640 | global $user_info, $language, $modSettings, $smcFunc; |
| 3507 | 3641 | |
| 3508 | 3642 | // Check that this feature is even enabled! |
| 3509 | - if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg'])) |
|
| 3510 | - fatal_lang_error('no_access', false); |
|
| 3643 | + if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg'])) { |
|
| 3644 | + fatal_lang_error('no_access', false); |
|
| 3645 | + } |
|
| 3511 | 3646 | |
| 3512 | 3647 | $pmsg = (int) $_REQUEST['pmsg']; |
| 3513 | 3648 | |
| 3514 | - if (!isAccessiblePM($pmsg, 'inbox')) |
|
| 3515 | - fatal_lang_error('no_access', false); |
|
| 3649 | + if (!isAccessiblePM($pmsg, 'inbox')) { |
|
| 3650 | + fatal_lang_error('no_access', false); |
|
| 3651 | + } |
|
| 3516 | 3652 | |
| 3517 | 3653 | $context['pm_id'] = $pmsg; |
| 3518 | 3654 | $context['page_title'] = $txt['pm_report_title']; |
@@ -3534,8 +3670,9 @@ discard block |
||
| 3534 | 3670 | ) |
| 3535 | 3671 | ); |
| 3536 | 3672 | $context['admins'] = array(); |
| 3537 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 3538 | - $context['admins'][$row['id_member']] = $row['real_name']; |
|
| 3673 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 3674 | + $context['admins'][$row['id_member']] = $row['real_name']; |
|
| 3675 | + } |
|
| 3539 | 3676 | $smcFunc['db_free_result']($request); |
| 3540 | 3677 | |
| 3541 | 3678 | // How many admins in total? |
@@ -3564,8 +3701,9 @@ discard block |
||
| 3564 | 3701 | ) |
| 3565 | 3702 | ); |
| 3566 | 3703 | // Can only be a hacker here! |
| 3567 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 3568 | - fatal_lang_error('no_access', false); |
|
| 3704 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 3705 | + fatal_lang_error('no_access', false); |
|
| 3706 | + } |
|
| 3569 | 3707 | list ($subject, $body, $time, $memberFromID, $memberFromName) = $smcFunc['db_fetch_row']($request); |
| 3570 | 3708 | $smcFunc['db_free_result']($request); |
| 3571 | 3709 | |
@@ -3589,15 +3727,17 @@ discard block |
||
| 3589 | 3727 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 3590 | 3728 | { |
| 3591 | 3729 | // If it's hidden still don't reveal their names - privacy after all ;) |
| 3592 | - if ($row['bcc']) |
|
| 3593 | - $hidden_recipients++; |
|
| 3594 | - else |
|
| 3595 | - $recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]'; |
|
| 3730 | + if ($row['bcc']) { |
|
| 3731 | + $hidden_recipients++; |
|
| 3732 | + } else { |
|
| 3733 | + $recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]'; |
|
| 3734 | + } |
|
| 3596 | 3735 | } |
| 3597 | 3736 | $smcFunc['db_free_result']($request); |
| 3598 | 3737 | |
| 3599 | - if ($hidden_recipients) |
|
| 3600 | - $recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients); |
|
| 3738 | + if ($hidden_recipients) { |
|
| 3739 | + $recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients); |
|
| 3740 | + } |
|
| 3601 | 3741 | |
| 3602 | 3742 | // Now let's get out and loop through the admins. |
| 3603 | 3743 | $request = $smcFunc['db_query']('', ' |
@@ -3613,8 +3753,9 @@ discard block |
||
| 3613 | 3753 | ); |
| 3614 | 3754 | |
| 3615 | 3755 | // Maybe we shouldn't advertise this? |
| 3616 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 3617 | - fatal_lang_error('no_access', false); |
|
| 3756 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 3757 | + fatal_lang_error('no_access', false); |
|
| 3758 | + } |
|
| 3618 | 3759 | |
| 3619 | 3760 | $memberFromName = un_htmlspecialchars($memberFromName); |
| 3620 | 3761 | |
@@ -3633,8 +3774,9 @@ discard block |
||
| 3633 | 3774 | // Make the body. |
| 3634 | 3775 | $report_body = str_replace(array('{REPORTER}', '{SENDER}'), array(un_htmlspecialchars($user_info['name']), $memberFromName), $txt['pm_report_pm_user_sent']); |
| 3635 | 3776 | $report_body .= "\n" . '[b]' . $_POST['reason'] . '[/b]' . "\n\n"; |
| 3636 | - if (!empty($recipients)) |
|
| 3637 | - $report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n"; |
|
| 3777 | + if (!empty($recipients)) { |
|
| 3778 | + $report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n"; |
|
| 3779 | + } |
|
| 3638 | 3780 | $report_body .= $txt['pm_report_pm_unedited_below'] . "\n" . '[quote author=' . (empty($memberFromID) ? '"' . $memberFromName . '"' : $memberFromName . ' link=action=profile;u=' . $memberFromID . ' date=' . $time) . ']' . "\n" . un_htmlspecialchars($body) . '[/quote]'; |
| 3639 | 3781 | |
| 3640 | 3782 | // Plonk it in the array ;) |
@@ -3654,12 +3796,14 @@ discard block |
||
| 3654 | 3796 | $smcFunc['db_free_result']($request); |
| 3655 | 3797 | |
| 3656 | 3798 | // Send a different email for each language. |
| 3657 | - foreach ($messagesToSend as $lang => $message) |
|
| 3658 | - sendpm($message['recipients'], $message['subject'], $message['body']); |
|
| 3799 | + foreach ($messagesToSend as $lang => $message) { |
|
| 3800 | + sendpm($message['recipients'], $message['subject'], $message['body']); |
|
| 3801 | + } |
|
| 3659 | 3802 | |
| 3660 | 3803 | // Give the user their own language back! |
| 3661 | - if (!empty($modSettings['userLanguage'])) |
|
| 3662 | - loadLanguage('PersonalMessage', '', false); |
|
| 3804 | + if (!empty($modSettings['userLanguage'])) { |
|
| 3805 | + loadLanguage('PersonalMessage', '', false); |
|
| 3806 | + } |
|
| 3663 | 3807 | |
| 3664 | 3808 | // Leave them with a template. |
| 3665 | 3809 | $context['sub_template'] = 'report_message_complete'; |
@@ -3705,8 +3849,9 @@ discard block |
||
| 3705 | 3849 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 3706 | 3850 | { |
| 3707 | 3851 | // Hide hidden groups! |
| 3708 | - if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) |
|
| 3709 | - continue; |
|
| 3852 | + if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) { |
|
| 3853 | + continue; |
|
| 3854 | + } |
|
| 3710 | 3855 | |
| 3711 | 3856 | $context['groups'][$row['id_group']] = $row['group_name']; |
| 3712 | 3857 | } |
@@ -3732,9 +3877,10 @@ discard block |
||
| 3732 | 3877 | $context['rule'] = $context['rules'][$context['rid']]; |
| 3733 | 3878 | $members = array(); |
| 3734 | 3879 | // Need to get member names! |
| 3735 | - foreach ($context['rule']['criteria'] as $k => $criteria) |
|
| 3736 | - if ($criteria['t'] == 'mid' && !empty($criteria['v'])) |
|
| 3880 | + foreach ($context['rule']['criteria'] as $k => $criteria) { |
|
| 3881 | + if ($criteria['t'] == 'mid' && !empty($criteria['v'])) |
|
| 3737 | 3882 | $members[(int) $criteria['v']] = $k; |
| 3883 | + } |
|
| 3738 | 3884 | |
| 3739 | 3885 | if (!empty($members)) |
| 3740 | 3886 | { |
@@ -3746,19 +3892,20 @@ discard block |
||
| 3746 | 3892 | 'member_list' => array_keys($members), |
| 3747 | 3893 | ) |
| 3748 | 3894 | ); |
| 3749 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 3750 | - $context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name']; |
|
| 3895 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 3896 | + $context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name']; |
|
| 3897 | + } |
|
| 3751 | 3898 | $smcFunc['db_free_result']($request); |
| 3752 | 3899 | } |
| 3753 | - } |
|
| 3754 | - else |
|
| 3755 | - $context['rule'] = array( |
|
| 3900 | + } else { |
|
| 3901 | + $context['rule'] = array( |
|
| 3756 | 3902 | 'id' => '', |
| 3757 | 3903 | 'name' => '', |
| 3758 | 3904 | 'criteria' => array(), |
| 3759 | 3905 | 'actions' => array(), |
| 3760 | 3906 | 'logic' => 'and', |
| 3761 | 3907 | ); |
| 3908 | + } |
|
| 3762 | 3909 | } |
| 3763 | 3910 | // Saving? |
| 3764 | 3911 | elseif (isset($_GET['save'])) |
@@ -3768,22 +3915,25 @@ discard block |
||
| 3768 | 3915 | |
| 3769 | 3916 | // Name is easy! |
| 3770 | 3917 | $ruleName = $smcFunc['htmlspecialchars'](trim($_POST['rule_name'])); |
| 3771 | - if (empty($ruleName)) |
|
| 3772 | - fatal_lang_error('pm_rule_no_name', false); |
|
| 3918 | + if (empty($ruleName)) { |
|
| 3919 | + fatal_lang_error('pm_rule_no_name', false); |
|
| 3920 | + } |
|
| 3773 | 3921 | |
| 3774 | 3922 | // Sanity check... |
| 3775 | - if (empty($_POST['ruletype']) || empty($_POST['acttype'])) |
|
| 3776 | - fatal_lang_error('pm_rule_no_criteria', false); |
|
| 3923 | + if (empty($_POST['ruletype']) || empty($_POST['acttype'])) { |
|
| 3924 | + fatal_lang_error('pm_rule_no_criteria', false); |
|
| 3925 | + } |
|
| 3777 | 3926 | |
| 3778 | 3927 | // Let's do the criteria first - it's also hardest! |
| 3779 | 3928 | $criteria = array(); |
| 3780 | 3929 | foreach ($_POST['ruletype'] as $ind => $type) |
| 3781 | 3930 | { |
| 3782 | 3931 | // Check everything is here... |
| 3783 | - if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) |
|
| 3784 | - continue; |
|
| 3785 | - elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) |
|
| 3786 | - continue; |
|
| 3932 | + if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) { |
|
| 3933 | + continue; |
|
| 3934 | + } elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) { |
|
| 3935 | + continue; |
|
| 3936 | + } |
|
| 3787 | 3937 | |
| 3788 | 3938 | // Members need to be found. |
| 3789 | 3939 | if ($type == 'mid') |
@@ -3807,13 +3957,13 @@ discard block |
||
| 3807 | 3957 | $smcFunc['db_free_result']($request); |
| 3808 | 3958 | |
| 3809 | 3959 | $criteria[] = array('t' => 'mid', 'v' => $memID); |
| 3960 | + } elseif ($type == 'bud') { |
|
| 3961 | + $criteria[] = array('t' => 'bud', 'v' => 1); |
|
| 3962 | + } elseif ($type == 'gid') { |
|
| 3963 | + $criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]); |
|
| 3964 | + } elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') { |
|
| 3965 | + $criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind]))); |
|
| 3810 | 3966 | } |
| 3811 | - elseif ($type == 'bud') |
|
| 3812 | - $criteria[] = array('t' => 'bud', 'v' => 1); |
|
| 3813 | - elseif ($type == 'gid') |
|
| 3814 | - $criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]); |
|
| 3815 | - elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') |
|
| 3816 | - $criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind]))); |
|
| 3817 | 3967 | } |
| 3818 | 3968 | |
| 3819 | 3969 | // Also do the actions! |
@@ -3823,26 +3973,29 @@ discard block |
||
| 3823 | 3973 | foreach ($_POST['acttype'] as $ind => $type) |
| 3824 | 3974 | { |
| 3825 | 3975 | // Picking a valid label? |
| 3826 | - if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]]))) |
|
| 3827 | - continue; |
|
| 3976 | + if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]]))) { |
|
| 3977 | + continue; |
|
| 3978 | + } |
|
| 3828 | 3979 | |
| 3829 | 3980 | // Record what we're doing. |
| 3830 | - if ($type == 'del') |
|
| 3831 | - $doDelete = 1; |
|
| 3832 | - elseif ($type == 'lab') |
|
| 3833 | - $actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]); |
|
| 3981 | + if ($type == 'del') { |
|
| 3982 | + $doDelete = 1; |
|
| 3983 | + } elseif ($type == 'lab') { |
|
| 3984 | + $actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]); |
|
| 3985 | + } |
|
| 3834 | 3986 | } |
| 3835 | 3987 | |
| 3836 | - if (empty($criteria) || (empty($actions) && !$doDelete)) |
|
| 3837 | - fatal_lang_error('pm_rule_no_criteria', false); |
|
| 3988 | + if (empty($criteria) || (empty($actions) && !$doDelete)) { |
|
| 3989 | + fatal_lang_error('pm_rule_no_criteria', false); |
|
| 3990 | + } |
|
| 3838 | 3991 | |
| 3839 | 3992 | // What are we storing? |
| 3840 | 3993 | $criteria = json_encode($criteria); |
| 3841 | 3994 | $actions = json_encode($actions); |
| 3842 | 3995 | |
| 3843 | 3996 | // Create the rule? |
| 3844 | - if (empty($context['rid'])) |
|
| 3845 | - $smcFunc['db_insert']('', |
|
| 3997 | + if (empty($context['rid'])) { |
|
| 3998 | + $smcFunc['db_insert']('', |
|
| 3846 | 3999 | '{db_prefix}pm_rules', |
| 3847 | 4000 | array( |
| 3848 | 4001 | 'id_member' => 'int', 'rule_name' => 'string', 'criteria' => 'string', 'actions' => 'string', |
@@ -3853,8 +4006,8 @@ discard block |
||
| 3853 | 4006 | ), |
| 3854 | 4007 | array('id_rule') |
| 3855 | 4008 | ); |
| 3856 | - else |
|
| 3857 | - $smcFunc['db_query']('', ' |
|
| 4009 | + } else { |
|
| 4010 | + $smcFunc['db_query']('', ' |
|
| 3858 | 4011 | UPDATE {db_prefix}pm_rules |
| 3859 | 4012 | SET rule_name = {string:rule_name}, criteria = {string:criteria}, actions = {string:actions}, |
| 3860 | 4013 | delete_pm = {int:delete_pm}, is_or = {int:is_or} |
@@ -3870,6 +4023,7 @@ discard block |
||
| 3870 | 4023 | 'actions' => $actions, |
| 3871 | 4024 | ) |
| 3872 | 4025 | ); |
| 4026 | + } |
|
| 3873 | 4027 | |
| 3874 | 4028 | redirectexit('action=pm;sa=manrules'); |
| 3875 | 4029 | } |
@@ -3878,11 +4032,12 @@ discard block |
||
| 3878 | 4032 | { |
| 3879 | 4033 | checkSession(); |
| 3880 | 4034 | $toDelete = array(); |
| 3881 | - foreach ($_POST['delrule'] as $k => $v) |
|
| 3882 | - $toDelete[] = (int) $k; |
|
| 4035 | + foreach ($_POST['delrule'] as $k => $v) { |
|
| 4036 | + $toDelete[] = (int) $k; |
|
| 4037 | + } |
|
| 3883 | 4038 | |
| 3884 | - if (!empty($toDelete)) |
|
| 3885 | - $smcFunc['db_query']('', ' |
|
| 4039 | + if (!empty($toDelete)) { |
|
| 4040 | + $smcFunc['db_query']('', ' |
|
| 3886 | 4041 | DELETE FROM {db_prefix}pm_rules |
| 3887 | 4042 | WHERE id_rule IN ({array_int:delete_list}) |
| 3888 | 4043 | AND id_member = {int:current_member}', |
@@ -3891,6 +4046,7 @@ discard block |
||
| 3891 | 4046 | 'delete_list' => $toDelete, |
| 3892 | 4047 | ) |
| 3893 | 4048 | ); |
| 4049 | + } |
|
| 3894 | 4050 | |
| 3895 | 4051 | redirectexit('action=pm;sa=manrules'); |
| 3896 | 4052 | } |
@@ -3909,8 +4065,9 @@ discard block |
||
| 3909 | 4065 | loadRules(); |
| 3910 | 4066 | |
| 3911 | 4067 | // No rules? |
| 3912 | - if (empty($context['rules'])) |
|
| 3913 | - return; |
|
| 4068 | + if (empty($context['rules'])) { |
|
| 4069 | + return; |
|
| 4070 | + } |
|
| 3914 | 4071 | |
| 3915 | 4072 | // Just unread ones? |
| 3916 | 4073 | $ruleQuery = $all_messages ? '' : ' AND pmr.is_new = 1'; |
@@ -3940,8 +4097,9 @@ discard block |
||
| 3940 | 4097 | // Loop through all the criteria hoping to make a match. |
| 3941 | 4098 | foreach ($rule['criteria'] as $criterium) |
| 3942 | 4099 | { |
| 3943 | - if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false)) |
|
| 3944 | - $match = true; |
|
| 4100 | + if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false)) { |
|
| 4101 | + $match = true; |
|
| 4102 | + } |
|
| 3945 | 4103 | // If we're adding and one criteria don't match then we stop! |
| 3946 | 4104 | elseif ($rule['logic'] == 'and') |
| 3947 | 4105 | { |
@@ -3953,17 +4111,18 @@ discard block |
||
| 3953 | 4111 | // If we have a match the rule must be true - act! |
| 3954 | 4112 | if ($match) |
| 3955 | 4113 | { |
| 3956 | - if ($rule['delete']) |
|
| 3957 | - $actions['deletes'][] = $row['id_pm']; |
|
| 3958 | - else |
|
| 4114 | + if ($rule['delete']) { |
|
| 4115 | + $actions['deletes'][] = $row['id_pm']; |
|
| 4116 | + } else |
|
| 3959 | 4117 | { |
| 3960 | 4118 | foreach ($rule['actions'] as $ruleAction) |
| 3961 | 4119 | { |
| 3962 | 4120 | if ($ruleAction['t'] == 'lab') |
| 3963 | 4121 | { |
| 3964 | 4122 | // Get a basic pot started! |
| 3965 | - if (!isset($actions['labels'][$row['id_pm']])) |
|
| 3966 | - $actions['labels'][$row['id_pm']] = array(); |
|
| 4123 | + if (!isset($actions['labels'][$row['id_pm']])) { |
|
| 4124 | + $actions['labels'][$row['id_pm']] = array(); |
|
| 4125 | + } |
|
| 3967 | 4126 | $actions['labels'][$row['id_pm']][] = $ruleAction['v']; |
| 3968 | 4127 | } |
| 3969 | 4128 | } |
@@ -3974,8 +4133,9 @@ discard block |
||
| 3974 | 4133 | $smcFunc['db_free_result']($request); |
| 3975 | 4134 | |
| 3976 | 4135 | // Deletes are easy! |
| 3977 | - if (!empty($actions['deletes'])) |
|
| 3978 | - deleteMessages($actions['deletes']); |
|
| 4136 | + if (!empty($actions['deletes'])) { |
|
| 4137 | + deleteMessages($actions['deletes']); |
|
| 4138 | + } |
|
| 3979 | 4139 | |
| 3980 | 4140 | // Relabel? |
| 3981 | 4141 | if (!empty($actions['labels'])) |
@@ -4002,8 +4162,7 @@ discard block |
||
| 4002 | 4162 | 'current_member' => $user_info['id'], |
| 4003 | 4163 | ) |
| 4004 | 4164 | ); |
| 4005 | - } |
|
| 4006 | - else |
|
| 4165 | + } else |
|
| 4007 | 4166 | { |
| 4008 | 4167 | $realLabels[] = $label['id']; |
| 4009 | 4168 | } |
@@ -4012,8 +4171,9 @@ discard block |
||
| 4012 | 4171 | |
| 4013 | 4172 | $inserts = array(); |
| 4014 | 4173 | // Now we insert the label info |
| 4015 | - foreach ($realLabels as $a_label) |
|
| 4016 | - $inserts[] = array($pm, $a_label); |
|
| 4174 | + foreach ($realLabels as $a_label) { |
|
| 4175 | + $inserts[] = array($pm, $a_label); |
|
| 4176 | + } |
|
| 4017 | 4177 | |
| 4018 | 4178 | $smcFunc['db_insert']('ignore', |
| 4019 | 4179 | '{db_prefix}pm_labeled_messages', |
@@ -4034,8 +4194,9 @@ discard block |
||
| 4034 | 4194 | { |
| 4035 | 4195 | global $user_info, $context, $smcFunc; |
| 4036 | 4196 | |
| 4037 | - if (isset($context['rules']) && !$reload) |
|
| 4038 | - return; |
|
| 4197 | + if (isset($context['rules']) && !$reload) { |
|
| 4198 | + return; |
|
| 4199 | + } |
|
| 4039 | 4200 | |
| 4040 | 4201 | $request = $smcFunc['db_query']('', ' |
| 4041 | 4202 | SELECT |
@@ -4059,8 +4220,9 @@ discard block |
||
| 4059 | 4220 | 'logic' => $row['is_or'] ? 'or' : 'and', |
| 4060 | 4221 | ); |
| 4061 | 4222 | |
| 4062 | - if ($row['delete_pm']) |
|
| 4063 | - $context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1); |
|
| 4223 | + if ($row['delete_pm']) { |
|
| 4224 | + $context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1); |
|
| 4225 | + } |
|
| 4064 | 4226 | } |
| 4065 | 4227 | $smcFunc['db_free_result']($request); |
| 4066 | 4228 | } |
@@ -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 | * Add the file functions to the $smcFunc array. |
@@ -52,8 +53,9 @@ discard block |
||
| 52 | 53 | 'messages', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages', |
| 53 | 54 | 'pm_recipients', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys', |
| 54 | 55 | 'themes', 'topics'); |
| 55 | - foreach ($reservedTables as $k => $table_name) |
|
| 56 | - $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
| 56 | + foreach ($reservedTables as $k => $table_name) { |
|
| 57 | + $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
| 58 | + } |
|
| 57 | 59 | |
| 58 | 60 | // We in turn may need the extra stuff. |
| 59 | 61 | db_extend('extra'); |
@@ -105,8 +107,9 @@ discard block |
||
| 105 | 107 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 106 | 108 | |
| 107 | 109 | // First - no way do we touch SMF tables. |
| 108 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
| 109 | - return false; |
|
| 110 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
| 111 | + return false; |
|
| 112 | + } |
|
| 110 | 113 | |
| 111 | 114 | // Log that we'll want to remove this on uninstall. |
| 112 | 115 | $db_package_log[] = array('remove_table', $table_name); |
@@ -116,16 +119,18 @@ discard block |
||
| 116 | 119 | if (in_array($full_table_name, $tables)) |
| 117 | 120 | { |
| 118 | 121 | // This is a sad day... drop the table? If not, return false (error) by default. |
| 119 | - if ($if_exists == 'overwrite') |
|
| 120 | - $smcFunc['db_drop_table']($table_name); |
|
| 121 | - else |
|
| 122 | - return $if_exists == 'ignore'; |
|
| 122 | + if ($if_exists == 'overwrite') { |
|
| 123 | + $smcFunc['db_drop_table']($table_name); |
|
| 124 | + } else { |
|
| 125 | + return $if_exists == 'ignore'; |
|
| 126 | + } |
|
| 123 | 127 | } |
| 124 | 128 | |
| 125 | 129 | // Righty - let's do the damn thing! |
| 126 | 130 | $table_query = 'CREATE TABLE ' . $table_name . "\n" . '('; |
| 127 | - foreach ($columns as $column) |
|
| 128 | - $table_query .= "\n\t" . smf_db_create_query_column($column) . ','; |
|
| 131 | + foreach ($columns as $column) { |
|
| 132 | + $table_query .= "\n\t" . smf_db_create_query_column($column) . ','; |
|
| 133 | + } |
|
| 129 | 134 | |
| 130 | 135 | // Loop through the indexes next... |
| 131 | 136 | foreach ($indexes as $index) |
@@ -133,19 +138,21 @@ discard block |
||
| 133 | 138 | $columns = implode(',', $index['columns']); |
| 134 | 139 | |
| 135 | 140 | // Is it the primary? |
| 136 | - if (isset($index['type']) && $index['type'] == 'primary') |
|
| 137 | - $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
| 138 | - else |
|
| 141 | + if (isset($index['type']) && $index['type'] == 'primary') { |
|
| 142 | + $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
| 143 | + } else |
|
| 139 | 144 | { |
| 140 | - if (empty($index['name'])) |
|
| 141 | - $index['name'] = implode('_', $index['columns']); |
|
| 145 | + if (empty($index['name'])) { |
|
| 146 | + $index['name'] = implode('_', $index['columns']); |
|
| 147 | + } |
|
| 142 | 148 | $table_query .= "\n\t" . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : 'KEY') . ' ' . $index['name'] . ' (' . $columns . '),'; |
| 143 | 149 | } |
| 144 | 150 | } |
| 145 | 151 | |
| 146 | 152 | // No trailing commas! |
| 147 | - if (substr($table_query, -1) == ',') |
|
| 148 | - $table_query = substr($table_query, 0, -1); |
|
| 153 | + if (substr($table_query, -1) == ',') { |
|
| 154 | + $table_query = substr($table_query, 0, -1); |
|
| 155 | + } |
|
| 149 | 156 | |
| 150 | 157 | // Which engine do we want here? |
| 151 | 158 | if (empty($engines)) |
@@ -155,8 +162,9 @@ discard block |
||
| 155 | 162 | |
| 156 | 163 | while ($row = $smcFunc['db_fetch_assoc']($get_engines)) |
| 157 | 164 | { |
| 158 | - if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') |
|
| 159 | - $engines[] = $row['Engine']; |
|
| 165 | + if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') { |
|
| 166 | + $engines[] = $row['Engine']; |
|
| 167 | + } |
|
| 160 | 168 | } |
| 161 | 169 | |
| 162 | 170 | $smcFunc['db_free_result']($get_engines); |
@@ -170,8 +178,9 @@ discard block |
||
| 170 | 178 | } |
| 171 | 179 | |
| 172 | 180 | $table_query .= ') ENGINE=' . $parameters['engine']; |
| 173 | - if (!empty($db_character_set) && $db_character_set == 'utf8') |
|
| 174 | - $table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
| 181 | + if (!empty($db_character_set) && $db_character_set == 'utf8') { |
|
| 182 | + $table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
| 183 | + } |
|
| 175 | 184 | |
| 176 | 185 | // Create the table! |
| 177 | 186 | $smcFunc['db_query']('', $table_query, |
@@ -203,8 +212,9 @@ discard block |
||
| 203 | 212 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 204 | 213 | |
| 205 | 214 | // God no - dropping one of these = bad. |
| 206 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
| 207 | - return false; |
|
| 215 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
| 216 | + return false; |
|
| 217 | + } |
|
| 208 | 218 | |
| 209 | 219 | // Does it exist? |
| 210 | 220 | if (in_array($full_table_name, $smcFunc['db_list_tables']())) |
@@ -245,14 +255,16 @@ discard block |
||
| 245 | 255 | |
| 246 | 256 | // Does it exist - if so don't add it again! |
| 247 | 257 | $columns = $smcFunc['db_list_columns']($table_name, false); |
| 248 | - foreach ($columns as $column) |
|
| 249 | - if ($column == $column_info['name']) |
|
| 258 | + foreach ($columns as $column) { |
|
| 259 | + if ($column == $column_info['name']) |
|
| 250 | 260 | { |
| 251 | 261 | // If we're going to overwrite then use change column. |
| 252 | 262 | if ($if_exists == 'update') |
| 253 | 263 | return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
| 254 | - else |
|
| 255 | - return false; |
|
| 264 | + } |
|
| 265 | + else { |
|
| 266 | + return false; |
|
| 267 | + } |
|
| 256 | 268 | } |
| 257 | 269 | |
| 258 | 270 | // Get the specifics... |
@@ -262,8 +274,9 @@ discard block |
||
| 262 | 274 | // Allow unsigned integers (mysql only) |
| 263 | 275 | $unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column_info['unsigned']) ? 'unsigned ' : ''; |
| 264 | 276 | |
| 265 | - if ($size !== null) |
|
| 266 | - $type = $type . '(' . $size . ')'; |
|
| 277 | + if ($size !== null) { |
|
| 278 | + $type = $type . '(' . $size . ')'; |
|
| 279 | + } |
|
| 267 | 280 | |
| 268 | 281 | // Now add the thing! |
| 269 | 282 | $query = ' |
@@ -295,8 +308,8 @@ discard block |
||
| 295 | 308 | |
| 296 | 309 | // Does it exist? |
| 297 | 310 | $columns = $smcFunc['db_list_columns']($table_name, true); |
| 298 | - foreach ($columns as $column) |
|
| 299 | - if ($column['name'] == $column_name) |
|
| 311 | + foreach ($columns as $column) { |
|
| 312 | + if ($column['name'] == $column_name) |
|
| 300 | 313 | { |
| 301 | 314 | $smcFunc['db_query']('', ' |
| 302 | 315 | ALTER TABLE ' . $table_name . ' |
@@ -305,6 +318,7 @@ discard block |
||
| 305 | 318 | 'security_override' => true, |
| 306 | 319 | ) |
| 307 | 320 | ); |
| 321 | + } |
|
| 308 | 322 | |
| 309 | 323 | return true; |
| 310 | 324 | } |
@@ -331,37 +345,47 @@ discard block |
||
| 331 | 345 | // Check it does exist! |
| 332 | 346 | $columns = $smcFunc['db_list_columns']($table_name, true); |
| 333 | 347 | $old_info = null; |
| 334 | - foreach ($columns as $column) |
|
| 335 | - if ($column['name'] == $old_column) |
|
| 348 | + foreach ($columns as $column) { |
|
| 349 | + if ($column['name'] == $old_column) |
|
| 336 | 350 | $old_info = $column; |
| 351 | + } |
|
| 337 | 352 | |
| 338 | 353 | // Nothing? |
| 339 | - if ($old_info == null) |
|
| 340 | - return false; |
|
| 354 | + if ($old_info == null) { |
|
| 355 | + return false; |
|
| 356 | + } |
|
| 341 | 357 | |
| 342 | 358 | // Get the right bits. |
| 343 | - if (!isset($column_info['name'])) |
|
| 344 | - $column_info['name'] = $old_column; |
|
| 345 | - if (!isset($column_info['default'])) |
|
| 346 | - $column_info['default'] = $old_info['default']; |
|
| 347 | - if (!isset($column_info['null'])) |
|
| 348 | - $column_info['null'] = $old_info['null']; |
|
| 349 | - if (!isset($column_info['auto'])) |
|
| 350 | - $column_info['auto'] = $old_info['auto']; |
|
| 351 | - if (!isset($column_info['type'])) |
|
| 352 | - $column_info['type'] = $old_info['type']; |
|
| 353 | - if (!isset($column_info['size']) || !is_numeric($column_info['size'])) |
|
| 354 | - $column_info['size'] = $old_info['size']; |
|
| 355 | - if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) |
|
| 356 | - $column_info['unsigned'] = ''; |
|
| 359 | + if (!isset($column_info['name'])) { |
|
| 360 | + $column_info['name'] = $old_column; |
|
| 361 | + } |
|
| 362 | + if (!isset($column_info['default'])) { |
|
| 363 | + $column_info['default'] = $old_info['default']; |
|
| 364 | + } |
|
| 365 | + if (!isset($column_info['null'])) { |
|
| 366 | + $column_info['null'] = $old_info['null']; |
|
| 367 | + } |
|
| 368 | + if (!isset($column_info['auto'])) { |
|
| 369 | + $column_info['auto'] = $old_info['auto']; |
|
| 370 | + } |
|
| 371 | + if (!isset($column_info['type'])) { |
|
| 372 | + $column_info['type'] = $old_info['type']; |
|
| 373 | + } |
|
| 374 | + if (!isset($column_info['size']) || !is_numeric($column_info['size'])) { |
|
| 375 | + $column_info['size'] = $old_info['size']; |
|
| 376 | + } |
|
| 377 | + if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) { |
|
| 378 | + $column_info['unsigned'] = ''; |
|
| 379 | + } |
|
| 357 | 380 | |
| 358 | 381 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); |
| 359 | 382 | |
| 360 | 383 | // Allow for unsigned integers (mysql only) |
| 361 | 384 | $unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column_info['unsigned']) ? 'unsigned ' : ''; |
| 362 | 385 | |
| 363 | - if ($size !== null) |
|
| 364 | - $type = $type . '(' . $size . ')'; |
|
| 386 | + if ($size !== null) { |
|
| 387 | + $type = $type . '(' . $size . ')'; |
|
| 388 | + } |
|
| 365 | 389 | |
| 366 | 390 | $smcFunc['db_query']('', ' |
| 367 | 391 | ALTER TABLE ' . $table_name . ' |
@@ -391,21 +415,23 @@ discard block |
||
| 391 | 415 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 392 | 416 | |
| 393 | 417 | // No columns = no index. |
| 394 | - if (empty($index_info['columns'])) |
|
| 395 | - return false; |
|
| 418 | + if (empty($index_info['columns'])) { |
|
| 419 | + return false; |
|
| 420 | + } |
|
| 396 | 421 | $columns = implode(',', $index_info['columns']); |
| 397 | 422 | |
| 398 | 423 | // No name - make it up! |
| 399 | 424 | if (empty($index_info['name'])) |
| 400 | 425 | { |
| 401 | 426 | // No need for primary. |
| 402 | - if (isset($index_info['type']) && $index_info['type'] == 'primary') |
|
| 403 | - $index_info['name'] = ''; |
|
| 404 | - else |
|
| 405 | - $index_info['name'] = implode('_', $index_info['columns']); |
|
| 427 | + if (isset($index_info['type']) && $index_info['type'] == 'primary') { |
|
| 428 | + $index_info['name'] = ''; |
|
| 429 | + } else { |
|
| 430 | + $index_info['name'] = implode('_', $index_info['columns']); |
|
| 431 | + } |
|
| 432 | + } else { |
|
| 433 | + $index_info['name'] = $index_info['name']; |
|
| 406 | 434 | } |
| 407 | - else |
|
| 408 | - $index_info['name'] = $index_info['name']; |
|
| 409 | 435 | |
| 410 | 436 | // Log that we are going to want to remove this! |
| 411 | 437 | $db_package_log[] = array('remove_index', $table_name, $index_info['name']); |
@@ -418,10 +444,11 @@ discard block |
||
| 418 | 444 | if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary')) |
| 419 | 445 | { |
| 420 | 446 | // If we want to overwrite simply remove the current one then continue. |
| 421 | - if ($if_exists != 'update' || $index['type'] == 'primary') |
|
| 422 | - return false; |
|
| 423 | - else |
|
| 424 | - $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
| 447 | + if ($if_exists != 'update' || $index['type'] == 'primary') { |
|
| 448 | + return false; |
|
| 449 | + } else { |
|
| 450 | + $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
| 451 | + } |
|
| 425 | 452 | } |
| 426 | 453 | } |
| 427 | 454 | |
@@ -435,8 +462,7 @@ discard block |
||
| 435 | 462 | 'security_override' => true, |
| 436 | 463 | ) |
| 437 | 464 | ); |
| 438 | - } |
|
| 439 | - else |
|
| 465 | + } else |
|
| 440 | 466 | { |
| 441 | 467 | $smcFunc['db_query']('', ' |
| 442 | 468 | ALTER TABLE ' . $table_name . ' |
@@ -520,8 +546,7 @@ discard block |
||
| 520 | 546 | $types = array( |
| 521 | 547 | 'inet' => 'varbinary', |
| 522 | 548 | ); |
| 523 | - } |
|
| 524 | - else |
|
| 549 | + } else |
|
| 525 | 550 | { |
| 526 | 551 | $types = array( |
| 527 | 552 | 'varbinary' => 'inet', |
@@ -535,16 +560,15 @@ discard block |
||
| 535 | 560 | { |
| 536 | 561 | $type_size = 16; |
| 537 | 562 | $type_name = 'varbinary'; |
| 538 | - } |
|
| 539 | - elseif ($type_name == 'varbinary' && $reverse && $type_size == 16) |
|
| 563 | + } elseif ($type_name == 'varbinary' && $reverse && $type_size == 16) |
|
| 540 | 564 | { |
| 541 | 565 | $type_name = 'inet'; |
| 542 | 566 | $type_size = null; |
| 567 | + } elseif ($type_name == 'varbinary') { |
|
| 568 | + $type_name = 'varbinary'; |
|
| 569 | + } else { |
|
| 570 | + $type_name = $types[$type_name]; |
|
| 543 | 571 | } |
| 544 | - elseif ($type_name == 'varbinary') |
|
| 545 | - $type_name = 'varbinary'; |
|
| 546 | - else |
|
| 547 | - $type_name = $types[$type_name]; |
|
| 548 | 572 | } |
| 549 | 573 | |
| 550 | 574 | return array($type_name, $type_size); |
@@ -612,8 +636,7 @@ discard block |
||
| 612 | 636 | if (!$detail) |
| 613 | 637 | { |
| 614 | 638 | $columns[] = $row['Field']; |
| 615 | - } |
|
| 616 | - else |
|
| 639 | + } else |
|
| 617 | 640 | { |
| 618 | 641 | // Is there an auto_increment? |
| 619 | 642 | $auto = strpos($row['Extra'], 'auto_increment') !== false ? true : false; |
@@ -623,10 +646,10 @@ discard block |
||
| 623 | 646 | { |
| 624 | 647 | $type = $matches[1]; |
| 625 | 648 | $size = $matches[2]; |
| 626 | - if (!empty($matches[3]) && $matches[3] == 'unsigned') |
|
| 627 | - $unsigned = true; |
|
| 628 | - } |
|
| 629 | - else |
|
| 649 | + if (!empty($matches[3]) && $matches[3] == 'unsigned') { |
|
| 650 | + $unsigned = true; |
|
| 651 | + } |
|
| 652 | + } else |
|
| 630 | 653 | { |
| 631 | 654 | $type = $row['Type']; |
| 632 | 655 | $size = null; |
@@ -677,19 +700,20 @@ discard block |
||
| 677 | 700 | $indexes = array(); |
| 678 | 701 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 679 | 702 | { |
| 680 | - if (!$detail) |
|
| 681 | - $indexes[] = $row['Key_name']; |
|
| 682 | - else |
|
| 703 | + if (!$detail) { |
|
| 704 | + $indexes[] = $row['Key_name']; |
|
| 705 | + } else |
|
| 683 | 706 | { |
| 684 | 707 | // What is the type? |
| 685 | - if ($row['Key_name'] == 'PRIMARY') |
|
| 686 | - $type = 'primary'; |
|
| 687 | - elseif (empty($row['Non_unique'])) |
|
| 688 | - $type = 'unique'; |
|
| 689 | - elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') |
|
| 690 | - $type = 'fulltext'; |
|
| 691 | - else |
|
| 692 | - $type = 'index'; |
|
| 708 | + if ($row['Key_name'] == 'PRIMARY') { |
|
| 709 | + $type = 'primary'; |
|
| 710 | + } elseif (empty($row['Non_unique'])) { |
|
| 711 | + $type = 'unique'; |
|
| 712 | + } elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') { |
|
| 713 | + $type = 'fulltext'; |
|
| 714 | + } else { |
|
| 715 | + $type = 'index'; |
|
| 716 | + } |
|
| 693 | 717 | |
| 694 | 718 | // This is the first column we've seen? |
| 695 | 719 | if (empty($indexes[$row['Key_name']])) |
@@ -702,10 +726,11 @@ discard block |
||
| 702 | 726 | } |
| 703 | 727 | |
| 704 | 728 | // Is it a partial index? |
| 705 | - if (!empty($row['Sub_part'])) |
|
| 706 | - $indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')'; |
|
| 707 | - else |
|
| 708 | - $indexes[$row['Key_name']]['columns'][] = $row['Column_name']; |
|
| 729 | + if (!empty($row['Sub_part'])) { |
|
| 730 | + $indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')'; |
|
| 731 | + } else { |
|
| 732 | + $indexes[$row['Key_name']]['columns'][] = $row['Column_name']; |
|
| 733 | + } |
|
| 709 | 734 | } |
| 710 | 735 | } |
| 711 | 736 | $smcFunc['db_free_result']($result); |
@@ -727,11 +752,11 @@ discard block |
||
| 727 | 752 | if (!empty($column['auto'])) |
| 728 | 753 | { |
| 729 | 754 | $default = 'auto_increment'; |
| 755 | + } elseif (isset($column['default']) && $column['default'] !== null) { |
|
| 756 | + $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
| 757 | + } else { |
|
| 758 | + $default = ''; |
|
| 730 | 759 | } |
| 731 | - elseif (isset($column['default']) && $column['default'] !== null) |
|
| 732 | - $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
| 733 | - else |
|
| 734 | - $default = ''; |
|
| 735 | 760 | |
| 736 | 761 | // Sort out the size... and stuff... |
| 737 | 762 | $column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null; |
@@ -740,8 +765,9 @@ discard block |
||
| 740 | 765 | // Allow unsigned integers (mysql only) |
| 741 | 766 | $unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column['unsigned']) ? 'unsigned ' : ''; |
| 742 | 767 | |
| 743 | - if ($size !== null) |
|
| 744 | - $type = $type . '(' . $size . ')'; |
|
| 768 | + if ($size !== null) { |
|
| 769 | + $type = $type . '(' . $size . ')'; |
|
| 770 | + } |
|
| 745 | 771 | |
| 746 | 772 | // Now just put it together! |
| 747 | 773 | return '`' .$column['name'] . '` ' . $type . ' ' . (!empty($unsigned) ? $unsigned : '') . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default; |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -34,8 +35,8 @@ discard block |
||
| 34 | 35 | global $smcFunc; |
| 35 | 36 | |
| 36 | 37 | // Map some database specific functions, only do this once. |
| 37 | - if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'postg_fetch_assoc') |
|
| 38 | - $smcFunc += array( |
|
| 38 | + if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'postg_fetch_assoc') { |
|
| 39 | + $smcFunc += array( |
|
| 39 | 40 | 'db_query' => 'smf_db_query', |
| 40 | 41 | 'db_quote' => 'smf_db_quote', |
| 41 | 42 | 'db_insert' => 'smf_db_insert', |
@@ -59,11 +60,13 @@ discard block |
||
| 59 | 60 | 'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string', |
| 60 | 61 | 'db_is_resource' => 'is_resource', |
| 61 | 62 | ); |
| 63 | + } |
|
| 62 | 64 | |
| 63 | - if (!empty($db_options['persist'])) |
|
| 64 | - $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 65 | - else |
|
| 66 | - $connection = @pg_connect( 'host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 65 | + if (!empty($db_options['persist'])) { |
|
| 66 | + $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 67 | + } else { |
|
| 68 | + $connection = @pg_connect( 'host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 69 | + } |
|
| 67 | 70 | |
| 68 | 71 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 69 | 72 | if (!$connection) |
@@ -71,8 +74,7 @@ discard block |
||
| 71 | 74 | if (!empty($db_options['non_fatal'])) |
| 72 | 75 | { |
| 73 | 76 | return null; |
| 74 | - } |
|
| 75 | - else |
|
| 77 | + } else |
|
| 76 | 78 | { |
| 77 | 79 | display_db_error(); |
| 78 | 80 | } |
@@ -123,34 +125,42 @@ discard block |
||
| 123 | 125 | |
| 124 | 126 | list ($values, $connection) = $db_callback; |
| 125 | 127 | |
| 126 | - if ($matches[1] === 'db_prefix') |
|
| 127 | - return $db_prefix; |
|
| 128 | + if ($matches[1] === 'db_prefix') { |
|
| 129 | + return $db_prefix; |
|
| 130 | + } |
|
| 128 | 131 | |
| 129 | - if ($matches[1] === 'query_see_board') |
|
| 130 | - return $user_info['query_see_board']; |
|
| 132 | + if ($matches[1] === 'query_see_board') { |
|
| 133 | + return $user_info['query_see_board']; |
|
| 134 | + } |
|
| 131 | 135 | |
| 132 | - if ($matches[1] === 'query_wanna_see_board') |
|
| 133 | - return $user_info['query_wanna_see_board']; |
|
| 136 | + if ($matches[1] === 'query_wanna_see_board') { |
|
| 137 | + return $user_info['query_wanna_see_board']; |
|
| 138 | + } |
|
| 134 | 139 | |
| 135 | - if ($matches[1] === 'empty') |
|
| 136 | - return '\'\''; |
|
| 140 | + if ($matches[1] === 'empty') { |
|
| 141 | + return '\'\''; |
|
| 142 | + } |
|
| 137 | 143 | |
| 138 | - if (!isset($matches[2])) |
|
| 139 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 144 | + if (!isset($matches[2])) { |
|
| 145 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 146 | + } |
|
| 140 | 147 | |
| 141 | - if ($matches[1] === 'literal') |
|
| 142 | - return '\'' . pg_escape_string($matches[2]) . '\''; |
|
| 148 | + if ($matches[1] === 'literal') { |
|
| 149 | + return '\'' . pg_escape_string($matches[2]) . '\''; |
|
| 150 | + } |
|
| 143 | 151 | |
| 144 | - if (!isset($values[$matches[2]])) |
|
| 145 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 152 | + if (!isset($values[$matches[2]])) { |
|
| 153 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 154 | + } |
|
| 146 | 155 | |
| 147 | 156 | $replacement = $values[$matches[2]]; |
| 148 | 157 | |
| 149 | 158 | switch ($matches[1]) |
| 150 | 159 | { |
| 151 | 160 | case 'int': |
| 152 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 153 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 161 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 162 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 163 | + } |
|
| 154 | 164 | return (string) (int) $replacement; |
| 155 | 165 | break; |
| 156 | 166 | |
@@ -162,49 +172,55 @@ discard block |
||
| 162 | 172 | case 'array_int': |
| 163 | 173 | if (is_array($replacement)) |
| 164 | 174 | { |
| 165 | - if (empty($replacement)) |
|
| 166 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 175 | + if (empty($replacement)) { |
|
| 176 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 177 | + } |
|
| 167 | 178 | |
| 168 | 179 | foreach ($replacement as $key => $value) |
| 169 | 180 | { |
| 170 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 171 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 181 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 182 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 183 | + } |
|
| 172 | 184 | |
| 173 | 185 | $replacement[$key] = (string) (int) $value; |
| 174 | 186 | } |
| 175 | 187 | |
| 176 | 188 | return implode(', ', $replacement); |
| 189 | + } else { |
|
| 190 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 177 | 191 | } |
| 178 | - else |
|
| 179 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 180 | 192 | |
| 181 | 193 | break; |
| 182 | 194 | |
| 183 | 195 | case 'array_string': |
| 184 | 196 | if (is_array($replacement)) |
| 185 | 197 | { |
| 186 | - if (empty($replacement)) |
|
| 187 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 198 | + if (empty($replacement)) { |
|
| 199 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 200 | + } |
|
| 188 | 201 | |
| 189 | - foreach ($replacement as $key => $value) |
|
| 190 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 202 | + foreach ($replacement as $key => $value) { |
|
| 203 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 204 | + } |
|
| 191 | 205 | |
| 192 | 206 | return implode(', ', $replacement); |
| 207 | + } else { |
|
| 208 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 193 | 209 | } |
| 194 | - else |
|
| 195 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 196 | 210 | break; |
| 197 | 211 | |
| 198 | 212 | case 'date': |
| 199 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
| 200 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 201 | - else |
|
| 202 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 213 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 214 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 215 | + } else { |
|
| 216 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 217 | + } |
|
| 203 | 218 | break; |
| 204 | 219 | |
| 205 | 220 | case 'float': |
| 206 | - if (!is_numeric($replacement)) |
|
| 207 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 221 | + if (!is_numeric($replacement)) { |
|
| 222 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 223 | + } |
|
| 208 | 224 | return (string) (float) $replacement; |
| 209 | 225 | break; |
| 210 | 226 | |
@@ -217,32 +233,37 @@ discard block |
||
| 217 | 233 | break; |
| 218 | 234 | |
| 219 | 235 | case 'inet': |
| 220 | - if ($replacement == 'null' || $replacement == '') |
|
| 221 | - return 'null'; |
|
| 222 | - if (inet_pton($replacement) === false) |
|
| 223 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 236 | + if ($replacement == 'null' || $replacement == '') { |
|
| 237 | + return 'null'; |
|
| 238 | + } |
|
| 239 | + if (inet_pton($replacement) === false) { |
|
| 240 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 241 | + } |
|
| 224 | 242 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
| 225 | 243 | break; |
| 226 | 244 | |
| 227 | 245 | case 'array_inet': |
| 228 | 246 | if (is_array($replacement)) |
| 229 | 247 | { |
| 230 | - if (empty($replacement)) |
|
| 231 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 248 | + if (empty($replacement)) { |
|
| 249 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 250 | + } |
|
| 232 | 251 | |
| 233 | 252 | foreach ($replacement as $key => $value) |
| 234 | 253 | { |
| 235 | - if ($replacement == 'null' || $replacement == '') |
|
| 236 | - $replacement[$key] = 'null'; |
|
| 237 | - if (!isValidIP($value)) |
|
| 238 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 254 | + if ($replacement == 'null' || $replacement == '') { |
|
| 255 | + $replacement[$key] = 'null'; |
|
| 256 | + } |
|
| 257 | + if (!isValidIP($value)) { |
|
| 258 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 259 | + } |
|
| 239 | 260 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
| 240 | 261 | } |
| 241 | 262 | |
| 242 | 263 | return implode(', ', $replacement); |
| 264 | + } else { |
|
| 265 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 243 | 266 | } |
| 244 | - else |
|
| 245 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 246 | 267 | break; |
| 247 | 268 | |
| 248 | 269 | default: |
@@ -329,14 +350,16 @@ discard block |
||
| 329 | 350 | ), |
| 330 | 351 | ); |
| 331 | 352 | |
| 332 | - if (isset($replacements[$identifier])) |
|
| 333 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 353 | + if (isset($replacements[$identifier])) { |
|
| 354 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 355 | + } |
|
| 334 | 356 | |
| 335 | 357 | // Limits need to be a little different. |
| 336 | 358 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
| 337 | 359 | |
| 338 | - if (trim($db_string) == '') |
|
| 339 | - return false; |
|
| 360 | + if (trim($db_string) == '') { |
|
| 361 | + return false; |
|
| 362 | + } |
|
| 340 | 363 | |
| 341 | 364 | // Comments that are allowed in a query are preg_removed. |
| 342 | 365 | static $allowed_comments_from = array( |
@@ -356,8 +379,9 @@ discard block |
||
| 356 | 379 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 357 | 380 | $db_replace_result = 0; |
| 358 | 381 | |
| 359 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 360 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 382 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 383 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 384 | + } |
|
| 361 | 385 | |
| 362 | 386 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
| 363 | 387 | { |
@@ -378,8 +402,9 @@ discard block |
||
| 378 | 402 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 379 | 403 | |
| 380 | 404 | // Initialize $db_cache if not already initialized. |
| 381 | - if (!isset($db_cache)) |
|
| 382 | - $db_cache = array(); |
|
| 405 | + if (!isset($db_cache)) { |
|
| 406 | + $db_cache = array(); |
|
| 407 | + } |
|
| 383 | 408 | |
| 384 | 409 | if (!empty($_SESSION['debug_redirect'])) |
| 385 | 410 | { |
@@ -405,17 +430,18 @@ discard block |
||
| 405 | 430 | while (true) |
| 406 | 431 | { |
| 407 | 432 | $pos = strpos($db_string, '\'', $pos + 1); |
| 408 | - if ($pos === false) |
|
| 409 | - break; |
|
| 433 | + if ($pos === false) { |
|
| 434 | + break; |
|
| 435 | + } |
|
| 410 | 436 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
| 411 | 437 | |
| 412 | 438 | while (true) |
| 413 | 439 | { |
| 414 | 440 | $pos1 = strpos($db_string, '\'', $pos + 1); |
| 415 | 441 | $pos2 = strpos($db_string, '\\', $pos + 1); |
| 416 | - if ($pos1 === false) |
|
| 417 | - break; |
|
| 418 | - elseif ($pos2 == false || $pos2 > $pos1) |
|
| 442 | + if ($pos1 === false) { |
|
| 443 | + break; |
|
| 444 | + } elseif ($pos2 == false || $pos2 > $pos1) |
|
| 419 | 445 | { |
| 420 | 446 | $pos = $pos1; |
| 421 | 447 | break; |
@@ -431,26 +457,31 @@ discard block |
||
| 431 | 457 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 432 | 458 | |
| 433 | 459 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 434 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 435 | - $fail = true; |
|
| 460 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 461 | + $fail = true; |
|
| 462 | + } |
|
| 436 | 463 | // Trying to change passwords, slow us down, or something? |
| 437 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 438 | - $fail = true; |
|
| 439 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 440 | - $fail = true; |
|
| 464 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 465 | + $fail = true; |
|
| 466 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 467 | + $fail = true; |
|
| 468 | + } |
|
| 441 | 469 | |
| 442 | - if (!empty($fail) && function_exists('log_error')) |
|
| 443 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 470 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 471 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 472 | + } |
|
| 444 | 473 | } |
| 445 | 474 | |
| 446 | 475 | $db_last_result = @pg_query($connection, $db_string); |
| 447 | 476 | |
| 448 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
| 449 | - $db_last_result = smf_db_error($db_string, $connection); |
|
| 477 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
| 478 | + $db_last_result = smf_db_error($db_string, $connection); |
|
| 479 | + } |
|
| 450 | 480 | |
| 451 | 481 | // Debugging. |
| 452 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 453 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 482 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 483 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 484 | + } |
|
| 454 | 485 | |
| 455 | 486 | return $db_last_result; |
| 456 | 487 | } |
@@ -463,10 +494,11 @@ discard block |
||
| 463 | 494 | { |
| 464 | 495 | global $db_last_result, $db_replace_result; |
| 465 | 496 | |
| 466 | - if ($db_replace_result) |
|
| 467 | - return $db_replace_result; |
|
| 468 | - elseif ($result === null && !$db_last_result) |
|
| 469 | - return 0; |
|
| 497 | + if ($db_replace_result) { |
|
| 498 | + return $db_replace_result; |
|
| 499 | + } elseif ($result === null && !$db_last_result) { |
|
| 500 | + return 0; |
|
| 501 | + } |
|
| 470 | 502 | |
| 471 | 503 | return pg_affected_rows($result === null ? $db_last_result : $result); |
| 472 | 504 | } |
@@ -485,16 +517,18 @@ discard block |
||
| 485 | 517 | |
| 486 | 518 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
| 487 | 519 | |
| 488 | - if ($connection === false) |
|
| 489 | - $connection = $db_connection; |
|
| 520 | + if ($connection === false) { |
|
| 521 | + $connection = $db_connection; |
|
| 522 | + } |
|
| 490 | 523 | |
| 491 | 524 | // Try get the last ID for the auto increment field. |
| 492 | 525 | $request = $smcFunc['db_query']('', 'SELECT CURRVAL(\'' . $table . '_seq\') AS insertID', |
| 493 | 526 | array( |
| 494 | 527 | ) |
| 495 | 528 | ); |
| 496 | - if (!$request) |
|
| 497 | - return false; |
|
| 529 | + if (!$request) { |
|
| 530 | + return false; |
|
| 531 | + } |
|
| 498 | 532 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
| 499 | 533 | $smcFunc['db_free_result']($request); |
| 500 | 534 | |
@@ -515,12 +549,13 @@ discard block |
||
| 515 | 549 | // Decide which connection to use |
| 516 | 550 | $connection = $connection === null ? $db_connection : $connection; |
| 517 | 551 | |
| 518 | - if ($type == 'begin') |
|
| 519 | - return @pg_query($connection, 'BEGIN'); |
|
| 520 | - elseif ($type == 'rollback') |
|
| 521 | - return @pg_query($connection, 'ROLLBACK'); |
|
| 522 | - elseif ($type == 'commit') |
|
| 523 | - return @pg_query($connection, 'COMMIT'); |
|
| 552 | + if ($type == 'begin') { |
|
| 553 | + return @pg_query($connection, 'BEGIN'); |
|
| 554 | + } elseif ($type == 'rollback') { |
|
| 555 | + return @pg_query($connection, 'ROLLBACK'); |
|
| 556 | + } elseif ($type == 'commit') { |
|
| 557 | + return @pg_query($connection, 'COMMIT'); |
|
| 558 | + } |
|
| 524 | 559 | |
| 525 | 560 | return false; |
| 526 | 561 | } |
@@ -548,19 +583,22 @@ discard block |
||
| 548 | 583 | $query_error = @pg_last_error($connection); |
| 549 | 584 | |
| 550 | 585 | // Log the error. |
| 551 | - if (function_exists('log_error')) |
|
| 552 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" .$db_string : ''), 'database', $file, $line); |
|
| 586 | + if (function_exists('log_error')) { |
|
| 587 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" .$db_string : ''), 'database', $file, $line); |
|
| 588 | + } |
|
| 553 | 589 | |
| 554 | 590 | // Nothing's defined yet... just die with it. |
| 555 | - if (empty($context) || empty($txt)) |
|
| 556 | - die($query_error); |
|
| 591 | + if (empty($context) || empty($txt)) { |
|
| 592 | + die($query_error); |
|
| 593 | + } |
|
| 557 | 594 | |
| 558 | 595 | // Show an error message, if possible. |
| 559 | 596 | $context['error_title'] = $txt['database_error']; |
| 560 | - if (allowedTo('admin_forum')) |
|
| 561 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 562 | - else |
|
| 563 | - $context['error_message'] = $txt['try_again']; |
|
| 597 | + if (allowedTo('admin_forum')) { |
|
| 598 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 599 | + } else { |
|
| 600 | + $context['error_message'] = $txt['try_again']; |
|
| 601 | + } |
|
| 564 | 602 | |
| 565 | 603 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 566 | 604 | { |
@@ -582,12 +620,14 @@ discard block |
||
| 582 | 620 | { |
| 583 | 621 | global $db_row_count; |
| 584 | 622 | |
| 585 | - if ($counter !== false) |
|
| 586 | - return pg_fetch_row($request, $counter); |
|
| 623 | + if ($counter !== false) { |
|
| 624 | + return pg_fetch_row($request, $counter); |
|
| 625 | + } |
|
| 587 | 626 | |
| 588 | 627 | // Reset the row counter... |
| 589 | - if (!isset($db_row_count[(int) $request])) |
|
| 590 | - $db_row_count[(int) $request] = 0; |
|
| 628 | + if (!isset($db_row_count[(int) $request])) { |
|
| 629 | + $db_row_count[(int) $request] = 0; |
|
| 630 | + } |
|
| 591 | 631 | |
| 592 | 632 | // Return the right row. |
| 593 | 633 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -604,12 +644,14 @@ discard block |
||
| 604 | 644 | { |
| 605 | 645 | global $db_row_count; |
| 606 | 646 | |
| 607 | - if ($counter !== false) |
|
| 608 | - return pg_fetch_assoc($request, $counter); |
|
| 647 | + if ($counter !== false) { |
|
| 648 | + return pg_fetch_assoc($request, $counter); |
|
| 649 | + } |
|
| 609 | 650 | |
| 610 | 651 | // Reset the row counter... |
| 611 | - if (!isset($db_row_count[(int) $request])) |
|
| 612 | - $db_row_count[(int) $request] = 0; |
|
| 652 | + if (!isset($db_row_count[(int) $request])) { |
|
| 653 | + $db_row_count[(int) $request] = 0; |
|
| 654 | + } |
|
| 613 | 655 | |
| 614 | 656 | // Return the right row. |
| 615 | 657 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -661,11 +703,13 @@ discard block |
||
| 661 | 703 | |
| 662 | 704 | $replace = ''; |
| 663 | 705 | |
| 664 | - if (empty($data)) |
|
| 665 | - return; |
|
| 706 | + if (empty($data)) { |
|
| 707 | + return; |
|
| 708 | + } |
|
| 666 | 709 | |
| 667 | - if (!is_array($data[array_rand($data)])) |
|
| 668 | - $data = array($data); |
|
| 710 | + if (!is_array($data[array_rand($data)])) { |
|
| 711 | + $data = array($data); |
|
| 712 | + } |
|
| 669 | 713 | |
| 670 | 714 | // Replace the prefix holder with the actual prefix. |
| 671 | 715 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -691,11 +735,13 @@ discard block |
||
| 691 | 735 | //pg 9.5 got replace support |
| 692 | 736 | $pg_version = $smcFunc['db_get_version'](); |
| 693 | 737 | // if we got a Beta Version |
| 694 | - if (stripos($pg_version, 'beta') !== false) |
|
| 695 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')).'.0'; |
|
| 738 | + if (stripos($pg_version, 'beta') !== false) { |
|
| 739 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')).'.0'; |
|
| 740 | + } |
|
| 696 | 741 | // or RC |
| 697 | - if (stripos($pg_version, 'rc') !== false) |
|
| 698 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')).'.0'; |
|
| 742 | + if (stripos($pg_version, 'rc') !== false) { |
|
| 743 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')).'.0'; |
|
| 744 | + } |
|
| 699 | 745 | |
| 700 | 746 | $replace_support = (version_compare($pg_version,'9.5.0','>=') ? true : false); |
| 701 | 747 | } |
@@ -714,8 +760,7 @@ discard block |
||
| 714 | 760 | $key_str .= ($count_pk > 0 ? ',' : ''); |
| 715 | 761 | $key_str .= $columnName; |
| 716 | 762 | $count_pk++; |
| 717 | - } |
|
| 718 | - else //normal field |
|
| 763 | + } else //normal field |
|
| 719 | 764 | { |
| 720 | 765 | $col_str .= ($count > 0 ? ',' : ''); |
| 721 | 766 | $col_str .= $columnName.' = EXCLUDED.'.$columnName; |
@@ -723,20 +768,21 @@ discard block |
||
| 723 | 768 | } |
| 724 | 769 | } |
| 725 | 770 | $replace = ' ON CONFLICT ('.$key_str.') DO UPDATE SET '.$col_str; |
| 726 | - } |
|
| 727 | - else |
|
| 771 | + } else |
|
| 728 | 772 | { |
| 729 | 773 | foreach ($columns as $columnName => $type) |
| 730 | 774 | { |
| 731 | 775 | // Are we restricting the length? |
| 732 | - if (strpos($type, 'string-') !== false) |
|
| 733 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 734 | - else |
|
| 735 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 776 | + if (strpos($type, 'string-') !== false) { |
|
| 777 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 778 | + } else { |
|
| 779 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 780 | + } |
|
| 736 | 781 | |
| 737 | 782 | // A key? That's what we were looking for. |
| 738 | - if (in_array($columnName, $keys)) |
|
| 739 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 783 | + if (in_array($columnName, $keys)) { |
|
| 784 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 785 | + } |
|
| 740 | 786 | $count++; |
| 741 | 787 | } |
| 742 | 788 | |
@@ -762,10 +808,11 @@ discard block |
||
| 762 | 808 | foreach ($columns as $columnName => $type) |
| 763 | 809 | { |
| 764 | 810 | // Are we restricting the length? |
| 765 | - if (strpos($type, 'string-') !== false) |
|
| 766 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 767 | - else |
|
| 768 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 811 | + if (strpos($type, 'string-') !== false) { |
|
| 812 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 813 | + } else { |
|
| 814 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 815 | + } |
|
| 769 | 816 | } |
| 770 | 817 | $insertData = substr($insertData, 0, -2) . ')'; |
| 771 | 818 | |
@@ -774,11 +821,12 @@ discard block |
||
| 774 | 821 | |
| 775 | 822 | // Here's where the variables are injected to the query. |
| 776 | 823 | $insertRows = array(); |
| 777 | - foreach ($data as $dataRow) |
|
| 778 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 824 | + foreach ($data as $dataRow) { |
|
| 825 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 826 | + } |
|
| 779 | 827 | |
| 780 | - foreach ($insertRows as $entry) |
|
| 781 | - // Do the insert. |
|
| 828 | + foreach ($insertRows as $entry) { |
|
| 829 | + // Do the insert. |
|
| 782 | 830 | $smcFunc['db_query']('', ' |
| 783 | 831 | INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '") |
| 784 | 832 | VALUES |
@@ -789,11 +837,13 @@ discard block |
||
| 789 | 837 | ), |
| 790 | 838 | $connection |
| 791 | 839 | ); |
| 840 | + } |
|
| 792 | 841 | } |
| 793 | 842 | |
| 794 | - if ($priv_trans) |
|
| 795 | - $smcFunc['db_transaction']('commit', $connection); |
|
| 796 | -} |
|
| 843 | + if ($priv_trans) { |
|
| 844 | + $smcFunc['db_transaction']('commit', $connection); |
|
| 845 | + } |
|
| 846 | + } |
|
| 797 | 847 | |
| 798 | 848 | /** |
| 799 | 849 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -830,8 +880,9 @@ discard block |
||
| 830 | 880 | */ |
| 831 | 881 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 832 | 882 | { |
| 833 | - if (empty($log_message)) |
|
| 834 | - $log_message = $error_message; |
|
| 883 | + if (empty($log_message)) { |
|
| 884 | + $log_message = $error_message; |
|
| 885 | + } |
|
| 835 | 886 | |
| 836 | 887 | foreach (debug_backtrace() as $step) |
| 837 | 888 | { |
@@ -850,12 +901,14 @@ discard block |
||
| 850 | 901 | } |
| 851 | 902 | |
| 852 | 903 | // A special case - we want the file and line numbers for debugging. |
| 853 | - if ($error_type == 'return') |
|
| 854 | - return array($file, $line); |
|
| 904 | + if ($error_type == 'return') { |
|
| 905 | + return array($file, $line); |
|
| 906 | + } |
|
| 855 | 907 | |
| 856 | 908 | // Is always a critical error. |
| 857 | - if (function_exists('log_error')) |
|
| 858 | - log_error($log_message, 'critical', $file, $line); |
|
| 909 | + if (function_exists('log_error')) { |
|
| 910 | + log_error($log_message, 'critical', $file, $line); |
|
| 911 | + } |
|
| 859 | 912 | |
| 860 | 913 | if (function_exists('fatal_error')) |
| 861 | 914 | { |
@@ -863,12 +916,12 @@ discard block |
||
| 863 | 916 | |
| 864 | 917 | // Cannot continue... |
| 865 | 918 | exit; |
| 919 | + } elseif ($error_type) { |
|
| 920 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 921 | + } else { |
|
| 922 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 923 | + } |
|
| 866 | 924 | } |
| 867 | - elseif ($error_type) |
|
| 868 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 869 | - else |
|
| 870 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 871 | -} |
|
| 872 | 925 | |
| 873 | 926 | /** |
| 874 | 927 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -885,10 +938,11 @@ discard block |
||
| 885 | 938 | '\\' => '\\\\', |
| 886 | 939 | ); |
| 887 | 940 | |
| 888 | - if ($translate_human_wildcards) |
|
| 889 | - $replacements += array( |
|
| 941 | + if ($translate_human_wildcards) { |
|
| 942 | + $replacements += array( |
|
| 890 | 943 | '*' => '%', |
| 891 | 944 | ); |
| 945 | + } |
|
| 892 | 946 | |
| 893 | 947 | return strtr($string, $replacements); |
| 894 | 948 | } |
@@ -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 | loadLanguage('Drafts'); |
| 21 | 22 | |
@@ -33,8 +34,9 @@ discard block |
||
| 33 | 34 | global $context, $user_info, $smcFunc, $modSettings, $board; |
| 34 | 35 | |
| 35 | 36 | // can you be, should you be ... here? |
| 36 | - if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) |
|
| 37 | - return false; |
|
| 37 | + if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) { |
|
| 38 | + return false; |
|
| 39 | + } |
|
| 38 | 40 | |
| 39 | 41 | // read in what they sent us, if anything |
| 40 | 42 | $id_draft = (int) $_POST['id_draft']; |
@@ -46,14 +48,16 @@ discard block |
||
| 46 | 48 | $context['draft_saved_on'] = $draft_info['poster_time']; |
| 47 | 49 | |
| 48 | 50 | // since we were called from the autosave function, send something back |
| 49 | - if (!empty($id_draft)) |
|
| 50 | - XmlDraft($id_draft); |
|
| 51 | + if (!empty($id_draft)) { |
|
| 52 | + XmlDraft($id_draft); |
|
| 53 | + } |
|
| 51 | 54 | |
| 52 | 55 | return true; |
| 53 | 56 | } |
| 54 | 57 | |
| 55 | - if (!isset($_POST['message'])) |
|
| 56 | - $_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : ''; |
|
| 58 | + if (!isset($_POST['message'])) { |
|
| 59 | + $_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : ''; |
|
| 60 | + } |
|
| 57 | 61 | |
| 58 | 62 | // prepare any data from the form |
| 59 | 63 | $topic_id = empty($_REQUEST['topic']) ? 0 : (int) $_REQUEST['topic']; |
@@ -66,8 +70,9 @@ discard block |
||
| 66 | 70 | |
| 67 | 71 | // message and subject still need a bit more work |
| 68 | 72 | preparsecode($draft['body']); |
| 69 | - if ($smcFunc['strlen']($draft['subject']) > 100) |
|
| 70 | - $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
| 73 | + if ($smcFunc['strlen']($draft['subject']) > 100) { |
|
| 74 | + $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
| 75 | + } |
|
| 71 | 76 | |
| 72 | 77 | // Modifying an existing draft, like hitting the save draft button or autosave enabled? |
| 73 | 78 | if (!empty($id_draft) && !empty($draft_info) && $draft_info['id_member'] == $user_info['id']) |
@@ -150,9 +155,9 @@ discard block |
||
| 150 | 155 | { |
| 151 | 156 | $context['draft_saved'] = true; |
| 152 | 157 | $context['id_draft'] = $id_draft; |
| 158 | + } else { |
|
| 159 | + $post_errors[] = 'draft_not_saved'; |
|
| 153 | 160 | } |
| 154 | - else |
|
| 155 | - $post_errors[] = 'draft_not_saved'; |
|
| 156 | 161 | |
| 157 | 162 | // cleanup |
| 158 | 163 | unset($_POST['save_draft']); |
@@ -182,8 +187,9 @@ discard block |
||
| 182 | 187 | global $context, $user_info, $smcFunc, $modSettings; |
| 183 | 188 | |
| 184 | 189 | // PM survey says ... can you stay or must you go |
| 185 | - if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) |
|
| 186 | - return false; |
|
| 190 | + if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) { |
|
| 191 | + return false; |
|
| 192 | + } |
|
| 187 | 193 | |
| 188 | 194 | // read in what you sent us |
| 189 | 195 | $id_pm_draft = (int) $_POST['id_pm_draft']; |
@@ -195,8 +201,9 @@ discard block |
||
| 195 | 201 | $context['draft_saved_on'] = $draft_info['poster_time']; |
| 196 | 202 | |
| 197 | 203 | // Send something back to the javascript caller |
| 198 | - if (!empty($id_draft)) |
|
| 199 | - XmlDraft($id_draft); |
|
| 204 | + if (!empty($id_draft)) { |
|
| 205 | + XmlDraft($id_draft); |
|
| 206 | + } |
|
| 200 | 207 | |
| 201 | 208 | return true; |
| 202 | 209 | } |
@@ -206,9 +213,9 @@ discard block |
||
| 206 | 213 | { |
| 207 | 214 | $recipientList['to'] = isset($_POST['recipient_to']) ? explode(',', $_POST['recipient_to']) : array(); |
| 208 | 215 | $recipientList['bcc'] = isset($_POST['recipient_bcc']) ? explode(',', $_POST['recipient_bcc']) : array(); |
| 216 | + } elseif (!empty($draft_info['to_list']) && empty($recipientList)) { |
|
| 217 | + $recipientList = smf_json_decode($draft_info['to_list'], true); |
|
| 209 | 218 | } |
| 210 | - elseif (!empty($draft_info['to_list']) && empty($recipientList)) |
|
| 211 | - $recipientList = smf_json_decode($draft_info['to_list'], true); |
|
| 212 | 219 | |
| 213 | 220 | // prepare the data we got from the form |
| 214 | 221 | $reply_id = empty($_POST['replied_to']) ? 0 : (int) $_POST['replied_to']; |
@@ -217,8 +224,9 @@ discard block |
||
| 217 | 224 | |
| 218 | 225 | // message and subject always need a bit more work |
| 219 | 226 | preparsecode($draft['body']); |
| 220 | - if ($smcFunc['strlen']($draft['subject']) > 100) |
|
| 221 | - $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
| 227 | + if ($smcFunc['strlen']($draft['subject']) > 100) { |
|
| 228 | + $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
| 229 | + } |
|
| 222 | 230 | |
| 223 | 231 | // Modifying an existing PM draft? |
| 224 | 232 | if (!empty($id_pm_draft) && !empty($draft_info) && $draft_info['id_member'] == $user_info['id']) |
@@ -284,9 +292,9 @@ discard block |
||
| 284 | 292 | { |
| 285 | 293 | $context['draft_saved'] = true; |
| 286 | 294 | $context['id_pm_draft'] = $id_pm_draft; |
| 295 | + } else { |
|
| 296 | + $post_errors[] = 'draft_not_saved'; |
|
| 287 | 297 | } |
| 288 | - else |
|
| 289 | - $post_errors[] = 'draft_not_saved'; |
|
| 290 | 298 | } |
| 291 | 299 | |
| 292 | 300 | // if we were called from the autosave function, send something back |
@@ -319,8 +327,9 @@ discard block |
||
| 319 | 327 | $type = (int) $type; |
| 320 | 328 | |
| 321 | 329 | // nothing to read, nothing to do |
| 322 | - if (empty($id_draft)) |
|
| 323 | - return false; |
|
| 330 | + if (empty($id_draft)) { |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 324 | 333 | |
| 325 | 334 | // load in this draft from the DB |
| 326 | 335 | $request = $smcFunc['db_query']('', ' |
@@ -340,8 +349,9 @@ discard block |
||
| 340 | 349 | ); |
| 341 | 350 | |
| 342 | 351 | // no results? |
| 343 | - if (!$smcFunc['db_num_rows']($request)) |
|
| 344 | - return false; |
|
| 352 | + if (!$smcFunc['db_num_rows']($request)) { |
|
| 353 | + return false; |
|
| 354 | + } |
|
| 345 | 355 | |
| 346 | 356 | // load up the data |
| 347 | 357 | $draft_info = $smcFunc['db_fetch_assoc']($request); |
@@ -362,8 +372,7 @@ discard block |
||
| 362 | 372 | $context['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : ''; |
| 363 | 373 | $context['board'] = !empty($draft_info['board_id']) ? $draft_info['id_board'] : ''; |
| 364 | 374 | $context['id_draft'] = !empty($draft_info['id_draft']) ? $draft_info['id_draft'] : 0; |
| 365 | - } |
|
| 366 | - elseif ($type === 1) |
|
| 375 | + } elseif ($type === 1) |
|
| 367 | 376 | { |
| 368 | 377 | // one of those pm drafts? then set it up like we have an error |
| 369 | 378 | $_REQUEST['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : ''; |
@@ -399,12 +408,14 @@ discard block |
||
| 399 | 408 | global $user_info, $smcFunc; |
| 400 | 409 | |
| 401 | 410 | // Only a single draft. |
| 402 | - if (is_numeric($id_draft)) |
|
| 403 | - $id_draft = array($id_draft); |
|
| 411 | + if (is_numeric($id_draft)) { |
|
| 412 | + $id_draft = array($id_draft); |
|
| 413 | + } |
|
| 404 | 414 | |
| 405 | 415 | // can't delete nothing |
| 406 | - if (empty($id_draft) || ($check && empty($user_info['id']))) |
|
| 407 | - return false; |
|
| 416 | + if (empty($id_draft) || ($check && empty($user_info['id']))) { |
|
| 417 | + return false; |
|
| 418 | + } |
|
| 408 | 419 | |
| 409 | 420 | $smcFunc['db_query']('', ' |
| 410 | 421 | DELETE FROM {db_prefix}user_drafts |
@@ -433,14 +444,16 @@ discard block |
||
| 433 | 444 | global $smcFunc, $scripturl, $context, $txt, $modSettings; |
| 434 | 445 | |
| 435 | 446 | // Permissions |
| 436 | - if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) |
|
| 437 | - return false; |
|
| 447 | + if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) { |
|
| 448 | + return false; |
|
| 449 | + } |
|
| 438 | 450 | |
| 439 | 451 | $context['drafts'] = array(); |
| 440 | 452 | |
| 441 | 453 | // has a specific draft has been selected? Load it up if there is not a message already in the editor |
| 442 | - if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) |
|
| 443 | - ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true); |
|
| 454 | + if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) { |
|
| 455 | + ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true); |
|
| 456 | + } |
|
| 444 | 457 | |
| 445 | 458 | // load the drafts this user has available |
| 446 | 459 | $request = $smcFunc['db_query']('', ' |
@@ -463,23 +476,26 @@ discard block |
||
| 463 | 476 | // add them to the draft array for display |
| 464 | 477 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 465 | 478 | { |
| 466 | - if (empty($row['subject'])) |
|
| 467 | - $row['subject'] = $txt['no_subject']; |
|
| 479 | + if (empty($row['subject'])) { |
|
| 480 | + $row['subject'] = $txt['no_subject']; |
|
| 481 | + } |
|
| 468 | 482 | |
| 469 | 483 | // Post drafts |
| 470 | - if ($draft_type === 0) |
|
| 471 | - $context['drafts'][] = array( |
|
| 484 | + if ($draft_type === 0) { |
|
| 485 | + $context['drafts'][] = array( |
|
| 472 | 486 | 'subject' => censorText(shorten_subject(stripslashes($row['subject']), 24)), |
| 473 | 487 | 'poster_time' => timeformat($row['poster_time']), |
| 474 | 488 | 'link' => '<a href="' . $scripturl . '?action=post;board=' . $row['id_board'] . ';' . (!empty($row['id_topic']) ? 'topic='. $row['id_topic'] .'.0;' : '') . 'id_draft=' . $row['id_draft'] . '">' . $row['subject'] . '</a>', |
| 475 | 489 | ); |
| 490 | + } |
|
| 476 | 491 | // PM drafts |
| 477 | - elseif ($draft_type === 1) |
|
| 478 | - $context['drafts'][] = array( |
|
| 492 | + elseif ($draft_type === 1) { |
|
| 493 | + $context['drafts'][] = array( |
|
| 479 | 494 | 'subject' => censorText(shorten_subject(stripslashes($row['subject']), 24)), |
| 480 | 495 | 'poster_time' => timeformat($row['poster_time']), |
| 481 | 496 | 'link' => '<a href="' . $scripturl . '?action=pm;sa=send;id_draft=' . $row['id_draft'] . '">' . (!empty($row['subject']) ? $row['subject'] : $txt['drafts_none']) . '</a>', |
| 482 | 497 | ); |
| 498 | + } |
|
| 483 | 499 | } |
| 484 | 500 | $smcFunc['db_free_result']($request); |
| 485 | 501 | } |
@@ -543,8 +559,9 @@ discard block |
||
| 543 | 559 | } |
| 544 | 560 | |
| 545 | 561 | // Default to 10. |
| 546 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
| 547 | - $_REQUEST['viewscount'] = 10; |
|
| 562 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
| 563 | + $_REQUEST['viewscount'] = 10; |
|
| 564 | + } |
|
| 548 | 565 | |
| 549 | 566 | // Get the count of applicable drafts on the boards they can (still) see ... |
| 550 | 567 | // @todo .. should we just let them see their drafts even if they have lost board access ? |
@@ -609,12 +626,14 @@ discard block |
||
| 609 | 626 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 610 | 627 | { |
| 611 | 628 | // Censor.... |
| 612 | - if (empty($row['body'])) |
|
| 613 | - $row['body'] = ''; |
|
| 629 | + if (empty($row['body'])) { |
|
| 630 | + $row['body'] = ''; |
|
| 631 | + } |
|
| 614 | 632 | |
| 615 | 633 | $row['subject'] = $smcFunc['htmltrim']($row['subject']); |
| 616 | - if (empty($row['subject'])) |
|
| 617 | - $row['subject'] = $txt['no_subject']; |
|
| 634 | + if (empty($row['subject'])) { |
|
| 635 | + $row['subject'] = $txt['no_subject']; |
|
| 636 | + } |
|
| 618 | 637 | |
| 619 | 638 | censorText($row['body']); |
| 620 | 639 | censorText($row['subject']); |
@@ -646,8 +665,9 @@ discard block |
||
| 646 | 665 | $smcFunc['db_free_result']($request); |
| 647 | 666 | |
| 648 | 667 | // If the drafts were retrieved in reverse order, get them right again. |
| 649 | - if ($reverse) |
|
| 650 | - $context['drafts'] = array_reverse($context['drafts'], true); |
|
| 668 | + if ($reverse) { |
|
| 669 | + $context['drafts'] = array_reverse($context['drafts'], true); |
|
| 670 | + } |
|
| 651 | 671 | |
| 652 | 672 | // Menu tab |
| 653 | 673 | $context[$context['profile_menu_name']]['tab_data'] = array( |
@@ -705,8 +725,9 @@ discard block |
||
| 705 | 725 | } |
| 706 | 726 | |
| 707 | 727 | // Default to 10. |
| 708 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
| 709 | - $_REQUEST['viewscount'] = 10; |
|
| 728 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
| 729 | + $_REQUEST['viewscount'] = 10; |
|
| 730 | + } |
|
| 710 | 731 | |
| 711 | 732 | // Get the count of applicable drafts |
| 712 | 733 | $request = $smcFunc['db_query']('', ' |
@@ -765,12 +786,14 @@ discard block |
||
| 765 | 786 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 766 | 787 | { |
| 767 | 788 | // Censor.... |
| 768 | - if (empty($row['body'])) |
|
| 769 | - $row['body'] = ''; |
|
| 789 | + if (empty($row['body'])) { |
|
| 790 | + $row['body'] = ''; |
|
| 791 | + } |
|
| 770 | 792 | |
| 771 | 793 | $row['subject'] = $smcFunc['htmltrim']($row['subject']); |
| 772 | - if (empty($row['subject'])) |
|
| 773 | - $row['subject'] = $txt['no_subject']; |
|
| 794 | + if (empty($row['subject'])) { |
|
| 795 | + $row['subject'] = $txt['no_subject']; |
|
| 796 | + } |
|
| 774 | 797 | |
| 775 | 798 | censorText($row['body']); |
| 776 | 799 | censorText($row['subject']); |
@@ -825,8 +848,9 @@ discard block |
||
| 825 | 848 | $smcFunc['db_free_result']($request); |
| 826 | 849 | |
| 827 | 850 | // if the drafts were retrieved in reverse order, then put them in the right order again. |
| 828 | - if ($reverse) |
|
| 829 | - $context['drafts'] = array_reverse($context['drafts'], true); |
|
| 851 | + if ($reverse) { |
|
| 852 | + $context['drafts'] = array_reverse($context['drafts'], true); |
|
| 853 | + } |
|
| 830 | 854 | |
| 831 | 855 | // off to the template we go |
| 832 | 856 | $context['page_title'] = $txt['drafts']; |
@@ -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 | * Locks a topic... either by way of a moderator or the topic starter. |
@@ -32,8 +33,9 @@ discard block |
||
| 32 | 33 | global $topic, $user_info, $sourcedir, $board, $smcFunc; |
| 33 | 34 | |
| 34 | 35 | // Just quit if there's no topic to lock. |
| 35 | - if (empty($topic)) |
|
| 36 | - fatal_lang_error('not_a_topic', false); |
|
| 36 | + if (empty($topic)) { |
|
| 37 | + fatal_lang_error('not_a_topic', false); |
|
| 38 | + } |
|
| 37 | 39 | |
| 38 | 40 | checkSession('get'); |
| 39 | 41 | |
@@ -55,23 +57,28 @@ discard block |
||
| 55 | 57 | |
| 56 | 58 | // Can you lock topics here, mister? |
| 57 | 59 | $user_lock = !allowedTo('lock_any'); |
| 58 | - if ($user_lock && $starter == $user_info['id']) |
|
| 59 | - isAllowedTo('lock_own'); |
|
| 60 | - else |
|
| 61 | - isAllowedTo('lock_any'); |
|
| 60 | + if ($user_lock && $starter == $user_info['id']) { |
|
| 61 | + isAllowedTo('lock_own'); |
|
| 62 | + } else { |
|
| 63 | + isAllowedTo('lock_any'); |
|
| 64 | + } |
|
| 62 | 65 | |
| 63 | 66 | // Locking with high privileges. |
| 64 | - if ($locked == '0' && !$user_lock) |
|
| 65 | - $locked = '1'; |
|
| 67 | + if ($locked == '0' && !$user_lock) { |
|
| 68 | + $locked = '1'; |
|
| 69 | + } |
|
| 66 | 70 | // Locking with low privileges. |
| 67 | - elseif ($locked == '0') |
|
| 68 | - $locked = '2'; |
|
| 71 | + elseif ($locked == '0') { |
|
| 72 | + $locked = '2'; |
|
| 73 | + } |
|
| 69 | 74 | // Unlocking - make sure you don't unlock what you can't. |
| 70 | - elseif ($locked == '2' || ($locked == '1' && !$user_lock)) |
|
| 71 | - $locked = '0'; |
|
| 75 | + elseif ($locked == '2' || ($locked == '1' && !$user_lock)) { |
|
| 76 | + $locked = '0'; |
|
| 77 | + } |
|
| 72 | 78 | // You cannot unlock this! |
| 73 | - else |
|
| 74 | - fatal_lang_error('locked_by_admin', 'user'); |
|
| 79 | + else { |
|
| 80 | + fatal_lang_error('locked_by_admin', 'user'); |
|
| 81 | + } |
|
| 75 | 82 | |
| 76 | 83 | // Actually lock the topic in the database with the new value. |
| 77 | 84 | $smcFunc['db_query']('', ' |
@@ -85,8 +92,9 @@ discard block |
||
| 85 | 92 | ); |
| 86 | 93 | |
| 87 | 94 | // If they are allowed a "moderator" permission, log it in the moderator log. |
| 88 | - if (!$user_lock) |
|
| 89 | - logAction($locked ? 'lock' : 'unlock', array('topic' => $topic, 'board' => $board)); |
|
| 95 | + if (!$user_lock) { |
|
| 96 | + logAction($locked ? 'lock' : 'unlock', array('topic' => $topic, 'board' => $board)); |
|
| 97 | + } |
|
| 90 | 98 | // Notify people that this topic has been locked? |
| 91 | 99 | sendNotifications($topic, empty($locked) ? 'unlock' : 'lock'); |
| 92 | 100 | |
@@ -112,8 +120,9 @@ discard block |
||
| 112 | 120 | isAllowedTo('make_sticky'); |
| 113 | 121 | |
| 114 | 122 | // You can't sticky a board or something! |
| 115 | - if (empty($topic)) |
|
| 116 | - fatal_lang_error('not_a_topic', false); |
|
| 123 | + if (empty($topic)) { |
|
| 124 | + fatal_lang_error('not_a_topic', false); |
|
| 125 | + } |
|
| 117 | 126 | |
| 118 | 127 | checkSession('get'); |
| 119 | 128 | |
@@ -147,8 +156,9 @@ discard block |
||
| 147 | 156 | // Log this sticky action - always a moderator thing. |
| 148 | 157 | logAction(empty($is_sticky) ? 'sticky' : 'unsticky', array('topic' => $topic, 'board' => $board)); |
| 149 | 158 | // Notify people that this topic has been stickied? |
| 150 | - if (empty($is_sticky)) |
|
| 151 | - sendNotifications($topic, 'sticky'); |
|
| 159 | + if (empty($is_sticky)) { |
|
| 160 | + sendNotifications($topic, 'sticky'); |
|
| 161 | + } |
|
| 152 | 162 | |
| 153 | 163 | // Take them back to the now stickied topic. |
| 154 | 164 | redirectexit('topic=' . $topic . '.' . $_REQUEST['start'] . ';moderate'); |
@@ -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 main function for the languages area. |
@@ -153,11 +154,11 @@ discard block |
||
| 153 | 154 | $language_list = new xmlArray(fetch_web_data($url), true); |
| 154 | 155 | |
| 155 | 156 | // Check that the site responded and that the language exists. |
| 156 | - if (!$language_list->exists('languages')) |
|
| 157 | - $context['smf_error'] = 'no_response'; |
|
| 158 | - elseif (!$language_list->exists('languages/language')) |
|
| 159 | - $context['smf_error'] = 'no_files'; |
|
| 160 | - else |
|
| 157 | + if (!$language_list->exists('languages')) { |
|
| 158 | + $context['smf_error'] = 'no_response'; |
|
| 159 | + } elseif (!$language_list->exists('languages/language')) { |
|
| 160 | + $context['smf_error'] = 'no_files'; |
|
| 161 | + } else |
|
| 161 | 162 | { |
| 162 | 163 | $language_list = $language_list->path('languages[0]'); |
| 163 | 164 | $lang_files = $language_list->set('language'); |
@@ -165,8 +166,9 @@ discard block |
||
| 165 | 166 | foreach ($lang_files as $file) |
| 166 | 167 | { |
| 167 | 168 | // Were we searching? |
| 168 | - if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false) |
|
| 169 | - continue; |
|
| 169 | + if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false) { |
|
| 170 | + continue; |
|
| 171 | + } |
|
| 170 | 172 | |
| 171 | 173 | $smf_languages[] = array( |
| 172 | 174 | 'id' => $file->fetch('id'), |
@@ -177,10 +179,11 @@ discard block |
||
| 177 | 179 | 'install_link' => '<a href="' . $scripturl . '?action=admin;area=languages;sa=downloadlang;did=' . $file->fetch('id') . ';' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['add_language_smf_install'] . '</a>', |
| 178 | 180 | ); |
| 179 | 181 | } |
| 180 | - if (empty($smf_languages)) |
|
| 181 | - $context['smf_error'] = 'no_files'; |
|
| 182 | - else |
|
| 183 | - return $smf_languages; |
|
| 182 | + if (empty($smf_languages)) { |
|
| 183 | + $context['smf_error'] = 'no_files'; |
|
| 184 | + } else { |
|
| 185 | + return $smf_languages; |
|
| 186 | + } |
|
| 184 | 187 | } |
| 185 | 188 | } |
| 186 | 189 | |
@@ -202,8 +205,9 @@ discard block |
||
| 202 | 205 | require_once($sourcedir . '/Subs-Package.php'); |
| 203 | 206 | |
| 204 | 207 | // Clearly we need to know what to request. |
| 205 | - if (!isset($_GET['did'])) |
|
| 206 | - fatal_lang_error('no_access', false); |
|
| 208 | + if (!isset($_GET['did'])) { |
|
| 209 | + fatal_lang_error('no_access', false); |
|
| 210 | + } |
|
| 207 | 211 | |
| 208 | 212 | // Some lovely context. |
| 209 | 213 | $context['download_id'] = $_GET['did']; |
@@ -223,8 +227,9 @@ discard block |
||
| 223 | 227 | foreach ($_POST['copy_file'] as $file) |
| 224 | 228 | { |
| 225 | 229 | // Check it's not very bad. |
| 226 | - if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file))) |
|
| 227 | - fatal_error($txt['languages_download_illegal_paths']); |
|
| 230 | + if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file))) { |
|
| 231 | + fatal_error($txt['languages_download_illegal_paths']); |
|
| 232 | + } |
|
| 228 | 233 | |
| 229 | 234 | $chmod_files[] = $boarddir . '/' . $file; |
| 230 | 235 | $install_files[] = $file; |
@@ -235,8 +240,9 @@ discard block |
||
| 235 | 240 | $files_left = $file_status['files']['notwritable']; |
| 236 | 241 | |
| 237 | 242 | // Something not writable? |
| 238 | - if (!empty($files_left)) |
|
| 239 | - $context['error_message'] = $txt['languages_download_not_chmod']; |
|
| 243 | + if (!empty($files_left)) { |
|
| 244 | + $context['error_message'] = $txt['languages_download_not_chmod']; |
|
| 245 | + } |
|
| 240 | 246 | // Otherwise, go go go! |
| 241 | 247 | elseif (!empty($install_files)) |
| 242 | 248 | { |
@@ -250,11 +256,13 @@ discard block |
||
| 250 | 256 | } |
| 251 | 257 | |
| 252 | 258 | // Open up the old china. |
| 253 | - if (!isset($archive_content)) |
|
| 254 | - $archive_content = read_tgz_file('http://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null); |
|
| 259 | + if (!isset($archive_content)) { |
|
| 260 | + $archive_content = read_tgz_file('http://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null); |
|
| 261 | + } |
|
| 255 | 262 | |
| 256 | - if (empty($archive_content)) |
|
| 257 | - fatal_error($txt['add_language_error_no_response']); |
|
| 263 | + if (empty($archive_content)) { |
|
| 264 | + fatal_error($txt['add_language_error_no_response']); |
|
| 265 | + } |
|
| 258 | 266 | |
| 259 | 267 | // Now for each of the files, let's do some *stuff* |
| 260 | 268 | $context['files'] = array( |
@@ -269,8 +277,9 @@ discard block |
||
| 269 | 277 | $extension = substr($filename, strrpos($filename, '.') + 1); |
| 270 | 278 | |
| 271 | 279 | // Don't do anything with files we don't understand. |
| 272 | - if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt'))) |
|
| 273 | - continue; |
|
| 280 | + if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt'))) { |
|
| 281 | + continue; |
|
| 282 | + } |
|
| 274 | 283 | |
| 275 | 284 | // Basic data. |
| 276 | 285 | $context_data = array( |
@@ -289,8 +298,9 @@ discard block |
||
| 289 | 298 | // Does the file exist, is it different and can we overwrite? |
| 290 | 299 | if (file_exists($boarddir . '/' . $file['filename'])) |
| 291 | 300 | { |
| 292 | - if (is_writable($boarddir . '/' . $file['filename'])) |
|
| 293 | - $context_data['writable'] = true; |
|
| 301 | + if (is_writable($boarddir . '/' . $file['filename'])) { |
|
| 302 | + $context_data['writable'] = true; |
|
| 303 | + } |
|
| 294 | 304 | |
| 295 | 305 | // Finally, do we actually think the content has changed? |
| 296 | 306 | if ($file['size'] == filesize($boarddir . '/' . $file['filename']) && $file['md5'] == md5_file($boarddir . '/' . $file['filename'])) |
@@ -303,16 +313,17 @@ discard block |
||
| 303 | 313 | { |
| 304 | 314 | $context_data['exists'] = 'same'; |
| 305 | 315 | $context_data['default_copy'] = false; |
| 316 | + } else { |
|
| 317 | + $context_data['exists'] = 'different'; |
|
| 306 | 318 | } |
| 307 | - else |
|
| 308 | - $context_data['exists'] = 'different'; |
|
| 309 | 319 | } |
| 310 | 320 | // No overwrite? |
| 311 | 321 | else |
| 312 | 322 | { |
| 313 | 323 | // Can we at least stick it in the directory... |
| 314 | - if (is_writable($boarddir . '/' . $dirname)) |
|
| 315 | - $context_data['writable'] = true; |
|
| 324 | + if (is_writable($boarddir . '/' . $dirname)) { |
|
| 325 | + $context_data['writable'] = true; |
|
| 326 | + } |
|
| 316 | 327 | } |
| 317 | 328 | |
| 318 | 329 | // I love PHP files, that's why I'm a developer and not an artistic type spending my time drinking absinth and living a life of sin... |
@@ -327,8 +338,9 @@ discard block |
||
| 327 | 338 | list ($name, $language) = explode('.', $filename); |
| 328 | 339 | |
| 329 | 340 | // Let's get the new version, I like versions, they tell me that I'm up to date. |
| 330 | - if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1) |
|
| 331 | - $context_data['version'] = $match[1]; |
|
| 341 | + if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1) { |
|
| 342 | + $context_data['version'] = $match[1]; |
|
| 343 | + } |
|
| 332 | 344 | |
| 333 | 345 | // Now does the old file exist - if so what is it's version? |
| 334 | 346 | if (file_exists($boarddir . '/' . $file['filename'])) |
@@ -344,40 +356,42 @@ discard block |
||
| 344 | 356 | $context_data['cur_version'] = $match[1]; |
| 345 | 357 | |
| 346 | 358 | // How does this compare? |
| 347 | - if ($context_data['cur_version'] == $context_data['version']) |
|
| 348 | - $context_data['version_compare'] = 'same'; |
|
| 349 | - elseif ($context_data['cur_version'] > $context_data['version']) |
|
| 350 | - $context_data['version_compare'] = 'older'; |
|
| 359 | + if ($context_data['cur_version'] == $context_data['version']) { |
|
| 360 | + $context_data['version_compare'] = 'same'; |
|
| 361 | + } elseif ($context_data['cur_version'] > $context_data['version']) { |
|
| 362 | + $context_data['version_compare'] = 'older'; |
|
| 363 | + } |
|
| 351 | 364 | |
| 352 | 365 | // Don't recommend copying if the version is the same. |
| 353 | - if ($context_data['version_compare'] != 'newer') |
|
| 354 | - $context_data['default_copy'] = false; |
|
| 366 | + if ($context_data['version_compare'] != 'newer') { |
|
| 367 | + $context_data['default_copy'] = false; |
|
| 368 | + } |
|
| 355 | 369 | } |
| 356 | 370 | } |
| 357 | 371 | |
| 358 | 372 | // Add the context data to the main set. |
| 359 | 373 | $context['files']['lang'][] = $context_data; |
| 360 | - } |
|
| 361 | - elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false) |
|
| 374 | + } elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false) |
|
| 362 | 375 | { |
| 363 | 376 | // Registration agreement is a primary file |
| 364 | 377 | $context['files']['lang'][] = $context_data; |
| 365 | - } |
|
| 366 | - else |
|
| 378 | + } else |
|
| 367 | 379 | { |
| 368 | 380 | // There shouldn't be anything else, but load this into "other" in case we decide to handle it in the future |
| 369 | 381 | $context['files']['other'][] = $context_data; |
| 370 | 382 | } |
| 371 | 383 | |
| 372 | 384 | // Collect together all non-writable areas. |
| 373 | - if (!$context_data['writable']) |
|
| 374 | - $context['make_writable'][] = $context_data['destination']; |
|
| 385 | + if (!$context_data['writable']) { |
|
| 386 | + $context['make_writable'][] = $context_data['destination']; |
|
| 387 | + } |
|
| 375 | 388 | } |
| 376 | 389 | |
| 377 | 390 | // So, I'm a perfectionist - let's get the theme names. |
| 378 | 391 | $theme_indexes = array(); |
| 379 | - foreach ($context['files']['images'] as $k => $dummy) |
|
| 380 | - $indexes[] = $k; |
|
| 392 | + foreach ($context['files']['images'] as $k => $dummy) { |
|
| 393 | + $indexes[] = $k; |
|
| 394 | + } |
|
| 381 | 395 | |
| 382 | 396 | $context['theme_names'] = array(); |
| 383 | 397 | if (!empty($indexes)) |
@@ -409,9 +423,10 @@ discard block |
||
| 409 | 423 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 410 | 424 | { |
| 411 | 425 | // Find the right one. |
| 412 | - foreach ($indexes as $index) |
|
| 413 | - if (strpos($row['value'], $index) !== false) |
|
| 426 | + foreach ($indexes as $index) { |
|
| 427 | + if (strpos($row['value'], $index) !== false) |
|
| 414 | 428 | $themes[$row['id_theme']] = $index; |
| 429 | + } |
|
| 415 | 430 | } |
| 416 | 431 | $smcFunc['db_free_result']($request); |
| 417 | 432 | |
@@ -451,22 +466,24 @@ discard block |
||
| 451 | 466 | { |
| 452 | 467 | if ($type == 'lang') |
| 453 | 468 | { |
| 454 | - foreach ($data as $k => $file) |
|
| 455 | - if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable'])) |
|
| 469 | + foreach ($data as $k => $file) { |
|
| 470 | + if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable'])) |
|
| 456 | 471 | $context['files'][$type][$k]['writable'] = true; |
| 457 | - } |
|
| 458 | - else |
|
| 472 | + } |
|
| 473 | + } else |
|
| 459 | 474 | { |
| 460 | - foreach ($data as $theme => $files) |
|
| 461 | - foreach ($files as $k => $file) |
|
| 475 | + foreach ($data as $theme => $files) { |
|
| 476 | + foreach ($files as $k => $file) |
|
| 462 | 477 | if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable'])) |
| 463 | 478 | $context['files'][$type][$theme][$k]['writable'] = true; |
| 479 | + } |
|
| 464 | 480 | } |
| 465 | 481 | } |
| 466 | 482 | |
| 467 | 483 | // Are we going to need more language stuff? |
| 468 | - if (!empty($context['still_not_writable'])) |
|
| 469 | - loadLanguage('Packages'); |
|
| 484 | + if (!empty($context['still_not_writable'])) { |
|
| 485 | + loadLanguage('Packages'); |
|
| 486 | + } |
|
| 470 | 487 | } |
| 471 | 488 | |
| 472 | 489 | // This is the list for the main files. |
@@ -679,12 +696,13 @@ discard block |
||
| 679 | 696 | highlightSelected("list_language_list_' . ($language == '' ? 'english' : $language). '");', true); |
| 680 | 697 | |
| 681 | 698 | // Display a warning if we cannot edit the default setting. |
| 682 | - if (!is_writable($boarddir . '/Settings.php')) |
|
| 683 | - $listOptions['additional_rows'][] = array( |
|
| 699 | + if (!is_writable($boarddir . '/Settings.php')) { |
|
| 700 | + $listOptions['additional_rows'][] = array( |
|
| 684 | 701 | 'position' => 'after_title', |
| 685 | 702 | 'value' => $txt['language_settings_writable'], |
| 686 | 703 | 'class' => 'smalltext alert', |
| 687 | 704 | ); |
| 705 | + } |
|
| 688 | 706 | |
| 689 | 707 | require_once($sourcedir . '/Subs-List.php'); |
| 690 | 708 | createList($listOptions); |
@@ -726,10 +744,11 @@ discard block |
||
| 726 | 744 | |
| 727 | 745 | // Put them back. |
| 728 | 746 | $settings['actual_theme_dir'] = $backup_actual_theme_dir; |
| 729 | - if (!empty($backup_base_theme_dir)) |
|
| 730 | - $settings['base_theme_dir'] = $backup_base_theme_dir; |
|
| 731 | - else |
|
| 732 | - unset($settings['base_theme_dir']); |
|
| 747 | + if (!empty($backup_base_theme_dir)) { |
|
| 748 | + $settings['base_theme_dir'] = $backup_base_theme_dir; |
|
| 749 | + } else { |
|
| 750 | + unset($settings['base_theme_dir']); |
|
| 751 | + } |
|
| 733 | 752 | |
| 734 | 753 | // Get the language files and data... |
| 735 | 754 | foreach ($context['languages'] as $lang) |
@@ -758,13 +777,15 @@ discard block |
||
| 758 | 777 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 759 | 778 | { |
| 760 | 779 | // Default? |
| 761 | - if (empty($row['lngfile']) || !isset($languages[$row['lngfile']])) |
|
| 762 | - $row['lngfile'] = $language; |
|
| 780 | + if (empty($row['lngfile']) || !isset($languages[$row['lngfile']])) { |
|
| 781 | + $row['lngfile'] = $language; |
|
| 782 | + } |
|
| 763 | 783 | |
| 764 | - if (!isset($languages[$row['lngfile']]) && isset($languages['english'])) |
|
| 765 | - $languages['english']['count'] += $row['num_users']; |
|
| 766 | - elseif (isset($languages[$row['lngfile']])) |
|
| 767 | - $languages[$row['lngfile']]['count'] += $row['num_users']; |
|
| 784 | + if (!isset($languages[$row['lngfile']]) && isset($languages['english'])) { |
|
| 785 | + $languages['english']['count'] += $row['num_users']; |
|
| 786 | + } elseif (isset($languages[$row['lngfile']])) { |
|
| 787 | + $languages[$row['lngfile']]['count'] += $row['num_users']; |
|
| 788 | + } |
|
| 768 | 789 | } |
| 769 | 790 | $smcFunc['db_free_result']($request); |
| 770 | 791 | |
@@ -804,13 +825,15 @@ discard block |
||
| 804 | 825 | |
| 805 | 826 | call_integration_hook('integrate_language_settings', array(&$config_vars)); |
| 806 | 827 | |
| 807 | - if ($return_config) |
|
| 808 | - return $config_vars; |
|
| 828 | + if ($return_config) { |
|
| 829 | + return $config_vars; |
|
| 830 | + } |
|
| 809 | 831 | |
| 810 | 832 | // Get our languages. No cache and use utf8. |
| 811 | 833 | getLanguages(false, false); |
| 812 | - foreach ($context['languages'] as $lang) |
|
| 813 | - $config_vars['language'][4][$lang['filename']] = array($lang['filename'], strtr($lang['name'], array('-utf8' => ' (UTF-8)'))); |
|
| 834 | + foreach ($context['languages'] as $lang) { |
|
| 835 | + $config_vars['language'][4][$lang['filename']] = array($lang['filename'], strtr($lang['name'], array('-utf8' => ' (UTF-8)'))); |
|
| 836 | + } |
|
| 814 | 837 | |
| 815 | 838 | // Saving settings? |
| 816 | 839 | if (isset($_REQUEST['save'])) |
@@ -820,8 +843,9 @@ discard block |
||
| 820 | 843 | call_integration_hook('integrate_save_language_settings', array(&$config_vars)); |
| 821 | 844 | |
| 822 | 845 | saveSettings($config_vars); |
| 823 | - if (!$settings_not_writable && !$settings_backup_fail) |
|
| 824 | - $_SESSION['adm-save'] = true; |
|
| 846 | + if (!$settings_not_writable && !$settings_backup_fail) { |
|
| 847 | + $_SESSION['adm-save'] = true; |
|
| 848 | + } |
|
| 825 | 849 | redirectexit('action=admin;area=languages;sa=settings'); |
| 826 | 850 | } |
| 827 | 851 | |
@@ -830,10 +854,11 @@ discard block |
||
| 830 | 854 | $context['settings_title'] = $txt['language_settings']; |
| 831 | 855 | $context['save_disabled'] = $settings_not_writable; |
| 832 | 856 | |
| 833 | - if ($settings_not_writable) |
|
| 834 | - $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>'; |
|
| 835 | - elseif ($settings_backup_fail) |
|
| 836 | - $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>'; |
|
| 857 | + if ($settings_not_writable) { |
|
| 858 | + $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>'; |
|
| 859 | + } elseif ($settings_backup_fail) { |
|
| 860 | + $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>'; |
|
| 861 | + } |
|
| 837 | 862 | |
| 838 | 863 | // Fill the config array. |
| 839 | 864 | prepareServerSettingsContext($config_vars); |
@@ -880,8 +905,9 @@ discard block |
||
| 880 | 905 | 'theme_dir' => $settings['default_theme_dir'], |
| 881 | 906 | ), |
| 882 | 907 | ); |
| 883 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 884 | - $themes[$row['id_theme']][$row['variable']] = $row['value']; |
|
| 908 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 909 | + $themes[$row['id_theme']][$row['variable']] = $row['value']; |
|
| 910 | + } |
|
| 885 | 911 | $smcFunc['db_free_result']($request); |
| 886 | 912 | |
| 887 | 913 | // This will be where we look |
@@ -893,14 +919,16 @@ discard block |
||
| 893 | 919 | // Check we have themes with a path and a name - just in case - and add the path. |
| 894 | 920 | foreach ($themes as $id => $data) |
| 895 | 921 | { |
| 896 | - if (count($data) != 2) |
|
| 897 | - unset($themes[$id]); |
|
| 898 | - elseif (is_dir($data['theme_dir'] . '/languages')) |
|
| 899 | - $lang_dirs[$id] = $data['theme_dir'] . '/languages'; |
|
| 922 | + if (count($data) != 2) { |
|
| 923 | + unset($themes[$id]); |
|
| 924 | + } elseif (is_dir($data['theme_dir'] . '/languages')) { |
|
| 925 | + $lang_dirs[$id] = $data['theme_dir'] . '/languages'; |
|
| 926 | + } |
|
| 900 | 927 | |
| 901 | 928 | // How about image directories? |
| 902 | - if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) |
|
| 903 | - $images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id']; |
|
| 929 | + if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) { |
|
| 930 | + $images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id']; |
|
| 931 | + } |
|
| 904 | 932 | } |
| 905 | 933 | |
| 906 | 934 | $current_file = $file_id ? $lang_dirs[$theme_id] . '/' . $file_id . '.' . $context['lang_id'] . '.php' : ''; |
@@ -914,15 +942,17 @@ discard block |
||
| 914 | 942 | while ($entry = $dir->read()) |
| 915 | 943 | { |
| 916 | 944 | // We're only after the files for this language. |
| 917 | - if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0) |
|
| 918 | - continue; |
|
| 945 | + if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0) { |
|
| 946 | + continue; |
|
| 947 | + } |
|
| 919 | 948 | |
| 920 | - if (!isset($context['possible_files'][$theme])) |
|
| 921 | - $context['possible_files'][$theme] = array( |
|
| 949 | + if (!isset($context['possible_files'][$theme])) { |
|
| 950 | + $context['possible_files'][$theme] = array( |
|
| 922 | 951 | 'id' => $theme, |
| 923 | 952 | 'name' => $themes[$theme]['name'], |
| 924 | 953 | 'files' => array(), |
| 925 | 954 | ); |
| 955 | + } |
|
| 926 | 956 | |
| 927 | 957 | $context['possible_files'][$theme]['files'][] = array( |
| 928 | 958 | 'id' => $matches[1], |
@@ -951,31 +981,36 @@ discard block |
||
| 951 | 981 | { |
| 952 | 982 | $_SESSION['last_backup_for'] = $context['lang_id'] . '$$$'; |
| 953 | 983 | $result = package_create_backup('backup_lang_' . $context['lang_id']); |
| 954 | - if (!$result) |
|
| 955 | - fatal_lang_error('could_not_language_backup', false); |
|
| 984 | + if (!$result) { |
|
| 985 | + fatal_lang_error('could_not_language_backup', false); |
|
| 986 | + } |
|
| 956 | 987 | } |
| 957 | 988 | |
| 958 | 989 | // Second, loop through the array to remove the files. |
| 959 | 990 | foreach ($lang_dirs as $curPath) |
| 960 | 991 | { |
| 961 | - foreach ($context['possible_files'][1]['files'] as $lang) |
|
| 962 | - if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php')) |
|
| 992 | + foreach ($context['possible_files'][1]['files'] as $lang) { |
|
| 993 | + if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php')) |
|
| 963 | 994 | unlink($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'); |
| 995 | + } |
|
| 964 | 996 | |
| 965 | 997 | // Check for the email template. |
| 966 | - if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) |
|
| 967 | - unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'); |
|
| 998 | + if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) { |
|
| 999 | + unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'); |
|
| 1000 | + } |
|
| 968 | 1001 | } |
| 969 | 1002 | |
| 970 | 1003 | // Third, the agreement file. |
| 971 | - if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) |
|
| 972 | - unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt'); |
|
| 1004 | + if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) { |
|
| 1005 | + unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt'); |
|
| 1006 | + } |
|
| 973 | 1007 | |
| 974 | 1008 | // Fourth, a related images folder, if it exists... |
| 975 | - if (!empty($images_dirs)) |
|
| 976 | - foreach ($images_dirs as $curPath) |
|
| 1009 | + if (!empty($images_dirs)) { |
|
| 1010 | + foreach ($images_dirs as $curPath) |
|
| 977 | 1011 | if (is_dir($curPath)) |
| 978 | 1012 | deltree($curPath); |
| 1013 | + } |
|
| 979 | 1014 | |
| 980 | 1015 | // Members can no longer use this language. |
| 981 | 1016 | $smcFunc['db_query']('', ' |
@@ -1060,8 +1095,9 @@ discard block |
||
| 1060 | 1095 | foreach ($_POST['entry'] as $k => $v) |
| 1061 | 1096 | { |
| 1062 | 1097 | // Only try to save if it's changed! |
| 1063 | - if ($_POST['entry'][$k] != $_POST['comp'][$k]) |
|
| 1064 | - $save_strings[$k] = cleanLangString($v, false); |
|
| 1098 | + if ($_POST['entry'][$k] != $_POST['comp'][$k]) { |
|
| 1099 | + $save_strings[$k] = cleanLangString($v, false); |
|
| 1100 | + } |
|
| 1065 | 1101 | } |
| 1066 | 1102 | } |
| 1067 | 1103 | |
@@ -1095,12 +1131,13 @@ discard block |
||
| 1095 | 1131 | if ($multiline_cache) |
| 1096 | 1132 | { |
| 1097 | 1133 | preg_match('~\$(helptxt|txt|editortxt)\[\'(.+)\'\]\s?=\s?(.+);~ms', strtr($multiline_cache, array("\r" => '')), $matches); |
| 1098 | - if (!empty($matches[3])) |
|
| 1099 | - $entries[$matches[2]] = array( |
|
| 1134 | + if (!empty($matches[3])) { |
|
| 1135 | + $entries[$matches[2]] = array( |
|
| 1100 | 1136 | 'type' => $matches[1], |
| 1101 | 1137 | 'full' => $matches[0], |
| 1102 | 1138 | 'entry' => $matches[3], |
| 1103 | 1139 | ); |
| 1140 | + } |
|
| 1104 | 1141 | } |
| 1105 | 1142 | |
| 1106 | 1143 | // These are the entries we can definitely save. |
@@ -1111,8 +1148,9 @@ discard block |
||
| 1111 | 1148 | { |
| 1112 | 1149 | // Ignore some things we set separately. |
| 1113 | 1150 | $ignore_files = array('lang_character_set', 'lang_locale', 'lang_dictionary', 'lang_spelling', 'lang_rtl'); |
| 1114 | - if (in_array($entryKey, $ignore_files)) |
|
| 1115 | - continue; |
|
| 1151 | + if (in_array($entryKey, $ignore_files)) { |
|
| 1152 | + continue; |
|
| 1153 | + } |
|
| 1116 | 1154 | |
| 1117 | 1155 | // These are arrays that need breaking out. |
| 1118 | 1156 | $arrays = array('days', 'days_short', 'months', 'months_titles', 'months_short', 'happy_birthday_author', 'karlbenson1_author', 'nite0859_author', 'zwaldowski_author', 'geezmo_author', 'karlbenson2_author'); |
@@ -1145,9 +1183,9 @@ discard block |
||
| 1145 | 1183 | { |
| 1146 | 1184 | $save_cache['entries'][$cur_index] = strtr($save_strings[$entryKey . '-+- ' . $cur_index], array('\'' => '')); |
| 1147 | 1185 | $save_cache['enabled'] = true; |
| 1186 | + } else { |
|
| 1187 | + $save_cache['entries'][$cur_index] = $subValue; |
|
| 1148 | 1188 | } |
| 1149 | - else |
|
| 1150 | - $save_cache['entries'][$cur_index] = $subValue; |
|
| 1151 | 1189 | |
| 1152 | 1190 | $context['file_entries'][] = array( |
| 1153 | 1191 | 'key' => $entryKey . '-+- ' . $cur_index, |
@@ -1170,9 +1208,9 @@ discard block |
||
| 1170 | 1208 | { |
| 1171 | 1209 | $items[] = $k2 . ' => \'' . $v2 . '\''; |
| 1172 | 1210 | $cur_index = $k2; |
| 1211 | + } else { |
|
| 1212 | + $items[] = '\'' . $v2 . '\''; |
|
| 1173 | 1213 | } |
| 1174 | - else |
|
| 1175 | - $items[] = '\'' . $v2 . '\''; |
|
| 1176 | 1214 | |
| 1177 | 1215 | $cur_index++; |
| 1178 | 1216 | } |
@@ -1182,15 +1220,15 @@ discard block |
||
| 1182 | 1220 | 'replace' => '$' . $entryValue['type'] . '[\'' . $entryKey . '\'] = array(' . implode(', ', $items) . ');', |
| 1183 | 1221 | ); |
| 1184 | 1222 | } |
| 1185 | - } |
|
| 1186 | - else |
|
| 1223 | + } else |
|
| 1187 | 1224 | { |
| 1188 | 1225 | // Saving? |
| 1189 | 1226 | if (isset($save_strings[$entryKey]) && $save_strings[$entryKey] != $entryValue['entry']) |
| 1190 | 1227 | { |
| 1191 | 1228 | // @todo Fix this properly. |
| 1192 | - if ($save_strings[$entryKey] == '') |
|
| 1193 | - $save_strings[$entryKey] = '\'\''; |
|
| 1229 | + if ($save_strings[$entryKey] == '') { |
|
| 1230 | + $save_strings[$entryKey] = '\'\''; |
|
| 1231 | + } |
|
| 1194 | 1232 | |
| 1195 | 1233 | // Set the new value. |
| 1196 | 1234 | $entryValue['entry'] = $save_strings[$entryKey]; |
@@ -1216,8 +1254,9 @@ discard block |
||
| 1216 | 1254 | checkSession(); |
| 1217 | 1255 | |
| 1218 | 1256 | $file_contents = implode('', file($current_file)); |
| 1219 | - foreach ($final_saves as $save) |
|
| 1220 | - $file_contents = strtr($file_contents, array($save['find'] => $save['replace'])); |
|
| 1257 | + foreach ($final_saves as $save) { |
|
| 1258 | + $file_contents = strtr($file_contents, array($save['find'] => $save['replace'])); |
|
| 1259 | + } |
|
| 1221 | 1260 | |
| 1222 | 1261 | // Save the actual changes. |
| 1223 | 1262 | $fp = fopen($current_file, 'w+'); |
@@ -1232,8 +1271,9 @@ discard block |
||
| 1232 | 1271 | } |
| 1233 | 1272 | |
| 1234 | 1273 | // If we saved, redirect. |
| 1235 | - if ($madeSave) |
|
| 1236 | - redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']); |
|
| 1274 | + if ($madeSave) { |
|
| 1275 | + redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']); |
|
| 1276 | + } |
|
| 1237 | 1277 | |
| 1238 | 1278 | createToken('admin-mlang'); |
| 1239 | 1279 | } |
@@ -1265,8 +1305,9 @@ discard block |
||
| 1265 | 1305 | // Toggle the escape. |
| 1266 | 1306 | $is_escape = !$is_escape; |
| 1267 | 1307 | // If we're now escaped don't add this string. |
| 1268 | - if ($is_escape) |
|
| 1269 | - continue; |
|
| 1308 | + if ($is_escape) { |
|
| 1309 | + continue; |
|
| 1310 | + } |
|
| 1270 | 1311 | } |
| 1271 | 1312 | // Special case - parsed string with line break etc? |
| 1272 | 1313 | elseif (($string{$i} == 'n' || $string{$i} == 't') && $in_string == 2 && $is_escape) |
@@ -1283,11 +1324,13 @@ discard block |
||
| 1283 | 1324 | if ($in_string != 2 && ($in_string != 1 || !$is_escape)) |
| 1284 | 1325 | { |
| 1285 | 1326 | // Is it the end of a single quote string? |
| 1286 | - if ($in_string == 1) |
|
| 1287 | - $in_string = 0; |
|
| 1327 | + if ($in_string == 1) { |
|
| 1328 | + $in_string = 0; |
|
| 1329 | + } |
|
| 1288 | 1330 | // Otherwise it's the start! |
| 1289 | - else |
|
| 1290 | - $in_string = 1; |
|
| 1331 | + else { |
|
| 1332 | + $in_string = 1; |
|
| 1333 | + } |
|
| 1291 | 1334 | |
| 1292 | 1335 | // Don't actually include this character! |
| 1293 | 1336 | continue; |
@@ -1300,19 +1343,22 @@ discard block |
||
| 1300 | 1343 | if ($in_string != 1 && ($in_string != 2 || !$is_escape)) |
| 1301 | 1344 | { |
| 1302 | 1345 | // Is it the end of a double quote string? |
| 1303 | - if ($in_string == 2) |
|
| 1304 | - $in_string = 0; |
|
| 1346 | + if ($in_string == 2) { |
|
| 1347 | + $in_string = 0; |
|
| 1348 | + } |
|
| 1305 | 1349 | // Otherwise it's the start! |
| 1306 | - else |
|
| 1307 | - $in_string = 2; |
|
| 1350 | + else { |
|
| 1351 | + $in_string = 2; |
|
| 1352 | + } |
|
| 1308 | 1353 | |
| 1309 | 1354 | // Don't actually include this character! |
| 1310 | 1355 | continue; |
| 1311 | 1356 | } |
| 1312 | 1357 | } |
| 1313 | 1358 | // A join/space outside of a string is simply removed. |
| 1314 | - elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.')) |
|
| 1315 | - continue; |
|
| 1359 | + elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.')) { |
|
| 1360 | + continue; |
|
| 1361 | + } |
|
| 1316 | 1362 | // Start of a variable? |
| 1317 | 1363 | elseif ($in_string == 0 && $string{$i} == '$') |
| 1318 | 1364 | { |
@@ -1346,8 +1392,7 @@ discard block |
||
| 1346 | 1392 | |
| 1347 | 1393 | // Unhtml then rehtml the whole thing! |
| 1348 | 1394 | $new_string = $smcFunc['htmlspecialchars'](un_htmlspecialchars($new_string)); |
| 1349 | - } |
|
| 1350 | - else |
|
| 1395 | + } else |
|
| 1351 | 1396 | { |
| 1352 | 1397 | // Keep track of what we're doing... |
| 1353 | 1398 | $in_string = 0; |
@@ -1376,10 +1421,11 @@ discard block |
||
| 1376 | 1421 | preg_match('~\{%([\$A-Za-z0-9\'\[\]_-]+)%\}~', substr($string, $i), $matches); |
| 1377 | 1422 | if (!empty($matches[1])) |
| 1378 | 1423 | { |
| 1379 | - if ($in_string == 1) |
|
| 1380 | - $new_string .= '\' . '; |
|
| 1381 | - elseif ($new_string) |
|
| 1382 | - $new_string .= ' . '; |
|
| 1424 | + if ($in_string == 1) { |
|
| 1425 | + $new_string .= '\' . '; |
|
| 1426 | + } elseif ($new_string) { |
|
| 1427 | + $new_string .= ' . '; |
|
| 1428 | + } |
|
| 1383 | 1429 | |
| 1384 | 1430 | $new_string .= $matches[1]; |
| 1385 | 1431 | $i += strlen($matches[1]) + 3; |
@@ -1392,8 +1438,9 @@ discard block |
||
| 1392 | 1438 | elseif ($string{$i} == '<') |
| 1393 | 1439 | { |
| 1394 | 1440 | // Probably HTML? |
| 1395 | - if ($string{$i + 1} != ' ') |
|
| 1396 | - $in_html = true; |
|
| 1441 | + if ($string{$i + 1} != ' ') { |
|
| 1442 | + $in_html = true; |
|
| 1443 | + } |
|
| 1397 | 1444 | // Assume we need an entity... |
| 1398 | 1445 | else |
| 1399 | 1446 | { |
@@ -1405,8 +1452,9 @@ discard block |
||
| 1405 | 1452 | elseif ($string{$i} == '>') |
| 1406 | 1453 | { |
| 1407 | 1454 | // Will it be HTML? |
| 1408 | - if ($in_html) |
|
| 1409 | - $in_html = false; |
|
| 1455 | + if ($in_html) { |
|
| 1456 | + $in_html = false; |
|
| 1457 | + } |
|
| 1410 | 1458 | // Otherwise we need an entity... |
| 1411 | 1459 | else |
| 1412 | 1460 | { |
@@ -1415,8 +1463,9 @@ discard block |
||
| 1415 | 1463 | } |
| 1416 | 1464 | } |
| 1417 | 1465 | // Is it a slash? If so escape it... |
| 1418 | - if ($string{$i} == '\\') |
|
| 1419 | - $new_string .= '\\'; |
|
| 1466 | + if ($string{$i} == '\\') { |
|
| 1467 | + $new_string .= '\\'; |
|
| 1468 | + } |
|
| 1420 | 1469 | // The infamous double quote? |
| 1421 | 1470 | elseif ($string{$i} == '"') |
| 1422 | 1471 | { |
@@ -1439,10 +1488,11 @@ discard block |
||
| 1439 | 1488 | } |
| 1440 | 1489 | |
| 1441 | 1490 | // If we ended as a string then close it off. |
| 1442 | - if ($in_string == 1) |
|
| 1443 | - $new_string .= '\''; |
|
| 1444 | - elseif ($in_string == 2) |
|
| 1445 | - $new_string .= '"'; |
|
| 1491 | + if ($in_string == 1) { |
|
| 1492 | + $new_string .= '\''; |
|
| 1493 | + } elseif ($in_string == 2) { |
|
| 1494 | + $new_string .= '"'; |
|
| 1495 | + } |
|
| 1446 | 1496 | } |
| 1447 | 1497 | |
| 1448 | 1498 | return $new_string; |
@@ -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 | } |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 3 |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -if (!defined('SMF')) |
|
| 18 | +if (!defined('SMF')) { |
|
| 19 | 19 | die('No direct access...'); |
| 20 | +} |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * Begin the registration process. |
@@ -29,19 +30,23 @@ discard block |
||
| 29 | 30 | global $language, $scripturl, $smcFunc, $sourcedir, $cur_profile; |
| 30 | 31 | |
| 31 | 32 | // Is this an incoming AJAX check? |
| 32 | - if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') |
|
| 33 | - return RegisterCheckUsername(); |
|
| 33 | + if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') { |
|
| 34 | + return RegisterCheckUsername(); |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | // Check if the administrator has it disabled. |
| 36 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') |
|
| 37 | - fatal_lang_error('registration_disabled', false); |
|
| 38 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') { |
|
| 39 | + fatal_lang_error('registration_disabled', false); |
|
| 40 | + } |
|
| 38 | 41 | |
| 39 | 42 | // If this user is an admin - redirect them to the admin registration page. |
| 40 | - if (allowedTo('moderate_forum') && !$user_info['is_guest']) |
|
| 41 | - redirectexit('action=admin;area=regcenter;sa=register'); |
|
| 43 | + if (allowedTo('moderate_forum') && !$user_info['is_guest']) { |
|
| 44 | + redirectexit('action=admin;area=regcenter;sa=register'); |
|
| 45 | + } |
|
| 42 | 46 | // You are not a guest, so you are a member - and members don't get to register twice! |
| 43 | - elseif (empty($user_info['is_guest'])) |
|
| 44 | - redirectexit(); |
|
| 47 | + elseif (empty($user_info['is_guest'])) { |
|
| 48 | + redirectexit(); |
|
| 49 | + } |
|
| 45 | 50 | |
| 46 | 51 | loadLanguage('Login'); |
| 47 | 52 | loadTemplate('Register'); |
@@ -82,16 +87,18 @@ discard block |
||
| 82 | 87 | } |
| 83 | 88 | } |
| 84 | 89 | // Make sure they don't squeeze through without agreeing. |
| 85 | - elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) |
|
| 86 | - $current_step = 1; |
|
| 90 | + elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) { |
|
| 91 | + $current_step = 1; |
|
| 92 | + } |
|
| 87 | 93 | |
| 88 | 94 | // Show the user the right form. |
| 89 | 95 | $context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form'; |
| 90 | 96 | $context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form']; |
| 91 | 97 | |
| 92 | 98 | // Kinda need this. |
| 93 | - if ($context['sub_template'] == 'registration_form') |
|
| 94 | - loadJavaScriptFile('register.js', array('defer' => false), 'smf_register'); |
|
| 99 | + if ($context['sub_template'] == 'registration_form') { |
|
| 100 | + loadJavaScriptFile('register.js', array('defer' => false), 'smf_register'); |
|
| 101 | + } |
|
| 95 | 102 | |
| 96 | 103 | // Add the register chain to the link tree. |
| 97 | 104 | $context['linktree'][] = array( |
@@ -100,24 +107,26 @@ discard block |
||
| 100 | 107 | ); |
| 101 | 108 | |
| 102 | 109 | // Prepare the time gate! Do it like so, in case later steps want to reset the limit for any reason, but make sure the time is the current one. |
| 103 | - if (!isset($_SESSION['register'])) |
|
| 104 | - $_SESSION['register'] = array( |
|
| 110 | + if (!isset($_SESSION['register'])) { |
|
| 111 | + $_SESSION['register'] = array( |
|
| 105 | 112 | 'timenow' => time(), |
| 106 | 113 | 'limit' => 10, // minimum number of seconds required on this page for registration |
| 107 | 114 | ); |
| 108 | - else |
|
| 109 | - $_SESSION['register']['timenow'] = time(); |
|
| 115 | + } else { |
|
| 116 | + $_SESSION['register']['timenow'] = time(); |
|
| 117 | + } |
|
| 110 | 118 | |
| 111 | 119 | // If you have to agree to the agreement, it needs to be fetched from the file. |
| 112 | 120 | if ($context['require_agreement']) |
| 113 | 121 | { |
| 114 | 122 | // Have we got a localized one? |
| 115 | - if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) |
|
| 116 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
| 117 | - elseif (file_exists($boarddir . '/agreement.txt')) |
|
| 118 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
| 119 | - else |
|
| 120 | - $context['agreement'] = ''; |
|
| 123 | + if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) { |
|
| 124 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
| 125 | + } elseif (file_exists($boarddir . '/agreement.txt')) { |
|
| 126 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
| 127 | + } else { |
|
| 128 | + $context['agreement'] = ''; |
|
| 129 | + } |
|
| 121 | 130 | |
| 122 | 131 | // Nothing to show, lets disable registration and inform the admin of this error |
| 123 | 132 | if (empty($context['agreement'])) |
@@ -133,8 +142,9 @@ discard block |
||
| 133 | 142 | $selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language']; |
| 134 | 143 | |
| 135 | 144 | // Do we have any languages? |
| 136 | - if (empty($context['languages'])) |
|
| 137 | - getLanguages(); |
|
| 145 | + if (empty($context['languages'])) { |
|
| 146 | + getLanguages(); |
|
| 147 | + } |
|
| 138 | 148 | |
| 139 | 149 | // Try to find our selected language. |
| 140 | 150 | foreach ($context['languages'] as $key => $lang) |
@@ -142,8 +152,9 @@ discard block |
||
| 142 | 152 | $context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => '')); |
| 143 | 153 | |
| 144 | 154 | // Found it! |
| 145 | - if ($selectedLanguage == $lang['filename']) |
|
| 146 | - $context['languages'][$key]['selected'] = true; |
|
| 155 | + if ($selectedLanguage == $lang['filename']) { |
|
| 156 | + $context['languages'][$key]['selected'] = true; |
|
| 157 | + } |
|
| 147 | 158 | } |
| 148 | 159 | } |
| 149 | 160 | |
@@ -167,9 +178,10 @@ discard block |
||
| 167 | 178 | $reg_fields = explode(',', $modSettings['registration_fields']); |
| 168 | 179 | |
| 169 | 180 | // We might have had some submissions on this front - go check. |
| 170 | - foreach ($reg_fields as $field) |
|
| 171 | - if (isset($_POST[$field])) |
|
| 181 | + foreach ($reg_fields as $field) { |
|
| 182 | + if (isset($_POST[$field])) |
|
| 172 | 183 | $cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]); |
| 184 | + } |
|
| 173 | 185 | |
| 174 | 186 | // Load all the fields in question. |
| 175 | 187 | setupProfileContext($reg_fields); |
@@ -186,8 +198,9 @@ discard block |
||
| 186 | 198 | $context['visual_verification_id'] = $verificationOptions['id']; |
| 187 | 199 | } |
| 188 | 200 | // Otherwise we have nothing to show. |
| 189 | - else |
|
| 190 | - $context['visual_verification'] = false; |
|
| 201 | + else { |
|
| 202 | + $context['visual_verification'] = false; |
|
| 203 | + } |
|
| 191 | 204 | |
| 192 | 205 | |
| 193 | 206 | $context += array( |
@@ -198,8 +211,9 @@ discard block |
||
| 198 | 211 | |
| 199 | 212 | // Were there any errors? |
| 200 | 213 | $context['registration_errors'] = array(); |
| 201 | - if (!empty($reg_errors)) |
|
| 202 | - $context['registration_errors'] = $reg_errors; |
|
| 214 | + if (!empty($reg_errors)) { |
|
| 215 | + $context['registration_errors'] = $reg_errors; |
|
| 216 | + } |
|
| 203 | 217 | |
| 204 | 218 | createToken('register'); |
| 205 | 219 | } |
@@ -216,27 +230,32 @@ discard block |
||
| 216 | 230 | validateToken('register'); |
| 217 | 231 | |
| 218 | 232 | // Check to ensure we're forcing SSL for authentication |
| 219 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
| 220 | - fatal_lang_error('register_ssl_required'); |
|
| 233 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
| 234 | + fatal_lang_error('register_ssl_required'); |
|
| 235 | + } |
|
| 221 | 236 | |
| 222 | 237 | // Start collecting together any errors. |
| 223 | 238 | $reg_errors = array(); |
| 224 | 239 | |
| 225 | 240 | // You can't register if it's disabled. |
| 226 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) |
|
| 227 | - fatal_lang_error('registration_disabled', false); |
|
| 241 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) { |
|
| 242 | + fatal_lang_error('registration_disabled', false); |
|
| 243 | + } |
|
| 228 | 244 | |
| 229 | 245 | // Well, if you don't agree, you can't register. |
| 230 | - if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) |
|
| 231 | - redirectexit(); |
|
| 246 | + if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) { |
|
| 247 | + redirectexit(); |
|
| 248 | + } |
|
| 232 | 249 | |
| 233 | 250 | // Make sure they came from *somewhere*, have a session. |
| 234 | - if (!isset($_SESSION['old_url'])) |
|
| 235 | - redirectexit('action=signup'); |
|
| 251 | + if (!isset($_SESSION['old_url'])) { |
|
| 252 | + redirectexit('action=signup'); |
|
| 253 | + } |
|
| 236 | 254 | |
| 237 | 255 | // If we don't require an agreement, we need a extra check for coppa. |
| 238 | - if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) |
|
| 239 | - $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
| 256 | + if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) { |
|
| 257 | + $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
| 258 | + } |
|
| 240 | 259 | // Are they under age, and under age users are banned? |
| 241 | 260 | if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa'])) |
| 242 | 261 | { |
@@ -245,8 +264,9 @@ discard block |
||
| 245 | 264 | } |
| 246 | 265 | |
| 247 | 266 | // Check the time gate for miscreants. First make sure they came from somewhere that actually set it up. |
| 248 | - if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) |
|
| 249 | - redirectexit('action=signup'); |
|
| 267 | + if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) { |
|
| 268 | + redirectexit('action=signup'); |
|
| 269 | + } |
|
| 250 | 270 | // Failing that, check the time on it. |
| 251 | 271 | if (time() - $_SESSION['register']['timenow'] < $_SESSION['register']['limit']) |
| 252 | 272 | { |
@@ -266,15 +286,17 @@ discard block |
||
| 266 | 286 | if (is_array($context['visual_verification'])) |
| 267 | 287 | { |
| 268 | 288 | loadLanguage('Errors'); |
| 269 | - foreach ($context['visual_verification'] as $error) |
|
| 270 | - $reg_errors[] = $txt['error_' . $error]; |
|
| 289 | + foreach ($context['visual_verification'] as $error) { |
|
| 290 | + $reg_errors[] = $txt['error_' . $error]; |
|
| 291 | + } |
|
| 271 | 292 | } |
| 272 | 293 | } |
| 273 | 294 | |
| 274 | 295 | foreach ($_POST as $key => $value) |
| 275 | 296 | { |
| 276 | - if (!is_array($_POST[$key])) |
|
| 277 | - $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
| 297 | + if (!is_array($_POST[$key])) { |
|
| 298 | + $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
| 299 | + } |
|
| 278 | 300 | } |
| 279 | 301 | |
| 280 | 302 | // Collect all extra registration fields someone might have filled in. |
@@ -304,12 +326,14 @@ discard block |
||
| 304 | 326 | $reg_fields = explode(',', $modSettings['registration_fields']); |
| 305 | 327 | |
| 306 | 328 | // Website is a little different |
| 307 | - if (in_array('website', $reg_fields)) |
|
| 308 | - $possible_strings += array('website_url', 'website_title'); |
|
| 329 | + if (in_array('website', $reg_fields)) { |
|
| 330 | + $possible_strings += array('website_url', 'website_title'); |
|
| 331 | + } |
|
| 309 | 332 | } |
| 310 | 333 | |
| 311 | - if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') |
|
| 312 | - $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
| 334 | + if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') { |
|
| 335 | + $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
| 336 | + } |
|
| 313 | 337 | |
| 314 | 338 | // Needed for isReservedName() and registerMember(). |
| 315 | 339 | require_once($sourcedir . '/Subs-Members.php'); |
@@ -318,32 +342,37 @@ discard block |
||
| 318 | 342 | if (isset($_POST['real_name']) && (allowedTo('profile_displayed_name') || allowedTo('moderate_forum'))) |
| 319 | 343 | { |
| 320 | 344 | $_POST['real_name'] = 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' : ''), ' ', $_POST['real_name'])); |
| 321 | - if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) |
|
| 322 | - $possible_strings[] = 'real_name'; |
|
| 345 | + if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) { |
|
| 346 | + $possible_strings[] = 'real_name'; |
|
| 347 | + } |
|
| 323 | 348 | } |
| 324 | 349 | |
| 325 | 350 | // Handle a string as a birthdate... |
| 326 | - if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') |
|
| 327 | - $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
| 351 | + if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') { |
|
| 352 | + $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
| 353 | + } |
|
| 328 | 354 | // Or birthdate parts... |
| 329 | - elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) |
|
| 330 | - $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
| 355 | + elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) { |
|
| 356 | + $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
| 357 | + } |
|
| 331 | 358 | |
| 332 | 359 | // Validate the passed language file. |
| 333 | 360 | if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage'])) |
| 334 | 361 | { |
| 335 | 362 | // Do we have any languages? |
| 336 | - if (empty($context['languages'])) |
|
| 337 | - getLanguages(); |
|
| 363 | + if (empty($context['languages'])) { |
|
| 364 | + getLanguages(); |
|
| 365 | + } |
|
| 338 | 366 | |
| 339 | 367 | // Did we find it? |
| 340 | - if (isset($context['languages'][$_POST['lngfile']])) |
|
| 341 | - $_SESSION['language'] = $_POST['lngfile']; |
|
| 342 | - else |
|
| 368 | + if (isset($context['languages'][$_POST['lngfile']])) { |
|
| 369 | + $_SESSION['language'] = $_POST['lngfile']; |
|
| 370 | + } else { |
|
| 371 | + unset($_POST['lngfile']); |
|
| 372 | + } |
|
| 373 | + } else { |
|
| 343 | 374 | unset($_POST['lngfile']); |
| 344 | 375 | } |
| 345 | - else |
|
| 346 | - unset($_POST['lngfile']); |
|
| 347 | 376 | |
| 348 | 377 | // Set the options needed for registration. |
| 349 | 378 | $regOptions = array( |
@@ -363,22 +392,27 @@ discard block |
||
| 363 | 392 | ); |
| 364 | 393 | |
| 365 | 394 | // Include the additional options that might have been filled in. |
| 366 | - foreach ($possible_strings as $var) |
|
| 367 | - if (isset($_POST[$var])) |
|
| 395 | + foreach ($possible_strings as $var) { |
|
| 396 | + if (isset($_POST[$var])) |
|
| 368 | 397 | $regOptions['extra_register_vars'][$var] = $smcFunc['htmlspecialchars']($_POST[$var], ENT_QUOTES); |
| 369 | - foreach ($possible_ints as $var) |
|
| 370 | - if (isset($_POST[$var])) |
|
| 398 | + } |
|
| 399 | + foreach ($possible_ints as $var) { |
|
| 400 | + if (isset($_POST[$var])) |
|
| 371 | 401 | $regOptions['extra_register_vars'][$var] = (int) $_POST[$var]; |
| 372 | - foreach ($possible_floats as $var) |
|
| 373 | - if (isset($_POST[$var])) |
|
| 402 | + } |
|
| 403 | + foreach ($possible_floats as $var) { |
|
| 404 | + if (isset($_POST[$var])) |
|
| 374 | 405 | $regOptions['extra_register_vars'][$var] = (float) $_POST[$var]; |
| 375 | - foreach ($possible_bools as $var) |
|
| 376 | - if (isset($_POST[$var])) |
|
| 406 | + } |
|
| 407 | + foreach ($possible_bools as $var) { |
|
| 408 | + if (isset($_POST[$var])) |
|
| 377 | 409 | $regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1; |
| 410 | + } |
|
| 378 | 411 | |
| 379 | 412 | // Registration options are always default options... |
| 380 | - if (isset($_POST['default_options'])) |
|
| 381 | - $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
| 413 | + if (isset($_POST['default_options'])) { |
|
| 414 | + $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
| 415 | + } |
|
| 382 | 416 | $regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array(); |
| 383 | 417 | |
| 384 | 418 | // Make sure they are clean, dammit! |
@@ -398,12 +432,14 @@ discard block |
||
| 398 | 432 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 399 | 433 | { |
| 400 | 434 | // Don't allow overriding of the theme variables. |
| 401 | - if (isset($regOptions['theme_vars'][$row['col_name']])) |
|
| 402 | - unset($regOptions['theme_vars'][$row['col_name']]); |
|
| 435 | + if (isset($regOptions['theme_vars'][$row['col_name']])) { |
|
| 436 | + unset($regOptions['theme_vars'][$row['col_name']]); |
|
| 437 | + } |
|
| 403 | 438 | |
| 404 | 439 | // Not actually showing it then? |
| 405 | - if (!$row['show_reg']) |
|
| 406 | - continue; |
|
| 440 | + if (!$row['show_reg']) { |
|
| 441 | + continue; |
|
| 442 | + } |
|
| 407 | 443 | |
| 408 | 444 | // Prepare the value! |
| 409 | 445 | $value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : ''; |
@@ -412,24 +448,27 @@ discard block |
||
| 412 | 448 | if (!in_array($row['field_type'], array('check', 'select', 'radio'))) |
| 413 | 449 | { |
| 414 | 450 | // Is it too long? |
| 415 | - if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) |
|
| 416 | - $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
| 451 | + if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) { |
|
| 452 | + $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
| 453 | + } |
|
| 417 | 454 | |
| 418 | 455 | // Any masks to apply? |
| 419 | 456 | if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none') |
| 420 | 457 | { |
| 421 | - if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) |
|
| 422 | - $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
| 423 | - elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) |
|
| 424 | - $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
| 425 | - elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) |
|
| 426 | - $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
| 458 | + if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) { |
|
| 459 | + $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
| 460 | + } elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) { |
|
| 461 | + $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
| 462 | + } elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) { |
|
| 463 | + $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
| 464 | + } |
|
| 427 | 465 | } |
| 428 | 466 | } |
| 429 | 467 | |
| 430 | 468 | // Is this required but not there? |
| 431 | - if (trim($value) == '' && $row['show_reg'] > 1) |
|
| 432 | - $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
| 469 | + if (trim($value) == '' && $row['show_reg'] > 1) { |
|
| 470 | + $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
| 471 | + } |
|
| 433 | 472 | } |
| 434 | 473 | $smcFunc['db_free_result']($request); |
| 435 | 474 | |
@@ -437,8 +476,9 @@ discard block |
||
| 437 | 476 | if (!empty($custom_field_errors)) |
| 438 | 477 | { |
| 439 | 478 | loadLanguage('Errors'); |
| 440 | - foreach ($custom_field_errors as $error) |
|
| 441 | - $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
| 479 | + foreach ($custom_field_errors as $error) { |
|
| 480 | + $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
| 481 | + } |
|
| 442 | 482 | } |
| 443 | 483 | |
| 444 | 484 | // Lets check for other errors before trying to register the member. |
@@ -483,8 +523,9 @@ discard block |
||
| 483 | 523 | } |
| 484 | 524 | |
| 485 | 525 | // If COPPA has been selected then things get complicated, setup the template. |
| 486 | - if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) |
|
| 487 | - redirectexit('action=coppa;member=' . $memberID); |
|
| 526 | + if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) { |
|
| 527 | + redirectexit('action=coppa;member=' . $memberID); |
|
| 528 | + } |
|
| 488 | 529 | // Basic template variable setup. |
| 489 | 530 | elseif (!empty($modSettings['registration_method'])) |
| 490 | 531 | { |
@@ -496,8 +537,7 @@ discard block |
||
| 496 | 537 | 'sub_template' => 'after', |
| 497 | 538 | 'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration'] |
| 498 | 539 | ); |
| 499 | - } |
|
| 500 | - else |
|
| 540 | + } else |
|
| 501 | 541 | { |
| 502 | 542 | call_integration_hook('integrate_activate', array($regOptions['username'])); |
| 503 | 543 | |
@@ -517,16 +557,18 @@ discard block |
||
| 517 | 557 | global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $language, $user_info; |
| 518 | 558 | |
| 519 | 559 | // Logged in users should not bother to activate their accounts |
| 520 | - if (!empty($user_info['id'])) |
|
| 521 | - redirectexit(); |
|
| 560 | + if (!empty($user_info['id'])) { |
|
| 561 | + redirectexit(); |
|
| 562 | + } |
|
| 522 | 563 | |
| 523 | 564 | loadLanguage('Login'); |
| 524 | 565 | loadTemplate('Login'); |
| 525 | 566 | |
| 526 | 567 | if (empty($_REQUEST['u']) && empty($_POST['user'])) |
| 527 | 568 | { |
| 528 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') |
|
| 529 | - fatal_lang_error('no_access', false); |
|
| 569 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') { |
|
| 570 | + fatal_lang_error('no_access', false); |
|
| 571 | + } |
|
| 530 | 572 | |
| 531 | 573 | $context['member_id'] = 0; |
| 532 | 574 | $context['sub_template'] = 'resend'; |
@@ -566,11 +608,13 @@ discard block |
||
| 566 | 608 | // Change their email address? (they probably tried a fake one first :P.) |
| 567 | 609 | if (isset($_POST['new_email'], $_REQUEST['passwd']) && hash_password($row['member_name'], $_REQUEST['passwd']) == $row['passwd'] && ($row['is_activated'] == 0 || $row['is_activated'] == 2)) |
| 568 | 610 | { |
| 569 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) |
|
| 570 | - fatal_lang_error('no_access', false); |
|
| 611 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) { |
|
| 612 | + fatal_lang_error('no_access', false); |
|
| 613 | + } |
|
| 571 | 614 | |
| 572 | - if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) |
|
| 573 | - fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
| 615 | + if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) { |
|
| 616 | + fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
| 617 | + } |
|
| 574 | 618 | |
| 575 | 619 | // Make sure their email isn't banned. |
| 576 | 620 | isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']); |
@@ -586,8 +630,9 @@ discard block |
||
| 586 | 630 | ) |
| 587 | 631 | ); |
| 588 | 632 | |
| 589 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 590 | - fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
| 633 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 634 | + fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
| 635 | + } |
|
| 591 | 636 | $smcFunc['db_free_result']($request); |
| 592 | 637 | |
| 593 | 638 | updateMemberData($row['id_member'], array('email_address' => $_POST['new_email'])); |
@@ -625,9 +670,9 @@ discard block |
||
| 625 | 670 | // Quit if this code is not right. |
| 626 | 671 | if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code']) |
| 627 | 672 | { |
| 628 | - if (!empty($row['is_activated'])) |
|
| 629 | - fatal_lang_error('already_activated', false); |
|
| 630 | - elseif ($row['validation_code'] == '') |
|
| 673 | + if (!empty($row['is_activated'])) { |
|
| 674 | + fatal_lang_error('already_activated', false); |
|
| 675 | + } elseif ($row['validation_code'] == '') |
|
| 631 | 676 | { |
| 632 | 677 | loadLanguage('Profile'); |
| 633 | 678 | fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $row['member_name']), false); |
@@ -677,8 +722,9 @@ discard block |
||
| 677 | 722 | loadTemplate('Register'); |
| 678 | 723 | |
| 679 | 724 | // No User ID?? |
| 680 | - if (!isset($_GET['member'])) |
|
| 681 | - fatal_lang_error('no_access', false); |
|
| 725 | + if (!isset($_GET['member'])) { |
|
| 726 | + fatal_lang_error('no_access', false); |
|
| 727 | + } |
|
| 682 | 728 | |
| 683 | 729 | // Get the user details... |
| 684 | 730 | $request = $smcFunc['db_query']('', ' |
@@ -691,8 +737,9 @@ discard block |
||
| 691 | 737 | 'is_coppa' => 5, |
| 692 | 738 | ) |
| 693 | 739 | ); |
| 694 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 695 | - fatal_lang_error('no_access', false); |
|
| 740 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 741 | + fatal_lang_error('no_access', false); |
|
| 742 | + } |
|
| 696 | 743 | list ($username) = $smcFunc['db_fetch_row']($request); |
| 697 | 744 | $smcFunc['db_free_result']($request); |
| 698 | 745 | |
@@ -730,8 +777,7 @@ discard block |
||
| 730 | 777 | echo $data; |
| 731 | 778 | obExit(false); |
| 732 | 779 | } |
| 733 | - } |
|
| 734 | - else |
|
| 780 | + } else |
|
| 735 | 781 | { |
| 736 | 782 | $context += array( |
| 737 | 783 | 'page_title' => $txt['coppa_title'], |
@@ -784,8 +830,9 @@ discard block |
||
| 784 | 830 | { |
| 785 | 831 | require_once($sourcedir . '/Subs-Graphics.php'); |
| 786 | 832 | |
| 787 | - if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) |
|
| 788 | - header('HTTP/1.1 400 Bad Request'); |
|
| 833 | + if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) { |
|
| 834 | + header('HTTP/1.1 400 Bad Request'); |
|
| 835 | + } |
|
| 789 | 836 | |
| 790 | 837 | // Otherwise just show a pre-defined letter. |
| 791 | 838 | elseif (isset($_REQUEST['letter'])) |
@@ -803,14 +850,13 @@ discard block |
||
| 803 | 850 | header('Content-Type: image/gif'); |
| 804 | 851 | die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B"); |
| 805 | 852 | } |
| 806 | - } |
|
| 807 | - |
|
| 808 | - elseif ($_REQUEST['format'] === '.wav') |
|
| 853 | + } elseif ($_REQUEST['format'] === '.wav') |
|
| 809 | 854 | { |
| 810 | 855 | require_once($sourcedir . '/Subs-Sound.php'); |
| 811 | 856 | |
| 812 | - if (!createWaveFile($code)) |
|
| 813 | - header('HTTP/1.1 400 Bad Request'); |
|
| 857 | + if (!createWaveFile($code)) { |
|
| 858 | + header('HTTP/1.1 400 Bad Request'); |
|
| 859 | + } |
|
| 814 | 860 | } |
| 815 | 861 | |
| 816 | 862 | // We all die one day... |