@@ -21,8 +21,8 @@ discard block |
||
| 21 | 21 | <div id="personal_messages">'; |
| 22 | 22 | |
| 23 | 23 | // Show the capacity bar, if available. |
| 24 | - if (!empty($context['limit_bar'])) |
|
| 25 | - echo ' |
|
| 24 | + if (!empty($context['limit_bar'])) { |
|
| 25 | + echo ' |
|
| 26 | 26 | <div class="cat_bar"> |
| 27 | 27 | <h3 class="catbg"> |
| 28 | 28 | <span class="floatleft">', $txt['pm_capacity'], ':</span> |
@@ -32,14 +32,16 @@ discard block |
||
| 32 | 32 | <span class="floatright', $context['limit_bar']['percent'] > 90 ? ' alert' : '', '">', $context['limit_bar']['text'], '</span> |
| 33 | 33 | </h3> |
| 34 | 34 | </div>'; |
| 35 | + } |
|
| 35 | 36 | |
| 36 | 37 | // Message sent? Show a small indication. |
| 37 | - if (isset($context['pm_sent'])) |
|
| 38 | - echo ' |
|
| 38 | + if (isset($context['pm_sent'])) { |
|
| 39 | + echo ' |
|
| 39 | 40 | <div class="infobox"> |
| 40 | 41 | ', $txt['pm_sent'], ' |
| 41 | 42 | </div>'; |
| 42 | -} |
|
| 43 | + } |
|
| 44 | + } |
|
| 43 | 45 | |
| 44 | 46 | /** |
| 45 | 47 | * Just the end of the index bar, nothing special. |
@@ -72,8 +74,7 @@ discard block |
||
| 72 | 74 | { |
| 73 | 75 | echo ' |
| 74 | 76 | <div class="no_unread">', $txt['pm_no_unread'], '</div>'; |
| 75 | - } |
|
| 76 | - else |
|
| 77 | + } else |
|
| 77 | 78 | { |
| 78 | 79 | foreach ($context['unread_pms'] as $id_pm => $pm_details) |
| 79 | 80 | { |
@@ -193,14 +194,15 @@ discard block |
||
| 193 | 194 | if ($context['get_pmessage']('message', true)) |
| 194 | 195 | { |
| 195 | 196 | // Show the helpful titlebar - generally. |
| 196 | - if ($context['display_mode'] != 1) |
|
| 197 | - echo ' |
|
| 197 | + if ($context['display_mode'] != 1) { |
|
| 198 | + echo ' |
|
| 198 | 199 | <div class="cat_bar"> |
| 199 | 200 | <h3 class="catbg"> |
| 200 | 201 | <span id="author">', $txt['author'], '</span> |
| 201 | 202 | <span id="topic_title">', $txt[$context['display_mode'] == 0 ? 'messages' : 'conversation'], '</span> |
| 202 | 203 | </h3> |
| 203 | 204 | </div>'; |
| 205 | + } |
|
| 204 | 206 | |
| 205 | 207 | // Show a few buttons if we are in conversation mode and outputting the first message. |
| 206 | 208 | if ($context['display_mode'] == 2) |
@@ -229,9 +231,10 @@ discard block |
||
| 229 | 231 | <div class="custom_fields_above_member"> |
| 230 | 232 | <ul class="nolist">'; |
| 231 | 233 | |
| 232 | - foreach ($message['custom_fields']['above_member'] as $custom) |
|
| 233 | - echo ' |
|
| 234 | + foreach ($message['custom_fields']['above_member'] as $custom) { |
|
| 235 | + echo ' |
|
| 234 | 236 | <li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>'; |
| 237 | + } |
|
| 235 | 238 | |
| 236 | 239 | echo ' |
| 237 | 240 | </ul> |
@@ -243,9 +246,10 @@ discard block |
||
| 243 | 246 | <a id="msg', $message['id'], '"></a>'; |
| 244 | 247 | |
| 245 | 248 | // Show online and offline buttons? |
| 246 | - if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest']) |
|
| 247 | - echo ' |
|
| 249 | + if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest']) { |
|
| 250 | + echo ' |
|
| 248 | 251 | <span class="' . ($message['member']['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $message['member']['online']['text'] . '"></span>'; |
| 252 | + } |
|
| 249 | 253 | |
| 250 | 254 | // Show a link to the member's profile (but only if the sender isn't a guest). |
| 251 | 255 | echo ' |
@@ -258,48 +262,56 @@ discard block |
||
| 258 | 262 | <ul class="user_info">'; |
| 259 | 263 | |
| 260 | 264 | // Show the user's avatar. |
| 261 | - if (!empty($modSettings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image'])) |
|
| 262 | - echo ' |
|
| 265 | + if (!empty($modSettings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image'])) { |
|
| 266 | + echo ' |
|
| 263 | 267 | <li class="avatar"> |
| 264 | 268 | <a href="', $scripturl, '?action=profile;u=', $message['member']['id'], '">', $message['member']['avatar']['image'], '</a> |
| 265 | 269 | </li>'; |
| 270 | + } |
|
| 266 | 271 | |
| 267 | 272 | // Are there any custom fields below the avatar? |
| 268 | - if (!empty($message['custom_fields']['below_avatar'])) |
|
| 269 | - foreach ($message['custom_fields']['below_avatar'] as $custom) |
|
| 273 | + if (!empty($message['custom_fields']['below_avatar'])) { |
|
| 274 | + foreach ($message['custom_fields']['below_avatar'] as $custom) |
|
| 270 | 275 | echo ' |
| 271 | 276 | <li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>'; |
| 277 | + } |
|
| 272 | 278 | |
| 273 | - if (!$message['member']['is_guest']) |
|
| 274 | - echo ' |
|
| 279 | + if (!$message['member']['is_guest']) { |
|
| 280 | + echo ' |
|
| 275 | 281 | <li class="icons">', $message['member']['group_icons'], '</li>'; |
| 282 | + } |
|
| 276 | 283 | // Show the member's primary group (like 'Administrator') if they have one. |
| 277 | - if (isset($message['member']['group']) && $message['member']['group'] != '') |
|
| 278 | - echo ' |
|
| 284 | + if (isset($message['member']['group']) && $message['member']['group'] != '') { |
|
| 285 | + echo ' |
|
| 279 | 286 | <li class="membergroup">', $message['member']['group'], '</li>'; |
| 287 | + } |
|
| 280 | 288 | |
| 281 | 289 | // Show the member's custom title, if they have one. |
| 282 | - if (isset($message['member']['title']) && $message['member']['title'] != '') |
|
| 283 | - echo ' |
|
| 290 | + if (isset($message['member']['title']) && $message['member']['title'] != '') { |
|
| 291 | + echo ' |
|
| 284 | 292 | <li class="title">', $message['member']['title'], '</li>'; |
| 293 | + } |
|
| 285 | 294 | |
| 286 | 295 | // Don't show these things for guests. |
| 287 | 296 | if (!$message['member']['is_guest']) |
| 288 | 297 | { |
| 289 | 298 | // Show the post group if and only if they have no other group or the option is on, and they are in a post group. |
| 290 | - if ((empty($modSettings['hide_post_group']) || $message['member']['group'] == '') && $message['member']['post_group'] != '') |
|
| 291 | - echo ' |
|
| 299 | + if ((empty($modSettings['hide_post_group']) || $message['member']['group'] == '') && $message['member']['post_group'] != '') { |
|
| 300 | + echo ' |
|
| 292 | 301 | <li class="postgroup">', $message['member']['post_group'], '</li>'; |
| 302 | + } |
|
| 293 | 303 | |
| 294 | 304 | // Show how many posts they have made. |
| 295 | - if (!isset($context['disabled_fields']['posts'])) |
|
| 296 | - echo ' |
|
| 305 | + if (!isset($context['disabled_fields']['posts'])) { |
|
| 306 | + echo ' |
|
| 297 | 307 | <li class="postcount">', $txt['member_postcount'], ': ', $message['member']['posts'], '</li>'; |
| 308 | + } |
|
| 298 | 309 | |
| 299 | 310 | // Show their personal text? |
| 300 | - if (!empty($modSettings['show_blurb']) && $message['member']['blurb'] != '') |
|
| 301 | - echo ' |
|
| 311 | + if (!empty($modSettings['show_blurb']) && $message['member']['blurb'] != '') { |
|
| 312 | + echo ' |
|
| 302 | 313 | <li class="blurb">', $message['member']['blurb'], '</li>'; |
| 314 | + } |
|
| 303 | 315 | |
| 304 | 316 | // Any custom fields to show as icons? |
| 305 | 317 | if (!empty($message['custom_fields']['icons'])) |
@@ -308,9 +320,10 @@ discard block |
||
| 308 | 320 | <li class="im_icons"> |
| 309 | 321 | <ol>'; |
| 310 | 322 | |
| 311 | - foreach ($message['custom_fields']['icons'] as $custom) |
|
| 312 | - echo ' |
|
| 323 | + foreach ($message['custom_fields']['icons'] as $custom) { |
|
| 324 | + echo ' |
|
| 313 | 325 | <li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>'; |
| 326 | + } |
|
| 314 | 327 | |
| 315 | 328 | echo ' |
| 316 | 329 | </ol> |
@@ -318,19 +331,22 @@ discard block |
||
| 318 | 331 | } |
| 319 | 332 | |
| 320 | 333 | // Show the IP to this user for this post - because you can moderate? |
| 321 | - if (!empty($context['can_moderate_forum']) && !empty($message['member']['ip'])) |
|
| 322 | - echo ' |
|
| 334 | + if (!empty($context['can_moderate_forum']) && !empty($message['member']['ip'])) { |
|
| 335 | + echo ' |
|
| 323 | 336 | <li class="poster_ip"><a href="', $scripturl, '?action=', !empty($message['member']['is_guest']) ? 'trackip' : 'profile;area=tracking;sa=ip;u=' . $message['member']['id'], ';searchip=', $message['member']['ip'], '">', $message['member']['ip'], '</a> <a href="', $scripturl, '?action=helpadmin;help=see_admin_ip" onclick="return reqOverlayDiv(this.href);" class="help">(?)</a></li>'; |
| 337 | + } |
|
| 324 | 338 | |
| 325 | 339 | // Or, should we show it because this is you? |
| 326 | - elseif ($message['can_see_ip']) |
|
| 327 | - echo ' |
|
| 340 | + elseif ($message['can_see_ip']) { |
|
| 341 | + echo ' |
|
| 328 | 342 | <li class="poster_ip"><a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $message['member']['ip'], '</a></li>'; |
| 343 | + } |
|
| 329 | 344 | |
| 330 | 345 | // Okay, you are logged in, then we can show something about why IPs are logged... |
| 331 | - else |
|
| 332 | - echo ' |
|
| 346 | + else { |
|
| 347 | + echo ' |
|
| 333 | 348 | <li class="poster_ip"><a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $txt['logged'], '</a></li>'; |
| 349 | + } |
|
| 334 | 350 | |
| 335 | 351 | // Show the profile, website, email address, and personal message buttons. |
| 336 | 352 | if ($message['member']['show_profile_buttons']) |
@@ -340,24 +356,28 @@ discard block |
||
| 340 | 356 | <ol class="profile_icons">'; |
| 341 | 357 | |
| 342 | 358 | // Show the profile button |
| 343 | - if ($message['member']['can_view_profile']) |
|
| 344 | - echo ' |
|
| 359 | + if ($message['member']['can_view_profile']) { |
|
| 360 | + echo ' |
|
| 345 | 361 | <li><a href="', $message['member']['href'], '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/icons/profile_sm.png" alt="' . $txt['view_profile'] . '" title="' . $txt['view_profile'] . '">' : $txt['view_profile']), '</a></li>'; |
| 362 | + } |
|
| 346 | 363 | |
| 347 | 364 | // Don't show an icon if they haven't specified a website. |
| 348 | - if ($message['member']['website']['url'] != '' && !isset($context['disabled_fields']['website'])) |
|
| 349 | - echo ' |
|
| 365 | + if ($message['member']['website']['url'] != '' && !isset($context['disabled_fields']['website'])) { |
|
| 366 | + echo ' |
|
| 350 | 367 | <li><a href="', $message['member']['website']['url'], '" title="' . $message['member']['website']['title'] . '" target="_blank" class="new_win">', ($settings['use_image_buttons'] ? '<span class="generic_icons www centericon" title="' . $message['member']['website']['title'] . '"></span>' : $txt['www']), '</a></li>'; |
| 368 | + } |
|
| 351 | 369 | |
| 352 | 370 | // Don't show the email address if they want it hidden. |
| 353 | - if ($message['member']['show_email']) |
|
| 354 | - echo ' |
|
| 371 | + if ($message['member']['show_email']) { |
|
| 372 | + echo ' |
|
| 355 | 373 | <li><a href="mailto:', $message['member']['email'], '" rel="nofollow">', ($settings['use_image_buttons'] ? '<span class="generic_icons mail centericon" title="' . $txt['email'] . '"></span>' : $txt['email']), '</a></li>'; |
| 374 | + } |
|
| 356 | 375 | |
| 357 | 376 | // Since we know this person isn't a guest, you *can* message them. |
| 358 | - if ($context['can_send_pm']) |
|
| 359 | - echo ' |
|
| 377 | + if ($context['can_send_pm']) { |
|
| 378 | + echo ' |
|
| 360 | 379 | <li><a href="', $scripturl, '?action=pm;sa=send;u=', $message['member']['id'], '" title="', $message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline'], '">', $settings['use_image_buttons'] ? '<span class="generic_icons im_' . ($message['member']['online']['is_online'] ? 'on' : 'off') . ' centericon" title="' . ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']) . '"></span> ' : ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']), '</a></li>'; |
| 380 | + } |
|
| 361 | 381 | |
| 362 | 382 | echo ' |
| 363 | 383 | </ol> |
@@ -365,21 +385,24 @@ discard block |
||
| 365 | 385 | } |
| 366 | 386 | |
| 367 | 387 | // Any custom fields for standard placement? |
| 368 | - if (!empty($message['custom_fields']['standard'])) |
|
| 369 | - foreach ($message['custom_fields']['standard'] as $custom) |
|
| 388 | + if (!empty($message['custom_fields']['standard'])) { |
|
| 389 | + foreach ($message['custom_fields']['standard'] as $custom) |
|
| 370 | 390 | echo ' |
| 371 | 391 | <li class="custom ', $custom['col_name'] ,'">', $custom['title'], ': ', $custom['value'], '</li>'; |
| 392 | + } |
|
| 372 | 393 | |
| 373 | 394 | // Are we showing the warning status? |
| 374 | - if ($message['member']['can_see_warning']) |
|
| 375 | - echo ' |
|
| 395 | + if ($message['member']['can_see_warning']) { |
|
| 396 | + echo ' |
|
| 376 | 397 | <li class="warning">', $context['can_issue_warning'] ? '<a href="' . $scripturl . '?action=profile;area=issuewarning;u=' . $message['member']['id'] . '">' : '', '<span class="generic_icons warning_', $message['member']['warning_status'], '"></span>', $context['can_issue_warning'] ? '</a>' : '', '<span class="warn_', $message['member']['warning_status'], '">', $txt['warn_' . $message['member']['warning_status']], '</span></li>'; |
| 398 | + } |
|
| 377 | 399 | |
| 378 | 400 | // Are there any custom fields to show at the bottom of the poster info? |
| 379 | - if (!empty($message['custom_fields']['bottom_poster'])) |
|
| 380 | - foreach ($message['custom_fields']['bottom_poster'] as $custom) |
|
| 401 | + if (!empty($message['custom_fields']['bottom_poster'])) { |
|
| 402 | + foreach ($message['custom_fields']['bottom_poster'] as $custom) |
|
| 381 | 403 | echo ' |
| 382 | 404 | <li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>'; |
| 405 | + } |
|
| 383 | 406 | } |
| 384 | 407 | |
| 385 | 408 | // Done with the information about the poster... on to the post itself. |
@@ -398,24 +421,28 @@ discard block |
||
| 398 | 421 | <span class="smalltext">« <strong> ', $txt['sent_to'], ':</strong> '; |
| 399 | 422 | |
| 400 | 423 | // People it was sent directly to.... |
| 401 | - if (!empty($message['recipients']['to'])) |
|
| 402 | - echo implode(', ', $message['recipients']['to']); |
|
| 424 | + if (!empty($message['recipients']['to'])) { |
|
| 425 | + echo implode(', ', $message['recipients']['to']); |
|
| 426 | + } |
|
| 403 | 427 | // Otherwise, we're just going to say "some people"... |
| 404 | - elseif ($context['folder'] != 'sent') |
|
| 405 | - echo '(', $txt['pm_undisclosed_recipients'], ')'; |
|
| 428 | + elseif ($context['folder'] != 'sent') { |
|
| 429 | + echo '(', $txt['pm_undisclosed_recipients'], ')'; |
|
| 430 | + } |
|
| 406 | 431 | |
| 407 | 432 | echo ' |
| 408 | 433 | <strong> ', $txt['on'], ':</strong> ', $message['time'], ' » |
| 409 | 434 | </span>'; |
| 410 | 435 | |
| 411 | 436 | // If we're in the sent items, show who it was sent to besides the "To:" people. |
| 412 | - if (!empty($message['recipients']['bcc'])) |
|
| 413 | - echo ' |
|
| 437 | + if (!empty($message['recipients']['bcc'])) { |
|
| 438 | + echo ' |
|
| 414 | 439 | <br><span class="smalltext">« <strong> ', $txt['pm_bcc'], ':</strong> ', implode(', ', $message['recipients']['bcc']), ' »</span>'; |
| 440 | + } |
|
| 415 | 441 | |
| 416 | - if (!empty($message['is_replied_to'])) |
|
| 417 | - echo ' |
|
| 442 | + if (!empty($message['is_replied_to'])) { |
|
| 443 | + echo ' |
|
| 418 | 444 | <br><span class="smalltext">« ', $context['folder'] == 'sent' ? $txt['pm_sent_is_replied_to'] : $txt['pm_is_replied_to'], ' »</span>'; |
| 445 | + } |
|
| 419 | 446 | |
| 420 | 447 | echo ' |
| 421 | 448 | </div> |
@@ -423,13 +450,15 @@ discard block |
||
| 423 | 450 | <div class="post"> |
| 424 | 451 | <div class="inner" id="msg_', $message['id'], '"', '>', $message['body'], '</div>'; |
| 425 | 452 | |
| 426 | - if ($message['can_report'] || $context['can_send_pm']) |
|
| 427 | - echo ' |
|
| 453 | + if ($message['can_report'] || $context['can_send_pm']) { |
|
| 454 | + echo ' |
|
| 428 | 455 | <div class="under_message">'; |
| 456 | + } |
|
| 429 | 457 | |
| 430 | - if ($message['can_report']) |
|
| 431 | - echo ' |
|
| 458 | + if ($message['can_report']) { |
|
| 459 | + echo ' |
|
| 432 | 460 | <a href="' . $scripturl . '?action=pm;sa=report;l=' . $context['current_label_id'] . ';pmsg=' . $message['id'] . '" class="floatright">' . $txt['pm_report_to_admin'] . '</a>'; |
| 461 | + } |
|
| 433 | 462 | |
| 434 | 463 | echo ' |
| 435 | 464 | <ul class="quickbuttons">'; |
@@ -441,32 +470,36 @@ discard block |
||
| 441 | 470 | if (!$message['member']['is_guest']) |
| 442 | 471 | { |
| 443 | 472 | // Is there than more than one recipient you can reply to? |
| 444 | - if ($message['number_recipients'] > 1) |
|
| 445 | - echo ' |
|
| 473 | + if ($message['number_recipients'] > 1) { |
|
| 474 | + echo ' |
|
| 446 | 475 | <li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote;u=all"><span class="generic_icons reply_all_button"></span>', $txt['reply_to_all'], '</a></li>'; |
| 476 | + } |
|
| 447 | 477 | |
| 448 | 478 | echo ' |
| 449 | 479 | <li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';u=', $message['member']['id'], '"><span class="generic_icons reply_button"></span>', $txt['reply'], '</a></li> |
| 450 | 480 | <li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote', $context['folder'] == 'sent' ? '' : ';u=' . $message['member']['id'], '"><span class="generic_icons quote"></span>', $txt['quote_action'], '</a></li>'; |
| 451 | 481 | } |
| 452 | 482 | // This is for "forwarding" - even if the member is gone. |
| 453 | - else |
|
| 454 | - echo ' |
|
| 483 | + else { |
|
| 484 | + echo ' |
|
| 455 | 485 | <li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote"><span class="generic_icons quote"></span>', $txt['reply_quote'], '</a></li>'; |
| 486 | + } |
|
| 456 | 487 | } |
| 457 | 488 | echo ' |
| 458 | 489 | <li><a href="', $scripturl, '?action=pm;sa=pmactions;pm_actions%5b', $message['id'], '%5D=delete;f=', $context['folder'], ';start=', $context['start'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';', $context['session_var'], '=', $context['session_id'], '" data-confirm="', addslashes($txt['remove_message_question']), '" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['delete'], '</a></li>'; |
| 459 | 490 | |
| 460 | - if (empty($context['display_mode'])) |
|
| 461 | - echo ' |
|
| 491 | + if (empty($context['display_mode'])) { |
|
| 492 | + echo ' |
|
| 462 | 493 | <li><input type="checkbox" name="pms[]" id="deletedisplay', $message['id'], '" value="', $message['id'], '" onclick="document.getElementById(\'deletelisting', $message['id'], '\').checked = this.checked;" class="input_check"></li>'; |
| 494 | + } |
|
| 463 | 495 | |
| 464 | 496 | echo ' |
| 465 | 497 | </ul>'; |
| 466 | 498 | |
| 467 | - if ($message['can_report'] || $context['can_send_pm']) |
|
| 468 | - echo ' |
|
| 499 | + if ($message['can_report'] || $context['can_send_pm']) { |
|
| 500 | + echo ' |
|
| 469 | 501 | </div>'; |
| 502 | + } |
|
| 470 | 503 | |
| 471 | 504 | // Are there any custom profile fields for above the signature? |
| 472 | 505 | if (!empty($message['custom_fields']['above_signature'])) |
@@ -475,9 +508,10 @@ discard block |
||
| 475 | 508 | <div class="custom_fields_above_signature"> |
| 476 | 509 | <ul class="nolist">'; |
| 477 | 510 | |
| 478 | - foreach ($message['custom_fields']['above_signature'] as $custom) |
|
| 479 | - echo ' |
|
| 511 | + foreach ($message['custom_fields']['above_signature'] as $custom) { |
|
| 512 | + echo ' |
|
| 480 | 513 | <li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>'; |
| 514 | + } |
|
| 481 | 515 | |
| 482 | 516 | echo ' |
| 483 | 517 | </ul> |
@@ -485,9 +519,10 @@ discard block |
||
| 485 | 519 | } |
| 486 | 520 | |
| 487 | 521 | // Show the member's signature? |
| 488 | - if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled']) |
|
| 489 | - echo ' |
|
| 522 | + if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled']) { |
|
| 523 | + echo ' |
|
| 490 | 524 | <div class="signature">', $message['member']['signature'], '</div>'; |
| 525 | + } |
|
| 491 | 526 | |
| 492 | 527 | // Are there any custom profile fields for below the signature? |
| 493 | 528 | if (!empty($message['custom_fields']['below_signature'])) |
@@ -496,9 +531,10 @@ discard block |
||
| 496 | 531 | <div class="custom_fields_below_signature"> |
| 497 | 532 | <ul class="nolist">'; |
| 498 | 533 | |
| 499 | - foreach ($message['custom_fields']['below_signature'] as $custom) |
|
| 500 | - echo ' |
|
| 534 | + foreach ($message['custom_fields']['below_signature'] as $custom) { |
|
| 535 | + echo ' |
|
| 501 | 536 | <li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>'; |
| 537 | + } |
|
| 502 | 538 | |
| 503 | 539 | echo ' |
| 504 | 540 | </ul> |
@@ -523,19 +559,21 @@ discard block |
||
| 523 | 559 | { |
| 524 | 560 | echo ' |
| 525 | 561 | <option value="" disabled>', $txt['pm_msg_label_apply'], ':</option>'; |
| 526 | - foreach ($context['labels'] as $label) |
|
| 527 | - if (!isset($message['labels'][$label['id']])) |
|
| 562 | + foreach ($context['labels'] as $label) { |
|
| 563 | + if (!isset($message['labels'][$label['id']])) |
|
| 528 | 564 | echo ' |
| 529 | 565 | <option value="', $label['id'], '"> ', $label['name'], '</option>'; |
| 566 | + } |
|
| 530 | 567 | } |
| 531 | 568 | // ... and are there any that can be removed? |
| 532 | 569 | if (!empty($message['labels']) && (count($message['labels']) > 1 || !isset($message['labels'][-1]))) |
| 533 | 570 | { |
| 534 | 571 | echo ' |
| 535 | 572 | <option value="" disabled>', $txt['pm_msg_label_remove'], ':</option>'; |
| 536 | - foreach ($message['labels'] as $label) |
|
| 537 | - echo ' |
|
| 573 | + foreach ($message['labels'] as $label) { |
|
| 574 | + echo ' |
|
| 538 | 575 | <option value="', $label['id'], '"> ', $label['name'], '</option>'; |
| 576 | + } |
|
| 539 | 577 | } |
| 540 | 578 | echo ' |
| 541 | 579 | </select> |
@@ -555,13 +593,14 @@ discard block |
||
| 555 | 593 | </div>'; |
| 556 | 594 | } |
| 557 | 595 | |
| 558 | - if (empty($context['display_mode'])) |
|
| 559 | - echo ' |
|
| 596 | + if (empty($context['display_mode'])) { |
|
| 597 | + echo ' |
|
| 560 | 598 | |
| 561 | 599 | <div class="pagesection"> |
| 562 | 600 | <div class="floatleft">', $context['page_index'], '</div> |
| 563 | 601 | <div class="floatright"><input type="submit" name="del_selected" value="', $txt['quickmod_delete_selected'], '" style="font-weight: normal;" onclick="if (!confirm(\'', $txt['delete_selected_confirm'], '\')) return false;" class="button_submit"></div> |
| 564 | 602 | </div>'; |
| 603 | + } |
|
| 565 | 604 | |
| 566 | 605 | // Show a few buttons if we are in conversation mode and outputting the first message. |
| 567 | 606 | elseif ($context['display_mode'] == 2 && isset($context['conversation_buttons'])) |
@@ -621,11 +660,12 @@ discard block |
||
| 621 | 660 | </tr> |
| 622 | 661 | </thead> |
| 623 | 662 | <tbody>'; |
| 624 | - if (!$context['show_delete']) |
|
| 625 | - echo ' |
|
| 663 | + if (!$context['show_delete']) { |
|
| 664 | + echo ' |
|
| 626 | 665 | <tr class="windowbg"> |
| 627 | 666 | <td colspan="5">', $txt['pm_alert_none'], '</td> |
| 628 | 667 | </tr>'; |
| 668 | + } |
|
| 629 | 669 | |
| 630 | 670 | while ($message = $context['get_pmessage']('subject')) |
| 631 | 671 | { |
@@ -678,9 +718,10 @@ discard block |
||
| 678 | 718 | |
| 679 | 719 | foreach ($context['labels'] as $label) |
| 680 | 720 | { |
| 681 | - if ($label['id'] != $context['current_label_id']) |
|
| 682 | - echo ' |
|
| 721 | + if ($label['id'] != $context['current_label_id']) { |
|
| 722 | + echo ' |
|
| 683 | 723 | <option value="add_', $label['id'], '"> ', $label['name'], '</option>'; |
| 724 | + } |
|
| 684 | 725 | } |
| 685 | 726 | |
| 686 | 727 | echo ' |
@@ -765,9 +806,10 @@ discard block |
||
| 765 | 806 | <dt class="between">', $txt['pm_search_post_age'], ':</dt> |
| 766 | 807 | <dd>', $txt['pm_search_between'], ' <input type="number" name="minage" value="', empty($context['search_params']['minage']) ? '0' : $context['search_params']['minage'], '" size="5" maxlength="5" class="input_text" min="0" max="9999"> ', $txt['pm_search_between_and'], ' <input type="number" name="maxage" value="', empty($context['search_params']['maxage']) ? '9999' : $context['search_params']['maxage'], '" size="5" maxlength="5" class="input_text" min="0" max="9999"> ', $txt['pm_search_between_days'], '</dd> |
| 767 | 808 | </dl>'; |
| 768 | - if (!$context['currently_using_labels']) |
|
| 769 | - echo ' |
|
| 809 | + if (!$context['currently_using_labels']) { |
|
| 810 | + echo ' |
|
| 770 | 811 | <input type="submit" name="pm_search" value="', $txt['pm_search_go'], '" class="button_submit">'; |
| 812 | + } |
|
| 771 | 813 | echo ' |
| 772 | 814 | <br class="clear_right"> |
| 773 | 815 | </div> |
@@ -787,12 +829,13 @@ discard block |
||
| 787 | 829 | <div id="advanced_panel_div"> |
| 788 | 830 | <ul id="searchLabelsExpand">'; |
| 789 | 831 | |
| 790 | - foreach ($context['search_labels'] as $label) |
|
| 791 | - echo ' |
|
| 832 | + foreach ($context['search_labels'] as $label) { |
|
| 833 | + echo ' |
|
| 792 | 834 | <li> |
| 793 | 835 | <label for="searchlabel_', $label['id'], '"><input type="checkbox" id="searchlabel_', $label['id'], '" name="searchlabel[', $label['id'], ']" value="', $label['id'], '"', $label['checked'] ? ' checked' : '', ' class="input_check"> |
| 794 | 836 | ', $label['name'], '</label> |
| 795 | 837 | </li>'; |
| 838 | + } |
|
| 796 | 839 | |
| 797 | 840 | echo ' |
| 798 | 841 | </ul> |
@@ -852,8 +895,8 @@ discard block |
||
| 852 | 895 | </div>'; |
| 853 | 896 | |
| 854 | 897 | // complete results ? |
| 855 | - if (empty($context['search_params']['show_complete']) && !empty($context['personal_messages'])) |
|
| 856 | - echo ' |
|
| 898 | + if (empty($context['search_params']['show_complete']) && !empty($context['personal_messages'])) { |
|
| 899 | + echo ' |
|
| 857 | 900 | <table class="table_grid"> |
| 858 | 901 | <thead> |
| 859 | 902 | <tr class="title_bar"> |
@@ -863,6 +906,7 @@ discard block |
||
| 863 | 906 | </tr> |
| 864 | 907 | </thead> |
| 865 | 908 | <tbody>'; |
| 909 | + } |
|
| 866 | 910 | |
| 867 | 911 | // Print each message out... |
| 868 | 912 | foreach ($context['personal_messages'] as $message) |
@@ -882,11 +926,13 @@ discard block |
||
| 882 | 926 | |
| 883 | 927 | // Show the recipients. |
| 884 | 928 | // @todo This doesn't deal with the sent item searching quite right for bcc. |
| 885 | - if (!empty($message['recipients']['to'])) |
|
| 886 | - echo implode(', ', $message['recipients']['to']); |
|
| 929 | + if (!empty($message['recipients']['to'])) { |
|
| 930 | + echo implode(', ', $message['recipients']['to']); |
|
| 931 | + } |
|
| 887 | 932 | // Otherwise, we're just going to say "some people"... |
| 888 | - elseif ($context['folder'] != 'sent') |
|
| 889 | - echo '(', $txt['pm_undisclosed_recipients'], ')'; |
|
| 933 | + elseif ($context['folder'] != 'sent') { |
|
| 934 | + echo '(', $txt['pm_undisclosed_recipients'], ')'; |
|
| 935 | + } |
|
| 890 | 936 | |
| 891 | 937 | echo ' |
| 892 | 938 | </h3> |
@@ -900,14 +946,16 @@ discard block |
||
| 900 | 946 | $quote_button = create_button('quote.png', 'reply_quote', 'reply_quote', 'class="centericon"'); |
| 901 | 947 | $reply_button = create_button('im_reply.png', 'reply', 'reply', 'class="centericon"'); |
| 902 | 948 | // You can only reply if they are not a guest... |
| 903 | - if (!$message['member']['is_guest']) |
|
| 904 | - echo ' |
|
| 949 | + if (!$message['member']['is_guest']) { |
|
| 950 | + echo ' |
|
| 905 | 951 | <a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote;u=', $context['folder'] == 'sent' ? '' : $message['member']['id'], '">', $quote_button , '</a>', $context['menu_separator'], ' |
| 906 | 952 | <a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';u=', $message['member']['id'], '">', $reply_button , '</a> ', $context['menu_separator']; |
| 953 | + } |
|
| 907 | 954 | // This is for "forwarding" - even if the member is gone. |
| 908 | - else |
|
| 909 | - echo ' |
|
| 955 | + else { |
|
| 956 | + echo ' |
|
| 910 | 957 | <a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote">', $quote_button , '</a>', $context['menu_separator']; |
| 958 | + } |
|
| 911 | 959 | } |
| 912 | 960 | |
| 913 | 961 | echo ' |
@@ -928,17 +976,19 @@ discard block |
||
| 928 | 976 | } |
| 929 | 977 | |
| 930 | 978 | // Finish off the page... |
| 931 | - if (empty($context['search_params']['show_complete']) && !empty($context['personal_messages'])) |
|
| 932 | - echo ' |
|
| 979 | + if (empty($context['search_params']['show_complete']) && !empty($context['personal_messages'])) { |
|
| 980 | + echo ' |
|
| 933 | 981 | </tbody> |
| 934 | 982 | </table>'; |
| 983 | + } |
|
| 935 | 984 | |
| 936 | 985 | // No results? |
| 937 | - if (empty($context['personal_messages'])) |
|
| 938 | - echo ' |
|
| 986 | + if (empty($context['personal_messages'])) { |
|
| 987 | + echo ' |
|
| 939 | 988 | <div class="windowbg"> |
| 940 | 989 | <p class="centertext">', $txt['pm_search_none_found'], '</p> |
| 941 | 990 | </div>'; |
| 991 | + } |
|
| 942 | 992 | |
| 943 | 993 | echo ' |
| 944 | 994 | <div class="pagesection"> |
@@ -962,12 +1012,14 @@ discard block |
||
| 962 | 1012 | <h3 class="catbg">', $txt['pm_send_report'], '</h3> |
| 963 | 1013 | </div> |
| 964 | 1014 | <div class="windowbg">'; |
| 965 | - if (!empty($context['send_log']['sent'])) |
|
| 966 | - foreach ($context['send_log']['sent'] as $log_entry) |
|
| 1015 | + if (!empty($context['send_log']['sent'])) { |
|
| 1016 | + foreach ($context['send_log']['sent'] as $log_entry) |
|
| 967 | 1017 | echo '<span class="error">', $log_entry, '</span><br>'; |
| 968 | - if (!empty($context['send_log']['failed'])) |
|
| 969 | - foreach ($context['send_log']['failed'] as $log_entry) |
|
| 1018 | + } |
|
| 1019 | + if (!empty($context['send_log']['failed'])) { |
|
| 1020 | + foreach ($context['send_log']['failed'] as $log_entry) |
|
| 970 | 1021 | echo '<span class="error">', $log_entry, '</span><br>'; |
| 1022 | + } |
|
| 971 | 1023 | echo ' |
| 972 | 1024 | </div> |
| 973 | 1025 | <br>'; |
@@ -1015,12 +1067,13 @@ discard block |
||
| 1015 | 1067 | </dl> |
| 1016 | 1068 | </div>'; |
| 1017 | 1069 | |
| 1018 | - if (!empty($modSettings['drafts_pm_enabled'])) |
|
| 1019 | - echo ' |
|
| 1070 | + if (!empty($modSettings['drafts_pm_enabled'])) { |
|
| 1071 | + echo ' |
|
| 1020 | 1072 | <div id="draft_section" class="infobox"', isset($context['draft_saved']) ? '' : ' style="display: none;"', '>', |
| 1021 | 1073 | sprintf($txt['draft_pm_saved'], $scripturl . '?action=pm;sa=showpmdrafts'), ' |
| 1022 | 1074 | ', (!empty($modSettings['drafts_keep_days']) ? ' <strong>' . sprintf($txt['draft_save_warning'], $modSettings['drafts_keep_days']) . '</strong>' : ''), ' |
| 1023 | 1075 | </div>'; |
| 1076 | + } |
|
| 1024 | 1077 | |
| 1025 | 1078 | echo ' |
| 1026 | 1079 | <dl id="post_header">'; |
@@ -1075,9 +1128,10 @@ discard block |
||
| 1075 | 1128 | } |
| 1076 | 1129 | |
| 1077 | 1130 | // What about smileys? |
| 1078 | - if (!empty($context['smileys']['postform']) || !empty($context['smileys']['popup'])) |
|
| 1079 | - echo ' |
|
| 1131 | + if (!empty($context['smileys']['postform']) || !empty($context['smileys']['popup'])) { |
|
| 1132 | + echo ' |
|
| 1080 | 1133 | <div id="smileyBox_message"></div>'; |
| 1134 | + } |
|
| 1081 | 1135 | |
| 1082 | 1136 | // Show BBC buttons, smileys and textbox. |
| 1083 | 1137 | echo ' |
@@ -1124,10 +1178,11 @@ discard block |
||
| 1124 | 1178 | <dt><strong>', $txt['subject'], '</strong></dt> |
| 1125 | 1179 | <dd><strong>', $txt['draft_saved_on'], '</strong></dd>'; |
| 1126 | 1180 | |
| 1127 | - foreach ($context['drafts'] as $draft) |
|
| 1128 | - echo ' |
|
| 1181 | + foreach ($context['drafts'] as $draft) { |
|
| 1182 | + echo ' |
|
| 1129 | 1183 | <dt>', $draft['link'], '</dt> |
| 1130 | 1184 | <dd>', $draft['poster_time'], '</dd>'; |
| 1185 | + } |
|
| 1131 | 1186 | echo ' |
| 1132 | 1187 | </dl> |
| 1133 | 1188 | </div>'; |
@@ -1233,8 +1288,8 @@ discard block |
||
| 1233 | 1288 | }'; |
| 1234 | 1289 | |
| 1235 | 1290 | // Code for showing and hiding drafts |
| 1236 | - if (!empty($context['drafts'])) |
|
| 1237 | - echo ' |
|
| 1291 | + if (!empty($context['drafts'])) { |
|
| 1292 | + echo ' |
|
| 1238 | 1293 | var oSwapDraftOptions = new smc_Toggle({ |
| 1239 | 1294 | bToggleEnabled: true, |
| 1240 | 1295 | bCurrentlyCollapsed: true, |
@@ -1256,13 +1311,14 @@ discard block |
||
| 1256 | 1311 | } |
| 1257 | 1312 | ] |
| 1258 | 1313 | });'; |
| 1314 | + } |
|
| 1259 | 1315 | |
| 1260 | 1316 | echo ' |
| 1261 | 1317 | </script>'; |
| 1262 | 1318 | |
| 1263 | 1319 | // Show the message you're replying to. |
| 1264 | - if ($context['reply']) |
|
| 1265 | - echo ' |
|
| 1320 | + if ($context['reply']) { |
|
| 1321 | + echo ' |
|
| 1266 | 1322 | <br> |
| 1267 | 1323 | <br> |
| 1268 | 1324 | <div class="cat_bar"> |
@@ -1276,6 +1332,7 @@ discard block |
||
| 1276 | 1332 | <hr> |
| 1277 | 1333 | ', $context['quoted_message']['body'], ' |
| 1278 | 1334 | </div><br class="clear">'; |
| 1335 | + } |
|
| 1279 | 1336 | |
| 1280 | 1337 | echo ' |
| 1281 | 1338 | <script> |
@@ -1286,22 +1343,24 @@ discard block |
||
| 1286 | 1343 | sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\', |
| 1287 | 1344 | sToControlId: \'to_control\', |
| 1288 | 1345 | aToRecipients: ['; |
| 1289 | - foreach ($context['recipients']['to'] as $i => $member) |
|
| 1290 | - echo ' |
|
| 1346 | + foreach ($context['recipients']['to'] as $i => $member) { |
|
| 1347 | + echo ' |
|
| 1291 | 1348 | { |
| 1292 | 1349 | sItemId: ', JavaScriptEscape($member['id']), ', |
| 1293 | 1350 | sItemName: ', JavaScriptEscape($member['name']), ' |
| 1294 | 1351 | }', $i == count($context['recipients']['to']) - 1 ? '' : ','; |
| 1352 | + } |
|
| 1295 | 1353 | |
| 1296 | 1354 | echo ' |
| 1297 | 1355 | ], |
| 1298 | 1356 | aBccRecipients: ['; |
| 1299 | - foreach ($context['recipients']['bcc'] as $i => $member) |
|
| 1300 | - echo ' |
|
| 1357 | + foreach ($context['recipients']['bcc'] as $i => $member) { |
|
| 1358 | + echo ' |
|
| 1301 | 1359 | { |
| 1302 | 1360 | sItemId: ', JavaScriptEscape($member['id']), ', |
| 1303 | 1361 | sItemName: ', JavaScriptEscape($member['name']), ' |
| 1304 | 1362 | }', $i == count($context['recipients']['bcc']) - 1 ? '' : ','; |
| 1363 | + } |
|
| 1305 | 1364 | |
| 1306 | 1365 | echo ' |
| 1307 | 1366 | ], |
@@ -1388,26 +1447,28 @@ discard block |
||
| 1388 | 1447 | </th> |
| 1389 | 1448 | <th class="centertext table_icon">'; |
| 1390 | 1449 | |
| 1391 | - if (count($context['labels']) > 2) |
|
| 1392 | - echo ' |
|
| 1450 | + if (count($context['labels']) > 2) { |
|
| 1451 | + echo ' |
|
| 1393 | 1452 | <input type="checkbox" class="input_check" onclick="invertAll(this, this.form);">'; |
| 1453 | + } |
|
| 1394 | 1454 | |
| 1395 | 1455 | echo ' |
| 1396 | 1456 | </th> |
| 1397 | 1457 | </tr> |
| 1398 | 1458 | </thead> |
| 1399 | 1459 | <tbody>'; |
| 1400 | - if (count($context['labels']) < 2) |
|
| 1401 | - echo ' |
|
| 1460 | + if (count($context['labels']) < 2) { |
|
| 1461 | + echo ' |
|
| 1402 | 1462 | <tr class="windowbg"> |
| 1403 | 1463 | <td colspan="2">', $txt['pm_labels_no_exist'], '</td> |
| 1404 | 1464 | </tr>'; |
| 1405 | - else |
|
| 1465 | + } else |
|
| 1406 | 1466 | { |
| 1407 | 1467 | foreach ($context['labels'] as $label) |
| 1408 | 1468 | { |
| 1409 | - if ($label['id'] == -1) |
|
| 1410 | - continue; |
|
| 1469 | + if ($label['id'] == -1) { |
|
| 1470 | + continue; |
|
| 1471 | + } |
|
| 1411 | 1472 | |
| 1412 | 1473 | echo ' |
| 1413 | 1474 | <tr class="windowbg"> |
@@ -1422,12 +1483,13 @@ discard block |
||
| 1422 | 1483 | </tbody> |
| 1423 | 1484 | </table>'; |
| 1424 | 1485 | |
| 1425 | - if (!count($context['labels']) < 2) |
|
| 1426 | - echo ' |
|
| 1486 | + if (!count($context['labels']) < 2) { |
|
| 1487 | + echo ' |
|
| 1427 | 1488 | <div class="padding"> |
| 1428 | 1489 | <input type="submit" name="save" value="', $txt['save'], '" class="button_submit"> |
| 1429 | 1490 | <input type="submit" name="delete" value="', $txt['quickmod_delete_selected'], '" data-confirm="', $txt['pm_labels_delete'] ,'" class="button_submit you_sure"> |
| 1430 | 1491 | </div>'; |
| 1492 | + } |
|
| 1431 | 1493 | |
| 1432 | 1494 | echo ' |
| 1433 | 1495 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
@@ -1482,9 +1544,10 @@ discard block |
||
| 1482 | 1544 | <dd> |
| 1483 | 1545 | <select name="id_admin"> |
| 1484 | 1546 | <option value="0">', $txt['pm_report_all_admins'], '</option>'; |
| 1485 | - foreach ($context['admins'] as $id => $name) |
|
| 1486 | - echo ' |
|
| 1547 | + foreach ($context['admins'] as $id => $name) { |
|
| 1548 | + echo ' |
|
| 1487 | 1549 | <option value="', $id, '">', $name, '</option>'; |
| 1550 | + } |
|
| 1488 | 1551 | echo ' |
| 1489 | 1552 | </select> |
| 1490 | 1553 | </dd>'; |
@@ -1546,9 +1609,10 @@ discard block |
||
| 1546 | 1609 | </th> |
| 1547 | 1610 | <th class="centertext table_icon">'; |
| 1548 | 1611 | |
| 1549 | - if (!empty($context['rules'])) |
|
| 1550 | - echo ' |
|
| 1612 | + if (!empty($context['rules'])) { |
|
| 1613 | + echo ' |
|
| 1551 | 1614 | <input type="checkbox" onclick="invertAll(this, this.form);" class="input_check">'; |
| 1615 | + } |
|
| 1552 | 1616 | |
| 1553 | 1617 | echo ' |
| 1554 | 1618 | </th> |
@@ -1556,13 +1620,14 @@ discard block |
||
| 1556 | 1620 | </thead> |
| 1557 | 1621 | <tbody>'; |
| 1558 | 1622 | |
| 1559 | - if (empty($context['rules'])) |
|
| 1560 | - echo ' |
|
| 1623 | + if (empty($context['rules'])) { |
|
| 1624 | + echo ' |
|
| 1561 | 1625 | <tr class="windowbg"> |
| 1562 | 1626 | <td colspan="2"> |
| 1563 | 1627 | ', $txt['pm_rules_none'], ' |
| 1564 | 1628 | </td> |
| 1565 | 1629 | </tr>'; |
| 1630 | + } |
|
| 1566 | 1631 | |
| 1567 | 1632 | foreach ($context['rules'] as $rule) |
| 1568 | 1633 | { |
@@ -1583,14 +1648,16 @@ discard block |
||
| 1583 | 1648 | <div class="righttext"> |
| 1584 | 1649 | <a class="button_link" href="', $scripturl, '?action=pm;sa=manrules;add;rid=0">', $txt['pm_add_rule'], '</a>'; |
| 1585 | 1650 | |
| 1586 | - if (!empty($context['rules'])) |
|
| 1587 | - echo ' |
|
| 1651 | + if (!empty($context['rules'])) { |
|
| 1652 | + echo ' |
|
| 1588 | 1653 | [<a href="', $scripturl, '?action=pm;sa=manrules;apply;', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['pm_js_apply_rules_confirm'], '\');">', $txt['pm_apply_rules'], '</a>]'; |
| 1654 | + } |
|
| 1589 | 1655 | |
| 1590 | - if (!empty($context['rules'])) |
|
| 1591 | - echo ' |
|
| 1656 | + if (!empty($context['rules'])) { |
|
| 1657 | + echo ' |
|
| 1592 | 1658 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
| 1593 | 1659 | <input type="submit" name="delselected" value="', $txt['pm_delete_selected_rule'], '" data-confirm="', $txt['pm_js_delete_rule_confirm'] ,'" class="button_submit smalltext you_sure">'; |
| 1660 | + } |
|
| 1594 | 1661 | |
| 1595 | 1662 | echo ' |
| 1596 | 1663 | </div> |
@@ -1612,14 +1679,16 @@ discard block |
||
| 1612 | 1679 | var groups = new Array() |
| 1613 | 1680 | var labels = new Array()'; |
| 1614 | 1681 | |
| 1615 | - foreach ($context['groups'] as $id => $title) |
|
| 1616 | - echo ' |
|
| 1682 | + foreach ($context['groups'] as $id => $title) { |
|
| 1683 | + echo ' |
|
| 1617 | 1684 | groups[', $id, '] = "', addslashes($title), '";'; |
| 1685 | + } |
|
| 1618 | 1686 | |
| 1619 | - foreach ($context['labels'] as $label) |
|
| 1620 | - if ($label['id'] != -1) |
|
| 1687 | + foreach ($context['labels'] as $label) { |
|
| 1688 | + if ($label['id'] != -1) |
|
| 1621 | 1689 | echo ' |
| 1622 | 1690 | labels[', ($label['id']), '] = "', addslashes($label['name']), '";'; |
| 1691 | + } |
|
| 1623 | 1692 | |
| 1624 | 1693 | echo ' |
| 1625 | 1694 | function addCriteriaOption() |
@@ -1634,8 +1703,9 @@ discard block |
||
| 1634 | 1703 | |
| 1635 | 1704 | setOuterHTML(document.getElementById("criteriaAddHere"), \'<br><select name="ruletype[\' + criteriaNum + \']" id="ruletype\' + criteriaNum + \'" onchange="updateRuleDef(\' + criteriaNum + \'); rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_criteria_pick']), ':<\' + \'/option><option value="mid">', addslashes($txt['pm_rule_mid']), '<\' + \'/option><option value="gid">', addslashes($txt['pm_rule_gid']), '<\' + \'/option><option value="sub">', addslashes($txt['pm_rule_sub']), '<\' + \'/option><option value="msg">', addslashes($txt['pm_rule_msg']), '<\' + \'/option><option value="bud">', addslashes($txt['pm_rule_bud']), '<\' + \'/option><\' + \'/select> <span id="defdiv\' + criteriaNum + \'" style="display: none;"><input type="text" name="ruledef[\' + criteriaNum + \']" id="ruledef\' + criteriaNum + \'" onkeyup="rebuildRuleDesc();" value="" class="input_text"><\' + \'/span><span id="defseldiv\' + criteriaNum + \'" style="display: none;"><select name="ruledefgroup[\' + criteriaNum + \']" id="ruledefgroup\' + criteriaNum + \'" onchange="rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_sel_group']), '<\' + \'/option>'; |
| 1636 | 1705 | |
| 1637 | - foreach ($context['groups'] as $id => $group) |
|
| 1638 | - echo '<option value="', $id, '">', strtr($group, array("'" => "\'")), '<\' + \'/option>'; |
|
| 1706 | + foreach ($context['groups'] as $id => $group) { |
|
| 1707 | + echo '<option value="', $id, '">', strtr($group, array("'" => "\'")), '<\' + \'/option>'; |
|
| 1708 | + } |
|
| 1639 | 1709 | |
| 1640 | 1710 | echo '<\' + \'/select><\' + \'/span><span id="criteriaAddHere"><\' + \'/span>\'); |
| 1641 | 1711 | } |
@@ -1652,9 +1722,10 @@ discard block |
||
| 1652 | 1722 | |
| 1653 | 1723 | setOuterHTML(document.getElementById("actionAddHere"), \'<br><select name="acttype[\' + actionNum + \']" id="acttype\' + actionNum + \'" onchange="updateActionDef(\' + actionNum + \'); rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_sel_action']), ':<\' + \'/option><option value="lab">', addslashes($txt['pm_rule_label']), '<\' + \'/option><option value="del">', addslashes($txt['pm_rule_delete']), '<\' + \'/option><\' + \'/select> <span id="labdiv\' + actionNum + \'" style="display: none;"><select name="labdef[\' + actionNum + \']" id="labdef\' + actionNum + \'" onchange="rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_sel_label']), '<\' + \'/option>'; |
| 1654 | 1724 | |
| 1655 | - foreach ($context['labels'] as $label) |
|
| 1656 | - if ($label['id'] != -1) |
|
| 1725 | + foreach ($context['labels'] as $label) { |
|
| 1726 | + if ($label['id'] != -1) |
|
| 1657 | 1727 | echo '<option value="', ($label['id']), '">', addslashes($label['name']), '<\' + \'/option>'; |
| 1728 | + } |
|
| 1658 | 1729 | |
| 1659 | 1730 | echo '<\' + \'/select><\' + \'/span><span id="actionAddHere"><\' + \'/span>\'); |
| 1660 | 1731 | } |
@@ -1768,18 +1839,20 @@ discard block |
||
| 1768 | 1839 | $isFirst = true; |
| 1769 | 1840 | foreach ($context['rule']['criteria'] as $k => $criteria) |
| 1770 | 1841 | { |
| 1771 | - if (!$isFirst && $criteria['t'] == '') |
|
| 1772 | - echo '<div id="removeonjs1">'; |
|
| 1773 | - elseif (!$isFirst) |
|
| 1774 | - echo '<br>'; |
|
| 1842 | + if (!$isFirst && $criteria['t'] == '') { |
|
| 1843 | + echo '<div id="removeonjs1">'; |
|
| 1844 | + } elseif (!$isFirst) { |
|
| 1845 | + echo '<br>'; |
|
| 1846 | + } |
|
| 1775 | 1847 | |
| 1776 | 1848 | echo ' |
| 1777 | 1849 | <select name="ruletype[', $k, ']" id="ruletype', $k, '" onchange="updateRuleDef(', $k, '); rebuildRuleDesc();"> |
| 1778 | 1850 | <option value="">', $txt['pm_rule_criteria_pick'], ':</option>'; |
| 1779 | 1851 | |
| 1780 | - foreach (array('mid', 'gid', 'sub', 'msg', 'bud') as $cr) |
|
| 1781 | - echo ' |
|
| 1852 | + foreach (array('mid', 'gid', 'sub', 'msg', 'bud') as $cr) { |
|
| 1853 | + echo ' |
|
| 1782 | 1854 | <option value="', $cr, '"', $criteria['t'] == $cr ? ' selected' : '', '>', $txt['pm_rule_' . $cr], '</option>'; |
| 1855 | + } |
|
| 1783 | 1856 | |
| 1784 | 1857 | echo ' |
| 1785 | 1858 | </select> |
@@ -1790,18 +1863,20 @@ discard block |
||
| 1790 | 1863 | <select name="ruledefgroup[', $k, ']" id="ruledefgroup', $k, '" onchange="rebuildRuleDesc();"> |
| 1791 | 1864 | <option value="">', $txt['pm_rule_sel_group'], '</option>'; |
| 1792 | 1865 | |
| 1793 | - foreach ($context['groups'] as $id => $group) |
|
| 1794 | - echo ' |
|
| 1866 | + foreach ($context['groups'] as $id => $group) { |
|
| 1867 | + echo ' |
|
| 1795 | 1868 | <option value="', $id, '"', $criteria['t'] == 'gid' && $criteria['v'] == $id ? ' selected' : '', '>', $group, '</option>'; |
| 1869 | + } |
|
| 1796 | 1870 | echo ' |
| 1797 | 1871 | </select> |
| 1798 | 1872 | </span>'; |
| 1799 | 1873 | |
| 1800 | 1874 | // If this is the dummy we add a means to hide for non js users. |
| 1801 | - if ($isFirst) |
|
| 1802 | - $isFirst = false; |
|
| 1803 | - elseif ($criteria['t'] == '') |
|
| 1804 | - echo '</div>'; |
|
| 1875 | + if ($isFirst) { |
|
| 1876 | + $isFirst = false; |
|
| 1877 | + } elseif ($criteria['t'] == '') { |
|
| 1878 | + echo '</div>'; |
|
| 1879 | + } |
|
| 1805 | 1880 | } |
| 1806 | 1881 | |
| 1807 | 1882 | echo ' |
@@ -1824,10 +1899,11 @@ discard block |
||
| 1824 | 1899 | $isFirst = true; |
| 1825 | 1900 | foreach ($context['rule']['actions'] as $k => $action) |
| 1826 | 1901 | { |
| 1827 | - if (!$isFirst && $action['t'] == '') |
|
| 1828 | - echo '<div id="removeonjs2">'; |
|
| 1829 | - elseif (!$isFirst) |
|
| 1830 | - echo '<br>'; |
|
| 1902 | + if (!$isFirst && $action['t'] == '') { |
|
| 1903 | + echo '<div id="removeonjs2">'; |
|
| 1904 | + } elseif (!$isFirst) { |
|
| 1905 | + echo '<br>'; |
|
| 1906 | + } |
|
| 1831 | 1907 | |
| 1832 | 1908 | echo ' |
| 1833 | 1909 | <select name="acttype[', $k, ']" id="acttype', $k, '" onchange="updateActionDef(', $k, '); rebuildRuleDesc();"> |
@@ -1838,20 +1914,22 @@ discard block |
||
| 1838 | 1914 | <span id="labdiv', $k, '"> |
| 1839 | 1915 | <select name="labdef[', $k, ']" id="labdef', $k, '" onchange="rebuildRuleDesc();"> |
| 1840 | 1916 | <option value="">', $txt['pm_rule_sel_label'], '</option>'; |
| 1841 | - foreach ($context['labels'] as $label) |
|
| 1842 | - if ($label['id'] != -1) |
|
| 1917 | + foreach ($context['labels'] as $label) { |
|
| 1918 | + if ($label['id'] != -1) |
|
| 1843 | 1919 | echo ' |
| 1844 | 1920 | <option value="', ($label['id']), '"', $action['t'] == 'lab' && $action['v'] == $label['id'] ? ' selected' : '', '>', $label['name'], '</option>'; |
| 1921 | + } |
|
| 1845 | 1922 | |
| 1846 | 1923 | echo ' |
| 1847 | 1924 | </select> |
| 1848 | 1925 | </span>'; |
| 1849 | 1926 | |
| 1850 | - if ($isFirst) |
|
| 1851 | - $isFirst = false; |
|
| 1852 | - elseif ($action['t'] == '') |
|
| 1853 | - echo ' |
|
| 1927 | + if ($isFirst) { |
|
| 1928 | + $isFirst = false; |
|
| 1929 | + } elseif ($action['t'] == '') { |
|
| 1930 | + echo ' |
|
| 1854 | 1931 | </div>'; |
| 1932 | + } |
|
| 1855 | 1933 | } |
| 1856 | 1934 | |
| 1857 | 1935 | echo ' |
@@ -1875,22 +1953,25 @@ discard block |
||
| 1875 | 1953 | echo ' |
| 1876 | 1954 | <script>'; |
| 1877 | 1955 | |
| 1878 | - foreach ($context['rule']['criteria'] as $k => $c) |
|
| 1879 | - echo ' |
|
| 1956 | + foreach ($context['rule']['criteria'] as $k => $c) { |
|
| 1957 | + echo ' |
|
| 1880 | 1958 | updateRuleDef(', $k, ');'; |
| 1959 | + } |
|
| 1881 | 1960 | |
| 1882 | - foreach ($context['rule']['actions'] as $k => $c) |
|
| 1883 | - echo ' |
|
| 1961 | + foreach ($context['rule']['actions'] as $k => $c) { |
|
| 1962 | + echo ' |
|
| 1884 | 1963 | updateActionDef(', $k, ');'; |
| 1964 | + } |
|
| 1885 | 1965 | |
| 1886 | 1966 | echo ' |
| 1887 | 1967 | rebuildRuleDesc();'; |
| 1888 | 1968 | |
| 1889 | 1969 | // If this isn't a new rule and we have JS enabled remove the JS compatibility stuff. |
| 1890 | - if ($context['rid']) |
|
| 1891 | - echo ' |
|
| 1970 | + if ($context['rid']) { |
|
| 1971 | + echo ' |
|
| 1892 | 1972 | document.getElementById("removeonjs1").style.display = "none"; |
| 1893 | 1973 | document.getElementById("removeonjs2").style.display = "none";'; |
| 1974 | + } |
|
| 1894 | 1975 | |
| 1895 | 1976 | echo ' |
| 1896 | 1977 | document.getElementById("addonjs1").style.display = ""; |
@@ -1918,12 +1999,12 @@ discard block |
||
| 1918 | 1999 | </div>'; |
| 1919 | 2000 | |
| 1920 | 2001 | // No drafts? Just show an informative message. |
| 1921 | - if (empty($context['drafts'])) |
|
| 1922 | - echo ' |
|
| 2002 | + if (empty($context['drafts'])) { |
|
| 2003 | + echo ' |
|
| 1923 | 2004 | <div class="windowbg2 centertext"> |
| 1924 | 2005 | ', $txt['draft_none'], ' |
| 1925 | 2006 | </div>'; |
| 1926 | - else |
|
| 2007 | + } else |
|
| 1927 | 2008 | { |
| 1928 | 2009 | // For every draft to be displayed, give it its own div, and show the important details of the draft. |
| 1929 | 2010 | foreach ($context['drafts'] as $draft) |
@@ -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 | * Retrieve a list and several other statistics of the users currently online. |
@@ -45,8 +46,9 @@ discard block |
||
| 45 | 46 | } |
| 46 | 47 | |
| 47 | 48 | // Not allowed sort method? Bang! Error! |
| 48 | - elseif (!in_array($membersOnlineOptions['sort'], $allowed_sort_options)) |
|
| 49 | - trigger_error('Sort method for getMembersOnlineStats() function is not allowed', E_USER_NOTICE); |
|
| 49 | + elseif (!in_array($membersOnlineOptions['sort'], $allowed_sort_options)) { |
|
| 50 | + trigger_error('Sort method for getMembersOnlineStats() function is not allowed', E_USER_NOTICE); |
|
| 51 | + } |
|
| 50 | 52 | |
| 51 | 53 | // Initialize the array that'll be returned later on. |
| 52 | 54 | $membersOnlineStats = array( |
@@ -63,8 +65,9 @@ discard block |
||
| 63 | 65 | // Get any spiders if enabled. |
| 64 | 66 | $spiders = array(); |
| 65 | 67 | $spider_finds = array(); |
| 66 | - if (!empty($modSettings['show_spider_online']) && ($modSettings['show_spider_online'] < 3 || allowedTo('admin_forum')) && !empty($modSettings['spider_name_cache'])) |
|
| 67 | - $spiders = smf_json_decode($modSettings['spider_name_cache'], true); |
|
| 68 | + if (!empty($modSettings['show_spider_online']) && ($modSettings['show_spider_online'] < 3 || allowedTo('admin_forum')) && !empty($modSettings['spider_name_cache'])) { |
|
| 69 | + $spiders = smf_json_decode($modSettings['spider_name_cache'], true); |
|
| 70 | + } |
|
| 68 | 71 | |
| 69 | 72 | // Load the users online right now. |
| 70 | 73 | $request = $smcFunc['db_query']('', ' |
@@ -92,9 +95,7 @@ discard block |
||
| 92 | 95 | $membersOnlineStats['num_guests']++; |
| 93 | 96 | |
| 94 | 97 | continue; |
| 95 | - } |
|
| 96 | - |
|
| 97 | - elseif (empty($row['show_online']) && empty($membersOnlineOptions['show_hidden'])) |
|
| 98 | + } elseif (empty($row['show_online']) && empty($membersOnlineOptions['show_hidden'])) |
|
| 98 | 99 | { |
| 99 | 100 | // Just increase the stats and don't add this hidden user to any list. |
| 100 | 101 | $membersOnlineStats['num_users_hidden']++; |
@@ -102,10 +103,11 @@ discard block |
||
| 102 | 103 | } |
| 103 | 104 | |
| 104 | 105 | // Some basic color coding... |
| 105 | - if (!empty($row['online_color'])) |
|
| 106 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
| 107 | - else |
|
| 108 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 106 | + if (!empty($row['online_color'])) { |
|
| 107 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
| 108 | + } else { |
|
| 109 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 110 | + } |
|
| 109 | 111 | |
| 110 | 112 | // Buddies get counted and highlighted. |
| 111 | 113 | $is_buddy = in_array($row['id_member'], $user_info['buddies']); |
@@ -132,12 +134,13 @@ discard block |
||
| 132 | 134 | $membersOnlineStats['list_users_online'][$row[$membersOnlineOptions['sort']] . '_' . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
| 133 | 135 | |
| 134 | 136 | // Store all distinct (primary) membergroups that are shown. |
| 135 | - if (!isset($membersOnlineStats['online_groups'][$row['id_group']])) |
|
| 136 | - $membersOnlineStats['online_groups'][$row['id_group']] = array( |
|
| 137 | + if (!isset($membersOnlineStats['online_groups'][$row['id_group']])) { |
|
| 138 | + $membersOnlineStats['online_groups'][$row['id_group']] = array( |
|
| 137 | 139 | 'id' => $row['id_group'], |
| 138 | 140 | 'name' => $row['group_name'], |
| 139 | 141 | 'color' => $row['online_color'] |
| 140 | 142 | ); |
| 143 | + } |
|
| 141 | 144 | } |
| 142 | 145 | $smcFunc['db_free_result']($request); |
| 143 | 146 | |
@@ -198,11 +201,12 @@ discard block |
||
| 198 | 201 | $settingsToUpdate = array(); |
| 199 | 202 | |
| 200 | 203 | // More members on now than ever were? Update it! |
| 201 | - if (!isset($modSettings['mostOnline']) || $total_users_online >= $modSettings['mostOnline']) |
|
| 202 | - $settingsToUpdate = array( |
|
| 204 | + if (!isset($modSettings['mostOnline']) || $total_users_online >= $modSettings['mostOnline']) { |
|
| 205 | + $settingsToUpdate = array( |
|
| 203 | 206 | 'mostOnline' => $total_users_online, |
| 204 | 207 | 'mostDate' => time() |
| 205 | 208 | ); |
| 209 | + } |
|
| 206 | 210 | |
| 207 | 211 | $date = strftime('%Y-%m-%d', forum_time(false)); |
| 208 | 212 | |
@@ -234,8 +238,9 @@ discard block |
||
| 234 | 238 | { |
| 235 | 239 | list ($modSettings['mostOnlineToday']) = $smcFunc['db_fetch_row']($request); |
| 236 | 240 | |
| 237 | - if ($total_users_online > $modSettings['mostOnlineToday']) |
|
| 238 | - trackStats(array('most_on' => $total_users_online)); |
|
| 241 | + if ($total_users_online > $modSettings['mostOnlineToday']) { |
|
| 242 | + trackStats(array('most_on' => $total_users_online)); |
|
| 243 | + } |
|
| 239 | 244 | |
| 240 | 245 | $total_users_online = max($total_users_online, $modSettings['mostOnlineToday']); |
| 241 | 246 | } |
@@ -252,8 +257,9 @@ discard block |
||
| 252 | 257 | $settingsToUpdate['mostOnlineToday'] = $total_users_online; |
| 253 | 258 | } |
| 254 | 259 | |
| 255 | - if (!empty($settingsToUpdate)) |
|
| 256 | - updateSettings($settingsToUpdate); |
|
| 257 | -} |
|
| 260 | + if (!empty($settingsToUpdate)) { |
|
| 261 | + updateSettings($settingsToUpdate); |
|
| 262 | + } |
|
| 263 | + } |
|
| 258 | 264 | |
| 259 | 265 | ?> |
| 260 | 266 | \ No newline at end of file |
@@ -18,8 +18,9 @@ discard block |
||
| 18 | 18 | * @version 2.1 Beta 3 |
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | -if (!defined('SMF')) |
|
| 21 | +if (!defined('SMF')) { |
|
| 22 | 22 | die('No direct access...'); |
| 23 | +} |
|
| 23 | 24 | |
| 24 | 25 | /** |
| 25 | 26 | * downloads a file from a url and stores it locally for avatar use by id_member. |
@@ -44,8 +45,9 @@ discard block |
||
| 44 | 45 | $destName = 'avatar_' . $memID . '_' . time() . '.' . $ext; |
| 45 | 46 | |
| 46 | 47 | // Just making sure there is a non-zero member. |
| 47 | - if (empty($memID)) |
|
| 48 | - return false; |
|
| 48 | + if (empty($memID)) { |
|
| 49 | + return false; |
|
| 50 | + } |
|
| 49 | 51 | |
| 50 | 52 | require_once($sourcedir . '/ManageAttachments.php'); |
| 51 | 53 | removeAttachments(array('id_member' => $memID)); |
@@ -76,10 +78,11 @@ discard block |
||
| 76 | 78 | $destName = $modSettings['custom_avatar_dir'] . '/' . $destName . '.tmp'; |
| 77 | 79 | |
| 78 | 80 | // Resize it. |
| 79 | - if (!empty($modSettings['avatar_download_png'])) |
|
| 80 | - $success = resizeImageFile($url, $destName, $max_width, $max_height, 3); |
|
| 81 | - else |
|
| 82 | - $success = resizeImageFile($url, $destName, $max_width, $max_height); |
|
| 81 | + if (!empty($modSettings['avatar_download_png'])) { |
|
| 82 | + $success = resizeImageFile($url, $destName, $max_width, $max_height, 3); |
|
| 83 | + } else { |
|
| 84 | + $success = resizeImageFile($url, $destName, $max_width, $max_height); |
|
| 85 | + } |
|
| 83 | 86 | |
| 84 | 87 | // Remove the .tmp extension. |
| 85 | 88 | $destName = substr($destName, 0, -4); |
@@ -108,11 +111,10 @@ discard block |
||
| 108 | 111 | ) |
| 109 | 112 | ); |
| 110 | 113 | return true; |
| 114 | + } else { |
|
| 115 | + return false; |
|
| 111 | 116 | } |
| 112 | - else |
|
| 113 | - return false; |
|
| 114 | - } |
|
| 115 | - else |
|
| 117 | + } else |
|
| 116 | 118 | { |
| 117 | 119 | $smcFunc['db_query']('', ' |
| 118 | 120 | DELETE FROM {db_prefix}attachments |
@@ -144,17 +146,18 @@ discard block |
||
| 144 | 146 | $destName = $source . '_thumb.tmp'; |
| 145 | 147 | |
| 146 | 148 | // Do the actual resize. |
| 147 | - if (!empty($modSettings['attachment_thumb_png'])) |
|
| 148 | - $success = resizeImageFile($source, $destName, $max_width, $max_height, 3); |
|
| 149 | - else |
|
| 150 | - $success = resizeImageFile($source, $destName, $max_width, $max_height); |
|
| 149 | + if (!empty($modSettings['attachment_thumb_png'])) { |
|
| 150 | + $success = resizeImageFile($source, $destName, $max_width, $max_height, 3); |
|
| 151 | + } else { |
|
| 152 | + $success = resizeImageFile($source, $destName, $max_width, $max_height); |
|
| 153 | + } |
|
| 151 | 154 | |
| 152 | 155 | // Okay, we're done with the temporary stuff. |
| 153 | 156 | $destName = substr($destName, 0, -4); |
| 154 | 157 | |
| 155 | - if ($success && @rename($destName . '.tmp', $destName)) |
|
| 156 | - return true; |
|
| 157 | - else |
|
| 158 | + if ($success && @rename($destName . '.tmp', $destName)) { |
|
| 159 | + return true; |
|
| 160 | + } else |
|
| 158 | 161 | { |
| 159 | 162 | @unlink($destName . '.tmp'); |
| 160 | 163 | @touch($destName); |
@@ -176,18 +179,21 @@ discard block |
||
| 176 | 179 | { |
| 177 | 180 | if (!resizeImageFile($fileName, $fileName . '.tmp', null, null, $preferred_format)) |
| 178 | 181 | { |
| 179 | - if (file_exists($fileName . '.tmp')) |
|
| 180 | - unlink($fileName . '.tmp'); |
|
| 182 | + if (file_exists($fileName . '.tmp')) { |
|
| 183 | + unlink($fileName . '.tmp'); |
|
| 184 | + } |
|
| 181 | 185 | |
| 182 | 186 | return false; |
| 183 | 187 | } |
| 184 | 188 | |
| 185 | - if (!unlink($fileName)) |
|
| 186 | - return false; |
|
| 189 | + if (!unlink($fileName)) { |
|
| 190 | + return false; |
|
| 191 | + } |
|
| 187 | 192 | |
| 188 | - if (!rename($fileName . '.tmp', $fileName)) |
|
| 189 | - return false; |
|
| 190 | -} |
|
| 193 | + if (!rename($fileName . '.tmp', $fileName)) { |
|
| 194 | + return false; |
|
| 195 | + } |
|
| 196 | + } |
|
| 191 | 197 | |
| 192 | 198 | /** |
| 193 | 199 | * Searches through the file to see if there's potentially harmful non-binary content. |
@@ -200,8 +206,9 @@ discard block |
||
| 200 | 206 | function checkImageContents($fileName, $extensiveCheck = false) |
| 201 | 207 | { |
| 202 | 208 | $fp = fopen($fileName, 'rb'); |
| 203 | - if (!$fp) |
|
| 204 | - fatal_lang_error('attach_timeout'); |
|
| 209 | + if (!$fp) { |
|
| 210 | + fatal_lang_error('attach_timeout'); |
|
| 211 | + } |
|
| 205 | 212 | |
| 206 | 213 | $prev_chunk = ''; |
| 207 | 214 | while (!feof($fp)) |
@@ -218,8 +225,7 @@ discard block |
||
| 218 | 225 | fclose($fp); |
| 219 | 226 | return false; |
| 220 | 227 | } |
| 221 | - } |
|
| 222 | - else |
|
| 228 | + } else |
|
| 223 | 229 | { |
| 224 | 230 | // Check for potential infection - focus on clues for inline php & flash. |
| 225 | 231 | // Will result in significantly fewer false positives than the paranoid check. |
@@ -247,8 +253,9 @@ discard block |
||
| 247 | 253 | global $gd2; |
| 248 | 254 | |
| 249 | 255 | // Check to see if GD is installed and what version. |
| 250 | - if (($extensionFunctions = get_extension_funcs('gd')) === false) |
|
| 251 | - return false; |
|
| 256 | + if (($extensionFunctions = get_extension_funcs('gd')) === false) { |
|
| 257 | + return false; |
|
| 258 | + } |
|
| 252 | 259 | |
| 253 | 260 | // Also determine if GD2 is installed and store it in a global. |
| 254 | 261 | $gd2 = in_array('imagecreatetruecolor', $extensionFunctions) && function_exists('imagecreatetruecolor'); |
@@ -320,8 +327,9 @@ discard block |
||
| 320 | 327 | global $sourcedir; |
| 321 | 328 | |
| 322 | 329 | // Nothing to do without GD or IM/MW |
| 323 | - if (!checkGD() && !checkImagick() && !checkMagickWand()) |
|
| 324 | - return false; |
|
| 330 | + if (!checkGD() && !checkImagick() && !checkMagickWand()) { |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 325 | 333 | |
| 326 | 334 | static $default_formats = array( |
| 327 | 335 | '1' => 'gif', |
@@ -343,38 +351,39 @@ discard block |
||
| 343 | 351 | fclose($fp_destination); |
| 344 | 352 | |
| 345 | 353 | $sizes = @getimagesize($destination); |
| 346 | - } |
|
| 347 | - elseif ($fp_destination) |
|
| 354 | + } elseif ($fp_destination) |
|
| 348 | 355 | { |
| 349 | 356 | $sizes = @getimagesize($source); |
| 350 | 357 | |
| 351 | 358 | $fp_source = fopen($source, 'rb'); |
| 352 | 359 | if ($fp_source !== false) |
| 353 | 360 | { |
| 354 | - while (!feof($fp_source)) |
|
| 355 | - fwrite($fp_destination, fread($fp_source, 8192)); |
|
| 361 | + while (!feof($fp_source)) { |
|
| 362 | + fwrite($fp_destination, fread($fp_source, 8192)); |
|
| 363 | + } |
|
| 356 | 364 | fclose($fp_source); |
| 365 | + } else { |
|
| 366 | + $sizes = array(-1, -1, -1); |
|
| 357 | 367 | } |
| 358 | - else |
|
| 359 | - $sizes = array(-1, -1, -1); |
|
| 360 | 368 | fclose($fp_destination); |
| 361 | 369 | } |
| 362 | 370 | // We can't get to the file. |
| 363 | - else |
|
| 364 | - $sizes = array(-1, -1, -1); |
|
| 371 | + else { |
|
| 372 | + $sizes = array(-1, -1, -1); |
|
| 373 | + } |
|
| 365 | 374 | |
| 366 | 375 | // See if we have -or- can get the needed memory for this operation |
| 367 | 376 | // ImageMagick isn't subject to PHP's memory limits :) |
| 368 | - if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes)) |
|
| 369 | - return false; |
|
| 377 | + if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes)) { |
|
| 378 | + return false; |
|
| 379 | + } |
|
| 370 | 380 | |
| 371 | 381 | // A known and supported format? |
| 372 | 382 | // @todo test PSD and gif. |
| 373 | 383 | if ((checkImagick() || checkMagickWand()) && isset($default_formats[$sizes[2]])) |
| 374 | 384 | { |
| 375 | 385 | return resizeImage(null, $destination, null, null, $max_width, $max_height, true, $preferred_format); |
| 376 | - } |
|
| 377 | - elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]])) |
|
| 386 | + } elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]])) |
|
| 378 | 387 | { |
| 379 | 388 | $imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]]; |
| 380 | 389 | if ($src_img = @$imagecreatefrom($destination)) |
@@ -427,14 +436,14 @@ discard block |
||
| 427 | 436 | $dest_width = empty($max_width) ? $src_width : $max_width; |
| 428 | 437 | $dest_height = empty($max_height) ? $src_height : $max_height; |
| 429 | 438 | |
| 430 | - if ($default_formats[$preferred_format] == 'jpeg') |
|
| 431 | - $imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 439 | + if ($default_formats[$preferred_format] == 'jpeg') { |
|
| 440 | + $imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 441 | + } |
|
| 432 | 442 | |
| 433 | 443 | $imagick->setImageFormat($default_formats[$preferred_format]); |
| 434 | 444 | $imagick->resizeImage($dest_width, $dest_height, Imagick::FILTER_LANCZOS, 1, true); |
| 435 | 445 | $success = $imagick->writeImage($destName); |
| 436 | - } |
|
| 437 | - else |
|
| 446 | + } else |
|
| 438 | 447 | { |
| 439 | 448 | $magick_wand = newMagickWand(); |
| 440 | 449 | MagickReadImage($magick_wand, $destName); |
@@ -443,8 +452,9 @@ discard block |
||
| 443 | 452 | $dest_width = empty($max_width) ? $src_width : $max_width; |
| 444 | 453 | $dest_height = empty($max_height) ? $src_height : $max_height; |
| 445 | 454 | |
| 446 | - if ($default_formats[$preferred_format] == 'jpeg') |
|
| 447 | - MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 455 | + if ($default_formats[$preferred_format] == 'jpeg') { |
|
| 456 | + MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 457 | + } |
|
| 448 | 458 | |
| 449 | 459 | MagickSetImageFormat($magick_wand, $default_formats[$preferred_format]); |
| 450 | 460 | MagickResizeImage($magick_wand, $dest_width, $dest_height, MW_LanczosFilter, 1, true); |
@@ -452,8 +462,7 @@ discard block |
||
| 452 | 462 | } |
| 453 | 463 | |
| 454 | 464 | return !empty($success); |
| 455 | - } |
|
| 456 | - elseif (checkGD()) |
|
| 465 | + } elseif (checkGD()) |
|
| 457 | 466 | { |
| 458 | 467 | $success = false; |
| 459 | 468 | |
@@ -464,8 +473,7 @@ discard block |
||
| 464 | 473 | { |
| 465 | 474 | $dst_width = $max_width; |
| 466 | 475 | $dst_height = round($src_height * $max_width / $src_width); |
| 467 | - } |
|
| 468 | - elseif (!empty($max_height)) |
|
| 476 | + } elseif (!empty($max_height)) |
|
| 469 | 477 | { |
| 470 | 478 | $dst_width = round($src_width * $max_height / $src_height); |
| 471 | 479 | $dst_height = $max_height; |
@@ -483,44 +491,48 @@ discard block |
||
| 483 | 491 | if ((!empty($preferred_format)) && ($preferred_format == 3)) |
| 484 | 492 | { |
| 485 | 493 | imagealphablending($dst_img, false); |
| 486 | - if (function_exists('imagesavealpha')) |
|
| 487 | - imagesavealpha($dst_img, true); |
|
| 494 | + if (function_exists('imagesavealpha')) { |
|
| 495 | + imagesavealpha($dst_img, true); |
|
| 496 | + } |
|
| 488 | 497 | } |
| 498 | + } else { |
|
| 499 | + $dst_img = imagecreate($dst_width, $dst_height); |
|
| 489 | 500 | } |
| 490 | - else |
|
| 491 | - $dst_img = imagecreate($dst_width, $dst_height); |
|
| 492 | 501 | |
| 493 | 502 | // Resize it! |
| 494 | - if ($gd2) |
|
| 495 | - imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
| 496 | - else |
|
| 497 | - imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
| 503 | + if ($gd2) { |
|
| 504 | + imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
| 505 | + } else { |
|
| 506 | + imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
| 507 | + } |
|
| 508 | + } else { |
|
| 509 | + $dst_img = $src_img; |
|
| 498 | 510 | } |
| 499 | - else |
|
| 500 | - $dst_img = $src_img; |
|
| 511 | + } else { |
|
| 512 | + $dst_img = $src_img; |
|
| 501 | 513 | } |
| 502 | - else |
|
| 503 | - $dst_img = $src_img; |
|
| 504 | 514 | |
| 505 | 515 | // Save the image as ... |
| 506 | - if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng')) |
|
| 507 | - $success = imagepng($dst_img, $destName); |
|
| 508 | - elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif')) |
|
| 509 | - $success = imagegif($dst_img, $destName); |
|
| 510 | - elseif (function_exists('imagejpeg')) |
|
| 511 | - $success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 516 | + if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng')) { |
|
| 517 | + $success = imagepng($dst_img, $destName); |
|
| 518 | + } elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif')) { |
|
| 519 | + $success = imagegif($dst_img, $destName); |
|
| 520 | + } elseif (function_exists('imagejpeg')) { |
|
| 521 | + $success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 522 | + } |
|
| 512 | 523 | |
| 513 | 524 | // Free the memory. |
| 514 | 525 | imagedestroy($src_img); |
| 515 | - if ($dst_img != $src_img) |
|
| 516 | - imagedestroy($dst_img); |
|
| 526 | + if ($dst_img != $src_img) { |
|
| 527 | + imagedestroy($dst_img); |
|
| 528 | + } |
|
| 517 | 529 | |
| 518 | 530 | return $success; |
| 519 | - } |
|
| 520 | - else |
|
| 521 | - // Without GD, no image resizing at all. |
|
| 531 | + } else { |
|
| 532 | + // Without GD, no image resizing at all. |
|
| 522 | 533 | return false; |
| 523 | -} |
|
| 534 | + } |
|
| 535 | + } |
|
| 524 | 536 | |
| 525 | 537 | /** |
| 526 | 538 | * Copy image. |
@@ -574,8 +586,9 @@ discard block |
||
| 574 | 586 | $color = imagecolorresolve($dst_img, $red, $green, $blue); |
| 575 | 587 | if ($color == -1) |
| 576 | 588 | { |
| 577 | - if ($palsize++ < 256) |
|
| 578 | - imagecolorallocate($dst_img, $red, $green, $blue); |
|
| 589 | + if ($palsize++ < 256) { |
|
| 590 | + imagecolorallocate($dst_img, $red, $green, $blue); |
|
| 591 | + } |
|
| 579 | 592 | $color = imagecolorclosest($dst_img, $red, $green, $blue); |
| 580 | 593 | } |
| 581 | 594 | |
@@ -605,13 +618,15 @@ discard block |
||
| 605 | 618 | $header = unpack('vtype/Vsize/Vreserved/Voffset', fread($fp, 14)); |
| 606 | 619 | $info = unpack('Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vcolorimportant', fread($fp, 40)); |
| 607 | 620 | |
| 608 | - if ($header['type'] != 0x4D42) |
|
| 609 | - return false; |
|
| 621 | + if ($header['type'] != 0x4D42) { |
|
| 622 | + return false; |
|
| 623 | + } |
|
| 610 | 624 | |
| 611 | - if ($gd2) |
|
| 612 | - $dst_img = imagecreatetruecolor($info['width'], $info['height']); |
|
| 613 | - else |
|
| 614 | - $dst_img = imagecreate($info['width'], $info['height']); |
|
| 625 | + if ($gd2) { |
|
| 626 | + $dst_img = imagecreatetruecolor($info['width'], $info['height']); |
|
| 627 | + } else { |
|
| 628 | + $dst_img = imagecreate($info['width'], $info['height']); |
|
| 629 | + } |
|
| 615 | 630 | |
| 616 | 631 | $palette_size = $header['offset'] - 54; |
| 617 | 632 | $info['ncolor'] = $palette_size / 4; |
@@ -637,8 +652,9 @@ discard block |
||
| 637 | 652 | fseek($fp, $header['offset'] + ($scan_line_size + $scan_line_align) * $l); |
| 638 | 653 | $scan_line = fread($fp, $scan_line_size); |
| 639 | 654 | |
| 640 | - if (strlen($scan_line) < $scan_line_size) |
|
| 641 | - continue; |
|
| 655 | + if (strlen($scan_line) < $scan_line_size) { |
|
| 656 | + continue; |
|
| 657 | + } |
|
| 642 | 658 | |
| 643 | 659 | if ($info['bits'] == 32) |
| 644 | 660 | { |
@@ -656,14 +672,14 @@ discard block |
||
| 656 | 672 | $color = imagecolorallocate($dst_img, $r, $g, $b); |
| 657 | 673 | |
| 658 | 674 | // Gah! Out of colors? Stupid GD 1... try anyhow. |
| 659 | - if ($color == -1) |
|
| 660 | - $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 675 | + if ($color == -1) { |
|
| 676 | + $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 677 | + } |
|
| 661 | 678 | } |
| 662 | 679 | |
| 663 | 680 | imagesetpixel($dst_img, $x, $y, $color); |
| 664 | 681 | } |
| 665 | - } |
|
| 666 | - elseif ($info['bits'] == 24) |
|
| 682 | + } elseif ($info['bits'] == 24) |
|
| 667 | 683 | { |
| 668 | 684 | $x = 0; |
| 669 | 685 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -678,14 +694,14 @@ discard block |
||
| 678 | 694 | $color = imagecolorallocate($dst_img, $r, $g, $b); |
| 679 | 695 | |
| 680 | 696 | // Gah! Out of colors? Stupid GD 1... try anyhow. |
| 681 | - if ($color == -1) |
|
| 682 | - $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 697 | + if ($color == -1) { |
|
| 698 | + $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 699 | + } |
|
| 683 | 700 | } |
| 684 | 701 | |
| 685 | 702 | imagesetpixel($dst_img, $x, $y, $color); |
| 686 | 703 | } |
| 687 | - } |
|
| 688 | - elseif ($info['bits'] == 16) |
|
| 704 | + } elseif ($info['bits'] == 16) |
|
| 689 | 705 | { |
| 690 | 706 | $x = 0; |
| 691 | 707 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -706,20 +722,20 @@ discard block |
||
| 706 | 722 | $color = imagecolorallocate($dst_img, $r, $g, $b); |
| 707 | 723 | |
| 708 | 724 | // Gah! Out of colors? Stupid GD 1... try anyhow. |
| 709 | - if ($color == -1) |
|
| 710 | - $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 725 | + if ($color == -1) { |
|
| 726 | + $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 727 | + } |
|
| 711 | 728 | } |
| 712 | 729 | |
| 713 | 730 | imagesetpixel($dst_img, $x, $y, $color); |
| 714 | 731 | } |
| 715 | - } |
|
| 716 | - elseif ($info['bits'] == 8) |
|
| 732 | + } elseif ($info['bits'] == 8) |
|
| 717 | 733 | { |
| 718 | 734 | $x = 0; |
| 719 | - for ($j = 0; $j < $scan_line_size; $x++) |
|
| 720 | - imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]); |
|
| 721 | - } |
|
| 722 | - elseif ($info['bits'] == 4) |
|
| 735 | + for ($j = 0; $j < $scan_line_size; $x++) { |
|
| 736 | + imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]); |
|
| 737 | + } |
|
| 738 | + } elseif ($info['bits'] == 4) |
|
| 723 | 739 | { |
| 724 | 740 | $x = 0; |
| 725 | 741 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -727,11 +743,11 @@ discard block |
||
| 727 | 743 | $byte = ord($scan_line{$j++}); |
| 728 | 744 | |
| 729 | 745 | imagesetpixel($dst_img, $x, $y, $palette[(int) ($byte / 16)]); |
| 730 | - if (++$x < $info['width']) |
|
| 731 | - imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]); |
|
| 746 | + if (++$x < $info['width']) { |
|
| 747 | + imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]); |
|
| 748 | + } |
|
| 732 | 749 | } |
| 733 | - } |
|
| 734 | - elseif ($info['bits'] == 1) |
|
| 750 | + } elseif ($info['bits'] == 1) |
|
| 735 | 751 | { |
| 736 | 752 | $x = 0; |
| 737 | 753 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -740,7 +756,9 @@ discard block |
||
| 740 | 756 | |
| 741 | 757 | imagesetpixel($dst_img, $x, $y, $palette[(($byte) & 128) != 0]); |
| 742 | 758 | for ($shift = 1; $shift < 8; $shift++) { |
| 743 | - if (++$x < $info['width']) imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]); |
|
| 759 | + if (++$x < $info['width']) { |
|
| 760 | + imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]); |
|
| 761 | + } |
|
| 744 | 762 | } |
| 745 | 763 | } |
| 746 | 764 | } |
@@ -764,15 +782,18 @@ discard block |
||
| 764 | 782 | */ |
| 765 | 783 | function gif_outputAsPng($gif, $lpszFileName, $background_color = -1) |
| 766 | 784 | { |
| 767 | - if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '') |
|
| 768 | - return false; |
|
| 785 | + if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '') { |
|
| 786 | + return false; |
|
| 787 | + } |
|
| 769 | 788 | |
| 770 | 789 | $fd = $gif->get_png_data($background_color); |
| 771 | - if (strlen($fd) <= 0) |
|
| 772 | - return false; |
|
| 790 | + if (strlen($fd) <= 0) { |
|
| 791 | + return false; |
|
| 792 | + } |
|
| 773 | 793 | |
| 774 | - if (!($fh = @fopen($lpszFileName, 'wb'))) |
|
| 775 | - return false; |
|
| 794 | + if (!($fh = @fopen($lpszFileName, 'wb'))) { |
|
| 795 | + return false; |
|
| 796 | + } |
|
| 776 | 797 | |
| 777 | 798 | @fwrite($fh, $fd, strlen($fd)); |
| 778 | 799 | @fflush($fh); |
@@ -799,8 +820,9 @@ discard block |
||
| 799 | 820 | // What type are we going to be doing? |
| 800 | 821 | $imageType = $modSettings['visual_verification_type']; |
| 801 | 822 | // Special case to allow the admin center to show samples. |
| 802 | - if ($user_info['is_admin'] && isset($_GET['type'])) |
|
| 803 | - $imageType = (int) $_GET['type']; |
|
| 823 | + if ($user_info['is_admin'] && isset($_GET['type'])) { |
|
| 824 | + $imageType = (int) $_GET['type']; |
|
| 825 | + } |
|
| 804 | 826 | |
| 805 | 827 | // Some quick references for what we do. |
| 806 | 828 | // Do we show no, low or high noise? |
@@ -834,25 +856,28 @@ discard block |
||
| 834 | 856 | $character_spacing = 1; |
| 835 | 857 | |
| 836 | 858 | // What color is the background - generally white unless we're on "hard". |
| 837 | - if ($simpleBGColor) |
|
| 838 | - $background_color = array(255, 255, 255); |
|
| 839 | - else |
|
| 840 | - $background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243); |
|
| 859 | + if ($simpleBGColor) { |
|
| 860 | + $background_color = array(255, 255, 255); |
|
| 861 | + } else { |
|
| 862 | + $background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243); |
|
| 863 | + } |
|
| 841 | 864 | |
| 842 | 865 | // The color of the characters shown (red, green, blue). |
| 843 | - if ($simpleFGColor) |
|
| 844 | - $foreground_color = array(0, 0, 0); |
|
| 845 | - else |
|
| 866 | + if ($simpleFGColor) { |
|
| 867 | + $foreground_color = array(0, 0, 0); |
|
| 868 | + } else |
|
| 846 | 869 | { |
| 847 | 870 | $foreground_color = array(64, 101, 136); |
| 848 | 871 | |
| 849 | 872 | // Has the theme author requested a custom color? |
| 850 | - if (isset($settings['verification_foreground'])) |
|
| 851 | - $foreground_color = $settings['verification_foreground']; |
|
| 873 | + if (isset($settings['verification_foreground'])) { |
|
| 874 | + $foreground_color = $settings['verification_foreground']; |
|
| 875 | + } |
|
| 852 | 876 | } |
| 853 | 877 | |
| 854 | - if (!is_dir($settings['default_theme_dir'] . '/fonts')) |
|
| 855 | - return false; |
|
| 878 | + if (!is_dir($settings['default_theme_dir'] . '/fonts')) { |
|
| 879 | + return false; |
|
| 880 | + } |
|
| 856 | 881 | |
| 857 | 882 | // Get a list of the available fonts. |
| 858 | 883 | $font_dir = dir($settings['default_theme_dir'] . '/fonts'); |
@@ -863,25 +888,28 @@ discard block |
||
| 863 | 888 | { |
| 864 | 889 | if (preg_match('~^(.+)\.gdf$~', $entry, $matches) === 1) |
| 865 | 890 | { |
| 866 | - if ($endian ^ (strpos($entry, '_end.gdf') === false)) |
|
| 867 | - $font_list[] = $entry; |
|
| 891 | + if ($endian ^ (strpos($entry, '_end.gdf') === false)) { |
|
| 892 | + $font_list[] = $entry; |
|
| 893 | + } |
|
| 894 | + } elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1) { |
|
| 895 | + $ttfont_list[] = $entry; |
|
| 868 | 896 | } |
| 869 | - elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1) |
|
| 870 | - $ttfont_list[] = $entry; |
|
| 871 | 897 | } |
| 872 | 898 | |
| 873 | - if (empty($font_list)) |
|
| 874 | - return false; |
|
| 899 | + if (empty($font_list)) { |
|
| 900 | + return false; |
|
| 901 | + } |
|
| 875 | 902 | |
| 876 | 903 | // For non-hard things don't even change fonts. |
| 877 | 904 | if (!$varyFonts) |
| 878 | 905 | { |
| 879 | 906 | $font_list = array($font_list[0]); |
| 880 | 907 | // Try use Screenge if we can - it looks good! |
| 881 | - if (in_array('AnonymousPro.ttf', $ttfont_list)) |
|
| 882 | - $ttfont_list = array('AnonymousPro.ttf'); |
|
| 883 | - else |
|
| 884 | - $ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]); |
|
| 908 | + if (in_array('AnonymousPro.ttf', $ttfont_list)) { |
|
| 909 | + $ttfont_list = array('AnonymousPro.ttf'); |
|
| 910 | + } else { |
|
| 911 | + $ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]); |
|
| 912 | + } |
|
| 885 | 913 | |
| 886 | 914 | } |
| 887 | 915 | |
@@ -899,14 +927,16 @@ discard block |
||
| 899 | 927 | } |
| 900 | 928 | |
| 901 | 929 | // Load all fonts and determine the maximum font height. |
| 902 | - foreach ($loaded_fonts as $font_index => $dummy) |
|
| 903 | - $loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]); |
|
| 930 | + foreach ($loaded_fonts as $font_index => $dummy) { |
|
| 931 | + $loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]); |
|
| 932 | + } |
|
| 904 | 933 | |
| 905 | 934 | // Determine the dimensions of each character. |
| 906 | - if ($imageType == 4 || $imageType == 5) |
|
| 907 | - $extra = 80; |
|
| 908 | - else |
|
| 909 | - $extra = 45; |
|
| 935 | + if ($imageType == 4 || $imageType == 5) { |
|
| 936 | + $extra = 80; |
|
| 937 | + } else { |
|
| 938 | + $extra = 45; |
|
| 939 | + } |
|
| 910 | 940 | |
| 911 | 941 | $total_width = $character_spacing * strlen($code) + $extra; |
| 912 | 942 | $max_height = 0; |
@@ -927,13 +957,15 @@ discard block |
||
| 927 | 957 | imagefilledrectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $bg_color); |
| 928 | 958 | |
| 929 | 959 | // Randomize the foreground color a little. |
| 930 | - for ($i = 0; $i < 3; $i++) |
|
| 931 | - $foreground_color[$i] = mt_rand(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255)); |
|
| 960 | + for ($i = 0; $i < 3; $i++) { |
|
| 961 | + $foreground_color[$i] = mt_rand(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255)); |
|
| 962 | + } |
|
| 932 | 963 | $fg_color = imagecolorallocate($code_image, $foreground_color[0], $foreground_color[1], $foreground_color[2]); |
| 933 | 964 | |
| 934 | 965 | // Color for the dots. |
| 935 | - for ($i = 0; $i < 3; $i++) |
|
| 936 | - $dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? mt_rand(0, max($foreground_color[$i] - 20, 0)) : mt_rand(min($foreground_color[$i] + 20, 255), 255); |
|
| 966 | + for ($i = 0; $i < 3; $i++) { |
|
| 967 | + $dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? mt_rand(0, max($foreground_color[$i] - 20, 0)) : mt_rand(min($foreground_color[$i] + 20, 255), 255); |
|
| 968 | + } |
|
| 937 | 969 | $randomness_color = imagecolorallocate($code_image, $dotbgcolor[0], $dotbgcolor[1], $dotbgcolor[2]); |
| 938 | 970 | |
| 939 | 971 | // Some squares/rectanges for new extreme level |
@@ -959,10 +991,11 @@ discard block |
||
| 959 | 991 | $can_do_ttf = function_exists('imagettftext'); |
| 960 | 992 | |
| 961 | 993 | // How much rotation will we give? |
| 962 | - if ($rotationType == 'none') |
|
| 963 | - $angle = 0; |
|
| 964 | - else |
|
| 965 | - $angle = mt_rand(-100, 100) / ($rotationType == 'high' ? 6 : 10); |
|
| 994 | + if ($rotationType == 'none') { |
|
| 995 | + $angle = 0; |
|
| 996 | + } else { |
|
| 997 | + $angle = mt_rand(-100, 100) / ($rotationType == 'high' ? 6 : 10); |
|
| 998 | + } |
|
| 966 | 999 | |
| 967 | 1000 | // What color shall we do it? |
| 968 | 1001 | if ($fontColorType == 'cyclic') |
@@ -976,51 +1009,56 @@ discard block |
||
| 976 | 1009 | array(0, 0, 0), |
| 977 | 1010 | array(143, 39, 31), |
| 978 | 1011 | ); |
| 979 | - if (!isset($last_index)) |
|
| 980 | - $last_index = -1; |
|
| 1012 | + if (!isset($last_index)) { |
|
| 1013 | + $last_index = -1; |
|
| 1014 | + } |
|
| 981 | 1015 | $new_index = $last_index; |
| 982 | - while ($last_index == $new_index) |
|
| 983 | - $new_index = mt_rand(0, count($colors) - 1); |
|
| 1016 | + while ($last_index == $new_index) { |
|
| 1017 | + $new_index = mt_rand(0, count($colors) - 1); |
|
| 1018 | + } |
|
| 984 | 1019 | $char_fg_color = $colors[$new_index]; |
| 985 | 1020 | $last_index = $new_index; |
| 1021 | + } elseif ($fontColorType == 'random') { |
|
| 1022 | + $char_fg_color = array(mt_rand(max($foreground_color[0] - 2, 0), $foreground_color[0]), mt_rand(max($foreground_color[1] - 2, 0), $foreground_color[1]), mt_rand(max($foreground_color[2] - 2, 0), $foreground_color[2])); |
|
| 1023 | + } else { |
|
| 1024 | + $char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]); |
|
| 986 | 1025 | } |
| 987 | - elseif ($fontColorType == 'random') |
|
| 988 | - $char_fg_color = array(mt_rand(max($foreground_color[0] - 2, 0), $foreground_color[0]), mt_rand(max($foreground_color[1] - 2, 0), $foreground_color[1]), mt_rand(max($foreground_color[2] - 2, 0), $foreground_color[2])); |
|
| 989 | - else |
|
| 990 | - $char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]); |
|
| 991 | 1026 | |
| 992 | 1027 | if (!empty($can_do_ttf)) |
| 993 | 1028 | { |
| 994 | 1029 | // GD2 handles font size differently. |
| 995 | - if ($fontSizeRandom) |
|
| 996 | - $font_size = $gd2 ? mt_rand(17, 19) : mt_rand(18, 25); |
|
| 997 | - else |
|
| 998 | - $font_size = $gd2 ? 18 : 24; |
|
| 1030 | + if ($fontSizeRandom) { |
|
| 1031 | + $font_size = $gd2 ? mt_rand(17, 19) : mt_rand(18, 25); |
|
| 1032 | + } else { |
|
| 1033 | + $font_size = $gd2 ? 18 : 24; |
|
| 1034 | + } |
|
| 999 | 1035 | |
| 1000 | 1036 | // Work out the sizes - also fix the character width cause TTF not quite so wide! |
| 1001 | 1037 | $font_x = $fontHorSpace == 'minus' && $cur_x > 0 ? $cur_x - 3 : $cur_x + 5; |
| 1002 | 1038 | $font_y = $max_height - ($fontVerPos == 'vrandom' ? mt_rand(2, 8) : ($fontVerPos == 'random' ? mt_rand(3, 5) : 5)); |
| 1003 | 1039 | |
| 1004 | 1040 | // What font face? |
| 1005 | - if (!empty($ttfont_list)) |
|
| 1006 | - $fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[mt_rand(0, count($ttfont_list) - 1)]; |
|
| 1041 | + if (!empty($ttfont_list)) { |
|
| 1042 | + $fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[mt_rand(0, count($ttfont_list) - 1)]; |
|
| 1043 | + } |
|
| 1007 | 1044 | |
| 1008 | 1045 | // What color are we to do it in? |
| 1009 | 1046 | $is_reverse = $showReverseChars ? mt_rand(0, 1) : false; |
| 1010 | 1047 | $char_color = function_exists('imagecolorallocatealpha') && $fontTrans ? imagecolorallocatealpha($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2], 50) : imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]); |
| 1011 | 1048 | |
| 1012 | 1049 | $fontcord = @imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $char_color, $fontface, $character['id']); |
| 1013 | - if (empty($fontcord)) |
|
| 1014 | - $can_do_ttf = false; |
|
| 1015 | - elseif ($is_reverse) |
|
| 1050 | + if (empty($fontcord)) { |
|
| 1051 | + $can_do_ttf = false; |
|
| 1052 | + } elseif ($is_reverse) |
|
| 1016 | 1053 | { |
| 1017 | 1054 | imagefilledpolygon($code_image, $fontcord, 4, $fg_color); |
| 1018 | 1055 | // Put the character back! |
| 1019 | 1056 | imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $randomness_color, $fontface, $character['id']); |
| 1020 | 1057 | } |
| 1021 | 1058 | |
| 1022 | - if ($can_do_ttf) |
|
| 1023 | - $cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3); |
|
| 1059 | + if ($can_do_ttf) { |
|
| 1060 | + $cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3); |
|
| 1061 | + } |
|
| 1024 | 1062 | } |
| 1025 | 1063 | |
| 1026 | 1064 | if (!$can_do_ttf) |
@@ -1039,8 +1077,9 @@ discard block |
||
| 1039 | 1077 | } |
| 1040 | 1078 | |
| 1041 | 1079 | // Sorry, no rotation available. |
| 1042 | - else |
|
| 1043 | - imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2])); |
|
| 1080 | + else { |
|
| 1081 | + imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2])); |
|
| 1082 | + } |
|
| 1044 | 1083 | $cur_x += $character['width'] + $character_spacing; |
| 1045 | 1084 | } |
| 1046 | 1085 | } |
@@ -1053,17 +1092,22 @@ discard block |
||
| 1053 | 1092 | } |
| 1054 | 1093 | |
| 1055 | 1094 | // Make the background color transparent on the hard image. |
| 1056 | - if (!$simpleBGColor) |
|
| 1057 | - imagecolortransparent($code_image, $bg_color); |
|
| 1058 | - if ($hasBorder) |
|
| 1059 | - imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color); |
|
| 1095 | + if (!$simpleBGColor) { |
|
| 1096 | + imagecolortransparent($code_image, $bg_color); |
|
| 1097 | + } |
|
| 1098 | + if ($hasBorder) { |
|
| 1099 | + imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color); |
|
| 1100 | + } |
|
| 1060 | 1101 | |
| 1061 | 1102 | // Add some noise to the background? |
| 1062 | 1103 | if ($noiseType != 'none') |
| 1063 | 1104 | { |
| 1064 | - for ($i = mt_rand(0, 2); $i < $max_height; $i += mt_rand(1, 2)) |
|
| 1065 | - for ($j = mt_rand(0, 10); $j < $total_width; $j += mt_rand(1, 10)) |
|
| 1066 | - imagesetpixel($code_image, $j, $i, mt_rand(0, 1) ? $fg_color : $randomness_color); |
|
| 1105 | + for ($i = mt_rand(0, 2); $i < $max_height; $i += mt_rand(1, 2)) { |
|
| 1106 | + for ($j = mt_rand(0, 10); |
|
| 1107 | + } |
|
| 1108 | + $j < $total_width; $j += mt_rand(1, 10)) { |
|
| 1109 | + imagesetpixel($code_image, $j, $i, mt_rand(0, 1) ? $fg_color : $randomness_color); |
|
| 1110 | + } |
|
| 1067 | 1111 | |
| 1068 | 1112 | // Put in some lines too? |
| 1069 | 1113 | if ($noiseType != 'extreme') |
@@ -1076,8 +1120,7 @@ discard block |
||
| 1076 | 1120 | $x1 = mt_rand(0, $total_width); |
| 1077 | 1121 | $x2 = mt_rand(0, $total_width); |
| 1078 | 1122 | $y1 = 0; $y2 = $max_height; |
| 1079 | - } |
|
| 1080 | - else |
|
| 1123 | + } else |
|
| 1081 | 1124 | { |
| 1082 | 1125 | $y1 = mt_rand(0, $max_height); |
| 1083 | 1126 | $y2 = mt_rand(0, $max_height); |
@@ -1086,8 +1129,7 @@ discard block |
||
| 1086 | 1129 | imagesetthickness($code_image, mt_rand(1, 2)); |
| 1087 | 1130 | imageline($code_image, $x1, $y1, $x2, $y2, mt_rand(0, 1) ? $fg_color : $randomness_color); |
| 1088 | 1131 | } |
| 1089 | - } |
|
| 1090 | - else |
|
| 1132 | + } else |
|
| 1091 | 1133 | { |
| 1092 | 1134 | // Put in some ellipse |
| 1093 | 1135 | $num_ellipse = $noiseType == 'extreme' ? mt_rand(6, 12) : mt_rand(2, 6); |
@@ -1107,8 +1149,7 @@ discard block |
||
| 1107 | 1149 | { |
| 1108 | 1150 | header('Content-type: image/gif'); |
| 1109 | 1151 | imagegif($code_image); |
| 1110 | - } |
|
| 1111 | - else |
|
| 1152 | + } else |
|
| 1112 | 1153 | { |
| 1113 | 1154 | header('Content-type: image/png'); |
| 1114 | 1155 | imagepng($code_image); |
@@ -1131,25 +1172,29 @@ discard block |
||
| 1131 | 1172 | { |
| 1132 | 1173 | global $settings; |
| 1133 | 1174 | |
| 1134 | - if (!is_dir($settings['default_theme_dir'] . '/fonts')) |
|
| 1135 | - return false; |
|
| 1175 | + if (!is_dir($settings['default_theme_dir'] . '/fonts')) { |
|
| 1176 | + return false; |
|
| 1177 | + } |
|
| 1136 | 1178 | |
| 1137 | 1179 | // Get a list of the available font directories. |
| 1138 | 1180 | $font_dir = dir($settings['default_theme_dir'] . '/fonts'); |
| 1139 | 1181 | $font_list = array(); |
| 1140 | - while ($entry = $font_dir->read()) |
|
| 1141 | - if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf')) |
|
| 1182 | + while ($entry = $font_dir->read()) { |
|
| 1183 | + if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf')) |
|
| 1142 | 1184 | $font_list[] = $entry; |
| 1185 | + } |
|
| 1143 | 1186 | |
| 1144 | - if (empty($font_list)) |
|
| 1145 | - return false; |
|
| 1187 | + if (empty($font_list)) { |
|
| 1188 | + return false; |
|
| 1189 | + } |
|
| 1146 | 1190 | |
| 1147 | 1191 | // Pick a random font. |
| 1148 | 1192 | $random_font = $font_list[array_rand($font_list)]; |
| 1149 | 1193 | |
| 1150 | 1194 | // Check if the given letter exists. |
| 1151 | - if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png')) |
|
| 1152 | - return false; |
|
| 1195 | + if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png')) { |
|
| 1196 | + return false; |
|
| 1197 | + } |
|
| 1153 | 1198 | |
| 1154 | 1199 | // Include it! |
| 1155 | 1200 | header('Content-type: image/png'); |
@@ -73,8 +73,9 @@ discard block |
||
| 73 | 73 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 74 | 74 | { |
| 75 | 75 | $groups = array_merge(array($row['id_group'], $row['id_post_group']), (empty($row['additional_groups']) ? array() : explode(',', $row['additional_groups']))); |
| 76 | - if (!in_array(1, $groups) && count(array_intersect($groups, explode(',', $row['member_groups']))) == 0) |
|
| 77 | - continue; |
|
| 76 | + if (!in_array(1, $groups) && count(array_intersect($groups, explode(',', $row['member_groups']))) == 0) { |
|
| 77 | + continue; |
|
| 78 | + } |
|
| 78 | 79 | |
| 79 | 80 | $members[] = $row['id_member']; |
| 80 | 81 | $watched[$row['id_member']] = $row; |
@@ -82,8 +83,9 @@ discard block |
||
| 82 | 83 | |
| 83 | 84 | $smcFunc['db_free_result']($request); |
| 84 | 85 | |
| 85 | - if (empty($members)) |
|
| 86 | - return true; |
|
| 86 | + if (empty($members)) { |
|
| 87 | + return true; |
|
| 88 | + } |
|
| 87 | 89 | |
| 88 | 90 | $members = array_unique($members); |
| 89 | 91 | $prefs = getNotifyPrefs($members, '', true); |
@@ -105,20 +107,23 @@ discard block |
||
| 105 | 107 | $notify_types = !empty($prefs[$member]['msg_notify_type']) ? $prefs[$member]['msg_notify_type'] : 1; |
| 106 | 108 | |
| 107 | 109 | // Don't send a notification if the watching member ignored the member who made the action. |
| 108 | - if (!empty($data['pm_ignore_list']) && in_array($data['id_member_updated'], explode(',', $data['pm_ignore_list']))) |
|
| 109 | - continue; |
|
| 110 | - if (!in_array($type, array('reply', 'topic')) && $notify_types == 2 && $member != $data['id_member_started']) |
|
| 111 | - continue; |
|
| 112 | - elseif (in_array($type, array('reply', 'topic')) && $member == $posterOptions['id']) |
|
| 113 | - continue; |
|
| 114 | - elseif (!in_array($type, array('reply', 'topic')) && $notify_types == 3) |
|
| 115 | - continue; |
|
| 116 | - elseif ($notify_types == 4) |
|
| 117 | - continue; |
|
| 110 | + if (!empty($data['pm_ignore_list']) && in_array($data['id_member_updated'], explode(',', $data['pm_ignore_list']))) { |
|
| 111 | + continue; |
|
| 112 | + } |
|
| 113 | + if (!in_array($type, array('reply', 'topic')) && $notify_types == 2 && $member != $data['id_member_started']) { |
|
| 114 | + continue; |
|
| 115 | + } elseif (in_array($type, array('reply', 'topic')) && $member == $posterOptions['id']) { |
|
| 116 | + continue; |
|
| 117 | + } elseif (!in_array($type, array('reply', 'topic')) && $notify_types == 3) { |
|
| 118 | + continue; |
|
| 119 | + } elseif ($notify_types == 4) { |
|
| 120 | + continue; |
|
| 121 | + } |
|
| 118 | 122 | |
| 119 | 123 | if ($frequency > 2 || (!empty($frequency) && $data['sent']) || in_array($member, $done_members) |
| 120 | - || (!empty($this->_details['members_only']) && !in_array($member, $this->_details['members_only']))) |
|
| 121 | - continue; |
|
| 124 | + || (!empty($this->_details['members_only']) && !in_array($member, $this->_details['members_only']))) { |
|
| 125 | + continue; |
|
| 126 | + } |
|
| 122 | 127 | |
| 123 | 128 | // Watched topic? |
| 124 | 129 | if (!empty($data['id_topic']) && $type != 'topic' && !empty($prefs[$member])) |
@@ -128,10 +133,12 @@ discard block |
||
| 128 | 133 | |
| 129 | 134 | if ($type == 'reply') |
| 130 | 135 | { |
| 131 | - if (!empty($prefs[$member]['msg_receive_body'])) |
|
| 132 | - $message_type .= '_body'; |
|
| 133 | - if (!empty($frequency)) |
|
| 134 | - $message_type .= '_once'; |
|
| 136 | + if (!empty($prefs[$member]['msg_receive_body'])) { |
|
| 137 | + $message_type .= '_body'; |
|
| 138 | + } |
|
| 139 | + if (!empty($frequency)) { |
|
| 140 | + $message_type .= '_once'; |
|
| 141 | + } |
|
| 135 | 142 | } |
| 136 | 143 | |
| 137 | 144 | $content_type = 'topic'; |
@@ -144,12 +151,14 @@ discard block |
||
| 144 | 151 | $content_type = 'board'; |
| 145 | 152 | |
| 146 | 153 | $message_type = !empty($frequency) ? 'notify_boards_once' : 'notify_boards'; |
| 147 | - if (!empty($prefs[$member]['msg_receive_body'])) |
|
| 148 | - $message_type .= '_body'; |
|
| 154 | + if (!empty($prefs[$member]['msg_receive_body'])) { |
|
| 155 | + $message_type .= '_body'; |
|
| 156 | + } |
|
| 149 | 157 | } |
| 150 | 158 | // If neither of the above, this might be a redundent row due to the OR clause in our SQL query, skip |
| 151 | - else |
|
| 152 | - continue; |
|
| 159 | + else { |
|
| 160 | + continue; |
|
| 161 | + } |
|
| 153 | 162 | |
| 154 | 163 | if ($pref & 0x02) |
| 155 | 164 | { |
@@ -212,14 +221,15 @@ discard block |
||
| 212 | 221 | ); |
| 213 | 222 | |
| 214 | 223 | // Insert the alerts if any |
| 215 | - if (!empty($alert_rows)) |
|
| 216 | - $smcFunc['db_insert']('', |
|
| 224 | + if (!empty($alert_rows)) { |
|
| 225 | + $smcFunc['db_insert']('', |
|
| 217 | 226 | '{db_prefix}user_alerts', |
| 218 | 227 | array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string', |
| 219 | 228 | 'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'), |
| 220 | 229 | $alert_rows, |
| 221 | 230 | array() |
| 222 | 231 | ); |
| 232 | + } |
|
| 223 | 233 | |
| 224 | 234 | return true; |
| 225 | 235 | } |
@@ -230,8 +240,9 @@ discard block |
||
| 230 | 240 | |
| 231 | 241 | foreach ($quotedMembers as $id => $member) |
| 232 | 242 | { |
| 233 | - if (!isset($prefs[$id]) || $id == $posterOptions['id'] || empty($prefs[$id]['msg_quote'])) |
|
| 234 | - continue; |
|
| 243 | + if (!isset($prefs[$id]) || $id == $posterOptions['id'] || empty($prefs[$id]['msg_quote'])) { |
|
| 244 | + continue; |
|
| 245 | + } |
|
| 235 | 246 | |
| 236 | 247 | $done_members[] = $id; |
| 237 | 248 | |
@@ -283,32 +294,35 @@ discard block |
||
| 283 | 294 | { |
| 284 | 295 | if (preg_match('/\[quote(.*)?\]/i', $block, $matches)) |
| 285 | 296 | { |
| 286 | - if ($quote_level == 0) |
|
| 287 | - $message .= '[quote' . $matches[1] . ']'; |
|
| 297 | + if ($quote_level == 0) { |
|
| 298 | + $message .= '[quote' . $matches[1] . ']'; |
|
| 299 | + } |
|
| 288 | 300 | $quote_level++; |
| 289 | - } |
|
| 290 | - elseif (preg_match('/\[\/quote\]/i', $block)) |
|
| 301 | + } elseif (preg_match('/\[\/quote\]/i', $block)) |
|
| 291 | 302 | { |
| 292 | - if ($quote_level <= 1) |
|
| 293 | - $message .= '[/quote]'; |
|
| 303 | + if ($quote_level <= 1) { |
|
| 304 | + $message .= '[/quote]'; |
|
| 305 | + } |
|
| 294 | 306 | if ($quote_level >= 1) |
| 295 | 307 | { |
| 296 | 308 | $quote_level--; |
| 297 | 309 | $message .= "\n"; |
| 298 | 310 | } |
| 311 | + } elseif ($quote_level <= 1) { |
|
| 312 | + $message .= $block; |
|
| 299 | 313 | } |
| 300 | - elseif ($quote_level <= 1) |
|
| 301 | - $message .= $block; |
|
| 302 | 314 | } |
| 303 | 315 | |
| 304 | 316 | preg_match_all('/\[quote.*?link=msg=([0-9]+).*?\]/i', $message, $matches); |
| 305 | 317 | |
| 306 | 318 | $id_msgs = $matches[1]; |
| 307 | - foreach ($id_msgs as $k => $id_msg) |
|
| 308 | - $id_msgs[$k] = (int) $id_msg; |
|
| 319 | + foreach ($id_msgs as $k => $id_msg) { |
|
| 320 | + $id_msgs[$k] = (int) $id_msg; |
|
| 321 | + } |
|
| 309 | 322 | |
| 310 | - if (empty($id_msgs)) |
|
| 311 | - return array(); |
|
| 323 | + if (empty($id_msgs)) { |
|
| 324 | + return array(); |
|
| 325 | + } |
|
| 312 | 326 | |
| 313 | 327 | // Get the messages |
| 314 | 328 | $request = $smcFunc['db_query']('', ' |
@@ -326,8 +340,9 @@ discard block |
||
| 326 | 340 | $members = array(); |
| 327 | 341 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 328 | 342 | { |
| 329 | - if ($posterOptions['id'] == $row['id_member']) |
|
| 330 | - continue; |
|
| 343 | + if ($posterOptions['id'] == $row['id_member']) { |
|
| 344 | + continue; |
|
| 345 | + } |
|
| 331 | 346 | |
| 332 | 347 | $members[$row['id_member']] = $row; |
| 333 | 348 | } |
@@ -341,10 +356,11 @@ discard block |
||
| 341 | 356 | |
| 342 | 357 | foreach ($members as $id => $member) |
| 343 | 358 | { |
| 344 | - if (!empty($prefs[$id]['msg_mention'])) |
|
| 345 | - $done_members[] = $id; |
|
| 346 | - else |
|
| 347 | - continue; |
|
| 359 | + if (!empty($prefs[$id]['msg_mention'])) { |
|
| 360 | + $done_members[] = $id; |
|
| 361 | + } else { |
|
| 362 | + continue; |
|
| 363 | + } |
|
| 348 | 364 | |
| 349 | 365 | // Alerts' emails are always instant |
| 350 | 366 | if ($prefs[$id]['msg_mention'] & 0x02) |
@@ -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 | * Fetches a list of boards and (optional) categories including |
@@ -37,11 +38,12 @@ discard block |
||
| 37 | 38 | require_once($sourcedir . '/Subs-Boards.php'); |
| 38 | 39 | |
| 39 | 40 | // For performance, track the latest post while going through the boards. |
| 40 | - if (!empty($boardIndexOptions['set_latest_post'])) |
|
| 41 | - $latest_post = array( |
|
| 41 | + if (!empty($boardIndexOptions['set_latest_post'])) { |
|
| 42 | + $latest_post = array( |
|
| 42 | 43 | 'timestamp' => 0, |
| 43 | 44 | 'ref' => 0, |
| 44 | 45 | ); |
| 46 | + } |
|
| 45 | 47 | |
| 46 | 48 | // Find all boards and categories, as well as related information. This will be sorted by the natural order of boards and categories, which we control. |
| 47 | 49 | $result_boards = $smcFunc['db_query']('', ' |
@@ -74,10 +76,11 @@ discard block |
||
| 74 | 76 | ); |
| 75 | 77 | |
| 76 | 78 | // Start with an empty array. |
| 77 | - if ($boardIndexOptions['include_categories']) |
|
| 78 | - $categories = array(); |
|
| 79 | - else |
|
| 80 | - $this_category = array(); |
|
| 79 | + if ($boardIndexOptions['include_categories']) { |
|
| 80 | + $categories = array(); |
|
| 81 | + } else { |
|
| 82 | + $this_category = array(); |
|
| 83 | + } |
|
| 81 | 84 | $boards = array(); |
| 82 | 85 | |
| 83 | 86 | // Run through the categories and boards (or only boards).... |
@@ -88,8 +91,9 @@ discard block |
||
| 88 | 91 | $row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0'; |
| 89 | 92 | |
| 90 | 93 | // Add parent boards to the $boards list later used to fetch moderators |
| 91 | - if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) |
|
| 92 | - $boards[] = $row_board['id_board']; |
|
| 94 | + if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) { |
|
| 95 | + $boards[] = $row_board['id_board']; |
|
| 96 | + } |
|
| 93 | 97 | |
| 94 | 98 | if ($boardIndexOptions['include_categories']) |
| 95 | 99 | { |
@@ -111,8 +115,9 @@ discard block |
||
| 111 | 115 | } |
| 112 | 116 | |
| 113 | 117 | // If this board has new posts in it (and isn't the recycle bin!) then the category is new. |
| 114 | - if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) |
|
| 115 | - $categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']) && $row_board['poster_name'] != ''; |
|
| 118 | + if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) { |
|
| 119 | + $categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']) && $row_board['poster_name'] != ''; |
|
| 120 | + } |
|
| 116 | 121 | |
| 117 | 122 | // Avoid showing category unread link where it only has redirection boards. |
| 118 | 123 | $categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect']; |
@@ -160,14 +165,12 @@ discard block |
||
| 160 | 165 | { |
| 161 | 166 | $this_category[$row_board['id_board']]['board_class'] = 'redirect'; |
| 162 | 167 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['redirect_board']; |
| 163 | - } |
|
| 164 | - elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest']) |
|
| 168 | + } elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest']) |
|
| 165 | 169 | { |
| 166 | 170 | // If we're showing to guests, we want to give them the idea that something interesting is going on! |
| 167 | 171 | $this_category[$row_board['id_board']]['board_class'] = 'on'; |
| 168 | 172 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['new_posts']; |
| 169 | - } |
|
| 170 | - else |
|
| 173 | + } else |
|
| 171 | 174 | { |
| 172 | 175 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['old_posts']; |
| 173 | 176 | } |
@@ -218,14 +221,16 @@ discard block |
||
| 218 | 221 | // Child of a child... just add it on... |
| 219 | 222 | elseif (!empty($boardIndexOptions['countChildPosts'])) |
| 220 | 223 | { |
| 221 | - if (!isset($parent_map)) |
|
| 222 | - $parent_map = array(); |
|
| 224 | + if (!isset($parent_map)) { |
|
| 225 | + $parent_map = array(); |
|
| 226 | + } |
|
| 223 | 227 | |
| 224 | - if (!isset($parent_map[$row_board['id_parent']])) |
|
| 225 | - foreach ($this_category as $id => $board) |
|
| 228 | + if (!isset($parent_map[$row_board['id_parent']])) { |
|
| 229 | + foreach ($this_category as $id => $board) |
|
| 226 | 230 | { |
| 227 | 231 | if (!isset($board['children'][$row_board['id_parent']])) |
| 228 | 232 | continue; |
| 233 | + } |
|
| 229 | 234 | |
| 230 | 235 | $parent_map[$row_board['id_parent']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]); |
| 231 | 236 | $parent_map[$row_board['id_board']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]); |
@@ -246,8 +251,9 @@ discard block |
||
| 246 | 251 | continue; |
| 247 | 252 | } |
| 248 | 253 | // Found a child of a child - skip. |
| 249 | - else |
|
| 250 | - continue; |
|
| 254 | + else { |
|
| 255 | + continue; |
|
| 256 | + } |
|
| 251 | 257 | |
| 252 | 258 | // Prepare the subject, and make sure it's not too long. |
| 253 | 259 | censorText($row_board['subject']); |
@@ -268,12 +274,13 @@ discard block |
||
| 268 | 274 | 'topic' => $row_board['id_topic'] |
| 269 | 275 | ); |
| 270 | 276 | |
| 271 | - if (!empty($settings['avatars_on_boardIndex'])) |
|
| 272 | - $this_last_post['member']['avatar'] = set_avatar_data(array( |
|
| 277 | + if (!empty($settings['avatars_on_boardIndex'])) { |
|
| 278 | + $this_last_post['member']['avatar'] = set_avatar_data(array( |
|
| 273 | 279 | 'avatar' => $row_board['avatar'], |
| 274 | 280 | 'email' => $row_board['email_address'], |
| 275 | 281 | 'filename' => !empty($row['member_filename']) ? $row_board['member_filename'] : '', |
| 276 | 282 | )); |
| 283 | + } |
|
| 277 | 284 | |
| 278 | 285 | // Provide the href and link. |
| 279 | 286 | if ($row_board['subject'] != '') |
@@ -285,8 +292,7 @@ discard block |
||
| 285 | 292 | link, href, subject, start (where they should go for the first unread post.), |
| 286 | 293 | and member. (which has id, name, link, href, username in it.) */ |
| 287 | 294 | $this_last_post['last_post_message'] = sprintf($txt['last_post_message'], $this_last_post['member']['link'], $this_last_post['link'], $this_last_post['time']); |
| 288 | - } |
|
| 289 | - else |
|
| 295 | + } else |
|
| 290 | 296 | { |
| 291 | 297 | $this_last_post['href'] = ''; |
| 292 | 298 | $this_last_post['link'] = $txt['not_applicable']; |
@@ -294,8 +300,9 @@ discard block |
||
| 294 | 300 | } |
| 295 | 301 | |
| 296 | 302 | // Set the last post in the parent board. |
| 297 | - if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && $this_category[$row_board['id_parent']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time']))) |
|
| 298 | - $this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post; |
|
| 303 | + if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && $this_category[$row_board['id_parent']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time']))) { |
|
| 304 | + $this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post; |
|
| 305 | + } |
|
| 299 | 306 | // Just in the child...? |
| 300 | 307 | if ($isChild) |
| 301 | 308 | { |
@@ -305,15 +312,17 @@ discard block |
||
| 305 | 312 | $this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['new'] &= $row_board['poster_name'] != ''; |
| 306 | 313 | } |
| 307 | 314 | // No last post for this board? It's not new then, is it..? |
| 308 | - elseif ($row_board['poster_name'] == '') |
|
| 309 | - $this_category[$row_board['id_board']]['new'] = false; |
|
| 315 | + elseif ($row_board['poster_name'] == '') { |
|
| 316 | + $this_category[$row_board['id_board']]['new'] = false; |
|
| 317 | + } |
|
| 310 | 318 | |
| 311 | 319 | // Determine a global most recent topic. |
| 312 | - if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) |
|
| 313 | - $latest_post = array( |
|
| 320 | + if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) { |
|
| 321 | + $latest_post = array( |
|
| 314 | 322 | 'timestamp' => $row_board['poster_time'], |
| 315 | 323 | 'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'], |
| 316 | 324 | ); |
| 325 | + } |
|
| 317 | 326 | } |
| 318 | 327 | $smcFunc['db_free_result']($result_boards); |
| 319 | 328 | |
@@ -330,8 +339,9 @@ discard block |
||
| 330 | 339 | if (!empty($moderators[$board['id']])) |
| 331 | 340 | { |
| 332 | 341 | $categories[$k]['boards'][$j]['moderators'] = $moderators[$board['id']]; |
| 333 | - foreach ($moderators[$board['id']] as $moderator) |
|
| 334 | - $categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link']; |
|
| 342 | + foreach ($moderators[$board['id']] as $moderator) { |
|
| 343 | + $categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link']; |
|
| 344 | + } |
|
| 335 | 345 | } |
| 336 | 346 | if (!empty($groups[$board['id']])) |
| 337 | 347 | { |
@@ -344,16 +354,16 @@ discard block |
||
| 344 | 354 | } |
| 345 | 355 | } |
| 346 | 356 | } |
| 347 | - } |
|
| 348 | - else |
|
| 357 | + } else |
|
| 349 | 358 | { |
| 350 | 359 | foreach ($this_category as $k => $board) |
| 351 | 360 | { |
| 352 | 361 | if (!empty($moderators[$board['id']])) |
| 353 | 362 | { |
| 354 | 363 | $this_category[$k]['moderators'] = $moderators[$board['id']]; |
| 355 | - foreach ($moderators[$board['id']] as $moderator) |
|
| 356 | - $this_category[$k]['link_moderators'][] = $moderator['link']; |
|
| 364 | + foreach ($moderators[$board['id']] as $moderator) { |
|
| 365 | + $this_category[$k]['link_moderators'][] = $moderator['link']; |
|
| 366 | + } |
|
| 357 | 367 | } |
| 358 | 368 | if (!empty($groups[$board['id']])) |
| 359 | 369 | { |
@@ -367,20 +377,23 @@ discard block |
||
| 367 | 377 | } |
| 368 | 378 | } |
| 369 | 379 | |
| 370 | - if ($boardIndexOptions['include_categories']) |
|
| 371 | - sortCategories($categories); |
|
| 372 | - else |
|
| 373 | - sortBoards($this_category); |
|
| 380 | + if ($boardIndexOptions['include_categories']) { |
|
| 381 | + sortCategories($categories); |
|
| 382 | + } else { |
|
| 383 | + sortBoards($this_category); |
|
| 384 | + } |
|
| 374 | 385 | |
| 375 | 386 | // By now we should know the most recent post...if we wanna know it that is. |
| 376 | - if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) |
|
| 377 | - $context['latest_post'] = $latest_post['ref']; |
|
| 387 | + if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) { |
|
| 388 | + $context['latest_post'] = $latest_post['ref']; |
|
| 389 | + } |
|
| 378 | 390 | |
| 379 | 391 | // I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea. |
| 380 | - if ($boardIndexOptions['include_categories']) |
|
| 381 | - call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories)); |
|
| 382 | - else |
|
| 383 | - call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category)); |
|
| 392 | + if ($boardIndexOptions['include_categories']) { |
|
| 393 | + call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories)); |
|
| 394 | + } else { |
|
| 395 | + call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category)); |
|
| 396 | + } |
|
| 384 | 397 | |
| 385 | 398 | return $boardIndexOptions['include_categories'] ? $categories : $this_category; |
| 386 | 399 | } |
@@ -51,30 +51,33 @@ discard block |
||
| 51 | 51 | $ignored_members = explode(',', $row['pm_ignore_list']); |
| 52 | 52 | |
| 53 | 53 | // If the user is in group 1 anywhere, they can see everything anyway. |
| 54 | - if (in_array(1, $groups) || count(array_intersect($allowed, $groups)) != 0) |
|
| 55 | - $author = $row['id_member']; |
|
| 54 | + if (in_array(1, $groups) || count(array_intersect($allowed, $groups)) != 0) { |
|
| 55 | + $author = $row['id_member']; |
|
| 56 | + } |
|
| 56 | 57 | } |
| 57 | 58 | $smcFunc['db_free_result']($request); |
| 58 | - } |
|
| 59 | - else |
|
| 59 | + } else |
|
| 60 | 60 | { |
| 61 | 61 | // This isn't something we know natively how to support. Call the hooks, if they're dealing with it, return false, otherwise return the user id. |
| 62 | 62 | $hook_results = call_integration_hook('integrate_find_like_author', array($this->_details['content_type'], $this->_details['content_id'])); |
| 63 | - foreach ($hook_results as $result) |
|
| 64 | - if (!empty($result)) |
|
| 63 | + foreach ($hook_results as $result) { |
|
| 64 | + if (!empty($result)) |
|
| 65 | 65 | { |
| 66 | 66 | $author = $result; |
| 67 | + } |
|
| 67 | 68 | break; |
| 68 | 69 | } |
| 69 | 70 | } |
| 70 | 71 | |
| 71 | 72 | // If we didn't have a member... leave. |
| 72 | - if (empty($author)) |
|
| 73 | - return true; |
|
| 73 | + if (empty($author)) { |
|
| 74 | + return true; |
|
| 75 | + } |
|
| 74 | 76 | |
| 75 | 77 | // If the person who sent the notification is the person whose content it is, do nothing. |
| 76 | - if ($author == $this->_details['sender_id']) |
|
| 77 | - return true; |
|
| 78 | + if ($author == $this->_details['sender_id']) { |
|
| 79 | + return true; |
|
| 80 | + } |
|
| 78 | 81 | |
| 79 | 82 | // If the person who sent the notification is on this person's ignore list, do nothing. |
| 80 | 83 | if (!empty($ignored_members) && in_array($this->_details['sender_id'], $ignored_members)) { |
@@ -88,8 +91,9 @@ discard block |
||
| 88 | 91 | // As a result, the value should really just be non empty. |
| 89 | 92 | |
| 90 | 93 | // Check the value. If no value or it's empty, they didn't want alerts, oh well. |
| 91 | - if (empty($prefs[$author][$this->_details['content_type'] . '_like'])) |
|
| 92 | - return true; |
|
| 94 | + if (empty($prefs[$author][$this->_details['content_type'] . '_like'])) { |
|
| 95 | + return true; |
|
| 96 | + } |
|
| 93 | 97 | |
| 94 | 98 | // Don't spam the alerts: if there is an existing unread alert of the |
| 95 | 99 | // requested type for the target user from the sender, don't make a new one. |
@@ -109,8 +113,9 @@ discard block |
||
| 109 | 113 | ) |
| 110 | 114 | ); |
| 111 | 115 | |
| 112 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
| 113 | - return true; |
|
| 116 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
| 117 | + return true; |
|
| 118 | + } |
|
| 114 | 119 | $smcFunc['db_free_result']($request); |
| 115 | 120 | |
| 116 | 121 | // Issue, update, move on. |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 3 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('No direct access...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Class fulltext_search |
@@ -98,8 +99,9 @@ discard block |
||
| 98 | 99 | $smcFunc['db_free_result']($request); |
| 99 | 100 | } |
| 100 | 101 | // 4 is the MySQL default... |
| 101 | - else |
|
| 102 | - $min_word_length = 4; |
|
| 102 | + else { |
|
| 103 | + $min_word_length = 4; |
|
| 104 | + } |
|
| 103 | 105 | |
| 104 | 106 | return $min_word_length; |
| 105 | 107 | } |
@@ -138,8 +140,7 @@ discard block |
||
| 138 | 140 | $wordsSearch['words'][] = trim($word, "/*- "); |
| 139 | 141 | $wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"'; |
| 140 | 142 | } |
| 141 | - } |
|
| 142 | - elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
| 143 | + } elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
| 143 | 144 | { |
| 144 | 145 | // short words have feelings too |
| 145 | 146 | $wordsSearch['words'][] = trim($word, "/*- "); |
@@ -149,8 +150,9 @@ discard block |
||
| 149 | 150 | |
| 150 | 151 | $fulltextWord = count($subwords) === 1 ? $word : '"' . $word . '"'; |
| 151 | 152 | $wordsSearch['indexed_words'][] = $fulltextWord; |
| 152 | - if ($isExcluded) |
|
| 153 | - $wordsExclude[] = $fulltextWord; |
|
| 153 | + if ($isExcluded) { |
|
| 154 | + $wordsExclude[] = $fulltextWord; |
|
| 155 | + } |
|
| 154 | 156 | } |
| 155 | 157 | |
| 156 | 158 | /** |
@@ -166,41 +168,50 @@ discard block |
||
| 166 | 168 | $query_where = array(); |
| 167 | 169 | $query_params = $search_data['params']; |
| 168 | 170 | |
| 169 | - if ($query_params['id_search']) |
|
| 170 | - $query_select['id_search'] = '{int:id_search}'; |
|
| 171 | + if ($query_params['id_search']) { |
|
| 172 | + $query_select['id_search'] = '{int:id_search}'; |
|
| 173 | + } |
|
| 171 | 174 | |
| 172 | 175 | $count = 0; |
| 173 | - if (empty($modSettings['search_simple_fulltext'])) |
|
| 174 | - foreach ($words['words'] as $regularWord) |
|
| 176 | + if (empty($modSettings['search_simple_fulltext'])) { |
|
| 177 | + foreach ($words['words'] as $regularWord) |
|
| 175 | 178 | { |
| 176 | 179 | $query_where[] = 'm.body' . (in_array($regularWord, $query_params['excluded_words']) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:complex_body_' . $count . '}'; |
| 180 | + } |
|
| 177 | 181 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
| 178 | 182 | } |
| 179 | 183 | |
| 180 | - if ($query_params['user_query']) |
|
| 181 | - $query_where[] = '{raw:user_query}'; |
|
| 182 | - if ($query_params['board_query']) |
|
| 183 | - $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 184 | + if ($query_params['user_query']) { |
|
| 185 | + $query_where[] = '{raw:user_query}'; |
|
| 186 | + } |
|
| 187 | + if ($query_params['board_query']) { |
|
| 188 | + $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 189 | + } |
|
| 184 | 190 | |
| 185 | - if ($query_params['topic']) |
|
| 186 | - $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 187 | - if ($query_params['min_msg_id']) |
|
| 188 | - $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 189 | - if ($query_params['max_msg_id']) |
|
| 190 | - $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 191 | + if ($query_params['topic']) { |
|
| 192 | + $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 193 | + } |
|
| 194 | + if ($query_params['min_msg_id']) { |
|
| 195 | + $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 196 | + } |
|
| 197 | + if ($query_params['max_msg_id']) { |
|
| 198 | + $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 199 | + } |
|
| 191 | 200 | |
| 192 | 201 | $count = 0; |
| 193 | - if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
|
| 194 | - foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 202 | + if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) { |
|
| 203 | + foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 195 | 204 | { |
| 196 | 205 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_phrase_' . $count . '}'; |
| 206 | + } |
|
| 197 | 207 | $query_params['exclude_subject_phrase_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($phrase, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $phrase), '\\\'') . '[[:>:]]'; |
| 198 | 208 | } |
| 199 | 209 | $count = 0; |
| 200 | - if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
|
| 201 | - foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 210 | + if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) { |
|
| 211 | + foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 202 | 212 | { |
| 203 | 213 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_words_' . $count . '}'; |
| 214 | + } |
|
| 204 | 215 | $query_params['exclude_subject_words_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($excludedWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $excludedWord), '\\\'') . '[[:>:]]'; |
| 205 | 216 | } |
| 206 | 217 | |
@@ -212,12 +223,11 @@ discard block |
||
| 212 | 223 | |
| 213 | 224 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:body_match})'; |
| 214 | 225 | $query_params['language_ftx'] = $language_ftx; |
| 226 | + } else { |
|
| 227 | + $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
| 215 | 228 | } |
| 216 | - else |
|
| 217 | - $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
| 218 | 229 | $query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words'])); |
| 219 | - } |
|
| 220 | - else |
|
| 230 | + } else |
|
| 221 | 231 | { |
| 222 | 232 | $query_params['boolean_match'] = ''; |
| 223 | 233 | |
@@ -231,10 +241,10 @@ discard block |
||
| 231 | 241 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' '; |
| 232 | 242 | $row++; |
| 233 | 243 | } |
| 234 | - } |
|
| 235 | - else |
|
| 236 | - foreach ($words['indexed_words'] as $fulltextWord) |
|
| 244 | + } else { |
|
| 245 | + foreach ($words['indexed_words'] as $fulltextWord) |
|
| 237 | 246 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' '; |
| 247 | + } |
|
| 238 | 248 | |
| 239 | 249 | $query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1); |
| 240 | 250 | |
@@ -246,9 +256,9 @@ discard block |
||
| 246 | 256 | |
| 247 | 257 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:boolean_match})'; |
| 248 | 258 | $query_params['language_ftx'] = $language_ftx; |
| 259 | + } else { |
|
| 260 | + $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
| 249 | 261 | } |
| 250 | - else |
|
| 251 | - $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
| 252 | 262 | } |
| 253 | 263 | |
| 254 | 264 | } |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Add the file functions to the $smcFunc array. |
@@ -23,29 +24,33 @@ discard block |
||
| 23 | 24 | { |
| 24 | 25 | global $smcFunc; |
| 25 | 26 | |
| 26 | - if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_search_query') |
|
| 27 | - $smcFunc += array( |
|
| 27 | + if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_search_query') { |
|
| 28 | + $smcFunc += array( |
|
| 28 | 29 | 'db_search_query' => 'smf_db_search_query', |
| 29 | 30 | 'db_search_support' => 'smf_db_search_support', |
| 30 | 31 | 'db_create_word_search' => 'smf_db_create_word_search', |
| 31 | 32 | 'db_support_ignore' => false, |
| 32 | 33 | 'db_search_language' => 'smf_db_search_language', |
| 33 | 34 | ); |
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | db_extend(); |
| 36 | 38 | |
| 37 | 39 | //pg 9.5 got ignore support |
| 38 | 40 | $version = $smcFunc['db_get_version'](); |
| 39 | 41 | // if we got a Beta Version |
| 40 | - if (stripos($version, 'beta') !== false) |
|
| 41 | - $version = substr($version, 0, stripos($version, 'beta')).'.0'; |
|
| 42 | + if (stripos($version, 'beta') !== false) { |
|
| 43 | + $version = substr($version, 0, stripos($version, 'beta')).'.0'; |
|
| 44 | + } |
|
| 42 | 45 | // or RC |
| 43 | - if (stripos($version, 'rc') !== false) |
|
| 44 | - $version = substr($version, 0, stripos($version, 'rc')).'.0'; |
|
| 46 | + if (stripos($version, 'rc') !== false) { |
|
| 47 | + $version = substr($version, 0, stripos($version, 'rc')).'.0'; |
|
| 48 | + } |
|
| 45 | 49 | |
| 46 | - if (version_compare($version,'9.5.0','>=')) |
|
| 47 | - $smcFunc['db_support_ignore'] = true; |
|
| 48 | -} |
|
| 50 | + if (version_compare($version,'9.5.0','>=')) { |
|
| 51 | + $smcFunc['db_support_ignore'] = true; |
|
| 52 | + } |
|
| 53 | + } |
|
| 49 | 54 | |
| 50 | 55 | /** |
| 51 | 56 | * This function will tell you whether this database type supports this search type. |
@@ -104,16 +109,16 @@ discard block |
||
| 104 | 109 | ), |
| 105 | 110 | ); |
| 106 | 111 | |
| 107 | - if (isset($replacements[$identifier])) |
|
| 108 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 112 | + if (isset($replacements[$identifier])) { |
|
| 113 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 114 | + } |
|
| 109 | 115 | if (preg_match('~^\s*INSERT\sIGNORE~i', $db_string) != 0) |
| 110 | 116 | { |
| 111 | 117 | $db_string = preg_replace('~^\s*INSERT\sIGNORE~i', 'INSERT', $db_string); |
| 112 | 118 | if ($smcFunc['db_support_ignore']){ |
| 113 | 119 | //pg style "INSERT INTO.... ON CONFLICT DO NOTHING" |
| 114 | 120 | $db_string = $db_string.' ON CONFLICT DO NOTHING'; |
| 115 | - } |
|
| 116 | - else |
|
| 121 | + } else |
|
| 117 | 122 | { |
| 118 | 123 | // Don't error on multi-insert. |
| 119 | 124 | $db_values['db_error_skip'] = true; |
@@ -121,8 +126,9 @@ discard block |
||
| 121 | 126 | } |
| 122 | 127 | |
| 123 | 128 | //fix double quotes |
| 124 | - if ($identifier == 'insert_into_log_messages_fulltext') |
|
| 125 | - $db_values = str_replace('"', "'", $db_values); |
|
| 129 | + if ($identifier == 'insert_into_log_messages_fulltext') { |
|
| 130 | + $db_values = str_replace('"', "'", $db_values); |
|
| 131 | + } |
|
| 126 | 132 | |
| 127 | 133 | $return = $smcFunc['db_query']('', $db_string, |
| 128 | 134 | $db_values, $connection |
@@ -164,9 +170,9 @@ discard block |
||
| 164 | 170 | |
| 165 | 171 | $language_ftx = 'english'; |
| 166 | 172 | |
| 167 | - if (!empty($modSettings['search_language'])) |
|
| 168 | - $language_ftx = $modSettings['search_language']; |
|
| 169 | - else |
|
| 173 | + if (!empty($modSettings['search_language'])) { |
|
| 174 | + $language_ftx = $modSettings['search_language']; |
|
| 175 | + } else |
|
| 170 | 176 | { |
| 171 | 177 | $request = $smcFunc['db_query']('',' |
| 172 | 178 | SHOW default_text_search_config', |
@@ -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'])) |
|
| 37 | - $smcFunc += array( |
|
| 37 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
| 38 | + $smcFunc += array( |
|
| 38 | 39 | 'db_query' => 'smf_db_query', |
| 39 | 40 | 'db_quote' => 'smf_db_quote', |
| 40 | 41 | 'db_fetch_assoc' => 'mysqli_fetch_assoc', |
@@ -60,9 +61,11 @@ discard block |
||
| 60 | 61 | 'db_mb4' => false, |
| 61 | 62 | 'db_ping' => 'mysqli_ping', |
| 62 | 63 | ); |
| 64 | + } |
|
| 63 | 65 | |
| 64 | - if (!empty($db_options['persist'])) |
|
| 65 | - $db_server = 'p:' . $db_server; |
|
| 66 | + if (!empty($db_options['persist'])) { |
|
| 67 | + $db_server = 'p:' . $db_server; |
|
| 68 | + } |
|
| 66 | 69 | |
| 67 | 70 | $connection = mysqli_init(); |
| 68 | 71 | |
@@ -71,31 +74,35 @@ discard block |
||
| 71 | 74 | $success = false; |
| 72 | 75 | |
| 73 | 76 | if ($connection) { |
| 74 | - if (!empty($db_options['port'])) |
|
| 75 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags); |
|
| 76 | - else |
|
| 77 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags); |
|
| 77 | + if (!empty($db_options['port'])) { |
|
| 78 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags); |
|
| 79 | + } else { |
|
| 80 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags); |
|
| 81 | + } |
|
| 78 | 82 | } |
| 79 | 83 | |
| 80 | 84 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 81 | 85 | if ($success === false) |
| 82 | 86 | { |
| 83 | - if (!empty($db_options['non_fatal'])) |
|
| 84 | - return null; |
|
| 85 | - else |
|
| 86 | - display_db_error(); |
|
| 87 | + if (!empty($db_options['non_fatal'])) { |
|
| 88 | + return null; |
|
| 89 | + } else { |
|
| 90 | + display_db_error(); |
|
| 91 | + } |
|
| 87 | 92 | } |
| 88 | 93 | |
| 89 | 94 | // Select the database, unless told not to |
| 90 | - if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) |
|
| 91 | - display_db_error(); |
|
| 95 | + if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) { |
|
| 96 | + display_db_error(); |
|
| 97 | + } |
|
| 92 | 98 | |
| 93 | 99 | // This makes it possible to have SMF automatically change the sql_mode and autocommit if needed. |
| 94 | - if (isset($mysql_set_mode) && $mysql_set_mode === true) |
|
| 95 | - $smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1', |
|
| 100 | + if (isset($mysql_set_mode) && $mysql_set_mode === true) { |
|
| 101 | + $smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1', |
|
| 96 | 102 | array(), |
| 97 | 103 | false |
| 98 | 104 | ); |
| 105 | + } |
|
| 99 | 106 | |
| 100 | 107 | return $connection; |
| 101 | 108 | } |
@@ -166,37 +173,46 @@ discard block |
||
| 166 | 173 | global $db_callback, $user_info, $db_prefix, $smcFunc; |
| 167 | 174 | |
| 168 | 175 | list ($values, $connection) = $db_callback; |
| 169 | - if (!is_object($connection)) |
|
| 170 | - display_db_error(); |
|
| 176 | + if (!is_object($connection)) { |
|
| 177 | + display_db_error(); |
|
| 178 | + } |
|
| 171 | 179 | |
| 172 | - if ($matches[1] === 'db_prefix') |
|
| 173 | - return $db_prefix; |
|
| 180 | + if ($matches[1] === 'db_prefix') { |
|
| 181 | + return $db_prefix; |
|
| 182 | + } |
|
| 174 | 183 | |
| 175 | - if ($matches[1] === 'query_see_board') |
|
| 176 | - return $user_info['query_see_board']; |
|
| 184 | + if ($matches[1] === 'query_see_board') { |
|
| 185 | + return $user_info['query_see_board']; |
|
| 186 | + } |
|
| 177 | 187 | |
| 178 | - if ($matches[1] === 'query_wanna_see_board') |
|
| 179 | - return $user_info['query_wanna_see_board']; |
|
| 188 | + if ($matches[1] === 'query_wanna_see_board') { |
|
| 189 | + return $user_info['query_wanna_see_board']; |
|
| 190 | + } |
|
| 180 | 191 | |
| 181 | - if ($matches[1] === 'empty') |
|
| 182 | - return '\'\''; |
|
| 192 | + if ($matches[1] === 'empty') { |
|
| 193 | + return '\'\''; |
|
| 194 | + } |
|
| 183 | 195 | |
| 184 | - if (!isset($matches[2])) |
|
| 185 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 196 | + if (!isset($matches[2])) { |
|
| 197 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 198 | + } |
|
| 186 | 199 | |
| 187 | - if ($matches[1] === 'literal') |
|
| 188 | - return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
| 200 | + if ($matches[1] === 'literal') { |
|
| 201 | + return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
| 202 | + } |
|
| 189 | 203 | |
| 190 | - if (!isset($values[$matches[2]])) |
|
| 191 | - 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 | + if (!isset($values[$matches[2]])) { |
|
| 205 | + 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__); |
|
| 206 | + } |
|
| 192 | 207 | |
| 193 | 208 | $replacement = $values[$matches[2]]; |
| 194 | 209 | |
| 195 | 210 | switch ($matches[1]) |
| 196 | 211 | { |
| 197 | 212 | case 'int': |
| 198 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 199 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 213 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 214 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 215 | + } |
|
| 200 | 216 | return (string) (int) $replacement; |
| 201 | 217 | break; |
| 202 | 218 | |
@@ -208,65 +224,73 @@ discard block |
||
| 208 | 224 | case 'array_int': |
| 209 | 225 | if (is_array($replacement)) |
| 210 | 226 | { |
| 211 | - if (empty($replacement)) |
|
| 212 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 227 | + if (empty($replacement)) { |
|
| 228 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 229 | + } |
|
| 213 | 230 | |
| 214 | 231 | foreach ($replacement as $key => $value) |
| 215 | 232 | { |
| 216 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 217 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 233 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 234 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 235 | + } |
|
| 218 | 236 | |
| 219 | 237 | $replacement[$key] = (string) (int) $value; |
| 220 | 238 | } |
| 221 | 239 | |
| 222 | 240 | return implode(', ', $replacement); |
| 241 | + } else { |
|
| 242 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 223 | 243 | } |
| 224 | - else |
|
| 225 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 226 | 244 | |
| 227 | 245 | break; |
| 228 | 246 | |
| 229 | 247 | case 'array_string': |
| 230 | 248 | if (is_array($replacement)) |
| 231 | 249 | { |
| 232 | - if (empty($replacement)) |
|
| 233 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 250 | + if (empty($replacement)) { |
|
| 251 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 252 | + } |
|
| 234 | 253 | |
| 235 | - foreach ($replacement as $key => $value) |
|
| 236 | - $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
| 254 | + foreach ($replacement as $key => $value) { |
|
| 255 | + $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
| 256 | + } |
|
| 237 | 257 | |
| 238 | 258 | return implode(', ', $replacement); |
| 259 | + } else { |
|
| 260 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 239 | 261 | } |
| 240 | - else |
|
| 241 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 242 | 262 | break; |
| 243 | 263 | |
| 244 | 264 | case 'date': |
| 245 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
| 246 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 247 | - else |
|
| 248 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 265 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 266 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 267 | + } else { |
|
| 268 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 269 | + } |
|
| 249 | 270 | break; |
| 250 | 271 | |
| 251 | 272 | case 'time': |
| 252 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
| 253 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
| 254 | - else |
|
| 255 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 273 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
| 274 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
| 275 | + } else { |
|
| 276 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 277 | + } |
|
| 256 | 278 | break; |
| 257 | 279 | |
| 258 | 280 | case 'datetime': |
| 259 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
| 260 | - return 'str_to_date('. |
|
| 281 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
| 282 | + return 'str_to_date('. |
|
| 261 | 283 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
| 262 | 284 | ',\'%Y-%m-%d %h:%i:%s\')'; |
| 263 | - else |
|
| 264 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 285 | + } else { |
|
| 286 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 287 | + } |
|
| 265 | 288 | break; |
| 266 | 289 | |
| 267 | 290 | case 'float': |
| 268 | - if (!is_numeric($replacement)) |
|
| 269 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 291 | + if (!is_numeric($replacement)) { |
|
| 292 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 293 | + } |
|
| 270 | 294 | return (string) (float) $replacement; |
| 271 | 295 | break; |
| 272 | 296 | |
@@ -280,32 +304,37 @@ discard block |
||
| 280 | 304 | break; |
| 281 | 305 | |
| 282 | 306 | case 'inet': |
| 283 | - if ($replacement == 'null' || $replacement == '') |
|
| 284 | - return 'null'; |
|
| 285 | - if (!isValidIP($replacement)) |
|
| 286 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 307 | + if ($replacement == 'null' || $replacement == '') { |
|
| 308 | + return 'null'; |
|
| 309 | + } |
|
| 310 | + if (!isValidIP($replacement)) { |
|
| 311 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 312 | + } |
|
| 287 | 313 | //we don't use the native support of mysql > 5.6.2 |
| 288 | 314 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
| 289 | 315 | |
| 290 | 316 | case 'array_inet': |
| 291 | 317 | if (is_array($replacement)) |
| 292 | 318 | { |
| 293 | - if (empty($replacement)) |
|
| 294 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 319 | + if (empty($replacement)) { |
|
| 320 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 321 | + } |
|
| 295 | 322 | |
| 296 | 323 | foreach ($replacement as $key => $value) |
| 297 | 324 | { |
| 298 | - if ($replacement == 'null' || $replacement == '') |
|
| 299 | - $replacement[$key] = 'null'; |
|
| 300 | - if (!isValidIP($value)) |
|
| 301 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 325 | + if ($replacement == 'null' || $replacement == '') { |
|
| 326 | + $replacement[$key] = 'null'; |
|
| 327 | + } |
|
| 328 | + if (!isValidIP($value)) { |
|
| 329 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 330 | + } |
|
| 302 | 331 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
| 303 | 332 | } |
| 304 | 333 | |
| 305 | 334 | return implode(', ', $replacement); |
| 335 | + } else { |
|
| 336 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 306 | 337 | } |
| 307 | - else |
|
| 308 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 309 | 338 | break; |
| 310 | 339 | |
| 311 | 340 | default: |
@@ -381,22 +410,25 @@ discard block |
||
| 381 | 410 | // Are we in SSI mode? If so try that username and password first |
| 382 | 411 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
| 383 | 412 | { |
| 384 | - if (empty($db_persist)) |
|
| 385 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 386 | - else |
|
| 387 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 413 | + if (empty($db_persist)) { |
|
| 414 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 415 | + } else { |
|
| 416 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 417 | + } |
|
| 388 | 418 | } |
| 389 | 419 | // Fall back to the regular username and password if need be |
| 390 | 420 | if (!$db_connection) |
| 391 | 421 | { |
| 392 | - if (empty($db_persist)) |
|
| 393 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 394 | - else |
|
| 395 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 422 | + if (empty($db_persist)) { |
|
| 423 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 424 | + } else { |
|
| 425 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 426 | + } |
|
| 396 | 427 | } |
| 397 | 428 | |
| 398 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
| 399 | - $db_connection = false; |
|
| 429 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
| 430 | + $db_connection = false; |
|
| 431 | + } |
|
| 400 | 432 | |
| 401 | 433 | $connection = $db_connection; |
| 402 | 434 | } |
@@ -404,18 +436,20 @@ discard block |
||
| 404 | 436 | // One more query.... |
| 405 | 437 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 406 | 438 | |
| 407 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 408 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 439 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 440 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 441 | + } |
|
| 409 | 442 | |
| 410 | 443 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
| 411 | 444 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
| 412 | 445 | { |
| 413 | 446 | // Add before LIMIT |
| 414 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
| 415 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 416 | - else |
|
| 417 | - // Append it. |
|
| 447 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
| 448 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 449 | + } else { |
|
| 450 | + // Append it. |
|
| 418 | 451 | $db_string .= "\n\t\t\tORDER BY null"; |
| 452 | + } |
|
| 419 | 453 | } |
| 420 | 454 | |
| 421 | 455 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -437,8 +471,9 @@ discard block |
||
| 437 | 471 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 438 | 472 | |
| 439 | 473 | // Initialize $db_cache if not already initialized. |
| 440 | - if (!isset($db_cache)) |
|
| 441 | - $db_cache = array(); |
|
| 474 | + if (!isset($db_cache)) { |
|
| 475 | + $db_cache = array(); |
|
| 476 | + } |
|
| 442 | 477 | |
| 443 | 478 | if (!empty($_SESSION['debug_redirect'])) |
| 444 | 479 | { |
@@ -464,17 +499,18 @@ discard block |
||
| 464 | 499 | while (true) |
| 465 | 500 | { |
| 466 | 501 | $pos = strpos($db_string, '\'', $pos + 1); |
| 467 | - if ($pos === false) |
|
| 468 | - break; |
|
| 502 | + if ($pos === false) { |
|
| 503 | + break; |
|
| 504 | + } |
|
| 469 | 505 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
| 470 | 506 | |
| 471 | 507 | while (true) |
| 472 | 508 | { |
| 473 | 509 | $pos1 = strpos($db_string, '\'', $pos + 1); |
| 474 | 510 | $pos2 = strpos($db_string, '\\', $pos + 1); |
| 475 | - if ($pos1 === false) |
|
| 476 | - break; |
|
| 477 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
| 511 | + if ($pos1 === false) { |
|
| 512 | + break; |
|
| 513 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
| 478 | 514 | { |
| 479 | 515 | $pos = $pos1; |
| 480 | 516 | break; |
@@ -490,29 +526,35 @@ discard block |
||
| 490 | 526 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 491 | 527 | |
| 492 | 528 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 493 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 494 | - $fail = true; |
|
| 529 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 530 | + $fail = true; |
|
| 531 | + } |
|
| 495 | 532 | // Trying to change passwords, slow us down, or something? |
| 496 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 497 | - $fail = true; |
|
| 498 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 499 | - $fail = true; |
|
| 533 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 534 | + $fail = true; |
|
| 535 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 536 | + $fail = true; |
|
| 537 | + } |
|
| 500 | 538 | |
| 501 | - if (!empty($fail) && function_exists('log_error')) |
|
| 502 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 539 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 540 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 541 | + } |
|
| 503 | 542 | } |
| 504 | 543 | |
| 505 | - if (empty($db_unbuffered)) |
|
| 506 | - $ret = @mysqli_query($connection, $db_string); |
|
| 507 | - else |
|
| 508 | - $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
| 544 | + if (empty($db_unbuffered)) { |
|
| 545 | + $ret = @mysqli_query($connection, $db_string); |
|
| 546 | + } else { |
|
| 547 | + $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
| 548 | + } |
|
| 509 | 549 | |
| 510 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
| 511 | - $ret = smf_db_error($db_string, $connection); |
|
| 550 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
| 551 | + $ret = smf_db_error($db_string, $connection); |
|
| 552 | + } |
|
| 512 | 553 | |
| 513 | 554 | // Debugging. |
| 514 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 515 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 555 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 556 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 557 | + } |
|
| 516 | 558 | |
| 517 | 559 | return $ret; |
| 518 | 560 | } |
@@ -559,12 +601,13 @@ discard block |
||
| 559 | 601 | // Decide which connection to use |
| 560 | 602 | $connection = $connection === null ? $db_connection : $connection; |
| 561 | 603 | |
| 562 | - if ($type == 'begin') |
|
| 563 | - return @mysqli_query($connection, 'BEGIN'); |
|
| 564 | - elseif ($type == 'rollback') |
|
| 565 | - return @mysqli_query($connection, 'ROLLBACK'); |
|
| 566 | - elseif ($type == 'commit') |
|
| 567 | - return @mysqli_query($connection, 'COMMIT'); |
|
| 604 | + if ($type == 'begin') { |
|
| 605 | + return @mysqli_query($connection, 'BEGIN'); |
|
| 606 | + } elseif ($type == 'rollback') { |
|
| 607 | + return @mysqli_query($connection, 'ROLLBACK'); |
|
| 608 | + } elseif ($type == 'commit') { |
|
| 609 | + return @mysqli_query($connection, 'COMMIT'); |
|
| 610 | + } |
|
| 568 | 611 | |
| 569 | 612 | return false; |
| 570 | 613 | } |
@@ -604,8 +647,9 @@ discard block |
||
| 604 | 647 | // 2013: Lost connection to server during query. |
| 605 | 648 | |
| 606 | 649 | // Log the error. |
| 607 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
| 608 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 650 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
| 651 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 652 | + } |
|
| 609 | 653 | |
| 610 | 654 | // Database error auto fixing ;). |
| 611 | 655 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -614,8 +658,9 @@ discard block |
||
| 614 | 658 | $old_cache = @$modSettings['cache_enable']; |
| 615 | 659 | $modSettings['cache_enable'] = '1'; |
| 616 | 660 | |
| 617 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
| 618 | - $db_last_error = max(@$db_last_error, $temp); |
|
| 661 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
| 662 | + $db_last_error = max(@$db_last_error, $temp); |
|
| 663 | + } |
|
| 619 | 664 | |
| 620 | 665 | if (@$db_last_error < time() - 3600 * 24 * 3) |
| 621 | 666 | { |
@@ -631,8 +676,9 @@ discard block |
||
| 631 | 676 | foreach ($tables as $table) |
| 632 | 677 | { |
| 633 | 678 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
| 634 | - if (trim($table) != '') |
|
| 635 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 679 | + if (trim($table) != '') { |
|
| 680 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 681 | + } |
|
| 636 | 682 | } |
| 637 | 683 | } |
| 638 | 684 | |
@@ -641,8 +687,9 @@ discard block |
||
| 641 | 687 | // Table crashed. Let's try to fix it. |
| 642 | 688 | elseif ($query_errno == 1016) |
| 643 | 689 | { |
| 644 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
| 645 | - $fix_tables = array('`' . $match[1] . '`'); |
|
| 690 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
| 691 | + $fix_tables = array('`' . $match[1] . '`'); |
|
| 692 | + } |
|
| 646 | 693 | } |
| 647 | 694 | // Indexes crashed. Should be easy to fix! |
| 648 | 695 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -661,13 +708,15 @@ discard block |
||
| 661 | 708 | |
| 662 | 709 | // Make a note of the REPAIR... |
| 663 | 710 | cache_put_data('db_last_error', time(), 600); |
| 664 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
| 665 | - updateSettingsFile(array('db_last_error' => time())); |
|
| 711 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
| 712 | + updateSettingsFile(array('db_last_error' => time())); |
|
| 713 | + } |
|
| 666 | 714 | |
| 667 | 715 | // Attempt to find and repair the broken table. |
| 668 | - foreach ($fix_tables as $table) |
|
| 669 | - $smcFunc['db_query']('', " |
|
| 716 | + foreach ($fix_tables as $table) { |
|
| 717 | + $smcFunc['db_query']('', " |
|
| 670 | 718 | REPAIR TABLE $table", false, false); |
| 719 | + } |
|
| 671 | 720 | |
| 672 | 721 | // And send off an email! |
| 673 | 722 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -676,11 +725,12 @@ discard block |
||
| 676 | 725 | |
| 677 | 726 | // Try the query again...? |
| 678 | 727 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 679 | - if ($ret !== false) |
|
| 680 | - return $ret; |
|
| 728 | + if ($ret !== false) { |
|
| 729 | + return $ret; |
|
| 730 | + } |
|
| 731 | + } else { |
|
| 732 | + $modSettings['cache_enable'] = $old_cache; |
|
| 681 | 733 | } |
| 682 | - else |
|
| 683 | - $modSettings['cache_enable'] = $old_cache; |
|
| 684 | 734 | |
| 685 | 735 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
| 686 | 736 | if (in_array($query_errno, array(1205, 1213, 2006, 2013))) |
@@ -690,22 +740,25 @@ discard block |
||
| 690 | 740 | // Are we in SSI mode? If so try that username and password first |
| 691 | 741 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
| 692 | 742 | { |
| 693 | - if (empty($db_persist)) |
|
| 694 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 695 | - else |
|
| 696 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 743 | + if (empty($db_persist)) { |
|
| 744 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 745 | + } else { |
|
| 746 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 747 | + } |
|
| 697 | 748 | } |
| 698 | 749 | // Fall back to the regular username and password if need be |
| 699 | 750 | if (!$db_connection) |
| 700 | 751 | { |
| 701 | - if (empty($db_persist)) |
|
| 702 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 703 | - else |
|
| 704 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 752 | + if (empty($db_persist)) { |
|
| 753 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 754 | + } else { |
|
| 755 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 756 | + } |
|
| 705 | 757 | } |
| 706 | 758 | |
| 707 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
| 708 | - $db_connection = false; |
|
| 759 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
| 760 | + $db_connection = false; |
|
| 761 | + } |
|
| 709 | 762 | } |
| 710 | 763 | |
| 711 | 764 | if ($db_connection) |
@@ -716,24 +769,27 @@ discard block |
||
| 716 | 769 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 717 | 770 | |
| 718 | 771 | $new_errno = mysqli_errno($db_connection); |
| 719 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
| 720 | - break; |
|
| 772 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
| 773 | + break; |
|
| 774 | + } |
|
| 721 | 775 | } |
| 722 | 776 | |
| 723 | 777 | // If it failed again, shucks to be you... we're not trying it over and over. |
| 724 | - if ($ret !== false) |
|
| 725 | - return $ret; |
|
| 778 | + if ($ret !== false) { |
|
| 779 | + return $ret; |
|
| 780 | + } |
|
| 726 | 781 | } |
| 727 | 782 | } |
| 728 | 783 | // Are they out of space, perhaps? |
| 729 | 784 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
| 730 | 785 | { |
| 731 | - if (!isset($txt)) |
|
| 732 | - $query_error .= ' - check database storage space.'; |
|
| 733 | - else |
|
| 786 | + if (!isset($txt)) { |
|
| 787 | + $query_error .= ' - check database storage space.'; |
|
| 788 | + } else |
|
| 734 | 789 | { |
| 735 | - if (!isset($txt['mysql_error_space'])) |
|
| 736 | - loadLanguage('Errors'); |
|
| 790 | + if (!isset($txt['mysql_error_space'])) { |
|
| 791 | + loadLanguage('Errors'); |
|
| 792 | + } |
|
| 737 | 793 | |
| 738 | 794 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
| 739 | 795 | } |
@@ -741,15 +797,17 @@ discard block |
||
| 741 | 797 | } |
| 742 | 798 | |
| 743 | 799 | // Nothing's defined yet... just die with it. |
| 744 | - if (empty($context) || empty($txt)) |
|
| 745 | - die($query_error); |
|
| 800 | + if (empty($context) || empty($txt)) { |
|
| 801 | + die($query_error); |
|
| 802 | + } |
|
| 746 | 803 | |
| 747 | 804 | // Show an error message, if possible. |
| 748 | 805 | $context['error_title'] = $txt['database_error']; |
| 749 | - if (allowedTo('admin_forum')) |
|
| 750 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 751 | - else |
|
| 752 | - $context['error_message'] = $txt['try_again']; |
|
| 806 | + if (allowedTo('admin_forum')) { |
|
| 807 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 808 | + } else { |
|
| 809 | + $context['error_message'] = $txt['try_again']; |
|
| 810 | + } |
|
| 753 | 811 | |
| 754 | 812 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 755 | 813 | { |
@@ -779,25 +837,28 @@ discard block |
||
| 779 | 837 | $connection = $connection === null ? $db_connection : $connection; |
| 780 | 838 | |
| 781 | 839 | // With nothing to insert, simply return. |
| 782 | - if (empty($data)) |
|
| 783 | - return; |
|
| 840 | + if (empty($data)) { |
|
| 841 | + return; |
|
| 842 | + } |
|
| 784 | 843 | |
| 785 | 844 | // Replace the prefix holder with the actual prefix. |
| 786 | 845 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
| 787 | 846 | |
| 788 | 847 | // Inserting data as a single row can be done as a single array. |
| 789 | - if (!is_array($data[array_rand($data)])) |
|
| 790 | - $data = array($data); |
|
| 848 | + if (!is_array($data[array_rand($data)])) { |
|
| 849 | + $data = array($data); |
|
| 850 | + } |
|
| 791 | 851 | |
| 792 | 852 | // Create the mold for a single row insert. |
| 793 | 853 | $insertData = '('; |
| 794 | 854 | foreach ($columns as $columnName => $type) |
| 795 | 855 | { |
| 796 | 856 | // Are we restricting the length? |
| 797 | - if (strpos($type, 'string-') !== false) |
|
| 798 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 799 | - else |
|
| 800 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 857 | + if (strpos($type, 'string-') !== false) { |
|
| 858 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 859 | + } else { |
|
| 860 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 861 | + } |
|
| 801 | 862 | } |
| 802 | 863 | $insertData = substr($insertData, 0, -2) . ')'; |
| 803 | 864 | |
@@ -806,8 +867,9 @@ discard block |
||
| 806 | 867 | |
| 807 | 868 | // Here's where the variables are injected to the query. |
| 808 | 869 | $insertRows = array(); |
| 809 | - foreach ($data as $dataRow) |
|
| 810 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 870 | + foreach ($data as $dataRow) { |
|
| 871 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 872 | + } |
|
| 811 | 873 | |
| 812 | 874 | // Determine the method of insertion. |
| 813 | 875 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
@@ -827,15 +889,16 @@ discard block |
||
| 827 | 889 | |
| 828 | 890 | if(!empty($keys) && (count($keys) > 0) && $method == '' && $returnmode > 0) |
| 829 | 891 | { |
| 830 | - if ($returnmode == 1) |
|
| 831 | - $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
| 832 | - else if ($returnmode == 2) |
|
| 892 | + if ($returnmode == 1) { |
|
| 893 | + $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
| 894 | + } else if ($returnmode == 2) |
|
| 833 | 895 | { |
| 834 | 896 | $return_var = array(); |
| 835 | 897 | $count = count($insertRows); |
| 836 | 898 | $start = smf_db_insert_id($table, $keys[0]); |
| 837 | - for ($i = 0; $i < $count; $i++ ) |
|
| 838 | - $return_var[] = $start + $i; |
|
| 899 | + for ($i = 0; $i < $count; $i++ ) { |
|
| 900 | + $return_var[] = $start + $i; |
|
| 901 | + } |
|
| 839 | 902 | } |
| 840 | 903 | return $return_var; |
| 841 | 904 | } |
@@ -853,8 +916,9 @@ discard block |
||
| 853 | 916 | */ |
| 854 | 917 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 855 | 918 | { |
| 856 | - if (empty($log_message)) |
|
| 857 | - $log_message = $error_message; |
|
| 919 | + if (empty($log_message)) { |
|
| 920 | + $log_message = $error_message; |
|
| 921 | + } |
|
| 858 | 922 | |
| 859 | 923 | foreach (debug_backtrace() as $step) |
| 860 | 924 | { |
@@ -873,12 +937,14 @@ discard block |
||
| 873 | 937 | } |
| 874 | 938 | |
| 875 | 939 | // A special case - we want the file and line numbers for debugging. |
| 876 | - if ($error_type == 'return') |
|
| 877 | - return array($file, $line); |
|
| 940 | + if ($error_type == 'return') { |
|
| 941 | + return array($file, $line); |
|
| 942 | + } |
|
| 878 | 943 | |
| 879 | 944 | // Is always a critical error. |
| 880 | - if (function_exists('log_error')) |
|
| 881 | - log_error($log_message, 'critical', $file, $line); |
|
| 945 | + if (function_exists('log_error')) { |
|
| 946 | + log_error($log_message, 'critical', $file, $line); |
|
| 947 | + } |
|
| 882 | 948 | |
| 883 | 949 | if (function_exists('fatal_error')) |
| 884 | 950 | { |
@@ -886,12 +952,12 @@ discard block |
||
| 886 | 952 | |
| 887 | 953 | // Cannot continue... |
| 888 | 954 | exit; |
| 955 | + } elseif ($error_type) { |
|
| 956 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 957 | + } else { |
|
| 958 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 959 | + } |
|
| 889 | 960 | } |
| 890 | - elseif ($error_type) |
|
| 891 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 892 | - else |
|
| 893 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 894 | -} |
|
| 895 | 961 | |
| 896 | 962 | /** |
| 897 | 963 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -908,10 +974,11 @@ discard block |
||
| 908 | 974 | '\\' => '\\\\', |
| 909 | 975 | ); |
| 910 | 976 | |
| 911 | - if ($translate_human_wildcards) |
|
| 912 | - $replacements += array( |
|
| 977 | + if ($translate_human_wildcards) { |
|
| 978 | + $replacements += array( |
|
| 913 | 979 | '*' => '%', |
| 914 | 980 | ); |
| 981 | + } |
|
| 915 | 982 | |
| 916 | 983 | return strtr($string, $replacements); |
| 917 | 984 | } |
@@ -925,8 +992,9 @@ discard block |
||
| 925 | 992 | */ |
| 926 | 993 | function smf_is_resource($result) |
| 927 | 994 | { |
| 928 | - if ($result instanceof mysqli_result) |
|
| 929 | - return true; |
|
| 995 | + if ($result instanceof mysqli_result) { |
|
| 996 | + return true; |
|
| 997 | + } |
|
| 930 | 998 | |
| 931 | 999 | return false; |
| 932 | 1000 | } |