@@ -303,7 +303,7 @@ |
||
| 303 | 303 | ), |
| 304 | 304 | array( |
| 305 | 305 | $_POST['msg'], $message['id_topic'], $message['id_board'], $message['id_poster'], $message['real_name'], |
| 306 | - $message['subject'], $message['body'] , time(), time(), 1, 0, |
|
| 306 | + $message['subject'], $message['body'], time(), time(), 1, 0, |
|
| 307 | 307 | ), |
| 308 | 308 | array('id_report') |
| 309 | 309 | ); |
@@ -12,8 +12,9 @@ discard block |
||
| 12 | 12 | * @version 2.1 Beta 3 |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -if (!defined('SMF')) |
|
| 15 | +if (!defined('SMF')) { |
|
| 16 | 16 | die('No direct access...'); |
| 17 | +} |
|
| 17 | 18 | |
| 18 | 19 | /** |
| 19 | 20 | * Report a post or profile to the moderator... ask for a comment. |
@@ -35,10 +36,11 @@ discard block |
||
| 35 | 36 | |
| 36 | 37 | // You can't use this if it's off or you are not allowed to do it. |
| 37 | 38 | // If we don't have the ID of something to report, we'll die with a no_access error below |
| 38 | - if (isset($_REQUEST['msg'])) |
|
| 39 | - isAllowedTo('report_any'); |
|
| 40 | - elseif (isset($_REQUEST['u'])) |
|
| 41 | - isAllowedTo('report_user'); |
|
| 39 | + if (isset($_REQUEST['msg'])) { |
|
| 40 | + isAllowedTo('report_any'); |
|
| 41 | + } elseif (isset($_REQUEST['u'])) { |
|
| 42 | + isAllowedTo('report_user'); |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | // Previewing or modifying? |
| 44 | 46 | if (isset($_POST['preview']) && !isset($_POST['save'])) |
@@ -56,19 +58,23 @@ discard block |
||
| 56 | 58 | } |
| 57 | 59 | |
| 58 | 60 | // If they're posting, it should be processed by ReportToModerator2. |
| 59 | - if ((isset($_POST[$context['session_var']]) || isset($_POST['save'])) && empty($context['post_errors']) && !isset($_POST['preview'])) |
|
| 60 | - ReportToModerator2(); |
|
| 61 | + if ((isset($_POST[$context['session_var']]) || isset($_POST['save'])) && empty($context['post_errors']) && !isset($_POST['preview'])) { |
|
| 62 | + ReportToModerator2(); |
|
| 63 | + } |
|
| 61 | 64 | |
| 62 | 65 | // We need a message ID or user ID to check! |
| 63 | - if (empty($_REQUEST['msg']) && empty($_REQUEST['mid']) && empty($_REQUEST['u'])) |
|
| 64 | - fatal_lang_error('no_access', false); |
|
| 66 | + if (empty($_REQUEST['msg']) && empty($_REQUEST['mid']) && empty($_REQUEST['u'])) { |
|
| 67 | + fatal_lang_error('no_access', false); |
|
| 68 | + } |
|
| 65 | 69 | |
| 66 | 70 | // For compatibility, accept mid, but we should be using msg. (not the flavor kind!) |
| 67 | - if (!empty($_REQUEST['msg']) || !empty($_REQUEST['mid'])) |
|
| 68 | - $_REQUEST['msg'] = empty($_REQUEST['msg']) ? (int) $_REQUEST['mid'] : (int) $_REQUEST['msg']; |
|
| 71 | + if (!empty($_REQUEST['msg']) || !empty($_REQUEST['mid'])) { |
|
| 72 | + $_REQUEST['msg'] = empty($_REQUEST['msg']) ? (int) $_REQUEST['mid'] : (int) $_REQUEST['msg']; |
|
| 73 | + } |
|
| 69 | 74 | // msg and mid empty - assume we're reporting a user |
| 70 | - elseif (!empty($_REQUEST['u'])) |
|
| 71 | - $_REQUEST['u'] = (int) $_REQUEST['u']; |
|
| 75 | + elseif (!empty($_REQUEST['u'])) { |
|
| 76 | + $_REQUEST['u'] = (int) $_REQUEST['u']; |
|
| 77 | + } |
|
| 72 | 78 | |
| 73 | 79 | // Set up some form values |
| 74 | 80 | $context['report_type'] = isset($_REQUEST['msg']) ? 'msg' : 'u'; |
@@ -89,8 +95,9 @@ discard block |
||
| 89 | 95 | 'id_msg' => $_REQUEST['msg'], |
| 90 | 96 | ) |
| 91 | 97 | ); |
| 92 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
| 93 | - fatal_lang_error('no_board', false); |
|
| 98 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
| 99 | + fatal_lang_error('no_board', false); |
|
| 100 | + } |
|
| 94 | 101 | list ($_REQUEST['msg'], $member, $starter) = $smcFunc['db_fetch_row']($result); |
| 95 | 102 | $smcFunc['db_free_result']($result); |
| 96 | 103 | |
@@ -101,8 +108,7 @@ discard block |
||
| 101 | 108 | |
| 102 | 109 | // The submit URL is different for users than it is for posts |
| 103 | 110 | $context['submit_url'] = $scripturl . '?action=reporttm;msg=' . $_REQUEST['msg'] . ';topic=' . $topic; |
| 104 | - } |
|
| 105 | - else |
|
| 111 | + } else |
|
| 106 | 112 | { |
| 107 | 113 | // Check the user's ID |
| 108 | 114 | $result = $smcFunc['db_query']('', ' |
@@ -114,8 +120,9 @@ discard block |
||
| 114 | 120 | ) |
| 115 | 121 | ); |
| 116 | 122 | |
| 117 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
| 118 | - fatal_lang_error('no_user', false); |
|
| 123 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
| 124 | + fatal_lang_error('no_user', false); |
|
| 125 | + } |
|
| 119 | 126 | list($_REQUEST['u'], $display_name, $username) = $smcFunc['db_fetch_row']($result); |
| 120 | 127 | |
| 121 | 128 | $context['current_user'] = $_REQUEST['u']; |
@@ -170,10 +177,11 @@ discard block |
||
| 170 | 177 | is_not_guest(); |
| 171 | 178 | |
| 172 | 179 | // You must have the proper permissions! |
| 173 | - if (isset($_REQUEST['msg'])) |
|
| 174 | - isAllowedTo('report_any'); |
|
| 175 | - else |
|
| 176 | - isAllowedTo('report_user'); |
|
| 180 | + if (isset($_REQUEST['msg'])) { |
|
| 181 | + isAllowedTo('report_any'); |
|
| 182 | + } else { |
|
| 183 | + isAllowedTo('report_user'); |
|
| 184 | + } |
|
| 177 | 185 | |
| 178 | 186 | // Make sure they aren't spamming. |
| 179 | 187 | spamProtection('reporttm'); |
@@ -187,17 +195,20 @@ discard block |
||
| 187 | 195 | $post_errors = array(); |
| 188 | 196 | |
| 189 | 197 | // Check their session. |
| 190 | - if (checkSession('post', '', false) != '') |
|
| 191 | - $post_errors[] = 'session_timeout'; |
|
| 198 | + if (checkSession('post', '', false) != '') { |
|
| 199 | + $post_errors[] = 'session_timeout'; |
|
| 200 | + } |
|
| 192 | 201 | |
| 193 | 202 | // Make sure we have a comment and it's clean. |
| 194 | - if (!isset($_POST['comment']) || $smcFunc['htmltrim']($_POST['comment']) === '') |
|
| 195 | - $post_errors[] = 'no_comment'; |
|
| 203 | + if (!isset($_POST['comment']) || $smcFunc['htmltrim']($_POST['comment']) === '') { |
|
| 204 | + $post_errors[] = 'no_comment'; |
|
| 205 | + } |
|
| 196 | 206 | |
| 197 | 207 | $poster_comment = strtr($smcFunc['htmlspecialchars']($_POST['comment']), array("\r" => '', "\t" => '')); |
| 198 | 208 | |
| 199 | - if ($smcFunc['strlen']($poster_comment) > 254) |
|
| 200 | - $post_errors[] = 'post_too_long'; |
|
| 209 | + if ($smcFunc['strlen']($poster_comment) > 254) { |
|
| 210 | + $post_errors[] = 'post_too_long'; |
|
| 211 | + } |
|
| 201 | 212 | |
| 202 | 213 | // Any errors? |
| 203 | 214 | if (!empty($post_errors)) |
@@ -205,8 +216,9 @@ discard block |
||
| 205 | 216 | loadLanguage('Errors'); |
| 206 | 217 | |
| 207 | 218 | $context['post_errors'] = array(); |
| 208 | - foreach ($post_errors as $post_error) |
|
| 209 | - $context['post_errors'][$post_error] = $txt['error_' . $post_error]; |
|
| 219 | + foreach ($post_errors as $post_error) { |
|
| 220 | + $context['post_errors'][$post_error] = $txt['error_' . $post_error]; |
|
| 221 | + } |
|
| 210 | 222 | |
| 211 | 223 | return ReportToModerator(); |
| 212 | 224 | } |
@@ -215,8 +227,7 @@ discard block |
||
| 215 | 227 | { |
| 216 | 228 | // Handle this elsewhere to keep things from getting too long |
| 217 | 229 | reportPost($_POST['msg'], $poster_comment); |
| 218 | - } |
|
| 219 | - else |
|
| 230 | + } else |
|
| 220 | 231 | { |
| 221 | 232 | reportUser($_POST['u'], $poster_comment); |
| 222 | 233 | } |
@@ -247,8 +258,9 @@ discard block |
||
| 247 | 258 | 'id_msg' => $_POST['msg'], |
| 248 | 259 | ) |
| 249 | 260 | ); |
| 250 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 251 | - fatal_lang_error('no_board', false); |
|
| 261 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 262 | + fatal_lang_error('no_board', false); |
|
| 263 | + } |
|
| 252 | 264 | $message = $smcFunc['db_fetch_assoc']($request); |
| 253 | 265 | $smcFunc['db_free_result']($request); |
| 254 | 266 | |
@@ -268,18 +280,20 @@ discard block |
||
| 268 | 280 | 'ignored' => 1, |
| 269 | 281 | ) |
| 270 | 282 | ); |
| 271 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 272 | - list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request); |
|
| 283 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 284 | + list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request); |
|
| 285 | + } |
|
| 273 | 286 | |
| 274 | 287 | $smcFunc['db_free_result']($request); |
| 275 | 288 | |
| 276 | 289 | // If we're just going to ignore these, then who gives a monkeys... |
| 277 | - if (!empty($ignore)) |
|
| 278 | - redirectexit('topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg']); |
|
| 290 | + if (!empty($ignore)) { |
|
| 291 | + redirectexit('topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg']); |
|
| 292 | + } |
|
| 279 | 293 | |
| 280 | 294 | // Already reported? My god, we could be dealing with a real rogue here... |
| 281 | - if (!empty($id_report)) |
|
| 282 | - $smcFunc['db_query']('', ' |
|
| 295 | + if (!empty($id_report)) { |
|
| 296 | + $smcFunc['db_query']('', ' |
|
| 283 | 297 | UPDATE {db_prefix}log_reported |
| 284 | 298 | SET num_reports = num_reports + 1, time_updated = {int:current_time} |
| 285 | 299 | WHERE id_report = {int:id_report}', |
@@ -288,11 +302,13 @@ discard block |
||
| 288 | 302 | 'id_report' => $id_report, |
| 289 | 303 | ) |
| 290 | 304 | ); |
| 305 | + } |
|
| 291 | 306 | // Otherwise, we shall make one! |
| 292 | 307 | else |
| 293 | 308 | { |
| 294 | - if (empty($message['real_name'])) |
|
| 295 | - $message['real_name'] = $message['poster_name']; |
|
| 309 | + if (empty($message['real_name'])) { |
|
| 310 | + $message['real_name'] = $message['poster_name']; |
|
| 311 | + } |
|
| 296 | 312 | |
| 297 | 313 | $smcFunc['db_insert']('', |
| 298 | 314 | '{db_prefix}log_reported', |
@@ -371,8 +387,9 @@ discard block |
||
| 371 | 387 | 'id_member' => $_POST['u'] |
| 372 | 388 | ) |
| 373 | 389 | ); |
| 374 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 375 | - fatal_lang_error('no_user', false); |
|
| 390 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 391 | + fatal_lang_error('no_user', false); |
|
| 392 | + } |
|
| 376 | 393 | $user = $smcFunc['db_fetch_assoc']($request); |
| 377 | 394 | $smcFunc['db_free_result']($request); |
| 378 | 395 | |
@@ -393,18 +410,20 @@ discard block |
||
| 393 | 410 | 'ignored' => 1, |
| 394 | 411 | ) |
| 395 | 412 | ); |
| 396 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 397 | - list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request); |
|
| 413 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 414 | + list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request); |
|
| 415 | + } |
|
| 398 | 416 | |
| 399 | 417 | $smcFunc['db_free_result']($request); |
| 400 | 418 | |
| 401 | 419 | // If we're just going to ignore these, then who gives a monkeys... |
| 402 | - if (!empty($ignore)) |
|
| 403 | - redirectexit('action=profile;u=' . $_POST['u']); |
|
| 420 | + if (!empty($ignore)) { |
|
| 421 | + redirectexit('action=profile;u=' . $_POST['u']); |
|
| 422 | + } |
|
| 404 | 423 | |
| 405 | 424 | // Already reported? My god, we could be dealing with a real rogue here... |
| 406 | - if (!empty($id_report)) |
|
| 407 | - $smcFunc['db_query']('', ' |
|
| 425 | + if (!empty($id_report)) { |
|
| 426 | + $smcFunc['db_query']('', ' |
|
| 408 | 427 | UPDATE {db_prefix}log_reported |
| 409 | 428 | SET num_reports = num_reports + 1, time_updated = {int:current_time} |
| 410 | 429 | WHERE id_report = {int:id_report}', |
@@ -413,6 +432,7 @@ discard block |
||
| 413 | 432 | 'id_report' => $id_report, |
| 414 | 433 | ) |
| 415 | 434 | ); |
| 435 | + } |
|
| 416 | 436 | // Otherwise, we shall make one! |
| 417 | 437 | else |
| 418 | 438 | { |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | 'class' => 'centercol', |
| 394 | 394 | ), |
| 395 | 395 | 'data' => array( |
| 396 | - 'function' => function ($rowData) |
|
| 396 | + 'function' => function($rowData) |
|
| 397 | 397 | { |
| 398 | 398 | return $rowData['selected'] ? '<span class="generic_icons valid"></span>' : ''; |
| 399 | 399 | }, |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | 'class' => 'centercol', |
| 454 | 454 | ), |
| 455 | 455 | 'data' => array( |
| 456 | - 'function' => function ($rowData) |
|
| 456 | + 'function' => function($rowData) |
|
| 457 | 457 | { |
| 458 | 458 | return $rowData['selected'] ? '' : sprintf('<input type="checkbox" name="smiley_set[%1$d]" class="input_check">', $rowData['id']); |
| 459 | 459 | }, |
@@ -997,7 +997,7 @@ discard block |
||
| 997 | 997 | 'value' => $txt['smileys_location'], |
| 998 | 998 | ), |
| 999 | 999 | 'data' => array( |
| 1000 | - 'function' => function ($rowData) use ($txt) |
|
| 1000 | + 'function' => function($rowData) use ($txt) |
|
| 1001 | 1001 | { |
| 1002 | 1002 | if (empty($rowData['hidden'])) |
| 1003 | 1003 | return $txt['smileys_location_form']; |
@@ -1017,7 +1017,7 @@ discard block |
||
| 1017 | 1017 | 'value' => $txt['smileys_description'], |
| 1018 | 1018 | ), |
| 1019 | 1019 | 'data' => array( |
| 1020 | - 'function' => function ($rowData) use ($context, $txt, $modSettings, $smcFunc) |
|
| 1020 | + 'function' => function($rowData) use ($context, $txt, $modSettings, $smcFunc) |
|
| 1021 | 1021 | { |
| 1022 | 1022 | if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) |
| 1023 | 1023 | return $smcFunc['htmlspecialchars']($rowData['description']); |
@@ -1557,7 +1557,7 @@ discard block |
||
| 1557 | 1557 | 'action' => $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.'))) |
| 1558 | 1558 | ); |
| 1559 | 1559 | |
| 1560 | - $file = $packagesdir . '/temp/' . $base_path . $action['filename']; |
|
| 1560 | + $file = $packagesdir . '/temp/' . $base_path . $action['filename']; |
|
| 1561 | 1561 | if (isset($action['filename']) && (!file_exists($file) || !is_writable(dirname($action['destination'])))) |
| 1562 | 1562 | { |
| 1563 | 1563 | $context['has_failure'] = true; |
@@ -1601,7 +1601,7 @@ discard block |
||
| 1601 | 1601 | { |
| 1602 | 1602 | updateSettings(array( |
| 1603 | 1603 | 'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . basename($action['action']), |
| 1604 | - 'smiley_sets_names' => $modSettings['smiley_sets_names'] . "\n" . $smileyInfo['name'] . (count($context['actions']) > 1 ? ' ' . (!empty($action['description']) ? $smcFunc['htmlspecialchars']($action['description']) : basename($action['action'])) : ''), |
|
| 1604 | + 'smiley_sets_names' => $modSettings['smiley_sets_names'] . "\n" . $smileyInfo['name'] . (count($context['actions']) > 1 ? ' ' . (!empty($action['description']) ? $smcFunc['htmlspecialchars']($action['description']) : basename($action['action'])) : ''), |
|
| 1605 | 1605 | )); |
| 1606 | 1606 | } |
| 1607 | 1607 | |
@@ -1613,7 +1613,7 @@ discard block |
||
| 1613 | 1613 | '{db_prefix}log_packages', |
| 1614 | 1614 | array( |
| 1615 | 1615 | 'filename' => 'string', 'name' => 'string', 'package_id' => 'string', 'version' => 'string', |
| 1616 | - 'id_member_installed' => 'int', 'member_installed' => 'string','time_installed' => 'int', |
|
| 1616 | + 'id_member_installed' => 'int', 'member_installed' => 'string', 'time_installed' => 'int', |
|
| 1617 | 1617 | 'install_state' => 'int', 'failed_steps' => 'string', 'themes_installed' => 'string', |
| 1618 | 1618 | 'member_removed' => 'int', 'db_changes' => 'string', 'credits' => 'string', |
| 1619 | 1619 | ), |
@@ -1862,7 +1862,7 @@ discard block |
||
| 1862 | 1862 | 'columns' => array( |
| 1863 | 1863 | 'icon' => array( |
| 1864 | 1864 | 'data' => array( |
| 1865 | - 'function' => function ($rowData) use ($settings, $smcFunc) |
|
| 1865 | + 'function' => function($rowData) use ($settings, $smcFunc) |
|
| 1866 | 1866 | { |
| 1867 | 1867 | $images_url = $settings[file_exists(sprintf('%1$s/images/post/%2$s.png', $settings['theme_dir'], $rowData['filename'])) ? 'actual_images_url' : 'default_images_url']; |
| 1868 | 1868 | return sprintf('<img src="%1$s/post/%2$s.png" alt="%3$s">', $images_url, $rowData['filename'], $smcFunc['htmlspecialchars']($rowData['title'])); |
@@ -1896,7 +1896,7 @@ discard block |
||
| 1896 | 1896 | 'value' => $txt['icons_board'], |
| 1897 | 1897 | ), |
| 1898 | 1898 | 'data' => array( |
| 1899 | - 'function' => function ($rowData) use ($txt) |
|
| 1899 | + 'function' => function($rowData) use ($txt) |
|
| 1900 | 1900 | { |
| 1901 | 1901 | return empty($rowData['board_name']) ? $txt['icons_edit_icons_all_boards'] : $rowData['board_name']; |
| 1902 | 1902 | }, |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * This is the dispatcher of smileys administration. |
@@ -91,8 +92,9 @@ discard block |
||
| 91 | 92 | ); |
| 92 | 93 | |
| 93 | 94 | // Some settings may not be enabled, disallow these from the tabs as appropriate. |
| 94 | - if (empty($modSettings['messageIcons_enable'])) |
|
| 95 | - $context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true; |
|
| 95 | + if (empty($modSettings['messageIcons_enable'])) { |
|
| 96 | + $context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true; |
|
| 97 | + } |
|
| 96 | 98 | if (empty($modSettings['smiley_enable'])) |
| 97 | 99 | { |
| 98 | 100 | $context[$context['admin_menu_name']]['tab_data']['tabs']['addsmiley']['disabled'] = true; |
@@ -125,8 +127,9 @@ discard block |
||
| 125 | 127 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
| 126 | 128 | |
| 127 | 129 | $smiley_context = array(); |
| 128 | - foreach ($smiley_sets as $i => $set) |
|
| 129 | - $smiley_context[$set] = $set_names[$i]; |
|
| 130 | + foreach ($smiley_sets as $i => $set) { |
|
| 131 | + $smiley_context[$set] = $set_names[$i]; |
|
| 132 | + } |
|
| 130 | 133 | |
| 131 | 134 | // All the settings for the page... |
| 132 | 135 | $config_vars = array( |
@@ -147,8 +150,9 @@ discard block |
||
| 147 | 150 | |
| 148 | 151 | call_integration_hook('integrate_modify_smiley_settings', array(&$config_vars)); |
| 149 | 152 | |
| 150 | - if ($return_config) |
|
| 151 | - return $config_vars; |
|
| 153 | + if ($return_config) { |
|
| 154 | + return $config_vars; |
|
| 155 | + } |
|
| 152 | 156 | |
| 153 | 157 | // Setup the basics of the settings template. |
| 154 | 158 | require_once($sourcedir . '/ManageServer.php'); |
@@ -207,8 +211,9 @@ discard block |
||
| 207 | 211 | foreach ($_POST['smiley_set'] as $id => $val) |
| 208 | 212 | { |
| 209 | 213 | // If this is the set you've marked as default, or the only one remaining, you can't delete it |
| 210 | - if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) |
|
| 211 | - unset($set_paths[$id], $set_names[$id]); |
|
| 214 | + if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) { |
|
| 215 | + unset($set_paths[$id], $set_names[$id]); |
|
| 216 | + } |
|
| 212 | 217 | } |
| 213 | 218 | |
| 214 | 219 | // Shortcut... array_merge() on a single array resets the numeric keys |
@@ -222,8 +227,9 @@ discard block |
||
| 222 | 227 | )); |
| 223 | 228 | } |
| 224 | 229 | // Add a new smiley set. |
| 225 | - elseif (!empty($_POST['add'])) |
|
| 226 | - $context['sub_action'] = 'modifyset'; |
|
| 230 | + elseif (!empty($_POST['add'])) { |
|
| 231 | + $context['sub_action'] = 'modifyset'; |
|
| 232 | + } |
|
| 227 | 233 | // Create or modify a smiley set. |
| 228 | 234 | elseif (isset($_POST['set'])) |
| 229 | 235 | { |
@@ -233,8 +239,9 @@ discard block |
||
| 233 | 239 | // Create a new smiley set. |
| 234 | 240 | if ($_POST['set'] == -1 && isset($_POST['smiley_sets_path'])) |
| 235 | 241 | { |
| 236 | - if (in_array($_POST['smiley_sets_path'], $set_paths)) |
|
| 237 | - fatal_lang_error('smiley_set_already_exists'); |
|
| 242 | + if (in_array($_POST['smiley_sets_path'], $set_paths)) { |
|
| 243 | + fatal_lang_error('smiley_set_already_exists'); |
|
| 244 | + } |
|
| 238 | 245 | |
| 239 | 246 | updateSettings(array( |
| 240 | 247 | 'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . $_POST['smiley_sets_path'], |
@@ -246,12 +253,14 @@ discard block |
||
| 246 | 253 | else |
| 247 | 254 | { |
| 248 | 255 | // Make sure the smiley set exists. |
| 249 | - if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) |
|
| 250 | - fatal_lang_error('smiley_set_not_found'); |
|
| 256 | + if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) { |
|
| 257 | + fatal_lang_error('smiley_set_not_found'); |
|
| 258 | + } |
|
| 251 | 259 | |
| 252 | 260 | // Make sure the path is not yet used by another smileyset. |
| 253 | - if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) |
|
| 254 | - fatal_lang_error('smiley_set_path_already_used'); |
|
| 261 | + if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) { |
|
| 262 | + fatal_lang_error('smiley_set_path_already_used'); |
|
| 263 | + } |
|
| 255 | 264 | |
| 256 | 265 | $set_paths[$_POST['set']] = $_POST['smiley_sets_path']; |
| 257 | 266 | $set_names[$_POST['set']] = $_POST['smiley_sets_name']; |
@@ -263,8 +272,9 @@ discard block |
||
| 263 | 272 | } |
| 264 | 273 | |
| 265 | 274 | // The user might have checked to also import smileys. |
| 266 | - if (!empty($_POST['smiley_sets_import'])) |
|
| 267 | - ImportSmileys($_POST['smiley_sets_path']); |
|
| 275 | + if (!empty($_POST['smiley_sets_import'])) { |
|
| 276 | + ImportSmileys($_POST['smiley_sets_path']); |
|
| 277 | + } |
|
| 268 | 278 | } |
| 269 | 279 | cache_put_data('parsing_smileys', null, 480); |
| 270 | 280 | cache_put_data('posting_smileys', null, 480); |
@@ -273,13 +283,14 @@ discard block |
||
| 273 | 283 | // Load all available smileysets... |
| 274 | 284 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
| 275 | 285 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
| 276 | - foreach ($context['smiley_sets'] as $i => $set) |
|
| 277 | - $context['smiley_sets'][$i] = array( |
|
| 286 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
| 287 | + $context['smiley_sets'][$i] = array( |
|
| 278 | 288 | 'id' => $i, |
| 279 | 289 | 'path' => $smcFunc['htmlspecialchars']($set), |
| 280 | 290 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
| 281 | 291 | 'selected' => $set == $modSettings['smiley_sets_default'] |
| 282 | 292 | ); |
| 293 | + } |
|
| 283 | 294 | |
| 284 | 295 | // Importing any smileys from an existing set? |
| 285 | 296 | if ($context['sub_action'] == 'import') |
@@ -290,8 +301,9 @@ discard block |
||
| 290 | 301 | $_GET['set'] = (int) $_GET['set']; |
| 291 | 302 | |
| 292 | 303 | // Sanity check - then import. |
| 293 | - if (isset($context['smiley_sets'][$_GET['set']])) |
|
| 294 | - ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path'])); |
|
| 304 | + if (isset($context['smiley_sets'][$_GET['set']])) { |
|
| 305 | + ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path'])); |
|
| 306 | + } |
|
| 295 | 307 | |
| 296 | 308 | // Force the process to continue. |
| 297 | 309 | $context['sub_action'] = 'modifyset'; |
@@ -301,15 +313,15 @@ discard block |
||
| 301 | 313 | if ($context['sub_action'] == 'modifyset') |
| 302 | 314 | { |
| 303 | 315 | $_GET['set'] = !isset($_GET['set']) ? -1 : (int) $_GET['set']; |
| 304 | - if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) |
|
| 305 | - $context['current_set'] = array( |
|
| 316 | + if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) { |
|
| 317 | + $context['current_set'] = array( |
|
| 306 | 318 | 'id' => '-1', |
| 307 | 319 | 'path' => '', |
| 308 | 320 | 'name' => '', |
| 309 | 321 | 'selected' => false, |
| 310 | 322 | 'is_new' => true, |
| 311 | 323 | ); |
| 312 | - else |
|
| 324 | + } else |
|
| 313 | 325 | { |
| 314 | 326 | $context['current_set'] = &$context['smiley_sets'][$_GET['set']]; |
| 315 | 327 | $context['current_set']['is_new'] = false; |
@@ -321,13 +333,15 @@ discard block |
||
| 321 | 333 | $dir = dir($modSettings['smileys_dir'] . '/' . $context['current_set']['path']); |
| 322 | 334 | while ($entry = $dir->read()) |
| 323 | 335 | { |
| 324 | - if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
| 325 | - $smileys[strtolower($entry)] = $entry; |
|
| 336 | + if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
| 337 | + $smileys[strtolower($entry)] = $entry; |
|
| 338 | + } |
|
| 326 | 339 | } |
| 327 | 340 | $dir->close(); |
| 328 | 341 | |
| 329 | - if (empty($smileys)) |
|
| 330 | - fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name'])); |
|
| 342 | + if (empty($smileys)) { |
|
| 343 | + fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name'])); |
|
| 344 | + } |
|
| 331 | 345 | |
| 332 | 346 | // Exclude the smileys that are already in the database. |
| 333 | 347 | $request = $smcFunc['db_query']('', ' |
@@ -338,9 +352,10 @@ discard block |
||
| 338 | 352 | 'smiley_list' => $smileys, |
| 339 | 353 | ) |
| 340 | 354 | ); |
| 341 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 342 | - if (isset($smileys[strtolower($row['filename'])])) |
|
| 355 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 356 | + if (isset($smileys[strtolower($row['filename'])])) |
|
| 343 | 357 | unset($smileys[strtolower($row['filename'])]); |
| 358 | + } |
|
| 344 | 359 | $smcFunc['db_free_result']($request); |
| 345 | 360 | |
| 346 | 361 | $context['current_set']['can_import'] = count($smileys); |
@@ -355,13 +370,14 @@ discard block |
||
| 355 | 370 | $dir = dir($modSettings['smileys_dir']); |
| 356 | 371 | while ($entry = $dir->read()) |
| 357 | 372 | { |
| 358 | - if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) |
|
| 359 | - $context['smiley_set_dirs'][] = array( |
|
| 373 | + if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) { |
|
| 374 | + $context['smiley_set_dirs'][] = array( |
|
| 360 | 375 | 'id' => $entry, |
| 361 | 376 | 'path' => $modSettings['smileys_dir'] . '/' . $entry, |
| 362 | 377 | 'selectable' => $entry == $context['current_set']['path'] || !in_array($entry, explode(',', $modSettings['smiley_sets_known'])), |
| 363 | 378 | 'current' => $entry == $context['current_set']['path'], |
| 364 | 379 | ); |
| 380 | + } |
|
| 365 | 381 | } |
| 366 | 382 | $dir->close(); |
| 367 | 383 | } |
@@ -371,8 +387,9 @@ discard block |
||
| 371 | 387 | createToken('admin-mss', 'request'); |
| 372 | 388 | |
| 373 | 389 | // In case we need to import smileys, we need to add the token in now. |
| 374 | - if (isset($context['current_set']['import_url'])) |
|
| 375 | - $context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token']; |
|
| 390 | + if (isset($context['current_set']['import_url'])) { |
|
| 391 | + $context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token']; |
|
| 392 | + } |
|
| 376 | 393 | |
| 377 | 394 | $listOptions = array( |
| 378 | 395 | 'id' => 'smiley_set_list', |
@@ -510,21 +527,23 @@ discard block |
||
| 510 | 527 | $cols['name'][] = $set_names[$i]; |
| 511 | 528 | } |
| 512 | 529 | $sort_flag = strpos($sort, 'DESC') === false ? SORT_ASC : SORT_DESC; |
| 513 | - if (substr($sort, 0, 4) === 'name') |
|
| 514 | - array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']); |
|
| 515 | - elseif (substr($sort, 0, 4) === 'path') |
|
| 516 | - array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']); |
|
| 517 | - else |
|
| 518 | - array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']); |
|
| 530 | + if (substr($sort, 0, 4) === 'name') { |
|
| 531 | + array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']); |
|
| 532 | + } elseif (substr($sort, 0, 4) === 'path') { |
|
| 533 | + array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']); |
|
| 534 | + } else { |
|
| 535 | + array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']); |
|
| 536 | + } |
|
| 519 | 537 | |
| 520 | 538 | $smiley_sets = array(); |
| 521 | - foreach ($cols['id'] as $i => $id) |
|
| 522 | - $smiley_sets[] = array( |
|
| 539 | + foreach ($cols['id'] as $i => $id) { |
|
| 540 | + $smiley_sets[] = array( |
|
| 523 | 541 | 'id' => $id, |
| 524 | 542 | 'path' => $cols['path'][$i], |
| 525 | 543 | 'name' => $cols['name'][$i], |
| 526 | 544 | 'selected' => $cols['path'][$i] == $modSettings['smiley_sets_default'] |
| 527 | 545 | ); |
| 546 | + } |
|
| 528 | 547 | |
| 529 | 548 | return $smiley_sets; |
| 530 | 549 | } |
@@ -553,13 +572,14 @@ discard block |
||
| 553 | 572 | $context['smileys_dir_found'] = is_dir($context['smileys_dir']); |
| 554 | 573 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
| 555 | 574 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
| 556 | - foreach ($context['smiley_sets'] as $i => $set) |
|
| 557 | - $context['smiley_sets'][$i] = array( |
|
| 575 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
| 576 | + $context['smiley_sets'][$i] = array( |
|
| 558 | 577 | 'id' => $i, |
| 559 | 578 | 'path' => $smcFunc['htmlspecialchars']($set), |
| 560 | 579 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
| 561 | 580 | 'selected' => $set == $modSettings['smiley_sets_default'] |
| 562 | 581 | ); |
| 582 | + } |
|
| 563 | 583 | |
| 564 | 584 | // Submitting a form? |
| 565 | 585 | if (isset($_POST[$context['session_var']], $_POST['smiley_code'])) |
@@ -575,8 +595,9 @@ discard block |
||
| 575 | 595 | $_POST['smiley_filename'] = htmltrim__recursive($_POST['smiley_filename']); |
| 576 | 596 | |
| 577 | 597 | // Make sure some code was entered. |
| 578 | - if (empty($_POST['smiley_code'])) |
|
| 579 | - fatal_lang_error('smiley_has_no_code'); |
|
| 598 | + if (empty($_POST['smiley_code'])) { |
|
| 599 | + fatal_lang_error('smiley_has_no_code'); |
|
| 600 | + } |
|
| 580 | 601 | |
| 581 | 602 | // Check whether the new code has duplicates. It should be unique. |
| 582 | 603 | $request = $smcFunc['db_query']('', ' |
@@ -588,8 +609,9 @@ discard block |
||
| 588 | 609 | 'smiley_code' => $_POST['smiley_code'], |
| 589 | 610 | ) |
| 590 | 611 | ); |
| 591 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
| 592 | - fatal_lang_error('smiley_not_unique'); |
|
| 612 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
| 613 | + fatal_lang_error('smiley_not_unique'); |
|
| 614 | + } |
|
| 593 | 615 | $smcFunc['db_free_result']($request); |
| 594 | 616 | |
| 595 | 617 | // If we are uploading - check all the smiley sets are writable! |
@@ -598,38 +620,44 @@ discard block |
||
| 598 | 620 | $writeErrors = array(); |
| 599 | 621 | foreach ($context['smiley_sets'] as $set) |
| 600 | 622 | { |
| 601 | - if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) |
|
| 602 | - $writeErrors[] = $set['path']; |
|
| 623 | + if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) { |
|
| 624 | + $writeErrors[] = $set['path']; |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + if (!empty($writeErrors)) { |
|
| 628 | + fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors))); |
|
| 603 | 629 | } |
| 604 | - if (!empty($writeErrors)) |
|
| 605 | - fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors))); |
|
| 606 | 630 | } |
| 607 | 631 | |
| 608 | 632 | // Uploading just one smiley for all of them? |
| 609 | 633 | if (isset($_POST['sameall']) && isset($_FILES['uploadSmiley']['name']) && $_FILES['uploadSmiley']['name'] != '') |
| 610 | 634 | { |
| 611 | - if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) |
|
| 612 | - fatal_lang_error('smileys_upload_error'); |
|
| 635 | + if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) { |
|
| 636 | + fatal_lang_error('smileys_upload_error'); |
|
| 637 | + } |
|
| 613 | 638 | |
| 614 | 639 | // Sorry, no spaces, dots, or anything else but letters allowed. |
| 615 | 640 | $_FILES['uploadSmiley']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['uploadSmiley']['name']); |
| 616 | 641 | |
| 617 | 642 | // We only allow image files - it's THAT simple - no messing around here... |
| 618 | - if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) |
|
| 619 | - fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
| 643 | + if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) { |
|
| 644 | + fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
| 645 | + } |
|
| 620 | 646 | |
| 621 | 647 | // We only need the filename... |
| 622 | 648 | $destName = basename($_FILES['uploadSmiley']['name']); |
| 623 | 649 | |
| 624 | 650 | // Make sure they aren't trying to upload a nasty file - for their own good here! |
| 625 | - if (in_array(strtolower($destName), $disabledFiles)) |
|
| 626 | - fatal_lang_error('smileys_upload_error_illegal'); |
|
| 651 | + if (in_array(strtolower($destName), $disabledFiles)) { |
|
| 652 | + fatal_lang_error('smileys_upload_error_illegal'); |
|
| 653 | + } |
|
| 627 | 654 | |
| 628 | 655 | // Check if the file already exists... and if not move it to EVERY smiley set directory. |
| 629 | 656 | $i = 0; |
| 630 | 657 | // Keep going until we find a set the file doesn't exist in. (or maybe it exists in all of them?) |
| 631 | - while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) |
|
| 632 | - $i++; |
|
| 658 | + while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) { |
|
| 659 | + $i++; |
|
| 660 | + } |
|
| 633 | 661 | |
| 634 | 662 | // Okay, we're going to put the smiley right here, since it's not there yet! |
| 635 | 663 | if (isset($context['smiley_sets'][$i]['path'])) |
@@ -644,8 +672,9 @@ discard block |
||
| 644 | 672 | $currentPath = $context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName; |
| 645 | 673 | |
| 646 | 674 | // The file is already there! Don't overwrite it! |
| 647 | - if (file_exists($currentPath)) |
|
| 648 | - continue; |
|
| 675 | + if (file_exists($currentPath)) { |
|
| 676 | + continue; |
|
| 677 | + } |
|
| 649 | 678 | |
| 650 | 679 | // Okay, so copy the first one we made to here. |
| 651 | 680 | copy($smileyLocation, $currentPath); |
@@ -662,13 +691,15 @@ discard block |
||
| 662 | 691 | $newName = ''; |
| 663 | 692 | foreach ($_FILES as $name => $data) |
| 664 | 693 | { |
| 665 | - if ($_FILES[$name]['name'] == '') |
|
| 666 | - fatal_lang_error('smileys_upload_error_blank'); |
|
| 694 | + if ($_FILES[$name]['name'] == '') { |
|
| 695 | + fatal_lang_error('smileys_upload_error_blank'); |
|
| 696 | + } |
|
| 667 | 697 | |
| 668 | - if (empty($newName)) |
|
| 669 | - $newName = basename($_FILES[$name]['name']); |
|
| 670 | - elseif (basename($_FILES[$name]['name']) != $newName) |
|
| 671 | - fatal_lang_error('smileys_upload_error_name'); |
|
| 698 | + if (empty($newName)) { |
|
| 699 | + $newName = basename($_FILES[$name]['name']); |
|
| 700 | + } elseif (basename($_FILES[$name]['name']) != $newName) { |
|
| 701 | + fatal_lang_error('smileys_upload_error_name'); |
|
| 702 | + } |
|
| 672 | 703 | } |
| 673 | 704 | |
| 674 | 705 | foreach ($context['smiley_sets'] as $i => $set) |
@@ -676,31 +707,36 @@ discard block |
||
| 676 | 707 | $set['name'] = un_htmlspecialchars($set['name']); |
| 677 | 708 | $set['path'] = un_htmlspecialchars($set['path']); |
| 678 | 709 | |
| 679 | - if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') |
|
| 680 | - continue; |
|
| 710 | + if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') { |
|
| 711 | + continue; |
|
| 712 | + } |
|
| 681 | 713 | |
| 682 | 714 | // Got one... |
| 683 | - if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) |
|
| 684 | - fatal_lang_error('smileys_upload_error'); |
|
| 715 | + if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) { |
|
| 716 | + fatal_lang_error('smileys_upload_error'); |
|
| 717 | + } |
|
| 685 | 718 | |
| 686 | 719 | // Sorry, no spaces, dots, or anything else but letters allowed. |
| 687 | 720 | $_FILES['individual_' . $set['name']]['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['individual_' . $set['name']]['name']); |
| 688 | 721 | |
| 689 | 722 | // We only allow image files - it's THAT simple - no messing around here... |
| 690 | - if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) |
|
| 691 | - fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
| 723 | + if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) { |
|
| 724 | + fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
| 725 | + } |
|
| 692 | 726 | |
| 693 | 727 | // We only need the filename... |
| 694 | 728 | $destName = basename($_FILES['individual_' . $set['name']]['name']); |
| 695 | 729 | |
| 696 | 730 | // Make sure they aren't trying to upload a nasty file - for their own good here! |
| 697 | - if (in_array(strtolower($destName), $disabledFiles)) |
|
| 698 | - fatal_lang_error('smileys_upload_error_illegal'); |
|
| 731 | + if (in_array(strtolower($destName), $disabledFiles)) { |
|
| 732 | + fatal_lang_error('smileys_upload_error_illegal'); |
|
| 733 | + } |
|
| 699 | 734 | |
| 700 | 735 | // If the file exists - ignore it. |
| 701 | 736 | $smileyLocation = $context['smileys_dir'] . '/' . $set['path'] . '/' . $destName; |
| 702 | - if (file_exists($smileyLocation)) |
|
| 703 | - continue; |
|
| 737 | + if (file_exists($smileyLocation)) { |
|
| 738 | + continue; |
|
| 739 | + } |
|
| 704 | 740 | |
| 705 | 741 | // Finally - move the image! |
| 706 | 742 | move_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name'], $smileyLocation); |
@@ -712,8 +748,9 @@ discard block |
||
| 712 | 748 | } |
| 713 | 749 | |
| 714 | 750 | // Also make sure a filename was given. |
| 715 | - if (empty($_POST['smiley_filename'])) |
|
| 716 | - fatal_lang_error('smiley_has_no_filename'); |
|
| 751 | + if (empty($_POST['smiley_filename'])) { |
|
| 752 | + fatal_lang_error('smiley_has_no_filename'); |
|
| 753 | + } |
|
| 717 | 754 | |
| 718 | 755 | // Find the position on the right. |
| 719 | 756 | $smiley_order = '0'; |
@@ -732,8 +769,9 @@ discard block |
||
| 732 | 769 | list ($smiley_order) = $smcFunc['db_fetch_row']($request); |
| 733 | 770 | $smcFunc['db_free_result']($request); |
| 734 | 771 | |
| 735 | - if (empty($smiley_order)) |
|
| 736 | - $smiley_order = '0'; |
|
| 772 | + if (empty($smiley_order)) { |
|
| 773 | + $smiley_order = '0'; |
|
| 774 | + } |
|
| 737 | 775 | } |
| 738 | 776 | $smcFunc['db_insert']('', |
| 739 | 777 | '{db_prefix}smileys', |
@@ -761,17 +799,19 @@ discard block |
||
| 761 | 799 | { |
| 762 | 800 | foreach ($context['smiley_sets'] as $smiley_set) |
| 763 | 801 | { |
| 764 | - if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) |
|
| 765 | - continue; |
|
| 802 | + if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) { |
|
| 803 | + continue; |
|
| 804 | + } |
|
| 766 | 805 | |
| 767 | 806 | $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])); |
| 768 | 807 | while ($entry = $dir->read()) |
| 769 | 808 | { |
| 770 | - if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
| 771 | - $context['filenames'][strtolower($entry)] = array( |
|
| 809 | + if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
| 810 | + $context['filenames'][strtolower($entry)] = array( |
|
| 772 | 811 | 'id' => $smcFunc['htmlspecialchars']($entry), |
| 773 | 812 | 'selected' => false, |
| 774 | 813 | ); |
| 814 | + } |
|
| 775 | 815 | } |
| 776 | 816 | $dir->close(); |
| 777 | 817 | } |
@@ -809,17 +849,19 @@ discard block |
||
| 809 | 849 | // Changing the selected smileys? |
| 810 | 850 | if (isset($_POST['smiley_action']) && !empty($_POST['checked_smileys'])) |
| 811 | 851 | { |
| 812 | - foreach ($_POST['checked_smileys'] as $id => $smiley_id) |
|
| 813 | - $_POST['checked_smileys'][$id] = (int) $smiley_id; |
|
| 852 | + foreach ($_POST['checked_smileys'] as $id => $smiley_id) { |
|
| 853 | + $_POST['checked_smileys'][$id] = (int) $smiley_id; |
|
| 854 | + } |
|
| 814 | 855 | |
| 815 | - if ($_POST['smiley_action'] == 'delete') |
|
| 816 | - $smcFunc['db_query']('', ' |
|
| 856 | + if ($_POST['smiley_action'] == 'delete') { |
|
| 857 | + $smcFunc['db_query']('', ' |
|
| 817 | 858 | DELETE FROM {db_prefix}smileys |
| 818 | 859 | WHERE id_smiley IN ({array_int:checked_smileys})', |
| 819 | 860 | array( |
| 820 | 861 | 'checked_smileys' => $_POST['checked_smileys'], |
| 821 | 862 | ) |
| 822 | 863 | ); |
| 864 | + } |
|
| 823 | 865 | // Changing the status of the smiley? |
| 824 | 866 | else |
| 825 | 867 | { |
@@ -829,8 +871,8 @@ discard block |
||
| 829 | 871 | 'hidden' => 1, |
| 830 | 872 | 'popup' => 2 |
| 831 | 873 | ); |
| 832 | - if (isset($displayTypes[$_POST['smiley_action']])) |
|
| 833 | - $smcFunc['db_query']('', ' |
|
| 874 | + if (isset($displayTypes[$_POST['smiley_action']])) { |
|
| 875 | + $smcFunc['db_query']('', ' |
|
| 834 | 876 | UPDATE {db_prefix}smileys |
| 835 | 877 | SET hidden = {int:display_type} |
| 836 | 878 | WHERE id_smiley IN ({array_int:checked_smileys})', |
@@ -839,6 +881,7 @@ discard block |
||
| 839 | 881 | 'display_type' => $displayTypes[$_POST['smiley_action']], |
| 840 | 882 | ) |
| 841 | 883 | ); |
| 884 | + } |
|
| 842 | 885 | } |
| 843 | 886 | } |
| 844 | 887 | // Create/modify a smiley. |
@@ -864,12 +907,14 @@ discard block |
||
| 864 | 907 | $_POST['smiley_location'] = empty($_POST['smiley_location']) || $_POST['smiley_location'] > 2 || $_POST['smiley_location'] < 0 ? 0 : (int) $_POST['smiley_location']; |
| 865 | 908 | |
| 866 | 909 | // Make sure some code was entered. |
| 867 | - if (empty($_POST['smiley_code'])) |
|
| 868 | - fatal_lang_error('smiley_has_no_code'); |
|
| 910 | + if (empty($_POST['smiley_code'])) { |
|
| 911 | + fatal_lang_error('smiley_has_no_code'); |
|
| 912 | + } |
|
| 869 | 913 | |
| 870 | 914 | // Also make sure a filename was given. |
| 871 | - if (empty($_POST['smiley_filename'])) |
|
| 872 | - fatal_lang_error('smiley_has_no_filename'); |
|
| 915 | + if (empty($_POST['smiley_filename'])) { |
|
| 916 | + fatal_lang_error('smiley_has_no_filename'); |
|
| 917 | + } |
|
| 873 | 918 | |
| 874 | 919 | // Check whether the new code has duplicates. It should be unique. |
| 875 | 920 | $request = $smcFunc['db_query']('', ' |
@@ -883,8 +928,9 @@ discard block |
||
| 883 | 928 | 'smiley_code' => $_POST['smiley_code'], |
| 884 | 929 | ) |
| 885 | 930 | ); |
| 886 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
| 887 | - fatal_lang_error('smiley_not_unique'); |
|
| 931 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
| 932 | + fatal_lang_error('smiley_not_unique'); |
|
| 933 | + } |
|
| 888 | 934 | $smcFunc['db_free_result']($request); |
| 889 | 935 | |
| 890 | 936 | $smcFunc['db_query']('', ' |
@@ -913,13 +959,14 @@ discard block |
||
| 913 | 959 | // Load all known smiley sets. |
| 914 | 960 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
| 915 | 961 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
| 916 | - foreach ($context['smiley_sets'] as $i => $set) |
|
| 917 | - $context['smiley_sets'][$i] = array( |
|
| 962 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
| 963 | + $context['smiley_sets'][$i] = array( |
|
| 918 | 964 | 'id' => $i, |
| 919 | 965 | 'path' => $smcFunc['htmlspecialchars']($set), |
| 920 | 966 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
| 921 | 967 | 'selected' => $set == $modSettings['smiley_sets_default'] |
| 922 | 968 | ); |
| 969 | + } |
|
| 923 | 970 | |
| 924 | 971 | // Prepare overview of all (custom) smileys. |
| 925 | 972 | if ($context['sub_action'] == 'editsmileys') |
@@ -935,9 +982,10 @@ discard block |
||
| 935 | 982 | // Create a list of options for selecting smiley sets. |
| 936 | 983 | $smileyset_option_list = ' |
| 937 | 984 | <select name="set" onchange="changeSet(this.options[this.selectedIndex].value);">'; |
| 938 | - foreach ($context['smiley_sets'] as $smiley_set) |
|
| 939 | - $smileyset_option_list .= ' |
|
| 985 | + foreach ($context['smiley_sets'] as $smiley_set) { |
|
| 986 | + $smileyset_option_list .= ' |
|
| 940 | 987 | <option value="' . $smiley_set['path'] . '"' . ($modSettings['smiley_sets_default'] == $smiley_set['path'] ? ' selected' : '') . '>' . $smiley_set['name'] . '</option>'; |
| 988 | + } |
|
| 941 | 989 | $smileyset_option_list .= ' |
| 942 | 990 | </select>'; |
| 943 | 991 | |
@@ -999,12 +1047,13 @@ discard block |
||
| 999 | 1047 | 'data' => array( |
| 1000 | 1048 | 'function' => function ($rowData) use ($txt) |
| 1001 | 1049 | { |
| 1002 | - if (empty($rowData['hidden'])) |
|
| 1003 | - return $txt['smileys_location_form']; |
|
| 1004 | - elseif ($rowData['hidden'] == 1) |
|
| 1005 | - return $txt['smileys_location_hidden']; |
|
| 1006 | - else |
|
| 1007 | - return $txt['smileys_location_popup']; |
|
| 1050 | + if (empty($rowData['hidden'])) { |
|
| 1051 | + return $txt['smileys_location_form']; |
|
| 1052 | + } elseif ($rowData['hidden'] == 1) { |
|
| 1053 | + return $txt['smileys_location_hidden']; |
|
| 1054 | + } else { |
|
| 1055 | + return $txt['smileys_location_popup']; |
|
| 1056 | + } |
|
| 1008 | 1057 | }, |
| 1009 | 1058 | ), |
| 1010 | 1059 | 'sort' => array( |
@@ -1019,19 +1068,22 @@ discard block |
||
| 1019 | 1068 | 'data' => array( |
| 1020 | 1069 | 'function' => function ($rowData) use ($context, $txt, $modSettings, $smcFunc) |
| 1021 | 1070 | { |
| 1022 | - if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) |
|
| 1023 | - return $smcFunc['htmlspecialchars']($rowData['description']); |
|
| 1071 | + if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) { |
|
| 1072 | + return $smcFunc['htmlspecialchars']($rowData['description']); |
|
| 1073 | + } |
|
| 1024 | 1074 | |
| 1025 | 1075 | // Check if there are smileys missing in some sets. |
| 1026 | 1076 | $missing_sets = array(); |
| 1027 | - foreach ($context['smiley_sets'] as $smiley_set) |
|
| 1028 | - if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename']))) |
|
| 1077 | + foreach ($context['smiley_sets'] as $smiley_set) { |
|
| 1078 | + if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename']))) |
|
| 1029 | 1079 | $missing_sets[] = $smiley_set['path']; |
| 1080 | + } |
|
| 1030 | 1081 | |
| 1031 | 1082 | $description = $smcFunc['htmlspecialchars']($rowData['description']); |
| 1032 | 1083 | |
| 1033 | - if (!empty($missing_sets)) |
|
| 1034 | - $description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets)); |
|
| 1084 | + if (!empty($missing_sets)) { |
|
| 1085 | + $description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets)); |
|
| 1086 | + } |
|
| 1035 | 1087 | |
| 1036 | 1088 | return $description; |
| 1037 | 1089 | }, |
@@ -1147,13 +1199,14 @@ discard block |
||
| 1147 | 1199 | $context['smileys_dir_found'] = is_dir($context['smileys_dir']); |
| 1148 | 1200 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
| 1149 | 1201 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
| 1150 | - foreach ($context['smiley_sets'] as $i => $set) |
|
| 1151 | - $context['smiley_sets'][$i] = array( |
|
| 1202 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
| 1203 | + $context['smiley_sets'][$i] = array( |
|
| 1152 | 1204 | 'id' => $i, |
| 1153 | 1205 | 'path' => $smcFunc['htmlspecialchars']($set), |
| 1154 | 1206 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
| 1155 | 1207 | 'selected' => $set == $modSettings['smiley_sets_default'] |
| 1156 | 1208 | ); |
| 1209 | + } |
|
| 1157 | 1210 | |
| 1158 | 1211 | $context['selected_set'] = $modSettings['smiley_sets_default']; |
| 1159 | 1212 | |
@@ -1163,17 +1216,19 @@ discard block |
||
| 1163 | 1216 | { |
| 1164 | 1217 | foreach ($context['smiley_sets'] as $smiley_set) |
| 1165 | 1218 | { |
| 1166 | - if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) |
|
| 1167 | - continue; |
|
| 1219 | + if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) { |
|
| 1220 | + continue; |
|
| 1221 | + } |
|
| 1168 | 1222 | |
| 1169 | 1223 | $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])); |
| 1170 | 1224 | while ($entry = $dir->read()) |
| 1171 | 1225 | { |
| 1172 | - if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
| 1173 | - $context['filenames'][strtolower($entry)] = array( |
|
| 1226 | + if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
| 1227 | + $context['filenames'][strtolower($entry)] = array( |
|
| 1174 | 1228 | 'id' => $smcFunc['htmlspecialchars']($entry), |
| 1175 | 1229 | 'selected' => false, |
| 1176 | 1230 | ); |
| 1231 | + } |
|
| 1177 | 1232 | } |
| 1178 | 1233 | $dir->close(); |
| 1179 | 1234 | } |
@@ -1188,8 +1243,9 @@ discard block |
||
| 1188 | 1243 | 'current_smiley' => (int) $_REQUEST['smiley'], |
| 1189 | 1244 | ) |
| 1190 | 1245 | ); |
| 1191 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
| 1192 | - fatal_lang_error('smiley_not_found'); |
|
| 1246 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
| 1247 | + fatal_lang_error('smiley_not_found'); |
|
| 1248 | + } |
|
| 1193 | 1249 | $context['current_smiley'] = $smcFunc['db_fetch_assoc']($request); |
| 1194 | 1250 | $smcFunc['db_free_result']($request); |
| 1195 | 1251 | |
@@ -1197,8 +1253,9 @@ discard block |
||
| 1197 | 1253 | $context['current_smiley']['filename'] = $smcFunc['htmlspecialchars']($context['current_smiley']['filename']); |
| 1198 | 1254 | $context['current_smiley']['description'] = $smcFunc['htmlspecialchars']($context['current_smiley']['description']); |
| 1199 | 1255 | |
| 1200 | - if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) |
|
| 1201 | - $context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true; |
|
| 1256 | + if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) { |
|
| 1257 | + $context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true; |
|
| 1258 | + } |
|
| 1202 | 1259 | } |
| 1203 | 1260 | } |
| 1204 | 1261 | |
@@ -1223,8 +1280,9 @@ discard block |
||
| 1223 | 1280 | ) |
| 1224 | 1281 | ); |
| 1225 | 1282 | $smileys = array(); |
| 1226 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1227 | - $smileys[] = $row; |
|
| 1283 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1284 | + $smileys[] = $row; |
|
| 1285 | + } |
|
| 1228 | 1286 | $smcFunc['db_free_result']($request); |
| 1229 | 1287 | |
| 1230 | 1288 | return $smileys; |
@@ -1264,8 +1322,9 @@ discard block |
||
| 1264 | 1322 | $_GET['location'] = empty($_GET['location']) || $_GET['location'] != 'popup' ? 0 : 2; |
| 1265 | 1323 | $_GET['source'] = empty($_GET['source']) ? 0 : (int) $_GET['source']; |
| 1266 | 1324 | |
| 1267 | - if (empty($_GET['source'])) |
|
| 1268 | - fatal_lang_error('smiley_not_found'); |
|
| 1325 | + if (empty($_GET['source'])) { |
|
| 1326 | + fatal_lang_error('smiley_not_found'); |
|
| 1327 | + } |
|
| 1269 | 1328 | |
| 1270 | 1329 | if (!empty($_GET['after'])) |
| 1271 | 1330 | { |
@@ -1281,12 +1340,12 @@ discard block |
||
| 1281 | 1340 | 'after_smiley' => $_GET['after'], |
| 1282 | 1341 | ) |
| 1283 | 1342 | ); |
| 1284 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
| 1285 | - fatal_lang_error('smiley_not_found'); |
|
| 1343 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
| 1344 | + fatal_lang_error('smiley_not_found'); |
|
| 1345 | + } |
|
| 1286 | 1346 | list ($smiley_row, $smiley_order, $smileyLocation) = $smcFunc['db_fetch_row']($request); |
| 1287 | 1347 | $smcFunc['db_free_result']($request); |
| 1288 | - } |
|
| 1289 | - else |
|
| 1348 | + } else |
|
| 1290 | 1349 | { |
| 1291 | 1350 | $smiley_row = (int) $_GET['row']; |
| 1292 | 1351 | $smiley_order = -1; |
@@ -1360,14 +1419,15 @@ discard block |
||
| 1360 | 1419 | $context['move_smiley'] = empty($_REQUEST['move']) ? 0 : (int) $_REQUEST['move']; |
| 1361 | 1420 | |
| 1362 | 1421 | // Make sure all rows are sequential. |
| 1363 | - foreach (array_keys($context['smileys']) as $location) |
|
| 1364 | - $context['smileys'][$location] = array( |
|
| 1422 | + foreach (array_keys($context['smileys']) as $location) { |
|
| 1423 | + $context['smileys'][$location] = array( |
|
| 1365 | 1424 | 'id' => $location, |
| 1366 | 1425 | 'title' => $location == 'postform' ? $txt['smileys_location_form'] : $txt['smileys_location_popup'], |
| 1367 | 1426 | 'description' => $location == 'postform' ? $txt['smileys_location_form_description'] : $txt['smileys_location_popup_description'], |
| 1368 | 1427 | 'last_row' => count($context['smileys'][$location]['rows']), |
| 1369 | 1428 | 'rows' => array_values($context['smileys'][$location]['rows']), |
| 1370 | 1429 | ); |
| 1430 | + } |
|
| 1371 | 1431 | |
| 1372 | 1432 | // Check & fix smileys that are not ordered properly in the database. |
| 1373 | 1433 | foreach (array_keys($context['smileys']) as $location) |
@@ -1392,8 +1452,8 @@ discard block |
||
| 1392 | 1452 | $context['smileys'][$location]['rows'][$id][0]['row'] = $id; |
| 1393 | 1453 | } |
| 1394 | 1454 | // Make sure the smiley order is always sequential. |
| 1395 | - foreach ($smiley_row as $order_id => $smiley) |
|
| 1396 | - if ($order_id != $smiley['order']) |
|
| 1455 | + foreach ($smiley_row as $order_id => $smiley) { |
|
| 1456 | + if ($order_id != $smiley['order']) |
|
| 1397 | 1457 | $smcFunc['db_query']('', ' |
| 1398 | 1458 | UPDATE {db_prefix}smileys |
| 1399 | 1459 | SET smiley_order = {int:new_order} |
@@ -1403,6 +1463,7 @@ discard block |
||
| 1403 | 1463 | 'current_smiley' => $smiley['id'], |
| 1404 | 1464 | ) |
| 1405 | 1465 | ); |
| 1466 | + } |
|
| 1406 | 1467 | } |
| 1407 | 1468 | } |
| 1408 | 1469 | |
@@ -1436,19 +1497,20 @@ discard block |
||
| 1436 | 1497 | $context['filename'] = $base_name; |
| 1437 | 1498 | |
| 1438 | 1499 | // Check that the smiley is from simplemachines.org, for now... maybe add mirroring later. |
| 1439 | - if (preg_match('~^http://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) |
|
| 1440 | - fatal_lang_error('not_on_simplemachines'); |
|
| 1500 | + if (preg_match('~^http://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) { |
|
| 1501 | + fatal_lang_error('not_on_simplemachines'); |
|
| 1502 | + } |
|
| 1441 | 1503 | |
| 1442 | 1504 | $destination = $packagesdir . '/' . $base_name; |
| 1443 | 1505 | |
| 1444 | - if (file_exists($destination)) |
|
| 1445 | - fatal_lang_error('package_upload_error_exists'); |
|
| 1506 | + if (file_exists($destination)) { |
|
| 1507 | + fatal_lang_error('package_upload_error_exists'); |
|
| 1508 | + } |
|
| 1446 | 1509 | |
| 1447 | 1510 | // Let's copy it to the Packages directory |
| 1448 | 1511 | file_put_contents($destination, fetch_web_data($_REQUEST['set_gz'])); |
| 1449 | 1512 | $testing = true; |
| 1450 | - } |
|
| 1451 | - elseif (isset($_REQUEST['package'])) |
|
| 1513 | + } elseif (isset($_REQUEST['package'])) |
|
| 1452 | 1514 | { |
| 1453 | 1515 | $base_name = basename($_REQUEST['package']); |
| 1454 | 1516 | $name = $smcFunc['htmlspecialchars'](strtok(basename($_REQUEST['package']), '.')); |
@@ -1458,12 +1520,14 @@ discard block |
||
| 1458 | 1520 | $destination = $packagesdir . '/' . basename($_REQUEST['package']); |
| 1459 | 1521 | } |
| 1460 | 1522 | |
| 1461 | - if (!file_exists($destination)) |
|
| 1462 | - fatal_lang_error('package_no_file', false); |
|
| 1523 | + if (!file_exists($destination)) { |
|
| 1524 | + fatal_lang_error('package_no_file', false); |
|
| 1525 | + } |
|
| 1463 | 1526 | |
| 1464 | 1527 | // Make sure temp directory exists and is empty. |
| 1465 | - if (file_exists($packagesdir . '/temp')) |
|
| 1466 | - deltree($packagesdir . '/temp', false); |
|
| 1528 | + if (file_exists($packagesdir . '/temp')) { |
|
| 1529 | + deltree($packagesdir . '/temp', false); |
|
| 1530 | + } |
|
| 1467 | 1531 | |
| 1468 | 1532 | if (!mktree($packagesdir . '/temp', 0755)) |
| 1469 | 1533 | { |
@@ -1475,31 +1539,37 @@ discard block |
||
| 1475 | 1539 | create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=smileys;sa=install;set_gz=' . $_REQUEST['set_gz'], 'crash_on_error' => true)); |
| 1476 | 1540 | |
| 1477 | 1541 | deltree($packagesdir . '/temp', false); |
| 1478 | - if (!mktree($packagesdir . '/temp', 0777)) |
|
| 1479 | - fatal_lang_error('package_cant_download', false); |
|
| 1542 | + if (!mktree($packagesdir . '/temp', 0777)) { |
|
| 1543 | + fatal_lang_error('package_cant_download', false); |
|
| 1544 | + } |
|
| 1480 | 1545 | } |
| 1481 | 1546 | } |
| 1482 | 1547 | |
| 1483 | 1548 | $extracted = read_tgz_file($destination, $packagesdir . '/temp'); |
| 1484 | - if (!$extracted) |
|
| 1485 | - fatal_lang_error('packageget_unable', false, array('http://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name)); |
|
| 1486 | - if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) |
|
| 1487 | - foreach ($extracted as $file) |
|
| 1549 | + if (!$extracted) { |
|
| 1550 | + fatal_lang_error('packageget_unable', false, array('http://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name)); |
|
| 1551 | + } |
|
| 1552 | + if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) { |
|
| 1553 | + foreach ($extracted as $file) |
|
| 1488 | 1554 | if (basename($file['filename']) == 'package-info.xml') |
| 1489 | 1555 | { |
| 1490 | 1556 | $base_path = dirname($file['filename']) . '/'; |
| 1557 | + } |
|
| 1491 | 1558 | break; |
| 1492 | 1559 | } |
| 1493 | 1560 | |
| 1494 | - if (!isset($base_path)) |
|
| 1495 | - $base_path = ''; |
|
| 1561 | + if (!isset($base_path)) { |
|
| 1562 | + $base_path = ''; |
|
| 1563 | + } |
|
| 1496 | 1564 | |
| 1497 | - if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) |
|
| 1498 | - fatal_lang_error('package_get_error_missing_xml', false); |
|
| 1565 | + if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) { |
|
| 1566 | + fatal_lang_error('package_get_error_missing_xml', false); |
|
| 1567 | + } |
|
| 1499 | 1568 | |
| 1500 | 1569 | $smileyInfo = getPackageInfo($context['filename']); |
| 1501 | - if (!is_array($smileyInfo)) |
|
| 1502 | - fatal_lang_error($smileyInfo); |
|
| 1570 | + if (!is_array($smileyInfo)) { |
|
| 1571 | + fatal_lang_error($smileyInfo); |
|
| 1572 | + } |
|
| 1503 | 1573 | |
| 1504 | 1574 | // See if it is installed? |
| 1505 | 1575 | $request = $smcFunc['db_query']('', ' |
@@ -1515,8 +1585,9 @@ discard block |
||
| 1515 | 1585 | ) |
| 1516 | 1586 | ); |
| 1517 | 1587 | |
| 1518 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
| 1519 | - fata_lang_error('package_installed_warning1'); |
|
| 1588 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
| 1589 | + fata_lang_error('package_installed_warning1'); |
|
| 1590 | + } |
|
| 1520 | 1591 | |
| 1521 | 1592 | // Everything is fine, now it's time to do something |
| 1522 | 1593 | $actions = parsePackageInfo($smileyInfo['xml'], true, 'install'); |
@@ -1533,23 +1604,23 @@ discard block |
||
| 1533 | 1604 | { |
| 1534 | 1605 | $has_readme = true; |
| 1535 | 1606 | $type = 'package_' . $action['type']; |
| 1536 | - if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) |
|
| 1537 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r")); |
|
| 1538 | - elseif (file_exists($action['filename'])) |
|
| 1539 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
| 1607 | + if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) { |
|
| 1608 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r")); |
|
| 1609 | + } elseif (file_exists($action['filename'])) { |
|
| 1610 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
| 1611 | + } |
|
| 1540 | 1612 | |
| 1541 | 1613 | if (!empty($action['parse_bbc'])) |
| 1542 | 1614 | { |
| 1543 | 1615 | require_once($sourcedir . '/Subs-Post.php'); |
| 1544 | 1616 | preparsecode($context[$type]); |
| 1545 | 1617 | $context[$type] = parse_bbc($context[$type]); |
| 1618 | + } else { |
|
| 1619 | + $context[$type] = nl2br($context[$type]); |
|
| 1546 | 1620 | } |
| 1547 | - else |
|
| 1548 | - $context[$type] = nl2br($context[$type]); |
|
| 1549 | 1621 | |
| 1550 | 1622 | continue; |
| 1551 | - } |
|
| 1552 | - elseif ($action['type'] == 'require-dir') |
|
| 1623 | + } elseif ($action['type'] == 'require-dir') |
|
| 1553 | 1624 | { |
| 1554 | 1625 | // Do this one... |
| 1555 | 1626 | $thisAction = array( |
@@ -1568,12 +1639,12 @@ discard block |
||
| 1568 | 1639 | ); |
| 1569 | 1640 | } |
| 1570 | 1641 | // @todo None given? |
| 1571 | - if (empty($thisAction['description'])) |
|
| 1572 | - $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
| 1642 | + if (empty($thisAction['description'])) { |
|
| 1643 | + $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
| 1644 | + } |
|
| 1573 | 1645 | |
| 1574 | 1646 | $context['actions'][] = $thisAction; |
| 1575 | - } |
|
| 1576 | - elseif ($action['type'] == 'credits') |
|
| 1647 | + } elseif ($action['type'] == 'credits') |
|
| 1577 | 1648 | { |
| 1578 | 1649 | // Time to build the billboard |
| 1579 | 1650 | $credits_tag = array( |
@@ -1632,12 +1703,14 @@ discard block |
||
| 1632 | 1703 | cache_put_data('posting_smileys', null, 480); |
| 1633 | 1704 | } |
| 1634 | 1705 | |
| 1635 | - if (file_exists($packagesdir . '/temp')) |
|
| 1636 | - deltree($packagesdir . '/temp'); |
|
| 1706 | + if (file_exists($packagesdir . '/temp')) { |
|
| 1707 | + deltree($packagesdir . '/temp'); |
|
| 1708 | + } |
|
| 1637 | 1709 | |
| 1638 | - if (!$testing) |
|
| 1639 | - redirectexit('action=admin;area=smileys'); |
|
| 1640 | -} |
|
| 1710 | + if (!$testing) { |
|
| 1711 | + redirectexit('action=admin;area=smileys'); |
|
| 1712 | + } |
|
| 1713 | + } |
|
| 1641 | 1714 | |
| 1642 | 1715 | /** |
| 1643 | 1716 | * A function to import new smileys from an existing directory into the database. |
@@ -1648,15 +1721,17 @@ discard block |
||
| 1648 | 1721 | { |
| 1649 | 1722 | global $modSettings, $smcFunc; |
| 1650 | 1723 | |
| 1651 | - if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) |
|
| 1652 | - fatal_lang_error('smiley_set_unable_to_import'); |
|
| 1724 | + if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) { |
|
| 1725 | + fatal_lang_error('smiley_set_unable_to_import'); |
|
| 1726 | + } |
|
| 1653 | 1727 | |
| 1654 | 1728 | $smileys = array(); |
| 1655 | 1729 | $dir = dir($modSettings['smileys_dir'] . '/' . $smileyPath); |
| 1656 | 1730 | while ($entry = $dir->read()) |
| 1657 | 1731 | { |
| 1658 | - if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
| 1659 | - $smileys[strtolower($entry)] = $entry; |
|
| 1732 | + if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
| 1733 | + $smileys[strtolower($entry)] = $entry; |
|
| 1734 | + } |
|
| 1660 | 1735 | } |
| 1661 | 1736 | $dir->close(); |
| 1662 | 1737 | |
@@ -1669,9 +1744,10 @@ discard block |
||
| 1669 | 1744 | 'smiley_list' => $smileys, |
| 1670 | 1745 | ) |
| 1671 | 1746 | ); |
| 1672 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1673 | - if (isset($smileys[strtolower($row['filename'])])) |
|
| 1747 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1748 | + if (isset($smileys[strtolower($row['filename'])])) |
|
| 1674 | 1749 | unset($smileys[strtolower($row['filename'])]); |
| 1750 | + } |
|
| 1675 | 1751 | $smcFunc['db_free_result']($request); |
| 1676 | 1752 | |
| 1677 | 1753 | $request = $smcFunc['db_query']('', ' |
@@ -1688,9 +1764,10 @@ discard block |
||
| 1688 | 1764 | $smcFunc['db_free_result']($request); |
| 1689 | 1765 | |
| 1690 | 1766 | $new_smileys = array(); |
| 1691 | - foreach ($smileys as $smiley) |
|
| 1692 | - if (strlen($smiley) <= 48) |
|
| 1767 | + foreach ($smileys as $smiley) { |
|
| 1768 | + if (strlen($smiley) <= 48) |
|
| 1693 | 1769 | $new_smileys[] = array(':' . strtok($smiley, '.') . ':', $smiley, strtok($smiley, '.'), 0, ++$smiley_order); |
| 1770 | + } |
|
| 1694 | 1771 | |
| 1695 | 1772 | if (!empty($new_smileys)) |
| 1696 | 1773 | { |
@@ -1755,8 +1832,9 @@ discard block |
||
| 1755 | 1832 | if (isset($_POST['delete']) && !empty($_POST['checked_icons'])) |
| 1756 | 1833 | { |
| 1757 | 1834 | $deleteIcons = array(); |
| 1758 | - foreach ($_POST['checked_icons'] as $icon) |
|
| 1759 | - $deleteIcons[] = (int) $icon; |
|
| 1835 | + foreach ($_POST['checked_icons'] as $icon) { |
|
| 1836 | + $deleteIcons[] = (int) $icon; |
|
| 1837 | + } |
|
| 1760 | 1838 | |
| 1761 | 1839 | // Do the actual delete! |
| 1762 | 1840 | $smcFunc['db_query']('', ' |
@@ -1773,35 +1851,41 @@ discard block |
||
| 1773 | 1851 | $_GET['icon'] = (int) $_GET['icon']; |
| 1774 | 1852 | |
| 1775 | 1853 | // Do some preperation with the data... like check the icon exists *somewhere* |
| 1776 | - if (strpos($_POST['icon_filename'], '.png') !== false) |
|
| 1777 | - $_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4); |
|
| 1778 | - if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) |
|
| 1779 | - fatal_lang_error('icon_not_found'); |
|
| 1854 | + if (strpos($_POST['icon_filename'], '.png') !== false) { |
|
| 1855 | + $_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4); |
|
| 1856 | + } |
|
| 1857 | + if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) { |
|
| 1858 | + fatal_lang_error('icon_not_found'); |
|
| 1859 | + } |
|
| 1780 | 1860 | // There is a 16 character limit on message icons... |
| 1781 | - elseif (strlen($_POST['icon_filename']) > 16) |
|
| 1782 | - fatal_lang_error('icon_name_too_long'); |
|
| 1783 | - elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) |
|
| 1784 | - fatal_lang_error('icon_after_itself'); |
|
| 1861 | + elseif (strlen($_POST['icon_filename']) > 16) { |
|
| 1862 | + fatal_lang_error('icon_name_too_long'); |
|
| 1863 | + } elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) { |
|
| 1864 | + fatal_lang_error('icon_after_itself'); |
|
| 1865 | + } |
|
| 1785 | 1866 | |
| 1786 | 1867 | // First do the sorting... if this is an edit reduce the order of everything after it by one ;) |
| 1787 | 1868 | if ($_GET['icon'] != 0) |
| 1788 | 1869 | { |
| 1789 | 1870 | $oldOrder = $context['icons'][$_GET['icon']]['true_order']; |
| 1790 | - foreach ($context['icons'] as $id => $data) |
|
| 1791 | - if ($data['true_order'] > $oldOrder) |
|
| 1871 | + foreach ($context['icons'] as $id => $data) { |
|
| 1872 | + if ($data['true_order'] > $oldOrder) |
|
| 1792 | 1873 | $context['icons'][$id]['true_order']--; |
| 1874 | + } |
|
| 1793 | 1875 | } |
| 1794 | 1876 | |
| 1795 | 1877 | // If there are no existing icons and this is a new one, set the id to 1 (mainly for non-mysql) |
| 1796 | - if (empty($_GET['icon']) && empty($context['icons'])) |
|
| 1797 | - $_GET['icon'] = 1; |
|
| 1878 | + if (empty($_GET['icon']) && empty($context['icons'])) { |
|
| 1879 | + $_GET['icon'] = 1; |
|
| 1880 | + } |
|
| 1798 | 1881 | |
| 1799 | 1882 | // Get the new order. |
| 1800 | 1883 | $newOrder = $_POST['icon_location'] == 0 ? 0 : $context['icons'][$_POST['icon_location']]['true_order'] + 1; |
| 1801 | 1884 | // Do the same, but with the one that used to be after this icon, done to avoid conflict. |
| 1802 | - foreach ($context['icons'] as $id => $data) |
|
| 1803 | - if ($data['true_order'] >= $newOrder) |
|
| 1885 | + foreach ($context['icons'] as $id => $data) { |
|
| 1886 | + if ($data['true_order'] >= $newOrder) |
|
| 1804 | 1887 | $context['icons'][$id]['true_order']++; |
| 1888 | + } |
|
| 1805 | 1889 | |
| 1806 | 1890 | // Finally set the current icon's position! |
| 1807 | 1891 | $context['icons'][$_GET['icon']]['true_order'] = $newOrder; |
@@ -1819,8 +1903,7 @@ discard block |
||
| 1819 | 1903 | if ($id != 0) |
| 1820 | 1904 | { |
| 1821 | 1905 | $iconInsert[] = array($id, $icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']); |
| 1822 | - } |
|
| 1823 | - else |
|
| 1906 | + } else |
|
| 1824 | 1907 | { |
| 1825 | 1908 | $iconInsert_new[] = array($icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']); |
| 1826 | 1909 | } |
@@ -1845,8 +1928,9 @@ discard block |
||
| 1845 | 1928 | } |
| 1846 | 1929 | |
| 1847 | 1930 | // Unless we're adding a new thing, we'll escape |
| 1848 | - if (!isset($_POST['add'])) |
|
| 1849 | - redirectexit('action=admin;area=smileys;sa=editicons'); |
|
| 1931 | + if (!isset($_POST['add'])) { |
|
| 1932 | + redirectexit('action=admin;area=smileys;sa=editicons'); |
|
| 1933 | + } |
|
| 1850 | 1934 | } |
| 1851 | 1935 | |
| 1852 | 1936 | $context[$context['admin_menu_name']]['current_subsection'] = 'editicons'; |
@@ -1956,8 +2040,9 @@ discard block |
||
| 1956 | 2040 | $context['new_icon'] = !isset($_GET['icon']); |
| 1957 | 2041 | |
| 1958 | 2042 | // Get the properties of the current icon from the icon list. |
| 1959 | - if (!$context['new_icon']) |
|
| 1960 | - $context['icon'] = $context['icons'][$_GET['icon']]; |
|
| 2043 | + if (!$context['new_icon']) { |
|
| 2044 | + $context['icon'] = $context['icons'][$_GET['icon']]; |
|
| 2045 | + } |
|
| 1961 | 2046 | |
| 1962 | 2047 | // Get a list of boards needed for assigning this icon to a specific board. |
| 1963 | 2048 | $boardListOptions = array( |
@@ -1991,8 +2076,9 @@ discard block |
||
| 1991 | 2076 | ); |
| 1992 | 2077 | |
| 1993 | 2078 | $message_icons = array(); |
| 1994 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1995 | - $message_icons[] = $row; |
|
| 2079 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2080 | + $message_icons[] = $row; |
|
| 2081 | + } |
|
| 1996 | 2082 | $smcFunc['db_free_result']($request); |
| 1997 | 2083 | |
| 1998 | 2084 | return $message_icons; |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 3 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('No direct access...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Fetches the list of preferences (or a single/subset of preferences) for |
@@ -30,8 +31,9 @@ discard block |
||
| 30 | 31 | // We want this as an array whether it is or not. |
| 31 | 32 | $members = is_array($members) ? $members : (array) $members; |
| 32 | 33 | |
| 33 | - if (!empty($prefs)) |
|
| 34 | - $prefs = is_array($prefs) ? $prefs : (array) $prefs; |
|
| 34 | + if (!empty($prefs)) { |
|
| 35 | + $prefs = is_array($prefs) ? $prefs : (array) $prefs; |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | $result = array(); |
| 37 | 39 | |
@@ -56,9 +58,10 @@ discard block |
||
| 56 | 58 | // We may want to keep the default values separate from a given user's. Or we might not. |
| 57 | 59 | if ($process_default && isset($result[0])) |
| 58 | 60 | { |
| 59 | - foreach ($members as $member) |
|
| 60 | - if (!isset($result[$member])) |
|
| 61 | + foreach ($members as $member) { |
|
| 62 | + if (!isset($result[$member])) |
|
| 61 | 63 | $result[$member] = $result[0]; |
| 64 | + } |
|
| 62 | 65 | |
| 63 | 66 | unset ($result[0]); |
| 64 | 67 | } |
@@ -76,12 +79,14 @@ discard block |
||
| 76 | 79 | { |
| 77 | 80 | global $smcFunc; |
| 78 | 81 | |
| 79 | - if (empty($prefs) || !is_int($memID)) |
|
| 80 | - return; |
|
| 82 | + if (empty($prefs) || !is_int($memID)) { |
|
| 83 | + return; |
|
| 84 | + } |
|
| 81 | 85 | |
| 82 | 86 | $update_rows = array(); |
| 83 | - foreach ($prefs as $k => $v) |
|
| 84 | - $update_rows[] = array($memID, $k, $v); |
|
| 87 | + foreach ($prefs as $k => $v) { |
|
| 88 | + $update_rows[] = array($memID, $k, $v); |
|
| 89 | + } |
|
| 85 | 90 | |
| 86 | 91 | $smcFunc['db_insert']('replace', |
| 87 | 92 | '{db_prefix}user_alerts_prefs', |
@@ -101,8 +106,9 @@ discard block |
||
| 101 | 106 | { |
| 102 | 107 | global $smcFunc; |
| 103 | 108 | |
| 104 | - if (empty($prefs) || empty($memID)) |
|
| 105 | - return; |
|
| 109 | + if (empty($prefs) || empty($memID)) { |
|
| 110 | + return; |
|
| 111 | + } |
|
| 106 | 112 | |
| 107 | 113 | $smcFunc['db_query']('', ' |
| 108 | 114 | DELETE FROM {db_prefix}user_alerts_prefs |
@@ -742,7 +742,7 @@ discard block |
||
| 742 | 742 | |
| 743 | 743 | // For each table.... |
| 744 | 744 | $_SESSION['optimized_tables'] = !empty($_SESSION['optimized_tables']) ? $_SESSION['optimized_tables'] : array(); |
| 745 | - for ($key=$_REQUEST['start']; $context['num_tables']-1; $key++) |
|
| 745 | + for ($key = $_REQUEST['start']; $context['num_tables'] - 1; $key++) |
|
| 746 | 746 | { |
| 747 | 747 | if (empty($tables[$key])) |
| 748 | 748 | break; |
@@ -1905,10 +1905,10 @@ discard block |
||
| 1905 | 1905 | 'value' => $txt['hooks_field_function_name'], |
| 1906 | 1906 | ), |
| 1907 | 1907 | 'data' => array( |
| 1908 | - 'function' => function ($data) use ($txt) |
|
| 1908 | + 'function' => function($data) use ($txt) |
|
| 1909 | 1909 | { |
| 1910 | 1910 | // Show a nice icon to indicate this is an instance. |
| 1911 | - $instance = (!empty($data['instance']) ? '<span class="generic_icons news" title="'. $txt['hooks_field_function_method'] .'"></span> ' : ''); |
|
| 1911 | + $instance = (!empty($data['instance']) ? '<span class="generic_icons news" title="' . $txt['hooks_field_function_method'] . '"></span> ' : ''); |
|
| 1912 | 1912 | |
| 1913 | 1913 | if (!empty($data['included_file'])) |
| 1914 | 1914 | return $instance . $txt['hooks_field_function'] . ': ' . $data['real_function'] . '<br>' . $txt['hooks_field_included_file'] . ': ' . $data['included_file']; |
@@ -1940,7 +1940,7 @@ discard block |
||
| 1940 | 1940 | 'style' => 'width:3%;', |
| 1941 | 1941 | ), |
| 1942 | 1942 | 'data' => array( |
| 1943 | - 'function' => function ($data) use ($txt, $scripturl, $context) |
|
| 1943 | + 'function' => function($data) use ($txt, $scripturl, $context) |
|
| 1944 | 1944 | { |
| 1945 | 1945 | $change_status = array('before' => '', 'after' => ''); |
| 1946 | 1946 | |
@@ -1977,7 +1977,7 @@ discard block |
||
| 1977 | 1977 | 'style' => 'width:3%', |
| 1978 | 1978 | ), |
| 1979 | 1979 | 'data' => array( |
| 1980 | - 'function' => function ($data) use ($txt, $scripturl, $context) |
|
| 1980 | + 'function' => function($data) use ($txt, $scripturl, $context) |
|
| 1981 | 1981 | { |
| 1982 | 1982 | if (!$data['hook_exists']) |
| 1983 | 1983 | return ' |
@@ -2113,7 +2113,7 @@ discard block |
||
| 2113 | 2113 | $context['insert_after_template'] .= ' |
| 2114 | 2114 | <script> |
| 2115 | 2115 | var hook_name_header = document.getElementById(\'header_list_integration_hooks_hook_name\'); |
| 2116 | - hook_name_header.innerHTML += ' . JavaScriptEscape('<select style="margin-left:15px;" onchange="window.location=(\'' . $scripturl . '?action=admin;area=maintain;sa=hooks\' + (this.value ? \';filter=\' + this.value : \'\'));"><option value="">' . $txt['hooks_reset_filter'] . '</option>' . implode('', $hooks_filters) . '</select>'). '; |
|
| 2116 | + hook_name_header.innerHTML += ' . JavaScriptEscape('<select style="margin-left:15px;" onchange="window.location=(\'' . $scripturl . '?action=admin;area=maintain;sa=hooks\' + (this.value ? \';filter=\' + this.value : \'\'));"><option value="">' . $txt['hooks_reset_filter'] . '</option>' . implode('', $hooks_filters) . '</select>') . '; |
|
| 2117 | 2117 | </script>'; |
| 2118 | 2118 | |
| 2119 | 2119 | $temp_data = array(); |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Main dispatcher, the maintenance access point. |
@@ -96,14 +97,16 @@ discard block |
||
| 96 | 97 | call_integration_hook('integrate_manage_maintenance', array(&$subActions)); |
| 97 | 98 | |
| 98 | 99 | // Yep, sub-action time! |
| 99 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
| 100 | - $subAction = $_REQUEST['sa']; |
|
| 101 | - else |
|
| 102 | - $subAction = 'routine'; |
|
| 100 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
| 101 | + $subAction = $_REQUEST['sa']; |
|
| 102 | + } else { |
|
| 103 | + $subAction = 'routine'; |
|
| 104 | + } |
|
| 103 | 105 | |
| 104 | 106 | // Doing something special? |
| 105 | - if (isset($_REQUEST['activity']) && isset($subActions[$subAction]['activities'][$_REQUEST['activity']])) |
|
| 106 | - $activity = $_REQUEST['activity']; |
|
| 107 | + if (isset($_REQUEST['activity']) && isset($subActions[$subAction]['activities'][$_REQUEST['activity']])) { |
|
| 108 | + $activity = $_REQUEST['activity']; |
|
| 109 | + } |
|
| 107 | 110 | |
| 108 | 111 | // Set a few things. |
| 109 | 112 | $context['page_title'] = $txt['maintain_title']; |
@@ -114,12 +117,14 @@ discard block |
||
| 114 | 117 | call_helper($subActions[$subAction]['function']); |
| 115 | 118 | |
| 116 | 119 | // Any special activity? |
| 117 | - if (isset($activity)) |
|
| 118 | - call_helper($subActions[$subAction]['activities'][$activity]); |
|
| 120 | + if (isset($activity)) { |
|
| 121 | + call_helper($subActions[$subAction]['activities'][$activity]); |
|
| 122 | + } |
|
| 119 | 123 | |
| 120 | 124 | //converted to UTF-8? show a small maintenance info |
| 121 | - if (isset($_GET['done']) && $_GET['done'] == 'convertutf8') |
|
| 122 | - $context['maintenance_finished'] = $txt['utf8_title']; |
|
| 125 | + if (isset($_GET['done']) && $_GET['done'] == 'convertutf8') { |
|
| 126 | + $context['maintenance_finished'] = $txt['utf8_title']; |
|
| 127 | + } |
|
| 123 | 128 | |
| 124 | 129 | // Create a maintenance token. Kinda hard to do it any other way. |
| 125 | 130 | createToken('admin-maint'); |
@@ -141,19 +146,22 @@ discard block |
||
| 141 | 146 | db_extend('packages'); |
| 142 | 147 | |
| 143 | 148 | $colData = $smcFunc['db_list_columns']('{db_prefix}messages', true); |
| 144 | - foreach ($colData as $column) |
|
| 145 | - if ($column['name'] == 'body') |
|
| 149 | + foreach ($colData as $column) { |
|
| 150 | + if ($column['name'] == 'body') |
|
| 146 | 151 | $body_type = $column['type']; |
| 152 | + } |
|
| 147 | 153 | |
| 148 | 154 | $context['convert_to'] = $body_type == 'text' ? 'mediumtext' : 'text'; |
| 149 | 155 | $context['convert_to_suggest'] = ($body_type != 'text' && !empty($modSettings['max_messageLength']) && $modSettings['max_messageLength'] < 65536); |
| 150 | 156 | } |
| 151 | 157 | |
| 152 | - if (isset($_GET['done']) && $_GET['done'] == 'convertutf8') |
|
| 153 | - $context['maintenance_finished'] = $txt['utf8_title']; |
|
| 154 | - if (isset($_GET['done']) && $_GET['done'] == 'convertentities') |
|
| 155 | - $context['maintenance_finished'] = $txt['entity_convert_title']; |
|
| 156 | -} |
|
| 158 | + if (isset($_GET['done']) && $_GET['done'] == 'convertutf8') { |
|
| 159 | + $context['maintenance_finished'] = $txt['utf8_title']; |
|
| 160 | + } |
|
| 161 | + if (isset($_GET['done']) && $_GET['done'] == 'convertentities') { |
|
| 162 | + $context['maintenance_finished'] = $txt['entity_convert_title']; |
|
| 163 | + } |
|
| 164 | + } |
|
| 157 | 165 | |
| 158 | 166 | /** |
| 159 | 167 | * Supporting function for the routine maintenance area. |
@@ -162,9 +170,10 @@ discard block |
||
| 162 | 170 | { |
| 163 | 171 | global $context, $txt; |
| 164 | 172 | |
| 165 | - if (isset($_GET['done']) && $_GET['done'] == 'recount') |
|
| 166 | - $context['maintenance_finished'] = $txt['maintain_recount']; |
|
| 167 | -} |
|
| 173 | + if (isset($_GET['done']) && $_GET['done'] == 'recount') { |
|
| 174 | + $context['maintenance_finished'] = $txt['maintain_recount']; |
|
| 175 | + } |
|
| 176 | + } |
|
| 168 | 177 | |
| 169 | 178 | /** |
| 170 | 179 | * Supporting function for the members maintenance area. |
@@ -195,8 +204,9 @@ discard block |
||
| 195 | 204 | } |
| 196 | 205 | $smcFunc['db_free_result']($result); |
| 197 | 206 | |
| 198 | - if (isset($_GET['done']) && $_GET['done'] == 'recountposts') |
|
| 199 | - $context['maintenance_finished'] = $txt['maintain_recountposts']; |
|
| 207 | + if (isset($_GET['done']) && $_GET['done'] == 'recountposts') { |
|
| 208 | + $context['maintenance_finished'] = $txt['maintain_recountposts']; |
|
| 209 | + } |
|
| 200 | 210 | |
| 201 | 211 | loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
| 202 | 212 | } |
@@ -222,11 +232,12 @@ discard block |
||
| 222 | 232 | $context['categories'] = array(); |
| 223 | 233 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 224 | 234 | { |
| 225 | - if (!isset($context['categories'][$row['id_cat']])) |
|
| 226 | - $context['categories'][$row['id_cat']] = array( |
|
| 235 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
| 236 | + $context['categories'][$row['id_cat']] = array( |
|
| 227 | 237 | 'name' => $row['cat_name'], |
| 228 | 238 | 'boards' => array() |
| 229 | 239 | ); |
| 240 | + } |
|
| 230 | 241 | |
| 231 | 242 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
| 232 | 243 | 'id' => $row['id_board'], |
@@ -239,11 +250,12 @@ discard block |
||
| 239 | 250 | require_once($sourcedir . '/Subs-Boards.php'); |
| 240 | 251 | sortCategories($context['categories']); |
| 241 | 252 | |
| 242 | - if (isset($_GET['done']) && $_GET['done'] == 'purgeold') |
|
| 243 | - $context['maintenance_finished'] = $txt['maintain_old']; |
|
| 244 | - elseif (isset($_GET['done']) && $_GET['done'] == 'massmove') |
|
| 245 | - $context['maintenance_finished'] = $txt['move_topics_maintenance']; |
|
| 246 | -} |
|
| 253 | + if (isset($_GET['done']) && $_GET['done'] == 'purgeold') { |
|
| 254 | + $context['maintenance_finished'] = $txt['maintain_old']; |
|
| 255 | + } elseif (isset($_GET['done']) && $_GET['done'] == 'massmove') { |
|
| 256 | + $context['maintenance_finished'] = $txt['move_topics_maintenance']; |
|
| 257 | + } |
|
| 258 | + } |
|
| 247 | 259 | |
| 248 | 260 | /** |
| 249 | 261 | * Find and fix all errors on the forum. |
@@ -351,15 +363,17 @@ discard block |
||
| 351 | 363 | // Show me your badge! |
| 352 | 364 | isAllowedTo('admin_forum'); |
| 353 | 365 | |
| 354 | - if ($db_type != 'mysql' && $db_type != 'mysqli') |
|
| 355 | - return; |
|
| 366 | + if ($db_type != 'mysql' && $db_type != 'mysqli') { |
|
| 367 | + return; |
|
| 368 | + } |
|
| 356 | 369 | |
| 357 | 370 | db_extend('packages'); |
| 358 | 371 | |
| 359 | 372 | $colData = $smcFunc['db_list_columns']('{db_prefix}messages', true); |
| 360 | - foreach ($colData as $column) |
|
| 361 | - if ($column['name'] == 'body') |
|
| 373 | + foreach ($colData as $column) { |
|
| 374 | + if ($column['name'] == 'body') |
|
| 362 | 375 | $body_type = $column['type']; |
| 376 | + } |
|
| 363 | 377 | |
| 364 | 378 | $context['convert_to'] = $body_type == 'text' ? 'mediumtext' : 'text'; |
| 365 | 379 | |
@@ -369,19 +383,22 @@ discard block |
||
| 369 | 383 | validateToken('admin-maint'); |
| 370 | 384 | |
| 371 | 385 | // Make it longer so we can do their limit. |
| 372 | - if ($body_type == 'text') |
|
| 373 | - $smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'mediumtext')); |
|
| 386 | + if ($body_type == 'text') { |
|
| 387 | + $smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'mediumtext')); |
|
| 388 | + } |
|
| 374 | 389 | // Shorten the column so we can have a bit (literally per record) less space occupied |
| 375 | - else |
|
| 376 | - $smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'text')); |
|
| 390 | + else { |
|
| 391 | + $smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'text')); |
|
| 392 | + } |
|
| 377 | 393 | |
| 378 | 394 | // 3rd party integrations may be interested in knowning about this. |
| 379 | 395 | call_integration_hook('integrate_convert_msgbody', array($body_type)); |
| 380 | 396 | |
| 381 | 397 | $colData = $smcFunc['db_list_columns']('{db_prefix}messages', true); |
| 382 | - foreach ($colData as $column) |
|
| 383 | - if ($column['name'] == 'body') |
|
| 398 | + foreach ($colData as $column) { |
|
| 399 | + if ($column['name'] == 'body') |
|
| 384 | 400 | $body_type = $column['type']; |
| 401 | + } |
|
| 385 | 402 | |
| 386 | 403 | $context['maintenance_finished'] = $txt[$context['convert_to'] . '_title']; |
| 387 | 404 | $context['convert_to'] = $body_type == 'text' ? 'mediumtext' : 'text'; |
@@ -389,14 +406,14 @@ discard block |
||
| 389 | 406 | |
| 390 | 407 | return; |
| 391 | 408 | redirectexit('action=admin;area=maintain;sa=database'); |
| 392 | - } |
|
| 393 | - elseif ($body_type != 'text' && (!isset($_POST['do_conversion']) || isset($_POST['cont']))) |
|
| 409 | + } elseif ($body_type != 'text' && (!isset($_POST['do_conversion']) || isset($_POST['cont']))) |
|
| 394 | 410 | { |
| 395 | 411 | checkSession(); |
| 396 | - if (empty($_REQUEST['start'])) |
|
| 397 | - validateToken('admin-maint'); |
|
| 398 | - else |
|
| 399 | - validateToken('admin-convertMsg'); |
|
| 412 | + if (empty($_REQUEST['start'])) { |
|
| 413 | + validateToken('admin-maint'); |
|
| 414 | + } else { |
|
| 415 | + validateToken('admin-convertMsg'); |
|
| 416 | + } |
|
| 400 | 417 | |
| 401 | 418 | $context['page_title'] = $txt['not_done_title']; |
| 402 | 419 | $context['continue_post_data'] = ''; |
@@ -428,8 +445,9 @@ discard block |
||
| 428 | 445 | 'increment' => $increment - 1, |
| 429 | 446 | ) |
| 430 | 447 | ); |
| 431 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 432 | - $id_msg_exceeding[] = $row['id_msg']; |
|
| 448 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 449 | + $id_msg_exceeding[] = $row['id_msg']; |
|
| 450 | + } |
|
| 433 | 451 | $smcFunc['db_free_result']($request); |
| 434 | 452 | |
| 435 | 453 | $_REQUEST['start'] += $increment; |
@@ -458,9 +476,9 @@ discard block |
||
| 458 | 476 | { |
| 459 | 477 | $query_msg = array_slice($id_msg_exceeding, 0, 100); |
| 460 | 478 | $context['exceeding_messages_morethan'] = sprintf($txt['exceeding_messages_morethan'], count($id_msg_exceeding)); |
| 479 | + } else { |
|
| 480 | + $query_msg = $id_msg_exceeding; |
|
| 461 | 481 | } |
| 462 | - else |
|
| 463 | - $query_msg = $id_msg_exceeding; |
|
| 464 | 482 | |
| 465 | 483 | $context['exceeding_messages'] = array(); |
| 466 | 484 | $request = $smcFunc['db_query']('', ' |
@@ -471,8 +489,9 @@ discard block |
||
| 471 | 489 | 'messages' => $query_msg, |
| 472 | 490 | ) |
| 473 | 491 | ); |
| 474 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 475 | - $context['exceeding_messages'][] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>'; |
|
| 492 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 493 | + $context['exceeding_messages'][] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>'; |
|
| 494 | + } |
|
| 476 | 495 | $smcFunc['db_free_result']($request); |
| 477 | 496 | } |
| 478 | 497 | } |
@@ -496,8 +515,9 @@ discard block |
||
| 496 | 515 | isAllowedTo('admin_forum'); |
| 497 | 516 | |
| 498 | 517 | // Check to see if UTF-8 is currently the default character set. |
| 499 | - if ($modSettings['global_character_set'] !== 'UTF-8' || !isset($db_character_set) || $db_character_set !== 'utf8') |
|
| 500 | - fatal_lang_error('entity_convert_only_utf8'); |
|
| 518 | + if ($modSettings['global_character_set'] !== 'UTF-8' || !isset($db_character_set) || $db_character_set !== 'utf8') { |
|
| 519 | + fatal_lang_error('entity_convert_only_utf8'); |
|
| 520 | + } |
|
| 501 | 521 | |
| 502 | 522 | // Some starting values. |
| 503 | 523 | $context['table'] = empty($_REQUEST['table']) ? 0 : (int) $_REQUEST['table']; |
@@ -559,8 +579,9 @@ discard block |
||
| 559 | 579 | // Make sure we keep stuff unique! |
| 560 | 580 | $primary_keys = array(); |
| 561 | 581 | |
| 562 | - if (function_exists('apache_reset_timeout')) |
|
| 563 | - @apache_reset_timeout(); |
|
| 582 | + if (function_exists('apache_reset_timeout')) { |
|
| 583 | + @apache_reset_timeout(); |
|
| 584 | + } |
|
| 564 | 585 | |
| 565 | 586 | // Get a list of text columns. |
| 566 | 587 | $columns = array(); |
@@ -571,9 +592,10 @@ discard block |
||
| 571 | 592 | 'cur_table' => $cur_table, |
| 572 | 593 | ) |
| 573 | 594 | ); |
| 574 | - while ($column_info = $smcFunc['db_fetch_assoc']($request)) |
|
| 575 | - if (strpos($column_info['Type'], 'text') !== false || strpos($column_info['Type'], 'char') !== false) |
|
| 595 | + while ($column_info = $smcFunc['db_fetch_assoc']($request)) { |
|
| 596 | + if (strpos($column_info['Type'], 'text') !== false || strpos($column_info['Type'], 'char') !== false) |
|
| 576 | 597 | $columns[] = strtolower($column_info['Field']); |
| 598 | + } |
|
| 577 | 599 | |
| 578 | 600 | // Get the column with the (first) primary key. |
| 579 | 601 | $request = $smcFunc['db_query']('', ' |
@@ -587,8 +609,9 @@ discard block |
||
| 587 | 609 | { |
| 588 | 610 | if ($row['Key_name'] === 'PRIMARY') |
| 589 | 611 | { |
| 590 | - if (empty($primary_key) || ($row['Seq_in_index'] == 1 && !in_array(strtolower($row['Column_name']), $columns))) |
|
| 591 | - $primary_key = $row['Column_name']; |
|
| 612 | + if (empty($primary_key) || ($row['Seq_in_index'] == 1 && !in_array(strtolower($row['Column_name']), $columns))) { |
|
| 613 | + $primary_key = $row['Column_name']; |
|
| 614 | + } |
|
| 592 | 615 | |
| 593 | 616 | $primary_keys[] = $row['Column_name']; |
| 594 | 617 | } |
@@ -597,8 +620,9 @@ discard block |
||
| 597 | 620 | |
| 598 | 621 | // No primary key, no glory. |
| 599 | 622 | // Same for columns. Just to be sure we've work to do! |
| 600 | - if (empty($primary_key) || empty($columns)) |
|
| 601 | - continue; |
|
| 623 | + if (empty($primary_key) || empty($columns)) { |
|
| 624 | + continue; |
|
| 625 | + } |
|
| 602 | 626 | |
| 603 | 627 | // Get the maximum value for the primary key. |
| 604 | 628 | $request = $smcFunc['db_query']('', ' |
@@ -612,8 +636,9 @@ discard block |
||
| 612 | 636 | list($max_value) = $smcFunc['db_fetch_row']($request); |
| 613 | 637 | $smcFunc['db_free_result']($request); |
| 614 | 638 | |
| 615 | - if (empty($max_value)) |
|
| 616 | - continue; |
|
| 639 | + if (empty($max_value)) { |
|
| 640 | + continue; |
|
| 641 | + } |
|
| 617 | 642 | |
| 618 | 643 | while ($context['start'] <= $max_value) |
| 619 | 644 | { |
@@ -637,10 +662,11 @@ discard block |
||
| 637 | 662 | { |
| 638 | 663 | $insertion_variables = array(); |
| 639 | 664 | $changes = array(); |
| 640 | - foreach ($row as $column_name => $column_value) |
|
| 641 | - if ($column_name !== $primary_key && strpos($column_value, '&#') !== false) |
|
| 665 | + foreach ($row as $column_name => $column_value) { |
|
| 666 | + if ($column_name !== $primary_key && strpos($column_value, '&#') !== false) |
|
| 642 | 667 | { |
| 643 | 668 | $changes[] = $column_name . ' = {string:changes_' . $column_name . '}'; |
| 669 | + } |
|
| 644 | 670 | $insertion_variables['changes_' . $column_name] = preg_replace_callback('~&#(\d{1,7}|x[0-9a-fA-F]{1,6});~', 'fixchar__callback', $column_value); |
| 645 | 671 | } |
| 646 | 672 | |
@@ -652,8 +678,8 @@ discard block |
||
| 652 | 678 | } |
| 653 | 679 | |
| 654 | 680 | // Update the row. |
| 655 | - if (!empty($changes)) |
|
| 656 | - $smcFunc['db_query']('', ' |
|
| 681 | + if (!empty($changes)) { |
|
| 682 | + $smcFunc['db_query']('', ' |
|
| 657 | 683 | UPDATE {db_prefix}' . $cur_table . ' |
| 658 | 684 | SET |
| 659 | 685 | ' . implode(', |
@@ -661,6 +687,7 @@ discard block |
||
| 661 | 687 | WHERE ' . implode(' AND ', $where), |
| 662 | 688 | $insertion_variables |
| 663 | 689 | ); |
| 690 | + } |
|
| 664 | 691 | } |
| 665 | 692 | $smcFunc['db_free_result']($request); |
| 666 | 693 | $context['start'] += 500; |
@@ -705,10 +732,11 @@ discard block |
||
| 705 | 732 | |
| 706 | 733 | checkSession('request'); |
| 707 | 734 | |
| 708 | - if (!isset($_SESSION['optimized_tables'])) |
|
| 709 | - validateToken('admin-maint'); |
|
| 710 | - else |
|
| 711 | - validateToken('admin-optimize', 'post', false); |
|
| 735 | + if (!isset($_SESSION['optimized_tables'])) { |
|
| 736 | + validateToken('admin-maint'); |
|
| 737 | + } else { |
|
| 738 | + validateToken('admin-optimize', 'post', false); |
|
| 739 | + } |
|
| 712 | 740 | |
| 713 | 741 | ignore_user_abort(true); |
| 714 | 742 | db_extend(); |
@@ -727,13 +755,15 @@ discard block |
||
| 727 | 755 | // Get a list of tables, as well as how many there are. |
| 728 | 756 | $temp_tables = $smcFunc['db_list_tables'](false, $real_prefix . '%'); |
| 729 | 757 | $tables = array(); |
| 730 | - foreach ($temp_tables as $table) |
|
| 731 | - $tables[] = array('table_name' => $table); |
|
| 758 | + foreach ($temp_tables as $table) { |
|
| 759 | + $tables[] = array('table_name' => $table); |
|
| 760 | + } |
|
| 732 | 761 | |
| 733 | 762 | // If there aren't any tables then I believe that would mean the world has exploded... |
| 734 | 763 | $context['num_tables'] = count($tables); |
| 735 | - if ($context['num_tables'] == 0) |
|
| 736 | - fatal_error('You appear to be running SMF in a flat file mode... fantastic!', false); |
|
| 764 | + if ($context['num_tables'] == 0) { |
|
| 765 | + fatal_error('You appear to be running SMF in a flat file mode... fantastic!', false); |
|
| 766 | + } |
|
| 737 | 767 | |
| 738 | 768 | $_REQUEST['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start']; |
| 739 | 769 | |
@@ -744,8 +774,9 @@ discard block |
||
| 744 | 774 | $_SESSION['optimized_tables'] = !empty($_SESSION['optimized_tables']) ? $_SESSION['optimized_tables'] : array(); |
| 745 | 775 | for ($key=$_REQUEST['start']; $context['num_tables']-1; $key++) |
| 746 | 776 | { |
| 747 | - if (empty($tables[$key])) |
|
| 748 | - break; |
|
| 777 | + if (empty($tables[$key])) { |
|
| 778 | + break; |
|
| 779 | + } |
|
| 749 | 780 | |
| 750 | 781 | // Continue? |
| 751 | 782 | if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)) > 10) |
@@ -759,8 +790,9 @@ discard block |
||
| 759 | 790 | createToken('admin-optimize'); |
| 760 | 791 | $context['continue_post_data'] = '<input type="hidden" name="' . $context['admin-optimize_token_var'] . '" value="' . $context['admin-optimize_token'] . '">'; |
| 761 | 792 | |
| 762 | - if (function_exists('apache_reset_timeout')) |
|
| 763 | - apache_reset_timeout(); |
|
| 793 | + if (function_exists('apache_reset_timeout')) { |
|
| 794 | + apache_reset_timeout(); |
|
| 795 | + } |
|
| 764 | 796 | |
| 765 | 797 | return; |
| 766 | 798 | } |
@@ -768,11 +800,12 @@ discard block |
||
| 768 | 800 | // Optimize the table! We use backticks here because it might be a custom table. |
| 769 | 801 | $data_freed = $smcFunc['db_optimize_table']($tables[$key]['table_name']); |
| 770 | 802 | |
| 771 | - if ($data_freed > 0) |
|
| 772 | - $_SESSION['optimized_tables'][] = array( |
|
| 803 | + if ($data_freed > 0) { |
|
| 804 | + $_SESSION['optimized_tables'][] = array( |
|
| 773 | 805 | 'name' => $tables[$key]['table_name'], |
| 774 | 806 | 'data_freed' => $data_freed, |
| 775 | 807 | ); |
| 808 | + } |
|
| 776 | 809 | } |
| 777 | 810 | |
| 778 | 811 | // Number of tables, etc... |
@@ -807,10 +840,11 @@ discard block |
||
| 807 | 840 | checkSession('request'); |
| 808 | 841 | |
| 809 | 842 | // validate the request or the loop |
| 810 | - if (!isset($_REQUEST['step'])) |
|
| 811 | - validateToken('admin-maint'); |
|
| 812 | - else |
|
| 813 | - validateToken('admin-boardrecount'); |
|
| 843 | + if (!isset($_REQUEST['step'])) { |
|
| 844 | + validateToken('admin-maint'); |
|
| 845 | + } else { |
|
| 846 | + validateToken('admin-boardrecount'); |
|
| 847 | + } |
|
| 814 | 848 | |
| 815 | 849 | $context['page_title'] = $txt['not_done_title']; |
| 816 | 850 | $context['continue_post_data'] = ''; |
@@ -831,8 +865,9 @@ discard block |
||
| 831 | 865 | $smcFunc['db_free_result']($request); |
| 832 | 866 | |
| 833 | 867 | $increment = min(max(50, ceil($max_topics / 4)), 2000); |
| 834 | - if (empty($_REQUEST['start'])) |
|
| 835 | - $_REQUEST['start'] = 0; |
|
| 868 | + if (empty($_REQUEST['start'])) { |
|
| 869 | + $_REQUEST['start'] = 0; |
|
| 870 | + } |
|
| 836 | 871 | |
| 837 | 872 | $total_steps = 8; |
| 838 | 873 | |
@@ -859,8 +894,8 @@ discard block |
||
| 859 | 894 | 'max_id' => $_REQUEST['start'] + $increment, |
| 860 | 895 | ) |
| 861 | 896 | ); |
| 862 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 863 | - $smcFunc['db_query']('', ' |
|
| 897 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 898 | + $smcFunc['db_query']('', ' |
|
| 864 | 899 | UPDATE {db_prefix}topics |
| 865 | 900 | SET num_replies = {int:num_replies} |
| 866 | 901 | WHERE id_topic = {int:id_topic}', |
@@ -869,6 +904,7 @@ discard block |
||
| 869 | 904 | 'id_topic' => $row['id_topic'], |
| 870 | 905 | ) |
| 871 | 906 | ); |
| 907 | + } |
|
| 872 | 908 | $smcFunc['db_free_result']($request); |
| 873 | 909 | |
| 874 | 910 | // Recount unapproved messages |
@@ -887,8 +923,8 @@ discard block |
||
| 887 | 923 | 'max_id' => $_REQUEST['start'] + $increment, |
| 888 | 924 | ) |
| 889 | 925 | ); |
| 890 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 891 | - $smcFunc['db_query']('', ' |
|
| 926 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 927 | + $smcFunc['db_query']('', ' |
|
| 892 | 928 | UPDATE {db_prefix}topics |
| 893 | 929 | SET unapproved_posts = {int:unapproved_posts} |
| 894 | 930 | WHERE id_topic = {int:id_topic}', |
@@ -897,6 +933,7 @@ discard block |
||
| 897 | 933 | 'id_topic' => $row['id_topic'], |
| 898 | 934 | ) |
| 899 | 935 | ); |
| 936 | + } |
|
| 900 | 937 | $smcFunc['db_free_result']($request); |
| 901 | 938 | |
| 902 | 939 | $_REQUEST['start'] += $increment; |
@@ -919,8 +956,8 @@ discard block |
||
| 919 | 956 | // Update the post count of each board. |
| 920 | 957 | if ($_REQUEST['step'] <= 1) |
| 921 | 958 | { |
| 922 | - if (empty($_REQUEST['start'])) |
|
| 923 | - $smcFunc['db_query']('', ' |
|
| 959 | + if (empty($_REQUEST['start'])) { |
|
| 960 | + $smcFunc['db_query']('', ' |
|
| 924 | 961 | UPDATE {db_prefix}boards |
| 925 | 962 | SET num_posts = {int:num_posts} |
| 926 | 963 | WHERE redirect = {string:redirect}', |
@@ -929,6 +966,7 @@ discard block |
||
| 929 | 966 | 'redirect' => '', |
| 930 | 967 | ) |
| 931 | 968 | ); |
| 969 | + } |
|
| 932 | 970 | |
| 933 | 971 | while ($_REQUEST['start'] < $max_topics) |
| 934 | 972 | { |
@@ -945,8 +983,8 @@ discard block |
||
| 945 | 983 | 'is_approved' => 1, |
| 946 | 984 | ) |
| 947 | 985 | ); |
| 948 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 949 | - $smcFunc['db_query']('', ' |
|
| 986 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 987 | + $smcFunc['db_query']('', ' |
|
| 950 | 988 | UPDATE {db_prefix}boards |
| 951 | 989 | SET num_posts = num_posts + {int:real_num_posts} |
| 952 | 990 | WHERE id_board = {int:id_board}', |
@@ -955,6 +993,7 @@ discard block |
||
| 955 | 993 | 'real_num_posts' => $row['real_num_posts'], |
| 956 | 994 | ) |
| 957 | 995 | ); |
| 996 | + } |
|
| 958 | 997 | $smcFunc['db_free_result']($request); |
| 959 | 998 | |
| 960 | 999 | $_REQUEST['start'] += $increment; |
@@ -977,14 +1016,15 @@ discard block |
||
| 977 | 1016 | // Update the topic count of each board. |
| 978 | 1017 | if ($_REQUEST['step'] <= 2) |
| 979 | 1018 | { |
| 980 | - if (empty($_REQUEST['start'])) |
|
| 981 | - $smcFunc['db_query']('', ' |
|
| 1019 | + if (empty($_REQUEST['start'])) { |
|
| 1020 | + $smcFunc['db_query']('', ' |
|
| 982 | 1021 | UPDATE {db_prefix}boards |
| 983 | 1022 | SET num_topics = {int:num_topics}', |
| 984 | 1023 | array( |
| 985 | 1024 | 'num_topics' => 0, |
| 986 | 1025 | ) |
| 987 | 1026 | ); |
| 1027 | + } |
|
| 988 | 1028 | |
| 989 | 1029 | while ($_REQUEST['start'] < $max_topics) |
| 990 | 1030 | { |
@@ -1001,8 +1041,8 @@ discard block |
||
| 1001 | 1041 | 'id_topic_max' => $_REQUEST['start'] + $increment, |
| 1002 | 1042 | ) |
| 1003 | 1043 | ); |
| 1004 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1005 | - $smcFunc['db_query']('', ' |
|
| 1044 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1045 | + $smcFunc['db_query']('', ' |
|
| 1006 | 1046 | UPDATE {db_prefix}boards |
| 1007 | 1047 | SET num_topics = num_topics + {int:real_num_topics} |
| 1008 | 1048 | WHERE id_board = {int:id_board}', |
@@ -1011,6 +1051,7 @@ discard block |
||
| 1011 | 1051 | 'real_num_topics' => $row['real_num_topics'], |
| 1012 | 1052 | ) |
| 1013 | 1053 | ); |
| 1054 | + } |
|
| 1014 | 1055 | $smcFunc['db_free_result']($request); |
| 1015 | 1056 | |
| 1016 | 1057 | $_REQUEST['start'] += $increment; |
@@ -1033,14 +1074,15 @@ discard block |
||
| 1033 | 1074 | // Update the unapproved post count of each board. |
| 1034 | 1075 | if ($_REQUEST['step'] <= 3) |
| 1035 | 1076 | { |
| 1036 | - if (empty($_REQUEST['start'])) |
|
| 1037 | - $smcFunc['db_query']('', ' |
|
| 1077 | + if (empty($_REQUEST['start'])) { |
|
| 1078 | + $smcFunc['db_query']('', ' |
|
| 1038 | 1079 | UPDATE {db_prefix}boards |
| 1039 | 1080 | SET unapproved_posts = {int:unapproved_posts}', |
| 1040 | 1081 | array( |
| 1041 | 1082 | 'unapproved_posts' => 0, |
| 1042 | 1083 | ) |
| 1043 | 1084 | ); |
| 1085 | + } |
|
| 1044 | 1086 | |
| 1045 | 1087 | while ($_REQUEST['start'] < $max_topics) |
| 1046 | 1088 | { |
@@ -1057,8 +1099,8 @@ discard block |
||
| 1057 | 1099 | 'is_approved' => 0, |
| 1058 | 1100 | ) |
| 1059 | 1101 | ); |
| 1060 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1061 | - $smcFunc['db_query']('', ' |
|
| 1102 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1103 | + $smcFunc['db_query']('', ' |
|
| 1062 | 1104 | UPDATE {db_prefix}boards |
| 1063 | 1105 | SET unapproved_posts = unapproved_posts + {int:unapproved_posts} |
| 1064 | 1106 | WHERE id_board = {int:id_board}', |
@@ -1067,6 +1109,7 @@ discard block |
||
| 1067 | 1109 | 'unapproved_posts' => $row['real_unapproved_posts'], |
| 1068 | 1110 | ) |
| 1069 | 1111 | ); |
| 1112 | + } |
|
| 1070 | 1113 | $smcFunc['db_free_result']($request); |
| 1071 | 1114 | |
| 1072 | 1115 | $_REQUEST['start'] += $increment; |
@@ -1089,14 +1132,15 @@ discard block |
||
| 1089 | 1132 | // Update the unapproved topic count of each board. |
| 1090 | 1133 | if ($_REQUEST['step'] <= 4) |
| 1091 | 1134 | { |
| 1092 | - if (empty($_REQUEST['start'])) |
|
| 1093 | - $smcFunc['db_query']('', ' |
|
| 1135 | + if (empty($_REQUEST['start'])) { |
|
| 1136 | + $smcFunc['db_query']('', ' |
|
| 1094 | 1137 | UPDATE {db_prefix}boards |
| 1095 | 1138 | SET unapproved_topics = {int:unapproved_topics}', |
| 1096 | 1139 | array( |
| 1097 | 1140 | 'unapproved_topics' => 0, |
| 1098 | 1141 | ) |
| 1099 | 1142 | ); |
| 1143 | + } |
|
| 1100 | 1144 | |
| 1101 | 1145 | while ($_REQUEST['start'] < $max_topics) |
| 1102 | 1146 | { |
@@ -1113,8 +1157,8 @@ discard block |
||
| 1113 | 1157 | 'id_topic_max' => $_REQUEST['start'] + $increment, |
| 1114 | 1158 | ) |
| 1115 | 1159 | ); |
| 1116 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1117 | - $smcFunc['db_query']('', ' |
|
| 1160 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1161 | + $smcFunc['db_query']('', ' |
|
| 1118 | 1162 | UPDATE {db_prefix}boards |
| 1119 | 1163 | SET unapproved_topics = unapproved_topics + {int:real_unapproved_topics} |
| 1120 | 1164 | WHERE id_board = {int:id_board}', |
@@ -1123,6 +1167,7 @@ discard block |
||
| 1123 | 1167 | 'real_unapproved_topics' => $row['real_unapproved_topics'], |
| 1124 | 1168 | ) |
| 1125 | 1169 | ); |
| 1170 | + } |
|
| 1126 | 1171 | $smcFunc['db_free_result']($request); |
| 1127 | 1172 | |
| 1128 | 1173 | $_REQUEST['start'] += $increment; |
@@ -1156,8 +1201,9 @@ discard block |
||
| 1156 | 1201 | 'is_not_deleted' => 0, |
| 1157 | 1202 | ) |
| 1158 | 1203 | ); |
| 1159 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1160 | - updateMemberData($row['id_member'], array('instant_messages' => $row['real_num'])); |
|
| 1204 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1205 | + updateMemberData($row['id_member'], array('instant_messages' => $row['real_num'])); |
|
| 1206 | + } |
|
| 1161 | 1207 | $smcFunc['db_free_result']($request); |
| 1162 | 1208 | |
| 1163 | 1209 | $request = $smcFunc['db_query']('', ' |
@@ -1172,8 +1218,9 @@ discard block |
||
| 1172 | 1218 | 'is_not_read' => 0, |
| 1173 | 1219 | ) |
| 1174 | 1220 | ); |
| 1175 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1176 | - updateMemberData($row['id_member'], array('unread_messages' => $row['real_num'])); |
|
| 1221 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1222 | + updateMemberData($row['id_member'], array('unread_messages' => $row['real_num'])); |
|
| 1223 | + } |
|
| 1177 | 1224 | $smcFunc['db_free_result']($request); |
| 1178 | 1225 | |
| 1179 | 1226 | if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)) > 3) |
@@ -1205,12 +1252,13 @@ discard block |
||
| 1205 | 1252 | ) |
| 1206 | 1253 | ); |
| 1207 | 1254 | $boards = array(); |
| 1208 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1209 | - $boards[$row['id_board']][] = $row['id_msg']; |
|
| 1255 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1256 | + $boards[$row['id_board']][] = $row['id_msg']; |
|
| 1257 | + } |
|
| 1210 | 1258 | $smcFunc['db_free_result']($request); |
| 1211 | 1259 | |
| 1212 | - foreach ($boards as $board_id => $messages) |
|
| 1213 | - $smcFunc['db_query']('', ' |
|
| 1260 | + foreach ($boards as $board_id => $messages) { |
|
| 1261 | + $smcFunc['db_query']('', ' |
|
| 1214 | 1262 | UPDATE {db_prefix}messages |
| 1215 | 1263 | SET id_board = {int:id_board} |
| 1216 | 1264 | WHERE id_msg IN ({array_int:id_msg_array})', |
@@ -1219,6 +1267,7 @@ discard block |
||
| 1219 | 1267 | 'id_board' => $board_id, |
| 1220 | 1268 | ) |
| 1221 | 1269 | ); |
| 1270 | + } |
|
| 1222 | 1271 | |
| 1223 | 1272 | $_REQUEST['start'] += $increment; |
| 1224 | 1273 | |
@@ -1248,8 +1297,9 @@ discard block |
||
| 1248 | 1297 | ) |
| 1249 | 1298 | ); |
| 1250 | 1299 | $realBoardCounts = array(); |
| 1251 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1252 | - $realBoardCounts[$row['id_board']] = $row['local_last_msg']; |
|
| 1300 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1301 | + $realBoardCounts[$row['id_board']] = $row['local_last_msg']; |
|
| 1302 | + } |
|
| 1253 | 1303 | $smcFunc['db_free_result']($request); |
| 1254 | 1304 | |
| 1255 | 1305 | $request = $smcFunc['db_query']('', ' |
@@ -1269,18 +1319,20 @@ discard block |
||
| 1269 | 1319 | krsort($resort_me); |
| 1270 | 1320 | |
| 1271 | 1321 | $lastModifiedMsg = array(); |
| 1272 | - foreach ($resort_me as $rows) |
|
| 1273 | - foreach ($rows as $row) |
|
| 1322 | + foreach ($resort_me as $rows) { |
|
| 1323 | + foreach ($rows as $row) |
|
| 1274 | 1324 | { |
| 1275 | 1325 | // The latest message is the latest of the current board and its children. |
| 1276 | 1326 | if (isset($lastModifiedMsg[$row['id_board']])) |
| 1277 | 1327 | $curLastModifiedMsg = max($row['local_last_msg'], $lastModifiedMsg[$row['id_board']]); |
| 1278 | - else |
|
| 1279 | - $curLastModifiedMsg = $row['local_last_msg']; |
|
| 1328 | + } |
|
| 1329 | + else { |
|
| 1330 | + $curLastModifiedMsg = $row['local_last_msg']; |
|
| 1331 | + } |
|
| 1280 | 1332 | |
| 1281 | 1333 | // If what is and what should be the latest message differ, an update is necessary. |
| 1282 | - if ($row['local_last_msg'] != $row['id_last_msg'] || $curLastModifiedMsg != $row['id_msg_updated']) |
|
| 1283 | - $smcFunc['db_query']('', ' |
|
| 1334 | + if ($row['local_last_msg'] != $row['id_last_msg'] || $curLastModifiedMsg != $row['id_msg_updated']) { |
|
| 1335 | + $smcFunc['db_query']('', ' |
|
| 1284 | 1336 | UPDATE {db_prefix}boards |
| 1285 | 1337 | SET id_last_msg = {int:id_last_msg}, id_msg_updated = {int:id_msg_updated} |
| 1286 | 1338 | WHERE id_board = {int:id_board}', |
@@ -1290,12 +1342,14 @@ discard block |
||
| 1290 | 1342 | 'id_board' => $row['id_board'], |
| 1291 | 1343 | ) |
| 1292 | 1344 | ); |
| 1345 | + } |
|
| 1293 | 1346 | |
| 1294 | 1347 | // Parent boards inherit the latest modified message of their children. |
| 1295 | - if (isset($lastModifiedMsg[$row['id_parent']])) |
|
| 1296 | - $lastModifiedMsg[$row['id_parent']] = max($row['local_last_msg'], $lastModifiedMsg[$row['id_parent']]); |
|
| 1297 | - else |
|
| 1298 | - $lastModifiedMsg[$row['id_parent']] = $row['local_last_msg']; |
|
| 1348 | + if (isset($lastModifiedMsg[$row['id_parent']])) { |
|
| 1349 | + $lastModifiedMsg[$row['id_parent']] = max($row['local_last_msg'], $lastModifiedMsg[$row['id_parent']]); |
|
| 1350 | + } else { |
|
| 1351 | + $lastModifiedMsg[$row['id_parent']] = $row['local_last_msg']; |
|
| 1352 | + } |
|
| 1299 | 1353 | } |
| 1300 | 1354 | |
| 1301 | 1355 | // Update all the basic statistics. |
@@ -1367,8 +1421,9 @@ discard block |
||
| 1367 | 1421 | require_once($sourcedir . '/Subs-Auth.php'); |
| 1368 | 1422 | $members = findMembers($_POST['to']); |
| 1369 | 1423 | |
| 1370 | - if (empty($members)) |
|
| 1371 | - fatal_lang_error('reattribute_cannot_find_member'); |
|
| 1424 | + if (empty($members)) { |
|
| 1425 | + fatal_lang_error('reattribute_cannot_find_member'); |
|
| 1426 | + } |
|
| 1372 | 1427 | |
| 1373 | 1428 | $memID = array_shift($members); |
| 1374 | 1429 | $memID = $memID['id']; |
@@ -1398,8 +1453,9 @@ discard block |
||
| 1398 | 1453 | validateToken('admin-maint'); |
| 1399 | 1454 | |
| 1400 | 1455 | $groups = array(); |
| 1401 | - foreach ($_POST['groups'] as $id => $dummy) |
|
| 1402 | - $groups[] = (int) $id; |
|
| 1456 | + foreach ($_POST['groups'] as $id => $dummy) { |
|
| 1457 | + $groups[] = (int) $id; |
|
| 1458 | + } |
|
| 1403 | 1459 | $time_limit = (time() - ($_POST['maxdays'] * 24 * 3600)); |
| 1404 | 1460 | $where_vars = array( |
| 1405 | 1461 | 'time_limit' => $time_limit, |
@@ -1408,9 +1464,9 @@ discard block |
||
| 1408 | 1464 | { |
| 1409 | 1465 | $where = 'mem.date_registered < {int:time_limit} AND mem.is_activated = {int:is_activated}'; |
| 1410 | 1466 | $where_vars['is_activated'] = 0; |
| 1467 | + } else { |
|
| 1468 | + $where = 'mem.last_login < {int:time_limit} AND (mem.last_login != 0 OR mem.date_registered < {int:time_limit})'; |
|
| 1411 | 1469 | } |
| 1412 | - else |
|
| 1413 | - $where = 'mem.last_login < {int:time_limit} AND (mem.last_login != 0 OR mem.date_registered < {int:time_limit})'; |
|
| 1414 | 1470 | |
| 1415 | 1471 | // Need to get *all* groups then work out which (if any) we avoid. |
| 1416 | 1472 | $request = $smcFunc['db_query']('', ' |
@@ -1429,8 +1485,7 @@ discard block |
||
| 1429 | 1485 | { |
| 1430 | 1486 | $where .= ' AND mem.id_post_group != {int:id_post_group_' . $row['id_group'] . '}'; |
| 1431 | 1487 | $where_vars['id_post_group_' . $row['id_group']] = $row['id_group']; |
| 1432 | - } |
|
| 1433 | - else |
|
| 1488 | + } else |
|
| 1434 | 1489 | { |
| 1435 | 1490 | $where .= ' AND mem.id_group != {int:id_group_' . $row['id_group'] . '} AND FIND_IN_SET({int:id_group_' . $row['id_group'] . '}, mem.additional_groups) = 0'; |
| 1436 | 1491 | $where_vars['id_group_' . $row['id_group']] = $row['id_group']; |
@@ -1457,8 +1512,9 @@ discard block |
||
| 1457 | 1512 | $members = array(); |
| 1458 | 1513 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1459 | 1514 | { |
| 1460 | - if (!$row['is_mod'] || !in_array(3, $groups)) |
|
| 1461 | - $members[] = $row['id_member']; |
|
| 1515 | + if (!$row['is_mod'] || !in_array(3, $groups)) { |
|
| 1516 | + $members[] = $row['id_member']; |
|
| 1517 | + } |
|
| 1462 | 1518 | } |
| 1463 | 1519 | $smcFunc['db_free_result']($request); |
| 1464 | 1520 | |
@@ -1505,8 +1561,9 @@ discard block |
||
| 1505 | 1561 | ) |
| 1506 | 1562 | ); |
| 1507 | 1563 | |
| 1508 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 1509 | - $drafts[] = (int) $row[0]; |
|
| 1564 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 1565 | + $drafts[] = (int) $row[0]; |
|
| 1566 | + } |
|
| 1510 | 1567 | $smcFunc['db_free_result']($request); |
| 1511 | 1568 | |
| 1512 | 1569 | // If we have old drafts, remove them |
@@ -1549,8 +1606,9 @@ discard block |
||
| 1549 | 1606 | $sticky = isset($_POST['move_type_sticky']) || isset($_GET['sticky']); |
| 1550 | 1607 | |
| 1551 | 1608 | // No boards then this is your stop. |
| 1552 | - if (empty($id_board_from) || empty($id_board_to)) |
|
| 1553 | - return; |
|
| 1609 | + if (empty($id_board_from) || empty($id_board_to)) { |
|
| 1610 | + return; |
|
| 1611 | + } |
|
| 1554 | 1612 | |
| 1555 | 1613 | // The big WHERE clause |
| 1556 | 1614 | $conditions = 'WHERE t.id_board = {int:id_board_from} |
@@ -1598,18 +1656,20 @@ discard block |
||
| 1598 | 1656 | ); |
| 1599 | 1657 | list ($total_topics) = $smcFunc['db_fetch_row']($request); |
| 1600 | 1658 | $smcFunc['db_free_result']($request); |
| 1659 | + } else { |
|
| 1660 | + $total_topics = (int) $_REQUEST['totaltopics']; |
|
| 1601 | 1661 | } |
| 1602 | - else |
|
| 1603 | - $total_topics = (int) $_REQUEST['totaltopics']; |
|
| 1604 | 1662 | |
| 1605 | 1663 | // Seems like we need this here. |
| 1606 | 1664 | $context['continue_get_data'] = '?action=admin;area=maintain;sa=topics;activity=massmove;id_board_from=' . $id_board_from . ';id_board_to=' . $id_board_to . ';totaltopics=' . $total_topics . ';max_days=' . $max_days; |
| 1607 | 1665 | |
| 1608 | - if ($locked) |
|
| 1609 | - $context['continue_get_data'] .= ';locked'; |
|
| 1666 | + if ($locked) { |
|
| 1667 | + $context['continue_get_data'] .= ';locked'; |
|
| 1668 | + } |
|
| 1610 | 1669 | |
| 1611 | - if ($sticky) |
|
| 1612 | - $context['continue_get_data'] .= ';sticky'; |
|
| 1670 | + if ($sticky) { |
|
| 1671 | + $context['continue_get_data'] .= ';sticky'; |
|
| 1672 | + } |
|
| 1613 | 1673 | |
| 1614 | 1674 | $context['continue_get_data'] .= ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
| 1615 | 1675 | |
@@ -1630,8 +1690,9 @@ discard block |
||
| 1630 | 1690 | |
| 1631 | 1691 | // Get the ids. |
| 1632 | 1692 | $topics = array(); |
| 1633 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1634 | - $topics[] = $row['id_topic']; |
|
| 1693 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1694 | + $topics[] = $row['id_topic']; |
|
| 1695 | + } |
|
| 1635 | 1696 | |
| 1636 | 1697 | // Just return if we don't have any topics left to move. |
| 1637 | 1698 | if (empty($topics)) |
@@ -1722,9 +1783,9 @@ discard block |
||
| 1722 | 1783 | // save it so we don't do this again for this task |
| 1723 | 1784 | list ($_SESSION['total_members']) = $smcFunc['db_fetch_row']($request); |
| 1724 | 1785 | $smcFunc['db_free_result']($request); |
| 1786 | + } else { |
|
| 1787 | + validateToken('admin-recountposts'); |
|
| 1725 | 1788 | } |
| 1726 | - else |
|
| 1727 | - validateToken('admin-recountposts'); |
|
| 1728 | 1789 | |
| 1729 | 1790 | // Lets get a group of members and determine their post count (from the boards that have post count enabled of course). |
| 1730 | 1791 | $request = $smcFunc['db_query']('', ' |
@@ -1770,8 +1831,9 @@ discard block |
||
| 1770 | 1831 | createToken('admin-recountposts'); |
| 1771 | 1832 | $context['continue_post_data'] = '<input type="hidden" name="' . $context['admin-recountposts_token_var'] . '" value="' . $context['admin-recountposts_token'] . '">'; |
| 1772 | 1833 | |
| 1773 | - if (function_exists('apache_reset_timeout')) |
|
| 1774 | - apache_reset_timeout(); |
|
| 1834 | + if (function_exists('apache_reset_timeout')) { |
|
| 1835 | + apache_reset_timeout(); |
|
| 1836 | + } |
|
| 1775 | 1837 | return; |
| 1776 | 1838 | } |
| 1777 | 1839 | |
@@ -1857,10 +1919,9 @@ discard block |
||
| 1857 | 1919 | checkSession('request'); |
| 1858 | 1920 | validateToken('admin-hook', 'request'); |
| 1859 | 1921 | |
| 1860 | - if ($_REQUEST['do'] == 'remove') |
|
| 1861 | - remove_integration_function($_REQUEST['hook'], urldecode($_REQUEST['function'])); |
|
| 1862 | - |
|
| 1863 | - else |
|
| 1922 | + if ($_REQUEST['do'] == 'remove') { |
|
| 1923 | + remove_integration_function($_REQUEST['hook'], urldecode($_REQUEST['function'])); |
|
| 1924 | + } else |
|
| 1864 | 1925 | { |
| 1865 | 1926 | $function_remove = urldecode($_REQUEST['function']) . (($_REQUEST['do'] == 'disable') ? '' : '!'); |
| 1866 | 1927 | $function_add = urldecode($_REQUEST['function']) . (($_REQUEST['do'] == 'disable') ? '!' : ''); |
@@ -1910,11 +1971,11 @@ discard block |
||
| 1910 | 1971 | // Show a nice icon to indicate this is an instance. |
| 1911 | 1972 | $instance = (!empty($data['instance']) ? '<span class="generic_icons news" title="'. $txt['hooks_field_function_method'] .'"></span> ' : ''); |
| 1912 | 1973 | |
| 1913 | - if (!empty($data['included_file'])) |
|
| 1914 | - return $instance . $txt['hooks_field_function'] . ': ' . $data['real_function'] . '<br>' . $txt['hooks_field_included_file'] . ': ' . $data['included_file']; |
|
| 1915 | - |
|
| 1916 | - else |
|
| 1917 | - return $instance . $data['real_function']; |
|
| 1974 | + if (!empty($data['included_file'])) { |
|
| 1975 | + return $instance . $txt['hooks_field_function'] . ': ' . $data['real_function'] . '<br>' . $txt['hooks_field_included_file'] . ': ' . $data['included_file']; |
|
| 1976 | + } else { |
|
| 1977 | + return $instance . $data['real_function']; |
|
| 1978 | + } |
|
| 1918 | 1979 | }, |
| 1919 | 1980 | ), |
| 1920 | 1981 | 'sort' => array( |
@@ -1979,11 +2040,12 @@ discard block |
||
| 1979 | 2040 | 'data' => array( |
| 1980 | 2041 | 'function' => function ($data) use ($txt, $scripturl, $context) |
| 1981 | 2042 | { |
| 1982 | - if (!$data['hook_exists']) |
|
| 1983 | - return ' |
|
| 2043 | + if (!$data['hook_exists']) { |
|
| 2044 | + return ' |
|
| 1984 | 2045 | <a href="' . $scripturl . '?action=admin;area=maintain;sa=hooks;do=remove;hook=' . $data['hook_name'] . ';function=' . urlencode($data['function_name']) . $context['filter_url'] . ';' . $context['admin-hook_token_var'] . '=' . $context['admin-hook_token'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" data-confirm="' . $txt['quickmod_confirm'] . '" class="you_sure"> |
| 1985 | 2046 | <span class="generic_icons delete" title="' . $txt['hooks_button_remove'] . '"></span> |
| 1986 | 2047 | </a>'; |
| 2048 | + } |
|
| 1987 | 2049 | }, |
| 1988 | 2050 | 'class' => 'centertext', |
| 1989 | 2051 | ), |
@@ -2018,10 +2080,11 @@ discard block |
||
| 2018 | 2080 | { |
| 2019 | 2081 | if ($file != '.' && $file != '..') |
| 2020 | 2082 | { |
| 2021 | - if (is_dir($dir_path . '/' . $file)) |
|
| 2022 | - $files = array_merge($files, get_files_recursive($dir_path . '/' . $file)); |
|
| 2023 | - else |
|
| 2024 | - $files[] = array('dir' => $dir_path, 'name' => $file); |
|
| 2083 | + if (is_dir($dir_path . '/' . $file)) { |
|
| 2084 | + $files = array_merge($files, get_files_recursive($dir_path . '/' . $file)); |
|
| 2085 | + } else { |
|
| 2086 | + $files[] = array('dir' => $dir_path, 'name' => $file); |
|
| 2087 | + } |
|
| 2025 | 2088 | } |
| 2026 | 2089 | } |
| 2027 | 2090 | } |
@@ -2070,16 +2133,16 @@ discard block |
||
| 2070 | 2133 | // I need to know if there is at least one function called in this file. |
| 2071 | 2134 | $temp_data['include'][$hookParsedData['pureFunc']] = array('hook' => $hook, 'function' => $hookParsedData['pureFunc']); |
| 2072 | 2135 | unset($temp_hooks[$hook][$rawFunc]); |
| 2073 | - } |
|
| 2074 | - elseif (strpos(str_replace(' (', '(', $fc), 'function ' . trim($hookParsedData['pureFunc']) . '(') !== false) |
|
| 2136 | + } elseif (strpos(str_replace(' (', '(', $fc), 'function ' . trim($hookParsedData['pureFunc']) . '(') !== false) |
|
| 2075 | 2137 | { |
| 2076 | 2138 | $hook_status[$hook][$hookParsedData['pureFunc']] = $hookParsedData; |
| 2077 | 2139 | $hook_status[$hook][$hookParsedData['pureFunc']]['exists'] = true; |
| 2078 | 2140 | $hook_status[$hook][$hookParsedData['pureFunc']]['in_file'] = (!empty($file['name']) ? $file['name'] : (!empty($hookParsedData['hookFile']) ? $hookParsedData['hookFile'] : '')); |
| 2079 | 2141 | |
| 2080 | 2142 | // Does the hook has its own file? |
| 2081 | - if (!empty($hookParsedData['hookFile'])) |
|
| 2082 | - $temp_data['include'][$hookParsedData['pureFunc']] = array('hook' => $hook, 'function' => $hookParsedData['pureFunc']); |
|
| 2143 | + if (!empty($hookParsedData['hookFile'])) { |
|
| 2144 | + $temp_data['include'][$hookParsedData['pureFunc']] = array('hook' => $hook, 'function' => $hookParsedData['pureFunc']); |
|
| 2145 | + } |
|
| 2083 | 2146 | |
| 2084 | 2147 | // I want to remember all the functions called within this file (to check later if they are enabled or disabled and decide if the integrare_*_include of that file can be disabled too) |
| 2085 | 2148 | $temp_data['function'][$file['name']][$hookParsedData['pureFunc']] = $hookParsedData['enabled']; |
@@ -2106,15 +2169,17 @@ discard block |
||
| 2106 | 2169 | $sort = array(); |
| 2107 | 2170 | $hooks_filters = array(); |
| 2108 | 2171 | |
| 2109 | - foreach ($hooks as $hook => $functions) |
|
| 2110 | - $hooks_filters[] = '<option' . ($context['current_filter'] == $hook ? ' selected ' : '') . ' value="' . $hook . '">' . $hook . '</option>'; |
|
| 2172 | + foreach ($hooks as $hook => $functions) { |
|
| 2173 | + $hooks_filters[] = '<option' . ($context['current_filter'] == $hook ? ' selected ' : '') . ' value="' . $hook . '">' . $hook . '</option>'; |
|
| 2174 | + } |
|
| 2111 | 2175 | |
| 2112 | - if (!empty($hooks_filters)) |
|
| 2113 | - $context['insert_after_template'] .= ' |
|
| 2176 | + if (!empty($hooks_filters)) { |
|
| 2177 | + $context['insert_after_template'] .= ' |
|
| 2114 | 2178 | <script> |
| 2115 | 2179 | var hook_name_header = document.getElementById(\'header_list_integration_hooks_hook_name\'); |
| 2116 | 2180 | hook_name_header.innerHTML += ' . JavaScriptEscape('<select style="margin-left:15px;" onchange="window.location=(\'' . $scripturl . '?action=admin;area=maintain;sa=hooks\' + (this.value ? \';filter=\' + this.value : \'\'));"><option value="">' . $txt['hooks_reset_filter'] . '</option>' . implode('', $hooks_filters) . '</select>'). '; |
| 2117 | 2181 | </script>'; |
| 2182 | + } |
|
| 2118 | 2183 | |
| 2119 | 2184 | $temp_data = array(); |
| 2120 | 2185 | $id = 0; |
@@ -2157,10 +2222,11 @@ discard block |
||
| 2157 | 2222 | |
| 2158 | 2223 | foreach ($temp_data as $data) |
| 2159 | 2224 | { |
| 2160 | - if (++$counter < $start) |
|
| 2161 | - continue; |
|
| 2162 | - elseif ($counter == $start + $per_page) |
|
| 2163 | - break; |
|
| 2225 | + if (++$counter < $start) { |
|
| 2226 | + continue; |
|
| 2227 | + } elseif ($counter == $start + $per_page) { |
|
| 2228 | + break; |
|
| 2229 | + } |
|
| 2164 | 2230 | |
| 2165 | 2231 | $hooks_data[] = $data; |
| 2166 | 2232 | } |
@@ -2182,13 +2248,15 @@ discard block |
||
| 2182 | 2248 | $hooks_count = 0; |
| 2183 | 2249 | |
| 2184 | 2250 | $context['filter'] = false; |
| 2185 | - if (isset($_GET['filter'])) |
|
| 2186 | - $context['filter'] = $_GET['filter']; |
|
| 2251 | + if (isset($_GET['filter'])) { |
|
| 2252 | + $context['filter'] = $_GET['filter']; |
|
| 2253 | + } |
|
| 2187 | 2254 | |
| 2188 | 2255 | foreach ($hooks as $hook => $functions) |
| 2189 | 2256 | { |
| 2190 | - if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook)) |
|
| 2191 | - $hooks_count += count($functions); |
|
| 2257 | + if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook)) { |
|
| 2258 | + $hooks_count += count($functions); |
|
| 2259 | + } |
|
| 2192 | 2260 | } |
| 2193 | 2261 | |
| 2194 | 2262 | return $hooks_count; |
@@ -2209,8 +2277,9 @@ discard block |
||
| 2209 | 2277 | $integration_hooks = array(); |
| 2210 | 2278 | foreach ($modSettings as $key => $value) |
| 2211 | 2279 | { |
| 2212 | - if (!empty($value) && substr($key, 0, 10) === 'integrate_') |
|
| 2213 | - $integration_hooks[$key] = explode(',', $value); |
|
| 2280 | + if (!empty($value) && substr($key, 0, 10) === 'integrate_') { |
|
| 2281 | + $integration_hooks[$key] = explode(',', $value); |
|
| 2282 | + } |
|
| 2214 | 2283 | } |
| 2215 | 2284 | } |
| 2216 | 2285 | |
@@ -2241,8 +2310,9 @@ discard block |
||
| 2241 | 2310 | ); |
| 2242 | 2311 | |
| 2243 | 2312 | // Meh... |
| 2244 | - if (empty($rawData)) |
|
| 2245 | - return $hookData; |
|
| 2313 | + if (empty($rawData)) { |
|
| 2314 | + return $hookData; |
|
| 2315 | + } |
|
| 2246 | 2316 | |
| 2247 | 2317 | // For convenience purposes only! |
| 2248 | 2318 | $modFunc = $rawData; |
@@ -2253,11 +2323,11 @@ discard block |
||
| 2253 | 2323 | list ($hookData['hookFile'], $modFunc) = explode('|', $modFunc); |
| 2254 | 2324 | |
| 2255 | 2325 | // Does the file exists? who knows! |
| 2256 | - if (empty($settings['theme_dir'])) |
|
| 2257 | - $hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
| 2258 | - |
|
| 2259 | - else |
|
| 2260 | - $hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
| 2326 | + if (empty($settings['theme_dir'])) { |
|
| 2327 | + $hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
| 2328 | + } else { |
|
| 2329 | + $hookData['absPath'] = strtr(trim($hookData['hookFile']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
| 2330 | + } |
|
| 2261 | 2331 | |
| 2262 | 2332 | $hookData['fileExists'] = file_exists($hookData['absPath']); |
| 2263 | 2333 | $hookData['hookFile'] = basename($hookData['hookFile']); |
@@ -2282,11 +2352,10 @@ discard block |
||
| 2282 | 2352 | { |
| 2283 | 2353 | list ($hookData['class'], $hookData['method']) = explode('::', $modFunc); |
| 2284 | 2354 | $hookData['pureFunc'] = $hookData['method']; |
| 2355 | + } else { |
|
| 2356 | + $hookData['pureFunc'] = $modFunc; |
|
| 2285 | 2357 | } |
| 2286 | 2358 | |
| 2287 | - else |
|
| 2288 | - $hookData['pureFunc'] = $modFunc; |
|
| 2289 | - |
|
| 2290 | 2359 | return $hookData; |
| 2291 | 2360 | } |
| 2292 | 2361 | |
@@ -2439,7 +2439,6 @@ |
||
| 2439 | 2439 | |
| 2440 | 2440 | /** |
| 2441 | 2441 | * Add a Javascript file for output later |
| 2442 | - |
|
| 2443 | 2442 | * @param string $filename The name of the file to load |
| 2444 | 2443 | * @param array $params An array of parameter info |
| 2445 | 2444 | * Keys are the following: |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 3 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Turn off/on notification for a particular board. |
@@ -34,8 +35,9 @@ discard block |
||
| 34 | 35 | is_not_guest(); |
| 35 | 36 | |
| 36 | 37 | // You have to specify a board to turn notifications on! |
| 37 | - if (empty($board)) |
|
| 38 | - fatal_lang_error('no_board', false); |
|
| 38 | + if (empty($board)) { |
|
| 39 | + fatal_lang_error('no_board', false); |
|
| 40 | + } |
|
| 39 | 41 | |
| 40 | 42 | // No subaction: find out what to do. |
| 41 | 43 | if (isset($_GET['mode'])) |
@@ -48,16 +50,16 @@ discard block |
||
| 48 | 50 | require_once($sourcedir . '/Subs-Notify.php'); |
| 49 | 51 | setNotifyPrefs($user_info['id'], array('board_notify_' . $board => $alertPref)); |
| 50 | 52 | |
| 51 | - if ($mode > 1) |
|
| 52 | - // Turn notification on. (note this just blows smoke if it's already on.) |
|
| 53 | + if ($mode > 1) { |
|
| 54 | + // Turn notification on. (note this just blows smoke if it's already on.) |
|
| 53 | 55 | $smcFunc['db_insert']('ignore', |
| 54 | 56 | '{db_prefix}log_notify', |
| 55 | 57 | array('id_member' => 'int', 'id_board' => 'int'), |
| 56 | 58 | array($user_info['id'], $board), |
| 57 | 59 | array('id_member', 'id_board') |
| 58 | 60 | ); |
| 59 | - else |
|
| 60 | - $smcFunc['db_query']('', ' |
|
| 61 | + } else { |
|
| 62 | + $smcFunc['db_query']('', ' |
|
| 61 | 63 | DELETE FROM {db_prefix}log_notify |
| 62 | 64 | WHERE id_member = {int:current_member} |
| 63 | 65 | AND id_board = {int:current_board}', |
@@ -66,6 +68,7 @@ discard block |
||
| 66 | 68 | 'current_member' => $user_info['id'], |
| 67 | 69 | ) |
| 68 | 70 | ); |
| 71 | + } |
|
| 69 | 72 | |
| 70 | 73 | } |
| 71 | 74 | |
@@ -81,10 +84,10 @@ discard block |
||
| 81 | 84 | ), |
| 82 | 85 | ); |
| 83 | 86 | $context['sub_template'] = 'generic_xml'; |
| 87 | + } else { |
|
| 88 | + redirectexit('board=' . $board . '.' . $_REQUEST['start']); |
|
| 89 | + } |
|
| 84 | 90 | } |
| 85 | - else |
|
| 86 | - redirectexit('board=' . $board . '.' . $_REQUEST['start']); |
|
| 87 | -} |
|
| 88 | 91 | |
| 89 | 92 | /** |
| 90 | 93 | * Turn off/on unread replies subscription for a topic as well as sets individual topic's alert preferences |
@@ -108,8 +111,9 @@ discard block |
||
| 108 | 111 | $mode = (int) $_GET['mode']; |
| 109 | 112 | $alertPref = $mode <= 1 ? 0 : ($mode == 2 ? 1 : 3); |
| 110 | 113 | |
| 111 | - if (empty($mode)) |
|
| 112 | - $mode = 1; |
|
| 114 | + if (empty($mode)) { |
|
| 115 | + $mode = 1; |
|
| 116 | + } |
|
| 113 | 117 | |
| 114 | 118 | $request = $smcFunc['db_query']('', ' |
| 115 | 119 | SELECT id_member, id_topic, id_msg, unwatched |
@@ -132,8 +136,7 @@ discard block |
||
| 132 | 136 | 'id_msg' => 0, |
| 133 | 137 | 'unwatched' => empty($mode) ? 1 : 0, |
| 134 | 138 | ); |
| 135 | - } |
|
| 136 | - else |
|
| 139 | + } else |
|
| 137 | 140 | { |
| 138 | 141 | $insert = false; |
| 139 | 142 | $log['unwatched'] = empty($mode) ? 1 : 0; |
@@ -160,9 +163,8 @@ discard block |
||
| 160 | 163 | array($user_info['id'], $log['id_topic']), |
| 161 | 164 | array('id_member', 'id_board') |
| 162 | 165 | ); |
| 163 | - } |
|
| 164 | - else |
|
| 165 | - $smcFunc['db_query']('', ' |
|
| 166 | + } else { |
|
| 167 | + $smcFunc['db_query']('', ' |
|
| 166 | 168 | DELETE FROM {db_prefix}log_notify |
| 167 | 169 | WHERE id_topic = {int:topic} |
| 168 | 170 | AND id_member = {int:member}', |
@@ -170,6 +172,7 @@ discard block |
||
| 170 | 172 | 'topic' => $log['id_topic'], |
| 171 | 173 | 'member' => $user_info['id'], |
| 172 | 174 | )); |
| 175 | + } |
|
| 173 | 176 | |
| 174 | 177 | } |
| 175 | 178 | } |
@@ -186,9 +189,9 @@ discard block |
||
| 186 | 189 | ), |
| 187 | 190 | ); |
| 188 | 191 | $context['sub_template'] = 'generic_xml'; |
| 192 | + } else { |
|
| 193 | + redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
| 194 | + } |
|
| 189 | 195 | } |
| 190 | - else |
|
| 191 | - redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
| 192 | -} |
|
| 193 | 196 | |
| 194 | 197 | ?> |
| 195 | 198 | \ No newline at end of file |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | LEFT JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic) |
| 233 | 233 | WHERE t.id_topic IS NULL |
| 234 | 234 | GROUP BY m.id_topic, m.id_board', |
| 235 | - 'fix_processing' => function ($row) use ($smcFunc) |
|
| 235 | + 'fix_processing' => function($row) use ($smcFunc) |
|
| 236 | 236 | { |
| 237 | 237 | global $salvageBoardID; |
| 238 | 238 | |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | // Remove all topics that have zero messages in the messages table. |
| 320 | 320 | 'fix_collect' => array( |
| 321 | 321 | 'index' => 'id_topic', |
| 322 | - 'process' => function ($topics) use ($smcFunc) |
|
| 322 | + 'process' => function($topics) use ($smcFunc) |
|
| 323 | 323 | { |
| 324 | 324 | $smcFunc['db_query']('', ' |
| 325 | 325 | DELETE FROM {db_prefix}topics |
@@ -357,21 +357,21 @@ discard block |
||
| 357 | 357 | AND p.id_poll IS NULL |
| 358 | 358 | GROUP BY o.id_poll |
| 359 | 359 | ', |
| 360 | - 'fix_processing' => function ($row) use ($smcFunc, $txt) |
|
| 360 | + 'fix_processing' => function($row) use ($smcFunc, $txt) |
|
| 361 | 361 | { |
| 362 | 362 | global $salvageBoardID; |
| 363 | 363 | |
| 364 | 364 | $row['poster_name'] = !empty($row['poster_name']) ? $row['poster_name'] : $txt['guest']; |
| 365 | 365 | $row['id_poster'] = !empty($row['id_poster']) ? $row['id_poster'] : 0; |
| 366 | 366 | |
| 367 | - if(empty($row['id_board'])) |
|
| 367 | + if (empty($row['id_board'])) |
|
| 368 | 368 | { |
| 369 | 369 | // Only if we don't have a reasonable idea of where to put it. |
| 370 | 370 | createSalvageArea(); |
| 371 | - $row['id_board'] = (int)$salvageBoardID; |
|
| 371 | + $row['id_board'] = (int) $salvageBoardID; |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - if(empty($row['id_topic'])) { |
|
| 374 | + if (empty($row['id_topic'])) { |
|
| 375 | 375 | $smcFunc['db_insert']('', |
| 376 | 376 | '{db_prefix}messages', |
| 377 | 377 | array( |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | LEFT JOIN {db_prefix}topics AS t ON (t.id_poll = p.id_poll) |
| 496 | 496 | WHERE p.id_poll BETWEEN {STEP_LOW} AND {STEP_HIGH} |
| 497 | 497 | AND t.id_poll IS NULL', |
| 498 | - 'fix_processing' => function ($row) use ($smcFunc, $txt) |
|
| 498 | + 'fix_processing' => function($row) use ($smcFunc, $txt) |
|
| 499 | 499 | { |
| 500 | 500 | global $salvageBoardID; |
| 501 | 501 | |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | WHERE t.id_topic BETWEEN {STEP_LOW} AND {STEP_HIGH} |
| 611 | 611 | GROUP BY t.id_topic, t.id_first_msg, t.id_last_msg, t.approved, mf.approved |
| 612 | 612 | ORDER BY t.id_topic', |
| 613 | - 'fix_processing' => function ($row) use ($smcFunc) |
|
| 613 | + 'fix_processing' => function($row) use ($smcFunc) |
|
| 614 | 614 | { |
| 615 | 615 | $row['firstmsg_approved'] = (int) $row['firstmsg_approved']; |
| 616 | 616 | $row['myid_first_msg'] = (int) $row['myid_first_msg']; |
@@ -639,7 +639,7 @@ discard block |
||
| 639 | 639 | ) |
| 640 | 640 | ); |
| 641 | 641 | }, |
| 642 | - 'message_function' => function ($row) use ($txt, &$context) |
|
| 642 | + 'message_function' => function($row) use ($txt, &$context) |
|
| 643 | 643 | { |
| 644 | 644 | // A pretend error? |
| 645 | 645 | if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved']) |
@@ -673,7 +673,7 @@ discard block |
||
| 673 | 673 | WHERE t.id_topic BETWEEN {STEP_LOW} AND {STEP_HIGH} |
| 674 | 674 | GROUP BY t.id_topic, t.num_replies, mf.approved |
| 675 | 675 | ORDER BY t.id_topic', |
| 676 | - 'fix_processing' => function ($row) |
|
| 676 | + 'fix_processing' => function($row) |
|
| 677 | 677 | { |
| 678 | 678 | |
| 679 | 679 | global $smcFunc; |
@@ -694,7 +694,7 @@ discard block |
||
| 694 | 694 | ); |
| 695 | 695 | |
| 696 | 696 | }, |
| 697 | - 'message_function' => function ($row) |
|
| 697 | + 'message_function' => function($row) |
|
| 698 | 698 | { |
| 699 | 699 | |
| 700 | 700 | global $txt, $context; |
@@ -727,7 +727,7 @@ discard block |
||
| 727 | 727 | GROUP BY t.id_topic, t.unapproved_posts |
| 728 | 728 | HAVING unapproved_posts != COUNT(mu.id_msg) |
| 729 | 729 | ORDER BY t.id_topic', |
| 730 | - 'fix_processing' => function ($row) |
|
| 730 | + 'fix_processing' => function($row) |
|
| 731 | 731 | { |
| 732 | 732 | |
| 733 | 733 | global $smcFunc; |
@@ -769,7 +769,7 @@ discard block |
||
| 769 | 769 | WHERE b.id_board IS NULL |
| 770 | 770 | AND t.id_topic BETWEEN {STEP_LOW} AND {STEP_HIGH} |
| 771 | 771 | GROUP BY t.id_board', |
| 772 | - 'fix_processing' => function ($row) |
|
| 772 | + 'fix_processing' => function($row) |
|
| 773 | 773 | { |
| 774 | 774 | |
| 775 | 775 | global $smcFunc, $salvageCatID, $txt; |
@@ -818,7 +818,7 @@ discard block |
||
| 818 | 818 | ORDER BY b.id_cat, b.id_board', |
| 819 | 819 | 'fix_collect' => array( |
| 820 | 820 | 'index' => 'id_cat', |
| 821 | - 'process' => function ($cats) |
|
| 821 | + 'process' => function($cats) |
|
| 822 | 822 | { |
| 823 | 823 | global $smcFunc, $salvageCatID; |
| 824 | 824 | createSalvageArea(); |
@@ -854,7 +854,7 @@ discard block |
||
| 854 | 854 | // Last step-make sure all non-guest posters still exist. |
| 855 | 855 | 'fix_collect' => array( |
| 856 | 856 | 'index' => 'id_msg', |
| 857 | - 'process' => function ($msgs) |
|
| 857 | + 'process' => function($msgs) |
|
| 858 | 858 | { |
| 859 | 859 | |
| 860 | 860 | global $smcFunc; |
@@ -883,7 +883,7 @@ discard block |
||
| 883 | 883 | ORDER BY b.id_parent, b.id_board', |
| 884 | 884 | 'fix_collect' => array( |
| 885 | 885 | 'index' => 'id_parent', |
| 886 | - 'process' => function ($parents) |
|
| 886 | + 'process' => function($parents) |
|
| 887 | 887 | { |
| 888 | 888 | global $smcFunc, $salvageBoardID, $salvageCatID; |
| 889 | 889 | createSalvageArea(); |
@@ -917,7 +917,7 @@ discard block |
||
| 917 | 917 | AND p.id_poll IS NULL', |
| 918 | 918 | 'fix_collect' => array( |
| 919 | 919 | 'index' => 'id_poll', |
| 920 | - 'process' => function ($polls) |
|
| 920 | + 'process' => function($polls) |
|
| 921 | 921 | { |
| 922 | 922 | |
| 923 | 923 | global $smcFunc; |
@@ -951,7 +951,7 @@ discard block |
||
| 951 | 951 | ORDER BY cal.id_topic', |
| 952 | 952 | 'fix_collect' => array( |
| 953 | 953 | 'index' => 'id_topic', |
| 954 | - 'process' => function ($events) |
|
| 954 | + 'process' => function($events) |
|
| 955 | 955 | { |
| 956 | 956 | |
| 957 | 957 | global $smcFunc; |
@@ -983,7 +983,7 @@ discard block |
||
| 983 | 983 | AND lt.id_member BETWEEN {STEP_LOW} AND {STEP_HIGH}', |
| 984 | 984 | 'fix_collect' => array( |
| 985 | 985 | 'index' => 'id_topic', |
| 986 | - 'process' => function ($topics) |
|
| 986 | + 'process' => function($topics) |
|
| 987 | 987 | { |
| 988 | 988 | |
| 989 | 989 | global $smcFunc; |
@@ -1015,7 +1015,7 @@ discard block |
||
| 1015 | 1015 | GROUP BY lt.id_member', |
| 1016 | 1016 | 'fix_collect' => array( |
| 1017 | 1017 | 'index' => 'id_member', |
| 1018 | - 'process' => function ($members) |
|
| 1018 | + 'process' => function($members) |
|
| 1019 | 1019 | { |
| 1020 | 1020 | |
| 1021 | 1021 | global $smcFunc; |
@@ -1047,7 +1047,7 @@ discard block |
||
| 1047 | 1047 | GROUP BY lb.id_board', |
| 1048 | 1048 | 'fix_collect' => array( |
| 1049 | 1049 | 'index' => 'id_board', |
| 1050 | - 'process' => function ($boards) |
|
| 1050 | + 'process' => function($boards) |
|
| 1051 | 1051 | { |
| 1052 | 1052 | |
| 1053 | 1053 | global $smcFunc; |
@@ -1079,7 +1079,7 @@ discard block |
||
| 1079 | 1079 | GROUP BY lb.id_member', |
| 1080 | 1080 | 'fix_collect' => array( |
| 1081 | 1081 | 'index' => 'id_member', |
| 1082 | - 'process' => function ($members) use ($smcFunc) |
|
| 1082 | + 'process' => function($members) use ($smcFunc) |
|
| 1083 | 1083 | { |
| 1084 | 1084 | $smcFunc['db_query']('', ' |
| 1085 | 1085 | DELETE FROM {db_prefix}log_boards |
@@ -1108,7 +1108,7 @@ discard block |
||
| 1108 | 1108 | GROUP BY lmr.id_board', |
| 1109 | 1109 | 'fix_collect' => array( |
| 1110 | 1110 | 'index' => 'id_board', |
| 1111 | - 'process' => function ($boards) use ($smcFunc) |
|
| 1111 | + 'process' => function($boards) use ($smcFunc) |
|
| 1112 | 1112 | { |
| 1113 | 1113 | $smcFunc['db_query']('', ' |
| 1114 | 1114 | DELETE FROM {db_prefix}log_mark_read |
@@ -1137,7 +1137,7 @@ discard block |
||
| 1137 | 1137 | GROUP BY lmr.id_member', |
| 1138 | 1138 | 'fix_collect' => array( |
| 1139 | 1139 | 'index' => 'id_member', |
| 1140 | - 'process' => function ($members) use ($smcFunc) |
|
| 1140 | + 'process' => function($members) use ($smcFunc) |
|
| 1141 | 1141 | { |
| 1142 | 1142 | $smcFunc['db_query']('', ' |
| 1143 | 1143 | DELETE FROM {db_prefix}log_mark_read |
@@ -1166,7 +1166,7 @@ discard block |
||
| 1166 | 1166 | GROUP BY pmr.id_pm', |
| 1167 | 1167 | 'fix_collect' => array( |
| 1168 | 1168 | 'index' => 'id_pm', |
| 1169 | - 'process' => function ($pms) use ($smcFunc) |
|
| 1169 | + 'process' => function($pms) use ($smcFunc) |
|
| 1170 | 1170 | { |
| 1171 | 1171 | $smcFunc['db_query']('', ' |
| 1172 | 1172 | DELETE FROM {db_prefix}pm_recipients |
@@ -1196,7 +1196,7 @@ discard block |
||
| 1196 | 1196 | GROUP BY pmr.id_member', |
| 1197 | 1197 | 'fix_collect' => array( |
| 1198 | 1198 | 'index' => 'id_member', |
| 1199 | - 'process' => function ($members) |
|
| 1199 | + 'process' => function($members) |
|
| 1200 | 1200 | { |
| 1201 | 1201 | |
| 1202 | 1202 | global $smcFunc; |
@@ -1228,7 +1228,7 @@ discard block |
||
| 1228 | 1228 | AND mem.id_member IS NULL', |
| 1229 | 1229 | 'fix_collect' => array( |
| 1230 | 1230 | 'index' => 'id_pm', |
| 1231 | - 'process' => function ($guestMessages) |
|
| 1231 | + 'process' => function($guestMessages) |
|
| 1232 | 1232 | { |
| 1233 | 1233 | |
| 1234 | 1234 | global $smcFunc; |
@@ -1260,7 +1260,7 @@ discard block |
||
| 1260 | 1260 | GROUP BY ln.id_member', |
| 1261 | 1261 | 'fix_collect' => array( |
| 1262 | 1262 | 'index' => 'id_member', |
| 1263 | - 'process' => function ($members) use ($smcFunc) |
|
| 1263 | + 'process' => function($members) use ($smcFunc) |
|
| 1264 | 1264 | { |
| 1265 | 1265 | $smcFunc['db_query']('', ' |
| 1266 | 1266 | DELETE FROM {db_prefix}log_notify |
@@ -1287,7 +1287,7 @@ discard block |
||
| 1287 | 1287 | LEFT JOIN {db_prefix}log_search_subjects AS lss ON (lss.id_topic = t.id_topic) |
| 1288 | 1288 | WHERE t.id_topic BETWEEN {STEP_LOW} AND {STEP_HIGH} |
| 1289 | 1289 | AND lss.id_topic IS NULL', |
| 1290 | - 'fix_full_processing' => function ($result) |
|
| 1290 | + 'fix_full_processing' => function($result) |
|
| 1291 | 1291 | { |
| 1292 | 1292 | |
| 1293 | 1293 | global $smcFunc; |
@@ -1319,7 +1319,7 @@ discard block |
||
| 1319 | 1319 | ); |
| 1320 | 1320 | |
| 1321 | 1321 | }, |
| 1322 | - 'message_function' => function ($row) |
|
| 1322 | + 'message_function' => function($row) |
|
| 1323 | 1323 | { |
| 1324 | 1324 | |
| 1325 | 1325 | global $txt, $context; |
@@ -1349,7 +1349,7 @@ discard block |
||
| 1349 | 1349 | AND t.id_topic IS NULL', |
| 1350 | 1350 | 'fix_collect' => array( |
| 1351 | 1351 | 'index' => 'id_topic', |
| 1352 | - 'process' => function ($deleteTopics) |
|
| 1352 | + 'process' => function($deleteTopics) |
|
| 1353 | 1353 | { |
| 1354 | 1354 | |
| 1355 | 1355 | global $smcFunc; |
@@ -1381,7 +1381,7 @@ discard block |
||
| 1381 | 1381 | AND mem.id_member IS NULL', |
| 1382 | 1382 | 'fix_collect' => array( |
| 1383 | 1383 | 'index' => 'id_member', |
| 1384 | - 'process' => function ($members) |
|
| 1384 | + 'process' => function($members) |
|
| 1385 | 1385 | { |
| 1386 | 1386 | |
| 1387 | 1387 | global $smcFunc; |
@@ -1412,7 +1412,7 @@ discard block |
||
| 1412 | 1412 | AND p.id_poll IS NULL', |
| 1413 | 1413 | 'fix_collect' => array( |
| 1414 | 1414 | 'index' => 'id_poll', |
| 1415 | - 'process' => function ($polls) |
|
| 1415 | + 'process' => function($polls) |
|
| 1416 | 1416 | { |
| 1417 | 1417 | |
| 1418 | 1418 | global $smcFunc; |
@@ -1443,7 +1443,7 @@ discard block |
||
| 1443 | 1443 | AND lrc.id_report IS NULL', |
| 1444 | 1444 | 'fix_collect' => array( |
| 1445 | 1445 | 'index' => 'id_report', |
| 1446 | - 'process' => function ($reports) |
|
| 1446 | + 'process' => function($reports) |
|
| 1447 | 1447 | { |
| 1448 | 1448 | |
| 1449 | 1449 | global $smcFunc; |
@@ -1474,7 +1474,7 @@ discard block |
||
| 1474 | 1474 | AND lr.id_report IS NULL', |
| 1475 | 1475 | 'fix_collect' => array( |
| 1476 | 1476 | 'index' => 'id_report', |
| 1477 | - 'process' => function ($reports) |
|
| 1477 | + 'process' => function($reports) |
|
| 1478 | 1478 | { |
| 1479 | 1479 | global $smcFunc; |
| 1480 | 1480 | $smcFunc['db_query']('', ' |
@@ -1504,7 +1504,7 @@ discard block |
||
| 1504 | 1504 | GROUP BY lgr.id_member', |
| 1505 | 1505 | 'fix_collect' => array( |
| 1506 | 1506 | 'index' => 'id_member', |
| 1507 | - 'process' => function ($members) |
|
| 1507 | + 'process' => function($members) |
|
| 1508 | 1508 | { |
| 1509 | 1509 | global $smcFunc; |
| 1510 | 1510 | $smcFunc['db_query']('', ' |
@@ -1534,7 +1534,7 @@ discard block |
||
| 1534 | 1534 | GROUP BY lgr.id_group', |
| 1535 | 1535 | 'fix_collect' => array( |
| 1536 | 1536 | 'index' => 'id_group', |
| 1537 | - 'process' => function ($groups) |
|
| 1537 | + 'process' => function($groups) |
|
| 1538 | 1538 | { |
| 1539 | 1539 | global $smcFunc; |
| 1540 | 1540 | $smcFunc['db_query']('', ' |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Finds or repairs errors in the database to fix possible problems. |
@@ -50,8 +51,9 @@ discard block |
||
| 50 | 51 | ); |
| 51 | 52 | |
| 52 | 53 | // Start displaying errors without fixing them. |
| 53 | - if (isset($_GET['fixErrors'])) |
|
| 54 | - checkSession('get'); |
|
| 54 | + if (isset($_GET['fixErrors'])) { |
|
| 55 | + checkSession('get'); |
|
| 56 | + } |
|
| 55 | 57 | |
| 56 | 58 | // Will want this. |
| 57 | 59 | loadForumTests(); |
@@ -69,11 +71,11 @@ discard block |
||
| 69 | 71 | $_SESSION['repairboards_to_fix'] = $context['to_fix']; |
| 70 | 72 | $_SESSION['repairboards_to_fix2'] = null; |
| 71 | 73 | |
| 72 | - if (empty($context['repair_errors'])) |
|
| 73 | - $context['repair_errors'][] = '???'; |
|
| 74 | + if (empty($context['repair_errors'])) { |
|
| 75 | + $context['repair_errors'][] = '???'; |
|
| 76 | + } |
|
| 74 | 77 | } |
| 75 | - } |
|
| 76 | - else |
|
| 78 | + } else |
|
| 77 | 79 | { |
| 78 | 80 | $context['error_search'] = false; |
| 79 | 81 | $context['to_fix'] = isset($_SESSION['repairboards_to_fix']) ? $_SESSION['repairboards_to_fix'] : array(); |
@@ -120,16 +122,19 @@ discard block |
||
| 120 | 122 | |
| 121 | 123 | // More time, I need more time! |
| 122 | 124 | @set_time_limit(600); |
| 123 | - if (function_exists('apache_reset_timeout')) |
|
| 124 | - @apache_reset_timeout(); |
|
| 125 | + if (function_exists('apache_reset_timeout')) { |
|
| 126 | + @apache_reset_timeout(); |
|
| 127 | + } |
|
| 125 | 128 | |
| 126 | 129 | // Errr, wait. How much time has this taken already? |
| 127 | - if (!$force && time() - array_sum(explode(' ', $time_start)) < 3) |
|
| 128 | - return; |
|
| 130 | + if (!$force && time() - array_sum(explode(' ', $time_start)) < 3) { |
|
| 131 | + return; |
|
| 132 | + } |
|
| 129 | 133 | |
| 130 | 134 | // Restore the query cache if interested. |
| 131 | - if (!empty($db_temp_cache)) |
|
| 132 | - $db_cache = $db_temp_cache; |
|
| 135 | + if (!empty($db_temp_cache)) { |
|
| 136 | + $db_cache = $db_temp_cache; |
|
| 137 | + } |
|
| 133 | 138 | |
| 134 | 139 | $context['continue_get_data'] = '?action=admin;area=repairboards' . (isset($_GET['fixErrors']) ? ';fixErrors' : '') . ';step=' . $_GET['step'] . ';substep=' . $_GET['substep'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
| 135 | 140 | $context['page_title'] = $txt['not_done_title']; |
@@ -138,10 +143,11 @@ discard block |
||
| 138 | 143 | $context['sub_template'] = 'not_done'; |
| 139 | 144 | |
| 140 | 145 | // Change these two if more steps are added! |
| 141 | - if (empty($max_substep)) |
|
| 142 | - $context['continue_percent'] = round(($_GET['step'] * 100) / $context['total_steps']); |
|
| 143 | - else |
|
| 144 | - $context['continue_percent'] = round((($_GET['step'] + ($_GET['substep'] / $max_substep)) * 100) / $context['total_steps']); |
|
| 146 | + if (empty($max_substep)) { |
|
| 147 | + $context['continue_percent'] = round(($_GET['step'] * 100) / $context['total_steps']); |
|
| 148 | + } else { |
|
| 149 | + $context['continue_percent'] = round((($_GET['step'] + ($_GET['substep'] / $max_substep)) * 100) / $context['total_steps']); |
|
| 150 | + } |
|
| 145 | 151 | |
| 146 | 152 | // Never more than 100%! |
| 147 | 153 | $context['continue_percent'] = min($context['continue_percent'], 100); |
@@ -617,8 +623,9 @@ discard block |
||
| 617 | 623 | $row['myid_last_msg'] = (int) $row['myid_last_msg']; |
| 618 | 624 | |
| 619 | 625 | // Not really a problem? |
| 620 | - if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved']) |
|
| 621 | - return false; |
|
| 626 | + if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved']) { |
|
| 627 | + return false; |
|
| 628 | + } |
|
| 622 | 629 | |
| 623 | 630 | $memberStartedID = (int) getMsgMemberID($row['myid_first_msg']); |
| 624 | 631 | $memberUpdatedID = (int) getMsgMemberID($row['myid_last_msg']); |
@@ -642,15 +649,19 @@ discard block |
||
| 642 | 649 | 'message_function' => function ($row) use ($txt, &$context) |
| 643 | 650 | { |
| 644 | 651 | // A pretend error? |
| 645 | - if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved']) |
|
| 646 | - return false; |
|
| 652 | + if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved']) { |
|
| 653 | + return false; |
|
| 654 | + } |
|
| 647 | 655 | |
| 648 | - if ($row['id_first_msg'] != $row['myid_first_msg']) |
|
| 649 | - $context['repair_errors'][] = sprintf($txt['repair_stats_topics_1'], $row['id_topic'], $row['id_first_msg']); |
|
| 650 | - if ($row['id_last_msg'] != $row['myid_last_msg']) |
|
| 651 | - $context['repair_errors'][] = sprintf($txt['repair_stats_topics_2'], $row['id_topic'], $row['id_last_msg']); |
|
| 652 | - if ($row['approved'] != $row['firstmsg_approved']) |
|
| 653 | - $context['repair_errors'][] = sprintf($txt['repair_stats_topics_5'], $row['id_topic']); |
|
| 656 | + if ($row['id_first_msg'] != $row['myid_first_msg']) { |
|
| 657 | + $context['repair_errors'][] = sprintf($txt['repair_stats_topics_1'], $row['id_topic'], $row['id_first_msg']); |
|
| 658 | + } |
|
| 659 | + if ($row['id_last_msg'] != $row['myid_last_msg']) { |
|
| 660 | + $context['repair_errors'][] = sprintf($txt['repair_stats_topics_2'], $row['id_topic'], $row['id_last_msg']); |
|
| 661 | + } |
|
| 662 | + if ($row['approved'] != $row['firstmsg_approved']) { |
|
| 663 | + $context['repair_errors'][] = sprintf($txt['repair_stats_topics_5'], $row['id_topic']); |
|
| 664 | + } |
|
| 654 | 665 | |
| 655 | 666 | return true; |
| 656 | 667 | }, |
@@ -680,8 +691,9 @@ discard block |
||
| 680 | 691 | $row['my_num_replies'] = (int) $row['my_num_replies']; |
| 681 | 692 | |
| 682 | 693 | // Not really a problem? |
| 683 | - if ($row['my_num_replies'] == $row['num_replies']) |
|
| 684 | - return false; |
|
| 694 | + if ($row['my_num_replies'] == $row['num_replies']) { |
|
| 695 | + return false; |
|
| 696 | + } |
|
| 685 | 697 | |
| 686 | 698 | $smcFunc['db_query']('', ' |
| 687 | 699 | UPDATE {db_prefix}topics |
@@ -700,11 +712,13 @@ discard block |
||
| 700 | 712 | global $txt, $context; |
| 701 | 713 | |
| 702 | 714 | // Just joking? |
| 703 | - if ($row['my_num_replies'] == $row['num_replies']) |
|
| 704 | - return false; |
|
| 715 | + if ($row['my_num_replies'] == $row['num_replies']) { |
|
| 716 | + return false; |
|
| 717 | + } |
|
| 705 | 718 | |
| 706 | - if ($row['num_replies'] != $row['my_num_replies']) |
|
| 707 | - $context['repair_errors'][] = sprintf($txt['repair_stats_topics_3'], $row['id_topic'], $row['num_replies']); |
|
| 719 | + if ($row['num_replies'] != $row['my_num_replies']) { |
|
| 720 | + $context['repair_errors'][] = sprintf($txt['repair_stats_topics_3'], $row['id_topic'], $row['num_replies']); |
|
| 721 | + } |
|
| 708 | 722 | |
| 709 | 723 | return true; |
| 710 | 724 | |
@@ -1295,8 +1309,9 @@ discard block |
||
| 1295 | 1309 | $inserts = array(); |
| 1296 | 1310 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 1297 | 1311 | { |
| 1298 | - foreach (text2words($row['subject']) as $word) |
|
| 1299 | - $inserts[] = array($word, $row['id_topic']); |
|
| 1312 | + foreach (text2words($row['subject']) as $word) { |
|
| 1313 | + $inserts[] = array($word, $row['id_topic']); |
|
| 1314 | + } |
|
| 1300 | 1315 | if (count($inserts) > 500) |
| 1301 | 1316 | { |
| 1302 | 1317 | $smcFunc['db_insert']('ignore', |
@@ -1310,13 +1325,14 @@ discard block |
||
| 1310 | 1325 | |
| 1311 | 1326 | } |
| 1312 | 1327 | |
| 1313 | - if (!empty($inserts)) |
|
| 1314 | - $smcFunc['db_insert']('ignore', |
|
| 1328 | + if (!empty($inserts)) { |
|
| 1329 | + $smcFunc['db_insert']('ignore', |
|
| 1315 | 1330 | '{db_prefix}log_search_subjects', |
| 1316 | 1331 | array('word' => 'string', 'id_topic' => 'int'), |
| 1317 | 1332 | $inserts, |
| 1318 | 1333 | array('word', 'id_topic') |
| 1319 | 1334 | ); |
| 1335 | + } |
|
| 1320 | 1336 | |
| 1321 | 1337 | }, |
| 1322 | 1338 | 'message_function' => function ($row) |
@@ -1586,8 +1602,9 @@ discard block |
||
| 1586 | 1602 | $current_step++; |
| 1587 | 1603 | |
| 1588 | 1604 | // Already done this? |
| 1589 | - if ($_GET['step'] > $current_step) |
|
| 1590 | - continue; |
|
| 1605 | + if ($_GET['step'] > $current_step) { |
|
| 1606 | + continue; |
|
| 1607 | + } |
|
| 1591 | 1608 | |
| 1592 | 1609 | // If we're fixing it but it ain't broke why try? |
| 1593 | 1610 | if ($do_fix && !in_array($error_type, $to_fix)) |
@@ -1616,14 +1633,16 @@ discard block |
||
| 1616 | 1633 | while (!$done) |
| 1617 | 1634 | { |
| 1618 | 1635 | // Make sure there's at least one ID to test. |
| 1619 | - if (isset($test['substeps']) && empty($step_max)) |
|
| 1620 | - break; |
|
| 1636 | + if (isset($test['substeps']) && empty($step_max)) { |
|
| 1637 | + break; |
|
| 1638 | + } |
|
| 1621 | 1639 | |
| 1622 | 1640 | // What is the testing query (Changes if we are testing or fixing) |
| 1623 | - if (!$do_fix) |
|
| 1624 | - $test_query = 'check_query'; |
|
| 1625 | - else |
|
| 1626 | - $test_query = isset($test['fix_query']) ? 'fix_query' : 'check_query'; |
|
| 1641 | + if (!$do_fix) { |
|
| 1642 | + $test_query = 'check_query'; |
|
| 1643 | + } else { |
|
| 1644 | + $test_query = isset($test['fix_query']) ? 'fix_query' : 'check_query'; |
|
| 1645 | + } |
|
| 1627 | 1646 | |
| 1628 | 1647 | // Do the test... |
| 1629 | 1648 | $request = $smcFunc['db_query']('', |
@@ -1634,10 +1653,11 @@ discard block |
||
| 1634 | 1653 | $needs_fix = false; |
| 1635 | 1654 | |
| 1636 | 1655 | // Does it need a fix? |
| 1637 | - if (!empty($test['check_type']) && $test['check_type'] == 'count') |
|
| 1638 | - list ($needs_fix) = $smcFunc['db_fetch_row']($request); |
|
| 1639 | - else |
|
| 1640 | - $needs_fix = $smcFunc['db_num_rows']($request); |
|
| 1656 | + if (!empty($test['check_type']) && $test['check_type'] == 'count') { |
|
| 1657 | + list ($needs_fix) = $smcFunc['db_fetch_row']($request); |
|
| 1658 | + } else { |
|
| 1659 | + $needs_fix = $smcFunc['db_num_rows']($request); |
|
| 1660 | + } |
|
| 1641 | 1661 | |
| 1642 | 1662 | $total_queries++; |
| 1643 | 1663 | |
@@ -1649,8 +1669,9 @@ discard block |
||
| 1649 | 1669 | // Assume need to fix. |
| 1650 | 1670 | $found_errors = true; |
| 1651 | 1671 | |
| 1652 | - if (isset($test['message'])) |
|
| 1653 | - $context['repair_errors'][] = $txt[$test['message']]; |
|
| 1672 | + if (isset($test['message'])) { |
|
| 1673 | + $context['repair_errors'][] = $txt[$test['message']]; |
|
| 1674 | + } |
|
| 1654 | 1675 | |
| 1655 | 1676 | // One per row! |
| 1656 | 1677 | elseif (isset($test['messages'])) |
@@ -1660,10 +1681,11 @@ discard block |
||
| 1660 | 1681 | $variables = $test['messages']; |
| 1661 | 1682 | foreach ($variables as $k => $v) |
| 1662 | 1683 | { |
| 1663 | - if ($k == 0 && isset($txt[$v])) |
|
| 1664 | - $variables[$k] = $txt[$v]; |
|
| 1665 | - elseif ($k > 0 && isset($row[$v])) |
|
| 1666 | - $variables[$k] = $row[$v]; |
|
| 1684 | + if ($k == 0 && isset($txt[$v])) { |
|
| 1685 | + $variables[$k] = $txt[$v]; |
|
| 1686 | + } elseif ($k > 0 && isset($row[$v])) { |
|
| 1687 | + $variables[$k] = $row[$v]; |
|
| 1688 | + } |
|
| 1667 | 1689 | } |
| 1668 | 1690 | $context['repair_errors'][] = call_user_func_array('sprintf', $variables); |
| 1669 | 1691 | } |
@@ -1674,13 +1696,15 @@ discard block |
||
| 1674 | 1696 | { |
| 1675 | 1697 | // Find out if there are actually errors. |
| 1676 | 1698 | $found_errors = false; |
| 1677 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1678 | - $found_errors |= $test['message_function']($row); |
|
| 1699 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1700 | + $found_errors |= $test['message_function']($row); |
|
| 1701 | + } |
|
| 1679 | 1702 | } |
| 1680 | 1703 | |
| 1681 | 1704 | // Actually have something to fix? |
| 1682 | - if ($found_errors) |
|
| 1683 | - $to_fix[] = $error_type; |
|
| 1705 | + if ($found_errors) { |
|
| 1706 | + $to_fix[] = $error_type; |
|
| 1707 | + } |
|
| 1684 | 1708 | } |
| 1685 | 1709 | |
| 1686 | 1710 | // We want to fix, we need to fix - so work out what exactly to do! |
@@ -1690,8 +1714,9 @@ discard block |
||
| 1690 | 1714 | if (isset($test['fix_collect'])) |
| 1691 | 1715 | { |
| 1692 | 1716 | $ids = array(); |
| 1693 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1694 | - $ids[] = $row[$test['fix_collect']['index']]; |
|
| 1717 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1718 | + $ids[] = $row[$test['fix_collect']['index']]; |
|
| 1719 | + } |
|
| 1695 | 1720 | if (!empty($ids)) |
| 1696 | 1721 | { |
| 1697 | 1722 | // Fix it! |
@@ -1700,30 +1725,34 @@ discard block |
||
| 1700 | 1725 | } |
| 1701 | 1726 | |
| 1702 | 1727 | // Simply executing a fix it query? |
| 1703 | - elseif (isset($test['fix_it_query'])) |
|
| 1704 | - $smcFunc['db_query']('', |
|
| 1728 | + elseif (isset($test['fix_it_query'])) { |
|
| 1729 | + $smcFunc['db_query']('', |
|
| 1705 | 1730 | $test['fix_it_query'], |
| 1706 | 1731 | array( |
| 1707 | 1732 | ) |
| 1708 | 1733 | ); |
| 1734 | + } |
|
| 1709 | 1735 | |
| 1710 | 1736 | // Do we have some processing to do? |
| 1711 | 1737 | elseif (isset($test['fix_processing'])) |
| 1712 | 1738 | { |
| 1713 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1714 | - $test['fix_processing']($row); |
|
| 1739 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1740 | + $test['fix_processing']($row); |
|
| 1741 | + } |
|
| 1715 | 1742 | } |
| 1716 | 1743 | |
| 1717 | 1744 | // What about the full set of processing? |
| 1718 | - elseif (isset($test['fix_full_processing'])) |
|
| 1719 | - $test['fix_full_processing']($request); |
|
| 1745 | + elseif (isset($test['fix_full_processing'])) { |
|
| 1746 | + $test['fix_full_processing']($request); |
|
| 1747 | + } |
|
| 1720 | 1748 | |
| 1721 | 1749 | // Do we have other things we need to fix as a result? |
| 1722 | 1750 | if (!empty($test['force_fix'])) |
| 1723 | 1751 | { |
| 1724 | - foreach ($test['force_fix'] as $item) |
|
| 1725 | - if (!in_array($item, $to_fix)) |
|
| 1752 | + foreach ($test['force_fix'] as $item) { |
|
| 1753 | + if (!in_array($item, $to_fix)) |
|
| 1726 | 1754 | $to_fix[] = $item; |
| 1755 | + } |
|
| 1727 | 1756 | } |
| 1728 | 1757 | } |
| 1729 | 1758 | } |
@@ -1741,16 +1770,17 @@ discard block |
||
| 1741 | 1770 | if ($_GET['substep'] <= $step_max) |
| 1742 | 1771 | { |
| 1743 | 1772 | pauseRepairProcess($to_fix, $error_type, $step_max); |
| 1773 | + } else { |
|
| 1774 | + $done = true; |
|
| 1744 | 1775 | } |
| 1745 | - else |
|
| 1746 | - $done = true; |
|
| 1776 | + } else { |
|
| 1777 | + $done = true; |
|
| 1747 | 1778 | } |
| 1748 | - else |
|
| 1749 | - $done = true; |
|
| 1750 | 1779 | |
| 1751 | 1780 | // Don't allow more than 1000 queries at a time. |
| 1752 | - if ($total_queries >= 1000) |
|
| 1753 | - pauseRepairProcess($to_fix, $error_type, $step_max, true); |
|
| 1781 | + if ($total_queries >= 1000) { |
|
| 1782 | + pauseRepairProcess($to_fix, $error_type, $step_max, true); |
|
| 1783 | + } |
|
| 1754 | 1784 | } |
| 1755 | 1785 | |
| 1756 | 1786 | // Keep going. |
@@ -1763,8 +1793,9 @@ discard block |
||
| 1763 | 1793 | if ($do_fix) |
| 1764 | 1794 | { |
| 1765 | 1795 | $key = array_search($error_type, $to_fix); |
| 1766 | - if ($key !== false && isset($to_fix[$key])) |
|
| 1767 | - unset($to_fix[$key]); |
|
| 1796 | + if ($key !== false && isset($to_fix[$key])) { |
|
| 1797 | + unset($to_fix[$key]); |
|
| 1798 | + } |
|
| 1768 | 1799 | } |
| 1769 | 1800 | |
| 1770 | 1801 | // Are we done? |
@@ -1787,10 +1818,11 @@ discard block |
||
| 1787 | 1818 | static $createOnce = false; |
| 1788 | 1819 | |
| 1789 | 1820 | // Have we already created it? |
| 1790 | - if ($createOnce) |
|
| 1791 | - return; |
|
| 1792 | - else |
|
| 1793 | - $createOnce = true; |
|
| 1821 | + if ($createOnce) { |
|
| 1822 | + return; |
|
| 1823 | + } else { |
|
| 1824 | + $createOnce = true; |
|
| 1825 | + } |
|
| 1794 | 1826 | |
| 1795 | 1827 | // Back to the forum's default language. |
| 1796 | 1828 | loadLanguage('Admin', $language); |
@@ -1805,8 +1837,9 @@ discard block |
||
| 1805 | 1837 | 'cat_name' => $txt['salvaged_category_name'], |
| 1806 | 1838 | ) |
| 1807 | 1839 | ); |
| 1808 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1809 | - list ($salvageCatID) = $smcFunc['db_fetch_row']($result); |
|
| 1840 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1841 | + list ($salvageCatID) = $smcFunc['db_fetch_row']($result); |
|
| 1842 | + } |
|
| 1810 | 1843 | $smcFunc['db_free_result']($result); |
| 1811 | 1844 | |
| 1812 | 1845 | if (empty($salvageCatID)) |
@@ -1839,8 +1872,9 @@ discard block |
||
| 1839 | 1872 | 'board_name' => $txt['salvaged_board_name'], |
| 1840 | 1873 | ) |
| 1841 | 1874 | ); |
| 1842 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1843 | - list ($salvageBoardID) = $smcFunc['db_fetch_row']($result); |
|
| 1875 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1876 | + list ($salvageBoardID) = $smcFunc['db_fetch_row']($result); |
|
| 1877 | + } |
|
| 1844 | 1878 | $smcFunc['db_free_result']($result); |
| 1845 | 1879 | |
| 1846 | 1880 | if (empty($salvageBoardID)) |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Add the file functions to the $smcFunc array. |
@@ -23,14 +24,15 @@ discard block |
||
| 23 | 24 | { |
| 24 | 25 | global $smcFunc; |
| 25 | 26 | |
| 26 | - if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_query') |
|
| 27 | - $smcFunc += array( |
|
| 27 | + if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_query') { |
|
| 28 | + $smcFunc += array( |
|
| 28 | 29 | 'db_search_query' => 'smf_db_query', |
| 29 | 30 | 'db_search_support' => 'smf_db_search_support', |
| 30 | 31 | 'db_create_word_search' => 'smf_db_create_word_search', |
| 31 | 32 | 'db_support_ignore' => true, |
| 32 | 33 | ); |
| 33 | -} |
|
| 34 | + } |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | /** |
| 36 | 38 | * This function will tell you whether this database type supports this search type. |
@@ -54,12 +56,13 @@ discard block |
||
| 54 | 56 | { |
| 55 | 57 | global $smcFunc; |
| 56 | 58 | |
| 57 | - if ($size == 'small') |
|
| 58 | - $size = 'smallint(5)'; |
|
| 59 | - elseif ($size == 'medium') |
|
| 60 | - $size = 'mediumint(8)'; |
|
| 61 | - else |
|
| 62 | - $size = 'int(10)'; |
|
| 59 | + if ($size == 'small') { |
|
| 60 | + $size = 'smallint(5)'; |
|
| 61 | + } elseif ($size == 'medium') { |
|
| 62 | + $size = 'mediumint(8)'; |
|
| 63 | + } else { |
|
| 64 | + $size = 'int(10)'; |
|
| 65 | + } |
|
| 63 | 66 | |
| 64 | 67 | $smcFunc['db_query']('', ' |
| 65 | 68 | CREATE TABLE {db_prefix}log_search_words ( |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | $replacement[$key] = 'null'; |
| 253 | 253 | if (!isValidIP($value)) |
| 254 | 254 | smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
| 255 | - $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
|
| 255 | + $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | return implode(', ', $replacement); |
@@ -811,7 +811,7 @@ discard block |
||
| 811 | 811 | * @param bool $translate_human_wildcards If true, turns human readable wildcards into SQL wildcards. |
| 812 | 812 | * @return string The escaped string |
| 813 | 813 | */ |
| 814 | -function smf_db_escape_wildcard_string($string, $translate_human_wildcards=false) |
|
| 814 | +function smf_db_escape_wildcard_string($string, $translate_human_wildcards = false) |
|
| 815 | 815 | { |
| 816 | 816 | $replacements = array( |
| 817 | 817 | '%' => '\%', |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -33,8 +34,8 @@ discard block |
||
| 33 | 34 | global $smcFunc, $mysql_set_mode; |
| 34 | 35 | |
| 35 | 36 | // Map some database specific functions, only do this once. |
| 36 | - if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysql_fetch_assoc') |
|
| 37 | - $smcFunc += array( |
|
| 37 | + if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysql_fetch_assoc') { |
|
| 38 | + $smcFunc += array( |
|
| 38 | 39 | 'db_query' => 'smf_db_query', |
| 39 | 40 | 'db_quote' => 'smf_db_quote', |
| 40 | 41 | 'db_fetch_assoc' => 'mysql_fetch_assoc', |
@@ -58,36 +59,42 @@ discard block |
||
| 58 | 59 | 'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string', |
| 59 | 60 | 'db_is_resource' => 'is_resource', |
| 60 | 61 | ); |
| 62 | + } |
|
| 61 | 63 | |
| 62 | - if (!empty($db_options['port'])) |
|
| 63 | - $db_server .= ':' . $db_options['port']; |
|
| 64 | + if (!empty($db_options['port'])) { |
|
| 65 | + $db_server .= ':' . $db_options['port']; |
|
| 66 | + } |
|
| 64 | 67 | |
| 65 | 68 | $flags = 2; //#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */ |
| 66 | 69 | |
| 67 | - if (!empty($db_options['persist'])) |
|
| 68 | - $connection = @mysql_pconnect($db_server, $db_user, $db_passwd, $flags); |
|
| 69 | - else |
|
| 70 | - $connection = @mysql_connect($db_server, $db_user, $db_passwd, false, $flags); |
|
| 70 | + if (!empty($db_options['persist'])) { |
|
| 71 | + $connection = @mysql_pconnect($db_server, $db_user, $db_passwd, $flags); |
|
| 72 | + } else { |
|
| 73 | + $connection = @mysql_connect($db_server, $db_user, $db_passwd, false, $flags); |
|
| 74 | + } |
|
| 71 | 75 | |
| 72 | 76 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 73 | 77 | if (!$connection) |
| 74 | 78 | { |
| 75 | - if (!empty($db_options['non_fatal'])) |
|
| 76 | - return null; |
|
| 77 | - else |
|
| 78 | - display_db_error(); |
|
| 79 | + if (!empty($db_options['non_fatal'])) { |
|
| 80 | + return null; |
|
| 81 | + } else { |
|
| 82 | + display_db_error(); |
|
| 83 | + } |
|
| 79 | 84 | } |
| 80 | 85 | |
| 81 | 86 | // Select the database, unless told not to |
| 82 | - if (empty($db_options['dont_select_db']) && !@mysql_select_db($db_name, $connection) && empty($db_options['non_fatal'])) |
|
| 83 | - display_db_error(); |
|
| 87 | + if (empty($db_options['dont_select_db']) && !@mysql_select_db($db_name, $connection) && empty($db_options['non_fatal'])) { |
|
| 88 | + display_db_error(); |
|
| 89 | + } |
|
| 84 | 90 | |
| 85 | 91 | // This makes it possible to have SMF automatically change the sql_mode and autocommit if needed. |
| 86 | - if (isset($mysql_set_mode) && $mysql_set_mode === true) |
|
| 87 | - $smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1', |
|
| 92 | + if (isset($mysql_set_mode) && $mysql_set_mode === true) { |
|
| 93 | + $smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1', |
|
| 88 | 94 | array(), |
| 89 | 95 | false |
| 90 | 96 | ); |
| 97 | + } |
|
| 91 | 98 | |
| 92 | 99 | return $connection; |
| 93 | 100 | } |
@@ -134,37 +141,46 @@ discard block |
||
| 134 | 141 | list ($values, $connection) = $db_callback; |
| 135 | 142 | |
| 136 | 143 | // Connection gone??? This should *never* happen at this point, yet it does :'( |
| 137 | - if (!is_resource($connection)) |
|
| 138 | - display_db_error(); |
|
| 144 | + if (!is_resource($connection)) { |
|
| 145 | + display_db_error(); |
|
| 146 | + } |
|
| 139 | 147 | |
| 140 | - if ($matches[1] === 'db_prefix') |
|
| 141 | - return $db_prefix; |
|
| 148 | + if ($matches[1] === 'db_prefix') { |
|
| 149 | + return $db_prefix; |
|
| 150 | + } |
|
| 142 | 151 | |
| 143 | - if ($matches[1] === 'query_see_board') |
|
| 144 | - return $user_info['query_see_board']; |
|
| 152 | + if ($matches[1] === 'query_see_board') { |
|
| 153 | + return $user_info['query_see_board']; |
|
| 154 | + } |
|
| 145 | 155 | |
| 146 | - if ($matches[1] === 'query_wanna_see_board') |
|
| 147 | - return $user_info['query_wanna_see_board']; |
|
| 156 | + if ($matches[1] === 'query_wanna_see_board') { |
|
| 157 | + return $user_info['query_wanna_see_board']; |
|
| 158 | + } |
|
| 148 | 159 | |
| 149 | - if ($matches[1] === 'empty') |
|
| 150 | - return '\'\''; |
|
| 160 | + if ($matches[1] === 'empty') { |
|
| 161 | + return '\'\''; |
|
| 162 | + } |
|
| 151 | 163 | |
| 152 | - if (!isset($matches[2])) |
|
| 153 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 164 | + if (!isset($matches[2])) { |
|
| 165 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 166 | + } |
|
| 154 | 167 | |
| 155 | - if ($matches[1] === 'literal') |
|
| 156 | - return '\'' . mysql_real_escape_string($matches[2], $connection) . '\''; |
|
| 168 | + if ($matches[1] === 'literal') { |
|
| 169 | + return '\'' . mysql_real_escape_string($matches[2], $connection) . '\''; |
|
| 170 | + } |
|
| 157 | 171 | |
| 158 | - if (!isset($values[$matches[2]])) |
|
| 159 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 172 | + if (!isset($values[$matches[2]])) { |
|
| 173 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 174 | + } |
|
| 160 | 175 | |
| 161 | 176 | $replacement = $values[$matches[2]]; |
| 162 | 177 | |
| 163 | 178 | switch ($matches[1]) |
| 164 | 179 | { |
| 165 | 180 | case 'int': |
| 166 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 167 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 181 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 182 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 183 | + } |
|
| 168 | 184 | return (string) (int) $replacement; |
| 169 | 185 | break; |
| 170 | 186 | |
@@ -176,49 +192,55 @@ discard block |
||
| 176 | 192 | case 'array_int': |
| 177 | 193 | if (is_array($replacement)) |
| 178 | 194 | { |
| 179 | - if (empty($replacement)) |
|
| 180 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 195 | + if (empty($replacement)) { |
|
| 196 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 197 | + } |
|
| 181 | 198 | |
| 182 | 199 | foreach ($replacement as $key => $value) |
| 183 | 200 | { |
| 184 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 185 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 201 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 202 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 203 | + } |
|
| 186 | 204 | |
| 187 | 205 | $replacement[$key] = (string) (int) $value; |
| 188 | 206 | } |
| 189 | 207 | |
| 190 | 208 | return implode(', ', $replacement); |
| 209 | + } else { |
|
| 210 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 191 | 211 | } |
| 192 | - else |
|
| 193 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 194 | 212 | |
| 195 | 213 | break; |
| 196 | 214 | |
| 197 | 215 | case 'array_string': |
| 198 | 216 | if (is_array($replacement)) |
| 199 | 217 | { |
| 200 | - if (empty($replacement)) |
|
| 201 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 218 | + if (empty($replacement)) { |
|
| 219 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 220 | + } |
|
| 202 | 221 | |
| 203 | - foreach ($replacement as $key => $value) |
|
| 204 | - $replacement[$key] = sprintf('\'%1$s\'', mysql_real_escape_string($value, $connection)); |
|
| 222 | + foreach ($replacement as $key => $value) { |
|
| 223 | + $replacement[$key] = sprintf('\'%1$s\'', mysql_real_escape_string($value, $connection)); |
|
| 224 | + } |
|
| 205 | 225 | |
| 206 | 226 | return implode(', ', $replacement); |
| 227 | + } else { |
|
| 228 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 207 | 229 | } |
| 208 | - else |
|
| 209 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 210 | 230 | break; |
| 211 | 231 | |
| 212 | 232 | case 'date': |
| 213 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
| 214 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 215 | - else |
|
| 216 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 233 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 234 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 235 | + } else { |
|
| 236 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 237 | + } |
|
| 217 | 238 | break; |
| 218 | 239 | |
| 219 | 240 | case 'float': |
| 220 | - if (!is_numeric($replacement)) |
|
| 221 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 241 | + if (!is_numeric($replacement)) { |
|
| 242 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 243 | + } |
|
| 222 | 244 | return (string) (float) $replacement; |
| 223 | 245 | break; |
| 224 | 246 | |
@@ -232,32 +254,37 @@ discard block |
||
| 232 | 254 | break; |
| 233 | 255 | |
| 234 | 256 | case 'inet': |
| 235 | - if ($replacement == 'null' || $replacement == '') |
|
| 236 | - return 'null'; |
|
| 237 | - if (!isValidIP($replacement)) |
|
| 238 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 257 | + if ($replacement == 'null' || $replacement == '') { |
|
| 258 | + return 'null'; |
|
| 259 | + } |
|
| 260 | + if (!isValidIP($replacement)) { |
|
| 261 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 262 | + } |
|
| 239 | 263 | //we don't use the native support of mysql > 5.6.2 |
| 240 | 264 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
| 241 | 265 | |
| 242 | 266 | case 'array_inet': |
| 243 | 267 | if (is_array($replacement)) |
| 244 | 268 | { |
| 245 | - if (empty($replacement)) |
|
| 246 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 269 | + if (empty($replacement)) { |
|
| 270 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 271 | + } |
|
| 247 | 272 | |
| 248 | 273 | foreach ($replacement as $key => $value) |
| 249 | 274 | { |
| 250 | - if ($replacement == 'null' || $replacement == '') |
|
| 251 | - $replacement[$key] = 'null'; |
|
| 252 | - if (!isValidIP($value)) |
|
| 253 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 275 | + if ($replacement == 'null' || $replacement == '') { |
|
| 276 | + $replacement[$key] = 'null'; |
|
| 277 | + } |
|
| 278 | + if (!isValidIP($value)) { |
|
| 279 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 280 | + } |
|
| 254 | 281 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
| 255 | 282 | } |
| 256 | 283 | |
| 257 | 284 | return implode(', ', $replacement); |
| 285 | + } else { |
|
| 286 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 258 | 287 | } |
| 259 | - else |
|
| 260 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 261 | 288 | break; |
| 262 | 289 | |
| 263 | 290 | default: |
@@ -328,18 +355,20 @@ discard block |
||
| 328 | 355 | // One more query.... |
| 329 | 356 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 330 | 357 | |
| 331 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 332 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 358 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 359 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 360 | + } |
|
| 333 | 361 | |
| 334 | 362 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
| 335 | 363 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
| 336 | 364 | { |
| 337 | 365 | // Add before LIMIT |
| 338 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
| 339 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 340 | - else |
|
| 341 | - // Append it. |
|
| 366 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
| 367 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 368 | + } else { |
|
| 369 | + // Append it. |
|
| 342 | 370 | $db_string .= "\n\t\t\tORDER BY null"; |
| 371 | + } |
|
| 343 | 372 | } |
| 344 | 373 | |
| 345 | 374 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -361,8 +390,9 @@ discard block |
||
| 361 | 390 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 362 | 391 | |
| 363 | 392 | // Initialize $db_cache if not already initialized. |
| 364 | - if (!isset($db_cache)) |
|
| 365 | - $db_cache = array(); |
|
| 393 | + if (!isset($db_cache)) { |
|
| 394 | + $db_cache = array(); |
|
| 395 | + } |
|
| 366 | 396 | |
| 367 | 397 | if (!empty($_SESSION['debug_redirect'])) |
| 368 | 398 | { |
@@ -388,17 +418,18 @@ discard block |
||
| 388 | 418 | while (true) |
| 389 | 419 | { |
| 390 | 420 | $pos = strpos($db_string, '\'', $pos + 1); |
| 391 | - if ($pos === false) |
|
| 392 | - break; |
|
| 421 | + if ($pos === false) { |
|
| 422 | + break; |
|
| 423 | + } |
|
| 393 | 424 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
| 394 | 425 | |
| 395 | 426 | while (true) |
| 396 | 427 | { |
| 397 | 428 | $pos1 = strpos($db_string, '\'', $pos + 1); |
| 398 | 429 | $pos2 = strpos($db_string, '\\', $pos + 1); |
| 399 | - if ($pos1 === false) |
|
| 400 | - break; |
|
| 401 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
| 430 | + if ($pos1 === false) { |
|
| 431 | + break; |
|
| 432 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
| 402 | 433 | { |
| 403 | 434 | $pos = $pos1; |
| 404 | 435 | break; |
@@ -414,29 +445,35 @@ discard block |
||
| 414 | 445 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 415 | 446 | |
| 416 | 447 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 417 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 418 | - $fail = true; |
|
| 448 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 449 | + $fail = true; |
|
| 450 | + } |
|
| 419 | 451 | // Trying to change passwords, slow us down, or something? |
| 420 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 421 | - $fail = true; |
|
| 422 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 423 | - $fail = true; |
|
| 452 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 453 | + $fail = true; |
|
| 454 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 455 | + $fail = true; |
|
| 456 | + } |
|
| 424 | 457 | |
| 425 | - if (!empty($fail) && function_exists('log_error')) |
|
| 426 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 458 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 459 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 460 | + } |
|
| 427 | 461 | } |
| 428 | 462 | |
| 429 | - if (empty($db_unbuffered)) |
|
| 430 | - $ret = @mysql_query($db_string, $connection); |
|
| 431 | - else |
|
| 432 | - $ret = @mysql_unbuffered_query($db_string, $connection); |
|
| 463 | + if (empty($db_unbuffered)) { |
|
| 464 | + $ret = @mysql_query($db_string, $connection); |
|
| 465 | + } else { |
|
| 466 | + $ret = @mysql_unbuffered_query($db_string, $connection); |
|
| 467 | + } |
|
| 433 | 468 | |
| 434 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
| 435 | - $ret = smf_db_error($db_string, $connection); |
|
| 469 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
| 470 | + $ret = smf_db_error($db_string, $connection); |
|
| 471 | + } |
|
| 436 | 472 | |
| 437 | 473 | // Debugging. |
| 438 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 439 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 474 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 475 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 476 | + } |
|
| 440 | 477 | |
| 441 | 478 | return $ret; |
| 442 | 479 | } |
@@ -485,12 +522,13 @@ discard block |
||
| 485 | 522 | // Decide which connection to use |
| 486 | 523 | $connection = $connection === null ? $db_connection : $connection; |
| 487 | 524 | |
| 488 | - if ($type == 'begin') |
|
| 489 | - return @mysql_query('BEGIN', $connection); |
|
| 490 | - elseif ($type == 'rollback') |
|
| 491 | - return @mysql_query('ROLLBACK', $connection); |
|
| 492 | - elseif ($type == 'commit') |
|
| 493 | - return @mysql_query('COMMIT', $connection); |
|
| 525 | + if ($type == 'begin') { |
|
| 526 | + return @mysql_query('BEGIN', $connection); |
|
| 527 | + } elseif ($type == 'rollback') { |
|
| 528 | + return @mysql_query('ROLLBACK', $connection); |
|
| 529 | + } elseif ($type == 'commit') { |
|
| 530 | + return @mysql_query('COMMIT', $connection); |
|
| 531 | + } |
|
| 494 | 532 | |
| 495 | 533 | return false; |
| 496 | 534 | } |
@@ -530,8 +568,9 @@ discard block |
||
| 530 | 568 | // 2013: Lost connection to server during query. |
| 531 | 569 | |
| 532 | 570 | // Log the error. |
| 533 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
| 534 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 571 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
| 572 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 573 | + } |
|
| 535 | 574 | |
| 536 | 575 | // Database error auto fixing ;). |
| 537 | 576 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -540,8 +579,9 @@ discard block |
||
| 540 | 579 | $old_cache = @$modSettings['cache_enable']; |
| 541 | 580 | $modSettings['cache_enable'] = '1'; |
| 542 | 581 | |
| 543 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
| 544 | - $db_last_error = max(@$db_last_error, $temp); |
|
| 582 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
| 583 | + $db_last_error = max(@$db_last_error, $temp); |
|
| 584 | + } |
|
| 545 | 585 | |
| 546 | 586 | if (@$db_last_error < time() - 3600 * 24 * 3) |
| 547 | 587 | { |
@@ -557,8 +597,9 @@ discard block |
||
| 557 | 597 | foreach ($tables as $table) |
| 558 | 598 | { |
| 559 | 599 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
| 560 | - if (trim($table) != '') |
|
| 561 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 600 | + if (trim($table) != '') { |
|
| 601 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 602 | + } |
|
| 562 | 603 | } |
| 563 | 604 | } |
| 564 | 605 | |
@@ -567,8 +608,9 @@ discard block |
||
| 567 | 608 | // Table crashed. Let's try to fix it. |
| 568 | 609 | elseif ($query_errno == 1016) |
| 569 | 610 | { |
| 570 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
| 571 | - $fix_tables = array('`' . $match[1] . '`'); |
|
| 611 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
| 612 | + $fix_tables = array('`' . $match[1] . '`'); |
|
| 613 | + } |
|
| 572 | 614 | } |
| 573 | 615 | // Indexes crashed. Should be easy to fix! |
| 574 | 616 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -587,13 +629,15 @@ discard block |
||
| 587 | 629 | |
| 588 | 630 | // Make a note of the REPAIR... |
| 589 | 631 | cache_put_data('db_last_error', time(), 600); |
| 590 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
| 591 | - updateSettingsFile(array('db_last_error' => time())); |
|
| 632 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
| 633 | + updateSettingsFile(array('db_last_error' => time())); |
|
| 634 | + } |
|
| 592 | 635 | |
| 593 | 636 | // Attempt to find and repair the broken table. |
| 594 | - foreach ($fix_tables as $table) |
|
| 595 | - $smcFunc['db_query']('', " |
|
| 637 | + foreach ($fix_tables as $table) { |
|
| 638 | + $smcFunc['db_query']('', " |
|
| 596 | 639 | REPAIR TABLE $table", false, false); |
| 640 | + } |
|
| 597 | 641 | |
| 598 | 642 | // And send off an email! |
| 599 | 643 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -602,11 +646,12 @@ discard block |
||
| 602 | 646 | |
| 603 | 647 | // Try the query again...? |
| 604 | 648 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 605 | - if ($ret !== false) |
|
| 606 | - return $ret; |
|
| 649 | + if ($ret !== false) { |
|
| 650 | + return $ret; |
|
| 651 | + } |
|
| 652 | + } else { |
|
| 653 | + $modSettings['cache_enable'] = $old_cache; |
|
| 607 | 654 | } |
| 608 | - else |
|
| 609 | - $modSettings['cache_enable'] = $old_cache; |
|
| 610 | 655 | |
| 611 | 656 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
| 612 | 657 | if (in_array($query_errno, array(1205, 1213, 2006, 2013))) |
@@ -616,22 +661,25 @@ discard block |
||
| 616 | 661 | // Are we in SSI mode? If so try that username and password first |
| 617 | 662 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
| 618 | 663 | { |
| 619 | - if (empty($db_persist)) |
|
| 620 | - $db_connection = @mysql_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 621 | - else |
|
| 622 | - $db_connection = @mysql_pconnect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 664 | + if (empty($db_persist)) { |
|
| 665 | + $db_connection = @mysql_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 666 | + } else { |
|
| 667 | + $db_connection = @mysql_pconnect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 668 | + } |
|
| 623 | 669 | } |
| 624 | 670 | // Fall back to the regular username and password if need be |
| 625 | 671 | if (!$db_connection) |
| 626 | 672 | { |
| 627 | - if (empty($db_persist)) |
|
| 628 | - $db_connection = @mysql_connect($db_server, $db_user, $db_passwd); |
|
| 629 | - else |
|
| 630 | - $db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd); |
|
| 673 | + if (empty($db_persist)) { |
|
| 674 | + $db_connection = @mysql_connect($db_server, $db_user, $db_passwd); |
|
| 675 | + } else { |
|
| 676 | + $db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd); |
|
| 677 | + } |
|
| 631 | 678 | } |
| 632 | 679 | |
| 633 | - if (!$db_connection || !@mysql_select_db($db_name, $db_connection)) |
|
| 634 | - $db_connection = false; |
|
| 680 | + if (!$db_connection || !@mysql_select_db($db_name, $db_connection)) { |
|
| 681 | + $db_connection = false; |
|
| 682 | + } |
|
| 635 | 683 | } |
| 636 | 684 | |
| 637 | 685 | if ($db_connection) |
@@ -642,24 +690,27 @@ discard block |
||
| 642 | 690 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 643 | 691 | |
| 644 | 692 | $new_errno = mysql_errno($db_connection); |
| 645 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
| 646 | - break; |
|
| 693 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
| 694 | + break; |
|
| 695 | + } |
|
| 647 | 696 | } |
| 648 | 697 | |
| 649 | 698 | // If it failed again, shucks to be you... we're not trying it over and over. |
| 650 | - if ($ret !== false) |
|
| 651 | - return $ret; |
|
| 699 | + if ($ret !== false) { |
|
| 700 | + return $ret; |
|
| 701 | + } |
|
| 652 | 702 | } |
| 653 | 703 | } |
| 654 | 704 | // Are they out of space, perhaps? |
| 655 | 705 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
| 656 | 706 | { |
| 657 | - if (!isset($txt)) |
|
| 658 | - $query_error .= ' - check database storage space.'; |
|
| 659 | - else |
|
| 707 | + if (!isset($txt)) { |
|
| 708 | + $query_error .= ' - check database storage space.'; |
|
| 709 | + } else |
|
| 660 | 710 | { |
| 661 | - if (!isset($txt['mysql_error_space'])) |
|
| 662 | - loadLanguage('Errors'); |
|
| 711 | + if (!isset($txt['mysql_error_space'])) { |
|
| 712 | + loadLanguage('Errors'); |
|
| 713 | + } |
|
| 663 | 714 | |
| 664 | 715 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
| 665 | 716 | } |
@@ -667,15 +718,17 @@ discard block |
||
| 667 | 718 | } |
| 668 | 719 | |
| 669 | 720 | // Nothing's defined yet... just die with it. |
| 670 | - if (empty($context) || empty($txt)) |
|
| 671 | - die($query_error); |
|
| 721 | + if (empty($context) || empty($txt)) { |
|
| 722 | + die($query_error); |
|
| 723 | + } |
|
| 672 | 724 | |
| 673 | 725 | // Show an error message, if possible. |
| 674 | 726 | $context['error_title'] = $txt['database_error']; |
| 675 | - if (allowedTo('admin_forum')) |
|
| 676 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 677 | - else |
|
| 678 | - $context['error_message'] = $txt['try_again']; |
|
| 727 | + if (allowedTo('admin_forum')) { |
|
| 728 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 729 | + } else { |
|
| 730 | + $context['error_message'] = $txt['try_again']; |
|
| 731 | + } |
|
| 679 | 732 | |
| 680 | 733 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 681 | 734 | { |
@@ -704,25 +757,28 @@ discard block |
||
| 704 | 757 | $connection = $connection === null ? $db_connection : $connection; |
| 705 | 758 | |
| 706 | 759 | // With nothing to insert, simply return. |
| 707 | - if (empty($data)) |
|
| 708 | - return; |
|
| 760 | + if (empty($data)) { |
|
| 761 | + return; |
|
| 762 | + } |
|
| 709 | 763 | |
| 710 | 764 | // Replace the prefix holder with the actual prefix. |
| 711 | 765 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
| 712 | 766 | |
| 713 | 767 | // Inserting data as a single row can be done as a single array. |
| 714 | - if (!is_array($data[array_rand($data)])) |
|
| 715 | - $data = array($data); |
|
| 768 | + if (!is_array($data[array_rand($data)])) { |
|
| 769 | + $data = array($data); |
|
| 770 | + } |
|
| 716 | 771 | |
| 717 | 772 | // Create the mold for a single row insert. |
| 718 | 773 | $insertData = '('; |
| 719 | 774 | foreach ($columns as $columnName => $type) |
| 720 | 775 | { |
| 721 | 776 | // Are we restricting the length? |
| 722 | - if (strpos($type, 'string-') !== false) |
|
| 723 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 724 | - else |
|
| 725 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 777 | + if (strpos($type, 'string-') !== false) { |
|
| 778 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 779 | + } else { |
|
| 780 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 781 | + } |
|
| 726 | 782 | } |
| 727 | 783 | $insertData = substr($insertData, 0, -2) . ')'; |
| 728 | 784 | |
@@ -731,8 +787,9 @@ discard block |
||
| 731 | 787 | |
| 732 | 788 | // Here's where the variables are injected to the query. |
| 733 | 789 | $insertRows = array(); |
| 734 | - foreach ($data as $dataRow) |
|
| 735 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 790 | + foreach ($data as $dataRow) { |
|
| 791 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 792 | + } |
|
| 736 | 793 | |
| 737 | 794 | // Determine the method of insertion. |
| 738 | 795 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
@@ -763,8 +820,9 @@ discard block |
||
| 763 | 820 | */ |
| 764 | 821 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 765 | 822 | { |
| 766 | - if (empty($log_message)) |
|
| 767 | - $log_message = $error_message; |
|
| 823 | + if (empty($log_message)) { |
|
| 824 | + $log_message = $error_message; |
|
| 825 | + } |
|
| 768 | 826 | |
| 769 | 827 | foreach (debug_backtrace() as $step) |
| 770 | 828 | { |
@@ -783,12 +841,14 @@ discard block |
||
| 783 | 841 | } |
| 784 | 842 | |
| 785 | 843 | // A special case - we want the file and line numbers for debugging. |
| 786 | - if ($error_type == 'return') |
|
| 787 | - return array($file, $line); |
|
| 844 | + if ($error_type == 'return') { |
|
| 845 | + return array($file, $line); |
|
| 846 | + } |
|
| 788 | 847 | |
| 789 | 848 | // Is always a critical error. |
| 790 | - if (function_exists('log_error')) |
|
| 791 | - log_error($log_message, 'critical', $file, $line); |
|
| 849 | + if (function_exists('log_error')) { |
|
| 850 | + log_error($log_message, 'critical', $file, $line); |
|
| 851 | + } |
|
| 792 | 852 | |
| 793 | 853 | if (function_exists('fatal_error')) |
| 794 | 854 | { |
@@ -796,12 +856,12 @@ discard block |
||
| 796 | 856 | |
| 797 | 857 | // Cannot continue... |
| 798 | 858 | exit; |
| 859 | + } elseif ($error_type) { |
|
| 860 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 861 | + } else { |
|
| 862 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 863 | + } |
|
| 799 | 864 | } |
| 800 | - elseif ($error_type) |
|
| 801 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 802 | - else |
|
| 803 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 804 | -} |
|
| 805 | 865 | |
| 806 | 866 | /** |
| 807 | 867 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -818,10 +878,11 @@ discard block |
||
| 818 | 878 | '\\' => '\\\\', |
| 819 | 879 | ); |
| 820 | 880 | |
| 821 | - if ($translate_human_wildcards) |
|
| 822 | - $replacements += array( |
|
| 881 | + if ($translate_human_wildcards) { |
|
| 882 | + $replacements += array( |
|
| 823 | 883 | '*' => '%', |
| 824 | 884 | ); |
| 885 | + } |
|
| 825 | 886 | |
| 826 | 887 | return strtr($string, $replacements); |
| 827 | 888 | } |
@@ -206,12 +206,12 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | if (!empty($modSettings['search_simple_fulltext'])) |
| 208 | 208 | { |
| 209 | - if($smcFunc['db_title'] == "PostgreSQL") |
|
| 209 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
| 210 | 210 | { |
| 211 | 211 | //we use the default language "default_text_search_config", otherwise we had to assgine the language here |
| 212 | 212 | //to_tsvector(body) -> to_tsvector($language,body) to_tsquery(...) -> to_tsquery($language,...) |
| 213 | 213 | $language_ftx = 'english'; |
| 214 | - $request = $smcFunc['db_query']('',' |
|
| 214 | + $request = $smcFunc['db_query']('', ' |
|
| 215 | 215 | SHOW default_text_search_config', |
| 216 | 216 | array() |
| 217 | 217 | ); |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | // remove any indexed words that are used in the complex body search terms |
| 236 | 236 | $words['indexed_words'] = array_diff($words['indexed_words'], $words['complex_words']); |
| 237 | 237 | |
| 238 | - if($smcFunc['db_title'] == "PostgreSQL"){ |
|
| 238 | + if ($smcFunc['db_title'] == "PostgreSQL") { |
|
| 239 | 239 | $row = 0; |
| 240 | 240 | foreach ($words['indexed_words'] as $fulltextWord) { |
| 241 | 241 | $query_params['boolean_match'] .= ($row <> 0 ? '&' : ''); |
@@ -251,12 +251,12 @@ discard block |
||
| 251 | 251 | |
| 252 | 252 | // if we have bool terms to search, add them in |
| 253 | 253 | if ($query_params['boolean_match']) { |
| 254 | - if($smcFunc['db_title'] == "PostgreSQL") |
|
| 254 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
| 255 | 255 | { |
| 256 | 256 | //we use the default language "default_text_search_config", otherwise we had to assgine the language here |
| 257 | 257 | //to_tsvector(body) -> to_tsvector($language,body) to_tsquery(...) -> to_tsquery($language,...) |
| 258 | 258 | $language_ftx = 'english'; |
| 259 | - $request = $smcFunc['db_query']('',' |
|
| 259 | + $request = $smcFunc['db_query']('', ' |
|
| 260 | 260 | SHOW default_text_search_config', |
| 261 | 261 | array() |
| 262 | 262 | ); |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? ( ' |
|
| 278 | + $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? (' |
|
| 279 | 279 | INSERT IGNORE INTO {db_prefix}' . $search_data['insert_into'] . ' |
| 280 | 280 | (' . implode(', ', array_keys($query_select)) . ')') : '') . ' |
| 281 | 281 | SELECT ' . implode(', ', $query_select) . ' |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 3 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('No direct access...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Class fulltext_search |
@@ -98,8 +99,9 @@ discard block |
||
| 98 | 99 | $smcFunc['db_free_result']($request); |
| 99 | 100 | } |
| 100 | 101 | // 4 is the MySQL default... |
| 101 | - else |
|
| 102 | - $min_word_length = 4; |
|
| 102 | + else { |
|
| 103 | + $min_word_length = 4; |
|
| 104 | + } |
|
| 103 | 105 | |
| 104 | 106 | return $min_word_length; |
| 105 | 107 | } |
@@ -138,8 +140,7 @@ discard block |
||
| 138 | 140 | $wordsSearch['words'][] = trim($word, "/*- "); |
| 139 | 141 | $wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"'; |
| 140 | 142 | } |
| 141 | - } |
|
| 142 | - elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
| 143 | + } elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
| 143 | 144 | { |
| 144 | 145 | // short words have feelings too |
| 145 | 146 | $wordsSearch['words'][] = trim($word, "/*- "); |
@@ -149,8 +150,9 @@ discard block |
||
| 149 | 150 | |
| 150 | 151 | $fulltextWord = count($subwords) === 1 ? $word : '"' . $word . '"'; |
| 151 | 152 | $wordsSearch['indexed_words'][] = $fulltextWord; |
| 152 | - if ($isExcluded) |
|
| 153 | - $wordsExclude[] = $fulltextWord; |
|
| 153 | + if ($isExcluded) { |
|
| 154 | + $wordsExclude[] = $fulltextWord; |
|
| 155 | + } |
|
| 154 | 156 | } |
| 155 | 157 | |
| 156 | 158 | /** |
@@ -166,41 +168,50 @@ discard block |
||
| 166 | 168 | $query_where = array(); |
| 167 | 169 | $query_params = $search_data['params']; |
| 168 | 170 | |
| 169 | - if ($query_params['id_search']) |
|
| 170 | - $query_select['id_search'] = '{int:id_search}'; |
|
| 171 | + if ($query_params['id_search']) { |
|
| 172 | + $query_select['id_search'] = '{int:id_search}'; |
|
| 173 | + } |
|
| 171 | 174 | |
| 172 | 175 | $count = 0; |
| 173 | - if (empty($modSettings['search_simple_fulltext'])) |
|
| 174 | - foreach ($words['words'] as $regularWord) |
|
| 176 | + if (empty($modSettings['search_simple_fulltext'])) { |
|
| 177 | + foreach ($words['words'] as $regularWord) |
|
| 175 | 178 | { |
| 176 | 179 | $query_where[] = 'm.body' . (in_array($regularWord, $query_params['excluded_words']) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:complex_body_' . $count . '}'; |
| 180 | + } |
|
| 177 | 181 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
| 178 | 182 | } |
| 179 | 183 | |
| 180 | - if ($query_params['user_query']) |
|
| 181 | - $query_where[] = '{raw:user_query}'; |
|
| 182 | - if ($query_params['board_query']) |
|
| 183 | - $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 184 | + if ($query_params['user_query']) { |
|
| 185 | + $query_where[] = '{raw:user_query}'; |
|
| 186 | + } |
|
| 187 | + if ($query_params['board_query']) { |
|
| 188 | + $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 189 | + } |
|
| 184 | 190 | |
| 185 | - if ($query_params['topic']) |
|
| 186 | - $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 187 | - if ($query_params['min_msg_id']) |
|
| 188 | - $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 189 | - if ($query_params['max_msg_id']) |
|
| 190 | - $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 191 | + if ($query_params['topic']) { |
|
| 192 | + $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 193 | + } |
|
| 194 | + if ($query_params['min_msg_id']) { |
|
| 195 | + $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 196 | + } |
|
| 197 | + if ($query_params['max_msg_id']) { |
|
| 198 | + $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 199 | + } |
|
| 191 | 200 | |
| 192 | 201 | $count = 0; |
| 193 | - if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
|
| 194 | - foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 202 | + if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) { |
|
| 203 | + foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 195 | 204 | { |
| 196 | 205 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_phrase_' . $count . '}'; |
| 206 | + } |
|
| 197 | 207 | $query_params['exclude_subject_phrase_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($phrase, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $phrase), '\\\'') . '[[:>:]]'; |
| 198 | 208 | } |
| 199 | 209 | $count = 0; |
| 200 | - if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
|
| 201 | - foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 210 | + if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) { |
|
| 211 | + foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 202 | 212 | { |
| 203 | 213 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_words_' . $count . '}'; |
| 214 | + } |
|
| 204 | 215 | $query_params['exclude_subject_words_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($excludedWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $excludedWord), '\\\'') . '[[:>:]]'; |
| 205 | 216 | } |
| 206 | 217 | |
@@ -223,12 +234,11 @@ discard block |
||
| 223 | 234 | } |
| 224 | 235 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:body_match})'; |
| 225 | 236 | $query_params['language_ftx'] = $language_ftx; |
| 237 | + } else { |
|
| 238 | + $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
| 226 | 239 | } |
| 227 | - else |
|
| 228 | - $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
| 229 | 240 | $query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words'])); |
| 230 | - } |
|
| 231 | - else |
|
| 241 | + } else |
|
| 232 | 242 | { |
| 233 | 243 | $query_params['boolean_match'] = ''; |
| 234 | 244 | |
@@ -242,10 +252,10 @@ discard block |
||
| 242 | 252 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' '; |
| 243 | 253 | $row++; |
| 244 | 254 | } |
| 245 | - } |
|
| 246 | - else |
|
| 247 | - foreach ($words['indexed_words'] as $fulltextWord) |
|
| 255 | + } else { |
|
| 256 | + foreach ($words['indexed_words'] as $fulltextWord) |
|
| 248 | 257 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' '; |
| 258 | + } |
|
| 249 | 259 | |
| 250 | 260 | $query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1); |
| 251 | 261 | |
@@ -268,9 +278,9 @@ discard block |
||
| 268 | 278 | } |
| 269 | 279 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:boolean_match})'; |
| 270 | 280 | $query_params['language_ftx'] = $language_ftx; |
| 281 | + } else { |
|
| 282 | + $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
| 271 | 283 | } |
| 272 | - else |
|
| 273 | - $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
| 274 | 284 | } |
| 275 | 285 | |
| 276 | 286 | } |