@@ -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 | * Finds or repairs errors in the database to fix possible problems. |
@@ -50,8 +51,9 @@ discard block |
||
| 50 | 51 | ); |
| 51 | 52 | |
| 52 | 53 | // Start displaying errors without fixing them. |
| 53 | - if (isset($_GET['fixErrors'])) |
|
| 54 | - checkSession('get'); |
|
| 54 | + if (isset($_GET['fixErrors'])) { |
|
| 55 | + checkSession('get'); |
|
| 56 | + } |
|
| 55 | 57 | |
| 56 | 58 | // Will want this. |
| 57 | 59 | loadForumTests(); |
@@ -69,11 +71,11 @@ discard block |
||
| 69 | 71 | $_SESSION['repairboards_to_fix'] = $context['to_fix']; |
| 70 | 72 | $_SESSION['repairboards_to_fix2'] = null; |
| 71 | 73 | |
| 72 | - if (empty($context['repair_errors'])) |
|
| 73 | - $context['repair_errors'][] = '???'; |
|
| 74 | + if (empty($context['repair_errors'])) { |
|
| 75 | + $context['repair_errors'][] = '???'; |
|
| 76 | + } |
|
| 74 | 77 | } |
| 75 | - } |
|
| 76 | - else |
|
| 78 | + } else |
|
| 77 | 79 | { |
| 78 | 80 | $context['error_search'] = false; |
| 79 | 81 | $context['to_fix'] = isset($_SESSION['repairboards_to_fix']) ? $_SESSION['repairboards_to_fix'] : array(); |
@@ -120,16 +122,19 @@ discard block |
||
| 120 | 122 | |
| 121 | 123 | // More time, I need more time! |
| 122 | 124 | @set_time_limit(600); |
| 123 | - if (function_exists('apache_reset_timeout')) |
|
| 124 | - @apache_reset_timeout(); |
|
| 125 | + if (function_exists('apache_reset_timeout')) { |
|
| 126 | + @apache_reset_timeout(); |
|
| 127 | + } |
|
| 125 | 128 | |
| 126 | 129 | // Errr, wait. How much time has this taken already? |
| 127 | - if (!$force && time() - array_sum(explode(' ', $time_start)) < 3) |
|
| 128 | - return; |
|
| 130 | + if (!$force && time() - array_sum(explode(' ', $time_start)) < 3) { |
|
| 131 | + return; |
|
| 132 | + } |
|
| 129 | 133 | |
| 130 | 134 | // Restore the query cache if interested. |
| 131 | - if (!empty($db_temp_cache)) |
|
| 132 | - $db_cache = $db_temp_cache; |
|
| 135 | + if (!empty($db_temp_cache)) { |
|
| 136 | + $db_cache = $db_temp_cache; |
|
| 137 | + } |
|
| 133 | 138 | |
| 134 | 139 | $context['continue_get_data'] = '?action=admin;area=repairboards' . (isset($_GET['fixErrors']) ? ';fixErrors' : '') . ';step=' . $_GET['step'] . ';substep=' . $_GET['substep'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
| 135 | 140 | $context['page_title'] = $txt['not_done_title']; |
@@ -138,10 +143,11 @@ discard block |
||
| 138 | 143 | $context['sub_template'] = 'not_done'; |
| 139 | 144 | |
| 140 | 145 | // Change these two if more steps are added! |
| 141 | - if (empty($max_substep)) |
|
| 142 | - $context['continue_percent'] = round(($_GET['step'] * 100) / $context['total_steps']); |
|
| 143 | - else |
|
| 144 | - $context['continue_percent'] = round((($_GET['step'] + ($_GET['substep'] / $max_substep)) * 100) / $context['total_steps']); |
|
| 146 | + if (empty($max_substep)) { |
|
| 147 | + $context['continue_percent'] = round(($_GET['step'] * 100) / $context['total_steps']); |
|
| 148 | + } else { |
|
| 149 | + $context['continue_percent'] = round((($_GET['step'] + ($_GET['substep'] / $max_substep)) * 100) / $context['total_steps']); |
|
| 150 | + } |
|
| 145 | 151 | |
| 146 | 152 | // Never more than 100%! |
| 147 | 153 | $context['continue_percent'] = min($context['continue_percent'], 100); |
@@ -617,8 +623,9 @@ discard block |
||
| 617 | 623 | $row['myid_last_msg'] = (int) $row['myid_last_msg']; |
| 618 | 624 | |
| 619 | 625 | // Not really a problem? |
| 620 | - if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved']) |
|
| 621 | - return false; |
|
| 626 | + if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved']) { |
|
| 627 | + return false; |
|
| 628 | + } |
|
| 622 | 629 | |
| 623 | 630 | $memberStartedID = (int) getMsgMemberID($row['myid_first_msg']); |
| 624 | 631 | $memberUpdatedID = (int) getMsgMemberID($row['myid_last_msg']); |
@@ -642,15 +649,19 @@ discard block |
||
| 642 | 649 | 'message_function' => function ($row) use ($txt, &$context) |
| 643 | 650 | { |
| 644 | 651 | // A pretend error? |
| 645 | - if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved']) |
|
| 646 | - return false; |
|
| 652 | + if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved']) { |
|
| 653 | + return false; |
|
| 654 | + } |
|
| 647 | 655 | |
| 648 | - if ($row['id_first_msg'] != $row['myid_first_msg']) |
|
| 649 | - $context['repair_errors'][] = sprintf($txt['repair_stats_topics_1'], $row['id_topic'], $row['id_first_msg']); |
|
| 650 | - if ($row['id_last_msg'] != $row['myid_last_msg']) |
|
| 651 | - $context['repair_errors'][] = sprintf($txt['repair_stats_topics_2'], $row['id_topic'], $row['id_last_msg']); |
|
| 652 | - if ($row['approved'] != $row['firstmsg_approved']) |
|
| 653 | - $context['repair_errors'][] = sprintf($txt['repair_stats_topics_5'], $row['id_topic']); |
|
| 656 | + if ($row['id_first_msg'] != $row['myid_first_msg']) { |
|
| 657 | + $context['repair_errors'][] = sprintf($txt['repair_stats_topics_1'], $row['id_topic'], $row['id_first_msg']); |
|
| 658 | + } |
|
| 659 | + if ($row['id_last_msg'] != $row['myid_last_msg']) { |
|
| 660 | + $context['repair_errors'][] = sprintf($txt['repair_stats_topics_2'], $row['id_topic'], $row['id_last_msg']); |
|
| 661 | + } |
|
| 662 | + if ($row['approved'] != $row['firstmsg_approved']) { |
|
| 663 | + $context['repair_errors'][] = sprintf($txt['repair_stats_topics_5'], $row['id_topic']); |
|
| 664 | + } |
|
| 654 | 665 | |
| 655 | 666 | return true; |
| 656 | 667 | }, |
@@ -680,8 +691,9 @@ discard block |
||
| 680 | 691 | $row['my_num_replies'] = (int) $row['my_num_replies']; |
| 681 | 692 | |
| 682 | 693 | // Not really a problem? |
| 683 | - if ($row['my_num_replies'] == $row['num_replies']) |
|
| 684 | - return false; |
|
| 694 | + if ($row['my_num_replies'] == $row['num_replies']) { |
|
| 695 | + return false; |
|
| 696 | + } |
|
| 685 | 697 | |
| 686 | 698 | $smcFunc['db_query']('', ' |
| 687 | 699 | UPDATE {db_prefix}topics |
@@ -700,11 +712,13 @@ discard block |
||
| 700 | 712 | global $txt, $context; |
| 701 | 713 | |
| 702 | 714 | // Just joking? |
| 703 | - if ($row['my_num_replies'] == $row['num_replies']) |
|
| 704 | - return false; |
|
| 715 | + if ($row['my_num_replies'] == $row['num_replies']) { |
|
| 716 | + return false; |
|
| 717 | + } |
|
| 705 | 718 | |
| 706 | - if ($row['num_replies'] != $row['my_num_replies']) |
|
| 707 | - $context['repair_errors'][] = sprintf($txt['repair_stats_topics_3'], $row['id_topic'], $row['num_replies']); |
|
| 719 | + if ($row['num_replies'] != $row['my_num_replies']) { |
|
| 720 | + $context['repair_errors'][] = sprintf($txt['repair_stats_topics_3'], $row['id_topic'], $row['num_replies']); |
|
| 721 | + } |
|
| 708 | 722 | |
| 709 | 723 | return true; |
| 710 | 724 | |
@@ -1295,8 +1309,9 @@ discard block |
||
| 1295 | 1309 | $inserts = array(); |
| 1296 | 1310 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 1297 | 1311 | { |
| 1298 | - foreach (text2words($row['subject']) as $word) |
|
| 1299 | - $inserts[] = array($word, $row['id_topic']); |
|
| 1312 | + foreach (text2words($row['subject']) as $word) { |
|
| 1313 | + $inserts[] = array($word, $row['id_topic']); |
|
| 1314 | + } |
|
| 1300 | 1315 | if (count($inserts) > 500) |
| 1301 | 1316 | { |
| 1302 | 1317 | $smcFunc['db_insert']('ignore', |
@@ -1310,13 +1325,14 @@ discard block |
||
| 1310 | 1325 | |
| 1311 | 1326 | } |
| 1312 | 1327 | |
| 1313 | - if (!empty($inserts)) |
|
| 1314 | - $smcFunc['db_insert']('ignore', |
|
| 1328 | + if (!empty($inserts)) { |
|
| 1329 | + $smcFunc['db_insert']('ignore', |
|
| 1315 | 1330 | '{db_prefix}log_search_subjects', |
| 1316 | 1331 | array('word' => 'string', 'id_topic' => 'int'), |
| 1317 | 1332 | $inserts, |
| 1318 | 1333 | array('word', 'id_topic') |
| 1319 | 1334 | ); |
| 1335 | + } |
|
| 1320 | 1336 | |
| 1321 | 1337 | }, |
| 1322 | 1338 | 'message_function' => function ($row) |
@@ -1586,8 +1602,9 @@ discard block |
||
| 1586 | 1602 | $current_step++; |
| 1587 | 1603 | |
| 1588 | 1604 | // Already done this? |
| 1589 | - if ($_GET['step'] > $current_step) |
|
| 1590 | - continue; |
|
| 1605 | + if ($_GET['step'] > $current_step) { |
|
| 1606 | + continue; |
|
| 1607 | + } |
|
| 1591 | 1608 | |
| 1592 | 1609 | // If we're fixing it but it ain't broke why try? |
| 1593 | 1610 | if ($do_fix && !in_array($error_type, $to_fix)) |
@@ -1616,14 +1633,16 @@ discard block |
||
| 1616 | 1633 | while (!$done) |
| 1617 | 1634 | { |
| 1618 | 1635 | // Make sure there's at least one ID to test. |
| 1619 | - if (isset($test['substeps']) && empty($step_max)) |
|
| 1620 | - break; |
|
| 1636 | + if (isset($test['substeps']) && empty($step_max)) { |
|
| 1637 | + break; |
|
| 1638 | + } |
|
| 1621 | 1639 | |
| 1622 | 1640 | // What is the testing query (Changes if we are testing or fixing) |
| 1623 | - if (!$do_fix) |
|
| 1624 | - $test_query = 'check_query'; |
|
| 1625 | - else |
|
| 1626 | - $test_query = isset($test['fix_query']) ? 'fix_query' : 'check_query'; |
|
| 1641 | + if (!$do_fix) { |
|
| 1642 | + $test_query = 'check_query'; |
|
| 1643 | + } else { |
|
| 1644 | + $test_query = isset($test['fix_query']) ? 'fix_query' : 'check_query'; |
|
| 1645 | + } |
|
| 1627 | 1646 | |
| 1628 | 1647 | // Do the test... |
| 1629 | 1648 | $request = $smcFunc['db_query']('', |
@@ -1634,10 +1653,11 @@ discard block |
||
| 1634 | 1653 | $needs_fix = false; |
| 1635 | 1654 | |
| 1636 | 1655 | // Does it need a fix? |
| 1637 | - if (!empty($test['check_type']) && $test['check_type'] == 'count') |
|
| 1638 | - list ($needs_fix) = $smcFunc['db_fetch_row']($request); |
|
| 1639 | - else |
|
| 1640 | - $needs_fix = $smcFunc['db_num_rows']($request); |
|
| 1656 | + if (!empty($test['check_type']) && $test['check_type'] == 'count') { |
|
| 1657 | + list ($needs_fix) = $smcFunc['db_fetch_row']($request); |
|
| 1658 | + } else { |
|
| 1659 | + $needs_fix = $smcFunc['db_num_rows']($request); |
|
| 1660 | + } |
|
| 1641 | 1661 | |
| 1642 | 1662 | $total_queries++; |
| 1643 | 1663 | |
@@ -1649,8 +1669,9 @@ discard block |
||
| 1649 | 1669 | // Assume need to fix. |
| 1650 | 1670 | $found_errors = true; |
| 1651 | 1671 | |
| 1652 | - if (isset($test['message'])) |
|
| 1653 | - $context['repair_errors'][] = $txt[$test['message']]; |
|
| 1672 | + if (isset($test['message'])) { |
|
| 1673 | + $context['repair_errors'][] = $txt[$test['message']]; |
|
| 1674 | + } |
|
| 1654 | 1675 | |
| 1655 | 1676 | // One per row! |
| 1656 | 1677 | elseif (isset($test['messages'])) |
@@ -1660,10 +1681,11 @@ discard block |
||
| 1660 | 1681 | $variables = $test['messages']; |
| 1661 | 1682 | foreach ($variables as $k => $v) |
| 1662 | 1683 | { |
| 1663 | - if ($k == 0 && isset($txt[$v])) |
|
| 1664 | - $variables[$k] = $txt[$v]; |
|
| 1665 | - elseif ($k > 0 && isset($row[$v])) |
|
| 1666 | - $variables[$k] = $row[$v]; |
|
| 1684 | + if ($k == 0 && isset($txt[$v])) { |
|
| 1685 | + $variables[$k] = $txt[$v]; |
|
| 1686 | + } elseif ($k > 0 && isset($row[$v])) { |
|
| 1687 | + $variables[$k] = $row[$v]; |
|
| 1688 | + } |
|
| 1667 | 1689 | } |
| 1668 | 1690 | $context['repair_errors'][] = call_user_func_array('sprintf', $variables); |
| 1669 | 1691 | } |
@@ -1674,13 +1696,15 @@ discard block |
||
| 1674 | 1696 | { |
| 1675 | 1697 | // Find out if there are actually errors. |
| 1676 | 1698 | $found_errors = false; |
| 1677 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1678 | - $found_errors |= $test['message_function']($row); |
|
| 1699 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1700 | + $found_errors |= $test['message_function']($row); |
|
| 1701 | + } |
|
| 1679 | 1702 | } |
| 1680 | 1703 | |
| 1681 | 1704 | // Actually have something to fix? |
| 1682 | - if ($found_errors) |
|
| 1683 | - $to_fix[] = $error_type; |
|
| 1705 | + if ($found_errors) { |
|
| 1706 | + $to_fix[] = $error_type; |
|
| 1707 | + } |
|
| 1684 | 1708 | } |
| 1685 | 1709 | |
| 1686 | 1710 | // We want to fix, we need to fix - so work out what exactly to do! |
@@ -1690,8 +1714,9 @@ discard block |
||
| 1690 | 1714 | if (isset($test['fix_collect'])) |
| 1691 | 1715 | { |
| 1692 | 1716 | $ids = array(); |
| 1693 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1694 | - $ids[] = $row[$test['fix_collect']['index']]; |
|
| 1717 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1718 | + $ids[] = $row[$test['fix_collect']['index']]; |
|
| 1719 | + } |
|
| 1695 | 1720 | if (!empty($ids)) |
| 1696 | 1721 | { |
| 1697 | 1722 | // Fix it! |
@@ -1700,30 +1725,34 @@ discard block |
||
| 1700 | 1725 | } |
| 1701 | 1726 | |
| 1702 | 1727 | // Simply executing a fix it query? |
| 1703 | - elseif (isset($test['fix_it_query'])) |
|
| 1704 | - $smcFunc['db_query']('', |
|
| 1728 | + elseif (isset($test['fix_it_query'])) { |
|
| 1729 | + $smcFunc['db_query']('', |
|
| 1705 | 1730 | $test['fix_it_query'], |
| 1706 | 1731 | array( |
| 1707 | 1732 | ) |
| 1708 | 1733 | ); |
| 1734 | + } |
|
| 1709 | 1735 | |
| 1710 | 1736 | // Do we have some processing to do? |
| 1711 | 1737 | elseif (isset($test['fix_processing'])) |
| 1712 | 1738 | { |
| 1713 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1714 | - $test['fix_processing']($row); |
|
| 1739 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1740 | + $test['fix_processing']($row); |
|
| 1741 | + } |
|
| 1715 | 1742 | } |
| 1716 | 1743 | |
| 1717 | 1744 | // What about the full set of processing? |
| 1718 | - elseif (isset($test['fix_full_processing'])) |
|
| 1719 | - $test['fix_full_processing']($request); |
|
| 1745 | + elseif (isset($test['fix_full_processing'])) { |
|
| 1746 | + $test['fix_full_processing']($request); |
|
| 1747 | + } |
|
| 1720 | 1748 | |
| 1721 | 1749 | // Do we have other things we need to fix as a result? |
| 1722 | 1750 | if (!empty($test['force_fix'])) |
| 1723 | 1751 | { |
| 1724 | - foreach ($test['force_fix'] as $item) |
|
| 1725 | - if (!in_array($item, $to_fix)) |
|
| 1752 | + foreach ($test['force_fix'] as $item) { |
|
| 1753 | + if (!in_array($item, $to_fix)) |
|
| 1726 | 1754 | $to_fix[] = $item; |
| 1755 | + } |
|
| 1727 | 1756 | } |
| 1728 | 1757 | } |
| 1729 | 1758 | } |
@@ -1741,16 +1770,17 @@ discard block |
||
| 1741 | 1770 | if ($_GET['substep'] <= $step_max) |
| 1742 | 1771 | { |
| 1743 | 1772 | pauseRepairProcess($to_fix, $error_type, $step_max); |
| 1773 | + } else { |
|
| 1774 | + $done = true; |
|
| 1744 | 1775 | } |
| 1745 | - else |
|
| 1746 | - $done = true; |
|
| 1776 | + } else { |
|
| 1777 | + $done = true; |
|
| 1747 | 1778 | } |
| 1748 | - else |
|
| 1749 | - $done = true; |
|
| 1750 | 1779 | |
| 1751 | 1780 | // Don't allow more than 1000 queries at a time. |
| 1752 | - if ($total_queries >= 1000) |
|
| 1753 | - pauseRepairProcess($to_fix, $error_type, $step_max, true); |
|
| 1781 | + if ($total_queries >= 1000) { |
|
| 1782 | + pauseRepairProcess($to_fix, $error_type, $step_max, true); |
|
| 1783 | + } |
|
| 1754 | 1784 | } |
| 1755 | 1785 | |
| 1756 | 1786 | // Keep going. |
@@ -1763,8 +1793,9 @@ discard block |
||
| 1763 | 1793 | if ($do_fix) |
| 1764 | 1794 | { |
| 1765 | 1795 | $key = array_search($error_type, $to_fix); |
| 1766 | - if ($key !== false && isset($to_fix[$key])) |
|
| 1767 | - unset($to_fix[$key]); |
|
| 1796 | + if ($key !== false && isset($to_fix[$key])) { |
|
| 1797 | + unset($to_fix[$key]); |
|
| 1798 | + } |
|
| 1768 | 1799 | } |
| 1769 | 1800 | |
| 1770 | 1801 | // Are we done? |
@@ -1787,10 +1818,11 @@ discard block |
||
| 1787 | 1818 | static $createOnce = false; |
| 1788 | 1819 | |
| 1789 | 1820 | // Have we already created it? |
| 1790 | - if ($createOnce) |
|
| 1791 | - return; |
|
| 1792 | - else |
|
| 1793 | - $createOnce = true; |
|
| 1821 | + if ($createOnce) { |
|
| 1822 | + return; |
|
| 1823 | + } else { |
|
| 1824 | + $createOnce = true; |
|
| 1825 | + } |
|
| 1794 | 1826 | |
| 1795 | 1827 | // Back to the forum's default language. |
| 1796 | 1828 | loadLanguage('Admin', $language); |
@@ -1805,8 +1837,9 @@ discard block |
||
| 1805 | 1837 | 'cat_name' => $txt['salvaged_category_name'], |
| 1806 | 1838 | ) |
| 1807 | 1839 | ); |
| 1808 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1809 | - list ($salvageCatID) = $smcFunc['db_fetch_row']($result); |
|
| 1840 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1841 | + list ($salvageCatID) = $smcFunc['db_fetch_row']($result); |
|
| 1842 | + } |
|
| 1810 | 1843 | $smcFunc['db_free_result']($result); |
| 1811 | 1844 | |
| 1812 | 1845 | if (empty($salvageCatID)) |
@@ -1839,8 +1872,9 @@ discard block |
||
| 1839 | 1872 | 'board_name' => $txt['salvaged_board_name'], |
| 1840 | 1873 | ) |
| 1841 | 1874 | ); |
| 1842 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1843 | - list ($salvageBoardID) = $smcFunc['db_fetch_row']($result); |
|
| 1875 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1876 | + list ($salvageBoardID) = $smcFunc['db_fetch_row']($result); |
|
| 1877 | + } |
|
| 1844 | 1878 | $smcFunc['db_free_result']($result); |
| 1845 | 1879 | |
| 1846 | 1880 | if (empty($salvageBoardID)) |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * The main handler and designator for AJAX stuff - jumpto, message icons and previews |
@@ -32,8 +33,9 @@ discard block |
||
| 32 | 33 | // Easy adding of sub actions. |
| 33 | 34 | call_integration_hook('integrate_XMLhttpMain_subActions', array(&$subActions)); |
| 34 | 35 | |
| 35 | - if (!isset($_REQUEST['sa'], $subActions[$_REQUEST['sa']])) |
|
| 36 | - fatal_lang_error('no_access', false); |
|
| 36 | + if (!isset($_REQUEST['sa'], $subActions[$_REQUEST['sa']])) { |
|
| 37 | + fatal_lang_error('no_access', false); |
|
| 38 | + } |
|
| 37 | 39 | |
| 38 | 40 | call_helper($subActions[$_REQUEST['sa']]); |
| 39 | 41 | } |
@@ -57,8 +59,9 @@ discard block |
||
| 57 | 59 | foreach ($context['jump_to'] as $id_cat => $cat) |
| 58 | 60 | { |
| 59 | 61 | $context['jump_to'][$id_cat]['name'] = un_htmlspecialchars(strip_tags($cat['name'])); |
| 60 | - foreach ($cat['boards'] as $id_board => $board) |
|
| 61 | - $context['jump_to'][$id_cat]['boards'][$id_board]['name'] = un_htmlspecialchars(strip_tags($board['name'])); |
|
| 62 | + foreach ($cat['boards'] as $id_board => $board) { |
|
| 63 | + $context['jump_to'][$id_cat]['boards'][$id_board]['name'] = un_htmlspecialchars(strip_tags($board['name'])); |
|
| 64 | + } |
|
| 62 | 65 | } |
| 63 | 66 | |
| 64 | 67 | $context['sub_template'] = 'jump_to'; |
@@ -95,8 +98,9 @@ discard block |
||
| 95 | 98 | |
| 96 | 99 | $context['sub_template'] = 'generic_xml'; |
| 97 | 100 | |
| 98 | - if (!isset($_POST['item']) || !in_array($_POST['item'], $items)) |
|
| 99 | - return false; |
|
| 101 | + if (!isset($_POST['item']) || !in_array($_POST['item'], $items)) { |
|
| 102 | + return false; |
|
| 103 | + } |
|
| 100 | 104 | |
| 101 | 105 | $_POST['item'](); |
| 102 | 106 | } |
@@ -112,10 +116,11 @@ discard block |
||
| 112 | 116 | |
| 113 | 117 | $errors = array(); |
| 114 | 118 | $news = !isset($_POST['news'])? '' : $smcFunc['htmlspecialchars']($_POST['news'], ENT_QUOTES); |
| 115 | - if (empty($news)) |
|
| 116 | - $errors[] = array('value' => 'no_news'); |
|
| 117 | - else |
|
| 118 | - preparsecode($news); |
|
| 119 | + if (empty($news)) { |
|
| 120 | + $errors[] = array('value' => 'no_news'); |
|
| 121 | + } else { |
|
| 122 | + preparsecode($news); |
|
| 123 | + } |
|
| 119 | 124 | |
| 120 | 125 | $context['xml_data'] = array( |
| 121 | 126 | 'news' => array( |
@@ -148,10 +153,12 @@ discard block |
||
| 148 | 153 | $context['send_pm'] = !empty($_POST['send_pm']) ? 1 : 0; |
| 149 | 154 | $context['send_html'] = !empty($_POST['send_html']) ? 1 : 0; |
| 150 | 155 | |
| 151 | - if (empty($_POST['subject'])) |
|
| 152 | - $context['post_error']['messages'][] = $txt['error_no_subject']; |
|
| 153 | - if (empty($_POST['message'])) |
|
| 154 | - $context['post_error']['messages'][] = $txt['error_no_message']; |
|
| 156 | + if (empty($_POST['subject'])) { |
|
| 157 | + $context['post_error']['messages'][] = $txt['error_no_subject']; |
|
| 158 | + } |
|
| 159 | + if (empty($_POST['message'])) { |
|
| 160 | + $context['post_error']['messages'][] = $txt['error_no_message']; |
|
| 161 | + } |
|
| 155 | 162 | |
| 156 | 163 | prepareMailingForPreview(); |
| 157 | 164 | |
@@ -196,38 +203,41 @@ discard block |
||
| 196 | 203 | $preview_signature = !empty($_POST['signature']) ? $_POST['signature'] : $txt['no_signature_preview']; |
| 197 | 204 | $validation = profileValidateSignature($preview_signature); |
| 198 | 205 | |
| 199 | - if ($validation !== true && $validation !== false) |
|
| 200 | - $errors[] = array('value' => $txt['profile_error_' . $validation], 'attributes' => array('type' => 'error')); |
|
| 206 | + if ($validation !== true && $validation !== false) { |
|
| 207 | + $errors[] = array('value' => $txt['profile_error_' . $validation], 'attributes' => array('type' => 'error')); |
|
| 208 | + } |
|
| 201 | 209 | |
| 202 | 210 | censorText($preview_signature); |
| 203 | 211 | $preview_signature = parse_bbc($preview_signature, true, 'sig' . $user); |
| 204 | - } |
|
| 205 | - elseif (!$can_change) |
|
| 212 | + } elseif (!$can_change) |
|
| 206 | 213 | { |
| 207 | - if ($is_owner) |
|
| 208 | - $errors[] = array('value' => $txt['cannot_profile_extra_own'], 'attributes' => array('type' => 'error')); |
|
| 209 | - else |
|
| 210 | - $errors[] = array('value' => $txt['cannot_profile_extra_any'], 'attributes' => array('type' => 'error')); |
|
| 214 | + if ($is_owner) { |
|
| 215 | + $errors[] = array('value' => $txt['cannot_profile_extra_own'], 'attributes' => array('type' => 'error')); |
|
| 216 | + } else { |
|
| 217 | + $errors[] = array('value' => $txt['cannot_profile_extra_any'], 'attributes' => array('type' => 'error')); |
|
| 218 | + } |
|
| 219 | + } else { |
|
| 220 | + $errors[] = array('value' => $txt['no_user_selected'], 'attributes' => array('type' => 'error')); |
|
| 211 | 221 | } |
| 212 | - else |
|
| 213 | - $errors[] = array('value' => $txt['no_user_selected'], 'attributes' => array('type' => 'error')); |
|
| 214 | 222 | |
| 215 | 223 | $context['xml_data']['signatures'] = array( |
| 216 | 224 | 'identifier' => 'signature', |
| 217 | 225 | 'children' => array() |
| 218 | 226 | ); |
| 219 | - if (isset($current_signature)) |
|
| 220 | - $context['xml_data']['signatures']['children'][] = array( |
|
| 227 | + if (isset($current_signature)) { |
|
| 228 | + $context['xml_data']['signatures']['children'][] = array( |
|
| 221 | 229 | 'value' => $current_signature, |
| 222 | 230 | 'attributes' => array('type' => 'current'), |
| 223 | 231 | ); |
| 224 | - if (isset($preview_signature)) |
|
| 225 | - $context['xml_data']['signatures']['children'][] = array( |
|
| 232 | + } |
|
| 233 | + if (isset($preview_signature)) { |
|
| 234 | + $context['xml_data']['signatures']['children'][] = array( |
|
| 226 | 235 | 'value' => $preview_signature, |
| 227 | 236 | 'attributes' => array('type' => 'preview'), |
| 228 | 237 | ); |
| 229 | - if (!empty($errors)) |
|
| 230 | - $context['xml_data']['errors'] = array( |
|
| 238 | + } |
|
| 239 | + if (!empty($errors)) { |
|
| 240 | + $context['xml_data']['errors'] = array( |
|
| 231 | 241 | 'identifier' => 'error', |
| 232 | 242 | 'children' => array_merge( |
| 233 | 243 | array( |
@@ -239,7 +249,8 @@ discard block |
||
| 239 | 249 | $errors |
| 240 | 250 | ), |
| 241 | 251 | ); |
| 242 | -} |
|
| 252 | + } |
|
| 253 | + } |
|
| 243 | 254 | |
| 244 | 255 | /** |
| 245 | 256 | * Handles previewing user warnings |
@@ -261,15 +272,17 @@ discard block |
||
| 261 | 272 | $context['preview_subject'] = !empty($_POST['title']) ? trim($smcFunc['htmlspecialchars']($_POST['title'])) : ''; |
| 262 | 273 | if (isset($_POST['issuing'])) |
| 263 | 274 | { |
| 264 | - if (empty($_POST['title']) || empty($_POST['body'])) |
|
| 265 | - $context['post_error']['messages'][] = $txt['warning_notify_blank']; |
|
| 266 | - } |
|
| 267 | - else |
|
| 275 | + if (empty($_POST['title']) || empty($_POST['body'])) { |
|
| 276 | + $context['post_error']['messages'][] = $txt['warning_notify_blank']; |
|
| 277 | + } |
|
| 278 | + } else |
|
| 268 | 279 | { |
| 269 | - if (empty($_POST['title'])) |
|
| 270 | - $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_title']; |
|
| 271 | - if (empty($_POST['body'])) |
|
| 272 | - $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_body']; |
|
| 280 | + if (empty($_POST['title'])) { |
|
| 281 | + $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_title']; |
|
| 282 | + } |
|
| 283 | + if (empty($_POST['body'])) { |
|
| 284 | + $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_body']; |
|
| 285 | + } |
|
| 273 | 286 | // Add in few replacements. |
| 274 | 287 | /** |
| 275 | 288 | * These are the defaults: |
@@ -300,9 +313,9 @@ discard block |
||
| 300 | 313 | $warning_body = parse_bbc($warning_body, true); |
| 301 | 314 | } |
| 302 | 315 | $context['preview_message'] = $warning_body; |
| 316 | + } else { |
|
| 317 | + $context['post_error']['messages'][] = array('value' => $txt['cannot_issue_warning'], 'attributes' => array('type' => 'error')); |
|
| 303 | 318 | } |
| 304 | - else |
|
| 305 | - $context['post_error']['messages'][] = array('value' => $txt['cannot_issue_warning'], 'attributes' => array('type' => 'error')); |
|
| 306 | 319 | |
| 307 | 320 | $context['sub_template'] = 'warning'; |
| 308 | 321 | } |
@@ -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. |
@@ -23,14 +24,15 @@ discard block |
||
| 23 | 24 | { |
| 24 | 25 | global $smcFunc; |
| 25 | 26 | |
| 26 | - if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_query') |
|
| 27 | - $smcFunc += array( |
|
| 27 | + if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_query') { |
|
| 28 | + $smcFunc += array( |
|
| 28 | 29 | 'db_search_query' => 'smf_db_query', |
| 29 | 30 | 'db_search_support' => 'smf_db_search_support', |
| 30 | 31 | 'db_create_word_search' => 'smf_db_create_word_search', |
| 31 | 32 | 'db_support_ignore' => true, |
| 32 | 33 | ); |
| 33 | -} |
|
| 34 | + } |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | /** |
| 36 | 38 | * This function will tell you whether this database type supports this search type. |
@@ -54,12 +56,13 @@ discard block |
||
| 54 | 56 | { |
| 55 | 57 | global $smcFunc; |
| 56 | 58 | |
| 57 | - if ($size == 'small') |
|
| 58 | - $size = 'smallint(5)'; |
|
| 59 | - elseif ($size == 'medium') |
|
| 60 | - $size = 'mediumint(8)'; |
|
| 61 | - else |
|
| 62 | - $size = 'int(10)'; |
|
| 59 | + if ($size == 'small') { |
|
| 60 | + $size = 'smallint(5)'; |
|
| 61 | + } elseif ($size == 'medium') { |
|
| 62 | + $size = 'mediumint(8)'; |
|
| 63 | + } else { |
|
| 64 | + $size = 'int(10)'; |
|
| 65 | + } |
|
| 63 | 66 | |
| 64 | 67 | $smcFunc['db_query']('', ' |
| 65 | 68 | CREATE TABLE {db_prefix}log_search_words ( |
@@ -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) |
@@ -33,8 +34,8 @@ discard block |
||
| 33 | 34 | global $smcFunc, $mysql_set_mode; |
| 34 | 35 | |
| 35 | 36 | // Map some database specific functions, only do this once. |
| 36 | - if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysql_fetch_assoc') |
|
| 37 | - $smcFunc += array( |
|
| 37 | + if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysql_fetch_assoc') { |
|
| 38 | + $smcFunc += array( |
|
| 38 | 39 | 'db_query' => 'smf_db_query', |
| 39 | 40 | 'db_quote' => 'smf_db_quote', |
| 40 | 41 | 'db_fetch_assoc' => 'mysql_fetch_assoc', |
@@ -58,36 +59,42 @@ discard block |
||
| 58 | 59 | 'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string', |
| 59 | 60 | 'db_is_resource' => 'is_resource', |
| 60 | 61 | ); |
| 62 | + } |
|
| 61 | 63 | |
| 62 | - if (!empty($db_options['port'])) |
|
| 63 | - $db_server .= ':' . $db_options['port']; |
|
| 64 | + if (!empty($db_options['port'])) { |
|
| 65 | + $db_server .= ':' . $db_options['port']; |
|
| 66 | + } |
|
| 64 | 67 | |
| 65 | 68 | $flags = 2; //#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */ |
| 66 | 69 | |
| 67 | - if (!empty($db_options['persist'])) |
|
| 68 | - $connection = @mysql_pconnect($db_server, $db_user, $db_passwd, $flags); |
|
| 69 | - else |
|
| 70 | - $connection = @mysql_connect($db_server, $db_user, $db_passwd, false, $flags); |
|
| 70 | + if (!empty($db_options['persist'])) { |
|
| 71 | + $connection = @mysql_pconnect($db_server, $db_user, $db_passwd, $flags); |
|
| 72 | + } else { |
|
| 73 | + $connection = @mysql_connect($db_server, $db_user, $db_passwd, false, $flags); |
|
| 74 | + } |
|
| 71 | 75 | |
| 72 | 76 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 73 | 77 | if (!$connection) |
| 74 | 78 | { |
| 75 | - if (!empty($db_options['non_fatal'])) |
|
| 76 | - return null; |
|
| 77 | - else |
|
| 78 | - display_db_error(); |
|
| 79 | + if (!empty($db_options['non_fatal'])) { |
|
| 80 | + return null; |
|
| 81 | + } else { |
|
| 82 | + display_db_error(); |
|
| 83 | + } |
|
| 79 | 84 | } |
| 80 | 85 | |
| 81 | 86 | // Select the database, unless told not to |
| 82 | - if (empty($db_options['dont_select_db']) && !@mysql_select_db($db_name, $connection) && empty($db_options['non_fatal'])) |
|
| 83 | - display_db_error(); |
|
| 87 | + if (empty($db_options['dont_select_db']) && !@mysql_select_db($db_name, $connection) && empty($db_options['non_fatal'])) { |
|
| 88 | + display_db_error(); |
|
| 89 | + } |
|
| 84 | 90 | |
| 85 | 91 | // This makes it possible to have SMF automatically change the sql_mode and autocommit if needed. |
| 86 | - if (isset($mysql_set_mode) && $mysql_set_mode === true) |
|
| 87 | - $smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1', |
|
| 92 | + if (isset($mysql_set_mode) && $mysql_set_mode === true) { |
|
| 93 | + $smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1', |
|
| 88 | 94 | array(), |
| 89 | 95 | false |
| 90 | 96 | ); |
| 97 | + } |
|
| 91 | 98 | |
| 92 | 99 | return $connection; |
| 93 | 100 | } |
@@ -134,37 +141,46 @@ discard block |
||
| 134 | 141 | list ($values, $connection) = $db_callback; |
| 135 | 142 | |
| 136 | 143 | // Connection gone??? This should *never* happen at this point, yet it does :'( |
| 137 | - if (!is_resource($connection)) |
|
| 138 | - display_db_error(); |
|
| 144 | + if (!is_resource($connection)) { |
|
| 145 | + display_db_error(); |
|
| 146 | + } |
|
| 139 | 147 | |
| 140 | - if ($matches[1] === 'db_prefix') |
|
| 141 | - return $db_prefix; |
|
| 148 | + if ($matches[1] === 'db_prefix') { |
|
| 149 | + return $db_prefix; |
|
| 150 | + } |
|
| 142 | 151 | |
| 143 | - if ($matches[1] === 'query_see_board') |
|
| 144 | - return $user_info['query_see_board']; |
|
| 152 | + if ($matches[1] === 'query_see_board') { |
|
| 153 | + return $user_info['query_see_board']; |
|
| 154 | + } |
|
| 145 | 155 | |
| 146 | - if ($matches[1] === 'query_wanna_see_board') |
|
| 147 | - return $user_info['query_wanna_see_board']; |
|
| 156 | + if ($matches[1] === 'query_wanna_see_board') { |
|
| 157 | + return $user_info['query_wanna_see_board']; |
|
| 158 | + } |
|
| 148 | 159 | |
| 149 | - if ($matches[1] === 'empty') |
|
| 150 | - return '\'\''; |
|
| 160 | + if ($matches[1] === 'empty') { |
|
| 161 | + return '\'\''; |
|
| 162 | + } |
|
| 151 | 163 | |
| 152 | - if (!isset($matches[2])) |
|
| 153 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 164 | + if (!isset($matches[2])) { |
|
| 165 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 166 | + } |
|
| 154 | 167 | |
| 155 | - if ($matches[1] === 'literal') |
|
| 156 | - return '\'' . mysql_real_escape_string($matches[2], $connection) . '\''; |
|
| 168 | + if ($matches[1] === 'literal') { |
|
| 169 | + return '\'' . mysql_real_escape_string($matches[2], $connection) . '\''; |
|
| 170 | + } |
|
| 157 | 171 | |
| 158 | - if (!isset($values[$matches[2]])) |
|
| 159 | - 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__); |
|
| 172 | + if (!isset($values[$matches[2]])) { |
|
| 173 | + 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__); |
|
| 174 | + } |
|
| 160 | 175 | |
| 161 | 176 | $replacement = $values[$matches[2]]; |
| 162 | 177 | |
| 163 | 178 | switch ($matches[1]) |
| 164 | 179 | { |
| 165 | 180 | case 'int': |
| 166 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 167 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 181 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 182 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 183 | + } |
|
| 168 | 184 | return (string) (int) $replacement; |
| 169 | 185 | break; |
| 170 | 186 | |
@@ -176,49 +192,55 @@ discard block |
||
| 176 | 192 | case 'array_int': |
| 177 | 193 | if (is_array($replacement)) |
| 178 | 194 | { |
| 179 | - if (empty($replacement)) |
|
| 180 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 195 | + if (empty($replacement)) { |
|
| 196 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 197 | + } |
|
| 181 | 198 | |
| 182 | 199 | foreach ($replacement as $key => $value) |
| 183 | 200 | { |
| 184 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 185 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 201 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 202 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 203 | + } |
|
| 186 | 204 | |
| 187 | 205 | $replacement[$key] = (string) (int) $value; |
| 188 | 206 | } |
| 189 | 207 | |
| 190 | 208 | return implode(', ', $replacement); |
| 209 | + } else { |
|
| 210 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 191 | 211 | } |
| 192 | - else |
|
| 193 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 194 | 212 | |
| 195 | 213 | break; |
| 196 | 214 | |
| 197 | 215 | case 'array_string': |
| 198 | 216 | if (is_array($replacement)) |
| 199 | 217 | { |
| 200 | - if (empty($replacement)) |
|
| 201 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 218 | + if (empty($replacement)) { |
|
| 219 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 220 | + } |
|
| 202 | 221 | |
| 203 | - foreach ($replacement as $key => $value) |
|
| 204 | - $replacement[$key] = sprintf('\'%1$s\'', mysql_real_escape_string($value, $connection)); |
|
| 222 | + foreach ($replacement as $key => $value) { |
|
| 223 | + $replacement[$key] = sprintf('\'%1$s\'', mysql_real_escape_string($value, $connection)); |
|
| 224 | + } |
|
| 205 | 225 | |
| 206 | 226 | return implode(', ', $replacement); |
| 227 | + } else { |
|
| 228 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 207 | 229 | } |
| 208 | - else |
|
| 209 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 210 | 230 | break; |
| 211 | 231 | |
| 212 | 232 | case 'date': |
| 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__); |
|
| 233 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 234 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 235 | + } else { |
|
| 236 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 237 | + } |
|
| 217 | 238 | break; |
| 218 | 239 | |
| 219 | 240 | case 'float': |
| 220 | - if (!is_numeric($replacement)) |
|
| 221 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 241 | + if (!is_numeric($replacement)) { |
|
| 242 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 243 | + } |
|
| 222 | 244 | return (string) (float) $replacement; |
| 223 | 245 | break; |
| 224 | 246 | |
@@ -232,10 +254,12 @@ discard block |
||
| 232 | 254 | break; |
| 233 | 255 | |
| 234 | 256 | case 'inet': |
| 235 | - if ($replacement == 'null' || $replacement == '') |
|
| 236 | - return 'null'; |
|
| 237 | - if (!isValidIP($replacement)) |
|
| 238 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 257 | + if ($replacement == 'null' || $replacement == '') { |
|
| 258 | + return 'null'; |
|
| 259 | + } |
|
| 260 | + if (!isValidIP($replacement)) { |
|
| 261 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 262 | + } |
|
| 239 | 263 | //we don't use the native support of mysql > 5.6.2 |
| 240 | 264 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
| 241 | 265 | break; |
@@ -243,22 +267,25 @@ discard block |
||
| 243 | 267 | case 'array_inet': |
| 244 | 268 | if (is_array($replacement)) |
| 245 | 269 | { |
| 246 | - if (empty($replacement)) |
|
| 247 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 270 | + if (empty($replacement)) { |
|
| 271 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 272 | + } |
|
| 248 | 273 | |
| 249 | 274 | foreach ($replacement as $key => $value) |
| 250 | 275 | { |
| 251 | - if ($replacement == 'null' || $replacement == '') |
|
| 252 | - $replacement[$key] = 'null'; |
|
| 253 | - if (!isValidIP($value)) |
|
| 254 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 276 | + if ($replacement == 'null' || $replacement == '') { |
|
| 277 | + $replacement[$key] = 'null'; |
|
| 278 | + } |
|
| 279 | + if (!isValidIP($value)) { |
|
| 280 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 281 | + } |
|
| 255 | 282 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
| 256 | 283 | } |
| 257 | 284 | |
| 258 | 285 | return implode(', ', $replacement); |
| 286 | + } else { |
|
| 287 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 259 | 288 | } |
| 260 | - else |
|
| 261 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 262 | 289 | break; |
| 263 | 290 | |
| 264 | 291 | default: |
@@ -329,18 +356,20 @@ discard block |
||
| 329 | 356 | // One more query.... |
| 330 | 357 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 331 | 358 | |
| 332 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 333 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 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__); |
|
| 361 | + } |
|
| 334 | 362 | |
| 335 | 363 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
| 336 | 364 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
| 337 | 365 | { |
| 338 | 366 | // Add before LIMIT |
| 339 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
| 340 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 341 | - else |
|
| 342 | - // Append it. |
|
| 367 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
| 368 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 369 | + } else { |
|
| 370 | + // Append it. |
|
| 343 | 371 | $db_string .= "\n\t\t\tORDER BY null"; |
| 372 | + } |
|
| 344 | 373 | } |
| 345 | 374 | |
| 346 | 375 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -362,8 +391,9 @@ discard block |
||
| 362 | 391 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 363 | 392 | |
| 364 | 393 | // Initialize $db_cache if not already initialized. |
| 365 | - if (!isset($db_cache)) |
|
| 366 | - $db_cache = array(); |
|
| 394 | + if (!isset($db_cache)) { |
|
| 395 | + $db_cache = array(); |
|
| 396 | + } |
|
| 367 | 397 | |
| 368 | 398 | if (!empty($_SESSION['debug_redirect'])) |
| 369 | 399 | { |
@@ -389,17 +419,18 @@ discard block |
||
| 389 | 419 | while (true) |
| 390 | 420 | { |
| 391 | 421 | $pos = strpos($db_string, '\'', $pos + 1); |
| 392 | - if ($pos === false) |
|
| 393 | - break; |
|
| 422 | + if ($pos === false) { |
|
| 423 | + break; |
|
| 424 | + } |
|
| 394 | 425 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
| 395 | 426 | |
| 396 | 427 | while (true) |
| 397 | 428 | { |
| 398 | 429 | $pos1 = strpos($db_string, '\'', $pos + 1); |
| 399 | 430 | $pos2 = strpos($db_string, '\\', $pos + 1); |
| 400 | - if ($pos1 === false) |
|
| 401 | - break; |
|
| 402 | - elseif ($pos2 == false || $pos2 > $pos1) |
|
| 431 | + if ($pos1 === false) { |
|
| 432 | + break; |
|
| 433 | + } elseif ($pos2 == false || $pos2 > $pos1) |
|
| 403 | 434 | { |
| 404 | 435 | $pos = $pos1; |
| 405 | 436 | break; |
@@ -415,29 +446,35 @@ discard block |
||
| 415 | 446 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 416 | 447 | |
| 417 | 448 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 418 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 419 | - $fail = true; |
|
| 449 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 450 | + $fail = true; |
|
| 451 | + } |
|
| 420 | 452 | // Trying to change passwords, slow us down, or something? |
| 421 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 422 | - $fail = true; |
|
| 423 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 424 | - $fail = true; |
|
| 453 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 454 | + $fail = true; |
|
| 455 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 456 | + $fail = true; |
|
| 457 | + } |
|
| 425 | 458 | |
| 426 | - if (!empty($fail) && function_exists('log_error')) |
|
| 427 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 459 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 460 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 461 | + } |
|
| 428 | 462 | } |
| 429 | 463 | |
| 430 | - if (empty($db_unbuffered)) |
|
| 431 | - $ret = @mysql_query($db_string, $connection); |
|
| 432 | - else |
|
| 433 | - $ret = @mysql_unbuffered_query($db_string, $connection); |
|
| 464 | + if (empty($db_unbuffered)) { |
|
| 465 | + $ret = @mysql_query($db_string, $connection); |
|
| 466 | + } else { |
|
| 467 | + $ret = @mysql_unbuffered_query($db_string, $connection); |
|
| 468 | + } |
|
| 434 | 469 | |
| 435 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
| 436 | - $ret = smf_db_error($db_string, $connection); |
|
| 470 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
| 471 | + $ret = smf_db_error($db_string, $connection); |
|
| 472 | + } |
|
| 437 | 473 | |
| 438 | 474 | // Debugging. |
| 439 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 440 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 475 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 476 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 477 | + } |
|
| 441 | 478 | |
| 442 | 479 | return $ret; |
| 443 | 480 | } |
@@ -486,12 +523,13 @@ discard block |
||
| 486 | 523 | // Decide which connection to use |
| 487 | 524 | $connection = $connection === null ? $db_connection : $connection; |
| 488 | 525 | |
| 489 | - if ($type == 'begin') |
|
| 490 | - return @mysql_query('BEGIN', $connection); |
|
| 491 | - elseif ($type == 'rollback') |
|
| 492 | - return @mysql_query('ROLLBACK', $connection); |
|
| 493 | - elseif ($type == 'commit') |
|
| 494 | - return @mysql_query('COMMIT', $connection); |
|
| 526 | + if ($type == 'begin') { |
|
| 527 | + return @mysql_query('BEGIN', $connection); |
|
| 528 | + } elseif ($type == 'rollback') { |
|
| 529 | + return @mysql_query('ROLLBACK', $connection); |
|
| 530 | + } elseif ($type == 'commit') { |
|
| 531 | + return @mysql_query('COMMIT', $connection); |
|
| 532 | + } |
|
| 495 | 533 | |
| 496 | 534 | return false; |
| 497 | 535 | } |
@@ -531,8 +569,9 @@ discard block |
||
| 531 | 569 | // 2013: Lost connection to server during query. |
| 532 | 570 | |
| 533 | 571 | // Log the error. |
| 534 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
| 535 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 572 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
| 573 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 574 | + } |
|
| 536 | 575 | |
| 537 | 576 | // Database error auto fixing ;). |
| 538 | 577 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -541,8 +580,9 @@ discard block |
||
| 541 | 580 | $old_cache = @$modSettings['cache_enable']; |
| 542 | 581 | $modSettings['cache_enable'] = '1'; |
| 543 | 582 | |
| 544 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
| 545 | - $db_last_error = max(@$db_last_error, $temp); |
|
| 583 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
| 584 | + $db_last_error = max(@$db_last_error, $temp); |
|
| 585 | + } |
|
| 546 | 586 | |
| 547 | 587 | if (@$db_last_error < time() - 3600 * 24 * 3) |
| 548 | 588 | { |
@@ -558,8 +598,9 @@ discard block |
||
| 558 | 598 | foreach ($tables as $table) |
| 559 | 599 | { |
| 560 | 600 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
| 561 | - if (trim($table) != '') |
|
| 562 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 601 | + if (trim($table) != '') { |
|
| 602 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 603 | + } |
|
| 563 | 604 | } |
| 564 | 605 | } |
| 565 | 606 | |
@@ -568,8 +609,9 @@ discard block |
||
| 568 | 609 | // Table crashed. Let's try to fix it. |
| 569 | 610 | elseif ($query_errno == 1016) |
| 570 | 611 | { |
| 571 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
| 572 | - $fix_tables = array('`' . $match[1] . '`'); |
|
| 612 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
| 613 | + $fix_tables = array('`' . $match[1] . '`'); |
|
| 614 | + } |
|
| 573 | 615 | } |
| 574 | 616 | // Indexes crashed. Should be easy to fix! |
| 575 | 617 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -588,13 +630,15 @@ discard block |
||
| 588 | 630 | |
| 589 | 631 | // Make a note of the REPAIR... |
| 590 | 632 | cache_put_data('db_last_error', time(), 600); |
| 591 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
| 592 | - updateSettingsFile(array('db_last_error' => time())); |
|
| 633 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
| 634 | + updateSettingsFile(array('db_last_error' => time())); |
|
| 635 | + } |
|
| 593 | 636 | |
| 594 | 637 | // Attempt to find and repair the broken table. |
| 595 | - foreach ($fix_tables as $table) |
|
| 596 | - $smcFunc['db_query']('', " |
|
| 638 | + foreach ($fix_tables as $table) { |
|
| 639 | + $smcFunc['db_query']('', " |
|
| 597 | 640 | REPAIR TABLE $table", false, false); |
| 641 | + } |
|
| 598 | 642 | |
| 599 | 643 | // And send off an email! |
| 600 | 644 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -603,11 +647,12 @@ discard block |
||
| 603 | 647 | |
| 604 | 648 | // Try the query again...? |
| 605 | 649 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 606 | - if ($ret !== false) |
|
| 607 | - return $ret; |
|
| 650 | + if ($ret !== false) { |
|
| 651 | + return $ret; |
|
| 652 | + } |
|
| 653 | + } else { |
|
| 654 | + $modSettings['cache_enable'] = $old_cache; |
|
| 608 | 655 | } |
| 609 | - else |
|
| 610 | - $modSettings['cache_enable'] = $old_cache; |
|
| 611 | 656 | |
| 612 | 657 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
| 613 | 658 | if (in_array($query_errno, array(1205, 1213, 2006, 2013))) |
@@ -617,22 +662,25 @@ discard block |
||
| 617 | 662 | // Are we in SSI mode? If so try that username and password first |
| 618 | 663 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
| 619 | 664 | { |
| 620 | - if (empty($db_persist)) |
|
| 621 | - $db_connection = @mysql_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 622 | - else |
|
| 623 | - $db_connection = @mysql_pconnect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 665 | + if (empty($db_persist)) { |
|
| 666 | + $db_connection = @mysql_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 667 | + } else { |
|
| 668 | + $db_connection = @mysql_pconnect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 669 | + } |
|
| 624 | 670 | } |
| 625 | 671 | // Fall back to the regular username and password if need be |
| 626 | 672 | if (!$db_connection) |
| 627 | 673 | { |
| 628 | - if (empty($db_persist)) |
|
| 629 | - $db_connection = @mysql_connect($db_server, $db_user, $db_passwd); |
|
| 630 | - else |
|
| 631 | - $db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd); |
|
| 674 | + if (empty($db_persist)) { |
|
| 675 | + $db_connection = @mysql_connect($db_server, $db_user, $db_passwd); |
|
| 676 | + } else { |
|
| 677 | + $db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd); |
|
| 678 | + } |
|
| 632 | 679 | } |
| 633 | 680 | |
| 634 | - if (!$db_connection || !@mysql_select_db($db_name, $db_connection)) |
|
| 635 | - $db_connection = false; |
|
| 681 | + if (!$db_connection || !@mysql_select_db($db_name, $db_connection)) { |
|
| 682 | + $db_connection = false; |
|
| 683 | + } |
|
| 636 | 684 | } |
| 637 | 685 | |
| 638 | 686 | if ($db_connection) |
@@ -643,24 +691,27 @@ discard block |
||
| 643 | 691 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 644 | 692 | |
| 645 | 693 | $new_errno = mysql_errno($db_connection); |
| 646 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
| 647 | - break; |
|
| 694 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
| 695 | + break; |
|
| 696 | + } |
|
| 648 | 697 | } |
| 649 | 698 | |
| 650 | 699 | // If it failed again, shucks to be you... we're not trying it over and over. |
| 651 | - if ($ret !== false) |
|
| 652 | - return $ret; |
|
| 700 | + if ($ret !== false) { |
|
| 701 | + return $ret; |
|
| 702 | + } |
|
| 653 | 703 | } |
| 654 | 704 | } |
| 655 | 705 | // Are they out of space, perhaps? |
| 656 | 706 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
| 657 | 707 | { |
| 658 | - if (!isset($txt)) |
|
| 659 | - $query_error .= ' - check database storage space.'; |
|
| 660 | - else |
|
| 708 | + if (!isset($txt)) { |
|
| 709 | + $query_error .= ' - check database storage space.'; |
|
| 710 | + } else |
|
| 661 | 711 | { |
| 662 | - if (!isset($txt['mysql_error_space'])) |
|
| 663 | - loadLanguage('Errors'); |
|
| 712 | + if (!isset($txt['mysql_error_space'])) { |
|
| 713 | + loadLanguage('Errors'); |
|
| 714 | + } |
|
| 664 | 715 | |
| 665 | 716 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
| 666 | 717 | } |
@@ -668,15 +719,17 @@ discard block |
||
| 668 | 719 | } |
| 669 | 720 | |
| 670 | 721 | // Nothing's defined yet... just die with it. |
| 671 | - if (empty($context) || empty($txt)) |
|
| 672 | - die($query_error); |
|
| 722 | + if (empty($context) || empty($txt)) { |
|
| 723 | + die($query_error); |
|
| 724 | + } |
|
| 673 | 725 | |
| 674 | 726 | // Show an error message, if possible. |
| 675 | 727 | $context['error_title'] = $txt['database_error']; |
| 676 | - if (allowedTo('admin_forum')) |
|
| 677 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 678 | - else |
|
| 679 | - $context['error_message'] = $txt['try_again']; |
|
| 728 | + if (allowedTo('admin_forum')) { |
|
| 729 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 730 | + } else { |
|
| 731 | + $context['error_message'] = $txt['try_again']; |
|
| 732 | + } |
|
| 680 | 733 | |
| 681 | 734 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 682 | 735 | { |
@@ -705,25 +758,28 @@ discard block |
||
| 705 | 758 | $connection = $connection === null ? $db_connection : $connection; |
| 706 | 759 | |
| 707 | 760 | // With nothing to insert, simply return. |
| 708 | - if (empty($data)) |
|
| 709 | - return; |
|
| 761 | + if (empty($data)) { |
|
| 762 | + return; |
|
| 763 | + } |
|
| 710 | 764 | |
| 711 | 765 | // Replace the prefix holder with the actual prefix. |
| 712 | 766 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
| 713 | 767 | |
| 714 | 768 | // Inserting data as a single row can be done as a single array. |
| 715 | - if (!is_array($data[array_rand($data)])) |
|
| 716 | - $data = array($data); |
|
| 769 | + if (!is_array($data[array_rand($data)])) { |
|
| 770 | + $data = array($data); |
|
| 771 | + } |
|
| 717 | 772 | |
| 718 | 773 | // Create the mold for a single row insert. |
| 719 | 774 | $insertData = '('; |
| 720 | 775 | foreach ($columns as $columnName => $type) |
| 721 | 776 | { |
| 722 | 777 | // Are we restricting the length? |
| 723 | - if (strpos($type, 'string-') !== false) |
|
| 724 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 725 | - else |
|
| 726 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 778 | + if (strpos($type, 'string-') !== false) { |
|
| 779 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 780 | + } else { |
|
| 781 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 782 | + } |
|
| 727 | 783 | } |
| 728 | 784 | $insertData = substr($insertData, 0, -2) . ')'; |
| 729 | 785 | |
@@ -732,8 +788,9 @@ discard block |
||
| 732 | 788 | |
| 733 | 789 | // Here's where the variables are injected to the query. |
| 734 | 790 | $insertRows = array(); |
| 735 | - foreach ($data as $dataRow) |
|
| 736 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 791 | + foreach ($data as $dataRow) { |
|
| 792 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 793 | + } |
|
| 737 | 794 | |
| 738 | 795 | // Determine the method of insertion. |
| 739 | 796 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
@@ -764,8 +821,9 @@ discard block |
||
| 764 | 821 | */ |
| 765 | 822 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 766 | 823 | { |
| 767 | - if (empty($log_message)) |
|
| 768 | - $log_message = $error_message; |
|
| 824 | + if (empty($log_message)) { |
|
| 825 | + $log_message = $error_message; |
|
| 826 | + } |
|
| 769 | 827 | |
| 770 | 828 | foreach (debug_backtrace() as $step) |
| 771 | 829 | { |
@@ -784,12 +842,14 @@ discard block |
||
| 784 | 842 | } |
| 785 | 843 | |
| 786 | 844 | // A special case - we want the file and line numbers for debugging. |
| 787 | - if ($error_type == 'return') |
|
| 788 | - return array($file, $line); |
|
| 845 | + if ($error_type == 'return') { |
|
| 846 | + return array($file, $line); |
|
| 847 | + } |
|
| 789 | 848 | |
| 790 | 849 | // Is always a critical error. |
| 791 | - if (function_exists('log_error')) |
|
| 792 | - log_error($log_message, 'critical', $file, $line); |
|
| 850 | + if (function_exists('log_error')) { |
|
| 851 | + log_error($log_message, 'critical', $file, $line); |
|
| 852 | + } |
|
| 793 | 853 | |
| 794 | 854 | if (function_exists('fatal_error')) |
| 795 | 855 | { |
@@ -797,12 +857,12 @@ discard block |
||
| 797 | 857 | |
| 798 | 858 | // Cannot continue... |
| 799 | 859 | exit; |
| 860 | + } elseif ($error_type) { |
|
| 861 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 862 | + } else { |
|
| 863 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 864 | + } |
|
| 800 | 865 | } |
| 801 | - elseif ($error_type) |
|
| 802 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 803 | - else |
|
| 804 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 805 | -} |
|
| 806 | 866 | |
| 807 | 867 | /** |
| 808 | 868 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -819,10 +879,11 @@ discard block |
||
| 819 | 879 | '\\' => '\\\\', |
| 820 | 880 | ); |
| 821 | 881 | |
| 822 | - if ($translate_human_wildcards) |
|
| 823 | - $replacements += array( |
|
| 882 | + if ($translate_human_wildcards) { |
|
| 883 | + $replacements += array( |
|
| 824 | 884 | '*' => '%', |
| 825 | 885 | ); |
| 886 | + } |
|
| 826 | 887 | |
| 827 | 888 | return strtr($string, $replacements); |
| 828 | 889 | } |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 3 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('No direct access...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Class fulltext_search |
@@ -98,8 +99,9 @@ discard block |
||
| 98 | 99 | $smcFunc['db_free_result']($request); |
| 99 | 100 | } |
| 100 | 101 | // 4 is the MySQL default... |
| 101 | - else |
|
| 102 | - $min_word_length = 4; |
|
| 102 | + else { |
|
| 103 | + $min_word_length = 4; |
|
| 104 | + } |
|
| 103 | 105 | |
| 104 | 106 | return $min_word_length; |
| 105 | 107 | } |
@@ -138,8 +140,7 @@ discard block |
||
| 138 | 140 | $wordsSearch['words'][] = trim($word, "/*- "); |
| 139 | 141 | $wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"'; |
| 140 | 142 | } |
| 141 | - } |
|
| 142 | - elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
| 143 | + } elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
| 143 | 144 | { |
| 144 | 145 | // short words have feelings too |
| 145 | 146 | $wordsSearch['words'][] = trim($word, "/*- "); |
@@ -149,8 +150,9 @@ discard block |
||
| 149 | 150 | |
| 150 | 151 | $fulltextWord = count($subwords) === 1 ? $word : '"' . $word . '"'; |
| 151 | 152 | $wordsSearch['indexed_words'][] = $fulltextWord; |
| 152 | - if ($isExcluded) |
|
| 153 | - $wordsExclude[] = $fulltextWord; |
|
| 153 | + if ($isExcluded) { |
|
| 154 | + $wordsExclude[] = $fulltextWord; |
|
| 155 | + } |
|
| 154 | 156 | } |
| 155 | 157 | |
| 156 | 158 | /** |
@@ -166,41 +168,50 @@ discard block |
||
| 166 | 168 | $query_where = array(); |
| 167 | 169 | $query_params = $search_data['params']; |
| 168 | 170 | |
| 169 | - if ($query_params['id_search']) |
|
| 170 | - $query_select['id_search'] = '{int:id_search}'; |
|
| 171 | + if ($query_params['id_search']) { |
|
| 172 | + $query_select['id_search'] = '{int:id_search}'; |
|
| 173 | + } |
|
| 171 | 174 | |
| 172 | 175 | $count = 0; |
| 173 | - if (empty($modSettings['search_simple_fulltext'])) |
|
| 174 | - foreach ($words['words'] as $regularWord) |
|
| 176 | + if (empty($modSettings['search_simple_fulltext'])) { |
|
| 177 | + foreach ($words['words'] as $regularWord) |
|
| 175 | 178 | { |
| 176 | 179 | $query_where[] = 'm.body' . (in_array($regularWord, $query_params['excluded_words']) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:complex_body_' . $count . '}'; |
| 180 | + } |
|
| 177 | 181 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
| 178 | 182 | } |
| 179 | 183 | |
| 180 | - if ($query_params['user_query']) |
|
| 181 | - $query_where[] = '{raw:user_query}'; |
|
| 182 | - if ($query_params['board_query']) |
|
| 183 | - $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 184 | + if ($query_params['user_query']) { |
|
| 185 | + $query_where[] = '{raw:user_query}'; |
|
| 186 | + } |
|
| 187 | + if ($query_params['board_query']) { |
|
| 188 | + $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 189 | + } |
|
| 184 | 190 | |
| 185 | - if ($query_params['topic']) |
|
| 186 | - $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 187 | - if ($query_params['min_msg_id']) |
|
| 188 | - $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 189 | - if ($query_params['max_msg_id']) |
|
| 190 | - $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 191 | + if ($query_params['topic']) { |
|
| 192 | + $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 193 | + } |
|
| 194 | + if ($query_params['min_msg_id']) { |
|
| 195 | + $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 196 | + } |
|
| 197 | + if ($query_params['max_msg_id']) { |
|
| 198 | + $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 199 | + } |
|
| 191 | 200 | |
| 192 | 201 | $count = 0; |
| 193 | - if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
|
| 194 | - foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 202 | + if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) { |
|
| 203 | + foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 195 | 204 | { |
| 196 | 205 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_phrase_' . $count . '}'; |
| 206 | + } |
|
| 197 | 207 | $query_params['exclude_subject_phrase_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($phrase, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $phrase), '\\\'') . '[[:>:]]'; |
| 198 | 208 | } |
| 199 | 209 | $count = 0; |
| 200 | - if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
|
| 201 | - foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 210 | + if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) { |
|
| 211 | + foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 202 | 212 | { |
| 203 | 213 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_words_' . $count . '}'; |
| 214 | + } |
|
| 204 | 215 | $query_params['exclude_subject_words_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($excludedWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $excludedWord), '\\\'') . '[[:>:]]'; |
| 205 | 216 | } |
| 206 | 217 | |
@@ -223,12 +234,11 @@ discard block |
||
| 223 | 234 | } |
| 224 | 235 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:body_match})'; |
| 225 | 236 | $query_params['language_ftx'] = $language_ftx; |
| 237 | + } else { |
|
| 238 | + $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
| 226 | 239 | } |
| 227 | - else |
|
| 228 | - $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
| 229 | 240 | $query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words'])); |
| 230 | - } |
|
| 231 | - else |
|
| 241 | + } else |
|
| 232 | 242 | { |
| 233 | 243 | $query_params['boolean_match'] = ''; |
| 234 | 244 | |
@@ -242,10 +252,10 @@ discard block |
||
| 242 | 252 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' '; |
| 243 | 253 | $row++; |
| 244 | 254 | } |
| 245 | - } |
|
| 246 | - else |
|
| 247 | - foreach ($words['indexed_words'] as $fulltextWord) |
|
| 255 | + } else { |
|
| 256 | + foreach ($words['indexed_words'] as $fulltextWord) |
|
| 248 | 257 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' '; |
| 258 | + } |
|
| 249 | 259 | |
| 250 | 260 | $query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1); |
| 251 | 261 | |
@@ -268,9 +278,9 @@ discard block |
||
| 268 | 278 | } |
| 269 | 279 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:boolean_match})'; |
| 270 | 280 | $query_params['language_ftx'] = $language_ftx; |
| 281 | + } else { |
|
| 282 | + $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
| 271 | 283 | } |
| 272 | - else |
|
| 273 | - $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
| 274 | 284 | } |
| 275 | 285 | |
| 276 | 286 | } |
@@ -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 | * Entry point for this section. |
@@ -38,8 +39,7 @@ discard block |
||
| 38 | 39 | 'stats' => 'SpiderStats', |
| 39 | 40 | ); |
| 40 | 41 | $default = 'stats'; |
| 41 | - } |
|
| 42 | - else |
|
| 42 | + } else |
|
| 43 | 43 | { |
| 44 | 44 | $subActions = array( |
| 45 | 45 | 'settings' => 'ManageSearchEngineSettings', |
@@ -90,11 +90,12 @@ discard block |
||
| 90 | 90 | { |
| 91 | 91 | disabledState = document.getElementById(\'spider_mode\').value == 0;'; |
| 92 | 92 | |
| 93 | - foreach ($config_vars as $variable) |
|
| 94 | - if ($variable[1] != 'spider_mode') |
|
| 93 | + foreach ($config_vars as $variable) { |
|
| 94 | + if ($variable[1] != 'spider_mode') |
|
| 95 | 95 | $javascript_function .= ' |
| 96 | 96 | if (document.getElementById(\'' . $variable[1] . '\')) |
| 97 | 97 | document.getElementById(\'' . $variable[1] . '\').disabled = disabledState;'; |
| 98 | + } |
|
| 98 | 99 | |
| 99 | 100 | $javascript_function .= ' |
| 100 | 101 | } |
@@ -102,8 +103,9 @@ discard block |
||
| 102 | 103 | |
| 103 | 104 | call_integration_hook('integrate_modify_search_engine_settings', array(&$config_vars)); |
| 104 | 105 | |
| 105 | - if ($return_config) |
|
| 106 | - return $config_vars; |
|
| 106 | + if ($return_config) { |
|
| 107 | + return $config_vars; |
|
| 108 | + } |
|
| 107 | 109 | |
| 108 | 110 | // We need to load the groups for the spider group thingy. |
| 109 | 111 | $request = $smcFunc['db_query']('', ' |
@@ -116,13 +118,15 @@ discard block |
||
| 116 | 118 | 'moderator_group' => 3, |
| 117 | 119 | ) |
| 118 | 120 | ); |
| 119 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 120 | - $config_vars['spider_group'][2][$row['id_group']] = $row['group_name']; |
|
| 121 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 122 | + $config_vars['spider_group'][2][$row['id_group']] = $row['group_name']; |
|
| 123 | + } |
|
| 121 | 124 | $smcFunc['db_free_result']($request); |
| 122 | 125 | |
| 123 | 126 | // Make sure it's valid - note that regular members are given id_group = 1 which is reversed in Load.php - no admins here! |
| 124 | - if (isset($_POST['spider_group']) && !isset($config_vars['spider_group'][2][$_POST['spider_group']])) |
|
| 125 | - $_POST['spider_group'] = 0; |
|
| 127 | + if (isset($_POST['spider_group']) && !isset($config_vars['spider_group'][2][$_POST['spider_group']])) { |
|
| 128 | + $_POST['spider_group'] = 0; |
|
| 129 | + } |
|
| 126 | 130 | |
| 127 | 131 | // We'll want this for our easy save. |
| 128 | 132 | require_once($sourcedir . '/ManageServer.php'); |
@@ -166,8 +170,9 @@ discard block |
||
| 166 | 170 | } |
| 167 | 171 | |
| 168 | 172 | // Are we adding a new one? |
| 169 | - if (!empty($_POST['addSpider'])) |
|
| 170 | - return EditSpider(); |
|
| 173 | + if (!empty($_POST['addSpider'])) { |
|
| 174 | + return EditSpider(); |
|
| 175 | + } |
|
| 171 | 176 | // User pressed the 'remove selection button'. |
| 172 | 177 | elseif (!empty($_POST['removeSpiders']) && !empty($_POST['remove']) && is_array($_POST['remove'])) |
| 173 | 178 | { |
@@ -175,8 +180,9 @@ discard block |
||
| 175 | 180 | validateToken('admin-ser'); |
| 176 | 181 | |
| 177 | 182 | // Make sure every entry is a proper integer. |
| 178 | - foreach ($_POST['remove'] as $index => $spider_id) |
|
| 179 | - $_POST['remove'][(int) $index] = (int) $spider_id; |
|
| 183 | + foreach ($_POST['remove'] as $index => $spider_id) { |
|
| 184 | + $_POST['remove'][(int) $index] = (int) $spider_id; |
|
| 185 | + } |
|
| 180 | 186 | |
| 181 | 187 | // Delete them all! |
| 182 | 188 | $smcFunc['db_query']('', ' |
@@ -215,8 +221,9 @@ discard block |
||
| 215 | 221 | ); |
| 216 | 222 | |
| 217 | 223 | $context['spider_last_seen'] = array(); |
| 218 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 219 | - $context['spider_last_seen'][$row['id_spider']] = $row['last_seen_time']; |
|
| 224 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 225 | + $context['spider_last_seen'][$row['id_spider']] = $row['last_seen_time']; |
|
| 226 | + } |
|
| 220 | 227 | $smcFunc['db_free_result']($request); |
| 221 | 228 | |
| 222 | 229 | createToken('admin-ser'); |
@@ -346,8 +353,9 @@ discard block |
||
| 346 | 353 | ) |
| 347 | 354 | ); |
| 348 | 355 | $spiders = array(); |
| 349 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 350 | - $spiders[$row['id_spider']] = $row; |
|
| 356 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 357 | + $spiders[$row['id_spider']] = $row; |
|
| 358 | + } |
|
| 351 | 359 | $smcFunc['db_free_result']($request); |
| 352 | 360 | |
| 353 | 361 | return $spiders; |
@@ -397,14 +405,15 @@ discard block |
||
| 397 | 405 | foreach ($ip_sets as $set) |
| 398 | 406 | { |
| 399 | 407 | $test = ip2range(trim($set)); |
| 400 | - if (!empty($test)) |
|
| 401 | - $ips[] = $set; |
|
| 408 | + if (!empty($test)) { |
|
| 409 | + $ips[] = $set; |
|
| 410 | + } |
|
| 402 | 411 | } |
| 403 | 412 | $ips = implode(',', $ips); |
| 404 | 413 | |
| 405 | 414 | // Goes in as it is... |
| 406 | - if ($context['id_spider']) |
|
| 407 | - $smcFunc['db_query']('', ' |
|
| 415 | + if ($context['id_spider']) { |
|
| 416 | + $smcFunc['db_query']('', ' |
|
| 408 | 417 | UPDATE {db_prefix}spiders |
| 409 | 418 | SET spider_name = {string:spider_name}, user_agent = {string:spider_agent}, |
| 410 | 419 | ip_info = {string:ip_info} |
@@ -416,8 +425,8 @@ discard block |
||
| 416 | 425 | 'ip_info' => $ips, |
| 417 | 426 | ) |
| 418 | 427 | ); |
| 419 | - else |
|
| 420 | - $smcFunc['db_insert']('insert', |
|
| 428 | + } else { |
|
| 429 | + $smcFunc['db_insert']('insert', |
|
| 421 | 430 | '{db_prefix}spiders', |
| 422 | 431 | array( |
| 423 | 432 | 'spider_name' => 'string', 'user_agent' => 'string', 'ip_info' => 'string', |
@@ -427,6 +436,7 @@ discard block |
||
| 427 | 436 | ), |
| 428 | 437 | array('id_spider') |
| 429 | 438 | ); |
| 439 | + } |
|
| 430 | 440 | |
| 431 | 441 | |
| 432 | 442 | cache_put_data('spider_search', null); |
@@ -454,13 +464,14 @@ discard block |
||
| 454 | 464 | 'current_spider' => $context['id_spider'], |
| 455 | 465 | ) |
| 456 | 466 | ); |
| 457 | - if ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 458 | - $context['spider'] = array( |
|
| 467 | + if ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 468 | + $context['spider'] = array( |
|
| 459 | 469 | 'id' => $row['id_spider'], |
| 460 | 470 | 'name' => $row['spider_name'], |
| 461 | 471 | 'agent' => $row['user_agent'], |
| 462 | 472 | 'ip_info' => $row['ip_info'], |
| 463 | 473 | ); |
| 474 | + } |
|
| 464 | 475 | $smcFunc['db_free_result']($request); |
| 465 | 476 | } |
| 466 | 477 | |
@@ -477,8 +488,9 @@ discard block |
||
| 477 | 488 | { |
| 478 | 489 | global $modSettings, $smcFunc; |
| 479 | 490 | |
| 480 | - if (isset($_SESSION['id_robot'])) |
|
| 481 | - unset($_SESSION['id_robot']); |
|
| 491 | + if (isset($_SESSION['id_robot'])) { |
|
| 492 | + unset($_SESSION['id_robot']); |
|
| 493 | + } |
|
| 482 | 494 | $_SESSION['robot_check'] = time(); |
| 483 | 495 | |
| 484 | 496 | // We cache the spider data for ten minutes if we can. |
@@ -492,15 +504,17 @@ discard block |
||
| 492 | 504 | ) |
| 493 | 505 | ); |
| 494 | 506 | $spider_data = array(); |
| 495 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 496 | - $spider_data[] = $row; |
|
| 507 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 508 | + $spider_data[] = $row; |
|
| 509 | + } |
|
| 497 | 510 | $smcFunc['db_free_result']($request); |
| 498 | 511 | |
| 499 | 512 | cache_put_data('spider_search', $spider_data, 600); |
| 500 | 513 | } |
| 501 | 514 | |
| 502 | - if (empty($spider_data)) |
|
| 503 | - return false; |
|
| 515 | + if (empty($spider_data)) { |
|
| 516 | + return false; |
|
| 517 | + } |
|
| 504 | 518 | |
| 505 | 519 | // Only do these bits once. |
| 506 | 520 | $ci_user_agent = strtolower($_SERVER['HTTP_USER_AGENT']); |
@@ -508,33 +522,38 @@ discard block |
||
| 508 | 522 | foreach ($spider_data as $spider) |
| 509 | 523 | { |
| 510 | 524 | // User agent is easy. |
| 511 | - if (!empty($spider['user_agent']) && strpos($ci_user_agent, strtolower($spider['user_agent'])) !== false) |
|
| 512 | - $_SESSION['id_robot'] = $spider['id_spider']; |
|
| 525 | + if (!empty($spider['user_agent']) && strpos($ci_user_agent, strtolower($spider['user_agent'])) !== false) { |
|
| 526 | + $_SESSION['id_robot'] = $spider['id_spider']; |
|
| 527 | + } |
|
| 513 | 528 | // IP stuff is harder. |
| 514 | 529 | elseif ($_SERVER['REMOTE_ADDR']) |
| 515 | 530 | { |
| 516 | 531 | $ips = explode(',', $spider['ip_info']); |
| 517 | 532 | foreach ($ips as $ip) |
| 518 | 533 | { |
| 519 | - if ($ip === '') |
|
| 520 | - continue; |
|
| 534 | + if ($ip === '') { |
|
| 535 | + continue; |
|
| 536 | + } |
|
| 521 | 537 | |
| 522 | 538 | $ip = ip2range($ip); |
| 523 | 539 | if (!empty($ip)) |
| 524 | 540 | { |
| 525 | - if (inet_ptod($ip['low']) <= inet_ptod($_SERVER['REMOTE_ADDR']) && inet_ptod($ip['high']) >= inet_ptod($_SERVER['REMOTE_ADDR'])) |
|
| 526 | - $_SESSION['id_robot'] = $spider['id_spider']; |
|
| 541 | + if (inet_ptod($ip['low']) <= inet_ptod($_SERVER['REMOTE_ADDR']) && inet_ptod($ip['high']) >= inet_ptod($_SERVER['REMOTE_ADDR'])) { |
|
| 542 | + $_SESSION['id_robot'] = $spider['id_spider']; |
|
| 543 | + } |
|
| 527 | 544 | } |
| 528 | 545 | } |
| 529 | 546 | } |
| 530 | 547 | |
| 531 | - if (isset($_SESSION['id_robot'])) |
|
| 532 | - break; |
|
| 548 | + if (isset($_SESSION['id_robot'])) { |
|
| 549 | + break; |
|
| 550 | + } |
|
| 533 | 551 | } |
| 534 | 552 | |
| 535 | 553 | // If this is low server tracking then log the spider here as opposed to the main logging function. |
| 536 | - if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] == 1 && !empty($_SESSION['id_robot'])) |
|
| 537 | - logSpider(); |
|
| 554 | + if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] == 1 && !empty($_SESSION['id_robot'])) { |
|
| 555 | + logSpider(); |
|
| 556 | + } |
|
| 538 | 557 | |
| 539 | 558 | return !empty($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
| 540 | 559 | } |
@@ -548,8 +567,9 @@ discard block |
||
| 548 | 567 | { |
| 549 | 568 | global $smcFunc, $modSettings, $context; |
| 550 | 569 | |
| 551 | - if (empty($modSettings['spider_mode']) || empty($_SESSION['id_robot'])) |
|
| 552 | - return; |
|
| 570 | + if (empty($modSettings['spider_mode']) || empty($_SESSION['id_robot'])) { |
|
| 571 | + return; |
|
| 572 | + } |
|
| 553 | 573 | |
| 554 | 574 | // Attempt to update today's entry. |
| 555 | 575 | if ($modSettings['spider_mode'] == 1) |
@@ -590,9 +610,9 @@ discard block |
||
| 590 | 610 | $url = $_GET + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']); |
| 591 | 611 | unset($url['sesc'], $url[$context['session_var']]); |
| 592 | 612 | $url = json_encode($url); |
| 613 | + } else { |
|
| 614 | + $url = ''; |
|
| 593 | 615 | } |
| 594 | - else |
|
| 595 | - $url = ''; |
|
| 596 | 616 | |
| 597 | 617 | $smcFunc['db_insert']('insert', |
| 598 | 618 | '{db_prefix}log_spider_hits', |
@@ -620,12 +640,14 @@ discard block |
||
| 620 | 640 | ) |
| 621 | 641 | ); |
| 622 | 642 | $spider_hits = array(); |
| 623 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 624 | - $spider_hits[] = $row; |
|
| 643 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 644 | + $spider_hits[] = $row; |
|
| 645 | + } |
|
| 625 | 646 | $smcFunc['db_free_result']($request); |
| 626 | 647 | |
| 627 | - if (empty($spider_hits)) |
|
| 628 | - return; |
|
| 648 | + if (empty($spider_hits)) { |
|
| 649 | + return; |
|
| 650 | + } |
|
| 629 | 651 | |
| 630 | 652 | // Attempt to update the master data. |
| 631 | 653 | $stat_inserts = array(); |
@@ -646,18 +668,20 @@ discard block |
||
| 646 | 668 | 'hits' => $stat['num_hits'], |
| 647 | 669 | ) |
| 648 | 670 | ); |
| 649 | - if ($smcFunc['db_affected_rows']() == 0) |
|
| 650 | - $stat_inserts[] = array($date, $stat['id_spider'], $stat['num_hits'], $stat['last_seen']); |
|
| 671 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
| 672 | + $stat_inserts[] = array($date, $stat['id_spider'], $stat['num_hits'], $stat['last_seen']); |
|
| 673 | + } |
|
| 651 | 674 | } |
| 652 | 675 | |
| 653 | 676 | // New stats? |
| 654 | - if (!empty($stat_inserts)) |
|
| 655 | - $smcFunc['db_insert']('ignore', |
|
| 677 | + if (!empty($stat_inserts)) { |
|
| 678 | + $smcFunc['db_insert']('ignore', |
|
| 656 | 679 | '{db_prefix}log_spider_stats', |
| 657 | 680 | array('stat_date' => 'date', 'id_spider' => 'int', 'page_hits' => 'int', 'last_seen' => 'int'), |
| 658 | 681 | $stat_inserts, |
| 659 | 682 | array('stat_date', 'id_spider') |
| 660 | 683 | ); |
| 684 | + } |
|
| 661 | 685 | |
| 662 | 686 | // All processed. |
| 663 | 687 | $smcFunc['db_query']('', ' |
@@ -700,8 +724,7 @@ discard block |
||
| 700 | 724 | 'delete_period' => $deleteTime, |
| 701 | 725 | ) |
| 702 | 726 | ); |
| 703 | - } |
|
| 704 | - else |
|
| 727 | + } else |
|
| 705 | 728 | { |
| 706 | 729 | // Deleting all of them |
| 707 | 730 | $smcFunc['db_query']('', ' |
@@ -791,10 +814,11 @@ discard block |
||
| 791 | 814 | foreach ($context['spider_logs']['rows'] as $k => $row) |
| 792 | 815 | { |
| 793 | 816 | // Feature disabled? |
| 794 | - if (empty($row['data']['viewing']['value']) && isset($modSettings['spider_mode']) && $modSettings['spider_mode'] < 3) |
|
| 795 | - $context['spider_logs']['rows'][$k]['viewing']['value'] = '<em>' . $txt['spider_disabled'] . '</em>'; |
|
| 796 | - else |
|
| 797 | - $urls[$k] = array($row['data']['viewing']['value'], -1); |
|
| 817 | + if (empty($row['data']['viewing']['value']) && isset($modSettings['spider_mode']) && $modSettings['spider_mode'] < 3) { |
|
| 818 | + $context['spider_logs']['rows'][$k]['viewing']['value'] = '<em>' . $txt['spider_disabled'] . '</em>'; |
|
| 819 | + } else { |
|
| 820 | + $urls[$k] = array($row['data']['viewing']['value'], -1); |
|
| 821 | + } |
|
| 798 | 822 | } |
| 799 | 823 | |
| 800 | 824 | // Now stick in the new URLs. |
@@ -836,8 +860,9 @@ discard block |
||
| 836 | 860 | ) |
| 837 | 861 | ); |
| 838 | 862 | $spider_logs = array(); |
| 839 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 840 | - $spider_logs[] = $row; |
|
| 863 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 864 | + $spider_logs[] = $row; |
|
| 865 | + } |
|
| 841 | 866 | $smcFunc['db_free_result']($request); |
| 842 | 867 | |
| 843 | 868 | return $spider_logs; |
@@ -913,14 +938,18 @@ discard block |
||
| 913 | 938 | |
| 914 | 939 | // Prepare the dates for the drop down. |
| 915 | 940 | $date_choices = array(); |
| 916 | - for ($y = $min_year; $y <= $max_year; $y++) |
|
| 917 | - for ($m = 1; $m <= 12; $m++) |
|
| 941 | + for ($y = $min_year; $y <= $max_year; $y++) { |
|
| 942 | + for ($m = 1; |
|
| 943 | + } |
|
| 944 | + $m <= 12; $m++) |
|
| 918 | 945 | { |
| 919 | 946 | // This doesn't count? |
| 920 | - if ($y == $min_year && $m < $min_month) |
|
| 921 | - continue; |
|
| 922 | - if ($y == $max_year && $m > $max_month) |
|
| 923 | - break; |
|
| 947 | + if ($y == $min_year && $m < $min_month) { |
|
| 948 | + continue; |
|
| 949 | + } |
|
| 950 | + if ($y == $max_year && $m > $max_month) { |
|
| 951 | + break; |
|
| 952 | + } |
|
| 924 | 953 | |
| 925 | 954 | $date_choices[$y . $m] = $txt['months_short'][$m] . ' ' . $y; |
| 926 | 955 | } |
@@ -933,13 +962,14 @@ discard block |
||
| 933 | 962 | ' . $txt['spider_stats_select_month'] . ': |
| 934 | 963 | <select name="new_date" onchange="document.spider_stat_list.submit();">'; |
| 935 | 964 | |
| 936 | - if (empty($date_choices)) |
|
| 937 | - $date_select .= ' |
|
| 965 | + if (empty($date_choices)) { |
|
| 966 | + $date_select .= ' |
|
| 938 | 967 | <option></option>'; |
| 939 | - else |
|
| 940 | - foreach ($date_choices as $id => $text) |
|
| 968 | + } else { |
|
| 969 | + foreach ($date_choices as $id => $text) |
|
| 941 | 970 | $date_select .= ' |
| 942 | 971 | <option value="' . $id . '"' . ($current_date == $id ? ' selected' : '') . '>' . $text . '</option>'; |
| 972 | + } |
|
| 943 | 973 | |
| 944 | 974 | $date_select .= ' |
| 945 | 975 | </select> |
@@ -1063,8 +1093,9 @@ discard block |
||
| 1063 | 1093 | ) |
| 1064 | 1094 | ); |
| 1065 | 1095 | $spider_stats = array(); |
| 1066 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1067 | - $spider_stats[] = $row; |
|
| 1096 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1097 | + $spider_stats[] = $row; |
|
| 1098 | + } |
|
| 1068 | 1099 | $smcFunc['db_free_result']($request); |
| 1069 | 1100 | |
| 1070 | 1101 | return $spider_stats; |
@@ -1105,8 +1136,9 @@ discard block |
||
| 1105 | 1136 | array() |
| 1106 | 1137 | ); |
| 1107 | 1138 | $spiders = array(); |
| 1108 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1109 | - $spiders[$row['id_spider']] = $row['spider_name']; |
|
| 1139 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1140 | + $spiders[$row['id_spider']] = $row['spider_name']; |
|
| 1141 | + } |
|
| 1110 | 1142 | $smcFunc['db_free_result']($request); |
| 1111 | 1143 | |
| 1112 | 1144 | updateSettings(array('spider_name_cache' => json_encode($spiders))); |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 3 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Check if the user is who he/she says he is |
@@ -42,12 +43,14 @@ discard block |
||
| 42 | 43 | $refreshTime = isset($_GET['xml']) ? 4200 : 3600; |
| 43 | 44 | |
| 44 | 45 | // Is the security option off? |
| 45 | - if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) |
|
| 46 | - return; |
|
| 46 | + if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 47 | 49 | |
| 48 | 50 | // Or are they already logged in?, Moderator or admin session is need for this area |
| 49 | - if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) |
|
| 50 | - return; |
|
| 51 | + if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) { |
|
| 52 | + return; |
|
| 53 | + } |
|
| 51 | 54 | |
| 52 | 55 | require_once($sourcedir . '/Subs-Auth.php'); |
| 53 | 56 | |
@@ -55,8 +58,9 @@ discard block |
||
| 55 | 58 | if (isset($_POST[$type. '_pass'])) |
| 56 | 59 | { |
| 57 | 60 | // Check to ensure we're forcing SSL for authentication |
| 58 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
| 59 | - fatal_lang_error('login_ssl_required'); |
|
| 61 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
| 62 | + fatal_lang_error('login_ssl_required'); |
|
| 63 | + } |
|
| 60 | 64 | |
| 61 | 65 | checkSession(); |
| 62 | 66 | |
@@ -72,17 +76,19 @@ discard block |
||
| 72 | 76 | } |
| 73 | 77 | |
| 74 | 78 | // Better be sure to remember the real referer |
| 75 | - if (empty($_SESSION['request_referer'])) |
|
| 76 | - $_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
| 77 | - elseif (empty($_POST)) |
|
| 78 | - unset($_SESSION['request_referer']); |
|
| 79 | + if (empty($_SESSION['request_referer'])) { |
|
| 80 | + $_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
| 81 | + } elseif (empty($_POST)) { |
|
| 82 | + unset($_SESSION['request_referer']); |
|
| 83 | + } |
|
| 79 | 84 | |
| 80 | 85 | // Need to type in a password for that, man. |
| 81 | - if (!isset($_GET['xml'])) |
|
| 82 | - adminLogin($type); |
|
| 83 | - else |
|
| 84 | - return 'session_verify_fail'; |
|
| 85 | -} |
|
| 86 | + if (!isset($_GET['xml'])) { |
|
| 87 | + adminLogin($type); |
|
| 88 | + } else { |
|
| 89 | + return 'session_verify_fail'; |
|
| 90 | + } |
|
| 91 | + } |
|
| 86 | 92 | |
| 87 | 93 | /** |
| 88 | 94 | * Require a user who is logged in. (not a guest.) |
@@ -96,25 +102,30 @@ discard block |
||
| 96 | 102 | global $user_info, $txt, $context, $scripturl, $modSettings; |
| 97 | 103 | |
| 98 | 104 | // Luckily, this person isn't a guest. |
| 99 | - if (!$user_info['is_guest']) |
|
| 100 | - return; |
|
| 105 | + if (!$user_info['is_guest']) { |
|
| 106 | + return; |
|
| 107 | + } |
|
| 101 | 108 | |
| 102 | 109 | // Log what they were trying to do didn't work) |
| 103 | - if (!empty($modSettings['who_enabled'])) |
|
| 104 | - $_GET['error'] = 'guest_login'; |
|
| 110 | + if (!empty($modSettings['who_enabled'])) { |
|
| 111 | + $_GET['error'] = 'guest_login'; |
|
| 112 | + } |
|
| 105 | 113 | writeLog(true); |
| 106 | 114 | |
| 107 | 115 | // Just die. |
| 108 | - if (isset($_REQUEST['xml'])) |
|
| 109 | - obExit(false); |
|
| 116 | + if (isset($_REQUEST['xml'])) { |
|
| 117 | + obExit(false); |
|
| 118 | + } |
|
| 110 | 119 | |
| 111 | 120 | // Attempt to detect if they came from dlattach. |
| 112 | - if (SMF != 'SSI' && empty($context['theme_loaded'])) |
|
| 113 | - loadTheme(); |
|
| 121 | + if (SMF != 'SSI' && empty($context['theme_loaded'])) { |
|
| 122 | + loadTheme(); |
|
| 123 | + } |
|
| 114 | 124 | |
| 115 | 125 | // Never redirect to an attachment |
| 116 | - if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) |
|
| 117 | - $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
| 126 | + if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) { |
|
| 127 | + $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
| 128 | + } |
|
| 118 | 129 | |
| 119 | 130 | // Load the Login template and language file. |
| 120 | 131 | loadLanguage('Login'); |
@@ -124,8 +135,7 @@ discard block |
||
| 124 | 135 | { |
| 125 | 136 | $_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING']; |
| 126 | 137 | redirectexit('action=login'); |
| 127 | - } |
|
| 128 | - else |
|
| 138 | + } else |
|
| 129 | 139 | { |
| 130 | 140 | loadTemplate('Login'); |
| 131 | 141 | $context['sub_template'] = 'kick_guest'; |
@@ -155,8 +165,9 @@ discard block |
||
| 155 | 165 | global $sourcedir, $cookiename, $user_settings, $smcFunc; |
| 156 | 166 | |
| 157 | 167 | // You cannot be banned if you are an admin - doesn't help if you log out. |
| 158 | - if ($user_info['is_admin']) |
|
| 159 | - return; |
|
| 168 | + if ($user_info['is_admin']) { |
|
| 169 | + return; |
|
| 170 | + } |
|
| 160 | 171 | |
| 161 | 172 | // Only check the ban every so often. (to reduce load.) |
| 162 | 173 | if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email'])) |
@@ -177,8 +188,9 @@ discard block |
||
| 177 | 188 | // Check both IP addresses. |
| 178 | 189 | foreach (array('ip', 'ip2') as $ip_number) |
| 179 | 190 | { |
| 180 | - if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) |
|
| 181 | - continue; |
|
| 191 | + if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) { |
|
| 192 | + continue; |
|
| 193 | + } |
|
| 182 | 194 | $ban_query[] = ' {inet:'.$ip_number.'} BETWEEN bi.ip_low and bi.ip_high'; |
| 183 | 195 | $ban_query_vars[$ip_number] = $user_info[$ip_number]; |
| 184 | 196 | // IP was valid, maybe there's also a hostname... |
@@ -228,24 +240,28 @@ discard block |
||
| 228 | 240 | // Store every type of ban that applies to you in your session. |
| 229 | 241 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 230 | 242 | { |
| 231 | - foreach ($restrictions as $restriction) |
|
| 232 | - if (!empty($row[$restriction])) |
|
| 243 | + foreach ($restrictions as $restriction) { |
|
| 244 | + if (!empty($row[$restriction])) |
|
| 233 | 245 | { |
| 234 | 246 | $_SESSION['ban'][$restriction]['reason'] = $row['reason']; |
| 247 | + } |
|
| 235 | 248 | $_SESSION['ban'][$restriction]['ids'][] = $row['id_ban']; |
| 236 | - if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) |
|
| 237 | - $_SESSION['ban']['expire_time'] = $row['expire_time']; |
|
| 249 | + if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) { |
|
| 250 | + $_SESSION['ban']['expire_time'] = $row['expire_time']; |
|
| 251 | + } |
|
| 238 | 252 | |
| 239 | - if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) |
|
| 240 | - $flag_is_activated = true; |
|
| 253 | + if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) { |
|
| 254 | + $flag_is_activated = true; |
|
| 255 | + } |
|
| 241 | 256 | } |
| 242 | 257 | } |
| 243 | 258 | $smcFunc['db_free_result']($request); |
| 244 | 259 | } |
| 245 | 260 | |
| 246 | 261 | // Mark the cannot_access and cannot_post bans as being 'hit'. |
| 247 | - if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) |
|
| 248 | - log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array())); |
|
| 262 | + if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) { |
|
| 263 | + log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array())); |
|
| 264 | + } |
|
| 249 | 265 | |
| 250 | 266 | // If for whatever reason the is_activated flag seems wrong, do a little work to clear it up. |
| 251 | 267 | if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated) |
@@ -260,8 +276,9 @@ discard block |
||
| 260 | 276 | if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_'])) |
| 261 | 277 | { |
| 262 | 278 | $bans = explode(',', $_COOKIE[$cookiename . '_']); |
| 263 | - foreach ($bans as $key => $value) |
|
| 264 | - $bans[$key] = (int) $value; |
|
| 279 | + foreach ($bans as $key => $value) { |
|
| 280 | + $bans[$key] = (int) $value; |
|
| 281 | + } |
|
| 265 | 282 | $request = $smcFunc['db_query']('', ' |
| 266 | 283 | SELECT bi.id_ban, bg.reason |
| 267 | 284 | FROM {db_prefix}ban_items AS bi |
@@ -297,14 +314,15 @@ discard block |
||
| 297 | 314 | if (isset($_SESSION['ban']['cannot_access'])) |
| 298 | 315 | { |
| 299 | 316 | // We don't wanna see you! |
| 300 | - if (!$user_info['is_guest']) |
|
| 301 | - $smcFunc['db_query']('', ' |
|
| 317 | + if (!$user_info['is_guest']) { |
|
| 318 | + $smcFunc['db_query']('', ' |
|
| 302 | 319 | DELETE FROM {db_prefix}log_online |
| 303 | 320 | WHERE id_member = {int:current_member}', |
| 304 | 321 | array( |
| 305 | 322 | 'current_member' => $user_info['id'], |
| 306 | 323 | ) |
| 307 | 324 | ); |
| 325 | + } |
|
| 308 | 326 | |
| 309 | 327 | // 'Log' the user out. Can't have any funny business... (save the name!) |
| 310 | 328 | $old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title']; |
@@ -390,9 +408,10 @@ discard block |
||
| 390 | 408 | } |
| 391 | 409 | |
| 392 | 410 | // Fix up the banning permissions. |
| 393 | - if (isset($user_info['permissions'])) |
|
| 394 | - banPermissions(); |
|
| 395 | -} |
|
| 411 | + if (isset($user_info['permissions'])) { |
|
| 412 | + banPermissions(); |
|
| 413 | + } |
|
| 414 | + } |
|
| 396 | 415 | |
| 397 | 416 | /** |
| 398 | 417 | * Fix permissions according to ban status. |
@@ -403,8 +422,9 @@ discard block |
||
| 403 | 422 | global $user_info, $sourcedir, $modSettings, $context; |
| 404 | 423 | |
| 405 | 424 | // Somehow they got here, at least take away all permissions... |
| 406 | - if (isset($_SESSION['ban']['cannot_access'])) |
|
| 407 | - $user_info['permissions'] = array(); |
|
| 425 | + if (isset($_SESSION['ban']['cannot_access'])) { |
|
| 426 | + $user_info['permissions'] = array(); |
|
| 427 | + } |
|
| 408 | 428 | // Okay, well, you can watch, but don't touch a thing. |
| 409 | 429 | elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning'])) |
| 410 | 430 | { |
@@ -446,44 +466,45 @@ discard block |
||
| 446 | 466 | call_integration_hook('integrate_warn_permissions', array(&$permission_change)); |
| 447 | 467 | foreach ($permission_change as $old => $new) |
| 448 | 468 | { |
| 449 | - if (!in_array($old, $user_info['permissions'])) |
|
| 450 | - unset($permission_change[$old]); |
|
| 451 | - else |
|
| 452 | - $user_info['permissions'][] = $new; |
|
| 469 | + if (!in_array($old, $user_info['permissions'])) { |
|
| 470 | + unset($permission_change[$old]); |
|
| 471 | + } else { |
|
| 472 | + $user_info['permissions'][] = $new; |
|
| 473 | + } |
|
| 453 | 474 | } |
| 454 | 475 | $user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change)); |
| 455 | 476 | } |
| 456 | 477 | |
| 457 | 478 | // @todo Find a better place to call this? Needs to be after permissions loaded! |
| 458 | 479 | // Finally, some bits we cache in the session because it saves queries. |
| 459 | - if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) |
|
| 460 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
| 461 | - else |
|
| 480 | + if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) { |
|
| 481 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
| 482 | + } else |
|
| 462 | 483 | { |
| 463 | 484 | require_once($sourcedir . '/Subs-Auth.php'); |
| 464 | 485 | rebuildModCache(); |
| 465 | 486 | } |
| 466 | 487 | |
| 467 | 488 | // Now that we have the mod cache taken care of lets setup a cache for the number of mod reports still open |
| 468 | - if (!empty($_SESSION['rc']) && $_SESSION['rc']['time'] > $modSettings['last_mod_report_action'] && $_SESSION['rc']['id'] == $user_info['id']) |
|
| 469 | - $context['open_mod_reports'] = $_SESSION['rc']['reports']; |
|
| 470 | - elseif ($_SESSION['mc']['bq'] != '0=1') |
|
| 489 | + if (!empty($_SESSION['rc']) && $_SESSION['rc']['time'] > $modSettings['last_mod_report_action'] && $_SESSION['rc']['id'] == $user_info['id']) { |
|
| 490 | + $context['open_mod_reports'] = $_SESSION['rc']['reports']; |
|
| 491 | + } elseif ($_SESSION['mc']['bq'] != '0=1') |
|
| 471 | 492 | { |
| 472 | 493 | require_once($sourcedir . '/Subs-ReportedContent.php'); |
| 473 | 494 | recountOpenReports('posts'); |
| 495 | + } else { |
|
| 496 | + $context['open_mod_reports'] = 0; |
|
| 474 | 497 | } |
| 475 | - else |
|
| 476 | - $context['open_mod_reports'] = 0; |
|
| 477 | 498 | |
| 478 | - if (!empty($_SESSION['rc']) && $_SESSION['rc']['time'] > $modSettings['last_mod_report_action'] && $_SESSION['rc']['id'] == $user_info['id']) |
|
| 479 | - $context['open_member_reports'] = !empty($_SESSION['rc']['member_reports']) ? $_SESSION['rc']['member_reports'] : 0; |
|
| 480 | - elseif (allowedTo('moderate_forum')) |
|
| 499 | + if (!empty($_SESSION['rc']) && $_SESSION['rc']['time'] > $modSettings['last_mod_report_action'] && $_SESSION['rc']['id'] == $user_info['id']) { |
|
| 500 | + $context['open_member_reports'] = !empty($_SESSION['rc']['member_reports']) ? $_SESSION['rc']['member_reports'] : 0; |
|
| 501 | + } elseif (allowedTo('moderate_forum')) |
|
| 481 | 502 | { |
| 482 | 503 | require_once($sourcedir . '/Subs-ReportedContent.php'); |
| 483 | 504 | recountOpenReports('members'); |
| 505 | + } else { |
|
| 506 | + $context['open_member_reports'] = 0; |
|
| 484 | 507 | } |
| 485 | - else |
|
| 486 | - $context['open_member_reports'] = 0; |
|
| 487 | 508 | |
| 488 | 509 | } |
| 489 | 510 | |
@@ -500,8 +521,9 @@ discard block |
||
| 500 | 521 | global $user_info, $smcFunc; |
| 501 | 522 | |
| 502 | 523 | // Don't log web accelerators, it's very confusing... |
| 503 | - if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
|
| 504 | - return; |
|
| 524 | + if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') { |
|
| 525 | + return; |
|
| 526 | + } |
|
| 505 | 527 | |
| 506 | 528 | $smcFunc['db_insert']('', |
| 507 | 529 | '{db_prefix}log_banned', |
@@ -511,8 +533,8 @@ discard block |
||
| 511 | 533 | ); |
| 512 | 534 | |
| 513 | 535 | // One extra point for these bans. |
| 514 | - if (!empty($ban_ids)) |
|
| 515 | - $smcFunc['db_query']('', ' |
|
| 536 | + if (!empty($ban_ids)) { |
|
| 537 | + $smcFunc['db_query']('', ' |
|
| 516 | 538 | UPDATE {db_prefix}ban_items |
| 517 | 539 | SET hits = hits + 1 |
| 518 | 540 | WHERE id_ban IN ({array_int:ban_ids})', |
@@ -520,7 +542,8 @@ discard block |
||
| 520 | 542 | 'ban_ids' => $ban_ids, |
| 521 | 543 | ) |
| 522 | 544 | ); |
| 523 | -} |
|
| 545 | + } |
|
| 546 | + } |
|
| 524 | 547 | |
| 525 | 548 | /** |
| 526 | 549 | * Checks if a given email address might be banned. |
@@ -536,8 +559,9 @@ discard block |
||
| 536 | 559 | global $txt, $smcFunc; |
| 537 | 560 | |
| 538 | 561 | // Can't ban an empty email |
| 539 | - if (empty($email) || trim($email) == '') |
|
| 540 | - return; |
|
| 562 | + if (empty($email) || trim($email) == '') { |
|
| 563 | + return; |
|
| 564 | + } |
|
| 541 | 565 | |
| 542 | 566 | // Let's start with the bans based on your IP/hostname/memberID... |
| 543 | 567 | $ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array(); |
@@ -610,16 +634,18 @@ discard block |
||
| 610 | 634 | if ($type == 'post') |
| 611 | 635 | { |
| 612 | 636 | $check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null); |
| 613 | - if ($check !== $sc) |
|
| 614 | - $error = 'session_timeout'; |
|
| 637 | + if ($check !== $sc) { |
|
| 638 | + $error = 'session_timeout'; |
|
| 639 | + } |
|
| 615 | 640 | } |
| 616 | 641 | |
| 617 | 642 | // How about $_GET['sesc']? |
| 618 | 643 | elseif ($type == 'get') |
| 619 | 644 | { |
| 620 | 645 | $check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null); |
| 621 | - if ($check !== $sc) |
|
| 622 | - $error = 'session_verify_fail'; |
|
| 646 | + if ($check !== $sc) { |
|
| 647 | + $error = 'session_verify_fail'; |
|
| 648 | + } |
|
| 623 | 649 | } |
| 624 | 650 | |
| 625 | 651 | // Or can it be in either? |
@@ -627,13 +653,15 @@ discard block |
||
| 627 | 653 | { |
| 628 | 654 | $check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null))); |
| 629 | 655 | |
| 630 | - if ($check !== $sc) |
|
| 631 | - $error = 'session_verify_fail'; |
|
| 656 | + if ($check !== $sc) { |
|
| 657 | + $error = 'session_verify_fail'; |
|
| 658 | + } |
|
| 632 | 659 | } |
| 633 | 660 | |
| 634 | 661 | // Verify that they aren't changing user agents on us - that could be bad. |
| 635 | - if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) |
|
| 636 | - $error = 'session_verify_fail'; |
|
| 662 | + if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) { |
|
| 663 | + $error = 'session_verify_fail'; |
|
| 664 | + } |
|
| 637 | 665 | |
| 638 | 666 | // Make sure a page with session check requirement is not being prefetched. |
| 639 | 667 | if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
@@ -644,30 +672,35 @@ discard block |
||
| 644 | 672 | } |
| 645 | 673 | |
| 646 | 674 | // Check the referring site - it should be the same server at least! |
| 647 | - if (isset($_SESSION['request_referer'])) |
|
| 648 | - $referrer = $_SESSION['request_referer']; |
|
| 649 | - else |
|
| 650 | - $referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
| 675 | + if (isset($_SESSION['request_referer'])) { |
|
| 676 | + $referrer = $_SESSION['request_referer']; |
|
| 677 | + } else { |
|
| 678 | + $referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array(); |
|
| 679 | + } |
|
| 651 | 680 | if (!empty($referrer['host'])) |
| 652 | 681 | { |
| 653 | - if (strpos($_SERVER['HTTP_HOST'], ':') !== false) |
|
| 654 | - $real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')); |
|
| 655 | - else |
|
| 656 | - $real_host = $_SERVER['HTTP_HOST']; |
|
| 682 | + if (strpos($_SERVER['HTTP_HOST'], ':') !== false) { |
|
| 683 | + $real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')); |
|
| 684 | + } else { |
|
| 685 | + $real_host = $_SERVER['HTTP_HOST']; |
|
| 686 | + } |
|
| 657 | 687 | |
| 658 | 688 | $parsed_url = parse_url($boardurl); |
| 659 | 689 | |
| 660 | 690 | // Are global cookies on? If so, let's check them ;). |
| 661 | 691 | if (!empty($modSettings['globalCookies'])) |
| 662 | 692 | { |
| 663 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
| 664 | - $parsed_url['host'] = $parts[1]; |
|
| 693 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
| 694 | + $parsed_url['host'] = $parts[1]; |
|
| 695 | + } |
|
| 665 | 696 | |
| 666 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) |
|
| 667 | - $referrer['host'] = $parts[1]; |
|
| 697 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) { |
|
| 698 | + $referrer['host'] = $parts[1]; |
|
| 699 | + } |
|
| 668 | 700 | |
| 669 | - if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) |
|
| 670 | - $real_host = $parts[1]; |
|
| 701 | + if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) { |
|
| 702 | + $real_host = $parts[1]; |
|
| 703 | + } |
|
| 671 | 704 | } |
| 672 | 705 | |
| 673 | 706 | // Okay: referrer must either match parsed_url or real_host. |
@@ -685,12 +718,14 @@ discard block |
||
| 685 | 718 | $log_error = true; |
| 686 | 719 | } |
| 687 | 720 | |
| 688 | - if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') |
|
| 689 | - fatal_error('Sound the alarm! It\'s a hacker! Close the castle gates!!', false); |
|
| 721 | + if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') { |
|
| 722 | + fatal_error('Sound the alarm! It\'s a hacker! Close the castle gates!!', false); |
|
| 723 | + } |
|
| 690 | 724 | |
| 691 | 725 | // Everything is ok, return an empty string. |
| 692 | - if (!isset($error)) |
|
| 693 | - return ''; |
|
| 726 | + if (!isset($error)) { |
|
| 727 | + return ''; |
|
| 728 | + } |
|
| 694 | 729 | // A session error occurred, show the error. |
| 695 | 730 | elseif ($is_fatal) |
| 696 | 731 | { |
@@ -699,13 +734,14 @@ discard block |
||
| 699 | 734 | ob_end_clean(); |
| 700 | 735 | header('HTTP/1.1 403 Forbidden - Session timeout'); |
| 701 | 736 | die; |
| 737 | + } else { |
|
| 738 | + fatal_lang_error($error, isset($log_error) ? 'user' : false); |
|
| 702 | 739 | } |
| 703 | - else |
|
| 704 | - fatal_lang_error($error, isset($log_error) ? 'user' : false); |
|
| 705 | 740 | } |
| 706 | 741 | // A session error occurred, return the error to the calling function. |
| 707 | - else |
|
| 708 | - return $error; |
|
| 742 | + else { |
|
| 743 | + return $error; |
|
| 744 | + } |
|
| 709 | 745 | |
| 710 | 746 | // We really should never fall through here, for very important reasons. Let's make sure. |
| 711 | 747 | trigger_error('Hacking attempt...', E_USER_ERROR); |
@@ -721,10 +757,9 @@ discard block |
||
| 721 | 757 | { |
| 722 | 758 | global $modSettings; |
| 723 | 759 | |
| 724 | - if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) |
|
| 725 | - return true; |
|
| 726 | - |
|
| 727 | - else |
|
| 760 | + if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) { |
|
| 761 | + return true; |
|
| 762 | + } else |
|
| 728 | 763 | { |
| 729 | 764 | $token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']); |
| 730 | 765 | $_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']); |
@@ -775,9 +810,9 @@ discard block |
||
| 775 | 810 | $return = $_SESSION['token'][$type . '-' . $action][3]; |
| 776 | 811 | unset($_SESSION['token'][$type . '-' . $action]); |
| 777 | 812 | return $return; |
| 813 | + } else { |
|
| 814 | + return ''; |
|
| 778 | 815 | } |
| 779 | - else |
|
| 780 | - return ''; |
|
| 781 | 816 | } |
| 782 | 817 | |
| 783 | 818 | // This nasty piece of code validates a token. |
@@ -808,12 +843,14 @@ discard block |
||
| 808 | 843 | fatal_lang_error('token_verify_fail', false); |
| 809 | 844 | } |
| 810 | 845 | // Remove this token as its useless |
| 811 | - else |
|
| 812 | - unset($_SESSION['token'][$type . '-' . $action]); |
|
| 846 | + else { |
|
| 847 | + unset($_SESSION['token'][$type . '-' . $action]); |
|
| 848 | + } |
|
| 813 | 849 | |
| 814 | 850 | // Randomly check if we should remove some older tokens. |
| 815 | - if (mt_rand(0, 138) == 23) |
|
| 816 | - cleanTokens(); |
|
| 851 | + if (mt_rand(0, 138) == 23) { |
|
| 852 | + cleanTokens(); |
|
| 853 | + } |
|
| 817 | 854 | |
| 818 | 855 | return false; |
| 819 | 856 | } |
@@ -828,14 +865,16 @@ discard block |
||
| 828 | 865 | function cleanTokens($complete = false) |
| 829 | 866 | { |
| 830 | 867 | // We appreciate cleaning up after yourselves. |
| 831 | - if (!isset($_SESSION['token'])) |
|
| 832 | - return; |
|
| 868 | + if (!isset($_SESSION['token'])) { |
|
| 869 | + return; |
|
| 870 | + } |
|
| 833 | 871 | |
| 834 | 872 | // Clean up tokens, trying to give enough time still. |
| 835 | - foreach ($_SESSION['token'] as $key => $data) |
|
| 836 | - if ($data[2] + 10800 < time() || $complete) |
|
| 873 | + foreach ($_SESSION['token'] as $key => $data) { |
|
| 874 | + if ($data[2] + 10800 < time() || $complete) |
|
| 837 | 875 | unset($_SESSION['token'][$key]); |
| 838 | -} |
|
| 876 | + } |
|
| 877 | + } |
|
| 839 | 878 | |
| 840 | 879 | /** |
| 841 | 880 | * Check whether a form has been submitted twice. |
@@ -853,37 +892,40 @@ discard block |
||
| 853 | 892 | { |
| 854 | 893 | global $context; |
| 855 | 894 | |
| 856 | - if (!isset($_SESSION['forms'])) |
|
| 857 | - $_SESSION['forms'] = array(); |
|
| 895 | + if (!isset($_SESSION['forms'])) { |
|
| 896 | + $_SESSION['forms'] = array(); |
|
| 897 | + } |
|
| 858 | 898 | |
| 859 | 899 | // Register a form number and store it in the session stack. (use this on the page that has the form.) |
| 860 | 900 | if ($action == 'register') |
| 861 | 901 | { |
| 862 | 902 | $context['form_sequence_number'] = 0; |
| 863 | - while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) |
|
| 864 | - $context['form_sequence_number'] = mt_rand(1, 16000000); |
|
| 903 | + while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) { |
|
| 904 | + $context['form_sequence_number'] = mt_rand(1, 16000000); |
|
| 905 | + } |
|
| 865 | 906 | } |
| 866 | 907 | // Check whether the submitted number can be found in the session. |
| 867 | 908 | elseif ($action == 'check') |
| 868 | 909 | { |
| 869 | - if (!isset($_REQUEST['seqnum'])) |
|
| 870 | - return true; |
|
| 871 | - elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
| 910 | + if (!isset($_REQUEST['seqnum'])) { |
|
| 911 | + return true; |
|
| 912 | + } elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
| 872 | 913 | { |
| 873 | 914 | $_SESSION['forms'][] = (int) $_REQUEST['seqnum']; |
| 874 | 915 | return true; |
| 916 | + } elseif ($is_fatal) { |
|
| 917 | + fatal_lang_error('error_form_already_submitted', false); |
|
| 918 | + } else { |
|
| 919 | + return false; |
|
| 875 | 920 | } |
| 876 | - elseif ($is_fatal) |
|
| 877 | - fatal_lang_error('error_form_already_submitted', false); |
|
| 878 | - else |
|
| 879 | - return false; |
|
| 880 | 921 | } |
| 881 | 922 | // Don't check, just free the stack number. |
| 882 | - elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) |
|
| 883 | - $_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum'])); |
|
| 884 | - elseif ($action != 'free') |
|
| 885 | - trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING); |
|
| 886 | -} |
|
| 923 | + elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) { |
|
| 924 | + $_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum'])); |
|
| 925 | + } elseif ($action != 'free') { |
|
| 926 | + trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING); |
|
| 927 | + } |
|
| 928 | + } |
|
| 887 | 929 | |
| 888 | 930 | /** |
| 889 | 931 | * Check the user's permissions. |
@@ -900,16 +942,19 @@ discard block |
||
| 900 | 942 | global $user_info, $smcFunc; |
| 901 | 943 | |
| 902 | 944 | // You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!) |
| 903 | - if (empty($permission)) |
|
| 904 | - return true; |
|
| 945 | + if (empty($permission)) { |
|
| 946 | + return true; |
|
| 947 | + } |
|
| 905 | 948 | |
| 906 | 949 | // You're never allowed to do something if your data hasn't been loaded yet! |
| 907 | - if (empty($user_info)) |
|
| 908 | - return false; |
|
| 950 | + if (empty($user_info)) { |
|
| 951 | + return false; |
|
| 952 | + } |
|
| 909 | 953 | |
| 910 | 954 | // Administrators are supermen :P. |
| 911 | - if ($user_info['is_admin']) |
|
| 912 | - return true; |
|
| 955 | + if ($user_info['is_admin']) { |
|
| 956 | + return true; |
|
| 957 | + } |
|
| 913 | 958 | |
| 914 | 959 | // Let's ensure this is an array. |
| 915 | 960 | $permission = (array)$permission; |
@@ -917,14 +962,16 @@ discard block |
||
| 917 | 962 | // Are we checking the _current_ board, or some other boards? |
| 918 | 963 | if ($boards === null) |
| 919 | 964 | { |
| 920 | - if (count(array_intersect($permission, $user_info['permissions'])) != 0) |
|
| 921 | - return true; |
|
| 965 | + if (count(array_intersect($permission, $user_info['permissions'])) != 0) { |
|
| 966 | + return true; |
|
| 967 | + } |
|
| 922 | 968 | // You aren't allowed, by default. |
| 923 | - else |
|
| 924 | - return false; |
|
| 969 | + else { |
|
| 970 | + return false; |
|
| 971 | + } |
|
| 972 | + } elseif (!is_array($boards)) { |
|
| 973 | + $boards = array($boards); |
|
| 925 | 974 | } |
| 926 | - elseif (!is_array($boards)) |
|
| 927 | - $boards = array($boards); |
|
| 928 | 975 | |
| 929 | 976 | $request = $smcFunc['db_query']('', ' |
| 930 | 977 | SELECT MIN(bp.add_deny) AS add_deny |
@@ -947,12 +994,14 @@ discard block |
||
| 947 | 994 | ); |
| 948 | 995 | |
| 949 | 996 | // Make sure they can do it on all of the boards. |
| 950 | - if ($smcFunc['db_num_rows']($request) != count($boards)) |
|
| 951 | - return false; |
|
| 997 | + if ($smcFunc['db_num_rows']($request) != count($boards)) { |
|
| 998 | + return false; |
|
| 999 | + } |
|
| 952 | 1000 | |
| 953 | 1001 | $result = true; |
| 954 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 955 | - $result &= !empty($row['add_deny']); |
|
| 1002 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1003 | + $result &= !empty($row['add_deny']); |
|
| 1004 | + } |
|
| 956 | 1005 | $smcFunc['db_free_result']($request); |
| 957 | 1006 | |
| 958 | 1007 | // If the query returned 1, they can do it... otherwise, they can't. |
@@ -1017,9 +1066,10 @@ discard block |
||
| 1017 | 1066 | |
| 1018 | 1067 | // If you're doing something on behalf of some "heavy" permissions, validate your session. |
| 1019 | 1068 | // (take out the heavy permissions, and if you can't do anything but those, you need a validated session.) |
| 1020 | - if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) |
|
| 1021 | - validateSession(); |
|
| 1022 | -} |
|
| 1069 | + if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) { |
|
| 1070 | + validateSession(); |
|
| 1071 | + } |
|
| 1072 | + } |
|
| 1023 | 1073 | |
| 1024 | 1074 | /** |
| 1025 | 1075 | * Return the boards a user has a certain (board) permission on. (array(0) if all.) |
@@ -1038,8 +1088,9 @@ discard block |
||
| 1038 | 1088 | global $user_info, $smcFunc; |
| 1039 | 1089 | |
| 1040 | 1090 | // Arrays are nice, most of the time. |
| 1041 | - if (!is_array($permissions)) |
|
| 1042 | - $permissions = array($permissions); |
|
| 1091 | + if (!is_array($permissions)) { |
|
| 1092 | + $permissions = array($permissions); |
|
| 1093 | + } |
|
| 1043 | 1094 | |
| 1044 | 1095 | /* |
| 1045 | 1096 | * Set $simple to true to use this function as it were in SMF 2.0.x. |
@@ -1051,13 +1102,14 @@ discard block |
||
| 1051 | 1102 | // Administrators are all powerful, sorry. |
| 1052 | 1103 | if ($user_info['is_admin']) |
| 1053 | 1104 | { |
| 1054 | - if ($simple) |
|
| 1055 | - return array(0); |
|
| 1056 | - else |
|
| 1105 | + if ($simple) { |
|
| 1106 | + return array(0); |
|
| 1107 | + } else |
|
| 1057 | 1108 | { |
| 1058 | 1109 | $boards = array(); |
| 1059 | - foreach ($permissions as $permission) |
|
| 1060 | - $boards[$permission] = array(0); |
|
| 1110 | + foreach ($permissions as $permission) { |
|
| 1111 | + $boards[$permission] = array(0); |
|
| 1112 | + } |
|
| 1061 | 1113 | |
| 1062 | 1114 | return $boards; |
| 1063 | 1115 | } |
@@ -1089,31 +1141,32 @@ discard block |
||
| 1089 | 1141 | { |
| 1090 | 1142 | if ($simple) |
| 1091 | 1143 | { |
| 1092 | - if (empty($row['add_deny'])) |
|
| 1093 | - $deny_boards[] = $row['id_board']; |
|
| 1094 | - else |
|
| 1095 | - $boards[] = $row['id_board']; |
|
| 1096 | - } |
|
| 1097 | - else |
|
| 1144 | + if (empty($row['add_deny'])) { |
|
| 1145 | + $deny_boards[] = $row['id_board']; |
|
| 1146 | + } else { |
|
| 1147 | + $boards[] = $row['id_board']; |
|
| 1148 | + } |
|
| 1149 | + } else |
|
| 1098 | 1150 | { |
| 1099 | - if (empty($row['add_deny'])) |
|
| 1100 | - $deny_boards[$row['permission']][] = $row['id_board']; |
|
| 1101 | - else |
|
| 1102 | - $boards[$row['permission']][] = $row['id_board']; |
|
| 1151 | + if (empty($row['add_deny'])) { |
|
| 1152 | + $deny_boards[$row['permission']][] = $row['id_board']; |
|
| 1153 | + } else { |
|
| 1154 | + $boards[$row['permission']][] = $row['id_board']; |
|
| 1155 | + } |
|
| 1103 | 1156 | } |
| 1104 | 1157 | } |
| 1105 | 1158 | $smcFunc['db_free_result']($request); |
| 1106 | 1159 | |
| 1107 | - if ($simple) |
|
| 1108 | - $boards = array_unique(array_values(array_diff($boards, $deny_boards))); |
|
| 1109 | - else |
|
| 1160 | + if ($simple) { |
|
| 1161 | + $boards = array_unique(array_values(array_diff($boards, $deny_boards))); |
|
| 1162 | + } else |
|
| 1110 | 1163 | { |
| 1111 | 1164 | foreach ($permissions as $permission) |
| 1112 | 1165 | { |
| 1113 | 1166 | // never had it to start with |
| 1114 | - if (empty($boards[$permission])) |
|
| 1115 | - $boards[$permission] = array(); |
|
| 1116 | - else |
|
| 1167 | + if (empty($boards[$permission])) { |
|
| 1168 | + $boards[$permission] = array(); |
|
| 1169 | + } else |
|
| 1117 | 1170 | { |
| 1118 | 1171 | // Or it may have been removed |
| 1119 | 1172 | $deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array(); |
@@ -1149,10 +1202,11 @@ discard block |
||
| 1149 | 1202 | |
| 1150 | 1203 | |
| 1151 | 1204 | // Moderators are free... |
| 1152 | - if (!allowedTo('moderate_board')) |
|
| 1153 | - $timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime']; |
|
| 1154 | - else |
|
| 1155 | - $timeLimit = 2; |
|
| 1205 | + if (!allowedTo('moderate_board')) { |
|
| 1206 | + $timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime']; |
|
| 1207 | + } else { |
|
| 1208 | + $timeLimit = 2; |
|
| 1209 | + } |
|
| 1156 | 1210 | |
| 1157 | 1211 | call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit)); |
| 1158 | 1212 | |
@@ -1179,8 +1233,9 @@ discard block |
||
| 1179 | 1233 | if ($smcFunc['db_affected_rows']() != 1) |
| 1180 | 1234 | { |
| 1181 | 1235 | // Spammer! You only have to wait a *few* seconds! |
| 1182 | - if (!$only_return_result) |
|
| 1183 | - fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit)); |
|
| 1236 | + if (!$only_return_result) { |
|
| 1237 | + fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit)); |
|
| 1238 | + } |
|
| 1184 | 1239 | |
| 1185 | 1240 | return true; |
| 1186 | 1241 | } |
@@ -1198,11 +1253,13 @@ discard block |
||
| 1198 | 1253 | */ |
| 1199 | 1254 | function secureDirectory($path, $attachments = false) |
| 1200 | 1255 | { |
| 1201 | - if (empty($path)) |
|
| 1202 | - return 'empty_path'; |
|
| 1256 | + if (empty($path)) { |
|
| 1257 | + return 'empty_path'; |
|
| 1258 | + } |
|
| 1203 | 1259 | |
| 1204 | - if (!is_writable($path)) |
|
| 1205 | - return 'path_not_writable'; |
|
| 1260 | + if (!is_writable($path)) { |
|
| 1261 | + return 'path_not_writable'; |
|
| 1262 | + } |
|
| 1206 | 1263 | |
| 1207 | 1264 | $directoryname = basename($path); |
| 1208 | 1265 | |
@@ -1214,9 +1271,9 @@ discard block |
||
| 1214 | 1271 | |
| 1215 | 1272 | RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml'; |
| 1216 | 1273 | |
| 1217 | - if (file_exists($path . '/.htaccess')) |
|
| 1218 | - $errors[] = 'htaccess_exists'; |
|
| 1219 | - else |
|
| 1274 | + if (file_exists($path . '/.htaccess')) { |
|
| 1275 | + $errors[] = 'htaccess_exists'; |
|
| 1276 | + } else |
|
| 1220 | 1277 | { |
| 1221 | 1278 | $fh = @fopen($path . '/.htaccess', 'w'); |
| 1222 | 1279 | if ($fh) { |
@@ -1228,9 +1285,9 @@ discard block |
||
| 1228 | 1285 | $errors[] = 'htaccess_cannot_create_file'; |
| 1229 | 1286 | } |
| 1230 | 1287 | |
| 1231 | - if (file_exists($path . '/index.php')) |
|
| 1232 | - $errors[] = 'index-php_exists'; |
|
| 1233 | - else |
|
| 1288 | + if (file_exists($path . '/index.php')) { |
|
| 1289 | + $errors[] = 'index-php_exists'; |
|
| 1290 | + } else |
|
| 1234 | 1291 | { |
| 1235 | 1292 | $fh = @fopen($path . '/index.php', 'w'); |
| 1236 | 1293 | if ($fh) { |
@@ -1257,11 +1314,12 @@ discard block |
||
| 1257 | 1314 | $errors[] = 'index-php_cannot_create_file'; |
| 1258 | 1315 | } |
| 1259 | 1316 | |
| 1260 | - if (!empty($errors)) |
|
| 1261 | - return $errors; |
|
| 1262 | - else |
|
| 1263 | - return true; |
|
| 1264 | -} |
|
| 1317 | + if (!empty($errors)) { |
|
| 1318 | + return $errors; |
|
| 1319 | + } else { |
|
| 1320 | + return true; |
|
| 1321 | + } |
|
| 1322 | + } |
|
| 1265 | 1323 | |
| 1266 | 1324 | /** |
| 1267 | 1325 | * This sets the X-Frame-Options header. |
@@ -1274,14 +1332,16 @@ discard block |
||
| 1274 | 1332 | global $modSettings; |
| 1275 | 1333 | |
| 1276 | 1334 | $option = 'SAMEORIGIN'; |
| 1277 | - if (is_null($override) && !empty($modSettings['frame_security'])) |
|
| 1278 | - $option = $modSettings['frame_security']; |
|
| 1279 | - elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) |
|
| 1280 | - $option = $override; |
|
| 1335 | + if (is_null($override) && !empty($modSettings['frame_security'])) { |
|
| 1336 | + $option = $modSettings['frame_security']; |
|
| 1337 | + } elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) { |
|
| 1338 | + $option = $override; |
|
| 1339 | + } |
|
| 1281 | 1340 | |
| 1282 | 1341 | // Don't bother setting the header if we have disabled it. |
| 1283 | - if ($option == 'DISABLE') |
|
| 1284 | - return; |
|
| 1342 | + if ($option == 'DISABLE') { |
|
| 1343 | + return; |
|
| 1344 | + } |
|
| 1285 | 1345 | |
| 1286 | 1346 | // Finally set it. |
| 1287 | 1347 | header('X-Frame-Options: ' . $option); |
@@ -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 | /* The contents of this file handle the deletion of topics, posts, and related |
| 21 | 22 | paraphernalia. It has the following functions: |
@@ -37,8 +38,9 @@ discard block |
||
| 37 | 38 | require_once($sourcedir . '/Subs-Post.php'); |
| 38 | 39 | |
| 39 | 40 | // Trying to fool us around, are we? |
| 40 | - if (empty($topic)) |
|
| 41 | - redirectexit(); |
|
| 41 | + if (empty($topic)) { |
|
| 42 | + redirectexit(); |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | removeDeleteConcurrence(); |
| 44 | 46 | |
@@ -55,20 +57,23 @@ discard block |
||
| 55 | 57 | list ($starter, $subject, $approved, $locked) = $smcFunc['db_fetch_row']($request); |
| 56 | 58 | $smcFunc['db_free_result']($request); |
| 57 | 59 | |
| 58 | - if ($starter == $user_info['id'] && !allowedTo('remove_any')) |
|
| 59 | - isAllowedTo('remove_own'); |
|
| 60 | - else |
|
| 61 | - isAllowedTo('remove_any'); |
|
| 60 | + if ($starter == $user_info['id'] && !allowedTo('remove_any')) { |
|
| 61 | + isAllowedTo('remove_own'); |
|
| 62 | + } else { |
|
| 63 | + isAllowedTo('remove_any'); |
|
| 64 | + } |
|
| 62 | 65 | |
| 63 | 66 | // Can they see the topic? |
| 64 | - if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id']) |
|
| 65 | - isAllowedTo('approve_posts'); |
|
| 67 | + if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id']) { |
|
| 68 | + isAllowedTo('approve_posts'); |
|
| 69 | + } |
|
| 66 | 70 | |
| 67 | 71 | // Ok, we got that far, but is it locked? |
| 68 | 72 | if ($locked) |
| 69 | 73 | { |
| 70 | - if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any'))) |
|
| 71 | - fatal_lang_error('cannot_remove_locked', 'user'); |
|
| 74 | + if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any'))) { |
|
| 75 | + fatal_lang_error('cannot_remove_locked', 'user'); |
|
| 76 | + } |
|
| 72 | 77 | } |
| 73 | 78 | |
| 74 | 79 | // Notify people that this topic has been removed. |
@@ -77,8 +82,9 @@ discard block |
||
| 77 | 82 | removeTopics($topic); |
| 78 | 83 | |
| 79 | 84 | // Note, only log topic ID in native form if it's not gone forever. |
| 80 | - if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id'])) |
|
| 81 | - logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board)); |
|
| 85 | + if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id'])) { |
|
| 86 | + logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board)); |
|
| 87 | + } |
|
| 82 | 88 | |
| 83 | 89 | redirectexit('board=' . $board . '.0'); |
| 84 | 90 | } |
@@ -96,8 +102,9 @@ discard block |
||
| 96 | 102 | $_REQUEST['msg'] = (int) $_REQUEST['msg']; |
| 97 | 103 | |
| 98 | 104 | // Is $topic set? |
| 99 | - if (empty($topic) && isset($_REQUEST['topic'])) |
|
| 100 | - $topic = (int) $_REQUEST['topic']; |
|
| 105 | + if (empty($topic) && isset($_REQUEST['topic'])) { |
|
| 106 | + $topic = (int) $_REQUEST['topic']; |
|
| 107 | + } |
|
| 101 | 108 | |
| 102 | 109 | removeDeleteConcurrence(); |
| 103 | 110 | |
@@ -116,44 +123,48 @@ discard block |
||
| 116 | 123 | $smcFunc['db_free_result']($request); |
| 117 | 124 | |
| 118 | 125 | // Verify they can see this! |
| 119 | - if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id']) |
|
| 120 | - isAllowedTo('approve_posts'); |
|
| 126 | + if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id']) { |
|
| 127 | + isAllowedTo('approve_posts'); |
|
| 128 | + } |
|
| 121 | 129 | |
| 122 | 130 | if ($poster == $user_info['id']) |
| 123 | 131 | { |
| 124 | 132 | if (!allowedTo('delete_own')) |
| 125 | 133 | { |
| 126 | - if ($starter == $user_info['id'] && !allowedTo('delete_any')) |
|
| 127 | - isAllowedTo('delete_replies'); |
|
| 128 | - elseif (!allowedTo('delete_any')) |
|
| 129 | - isAllowedTo('delete_own'); |
|
| 134 | + if ($starter == $user_info['id'] && !allowedTo('delete_any')) { |
|
| 135 | + isAllowedTo('delete_replies'); |
|
| 136 | + } elseif (!allowedTo('delete_any')) { |
|
| 137 | + isAllowedTo('delete_own'); |
|
| 138 | + } |
|
| 139 | + } elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time()) { |
|
| 140 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 130 | 141 | } |
| 131 | - elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time()) |
|
| 132 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 142 | + } elseif ($starter == $user_info['id'] && !allowedTo('delete_any')) { |
|
| 143 | + isAllowedTo('delete_replies'); |
|
| 144 | + } else { |
|
| 145 | + isAllowedTo('delete_any'); |
|
| 133 | 146 | } |
| 134 | - elseif ($starter == $user_info['id'] && !allowedTo('delete_any')) |
|
| 135 | - isAllowedTo('delete_replies'); |
|
| 136 | - else |
|
| 137 | - isAllowedTo('delete_any'); |
|
| 138 | 147 | |
| 139 | 148 | // If the full topic was removed go back to the board. |
| 140 | 149 | $full_topic = removeMessage($_REQUEST['msg']); |
| 141 | 150 | |
| 142 | - if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id'])) |
|
| 143 | - logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board)); |
|
| 151 | + if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id'])) { |
|
| 152 | + logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board)); |
|
| 153 | + } |
|
| 144 | 154 | |
| 145 | 155 | // We want to redirect back to recent action. |
| 146 | - if (isset($_REQUEST['modcenter'])) |
|
| 147 | - redirectexit('action=moderate;area=reportedposts;done'); |
|
| 148 | - elseif (isset($_REQUEST['recent'])) |
|
| 149 | - redirectexit('action=recent'); |
|
| 150 | - elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u'])) |
|
| 151 | - redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']); |
|
| 152 | - elseif ($full_topic) |
|
| 153 | - redirectexit('board=' . $board . '.0'); |
|
| 154 | - else |
|
| 155 | - redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
| 156 | -} |
|
| 156 | + if (isset($_REQUEST['modcenter'])) { |
|
| 157 | + redirectexit('action=moderate;area=reportedposts;done'); |
|
| 158 | + } elseif (isset($_REQUEST['recent'])) { |
|
| 159 | + redirectexit('action=recent'); |
|
| 160 | + } elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u'])) { |
|
| 161 | + redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']); |
|
| 162 | + } elseif ($full_topic) { |
|
| 163 | + redirectexit('board=' . $board . '.0'); |
|
| 164 | + } else { |
|
| 165 | + redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
| 166 | + } |
|
| 167 | + } |
|
| 157 | 168 | |
| 158 | 169 | /** |
| 159 | 170 | * So long as you are sure... all old posts will be gone. |
@@ -167,8 +178,9 @@ discard block |
||
| 167 | 178 | checkSession('post', 'admin'); |
| 168 | 179 | |
| 169 | 180 | // No boards at all? Forget it then :/. |
| 170 | - if (empty($_POST['boards'])) |
|
| 171 | - redirectexit('action=admin;area=maintain;sa=topics'); |
|
| 181 | + if (empty($_POST['boards'])) { |
|
| 182 | + redirectexit('action=admin;area=maintain;sa=topics'); |
|
| 183 | + } |
|
| 172 | 184 | |
| 173 | 185 | // This should exist, but we can make sure. |
| 174 | 186 | $_POST['delete_type'] = isset($_POST['delete_type']) ? $_POST['delete_type'] : 'nothing'; |
@@ -222,8 +234,9 @@ discard block |
||
| 222 | 234 | $condition_params |
| 223 | 235 | ); |
| 224 | 236 | $topics = array(); |
| 225 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 226 | - $topics[] = $row['id_topic']; |
|
| 237 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 238 | + $topics[] = $row['id_topic']; |
|
| 239 | + } |
|
| 227 | 240 | $smcFunc['db_free_result']($request); |
| 228 | 241 | |
| 229 | 242 | removeTopics($topics, false, true); |
@@ -247,11 +260,13 @@ discard block |
||
| 247 | 260 | global $sourcedir, $modSettings, $smcFunc; |
| 248 | 261 | |
| 249 | 262 | // Nothing to do? |
| 250 | - if (empty($topics)) |
|
| 251 | - return; |
|
| 263 | + if (empty($topics)) { |
|
| 264 | + return; |
|
| 265 | + } |
|
| 252 | 266 | // Only a single topic. |
| 253 | - if (is_numeric($topics)) |
|
| 254 | - $topics = array($topics); |
|
| 267 | + if (is_numeric($topics)) { |
|
| 268 | + $topics = array($topics); |
|
| 269 | + } |
|
| 255 | 270 | |
| 256 | 271 | $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
| 257 | 272 | |
@@ -276,8 +291,9 @@ discard block |
||
| 276 | 291 | ); |
| 277 | 292 | if ($smcFunc['db_num_rows']($requestMembers) > 0) |
| 278 | 293 | { |
| 279 | - while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers)) |
|
| 280 | - updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts'])); |
|
| 294 | + while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers)) { |
|
| 295 | + updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts'])); |
|
| 296 | + } |
|
| 281 | 297 | } |
| 282 | 298 | $smcFunc['db_free_result']($requestMembers); |
| 283 | 299 | } |
@@ -303,8 +319,9 @@ discard block |
||
| 303 | 319 | $recycleTopics = array(); |
| 304 | 320 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 305 | 321 | { |
| 306 | - if (function_exists('apache_reset_timeout')) |
|
| 307 | - @apache_reset_timeout(); |
|
| 322 | + if (function_exists('apache_reset_timeout')) { |
|
| 323 | + @apache_reset_timeout(); |
|
| 324 | + } |
|
| 308 | 325 | |
| 309 | 326 | $recycleTopics[] = $row['id_topic']; |
| 310 | 327 | |
@@ -346,20 +363,22 @@ discard block |
||
| 346 | 363 | |
| 347 | 364 | // Topics that were recycled don't need to be deleted, so subtract them. |
| 348 | 365 | $topics = array_diff($topics, $recycleTopics); |
| 366 | + } else { |
|
| 367 | + $smcFunc['db_free_result']($request); |
|
| 349 | 368 | } |
| 350 | - else |
|
| 351 | - $smcFunc['db_free_result']($request); |
|
| 352 | 369 | } |
| 353 | 370 | |
| 354 | 371 | // Still topics left to delete? |
| 355 | - if (empty($topics)) |
|
| 356 | - return; |
|
| 372 | + if (empty($topics)) { |
|
| 373 | + return; |
|
| 374 | + } |
|
| 357 | 375 | |
| 358 | 376 | // Callback for search APIs to do their thing |
| 359 | 377 | require_once($sourcedir . '/Search.php'); |
| 360 | 378 | $searchAPI = findSearchAPI(); |
| 361 | - if ($searchAPI->supportsMethod('topicsRemoved')) |
|
| 362 | - $searchAPI->topicsRemoved($topics); |
|
| 379 | + if ($searchAPI->supportsMethod('topicsRemoved')) { |
|
| 380 | + $searchAPI->topicsRemoved($topics); |
|
| 381 | + } |
|
| 363 | 382 | |
| 364 | 383 | $adjustBoards = array(); |
| 365 | 384 | |
@@ -391,10 +410,11 @@ discard block |
||
| 391 | 410 | $adjustBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts']; |
| 392 | 411 | |
| 393 | 412 | // Add the topics to the right type. |
| 394 | - if ($row['approved']) |
|
| 395 | - $adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics']; |
|
| 396 | - else |
|
| 397 | - $adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics']; |
|
| 413 | + if ($row['approved']) { |
|
| 414 | + $adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics']; |
|
| 415 | + } else { |
|
| 416 | + $adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics']; |
|
| 417 | + } |
|
| 398 | 418 | } |
| 399 | 419 | $smcFunc['db_free_result']($request); |
| 400 | 420 | |
@@ -403,8 +423,9 @@ discard block |
||
| 403 | 423 | // Decrease the posts/topics... |
| 404 | 424 | foreach ($adjustBoards as $stats) |
| 405 | 425 | { |
| 406 | - if (function_exists('apache_reset_timeout')) |
|
| 407 | - @apache_reset_timeout(); |
|
| 426 | + if (function_exists('apache_reset_timeout')) { |
|
| 427 | + @apache_reset_timeout(); |
|
| 428 | + } |
|
| 408 | 429 | |
| 409 | 430 | $smcFunc['db_query']('', ' |
| 410 | 431 | UPDATE {db_prefix}boards |
@@ -438,8 +459,9 @@ discard block |
||
| 438 | 459 | ) |
| 439 | 460 | ); |
| 440 | 461 | $polls = array(); |
| 441 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 442 | - $polls[] = $row['id_poll']; |
|
| 462 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 463 | + $polls[] = $row['id_poll']; |
|
| 464 | + } |
|
| 443 | 465 | $smcFunc['db_free_result']($request); |
| 444 | 466 | |
| 445 | 467 | if (!empty($polls)) |
@@ -492,8 +514,9 @@ discard block |
||
| 492 | 514 | ); |
| 493 | 515 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 494 | 516 | { |
| 495 | - if (function_exists('apache_reset_timeout')) |
|
| 496 | - @apache_reset_timeout(); |
|
| 517 | + if (function_exists('apache_reset_timeout')) { |
|
| 518 | + @apache_reset_timeout(); |
|
| 519 | + } |
|
| 497 | 520 | |
| 498 | 521 | $words = array_merge($words, text2words($row['body'], $customIndexSettings['bytes_per_word'], true)); |
| 499 | 522 | $messages[] = $row['id_msg']; |
@@ -501,8 +524,8 @@ discard block |
||
| 501 | 524 | $smcFunc['db_free_result']($request); |
| 502 | 525 | $words = array_unique($words); |
| 503 | 526 | |
| 504 | - if (!empty($words) && !empty($messages)) |
|
| 505 | - $smcFunc['db_query']('', ' |
|
| 527 | + if (!empty($words) && !empty($messages)) { |
|
| 528 | + $smcFunc['db_query']('', ' |
|
| 506 | 529 | DELETE FROM {db_prefix}log_search_words |
| 507 | 530 | WHERE id_word IN ({array_int:word_list}) |
| 508 | 531 | AND id_msg IN ({array_int:message_list})', |
@@ -511,6 +534,7 @@ discard block |
||
| 511 | 534 | 'message_list' => $messages, |
| 512 | 535 | ) |
| 513 | 536 | ); |
| 537 | + } |
|
| 514 | 538 | } |
| 515 | 539 | |
| 516 | 540 | // Delete anything related to the topic. |
@@ -569,8 +593,9 @@ discard block |
||
| 569 | 593 | |
| 570 | 594 | require_once($sourcedir . '/Subs-Post.php'); |
| 571 | 595 | $updates = array(); |
| 572 | - foreach ($adjustBoards as $stats) |
|
| 573 | - $updates[] = $stats['id_board']; |
|
| 596 | + foreach ($adjustBoards as $stats) { |
|
| 597 | + $updates[] = $stats['id_board']; |
|
| 598 | + } |
|
| 574 | 599 | updateLastMessages($updates); |
| 575 | 600 | } |
| 576 | 601 | |
@@ -587,8 +612,9 @@ discard block |
||
| 587 | 612 | { |
| 588 | 613 | global $board, $sourcedir, $modSettings, $user_info, $smcFunc; |
| 589 | 614 | |
| 590 | - if (empty($message) || !is_numeric($message)) |
|
| 591 | - return false; |
|
| 615 | + if (empty($message) || !is_numeric($message)) { |
|
| 616 | + return false; |
|
| 617 | + } |
|
| 592 | 618 | |
| 593 | 619 | $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
| 594 | 620 | |
@@ -607,8 +633,9 @@ discard block |
||
| 607 | 633 | 'id_msg' => $message, |
| 608 | 634 | ) |
| 609 | 635 | ); |
| 610 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 611 | - return false; |
|
| 636 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 637 | + return false; |
|
| 638 | + } |
|
| 612 | 639 | $row = $smcFunc['db_fetch_assoc']($request); |
| 613 | 640 | $smcFunc['db_free_result']($request); |
| 614 | 641 | |
@@ -629,54 +656,57 @@ discard block |
||
| 629 | 656 | { |
| 630 | 657 | if ($row['id_member_poster'] == $user_info['id']) |
| 631 | 658 | { |
| 632 | - if (!$delete_replies) |
|
| 633 | - fatal_lang_error('cannot_delete_replies', 'permission'); |
|
| 659 | + if (!$delete_replies) { |
|
| 660 | + fatal_lang_error('cannot_delete_replies', 'permission'); |
|
| 661 | + } |
|
| 662 | + } else { |
|
| 663 | + fatal_lang_error('cannot_delete_own', 'permission'); |
|
| 634 | 664 | } |
| 635 | - else |
|
| 636 | - fatal_lang_error('cannot_delete_own', 'permission'); |
|
| 665 | + } elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) { |
|
| 666 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 637 | 667 | } |
| 638 | - elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) |
|
| 639 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 640 | - } |
|
| 641 | - elseif ($row['id_member_poster'] == $user_info['id']) |
|
| 668 | + } elseif ($row['id_member_poster'] == $user_info['id']) |
|
| 642 | 669 | { |
| 643 | - if (!$delete_replies) |
|
| 644 | - fatal_lang_error('cannot_delete_replies', 'permission'); |
|
| 670 | + if (!$delete_replies) { |
|
| 671 | + fatal_lang_error('cannot_delete_replies', 'permission'); |
|
| 672 | + } |
|
| 673 | + } else { |
|
| 674 | + fatal_lang_error('cannot_delete_any', 'permission'); |
|
| 645 | 675 | } |
| 646 | - else |
|
| 647 | - fatal_lang_error('cannot_delete_any', 'permission'); |
|
| 648 | 676 | } |
| 649 | 677 | |
| 650 | 678 | // Can't delete an unapproved message, if you can't see it! |
| 651 | 679 | if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !(in_array(0, $delete_any) || in_array($row['id_board'], $delete_any))) |
| 652 | 680 | { |
| 653 | 681 | $approve_posts = boardsAllowedTo('approve_posts'); |
| 654 | - if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts)) |
|
| 655 | - return false; |
|
| 682 | + if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts)) { |
|
| 683 | + return false; |
|
| 684 | + } |
|
| 656 | 685 | } |
| 657 | - } |
|
| 658 | - else |
|
| 686 | + } else |
|
| 659 | 687 | { |
| 660 | 688 | // Check permissions to delete this message. |
| 661 | 689 | if ($row['id_member'] == $user_info['id']) |
| 662 | 690 | { |
| 663 | 691 | if (!allowedTo('delete_own')) |
| 664 | 692 | { |
| 665 | - if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) |
|
| 666 | - isAllowedTo('delete_replies'); |
|
| 667 | - elseif (!allowedTo('delete_any')) |
|
| 668 | - isAllowedTo('delete_own'); |
|
| 693 | + if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) { |
|
| 694 | + isAllowedTo('delete_replies'); |
|
| 695 | + } elseif (!allowedTo('delete_any')) { |
|
| 696 | + isAllowedTo('delete_own'); |
|
| 697 | + } |
|
| 698 | + } elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) { |
|
| 699 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 669 | 700 | } |
| 670 | - elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) |
|
| 671 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 701 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) { |
|
| 702 | + isAllowedTo('delete_replies'); |
|
| 703 | + } else { |
|
| 704 | + isAllowedTo('delete_any'); |
|
| 672 | 705 | } |
| 673 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) |
|
| 674 | - isAllowedTo('delete_replies'); |
|
| 675 | - else |
|
| 676 | - isAllowedTo('delete_any'); |
|
| 677 | 706 | |
| 678 | - if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own')) |
|
| 679 | - isAllowedTo('approve_posts'); |
|
| 707 | + if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own')) { |
|
| 708 | + isAllowedTo('approve_posts'); |
|
| 709 | + } |
|
| 680 | 710 | } |
| 681 | 711 | |
| 682 | 712 | // Delete the *whole* topic, but only if the topic consists of one message. |
@@ -692,31 +722,34 @@ discard block |
||
| 692 | 722 | $remove_own = in_array(0, $remove_own) || in_array($row['id_board'], $remove_own); |
| 693 | 723 | } |
| 694 | 724 | |
| 695 | - if ($row['id_member'] != $user_info['id'] && !$remove_any) |
|
| 696 | - fatal_lang_error('cannot_remove_any', 'permission'); |
|
| 697 | - elseif (!$remove_any && !$remove_own) |
|
| 698 | - fatal_lang_error('cannot_remove_own', 'permission'); |
|
| 699 | - } |
|
| 700 | - else |
|
| 725 | + if ($row['id_member'] != $user_info['id'] && !$remove_any) { |
|
| 726 | + fatal_lang_error('cannot_remove_any', 'permission'); |
|
| 727 | + } elseif (!$remove_any && !$remove_own) { |
|
| 728 | + fatal_lang_error('cannot_remove_own', 'permission'); |
|
| 729 | + } |
|
| 730 | + } else |
|
| 701 | 731 | { |
| 702 | 732 | // Check permissions to delete a whole topic. |
| 703 | - if ($row['id_member'] != $user_info['id']) |
|
| 704 | - isAllowedTo('remove_any'); |
|
| 705 | - elseif (!allowedTo('remove_any')) |
|
| 706 | - isAllowedTo('remove_own'); |
|
| 733 | + if ($row['id_member'] != $user_info['id']) { |
|
| 734 | + isAllowedTo('remove_any'); |
|
| 735 | + } elseif (!allowedTo('remove_any')) { |
|
| 736 | + isAllowedTo('remove_own'); |
|
| 737 | + } |
|
| 707 | 738 | } |
| 708 | 739 | |
| 709 | 740 | // ...if there is only one post. |
| 710 | - if (!empty($row['num_replies'])) |
|
| 711 | - fatal_lang_error('delFirstPost', false); |
|
| 741 | + if (!empty($row['num_replies'])) { |
|
| 742 | + fatal_lang_error('delFirstPost', false); |
|
| 743 | + } |
|
| 712 | 744 | |
| 713 | 745 | removeTopics($row['id_topic']); |
| 714 | 746 | return true; |
| 715 | 747 | } |
| 716 | 748 | |
| 717 | 749 | // Deleting a recycled message can not lower anyone's post count. |
| 718 | - if (!empty($recycle_board) && $row['id_board'] == $recycle_board) |
|
| 719 | - $decreasePostCount = false; |
|
| 750 | + if (!empty($recycle_board) && $row['id_board'] == $recycle_board) { |
|
| 751 | + $decreasePostCount = false; |
|
| 752 | + } |
|
| 720 | 753 | |
| 721 | 754 | // This is the last post, update the last post on the board. |
| 722 | 755 | if ($row['id_last_msg'] == $message) |
@@ -755,8 +788,8 @@ discard block |
||
| 755 | 788 | ); |
| 756 | 789 | } |
| 757 | 790 | // Only decrease post counts. |
| 758 | - else |
|
| 759 | - $smcFunc['db_query']('', ' |
|
| 791 | + else { |
|
| 792 | + $smcFunc['db_query']('', ' |
|
| 760 | 793 | UPDATE {db_prefix}topics |
| 761 | 794 | SET ' . ($row['approved'] ? ' |
| 762 | 795 | num_replies = CASE WHEN num_replies = {int:no_replies} THEN 0 ELSE num_replies - 1 END' : ' |
@@ -768,6 +801,7 @@ discard block |
||
| 768 | 801 | 'id_topic' => $row['id_topic'], |
| 769 | 802 | ) |
| 770 | 803 | ); |
| 804 | + } |
|
| 771 | 805 | |
| 772 | 806 | // Default recycle to false. |
| 773 | 807 | $recycle = false; |
@@ -787,8 +821,9 @@ discard block |
||
| 787 | 821 | 'recycle_board' => $modSettings['recycle_board'], |
| 788 | 822 | ) |
| 789 | 823 | ); |
| 790 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 791 | - fatal_lang_error('recycle_no_valid_board'); |
|
| 824 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 825 | + fatal_lang_error('recycle_no_valid_board'); |
|
| 826 | + } |
|
| 792 | 827 | list ($isRead, $last_board_msg) = $smcFunc['db_fetch_row']($request); |
| 793 | 828 | $smcFunc['db_free_result']($request); |
| 794 | 829 | |
@@ -807,8 +842,8 @@ discard block |
||
| 807 | 842 | $smcFunc['db_free_result']($request); |
| 808 | 843 | |
| 809 | 844 | // Insert a new topic in the recycle board if $id_recycle_topic is empty. |
| 810 | - if (empty($id_recycle_topic)) |
|
| 811 | - $smcFunc['db_insert']('', |
|
| 845 | + if (empty($id_recycle_topic)) { |
|
| 846 | + $smcFunc['db_insert']('', |
|
| 812 | 847 | '{db_prefix}topics', |
| 813 | 848 | array( |
| 814 | 849 | 'id_board' => 'int', 'id_member_started' => 'int', 'id_member_updated' => 'int', 'id_first_msg' => 'int', |
@@ -820,6 +855,7 @@ discard block |
||
| 820 | 855 | ), |
| 821 | 856 | array('id_topic') |
| 822 | 857 | ); |
| 858 | + } |
|
| 823 | 859 | |
| 824 | 860 | // Capture the ID of the new topic... |
| 825 | 861 | $topicID = empty($id_recycle_topic) ? $smcFunc['db_insert_id']('{db_prefix}topics', 'id_topic') : $id_recycle_topic; |
@@ -857,22 +893,24 @@ discard block |
||
| 857 | 893 | ); |
| 858 | 894 | |
| 859 | 895 | // Mark recycled topic as read. |
| 860 | - if (!$user_info['is_guest']) |
|
| 861 | - $smcFunc['db_insert']('replace', |
|
| 896 | + if (!$user_info['is_guest']) { |
|
| 897 | + $smcFunc['db_insert']('replace', |
|
| 862 | 898 | '{db_prefix}log_topics', |
| 863 | 899 | array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int', 'unwatched' => 'int'), |
| 864 | 900 | array($topicID, $user_info['id'], $modSettings['maxMsgID'], 0), |
| 865 | 901 | array('id_topic', 'id_member') |
| 866 | 902 | ); |
| 903 | + } |
|
| 867 | 904 | |
| 868 | 905 | // Mark recycle board as seen, if it was marked as seen before. |
| 869 | - if (!empty($isRead) && !$user_info['is_guest']) |
|
| 870 | - $smcFunc['db_insert']('replace', |
|
| 906 | + if (!empty($isRead) && !$user_info['is_guest']) { |
|
| 907 | + $smcFunc['db_insert']('replace', |
|
| 871 | 908 | '{db_prefix}log_boards', |
| 872 | 909 | array('id_board' => 'int', 'id_member' => 'int', 'id_msg' => 'int'), |
| 873 | 910 | array($modSettings['recycle_board'], $user_info['id'], $modSettings['maxMsgID']), |
| 874 | 911 | array('id_board', 'id_member') |
| 875 | 912 | ); |
| 913 | + } |
|
| 876 | 914 | |
| 877 | 915 | // Add one topic and post to the recycle bin board. |
| 878 | 916 | $smcFunc['db_query']('', ' |
@@ -890,8 +928,8 @@ discard block |
||
| 890 | 928 | ); |
| 891 | 929 | |
| 892 | 930 | // Lets increase the num_replies, and the first/last message ID as appropriate. |
| 893 | - if (!empty($id_recycle_topic)) |
|
| 894 | - $smcFunc['db_query']('', ' |
|
| 931 | + if (!empty($id_recycle_topic)) { |
|
| 932 | + $smcFunc['db_query']('', ' |
|
| 895 | 933 | UPDATE {db_prefix}topics |
| 896 | 934 | SET num_replies = num_replies + 1' . |
| 897 | 935 | ($message > $last_topic_msg ? ', id_last_msg = {int:id_merged_msg}' : '') . |
@@ -902,6 +940,7 @@ discard block |
||
| 902 | 940 | 'id_merged_msg' => $message, |
| 903 | 941 | ) |
| 904 | 942 | ); |
| 943 | + } |
|
| 905 | 944 | |
| 906 | 945 | // Make sure this message isn't getting deleted later on. |
| 907 | 946 | $recycle = true; |
@@ -911,8 +950,8 @@ discard block |
||
| 911 | 950 | } |
| 912 | 951 | |
| 913 | 952 | // If it wasn't approved don't keep it in the queue. |
| 914 | - if (!$row['approved']) |
|
| 915 | - $smcFunc['db_query']('', ' |
|
| 953 | + if (!$row['approved']) { |
|
| 954 | + $smcFunc['db_query']('', ' |
|
| 916 | 955 | DELETE FROM {db_prefix}approval_queue |
| 917 | 956 | WHERE id_msg = {int:id_msg} |
| 918 | 957 | AND id_attach = {int:id_attach}', |
@@ -921,6 +960,7 @@ discard block |
||
| 921 | 960 | 'id_attach' => 0, |
| 922 | 961 | ) |
| 923 | 962 | ); |
| 963 | + } |
|
| 924 | 964 | } |
| 925 | 965 | |
| 926 | 966 | $smcFunc['db_query']('', ' |
@@ -938,8 +978,9 @@ discard block |
||
| 938 | 978 | |
| 939 | 979 | // If the poster was registered and the board this message was on incremented |
| 940 | 980 | // the member's posts when it was posted, decrease his or her post count. |
| 941 | - if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved']) |
|
| 942 | - updateMemberData($row['id_member'], array('posts' => '-')); |
|
| 981 | + if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved']) { |
|
| 982 | + updateMemberData($row['id_member'], array('posts' => '-')); |
|
| 983 | + } |
|
| 943 | 984 | |
| 944 | 985 | // Only remove posts if they're not recycled. |
| 945 | 986 | if (!$recycle) |
@@ -947,8 +988,9 @@ discard block |
||
| 947 | 988 | // Callback for search APIs to do their thing |
| 948 | 989 | require_once($sourcedir . '/Search.php'); |
| 949 | 990 | $searchAPI = findSearchAPI(); |
| 950 | - if ($searchAPI->supportsMethod('postRemoved')) |
|
| 951 | - $searchAPI->postRemoved($message); |
|
| 991 | + if ($searchAPI->supportsMethod('postRemoved')) { |
|
| 992 | + $searchAPI->postRemoved($message); |
|
| 993 | + } |
|
| 952 | 994 | |
| 953 | 995 | // Remove the message! |
| 954 | 996 | $smcFunc['db_query']('', ' |
@@ -963,8 +1005,8 @@ discard block |
||
| 963 | 1005 | { |
| 964 | 1006 | $customIndexSettings = smf_json_decode($modSettings['search_custom_index_config'], true); |
| 965 | 1007 | $words = text2words($row['body'], $customIndexSettings['bytes_per_word'], true); |
| 966 | - if (!empty($words)) |
|
| 967 | - $smcFunc['db_query']('', ' |
|
| 1008 | + if (!empty($words)) { |
|
| 1009 | + $smcFunc['db_query']('', ' |
|
| 968 | 1010 | DELETE FROM {db_prefix}log_search_words |
| 969 | 1011 | WHERE id_word IN ({array_int:word_list}) |
| 970 | 1012 | AND id_msg = {int:id_msg}', |
@@ -973,6 +1015,7 @@ discard block |
||
| 973 | 1015 | 'id_msg' => $message, |
| 974 | 1016 | ) |
| 975 | 1017 | ); |
| 1018 | + } |
|
| 976 | 1019 | } |
| 977 | 1020 | |
| 978 | 1021 | // Delete attachment(s) if they exist. |
@@ -996,10 +1039,11 @@ discard block |
||
| 996 | 1039 | |
| 997 | 1040 | // And now to update the last message of each board we messed with. |
| 998 | 1041 | require_once($sourcedir . '/Subs-Post.php'); |
| 999 | - if ($recycle) |
|
| 1000 | - updateLastMessages(array($row['id_board'], $modSettings['recycle_board'])); |
|
| 1001 | - else |
|
| 1002 | - updateLastMessages($row['id_board']); |
|
| 1042 | + if ($recycle) { |
|
| 1043 | + updateLastMessages(array($row['id_board'], $modSettings['recycle_board'])); |
|
| 1044 | + } else { |
|
| 1045 | + updateLastMessages($row['id_board']); |
|
| 1046 | + } |
|
| 1003 | 1047 | |
| 1004 | 1048 | // Close any moderation reports for this message. |
| 1005 | 1049 | $smcFunc['db_query']('', ' |
@@ -1032,8 +1076,9 @@ discard block |
||
| 1032 | 1076 | checkSession('get'); |
| 1033 | 1077 | |
| 1034 | 1078 | // Is recycled board enabled? |
| 1035 | - if (empty($modSettings['recycle_enable'])) |
|
| 1036 | - fatal_lang_error('restored_disabled', 'critical'); |
|
| 1079 | + if (empty($modSettings['recycle_enable'])) { |
|
| 1080 | + fatal_lang_error('restored_disabled', 'critical'); |
|
| 1081 | + } |
|
| 1037 | 1082 | |
| 1038 | 1083 | // Can we be in here? |
| 1039 | 1084 | isAllowedTo('move_any', $modSettings['recycle_board']); |
@@ -1048,8 +1093,9 @@ discard block |
||
| 1048 | 1093 | if (!empty($_REQUEST['msgs'])) |
| 1049 | 1094 | { |
| 1050 | 1095 | $msgs = explode(',', $_REQUEST['msgs']); |
| 1051 | - foreach ($msgs as $k => $msg) |
|
| 1052 | - $msgs[$k] = (int) $msg; |
|
| 1096 | + foreach ($msgs as $k => $msg) { |
|
| 1097 | + $msgs[$k] = (int) $msg; |
|
| 1098 | + } |
|
| 1053 | 1099 | |
| 1054 | 1100 | // Get the id_previous_board and id_previous_topic. |
| 1055 | 1101 | $request = $smcFunc['db_query']('', ' |
@@ -1083,8 +1129,8 @@ discard block |
||
| 1083 | 1129 | } |
| 1084 | 1130 | |
| 1085 | 1131 | $previous_topics[] = $row['id_previous_topic']; |
| 1086 | - if (empty($actioned_messages[$row['id_previous_topic']])) |
|
| 1087 | - $actioned_messages[$row['id_previous_topic']] = array( |
|
| 1132 | + if (empty($actioned_messages[$row['id_previous_topic']])) { |
|
| 1133 | + $actioned_messages[$row['id_previous_topic']] = array( |
|
| 1088 | 1134 | 'msgs' => array(), |
| 1089 | 1135 | 'count_posts' => $row['count_posts'], |
| 1090 | 1136 | 'subject' => $row['subject'], |
@@ -1094,17 +1140,20 @@ discard block |
||
| 1094 | 1140 | 'current_board' => $row['id_board'], |
| 1095 | 1141 | 'members' => array(), |
| 1096 | 1142 | ); |
| 1143 | + } |
|
| 1097 | 1144 | |
| 1098 | 1145 | $actioned_messages[$row['id_previous_topic']]['msgs'][$row['id_msg']] = $row['subject']; |
| 1099 | - if ($row['id_member']) |
|
| 1100 | - $actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member']; |
|
| 1146 | + if ($row['id_member']) { |
|
| 1147 | + $actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member']; |
|
| 1148 | + } |
|
| 1101 | 1149 | } |
| 1102 | 1150 | $smcFunc['db_free_result']($request); |
| 1103 | 1151 | |
| 1104 | 1152 | // Check for topics we are going to fully restore. |
| 1105 | - foreach ($actioned_messages as $topic => $data) |
|
| 1106 | - if (in_array($topic, $topics_to_restore)) |
|
| 1153 | + foreach ($actioned_messages as $topic => $data) { |
|
| 1154 | + if (in_array($topic, $topics_to_restore)) |
|
| 1107 | 1155 | unset($actioned_messages[$topic]); |
| 1156 | + } |
|
| 1108 | 1157 | |
| 1109 | 1158 | // Load any previous topics to check they exist. |
| 1110 | 1159 | if (!empty($previous_topics)) |
@@ -1119,11 +1168,12 @@ discard block |
||
| 1119 | 1168 | ) |
| 1120 | 1169 | ); |
| 1121 | 1170 | $previous_topics = array(); |
| 1122 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1123 | - $previous_topics[$row['id_topic']] = array( |
|
| 1171 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1172 | + $previous_topics[$row['id_topic']] = array( |
|
| 1124 | 1173 | 'board' => $row['id_board'], |
| 1125 | 1174 | 'subject' => $row['subject'], |
| 1126 | 1175 | ); |
| 1176 | + } |
|
| 1127 | 1177 | $smcFunc['db_free_result']($request); |
| 1128 | 1178 | } |
| 1129 | 1179 | |
@@ -1145,11 +1195,11 @@ discard block |
||
| 1145 | 1195 | // Log em. |
| 1146 | 1196 | logAction('restore_posts', array('topic' => $topic, 'subject' => $previous_topics[$topic]['subject'], 'board' => empty($data['previous_board']) ? $data['possible_prev_board'] : $data['previous_board'])); |
| 1147 | 1197 | $messages = array_merge(array_keys($data['msgs']), $messages); |
| 1148 | - } |
|
| 1149 | - else |
|
| 1198 | + } else |
|
| 1150 | 1199 | { |
| 1151 | - foreach ($data['msgs'] as $msg) |
|
| 1152 | - $unfound_messages[$msg['id']] = $msg['subject']; |
|
| 1200 | + foreach ($data['msgs'] as $msg) { |
|
| 1201 | + $unfound_messages[$msg['id']] = $msg['subject']; |
|
| 1202 | + } |
|
| 1153 | 1203 | } |
| 1154 | 1204 | } |
| 1155 | 1205 | } |
@@ -1158,8 +1208,9 @@ discard block |
||
| 1158 | 1208 | if (!empty($_REQUEST['topics'])) |
| 1159 | 1209 | { |
| 1160 | 1210 | $topics = explode(',', $_REQUEST['topics']); |
| 1161 | - foreach ($topics as $id) |
|
| 1162 | - $topics_to_restore[] = (int) $id; |
|
| 1211 | + foreach ($topics as $id) { |
|
| 1212 | + $topics_to_restore[] = (int) $id; |
|
| 1213 | + } |
|
| 1163 | 1214 | } |
| 1164 | 1215 | |
| 1165 | 1216 | if (!empty($topics_to_restore)) |
@@ -1213,8 +1264,9 @@ discard block |
||
| 1213 | 1264 | ) |
| 1214 | 1265 | ); |
| 1215 | 1266 | |
| 1216 | - while ($member = $smcFunc['db_fetch_assoc']($request2)) |
|
| 1217 | - updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count'])); |
|
| 1267 | + while ($member = $smcFunc['db_fetch_assoc']($request2)) { |
|
| 1268 | + updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count'])); |
|
| 1269 | + } |
|
| 1218 | 1270 | $smcFunc['db_free_result']($request2); |
| 1219 | 1271 | } |
| 1220 | 1272 | |
@@ -1225,8 +1277,9 @@ discard block |
||
| 1225 | 1277 | } |
| 1226 | 1278 | |
| 1227 | 1279 | // Didn't find some things? |
| 1228 | - if (!empty($unfound_messages)) |
|
| 1229 | - fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages))); |
|
| 1280 | + if (!empty($unfound_messages)) { |
|
| 1281 | + fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages))); |
|
| 1282 | + } |
|
| 1230 | 1283 | |
| 1231 | 1284 | // Just send them to the index if they get here. |
| 1232 | 1285 | redirectexit(); |
@@ -1246,12 +1299,14 @@ discard block |
||
| 1246 | 1299 | //!!! This really needs to be rewritten to take a load of messages from ANY topic, it's also inefficient. |
| 1247 | 1300 | |
| 1248 | 1301 | // Is it an array? |
| 1249 | - if (!is_array($msgs)) |
|
| 1250 | - $msgs = array($msgs); |
|
| 1302 | + if (!is_array($msgs)) { |
|
| 1303 | + $msgs = array($msgs); |
|
| 1304 | + } |
|
| 1251 | 1305 | |
| 1252 | 1306 | // Lets make sure they are int. |
| 1253 | - foreach ($msgs as $key => $msg) |
|
| 1254 | - $msgs[$key] = (int) $msg; |
|
| 1307 | + foreach ($msgs as $key => $msg) { |
|
| 1308 | + $msgs[$key] = (int) $msg; |
|
| 1309 | + } |
|
| 1255 | 1310 | |
| 1256 | 1311 | // Get the source information. |
| 1257 | 1312 | $request = $smcFunc['db_query']('', ' |
@@ -1294,8 +1349,9 @@ discard block |
||
| 1294 | 1349 | ) |
| 1295 | 1350 | ); |
| 1296 | 1351 | |
| 1297 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1298 | - updateMemberData($row['id_member'], array('posts' => '+')); |
|
| 1352 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1353 | + updateMemberData($row['id_member'], array('posts' => '+')); |
|
| 1354 | + } |
|
| 1299 | 1355 | } |
| 1300 | 1356 | |
| 1301 | 1357 | // Time to move the messages. |
@@ -1331,13 +1387,15 @@ discard block |
||
| 1331 | 1387 | ); |
| 1332 | 1388 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1333 | 1389 | { |
| 1334 | - if ($row['id_first_msg'] < $target_topic_data['id_first_msg']) |
|
| 1335 | - $target_topic_data['id_first_msg'] = $row['id_first_msg']; |
|
| 1390 | + if ($row['id_first_msg'] < $target_topic_data['id_first_msg']) { |
|
| 1391 | + $target_topic_data['id_first_msg'] = $row['id_first_msg']; |
|
| 1392 | + } |
|
| 1336 | 1393 | $target_topic_data['id_last_msg'] = $row['id_last_msg']; |
| 1337 | - if (!$row['approved']) |
|
| 1338 | - $target_topic_data['unapproved_posts'] = $row['message_count']; |
|
| 1339 | - else |
|
| 1340 | - $target_topic_data['num_replies'] = max(0, $row['message_count'] - 1); |
|
| 1394 | + if (!$row['approved']) { |
|
| 1395 | + $target_topic_data['unapproved_posts'] = $row['message_count']; |
|
| 1396 | + } else { |
|
| 1397 | + $target_topic_data['num_replies'] = max(0, $row['message_count'] - 1); |
|
| 1398 | + } |
|
| 1341 | 1399 | } |
| 1342 | 1400 | $smcFunc['db_free_result']($request); |
| 1343 | 1401 | |
@@ -1396,13 +1454,15 @@ discard block |
||
| 1396 | 1454 | ); |
| 1397 | 1455 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1398 | 1456 | { |
| 1399 | - if ($row['id_first_msg'] < $source_topic_data['id_first_msg']) |
|
| 1400 | - $source_topic_data['id_first_msg'] = $row['id_first_msg']; |
|
| 1457 | + if ($row['id_first_msg'] < $source_topic_data['id_first_msg']) { |
|
| 1458 | + $source_topic_data['id_first_msg'] = $row['id_first_msg']; |
|
| 1459 | + } |
|
| 1401 | 1460 | $source_topic_data['id_last_msg'] = $row['id_last_msg']; |
| 1402 | - if (!$row['approved']) |
|
| 1403 | - $source_topic_data['unapproved_posts'] = $row['message_count']; |
|
| 1404 | - else |
|
| 1405 | - $source_topic_data['num_replies'] = max(0, $row['message_count'] - 1); |
|
| 1461 | + if (!$row['approved']) { |
|
| 1462 | + $source_topic_data['unapproved_posts'] = $row['message_count']; |
|
| 1463 | + } else { |
|
| 1464 | + $source_topic_data['num_replies'] = max(0, $row['message_count'] - 1); |
|
| 1465 | + } |
|
| 1406 | 1466 | } |
| 1407 | 1467 | $smcFunc['db_free_result']($request); |
| 1408 | 1468 | |
@@ -1466,10 +1526,12 @@ discard block |
||
| 1466 | 1526 | |
| 1467 | 1527 | // Subject cache? |
| 1468 | 1528 | $cache_updates = array(); |
| 1469 | - if ($target_first_msg != $target_topic_data['id_first_msg']) |
|
| 1470 | - $cache_updates[] = $target_topic_data['id_first_msg']; |
|
| 1471 | - if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg']) |
|
| 1472 | - $cache_updates[] = $source_topic_data['id_first_msg']; |
|
| 1529 | + if ($target_first_msg != $target_topic_data['id_first_msg']) { |
|
| 1530 | + $cache_updates[] = $target_topic_data['id_first_msg']; |
|
| 1531 | + } |
|
| 1532 | + if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg']) { |
|
| 1533 | + $cache_updates[] = $source_topic_data['id_first_msg']; |
|
| 1534 | + } |
|
| 1473 | 1535 | |
| 1474 | 1536 | if (!empty($cache_updates)) |
| 1475 | 1537 | { |
@@ -1481,8 +1543,9 @@ discard block |
||
| 1481 | 1543 | 'first_messages' => $cache_updates, |
| 1482 | 1544 | ) |
| 1483 | 1545 | ); |
| 1484 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1485 | - updateStats('subject', $row['id_topic'], $row['subject']); |
|
| 1546 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1547 | + updateStats('subject', $row['id_topic'], $row['subject']); |
|
| 1548 | + } |
|
| 1486 | 1549 | $smcFunc['db_free_result']($request); |
| 1487 | 1550 | } |
| 1488 | 1551 | |
@@ -1498,22 +1561,26 @@ discard block |
||
| 1498 | 1561 | global $modSettings, $board, $scripturl, $context; |
| 1499 | 1562 | |
| 1500 | 1563 | // No recycle no need to go further |
| 1501 | - if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board'])) |
|
| 1502 | - return false; |
|
| 1564 | + if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board'])) { |
|
| 1565 | + return false; |
|
| 1566 | + } |
|
| 1503 | 1567 | |
| 1504 | 1568 | // If it's confirmed go on and delete (from recycle) |
| 1505 | - if (isset($_GET['confirm_delete'])) |
|
| 1506 | - return true; |
|
| 1569 | + if (isset($_GET['confirm_delete'])) { |
|
| 1570 | + return true; |
|
| 1571 | + } |
|
| 1507 | 1572 | |
| 1508 | - if (empty($board)) |
|
| 1509 | - return false; |
|
| 1573 | + if (empty($board)) { |
|
| 1574 | + return false; |
|
| 1575 | + } |
|
| 1510 | 1576 | |
| 1511 | - if ($modSettings['recycle_board'] != $board) |
|
| 1512 | - return true; |
|
| 1513 | - elseif (isset($_REQUEST['msg'])) |
|
| 1514 | - $confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
|
| 1515 | - else |
|
| 1516 | - $confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']; |
|
| 1577 | + if ($modSettings['recycle_board'] != $board) { |
|
| 1578 | + return true; |
|
| 1579 | + } elseif (isset($_REQUEST['msg'])) { |
|
| 1580 | + $confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
|
| 1581 | + } else { |
|
| 1582 | + $confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']; |
|
| 1583 | + } |
|
| 1517 | 1584 | |
| 1518 | 1585 | fatal_lang_error('post_already_deleted', false, array($confirm_url)); |
| 1519 | 1586 | } |
@@ -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 a handling function for all things post moderation. |
@@ -39,8 +40,9 @@ discard block |
||
| 39 | 40 | ); |
| 40 | 41 | |
| 41 | 42 | // Pick something valid... |
| 42 | - if (!isset($_REQUEST['sa']) || !isset($subActions[$_REQUEST['sa']])) |
|
| 43 | - $_REQUEST['sa'] = 'replies'; |
|
| 43 | + if (!isset($_REQUEST['sa']) || !isset($subActions[$_REQUEST['sa']])) { |
|
| 44 | + $_REQUEST['sa'] = 'replies'; |
|
| 45 | + } |
|
| 44 | 46 | |
| 45 | 47 | call_integration_hook('integrate_post_moderation', array(&$subActions)); |
| 46 | 48 | |
@@ -68,13 +70,15 @@ discard block |
||
| 68 | 70 | $approve_boards = $approve_boards == array(0) ? $filter_board : array_intersect($approve_boards, $filter_board); |
| 69 | 71 | } |
| 70 | 72 | |
| 71 | - if ($approve_boards == array(0)) |
|
| 72 | - $approve_query = ''; |
|
| 73 | - elseif (!empty($approve_boards)) |
|
| 74 | - $approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')'; |
|
| 73 | + if ($approve_boards == array(0)) { |
|
| 74 | + $approve_query = ''; |
|
| 75 | + } elseif (!empty($approve_boards)) { |
|
| 76 | + $approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')'; |
|
| 77 | + } |
|
| 75 | 78 | // Nada, zip, etc... |
| 76 | - else |
|
| 77 | - $approve_query = ' AND 1=0'; |
|
| 79 | + else { |
|
| 80 | + $approve_query = ' AND 1=0'; |
|
| 81 | + } |
|
| 78 | 82 | |
| 79 | 83 | // We also need to know where we can delete topics and/or replies to. |
| 80 | 84 | if ($context['current_view'] == 'topics') |
@@ -82,8 +86,7 @@ discard block |
||
| 82 | 86 | $delete_own_boards = boardsAllowedTo('remove_own'); |
| 83 | 87 | $delete_any_boards = boardsAllowedTo('remove_any'); |
| 84 | 88 | $delete_own_replies = array(); |
| 85 | - } |
|
| 86 | - else |
|
| 89 | + } else |
|
| 87 | 90 | { |
| 88 | 91 | $delete_own_boards = boardsAllowedTo('delete_own'); |
| 89 | 92 | $delete_any_boards = boardsAllowedTo('delete_any'); |
@@ -92,21 +95,25 @@ discard block |
||
| 92 | 95 | |
| 93 | 96 | $toAction = array(); |
| 94 | 97 | // Check if we have something to do? |
| 95 | - if (isset($_GET['approve'])) |
|
| 96 | - $toAction[] = (int) $_GET['approve']; |
|
| 98 | + if (isset($_GET['approve'])) { |
|
| 99 | + $toAction[] = (int) $_GET['approve']; |
|
| 100 | + } |
|
| 97 | 101 | // Just a deletion? |
| 98 | - elseif (isset($_GET['delete'])) |
|
| 99 | - $toAction[] = (int) $_GET['delete']; |
|
| 102 | + elseif (isset($_GET['delete'])) { |
|
| 103 | + $toAction[] = (int) $_GET['delete']; |
|
| 104 | + } |
|
| 100 | 105 | // Lots of approvals? |
| 101 | - elseif (isset($_POST['item'])) |
|
| 102 | - foreach ($_POST['item'] as $item) |
|
| 106 | + elseif (isset($_POST['item'])) { |
|
| 107 | + foreach ($_POST['item'] as $item) |
|
| 103 | 108 | $toAction[] = (int) $item; |
| 109 | + } |
|
| 104 | 110 | |
| 105 | 111 | // What are we actually doing. |
| 106 | - if (isset($_GET['approve']) || (isset($_POST['do']) && $_POST['do'] == 'approve')) |
|
| 107 | - $curAction = 'approve'; |
|
| 108 | - elseif (isset($_GET['delete']) || (isset($_POST['do']) && $_POST['do'] == 'delete')) |
|
| 109 | - $curAction = 'delete'; |
|
| 112 | + if (isset($_GET['approve']) || (isset($_POST['do']) && $_POST['do'] == 'approve')) { |
|
| 113 | + $curAction = 'approve'; |
|
| 114 | + } elseif (isset($_GET['delete']) || (isset($_POST['do']) && $_POST['do'] == 'delete')) { |
|
| 115 | + $curAction = 'delete'; |
|
| 116 | + } |
|
| 110 | 117 | |
| 111 | 118 | // Right, so we have something to do? |
| 112 | 119 | if (!empty($toAction) && isset($curAction)) |
@@ -135,8 +142,9 @@ discard block |
||
| 135 | 142 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 136 | 143 | { |
| 137 | 144 | // If it's not within what our view is ignore it... |
| 138 | - if (($row['id_msg'] == $row['id_first_msg'] && $context['current_view'] != 'topics') || ($row['id_msg'] != $row['id_first_msg'] && $context['current_view'] != 'replies')) |
|
| 139 | - continue; |
|
| 145 | + if (($row['id_msg'] == $row['id_first_msg'] && $context['current_view'] != 'topics') || ($row['id_msg'] != $row['id_first_msg'] && $context['current_view'] != 'replies')) { |
|
| 146 | + continue; |
|
| 147 | + } |
|
| 140 | 148 | |
| 141 | 149 | $can_add = false; |
| 142 | 150 | // If we're approving this is simple. |
@@ -148,18 +156,22 @@ discard block |
||
| 148 | 156 | elseif ($curAction == 'delete') |
| 149 | 157 | { |
| 150 | 158 | // Own post is easy! |
| 151 | - if ($row['id_member'] == $user_info['id'] && ($delete_own_boards == array(0) || in_array($row['id_board'], $delete_own_boards))) |
|
| 152 | - $can_add = true; |
|
| 159 | + if ($row['id_member'] == $user_info['id'] && ($delete_own_boards == array(0) || in_array($row['id_board'], $delete_own_boards))) { |
|
| 160 | + $can_add = true; |
|
| 161 | + } |
|
| 153 | 162 | // Is it a reply to their own topic? |
| 154 | - elseif ($row['id_member'] == $row['id_member_started'] && $row['id_msg'] != $row['id_first_msg'] && ($delete_own_replies == array(0) || in_array($row['id_board'], $delete_own_replies))) |
|
| 155 | - $can_add = true; |
|
| 163 | + elseif ($row['id_member'] == $row['id_member_started'] && $row['id_msg'] != $row['id_first_msg'] && ($delete_own_replies == array(0) || in_array($row['id_board'], $delete_own_replies))) { |
|
| 164 | + $can_add = true; |
|
| 165 | + } |
|
| 156 | 166 | // Someone elses? |
| 157 | - elseif ($row['id_member'] != $user_info['id'] && ($delete_any_boards == array(0) || in_array($row['id_board'], $delete_any_boards))) |
|
| 158 | - $can_add = true; |
|
| 167 | + elseif ($row['id_member'] != $user_info['id'] && ($delete_any_boards == array(0) || in_array($row['id_board'], $delete_any_boards))) { |
|
| 168 | + $can_add = true; |
|
| 169 | + } |
|
| 159 | 170 | } |
| 160 | 171 | |
| 161 | - if ($can_add) |
|
| 162 | - $anItem = $context['current_view'] == 'topics' ? $row['id_topic'] : $row['id_msg']; |
|
| 172 | + if ($can_add) { |
|
| 173 | + $anItem = $context['current_view'] == 'topics' ? $row['id_topic'] : $row['id_msg']; |
|
| 174 | + } |
|
| 163 | 175 | $toAction[] = $anItem; |
| 164 | 176 | |
| 165 | 177 | // All clear. What have we got now, what, what? |
@@ -177,8 +189,7 @@ discard block |
||
| 177 | 189 | if ($curAction == 'approve') |
| 178 | 190 | { |
| 179 | 191 | approveMessages ($toAction, $details, $context['current_view']); |
| 180 | - } |
|
| 181 | - else |
|
| 192 | + } else |
|
| 182 | 193 | { |
| 183 | 194 | removeMessages ($toAction, $details, $context['current_view']); |
| 184 | 195 | } |
@@ -265,16 +276,19 @@ discard block |
||
| 265 | 276 | for ($i = 1; $row = $smcFunc['db_fetch_assoc']($request); $i++) |
| 266 | 277 | { |
| 267 | 278 | // Can delete is complicated, let's solve it first... is it their own post? |
| 268 | - if ($row['id_member'] == $user_info['id'] && ($delete_own_boards == array(0) || in_array($row['id_board'], $delete_own_boards))) |
|
| 269 | - $can_delete = true; |
|
| 279 | + if ($row['id_member'] == $user_info['id'] && ($delete_own_boards == array(0) || in_array($row['id_board'], $delete_own_boards))) { |
|
| 280 | + $can_delete = true; |
|
| 281 | + } |
|
| 270 | 282 | // Is it a reply to their own topic? |
| 271 | - elseif ($row['id_member'] == $row['id_member_started'] && $row['id_msg'] != $row['id_first_msg'] && ($delete_own_replies == array(0) || in_array($row['id_board'], $delete_own_replies))) |
|
| 272 | - $can_delete = true; |
|
| 283 | + elseif ($row['id_member'] == $row['id_member_started'] && $row['id_msg'] != $row['id_first_msg'] && ($delete_own_replies == array(0) || in_array($row['id_board'], $delete_own_replies))) { |
|
| 284 | + $can_delete = true; |
|
| 285 | + } |
|
| 273 | 286 | // Someone elses? |
| 274 | - elseif ($row['id_member'] != $user_info['id'] && ($delete_any_boards == array(0) || in_array($row['id_board'], $delete_any_boards))) |
|
| 275 | - $can_delete = true; |
|
| 276 | - else |
|
| 277 | - $can_delete = false; |
|
| 287 | + elseif ($row['id_member'] != $user_info['id'] && ($delete_any_boards == array(0) || in_array($row['id_board'], $delete_any_boards))) { |
|
| 288 | + $can_delete = true; |
|
| 289 | + } else { |
|
| 290 | + $can_delete = false; |
|
| 291 | + } |
|
| 278 | 292 | |
| 279 | 293 | $context['unapproved_items'][] = array( |
| 280 | 294 | 'id' => $row['id_msg'], |
@@ -323,28 +337,31 @@ discard block |
||
| 323 | 337 | // Once again, permissions are king! |
| 324 | 338 | $approve_boards = boardsAllowedTo('approve_posts'); |
| 325 | 339 | |
| 326 | - if ($approve_boards == array(0)) |
|
| 327 | - $approve_query = ''; |
|
| 328 | - elseif (!empty($approve_boards)) |
|
| 329 | - $approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')'; |
|
| 330 | - else |
|
| 331 | - $approve_query = ' AND 1=0'; |
|
| 340 | + if ($approve_boards == array(0)) { |
|
| 341 | + $approve_query = ''; |
|
| 342 | + } elseif (!empty($approve_boards)) { |
|
| 343 | + $approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')'; |
|
| 344 | + } else { |
|
| 345 | + $approve_query = ' AND 1=0'; |
|
| 346 | + } |
|
| 332 | 347 | |
| 333 | 348 | // Get together the array of things to act on, if any. |
| 334 | 349 | $attachments = array(); |
| 335 | - if (isset($_GET['approve'])) |
|
| 336 | - $attachments[] = (int) $_GET['approve']; |
|
| 337 | - elseif (isset($_GET['delete'])) |
|
| 338 | - $attachments[] = (int) $_GET['delete']; |
|
| 339 | - elseif (isset($_POST['item'])) |
|
| 340 | - foreach ($_POST['item'] as $item) |
|
| 350 | + if (isset($_GET['approve'])) { |
|
| 351 | + $attachments[] = (int) $_GET['approve']; |
|
| 352 | + } elseif (isset($_GET['delete'])) { |
|
| 353 | + $attachments[] = (int) $_GET['delete']; |
|
| 354 | + } elseif (isset($_POST['item'])) { |
|
| 355 | + foreach ($_POST['item'] as $item) |
|
| 341 | 356 | $attachments[] = (int) $item; |
| 357 | + } |
|
| 342 | 358 | |
| 343 | 359 | // Are we approving or deleting? |
| 344 | - if (isset($_GET['approve']) || (isset($_POST['do']) && $_POST['do'] == 'approve')) |
|
| 345 | - $curAction = 'approve'; |
|
| 346 | - elseif (isset($_GET['delete']) || (isset($_POST['do']) && $_POST['do'] == 'delete')) |
|
| 347 | - $curAction = 'delete'; |
|
| 360 | + if (isset($_GET['approve']) || (isset($_POST['do']) && $_POST['do'] == 'approve')) { |
|
| 361 | + $curAction = 'approve'; |
|
| 362 | + } elseif (isset($_GET['delete']) || (isset($_POST['do']) && $_POST['do'] == 'delete')) { |
|
| 363 | + $curAction = 'delete'; |
|
| 364 | + } |
|
| 348 | 365 | |
| 349 | 366 | // Something to do, let's do it! |
| 350 | 367 | if (!empty($attachments) && isset($curAction)) |
@@ -372,17 +389,19 @@ discard block |
||
| 372 | 389 | ) |
| 373 | 390 | ); |
| 374 | 391 | $attachments = array(); |
| 375 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 376 | - $attachments[] = $row['id_attach']; |
|
| 392 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 393 | + $attachments[] = $row['id_attach']; |
|
| 394 | + } |
|
| 377 | 395 | $smcFunc['db_free_result']($request); |
| 378 | 396 | |
| 379 | 397 | // Assuming it wasn't all like, proper illegal, we can do the approving. |
| 380 | 398 | if (!empty($attachments)) |
| 381 | 399 | { |
| 382 | - if ($curAction == 'approve') |
|
| 383 | - ApproveAttachments($attachments); |
|
| 384 | - else |
|
| 385 | - removeAttachments(array('id_attach' => $attachments, 'do_logging' => true)); |
|
| 400 | + if ($curAction == 'approve') { |
|
| 401 | + ApproveAttachments($attachments); |
|
| 402 | + } else { |
|
| 403 | + removeAttachments(array('id_attach' => $attachments, 'do_logging' => true)); |
|
| 404 | + } |
|
| 386 | 405 | } |
| 387 | 406 | } |
| 388 | 407 | |
@@ -682,15 +701,16 @@ discard block |
||
| 682 | 701 | { |
| 683 | 702 | approveTopics($topic, !$approved); |
| 684 | 703 | |
| 685 | - if ($starter != $user_info['id']) |
|
| 686 | - logAction(($approved ? 'un' : '') . 'approve_topic', array('topic' => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board)); |
|
| 687 | - } |
|
| 688 | - else |
|
| 704 | + if ($starter != $user_info['id']) { |
|
| 705 | + logAction(($approved ? 'un' : '') . 'approve_topic', array('topic' => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board)); |
|
| 706 | + } |
|
| 707 | + } else |
|
| 689 | 708 | { |
| 690 | 709 | approvePosts($_REQUEST['msg'], !$approved); |
| 691 | 710 | |
| 692 | - if ($poster != $user_info['id']) |
|
| 693 | - logAction(($approved ? 'un' : '') . 'approve', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board)); |
|
| 711 | + if ($poster != $user_info['id']) { |
|
| 712 | + logAction(($approved ? 'un' : '') . 'approve', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board)); |
|
| 713 | + } |
|
| 694 | 714 | } |
| 695 | 715 | |
| 696 | 716 | redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg']. '#msg' . $_REQUEST['msg']); |
@@ -716,8 +736,7 @@ discard block |
||
| 716 | 736 | { |
| 717 | 737 | logAction('approve_topic', array('topic' => $topic, 'subject' => $messageDetails[$topic]['subject'], 'member' => $messageDetails[$topic]['member'], 'board' => $messageDetails[$topic]['board'])); |
| 718 | 738 | } |
| 719 | - } |
|
| 720 | - else |
|
| 739 | + } else |
|
| 721 | 740 | { |
| 722 | 741 | approvePosts($messages); |
| 723 | 742 | // and tell the world about it again |
@@ -745,8 +764,9 @@ discard block |
||
| 745 | 764 | ) |
| 746 | 765 | ); |
| 747 | 766 | $msgs = array(); |
| 748 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 749 | - $msgs[] = $row[0]; |
|
| 767 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 768 | + $msgs[] = $row[0]; |
|
| 769 | + } |
|
| 750 | 770 | $smcFunc['db_free_result']($request); |
| 751 | 771 | |
| 752 | 772 | if (!empty($msgs)) |
@@ -765,8 +785,9 @@ discard block |
||
| 765 | 785 | ) |
| 766 | 786 | ); |
| 767 | 787 | $attaches = array(); |
| 768 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 769 | - $attaches[] = $row[0]; |
|
| 788 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 789 | + $attaches[] = $row[0]; |
|
| 790 | + } |
|
| 770 | 791 | $smcFunc['db_free_result']($request); |
| 771 | 792 | |
| 772 | 793 | if (!empty($attaches)) |
@@ -794,12 +815,12 @@ discard block |
||
| 794 | 815 | { |
| 795 | 816 | removeTopics($messages); |
| 796 | 817 | // and tell the world about it |
| 797 | - foreach ($messages as $topic) |
|
| 798 | - // Note, only log topic ID in native form if it's not gone forever. |
|
| 818 | + foreach ($messages as $topic) { |
|
| 819 | + // Note, only log topic ID in native form if it's not gone forever. |
|
| 799 | 820 | logAction('remove', array( |
| 800 | 821 | (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $messageDetails[$topic]['board'] ? 'topic' : 'old_topic_id') => $topic, 'subject' => $messageDetails[$topic]['subject'], 'member' => $messageDetails[$topic]['member'], 'board' => $messageDetails[$topic]['board'])); |
| 801 | - } |
|
| 802 | - else |
|
| 822 | + } |
|
| 823 | + } else |
|
| 803 | 824 | { |
| 804 | 825 | foreach ($messages as $post) |
| 805 | 826 | { |