@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * This function works out what to do! |
@@ -24,9 +25,9 @@ discard block |
||
| 24 | 25 | global $time_start, $smcFunc, $modSettings; |
| 25 | 26 | |
| 26 | 27 | // Special case for doing the mail queue. |
| 27 | - if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') |
|
| 28 | - ReduceMailQueue(); |
|
| 29 | - else |
|
| 28 | + if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') { |
|
| 29 | + ReduceMailQueue(); |
|
| 30 | + } else |
|
| 30 | 31 | { |
| 31 | 32 | $task_string = ''; |
| 32 | 33 | |
@@ -53,18 +54,20 @@ discard block |
||
| 53 | 54 | |
| 54 | 55 | // How long in seconds it the gap? |
| 55 | 56 | $duration = $row['time_regularity']; |
| 56 | - if ($row['time_unit'] == 'm') |
|
| 57 | - $duration *= 60; |
|
| 58 | - elseif ($row['time_unit'] == 'h') |
|
| 59 | - $duration *= 3600; |
|
| 60 | - elseif ($row['time_unit'] == 'd') |
|
| 61 | - $duration *= 86400; |
|
| 62 | - elseif ($row['time_unit'] == 'w') |
|
| 63 | - $duration *= 604800; |
|
| 57 | + if ($row['time_unit'] == 'm') { |
|
| 58 | + $duration *= 60; |
|
| 59 | + } elseif ($row['time_unit'] == 'h') { |
|
| 60 | + $duration *= 3600; |
|
| 61 | + } elseif ($row['time_unit'] == 'd') { |
|
| 62 | + $duration *= 86400; |
|
| 63 | + } elseif ($row['time_unit'] == 'w') { |
|
| 64 | + $duration *= 604800; |
|
| 65 | + } |
|
| 64 | 66 | |
| 65 | 67 | // If we were really late running this task actually skip the next one. |
| 66 | - if (time() + ($duration / 2) > $next_time) |
|
| 67 | - $next_time += $duration; |
|
| 68 | + if (time() + ($duration / 2) > $next_time) { |
|
| 69 | + $next_time += $duration; |
|
| 70 | + } |
|
| 68 | 71 | |
| 69 | 72 | // Update it now, so no others run this! |
| 70 | 73 | $smcFunc['db_query']('', ' |
@@ -81,16 +84,19 @@ discard block |
||
| 81 | 84 | $affected_rows = $smcFunc['db_affected_rows'](); |
| 82 | 85 | |
| 83 | 86 | // What kind of task are we handling? |
| 84 | - if (!empty($row['callable'])) |
|
| 85 | - $task_string = $row['callable']; |
|
| 87 | + if (!empty($row['callable'])) { |
|
| 88 | + $task_string = $row['callable']; |
|
| 89 | + } |
|
| 86 | 90 | |
| 87 | 91 | // Default SMF task or old mods? |
| 88 | - elseif (function_exists('scheduled_' . $row['task'])) |
|
| 89 | - $task_string = 'scheduled_' . $row['task']; |
|
| 92 | + elseif (function_exists('scheduled_' . $row['task'])) { |
|
| 93 | + $task_string = 'scheduled_' . $row['task']; |
|
| 94 | + } |
|
| 90 | 95 | |
| 91 | 96 | // One last resource, the task name. |
| 92 | - elseif (!empty($row['task'])) |
|
| 93 | - $task_string = $row['task']; |
|
| 97 | + elseif (!empty($row['task'])) { |
|
| 98 | + $task_string = $row['task']; |
|
| 99 | + } |
|
| 94 | 100 | |
| 95 | 101 | // The function must exist or we are wasting our time, plus do some timestamp checking, and database check! |
| 96 | 102 | if (!empty($task_string) && (!isset($_GET['ts']) || $_GET['ts'] == $row['next_time']) && $affected_rows) |
@@ -101,11 +107,11 @@ discard block |
||
| 101 | 107 | $callable_task = call_helper($task_string, true); |
| 102 | 108 | |
| 103 | 109 | // Perform the task. |
| 104 | - if (!empty($callable_task)) |
|
| 105 | - $completed = call_user_func($callable_task); |
|
| 106 | - |
|
| 107 | - else |
|
| 108 | - $completed = false; |
|
| 110 | + if (!empty($callable_task)) { |
|
| 111 | + $completed = call_user_func($callable_task); |
|
| 112 | + } else { |
|
| 113 | + $completed = false; |
|
| 114 | + } |
|
| 109 | 115 | |
| 110 | 116 | // Log that we did it ;) |
| 111 | 117 | if ($completed) |
@@ -138,18 +144,20 @@ discard block |
||
| 138 | 144 | ) |
| 139 | 145 | ); |
| 140 | 146 | // No new task scheduled yet? |
| 141 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 142 | - $nextEvent = time() + 86400; |
|
| 143 | - else |
|
| 144 | - list ($nextEvent) = $smcFunc['db_fetch_row']($request); |
|
| 147 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 148 | + $nextEvent = time() + 86400; |
|
| 149 | + } else { |
|
| 150 | + list ($nextEvent) = $smcFunc['db_fetch_row']($request); |
|
| 151 | + } |
|
| 145 | 152 | $smcFunc['db_free_result']($request); |
| 146 | 153 | |
| 147 | 154 | updateSettings(array('next_task_time' => $nextEvent)); |
| 148 | 155 | } |
| 149 | 156 | |
| 150 | 157 | // Shall we return? |
| 151 | - if (!isset($_GET['scheduled'])) |
|
| 152 | - return true; |
|
| 158 | + if (!isset($_GET['scheduled'])) { |
|
| 159 | + return true; |
|
| 160 | + } |
|
| 153 | 161 | |
| 154 | 162 | // Finally, send some stuff... |
| 155 | 163 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -181,16 +189,18 @@ discard block |
||
| 181 | 189 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 182 | 190 | { |
| 183 | 191 | // If this is no longer around we'll ignore it. |
| 184 | - if (empty($row['id_topic'])) |
|
| 185 | - continue; |
|
| 192 | + if (empty($row['id_topic'])) { |
|
| 193 | + continue; |
|
| 194 | + } |
|
| 186 | 195 | |
| 187 | 196 | // What type is it? |
| 188 | - if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) |
|
| 189 | - $type = 'topic'; |
|
| 190 | - elseif ($row['id_attach']) |
|
| 191 | - $type = 'attach'; |
|
| 192 | - else |
|
| 193 | - $type = 'msg'; |
|
| 197 | + if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) { |
|
| 198 | + $type = 'topic'; |
|
| 199 | + } elseif ($row['id_attach']) { |
|
| 200 | + $type = 'attach'; |
|
| 201 | + } else { |
|
| 202 | + $type = 'msg'; |
|
| 203 | + } |
|
| 194 | 204 | |
| 195 | 205 | // Add it to the array otherwise. |
| 196 | 206 | $notices[$row['id_board']][$type][] = array( |
@@ -211,8 +221,9 @@ discard block |
||
| 211 | 221 | ); |
| 212 | 222 | |
| 213 | 223 | // If nothing quit now. |
| 214 | - if (empty($notices)) |
|
| 215 | - return true; |
|
| 224 | + if (empty($notices)) { |
|
| 225 | + return true; |
|
| 226 | + } |
|
| 216 | 227 | |
| 217 | 228 | // Now we need to think about finding out *who* can approve - this is hard! |
| 218 | 229 | |
@@ -231,14 +242,16 @@ discard block |
||
| 231 | 242 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 232 | 243 | { |
| 233 | 244 | // Sorry guys, but we have to ignore guests AND members - it would be too many otherwise. |
| 234 | - if ($row['id_group'] < 2) |
|
| 235 | - continue; |
|
| 245 | + if ($row['id_group'] < 2) { |
|
| 246 | + continue; |
|
| 247 | + } |
|
| 236 | 248 | |
| 237 | 249 | $perms[$row['id_profile']][$row['add_deny'] ? 'add' : 'deny'][] = $row['id_group']; |
| 238 | 250 | |
| 239 | 251 | // Anyone who can access has to be considered. |
| 240 | - if ($row['add_deny']) |
|
| 241 | - $addGroups[] = $row['id_group']; |
|
| 252 | + if ($row['add_deny']) { |
|
| 253 | + $addGroups[] = $row['id_group']; |
|
| 254 | + } |
|
| 242 | 255 | } |
| 243 | 256 | $smcFunc['db_free_result']($request); |
| 244 | 257 | |
@@ -283,8 +296,9 @@ discard block |
||
| 283 | 296 | if (!empty($row['mod_prefs'])) |
| 284 | 297 | { |
| 285 | 298 | list(,, $pref_binary) = explode('|', $row['mod_prefs']); |
| 286 | - if (!($pref_binary & 4)) |
|
| 287 | - continue; |
|
| 299 | + if (!($pref_binary & 4)) { |
|
| 300 | + continue; |
|
| 301 | + } |
|
| 288 | 302 | } |
| 289 | 303 | |
| 290 | 304 | $members[$row['id_member']] = array( |
@@ -309,8 +323,9 @@ discard block |
||
| 309 | 323 | $emailbody = ''; |
| 310 | 324 | |
| 311 | 325 | // Load the language file as required. |
| 312 | - if (empty($current_language) || $current_language != $member['language']) |
|
| 313 | - $current_language = loadLanguage('EmailTemplates', $member['language'], false); |
|
| 326 | + if (empty($current_language) || $current_language != $member['language']) { |
|
| 327 | + $current_language = loadLanguage('EmailTemplates', $member['language'], false); |
|
| 328 | + } |
|
| 314 | 329 | |
| 315 | 330 | // Loop through each notice... |
| 316 | 331 | foreach ($notices as $board => $notice) |
@@ -318,29 +333,34 @@ discard block |
||
| 318 | 333 | $access = false; |
| 319 | 334 | |
| 320 | 335 | // Can they mod in this board? |
| 321 | - if (isset($mods[$id][$board])) |
|
| 322 | - $access = true; |
|
| 336 | + if (isset($mods[$id][$board])) { |
|
| 337 | + $access = true; |
|
| 338 | + } |
|
| 323 | 339 | |
| 324 | 340 | // Do the group check... |
| 325 | 341 | if (!$access && isset($perms[$profiles[$board]]['add'])) |
| 326 | 342 | { |
| 327 | 343 | // They can access?! |
| 328 | - if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) |
|
| 329 | - $access = true; |
|
| 344 | + if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) { |
|
| 345 | + $access = true; |
|
| 346 | + } |
|
| 330 | 347 | |
| 331 | 348 | // If they have deny rights don't consider them! |
| 332 | - if (isset($perms[$profiles[$board]]['deny'])) |
|
| 333 | - if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups'])) |
|
| 349 | + if (isset($perms[$profiles[$board]]['deny'])) { |
|
| 350 | + if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups'])) |
|
| 334 | 351 | $access = false; |
| 352 | + } |
|
| 335 | 353 | } |
| 336 | 354 | |
| 337 | 355 | // Finally, fix it for admins! |
| 338 | - if (in_array(1, $member['groups'])) |
|
| 339 | - $access = true; |
|
| 356 | + if (in_array(1, $member['groups'])) { |
|
| 357 | + $access = true; |
|
| 358 | + } |
|
| 340 | 359 | |
| 341 | 360 | // If they can't access it then give it a break! |
| 342 | - if (!$access) |
|
| 343 | - continue; |
|
| 361 | + if (!$access) { |
|
| 362 | + continue; |
|
| 363 | + } |
|
| 344 | 364 | |
| 345 | 365 | foreach ($notice as $type => $items) |
| 346 | 366 | { |
@@ -348,15 +368,17 @@ discard block |
||
| 348 | 368 | $emailbody .= $txt['scheduled_approval_email_' . $type] . "\n" . |
| 349 | 369 | '------------------------------------------------------' . "\n"; |
| 350 | 370 | |
| 351 | - foreach ($items as $item) |
|
| 352 | - $emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n"; |
|
| 371 | + foreach ($items as $item) { |
|
| 372 | + $emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n"; |
|
| 373 | + } |
|
| 353 | 374 | |
| 354 | 375 | $emailbody .= "\n"; |
| 355 | 376 | } |
| 356 | 377 | } |
| 357 | 378 | |
| 358 | - if ($emailbody == '') |
|
| 359 | - continue; |
|
| 379 | + if ($emailbody == '') { |
|
| 380 | + continue; |
|
| 381 | + } |
|
| 360 | 382 | |
| 361 | 383 | $replacements = array( |
| 362 | 384 | 'REALNAME' => $member['name'], |
@@ -397,8 +419,9 @@ discard block |
||
| 397 | 419 | ) |
| 398 | 420 | ); |
| 399 | 421 | $members = array(); |
| 400 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 401 | - $members[$row['id_member']] = $row['warning']; |
|
| 422 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 423 | + $members[$row['id_member']] = $row['warning']; |
|
| 424 | + } |
|
| 402 | 425 | $smcFunc['db_free_result']($request); |
| 403 | 426 | |
| 404 | 427 | // Have some members to check? |
@@ -420,17 +443,18 @@ discard block |
||
| 420 | 443 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 421 | 444 | { |
| 422 | 445 | // More than 24 hours ago? |
| 423 | - if ($row['last_warning'] <= time() - 86400) |
|
| 424 | - $member_changes[] = array( |
|
| 446 | + if ($row['last_warning'] <= time() - 86400) { |
|
| 447 | + $member_changes[] = array( |
|
| 425 | 448 | 'id' => $row['id_recipient'], |
| 426 | 449 | 'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0, |
| 427 | 450 | ); |
| 451 | + } |
|
| 428 | 452 | } |
| 429 | 453 | $smcFunc['db_free_result']($request); |
| 430 | 454 | |
| 431 | 455 | // Have some members to change? |
| 432 | - if (!empty($member_changes)) |
|
| 433 | - foreach ($member_changes as $change) |
|
| 456 | + if (!empty($member_changes)) { |
|
| 457 | + foreach ($member_changes as $change) |
|
| 434 | 458 | $smcFunc['db_query']('', ' |
| 435 | 459 | UPDATE {db_prefix}members |
| 436 | 460 | SET warning = {int:warning} |
@@ -440,6 +464,7 @@ discard block |
||
| 440 | 464 | 'id_member' => $change['id'], |
| 441 | 465 | ) |
| 442 | 466 | ); |
| 467 | + } |
|
| 443 | 468 | } |
| 444 | 469 | } |
| 445 | 470 | |
@@ -452,16 +477,17 @@ discard block |
||
| 452 | 477 | |
| 453 | 478 | // Check the database version - for some buggy MySQL version. |
| 454 | 479 | $server_version = $smcFunc['db_server_info'](); |
| 455 | - if (($db_type == 'mysql') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) |
|
| 456 | - updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 457 | - elseif (!empty($modSettings['db_mysql_group_by_fix'])) |
|
| 458 | - $smcFunc['db_query']('', ' |
|
| 480 | + if (($db_type == 'mysql') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { |
|
| 481 | + updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 482 | + } elseif (!empty($modSettings['db_mysql_group_by_fix'])) { |
|
| 483 | + $smcFunc['db_query']('', ' |
|
| 459 | 484 | DELETE FROM {db_prefix}settings |
| 460 | 485 | WHERE variable = {string:mysql_fix}', |
| 461 | 486 | array( |
| 462 | 487 | 'mysql_fix' => 'db_mysql_group_by_fix', |
| 463 | 488 | ) |
| 464 | 489 | ); |
| 490 | + } |
|
| 465 | 491 | |
| 466 | 492 | // Clean up some old login history information. |
| 467 | 493 | $smcFunc['db_query']('', ' |
@@ -519,15 +545,17 @@ discard block |
||
| 519 | 545 | |
| 520 | 546 | // Store this useful data! |
| 521 | 547 | $boards[$row['id_board']] = $row['id_board']; |
| 522 | - if ($row['id_topic']) |
|
| 523 | - $notify['topics'][$row['id_topic']][] = $row['id_member']; |
|
| 524 | - else |
|
| 525 | - $notify['boards'][$row['id_board']][] = $row['id_member']; |
|
| 548 | + if ($row['id_topic']) { |
|
| 549 | + $notify['topics'][$row['id_topic']][] = $row['id_member']; |
|
| 550 | + } else { |
|
| 551 | + $notify['boards'][$row['id_board']][] = $row['id_member']; |
|
| 552 | + } |
|
| 526 | 553 | } |
| 527 | 554 | $smcFunc['db_free_result']($request); |
| 528 | 555 | |
| 529 | - if (empty($boards)) |
|
| 530 | - return true; |
|
| 556 | + if (empty($boards)) { |
|
| 557 | + return true; |
|
| 558 | + } |
|
| 531 | 559 | |
| 532 | 560 | // Just get the board names. |
| 533 | 561 | $request = $smcFunc['db_query']('', ' |
@@ -539,12 +567,14 @@ discard block |
||
| 539 | 567 | ) |
| 540 | 568 | ); |
| 541 | 569 | $boards = array(); |
| 542 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 543 | - $boards[$row['id_board']] = $row['name']; |
|
| 570 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 571 | + $boards[$row['id_board']] = $row['name']; |
|
| 572 | + } |
|
| 544 | 573 | $smcFunc['db_free_result']($request); |
| 545 | 574 | |
| 546 | - if (empty($boards)) |
|
| 547 | - return true; |
|
| 575 | + if (empty($boards)) { |
|
| 576 | + return true; |
|
| 577 | + } |
|
| 548 | 578 | |
| 549 | 579 | // Get the actual topics... |
| 550 | 580 | $request = $smcFunc['db_query']('', ' |
@@ -564,52 +594,57 @@ discard block |
||
| 564 | 594 | $types = array(); |
| 565 | 595 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 566 | 596 | { |
| 567 | - if (!isset($types[$row['note_type']][$row['id_board']])) |
|
| 568 | - $types[$row['note_type']][$row['id_board']] = array( |
|
| 597 | + if (!isset($types[$row['note_type']][$row['id_board']])) { |
|
| 598 | + $types[$row['note_type']][$row['id_board']] = array( |
|
| 569 | 599 | 'lines' => array(), |
| 570 | 600 | 'name' => $row['board_name'], |
| 571 | 601 | 'id' => $row['id_board'], |
| 572 | 602 | ); |
| 603 | + } |
|
| 573 | 604 | |
| 574 | 605 | if ($row['note_type'] == 'reply') |
| 575 | 606 | { |
| 576 | - if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) |
|
| 577 | - $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++; |
|
| 578 | - else |
|
| 579 | - $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array( |
|
| 607 | + if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) { |
|
| 608 | + $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++; |
|
| 609 | + } else { |
|
| 610 | + $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array( |
|
| 580 | 611 | 'id' => $row['id_topic'], |
| 581 | 612 | 'subject' => un_htmlspecialchars($row['subject']), |
| 582 | 613 | 'count' => 1, |
| 583 | 614 | ); |
| 584 | - } |
|
| 585 | - elseif ($row['note_type'] == 'topic') |
|
| 615 | + } |
|
| 616 | + } elseif ($row['note_type'] == 'topic') |
|
| 586 | 617 | { |
| 587 | - if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) |
|
| 588 | - $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array( |
|
| 618 | + if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) { |
|
| 619 | + $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array( |
|
| 589 | 620 | 'id' => $row['id_topic'], |
| 590 | 621 | 'subject' => un_htmlspecialchars($row['subject']), |
| 591 | 622 | ); |
| 592 | - } |
|
| 593 | - else |
|
| 623 | + } |
|
| 624 | + } else |
|
| 594 | 625 | { |
| 595 | - if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) |
|
| 596 | - $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array( |
|
| 626 | + if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) { |
|
| 627 | + $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array( |
|
| 597 | 628 | 'id' => $row['id_topic'], |
| 598 | 629 | 'subject' => un_htmlspecialchars($row['subject']), |
| 599 | 630 | 'starter' => $row['id_member_started'], |
| 600 | 631 | ); |
| 632 | + } |
|
| 601 | 633 | } |
| 602 | 634 | |
| 603 | 635 | $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array(); |
| 604 | - if (!empty($notify['topics'][$row['id_topic']])) |
|
| 605 | - $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]); |
|
| 606 | - if (!empty($notify['boards'][$row['id_board']])) |
|
| 607 | - $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]); |
|
| 636 | + if (!empty($notify['topics'][$row['id_topic']])) { |
|
| 637 | + $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]); |
|
| 638 | + } |
|
| 639 | + if (!empty($notify['boards'][$row['id_board']])) { |
|
| 640 | + $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]); |
|
| 641 | + } |
|
| 608 | 642 | } |
| 609 | 643 | $smcFunc['db_free_result']($request); |
| 610 | 644 | |
| 611 | - if (empty($types)) |
|
| 612 | - return true; |
|
| 645 | + if (empty($types)) { |
|
| 646 | + return true; |
|
| 647 | + } |
|
| 613 | 648 | |
| 614 | 649 | // Let's load all the languages into a cache thingy. |
| 615 | 650 | $langtxt = array(); |
@@ -650,8 +685,9 @@ discard block |
||
| 650 | 685 | $notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1; |
| 651 | 686 | |
| 652 | 687 | // Did they not elect to choose this? |
| 653 | - if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) |
|
| 654 | - continue; |
|
| 688 | + if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) { |
|
| 689 | + continue; |
|
| 690 | + } |
|
| 655 | 691 | |
| 656 | 692 | // Right character set! |
| 657 | 693 | $context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set']; |
@@ -667,39 +703,43 @@ discard block |
||
| 667 | 703 | if (isset($types['topic'])) |
| 668 | 704 | { |
| 669 | 705 | $titled = false; |
| 670 | - foreach ($types['topic'] as $id => $board) |
|
| 671 | - foreach ($board['lines'] as $topic) |
|
| 706 | + foreach ($types['topic'] as $id => $board) { |
|
| 707 | + foreach ($board['lines'] as $topic) |
|
| 672 | 708 | if (in_array($mid, $topic['members'])) |
| 673 | 709 | { |
| 674 | 710 | if (!$titled) |
| 675 | 711 | { |
| 676 | 712 | $email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------'; |
| 713 | + } |
|
| 677 | 714 | $titled = true; |
| 678 | 715 | } |
| 679 | 716 | $email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']); |
| 680 | 717 | } |
| 681 | - if ($titled) |
|
| 682 | - $email['body'] .= "\n"; |
|
| 718 | + if ($titled) { |
|
| 719 | + $email['body'] .= "\n"; |
|
| 720 | + } |
|
| 683 | 721 | } |
| 684 | 722 | |
| 685 | 723 | // What about replies? |
| 686 | 724 | if (isset($types['reply'])) |
| 687 | 725 | { |
| 688 | 726 | $titled = false; |
| 689 | - foreach ($types['reply'] as $id => $board) |
|
| 690 | - foreach ($board['lines'] as $topic) |
|
| 727 | + foreach ($types['reply'] as $id => $board) { |
|
| 728 | + foreach ($board['lines'] as $topic) |
|
| 691 | 729 | if (in_array($mid, $topic['members'])) |
| 692 | 730 | { |
| 693 | 731 | if (!$titled) |
| 694 | 732 | { |
| 695 | 733 | $email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------'; |
| 734 | + } |
|
| 696 | 735 | $titled = true; |
| 697 | 736 | } |
| 698 | 737 | $email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject'])); |
| 699 | 738 | } |
| 700 | 739 | |
| 701 | - if ($titled) |
|
| 702 | - $email['body'] .= "\n"; |
|
| 740 | + if ($titled) { |
|
| 741 | + $email['body'] .= "\n"; |
|
| 742 | + } |
|
| 703 | 743 | } |
| 704 | 744 | |
| 705 | 745 | // Finally, moderation actions! |
@@ -708,24 +748,27 @@ discard block |
||
| 708 | 748 | $titled = false; |
| 709 | 749 | foreach ($types as $note_type => $type) |
| 710 | 750 | { |
| 711 | - if ($note_type == 'topic' || $note_type == 'reply') |
|
| 712 | - continue; |
|
| 751 | + if ($note_type == 'topic' || $note_type == 'reply') { |
|
| 752 | + continue; |
|
| 753 | + } |
|
| 713 | 754 | |
| 714 | - foreach ($type as $id => $board) |
|
| 715 | - foreach ($board['lines'] as $topic) |
|
| 755 | + foreach ($type as $id => $board) { |
|
| 756 | + foreach ($board['lines'] as $topic) |
|
| 716 | 757 | if (in_array($mid, $topic['members'])) |
| 717 | 758 | { |
| 718 | 759 | if (!$titled) |
| 719 | 760 | { |
| 720 | 761 | $email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------'; |
| 762 | + } |
|
| 721 | 763 | $titled = true; |
| 722 | 764 | } |
| 723 | 765 | $email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']); |
| 724 | 766 | } |
| 725 | 767 | } |
| 726 | 768 | } |
| 727 | - if ($titled) |
|
| 728 | - $email['body'] .= "\n"; |
|
| 769 | + if ($titled) { |
|
| 770 | + $email['body'] .= "\n"; |
|
| 771 | + } |
|
| 729 | 772 | |
| 730 | 773 | // Then just say our goodbyes! |
| 731 | 774 | $email['body'] .= "\n\n" . $txt['regards_team']; |
@@ -753,8 +796,7 @@ discard block |
||
| 753 | 796 | 'not_daily' => 0, |
| 754 | 797 | ) |
| 755 | 798 | ); |
| 756 | - } |
|
| 757 | - else |
|
| 799 | + } else |
|
| 758 | 800 | { |
| 759 | 801 | // Clear any only weekly ones, and stop us from sending daily again. |
| 760 | 802 | $smcFunc['db_query']('', ' |
@@ -816,16 +858,19 @@ discard block |
||
| 816 | 858 | global $modSettings, $smcFunc, $sourcedir; |
| 817 | 859 | |
| 818 | 860 | // Are we intending another script to be sending out the queue? |
| 819 | - if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) |
|
| 820 | - return false; |
|
| 861 | + if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) { |
|
| 862 | + return false; |
|
| 863 | + } |
|
| 821 | 864 | |
| 822 | 865 | // By default send 5 at once. |
| 823 | - if (!$number) |
|
| 824 | - $number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity']; |
|
| 866 | + if (!$number) { |
|
| 867 | + $number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity']; |
|
| 868 | + } |
|
| 825 | 869 | |
| 826 | 870 | // If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us. |
| 827 | - if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) |
|
| 828 | - return false; |
|
| 871 | + if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) { |
|
| 872 | + return false; |
|
| 873 | + } |
|
| 829 | 874 | |
| 830 | 875 | // By default move the next sending on by 10 seconds, and require an affected row. |
| 831 | 876 | if (!$override_limit) |
@@ -842,8 +887,9 @@ discard block |
||
| 842 | 887 | 'last_send' => $modSettings['mail_next_send'], |
| 843 | 888 | ) |
| 844 | 889 | ); |
| 845 | - if ($smcFunc['db_affected_rows']() == 0) |
|
| 846 | - return false; |
|
| 890 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
| 891 | + return false; |
|
| 892 | + } |
|
| 847 | 893 | $modSettings['mail_next_send'] = time() + $delay; |
| 848 | 894 | } |
| 849 | 895 | |
@@ -864,8 +910,9 @@ discard block |
||
| 864 | 910 | $mn += $number; |
| 865 | 911 | } |
| 866 | 912 | // No more I'm afraid, return! |
| 867 | - else |
|
| 868 | - return false; |
|
| 913 | + else { |
|
| 914 | + return false; |
|
| 915 | + } |
|
| 869 | 916 | |
| 870 | 917 | // Reflect that we're about to send some, do it now to be safe. |
| 871 | 918 | updateSettings(array('mail_recent' => $mt . '|' . $mn)); |
@@ -900,14 +947,15 @@ discard block |
||
| 900 | 947 | $smcFunc['db_free_result']($request); |
| 901 | 948 | |
| 902 | 949 | // Delete, delete, delete!!! |
| 903 | - if (!empty($ids)) |
|
| 904 | - $smcFunc['db_query']('', ' |
|
| 950 | + if (!empty($ids)) { |
|
| 951 | + $smcFunc['db_query']('', ' |
|
| 905 | 952 | DELETE FROM {db_prefix}mail_queue |
| 906 | 953 | WHERE id_mail IN ({array_int:mail_list})', |
| 907 | 954 | array( |
| 908 | 955 | 'mail_list' => $ids, |
| 909 | 956 | ) |
| 910 | 957 | ); |
| 958 | + } |
|
| 911 | 959 | |
| 912 | 960 | // Don't believe we have any left? |
| 913 | 961 | if (count($ids) < $number) |
@@ -925,11 +973,13 @@ discard block |
||
| 925 | 973 | ); |
| 926 | 974 | } |
| 927 | 975 | |
| 928 | - if (empty($ids)) |
|
| 929 | - return false; |
|
| 976 | + if (empty($ids)) { |
|
| 977 | + return false; |
|
| 978 | + } |
|
| 930 | 979 | |
| 931 | - if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') |
|
| 932 | - require_once($sourcedir . '/Subs-Post.php'); |
|
| 980 | + if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') { |
|
| 981 | + require_once($sourcedir . '/Subs-Post.php'); |
|
| 982 | + } |
|
| 933 | 983 | |
| 934 | 984 | // Send each email, yea! |
| 935 | 985 | $failed_emails = array(); |
@@ -949,15 +999,17 @@ discard block |
||
| 949 | 999 | |
| 950 | 1000 | // Try to stop a timeout, this would be bad... |
| 951 | 1001 | @set_time_limit(300); |
| 952 | - if (function_exists('apache_reset_timeout')) |
|
| 953 | - @apache_reset_timeout(); |
|
| 1002 | + if (function_exists('apache_reset_timeout')) { |
|
| 1003 | + @apache_reset_timeout(); |
|
| 1004 | + } |
|
| 1005 | + } else { |
|
| 1006 | + $result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']); |
|
| 954 | 1007 | } |
| 955 | - else |
|
| 956 | - $result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']); |
|
| 957 | 1008 | |
| 958 | 1009 | // Hopefully it sent? |
| 959 | - if (!$result) |
|
| 960 | - $failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']); |
|
| 1010 | + if (!$result) { |
|
| 1011 | + $failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']); |
|
| 1012 | + } |
|
| 961 | 1013 | } |
| 962 | 1014 | |
| 963 | 1015 | // Any emails that didn't send? |
@@ -972,8 +1024,8 @@ discard block |
||
| 972 | 1024 | ); |
| 973 | 1025 | |
| 974 | 1026 | // If we have failed to many times, tell mail to wait a bit and try again. |
| 975 | - if ($modSettings['mail_failed_attempts'] > 5) |
|
| 976 | - $smcFunc['db_query']('', ' |
|
| 1027 | + if ($modSettings['mail_failed_attempts'] > 5) { |
|
| 1028 | + $smcFunc['db_query']('', ' |
|
| 977 | 1029 | UPDATE {db_prefix}settings |
| 978 | 1030 | SET value = {string:next_mail_send} |
| 979 | 1031 | WHERE variable = {literal:mail_next_send} |
@@ -982,6 +1034,7 @@ discard block |
||
| 982 | 1034 | 'next_mail_send' => time() + 60, |
| 983 | 1035 | 'last_send' => $modSettings['mail_next_send'], |
| 984 | 1036 | )); |
| 1037 | + } |
|
| 985 | 1038 | |
| 986 | 1039 | // Add our email back to the queue, manually. |
| 987 | 1040 | $smcFunc['db_insert']('insert', |
@@ -994,8 +1047,8 @@ discard block |
||
| 994 | 1047 | return false; |
| 995 | 1048 | } |
| 996 | 1049 | // We where unable to send the email, clear our failed attempts. |
| 997 | - elseif (!empty($modSettings['mail_failed_attempts'])) |
|
| 998 | - $smcFunc['db_query']('', ' |
|
| 1050 | + elseif (!empty($modSettings['mail_failed_attempts'])) { |
|
| 1051 | + $smcFunc['db_query']('', ' |
|
| 999 | 1052 | UPDATE {db_prefix}settings |
| 1000 | 1053 | SET value = {string:zero} |
| 1001 | 1054 | WHERE variable = {string:mail_failed_attempts}', |
@@ -1003,6 +1056,7 @@ discard block |
||
| 1003 | 1056 | 'zero' => '0', |
| 1004 | 1057 | 'mail_failed_attempts' => 'mail_failed_attempts', |
| 1005 | 1058 | )); |
| 1059 | + } |
|
| 1006 | 1060 | |
| 1007 | 1061 | // Had something to send... |
| 1008 | 1062 | return true; |
@@ -1019,16 +1073,18 @@ discard block |
||
| 1019 | 1073 | global $modSettings, $smcFunc; |
| 1020 | 1074 | |
| 1021 | 1075 | $task_query = ''; |
| 1022 | - if (!is_array($tasks)) |
|
| 1023 | - $tasks = array($tasks); |
|
| 1076 | + if (!is_array($tasks)) { |
|
| 1077 | + $tasks = array($tasks); |
|
| 1078 | + } |
|
| 1024 | 1079 | |
| 1025 | 1080 | // Actually have something passed? |
| 1026 | 1081 | if (!empty($tasks)) |
| 1027 | 1082 | { |
| 1028 | - if (!isset($tasks[0]) || is_numeric($tasks[0])) |
|
| 1029 | - $task_query = ' AND id_task IN ({array_int:tasks})'; |
|
| 1030 | - else |
|
| 1031 | - $task_query = ' AND task IN ({array_string:tasks})'; |
|
| 1083 | + if (!isset($tasks[0]) || is_numeric($tasks[0])) { |
|
| 1084 | + $task_query = ' AND id_task IN ({array_int:tasks})'; |
|
| 1085 | + } else { |
|
| 1086 | + $task_query = ' AND task IN ({array_string:tasks})'; |
|
| 1087 | + } |
|
| 1032 | 1088 | } |
| 1033 | 1089 | $nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time']; |
| 1034 | 1090 | |
@@ -1049,20 +1105,22 @@ discard block |
||
| 1049 | 1105 | $next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']); |
| 1050 | 1106 | |
| 1051 | 1107 | // Only bother moving the task if it's out of place or we're forcing it! |
| 1052 | - if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) |
|
| 1053 | - $tasks[$row['id_task']] = $next_time; |
|
| 1054 | - else |
|
| 1055 | - $next_time = $row['next_time']; |
|
| 1108 | + if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) { |
|
| 1109 | + $tasks[$row['id_task']] = $next_time; |
|
| 1110 | + } else { |
|
| 1111 | + $next_time = $row['next_time']; |
|
| 1112 | + } |
|
| 1056 | 1113 | |
| 1057 | 1114 | // If this is sooner than the current next task, make this the next task. |
| 1058 | - if ($next_time < $nextTaskTime) |
|
| 1059 | - $nextTaskTime = $next_time; |
|
| 1115 | + if ($next_time < $nextTaskTime) { |
|
| 1116 | + $nextTaskTime = $next_time; |
|
| 1117 | + } |
|
| 1060 | 1118 | } |
| 1061 | 1119 | $smcFunc['db_free_result']($request); |
| 1062 | 1120 | |
| 1063 | 1121 | // Now make the changes! |
| 1064 | - foreach ($tasks as $id => $time) |
|
| 1065 | - $smcFunc['db_query']('', ' |
|
| 1122 | + foreach ($tasks as $id => $time) { |
|
| 1123 | + $smcFunc['db_query']('', ' |
|
| 1066 | 1124 | UPDATE {db_prefix}scheduled_tasks |
| 1067 | 1125 | SET next_time = {int:next_time} |
| 1068 | 1126 | WHERE id_task = {int:id_task}', |
@@ -1071,11 +1129,13 @@ discard block |
||
| 1071 | 1129 | 'id_task' => $id, |
| 1072 | 1130 | ) |
| 1073 | 1131 | ); |
| 1132 | + } |
|
| 1074 | 1133 | |
| 1075 | 1134 | // If the next task is now different update. |
| 1076 | - if ($modSettings['next_task_time'] != $nextTaskTime) |
|
| 1077 | - updateSettings(array('next_task_time' => $nextTaskTime)); |
|
| 1078 | -} |
|
| 1135 | + if ($modSettings['next_task_time'] != $nextTaskTime) { |
|
| 1136 | + updateSettings(array('next_task_time' => $nextTaskTime)); |
|
| 1137 | + } |
|
| 1138 | + } |
|
| 1079 | 1139 | |
| 1080 | 1140 | /** |
| 1081 | 1141 | * Simply returns a time stamp of the next instance of these time parameters. |
@@ -1088,8 +1148,9 @@ discard block |
||
| 1088 | 1148 | function next_time($regularity, $unit, $offset) |
| 1089 | 1149 | { |
| 1090 | 1150 | // Just in case! |
| 1091 | - if ($regularity == 0) |
|
| 1092 | - $regularity = 2; |
|
| 1151 | + if ($regularity == 0) { |
|
| 1152 | + $regularity = 2; |
|
| 1153 | + } |
|
| 1093 | 1154 | |
| 1094 | 1155 | $curMin = date('i', time()); |
| 1095 | 1156 | |
@@ -1099,15 +1160,16 @@ discard block |
||
| 1099 | 1160 | $off = date('i', $offset); |
| 1100 | 1161 | |
| 1101 | 1162 | // If it's now just pretend it ain't, |
| 1102 | - if ($off == $curMin) |
|
| 1103 | - $next_time = time() + $regularity; |
|
| 1104 | - else |
|
| 1163 | + if ($off == $curMin) { |
|
| 1164 | + $next_time = time() + $regularity; |
|
| 1165 | + } else |
|
| 1105 | 1166 | { |
| 1106 | 1167 | // Make sure that the offset is always in the past. |
| 1107 | 1168 | $off = $off > $curMin ? $off - 60 : $off; |
| 1108 | 1169 | |
| 1109 | - while ($off <= $curMin) |
|
| 1110 | - $off += $regularity; |
|
| 1170 | + while ($off <= $curMin) { |
|
| 1171 | + $off += $regularity; |
|
| 1172 | + } |
|
| 1111 | 1173 | |
| 1112 | 1174 | // Now we know when the time should be! |
| 1113 | 1175 | $next_time = time() + 60 * ($off - $curMin); |
@@ -1127,11 +1189,13 @@ discard block |
||
| 1127 | 1189 | // Default we'll jump in hours. |
| 1128 | 1190 | $applyOffset = 3600; |
| 1129 | 1191 | // 24 hours = 1 day. |
| 1130 | - if ($unit == 'd') |
|
| 1131 | - $applyOffset = 86400; |
|
| 1192 | + if ($unit == 'd') { |
|
| 1193 | + $applyOffset = 86400; |
|
| 1194 | + } |
|
| 1132 | 1195 | // Otherwise a week. |
| 1133 | - if ($unit == 'w') |
|
| 1134 | - $applyOffset = 604800; |
|
| 1196 | + if ($unit == 'w') { |
|
| 1197 | + $applyOffset = 604800; |
|
| 1198 | + } |
|
| 1135 | 1199 | |
| 1136 | 1200 | $applyOffset *= $regularity; |
| 1137 | 1201 | |
@@ -1168,8 +1232,9 @@ discard block |
||
| 1168 | 1232 | $settings[$row['variable']] = $row['value']; |
| 1169 | 1233 | |
| 1170 | 1234 | // Is this the default theme? |
| 1171 | - if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') |
|
| 1172 | - $settings['default_' . $row['variable']] = $row['value']; |
|
| 1235 | + if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') { |
|
| 1236 | + $settings['default_' . $row['variable']] = $row['value']; |
|
| 1237 | + } |
|
| 1173 | 1238 | } |
| 1174 | 1239 | $smcFunc['db_free_result']($result); |
| 1175 | 1240 | |
@@ -1179,12 +1244,14 @@ discard block |
||
| 1179 | 1244 | $settings['template_dirs'] = array($settings['theme_dir']); |
| 1180 | 1245 | |
| 1181 | 1246 | // Based on theme (if there is one). |
| 1182 | - if (!empty($settings['base_theme_dir'])) |
|
| 1183 | - $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
| 1247 | + if (!empty($settings['base_theme_dir'])) { |
|
| 1248 | + $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
| 1249 | + } |
|
| 1184 | 1250 | |
| 1185 | 1251 | // Lastly the default theme. |
| 1186 | - if ($settings['theme_dir'] != $settings['default_theme_dir']) |
|
| 1187 | - $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
| 1252 | + if ($settings['theme_dir'] != $settings['default_theme_dir']) { |
|
| 1253 | + $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
| 1254 | + } |
|
| 1188 | 1255 | } |
| 1189 | 1256 | |
| 1190 | 1257 | // Assume we want this. |
@@ -1330,8 +1397,9 @@ discard block |
||
| 1330 | 1397 | // Ok should we prune the logs? |
| 1331 | 1398 | if (!empty($modSettings['pruningOptions'])) |
| 1332 | 1399 | { |
| 1333 | - if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) |
|
| 1334 | - list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']); |
|
| 1400 | + if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) { |
|
| 1401 | + list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']); |
|
| 1402 | + } |
|
| 1335 | 1403 | |
| 1336 | 1404 | if (!empty($modSettings['pruneErrorLog'])) |
| 1337 | 1405 | { |
@@ -1397,8 +1465,9 @@ discard block |
||
| 1397 | 1465 | ) |
| 1398 | 1466 | ); |
| 1399 | 1467 | |
| 1400 | - while ($row = $smcFunc['db_fetch_row']($result)) |
|
| 1401 | - $reports[] = $row[0]; |
|
| 1468 | + while ($row = $smcFunc['db_fetch_row']($result)) { |
|
| 1469 | + $reports[] = $row[0]; |
|
| 1470 | + } |
|
| 1402 | 1471 | |
| 1403 | 1472 | $smcFunc['db_free_result']($result); |
| 1404 | 1473 | |
@@ -1560,8 +1629,9 @@ discard block |
||
| 1560 | 1629 | $emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']); |
| 1561 | 1630 | |
| 1562 | 1631 | // Send the actual email. |
| 1563 | - if ($notifyPrefs[$row['id_member']] & 0x02) |
|
| 1564 | - sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2); |
|
| 1632 | + if ($notifyPrefs[$row['id_member']] & 0x02) { |
|
| 1633 | + sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2); |
|
| 1634 | + } |
|
| 1565 | 1635 | |
| 1566 | 1636 | if ($notifyPrefs[$row['id_member']] & 0x01) |
| 1567 | 1637 | { |
@@ -1584,18 +1654,19 @@ discard block |
||
| 1584 | 1654 | } |
| 1585 | 1655 | |
| 1586 | 1656 | // Insert the alerts if any |
| 1587 | - if (!empty($alert_rows)) |
|
| 1588 | - $smcFunc['db_insert']('', |
|
| 1657 | + if (!empty($alert_rows)) { |
|
| 1658 | + $smcFunc['db_insert']('', |
|
| 1589 | 1659 | '{db_prefix}user_alerts', |
| 1590 | 1660 | array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string', |
| 1591 | 1661 | 'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'), |
| 1592 | 1662 | $alert_rows, |
| 1593 | 1663 | array() |
| 1594 | 1664 | ); |
| 1665 | + } |
|
| 1595 | 1666 | |
| 1596 | 1667 | // Mark the reminder as sent. |
| 1597 | - if (!empty($subs_reminded)) |
|
| 1598 | - $smcFunc['db_query']('', ' |
|
| 1668 | + if (!empty($subs_reminded)) { |
|
| 1669 | + $smcFunc['db_query']('', ' |
|
| 1599 | 1670 | UPDATE {db_prefix}log_subscribed |
| 1600 | 1671 | SET reminder_sent = {int:reminder_sent} |
| 1601 | 1672 | WHERE id_sublog IN ({array_int:subscription_list})', |
@@ -1604,6 +1675,7 @@ discard block |
||
| 1604 | 1675 | 'reminder_sent' => 1, |
| 1605 | 1676 | ) |
| 1606 | 1677 | ); |
| 1678 | + } |
|
| 1607 | 1679 | |
| 1608 | 1680 | return true; |
| 1609 | 1681 | } |
@@ -1619,13 +1691,13 @@ discard block |
||
| 1619 | 1691 | // We need to know where this thing is going. |
| 1620 | 1692 | if (!empty($modSettings['currentAttachmentUploadDir'])) |
| 1621 | 1693 | { |
| 1622 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
| 1623 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 1694 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
| 1695 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 1696 | + } |
|
| 1624 | 1697 | |
| 1625 | 1698 | // Just use the current path for temp files. |
| 1626 | 1699 | $attach_dirs = $modSettings['attachmentUploadDir']; |
| 1627 | - } |
|
| 1628 | - else |
|
| 1700 | + } else |
|
| 1629 | 1701 | { |
| 1630 | 1702 | $attach_dirs = array($modSettings['attachmentUploadDir']); |
| 1631 | 1703 | } |
@@ -1644,14 +1716,16 @@ discard block |
||
| 1644 | 1716 | |
| 1645 | 1717 | while ($file = readdir($dir)) |
| 1646 | 1718 | { |
| 1647 | - if ($file == '.' || $file == '..') |
|
| 1648 | - continue; |
|
| 1719 | + if ($file == '.' || $file == '..') { |
|
| 1720 | + continue; |
|
| 1721 | + } |
|
| 1649 | 1722 | |
| 1650 | 1723 | if (strpos($file, 'post_tmp_') !== false) |
| 1651 | 1724 | { |
| 1652 | 1725 | // Temp file is more than 5 hours old! |
| 1653 | - if (filemtime($attach_dir . '/' . $file) < time() - 18000) |
|
| 1654 | - @unlink($attach_dir . '/' . $file); |
|
| 1726 | + if (filemtime($attach_dir . '/' . $file) < time() - 18000) { |
|
| 1727 | + @unlink($attach_dir . '/' . $file); |
|
| 1728 | + } |
|
| 1655 | 1729 | } |
| 1656 | 1730 | } |
| 1657 | 1731 | closedir($dir); |
@@ -1684,8 +1758,9 @@ discard block |
||
| 1684 | 1758 | ) |
| 1685 | 1759 | ); |
| 1686 | 1760 | |
| 1687 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 1688 | - $topics[] = $row[0]; |
|
| 1761 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 1762 | + $topics[] = $row[0]; |
|
| 1763 | + } |
|
| 1689 | 1764 | $smcFunc['db_free_result']($request); |
| 1690 | 1765 | |
| 1691 | 1766 | // Zap, your gone |
@@ -1705,8 +1780,9 @@ discard block |
||
| 1705 | 1780 | { |
| 1706 | 1781 | global $smcFunc, $sourcedir, $modSettings; |
| 1707 | 1782 | |
| 1708 | - if (empty($modSettings['drafts_keep_days'])) |
|
| 1709 | - return true; |
|
| 1783 | + if (empty($modSettings['drafts_keep_days'])) { |
|
| 1784 | + return true; |
|
| 1785 | + } |
|
| 1710 | 1786 | |
| 1711 | 1787 | // init |
| 1712 | 1788 | $drafts = array(); |
@@ -1724,8 +1800,9 @@ discard block |
||
| 1724 | 1800 | ) |
| 1725 | 1801 | ); |
| 1726 | 1802 | |
| 1727 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 1728 | - $drafts[] = (int) $row[0]; |
|
| 1803 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 1804 | + $drafts[] = (int) $row[0]; |
|
| 1805 | + } |
|
| 1729 | 1806 | $smcFunc['db_free_result']($request); |
| 1730 | 1807 | |
| 1731 | 1808 | // If we have old one, remove them |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * This file contains helper functions for upgrade.php |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF_VERSION')) |
|
| 16 | +if (!defined('SMF_VERSION')) { |
|
| 17 | 17 | die('No direct access!'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Clean the cache using the SMF 2.1 CacheAPI. |
@@ -45,8 +46,9 @@ discard block |
||
| 45 | 46 | global $smcFunc; |
| 46 | 47 | static $member_groups = array(); |
| 47 | 48 | |
| 48 | - if (!empty($member_groups)) |
|
| 49 | - return $member_groups; |
|
| 49 | + if (!empty($member_groups)) { |
|
| 50 | + return $member_groups; |
|
| 51 | + } |
|
| 50 | 52 | |
| 51 | 53 | $request = $smcFunc['db_query']('', ' |
| 52 | 54 | SELECT group_name, id_group |
@@ -71,8 +73,9 @@ discard block |
||
| 71 | 73 | ) |
| 72 | 74 | ); |
| 73 | 75 | } |
| 74 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 75 | - $member_groups[trim($row[0])] = $row[1]; |
|
| 76 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 77 | + $member_groups[trim($row[0])] = $row[1]; |
|
| 78 | + } |
|
| 76 | 79 | $smcFunc['db_free_result']($request); |
| 77 | 80 | |
| 78 | 81 | return $member_groups; |
@@ -88,8 +91,9 @@ discard block |
||
| 88 | 91 | { |
| 89 | 92 | global $upcontext, $boarddir, $sourcedir; |
| 90 | 93 | |
| 91 | - if (empty($files)) |
|
| 92 | - return true; |
|
| 94 | + if (empty($files)) { |
|
| 95 | + return true; |
|
| 96 | + } |
|
| 93 | 97 | |
| 94 | 98 | $failure = false; |
| 95 | 99 | // On linux, it's easy - just use is_writable! |
@@ -104,14 +108,16 @@ discard block |
||
| 104 | 108 | @chmod($file, 0755); |
| 105 | 109 | |
| 106 | 110 | // Well, 755 hopefully worked... if not, try 777. |
| 107 | - if (!is_writable($file) && !@chmod($file, 0777)) |
|
| 108 | - $failure = true; |
|
| 111 | + if (!is_writable($file) && !@chmod($file, 0777)) { |
|
| 112 | + $failure = true; |
|
| 113 | + } |
|
| 109 | 114 | // Otherwise remove it as it's good! |
| 110 | - else |
|
| 111 | - unset($files[$k]); |
|
| 115 | + else { |
|
| 116 | + unset($files[$k]); |
|
| 117 | + } |
|
| 118 | + } else { |
|
| 119 | + unset($files[$k]); |
|
| 112 | 120 | } |
| 113 | - else |
|
| 114 | - unset($files[$k]); |
|
| 115 | 121 | } |
| 116 | 122 | } |
| 117 | 123 | // Windows is trickier. Let's try opening for r+... |
@@ -122,30 +128,35 @@ discard block |
||
| 122 | 128 | foreach ($files as $k => $file) |
| 123 | 129 | { |
| 124 | 130 | // Folders can't be opened for write... but the index.php in them can ;). |
| 125 | - if (is_dir($file)) |
|
| 126 | - $file .= '/index.php'; |
|
| 131 | + if (is_dir($file)) { |
|
| 132 | + $file .= '/index.php'; |
|
| 133 | + } |
|
| 127 | 134 | |
| 128 | 135 | // Funny enough, chmod actually does do something on windows - it removes the read only attribute. |
| 129 | 136 | @chmod($file, 0777); |
| 130 | 137 | $fp = @fopen($file, 'r+'); |
| 131 | 138 | |
| 132 | 139 | // Hmm, okay, try just for write in that case... |
| 133 | - if (!$fp) |
|
| 134 | - $fp = @fopen($file, 'w'); |
|
| 140 | + if (!$fp) { |
|
| 141 | + $fp = @fopen($file, 'w'); |
|
| 142 | + } |
|
| 135 | 143 | |
| 136 | - if (!$fp) |
|
| 137 | - $failure = true; |
|
| 138 | - else |
|
| 139 | - unset($files[$k]); |
|
| 144 | + if (!$fp) { |
|
| 145 | + $failure = true; |
|
| 146 | + } else { |
|
| 147 | + unset($files[$k]); |
|
| 148 | + } |
|
| 140 | 149 | @fclose($fp); |
| 141 | 150 | } |
| 142 | 151 | } |
| 143 | 152 | |
| 144 | - if (empty($files)) |
|
| 145 | - return true; |
|
| 153 | + if (empty($files)) { |
|
| 154 | + return true; |
|
| 155 | + } |
|
| 146 | 156 | |
| 147 | - if (!isset($_SERVER)) |
|
| 148 | - return !$failure; |
|
| 157 | + if (!isset($_SERVER)) { |
|
| 158 | + return !$failure; |
|
| 159 | + } |
|
| 149 | 160 | |
| 150 | 161 | // What still needs to be done? |
| 151 | 162 | $upcontext['chmod']['files'] = $files; |
@@ -197,36 +208,40 @@ discard block |
||
| 197 | 208 | |
| 198 | 209 | if (!isset($ftp) || $ftp->error !== false) |
| 199 | 210 | { |
| 200 | - if (!isset($ftp)) |
|
| 201 | - $ftp = new ftp_connection(null); |
|
| 211 | + if (!isset($ftp)) { |
|
| 212 | + $ftp = new ftp_connection(null); |
|
| 213 | + } |
|
| 202 | 214 | // Save the error so we can mess with listing... |
| 203 | - elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) |
|
| 204 | - $upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 215 | + elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) { |
|
| 216 | + $upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 217 | + } |
|
| 205 | 218 | |
| 206 | 219 | list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__)); |
| 207 | 220 | |
| 208 | - if ($found_path || !isset($upcontext['chmod']['path'])) |
|
| 209 | - $upcontext['chmod']['path'] = $detect_path; |
|
| 221 | + if ($found_path || !isset($upcontext['chmod']['path'])) { |
|
| 222 | + $upcontext['chmod']['path'] = $detect_path; |
|
| 223 | + } |
|
| 210 | 224 | |
| 211 | - if (!isset($upcontext['chmod']['username'])) |
|
| 212 | - $upcontext['chmod']['username'] = $username; |
|
| 225 | + if (!isset($upcontext['chmod']['username'])) { |
|
| 226 | + $upcontext['chmod']['username'] = $username; |
|
| 227 | + } |
|
| 213 | 228 | |
| 214 | 229 | // Don't forget the login token. |
| 215 | 230 | $upcontext += createToken('login'); |
| 216 | 231 | |
| 217 | 232 | return false; |
| 218 | - } |
|
| 219 | - else |
|
| 233 | + } else |
|
| 220 | 234 | { |
| 221 | 235 | // We want to do a relative path for FTP. |
| 222 | 236 | if (!in_array($upcontext['chmod']['path'], array('', '/'))) |
| 223 | 237 | { |
| 224 | 238 | $ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => '')); |
| 225 | - if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) |
|
| 226 | - $ftp_root = substr($ftp_root, 0, -1); |
|
| 239 | + if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) { |
|
| 240 | + $ftp_root = substr($ftp_root, 0, -1); |
|
| 241 | + } |
|
| 242 | + } else { |
|
| 243 | + $ftp_root = $boarddir; |
|
| 227 | 244 | } |
| 228 | - else |
|
| 229 | - $ftp_root = $boarddir; |
|
| 230 | 245 | |
| 231 | 246 | // Save the info for next time! |
| 232 | 247 | $_SESSION['installer_temp_ftp'] = array( |
@@ -240,10 +255,12 @@ discard block |
||
| 240 | 255 | |
| 241 | 256 | foreach ($files as $k => $file) |
| 242 | 257 | { |
| 243 | - if (!is_writable($file)) |
|
| 244 | - $ftp->chmod($file, 0755); |
|
| 245 | - if (!is_writable($file)) |
|
| 246 | - $ftp->chmod($file, 0777); |
|
| 258 | + if (!is_writable($file)) { |
|
| 259 | + $ftp->chmod($file, 0755); |
|
| 260 | + } |
|
| 261 | + if (!is_writable($file)) { |
|
| 262 | + $ftp->chmod($file, 0777); |
|
| 263 | + } |
|
| 247 | 264 | |
| 248 | 265 | // Assuming that didn't work calculate the path without the boarddir. |
| 249 | 266 | if (!is_writable($file)) |
@@ -252,19 +269,23 @@ discard block |
||
| 252 | 269 | { |
| 253 | 270 | $ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => '')); |
| 254 | 271 | $ftp->chmod($ftp_file, 0755); |
| 255 | - if (!is_writable($file)) |
|
| 256 | - $ftp->chmod($ftp_file, 0777); |
|
| 272 | + if (!is_writable($file)) { |
|
| 273 | + $ftp->chmod($ftp_file, 0777); |
|
| 274 | + } |
|
| 257 | 275 | // Sometimes an extra slash can help... |
| 258 | 276 | $ftp_file = '/' . $ftp_file; |
| 259 | - if (!is_writable($file)) |
|
| 260 | - $ftp->chmod($ftp_file, 0755); |
|
| 261 | - if (!is_writable($file)) |
|
| 262 | - $ftp->chmod($ftp_file, 0777); |
|
| 277 | + if (!is_writable($file)) { |
|
| 278 | + $ftp->chmod($ftp_file, 0755); |
|
| 279 | + } |
|
| 280 | + if (!is_writable($file)) { |
|
| 281 | + $ftp->chmod($ftp_file, 0777); |
|
| 282 | + } |
|
| 263 | 283 | } |
| 264 | 284 | } |
| 265 | 285 | |
| 266 | - if (is_writable($file)) |
|
| 267 | - unset($files[$k]); |
|
| 286 | + if (is_writable($file)) { |
|
| 287 | + unset($files[$k]); |
|
| 288 | + } |
|
| 268 | 289 | } |
| 269 | 290 | |
| 270 | 291 | $ftp->close(); |
@@ -274,8 +295,9 @@ discard block |
||
| 274 | 295 | // What remains? |
| 275 | 296 | $upcontext['chmod']['files'] = $files; |
| 276 | 297 | |
| 277 | - if (empty($files)) |
|
| 278 | - return true; |
|
| 298 | + if (empty($files)) { |
|
| 299 | + return true; |
|
| 300 | + } |
|
| 279 | 301 | |
| 280 | 302 | return false; |
| 281 | 303 | } |
@@ -288,8 +310,9 @@ discard block |
||
| 288 | 310 | */ |
| 289 | 311 | function quickFileWritable($file) |
| 290 | 312 | { |
| 291 | - if (is_writable($file)) |
|
| 292 | - return true; |
|
| 313 | + if (is_writable($file)) { |
|
| 314 | + return true; |
|
| 315 | + } |
|
| 293 | 316 | |
| 294 | 317 | @chmod($file, 0755); |
| 295 | 318 | |
@@ -299,10 +322,11 @@ discard block |
||
| 299 | 322 | foreach ($chmod_values as $val) |
| 300 | 323 | { |
| 301 | 324 | // If it's writable, break out of the loop |
| 302 | - if (is_writable($file)) |
|
| 303 | - break; |
|
| 304 | - else |
|
| 305 | - @chmod($file, $val); |
|
| 325 | + if (is_writable($file)) { |
|
| 326 | + break; |
|
| 327 | + } else { |
|
| 328 | + @chmod($file, $val); |
|
| 329 | + } |
|
| 306 | 330 | } |
| 307 | 331 | |
| 308 | 332 | return is_writable($file); |
@@ -329,14 +353,16 @@ discard block |
||
| 329 | 353 | { |
| 330 | 354 | static $fp = null; |
| 331 | 355 | |
| 332 | - if ($fp === null) |
|
| 333 | - $fp = fopen('php://stderr', 'wb'); |
|
| 356 | + if ($fp === null) { |
|
| 357 | + $fp = fopen('php://stderr', 'wb'); |
|
| 358 | + } |
|
| 334 | 359 | |
| 335 | 360 | fwrite($fp, $message . "\n"); |
| 336 | 361 | |
| 337 | - if ($fatal) |
|
| 338 | - exit; |
|
| 339 | -} |
|
| 362 | + if ($fatal) { |
|
| 363 | + exit; |
|
| 364 | + } |
|
| 365 | + } |
|
| 340 | 366 | |
| 341 | 367 | /** |
| 342 | 368 | * Throws a graphical error message. |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 3 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Check if the current directory is still valid or not. |
@@ -28,22 +29,24 @@ discard block |
||
| 28 | 29 | global $boarddir, $modSettings, $context; |
| 29 | 30 | |
| 30 | 31 | // Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found. |
| 31 | - if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') |
|
| 32 | - $doit = true; |
|
| 33 | - elseif (empty($modSettings['automanage_attachments'])) |
|
| 34 | - return; |
|
| 35 | - elseif (!isset($_FILES)) |
|
| 36 | - return; |
|
| 37 | - elseif (isset($_FILES['attachment'])) |
|
| 38 | - foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
| 32 | + if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') { |
|
| 33 | + $doit = true; |
|
| 34 | + } elseif (empty($modSettings['automanage_attachments'])) { |
|
| 35 | + return; |
|
| 36 | + } elseif (!isset($_FILES)) { |
|
| 37 | + return; |
|
| 38 | + } elseif (isset($_FILES['attachment'])) { |
|
| 39 | + foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
| 39 | 40 | if (!empty($dummy)) |
| 40 | 41 | { |
| 41 | 42 | $doit = true; |
| 43 | + } |
|
| 42 | 44 | break; |
| 43 | 45 | } |
| 44 | 46 | |
| 45 | - if (!isset($doit)) |
|
| 46 | - return; |
|
| 47 | + if (!isset($doit)) { |
|
| 48 | + return; |
|
| 49 | + } |
|
| 47 | 50 | |
| 48 | 51 | $year = date('Y'); |
| 49 | 52 | $month = date('m'); |
@@ -54,21 +57,25 @@ discard block |
||
| 54 | 57 | |
| 55 | 58 | if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments'])) |
| 56 | 59 | { |
| 57 | - if (!is_array($modSettings['attachment_basedirectories'])) |
|
| 58 | - $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 60 | + if (!is_array($modSettings['attachment_basedirectories'])) { |
|
| 61 | + $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 62 | + } |
|
| 59 | 63 | $base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']); |
| 64 | + } else { |
|
| 65 | + $base_dir = 0; |
|
| 60 | 66 | } |
| 61 | - else |
|
| 62 | - $base_dir = 0; |
|
| 63 | 67 | |
| 64 | 68 | if ($modSettings['automanage_attachments'] == 1) |
| 65 | 69 | { |
| 66 | - if (!isset($modSettings['last_attachments_directory'])) |
|
| 67 | - $modSettings['last_attachments_directory'] = array(); |
|
| 68 | - if (!is_array($modSettings['last_attachments_directory'])) |
|
| 69 | - $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
| 70 | - if (!isset($modSettings['last_attachments_directory'][$base_dir])) |
|
| 71 | - $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
| 70 | + if (!isset($modSettings['last_attachments_directory'])) { |
|
| 71 | + $modSettings['last_attachments_directory'] = array(); |
|
| 72 | + } |
|
| 73 | + if (!is_array($modSettings['last_attachments_directory'])) { |
|
| 74 | + $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
| 75 | + } |
|
| 76 | + if (!isset($modSettings['last_attachments_directory'][$base_dir])) { |
|
| 77 | + $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
| 78 | + } |
|
| 72 | 79 | } |
| 73 | 80 | |
| 74 | 81 | $basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
@@ -97,12 +104,14 @@ discard block |
||
| 97 | 104 | $updir = ''; |
| 98 | 105 | } |
| 99 | 106 | |
| 100 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
| 101 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 102 | - if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) |
|
| 103 | - $outputCreation = automanage_attachments_create_directory($updir); |
|
| 104 | - elseif (in_array($updir, $modSettings['attachmentUploadDir'])) |
|
| 105 | - $outputCreation = true; |
|
| 107 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
| 108 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 109 | + } |
|
| 110 | + if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) { |
|
| 111 | + $outputCreation = automanage_attachments_create_directory($updir); |
|
| 112 | + } elseif (in_array($updir, $modSettings['attachmentUploadDir'])) { |
|
| 113 | + $outputCreation = true; |
|
| 114 | + } |
|
| 106 | 115 | |
| 107 | 116 | if ($outputCreation) |
| 108 | 117 | { |
@@ -139,8 +148,9 @@ discard block |
||
| 139 | 148 | $count = count($tree); |
| 140 | 149 | |
| 141 | 150 | $directory = attachments_init_dir($tree, $count); |
| 142 | - if ($directory === false) |
|
| 143 | - return false; |
|
| 151 | + if ($directory === false) { |
|
| 152 | + return false; |
|
| 153 | + } |
|
| 144 | 154 | } |
| 145 | 155 | |
| 146 | 156 | $directory .= DIRECTORY_SEPARATOR . array_shift($tree); |
@@ -168,8 +178,9 @@ discard block |
||
| 168 | 178 | } |
| 169 | 179 | |
| 170 | 180 | // Everything seems fine...let's create the .htaccess |
| 171 | - if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) |
|
| 172 | - secureDirectory($updir, true); |
|
| 181 | + if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) { |
|
| 182 | + secureDirectory($updir, true); |
|
| 183 | + } |
|
| 173 | 184 | |
| 174 | 185 | $sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR; |
| 175 | 186 | $updir = rtrim($updir, $sep); |
@@ -201,8 +212,9 @@ discard block |
||
| 201 | 212 | { |
| 202 | 213 | global $modSettings, $boarddir; |
| 203 | 214 | |
| 204 | - if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) |
|
| 205 | - return; |
|
| 215 | + if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) { |
|
| 216 | + return; |
|
| 217 | + } |
|
| 206 | 218 | |
| 207 | 219 | $basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir; |
| 208 | 220 | // Just to be sure: I don't want directory separators at the end |
@@ -214,13 +226,14 @@ discard block |
||
| 214 | 226 | { |
| 215 | 227 | $base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']); |
| 216 | 228 | $base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0; |
| 229 | + } else { |
|
| 230 | + $base_dir = 0; |
|
| 217 | 231 | } |
| 218 | - else |
|
| 219 | - $base_dir = 0; |
|
| 220 | 232 | |
| 221 | 233 | // Get the last attachment directory for that base directory |
| 222 | - if (empty($modSettings['last_attachments_directory'][$base_dir])) |
|
| 223 | - $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
| 234 | + if (empty($modSettings['last_attachments_directory'][$base_dir])) { |
|
| 235 | + $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
| 236 | + } |
|
| 224 | 237 | // And increment it. |
| 225 | 238 | $modSettings['last_attachments_directory'][$base_dir]++; |
| 226 | 239 | |
@@ -235,10 +248,10 @@ discard block |
||
| 235 | 248 | $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
| 236 | 249 | |
| 237 | 250 | return true; |
| 251 | + } else { |
|
| 252 | + return false; |
|
| 253 | + } |
|
| 238 | 254 | } |
| 239 | - else |
|
| 240 | - return false; |
|
| 241 | -} |
|
| 242 | 255 | |
| 243 | 256 | /** |
| 244 | 257 | * Split a path into a list of all directories and subdirectories |
@@ -256,12 +269,13 @@ discard block |
||
| 256 | 269 | * in Windows we need to explode for both \ and / |
| 257 | 270 | * while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR) |
| 258 | 271 | */ |
| 259 | - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') |
|
| 260 | - $tree = preg_split('#[\\\/]#', $directory); |
|
| 261 | - else |
|
| 272 | + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
| 273 | + $tree = preg_split('#[\\\/]#', $directory); |
|
| 274 | + } else |
|
| 262 | 275 | { |
| 263 | - if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) |
|
| 264 | - return false; |
|
| 276 | + if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) { |
|
| 277 | + return false; |
|
| 278 | + } |
|
| 265 | 279 | |
| 266 | 280 | $tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR)); |
| 267 | 281 | } |
@@ -285,10 +299,11 @@ discard block |
||
| 285 | 299 | //Better be sure that the first part of the path is actually a drive letter... |
| 286 | 300 | //...even if, I should check this in the admin page...isn't it? |
| 287 | 301 | //...NHAAA Let's leave space for users' complains! :P |
| 288 | - if (preg_match('/^[a-z]:$/i', $tree[0])) |
|
| 289 | - $directory = array_shift($tree); |
|
| 290 | - else |
|
| 291 | - return false; |
|
| 302 | + if (preg_match('/^[a-z]:$/i', $tree[0])) { |
|
| 303 | + $directory = array_shift($tree); |
|
| 304 | + } else { |
|
| 305 | + return false; |
|
| 306 | + } |
|
| 292 | 307 | |
| 293 | 308 | $count--; |
| 294 | 309 | } |
@@ -303,18 +318,20 @@ discard block |
||
| 303 | 318 | global $context, $modSettings, $smcFunc, $txt, $user_info; |
| 304 | 319 | |
| 305 | 320 | // Make sure we're uploading to the right place. |
| 306 | - if (!empty($modSettings['automanage_attachments'])) |
|
| 307 | - automanage_attachments_check_directory(); |
|
| 321 | + if (!empty($modSettings['automanage_attachments'])) { |
|
| 322 | + automanage_attachments_check_directory(); |
|
| 323 | + } |
|
| 308 | 324 | |
| 309 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
| 310 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 325 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
| 326 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 327 | + } |
|
| 311 | 328 | |
| 312 | 329 | $context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
| 313 | 330 | |
| 314 | 331 | // Is the attachments folder actualy there? |
| 315 | - if (!empty($context['dir_creation_error'])) |
|
| 316 | - $initial_error = $context['dir_creation_error']; |
|
| 317 | - elseif (!is_dir($context['attach_dir'])) |
|
| 332 | + if (!empty($context['dir_creation_error'])) { |
|
| 333 | + $initial_error = $context['dir_creation_error']; |
|
| 334 | + } elseif (!is_dir($context['attach_dir'])) |
|
| 318 | 335 | { |
| 319 | 336 | $initial_error = 'attach_folder_warning'; |
| 320 | 337 | log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical'); |
@@ -337,12 +354,12 @@ discard block |
||
| 337 | 354 | ); |
| 338 | 355 | list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request); |
| 339 | 356 | $smcFunc['db_free_result']($request); |
| 340 | - } |
|
| 341 | - else |
|
| 342 | - $context['attachments'] = array( |
|
| 357 | + } else { |
|
| 358 | + $context['attachments'] = array( |
|
| 343 | 359 | 'quantity' => 0, |
| 344 | 360 | 'total_size' => 0, |
| 345 | 361 | ); |
| 362 | + } |
|
| 346 | 363 | } |
| 347 | 364 | |
| 348 | 365 | // Hmm. There are still files in session. |
@@ -352,39 +369,44 @@ discard block |
||
| 352 | 369 | // Let's try to keep them. But... |
| 353 | 370 | $ignore_temp = true; |
| 354 | 371 | // If new files are being added. We can't ignore those |
| 355 | - foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
| 356 | - if (!empty($dummy)) |
|
| 372 | + foreach ($_FILES['attachment']['tmp_name'] as $dummy) { |
|
| 373 | + if (!empty($dummy)) |
|
| 357 | 374 | { |
| 358 | 375 | $ignore_temp = false; |
| 376 | + } |
|
| 359 | 377 | break; |
| 360 | 378 | } |
| 361 | 379 | |
| 362 | 380 | // Need to make space for the new files. So, bye bye. |
| 363 | 381 | if (!$ignore_temp) |
| 364 | 382 | { |
| 365 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
| 366 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
| 383 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) { |
|
| 384 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
| 367 | 385 | unlink($attachment['tmp_name']); |
| 386 | + } |
|
| 368 | 387 | |
| 369 | 388 | $context['we_are_history'] = $txt['error_temp_attachments_flushed']; |
| 370 | 389 | $_SESSION['temp_attachments'] = array(); |
| 371 | 390 | } |
| 372 | 391 | } |
| 373 | 392 | |
| 374 | - if (!isset($_FILES['attachment']['name'])) |
|
| 375 | - $_FILES['attachment']['tmp_name'] = array(); |
|
| 393 | + if (!isset($_FILES['attachment']['name'])) { |
|
| 394 | + $_FILES['attachment']['tmp_name'] = array(); |
|
| 395 | + } |
|
| 376 | 396 | |
| 377 | - if (!isset($_SESSION['temp_attachments'])) |
|
| 378 | - $_SESSION['temp_attachments'] = array(); |
|
| 397 | + if (!isset($_SESSION['temp_attachments'])) { |
|
| 398 | + $_SESSION['temp_attachments'] = array(); |
|
| 399 | + } |
|
| 379 | 400 | |
| 380 | 401 | // Remember where we are at. If it's anywhere at all. |
| 381 | - if (!$ignore_temp) |
|
| 382 | - $_SESSION['temp_attachments']['post'] = array( |
|
| 402 | + if (!$ignore_temp) { |
|
| 403 | + $_SESSION['temp_attachments']['post'] = array( |
|
| 383 | 404 | 'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0, |
| 384 | 405 | 'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0, |
| 385 | 406 | 'topic' => !empty($topic) ? $topic : 0, |
| 386 | 407 | 'board' => !empty($board) ? $board : 0, |
| 387 | 408 | ); |
| 409 | + } |
|
| 388 | 410 | |
| 389 | 411 | // If we have an initial error, lets just display it. |
| 390 | 412 | if (!empty($initial_error)) |
@@ -392,9 +414,10 @@ discard block |
||
| 392 | 414 | $_SESSION['temp_attachments']['initial_error'] = $initial_error; |
| 393 | 415 | |
| 394 | 416 | // And delete the files 'cos they ain't going nowhere. |
| 395 | - foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
|
| 396 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 417 | + foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) { |
|
| 418 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 397 | 419 | unlink($_FILES['attachment']['tmp_name'][$n]); |
| 420 | + } |
|
| 398 | 421 | |
| 399 | 422 | $_FILES['attachment']['tmp_name'] = array(); |
| 400 | 423 | } |
@@ -402,21 +425,24 @@ discard block |
||
| 402 | 425 | // Loop through $_FILES['attachment'] array and move each file to the current attachments folder. |
| 403 | 426 | foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
| 404 | 427 | { |
| 405 | - if ($_FILES['attachment']['name'][$n] == '') |
|
| 406 | - continue; |
|
| 428 | + if ($_FILES['attachment']['name'][$n] == '') { |
|
| 429 | + continue; |
|
| 430 | + } |
|
| 407 | 431 | |
| 408 | 432 | // First, let's first check for PHP upload errors. |
| 409 | 433 | $errors = array(); |
| 410 | 434 | if (!empty($_FILES['attachment']['error'][$n])) |
| 411 | 435 | { |
| 412 | - if ($_FILES['attachment']['error'][$n] == 2) |
|
| 413 | - $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
| 414 | - elseif ($_FILES['attachment']['error'][$n] == 6) |
|
| 415 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
| 416 | - else |
|
| 417 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
| 418 | - if (empty($errors)) |
|
| 419 | - $errors[] = 'attach_php_error'; |
|
| 436 | + if ($_FILES['attachment']['error'][$n] == 2) { |
|
| 437 | + $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
| 438 | + } elseif ($_FILES['attachment']['error'][$n] == 6) { |
|
| 439 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
| 440 | + } else { |
|
| 441 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
| 442 | + } |
|
| 443 | + if (empty($errors)) { |
|
| 444 | + $errors[] = 'attach_php_error'; |
|
| 445 | + } |
|
| 420 | 446 | } |
| 421 | 447 | |
| 422 | 448 | // Try to move and rename the file before doing any more checks on it. |
@@ -426,8 +452,9 @@ discard block |
||
| 426 | 452 | { |
| 427 | 453 | // The reported MIME type of the attachment might not be reliable. |
| 428 | 454 | // Fortunately, PHP 5.3+ lets us easily verify the real MIME type. |
| 429 | - if (function_exists('mime_content_type')) |
|
| 430 | - $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
| 455 | + if (function_exists('mime_content_type')) { |
|
| 456 | + $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
| 457 | + } |
|
| 431 | 458 | |
| 432 | 459 | $_SESSION['temp_attachments'][$attachID] = array( |
| 433 | 460 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -439,16 +466,16 @@ discard block |
||
| 439 | 466 | ); |
| 440 | 467 | |
| 441 | 468 | // Move the file to the attachments folder with a temp name for now. |
| 442 | - if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) |
|
| 443 | - smf_chmod($destName, 0644); |
|
| 444 | - else |
|
| 469 | + if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) { |
|
| 470 | + smf_chmod($destName, 0644); |
|
| 471 | + } else |
|
| 445 | 472 | { |
| 446 | 473 | $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout'; |
| 447 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 448 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 474 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
| 475 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 476 | + } |
|
| 449 | 477 | } |
| 450 | - } |
|
| 451 | - else |
|
| 478 | + } else |
|
| 452 | 479 | { |
| 453 | 480 | $_SESSION['temp_attachments'][$attachID] = array( |
| 454 | 481 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -456,12 +483,14 @@ discard block |
||
| 456 | 483 | 'errors' => $errors, |
| 457 | 484 | ); |
| 458 | 485 | |
| 459 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 460 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 486 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
| 487 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 488 | + } |
|
| 461 | 489 | } |
| 462 | 490 | // If there's no errors to this point. We still do need to apply some additional checks before we are finished. |
| 463 | - if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
|
| 464 | - attachmentChecks($attachID); |
|
| 491 | + if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) { |
|
| 492 | + attachmentChecks($attachID); |
|
| 493 | + } |
|
| 465 | 494 | } |
| 466 | 495 | // Mod authors, finally a hook to hang an alternate attachment upload system upon |
| 467 | 496 | // Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand()) |
@@ -488,21 +517,20 @@ discard block |
||
| 488 | 517 | global $modSettings, $context, $sourcedir, $smcFunc; |
| 489 | 518 | |
| 490 | 519 | // No data or missing data .... Not necessarily needed, but in case a mod author missed something. |
| 491 | - if (empty($_SESSION['temp_attachments'][$attachID])) |
|
| 492 | - $error = '$_SESSION[\'temp_attachments\'][$attachID]'; |
|
| 493 | - |
|
| 494 | - elseif (empty($attachID)) |
|
| 495 | - $error = '$attachID'; |
|
| 496 | - |
|
| 497 | - elseif (empty($context['attachments'])) |
|
| 498 | - $error = '$context[\'attachments\']'; |
|
| 499 | - |
|
| 500 | - elseif (empty($context['attach_dir'])) |
|
| 501 | - $error = '$context[\'attach_dir\']'; |
|
| 520 | + if (empty($_SESSION['temp_attachments'][$attachID])) { |
|
| 521 | + $error = '$_SESSION[\'temp_attachments\'][$attachID]'; |
|
| 522 | + } elseif (empty($attachID)) { |
|
| 523 | + $error = '$attachID'; |
|
| 524 | + } elseif (empty($context['attachments'])) { |
|
| 525 | + $error = '$context[\'attachments\']'; |
|
| 526 | + } elseif (empty($context['attach_dir'])) { |
|
| 527 | + $error = '$context[\'attach_dir\']'; |
|
| 528 | + } |
|
| 502 | 529 | |
| 503 | 530 | // Let's get their attention. |
| 504 | - if (!empty($error)) |
|
| 505 | - fatal_lang_error('attach_check_nag', 'debug', array($error)); |
|
| 531 | + if (!empty($error)) { |
|
| 532 | + fatal_lang_error('attach_check_nag', 'debug', array($error)); |
|
| 533 | + } |
|
| 506 | 534 | |
| 507 | 535 | // Just in case this slipped by the first checks, we stop it here and now |
| 508 | 536 | if ($_SESSION['temp_attachments'][$attachID]['size'] == 0) |
@@ -531,8 +559,9 @@ discard block |
||
| 531 | 559 | $size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']); |
| 532 | 560 | if (!(empty($size)) && ($size[2] != $old_format)) |
| 533 | 561 | { |
| 534 | - if (isset($context['validImageTypes'][$size[2]])) |
|
| 535 | - $_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
| 562 | + if (isset($context['validImageTypes'][$size[2]])) { |
|
| 563 | + $_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
| 564 | + } |
|
| 536 | 565 | } |
| 537 | 566 | } |
| 538 | 567 | } |
@@ -586,42 +615,48 @@ discard block |
||
| 586 | 615 | // Or, let the user know that it ain't gonna happen. |
| 587 | 616 | else |
| 588 | 617 | { |
| 589 | - if (isset($context['dir_creation_error'])) |
|
| 590 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error']; |
|
| 591 | - else |
|
| 592 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
| 618 | + if (isset($context['dir_creation_error'])) { |
|
| 619 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error']; |
|
| 620 | + } else { |
|
| 621 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
| 622 | + } |
|
| 593 | 623 | } |
| 624 | + } else { |
|
| 625 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
| 594 | 626 | } |
| 595 | - else |
|
| 596 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
| 597 | 627 | } |
| 598 | 628 | } |
| 599 | 629 | |
| 600 | 630 | // Is the file too big? |
| 601 | 631 | $context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size']; |
| 602 | - if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) |
|
| 603 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0))); |
|
| 632 | + if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) { |
|
| 633 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0))); |
|
| 634 | + } |
|
| 604 | 635 | |
| 605 | 636 | // Check the total upload size for this post... |
| 606 | - if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) |
|
| 607 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0))); |
|
| 637 | + if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) { |
|
| 638 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0))); |
|
| 639 | + } |
|
| 608 | 640 | |
| 609 | 641 | // Have we reached the maximum number of files we are allowed? |
| 610 | 642 | $context['attachments']['quantity']++; |
| 611 | 643 | |
| 612 | 644 | // Set a max limit if none exists |
| 613 | - if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) |
|
| 614 | - $modSettings['attachmentNumPerPostLimit'] = 50; |
|
| 645 | + if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) { |
|
| 646 | + $modSettings['attachmentNumPerPostLimit'] = 50; |
|
| 647 | + } |
|
| 615 | 648 | |
| 616 | - if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) |
|
| 617 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit'])); |
|
| 649 | + if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) { |
|
| 650 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit'])); |
|
| 651 | + } |
|
| 618 | 652 | |
| 619 | 653 | // File extension check |
| 620 | 654 | if (!empty($modSettings['attachmentCheckExtensions'])) |
| 621 | 655 | { |
| 622 | 656 | $allowed = explode(',', strtolower($modSettings['attachmentExtensions'])); |
| 623 | - foreach ($allowed as $k => $dummy) |
|
| 624 | - $allowed[$k] = trim($dummy); |
|
| 657 | + foreach ($allowed as $k => $dummy) { |
|
| 658 | + $allowed[$k] = trim($dummy); |
|
| 659 | + } |
|
| 625 | 660 | |
| 626 | 661 | if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed)) |
| 627 | 662 | { |
@@ -633,10 +668,12 @@ discard block |
||
| 633 | 668 | // Undo the math if there's an error |
| 634 | 669 | if (!empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
| 635 | 670 | { |
| 636 | - if (isset($context['dir_size'])) |
|
| 637 | - $context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
|
| 638 | - if (isset($context['dir_files'])) |
|
| 639 | - $context['dir_files']--; |
|
| 671 | + if (isset($context['dir_size'])) { |
|
| 672 | + $context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
|
| 673 | + } |
|
| 674 | + if (isset($context['dir_files'])) { |
|
| 675 | + $context['dir_files']--; |
|
| 676 | + } |
|
| 640 | 677 | $context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
| 641 | 678 | $context['attachments']['quantity']--; |
| 642 | 679 | return false; |
@@ -668,12 +705,14 @@ discard block |
||
| 668 | 705 | if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width']) |
| 669 | 706 | { |
| 670 | 707 | // Got a proper mime type? |
| 671 | - if (!empty($size['mime'])) |
|
| 672 | - $attachmentOptions['mime_type'] = $size['mime']; |
|
| 708 | + if (!empty($size['mime'])) { |
|
| 709 | + $attachmentOptions['mime_type'] = $size['mime']; |
|
| 710 | + } |
|
| 673 | 711 | |
| 674 | 712 | // Otherwise a valid one? |
| 675 | - elseif (isset($context['validImageTypes'][$size[2]])) |
|
| 676 | - $attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
| 713 | + elseif (isset($context['validImageTypes'][$size[2]])) { |
|
| 714 | + $attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
| 715 | + } |
|
| 677 | 716 | } |
| 678 | 717 | |
| 679 | 718 | // It is possible we might have a MIME type that isn't actually an image but still have a size. |
@@ -685,15 +724,17 @@ discard block |
||
| 685 | 724 | } |
| 686 | 725 | |
| 687 | 726 | // Get the hash if no hash has been given yet. |
| 688 | - if (empty($attachmentOptions['file_hash'])) |
|
| 689 | - $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true); |
|
| 727 | + if (empty($attachmentOptions['file_hash'])) { |
|
| 728 | + $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true); |
|
| 729 | + } |
|
| 690 | 730 | |
| 691 | 731 | // Assuming no-one set the extension let's take a look at it. |
| 692 | 732 | if (empty($attachmentOptions['fileext'])) |
| 693 | 733 | { |
| 694 | 734 | $attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : ''); |
| 695 | - if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) |
|
| 696 | - $attachmentOptions['fileext'] = ''; |
|
| 735 | + if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) { |
|
| 736 | + $attachmentOptions['fileext'] = ''; |
|
| 737 | + } |
|
| 697 | 738 | } |
| 698 | 739 | |
| 699 | 740 | // Last chance to change stuff! |
@@ -702,8 +743,9 @@ discard block |
||
| 702 | 743 | // Make sure the folder is valid... |
| 703 | 744 | $tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : smf_json_decode($modSettings['attachmentUploadDir'], true); |
| 704 | 745 | $folders = array_keys($tmp); |
| 705 | - if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) |
|
| 706 | - $attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir']; |
|
| 746 | + if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) { |
|
| 747 | + $attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir']; |
|
| 748 | + } |
|
| 707 | 749 | |
| 708 | 750 | $attachmentOptions['id'] = $smcFunc['db_insert']('', |
| 709 | 751 | '{db_prefix}attachments', |
@@ -734,8 +776,8 @@ discard block |
||
| 734 | 776 | rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']); |
| 735 | 777 | |
| 736 | 778 | // If it's not approved then add to the approval queue. |
| 737 | - if (!$attachmentOptions['approved']) |
|
| 738 | - $smcFunc['db_insert']('', |
|
| 779 | + if (!$attachmentOptions['approved']) { |
|
| 780 | + $smcFunc['db_insert']('', |
|
| 739 | 781 | '{db_prefix}approval_queue', |
| 740 | 782 | array( |
| 741 | 783 | 'id_attach' => 'int', 'id_msg' => 'int', |
@@ -745,9 +787,11 @@ discard block |
||
| 745 | 787 | ), |
| 746 | 788 | array() |
| 747 | 789 | ); |
| 790 | + } |
|
| 748 | 791 | |
| 749 | - if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) |
|
| 750 | - return true; |
|
| 792 | + if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) { |
|
| 793 | + return true; |
|
| 794 | + } |
|
| 751 | 795 | |
| 752 | 796 | // Like thumbnails, do we? |
| 753 | 797 | if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight'])) |
@@ -758,13 +802,15 @@ discard block |
||
| 758 | 802 | $size = @getimagesize($attachmentOptions['destination'] . '_thumb'); |
| 759 | 803 | list ($thumb_width, $thumb_height) = $size; |
| 760 | 804 | |
| 761 | - if (!empty($size['mime'])) |
|
| 762 | - $thumb_mime = $size['mime']; |
|
| 763 | - elseif (isset($context['validImageTypes'][$size[2]])) |
|
| 764 | - $thumb_mime = 'image/' . $context['validImageTypes'][$size[2]]; |
|
| 805 | + if (!empty($size['mime'])) { |
|
| 806 | + $thumb_mime = $size['mime']; |
|
| 807 | + } elseif (isset($context['validImageTypes'][$size[2]])) { |
|
| 808 | + $thumb_mime = 'image/' . $context['validImageTypes'][$size[2]]; |
|
| 809 | + } |
|
| 765 | 810 | // Lord only knows how this happened... |
| 766 | - else |
|
| 767 | - $thumb_mime = ''; |
|
| 811 | + else { |
|
| 812 | + $thumb_mime = ''; |
|
| 813 | + } |
|
| 768 | 814 | |
| 769 | 815 | $thumb_filename = $attachmentOptions['name'] . '_thumb'; |
| 770 | 816 | $thumb_size = filesize($attachmentOptions['destination'] . '_thumb'); |
@@ -844,15 +890,17 @@ discard block |
||
| 844 | 890 | global $smcFunc; |
| 845 | 891 | |
| 846 | 892 | // Oh, come on! |
| 847 | - if (empty($attachIDs) || empty($msgID)) |
|
| 848 | - return false; |
|
| 893 | + if (empty($attachIDs) || empty($msgID)) { |
|
| 894 | + return false; |
|
| 895 | + } |
|
| 849 | 896 | |
| 850 | 897 | // "I see what is right and approve, but I do what is wrong." |
| 851 | 898 | call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID)); |
| 852 | 899 | |
| 853 | 900 | // One last check |
| 854 | - if (empty($attachIDs)) |
|
| 855 | - return false; |
|
| 901 | + if (empty($attachIDs)) { |
|
| 902 | + return false; |
|
| 903 | + } |
|
| 856 | 904 | |
| 857 | 905 | // Perform. |
| 858 | 906 | $smcFunc['db_query']('', ' |
@@ -882,8 +930,9 @@ discard block |
||
| 882 | 930 | $externalParse = false; |
| 883 | 931 | |
| 884 | 932 | // Meh... |
| 885 | - if (empty($attachID)) |
|
| 886 | - return 'attachments_no_data_loaded'; |
|
| 933 | + if (empty($attachID)) { |
|
| 934 | + return 'attachments_no_data_loaded'; |
|
| 935 | + } |
|
| 887 | 936 | |
| 888 | 937 | // Make it easy. |
| 889 | 938 | $msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0; |
@@ -892,20 +941,23 @@ discard block |
||
| 892 | 941 | $externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID)); |
| 893 | 942 | |
| 894 | 943 | // "I am innocent of the blood of this just person: see ye to it." |
| 895 | - if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) |
|
| 896 | - return $externalParse; |
|
| 944 | + if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) { |
|
| 945 | + return $externalParse; |
|
| 946 | + } |
|
| 897 | 947 | |
| 898 | 948 | //Are attachments enable? |
| 899 | - if (empty($modSettings['attachmentEnable'])) |
|
| 900 | - return 'attachments_not_enable'; |
|
| 949 | + if (empty($modSettings['attachmentEnable'])) { |
|
| 950 | + return 'attachments_not_enable'; |
|
| 951 | + } |
|
| 901 | 952 | |
| 902 | 953 | // Previewing much? no msg ID has been set yet. |
| 903 | 954 | if (!empty($context['preview_message'])) |
| 904 | 955 | { |
| 905 | 956 | $allAttachments = getAttachsByMsg(0); |
| 906 | 957 | |
| 907 | - if (empty($allAttachments[0][$attachID])) |
|
| 908 | - return 'attachments_no_data_loaded'; |
|
| 958 | + if (empty($allAttachments[0][$attachID])) { |
|
| 959 | + return 'attachments_no_data_loaded'; |
|
| 960 | + } |
|
| 909 | 961 | |
| 910 | 962 | $attachLoaded = loadAttachmentContext(0, $allAttachments); |
| 911 | 963 | |
@@ -917,57 +969,66 @@ discard block |
||
| 917 | 969 | $attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>'; |
| 918 | 970 | |
| 919 | 971 | // Fix the thumbnail too, if the image has one. |
| 920 | - if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) |
|
| 921 | - $attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview'; |
|
| 972 | + if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) { |
|
| 973 | + $attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview'; |
|
| 974 | + } |
|
| 922 | 975 | |
| 923 | 976 | return $attachContext; |
| 924 | 977 | } |
| 925 | 978 | |
| 926 | 979 | // There is always the chance someone else has already done our dirty work... |
| 927 | 980 | // If so, all pertinent checks were already done. Hopefully... |
| 928 | - if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) |
|
| 929 | - return $context['current_attachments'][$attachID]; |
|
| 981 | + if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) { |
|
| 982 | + return $context['current_attachments'][$attachID]; |
|
| 983 | + } |
|
| 930 | 984 | |
| 931 | 985 | // If we are lucky enough to be in $board's scope then check it! |
| 932 | - if (!empty($board) && !allowedTo('view_attachments', $board)) |
|
| 933 | - return 'attachments_not_allowed_to_see'; |
|
| 986 | + if (!empty($board) && !allowedTo('view_attachments', $board)) { |
|
| 987 | + return 'attachments_not_allowed_to_see'; |
|
| 988 | + } |
|
| 934 | 989 | |
| 935 | 990 | // Get the message info associated with this particular attach ID. |
| 936 | 991 | $attachInfo = getAttachMsgInfo($attachID); |
| 937 | 992 | |
| 938 | 993 | // There is always the chance this attachment no longer exists or isn't associated to a message anymore... |
| 939 | - if (empty($attachInfo) || empty($attachInfo['msg'])) |
|
| 940 | - return 'attachments_no_msg_associated'; |
|
| 994 | + if (empty($attachInfo) || empty($attachInfo['msg'])) { |
|
| 995 | + return 'attachments_no_msg_associated'; |
|
| 996 | + } |
|
| 941 | 997 | |
| 942 | 998 | // Hold it! got the info now check if you can see this attachment. |
| 943 | - if (!allowedTo('view_attachments', $attachInfo['board'])) |
|
| 944 | - return 'attachments_not_allowed_to_see'; |
|
| 999 | + if (!allowedTo('view_attachments', $attachInfo['board'])) { |
|
| 1000 | + return 'attachments_not_allowed_to_see'; |
|
| 1001 | + } |
|
| 945 | 1002 | |
| 946 | 1003 | $allAttachments = getAttachsByMsg($attachInfo['msg']); |
| 947 | 1004 | $attachContext = $allAttachments[$attachInfo['msg']][$attachID]; |
| 948 | 1005 | |
| 949 | 1006 | // No point in keep going further. |
| 950 | - if (!allowedTo('view_attachments', $attachContext['board'])) |
|
| 951 | - return 'attachments_not_allowed_to_see'; |
|
| 1007 | + if (!allowedTo('view_attachments', $attachContext['board'])) { |
|
| 1008 | + return 'attachments_not_allowed_to_see'; |
|
| 1009 | + } |
|
| 952 | 1010 | |
| 953 | 1011 | // Load this particular attach's context. |
| 954 | - if (!empty($attachContext)) |
|
| 955 | - $attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments); |
|
| 1012 | + if (!empty($attachContext)) { |
|
| 1013 | + $attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments); |
|
| 1014 | + } |
|
| 956 | 1015 | |
| 957 | 1016 | // One last check, you know, gotta be paranoid... |
| 958 | - else |
|
| 959 | - return 'attachments_no_data_loaded'; |
|
| 1017 | + else { |
|
| 1018 | + return 'attachments_no_data_loaded'; |
|
| 1019 | + } |
|
| 960 | 1020 | |
| 961 | 1021 | // This is the last "if" I promise! |
| 962 | - if (empty($attachLoaded)) |
|
| 963 | - return 'attachments_no_data_loaded'; |
|
| 964 | - |
|
| 965 | - else |
|
| 966 | - $attachContext = $attachLoaded[$attachID]; |
|
| 1022 | + if (empty($attachLoaded)) { |
|
| 1023 | + return 'attachments_no_data_loaded'; |
|
| 1024 | + } else { |
|
| 1025 | + $attachContext = $attachLoaded[$attachID]; |
|
| 1026 | + } |
|
| 967 | 1027 | |
| 968 | 1028 | // You may or may not want to show this under the post. |
| 969 | - if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) |
|
| 970 | - $context['show_attach_under_post'][$attachID] = $attachID; |
|
| 1029 | + if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) { |
|
| 1030 | + $context['show_attach_under_post'][$attachID] = $attachID; |
|
| 1031 | + } |
|
| 971 | 1032 | |
| 972 | 1033 | // Last minute changes? |
| 973 | 1034 | call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext)); |
@@ -987,8 +1048,9 @@ discard block |
||
| 987 | 1048 | { |
| 988 | 1049 | global $smcFunc, $modSettings; |
| 989 | 1050 | |
| 990 | - if (empty($attachIDs)) |
|
| 991 | - return array(); |
|
| 1051 | + if (empty($attachIDs)) { |
|
| 1052 | + return array(); |
|
| 1053 | + } |
|
| 992 | 1054 | |
| 993 | 1055 | $return = array(); |
| 994 | 1056 | |
@@ -1004,11 +1066,12 @@ discard block |
||
| 1004 | 1066 | ) |
| 1005 | 1067 | ); |
| 1006 | 1068 | |
| 1007 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
| 1008 | - return array(); |
|
| 1069 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
| 1070 | + return array(); |
|
| 1071 | + } |
|
| 1009 | 1072 | |
| 1010 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1011 | - $return[$row['id_attach']] = array( |
|
| 1073 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1074 | + $return[$row['id_attach']] = array( |
|
| 1012 | 1075 | 'name' => $smcFunc['htmlspecialchars']($row['filename']), |
| 1013 | 1076 | 'size' => $row['size'], |
| 1014 | 1077 | 'attachID' => $row['id_attach'], |
@@ -1017,6 +1080,7 @@ discard block |
||
| 1017 | 1080 | 'mime_type' => $row['mime_type'], |
| 1018 | 1081 | 'thumb' => $row['id_thumb'], |
| 1019 | 1082 | ); |
| 1083 | + } |
|
| 1020 | 1084 | $smcFunc['db_free_result']($request); |
| 1021 | 1085 | |
| 1022 | 1086 | return $return; |
@@ -1033,8 +1097,9 @@ discard block |
||
| 1033 | 1097 | { |
| 1034 | 1098 | global $smcFunc; |
| 1035 | 1099 | |
| 1036 | - if (empty($attachID)) |
|
| 1037 | - return array(); |
|
| 1100 | + if (empty($attachID)) { |
|
| 1101 | + return array(); |
|
| 1102 | + } |
|
| 1038 | 1103 | |
| 1039 | 1104 | $request = $smcFunc['db_query']('', ' |
| 1040 | 1105 | SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board |
@@ -1047,8 +1112,9 @@ discard block |
||
| 1047 | 1112 | ) |
| 1048 | 1113 | ); |
| 1049 | 1114 | |
| 1050 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
| 1051 | - return array(); |
|
| 1115 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
| 1116 | + return array(); |
|
| 1117 | + } |
|
| 1052 | 1118 | |
| 1053 | 1119 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1054 | 1120 | $smcFunc['db_free_result']($request); |
@@ -1089,8 +1155,9 @@ discard block |
||
| 1089 | 1155 | $temp = array(); |
| 1090 | 1156 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1091 | 1157 | { |
| 1092 | - if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) |
|
| 1093 | - continue; |
|
| 1158 | + if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) { |
|
| 1159 | + continue; |
|
| 1160 | + } |
|
| 1094 | 1161 | |
| 1095 | 1162 | $temp[$row['id_attach']] = $row; |
| 1096 | 1163 | } |
@@ -1119,8 +1186,9 @@ discard block |
||
| 1119 | 1186 | { |
| 1120 | 1187 | global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc; |
| 1121 | 1188 | |
| 1122 | - if (empty($attachments) || empty($attachments[$id_msg])) |
|
| 1123 | - return array(); |
|
| 1189 | + if (empty($attachments) || empty($attachments[$id_msg])) { |
|
| 1190 | + return array(); |
|
| 1191 | + } |
|
| 1124 | 1192 | |
| 1125 | 1193 | // Set up the attachment info - based on code by Meriadoc. |
| 1126 | 1194 | $attachmentData = array(); |
@@ -1144,11 +1212,13 @@ discard block |
||
| 1144 | 1212 | ); |
| 1145 | 1213 | |
| 1146 | 1214 | // If something is unapproved we'll note it so we can sort them. |
| 1147 | - if (!$attachment['approved']) |
|
| 1148 | - $have_unapproved = true; |
|
| 1215 | + if (!$attachment['approved']) { |
|
| 1216 | + $have_unapproved = true; |
|
| 1217 | + } |
|
| 1149 | 1218 | |
| 1150 | - if (!$attachmentData[$i]['is_image']) |
|
| 1151 | - continue; |
|
| 1219 | + if (!$attachmentData[$i]['is_image']) { |
|
| 1220 | + continue; |
|
| 1221 | + } |
|
| 1152 | 1222 | |
| 1153 | 1223 | $attachmentData[$i]['real_width'] = $attachment['width']; |
| 1154 | 1224 | $attachmentData[$i]['width'] = $attachment['width']; |
@@ -1169,12 +1239,12 @@ discard block |
||
| 1169 | 1239 | // So what folder are we putting this image in? |
| 1170 | 1240 | if (!empty($modSettings['currentAttachmentUploadDir'])) |
| 1171 | 1241 | { |
| 1172 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
| 1173 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 1242 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
| 1243 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 1244 | + } |
|
| 1174 | 1245 | $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
| 1175 | 1246 | $id_folder_thumb = $modSettings['currentAttachmentUploadDir']; |
| 1176 | - } |
|
| 1177 | - else |
|
| 1247 | + } else |
|
| 1178 | 1248 | { |
| 1179 | 1249 | $path = $modSettings['attachmentUploadDir']; |
| 1180 | 1250 | $id_folder_thumb = 1; |
@@ -1189,10 +1259,11 @@ discard block |
||
| 1189 | 1259 | $thumb_ext = isset($context['validImageTypes'][$size[2]]) ? $context['validImageTypes'][$size[2]] : ''; |
| 1190 | 1260 | |
| 1191 | 1261 | // Figure out the mime type. |
| 1192 | - if (!empty($size['mime'])) |
|
| 1193 | - $thumb_mime = $size['mime']; |
|
| 1194 | - else |
|
| 1195 | - $thumb_mime = 'image/' . $thumb_ext; |
|
| 1262 | + if (!empty($size['mime'])) { |
|
| 1263 | + $thumb_mime = $size['mime']; |
|
| 1264 | + } else { |
|
| 1265 | + $thumb_mime = 'image/' . $thumb_ext; |
|
| 1266 | + } |
|
| 1196 | 1267 | |
| 1197 | 1268 | $thumb_filename = $attachment['filename'] . '_thumb'; |
| 1198 | 1269 | $thumb_hash = getAttachmentFilename($thumb_filename, false, null, true); |
@@ -1239,11 +1310,12 @@ discard block |
||
| 1239 | 1310 | } |
| 1240 | 1311 | } |
| 1241 | 1312 | |
| 1242 | - if (!empty($attachment['id_thumb'])) |
|
| 1243 | - $attachmentData[$i]['thumbnail'] = array( |
|
| 1313 | + if (!empty($attachment['id_thumb'])) { |
|
| 1314 | + $attachmentData[$i]['thumbnail'] = array( |
|
| 1244 | 1315 | 'id' => $attachment['id_thumb'], |
| 1245 | 1316 | 'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image', |
| 1246 | 1317 | ); |
| 1318 | + } |
|
| 1247 | 1319 | $attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']); |
| 1248 | 1320 | |
| 1249 | 1321 | // If thumbnails are disabled, check the maximum size of the image. |
@@ -1253,30 +1325,31 @@ discard block |
||
| 1253 | 1325 | { |
| 1254 | 1326 | $attachmentData[$i]['width'] = $modSettings['max_image_width']; |
| 1255 | 1327 | $attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']); |
| 1256 | - } |
|
| 1257 | - elseif (!empty($modSettings['max_image_width'])) |
|
| 1328 | + } elseif (!empty($modSettings['max_image_width'])) |
|
| 1258 | 1329 | { |
| 1259 | 1330 | $attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']); |
| 1260 | 1331 | $attachmentData[$i]['height'] = $modSettings['max_image_height']; |
| 1261 | 1332 | } |
| 1262 | - } |
|
| 1263 | - elseif ($attachmentData[$i]['thumbnail']['has_thumb']) |
|
| 1333 | + } elseif ($attachmentData[$i]['thumbnail']['has_thumb']) |
|
| 1264 | 1334 | { |
| 1265 | 1335 | // If the image is too large to show inline, make it a popup. |
| 1266 | - if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) |
|
| 1267 | - $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);'; |
|
| 1268 | - else |
|
| 1269 | - $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');'; |
|
| 1336 | + if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) { |
|
| 1337 | + $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);'; |
|
| 1338 | + } else { |
|
| 1339 | + $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');'; |
|
| 1340 | + } |
|
| 1270 | 1341 | } |
| 1271 | 1342 | |
| 1272 | - if (!$attachmentData[$i]['thumbnail']['has_thumb']) |
|
| 1273 | - $attachmentData[$i]['downloads']++; |
|
| 1343 | + if (!$attachmentData[$i]['thumbnail']['has_thumb']) { |
|
| 1344 | + $attachmentData[$i]['downloads']++; |
|
| 1345 | + } |
|
| 1274 | 1346 | } |
| 1275 | 1347 | } |
| 1276 | 1348 | |
| 1277 | 1349 | // Do we need to instigate a sort? |
| 1278 | - if ($have_unapproved) |
|
| 1279 | - usort($attachmentData, 'approved_attach_sort'); |
|
| 1350 | + if ($have_unapproved) { |
|
| 1351 | + usort($attachmentData, 'approved_attach_sort'); |
|
| 1352 | + } |
|
| 1280 | 1353 | |
| 1281 | 1354 | return $attachmentData; |
| 1282 | 1355 | } |
@@ -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 | loadLanguage('Drafts'); |
| 21 | 22 | |
@@ -33,8 +34,9 @@ discard block |
||
| 33 | 34 | global $context, $user_info, $smcFunc, $modSettings, $board; |
| 34 | 35 | |
| 35 | 36 | // can you be, should you be ... here? |
| 36 | - if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) |
|
| 37 | - return false; |
|
| 37 | + if (empty($modSettings['drafts_post_enabled']) || !allowedTo('post_draft') || !isset($_POST['save_draft']) || !isset($_POST['id_draft'])) { |
|
| 38 | + return false; |
|
| 39 | + } |
|
| 38 | 40 | |
| 39 | 41 | // read in what they sent us, if anything |
| 40 | 42 | $id_draft = (int) $_POST['id_draft']; |
@@ -46,14 +48,16 @@ discard block |
||
| 46 | 48 | $context['draft_saved_on'] = $draft_info['poster_time']; |
| 47 | 49 | |
| 48 | 50 | // since we were called from the autosave function, send something back |
| 49 | - if (!empty($id_draft)) |
|
| 50 | - XmlDraft($id_draft); |
|
| 51 | + if (!empty($id_draft)) { |
|
| 52 | + XmlDraft($id_draft); |
|
| 53 | + } |
|
| 51 | 54 | |
| 52 | 55 | return true; |
| 53 | 56 | } |
| 54 | 57 | |
| 55 | - if (!isset($_POST['message'])) |
|
| 56 | - $_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : ''; |
|
| 58 | + if (!isset($_POST['message'])) { |
|
| 59 | + $_POST['message'] = isset($_POST['quickReply']) ? $_POST['quickReply'] : ''; |
|
| 60 | + } |
|
| 57 | 61 | |
| 58 | 62 | // prepare any data from the form |
| 59 | 63 | $topic_id = empty($_REQUEST['topic']) ? 0 : (int) $_REQUEST['topic']; |
@@ -66,8 +70,9 @@ discard block |
||
| 66 | 70 | |
| 67 | 71 | // message and subject still need a bit more work |
| 68 | 72 | preparsecode($draft['body']); |
| 69 | - if ($smcFunc['strlen']($draft['subject']) > 100) |
|
| 70 | - $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
| 73 | + if ($smcFunc['strlen']($draft['subject']) > 100) { |
|
| 74 | + $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
| 75 | + } |
|
| 71 | 76 | |
| 72 | 77 | // Modifying an existing draft, like hitting the save draft button or autosave enabled? |
| 73 | 78 | if (!empty($id_draft) && !empty($draft_info)) |
@@ -148,9 +153,9 @@ discard block |
||
| 148 | 153 | { |
| 149 | 154 | $context['draft_saved'] = true; |
| 150 | 155 | $context['id_draft'] = $id_draft; |
| 156 | + } else { |
|
| 157 | + $post_errors[] = 'draft_not_saved'; |
|
| 151 | 158 | } |
| 152 | - else |
|
| 153 | - $post_errors[] = 'draft_not_saved'; |
|
| 154 | 159 | |
| 155 | 160 | // cleanup |
| 156 | 161 | unset($_POST['save_draft']); |
@@ -180,8 +185,9 @@ discard block |
||
| 180 | 185 | global $context, $user_info, $smcFunc, $modSettings; |
| 181 | 186 | |
| 182 | 187 | // PM survey says ... can you stay or must you go |
| 183 | - if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) |
|
| 184 | - return false; |
|
| 188 | + if (empty($modSettings['drafts_pm_enabled']) || !allowedTo('pm_draft') || !isset($_POST['save_draft'])) { |
|
| 189 | + return false; |
|
| 190 | + } |
|
| 185 | 191 | |
| 186 | 192 | // read in what you sent us |
| 187 | 193 | $id_pm_draft = (int) $_POST['id_pm_draft']; |
@@ -193,8 +199,9 @@ discard block |
||
| 193 | 199 | $context['draft_saved_on'] = $draft_info['poster_time']; |
| 194 | 200 | |
| 195 | 201 | // Send something back to the javascript caller |
| 196 | - if (!empty($id_draft)) |
|
| 197 | - XmlDraft($id_draft); |
|
| 202 | + if (!empty($id_draft)) { |
|
| 203 | + XmlDraft($id_draft); |
|
| 204 | + } |
|
| 198 | 205 | |
| 199 | 206 | return true; |
| 200 | 207 | } |
@@ -204,9 +211,9 @@ discard block |
||
| 204 | 211 | { |
| 205 | 212 | $recipientList['to'] = isset($_POST['recipient_to']) ? explode(',', $_POST['recipient_to']) : array(); |
| 206 | 213 | $recipientList['bcc'] = isset($_POST['recipient_bcc']) ? explode(',', $_POST['recipient_bcc']) : array(); |
| 214 | + } elseif (!empty($draft_info['to_list']) && empty($recipientList)) { |
|
| 215 | + $recipientList = smf_json_decode($draft_info['to_list'], true); |
|
| 207 | 216 | } |
| 208 | - elseif (!empty($draft_info['to_list']) && empty($recipientList)) |
|
| 209 | - $recipientList = smf_json_decode($draft_info['to_list'], true); |
|
| 210 | 217 | |
| 211 | 218 | // prepare the data we got from the form |
| 212 | 219 | $reply_id = empty($_POST['replied_to']) ? 0 : (int) $_POST['replied_to']; |
@@ -215,8 +222,9 @@ discard block |
||
| 215 | 222 | |
| 216 | 223 | // message and subject always need a bit more work |
| 217 | 224 | preparsecode($draft['body']); |
| 218 | - if ($smcFunc['strlen']($draft['subject']) > 100) |
|
| 219 | - $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
| 225 | + if ($smcFunc['strlen']($draft['subject']) > 100) { |
|
| 226 | + $draft['subject'] = $smcFunc['substr']($draft['subject'], 0, 100); |
|
| 227 | + } |
|
| 220 | 228 | |
| 221 | 229 | // Modifying an existing PM draft? |
| 222 | 230 | if (!empty($id_pm_draft) && !empty($draft_info)) |
@@ -280,9 +288,9 @@ discard block |
||
| 280 | 288 | { |
| 281 | 289 | $context['draft_saved'] = true; |
| 282 | 290 | $context['id_pm_draft'] = $id_pm_draft; |
| 291 | + } else { |
|
| 292 | + $post_errors[] = 'draft_not_saved'; |
|
| 283 | 293 | } |
| 284 | - else |
|
| 285 | - $post_errors[] = 'draft_not_saved'; |
|
| 286 | 294 | } |
| 287 | 295 | |
| 288 | 296 | // if we were called from the autosave function, send something back |
@@ -315,8 +323,9 @@ discard block |
||
| 315 | 323 | $type = (int) $type; |
| 316 | 324 | |
| 317 | 325 | // nothing to read, nothing to do |
| 318 | - if (empty($id_draft)) |
|
| 319 | - return false; |
|
| 326 | + if (empty($id_draft)) { |
|
| 327 | + return false; |
|
| 328 | + } |
|
| 320 | 329 | |
| 321 | 330 | // load in this draft from the DB |
| 322 | 331 | $request = $smcFunc['db_query']('', ' |
@@ -337,8 +346,9 @@ discard block |
||
| 337 | 346 | ); |
| 338 | 347 | |
| 339 | 348 | // no results? |
| 340 | - if (!$smcFunc['db_num_rows']($request)) |
|
| 341 | - return false; |
|
| 349 | + if (!$smcFunc['db_num_rows']($request)) { |
|
| 350 | + return false; |
|
| 351 | + } |
|
| 342 | 352 | |
| 343 | 353 | // load up the data |
| 344 | 354 | $draft_info = $smcFunc['db_fetch_assoc']($request); |
@@ -358,8 +368,7 @@ discard block |
||
| 358 | 368 | $context['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : ''; |
| 359 | 369 | $context['board'] = !empty($draft_info['id_board']) ? $draft_info['id_board'] : ''; |
| 360 | 370 | $context['id_draft'] = !empty($draft_info['id_draft']) ? $draft_info['id_draft'] : 0; |
| 361 | - } |
|
| 362 | - elseif ($type === 1) |
|
| 371 | + } elseif ($type === 1) |
|
| 363 | 372 | { |
| 364 | 373 | // one of those pm drafts? then set it up like we have an error |
| 365 | 374 | $_REQUEST['subject'] = !empty($draft_info['subject']) ? stripslashes($draft_info['subject']) : ''; |
@@ -395,12 +404,14 @@ discard block |
||
| 395 | 404 | global $user_info, $smcFunc; |
| 396 | 405 | |
| 397 | 406 | // Only a single draft. |
| 398 | - if (is_numeric($id_draft)) |
|
| 399 | - $id_draft = array($id_draft); |
|
| 407 | + if (is_numeric($id_draft)) { |
|
| 408 | + $id_draft = array($id_draft); |
|
| 409 | + } |
|
| 400 | 410 | |
| 401 | 411 | // can't delete nothing |
| 402 | - if (empty($id_draft) || ($check && empty($user_info['id']))) |
|
| 403 | - return false; |
|
| 412 | + if (empty($id_draft) || ($check && empty($user_info['id']))) { |
|
| 413 | + return false; |
|
| 414 | + } |
|
| 404 | 415 | |
| 405 | 416 | $smcFunc['db_query']('', ' |
| 406 | 417 | DELETE FROM {db_prefix}user_drafts |
@@ -429,14 +440,16 @@ discard block |
||
| 429 | 440 | global $smcFunc, $scripturl, $context, $txt, $modSettings; |
| 430 | 441 | |
| 431 | 442 | // Permissions |
| 432 | - if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) |
|
| 433 | - return false; |
|
| 443 | + if (($draft_type === 0 && empty($context['drafts_save'])) || ($draft_type === 1 && empty($context['drafts_pm_save'])) || empty($member_id)) { |
|
| 444 | + return false; |
|
| 445 | + } |
|
| 434 | 446 | |
| 435 | 447 | $context['drafts'] = array(); |
| 436 | 448 | |
| 437 | 449 | // has a specific draft has been selected? Load it up if there is not a message already in the editor |
| 438 | - if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) |
|
| 439 | - ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true); |
|
| 450 | + if (isset($_REQUEST['id_draft']) && empty($_POST['subject']) && empty($_POST['message'])) { |
|
| 451 | + ReadDraft((int) $_REQUEST['id_draft'], $draft_type, true, true); |
|
| 452 | + } |
|
| 440 | 453 | |
| 441 | 454 | // load the drafts this user has available |
| 442 | 455 | $request = $smcFunc['db_query']('', ' |
@@ -459,8 +472,9 @@ discard block |
||
| 459 | 472 | // add them to the draft array for display |
| 460 | 473 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 461 | 474 | { |
| 462 | - if (empty($row['subject'])) |
|
| 463 | - $row['subject'] = $txt['no_subject']; |
|
| 475 | + if (empty($row['subject'])) { |
|
| 476 | + $row['subject'] = $txt['no_subject']; |
|
| 477 | + } |
|
| 464 | 478 | |
| 465 | 479 | // Post drafts |
| 466 | 480 | if ($draft_type === 0) |
@@ -545,8 +559,9 @@ discard block |
||
| 545 | 559 | } |
| 546 | 560 | |
| 547 | 561 | // Default to 10. |
| 548 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
| 549 | - $_REQUEST['viewscount'] = 10; |
|
| 562 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
| 563 | + $_REQUEST['viewscount'] = 10; |
|
| 564 | + } |
|
| 550 | 565 | |
| 551 | 566 | // Get the count of applicable drafts on the boards they can (still) see ... |
| 552 | 567 | // @todo .. should we just let them see their drafts even if they have lost board access ? |
@@ -611,12 +626,14 @@ discard block |
||
| 611 | 626 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 612 | 627 | { |
| 613 | 628 | // Censor.... |
| 614 | - if (empty($row['body'])) |
|
| 615 | - $row['body'] = ''; |
|
| 629 | + if (empty($row['body'])) { |
|
| 630 | + $row['body'] = ''; |
|
| 631 | + } |
|
| 616 | 632 | |
| 617 | 633 | $row['subject'] = $smcFunc['htmltrim']($row['subject']); |
| 618 | - if (empty($row['subject'])) |
|
| 619 | - $row['subject'] = $txt['no_subject']; |
|
| 634 | + if (empty($row['subject'])) { |
|
| 635 | + $row['subject'] = $txt['no_subject']; |
|
| 636 | + } |
|
| 620 | 637 | |
| 621 | 638 | censorText($row['body']); |
| 622 | 639 | censorText($row['subject']); |
@@ -648,8 +665,9 @@ discard block |
||
| 648 | 665 | $smcFunc['db_free_result']($request); |
| 649 | 666 | |
| 650 | 667 | // If the drafts were retrieved in reverse order, get them right again. |
| 651 | - if ($reverse) |
|
| 652 | - $context['drafts'] = array_reverse($context['drafts'], true); |
|
| 668 | + if ($reverse) { |
|
| 669 | + $context['drafts'] = array_reverse($context['drafts'], true); |
|
| 670 | + } |
|
| 653 | 671 | |
| 654 | 672 | // Menu tab |
| 655 | 673 | $context[$context['profile_menu_name']]['tab_data'] = array( |
@@ -707,8 +725,9 @@ discard block |
||
| 707 | 725 | } |
| 708 | 726 | |
| 709 | 727 | // Default to 10. |
| 710 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
| 711 | - $_REQUEST['viewscount'] = 10; |
|
| 728 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
| 729 | + $_REQUEST['viewscount'] = 10; |
|
| 730 | + } |
|
| 712 | 731 | |
| 713 | 732 | // Get the count of applicable drafts |
| 714 | 733 | $request = $smcFunc['db_query']('', ' |
@@ -767,12 +786,14 @@ discard block |
||
| 767 | 786 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 768 | 787 | { |
| 769 | 788 | // Censor.... |
| 770 | - if (empty($row['body'])) |
|
| 771 | - $row['body'] = ''; |
|
| 789 | + if (empty($row['body'])) { |
|
| 790 | + $row['body'] = ''; |
|
| 791 | + } |
|
| 772 | 792 | |
| 773 | 793 | $row['subject'] = $smcFunc['htmltrim']($row['subject']); |
| 774 | - if (empty($row['subject'])) |
|
| 775 | - $row['subject'] = $txt['no_subject']; |
|
| 794 | + if (empty($row['subject'])) { |
|
| 795 | + $row['subject'] = $txt['no_subject']; |
|
| 796 | + } |
|
| 776 | 797 | |
| 777 | 798 | censorText($row['body']); |
| 778 | 799 | censorText($row['subject']); |
@@ -827,8 +848,9 @@ discard block |
||
| 827 | 848 | $smcFunc['db_free_result']($request); |
| 828 | 849 | |
| 829 | 850 | // if the drafts were retrieved in reverse order, then put them in the right order again. |
| 830 | - if ($reverse) |
|
| 831 | - $context['drafts'] = array_reverse($context['drafts'], true); |
|
| 851 | + if ($reverse) { |
|
| 852 | + $context['drafts'] = array_reverse($context['drafts'], true); |
|
| 853 | + } |
|
| 832 | 854 | |
| 833 | 855 | // off to the template we go |
| 834 | 856 | $context['page_title'] = $txt['drafts']; |
@@ -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 | class Attachments |
| 20 | 21 | { |
@@ -70,16 +71,18 @@ discard block |
||
| 70 | 71 | |
| 71 | 72 | $this->_sa = !empty($_REQUEST['sa']) ? $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_REQUEST['sa'])) : false; |
| 72 | 73 | |
| 73 | - if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) |
|
| 74 | - $this->{$this->_sa}(); |
|
| 74 | + if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) { |
|
| 75 | + $this->{$this->_sa}(); |
|
| 76 | + } |
|
| 75 | 77 | |
| 76 | 78 | // Just send a generic message. |
| 77 | - else |
|
| 78 | - $this->setResponse(array( |
|
| 79 | + else { |
|
| 80 | + $this->setResponse(array( |
|
| 79 | 81 | 'text' => $this->_sa == 'add' ? 'attach_error_title' : 'attached_file_deleted_error', |
| 80 | 82 | 'type' => 'error', |
| 81 | 83 | 'data' => false, |
| 82 | 84 | )); |
| 85 | + } |
|
| 83 | 86 | |
| 84 | 87 | // Back to the future, oh, to the browser! |
| 85 | 88 | $this->sendResponse(); |
@@ -95,12 +98,13 @@ discard block |
||
| 95 | 98 | $attachID = !empty($_REQUEST['attach']) && is_numeric($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : 0; |
| 96 | 99 | |
| 97 | 100 | // Need something to work with. |
| 98 | - if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) |
|
| 99 | - return $this->setResponse(array( |
|
| 101 | + if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) { |
|
| 102 | + return $this->setResponse(array( |
|
| 100 | 103 | 'text' => 'attached_file_deleted_error', |
| 101 | 104 | 'type' => 'error', |
| 102 | 105 | 'data' => false, |
| 103 | 106 | )); |
| 107 | + } |
|
| 104 | 108 | |
| 105 | 109 | // Lets pass some params and see what happens :P |
| 106 | 110 | $affectedMessage = removeAttachments(array('id_attach' => $attachID), '', true, true); |
@@ -119,19 +123,21 @@ discard block |
||
| 119 | 123 | public function add() |
| 120 | 124 | { |
| 121 | 125 | // You gotta be able to post attachments. |
| 122 | - if (!$this->_canPostAttachment) |
|
| 123 | - return $this->setResponse(array( |
|
| 126 | + if (!$this->_canPostAttachment) { |
|
| 127 | + return $this->setResponse(array( |
|
| 124 | 128 | 'text' => 'attached_file_cannot', |
| 125 | 129 | 'type' => 'error', |
| 126 | 130 | 'data' => false, |
| 127 | 131 | )); |
| 132 | + } |
|
| 128 | 133 | |
| 129 | 134 | // Process them at once! |
| 130 | 135 | $this->processAttachments(); |
| 131 | 136 | |
| 132 | 137 | // The attachments was created and moved the the right folder, time to update the DB. |
| 133 | - if (!empty($_SESSION['temp_attachments'])) |
|
| 134 | - $this->createAtttach(); |
|
| 138 | + if (!empty($_SESSION['temp_attachments'])) { |
|
| 139 | + $this->createAtttach(); |
|
| 140 | + } |
|
| 135 | 141 | |
| 136 | 142 | // Set the response. |
| 137 | 143 | $this->setResponse(); |
@@ -144,8 +150,9 @@ discard block |
||
| 144 | 150 | { |
| 145 | 151 | global $context, $modSettings, $smcFunc, $user_info, $txt; |
| 146 | 152 | |
| 147 | - if (!isset($_FILES['attachment']['name'])) |
|
| 148 | - $_FILES['attachment']['tmp_name'] = array(); |
|
| 153 | + if (!isset($_FILES['attachment']['name'])) { |
|
| 154 | + $_FILES['attachment']['tmp_name'] = array(); |
|
| 155 | + } |
|
| 149 | 156 | |
| 150 | 157 | // If there are attachments, calculate the total size and how many. |
| 151 | 158 | $context['attachments']['total_size'] = 0; |
@@ -155,25 +162,30 @@ discard block |
||
| 155 | 162 | if (isset($_REQUEST['msg'])) |
| 156 | 163 | { |
| 157 | 164 | $context['attachments']['quantity'] = count($context['current_attachments']); |
| 158 | - foreach ($context['current_attachments'] as $attachment) |
|
| 159 | - $context['attachments']['total_size'] += $attachment['size']; |
|
| 165 | + foreach ($context['current_attachments'] as $attachment) { |
|
| 166 | + $context['attachments']['total_size'] += $attachment['size']; |
|
| 167 | + } |
|
| 160 | 168 | } |
| 161 | 169 | |
| 162 | 170 | // A bit of house keeping first. |
| 163 | - if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) |
|
| 164 | - unset($_SESSION['temp_attachments']); |
|
| 171 | + if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) { |
|
| 172 | + unset($_SESSION['temp_attachments']); |
|
| 173 | + } |
|
| 165 | 174 | |
| 166 | 175 | // Our infamous SESSION var, we are gonna have soo much fun with it! |
| 167 | - if (!isset($_SESSION['temp_attachments'])) |
|
| 168 | - $_SESSION['temp_attachments'] = array(); |
|
| 176 | + if (!isset($_SESSION['temp_attachments'])) { |
|
| 177 | + $_SESSION['temp_attachments'] = array(); |
|
| 178 | + } |
|
| 169 | 179 | |
| 170 | 180 | // Make sure we're uploading to the right place. |
| 171 | - if (!empty($modSettings['automanage_attachments'])) |
|
| 172 | - automanage_attachments_check_directory(); |
|
| 181 | + if (!empty($modSettings['automanage_attachments'])) { |
|
| 182 | + automanage_attachments_check_directory(); |
|
| 183 | + } |
|
| 173 | 184 | |
| 174 | 185 | // Is the attachments folder actually there? |
| 175 | - if (!empty($context['dir_creation_error'])) |
|
| 176 | - $this->_generalErrors[] = $context['dir_creation_error']; |
|
| 186 | + if (!empty($context['dir_creation_error'])) { |
|
| 187 | + $this->_generalErrors[] = $context['dir_creation_error']; |
|
| 188 | + } |
|
| 177 | 189 | |
| 178 | 190 | // The current attach folder ha some issues... |
| 179 | 191 | elseif (!is_dir($this->_attchDir)) |
@@ -198,13 +210,12 @@ discard block |
||
| 198 | 210 | ); |
| 199 | 211 | list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request); |
| 200 | 212 | $smcFunc['db_free_result']($request); |
| 201 | - } |
|
| 202 | - |
|
| 203 | - else |
|
| 204 | - $context['attachments'] = array( |
|
| 213 | + } else { |
|
| 214 | + $context['attachments'] = array( |
|
| 205 | 215 | 'quantity' => 0, |
| 206 | 216 | 'total_size' => 0, |
| 207 | 217 | ); |
| 218 | + } |
|
| 208 | 219 | |
| 209 | 220 | // Check for other general errors here. |
| 210 | 221 | |
@@ -212,9 +223,10 @@ discard block |
||
| 212 | 223 | if (!empty($this->_generalErrors)) |
| 213 | 224 | { |
| 214 | 225 | // And delete the files 'cos they ain't going nowhere. |
| 215 | - foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
|
| 216 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 226 | + foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) { |
|
| 227 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 217 | 228 | unlink($_FILES['attachment']['tmp_name'][$n]); |
| 229 | + } |
|
| 218 | 230 | |
| 219 | 231 | $_FILES['attachment']['tmp_name'] = array(); |
| 220 | 232 | |
@@ -225,26 +237,29 @@ discard block |
||
| 225 | 237 | // Loop through $_FILES['attachment'] array and move each file to the current attachments folder. |
| 226 | 238 | foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
| 227 | 239 | { |
| 228 | - if ($_FILES['attachment']['name'][$n] == '') |
|
| 229 | - continue; |
|
| 240 | + if ($_FILES['attachment']['name'][$n] == '') { |
|
| 241 | + continue; |
|
| 242 | + } |
|
| 230 | 243 | |
| 231 | 244 | // First, let's first check for PHP upload errors. |
| 232 | 245 | $errors = array(); |
| 233 | 246 | if (!empty($_FILES['attachment']['error'][$n])) |
| 234 | 247 | { |
| 235 | - if ($_FILES['attachment']['error'][$n] == 2) |
|
| 236 | - $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
| 237 | - |
|
| 238 | - else |
|
| 239 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
| 248 | + if ($_FILES['attachment']['error'][$n] == 2) { |
|
| 249 | + $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
| 250 | + } else { |
|
| 251 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
| 252 | + } |
|
| 240 | 253 | |
| 241 | 254 | // Log this one, because... |
| 242 | - if ($_FILES['attachment']['error'][$n] == 6) |
|
| 243 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
| 255 | + if ($_FILES['attachment']['error'][$n] == 6) { |
|
| 256 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
| 257 | + } |
|
| 244 | 258 | |
| 245 | 259 | // Weird, no errors were cached, still fill out a generic one. |
| 246 | - if (empty($errors)) |
|
| 247 | - $errors[] = 'attach_php_error'; |
|
| 260 | + if (empty($errors)) { |
|
| 261 | + $errors[] = 'attach_php_error'; |
|
| 262 | + } |
|
| 248 | 263 | } |
| 249 | 264 | |
| 250 | 265 | // Try to move and rename the file before doing any more checks on it. |
@@ -256,8 +271,9 @@ discard block |
||
| 256 | 271 | { |
| 257 | 272 | // The reported MIME type of the attachment might not be reliable. |
| 258 | 273 | // Fortunately, PHP 5.3+ lets us easily verify the real MIME type. |
| 259 | - if (function_exists('mime_content_type')) |
|
| 260 | - $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
| 274 | + if (function_exists('mime_content_type')) { |
|
| 275 | + $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
| 276 | + } |
|
| 261 | 277 | |
| 262 | 278 | $_SESSION['temp_attachments'][$attachID] = array( |
| 263 | 279 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -269,16 +285,18 @@ discard block |
||
| 269 | 285 | ); |
| 270 | 286 | |
| 271 | 287 | // Move the file to the attachments folder with a temp name for now. |
| 272 | - if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) |
|
| 273 | - smf_chmod($destName, 0644); |
|
| 288 | + if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) { |
|
| 289 | + smf_chmod($destName, 0644); |
|
| 290 | + } |
|
| 274 | 291 | |
| 275 | 292 | // This is madness!! |
| 276 | 293 | else |
| 277 | 294 | { |
| 278 | 295 | // File couldn't be moved. |
| 279 | 296 | $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout'; |
| 280 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 281 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 297 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
| 298 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 299 | + } |
|
| 282 | 300 | } |
| 283 | 301 | } |
| 284 | 302 | |
@@ -291,13 +309,15 @@ discard block |
||
| 291 | 309 | 'errors' => $errors, |
| 292 | 310 | ); |
| 293 | 311 | |
| 294 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 295 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 312 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
| 313 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 314 | + } |
|
| 296 | 315 | } |
| 297 | 316 | |
| 298 | 317 | // If there's no errors to this point. We still do need to apply some additional checks before we are finished. |
| 299 | - if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
|
| 300 | - attachmentChecks($attachID); |
|
| 318 | + if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) { |
|
| 319 | + attachmentChecks($attachID); |
|
| 320 | + } |
|
| 301 | 321 | } |
| 302 | 322 | |
| 303 | 323 | // Mod authors, finally a hook to hang an alternate attachment upload system upon |
@@ -344,14 +364,15 @@ discard block |
||
| 344 | 364 | |
| 345 | 365 | $_SESSION['already_attached'][$attachmentOptions['attachID']] = $attachmentOptions['attachID']; |
| 346 | 366 | |
| 347 | - if (!empty($attachmentOptions['thumb'])) |
|
| 348 | - $_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb']; |
|
| 367 | + if (!empty($attachmentOptions['thumb'])) { |
|
| 368 | + $_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb']; |
|
| 369 | + } |
|
| 349 | 370 | |
| 350 | - if ($this->_msg) |
|
| 351 | - assignAttachments($_SESSION['already_attached'], $this->_msg); |
|
| 371 | + if ($this->_msg) { |
|
| 372 | + assignAttachments($_SESSION['already_attached'], $this->_msg); |
|
| 373 | + } |
|
| 352 | 374 | } |
| 353 | - } |
|
| 354 | - else |
|
| 375 | + } else |
|
| 355 | 376 | { |
| 356 | 377 | // Sort out the errors for display and delete any associated files. |
| 357 | 378 | $log_these = array('attachments_no_create', 'attachments_no_write', 'attach_timeout', 'ran_out_of_space', 'cant_access_upload_path', 'attach_0_byte_file'); |
@@ -363,14 +384,16 @@ discard block |
||
| 363 | 384 | if (!is_array($error)) |
| 364 | 385 | { |
| 365 | 386 | $attachmentOptions['errors'][] = $txt[$error]; |
| 366 | - if (in_array($error, $log_these)) |
|
| 367 | - log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
| 387 | + if (in_array($error, $log_these)) { |
|
| 388 | + log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
| 389 | + } |
|
| 390 | + } else { |
|
| 391 | + $attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]); |
|
| 368 | 392 | } |
| 369 | - else |
|
| 370 | - $attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]); |
|
| 371 | 393 | } |
| 372 | - if (file_exists($attachment['tmp_name'])) |
|
| 373 | - unlink($attachment['tmp_name']); |
|
| 394 | + if (file_exists($attachment['tmp_name'])) { |
|
| 395 | + unlink($attachment['tmp_name']); |
|
| 396 | + } |
|
| 374 | 397 | } |
| 375 | 398 | |
| 376 | 399 | // Regardless of errors, pass the results. |
@@ -378,8 +401,9 @@ discard block |
||
| 378 | 401 | } |
| 379 | 402 | |
| 380 | 403 | // Temp save this on the db. |
| 381 | - if (!empty($_SESSION['already_attached'])) |
|
| 382 | - $this->_attachSuccess = $_SESSION['already_attached']; |
|
| 404 | + if (!empty($_SESSION['already_attached'])) { |
|
| 405 | + $this->_attachSuccess = $_SESSION['already_attached']; |
|
| 406 | + } |
|
| 383 | 407 | |
| 384 | 408 | unset($_SESSION['temp_attachments']); |
| 385 | 409 | } |
@@ -399,14 +423,16 @@ discard block |
||
| 399 | 423 | if ($this->_sa == 'add') |
| 400 | 424 | { |
| 401 | 425 | // Is there any generic errors? made some sense out of them! |
| 402 | - if ($this->_generalErrors) |
|
| 403 | - foreach ($this->_generalErrors as $k => $v) |
|
| 426 | + if ($this->_generalErrors) { |
|
| 427 | + foreach ($this->_generalErrors as $k => $v) |
|
| 404 | 428 | $this->_generalErrors[$k] = (is_array($v) ? vsprintf($txt[$v[0]], $v[1]) : $txt[$v]); |
| 429 | + } |
|
| 405 | 430 | |
| 406 | 431 | // Gotta urlencode the filename. |
| 407 | - if ($this->_attachResults) |
|
| 408 | - foreach ($this->_attachResults as $k => $v) |
|
| 432 | + if ($this->_attachResults) { |
|
| 433 | + foreach ($this->_attachResults as $k => $v) |
|
| 409 | 434 | $this->_attachResults[$k]['name'] = urlencode($this->_attachResults[$k]['name']); |
| 435 | + } |
|
| 410 | 436 | |
| 411 | 437 | $this->_response = array( |
| 412 | 438 | 'files' => $this->_attachResults ? $this->_attachResults : false, |
@@ -415,9 +441,10 @@ discard block |
||
| 415 | 441 | } |
| 416 | 442 | |
| 417 | 443 | // Rest of us mere mortals gets no special treatment... |
| 418 | - elseif (!empty($data)) |
|
| 419 | - if (!empty($data['text']) && !empty($txt[$data['text']])) |
|
| 444 | + elseif (!empty($data)) { |
|
| 445 | + if (!empty($data['text']) && !empty($txt[$data['text']])) |
|
| 420 | 446 | $this->_response['text'] = $txt[$data['text']]; |
| 447 | + } |
|
| 421 | 448 | } |
| 422 | 449 | |
| 423 | 450 | protected function sendResponse() |
@@ -426,11 +453,11 @@ discard block |
||
| 426 | 453 | |
| 427 | 454 | ob_end_clean(); |
| 428 | 455 | |
| 429 | - if (!empty($modSettings['CompressedOutput'])) |
|
| 430 | - @ob_start('ob_gzhandler'); |
|
| 431 | - |
|
| 432 | - else |
|
| 433 | - ob_start(); |
|
| 456 | + if (!empty($modSettings['CompressedOutput'])) { |
|
| 457 | + @ob_start('ob_gzhandler'); |
|
| 458 | + } else { |
|
| 459 | + ob_start(); |
|
| 460 | + } |
|
| 434 | 461 | |
| 435 | 462 | // Set the header. |
| 436 | 463 | header('Content-Type: application/json; charset='. $context['character_set'] .''); |
@@ -53,14 +53,15 @@ discard block |
||
| 53 | 53 | foreach ($context['smileys'] as $location => $smileyRows) |
| 54 | 54 | { |
| 55 | 55 | $countLocations--; |
| 56 | - if ($location == 'postform') |
|
| 57 | - echo ' |
|
| 56 | + if ($location == 'postform') { |
|
| 57 | + echo ' |
|
| 58 | 58 | dropdown: |
| 59 | 59 | {'; |
| 60 | - elseif ($location == 'popup') |
|
| 61 | - echo ' |
|
| 60 | + } elseif ($location == 'popup') { |
|
| 61 | + echo ' |
|
| 62 | 62 | popup: |
| 63 | 63 | {'; |
| 64 | + } |
|
| 64 | 65 | |
| 65 | 66 | $numRows = count($smileyRows); |
| 66 | 67 | // This is needed because otherwise the editor will remove all the duplicate (empty) keys and leave only 1 additional line |
@@ -72,21 +73,22 @@ discard block |
||
| 72 | 73 | echo ' |
| 73 | 74 | ', JavaScriptEscape($smiley['code']), ': ', JavaScriptEscape($settings['smileys_url'] . '/' . $smiley['filename']), empty($smiley['isLast']) ? ',' : ''; |
| 74 | 75 | } |
| 75 | - if (empty($smileyRow['isLast']) && $numRows != 1) |
|
| 76 | - echo ', |
|
| 76 | + if (empty($smileyRow['isLast']) && $numRows != 1) { |
|
| 77 | + echo ', |
|
| 77 | 78 | \'-', $emptyPlaceholder++, '\': \'\','; |
| 79 | + } |
|
| 78 | 80 | } |
| 79 | 81 | echo ' |
| 80 | 82 | }', $countLocations != 0 ? ',' : ''; |
| 81 | 83 | } |
| 82 | 84 | echo ' |
| 83 | 85 | }'; |
| 84 | - } |
|
| 85 | - else |
|
| 86 | - echo ', |
|
| 86 | + } else { |
|
| 87 | + echo ', |
|
| 87 | 88 | emoticons: |
| 88 | 89 | {}, |
| 89 | 90 | emoticonsEnabled:false'; |
| 91 | + } |
|
| 90 | 92 | |
| 91 | 93 | if ($context['show_bbc'] && $bbcContainer !== null) |
| 92 | 94 | { |
@@ -97,15 +99,16 @@ discard block |
||
| 97 | 99 | { |
| 98 | 100 | echo implode('|', $buttonRow); |
| 99 | 101 | $count_tags--; |
| 100 | - if (!empty($count_tags)) |
|
| 101 | - echo '||'; |
|
| 102 | + if (!empty($count_tags)) { |
|
| 103 | + echo '||'; |
|
| 104 | + } |
|
| 102 | 105 | } |
| 103 | 106 | |
| 104 | 107 | echo '",'; |
| 105 | - } |
|
| 106 | - else |
|
| 107 | - echo ', |
|
| 108 | + } else { |
|
| 109 | + echo ', |
|
| 108 | 110 | toolbar: "",'; |
| 111 | + } |
|
| 109 | 112 | |
| 110 | 113 | echo ' |
| 111 | 114 | }); |
@@ -146,43 +149,48 @@ discard block |
||
| 146 | 149 | </span>'; |
| 147 | 150 | |
| 148 | 151 | $tempTab = $context['tabindex']; |
| 149 | - if (!empty($context['drafts_pm_save'])) |
|
| 150 | - $tempTab++; |
|
| 151 | - elseif (!empty($context['drafts_save'])) |
|
| 152 | - $tempTab++; |
|
| 153 | - elseif ($editor_context['preview_type']) |
|
| 154 | - $tempTab++; |
|
| 155 | - elseif ($context['show_spellchecking']) |
|
| 156 | - $tempTab++; |
|
| 152 | + if (!empty($context['drafts_pm_save'])) { |
|
| 153 | + $tempTab++; |
|
| 154 | + } elseif (!empty($context['drafts_save'])) { |
|
| 155 | + $tempTab++; |
|
| 156 | + } elseif ($editor_context['preview_type']) { |
|
| 157 | + $tempTab++; |
|
| 158 | + } elseif ($context['show_spellchecking']) { |
|
| 159 | + $tempTab++; |
|
| 160 | + } |
|
| 157 | 161 | |
| 158 | 162 | $tempTab++; |
| 159 | 163 | $context['tabindex'] = $tempTab; |
| 160 | 164 | |
| 161 | - if (!empty($context['drafts_pm_save'])) |
|
| 162 | - echo ' |
|
| 165 | + if (!empty($context['drafts_pm_save'])) { |
|
| 166 | + echo ' |
|
| 163 | 167 | <input type="submit" name="save_draft" value="', $txt['draft_save'], '" tabindex="', --$tempTab, '" onclick="submitThisOnce(this);" accesskey="d" class="button_submit"> |
| 164 | 168 | <input type="hidden" id="id_pm_draft" name="id_pm_draft" value="', empty($context['id_pm_draft']) ? 0 : $context['id_pm_draft'], '">'; |
| 169 | + } |
|
| 165 | 170 | |
| 166 | - if (!empty($context['drafts_save'])) |
|
| 167 | - echo ' |
|
| 171 | + if (!empty($context['drafts_save'])) { |
|
| 172 | + echo ' |
|
| 168 | 173 | <input type="submit" name="save_draft" value="', $txt['draft_save'], '" tabindex="', --$tempTab, '" onclick="return confirm(' . JavaScriptEscape($txt['draft_save_note']) . ') && submitThisOnce(this);" accesskey="d" class="button_submit"> |
| 169 | 174 | <input type="hidden" id="id_draft" name="id_draft" value="', empty($context['id_draft']) ? 0 : $context['id_draft'], '">'; |
| 175 | + } |
|
| 170 | 176 | |
| 171 | - if ($context['show_spellchecking']) |
|
| 172 | - echo ' |
|
| 177 | + if ($context['show_spellchecking']) { |
|
| 178 | + echo ' |
|
| 173 | 179 | <input type="button" value="', $txt['spell_check'], '" tabindex="', --$tempTab, '" onclick="oEditorHandle_', $editor_id, '.spellCheckStart();" class="button_submit">'; |
| 180 | + } |
|
| 174 | 181 | |
| 175 | - if ($editor_context['preview_type']) |
|
| 176 | - echo ' |
|
| 182 | + if ($editor_context['preview_type']) { |
|
| 183 | + echo ' |
|
| 177 | 184 | <input type="submit" name="preview" value="', isset($editor_context['labels']['preview_button']) ? $editor_context['labels']['preview_button'] : $txt['preview'], '" tabindex="', --$tempTab, '" onclick="', $editor_context['preview_type'] == 2 ? 'return event.ctrlKey || previewPost();' : 'return submitThisOnce(this);', '" accesskey="p" class="button_submit">'; |
| 185 | + } |
|
| 178 | 186 | |
| 179 | 187 | |
| 180 | 188 | echo ' |
| 181 | 189 | <input type="submit" value="', isset($editor_context['labels']['post_button']) ? $editor_context['labels']['post_button'] : $txt['post'], '" name="post" tabindex="', --$tempTab, '" onclick="return submitThisOnce(this);" accesskey="s" class="button_submit">'; |
| 182 | 190 | |
| 183 | 191 | // Load in the PM autosaver if it's enabled |
| 184 | - if (!empty($context['drafts_pm_save']) && !empty($context['drafts_autosave'])) |
|
| 185 | - echo ' |
|
| 192 | + if (!empty($context['drafts_pm_save']) && !empty($context['drafts_autosave'])) { |
|
| 193 | + echo ' |
|
| 186 | 194 | <span class="righttext padding" style="display: block"> |
| 187 | 195 | <span id="throbber" style="display:none"><img src="' . $settings['images_url'] . '/loading_sm.gif" alt="" class="centericon"> </span> |
| 188 | 196 | <span id="draft_lastautosave" ></span> |
@@ -200,10 +208,11 @@ discard block |
||
| 200 | 208 | iFreq: ', (empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000), ' |
| 201 | 209 | }); |
| 202 | 210 | </script>'; |
| 211 | + } |
|
| 203 | 212 | |
| 204 | 213 | // Start an instance of the auto saver if its enabled |
| 205 | - if (!empty($context['drafts_save']) && !empty($context['drafts_autosave'])) |
|
| 206 | - echo ' |
|
| 214 | + if (!empty($context['drafts_save']) && !empty($context['drafts_autosave'])) { |
|
| 215 | + echo ' |
|
| 207 | 216 | <span class="righttext padding" style="display: block"> |
| 208 | 217 | <span id="throbber" style="display:none"><img src="' . $settings['images_url'] . '/loading_sm.gif" alt="" class="centericon"> </span> |
| 209 | 218 | <span id="draft_lastautosave" ></span> |
@@ -220,7 +229,8 @@ discard block |
||
| 220 | 229 | iFreq: ', $context['drafts_autosave_frequency'], ' |
| 221 | 230 | }); |
| 222 | 231 | </script>'; |
| 223 | -} |
|
| 232 | + } |
|
| 233 | + } |
|
| 224 | 234 | |
| 225 | 235 | /** |
| 226 | 236 | * This template displays a verification form |
@@ -237,51 +247,57 @@ discard block |
||
| 237 | 247 | $verify_context = &$context['controls']['verification'][$verify_id]; |
| 238 | 248 | |
| 239 | 249 | // Keep track of where we are. |
| 240 | - if (empty($verify_context['tracking']) || $reset) |
|
| 241 | - $verify_context['tracking'] = 0; |
|
| 250 | + if (empty($verify_context['tracking']) || $reset) { |
|
| 251 | + $verify_context['tracking'] = 0; |
|
| 252 | + } |
|
| 242 | 253 | |
| 243 | 254 | // How many items are there to display in total. |
| 244 | 255 | $total_items = count($verify_context['questions']) + ($verify_context['show_visual'] || $verify_context['can_recaptcha'] ? 1 : 0); |
| 245 | 256 | |
| 246 | 257 | // If we've gone too far, stop. |
| 247 | - if ($verify_context['tracking'] > $total_items) |
|
| 248 | - return false; |
|
| 258 | + if ($verify_context['tracking'] > $total_items) { |
|
| 259 | + return false; |
|
| 260 | + } |
|
| 249 | 261 | |
| 250 | 262 | // Loop through each item to show them. |
| 251 | 263 | for ($i = 0; $i < $total_items; $i++) |
| 252 | 264 | { |
| 253 | 265 | // If we're after a single item only show it if we're in the right place. |
| 254 | - if ($display_type == 'single' && $verify_context['tracking'] != $i) |
|
| 255 | - continue; |
|
| 266 | + if ($display_type == 'single' && $verify_context['tracking'] != $i) { |
|
| 267 | + continue; |
|
| 268 | + } |
|
| 256 | 269 | |
| 257 | - if ($display_type != 'single') |
|
| 258 | - echo ' |
|
| 270 | + if ($display_type != 'single') { |
|
| 271 | + echo ' |
|
| 259 | 272 | <div id="verification_control_', $i, '" class="verification_control">'; |
| 273 | + } |
|
| 260 | 274 | |
| 261 | 275 | // Display empty field, but only if we have one, and it's the first time. |
| 262 | - if ($verify_context['empty_field'] && empty($i)) |
|
| 263 | - echo ' |
|
| 276 | + if ($verify_context['empty_field'] && empty($i)) { |
|
| 277 | + echo ' |
|
| 264 | 278 | <div class="smalltext vv_special"> |
| 265 | 279 | ', $txt['visual_verification_hidden'], ': |
| 266 | 280 | <input type="text" name="', $_SESSION[$verify_id . '_vv']['empty_field'], '" autocomplete="off" size="30" value=""> |
| 267 | 281 | </div>'; |
| 282 | + } |
|
| 268 | 283 | |
| 269 | 284 | // Do the actual stuff |
| 270 | 285 | if ($i == 0 && ($verify_context['show_visual'] || $verify_context['can_recaptcha'])) |
| 271 | 286 | { |
| 272 | 287 | if ($verify_context['show_visual']) |
| 273 | 288 | { |
| 274 | - if ($context['use_graphic_library']) |
|
| 275 | - echo ' |
|
| 289 | + if ($context['use_graphic_library']) { |
|
| 290 | + echo ' |
|
| 276 | 291 | <img src="', $verify_context['image_href'], '" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '">'; |
| 277 | - else |
|
| 278 | - echo ' |
|
| 292 | + } else { |
|
| 293 | + echo ' |
|
| 279 | 294 | <img src="', $verify_context['image_href'], ';letter=1" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_1"> |
| 280 | 295 | <img src="', $verify_context['image_href'], ';letter=2" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_2"> |
| 281 | 296 | <img src="', $verify_context['image_href'], ';letter=3" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_3"> |
| 282 | 297 | <img src="', $verify_context['image_href'], ';letter=4" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_4"> |
| 283 | 298 | <img src="', $verify_context['image_href'], ';letter=5" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_5"> |
| 284 | 299 | <img src="', $verify_context['image_href'], ';letter=6" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_6">'; |
| 300 | + } |
|
| 285 | 301 | |
| 286 | 302 | echo ' |
| 287 | 303 | <div class="smalltext" style="margin: 4px 0 8px 0;"> |
@@ -297,8 +313,7 @@ discard block |
||
| 297 | 313 | <div class="g-recaptcha centertext" data-sitekey="' . $verify_context['recaptcha_site_key'] . '" data-theme="' . $verify_context['recaptcha_theme'] . '"></div><br> |
| 298 | 314 | <script type="text/javascript" src="https://www.google.com/recaptcha/api.js"></script>'; |
| 299 | 315 | } |
| 300 | - } |
|
| 301 | - else |
|
| 316 | + } else |
|
| 302 | 317 | { |
| 303 | 318 | // Where in the question array is this question? |
| 304 | 319 | $qIndex = $verify_context['show_visual'] ? $i - 1 : $i; |
@@ -310,21 +325,24 @@ discard block |
||
| 310 | 325 | </div>'; |
| 311 | 326 | } |
| 312 | 327 | |
| 313 | - if ($display_type != 'single') |
|
| 314 | - echo ' |
|
| 328 | + if ($display_type != 'single') { |
|
| 329 | + echo ' |
|
| 315 | 330 | </div>'; |
| 331 | + } |
|
| 316 | 332 | |
| 317 | 333 | // If we were displaying just one and we did it, break. |
| 318 | - if ($display_type == 'single' && $verify_context['tracking'] == $i) |
|
| 319 | - break; |
|
| 334 | + if ($display_type == 'single' && $verify_context['tracking'] == $i) { |
|
| 335 | + break; |
|
| 336 | + } |
|
| 320 | 337 | } |
| 321 | 338 | |
| 322 | 339 | // Assume we found something, always, |
| 323 | 340 | $verify_context['tracking']++; |
| 324 | 341 | |
| 325 | 342 | // Tell something displaying piecemeal to keep going. |
| 326 | - if ($display_type == 'single') |
|
| 327 | - return true; |
|
| 328 | -} |
|
| 343 | + if ($display_type == 'single') { |
|
| 344 | + return true; |
|
| 345 | + } |
|
| 346 | + } |
|
| 329 | 347 | |
| 330 | 348 | ?> |
| 331 | 349 | \ No newline at end of file |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 3 |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -if (!defined('SMF')) |
|
| 18 | +if (!defined('SMF')) { |
|
| 19 | 19 | die('No direct access...'); |
| 20 | +} |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * Main dispatcher. This function checks permissions and passes control through to the relevant section. |
@@ -245,8 +246,9 @@ discard block |
||
| 245 | 246 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 246 | 247 | { |
| 247 | 248 | // Private PM/email subjects and similar shouldn't be shown in the mailbox area. |
| 248 | - if (!empty($row['private'])) |
|
| 249 | - $row['subject'] = $txt['personal_message']; |
|
| 249 | + if (!empty($row['private'])) { |
|
| 250 | + $row['subject'] = $txt['personal_message']; |
|
| 251 | + } |
|
| 250 | 252 | |
| 251 | 253 | $mails[] = $row; |
| 252 | 254 | } |
@@ -300,8 +302,9 @@ discard block |
||
| 300 | 302 | $element = substr($key, strrpos($key, '_') + 1); |
| 301 | 303 | $processedBirthdayEmails[$index][$element] = $value; |
| 302 | 304 | } |
| 303 | - foreach ($processedBirthdayEmails as $index => $dummy) |
|
| 304 | - $emails[$index] = $index; |
|
| 305 | + foreach ($processedBirthdayEmails as $index => $dummy) { |
|
| 306 | + $emails[$index] = $index; |
|
| 307 | + } |
|
| 305 | 308 | |
| 306 | 309 | $config_vars = array( |
| 307 | 310 | // Mail queue stuff, this rocks ;) |
@@ -322,8 +325,9 @@ discard block |
||
| 322 | 325 | |
| 323 | 326 | call_integration_hook('integrate_modify_mail_settings', array(&$config_vars)); |
| 324 | 327 | |
| 325 | - if ($return_config) |
|
| 326 | - return $config_vars; |
|
| 328 | + if ($return_config) { |
|
| 329 | + return $config_vars; |
|
| 330 | + } |
|
| 327 | 331 | |
| 328 | 332 | // Saving? |
| 329 | 333 | if (isset($_GET['save'])) |
@@ -398,9 +402,9 @@ discard block |
||
| 398 | 402 | ); |
| 399 | 403 | list ($_GET['te']) = $smcFunc['db_fetch_row']($request); |
| 400 | 404 | $smcFunc['db_free_result']($request); |
| 405 | + } else { |
|
| 406 | + $_GET['te'] = (int) $_GET['te']; |
|
| 401 | 407 | } |
| 402 | - else |
|
| 403 | - $_GET['te'] = (int) $_GET['te']; |
|
| 404 | 408 | |
| 405 | 409 | $_GET['sent'] = isset($_GET['sent']) ? (int) $_GET['sent'] : 0; |
| 406 | 410 | |
@@ -424,12 +428,14 @@ discard block |
||
| 424 | 428 | |
| 425 | 429 | // Try get more time... |
| 426 | 430 | @set_time_limit(600); |
| 427 | - if (function_exists('apache_reset_timeout')) |
|
| 428 | - @apache_reset_timeout(); |
|
| 431 | + if (function_exists('apache_reset_timeout')) { |
|
| 432 | + @apache_reset_timeout(); |
|
| 433 | + } |
|
| 429 | 434 | |
| 430 | 435 | // Have we already used our maximum time? |
| 431 | - if (time() - array_sum(explode(' ', $time_start)) < 5) |
|
| 432 | - return; |
|
| 436 | + if (time() - array_sum(explode(' ', $time_start)) < 5) { |
|
| 437 | + return; |
|
| 438 | + } |
|
| 433 | 439 | |
| 434 | 440 | $context['continue_get_data'] = '?action=admin;area=mailqueue;sa=clear;te=' . $_GET['te'] . ';sent=' . $_GET['sent'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
| 435 | 441 | $context['page_title'] = $txt['not_done_title']; |
@@ -459,8 +465,9 @@ discard block |
||
| 459 | 465 | { |
| 460 | 466 | global $txt; |
| 461 | 467 | |
| 462 | - if ($time_diff < 0) |
|
| 463 | - $time_diff = 0; |
|
| 468 | + if ($time_diff < 0) { |
|
| 469 | + $time_diff = 0; |
|
| 470 | + } |
|
| 464 | 471 | |
| 465 | 472 | // Just do a bit of an if fest... |
| 466 | 473 | if ($time_diff > 86400) |
@@ -481,8 +488,9 @@ discard block |
||
| 481 | 488 | return sprintf($minutes == 1 ? $txt['mq_minute'] : $txt['mq_minutes'], $minutes); |
| 482 | 489 | } |
| 483 | 490 | // Otherwise must be second |
| 484 | - else |
|
| 485 | - return sprintf($time_diff == 1 ? $txt['mq_second'] : $txt['mq_seconds'], $time_diff); |
|
| 486 | -} |
|
| 491 | + else { |
|
| 492 | + return sprintf($time_diff == 1 ? $txt['mq_second'] : $txt['mq_seconds'], $time_diff); |
|
| 493 | + } |
|
| 494 | + } |
|
| 487 | 495 | |
| 488 | 496 | ?> |
| 489 | 497 | \ No newline at end of file |
@@ -12,7 +12,8 @@ |
||
| 12 | 12 | header('Location: ' . $boardurl); |
| 13 | 13 | } |
| 14 | 14 | // Can't find it... just forget it. |
| 15 | -else |
|
| 15 | +else { |
|
| 16 | 16 | exit; |
| 17 | +} |
|
| 17 | 18 | |
| 18 | 19 | ?> |
| 19 | 20 | \ No newline at end of file |
@@ -12,7 +12,8 @@ |
||
| 12 | 12 | header('Location: ' . $boardurl); |
| 13 | 13 | } |
| 14 | 14 | // Can't find it... just forget it. |
| 15 | -else |
|
| 15 | +else { |
|
| 16 | 16 | exit; |
| 17 | +} |
|
| 17 | 18 | |
| 18 | 19 | ?> |
| 19 | 20 | \ No newline at end of file |