@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Entry point for the moderation center. |
@@ -26,8 +27,9 @@ discard block |
||
| 26 | 27 | global $smcFunc, $txt, $context, $scripturl, $modSettings, $user_info, $sourcedir, $options; |
| 27 | 28 | |
| 28 | 29 | // Don't run this twice... and don't conflict with the admin bar. |
| 29 | - if (isset($context['admin_area'])) |
|
| 30 | - return; |
|
| 30 | + if (isset($context['admin_area'])) { |
|
| 31 | + return; |
|
| 32 | + } |
|
| 31 | 33 | |
| 32 | 34 | $context['can_moderate_boards'] = $user_info['mod_cache']['bq'] != '0=1'; |
| 33 | 35 | $context['can_moderate_groups'] = $user_info['mod_cache']['gq'] != '0=1'; |
@@ -35,8 +37,9 @@ discard block |
||
| 35 | 37 | $context['can_moderate_users'] = allowedTo('moderate_forum'); |
| 36 | 38 | |
| 37 | 39 | // Everyone using this area must be allowed here! |
| 38 | - if (!$context['can_moderate_boards'] && !$context['can_moderate_groups'] && !$context['can_moderate_approvals'] && !$context['can_moderate_users']) |
|
| 39 | - isAllowedTo('access_mod_center'); |
|
| 40 | + if (!$context['can_moderate_boards'] && !$context['can_moderate_groups'] && !$context['can_moderate_approvals'] && !$context['can_moderate_users']) { |
|
| 41 | + isAllowedTo('access_mod_center'); |
|
| 42 | + } |
|
| 40 | 43 | |
| 41 | 44 | // We're gonna want a menu of some kind. |
| 42 | 45 | require_once($sourcedir . '/Subs-Menu.php'); |
@@ -195,8 +198,9 @@ discard block |
||
| 195 | 198 | unset($moderation_areas); |
| 196 | 199 | |
| 197 | 200 | // We got something - didn't we? DIDN'T WE! |
| 198 | - if ($mod_include_data == false) |
|
| 199 | - fatal_lang_error('no_access', false); |
|
| 201 | + if ($mod_include_data == false) { |
|
| 202 | + fatal_lang_error('no_access', false); |
|
| 203 | + } |
|
| 200 | 204 | |
| 201 | 205 | // Retain the ID information in case required by a subaction. |
| 202 | 206 | $context['moderation_menu_id'] = $context['max_menu_id']; |
@@ -219,22 +223,25 @@ discard block |
||
| 219 | 223 | 'url' => $scripturl . '?action=moderate', |
| 220 | 224 | 'name' => $txt['moderation_center'], |
| 221 | 225 | ); |
| 222 | - if (isset($mod_include_data['current_area']) && $mod_include_data['current_area'] != 'index') |
|
| 223 | - $context['linktree'][] = array( |
|
| 226 | + if (isset($mod_include_data['current_area']) && $mod_include_data['current_area'] != 'index') { |
|
| 227 | + $context['linktree'][] = array( |
|
| 224 | 228 | 'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'], |
| 225 | 229 | 'name' => $mod_include_data['label'], |
| 226 | 230 | ); |
| 227 | - if (!empty($mod_include_data['current_subsection']) && $mod_include_data['subsections'][$mod_include_data['current_subsection']][0] != $mod_include_data['label']) |
|
| 228 | - $context['linktree'][] = array( |
|
| 231 | + } |
|
| 232 | + if (!empty($mod_include_data['current_subsection']) && $mod_include_data['subsections'][$mod_include_data['current_subsection']][0] != $mod_include_data['label']) { |
|
| 233 | + $context['linktree'][] = array( |
|
| 229 | 234 | 'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'] . ';sa=' . $mod_include_data['current_subsection'], |
| 230 | 235 | 'name' => $mod_include_data['subsections'][$mod_include_data['current_subsection']][0], |
| 231 | 236 | ); |
| 237 | + } |
|
| 232 | 238 | |
| 233 | 239 | // Now - finally - the bit before the encore - the main performance of course! |
| 234 | 240 | if (!$dont_call) |
| 235 | 241 | { |
| 236 | - if (isset($mod_include_data['file'])) |
|
| 237 | - require_once($sourcedir . '/' . $mod_include_data['file']); |
|
| 242 | + if (isset($mod_include_data['file'])) { |
|
| 243 | + require_once($sourcedir . '/' . $mod_include_data['file']); |
|
| 244 | + } |
|
| 238 | 245 | |
| 239 | 246 | call_helper($mod_include_data['function']); |
| 240 | 247 | } |
@@ -259,8 +266,9 @@ discard block |
||
| 259 | 266 | // Load what blocks the user actually can see... |
| 260 | 267 | $valid_blocks = array(); |
| 261 | 268 | |
| 262 | - if ($context['can_moderate_groups']) |
|
| 263 | - $valid_blocks['g'] = 'GroupRequests'; |
|
| 269 | + if ($context['can_moderate_groups']) { |
|
| 270 | + $valid_blocks['g'] = 'GroupRequests'; |
|
| 271 | + } |
|
| 264 | 272 | if ($context['can_moderate_boards']) |
| 265 | 273 | { |
| 266 | 274 | $valid_blocks['r'] = 'ReportedPosts'; |
@@ -269,8 +277,9 @@ discard block |
||
| 269 | 277 | if ($context['can_moderate_users']) |
| 270 | 278 | { |
| 271 | 279 | // This falls under the category of moderating users as well... |
| 272 | - if (!$context['can_moderate_boards']) |
|
| 273 | - $valid_blocks['w'] = 'WatchedUsers'; |
|
| 280 | + if (!$context['can_moderate_boards']) { |
|
| 281 | + $valid_blocks['w'] = 'WatchedUsers'; |
|
| 282 | + } |
|
| 274 | 283 | |
| 275 | 284 | $valid_blocks['rm'] = 'ReportedMembers'; |
| 276 | 285 | } |
@@ -281,8 +290,9 @@ discard block |
||
| 281 | 290 | foreach ($valid_blocks as $k => $block) |
| 282 | 291 | { |
| 283 | 292 | $block = 'ModBlock' . $block; |
| 284 | - if (function_exists($block)) |
|
| 285 | - $context['mod_blocks'][] = $block(); |
|
| 293 | + if (function_exists($block)) { |
|
| 294 | + $context['mod_blocks'][] = $block(); |
|
| 295 | + } |
|
| 286 | 296 | } |
| 287 | 297 | |
| 288 | 298 | $context['admin_prefs'] = !empty($options['admin_preferences']) ? $smcFunc['json_decode']($options['admin_preferences'], true) : array(); |
@@ -309,8 +319,9 @@ discard block |
||
| 309 | 319 | ) |
| 310 | 320 | ); |
| 311 | 321 | $watched_users = array(); |
| 312 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 313 | - $watched_users[] = $row; |
|
| 322 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 323 | + $watched_users[] = $row; |
|
| 324 | + } |
|
| 314 | 325 | $smcFunc['db_free_result']($request); |
| 315 | 326 | |
| 316 | 327 | cache_put_data('recent_user_watches', $watched_users, 240); |
@@ -402,8 +413,9 @@ discard block |
||
| 402 | 413 | $note_owner = $smcFunc['db_num_rows']($get_owner); |
| 403 | 414 | $smcFunc['db_free_result']($get_owner); |
| 404 | 415 | |
| 405 | - if (empty($note_owner)) |
|
| 406 | - fatal_lang_error('mc_notes_delete_own', false); |
|
| 416 | + if (empty($note_owner)) { |
|
| 417 | + fatal_lang_error('mc_notes_delete_own', false); |
|
| 418 | + } |
|
| 407 | 419 | } |
| 408 | 420 | |
| 409 | 421 | // Lets delete it. |
@@ -460,12 +472,14 @@ discard block |
||
| 460 | 472 | ) |
| 461 | 473 | ); |
| 462 | 474 | $moderator_notes = array(); |
| 463 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 464 | - $moderator_notes[] = $row; |
|
| 475 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 476 | + $moderator_notes[] = $row; |
|
| 477 | + } |
|
| 465 | 478 | $smcFunc['db_free_result']($request); |
| 466 | 479 | |
| 467 | - if ($offset == 0) |
|
| 468 | - cache_put_data('moderator_notes', $moderator_notes, 240); |
|
| 480 | + if ($offset == 0) { |
|
| 481 | + cache_put_data('moderator_notes', $moderator_notes, 240); |
|
| 482 | + } |
|
| 469 | 483 | } |
| 470 | 484 | |
| 471 | 485 | // Lets construct a page index. |
@@ -504,8 +518,9 @@ discard block |
||
| 504 | 518 | // Got the info already? |
| 505 | 519 | $cachekey = md5($smcFunc['json_encode']($user_info['mod_cache']['bq'])); |
| 506 | 520 | $context['reported_posts'] = array(); |
| 507 | - if ($user_info['mod_cache']['bq'] == '0=1') |
|
| 508 | - return 'reported_posts_block'; |
|
| 521 | + if ($user_info['mod_cache']['bq'] == '0=1') { |
|
| 522 | + return 'reported_posts_block'; |
|
| 523 | + } |
|
| 509 | 524 | |
| 510 | 525 | if (($reported_posts = cache_get_data('reported_posts_' . $cachekey, 90)) === null) |
| 511 | 526 | { |
@@ -529,8 +544,9 @@ discard block |
||
| 529 | 544 | ) |
| 530 | 545 | ); |
| 531 | 546 | $reported_posts = array(); |
| 532 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 533 | - $reported_posts[] = $row; |
|
| 547 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 548 | + $reported_posts[] = $row; |
|
| 549 | + } |
|
| 534 | 550 | $smcFunc['db_free_result']($request); |
| 535 | 551 | |
| 536 | 552 | // Cache it. |
@@ -568,8 +584,9 @@ discard block |
||
| 568 | 584 | |
| 569 | 585 | $context['group_requests'] = array(); |
| 570 | 586 | // Make sure they can even moderate someone! |
| 571 | - if ($user_info['mod_cache']['gq'] == '0=1') |
|
| 572 | - return 'group_requests_block'; |
|
| 587 | + if ($user_info['mod_cache']['gq'] == '0=1') { |
|
| 588 | + return 'group_requests_block'; |
|
| 589 | + } |
|
| 573 | 590 | |
| 574 | 591 | // What requests are outstanding? |
| 575 | 592 | $request = $smcFunc['db_query']('', ' |
@@ -618,8 +635,9 @@ discard block |
||
| 618 | 635 | // Got the info already? |
| 619 | 636 | $cachekey = md5($smcFunc['json_encode']((int) allowedTo('moderate_forum'))); |
| 620 | 637 | $context['reported_users'] = array(); |
| 621 | - if (!allowedTo('moderate_forum')) |
|
| 622 | - return 'reported_users_block'; |
|
| 638 | + if (!allowedTo('moderate_forum')) { |
|
| 639 | + return 'reported_users_block'; |
|
| 640 | + } |
|
| 623 | 641 | |
| 624 | 642 | if (($reported_users = cache_get_data('reported_users_' . $cachekey, 90)) === null) |
| 625 | 643 | { |
@@ -642,8 +660,9 @@ discard block |
||
| 642 | 660 | ) |
| 643 | 661 | ); |
| 644 | 662 | $reported_users = array(); |
| 645 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 646 | - $reported_users[] = $row; |
|
| 663 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 664 | + $reported_users[] = $row; |
|
| 665 | + } |
|
| 647 | 666 | $smcFunc['db_free_result']($request); |
| 648 | 667 | |
| 649 | 668 | // Cache it. |
@@ -742,15 +761,15 @@ discard block |
||
| 742 | 761 | // Time to update. |
| 743 | 762 | updateSettings(array('last_mod_report_action' => time())); |
| 744 | 763 | recountOpenReports('members'); |
| 745 | - } |
|
| 746 | - elseif (isset($_POST['close']) && isset($_POST['close_selected'])) |
|
| 764 | + } elseif (isset($_POST['close']) && isset($_POST['close_selected'])) |
|
| 747 | 765 | { |
| 748 | 766 | checkSession(); |
| 749 | 767 | |
| 750 | 768 | // All the ones to update... |
| 751 | 769 | $toClose = array(); |
| 752 | - foreach ($_POST['close'] as $rid) |
|
| 753 | - $toClose[] = (int) $rid; |
|
| 770 | + foreach ($_POST['close'] as $rid) { |
|
| 771 | + $toClose[] = (int) $rid; |
|
| 772 | + } |
|
| 754 | 773 | |
| 755 | 774 | if (!empty($toClose)) |
| 756 | 775 | { |
@@ -903,8 +922,9 @@ discard block |
||
| 903 | 922 | global $context, $user_info; |
| 904 | 923 | |
| 905 | 924 | // You need to be allowed to moderate groups... |
| 906 | - if ($user_info['mod_cache']['gq'] == '0=1') |
|
| 907 | - isAllowedTo('manage_membergroups'); |
|
| 925 | + if ($user_info['mod_cache']['gq'] == '0=1') { |
|
| 926 | + isAllowedTo('manage_membergroups'); |
|
| 927 | + } |
|
| 908 | 928 | |
| 909 | 929 | // Load the group templates. |
| 910 | 930 | loadTemplate('ModerationCenter'); |
@@ -915,8 +935,9 @@ discard block |
||
| 915 | 935 | 'view' => 'ViewGroups', |
| 916 | 936 | ); |
| 917 | 937 | |
| 918 | - if (!isset($_GET['sa']) || !isset($subActions[$_GET['sa']])) |
|
| 919 | - $_GET['sa'] = 'view'; |
|
| 938 | + if (!isset($_GET['sa']) || !isset($subActions[$_GET['sa']])) { |
|
| 939 | + $_GET['sa'] = 'view'; |
|
| 940 | + } |
|
| 920 | 941 | $context['sub_action'] = $_GET['sa']; |
| 921 | 942 | |
| 922 | 943 | // Call the relevant function. |
@@ -946,8 +967,9 @@ discard block |
||
| 946 | 967 | 'id_notice' => $id_notice, |
| 947 | 968 | ) |
| 948 | 969 | ); |
| 949 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 950 | - fatal_lang_error('no_access', false); |
|
| 970 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 971 | + fatal_lang_error('no_access', false); |
|
| 972 | + } |
|
| 951 | 973 | list ($context['notice_body'], $context['notice_subject']) = $smcFunc['db_fetch_row']($request); |
| 952 | 974 | $smcFunc['db_free_result']($request); |
| 953 | 975 | |
@@ -984,18 +1006,20 @@ discard block |
||
| 984 | 1006 | checkSession(!is_array($_REQUEST['delete']) ? 'get' : 'post'); |
| 985 | 1007 | |
| 986 | 1008 | $toDelete = array(); |
| 987 | - if (!is_array($_REQUEST['delete'])) |
|
| 988 | - $toDelete[] = (int) $_REQUEST['delete']; |
|
| 989 | - else |
|
| 990 | - foreach ($_REQUEST['delete'] as $did) |
|
| 1009 | + if (!is_array($_REQUEST['delete'])) { |
|
| 1010 | + $toDelete[] = (int) $_REQUEST['delete']; |
|
| 1011 | + } else { |
|
| 1012 | + foreach ($_REQUEST['delete'] as $did) |
|
| 991 | 1013 | $toDelete[] = (int) $did; |
| 1014 | + } |
|
| 992 | 1015 | |
| 993 | 1016 | if (!empty($toDelete)) |
| 994 | 1017 | { |
| 995 | 1018 | require_once($sourcedir . '/RemoveTopic.php'); |
| 996 | 1019 | // If they don't have permission we'll let it error - either way no chance of a security slip here! |
| 997 | - foreach ($toDelete as $did) |
|
| 998 | - removeMessage($did); |
|
| 1020 | + foreach ($toDelete as $did) { |
|
| 1021 | + removeMessage($did); |
|
| 1022 | + } |
|
| 999 | 1023 | } |
| 1000 | 1024 | } |
| 1001 | 1025 | |
@@ -1004,20 +1028,21 @@ discard block |
||
| 1004 | 1028 | { |
| 1005 | 1029 | $approve_query = ''; |
| 1006 | 1030 | $delete_boards = array(); |
| 1007 | - } |
|
| 1008 | - else |
|
| 1031 | + } else |
|
| 1009 | 1032 | { |
| 1010 | 1033 | // Still obey permissions! |
| 1011 | 1034 | $approve_boards = boardsAllowedTo('approve_posts'); |
| 1012 | 1035 | $delete_boards = boardsAllowedTo('delete_any'); |
| 1013 | 1036 | |
| 1014 | - if ($approve_boards == array(0)) |
|
| 1015 | - $approve_query = ''; |
|
| 1016 | - elseif (!empty($approve_boards)) |
|
| 1017 | - $approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')'; |
|
| 1037 | + if ($approve_boards == array(0)) { |
|
| 1038 | + $approve_query = ''; |
|
| 1039 | + } elseif (!empty($approve_boards)) { |
|
| 1040 | + $approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')'; |
|
| 1041 | + } |
|
| 1018 | 1042 | // Nada, zip, etc... |
| 1019 | - else |
|
| 1020 | - $approve_query = ' AND 1=0'; |
|
| 1043 | + else { |
|
| 1044 | + $approve_query = ' AND 1=0'; |
|
| 1045 | + } |
|
| 1021 | 1046 | } |
| 1022 | 1047 | |
| 1023 | 1048 | require_once($sourcedir . '/Subs-List.php'); |
@@ -1116,10 +1141,11 @@ discard block |
||
| 1116 | 1141 | 'data' => array( |
| 1117 | 1142 | 'function' => function($member) use ($scripturl) |
| 1118 | 1143 | { |
| 1119 | - if ($member['last_post_id']) |
|
| 1120 | - return '<a href="' . $scripturl . '?msg=' . $member['last_post_id'] . '">' . $member['last_post'] . '</a>'; |
|
| 1121 | - else |
|
| 1122 | - return $member['last_post']; |
|
| 1144 | + if ($member['last_post_id']) { |
|
| 1145 | + return '<a href="' . $scripturl . '?msg=' . $member['last_post_id'] . '">' . $member['last_post'] . '</a>'; |
|
| 1146 | + } else { |
|
| 1147 | + return $member['last_post']; |
|
| 1148 | + } |
|
| 1123 | 1149 | }, |
| 1124 | 1150 | ), |
| 1125 | 1151 | ), |
@@ -1247,8 +1273,9 @@ discard block |
||
| 1247 | 1273 | ) |
| 1248 | 1274 | ); |
| 1249 | 1275 | $latest_posts = array(); |
| 1250 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1251 | - $latest_posts[$row['id_member']] = $row['last_post_id']; |
|
| 1276 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1277 | + $latest_posts[$row['id_member']] = $row['last_post_id']; |
|
| 1278 | + } |
|
| 1252 | 1279 | |
| 1253 | 1280 | if (!empty($latest_posts)) |
| 1254 | 1281 | { |
@@ -1439,15 +1466,17 @@ discard block |
||
| 1439 | 1466 | // Setup the direction stuff... |
| 1440 | 1467 | $context['order'] = isset($_REQUEST['sort']) && isset($sort_types[$_REQUEST['sort']]) ? $_REQUEST['sort'] : 'member'; |
| 1441 | 1468 | |
| 1442 | - if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search'])) |
|
| 1443 | - $search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search']; |
|
| 1444 | - else |
|
| 1445 | - $search_params_string = $search_params['string']; |
|
| 1469 | + if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search'])) { |
|
| 1470 | + $search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search']; |
|
| 1471 | + } else { |
|
| 1472 | + $search_params_string = $search_params['string']; |
|
| 1473 | + } |
|
| 1446 | 1474 | |
| 1447 | - if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']])) |
|
| 1448 | - $search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member'); |
|
| 1449 | - else |
|
| 1450 | - $search_params_type = $search_params['type']; |
|
| 1475 | + if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']])) { |
|
| 1476 | + $search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member'); |
|
| 1477 | + } else { |
|
| 1478 | + $search_params_type = $search_params['type']; |
|
| 1479 | + } |
|
| 1451 | 1480 | |
| 1452 | 1481 | $search_params = array( |
| 1453 | 1482 | 'string' => $search_params_string, |
@@ -1530,9 +1559,10 @@ discard block |
||
| 1530 | 1559 | ' . $rowData['reason'] . ' |
| 1531 | 1560 | </div>'; |
| 1532 | 1561 | |
| 1533 | - if (!empty($rowData['id_notice'])) |
|
| 1534 | - $output .= ' |
|
| 1562 | + if (!empty($rowData['id_notice'])) { |
|
| 1563 | + $output .= ' |
|
| 1535 | 1564 | <a href="' . $scripturl . '?action=moderate;area=notice;nid=' . $rowData['id_notice'] . '" onclick="window.open(this.href, \'\', \'scrollbars=yes,resizable=yes,width=400,height=250\');return false;" target="_blank" rel="noopener" title="' . $txt['profile_warning_previous_notice'] . '"><span class="generic_icons filter centericon"></span></a>'; |
| 1565 | + } |
|
| 1536 | 1566 | return $output; |
| 1537 | 1567 | }, |
| 1538 | 1568 | ), |
@@ -1650,9 +1680,9 @@ discard block |
||
| 1650 | 1680 | global $smcFunc, $modSettings, $context, $txt, $scripturl, $sourcedir, $user_info; |
| 1651 | 1681 | |
| 1652 | 1682 | // Submitting a new one? |
| 1653 | - if (isset($_POST['add'])) |
|
| 1654 | - return ModifyWarningTemplate(); |
|
| 1655 | - elseif (isset($_POST['delete']) && !empty($_POST['deltpl'])) |
|
| 1683 | + if (isset($_POST['add'])) { |
|
| 1684 | + return ModifyWarningTemplate(); |
|
| 1685 | + } elseif (isset($_POST['delete']) && !empty($_POST['deltpl'])) |
|
| 1656 | 1686 | { |
| 1657 | 1687 | checkSession(); |
| 1658 | 1688 | validateToken('mod-wt'); |
@@ -1671,8 +1701,9 @@ discard block |
||
| 1671 | 1701 | 'current_member' => $user_info['id'], |
| 1672 | 1702 | ) |
| 1673 | 1703 | ); |
| 1674 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1675 | - logAction('delete_warn_template', array('template' => $row['recipient_name'])); |
|
| 1704 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1705 | + logAction('delete_warn_template', array('template' => $row['recipient_name'])); |
|
| 1706 | + } |
|
| 1676 | 1707 | $smcFunc['db_free_result']($request); |
| 1677 | 1708 | |
| 1678 | 1709 | // Do the deletes. |
@@ -1963,16 +1994,18 @@ discard block |
||
| 1963 | 1994 | ); |
| 1964 | 1995 | |
| 1965 | 1996 | // If it wasn't visible and now is they've effectively added it. |
| 1966 | - if ($context['template_data']['personal'] && !$recipient_id) |
|
| 1967 | - logAction('add_warn_template', array('template' => $_POST['template_title'])); |
|
| 1997 | + if ($context['template_data']['personal'] && !$recipient_id) { |
|
| 1998 | + logAction('add_warn_template', array('template' => $_POST['template_title'])); |
|
| 1999 | + } |
|
| 1968 | 2000 | // Conversely if they made it personal it's a delete. |
| 1969 | - elseif (!$context['template_data']['personal'] && $recipient_id) |
|
| 1970 | - logAction('delete_warn_template', array('template' => $_POST['template_title'])); |
|
| 2001 | + elseif (!$context['template_data']['personal'] && $recipient_id) { |
|
| 2002 | + logAction('delete_warn_template', array('template' => $_POST['template_title'])); |
|
| 2003 | + } |
|
| 1971 | 2004 | // Otherwise just an edit. |
| 1972 | - else |
|
| 1973 | - logAction('modify_warn_template', array('template' => $_POST['template_title'])); |
|
| 1974 | - } |
|
| 1975 | - else |
|
| 2005 | + else { |
|
| 2006 | + logAction('modify_warn_template', array('template' => $_POST['template_title'])); |
|
| 2007 | + } |
|
| 2008 | + } else |
|
| 1976 | 2009 | { |
| 1977 | 2010 | $smcFunc['db_insert']('', |
| 1978 | 2011 | '{db_prefix}log_comments', |
@@ -1992,17 +2025,18 @@ discard block |
||
| 1992 | 2025 | |
| 1993 | 2026 | // Get out of town... |
| 1994 | 2027 | redirectexit('action=moderate;area=warnings;sa=templates'); |
| 1995 | - } |
|
| 1996 | - else |
|
| 2028 | + } else |
|
| 1997 | 2029 | { |
| 1998 | 2030 | $context['warning_errors'] = array(); |
| 1999 | 2031 | $context['template_data']['title'] = !empty($_POST['template_title']) ? $_POST['template_title'] : ''; |
| 2000 | 2032 | $context['template_data']['body'] = !empty($_POST['template_body']) ? $_POST['template_body'] : $txt['mc_warning_template_body_default']; |
| 2001 | 2033 | $context['template_data']['personal'] = !empty($_POST['make_personal']); |
| 2002 | - if (empty($_POST['template_title'])) |
|
| 2003 | - $context['warning_errors'][] = $txt['mc_warning_template_error_no_title']; |
|
| 2004 | - if (empty($_POST['template_body'])) |
|
| 2005 | - $context['warning_errors'][] = $txt['mc_warning_template_error_no_body']; |
|
| 2034 | + if (empty($_POST['template_title'])) { |
|
| 2035 | + $context['warning_errors'][] = $txt['mc_warning_template_error_no_title']; |
|
| 2036 | + } |
|
| 2037 | + if (empty($_POST['template_body'])) { |
|
| 2038 | + $context['warning_errors'][] = $txt['mc_warning_template_error_no_body']; |
|
| 2039 | + } |
|
| 2006 | 2040 | } |
| 2007 | 2041 | } |
| 2008 | 2042 | |
@@ -2047,8 +2081,9 @@ discard block |
||
| 2047 | 2081 | // Now check other options! |
| 2048 | 2082 | $pref_binary = 0; |
| 2049 | 2083 | |
| 2050 | - if ($context['can_moderate_approvals'] && !empty($_POST['mod_notify_approval'])) |
|
| 2051 | - $pref_binary |= 4; |
|
| 2084 | + if ($context['can_moderate_approvals'] && !empty($_POST['mod_notify_approval'])) { |
|
| 2085 | + $pref_binary |= 4; |
|
| 2086 | + } |
|
| 2052 | 2087 | |
| 2053 | 2088 | // Put it all together. |
| 2054 | 2089 | $mod_prefs = '0||' . $pref_binary; |
@@ -2072,9 +2107,10 @@ discard block |
||
| 2072 | 2107 | unset($_SESSION['moderate_time']); |
| 2073 | 2108 | |
| 2074 | 2109 | // Clean any moderator tokens as well. |
| 2075 | - foreach ($_SESSION['token'] as $key => $token) |
|
| 2076 | - if (strpos($key, '-mod') !== false) |
|
| 2110 | + foreach ($_SESSION['token'] as $key => $token) { |
|
| 2111 | + if (strpos($key, '-mod') !== false) |
|
| 2077 | 2112 | unset($_SESSION['token'][$key]); |
| 2113 | + } |
|
| 2078 | 2114 | |
| 2079 | 2115 | redirectexit(); |
| 2080 | 2116 | } |
@@ -17,8 +17,9 @@ discard block |
||
| 17 | 17 | * @version 2.1 Beta 4 |
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | -if (!defined('SMF')) |
|
| 20 | +if (!defined('SMF')) { |
|
| 21 | 21 | die('No direct access...'); |
| 22 | +} |
|
| 22 | 23 | |
| 23 | 24 | /** |
| 24 | 25 | * Attempt to start the session, unless it already has been. |
@@ -38,8 +39,9 @@ discard block |
||
| 38 | 39 | { |
| 39 | 40 | $parsed_url = parse_url($boardurl); |
| 40 | 41 | |
| 41 | - if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
| 42 | - @ini_set('session.cookie_domain', '.' . $parts[1]); |
|
| 42 | + if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
| 43 | + @ini_set('session.cookie_domain', '.' . $parts[1]); |
|
| 44 | + } |
|
| 43 | 45 | } |
| 44 | 46 | // @todo Set the session cookie path? |
| 45 | 47 | |
@@ -47,8 +49,9 @@ discard block |
||
| 47 | 49 | if ((ini_get('session.auto_start') == 1 && !empty($modSettings['databaseSession_enable'])) || session_id() == '') |
| 48 | 50 | { |
| 49 | 51 | // Attempt to end the already-started session. |
| 50 | - if (ini_get('session.auto_start') == 1) |
|
| 51 | - session_write_close(); |
|
| 52 | + if (ini_get('session.auto_start') == 1) { |
|
| 53 | + session_write_close(); |
|
| 54 | + } |
|
| 52 | 55 | |
| 53 | 56 | // This is here to stop people from using bad junky PHPSESSIDs. |
| 54 | 57 | if (isset($_REQUEST[session_name()]) && preg_match('~^[A-Za-z0-9,-]{16,64}$~', $_REQUEST[session_name()]) == 0 && !isset($_COOKIE[session_name()])) |
@@ -63,23 +66,26 @@ discard block |
||
| 63 | 66 | if (!empty($modSettings['databaseSession_enable'])) |
| 64 | 67 | { |
| 65 | 68 | @ini_set('session.serialize_handler', 'php_serialize'); |
| 66 | - if (ini_get('session.serialize_handler') != 'php_serialize') |
|
| 67 | - @ini_set('session.serialize_handler', 'php'); |
|
| 69 | + if (ini_get('session.serialize_handler') != 'php_serialize') { |
|
| 70 | + @ini_set('session.serialize_handler', 'php'); |
|
| 71 | + } |
|
| 68 | 72 | session_set_save_handler('sessionOpen', 'sessionClose', 'sessionRead', 'sessionWrite', 'sessionDestroy', 'sessionGC'); |
| 69 | 73 | @ini_set('session.gc_probability', '1'); |
| 74 | + } elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) { |
|
| 75 | + @ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60)); |
|
| 70 | 76 | } |
| 71 | - elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) |
|
| 72 | - @ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60)); |
|
| 73 | 77 | |
| 74 | 78 | // Use cache setting sessions? |
| 75 | - if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') |
|
| 76 | - call_integration_hook('integrate_session_handlers'); |
|
| 79 | + if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') { |
|
| 80 | + call_integration_hook('integrate_session_handlers'); |
|
| 81 | + } |
|
| 77 | 82 | |
| 78 | 83 | session_start(); |
| 79 | 84 | |
| 80 | 85 | // Change it so the cache settings are a little looser than default. |
| 81 | - if (!empty($modSettings['databaseSession_loose'])) |
|
| 82 | - header('Cache-Control: private'); |
|
| 86 | + if (!empty($modSettings['databaseSession_loose'])) { |
|
| 87 | + header('Cache-Control: private'); |
|
| 88 | + } |
|
| 83 | 89 | } |
| 84 | 90 | |
| 85 | 91 | // Set the randomly generated code. |
@@ -125,8 +131,9 @@ discard block |
||
| 125 | 131 | { |
| 126 | 132 | global $smcFunc; |
| 127 | 133 | |
| 128 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
| 129 | - return ''; |
|
| 134 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
| 135 | + return ''; |
|
| 136 | + } |
|
| 130 | 137 | |
| 131 | 138 | // Look for it in the database. |
| 132 | 139 | $result = $smcFunc['db_query']('', ' |
@@ -155,8 +162,9 @@ discard block |
||
| 155 | 162 | { |
| 156 | 163 | global $smcFunc; |
| 157 | 164 | |
| 158 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
| 159 | - return false; |
|
| 165 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
| 166 | + return false; |
|
| 167 | + } |
|
| 160 | 168 | |
| 161 | 169 | // First try to update an existing row... |
| 162 | 170 | $smcFunc['db_query']('', ' |
@@ -171,13 +179,14 @@ discard block |
||
| 171 | 179 | ); |
| 172 | 180 | |
| 173 | 181 | // If that didn't work, try inserting a new one. |
| 174 | - if ($smcFunc['db_affected_rows']() == 0) |
|
| 175 | - $smcFunc['db_insert']('ignore', |
|
| 182 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
| 183 | + $smcFunc['db_insert']('ignore', |
|
| 176 | 184 | '{db_prefix}sessions', |
| 177 | 185 | array('session_id' => 'string', 'data' => 'string', 'last_update' => 'int'), |
| 178 | 186 | array($session_id, $data, time()), |
| 179 | 187 | array('session_id') |
| 180 | 188 | ); |
| 189 | + } |
|
| 181 | 190 | |
| 182 | 191 | return ($smcFunc['db_affected_rows']() == 0 ? false : true); |
| 183 | 192 | } |
@@ -192,8 +201,9 @@ discard block |
||
| 192 | 201 | { |
| 193 | 202 | global $smcFunc; |
| 194 | 203 | |
| 195 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
| 196 | - return false; |
|
| 204 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
| 205 | + return false; |
|
| 206 | + } |
|
| 197 | 207 | |
| 198 | 208 | // Just delete the row... |
| 199 | 209 | $smcFunc['db_query']('', ' |
@@ -219,8 +229,9 @@ discard block |
||
| 219 | 229 | global $modSettings, $smcFunc; |
| 220 | 230 | |
| 221 | 231 | // Just set to the default or lower? Ignore it for a higher value. (hopefully) |
| 222 | - if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) |
|
| 223 | - $max_lifetime = max($modSettings['databaseSession_lifetime'], 60); |
|
| 232 | + if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) { |
|
| 233 | + $max_lifetime = max($modSettings['databaseSession_lifetime'], 60); |
|
| 234 | + } |
|
| 224 | 235 | |
| 225 | 236 | // Clean up after yerself ;). |
| 226 | 237 | $smcFunc['db_query']('', ' |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 4 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('No direct access...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * View a summary. |
@@ -23,8 +24,9 @@ discard block |
||
| 23 | 24 | global $context, $memberContext, $txt, $modSettings, $user_profile, $sourcedir, $scripturl, $smcFunc; |
| 24 | 25 | |
| 25 | 26 | // Attempt to load the member's profile data. |
| 26 | - if (!loadMemberContext($memID) || !isset($memberContext[$memID])) |
|
| 27 | - fatal_lang_error('not_a_user', false, 404); |
|
| 27 | + if (!loadMemberContext($memID) || !isset($memberContext[$memID])) { |
|
| 28 | + fatal_lang_error('not_a_user', false, 404); |
|
| 29 | + } |
|
| 28 | 30 | |
| 29 | 31 | // Set up the stuff and load the user. |
| 30 | 32 | $context += array( |
@@ -49,19 +51,21 @@ discard block |
||
| 49 | 51 | |
| 50 | 52 | // See if they have broken any warning levels... |
| 51 | 53 | list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']); |
| 52 | - if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) |
|
| 53 | - $context['warning_status'] = $txt['profile_warning_is_muted']; |
|
| 54 | - elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) |
|
| 55 | - $context['warning_status'] = $txt['profile_warning_is_moderation']; |
|
| 56 | - elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) |
|
| 57 | - $context['warning_status'] = $txt['profile_warning_is_watch']; |
|
| 54 | + if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) { |
|
| 55 | + $context['warning_status'] = $txt['profile_warning_is_muted']; |
|
| 56 | + } elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) { |
|
| 57 | + $context['warning_status'] = $txt['profile_warning_is_moderation']; |
|
| 58 | + } elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) { |
|
| 59 | + $context['warning_status'] = $txt['profile_warning_is_watch']; |
|
| 60 | + } |
|
| 58 | 61 | |
| 59 | 62 | // They haven't even been registered for a full day!? |
| 60 | 63 | $days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24)); |
| 61 | - if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) |
|
| 62 | - $context['member']['posts_per_day'] = $txt['not_applicable']; |
|
| 63 | - else |
|
| 64 | - $context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3); |
|
| 64 | + if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) { |
|
| 65 | + $context['member']['posts_per_day'] = $txt['not_applicable']; |
|
| 66 | + } else { |
|
| 67 | + $context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3); |
|
| 68 | + } |
|
| 65 | 69 | |
| 66 | 70 | // Set the age... |
| 67 | 71 | if (empty($context['member']['birth_date']) || substr($context['member']['birth_date'], 0, 4) < 1002) |
@@ -70,8 +74,7 @@ discard block |
||
| 70 | 74 | 'age' => $txt['not_applicable'], |
| 71 | 75 | 'today_is_birthday' => false |
| 72 | 76 | ); |
| 73 | - } |
|
| 74 | - else |
|
| 77 | + } else |
|
| 75 | 78 | { |
| 76 | 79 | list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d'); |
| 77 | 80 | $datearray = getdate(forum_time()); |
@@ -84,15 +87,16 @@ discard block |
||
| 84 | 87 | if (allowedTo('moderate_forum')) |
| 85 | 88 | { |
| 86 | 89 | // Make sure it's a valid ip address; otherwise, don't bother... |
| 87 | - if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) |
|
| 88 | - $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']); |
|
| 89 | - else |
|
| 90 | - $context['member']['hostname'] = ''; |
|
| 90 | + if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) { |
|
| 91 | + $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']); |
|
| 92 | + } else { |
|
| 93 | + $context['member']['hostname'] = ''; |
|
| 94 | + } |
|
| 91 | 95 | |
| 92 | 96 | $context['can_see_ip'] = true; |
| 97 | + } else { |
|
| 98 | + $context['can_see_ip'] = false; |
|
| 93 | 99 | } |
| 94 | - else |
|
| 95 | - $context['can_see_ip'] = false; |
|
| 96 | 100 | |
| 97 | 101 | // Are they hidden? |
| 98 | 102 | $context['member']['is_hidden'] = empty($user_profile[$memID]['show_online']); |
@@ -103,8 +107,9 @@ discard block |
||
| 103 | 107 | include_once($sourcedir . '/Who.php'); |
| 104 | 108 | $action = determineActions($user_profile[$memID]['url']); |
| 105 | 109 | |
| 106 | - if ($action !== false) |
|
| 107 | - $context['member']['action'] = $action; |
|
| 110 | + if ($action !== false) { |
|
| 111 | + $context['member']['action'] = $action; |
|
| 112 | + } |
|
| 108 | 113 | } |
| 109 | 114 | |
| 110 | 115 | // If the user is awaiting activation, and the viewer has permission - setup some activation context messages. |
@@ -167,13 +172,15 @@ discard block |
||
| 167 | 172 | { |
| 168 | 173 | // Work out what restrictions we actually have. |
| 169 | 174 | $ban_restrictions = array(); |
| 170 | - foreach (array('access', 'login', 'post') as $type) |
|
| 171 | - if ($row['cannot_' . $type]) |
|
| 175 | + foreach (array('access', 'login', 'post') as $type) { |
|
| 176 | + if ($row['cannot_' . $type]) |
|
| 172 | 177 | $ban_restrictions[] = $txt['ban_type_' . $type]; |
| 178 | + } |
|
| 173 | 179 | |
| 174 | 180 | // No actual ban in place? |
| 175 | - if (empty($ban_restrictions)) |
|
| 176 | - continue; |
|
| 181 | + if (empty($ban_restrictions)) { |
|
| 182 | + continue; |
|
| 183 | + } |
|
| 177 | 184 | |
| 178 | 185 | // Prepare the link for context. |
| 179 | 186 | $ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>'); |
@@ -195,9 +202,10 @@ discard block |
||
| 195 | 202 | $context['print_custom_fields'] = array(); |
| 196 | 203 | |
| 197 | 204 | // Any custom profile fields? |
| 198 | - if (!empty($context['custom_fields'])) |
|
| 199 | - foreach ($context['custom_fields'] as $custom) |
|
| 205 | + if (!empty($context['custom_fields'])) { |
|
| 206 | + foreach ($context['custom_fields'] as $custom) |
|
| 200 | 207 | $context['print_custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom; |
| 208 | + } |
|
| 201 | 209 | |
| 202 | 210 | } |
| 203 | 211 | |
@@ -245,16 +253,18 @@ discard block |
||
| 245 | 253 | $row['extra'] = !empty($row['extra']) ? $smcFunc['json_decode']($row['extra'], true) : array(); |
| 246 | 254 | $alerts[$id_alert] = $row; |
| 247 | 255 | |
| 248 | - if (!empty($row['sender_id'])) |
|
| 249 | - $senders[] = $row['sender_id']; |
|
| 256 | + if (!empty($row['sender_id'])) { |
|
| 257 | + $senders[] = $row['sender_id']; |
|
| 258 | + } |
|
| 250 | 259 | } |
| 251 | 260 | $smcFunc['db_free_result']($request); |
| 252 | 261 | |
| 253 | 262 | if($withSender) |
| 254 | 263 | { |
| 255 | 264 | $senders = loadMemberData($senders); |
| 256 | - foreach ($senders as $member) |
|
| 257 | - loadMemberContext($member); |
|
| 265 | + foreach ($senders as $member) { |
|
| 266 | + loadMemberContext($member); |
|
| 267 | + } |
|
| 258 | 268 | } |
| 259 | 269 | |
| 260 | 270 | // Now go through and actually make with the text. |
@@ -269,12 +279,15 @@ discard block |
||
| 269 | 279 | $msgs = array(); |
| 270 | 280 | foreach ($alerts as $id_alert => $alert) |
| 271 | 281 | { |
| 272 | - if (isset($alert['extra']['board'])) |
|
| 273 | - $boards[$alert['extra']['board']] = $txt['board_na']; |
|
| 274 | - if (isset($alert['extra']['topic'])) |
|
| 275 | - $topics[$alert['extra']['topic']] = $txt['topic_na']; |
|
| 276 | - if ($alert['content_type'] == 'msg') |
|
| 277 | - $msgs[$alert['content_id']] = $txt['topic_na']; |
|
| 282 | + if (isset($alert['extra']['board'])) { |
|
| 283 | + $boards[$alert['extra']['board']] = $txt['board_na']; |
|
| 284 | + } |
|
| 285 | + if (isset($alert['extra']['topic'])) { |
|
| 286 | + $topics[$alert['extra']['topic']] = $txt['topic_na']; |
|
| 287 | + } |
|
| 288 | + if ($alert['content_type'] == 'msg') { |
|
| 289 | + $msgs[$alert['content_id']] = $txt['topic_na']; |
|
| 290 | + } |
|
| 278 | 291 | } |
| 279 | 292 | |
| 280 | 293 | // Having figured out what boards etc. there are, let's now get the names of them if we can see them. If not, there's already a fallback set up. |
@@ -289,8 +302,9 @@ discard block |
||
| 289 | 302 | 'boards' => array_keys($boards), |
| 290 | 303 | ) |
| 291 | 304 | ); |
| 292 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 293 | - $boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
| 305 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 306 | + $boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
| 307 | + } |
|
| 294 | 308 | } |
| 295 | 309 | if (!empty($topics)) |
| 296 | 310 | { |
@@ -305,8 +319,9 @@ discard block |
||
| 305 | 319 | 'topics' => array_keys($topics), |
| 306 | 320 | ) |
| 307 | 321 | ); |
| 308 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 309 | - $topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>'; |
|
| 322 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 323 | + $topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>'; |
|
| 324 | + } |
|
| 310 | 325 | } |
| 311 | 326 | if (!empty($msgs)) |
| 312 | 327 | { |
@@ -321,44 +336,51 @@ discard block |
||
| 321 | 336 | 'msgs' => array_keys($msgs), |
| 322 | 337 | ) |
| 323 | 338 | ); |
| 324 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 325 | - $msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>'; |
|
| 339 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 340 | + $msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>'; |
|
| 341 | + } |
|
| 326 | 342 | } |
| 327 | 343 | |
| 328 | 344 | // Now to go back through the alerts, reattach this extra information and then try to build the string out of it (if a hook didn't already) |
| 329 | 345 | foreach ($alerts as $id_alert => $alert) |
| 330 | 346 | { |
| 331 | - if (!empty($alert['text'])) |
|
| 332 | - continue; |
|
| 333 | - if (isset($alert['extra']['board'])) |
|
| 334 | - if ($boards[$alert['extra']['board']] == $txt['board_na']) |
|
| 347 | + if (!empty($alert['text'])) { |
|
| 348 | + continue; |
|
| 349 | + } |
|
| 350 | + if (isset($alert['extra']['board'])) { |
|
| 351 | + if ($boards[$alert['extra']['board']] == $txt['board_na']) |
|
| 335 | 352 | { |
| 336 | 353 | unset($alerts[$id_alert]); |
| 354 | + } |
|
| 337 | 355 | continue; |
| 356 | + } else { |
|
| 357 | + $alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']]; |
|
| 338 | 358 | } |
| 339 | - else |
|
| 340 | - $alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']]; |
|
| 341 | - if (isset($alert['extra']['topic'])) |
|
| 342 | - if ($alert['extra']['topic'] == $txt['topic_na']) |
|
| 359 | + if (isset($alert['extra']['topic'])) { |
|
| 360 | + if ($alert['extra']['topic'] == $txt['topic_na']) |
|
| 343 | 361 | { |
| 344 | 362 | unset($alerts[$id_alert]); |
| 363 | + } |
|
| 345 | 364 | continue; |
| 365 | + } else { |
|
| 366 | + $alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']]; |
|
| 346 | 367 | } |
| 347 | - else |
|
| 348 | - $alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']]; |
|
| 349 | - if ($alert['content_type'] == 'msg') |
|
| 350 | - if ($msgs[$alert['content_id']] == $txt['topic_na']) |
|
| 368 | + if ($alert['content_type'] == 'msg') { |
|
| 369 | + if ($msgs[$alert['content_id']] == $txt['topic_na']) |
|
| 351 | 370 | { |
| 352 | 371 | unset($alerts[$id_alert]); |
| 372 | + } |
|
| 353 | 373 | continue; |
| 354 | - } |
|
| 355 | - else |
|
| 356 | - $alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']]; |
|
| 357 | - if ($alert['content_type'] == 'profile') |
|
| 358 | - $alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>'; |
|
| 374 | + } else { |
|
| 375 | + $alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']]; |
|
| 376 | + } |
|
| 377 | + if ($alert['content_type'] == 'profile') { |
|
| 378 | + $alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>'; |
|
| 379 | + } |
|
| 359 | 380 | |
| 360 | - if (!empty($memberContext[$alert['sender_id']])) |
|
| 361 | - $alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']]; |
|
| 381 | + if (!empty($memberContext[$alert['sender_id']])) { |
|
| 382 | + $alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']]; |
|
| 383 | + } |
|
| 362 | 384 | |
| 363 | 385 | $string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action']; |
| 364 | 386 | if (isset($txt[$string])) |
@@ -446,11 +468,11 @@ discard block |
||
| 446 | 468 | checkSession('request'); |
| 447 | 469 | |
| 448 | 470 | // Call it! |
| 449 | - if ($action == 'remove') |
|
| 450 | - alert_delete($toMark, $memID); |
|
| 451 | - |
|
| 452 | - else |
|
| 453 | - alert_mark($memID, $toMark, $action == 'read' ? 1 : 0); |
|
| 471 | + if ($action == 'remove') { |
|
| 472 | + alert_delete($toMark, $memID); |
|
| 473 | + } else { |
|
| 474 | + alert_mark($memID, $toMark, $action == 'read' ? 1 : 0); |
|
| 475 | + } |
|
| 454 | 476 | |
| 455 | 477 | // Set a nice update message. |
| 456 | 478 | $_SESSION['update_message'] = true; |
@@ -500,23 +522,27 @@ discard block |
||
| 500 | 522 | ); |
| 501 | 523 | |
| 502 | 524 | // Set the page title |
| 503 | - if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title)) |
|
| 504 | - $context['page_title'] = $txt['show' . $title[$_GET['sa']]]; |
|
| 505 | - else |
|
| 506 | - $context['page_title'] = $txt['showPosts']; |
|
| 525 | + if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title)) { |
|
| 526 | + $context['page_title'] = $txt['show' . $title[$_GET['sa']]]; |
|
| 527 | + } else { |
|
| 528 | + $context['page_title'] = $txt['showPosts']; |
|
| 529 | + } |
|
| 507 | 530 | |
| 508 | 531 | $context['page_title'] .= ' - ' . $user_profile[$memID]['real_name']; |
| 509 | 532 | |
| 510 | 533 | // Is the load average too high to allow searching just now? |
| 511 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) |
|
| 512 | - fatal_lang_error('loadavg_show_posts_disabled', false); |
|
| 534 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) { |
|
| 535 | + fatal_lang_error('loadavg_show_posts_disabled', false); |
|
| 536 | + } |
|
| 513 | 537 | |
| 514 | 538 | // If we're specifically dealing with attachments use that function! |
| 515 | - if (isset($_GET['sa']) && $_GET['sa'] == 'attach') |
|
| 516 | - return showAttachments($memID); |
|
| 539 | + if (isset($_GET['sa']) && $_GET['sa'] == 'attach') { |
|
| 540 | + return showAttachments($memID); |
|
| 541 | + } |
|
| 517 | 542 | // Instead, if we're dealing with unwatched topics (and the feature is enabled) use that other function. |
| 518 | - elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics') |
|
| 519 | - return showUnwatched($memID); |
|
| 543 | + elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics') { |
|
| 544 | + return showUnwatched($memID); |
|
| 545 | + } |
|
| 520 | 546 | |
| 521 | 547 | // Are we just viewing topics? |
| 522 | 548 | $context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false; |
@@ -539,27 +565,30 @@ discard block |
||
| 539 | 565 | $smcFunc['db_free_result']($request); |
| 540 | 566 | |
| 541 | 567 | // Trying to remove a message that doesn't exist. |
| 542 | - if (empty($info)) |
|
| 543 | - redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); |
|
| 568 | + if (empty($info)) { |
|
| 569 | + redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); |
|
| 570 | + } |
|
| 544 | 571 | |
| 545 | 572 | // We can be lazy, since removeMessage() will check the permissions for us. |
| 546 | 573 | require_once($sourcedir . '/RemoveTopic.php'); |
| 547 | 574 | removeMessage((int) $_GET['delete']); |
| 548 | 575 | |
| 549 | 576 | // Add it to the mod log. |
| 550 | - if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) |
|
| 551 | - logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3])); |
|
| 577 | + if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) { |
|
| 578 | + logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3])); |
|
| 579 | + } |
|
| 552 | 580 | |
| 553 | 581 | // Back to... where we are now ;). |
| 554 | 582 | redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); |
| 555 | 583 | } |
| 556 | 584 | |
| 557 | 585 | // Default to 10. |
| 558 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
| 559 | - $_REQUEST['viewscount'] = '10'; |
|
| 586 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
| 587 | + $_REQUEST['viewscount'] = '10'; |
|
| 588 | + } |
|
| 560 | 589 | |
| 561 | - if ($context['is_topics']) |
|
| 562 | - $request = $smcFunc['db_query']('', ' |
|
| 590 | + if ($context['is_topics']) { |
|
| 591 | + $request = $smcFunc['db_query']('', ' |
|
| 563 | 592 | SELECT COUNT(*) |
| 564 | 593 | FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : ' |
| 565 | 594 | INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . ' |
@@ -572,8 +601,8 @@ discard block |
||
| 572 | 601 | 'board' => $board, |
| 573 | 602 | ) |
| 574 | 603 | ); |
| 575 | - else |
|
| 576 | - $request = $smcFunc['db_query']('', ' |
|
| 604 | + } else { |
|
| 605 | + $request = $smcFunc['db_query']('', ' |
|
| 577 | 606 | SELECT COUNT(*) |
| 578 | 607 | FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : ' |
| 579 | 608 | INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . ' |
@@ -586,6 +615,7 @@ discard block |
||
| 586 | 615 | 'board' => $board, |
| 587 | 616 | ) |
| 588 | 617 | ); |
| 618 | + } |
|
| 589 | 619 | list ($msgCount) = $smcFunc['db_fetch_row']($request); |
| 590 | 620 | $smcFunc['db_free_result']($request); |
| 591 | 621 | |
@@ -606,10 +636,11 @@ discard block |
||
| 606 | 636 | |
| 607 | 637 | $range_limit = ''; |
| 608 | 638 | |
| 609 | - if ($context['is_topics']) |
|
| 610 | - $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics']; |
|
| 611 | - else |
|
| 612 | - $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
|
| 639 | + if ($context['is_topics']) { |
|
| 640 | + $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics']; |
|
| 641 | + } else { |
|
| 642 | + $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
|
| 643 | + } |
|
| 613 | 644 | |
| 614 | 645 | $maxIndex = $maxPerPage; |
| 615 | 646 | |
@@ -635,9 +666,9 @@ discard block |
||
| 635 | 666 | { |
| 636 | 667 | $margin *= 5; |
| 637 | 668 | $range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin); |
| 669 | + } else { |
|
| 670 | + $range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin); |
|
| 638 | 671 | } |
| 639 | - else |
|
| 640 | - $range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin); |
|
| 641 | 672 | } |
| 642 | 673 | |
| 643 | 674 | // Find this user's posts. The left join on categories somehow makes this faster, weird as it looks. |
@@ -669,8 +700,7 @@ discard block |
||
| 669 | 700 | 'max' => $maxIndex, |
| 670 | 701 | ) |
| 671 | 702 | ); |
| 672 | - } |
|
| 673 | - else |
|
| 703 | + } else |
|
| 674 | 704 | { |
| 675 | 705 | $request = $smcFunc['db_query']('', ' |
| 676 | 706 | SELECT |
@@ -699,8 +729,9 @@ discard block |
||
| 699 | 729 | } |
| 700 | 730 | |
| 701 | 731 | // Make sure we quit this loop. |
| 702 | - if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped || $range_limit == '') |
|
| 703 | - break; |
|
| 732 | + if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped || $range_limit == '') { |
|
| 733 | + break; |
|
| 734 | + } |
|
| 704 | 735 | $looped = true; |
| 705 | 736 | $range_limit = ''; |
| 706 | 737 | } |
@@ -744,19 +775,21 @@ discard block |
||
| 744 | 775 | 'css_class' => $row['approved'] ? 'windowbg' : 'approvebg', |
| 745 | 776 | ); |
| 746 | 777 | |
| 747 | - if ($user_info['id'] == $row['id_member_started']) |
|
| 748 | - $board_ids['own'][$row['id_board']][] = $counter; |
|
| 778 | + if ($user_info['id'] == $row['id_member_started']) { |
|
| 779 | + $board_ids['own'][$row['id_board']][] = $counter; |
|
| 780 | + } |
|
| 749 | 781 | $board_ids['any'][$row['id_board']][] = $counter; |
| 750 | 782 | } |
| 751 | 783 | $smcFunc['db_free_result']($request); |
| 752 | 784 | |
| 753 | 785 | // All posts were retrieved in reverse order, get them right again. |
| 754 | - if ($reverse) |
|
| 755 | - $context['posts'] = array_reverse($context['posts'], true); |
|
| 786 | + if ($reverse) { |
|
| 787 | + $context['posts'] = array_reverse($context['posts'], true); |
|
| 788 | + } |
|
| 756 | 789 | |
| 757 | 790 | // These are all the permissions that are different from board to board.. |
| 758 | - if ($context['is_topics']) |
|
| 759 | - $permissions = array( |
|
| 791 | + if ($context['is_topics']) { |
|
| 792 | + $permissions = array( |
|
| 760 | 793 | 'own' => array( |
| 761 | 794 | 'post_reply_own' => 'can_reply', |
| 762 | 795 | ), |
@@ -764,8 +797,8 @@ discard block |
||
| 764 | 797 | 'post_reply_any' => 'can_reply', |
| 765 | 798 | ) |
| 766 | 799 | ); |
| 767 | - else |
|
| 768 | - $permissions = array( |
|
| 800 | + } else { |
|
| 801 | + $permissions = array( |
|
| 769 | 802 | 'own' => array( |
| 770 | 803 | 'post_reply_own' => 'can_reply', |
| 771 | 804 | 'delete_own' => 'can_delete', |
@@ -775,6 +808,7 @@ discard block |
||
| 775 | 808 | 'delete_any' => 'can_delete', |
| 776 | 809 | ) |
| 777 | 810 | ); |
| 811 | + } |
|
| 778 | 812 | |
| 779 | 813 | // For every permission in the own/any lists... |
| 780 | 814 | foreach ($permissions as $type => $list) |
@@ -785,19 +819,22 @@ discard block |
||
| 785 | 819 | $boards = boardsAllowedTo($permission); |
| 786 | 820 | |
| 787 | 821 | // Hmm, they can do it on all boards, can they? |
| 788 | - if (!empty($boards) && $boards[0] == 0) |
|
| 789 | - $boards = array_keys($board_ids[$type]); |
|
| 822 | + if (!empty($boards) && $boards[0] == 0) { |
|
| 823 | + $boards = array_keys($board_ids[$type]); |
|
| 824 | + } |
|
| 790 | 825 | |
| 791 | 826 | // Now go through each board they can do the permission on. |
| 792 | 827 | foreach ($boards as $board_id) |
| 793 | 828 | { |
| 794 | 829 | // There aren't any posts displayed from this board. |
| 795 | - if (!isset($board_ids[$type][$board_id])) |
|
| 796 | - continue; |
|
| 830 | + if (!isset($board_ids[$type][$board_id])) { |
|
| 831 | + continue; |
|
| 832 | + } |
|
| 797 | 833 | |
| 798 | 834 | // Set the permission to true ;). |
| 799 | - foreach ($board_ids[$type][$board_id] as $counter) |
|
| 800 | - $context['posts'][$counter][$allowed] = true; |
|
| 835 | + foreach ($board_ids[$type][$board_id] as $counter) { |
|
| 836 | + $context['posts'][$counter][$allowed] = true; |
|
| 837 | + } |
|
| 801 | 838 | } |
| 802 | 839 | } |
| 803 | 840 | } |
@@ -828,8 +865,9 @@ discard block |
||
| 828 | 865 | $boardsAllowed = boardsAllowedTo('view_attachments'); |
| 829 | 866 | |
| 830 | 867 | // Make sure we can't actually see anything... |
| 831 | - if (empty($boardsAllowed)) |
|
| 832 | - $boardsAllowed = array(-1); |
|
| 868 | + if (empty($boardsAllowed)) { |
|
| 869 | + $boardsAllowed = array(-1); |
|
| 870 | + } |
|
| 833 | 871 | |
| 834 | 872 | require_once($sourcedir . '/Subs-List.php'); |
| 835 | 873 | |
@@ -980,8 +1018,8 @@ discard block |
||
| 980 | 1018 | ) |
| 981 | 1019 | ); |
| 982 | 1020 | $attachments = array(); |
| 983 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 984 | - $attachments[] = array( |
|
| 1021 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1022 | + $attachments[] = array( |
|
| 985 | 1023 | 'id' => $row['id_attach'], |
| 986 | 1024 | 'filename' => $row['filename'], |
| 987 | 1025 | 'downloads' => $row['downloads'], |
@@ -993,6 +1031,7 @@ discard block |
||
| 993 | 1031 | 'board_name' => $row['name'], |
| 994 | 1032 | 'approved' => $row['approved'], |
| 995 | 1033 | ); |
| 1034 | + } |
|
| 996 | 1035 | |
| 997 | 1036 | $smcFunc['db_free_result']($request); |
| 998 | 1037 | |
@@ -1047,8 +1086,9 @@ discard block |
||
| 1047 | 1086 | global $txt, $user_info, $scripturl, $modSettings, $context, $sourcedir; |
| 1048 | 1087 | |
| 1049 | 1088 | // Only the owner can see the list (if the function is enabled of course) |
| 1050 | - if ($user_info['id'] != $memID) |
|
| 1051 | - return; |
|
| 1089 | + if ($user_info['id'] != $memID) { |
|
| 1090 | + return; |
|
| 1091 | + } |
|
| 1052 | 1092 | |
| 1053 | 1093 | require_once($sourcedir . '/Subs-List.php'); |
| 1054 | 1094 | |
@@ -1194,8 +1234,9 @@ discard block |
||
| 1194 | 1234 | ); |
| 1195 | 1235 | |
| 1196 | 1236 | $topics = array(); |
| 1197 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1198 | - $topics[] = $row['id_topic']; |
|
| 1237 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1238 | + $topics[] = $row['id_topic']; |
|
| 1239 | + } |
|
| 1199 | 1240 | |
| 1200 | 1241 | $smcFunc['db_free_result']($request); |
| 1201 | 1242 | |
@@ -1215,8 +1256,9 @@ discard block |
||
| 1215 | 1256 | 'topics' => $topics, |
| 1216 | 1257 | ) |
| 1217 | 1258 | ); |
| 1218 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1219 | - $topicsInfo[] = $row; |
|
| 1259 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1260 | + $topicsInfo[] = $row; |
|
| 1261 | + } |
|
| 1220 | 1262 | $smcFunc['db_free_result']($request); |
| 1221 | 1263 | } |
| 1222 | 1264 | |
@@ -1264,8 +1306,9 @@ discard block |
||
| 1264 | 1306 | $context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name']; |
| 1265 | 1307 | |
| 1266 | 1308 | // Is the load average too high to allow searching just now? |
| 1267 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) |
|
| 1268 | - fatal_lang_error('loadavg_userstats_disabled', false); |
|
| 1309 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) { |
|
| 1310 | + fatal_lang_error('loadavg_userstats_disabled', false); |
|
| 1311 | + } |
|
| 1269 | 1312 | |
| 1270 | 1313 | // General user statistics. |
| 1271 | 1314 | $timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400); |
@@ -1408,11 +1451,13 @@ discard block |
||
| 1408 | 1451 | } |
| 1409 | 1452 | $smcFunc['db_free_result']($result); |
| 1410 | 1453 | |
| 1411 | - if ($maxPosts > 0) |
|
| 1412 | - for ($hour = 0; $hour < 24; $hour++) |
|
| 1454 | + if ($maxPosts > 0) { |
|
| 1455 | + for ($hour = 0; |
|
| 1456 | + } |
|
| 1457 | + $hour < 24; $hour++) |
|
| 1413 | 1458 | { |
| 1414 | - if (!isset($context['posts_by_time'][$hour])) |
|
| 1415 | - $context['posts_by_time'][$hour] = array( |
|
| 1459 | + if (!isset($context['posts_by_time'][$hour])) { |
|
| 1460 | + $context['posts_by_time'][$hour] = array( |
|
| 1416 | 1461 | 'hour' => $hour, |
| 1417 | 1462 | 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)), |
| 1418 | 1463 | 'posts' => 0, |
@@ -1420,7 +1465,7 @@ discard block |
||
| 1420 | 1465 | 'relative_percent' => 0, |
| 1421 | 1466 | 'is_last' => $hour == 23, |
| 1422 | 1467 | ); |
| 1423 | - else |
|
| 1468 | + } else |
|
| 1424 | 1469 | { |
| 1425 | 1470 | $context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts); |
| 1426 | 1471 | $context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts); |
@@ -1453,8 +1498,9 @@ discard block |
||
| 1453 | 1498 | |
| 1454 | 1499 | foreach ($subActions as $sa => $action) |
| 1455 | 1500 | { |
| 1456 | - if (!allowedTo($action[2])) |
|
| 1457 | - unset($subActions[$sa]); |
|
| 1501 | + if (!allowedTo($action[2])) { |
|
| 1502 | + unset($subActions[$sa]); |
|
| 1503 | + } |
|
| 1458 | 1504 | } |
| 1459 | 1505 | |
| 1460 | 1506 | // Create the tabs for the template. |
@@ -1472,15 +1518,18 @@ discard block |
||
| 1472 | 1518 | ); |
| 1473 | 1519 | |
| 1474 | 1520 | // Moderation must be on to track edits. |
| 1475 | - if (empty($modSettings['userlog_enabled'])) |
|
| 1476 | - unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']); |
|
| 1521 | + if (empty($modSettings['userlog_enabled'])) { |
|
| 1522 | + unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']); |
|
| 1523 | + } |
|
| 1477 | 1524 | |
| 1478 | 1525 | // Group requests must be active to show it... |
| 1479 | - if (empty($modSettings['show_group_membership'])) |
|
| 1480 | - unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']); |
|
| 1526 | + if (empty($modSettings['show_group_membership'])) { |
|
| 1527 | + unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']); |
|
| 1528 | + } |
|
| 1481 | 1529 | |
| 1482 | - if (empty($subActions)) |
|
| 1483 | - fatal_lang_error('no_access', false); |
|
| 1530 | + if (empty($subActions)) { |
|
| 1531 | + fatal_lang_error('no_access', false); |
|
| 1532 | + } |
|
| 1484 | 1533 | |
| 1485 | 1534 | $keys = array_keys($subActions); |
| 1486 | 1535 | $default = array_shift($keys); |
@@ -1493,9 +1542,10 @@ discard block |
||
| 1493 | 1542 | $context['sub_template'] = $subActions[$context['tracking_area']][0]; |
| 1494 | 1543 | $call = call_helper($subActions[$context['tracking_area']][0], true); |
| 1495 | 1544 | |
| 1496 | - if (!empty($call)) |
|
| 1497 | - call_user_func($call, $memID); |
|
| 1498 | -} |
|
| 1545 | + if (!empty($call)) { |
|
| 1546 | + call_user_func($call, $memID); |
|
| 1547 | + } |
|
| 1548 | + } |
|
| 1499 | 1549 | |
| 1500 | 1550 | /** |
| 1501 | 1551 | * Handles tracking a user's activity |
@@ -1511,8 +1561,9 @@ discard block |
||
| 1511 | 1561 | isAllowedTo('moderate_forum'); |
| 1512 | 1562 | |
| 1513 | 1563 | $context['last_ip'] = $user_profile[$memID]['member_ip']; |
| 1514 | - if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) |
|
| 1515 | - $context['last_ip2'] = $user_profile[$memID]['member_ip2']; |
|
| 1564 | + if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) { |
|
| 1565 | + $context['last_ip2'] = $user_profile[$memID]['member_ip2']; |
|
| 1566 | + } |
|
| 1516 | 1567 | $context['member']['name'] = $user_profile[$memID]['real_name']; |
| 1517 | 1568 | |
| 1518 | 1569 | // Set the options for the list component. |
@@ -1679,8 +1730,9 @@ discard block |
||
| 1679 | 1730 | ) |
| 1680 | 1731 | ); |
| 1681 | 1732 | $message_members = array(); |
| 1682 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1683 | - $message_members[] = $row['id_member']; |
|
| 1733 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1734 | + $message_members[] = $row['id_member']; |
|
| 1735 | + } |
|
| 1684 | 1736 | $smcFunc['db_free_result']($request); |
| 1685 | 1737 | |
| 1686 | 1738 | // Fetch their names, cause of the GROUP BY doesn't like giving us that normally. |
@@ -1695,8 +1747,9 @@ discard block |
||
| 1695 | 1747 | 'ip_list' => $ips, |
| 1696 | 1748 | ) |
| 1697 | 1749 | ); |
| 1698 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1699 | - $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 1750 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1751 | + $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 1752 | + } |
|
| 1700 | 1753 | $smcFunc['db_free_result']($request); |
| 1701 | 1754 | } |
| 1702 | 1755 | |
@@ -1710,8 +1763,9 @@ discard block |
||
| 1710 | 1763 | 'ip_list' => $ips, |
| 1711 | 1764 | ) |
| 1712 | 1765 | ); |
| 1713 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1714 | - $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 1766 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1767 | + $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 1768 | + } |
|
| 1715 | 1769 | $smcFunc['db_free_result']($request); |
| 1716 | 1770 | } |
| 1717 | 1771 | } |
@@ -1771,8 +1825,8 @@ discard block |
||
| 1771 | 1825 | )) |
| 1772 | 1826 | ); |
| 1773 | 1827 | $error_messages = array(); |
| 1774 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1775 | - $error_messages[] = array( |
|
| 1828 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1829 | + $error_messages[] = array( |
|
| 1776 | 1830 | 'ip' => inet_dtop($row['ip']), |
| 1777 | 1831 | 'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'], |
| 1778 | 1832 | 'message' => strtr($row['message'], array('<span class="remove">' => '', '</span>' => '')), |
@@ -1780,6 +1834,7 @@ discard block |
||
| 1780 | 1834 | 'time' => timeformat($row['log_time']), |
| 1781 | 1835 | 'timestamp' => forum_time(true, $row['log_time']), |
| 1782 | 1836 | ); |
| 1837 | + } |
|
| 1783 | 1838 | $smcFunc['db_free_result']($request); |
| 1784 | 1839 | |
| 1785 | 1840 | return $error_messages; |
@@ -1842,8 +1897,8 @@ discard block |
||
| 1842 | 1897 | )) |
| 1843 | 1898 | ); |
| 1844 | 1899 | $messages = array(); |
| 1845 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1846 | - $messages[] = array( |
|
| 1900 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1901 | + $messages[] = array( |
|
| 1847 | 1902 | 'ip' => inet_dtop($row['poster_ip']), |
| 1848 | 1903 | 'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>', |
| 1849 | 1904 | 'board' => array( |
@@ -1856,6 +1911,7 @@ discard block |
||
| 1856 | 1911 | 'time' => timeformat($row['poster_time']), |
| 1857 | 1912 | 'timestamp' => forum_time(true, $row['poster_time']) |
| 1858 | 1913 | ); |
| 1914 | + } |
|
| 1859 | 1915 | $smcFunc['db_free_result']($request); |
| 1860 | 1916 | |
| 1861 | 1917 | return $messages; |
@@ -1882,19 +1938,20 @@ discard block |
||
| 1882 | 1938 | $context['sub_template'] = 'trackIP'; |
| 1883 | 1939 | $context['page_title'] = $txt['profile']; |
| 1884 | 1940 | $context['base_url'] = $scripturl . '?action=trackip'; |
| 1885 | - } |
|
| 1886 | - else |
|
| 1941 | + } else |
|
| 1887 | 1942 | { |
| 1888 | 1943 | $context['ip'] = $user_profile[$memID]['member_ip']; |
| 1889 | 1944 | $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID; |
| 1890 | 1945 | } |
| 1891 | 1946 | |
| 1892 | 1947 | // Searching? |
| 1893 | - if (isset($_REQUEST['searchip'])) |
|
| 1894 | - $context['ip'] = trim($_REQUEST['searchip']); |
|
| 1948 | + if (isset($_REQUEST['searchip'])) { |
|
| 1949 | + $context['ip'] = trim($_REQUEST['searchip']); |
|
| 1950 | + } |
|
| 1895 | 1951 | |
| 1896 | - if (isValidIP($context['ip']) === false) |
|
| 1897 | - fatal_lang_error('invalid_tracking_ip', false); |
|
| 1952 | + if (isValidIP($context['ip']) === false) { |
|
| 1953 | + fatal_lang_error('invalid_tracking_ip', false); |
|
| 1954 | + } |
|
| 1898 | 1955 | |
| 1899 | 1956 | //mysql didn't support like search with varbinary |
| 1900 | 1957 | //$ip_var = str_replace('*', '%', $context['ip']); |
@@ -1902,8 +1959,9 @@ discard block |
||
| 1902 | 1959 | $ip_var = $context['ip']; |
| 1903 | 1960 | $ip_string = '= {inet:ip_address}'; |
| 1904 | 1961 | |
| 1905 | - if (empty($context['tracking_area'])) |
|
| 1906 | - $context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip']; |
|
| 1962 | + if (empty($context['tracking_area'])) { |
|
| 1963 | + $context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip']; |
|
| 1964 | + } |
|
| 1907 | 1965 | |
| 1908 | 1966 | $request = $smcFunc['db_query']('', ' |
| 1909 | 1967 | SELECT id_member, real_name AS display_name, member_ip |
@@ -1914,8 +1972,9 @@ discard block |
||
| 1914 | 1972 | ) |
| 1915 | 1973 | ); |
| 1916 | 1974 | $context['ips'] = array(); |
| 1917 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1918 | - $context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>'; |
|
| 1975 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1976 | + $context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>'; |
|
| 1977 | + } |
|
| 1919 | 1978 | $smcFunc['db_free_result']($request); |
| 1920 | 1979 | |
| 1921 | 1980 | ksort($context['ips']); |
@@ -2144,8 +2203,9 @@ discard block |
||
| 2144 | 2203 | foreach ($context['whois_servers'] as $whois) |
| 2145 | 2204 | { |
| 2146 | 2205 | // Strip off the "decimal point" and anything following... |
| 2147 | - if (in_array((int) $context['ip'], $whois['range'])) |
|
| 2148 | - $context['auto_whois_server'] = $whois; |
|
| 2206 | + if (in_array((int) $context['ip'], $whois['range'])) { |
|
| 2207 | + $context['auto_whois_server'] = $whois; |
|
| 2208 | + } |
|
| 2149 | 2209 | } |
| 2150 | 2210 | } |
| 2151 | 2211 | } |
@@ -2162,10 +2222,11 @@ discard block |
||
| 2162 | 2222 | // Gonna want this for the list. |
| 2163 | 2223 | require_once($sourcedir . '/Subs-List.php'); |
| 2164 | 2224 | |
| 2165 | - if ($memID == 0) |
|
| 2166 | - $context['base_url'] = $scripturl . '?action=trackip'; |
|
| 2167 | - else |
|
| 2168 | - $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID; |
|
| 2225 | + if ($memID == 0) { |
|
| 2226 | + $context['base_url'] = $scripturl . '?action=trackip'; |
|
| 2227 | + } else { |
|
| 2228 | + $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID; |
|
| 2229 | + } |
|
| 2169 | 2230 | |
| 2170 | 2231 | // Start with the user messages. |
| 2171 | 2232 | $listOptions = array( |
@@ -2275,12 +2336,13 @@ discard block |
||
| 2275 | 2336 | ) |
| 2276 | 2337 | ); |
| 2277 | 2338 | $logins = array(); |
| 2278 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2279 | - $logins[] = array( |
|
| 2339 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2340 | + $logins[] = array( |
|
| 2280 | 2341 | 'time' => timeformat($row['time']), |
| 2281 | 2342 | 'ip' => inet_dtop($row['ip']), |
| 2282 | 2343 | 'ip2' => inet_dtop($row['ip2']), |
| 2283 | 2344 | ); |
| 2345 | + } |
|
| 2284 | 2346 | $smcFunc['db_free_result']($request); |
| 2285 | 2347 | |
| 2286 | 2348 | return $logins; |
@@ -2305,11 +2367,12 @@ discard block |
||
| 2305 | 2367 | ) |
| 2306 | 2368 | ); |
| 2307 | 2369 | $context['custom_field_titles'] = array(); |
| 2308 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2309 | - $context['custom_field_titles']['customfield_' . $row['col_name']] = array( |
|
| 2370 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2371 | + $context['custom_field_titles']['customfield_' . $row['col_name']] = array( |
|
| 2310 | 2372 | 'title' => $row['field_name'], |
| 2311 | 2373 | 'parse_bbc' => $row['bbc'], |
| 2312 | 2374 | ); |
| 2375 | + } |
|
| 2313 | 2376 | $smcFunc['db_free_result']($request); |
| 2314 | 2377 | |
| 2315 | 2378 | // Set the options for the error lists. |
@@ -2448,19 +2511,22 @@ discard block |
||
| 2448 | 2511 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2449 | 2512 | { |
| 2450 | 2513 | $extra = $smcFunc['json_decode']($row['extra'], true); |
| 2451 | - if (!empty($extra['applicator'])) |
|
| 2452 | - $members[] = $extra['applicator']; |
|
| 2514 | + if (!empty($extra['applicator'])) { |
|
| 2515 | + $members[] = $extra['applicator']; |
|
| 2516 | + } |
|
| 2453 | 2517 | |
| 2454 | 2518 | // Work out what the name of the action is. |
| 2455 | - if (isset($txt['trackEdit_action_' . $row['action']])) |
|
| 2456 | - $action_text = $txt['trackEdit_action_' . $row['action']]; |
|
| 2457 | - elseif (isset($txt[$row['action']])) |
|
| 2458 | - $action_text = $txt[$row['action']]; |
|
| 2519 | + if (isset($txt['trackEdit_action_' . $row['action']])) { |
|
| 2520 | + $action_text = $txt['trackEdit_action_' . $row['action']]; |
|
| 2521 | + } elseif (isset($txt[$row['action']])) { |
|
| 2522 | + $action_text = $txt[$row['action']]; |
|
| 2523 | + } |
|
| 2459 | 2524 | // Custom field? |
| 2460 | - elseif (isset($context['custom_field_titles'][$row['action']])) |
|
| 2461 | - $action_text = $context['custom_field_titles'][$row['action']]['title']; |
|
| 2462 | - else |
|
| 2463 | - $action_text = $row['action']; |
|
| 2525 | + elseif (isset($context['custom_field_titles'][$row['action']])) { |
|
| 2526 | + $action_text = $context['custom_field_titles'][$row['action']]['title']; |
|
| 2527 | + } else { |
|
| 2528 | + $action_text = $row['action']; |
|
| 2529 | + } |
|
| 2464 | 2530 | |
| 2465 | 2531 | // Parse BBC? |
| 2466 | 2532 | $parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false; |
@@ -2492,13 +2558,15 @@ discard block |
||
| 2492 | 2558 | ) |
| 2493 | 2559 | ); |
| 2494 | 2560 | $members = array(); |
| 2495 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2496 | - $members[$row['id_member']] = $row['real_name']; |
|
| 2561 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2562 | + $members[$row['id_member']] = $row['real_name']; |
|
| 2563 | + } |
|
| 2497 | 2564 | $smcFunc['db_free_result']($request); |
| 2498 | 2565 | |
| 2499 | - foreach ($edits as $key => $value) |
|
| 2500 | - if (isset($members[$value['id_member']])) |
|
| 2566 | + foreach ($edits as $key => $value) { |
|
| 2567 | + if (isset($members[$value['id_member']])) |
|
| 2501 | 2568 | $edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>'; |
| 2569 | + } |
|
| 2502 | 2570 | } |
| 2503 | 2571 | |
| 2504 | 2572 | return $edits; |
@@ -2699,10 +2767,11 @@ discard block |
||
| 2699 | 2767 | $context['board'] = $board; |
| 2700 | 2768 | |
| 2701 | 2769 | // Determine which groups this user is in. |
| 2702 | - if (empty($user_profile[$memID]['additional_groups'])) |
|
| 2703 | - $curGroups = array(); |
|
| 2704 | - else |
|
| 2705 | - $curGroups = explode(',', $user_profile[$memID]['additional_groups']); |
|
| 2770 | + if (empty($user_profile[$memID]['additional_groups'])) { |
|
| 2771 | + $curGroups = array(); |
|
| 2772 | + } else { |
|
| 2773 | + $curGroups = explode(',', $user_profile[$memID]['additional_groups']); |
|
| 2774 | + } |
|
| 2706 | 2775 | $curGroups[] = $user_profile[$memID]['id_group']; |
| 2707 | 2776 | $curGroups[] = $user_profile[$memID]['id_post_group']; |
| 2708 | 2777 | |
@@ -2722,28 +2791,30 @@ discard block |
||
| 2722 | 2791 | $context['no_access_boards'] = array(); |
| 2723 | 2792 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2724 | 2793 | { |
| 2725 | - if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) |
|
| 2726 | - $context['no_access_boards'][] = array( |
|
| 2794 | + if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) { |
|
| 2795 | + $context['no_access_boards'][] = array( |
|
| 2727 | 2796 | 'id' => $row['id_board'], |
| 2728 | 2797 | 'name' => $row['name'], |
| 2729 | 2798 | 'is_last' => false, |
| 2730 | 2799 | ); |
| 2731 | - elseif ($row['id_profile'] != 1 || $row['is_mod']) |
|
| 2732 | - $context['boards'][$row['id_board']] = array( |
|
| 2800 | + } elseif ($row['id_profile'] != 1 || $row['is_mod']) { |
|
| 2801 | + $context['boards'][$row['id_board']] = array( |
|
| 2733 | 2802 | 'id' => $row['id_board'], |
| 2734 | 2803 | 'name' => $row['name'], |
| 2735 | 2804 | 'selected' => $board == $row['id_board'], |
| 2736 | 2805 | 'profile' => $row['id_profile'], |
| 2737 | 2806 | 'profile_name' => $context['profiles'][$row['id_profile']]['name'], |
| 2738 | 2807 | ); |
| 2808 | + } |
|
| 2739 | 2809 | } |
| 2740 | 2810 | $smcFunc['db_free_result']($request); |
| 2741 | 2811 | |
| 2742 | 2812 | require_once($sourcedir . '/Subs-Boards.php'); |
| 2743 | 2813 | sortBoards($context['boards']); |
| 2744 | 2814 | |
| 2745 | - if (!empty($context['no_access_boards'])) |
|
| 2746 | - $context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true; |
|
| 2815 | + if (!empty($context['no_access_boards'])) { |
|
| 2816 | + $context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true; |
|
| 2817 | + } |
|
| 2747 | 2818 | |
| 2748 | 2819 | $context['member']['permissions'] = array( |
| 2749 | 2820 | 'general' => array(), |
@@ -2752,8 +2823,9 @@ discard block |
||
| 2752 | 2823 | |
| 2753 | 2824 | // If you're an admin we know you can do everything, we might as well leave. |
| 2754 | 2825 | $context['member']['has_all_permissions'] = in_array(1, $curGroups); |
| 2755 | - if ($context['member']['has_all_permissions']) |
|
| 2756 | - return; |
|
| 2826 | + if ($context['member']['has_all_permissions']) { |
|
| 2827 | + return; |
|
| 2828 | + } |
|
| 2757 | 2829 | |
| 2758 | 2830 | $denied = array(); |
| 2759 | 2831 | |
@@ -2772,21 +2844,24 @@ discard block |
||
| 2772 | 2844 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 2773 | 2845 | { |
| 2774 | 2846 | // We don't know about this permission, it doesn't exist :P. |
| 2775 | - if (!isset($txt['permissionname_' . $row['permission']])) |
|
| 2776 | - continue; |
|
| 2847 | + if (!isset($txt['permissionname_' . $row['permission']])) { |
|
| 2848 | + continue; |
|
| 2849 | + } |
|
| 2777 | 2850 | |
| 2778 | - if (empty($row['add_deny'])) |
|
| 2779 | - $denied[] = $row['permission']; |
|
| 2851 | + if (empty($row['add_deny'])) { |
|
| 2852 | + $denied[] = $row['permission']; |
|
| 2853 | + } |
|
| 2780 | 2854 | |
| 2781 | 2855 | // Permissions that end with _own or _any consist of two parts. |
| 2782 | - if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) |
|
| 2783 | - $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']]; |
|
| 2784 | - else |
|
| 2785 | - $name = $txt['permissionname_' . $row['permission']]; |
|
| 2856 | + if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) { |
|
| 2857 | + $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']]; |
|
| 2858 | + } else { |
|
| 2859 | + $name = $txt['permissionname_' . $row['permission']]; |
|
| 2860 | + } |
|
| 2786 | 2861 | |
| 2787 | 2862 | // Add this permission if it doesn't exist yet. |
| 2788 | - if (!isset($context['member']['permissions']['general'][$row['permission']])) |
|
| 2789 | - $context['member']['permissions']['general'][$row['permission']] = array( |
|
| 2863 | + if (!isset($context['member']['permissions']['general'][$row['permission']])) { |
|
| 2864 | + $context['member']['permissions']['general'][$row['permission']] = array( |
|
| 2790 | 2865 | 'id' => $row['permission'], |
| 2791 | 2866 | 'groups' => array( |
| 2792 | 2867 | 'allowed' => array(), |
@@ -2796,6 +2871,7 @@ discard block |
||
| 2796 | 2871 | 'is_denied' => false, |
| 2797 | 2872 | 'is_global' => true, |
| 2798 | 2873 | ); |
| 2874 | + } |
|
| 2799 | 2875 | |
| 2800 | 2876 | // Add the membergroup to either the denied or the allowed groups. |
| 2801 | 2877 | $context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name']; |
@@ -2829,18 +2905,20 @@ discard block |
||
| 2829 | 2905 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2830 | 2906 | { |
| 2831 | 2907 | // We don't know about this permission, it doesn't exist :P. |
| 2832 | - if (!isset($txt['permissionname_' . $row['permission']])) |
|
| 2833 | - continue; |
|
| 2908 | + if (!isset($txt['permissionname_' . $row['permission']])) { |
|
| 2909 | + continue; |
|
| 2910 | + } |
|
| 2834 | 2911 | |
| 2835 | 2912 | // The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'. |
| 2836 | - if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) |
|
| 2837 | - $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']]; |
|
| 2838 | - else |
|
| 2839 | - $name = $txt['permissionname_' . $row['permission']]; |
|
| 2913 | + if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) { |
|
| 2914 | + $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']]; |
|
| 2915 | + } else { |
|
| 2916 | + $name = $txt['permissionname_' . $row['permission']]; |
|
| 2917 | + } |
|
| 2840 | 2918 | |
| 2841 | 2919 | // Create the structure for this permission. |
| 2842 | - if (!isset($context['member']['permissions']['board'][$row['permission']])) |
|
| 2843 | - $context['member']['permissions']['board'][$row['permission']] = array( |
|
| 2920 | + if (!isset($context['member']['permissions']['board'][$row['permission']])) { |
|
| 2921 | + $context['member']['permissions']['board'][$row['permission']] = array( |
|
| 2844 | 2922 | 'id' => $row['permission'], |
| 2845 | 2923 | 'groups' => array( |
| 2846 | 2924 | 'allowed' => array(), |
@@ -2850,6 +2928,7 @@ discard block |
||
| 2850 | 2928 | 'is_denied' => false, |
| 2851 | 2929 | 'is_global' => empty($board), |
| 2852 | 2930 | ); |
| 2931 | + } |
|
| 2853 | 2932 | |
| 2854 | 2933 | $context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name']; |
| 2855 | 2934 | |
@@ -2868,8 +2947,9 @@ discard block |
||
| 2868 | 2947 | global $modSettings, $context, $sourcedir, $txt, $scripturl; |
| 2869 | 2948 | |
| 2870 | 2949 | // Firstly, can we actually even be here? |
| 2871 | - if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) |
|
| 2872 | - fatal_lang_error('no_access', false); |
|
| 2950 | + if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) { |
|
| 2951 | + fatal_lang_error('no_access', false); |
|
| 2952 | + } |
|
| 2873 | 2953 | |
| 2874 | 2954 | // Make sure things which are disabled stay disabled. |
| 2875 | 2955 | $modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110; |
@@ -2956,9 +3036,10 @@ discard block |
||
| 2956 | 3036 | $modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'], |
| 2957 | 3037 | ); |
| 2958 | 3038 | $context['current_level'] = 0; |
| 2959 | - foreach ($context['level_effects'] as $limit => $dummy) |
|
| 2960 | - if ($context['member']['warning'] >= $limit) |
|
| 3039 | + foreach ($context['level_effects'] as $limit => $dummy) { |
|
| 3040 | + if ($context['member']['warning'] >= $limit) |
|
| 2961 | 3041 | $context['current_level'] = $limit; |
| 2962 | -} |
|
| 3042 | + } |
|
| 3043 | + } |
|
| 2963 | 3044 | |
| 2964 | 3045 | ?> |
| 2965 | 3046 | \ No newline at end of file |
@@ -255,8 +255,8 @@ discard block |
||
| 255 | 255 | |
| 256 | 256 | case 'datetime': |
| 257 | 257 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
| 258 | - return 'str_to_date('. |
|
| 259 | - sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
|
| 258 | + return 'str_to_date(' . |
|
| 259 | + sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5], $datetime_matches[6]) . |
|
| 260 | 260 | ',\'%Y-%m-%d %h:%i:%s\')'; |
| 261 | 261 | else |
| 262 | 262 | smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
@@ -460,7 +460,7 @@ discard block |
||
| 460 | 460 | $old_pos = 0; |
| 461 | 461 | $pos = -1; |
| 462 | 462 | // Remove the string escape for better runtime |
| 463 | - $db_string_1 = str_replace('\\\'','',$db_string); |
|
| 463 | + $db_string_1 = str_replace('\\\'', '', $db_string); |
|
| 464 | 464 | while (true) |
| 465 | 465 | { |
| 466 | 466 | $pos = strpos($db_string_1, '\'', $pos + 1); |
@@ -842,7 +842,7 @@ discard block |
||
| 842 | 842 | { |
| 843 | 843 | $count = count($insertRows); |
| 844 | 844 | $ai = 0; |
| 845 | - for($i = 0; $i < $count; $i++) |
|
| 845 | + for ($i = 0; $i < $count; $i++) |
|
| 846 | 846 | { |
| 847 | 847 | $old_id = $smcFunc['db_insert_id'](); |
| 848 | 848 | |
@@ -868,13 +868,13 @@ discard block |
||
| 868 | 868 | $count2 = count($indexed_columns); |
| 869 | 869 | for ($x = 0; $x < $count2; $x++) |
| 870 | 870 | { |
| 871 | - $where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x]; |
|
| 871 | + $where_string += key($indexed_columns[$x]) . ' = ' . $insertRows[$i][$x]; |
|
| 872 | 872 | if (($x + 1) < $count2) |
| 873 | 873 | $where_string += ' AND '; |
| 874 | 874 | } |
| 875 | 875 | |
| 876 | - $request = $smcFunc['db_query']('',' |
|
| 877 | - SELECT `'. $keys[0] . '` FROM ' . $table .' |
|
| 876 | + $request = $smcFunc['db_query']('', ' |
|
| 877 | + SELECT `'. $keys[0] . '` FROM ' . $table . ' |
|
| 878 | 878 | WHERE ' . $where_string . ' LIMIT 1', |
| 879 | 879 | array() |
| 880 | 880 | ); |
@@ -903,7 +903,7 @@ discard block |
||
| 903 | 903 | $return_var = array(); |
| 904 | 904 | $count = count($insertRows); |
| 905 | 905 | $start = smf_db_insert_id($table, $keys[0]); |
| 906 | - for ($i = 0; $i < $count; $i++ ) |
|
| 906 | + for ($i = 0; $i < $count; $i++) |
|
| 907 | 907 | $return_var[] = $start + $i; |
| 908 | 908 | } |
| 909 | 909 | return $return_var; |
@@ -1036,7 +1036,7 @@ discard block |
||
| 1036 | 1036 | mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi', |
| 1037 | 1037 | $error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6], |
| 1038 | 1038 | $error_array[7], $error_array[8]); |
| 1039 | - mysqli_stmt_execute ($mysql_error_data_prep); |
|
| 1039 | + mysqli_stmt_execute($mysql_error_data_prep); |
|
| 1040 | 1040 | } |
| 1041 | 1041 | |
| 1042 | 1042 | /** |
@@ -1050,7 +1050,7 @@ discard block |
||
| 1050 | 1050 | */ |
| 1051 | 1051 | function smf_db_custom_order($field, $array_values, $desc = false) |
| 1052 | 1052 | { |
| 1053 | - $return = 'CASE '. $field . ' '; |
|
| 1053 | + $return = 'CASE ' . $field . ' '; |
|
| 1054 | 1054 | $count = count($array_values); |
| 1055 | 1055 | $then = ($desc ? ' THEN -' : ' THEN '); |
| 1056 | 1056 | |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -33,8 +34,8 @@ discard block |
||
| 33 | 34 | global $smcFunc; |
| 34 | 35 | |
| 35 | 36 | // Map some database specific functions, only do this once. |
| 36 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
| 37 | - $smcFunc += array( |
|
| 37 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
| 38 | + $smcFunc += array( |
|
| 38 | 39 | 'db_query' => 'smf_db_query', |
| 39 | 40 | 'db_quote' => 'smf_db_quote', |
| 40 | 41 | 'db_fetch_assoc' => 'mysqli_fetch_assoc', |
@@ -63,9 +64,11 @@ discard block |
||
| 63 | 64 | 'db_error_insert' => 'smf_db_error_insert', |
| 64 | 65 | 'db_custom_order' => 'smf_db_custom_order', |
| 65 | 66 | ); |
| 67 | + } |
|
| 66 | 68 | |
| 67 | - if (!empty($db_options['persist'])) |
|
| 68 | - $db_server = 'p:' . $db_server; |
|
| 69 | + if (!empty($db_options['persist'])) { |
|
| 70 | + $db_server = 'p:' . $db_server; |
|
| 71 | + } |
|
| 69 | 72 | |
| 70 | 73 | $connection = mysqli_init(); |
| 71 | 74 | |
@@ -74,24 +77,27 @@ discard block |
||
| 74 | 77 | $success = false; |
| 75 | 78 | |
| 76 | 79 | if ($connection) { |
| 77 | - if (!empty($db_options['port'])) |
|
| 78 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags); |
|
| 79 | - else |
|
| 80 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags); |
|
| 80 | + if (!empty($db_options['port'])) { |
|
| 81 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags); |
|
| 82 | + } else { |
|
| 83 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags); |
|
| 84 | + } |
|
| 81 | 85 | } |
| 82 | 86 | |
| 83 | 87 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 84 | 88 | if ($success === false) |
| 85 | 89 | { |
| 86 | - if (!empty($db_options['non_fatal'])) |
|
| 87 | - return null; |
|
| 88 | - else |
|
| 89 | - display_db_error(); |
|
| 90 | + if (!empty($db_options['non_fatal'])) { |
|
| 91 | + return null; |
|
| 92 | + } else { |
|
| 93 | + display_db_error(); |
|
| 94 | + } |
|
| 90 | 95 | } |
| 91 | 96 | |
| 92 | 97 | // Select the database, unless told not to |
| 93 | - if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) |
|
| 94 | - display_db_error(); |
|
| 98 | + if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) { |
|
| 99 | + display_db_error(); |
|
| 100 | + } |
|
| 95 | 101 | |
| 96 | 102 | $smcFunc['db_query']('', 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'', |
| 97 | 103 | array(), |
@@ -167,34 +173,42 @@ discard block |
||
| 167 | 173 | global $db_callback, $user_info, $db_prefix, $smcFunc; |
| 168 | 174 | |
| 169 | 175 | list ($values, $connection) = $db_callback; |
| 170 | - if (!is_object($connection)) |
|
| 171 | - display_db_error(); |
|
| 176 | + if (!is_object($connection)) { |
|
| 177 | + display_db_error(); |
|
| 178 | + } |
|
| 172 | 179 | |
| 173 | - if ($matches[1] === 'db_prefix') |
|
| 174 | - return $db_prefix; |
|
| 180 | + if ($matches[1] === 'db_prefix') { |
|
| 181 | + return $db_prefix; |
|
| 182 | + } |
|
| 175 | 183 | |
| 176 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
| 177 | - return $user_info[$matches[1]]; |
|
| 184 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
| 185 | + return $user_info[$matches[1]]; |
|
| 186 | + } |
|
| 178 | 187 | |
| 179 | - if ($matches[1] === 'empty') |
|
| 180 | - return '\'\''; |
|
| 188 | + if ($matches[1] === 'empty') { |
|
| 189 | + return '\'\''; |
|
| 190 | + } |
|
| 181 | 191 | |
| 182 | - if (!isset($matches[2])) |
|
| 183 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 192 | + if (!isset($matches[2])) { |
|
| 193 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 194 | + } |
|
| 184 | 195 | |
| 185 | - if ($matches[1] === 'literal') |
|
| 186 | - return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
| 196 | + if ($matches[1] === 'literal') { |
|
| 197 | + return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
| 198 | + } |
|
| 187 | 199 | |
| 188 | - if (!isset($values[$matches[2]])) |
|
| 189 | - 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__); |
|
| 200 | + if (!isset($values[$matches[2]])) { |
|
| 201 | + 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__); |
|
| 202 | + } |
|
| 190 | 203 | |
| 191 | 204 | $replacement = $values[$matches[2]]; |
| 192 | 205 | |
| 193 | 206 | switch ($matches[1]) |
| 194 | 207 | { |
| 195 | 208 | case 'int': |
| 196 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 197 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 209 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 210 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 211 | + } |
|
| 198 | 212 | return (string) (int) $replacement; |
| 199 | 213 | break; |
| 200 | 214 | |
@@ -206,65 +220,73 @@ discard block |
||
| 206 | 220 | case 'array_int': |
| 207 | 221 | if (is_array($replacement)) |
| 208 | 222 | { |
| 209 | - if (empty($replacement)) |
|
| 210 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 223 | + if (empty($replacement)) { |
|
| 224 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 225 | + } |
|
| 211 | 226 | |
| 212 | 227 | foreach ($replacement as $key => $value) |
| 213 | 228 | { |
| 214 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 215 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 229 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 230 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 231 | + } |
|
| 216 | 232 | |
| 217 | 233 | $replacement[$key] = (string) (int) $value; |
| 218 | 234 | } |
| 219 | 235 | |
| 220 | 236 | return implode(', ', $replacement); |
| 237 | + } else { |
|
| 238 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 221 | 239 | } |
| 222 | - else |
|
| 223 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 224 | 240 | |
| 225 | 241 | break; |
| 226 | 242 | |
| 227 | 243 | case 'array_string': |
| 228 | 244 | if (is_array($replacement)) |
| 229 | 245 | { |
| 230 | - if (empty($replacement)) |
|
| 231 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 246 | + if (empty($replacement)) { |
|
| 247 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 248 | + } |
|
| 232 | 249 | |
| 233 | - foreach ($replacement as $key => $value) |
|
| 234 | - $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
| 250 | + foreach ($replacement as $key => $value) { |
|
| 251 | + $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
| 252 | + } |
|
| 235 | 253 | |
| 236 | 254 | return implode(', ', $replacement); |
| 255 | + } else { |
|
| 256 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 237 | 257 | } |
| 238 | - else |
|
| 239 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 240 | 258 | break; |
| 241 | 259 | |
| 242 | 260 | case 'date': |
| 243 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
| 244 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 245 | - else |
|
| 246 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 261 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 262 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 263 | + } else { |
|
| 264 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 265 | + } |
|
| 247 | 266 | break; |
| 248 | 267 | |
| 249 | 268 | case 'time': |
| 250 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
| 251 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
| 252 | - else |
|
| 253 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 269 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
| 270 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
| 271 | + } else { |
|
| 272 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 273 | + } |
|
| 254 | 274 | break; |
| 255 | 275 | |
| 256 | 276 | case 'datetime': |
| 257 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
| 258 | - return 'str_to_date('. |
|
| 277 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
| 278 | + return 'str_to_date('. |
|
| 259 | 279 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
| 260 | 280 | ',\'%Y-%m-%d %h:%i:%s\')'; |
| 261 | - else |
|
| 262 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 281 | + } else { |
|
| 282 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 283 | + } |
|
| 263 | 284 | break; |
| 264 | 285 | |
| 265 | 286 | case 'float': |
| 266 | - if (!is_numeric($replacement)) |
|
| 267 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 287 | + if (!is_numeric($replacement)) { |
|
| 288 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 289 | + } |
|
| 268 | 290 | return (string) (float) $replacement; |
| 269 | 291 | break; |
| 270 | 292 | |
@@ -278,32 +300,37 @@ discard block |
||
| 278 | 300 | break; |
| 279 | 301 | |
| 280 | 302 | case 'inet': |
| 281 | - if ($replacement == 'null' || $replacement == '') |
|
| 282 | - return 'null'; |
|
| 283 | - if (!isValidIP($replacement)) |
|
| 284 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 303 | + if ($replacement == 'null' || $replacement == '') { |
|
| 304 | + return 'null'; |
|
| 305 | + } |
|
| 306 | + if (!isValidIP($replacement)) { |
|
| 307 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 308 | + } |
|
| 285 | 309 | //we don't use the native support of mysql > 5.6.2 |
| 286 | 310 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
| 287 | 311 | |
| 288 | 312 | case 'array_inet': |
| 289 | 313 | if (is_array($replacement)) |
| 290 | 314 | { |
| 291 | - if (empty($replacement)) |
|
| 292 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 315 | + if (empty($replacement)) { |
|
| 316 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 317 | + } |
|
| 293 | 318 | |
| 294 | 319 | foreach ($replacement as $key => $value) |
| 295 | 320 | { |
| 296 | - if ($replacement == 'null' || $replacement == '') |
|
| 297 | - $replacement[$key] = 'null'; |
|
| 298 | - if (!isValidIP($value)) |
|
| 299 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 321 | + if ($replacement == 'null' || $replacement == '') { |
|
| 322 | + $replacement[$key] = 'null'; |
|
| 323 | + } |
|
| 324 | + if (!isValidIP($value)) { |
|
| 325 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 326 | + } |
|
| 300 | 327 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
| 301 | 328 | } |
| 302 | 329 | |
| 303 | 330 | return implode(', ', $replacement); |
| 331 | + } else { |
|
| 332 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 304 | 333 | } |
| 305 | - else |
|
| 306 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 307 | 334 | break; |
| 308 | 335 | |
| 309 | 336 | default: |
@@ -379,22 +406,25 @@ discard block |
||
| 379 | 406 | // Are we in SSI mode? If so try that username and password first |
| 380 | 407 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
| 381 | 408 | { |
| 382 | - if (empty($db_persist)) |
|
| 383 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 384 | - else |
|
| 385 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 409 | + if (empty($db_persist)) { |
|
| 410 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 411 | + } else { |
|
| 412 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 413 | + } |
|
| 386 | 414 | } |
| 387 | 415 | // Fall back to the regular username and password if need be |
| 388 | 416 | if (!$db_connection) |
| 389 | 417 | { |
| 390 | - if (empty($db_persist)) |
|
| 391 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 392 | - else |
|
| 393 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 418 | + if (empty($db_persist)) { |
|
| 419 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 420 | + } else { |
|
| 421 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 422 | + } |
|
| 394 | 423 | } |
| 395 | 424 | |
| 396 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
| 397 | - $db_connection = false; |
|
| 425 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
| 426 | + $db_connection = false; |
|
| 427 | + } |
|
| 398 | 428 | |
| 399 | 429 | $connection = $db_connection; |
| 400 | 430 | } |
@@ -402,18 +432,20 @@ discard block |
||
| 402 | 432 | // One more query.... |
| 403 | 433 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 404 | 434 | |
| 405 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 406 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 435 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 436 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 437 | + } |
|
| 407 | 438 | |
| 408 | 439 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
| 409 | 440 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
| 410 | 441 | { |
| 411 | 442 | // Add before LIMIT |
| 412 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
| 413 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 414 | - else |
|
| 415 | - // Append it. |
|
| 443 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
| 444 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 445 | + } else { |
|
| 446 | + // Append it. |
|
| 416 | 447 | $db_string .= "\n\t\t\tORDER BY null"; |
| 448 | + } |
|
| 417 | 449 | } |
| 418 | 450 | |
| 419 | 451 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -435,8 +467,9 @@ discard block |
||
| 435 | 467 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 436 | 468 | |
| 437 | 469 | // Initialize $db_cache if not already initialized. |
| 438 | - if (!isset($db_cache)) |
|
| 439 | - $db_cache = array(); |
|
| 470 | + if (!isset($db_cache)) { |
|
| 471 | + $db_cache = array(); |
|
| 472 | + } |
|
| 440 | 473 | |
| 441 | 474 | if (!empty($_SESSION['debug_redirect'])) |
| 442 | 475 | { |
@@ -464,17 +497,18 @@ discard block |
||
| 464 | 497 | while (true) |
| 465 | 498 | { |
| 466 | 499 | $pos = strpos($db_string_1, '\'', $pos + 1); |
| 467 | - if ($pos === false) |
|
| 468 | - break; |
|
| 500 | + if ($pos === false) { |
|
| 501 | + break; |
|
| 502 | + } |
|
| 469 | 503 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
| 470 | 504 | |
| 471 | 505 | while (true) |
| 472 | 506 | { |
| 473 | 507 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
| 474 | 508 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
| 475 | - if ($pos1 === false) |
|
| 476 | - break; |
|
| 477 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
| 509 | + if ($pos1 === false) { |
|
| 510 | + break; |
|
| 511 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
| 478 | 512 | { |
| 479 | 513 | $pos = $pos1; |
| 480 | 514 | break; |
@@ -490,29 +524,35 @@ discard block |
||
| 490 | 524 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 491 | 525 | |
| 492 | 526 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 493 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 494 | - $fail = true; |
|
| 527 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 528 | + $fail = true; |
|
| 529 | + } |
|
| 495 | 530 | // Trying to change passwords, slow us down, or something? |
| 496 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 497 | - $fail = true; |
|
| 498 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 499 | - $fail = true; |
|
| 531 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 532 | + $fail = true; |
|
| 533 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 534 | + $fail = true; |
|
| 535 | + } |
|
| 500 | 536 | |
| 501 | - if (!empty($fail) && function_exists('log_error')) |
|
| 502 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 537 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 538 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 539 | + } |
|
| 503 | 540 | } |
| 504 | 541 | |
| 505 | - if (empty($db_unbuffered)) |
|
| 506 | - $ret = @mysqli_query($connection, $db_string); |
|
| 507 | - else |
|
| 508 | - $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
| 542 | + if (empty($db_unbuffered)) { |
|
| 543 | + $ret = @mysqli_query($connection, $db_string); |
|
| 544 | + } else { |
|
| 545 | + $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
| 546 | + } |
|
| 509 | 547 | |
| 510 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
| 511 | - $ret = smf_db_error($db_string, $connection); |
|
| 548 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
| 549 | + $ret = smf_db_error($db_string, $connection); |
|
| 550 | + } |
|
| 512 | 551 | |
| 513 | 552 | // Debugging. |
| 514 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 515 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 553 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 554 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 555 | + } |
|
| 516 | 556 | |
| 517 | 557 | return $ret; |
| 518 | 558 | } |
@@ -559,12 +599,13 @@ discard block |
||
| 559 | 599 | // Decide which connection to use |
| 560 | 600 | $connection = $connection === null ? $db_connection : $connection; |
| 561 | 601 | |
| 562 | - if ($type == 'begin') |
|
| 563 | - return @mysqli_query($connection, 'BEGIN'); |
|
| 564 | - elseif ($type == 'rollback') |
|
| 565 | - return @mysqli_query($connection, 'ROLLBACK'); |
|
| 566 | - elseif ($type == 'commit') |
|
| 567 | - return @mysqli_query($connection, 'COMMIT'); |
|
| 602 | + if ($type == 'begin') { |
|
| 603 | + return @mysqli_query($connection, 'BEGIN'); |
|
| 604 | + } elseif ($type == 'rollback') { |
|
| 605 | + return @mysqli_query($connection, 'ROLLBACK'); |
|
| 606 | + } elseif ($type == 'commit') { |
|
| 607 | + return @mysqli_query($connection, 'COMMIT'); |
|
| 608 | + } |
|
| 568 | 609 | |
| 569 | 610 | return false; |
| 570 | 611 | } |
@@ -604,8 +645,9 @@ discard block |
||
| 604 | 645 | // 2013: Lost connection to server during query. |
| 605 | 646 | |
| 606 | 647 | // Log the error. |
| 607 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
| 608 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 648 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
| 649 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 650 | + } |
|
| 609 | 651 | |
| 610 | 652 | // Database error auto fixing ;). |
| 611 | 653 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -614,8 +656,9 @@ discard block |
||
| 614 | 656 | $old_cache = @$modSettings['cache_enable']; |
| 615 | 657 | $modSettings['cache_enable'] = '1'; |
| 616 | 658 | |
| 617 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
| 618 | - $db_last_error = max(@$db_last_error, $temp); |
|
| 659 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
| 660 | + $db_last_error = max(@$db_last_error, $temp); |
|
| 661 | + } |
|
| 619 | 662 | |
| 620 | 663 | if (@$db_last_error < time() - 3600 * 24 * 3) |
| 621 | 664 | { |
@@ -631,8 +674,9 @@ discard block |
||
| 631 | 674 | foreach ($tables as $table) |
| 632 | 675 | { |
| 633 | 676 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
| 634 | - if (trim($table) != '') |
|
| 635 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 677 | + if (trim($table) != '') { |
|
| 678 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 679 | + } |
|
| 636 | 680 | } |
| 637 | 681 | } |
| 638 | 682 | |
@@ -641,8 +685,9 @@ discard block |
||
| 641 | 685 | // Table crashed. Let's try to fix it. |
| 642 | 686 | elseif ($query_errno == 1016) |
| 643 | 687 | { |
| 644 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
| 645 | - $fix_tables = array('`' . $match[1] . '`'); |
|
| 688 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
| 689 | + $fix_tables = array('`' . $match[1] . '`'); |
|
| 690 | + } |
|
| 646 | 691 | } |
| 647 | 692 | // Indexes crashed. Should be easy to fix! |
| 648 | 693 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -661,13 +706,15 @@ discard block |
||
| 661 | 706 | |
| 662 | 707 | // Make a note of the REPAIR... |
| 663 | 708 | cache_put_data('db_last_error', time(), 600); |
| 664 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
| 665 | - updateSettingsFile(array('db_last_error' => time())); |
|
| 709 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
| 710 | + updateSettingsFile(array('db_last_error' => time())); |
|
| 711 | + } |
|
| 666 | 712 | |
| 667 | 713 | // Attempt to find and repair the broken table. |
| 668 | - foreach ($fix_tables as $table) |
|
| 669 | - $smcFunc['db_query']('', " |
|
| 714 | + foreach ($fix_tables as $table) { |
|
| 715 | + $smcFunc['db_query']('', " |
|
| 670 | 716 | REPAIR TABLE $table", false, false); |
| 717 | + } |
|
| 671 | 718 | |
| 672 | 719 | // And send off an email! |
| 673 | 720 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -676,11 +723,12 @@ discard block |
||
| 676 | 723 | |
| 677 | 724 | // Try the query again...? |
| 678 | 725 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 679 | - if ($ret !== false) |
|
| 680 | - return $ret; |
|
| 726 | + if ($ret !== false) { |
|
| 727 | + return $ret; |
|
| 728 | + } |
|
| 729 | + } else { |
|
| 730 | + $modSettings['cache_enable'] = $old_cache; |
|
| 681 | 731 | } |
| 682 | - else |
|
| 683 | - $modSettings['cache_enable'] = $old_cache; |
|
| 684 | 732 | |
| 685 | 733 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
| 686 | 734 | if (in_array($query_errno, array(1205, 1213, 2006, 2013))) |
@@ -690,22 +738,25 @@ discard block |
||
| 690 | 738 | // Are we in SSI mode? If so try that username and password first |
| 691 | 739 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
| 692 | 740 | { |
| 693 | - if (empty($db_persist)) |
|
| 694 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 695 | - else |
|
| 696 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 741 | + if (empty($db_persist)) { |
|
| 742 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 743 | + } else { |
|
| 744 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 745 | + } |
|
| 697 | 746 | } |
| 698 | 747 | // Fall back to the regular username and password if need be |
| 699 | 748 | if (!$db_connection) |
| 700 | 749 | { |
| 701 | - if (empty($db_persist)) |
|
| 702 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 703 | - else |
|
| 704 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 750 | + if (empty($db_persist)) { |
|
| 751 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 752 | + } else { |
|
| 753 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 754 | + } |
|
| 705 | 755 | } |
| 706 | 756 | |
| 707 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
| 708 | - $db_connection = false; |
|
| 757 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
| 758 | + $db_connection = false; |
|
| 759 | + } |
|
| 709 | 760 | } |
| 710 | 761 | |
| 711 | 762 | if ($db_connection) |
@@ -716,24 +767,27 @@ discard block |
||
| 716 | 767 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 717 | 768 | |
| 718 | 769 | $new_errno = mysqli_errno($db_connection); |
| 719 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
| 720 | - break; |
|
| 770 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
| 771 | + break; |
|
| 772 | + } |
|
| 721 | 773 | } |
| 722 | 774 | |
| 723 | 775 | // If it failed again, shucks to be you... we're not trying it over and over. |
| 724 | - if ($ret !== false) |
|
| 725 | - return $ret; |
|
| 776 | + if ($ret !== false) { |
|
| 777 | + return $ret; |
|
| 778 | + } |
|
| 726 | 779 | } |
| 727 | 780 | } |
| 728 | 781 | // Are they out of space, perhaps? |
| 729 | 782 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
| 730 | 783 | { |
| 731 | - if (!isset($txt)) |
|
| 732 | - $query_error .= ' - check database storage space.'; |
|
| 733 | - else |
|
| 784 | + if (!isset($txt)) { |
|
| 785 | + $query_error .= ' - check database storage space.'; |
|
| 786 | + } else |
|
| 734 | 787 | { |
| 735 | - if (!isset($txt['mysql_error_space'])) |
|
| 736 | - loadLanguage('Errors'); |
|
| 788 | + if (!isset($txt['mysql_error_space'])) { |
|
| 789 | + loadLanguage('Errors'); |
|
| 790 | + } |
|
| 737 | 791 | |
| 738 | 792 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
| 739 | 793 | } |
@@ -741,15 +795,17 @@ discard block |
||
| 741 | 795 | } |
| 742 | 796 | |
| 743 | 797 | // Nothing's defined yet... just die with it. |
| 744 | - if (empty($context) || empty($txt)) |
|
| 745 | - die($query_error); |
|
| 798 | + if (empty($context) || empty($txt)) { |
|
| 799 | + die($query_error); |
|
| 800 | + } |
|
| 746 | 801 | |
| 747 | 802 | // Show an error message, if possible. |
| 748 | 803 | $context['error_title'] = $txt['database_error']; |
| 749 | - if (allowedTo('admin_forum')) |
|
| 750 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 751 | - else |
|
| 752 | - $context['error_message'] = $txt['try_again']; |
|
| 804 | + if (allowedTo('admin_forum')) { |
|
| 805 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 806 | + } else { |
|
| 807 | + $context['error_message'] = $txt['try_again']; |
|
| 808 | + } |
|
| 753 | 809 | |
| 754 | 810 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 755 | 811 | { |
@@ -781,8 +837,9 @@ discard block |
||
| 781 | 837 | $return_var = null; |
| 782 | 838 | |
| 783 | 839 | // With nothing to insert, simply return. |
| 784 | - if (empty($data)) |
|
| 785 | - return; |
|
| 840 | + if (empty($data)) { |
|
| 841 | + return; |
|
| 842 | + } |
|
| 786 | 843 | |
| 787 | 844 | // Replace the prefix holder with the actual prefix. |
| 788 | 845 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -792,23 +849,26 @@ discard block |
||
| 792 | 849 | if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) |
| 793 | 850 | { |
| 794 | 851 | $with_returning = true; |
| 795 | - if ($returnmode == 2) |
|
| 796 | - $return_var = array(); |
|
| 852 | + if ($returnmode == 2) { |
|
| 853 | + $return_var = array(); |
|
| 854 | + } |
|
| 797 | 855 | } |
| 798 | 856 | |
| 799 | 857 | // Inserting data as a single row can be done as a single array. |
| 800 | - if (!is_array($data[array_rand($data)])) |
|
| 801 | - $data = array($data); |
|
| 858 | + if (!is_array($data[array_rand($data)])) { |
|
| 859 | + $data = array($data); |
|
| 860 | + } |
|
| 802 | 861 | |
| 803 | 862 | // Create the mold for a single row insert. |
| 804 | 863 | $insertData = '('; |
| 805 | 864 | foreach ($columns as $columnName => $type) |
| 806 | 865 | { |
| 807 | 866 | // Are we restricting the length? |
| 808 | - if (strpos($type, 'string-') !== false) |
|
| 809 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 810 | - else |
|
| 811 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 867 | + if (strpos($type, 'string-') !== false) { |
|
| 868 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 869 | + } else { |
|
| 870 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 871 | + } |
|
| 812 | 872 | } |
| 813 | 873 | $insertData = substr($insertData, 0, -2) . ')'; |
| 814 | 874 | |
@@ -817,8 +877,9 @@ discard block |
||
| 817 | 877 | |
| 818 | 878 | // Here's where the variables are injected to the query. |
| 819 | 879 | $insertRows = array(); |
| 820 | - foreach ($data as $dataRow) |
|
| 821 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 880 | + foreach ($data as $dataRow) { |
|
| 881 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 882 | + } |
|
| 822 | 883 | |
| 823 | 884 | // Determine the method of insertion. |
| 824 | 885 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
@@ -837,8 +898,7 @@ discard block |
||
| 837 | 898 | ), |
| 838 | 899 | $connection |
| 839 | 900 | ); |
| 840 | - } |
|
| 841 | - else //special way for ignore method with returning |
|
| 901 | + } else //special way for ignore method with returning |
|
| 842 | 902 | { |
| 843 | 903 | $count = count($insertRows); |
| 844 | 904 | $ai = 0; |
@@ -858,19 +918,21 @@ discard block |
||
| 858 | 918 | ); |
| 859 | 919 | $new_id = $smcFunc['db_insert_id'](); |
| 860 | 920 | |
| 861 | - if ($last_id != $new_id) //the inserted value was new |
|
| 921 | + if ($last_id != $new_id) { |
|
| 922 | + //the inserted value was new |
|
| 862 | 923 | { |
| 863 | 924 | $ai = $new_id; |
| 864 | 925 | } |
| 865 | - else // the inserted value already exists we need to find the pk |
|
| 926 | + } else // the inserted value already exists we need to find the pk |
|
| 866 | 927 | { |
| 867 | 928 | $where_string = ''; |
| 868 | 929 | $count2 = count($indexed_columns); |
| 869 | 930 | for ($x = 0; $x < $count2; $x++) |
| 870 | 931 | { |
| 871 | 932 | $where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x]; |
| 872 | - if (($x + 1) < $count2) |
|
| 873 | - $where_string += ' AND '; |
|
| 933 | + if (($x + 1) < $count2) { |
|
| 934 | + $where_string += ' AND '; |
|
| 935 | + } |
|
| 874 | 936 | } |
| 875 | 937 | |
| 876 | 938 | $request = $smcFunc['db_query']('',' |
@@ -886,25 +948,27 @@ discard block |
||
| 886 | 948 | } |
| 887 | 949 | } |
| 888 | 950 | |
| 889 | - if ($returnmode == 1) |
|
| 890 | - $return_var = $ai; |
|
| 891 | - else if ($returnmode == 2) |
|
| 892 | - $return_var[] = $ai; |
|
| 951 | + if ($returnmode == 1) { |
|
| 952 | + $return_var = $ai; |
|
| 953 | + } else if ($returnmode == 2) { |
|
| 954 | + $return_var[] = $ai; |
|
| 955 | + } |
|
| 893 | 956 | } |
| 894 | 957 | } |
| 895 | 958 | |
| 896 | 959 | |
| 897 | 960 | if ($with_returning) |
| 898 | 961 | { |
| 899 | - if ($returnmode == 1 && empty($return_var)) |
|
| 900 | - $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
| 901 | - else if ($returnmode == 2 && empty($return_var)) |
|
| 962 | + if ($returnmode == 1 && empty($return_var)) { |
|
| 963 | + $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
| 964 | + } else if ($returnmode == 2 && empty($return_var)) |
|
| 902 | 965 | { |
| 903 | 966 | $return_var = array(); |
| 904 | 967 | $count = count($insertRows); |
| 905 | 968 | $start = smf_db_insert_id($table, $keys[0]); |
| 906 | - for ($i = 0; $i < $count; $i++ ) |
|
| 907 | - $return_var[] = $start + $i; |
|
| 969 | + for ($i = 0; $i < $count; $i++ ) { |
|
| 970 | + $return_var[] = $start + $i; |
|
| 971 | + } |
|
| 908 | 972 | } |
| 909 | 973 | return $return_var; |
| 910 | 974 | } |
@@ -922,8 +986,9 @@ discard block |
||
| 922 | 986 | */ |
| 923 | 987 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 924 | 988 | { |
| 925 | - if (empty($log_message)) |
|
| 926 | - $log_message = $error_message; |
|
| 989 | + if (empty($log_message)) { |
|
| 990 | + $log_message = $error_message; |
|
| 991 | + } |
|
| 927 | 992 | |
| 928 | 993 | foreach (debug_backtrace() as $step) |
| 929 | 994 | { |
@@ -942,12 +1007,14 @@ discard block |
||
| 942 | 1007 | } |
| 943 | 1008 | |
| 944 | 1009 | // A special case - we want the file and line numbers for debugging. |
| 945 | - if ($error_type == 'return') |
|
| 946 | - return array($file, $line); |
|
| 1010 | + if ($error_type == 'return') { |
|
| 1011 | + return array($file, $line); |
|
| 1012 | + } |
|
| 947 | 1013 | |
| 948 | 1014 | // Is always a critical error. |
| 949 | - if (function_exists('log_error')) |
|
| 950 | - log_error($log_message, 'critical', $file, $line); |
|
| 1015 | + if (function_exists('log_error')) { |
|
| 1016 | + log_error($log_message, 'critical', $file, $line); |
|
| 1017 | + } |
|
| 951 | 1018 | |
| 952 | 1019 | if (function_exists('fatal_error')) |
| 953 | 1020 | { |
@@ -955,12 +1022,12 @@ discard block |
||
| 955 | 1022 | |
| 956 | 1023 | // Cannot continue... |
| 957 | 1024 | exit; |
| 1025 | + } elseif ($error_type) { |
|
| 1026 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 1027 | + } else { |
|
| 1028 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 1029 | + } |
|
| 958 | 1030 | } |
| 959 | - elseif ($error_type) |
|
| 960 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 961 | - else |
|
| 962 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 963 | -} |
|
| 964 | 1031 | |
| 965 | 1032 | /** |
| 966 | 1033 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -977,10 +1044,11 @@ discard block |
||
| 977 | 1044 | '\\' => '\\\\', |
| 978 | 1045 | ); |
| 979 | 1046 | |
| 980 | - if ($translate_human_wildcards) |
|
| 981 | - $replacements += array( |
|
| 1047 | + if ($translate_human_wildcards) { |
|
| 1048 | + $replacements += array( |
|
| 982 | 1049 | '*' => '%', |
| 983 | 1050 | ); |
| 1051 | + } |
|
| 984 | 1052 | |
| 985 | 1053 | return strtr($string, $replacements); |
| 986 | 1054 | } |
@@ -994,8 +1062,9 @@ discard block |
||
| 994 | 1062 | */ |
| 995 | 1063 | function smf_is_resource($result) |
| 996 | 1064 | { |
| 997 | - if ($result instanceof mysqli_result) |
|
| 998 | - return true; |
|
| 1065 | + if ($result instanceof mysqli_result) { |
|
| 1066 | + return true; |
|
| 1067 | + } |
|
| 999 | 1068 | |
| 1000 | 1069 | return false; |
| 1001 | 1070 | } |
@@ -1023,16 +1092,18 @@ discard block |
||
| 1023 | 1092 | global $db_prefix, $db_connection; |
| 1024 | 1093 | static $mysql_error_data_prep; |
| 1025 | 1094 | |
| 1026 | - if (empty($mysql_error_data_prep)) |
|
| 1027 | - $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
| 1095 | + if (empty($mysql_error_data_prep)) { |
|
| 1096 | + $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
| 1028 | 1097 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line) |
| 1029 | 1098 | VALUES( ?, ?, unhex(?), ?, ?, ?, ?, ?, ?)' |
| 1030 | 1099 | ); |
| 1100 | + } |
|
| 1031 | 1101 | |
| 1032 | - if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) |
|
| 1033 | - $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
| 1034 | - else |
|
| 1035 | - $error_array[2] = null; |
|
| 1102 | + if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) { |
|
| 1103 | + $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
| 1104 | + } else { |
|
| 1105 | + $error_array[2] = null; |
|
| 1106 | + } |
|
| 1036 | 1107 | mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi', |
| 1037 | 1108 | $error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6], |
| 1038 | 1109 | $error_array[7], $error_array[8]); |
@@ -1054,8 +1125,9 @@ discard block |
||
| 1054 | 1125 | $count = count($array_values); |
| 1055 | 1126 | $then = ($desc ? ' THEN -' : ' THEN '); |
| 1056 | 1127 | |
| 1057 | - for ($i = 0; $i < $count; $i++) |
|
| 1058 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
| 1128 | + for ($i = 0; $i < $count; $i++) { |
|
| 1129 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
| 1130 | + } |
|
| 1059 | 1131 | |
| 1060 | 1132 | $return .= 'END'; |
| 1061 | 1133 | return $return; |
@@ -199,22 +199,22 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | case 'date': |
| 201 | 201 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
| 202 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
| 202 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]) . '::date'; |
|
| 203 | 203 | else |
| 204 | 204 | smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
| 205 | 205 | break; |
| 206 | 206 | |
| 207 | 207 | case 'time': |
| 208 | 208 | if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
| 209 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
| 209 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]) . '::time'; |
|
| 210 | 210 | else |
| 211 | 211 | smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
| 212 | 212 | break; |
| 213 | 213 | |
| 214 | 214 | case 'datetime': |
| 215 | 215 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
| 216 | - return 'to_timestamp('. |
|
| 217 | - sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
|
| 216 | + return 'to_timestamp(' . |
|
| 217 | + sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5], $datetime_matches[6]) . |
|
| 218 | 218 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
| 219 | 219 | else |
| 220 | 220 | smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | $old_pos = 0; |
| 425 | 425 | $pos = -1; |
| 426 | 426 | // Remove the string escape for better runtime |
| 427 | - $db_string_1 = str_replace('\'\'','',$db_string); |
|
| 427 | + $db_string_1 = str_replace('\'\'', '', $db_string); |
|
| 428 | 428 | while (true) |
| 429 | 429 | { |
| 430 | 430 | $pos = strpos($db_string_1, '\'', $pos + 1); |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) |
| 803 | 803 | { |
| 804 | 804 | // we only take the first key |
| 805 | - $returning = ' RETURNING '.$keys[0]; |
|
| 805 | + $returning = ' RETURNING ' . $keys[0]; |
|
| 806 | 806 | $with_returning = true; |
| 807 | 807 | } |
| 808 | 808 | |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '") |
| 834 | 834 | VALUES |
| 835 | 835 | ' . implode(', |
| 836 | - ', $insertRows).$replace.$returning, |
|
| 836 | + ', $insertRows) . $replace . $returning, |
|
| 837 | 837 | array( |
| 838 | 838 | 'security_override' => true, |
| 839 | 839 | 'db_error_skip' => $method == 'ignore' || $table === $db_prefix . 'log_errors', |
@@ -846,7 +846,7 @@ discard block |
||
| 846 | 846 | if ($returnmode === 2) |
| 847 | 847 | $return_var = array(); |
| 848 | 848 | |
| 849 | - while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
|
| 849 | + while (($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
|
| 850 | 850 | { |
| 851 | 851 | if (is_numeric($row[0])) // try to emulate mysql limitation |
| 852 | 852 | { |
@@ -1009,7 +1009,7 @@ discard block |
||
| 1009 | 1009 | */ |
| 1010 | 1010 | function smf_db_custom_order($field, $array_values, $desc = false) |
| 1011 | 1011 | { |
| 1012 | - $return = 'CASE '. $field . ' '; |
|
| 1012 | + $return = 'CASE ' . $field . ' '; |
|
| 1013 | 1013 | $count = count($array_values); |
| 1014 | 1014 | $then = ($desc ? ' THEN -' : ' THEN '); |
| 1015 | 1015 | |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -34,8 +35,8 @@ discard block |
||
| 34 | 35 | global $smcFunc; |
| 35 | 36 | |
| 36 | 37 | // Map some database specific functions, only do this once. |
| 37 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
| 38 | - $smcFunc += array( |
|
| 38 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
| 39 | + $smcFunc += array( |
|
| 39 | 40 | 'db_query' => 'smf_db_query', |
| 40 | 41 | 'db_quote' => 'smf_db_quote', |
| 41 | 42 | 'db_insert' => 'smf_db_insert', |
@@ -64,11 +65,13 @@ discard block |
||
| 64 | 65 | 'db_error_insert' => 'smf_db_error_insert', |
| 65 | 66 | 'db_custom_order' => 'smf_db_custom_order', |
| 66 | 67 | ); |
| 68 | + } |
|
| 67 | 69 | |
| 68 | - if (!empty($db_options['persist'])) |
|
| 69 | - $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 70 | - else |
|
| 71 | - $connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 70 | + if (!empty($db_options['persist'])) { |
|
| 71 | + $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 72 | + } else { |
|
| 73 | + $connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 74 | + } |
|
| 72 | 75 | |
| 73 | 76 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 74 | 77 | if (!$connection) |
@@ -76,8 +79,7 @@ discard block |
||
| 76 | 79 | if (!empty($db_options['non_fatal'])) |
| 77 | 80 | { |
| 78 | 81 | return null; |
| 79 | - } |
|
| 80 | - else |
|
| 82 | + } else |
|
| 81 | 83 | { |
| 82 | 84 | display_db_error(); |
| 83 | 85 | } |
@@ -128,31 +130,38 @@ discard block |
||
| 128 | 130 | |
| 129 | 131 | list ($values, $connection) = $db_callback; |
| 130 | 132 | |
| 131 | - if ($matches[1] === 'db_prefix') |
|
| 132 | - return $db_prefix; |
|
| 133 | + if ($matches[1] === 'db_prefix') { |
|
| 134 | + return $db_prefix; |
|
| 135 | + } |
|
| 133 | 136 | |
| 134 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
| 135 | - return $user_info[$matches[1]]; |
|
| 137 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
| 138 | + return $user_info[$matches[1]]; |
|
| 139 | + } |
|
| 136 | 140 | |
| 137 | - if ($matches[1] === 'empty') |
|
| 138 | - return '\'\''; |
|
| 141 | + if ($matches[1] === 'empty') { |
|
| 142 | + return '\'\''; |
|
| 143 | + } |
|
| 139 | 144 | |
| 140 | - if (!isset($matches[2])) |
|
| 141 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 145 | + if (!isset($matches[2])) { |
|
| 146 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 147 | + } |
|
| 142 | 148 | |
| 143 | - if ($matches[1] === 'literal') |
|
| 144 | - return '\'' . pg_escape_string($matches[2]) . '\''; |
|
| 149 | + if ($matches[1] === 'literal') { |
|
| 150 | + return '\'' . pg_escape_string($matches[2]) . '\''; |
|
| 151 | + } |
|
| 145 | 152 | |
| 146 | - if (!isset($values[$matches[2]])) |
|
| 147 | - 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__); |
|
| 153 | + if (!isset($values[$matches[2]])) { |
|
| 154 | + 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__); |
|
| 155 | + } |
|
| 148 | 156 | |
| 149 | 157 | $replacement = $values[$matches[2]]; |
| 150 | 158 | |
| 151 | 159 | switch ($matches[1]) |
| 152 | 160 | { |
| 153 | 161 | case 'int': |
| 154 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 155 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 162 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 163 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 164 | + } |
|
| 156 | 165 | return (string) (int) $replacement; |
| 157 | 166 | break; |
| 158 | 167 | |
@@ -164,65 +173,73 @@ discard block |
||
| 164 | 173 | case 'array_int': |
| 165 | 174 | if (is_array($replacement)) |
| 166 | 175 | { |
| 167 | - if (empty($replacement)) |
|
| 168 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 176 | + if (empty($replacement)) { |
|
| 177 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 178 | + } |
|
| 169 | 179 | |
| 170 | 180 | foreach ($replacement as $key => $value) |
| 171 | 181 | { |
| 172 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 173 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 182 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 183 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 184 | + } |
|
| 174 | 185 | |
| 175 | 186 | $replacement[$key] = (string) (int) $value; |
| 176 | 187 | } |
| 177 | 188 | |
| 178 | 189 | return implode(', ', $replacement); |
| 190 | + } else { |
|
| 191 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 179 | 192 | } |
| 180 | - else |
|
| 181 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 182 | 193 | |
| 183 | 194 | break; |
| 184 | 195 | |
| 185 | 196 | case 'array_string': |
| 186 | 197 | if (is_array($replacement)) |
| 187 | 198 | { |
| 188 | - if (empty($replacement)) |
|
| 189 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 199 | + if (empty($replacement)) { |
|
| 200 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 201 | + } |
|
| 190 | 202 | |
| 191 | - foreach ($replacement as $key => $value) |
|
| 192 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 203 | + foreach ($replacement as $key => $value) { |
|
| 204 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 205 | + } |
|
| 193 | 206 | |
| 194 | 207 | return implode(', ', $replacement); |
| 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__); |
|
| 195 | 210 | } |
| 196 | - else |
|
| 197 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 198 | 211 | break; |
| 199 | 212 | |
| 200 | 213 | case 'date': |
| 201 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
| 202 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
| 203 | - else |
|
| 204 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 214 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 215 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
| 216 | + } else { |
|
| 217 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 218 | + } |
|
| 205 | 219 | break; |
| 206 | 220 | |
| 207 | 221 | case 'time': |
| 208 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
| 209 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
| 210 | - else |
|
| 211 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 222 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
| 223 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
| 224 | + } else { |
|
| 225 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 226 | + } |
|
| 212 | 227 | break; |
| 213 | 228 | |
| 214 | 229 | case 'datetime': |
| 215 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
| 216 | - return 'to_timestamp('. |
|
| 230 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
| 231 | + return 'to_timestamp('. |
|
| 217 | 232 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
| 218 | 233 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
| 219 | - else |
|
| 220 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 234 | + } else { |
|
| 235 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 236 | + } |
|
| 221 | 237 | break; |
| 222 | 238 | |
| 223 | 239 | case 'float': |
| 224 | - if (!is_numeric($replacement)) |
|
| 225 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 240 | + if (!is_numeric($replacement)) { |
|
| 241 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 242 | + } |
|
| 226 | 243 | return (string) (float) $replacement; |
| 227 | 244 | break; |
| 228 | 245 | |
@@ -235,31 +252,36 @@ discard block |
||
| 235 | 252 | break; |
| 236 | 253 | |
| 237 | 254 | case 'inet': |
| 238 | - if ($replacement == 'null' || $replacement == '') |
|
| 239 | - return 'null'; |
|
| 240 | - if (inet_pton($replacement) === false) |
|
| 241 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 255 | + if ($replacement == 'null' || $replacement == '') { |
|
| 256 | + return 'null'; |
|
| 257 | + } |
|
| 258 | + if (inet_pton($replacement) === false) { |
|
| 259 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 260 | + } |
|
| 242 | 261 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
| 243 | 262 | |
| 244 | 263 | case 'array_inet': |
| 245 | 264 | if (is_array($replacement)) |
| 246 | 265 | { |
| 247 | - if (empty($replacement)) |
|
| 248 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 266 | + if (empty($replacement)) { |
|
| 267 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 268 | + } |
|
| 249 | 269 | |
| 250 | 270 | foreach ($replacement as $key => $value) |
| 251 | 271 | { |
| 252 | - if ($replacement == 'null' || $replacement == '') |
|
| 253 | - $replacement[$key] = 'null'; |
|
| 254 | - if (!isValidIP($value)) |
|
| 255 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 272 | + if ($replacement == 'null' || $replacement == '') { |
|
| 273 | + $replacement[$key] = 'null'; |
|
| 274 | + } |
|
| 275 | + if (!isValidIP($value)) { |
|
| 276 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 277 | + } |
|
| 256 | 278 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
| 257 | 279 | } |
| 258 | 280 | |
| 259 | 281 | return implode(', ', $replacement); |
| 282 | + } else { |
|
| 283 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 260 | 284 | } |
| 261 | - else |
|
| 262 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 263 | 285 | break; |
| 264 | 286 | |
| 265 | 287 | default: |
@@ -350,14 +372,16 @@ discard block |
||
| 350 | 372 | ), |
| 351 | 373 | ); |
| 352 | 374 | |
| 353 | - if (isset($replacements[$identifier])) |
|
| 354 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 375 | + if (isset($replacements[$identifier])) { |
|
| 376 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 377 | + } |
|
| 355 | 378 | |
| 356 | 379 | // Limits need to be a little different. |
| 357 | 380 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
| 358 | 381 | |
| 359 | - if (trim($db_string) == '') |
|
| 360 | - return false; |
|
| 382 | + if (trim($db_string) == '') { |
|
| 383 | + return false; |
|
| 384 | + } |
|
| 361 | 385 | |
| 362 | 386 | // Comments that are allowed in a query are preg_removed. |
| 363 | 387 | static $allowed_comments_from = array( |
@@ -377,8 +401,9 @@ discard block |
||
| 377 | 401 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 378 | 402 | $db_replace_result = 0; |
| 379 | 403 | |
| 380 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 381 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 404 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 405 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 406 | + } |
|
| 382 | 407 | |
| 383 | 408 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
| 384 | 409 | { |
@@ -399,8 +424,9 @@ discard block |
||
| 399 | 424 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 400 | 425 | |
| 401 | 426 | // Initialize $db_cache if not already initialized. |
| 402 | - if (!isset($db_cache)) |
|
| 403 | - $db_cache = array(); |
|
| 427 | + if (!isset($db_cache)) { |
|
| 428 | + $db_cache = array(); |
|
| 429 | + } |
|
| 404 | 430 | |
| 405 | 431 | if (!empty($_SESSION['debug_redirect'])) |
| 406 | 432 | { |
@@ -428,17 +454,18 @@ discard block |
||
| 428 | 454 | while (true) |
| 429 | 455 | { |
| 430 | 456 | $pos = strpos($db_string_1, '\'', $pos + 1); |
| 431 | - if ($pos === false) |
|
| 432 | - break; |
|
| 457 | + if ($pos === false) { |
|
| 458 | + break; |
|
| 459 | + } |
|
| 433 | 460 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
| 434 | 461 | |
| 435 | 462 | while (true) |
| 436 | 463 | { |
| 437 | 464 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
| 438 | 465 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
| 439 | - if ($pos1 === false) |
|
| 440 | - break; |
|
| 441 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
| 466 | + if ($pos1 === false) { |
|
| 467 | + break; |
|
| 468 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
| 442 | 469 | { |
| 443 | 470 | $pos = $pos1; |
| 444 | 471 | break; |
@@ -454,16 +481,19 @@ discard block |
||
| 454 | 481 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 455 | 482 | |
| 456 | 483 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 457 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 458 | - $fail = true; |
|
| 484 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 485 | + $fail = true; |
|
| 486 | + } |
|
| 459 | 487 | // Trying to change passwords, slow us down, or something? |
| 460 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 461 | - $fail = true; |
|
| 462 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 463 | - $fail = true; |
|
| 488 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 489 | + $fail = true; |
|
| 490 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 491 | + $fail = true; |
|
| 492 | + } |
|
| 464 | 493 | |
| 465 | - if (!empty($fail) && function_exists('log_error')) |
|
| 466 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 494 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 495 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 496 | + } |
|
| 467 | 497 | } |
| 468 | 498 | |
| 469 | 499 | // Set optimize stuff |
@@ -482,18 +512,21 @@ discard block |
||
| 482 | 512 | |
| 483 | 513 | $db_string = $query_hints_set . $db_string; |
| 484 | 514 | |
| 485 | - if (isset($db_show_debug) && $db_show_debug === true && $db_cache[$db_count]['q'] != '...') |
|
| 486 | - $db_cache[$db_count]['q'] = "\t\t" . $db_string; |
|
| 515 | + if (isset($db_show_debug) && $db_show_debug === true && $db_cache[$db_count]['q'] != '...') { |
|
| 516 | + $db_cache[$db_count]['q'] = "\t\t" . $db_string; |
|
| 517 | + } |
|
| 487 | 518 | } |
| 488 | 519 | |
| 489 | 520 | $db_last_result = @pg_query($connection, $db_string); |
| 490 | 521 | |
| 491 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
| 492 | - $db_last_result = smf_db_error($db_string, $connection); |
|
| 522 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
| 523 | + $db_last_result = smf_db_error($db_string, $connection); |
|
| 524 | + } |
|
| 493 | 525 | |
| 494 | 526 | // Debugging. |
| 495 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 496 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 527 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 528 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 529 | + } |
|
| 497 | 530 | |
| 498 | 531 | return $db_last_result; |
| 499 | 532 | } |
@@ -510,10 +543,11 @@ discard block |
||
| 510 | 543 | { |
| 511 | 544 | global $db_last_result, $db_replace_result; |
| 512 | 545 | |
| 513 | - if ($db_replace_result) |
|
| 514 | - return $db_replace_result; |
|
| 515 | - elseif ($result === null && !$db_last_result) |
|
| 516 | - return 0; |
|
| 546 | + if ($db_replace_result) { |
|
| 547 | + return $db_replace_result; |
|
| 548 | + } elseif ($result === null && !$db_last_result) { |
|
| 549 | + return 0; |
|
| 550 | + } |
|
| 517 | 551 | |
| 518 | 552 | return pg_affected_rows($result === null ? $db_last_result : $result); |
| 519 | 553 | } |
@@ -537,8 +571,9 @@ discard block |
||
| 537 | 571 | array( |
| 538 | 572 | ) |
| 539 | 573 | ); |
| 540 | - if (!$request) |
|
| 541 | - return false; |
|
| 574 | + if (!$request) { |
|
| 575 | + return false; |
|
| 576 | + } |
|
| 542 | 577 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
| 543 | 578 | $smcFunc['db_free_result']($request); |
| 544 | 579 | |
@@ -559,12 +594,13 @@ discard block |
||
| 559 | 594 | // Decide which connection to use |
| 560 | 595 | $connection = $connection === null ? $db_connection : $connection; |
| 561 | 596 | |
| 562 | - if ($type == 'begin') |
|
| 563 | - return @pg_query($connection, 'BEGIN'); |
|
| 564 | - elseif ($type == 'rollback') |
|
| 565 | - return @pg_query($connection, 'ROLLBACK'); |
|
| 566 | - elseif ($type == 'commit') |
|
| 567 | - return @pg_query($connection, 'COMMIT'); |
|
| 597 | + if ($type == 'begin') { |
|
| 598 | + return @pg_query($connection, 'BEGIN'); |
|
| 599 | + } elseif ($type == 'rollback') { |
|
| 600 | + return @pg_query($connection, 'ROLLBACK'); |
|
| 601 | + } elseif ($type == 'commit') { |
|
| 602 | + return @pg_query($connection, 'COMMIT'); |
|
| 603 | + } |
|
| 568 | 604 | |
| 569 | 605 | return false; |
| 570 | 606 | } |
@@ -592,19 +628,22 @@ discard block |
||
| 592 | 628 | $query_error = @pg_last_error($connection); |
| 593 | 629 | |
| 594 | 630 | // Log the error. |
| 595 | - if (function_exists('log_error')) |
|
| 596 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
| 631 | + if (function_exists('log_error')) { |
|
| 632 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
| 633 | + } |
|
| 597 | 634 | |
| 598 | 635 | // Nothing's defined yet... just die with it. |
| 599 | - if (empty($context) || empty($txt)) |
|
| 600 | - die($query_error); |
|
| 636 | + if (empty($context) || empty($txt)) { |
|
| 637 | + die($query_error); |
|
| 638 | + } |
|
| 601 | 639 | |
| 602 | 640 | // Show an error message, if possible. |
| 603 | 641 | $context['error_title'] = $txt['database_error']; |
| 604 | - if (allowedTo('admin_forum')) |
|
| 605 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 606 | - else |
|
| 607 | - $context['error_message'] = $txt['try_again']; |
|
| 642 | + if (allowedTo('admin_forum')) { |
|
| 643 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 644 | + } else { |
|
| 645 | + $context['error_message'] = $txt['try_again']; |
|
| 646 | + } |
|
| 608 | 647 | |
| 609 | 648 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 610 | 649 | { |
@@ -626,12 +665,14 @@ discard block |
||
| 626 | 665 | { |
| 627 | 666 | global $db_row_count; |
| 628 | 667 | |
| 629 | - if ($counter !== false) |
|
| 630 | - return pg_fetch_row($request, $counter); |
|
| 668 | + if ($counter !== false) { |
|
| 669 | + return pg_fetch_row($request, $counter); |
|
| 670 | + } |
|
| 631 | 671 | |
| 632 | 672 | // Reset the row counter... |
| 633 | - if (!isset($db_row_count[(int) $request])) |
|
| 634 | - $db_row_count[(int) $request] = 0; |
|
| 673 | + if (!isset($db_row_count[(int) $request])) { |
|
| 674 | + $db_row_count[(int) $request] = 0; |
|
| 675 | + } |
|
| 635 | 676 | |
| 636 | 677 | // Return the right row. |
| 637 | 678 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -648,12 +689,14 @@ discard block |
||
| 648 | 689 | { |
| 649 | 690 | global $db_row_count; |
| 650 | 691 | |
| 651 | - if ($counter !== false) |
|
| 652 | - return pg_fetch_assoc($request, $counter); |
|
| 692 | + if ($counter !== false) { |
|
| 693 | + return pg_fetch_assoc($request, $counter); |
|
| 694 | + } |
|
| 653 | 695 | |
| 654 | 696 | // Reset the row counter... |
| 655 | - if (!isset($db_row_count[(int) $request])) |
|
| 656 | - $db_row_count[(int) $request] = 0; |
|
| 697 | + if (!isset($db_row_count[(int) $request])) { |
|
| 698 | + $db_row_count[(int) $request] = 0; |
|
| 699 | + } |
|
| 657 | 700 | |
| 658 | 701 | // Return the right row. |
| 659 | 702 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -706,11 +749,13 @@ discard block |
||
| 706 | 749 | |
| 707 | 750 | $replace = ''; |
| 708 | 751 | |
| 709 | - if (empty($data)) |
|
| 710 | - return; |
|
| 752 | + if (empty($data)) { |
|
| 753 | + return; |
|
| 754 | + } |
|
| 711 | 755 | |
| 712 | - if (!is_array($data[array_rand($data)])) |
|
| 713 | - $data = array($data); |
|
| 756 | + if (!is_array($data[array_rand($data)])) { |
|
| 757 | + $data = array($data); |
|
| 758 | + } |
|
| 714 | 759 | |
| 715 | 760 | // Replace the prefix holder with the actual prefix. |
| 716 | 761 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -729,11 +774,13 @@ discard block |
||
| 729 | 774 | //pg 9.5 got replace support |
| 730 | 775 | $pg_version = $smcFunc['db_get_version'](); |
| 731 | 776 | // if we got a Beta Version |
| 732 | - if (stripos($pg_version, 'beta') !== false) |
|
| 733 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
| 777 | + if (stripos($pg_version, 'beta') !== false) { |
|
| 778 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
| 779 | + } |
|
| 734 | 780 | // or RC |
| 735 | - if (stripos($pg_version, 'rc') !== false) |
|
| 736 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
| 781 | + if (stripos($pg_version, 'rc') !== false) { |
|
| 782 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
| 783 | + } |
|
| 737 | 784 | |
| 738 | 785 | $replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false); |
| 739 | 786 | } |
@@ -752,32 +799,35 @@ discard block |
||
| 752 | 799 | $key_str .= ($count_pk > 0 ? ',' : ''); |
| 753 | 800 | $key_str .= $columnName; |
| 754 | 801 | $count_pk++; |
| 755 | - } |
|
| 756 | - else if ($method == 'replace') //normal field |
|
| 802 | + } else if ($method == 'replace') { |
|
| 803 | + //normal field |
|
| 757 | 804 | { |
| 758 | 805 | $col_str .= ($count > 0 ? ',' : ''); |
| 806 | + } |
|
| 759 | 807 | $col_str .= $columnName . ' = EXCLUDED.' . $columnName; |
| 760 | 808 | $count++; |
| 761 | 809 | } |
| 762 | 810 | } |
| 763 | - if ($method == 'replace') |
|
| 764 | - $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
| 765 | - else |
|
| 766 | - $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
| 767 | - } |
|
| 768 | - else if ($method == 'replace') |
|
| 811 | + if ($method == 'replace') { |
|
| 812 | + $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
| 813 | + } else { |
|
| 814 | + $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
| 815 | + } |
|
| 816 | + } else if ($method == 'replace') |
|
| 769 | 817 | { |
| 770 | 818 | foreach ($columns as $columnName => $type) |
| 771 | 819 | { |
| 772 | 820 | // Are we restricting the length? |
| 773 | - if (strpos($type, 'string-') !== false) |
|
| 774 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 775 | - else |
|
| 776 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 821 | + if (strpos($type, 'string-') !== false) { |
|
| 822 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 823 | + } else { |
|
| 824 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 825 | + } |
|
| 777 | 826 | |
| 778 | 827 | // A key? That's what we were looking for. |
| 779 | - if (in_array($columnName, $keys)) |
|
| 780 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 828 | + if (in_array($columnName, $keys)) { |
|
| 829 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 830 | + } |
|
| 781 | 831 | $count++; |
| 782 | 832 | } |
| 783 | 833 | |
@@ -813,10 +863,11 @@ discard block |
||
| 813 | 863 | foreach ($columns as $columnName => $type) |
| 814 | 864 | { |
| 815 | 865 | // Are we restricting the length? |
| 816 | - if (strpos($type, 'string-') !== false) |
|
| 817 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 818 | - else |
|
| 819 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 866 | + if (strpos($type, 'string-') !== false) { |
|
| 867 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 868 | + } else { |
|
| 869 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 870 | + } |
|
| 820 | 871 | } |
| 821 | 872 | $insertData = substr($insertData, 0, -2) . ')'; |
| 822 | 873 | |
@@ -825,8 +876,9 @@ discard block |
||
| 825 | 876 | |
| 826 | 877 | // Here's where the variables are injected to the query. |
| 827 | 878 | $insertRows = array(); |
| 828 | - foreach ($data as $dataRow) |
|
| 829 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 879 | + foreach ($data as $dataRow) { |
|
| 880 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 881 | + } |
|
| 830 | 882 | |
| 831 | 883 | // Do the insert. |
| 832 | 884 | $request = $smcFunc['db_query']('', ' |
@@ -843,19 +895,21 @@ discard block |
||
| 843 | 895 | |
| 844 | 896 | if ($with_returning && $request !== false) |
| 845 | 897 | { |
| 846 | - if ($returnmode === 2) |
|
| 847 | - $return_var = array(); |
|
| 898 | + if ($returnmode === 2) { |
|
| 899 | + $return_var = array(); |
|
| 900 | + } |
|
| 848 | 901 | |
| 849 | 902 | while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
| 850 | 903 | { |
| 851 | - if (is_numeric($row[0])) // try to emulate mysql limitation |
|
| 904 | + if (is_numeric($row[0])) { |
|
| 905 | + // try to emulate mysql limitation |
|
| 852 | 906 | { |
| 853 | 907 | if ($returnmode === 1) |
| 854 | 908 | $return_var = $row[0]; |
| 855 | - elseif ($returnmode === 2) |
|
| 856 | - $return_var[] = $row[0]; |
|
| 857 | - } |
|
| 858 | - else |
|
| 909 | + } elseif ($returnmode === 2) { |
|
| 910 | + $return_var[] = $row[0]; |
|
| 911 | + } |
|
| 912 | + } else |
|
| 859 | 913 | { |
| 860 | 914 | $with_returning = false; |
| 861 | 915 | trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR); |
@@ -864,9 +918,10 @@ discard block |
||
| 864 | 918 | } |
| 865 | 919 | } |
| 866 | 920 | |
| 867 | - if ($with_returning && !empty($return_var)) |
|
| 868 | - return $return_var; |
|
| 869 | -} |
|
| 921 | + if ($with_returning && !empty($return_var)) { |
|
| 922 | + return $return_var; |
|
| 923 | + } |
|
| 924 | + } |
|
| 870 | 925 | |
| 871 | 926 | /** |
| 872 | 927 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -903,8 +958,9 @@ discard block |
||
| 903 | 958 | */ |
| 904 | 959 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 905 | 960 | { |
| 906 | - if (empty($log_message)) |
|
| 907 | - $log_message = $error_message; |
|
| 961 | + if (empty($log_message)) { |
|
| 962 | + $log_message = $error_message; |
|
| 963 | + } |
|
| 908 | 964 | |
| 909 | 965 | foreach (debug_backtrace() as $step) |
| 910 | 966 | { |
@@ -923,12 +979,14 @@ discard block |
||
| 923 | 979 | } |
| 924 | 980 | |
| 925 | 981 | // A special case - we want the file and line numbers for debugging. |
| 926 | - if ($error_type == 'return') |
|
| 927 | - return array($file, $line); |
|
| 982 | + if ($error_type == 'return') { |
|
| 983 | + return array($file, $line); |
|
| 984 | + } |
|
| 928 | 985 | |
| 929 | 986 | // Is always a critical error. |
| 930 | - if (function_exists('log_error')) |
|
| 931 | - log_error($log_message, 'critical', $file, $line); |
|
| 987 | + if (function_exists('log_error')) { |
|
| 988 | + log_error($log_message, 'critical', $file, $line); |
|
| 989 | + } |
|
| 932 | 990 | |
| 933 | 991 | if (function_exists('fatal_error')) |
| 934 | 992 | { |
@@ -936,12 +994,12 @@ discard block |
||
| 936 | 994 | |
| 937 | 995 | // Cannot continue... |
| 938 | 996 | exit; |
| 997 | + } elseif ($error_type) { |
|
| 998 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 999 | + } else { |
|
| 1000 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 1001 | + } |
|
| 939 | 1002 | } |
| 940 | - elseif ($error_type) |
|
| 941 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 942 | - else |
|
| 943 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 944 | -} |
|
| 945 | 1003 | |
| 946 | 1004 | /** |
| 947 | 1005 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -958,10 +1016,11 @@ discard block |
||
| 958 | 1016 | '\\' => '\\\\', |
| 959 | 1017 | ); |
| 960 | 1018 | |
| 961 | - if ($translate_human_wildcards) |
|
| 962 | - $replacements += array( |
|
| 1019 | + if ($translate_human_wildcards) { |
|
| 1020 | + $replacements += array( |
|
| 963 | 1021 | '*' => '%', |
| 964 | 1022 | ); |
| 1023 | + } |
|
| 965 | 1024 | |
| 966 | 1025 | return strtr($string, $replacements); |
| 967 | 1026 | } |
@@ -989,11 +1048,12 @@ discard block |
||
| 989 | 1048 | global $db_prefix, $db_connection; |
| 990 | 1049 | static $pg_error_data_prep; |
| 991 | 1050 | |
| 992 | - if (empty($pg_error_data_prep)) |
|
| 993 | - $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
| 1051 | + if (empty($pg_error_data_prep)) { |
|
| 1052 | + $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
| 994 | 1053 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line) |
| 995 | 1054 | VALUES( $1, $2, $3, $4, $5, $6, $7, $8, $9)' |
| 996 | 1055 | ); |
| 1056 | + } |
|
| 997 | 1057 | |
| 998 | 1058 | pg_execute($db_connection, 'smf_log_errors', $error_array); |
| 999 | 1059 | } |
@@ -1013,8 +1073,9 @@ discard block |
||
| 1013 | 1073 | $count = count($array_values); |
| 1014 | 1074 | $then = ($desc ? ' THEN -' : ' THEN '); |
| 1015 | 1075 | |
| 1016 | - for ($i = 0; $i < $count; $i++) |
|
| 1017 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
| 1076 | + for ($i = 0; $i < $count; $i++) { |
|
| 1077 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
| 1078 | + } |
|
| 1018 | 1079 | |
| 1019 | 1080 | $return .= 'END'; |
| 1020 | 1081 | return $return; |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Truncate the GET array to a specified length |
@@ -26,14 +27,15 @@ discard block |
||
| 26 | 27 | function truncateArray($arr, $max_length=1900) |
| 27 | 28 | { |
| 28 | 29 | $curr_length = array_sum(array_map("strlen", $arr)); |
| 29 | - if ($curr_length <= $max_length) |
|
| 30 | - return $arr; |
|
| 31 | - else |
|
| 30 | + if ($curr_length <= $max_length) { |
|
| 31 | + return $arr; |
|
| 32 | + } else |
|
| 32 | 33 | { |
| 33 | 34 | // Truncate each element's value to a reasonable length |
| 34 | 35 | $param_max = floor($max_length/count($arr)); |
| 35 | - foreach ($arr as $key => &$value) |
|
| 36 | - $value = substr($value, 0, $param_max - strlen($key) - 5); |
|
| 36 | + foreach ($arr as $key => &$value) { |
|
| 37 | + $value = substr($value, 0, $param_max - strlen($key) - 5); |
|
| 38 | + } |
|
| 37 | 39 | return $arr; |
| 38 | 40 | } |
| 39 | 41 | } |
@@ -55,8 +57,9 @@ discard block |
||
| 55 | 57 | // Don't update for every page - this isn't wholly accurate but who cares. |
| 56 | 58 | if ($topic) |
| 57 | 59 | { |
| 58 | - if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) |
|
| 59 | - $force = false; |
|
| 60 | + if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) { |
|
| 61 | + $force = false; |
|
| 62 | + } |
|
| 60 | 63 | $_SESSION['last_topic_id'] = $topic; |
| 61 | 64 | } |
| 62 | 65 | } |
@@ -69,22 +72,24 @@ discard block |
||
| 69 | 72 | } |
| 70 | 73 | |
| 71 | 74 | // Don't mark them as online more than every so often. |
| 72 | - if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) |
|
| 73 | - return; |
|
| 75 | + if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) { |
|
| 76 | + return; |
|
| 77 | + } |
|
| 74 | 78 | |
| 75 | 79 | if (!empty($modSettings['who_enabled'])) |
| 76 | 80 | { |
| 77 | 81 | $encoded_get = truncateArray($_GET) + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']); |
| 78 | 82 | |
| 79 | 83 | // In the case of a dlattach action, session_var may not be set. |
| 80 | - if (!isset($context['session_var'])) |
|
| 81 | - $context['session_var'] = $_SESSION['session_var']; |
|
| 84 | + if (!isset($context['session_var'])) { |
|
| 85 | + $context['session_var'] = $_SESSION['session_var']; |
|
| 86 | + } |
|
| 82 | 87 | |
| 83 | 88 | unset($encoded_get['sesc'], $encoded_get[$context['session_var']]); |
| 84 | 89 | $encoded_get = $smcFunc['json_encode']($encoded_get); |
| 90 | + } else { |
|
| 91 | + $encoded_get = ''; |
|
| 85 | 92 | } |
| 86 | - else |
|
| 87 | - $encoded_get = ''; |
|
| 88 | 93 | |
| 89 | 94 | // Guests use 0, members use their session ID. |
| 90 | 95 | $session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id(); |
@@ -124,17 +129,18 @@ discard block |
||
| 124 | 129 | ); |
| 125 | 130 | |
| 126 | 131 | // Guess it got deleted. |
| 127 | - if ($smcFunc['db_affected_rows']() == 0) |
|
| 132 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
| 133 | + $_SESSION['log_time'] = 0; |
|
| 134 | + } |
|
| 135 | + } else { |
|
| 128 | 136 | $_SESSION['log_time'] = 0; |
| 129 | 137 | } |
| 130 | - else |
|
| 131 | - $_SESSION['log_time'] = 0; |
|
| 132 | 138 | |
| 133 | 139 | // Otherwise, we have to delete and insert. |
| 134 | 140 | if (empty($_SESSION['log_time'])) |
| 135 | 141 | { |
| 136 | - if ($do_delete || !empty($user_info['id'])) |
|
| 137 | - $smcFunc['db_query']('', ' |
|
| 142 | + if ($do_delete || !empty($user_info['id'])) { |
|
| 143 | + $smcFunc['db_query']('', ' |
|
| 138 | 144 | DELETE FROM {db_prefix}log_online |
| 139 | 145 | WHERE ' . ($do_delete ? 'log_time < {int:log_time}' : '') . ($do_delete && !empty($user_info['id']) ? ' OR ' : '') . (empty($user_info['id']) ? '' : 'id_member = {int:current_member}'), |
| 140 | 146 | array( |
@@ -142,6 +148,7 @@ discard block |
||
| 142 | 148 | 'log_time' => time() - $modSettings['lastActive'] * 60, |
| 143 | 149 | ) |
| 144 | 150 | ); |
| 151 | + } |
|
| 145 | 152 | |
| 146 | 153 | $smcFunc['db_insert']($do_delete ? 'ignore' : 'replace', |
| 147 | 154 | '{db_prefix}log_online', |
@@ -155,21 +162,24 @@ discard block |
||
| 155 | 162 | $_SESSION['log_time'] = time(); |
| 156 | 163 | |
| 157 | 164 | // Well, they are online now. |
| 158 | - if (empty($_SESSION['timeOnlineUpdated'])) |
|
| 159 | - $_SESSION['timeOnlineUpdated'] = time(); |
|
| 165 | + if (empty($_SESSION['timeOnlineUpdated'])) { |
|
| 166 | + $_SESSION['timeOnlineUpdated'] = time(); |
|
| 167 | + } |
|
| 160 | 168 | |
| 161 | 169 | // Set their login time, if not already done within the last minute. |
| 162 | 170 | if (SMF != 'SSI' && !empty($user_info['last_login']) && $user_info['last_login'] < time() - 60 && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('.xml', 'login2', 'logintfa')))) |
| 163 | 171 | { |
| 164 | 172 | // Don't count longer than 15 minutes. |
| 165 | - if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) |
|
| 166 | - $_SESSION['timeOnlineUpdated'] = time(); |
|
| 173 | + if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) { |
|
| 174 | + $_SESSION['timeOnlineUpdated'] = time(); |
|
| 175 | + } |
|
| 167 | 176 | |
| 168 | 177 | $user_settings['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated']; |
| 169 | 178 | updateMemberData($user_info['id'], array('last_login' => time(), 'member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'], 'total_time_logged_in' => $user_settings['total_time_logged_in'])); |
| 170 | 179 | |
| 171 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 172 | - cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60); |
|
| 180 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 181 | + cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60); |
|
| 182 | + } |
|
| 173 | 183 | |
| 174 | 184 | $user_info['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated']; |
| 175 | 185 | $_SESSION['timeOnlineUpdated'] = time(); |
@@ -206,8 +216,7 @@ discard block |
||
| 206 | 216 | // Oops. maybe we have no more disk space left, or some other troubles, troubles... |
| 207 | 217 | // Copy the file back and run for your life! |
| 208 | 218 | @copy($boarddir . '/db_last_error_bak.php', $boarddir . '/db_last_error.php'); |
| 209 | - } |
|
| 210 | - else |
|
| 219 | + } else |
|
| 211 | 220 | { |
| 212 | 221 | @touch($boarddir . '/' . 'Settings.php'); |
| 213 | 222 | return true; |
@@ -227,22 +236,27 @@ discard block |
||
| 227 | 236 | global $db_cache, $db_count, $cache_misses, $cache_count_misses, $db_show_debug, $cache_count, $cache_hits, $smcFunc, $txt; |
| 228 | 237 | |
| 229 | 238 | // Add to Settings.php if you want to show the debugging information. |
| 230 | - if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) |
|
| 231 | - return; |
|
| 239 | + if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) { |
|
| 240 | + return; |
|
| 241 | + } |
|
| 232 | 242 | |
| 233 | - if (empty($_SESSION['view_queries'])) |
|
| 234 | - $_SESSION['view_queries'] = 0; |
|
| 235 | - if (empty($context['debug']['language_files'])) |
|
| 236 | - $context['debug']['language_files'] = array(); |
|
| 237 | - if (empty($context['debug']['sheets'])) |
|
| 238 | - $context['debug']['sheets'] = array(); |
|
| 243 | + if (empty($_SESSION['view_queries'])) { |
|
| 244 | + $_SESSION['view_queries'] = 0; |
|
| 245 | + } |
|
| 246 | + if (empty($context['debug']['language_files'])) { |
|
| 247 | + $context['debug']['language_files'] = array(); |
|
| 248 | + } |
|
| 249 | + if (empty($context['debug']['sheets'])) { |
|
| 250 | + $context['debug']['sheets'] = array(); |
|
| 251 | + } |
|
| 239 | 252 | |
| 240 | 253 | $files = get_included_files(); |
| 241 | 254 | $total_size = 0; |
| 242 | 255 | for ($i = 0, $n = count($files); $i < $n; $i++) |
| 243 | 256 | { |
| 244 | - if (file_exists($files[$i])) |
|
| 245 | - $total_size += filesize($files[$i]); |
|
| 257 | + if (file_exists($files[$i])) { |
|
| 258 | + $total_size += filesize($files[$i]); |
|
| 259 | + } |
|
| 246 | 260 | $files[$i] = strtr($files[$i], array($boarddir => '.', $sourcedir => '(Sources)', $cachedir => '(Cache)', $settings['actual_theme_dir'] => '(Current Theme)')); |
| 247 | 261 | } |
| 248 | 262 | |
@@ -251,8 +265,9 @@ discard block |
||
| 251 | 265 | { |
| 252 | 266 | foreach ($db_cache as $q => $qq) |
| 253 | 267 | { |
| 254 | - if (!empty($qq['w'])) |
|
| 255 | - $warnings += count($qq['w']); |
|
| 268 | + if (!empty($qq['w'])) { |
|
| 269 | + $warnings += count($qq['w']); |
|
| 270 | + } |
|
| 256 | 271 | } |
| 257 | 272 | |
| 258 | 273 | $_SESSION['debug'] = &$db_cache; |
@@ -273,12 +288,14 @@ discard block |
||
| 273 | 288 | ',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),' |
| 274 | 289 | ', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>'; |
| 275 | 290 | |
| 276 | - if (function_exists('memory_get_peak_usage')) |
|
| 277 | - echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>'; |
|
| 291 | + if (function_exists('memory_get_peak_usage')) { |
|
| 292 | + echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>'; |
|
| 293 | + } |
|
| 278 | 294 | |
| 279 | 295 | // What tokens are active? |
| 280 | - if (isset($_SESSION['token'])) |
|
| 281 | - echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>'; |
|
| 296 | + if (isset($_SESSION['token'])) { |
|
| 297 | + echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>'; |
|
| 298 | + } |
|
| 282 | 299 | |
| 283 | 300 | if (!empty($modSettings['cache_enable']) && !empty($cache_hits)) |
| 284 | 301 | { |
@@ -292,10 +309,12 @@ discard block |
||
| 292 | 309 | $total_t += $cache_hit['t']; |
| 293 | 310 | $total_s += $cache_hit['s']; |
| 294 | 311 | } |
| 295 | - if (!isset($cache_misses)) |
|
| 296 | - $cache_misses = array(); |
|
| 297 | - foreach ($cache_misses as $missed) |
|
| 298 | - $missed_entries[] = $missed['d'] . ' ' . $missed['k']; |
|
| 312 | + if (!isset($cache_misses)) { |
|
| 313 | + $cache_misses = array(); |
|
| 314 | + } |
|
| 315 | + foreach ($cache_misses as $missed) { |
|
| 316 | + $missed_entries[] = $missed['d'] . ' ' . $missed['k']; |
|
| 317 | + } |
|
| 299 | 318 | |
| 300 | 319 | echo ' |
| 301 | 320 | ', $txt['debug_cache_hits'], $cache_count, ': ', sprintf($txt['debug_cache_seconds_bytes_total'], comma_format($total_t, 5), comma_format($total_s)), ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_cache_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_cache_info" style="display: none;"><em>', implode('</em>, <em>', $entries), '</em></span>)<br> |
@@ -306,38 +325,44 @@ discard block |
||
| 306 | 325 | <a href="', $scripturl, '?action=viewquery" target="_blank" rel="noopener">', $warnings == 0 ? sprintf($txt['debug_queries_used'], (int) $db_count) : sprintf($txt['debug_queries_used_and_warnings'], (int) $db_count, $warnings), '</a><br> |
| 307 | 326 | <br>'; |
| 308 | 327 | |
| 309 | - if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) |
|
| 310 | - foreach ($db_cache as $q => $qq) |
|
| 328 | + if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) { |
|
| 329 | + foreach ($db_cache as $q => $qq) |
|
| 311 | 330 | { |
| 312 | 331 | $is_select = strpos(trim($qq['q']), 'SELECT') === 0 || preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+SELECT .+$~s', trim($qq['q'])) != 0; |
| 332 | + } |
|
| 313 | 333 | // Temporary tables created in earlier queries are not explainable. |
| 314 | 334 | if ($is_select) |
| 315 | 335 | { |
| 316 | - foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) |
|
| 317 | - if (strpos(trim($qq['q']), $tmp) !== false) |
|
| 336 | + foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) { |
|
| 337 | + if (strpos(trim($qq['q']), $tmp) !== false) |
|
| 318 | 338 | { |
| 319 | 339 | $is_select = false; |
| 340 | + } |
|
| 320 | 341 | break; |
| 321 | 342 | } |
| 322 | 343 | } |
| 323 | 344 | // But actual creation of the temporary tables are. |
| 324 | - elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0) |
|
| 325 | - $is_select = true; |
|
| 345 | + elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0) { |
|
| 346 | + $is_select = true; |
|
| 347 | + } |
|
| 326 | 348 | |
| 327 | 349 | // Make the filenames look a bit better. |
| 328 | - if (isset($qq['f'])) |
|
| 329 | - $qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']); |
|
| 350 | + if (isset($qq['f'])) { |
|
| 351 | + $qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']); |
|
| 352 | + } |
|
| 330 | 353 | |
| 331 | 354 | echo ' |
| 332 | 355 | <strong>', $is_select ? '<a href="' . $scripturl . '?action=viewquery;qq=' . ($q + 1) . '#qq' . $q . '" target="_blank" rel="noopener" style="text-decoration: none;">' : '', nl2br(str_replace("\t", ' ', $smcFunc['htmlspecialchars'](ltrim($qq['q'], "\n\r")))) . ($is_select ? '</a></strong>' : '</strong>') . '<br> |
| 333 | 356 | '; |
| 334 | - if (!empty($qq['f']) && !empty($qq['l'])) |
|
| 335 | - echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']); |
|
| 357 | + if (!empty($qq['f']) && !empty($qq['l'])) { |
|
| 358 | + echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']); |
|
| 359 | + } |
|
| 336 | 360 | |
| 337 | - if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at'])) |
|
| 338 | - echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br>'; |
|
| 339 | - elseif (isset($qq['t'])) |
|
| 340 | - echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br>'; |
|
| 361 | + if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at'])) { |
|
| 362 | + echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br>'; |
|
| 363 | + } elseif (isset($qq['t'])) { |
|
| 364 | + echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br>'; |
|
| 365 | + } |
|
| 341 | 366 | echo ' |
| 342 | 367 | <br>'; |
| 343 | 368 | } |
@@ -362,12 +387,14 @@ discard block |
||
| 362 | 387 | global $modSettings, $smcFunc; |
| 363 | 388 | static $cache_stats = array(); |
| 364 | 389 | |
| 365 | - if (empty($modSettings['trackStats'])) |
|
| 366 | - return false; |
|
| 367 | - if (!empty($stats)) |
|
| 368 | - return $cache_stats = array_merge($cache_stats, $stats); |
|
| 369 | - elseif (empty($cache_stats)) |
|
| 370 | - return false; |
|
| 390 | + if (empty($modSettings['trackStats'])) { |
|
| 391 | + return false; |
|
| 392 | + } |
|
| 393 | + if (!empty($stats)) { |
|
| 394 | + return $cache_stats = array_merge($cache_stats, $stats); |
|
| 395 | + } elseif (empty($cache_stats)) { |
|
| 396 | + return false; |
|
| 397 | + } |
|
| 371 | 398 | |
| 372 | 399 | $setStringUpdate = ''; |
| 373 | 400 | $insert_keys = array(); |
@@ -380,10 +407,11 @@ discard block |
||
| 380 | 407 | $setStringUpdate .= ' |
| 381 | 408 | ' . $field . ' = ' . ($change === '+' ? $field . ' + 1' : '{int:' . $field . '}') . ','; |
| 382 | 409 | |
| 383 | - if ($change === '+') |
|
| 384 | - $cache_stats[$field] = 1; |
|
| 385 | - else |
|
| 386 | - $update_parameters[$field] = $change; |
|
| 410 | + if ($change === '+') { |
|
| 411 | + $cache_stats[$field] = 1; |
|
| 412 | + } else { |
|
| 413 | + $update_parameters[$field] = $change; |
|
| 414 | + } |
|
| 387 | 415 | $insert_keys[$field] = 'int'; |
| 388 | 416 | } |
| 389 | 417 | |
@@ -447,43 +475,50 @@ discard block |
||
| 447 | 475 | ); |
| 448 | 476 | |
| 449 | 477 | // Make sure this particular log is enabled first... |
| 450 | - if (empty($modSettings['modlog_enabled'])) |
|
| 451 | - unset ($log_types['moderate']); |
|
| 452 | - if (empty($modSettings['userlog_enabled'])) |
|
| 453 | - unset ($log_types['user']); |
|
| 454 | - if (empty($modSettings['adminlog_enabled'])) |
|
| 455 | - unset ($log_types['admin']); |
|
| 478 | + if (empty($modSettings['modlog_enabled'])) { |
|
| 479 | + unset ($log_types['moderate']); |
|
| 480 | + } |
|
| 481 | + if (empty($modSettings['userlog_enabled'])) { |
|
| 482 | + unset ($log_types['user']); |
|
| 483 | + } |
|
| 484 | + if (empty($modSettings['adminlog_enabled'])) { |
|
| 485 | + unset ($log_types['admin']); |
|
| 486 | + } |
|
| 456 | 487 | |
| 457 | 488 | call_integration_hook('integrate_log_types', array(&$log_types)); |
| 458 | 489 | |
| 459 | 490 | foreach ($logs as $log) |
| 460 | 491 | { |
| 461 | - if (!isset($log_types[$log['log_type']])) |
|
| 462 | - return false; |
|
| 492 | + if (!isset($log_types[$log['log_type']])) { |
|
| 493 | + return false; |
|
| 494 | + } |
|
| 463 | 495 | |
| 464 | - if (!is_array($log['extra'])) |
|
| 465 | - trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE); |
|
| 496 | + if (!is_array($log['extra'])) { |
|
| 497 | + trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE); |
|
| 498 | + } |
|
| 466 | 499 | |
| 467 | 500 | // Pull out the parts we want to store separately, but also make sure that the data is proper |
| 468 | 501 | if (isset($log['extra']['topic'])) |
| 469 | 502 | { |
| 470 | - if (!is_numeric($log['extra']['topic'])) |
|
| 471 | - trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE); |
|
| 503 | + if (!is_numeric($log['extra']['topic'])) { |
|
| 504 | + trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE); |
|
| 505 | + } |
|
| 472 | 506 | $topic_id = empty($log['extra']['topic']) ? 0 : (int) $log['extra']['topic']; |
| 473 | 507 | unset($log['extra']['topic']); |
| 508 | + } else { |
|
| 509 | + $topic_id = 0; |
|
| 474 | 510 | } |
| 475 | - else |
|
| 476 | - $topic_id = 0; |
|
| 477 | 511 | |
| 478 | 512 | if (isset($log['extra']['message'])) |
| 479 | 513 | { |
| 480 | - if (!is_numeric($log['extra']['message'])) |
|
| 481 | - trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE); |
|
| 514 | + if (!is_numeric($log['extra']['message'])) { |
|
| 515 | + trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE); |
|
| 516 | + } |
|
| 482 | 517 | $msg_id = empty($log['extra']['message']) ? 0 : (int) $log['extra']['message']; |
| 483 | 518 | unset($log['extra']['message']); |
| 519 | + } else { |
|
| 520 | + $msg_id = 0; |
|
| 484 | 521 | } |
| 485 | - else |
|
| 486 | - $msg_id = 0; |
|
| 487 | 522 | |
| 488 | 523 | // @todo cache this? |
| 489 | 524 | // Is there an associated report on this? |
@@ -510,23 +545,26 @@ discard block |
||
| 510 | 545 | $smcFunc['db_free_result']($request); |
| 511 | 546 | } |
| 512 | 547 | |
| 513 | - if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) |
|
| 514 | - trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE); |
|
| 548 | + if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) { |
|
| 549 | + trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE); |
|
| 550 | + } |
|
| 515 | 551 | |
| 516 | 552 | if (isset($log['extra']['board'])) |
| 517 | 553 | { |
| 518 | - if (!is_numeric($log['extra']['board'])) |
|
| 519 | - trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE); |
|
| 554 | + if (!is_numeric($log['extra']['board'])) { |
|
| 555 | + trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE); |
|
| 556 | + } |
|
| 520 | 557 | $board_id = empty($log['extra']['board']) ? 0 : (int) $log['extra']['board']; |
| 521 | 558 | unset($log['extra']['board']); |
| 559 | + } else { |
|
| 560 | + $board_id = 0; |
|
| 522 | 561 | } |
| 523 | - else |
|
| 524 | - $board_id = 0; |
|
| 525 | 562 | |
| 526 | 563 | if (isset($log['extra']['board_to'])) |
| 527 | 564 | { |
| 528 | - if (!is_numeric($log['extra']['board_to'])) |
|
| 529 | - trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE); |
|
| 565 | + if (!is_numeric($log['extra']['board_to'])) { |
|
| 566 | + trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE); |
|
| 567 | + } |
|
| 530 | 568 | if (empty($board_id)) |
| 531 | 569 | { |
| 532 | 570 | $board_id = empty($log['extra']['board_to']) ? 0 : (int) $log['extra']['board_to']; |
@@ -534,10 +572,11 @@ discard block |
||
| 534 | 572 | } |
| 535 | 573 | } |
| 536 | 574 | |
| 537 | - if (isset($log['extra']['member_affected'])) |
|
| 538 | - $memID = $log['extra']['member_affected']; |
|
| 539 | - else |
|
| 540 | - $memID = $user_info['id']; |
|
| 575 | + if (isset($log['extra']['member_affected'])) { |
|
| 576 | + $memID = $log['extra']['member_affected']; |
|
| 577 | + } else { |
|
| 578 | + $memID = $user_info['id']; |
|
| 579 | + } |
|
| 541 | 580 | |
| 542 | 581 | $inserts[] = array( |
| 543 | 582 | time(), $log_types[$log['log_type']], $memID, $user_info['ip'], $log['action'], |
@@ -349,7 +349,7 @@ |
||
| 349 | 349 | SELECT |
| 350 | 350 | t.id_topic, t.num_replies, t.locked, t.num_views, t.is_sticky, t.id_poll, t.id_previous_board, |
| 351 | 351 | ' . ($user_info['is_guest'] ? '0' : 'COALESCE(lt.id_msg, COALESCE(lmr.id_msg, -1)) + 1') . ' AS new_from, |
| 352 | - ' . ( $enableParticipation ? ' COALESCE(( SELECT 1 FROM {db_prefix}messages AS parti WHERE t.id_topic = parti.id_topic and parti.id_member = {int:current_member} LIMIT 1) , 0) as is_posted_in, |
|
| 352 | + ' . ($enableParticipation ? ' COALESCE(( SELECT 1 FROM {db_prefix}messages AS parti WHERE t.id_topic = parti.id_topic and parti.id_member = {int:current_member} LIMIT 1) , 0) as is_posted_in, |
|
| 353 | 353 | ' : '') . ' |
| 354 | 354 | t.id_last_msg, t.approved, t.unapproved_posts, ml.poster_time AS last_poster_time, t.id_redirect_topic, |
| 355 | 355 | ml.id_msg_modified, ml.subject AS last_subject, ml.icon AS last_icon, |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 4 |
| 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 | * Show the list of topics in this board, along with any child boards. |
@@ -56,8 +57,9 @@ discard block |
||
| 56 | 57 | |
| 57 | 58 | $context['name'] = $board_info['name']; |
| 58 | 59 | $context['description'] = $board_info['description']; |
| 59 | - if (!empty($board_info['description'])) |
|
| 60 | - $context['meta_description'] = strip_tags($board_info['description']); |
|
| 60 | + if (!empty($board_info['description'])) { |
|
| 61 | + $context['meta_description'] = strip_tags($board_info['description']); |
|
| 62 | + } |
|
| 61 | 63 | |
| 62 | 64 | // How many topics do we have in total? |
| 63 | 65 | $board_info['total_topics'] = allowedTo('approve_posts') ? $board_info['num_topics'] + $board_info['unapproved_topics'] : $board_info['num_topics'] + $board_info['unapproved_user_topics']; |
@@ -73,12 +75,14 @@ discard block |
||
| 73 | 75 | $session_name = session_name(); |
| 74 | 76 | foreach ($_GET as $k => $v) |
| 75 | 77 | { |
| 76 | - if (!in_array($k, array('board', 'start', $session_name))) |
|
| 77 | - $context['robot_no_index'] = true; |
|
| 78 | + if (!in_array($k, array('board', 'start', $session_name))) { |
|
| 79 | + $context['robot_no_index'] = true; |
|
| 80 | + } |
|
| 78 | 81 | } |
| 79 | 82 | } |
| 80 | - if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) |
|
| 81 | - $context['robot_no_index'] = true; |
|
| 83 | + if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) { |
|
| 84 | + $context['robot_no_index'] = true; |
|
| 85 | + } |
|
| 82 | 86 | |
| 83 | 87 | // If we can view unapproved messages and there are some build up a list. |
| 84 | 88 | if (allowedTo('approve_posts') && ($board_info['unapproved_topics'] || $board_info['unapproved_posts'])) |
@@ -89,14 +93,16 @@ discard block |
||
| 89 | 93 | } |
| 90 | 94 | |
| 91 | 95 | // We only know these. |
| 92 | - if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post'))) |
|
| 93 | - $_REQUEST['sort'] = 'last_post'; |
|
| 96 | + if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post'))) { |
|
| 97 | + $_REQUEST['sort'] = 'last_post'; |
|
| 98 | + } |
|
| 94 | 99 | |
| 95 | 100 | // Make sure the starting place makes sense and construct the page index. |
| 96 | - if (isset($_REQUEST['sort'])) |
|
| 97 | - $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true); |
|
| 98 | - else |
|
| 99 | - $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true); |
|
| 101 | + if (isset($_REQUEST['sort'])) { |
|
| 102 | + $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true); |
|
| 103 | + } else { |
|
| 104 | + $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true); |
|
| 105 | + } |
|
| 100 | 106 | $context['start'] = &$_REQUEST['start']; |
| 101 | 107 | |
| 102 | 108 | // Set a canonical URL for this page. |
@@ -132,14 +138,16 @@ discard block |
||
| 132 | 138 | $context['link_moderators'] = array(); |
| 133 | 139 | if (!empty($board_info['moderators'])) |
| 134 | 140 | { |
| 135 | - foreach ($board_info['moderators'] as $mod) |
|
| 136 | - $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
|
| 141 | + foreach ($board_info['moderators'] as $mod) { |
|
| 142 | + $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
|
| 143 | + } |
|
| 137 | 144 | } |
| 138 | 145 | if (!empty($board_info['moderator_groups'])) |
| 139 | 146 | { |
| 140 | 147 | // By default just tack the moderator groups onto the end of the members |
| 141 | - foreach ($board_info['moderator_groups'] as $mod_group) |
|
| 142 | - $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
|
| 148 | + foreach ($board_info['moderator_groups'] as $mod_group) { |
|
| 149 | + $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
|
| 150 | + } |
|
| 143 | 151 | } |
| 144 | 152 | |
| 145 | 153 | // Now we tack the info onto the end of the linktree |
@@ -191,20 +199,24 @@ discard block |
||
| 191 | 199 | ); |
| 192 | 200 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 193 | 201 | { |
| 194 | - if (empty($row['id_member'])) |
|
| 195 | - continue; |
|
| 202 | + if (empty($row['id_member'])) { |
|
| 203 | + continue; |
|
| 204 | + } |
|
| 196 | 205 | |
| 197 | - if (!empty($row['online_color'])) |
|
| 198 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
| 199 | - else |
|
| 200 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 206 | + if (!empty($row['online_color'])) { |
|
| 207 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
| 208 | + } else { |
|
| 209 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 210 | + } |
|
| 201 | 211 | |
| 202 | 212 | $is_buddy = in_array($row['id_member'], $user_info['buddies']); |
| 203 | - if ($is_buddy) |
|
| 204 | - $link = '<strong>' . $link . '</strong>'; |
|
| 213 | + if ($is_buddy) { |
|
| 214 | + $link = '<strong>' . $link . '</strong>'; |
|
| 215 | + } |
|
| 205 | 216 | |
| 206 | - if (!empty($row['show_online']) || allowedTo('moderate_forum')) |
|
| 207 | - $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
|
| 217 | + if (!empty($row['show_online']) || allowedTo('moderate_forum')) { |
|
| 218 | + $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
|
| 219 | + } |
|
| 208 | 220 | // @todo why are we filling this array of data that are just counted (twice) and discarded? ??? |
| 209 | 221 | $context['view_members'][$row['log_time'] . $row['member_name']] = array( |
| 210 | 222 | 'id' => $row['id_member'], |
@@ -217,8 +229,9 @@ discard block |
||
| 217 | 229 | 'hidden' => empty($row['show_online']), |
| 218 | 230 | ); |
| 219 | 231 | |
| 220 | - if (empty($row['show_online'])) |
|
| 221 | - $context['view_num_hidden']++; |
|
| 232 | + if (empty($row['show_online'])) { |
|
| 233 | + $context['view_num_hidden']++; |
|
| 234 | + } |
|
| 222 | 235 | } |
| 223 | 236 | $context['view_num_guests'] = $smcFunc['db_num_rows']($request) - count($context['view_members']); |
| 224 | 237 | $smcFunc['db_free_result']($request); |
@@ -260,8 +273,9 @@ discard block |
||
| 260 | 273 | // Bring in any changes we want to make before the query. |
| 261 | 274 | call_integration_hook('integrate_pre_messageindex', array(&$sort_methods)); |
| 262 | 275 | |
| 263 | - foreach ($sort_methods as $key => $val) |
|
| 264 | - $context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>'; |
|
| 276 | + foreach ($sort_methods as $key => $val) { |
|
| 277 | + $context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>'; |
|
| 278 | + } |
|
| 265 | 279 | |
| 266 | 280 | // Calculate the fastest way to get the topics. |
| 267 | 281 | $start = (int) $_REQUEST['start']; |
@@ -271,14 +285,15 @@ discard block |
||
| 271 | 285 | $fake_ascending = true; |
| 272 | 286 | $context['maxindex'] = $board_info['total_topics'] < $start + $context['maxindex'] + 1 ? $board_info['total_topics'] - $start : $context['maxindex']; |
| 273 | 287 | $start = $board_info['total_topics'] < $start + $context['maxindex'] + 1 ? 0 : $board_info['total_topics'] - $start - $context['maxindex']; |
| 288 | + } else { |
|
| 289 | + $fake_ascending = false; |
|
| 274 | 290 | } |
| 275 | - else |
|
| 276 | - $fake_ascending = false; |
|
| 277 | 291 | |
| 278 | 292 | // Setup the default topic icons... |
| 279 | 293 | $context['icon_sources'] = array(); |
| 280 | - foreach ($context['stable_icons'] as $icon) |
|
| 281 | - $context['icon_sources'][$icon] = 'images_url'; |
|
| 294 | + foreach ($context['stable_icons'] as $icon) { |
|
| 295 | + $context['icon_sources'][$icon] = 'images_url'; |
|
| 296 | + } |
|
| 282 | 297 | |
| 283 | 298 | $topic_ids = array(); |
| 284 | 299 | $context['topics'] = array(); |
@@ -316,8 +331,9 @@ discard block |
||
| 316 | 331 | $message_pre_index_parameters |
| 317 | 332 | ); |
| 318 | 333 | $topic_ids = array(); |
| 319 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 320 | - $topic_ids[] = $row['id_topic']; |
|
| 334 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 335 | + $topic_ids[] = $row['id_topic']; |
|
| 336 | + } |
|
| 321 | 337 | } |
| 322 | 338 | |
| 323 | 339 | // Grab the appropriate topic information... |
@@ -340,10 +356,11 @@ discard block |
||
| 340 | 356 | $message_index_wheres = array(); |
| 341 | 357 | call_integration_hook('integrate_message_index', array(&$message_index_selects, &$message_index_tables, &$message_index_parameters, &$message_index_wheres, &$topic_ids)); |
| 342 | 358 | |
| 343 | - if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest']) |
|
| 344 | - $enableParticipation = true; |
|
| 345 | - else |
|
| 346 | - $enableParticipation = false; |
|
| 359 | + if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest']) { |
|
| 360 | + $enableParticipation = true; |
|
| 361 | + } else { |
|
| 362 | + $enableParticipation = false; |
|
| 363 | + } |
|
| 347 | 364 | |
| 348 | 365 | $result = $smcFunc['db_query']('substring', ' |
| 349 | 366 | SELECT |
@@ -382,11 +399,13 @@ discard block |
||
| 382 | 399 | // Begin 'printing' the message index for current board. |
| 383 | 400 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 384 | 401 | { |
| 385 | - if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') |
|
| 386 | - continue; |
|
| 402 | + if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') { |
|
| 403 | + continue; |
|
| 404 | + } |
|
| 387 | 405 | |
| 388 | - if (!$pre_query) |
|
| 389 | - $topic_ids[] = $row['id_topic']; |
|
| 406 | + if (!$pre_query) { |
|
| 407 | + $topic_ids[] = $row['id_topic']; |
|
| 408 | + } |
|
| 390 | 409 | |
| 391 | 410 | // Reference the main color class. |
| 392 | 411 | $colorClass = 'windowbg'; |
@@ -396,8 +415,9 @@ discard block |
||
| 396 | 415 | { |
| 397 | 416 | // Limit them to $modSettings['preview_characters'] characters |
| 398 | 417 | $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => ' '))); |
| 399 | - if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters']) |
|
| 400 | - $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...'; |
|
| 418 | + if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters']) { |
|
| 419 | + $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...'; |
|
| 420 | + } |
|
| 401 | 421 | |
| 402 | 422 | // Censor the subject and message preview. |
| 403 | 423 | censorText($row['first_subject']); |
@@ -408,27 +428,27 @@ discard block |
||
| 408 | 428 | { |
| 409 | 429 | $row['last_subject'] = $row['first_subject']; |
| 410 | 430 | $row['last_body'] = $row['first_body']; |
| 411 | - } |
|
| 412 | - else |
|
| 431 | + } else |
|
| 413 | 432 | { |
| 414 | 433 | $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => ' '))); |
| 415 | - if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters']) |
|
| 416 | - $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...'; |
|
| 434 | + if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters']) { |
|
| 435 | + $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...'; |
|
| 436 | + } |
|
| 417 | 437 | |
| 418 | 438 | censorText($row['last_subject']); |
| 419 | 439 | censorText($row['last_body']); |
| 420 | 440 | } |
| 421 | - } |
|
| 422 | - else |
|
| 441 | + } else |
|
| 423 | 442 | { |
| 424 | 443 | $row['first_body'] = ''; |
| 425 | 444 | $row['last_body'] = ''; |
| 426 | 445 | censorText($row['first_subject']); |
| 427 | 446 | |
| 428 | - if ($row['id_first_msg'] == $row['id_last_msg']) |
|
| 429 | - $row['last_subject'] = $row['first_subject']; |
|
| 430 | - else |
|
| 431 | - censorText($row['last_subject']); |
|
| 447 | + if ($row['id_first_msg'] == $row['id_last_msg']) { |
|
| 448 | + $row['last_subject'] = $row['first_subject']; |
|
| 449 | + } else { |
|
| 450 | + censorText($row['last_subject']); |
|
| 451 | + } |
|
| 432 | 452 | } |
| 433 | 453 | |
| 434 | 454 | // Decide how many pages the topic should have. |
@@ -439,42 +459,50 @@ discard block |
||
| 439 | 459 | $pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true, false); |
| 440 | 460 | |
| 441 | 461 | // If we can use all, show all. |
| 442 | - if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages']) |
|
| 443 | - $pages .= ' <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>'; |
|
| 462 | + if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages']) { |
|
| 463 | + $pages .= ' <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>'; |
|
| 464 | + } |
|
| 465 | + } else { |
|
| 466 | + $pages = ''; |
|
| 444 | 467 | } |
| 445 | - else |
|
| 446 | - $pages = ''; |
|
| 447 | 468 | |
| 448 | 469 | // We need to check the topic icons exist... |
| 449 | 470 | if (!empty($modSettings['messageIconChecks_enable'])) |
| 450 | 471 | { |
| 451 | - if (!isset($context['icon_sources'][$row['first_icon']])) |
|
| 452 | - $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 453 | - if (!isset($context['icon_sources'][$row['last_icon']])) |
|
| 454 | - $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 455 | - } |
|
| 456 | - else |
|
| 472 | + if (!isset($context['icon_sources'][$row['first_icon']])) { |
|
| 473 | + $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 474 | + } |
|
| 475 | + if (!isset($context['icon_sources'][$row['last_icon']])) { |
|
| 476 | + $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 477 | + } |
|
| 478 | + } else |
|
| 457 | 479 | { |
| 458 | - if (!isset($context['icon_sources'][$row['first_icon']])) |
|
| 459 | - $context['icon_sources'][$row['first_icon']] = 'images_url'; |
|
| 460 | - if (!isset($context['icon_sources'][$row['last_icon']])) |
|
| 461 | - $context['icon_sources'][$row['last_icon']] = 'images_url'; |
|
| 480 | + if (!isset($context['icon_sources'][$row['first_icon']])) { |
|
| 481 | + $context['icon_sources'][$row['first_icon']] = 'images_url'; |
|
| 482 | + } |
|
| 483 | + if (!isset($context['icon_sources'][$row['last_icon']])) { |
|
| 484 | + $context['icon_sources'][$row['last_icon']] = 'images_url'; |
|
| 485 | + } |
|
| 462 | 486 | } |
| 463 | 487 | |
| 464 | - if (!empty($board_info['recycle'])) |
|
| 465 | - $row['first_icon'] = 'recycled'; |
|
| 488 | + if (!empty($board_info['recycle'])) { |
|
| 489 | + $row['first_icon'] = 'recycled'; |
|
| 490 | + } |
|
| 466 | 491 | |
| 467 | 492 | // Is this topic pending approval, or does it have any posts pending approval? |
| 468 | - if ($context['can_approve_posts'] && $row['unapproved_posts']) |
|
| 469 | - $colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost'); |
|
| 493 | + if ($context['can_approve_posts'] && $row['unapproved_posts']) { |
|
| 494 | + $colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost'); |
|
| 495 | + } |
|
| 470 | 496 | |
| 471 | 497 | // Sticky topics should get a different color, too. |
| 472 | - if ($row['is_sticky']) |
|
| 473 | - $colorClass .= ' sticky'; |
|
| 498 | + if ($row['is_sticky']) { |
|
| 499 | + $colorClass .= ' sticky'; |
|
| 500 | + } |
|
| 474 | 501 | |
| 475 | 502 | // Locked topics get special treatment as well. |
| 476 | - if ($row['locked']) |
|
| 477 | - $colorClass .= ' locked'; |
|
| 503 | + if ($row['locked']) { |
|
| 504 | + $colorClass .= ' locked'; |
|
| 505 | + } |
|
| 478 | 506 | |
| 479 | 507 | // 'Print' the topic info. |
| 480 | 508 | $context['topics'][$row['id_topic']] = array_merge($row, array( |
@@ -555,8 +583,9 @@ discard block |
||
| 555 | 583 | $smcFunc['db_free_result']($result); |
| 556 | 584 | |
| 557 | 585 | // Fix the sequence of topics if they were retrieved in the wrong order. (for speed reasons...) |
| 558 | - if ($fake_ascending) |
|
| 559 | - $context['topics'] = array_reverse($context['topics'], true); |
|
| 586 | + if ($fake_ascending) { |
|
| 587 | + $context['topics'] = array_reverse($context['topics'], true); |
|
| 588 | + } |
|
| 560 | 589 | } |
| 561 | 590 | |
| 562 | 591 | $context['jump_to'] = array( |
@@ -579,9 +608,9 @@ discard block |
||
| 579 | 608 | // Can we restore topics? |
| 580 | 609 | $context['can_restore'] = allowedTo('move_any') && !empty($board_info['recycle']); |
| 581 | 610 | |
| 582 | - if ($user_info['is_admin'] || $modSettings['topic_move_any']) |
|
| 583 | - $context['can_move_any'] = true; |
|
| 584 | - else |
|
| 611 | + if ($user_info['is_admin'] || $modSettings['topic_move_any']) { |
|
| 612 | + $context['can_move_any'] = true; |
|
| 613 | + } else |
|
| 585 | 614 | { |
| 586 | 615 | // We'll use this in a minute |
| 587 | 616 | $boards_allowed = boardsAllowedTo('post_new'); |
@@ -608,11 +637,13 @@ discard block |
||
| 608 | 637 | } |
| 609 | 638 | |
| 610 | 639 | // Can we use quick moderation checkboxes? |
| 611 | - if ($options['display_quick_mod'] == 1) |
|
| 612 | - $context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore']; |
|
| 640 | + if ($options['display_quick_mod'] == 1) { |
|
| 641 | + $context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore']; |
|
| 642 | + } |
|
| 613 | 643 | // Or the icons? |
| 614 | - else |
|
| 615 | - $context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move']; |
|
| 644 | + else { |
|
| 645 | + $context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move']; |
|
| 646 | + } |
|
| 616 | 647 | } |
| 617 | 648 | |
| 618 | 649 | if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1) |
@@ -646,13 +677,15 @@ discard block |
||
| 646 | 677 | ); |
| 647 | 678 | |
| 648 | 679 | // We've seen all these boards now! |
| 649 | - foreach ($board_info['parent_boards'] as $k => $dummy) |
|
| 650 | - if (isset($_SESSION['topicseen_cache'][$k])) |
|
| 680 | + foreach ($board_info['parent_boards'] as $k => $dummy) { |
|
| 681 | + if (isset($_SESSION['topicseen_cache'][$k])) |
|
| 651 | 682 | unset($_SESSION['topicseen_cache'][$k]); |
| 683 | + } |
|
| 652 | 684 | } |
| 653 | 685 | |
| 654 | - if (isset($_SESSION['topicseen_cache'][$board])) |
|
| 655 | - unset($_SESSION['topicseen_cache'][$board]); |
|
| 686 | + if (isset($_SESSION['topicseen_cache'][$board])) { |
|
| 687 | + unset($_SESSION['topicseen_cache'][$board]); |
|
| 688 | + } |
|
| 656 | 689 | |
| 657 | 690 | $request = $smcFunc['db_query']('', ' |
| 658 | 691 | SELECT id_topic, id_board, sent |
@@ -673,8 +706,9 @@ discard block |
||
| 673 | 706 | $context['is_marked_notify'] = true; |
| 674 | 707 | $board_sent = $row['sent']; |
| 675 | 708 | } |
| 676 | - if (!empty($row['id_topic'])) |
|
| 677 | - $context['topics'][$row['id_topic']]['is_watched'] = true; |
|
| 709 | + if (!empty($row['id_topic'])) { |
|
| 710 | + $context['topics'][$row['id_topic']]['is_watched'] = true; |
|
| 711 | + } |
|
| 678 | 712 | } |
| 679 | 713 | $smcFunc['db_free_result']($request); |
| 680 | 714 | |
@@ -698,8 +732,7 @@ discard block |
||
| 698 | 732 | $pref = !empty($pref[$user_info['id']]) ? $pref[$user_info['id']] : array(); |
| 699 | 733 | $pref = isset($pref['board_notify_' . $board]) ? $pref['board_notify_' . $board] : (!empty($pref['board_notify']) ? $pref['board_notify'] : 0); |
| 700 | 734 | $context['board_notification_mode'] = !$context['is_marked_notify'] ? 1 : ($pref & 0x02 ? 3 : ($pref & 0x01 ? 2 : 1)); |
| 701 | - } |
|
| 702 | - else |
|
| 735 | + } else |
|
| 703 | 736 | { |
| 704 | 737 | $context['is_marked_notify'] = false; |
| 705 | 738 | $context['board_notification_mode'] = 1; |
@@ -712,23 +745,27 @@ discard block |
||
| 712 | 745 | $context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false; |
| 713 | 746 | |
| 714 | 747 | // Don't want to show this forever... |
| 715 | - if ($context['becomesUnapproved']) |
|
| 716 | - unset($_SESSION['becomesUnapproved']); |
|
| 748 | + if ($context['becomesUnapproved']) { |
|
| 749 | + unset($_SESSION['becomesUnapproved']); |
|
| 750 | + } |
|
| 717 | 751 | |
| 718 | 752 | // Build the message index button array. |
| 719 | 753 | $context['normal_buttons'] = array(); |
| 720 | 754 | |
| 721 | - if ($context['can_post_new']) |
|
| 722 | - $context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true); |
|
| 755 | + if ($context['can_post_new']) { |
|
| 756 | + $context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true); |
|
| 757 | + } |
|
| 723 | 758 | |
| 724 | - if ($context['can_post_poll']) |
|
| 725 | - $context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll'); |
|
| 759 | + if ($context['can_post_poll']) { |
|
| 760 | + $context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll'); |
|
| 761 | + } |
|
| 726 | 762 | |
| 727 | - if (!$context['user']['is_logged']) |
|
| 728 | - $context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']); |
|
| 763 | + if (!$context['user']['is_logged']) { |
|
| 764 | + $context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']); |
|
| 765 | + } |
|
| 729 | 766 | |
| 730 | - if ($context['can_mark_notify']) |
|
| 731 | - $context['normal_buttons']['notify'] = array( |
|
| 767 | + if ($context['can_mark_notify']) { |
|
| 768 | + $context['normal_buttons']['notify'] = array( |
|
| 732 | 769 | 'lang' => true, |
| 733 | 770 | 'text' => 'notify_board_' . $context['board_notification_mode'], |
| 734 | 771 | 'sub_buttons' => array( |
@@ -746,6 +783,7 @@ discard block |
||
| 746 | 783 | ), |
| 747 | 784 | ), |
| 748 | 785 | ); |
| 786 | + } |
|
| 749 | 787 | |
| 750 | 788 | // Javascript for inline editing. |
| 751 | 789 | loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic'); |
@@ -767,18 +805,21 @@ discard block |
||
| 767 | 805 | checkSession('request'); |
| 768 | 806 | |
| 769 | 807 | // Lets go straight to the restore area. |
| 770 | - if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics'])) |
|
| 771 | - redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 808 | + if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics'])) { |
|
| 809 | + redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 810 | + } |
|
| 772 | 811 | |
| 773 | - if (isset($_SESSION['topicseen_cache'])) |
|
| 774 | - $_SESSION['topicseen_cache'] = array(); |
|
| 812 | + if (isset($_SESSION['topicseen_cache'])) { |
|
| 813 | + $_SESSION['topicseen_cache'] = array(); |
|
| 814 | + } |
|
| 775 | 815 | |
| 776 | 816 | // This is going to be needed to send off the notifications and for updateLastMessages(). |
| 777 | 817 | require_once($sourcedir . '/Subs-Post.php'); |
| 778 | 818 | |
| 779 | 819 | // Remember the last board they moved things to. |
| 780 | - if (isset($_REQUEST['move_to'])) |
|
| 781 | - $_SESSION['move_to_topic'] = $_REQUEST['move_to']; |
|
| 820 | + if (isset($_REQUEST['move_to'])) { |
|
| 821 | + $_SESSION['move_to_topic'] = $_REQUEST['move_to']; |
|
| 822 | + } |
|
| 782 | 823 | |
| 783 | 824 | // Only a few possible actions. |
| 784 | 825 | $possibleActions = array(); |
@@ -798,8 +839,7 @@ discard block |
||
| 798 | 839 | ); |
| 799 | 840 | |
| 800 | 841 | $redirect_url = 'board=' . $board . '.' . $_REQUEST['start']; |
| 801 | - } |
|
| 802 | - else |
|
| 842 | + } else |
|
| 803 | 843 | { |
| 804 | 844 | /** |
| 805 | 845 | * @todo Ugly. There's no getting around this, is there? |
@@ -817,8 +857,7 @@ discard block |
||
| 817 | 857 | if (!empty($board)) |
| 818 | 858 | { |
| 819 | 859 | $boards_can['post_new'] = array_diff(boardsAllowedTo('post_new'), array($board)); |
| 820 | - } |
|
| 821 | - else |
|
| 860 | + } else |
|
| 822 | 861 | { |
| 823 | 862 | $boards_can['post_new'] = boardsAllowedTo('post_new'); |
| 824 | 863 | } |
@@ -829,55 +868,67 @@ discard block |
||
| 829 | 868 | } |
| 830 | 869 | } |
| 831 | 870 | |
| 832 | - if (!$user_info['is_guest']) |
|
| 833 | - $possibleActions[] = 'markread'; |
|
| 834 | - if (!empty($boards_can['make_sticky'])) |
|
| 835 | - $possibleActions[] = 'sticky'; |
|
| 836 | - if (!empty($boards_can['move_any']) || !empty($boards_can['move_own'])) |
|
| 837 | - $possibleActions[] = 'move'; |
|
| 838 | - if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own'])) |
|
| 839 | - $possibleActions[] = 'remove'; |
|
| 840 | - if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own'])) |
|
| 841 | - $possibleActions[] = 'lock'; |
|
| 842 | - if (!empty($boards_can['merge_any'])) |
|
| 843 | - $possibleActions[] = 'merge'; |
|
| 844 | - if (!empty($boards_can['approve_posts'])) |
|
| 845 | - $possibleActions[] = 'approve'; |
|
| 871 | + if (!$user_info['is_guest']) { |
|
| 872 | + $possibleActions[] = 'markread'; |
|
| 873 | + } |
|
| 874 | + if (!empty($boards_can['make_sticky'])) { |
|
| 875 | + $possibleActions[] = 'sticky'; |
|
| 876 | + } |
|
| 877 | + if (!empty($boards_can['move_any']) || !empty($boards_can['move_own'])) { |
|
| 878 | + $possibleActions[] = 'move'; |
|
| 879 | + } |
|
| 880 | + if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own'])) { |
|
| 881 | + $possibleActions[] = 'remove'; |
|
| 882 | + } |
|
| 883 | + if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own'])) { |
|
| 884 | + $possibleActions[] = 'lock'; |
|
| 885 | + } |
|
| 886 | + if (!empty($boards_can['merge_any'])) { |
|
| 887 | + $possibleActions[] = 'merge'; |
|
| 888 | + } |
|
| 889 | + if (!empty($boards_can['approve_posts'])) { |
|
| 890 | + $possibleActions[] = 'approve'; |
|
| 891 | + } |
|
| 846 | 892 | |
| 847 | 893 | // Two methods: $_REQUEST['actions'] (id_topic => action), and $_REQUEST['topics'] and $_REQUEST['qaction']. |
| 848 | 894 | // (if action is 'move', $_REQUEST['move_to'] or $_REQUEST['move_tos'][$topic] is used.) |
| 849 | 895 | if (!empty($_REQUEST['topics'])) |
| 850 | 896 | { |
| 851 | 897 | // If the action isn't valid, just quit now. |
| 852 | - if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions)) |
|
| 853 | - redirectexit($redirect_url); |
|
| 898 | + if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions)) { |
|
| 899 | + redirectexit($redirect_url); |
|
| 900 | + } |
|
| 854 | 901 | |
| 855 | 902 | // Merge requires all topics as one parameter and can be done at once. |
| 856 | 903 | if ($_REQUEST['qaction'] == 'merge') |
| 857 | 904 | { |
| 858 | 905 | // Merge requires at least two topics. |
| 859 | - if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2) |
|
| 860 | - redirectexit($redirect_url); |
|
| 906 | + if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2) { |
|
| 907 | + redirectexit($redirect_url); |
|
| 908 | + } |
|
| 861 | 909 | |
| 862 | 910 | require_once($sourcedir . '/SplitTopics.php'); |
| 863 | 911 | return MergeExecute($_REQUEST['topics']); |
| 864 | 912 | } |
| 865 | 913 | |
| 866 | 914 | // Just convert to the other method, to make it easier. |
| 867 | - foreach ($_REQUEST['topics'] as $topic) |
|
| 868 | - $_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction']; |
|
| 915 | + foreach ($_REQUEST['topics'] as $topic) { |
|
| 916 | + $_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction']; |
|
| 917 | + } |
|
| 869 | 918 | } |
| 870 | 919 | |
| 871 | 920 | // Weird... how'd you get here? |
| 872 | - if (empty($_REQUEST['actions'])) |
|
| 873 | - redirectexit($redirect_url); |
|
| 921 | + if (empty($_REQUEST['actions'])) { |
|
| 922 | + redirectexit($redirect_url); |
|
| 923 | + } |
|
| 874 | 924 | |
| 875 | 925 | // Validate each action. |
| 876 | 926 | $temp = array(); |
| 877 | 927 | foreach ($_REQUEST['actions'] as $topic => $action) |
| 878 | 928 | { |
| 879 | - if (in_array($action, $possibleActions)) |
|
| 880 | - $temp[(int) $topic] = $action; |
|
| 929 | + if (in_array($action, $possibleActions)) { |
|
| 930 | + $temp[(int) $topic] = $action; |
|
| 931 | + } |
|
| 881 | 932 | } |
| 882 | 933 | $_REQUEST['actions'] = $temp; |
| 883 | 934 | |
@@ -898,27 +949,31 @@ discard block |
||
| 898 | 949 | { |
| 899 | 950 | if (!empty($board)) |
| 900 | 951 | { |
| 901 | - if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts'))) |
|
| 902 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
| 903 | - } |
|
| 904 | - else |
|
| 952 | + if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts'))) { |
|
| 953 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
| 954 | + } |
|
| 955 | + } else |
|
| 905 | 956 | { |
| 906 | 957 | // Don't allow them to act on unapproved posts they can't see... |
| 907 | - if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])) |
|
| 908 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
| 958 | + if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])) { |
|
| 959 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
| 960 | + } |
|
| 909 | 961 | // Goodness, this is fun. We need to validate the action. |
| 910 | - elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky'])) |
|
| 911 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
| 912 | - elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own'])))) |
|
| 913 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
| 914 | - elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own'])))) |
|
| 915 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
| 962 | + elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky'])) { |
|
| 963 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
| 964 | + } elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own'])))) { |
|
| 965 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
| 966 | + } elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own'])))) { |
|
| 967 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
| 968 | + } |
|
| 916 | 969 | // @todo $locked is not set, what are you trying to do? (taking the change it is supposed to be $row['locked']) |
| 917 | - elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own'])))) |
|
| 918 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
| 970 | + elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own'])))) { |
|
| 971 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
| 972 | + } |
|
| 919 | 973 | // If the topic is approved then you need permission to approve the posts within. |
| 920 | - elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])))) |
|
| 921 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
| 974 | + elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])))) { |
|
| 975 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
| 976 | + } |
|
| 922 | 977 | } |
| 923 | 978 | } |
| 924 | 979 | $smcFunc['db_free_result']($request); |
@@ -936,11 +991,11 @@ discard block |
||
| 936 | 991 | { |
| 937 | 992 | $topic = (int) $topic; |
| 938 | 993 | |
| 939 | - if ($action == 'markread') |
|
| 940 | - $markCache[] = $topic; |
|
| 941 | - elseif ($action == 'sticky') |
|
| 942 | - $stickyCache[] = $topic; |
|
| 943 | - elseif ($action == 'move') |
|
| 994 | + if ($action == 'markread') { |
|
| 995 | + $markCache[] = $topic; |
|
| 996 | + } elseif ($action == 'sticky') { |
|
| 997 | + $stickyCache[] = $topic; |
|
| 998 | + } elseif ($action == 'move') |
|
| 944 | 999 | { |
| 945 | 1000 | require_once($sourcedir . '/MoveTopic.php'); |
| 946 | 1001 | moveTopicConcurrence(); |
@@ -948,23 +1003,25 @@ discard block |
||
| 948 | 1003 | // $moveCache[0] is the topic, $moveCache[1] is the board to move to. |
| 949 | 1004 | $moveCache[1][$topic] = (int) (isset($_REQUEST['move_tos'][$topic]) ? $_REQUEST['move_tos'][$topic] : $_REQUEST['move_to']); |
| 950 | 1005 | |
| 951 | - if (empty($moveCache[1][$topic])) |
|
| 952 | - continue; |
|
| 1006 | + if (empty($moveCache[1][$topic])) { |
|
| 1007 | + continue; |
|
| 1008 | + } |
|
| 953 | 1009 | |
| 954 | 1010 | $moveCache[0][] = $topic; |
| 1011 | + } elseif ($action == 'remove') { |
|
| 1012 | + $removeCache[] = $topic; |
|
| 1013 | + } elseif ($action == 'lock') { |
|
| 1014 | + $lockCache[] = $topic; |
|
| 1015 | + } elseif ($action == 'approve') { |
|
| 1016 | + $approveCache[] = $topic; |
|
| 955 | 1017 | } |
| 956 | - elseif ($action == 'remove') |
|
| 957 | - $removeCache[] = $topic; |
|
| 958 | - elseif ($action == 'lock') |
|
| 959 | - $lockCache[] = $topic; |
|
| 960 | - elseif ($action == 'approve') |
|
| 961 | - $approveCache[] = $topic; |
|
| 962 | 1018 | } |
| 963 | 1019 | |
| 964 | - if (empty($board)) |
|
| 965 | - $affectedBoards = array(); |
|
| 966 | - else |
|
| 967 | - $affectedBoards = array($board => array(0, 0)); |
|
| 1020 | + if (empty($board)) { |
|
| 1021 | + $affectedBoards = array(); |
|
| 1022 | + } else { |
|
| 1023 | + $affectedBoards = array($board => array(0, 0)); |
|
| 1024 | + } |
|
| 968 | 1025 | |
| 969 | 1026 | // Do all the stickies... |
| 970 | 1027 | if (!empty($stickyCache)) |
@@ -1024,14 +1081,16 @@ discard block |
||
| 1024 | 1081 | { |
| 1025 | 1082 | $to = $moveCache[1][$row['id_topic']]; |
| 1026 | 1083 | |
| 1027 | - if (empty($to)) |
|
| 1028 | - continue; |
|
| 1084 | + if (empty($to)) { |
|
| 1085 | + continue; |
|
| 1086 | + } |
|
| 1029 | 1087 | |
| 1030 | 1088 | // Does this topic's board count the posts or not? |
| 1031 | 1089 | $countPosts[$row['id_topic']] = empty($row['count_posts']); |
| 1032 | 1090 | |
| 1033 | - if (!isset($moveTos[$to])) |
|
| 1034 | - $moveTos[$to] = array(); |
|
| 1091 | + if (!isset($moveTos[$to])) { |
|
| 1092 | + $moveTos[$to] = array(); |
|
| 1093 | + } |
|
| 1035 | 1094 | |
| 1036 | 1095 | $moveTos[$to][] = $row['id_topic']; |
| 1037 | 1096 | |
@@ -1045,8 +1104,9 @@ discard block |
||
| 1045 | 1104 | require_once($sourcedir . '/MoveTopic.php'); |
| 1046 | 1105 | |
| 1047 | 1106 | // Do the actual moves... |
| 1048 | - foreach ($moveTos as $to => $topics) |
|
| 1049 | - moveTopics($topics, $to); |
|
| 1107 | + foreach ($moveTos as $to => $topics) { |
|
| 1108 | + moveTopics($topics, $to); |
|
| 1109 | + } |
|
| 1050 | 1110 | |
| 1051 | 1111 | // Does the post counts need to be updated? |
| 1052 | 1112 | if (!empty($moveTos)) |
@@ -1095,20 +1155,23 @@ discard block |
||
| 1095 | 1155 | |
| 1096 | 1156 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1097 | 1157 | { |
| 1098 | - if (!isset($members[$row['id_member']])) |
|
| 1099 | - $members[$row['id_member']] = 0; |
|
| 1158 | + if (!isset($members[$row['id_member']])) { |
|
| 1159 | + $members[$row['id_member']] = 0; |
|
| 1160 | + } |
|
| 1100 | 1161 | |
| 1101 | - if ($topicRecounts[$row['id_topic']] === '+') |
|
| 1102 | - $members[$row['id_member']] += 1; |
|
| 1103 | - else |
|
| 1104 | - $members[$row['id_member']] -= 1; |
|
| 1162 | + if ($topicRecounts[$row['id_topic']] === '+') { |
|
| 1163 | + $members[$row['id_member']] += 1; |
|
| 1164 | + } else { |
|
| 1165 | + $members[$row['id_member']] -= 1; |
|
| 1166 | + } |
|
| 1105 | 1167 | } |
| 1106 | 1168 | |
| 1107 | 1169 | $smcFunc['db_free_result']($request); |
| 1108 | 1170 | |
| 1109 | 1171 | // And now update them member's post counts |
| 1110 | - foreach ($members as $id_member => $post_adj) |
|
| 1111 | - updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj)); |
|
| 1172 | + foreach ($members as $id_member => $post_adj) { |
|
| 1173 | + updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj)); |
|
| 1174 | + } |
|
| 1112 | 1175 | |
| 1113 | 1176 | } |
| 1114 | 1177 | } |
@@ -1188,8 +1251,9 @@ discard block |
||
| 1188 | 1251 | approveTopics($approveCache); |
| 1189 | 1252 | |
| 1190 | 1253 | // Time for some logging! |
| 1191 | - foreach ($approveCache as $topic) |
|
| 1192 | - logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic])); |
|
| 1254 | + foreach ($approveCache as $topic) { |
|
| 1255 | + logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic])); |
|
| 1256 | + } |
|
| 1193 | 1257 | } |
| 1194 | 1258 | } |
| 1195 | 1259 | |
@@ -1224,8 +1288,7 @@ discard block |
||
| 1224 | 1288 | $lockStatus[$row['id_topic']] = empty($row['locked']); |
| 1225 | 1289 | } |
| 1226 | 1290 | $smcFunc['db_free_result']($result); |
| 1227 | - } |
|
| 1228 | - else |
|
| 1291 | + } else |
|
| 1229 | 1292 | { |
| 1230 | 1293 | $result = $smcFunc['db_query']('', ' |
| 1231 | 1294 | SELECT id_topic, locked, id_board |
@@ -1275,13 +1338,15 @@ discard block |
||
| 1275 | 1338 | ) |
| 1276 | 1339 | ); |
| 1277 | 1340 | $logged_topics = array(); |
| 1278 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1279 | - $logged_topics[$row['id_topic']] = $row['unwatched']; |
|
| 1341 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1342 | + $logged_topics[$row['id_topic']] = $row['unwatched']; |
|
| 1343 | + } |
|
| 1280 | 1344 | $smcFunc['db_free_result']($request); |
| 1281 | 1345 | |
| 1282 | 1346 | $markArray = array(); |
| 1283 | - foreach ($markCache as $topic) |
|
| 1284 | - $markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0)); |
|
| 1347 | + foreach ($markCache as $topic) { |
|
| 1348 | + $markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0)); |
|
| 1349 | + } |
|
| 1285 | 1350 | |
| 1286 | 1351 | $smcFunc['db_insert']('replace', |
| 1287 | 1352 | '{db_prefix}log_topics', |
@@ -1294,8 +1359,9 @@ discard block |
||
| 1294 | 1359 | foreach ($moveCache as $topic) |
| 1295 | 1360 | { |
| 1296 | 1361 | // Didn't actually move anything! |
| 1297 | - if (!isset($topic[0])) |
|
| 1298 | - break; |
|
| 1362 | + if (!isset($topic[0])) { |
|
| 1363 | + break; |
|
| 1364 | + } |
|
| 1299 | 1365 | |
| 1300 | 1366 | logAction('move', array('topic' => $topic[0], 'board_from' => $topic[1], 'board_to' => $topic[2])); |
| 1301 | 1367 | sendNotifications($topic[0], 'move'); |
@@ -1317,8 +1383,9 @@ discard block |
||
| 1317 | 1383 | 'calendar_updated' => time(), |
| 1318 | 1384 | )); |
| 1319 | 1385 | |
| 1320 | - if (!empty($affectedBoards)) |
|
| 1321 | - updateLastMessages(array_keys($affectedBoards)); |
|
| 1386 | + if (!empty($affectedBoards)) { |
|
| 1387 | + updateLastMessages(array_keys($affectedBoards)); |
|
| 1388 | + } |
|
| 1322 | 1389 | |
| 1323 | 1390 | redirectexit($redirect_url); |
| 1324 | 1391 | } |