@@ -807,7 +807,7 @@ |
||
| 807 | 807 | /** |
| 808 | 808 | * Send a group of emails from the mail queue. |
| 809 | 809 | * |
| 810 | - * @param bool|int $number The number to send each loop through or false to use the standard limits |
|
| 810 | + * @param integer $number The number to send each loop through or false to use the standard limits |
|
| 811 | 811 | * @param bool $override_limit Whether to bypass the limit |
| 812 | 812 | * @param bool $force_send Whether to forcibly send the messages now (useful when using cron jobs) |
| 813 | 813 | * @return bool Whether things were sent |
@@ -384,7 +384,7 @@ |
||
| 384 | 384 | clean_cache(); |
| 385 | 385 | |
| 386 | 386 | // If warning decrement is enabled and we have people who have not had a new warning in 24 hours, lower their warning level. |
| 387 | - list (, , $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']); |
|
| 387 | + list (,, $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']); |
|
| 388 | 388 | if ($modSettings['warning_decrement']) |
| 389 | 389 | { |
| 390 | 390 | // Find every member who has a warning level... |
@@ -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' || $db_type == 'mysqli') && 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' || $db_type == 'mysqli') && 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(); |
@@ -651,8 +686,9 @@ discard block |
||
| 651 | 686 | $notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1; |
| 652 | 687 | |
| 653 | 688 | // Did they not elect to choose this? |
| 654 | - if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) |
|
| 655 | - continue; |
|
| 689 | + if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) { |
|
| 690 | + continue; |
|
| 691 | + } |
|
| 656 | 692 | |
| 657 | 693 | // Right character set! |
| 658 | 694 | $context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set']; |
@@ -668,39 +704,43 @@ discard block |
||
| 668 | 704 | if (isset($types['topic'])) |
| 669 | 705 | { |
| 670 | 706 | $titled = false; |
| 671 | - foreach ($types['topic'] as $id => $board) |
|
| 672 | - foreach ($board['lines'] as $topic) |
|
| 707 | + foreach ($types['topic'] as $id => $board) { |
|
| 708 | + foreach ($board['lines'] as $topic) |
|
| 673 | 709 | if (in_array($mid, $topic['members'])) |
| 674 | 710 | { |
| 675 | 711 | if (!$titled) |
| 676 | 712 | { |
| 677 | 713 | $email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------'; |
| 714 | + } |
|
| 678 | 715 | $titled = true; |
| 679 | 716 | } |
| 680 | 717 | $email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']); |
| 681 | 718 | } |
| 682 | - if ($titled) |
|
| 683 | - $email['body'] .= "\n"; |
|
| 719 | + if ($titled) { |
|
| 720 | + $email['body'] .= "\n"; |
|
| 721 | + } |
|
| 684 | 722 | } |
| 685 | 723 | |
| 686 | 724 | // What about replies? |
| 687 | 725 | if (isset($types['reply'])) |
| 688 | 726 | { |
| 689 | 727 | $titled = false; |
| 690 | - foreach ($types['reply'] as $id => $board) |
|
| 691 | - foreach ($board['lines'] as $topic) |
|
| 728 | + foreach ($types['reply'] as $id => $board) { |
|
| 729 | + foreach ($board['lines'] as $topic) |
|
| 692 | 730 | if (in_array($mid, $topic['members'])) |
| 693 | 731 | { |
| 694 | 732 | if (!$titled) |
| 695 | 733 | { |
| 696 | 734 | $email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------'; |
| 735 | + } |
|
| 697 | 736 | $titled = true; |
| 698 | 737 | } |
| 699 | 738 | $email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject'])); |
| 700 | 739 | } |
| 701 | 740 | |
| 702 | - if ($titled) |
|
| 703 | - $email['body'] .= "\n"; |
|
| 741 | + if ($titled) { |
|
| 742 | + $email['body'] .= "\n"; |
|
| 743 | + } |
|
| 704 | 744 | } |
| 705 | 745 | |
| 706 | 746 | // Finally, moderation actions! |
@@ -709,24 +749,27 @@ discard block |
||
| 709 | 749 | $titled = false; |
| 710 | 750 | foreach ($types as $note_type => $type) |
| 711 | 751 | { |
| 712 | - if ($note_type == 'topic' || $note_type == 'reply') |
|
| 713 | - continue; |
|
| 752 | + if ($note_type == 'topic' || $note_type == 'reply') { |
|
| 753 | + continue; |
|
| 754 | + } |
|
| 714 | 755 | |
| 715 | - foreach ($type as $id => $board) |
|
| 716 | - foreach ($board['lines'] as $topic) |
|
| 756 | + foreach ($type as $id => $board) { |
|
| 757 | + foreach ($board['lines'] as $topic) |
|
| 717 | 758 | if (in_array($mid, $topic['members'])) |
| 718 | 759 | { |
| 719 | 760 | if (!$titled) |
| 720 | 761 | { |
| 721 | 762 | $email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------'; |
| 763 | + } |
|
| 722 | 764 | $titled = true; |
| 723 | 765 | } |
| 724 | 766 | $email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']); |
| 725 | 767 | } |
| 726 | 768 | } |
| 727 | 769 | } |
| 728 | - if ($titled) |
|
| 729 | - $email['body'] .= "\n"; |
|
| 770 | + if ($titled) { |
|
| 771 | + $email['body'] .= "\n"; |
|
| 772 | + } |
|
| 730 | 773 | |
| 731 | 774 | // Then just say our goodbyes! |
| 732 | 775 | $email['body'] .= "\n\n" . $txt['regards_team']; |
@@ -754,8 +797,7 @@ discard block |
||
| 754 | 797 | 'not_daily' => 0, |
| 755 | 798 | ) |
| 756 | 799 | ); |
| 757 | - } |
|
| 758 | - else |
|
| 800 | + } else |
|
| 759 | 801 | { |
| 760 | 802 | // Clear any only weekly ones, and stop us from sending daily again. |
| 761 | 803 | $smcFunc['db_query']('', ' |
@@ -817,16 +859,19 @@ discard block |
||
| 817 | 859 | global $modSettings, $smcFunc, $sourcedir; |
| 818 | 860 | |
| 819 | 861 | // Are we intending another script to be sending out the queue? |
| 820 | - if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) |
|
| 821 | - return false; |
|
| 862 | + if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) { |
|
| 863 | + return false; |
|
| 864 | + } |
|
| 822 | 865 | |
| 823 | 866 | // By default send 5 at once. |
| 824 | - if (!$number) |
|
| 825 | - $number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity']; |
|
| 867 | + if (!$number) { |
|
| 868 | + $number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity']; |
|
| 869 | + } |
|
| 826 | 870 | |
| 827 | 871 | // If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us. |
| 828 | - if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) |
|
| 829 | - return false; |
|
| 872 | + if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) { |
|
| 873 | + return false; |
|
| 874 | + } |
|
| 830 | 875 | |
| 831 | 876 | // By default move the next sending on by 10 seconds, and require an affected row. |
| 832 | 877 | if (!$override_limit) |
@@ -843,8 +888,9 @@ discard block |
||
| 843 | 888 | 'last_send' => $modSettings['mail_next_send'], |
| 844 | 889 | ) |
| 845 | 890 | ); |
| 846 | - if ($smcFunc['db_affected_rows']() == 0) |
|
| 847 | - return false; |
|
| 891 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
| 892 | + return false; |
|
| 893 | + } |
|
| 848 | 894 | $modSettings['mail_next_send'] = time() + $delay; |
| 849 | 895 | } |
| 850 | 896 | |
@@ -865,8 +911,9 @@ discard block |
||
| 865 | 911 | $mn += $number; |
| 866 | 912 | } |
| 867 | 913 | // No more I'm afraid, return! |
| 868 | - else |
|
| 869 | - return false; |
|
| 914 | + else { |
|
| 915 | + return false; |
|
| 916 | + } |
|
| 870 | 917 | |
| 871 | 918 | // Reflect that we're about to send some, do it now to be safe. |
| 872 | 919 | updateSettings(array('mail_recent' => $mt . '|' . $mn)); |
@@ -901,14 +948,15 @@ discard block |
||
| 901 | 948 | $smcFunc['db_free_result']($request); |
| 902 | 949 | |
| 903 | 950 | // Delete, delete, delete!!! |
| 904 | - if (!empty($ids)) |
|
| 905 | - $smcFunc['db_query']('', ' |
|
| 951 | + if (!empty($ids)) { |
|
| 952 | + $smcFunc['db_query']('', ' |
|
| 906 | 953 | DELETE FROM {db_prefix}mail_queue |
| 907 | 954 | WHERE id_mail IN ({array_int:mail_list})', |
| 908 | 955 | array( |
| 909 | 956 | 'mail_list' => $ids, |
| 910 | 957 | ) |
| 911 | 958 | ); |
| 959 | + } |
|
| 912 | 960 | |
| 913 | 961 | // Don't believe we have any left? |
| 914 | 962 | if (count($ids) < $number) |
@@ -926,11 +974,13 @@ discard block |
||
| 926 | 974 | ); |
| 927 | 975 | } |
| 928 | 976 | |
| 929 | - if (empty($ids)) |
|
| 930 | - return false; |
|
| 977 | + if (empty($ids)) { |
|
| 978 | + return false; |
|
| 979 | + } |
|
| 931 | 980 | |
| 932 | - if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') |
|
| 933 | - require_once($sourcedir . '/Subs-Post.php'); |
|
| 981 | + if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') { |
|
| 982 | + require_once($sourcedir . '/Subs-Post.php'); |
|
| 983 | + } |
|
| 934 | 984 | |
| 935 | 985 | // Send each email, yea! |
| 936 | 986 | $failed_emails = array(); |
@@ -950,15 +1000,17 @@ discard block |
||
| 950 | 1000 | |
| 951 | 1001 | // Try to stop a timeout, this would be bad... |
| 952 | 1002 | @set_time_limit(300); |
| 953 | - if (function_exists('apache_reset_timeout')) |
|
| 954 | - @apache_reset_timeout(); |
|
| 1003 | + if (function_exists('apache_reset_timeout')) { |
|
| 1004 | + @apache_reset_timeout(); |
|
| 1005 | + } |
|
| 1006 | + } else { |
|
| 1007 | + $result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']); |
|
| 955 | 1008 | } |
| 956 | - else |
|
| 957 | - $result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']); |
|
| 958 | 1009 | |
| 959 | 1010 | // Hopefully it sent? |
| 960 | - if (!$result) |
|
| 961 | - $failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']); |
|
| 1011 | + if (!$result) { |
|
| 1012 | + $failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']); |
|
| 1013 | + } |
|
| 962 | 1014 | } |
| 963 | 1015 | |
| 964 | 1016 | // Any emails that didn't send? |
@@ -973,8 +1025,8 @@ discard block |
||
| 973 | 1025 | ); |
| 974 | 1026 | |
| 975 | 1027 | // If we have failed to many times, tell mail to wait a bit and try again. |
| 976 | - if ($modSettings['mail_failed_attempts'] > 5) |
|
| 977 | - $smcFunc['db_query']('', ' |
|
| 1028 | + if ($modSettings['mail_failed_attempts'] > 5) { |
|
| 1029 | + $smcFunc['db_query']('', ' |
|
| 978 | 1030 | UPDATE {db_prefix}settings |
| 979 | 1031 | SET value = {string:next_mail_send} |
| 980 | 1032 | WHERE variable = {literal:mail_next_send} |
@@ -983,6 +1035,7 @@ discard block |
||
| 983 | 1035 | 'next_mail_send' => time() + 60, |
| 984 | 1036 | 'last_send' => $modSettings['mail_next_send'], |
| 985 | 1037 | )); |
| 1038 | + } |
|
| 986 | 1039 | |
| 987 | 1040 | // Add our email back to the queue, manually. |
| 988 | 1041 | $smcFunc['db_insert']('insert', |
@@ -995,8 +1048,8 @@ discard block |
||
| 995 | 1048 | return false; |
| 996 | 1049 | } |
| 997 | 1050 | // We where unable to send the email, clear our failed attempts. |
| 998 | - elseif (!empty($modSettings['mail_failed_attempts'])) |
|
| 999 | - $smcFunc['db_query']('', ' |
|
| 1051 | + elseif (!empty($modSettings['mail_failed_attempts'])) { |
|
| 1052 | + $smcFunc['db_query']('', ' |
|
| 1000 | 1053 | UPDATE {db_prefix}settings |
| 1001 | 1054 | SET value = {string:zero} |
| 1002 | 1055 | WHERE variable = {string:mail_failed_attempts}', |
@@ -1004,6 +1057,7 @@ discard block |
||
| 1004 | 1057 | 'zero' => '0', |
| 1005 | 1058 | 'mail_failed_attempts' => 'mail_failed_attempts', |
| 1006 | 1059 | )); |
| 1060 | + } |
|
| 1007 | 1061 | |
| 1008 | 1062 | // Had something to send... |
| 1009 | 1063 | return true; |
@@ -1020,16 +1074,18 @@ discard block |
||
| 1020 | 1074 | global $modSettings, $smcFunc; |
| 1021 | 1075 | |
| 1022 | 1076 | $task_query = ''; |
| 1023 | - if (!is_array($tasks)) |
|
| 1024 | - $tasks = array($tasks); |
|
| 1077 | + if (!is_array($tasks)) { |
|
| 1078 | + $tasks = array($tasks); |
|
| 1079 | + } |
|
| 1025 | 1080 | |
| 1026 | 1081 | // Actually have something passed? |
| 1027 | 1082 | if (!empty($tasks)) |
| 1028 | 1083 | { |
| 1029 | - if (!isset($tasks[0]) || is_numeric($tasks[0])) |
|
| 1030 | - $task_query = ' AND id_task IN ({array_int:tasks})'; |
|
| 1031 | - else |
|
| 1032 | - $task_query = ' AND task IN ({array_string:tasks})'; |
|
| 1084 | + if (!isset($tasks[0]) || is_numeric($tasks[0])) { |
|
| 1085 | + $task_query = ' AND id_task IN ({array_int:tasks})'; |
|
| 1086 | + } else { |
|
| 1087 | + $task_query = ' AND task IN ({array_string:tasks})'; |
|
| 1088 | + } |
|
| 1033 | 1089 | } |
| 1034 | 1090 | $nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time']; |
| 1035 | 1091 | |
@@ -1050,20 +1106,22 @@ discard block |
||
| 1050 | 1106 | $next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']); |
| 1051 | 1107 | |
| 1052 | 1108 | // Only bother moving the task if it's out of place or we're forcing it! |
| 1053 | - if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) |
|
| 1054 | - $tasks[$row['id_task']] = $next_time; |
|
| 1055 | - else |
|
| 1056 | - $next_time = $row['next_time']; |
|
| 1109 | + if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) { |
|
| 1110 | + $tasks[$row['id_task']] = $next_time; |
|
| 1111 | + } else { |
|
| 1112 | + $next_time = $row['next_time']; |
|
| 1113 | + } |
|
| 1057 | 1114 | |
| 1058 | 1115 | // If this is sooner than the current next task, make this the next task. |
| 1059 | - if ($next_time < $nextTaskTime) |
|
| 1060 | - $nextTaskTime = $next_time; |
|
| 1116 | + if ($next_time < $nextTaskTime) { |
|
| 1117 | + $nextTaskTime = $next_time; |
|
| 1118 | + } |
|
| 1061 | 1119 | } |
| 1062 | 1120 | $smcFunc['db_free_result']($request); |
| 1063 | 1121 | |
| 1064 | 1122 | // Now make the changes! |
| 1065 | - foreach ($tasks as $id => $time) |
|
| 1066 | - $smcFunc['db_query']('', ' |
|
| 1123 | + foreach ($tasks as $id => $time) { |
|
| 1124 | + $smcFunc['db_query']('', ' |
|
| 1067 | 1125 | UPDATE {db_prefix}scheduled_tasks |
| 1068 | 1126 | SET next_time = {int:next_time} |
| 1069 | 1127 | WHERE id_task = {int:id_task}', |
@@ -1072,11 +1130,13 @@ discard block |
||
| 1072 | 1130 | 'id_task' => $id, |
| 1073 | 1131 | ) |
| 1074 | 1132 | ); |
| 1133 | + } |
|
| 1075 | 1134 | |
| 1076 | 1135 | // If the next task is now different update. |
| 1077 | - if ($modSettings['next_task_time'] != $nextTaskTime) |
|
| 1078 | - updateSettings(array('next_task_time' => $nextTaskTime)); |
|
| 1079 | -} |
|
| 1136 | + if ($modSettings['next_task_time'] != $nextTaskTime) { |
|
| 1137 | + updateSettings(array('next_task_time' => $nextTaskTime)); |
|
| 1138 | + } |
|
| 1139 | + } |
|
| 1080 | 1140 | |
| 1081 | 1141 | /** |
| 1082 | 1142 | * Simply returns a time stamp of the next instance of these time parameters. |
@@ -1089,8 +1149,9 @@ discard block |
||
| 1089 | 1149 | function next_time($regularity, $unit, $offset) |
| 1090 | 1150 | { |
| 1091 | 1151 | // Just in case! |
| 1092 | - if ($regularity == 0) |
|
| 1093 | - $regularity = 2; |
|
| 1152 | + if ($regularity == 0) { |
|
| 1153 | + $regularity = 2; |
|
| 1154 | + } |
|
| 1094 | 1155 | |
| 1095 | 1156 | $curHour = date('H', time()); |
| 1096 | 1157 | $curMin = date('i', time()); |
@@ -1102,15 +1163,16 @@ discard block |
||
| 1102 | 1163 | $off = date('i', $offset); |
| 1103 | 1164 | |
| 1104 | 1165 | // If it's now just pretend it ain't, |
| 1105 | - if ($off == $curMin) |
|
| 1106 | - $next_time = time() + $regularity; |
|
| 1107 | - else |
|
| 1166 | + if ($off == $curMin) { |
|
| 1167 | + $next_time = time() + $regularity; |
|
| 1168 | + } else |
|
| 1108 | 1169 | { |
| 1109 | 1170 | // Make sure that the offset is always in the past. |
| 1110 | 1171 | $off = $off > $curMin ? $off - 60 : $off; |
| 1111 | 1172 | |
| 1112 | - while ($off <= $curMin) |
|
| 1113 | - $off += $regularity; |
|
| 1173 | + while ($off <= $curMin) { |
|
| 1174 | + $off += $regularity; |
|
| 1175 | + } |
|
| 1114 | 1176 | |
| 1115 | 1177 | // Now we know when the time should be! |
| 1116 | 1178 | $next_time = time() + 60 * ($off - $curMin); |
@@ -1130,11 +1192,13 @@ discard block |
||
| 1130 | 1192 | // Default we'll jump in hours. |
| 1131 | 1193 | $applyOffset = 3600; |
| 1132 | 1194 | // 24 hours = 1 day. |
| 1133 | - if ($unit == 'd') |
|
| 1134 | - $applyOffset = 86400; |
|
| 1195 | + if ($unit == 'd') { |
|
| 1196 | + $applyOffset = 86400; |
|
| 1197 | + } |
|
| 1135 | 1198 | // Otherwise a week. |
| 1136 | - if ($unit == 'w') |
|
| 1137 | - $applyOffset = 604800; |
|
| 1199 | + if ($unit == 'w') { |
|
| 1200 | + $applyOffset = 604800; |
|
| 1201 | + } |
|
| 1138 | 1202 | |
| 1139 | 1203 | $applyOffset *= $regularity; |
| 1140 | 1204 | |
@@ -1171,8 +1235,9 @@ discard block |
||
| 1171 | 1235 | $settings[$row['variable']] = $row['value']; |
| 1172 | 1236 | |
| 1173 | 1237 | // Is this the default theme? |
| 1174 | - if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') |
|
| 1175 | - $settings['default_' . $row['variable']] = $row['value']; |
|
| 1238 | + if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') { |
|
| 1239 | + $settings['default_' . $row['variable']] = $row['value']; |
|
| 1240 | + } |
|
| 1176 | 1241 | } |
| 1177 | 1242 | $smcFunc['db_free_result']($result); |
| 1178 | 1243 | |
@@ -1182,12 +1247,14 @@ discard block |
||
| 1182 | 1247 | $settings['template_dirs'] = array($settings['theme_dir']); |
| 1183 | 1248 | |
| 1184 | 1249 | // Based on theme (if there is one). |
| 1185 | - if (!empty($settings['base_theme_dir'])) |
|
| 1186 | - $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
| 1250 | + if (!empty($settings['base_theme_dir'])) { |
|
| 1251 | + $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
| 1252 | + } |
|
| 1187 | 1253 | |
| 1188 | 1254 | // Lastly the default theme. |
| 1189 | - if ($settings['theme_dir'] != $settings['default_theme_dir']) |
|
| 1190 | - $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
| 1255 | + if ($settings['theme_dir'] != $settings['default_theme_dir']) { |
|
| 1256 | + $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
| 1257 | + } |
|
| 1191 | 1258 | } |
| 1192 | 1259 | |
| 1193 | 1260 | // Assume we want this. |
@@ -1333,8 +1400,9 @@ discard block |
||
| 1333 | 1400 | // Ok should we prune the logs? |
| 1334 | 1401 | if (!empty($modSettings['pruningOptions'])) |
| 1335 | 1402 | { |
| 1336 | - if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) |
|
| 1337 | - list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']); |
|
| 1403 | + if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) { |
|
| 1404 | + list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']); |
|
| 1405 | + } |
|
| 1338 | 1406 | |
| 1339 | 1407 | if (!empty($modSettings['pruneErrorLog'])) |
| 1340 | 1408 | { |
@@ -1400,8 +1468,9 @@ discard block |
||
| 1400 | 1468 | ) |
| 1401 | 1469 | ); |
| 1402 | 1470 | |
| 1403 | - while ($row = $smcFunc['db_fetch_row']($result)) |
|
| 1404 | - $reports[] = $row[0]; |
|
| 1471 | + while ($row = $smcFunc['db_fetch_row']($result)) { |
|
| 1472 | + $reports[] = $row[0]; |
|
| 1473 | + } |
|
| 1405 | 1474 | |
| 1406 | 1475 | $smcFunc['db_free_result']($result); |
| 1407 | 1476 | |
@@ -1563,8 +1632,9 @@ discard block |
||
| 1563 | 1632 | $emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']); |
| 1564 | 1633 | |
| 1565 | 1634 | // Send the actual email. |
| 1566 | - if ($notifyPrefs[$row['id_member']] & 0x02) |
|
| 1567 | - sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2); |
|
| 1635 | + if ($notifyPrefs[$row['id_member']] & 0x02) { |
|
| 1636 | + sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2); |
|
| 1637 | + } |
|
| 1568 | 1638 | |
| 1569 | 1639 | if ($notifyPrefs[$row['id_member']] & 0x01) |
| 1570 | 1640 | { |
@@ -1587,18 +1657,19 @@ discard block |
||
| 1587 | 1657 | } |
| 1588 | 1658 | |
| 1589 | 1659 | // Insert the alerts if any |
| 1590 | - if (!empty($alert_rows)) |
|
| 1591 | - $smcFunc['db_insert']('', |
|
| 1660 | + if (!empty($alert_rows)) { |
|
| 1661 | + $smcFunc['db_insert']('', |
|
| 1592 | 1662 | '{db_prefix}user_alerts', |
| 1593 | 1663 | array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string', |
| 1594 | 1664 | 'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'), |
| 1595 | 1665 | $alert_rows, |
| 1596 | 1666 | array() |
| 1597 | 1667 | ); |
| 1668 | + } |
|
| 1598 | 1669 | |
| 1599 | 1670 | // Mark the reminder as sent. |
| 1600 | - if (!empty($subs_reminded)) |
|
| 1601 | - $smcFunc['db_query']('', ' |
|
| 1671 | + if (!empty($subs_reminded)) { |
|
| 1672 | + $smcFunc['db_query']('', ' |
|
| 1602 | 1673 | UPDATE {db_prefix}log_subscribed |
| 1603 | 1674 | SET reminder_sent = {int:reminder_sent} |
| 1604 | 1675 | WHERE id_sublog IN ({array_int:subscription_list})', |
@@ -1607,6 +1678,7 @@ discard block |
||
| 1607 | 1678 | 'reminder_sent' => 1, |
| 1608 | 1679 | ) |
| 1609 | 1680 | ); |
| 1681 | + } |
|
| 1610 | 1682 | |
| 1611 | 1683 | return true; |
| 1612 | 1684 | } |
@@ -1622,13 +1694,13 @@ discard block |
||
| 1622 | 1694 | // We need to know where this thing is going. |
| 1623 | 1695 | if (!empty($modSettings['currentAttachmentUploadDir'])) |
| 1624 | 1696 | { |
| 1625 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
| 1626 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 1697 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
| 1698 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 1699 | + } |
|
| 1627 | 1700 | |
| 1628 | 1701 | // Just use the current path for temp files. |
| 1629 | 1702 | $attach_dirs = $modSettings['attachmentUploadDir']; |
| 1630 | - } |
|
| 1631 | - else |
|
| 1703 | + } else |
|
| 1632 | 1704 | { |
| 1633 | 1705 | $attach_dirs = array($modSettings['attachmentUploadDir']); |
| 1634 | 1706 | } |
@@ -1647,14 +1719,16 @@ discard block |
||
| 1647 | 1719 | |
| 1648 | 1720 | while ($file = readdir($dir)) |
| 1649 | 1721 | { |
| 1650 | - if ($file == '.' || $file == '..') |
|
| 1651 | - continue; |
|
| 1722 | + if ($file == '.' || $file == '..') { |
|
| 1723 | + continue; |
|
| 1724 | + } |
|
| 1652 | 1725 | |
| 1653 | 1726 | if (strpos($file, 'post_tmp_') !== false) |
| 1654 | 1727 | { |
| 1655 | 1728 | // Temp file is more than 5 hours old! |
| 1656 | - if (filemtime($attach_dir . '/' . $file) < time() - 18000) |
|
| 1657 | - @unlink($attach_dir . '/' . $file); |
|
| 1729 | + if (filemtime($attach_dir . '/' . $file) < time() - 18000) { |
|
| 1730 | + @unlink($attach_dir . '/' . $file); |
|
| 1731 | + } |
|
| 1658 | 1732 | } |
| 1659 | 1733 | } |
| 1660 | 1734 | closedir($dir); |
@@ -1687,8 +1761,9 @@ discard block |
||
| 1687 | 1761 | ) |
| 1688 | 1762 | ); |
| 1689 | 1763 | |
| 1690 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 1691 | - $topics[] = $row[0]; |
|
| 1764 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 1765 | + $topics[] = $row[0]; |
|
| 1766 | + } |
|
| 1692 | 1767 | $smcFunc['db_free_result']($request); |
| 1693 | 1768 | |
| 1694 | 1769 | // Zap, your gone |
@@ -1708,8 +1783,9 @@ discard block |
||
| 1708 | 1783 | { |
| 1709 | 1784 | global $smcFunc, $sourcedir, $modSettings; |
| 1710 | 1785 | |
| 1711 | - if (empty($modSettings['drafts_keep_days'])) |
|
| 1712 | - return true; |
|
| 1786 | + if (empty($modSettings['drafts_keep_days'])) { |
|
| 1787 | + return true; |
|
| 1788 | + } |
|
| 1713 | 1789 | |
| 1714 | 1790 | // init |
| 1715 | 1791 | $drafts = array(); |
@@ -1727,8 +1803,9 @@ discard block |
||
| 1727 | 1803 | ) |
| 1728 | 1804 | ); |
| 1729 | 1805 | |
| 1730 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 1731 | - $drafts[] = (int) $row[0]; |
|
| 1806 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 1807 | + $drafts[] = (int) $row[0]; |
|
| 1808 | + } |
|
| 1732 | 1809 | $smcFunc['db_free_result']($request); |
| 1733 | 1810 | |
| 1734 | 1811 | // If we have old one, remove them |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * Get a list of versions that are currently installed on the server. |
| 21 | - * @param array $checkFor An array of what to check versions for - can contain one or more of 'gd', 'imagemagick', 'db_server', 'phpa', 'memcache', 'xcache', 'apc', 'php' or 'server' |
|
| 21 | + * @param string[] $checkFor An array of what to check versions for - can contain one or more of 'gd', 'imagemagick', 'db_server', 'phpa', 'memcache', 'xcache', 'apc', 'php' or 'server' |
|
| 22 | 22 | * @return array An array of versions (keys are same as what was in $checkFor, values are the versions) |
| 23 | 23 | */ |
| 24 | 24 | function getServerVersions($checkFor) |
@@ -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 | * Get a list of versions that are currently installed on the server. |
@@ -45,8 +46,7 @@ discard block |
||
| 45 | 46 | $temp2 = $temp->getVersion(); |
| 46 | 47 | $im_version = $temp2['versionString']; |
| 47 | 48 | $extension_version = 'Imagick ' . phpversion('Imagick'); |
| 48 | - } |
|
| 49 | - else |
|
| 49 | + } else |
|
| 50 | 50 | { |
| 51 | 51 | $im_version = MagickGetVersionString(); |
| 52 | 52 | $extension_version = 'MagickWand ' . phpversion('MagickWand'); |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | if (in_array('db_server', $checkFor)) |
| 62 | 62 | { |
| 63 | 63 | db_extend(); |
| 64 | - if (!isset($db_connection) || $db_connection === false) |
|
| 65 | - trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE); |
|
| 66 | - else |
|
| 64 | + if (!isset($db_connection) || $db_connection === false) { |
|
| 65 | + trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE); |
|
| 66 | + } else |
|
| 67 | 67 | { |
| 68 | 68 | $versions['db_engine'] = array('title' => sprintf($txt['support_versions_db_engine'], $smcFunc['db_title']), 'version' => ''); |
| 69 | 69 | $versions['db_engine']['version'] = $smcFunc['db_get_engine'](); |
@@ -74,24 +74,31 @@ discard block |
||
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // If we're using memcache we need the server info. |
| 77 | - if (empty($memcached) && function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') |
|
| 78 | - get_memcached_server(); |
|
| 77 | + if (empty($memcached) && function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') { |
|
| 78 | + get_memcached_server(); |
|
| 79 | + } |
|
| 79 | 80 | |
| 80 | 81 | // Check to see if we have any accelerators installed... |
| 81 | - if (in_array('phpa', $checkFor) && isset($_PHPA)) |
|
| 82 | - $versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']); |
|
| 83 | - if (in_array('apc', $checkFor) && extension_loaded('apc')) |
|
| 84 | - $versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc')); |
|
| 85 | - if (in_array('memcache', $checkFor) && function_exists('memcache_set')) |
|
| 86 | - $versions['memcache'] = array('title' => 'Memcached', 'version' => empty($memcached) ? '???' : memcache_get_version($memcached)); |
|
| 87 | - if (in_array('xcache', $checkFor) && function_exists('xcache_set')) |
|
| 88 | - $versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION); |
|
| 82 | + if (in_array('phpa', $checkFor) && isset($_PHPA)) { |
|
| 83 | + $versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']); |
|
| 84 | + } |
|
| 85 | + if (in_array('apc', $checkFor) && extension_loaded('apc')) { |
|
| 86 | + $versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc')); |
|
| 87 | + } |
|
| 88 | + if (in_array('memcache', $checkFor) && function_exists('memcache_set')) { |
|
| 89 | + $versions['memcache'] = array('title' => 'Memcached', 'version' => empty($memcached) ? '???' : memcache_get_version($memcached)); |
|
| 90 | + } |
|
| 91 | + if (in_array('xcache', $checkFor) && function_exists('xcache_set')) { |
|
| 92 | + $versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION); |
|
| 93 | + } |
|
| 89 | 94 | |
| 90 | - if (in_array('php', $checkFor)) |
|
| 91 | - $versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo'); |
|
| 95 | + if (in_array('php', $checkFor)) { |
|
| 96 | + $versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo'); |
|
| 97 | + } |
|
| 92 | 98 | |
| 93 | - if (in_array('server', $checkFor)) |
|
| 94 | - $versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']); |
|
| 99 | + if (in_array('server', $checkFor)) { |
|
| 100 | + $versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']); |
|
| 101 | + } |
|
| 95 | 102 | |
| 96 | 103 | return $versions; |
| 97 | 104 | } |
@@ -131,11 +138,13 @@ discard block |
||
| 131 | 138 | fclose($fp); |
| 132 | 139 | |
| 133 | 140 | // The comment looks rougly like... that. |
| 134 | - if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) |
|
| 135 | - $version_info['file_versions']['SSI.php'] = $match[1]; |
|
| 141 | + if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) { |
|
| 142 | + $version_info['file_versions']['SSI.php'] = $match[1]; |
|
| 143 | + } |
|
| 136 | 144 | // Not found! This is bad. |
| 137 | - else |
|
| 138 | - $version_info['file_versions']['SSI.php'] = '??'; |
|
| 145 | + else { |
|
| 146 | + $version_info['file_versions']['SSI.php'] = '??'; |
|
| 147 | + } |
|
| 139 | 148 | } |
| 140 | 149 | |
| 141 | 150 | // Do the paid subscriptions handler? |
@@ -146,11 +155,13 @@ discard block |
||
| 146 | 155 | fclose($fp); |
| 147 | 156 | |
| 148 | 157 | // Found it? |
| 149 | - if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) |
|
| 150 | - $version_info['file_versions']['subscriptions.php'] = $match[1]; |
|
| 158 | + if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) { |
|
| 159 | + $version_info['file_versions']['subscriptions.php'] = $match[1]; |
|
| 160 | + } |
|
| 151 | 161 | // If we haven't how do we all get paid? |
| 152 | - else |
|
| 153 | - $version_info['file_versions']['subscriptions.php'] = '??'; |
|
| 162 | + else { |
|
| 163 | + $version_info['file_versions']['subscriptions.php'] = '??'; |
|
| 164 | + } |
|
| 154 | 165 | } |
| 155 | 166 | |
| 156 | 167 | // Load all the files in the Sources directory, except this file and the redirect. |
@@ -165,11 +176,13 @@ discard block |
||
| 165 | 176 | fclose($fp); |
| 166 | 177 | |
| 167 | 178 | // Look for the version comment in the file header. |
| 168 | - if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) |
|
| 169 | - $version_info['file_versions'][$entry] = $match[1]; |
|
| 179 | + if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) { |
|
| 180 | + $version_info['file_versions'][$entry] = $match[1]; |
|
| 181 | + } |
|
| 170 | 182 | // It wasn't found, but the file was... show a '??'. |
| 171 | - else |
|
| 172 | - $version_info['file_versions'][$entry] = '??'; |
|
| 183 | + else { |
|
| 184 | + $version_info['file_versions'][$entry] = '??'; |
|
| 185 | + } |
|
| 173 | 186 | } |
| 174 | 187 | } |
| 175 | 188 | $sources_dir->close(); |
@@ -188,11 +201,13 @@ discard block |
||
| 188 | 201 | fclose($fp); |
| 189 | 202 | |
| 190 | 203 | // Look for the version comment in the file header. |
| 191 | - if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) |
|
| 192 | - $version_info['tasks_versions'][$entry] = $match[1]; |
|
| 204 | + if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) { |
|
| 205 | + $version_info['tasks_versions'][$entry] = $match[1]; |
|
| 206 | + } |
|
| 193 | 207 | // It wasn't found, but the file was... show a '??'. |
| 194 | - else |
|
| 195 | - $version_info['tasks_versions'][$entry] = '??'; |
|
| 208 | + else { |
|
| 209 | + $version_info['tasks_versions'][$entry] = '??'; |
|
| 210 | + } |
|
| 196 | 211 | } |
| 197 | 212 | } |
| 198 | 213 | $tasks_dir->close(); |
@@ -200,8 +215,9 @@ discard block |
||
| 200 | 215 | |
| 201 | 216 | // Load all the files in the default template directory - and the current theme if applicable. |
| 202 | 217 | $directories = array('default_template_versions' => $settings['default_theme_dir']); |
| 203 | - if ($settings['theme_id'] != 1) |
|
| 204 | - $directories += array('template_versions' => $settings['theme_dir']); |
|
| 218 | + if ($settings['theme_id'] != 1) { |
|
| 219 | + $directories += array('template_versions' => $settings['theme_dir']); |
|
| 220 | + } |
|
| 205 | 221 | |
| 206 | 222 | foreach ($directories as $type => $dirname) |
| 207 | 223 | { |
@@ -216,11 +232,13 @@ discard block |
||
| 216 | 232 | fclose($fp); |
| 217 | 233 | |
| 218 | 234 | // Look for the version comment in the file header. |
| 219 | - if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) |
|
| 220 | - $version_info[$type][$entry] = $match[1]; |
|
| 235 | + if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) { |
|
| 236 | + $version_info[$type][$entry] = $match[1]; |
|
| 237 | + } |
|
| 221 | 238 | // It wasn't found, but the file was... show a '??'. |
| 222 | - else |
|
| 223 | - $version_info[$type][$entry] = '??'; |
|
| 239 | + else { |
|
| 240 | + $version_info[$type][$entry] = '??'; |
|
| 241 | + } |
|
| 224 | 242 | } |
| 225 | 243 | } |
| 226 | 244 | $this_dir->close(); |
@@ -241,11 +259,13 @@ discard block |
||
| 241 | 259 | list ($name, $language) = explode('.', $entry); |
| 242 | 260 | |
| 243 | 261 | // Look for the version comment in the file header. |
| 244 | - if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1) |
|
| 245 | - $version_info['default_language_versions'][$language][$name] = $match[1]; |
|
| 262 | + if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1) { |
|
| 263 | + $version_info['default_language_versions'][$language][$name] = $match[1]; |
|
| 264 | + } |
|
| 246 | 265 | // It wasn't found, but the file was... show a '??'. |
| 247 | - else |
|
| 248 | - $version_info['default_language_versions'][$language][$name] = '??'; |
|
| 266 | + else { |
|
| 267 | + $version_info['default_language_versions'][$language][$name] = '??'; |
|
| 268 | + } |
|
| 249 | 269 | } |
| 250 | 270 | } |
| 251 | 271 | $this_dir->close(); |
@@ -260,8 +280,9 @@ discard block |
||
| 260 | 280 | ksort($version_info['tasks_versions']); |
| 261 | 281 | |
| 262 | 282 | // For languages sort each language too. |
| 263 | - foreach ($version_info['default_language_versions'] as $language => $dummy) |
|
| 264 | - ksort($version_info['default_language_versions'][$language]); |
|
| 283 | + foreach ($version_info['default_language_versions'] as $language => $dummy) { |
|
| 284 | + ksort($version_info['default_language_versions'][$language]); |
|
| 285 | + } |
|
| 265 | 286 | } |
| 266 | 287 | return $version_info; |
| 267 | 288 | } |
@@ -303,27 +324,31 @@ discard block |
||
| 303 | 324 | $settingsArray = trim(file_get_contents($boarddir . '/Settings.php')); |
| 304 | 325 | |
| 305 | 326 | // Break it up based on \r or \n, and then clean out extra characters. |
| 306 | - if (strpos($settingsArray, "\n") !== false) |
|
| 307 | - $settingsArray = explode("\n", $settingsArray); |
|
| 308 | - elseif (strpos($settingsArray, "\r") !== false) |
|
| 309 | - $settingsArray = explode("\r", $settingsArray); |
|
| 310 | - else |
|
| 311 | - return; |
|
| 327 | + if (strpos($settingsArray, "\n") !== false) { |
|
| 328 | + $settingsArray = explode("\n", $settingsArray); |
|
| 329 | + } elseif (strpos($settingsArray, "\r") !== false) { |
|
| 330 | + $settingsArray = explode("\r", $settingsArray); |
|
| 331 | + } else { |
|
| 332 | + return; |
|
| 333 | + } |
|
| 312 | 334 | |
| 313 | 335 | // Presumably, the file has to have stuff in it for this function to be called :P. |
| 314 | - if (count($settingsArray) < 10) |
|
| 315 | - return; |
|
| 336 | + if (count($settingsArray) < 10) { |
|
| 337 | + return; |
|
| 338 | + } |
|
| 316 | 339 | |
| 317 | 340 | // remove any /r's that made there way in here |
| 318 | - foreach ($settingsArray as $k => $dummy) |
|
| 319 | - $settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n"; |
|
| 341 | + foreach ($settingsArray as $k => $dummy) { |
|
| 342 | + $settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n"; |
|
| 343 | + } |
|
| 320 | 344 | |
| 321 | 345 | // go line by line and see whats changing |
| 322 | 346 | for ($i = 0, $n = count($settingsArray); $i < $n; $i++) |
| 323 | 347 | { |
| 324 | 348 | // Don't trim or bother with it if it's not a variable. |
| 325 | - if (substr($settingsArray[$i], 0, 1) != '$') |
|
| 326 | - continue; |
|
| 349 | + if (substr($settingsArray[$i], 0, 1) != '$') { |
|
| 350 | + continue; |
|
| 351 | + } |
|
| 327 | 352 | |
| 328 | 353 | $settingsArray[$i] = trim($settingsArray[$i]) . "\n"; |
| 329 | 354 | |
@@ -335,8 +360,7 @@ discard block |
||
| 335 | 360 | { |
| 336 | 361 | updateDbLastError($val); |
| 337 | 362 | unset($config_vars[$var]); |
| 338 | - } |
|
| 339 | - elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
| 363 | + } elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
| 340 | 364 | { |
| 341 | 365 | $comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#'); |
| 342 | 366 | $settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment == '' ? '' : "\t\t" . rtrim($comment)) . "\n"; |
@@ -347,34 +371,39 @@ discard block |
||
| 347 | 371 | } |
| 348 | 372 | |
| 349 | 373 | // End of the file ... maybe |
| 350 | - if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') |
|
| 351 | - $end = $i; |
|
| 374 | + if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') { |
|
| 375 | + $end = $i; |
|
| 376 | + } |
|
| 352 | 377 | } |
| 353 | 378 | |
| 354 | 379 | // This should never happen, but apparently it is happening. |
| 355 | - if (empty($end) || $end < 10) |
|
| 356 | - $end = count($settingsArray) - 1; |
|
| 380 | + if (empty($end) || $end < 10) { |
|
| 381 | + $end = count($settingsArray) - 1; |
|
| 382 | + } |
|
| 357 | 383 | |
| 358 | 384 | // Still more variables to go? Then lets add them at the end. |
| 359 | 385 | if (!empty($config_vars)) |
| 360 | 386 | { |
| 361 | - if (trim($settingsArray[$end]) == '?' . '>') |
|
| 362 | - $settingsArray[$end++] = ''; |
|
| 363 | - else |
|
| 364 | - $end++; |
|
| 387 | + if (trim($settingsArray[$end]) == '?' . '>') { |
|
| 388 | + $settingsArray[$end++] = ''; |
|
| 389 | + } else { |
|
| 390 | + $end++; |
|
| 391 | + } |
|
| 365 | 392 | |
| 366 | 393 | // Add in any newly defined vars that were passed |
| 367 | - foreach ($config_vars as $var => $val) |
|
| 368 | - $settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n"; |
|
| 394 | + foreach ($config_vars as $var => $val) { |
|
| 395 | + $settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n"; |
|
| 396 | + } |
|
| 369 | 397 | |
| 370 | 398 | $settingsArray[$end] = '?' . '>'; |
| 399 | + } else { |
|
| 400 | + $settingsArray[$end] = trim($settingsArray[$end]); |
|
| 371 | 401 | } |
| 372 | - else |
|
| 373 | - $settingsArray[$end] = trim($settingsArray[$end]); |
|
| 374 | 402 | |
| 375 | 403 | // Sanity error checking: the file needs to be at least 12 lines. |
| 376 | - if (count($settingsArray) < 12) |
|
| 377 | - return; |
|
| 404 | + if (count($settingsArray) < 12) { |
|
| 405 | + return; |
|
| 406 | + } |
|
| 378 | 407 | |
| 379 | 408 | // Try to avoid a few pitfalls: |
| 380 | 409 | // - like a possible race condition, |
@@ -382,8 +411,9 @@ discard block |
||
| 382 | 411 | // |
| 383 | 412 | // Check before you act: if cache is enabled, we can do a simple write test |
| 384 | 413 | // to validate that we even write things on this filesystem. |
| 385 | - if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) |
|
| 386 | - $cachedir = $boarddir . '/cache'; |
|
| 414 | + if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) { |
|
| 415 | + $cachedir = $boarddir . '/cache'; |
|
| 416 | + } |
|
| 387 | 417 | |
| 388 | 418 | $test_fp = @fopen($cachedir . '/settings_update.tmp', "w+"); |
| 389 | 419 | if ($test_fp) |
@@ -419,16 +449,18 @@ discard block |
||
| 419 | 449 | // Well this is not good at all, lets see if we can save this |
| 420 | 450 | $context['settings_message'] = 'settings_error'; |
| 421 | 451 | |
| 422 | - if (file_exists($boarddir . '/Settings_bak.php')) |
|
| 423 | - @copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php'); |
|
| 452 | + if (file_exists($boarddir . '/Settings_bak.php')) { |
|
| 453 | + @copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php'); |
|
| 454 | + } |
|
| 424 | 455 | } |
| 425 | 456 | } |
| 426 | 457 | |
| 427 | 458 | // Even though on normal installations the filemtime should prevent this being used by the installer incorrectly |
| 428 | 459 | // it seems that there are times it might not. So let's MAKE it dump the cache. |
| 429 | - if (function_exists('opcache_invalidate')) |
|
| 430 | - opcache_invalidate($boarddir . '/Settings.php', true); |
|
| 431 | -} |
|
| 460 | + if (function_exists('opcache_invalidate')) { |
|
| 461 | + opcache_invalidate($boarddir . '/Settings.php', true); |
|
| 462 | + } |
|
| 463 | + } |
|
| 432 | 464 | |
| 433 | 465 | /** |
| 434 | 466 | * Saves the time of the last db error for the error log |
@@ -454,8 +486,9 @@ discard block |
||
| 454 | 486 | global $options, $context, $smcFunc, $settings, $user_info; |
| 455 | 487 | |
| 456 | 488 | // This must exist! |
| 457 | - if (!isset($context['admin_preferences'])) |
|
| 458 | - return false; |
|
| 489 | + if (!isset($context['admin_preferences'])) { |
|
| 490 | + return false; |
|
| 491 | + } |
|
| 459 | 492 | |
| 460 | 493 | // This is what we'll be saving. |
| 461 | 494 | $options['admin_preferences'] = json_encode($context['admin_preferences']); |
@@ -519,8 +552,9 @@ discard block |
||
| 519 | 552 | $emails_sent = array(); |
| 520 | 553 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 521 | 554 | { |
| 522 | - if (empty($prefs[$row['id_member']]['announcements'])) |
|
| 523 | - continue; |
|
| 555 | + if (empty($prefs[$row['id_member']]['announcements'])) { |
|
| 556 | + continue; |
|
| 557 | + } |
|
| 524 | 558 | |
| 525 | 559 | // Stick their particulars in the replacement data. |
| 526 | 560 | $replacements['IDMEMBER'] = $row['id_member']; |
@@ -539,11 +573,12 @@ discard block |
||
| 539 | 573 | $smcFunc['db_free_result']($request); |
| 540 | 574 | |
| 541 | 575 | // Any additional users we must email this to? |
| 542 | - if (!empty($additional_recipients)) |
|
| 543 | - foreach ($additional_recipients as $recipient) |
|
| 576 | + if (!empty($additional_recipients)) { |
|
| 577 | + foreach ($additional_recipients as $recipient) |
|
| 544 | 578 | { |
| 545 | 579 | if (in_array($recipient['email'], $emails_sent)) |
| 546 | 580 | continue; |
| 581 | + } |
|
| 547 | 582 | |
| 548 | 583 | $replacements['IDMEMBER'] = $recipient['id']; |
| 549 | 584 | $replacements['REALNAME'] = $recipient['name']; |
@@ -150,7 +150,7 @@ |
||
| 150 | 150 | * |
| 151 | 151 | * @param bool $local Whether we want local cookies |
| 152 | 152 | * @param bool $global Whether we want global cookies |
| 153 | - * @return array An array to set the cookie on with domain and path in it, in that order |
|
| 153 | + * @return string An array to set the cookie on with domain and path in it, in that order |
|
| 154 | 154 | */ |
| 155 | 155 | function url_parts($local, $global) |
| 156 | 156 | { |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | // This ensures you can't search someones email address if you can't see it. |
| 394 | 394 | if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) |
| 395 | 395 | $email_condition = ' |
| 396 | - OR (email_address ' . $comparison . ' \'' . implode( '\') OR (email_address ' . $comparison . ' \'', $names) . '\')'; |
|
| 396 | + OR (email_address ' . $comparison . ' \'' . implode('\') OR (email_address ' . $comparison . ' \'', $names) . '\')'; |
|
| 397 | 397 | else |
| 398 | 398 | $email_condition = ''; |
| 399 | 399 | |
@@ -412,8 +412,8 @@ discard block |
||
| 412 | 412 | LIMIT {int:limit}', |
| 413 | 413 | array( |
| 414 | 414 | 'buddy_list' => $user_info['buddies'], |
| 415 | - 'member_name_search' => $member_name . ' ' . $comparison . ' \'' . implode( '\' OR ' . $member_name . ' ' . $comparison . ' \'', $names) . '\'', |
|
| 416 | - 'real_name_search' => $real_name . ' ' . $comparison . ' \'' . implode( '\' OR ' . $real_name . ' ' . $comparison . ' \'', $names) . '\'', |
|
| 415 | + 'member_name_search' => $member_name . ' ' . $comparison . ' \'' . implode('\' OR ' . $member_name . ' ' . $comparison . ' \'', $names) . '\'', |
|
| 416 | + 'real_name_search' => $real_name . ' ' . $comparison . ' \'' . implode('\' OR ' . $real_name . ' ' . $comparison . ' \'', $names) . '\'', |
|
| 417 | 417 | 'email_condition' => $email_condition, |
| 418 | 418 | 'limit' => $max, |
| 419 | 419 | ) |
@@ -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 | * Sets the SMF-style login cookie and session based on the id_member and password passed. |
@@ -43,8 +44,9 @@ discard block |
||
| 43 | 44 | $array = smf_json_decode($_COOKIE[$cookiename], true); |
| 44 | 45 | |
| 45 | 46 | // Legacy format |
| 46 | - if (is_null($array)) |
|
| 47 | - $array = safe_unserialize($_COOKIE[$cookiename]); |
|
| 47 | + if (is_null($array)) { |
|
| 48 | + $array = safe_unserialize($_COOKIE[$cookiename]); |
|
| 49 | + } |
|
| 48 | 50 | |
| 49 | 51 | // Out with the old, in with the new! |
| 50 | 52 | if (isset($array[3]) && $array[3] != $cookie_state) |
@@ -62,8 +64,9 @@ discard block |
||
| 62 | 64 | smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]); |
| 63 | 65 | |
| 64 | 66 | // If subdomain-independent cookies are on, unset the subdomain-dependent cookie too. |
| 65 | - if (empty($id) && !empty($modSettings['globalCookies'])) |
|
| 66 | - smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], ''); |
|
| 67 | + if (empty($id) && !empty($modSettings['globalCookies'])) { |
|
| 68 | + smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], ''); |
|
| 69 | + } |
|
| 67 | 70 | |
| 68 | 71 | // Any alias URLs? This is mainly for use with frames, etc. |
| 69 | 72 | if (!empty($modSettings['forum_alias_urls'])) |
@@ -79,8 +82,9 @@ discard block |
||
| 79 | 82 | |
| 80 | 83 | $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])); |
| 81 | 84 | |
| 82 | - if ($cookie_url[0] == '') |
|
| 83 | - $cookie_url[0] = strtok($alias, '/'); |
|
| 85 | + if ($cookie_url[0] == '') { |
|
| 86 | + $cookie_url[0] = strtok($alias, '/'); |
|
| 87 | + } |
|
| 84 | 88 | |
| 85 | 89 | smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]); |
| 86 | 90 | } |
@@ -126,8 +130,9 @@ discard block |
||
| 126 | 130 | $identifier = $cookiename . '_tfa'; |
| 127 | 131 | $cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2); |
| 128 | 132 | |
| 129 | - if ($preserve) |
|
| 130 | - $cookie_length = 81600 * 30; |
|
| 133 | + if ($preserve) { |
|
| 134 | + $cookie_length = 81600 * 30; |
|
| 135 | + } |
|
| 131 | 136 | |
| 132 | 137 | // Get the data and path to set it on. |
| 133 | 138 | $data = json_encode(empty($id) ? array(0, '', 0, $cookie_state, false) : array($id, $secret, time() + $cookie_length, $cookie_state, $preserve)); |
@@ -137,8 +142,9 @@ discard block |
||
| 137 | 142 | smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]); |
| 138 | 143 | |
| 139 | 144 | // If subdomain-independent cookies are on, unset the subdomain-dependent cookie too. |
| 140 | - if (empty($id) && !empty($modSettings['globalCookies'])) |
|
| 141 | - smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], ''); |
|
| 145 | + if (empty($id) && !empty($modSettings['globalCookies'])) { |
|
| 146 | + smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], ''); |
|
| 147 | + } |
|
| 142 | 148 | |
| 143 | 149 | $_COOKIE[$identifier] = $data; |
| 144 | 150 | } |
@@ -160,23 +166,28 @@ discard block |
||
| 160 | 166 | $parsed_url = parse_url($boardurl); |
| 161 | 167 | |
| 162 | 168 | // Is local cookies off? |
| 163 | - if (empty($parsed_url['path']) || !$local) |
|
| 164 | - $parsed_url['path'] = ''; |
|
| 169 | + if (empty($parsed_url['path']) || !$local) { |
|
| 170 | + $parsed_url['path'] = ''; |
|
| 171 | + } |
|
| 165 | 172 | |
| 166 | - if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) |
|
| 167 | - $parsed_url['host'] = $modSettings['globalCookiesDomain']; |
|
| 173 | + if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) { |
|
| 174 | + $parsed_url['host'] = $modSettings['globalCookiesDomain']; |
|
| 175 | + } |
|
| 168 | 176 | |
| 169 | 177 | // Globalize cookies across domains (filter out IP-addresses)? |
| 170 | - elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
| 171 | - $parsed_url['host'] = '.' . $parts[1]; |
|
| 178 | + elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
| 179 | + $parsed_url['host'] = '.' . $parts[1]; |
|
| 180 | + } |
|
| 172 | 181 | |
| 173 | 182 | // We shouldn't use a host at all if both options are off. |
| 174 | - elseif (!$local && !$global) |
|
| 175 | - $parsed_url['host'] = ''; |
|
| 183 | + elseif (!$local && !$global) { |
|
| 184 | + $parsed_url['host'] = ''; |
|
| 185 | + } |
|
| 176 | 186 | |
| 177 | 187 | // The host also shouldn't be set if there aren't any dots in it. |
| 178 | - elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) |
|
| 179 | - $parsed_url['host'] = ''; |
|
| 188 | + elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) { |
|
| 189 | + $parsed_url['host'] = ''; |
|
| 190 | + } |
|
| 180 | 191 | |
| 181 | 192 | return array($parsed_url['host'], $parsed_url['path'] . '/'); |
| 182 | 193 | } |
@@ -195,8 +206,9 @@ discard block |
||
| 195 | 206 | createToken('login'); |
| 196 | 207 | |
| 197 | 208 | // Never redirect to an attachment |
| 198 | - if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) |
|
| 199 | - $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
| 209 | + if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) { |
|
| 210 | + $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
| 211 | + } |
|
| 200 | 212 | |
| 201 | 213 | $context['sub_template'] = 'kick_guest'; |
| 202 | 214 | $context['page_title'] = $txt['login']; |
@@ -251,10 +263,12 @@ discard block |
||
| 251 | 263 | $txt['security_wrong'] = sprintf($txt['security_wrong'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $txt['unknown'], $_SERVER['HTTP_USER_AGENT'], $user_info['ip']); |
| 252 | 264 | log_error($txt['security_wrong'], 'critical'); |
| 253 | 265 | |
| 254 | - if (isset($_POST[$type . '_hash_pass'])) |
|
| 255 | - unset($_POST[$type . '_hash_pass']); |
|
| 256 | - if (isset($_POST[$type . '_pass'])) |
|
| 257 | - unset($_POST[$type . '_pass']); |
|
| 266 | + if (isset($_POST[$type . '_hash_pass'])) { |
|
| 267 | + unset($_POST[$type . '_hash_pass']); |
|
| 268 | + } |
|
| 269 | + if (isset($_POST[$type . '_pass'])) { |
|
| 270 | + unset($_POST[$type . '_pass']); |
|
| 271 | + } |
|
| 258 | 272 | |
| 259 | 273 | $context['incorrect_password'] = true; |
| 260 | 274 | } |
@@ -267,15 +281,17 @@ discard block |
||
| 267 | 281 | |
| 268 | 282 | // Now go through $_POST. Make sure the session hash is sent. |
| 269 | 283 | $_POST[$context['session_var']] = $context['session_id']; |
| 270 | - foreach ($_POST as $k => $v) |
|
| 271 | - $context['post_data'] .= adminLogin_outputPostVars($k, $v); |
|
| 284 | + foreach ($_POST as $k => $v) { |
|
| 285 | + $context['post_data'] .= adminLogin_outputPostVars($k, $v); |
|
| 286 | + } |
|
| 272 | 287 | |
| 273 | 288 | // Now we'll use the admin_login sub template of the Login template. |
| 274 | 289 | $context['sub_template'] = 'admin_login'; |
| 275 | 290 | |
| 276 | 291 | // And title the page something like "Login". |
| 277 | - if (!isset($context['page_title'])) |
|
| 278 | - $context['page_title'] = $txt['login']; |
|
| 292 | + if (!isset($context['page_title'])) { |
|
| 293 | + $context['page_title'] = $txt['login']; |
|
| 294 | + } |
|
| 279 | 295 | |
| 280 | 296 | // The type of action. |
| 281 | 297 | $context['sessionCheckType'] = $type; |
@@ -298,14 +314,15 @@ discard block |
||
| 298 | 314 | { |
| 299 | 315 | global $smcFunc; |
| 300 | 316 | |
| 301 | - if (!is_array($v)) |
|
| 302 | - return ' |
|
| 317 | + if (!is_array($v)) { |
|
| 318 | + return ' |
|
| 303 | 319 | <input type="hidden" name="' . $smcFunc['htmlspecialchars']($k) . '" value="' . strtr($v, array('"' => '"', '<' => '<', '>' => '>')) . '">'; |
| 304 | - else |
|
| 320 | + } else |
|
| 305 | 321 | { |
| 306 | 322 | $ret = ''; |
| 307 | - foreach ($v as $k2 => $v2) |
|
| 308 | - $ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2); |
|
| 323 | + foreach ($v as $k2 => $v2) { |
|
| 324 | + $ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2); |
|
| 325 | + } |
|
| 309 | 326 | |
| 310 | 327 | return $ret; |
| 311 | 328 | } |
@@ -332,18 +349,20 @@ discard block |
||
| 332 | 349 | foreach ($get as $k => $v) |
| 333 | 350 | { |
| 334 | 351 | // Only if it's not already in the $scripturl! |
| 335 | - if (!isset($temp[$k])) |
|
| 336 | - $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
| 352 | + if (!isset($temp[$k])) { |
|
| 353 | + $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
| 354 | + } |
|
| 337 | 355 | // If it changed, put it out there, but with an ampersand. |
| 338 | - elseif ($temp[$k] != $get[$k]) |
|
| 339 | - $query_string .= urlencode($k) . '=' . urlencode($v) . '&'; |
|
| 356 | + elseif ($temp[$k] != $get[$k]) { |
|
| 357 | + $query_string .= urlencode($k) . '=' . urlencode($v) . '&'; |
|
| 358 | + } |
|
| 340 | 359 | } |
| 341 | - } |
|
| 342 | - else |
|
| 360 | + } else |
|
| 343 | 361 | { |
| 344 | 362 | // Add up all the data from $_GET into get_data. |
| 345 | - foreach ($get as $k => $v) |
|
| 346 | - $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
| 363 | + foreach ($get as $k => $v) { |
|
| 364 | + $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
| 365 | + } |
|
| 347 | 366 | } |
| 348 | 367 | |
| 349 | 368 | $query_string = substr($query_string, 0, -1); |
@@ -366,8 +385,9 @@ discard block |
||
| 366 | 385 | global $scripturl, $user_info, $smcFunc; |
| 367 | 386 | |
| 368 | 387 | // If it's not already an array, make it one. |
| 369 | - if (!is_array($names)) |
|
| 370 | - $names = explode(',', $names); |
|
| 388 | + if (!is_array($names)) { |
|
| 389 | + $names = explode(',', $names); |
|
| 390 | + } |
|
| 371 | 391 | |
| 372 | 392 | $maybe_email = false; |
| 373 | 393 | foreach ($names as $i => $name) |
@@ -378,10 +398,11 @@ discard block |
||
| 378 | 398 | $maybe_email |= strpos($name, '@') !== false; |
| 379 | 399 | |
| 380 | 400 | // Make it so standard wildcards will work. (* and ?) |
| 381 | - if ($use_wildcards) |
|
| 382 | - $names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => ''')); |
|
| 383 | - else |
|
| 384 | - $names[$i] = strtr($names[$i], array('\'' => ''')); |
|
| 401 | + if ($use_wildcards) { |
|
| 402 | + $names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => ''')); |
|
| 403 | + } else { |
|
| 404 | + $names[$i] = strtr($names[$i], array('\'' => ''')); |
|
| 405 | + } |
|
| 385 | 406 | } |
| 386 | 407 | |
| 387 | 408 | // What are we using to compare? |
@@ -391,11 +412,12 @@ discard block |
||
| 391 | 412 | $results = array(); |
| 392 | 413 | |
| 393 | 414 | // This ensures you can't search someones email address if you can't see it. |
| 394 | - if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) |
|
| 395 | - $email_condition = ' |
|
| 415 | + if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) { |
|
| 416 | + $email_condition = ' |
|
| 396 | 417 | OR (email_address ' . $comparison . ' \'' . implode( '\') OR (email_address ' . $comparison . ' \'', $names) . '\')'; |
| 397 | - else |
|
| 398 | - $email_condition = ''; |
|
| 418 | + } else { |
|
| 419 | + $email_condition = ''; |
|
| 420 | + } |
|
| 399 | 421 | |
| 400 | 422 | // Get the case of the columns right - but only if we need to as things like MySQL will go slow needlessly otherwise. |
| 401 | 423 | $member_name = $smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name'; |
@@ -453,10 +475,11 @@ discard block |
||
| 453 | 475 | $context['template_layers'] = array(); |
| 454 | 476 | $context['sub_template'] = 'find_members'; |
| 455 | 477 | |
| 456 | - if (isset($_REQUEST['search'])) |
|
| 457 | - $context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES); |
|
| 458 | - else |
|
| 459 | - $_REQUEST['start'] = 0; |
|
| 478 | + if (isset($_REQUEST['search'])) { |
|
| 479 | + $context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES); |
|
| 480 | + } else { |
|
| 481 | + $_REQUEST['start'] = 0; |
|
| 482 | + } |
|
| 460 | 483 | |
| 461 | 484 | // Allow the user to pass the input to be added to to the box. |
| 462 | 485 | $context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to'; |
@@ -497,10 +520,10 @@ discard block |
||
| 497 | 520 | ); |
| 498 | 521 | |
| 499 | 522 | $context['results'] = array_slice($context['results'], $_REQUEST['start'], 7); |
| 523 | + } else { |
|
| 524 | + $context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']); |
|
| 525 | + } |
|
| 500 | 526 | } |
| 501 | - else |
|
| 502 | - $context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']); |
|
| 503 | -} |
|
| 504 | 527 | |
| 505 | 528 | /** |
| 506 | 529 | * Outputs each member name on its own line. |
@@ -516,8 +539,9 @@ discard block |
||
| 516 | 539 | $_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search'])); |
| 517 | 540 | $_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&' => '&')); |
| 518 | 541 | |
| 519 | - if (function_exists('iconv')) |
|
| 520 | - header('Content-Type: text/plain; charset=UTF-8'); |
|
| 542 | + if (function_exists('iconv')) { |
|
| 543 | + header('Content-Type: text/plain; charset=UTF-8'); |
|
| 544 | + } |
|
| 521 | 545 | |
| 522 | 546 | $request = $smcFunc['db_query']('', ' |
| 523 | 547 | SELECT real_name |
@@ -537,14 +561,16 @@ discard block |
||
| 537 | 561 | if (function_exists('iconv')) |
| 538 | 562 | { |
| 539 | 563 | $utf8 = iconv($txt['lang_character_set'], 'UTF-8', $row['real_name']); |
| 540 | - if ($utf8) |
|
| 541 | - $row['real_name'] = $utf8; |
|
| 564 | + if ($utf8) { |
|
| 565 | + $row['real_name'] = $utf8; |
|
| 566 | + } |
|
| 542 | 567 | } |
| 543 | 568 | |
| 544 | 569 | $row['real_name'] = strtr($row['real_name'], array('&' => '&', '<' => '<', '>' => '>', '"' => '"')); |
| 545 | 570 | |
| 546 | - if (preg_match('~&#\d+;~', $row['real_name']) != 0) |
|
| 547 | - $row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']); |
|
| 571 | + if (preg_match('~&#\d+;~', $row['real_name']) != 0) { |
|
| 572 | + $row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']); |
|
| 573 | + } |
|
| 548 | 574 | |
| 549 | 575 | echo $row['real_name'], "\n"; |
| 550 | 576 | } |
@@ -601,9 +627,9 @@ discard block |
||
| 601 | 627 | |
| 602 | 628 | // Update the database... |
| 603 | 629 | updateMemberData($memID, array('member_name' => $user, 'passwd' => $newPassword_sha1)); |
| 630 | + } else { |
|
| 631 | + updateMemberData($memID, array('passwd' => $newPassword_sha1)); |
|
| 604 | 632 | } |
| 605 | - else |
|
| 606 | - updateMemberData($memID, array('passwd' => $newPassword_sha1)); |
|
| 607 | 633 | |
| 608 | 634 | call_integration_hook('integrate_reset_pass', array($old_user, $user, $newPassword)); |
| 609 | 635 | |
@@ -634,31 +660,37 @@ discard block |
||
| 634 | 660 | $errors = array(); |
| 635 | 661 | |
| 636 | 662 | // Don't use too long a name. |
| 637 | - if ($smcFunc['strlen']($username) > 25) |
|
| 638 | - $errors[] = array('lang', 'error_long_name'); |
|
| 663 | + if ($smcFunc['strlen']($username) > 25) { |
|
| 664 | + $errors[] = array('lang', 'error_long_name'); |
|
| 665 | + } |
|
| 639 | 666 | |
| 640 | 667 | // No name?! How can you register with no name? |
| 641 | - if ($username == '') |
|
| 642 | - $errors[] = array('lang', 'need_username'); |
|
| 668 | + if ($username == '') { |
|
| 669 | + $errors[] = array('lang', 'need_username'); |
|
| 670 | + } |
|
| 643 | 671 | |
| 644 | 672 | // Only these characters are permitted. |
| 645 | - if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) |
|
| 646 | - $errors[] = array('lang', 'error_invalid_characters_username'); |
|
| 673 | + if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) { |
|
| 674 | + $errors[] = array('lang', 'error_invalid_characters_username'); |
|
| 675 | + } |
|
| 647 | 676 | |
| 648 | - if (stristr($username, $txt['guest_title']) !== false) |
|
| 649 | - $errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title'])); |
|
| 677 | + if (stristr($username, $txt['guest_title']) !== false) { |
|
| 678 | + $errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title'])); |
|
| 679 | + } |
|
| 650 | 680 | |
| 651 | 681 | if ($check_reserved_name) |
| 652 | 682 | { |
| 653 | 683 | require_once($sourcedir . '/Subs-Members.php'); |
| 654 | - if (isReservedName($username, $memID, false)) |
|
| 655 | - $errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']); |
|
| 684 | + if (isReservedName($username, $memID, false)) { |
|
| 685 | + $errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']); |
|
| 686 | + } |
|
| 656 | 687 | } |
| 657 | 688 | |
| 658 | - if ($return_error) |
|
| 659 | - return $errors; |
|
| 660 | - elseif (empty($errors)) |
|
| 661 | - return null; |
|
| 689 | + if ($return_error) { |
|
| 690 | + return $errors; |
|
| 691 | + } elseif (empty($errors)) { |
|
| 692 | + return null; |
|
| 693 | + } |
|
| 662 | 694 | |
| 663 | 695 | loadLanguage('Errors'); |
| 664 | 696 | $error = $errors[0]; |
@@ -684,22 +716,26 @@ discard block |
||
| 684 | 716 | global $modSettings, $smcFunc; |
| 685 | 717 | |
| 686 | 718 | // Perform basic requirements first. |
| 687 | - if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) |
|
| 688 | - return 'short'; |
|
| 719 | + if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) { |
|
| 720 | + return 'short'; |
|
| 721 | + } |
|
| 689 | 722 | |
| 690 | 723 | // Is this enough? |
| 691 | - if (empty($modSettings['password_strength'])) |
|
| 692 | - return null; |
|
| 724 | + if (empty($modSettings['password_strength'])) { |
|
| 725 | + return null; |
|
| 726 | + } |
|
| 693 | 727 | |
| 694 | 728 | // Otherwise, perform the medium strength test - checking if password appears in the restricted string. |
| 695 | - if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) |
|
| 696 | - return 'restricted_words'; |
|
| 697 | - elseif ($smcFunc['strpos']($password, $username) !== false) |
|
| 698 | - return 'restricted_words'; |
|
| 729 | + if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) { |
|
| 730 | + return 'restricted_words'; |
|
| 731 | + } elseif ($smcFunc['strpos']($password, $username) !== false) { |
|
| 732 | + return 'restricted_words'; |
|
| 733 | + } |
|
| 699 | 734 | |
| 700 | 735 | // If just medium, we're done. |
| 701 | - if ($modSettings['password_strength'] == 1) |
|
| 702 | - return null; |
|
| 736 | + if ($modSettings['password_strength'] == 1) { |
|
| 737 | + return null; |
|
| 738 | + } |
|
| 703 | 739 | |
| 704 | 740 | // Otherwise, hard test next, check for numbers and letters, uppercase too. |
| 705 | 741 | $good = preg_match('~(\D\d|\d\D)~', $password) != 0; |
@@ -731,14 +767,16 @@ discard block |
||
| 731 | 767 | ) |
| 732 | 768 | ); |
| 733 | 769 | $groups = array(); |
| 734 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 735 | - $groups[] = $row['id_group']; |
|
| 770 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 771 | + $groups[] = $row['id_group']; |
|
| 772 | + } |
|
| 736 | 773 | $smcFunc['db_free_result']($request); |
| 737 | 774 | |
| 738 | - if (empty($groups)) |
|
| 739 | - $group_query = '0=1'; |
|
| 740 | - else |
|
| 741 | - $group_query = 'id_group IN (' . implode(',', $groups) . ')'; |
|
| 775 | + if (empty($groups)) { |
|
| 776 | + $group_query = '0=1'; |
|
| 777 | + } else { |
|
| 778 | + $group_query = 'id_group IN (' . implode(',', $groups) . ')'; |
|
| 779 | + } |
|
| 742 | 780 | } |
| 743 | 781 | |
| 744 | 782 | // Then, same again, just the boards this time! |
@@ -748,10 +786,11 @@ discard block |
||
| 748 | 786 | { |
| 749 | 787 | $boards = boardsAllowedTo('moderate_board', true); |
| 750 | 788 | |
| 751 | - if (empty($boards)) |
|
| 752 | - $board_query = '0=1'; |
|
| 753 | - else |
|
| 754 | - $board_query = 'id_board IN (' . implode(',', $boards) . ')'; |
|
| 789 | + if (empty($boards)) { |
|
| 790 | + $board_query = '0=1'; |
|
| 791 | + } else { |
|
| 792 | + $board_query = 'id_board IN (' . implode(',', $boards) . ')'; |
|
| 793 | + } |
|
| 755 | 794 | } |
| 756 | 795 | |
| 757 | 796 | // What boards are they the moderator of? |
@@ -766,8 +805,9 @@ discard block |
||
| 766 | 805 | 'current_member' => $user_info['id'], |
| 767 | 806 | ) |
| 768 | 807 | ); |
| 769 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 770 | - $boards_mod[] = $row['id_board']; |
|
| 808 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 809 | + $boards_mod[] = $row['id_board']; |
|
| 810 | + } |
|
| 771 | 811 | $smcFunc['db_free_result']($request); |
| 772 | 812 | |
| 773 | 813 | // Can any of the groups they're in moderate any of the boards? |
@@ -779,8 +819,9 @@ discard block |
||
| 779 | 819 | 'groups' => $user_info['groups'], |
| 780 | 820 | ) |
| 781 | 821 | ); |
| 782 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 783 | - $boards_mod[] = $row['id_board']; |
|
| 822 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 823 | + $boards_mod[] = $row['id_board']; |
|
| 824 | + } |
|
| 784 | 825 | $smcFunc['db_free_result']($request); |
| 785 | 826 | |
| 786 | 827 | // Just in case we've got duplicates here... |
@@ -825,10 +866,12 @@ discard block |
||
| 825 | 866 | global $modSettings; |
| 826 | 867 | |
| 827 | 868 | // In case a customization wants to override the default settings |
| 828 | - if ($httponly === null) |
|
| 829 | - $httponly = !empty($modSettings['httponlyCookies']); |
|
| 830 | - if ($secure === null) |
|
| 831 | - $secure = !empty($modSettings['secureCookies']); |
|
| 869 | + if ($httponly === null) { |
|
| 870 | + $httponly = !empty($modSettings['httponlyCookies']); |
|
| 871 | + } |
|
| 872 | + if ($secure === null) { |
|
| 873 | + $secure = !empty($modSettings['secureCookies']); |
|
| 874 | + } |
|
| 832 | 875 | |
| 833 | 876 | // Intercept cookie? |
| 834 | 877 | call_integration_hook('integrate_cookie', array($name, $value, $expire, $path, $domain, $secure, $httponly)); |
@@ -848,8 +891,9 @@ discard block |
||
| 848 | 891 | function hash_password($username, $password, $cost = null) |
| 849 | 892 | { |
| 850 | 893 | global $sourcedir, $smcFunc, $modSettings; |
| 851 | - if (!function_exists('password_hash')) |
|
| 852 | - require_once($sourcedir . '/Subs-Password.php'); |
|
| 894 | + if (!function_exists('password_hash')) { |
|
| 895 | + require_once($sourcedir . '/Subs-Password.php'); |
|
| 896 | + } |
|
| 853 | 897 | |
| 854 | 898 | $cost = empty($cost) ? (empty($modSettings['bcrypt_hash_cost']) ? 10 : $modSettings['bcrypt_hash_cost']) : $cost; |
| 855 | 899 | |
@@ -881,8 +925,9 @@ discard block |
||
| 881 | 925 | function hash_verify_password($username, $password, $hash) |
| 882 | 926 | { |
| 883 | 927 | global $sourcedir, $smcFunc; |
| 884 | - if (!function_exists('password_verify')) |
|
| 885 | - require_once($sourcedir . '/Subs-Password.php'); |
|
| 928 | + if (!function_exists('password_verify')) { |
|
| 929 | + require_once($sourcedir . '/Subs-Password.php'); |
|
| 930 | + } |
|
| 886 | 931 | |
| 887 | 932 | return password_verify($smcFunc['strtolower']($username) . $password, $hash); |
| 888 | 933 | } |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | * Backtrace, log, try to fix. |
| 559 | 559 | * |
| 560 | 560 | * @param string $db_string The DB string |
| 561 | - * @param object $connection The connection to use (if null, $db_connection is used) |
|
| 561 | + * @param resource $connection The connection to use (if null, $db_connection is used) |
|
| 562 | 562 | */ |
| 563 | 563 | function smf_db_error($db_string, $connection = null) |
| 564 | 564 | { |
@@ -753,7 +753,7 @@ discard block |
||
| 753 | 753 | * @param array $data The data to insert |
| 754 | 754 | * @param array $keys The keys for the table |
| 755 | 755 | * @param bool $disable_trans Whether to disable transactions |
| 756 | - * @param object $connection The connection to use (if null, $db_connection is used) |
|
| 756 | + * @param resource $connection The connection to use (if null, $db_connection is used) |
|
| 757 | 757 | */ |
| 758 | 758 | function smf_db_insert($method = 'replace', $table, $columns, $data, $keys, $disable_trans = false, $connection = null) |
| 759 | 759 | { |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | if ($connection) { |
| 72 | 72 | if (!empty($db_options['port'])) |
| 73 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'] , null ,$flags); |
|
| 73 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags); |
|
| 74 | 74 | else |
| 75 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd,'', 0, null, $flags); |
|
| 75 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | // Something's wrong, show an error if its fatal (which we assume it is) |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | $replacement[$key] = 'null'; |
| 282 | 282 | if (!isValidIP($value)) |
| 283 | 283 | smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
| 284 | - $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
|
| 284 | + $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | return implode(', ', $replacement); |
@@ -868,7 +868,7 @@ discard block |
||
| 868 | 868 | * @param bool $translate_human_wildcards If true, turns human readable wildcards into SQL wildcards. |
| 869 | 869 | * @return string The escaped string |
| 870 | 870 | */ |
| 871 | -function smf_db_escape_wildcard_string($string, $translate_human_wildcards=false) |
|
| 871 | +function smf_db_escape_wildcard_string($string, $translate_human_wildcards = false) |
|
| 872 | 872 | { |
| 873 | 873 | $replacements = array( |
| 874 | 874 | '%' => '\%', |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -33,8 +34,8 @@ discard block |
||
| 33 | 34 | global $smcFunc, $mysql_set_mode; |
| 34 | 35 | |
| 35 | 36 | // Map some database specific functions, only do this once. |
| 36 | - if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysqli_fetch_assoc') |
|
| 37 | - $smcFunc += array( |
|
| 37 | + if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysqli_fetch_assoc') { |
|
| 38 | + $smcFunc += array( |
|
| 38 | 39 | 'db_query' => 'smf_db_query', |
| 39 | 40 | 'db_quote' => 'smf_db_quote', |
| 40 | 41 | 'db_fetch_assoc' => 'mysqli_fetch_assoc', |
@@ -58,9 +59,11 @@ discard block |
||
| 58 | 59 | 'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string', |
| 59 | 60 | 'db_is_resource' => 'smf_is_resource', |
| 60 | 61 | ); |
| 62 | + } |
|
| 61 | 63 | |
| 62 | - if (!empty($db_options['persist'])) |
|
| 63 | - $db_server = 'p:' . $db_server; |
|
| 64 | + if (!empty($db_options['persist'])) { |
|
| 65 | + $db_server = 'p:' . $db_server; |
|
| 66 | + } |
|
| 64 | 67 | |
| 65 | 68 | $connection = mysqli_init(); |
| 66 | 69 | |
@@ -69,31 +72,35 @@ discard block |
||
| 69 | 72 | $success = false; |
| 70 | 73 | |
| 71 | 74 | if ($connection) { |
| 72 | - if (!empty($db_options['port'])) |
|
| 73 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'] , null ,$flags); |
|
| 74 | - else |
|
| 75 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd,'', 0, null, $flags); |
|
| 75 | + if (!empty($db_options['port'])) { |
|
| 76 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'] , null ,$flags); |
|
| 77 | + } else { |
|
| 78 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd,'', 0, null, $flags); |
|
| 79 | + } |
|
| 76 | 80 | } |
| 77 | 81 | |
| 78 | 82 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 79 | 83 | if ($success === false) |
| 80 | 84 | { |
| 81 | - if (!empty($db_options['non_fatal'])) |
|
| 82 | - return null; |
|
| 83 | - else |
|
| 84 | - display_db_error(); |
|
| 85 | + if (!empty($db_options['non_fatal'])) { |
|
| 86 | + return null; |
|
| 87 | + } else { |
|
| 88 | + display_db_error(); |
|
| 89 | + } |
|
| 85 | 90 | } |
| 86 | 91 | |
| 87 | 92 | // Select the database, unless told not to |
| 88 | - if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) |
|
| 89 | - display_db_error(); |
|
| 93 | + if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) { |
|
| 94 | + display_db_error(); |
|
| 95 | + } |
|
| 90 | 96 | |
| 91 | 97 | // This makes it possible to have SMF automatically change the sql_mode and autocommit if needed. |
| 92 | - if (isset($mysql_set_mode) && $mysql_set_mode === true) |
|
| 93 | - $smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1', |
|
| 98 | + if (isset($mysql_set_mode) && $mysql_set_mode === true) { |
|
| 99 | + $smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1', |
|
| 94 | 100 | array(), |
| 95 | 101 | false |
| 96 | 102 | ); |
| 103 | + } |
|
| 97 | 104 | |
| 98 | 105 | return $connection; |
| 99 | 106 | } |
@@ -164,37 +171,46 @@ discard block |
||
| 164 | 171 | global $db_callback, $user_info, $db_prefix, $smcFunc; |
| 165 | 172 | |
| 166 | 173 | list ($values, $connection) = $db_callback; |
| 167 | - if (!is_object($connection)) |
|
| 168 | - display_db_error(); |
|
| 174 | + if (!is_object($connection)) { |
|
| 175 | + display_db_error(); |
|
| 176 | + } |
|
| 169 | 177 | |
| 170 | - if ($matches[1] === 'db_prefix') |
|
| 171 | - return $db_prefix; |
|
| 178 | + if ($matches[1] === 'db_prefix') { |
|
| 179 | + return $db_prefix; |
|
| 180 | + } |
|
| 172 | 181 | |
| 173 | - if ($matches[1] === 'query_see_board') |
|
| 174 | - return $user_info['query_see_board']; |
|
| 182 | + if ($matches[1] === 'query_see_board') { |
|
| 183 | + return $user_info['query_see_board']; |
|
| 184 | + } |
|
| 175 | 185 | |
| 176 | - if ($matches[1] === 'query_wanna_see_board') |
|
| 177 | - return $user_info['query_wanna_see_board']; |
|
| 186 | + if ($matches[1] === 'query_wanna_see_board') { |
|
| 187 | + return $user_info['query_wanna_see_board']; |
|
| 188 | + } |
|
| 178 | 189 | |
| 179 | - if ($matches[1] === 'empty') |
|
| 180 | - return '\'\''; |
|
| 190 | + if ($matches[1] === 'empty') { |
|
| 191 | + return '\'\''; |
|
| 192 | + } |
|
| 181 | 193 | |
| 182 | - if (!isset($matches[2])) |
|
| 183 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 194 | + if (!isset($matches[2])) { |
|
| 195 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 196 | + } |
|
| 184 | 197 | |
| 185 | - if ($matches[1] === 'literal') |
|
| 186 | - return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
| 198 | + if ($matches[1] === 'literal') { |
|
| 199 | + return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
| 200 | + } |
|
| 187 | 201 | |
| 188 | - if (!isset($values[$matches[2]])) |
|
| 189 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 202 | + if (!isset($values[$matches[2]])) { |
|
| 203 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 204 | + } |
|
| 190 | 205 | |
| 191 | 206 | $replacement = $values[$matches[2]]; |
| 192 | 207 | |
| 193 | 208 | switch ($matches[1]) |
| 194 | 209 | { |
| 195 | 210 | case 'int': |
| 196 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 197 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 211 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 212 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 213 | + } |
|
| 198 | 214 | return (string) (int) $replacement; |
| 199 | 215 | break; |
| 200 | 216 | |
@@ -206,49 +222,55 @@ discard block |
||
| 206 | 222 | case 'array_int': |
| 207 | 223 | if (is_array($replacement)) |
| 208 | 224 | { |
| 209 | - if (empty($replacement)) |
|
| 210 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 225 | + if (empty($replacement)) { |
|
| 226 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 227 | + } |
|
| 211 | 228 | |
| 212 | 229 | foreach ($replacement as $key => $value) |
| 213 | 230 | { |
| 214 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 215 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 231 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 232 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 233 | + } |
|
| 216 | 234 | |
| 217 | 235 | $replacement[$key] = (string) (int) $value; |
| 218 | 236 | } |
| 219 | 237 | |
| 220 | 238 | return implode(', ', $replacement); |
| 239 | + } else { |
|
| 240 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 221 | 241 | } |
| 222 | - else |
|
| 223 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 224 | 242 | |
| 225 | 243 | break; |
| 226 | 244 | |
| 227 | 245 | case 'array_string': |
| 228 | 246 | if (is_array($replacement)) |
| 229 | 247 | { |
| 230 | - if (empty($replacement)) |
|
| 231 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 248 | + if (empty($replacement)) { |
|
| 249 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 250 | + } |
|
| 232 | 251 | |
| 233 | - foreach ($replacement as $key => $value) |
|
| 234 | - $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
| 252 | + foreach ($replacement as $key => $value) { |
|
| 253 | + $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
| 254 | + } |
|
| 235 | 255 | |
| 236 | 256 | return implode(', ', $replacement); |
| 257 | + } else { |
|
| 258 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 237 | 259 | } |
| 238 | - else |
|
| 239 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 240 | 260 | break; |
| 241 | 261 | |
| 242 | 262 | case 'date': |
| 243 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
| 244 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 245 | - else |
|
| 246 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 263 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 264 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 265 | + } else { |
|
| 266 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 267 | + } |
|
| 247 | 268 | break; |
| 248 | 269 | |
| 249 | 270 | case 'float': |
| 250 | - if (!is_numeric($replacement)) |
|
| 251 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 271 | + if (!is_numeric($replacement)) { |
|
| 272 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 273 | + } |
|
| 252 | 274 | return (string) (float) $replacement; |
| 253 | 275 | break; |
| 254 | 276 | |
@@ -262,32 +284,37 @@ discard block |
||
| 262 | 284 | break; |
| 263 | 285 | |
| 264 | 286 | case 'inet': |
| 265 | - if ($replacement == 'null' || $replacement == '') |
|
| 266 | - return 'null'; |
|
| 267 | - if (!isValidIP($replacement)) |
|
| 268 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 287 | + if ($replacement == 'null' || $replacement == '') { |
|
| 288 | + return 'null'; |
|
| 289 | + } |
|
| 290 | + if (!isValidIP($replacement)) { |
|
| 291 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 292 | + } |
|
| 269 | 293 | //we don't use the native support of mysql > 5.6.2 |
| 270 | 294 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
| 271 | 295 | |
| 272 | 296 | case 'array_inet': |
| 273 | 297 | if (is_array($replacement)) |
| 274 | 298 | { |
| 275 | - if (empty($replacement)) |
|
| 276 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 299 | + if (empty($replacement)) { |
|
| 300 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 301 | + } |
|
| 277 | 302 | |
| 278 | 303 | foreach ($replacement as $key => $value) |
| 279 | 304 | { |
| 280 | - if ($replacement == 'null' || $replacement == '') |
|
| 281 | - $replacement[$key] = 'null'; |
|
| 282 | - if (!isValidIP($value)) |
|
| 283 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 305 | + if ($replacement == 'null' || $replacement == '') { |
|
| 306 | + $replacement[$key] = 'null'; |
|
| 307 | + } |
|
| 308 | + if (!isValidIP($value)) { |
|
| 309 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 310 | + } |
|
| 284 | 311 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
| 285 | 312 | } |
| 286 | 313 | |
| 287 | 314 | return implode(', ', $replacement); |
| 315 | + } else { |
|
| 316 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 288 | 317 | } |
| 289 | - else |
|
| 290 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 291 | 318 | break; |
| 292 | 319 | |
| 293 | 320 | default: |
@@ -363,22 +390,25 @@ discard block |
||
| 363 | 390 | // Are we in SSI mode? If so try that username and password first |
| 364 | 391 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
| 365 | 392 | { |
| 366 | - if (empty($db_persist)) |
|
| 367 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 368 | - else |
|
| 369 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 393 | + if (empty($db_persist)) { |
|
| 394 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 395 | + } else { |
|
| 396 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 397 | + } |
|
| 370 | 398 | } |
| 371 | 399 | // Fall back to the regular username and password if need be |
| 372 | 400 | if (!$db_connection) |
| 373 | 401 | { |
| 374 | - if (empty($db_persist)) |
|
| 375 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 376 | - else |
|
| 377 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 402 | + if (empty($db_persist)) { |
|
| 403 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 404 | + } else { |
|
| 405 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 406 | + } |
|
| 378 | 407 | } |
| 379 | 408 | |
| 380 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
| 381 | - $db_connection = false; |
|
| 409 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
| 410 | + $db_connection = false; |
|
| 411 | + } |
|
| 382 | 412 | |
| 383 | 413 | $connection = $db_connection; |
| 384 | 414 | } |
@@ -386,18 +416,20 @@ discard block |
||
| 386 | 416 | // One more query.... |
| 387 | 417 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 388 | 418 | |
| 389 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 390 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 419 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 420 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 421 | + } |
|
| 391 | 422 | |
| 392 | 423 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
| 393 | 424 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
| 394 | 425 | { |
| 395 | 426 | // Add before LIMIT |
| 396 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
| 397 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 398 | - else |
|
| 399 | - // Append it. |
|
| 427 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
| 428 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
| 429 | + } else { |
|
| 430 | + // Append it. |
|
| 400 | 431 | $db_string .= "\n\t\t\tORDER BY null"; |
| 432 | + } |
|
| 401 | 433 | } |
| 402 | 434 | |
| 403 | 435 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -419,8 +451,9 @@ discard block |
||
| 419 | 451 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 420 | 452 | |
| 421 | 453 | // Initialize $db_cache if not already initialized. |
| 422 | - if (!isset($db_cache)) |
|
| 423 | - $db_cache = array(); |
|
| 454 | + if (!isset($db_cache)) { |
|
| 455 | + $db_cache = array(); |
|
| 456 | + } |
|
| 424 | 457 | |
| 425 | 458 | if (!empty($_SESSION['debug_redirect'])) |
| 426 | 459 | { |
@@ -446,17 +479,18 @@ discard block |
||
| 446 | 479 | while (true) |
| 447 | 480 | { |
| 448 | 481 | $pos = strpos($db_string, '\'', $pos + 1); |
| 449 | - if ($pos === false) |
|
| 450 | - break; |
|
| 482 | + if ($pos === false) { |
|
| 483 | + break; |
|
| 484 | + } |
|
| 451 | 485 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
| 452 | 486 | |
| 453 | 487 | while (true) |
| 454 | 488 | { |
| 455 | 489 | $pos1 = strpos($db_string, '\'', $pos + 1); |
| 456 | 490 | $pos2 = strpos($db_string, '\\', $pos + 1); |
| 457 | - if ($pos1 === false) |
|
| 458 | - break; |
|
| 459 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
| 491 | + if ($pos1 === false) { |
|
| 492 | + break; |
|
| 493 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
| 460 | 494 | { |
| 461 | 495 | $pos = $pos1; |
| 462 | 496 | break; |
@@ -472,29 +506,35 @@ discard block |
||
| 472 | 506 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 473 | 507 | |
| 474 | 508 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 475 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 476 | - $fail = true; |
|
| 509 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 510 | + $fail = true; |
|
| 511 | + } |
|
| 477 | 512 | // Trying to change passwords, slow us down, or something? |
| 478 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 479 | - $fail = true; |
|
| 480 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 481 | - $fail = true; |
|
| 513 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 514 | + $fail = true; |
|
| 515 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 516 | + $fail = true; |
|
| 517 | + } |
|
| 482 | 518 | |
| 483 | - if (!empty($fail) && function_exists('log_error')) |
|
| 484 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 519 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 520 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 521 | + } |
|
| 485 | 522 | } |
| 486 | 523 | |
| 487 | - if (empty($db_unbuffered)) |
|
| 488 | - $ret = @mysqli_query($connection, $db_string); |
|
| 489 | - else |
|
| 490 | - $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
| 524 | + if (empty($db_unbuffered)) { |
|
| 525 | + $ret = @mysqli_query($connection, $db_string); |
|
| 526 | + } else { |
|
| 527 | + $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
| 528 | + } |
|
| 491 | 529 | |
| 492 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
| 493 | - $ret = smf_db_error($db_string, $connection); |
|
| 530 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
| 531 | + $ret = smf_db_error($db_string, $connection); |
|
| 532 | + } |
|
| 494 | 533 | |
| 495 | 534 | // Debugging. |
| 496 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 497 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 535 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 536 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 537 | + } |
|
| 498 | 538 | |
| 499 | 539 | return $ret; |
| 500 | 540 | } |
@@ -543,12 +583,13 @@ discard block |
||
| 543 | 583 | // Decide which connection to use |
| 544 | 584 | $connection = $connection === null ? $db_connection : $connection; |
| 545 | 585 | |
| 546 | - if ($type == 'begin') |
|
| 547 | - return @mysqli_query($connection, 'BEGIN'); |
|
| 548 | - elseif ($type == 'rollback') |
|
| 549 | - return @mysqli_query($connection, 'ROLLBACK'); |
|
| 550 | - elseif ($type == 'commit') |
|
| 551 | - return @mysqli_query($connection, 'COMMIT'); |
|
| 586 | + if ($type == 'begin') { |
|
| 587 | + return @mysqli_query($connection, 'BEGIN'); |
|
| 588 | + } elseif ($type == 'rollback') { |
|
| 589 | + return @mysqli_query($connection, 'ROLLBACK'); |
|
| 590 | + } elseif ($type == 'commit') { |
|
| 591 | + return @mysqli_query($connection, 'COMMIT'); |
|
| 592 | + } |
|
| 552 | 593 | |
| 553 | 594 | return false; |
| 554 | 595 | } |
@@ -588,8 +629,9 @@ discard block |
||
| 588 | 629 | // 2013: Lost connection to server during query. |
| 589 | 630 | |
| 590 | 631 | // Log the error. |
| 591 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
| 592 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 632 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
| 633 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
| 634 | + } |
|
| 593 | 635 | |
| 594 | 636 | // Database error auto fixing ;). |
| 595 | 637 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -598,8 +640,9 @@ discard block |
||
| 598 | 640 | $old_cache = @$modSettings['cache_enable']; |
| 599 | 641 | $modSettings['cache_enable'] = '1'; |
| 600 | 642 | |
| 601 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
| 602 | - $db_last_error = max(@$db_last_error, $temp); |
|
| 643 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
| 644 | + $db_last_error = max(@$db_last_error, $temp); |
|
| 645 | + } |
|
| 603 | 646 | |
| 604 | 647 | if (@$db_last_error < time() - 3600 * 24 * 3) |
| 605 | 648 | { |
@@ -615,8 +658,9 @@ discard block |
||
| 615 | 658 | foreach ($tables as $table) |
| 616 | 659 | { |
| 617 | 660 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
| 618 | - if (trim($table) != '') |
|
| 619 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 661 | + if (trim($table) != '') { |
|
| 662 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
| 663 | + } |
|
| 620 | 664 | } |
| 621 | 665 | } |
| 622 | 666 | |
@@ -625,8 +669,9 @@ discard block |
||
| 625 | 669 | // Table crashed. Let's try to fix it. |
| 626 | 670 | elseif ($query_errno == 1016) |
| 627 | 671 | { |
| 628 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
| 629 | - $fix_tables = array('`' . $match[1] . '`'); |
|
| 672 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
| 673 | + $fix_tables = array('`' . $match[1] . '`'); |
|
| 674 | + } |
|
| 630 | 675 | } |
| 631 | 676 | // Indexes crashed. Should be easy to fix! |
| 632 | 677 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -645,13 +690,15 @@ discard block |
||
| 645 | 690 | |
| 646 | 691 | // Make a note of the REPAIR... |
| 647 | 692 | cache_put_data('db_last_error', time(), 600); |
| 648 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
| 649 | - updateSettingsFile(array('db_last_error' => time())); |
|
| 693 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
| 694 | + updateSettingsFile(array('db_last_error' => time())); |
|
| 695 | + } |
|
| 650 | 696 | |
| 651 | 697 | // Attempt to find and repair the broken table. |
| 652 | - foreach ($fix_tables as $table) |
|
| 653 | - $smcFunc['db_query']('', " |
|
| 698 | + foreach ($fix_tables as $table) { |
|
| 699 | + $smcFunc['db_query']('', " |
|
| 654 | 700 | REPAIR TABLE $table", false, false); |
| 701 | + } |
|
| 655 | 702 | |
| 656 | 703 | // And send off an email! |
| 657 | 704 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -660,11 +707,12 @@ discard block |
||
| 660 | 707 | |
| 661 | 708 | // Try the query again...? |
| 662 | 709 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 663 | - if ($ret !== false) |
|
| 664 | - return $ret; |
|
| 710 | + if ($ret !== false) { |
|
| 711 | + return $ret; |
|
| 712 | + } |
|
| 713 | + } else { |
|
| 714 | + $modSettings['cache_enable'] = $old_cache; |
|
| 665 | 715 | } |
| 666 | - else |
|
| 667 | - $modSettings['cache_enable'] = $old_cache; |
|
| 668 | 716 | |
| 669 | 717 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
| 670 | 718 | if (in_array($query_errno, array(1205, 1213, 2006, 2013))) |
@@ -674,22 +722,25 @@ discard block |
||
| 674 | 722 | // Are we in SSI mode? If so try that username and password first |
| 675 | 723 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
| 676 | 724 | { |
| 677 | - if (empty($db_persist)) |
|
| 678 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 679 | - else |
|
| 680 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 725 | + if (empty($db_persist)) { |
|
| 726 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 727 | + } else { |
|
| 728 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
| 729 | + } |
|
| 681 | 730 | } |
| 682 | 731 | // Fall back to the regular username and password if need be |
| 683 | 732 | if (!$db_connection) |
| 684 | 733 | { |
| 685 | - if (empty($db_persist)) |
|
| 686 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 687 | - else |
|
| 688 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 734 | + if (empty($db_persist)) { |
|
| 735 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
| 736 | + } else { |
|
| 737 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
| 738 | + } |
|
| 689 | 739 | } |
| 690 | 740 | |
| 691 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
| 692 | - $db_connection = false; |
|
| 741 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
| 742 | + $db_connection = false; |
|
| 743 | + } |
|
| 693 | 744 | } |
| 694 | 745 | |
| 695 | 746 | if ($db_connection) |
@@ -700,24 +751,27 @@ discard block |
||
| 700 | 751 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
| 701 | 752 | |
| 702 | 753 | $new_errno = mysqli_errno($db_connection); |
| 703 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
| 704 | - break; |
|
| 754 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
| 755 | + break; |
|
| 756 | + } |
|
| 705 | 757 | } |
| 706 | 758 | |
| 707 | 759 | // If it failed again, shucks to be you... we're not trying it over and over. |
| 708 | - if ($ret !== false) |
|
| 709 | - return $ret; |
|
| 760 | + if ($ret !== false) { |
|
| 761 | + return $ret; |
|
| 762 | + } |
|
| 710 | 763 | } |
| 711 | 764 | } |
| 712 | 765 | // Are they out of space, perhaps? |
| 713 | 766 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
| 714 | 767 | { |
| 715 | - if (!isset($txt)) |
|
| 716 | - $query_error .= ' - check database storage space.'; |
|
| 717 | - else |
|
| 768 | + if (!isset($txt)) { |
|
| 769 | + $query_error .= ' - check database storage space.'; |
|
| 770 | + } else |
|
| 718 | 771 | { |
| 719 | - if (!isset($txt['mysql_error_space'])) |
|
| 720 | - loadLanguage('Errors'); |
|
| 772 | + if (!isset($txt['mysql_error_space'])) { |
|
| 773 | + loadLanguage('Errors'); |
|
| 774 | + } |
|
| 721 | 775 | |
| 722 | 776 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
| 723 | 777 | } |
@@ -725,15 +779,17 @@ discard block |
||
| 725 | 779 | } |
| 726 | 780 | |
| 727 | 781 | // Nothing's defined yet... just die with it. |
| 728 | - if (empty($context) || empty($txt)) |
|
| 729 | - die($query_error); |
|
| 782 | + if (empty($context) || empty($txt)) { |
|
| 783 | + die($query_error); |
|
| 784 | + } |
|
| 730 | 785 | |
| 731 | 786 | // Show an error message, if possible. |
| 732 | 787 | $context['error_title'] = $txt['database_error']; |
| 733 | - if (allowedTo('admin_forum')) |
|
| 734 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 735 | - else |
|
| 736 | - $context['error_message'] = $txt['try_again']; |
|
| 788 | + if (allowedTo('admin_forum')) { |
|
| 789 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 790 | + } else { |
|
| 791 | + $context['error_message'] = $txt['try_again']; |
|
| 792 | + } |
|
| 737 | 793 | |
| 738 | 794 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 739 | 795 | { |
@@ -762,25 +818,28 @@ discard block |
||
| 762 | 818 | $connection = $connection === null ? $db_connection : $connection; |
| 763 | 819 | |
| 764 | 820 | // With nothing to insert, simply return. |
| 765 | - if (empty($data)) |
|
| 766 | - return; |
|
| 821 | + if (empty($data)) { |
|
| 822 | + return; |
|
| 823 | + } |
|
| 767 | 824 | |
| 768 | 825 | // Replace the prefix holder with the actual prefix. |
| 769 | 826 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
| 770 | 827 | |
| 771 | 828 | // Inserting data as a single row can be done as a single array. |
| 772 | - if (!is_array($data[array_rand($data)])) |
|
| 773 | - $data = array($data); |
|
| 829 | + if (!is_array($data[array_rand($data)])) { |
|
| 830 | + $data = array($data); |
|
| 831 | + } |
|
| 774 | 832 | |
| 775 | 833 | // Create the mold for a single row insert. |
| 776 | 834 | $insertData = '('; |
| 777 | 835 | foreach ($columns as $columnName => $type) |
| 778 | 836 | { |
| 779 | 837 | // Are we restricting the length? |
| 780 | - if (strpos($type, 'string-') !== false) |
|
| 781 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 782 | - else |
|
| 783 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 838 | + if (strpos($type, 'string-') !== false) { |
|
| 839 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 840 | + } else { |
|
| 841 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 842 | + } |
|
| 784 | 843 | } |
| 785 | 844 | $insertData = substr($insertData, 0, -2) . ')'; |
| 786 | 845 | |
@@ -789,8 +848,9 @@ discard block |
||
| 789 | 848 | |
| 790 | 849 | // Here's where the variables are injected to the query. |
| 791 | 850 | $insertRows = array(); |
| 792 | - foreach ($data as $dataRow) |
|
| 793 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 851 | + foreach ($data as $dataRow) { |
|
| 852 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 853 | + } |
|
| 794 | 854 | |
| 795 | 855 | // Determine the method of insertion. |
| 796 | 856 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
@@ -821,8 +881,9 @@ discard block |
||
| 821 | 881 | */ |
| 822 | 882 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 823 | 883 | { |
| 824 | - if (empty($log_message)) |
|
| 825 | - $log_message = $error_message; |
|
| 884 | + if (empty($log_message)) { |
|
| 885 | + $log_message = $error_message; |
|
| 886 | + } |
|
| 826 | 887 | |
| 827 | 888 | foreach (debug_backtrace() as $step) |
| 828 | 889 | { |
@@ -841,12 +902,14 @@ discard block |
||
| 841 | 902 | } |
| 842 | 903 | |
| 843 | 904 | // A special case - we want the file and line numbers for debugging. |
| 844 | - if ($error_type == 'return') |
|
| 845 | - return array($file, $line); |
|
| 905 | + if ($error_type == 'return') { |
|
| 906 | + return array($file, $line); |
|
| 907 | + } |
|
| 846 | 908 | |
| 847 | 909 | // Is always a critical error. |
| 848 | - if (function_exists('log_error')) |
|
| 849 | - log_error($log_message, 'critical', $file, $line); |
|
| 910 | + if (function_exists('log_error')) { |
|
| 911 | + log_error($log_message, 'critical', $file, $line); |
|
| 912 | + } |
|
| 850 | 913 | |
| 851 | 914 | if (function_exists('fatal_error')) |
| 852 | 915 | { |
@@ -854,12 +917,12 @@ discard block |
||
| 854 | 917 | |
| 855 | 918 | // Cannot continue... |
| 856 | 919 | exit; |
| 920 | + } elseif ($error_type) { |
|
| 921 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 922 | + } else { |
|
| 923 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 924 | + } |
|
| 857 | 925 | } |
| 858 | - elseif ($error_type) |
|
| 859 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 860 | - else |
|
| 861 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 862 | -} |
|
| 863 | 926 | |
| 864 | 927 | /** |
| 865 | 928 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -876,10 +939,11 @@ discard block |
||
| 876 | 939 | '\\' => '\\\\', |
| 877 | 940 | ); |
| 878 | 941 | |
| 879 | - if ($translate_human_wildcards) |
|
| 880 | - $replacements += array( |
|
| 942 | + if ($translate_human_wildcards) { |
|
| 943 | + $replacements += array( |
|
| 881 | 944 | '*' => '%', |
| 882 | 945 | ); |
| 946 | + } |
|
| 883 | 947 | |
| 884 | 948 | return strtr($string, $replacements); |
| 885 | 949 | } |
@@ -893,8 +957,9 @@ discard block |
||
| 893 | 957 | */ |
| 894 | 958 | function smf_is_resource($result) |
| 895 | 959 | { |
| 896 | - if ($result instanceof mysqli_result) |
|
| 897 | - return true; |
|
| 960 | + if ($result instanceof mysqli_result) { |
|
| 961 | + return true; |
|
| 962 | + } |
|
| 898 | 963 | |
| 899 | 964 | return false; |
| 900 | 965 | } |
@@ -456,7 +456,6 @@ discard block |
||
| 456 | 456 | |
| 457 | 457 | /** |
| 458 | 458 | * affected_rows |
| 459 | - * @param resource $connection |
|
| 460 | 459 | */ |
| 461 | 460 | function smf_db_affected_rows($result = null) |
| 462 | 461 | { |
@@ -799,7 +798,7 @@ discard block |
||
| 799 | 798 | * |
| 800 | 799 | * @param string $db_name The database name |
| 801 | 800 | * @param resource $db_connection The database connection |
| 802 | - * @return true Always returns true |
|
| 801 | + * @return boolean Always returns true |
|
| 803 | 802 | */ |
| 804 | 803 | function smf_db_select_db($db_name, $db_connection) |
| 805 | 804 | { |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | if (!empty($db_options['persist'])) |
| 64 | 64 | $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
| 65 | 65 | else |
| 66 | - $connection = @pg_connect( 'host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 66 | + $connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 67 | 67 | |
| 68 | 68 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 69 | 69 | if (!$connection) |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * |
| 88 | 88 | * @param string $type Indicates which additional file to load. ('extra', 'packages') |
| 89 | 89 | */ |
| 90 | -function db_extend ($type = 'extra') |
|
| 90 | +function db_extend($type = 'extra') |
|
| 91 | 91 | { |
| 92 | 92 | global $sourcedir, $db_type; |
| 93 | 93 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * @param string $db_prefix The database prefix |
| 104 | 104 | * @param string $db_name The database name |
| 105 | 105 | */ |
| 106 | -function db_fix_prefix (&$db_prefix, $db_name) |
|
| 106 | +function db_fix_prefix(&$db_prefix, $db_name) |
|
| 107 | 107 | { |
| 108 | 108 | return; |
| 109 | 109 | } |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | $replacement[$key] = 'null'; |
| 236 | 236 | if (!isValidIP($value)) |
| 237 | 237 | smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
| 238 | - $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
|
| 238 | + $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | return implode(', ', $replacement); |
@@ -548,7 +548,7 @@ discard block |
||
| 548 | 548 | |
| 549 | 549 | // Log the error. |
| 550 | 550 | if (function_exists('log_error')) |
| 551 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" .$db_string : ''), 'database', $file, $line); |
|
| 551 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
| 552 | 552 | |
| 553 | 553 | // Nothing's defined yet... just die with it. |
| 554 | 554 | if (empty($context) || empty($txt)) |
@@ -684,31 +684,31 @@ discard block |
||
| 684 | 684 | static $pg_version; |
| 685 | 685 | static $replace_support; |
| 686 | 686 | |
| 687 | - if(empty($pg_version)) |
|
| 687 | + if (empty($pg_version)) |
|
| 688 | 688 | { |
| 689 | 689 | db_extend(); |
| 690 | 690 | //pg 9.5 got replace support |
| 691 | 691 | $pg_version = $smcFunc['db_get_version'](); |
| 692 | 692 | // if we got a Beta Version |
| 693 | 693 | if (stripos($pg_version, 'beta') !== false) |
| 694 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')).'.0'; |
|
| 694 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
| 695 | 695 | // or RC |
| 696 | 696 | if (stripos($pg_version, 'rc') !== false) |
| 697 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')).'.0'; |
|
| 697 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
| 698 | 698 | |
| 699 | - $replace_support = (version_compare($pg_version,'9.5.0','>=') ? true : false); |
|
| 699 | + $replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false); |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | $count = 0; |
| 703 | 703 | $where = ''; |
| 704 | 704 | $count_pk = 0; |
| 705 | 705 | |
| 706 | - If($replace_support) |
|
| 706 | + If ($replace_support) |
|
| 707 | 707 | { |
| 708 | 708 | foreach ($columns as $columnName => $type) |
| 709 | 709 | { |
| 710 | 710 | //check pk fiel |
| 711 | - IF(in_array($columnName, $keys)) |
|
| 711 | + IF (in_array($columnName, $keys)) |
|
| 712 | 712 | { |
| 713 | 713 | $key_str .= ($count_pk > 0 ? ',' : ''); |
| 714 | 714 | $key_str .= $columnName; |
@@ -717,11 +717,11 @@ discard block |
||
| 717 | 717 | else //normal field |
| 718 | 718 | { |
| 719 | 719 | $col_str .= ($count > 0 ? ',' : ''); |
| 720 | - $col_str .= $columnName.' = EXCLUDED.'.$columnName; |
|
| 720 | + $col_str .= $columnName . ' = EXCLUDED.' . $columnName; |
|
| 721 | 721 | $count++; |
| 722 | 722 | } |
| 723 | 723 | } |
| 724 | - $replace = ' ON CONFLICT ('.$key_str.') DO UPDATE SET '.$col_str; |
|
| 724 | + $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
| 725 | 725 | } |
| 726 | 726 | else |
| 727 | 727 | { |
@@ -781,7 +781,7 @@ discard block |
||
| 781 | 781 | $smcFunc['db_query']('', ' |
| 782 | 782 | INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '") |
| 783 | 783 | VALUES |
| 784 | - ' . $entry.$replace, |
|
| 784 | + ' . $entry . $replace, |
|
| 785 | 785 | array( |
| 786 | 786 | 'security_override' => true, |
| 787 | 787 | 'db_error_skip' => $method == 'ignore' || $table === $db_prefix . 'log_errors', |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | * @param bool $translate_human_wildcards If true, turns human readable wildcards into SQL wildcards. |
| 877 | 877 | * @return string The escaped string |
| 878 | 878 | */ |
| 879 | -function smf_db_escape_wildcard_string($string, $translate_human_wildcards=false) |
|
| 879 | +function smf_db_escape_wildcard_string($string, $translate_human_wildcards = false) |
|
| 880 | 880 | { |
| 881 | 881 | $replacements = array( |
| 882 | 882 | '%' => '\%', |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -34,8 +35,8 @@ discard block |
||
| 34 | 35 | global $smcFunc; |
| 35 | 36 | |
| 36 | 37 | // Map some database specific functions, only do this once. |
| 37 | - if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'postg_fetch_assoc') |
|
| 38 | - $smcFunc += array( |
|
| 38 | + if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'postg_fetch_assoc') { |
|
| 39 | + $smcFunc += array( |
|
| 39 | 40 | 'db_query' => 'smf_db_query', |
| 40 | 41 | 'db_quote' => 'smf_db_quote', |
| 41 | 42 | 'db_insert' => 'smf_db_insert', |
@@ -59,11 +60,13 @@ discard block |
||
| 59 | 60 | 'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string', |
| 60 | 61 | 'db_is_resource' => 'is_resource', |
| 61 | 62 | ); |
| 63 | + } |
|
| 62 | 64 | |
| 63 | - if (!empty($db_options['persist'])) |
|
| 64 | - $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 65 | - else |
|
| 66 | - $connection = @pg_connect( 'host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 65 | + if (!empty($db_options['persist'])) { |
|
| 66 | + $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 67 | + } else { |
|
| 68 | + $connection = @pg_connect( 'host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
| 69 | + } |
|
| 67 | 70 | |
| 68 | 71 | // Something's wrong, show an error if its fatal (which we assume it is) |
| 69 | 72 | if (!$connection) |
@@ -71,8 +74,7 @@ discard block |
||
| 71 | 74 | if (!empty($db_options['non_fatal'])) |
| 72 | 75 | { |
| 73 | 76 | return null; |
| 74 | - } |
|
| 75 | - else |
|
| 77 | + } else |
|
| 76 | 78 | { |
| 77 | 79 | display_db_error(); |
| 78 | 80 | } |
@@ -123,34 +125,42 @@ discard block |
||
| 123 | 125 | |
| 124 | 126 | list ($values, $connection) = $db_callback; |
| 125 | 127 | |
| 126 | - if ($matches[1] === 'db_prefix') |
|
| 127 | - return $db_prefix; |
|
| 128 | + if ($matches[1] === 'db_prefix') { |
|
| 129 | + return $db_prefix; |
|
| 130 | + } |
|
| 128 | 131 | |
| 129 | - if ($matches[1] === 'query_see_board') |
|
| 130 | - return $user_info['query_see_board']; |
|
| 132 | + if ($matches[1] === 'query_see_board') { |
|
| 133 | + return $user_info['query_see_board']; |
|
| 134 | + } |
|
| 131 | 135 | |
| 132 | - if ($matches[1] === 'query_wanna_see_board') |
|
| 133 | - return $user_info['query_wanna_see_board']; |
|
| 136 | + if ($matches[1] === 'query_wanna_see_board') { |
|
| 137 | + return $user_info['query_wanna_see_board']; |
|
| 138 | + } |
|
| 134 | 139 | |
| 135 | - if ($matches[1] === 'empty') |
|
| 136 | - return '\'\''; |
|
| 140 | + if ($matches[1] === 'empty') { |
|
| 141 | + return '\'\''; |
|
| 142 | + } |
|
| 137 | 143 | |
| 138 | - if (!isset($matches[2])) |
|
| 139 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 144 | + if (!isset($matches[2])) { |
|
| 145 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 146 | + } |
|
| 140 | 147 | |
| 141 | - if ($matches[1] === 'literal') |
|
| 142 | - return '\'' . pg_escape_string($matches[2]) . '\''; |
|
| 148 | + if ($matches[1] === 'literal') { |
|
| 149 | + return '\'' . pg_escape_string($matches[2]) . '\''; |
|
| 150 | + } |
|
| 143 | 151 | |
| 144 | - if (!isset($values[$matches[2]])) |
|
| 145 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 152 | + if (!isset($values[$matches[2]])) { |
|
| 153 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 154 | + } |
|
| 146 | 155 | |
| 147 | 156 | $replacement = $values[$matches[2]]; |
| 148 | 157 | |
| 149 | 158 | switch ($matches[1]) |
| 150 | 159 | { |
| 151 | 160 | case 'int': |
| 152 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
| 153 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 161 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
| 162 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 163 | + } |
|
| 154 | 164 | return (string) (int) $replacement; |
| 155 | 165 | break; |
| 156 | 166 | |
@@ -162,49 +172,55 @@ discard block |
||
| 162 | 172 | case 'array_int': |
| 163 | 173 | if (is_array($replacement)) |
| 164 | 174 | { |
| 165 | - if (empty($replacement)) |
|
| 166 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 175 | + if (empty($replacement)) { |
|
| 176 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 177 | + } |
|
| 167 | 178 | |
| 168 | 179 | foreach ($replacement as $key => $value) |
| 169 | 180 | { |
| 170 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
| 171 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 181 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
| 182 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 183 | + } |
|
| 172 | 184 | |
| 173 | 185 | $replacement[$key] = (string) (int) $value; |
| 174 | 186 | } |
| 175 | 187 | |
| 176 | 188 | return implode(', ', $replacement); |
| 189 | + } else { |
|
| 190 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 177 | 191 | } |
| 178 | - else |
|
| 179 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 180 | 192 | |
| 181 | 193 | break; |
| 182 | 194 | |
| 183 | 195 | case 'array_string': |
| 184 | 196 | if (is_array($replacement)) |
| 185 | 197 | { |
| 186 | - if (empty($replacement)) |
|
| 187 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 198 | + if (empty($replacement)) { |
|
| 199 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 200 | + } |
|
| 188 | 201 | |
| 189 | - foreach ($replacement as $key => $value) |
|
| 190 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 202 | + foreach ($replacement as $key => $value) { |
|
| 203 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
| 204 | + } |
|
| 191 | 205 | |
| 192 | 206 | return implode(', ', $replacement); |
| 207 | + } else { |
|
| 208 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 193 | 209 | } |
| 194 | - else |
|
| 195 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 196 | 210 | break; |
| 197 | 211 | |
| 198 | 212 | case 'date': |
| 199 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
| 200 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 201 | - else |
|
| 202 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 213 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
| 214 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
| 215 | + } else { |
|
| 216 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 217 | + } |
|
| 203 | 218 | break; |
| 204 | 219 | |
| 205 | 220 | case 'float': |
| 206 | - if (!is_numeric($replacement)) |
|
| 207 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 221 | + if (!is_numeric($replacement)) { |
|
| 222 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 223 | + } |
|
| 208 | 224 | return (string) (float) $replacement; |
| 209 | 225 | break; |
| 210 | 226 | |
@@ -217,31 +233,36 @@ discard block |
||
| 217 | 233 | break; |
| 218 | 234 | |
| 219 | 235 | case 'inet': |
| 220 | - if ($replacement == 'null' || $replacement == '') |
|
| 221 | - return 'null'; |
|
| 222 | - if (inet_pton($replacement) === false) |
|
| 223 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 236 | + if ($replacement == 'null' || $replacement == '') { |
|
| 237 | + return 'null'; |
|
| 238 | + } |
|
| 239 | + if (inet_pton($replacement) === false) { |
|
| 240 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 241 | + } |
|
| 224 | 242 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
| 225 | 243 | |
| 226 | 244 | case 'array_inet': |
| 227 | 245 | if (is_array($replacement)) |
| 228 | 246 | { |
| 229 | - if (empty($replacement)) |
|
| 230 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 247 | + if (empty($replacement)) { |
|
| 248 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 249 | + } |
|
| 231 | 250 | |
| 232 | 251 | foreach ($replacement as $key => $value) |
| 233 | 252 | { |
| 234 | - if ($replacement == 'null' || $replacement == '') |
|
| 235 | - $replacement[$key] = 'null'; |
|
| 236 | - if (!isValidIP($value)) |
|
| 237 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 253 | + if ($replacement == 'null' || $replacement == '') { |
|
| 254 | + $replacement[$key] = 'null'; |
|
| 255 | + } |
|
| 256 | + if (!isValidIP($value)) { |
|
| 257 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 258 | + } |
|
| 238 | 259 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
| 239 | 260 | } |
| 240 | 261 | |
| 241 | 262 | return implode(', ', $replacement); |
| 263 | + } else { |
|
| 264 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 242 | 265 | } |
| 243 | - else |
|
| 244 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
| 245 | 266 | break; |
| 246 | 267 | |
| 247 | 268 | default: |
@@ -328,14 +349,16 @@ discard block |
||
| 328 | 349 | ), |
| 329 | 350 | ); |
| 330 | 351 | |
| 331 | - if (isset($replacements[$identifier])) |
|
| 332 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 352 | + if (isset($replacements[$identifier])) { |
|
| 353 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
| 354 | + } |
|
| 333 | 355 | |
| 334 | 356 | // Limits need to be a little different. |
| 335 | 357 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
| 336 | 358 | |
| 337 | - if (trim($db_string) == '') |
|
| 338 | - return false; |
|
| 359 | + if (trim($db_string) == '') { |
|
| 360 | + return false; |
|
| 361 | + } |
|
| 339 | 362 | |
| 340 | 363 | // Comments that are allowed in a query are preg_removed. |
| 341 | 364 | static $allowed_comments_from = array( |
@@ -355,8 +378,9 @@ discard block |
||
| 355 | 378 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
| 356 | 379 | $db_replace_result = 0; |
| 357 | 380 | |
| 358 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
| 359 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 381 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
| 382 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
| 383 | + } |
|
| 360 | 384 | |
| 361 | 385 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
| 362 | 386 | { |
@@ -377,8 +401,9 @@ discard block |
||
| 377 | 401 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
| 378 | 402 | |
| 379 | 403 | // Initialize $db_cache if not already initialized. |
| 380 | - if (!isset($db_cache)) |
|
| 381 | - $db_cache = array(); |
|
| 404 | + if (!isset($db_cache)) { |
|
| 405 | + $db_cache = array(); |
|
| 406 | + } |
|
| 382 | 407 | |
| 383 | 408 | if (!empty($_SESSION['debug_redirect'])) |
| 384 | 409 | { |
@@ -404,17 +429,18 @@ discard block |
||
| 404 | 429 | while (true) |
| 405 | 430 | { |
| 406 | 431 | $pos = strpos($db_string, '\'', $pos + 1); |
| 407 | - if ($pos === false) |
|
| 408 | - break; |
|
| 432 | + if ($pos === false) { |
|
| 433 | + break; |
|
| 434 | + } |
|
| 409 | 435 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
| 410 | 436 | |
| 411 | 437 | while (true) |
| 412 | 438 | { |
| 413 | 439 | $pos1 = strpos($db_string, '\'', $pos + 1); |
| 414 | 440 | $pos2 = strpos($db_string, '\\', $pos + 1); |
| 415 | - if ($pos1 === false) |
|
| 416 | - break; |
|
| 417 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
| 441 | + if ($pos1 === false) { |
|
| 442 | + break; |
|
| 443 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
| 418 | 444 | { |
| 419 | 445 | $pos = $pos1; |
| 420 | 446 | break; |
@@ -430,26 +456,31 @@ discard block |
||
| 430 | 456 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
| 431 | 457 | |
| 432 | 458 | // Comments? We don't use comments in our queries, we leave 'em outside! |
| 433 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 434 | - $fail = true; |
|
| 459 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
| 460 | + $fail = true; |
|
| 461 | + } |
|
| 435 | 462 | // Trying to change passwords, slow us down, or something? |
| 436 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 437 | - $fail = true; |
|
| 438 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 439 | - $fail = true; |
|
| 463 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
| 464 | + $fail = true; |
|
| 465 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
| 466 | + $fail = true; |
|
| 467 | + } |
|
| 440 | 468 | |
| 441 | - if (!empty($fail) && function_exists('log_error')) |
|
| 442 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 469 | + if (!empty($fail) && function_exists('log_error')) { |
|
| 470 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 471 | + } |
|
| 443 | 472 | } |
| 444 | 473 | |
| 445 | 474 | $db_last_result = @pg_query($connection, $db_string); |
| 446 | 475 | |
| 447 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
| 448 | - $db_last_result = smf_db_error($db_string, $connection); |
|
| 476 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
| 477 | + $db_last_result = smf_db_error($db_string, $connection); |
|
| 478 | + } |
|
| 449 | 479 | |
| 450 | 480 | // Debugging. |
| 451 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 452 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 481 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 482 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 483 | + } |
|
| 453 | 484 | |
| 454 | 485 | return $db_last_result; |
| 455 | 486 | } |
@@ -462,10 +493,11 @@ discard block |
||
| 462 | 493 | { |
| 463 | 494 | global $db_last_result, $db_replace_result; |
| 464 | 495 | |
| 465 | - if ($db_replace_result) |
|
| 466 | - return $db_replace_result; |
|
| 467 | - elseif ($result === null && !$db_last_result) |
|
| 468 | - return 0; |
|
| 496 | + if ($db_replace_result) { |
|
| 497 | + return $db_replace_result; |
|
| 498 | + } elseif ($result === null && !$db_last_result) { |
|
| 499 | + return 0; |
|
| 500 | + } |
|
| 469 | 501 | |
| 470 | 502 | return pg_affected_rows($result === null ? $db_last_result : $result); |
| 471 | 503 | } |
@@ -484,16 +516,18 @@ discard block |
||
| 484 | 516 | |
| 485 | 517 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
| 486 | 518 | |
| 487 | - if ($connection === false) |
|
| 488 | - $connection = $db_connection; |
|
| 519 | + if ($connection === false) { |
|
| 520 | + $connection = $db_connection; |
|
| 521 | + } |
|
| 489 | 522 | |
| 490 | 523 | // Try get the last ID for the auto increment field. |
| 491 | 524 | $request = $smcFunc['db_query']('', 'SELECT CURRVAL(\'' . $table . '_seq\') AS insertID', |
| 492 | 525 | array( |
| 493 | 526 | ) |
| 494 | 527 | ); |
| 495 | - if (!$request) |
|
| 496 | - return false; |
|
| 528 | + if (!$request) { |
|
| 529 | + return false; |
|
| 530 | + } |
|
| 497 | 531 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
| 498 | 532 | $smcFunc['db_free_result']($request); |
| 499 | 533 | |
@@ -514,12 +548,13 @@ discard block |
||
| 514 | 548 | // Decide which connection to use |
| 515 | 549 | $connection = $connection === null ? $db_connection : $connection; |
| 516 | 550 | |
| 517 | - if ($type == 'begin') |
|
| 518 | - return @pg_query($connection, 'BEGIN'); |
|
| 519 | - elseif ($type == 'rollback') |
|
| 520 | - return @pg_query($connection, 'ROLLBACK'); |
|
| 521 | - elseif ($type == 'commit') |
|
| 522 | - return @pg_query($connection, 'COMMIT'); |
|
| 551 | + if ($type == 'begin') { |
|
| 552 | + return @pg_query($connection, 'BEGIN'); |
|
| 553 | + } elseif ($type == 'rollback') { |
|
| 554 | + return @pg_query($connection, 'ROLLBACK'); |
|
| 555 | + } elseif ($type == 'commit') { |
|
| 556 | + return @pg_query($connection, 'COMMIT'); |
|
| 557 | + } |
|
| 523 | 558 | |
| 524 | 559 | return false; |
| 525 | 560 | } |
@@ -547,19 +582,22 @@ discard block |
||
| 547 | 582 | $query_error = @pg_last_error($connection); |
| 548 | 583 | |
| 549 | 584 | // Log the error. |
| 550 | - if (function_exists('log_error')) |
|
| 551 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" .$db_string : ''), 'database', $file, $line); |
|
| 585 | + if (function_exists('log_error')) { |
|
| 586 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" .$db_string : ''), 'database', $file, $line); |
|
| 587 | + } |
|
| 552 | 588 | |
| 553 | 589 | // Nothing's defined yet... just die with it. |
| 554 | - if (empty($context) || empty($txt)) |
|
| 555 | - die($query_error); |
|
| 590 | + if (empty($context) || empty($txt)) { |
|
| 591 | + die($query_error); |
|
| 592 | + } |
|
| 556 | 593 | |
| 557 | 594 | // Show an error message, if possible. |
| 558 | 595 | $context['error_title'] = $txt['database_error']; |
| 559 | - if (allowedTo('admin_forum')) |
|
| 560 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 561 | - else |
|
| 562 | - $context['error_message'] = $txt['try_again']; |
|
| 596 | + if (allowedTo('admin_forum')) { |
|
| 597 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
| 598 | + } else { |
|
| 599 | + $context['error_message'] = $txt['try_again']; |
|
| 600 | + } |
|
| 563 | 601 | |
| 564 | 602 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
| 565 | 603 | { |
@@ -581,12 +619,14 @@ discard block |
||
| 581 | 619 | { |
| 582 | 620 | global $db_row_count; |
| 583 | 621 | |
| 584 | - if ($counter !== false) |
|
| 585 | - return pg_fetch_row($request, $counter); |
|
| 622 | + if ($counter !== false) { |
|
| 623 | + return pg_fetch_row($request, $counter); |
|
| 624 | + } |
|
| 586 | 625 | |
| 587 | 626 | // Reset the row counter... |
| 588 | - if (!isset($db_row_count[(int) $request])) |
|
| 589 | - $db_row_count[(int) $request] = 0; |
|
| 627 | + if (!isset($db_row_count[(int) $request])) { |
|
| 628 | + $db_row_count[(int) $request] = 0; |
|
| 629 | + } |
|
| 590 | 630 | |
| 591 | 631 | // Return the right row. |
| 592 | 632 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -603,12 +643,14 @@ discard block |
||
| 603 | 643 | { |
| 604 | 644 | global $db_row_count; |
| 605 | 645 | |
| 606 | - if ($counter !== false) |
|
| 607 | - return pg_fetch_assoc($request, $counter); |
|
| 646 | + if ($counter !== false) { |
|
| 647 | + return pg_fetch_assoc($request, $counter); |
|
| 648 | + } |
|
| 608 | 649 | |
| 609 | 650 | // Reset the row counter... |
| 610 | - if (!isset($db_row_count[(int) $request])) |
|
| 611 | - $db_row_count[(int) $request] = 0; |
|
| 651 | + if (!isset($db_row_count[(int) $request])) { |
|
| 652 | + $db_row_count[(int) $request] = 0; |
|
| 653 | + } |
|
| 612 | 654 | |
| 613 | 655 | // Return the right row. |
| 614 | 656 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -660,11 +702,13 @@ discard block |
||
| 660 | 702 | |
| 661 | 703 | $replace = ''; |
| 662 | 704 | |
| 663 | - if (empty($data)) |
|
| 664 | - return; |
|
| 705 | + if (empty($data)) { |
|
| 706 | + return; |
|
| 707 | + } |
|
| 665 | 708 | |
| 666 | - if (!is_array($data[array_rand($data)])) |
|
| 667 | - $data = array($data); |
|
| 709 | + if (!is_array($data[array_rand($data)])) { |
|
| 710 | + $data = array($data); |
|
| 711 | + } |
|
| 668 | 712 | |
| 669 | 713 | // Replace the prefix holder with the actual prefix. |
| 670 | 714 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -690,11 +734,13 @@ discard block |
||
| 690 | 734 | //pg 9.5 got replace support |
| 691 | 735 | $pg_version = $smcFunc['db_get_version'](); |
| 692 | 736 | // if we got a Beta Version |
| 693 | - if (stripos($pg_version, 'beta') !== false) |
|
| 694 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')).'.0'; |
|
| 737 | + if (stripos($pg_version, 'beta') !== false) { |
|
| 738 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')).'.0'; |
|
| 739 | + } |
|
| 695 | 740 | // or RC |
| 696 | - if (stripos($pg_version, 'rc') !== false) |
|
| 697 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')).'.0'; |
|
| 741 | + if (stripos($pg_version, 'rc') !== false) { |
|
| 742 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')).'.0'; |
|
| 743 | + } |
|
| 698 | 744 | |
| 699 | 745 | $replace_support = (version_compare($pg_version,'9.5.0','>=') ? true : false); |
| 700 | 746 | } |
@@ -713,8 +759,7 @@ discard block |
||
| 713 | 759 | $key_str .= ($count_pk > 0 ? ',' : ''); |
| 714 | 760 | $key_str .= $columnName; |
| 715 | 761 | $count_pk++; |
| 716 | - } |
|
| 717 | - else //normal field |
|
| 762 | + } else //normal field |
|
| 718 | 763 | { |
| 719 | 764 | $col_str .= ($count > 0 ? ',' : ''); |
| 720 | 765 | $col_str .= $columnName.' = EXCLUDED.'.$columnName; |
@@ -722,20 +767,21 @@ discard block |
||
| 722 | 767 | } |
| 723 | 768 | } |
| 724 | 769 | $replace = ' ON CONFLICT ('.$key_str.') DO UPDATE SET '.$col_str; |
| 725 | - } |
|
| 726 | - else |
|
| 770 | + } else |
|
| 727 | 771 | { |
| 728 | 772 | foreach ($columns as $columnName => $type) |
| 729 | 773 | { |
| 730 | 774 | // Are we restricting the length? |
| 731 | - if (strpos($type, 'string-') !== false) |
|
| 732 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 733 | - else |
|
| 734 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 775 | + if (strpos($type, 'string-') !== false) { |
|
| 776 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
| 777 | + } else { |
|
| 778 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
| 779 | + } |
|
| 735 | 780 | |
| 736 | 781 | // A key? That's what we were looking for. |
| 737 | - if (in_array($columnName, $keys)) |
|
| 738 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 782 | + if (in_array($columnName, $keys)) { |
|
| 783 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
| 784 | + } |
|
| 739 | 785 | $count++; |
| 740 | 786 | } |
| 741 | 787 | |
@@ -761,10 +807,11 @@ discard block |
||
| 761 | 807 | foreach ($columns as $columnName => $type) |
| 762 | 808 | { |
| 763 | 809 | // Are we restricting the length? |
| 764 | - if (strpos($type, 'string-') !== false) |
|
| 765 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 766 | - else |
|
| 767 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 810 | + if (strpos($type, 'string-') !== false) { |
|
| 811 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
| 812 | + } else { |
|
| 813 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
| 814 | + } |
|
| 768 | 815 | } |
| 769 | 816 | $insertData = substr($insertData, 0, -2) . ')'; |
| 770 | 817 | |
@@ -773,11 +820,12 @@ discard block |
||
| 773 | 820 | |
| 774 | 821 | // Here's where the variables are injected to the query. |
| 775 | 822 | $insertRows = array(); |
| 776 | - foreach ($data as $dataRow) |
|
| 777 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 823 | + foreach ($data as $dataRow) { |
|
| 824 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
| 825 | + } |
|
| 778 | 826 | |
| 779 | - foreach ($insertRows as $entry) |
|
| 780 | - // Do the insert. |
|
| 827 | + foreach ($insertRows as $entry) { |
|
| 828 | + // Do the insert. |
|
| 781 | 829 | $smcFunc['db_query']('', ' |
| 782 | 830 | INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '") |
| 783 | 831 | VALUES |
@@ -788,11 +836,13 @@ discard block |
||
| 788 | 836 | ), |
| 789 | 837 | $connection |
| 790 | 838 | ); |
| 839 | + } |
|
| 791 | 840 | } |
| 792 | 841 | |
| 793 | - if ($priv_trans) |
|
| 794 | - $smcFunc['db_transaction']('commit', $connection); |
|
| 795 | -} |
|
| 842 | + if ($priv_trans) { |
|
| 843 | + $smcFunc['db_transaction']('commit', $connection); |
|
| 844 | + } |
|
| 845 | + } |
|
| 796 | 846 | |
| 797 | 847 | /** |
| 798 | 848 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -829,8 +879,9 @@ discard block |
||
| 829 | 879 | */ |
| 830 | 880 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
| 831 | 881 | { |
| 832 | - if (empty($log_message)) |
|
| 833 | - $log_message = $error_message; |
|
| 882 | + if (empty($log_message)) { |
|
| 883 | + $log_message = $error_message; |
|
| 884 | + } |
|
| 834 | 885 | |
| 835 | 886 | foreach (debug_backtrace() as $step) |
| 836 | 887 | { |
@@ -849,12 +900,14 @@ discard block |
||
| 849 | 900 | } |
| 850 | 901 | |
| 851 | 902 | // A special case - we want the file and line numbers for debugging. |
| 852 | - if ($error_type == 'return') |
|
| 853 | - return array($file, $line); |
|
| 903 | + if ($error_type == 'return') { |
|
| 904 | + return array($file, $line); |
|
| 905 | + } |
|
| 854 | 906 | |
| 855 | 907 | // Is always a critical error. |
| 856 | - if (function_exists('log_error')) |
|
| 857 | - log_error($log_message, 'critical', $file, $line); |
|
| 908 | + if (function_exists('log_error')) { |
|
| 909 | + log_error($log_message, 'critical', $file, $line); |
|
| 910 | + } |
|
| 858 | 911 | |
| 859 | 912 | if (function_exists('fatal_error')) |
| 860 | 913 | { |
@@ -862,12 +915,12 @@ discard block |
||
| 862 | 915 | |
| 863 | 916 | // Cannot continue... |
| 864 | 917 | exit; |
| 918 | + } elseif ($error_type) { |
|
| 919 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 920 | + } else { |
|
| 921 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 922 | + } |
|
| 865 | 923 | } |
| 866 | - elseif ($error_type) |
|
| 867 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
| 868 | - else |
|
| 869 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
| 870 | -} |
|
| 871 | 924 | |
| 872 | 925 | /** |
| 873 | 926 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -884,10 +937,11 @@ discard block |
||
| 884 | 937 | '\\' => '\\\\', |
| 885 | 938 | ); |
| 886 | 939 | |
| 887 | - if ($translate_human_wildcards) |
|
| 888 | - $replacements += array( |
|
| 940 | + if ($translate_human_wildcards) { |
|
| 941 | + $replacements += array( |
|
| 889 | 942 | '*' => '%', |
| 890 | 943 | ); |
| 944 | + } |
|
| 891 | 945 | |
| 892 | 946 | return strtr($string, $replacements); |
| 893 | 947 | } |
@@ -170,7 +170,7 @@ |
||
| 170 | 170 | * |
| 171 | 171 | * @param string $fileName The path to the file |
| 172 | 172 | * @param int $preferred_format The preferred format - 0 to automatically determine, 1 for gif, 2 for jpg, 3 for png, 6 for bmp and 15 for wbmp |
| 173 | - * @return boolean Whether the reencoding was successful |
|
| 173 | + * @return false|null Whether the reencoding was successful |
|
| 174 | 174 | */ |
| 175 | 175 | function reencodeImage($fileName, $preferred_format = 0) |
| 176 | 176 | { |
@@ -523,7 +523,6 @@ discard block |
||
| 523 | 523 | /** |
| 524 | 524 | * Copy image. |
| 525 | 525 | * Used when imagecopyresample() is not available. |
| 526 | - |
|
| 527 | 526 | * @param resource $dst_img The destination image - a GD image resource |
| 528 | 527 | * @param resource $src_img The source image - a GD image resource |
| 529 | 528 | * @param int $dst_x The "x" coordinate of the destination image |
@@ -754,7 +753,6 @@ discard block |
||
| 754 | 753 | |
| 755 | 754 | /** |
| 756 | 755 | * Writes a gif file to disk as a png file. |
| 757 | - |
|
| 758 | 756 | * @param resource $gif A gif image resource |
| 759 | 757 | * @param string $lpszFileName The name of the file |
| 760 | 758 | * @param int $background_color The background color |
@@ -18,8 +18,9 @@ discard block |
||
| 18 | 18 | * @version 2.1 Beta 3 |
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | -if (!defined('SMF')) |
|
| 21 | +if (!defined('SMF')) { |
|
| 22 | 22 | die('No direct access...'); |
| 23 | +} |
|
| 23 | 24 | |
| 24 | 25 | /** |
| 25 | 26 | * downloads a file from a url and stores it locally for avatar use by id_member. |
@@ -44,8 +45,9 @@ discard block |
||
| 44 | 45 | $destName = 'avatar_' . $memID . '_' . time() . '.' . $ext; |
| 45 | 46 | |
| 46 | 47 | // Just making sure there is a non-zero member. |
| 47 | - if (empty($memID)) |
|
| 48 | - return false; |
|
| 48 | + if (empty($memID)) { |
|
| 49 | + return false; |
|
| 50 | + } |
|
| 49 | 51 | |
| 50 | 52 | require_once($sourcedir . '/ManageAttachments.php'); |
| 51 | 53 | removeAttachments(array('id_member' => $memID)); |
@@ -76,10 +78,11 @@ discard block |
||
| 76 | 78 | $destName = $modSettings['custom_avatar_dir'] . '/' . $destName . '.tmp'; |
| 77 | 79 | |
| 78 | 80 | // Resize it. |
| 79 | - if (!empty($modSettings['avatar_download_png'])) |
|
| 80 | - $success = resizeImageFile($url, $destName, $max_width, $max_height, 3); |
|
| 81 | - else |
|
| 82 | - $success = resizeImageFile($url, $destName, $max_width, $max_height); |
|
| 81 | + if (!empty($modSettings['avatar_download_png'])) { |
|
| 82 | + $success = resizeImageFile($url, $destName, $max_width, $max_height, 3); |
|
| 83 | + } else { |
|
| 84 | + $success = resizeImageFile($url, $destName, $max_width, $max_height); |
|
| 85 | + } |
|
| 83 | 86 | |
| 84 | 87 | // Remove the .tmp extension. |
| 85 | 88 | $destName = substr($destName, 0, -4); |
@@ -108,11 +111,10 @@ discard block |
||
| 108 | 111 | ) |
| 109 | 112 | ); |
| 110 | 113 | return true; |
| 114 | + } else { |
|
| 115 | + return false; |
|
| 111 | 116 | } |
| 112 | - else |
|
| 113 | - return false; |
|
| 114 | - } |
|
| 115 | - else |
|
| 117 | + } else |
|
| 116 | 118 | { |
| 117 | 119 | $smcFunc['db_query']('', ' |
| 118 | 120 | DELETE FROM {db_prefix}attachments |
@@ -144,17 +146,18 @@ discard block |
||
| 144 | 146 | $destName = $source . '_thumb.tmp'; |
| 145 | 147 | |
| 146 | 148 | // Do the actual resize. |
| 147 | - if (!empty($modSettings['attachment_thumb_png'])) |
|
| 148 | - $success = resizeImageFile($source, $destName, $max_width, $max_height, 3); |
|
| 149 | - else |
|
| 150 | - $success = resizeImageFile($source, $destName, $max_width, $max_height); |
|
| 149 | + if (!empty($modSettings['attachment_thumb_png'])) { |
|
| 150 | + $success = resizeImageFile($source, $destName, $max_width, $max_height, 3); |
|
| 151 | + } else { |
|
| 152 | + $success = resizeImageFile($source, $destName, $max_width, $max_height); |
|
| 153 | + } |
|
| 151 | 154 | |
| 152 | 155 | // Okay, we're done with the temporary stuff. |
| 153 | 156 | $destName = substr($destName, 0, -4); |
| 154 | 157 | |
| 155 | - if ($success && @rename($destName . '.tmp', $destName)) |
|
| 156 | - return true; |
|
| 157 | - else |
|
| 158 | + if ($success && @rename($destName . '.tmp', $destName)) { |
|
| 159 | + return true; |
|
| 160 | + } else |
|
| 158 | 161 | { |
| 159 | 162 | @unlink($destName . '.tmp'); |
| 160 | 163 | @touch($destName); |
@@ -176,18 +179,21 @@ discard block |
||
| 176 | 179 | { |
| 177 | 180 | if (!resizeImageFile($fileName, $fileName . '.tmp', null, null, $preferred_format)) |
| 178 | 181 | { |
| 179 | - if (file_exists($fileName . '.tmp')) |
|
| 180 | - unlink($fileName . '.tmp'); |
|
| 182 | + if (file_exists($fileName . '.tmp')) { |
|
| 183 | + unlink($fileName . '.tmp'); |
|
| 184 | + } |
|
| 181 | 185 | |
| 182 | 186 | return false; |
| 183 | 187 | } |
| 184 | 188 | |
| 185 | - if (!unlink($fileName)) |
|
| 186 | - return false; |
|
| 189 | + if (!unlink($fileName)) { |
|
| 190 | + return false; |
|
| 191 | + } |
|
| 187 | 192 | |
| 188 | - if (!rename($fileName . '.tmp', $fileName)) |
|
| 189 | - return false; |
|
| 190 | -} |
|
| 193 | + if (!rename($fileName . '.tmp', $fileName)) { |
|
| 194 | + return false; |
|
| 195 | + } |
|
| 196 | + } |
|
| 191 | 197 | |
| 192 | 198 | /** |
| 193 | 199 | * Searches through the file to see if there's potentially harmful non-binary content. |
@@ -200,8 +206,9 @@ discard block |
||
| 200 | 206 | function checkImageContents($fileName, $extensiveCheck = false) |
| 201 | 207 | { |
| 202 | 208 | $fp = fopen($fileName, 'rb'); |
| 203 | - if (!$fp) |
|
| 204 | - fatal_lang_error('attach_timeout'); |
|
| 209 | + if (!$fp) { |
|
| 210 | + fatal_lang_error('attach_timeout'); |
|
| 211 | + } |
|
| 205 | 212 | |
| 206 | 213 | $prev_chunk = ''; |
| 207 | 214 | while (!feof($fp)) |
@@ -217,8 +224,7 @@ discard block |
||
| 217 | 224 | fclose($fp); |
| 218 | 225 | return false; |
| 219 | 226 | } |
| 220 | - } |
|
| 221 | - else |
|
| 227 | + } else |
|
| 222 | 228 | { |
| 223 | 229 | // Check for potential infection |
| 224 | 230 | if (preg_match('~(iframe|(?<!cellTextIs)html|eval|body|script\W|[CF]WS[\x01-\x0C])~i', $prev_chunk . $cur_chunk) === 1) |
@@ -245,8 +251,9 @@ discard block |
||
| 245 | 251 | global $gd2; |
| 246 | 252 | |
| 247 | 253 | // Check to see if GD is installed and what version. |
| 248 | - if (($extensionFunctions = get_extension_funcs('gd')) === false) |
|
| 249 | - return false; |
|
| 254 | + if (($extensionFunctions = get_extension_funcs('gd')) === false) { |
|
| 255 | + return false; |
|
| 256 | + } |
|
| 250 | 257 | |
| 251 | 258 | // Also determine if GD2 is installed and store it in a global. |
| 252 | 259 | $gd2 = in_array('imagecreatetruecolor', $extensionFunctions) && function_exists('imagecreatetruecolor'); |
@@ -318,8 +325,9 @@ discard block |
||
| 318 | 325 | global $sourcedir; |
| 319 | 326 | |
| 320 | 327 | // Nothing to do without GD or IM/MW |
| 321 | - if (!checkGD() && !checkImagick() && !checkMagickWand()) |
|
| 322 | - return false; |
|
| 328 | + if (!checkGD() && !checkImagick() && !checkMagickWand()) { |
|
| 329 | + return false; |
|
| 330 | + } |
|
| 323 | 331 | |
| 324 | 332 | static $default_formats = array( |
| 325 | 333 | '1' => 'gif', |
@@ -341,38 +349,39 @@ discard block |
||
| 341 | 349 | fclose($fp_destination); |
| 342 | 350 | |
| 343 | 351 | $sizes = @getimagesize($destination); |
| 344 | - } |
|
| 345 | - elseif ($fp_destination) |
|
| 352 | + } elseif ($fp_destination) |
|
| 346 | 353 | { |
| 347 | 354 | $sizes = @getimagesize($source); |
| 348 | 355 | |
| 349 | 356 | $fp_source = fopen($source, 'rb'); |
| 350 | 357 | if ($fp_source !== false) |
| 351 | 358 | { |
| 352 | - while (!feof($fp_source)) |
|
| 353 | - fwrite($fp_destination, fread($fp_source, 8192)); |
|
| 359 | + while (!feof($fp_source)) { |
|
| 360 | + fwrite($fp_destination, fread($fp_source, 8192)); |
|
| 361 | + } |
|
| 354 | 362 | fclose($fp_source); |
| 363 | + } else { |
|
| 364 | + $sizes = array(-1, -1, -1); |
|
| 355 | 365 | } |
| 356 | - else |
|
| 357 | - $sizes = array(-1, -1, -1); |
|
| 358 | 366 | fclose($fp_destination); |
| 359 | 367 | } |
| 360 | 368 | // We can't get to the file. |
| 361 | - else |
|
| 362 | - $sizes = array(-1, -1, -1); |
|
| 369 | + else { |
|
| 370 | + $sizes = array(-1, -1, -1); |
|
| 371 | + } |
|
| 363 | 372 | |
| 364 | 373 | // See if we have -or- can get the needed memory for this operation |
| 365 | 374 | // ImageMagick isn't subject to PHP's memory limits :) |
| 366 | - if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes)) |
|
| 367 | - return false; |
|
| 375 | + if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes)) { |
|
| 376 | + return false; |
|
| 377 | + } |
|
| 368 | 378 | |
| 369 | 379 | // A known and supported format? |
| 370 | 380 | // @todo test PSD and gif. |
| 371 | 381 | if ((checkImagick() || checkMagickWand()) && isset($default_formats[$sizes[2]])) |
| 372 | 382 | { |
| 373 | 383 | return resizeImage(null, $destination, null, null, $max_width, $max_height, true, $preferred_format); |
| 374 | - } |
|
| 375 | - elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]])) |
|
| 384 | + } elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]])) |
|
| 376 | 385 | { |
| 377 | 386 | $imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]]; |
| 378 | 387 | if ($src_img = @$imagecreatefrom($destination)) |
@@ -425,14 +434,14 @@ discard block |
||
| 425 | 434 | $dest_width = empty($max_width) ? $src_width : $max_width; |
| 426 | 435 | $dest_height = empty($max_height) ? $src_height : $max_height; |
| 427 | 436 | |
| 428 | - if ($default_formats[$preferred_format] == 'jpeg') |
|
| 429 | - $imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 437 | + if ($default_formats[$preferred_format] == 'jpeg') { |
|
| 438 | + $imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 439 | + } |
|
| 430 | 440 | |
| 431 | 441 | $imagick->setImageFormat($default_formats[$preferred_format]); |
| 432 | 442 | $imagick->resizeImage($dest_width, $dest_height, Imagick::FILTER_LANCZOS, 1, true); |
| 433 | 443 | $success = $imagick->writeImage($destName); |
| 434 | - } |
|
| 435 | - else |
|
| 444 | + } else |
|
| 436 | 445 | { |
| 437 | 446 | $magick_wand = newMagickWand(); |
| 438 | 447 | MagickReadImage($magick_wand, $destName); |
@@ -441,8 +450,9 @@ discard block |
||
| 441 | 450 | $dest_width = empty($max_width) ? $src_width : $max_width; |
| 442 | 451 | $dest_height = empty($max_height) ? $src_height : $max_height; |
| 443 | 452 | |
| 444 | - if ($default_formats[$preferred_format] == 'jpeg') |
|
| 445 | - MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 453 | + if ($default_formats[$preferred_format] == 'jpeg') { |
|
| 454 | + MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 455 | + } |
|
| 446 | 456 | |
| 447 | 457 | MagickSetImageFormat($magick_wand, $default_formats[$preferred_format]); |
| 448 | 458 | MagickResizeImage($magick_wand, $dest_width, $dest_height, MW_LanczosFilter, 1, true); |
@@ -450,8 +460,7 @@ discard block |
||
| 450 | 460 | } |
| 451 | 461 | |
| 452 | 462 | return !empty($success); |
| 453 | - } |
|
| 454 | - elseif (checkGD()) |
|
| 463 | + } elseif (checkGD()) |
|
| 455 | 464 | { |
| 456 | 465 | $success = false; |
| 457 | 466 | |
@@ -462,8 +471,7 @@ discard block |
||
| 462 | 471 | { |
| 463 | 472 | $dst_width = $max_width; |
| 464 | 473 | $dst_height = round($src_height * $max_width / $src_width); |
| 465 | - } |
|
| 466 | - elseif (!empty($max_height)) |
|
| 474 | + } elseif (!empty($max_height)) |
|
| 467 | 475 | { |
| 468 | 476 | $dst_width = round($src_width * $max_height / $src_height); |
| 469 | 477 | $dst_height = $max_height; |
@@ -481,44 +489,48 @@ discard block |
||
| 481 | 489 | if ((!empty($preferred_format)) && ($preferred_format == 3)) |
| 482 | 490 | { |
| 483 | 491 | imagealphablending($dst_img, false); |
| 484 | - if (function_exists('imagesavealpha')) |
|
| 485 | - imagesavealpha($dst_img, true); |
|
| 492 | + if (function_exists('imagesavealpha')) { |
|
| 493 | + imagesavealpha($dst_img, true); |
|
| 494 | + } |
|
| 486 | 495 | } |
| 496 | + } else { |
|
| 497 | + $dst_img = imagecreate($dst_width, $dst_height); |
|
| 487 | 498 | } |
| 488 | - else |
|
| 489 | - $dst_img = imagecreate($dst_width, $dst_height); |
|
| 490 | 499 | |
| 491 | 500 | // Resize it! |
| 492 | - if ($gd2) |
|
| 493 | - imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
| 494 | - else |
|
| 495 | - imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
| 501 | + if ($gd2) { |
|
| 502 | + imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
| 503 | + } else { |
|
| 504 | + imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); |
|
| 505 | + } |
|
| 506 | + } else { |
|
| 507 | + $dst_img = $src_img; |
|
| 496 | 508 | } |
| 497 | - else |
|
| 498 | - $dst_img = $src_img; |
|
| 509 | + } else { |
|
| 510 | + $dst_img = $src_img; |
|
| 499 | 511 | } |
| 500 | - else |
|
| 501 | - $dst_img = $src_img; |
|
| 502 | 512 | |
| 503 | 513 | // Save the image as ... |
| 504 | - if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng')) |
|
| 505 | - $success = imagepng($dst_img, $destName); |
|
| 506 | - elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif')) |
|
| 507 | - $success = imagegif($dst_img, $destName); |
|
| 508 | - elseif (function_exists('imagejpeg')) |
|
| 509 | - $success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 514 | + if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng')) { |
|
| 515 | + $success = imagepng($dst_img, $destName); |
|
| 516 | + } elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif')) { |
|
| 517 | + $success = imagegif($dst_img, $destName); |
|
| 518 | + } elseif (function_exists('imagejpeg')) { |
|
| 519 | + $success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82); |
|
| 520 | + } |
|
| 510 | 521 | |
| 511 | 522 | // Free the memory. |
| 512 | 523 | imagedestroy($src_img); |
| 513 | - if ($dst_img != $src_img) |
|
| 514 | - imagedestroy($dst_img); |
|
| 524 | + if ($dst_img != $src_img) { |
|
| 525 | + imagedestroy($dst_img); |
|
| 526 | + } |
|
| 515 | 527 | |
| 516 | 528 | return $success; |
| 517 | - } |
|
| 518 | - else |
|
| 519 | - // Without GD, no image resizing at all. |
|
| 529 | + } else { |
|
| 530 | + // Without GD, no image resizing at all. |
|
| 520 | 531 | return false; |
| 521 | -} |
|
| 532 | + } |
|
| 533 | + } |
|
| 522 | 534 | |
| 523 | 535 | /** |
| 524 | 536 | * Copy image. |
@@ -572,8 +584,9 @@ discard block |
||
| 572 | 584 | $color = imagecolorresolve($dst_img, $red, $green, $blue); |
| 573 | 585 | if ($color == -1) |
| 574 | 586 | { |
| 575 | - if ($palsize++ < 256) |
|
| 576 | - imagecolorallocate($dst_img, $red, $green, $blue); |
|
| 587 | + if ($palsize++ < 256) { |
|
| 588 | + imagecolorallocate($dst_img, $red, $green, $blue); |
|
| 589 | + } |
|
| 577 | 590 | $color = imagecolorclosest($dst_img, $red, $green, $blue); |
| 578 | 591 | } |
| 579 | 592 | |
@@ -603,13 +616,15 @@ discard block |
||
| 603 | 616 | $header = unpack('vtype/Vsize/Vreserved/Voffset', fread($fp, 14)); |
| 604 | 617 | $info = unpack('Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vcolorimportant', fread($fp, 40)); |
| 605 | 618 | |
| 606 | - if ($header['type'] != 0x4D42) |
|
| 607 | - return false; |
|
| 619 | + if ($header['type'] != 0x4D42) { |
|
| 620 | + return false; |
|
| 621 | + } |
|
| 608 | 622 | |
| 609 | - if ($gd2) |
|
| 610 | - $dst_img = imagecreatetruecolor($info['width'], $info['height']); |
|
| 611 | - else |
|
| 612 | - $dst_img = imagecreate($info['width'], $info['height']); |
|
| 623 | + if ($gd2) { |
|
| 624 | + $dst_img = imagecreatetruecolor($info['width'], $info['height']); |
|
| 625 | + } else { |
|
| 626 | + $dst_img = imagecreate($info['width'], $info['height']); |
|
| 627 | + } |
|
| 613 | 628 | |
| 614 | 629 | $palette_size = $header['offset'] - 54; |
| 615 | 630 | $info['ncolor'] = $palette_size / 4; |
@@ -635,8 +650,9 @@ discard block |
||
| 635 | 650 | fseek($fp, $header['offset'] + ($scan_line_size + $scan_line_align) * $l); |
| 636 | 651 | $scan_line = fread($fp, $scan_line_size); |
| 637 | 652 | |
| 638 | - if (strlen($scan_line) < $scan_line_size) |
|
| 639 | - continue; |
|
| 653 | + if (strlen($scan_line) < $scan_line_size) { |
|
| 654 | + continue; |
|
| 655 | + } |
|
| 640 | 656 | |
| 641 | 657 | if ($info['bits'] == 32) |
| 642 | 658 | { |
@@ -654,14 +670,14 @@ discard block |
||
| 654 | 670 | $color = imagecolorallocate($dst_img, $r, $g, $b); |
| 655 | 671 | |
| 656 | 672 | // Gah! Out of colors? Stupid GD 1... try anyhow. |
| 657 | - if ($color == -1) |
|
| 658 | - $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 673 | + if ($color == -1) { |
|
| 674 | + $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 675 | + } |
|
| 659 | 676 | } |
| 660 | 677 | |
| 661 | 678 | imagesetpixel($dst_img, $x, $y, $color); |
| 662 | 679 | } |
| 663 | - } |
|
| 664 | - elseif ($info['bits'] == 24) |
|
| 680 | + } elseif ($info['bits'] == 24) |
|
| 665 | 681 | { |
| 666 | 682 | $x = 0; |
| 667 | 683 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -676,14 +692,14 @@ discard block |
||
| 676 | 692 | $color = imagecolorallocate($dst_img, $r, $g, $b); |
| 677 | 693 | |
| 678 | 694 | // Gah! Out of colors? Stupid GD 1... try anyhow. |
| 679 | - if ($color == -1) |
|
| 680 | - $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 695 | + if ($color == -1) { |
|
| 696 | + $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 697 | + } |
|
| 681 | 698 | } |
| 682 | 699 | |
| 683 | 700 | imagesetpixel($dst_img, $x, $y, $color); |
| 684 | 701 | } |
| 685 | - } |
|
| 686 | - elseif ($info['bits'] == 16) |
|
| 702 | + } elseif ($info['bits'] == 16) |
|
| 687 | 703 | { |
| 688 | 704 | $x = 0; |
| 689 | 705 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -704,20 +720,20 @@ discard block |
||
| 704 | 720 | $color = imagecolorallocate($dst_img, $r, $g, $b); |
| 705 | 721 | |
| 706 | 722 | // Gah! Out of colors? Stupid GD 1... try anyhow. |
| 707 | - if ($color == -1) |
|
| 708 | - $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 723 | + if ($color == -1) { |
|
| 724 | + $color = imagecolorclosest($dst_img, $r, $g, $b); |
|
| 725 | + } |
|
| 709 | 726 | } |
| 710 | 727 | |
| 711 | 728 | imagesetpixel($dst_img, $x, $y, $color); |
| 712 | 729 | } |
| 713 | - } |
|
| 714 | - elseif ($info['bits'] == 8) |
|
| 730 | + } elseif ($info['bits'] == 8) |
|
| 715 | 731 | { |
| 716 | 732 | $x = 0; |
| 717 | - for ($j = 0; $j < $scan_line_size; $x++) |
|
| 718 | - imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]); |
|
| 719 | - } |
|
| 720 | - elseif ($info['bits'] == 4) |
|
| 733 | + for ($j = 0; $j < $scan_line_size; $x++) { |
|
| 734 | + imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]); |
|
| 735 | + } |
|
| 736 | + } elseif ($info['bits'] == 4) |
|
| 721 | 737 | { |
| 722 | 738 | $x = 0; |
| 723 | 739 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -725,11 +741,11 @@ discard block |
||
| 725 | 741 | $byte = ord($scan_line{$j++}); |
| 726 | 742 | |
| 727 | 743 | imagesetpixel($dst_img, $x, $y, $palette[(int) ($byte / 16)]); |
| 728 | - if (++$x < $info['width']) |
|
| 729 | - imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]); |
|
| 744 | + if (++$x < $info['width']) { |
|
| 745 | + imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]); |
|
| 746 | + } |
|
| 730 | 747 | } |
| 731 | - } |
|
| 732 | - elseif ($info['bits'] == 1) |
|
| 748 | + } elseif ($info['bits'] == 1) |
|
| 733 | 749 | { |
| 734 | 750 | $x = 0; |
| 735 | 751 | for ($j = 0; $j < $scan_line_size; $x++) |
@@ -738,7 +754,9 @@ discard block |
||
| 738 | 754 | |
| 739 | 755 | imagesetpixel($dst_img, $x, $y, $palette[(($byte) & 128) != 0]); |
| 740 | 756 | for ($shift = 1; $shift < 8; $shift++) { |
| 741 | - if (++$x < $info['width']) imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]); |
|
| 757 | + if (++$x < $info['width']) { |
|
| 758 | + imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]); |
|
| 759 | + } |
|
| 742 | 760 | } |
| 743 | 761 | } |
| 744 | 762 | } |
@@ -762,15 +780,18 @@ discard block |
||
| 762 | 780 | */ |
| 763 | 781 | function gif_outputAsPng($gif, $lpszFileName, $background_color = -1) |
| 764 | 782 | { |
| 765 | - if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '') |
|
| 766 | - return false; |
|
| 783 | + if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '') { |
|
| 784 | + return false; |
|
| 785 | + } |
|
| 767 | 786 | |
| 768 | 787 | $fd = $gif->get_png_data($background_color); |
| 769 | - if (strlen($fd) <= 0) |
|
| 770 | - return false; |
|
| 788 | + if (strlen($fd) <= 0) { |
|
| 789 | + return false; |
|
| 790 | + } |
|
| 771 | 791 | |
| 772 | - if (!($fh = @fopen($lpszFileName, 'wb'))) |
|
| 773 | - return false; |
|
| 792 | + if (!($fh = @fopen($lpszFileName, 'wb'))) { |
|
| 793 | + return false; |
|
| 794 | + } |
|
| 774 | 795 | |
| 775 | 796 | @fwrite($fh, $fd, strlen($fd)); |
| 776 | 797 | @fflush($fh); |
@@ -797,8 +818,9 @@ discard block |
||
| 797 | 818 | // What type are we going to be doing? |
| 798 | 819 | $imageType = $modSettings['visual_verification_type']; |
| 799 | 820 | // Special case to allow the admin center to show samples. |
| 800 | - if ($user_info['is_admin'] && isset($_GET['type'])) |
|
| 801 | - $imageType = (int) $_GET['type']; |
|
| 821 | + if ($user_info['is_admin'] && isset($_GET['type'])) { |
|
| 822 | + $imageType = (int) $_GET['type']; |
|
| 823 | + } |
|
| 802 | 824 | |
| 803 | 825 | // Some quick references for what we do. |
| 804 | 826 | // Do we show no, low or high noise? |
@@ -832,25 +854,28 @@ discard block |
||
| 832 | 854 | $character_spacing = 1; |
| 833 | 855 | |
| 834 | 856 | // What color is the background - generally white unless we're on "hard". |
| 835 | - if ($simpleBGColor) |
|
| 836 | - $background_color = array(255, 255, 255); |
|
| 837 | - else |
|
| 838 | - $background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243); |
|
| 857 | + if ($simpleBGColor) { |
|
| 858 | + $background_color = array(255, 255, 255); |
|
| 859 | + } else { |
|
| 860 | + $background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243); |
|
| 861 | + } |
|
| 839 | 862 | |
| 840 | 863 | // The color of the characters shown (red, green, blue). |
| 841 | - if ($simpleFGColor) |
|
| 842 | - $foreground_color = array(0, 0, 0); |
|
| 843 | - else |
|
| 864 | + if ($simpleFGColor) { |
|
| 865 | + $foreground_color = array(0, 0, 0); |
|
| 866 | + } else |
|
| 844 | 867 | { |
| 845 | 868 | $foreground_color = array(64, 101, 136); |
| 846 | 869 | |
| 847 | 870 | // Has the theme author requested a custom color? |
| 848 | - if (isset($settings['verification_foreground'])) |
|
| 849 | - $foreground_color = $settings['verification_foreground']; |
|
| 871 | + if (isset($settings['verification_foreground'])) { |
|
| 872 | + $foreground_color = $settings['verification_foreground']; |
|
| 873 | + } |
|
| 850 | 874 | } |
| 851 | 875 | |
| 852 | - if (!is_dir($settings['default_theme_dir'] . '/fonts')) |
|
| 853 | - return false; |
|
| 876 | + if (!is_dir($settings['default_theme_dir'] . '/fonts')) { |
|
| 877 | + return false; |
|
| 878 | + } |
|
| 854 | 879 | |
| 855 | 880 | // Get a list of the available fonts. |
| 856 | 881 | $font_dir = dir($settings['default_theme_dir'] . '/fonts'); |
@@ -861,25 +886,28 @@ discard block |
||
| 861 | 886 | { |
| 862 | 887 | if (preg_match('~^(.+)\.gdf$~', $entry, $matches) === 1) |
| 863 | 888 | { |
| 864 | - if ($endian ^ (strpos($entry, '_end.gdf') === false)) |
|
| 865 | - $font_list[] = $entry; |
|
| 889 | + if ($endian ^ (strpos($entry, '_end.gdf') === false)) { |
|
| 890 | + $font_list[] = $entry; |
|
| 891 | + } |
|
| 892 | + } elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1) { |
|
| 893 | + $ttfont_list[] = $entry; |
|
| 866 | 894 | } |
| 867 | - elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1) |
|
| 868 | - $ttfont_list[] = $entry; |
|
| 869 | 895 | } |
| 870 | 896 | |
| 871 | - if (empty($font_list)) |
|
| 872 | - return false; |
|
| 897 | + if (empty($font_list)) { |
|
| 898 | + return false; |
|
| 899 | + } |
|
| 873 | 900 | |
| 874 | 901 | // For non-hard things don't even change fonts. |
| 875 | 902 | if (!$varyFonts) |
| 876 | 903 | { |
| 877 | 904 | $font_list = array($font_list[0]); |
| 878 | 905 | // Try use Screenge if we can - it looks good! |
| 879 | - if (in_array('AnonymousPro.ttf', $ttfont_list)) |
|
| 880 | - $ttfont_list = array('AnonymousPro.ttf'); |
|
| 881 | - else |
|
| 882 | - $ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]); |
|
| 906 | + if (in_array('AnonymousPro.ttf', $ttfont_list)) { |
|
| 907 | + $ttfont_list = array('AnonymousPro.ttf'); |
|
| 908 | + } else { |
|
| 909 | + $ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]); |
|
| 910 | + } |
|
| 883 | 911 | |
| 884 | 912 | } |
| 885 | 913 | |
@@ -897,14 +925,16 @@ discard block |
||
| 897 | 925 | } |
| 898 | 926 | |
| 899 | 927 | // Load all fonts and determine the maximum font height. |
| 900 | - foreach ($loaded_fonts as $font_index => $dummy) |
|
| 901 | - $loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]); |
|
| 928 | + foreach ($loaded_fonts as $font_index => $dummy) { |
|
| 929 | + $loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]); |
|
| 930 | + } |
|
| 902 | 931 | |
| 903 | 932 | // Determine the dimensions of each character. |
| 904 | - if ($imageType == 4 || $imageType == 5) |
|
| 905 | - $extra = 80; |
|
| 906 | - else |
|
| 907 | - $extra = 45; |
|
| 933 | + if ($imageType == 4 || $imageType == 5) { |
|
| 934 | + $extra = 80; |
|
| 935 | + } else { |
|
| 936 | + $extra = 45; |
|
| 937 | + } |
|
| 908 | 938 | |
| 909 | 939 | $total_width = $character_spacing * strlen($code) + $extra; |
| 910 | 940 | $max_height = 0; |
@@ -925,13 +955,15 @@ discard block |
||
| 925 | 955 | imagefilledrectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $bg_color); |
| 926 | 956 | |
| 927 | 957 | // Randomize the foreground color a little. |
| 928 | - for ($i = 0; $i < 3; $i++) |
|
| 929 | - $foreground_color[$i] = mt_rand(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255)); |
|
| 958 | + for ($i = 0; $i < 3; $i++) { |
|
| 959 | + $foreground_color[$i] = mt_rand(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255)); |
|
| 960 | + } |
|
| 930 | 961 | $fg_color = imagecolorallocate($code_image, $foreground_color[0], $foreground_color[1], $foreground_color[2]); |
| 931 | 962 | |
| 932 | 963 | // Color for the dots. |
| 933 | - for ($i = 0; $i < 3; $i++) |
|
| 934 | - $dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? mt_rand(0, max($foreground_color[$i] - 20, 0)) : mt_rand(min($foreground_color[$i] + 20, 255), 255); |
|
| 964 | + for ($i = 0; $i < 3; $i++) { |
|
| 965 | + $dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? mt_rand(0, max($foreground_color[$i] - 20, 0)) : mt_rand(min($foreground_color[$i] + 20, 255), 255); |
|
| 966 | + } |
|
| 935 | 967 | $randomness_color = imagecolorallocate($code_image, $dotbgcolor[0], $dotbgcolor[1], $dotbgcolor[2]); |
| 936 | 968 | |
| 937 | 969 | // Some squares/rectanges for new extreme level |
@@ -957,10 +989,11 @@ discard block |
||
| 957 | 989 | $can_do_ttf = function_exists('imagettftext'); |
| 958 | 990 | |
| 959 | 991 | // How much rotation will we give? |
| 960 | - if ($rotationType == 'none') |
|
| 961 | - $angle = 0; |
|
| 962 | - else |
|
| 963 | - $angle = mt_rand(-100, 100) / ($rotationType == 'high' ? 6 : 10); |
|
| 992 | + if ($rotationType == 'none') { |
|
| 993 | + $angle = 0; |
|
| 994 | + } else { |
|
| 995 | + $angle = mt_rand(-100, 100) / ($rotationType == 'high' ? 6 : 10); |
|
| 996 | + } |
|
| 964 | 997 | |
| 965 | 998 | // What color shall we do it? |
| 966 | 999 | if ($fontColorType == 'cyclic') |
@@ -974,51 +1007,56 @@ discard block |
||
| 974 | 1007 | array(0, 0, 0), |
| 975 | 1008 | array(143, 39, 31), |
| 976 | 1009 | ); |
| 977 | - if (!isset($last_index)) |
|
| 978 | - $last_index = -1; |
|
| 1010 | + if (!isset($last_index)) { |
|
| 1011 | + $last_index = -1; |
|
| 1012 | + } |
|
| 979 | 1013 | $new_index = $last_index; |
| 980 | - while ($last_index == $new_index) |
|
| 981 | - $new_index = mt_rand(0, count($colors) - 1); |
|
| 1014 | + while ($last_index == $new_index) { |
|
| 1015 | + $new_index = mt_rand(0, count($colors) - 1); |
|
| 1016 | + } |
|
| 982 | 1017 | $char_fg_color = $colors[$new_index]; |
| 983 | 1018 | $last_index = $new_index; |
| 1019 | + } elseif ($fontColorType == 'random') { |
|
| 1020 | + $char_fg_color = array(mt_rand(max($foreground_color[0] - 2, 0), $foreground_color[0]), mt_rand(max($foreground_color[1] - 2, 0), $foreground_color[1]), mt_rand(max($foreground_color[2] - 2, 0), $foreground_color[2])); |
|
| 1021 | + } else { |
|
| 1022 | + $char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]); |
|
| 984 | 1023 | } |
| 985 | - elseif ($fontColorType == 'random') |
|
| 986 | - $char_fg_color = array(mt_rand(max($foreground_color[0] - 2, 0), $foreground_color[0]), mt_rand(max($foreground_color[1] - 2, 0), $foreground_color[1]), mt_rand(max($foreground_color[2] - 2, 0), $foreground_color[2])); |
|
| 987 | - else |
|
| 988 | - $char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]); |
|
| 989 | 1024 | |
| 990 | 1025 | if (!empty($can_do_ttf)) |
| 991 | 1026 | { |
| 992 | 1027 | // GD2 handles font size differently. |
| 993 | - if ($fontSizeRandom) |
|
| 994 | - $font_size = $gd2 ? mt_rand(17, 19) : mt_rand(18, 25); |
|
| 995 | - else |
|
| 996 | - $font_size = $gd2 ? 18 : 24; |
|
| 1028 | + if ($fontSizeRandom) { |
|
| 1029 | + $font_size = $gd2 ? mt_rand(17, 19) : mt_rand(18, 25); |
|
| 1030 | + } else { |
|
| 1031 | + $font_size = $gd2 ? 18 : 24; |
|
| 1032 | + } |
|
| 997 | 1033 | |
| 998 | 1034 | // Work out the sizes - also fix the character width cause TTF not quite so wide! |
| 999 | 1035 | $font_x = $fontHorSpace == 'minus' && $cur_x > 0 ? $cur_x - 3 : $cur_x + 5; |
| 1000 | 1036 | $font_y = $max_height - ($fontVerPos == 'vrandom' ? mt_rand(2, 8) : ($fontVerPos == 'random' ? mt_rand(3, 5) : 5)); |
| 1001 | 1037 | |
| 1002 | 1038 | // What font face? |
| 1003 | - if (!empty($ttfont_list)) |
|
| 1004 | - $fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[mt_rand(0, count($ttfont_list) - 1)]; |
|
| 1039 | + if (!empty($ttfont_list)) { |
|
| 1040 | + $fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[mt_rand(0, count($ttfont_list) - 1)]; |
|
| 1041 | + } |
|
| 1005 | 1042 | |
| 1006 | 1043 | // What color are we to do it in? |
| 1007 | 1044 | $is_reverse = $showReverseChars ? mt_rand(0, 1) : false; |
| 1008 | 1045 | $char_color = function_exists('imagecolorallocatealpha') && $fontTrans ? imagecolorallocatealpha($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2], 50) : imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]); |
| 1009 | 1046 | |
| 1010 | 1047 | $fontcord = @imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $char_color, $fontface, $character['id']); |
| 1011 | - if (empty($fontcord)) |
|
| 1012 | - $can_do_ttf = false; |
|
| 1013 | - elseif ($is_reverse) |
|
| 1048 | + if (empty($fontcord)) { |
|
| 1049 | + $can_do_ttf = false; |
|
| 1050 | + } elseif ($is_reverse) |
|
| 1014 | 1051 | { |
| 1015 | 1052 | imagefilledpolygon($code_image, $fontcord, 4, $fg_color); |
| 1016 | 1053 | // Put the character back! |
| 1017 | 1054 | imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $randomness_color, $fontface, $character['id']); |
| 1018 | 1055 | } |
| 1019 | 1056 | |
| 1020 | - if ($can_do_ttf) |
|
| 1021 | - $cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3); |
|
| 1057 | + if ($can_do_ttf) { |
|
| 1058 | + $cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3); |
|
| 1059 | + } |
|
| 1022 | 1060 | } |
| 1023 | 1061 | |
| 1024 | 1062 | if (!$can_do_ttf) |
@@ -1037,8 +1075,9 @@ discard block |
||
| 1037 | 1075 | } |
| 1038 | 1076 | |
| 1039 | 1077 | // Sorry, no rotation available. |
| 1040 | - else |
|
| 1041 | - imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2])); |
|
| 1078 | + else { |
|
| 1079 | + imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2])); |
|
| 1080 | + } |
|
| 1042 | 1081 | $cur_x += $character['width'] + $character_spacing; |
| 1043 | 1082 | } |
| 1044 | 1083 | } |
@@ -1051,17 +1090,22 @@ discard block |
||
| 1051 | 1090 | } |
| 1052 | 1091 | |
| 1053 | 1092 | // Make the background color transparent on the hard image. |
| 1054 | - if (!$simpleBGColor) |
|
| 1055 | - imagecolortransparent($code_image, $bg_color); |
|
| 1056 | - if ($hasBorder) |
|
| 1057 | - imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color); |
|
| 1093 | + if (!$simpleBGColor) { |
|
| 1094 | + imagecolortransparent($code_image, $bg_color); |
|
| 1095 | + } |
|
| 1096 | + if ($hasBorder) { |
|
| 1097 | + imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color); |
|
| 1098 | + } |
|
| 1058 | 1099 | |
| 1059 | 1100 | // Add some noise to the background? |
| 1060 | 1101 | if ($noiseType != 'none') |
| 1061 | 1102 | { |
| 1062 | - for ($i = mt_rand(0, 2); $i < $max_height; $i += mt_rand(1, 2)) |
|
| 1063 | - for ($j = mt_rand(0, 10); $j < $total_width; $j += mt_rand(1, 10)) |
|
| 1064 | - imagesetpixel($code_image, $j, $i, mt_rand(0, 1) ? $fg_color : $randomness_color); |
|
| 1103 | + for ($i = mt_rand(0, 2); $i < $max_height; $i += mt_rand(1, 2)) { |
|
| 1104 | + for ($j = mt_rand(0, 10); |
|
| 1105 | + } |
|
| 1106 | + $j < $total_width; $j += mt_rand(1, 10)) { |
|
| 1107 | + imagesetpixel($code_image, $j, $i, mt_rand(0, 1) ? $fg_color : $randomness_color); |
|
| 1108 | + } |
|
| 1065 | 1109 | |
| 1066 | 1110 | // Put in some lines too? |
| 1067 | 1111 | if ($noiseType != 'extreme') |
@@ -1074,8 +1118,7 @@ discard block |
||
| 1074 | 1118 | $x1 = mt_rand(0, $total_width); |
| 1075 | 1119 | $x2 = mt_rand(0, $total_width); |
| 1076 | 1120 | $y1 = 0; $y2 = $max_height; |
| 1077 | - } |
|
| 1078 | - else |
|
| 1121 | + } else |
|
| 1079 | 1122 | { |
| 1080 | 1123 | $y1 = mt_rand(0, $max_height); |
| 1081 | 1124 | $y2 = mt_rand(0, $max_height); |
@@ -1084,8 +1127,7 @@ discard block |
||
| 1084 | 1127 | imagesetthickness($code_image, mt_rand(1, 2)); |
| 1085 | 1128 | imageline($code_image, $x1, $y1, $x2, $y2, mt_rand(0, 1) ? $fg_color : $randomness_color); |
| 1086 | 1129 | } |
| 1087 | - } |
|
| 1088 | - else |
|
| 1130 | + } else |
|
| 1089 | 1131 | { |
| 1090 | 1132 | // Put in some ellipse |
| 1091 | 1133 | $num_ellipse = $noiseType == 'extreme' ? mt_rand(6, 12) : mt_rand(2, 6); |
@@ -1105,8 +1147,7 @@ discard block |
||
| 1105 | 1147 | { |
| 1106 | 1148 | header('Content-type: image/gif'); |
| 1107 | 1149 | imagegif($code_image); |
| 1108 | - } |
|
| 1109 | - else |
|
| 1150 | + } else |
|
| 1110 | 1151 | { |
| 1111 | 1152 | header('Content-type: image/png'); |
| 1112 | 1153 | imagepng($code_image); |
@@ -1129,25 +1170,29 @@ discard block |
||
| 1129 | 1170 | { |
| 1130 | 1171 | global $settings; |
| 1131 | 1172 | |
| 1132 | - if (!is_dir($settings['default_theme_dir'] . '/fonts')) |
|
| 1133 | - return false; |
|
| 1173 | + if (!is_dir($settings['default_theme_dir'] . '/fonts')) { |
|
| 1174 | + return false; |
|
| 1175 | + } |
|
| 1134 | 1176 | |
| 1135 | 1177 | // Get a list of the available font directories. |
| 1136 | 1178 | $font_dir = dir($settings['default_theme_dir'] . '/fonts'); |
| 1137 | 1179 | $font_list = array(); |
| 1138 | - while ($entry = $font_dir->read()) |
|
| 1139 | - if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf')) |
|
| 1180 | + while ($entry = $font_dir->read()) { |
|
| 1181 | + if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf')) |
|
| 1140 | 1182 | $font_list[] = $entry; |
| 1183 | + } |
|
| 1141 | 1184 | |
| 1142 | - if (empty($font_list)) |
|
| 1143 | - return false; |
|
| 1185 | + if (empty($font_list)) { |
|
| 1186 | + return false; |
|
| 1187 | + } |
|
| 1144 | 1188 | |
| 1145 | 1189 | // Pick a random font. |
| 1146 | 1190 | $random_font = $font_list[array_rand($font_list)]; |
| 1147 | 1191 | |
| 1148 | 1192 | // Check if the given letter exists. |
| 1149 | - if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png')) |
|
| 1150 | - return false; |
|
| 1193 | + if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png')) { |
|
| 1194 | + return false; |
|
| 1195 | + } |
|
| 1151 | 1196 | |
| 1152 | 1197 | // Include it! |
| 1153 | 1198 | header('Content-type: image/png'); |
@@ -243,6 +243,7 @@ |
||
| 243 | 243 | * @param null|array The groups to remove the member(s) from. If null, the specified members are stripped from all their membergroups. |
| 244 | 244 | * @param bool $permissionCheckDone Whether we've already checked permissions prior to calling this function |
| 245 | 245 | * @param bool $ignoreProtected Whether to ignore protected groups |
| 246 | + * @param integer $groups |
|
| 246 | 247 | * @return bool Whether the operation was successful |
| 247 | 248 | */ |
| 248 | 249 | function removeMembersFromGroups($members, $groups = null, $permissionCheckDone = false, $ignoreProtected = false) |
@@ -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 | * Delete one of more membergroups. |
@@ -31,15 +32,16 @@ discard block |
||
| 31 | 32 | global $smcFunc, $modSettings, $txt; |
| 32 | 33 | |
| 33 | 34 | // Make sure it's an array. |
| 34 | - if (!is_array($groups)) |
|
| 35 | - $groups = array((int) $groups); |
|
| 36 | - else |
|
| 35 | + if (!is_array($groups)) { |
|
| 36 | + $groups = array((int) $groups); |
|
| 37 | + } else |
|
| 37 | 38 | { |
| 38 | 39 | $groups = array_unique($groups); |
| 39 | 40 | |
| 40 | 41 | // Make sure all groups are integer. |
| 41 | - foreach ($groups as $key => $value) |
|
| 42 | - $groups[$key] = (int) $value; |
|
| 42 | + foreach ($groups as $key => $value) { |
|
| 43 | + $groups[$key] = (int) $value; |
|
| 44 | + } |
|
| 43 | 45 | } |
| 44 | 46 | |
| 45 | 47 | // Some groups are protected (guests, administrators, moderators, newbies). |
@@ -56,15 +58,17 @@ discard block |
||
| 56 | 58 | 'is_protected' => 1, |
| 57 | 59 | ) |
| 58 | 60 | ); |
| 59 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 60 | - $protected_groups[] = $row['id_group']; |
|
| 61 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 62 | + $protected_groups[] = $row['id_group']; |
|
| 63 | + } |
|
| 61 | 64 | $smcFunc['db_free_result']($request); |
| 62 | 65 | } |
| 63 | 66 | |
| 64 | 67 | // Make sure they don't delete protected groups! |
| 65 | 68 | $groups = array_diff($groups, array_unique($protected_groups)); |
| 66 | - if (empty($groups)) |
|
| 67 | - return 'no_group_found'; |
|
| 69 | + if (empty($groups)) { |
|
| 70 | + return 'no_group_found'; |
|
| 71 | + } |
|
| 68 | 72 | |
| 69 | 73 | // Make sure they don't try to delete a group attached to a paid subscription. |
| 70 | 74 | $subscriptions = array(); |
@@ -74,13 +78,14 @@ discard block |
||
| 74 | 78 | ORDER BY name'); |
| 75 | 79 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 76 | 80 | { |
| 77 | - if (in_array($row['id_group'], $groups)) |
|
| 78 | - $subscriptions[] = $row['name']; |
|
| 79 | - else |
|
| 81 | + if (in_array($row['id_group'], $groups)) { |
|
| 82 | + $subscriptions[] = $row['name']; |
|
| 83 | + } else |
|
| 80 | 84 | { |
| 81 | 85 | $add_groups = explode(',', $row['add_groups']); |
| 82 | - if (count(array_intersect($add_groups, $groups)) != 0) |
|
| 83 | - $subscriptions[] = $row['name']; |
|
| 86 | + if (count(array_intersect($add_groups, $groups)) != 0) { |
|
| 87 | + $subscriptions[] = $row['name']; |
|
| 88 | + } |
|
| 84 | 89 | } |
| 85 | 90 | } |
| 86 | 91 | $smcFunc['db_free_result']($request); |
@@ -101,8 +106,9 @@ discard block |
||
| 101 | 106 | 'group_list' => $groups, |
| 102 | 107 | ) |
| 103 | 108 | ); |
| 104 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 105 | - logAction('delete_group', array('group' => $row['group_name']), 'admin'); |
|
| 109 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 110 | + logAction('delete_group', array('group' => $row['group_name']), 'admin'); |
|
| 111 | + } |
|
| 106 | 112 | $smcFunc['db_free_result']($request); |
| 107 | 113 | |
| 108 | 114 | call_integration_hook('integrate_delete_membergroups', array($groups)); |
@@ -187,12 +193,14 @@ discard block |
||
| 187 | 193 | ) |
| 188 | 194 | ); |
| 189 | 195 | $updates = array(); |
| 190 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 191 | - $updates[$row['additional_groups']][] = $row['id_member']; |
|
| 196 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 197 | + $updates[$row['additional_groups']][] = $row['id_member']; |
|
| 198 | + } |
|
| 192 | 199 | $smcFunc['db_free_result']($request); |
| 193 | 200 | |
| 194 | - foreach ($updates as $additional_groups => $memberArray) |
|
| 195 | - updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups)))); |
|
| 201 | + foreach ($updates as $additional_groups => $memberArray) { |
|
| 202 | + updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups)))); |
|
| 203 | + } |
|
| 196 | 204 | |
| 197 | 205 | // No boards can provide access to these membergroups anymore. |
| 198 | 206 | $request = $smcFunc['db_query']('', ' |
@@ -204,12 +212,13 @@ discard block |
||
| 204 | 212 | ) |
| 205 | 213 | ); |
| 206 | 214 | $updates = array(); |
| 207 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 208 | - $updates[$row['member_groups']][] = $row['id_board']; |
|
| 215 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 216 | + $updates[$row['member_groups']][] = $row['id_board']; |
|
| 217 | + } |
|
| 209 | 218 | $smcFunc['db_free_result']($request); |
| 210 | 219 | |
| 211 | - foreach ($updates as $member_groups => $boardArray) |
|
| 212 | - $smcFunc['db_query']('', ' |
|
| 220 | + foreach ($updates as $member_groups => $boardArray) { |
|
| 221 | + $smcFunc['db_query']('', ' |
|
| 213 | 222 | UPDATE {db_prefix}boards |
| 214 | 223 | SET member_groups = {string:member_groups} |
| 215 | 224 | WHERE id_board IN ({array_int:board_lists})', |
@@ -218,6 +227,7 @@ discard block |
||
| 218 | 227 | 'member_groups' => implode(',', array_diff(explode(',', $member_groups), $groups)), |
| 219 | 228 | ) |
| 220 | 229 | ); |
| 230 | + } |
|
| 221 | 231 | |
| 222 | 232 | // Recalculate the post groups, as they likely changed. |
| 223 | 233 | updateStats('postgroups'); |
@@ -225,8 +235,9 @@ discard block |
||
| 225 | 235 | // Make a note of the fact that the cache may be wrong. |
| 226 | 236 | $settings_update = array('settings_updated' => time()); |
| 227 | 237 | // Have we deleted the spider group? |
| 228 | - if (isset($modSettings['spider_group']) && in_array($modSettings['spider_group'], $groups)) |
|
| 229 | - $settings_update['spider_group'] = 0; |
|
| 238 | + if (isset($modSettings['spider_group']) && in_array($modSettings['spider_group'], $groups)) { |
|
| 239 | + $settings_update['spider_group'] = 0; |
|
| 240 | + } |
|
| 230 | 241 | |
| 231 | 242 | updateSettings($settings_update); |
| 232 | 243 | |
@@ -250,22 +261,24 @@ discard block |
||
| 250 | 261 | global $smcFunc, $modSettings, $sourcedir; |
| 251 | 262 | |
| 252 | 263 | // You're getting nowhere without this permission, unless of course you are the group's moderator. |
| 253 | - if (!$permissionCheckDone) |
|
| 254 | - isAllowedTo('manage_membergroups'); |
|
| 264 | + if (!$permissionCheckDone) { |
|
| 265 | + isAllowedTo('manage_membergroups'); |
|
| 266 | + } |
|
| 255 | 267 | |
| 256 | 268 | // Assume something will happen. |
| 257 | 269 | updateSettings(array('settings_updated' => time())); |
| 258 | 270 | |
| 259 | 271 | // Cleaning the input. |
| 260 | - if (!is_array($members)) |
|
| 261 | - $members = array((int) $members); |
|
| 262 | - else |
|
| 272 | + if (!is_array($members)) { |
|
| 273 | + $members = array((int) $members); |
|
| 274 | + } else |
|
| 263 | 275 | { |
| 264 | 276 | $members = array_unique($members); |
| 265 | 277 | |
| 266 | 278 | // Cast the members to integer. |
| 267 | - foreach ($members as $key => $value) |
|
| 268 | - $members[$key] = (int) $value; |
|
| 279 | + foreach ($members as $key => $value) { |
|
| 280 | + $members[$key] = (int) $value; |
|
| 281 | + } |
|
| 269 | 282 | } |
| 270 | 283 | |
| 271 | 284 | // Before we get started, let's check we won't leave the admin group empty! |
@@ -277,14 +290,15 @@ discard block |
||
| 277 | 290 | // Remove any admins if there are too many. |
| 278 | 291 | $non_changing_admins = array_diff(array_keys($admins), $members); |
| 279 | 292 | |
| 280 | - if (empty($non_changing_admins)) |
|
| 281 | - $members = array_diff($members, array_keys($admins)); |
|
| 293 | + if (empty($non_changing_admins)) { |
|
| 294 | + $members = array_diff($members, array_keys($admins)); |
|
| 295 | + } |
|
| 282 | 296 | } |
| 283 | 297 | |
| 284 | 298 | // Just in case. |
| 285 | - if (empty($members)) |
|
| 286 | - return false; |
|
| 287 | - elseif ($groups === null) |
|
| 299 | + if (empty($members)) { |
|
| 300 | + return false; |
|
| 301 | + } elseif ($groups === null) |
|
| 288 | 302 | { |
| 289 | 303 | // Wanna remove all groups from these members? That's easy. |
| 290 | 304 | $smcFunc['db_query']('', ' |
@@ -306,20 +320,21 @@ discard block |
||
| 306 | 320 | updateStats('postgroups', $members); |
| 307 | 321 | |
| 308 | 322 | // Log what just happened. |
| 309 | - foreach ($members as $member) |
|
| 310 | - logAction('removed_all_groups', array('member' => $member), 'admin'); |
|
| 323 | + foreach ($members as $member) { |
|
| 324 | + logAction('removed_all_groups', array('member' => $member), 'admin'); |
|
| 325 | + } |
|
| 311 | 326 | |
| 312 | 327 | return true; |
| 313 | - } |
|
| 314 | - elseif (!is_array($groups)) |
|
| 315 | - $groups = array((int) $groups); |
|
| 316 | - else |
|
| 328 | + } elseif (!is_array($groups)) { |
|
| 329 | + $groups = array((int) $groups); |
|
| 330 | + } else |
|
| 317 | 331 | { |
| 318 | 332 | $groups = array_unique($groups); |
| 319 | 333 | |
| 320 | 334 | // Make sure all groups are integer. |
| 321 | - foreach ($groups as $key => $value) |
|
| 322 | - $groups[$key] = (int) $value; |
|
| 335 | + foreach ($groups as $key => $value) { |
|
| 336 | + $groups[$key] = (int) $value; |
|
| 337 | + } |
|
| 323 | 338 | } |
| 324 | 339 | |
| 325 | 340 | // Fetch a list of groups members cannot be assigned to explicitly, and the group names of the ones we want. |
@@ -335,10 +350,11 @@ discard block |
||
| 335 | 350 | $group_names = array(); |
| 336 | 351 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 337 | 352 | { |
| 338 | - if ($row['min_posts'] != -1) |
|
| 339 | - $implicitGroups[] = $row['id_group']; |
|
| 340 | - else |
|
| 341 | - $group_names[$row['id_group']] = $row['group_name']; |
|
| 353 | + if ($row['min_posts'] != -1) { |
|
| 354 | + $implicitGroups[] = $row['id_group']; |
|
| 355 | + } else { |
|
| 356 | + $group_names[$row['id_group']] = $row['group_name']; |
|
| 357 | + } |
|
| 342 | 358 | } |
| 343 | 359 | $smcFunc['db_free_result']($request); |
| 344 | 360 | |
@@ -357,8 +373,9 @@ discard block |
||
| 357 | 373 | ) |
| 358 | 374 | ); |
| 359 | 375 | $protected_groups = array(1); |
| 360 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 361 | - $protected_groups[] = $row['id_group']; |
|
| 376 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 377 | + $protected_groups[] = $row['id_group']; |
|
| 378 | + } |
|
| 362 | 379 | $smcFunc['db_free_result']($request); |
| 363 | 380 | |
| 364 | 381 | // If you're not an admin yourself, you can't touch protected groups! |
@@ -366,8 +383,9 @@ discard block |
||
| 366 | 383 | } |
| 367 | 384 | |
| 368 | 385 | // Only continue if there are still groups and members left. |
| 369 | - if (empty($groups) || empty($members)) |
|
| 370 | - return false; |
|
| 386 | + if (empty($groups) || empty($members)) { |
|
| 387 | + return false; |
|
| 388 | + } |
|
| 371 | 389 | |
| 372 | 390 | // First, reset those who have this as their primary group - this is the easy one. |
| 373 | 391 | $log_inserts = array(); |
@@ -381,8 +399,9 @@ discard block |
||
| 381 | 399 | 'member_list' => $members, |
| 382 | 400 | ) |
| 383 | 401 | ); |
| 384 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 385 | - $log_inserts[] = array('group' => $group_names[$row['id_group']], 'member' => $row['id_member']); |
|
| 402 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 403 | + $log_inserts[] = array('group' => $group_names[$row['id_group']], 'member' => $row['id_member']); |
|
| 404 | + } |
|
| 386 | 405 | $smcFunc['db_free_result']($request); |
| 387 | 406 | |
| 388 | 407 | $smcFunc['db_query']('', ' |
@@ -414,16 +433,17 @@ discard block |
||
| 414 | 433 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 415 | 434 | { |
| 416 | 435 | // What log entries must we make for this one, eh? |
| 417 | - foreach (explode(',', $row['additional_groups']) as $group) |
|
| 418 | - if (in_array($group, $groups)) |
|
| 436 | + foreach (explode(',', $row['additional_groups']) as $group) { |
|
| 437 | + if (in_array($group, $groups)) |
|
| 419 | 438 | $log_inserts[] = array('group' => $group_names[$group], 'member' => $row['id_member']); |
| 439 | + } |
|
| 420 | 440 | |
| 421 | 441 | $updates[$row['additional_groups']][] = $row['id_member']; |
| 422 | 442 | } |
| 423 | 443 | $smcFunc['db_free_result']($request); |
| 424 | 444 | |
| 425 | - foreach ($updates as $additional_groups => $memberArray) |
|
| 426 | - $smcFunc['db_query']('', ' |
|
| 445 | + foreach ($updates as $additional_groups => $memberArray) { |
|
| 446 | + $smcFunc['db_query']('', ' |
|
| 427 | 447 | UPDATE {db_prefix}members |
| 428 | 448 | SET additional_groups = {string:additional_groups} |
| 429 | 449 | WHERE id_member IN ({array_int:member_list})', |
@@ -432,6 +452,7 @@ discard block |
||
| 432 | 452 | 'additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups)), |
| 433 | 453 | ) |
| 434 | 454 | ); |
| 455 | + } |
|
| 435 | 456 | |
| 436 | 457 | // Their post groups may have changed now... |
| 437 | 458 | updateStats('postgroups', $members); |
@@ -440,8 +461,9 @@ discard block |
||
| 440 | 461 | if (!empty($log_inserts) && !empty($modSettings['modlog_enabled'])) |
| 441 | 462 | { |
| 442 | 463 | require_once($sourcedir . '/Logging.php'); |
| 443 | - foreach ($log_inserts as $extra) |
|
| 444 | - logAction('removed_from_group', $extra, 'admin'); |
|
| 464 | + foreach ($log_inserts as $extra) { |
|
| 465 | + logAction('removed_from_group', $extra, 'admin'); |
|
| 466 | + } |
|
| 445 | 467 | } |
| 446 | 468 | |
| 447 | 469 | // Mission successful. |
@@ -477,21 +499,23 @@ discard block |
||
| 477 | 499 | global $smcFunc, $sourcedir; |
| 478 | 500 | |
| 479 | 501 | // Show your licence, but only if it hasn't been done yet. |
| 480 | - if (!$permissionCheckDone) |
|
| 481 | - isAllowedTo('manage_membergroups'); |
|
| 502 | + if (!$permissionCheckDone) { |
|
| 503 | + isAllowedTo('manage_membergroups'); |
|
| 504 | + } |
|
| 482 | 505 | |
| 483 | 506 | // Make sure we don't keep old stuff cached. |
| 484 | 507 | updateSettings(array('settings_updated' => time())); |
| 485 | 508 | |
| 486 | - if (!is_array($members)) |
|
| 487 | - $members = array((int) $members); |
|
| 488 | - else |
|
| 509 | + if (!is_array($members)) { |
|
| 510 | + $members = array((int) $members); |
|
| 511 | + } else |
|
| 489 | 512 | { |
| 490 | 513 | $members = array_unique($members); |
| 491 | 514 | |
| 492 | 515 | // Make sure all members are integer. |
| 493 | - foreach ($members as $key => $value) |
|
| 494 | - $members[$key] = (int) $value; |
|
| 516 | + foreach ($members as $key => $value) { |
|
| 517 | + $members[$key] = (int) $value; |
|
| 518 | + } |
|
| 495 | 519 | } |
| 496 | 520 | $group = (int) $group; |
| 497 | 521 | |
@@ -508,20 +532,23 @@ discard block |
||
| 508 | 532 | $group_names = array(); |
| 509 | 533 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 510 | 534 | { |
| 511 | - if ($row['min_posts'] != -1) |
|
| 512 | - $implicitGroups[] = $row['id_group']; |
|
| 513 | - else |
|
| 514 | - $group_names[$row['id_group']] = $row['group_name']; |
|
| 535 | + if ($row['min_posts'] != -1) { |
|
| 536 | + $implicitGroups[] = $row['id_group']; |
|
| 537 | + } else { |
|
| 538 | + $group_names[$row['id_group']] = $row['group_name']; |
|
| 539 | + } |
|
| 515 | 540 | } |
| 516 | 541 | $smcFunc['db_free_result']($request); |
| 517 | 542 | |
| 518 | 543 | // Sorry, you can't join an implicit group. |
| 519 | - if (in_array($group, $implicitGroups) || empty($members)) |
|
| 520 | - return false; |
|
| 544 | + if (in_array($group, $implicitGroups) || empty($members)) { |
|
| 545 | + return false; |
|
| 546 | + } |
|
| 521 | 547 | |
| 522 | 548 | // Only admins can add admins... |
| 523 | - if (!allowedTo('admin_forum') && $group == 1) |
|
| 524 | - return false; |
|
| 549 | + if (!allowedTo('admin_forum') && $group == 1) { |
|
| 550 | + return false; |
|
| 551 | + } |
|
| 525 | 552 | // ... and assign protected groups! |
| 526 | 553 | elseif (!allowedTo('admin_forum') && !$ignoreProtected) |
| 527 | 554 | { |
@@ -539,13 +566,14 @@ discard block |
||
| 539 | 566 | $smcFunc['db_free_result']($request); |
| 540 | 567 | |
| 541 | 568 | // Is it protected? |
| 542 | - if ($is_protected == 1) |
|
| 543 | - return false; |
|
| 569 | + if ($is_protected == 1) { |
|
| 570 | + return false; |
|
| 571 | + } |
|
| 544 | 572 | } |
| 545 | 573 | |
| 546 | 574 | // Do the actual updates. |
| 547 | - if ($type == 'only_additional') |
|
| 548 | - $smcFunc['db_query']('', ' |
|
| 575 | + if ($type == 'only_additional') { |
|
| 576 | + $smcFunc['db_query']('', ' |
|
| 549 | 577 | UPDATE {db_prefix}members |
| 550 | 578 | SET additional_groups = CASE WHEN additional_groups = {string:blank_string} THEN {string:id_group_string} ELSE CONCAT(additional_groups, {string:id_group_string_extend}) END |
| 551 | 579 | WHERE id_member IN ({array_int:member_list}) |
@@ -559,8 +587,8 @@ discard block |
||
| 559 | 587 | 'blank_string' => '', |
| 560 | 588 | ) |
| 561 | 589 | ); |
| 562 | - elseif ($type == 'only_primary' || $type == 'force_primary') |
|
| 563 | - $smcFunc['db_query']('', ' |
|
| 590 | + } elseif ($type == 'only_primary' || $type == 'force_primary') { |
|
| 591 | + $smcFunc['db_query']('', ' |
|
| 564 | 592 | UPDATE {db_prefix}members |
| 565 | 593 | SET id_group = {int:id_group} |
| 566 | 594 | WHERE id_member IN ({array_int:member_list})' . ($type == 'force_primary' ? '' : ' |
@@ -572,8 +600,8 @@ discard block |
||
| 572 | 600 | 'regular_group' => 0, |
| 573 | 601 | ) |
| 574 | 602 | ); |
| 575 | - elseif ($type == 'auto') |
|
| 576 | - $smcFunc['db_query']('', ' |
|
| 603 | + } elseif ($type == 'auto') { |
|
| 604 | + $smcFunc['db_query']('', ' |
|
| 577 | 605 | UPDATE {db_prefix}members |
| 578 | 606 | SET |
| 579 | 607 | id_group = CASE WHEN id_group = {int:regular_group} THEN {int:id_group} ELSE id_group END, |
@@ -592,9 +620,11 @@ discard block |
||
| 592 | 620 | 'id_group_string_extend' => ',' . $group, |
| 593 | 621 | ) |
| 594 | 622 | ); |
| 623 | + } |
|
| 595 | 624 | // Ack!!? What happened? |
| 596 | - else |
|
| 597 | - trigger_error('addMembersToGroup(): Unknown type \'' . $type . '\'', E_USER_WARNING); |
|
| 625 | + else { |
|
| 626 | + trigger_error('addMembersToGroup(): Unknown type \'' . $type . '\'', E_USER_WARNING); |
|
| 627 | + } |
|
| 598 | 628 | |
| 599 | 629 | call_integration_hook('integrate_add_members_to_group', array($members, $group, &$group_names)); |
| 600 | 630 | |
@@ -603,8 +633,9 @@ discard block |
||
| 603 | 633 | |
| 604 | 634 | // Log the data. |
| 605 | 635 | require_once($sourcedir . '/Logging.php'); |
| 606 | - foreach ($members as $member) |
|
| 607 | - logAction('added_to_group', array('group' => $group_names[$group], 'member' => $member), 'admin'); |
|
| 636 | + foreach ($members as $member) { |
|
| 637 | + logAction('added_to_group', array('group' => $group_names[$group], 'member' => $member), 'admin'); |
|
| 638 | + } |
|
| 608 | 639 | |
| 609 | 640 | return true; |
| 610 | 641 | } |
@@ -632,8 +663,9 @@ discard block |
||
| 632 | 663 | ) |
| 633 | 664 | ); |
| 634 | 665 | $members = array(); |
| 635 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 636 | - $members[$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 666 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 667 | + $members[$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 668 | + } |
|
| 637 | 669 | $smcFunc['db_free_result']($request); |
| 638 | 670 | |
| 639 | 671 | // If there are more than $limit members, add a 'more' link. |
@@ -641,10 +673,10 @@ discard block |
||
| 641 | 673 | { |
| 642 | 674 | array_pop($members); |
| 643 | 675 | return true; |
| 676 | + } else { |
|
| 677 | + return false; |
|
| 678 | + } |
|
| 644 | 679 | } |
| 645 | - else |
|
| 646 | - return false; |
|
| 647 | -} |
|
| 648 | 680 | |
| 649 | 681 | /** |
| 650 | 682 | * Retrieve a list of (visible) membergroups used by the cache. |
@@ -669,8 +701,9 @@ discard block |
||
| 669 | 701 | ) |
| 670 | 702 | ); |
| 671 | 703 | $groupCache = array(); |
| 672 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 673 | - $groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>'; |
|
| 704 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 705 | + $groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>'; |
|
| 706 | + } |
|
| 674 | 707 | $smcFunc['db_free_result']($request); |
| 675 | 708 | |
| 676 | 709 | return array( |
@@ -718,8 +751,9 @@ discard block |
||
| 718 | 751 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 719 | 752 | { |
| 720 | 753 | // We only list the groups they can see. |
| 721 | - if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) |
|
| 722 | - continue; |
|
| 754 | + if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) { |
|
| 755 | + continue; |
|
| 756 | + } |
|
| 723 | 757 | |
| 724 | 758 | $row['icons'] = explode('#', $row['icons']); |
| 725 | 759 | |
@@ -754,12 +788,11 @@ discard block |
||
| 754 | 788 | 'group_list' => $group_ids, |
| 755 | 789 | ) |
| 756 | 790 | ); |
| 757 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
| 758 | - $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
| 791 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
| 792 | + $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
| 793 | + } |
|
| 759 | 794 | $smcFunc['db_free_result']($query); |
| 760 | - } |
|
| 761 | - |
|
| 762 | - else |
|
| 795 | + } else |
|
| 763 | 796 | { |
| 764 | 797 | $query = $smcFunc['db_query']('', ' |
| 765 | 798 | SELECT id_group, COUNT(*) AS num_members |
@@ -770,8 +803,9 @@ discard block |
||
| 770 | 803 | 'group_list' => $group_ids, |
| 771 | 804 | ) |
| 772 | 805 | ); |
| 773 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
| 774 | - $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
| 806 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
| 807 | + $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
| 808 | + } |
|
| 775 | 809 | $smcFunc['db_free_result']($query); |
| 776 | 810 | |
| 777 | 811 | // Only do additional groups if we can moderate... |
@@ -790,8 +824,9 @@ discard block |
||
| 790 | 824 | 'blank_string' => '', |
| 791 | 825 | ) |
| 792 | 826 | ); |
| 793 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
| 794 | - $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
| 827 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
| 828 | + $groups[$row['id_group']]['num_members'] += $row['num_members']; |
|
| 829 | + } |
|
| 795 | 830 | $smcFunc['db_free_result']($query); |
| 796 | 831 | } |
| 797 | 832 | } |
@@ -805,8 +840,9 @@ discard block |
||
| 805 | 840 | 'group_list' => $group_ids, |
| 806 | 841 | ) |
| 807 | 842 | ); |
| 808 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
| 809 | - $groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 843 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
| 844 | + $groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 845 | + } |
|
| 810 | 846 | $smcFunc['db_free_result']($query); |
| 811 | 847 | } |
| 812 | 848 | |
@@ -815,8 +851,9 @@ discard block |
||
| 815 | 851 | { |
| 816 | 852 | $sort_ascending = strpos($sort, 'DESC') === false; |
| 817 | 853 | |
| 818 | - foreach ($groups as $group) |
|
| 819 | - $sort_array[] = $group['id_group'] != 3 ? (int) $group['num_members'] : -1; |
|
| 854 | + foreach ($groups as $group) { |
|
| 855 | + $sort_array[] = $group['id_group'] != 3 ? (int) $group['num_members'] : -1; |
|
| 856 | + } |
|
| 820 | 857 | |
| 821 | 858 | array_multisort($sort_array, $sort_ascending ? SORT_ASC : SORT_DESC, SORT_REGULAR, $groups); |
| 822 | 859 | } |
@@ -286,7 +286,7 @@ |
||
| 286 | 286 | /** |
| 287 | 287 | * Delete a menu. |
| 288 | 288 | * @param string $menu_id The ID of the menu to destroy or 'last' for the most recent one |
| 289 | - * @return bool|void False if the menu doesn't exist, nothing otherwise |
|
| 289 | + * @return false|null False if the menu doesn't exist, nothing otherwise |
|
| 290 | 290 | */ |
| 291 | 291 | function destroyMenu($menu_id = 'last') |
| 292 | 292 | { |
@@ -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 | * Create a menu. |
@@ -64,22 +65,26 @@ discard block |
||
| 64 | 65 | $menu_context['current_action'] = isset($menuOptions['action']) ? $menuOptions['action'] : $context['current_action']; |
| 65 | 66 | |
| 66 | 67 | // Allow extend *any* menu with a single hook |
| 67 | - if (!empty($menu_context['current_action'])) |
|
| 68 | - call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData)); |
|
| 68 | + if (!empty($menu_context['current_action'])) { |
|
| 69 | + call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData)); |
|
| 70 | + } |
|
| 69 | 71 | |
| 70 | 72 | // What is the current area selected? |
| 71 | - if (isset($menuOptions['current_area']) || isset($_GET['area'])) |
|
| 72 | - $menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area']; |
|
| 73 | + if (isset($menuOptions['current_area']) || isset($_GET['area'])) { |
|
| 74 | + $menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area']; |
|
| 75 | + } |
|
| 73 | 76 | |
| 74 | 77 | // Build a list of additional parameters that should go in the URL. |
| 75 | 78 | $menu_context['extra_parameters'] = ''; |
| 76 | - if (!empty($menuOptions['extra_url_parameters'])) |
|
| 77 | - foreach ($menuOptions['extra_url_parameters'] as $key => $value) |
|
| 79 | + if (!empty($menuOptions['extra_url_parameters'])) { |
|
| 80 | + foreach ($menuOptions['extra_url_parameters'] as $key => $value) |
|
| 78 | 81 | $menu_context['extra_parameters'] .= ';' . $key . '=' . $value; |
| 82 | + } |
|
| 79 | 83 | |
| 80 | 84 | // Only include the session ID in the URL if it's strictly necessary. |
| 81 | - if (empty($menuOptions['disable_url_session_check'])) |
|
| 82 | - $menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id']; |
|
| 85 | + if (empty($menuOptions['disable_url_session_check'])) { |
|
| 86 | + $menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id']; |
|
| 87 | + } |
|
| 83 | 88 | |
| 84 | 89 | $include_data = array(); |
| 85 | 90 | |
@@ -87,8 +92,9 @@ discard block |
||
| 87 | 92 | foreach ($menuData as $section_id => $section) |
| 88 | 93 | { |
| 89 | 94 | // Is this enabled - or has as permission check - which fails? |
| 90 | - if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission']))) |
|
| 91 | - continue; |
|
| 95 | + if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission']))) { |
|
| 96 | + continue; |
|
| 97 | + } |
|
| 92 | 98 | |
| 93 | 99 | // Now we cycle through the sections to pick the right area. |
| 94 | 100 | foreach ($section['areas'] as $area_id => $area) |
@@ -110,41 +116,45 @@ discard block |
||
| 110 | 116 | if (empty($area['hidden'])) |
| 111 | 117 | { |
| 112 | 118 | // First time this section? |
| 113 | - if (!isset($menu_context['sections'][$section_id])) |
|
| 114 | - $menu_context['sections'][$section_id]['title'] = $section['title']; |
|
| 119 | + if (!isset($menu_context['sections'][$section_id])) { |
|
| 120 | + $menu_context['sections'][$section_id]['title'] = $section['title']; |
|
| 121 | + } |
|
| 115 | 122 | |
| 116 | 123 | $menu_context['sections'][$section_id]['areas'][$area_id] = array('label' => isset($area['label']) ? $area['label'] : $txt[$area_id]); |
| 117 | 124 | // We'll need the ID as well... |
| 118 | 125 | $menu_context['sections'][$section_id]['id'] = $section_id; |
| 119 | 126 | // Does it have a custom URL? |
| 120 | - if (isset($area['custom_url'])) |
|
| 121 | - $menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url']; |
|
| 127 | + if (isset($area['custom_url'])) { |
|
| 128 | + $menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url']; |
|
| 129 | + } |
|
| 122 | 130 | |
| 123 | 131 | // Does this area have its own icon? |
| 124 | - if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa') |
|
| 125 | - $menu_context['sections'][$section_id]['areas'][$area_id] = safe_unserialize(base64_decode('YTozOntzOjU6ImxhYmVsIjtzOjEyOiJPb21wYSBMb29tcGEiO3M6MzoidXJsIjtzOjQzOiJodHRwOi8vZW4ud2lraXBlZGlhLm9yZy93aWtpL09vbXBhX0xvb21wYXM/IjtzOjQ6Imljb24iO3M6ODY6IjxpbWcgc3JjPSJodHRwOi8vd3d3LnNpbXBsZW1hY2hpbmVzLm9yZy9pbWFnZXMvb29tcGEuZ2lmIiBhbHQ9IkknbSBhbiBPb21wYSBMb29tcGEiIC8+Ijt9')); |
|
| 126 | - elseif (isset($area['icon']) && file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon'])) |
|
| 127 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">'; |
|
| 128 | - elseif (isset($area['icon']) && file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon'])) |
|
| 129 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">'; |
|
| 130 | - elseif (isset($area['icon'])) |
|
| 131 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>'; |
|
| 132 | - else |
|
| 133 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>'; |
|
| 134 | - |
|
| 135 | - if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon'])) |
|
| 136 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class']; |
|
| 137 | - elseif (isset($area['icon'])) |
|
| 132 | + if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa') { |
|
| 133 | + $menu_context['sections'][$section_id]['areas'][$area_id] = safe_unserialize(base64_decode('YTozOntzOjU6ImxhYmVsIjtzOjEyOiJPb21wYSBMb29tcGEiO3M6MzoidXJsIjtzOjQzOiJodHRwOi8vZW4ud2lraXBlZGlhLm9yZy93aWtpL09vbXBhX0xvb21wYXM/IjtzOjQ6Imljb24iO3M6ODY6IjxpbWcgc3JjPSJodHRwOi8vd3d3LnNpbXBsZW1hY2hpbmVzLm9yZy9pbWFnZXMvb29tcGEuZ2lmIiBhbHQ9IkknbSBhbiBPb21wYSBMb29tcGEiIC8+Ijt9')); |
|
| 134 | + } elseif (isset($area['icon']) && file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon'])) { |
|
| 135 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">'; |
|
| 136 | + } elseif (isset($area['icon']) && file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon'])) { |
|
| 137 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">'; |
|
| 138 | + } elseif (isset($area['icon'])) { |
|
| 139 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>'; |
|
| 140 | + } else { |
|
| 141 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>'; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon'])) { |
|
| 145 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class']; |
|
| 146 | + } elseif (isset($area['icon'])) |
|
| 138 | 147 | { |
| 139 | - if ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon'])) |
|
| 140 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon']; |
|
| 141 | - elseif ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon'])) |
|
| 142 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon']; |
|
| 148 | + if ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon'])) { |
|
| 149 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon']; |
|
| 150 | + } elseif ((substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif') && file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon'])) { |
|
| 151 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon']; |
|
| 152 | + } |
|
| 143 | 153 | |
| 144 | 154 | $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area['icon']); |
| 155 | + } else { |
|
| 156 | + $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id); |
|
| 145 | 157 | } |
| 146 | - else |
|
| 147 | - $menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id); |
|
| 148 | 158 | |
| 149 | 159 | // Some areas may be listed but not active, which we show as greyed out. |
| 150 | 160 | $menu_context['sections'][$section_id]['areas'][$area_id]['inactive'] = !empty($area['inactive']); |
@@ -158,35 +168,41 @@ discard block |
||
| 158 | 168 | { |
| 159 | 169 | if ((empty($sub[1]) || allowedTo($sub[1])) && (!isset($sub['enabled']) || !empty($sub['enabled']))) |
| 160 | 170 | { |
| 161 | - if ($first_sa == null) |
|
| 162 | - $first_sa = $sa; |
|
| 171 | + if ($first_sa == null) { |
|
| 172 | + $first_sa = $sa; |
|
| 173 | + } |
|
| 163 | 174 | |
| 164 | 175 | $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa] = array('label' => $sub[0]); |
| 165 | 176 | // Custom URL? |
| 166 | - if (isset($sub['url'])) |
|
| 167 | - $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url']; |
|
| 177 | + if (isset($sub['url'])) { |
|
| 178 | + $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url']; |
|
| 179 | + } |
|
| 168 | 180 | |
| 169 | 181 | // A bit complicated - but is this set? |
| 170 | 182 | if ($menu_context['current_area'] == $area_id) |
| 171 | 183 | { |
| 172 | 184 | // Save which is the first... |
| 173 | - if (empty($first_sa)) |
|
| 174 | - $first_sa = $sa; |
|
| 185 | + if (empty($first_sa)) { |
|
| 186 | + $first_sa = $sa; |
|
| 187 | + } |
|
| 175 | 188 | |
| 176 | 189 | // Is this the current subsection? |
| 177 | - if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa) |
|
| 178 | - $menu_context['current_subsection'] = $sa; |
|
| 190 | + if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa) { |
|
| 191 | + $menu_context['current_subsection'] = $sa; |
|
| 192 | + } |
|
| 179 | 193 | // Otherwise is it the default? |
| 180 | - elseif (!isset($menu_context['current_subsection']) && !empty($sub[2])) |
|
| 181 | - $menu_context['current_subsection'] = $sa; |
|
| 194 | + elseif (!isset($menu_context['current_subsection']) && !empty($sub[2])) { |
|
| 195 | + $menu_context['current_subsection'] = $sa; |
|
| 196 | + } |
|
| 182 | 197 | } |
| 183 | 198 | |
| 184 | 199 | // Let's assume this is the last, for now. |
| 185 | 200 | $last_sa = $sa; |
| 186 | 201 | } |
| 187 | 202 | // Mark it as disabled... |
| 188 | - else |
|
| 189 | - $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true; |
|
| 203 | + else { |
|
| 204 | + $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true; |
|
| 205 | + } |
|
| 190 | 206 | } |
| 191 | 207 | |
| 192 | 208 | // Set which one is first, last and selected in the group. |
@@ -195,8 +211,9 @@ discard block |
||
| 195 | 211 | $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $last_sa : $first_sa]['is_first'] = true; |
| 196 | 212 | $menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $first_sa : $last_sa]['is_last'] = true; |
| 197 | 213 | |
| 198 | - if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection'])) |
|
| 199 | - $menu_context['current_subsection'] = $first_sa; |
|
| 214 | + if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection'])) { |
|
| 215 | + $menu_context['current_subsection'] = $first_sa; |
|
| 216 | + } |
|
| 200 | 217 | } |
| 201 | 218 | } |
| 202 | 219 | } |
@@ -230,23 +247,26 @@ discard block |
||
| 230 | 247 | $menu_context['base_url'] = isset($menuOptions['base_url']) ? $menuOptions['base_url'] : $scripturl . '?action=' . $menu_context['current_action']; |
| 231 | 248 | |
| 232 | 249 | // If we didn't find the area we were looking for go to a default one. |
| 233 | - if (isset($backup_area) && empty($found_section)) |
|
| 234 | - $menu_context['current_area'] = $backup_area; |
|
| 250 | + if (isset($backup_area) && empty($found_section)) { |
|
| 251 | + $menu_context['current_area'] = $backup_area; |
|
| 252 | + } |
|
| 235 | 253 | |
| 236 | 254 | // If there are sections quickly goes through all the sections to check if the base menu has an url |
| 237 | 255 | if (!empty($menu_context['current_section'])) |
| 238 | 256 | { |
| 239 | 257 | $menu_context['sections'][$menu_context['current_section']]['selected'] = true; |
| 240 | 258 | $menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['selected'] = true; |
| 241 | - if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']])) |
|
| 242 | - $menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true; |
|
| 259 | + if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']])) { |
|
| 260 | + $menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true; |
|
| 261 | + } |
|
| 243 | 262 | |
| 244 | - foreach ($menu_context['sections'] as $section_id => $section) |
|
| 245 | - foreach ($section['areas'] as $area_id => $area) |
|
| 263 | + foreach ($menu_context['sections'] as $section_id => $section) { |
|
| 264 | + foreach ($section['areas'] as $area_id => $area) |
|
| 246 | 265 | { |
| 247 | 266 | if (!isset($menu_context['sections'][$section_id]['url'])) |
| 248 | 267 | { |
| 249 | 268 | $menu_context['sections'][$section_id]['url'] = isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $area_id; |
| 269 | + } |
|
| 250 | 270 | break; |
| 251 | 271 | } |
| 252 | 272 | } |
@@ -257,8 +277,9 @@ discard block |
||
| 257 | 277 | { |
| 258 | 278 | // Never happened! |
| 259 | 279 | $context['max_menu_id']--; |
| 260 | - if ($context['max_menu_id'] == 0) |
|
| 261 | - unset($context['max_menu_id']); |
|
| 280 | + if ($context['max_menu_id'] == 0) { |
|
| 281 | + unset($context['max_menu_id']); |
|
| 282 | + } |
|
| 262 | 283 | |
| 263 | 284 | return false; |
| 264 | 285 | } |
@@ -269,8 +290,9 @@ discard block |
||
| 269 | 290 | $context['template_layers'][] = $menu_context['layer_name']; |
| 270 | 291 | |
| 271 | 292 | // Check we had something - for sanity sake. |
| 272 | - if (empty($include_data)) |
|
| 273 | - return false; |
|
| 293 | + if (empty($include_data)) { |
|
| 294 | + return false; |
|
| 295 | + } |
|
| 274 | 296 | |
| 275 | 297 | // Finally - return information on the selected item. |
| 276 | 298 | $include_data += array( |
@@ -293,12 +315,14 @@ discard block |
||
| 293 | 315 | global $context; |
| 294 | 316 | |
| 295 | 317 | $menu_name = $menu_id == 'last' && isset($context['max_menu_id']) && isset($context['menu_data_' . $context['max_menu_id']]) ? 'menu_data_' . $context['max_menu_id'] : 'menu_data_' . $menu_id; |
| 296 | - if (!isset($context[$menu_name])) |
|
| 297 | - return false; |
|
| 318 | + if (!isset($context[$menu_name])) { |
|
| 319 | + return false; |
|
| 320 | + } |
|
| 298 | 321 | |
| 299 | 322 | $layer_index = array_search($context[$menu_name]['layer_name'], $context['template_layers']); |
| 300 | - if ($layer_index !== false) |
|
| 301 | - unset($context['template_layers'][$layer_index]); |
|
| 323 | + if ($layer_index !== false) { |
|
| 324 | + unset($context['template_layers'][$layer_index]); |
|
| 325 | + } |
|
| 302 | 326 | |
| 303 | 327 | unset($context[$menu_name]); |
| 304 | 328 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @param bool $single_file If true returns the contents of the file specified by destination if it exists |
| 29 | 29 | * @param bool $overwrite Whether to overwrite existing files |
| 30 | 30 | * @param null|array $files_to_extract Specific files to extract |
| 31 | - * @return array|false An array of information about extracted files or false on failure |
|
| 31 | + * @return string An array of information about extracted files or false on failure |
|
| 32 | 32 | */ |
| 33 | 33 | function read_tgz_file($gzfilename, $destination, $single_file = false, $overwrite = false, $files_to_extract = null) |
| 34 | 34 | { |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @param bool $single_file Whether to only extract a single file |
| 60 | 60 | * @param bool $overwrite Whether to overwrite existing data |
| 61 | 61 | * @param null|array $files_to_extract If set, only extracts the specified files |
| 62 | - * @return array|false An array of information about the extracted files or false on failure |
|
| 62 | + * @return string An array of information about the extracted files or false on failure |
|
| 63 | 63 | */ |
| 64 | 64 | function read_tgz_data($gzfilename, $destination, $single_file = false, $overwrite = false, $files_to_extract = null) |
| 65 | 65 | { |
@@ -3251,7 +3251,7 @@ discard block |
||
| 3251 | 3251 | * http://www.php.net/crc32#79567 |
| 3252 | 3252 | * |
| 3253 | 3253 | * @param string $number |
| 3254 | - * @return string The crc32 |
|
| 3254 | + * @return integer The crc32 |
|
| 3255 | 3255 | */ |
| 3256 | 3256 | function smf_crc32($number) |
| 3257 | 3257 | { |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | |
| 573 | 573 | // Don't want to mess with code... |
| 574 | 574 | $types = array('install', 'uninstall', 'upgrade'); |
| 575 | - foreach($types as $type) |
|
| 575 | + foreach ($types as $type) |
|
| 576 | 576 | { |
| 577 | 577 | if (isset($package[$type]['code'])) |
| 578 | 578 | { |
@@ -697,7 +697,7 @@ discard block |
||
| 697 | 697 | 'value' => $txt['package_restore_permissions_cur_status'], |
| 698 | 698 | ), |
| 699 | 699 | 'data' => array( |
| 700 | - 'function' => function ($rowData) use ($txt) |
|
| 700 | + 'function' => function($rowData) use ($txt) |
|
| 701 | 701 | { |
| 702 | 702 | $formatTxt = $rowData['result'] == '' || $rowData['result'] == 'skipped' ? $txt['package_restore_permissions_pre_change'] : $txt['package_restore_permissions_post_change']; |
| 703 | 703 | return sprintf($formatTxt, $rowData['cur_perms'], $rowData['new_perms'], $rowData['writable_message']); |
@@ -725,7 +725,7 @@ discard block |
||
| 725 | 725 | 'value' => $txt['package_restore_permissions_result'], |
| 726 | 726 | ), |
| 727 | 727 | 'data' => array( |
| 728 | - 'function' => function ($rowData) use ($txt) |
|
| 728 | + 'function' => function($rowData) use ($txt) |
|
| 729 | 729 | { |
| 730 | 730 | return $txt['package_restore_permissions_action_' . $rowData['result']]; |
| 731 | 731 | }, |
@@ -1195,7 +1195,7 @@ discard block |
||
| 1195 | 1195 | if ($action->exists('@lang')) |
| 1196 | 1196 | { |
| 1197 | 1197 | // Auto-select the language based on either request variable or current language. |
| 1198 | - if ((isset($_REQUEST['readme']) && $action->fetch('@lang') == $_REQUEST['readme']) || (isset($_REQUEST['license']) && $action->fetch('@lang') == $_REQUEST['license']) || (!isset($_REQUEST['readme']) && $action->fetch('@lang') == $language) || (!isset($_REQUEST['license']) && $action->fetch('@lang') == $language)) |
|
| 1198 | + if ((isset($_REQUEST['readme']) && $action->fetch('@lang') == $_REQUEST['readme']) || (isset($_REQUEST['license']) && $action->fetch('@lang') == $_REQUEST['license']) || (!isset($_REQUEST['readme']) && $action->fetch('@lang') == $language) || (!isset($_REQUEST['license']) && $action->fetch('@lang') == $language)) |
|
| 1199 | 1199 | { |
| 1200 | 1200 | // In case the user put the blocks in the wrong order. |
| 1201 | 1201 | if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default') |
@@ -1243,7 +1243,7 @@ discard block |
||
| 1243 | 1243 | 'redirect_url' => $action->exists('@url') ? $action->fetch('@url') : '', |
| 1244 | 1244 | 'redirect_timeout' => $action->exists('@timeout') ? (int) $action->fetch('@timeout') : '', |
| 1245 | 1245 | 'parse_bbc' => $action->exists('@parsebbc') && $action->fetch('@parsebbc') == 'true', |
| 1246 | - 'language' => (($actionType == 'readme' || $actionType == 'license') && $action->exists('@lang') && $action->fetch('@lang') == $language) ? $language : '', |
|
| 1246 | + 'language' => (($actionType == 'readme' || $actionType == 'license') && $action->exists('@lang') && $action->fetch('@lang') == $language) ? $language : '', |
|
| 1247 | 1247 | ); |
| 1248 | 1248 | |
| 1249 | 1249 | continue; |
@@ -16,8 +16,9 @@ discard block |
||
| 16 | 16 | * @version 2.1 Beta 3 |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | -if (!defined('SMF')) |
|
| 19 | +if (!defined('SMF')) { |
|
| 20 | 20 | die('No direct access...'); |
| 21 | +} |
|
| 21 | 22 | |
| 22 | 23 | /** |
| 23 | 24 | * Reads a .tar.gz file, filename, in and extracts file(s) from it. |
@@ -67,47 +68,53 @@ discard block |
||
| 67 | 68 | loadLanguage('Packages'); |
| 68 | 69 | |
| 69 | 70 | // This function sorta needs gzinflate! |
| 70 | - if (!function_exists('gzinflate')) |
|
| 71 | - fatal_lang_error('package_no_zlib', 'critical'); |
|
| 71 | + if (!function_exists('gzinflate')) { |
|
| 72 | + fatal_lang_error('package_no_zlib', 'critical'); |
|
| 73 | + } |
|
| 72 | 74 | |
| 73 | 75 | if (substr($gzfilename, 0, 7) == 'http://' || substr($gzfilename, 0, 8) == 'https://') |
| 74 | 76 | { |
| 75 | 77 | $data = fetch_web_data($gzfilename); |
| 76 | 78 | |
| 77 | - if ($data === false) |
|
| 78 | - return false; |
|
| 79 | - } |
|
| 80 | - else |
|
| 79 | + if ($data === false) { |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 82 | + } else |
|
| 81 | 83 | { |
| 82 | 84 | $data = @file_get_contents($gzfilename); |
| 83 | 85 | |
| 84 | - if ($data === false) |
|
| 85 | - return false; |
|
| 86 | + if ($data === false) { |
|
| 87 | + return false; |
|
| 88 | + } |
|
| 86 | 89 | } |
| 87 | 90 | |
| 88 | 91 | umask(0); |
| 89 | - if (!$single_file && $destination !== null && !file_exists($destination)) |
|
| 90 | - mktree($destination, 0777); |
|
| 92 | + if (!$single_file && $destination !== null && !file_exists($destination)) { |
|
| 93 | + mktree($destination, 0777); |
|
| 94 | + } |
|
| 91 | 95 | |
| 92 | 96 | // No signature? |
| 93 | - if (strlen($data) < 2) |
|
| 94 | - return false; |
|
| 97 | + if (strlen($data) < 2) { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 95 | 100 | |
| 96 | 101 | $id = unpack('H2a/H2b', substr($data, 0, 2)); |
| 97 | 102 | if (strtolower($id['a'] . $id['b']) != '1f8b') |
| 98 | 103 | { |
| 99 | 104 | // Okay, this ain't no tar.gz, but maybe it's a zip file. |
| 100 | - if (substr($data, 0, 2) == 'PK') |
|
| 101 | - return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract); |
|
| 102 | - else |
|
| 103 | - return false; |
|
| 105 | + if (substr($data, 0, 2) == 'PK') { |
|
| 106 | + return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract); |
|
| 107 | + } else { |
|
| 108 | + return false; |
|
| 109 | + } |
|
| 104 | 110 | } |
| 105 | 111 | |
| 106 | 112 | $flags = unpack('Ct/Cf', substr($data, 2, 2)); |
| 107 | 113 | |
| 108 | 114 | // Not deflate! |
| 109 | - if ($flags['t'] != 8) |
|
| 110 | - return false; |
|
| 115 | + if ($flags['t'] != 8) { |
|
| 116 | + return false; |
|
| 117 | + } |
|
| 111 | 118 | $flags = $flags['f']; |
| 112 | 119 | |
| 113 | 120 | $offset = 10; |
@@ -117,18 +124,21 @@ discard block |
||
| 117 | 124 | // @todo Might be mussed. |
| 118 | 125 | if ($flags & 12) |
| 119 | 126 | { |
| 120 | - while ($flags & 8 && $data{$offset++} != "\0") |
|
| 121 | - continue; |
|
| 122 | - while ($flags & 4 && $data{$offset++} != "\0") |
|
| 123 | - continue; |
|
| 127 | + while ($flags & 8 && $data{$offset++} != "\0") { |
|
| 128 | + continue; |
|
| 129 | + } |
|
| 130 | + while ($flags & 4 && $data{$offset++} != "\0") { |
|
| 131 | + continue; |
|
| 132 | + } |
|
| 124 | 133 | } |
| 125 | 134 | |
| 126 | 135 | $crc = unpack('Vcrc32/Visize', substr($data, strlen($data) - 8, 8)); |
| 127 | 136 | $data = @gzinflate(substr($data, $offset, strlen($data) - 8 - $offset)); |
| 128 | 137 | |
| 129 | 138 | // smf_crc32 and crc32 may not return the same results, so we accept either. |
| 130 | - if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data)) |
|
| 131 | - return false; |
|
| 139 | + if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data)) { |
|
| 140 | + return false; |
|
| 141 | + } |
|
| 132 | 142 | |
| 133 | 143 | $blocks = strlen($data) / 512 - 1; |
| 134 | 144 | $offset = 0; |
@@ -149,83 +159,98 @@ discard block |
||
| 149 | 159 | |
| 150 | 160 | foreach ($current as $k => $v) |
| 151 | 161 | { |
| 152 | - if (in_array($k, $octdec)) |
|
| 153 | - $current[$k] = octdec(trim($v)); |
|
| 154 | - else |
|
| 155 | - $current[$k] = trim($v); |
|
| 162 | + if (in_array($k, $octdec)) { |
|
| 163 | + $current[$k] = octdec(trim($v)); |
|
| 164 | + } else { |
|
| 165 | + $current[$k] = trim($v); |
|
| 166 | + } |
|
| 156 | 167 | } |
| 157 | 168 | |
| 158 | - if ($current['type'] == 5 && substr($current['filename'], -1) != '/') |
|
| 159 | - $current['filename'] .= '/'; |
|
| 169 | + if ($current['type'] == 5 && substr($current['filename'], -1) != '/') { |
|
| 170 | + $current['filename'] .= '/'; |
|
| 171 | + } |
|
| 160 | 172 | |
| 161 | 173 | $checksum = 256; |
| 162 | - for ($i = 0; $i < 148; $i++) |
|
| 163 | - $checksum += ord($header{$i}); |
|
| 164 | - for ($i = 156; $i < 512; $i++) |
|
| 165 | - $checksum += ord($header{$i}); |
|
| 174 | + for ($i = 0; $i < 148; $i++) { |
|
| 175 | + $checksum += ord($header{$i}); |
|
| 176 | + } |
|
| 177 | + for ($i = 156; $i < 512; $i++) { |
|
| 178 | + $checksum += ord($header{$i}); |
|
| 179 | + } |
|
| 166 | 180 | |
| 167 | - if ($current['checksum'] != $checksum) |
|
| 168 | - break; |
|
| 181 | + if ($current['checksum'] != $checksum) { |
|
| 182 | + break; |
|
| 183 | + } |
|
| 169 | 184 | |
| 170 | 185 | $size = ceil($current['size'] / 512); |
| 171 | 186 | $current['data'] = substr($data, ++$offset << 9, $current['size']); |
| 172 | 187 | $offset += $size; |
| 173 | 188 | |
| 174 | 189 | // Not a directory and doesn't exist already... |
| 175 | - if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename'])) |
|
| 176 | - $write_this = true; |
|
| 190 | + if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename'])) { |
|
| 191 | + $write_this = true; |
|
| 192 | + } |
|
| 177 | 193 | // File exists... check if it is newer. |
| 178 | - elseif (substr($current['filename'], -1, 1) != '/') |
|
| 179 | - $write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime']; |
|
| 194 | + elseif (substr($current['filename'], -1, 1) != '/') { |
|
| 195 | + $write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime']; |
|
| 196 | + } |
|
| 180 | 197 | // Folder... create. |
| 181 | 198 | elseif ($destination !== null && !$single_file) |
| 182 | 199 | { |
| 183 | 200 | // Protect from accidental parent directory writing... |
| 184 | 201 | $current['filename'] = strtr($current['filename'], array('../' => '', '/..' => '')); |
| 185 | 202 | |
| 186 | - if (!file_exists($destination . '/' . $current['filename'])) |
|
| 187 | - mktree($destination . '/' . $current['filename'], 0777); |
|
| 203 | + if (!file_exists($destination . '/' . $current['filename'])) { |
|
| 204 | + mktree($destination . '/' . $current['filename'], 0777); |
|
| 205 | + } |
|
| 188 | 206 | $write_this = false; |
| 207 | + } else { |
|
| 208 | + $write_this = false; |
|
| 189 | 209 | } |
| 190 | - else |
|
| 191 | - $write_this = false; |
|
| 192 | 210 | |
| 193 | 211 | if ($write_this && $destination !== null) |
| 194 | 212 | { |
| 195 | - if (strpos($current['filename'], '/') !== false && !$single_file) |
|
| 196 | - mktree($destination . '/' . dirname($current['filename']), 0777); |
|
| 213 | + if (strpos($current['filename'], '/') !== false && !$single_file) { |
|
| 214 | + mktree($destination . '/' . dirname($current['filename']), 0777); |
|
| 215 | + } |
|
| 197 | 216 | |
| 198 | 217 | // Is this the file we're looking for? |
| 199 | - if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename']))) |
|
| 200 | - return $current['data']; |
|
| 218 | + if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename']))) { |
|
| 219 | + return $current['data']; |
|
| 220 | + } |
|
| 201 | 221 | // If we're looking for another file, keep going. |
| 202 | - elseif ($single_file) |
|
| 203 | - continue; |
|
| 222 | + elseif ($single_file) { |
|
| 223 | + continue; |
|
| 224 | + } |
|
| 204 | 225 | // Looking for restricted files? |
| 205 | - elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract)) |
|
| 206 | - continue; |
|
| 226 | + elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract)) { |
|
| 227 | + continue; |
|
| 228 | + } |
|
| 207 | 229 | |
| 208 | 230 | package_put_contents($destination . '/' . $current['filename'], $current['data']); |
| 209 | 231 | } |
| 210 | 232 | |
| 211 | - if (substr($current['filename'], -1, 1) != '/') |
|
| 212 | - $return[] = array( |
|
| 233 | + if (substr($current['filename'], -1, 1) != '/') { |
|
| 234 | + $return[] = array( |
|
| 213 | 235 | 'filename' => $current['filename'], |
| 214 | 236 | 'md5' => md5($current['data']), |
| 215 | 237 | 'preview' => substr($current['data'], 0, 100), |
| 216 | 238 | 'size' => $current['size'], |
| 217 | 239 | 'skipped' => false |
| 218 | 240 | ); |
| 241 | + } |
|
| 219 | 242 | } |
| 220 | 243 | |
| 221 | - if ($destination !== null && !$single_file) |
|
| 222 | - package_flush_cache(); |
|
| 244 | + if ($destination !== null && !$single_file) { |
|
| 245 | + package_flush_cache(); |
|
| 246 | + } |
|
| 223 | 247 | |
| 224 | - if ($single_file) |
|
| 225 | - return false; |
|
| 226 | - else |
|
| 227 | - return $return; |
|
| 228 | -} |
|
| 248 | + if ($single_file) { |
|
| 249 | + return false; |
|
| 250 | + } else { |
|
| 251 | + return $return; |
|
| 252 | + } |
|
| 253 | + } |
|
| 229 | 254 | |
| 230 | 255 | /** |
| 231 | 256 | * Extract zip data. A functional copy of {@list read_zip_data()}. |
@@ -254,65 +279,74 @@ discard block |
||
| 254 | 279 | { |
| 255 | 280 | $i = $iterator->getSubPathname(); |
| 256 | 281 | // If this is a file, and it doesn't exist.... happy days! |
| 257 | - if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i)) |
|
| 258 | - $write_this = true; |
|
| 282 | + if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i)) { |
|
| 283 | + $write_this = true; |
|
| 284 | + } |
|
| 259 | 285 | // If the file exists, we may not want to overwrite it. |
| 260 | - elseif (substr($i, -1) != '/') |
|
| 261 | - $write_this = $overwrite; |
|
| 262 | - else |
|
| 263 | - $write_this = false; |
|
| 286 | + elseif (substr($i, -1) != '/') { |
|
| 287 | + $write_this = $overwrite; |
|
| 288 | + } else { |
|
| 289 | + $write_this = false; |
|
| 290 | + } |
|
| 264 | 291 | |
| 265 | 292 | // Get the actual compressed data. |
| 266 | - if (!$file_info->isDir()) |
|
| 267 | - $file_data = file_get_contents($file_info); |
|
| 268 | - elseif ($destination !== null && !$single_file) |
|
| 293 | + if (!$file_info->isDir()) { |
|
| 294 | + $file_data = file_get_contents($file_info); |
|
| 295 | + } elseif ($destination !== null && !$single_file) |
|
| 269 | 296 | { |
| 270 | 297 | // Folder... create. |
| 271 | - if (!file_exists($destination . '/' . $i)) |
|
| 272 | - mktree($destination . '/' . $i, 0777); |
|
| 298 | + if (!file_exists($destination . '/' . $i)) { |
|
| 299 | + mktree($destination . '/' . $i, 0777); |
|
| 300 | + } |
|
| 273 | 301 | $file_data = null; |
| 302 | + } else { |
|
| 303 | + $file_data = null; |
|
| 274 | 304 | } |
| 275 | - else |
|
| 276 | - $file_data = null; |
|
| 277 | 305 | |
| 278 | 306 | // Okay! We can write this file, looks good from here... |
| 279 | 307 | if ($write_this && $destination !== null) |
| 280 | 308 | { |
| 281 | - if (!$single_file && !is_dir($destination . '/' . dirname($i))) |
|
| 282 | - mktree($destination . '/' . dirname($i), 0777); |
|
| 309 | + if (!$single_file && !is_dir($destination . '/' . dirname($i))) { |
|
| 310 | + mktree($destination . '/' . dirname($i), 0777); |
|
| 311 | + } |
|
| 283 | 312 | |
| 284 | 313 | // If we're looking for a specific file, and this is it... ka-bam, baby. |
| 285 | - if ($single_file && ($destination == $i || $destination == '*/' . basename($i))) |
|
| 286 | - return $file_data; |
|
| 314 | + if ($single_file && ($destination == $i || $destination == '*/' . basename($i))) { |
|
| 315 | + return $file_data; |
|
| 316 | + } |
|
| 287 | 317 | // Oh? Another file. Fine. You don't like this file, do you? I know how it is. Yeah... just go away. No, don't apologize. I know this file's just not *good enough* for you. |
| 288 | - elseif ($single_file) |
|
| 289 | - continue; |
|
| 318 | + elseif ($single_file) { |
|
| 319 | + continue; |
|
| 320 | + } |
|
| 290 | 321 | // Don't really want this? |
| 291 | - elseif ($files_to_extract !== null && !in_array($i, $files_to_extract)) |
|
| 292 | - continue; |
|
| 322 | + elseif ($files_to_extract !== null && !in_array($i, $files_to_extract)) { |
|
| 323 | + continue; |
|
| 324 | + } |
|
| 293 | 325 | |
| 294 | 326 | package_put_contents($destination . '/' . $i, $file_data); |
| 295 | 327 | } |
| 296 | 328 | |
| 297 | - if (substr($i, -1, 1) != '/') |
|
| 298 | - $return[] = array( |
|
| 329 | + if (substr($i, -1, 1) != '/') { |
|
| 330 | + $return[] = array( |
|
| 299 | 331 | 'filename' => $i, |
| 300 | 332 | 'md5' => md5($file_data), |
| 301 | 333 | 'preview' => substr($file_data, 0, 100), |
| 302 | 334 | 'size' => strlen($file_data), |
| 303 | 335 | 'skipped' => false |
| 304 | 336 | ); |
| 337 | + } |
|
| 305 | 338 | } |
| 306 | 339 | |
| 307 | - if ($destination !== null && !$single_file) |
|
| 308 | - package_flush_cache(); |
|
| 340 | + if ($destination !== null && !$single_file) { |
|
| 341 | + package_flush_cache(); |
|
| 342 | + } |
|
| 309 | 343 | |
| 310 | - if ($single_file) |
|
| 311 | - return false; |
|
| 312 | - else |
|
| 313 | - return $return; |
|
| 314 | - } |
|
| 315 | - catch (Exception $e) |
|
| 344 | + if ($single_file) { |
|
| 345 | + return false; |
|
| 346 | + } else { |
|
| 347 | + return $return; |
|
| 348 | + } |
|
| 349 | + } catch (Exception $e) |
|
| 316 | 350 | { |
| 317 | 351 | return false; |
| 318 | 352 | } |
@@ -334,13 +368,15 @@ discard block |
||
| 334 | 368 | function read_zip_data($data, $destination, $single_file = false, $overwrite = false, $files_to_extract = null) |
| 335 | 369 | { |
| 336 | 370 | umask(0); |
| 337 | - if ($destination !== null && !file_exists($destination) && !$single_file) |
|
| 338 | - mktree($destination, 0777); |
|
| 371 | + if ($destination !== null && !file_exists($destination) && !$single_file) { |
|
| 372 | + mktree($destination, 0777); |
|
| 373 | + } |
|
| 339 | 374 | |
| 340 | 375 | // Look for the end of directory signature 0x06054b50 |
| 341 | 376 | $data_ecr = explode("\x50\x4b\x05\x06", $data); |
| 342 | - if (!isset($data_ecr[1])) |
|
| 343 | - return false; |
|
| 377 | + if (!isset($data_ecr[1])) { |
|
| 378 | + return false; |
|
| 379 | + } |
|
| 344 | 380 | |
| 345 | 381 | $return = array(); |
| 346 | 382 | |
@@ -355,8 +391,9 @@ discard block |
||
| 355 | 391 | array_shift($file_sections); |
| 356 | 392 | |
| 357 | 393 | // sections and count from the signature must match or the zip file is bad |
| 358 | - if (count($file_sections) != $zip_info['files']) |
|
| 359 | - return false; |
|
| 394 | + if (count($file_sections) != $zip_info['files']) { |
|
| 395 | + return false; |
|
| 396 | + } |
|
| 360 | 397 | |
| 361 | 398 | // go though each file in the archive |
| 362 | 399 | foreach ($file_sections as $data) |
@@ -378,68 +415,79 @@ discard block |
||
| 378 | 415 | } |
| 379 | 416 | |
| 380 | 417 | // If this is a file, and it doesn't exist.... happy days! |
| 381 | - if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename'])) |
|
| 382 | - $write_this = true; |
|
| 418 | + if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename'])) { |
|
| 419 | + $write_this = true; |
|
| 420 | + } |
|
| 383 | 421 | // If the file exists, we may not want to overwrite it. |
| 384 | - elseif (substr($file_info['filename'], -1) != '/') |
|
| 385 | - $write_this = $overwrite; |
|
| 422 | + elseif (substr($file_info['filename'], -1) != '/') { |
|
| 423 | + $write_this = $overwrite; |
|
| 424 | + } |
|
| 386 | 425 | // This is a directory, so we're gonna want to create it. (probably...) |
| 387 | 426 | elseif ($destination !== null && !$single_file) |
| 388 | 427 | { |
| 389 | 428 | // Just a little accident prevention, don't mind me. |
| 390 | 429 | $file_info['filename'] = strtr($file_info['filename'], array('../' => '', '/..' => '')); |
| 391 | 430 | |
| 392 | - if (!file_exists($destination . '/' . $file_info['filename'])) |
|
| 393 | - mktree($destination . '/' . $file_info['filename'], 0777); |
|
| 431 | + if (!file_exists($destination . '/' . $file_info['filename'])) { |
|
| 432 | + mktree($destination . '/' . $file_info['filename'], 0777); |
|
| 433 | + } |
|
| 394 | 434 | $write_this = false; |
| 435 | + } else { |
|
| 436 | + $write_this = false; |
|
| 395 | 437 | } |
| 396 | - else |
|
| 397 | - $write_this = false; |
|
| 398 | 438 | |
| 399 | 439 | // Get the actual compressed data. |
| 400 | 440 | $file_info['data'] = substr($data, 26 + $file_info['filename_length'] + $file_info['extrafield_length']); |
| 401 | 441 | |
| 402 | 442 | // Only inflate it if we need to ;) |
| 403 | - if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size'])) |
|
| 404 | - $file_info['data'] = gzinflate($file_info['data']); |
|
| 443 | + if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size'])) { |
|
| 444 | + $file_info['data'] = gzinflate($file_info['data']); |
|
| 445 | + } |
|
| 405 | 446 | |
| 406 | 447 | // Okay! We can write this file, looks good from here... |
| 407 | 448 | if ($write_this && $destination !== null) |
| 408 | 449 | { |
| 409 | - if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir']))) |
|
| 410 | - mktree($file_info['dir'], 0777); |
|
| 450 | + if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir']))) { |
|
| 451 | + mktree($file_info['dir'], 0777); |
|
| 452 | + } |
|
| 411 | 453 | |
| 412 | 454 | // If we're looking for a specific file, and this is it... ka-bam, baby. |
| 413 | - if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename']))) |
|
| 414 | - return $file_info['data']; |
|
| 455 | + if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename']))) { |
|
| 456 | + return $file_info['data']; |
|
| 457 | + } |
|
| 415 | 458 | // Oh? Another file. Fine. You don't like this file, do you? I know how it is. Yeah... just go away. No, don't apologize. I know this file's just not *good enough* for you. |
| 416 | - elseif ($single_file) |
|
| 417 | - continue; |
|
| 459 | + elseif ($single_file) { |
|
| 460 | + continue; |
|
| 461 | + } |
|
| 418 | 462 | // Don't really want this? |
| 419 | - elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract)) |
|
| 420 | - continue; |
|
| 463 | + elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract)) { |
|
| 464 | + continue; |
|
| 465 | + } |
|
| 421 | 466 | |
| 422 | 467 | package_put_contents($destination . '/' . $file_info['filename'], $file_info['data']); |
| 423 | 468 | } |
| 424 | 469 | |
| 425 | - if (substr($file_info['filename'], -1, 1) != '/') |
|
| 426 | - $return[] = array( |
|
| 470 | + if (substr($file_info['filename'], -1, 1) != '/') { |
|
| 471 | + $return[] = array( |
|
| 427 | 472 | 'filename' => $file_info['filename'], |
| 428 | 473 | 'md5' => md5($file_info['data']), |
| 429 | 474 | 'preview' => substr($file_info['data'], 0, 100), |
| 430 | 475 | 'size' => $file_info['size'], |
| 431 | 476 | 'skipped' => false |
| 432 | 477 | ); |
| 478 | + } |
|
| 433 | 479 | } |
| 434 | 480 | |
| 435 | - if ($destination !== null && !$single_file) |
|
| 436 | - package_flush_cache(); |
|
| 481 | + if ($destination !== null && !$single_file) { |
|
| 482 | + package_flush_cache(); |
|
| 483 | + } |
|
| 437 | 484 | |
| 438 | - if ($single_file) |
|
| 439 | - return false; |
|
| 440 | - else |
|
| 441 | - return $return; |
|
| 442 | -} |
|
| 485 | + if ($single_file) { |
|
| 486 | + return false; |
|
| 487 | + } else { |
|
| 488 | + return $return; |
|
| 489 | + } |
|
| 490 | + } |
|
| 443 | 491 | |
| 444 | 492 | /** |
| 445 | 493 | * Checks the existence of a remote file since file_exists() does not do remote. |
@@ -451,14 +499,16 @@ discard block |
||
| 451 | 499 | { |
| 452 | 500 | $a_url = parse_url($url); |
| 453 | 501 | |
| 454 | - if (!isset($a_url['scheme'])) |
|
| 455 | - return false; |
|
| 502 | + if (!isset($a_url['scheme'])) { |
|
| 503 | + return false; |
|
| 504 | + } |
|
| 456 | 505 | |
| 457 | 506 | // Attempt to connect... |
| 458 | 507 | $temp = ''; |
| 459 | 508 | $fid = fsockopen($a_url['host'], !isset($a_url['port']) ? 80 : $a_url['port'], $temp, $temp, 8); |
| 460 | - if (!$fid) |
|
| 461 | - return false; |
|
| 509 | + if (!$fid) { |
|
| 510 | + return false; |
|
| 511 | + } |
|
| 462 | 512 | |
| 463 | 513 | fputs($fid, 'HEAD ' . $a_url['path'] . ' HTTP/1.0' . "\r\n" . 'Host: ' . $a_url['host'] . "\r\n\r\n"); |
| 464 | 514 | $head = fread($fid, 1024); |
@@ -493,8 +543,9 @@ discard block |
||
| 493 | 543 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 494 | 544 | { |
| 495 | 545 | // Already found this? If so don't add it twice! |
| 496 | - if (in_array($row['package_id'], $found)) |
|
| 497 | - continue; |
|
| 546 | + if (in_array($row['package_id'], $found)) { |
|
| 547 | + continue; |
|
| 548 | + } |
|
| 498 | 549 | |
| 499 | 550 | $found[] = $row['package_id']; |
| 500 | 551 | |
@@ -529,19 +580,21 @@ discard block |
||
| 529 | 580 | global $sourcedir, $packagesdir, $smcFunc; |
| 530 | 581 | |
| 531 | 582 | // Extract package-info.xml from downloaded file. (*/ is used because it could be in any directory.) |
| 532 | - if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false) |
|
| 533 | - $packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true); |
|
| 534 | - else |
|
| 583 | + if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false) { |
|
| 584 | + $packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true); |
|
| 585 | + } else |
|
| 535 | 586 | { |
| 536 | - if (!file_exists($packagesdir . '/' . $gzfilename)) |
|
| 537 | - return 'package_get_error_not_found'; |
|
| 587 | + if (!file_exists($packagesdir . '/' . $gzfilename)) { |
|
| 588 | + return 'package_get_error_not_found'; |
|
| 589 | + } |
|
| 538 | 590 | |
| 539 | - if (is_file($packagesdir . '/' . $gzfilename)) |
|
| 540 | - $packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true); |
|
| 541 | - elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml')) |
|
| 542 | - $packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml'); |
|
| 543 | - else |
|
| 544 | - return 'package_get_error_missing_xml'; |
|
| 591 | + if (is_file($packagesdir . '/' . $gzfilename)) { |
|
| 592 | + $packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true); |
|
| 593 | + } elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml')) { |
|
| 594 | + $packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml'); |
|
| 595 | + } else { |
|
| 596 | + return 'package_get_error_missing_xml'; |
|
| 597 | + } |
|
| 545 | 598 | } |
| 546 | 599 | |
| 547 | 600 | // Nothing? |
@@ -549,10 +602,11 @@ discard block |
||
| 549 | 602 | { |
| 550 | 603 | // Perhaps they are trying to install a theme, lets tell them nicely this is the wrong function |
| 551 | 604 | $packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/theme_info.xml', true); |
| 552 | - if (!empty($packageInfo)) |
|
| 553 | - return 'package_get_error_is_theme'; |
|
| 554 | - else |
|
| 555 | - return 'package_get_error_is_zero'; |
|
| 605 | + if (!empty($packageInfo)) { |
|
| 606 | + return 'package_get_error_is_theme'; |
|
| 607 | + } else { |
|
| 608 | + return 'package_get_error_is_zero'; |
|
| 609 | + } |
|
| 556 | 610 | } |
| 557 | 611 | |
| 558 | 612 | // Parse package-info.xml into an xmlArray. |
@@ -560,8 +614,9 @@ discard block |
||
| 560 | 614 | $packageInfo = new xmlArray($packageInfo); |
| 561 | 615 | |
| 562 | 616 | // @todo Error message of some sort? |
| 563 | - if (!$packageInfo->exists('package-info[0]')) |
|
| 564 | - return 'package_get_error_packageinfo_corrupt'; |
|
| 617 | + if (!$packageInfo->exists('package-info[0]')) { |
|
| 618 | + return 'package_get_error_packageinfo_corrupt'; |
|
| 619 | + } |
|
| 565 | 620 | |
| 566 | 621 | $packageInfo = $packageInfo->path('package-info[0]'); |
| 567 | 622 | |
@@ -580,8 +635,9 @@ discard block |
||
| 580 | 635 | } |
| 581 | 636 | } |
| 582 | 637 | |
| 583 | - if (!isset($package['type'])) |
|
| 584 | - $package['type'] = 'modification'; |
|
| 638 | + if (!isset($package['type'])) { |
|
| 639 | + $package['type'] = 'modification'; |
|
| 640 | + } |
|
| 585 | 641 | |
| 586 | 642 | return $package; |
| 587 | 643 | } |
@@ -634,15 +690,14 @@ discard block |
||
| 634 | 690 | { |
| 635 | 691 | $ftp_file = strtr($file, array($_SESSION['pack_ftp']['root'] => '')); |
| 636 | 692 | $package_ftp->chmod($ftp_file, $perms); |
| 693 | + } else { |
|
| 694 | + smf_chmod($file, $perms); |
|
| 637 | 695 | } |
| 638 | - else |
|
| 639 | - smf_chmod($file, $perms); |
|
| 640 | 696 | |
| 641 | 697 | $new_permissions = @fileperms($file); |
| 642 | 698 | $result = $new_permissions == $perms ? 'success' : 'failure'; |
| 643 | 699 | unset($_SESSION['pack_ftp']['original_perms'][$file]); |
| 644 | - } |
|
| 645 | - elseif ($do_change) |
|
| 700 | + } elseif ($do_change) |
|
| 646 | 701 | { |
| 647 | 702 | $new_permissions = ''; |
| 648 | 703 | $result = 'skipped'; |
@@ -758,8 +813,7 @@ discard block |
||
| 758 | 813 | |
| 759 | 814 | $context['sub_template'] = 'show_list'; |
| 760 | 815 | $context['default_list'] = 'restore_file_permissions'; |
| 761 | - } |
|
| 762 | - else |
|
| 816 | + } else |
|
| 763 | 817 | { |
| 764 | 818 | unset($listOptions['columns']['result']); |
| 765 | 819 | } |
@@ -769,12 +823,14 @@ discard block |
||
| 769 | 823 | createList($listOptions); |
| 770 | 824 | |
| 771 | 825 | // If we just restored permissions then whereever we are, we are now done and dusted. |
| 772 | - if (!empty($_POST['restore_perms'])) |
|
| 773 | - obExit(); |
|
| 826 | + if (!empty($_POST['restore_perms'])) { |
|
| 827 | + obExit(); |
|
| 828 | + } |
|
| 774 | 829 | } |
| 775 | 830 | // Otherwise, it's entirely irrelevant? |
| 776 | - elseif ($restore_write_status) |
|
| 777 | - return true; |
|
| 831 | + elseif ($restore_write_status) { |
|
| 832 | + return true; |
|
| 833 | + } |
|
| 778 | 834 | |
| 779 | 835 | // This is where we report what we got up to. |
| 780 | 836 | $return_data = array( |
@@ -812,11 +868,12 @@ discard block |
||
| 812 | 868 | if (!in_array($_POST['ftp_path'], array('', '/'))) |
| 813 | 869 | { |
| 814 | 870 | $ftp_root = strtr($boarddir, array($_POST['ftp_path'] => '')); |
| 815 | - if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/')) |
|
| 816 | - $ftp_root = substr($ftp_root, 0, -1); |
|
| 871 | + if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/')) { |
|
| 872 | + $ftp_root = substr($ftp_root, 0, -1); |
|
| 873 | + } |
|
| 874 | + } else { |
|
| 875 | + $ftp_root = $boarddir; |
|
| 817 | 876 | } |
| 818 | - else |
|
| 819 | - $ftp_root = $boarddir; |
|
| 820 | 877 | |
| 821 | 878 | $_SESSION['pack_ftp'] = array( |
| 822 | 879 | 'server' => $_POST['ftp_server'], |
@@ -828,8 +885,9 @@ discard block |
||
| 828 | 885 | 'connected' => true, |
| 829 | 886 | ); |
| 830 | 887 | |
| 831 | - if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) |
|
| 832 | - updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
| 888 | + if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) { |
|
| 889 | + updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
| 890 | + } |
|
| 833 | 891 | |
| 834 | 892 | // This is now the primary connection. |
| 835 | 893 | $package_ftp = $ftp; |
@@ -842,12 +900,13 @@ discard block |
||
| 842 | 900 | foreach ($chmodFiles as $k => $file) |
| 843 | 901 | { |
| 844 | 902 | // Sometimes this can somehow happen maybe? |
| 845 | - if (empty($file)) |
|
| 846 | - unset($chmodFiles[$k]); |
|
| 903 | + if (empty($file)) { |
|
| 904 | + unset($chmodFiles[$k]); |
|
| 905 | + } |
|
| 847 | 906 | // Already writable? |
| 848 | - elseif (@is_writable($file)) |
|
| 849 | - $return_data['files']['writable'][] = $file; |
|
| 850 | - else |
|
| 907 | + elseif (@is_writable($file)) { |
|
| 908 | + $return_data['files']['writable'][] = $file; |
|
| 909 | + } else |
|
| 851 | 910 | { |
| 852 | 911 | // Now try to change that. |
| 853 | 912 | $return_data['files'][package_chmod($file, 'writable', true) ? 'writable' : 'notwritable'][] = $file; |
@@ -864,19 +923,21 @@ discard block |
||
| 864 | 923 | { |
| 865 | 924 | require_once($sourcedir . '/Class-Package.php'); |
| 866 | 925 | $ftp = new ftp_connection(null); |
| 926 | + } elseif ($ftp->error !== false && !isset($ftp_error)) { |
|
| 927 | + $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 867 | 928 | } |
| 868 | - elseif ($ftp->error !== false && !isset($ftp_error)) |
|
| 869 | - $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 870 | 929 | |
| 871 | 930 | list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir); |
| 872 | 931 | |
| 873 | - if ($found_path) |
|
| 874 | - $_POST['ftp_path'] = $detect_path; |
|
| 875 | - elseif (!isset($_POST['ftp_path'])) |
|
| 876 | - $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
| 932 | + if ($found_path) { |
|
| 933 | + $_POST['ftp_path'] = $detect_path; |
|
| 934 | + } elseif (!isset($_POST['ftp_path'])) { |
|
| 935 | + $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
| 936 | + } |
|
| 877 | 937 | |
| 878 | - if (!isset($_POST['ftp_username'])) |
|
| 879 | - $_POST['ftp_username'] = $username; |
|
| 938 | + if (!isset($_POST['ftp_username'])) { |
|
| 939 | + $_POST['ftp_username'] = $username; |
|
| 940 | + } |
|
| 880 | 941 | } |
| 881 | 942 | |
| 882 | 943 | $context['package_ftp'] = array( |
@@ -889,8 +950,9 @@ discard block |
||
| 889 | 950 | ); |
| 890 | 951 | |
| 891 | 952 | // Which files failed? |
| 892 | - if (!isset($context['notwritable_files'])) |
|
| 893 | - $context['notwritable_files'] = array(); |
|
| 953 | + if (!isset($context['notwritable_files'])) { |
|
| 954 | + $context['notwritable_files'] = array(); |
|
| 955 | + } |
|
| 894 | 956 | $context['notwritable_files'] = array_merge($context['notwritable_files'], $return_data['files']['notwritable']); |
| 895 | 957 | |
| 896 | 958 | // Sent here to die? |
@@ -923,40 +985,48 @@ discard block |
||
| 923 | 985 | foreach ($files as $k => $file) |
| 924 | 986 | { |
| 925 | 987 | // If this file doesn't exist, then we actually want to look at the directory, no? |
| 926 | - if (!file_exists($file)) |
|
| 927 | - $file = dirname($file); |
|
| 988 | + if (!file_exists($file)) { |
|
| 989 | + $file = dirname($file); |
|
| 990 | + } |
|
| 928 | 991 | |
| 929 | 992 | // This looks odd, but it's an attempt to work around PHP suExec. |
| 930 | - if (!@is_writable($file)) |
|
| 931 | - smf_chmod($file, 0755); |
|
| 932 | - if (!@is_writable($file)) |
|
| 933 | - smf_chmod($file, 0777); |
|
| 934 | - if (!@is_writable(dirname($file))) |
|
| 935 | - smf_chmod($file, 0755); |
|
| 936 | - if (!@is_writable(dirname($file))) |
|
| 937 | - smf_chmod($file, 0777); |
|
| 993 | + if (!@is_writable($file)) { |
|
| 994 | + smf_chmod($file, 0755); |
|
| 995 | + } |
|
| 996 | + if (!@is_writable($file)) { |
|
| 997 | + smf_chmod($file, 0777); |
|
| 998 | + } |
|
| 999 | + if (!@is_writable(dirname($file))) { |
|
| 1000 | + smf_chmod($file, 0755); |
|
| 1001 | + } |
|
| 1002 | + if (!@is_writable(dirname($file))) { |
|
| 1003 | + smf_chmod($file, 0777); |
|
| 1004 | + } |
|
| 938 | 1005 | |
| 939 | 1006 | $fp = is_dir($file) ? @opendir($file) : @fopen($file, 'rb'); |
| 940 | 1007 | if (@is_writable($file) && $fp) |
| 941 | 1008 | { |
| 942 | 1009 | unset($files[$k]); |
| 943 | - if (!is_dir($file)) |
|
| 944 | - fclose($fp); |
|
| 945 | - else |
|
| 946 | - closedir($fp); |
|
| 1010 | + if (!is_dir($file)) { |
|
| 1011 | + fclose($fp); |
|
| 1012 | + } else { |
|
| 1013 | + closedir($fp); |
|
| 1014 | + } |
|
| 947 | 1015 | } |
| 948 | 1016 | } |
| 949 | 1017 | |
| 950 | 1018 | // No FTP required! |
| 951 | - if (empty($files)) |
|
| 952 | - return array(); |
|
| 1019 | + if (empty($files)) { |
|
| 1020 | + return array(); |
|
| 1021 | + } |
|
| 953 | 1022 | } |
| 954 | 1023 | |
| 955 | 1024 | // They've opted to not use FTP, and try anyway. |
| 956 | 1025 | if (isset($_SESSION['pack_ftp']) && $_SESSION['pack_ftp'] == false) |
| 957 | 1026 | { |
| 958 | - if ($files === null) |
|
| 959 | - return array(); |
|
| 1027 | + if ($files === null) { |
|
| 1028 | + return array(); |
|
| 1029 | + } |
|
| 960 | 1030 | |
| 961 | 1031 | foreach ($files as $k => $file) |
| 962 | 1032 | { |
@@ -968,26 +1038,29 @@ discard block |
||
| 968 | 1038 | smf_chmod($file, 0755); |
| 969 | 1039 | } |
| 970 | 1040 | |
| 971 | - if (!@is_writable($file)) |
|
| 972 | - smf_chmod($file, 0777); |
|
| 973 | - if (!@is_writable(dirname($file))) |
|
| 974 | - smf_chmod(dirname($file), 0777); |
|
| 1041 | + if (!@is_writable($file)) { |
|
| 1042 | + smf_chmod($file, 0777); |
|
| 1043 | + } |
|
| 1044 | + if (!@is_writable(dirname($file))) { |
|
| 1045 | + smf_chmod(dirname($file), 0777); |
|
| 1046 | + } |
|
| 975 | 1047 | |
| 976 | - if (@is_writable($file)) |
|
| 977 | - unset($files[$k]); |
|
| 1048 | + if (@is_writable($file)) { |
|
| 1049 | + unset($files[$k]); |
|
| 1050 | + } |
|
| 978 | 1051 | } |
| 979 | 1052 | |
| 980 | 1053 | return $files; |
| 981 | - } |
|
| 982 | - elseif (isset($_SESSION['pack_ftp'])) |
|
| 1054 | + } elseif (isset($_SESSION['pack_ftp'])) |
|
| 983 | 1055 | { |
| 984 | 1056 | // Load the file containing the ftp_connection class. |
| 985 | 1057 | require_once($sourcedir . '/Class-Package.php'); |
| 986 | 1058 | |
| 987 | 1059 | $package_ftp = new ftp_connection($_SESSION['pack_ftp']['server'], $_SESSION['pack_ftp']['port'], $_SESSION['pack_ftp']['username'], package_crypt($_SESSION['pack_ftp']['password'])); |
| 988 | 1060 | |
| 989 | - if ($files === null) |
|
| 990 | - return array(); |
|
| 1061 | + if ($files === null) { |
|
| 1062 | + return array(); |
|
| 1063 | + } |
|
| 991 | 1064 | |
| 992 | 1065 | foreach ($files as $k => $file) |
| 993 | 1066 | { |
@@ -1001,13 +1074,16 @@ discard block |
||
| 1001 | 1074 | $package_ftp->chmod($ftp_file, 0755); |
| 1002 | 1075 | } |
| 1003 | 1076 | |
| 1004 | - if (!@is_writable($file)) |
|
| 1005 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 1006 | - if (!@is_writable(dirname($file))) |
|
| 1007 | - $package_ftp->chmod(dirname($ftp_file), 0777); |
|
| 1077 | + if (!@is_writable($file)) { |
|
| 1078 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 1079 | + } |
|
| 1080 | + if (!@is_writable(dirname($file))) { |
|
| 1081 | + $package_ftp->chmod(dirname($ftp_file), 0777); |
|
| 1082 | + } |
|
| 1008 | 1083 | |
| 1009 | - if (@is_writable($file)) |
|
| 1010 | - unset($files[$k]); |
|
| 1084 | + if (@is_writable($file)) { |
|
| 1085 | + unset($files[$k]); |
|
| 1086 | + } |
|
| 1011 | 1087 | } |
| 1012 | 1088 | |
| 1013 | 1089 | return $files; |
@@ -1019,8 +1095,7 @@ discard block |
||
| 1019 | 1095 | |
| 1020 | 1096 | $files = packageRequireFTP($destination_url, $files, $return); |
| 1021 | 1097 | return $files; |
| 1022 | - } |
|
| 1023 | - elseif (isset($_POST['ftp_username'])) |
|
| 1098 | + } elseif (isset($_POST['ftp_username'])) |
|
| 1024 | 1099 | { |
| 1025 | 1100 | require_once($sourcedir . '/Class-Package.php'); |
| 1026 | 1101 | $ftp = new ftp_connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']); |
@@ -1042,19 +1117,21 @@ discard block |
||
| 1042 | 1117 | { |
| 1043 | 1118 | require_once($sourcedir . '/Class-Package.php'); |
| 1044 | 1119 | $ftp = new ftp_connection(null); |
| 1120 | + } elseif ($ftp->error !== false && !isset($ftp_error)) { |
|
| 1121 | + $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 1045 | 1122 | } |
| 1046 | - elseif ($ftp->error !== false && !isset($ftp_error)) |
|
| 1047 | - $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 1048 | 1123 | |
| 1049 | 1124 | list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir); |
| 1050 | 1125 | |
| 1051 | - if ($found_path) |
|
| 1052 | - $_POST['ftp_path'] = $detect_path; |
|
| 1053 | - elseif (!isset($_POST['ftp_path'])) |
|
| 1054 | - $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
| 1126 | + if ($found_path) { |
|
| 1127 | + $_POST['ftp_path'] = $detect_path; |
|
| 1128 | + } elseif (!isset($_POST['ftp_path'])) { |
|
| 1129 | + $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
| 1130 | + } |
|
| 1055 | 1131 | |
| 1056 | - if (!isset($_POST['ftp_username'])) |
|
| 1057 | - $_POST['ftp_username'] = $username; |
|
| 1132 | + if (!isset($_POST['ftp_username'])) { |
|
| 1133 | + $_POST['ftp_username'] = $username; |
|
| 1134 | + } |
|
| 1058 | 1135 | |
| 1059 | 1136 | $context['package_ftp'] = array( |
| 1060 | 1137 | 'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'), |
@@ -1066,23 +1143,24 @@ discard block |
||
| 1066 | 1143 | ); |
| 1067 | 1144 | |
| 1068 | 1145 | // If we're returning dump out here. |
| 1069 | - if ($return) |
|
| 1070 | - return $files; |
|
| 1146 | + if ($return) { |
|
| 1147 | + return $files; |
|
| 1148 | + } |
|
| 1071 | 1149 | |
| 1072 | 1150 | $context['page_title'] = $txt['package_ftp_necessary']; |
| 1073 | 1151 | $context['sub_template'] = 'ftp_required'; |
| 1074 | 1152 | obExit(); |
| 1075 | - } |
|
| 1076 | - else |
|
| 1153 | + } else |
|
| 1077 | 1154 | { |
| 1078 | 1155 | if (!in_array($_POST['ftp_path'], array('', '/'))) |
| 1079 | 1156 | { |
| 1080 | 1157 | $ftp_root = strtr($boarddir, array($_POST['ftp_path'] => '')); |
| 1081 | - if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/')) |
|
| 1082 | - $ftp_root = substr($ftp_root, 0, -1); |
|
| 1158 | + if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/')) { |
|
| 1159 | + $ftp_root = substr($ftp_root, 0, -1); |
|
| 1160 | + } |
|
| 1161 | + } else { |
|
| 1162 | + $ftp_root = $boarddir; |
|
| 1083 | 1163 | } |
| 1084 | - else |
|
| 1085 | - $ftp_root = $boarddir; |
|
| 1086 | 1164 | |
| 1087 | 1165 | $_SESSION['pack_ftp'] = array( |
| 1088 | 1166 | 'server' => $_POST['ftp_server'], |
@@ -1093,8 +1171,9 @@ discard block |
||
| 1093 | 1171 | 'root' => $ftp_root, |
| 1094 | 1172 | ); |
| 1095 | 1173 | |
| 1096 | - if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) |
|
| 1097 | - updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
| 1174 | + if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) { |
|
| 1175 | + updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
| 1176 | + } |
|
| 1098 | 1177 | |
| 1099 | 1178 | $files = packageRequireFTP($destination_url, $files, $return); |
| 1100 | 1179 | } |
@@ -1122,16 +1201,18 @@ discard block |
||
| 1122 | 1201 | global $packagesdir, $forum_version, $context, $temp_path, $language, $smcFunc; |
| 1123 | 1202 | |
| 1124 | 1203 | // Mayday! That action doesn't exist!! |
| 1125 | - if (empty($packageXML) || !$packageXML->exists($method)) |
|
| 1126 | - return array(); |
|
| 1204 | + if (empty($packageXML) || !$packageXML->exists($method)) { |
|
| 1205 | + return array(); |
|
| 1206 | + } |
|
| 1127 | 1207 | |
| 1128 | 1208 | // We haven't found the package script yet... |
| 1129 | 1209 | $script = false; |
| 1130 | 1210 | $the_version = strtr($forum_version, array('SMF ' => '')); |
| 1131 | 1211 | |
| 1132 | 1212 | // Emulation support... |
| 1133 | - if (!empty($_SESSION['version_emulate'])) |
|
| 1134 | - $the_version = $_SESSION['version_emulate']; |
|
| 1213 | + if (!empty($_SESSION['version_emulate'])) { |
|
| 1214 | + $the_version = $_SESSION['version_emulate']; |
|
| 1215 | + } |
|
| 1135 | 1216 | |
| 1136 | 1217 | // Single package emulation |
| 1137 | 1218 | if (!empty($_REQUEST['ve']) && !empty($_REQUEST['package'])) |
@@ -1139,8 +1220,9 @@ discard block |
||
| 1139 | 1220 | $the_version = $_REQUEST['ve']; |
| 1140 | 1221 | $_SESSION['single_version_emulate'][$_REQUEST['package']] = $the_version; |
| 1141 | 1222 | } |
| 1142 | - if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']]))) |
|
| 1143 | - $the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']]; |
|
| 1223 | + if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']]))) { |
|
| 1224 | + $the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']]; |
|
| 1225 | + } |
|
| 1144 | 1226 | |
| 1145 | 1227 | // Get all the versions of this method and find the right one. |
| 1146 | 1228 | $these_methods = $packageXML->set($method); |
@@ -1150,16 +1232,18 @@ discard block |
||
| 1150 | 1232 | if ($this_method->exists('@for')) |
| 1151 | 1233 | { |
| 1152 | 1234 | // Don't keep going if this won't work for this version of SMF. |
| 1153 | - if (!matchPackageVersion($the_version, $this_method->fetch('@for'))) |
|
| 1154 | - continue; |
|
| 1235 | + if (!matchPackageVersion($the_version, $this_method->fetch('@for'))) { |
|
| 1236 | + continue; |
|
| 1237 | + } |
|
| 1155 | 1238 | } |
| 1156 | 1239 | |
| 1157 | 1240 | // Upgrades may go from a certain old version of the mod. |
| 1158 | 1241 | if ($method == 'upgrade' && $this_method->exists('@from')) |
| 1159 | 1242 | { |
| 1160 | 1243 | // Well, this is for the wrong old version... |
| 1161 | - if (!matchPackageVersion($previous_version, $this_method->fetch('@from'))) |
|
| 1162 | - continue; |
|
| 1244 | + if (!matchPackageVersion($previous_version, $this_method->fetch('@from'))) { |
|
| 1245 | + continue; |
|
| 1246 | + } |
|
| 1163 | 1247 | } |
| 1164 | 1248 | |
| 1165 | 1249 | // We've found it! |
@@ -1168,8 +1252,9 @@ discard block |
||
| 1168 | 1252 | } |
| 1169 | 1253 | |
| 1170 | 1254 | // Bad news, a matching script wasn't found! |
| 1171 | - if ($script === false) |
|
| 1172 | - return array(); |
|
| 1255 | + if ($script === false) { |
|
| 1256 | + return array(); |
|
| 1257 | + } |
|
| 1173 | 1258 | |
| 1174 | 1259 | // Find all the actions in this method - in theory, these should only be allowed actions. (* means all.) |
| 1175 | 1260 | $actions = $script->set('*'); |
@@ -1198,12 +1283,12 @@ discard block |
||
| 1198 | 1283 | if ((isset($_REQUEST['readme']) && $action->fetch('@lang') == $_REQUEST['readme']) || (isset($_REQUEST['license']) && $action->fetch('@lang') == $_REQUEST['license']) || (!isset($_REQUEST['readme']) && $action->fetch('@lang') == $language) || (!isset($_REQUEST['license']) && $action->fetch('@lang') == $language)) |
| 1199 | 1284 | { |
| 1200 | 1285 | // In case the user put the blocks in the wrong order. |
| 1201 | - if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default') |
|
| 1202 | - $context[$type][] = 'default'; |
|
| 1286 | + if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default') { |
|
| 1287 | + $context[$type][] = 'default'; |
|
| 1288 | + } |
|
| 1203 | 1289 | |
| 1204 | 1290 | $context[$type]['selected'] = $smcFunc['htmlspecialchars']($action->fetch('@lang')); |
| 1205 | - } |
|
| 1206 | - else |
|
| 1291 | + } else |
|
| 1207 | 1292 | { |
| 1208 | 1293 | // We don't want this now, but we'll allow the user to select to read it. |
| 1209 | 1294 | $context[$type][] = $smcFunc['htmlspecialchars']($action->fetch('@lang')); |
@@ -1218,9 +1303,9 @@ discard block |
||
| 1218 | 1303 | { |
| 1219 | 1304 | $context[$type][] = 'default'; |
| 1220 | 1305 | continue; |
| 1306 | + } else { |
|
| 1307 | + $context[$type]['selected'] = 'default'; |
|
| 1221 | 1308 | } |
| 1222 | - else |
|
| 1223 | - $context[$type]['selected'] = 'default'; |
|
| 1224 | 1309 | } |
| 1225 | 1310 | } |
| 1226 | 1311 | |
@@ -1230,9 +1315,9 @@ discard block |
||
| 1230 | 1315 | $filename = $temp_path . '$auto_' . $temp_auto++ . (in_array($actionType, array('readme', 'redirect', 'license')) ? '.txt' : ($actionType == 'code' || $actionType == 'database' ? '.php' : '.mod')); |
| 1231 | 1316 | package_put_contents($filename, $action->fetch('.')); |
| 1232 | 1317 | $filename = strtr($filename, array($temp_path => '')); |
| 1318 | + } else { |
|
| 1319 | + $filename = $action->fetch('.'); |
|
| 1233 | 1320 | } |
| 1234 | - else |
|
| 1235 | - $filename = $action->fetch('.'); |
|
| 1236 | 1321 | |
| 1237 | 1322 | $return[] = array( |
| 1238 | 1323 | 'type' => $actionType, |
@@ -1247,8 +1332,7 @@ discard block |
||
| 1247 | 1332 | ); |
| 1248 | 1333 | |
| 1249 | 1334 | continue; |
| 1250 | - } |
|
| 1251 | - elseif ($actionType == 'hook') |
|
| 1335 | + } elseif ($actionType == 'hook') |
|
| 1252 | 1336 | { |
| 1253 | 1337 | $return[] = array( |
| 1254 | 1338 | 'type' => $actionType, |
@@ -1260,16 +1344,16 @@ discard block |
||
| 1260 | 1344 | 'description' => '', |
| 1261 | 1345 | ); |
| 1262 | 1346 | continue; |
| 1263 | - } |
|
| 1264 | - elseif ($actionType == 'credits') |
|
| 1347 | + } elseif ($actionType == 'credits') |
|
| 1265 | 1348 | { |
| 1266 | 1349 | // quick check of any supplied url |
| 1267 | 1350 | $url = $action->exists('@url') ? $action->fetch('@url') : ''; |
| 1268 | 1351 | if (strlen(trim($url)) > 0 && substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://') |
| 1269 | 1352 | { |
| 1270 | 1353 | $url = 'http://' . $url; |
| 1271 | - if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')) |
|
| 1272 | - $url = ''; |
|
| 1354 | + if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')) { |
|
| 1355 | + $url = ''; |
|
| 1356 | + } |
|
| 1273 | 1357 | } |
| 1274 | 1358 | |
| 1275 | 1359 | $return[] = array( |
@@ -1281,8 +1365,7 @@ discard block |
||
| 1281 | 1365 | 'title' => $action->fetch('.'), |
| 1282 | 1366 | ); |
| 1283 | 1367 | continue; |
| 1284 | - } |
|
| 1285 | - elseif ($actionType == 'requires') |
|
| 1368 | + } elseif ($actionType == 'requires') |
|
| 1286 | 1369 | { |
| 1287 | 1370 | $return[] = array( |
| 1288 | 1371 | 'type' => $actionType, |
@@ -1291,14 +1374,12 @@ discard block |
||
| 1291 | 1374 | 'description' => '', |
| 1292 | 1375 | ); |
| 1293 | 1376 | continue; |
| 1294 | - } |
|
| 1295 | - elseif ($actionType == 'error') |
|
| 1377 | + } elseif ($actionType == 'error') |
|
| 1296 | 1378 | { |
| 1297 | 1379 | $return[] = array( |
| 1298 | 1380 | 'type' => 'error', |
| 1299 | 1381 | ); |
| 1300 | - } |
|
| 1301 | - elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir'))) |
|
| 1382 | + } elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir'))) |
|
| 1302 | 1383 | { |
| 1303 | 1384 | $this_action = &$return[]; |
| 1304 | 1385 | $this_action = array( |
@@ -1312,8 +1393,7 @@ discard block |
||
| 1312 | 1393 | { |
| 1313 | 1394 | $this_action['unparsed_destination'] = $action->fetch('@destination'); |
| 1314 | 1395 | $this_action['destination'] = parse_path($action->fetch('@destination')) . '/' . basename($this_action['filename']); |
| 1315 | - } |
|
| 1316 | - else |
|
| 1396 | + } else |
|
| 1317 | 1397 | { |
| 1318 | 1398 | $this_action['unparsed_filename'] = $this_action['filename']; |
| 1319 | 1399 | $this_action['filename'] = parse_path($this_action['filename']); |
@@ -1322,10 +1402,11 @@ discard block |
||
| 1322 | 1402 | // If we're moving or requiring (copying) a file. |
| 1323 | 1403 | if (substr($actionType, 0, 4) == 'move' || substr($actionType, 0, 7) == 'require') |
| 1324 | 1404 | { |
| 1325 | - if ($action->exists('@from')) |
|
| 1326 | - $this_action['source'] = parse_path($action->fetch('@from')); |
|
| 1327 | - else |
|
| 1328 | - $this_action['source'] = $temp_path . $this_action['filename']; |
|
| 1405 | + if ($action->exists('@from')) { |
|
| 1406 | + $this_action['source'] = parse_path($action->fetch('@from')); |
|
| 1407 | + } else { |
|
| 1408 | + $this_action['source'] = $temp_path . $this_action['filename']; |
|
| 1409 | + } |
|
| 1329 | 1410 | } |
| 1330 | 1411 | |
| 1331 | 1412 | // Check if these things can be done. (chmod's etc.) |
@@ -1334,22 +1415,23 @@ discard block |
||
| 1334 | 1415 | if (!mktree($this_action['destination'], false)) |
| 1335 | 1416 | { |
| 1336 | 1417 | $temp = $this_action['destination']; |
| 1337 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1338 | - $temp = dirname($temp); |
|
| 1418 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1419 | + $temp = dirname($temp); |
|
| 1420 | + } |
|
| 1339 | 1421 | |
| 1340 | 1422 | $return[] = array( |
| 1341 | 1423 | 'type' => 'chmod', |
| 1342 | 1424 | 'filename' => $temp |
| 1343 | 1425 | ); |
| 1344 | 1426 | } |
| 1345 | - } |
|
| 1346 | - elseif ($actionType == 'create-file') |
|
| 1427 | + } elseif ($actionType == 'create-file') |
|
| 1347 | 1428 | { |
| 1348 | 1429 | if (!mktree(dirname($this_action['destination']), false)) |
| 1349 | 1430 | { |
| 1350 | 1431 | $temp = dirname($this_action['destination']); |
| 1351 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1352 | - $temp = dirname($temp); |
|
| 1432 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1433 | + $temp = dirname($temp); |
|
| 1434 | + } |
|
| 1353 | 1435 | |
| 1354 | 1436 | $return[] = array( |
| 1355 | 1437 | 'type' => 'chmod', |
@@ -1357,36 +1439,38 @@ discard block |
||
| 1357 | 1439 | ); |
| 1358 | 1440 | } |
| 1359 | 1441 | |
| 1360 | - if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) |
|
| 1361 | - $return[] = array( |
|
| 1442 | + if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) { |
|
| 1443 | + $return[] = array( |
|
| 1362 | 1444 | 'type' => 'chmod', |
| 1363 | 1445 | 'filename' => $this_action['destination'] |
| 1364 | 1446 | ); |
| 1365 | - } |
|
| 1366 | - elseif ($actionType == 'require-dir') |
|
| 1447 | + } |
|
| 1448 | + } elseif ($actionType == 'require-dir') |
|
| 1367 | 1449 | { |
| 1368 | 1450 | if (!mktree($this_action['destination'], false)) |
| 1369 | 1451 | { |
| 1370 | 1452 | $temp = $this_action['destination']; |
| 1371 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1372 | - $temp = dirname($temp); |
|
| 1453 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1454 | + $temp = dirname($temp); |
|
| 1455 | + } |
|
| 1373 | 1456 | |
| 1374 | 1457 | $return[] = array( |
| 1375 | 1458 | 'type' => 'chmod', |
| 1376 | 1459 | 'filename' => $temp |
| 1377 | 1460 | ); |
| 1378 | 1461 | } |
| 1379 | - } |
|
| 1380 | - elseif ($actionType == 'require-file') |
|
| 1462 | + } elseif ($actionType == 'require-file') |
|
| 1381 | 1463 | { |
| 1382 | - if ($action->exists('@theme')) |
|
| 1383 | - $this_action['theme_action'] = $action->fetch('@theme'); |
|
| 1464 | + if ($action->exists('@theme')) { |
|
| 1465 | + $this_action['theme_action'] = $action->fetch('@theme'); |
|
| 1466 | + } |
|
| 1384 | 1467 | |
| 1385 | 1468 | if (!mktree(dirname($this_action['destination']), false)) |
| 1386 | 1469 | { |
| 1387 | 1470 | $temp = dirname($this_action['destination']); |
| 1388 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1389 | - $temp = dirname($temp); |
|
| 1471 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1472 | + $temp = dirname($temp); |
|
| 1473 | + } |
|
| 1390 | 1474 | |
| 1391 | 1475 | $return[] = array( |
| 1392 | 1476 | 'type' => 'chmod', |
@@ -1394,19 +1478,20 @@ discard block |
||
| 1394 | 1478 | ); |
| 1395 | 1479 | } |
| 1396 | 1480 | |
| 1397 | - if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) |
|
| 1398 | - $return[] = array( |
|
| 1481 | + if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) { |
|
| 1482 | + $return[] = array( |
|
| 1399 | 1483 | 'type' => 'chmod', |
| 1400 | 1484 | 'filename' => $this_action['destination'] |
| 1401 | 1485 | ); |
| 1402 | - } |
|
| 1403 | - elseif ($actionType == 'move-dir' || $actionType == 'move-file') |
|
| 1486 | + } |
|
| 1487 | + } elseif ($actionType == 'move-dir' || $actionType == 'move-file') |
|
| 1404 | 1488 | { |
| 1405 | 1489 | if (!mktree(dirname($this_action['destination']), false)) |
| 1406 | 1490 | { |
| 1407 | 1491 | $temp = dirname($this_action['destination']); |
| 1408 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1409 | - $temp = dirname($temp); |
|
| 1492 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1493 | + $temp = dirname($temp); |
|
| 1494 | + } |
|
| 1410 | 1495 | |
| 1411 | 1496 | $return[] = array( |
| 1412 | 1497 | 'type' => 'chmod', |
@@ -1414,30 +1499,30 @@ discard block |
||
| 1414 | 1499 | ); |
| 1415 | 1500 | } |
| 1416 | 1501 | |
| 1417 | - if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) |
|
| 1418 | - $return[] = array( |
|
| 1502 | + if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) { |
|
| 1503 | + $return[] = array( |
|
| 1419 | 1504 | 'type' => 'chmod', |
| 1420 | 1505 | 'filename' => $this_action['destination'] |
| 1421 | 1506 | ); |
| 1422 | - } |
|
| 1423 | - elseif ($actionType == 'remove-dir') |
|
| 1507 | + } |
|
| 1508 | + } elseif ($actionType == 'remove-dir') |
|
| 1424 | 1509 | { |
| 1425 | - if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) |
|
| 1426 | - $return[] = array( |
|
| 1510 | + if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) { |
|
| 1511 | + $return[] = array( |
|
| 1427 | 1512 | 'type' => 'chmod', |
| 1428 | 1513 | 'filename' => $this_action['filename'] |
| 1429 | 1514 | ); |
| 1430 | - } |
|
| 1431 | - elseif ($actionType == 'remove-file') |
|
| 1515 | + } |
|
| 1516 | + } elseif ($actionType == 'remove-file') |
|
| 1432 | 1517 | { |
| 1433 | - if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) |
|
| 1434 | - $return[] = array( |
|
| 1518 | + if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) { |
|
| 1519 | + $return[] = array( |
|
| 1435 | 1520 | 'type' => 'chmod', |
| 1436 | 1521 | 'filename' => $this_action['filename'] |
| 1437 | 1522 | ); |
| 1523 | + } |
|
| 1438 | 1524 | } |
| 1439 | - } |
|
| 1440 | - else |
|
| 1525 | + } else |
|
| 1441 | 1526 | { |
| 1442 | 1527 | $return[] = array( |
| 1443 | 1528 | 'type' => 'error', |
@@ -1448,8 +1533,9 @@ discard block |
||
| 1448 | 1533 | } |
| 1449 | 1534 | |
| 1450 | 1535 | // Only testing - just return a list of things to be done. |
| 1451 | - if ($testing_only) |
|
| 1452 | - return $return; |
|
| 1536 | + if ($testing_only) { |
|
| 1537 | + return $return; |
|
| 1538 | + } |
|
| 1453 | 1539 | |
| 1454 | 1540 | umask(0); |
| 1455 | 1541 | |
@@ -1457,78 +1543,81 @@ discard block |
||
| 1457 | 1543 | $not_done = array(array('type' => '!')); |
| 1458 | 1544 | foreach ($return as $action) |
| 1459 | 1545 | { |
| 1460 | - if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits'))) |
|
| 1461 | - $not_done[] = $action; |
|
| 1546 | + if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits'))) { |
|
| 1547 | + $not_done[] = $action; |
|
| 1548 | + } |
|
| 1462 | 1549 | |
| 1463 | 1550 | if ($action['type'] == 'create-dir') |
| 1464 | 1551 | { |
| 1465 | - if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) |
|
| 1466 | - $failure |= !mktree($action['destination'], 0777); |
|
| 1467 | - } |
|
| 1468 | - elseif ($action['type'] == 'create-file') |
|
| 1552 | + if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) { |
|
| 1553 | + $failure |= !mktree($action['destination'], 0777); |
|
| 1554 | + } |
|
| 1555 | + } elseif ($action['type'] == 'create-file') |
|
| 1469 | 1556 | { |
| 1470 | - if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) |
|
| 1471 | - $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1557 | + if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) { |
|
| 1558 | + $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1559 | + } |
|
| 1472 | 1560 | |
| 1473 | 1561 | // Create an empty file. |
| 1474 | 1562 | package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only); |
| 1475 | 1563 | |
| 1476 | - if (!file_exists($action['destination'])) |
|
| 1477 | - $failure = true; |
|
| 1478 | - } |
|
| 1479 | - elseif ($action['type'] == 'require-dir') |
|
| 1564 | + if (!file_exists($action['destination'])) { |
|
| 1565 | + $failure = true; |
|
| 1566 | + } |
|
| 1567 | + } elseif ($action['type'] == 'require-dir') |
|
| 1480 | 1568 | { |
| 1481 | 1569 | copytree($action['source'], $action['destination']); |
| 1482 | 1570 | // Any other theme folders? |
| 1483 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) |
|
| 1484 | - foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
| 1571 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) { |
|
| 1572 | + foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
| 1485 | 1573 | copytree($action['source'], $theme_destination); |
| 1486 | - } |
|
| 1487 | - elseif ($action['type'] == 'require-file') |
|
| 1574 | + } |
|
| 1575 | + } elseif ($action['type'] == 'require-file') |
|
| 1488 | 1576 | { |
| 1489 | - if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) |
|
| 1490 | - $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1577 | + if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) { |
|
| 1578 | + $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1579 | + } |
|
| 1491 | 1580 | |
| 1492 | 1581 | package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only); |
| 1493 | 1582 | |
| 1494 | 1583 | $failure |= !copy($action['source'], $action['destination']); |
| 1495 | 1584 | |
| 1496 | 1585 | // Any other theme files? |
| 1497 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) |
|
| 1498 | - foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
| 1586 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) { |
|
| 1587 | + foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
| 1499 | 1588 | { |
| 1500 | 1589 | if (!mktree(dirname($theme_destination), 0755) || !is_writable(dirname($theme_destination))) |
| 1501 | 1590 | $failure |= !mktree(dirname($theme_destination), 0777); |
| 1591 | + } |
|
| 1502 | 1592 | |
| 1503 | 1593 | package_put_contents($theme_destination, package_get_contents($action['source']), $testing_only); |
| 1504 | 1594 | |
| 1505 | 1595 | $failure |= !copy($action['source'], $theme_destination); |
| 1506 | 1596 | } |
| 1507 | - } |
|
| 1508 | - elseif ($action['type'] == 'move-file') |
|
| 1597 | + } elseif ($action['type'] == 'move-file') |
|
| 1509 | 1598 | { |
| 1510 | - if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) |
|
| 1511 | - $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1599 | + if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) { |
|
| 1600 | + $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1601 | + } |
|
| 1512 | 1602 | |
| 1513 | 1603 | $failure |= !rename($action['source'], $action['destination']); |
| 1514 | - } |
|
| 1515 | - elseif ($action['type'] == 'move-dir') |
|
| 1604 | + } elseif ($action['type'] == 'move-dir') |
|
| 1516 | 1605 | { |
| 1517 | - if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) |
|
| 1518 | - $failure |= !mktree($action['destination'], 0777); |
|
| 1606 | + if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) { |
|
| 1607 | + $failure |= !mktree($action['destination'], 0777); |
|
| 1608 | + } |
|
| 1519 | 1609 | |
| 1520 | 1610 | $failure |= !rename($action['source'], $action['destination']); |
| 1521 | - } |
|
| 1522 | - elseif ($action['type'] == 'remove-dir') |
|
| 1611 | + } elseif ($action['type'] == 'remove-dir') |
|
| 1523 | 1612 | { |
| 1524 | 1613 | deltree($action['filename']); |
| 1525 | 1614 | |
| 1526 | 1615 | // Any other theme folders? |
| 1527 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) |
|
| 1528 | - foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
| 1616 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) { |
|
| 1617 | + foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
| 1529 | 1618 | deltree($theme_destination); |
| 1530 | - } |
|
| 1531 | - elseif ($action['type'] == 'remove-file') |
|
| 1619 | + } |
|
| 1620 | + } elseif ($action['type'] == 'remove-file') |
|
| 1532 | 1621 | { |
| 1533 | 1622 | // Make sure the file exists before deleting it. |
| 1534 | 1623 | if (file_exists($action['filename'])) |
@@ -1537,16 +1626,18 @@ discard block |
||
| 1537 | 1626 | $failure |= !unlink($action['filename']); |
| 1538 | 1627 | } |
| 1539 | 1628 | // The file that was supposed to be deleted couldn't be found. |
| 1540 | - else |
|
| 1541 | - $failure = true; |
|
| 1629 | + else { |
|
| 1630 | + $failure = true; |
|
| 1631 | + } |
|
| 1542 | 1632 | |
| 1543 | 1633 | // Any other theme folders? |
| 1544 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) |
|
| 1545 | - foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
| 1634 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) { |
|
| 1635 | + foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
| 1546 | 1636 | if (file_exists($theme_destination)) |
| 1547 | 1637 | $failure |= !unlink($theme_destination); |
| 1548 | - else |
|
| 1549 | - $failure = true; |
|
| 1638 | + } else { |
|
| 1639 | + $failure = true; |
|
| 1640 | + } |
|
| 1550 | 1641 | } |
| 1551 | 1642 | } |
| 1552 | 1643 | |
@@ -1568,8 +1659,9 @@ discard block |
||
| 1568 | 1659 | { |
| 1569 | 1660 | static $near_version = 0; |
| 1570 | 1661 | |
| 1571 | - if ($reset) |
|
| 1572 | - $near_version = 0; |
|
| 1662 | + if ($reset) { |
|
| 1663 | + $near_version = 0; |
|
| 1664 | + } |
|
| 1573 | 1665 | |
| 1574 | 1666 | // Normalize the $versions while we remove our previous Doh! |
| 1575 | 1667 | $versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions))); |
@@ -1578,16 +1670,19 @@ discard block |
||
| 1578 | 1670 | foreach ($versions as $for) |
| 1579 | 1671 | { |
| 1580 | 1672 | // Adjust for those wild cards |
| 1581 | - if (strpos($for, '*') !== false) |
|
| 1582 | - $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
| 1673 | + if (strpos($for, '*') !== false) { |
|
| 1674 | + $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
| 1675 | + } |
|
| 1583 | 1676 | |
| 1584 | 1677 | // If we have a range, grab the lower value, done this way so it looks normal-er to the user e.g. 2.0 vs 2.0.99 |
| 1585 | - if (strpos($for, '-') !== false) |
|
| 1586 | - list ($for, $higher) = explode('-', $for); |
|
| 1678 | + if (strpos($for, '-') !== false) { |
|
| 1679 | + list ($for, $higher) = explode('-', $for); |
|
| 1680 | + } |
|
| 1587 | 1681 | |
| 1588 | 1682 | // Do the compare, if the for is greater, than what we have but not greater than what we are running ..... |
| 1589 | - if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1) |
|
| 1590 | - $near_version = $for; |
|
| 1683 | + if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1) { |
|
| 1684 | + $near_version = $for; |
|
| 1685 | + } |
|
| 1591 | 1686 | } |
| 1592 | 1687 | |
| 1593 | 1688 | return !empty($near_version) ? $near_version : false; |
@@ -1610,15 +1705,17 @@ discard block |
||
| 1610 | 1705 | $versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions))); |
| 1611 | 1706 | |
| 1612 | 1707 | // Perhaps we do accept anything? |
| 1613 | - if (in_array('all', $versions)) |
|
| 1614 | - return true; |
|
| 1708 | + if (in_array('all', $versions)) { |
|
| 1709 | + return true; |
|
| 1710 | + } |
|
| 1615 | 1711 | |
| 1616 | 1712 | // Loop through each version. |
| 1617 | 1713 | foreach ($versions as $for) |
| 1618 | 1714 | { |
| 1619 | 1715 | // Wild card spotted? |
| 1620 | - if (strpos($for, '*') !== false) |
|
| 1621 | - $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
| 1716 | + if (strpos($for, '*') !== false) { |
|
| 1717 | + $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
| 1718 | + } |
|
| 1622 | 1719 | |
| 1623 | 1720 | // Do we have a range? |
| 1624 | 1721 | if (strpos($for, '-') !== false) |
@@ -1626,12 +1723,14 @@ discard block |
||
| 1626 | 1723 | list ($lower, $upper) = explode('-', $for); |
| 1627 | 1724 | |
| 1628 | 1725 | // Compare the version against lower and upper bounds. |
| 1629 | - if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1) |
|
| 1630 | - return true; |
|
| 1726 | + if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1) { |
|
| 1727 | + return true; |
|
| 1728 | + } |
|
| 1631 | 1729 | } |
| 1632 | 1730 | // Otherwise check if they are equal... |
| 1633 | - elseif (compareVersions($version, $for) === 0) |
|
| 1634 | - return true; |
|
| 1731 | + elseif (compareVersions($version, $for) === 0) { |
|
| 1732 | + return true; |
|
| 1733 | + } |
|
| 1635 | 1734 | } |
| 1636 | 1735 | |
| 1637 | 1736 | return false; |
@@ -1671,12 +1770,14 @@ discard block |
||
| 1671 | 1770 | } |
| 1672 | 1771 | |
| 1673 | 1772 | // Are they the same, perhaps? |
| 1674 | - if ($versions[1] === $versions[2]) |
|
| 1675 | - return 0; |
|
| 1773 | + if ($versions[1] === $versions[2]) { |
|
| 1774 | + return 0; |
|
| 1775 | + } |
|
| 1676 | 1776 | |
| 1677 | 1777 | // Get version numbering categories... |
| 1678 | - if (!isset($categories)) |
|
| 1679 | - $categories = array_keys($versions[1]); |
|
| 1778 | + if (!isset($categories)) { |
|
| 1779 | + $categories = array_keys($versions[1]); |
|
| 1780 | + } |
|
| 1680 | 1781 | |
| 1681 | 1782 | // Loop through each category. |
| 1682 | 1783 | foreach ($categories as $category) |
@@ -1686,13 +1787,15 @@ discard block |
||
| 1686 | 1787 | { |
| 1687 | 1788 | // Dev builds are a problematic exception. |
| 1688 | 1789 | // (stable) dev < (stable) but (unstable) dev = (unstable) |
| 1689 | - if ($category == 'type') |
|
| 1690 | - return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1); |
|
| 1691 | - elseif ($category == 'dev') |
|
| 1692 | - return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0); |
|
| 1790 | + if ($category == 'type') { |
|
| 1791 | + return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1); |
|
| 1792 | + } elseif ($category == 'dev') { |
|
| 1793 | + return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0); |
|
| 1794 | + } |
|
| 1693 | 1795 | // Otherwise a simple comparison. |
| 1694 | - else |
|
| 1695 | - return $versions[1][$category] > $versions[2][$category] ? 1 : -1; |
|
| 1796 | + else { |
|
| 1797 | + return $versions[1][$category] > $versions[2][$category] ? 1 : -1; |
|
| 1798 | + } |
|
| 1696 | 1799 | } |
| 1697 | 1800 | } |
| 1698 | 1801 | |
@@ -1726,11 +1829,13 @@ discard block |
||
| 1726 | 1829 | ); |
| 1727 | 1830 | |
| 1728 | 1831 | // do we parse in a package directory? |
| 1729 | - if (!empty($temp_path)) |
|
| 1730 | - $dirs['$package'] = $temp_path; |
|
| 1832 | + if (!empty($temp_path)) { |
|
| 1833 | + $dirs['$package'] = $temp_path; |
|
| 1834 | + } |
|
| 1731 | 1835 | |
| 1732 | - if (strlen($path) == 0) |
|
| 1733 | - trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR); |
|
| 1836 | + if (strlen($path) == 0) { |
|
| 1837 | + trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR); |
|
| 1838 | + } |
|
| 1734 | 1839 | |
| 1735 | 1840 | return strtr($path, $dirs); |
| 1736 | 1841 | } |
@@ -1746,8 +1851,9 @@ discard block |
||
| 1746 | 1851 | { |
| 1747 | 1852 | global $package_ftp; |
| 1748 | 1853 | |
| 1749 | - if (!file_exists($dir)) |
|
| 1750 | - return; |
|
| 1854 | + if (!file_exists($dir)) { |
|
| 1855 | + return; |
|
| 1856 | + } |
|
| 1751 | 1857 | |
| 1752 | 1858 | $current_dir = @opendir($dir); |
| 1753 | 1859 | if ($current_dir == false) |
@@ -1755,8 +1861,9 @@ discard block |
||
| 1755 | 1861 | if ($delete_dir && isset($package_ftp)) |
| 1756 | 1862 | { |
| 1757 | 1863 | $ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => '')); |
| 1758 | - if (!is_dir($dir)) |
|
| 1759 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 1864 | + if (!is_dir($dir)) { |
|
| 1865 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 1866 | + } |
|
| 1760 | 1867 | $package_ftp->unlink($ftp_file); |
| 1761 | 1868 | } |
| 1762 | 1869 | |
@@ -1765,26 +1872,28 @@ discard block |
||
| 1765 | 1872 | |
| 1766 | 1873 | while ($entryname = readdir($current_dir)) |
| 1767 | 1874 | { |
| 1768 | - if (in_array($entryname, array('.', '..'))) |
|
| 1769 | - continue; |
|
| 1875 | + if (in_array($entryname, array('.', '..'))) { |
|
| 1876 | + continue; |
|
| 1877 | + } |
|
| 1770 | 1878 | |
| 1771 | - if (is_dir($dir . '/' . $entryname)) |
|
| 1772 | - deltree($dir . '/' . $entryname); |
|
| 1773 | - else |
|
| 1879 | + if (is_dir($dir . '/' . $entryname)) { |
|
| 1880 | + deltree($dir . '/' . $entryname); |
|
| 1881 | + } else |
|
| 1774 | 1882 | { |
| 1775 | 1883 | // Here, 755 doesn't really matter since we're deleting it anyway. |
| 1776 | 1884 | if (isset($package_ftp)) |
| 1777 | 1885 | { |
| 1778 | 1886 | $ftp_file = strtr($dir . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => '')); |
| 1779 | 1887 | |
| 1780 | - if (!is_writable($dir . '/' . $entryname)) |
|
| 1781 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 1888 | + if (!is_writable($dir . '/' . $entryname)) { |
|
| 1889 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 1890 | + } |
|
| 1782 | 1891 | $package_ftp->unlink($ftp_file); |
| 1783 | - } |
|
| 1784 | - else |
|
| 1892 | + } else |
|
| 1785 | 1893 | { |
| 1786 | - if (!is_writable($dir . '/' . $entryname)) |
|
| 1787 | - smf_chmod($dir . '/' . $entryname, 0777); |
|
| 1894 | + if (!is_writable($dir . '/' . $entryname)) { |
|
| 1895 | + smf_chmod($dir . '/' . $entryname, 0777); |
|
| 1896 | + } |
|
| 1788 | 1897 | unlink($dir . '/' . $entryname); |
| 1789 | 1898 | } |
| 1790 | 1899 | } |
@@ -1797,14 +1906,15 @@ discard block |
||
| 1797 | 1906 | if (isset($package_ftp)) |
| 1798 | 1907 | { |
| 1799 | 1908 | $ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => '')); |
| 1800 | - if (!is_writable($dir . '/' . $entryname)) |
|
| 1801 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 1909 | + if (!is_writable($dir . '/' . $entryname)) { |
|
| 1910 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 1911 | + } |
|
| 1802 | 1912 | $package_ftp->unlink($ftp_file); |
| 1803 | - } |
|
| 1804 | - else |
|
| 1913 | + } else |
|
| 1805 | 1914 | { |
| 1806 | - if (!is_writable($dir)) |
|
| 1807 | - smf_chmod($dir, 0777); |
|
| 1915 | + if (!is_writable($dir)) { |
|
| 1916 | + smf_chmod($dir, 0777); |
|
| 1917 | + } |
|
| 1808 | 1918 | @rmdir($dir); |
| 1809 | 1919 | } |
| 1810 | 1920 | } |
@@ -1826,10 +1936,11 @@ discard block |
||
| 1826 | 1936 | { |
| 1827 | 1937 | if (!is_writable($strPath) && $mode !== false) |
| 1828 | 1938 | { |
| 1829 | - if (isset($package_ftp)) |
|
| 1830 | - $package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode); |
|
| 1831 | - else |
|
| 1832 | - smf_chmod($strPath, $mode); |
|
| 1939 | + if (isset($package_ftp)) { |
|
| 1940 | + $package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode); |
|
| 1941 | + } else { |
|
| 1942 | + smf_chmod($strPath, $mode); |
|
| 1943 | + } |
|
| 1833 | 1944 | } |
| 1834 | 1945 | |
| 1835 | 1946 | $test = @opendir($strPath); |
@@ -1837,36 +1948,37 @@ discard block |
||
| 1837 | 1948 | { |
| 1838 | 1949 | closedir($test); |
| 1839 | 1950 | return is_writable($strPath); |
| 1951 | + } else { |
|
| 1952 | + return false; |
|
| 1840 | 1953 | } |
| 1841 | - else |
|
| 1842 | - return false; |
|
| 1843 | 1954 | } |
| 1844 | 1955 | // Is this an invalid path and/or we can't make the directory? |
| 1845 | - if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode)) |
|
| 1846 | - return false; |
|
| 1956 | + if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode)) { |
|
| 1957 | + return false; |
|
| 1958 | + } |
|
| 1847 | 1959 | |
| 1848 | 1960 | if (!is_writable(dirname($strPath)) && $mode !== false) |
| 1849 | 1961 | { |
| 1850 | - if (isset($package_ftp)) |
|
| 1851 | - $package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode); |
|
| 1852 | - else |
|
| 1853 | - smf_chmod(dirname($strPath), $mode); |
|
| 1962 | + if (isset($package_ftp)) { |
|
| 1963 | + $package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode); |
|
| 1964 | + } else { |
|
| 1965 | + smf_chmod(dirname($strPath), $mode); |
|
| 1966 | + } |
|
| 1854 | 1967 | } |
| 1855 | 1968 | |
| 1856 | - if ($mode !== false && isset($package_ftp)) |
|
| 1857 | - return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))); |
|
| 1858 | - elseif ($mode === false) |
|
| 1969 | + if ($mode !== false && isset($package_ftp)) { |
|
| 1970 | + return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))); |
|
| 1971 | + } elseif ($mode === false) |
|
| 1859 | 1972 | { |
| 1860 | 1973 | $test = @opendir(dirname($strPath)); |
| 1861 | 1974 | if ($test) |
| 1862 | 1975 | { |
| 1863 | 1976 | closedir($test); |
| 1864 | 1977 | return true; |
| 1978 | + } else { |
|
| 1979 | + return false; |
|
| 1865 | 1980 | } |
| 1866 | - else |
|
| 1867 | - return false; |
|
| 1868 | - } |
|
| 1869 | - else |
|
| 1981 | + } else |
|
| 1870 | 1982 | { |
| 1871 | 1983 | @mkdir($strPath, $mode); |
| 1872 | 1984 | $test = @opendir($strPath); |
@@ -1874,9 +1986,9 @@ discard block |
||
| 1874 | 1986 | { |
| 1875 | 1987 | closedir($test); |
| 1876 | 1988 | return true; |
| 1989 | + } else { |
|
| 1990 | + return false; |
|
| 1877 | 1991 | } |
| 1878 | - else |
|
| 1879 | - return false; |
|
| 1880 | 1992 | } |
| 1881 | 1993 | } |
| 1882 | 1994 | |
@@ -1891,39 +2003,46 @@ discard block |
||
| 1891 | 2003 | { |
| 1892 | 2004 | global $package_ftp; |
| 1893 | 2005 | |
| 1894 | - if (!file_exists($destination) || !is_writable($destination)) |
|
| 1895 | - mktree($destination, 0755); |
|
| 1896 | - if (!is_writable($destination)) |
|
| 1897 | - mktree($destination, 0777); |
|
| 2006 | + if (!file_exists($destination) || !is_writable($destination)) { |
|
| 2007 | + mktree($destination, 0755); |
|
| 2008 | + } |
|
| 2009 | + if (!is_writable($destination)) { |
|
| 2010 | + mktree($destination, 0777); |
|
| 2011 | + } |
|
| 1898 | 2012 | |
| 1899 | 2013 | $current_dir = opendir($source); |
| 1900 | - if ($current_dir == false) |
|
| 1901 | - return; |
|
| 2014 | + if ($current_dir == false) { |
|
| 2015 | + return; |
|
| 2016 | + } |
|
| 1902 | 2017 | |
| 1903 | 2018 | while ($entryname = readdir($current_dir)) |
| 1904 | 2019 | { |
| 1905 | - if (in_array($entryname, array('.', '..'))) |
|
| 1906 | - continue; |
|
| 2020 | + if (in_array($entryname, array('.', '..'))) { |
|
| 2021 | + continue; |
|
| 2022 | + } |
|
| 1907 | 2023 | |
| 1908 | - if (isset($package_ftp)) |
|
| 1909 | - $ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2024 | + if (isset($package_ftp)) { |
|
| 2025 | + $ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2026 | + } |
|
| 1910 | 2027 | |
| 1911 | 2028 | if (is_file($source . '/' . $entryname)) |
| 1912 | 2029 | { |
| 1913 | - if (isset($package_ftp) && !file_exists($destination . '/' . $entryname)) |
|
| 1914 | - $package_ftp->create_file($ftp_file); |
|
| 1915 | - elseif (!file_exists($destination . '/' . $entryname)) |
|
| 1916 | - @touch($destination . '/' . $entryname); |
|
| 2030 | + if (isset($package_ftp) && !file_exists($destination . '/' . $entryname)) { |
|
| 2031 | + $package_ftp->create_file($ftp_file); |
|
| 2032 | + } elseif (!file_exists($destination . '/' . $entryname)) { |
|
| 2033 | + @touch($destination . '/' . $entryname); |
|
| 2034 | + } |
|
| 1917 | 2035 | } |
| 1918 | 2036 | |
| 1919 | 2037 | package_chmod($destination . '/' . $entryname); |
| 1920 | 2038 | |
| 1921 | - if (is_dir($source . '/' . $entryname)) |
|
| 1922 | - copytree($source . '/' . $entryname, $destination . '/' . $entryname); |
|
| 1923 | - elseif (file_exists($destination . '/' . $entryname)) |
|
| 1924 | - package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname)); |
|
| 1925 | - else |
|
| 1926 | - copy($source . '/' . $entryname, $destination . '/' . $entryname); |
|
| 2039 | + if (is_dir($source . '/' . $entryname)) { |
|
| 2040 | + copytree($source . '/' . $entryname, $destination . '/' . $entryname); |
|
| 2041 | + } elseif (file_exists($destination . '/' . $entryname)) { |
|
| 2042 | + package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname)); |
|
| 2043 | + } else { |
|
| 2044 | + copy($source . '/' . $entryname, $destination . '/' . $entryname); |
|
| 2045 | + } |
|
| 1927 | 2046 | } |
| 1928 | 2047 | |
| 1929 | 2048 | closedir($current_dir); |
@@ -1941,21 +2060,24 @@ discard block |
||
| 1941 | 2060 | $data = array(); |
| 1942 | 2061 | |
| 1943 | 2062 | $dir = @dir($path . $sub_path); |
| 1944 | - if (!$dir) |
|
| 1945 | - return array(); |
|
| 2063 | + if (!$dir) { |
|
| 2064 | + return array(); |
|
| 2065 | + } |
|
| 1946 | 2066 | while ($entry = $dir->read()) |
| 1947 | 2067 | { |
| 1948 | - if ($entry == '.' || $entry == '..') |
|
| 1949 | - continue; |
|
| 2068 | + if ($entry == '.' || $entry == '..') { |
|
| 2069 | + continue; |
|
| 2070 | + } |
|
| 1950 | 2071 | |
| 1951 | - if (is_dir($path . $sub_path . '/' . $entry)) |
|
| 1952 | - $data = array_merge($data, listtree($path, $sub_path . '/' . $entry)); |
|
| 1953 | - else |
|
| 1954 | - $data[] = array( |
|
| 2072 | + if (is_dir($path . $sub_path . '/' . $entry)) { |
|
| 2073 | + $data = array_merge($data, listtree($path, $sub_path . '/' . $entry)); |
|
| 2074 | + } else { |
|
| 2075 | + $data[] = array( |
|
| 1955 | 2076 | 'filename' => $sub_path == '' ? $entry : $sub_path . '/' . $entry, |
| 1956 | 2077 | 'size' => filesize($path . $sub_path . '/' . $entry), |
| 1957 | 2078 | 'skipped' => false, |
| 1958 | 2079 | ); |
| 2080 | + } |
|
| 1959 | 2081 | } |
| 1960 | 2082 | $dir->close(); |
| 1961 | 2083 | |
@@ -2010,8 +2132,9 @@ discard block |
||
| 2010 | 2132 | { |
| 2011 | 2133 | // If this filename is relative, if so take a guess at what it should be. |
| 2012 | 2134 | $real_filename = $filename; |
| 2013 | - if (strpos($filename, 'Themes') === 0) |
|
| 2014 | - $real_filename = $boarddir . '/' . $filename; |
|
| 2135 | + if (strpos($filename, 'Themes') === 0) { |
|
| 2136 | + $real_filename = $boarddir . '/' . $filename; |
|
| 2137 | + } |
|
| 2015 | 2138 | |
| 2016 | 2139 | if (strpos($real_filename, $theme['theme_dir']) === 0) |
| 2017 | 2140 | { |
@@ -2030,8 +2153,9 @@ discard block |
||
| 2030 | 2153 | foreach ($theme_paths as $id => $theme) |
| 2031 | 2154 | { |
| 2032 | 2155 | // Default is getting done anyway, so no need for involvement here. |
| 2033 | - if ($id == 1) |
|
| 2034 | - continue; |
|
| 2156 | + if ($id == 1) { |
|
| 2157 | + continue; |
|
| 2158 | + } |
|
| 2035 | 2159 | |
| 2036 | 2160 | // For every template, do we want it? Yea, no, maybe? |
| 2037 | 2161 | foreach ($template_changes[1] as $index => $template_file) |
@@ -2054,8 +2178,9 @@ discard block |
||
| 2054 | 2178 | ); |
| 2055 | 2179 | |
| 2056 | 2180 | // Sometimes though, we have some additional files for other themes, if we have add them to the mix. |
| 2057 | - if (isset($custom_themes_add[$files_to_change[1]])) |
|
| 2058 | - $files_to_change += $custom_themes_add[$files_to_change[1]]; |
|
| 2181 | + if (isset($custom_themes_add[$files_to_change[1]])) { |
|
| 2182 | + $files_to_change += $custom_themes_add[$files_to_change[1]]; |
|
| 2183 | + } |
|
| 2059 | 2184 | |
| 2060 | 2185 | // Now, loop through all the files we're changing, and, well, change them ;) |
| 2061 | 2186 | foreach ($files_to_change as $theme => $working_file) |
@@ -2089,11 +2214,13 @@ discard block |
||
| 2089 | 2214 | continue; |
| 2090 | 2215 | } |
| 2091 | 2216 | // Okay, we're creating this file then...? |
| 2092 | - elseif (!file_exists($working_file)) |
|
| 2093 | - $working_data = ''; |
|
| 2217 | + elseif (!file_exists($working_file)) { |
|
| 2218 | + $working_data = ''; |
|
| 2219 | + } |
|
| 2094 | 2220 | // Phew, it exists! Load 'er up! |
| 2095 | - else |
|
| 2096 | - $working_data = str_replace("\r", '', package_get_contents($working_file)); |
|
| 2221 | + else { |
|
| 2222 | + $working_data = str_replace("\r", '', package_get_contents($working_file)); |
|
| 2223 | + } |
|
| 2097 | 2224 | |
| 2098 | 2225 | $actions[] = array( |
| 2099 | 2226 | 'type' => 'opened', |
@@ -2114,8 +2241,8 @@ discard block |
||
| 2114 | 2241 | |
| 2115 | 2242 | // Grab all search items of this operation (in most cases just 1). |
| 2116 | 2243 | $searches = $operation->set('search'); |
| 2117 | - foreach ($searches as $i => $search) |
|
| 2118 | - $actual_operation['searches'][] = array( |
|
| 2244 | + foreach ($searches as $i => $search) { |
|
| 2245 | + $actual_operation['searches'][] = array( |
|
| 2119 | 2246 | 'position' => $search->exists('@position') && in_array(trim($search->fetch('@position')), array('before', 'after', 'replace', 'end')) ? trim($search->fetch('@position')) : 'replace', |
| 2120 | 2247 | 'is_reg_exp' => $search->exists('@regexp') && trim($search->fetch('@regexp')) === 'true', |
| 2121 | 2248 | 'loose_whitespace' => $search->exists('@whitespace') && trim($search->fetch('@whitespace')) === 'loose', |
@@ -2124,6 +2251,7 @@ discard block |
||
| 2124 | 2251 | 'preg_search' => '', |
| 2125 | 2252 | 'preg_replace' => '', |
| 2126 | 2253 | ); |
| 2254 | + } |
|
| 2127 | 2255 | |
| 2128 | 2256 | // At least one search should be defined. |
| 2129 | 2257 | if (empty($actual_operation['searches'])) |
@@ -2148,30 +2276,32 @@ discard block |
||
| 2148 | 2276 | // Reverse modification of regular expressions are not allowed. |
| 2149 | 2277 | if ($search['is_reg_exp']) |
| 2150 | 2278 | { |
| 2151 | - if ($actual_operation['error'] === 'fatal') |
|
| 2152 | - $actions[] = array( |
|
| 2279 | + if ($actual_operation['error'] === 'fatal') { |
|
| 2280 | + $actions[] = array( |
|
| 2153 | 2281 | 'type' => 'failure', |
| 2154 | 2282 | 'filename' => $working_file, |
| 2155 | 2283 | 'search' => $search['search'], |
| 2156 | 2284 | 'is_custom' => $theme > 1 ? $theme : 0, |
| 2157 | 2285 | ); |
| 2286 | + } |
|
| 2158 | 2287 | |
| 2159 | 2288 | // Continue to the next operation. |
| 2160 | 2289 | continue 2; |
| 2161 | 2290 | } |
| 2162 | 2291 | |
| 2163 | 2292 | // The replacement is now the search subject... |
| 2164 | - if ($search['position'] === 'replace' || $search['position'] === 'end') |
|
| 2165 | - $actual_operation['searches'][$i]['search'] = $search['add']; |
|
| 2166 | - else |
|
| 2293 | + if ($search['position'] === 'replace' || $search['position'] === 'end') { |
|
| 2294 | + $actual_operation['searches'][$i]['search'] = $search['add']; |
|
| 2295 | + } else |
|
| 2167 | 2296 | { |
| 2168 | 2297 | // Reversing a before/after modification becomes a replacement. |
| 2169 | 2298 | $actual_operation['searches'][$i]['position'] = 'replace'; |
| 2170 | 2299 | |
| 2171 | - if ($search['position'] === 'before') |
|
| 2172 | - $actual_operation['searches'][$i]['search'] .= $search['add']; |
|
| 2173 | - elseif ($search['position'] === 'after') |
|
| 2174 | - $actual_operation['searches'][$i]['search'] = $search['add'] . $search['search']; |
|
| 2300 | + if ($search['position'] === 'before') { |
|
| 2301 | + $actual_operation['searches'][$i]['search'] .= $search['add']; |
|
| 2302 | + } elseif ($search['position'] === 'after') { |
|
| 2303 | + $actual_operation['searches'][$i]['search'] = $search['add'] . $search['search']; |
|
| 2304 | + } |
|
| 2175 | 2305 | } |
| 2176 | 2306 | |
| 2177 | 2307 | // ...and the search subject is now the replacement. |
@@ -2199,16 +2329,17 @@ discard block |
||
| 2199 | 2329 | foreach ($actual_operation['searches'] as $i => $search) |
| 2200 | 2330 | { |
| 2201 | 2331 | // Not much needed if the search subject is already a regexp. |
| 2202 | - if ($search['is_reg_exp']) |
|
| 2203 | - $actual_operation['searches'][$i]['preg_search'] = $search['search']; |
|
| 2204 | - else |
|
| 2332 | + if ($search['is_reg_exp']) { |
|
| 2333 | + $actual_operation['searches'][$i]['preg_search'] = $search['search']; |
|
| 2334 | + } else |
|
| 2205 | 2335 | { |
| 2206 | 2336 | // Make the search subject fit into a regular expression. |
| 2207 | 2337 | $actual_operation['searches'][$i]['preg_search'] = preg_quote($search['search'], '~'); |
| 2208 | 2338 | |
| 2209 | 2339 | // Using 'loose', a random amount of tabs and spaces may be used. |
| 2210 | - if ($search['loose_whitespace']) |
|
| 2211 | - $actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']); |
|
| 2340 | + if ($search['loose_whitespace']) { |
|
| 2341 | + $actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']); |
|
| 2342 | + } |
|
| 2212 | 2343 | } |
| 2213 | 2344 | |
| 2214 | 2345 | // Shuzzup. This is done so we can safely use a regular expression. ($0 is bad!!) |
@@ -2234,8 +2365,7 @@ discard block |
||
| 2234 | 2365 | if ($undo) |
| 2235 | 2366 | { |
| 2236 | 2367 | $actual_operation['searches'][$i]['preg_replace'] = ''; |
| 2237 | - } |
|
| 2238 | - else |
|
| 2368 | + } else |
|
| 2239 | 2369 | { |
| 2240 | 2370 | $actual_operation['searches'][$i]['preg_search'] = '(\\n\\?\\>)?$'; |
| 2241 | 2371 | $actual_operation['searches'][$i]['preg_replace'] .= '$1'; |
@@ -2282,8 +2412,9 @@ discard block |
||
| 2282 | 2412 | } |
| 2283 | 2413 | |
| 2284 | 2414 | // Replace it into nothing? That's not an option...unless it's an undoing end. |
| 2285 | - if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo)) |
|
| 2286 | - continue; |
|
| 2415 | + if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo)) { |
|
| 2416 | + continue; |
|
| 2417 | + } |
|
| 2287 | 2418 | |
| 2288 | 2419 | // Finally, we're doing some replacements. |
| 2289 | 2420 | $working_data = preg_replace('~' . $actual_operation['searches'][$i]['preg_search'] . '~s', $actual_operation['searches'][$i]['preg_replace'], $working_data, 1); |
@@ -2308,22 +2439,25 @@ discard block |
||
| 2308 | 2439 | |
| 2309 | 2440 | package_chmod($working_file); |
| 2310 | 2441 | |
| 2311 | - if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file)))) |
|
| 2312 | - $actions[] = array( |
|
| 2442 | + if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file)))) { |
|
| 2443 | + $actions[] = array( |
|
| 2313 | 2444 | 'type' => 'chmod', |
| 2314 | 2445 | 'filename' => $working_file |
| 2315 | 2446 | ); |
| 2447 | + } |
|
| 2316 | 2448 | |
| 2317 | - if (basename($working_file) == 'Settings_bak.php') |
|
| 2318 | - continue; |
|
| 2449 | + if (basename($working_file) == 'Settings_bak.php') { |
|
| 2450 | + continue; |
|
| 2451 | + } |
|
| 2319 | 2452 | |
| 2320 | 2453 | if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) |
| 2321 | 2454 | { |
| 2322 | 2455 | // No, no, not Settings.php! |
| 2323 | - if (basename($working_file) == 'Settings.php') |
|
| 2324 | - @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2325 | - else |
|
| 2326 | - @copy($working_file, $working_file . '~'); |
|
| 2456 | + if (basename($working_file) == 'Settings.php') { |
|
| 2457 | + @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2458 | + } else { |
|
| 2459 | + @copy($working_file, $working_file . '~'); |
|
| 2460 | + } |
|
| 2327 | 2461 | } |
| 2328 | 2462 | |
| 2329 | 2463 | // Always call this, even if in testing, because it won't really be written in testing mode. |
@@ -2390,8 +2524,9 @@ discard block |
||
| 2390 | 2524 | if ($code_match[1] != 'edit file' && $code_match[1] != 'file') |
| 2391 | 2525 | { |
| 2392 | 2526 | // It's a step, let's add that to the current steps. |
| 2393 | - if (isset($temp_changes[$step_counter])) |
|
| 2394 | - $temp_changes[$step_counter]['changes'][] = $code_match[0]; |
|
| 2527 | + if (isset($temp_changes[$step_counter])) { |
|
| 2528 | + $temp_changes[$step_counter]['changes'][] = $code_match[0]; |
|
| 2529 | + } |
|
| 2395 | 2530 | continue; |
| 2396 | 2531 | } |
| 2397 | 2532 | |
@@ -2408,11 +2543,13 @@ discard block |
||
| 2408 | 2543 | foreach ($theme_paths as $id => $theme) |
| 2409 | 2544 | { |
| 2410 | 2545 | // If this filename is relative, if so take a guess at what it should be. |
| 2411 | - if (strpos($filename, 'Themes') === 0) |
|
| 2412 | - $filename = $boarddir . '/' . $filename; |
|
| 2546 | + if (strpos($filename, 'Themes') === 0) { |
|
| 2547 | + $filename = $boarddir . '/' . $filename; |
|
| 2548 | + } |
|
| 2413 | 2549 | |
| 2414 | - if (strpos($filename, $theme['theme_dir']) === 0) |
|
| 2415 | - $template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1); |
|
| 2550 | + if (strpos($filename, $theme['theme_dir']) === 0) { |
|
| 2551 | + $template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1); |
|
| 2552 | + } |
|
| 2416 | 2553 | } |
| 2417 | 2554 | } |
| 2418 | 2555 | |
@@ -2427,8 +2564,9 @@ discard block |
||
| 2427 | 2564 | foreach ($theme_paths as $id => $theme) |
| 2428 | 2565 | { |
| 2429 | 2566 | // Don't do default, it means nothing to me. |
| 2430 | - if ($id == 1) |
|
| 2431 | - continue; |
|
| 2567 | + if ($id == 1) { |
|
| 2568 | + continue; |
|
| 2569 | + } |
|
| 2432 | 2570 | |
| 2433 | 2571 | // Now, for each file do we need to edit it? |
| 2434 | 2572 | foreach ($template_changes[1] as $pos => $template_file) |
@@ -2464,32 +2602,36 @@ discard block |
||
| 2464 | 2602 | package_chmod($working_file); |
| 2465 | 2603 | |
| 2466 | 2604 | // Don't even dare. |
| 2467 | - if (basename($working_file) == 'Settings_bak.php') |
|
| 2468 | - continue; |
|
| 2605 | + if (basename($working_file) == 'Settings_bak.php') { |
|
| 2606 | + continue; |
|
| 2607 | + } |
|
| 2469 | 2608 | |
| 2470 | - if (!is_writable($working_file)) |
|
| 2471 | - $actions[] = array( |
|
| 2609 | + if (!is_writable($working_file)) { |
|
| 2610 | + $actions[] = array( |
|
| 2472 | 2611 | 'type' => 'chmod', |
| 2473 | 2612 | 'filename' => $working_file |
| 2474 | 2613 | ); |
| 2614 | + } |
|
| 2475 | 2615 | |
| 2476 | 2616 | if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) |
| 2477 | 2617 | { |
| 2478 | - if (basename($working_file) == 'Settings.php') |
|
| 2479 | - @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2480 | - else |
|
| 2481 | - @copy($working_file, $working_file . '~'); |
|
| 2618 | + if (basename($working_file) == 'Settings.php') { |
|
| 2619 | + @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2620 | + } else { |
|
| 2621 | + @copy($working_file, $working_file . '~'); |
|
| 2622 | + } |
|
| 2482 | 2623 | } |
| 2483 | 2624 | |
| 2484 | 2625 | package_put_contents($working_file, $working_data, $testing); |
| 2485 | 2626 | } |
| 2486 | 2627 | |
| 2487 | - if ($working_file !== null) |
|
| 2488 | - $actions[] = array( |
|
| 2628 | + if ($working_file !== null) { |
|
| 2629 | + $actions[] = array( |
|
| 2489 | 2630 | 'type' => 'saved', |
| 2490 | 2631 | 'filename' => $working_file, |
| 2491 | 2632 | 'is_custom' => $is_custom, |
| 2492 | 2633 | ); |
| 2634 | + } |
|
| 2493 | 2635 | |
| 2494 | 2636 | // Is this "now working on" file a theme specific one? |
| 2495 | 2637 | $is_custom = isset($theme_id_ref[$counter - 1]) ? $theme_id_ref[$counter - 1] : 0; |
@@ -2508,10 +2650,11 @@ discard block |
||
| 2508 | 2650 | { |
| 2509 | 2651 | $places_to_check = array($boarddir, $sourcedir, $settings['default_theme_dir'], $settings['default_theme_dir'] . '/languages'); |
| 2510 | 2652 | |
| 2511 | - foreach ($places_to_check as $place) |
|
| 2512 | - if (file_exists($place . '/' . $working_file)) |
|
| 2653 | + foreach ($places_to_check as $place) { |
|
| 2654 | + if (file_exists($place . '/' . $working_file)) |
|
| 2513 | 2655 | { |
| 2514 | 2656 | $working_file = $place . '/' . $working_file; |
| 2657 | + } |
|
| 2515 | 2658 | break; |
| 2516 | 2659 | } |
| 2517 | 2660 | } |
@@ -2525,8 +2668,7 @@ discard block |
||
| 2525 | 2668 | 'type' => 'opened', |
| 2526 | 2669 | 'filename' => $working_file |
| 2527 | 2670 | ); |
| 2528 | - } |
|
| 2529 | - else |
|
| 2671 | + } else |
|
| 2530 | 2672 | { |
| 2531 | 2673 | $actions[] = array( |
| 2532 | 2674 | 'type' => 'missing', |
@@ -2562,11 +2704,13 @@ discard block |
||
| 2562 | 2704 | $replace_with = $code_match[2]; |
| 2563 | 2705 | |
| 2564 | 2706 | // Add this afterward... |
| 2565 | - if ($code_match[1] == 'add' || $code_match[1] == 'add after') |
|
| 2566 | - $replace_with = $working_search . "\n" . $replace_with; |
|
| 2707 | + if ($code_match[1] == 'add' || $code_match[1] == 'add after') { |
|
| 2708 | + $replace_with = $working_search . "\n" . $replace_with; |
|
| 2709 | + } |
|
| 2567 | 2710 | // Add this beforehand. |
| 2568 | - elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above') |
|
| 2569 | - $replace_with .= "\n" . $working_search; |
|
| 2711 | + elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above') { |
|
| 2712 | + $replace_with .= "\n" . $working_search; |
|
| 2713 | + } |
|
| 2570 | 2714 | // Otherwise.. replace with $replace_with ;). |
| 2571 | 2715 | } |
| 2572 | 2716 | |
@@ -2629,29 +2773,32 @@ discard block |
||
| 2629 | 2773 | { |
| 2630 | 2774 | package_chmod($working_file); |
| 2631 | 2775 | |
| 2632 | - if (!is_writable($working_file)) |
|
| 2633 | - $actions[] = array( |
|
| 2776 | + if (!is_writable($working_file)) { |
|
| 2777 | + $actions[] = array( |
|
| 2634 | 2778 | 'type' => 'chmod', |
| 2635 | 2779 | 'filename' => $working_file |
| 2636 | 2780 | ); |
| 2781 | + } |
|
| 2637 | 2782 | |
| 2638 | 2783 | if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) |
| 2639 | 2784 | { |
| 2640 | - if (basename($working_file) == 'Settings.php') |
|
| 2641 | - @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2642 | - else |
|
| 2643 | - @copy($working_file, $working_file . '~'); |
|
| 2785 | + if (basename($working_file) == 'Settings.php') { |
|
| 2786 | + @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2787 | + } else { |
|
| 2788 | + @copy($working_file, $working_file . '~'); |
|
| 2789 | + } |
|
| 2644 | 2790 | } |
| 2645 | 2791 | |
| 2646 | 2792 | package_put_contents($working_file, $working_data, $testing); |
| 2647 | 2793 | } |
| 2648 | 2794 | |
| 2649 | - if ($working_file !== null) |
|
| 2650 | - $actions[] = array( |
|
| 2795 | + if ($working_file !== null) { |
|
| 2796 | + $actions[] = array( |
|
| 2651 | 2797 | 'type' => 'saved', |
| 2652 | 2798 | 'filename' => $working_file, |
| 2653 | 2799 | 'is_custom' => $is_custom, |
| 2654 | 2800 | ); |
| 2801 | + } |
|
| 2655 | 2802 | |
| 2656 | 2803 | $actions[] = array( |
| 2657 | 2804 | 'type' => 'result', |
@@ -2677,17 +2824,19 @@ discard block |
||
| 2677 | 2824 | $mem_check = setMemoryLimit('128M'); |
| 2678 | 2825 | |
| 2679 | 2826 | // Windows doesn't seem to care about the memory_limit. |
| 2680 | - if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) |
|
| 2681 | - $package_cache = array(); |
|
| 2682 | - else |
|
| 2683 | - $package_cache = false; |
|
| 2827 | + if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) { |
|
| 2828 | + $package_cache = array(); |
|
| 2829 | + } else { |
|
| 2830 | + $package_cache = false; |
|
| 2831 | + } |
|
| 2684 | 2832 | } |
| 2685 | 2833 | |
| 2686 | - if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename])) |
|
| 2687 | - return file_get_contents($filename); |
|
| 2688 | - else |
|
| 2689 | - return $package_cache[$filename]; |
|
| 2690 | -} |
|
| 2834 | + if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename])) { |
|
| 2835 | + return file_get_contents($filename); |
|
| 2836 | + } else { |
|
| 2837 | + return $package_cache[$filename]; |
|
| 2838 | + } |
|
| 2839 | + } |
|
| 2691 | 2840 | |
| 2692 | 2841 | /** |
| 2693 | 2842 | * Writes data to a file, almost exactly like the file_put_contents() function. |
@@ -2710,19 +2859,22 @@ discard block |
||
| 2710 | 2859 | // Try to increase the memory limit - we don't want to run out of ram! |
| 2711 | 2860 | $mem_check = setMemoryLimit('128M'); |
| 2712 | 2861 | |
| 2713 | - if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) |
|
| 2714 | - $package_cache = array(); |
|
| 2715 | - else |
|
| 2716 | - $package_cache = false; |
|
| 2862 | + if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) { |
|
| 2863 | + $package_cache = array(); |
|
| 2864 | + } else { |
|
| 2865 | + $package_cache = false; |
|
| 2866 | + } |
|
| 2717 | 2867 | } |
| 2718 | 2868 | |
| 2719 | - if (isset($package_ftp)) |
|
| 2720 | - $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2869 | + if (isset($package_ftp)) { |
|
| 2870 | + $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2871 | + } |
|
| 2721 | 2872 | |
| 2722 | - if (!file_exists($filename) && isset($package_ftp)) |
|
| 2723 | - $package_ftp->create_file($ftp_file); |
|
| 2724 | - elseif (!file_exists($filename)) |
|
| 2725 | - @touch($filename); |
|
| 2873 | + if (!file_exists($filename) && isset($package_ftp)) { |
|
| 2874 | + $package_ftp->create_file($ftp_file); |
|
| 2875 | + } elseif (!file_exists($filename)) { |
|
| 2876 | + @touch($filename); |
|
| 2877 | + } |
|
| 2726 | 2878 | |
| 2727 | 2879 | package_chmod($filename); |
| 2728 | 2880 | |
@@ -2731,22 +2883,23 @@ discard block |
||
| 2731 | 2883 | $fp = @fopen($filename, in_array(substr($filename, -3), $text_filetypes) ? 'w' : 'wb'); |
| 2732 | 2884 | |
| 2733 | 2885 | // We should show an error message or attempt a rollback, no? |
| 2734 | - if (!$fp) |
|
| 2735 | - return false; |
|
| 2886 | + if (!$fp) { |
|
| 2887 | + return false; |
|
| 2888 | + } |
|
| 2736 | 2889 | |
| 2737 | 2890 | fwrite($fp, $data); |
| 2738 | 2891 | fclose($fp); |
| 2739 | - } |
|
| 2740 | - elseif (strpos($filename, 'Packages/') !== false || $package_cache === false) |
|
| 2741 | - return strlen($data); |
|
| 2742 | - else |
|
| 2892 | + } elseif (strpos($filename, 'Packages/') !== false || $package_cache === false) { |
|
| 2893 | + return strlen($data); |
|
| 2894 | + } else |
|
| 2743 | 2895 | { |
| 2744 | 2896 | $package_cache[$filename] = $data; |
| 2745 | 2897 | |
| 2746 | 2898 | // Permission denied, eh? |
| 2747 | 2899 | $fp = @fopen($filename, 'r+'); |
| 2748 | - if (!$fp) |
|
| 2749 | - return false; |
|
| 2900 | + if (!$fp) { |
|
| 2901 | + return false; |
|
| 2902 | + } |
|
| 2750 | 2903 | fclose($fp); |
| 2751 | 2904 | } |
| 2752 | 2905 | |
@@ -2763,19 +2916,22 @@ discard block |
||
| 2763 | 2916 | global $package_ftp, $package_cache; |
| 2764 | 2917 | static $text_filetypes = array('php', 'txt', '.js', 'css', 'vbs', 'tml', 'htm'); |
| 2765 | 2918 | |
| 2766 | - if (empty($package_cache)) |
|
| 2767 | - return; |
|
| 2919 | + if (empty($package_cache)) { |
|
| 2920 | + return; |
|
| 2921 | + } |
|
| 2768 | 2922 | |
| 2769 | 2923 | // First, let's check permissions! |
| 2770 | 2924 | foreach ($package_cache as $filename => $data) |
| 2771 | 2925 | { |
| 2772 | - if (isset($package_ftp)) |
|
| 2773 | - $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2926 | + if (isset($package_ftp)) { |
|
| 2927 | + $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2928 | + } |
|
| 2774 | 2929 | |
| 2775 | - if (!file_exists($filename) && isset($package_ftp)) |
|
| 2776 | - $package_ftp->create_file($ftp_file); |
|
| 2777 | - elseif (!file_exists($filename)) |
|
| 2778 | - @touch($filename); |
|
| 2930 | + if (!file_exists($filename) && isset($package_ftp)) { |
|
| 2931 | + $package_ftp->create_file($ftp_file); |
|
| 2932 | + } elseif (!file_exists($filename)) { |
|
| 2933 | + @touch($filename); |
|
| 2934 | + } |
|
| 2779 | 2935 | |
| 2780 | 2936 | $result = package_chmod($filename); |
| 2781 | 2937 | |
@@ -2822,8 +2978,9 @@ discard block |
||
| 2822 | 2978 | { |
| 2823 | 2979 | global $package_ftp; |
| 2824 | 2980 | |
| 2825 | - if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable') |
|
| 2826 | - return true; |
|
| 2981 | + if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable') { |
|
| 2982 | + return true; |
|
| 2983 | + } |
|
| 2827 | 2984 | |
| 2828 | 2985 | // Start off checking without FTP. |
| 2829 | 2986 | if (!isset($package_ftp) || $package_ftp === false) |
@@ -2845,8 +3002,7 @@ discard block |
||
| 2845 | 3002 | |
| 2846 | 3003 | // Keep track of the writable status here. |
| 2847 | 3004 | $file_permissions = @fileperms($chmod_file); |
| 2848 | - } |
|
| 2849 | - else |
|
| 3005 | + } else |
|
| 2850 | 3006 | { |
| 2851 | 3007 | // This looks odd, but it's an attempt to work around PHP suExec. |
| 2852 | 3008 | if (!file_exists($chmod_file) && $perm_state == 'writable') |
@@ -2856,24 +3012,28 @@ discard block |
||
| 2856 | 3012 | mktree(dirname($chmod_file), 0755); |
| 2857 | 3013 | @touch($chmod_file); |
| 2858 | 3014 | smf_chmod($chmod_file, 0755); |
| 3015 | + } else { |
|
| 3016 | + $file_permissions = @fileperms($chmod_file); |
|
| 2859 | 3017 | } |
| 2860 | - else |
|
| 2861 | - $file_permissions = @fileperms($chmod_file); |
|
| 2862 | 3018 | } |
| 2863 | 3019 | |
| 2864 | 3020 | // This looks odd, but it's another attempt to work around PHP suExec. |
| 2865 | - if ($perm_state != 'writable') |
|
| 2866 | - smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644); |
|
| 2867 | - else |
|
| 3021 | + if ($perm_state != 'writable') { |
|
| 3022 | + smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644); |
|
| 3023 | + } else |
|
| 2868 | 3024 | { |
| 2869 | - if (!@is_writable($chmod_file)) |
|
| 2870 | - smf_chmod($chmod_file, 0755); |
|
| 2871 | - if (!@is_writable($chmod_file)) |
|
| 2872 | - smf_chmod($chmod_file, 0777); |
|
| 2873 | - if (!@is_writable(dirname($chmod_file))) |
|
| 2874 | - smf_chmod($chmod_file, 0755); |
|
| 2875 | - if (!@is_writable(dirname($chmod_file))) |
|
| 2876 | - smf_chmod($chmod_file, 0777); |
|
| 3025 | + if (!@is_writable($chmod_file)) { |
|
| 3026 | + smf_chmod($chmod_file, 0755); |
|
| 3027 | + } |
|
| 3028 | + if (!@is_writable($chmod_file)) { |
|
| 3029 | + smf_chmod($chmod_file, 0777); |
|
| 3030 | + } |
|
| 3031 | + if (!@is_writable(dirname($chmod_file))) { |
|
| 3032 | + smf_chmod($chmod_file, 0755); |
|
| 3033 | + } |
|
| 3034 | + if (!@is_writable(dirname($chmod_file))) { |
|
| 3035 | + smf_chmod($chmod_file, 0777); |
|
| 3036 | + } |
|
| 2877 | 3037 | } |
| 2878 | 3038 | |
| 2879 | 3039 | // The ultimate writable test. |
@@ -2882,20 +3042,22 @@ discard block |
||
| 2882 | 3042 | $fp = is_dir($chmod_file) ? @opendir($chmod_file) : @fopen($chmod_file, 'rb'); |
| 2883 | 3043 | if (@is_writable($chmod_file) && $fp) |
| 2884 | 3044 | { |
| 2885 | - if (!is_dir($chmod_file)) |
|
| 2886 | - fclose($fp); |
|
| 2887 | - else |
|
| 2888 | - closedir($fp); |
|
| 3045 | + if (!is_dir($chmod_file)) { |
|
| 3046 | + fclose($fp); |
|
| 3047 | + } else { |
|
| 3048 | + closedir($fp); |
|
| 3049 | + } |
|
| 2889 | 3050 | |
| 2890 | 3051 | // It worked! |
| 2891 | - if ($track_change) |
|
| 2892 | - $_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions; |
|
| 3052 | + if ($track_change) { |
|
| 3053 | + $_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions; |
|
| 3054 | + } |
|
| 2893 | 3055 | |
| 2894 | 3056 | return true; |
| 2895 | 3057 | } |
| 3058 | + } elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file])) { |
|
| 3059 | + unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]); |
|
| 2896 | 3060 | } |
| 2897 | - elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file])) |
|
| 2898 | - unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]); |
|
| 2899 | 3061 | } |
| 2900 | 3062 | |
| 2901 | 3063 | // If we're here we're a failure. |
@@ -2914,31 +3076,33 @@ discard block |
||
| 2914 | 3076 | mktree(dirname($filename), 0755); |
| 2915 | 3077 | $package_ftp->create_file($ftp_file); |
| 2916 | 3078 | $package_ftp->chmod($ftp_file, 0755); |
| 3079 | + } else { |
|
| 3080 | + $file_permissions = @fileperms($filename); |
|
| 2917 | 3081 | } |
| 2918 | - else |
|
| 2919 | - $file_permissions = @fileperms($filename); |
|
| 2920 | 3082 | |
| 2921 | 3083 | if ($perm_state != 'writable') |
| 2922 | 3084 | { |
| 2923 | 3085 | $package_ftp->chmod($ftp_file, $perm_state == 'execute' ? 0755 : 0644); |
| 2924 | - } |
|
| 2925 | - else |
|
| 3086 | + } else |
|
| 2926 | 3087 | { |
| 2927 | - if (!@is_writable($filename)) |
|
| 2928 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 2929 | - if (!@is_writable(dirname($filename))) |
|
| 2930 | - $package_ftp->chmod(dirname($ftp_file), 0777); |
|
| 3088 | + if (!@is_writable($filename)) { |
|
| 3089 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 3090 | + } |
|
| 3091 | + if (!@is_writable(dirname($filename))) { |
|
| 3092 | + $package_ftp->chmod(dirname($ftp_file), 0777); |
|
| 3093 | + } |
|
| 2931 | 3094 | } |
| 2932 | 3095 | |
| 2933 | 3096 | if (@is_writable($filename)) |
| 2934 | 3097 | { |
| 2935 | - if ($track_change) |
|
| 2936 | - $_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions; |
|
| 3098 | + if ($track_change) { |
|
| 3099 | + $_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions; |
|
| 3100 | + } |
|
| 2937 | 3101 | |
| 2938 | 3102 | return true; |
| 3103 | + } elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename])) { |
|
| 3104 | + unset($_SESSION['pack_ftp']['original_perms'][$filename]); |
|
| 2939 | 3105 | } |
| 2940 | - elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename])) |
|
| 2941 | - unset($_SESSION['pack_ftp']['original_perms'][$filename]); |
|
| 2942 | 3106 | } |
| 2943 | 3107 | |
| 2944 | 3108 | // Oh dear, we failed if we get here. |
@@ -2956,11 +3120,13 @@ discard block |
||
| 2956 | 3120 | $n = strlen($pass); |
| 2957 | 3121 | |
| 2958 | 3122 | $salt = session_id(); |
| 2959 | - while (strlen($salt) < $n) |
|
| 2960 | - $salt .= session_id(); |
|
| 3123 | + while (strlen($salt) < $n) { |
|
| 3124 | + $salt .= session_id(); |
|
| 3125 | + } |
|
| 2961 | 3126 | |
| 2962 | - for ($i = 0; $i < $n; $i++) |
|
| 2963 | - $pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32)); |
|
| 3127 | + for ($i = 0; $i < $n; $i++) { |
|
| 3128 | + $pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32)); |
|
| 3129 | + } |
|
| 2964 | 3130 | |
| 2965 | 3131 | return $pass; |
| 2966 | 3132 | } |
@@ -2979,8 +3145,9 @@ discard block |
||
| 2979 | 3145 | $base_files = array('index.php', 'SSI.php', 'agreement.txt', 'cron.php', 'ssi_examples.php', 'ssi_examples.shtml', 'subscriptions.php'); |
| 2980 | 3146 | foreach ($base_files as $file) |
| 2981 | 3147 | { |
| 2982 | - if (file_exists($boarddir . '/' . $file)) |
|
| 2983 | - $files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file; |
|
| 3148 | + if (file_exists($boarddir . '/' . $file)) { |
|
| 3149 | + $files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file; |
|
| 3150 | + } |
|
| 2984 | 3151 | } |
| 2985 | 3152 | |
| 2986 | 3153 | $dirs = array( |
@@ -2997,8 +3164,9 @@ discard block |
||
| 2997 | 3164 | 'theme_dir' => 'theme_dir', |
| 2998 | 3165 | ) |
| 2999 | 3166 | ); |
| 3000 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 3001 | - $dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/'); |
|
| 3167 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 3168 | + $dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/'); |
|
| 3169 | + } |
|
| 3002 | 3170 | $smcFunc['db_free_result']($request); |
| 3003 | 3171 | |
| 3004 | 3172 | try |
@@ -3013,11 +3181,13 @@ discard block |
||
| 3013 | 3181 | |
| 3014 | 3182 | foreach ($iter as $entry => $dir) |
| 3015 | 3183 | { |
| 3016 | - if ($dir->isDir()) |
|
| 3017 | - continue; |
|
| 3184 | + if ($dir->isDir()) { |
|
| 3185 | + continue; |
|
| 3186 | + } |
|
| 3018 | 3187 | |
| 3019 | - if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0) |
|
| 3020 | - continue; |
|
| 3188 | + if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0) { |
|
| 3189 | + continue; |
|
| 3190 | + } |
|
| 3021 | 3191 | |
| 3022 | 3192 | $files[empty($_REQUEST['use_full_paths']) ? str_replace(realpath($boarddir), '', $entry) : $entry] = $entry; |
| 3023 | 3193 | } |
@@ -3025,26 +3195,30 @@ discard block |
||
| 3025 | 3195 | $obj = new ArrayObject($files); |
| 3026 | 3196 | $iterator = $obj->getIterator(); |
| 3027 | 3197 | |
| 3028 | - if (!file_exists($packagesdir . '/backups')) |
|
| 3029 | - mktree($packagesdir . '/backups', 0777); |
|
| 3030 | - if (!is_writable($packagesdir . '/backups')) |
|
| 3031 | - package_chmod($packagesdir . '/backups'); |
|
| 3198 | + if (!file_exists($packagesdir . '/backups')) { |
|
| 3199 | + mktree($packagesdir . '/backups', 0777); |
|
| 3200 | + } |
|
| 3201 | + if (!is_writable($packagesdir . '/backups')) { |
|
| 3202 | + package_chmod($packagesdir . '/backups'); |
|
| 3203 | + } |
|
| 3032 | 3204 | $output_file = $packagesdir . '/backups/' . strftime('%Y-%m-%d_') . preg_replace('~[$\\\\/:<>|?*"\']~', '', $id); |
| 3033 | 3205 | $output_ext = '.tar'; |
| 3034 | 3206 | |
| 3035 | 3207 | if (file_exists($output_file . $output_ext)) |
| 3036 | 3208 | { |
| 3037 | 3209 | $i = 2; |
| 3038 | - while (file_exists($output_file . '_' . $i . $output_ext)) |
|
| 3039 | - $i++; |
|
| 3210 | + while (file_exists($output_file . '_' . $i . $output_ext)) { |
|
| 3211 | + $i++; |
|
| 3212 | + } |
|
| 3040 | 3213 | $output_file = $output_file . '_' . $i . $output_ext; |
| 3214 | + } else { |
|
| 3215 | + $output_file .= $output_ext; |
|
| 3041 | 3216 | } |
| 3042 | - else |
|
| 3043 | - $output_file .= $output_ext; |
|
| 3044 | 3217 | |
| 3045 | 3218 | @set_time_limit(300); |
| 3046 | - if (function_exists('apache_reset_timeout')) |
|
| 3047 | - @apache_reset_timeout(); |
|
| 3219 | + if (function_exists('apache_reset_timeout')) { |
|
| 3220 | + @apache_reset_timeout(); |
|
| 3221 | + } |
|
| 3048 | 3222 | |
| 3049 | 3223 | $a = new PharData($output_file); |
| 3050 | 3224 | $a->buildFromIterator($iterator); |
@@ -3056,8 +3230,7 @@ discard block |
||
| 3056 | 3230 | */ |
| 3057 | 3231 | unset($a); |
| 3058 | 3232 | unlink($output_file); |
| 3059 | - } |
|
| 3060 | - catch (Exception $e) |
|
| 3233 | + } catch (Exception $e) |
|
| 3061 | 3234 | { |
| 3062 | 3235 | log_error($e->getMessage(), 'backup'); |
| 3063 | 3236 | |
@@ -3089,32 +3262,35 @@ discard block |
||
| 3089 | 3262 | preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match); |
| 3090 | 3263 | |
| 3091 | 3264 | // An FTP url. We should try connecting and RETRieving it... |
| 3092 | - if (empty($match[1])) |
|
| 3093 | - return false; |
|
| 3094 | - elseif ($match[1] == 'ftp') |
|
| 3265 | + if (empty($match[1])) { |
|
| 3266 | + return false; |
|
| 3267 | + } elseif ($match[1] == 'ftp') |
|
| 3095 | 3268 | { |
| 3096 | 3269 | // Include the file containing the ftp_connection class. |
| 3097 | 3270 | require_once($sourcedir . '/Class-Package.php'); |
| 3098 | 3271 | |
| 3099 | 3272 | // Establish a connection and attempt to enable passive mode. |
| 3100 | 3273 | $ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email); |
| 3101 | - if ($ftp->error !== false || !$ftp->passive()) |
|
| 3102 | - return false; |
|
| 3274 | + if ($ftp->error !== false || !$ftp->passive()) { |
|
| 3275 | + return false; |
|
| 3276 | + } |
|
| 3103 | 3277 | |
| 3104 | 3278 | // I want that one *points*! |
| 3105 | 3279 | fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n"); |
| 3106 | 3280 | |
| 3107 | 3281 | // Since passive mode worked (or we would have returned already!) open the connection. |
| 3108 | 3282 | $fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5); |
| 3109 | - if (!$fp) |
|
| 3110 | - return false; |
|
| 3283 | + if (!$fp) { |
|
| 3284 | + return false; |
|
| 3285 | + } |
|
| 3111 | 3286 | |
| 3112 | 3287 | // The server should now say something in acknowledgement. |
| 3113 | 3288 | $ftp->check_response(150); |
| 3114 | 3289 | |
| 3115 | 3290 | $data = ''; |
| 3116 | - while (!feof($fp)) |
|
| 3117 | - $data .= fread($fp, 4096); |
|
| 3291 | + while (!feof($fp)) { |
|
| 3292 | + $data .= fread($fp, 4096); |
|
| 3293 | + } |
|
| 3118 | 3294 | fclose($fp); |
| 3119 | 3295 | |
| 3120 | 3296 | // All done, right? Good. |
@@ -3131,22 +3307,25 @@ discard block |
||
| 3131 | 3307 | $fetch_data->get_url_data($url, $post_data); |
| 3132 | 3308 | |
| 3133 | 3309 | // no errors and a 200 result, then we have a good dataset, well we at least have data ;) |
| 3134 | - if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) |
|
| 3135 | - $data = $fetch_data->result('body'); |
|
| 3136 | - else |
|
| 3137 | - return false; |
|
| 3310 | + if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) { |
|
| 3311 | + $data = $fetch_data->result('body'); |
|
| 3312 | + } else { |
|
| 3313 | + return false; |
|
| 3314 | + } |
|
| 3138 | 3315 | } |
| 3139 | 3316 | // This is more likely; a standard HTTP URL. |
| 3140 | 3317 | elseif (isset($match[1]) && $match[1] == 'http') |
| 3141 | 3318 | { |
| 3142 | - if ($keep_alive && $match[3] == $keep_alive_dom) |
|
| 3143 | - $fp = $keep_alive_fp; |
|
| 3319 | + if ($keep_alive && $match[3] == $keep_alive_dom) { |
|
| 3320 | + $fp = $keep_alive_fp; |
|
| 3321 | + } |
|
| 3144 | 3322 | if (empty($fp)) |
| 3145 | 3323 | { |
| 3146 | 3324 | // Open the socket on the port we want... |
| 3147 | 3325 | $fp = @fsockopen(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? ($match[2] ? 443 : 80) : $match[5], $err, $err, 5); |
| 3148 | - if (!$fp) |
|
| 3149 | - return false; |
|
| 3326 | + if (!$fp) { |
|
| 3327 | + return false; |
|
| 3328 | + } |
|
| 3150 | 3329 | } |
| 3151 | 3330 | |
| 3152 | 3331 | if ($keep_alive) |
@@ -3161,20 +3340,21 @@ discard block |
||
| 3161 | 3340 | fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n"); |
| 3162 | 3341 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
| 3163 | 3342 | fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n"); |
| 3164 | - if ($keep_alive) |
|
| 3165 | - fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n"); |
|
| 3166 | - else |
|
| 3167 | - fwrite($fp, 'Connection: close' . "\r\n\r\n"); |
|
| 3168 | - } |
|
| 3169 | - else |
|
| 3343 | + if ($keep_alive) { |
|
| 3344 | + fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n"); |
|
| 3345 | + } else { |
|
| 3346 | + fwrite($fp, 'Connection: close' . "\r\n\r\n"); |
|
| 3347 | + } |
|
| 3348 | + } else |
|
| 3170 | 3349 | { |
| 3171 | 3350 | fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n"); |
| 3172 | 3351 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
| 3173 | 3352 | fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n"); |
| 3174 | - if ($keep_alive) |
|
| 3175 | - fwrite($fp, 'Connection: Keep-Alive' . "\r\n"); |
|
| 3176 | - else |
|
| 3177 | - fwrite($fp, 'Connection: close' . "\r\n"); |
|
| 3353 | + if ($keep_alive) { |
|
| 3354 | + fwrite($fp, 'Connection: Keep-Alive' . "\r\n"); |
|
| 3355 | + } else { |
|
| 3356 | + fwrite($fp, 'Connection: close' . "\r\n"); |
|
| 3357 | + } |
|
| 3178 | 3358 | fwrite($fp, 'Content-Type: application/x-www-form-urlencoded' . "\r\n"); |
| 3179 | 3359 | fwrite($fp, 'Content-Length: ' . strlen($post_data) . "\r\n\r\n"); |
| 3180 | 3360 | fwrite($fp, $post_data); |
@@ -3187,30 +3367,33 @@ discard block |
||
| 3187 | 3367 | { |
| 3188 | 3368 | $header = ''; |
| 3189 | 3369 | $location = ''; |
| 3190 | - while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
|
| 3191 | - if (strpos($header, 'Location:') !== false) |
|
| 3370 | + while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') { |
|
| 3371 | + if (strpos($header, 'Location:') !== false) |
|
| 3192 | 3372 | $location = trim(substr($header, strpos($header, ':') + 1)); |
| 3373 | + } |
|
| 3193 | 3374 | |
| 3194 | - if (empty($location)) |
|
| 3195 | - return false; |
|
| 3196 | - else |
|
| 3375 | + if (empty($location)) { |
|
| 3376 | + return false; |
|
| 3377 | + } else |
|
| 3197 | 3378 | { |
| 3198 | - if (!$keep_alive) |
|
| 3199 | - fclose($fp); |
|
| 3379 | + if (!$keep_alive) { |
|
| 3380 | + fclose($fp); |
|
| 3381 | + } |
|
| 3200 | 3382 | return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1); |
| 3201 | 3383 | } |
| 3202 | 3384 | } |
| 3203 | 3385 | |
| 3204 | 3386 | // Make sure we get a 200 OK. |
| 3205 | - elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) |
|
| 3206 | - return false; |
|
| 3387 | + elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) { |
|
| 3388 | + return false; |
|
| 3389 | + } |
|
| 3207 | 3390 | |
| 3208 | 3391 | // Skip the headers... |
| 3209 | 3392 | while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
| 3210 | 3393 | { |
| 3211 | - if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) |
|
| 3212 | - $content_length = $match[1]; |
|
| 3213 | - elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
| 3394 | + if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) { |
|
| 3395 | + $content_length = $match[1]; |
|
| 3396 | + } elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
| 3214 | 3397 | { |
| 3215 | 3398 | $keep_alive_dom = null; |
| 3216 | 3399 | $keep_alive = false; |
@@ -3222,19 +3405,20 @@ discard block |
||
| 3222 | 3405 | $data = ''; |
| 3223 | 3406 | if (isset($content_length)) |
| 3224 | 3407 | { |
| 3225 | - while (!feof($fp) && strlen($data) < $content_length) |
|
| 3226 | - $data .= fread($fp, $content_length - strlen($data)); |
|
| 3227 | - } |
|
| 3228 | - else |
|
| 3408 | + while (!feof($fp) && strlen($data) < $content_length) { |
|
| 3409 | + $data .= fread($fp, $content_length - strlen($data)); |
|
| 3410 | + } |
|
| 3411 | + } else |
|
| 3229 | 3412 | { |
| 3230 | - while (!feof($fp)) |
|
| 3231 | - $data .= fread($fp, 4096); |
|
| 3413 | + while (!feof($fp)) { |
|
| 3414 | + $data .= fread($fp, 4096); |
|
| 3415 | + } |
|
| 3232 | 3416 | } |
| 3233 | 3417 | |
| 3234 | - if (!$keep_alive) |
|
| 3235 | - fclose($fp); |
|
| 3236 | - } |
|
| 3237 | - else |
|
| 3418 | + if (!$keep_alive) { |
|
| 3419 | + fclose($fp); |
|
| 3420 | + } |
|
| 3421 | + } else |
|
| 3238 | 3422 | { |
| 3239 | 3423 | // Umm, this shouldn't happen? |
| 3240 | 3424 | trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE); |