@@ -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 | * Handles showing the post screen, loading the post to be modified, and loading any post quoted. |
@@ -35,12 +36,14 @@ discard block |
||
| 35 | 36 | global $sourcedir, $smcFunc, $language; |
| 36 | 37 | |
| 37 | 38 | loadLanguage('Post'); |
| 38 | - if (!empty($modSettings['drafts_post_enabled'])) |
|
| 39 | - loadLanguage('Drafts'); |
|
| 39 | + if (!empty($modSettings['drafts_post_enabled'])) { |
|
| 40 | + loadLanguage('Drafts'); |
|
| 41 | + } |
|
| 40 | 42 | |
| 41 | 43 | // You can't reply with a poll... hacker. |
| 42 | - if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) |
|
| 43 | - unset($_REQUEST['poll']); |
|
| 44 | + if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) { |
|
| 45 | + unset($_REQUEST['poll']); |
|
| 46 | + } |
|
| 44 | 47 | |
| 45 | 48 | // Posting an event? |
| 46 | 49 | $context['make_event'] = isset($_REQUEST['calendar']); |
@@ -55,8 +58,9 @@ discard block |
||
| 55 | 58 | $context['auto_notify'] = !empty($context['notify_prefs']['msg_auto_notify']); |
| 56 | 59 | |
| 57 | 60 | // You must be posting to *some* board. |
| 58 | - if (empty($board) && !$context['make_event']) |
|
| 59 | - fatal_lang_error('no_board', false); |
|
| 61 | + if (empty($board) && !$context['make_event']) { |
|
| 62 | + fatal_lang_error('no_board', false); |
|
| 63 | + } |
|
| 60 | 64 | |
| 61 | 65 | require_once($sourcedir . '/Subs-Post.php'); |
| 62 | 66 | |
@@ -79,10 +83,11 @@ discard block |
||
| 79 | 83 | array( |
| 80 | 84 | 'msg' => (int) $_REQUEST['msg'], |
| 81 | 85 | )); |
| 82 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
| 83 | - unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']); |
|
| 84 | - else |
|
| 85 | - list ($topic) = $smcFunc['db_fetch_row']($request); |
|
| 86 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
| 87 | + unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']); |
|
| 88 | + } else { |
|
| 89 | + list ($topic) = $smcFunc['db_fetch_row']($request); |
|
| 90 | + } |
|
| 86 | 91 | $smcFunc['db_free_result']($request); |
| 87 | 92 | } |
| 88 | 93 | |
@@ -109,33 +114,36 @@ discard block |
||
| 109 | 114 | $smcFunc['db_free_result']($request); |
| 110 | 115 | |
| 111 | 116 | // If this topic already has a poll, they sure can't add another. |
| 112 | - if (isset($_REQUEST['poll']) && $pollID > 0) |
|
| 113 | - unset($_REQUEST['poll']); |
|
| 117 | + if (isset($_REQUEST['poll']) && $pollID > 0) { |
|
| 118 | + unset($_REQUEST['poll']); |
|
| 119 | + } |
|
| 114 | 120 | |
| 115 | 121 | if (empty($_REQUEST['msg'])) |
| 116 | 122 | { |
| 117 | - if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) |
|
| 118 | - is_not_guest(); |
|
| 123 | + if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) { |
|
| 124 | + is_not_guest(); |
|
| 125 | + } |
|
| 119 | 126 | |
| 120 | 127 | // By default the reply will be approved... |
| 121 | 128 | $context['becomes_approved'] = true; |
| 122 | 129 | if ($id_member_poster != $user_info['id'] || $user_info['is_guest']) |
| 123 | 130 | { |
| 124 | - if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) |
|
| 125 | - $context['becomes_approved'] = false; |
|
| 126 | - else |
|
| 127 | - isAllowedTo('post_reply_any'); |
|
| 128 | - } |
|
| 129 | - elseif (!allowedTo('post_reply_any')) |
|
| 131 | + if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) { |
|
| 132 | + $context['becomes_approved'] = false; |
|
| 133 | + } else { |
|
| 134 | + isAllowedTo('post_reply_any'); |
|
| 135 | + } |
|
| 136 | + } elseif (!allowedTo('post_reply_any')) |
|
| 130 | 137 | { |
| 131 | - if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) |
|
| 132 | - $context['becomes_approved'] = false; |
|
| 133 | - else |
|
| 134 | - isAllowedTo('post_reply_own'); |
|
| 138 | + if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) { |
|
| 139 | + $context['becomes_approved'] = false; |
|
| 140 | + } else { |
|
| 141 | + isAllowedTo('post_reply_own'); |
|
| 142 | + } |
|
| 135 | 143 | } |
| 144 | + } else { |
|
| 145 | + $context['becomes_approved'] = true; |
|
| 136 | 146 | } |
| 137 | - else |
|
| 138 | - $context['becomes_approved'] = true; |
|
| 139 | 147 | |
| 140 | 148 | $context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own')); |
| 141 | 149 | $context['can_sticky'] = allowedTo('make_sticky'); |
@@ -147,18 +155,19 @@ discard block |
||
| 147 | 155 | $context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky; |
| 148 | 156 | |
| 149 | 157 | // Check whether this is a really old post being bumped... |
| 150 | - if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) |
|
| 151 | - $post_errors[] = array('old_topic', array($modSettings['oldTopicDays'])); |
|
| 152 | - } |
|
| 153 | - else |
|
| 158 | + if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) { |
|
| 159 | + $post_errors[] = array('old_topic', array($modSettings['oldTopicDays'])); |
|
| 160 | + } |
|
| 161 | + } else |
|
| 154 | 162 | { |
| 155 | 163 | $context['becomes_approved'] = true; |
| 156 | 164 | if ((!$context['make_event'] || !empty($board))) |
| 157 | 165 | { |
| 158 | - if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) |
|
| 159 | - $context['becomes_approved'] = false; |
|
| 160 | - else |
|
| 161 | - isAllowedTo('post_new'); |
|
| 166 | + if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) { |
|
| 167 | + $context['becomes_approved'] = false; |
|
| 168 | + } else { |
|
| 169 | + isAllowedTo('post_new'); |
|
| 170 | + } |
|
| 162 | 171 | } |
| 163 | 172 | |
| 164 | 173 | $locked = 0; |
@@ -196,20 +205,24 @@ discard block |
||
| 196 | 205 | } |
| 197 | 206 | |
| 198 | 207 | // Don't allow a post if it's locked and you aren't all powerful. |
| 199 | - if ($locked && !allowedTo('moderate_board')) |
|
| 200 | - fatal_lang_error('topic_locked', false); |
|
| 208 | + if ($locked && !allowedTo('moderate_board')) { |
|
| 209 | + fatal_lang_error('topic_locked', false); |
|
| 210 | + } |
|
| 201 | 211 | // Check the users permissions - is the user allowed to add or post a poll? |
| 202 | 212 | if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1') |
| 203 | 213 | { |
| 204 | 214 | // New topic, new poll. |
| 205 | - if (empty($topic)) |
|
| 206 | - isAllowedTo('poll_post'); |
|
| 215 | + if (empty($topic)) { |
|
| 216 | + isAllowedTo('poll_post'); |
|
| 217 | + } |
|
| 207 | 218 | // This is an old topic - but it is yours! Can you add to it? |
| 208 | - elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) |
|
| 209 | - isAllowedTo('poll_add_own'); |
|
| 219 | + elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) { |
|
| 220 | + isAllowedTo('poll_add_own'); |
|
| 221 | + } |
|
| 210 | 222 | // If you're not the owner, can you add to any poll? |
| 211 | - else |
|
| 212 | - isAllowedTo('poll_add_any'); |
|
| 223 | + else { |
|
| 224 | + isAllowedTo('poll_add_any'); |
|
| 225 | + } |
|
| 213 | 226 | |
| 214 | 227 | require_once($sourcedir . '/Subs-Members.php'); |
| 215 | 228 | $allowedVoteGroups = groupsAllowedTo('poll_vote', $board); |
@@ -238,8 +251,9 @@ discard block |
||
| 238 | 251 | if ($context['make_event']) |
| 239 | 252 | { |
| 240 | 253 | // They might want to pick a board. |
| 241 | - if (!isset($context['current_board'])) |
|
| 242 | - $context['current_board'] = 0; |
|
| 254 | + if (!isset($context['current_board'])) { |
|
| 255 | + $context['current_board'] = 0; |
|
| 256 | + } |
|
| 243 | 257 | |
| 244 | 258 | // Start loading up the event info. |
| 245 | 259 | $context['event'] = array(); |
@@ -277,26 +291,28 @@ discard block |
||
| 277 | 291 | $smcFunc['db_free_result']($request); |
| 278 | 292 | |
| 279 | 293 | // Make sure the user is allowed to edit this event. |
| 280 | - if ($row['id_member'] != $user_info['id']) |
|
| 281 | - isAllowedTo('calendar_edit_any'); |
|
| 282 | - elseif (!allowedTo('calendar_edit_any')) |
|
| 283 | - isAllowedTo('calendar_edit_own'); |
|
| 294 | + if ($row['id_member'] != $user_info['id']) { |
|
| 295 | + isAllowedTo('calendar_edit_any'); |
|
| 296 | + } elseif (!allowedTo('calendar_edit_any')) { |
|
| 297 | + isAllowedTo('calendar_edit_own'); |
|
| 298 | + } |
|
| 284 | 299 | |
| 285 | 300 | $context['event']['month'] = $row['month']; |
| 286 | 301 | $context['event']['day'] = $row['day']; |
| 287 | 302 | $context['event']['year'] = $row['year']; |
| 288 | 303 | $context['event']['title'] = $row['title']; |
| 289 | 304 | $context['event']['span'] = $row['span'] + 1; |
| 290 | - } |
|
| 291 | - else |
|
| 305 | + } else |
|
| 292 | 306 | { |
| 293 | 307 | $today = getdate(); |
| 294 | 308 | |
| 295 | 309 | // You must have a month and year specified! |
| 296 | - if (!isset($_REQUEST['month'])) |
|
| 297 | - $_REQUEST['month'] = $today['mon']; |
|
| 298 | - if (!isset($_REQUEST['year'])) |
|
| 299 | - $_REQUEST['year'] = $today['year']; |
|
| 310 | + if (!isset($_REQUEST['month'])) { |
|
| 311 | + $_REQUEST['month'] = $today['mon']; |
|
| 312 | + } |
|
| 313 | + if (!isset($_REQUEST['year'])) { |
|
| 314 | + $_REQUEST['year'] = $today['year']; |
|
| 315 | + } |
|
| 300 | 316 | |
| 301 | 317 | $context['event']['month'] = (int) $_REQUEST['month']; |
| 302 | 318 | $context['event']['year'] = (int) $_REQUEST['year']; |
@@ -304,15 +320,18 @@ discard block |
||
| 304 | 320 | $context['event']['span'] = isset($_REQUEST['span']) ? $_REQUEST['span'] : 1; |
| 305 | 321 | |
| 306 | 322 | // Make sure the year and month are in the valid range. |
| 307 | - if ($context['event']['month'] < 1 || $context['event']['month'] > 12) |
|
| 308 | - fatal_lang_error('invalid_month', false); |
|
| 309 | - if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) |
|
| 310 | - fatal_lang_error('invalid_year', false); |
|
| 323 | + if ($context['event']['month'] < 1 || $context['event']['month'] > 12) { |
|
| 324 | + fatal_lang_error('invalid_month', false); |
|
| 325 | + } |
|
| 326 | + if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) { |
|
| 327 | + fatal_lang_error('invalid_year', false); |
|
| 328 | + } |
|
| 311 | 329 | |
| 312 | 330 | // Get a list of boards they can post in. |
| 313 | 331 | $boards = boardsAllowedTo('post_new'); |
| 314 | - if (empty($boards)) |
|
| 315 | - fatal_lang_error('cannot_post_new', 'user'); |
|
| 332 | + if (empty($boards)) { |
|
| 333 | + fatal_lang_error('cannot_post_new', 'user'); |
|
| 334 | + } |
|
| 316 | 335 | |
| 317 | 336 | // Load a list of boards for this event in the context. |
| 318 | 337 | require_once($sourcedir . '/Subs-MessageIndex.php'); |
@@ -357,10 +376,11 @@ discard block |
||
| 357 | 376 | |
| 358 | 377 | if (!empty($context['new_replies'])) |
| 359 | 378 | { |
| 360 | - if ($context['new_replies'] == 1) |
|
| 361 | - $txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply']; |
|
| 362 | - else |
|
| 363 | - $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']); |
|
| 379 | + if ($context['new_replies'] == 1) { |
|
| 380 | + $txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply']; |
|
| 381 | + } else { |
|
| 382 | + $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']); |
|
| 383 | + } |
|
| 364 | 384 | |
| 365 | 385 | $post_errors[] = 'new_replies'; |
| 366 | 386 | |
@@ -372,9 +392,9 @@ discard block |
||
| 372 | 392 | // Get a response prefix (like 'Re:') in the default forum language. |
| 373 | 393 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
| 374 | 394 | { |
| 375 | - if ($language === $user_info['language']) |
|
| 376 | - $context['response_prefix'] = $txt['response_prefix']; |
|
| 377 | - else |
|
| 395 | + if ($language === $user_info['language']) { |
|
| 396 | + $context['response_prefix'] = $txt['response_prefix']; |
|
| 397 | + } else |
|
| 378 | 398 | { |
| 379 | 399 | loadLanguage('index', $language, false); |
| 380 | 400 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -387,8 +407,9 @@ discard block |
||
| 387 | 407 | // Do we have a body, but an error happened. |
| 388 | 408 | if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error'])) |
| 389 | 409 | { |
| 390 | - if (isset($_REQUEST['quickReply'])) |
|
| 391 | - $_REQUEST['message'] = $_REQUEST['quickReply']; |
|
| 410 | + if (isset($_REQUEST['quickReply'])) { |
|
| 411 | + $_REQUEST['message'] = $_REQUEST['quickReply']; |
|
| 412 | + } |
|
| 392 | 413 | |
| 393 | 414 | // Validate inputs. |
| 394 | 415 | if (empty($context['post_error'])) |
@@ -396,15 +417,17 @@ discard block |
||
| 396 | 417 | // This means they didn't click Post and get an error. |
| 397 | 418 | $really_previewing = true; |
| 398 | 419 | |
| 399 | - } |
|
| 400 | - else |
|
| 420 | + } else |
|
| 401 | 421 | { |
| 402 | - if (!isset($_REQUEST['subject'])) |
|
| 403 | - $_REQUEST['subject'] = ''; |
|
| 404 | - if (!isset($_REQUEST['message'])) |
|
| 405 | - $_REQUEST['message'] = ''; |
|
| 406 | - if (!isset($_REQUEST['icon'])) |
|
| 407 | - $_REQUEST['icon'] = 'xx'; |
|
| 422 | + if (!isset($_REQUEST['subject'])) { |
|
| 423 | + $_REQUEST['subject'] = ''; |
|
| 424 | + } |
|
| 425 | + if (!isset($_REQUEST['message'])) { |
|
| 426 | + $_REQUEST['message'] = ''; |
|
| 427 | + } |
|
| 428 | + if (!isset($_REQUEST['icon'])) { |
|
| 429 | + $_REQUEST['icon'] = 'xx'; |
|
| 430 | + } |
|
| 408 | 431 | |
| 409 | 432 | // They are previewing if they asked to preview (i.e. came from quick reply). |
| 410 | 433 | $really_previewing = !empty($_POST['preview']); |
@@ -420,8 +443,9 @@ discard block |
||
| 420 | 443 | $form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES); |
| 421 | 444 | |
| 422 | 445 | // Make sure the subject isn't too long - taking into account special characters. |
| 423 | - if ($smcFunc['strlen']($form_subject) > 100) |
|
| 424 | - $form_subject = $smcFunc['substr']($form_subject, 0, 100); |
|
| 446 | + if ($smcFunc['strlen']($form_subject) > 100) { |
|
| 447 | + $form_subject = $smcFunc['substr']($form_subject, 0, 100); |
|
| 448 | + } |
|
| 425 | 449 | |
| 426 | 450 | if (isset($_REQUEST['poll'])) |
| 427 | 451 | { |
@@ -433,8 +457,9 @@ discard block |
||
| 433 | 457 | $_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']); |
| 434 | 458 | foreach ($_POST['options'] as $option) |
| 435 | 459 | { |
| 436 | - if (trim($option) == '') |
|
| 437 | - continue; |
|
| 460 | + if (trim($option) == '') { |
|
| 461 | + continue; |
|
| 462 | + } |
|
| 438 | 463 | |
| 439 | 464 | $context['choices'][] = array( |
| 440 | 465 | 'id' => $choice_id++, |
@@ -496,13 +521,14 @@ discard block |
||
| 496 | 521 | $context['preview_subject'] = $form_subject; |
| 497 | 522 | |
| 498 | 523 | censorText($context['preview_subject']); |
| 524 | + } else { |
|
| 525 | + $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>'; |
|
| 499 | 526 | } |
| 500 | - else |
|
| 501 | - $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>'; |
|
| 502 | 527 | |
| 503 | 528 | // Protect any CDATA blocks. |
| 504 | - if (isset($_REQUEST['xml'])) |
|
| 505 | - $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>')); |
|
| 529 | + if (isset($_REQUEST['xml'])) { |
|
| 530 | + $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]>< == 0) |
|
| 545 | - fatal_lang_error('no_board', false); |
|
| 570 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 571 | + fatal_lang_error('no_board', false); |
|
| 572 | + } |
|
| 546 | 573 | $row = $smcFunc['db_fetch_assoc']($request); |
| 547 | 574 | |
| 548 | 575 | $attachment_stuff = array($row); |
| 549 | - while ($row2 = $smcFunc['db_fetch_assoc']($request)) |
|
| 550 | - $attachment_stuff[] = $row2; |
|
| 576 | + while ($row2 = $smcFunc['db_fetch_assoc']($request)) { |
|
| 577 | + $attachment_stuff[] = $row2; |
|
| 578 | + } |
|
| 551 | 579 | $smcFunc['db_free_result']($request); |
| 552 | 580 | |
| 553 | 581 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
| 554 | 582 | { |
| 555 | 583 | // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public. |
| 556 | - if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
| 557 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 558 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) |
|
| 559 | - isAllowedTo('modify_replies'); |
|
| 560 | - else |
|
| 561 | - isAllowedTo('modify_own'); |
|
| 584 | + if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
| 585 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 586 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
| 587 | + isAllowedTo('modify_replies'); |
|
| 588 | + } else { |
|
| 589 | + isAllowedTo('modify_own'); |
|
| 590 | + } |
|
| 591 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) { |
|
| 592 | + isAllowedTo('modify_replies'); |
|
| 593 | + } else { |
|
| 594 | + isAllowedTo('modify_any'); |
|
| 562 | 595 | } |
| 563 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 564 | - isAllowedTo('modify_replies'); |
|
| 565 | - else |
|
| 566 | - isAllowedTo('modify_any'); |
|
| 567 | 596 | |
| 568 | 597 | if ($context['can_announce'] && !empty($row['id_action'])) |
| 569 | 598 | { |
@@ -587,8 +616,9 @@ discard block |
||
| 587 | 616 | |
| 588 | 617 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 589 | 618 | { |
| 590 | - if ($row['filesize'] <= 0) |
|
| 591 | - continue; |
|
| 619 | + if ($row['filesize'] <= 0) { |
|
| 620 | + continue; |
|
| 621 | + } |
|
| 592 | 622 | $context['current_attachments'][$row['id_attach']] = array( |
| 593 | 623 | 'name' => $smcFunc['htmlspecialchars']($row['filename']), |
| 594 | 624 | 'size' => $row['filesize'], |
@@ -658,29 +688,32 @@ discard block |
||
| 658 | 688 | ) |
| 659 | 689 | ); |
| 660 | 690 | // The message they were trying to edit was most likely deleted. |
| 661 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 662 | - fatal_lang_error('no_message', false); |
|
| 691 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 692 | + fatal_lang_error('no_message', false); |
|
| 693 | + } |
|
| 663 | 694 | $row = $smcFunc['db_fetch_assoc']($request); |
| 664 | 695 | |
| 665 | 696 | $attachment_stuff = array($row); |
| 666 | - while ($row2 = $smcFunc['db_fetch_assoc']($request)) |
|
| 667 | - $attachment_stuff[] = $row2; |
|
| 697 | + while ($row2 = $smcFunc['db_fetch_assoc']($request)) { |
|
| 698 | + $attachment_stuff[] = $row2; |
|
| 699 | + } |
|
| 668 | 700 | $smcFunc['db_free_result']($request); |
| 669 | 701 | |
| 670 | 702 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
| 671 | 703 | { |
| 672 | 704 | // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public. |
| 673 | - if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
| 674 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 675 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) |
|
| 676 | - isAllowedTo('modify_replies'); |
|
| 677 | - else |
|
| 678 | - isAllowedTo('modify_own'); |
|
| 705 | + if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
| 706 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 707 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
| 708 | + isAllowedTo('modify_replies'); |
|
| 709 | + } else { |
|
| 710 | + isAllowedTo('modify_own'); |
|
| 711 | + } |
|
| 712 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) { |
|
| 713 | + isAllowedTo('modify_replies'); |
|
| 714 | + } else { |
|
| 715 | + isAllowedTo('modify_any'); |
|
| 679 | 716 | } |
| 680 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 681 | - isAllowedTo('modify_replies'); |
|
| 682 | - else |
|
| 683 | - isAllowedTo('modify_any'); |
|
| 684 | 717 | |
| 685 | 718 | if ($context['can_announce'] && !empty($row['id_action'])) |
| 686 | 719 | { |
@@ -707,15 +740,17 @@ discard block |
||
| 707 | 740 | $context['icon'] = $row['icon']; |
| 708 | 741 | |
| 709 | 742 | // Show an "approve" box if the user can approve it, and the message isn't approved. |
| 710 | - if (!$row['approved'] && !$context['show_approval']) |
|
| 711 | - $context['show_approval'] = allowedTo('approve_posts'); |
|
| 743 | + if (!$row['approved'] && !$context['show_approval']) { |
|
| 744 | + $context['show_approval'] = allowedTo('approve_posts'); |
|
| 745 | + } |
|
| 712 | 746 | |
| 713 | 747 | // Sort the attachments so they are in the order saved |
| 714 | 748 | $temp = array(); |
| 715 | 749 | foreach ($attachment_stuff as $attachment) |
| 716 | 750 | { |
| 717 | - if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) |
|
| 718 | - $temp[$attachment['id_attach']] = $attachment; |
|
| 751 | + if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) { |
|
| 752 | + $temp[$attachment['id_attach']] = $attachment; |
|
| 753 | + } |
|
| 719 | 754 | |
| 720 | 755 | } |
| 721 | 756 | ksort($temp); |
@@ -777,14 +812,16 @@ discard block |
||
| 777 | 812 | 'is_approved' => 1, |
| 778 | 813 | ) |
| 779 | 814 | ); |
| 780 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 781 | - fatal_lang_error('quoted_post_deleted', false); |
|
| 815 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 816 | + fatal_lang_error('quoted_post_deleted', false); |
|
| 817 | + } |
|
| 782 | 818 | list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request); |
| 783 | 819 | $smcFunc['db_free_result']($request); |
| 784 | 820 | |
| 785 | 821 | // Add 'Re: ' to the front of the quoted subject. |
| 786 | - if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
|
| 787 | - $form_subject = $context['response_prefix'] . $form_subject; |
|
| 822 | + if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) { |
|
| 823 | + $form_subject = $context['response_prefix'] . $form_subject; |
|
| 824 | + } |
|
| 788 | 825 | |
| 789 | 826 | // Censor the message and subject. |
| 790 | 827 | censorText($form_message); |
@@ -797,10 +834,11 @@ discard block |
||
| 797 | 834 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
| 798 | 835 | { |
| 799 | 836 | // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat. |
| 800 | - if ($i % 4 == 0) |
|
| 801 | - $parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function ($m) |
|
| 837 | + if ($i % 4 == 0) { |
|
| 838 | + $parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function ($m) |
|
| 802 | 839 | { |
| 803 | 840 | return '[html]' . preg_replace('~<br\s?/?' . '>~i', '<br /><br>', "$m[1]") . '[/html]'; |
| 841 | + } |
|
| 804 | 842 | }, $parts[$i]); |
| 805 | 843 | } |
| 806 | 844 | $form_message = implode('', $parts); |
@@ -809,8 +847,9 @@ discard block |
||
| 809 | 847 | $form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message); |
| 810 | 848 | |
| 811 | 849 | // Remove any nested quotes, if necessary. |
| 812 | - if (!empty($modSettings['removeNestedQuotes'])) |
|
| 813 | - $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
| 850 | + if (!empty($modSettings['removeNestedQuotes'])) { |
|
| 851 | + $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
| 852 | + } |
|
| 814 | 853 | |
| 815 | 854 | // Add a quote string on the front and end. |
| 816 | 855 | $form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]'; |
@@ -822,15 +861,15 @@ discard block |
||
| 822 | 861 | $form_subject = $first_subject; |
| 823 | 862 | |
| 824 | 863 | // Add 'Re: ' to the front of the subject. |
| 825 | - if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
|
| 826 | - $form_subject = $context['response_prefix'] . $form_subject; |
|
| 864 | + if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) { |
|
| 865 | + $form_subject = $context['response_prefix'] . $form_subject; |
|
| 866 | + } |
|
| 827 | 867 | |
| 828 | 868 | // Censor the subject. |
| 829 | 869 | censorText($form_subject); |
| 830 | 870 | |
| 831 | 871 | $form_message = ''; |
| 832 | - } |
|
| 833 | - else |
|
| 872 | + } else |
|
| 834 | 873 | { |
| 835 | 874 | $form_subject = isset($_GET['subject']) ? $_GET['subject'] : ''; |
| 836 | 875 | $form_message = ''; |
@@ -848,13 +887,15 @@ discard block |
||
| 848 | 887 | if (isset($_REQUEST['msg'])) |
| 849 | 888 | { |
| 850 | 889 | $context['attachments']['quantity'] = count($context['current_attachments']); |
| 851 | - foreach ($context['current_attachments'] as $attachment) |
|
| 852 | - $context['attachments']['total_size'] += $attachment['size']; |
|
| 890 | + foreach ($context['current_attachments'] as $attachment) { |
|
| 891 | + $context['attachments']['total_size'] += $attachment['size']; |
|
| 892 | + } |
|
| 853 | 893 | } |
| 854 | 894 | |
| 855 | 895 | // A bit of house keeping first. |
| 856 | - if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) |
|
| 857 | - unset($_SESSION['temp_attachments']); |
|
| 896 | + if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) { |
|
| 897 | + unset($_SESSION['temp_attachments']); |
|
| 898 | + } |
|
| 858 | 899 | |
| 859 | 900 | if (!empty($_SESSION['temp_attachments'])) |
| 860 | 901 | { |
@@ -863,9 +904,10 @@ discard block |
||
| 863 | 904 | { |
| 864 | 905 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
| 865 | 906 | { |
| 866 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
| 867 | - if (file_exists($attachment['tmp_name'])) |
|
| 907 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) { |
|
| 908 | + if (file_exists($attachment['tmp_name'])) |
|
| 868 | 909 | unlink($attachment['tmp_name']); |
| 910 | + } |
|
| 869 | 911 | } |
| 870 | 912 | $post_errors[] = 'temp_attachments_gone'; |
| 871 | 913 | $_SESSION['temp_attachments'] = array(); |
@@ -879,8 +921,9 @@ discard block |
||
| 879 | 921 | // See if any files still exist before showing the warning message and the files attached. |
| 880 | 922 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
| 881 | 923 | { |
| 882 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
|
| 883 | - continue; |
|
| 924 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { |
|
| 925 | + continue; |
|
| 926 | + } |
|
| 884 | 927 | |
| 885 | 928 | if (file_exists($attachment['tmp_name'])) |
| 886 | 929 | { |
@@ -890,20 +933,21 @@ discard block |
||
| 890 | 933 | break; |
| 891 | 934 | } |
| 892 | 935 | } |
| 893 | - } |
|
| 894 | - else |
|
| 936 | + } else |
|
| 895 | 937 | { |
| 896 | 938 | // Since, they don't belong here. Let's inform the user that they exist.. |
| 897 | - if (!empty($topic)) |
|
| 898 | - $delete_url = $scripturl . '?action=post' .(!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp'; |
|
| 899 | - else |
|
| 900 | - $delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp'; |
|
| 939 | + if (!empty($topic)) { |
|
| 940 | + $delete_url = $scripturl . '?action=post' .(!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp'; |
|
| 941 | + } else { |
|
| 942 | + $delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp'; |
|
| 943 | + } |
|
| 901 | 944 | |
| 902 | 945 | // Compile a list of the files to show the user. |
| 903 | 946 | $file_list = array(); |
| 904 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
| 905 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
| 947 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) { |
|
| 948 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
| 906 | 949 | $file_list[] = $attachment['name']; |
| 950 | + } |
|
| 907 | 951 | |
| 908 | 952 | $_SESSION['temp_attachments']['post']['files'] = $file_list; |
| 909 | 953 | $file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>'; |
@@ -915,8 +959,7 @@ discard block |
||
| 915 | 959 | |
| 916 | 960 | $post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list)); |
| 917 | 961 | $context['ignore_temp_attachments'] = true; |
| 918 | - } |
|
| 919 | - else |
|
| 962 | + } else |
|
| 920 | 963 | { |
| 921 | 964 | $post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list)); |
| 922 | 965 | $context['ignore_temp_attachments'] = true; |
@@ -924,16 +967,19 @@ discard block |
||
| 924 | 967 | } |
| 925 | 968 | } |
| 926 | 969 | |
| 927 | - if (!empty($context['we_are_history'])) |
|
| 928 | - $post_errors[] = $context['we_are_history']; |
|
| 970 | + if (!empty($context['we_are_history'])) { |
|
| 971 | + $post_errors[] = $context['we_are_history']; |
|
| 972 | + } |
|
| 929 | 973 | |
| 930 | 974 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
| 931 | 975 | { |
| 932 | - if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) |
|
| 933 | - break; |
|
| 976 | + if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) { |
|
| 977 | + break; |
|
| 978 | + } |
|
| 934 | 979 | |
| 935 | - if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
|
| 936 | - continue; |
|
| 980 | + if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { |
|
| 981 | + continue; |
|
| 982 | + } |
|
| 937 | 983 | |
| 938 | 984 | if ($attachID == 'initial_error') |
| 939 | 985 | { |
@@ -948,15 +994,17 @@ discard block |
||
| 948 | 994 | { |
| 949 | 995 | $txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : ''; |
| 950 | 996 | $txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">'; |
| 951 | - foreach ($attachment['errors'] as $error) |
|
| 952 | - $txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >'; |
|
| 997 | + foreach ($attachment['errors'] as $error) { |
|
| 998 | + $txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >'; |
|
| 999 | + } |
|
| 953 | 1000 | $txt['error_attach_errors'] .= '</div>'; |
| 954 | 1001 | $post_errors[] = 'attach_errors'; |
| 955 | 1002 | |
| 956 | 1003 | // Take out the trash. |
| 957 | 1004 | unset($_SESSION['temp_attachments'][$attachID]); |
| 958 | - if (file_exists($attachment['tmp_name'])) |
|
| 959 | - unlink($attachment['tmp_name']); |
|
| 1005 | + if (file_exists($attachment['tmp_name'])) { |
|
| 1006 | + unlink($attachment['tmp_name']); |
|
| 1007 | + } |
|
| 960 | 1008 | continue; |
| 961 | 1009 | } |
| 962 | 1010 | |
@@ -969,8 +1017,9 @@ discard block |
||
| 969 | 1017 | |
| 970 | 1018 | $context['attachments']['quantity']++; |
| 971 | 1019 | $context['attachments']['total_size'] += $attachment['size']; |
| 972 | - if (!isset($context['files_in_session_warning'])) |
|
| 973 | - $context['files_in_session_warning'] = $txt['attached_files_in_session']; |
|
| 1020 | + if (!isset($context['files_in_session_warning'])) { |
|
| 1021 | + $context['files_in_session_warning'] = $txt['attached_files_in_session']; |
|
| 1022 | + } |
|
| 974 | 1023 | |
| 975 | 1024 | $context['current_attachments'][$attachID] = array( |
| 976 | 1025 | 'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>', |
@@ -998,8 +1047,9 @@ discard block |
||
| 998 | 1047 | } |
| 999 | 1048 | |
| 1000 | 1049 | // If they came from quick reply, and have to enter verification details, give them some notice. |
| 1001 | - if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) |
|
| 1002 | - $post_errors[] = 'need_qr_verification'; |
|
| 1050 | + if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) { |
|
| 1051 | + $post_errors[] = 'need_qr_verification'; |
|
| 1052 | + } |
|
| 1003 | 1053 | |
| 1004 | 1054 | /* |
| 1005 | 1055 | * There are two error types: serious and minor. Serious errors |
@@ -1016,52 +1066,56 @@ discard block |
||
| 1016 | 1066 | { |
| 1017 | 1067 | loadLanguage('Errors'); |
| 1018 | 1068 | $context['error_type'] = 'minor'; |
| 1019 | - foreach ($post_errors as $post_error) |
|
| 1020 | - if (is_array($post_error)) |
|
| 1069 | + foreach ($post_errors as $post_error) { |
|
| 1070 | + if (is_array($post_error)) |
|
| 1021 | 1071 | { |
| 1022 | 1072 | $post_error_id = $post_error[0]; |
| 1073 | + } |
|
| 1023 | 1074 | $context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]); |
| 1024 | 1075 | |
| 1025 | 1076 | // If it's not a minor error flag it as such. |
| 1026 | - if (!in_array($post_error_id, $minor_errors)) |
|
| 1027 | - $context['error_type'] = 'serious'; |
|
| 1028 | - } |
|
| 1029 | - else |
|
| 1077 | + if (!in_array($post_error_id, $minor_errors)) { |
|
| 1078 | + $context['error_type'] = 'serious'; |
|
| 1079 | + } |
|
| 1080 | + } else |
|
| 1030 | 1081 | { |
| 1031 | 1082 | $context['post_error'][$post_error] = $txt['error_' . $post_error]; |
| 1032 | 1083 | |
| 1033 | 1084 | // If it's not a minor error flag it as such. |
| 1034 | - if (!in_array($post_error, $minor_errors)) |
|
| 1035 | - $context['error_type'] = 'serious'; |
|
| 1085 | + if (!in_array($post_error, $minor_errors)) { |
|
| 1086 | + $context['error_type'] = 'serious'; |
|
| 1087 | + } |
|
| 1036 | 1088 | } |
| 1037 | 1089 | } |
| 1038 | 1090 | |
| 1039 | 1091 | // What are you doing? Posting a poll, modifying, previewing, new post, or reply... |
| 1040 | - if (isset($_REQUEST['poll'])) |
|
| 1041 | - $context['page_title'] = $txt['new_poll']; |
|
| 1042 | - elseif ($context['make_event']) |
|
| 1043 | - $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit']; |
|
| 1044 | - elseif (isset($_REQUEST['msg'])) |
|
| 1045 | - $context['page_title'] = $txt['modify_msg']; |
|
| 1046 | - elseif (isset($_REQUEST['subject'], $context['preview_subject'])) |
|
| 1047 | - $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']); |
|
| 1048 | - elseif (empty($topic)) |
|
| 1049 | - $context['page_title'] = $txt['start_new_topic']; |
|
| 1050 | - else |
|
| 1051 | - $context['page_title'] = $txt['post_reply']; |
|
| 1092 | + if (isset($_REQUEST['poll'])) { |
|
| 1093 | + $context['page_title'] = $txt['new_poll']; |
|
| 1094 | + } elseif ($context['make_event']) { |
|
| 1095 | + $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit']; |
|
| 1096 | + } elseif (isset($_REQUEST['msg'])) { |
|
| 1097 | + $context['page_title'] = $txt['modify_msg']; |
|
| 1098 | + } elseif (isset($_REQUEST['subject'], $context['preview_subject'])) { |
|
| 1099 | + $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']); |
|
| 1100 | + } elseif (empty($topic)) { |
|
| 1101 | + $context['page_title'] = $txt['start_new_topic']; |
|
| 1102 | + } else { |
|
| 1103 | + $context['page_title'] = $txt['post_reply']; |
|
| 1104 | + } |
|
| 1052 | 1105 | |
| 1053 | 1106 | // Build the link tree. |
| 1054 | - if (empty($topic)) |
|
| 1055 | - $context['linktree'][] = array( |
|
| 1107 | + if (empty($topic)) { |
|
| 1108 | + $context['linktree'][] = array( |
|
| 1056 | 1109 | 'name' => '<em>' . $txt['start_new_topic'] . '</em>' |
| 1057 | 1110 | ); |
| 1058 | - else |
|
| 1059 | - $context['linktree'][] = array( |
|
| 1111 | + } else { |
|
| 1112 | + $context['linktree'][] = array( |
|
| 1060 | 1113 | 'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'], |
| 1061 | 1114 | 'name' => $form_subject, |
| 1062 | 1115 | 'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>', |
| 1063 | 1116 | 'extra_after' => '<span><strong class="nav">)</strong></span>' |
| 1064 | 1117 | ); |
| 1118 | + } |
|
| 1065 | 1119 | |
| 1066 | 1120 | $context['subject'] = addcslashes($form_subject, '"'); |
| 1067 | 1121 | $context['message'] = str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), $form_message); |
@@ -1105,8 +1159,9 @@ discard block |
||
| 1105 | 1159 | // Message icons - customized icons are off? |
| 1106 | 1160 | $context['icons'] = getMessageIcons($board); |
| 1107 | 1161 | |
| 1108 | - if (!empty($context['icons'])) |
|
| 1109 | - $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
| 1162 | + if (!empty($context['icons'])) { |
|
| 1163 | + $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
| 1164 | + } |
|
| 1110 | 1165 | |
| 1111 | 1166 | // Are we starting a poll? if set the poll icon as selected if its available |
| 1112 | 1167 | if (isset($_REQUEST['poll'])) |
@@ -1126,8 +1181,9 @@ discard block |
||
| 1126 | 1181 | for ($i = 0, $n = count($context['icons']); $i < $n; $i++) |
| 1127 | 1182 | { |
| 1128 | 1183 | $context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value']; |
| 1129 | - if ($context['icons'][$i]['selected']) |
|
| 1130 | - $context['icon_url'] = $context['icons'][$i]['url']; |
|
| 1184 | + if ($context['icons'][$i]['selected']) { |
|
| 1185 | + $context['icon_url'] = $context['icons'][$i]['url']; |
|
| 1186 | + } |
|
| 1131 | 1187 | } |
| 1132 | 1188 | if (empty($context['icon_url'])) |
| 1133 | 1189 | { |
@@ -1141,8 +1197,9 @@ discard block |
||
| 1141 | 1197 | )); |
| 1142 | 1198 | } |
| 1143 | 1199 | |
| 1144 | - if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) |
|
| 1145 | - getTopic(); |
|
| 1200 | + if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) { |
|
| 1201 | + getTopic(); |
|
| 1202 | + } |
|
| 1146 | 1203 | |
| 1147 | 1204 | // If the user can post attachments prepare the warning labels. |
| 1148 | 1205 | if ($context['can_post_attachment']) |
@@ -1153,15 +1210,17 @@ discard block |
||
| 1153 | 1210 | $context['attachment_restrictions'] = array(); |
| 1154 | 1211 | $context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', ')); |
| 1155 | 1212 | $attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit'); |
| 1156 | - foreach ($attachmentRestrictionTypes as $type) |
|
| 1157 | - if (!empty($modSettings[$type])) |
|
| 1213 | + foreach ($attachmentRestrictionTypes as $type) { |
|
| 1214 | + if (!empty($modSettings[$type])) |
|
| 1158 | 1215 | { |
| 1159 | 1216 | $context['attachment_restrictions'][] = sprintf($txt['attach_restrict_' . $type . ($modSettings[$type] >= 1024 ? '_MB' : '')], comma_format($modSettings[$type], 0)); |
| 1217 | + } |
|
| 1160 | 1218 | // Show some numbers. If they exist. |
| 1161 | - if ($type == 'attachmentNumPerPostLimit' && $context['attachments']['quantity'] > 0) |
|
| 1162 | - $context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']); |
|
| 1163 | - elseif ($type == 'attachmentPostLimit' && $context['attachments']['total_size'] > 0) |
|
| 1164 | - $context['attachment_restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)), 0)); |
|
| 1219 | + if ($type == 'attachmentNumPerPostLimit' && $context['attachments']['quantity'] > 0) { |
|
| 1220 | + $context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']); |
|
| 1221 | + } elseif ($type == 'attachmentPostLimit' && $context['attachments']['total_size'] > 0) { |
|
| 1222 | + $context['attachment_restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)), 0)); |
|
| 1223 | + } |
|
| 1165 | 1224 | } |
| 1166 | 1225 | } |
| 1167 | 1226 | |
@@ -1195,8 +1254,8 @@ discard block |
||
| 1195 | 1254 | |
| 1196 | 1255 | if (!empty($context['current_attachments'])) |
| 1197 | 1256 | { |
| 1198 | - foreach ($context['current_attachments'] as $key => $mock) |
|
| 1199 | - addInlineJavaScript(' |
|
| 1257 | + foreach ($context['current_attachments'] as $key => $mock) { |
|
| 1258 | + addInlineJavaScript(' |
|
| 1200 | 1259 | current_attachments.push({ |
| 1201 | 1260 | name: '. JavaScriptEscape($mock['name']) .', |
| 1202 | 1261 | size: '. $mock['size'] .', |
@@ -1205,6 +1264,7 @@ discard block |
||
| 1205 | 1264 | type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') .', |
| 1206 | 1265 | thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) .' |
| 1207 | 1266 | });', true); |
| 1267 | + } |
|
| 1208 | 1268 | } |
| 1209 | 1269 | |
| 1210 | 1270 | // File Upload. |
@@ -1249,8 +1309,9 @@ discard block |
||
| 1249 | 1309 | var current_board = '. (empty($context['current_board']) ? 'null' : $context['current_board']) .';', false); |
| 1250 | 1310 | |
| 1251 | 1311 | // Finally, load the template. |
| 1252 | - if (!isset($_REQUEST['xml'])) |
|
| 1253 | - loadTemplate('Post'); |
|
| 1312 | + if (!isset($_REQUEST['xml'])) { |
|
| 1313 | + loadTemplate('Post'); |
|
| 1314 | + } |
|
| 1254 | 1315 | |
| 1255 | 1316 | call_integration_hook('integrate_post_end'); |
| 1256 | 1317 | } |
@@ -1271,13 +1332,14 @@ discard block |
||
| 1271 | 1332 | // Sneaking off, are we? |
| 1272 | 1333 | if (empty($_POST) && empty($topic)) |
| 1273 | 1334 | { |
| 1274 | - if (empty($_SERVER['CONTENT_LENGTH'])) |
|
| 1275 | - redirectexit('action=post;board=' . $board . '.0'); |
|
| 1276 | - else |
|
| 1277 | - fatal_lang_error('post_upload_error', false); |
|
| 1335 | + if (empty($_SERVER['CONTENT_LENGTH'])) { |
|
| 1336 | + redirectexit('action=post;board=' . $board . '.0'); |
|
| 1337 | + } else { |
|
| 1338 | + fatal_lang_error('post_upload_error', false); |
|
| 1339 | + } |
|
| 1340 | + } elseif (empty($_POST) && !empty($topic)) { |
|
| 1341 | + redirectexit('action=post;topic=' . $topic . '.0'); |
|
| 1278 | 1342 | } |
| 1279 | - elseif (empty($_POST) && !empty($topic)) |
|
| 1280 | - redirectexit('action=post;topic=' . $topic . '.0'); |
|
| 1281 | 1343 | |
| 1282 | 1344 | // No need! |
| 1283 | 1345 | $context['robot_no_index'] = true; |
@@ -1289,8 +1351,9 @@ discard block |
||
| 1289 | 1351 | $post_errors = array(); |
| 1290 | 1352 | |
| 1291 | 1353 | // If the session has timed out, let the user re-submit their form. |
| 1292 | - if (checkSession('post', '', false) != '') |
|
| 1293 | - $post_errors[] = 'session_timeout'; |
|
| 1354 | + if (checkSession('post', '', false) != '') { |
|
| 1355 | + $post_errors[] = 'session_timeout'; |
|
| 1356 | + } |
|
| 1294 | 1357 | |
| 1295 | 1358 | // Wrong verification code? |
| 1296 | 1359 | if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1))) |
@@ -1300,33 +1363,38 @@ discard block |
||
| 1300 | 1363 | 'id' => 'post', |
| 1301 | 1364 | ); |
| 1302 | 1365 | $context['require_verification'] = create_control_verification($verificationOptions, true); |
| 1303 | - if (is_array($context['require_verification'])) |
|
| 1304 | - $post_errors = array_merge($post_errors, $context['require_verification']); |
|
| 1366 | + if (is_array($context['require_verification'])) { |
|
| 1367 | + $post_errors = array_merge($post_errors, $context['require_verification']); |
|
| 1368 | + } |
|
| 1305 | 1369 | } |
| 1306 | 1370 | |
| 1307 | 1371 | require_once($sourcedir . '/Subs-Post.php'); |
| 1308 | 1372 | loadLanguage('Post'); |
| 1309 | 1373 | |
| 1310 | 1374 | // Drafts enabled and needed? |
| 1311 | - if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) |
|
| 1312 | - require_once($sourcedir . '/Drafts.php'); |
|
| 1375 | + if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) { |
|
| 1376 | + require_once($sourcedir . '/Drafts.php'); |
|
| 1377 | + } |
|
| 1313 | 1378 | |
| 1314 | 1379 | // First check to see if they are trying to delete any current attachments. |
| 1315 | 1380 | if (isset($_POST['attach_del'])) |
| 1316 | 1381 | { |
| 1317 | 1382 | $keep_temp = array(); |
| 1318 | 1383 | $keep_ids = array(); |
| 1319 | - foreach ($_POST['attach_del'] as $dummy) |
|
| 1320 | - if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false) |
|
| 1384 | + foreach ($_POST['attach_del'] as $dummy) { |
|
| 1385 | + if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false) |
|
| 1321 | 1386 | $keep_temp[] = $dummy; |
| 1322 | - else |
|
| 1323 | - $keep_ids[] = (int) $dummy; |
|
| 1387 | + } |
|
| 1388 | + else { |
|
| 1389 | + $keep_ids[] = (int) $dummy; |
|
| 1390 | + } |
|
| 1324 | 1391 | |
| 1325 | - if (isset($_SESSION['temp_attachments'])) |
|
| 1326 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
| 1392 | + if (isset($_SESSION['temp_attachments'])) { |
|
| 1393 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
| 1327 | 1394 | { |
| 1328 | 1395 | if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
| 1329 | 1396 | continue; |
| 1397 | + } |
|
| 1330 | 1398 | |
| 1331 | 1399 | unset($_SESSION['temp_attachments'][$attachID]); |
| 1332 | 1400 | unlink($attachment['tmp_name']); |
@@ -1368,24 +1436,28 @@ discard block |
||
| 1368 | 1436 | $smcFunc['db_free_result']($request); |
| 1369 | 1437 | |
| 1370 | 1438 | // Though the topic should be there, it might have vanished. |
| 1371 | - if (!is_array($topic_info)) |
|
| 1372 | - fatal_lang_error('topic_doesnt_exist', 404); |
|
| 1439 | + if (!is_array($topic_info)) { |
|
| 1440 | + fatal_lang_error('topic_doesnt_exist', 404); |
|
| 1441 | + } |
|
| 1373 | 1442 | |
| 1374 | 1443 | // Did this topic suddenly move? Just checking... |
| 1375 | - if ($topic_info['id_board'] != $board) |
|
| 1376 | - fatal_lang_error('not_a_topic'); |
|
| 1444 | + if ($topic_info['id_board'] != $board) { |
|
| 1445 | + fatal_lang_error('not_a_topic'); |
|
| 1446 | + } |
|
| 1377 | 1447 | } |
| 1378 | 1448 | |
| 1379 | 1449 | // Replying to a topic? |
| 1380 | 1450 | if (!empty($topic) && !isset($_REQUEST['msg'])) |
| 1381 | 1451 | { |
| 1382 | 1452 | // Don't allow a post if it's locked. |
| 1383 | - if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) |
|
| 1384 | - fatal_lang_error('topic_locked', false); |
|
| 1453 | + if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) { |
|
| 1454 | + fatal_lang_error('topic_locked', false); |
|
| 1455 | + } |
|
| 1385 | 1456 | |
| 1386 | 1457 | // Sorry, multiple polls aren't allowed... yet. You should stop giving me ideas :P. |
| 1387 | - if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) |
|
| 1388 | - unset($_REQUEST['poll']); |
|
| 1458 | + if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) { |
|
| 1459 | + unset($_REQUEST['poll']); |
|
| 1460 | + } |
|
| 1389 | 1461 | |
| 1390 | 1462 | // Do the permissions and approval stuff... |
| 1391 | 1463 | $becomesApproved = true; |
@@ -1401,44 +1473,43 @@ discard block |
||
| 1401 | 1473 | |
| 1402 | 1474 | // Set a nice session var... |
| 1403 | 1475 | $_SESSION['becomesUnapproved'] = true; |
| 1404 | - } |
|
| 1405 | - |
|
| 1406 | - elseif ($topic_info['id_member_started'] != $user_info['id']) |
|
| 1476 | + } elseif ($topic_info['id_member_started'] != $user_info['id']) |
|
| 1407 | 1477 | { |
| 1408 | - if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) |
|
| 1409 | - $becomesApproved = false; |
|
| 1410 | - |
|
| 1411 | - else |
|
| 1412 | - isAllowedTo('post_reply_any'); |
|
| 1413 | - } |
|
| 1414 | - elseif (!allowedTo('post_reply_any')) |
|
| 1478 | + if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) { |
|
| 1479 | + $becomesApproved = false; |
|
| 1480 | + } else { |
|
| 1481 | + isAllowedTo('post_reply_any'); |
|
| 1482 | + } |
|
| 1483 | + } elseif (!allowedTo('post_reply_any')) |
|
| 1415 | 1484 | { |
| 1416 | - if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) |
|
| 1417 | - $becomesApproved = false; |
|
| 1418 | - |
|
| 1419 | - else |
|
| 1420 | - isAllowedTo('post_reply_own'); |
|
| 1485 | + if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) { |
|
| 1486 | + $becomesApproved = false; |
|
| 1487 | + } else { |
|
| 1488 | + isAllowedTo('post_reply_own'); |
|
| 1489 | + } |
|
| 1421 | 1490 | } |
| 1422 | 1491 | |
| 1423 | 1492 | if (isset($_POST['lock'])) |
| 1424 | 1493 | { |
| 1425 | 1494 | // Nothing is changed to the lock. |
| 1426 | - if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) |
|
| 1427 | - unset($_POST['lock']); |
|
| 1495 | + if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) { |
|
| 1496 | + unset($_POST['lock']); |
|
| 1497 | + } |
|
| 1428 | 1498 | |
| 1429 | 1499 | // You're have no permission to lock this topic. |
| 1430 | - elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) |
|
| 1431 | - unset($_POST['lock']); |
|
| 1500 | + elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) { |
|
| 1501 | + unset($_POST['lock']); |
|
| 1502 | + } |
|
| 1432 | 1503 | |
| 1433 | 1504 | // You are allowed to (un)lock your own topic only. |
| 1434 | 1505 | elseif (!allowedTo('lock_any')) |
| 1435 | 1506 | { |
| 1436 | 1507 | // You cannot override a moderator lock. |
| 1437 | - if ($topic_info['locked'] == 1) |
|
| 1438 | - unset($_POST['lock']); |
|
| 1439 | - |
|
| 1440 | - else |
|
| 1441 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 1508 | + if ($topic_info['locked'] == 1) { |
|
| 1509 | + unset($_POST['lock']); |
|
| 1510 | + } else { |
|
| 1511 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 1512 | + } |
|
| 1442 | 1513 | } |
| 1443 | 1514 | // Hail mighty moderator, (un)lock this topic immediately. |
| 1444 | 1515 | else |
@@ -1446,19 +1517,21 @@ discard block |
||
| 1446 | 1517 | $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
| 1447 | 1518 | |
| 1448 | 1519 | // Did someone (un)lock this while you were posting? |
| 1449 | - if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) |
|
| 1450 | - $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
| 1520 | + if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) { |
|
| 1521 | + $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
| 1522 | + } |
|
| 1451 | 1523 | } |
| 1452 | 1524 | } |
| 1453 | 1525 | |
| 1454 | 1526 | // So you wanna (un)sticky this...let's see. |
| 1455 | - if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) |
|
| 1456 | - unset($_POST['sticky']); |
|
| 1457 | - elseif (isset($_POST['sticky'])) |
|
| 1527 | + if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) { |
|
| 1528 | + unset($_POST['sticky']); |
|
| 1529 | + } elseif (isset($_POST['sticky'])) |
|
| 1458 | 1530 | { |
| 1459 | 1531 | // Did someone (un)sticky this while you were posting? |
| 1460 | - if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) |
|
| 1461 | - $post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky'; |
|
| 1532 | + if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) { |
|
| 1533 | + $post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky'; |
|
| 1534 | + } |
|
| 1462 | 1535 | } |
| 1463 | 1536 | |
| 1464 | 1537 | // If drafts are enabled, then pass this off |
@@ -1485,26 +1558,31 @@ discard block |
||
| 1485 | 1558 | |
| 1486 | 1559 | // Do like, the permissions, for safety and stuff... |
| 1487 | 1560 | $becomesApproved = true; |
| 1488 | - if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) |
|
| 1489 | - $becomesApproved = false; |
|
| 1490 | - else |
|
| 1491 | - isAllowedTo('post_new'); |
|
| 1561 | + if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) { |
|
| 1562 | + $becomesApproved = false; |
|
| 1563 | + } else { |
|
| 1564 | + isAllowedTo('post_new'); |
|
| 1565 | + } |
|
| 1492 | 1566 | |
| 1493 | 1567 | if (isset($_POST['lock'])) |
| 1494 | 1568 | { |
| 1495 | 1569 | // New topics are by default not locked. |
| 1496 | - if (empty($_POST['lock'])) |
|
| 1497 | - unset($_POST['lock']); |
|
| 1570 | + if (empty($_POST['lock'])) { |
|
| 1571 | + unset($_POST['lock']); |
|
| 1572 | + } |
|
| 1498 | 1573 | // Besides, you need permission. |
| 1499 | - elseif (!allowedTo(array('lock_any', 'lock_own'))) |
|
| 1500 | - unset($_POST['lock']); |
|
| 1574 | + elseif (!allowedTo(array('lock_any', 'lock_own'))) { |
|
| 1575 | + unset($_POST['lock']); |
|
| 1576 | + } |
|
| 1501 | 1577 | // A moderator-lock (1) can override a user-lock (2). |
| 1502 | - else |
|
| 1503 | - $_POST['lock'] = allowedTo('lock_any') ? 1 : 2; |
|
| 1578 | + else { |
|
| 1579 | + $_POST['lock'] = allowedTo('lock_any') ? 1 : 2; |
|
| 1580 | + } |
|
| 1504 | 1581 | } |
| 1505 | 1582 | |
| 1506 | - if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) |
|
| 1507 | - unset($_POST['sticky']); |
|
| 1583 | + if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) { |
|
| 1584 | + unset($_POST['sticky']); |
|
| 1585 | + } |
|
| 1508 | 1586 | |
| 1509 | 1587 | // Saving your new topic as a draft first? |
| 1510 | 1588 | if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft'])) |
@@ -1529,31 +1607,37 @@ discard block |
||
| 1529 | 1607 | 'id_msg' => $_REQUEST['msg'], |
| 1530 | 1608 | ) |
| 1531 | 1609 | ); |
| 1532 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1533 | - fatal_lang_error('cant_find_messages', false); |
|
| 1610 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1611 | + fatal_lang_error('cant_find_messages', false); |
|
| 1612 | + } |
|
| 1534 | 1613 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1535 | 1614 | $smcFunc['db_free_result']($request); |
| 1536 | 1615 | |
| 1537 | - if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) |
|
| 1538 | - fatal_lang_error('topic_locked', false); |
|
| 1616 | + if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) { |
|
| 1617 | + fatal_lang_error('topic_locked', false); |
|
| 1618 | + } |
|
| 1539 | 1619 | |
| 1540 | 1620 | if (isset($_POST['lock'])) |
| 1541 | 1621 | { |
| 1542 | 1622 | // Nothing changes to the lock status. |
| 1543 | - if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) |
|
| 1544 | - unset($_POST['lock']); |
|
| 1623 | + if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) { |
|
| 1624 | + unset($_POST['lock']); |
|
| 1625 | + } |
|
| 1545 | 1626 | // You're simply not allowed to (un)lock this. |
| 1546 | - elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) |
|
| 1547 | - unset($_POST['lock']); |
|
| 1627 | + elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) { |
|
| 1628 | + unset($_POST['lock']); |
|
| 1629 | + } |
|
| 1548 | 1630 | // You're only allowed to lock your own topics. |
| 1549 | 1631 | elseif (!allowedTo('lock_any')) |
| 1550 | 1632 | { |
| 1551 | 1633 | // You're not allowed to break a moderator's lock. |
| 1552 | - if ($topic_info['locked'] == 1) |
|
| 1553 | - unset($_POST['lock']); |
|
| 1634 | + if ($topic_info['locked'] == 1) { |
|
| 1635 | + unset($_POST['lock']); |
|
| 1636 | + } |
|
| 1554 | 1637 | // Lock it with a soft lock or unlock it. |
| 1555 | - else |
|
| 1556 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 1638 | + else { |
|
| 1639 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 1640 | + } |
|
| 1557 | 1641 | } |
| 1558 | 1642 | // You must be the moderator. |
| 1559 | 1643 | else |
@@ -1561,44 +1645,46 @@ discard block |
||
| 1561 | 1645 | $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
| 1562 | 1646 | |
| 1563 | 1647 | // Did someone (un)lock this while you were posting? |
| 1564 | - if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) |
|
| 1565 | - $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
| 1648 | + if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) { |
|
| 1649 | + $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
| 1650 | + } |
|
| 1566 | 1651 | } |
| 1567 | 1652 | } |
| 1568 | 1653 | |
| 1569 | 1654 | // Change the sticky status of this topic? |
| 1570 | - if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) |
|
| 1571 | - unset($_POST['sticky']); |
|
| 1572 | - elseif (isset($_POST['sticky'])) |
|
| 1655 | + if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) { |
|
| 1656 | + unset($_POST['sticky']); |
|
| 1657 | + } elseif (isset($_POST['sticky'])) |
|
| 1573 | 1658 | { |
| 1574 | 1659 | // Did someone (un)sticky this while you were posting? |
| 1575 | - if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) |
|
| 1576 | - $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied'; |
|
| 1660 | + if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) { |
|
| 1661 | + $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied'; |
|
| 1662 | + } |
|
| 1577 | 1663 | } |
| 1578 | 1664 | |
| 1579 | 1665 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
| 1580 | 1666 | { |
| 1581 | - if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
| 1582 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 1583 | - elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) |
|
| 1584 | - isAllowedTo('modify_replies'); |
|
| 1585 | - else |
|
| 1586 | - isAllowedTo('modify_own'); |
|
| 1587 | - } |
|
| 1588 | - elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 1667 | + if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
| 1668 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 1669 | + } elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
| 1670 | + isAllowedTo('modify_replies'); |
|
| 1671 | + } else { |
|
| 1672 | + isAllowedTo('modify_own'); |
|
| 1673 | + } |
|
| 1674 | + } elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 1589 | 1675 | { |
| 1590 | 1676 | isAllowedTo('modify_replies'); |
| 1591 | 1677 | |
| 1592 | 1678 | // If you're modifying a reply, I say it better be logged... |
| 1593 | 1679 | $moderationAction = true; |
| 1594 | - } |
|
| 1595 | - else |
|
| 1680 | + } else |
|
| 1596 | 1681 | { |
| 1597 | 1682 | isAllowedTo('modify_any'); |
| 1598 | 1683 | |
| 1599 | 1684 | // Log it, assuming you're not modifying your own post. |
| 1600 | - if ($row['id_member'] != $user_info['id']) |
|
| 1601 | - $moderationAction = true; |
|
| 1685 | + if ($row['id_member'] != $user_info['id']) { |
|
| 1686 | + $moderationAction = true; |
|
| 1687 | + } |
|
| 1602 | 1688 | } |
| 1603 | 1689 | |
| 1604 | 1690 | // If drafts are enabled, then lets send this off to save |
@@ -1635,20 +1721,24 @@ discard block |
||
| 1635 | 1721 | $_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']); |
| 1636 | 1722 | $_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']); |
| 1637 | 1723 | |
| 1638 | - if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') |
|
| 1639 | - $post_errors[] = 'no_name'; |
|
| 1640 | - if ($smcFunc['strlen']($_POST['guestname']) > 25) |
|
| 1641 | - $post_errors[] = 'long_name'; |
|
| 1724 | + if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') { |
|
| 1725 | + $post_errors[] = 'no_name'; |
|
| 1726 | + } |
|
| 1727 | + if ($smcFunc['strlen']($_POST['guestname']) > 25) { |
|
| 1728 | + $post_errors[] = 'long_name'; |
|
| 1729 | + } |
|
| 1642 | 1730 | |
| 1643 | 1731 | if (empty($modSettings['guest_post_no_email'])) |
| 1644 | 1732 | { |
| 1645 | 1733 | // Only check if they changed it! |
| 1646 | 1734 | if (!isset($row) || $row['poster_email'] != $_POST['email']) |
| 1647 | 1735 | { |
| 1648 | - if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) |
|
| 1649 | - $post_errors[] = 'no_email'; |
|
| 1650 | - if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) |
|
| 1651 | - $post_errors[] = 'bad_email'; |
|
| 1736 | + if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) { |
|
| 1737 | + $post_errors[] = 'no_email'; |
|
| 1738 | + } |
|
| 1739 | + if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { |
|
| 1740 | + $post_errors[] = 'bad_email'; |
|
| 1741 | + } |
|
| 1652 | 1742 | } |
| 1653 | 1743 | |
| 1654 | 1744 | // Now make sure this email address is not banned from posting. |
@@ -1664,75 +1754,89 @@ discard block |
||
| 1664 | 1754 | } |
| 1665 | 1755 | |
| 1666 | 1756 | // Coming from the quickReply? |
| 1667 | - if(isset($_POST['quickReply'])) |
|
| 1668 | - $_POST['message'] = $_POST['quickReply']; |
|
| 1757 | + if(isset($_POST['quickReply'])) { |
|
| 1758 | + $_POST['message'] = $_POST['quickReply']; |
|
| 1759 | + } |
|
| 1669 | 1760 | |
| 1670 | 1761 | // Check the subject and message. |
| 1671 | - if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') |
|
| 1672 | - $post_errors[] = 'no_subject'; |
|
| 1673 | - if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') |
|
| 1674 | - $post_errors[] = 'no_message'; |
|
| 1675 | - elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) |
|
| 1676 | - $post_errors[] = array('long_message', array($modSettings['max_messageLength'])); |
|
| 1677 | - else |
|
| 1762 | + if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') { |
|
| 1763 | + $post_errors[] = 'no_subject'; |
|
| 1764 | + } |
|
| 1765 | + if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') { |
|
| 1766 | + $post_errors[] = 'no_message'; |
|
| 1767 | + } elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) { |
|
| 1768 | + $post_errors[] = array('long_message', array($modSettings['max_messageLength'])); |
|
| 1769 | + } else |
|
| 1678 | 1770 | { |
| 1679 | 1771 | // Prepare the message a bit for some additional testing. |
| 1680 | 1772 | $_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES); |
| 1681 | 1773 | |
| 1682 | 1774 | // Preparse code. (Zef) |
| 1683 | - if ($user_info['is_guest']) |
|
| 1684 | - $user_info['name'] = $_POST['guestname']; |
|
| 1775 | + if ($user_info['is_guest']) { |
|
| 1776 | + $user_info['name'] = $_POST['guestname']; |
|
| 1777 | + } |
|
| 1685 | 1778 | preparsecode($_POST['message']); |
| 1686 | 1779 | |
| 1687 | 1780 | // Let's see if there's still some content left without the tags. |
| 1688 | - if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) |
|
| 1689 | - $post_errors[] = 'no_message'; |
|
| 1781 | + if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) { |
|
| 1782 | + $post_errors[] = 'no_message'; |
|
| 1783 | + } |
|
| 1784 | + } |
|
| 1785 | + if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') { |
|
| 1786 | + $post_errors[] = 'no_event'; |
|
| 1690 | 1787 | } |
| 1691 | - if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') |
|
| 1692 | - $post_errors[] = 'no_event'; |
|
| 1693 | 1788 | // You are not! |
| 1694 | - if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) |
|
| 1695 | - fatal_error('Knave! Masquerader! Charlatan!', false); |
|
| 1789 | + if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) { |
|
| 1790 | + fatal_error('Knave! Masquerader! Charlatan!', false); |
|
| 1791 | + } |
|
| 1696 | 1792 | |
| 1697 | 1793 | // Validate the poll... |
| 1698 | 1794 | if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1') |
| 1699 | 1795 | { |
| 1700 | - if (!empty($topic) && !isset($_REQUEST['msg'])) |
|
| 1701 | - fatal_lang_error('no_access', false); |
|
| 1796 | + if (!empty($topic) && !isset($_REQUEST['msg'])) { |
|
| 1797 | + fatal_lang_error('no_access', false); |
|
| 1798 | + } |
|
| 1702 | 1799 | |
| 1703 | 1800 | // This is a new topic... so it's a new poll. |
| 1704 | - if (empty($topic)) |
|
| 1705 | - isAllowedTo('poll_post'); |
|
| 1801 | + if (empty($topic)) { |
|
| 1802 | + isAllowedTo('poll_post'); |
|
| 1803 | + } |
|
| 1706 | 1804 | // Can you add to your own topics? |
| 1707 | - elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) |
|
| 1708 | - isAllowedTo('poll_add_own'); |
|
| 1805 | + elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) { |
|
| 1806 | + isAllowedTo('poll_add_own'); |
|
| 1807 | + } |
|
| 1709 | 1808 | // Can you add polls to any topic, then? |
| 1710 | - else |
|
| 1711 | - isAllowedTo('poll_add_any'); |
|
| 1809 | + else { |
|
| 1810 | + isAllowedTo('poll_add_any'); |
|
| 1811 | + } |
|
| 1712 | 1812 | |
| 1713 | - if (!isset($_POST['question']) || trim($_POST['question']) == '') |
|
| 1714 | - $post_errors[] = 'no_question'; |
|
| 1813 | + if (!isset($_POST['question']) || trim($_POST['question']) == '') { |
|
| 1814 | + $post_errors[] = 'no_question'; |
|
| 1815 | + } |
|
| 1715 | 1816 | |
| 1716 | 1817 | $_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']); |
| 1717 | 1818 | |
| 1718 | 1819 | // Get rid of empty ones. |
| 1719 | - foreach ($_POST['options'] as $k => $option) |
|
| 1720 | - if ($option == '') |
|
| 1820 | + foreach ($_POST['options'] as $k => $option) { |
|
| 1821 | + if ($option == '') |
|
| 1721 | 1822 | unset($_POST['options'][$k], $_POST['options'][$k]); |
| 1823 | + } |
|
| 1722 | 1824 | |
| 1723 | 1825 | // What are you going to vote between with one choice?!? |
| 1724 | - if (count($_POST['options']) < 2) |
|
| 1725 | - $post_errors[] = 'poll_few'; |
|
| 1726 | - elseif (count($_POST['options']) > 256) |
|
| 1727 | - $post_errors[] = 'poll_many'; |
|
| 1826 | + if (count($_POST['options']) < 2) { |
|
| 1827 | + $post_errors[] = 'poll_few'; |
|
| 1828 | + } elseif (count($_POST['options']) > 256) { |
|
| 1829 | + $post_errors[] = 'poll_many'; |
|
| 1830 | + } |
|
| 1728 | 1831 | } |
| 1729 | 1832 | |
| 1730 | 1833 | if ($posterIsGuest) |
| 1731 | 1834 | { |
| 1732 | 1835 | // If user is a guest, make sure the chosen name isn't taken. |
| 1733 | 1836 | require_once($sourcedir . '/Subs-Members.php'); |
| 1734 | - if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) |
|
| 1735 | - $post_errors[] = 'bad_name'; |
|
| 1837 | + if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) { |
|
| 1838 | + $post_errors[] = 'bad_name'; |
|
| 1839 | + } |
|
| 1736 | 1840 | } |
| 1737 | 1841 | // If the user isn't a guest, get his or her name and email. |
| 1738 | 1842 | elseif (!isset($_REQUEST['msg'])) |
@@ -1763,8 +1867,9 @@ discard block |
||
| 1763 | 1867 | } |
| 1764 | 1868 | |
| 1765 | 1869 | // Make sure the user isn't spamming the board. |
| 1766 | - if (!isset($_REQUEST['msg'])) |
|
| 1767 | - spamProtection('post'); |
|
| 1870 | + if (!isset($_REQUEST['msg'])) { |
|
| 1871 | + spamProtection('post'); |
|
| 1872 | + } |
|
| 1768 | 1873 | |
| 1769 | 1874 | // At about this point, we're posting and that's that. |
| 1770 | 1875 | ignore_user_abort(true); |
@@ -1777,32 +1882,36 @@ discard block |
||
| 1777 | 1882 | $_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => '')); |
| 1778 | 1883 | |
| 1779 | 1884 | // At this point, we want to make sure the subject isn't too long. |
| 1780 | - if ($smcFunc['strlen']($_POST['subject']) > 100) |
|
| 1781 | - $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
| 1885 | + if ($smcFunc['strlen']($_POST['subject']) > 100) { |
|
| 1886 | + $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
| 1887 | + } |
|
| 1782 | 1888 | |
| 1783 | 1889 | // Same with the "why did you edit this" text. |
| 1784 | - if ($smcFunc['strlen']($_POST['modify_reason']) > 100) |
|
| 1785 | - $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
| 1890 | + if ($smcFunc['strlen']($_POST['modify_reason']) > 100) { |
|
| 1891 | + $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
| 1892 | + } |
|
| 1786 | 1893 | |
| 1787 | 1894 | // Make the poll... |
| 1788 | 1895 | if (isset($_REQUEST['poll'])) |
| 1789 | 1896 | { |
| 1790 | 1897 | // Make sure that the user has not entered a ridiculous number of options.. |
| 1791 | - if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) |
|
| 1792 | - $_POST['poll_max_votes'] = 1; |
|
| 1793 | - elseif ($_POST['poll_max_votes'] > count($_POST['options'])) |
|
| 1794 | - $_POST['poll_max_votes'] = count($_POST['options']); |
|
| 1795 | - else |
|
| 1796 | - $_POST['poll_max_votes'] = (int) $_POST['poll_max_votes']; |
|
| 1898 | + if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) { |
|
| 1899 | + $_POST['poll_max_votes'] = 1; |
|
| 1900 | + } elseif ($_POST['poll_max_votes'] > count($_POST['options'])) { |
|
| 1901 | + $_POST['poll_max_votes'] = count($_POST['options']); |
|
| 1902 | + } else { |
|
| 1903 | + $_POST['poll_max_votes'] = (int) $_POST['poll_max_votes']; |
|
| 1904 | + } |
|
| 1797 | 1905 | |
| 1798 | 1906 | $_POST['poll_expire'] = (int) $_POST['poll_expire']; |
| 1799 | 1907 | $_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']); |
| 1800 | 1908 | |
| 1801 | 1909 | // Just set it to zero if it's not there.. |
| 1802 | - if (!isset($_POST['poll_hide'])) |
|
| 1803 | - $_POST['poll_hide'] = 0; |
|
| 1804 | - else |
|
| 1805 | - $_POST['poll_hide'] = (int) $_POST['poll_hide']; |
|
| 1910 | + if (!isset($_POST['poll_hide'])) { |
|
| 1911 | + $_POST['poll_hide'] = 0; |
|
| 1912 | + } else { |
|
| 1913 | + $_POST['poll_hide'] = (int) $_POST['poll_hide']; |
|
| 1914 | + } |
|
| 1806 | 1915 | $_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0; |
| 1807 | 1916 | |
| 1808 | 1917 | $_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0; |
@@ -1811,16 +1920,19 @@ discard block |
||
| 1811 | 1920 | { |
| 1812 | 1921 | require_once($sourcedir . '/Subs-Members.php'); |
| 1813 | 1922 | $allowedVoteGroups = groupsAllowedTo('poll_vote', $board); |
| 1814 | - if (!in_array(-1, $allowedVoteGroups['allowed'])) |
|
| 1815 | - $_POST['poll_guest_vote'] = 0; |
|
| 1923 | + if (!in_array(-1, $allowedVoteGroups['allowed'])) { |
|
| 1924 | + $_POST['poll_guest_vote'] = 0; |
|
| 1925 | + } |
|
| 1816 | 1926 | } |
| 1817 | 1927 | |
| 1818 | 1928 | // If the user tries to set the poll too far in advance, don't let them. |
| 1819 | - if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) |
|
| 1820 | - fatal_lang_error('poll_range_error', false); |
|
| 1929 | + if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) { |
|
| 1930 | + fatal_lang_error('poll_range_error', false); |
|
| 1931 | + } |
|
| 1821 | 1932 | // Don't allow them to select option 2 for hidden results if it's not time limited. |
| 1822 | - elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) |
|
| 1823 | - $_POST['poll_hide'] = 1; |
|
| 1933 | + elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) { |
|
| 1934 | + $_POST['poll_hide'] = 1; |
|
| 1935 | + } |
|
| 1824 | 1936 | |
| 1825 | 1937 | // Clean up the question and answers. |
| 1826 | 1938 | $_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']); |
@@ -1834,13 +1946,15 @@ discard block |
||
| 1834 | 1946 | { |
| 1835 | 1947 | $attachIDs = array(); |
| 1836 | 1948 | $attach_errors = array(); |
| 1837 | - if (!empty($context['we_are_history'])) |
|
| 1838 | - $attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>'; |
|
| 1949 | + if (!empty($context['we_are_history'])) { |
|
| 1950 | + $attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>'; |
|
| 1951 | + } |
|
| 1839 | 1952 | |
| 1840 | 1953 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
| 1841 | 1954 | { |
| 1842 | - if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
|
| 1843 | - continue; |
|
| 1955 | + if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { |
|
| 1956 | + continue; |
|
| 1957 | + } |
|
| 1844 | 1958 | |
| 1845 | 1959 | // If there was an initial error just show that message. |
| 1846 | 1960 | if ($attachID == 'initial_error') |
@@ -1869,12 +1983,13 @@ discard block |
||
| 1869 | 1983 | if (createAttachment($attachmentOptions)) |
| 1870 | 1984 | { |
| 1871 | 1985 | $attachIDs[] = $attachmentOptions['id']; |
| 1872 | - if (!empty($attachmentOptions['thumb'])) |
|
| 1873 | - $attachIDs[] = $attachmentOptions['thumb']; |
|
| 1986 | + if (!empty($attachmentOptions['thumb'])) { |
|
| 1987 | + $attachIDs[] = $attachmentOptions['thumb']; |
|
| 1988 | + } |
|
| 1874 | 1989 | } |
| 1990 | + } else { |
|
| 1991 | + $attach_errors[] = '<dt> </dt>'; |
|
| 1875 | 1992 | } |
| 1876 | - else |
|
| 1877 | - $attach_errors[] = '<dt> </dt>'; |
|
| 1878 | 1993 | |
| 1879 | 1994 | if (!empty($attachmentOptions['errors'])) |
| 1880 | 1995 | { |
@@ -1886,14 +2001,16 @@ discard block |
||
| 1886 | 2001 | if (!is_array($error)) |
| 1887 | 2002 | { |
| 1888 | 2003 | $attach_errors[] = '<dd>' . $txt[$error] . '</dd>'; |
| 1889 | - if (in_array($error, $log_these)) |
|
| 1890 | - log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
| 2004 | + if (in_array($error, $log_these)) { |
|
| 2005 | + log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
| 2006 | + } |
|
| 2007 | + } else { |
|
| 2008 | + $attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>'; |
|
| 1891 | 2009 | } |
| 1892 | - else |
|
| 1893 | - $attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>'; |
|
| 1894 | 2010 | } |
| 1895 | - if (file_exists($attachment['tmp_name'])) |
|
| 1896 | - unlink($attachment['tmp_name']); |
|
| 2011 | + if (file_exists($attachment['tmp_name'])) { |
|
| 2012 | + unlink($attachment['tmp_name']); |
|
| 2013 | + } |
|
| 1897 | 2014 | } |
| 1898 | 2015 | } |
| 1899 | 2016 | unset($_SESSION['temp_attachments']); |
@@ -1934,24 +2051,24 @@ discard block |
||
| 1934 | 2051 | ); |
| 1935 | 2052 | |
| 1936 | 2053 | call_integration_hook('integrate_poll_add_edit', array($id_poll, false)); |
| 2054 | + } else { |
|
| 2055 | + $id_poll = 0; |
|
| 1937 | 2056 | } |
| 1938 | - else |
|
| 1939 | - $id_poll = 0; |
|
| 1940 | 2057 | |
| 1941 | 2058 | // Creating a new topic? |
| 1942 | 2059 | $newTopic = empty($_REQUEST['msg']) && empty($topic); |
| 1943 | 2060 | |
| 1944 | 2061 | // Check the icon. |
| 1945 | - if (!isset($_POST['icon'])) |
|
| 1946 | - $_POST['icon'] = 'xx'; |
|
| 1947 | - |
|
| 1948 | - else |
|
| 2062 | + if (!isset($_POST['icon'])) { |
|
| 2063 | + $_POST['icon'] = 'xx'; |
|
| 2064 | + } else |
|
| 1949 | 2065 | { |
| 1950 | 2066 | $_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']); |
| 1951 | 2067 | |
| 1952 | 2068 | // Need to figure it out if this is a valid icon name. |
| 1953 | - if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) |
|
| 1954 | - $_POST['icon'] = 'xx'; |
|
| 2069 | + if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) { |
|
| 2070 | + $_POST['icon'] = 'xx'; |
|
| 2071 | + } |
|
| 1955 | 2072 | } |
| 1956 | 2073 | |
| 1957 | 2074 | // Collect all parameters for the creation or modification of a post. |
@@ -1992,8 +2109,9 @@ discard block |
||
| 1992 | 2109 | } |
| 1993 | 2110 | |
| 1994 | 2111 | // This will save some time... |
| 1995 | - if (empty($approve_has_changed)) |
|
| 1996 | - unset($msgOptions['approved']); |
|
| 2112 | + if (empty($approve_has_changed)) { |
|
| 2113 | + unset($msgOptions['approved']); |
|
| 2114 | + } |
|
| 1997 | 2115 | |
| 1998 | 2116 | modifyPost($msgOptions, $topicOptions, $posterOptions); |
| 1999 | 2117 | } |
@@ -2002,8 +2120,9 @@ discard block |
||
| 2002 | 2120 | { |
| 2003 | 2121 | createPost($msgOptions, $topicOptions, $posterOptions); |
| 2004 | 2122 | |
| 2005 | - if (isset($topicOptions['id'])) |
|
| 2006 | - $topic = $topicOptions['id']; |
|
| 2123 | + if (isset($topicOptions['id'])) { |
|
| 2124 | + $topic = $topicOptions['id']; |
|
| 2125 | + } |
|
| 2007 | 2126 | } |
| 2008 | 2127 | |
| 2009 | 2128 | // Assign the previously uploaded attachments to the brand new message. |
@@ -2015,8 +2134,9 @@ discard block |
||
| 2015 | 2134 | } |
| 2016 | 2135 | |
| 2017 | 2136 | // If we had a draft for this, its time to remove it since it was just posted |
| 2018 | - if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) |
|
| 2019 | - DeleteDraft($_POST['id_draft']); |
|
| 2137 | + if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) { |
|
| 2138 | + DeleteDraft($_POST['id_draft']); |
|
| 2139 | + } |
|
| 2020 | 2140 | |
| 2021 | 2141 | // Editing or posting an event? |
| 2022 | 2142 | if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1)) |
@@ -2036,8 +2156,7 @@ discard block |
||
| 2036 | 2156 | 'span' => isset($_POST['span']) && $_POST['span'] > 0 ? min((int) $modSettings['cal_maxspan'], (int) $_POST['span'] - 1) : 0, |
| 2037 | 2157 | ); |
| 2038 | 2158 | insertEvent($eventOptions); |
| 2039 | - } |
|
| 2040 | - elseif (isset($_POST['calendar'])) |
|
| 2159 | + } elseif (isset($_POST['calendar'])) |
|
| 2041 | 2160 | { |
| 2042 | 2161 | $_REQUEST['eventid'] = (int) $_REQUEST['eventid']; |
| 2043 | 2162 | |
@@ -2065,14 +2184,15 @@ discard block |
||
| 2065 | 2184 | } |
| 2066 | 2185 | |
| 2067 | 2186 | // Delete it? |
| 2068 | - if (isset($_REQUEST['deleteevent'])) |
|
| 2069 | - $smcFunc['db_query']('', ' |
|
| 2187 | + if (isset($_REQUEST['deleteevent'])) { |
|
| 2188 | + $smcFunc['db_query']('', ' |
|
| 2070 | 2189 | DELETE FROM {db_prefix}calendar |
| 2071 | 2190 | WHERE id_event = {int:id_event}', |
| 2072 | 2191 | array( |
| 2073 | 2192 | 'id_event' => $_REQUEST['eventid'], |
| 2074 | 2193 | ) |
| 2075 | 2194 | ); |
| 2195 | + } |
|
| 2076 | 2196 | // ... or just update it? |
| 2077 | 2197 | else |
| 2078 | 2198 | { |
@@ -2116,9 +2236,8 @@ discard block |
||
| 2116 | 2236 | array($user_info['id'], $topic, 0), |
| 2117 | 2237 | array('id_member', 'id_topic', 'id_board') |
| 2118 | 2238 | ); |
| 2119 | - } |
|
| 2120 | - elseif (!$newTopic) |
|
| 2121 | - $smcFunc['db_query']('', ' |
|
| 2239 | + } elseif (!$newTopic) { |
|
| 2240 | + $smcFunc['db_query']('', ' |
|
| 2122 | 2241 | DELETE FROM {db_prefix}log_notify |
| 2123 | 2242 | WHERE id_member = {int:current_member} |
| 2124 | 2243 | AND id_topic = {int:current_topic}', |
@@ -2127,16 +2246,20 @@ discard block |
||
| 2127 | 2246 | 'current_topic' => $topic, |
| 2128 | 2247 | ) |
| 2129 | 2248 | ); |
| 2249 | + } |
|
| 2130 | 2250 | |
| 2131 | 2251 | // Log an act of moderation - modifying. |
| 2132 | - if (!empty($moderationAction)) |
|
| 2133 | - logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
| 2252 | + if (!empty($moderationAction)) { |
|
| 2253 | + logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
| 2254 | + } |
|
| 2134 | 2255 | |
| 2135 | - if (isset($_POST['lock']) && $_POST['lock'] != 2) |
|
| 2136 | - logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
| 2256 | + if (isset($_POST['lock']) && $_POST['lock'] != 2) { |
|
| 2257 | + logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
| 2258 | + } |
|
| 2137 | 2259 | |
| 2138 | - if (isset($_POST['sticky'])) |
|
| 2139 | - logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
| 2260 | + if (isset($_POST['sticky'])) { |
|
| 2261 | + logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
| 2262 | + } |
|
| 2140 | 2263 | |
| 2141 | 2264 | // Returning to the topic? |
| 2142 | 2265 | if (!empty($_REQUEST['goback'])) |
@@ -2155,26 +2278,31 @@ discard block |
||
| 2155 | 2278 | ); |
| 2156 | 2279 | } |
| 2157 | 2280 | |
| 2158 | - if ($board_info['num_topics'] == 0) |
|
| 2159 | - cache_put_data('board-' . $board, null, 120); |
|
| 2281 | + if ($board_info['num_topics'] == 0) { |
|
| 2282 | + cache_put_data('board-' . $board, null, 120); |
|
| 2283 | + } |
|
| 2160 | 2284 | |
| 2161 | 2285 | call_integration_hook('integrate_post2_end'); |
| 2162 | 2286 | |
| 2163 | - if (!empty($_POST['announce_topic'])) |
|
| 2164 | - redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2287 | + if (!empty($_POST['announce_topic'])) { |
|
| 2288 | + redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2289 | + } |
|
| 2165 | 2290 | |
| 2166 | - if (!empty($_POST['move']) && allowedTo('move_any')) |
|
| 2167 | - redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2291 | + if (!empty($_POST['move']) && allowedTo('move_any')) { |
|
| 2292 | + redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2293 | + } |
|
| 2168 | 2294 | |
| 2169 | 2295 | // Return to post if the mod is on. |
| 2170 | - if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) |
|
| 2171 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie')); |
|
| 2172 | - elseif (!empty($_REQUEST['goback'])) |
|
| 2173 | - redirectexit('topic=' . $topic . '.new#new', isBrowser('ie')); |
|
| 2296 | + if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) { |
|
| 2297 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie')); |
|
| 2298 | + } elseif (!empty($_REQUEST['goback'])) { |
|
| 2299 | + redirectexit('topic=' . $topic . '.new#new', isBrowser('ie')); |
|
| 2300 | + } |
|
| 2174 | 2301 | // Dut-dut-duh-duh-DUH-duh-dut-duh-duh! *dances to the Final Fantasy Fanfare...* |
| 2175 | - else |
|
| 2176 | - redirectexit('board=' . $board . '.0'); |
|
| 2177 | -} |
|
| 2302 | + else { |
|
| 2303 | + redirectexit('board=' . $board . '.0'); |
|
| 2304 | + } |
|
| 2305 | + } |
|
| 2178 | 2306 | |
| 2179 | 2307 | /** |
| 2180 | 2308 | * Handle the announce topic function (action=announce). |
@@ -2192,8 +2320,9 @@ discard block |
||
| 2192 | 2320 | |
| 2193 | 2321 | validateSession(); |
| 2194 | 2322 | |
| 2195 | - if (empty($topic)) |
|
| 2196 | - fatal_lang_error('topic_gone', false); |
|
| 2323 | + if (empty($topic)) { |
|
| 2324 | + fatal_lang_error('topic_gone', false); |
|
| 2325 | + } |
|
| 2197 | 2326 | |
| 2198 | 2327 | loadLanguage('Post'); |
| 2199 | 2328 | loadTemplate('Post'); |
@@ -2220,8 +2349,9 @@ discard block |
||
| 2220 | 2349 | global $txt, $context, $topic, $board, $board_info, $smcFunc; |
| 2221 | 2350 | |
| 2222 | 2351 | $groups = array_merge($board_info['groups'], array(1)); |
| 2223 | - foreach ($groups as $id => $group) |
|
| 2224 | - $groups[$id] = (int) $group; |
|
| 2352 | + foreach ($groups as $id => $group) { |
|
| 2353 | + $groups[$id] = (int) $group; |
|
| 2354 | + } |
|
| 2225 | 2355 | |
| 2226 | 2356 | $context['groups'] = array(); |
| 2227 | 2357 | if (in_array(0, $groups)) |
@@ -2264,8 +2394,9 @@ discard block |
||
| 2264 | 2394 | 'group_list' => $groups, |
| 2265 | 2395 | ) |
| 2266 | 2396 | ); |
| 2267 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2268 | - $context['groups'][$row['id_group']]['name'] = $row['group_name']; |
|
| 2397 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2398 | + $context['groups'][$row['id_group']]['name'] = $row['group_name']; |
|
| 2399 | + } |
|
| 2269 | 2400 | $smcFunc['db_free_result']($request); |
| 2270 | 2401 | |
| 2271 | 2402 | // Get the subject of the topic we're about to announce. |
@@ -2307,16 +2438,19 @@ discard block |
||
| 2307 | 2438 | $context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start']; |
| 2308 | 2439 | $groups = array_merge($board_info['groups'], array(1)); |
| 2309 | 2440 | |
| 2310 | - if (isset($_POST['membergroups'])) |
|
| 2311 | - $_POST['who'] = explode(',', $_POST['membergroups']); |
|
| 2441 | + if (isset($_POST['membergroups'])) { |
|
| 2442 | + $_POST['who'] = explode(',', $_POST['membergroups']); |
|
| 2443 | + } |
|
| 2312 | 2444 | |
| 2313 | 2445 | // Check whether at least one membergroup was selected. |
| 2314 | - if (empty($_POST['who'])) |
|
| 2315 | - fatal_lang_error('no_membergroup_selected'); |
|
| 2446 | + if (empty($_POST['who'])) { |
|
| 2447 | + fatal_lang_error('no_membergroup_selected'); |
|
| 2448 | + } |
|
| 2316 | 2449 | |
| 2317 | 2450 | // Make sure all membergroups are integers and can access the board of the announcement. |
| 2318 | - foreach ($_POST['who'] as $id => $mg) |
|
| 2319 | - $_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0; |
|
| 2451 | + foreach ($_POST['who'] as $id => $mg) { |
|
| 2452 | + $_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0; |
|
| 2453 | + } |
|
| 2320 | 2454 | |
| 2321 | 2455 | // Get the topic subject and censor it. |
| 2322 | 2456 | $request = $smcFunc['db_query']('', ' |
@@ -2362,12 +2496,13 @@ discard block |
||
| 2362 | 2496 | if ($smcFunc['db_num_rows']($request) == 0) |
| 2363 | 2497 | { |
| 2364 | 2498 | logAction('announce_topic', array('topic' => $topic), 'user'); |
| 2365 | - if (!empty($_REQUEST['move']) && allowedTo('move_any')) |
|
| 2366 | - redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2367 | - elseif (!empty($_REQUEST['goback'])) |
|
| 2368 | - redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie')); |
|
| 2369 | - else |
|
| 2370 | - redirectexit('board=' . $board . '.0'); |
|
| 2499 | + if (!empty($_REQUEST['move']) && allowedTo('move_any')) { |
|
| 2500 | + redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2501 | + } elseif (!empty($_REQUEST['goback'])) { |
|
| 2502 | + redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie')); |
|
| 2503 | + } else { |
|
| 2504 | + redirectexit('board=' . $board . '.0'); |
|
| 2505 | + } |
|
| 2371 | 2506 | } |
| 2372 | 2507 | |
| 2373 | 2508 | $announcements = array(); |
@@ -2386,8 +2521,9 @@ discard block |
||
| 2386 | 2521 | foreach ($rows as $row) |
| 2387 | 2522 | { |
| 2388 | 2523 | // Force them to have it? |
| 2389 | - if (empty($prefs[$row['id_member']]['announcements'])) |
|
| 2390 | - continue; |
|
| 2524 | + if (empty($prefs[$row['id_member']]['announcements'])) { |
|
| 2525 | + continue; |
|
| 2526 | + } |
|
| 2391 | 2527 | |
| 2392 | 2528 | $cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']; |
| 2393 | 2529 | |
@@ -2415,8 +2551,9 @@ discard block |
||
| 2415 | 2551 | } |
| 2416 | 2552 | |
| 2417 | 2553 | // For each language send a different mail - low priority... |
| 2418 | - foreach ($announcements as $lang => $mail) |
|
| 2419 | - sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5); |
|
| 2554 | + foreach ($announcements as $lang => $mail) { |
|
| 2555 | + sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5); |
|
| 2556 | + } |
|
| 2420 | 2557 | |
| 2421 | 2558 | $context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1); |
| 2422 | 2559 | |
@@ -2426,9 +2563,10 @@ discard block |
||
| 2426 | 2563 | $context['sub_template'] = 'announcement_send'; |
| 2427 | 2564 | |
| 2428 | 2565 | // Go back to the correct language for the user ;). |
| 2429 | - if (!empty($modSettings['userLanguage'])) |
|
| 2430 | - loadLanguage('Post'); |
|
| 2431 | -} |
|
| 2566 | + if (!empty($modSettings['userLanguage'])) { |
|
| 2567 | + loadLanguage('Post'); |
|
| 2568 | + } |
|
| 2569 | + } |
|
| 2432 | 2570 | |
| 2433 | 2571 | /** |
| 2434 | 2572 | * Get the topic for display purposes. |
@@ -2441,12 +2579,13 @@ discard block |
||
| 2441 | 2579 | { |
| 2442 | 2580 | global $topic, $modSettings, $context, $smcFunc, $counter, $options; |
| 2443 | 2581 | |
| 2444 | - if (isset($_REQUEST['xml'])) |
|
| 2445 | - $limit = ' |
|
| 2582 | + if (isset($_REQUEST['xml'])) { |
|
| 2583 | + $limit = ' |
|
| 2446 | 2584 | LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']); |
| 2447 | - else |
|
| 2448 | - $limit = empty($modSettings['topicSummaryPosts']) ? '' : ' |
|
| 2585 | + } else { |
|
| 2586 | + $limit = empty($modSettings['topicSummaryPosts']) ? '' : ' |
|
| 2449 | 2587 | LIMIT ' . (int) $modSettings['topicSummaryPosts']; |
| 2588 | + } |
|
| 2450 | 2589 | |
| 2451 | 2590 | // If you're modifying, get only those posts before the current one. (otherwise get all.) |
| 2452 | 2591 | $request = $smcFunc['db_query']('', ' |
@@ -2484,8 +2623,9 @@ discard block |
||
| 2484 | 2623 | 'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']), |
| 2485 | 2624 | ); |
| 2486 | 2625 | |
| 2487 | - if (!empty($context['new_replies'])) |
|
| 2488 | - $context['new_replies']--; |
|
| 2626 | + if (!empty($context['new_replies'])) { |
|
| 2627 | + $context['new_replies']--; |
|
| 2628 | + } |
|
| 2489 | 2629 | } |
| 2490 | 2630 | $smcFunc['db_free_result']($request); |
| 2491 | 2631 | } |
@@ -2502,8 +2642,9 @@ discard block |
||
| 2502 | 2642 | global $sourcedir, $smcFunc; |
| 2503 | 2643 | |
| 2504 | 2644 | loadLanguage('Post'); |
| 2505 | - if (!isset($_REQUEST['xml'])) |
|
| 2506 | - loadTemplate('Post'); |
|
| 2645 | + if (!isset($_REQUEST['xml'])) { |
|
| 2646 | + loadTemplate('Post'); |
|
| 2647 | + } |
|
| 2507 | 2648 | |
| 2508 | 2649 | include_once($sourcedir . '/Subs-Post.php'); |
| 2509 | 2650 | |
@@ -2534,8 +2675,9 @@ discard block |
||
| 2534 | 2675 | $smcFunc['db_free_result']($request); |
| 2535 | 2676 | |
| 2536 | 2677 | $context['sub_template'] = 'quotefast'; |
| 2537 | - if (!empty($row)) |
|
| 2538 | - $can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']); |
|
| 2678 | + if (!empty($row)) { |
|
| 2679 | + $can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']); |
|
| 2680 | + } |
|
| 2539 | 2681 | |
| 2540 | 2682 | if (!empty($can_view_post)) |
| 2541 | 2683 | { |
@@ -2568,8 +2710,9 @@ discard block |
||
| 2568 | 2710 | } |
| 2569 | 2711 | |
| 2570 | 2712 | // Remove any nested quotes. |
| 2571 | - if (!empty($modSettings['removeNestedQuotes'])) |
|
| 2572 | - $row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']); |
|
| 2713 | + if (!empty($modSettings['removeNestedQuotes'])) { |
|
| 2714 | + $row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']); |
|
| 2715 | + } |
|
| 2573 | 2716 | |
| 2574 | 2717 | $lb = "\n"; |
| 2575 | 2718 | |
@@ -2595,14 +2738,14 @@ discard block |
||
| 2595 | 2738 | 'time' => '', |
| 2596 | 2739 | ), |
| 2597 | 2740 | ); |
| 2598 | - } |
|
| 2599 | - else |
|
| 2600 | - $context['quote'] = array( |
|
| 2741 | + } else { |
|
| 2742 | + $context['quote'] = array( |
|
| 2601 | 2743 | 'xml' => '', |
| 2602 | 2744 | 'mozilla' => '', |
| 2603 | 2745 | 'text' => '', |
| 2604 | 2746 | ); |
| 2605 | -} |
|
| 2747 | + } |
|
| 2748 | + } |
|
| 2606 | 2749 | |
| 2607 | 2750 | /** |
| 2608 | 2751 | * Used to edit the body or subject of a message inline |
@@ -2614,8 +2757,9 @@ discard block |
||
| 2614 | 2757 | global $user_info, $context, $smcFunc, $language, $board_info; |
| 2615 | 2758 | |
| 2616 | 2759 | // We have to have a topic! |
| 2617 | - if (empty($topic)) |
|
| 2618 | - obExit(false); |
|
| 2760 | + if (empty($topic)) { |
|
| 2761 | + obExit(false); |
|
| 2762 | + } |
|
| 2619 | 2763 | |
| 2620 | 2764 | checkSession('get'); |
| 2621 | 2765 | require_once($sourcedir . '/Subs-Post.php'); |
@@ -2641,31 +2785,35 @@ discard block |
||
| 2641 | 2785 | 'guest_id' => 0, |
| 2642 | 2786 | ) |
| 2643 | 2787 | ); |
| 2644 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 2645 | - fatal_lang_error('no_board', false); |
|
| 2788 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 2789 | + fatal_lang_error('no_board', false); |
|
| 2790 | + } |
|
| 2646 | 2791 | $row = $smcFunc['db_fetch_assoc']($request); |
| 2647 | 2792 | $smcFunc['db_free_result']($request); |
| 2648 | 2793 | |
| 2649 | 2794 | // Change either body or subject requires permissions to modify messages. |
| 2650 | 2795 | if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon'])) |
| 2651 | 2796 | { |
| 2652 | - if (!empty($row['locked'])) |
|
| 2653 | - isAllowedTo('moderate_board'); |
|
| 2797 | + if (!empty($row['locked'])) { |
|
| 2798 | + isAllowedTo('moderate_board'); |
|
| 2799 | + } |
|
| 2654 | 2800 | |
| 2655 | 2801 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
| 2656 | 2802 | { |
| 2657 | - if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
| 2658 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 2659 | - elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) |
|
| 2660 | - isAllowedTo('modify_replies'); |
|
| 2661 | - else |
|
| 2662 | - isAllowedTo('modify_own'); |
|
| 2803 | + if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
| 2804 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 2805 | + } elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
| 2806 | + isAllowedTo('modify_replies'); |
|
| 2807 | + } else { |
|
| 2808 | + isAllowedTo('modify_own'); |
|
| 2809 | + } |
|
| 2663 | 2810 | } |
| 2664 | 2811 | // Otherwise, they're locked out; someone who can modify the replies is needed. |
| 2665 | - elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 2666 | - isAllowedTo('modify_replies'); |
|
| 2667 | - else |
|
| 2668 | - isAllowedTo('modify_any'); |
|
| 2812 | + elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) { |
|
| 2813 | + isAllowedTo('modify_replies'); |
|
| 2814 | + } else { |
|
| 2815 | + isAllowedTo('modify_any'); |
|
| 2816 | + } |
|
| 2669 | 2817 | |
| 2670 | 2818 | // Only log this action if it wasn't your message. |
| 2671 | 2819 | $moderationAction = $row['id_member'] != $user_info['id']; |
@@ -2677,10 +2825,10 @@ discard block |
||
| 2677 | 2825 | $_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => '')); |
| 2678 | 2826 | |
| 2679 | 2827 | // Maximum number of characters. |
| 2680 | - if ($smcFunc['strlen']($_POST['subject']) > 100) |
|
| 2681 | - $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
| 2682 | - } |
|
| 2683 | - elseif (isset($_POST['subject'])) |
|
| 2828 | + if ($smcFunc['strlen']($_POST['subject']) > 100) { |
|
| 2829 | + $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
| 2830 | + } |
|
| 2831 | + } elseif (isset($_POST['subject'])) |
|
| 2684 | 2832 | { |
| 2685 | 2833 | $post_errors[] = 'no_subject'; |
| 2686 | 2834 | unset($_POST['subject']); |
@@ -2692,13 +2840,11 @@ discard block |
||
| 2692 | 2840 | { |
| 2693 | 2841 | $post_errors[] = 'no_message'; |
| 2694 | 2842 | unset($_POST['message']); |
| 2695 | - } |
|
| 2696 | - elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) |
|
| 2843 | + } elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) |
|
| 2697 | 2844 | { |
| 2698 | 2845 | $post_errors[] = 'long_message'; |
| 2699 | 2846 | unset($_POST['message']); |
| 2700 | - } |
|
| 2701 | - else |
|
| 2847 | + } else |
|
| 2702 | 2848 | { |
| 2703 | 2849 | $_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES); |
| 2704 | 2850 | |
@@ -2714,31 +2860,34 @@ discard block |
||
| 2714 | 2860 | |
| 2715 | 2861 | if (isset($_POST['lock'])) |
| 2716 | 2862 | { |
| 2717 | - if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) |
|
| 2718 | - unset($_POST['lock']); |
|
| 2719 | - elseif (!allowedTo('lock_any')) |
|
| 2863 | + if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) { |
|
| 2864 | + unset($_POST['lock']); |
|
| 2865 | + } elseif (!allowedTo('lock_any')) |
|
| 2720 | 2866 | { |
| 2721 | - if ($row['locked'] == 1) |
|
| 2722 | - unset($_POST['lock']); |
|
| 2723 | - else |
|
| 2724 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 2867 | + if ($row['locked'] == 1) { |
|
| 2868 | + unset($_POST['lock']); |
|
| 2869 | + } else { |
|
| 2870 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 2871 | + } |
|
| 2872 | + } elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) { |
|
| 2873 | + unset($_POST['lock']); |
|
| 2874 | + } else { |
|
| 2875 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
|
| 2725 | 2876 | } |
| 2726 | - elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) |
|
| 2727 | - unset($_POST['lock']); |
|
| 2728 | - else |
|
| 2729 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
|
| 2730 | 2877 | } |
| 2731 | 2878 | |
| 2732 | - if (isset($_POST['sticky']) && !allowedTo('make_sticky')) |
|
| 2733 | - unset($_POST['sticky']); |
|
| 2879 | + if (isset($_POST['sticky']) && !allowedTo('make_sticky')) { |
|
| 2880 | + unset($_POST['sticky']); |
|
| 2881 | + } |
|
| 2734 | 2882 | |
| 2735 | 2883 | if (isset($_POST['modify_reason'])) |
| 2736 | 2884 | { |
| 2737 | 2885 | $_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => '')); |
| 2738 | 2886 | |
| 2739 | 2887 | // Maximum number of characters. |
| 2740 | - if ($smcFunc['strlen']($_POST['modify_reason']) > 100) |
|
| 2741 | - $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
| 2888 | + if ($smcFunc['strlen']($_POST['modify_reason']) > 100) { |
|
| 2889 | + $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
| 2890 | + } |
|
| 2742 | 2891 | } |
| 2743 | 2892 | |
| 2744 | 2893 | if (empty($post_errors)) |
@@ -2775,8 +2924,9 @@ discard block |
||
| 2775 | 2924 | } |
| 2776 | 2925 | } |
| 2777 | 2926 | // If nothing was changed there's no need to add an entry to the moderation log. |
| 2778 | - else |
|
| 2779 | - $moderationAction = false; |
|
| 2927 | + else { |
|
| 2928 | + $moderationAction = false; |
|
| 2929 | + } |
|
| 2780 | 2930 | |
| 2781 | 2931 | modifyPost($msgOptions, $topicOptions, $posterOptions); |
| 2782 | 2932 | |
@@ -2794,9 +2944,9 @@ discard block |
||
| 2794 | 2944 | // Get the proper (default language) response prefix first. |
| 2795 | 2945 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
| 2796 | 2946 | { |
| 2797 | - if ($language === $user_info['language']) |
|
| 2798 | - $context['response_prefix'] = $txt['response_prefix']; |
|
| 2799 | - else |
|
| 2947 | + if ($language === $user_info['language']) { |
|
| 2948 | + $context['response_prefix'] = $txt['response_prefix']; |
|
| 2949 | + } else |
|
| 2800 | 2950 | { |
| 2801 | 2951 | loadLanguage('index', $language, false); |
| 2802 | 2952 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -2818,8 +2968,9 @@ discard block |
||
| 2818 | 2968 | ); |
| 2819 | 2969 | } |
| 2820 | 2970 | |
| 2821 | - if (!empty($moderationAction)) |
|
| 2822 | - logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
| 2971 | + if (!empty($moderationAction)) { |
|
| 2972 | + logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
| 2973 | + } |
|
| 2823 | 2974 | } |
| 2824 | 2975 | |
| 2825 | 2976 | if (isset($_REQUEST['xml'])) |
@@ -2860,8 +3011,7 @@ discard block |
||
| 2860 | 3011 | ); |
| 2861 | 3012 | |
| 2862 | 3013 | censorText($context['message']['subject']); |
| 2863 | - } |
|
| 2864 | - else |
|
| 3014 | + } else |
|
| 2865 | 3015 | { |
| 2866 | 3016 | $context['message'] = array( |
| 2867 | 3017 | 'id' => $row['id_msg'], |
@@ -2873,15 +3023,16 @@ discard block |
||
| 2873 | 3023 | loadLanguage('Errors'); |
| 2874 | 3024 | foreach ($post_errors as $post_error) |
| 2875 | 3025 | { |
| 2876 | - if ($post_error == 'long_message') |
|
| 2877 | - $context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']); |
|
| 2878 | - else |
|
| 2879 | - $context['message']['errors'][] = $txt['error_' . $post_error]; |
|
| 3026 | + if ($post_error == 'long_message') { |
|
| 3027 | + $context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']); |
|
| 3028 | + } else { |
|
| 3029 | + $context['message']['errors'][] = $txt['error_' . $post_error]; |
|
| 3030 | + } |
|
| 2880 | 3031 | } |
| 2881 | 3032 | } |
| 3033 | + } else { |
|
| 3034 | + obExit(false); |
|
| 3035 | + } |
|
| 2882 | 3036 | } |
| 2883 | - else |
|
| 2884 | - obExit(false); |
|
| 2885 | -} |
|
| 2886 | 3037 | |
| 2887 | 3038 | ?> |
| 2888 | 3039 | \ No newline at end of file |
@@ -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 | * Shows a listing of registered members. |
@@ -110,8 +111,9 @@ discard block |
||
| 110 | 111 | |
| 111 | 112 | $context['custom_profile_fields'] = getCustFieldsMList(); |
| 112 | 113 | |
| 113 | - if (!empty($context['custom_profile_fields']['columns'])) |
|
| 114 | - $context['columns'] += $context['custom_profile_fields']['columns']; |
|
| 114 | + if (!empty($context['custom_profile_fields']['columns'])) { |
|
| 115 | + $context['columns'] += $context['custom_profile_fields']['columns']; |
|
| 116 | + } |
|
| 115 | 117 | |
| 116 | 118 | $context['colspan'] = 0; |
| 117 | 119 | $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array(); |
@@ -147,12 +149,12 @@ discard block |
||
| 147 | 149 | call_integration_hook('integrate_memberlist_buttons'); |
| 148 | 150 | |
| 149 | 151 | // Jump to the sub action. |
| 150 | - if (isset($subActions[$context['listing_by']])) |
|
| 151 | - call_helper($subActions[$context['listing_by']][1]); |
|
| 152 | - |
|
| 153 | - else |
|
| 154 | - call_helper($subActions['all'][1]); |
|
| 155 | -} |
|
| 152 | + if (isset($subActions[$context['listing_by']])) { |
|
| 153 | + call_helper($subActions[$context['listing_by']][1]); |
|
| 154 | + } else { |
|
| 155 | + call_helper($subActions['all'][1]); |
|
| 156 | + } |
|
| 157 | + } |
|
| 156 | 158 | |
| 157 | 159 | /** |
| 158 | 160 | * List all members, page by page, with sorting. |
@@ -177,8 +179,9 @@ discard block |
||
| 177 | 179 | if ($use_cache) |
| 178 | 180 | { |
| 179 | 181 | // Maybe there's something cached already. |
| 180 | - if (!empty($modSettings['memberlist_cache'])) |
|
| 181 | - $memberlist_cache = smf_json_decode($modSettings['memberlist_cache'], true); |
|
| 182 | + if (!empty($modSettings['memberlist_cache'])) { |
|
| 183 | + $memberlist_cache = smf_json_decode($modSettings['memberlist_cache'], true); |
|
| 184 | + } |
|
| 182 | 185 | |
| 183 | 186 | // The chunk size for the cached index. |
| 184 | 187 | $cache_step_size = 500; |
@@ -234,13 +237,15 @@ discard block |
||
| 234 | 237 | } |
| 235 | 238 | |
| 236 | 239 | // Set defaults for sort (real_name) and start. (0) |
| 237 | - if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) |
|
| 238 | - $_REQUEST['sort'] = 'real_name'; |
|
| 240 | + if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) { |
|
| 241 | + $_REQUEST['sort'] = 'real_name'; |
|
| 242 | + } |
|
| 239 | 243 | |
| 240 | 244 | if (!is_numeric($_REQUEST['start'])) |
| 241 | 245 | { |
| 242 | - if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0) |
|
| 243 | - fatal_error('Hacker?', false); |
|
| 246 | + if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0) { |
|
| 247 | + fatal_error('Hacker?', false); |
|
| 248 | + } |
|
| 244 | 249 | |
| 245 | 250 | $_REQUEST['start'] = $match[0]; |
| 246 | 251 | |
@@ -259,16 +264,18 @@ discard block |
||
| 259 | 264 | } |
| 260 | 265 | |
| 261 | 266 | $context['letter_links'] = ''; |
| 262 | - for ($i = 97; $i < 123; $i++) |
|
| 263 | - $context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> '; |
|
| 267 | + for ($i = 97; $i < 123; $i++) { |
|
| 268 | + $context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> '; |
|
| 269 | + } |
|
| 264 | 270 | |
| 265 | 271 | // Sort out the column information. |
| 266 | 272 | foreach ($context['columns'] as $col => $column_details) |
| 267 | 273 | { |
| 268 | 274 | $context['columns'][$col]['href'] = $scripturl . '?action=mlist;sort=' . $col . ';start=0'; |
| 269 | 275 | |
| 270 | - if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) |
|
| 271 | - $context['columns'][$col]['href'] .= ';desc'; |
|
| 276 | + if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) { |
|
| 277 | + $context['columns'][$col]['href'] .= ';desc'; |
|
| 278 | + } |
|
| 272 | 279 | |
| 273 | 280 | $context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>'; |
| 274 | 281 | $context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col; |
@@ -317,8 +324,9 @@ discard block |
||
| 317 | 324 | elseif ($use_cache && $_REQUEST['sort'] === 'real_name') |
| 318 | 325 | { |
| 319 | 326 | $first_offset = floor(($memberlist_cache['num_members'] - $modSettings['defaultMaxMembers'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size; |
| 320 | - if ($first_offset < 0) |
|
| 321 | - $first_offset = 0; |
|
| 327 | + if ($first_offset < 0) { |
|
| 328 | + $first_offset = 0; |
|
| 329 | + } |
|
| 322 | 330 | $second_offset = ceil(($memberlist_cache['num_members'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size; |
| 323 | 331 | |
| 324 | 332 | $where = 'mem.real_name BETWEEN {string:real_name_low} AND {string:real_name_high}'; |
@@ -395,12 +403,13 @@ discard block |
||
| 395 | 403 | ) |
| 396 | 404 | ); |
| 397 | 405 | $context['custom_search_fields'] = array(); |
| 398 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 399 | - $context['custom_search_fields'][$row['col_name']] = array( |
|
| 406 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 407 | + $context['custom_search_fields'][$row['col_name']] = array( |
|
| 400 | 408 | 'colname' => $row['col_name'], |
| 401 | 409 | 'name' => $row['field_name'], |
| 402 | 410 | 'desc' => $row['field_desc'], |
| 403 | 411 | ); |
| 412 | + } |
|
| 404 | 413 | $smcFunc['db_free_result']($request); |
| 405 | 414 | |
| 406 | 415 | // They're searching.. |
@@ -413,23 +422,27 @@ discard block |
||
| 413 | 422 | $context['old_search_value'] = urlencode($_REQUEST['search']); |
| 414 | 423 | |
| 415 | 424 | // No fields? Use default... |
| 416 | - if (empty($_POST['fields'])) |
|
| 417 | - $_POST['fields'] = array('name'); |
|
| 425 | + if (empty($_POST['fields'])) { |
|
| 426 | + $_POST['fields'] = array('name'); |
|
| 427 | + } |
|
| 418 | 428 | |
| 419 | 429 | // Set defaults for how the results are sorted |
| 420 | - if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) |
|
| 421 | - $_REQUEST['sort'] = 'real_name'; |
|
| 430 | + if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) { |
|
| 431 | + $_REQUEST['sort'] = 'real_name'; |
|
| 432 | + } |
|
| 422 | 433 | |
| 423 | 434 | // Build the column link / sort information. |
| 424 | 435 | foreach ($context['columns'] as $col => $column_details) |
| 425 | 436 | { |
| 426 | 437 | $context['columns'][$col]['href'] = $scripturl . '?action=mlist;sa=search;start=0;sort=' . $col; |
| 427 | 438 | |
| 428 | - if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) |
|
| 429 | - $context['columns'][$col]['href'] .= ';desc'; |
|
| 439 | + if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) { |
|
| 440 | + $context['columns'][$col]['href'] .= ';desc'; |
|
| 441 | + } |
|
| 430 | 442 | |
| 431 | - if (isset($_POST['search']) && isset($_POST['fields'])) |
|
| 432 | - $context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']); |
|
| 443 | + if (isset($_POST['search']) && isset($_POST['fields'])) { |
|
| 444 | + $context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']); |
|
| 445 | + } |
|
| 433 | 446 | |
| 434 | 447 | $context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>'; |
| 435 | 448 | $context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col; |
@@ -452,8 +465,7 @@ discard block |
||
| 452 | 465 | { |
| 453 | 466 | $fields = allowedTo('moderate_forum') ? array('member_name', 'real_name') : array('real_name'); |
| 454 | 467 | $search_fields[] = 'name'; |
| 455 | - } |
|
| 456 | - else |
|
| 468 | + } else |
|
| 457 | 469 | { |
| 458 | 470 | $fields = array(); |
| 459 | 471 | $search_fields = array(); |
@@ -478,9 +490,10 @@ discard block |
||
| 478 | 490 | $search_fields[] = 'email'; |
| 479 | 491 | } |
| 480 | 492 | |
| 481 | - if ($smcFunc['db_case_sensitive']) |
|
| 482 | - foreach ($fields as $key => $field) |
|
| 493 | + if ($smcFunc['db_case_sensitive']) { |
|
| 494 | + foreach ($fields as $key => $field) |
|
| 483 | 495 | $fields[$key] = 'LOWER(' . $field . ')'; |
| 496 | + } |
|
| 484 | 497 | |
| 485 | 498 | $customJoin = array(); |
| 486 | 499 | $customCount = 10; |
@@ -499,8 +512,9 @@ discard block |
||
| 499 | 512 | } |
| 500 | 513 | |
| 501 | 514 | // No search fields? That means you're trying to hack things |
| 502 | - if (empty($search_fields)) |
|
| 503 | - fatal_lang_error('invalid_search_string', false); |
|
| 515 | + if (empty($search_fields)) { |
|
| 516 | + fatal_lang_error('invalid_search_string', false); |
|
| 517 | + } |
|
| 504 | 518 | |
| 505 | 519 | $query = $_POST['search'] == '' ? '= {string:blank_string}' : ($smcFunc['db_case_sensitive'] ? 'LIKE LOWER({string:search})' : 'LIKE {string:search}'); |
| 506 | 520 | |
@@ -538,8 +552,7 @@ discard block |
||
| 538 | 552 | ); |
| 539 | 553 | printMemberListRows($request); |
| 540 | 554 | $smcFunc['db_free_result']($request); |
| 541 | - } |
|
| 542 | - else |
|
| 555 | + } else |
|
| 543 | 556 | { |
| 544 | 557 | // These are all the possible fields. |
| 545 | 558 | $context['search_fields'] = array( |
@@ -554,14 +567,14 @@ discard block |
||
| 554 | 567 | { |
| 555 | 568 | unset($context['search_fields']['email']); |
| 556 | 569 | $context['search_defaults'] = array('name'); |
| 557 | - } |
|
| 558 | - else |
|
| 570 | + } else |
|
| 559 | 571 | { |
| 560 | 572 | $context['search_defaults'] = array('name', 'email'); |
| 561 | 573 | } |
| 562 | 574 | |
| 563 | - foreach ($context['custom_search_fields'] as $field) |
|
| 564 | - $context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']); |
|
| 575 | + foreach ($context['custom_search_fields'] as $field) { |
|
| 576 | + $context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']); |
|
| 577 | + } |
|
| 565 | 578 | |
| 566 | 579 | $context['sub_template'] = 'search'; |
| 567 | 580 | $context['old_search'] = isset($_GET['search']) ? $_GET['search'] : (isset($_POST['search']) ? $smcFunc['htmlspecialchars']($_POST['search']) : ''); |
@@ -603,12 +616,14 @@ discard block |
||
| 603 | 616 | $smcFunc['db_free_result']($result); |
| 604 | 617 | |
| 605 | 618 | // Avoid division by zero... |
| 606 | - if ($most_posts == 0) |
|
| 607 | - $most_posts = 1; |
|
| 619 | + if ($most_posts == 0) { |
|
| 620 | + $most_posts = 1; |
|
| 621 | + } |
|
| 608 | 622 | |
| 609 | 623 | $members = array(); |
| 610 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 611 | - $members[] = $row['id_member']; |
|
| 624 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 625 | + $members[] = $row['id_member']; |
|
| 626 | + } |
|
| 612 | 627 | |
| 613 | 628 | // Load all the members for display. |
| 614 | 629 | loadMemberData($members); |
@@ -616,8 +631,9 @@ discard block |
||
| 616 | 631 | $context['members'] = array(); |
| 617 | 632 | foreach ($members as $member) |
| 618 | 633 | { |
| 619 | - if (!loadMemberContext($member)) |
|
| 620 | - continue; |
|
| 634 | + if (!loadMemberContext($member)) { |
|
| 635 | + continue; |
|
| 636 | + } |
|
| 621 | 637 | |
| 622 | 638 | $context['members'][$member] = $memberContext[$member]; |
| 623 | 639 | $context['members'][$member]['post_percent'] = round(($context['members'][$member]['real_posts'] * 100) / $most_posts); |
@@ -634,20 +650,21 @@ discard block |
||
| 634 | 650 | continue; |
| 635 | 651 | } |
| 636 | 652 | |
| 637 | - if ($column['bbc'] && !empty($context['members'][$member]['options'][$key])) |
|
| 638 | - $context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key])); |
|
| 639 | - |
|
| 640 | - elseif ($column['type'] == 'check') |
|
| 641 | - $context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes']; |
|
| 653 | + if ($column['bbc'] && !empty($context['members'][$member]['options'][$key])) { |
|
| 654 | + $context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key])); |
|
| 655 | + } elseif ($column['type'] == 'check') { |
|
| 656 | + $context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes']; |
|
| 657 | + } |
|
| 642 | 658 | |
| 643 | 659 | // Enclosing the user input within some other text? |
| 644 | - if (!empty($column['enclose'])) |
|
| 645 | - $context['members'][$member]['options'][$key] = strtr($column['enclose'], array( |
|
| 660 | + if (!empty($column['enclose'])) { |
|
| 661 | + $context['members'][$member]['options'][$key] = strtr($column['enclose'], array( |
|
| 646 | 662 | '{SCRIPTURL}' => $scripturl, |
| 647 | 663 | '{IMAGES_URL}' => $settings['images_url'], |
| 648 | 664 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
| 649 | 665 | '{INPUT}' => $context['members'][$member]['options'][$key], |
| 650 | 666 | )); |
| 667 | + } |
|
| 651 | 668 | } |
| 652 | 669 | } |
| 653 | 670 | } |
@@ -688,17 +705,17 @@ discard block |
||
| 688 | 705 | ); |
| 689 | 706 | |
| 690 | 707 | // Get the right sort method depending on the cust field type. |
| 691 | - if ($row['field_type'] != 'check') |
|
| 692 | - $cpf['columns'][$row['col_name']]['sort'] = array( |
|
| 708 | + if ($row['field_type'] != 'check') { |
|
| 709 | + $cpf['columns'][$row['col_name']]['sort'] = array( |
|
| 693 | 710 | 'down' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 ASC, COALESCE(t' . $row['col_name'] . '.value, "") DESC', |
| 694 | 711 | 'up' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 DESC, COALESCE(t' . $row['col_name'] . '.value, "") ASC' |
| 695 | 712 | ); |
| 696 | - |
|
| 697 | - else |
|
| 698 | - $cpf['columns'][$row['col_name']]['sort'] = array( |
|
| 713 | + } else { |
|
| 714 | + $cpf['columns'][$row['col_name']]['sort'] = array( |
|
| 699 | 715 | 'down' => 't' . $row['col_name'] . '.value DESC', |
| 700 | 716 | 'up' => 't' . $row['col_name'] . '.value ASC' |
| 701 | 717 | ); |
| 718 | + } |
|
| 702 | 719 | |
| 703 | 720 | $cpf['join'][$row['col_name']] = 'LEFT JOIN {db_prefix}themes AS t' . $row['col_name'] . ' ON (t' . $row['col_name'] . '.variable = {literal:' . $row['col_name'] . '} AND t' . $row['col_name'] . '.id_theme = 1 AND t' . $row['col_name'] . '.id_member = mem.id_member)'; |
| 704 | 721 | } |
@@ -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 entry point for the admin search settings screen. |
@@ -107,11 +108,13 @@ discard block |
||
| 107 | 108 | // Perhaps the search method wants to add some settings? |
| 108 | 109 | require_once($sourcedir . '/Search.php'); |
| 109 | 110 | $searchAPI = findSearchAPI(); |
| 110 | - if (is_callable(array($searchAPI, 'searchSettings'))) |
|
| 111 | - call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars)); |
|
| 111 | + if (is_callable(array($searchAPI, 'searchSettings'))) { |
|
| 112 | + call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars)); |
|
| 113 | + } |
|
| 112 | 114 | |
| 113 | - if ($return_config) |
|
| 114 | - return $config_vars; |
|
| 115 | + if ($return_config) { |
|
| 116 | + return $config_vars; |
|
| 117 | + } |
|
| 115 | 118 | |
| 116 | 119 | $context['page_title'] = $txt['search_settings_title']; |
| 117 | 120 | $context['sub_template'] = 'show_settings'; |
@@ -126,8 +129,9 @@ discard block |
||
| 126 | 129 | |
| 127 | 130 | call_integration_hook('integrate_save_search_settings'); |
| 128 | 131 | |
| 129 | - if (empty($_POST['search_results_per_page'])) |
|
| 130 | - $_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages']; |
|
| 132 | + if (empty($_POST['search_results_per_page'])) { |
|
| 133 | + $_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages']; |
|
| 134 | + } |
|
| 131 | 135 | saveDBSettings($config_vars); |
| 132 | 136 | $_SESSION['adm-save'] = true; |
| 133 | 137 | redirectexit('action=admin;area=managesearch;sa=settings;' . $context['session_var'] . '=' . $context['session_id']); |
@@ -177,17 +181,20 @@ discard block |
||
| 177 | 181 | call_integration_hook('integrate_save_search_weights'); |
| 178 | 182 | |
| 179 | 183 | $changes = array(); |
| 180 | - foreach ($factors as $factor) |
|
| 181 | - $changes[$factor] = (int) $_POST[$factor]; |
|
| 184 | + foreach ($factors as $factor) { |
|
| 185 | + $changes[$factor] = (int) $_POST[$factor]; |
|
| 186 | + } |
|
| 182 | 187 | updateSettings($changes); |
| 183 | 188 | } |
| 184 | 189 | |
| 185 | 190 | $context['relative_weights'] = array('total' => 0); |
| 186 | - foreach ($factors as $factor) |
|
| 187 | - $context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0; |
|
| 191 | + foreach ($factors as $factor) { |
|
| 192 | + $context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0; |
|
| 193 | + } |
|
| 188 | 194 | |
| 189 | - foreach ($factors as $factor) |
|
| 190 | - $context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1); |
|
| 195 | + foreach ($factors as $factor) { |
|
| 196 | + $context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1); |
|
| 197 | + } |
|
| 191 | 198 | |
| 192 | 199 | createToken('admin-msw'); |
| 193 | 200 | } |
@@ -215,8 +222,9 @@ discard block |
||
| 215 | 222 | $context['search_apis'] = loadSearchAPIs(); |
| 216 | 223 | |
| 217 | 224 | // Detect whether a fulltext index is set. |
| 218 | - if ($context['supports_fulltext']) |
|
| 219 | - detectFulltextIndex(); |
|
| 225 | + if ($context['supports_fulltext']) { |
|
| 226 | + detectFulltextIndex(); |
|
| 227 | + } |
|
| 220 | 228 | |
| 221 | 229 | if (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'createfulltext') |
| 222 | 230 | { |
@@ -250,8 +258,7 @@ discard block |
||
| 250 | 258 | 'language' => $language_ftx |
| 251 | 259 | ) |
| 252 | 260 | ); |
| 253 | - } |
|
| 254 | - else |
|
| 261 | + } else |
|
| 255 | 262 | { |
| 256 | 263 | // Make sure it's gone before creating it. |
| 257 | 264 | $smcFunc['db_query']('', ' |
@@ -271,8 +278,7 @@ discard block |
||
| 271 | 278 | } |
| 272 | 279 | |
| 273 | 280 | $context['fulltext_index'] = 'body'; |
| 274 | - } |
|
| 275 | - elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index'])) |
|
| 281 | + } elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index'])) |
|
| 276 | 282 | { |
| 277 | 283 | checkSession('get'); |
| 278 | 284 | validateToken('admin-msm', 'get'); |
@@ -289,12 +295,12 @@ discard block |
||
| 289 | 295 | $context['fulltext_index'] = ''; |
| 290 | 296 | |
| 291 | 297 | // Go back to the default search method. |
| 292 | - if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext') |
|
| 293 | - updateSettings(array( |
|
| 298 | + if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext') { |
|
| 299 | + updateSettings(array( |
|
| 294 | 300 | 'search_index' => '', |
| 295 | 301 | )); |
| 296 | - } |
|
| 297 | - elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom') |
|
| 302 | + } |
|
| 303 | + } elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom') |
|
| 298 | 304 | { |
| 299 | 305 | checkSession('get'); |
| 300 | 306 | validateToken('admin-msm', 'get'); |
@@ -316,12 +322,12 @@ discard block |
||
| 316 | 322 | )); |
| 317 | 323 | |
| 318 | 324 | // Go back to the default search method. |
| 319 | - if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') |
|
| 320 | - updateSettings(array( |
|
| 325 | + if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') { |
|
| 326 | + updateSettings(array( |
|
| 321 | 327 | 'search_index' => '', |
| 322 | 328 | )); |
| 323 | - } |
|
| 324 | - elseif (isset($_POST['save'])) |
|
| 329 | + } |
|
| 330 | + } elseif (isset($_POST['save'])) |
|
| 325 | 331 | { |
| 326 | 332 | checkSession(); |
| 327 | 333 | validateToken('admin-msmpost'); |
@@ -343,8 +349,8 @@ discard block |
||
| 343 | 349 | // Get some info about the messages table, to show its size and index size. |
| 344 | 350 | if ($db_type == 'mysql' || $db_type == 'mysqli') |
| 345 | 351 | { |
| 346 | - if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) |
|
| 347 | - $request = $smcFunc['db_query']('', ' |
|
| 352 | + if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) { |
|
| 353 | + $request = $smcFunc['db_query']('', ' |
|
| 348 | 354 | SHOW TABLE STATUS |
| 349 | 355 | FROM {string:database_name} |
| 350 | 356 | LIKE {string:table_name}', |
@@ -353,14 +359,15 @@ discard block |
||
| 353 | 359 | 'table_name' => str_replace('_', '\_', $match[2]) . 'messages', |
| 354 | 360 | ) |
| 355 | 361 | ); |
| 356 | - else |
|
| 357 | - $request = $smcFunc['db_query']('', ' |
|
| 362 | + } else { |
|
| 363 | + $request = $smcFunc['db_query']('', ' |
|
| 358 | 364 | SHOW TABLE STATUS |
| 359 | 365 | LIKE {string:table_name}', |
| 360 | 366 | array( |
| 361 | 367 | 'table_name' => str_replace('_', '\_', $db_prefix) . 'messages', |
| 362 | 368 | ) |
| 363 | 369 | ); |
| 370 | + } |
|
| 364 | 371 | if ($request !== false && $smcFunc['db_num_rows']($request) == 1) |
| 365 | 372 | { |
| 366 | 373 | // Only do this if the user has permission to execute this query. |
@@ -372,8 +379,8 @@ discard block |
||
| 372 | 379 | } |
| 373 | 380 | |
| 374 | 381 | // Now check the custom index table, if it exists at all. |
| 375 | - if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) |
|
| 376 | - $request = $smcFunc['db_query']('', ' |
|
| 382 | + if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) { |
|
| 383 | + $request = $smcFunc['db_query']('', ' |
|
| 377 | 384 | SHOW TABLE STATUS |
| 378 | 385 | FROM {string:database_name} |
| 379 | 386 | LIKE {string:table_name}', |
@@ -382,14 +389,15 @@ discard block |
||
| 382 | 389 | 'table_name' => str_replace('_', '\_', $match[2]) . 'log_search_words', |
| 383 | 390 | ) |
| 384 | 391 | ); |
| 385 | - else |
|
| 386 | - $request = $smcFunc['db_query']('', ' |
|
| 392 | + } else { |
|
| 393 | + $request = $smcFunc['db_query']('', ' |
|
| 387 | 394 | SHOW TABLE STATUS |
| 388 | 395 | LIKE {string:table_name}', |
| 389 | 396 | array( |
| 390 | 397 | 'table_name' => str_replace('_', '\_', $db_prefix) . 'log_search_words', |
| 391 | 398 | ) |
| 392 | 399 | ); |
| 400 | + } |
|
| 393 | 401 | if ($request !== false && $smcFunc['db_num_rows']($request) == 1) |
| 394 | 402 | { |
| 395 | 403 | // Only do this if the user has permission to execute this query. |
@@ -398,8 +406,7 @@ discard block |
||
| 398 | 406 | $context['table_info']['custom_index_length'] = $row['Data_length'] + $row['Index_length']; |
| 399 | 407 | $smcFunc['db_free_result']($request); |
| 400 | 408 | } |
| 401 | - } |
|
| 402 | - elseif ($db_type == 'postgresql') |
|
| 409 | + } elseif ($db_type == 'postgresql') |
|
| 403 | 410 | { |
| 404 | 411 | // In order to report the sizes correctly we need to perform vacuum (optimize) on the tables we will be using. |
| 405 | 412 | //db_extend(); |
@@ -441,38 +448,38 @@ discard block |
||
| 441 | 448 | $context['table_info']['data_length'] = (int) $row['table_size']; |
| 442 | 449 | $context['table_info']['index_length'] = (int) $row['index_size']; |
| 443 | 450 | $context['table_info']['fulltext_length'] = (int) $row['index_size']; |
| 444 | - } |
|
| 445 | - elseif ($row['indexname'] == $db_prefix. 'log_search_words') |
|
| 451 | + } elseif ($row['indexname'] == $db_prefix. 'log_search_words') |
|
| 446 | 452 | { |
| 447 | 453 | $context['table_info']['index_length'] = (int) $row['index_size']; |
| 448 | 454 | $context['table_info']['custom_index_length'] = (int) $row['index_size']; |
| 449 | 455 | } |
| 450 | 456 | } |
| 451 | 457 | $smcFunc['db_free_result']($request); |
| 452 | - } |
|
| 453 | - else |
|
| 454 | - // Didn't work for some reason... |
|
| 458 | + } else { |
|
| 459 | + // Didn't work for some reason... |
|
| 455 | 460 | $context['table_info'] = array( |
| 456 | 461 | 'data_length' => $txt['not_applicable'], |
| 457 | 462 | 'index_length' => $txt['not_applicable'], |
| 458 | 463 | 'fulltext_length' => $txt['not_applicable'], |
| 459 | 464 | 'custom_index_length' => $txt['not_applicable'], |
| 460 | 465 | ); |
| 461 | - } |
|
| 462 | - else |
|
| 463 | - $context['table_info'] = array( |
|
| 466 | + } |
|
| 467 | + } else { |
|
| 468 | + $context['table_info'] = array( |
|
| 464 | 469 | 'data_length' => $txt['not_applicable'], |
| 465 | 470 | 'index_length' => $txt['not_applicable'], |
| 466 | 471 | 'fulltext_length' => $txt['not_applicable'], |
| 467 | 472 | 'custom_index_length' => $txt['not_applicable'], |
| 468 | 473 | ); |
| 474 | + } |
|
| 469 | 475 | |
| 470 | 476 | // Format the data and index length in kilobytes. |
| 471 | 477 | foreach ($context['table_info'] as $type => $size) |
| 472 | 478 | { |
| 473 | 479 | // If it's not numeric then just break. This database engine doesn't support size. |
| 474 | - if (!is_numeric($size)) |
|
| 475 | - break; |
|
| 480 | + if (!is_numeric($size)) { |
|
| 481 | + break; |
|
| 482 | + } |
|
| 476 | 483 | |
| 477 | 484 | $context['table_info'][$type] = comma_format($context['table_info'][$type] / 1024) . ' ' . $txt['search_method_kilobytes']; |
| 478 | 485 | } |
@@ -501,8 +508,9 @@ discard block |
||
| 501 | 508 | |
| 502 | 509 | // Scotty, we need more time... |
| 503 | 510 | @set_time_limit(600); |
| 504 | - if (function_exists('apache_reset_timeout')) |
|
| 505 | - @apache_reset_timeout(); |
|
| 511 | + if (function_exists('apache_reset_timeout')) { |
|
| 512 | + @apache_reset_timeout(); |
|
| 513 | + } |
|
| 506 | 514 | |
| 507 | 515 | $context[$context['admin_menu_name']]['current_subsection'] = 'method'; |
| 508 | 516 | $context['page_title'] = $txt['search_index_custom']; |
@@ -532,8 +540,7 @@ discard block |
||
| 532 | 540 | $context['start'] = (int) $context['index_settings']['resume_at']; |
| 533 | 541 | unset($context['index_settings']['resume_at']); |
| 534 | 542 | $context['step'] = 1; |
| 535 | - } |
|
| 536 | - else |
|
| 543 | + } else |
|
| 537 | 544 | { |
| 538 | 545 | $context['index_settings'] = array( |
| 539 | 546 | 'bytes_per_word' => isset($_REQUEST['bytes_per_word']) && isset($index_properties[$_REQUEST['bytes_per_word']]) ? (int) $_REQUEST['bytes_per_word'] : 2, |
@@ -542,12 +549,14 @@ discard block |
||
| 542 | 549 | $context['step'] = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0; |
| 543 | 550 | |
| 544 | 551 | // admin timeouts are painful when building these long indexes - but only if we actually have such things enabled |
| 545 | - if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1) |
|
| 546 | - $_SESSION['admin_time'] = time(); |
|
| 552 | + if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1) { |
|
| 553 | + $_SESSION['admin_time'] = time(); |
|
| 554 | + } |
|
| 547 | 555 | } |
| 548 | 556 | |
| 549 | - if ($context['step'] !== 0) |
|
| 550 | - checkSession('request'); |
|
| 557 | + if ($context['step'] !== 0) { |
|
| 558 | + checkSession('request'); |
|
| 559 | + } |
|
| 551 | 560 | |
| 552 | 561 | // Step 0: let the user determine how they like their index. |
| 553 | 562 | if ($context['step'] === 0) |
@@ -576,12 +585,14 @@ discard block |
||
| 576 | 585 | $smcFunc['db_create_word_search']($index_properties[$context['index_settings']['bytes_per_word']]['column_definition']); |
| 577 | 586 | |
| 578 | 587 | // Temporarily switch back to not using a search index. |
| 579 | - if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') |
|
| 580 | - updateSettings(array('search_index' => '')); |
|
| 588 | + if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') { |
|
| 589 | + updateSettings(array('search_index' => '')); |
|
| 590 | + } |
|
| 581 | 591 | |
| 582 | 592 | // Don't let simultanious processes be updating the search index. |
| 583 | - if (!empty($modSettings['search_custom_index_config'])) |
|
| 584 | - updateSettings(array('search_custom_index_config' => '')); |
|
| 593 | + if (!empty($modSettings['search_custom_index_config'])) { |
|
| 594 | + updateSettings(array('search_custom_index_config' => '')); |
|
| 595 | + } |
|
| 585 | 596 | } |
| 586 | 597 | |
| 587 | 598 | $num_messages = array( |
@@ -597,16 +608,16 @@ discard block |
||
| 597 | 608 | 'starting_id' => $context['start'], |
| 598 | 609 | ) |
| 599 | 610 | ); |
| 600 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 601 | - $num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages']; |
|
| 611 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 612 | + $num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages']; |
|
| 613 | + } |
|
| 602 | 614 | |
| 603 | 615 | if (empty($num_messages['todo'])) |
| 604 | 616 | { |
| 605 | 617 | $context['step'] = 2; |
| 606 | 618 | $context['percentage'] = 80; |
| 607 | 619 | $context['start'] = 0; |
| 608 | - } |
|
| 609 | - else |
|
| 620 | + } else |
|
| 610 | 621 | { |
| 611 | 622 | // Number of seconds before the next step. |
| 612 | 623 | $stop = time() + 3; |
@@ -647,21 +658,22 @@ discard block |
||
| 647 | 658 | |
| 648 | 659 | $context['start'] += $forced_break ? $number_processed : $messages_per_batch; |
| 649 | 660 | |
| 650 | - if (!empty($inserts)) |
|
| 651 | - $smcFunc['db_insert']('ignore', |
|
| 661 | + if (!empty($inserts)) { |
|
| 662 | + $smcFunc['db_insert']('ignore', |
|
| 652 | 663 | '{db_prefix}log_search_words', |
| 653 | 664 | array('id_word' => 'int', 'id_msg' => 'int'), |
| 654 | 665 | $inserts, |
| 655 | 666 | array('id_word', 'id_msg') |
| 656 | 667 | ); |
| 668 | + } |
|
| 657 | 669 | if ($num_messages['todo'] === 0) |
| 658 | 670 | { |
| 659 | 671 | $context['step'] = 2; |
| 660 | 672 | $context['start'] = 0; |
| 661 | 673 | break; |
| 674 | + } else { |
|
| 675 | + updateSettings(array('search_custom_index_resume' => json_encode(array_merge($context['index_settings'], array('resume_at' => $context['start']))))); |
|
| 662 | 676 | } |
| 663 | - else |
|
| 664 | - updateSettings(array('search_custom_index_resume' => json_encode(array_merge($context['index_settings'], array('resume_at' => $context['start']))))); |
|
| 665 | 677 | } |
| 666 | 678 | |
| 667 | 679 | // Since there are still two steps to go, 80% is the maximum here. |
@@ -672,9 +684,9 @@ discard block |
||
| 672 | 684 | // Step 2: removing the words that occur too often and are of no use. |
| 673 | 685 | elseif ($context['step'] === 2) |
| 674 | 686 | { |
| 675 | - if ($context['index_settings']['bytes_per_word'] < 4) |
|
| 676 | - $context['step'] = 3; |
|
| 677 | - else |
|
| 687 | + if ($context['index_settings']['bytes_per_word'] < 4) { |
|
| 688 | + $context['step'] = 3; |
|
| 689 | + } else |
|
| 678 | 690 | { |
| 679 | 691 | $stop_words = $context['start'] === 0 || empty($modSettings['search_stopwords']) ? array() : explode(',', $modSettings['search_stopwords']); |
| 680 | 692 | $stop = time() + 3; |
@@ -695,20 +707,22 @@ discard block |
||
| 695 | 707 | 'minimum_messages' => $max_messages, |
| 696 | 708 | ) |
| 697 | 709 | ); |
| 698 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 699 | - $stop_words[] = $row['id_word']; |
|
| 710 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 711 | + $stop_words[] = $row['id_word']; |
|
| 712 | + } |
|
| 700 | 713 | $smcFunc['db_free_result']($request); |
| 701 | 714 | |
| 702 | 715 | updateSettings(array('search_stopwords' => implode(',', $stop_words))); |
| 703 | 716 | |
| 704 | - if (!empty($stop_words)) |
|
| 705 | - $smcFunc['db_query']('', ' |
|
| 717 | + if (!empty($stop_words)) { |
|
| 718 | + $smcFunc['db_query']('', ' |
|
| 706 | 719 | DELETE FROM {db_prefix}log_search_words |
| 707 | 720 | WHERE id_word in ({array_int:stop_words})', |
| 708 | 721 | array( |
| 709 | 722 | 'stop_words' => $stop_words, |
| 710 | 723 | ) |
| 711 | 724 | ); |
| 725 | + } |
|
| 712 | 726 | |
| 713 | 727 | $context['start'] += $index_properties[$context['index_settings']['bytes_per_word']]['step_size']; |
| 714 | 728 | if ($context['start'] > $index_properties[$context['index_settings']['bytes_per_word']]['max_size']) |
@@ -769,8 +783,9 @@ discard block |
||
| 769 | 783 | $searchAPI = new $search_class_name(); |
| 770 | 784 | |
| 771 | 785 | // No Support? NEXT! |
| 772 | - if (!$searchAPI->is_supported) |
|
| 773 | - continue; |
|
| 786 | + if (!$searchAPI->is_supported) { |
|
| 787 | + continue; |
|
| 788 | + } |
|
| 774 | 789 | |
| 775 | 790 | $apis[$index_name] = array( |
| 776 | 791 | 'filename' => $file, |
@@ -817,10 +832,10 @@ discard block |
||
| 817 | 832 | 'messages_ftx' => $db_prefix.'messages_ftx', |
| 818 | 833 | ) |
| 819 | 834 | ); |
| 820 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 821 | - $context['fulltext_index'][] = $row['indexname']; |
|
| 822 | - } |
|
| 823 | - else |
|
| 835 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 836 | + $context['fulltext_index'][] = $row['indexname']; |
|
| 837 | + } |
|
| 838 | + } else |
|
| 824 | 839 | { |
| 825 | 840 | $request = $smcFunc['db_query']('', ' |
| 826 | 841 | SHOW INDEX |
@@ -831,17 +846,19 @@ discard block |
||
| 831 | 846 | $context['fulltext_index'] = ''; |
| 832 | 847 | if ($request !== false || $smcFunc['db_num_rows']($request) != 0) |
| 833 | 848 | { |
| 834 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 835 | - if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
| 849 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 850 | + if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
| 836 | 851 | $context['fulltext_index'][] = $row['Key_name']; |
| 852 | + } |
|
| 837 | 853 | $smcFunc['db_free_result']($request); |
| 838 | 854 | |
| 839 | - if (is_array($context['fulltext_index'])) |
|
| 840 | - $context['fulltext_index'] = array_unique($context['fulltext_index']); |
|
| 855 | + if (is_array($context['fulltext_index'])) { |
|
| 856 | + $context['fulltext_index'] = array_unique($context['fulltext_index']); |
|
| 857 | + } |
|
| 841 | 858 | } |
| 842 | 859 | |
| 843 | - if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) |
|
| 844 | - $request = $smcFunc['db_query']('', ' |
|
| 860 | + if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) { |
|
| 861 | + $request = $smcFunc['db_query']('', ' |
|
| 845 | 862 | SHOW TABLE STATUS |
| 846 | 863 | FROM {string:database_name} |
| 847 | 864 | LIKE {string:table_name}', |
@@ -850,20 +867,22 @@ discard block |
||
| 850 | 867 | 'table_name' => str_replace('_', '\_', $match[2]) . 'messages', |
| 851 | 868 | ) |
| 852 | 869 | ); |
| 853 | - else |
|
| 854 | - $request = $smcFunc['db_query']('', ' |
|
| 870 | + } else { |
|
| 871 | + $request = $smcFunc['db_query']('', ' |
|
| 855 | 872 | SHOW TABLE STATUS |
| 856 | 873 | LIKE {string:table_name}', |
| 857 | 874 | array( |
| 858 | 875 | 'table_name' => str_replace('_', '\_', $db_prefix) . 'messages', |
| 859 | 876 | ) |
| 860 | 877 | ); |
| 878 | + } |
|
| 861 | 879 | |
| 862 | 880 | if ($request !== false) |
| 863 | 881 | { |
| 864 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 865 | - if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'], '5.6.4', '>='))) |
|
| 882 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 883 | + if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'], '5.6.4', '>='))) |
|
| 866 | 884 | $context['cannot_create_fulltext'] = true; |
| 885 | + } |
|
| 867 | 886 | $smcFunc['db_free_result']($request); |
| 868 | 887 | } |
| 869 | 888 | } |
@@ -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 | * Display some useful/interesting board statistics. |
@@ -30,8 +31,9 @@ discard block |
||
| 30 | 31 | |
| 31 | 32 | isAllowedTo('view_stats'); |
| 32 | 33 | // Page disabled - redirect them out |
| 33 | - if (empty($modSettings['trackStats'])) |
|
| 34 | - fatal_lang_error('feature_disabled', true); |
|
| 34 | + if (empty($modSettings['trackStats'])) { |
|
| 35 | + fatal_lang_error('feature_disabled', true); |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | if (!empty($_REQUEST['expand'])) |
| 37 | 39 | { |
@@ -39,31 +41,34 @@ discard block |
||
| 39 | 41 | |
| 40 | 42 | $month = (int) substr($_REQUEST['expand'], 4); |
| 41 | 43 | $year = (int) substr($_REQUEST['expand'], 0, 4); |
| 42 | - if ($year > 1900 && $year < 2200 && $month >= 1 && $month <= 12) |
|
| 43 | - $_SESSION['expanded_stats'][$year][] = $month; |
|
| 44 | - } |
|
| 45 | - elseif (!empty($_REQUEST['collapse'])) |
|
| 44 | + if ($year > 1900 && $year < 2200 && $month >= 1 && $month <= 12) { |
|
| 45 | + $_SESSION['expanded_stats'][$year][] = $month; |
|
| 46 | + } |
|
| 47 | + } elseif (!empty($_REQUEST['collapse'])) |
|
| 46 | 48 | { |
| 47 | 49 | $context['robot_no_index'] = true; |
| 48 | 50 | |
| 49 | 51 | $month = (int) substr($_REQUEST['collapse'], 4); |
| 50 | 52 | $year = (int) substr($_REQUEST['collapse'], 0, 4); |
| 51 | - if (!empty($_SESSION['expanded_stats'][$year])) |
|
| 52 | - $_SESSION['expanded_stats'][$year] = array_diff($_SESSION['expanded_stats'][$year], array($month)); |
|
| 53 | + if (!empty($_SESSION['expanded_stats'][$year])) { |
|
| 54 | + $_SESSION['expanded_stats'][$year] = array_diff($_SESSION['expanded_stats'][$year], array($month)); |
|
| 55 | + } |
|
| 53 | 56 | } |
| 54 | 57 | |
| 55 | 58 | // Handle the XMLHttpRequest. |
| 56 | 59 | if (isset($_REQUEST['xml'])) |
| 57 | 60 | { |
| 58 | 61 | // Collapsing stats only needs adjustments of the session variables. |
| 59 | - if (!empty($_REQUEST['collapse'])) |
|
| 60 | - obExit(false); |
|
| 62 | + if (!empty($_REQUEST['collapse'])) { |
|
| 63 | + obExit(false); |
|
| 64 | + } |
|
| 61 | 65 | |
| 62 | 66 | $context['sub_template'] = 'stats'; |
| 63 | 67 | $context['yearly'] = array(); |
| 64 | 68 | |
| 65 | - if (empty($month) || empty($year)) |
|
| 66 | - return; |
|
| 69 | + if (empty($month) || empty($year)) { |
|
| 70 | + return; |
|
| 71 | + } |
|
| 67 | 72 | |
| 68 | 73 | getDailyStats('YEAR(date) = {int:year} AND MONTH(date) = {int:month}', array('year' => $year, 'month' => $month)); |
| 69 | 74 | $context['yearly'][$year]['months'][$month]['date'] = array( |
@@ -220,8 +225,9 @@ discard block |
||
| 220 | 225 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>' |
| 221 | 226 | ); |
| 222 | 227 | |
| 223 | - if ($max_num_posts < $row_members['posts']) |
|
| 224 | - $max_num_posts = $row_members['posts']; |
|
| 228 | + if ($max_num_posts < $row_members['posts']) { |
|
| 229 | + $max_num_posts = $row_members['posts']; |
|
| 230 | + } |
|
| 225 | 231 | } |
| 226 | 232 | $smcFunc['db_free_result']($members_result); |
| 227 | 233 | |
@@ -257,8 +263,9 @@ discard block |
||
| 257 | 263 | 'link' => '<a href="' . $scripturl . '?board=' . $row_board['id_board'] . '.0">' . $row_board['name'] . '</a>' |
| 258 | 264 | ); |
| 259 | 265 | |
| 260 | - if ($max_num_posts < $row_board['num_posts']) |
|
| 261 | - $max_num_posts = $row_board['num_posts']; |
|
| 266 | + if ($max_num_posts < $row_board['num_posts']) { |
|
| 267 | + $max_num_posts = $row_board['num_posts']; |
|
| 268 | + } |
|
| 262 | 269 | } |
| 263 | 270 | $smcFunc['db_free_result']($boards_result); |
| 264 | 271 | |
@@ -284,12 +291,13 @@ discard block |
||
| 284 | 291 | ) |
| 285 | 292 | ); |
| 286 | 293 | $topic_ids = array(); |
| 287 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 288 | - $topic_ids[] = $row['id_topic']; |
|
| 294 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 295 | + $topic_ids[] = $row['id_topic']; |
|
| 296 | + } |
|
| 289 | 297 | $smcFunc['db_free_result']($request); |
| 298 | + } else { |
|
| 299 | + $topic_ids = array(); |
|
| 290 | 300 | } |
| 291 | - else |
|
| 292 | - $topic_ids = array(); |
|
| 293 | 301 | |
| 294 | 302 | // Topic replies top 10. |
| 295 | 303 | $topic_reply_result = $smcFunc['db_query']('', ' |
@@ -329,8 +337,9 @@ discard block |
||
| 329 | 337 | 'link' => '<a href="' . $scripturl . '?topic=' . $row_topic_reply['id_topic'] . '.0">' . $row_topic_reply['subject'] . '</a>' |
| 330 | 338 | ); |
| 331 | 339 | |
| 332 | - if ($max_num_replies < $row_topic_reply['num_replies']) |
|
| 333 | - $max_num_replies = $row_topic_reply['num_replies']; |
|
| 340 | + if ($max_num_replies < $row_topic_reply['num_replies']) { |
|
| 341 | + $max_num_replies = $row_topic_reply['num_replies']; |
|
| 342 | + } |
|
| 334 | 343 | } |
| 335 | 344 | $smcFunc['db_free_result']($topic_reply_result); |
| 336 | 345 | |
@@ -354,12 +363,13 @@ discard block |
||
| 354 | 363 | ) |
| 355 | 364 | ); |
| 356 | 365 | $topic_ids = array(); |
| 357 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 358 | - $topic_ids[] = $row['id_topic']; |
|
| 366 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 367 | + $topic_ids[] = $row['id_topic']; |
|
| 368 | + } |
|
| 359 | 369 | $smcFunc['db_free_result']($request); |
| 370 | + } else { |
|
| 371 | + $topic_ids = array(); |
|
| 360 | 372 | } |
| 361 | - else |
|
| 362 | - $topic_ids = array(); |
|
| 363 | 373 | |
| 364 | 374 | // Topic views top 10. |
| 365 | 375 | $topic_view_result = $smcFunc['db_query']('', ' |
@@ -399,8 +409,9 @@ discard block |
||
| 399 | 409 | 'link' => '<a href="' . $scripturl . '?topic=' . $row_topic_views['id_topic'] . '.0">' . $row_topic_views['subject'] . '</a>' |
| 400 | 410 | ); |
| 401 | 411 | |
| 402 | - if ($max_num < $row_topic_views['num_views']) |
|
| 403 | - $max_num = $row_topic_views['num_views']; |
|
| 412 | + if ($max_num < $row_topic_views['num_views']) { |
|
| 413 | + $max_num = $row_topic_views['num_views']; |
|
| 414 | + } |
|
| 404 | 415 | } |
| 405 | 416 | $smcFunc['db_free_result']($topic_view_result); |
| 406 | 417 | |
@@ -425,15 +436,17 @@ discard block |
||
| 425 | 436 | ) |
| 426 | 437 | ); |
| 427 | 438 | $members = array(); |
| 428 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 429 | - $members[$row['id_member_started']] = $row['hits']; |
|
| 439 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 440 | + $members[$row['id_member_started']] = $row['hits']; |
|
| 441 | + } |
|
| 430 | 442 | $smcFunc['db_free_result']($request); |
| 431 | 443 | |
| 432 | 444 | cache_put_data('stats_top_starters', $members, 360); |
| 433 | 445 | } |
| 434 | 446 | |
| 435 | - if (empty($members)) |
|
| 436 | - $members = array(0 => 0); |
|
| 447 | + if (empty($members)) { |
|
| 448 | + $members = array(0 => 0); |
|
| 449 | + } |
|
| 437 | 450 | |
| 438 | 451 | // Topic poster top 10. |
| 439 | 452 | $members_result = $smcFunc['db_query']('', ' |
@@ -458,8 +471,9 @@ discard block |
||
| 458 | 471 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>' |
| 459 | 472 | ); |
| 460 | 473 | |
| 461 | - if ($max_num < $members[$row_members['id_member']]) |
|
| 462 | - $max_num = $members[$row_members['id_member']]; |
|
| 474 | + if ($max_num < $members[$row_members['id_member']]) { |
|
| 475 | + $max_num = $members[$row_members['id_member']]; |
|
| 476 | + } |
|
| 463 | 477 | } |
| 464 | 478 | ksort($context['stats_blocks']['starters']); |
| 465 | 479 | $smcFunc['db_free_result']($members_result); |
@@ -488,8 +502,9 @@ discard block |
||
| 488 | 502 | while ($row_members = $smcFunc['db_fetch_assoc']($members_result)) |
| 489 | 503 | { |
| 490 | 504 | $temp2[] = (int) $row_members['id_member']; |
| 491 | - if (count($context['stats_blocks']['time_online']) >= 10) |
|
| 492 | - continue; |
|
| 505 | + if (count($context['stats_blocks']['time_online']) >= 10) { |
|
| 506 | + continue; |
|
| 507 | + } |
|
| 493 | 508 | |
| 494 | 509 | // Figure out the days, hours and minutes. |
| 495 | 510 | $timeDays = floor($row_members['total_time_logged_in'] / 86400); |
@@ -497,10 +512,12 @@ discard block |
||
| 497 | 512 | |
| 498 | 513 | // Figure out which things to show... (days, hours, minutes, etc.) |
| 499 | 514 | $timelogged = ''; |
| 500 | - if ($timeDays > 0) |
|
| 501 | - $timelogged .= $timeDays . $txt['totalTimeLogged5']; |
|
| 502 | - if ($timeHours > 0) |
|
| 503 | - $timelogged .= $timeHours . $txt['totalTimeLogged6']; |
|
| 515 | + if ($timeDays > 0) { |
|
| 516 | + $timelogged .= $timeDays . $txt['totalTimeLogged5']; |
|
| 517 | + } |
|
| 518 | + if ($timeHours > 0) { |
|
| 519 | + $timelogged .= $timeHours . $txt['totalTimeLogged6']; |
|
| 520 | + } |
|
| 504 | 521 | $timelogged .= floor(($row_members['total_time_logged_in'] % 3600) / 60) . $txt['totalTimeLogged7']; |
| 505 | 522 | |
| 506 | 523 | $context['stats_blocks']['time_online'][] = array( |
@@ -512,17 +529,20 @@ discard block |
||
| 512 | 529 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>' |
| 513 | 530 | ); |
| 514 | 531 | |
| 515 | - if ($max_time_online < $row_members['total_time_logged_in']) |
|
| 516 | - $max_time_online = $row_members['total_time_logged_in']; |
|
| 532 | + if ($max_time_online < $row_members['total_time_logged_in']) { |
|
| 533 | + $max_time_online = $row_members['total_time_logged_in']; |
|
| 534 | + } |
|
| 517 | 535 | } |
| 518 | 536 | $smcFunc['db_free_result']($members_result); |
| 519 | 537 | |
| 520 | - foreach ($context['stats_blocks']['time_online'] as $i => $member) |
|
| 521 | - $context['stats_blocks']['time_online'][$i]['percent'] = round(($member['seconds_online'] * 100) / $max_time_online); |
|
| 538 | + foreach ($context['stats_blocks']['time_online'] as $i => $member) { |
|
| 539 | + $context['stats_blocks']['time_online'][$i]['percent'] = round(($member['seconds_online'] * 100) / $max_time_online); |
|
| 540 | + } |
|
| 522 | 541 | |
| 523 | 542 | // Cache the ones we found for a bit, just so we don't have to look again. |
| 524 | - if ($temp !== $temp2) |
|
| 525 | - cache_put_data('stats_total_time_members', $temp2, 480); |
|
| 543 | + if ($temp !== $temp2) { |
|
| 544 | + cache_put_data('stats_total_time_members', $temp2, 480); |
|
| 545 | + } |
|
| 526 | 546 | |
| 527 | 547 | // Likes. |
| 528 | 548 | if (!empty($modSettings['enable_likes'])) |
@@ -558,13 +578,15 @@ discard block |
||
| 558 | 578 | 'link' => '<a href="' . $scripturl . '?msg=' . $row_liked_message['id_msg'] .'">' . $row_liked_message['subject'] . '</a>' |
| 559 | 579 | ); |
| 560 | 580 | |
| 561 | - if ($max_liked_message < $row_liked_message['likes']) |
|
| 562 | - $max_liked_message = $row_liked_message['likes']; |
|
| 581 | + if ($max_liked_message < $row_liked_message['likes']) { |
|
| 582 | + $max_liked_message = $row_liked_message['likes']; |
|
| 583 | + } |
|
| 563 | 584 | } |
| 564 | 585 | $smcFunc['db_free_result']($liked_messages); |
| 565 | 586 | |
| 566 | - foreach ($context['stats_blocks']['liked_messages'] as $i => $liked_messages) |
|
| 567 | - $context['stats_blocks']['liked_messages'][$i]['percent'] = round(($liked_messages['num'] * 100) / $max_liked_message); |
|
| 587 | + foreach ($context['stats_blocks']['liked_messages'] as $i => $liked_messages) { |
|
| 588 | + $context['stats_blocks']['liked_messages'][$i]['percent'] = round(($liked_messages['num'] * 100) / $max_liked_message); |
|
| 589 | + } |
|
| 568 | 590 | |
| 569 | 591 | // Liked users top 10. |
| 570 | 592 | $context['stats_blocks']['liked_users'] = array(); |
@@ -595,14 +617,16 @@ discard block |
||
| 595 | 617 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_liked_users['liked_user'] . '">' . $row_liked_users['real_name'] . '</a>', |
| 596 | 618 | ); |
| 597 | 619 | |
| 598 | - if ($max_liked_users < $row_liked_users['count']) |
|
| 599 | - $max_liked_users = $row_liked_users['count']; |
|
| 620 | + if ($max_liked_users < $row_liked_users['count']) { |
|
| 621 | + $max_liked_users = $row_liked_users['count']; |
|
| 622 | + } |
|
| 600 | 623 | } |
| 601 | 624 | |
| 602 | 625 | $smcFunc['db_free_result']($liked_users); |
| 603 | 626 | |
| 604 | - foreach ($context['stats_blocks']['liked_users'] as $i => $liked_users) |
|
| 605 | - $context['stats_blocks']['liked_users'][$i]['percent'] = round(($liked_users['num'] * 100) / $max_liked_users); |
|
| 627 | + foreach ($context['stats_blocks']['liked_users'] as $i => $liked_users) { |
|
| 628 | + $context['stats_blocks']['liked_users'][$i]['percent'] = round(($liked_users['num'] * 100) / $max_liked_users); |
|
| 629 | + } |
|
| 606 | 630 | } |
| 607 | 631 | |
| 608 | 632 | // Activity by month. |
@@ -620,8 +644,8 @@ discard block |
||
| 620 | 644 | $ID_MONTH = $row_months['stats_year'] . sprintf('%02d', $row_months['stats_month']); |
| 621 | 645 | $expanded = !empty($_SESSION['expanded_stats'][$row_months['stats_year']]) && in_array($row_months['stats_month'], $_SESSION['expanded_stats'][$row_months['stats_year']]); |
| 622 | 646 | |
| 623 | - if (!isset($context['yearly'][$row_months['stats_year']])) |
|
| 624 | - $context['yearly'][$row_months['stats_year']] = array( |
|
| 647 | + if (!isset($context['yearly'][$row_months['stats_year']])) { |
|
| 648 | + $context['yearly'][$row_months['stats_year']] = array( |
|
| 625 | 649 | 'year' => $row_months['stats_year'], |
| 626 | 650 | 'new_topics' => 0, |
| 627 | 651 | 'new_posts' => 0, |
@@ -633,6 +657,7 @@ discard block |
||
| 633 | 657 | 'expanded' => false, |
| 634 | 658 | 'current_year' => $row_months['stats_year'] == date('Y'), |
| 635 | 659 | ); |
| 660 | + } |
|
| 636 | 661 | |
| 637 | 662 | $context['yearly'][$row_months['stats_year']]['months'][(int) $row_months['stats_month']] = array( |
| 638 | 663 | 'id' => $ID_MONTH, |
@@ -678,26 +703,30 @@ discard block |
||
| 678 | 703 | $context['yearly'][$year]['hits'] = comma_format($data['hits']); |
| 679 | 704 | |
| 680 | 705 | // Keep a list of collapsed years. |
| 681 | - if (!$data['expanded'] && !$data['current_year']) |
|
| 682 | - $context['collapsed_years'][] = $year; |
|
| 706 | + if (!$data['expanded'] && !$data['current_year']) { |
|
| 707 | + $context['collapsed_years'][] = $year; |
|
| 708 | + } |
|
| 683 | 709 | } |
| 684 | 710 | |
| 685 | - if (empty($_SESSION['expanded_stats'])) |
|
| 686 | - return; |
|
| 711 | + if (empty($_SESSION['expanded_stats'])) { |
|
| 712 | + return; |
|
| 713 | + } |
|
| 687 | 714 | |
| 688 | 715 | $condition_text = array(); |
| 689 | 716 | $condition_params = array(); |
| 690 | - foreach ($_SESSION['expanded_stats'] as $year => $months) |
|
| 691 | - if (!empty($months)) |
|
| 717 | + foreach ($_SESSION['expanded_stats'] as $year => $months) { |
|
| 718 | + if (!empty($months)) |
|
| 692 | 719 | { |
| 693 | 720 | $condition_text[] = 'YEAR(date) = {int:year_' . $year . '} AND MONTH(date) IN ({array_int:months_' . $year . '})'; |
| 721 | + } |
|
| 694 | 722 | $condition_params['year_' . $year] = $year; |
| 695 | 723 | $condition_params['months_' . $year] = $months; |
| 696 | 724 | } |
| 697 | 725 | |
| 698 | 726 | // No daily stats to even look at? |
| 699 | - if (empty($condition_text)) |
|
| 700 | - return; |
|
| 727 | + if (empty($condition_text)) { |
|
| 728 | + return; |
|
| 729 | + } |
|
| 701 | 730 | |
| 702 | 731 | getDailyStats(implode(' OR ', $condition_text), $condition_params); |
| 703 | 732 | |
@@ -723,8 +752,8 @@ discard block |
||
| 723 | 752 | ORDER BY stats_day ASC', |
| 724 | 753 | $condition_parameters |
| 725 | 754 | ); |
| 726 | - while ($row_days = $smcFunc['db_fetch_assoc']($days_result)) |
|
| 727 | - $context['yearly'][$row_days['stats_year']]['months'][(int) $row_days['stats_month']]['days'][] = array( |
|
| 755 | + while ($row_days = $smcFunc['db_fetch_assoc']($days_result)) { |
|
| 756 | + $context['yearly'][$row_days['stats_year']]['months'][(int) $row_days['stats_month']]['days'][] = array( |
|
| 728 | 757 | 'day' => sprintf('%02d', $row_days['stats_day']), |
| 729 | 758 | 'month' => sprintf('%02d', $row_days['stats_month']), |
| 730 | 759 | 'year' => $row_days['stats_year'], |
@@ -734,6 +763,7 @@ discard block |
||
| 734 | 763 | 'most_members_online' => comma_format($row_days['most_on']), |
| 735 | 764 | 'hits' => comma_format($row_days['hits']) |
| 736 | 765 | ); |
| 766 | + } |
|
| 737 | 767 | $smcFunc['db_free_result']($days_result); |
| 738 | 768 | } |
| 739 | 769 | |
@@ -752,16 +782,19 @@ discard block |
||
| 752 | 782 | global $modSettings, $user_info, $forum_version, $sourcedir; |
| 753 | 783 | |
| 754 | 784 | // First, is it disabled? |
| 755 | - if (empty($modSettings['allow_sm_stats'])) |
|
| 756 | - die(); |
|
| 785 | + if (empty($modSettings['allow_sm_stats'])) { |
|
| 786 | + die(); |
|
| 787 | + } |
|
| 757 | 788 | |
| 758 | 789 | // Are we saying who we are, and are we right? (OR an admin) |
| 759 | - if (!$user_info['is_admin'] && (!isset($_GET['sid']) || $_GET['sid'] != $modSettings['allow_sm_stats'])) |
|
| 760 | - die(); |
|
| 790 | + if (!$user_info['is_admin'] && (!isset($_GET['sid']) || $_GET['sid'] != $modSettings['allow_sm_stats'])) { |
|
| 791 | + die(); |
|
| 792 | + } |
|
| 761 | 793 | |
| 762 | 794 | // Verify the referer... |
| 763 | - if (!$user_info['is_admin'] && (!isset($_SERVER['HTTP_REFERER']) || md5($_SERVER['HTTP_REFERER']) != '746cb59a1a0d5cf4bd240e5a67c73085')) |
|
| 764 | - die(); |
|
| 795 | + if (!$user_info['is_admin'] && (!isset($_SERVER['HTTP_REFERER']) || md5($_SERVER['HTTP_REFERER']) != '746cb59a1a0d5cf4bd240e5a67c73085')) { |
|
| 796 | + die(); |
|
| 797 | + } |
|
| 765 | 798 | |
| 766 | 799 | // Get some server versions. |
| 767 | 800 | require_once($sourcedir . '/Subs-Admin.php'); |
@@ -787,16 +820,17 @@ discard block |
||
| 787 | 820 | ); |
| 788 | 821 | |
| 789 | 822 | // Encode all the data, for security. |
| 790 | - foreach ($stats_to_send as $k => $v) |
|
| 791 | - $stats_to_send[$k] = urlencode($k) . '=' . urlencode($v); |
|
| 823 | + foreach ($stats_to_send as $k => $v) { |
|
| 824 | + $stats_to_send[$k] = urlencode($k) . '=' . urlencode($v); |
|
| 825 | + } |
|
| 792 | 826 | |
| 793 | 827 | // Turn this into the query string! |
| 794 | 828 | $stats_to_send = implode('&', $stats_to_send); |
| 795 | 829 | |
| 796 | 830 | // If we're an admin, just plonk them out. |
| 797 | - if ($user_info['is_admin']) |
|
| 798 | - echo $stats_to_send; |
|
| 799 | - else |
|
| 831 | + if ($user_info['is_admin']) { |
|
| 832 | + echo $stats_to_send; |
|
| 833 | + } else |
|
| 800 | 834 | { |
| 801 | 835 | // Connect to the collection script. |
| 802 | 836 | $fp = @fsockopen('www.simplemachines.org', 80, $errno, $errstr); |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * The main admin handling function.<br> |
@@ -444,8 +445,9 @@ discard block |
||
| 444 | 445 | foreach ($admin_includes as $include) |
| 445 | 446 | { |
| 446 | 447 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
| 447 | - if (file_exists($include)) |
|
| 448 | - require_once($include); |
|
| 448 | + if (file_exists($include)) { |
|
| 449 | + require_once($include); |
|
| 450 | + } |
|
| 449 | 451 | } |
| 450 | 452 | } |
| 451 | 453 | |
@@ -457,24 +459,27 @@ discard block |
||
| 457 | 459 | unset($admin_areas); |
| 458 | 460 | |
| 459 | 461 | // Nothing valid? |
| 460 | - if ($admin_include_data == false) |
|
| 461 | - fatal_lang_error('no_access', false); |
|
| 462 | + if ($admin_include_data == false) { |
|
| 463 | + fatal_lang_error('no_access', false); |
|
| 464 | + } |
|
| 462 | 465 | |
| 463 | 466 | // Build the link tree. |
| 464 | 467 | $context['linktree'][] = array( |
| 465 | 468 | 'url' => $scripturl . '?action=admin', |
| 466 | 469 | 'name' => $txt['admin_center'], |
| 467 | 470 | ); |
| 468 | - if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index') |
|
| 469 | - $context['linktree'][] = array( |
|
| 471 | + if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index') { |
|
| 472 | + $context['linktree'][] = array( |
|
| 470 | 473 | 'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';' . $context['session_var'] . '=' . $context['session_id'], |
| 471 | 474 | 'name' => $admin_include_data['label'], |
| 472 | 475 | ); |
| 473 | - if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label']) |
|
| 474 | - $context['linktree'][] = array( |
|
| 476 | + } |
|
| 477 | + if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label']) { |
|
| 478 | + $context['linktree'][] = array( |
|
| 475 | 479 | 'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';sa=' . $admin_include_data['current_subsection'] . ';' . $context['session_var'] . '=' . $context['session_id'], |
| 476 | 480 | 'name' => $admin_include_data['subsections'][$admin_include_data['current_subsection']][0], |
| 477 | 481 | ); |
| 482 | + } |
|
| 478 | 483 | |
| 479 | 484 | // Make a note of the Unique ID for this menu. |
| 480 | 485 | $context['admin_menu_id'] = $context['max_menu_id']; |
@@ -484,16 +489,18 @@ discard block |
||
| 484 | 489 | $context['admin_area'] = $admin_include_data['current_area']; |
| 485 | 490 | |
| 486 | 491 | // Now - finally - call the right place! |
| 487 | - if (isset($admin_include_data['file'])) |
|
| 488 | - require_once($sourcedir . '/' . $admin_include_data['file']); |
|
| 492 | + if (isset($admin_include_data['file'])) { |
|
| 493 | + require_once($sourcedir . '/' . $admin_include_data['file']); |
|
| 494 | + } |
|
| 489 | 495 | |
| 490 | 496 | // Get the right callable. |
| 491 | 497 | $call = call_helper($admin_include_data['function'], true); |
| 492 | 498 | |
| 493 | 499 | // Is it valid? |
| 494 | - if (!empty($call)) |
|
| 495 | - call_user_func($call); |
|
| 496 | -} |
|
| 500 | + if (!empty($call)) { |
|
| 501 | + call_user_func($call); |
|
| 502 | + } |
|
| 503 | + } |
|
| 497 | 504 | |
| 498 | 505 | /** |
| 499 | 506 | * The main administration section. |
@@ -547,13 +554,14 @@ discard block |
||
| 547 | 554 | |
| 548 | 555 | $context['sub_template'] = $context['admin_area'] == 'credits' ? 'credits' : 'admin'; |
| 549 | 556 | $context['page_title'] = $context['admin_area'] == 'credits' ? $txt['support_credits_title'] : $txt['admin_center']; |
| 550 | - if ($context['admin_area'] != 'credits') |
|
| 551 | - $context[$context['admin_menu_name']]['tab_data'] = array( |
|
| 557 | + if ($context['admin_area'] != 'credits') { |
|
| 558 | + $context[$context['admin_menu_name']]['tab_data'] = array( |
|
| 552 | 559 | 'title' => $txt['admin_center'], |
| 553 | 560 | 'help' => '', |
| 554 | 561 | 'description' => '<strong>' . $txt['hello_guest'] . ' ' . $context['user']['name'] . '!</strong> |
| 555 | 562 | ' . sprintf($txt['admin_main_welcome'], $txt['admin_center'], $txt['help'], $txt['help']), |
| 556 | 563 | ); |
| 564 | + } |
|
| 557 | 565 | |
| 558 | 566 | // Lastly, fill in the blanks in the support resources paragraphs. |
| 559 | 567 | $txt['support_resources_p1'] = sprintf($txt['support_resources_p1'], |
@@ -571,9 +579,10 @@ discard block |
||
| 571 | 579 | 'http://www.simplemachines.org/redirect/customize_support' |
| 572 | 580 | ); |
| 573 | 581 | |
| 574 | - if ($context['admin_area'] == 'admin') |
|
| 575 | - loadJavaScriptFile('admin.js', array('defer' => false), 'smf_admin'); |
|
| 576 | -} |
|
| 582 | + if ($context['admin_area'] == 'admin') { |
|
| 583 | + loadJavaScriptFile('admin.js', array('defer' => false), 'smf_admin'); |
|
| 584 | + } |
|
| 585 | + } |
|
| 577 | 586 | |
| 578 | 587 | /** |
| 579 | 588 | * Get one of the admin information files from Simple Machines. |
@@ -584,8 +593,9 @@ discard block |
||
| 584 | 593 | |
| 585 | 594 | setMemoryLimit('32M'); |
| 586 | 595 | |
| 587 | - if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename'])) |
|
| 588 | - fatal_lang_error('no_access', false); |
|
| 596 | + if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename'])) { |
|
| 597 | + fatal_lang_error('no_access', false); |
|
| 598 | + } |
|
| 589 | 599 | |
| 590 | 600 | // Strip off the forum cache part or we won't find it... |
| 591 | 601 | $_REQUEST['filename'] = str_replace($modSettings['browser_cache'], '', $_REQUEST['filename']); |
@@ -600,27 +610,30 @@ discard block |
||
| 600 | 610 | ) |
| 601 | 611 | ); |
| 602 | 612 | |
| 603 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 604 | - fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']), 404); |
|
| 613 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 614 | + fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']), 404); |
|
| 615 | + } |
|
| 605 | 616 | |
| 606 | 617 | list ($file_data, $filetype) = $smcFunc['db_fetch_row']($request); |
| 607 | 618 | $smcFunc['db_free_result']($request); |
| 608 | 619 | |
| 609 | 620 | // @todo Temp |
| 610 | 621 | // Figure out if sesc is still being used. |
| 611 | - if (strpos($file_data, ';sesc=') !== false && $filetype == 'text/javascript') |
|
| 612 | - $file_data = ' |
|
| 622 | + if (strpos($file_data, ';sesc=') !== false && $filetype == 'text/javascript') { |
|
| 623 | + $file_data = ' |
|
| 613 | 624 | if (!(\'smfForum_sessionvar\' in window)) |
| 614 | 625 | window.smfForum_sessionvar = \'sesc\'; |
| 615 | 626 | ' . strtr($file_data, array(';sesc=' => ';\' + window.smfForum_sessionvar + \'=')); |
| 627 | + } |
|
| 616 | 628 | |
| 617 | 629 | $context['template_layers'] = array(); |
| 618 | 630 | // Lets make sure we aren't going to output anything nasty. |
| 619 | 631 | @ob_end_clean(); |
| 620 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
| 621 | - @ob_start('ob_gzhandler'); |
|
| 622 | - else |
|
| 623 | - @ob_start(); |
|
| 632 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
| 633 | + @ob_start('ob_gzhandler'); |
|
| 634 | + } else { |
|
| 635 | + @ob_start(); |
|
| 636 | + } |
|
| 624 | 637 | |
| 625 | 638 | // Make sure they know what type of file we are. |
| 626 | 639 | header('Content-Type: ' . $filetype); |
@@ -660,11 +673,12 @@ discard block |
||
| 660 | 673 | updateAdminPreferences(); |
| 661 | 674 | } |
| 662 | 675 | |
| 663 | - if (trim($context['search_term']) == '') |
|
| 664 | - $context['search_results'] = array(); |
|
| 665 | - else |
|
| 666 | - call_helper($subActions[$context['search_type']]); |
|
| 667 | -} |
|
| 676 | + if (trim($context['search_term']) == '') { |
|
| 677 | + $context['search_results'] = array(); |
|
| 678 | + } else { |
|
| 679 | + call_helper($subActions[$context['search_type']]); |
|
| 680 | + } |
|
| 681 | + } |
|
| 668 | 682 | |
| 669 | 683 | /** |
| 670 | 684 | * A complicated but relatively quick internal search. |
@@ -728,8 +742,9 @@ discard block |
||
| 728 | 742 | |
| 729 | 743 | loadLanguage(implode('+', $language_files)); |
| 730 | 744 | |
| 731 | - foreach ($include_files as $file) |
|
| 732 | - require_once($sourcedir . '/' . $file . '.php'); |
|
| 745 | + foreach ($include_files as $file) { |
|
| 746 | + require_once($sourcedir . '/' . $file . '.php'); |
|
| 747 | + } |
|
| 733 | 748 | |
| 734 | 749 | /* This is the huge array that defines everything... it's a huge array of items formatted as follows: |
| 735 | 750 | 0 = Language index (Can be array of indexes) to search through for this setting. |
@@ -753,11 +768,12 @@ discard block |
||
| 753 | 768 | foreach ($section['areas'] as $menu_key => $menu_item) |
| 754 | 769 | { |
| 755 | 770 | $search_data['sections'][] = array($menu_item['label'], 'area=' . $menu_key); |
| 756 | - if (!empty($menu_item['subsections'])) |
|
| 757 | - foreach ($menu_item['subsections'] as $key => $sublabel) |
|
| 771 | + if (!empty($menu_item['subsections'])) { |
|
| 772 | + foreach ($menu_item['subsections'] as $key => $sublabel) |
|
| 758 | 773 | { |
| 759 | 774 | if (isset($sublabel['label'])) |
| 760 | 775 | $search_data['sections'][] = array($sublabel['label'], 'area=' . $menu_key . ';sa=' . $key); |
| 776 | + } |
|
| 761 | 777 | } |
| 762 | 778 | } |
| 763 | 779 | } |
@@ -767,9 +783,10 @@ discard block |
||
| 767 | 783 | // Get a list of their variables. |
| 768 | 784 | $config_vars = $setting_area[0](true); |
| 769 | 785 | |
| 770 | - foreach ($config_vars as $var) |
|
| 771 | - if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch', 'desc'))) |
|
| 786 | + foreach ($config_vars as $var) { |
|
| 787 | + if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch', 'desc'))) |
|
| 772 | 788 | $search_data['settings'][] = array($var[(isset($var[2]) && in_array($var[2], array('file', 'db'))) ? 0 : 1], $setting_area[1]); |
| 789 | + } |
|
| 773 | 790 | } |
| 774 | 791 | |
| 775 | 792 | $context['page_title'] = $txt['admin_search_results']; |
@@ -782,8 +799,9 @@ discard block |
||
| 782 | 799 | foreach ($data as $item) |
| 783 | 800 | { |
| 784 | 801 | $found = false; |
| 785 | - if (!is_array($item[0])) |
|
| 786 | - $item[0] = array($item[0]); |
|
| 802 | + if (!is_array($item[0])) { |
|
| 803 | + $item[0] = array($item[0]); |
|
| 804 | + } |
|
| 787 | 805 | foreach ($item[0] as $term) |
| 788 | 806 | { |
| 789 | 807 | if (stripos($term, $search_term) !== false || (isset($txt[$term]) && stripos($txt[$term], $search_term) !== false) || (isset($txt['setting_' . $term]) && stripos($txt['setting_' . $term], $search_term) !== false)) |
@@ -841,8 +859,9 @@ discard block |
||
| 841 | 859 | $postVars = explode(' ', $context['search_term']); |
| 842 | 860 | |
| 843 | 861 | // Encode the search data. |
| 844 | - foreach ($postVars as $k => $v) |
|
| 845 | - $postVars[$k] = urlencode($v); |
|
| 862 | + foreach ($postVars as $k => $v) { |
|
| 863 | + $postVars[$k] = urlencode($v); |
|
| 864 | + } |
|
| 846 | 865 | |
| 847 | 866 | // This is what we will send. |
| 848 | 867 | $postVars = implode('+', $postVars); |
@@ -854,8 +873,9 @@ discard block |
||
| 854 | 873 | $search_results = fetch_web_data($context['doc_apiurl'] . '?action=query&list=search&srprop=timestamp|snippet&format=xml&srwhat=text&srsearch=' . $postVars); |
| 855 | 874 | |
| 856 | 875 | // If we didn't get any xml back we are in trouble - perhaps the doc site is overloaded? |
| 857 | - if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\?' . '>\s*(<api>.+?</api>)~is', $search_results, $matches) != true) |
|
| 858 | - fatal_lang_error('cannot_connect_doc_site'); |
|
| 876 | + if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\?' . '>\s*(<api>.+?</api>)~is', $search_results, $matches) != true) { |
|
| 877 | + fatal_lang_error('cannot_connect_doc_site'); |
|
| 878 | + } |
|
| 859 | 879 | |
| 860 | 880 | $search_results = $matches[1]; |
| 861 | 881 | |
@@ -867,8 +887,9 @@ discard block |
||
| 867 | 887 | $results = new xmlArray($search_results, false); |
| 868 | 888 | |
| 869 | 889 | // Move through the api layer. |
| 870 | - if (!$results->exists('api')) |
|
| 871 | - fatal_lang_error('cannot_connect_doc_site'); |
|
| 890 | + if (!$results->exists('api')) { |
|
| 891 | + fatal_lang_error('cannot_connect_doc_site'); |
|
| 892 | + } |
|
| 872 | 893 | |
| 873 | 894 | // Are there actually some results? |
| 874 | 895 | if ($results->exists('api/query/search/p')) |
@@ -904,8 +925,9 @@ discard block |
||
| 904 | 925 | ); |
| 905 | 926 | |
| 906 | 927 | // If it's not got a sa set it must have come here for first time, pretend error log should be reversed. |
| 907 | - if (!isset($_REQUEST['sa'])) |
|
| 908 | - $_REQUEST['desc'] = true; |
|
| 928 | + if (!isset($_REQUEST['sa'])) { |
|
| 929 | + $_REQUEST['desc'] = true; |
|
| 930 | + } |
|
| 909 | 931 | |
| 910 | 932 | // Setup some tab stuff. |
| 911 | 933 | $context[$context['admin_menu_name']]['tab_data'] = array( |
@@ -955,9 +977,10 @@ discard block |
||
| 955 | 977 | unset($_SESSION['admin_time']); |
| 956 | 978 | |
| 957 | 979 | // Clean any admin tokens as well. |
| 958 | - foreach ($_SESSION['token'] as $key => $token) |
|
| 959 | - if (strpos($key, '-admin') !== false) |
|
| 980 | + foreach ($_SESSION['token'] as $key => $token) { |
|
| 981 | + if (strpos($key, '-admin') !== false) |
|
| 960 | 982 | unset($_SESSION['token'][$key]); |
| 983 | + } |
|
| 961 | 984 | |
| 962 | 985 | redirectexit(); |
| 963 | 986 | } |
@@ -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 | * Prepares the information from the moderation log for viewing. |
@@ -32,14 +33,16 @@ discard block |
||
| 32 | 33 | |
| 33 | 34 | // Are we looking at the moderation log or the administration log. |
| 34 | 35 | $context['log_type'] = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'adminlog' ? 3 : 1; |
| 35 | - if ($context['log_type'] == 3) |
|
| 36 | - isAllowedTo('admin_forum'); |
|
| 36 | + if ($context['log_type'] == 3) { |
|
| 37 | + isAllowedTo('admin_forum'); |
|
| 38 | + } |
|
| 37 | 39 | |
| 38 | 40 | // These change dependant on whether we are viewing the moderation or admin log. |
| 39 | - if ($context['log_type'] == 3 || $_REQUEST['action'] == 'admin') |
|
| 40 | - $context['url_start'] = '?action=admin;area=logs;sa=' . ($context['log_type'] == 3 ? 'adminlog' : 'modlog') . ';type=' . $context['log_type']; |
|
| 41 | - else |
|
| 42 | - $context['url_start'] = '?action=moderate;area=modlog;type=' . $context['log_type']; |
|
| 41 | + if ($context['log_type'] == 3 || $_REQUEST['action'] == 'admin') { |
|
| 42 | + $context['url_start'] = '?action=admin;area=logs;sa=' . ($context['log_type'] == 3 ? 'adminlog' : 'modlog') . ';type=' . $context['log_type']; |
|
| 43 | + } else { |
|
| 44 | + $context['url_start'] = '?action=moderate;area=modlog;type=' . $context['log_type']; |
|
| 45 | + } |
|
| 43 | 46 | |
| 44 | 47 | $context['can_delete'] = allowedTo('admin_forum'); |
| 45 | 48 | |
@@ -67,8 +70,7 @@ discard block |
||
| 67 | 70 | $log_type = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'adminlog' ? 'admin' : 'moderate'; |
| 68 | 71 | logAction('clearlog_' . $log_type, array(), $log_type); |
| 69 | 72 | |
| 70 | - } |
|
| 71 | - elseif (!empty($_POST['remove']) && isset($_POST['delete']) && $context['can_delete']) |
|
| 73 | + } elseif (!empty($_POST['remove']) && isset($_POST['delete']) && $context['can_delete']) |
|
| 72 | 74 | { |
| 73 | 75 | checkSession(); |
| 74 | 76 | validateToken('mod-ml'); |
@@ -114,15 +116,17 @@ discard block |
||
| 114 | 116 | 'ip' => array('sql' => 'lm.ip', 'label' => $txt['modlog_ip']) |
| 115 | 117 | ); |
| 116 | 118 | |
| 117 | - if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search'])) |
|
| 118 | - $search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search']; |
|
| 119 | - else |
|
| 120 | - $search_params_string = $search_params['string']; |
|
| 119 | + if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search'])) { |
|
| 120 | + $search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search']; |
|
| 121 | + } else { |
|
| 122 | + $search_params_string = $search_params['string']; |
|
| 123 | + } |
|
| 121 | 124 | |
| 122 | - if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']])) |
|
| 123 | - $search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member'); |
|
| 124 | - else |
|
| 125 | - $search_params_type = $search_params['type']; |
|
| 125 | + if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']])) { |
|
| 126 | + $search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member'); |
|
| 127 | + } else { |
|
| 128 | + $search_params_type = $search_params['type']; |
|
| 129 | + } |
|
| 126 | 130 | |
| 127 | 131 | $search_params_column = $searchTypes[$search_params_type]['sql']; |
| 128 | 132 | $search_params = array( |
@@ -297,13 +301,14 @@ discard block |
||
| 297 | 301 | $context['sub_template'] = 'show_list'; |
| 298 | 302 | $context['default_list'] = 'moderation_log_list'; |
| 299 | 303 | |
| 300 | - if (isset($context['moderation_menu_name'])) |
|
| 301 | - $context[$context['moderation_menu_name']]['tab_data'] = array( |
|
| 304 | + if (isset($context['moderation_menu_name'])) { |
|
| 305 | + $context[$context['moderation_menu_name']]['tab_data'] = array( |
|
| 302 | 306 | 'title' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log'], |
| 303 | 307 | 'help' => $context['log_type'] == 3 ? 'adminlog' : 'modlog', |
| 304 | 308 | 'description' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log_desc'] |
| 305 | 309 | ); |
| 306 | -} |
|
| 310 | + } |
|
| 311 | + } |
|
| 307 | 312 | |
| 308 | 313 | /** |
| 309 | 314 | * Get the number of mod log entries. |
@@ -407,30 +412,35 @@ discard block |
||
| 407 | 412 | // Add on some of the column stuff info |
| 408 | 413 | if (!empty($row['id_board'])) |
| 409 | 414 | { |
| 410 | - if ($row['action'] == 'move') |
|
| 411 | - $row['extra']['board_to'] = $row['id_board']; |
|
| 412 | - else |
|
| 413 | - $row['extra']['board'] = $row['id_board']; |
|
| 415 | + if ($row['action'] == 'move') { |
|
| 416 | + $row['extra']['board_to'] = $row['id_board']; |
|
| 417 | + } else { |
|
| 418 | + $row['extra']['board'] = $row['id_board']; |
|
| 419 | + } |
|
| 414 | 420 | } |
| 415 | 421 | |
| 416 | - if (!empty($row['id_topic'])) |
|
| 417 | - $row['extra']['topic'] = $row['id_topic']; |
|
| 418 | - if (!empty($row['id_msg'])) |
|
| 419 | - $row['extra']['message'] = $row['id_msg']; |
|
| 422 | + if (!empty($row['id_topic'])) { |
|
| 423 | + $row['extra']['topic'] = $row['id_topic']; |
|
| 424 | + } |
|
| 425 | + if (!empty($row['id_msg'])) { |
|
| 426 | + $row['extra']['message'] = $row['id_msg']; |
|
| 427 | + } |
|
| 420 | 428 | |
| 421 | 429 | // Is this associated with a topic? |
| 422 | - if (isset($row['extra']['topic'])) |
|
| 423 | - $topics[(int) $row['extra']['topic']][] = $row['id_action']; |
|
| 424 | - if (isset($row['extra']['new_topic'])) |
|
| 425 | - $topics[(int) $row['extra']['new_topic']][] = $row['id_action']; |
|
| 430 | + if (isset($row['extra']['topic'])) { |
|
| 431 | + $topics[(int) $row['extra']['topic']][] = $row['id_action']; |
|
| 432 | + } |
|
| 433 | + if (isset($row['extra']['new_topic'])) { |
|
| 434 | + $topics[(int) $row['extra']['new_topic']][] = $row['id_action']; |
|
| 435 | + } |
|
| 426 | 436 | |
| 427 | 437 | // How about a member? |
| 428 | 438 | if (isset($row['extra']['member'])) |
| 429 | 439 | { |
| 430 | 440 | // Guests don't have names! |
| 431 | - if (empty($row['extra']['member'])) |
|
| 432 | - $row['extra']['member'] = $txt['modlog_parameter_guest']; |
|
| 433 | - else |
|
| 441 | + if (empty($row['extra']['member'])) { |
|
| 442 | + $row['extra']['member'] = $txt['modlog_parameter_guest']; |
|
| 443 | + } else |
|
| 434 | 444 | { |
| 435 | 445 | // Try to find it... |
| 436 | 446 | $members[(int) $row['extra']['member']][] = $row['id_action']; |
@@ -438,35 +448,42 @@ discard block |
||
| 438 | 448 | } |
| 439 | 449 | |
| 440 | 450 | // Associated with a board? |
| 441 | - if (isset($row['extra']['board_to'])) |
|
| 442 | - $boards[(int) $row['extra']['board_to']][] = $row['id_action']; |
|
| 443 | - if (isset($row['extra']['board_from'])) |
|
| 444 | - $boards[(int) $row['extra']['board_from']][] = $row['id_action']; |
|
| 445 | - if (isset($row['extra']['board'])) |
|
| 446 | - $boards[(int) $row['extra']['board']][] = $row['id_action']; |
|
| 451 | + if (isset($row['extra']['board_to'])) { |
|
| 452 | + $boards[(int) $row['extra']['board_to']][] = $row['id_action']; |
|
| 453 | + } |
|
| 454 | + if (isset($row['extra']['board_from'])) { |
|
| 455 | + $boards[(int) $row['extra']['board_from']][] = $row['id_action']; |
|
| 456 | + } |
|
| 457 | + if (isset($row['extra']['board'])) { |
|
| 458 | + $boards[(int) $row['extra']['board']][] = $row['id_action']; |
|
| 459 | + } |
|
| 447 | 460 | |
| 448 | 461 | // A message? |
| 449 | - if (isset($row['extra']['message'])) |
|
| 450 | - $messages[(int) $row['extra']['message']][] = $row['id_action']; |
|
| 462 | + if (isset($row['extra']['message'])) { |
|
| 463 | + $messages[(int) $row['extra']['message']][] = $row['id_action']; |
|
| 464 | + } |
|
| 451 | 465 | |
| 452 | 466 | // IP Info? |
| 453 | - if (isset($row['extra']['ip_range'])) |
|
| 454 | - if ($seeIP) |
|
| 467 | + if (isset($row['extra']['ip_range'])) { |
|
| 468 | + if ($seeIP) |
|
| 455 | 469 | $row['extra']['ip_range'] = '<a href="' . $scripturl . '?action=trackip;searchip=' . $row['extra']['ip_range'] . '">' . $row['extra']['ip_range'] . '</a>'; |
| 456 | - else |
|
| 457 | - $row['extra']['ip_range'] = $txt['logged']; |
|
| 470 | + } else { |
|
| 471 | + $row['extra']['ip_range'] = $txt['logged']; |
|
| 472 | + } |
|
| 458 | 473 | |
| 459 | 474 | // Email? |
| 460 | - if (isset($row['extra']['email'])) |
|
| 461 | - $row['extra']['email'] = '<a href="mailto:' . $row['extra']['email'] . '">' . $row['extra']['email'] . '</a>'; |
|
| 475 | + if (isset($row['extra']['email'])) { |
|
| 476 | + $row['extra']['email'] = '<a href="mailto:' . $row['extra']['email'] . '">' . $row['extra']['email'] . '</a>'; |
|
| 477 | + } |
|
| 462 | 478 | |
| 463 | 479 | // Bans are complex. |
| 464 | 480 | if ($row['action'] == 'ban' || $row['action'] == 'banremove') |
| 465 | 481 | { |
| 466 | 482 | $row['action_text'] = $txt['modlog_ac_ban' . ($row['action'] == 'banremove' ? '_remove' : '')]; |
| 467 | - foreach (array('member', 'email', 'ip_range', 'hostname') as $type) |
|
| 468 | - if (isset($row['extra'][$type])) |
|
| 483 | + foreach (array('member', 'email', 'ip_range', 'hostname') as $type) { |
|
| 484 | + if (isset($row['extra'][$type])) |
|
| 469 | 485 | $row['action_text'] .= $txt['modlog_ac_ban_trigger_' . $type]; |
| 486 | + } |
|
| 470 | 487 | } |
| 471 | 488 | |
| 472 | 489 | // The array to go to the template. Note here that action is set to a "default" value of the action doesn't match anything in the descriptions. Allows easy adding of logging events with basic details. |
@@ -502,12 +519,13 @@ discard block |
||
| 502 | 519 | foreach ($boards[$row['id_board']] as $action) |
| 503 | 520 | { |
| 504 | 521 | // Make the board number into a link - dealing with moving too. |
| 505 | - if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board']) |
|
| 506 | - $entries[$action]['extra']['board_to'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
| 507 | - elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board']) |
|
| 508 | - $entries[$action]['extra']['board_from'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
| 509 | - elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board']) |
|
| 510 | - $entries[$action]['extra']['board'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
| 522 | + if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board']) { |
|
| 523 | + $entries[$action]['extra']['board_to'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
| 524 | + } elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board']) { |
|
| 525 | + $entries[$action]['extra']['board_from'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
| 526 | + } elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board']) { |
|
| 527 | + $entries[$action]['extra']['board'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
| 528 | + } |
|
| 511 | 529 | } |
| 512 | 530 | } |
| 513 | 531 | $smcFunc['db_free_result']($request); |
@@ -541,10 +559,11 @@ discard block |
||
| 541 | 559 | ); |
| 542 | 560 | |
| 543 | 561 | // Make the topic number into a link - dealing with splitting too. |
| 544 | - if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic']) |
|
| 545 | - $this_action['extra']['topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>'; |
|
| 546 | - elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic']) |
|
| 547 | - $this_action['extra']['new_topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>'; |
|
| 562 | + if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic']) { |
|
| 563 | + $this_action['extra']['topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>'; |
|
| 564 | + } elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic']) { |
|
| 565 | + $this_action['extra']['new_topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>'; |
|
| 566 | + } |
|
| 548 | 567 | } |
| 549 | 568 | } |
| 550 | 569 | $smcFunc['db_free_result']($request); |
@@ -577,8 +596,9 @@ discard block |
||
| 577 | 596 | ); |
| 578 | 597 | |
| 579 | 598 | // Make the message number into a link. |
| 580 | - if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg']) |
|
| 581 | - $this_action['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>'; |
|
| 599 | + if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg']) { |
|
| 600 | + $this_action['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>'; |
|
| 601 | + } |
|
| 582 | 602 | } |
| 583 | 603 | } |
| 584 | 604 | $smcFunc['db_free_result']($request); |
@@ -618,25 +638,29 @@ discard block |
||
| 618 | 638 | foreach ($entries as $k => $entry) |
| 619 | 639 | { |
| 620 | 640 | // Make any message info links so its easier to go find that message. |
| 621 | - if (isset($entry['extra']['message']) && (empty($entry['message']) || empty($entry['message']['id']))) |
|
| 622 | - $entries[$k]['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $entry['extra']['message'] . '">' . $entry['extra']['message'] . '</a>'; |
|
| 641 | + if (isset($entry['extra']['message']) && (empty($entry['message']) || empty($entry['message']['id']))) { |
|
| 642 | + $entries[$k]['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $entry['extra']['message'] . '">' . $entry['extra']['message'] . '</a>'; |
|
| 643 | + } |
|
| 623 | 644 | |
| 624 | 645 | // Mark up any deleted members, topics and boards. |
| 625 | - foreach (array('board', 'board_from', 'board_to', 'member', 'topic', 'new_topic') as $type) |
|
| 626 | - if (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type])) |
|
| 646 | + foreach (array('board', 'board_from', 'board_to', 'member', 'topic', 'new_topic') as $type) { |
|
| 647 | + if (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type])) |
|
| 627 | 648 | $entries[$k]['extra'][$type] = sprintf($txt['modlog_id'], $entry['extra'][$type]); |
| 649 | + } |
|
| 628 | 650 | |
| 629 | 651 | if (isset($entry['extra']['report'])) |
| 630 | 652 | { |
| 631 | 653 | // Member profile reports go in a different area |
| 632 | - if (stristr($entry['action'], 'user_report')) |
|
| 633 | - $entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedmembers;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>'; |
|
| 634 | - else |
|
| 635 | - $entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedposts;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>'; |
|
| 654 | + if (stristr($entry['action'], 'user_report')) { |
|
| 655 | + $entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedmembers;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>'; |
|
| 656 | + } else { |
|
| 657 | + $entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedposts;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>'; |
|
| 658 | + } |
|
| 636 | 659 | } |
| 637 | 660 | |
| 638 | - if (empty($entries[$k]['action_text'])) |
|
| 639 | - $entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action']; |
|
| 661 | + if (empty($entries[$k]['action_text'])) { |
|
| 662 | + $entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action']; |
|
| 663 | + } |
|
| 640 | 664 | $entries[$k]['action_text'] = preg_replace_callback('~\{([A-Za-z\d_]+)\}~i', |
| 641 | 665 | function ($matches) use ($entries, $k) |
| 642 | 666 | { |
@@ -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 functions implemented in this file to the $smcFunc array. |
@@ -23,8 +24,8 @@ discard block |
||
| 23 | 24 | { |
| 24 | 25 | global $smcFunc; |
| 25 | 26 | |
| 26 | - if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table') |
|
| 27 | - $smcFunc += array( |
|
| 27 | + if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table') { |
|
| 28 | + $smcFunc += array( |
|
| 28 | 29 | 'db_backup_table' => 'smf_db_backup_table', |
| 29 | 30 | 'db_optimize_table' => 'smf_db_optimize_table', |
| 30 | 31 | 'db_insert_sql' => 'smf_db_insert_sql', |
@@ -33,7 +34,8 @@ discard block |
||
| 33 | 34 | 'db_get_version' => 'smf_db_get_version', |
| 34 | 35 | 'db_get_engine' => 'smf_db_get_engine', |
| 35 | 36 | ); |
| 36 | -} |
|
| 37 | + } |
|
| 38 | + } |
|
| 37 | 39 | |
| 38 | 40 | /** |
| 39 | 41 | * Backup $table to $backup_table. |
@@ -49,13 +51,14 @@ discard block |
||
| 49 | 51 | |
| 50 | 52 | // Do we need to drop it first? |
| 51 | 53 | $tables = smf_db_list_tables(false, $backup_table); |
| 52 | - if (!empty($tables)) |
|
| 53 | - $smcFunc['db_query']('', ' |
|
| 54 | + if (!empty($tables)) { |
|
| 55 | + $smcFunc['db_query']('', ' |
|
| 54 | 56 | DROP TABLE {raw:backup_table}', |
| 55 | 57 | array( |
| 56 | 58 | 'backup_table' => $backup_table, |
| 57 | 59 | ) |
| 58 | 60 | ); |
| 61 | + } |
|
| 59 | 62 | |
| 60 | 63 | /** |
| 61 | 64 | * @todo Should we create backups of sequences as well? |
@@ -118,8 +121,9 @@ discard block |
||
| 118 | 121 | ) |
| 119 | 122 | ); |
| 120 | 123 | |
| 121 | - if (!$request) |
|
| 122 | - return -1; |
|
| 124 | + if (!$request) { |
|
| 125 | + return -1; |
|
| 126 | + } |
|
| 123 | 127 | |
| 124 | 128 | $request = $smcFunc['db_query']('', ' |
| 125 | 129 | SELECT pg_relation_size(C.oid) AS "size" |
@@ -137,11 +141,12 @@ discard block |
||
| 137 | 141 | $row = $smcFunc['db_fetch_assoc']($request); |
| 138 | 142 | $smcFunc['db_free_result']($request); |
| 139 | 143 | |
| 140 | - if (isset($row['size'])) |
|
| 141 | - return ($old_size - $row['size']) / 1024; |
|
| 142 | - else |
|
| 143 | - return 0; |
|
| 144 | -} |
|
| 144 | + if (isset($row['size'])) { |
|
| 145 | + return ($old_size - $row['size']) / 1024; |
|
| 146 | + } else { |
|
| 147 | + return 0; |
|
| 148 | + } |
|
| 149 | + } |
|
| 145 | 150 | |
| 146 | 151 | /** |
| 147 | 152 | * This function lists all tables in the database. |
@@ -168,8 +173,9 @@ discard block |
||
| 168 | 173 | ); |
| 169 | 174 | |
| 170 | 175 | $tables = array(); |
| 171 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 172 | - $tables[] = $row[0]; |
|
| 176 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 177 | + $tables[] = $row[0]; |
|
| 178 | + } |
|
| 173 | 179 | $smcFunc['db_free_result']($request); |
| 174 | 180 | |
| 175 | 181 | return $tables; |
@@ -212,8 +218,9 @@ discard block |
||
| 212 | 218 | // The number of rows, just for record keeping and breaking INSERTs up. |
| 213 | 219 | $num_rows = $smcFunc['db_num_rows']($result); |
| 214 | 220 | |
| 215 | - if ($num_rows == 0) |
|
| 216 | - return ''; |
|
| 221 | + if ($num_rows == 0) { |
|
| 222 | + return ''; |
|
| 223 | + } |
|
| 217 | 224 | |
| 218 | 225 | if ($new_table) |
| 219 | 226 | { |
@@ -234,12 +241,13 @@ discard block |
||
| 234 | 241 | foreach ($row as $key => $item) |
| 235 | 242 | { |
| 236 | 243 | // Try to figure out the type of each field. (NULL, number, or 'string'.) |
| 237 | - if (!isset($item)) |
|
| 238 | - $field_list[] = 'NULL'; |
|
| 239 | - elseif (is_numeric($item) && (int) $item == $item) |
|
| 240 | - $field_list[] = $item; |
|
| 241 | - else |
|
| 242 | - $field_list[] = '\'' . $smcFunc['db_escape_string']($item) . '\''; |
|
| 244 | + if (!isset($item)) { |
|
| 245 | + $field_list[] = 'NULL'; |
|
| 246 | + } elseif (is_numeric($item) && (int) $item == $item) { |
|
| 247 | + $field_list[] = $item; |
|
| 248 | + } else { |
|
| 249 | + $field_list[] = '\'' . $smcFunc['db_escape_string']($item) . '\''; |
|
| 250 | + } |
|
| 243 | 251 | } |
| 244 | 252 | |
| 245 | 253 | // 'Insert' the data. |
@@ -289,12 +297,14 @@ discard block |
||
| 289 | 297 | ); |
| 290 | 298 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 291 | 299 | { |
| 292 | - if ($row['data_type'] == 'character varying') |
|
| 293 | - $row['data_type'] = 'varchar'; |
|
| 294 | - elseif ($row['data_type'] == 'character') |
|
| 295 | - $row['data_type'] = 'char'; |
|
| 296 | - if ($row['character_maximum_length']) |
|
| 297 | - $row['data_type'] .= '(' . $row['character_maximum_length'] . ')'; |
|
| 300 | + if ($row['data_type'] == 'character varying') { |
|
| 301 | + $row['data_type'] = 'varchar'; |
|
| 302 | + } elseif ($row['data_type'] == 'character') { |
|
| 303 | + $row['data_type'] = 'char'; |
|
| 304 | + } |
|
| 305 | + if ($row['character_maximum_length']) { |
|
| 306 | + $row['data_type'] .= '(' . $row['character_maximum_length'] . ')'; |
|
| 307 | + } |
|
| 298 | 308 | |
| 299 | 309 | // Make the CREATE for this column. |
| 300 | 310 | $schema_create .= ' "' . $row['column_name'] . '" ' . $row['data_type'] . ($row['is_nullable'] != 'YES' ? ' NOT NULL' : ''); |
@@ -345,13 +355,14 @@ discard block |
||
| 345 | 355 | { |
| 346 | 356 | if ($row['is_primary']) |
| 347 | 357 | { |
| 348 | - if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) |
|
| 349 | - continue; |
|
| 358 | + if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) { |
|
| 359 | + continue; |
|
| 360 | + } |
|
| 350 | 361 | |
| 351 | 362 | $index_create .= $crlf . 'ALTER TABLE ' . $tableName . ' ADD PRIMARY KEY ("' . $matches[1] . '");'; |
| 363 | + } else { |
|
| 364 | + $index_create .= $crlf . $row['inddef'] . ';'; |
|
| 352 | 365 | } |
| 353 | - else |
|
| 354 | - $index_create .= $crlf . $row['inddef'] . ';'; |
|
| 355 | 366 | } |
| 356 | 367 | $smcFunc['db_free_result']($result); |
| 357 | 368 | |
@@ -369,8 +380,9 @@ discard block |
||
| 369 | 380 | { |
| 370 | 381 | static $ver; |
| 371 | 382 | |
| 372 | - if(!empty($ver)) |
|
| 373 | - return $ver; |
|
| 383 | + if(!empty($ver)) { |
|
| 384 | + return $ver; |
|
| 385 | + } |
|
| 374 | 386 | |
| 375 | 387 | global $smcFunc; |
| 376 | 388 | |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Add the file functions to the $smcFunc array. |
@@ -52,8 +53,9 @@ discard block |
||
| 52 | 53 | 'messages', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages', |
| 53 | 54 | 'pm_recipients', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys', |
| 54 | 55 | 'themes', 'topics'); |
| 55 | - foreach ($reservedTables as $k => $table_name) |
|
| 56 | - $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
| 56 | + foreach ($reservedTables as $k => $table_name) { |
|
| 57 | + $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
| 58 | + } |
|
| 57 | 59 | |
| 58 | 60 | // We in turn may need the extra stuff. |
| 59 | 61 | db_extend('extra'); |
@@ -102,8 +104,9 @@ discard block |
||
| 102 | 104 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 103 | 105 | |
| 104 | 106 | // First - no way do we touch SMF tables. |
| 105 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
| 106 | - return false; |
|
| 107 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
| 108 | + return false; |
|
| 109 | + } |
|
| 107 | 110 | |
| 108 | 111 | // Log that we'll want to remove this on uninstall. |
| 109 | 112 | $db_package_log[] = array('remove_table', $table_name); |
@@ -113,10 +116,11 @@ discard block |
||
| 113 | 116 | if (in_array($full_table_name, $tables)) |
| 114 | 117 | { |
| 115 | 118 | // This is a sad day... drop the table? If not, return false (error) by default. |
| 116 | - if ($if_exists == 'overwrite') |
|
| 117 | - $smcFunc['db_drop_table']($table_name); |
|
| 118 | - else |
|
| 119 | - return $if_exists == 'ignore'; |
|
| 119 | + if ($if_exists == 'overwrite') { |
|
| 120 | + $smcFunc['db_drop_table']($table_name); |
|
| 121 | + } else { |
|
| 122 | + return $if_exists == 'ignore'; |
|
| 123 | + } |
|
| 120 | 124 | } |
| 121 | 125 | |
| 122 | 126 | // If we've got this far - good news - no table exists. We can build our own! |
@@ -134,17 +138,18 @@ discard block |
||
| 134 | 138 | ) |
| 135 | 139 | ); |
| 136 | 140 | $default = 'default nextval(\'' . $table_name . '_seq\')'; |
| 141 | + } elseif (isset($column['default']) && $column['default'] !== null) { |
|
| 142 | + $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
| 143 | + } else { |
|
| 144 | + $default = ''; |
|
| 137 | 145 | } |
| 138 | - elseif (isset($column['default']) && $column['default'] !== null) |
|
| 139 | - $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
| 140 | - else |
|
| 141 | - $default = ''; |
|
| 142 | 146 | |
| 143 | 147 | // Sort out the size... |
| 144 | 148 | $column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null; |
| 145 | 149 | list ($type, $size) = $smcFunc['db_calculate_type']($column['type'], $column['size']); |
| 146 | - if ($size !== null) |
|
| 147 | - $type = $type . '(' . $size . ')'; |
|
| 150 | + if ($size !== null) { |
|
| 151 | + $type = $type . '(' . $size . ')'; |
|
| 152 | + } |
|
| 148 | 153 | |
| 149 | 154 | // Now just put it together! |
| 150 | 155 | $table_query .= "\n\t\"" . $column['name'] . '" ' . $type . ' ' . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default . ','; |
@@ -157,19 +162,21 @@ discard block |
||
| 157 | 162 | $columns = implode(',', $index['columns']); |
| 158 | 163 | |
| 159 | 164 | // Primary goes in the table... |
| 160 | - if (isset($index['type']) && $index['type'] == 'primary') |
|
| 161 | - $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
| 162 | - else |
|
| 165 | + if (isset($index['type']) && $index['type'] == 'primary') { |
|
| 166 | + $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
| 167 | + } else |
|
| 163 | 168 | { |
| 164 | - if (empty($index['name'])) |
|
| 165 | - $index['name'] = implode('_', $index['columns']); |
|
| 169 | + if (empty($index['name'])) { |
|
| 170 | + $index['name'] = implode('_', $index['columns']); |
|
| 171 | + } |
|
| 166 | 172 | $index_queries[] = 'CREATE ' . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $table_name . '_' . $index['name'] . ' ON ' . $table_name . ' (' . $columns . ')'; |
| 167 | 173 | } |
| 168 | 174 | } |
| 169 | 175 | |
| 170 | 176 | // No trailing commas! |
| 171 | - if (substr($table_query, -1) == ',') |
|
| 172 | - $table_query = substr($table_query, 0, -1); |
|
| 177 | + if (substr($table_query, -1) == ',') { |
|
| 178 | + $table_query = substr($table_query, 0, -1); |
|
| 179 | + } |
|
| 173 | 180 | |
| 174 | 181 | $table_query .= ')'; |
| 175 | 182 | |
@@ -180,12 +187,13 @@ discard block |
||
| 180 | 187 | ) |
| 181 | 188 | ); |
| 182 | 189 | // And the indexes... |
| 183 | - foreach ($index_queries as $query) |
|
| 184 | - $smcFunc['db_query']('', $query, |
|
| 190 | + foreach ($index_queries as $query) { |
|
| 191 | + $smcFunc['db_query']('', $query, |
|
| 185 | 192 | array( |
| 186 | 193 | 'security_override' => true, |
| 187 | 194 | ) |
| 188 | 195 | ); |
| 196 | + } |
|
| 189 | 197 | |
| 190 | 198 | // Go, go power rangers! |
| 191 | 199 | $smcFunc['db_transaction']('commit'); |
@@ -213,8 +221,9 @@ discard block |
||
| 213 | 221 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 214 | 222 | |
| 215 | 223 | // God no - dropping one of these = bad. |
| 216 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
| 217 | - return false; |
|
| 224 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
| 225 | + return false; |
|
| 226 | + } |
|
| 218 | 227 | |
| 219 | 228 | // Does it exist? |
| 220 | 229 | if (in_array($full_table_name, $smcFunc['db_list_tables']())) |
@@ -272,21 +281,24 @@ discard block |
||
| 272 | 281 | |
| 273 | 282 | // Does it exist - if so don't add it again! |
| 274 | 283 | $columns = $smcFunc['db_list_columns']($table_name, false); |
| 275 | - foreach ($columns as $column) |
|
| 276 | - if ($column == $column_info['name']) |
|
| 284 | + foreach ($columns as $column) { |
|
| 285 | + if ($column == $column_info['name']) |
|
| 277 | 286 | { |
| 278 | 287 | // If we're going to overwrite then use change column. |
| 279 | 288 | if ($if_exists == 'update') |
| 280 | 289 | return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
| 281 | - else |
|
| 282 | - return false; |
|
| 290 | + } |
|
| 291 | + else { |
|
| 292 | + return false; |
|
| 293 | + } |
|
| 283 | 294 | } |
| 284 | 295 | |
| 285 | 296 | // Get the specifics... |
| 286 | 297 | $column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null; |
| 287 | 298 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); |
| 288 | - if ($size !== null) |
|
| 289 | - $type = $type . '(' . $size . ')'; |
|
| 299 | + if ($size !== null) { |
|
| 300 | + $type = $type . '(' . $size . ')'; |
|
| 301 | + } |
|
| 290 | 302 | |
| 291 | 303 | // Now add the thing! |
| 292 | 304 | $query = ' |
@@ -301,11 +313,12 @@ discard block |
||
| 301 | 313 | // If there's more attributes they need to be done via a change on PostgreSQL. |
| 302 | 314 | unset($column_info['type'], $column_info['size']); |
| 303 | 315 | |
| 304 | - if (count($column_info) != 1) |
|
| 305 | - return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
|
| 306 | - else |
|
| 307 | - return true; |
|
| 308 | -} |
|
| 316 | + if (count($column_info) != 1) { |
|
| 317 | + return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
|
| 318 | + } else { |
|
| 319 | + return true; |
|
| 320 | + } |
|
| 321 | + } |
|
| 309 | 322 | |
| 310 | 323 | /** |
| 311 | 324 | * Removes a column. |
@@ -324,8 +337,8 @@ discard block |
||
| 324 | 337 | |
| 325 | 338 | // Does it exist? |
| 326 | 339 | $columns = $smcFunc['db_list_columns']($table_name, true); |
| 327 | - foreach ($columns as $column) |
|
| 328 | - if ($column['name'] == $column_name) |
|
| 340 | + foreach ($columns as $column) { |
|
| 341 | + if ($column['name'] == $column_name) |
|
| 329 | 342 | { |
| 330 | 343 | // If there is an auto we need remove it! |
| 331 | 344 | if ($column['auto']) |
@@ -335,6 +348,7 @@ discard block |
||
| 335 | 348 | 'security_override' => true, |
| 336 | 349 | ) |
| 337 | 350 | ); |
| 351 | + } |
|
| 338 | 352 | |
| 339 | 353 | $smcFunc['db_query']('', ' |
| 340 | 354 | ALTER TABLE ' . $table_name . ' |
@@ -369,13 +383,15 @@ discard block |
||
| 369 | 383 | // Check it does exist! |
| 370 | 384 | $columns = $smcFunc['db_list_columns']($table_name, true); |
| 371 | 385 | $old_info = null; |
| 372 | - foreach ($columns as $column) |
|
| 373 | - if ($column['name'] == $old_column) |
|
| 386 | + foreach ($columns as $column) { |
|
| 387 | + if ($column['name'] == $old_column) |
|
| 374 | 388 | $old_info = $column; |
| 389 | + } |
|
| 375 | 390 | |
| 376 | 391 | // Nothing? |
| 377 | - if ($old_info == null) |
|
| 378 | - return false; |
|
| 392 | + if ($old_info == null) { |
|
| 393 | + return false; |
|
| 394 | + } |
|
| 379 | 395 | |
| 380 | 396 | // Now we check each bit individually and ALTER as required. |
| 381 | 397 | if (isset($column_info['name']) && $column_info['name'] != $old_column) |
@@ -432,8 +448,9 @@ discard block |
||
| 432 | 448 | { |
| 433 | 449 | $column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null; |
| 434 | 450 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); |
| 435 | - if ($size !== null) |
|
| 436 | - $type = $type . '(' . $size . ')'; |
|
| 451 | + if ($size !== null) { |
|
| 452 | + $type = $type . '(' . $size . ')'; |
|
| 453 | + } |
|
| 437 | 454 | |
| 438 | 455 | // The alter is a pain. |
| 439 | 456 | $smcFunc['db_transaction']('begin'); |
@@ -527,21 +544,23 @@ discard block |
||
| 527 | 544 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 528 | 545 | |
| 529 | 546 | // No columns = no index. |
| 530 | - if (empty($index_info['columns'])) |
|
| 531 | - return false; |
|
| 547 | + if (empty($index_info['columns'])) { |
|
| 548 | + return false; |
|
| 549 | + } |
|
| 532 | 550 | $columns = implode(',', $index_info['columns']); |
| 533 | 551 | |
| 534 | 552 | // No name - make it up! |
| 535 | 553 | if (empty($index_info['name'])) |
| 536 | 554 | { |
| 537 | 555 | // No need for primary. |
| 538 | - if (isset($index_info['type']) && $index_info['type'] == 'primary') |
|
| 539 | - $index_info['name'] = ''; |
|
| 540 | - else |
|
| 541 | - $index_info['name'] = $table_name . implode('_', $index_info['columns']); |
|
| 556 | + if (isset($index_info['type']) && $index_info['type'] == 'primary') { |
|
| 557 | + $index_info['name'] = ''; |
|
| 558 | + } else { |
|
| 559 | + $index_info['name'] = $table_name . implode('_', $index_info['columns']); |
|
| 560 | + } |
|
| 561 | + } else { |
|
| 562 | + $index_info['name'] = $table_name . $index_info['name']; |
|
| 542 | 563 | } |
| 543 | - else |
|
| 544 | - $index_info['name'] = $table_name . $index_info['name']; |
|
| 545 | 564 | |
| 546 | 565 | // Log that we are going to want to remove this! |
| 547 | 566 | $db_package_log[] = array('remove_index', $table_name, $index_info['name']); |
@@ -554,10 +573,11 @@ discard block |
||
| 554 | 573 | if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary')) |
| 555 | 574 | { |
| 556 | 575 | // If we want to overwrite simply remove the current one then continue. |
| 557 | - if ($if_exists != 'update' || $index['type'] == 'primary') |
|
| 558 | - return false; |
|
| 559 | - else |
|
| 560 | - $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
| 576 | + if ($if_exists != 'update' || $index['type'] == 'primary') { |
|
| 577 | + return false; |
|
| 578 | + } else { |
|
| 579 | + $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
| 580 | + } |
|
| 561 | 581 | } |
| 562 | 582 | } |
| 563 | 583 | |
@@ -571,8 +591,7 @@ discard block |
||
| 571 | 591 | 'security_override' => true, |
| 572 | 592 | ) |
| 573 | 593 | ); |
| 574 | - } |
|
| 575 | - else |
|
| 594 | + } else |
|
| 576 | 595 | { |
| 577 | 596 | $smcFunc['db_query']('', ' |
| 578 | 597 | CREATE ' . (isset($index_info['type']) && $index_info['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $index_info['name'] . ' ON ' . $table_name . ' (' . $columns . ')', |
@@ -600,8 +619,9 @@ discard block |
||
| 600 | 619 | |
| 601 | 620 | // Better exist! |
| 602 | 621 | $indexes = $smcFunc['db_list_indexes']($table_name, true); |
| 603 | - if ($index_name != 'primary') |
|
| 604 | - $index_name = $table_name . '_' . $index_name; |
|
| 622 | + if ($index_name != 'primary') { |
|
| 623 | + $index_name = $table_name . '_' . $index_name; |
|
| 624 | + } |
|
| 605 | 625 | |
| 606 | 626 | foreach ($indexes as $index) |
| 607 | 627 | { |
@@ -665,8 +685,7 @@ discard block |
||
| 665 | 685 | 'datetime' => 'timestamp without time zone', |
| 666 | 686 | 'timestamp' => 'timestamp without time zone', |
| 667 | 687 | ); |
| 668 | - } |
|
| 669 | - else |
|
| 688 | + } else |
|
| 670 | 689 | { |
| 671 | 690 | $types = array( |
| 672 | 691 | 'character varying' => 'varchar', |
@@ -682,14 +701,16 @@ discard block |
||
| 682 | 701 | // Got it? Change it! |
| 683 | 702 | if (isset($types[$type_name])) |
| 684 | 703 | { |
| 685 | - if ($type_name == 'tinytext') |
|
| 686 | - $type_size = 255; |
|
| 704 | + if ($type_name == 'tinytext') { |
|
| 705 | + $type_size = 255; |
|
| 706 | + } |
|
| 687 | 707 | $type_name = $types[$type_name]; |
| 688 | 708 | } |
| 689 | 709 | |
| 690 | 710 | // Only char fields got size |
| 691 | - if (strpos($type_name, 'char') === false) |
|
| 692 | - $type_size = null; |
|
| 711 | + if (strpos($type_name, 'char') === false) { |
|
| 712 | + $type_size = null; |
|
| 713 | + } |
|
| 693 | 714 | |
| 694 | 715 | |
| 695 | 716 | return array($type_name, $type_size); |
@@ -744,8 +765,7 @@ discard block |
||
| 744 | 765 | if (!$detail) |
| 745 | 766 | { |
| 746 | 767 | $columns[] = $row['column_name']; |
| 747 | - } |
|
| 748 | - else |
|
| 768 | + } else |
|
| 749 | 769 | { |
| 750 | 770 | $auto = false; |
| 751 | 771 | // What is the default? |
@@ -753,11 +773,11 @@ discard block |
||
| 753 | 773 | { |
| 754 | 774 | $default = null; |
| 755 | 775 | $auto = true; |
| 776 | + } elseif (trim($row['column_default']) != '') { |
|
| 777 | + $default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::')); |
|
| 778 | + } else { |
|
| 779 | + $default = null; |
|
| 756 | 780 | } |
| 757 | - elseif (trim($row['column_default']) != '') |
|
| 758 | - $default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::')); |
|
| 759 | - else |
|
| 760 | - $default = null; |
|
| 761 | 781 | |
| 762 | 782 | // Make the type generic. |
| 763 | 783 | list ($type, $size) = $smcFunc['db_calculate_type']($row['data_type'], $row['character_maximum_length'], true); |
@@ -808,26 +828,30 @@ discard block |
||
| 808 | 828 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 809 | 829 | { |
| 810 | 830 | // Try get the columns that make it up. |
| 811 | - if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) |
|
| 812 | - continue; |
|
| 831 | + if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) { |
|
| 832 | + continue; |
|
| 833 | + } |
|
| 813 | 834 | |
| 814 | 835 | $columns = explode(',', $matches[1]); |
| 815 | 836 | |
| 816 | - if (empty($columns)) |
|
| 817 | - continue; |
|
| 837 | + if (empty($columns)) { |
|
| 838 | + continue; |
|
| 839 | + } |
|
| 818 | 840 | |
| 819 | - foreach ($columns as $k => $v) |
|
| 820 | - $columns[$k] = trim($v); |
|
| 841 | + foreach ($columns as $k => $v) { |
|
| 842 | + $columns[$k] = trim($v); |
|
| 843 | + } |
|
| 821 | 844 | |
| 822 | 845 | // Fix up the name to be consistent cross databases |
| 823 | - if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1) |
|
| 824 | - $row['name'] = 'PRIMARY'; |
|
| 825 | - else |
|
| 826 | - $row['name'] = str_replace($table_name . '_', '', $row['name']); |
|
| 846 | + if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1) { |
|
| 847 | + $row['name'] = 'PRIMARY'; |
|
| 848 | + } else { |
|
| 849 | + $row['name'] = str_replace($table_name . '_', '', $row['name']); |
|
| 850 | + } |
|
| 827 | 851 | |
| 828 | - if (!$detail) |
|
| 829 | - $indexes[] = $row['name']; |
|
| 830 | - else |
|
| 852 | + if (!$detail) { |
|
| 853 | + $indexes[] = $row['name']; |
|
| 854 | + } else |
|
| 831 | 855 | { |
| 832 | 856 | $indexes[$row['name']] = array( |
| 833 | 857 | 'name' => $row['name'], |
@@ -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'] != 'mysqli_fetch_assoc') |
|
| 37 | - $smcFunc += array( |
|
| 37 | + if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysqli_fetch_assoc') { |
|
| 38 | + $smcFunc += array( |
|
| 38 | 39 | 'db_query' => 'smf_db_query', |
| 39 | 40 | 'db_quote' => 'smf_db_quote', |
| 40 | 41 | 'db_fetch_assoc' => 'mysqli_fetch_assoc', |
@@ -58,9 +59,11 @@ discard block |
||
| 58 | 59 | 'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string', |
| 59 | 60 | 'db_is_resource' => 'smf_is_resource', |
| 60 | 61 | ); |
| 62 | + } |
|
| 61 | 63 | |
| 62 | - if (!empty($db_options['persist'])) |
|
| 63 | - $db_server = 'p:' . $db_server; |
|
| 64 | + if (!empty($db_options['persist'])) { |
|
| 65 | + $db_server = 'p:' . $db_server; |
|
| 66 | + } |
|
| 64 | 67 | |
| 65 | 68 | $connection = mysqli_init(); |
| 66 | 69 | |
@@ -69,31 +72,35 @@ discard block |
||
| 69 | 72 | $success = false; |
| 70 | 73 | |
| 71 | 74 | if ($connection) { |
| 72 | - if (!empty($db_options['port'])) |
|
| 73 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'] , null ,$flags); |
|
| 74 | - else |
|
| 75 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd,'', 0, null, $flags); |
|
| 75 | + if (!empty($db_options['port'])) { |
|
| 76 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'] , null ,$flags); |
|
| 77 | + } else { |
|
| 78 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd,'', 0, null, $flags); |
|
| 79 | + } |
|
| 76 | 80 | } |
| 77 | 81 | |
| 78 | 82 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 79 | 83 | if ($success === false) |
| 80 | 84 | { |
| 81 | - if (!empty($db_options['non_fatal'])) |
|
| 82 | - return null; |
|
| 83 | - else |
|
| 84 | - display_db_error(); |
|
| 85 | + if (!empty($db_options['non_fatal'])) { |
|
| 86 | + return null; |
|
| 87 | + } else { |
|
| 88 | + display_db_error(); |
|
| 89 | + } |
|
| 85 | 90 | } |
| 86 | 91 | |
| 87 | 92 | // Select the database, unless told not to |
| 88 | - if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) |
|
| 89 | - display_db_error(); |
|
| 93 | + if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) { |
|
| 94 | + display_db_error(); |
|
| 95 | + } |
|
| 90 | 96 | |
| 91 | 97 | // This makes it possible to have SMF automatically change the sql_mode and autocommit if needed. |
| 92 | - if (isset($mysql_set_mode) && $mysql_set_mode === true) |
|
| 93 | - $smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1', |
|
| 98 | + if (isset($mysql_set_mode) && $mysql_set_mode === true) { |
|
| 99 | + $smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1', |
|
| 94 | 100 | array(), |
| 95 | 101 | false |
| 96 | 102 | ); |
| 103 | + } |
|
| 97 | 104 | |
| 98 | 105 | return $connection; |
| 99 | 106 | } |
@@ -164,37 +171,46 @@ discard block |
||
| 164 | 171 | global $db_callback, $user_info, $db_prefix, $smcFunc; |
| 165 | 172 | |
| 166 | 173 | list ($values, $connection) = $db_callback; |
| 167 | - if (!is_object($connection)) |
|
| 168 | - display_db_error(); |
|
| 174 | + if (!is_object($connection)) { |
|
| 175 | + display_db_error(); |
|
| 176 | + } |
|
| 169 | 177 | |
| 170 | - if ($matches[1] === 'db_prefix') |
|
| 171 | - return $db_prefix; |
|
| 178 | + if ($matches[1] === 'db_prefix') { |
|
| 179 | + return $db_prefix; |
|
| 180 | + } |
|
| 172 | 181 | |
| 173 | - if ($matches[1] === 'query_see_board') |
|
| 174 | - return $user_info['query_see_board']; |
|
| 182 | + if ($matches[1] === 'query_see_board') { |
|
| 183 | + return $user_info['query_see_board']; |
|
| 184 | + } |
|
| 175 | 185 | |
| 176 | - if ($matches[1] === 'query_wanna_see_board') |
|
| 177 | - return $user_info['query_wanna_see_board']; |
|
| 186 | + if ($matches[1] === 'query_wanna_see_board') { |
|
| 187 | + return $user_info['query_wanna_see_board']; |
|
| 188 | + } |
|
| 178 | 189 | |
| 179 | - if ($matches[1] === 'empty') |
|
| 180 | - return '\'\''; |
|
| 190 | + if ($matches[1] === 'empty') { |
|
| 191 | + return '\'\''; |
|
| 192 | + } |
|
| 181 | 193 | |
| 182 | - if (!isset($matches[2])) |
|
| 183 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 194 | + if (!isset($matches[2])) { |
|
| 195 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 196 | + } |
|
| 184 | 197 | |
| 185 | - if ($matches[1] === 'literal') |
|
| 186 | - return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
| 198 | + if ($matches[1] === 'literal') { |
|
| 199 | + return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
| 200 | + } |
|
| 187 | 201 | |
| 188 | - if (!isset($values[$matches[2]])) |
|
| 189 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 202 | + if (!isset($values[$matches[2]])) { |
|
| 203 | + 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__); |
|
| 204 | + } |
|
| 190 | 205 | |
| 191 | 206 | $replacement = $values[$matches[2]]; |
| 192 | 207 | |
| 193 | 208 | switch ($matches[1]) |
| 194 | 209 | { |
| 195 | 210 | case 'int': |
| 196 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 197 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 211 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 212 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 213 | + } |
|
| 198 | 214 | return (string) (int) $replacement; |
| 199 | 215 | break; |
| 200 | 216 | |
@@ -206,49 +222,55 @@ discard block |
||
| 206 | 222 | case 'array_int': |
| 207 | 223 | if (is_array($replacement)) |
| 208 | 224 | { |
| 209 | - if (empty($replacement)) |
|
| 210 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 225 | + if (empty($replacement)) { |
|
| 226 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 227 | + } |
|
| 211 | 228 | |
| 212 | 229 | foreach ($replacement as $key => $value) |
| 213 | 230 | { |
| 214 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 215 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 231 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 232 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 233 | + } |
|
| 216 | 234 | |
| 217 | 235 | $replacement[$key] = (string) (int) $value; |
| 218 | 236 | } |
| 219 | 237 | |
| 220 | 238 | return implode(', ', $replacement); |
| 239 | + } else { |
|
| 240 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 221 | 241 | } |
| 222 | - else |
|
| 223 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 224 | 242 | |
| 225 | 243 | break; |
| 226 | 244 | |
| 227 | 245 | case 'array_string': |
| 228 | 246 | if (is_array($replacement)) |
| 229 | 247 | { |
| 230 | - if (empty($replacement)) |
|
| 231 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 248 | + if (empty($replacement)) { |
|
| 249 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 250 | + } |
|
| 232 | 251 | |
| 233 | - foreach ($replacement as $key => $value) |
|
| 234 | - $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
| 252 | + foreach ($replacement as $key => $value) { |
|
| 253 | + $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
| 254 | + } |
|
| 235 | 255 | |
| 236 | 256 | return implode(', ', $replacement); |
| 257 | + } else { |
|
| 258 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 237 | 259 | } |
| 238 | - else |
|
| 239 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 240 | 260 | break; |
| 241 | 261 | |
| 242 | 262 | case 'date': |
| 243 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
| 244 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 245 | - else |
|
| 246 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 263 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 264 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 265 | + } else { |
|
| 266 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 267 | + } |
|
| 247 | 268 | break; |
| 248 | 269 | |
| 249 | 270 | case 'float': |
| 250 | - if (!is_numeric($replacement)) |
|
| 251 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 271 | + if (!is_numeric($replacement)) { |
|
| 272 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 273 | + } |
|
| 252 | 274 | return (string) (float) $replacement; |
| 253 | 275 | break; |
| 254 | 276 | |
@@ -262,10 +284,12 @@ discard block |
||
| 262 | 284 | break; |
| 263 | 285 | |
| 264 | 286 | case 'inet': |
| 265 | - if ($replacement == 'null' || $replacement == '') |
|
| 266 | - return 'null'; |
|
| 267 | - if (!isValidIP($replacement)) |
|
| 268 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 287 | + if ($replacement == 'null' || $replacement == '') { |
|
| 288 | + return 'null'; |
|
| 289 | + } |
|
| 290 | + if (!isValidIP($replacement)) { |
|
| 291 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 292 | + } |
|
| 269 | 293 | //we don't use the native support of mysql > 5.6.2 |
| 270 | 294 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
| 271 | 295 | break; |
@@ -273,22 +297,25 @@ discard block |
||
| 273 | 297 | case 'array_inet': |
| 274 | 298 | if (is_array($replacement)) |
| 275 | 299 | { |
| 276 | - if (empty($replacement)) |
|
| 277 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 300 | + if (empty($replacement)) { |
|
| 301 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 302 | + } |
|
| 278 | 303 | |
| 279 | 304 | foreach ($replacement as $key => $value) |
| 280 | 305 | { |
| 281 | - if ($replacement == 'null' || $replacement == '') |
|
| 282 | - $replacement[$key] = 'null'; |
|
| 283 | - if (!isValidIP($value)) |
|
| 284 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 306 | + if ($replacement == 'null' || $replacement == '') { |
|
| 307 | + $replacement[$key] = 'null'; |
|
| 308 | + } |
|
| 309 | + if (!isValidIP($value)) { |
|
| 310 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 311 | + } |
|
| 285 | 312 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
| 286 | 313 | } |
| 287 | 314 | |
| 288 | 315 | return implode(', ', $replacement); |
| 316 | + } else { |
|
| 317 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 289 | 318 | } |
| 290 | - else |
|
| 291 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 292 | 319 | break; |
| 293 | 320 | |
| 294 | 321 | default: |
@@ -364,22 +391,25 @@ discard block |
||
| 364 | 391 | // Are we in SSI mode? If so try that username and password first |
| 365 | 392 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
| 366 | 393 | { |
| 367 | - if (empty($db_persist)) |
|
| 368 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 369 | - else |
|
| 370 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 394 | + if (empty($db_persist)) { |
|
| 395 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 396 | + } else { |
|
| 397 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 398 | + } |
|
| 371 | 399 | } |
| 372 | 400 | // Fall back to the regular username and password if need be |
| 373 | 401 | if (!$db_connection) |
| 374 | 402 | { |
| 375 | - if (empty($db_persist)) |
|
| 376 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 377 | - else |
|
| 378 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 403 | + if (empty($db_persist)) { |
|
| 404 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 405 | + } else { |
|
| 406 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 407 | + } |
|
| 379 | 408 | } |
| 380 | 409 | |
| 381 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
| 382 | - $db_connection = false; |
|
| 410 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
| 411 | + $db_connection = false; |
|
| 412 | + } |
|
| 383 | 413 | |
| 384 | 414 | $connection = $db_connection; |
| 385 | 415 | } |
@@ -387,18 +417,20 @@ discard block |
||
| 387 | 417 | // One more query.... |
| 388 | 418 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 389 | 419 | |
| 390 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 391 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 420 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 421 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 422 | + } |
|
| 392 | 423 | |
| 393 | 424 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
| 394 | 425 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
| 395 | 426 | { |
| 396 | 427 | // Add before LIMIT |
| 397 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
| 398 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 399 | - else |
|
| 400 | - // Append it. |
|
| 428 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
| 429 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 430 | + } else { |
|
| 431 | + // Append it. |
|
| 401 | 432 | $db_string .= "\n\t\t\tORDER BY null"; |
| 433 | + } |
|
| 402 | 434 | } |
| 403 | 435 | |
| 404 | 436 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -420,8 +452,9 @@ discard block |
||
| 420 | 452 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 421 | 453 | |
| 422 | 454 | // Initialize $db_cache if not already initialized. |
| 423 | - if (!isset($db_cache)) |
|
| 424 | - $db_cache = array(); |
|
| 455 | + if (!isset($db_cache)) { |
|
| 456 | + $db_cache = array(); |
|
| 457 | + } |
|
| 425 | 458 | |
| 426 | 459 | if (!empty($_SESSION['debug_redirect'])) |
| 427 | 460 | { |
@@ -447,17 +480,18 @@ discard block |
||
| 447 | 480 | while (true) |
| 448 | 481 | { |
| 449 | 482 | $pos = strpos($db_string, '\'', $pos + 1); |
| 450 | - if ($pos === false) |
|
| 451 | - break; |
|
| 483 | + if ($pos === false) { |
|
| 484 | + break; |
|
| 485 | + } |
|
| 452 | 486 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
| 453 | 487 | |
| 454 | 488 | while (true) |
| 455 | 489 | { |
| 456 | 490 | $pos1 = strpos($db_string, '\'', $pos + 1); |
| 457 | 491 | $pos2 = strpos($db_string, '\\', $pos + 1); |
| 458 | - if ($pos1 === false) |
|
| 459 | - break; |
|
| 460 | - elseif ($pos2 == false || $pos2 > $pos1) |
|
| 492 | + if ($pos1 === false) { |
|
| 493 | + break; |
|
| 494 | + } elseif ($pos2 == false || $pos2 > $pos1) |
|
| 461 | 495 | { |
| 462 | 496 | $pos = $pos1; |
| 463 | 497 | break; |
@@ -473,29 +507,35 @@ discard block |
||
| 473 | 507 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 474 | 508 | |
| 475 | 509 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 476 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 477 | - $fail = true; |
|
| 510 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 511 | + $fail = true; |
|
| 512 | + } |
|
| 478 | 513 | // Trying to change passwords, slow us down, or something? |
| 479 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 480 | - $fail = true; |
|
| 481 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 482 | - $fail = true; |
|
| 514 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 515 | + $fail = true; |
|
| 516 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 517 | + $fail = true; |
|
| 518 | + } |
|
| 483 | 519 | |
| 484 | - if (!empty($fail) && function_exists('log_error')) |
|
| 485 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 520 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 521 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 522 | + } |
|
| 486 | 523 | } |
| 487 | 524 | |
| 488 | - if (empty($db_unbuffered)) |
|
| 489 | - $ret = @mysqli_query($connection, $db_string); |
|
| 490 | - else |
|
| 491 | - $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
| 525 | + if (empty($db_unbuffered)) { |
|
| 526 | + $ret = @mysqli_query($connection, $db_string); |
|
| 527 | + } else { |
|
| 528 | + $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
| 529 | + } |
|
| 492 | 530 | |
| 493 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
| 494 | - $ret = smf_db_error($db_string, $connection); |
|
| 531 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
| 532 | + $ret = smf_db_error($db_string, $connection); |
|
| 533 | + } |
|
| 495 | 534 | |
| 496 | 535 | // Debugging. |
| 497 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 498 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 536 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 537 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 538 | + } |
|
| 499 | 539 | |
| 500 | 540 | return $ret; |
| 501 | 541 | } |
@@ -544,12 +584,13 @@ discard block |
||
| 544 | 584 | // Decide which connection to use |
| 545 | 585 | $connection = $connection === null ? $db_connection : $connection; |
| 546 | 586 | |
| 547 | - if ($type == 'begin') |
|
| 548 | - return @mysqli_query($connection, 'BEGIN'); |
|
| 549 | - elseif ($type == 'rollback') |
|
| 550 | - return @mysqli_query($connection, 'ROLLBACK'); |
|
| 551 | - elseif ($type == 'commit') |
|
| 552 | - return @mysqli_query($connection, 'COMMIT'); |
|
| 587 | + if ($type == 'begin') { |
|
| 588 | + return @mysqli_query($connection, 'BEGIN'); |
|
| 589 | + } elseif ($type == 'rollback') { |
|
| 590 | + return @mysqli_query($connection, 'ROLLBACK'); |
|
| 591 | + } elseif ($type == 'commit') { |
|
| 592 | + return @mysqli_query($connection, 'COMMIT'); |
|
| 593 | + } |
|
| 553 | 594 | |
| 554 | 595 | return false; |
| 555 | 596 | } |
@@ -589,8 +630,9 @@ discard block |
||
| 589 | 630 | // 2013: Lost connection to server during query. |
| 590 | 631 | |
| 591 | 632 | // Log the error. |
| 592 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
| 593 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 633 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
| 634 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 635 | + } |
|
| 594 | 636 | |
| 595 | 637 | // Database error auto fixing ;). |
| 596 | 638 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -599,8 +641,9 @@ discard block |
||
| 599 | 641 | $old_cache = @$modSettings['cache_enable']; |
| 600 | 642 | $modSettings['cache_enable'] = '1'; |
| 601 | 643 | |
| 602 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
| 603 | - $db_last_error = max(@$db_last_error, $temp); |
|
| 644 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
| 645 | + $db_last_error = max(@$db_last_error, $temp); |
|
| 646 | + } |
|
| 604 | 647 | |
| 605 | 648 | if (@$db_last_error < time() - 3600 * 24 * 3) |
| 606 | 649 | { |
@@ -616,8 +659,9 @@ discard block |
||
| 616 | 659 | foreach ($tables as $table) |
| 617 | 660 | { |
| 618 | 661 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
| 619 | - if (trim($table) != '') |
|
| 620 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 662 | + if (trim($table) != '') { |
|
| 663 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 664 | + } |
|
| 621 | 665 | } |
| 622 | 666 | } |
| 623 | 667 | |
@@ -626,8 +670,9 @@ discard block |
||
| 626 | 670 | // Table crashed. Let's try to fix it. |
| 627 | 671 | elseif ($query_errno == 1016) |
| 628 | 672 | { |
| 629 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
| 630 | - $fix_tables = array('`' . $match[1] . '`'); |
|
| 673 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
| 674 | + $fix_tables = array('`' . $match[1] . '`'); |
|
| 675 | + } |
|
| 631 | 676 | } |
| 632 | 677 | // Indexes crashed. Should be easy to fix! |
| 633 | 678 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -646,13 +691,15 @@ discard block |
||
| 646 | 691 | |
| 647 | 692 | // Make a note of the REPAIR... |
| 648 | 693 | cache_put_data('db_last_error', time(), 600); |
| 649 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
| 650 | - updateSettingsFile(array('db_last_error' => time())); |
|
| 694 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
| 695 | + updateSettingsFile(array('db_last_error' => time())); |
|
| 696 | + } |
|
| 651 | 697 | |
| 652 | 698 | // Attempt to find and repair the broken table. |
| 653 | - foreach ($fix_tables as $table) |
|
| 654 | - $smcFunc['db_query']('', " |
|
| 699 | + foreach ($fix_tables as $table) { |
|
| 700 | + $smcFunc['db_query']('', " |
|
| 655 | 701 | REPAIR TABLE $table", false, false); |
| 702 | + } |
|
| 656 | 703 | |
| 657 | 704 | // And send off an email! |
| 658 | 705 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -661,11 +708,12 @@ discard block |
||
| 661 | 708 | |
| 662 | 709 | // Try the query again...? |
| 663 | 710 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 664 | - if ($ret !== false) |
|
| 665 | - return $ret; |
|
| 711 | + if ($ret !== false) { |
|
| 712 | + return $ret; |
|
| 713 | + } |
|
| 714 | + } else { |
|
| 715 | + $modSettings['cache_enable'] = $old_cache; |
|
| 666 | 716 | } |
| 667 | - else |
|
| 668 | - $modSettings['cache_enable'] = $old_cache; |
|
| 669 | 717 | |
| 670 | 718 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
| 671 | 719 | if (in_array($query_errno, array(1205, 1213, 2006, 2013))) |
@@ -675,22 +723,25 @@ discard block |
||
| 675 | 723 | // Are we in SSI mode? If so try that username and password first |
| 676 | 724 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
| 677 | 725 | { |
| 678 | - if (empty($db_persist)) |
|
| 679 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 680 | - else |
|
| 681 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 726 | + if (empty($db_persist)) { |
|
| 727 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 728 | + } else { |
|
| 729 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 730 | + } |
|
| 682 | 731 | } |
| 683 | 732 | // Fall back to the regular username and password if need be |
| 684 | 733 | if (!$db_connection) |
| 685 | 734 | { |
| 686 | - if (empty($db_persist)) |
|
| 687 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 688 | - else |
|
| 689 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 735 | + if (empty($db_persist)) { |
|
| 736 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 737 | + } else { |
|
| 738 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 739 | + } |
|
| 690 | 740 | } |
| 691 | 741 | |
| 692 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
| 693 | - $db_connection = false; |
|
| 742 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
| 743 | + $db_connection = false; |
|
| 744 | + } |
|
| 694 | 745 | } |
| 695 | 746 | |
| 696 | 747 | if ($db_connection) |
@@ -701,24 +752,27 @@ discard block |
||
| 701 | 752 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 702 | 753 | |
| 703 | 754 | $new_errno = mysqli_errno($db_connection); |
| 704 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
| 705 | - break; |
|
| 755 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
| 756 | + break; |
|
| 757 | + } |
|
| 706 | 758 | } |
| 707 | 759 | |
| 708 | 760 | // If it failed again, shucks to be you... we're not trying it over and over. |
| 709 | - if ($ret !== false) |
|
| 710 | - return $ret; |
|
| 761 | + if ($ret !== false) { |
|
| 762 | + return $ret; |
|
| 763 | + } |
|
| 711 | 764 | } |
| 712 | 765 | } |
| 713 | 766 | // Are they out of space, perhaps? |
| 714 | 767 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
| 715 | 768 | { |
| 716 | - if (!isset($txt)) |
|
| 717 | - $query_error .= ' - check database storage space.'; |
|
| 718 | - else |
|
| 769 | + if (!isset($txt)) { |
|
| 770 | + $query_error .= ' - check database storage space.'; |
|
| 771 | + } else |
|
| 719 | 772 | { |
| 720 | - if (!isset($txt['mysql_error_space'])) |
|
| 721 | - loadLanguage('Errors'); |
|
| 773 | + if (!isset($txt['mysql_error_space'])) { |
|
| 774 | + loadLanguage('Errors'); |
|
| 775 | + } |
|
| 722 | 776 | |
| 723 | 777 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
| 724 | 778 | } |
@@ -726,15 +780,17 @@ discard block |
||
| 726 | 780 | } |
| 727 | 781 | |
| 728 | 782 | // Nothing's defined yet... just die with it. |
| 729 | - if (empty($context) || empty($txt)) |
|
| 730 | - die($query_error); |
|
| 783 | + if (empty($context) || empty($txt)) { |
|
| 784 | + die($query_error); |
|
| 785 | + } |
|
| 731 | 786 | |
| 732 | 787 | // Show an error message, if possible. |
| 733 | 788 | $context['error_title'] = $txt['database_error']; |
| 734 | - if (allowedTo('admin_forum')) |
|
| 735 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 736 | - else |
|
| 737 | - $context['error_message'] = $txt['try_again']; |
|
| 789 | + if (allowedTo('admin_forum')) { |
|
| 790 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 791 | + } else { |
|
| 792 | + $context['error_message'] = $txt['try_again']; |
|
| 793 | + } |
|
| 738 | 794 | |
| 739 | 795 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 740 | 796 | { |
@@ -763,25 +819,28 @@ discard block |
||
| 763 | 819 | $connection = $connection === null ? $db_connection : $connection; |
| 764 | 820 | |
| 765 | 821 | // With nothing to insert, simply return. |
| 766 | - if (empty($data)) |
|
| 767 | - return; |
|
| 822 | + if (empty($data)) { |
|
| 823 | + return; |
|
| 824 | + } |
|
| 768 | 825 | |
| 769 | 826 | // Replace the prefix holder with the actual prefix. |
| 770 | 827 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
| 771 | 828 | |
| 772 | 829 | // Inserting data as a single row can be done as a single array. |
| 773 | - if (!is_array($data[array_rand($data)])) |
|
| 774 | - $data = array($data); |
|
| 830 | + if (!is_array($data[array_rand($data)])) { |
|
| 831 | + $data = array($data); |
|
| 832 | + } |
|
| 775 | 833 | |
| 776 | 834 | // Create the mold for a single row insert. |
| 777 | 835 | $insertData = '('; |
| 778 | 836 | foreach ($columns as $columnName => $type) |
| 779 | 837 | { |
| 780 | 838 | // Are we restricting the length? |
| 781 | - if (strpos($type, 'string-') !== false) |
|
| 782 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 783 | - else |
|
| 784 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 839 | + if (strpos($type, 'string-') !== false) { |
|
| 840 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 841 | + } else { |
|
| 842 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 843 | + } |
|
| 785 | 844 | } |
| 786 | 845 | $insertData = substr($insertData, 0, -2) . ')'; |
| 787 | 846 | |
@@ -790,8 +849,9 @@ discard block |
||
| 790 | 849 | |
| 791 | 850 | // Here's where the variables are injected to the query. |
| 792 | 851 | $insertRows = array(); |
| 793 | - foreach ($data as $dataRow) |
|
| 794 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 852 | + foreach ($data as $dataRow) { |
|
| 853 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 854 | + } |
|
| 795 | 855 | |
| 796 | 856 | // Determine the method of insertion. |
| 797 | 857 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
@@ -822,8 +882,9 @@ discard block |
||
| 822 | 882 | */ |
| 823 | 883 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 824 | 884 | { |
| 825 | - if (empty($log_message)) |
|
| 826 | - $log_message = $error_message; |
|
| 885 | + if (empty($log_message)) { |
|
| 886 | + $log_message = $error_message; |
|
| 887 | + } |
|
| 827 | 888 | |
| 828 | 889 | foreach (debug_backtrace() as $step) |
| 829 | 890 | { |
@@ -842,12 +903,14 @@ discard block |
||
| 842 | 903 | } |
| 843 | 904 | |
| 844 | 905 | // A special case - we want the file and line numbers for debugging. |
| 845 | - if ($error_type == 'return') |
|
| 846 | - return array($file, $line); |
|
| 906 | + if ($error_type == 'return') { |
|
| 907 | + return array($file, $line); |
|
| 908 | + } |
|
| 847 | 909 | |
| 848 | 910 | // Is always a critical error. |
| 849 | - if (function_exists('log_error')) |
|
| 850 | - log_error($log_message, 'critical', $file, $line); |
|
| 911 | + if (function_exists('log_error')) { |
|
| 912 | + log_error($log_message, 'critical', $file, $line); |
|
| 913 | + } |
|
| 851 | 914 | |
| 852 | 915 | if (function_exists('fatal_error')) |
| 853 | 916 | { |
@@ -855,12 +918,12 @@ discard block |
||
| 855 | 918 | |
| 856 | 919 | // Cannot continue... |
| 857 | 920 | exit; |
| 921 | + } elseif ($error_type) { |
|
| 922 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 923 | + } else { |
|
| 924 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 925 | + } |
|
| 858 | 926 | } |
| 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 | -} |
|
| 864 | 927 | |
| 865 | 928 | /** |
| 866 | 929 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -877,10 +940,11 @@ discard block |
||
| 877 | 940 | '\\' => '\\\\', |
| 878 | 941 | ); |
| 879 | 942 | |
| 880 | - if ($translate_human_wildcards) |
|
| 881 | - $replacements += array( |
|
| 943 | + if ($translate_human_wildcards) { |
|
| 944 | + $replacements += array( |
|
| 882 | 945 | '*' => '%', |
| 883 | 946 | ); |
| 947 | + } |
|
| 884 | 948 | |
| 885 | 949 | return strtr($string, $replacements); |
| 886 | 950 | } |
@@ -894,8 +958,9 @@ discard block |
||
| 894 | 958 | */ |
| 895 | 959 | function smf_is_resource($result) |
| 896 | 960 | { |
| 897 | - if ($result instanceof mysqli_result) |
|
| 898 | - return true; |
|
| 961 | + if ($result instanceof mysqli_result) { |
|
| 962 | + return true; |
|
| 963 | + } |
|
| 899 | 964 | |
| 900 | 965 | return false; |
| 901 | 966 | } |