@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * This is the dispatcher of smileys administration. |
@@ -91,8 +92,9 @@ discard block |
||
| 91 | 92 | ); |
| 92 | 93 | |
| 93 | 94 | // Some settings may not be enabled, disallow these from the tabs as appropriate. |
| 94 | - if (empty($modSettings['messageIcons_enable'])) |
|
| 95 | - $context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true; |
|
| 95 | + if (empty($modSettings['messageIcons_enable'])) { |
|
| 96 | + $context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true; |
|
| 97 | + } |
|
| 96 | 98 | if (empty($modSettings['smiley_enable'])) |
| 97 | 99 | { |
| 98 | 100 | $context[$context['admin_menu_name']]['tab_data']['tabs']['addsmiley']['disabled'] = true; |
@@ -125,8 +127,9 @@ discard block |
||
| 125 | 127 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
| 126 | 128 | |
| 127 | 129 | $smiley_context = array(); |
| 128 | - foreach ($smiley_sets as $i => $set) |
|
| 129 | - $smiley_context[$set] = $set_names[$i]; |
|
| 130 | + foreach ($smiley_sets as $i => $set) { |
|
| 131 | + $smiley_context[$set] = $set_names[$i]; |
|
| 132 | + } |
|
| 130 | 133 | |
| 131 | 134 | // All the settings for the page... |
| 132 | 135 | $config_vars = array( |
@@ -147,8 +150,9 @@ discard block |
||
| 147 | 150 | |
| 148 | 151 | call_integration_hook('integrate_modify_smiley_settings', array(&$config_vars)); |
| 149 | 152 | |
| 150 | - if ($return_config) |
|
| 151 | - return $config_vars; |
|
| 153 | + if ($return_config) { |
|
| 154 | + return $config_vars; |
|
| 155 | + } |
|
| 152 | 156 | |
| 153 | 157 | // Setup the basics of the settings template. |
| 154 | 158 | require_once($sourcedir . '/ManageServer.php'); |
@@ -207,8 +211,9 @@ discard block |
||
| 207 | 211 | foreach ($_POST['smiley_set'] as $id => $val) |
| 208 | 212 | { |
| 209 | 213 | // If this is the set you've marked as default, or the only one remaining, you can't delete it |
| 210 | - if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) |
|
| 211 | - unset($set_paths[$id], $set_names[$id]); |
|
| 214 | + if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) { |
|
| 215 | + unset($set_paths[$id], $set_names[$id]); |
|
| 216 | + } |
|
| 212 | 217 | } |
| 213 | 218 | |
| 214 | 219 | // Shortcut... array_merge() on a single array resets the numeric keys |
@@ -222,8 +227,9 @@ discard block |
||
| 222 | 227 | )); |
| 223 | 228 | } |
| 224 | 229 | // Add a new smiley set. |
| 225 | - elseif (!empty($_POST['add'])) |
|
| 226 | - $context['sub_action'] = 'modifyset'; |
|
| 230 | + elseif (!empty($_POST['add'])) { |
|
| 231 | + $context['sub_action'] = 'modifyset'; |
|
| 232 | + } |
|
| 227 | 233 | // Create or modify a smiley set. |
| 228 | 234 | elseif (isset($_POST['set'])) |
| 229 | 235 | { |
@@ -233,8 +239,9 @@ discard block |
||
| 233 | 239 | // Create a new smiley set. |
| 234 | 240 | if ($_POST['set'] == -1 && isset($_POST['smiley_sets_path'])) |
| 235 | 241 | { |
| 236 | - if (in_array($_POST['smiley_sets_path'], $set_paths)) |
|
| 237 | - fatal_lang_error('smiley_set_already_exists'); |
|
| 242 | + if (in_array($_POST['smiley_sets_path'], $set_paths)) { |
|
| 243 | + fatal_lang_error('smiley_set_already_exists'); |
|
| 244 | + } |
|
| 238 | 245 | |
| 239 | 246 | updateSettings(array( |
| 240 | 247 | 'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . $_POST['smiley_sets_path'], |
@@ -246,12 +253,14 @@ discard block |
||
| 246 | 253 | else |
| 247 | 254 | { |
| 248 | 255 | // Make sure the smiley set exists. |
| 249 | - if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) |
|
| 250 | - fatal_lang_error('smiley_set_not_found'); |
|
| 256 | + if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) { |
|
| 257 | + fatal_lang_error('smiley_set_not_found'); |
|
| 258 | + } |
|
| 251 | 259 | |
| 252 | 260 | // Make sure the path is not yet used by another smileyset. |
| 253 | - if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) |
|
| 254 | - fatal_lang_error('smiley_set_path_already_used'); |
|
| 261 | + if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) { |
|
| 262 | + fatal_lang_error('smiley_set_path_already_used'); |
|
| 263 | + } |
|
| 255 | 264 | |
| 256 | 265 | $set_paths[$_POST['set']] = $_POST['smiley_sets_path']; |
| 257 | 266 | $set_names[$_POST['set']] = $_POST['smiley_sets_name']; |
@@ -263,8 +272,9 @@ discard block |
||
| 263 | 272 | } |
| 264 | 273 | |
| 265 | 274 | // The user might have checked to also import smileys. |
| 266 | - if (!empty($_POST['smiley_sets_import'])) |
|
| 267 | - ImportSmileys($_POST['smiley_sets_path']); |
|
| 275 | + if (!empty($_POST['smiley_sets_import'])) { |
|
| 276 | + ImportSmileys($_POST['smiley_sets_path']); |
|
| 277 | + } |
|
| 268 | 278 | } |
| 269 | 279 | cache_put_data('parsing_smileys', null, 480); |
| 270 | 280 | cache_put_data('posting_smileys', null, 480); |
@@ -273,13 +283,14 @@ discard block |
||
| 273 | 283 | // Load all available smileysets... |
| 274 | 284 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
| 275 | 285 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
| 276 | - foreach ($context['smiley_sets'] as $i => $set) |
|
| 277 | - $context['smiley_sets'][$i] = array( |
|
| 286 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
| 287 | + $context['smiley_sets'][$i] = array( |
|
| 278 | 288 | 'id' => $i, |
| 279 | 289 | 'path' => $smcFunc['htmlspecialchars']($set), |
| 280 | 290 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
| 281 | 291 | 'selected' => $set == $modSettings['smiley_sets_default'] |
| 282 | 292 | ); |
| 293 | + } |
|
| 283 | 294 | |
| 284 | 295 | // Importing any smileys from an existing set? |
| 285 | 296 | if ($context['sub_action'] == 'import') |
@@ -290,8 +301,9 @@ discard block |
||
| 290 | 301 | $_GET['set'] = (int) $_GET['set']; |
| 291 | 302 | |
| 292 | 303 | // Sanity check - then import. |
| 293 | - if (isset($context['smiley_sets'][$_GET['set']])) |
|
| 294 | - ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path'])); |
|
| 304 | + if (isset($context['smiley_sets'][$_GET['set']])) { |
|
| 305 | + ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path'])); |
|
| 306 | + } |
|
| 295 | 307 | |
| 296 | 308 | // Force the process to continue. |
| 297 | 309 | $context['sub_action'] = 'modifyset'; |
@@ -301,15 +313,15 @@ discard block |
||
| 301 | 313 | if ($context['sub_action'] == 'modifyset') |
| 302 | 314 | { |
| 303 | 315 | $_GET['set'] = !isset($_GET['set']) ? -1 : (int) $_GET['set']; |
| 304 | - if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) |
|
| 305 | - $context['current_set'] = array( |
|
| 316 | + if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) { |
|
| 317 | + $context['current_set'] = array( |
|
| 306 | 318 | 'id' => '-1', |
| 307 | 319 | 'path' => '', |
| 308 | 320 | 'name' => '', |
| 309 | 321 | 'selected' => false, |
| 310 | 322 | 'is_new' => true, |
| 311 | 323 | ); |
| 312 | - else |
|
| 324 | + } else |
|
| 313 | 325 | { |
| 314 | 326 | $context['current_set'] = &$context['smiley_sets'][$_GET['set']]; |
| 315 | 327 | $context['current_set']['is_new'] = false; |
@@ -321,13 +333,15 @@ discard block |
||
| 321 | 333 | $dir = dir($modSettings['smileys_dir'] . '/' . $context['current_set']['path']); |
| 322 | 334 | while ($entry = $dir->read()) |
| 323 | 335 | { |
| 324 | - if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
| 325 | - $smileys[strtolower($entry)] = $entry; |
|
| 336 | + if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
| 337 | + $smileys[strtolower($entry)] = $entry; |
|
| 338 | + } |
|
| 326 | 339 | } |
| 327 | 340 | $dir->close(); |
| 328 | 341 | |
| 329 | - if (empty($smileys)) |
|
| 330 | - fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name'])); |
|
| 342 | + if (empty($smileys)) { |
|
| 343 | + fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name'])); |
|
| 344 | + } |
|
| 331 | 345 | |
| 332 | 346 | // Exclude the smileys that are already in the database. |
| 333 | 347 | $request = $smcFunc['db_query']('', ' |
@@ -338,9 +352,10 @@ discard block |
||
| 338 | 352 | 'smiley_list' => $smileys, |
| 339 | 353 | ) |
| 340 | 354 | ); |
| 341 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 342 | - if (isset($smileys[strtolower($row['filename'])])) |
|
| 355 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 356 | + if (isset($smileys[strtolower($row['filename'])])) |
|
| 343 | 357 | unset($smileys[strtolower($row['filename'])]); |
| 358 | + } |
|
| 344 | 359 | $smcFunc['db_free_result']($request); |
| 345 | 360 | |
| 346 | 361 | $context['current_set']['can_import'] = count($smileys); |
@@ -355,13 +370,14 @@ discard block |
||
| 355 | 370 | $dir = dir($modSettings['smileys_dir']); |
| 356 | 371 | while ($entry = $dir->read()) |
| 357 | 372 | { |
| 358 | - if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) |
|
| 359 | - $context['smiley_set_dirs'][] = array( |
|
| 373 | + if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) { |
|
| 374 | + $context['smiley_set_dirs'][] = array( |
|
| 360 | 375 | 'id' => $entry, |
| 361 | 376 | 'path' => $modSettings['smileys_dir'] . '/' . $entry, |
| 362 | 377 | 'selectable' => $entry == $context['current_set']['path'] || !in_array($entry, explode(',', $modSettings['smiley_sets_known'])), |
| 363 | 378 | 'current' => $entry == $context['current_set']['path'], |
| 364 | 379 | ); |
| 380 | + } |
|
| 365 | 381 | } |
| 366 | 382 | $dir->close(); |
| 367 | 383 | } |
@@ -371,8 +387,9 @@ discard block |
||
| 371 | 387 | createToken('admin-mss', 'request'); |
| 372 | 388 | |
| 373 | 389 | // In case we need to import smileys, we need to add the token in now. |
| 374 | - if (isset($context['current_set']['import_url'])) |
|
| 375 | - $context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token']; |
|
| 390 | + if (isset($context['current_set']['import_url'])) { |
|
| 391 | + $context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token']; |
|
| 392 | + } |
|
| 376 | 393 | |
| 377 | 394 | $listOptions = array( |
| 378 | 395 | 'id' => 'smiley_set_list', |
@@ -510,21 +527,23 @@ discard block |
||
| 510 | 527 | $cols['name'][] = $set_names[$i]; |
| 511 | 528 | } |
| 512 | 529 | $sort_flag = strpos($sort, 'DESC') === false ? SORT_ASC : SORT_DESC; |
| 513 | - if (substr($sort, 0, 4) === 'name') |
|
| 514 | - array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']); |
|
| 515 | - elseif (substr($sort, 0, 4) === 'path') |
|
| 516 | - array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']); |
|
| 517 | - else |
|
| 518 | - array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']); |
|
| 530 | + if (substr($sort, 0, 4) === 'name') { |
|
| 531 | + array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']); |
|
| 532 | + } elseif (substr($sort, 0, 4) === 'path') { |
|
| 533 | + array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']); |
|
| 534 | + } else { |
|
| 535 | + array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']); |
|
| 536 | + } |
|
| 519 | 537 | |
| 520 | 538 | $smiley_sets = array(); |
| 521 | - foreach ($cols['id'] as $i => $id) |
|
| 522 | - $smiley_sets[] = array( |
|
| 539 | + foreach ($cols['id'] as $i => $id) { |
|
| 540 | + $smiley_sets[] = array( |
|
| 523 | 541 | 'id' => $id, |
| 524 | 542 | 'path' => $cols['path'][$i], |
| 525 | 543 | 'name' => $cols['name'][$i], |
| 526 | 544 | 'selected' => $cols['path'][$i] == $modSettings['smiley_sets_default'] |
| 527 | 545 | ); |
| 546 | + } |
|
| 528 | 547 | |
| 529 | 548 | return $smiley_sets; |
| 530 | 549 | } |
@@ -553,13 +572,14 @@ discard block |
||
| 553 | 572 | $context['smileys_dir_found'] = is_dir($context['smileys_dir']); |
| 554 | 573 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
| 555 | 574 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
| 556 | - foreach ($context['smiley_sets'] as $i => $set) |
|
| 557 | - $context['smiley_sets'][$i] = array( |
|
| 575 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
| 576 | + $context['smiley_sets'][$i] = array( |
|
| 558 | 577 | 'id' => $i, |
| 559 | 578 | 'path' => $smcFunc['htmlspecialchars']($set), |
| 560 | 579 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
| 561 | 580 | 'selected' => $set == $modSettings['smiley_sets_default'] |
| 562 | 581 | ); |
| 582 | + } |
|
| 563 | 583 | |
| 564 | 584 | // Submitting a form? |
| 565 | 585 | if (isset($_POST[$context['session_var']], $_POST['smiley_code'])) |
@@ -575,8 +595,9 @@ discard block |
||
| 575 | 595 | $_POST['smiley_filename'] = htmltrim__recursive($_POST['smiley_filename']); |
| 576 | 596 | |
| 577 | 597 | // Make sure some code was entered. |
| 578 | - if (empty($_POST['smiley_code'])) |
|
| 579 | - fatal_lang_error('smiley_has_no_code'); |
|
| 598 | + if (empty($_POST['smiley_code'])) { |
|
| 599 | + fatal_lang_error('smiley_has_no_code'); |
|
| 600 | + } |
|
| 580 | 601 | |
| 581 | 602 | // Check whether the new code has duplicates. It should be unique. |
| 582 | 603 | $request = $smcFunc['db_query']('', ' |
@@ -588,8 +609,9 @@ discard block |
||
| 588 | 609 | 'smiley_code' => $_POST['smiley_code'], |
| 589 | 610 | ) |
| 590 | 611 | ); |
| 591 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
| 592 | - fatal_lang_error('smiley_not_unique'); |
|
| 612 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
| 613 | + fatal_lang_error('smiley_not_unique'); |
|
| 614 | + } |
|
| 593 | 615 | $smcFunc['db_free_result']($request); |
| 594 | 616 | |
| 595 | 617 | // If we are uploading - check all the smiley sets are writable! |
@@ -598,38 +620,44 @@ discard block |
||
| 598 | 620 | $writeErrors = array(); |
| 599 | 621 | foreach ($context['smiley_sets'] as $set) |
| 600 | 622 | { |
| 601 | - if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) |
|
| 602 | - $writeErrors[] = $set['path']; |
|
| 623 | + if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) { |
|
| 624 | + $writeErrors[] = $set['path']; |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + if (!empty($writeErrors)) { |
|
| 628 | + fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors))); |
|
| 603 | 629 | } |
| 604 | - if (!empty($writeErrors)) |
|
| 605 | - fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors))); |
|
| 606 | 630 | } |
| 607 | 631 | |
| 608 | 632 | // Uploading just one smiley for all of them? |
| 609 | 633 | if (isset($_POST['sameall']) && isset($_FILES['uploadSmiley']['name']) && $_FILES['uploadSmiley']['name'] != '') |
| 610 | 634 | { |
| 611 | - if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) |
|
| 612 | - fatal_lang_error('smileys_upload_error'); |
|
| 635 | + if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) { |
|
| 636 | + fatal_lang_error('smileys_upload_error'); |
|
| 637 | + } |
|
| 613 | 638 | |
| 614 | 639 | // Sorry, no spaces, dots, or anything else but letters allowed. |
| 615 | 640 | $_FILES['uploadSmiley']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['uploadSmiley']['name']); |
| 616 | 641 | |
| 617 | 642 | // We only allow image files - it's THAT simple - no messing around here... |
| 618 | - if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) |
|
| 619 | - fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
| 643 | + if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) { |
|
| 644 | + fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
| 645 | + } |
|
| 620 | 646 | |
| 621 | 647 | // We only need the filename... |
| 622 | 648 | $destName = basename($_FILES['uploadSmiley']['name']); |
| 623 | 649 | |
| 624 | 650 | // Make sure they aren't trying to upload a nasty file - for their own good here! |
| 625 | - if (in_array(strtolower($destName), $disabledFiles)) |
|
| 626 | - fatal_lang_error('smileys_upload_error_illegal'); |
|
| 651 | + if (in_array(strtolower($destName), $disabledFiles)) { |
|
| 652 | + fatal_lang_error('smileys_upload_error_illegal'); |
|
| 653 | + } |
|
| 627 | 654 | |
| 628 | 655 | // Check if the file already exists... and if not move it to EVERY smiley set directory. |
| 629 | 656 | $i = 0; |
| 630 | 657 | // Keep going until we find a set the file doesn't exist in. (or maybe it exists in all of them?) |
| 631 | - while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) |
|
| 632 | - $i++; |
|
| 658 | + while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) { |
|
| 659 | + $i++; |
|
| 660 | + } |
|
| 633 | 661 | |
| 634 | 662 | // Okay, we're going to put the smiley right here, since it's not there yet! |
| 635 | 663 | if (isset($context['smiley_sets'][$i]['path'])) |
@@ -644,8 +672,9 @@ discard block |
||
| 644 | 672 | $currentPath = $context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName; |
| 645 | 673 | |
| 646 | 674 | // The file is already there! Don't overwrite it! |
| 647 | - if (file_exists($currentPath)) |
|
| 648 | - continue; |
|
| 675 | + if (file_exists($currentPath)) { |
|
| 676 | + continue; |
|
| 677 | + } |
|
| 649 | 678 | |
| 650 | 679 | // Okay, so copy the first one we made to here. |
| 651 | 680 | copy($smileyLocation, $currentPath); |
@@ -662,13 +691,15 @@ discard block |
||
| 662 | 691 | $newName = ''; |
| 663 | 692 | foreach ($_FILES as $name => $data) |
| 664 | 693 | { |
| 665 | - if ($_FILES[$name]['name'] == '') |
|
| 666 | - fatal_lang_error('smileys_upload_error_blank'); |
|
| 694 | + if ($_FILES[$name]['name'] == '') { |
|
| 695 | + fatal_lang_error('smileys_upload_error_blank'); |
|
| 696 | + } |
|
| 667 | 697 | |
| 668 | - if (empty($newName)) |
|
| 669 | - $newName = basename($_FILES[$name]['name']); |
|
| 670 | - elseif (basename($_FILES[$name]['name']) != $newName) |
|
| 671 | - fatal_lang_error('smileys_upload_error_name'); |
|
| 698 | + if (empty($newName)) { |
|
| 699 | + $newName = basename($_FILES[$name]['name']); |
|
| 700 | + } elseif (basename($_FILES[$name]['name']) != $newName) { |
|
| 701 | + fatal_lang_error('smileys_upload_error_name'); |
|
| 702 | + } |
|
| 672 | 703 | } |
| 673 | 704 | |
| 674 | 705 | foreach ($context['smiley_sets'] as $i => $set) |
@@ -676,31 +707,36 @@ discard block |
||
| 676 | 707 | $set['name'] = un_htmlspecialchars($set['name']); |
| 677 | 708 | $set['path'] = un_htmlspecialchars($set['path']); |
| 678 | 709 | |
| 679 | - if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') |
|
| 680 | - continue; |
|
| 710 | + if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') { |
|
| 711 | + continue; |
|
| 712 | + } |
|
| 681 | 713 | |
| 682 | 714 | // Got one... |
| 683 | - if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) |
|
| 684 | - fatal_lang_error('smileys_upload_error'); |
|
| 715 | + if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) { |
|
| 716 | + fatal_lang_error('smileys_upload_error'); |
|
| 717 | + } |
|
| 685 | 718 | |
| 686 | 719 | // Sorry, no spaces, dots, or anything else but letters allowed. |
| 687 | 720 | $_FILES['individual_' . $set['name']]['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['individual_' . $set['name']]['name']); |
| 688 | 721 | |
| 689 | 722 | // We only allow image files - it's THAT simple - no messing around here... |
| 690 | - if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) |
|
| 691 | - fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
| 723 | + if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) { |
|
| 724 | + fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
| 725 | + } |
|
| 692 | 726 | |
| 693 | 727 | // We only need the filename... |
| 694 | 728 | $destName = basename($_FILES['individual_' . $set['name']]['name']); |
| 695 | 729 | |
| 696 | 730 | // Make sure they aren't trying to upload a nasty file - for their own good here! |
| 697 | - if (in_array(strtolower($destName), $disabledFiles)) |
|
| 698 | - fatal_lang_error('smileys_upload_error_illegal'); |
|
| 731 | + if (in_array(strtolower($destName), $disabledFiles)) { |
|
| 732 | + fatal_lang_error('smileys_upload_error_illegal'); |
|
| 733 | + } |
|
| 699 | 734 | |
| 700 | 735 | // If the file exists - ignore it. |
| 701 | 736 | $smileyLocation = $context['smileys_dir'] . '/' . $set['path'] . '/' . $destName; |
| 702 | - if (file_exists($smileyLocation)) |
|
| 703 | - continue; |
|
| 737 | + if (file_exists($smileyLocation)) { |
|
| 738 | + continue; |
|
| 739 | + } |
|
| 704 | 740 | |
| 705 | 741 | // Finally - move the image! |
| 706 | 742 | move_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name'], $smileyLocation); |
@@ -712,8 +748,9 @@ discard block |
||
| 712 | 748 | } |
| 713 | 749 | |
| 714 | 750 | // Also make sure a filename was given. |
| 715 | - if (empty($_POST['smiley_filename'])) |
|
| 716 | - fatal_lang_error('smiley_has_no_filename'); |
|
| 751 | + if (empty($_POST['smiley_filename'])) { |
|
| 752 | + fatal_lang_error('smiley_has_no_filename'); |
|
| 753 | + } |
|
| 717 | 754 | |
| 718 | 755 | // Find the position on the right. |
| 719 | 756 | $smiley_order = '0'; |
@@ -732,8 +769,9 @@ discard block |
||
| 732 | 769 | list ($smiley_order) = $smcFunc['db_fetch_row']($request); |
| 733 | 770 | $smcFunc['db_free_result']($request); |
| 734 | 771 | |
| 735 | - if (empty($smiley_order)) |
|
| 736 | - $smiley_order = '0'; |
|
| 772 | + if (empty($smiley_order)) { |
|
| 773 | + $smiley_order = '0'; |
|
| 774 | + } |
|
| 737 | 775 | } |
| 738 | 776 | $smcFunc['db_insert']('', |
| 739 | 777 | '{db_prefix}smileys', |
@@ -761,17 +799,19 @@ discard block |
||
| 761 | 799 | { |
| 762 | 800 | foreach ($context['smiley_sets'] as $smiley_set) |
| 763 | 801 | { |
| 764 | - if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) |
|
| 765 | - continue; |
|
| 802 | + if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) { |
|
| 803 | + continue; |
|
| 804 | + } |
|
| 766 | 805 | |
| 767 | 806 | $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])); |
| 768 | 807 | while ($entry = $dir->read()) |
| 769 | 808 | { |
| 770 | - if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
| 771 | - $context['filenames'][strtolower($entry)] = array( |
|
| 809 | + if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
| 810 | + $context['filenames'][strtolower($entry)] = array( |
|
| 772 | 811 | 'id' => $smcFunc['htmlspecialchars']($entry), |
| 773 | 812 | 'selected' => false, |
| 774 | 813 | ); |
| 814 | + } |
|
| 775 | 815 | } |
| 776 | 816 | $dir->close(); |
| 777 | 817 | } |
@@ -809,17 +849,19 @@ discard block |
||
| 809 | 849 | // Changing the selected smileys? |
| 810 | 850 | if (isset($_POST['smiley_action']) && !empty($_POST['checked_smileys'])) |
| 811 | 851 | { |
| 812 | - foreach ($_POST['checked_smileys'] as $id => $smiley_id) |
|
| 813 | - $_POST['checked_smileys'][$id] = (int) $smiley_id; |
|
| 852 | + foreach ($_POST['checked_smileys'] as $id => $smiley_id) { |
|
| 853 | + $_POST['checked_smileys'][$id] = (int) $smiley_id; |
|
| 854 | + } |
|
| 814 | 855 | |
| 815 | - if ($_POST['smiley_action'] == 'delete') |
|
| 816 | - $smcFunc['db_query']('', ' |
|
| 856 | + if ($_POST['smiley_action'] == 'delete') { |
|
| 857 | + $smcFunc['db_query']('', ' |
|
| 817 | 858 | DELETE FROM {db_prefix}smileys |
| 818 | 859 | WHERE id_smiley IN ({array_int:checked_smileys})', |
| 819 | 860 | array( |
| 820 | 861 | 'checked_smileys' => $_POST['checked_smileys'], |
| 821 | 862 | ) |
| 822 | 863 | ); |
| 864 | + } |
|
| 823 | 865 | // Changing the status of the smiley? |
| 824 | 866 | else |
| 825 | 867 | { |
@@ -829,8 +871,8 @@ discard block |
||
| 829 | 871 | 'hidden' => 1, |
| 830 | 872 | 'popup' => 2 |
| 831 | 873 | ); |
| 832 | - if (isset($displayTypes[$_POST['smiley_action']])) |
|
| 833 | - $smcFunc['db_query']('', ' |
|
| 874 | + if (isset($displayTypes[$_POST['smiley_action']])) { |
|
| 875 | + $smcFunc['db_query']('', ' |
|
| 834 | 876 | UPDATE {db_prefix}smileys |
| 835 | 877 | SET hidden = {int:display_type} |
| 836 | 878 | WHERE id_smiley IN ({array_int:checked_smileys})', |
@@ -839,6 +881,7 @@ discard block |
||
| 839 | 881 | 'display_type' => $displayTypes[$_POST['smiley_action']], |
| 840 | 882 | ) |
| 841 | 883 | ); |
| 884 | + } |
|
| 842 | 885 | } |
| 843 | 886 | } |
| 844 | 887 | // Create/modify a smiley. |
@@ -864,12 +907,14 @@ discard block |
||
| 864 | 907 | $_POST['smiley_location'] = empty($_POST['smiley_location']) || $_POST['smiley_location'] > 2 || $_POST['smiley_location'] < 0 ? 0 : (int) $_POST['smiley_location']; |
| 865 | 908 | |
| 866 | 909 | // Make sure some code was entered. |
| 867 | - if (empty($_POST['smiley_code'])) |
|
| 868 | - fatal_lang_error('smiley_has_no_code'); |
|
| 910 | + if (empty($_POST['smiley_code'])) { |
|
| 911 | + fatal_lang_error('smiley_has_no_code'); |
|
| 912 | + } |
|
| 869 | 913 | |
| 870 | 914 | // Also make sure a filename was given. |
| 871 | - if (empty($_POST['smiley_filename'])) |
|
| 872 | - fatal_lang_error('smiley_has_no_filename'); |
|
| 915 | + if (empty($_POST['smiley_filename'])) { |
|
| 916 | + fatal_lang_error('smiley_has_no_filename'); |
|
| 917 | + } |
|
| 873 | 918 | |
| 874 | 919 | // Check whether the new code has duplicates. It should be unique. |
| 875 | 920 | $request = $smcFunc['db_query']('', ' |
@@ -883,8 +928,9 @@ discard block |
||
| 883 | 928 | 'smiley_code' => $_POST['smiley_code'], |
| 884 | 929 | ) |
| 885 | 930 | ); |
| 886 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
| 887 | - fatal_lang_error('smiley_not_unique'); |
|
| 931 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
| 932 | + fatal_lang_error('smiley_not_unique'); |
|
| 933 | + } |
|
| 888 | 934 | $smcFunc['db_free_result']($request); |
| 889 | 935 | |
| 890 | 936 | $smcFunc['db_query']('', ' |
@@ -913,13 +959,14 @@ discard block |
||
| 913 | 959 | // Load all known smiley sets. |
| 914 | 960 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
| 915 | 961 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
| 916 | - foreach ($context['smiley_sets'] as $i => $set) |
|
| 917 | - $context['smiley_sets'][$i] = array( |
|
| 962 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
| 963 | + $context['smiley_sets'][$i] = array( |
|
| 918 | 964 | 'id' => $i, |
| 919 | 965 | 'path' => $smcFunc['htmlspecialchars']($set), |
| 920 | 966 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
| 921 | 967 | 'selected' => $set == $modSettings['smiley_sets_default'] |
| 922 | 968 | ); |
| 969 | + } |
|
| 923 | 970 | |
| 924 | 971 | // Prepare overview of all (custom) smileys. |
| 925 | 972 | if ($context['sub_action'] == 'editsmileys') |
@@ -935,9 +982,10 @@ discard block |
||
| 935 | 982 | // Create a list of options for selecting smiley sets. |
| 936 | 983 | $smileyset_option_list = ' |
| 937 | 984 | <select name="set" onchange="changeSet(this.options[this.selectedIndex].value);">'; |
| 938 | - foreach ($context['smiley_sets'] as $smiley_set) |
|
| 939 | - $smileyset_option_list .= ' |
|
| 985 | + foreach ($context['smiley_sets'] as $smiley_set) { |
|
| 986 | + $smileyset_option_list .= ' |
|
| 940 | 987 | <option value="' . $smiley_set['path'] . '"' . ($modSettings['smiley_sets_default'] == $smiley_set['path'] ? ' selected' : '') . '>' . $smiley_set['name'] . '</option>'; |
| 988 | + } |
|
| 941 | 989 | $smileyset_option_list .= ' |
| 942 | 990 | </select>'; |
| 943 | 991 | |
@@ -999,12 +1047,13 @@ discard block |
||
| 999 | 1047 | 'data' => array( |
| 1000 | 1048 | 'function' => function ($rowData) use ($txt) |
| 1001 | 1049 | { |
| 1002 | - if (empty($rowData['hidden'])) |
|
| 1003 | - return $txt['smileys_location_form']; |
|
| 1004 | - elseif ($rowData['hidden'] == 1) |
|
| 1005 | - return $txt['smileys_location_hidden']; |
|
| 1006 | - else |
|
| 1007 | - return $txt['smileys_location_popup']; |
|
| 1050 | + if (empty($rowData['hidden'])) { |
|
| 1051 | + return $txt['smileys_location_form']; |
|
| 1052 | + } elseif ($rowData['hidden'] == 1) { |
|
| 1053 | + return $txt['smileys_location_hidden']; |
|
| 1054 | + } else { |
|
| 1055 | + return $txt['smileys_location_popup']; |
|
| 1056 | + } |
|
| 1008 | 1057 | }, |
| 1009 | 1058 | ), |
| 1010 | 1059 | 'sort' => array( |
@@ -1019,19 +1068,22 @@ discard block |
||
| 1019 | 1068 | 'data' => array( |
| 1020 | 1069 | 'function' => function ($rowData) use ($context, $txt, $modSettings, $smcFunc) |
| 1021 | 1070 | { |
| 1022 | - if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) |
|
| 1023 | - return $smcFunc['htmlspecialchars']($rowData['description']); |
|
| 1071 | + if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) { |
|
| 1072 | + return $smcFunc['htmlspecialchars']($rowData['description']); |
|
| 1073 | + } |
|
| 1024 | 1074 | |
| 1025 | 1075 | // Check if there are smileys missing in some sets. |
| 1026 | 1076 | $missing_sets = array(); |
| 1027 | - foreach ($context['smiley_sets'] as $smiley_set) |
|
| 1028 | - if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename']))) |
|
| 1077 | + foreach ($context['smiley_sets'] as $smiley_set) { |
|
| 1078 | + if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename']))) |
|
| 1029 | 1079 | $missing_sets[] = $smiley_set['path']; |
| 1080 | + } |
|
| 1030 | 1081 | |
| 1031 | 1082 | $description = $smcFunc['htmlspecialchars']($rowData['description']); |
| 1032 | 1083 | |
| 1033 | - if (!empty($missing_sets)) |
|
| 1034 | - $description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets)); |
|
| 1084 | + if (!empty($missing_sets)) { |
|
| 1085 | + $description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets)); |
|
| 1086 | + } |
|
| 1035 | 1087 | |
| 1036 | 1088 | return $description; |
| 1037 | 1089 | }, |
@@ -1147,13 +1199,14 @@ discard block |
||
| 1147 | 1199 | $context['smileys_dir_found'] = is_dir($context['smileys_dir']); |
| 1148 | 1200 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
| 1149 | 1201 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
| 1150 | - foreach ($context['smiley_sets'] as $i => $set) |
|
| 1151 | - $context['smiley_sets'][$i] = array( |
|
| 1202 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
| 1203 | + $context['smiley_sets'][$i] = array( |
|
| 1152 | 1204 | 'id' => $i, |
| 1153 | 1205 | 'path' => $smcFunc['htmlspecialchars']($set), |
| 1154 | 1206 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
| 1155 | 1207 | 'selected' => $set == $modSettings['smiley_sets_default'] |
| 1156 | 1208 | ); |
| 1209 | + } |
|
| 1157 | 1210 | |
| 1158 | 1211 | $context['selected_set'] = $modSettings['smiley_sets_default']; |
| 1159 | 1212 | |
@@ -1163,17 +1216,19 @@ discard block |
||
| 1163 | 1216 | { |
| 1164 | 1217 | foreach ($context['smiley_sets'] as $smiley_set) |
| 1165 | 1218 | { |
| 1166 | - if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) |
|
| 1167 | - continue; |
|
| 1219 | + if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) { |
|
| 1220 | + continue; |
|
| 1221 | + } |
|
| 1168 | 1222 | |
| 1169 | 1223 | $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])); |
| 1170 | 1224 | while ($entry = $dir->read()) |
| 1171 | 1225 | { |
| 1172 | - if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
| 1173 | - $context['filenames'][strtolower($entry)] = array( |
|
| 1226 | + if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
| 1227 | + $context['filenames'][strtolower($entry)] = array( |
|
| 1174 | 1228 | 'id' => $smcFunc['htmlspecialchars']($entry), |
| 1175 | 1229 | 'selected' => false, |
| 1176 | 1230 | ); |
| 1231 | + } |
|
| 1177 | 1232 | } |
| 1178 | 1233 | $dir->close(); |
| 1179 | 1234 | } |
@@ -1188,8 +1243,9 @@ discard block |
||
| 1188 | 1243 | 'current_smiley' => (int) $_REQUEST['smiley'], |
| 1189 | 1244 | ) |
| 1190 | 1245 | ); |
| 1191 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
| 1192 | - fatal_lang_error('smiley_not_found'); |
|
| 1246 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
| 1247 | + fatal_lang_error('smiley_not_found'); |
|
| 1248 | + } |
|
| 1193 | 1249 | $context['current_smiley'] = $smcFunc['db_fetch_assoc']($request); |
| 1194 | 1250 | $smcFunc['db_free_result']($request); |
| 1195 | 1251 | |
@@ -1197,8 +1253,9 @@ discard block |
||
| 1197 | 1253 | $context['current_smiley']['filename'] = $smcFunc['htmlspecialchars']($context['current_smiley']['filename']); |
| 1198 | 1254 | $context['current_smiley']['description'] = $smcFunc['htmlspecialchars']($context['current_smiley']['description']); |
| 1199 | 1255 | |
| 1200 | - if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) |
|
| 1201 | - $context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true; |
|
| 1256 | + if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) { |
|
| 1257 | + $context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true; |
|
| 1258 | + } |
|
| 1202 | 1259 | } |
| 1203 | 1260 | } |
| 1204 | 1261 | |
@@ -1223,8 +1280,9 @@ discard block |
||
| 1223 | 1280 | ) |
| 1224 | 1281 | ); |
| 1225 | 1282 | $smileys = array(); |
| 1226 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1227 | - $smileys[] = $row; |
|
| 1283 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1284 | + $smileys[] = $row; |
|
| 1285 | + } |
|
| 1228 | 1286 | $smcFunc['db_free_result']($request); |
| 1229 | 1287 | |
| 1230 | 1288 | return $smileys; |
@@ -1264,8 +1322,9 @@ discard block |
||
| 1264 | 1322 | $_GET['location'] = empty($_GET['location']) || $_GET['location'] != 'popup' ? 0 : 2; |
| 1265 | 1323 | $_GET['source'] = empty($_GET['source']) ? 0 : (int) $_GET['source']; |
| 1266 | 1324 | |
| 1267 | - if (empty($_GET['source'])) |
|
| 1268 | - fatal_lang_error('smiley_not_found'); |
|
| 1325 | + if (empty($_GET['source'])) { |
|
| 1326 | + fatal_lang_error('smiley_not_found'); |
|
| 1327 | + } |
|
| 1269 | 1328 | |
| 1270 | 1329 | if (!empty($_GET['after'])) |
| 1271 | 1330 | { |
@@ -1281,12 +1340,12 @@ discard block |
||
| 1281 | 1340 | 'after_smiley' => $_GET['after'], |
| 1282 | 1341 | ) |
| 1283 | 1342 | ); |
| 1284 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
| 1285 | - fatal_lang_error('smiley_not_found'); |
|
| 1343 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
| 1344 | + fatal_lang_error('smiley_not_found'); |
|
| 1345 | + } |
|
| 1286 | 1346 | list ($smiley_row, $smiley_order, $smileyLocation) = $smcFunc['db_fetch_row']($request); |
| 1287 | 1347 | $smcFunc['db_free_result']($request); |
| 1288 | - } |
|
| 1289 | - else |
|
| 1348 | + } else |
|
| 1290 | 1349 | { |
| 1291 | 1350 | $smiley_row = (int) $_GET['row']; |
| 1292 | 1351 | $smiley_order = -1; |
@@ -1360,14 +1419,15 @@ discard block |
||
| 1360 | 1419 | $context['move_smiley'] = empty($_REQUEST['move']) ? 0 : (int) $_REQUEST['move']; |
| 1361 | 1420 | |
| 1362 | 1421 | // Make sure all rows are sequential. |
| 1363 | - foreach (array_keys($context['smileys']) as $location) |
|
| 1364 | - $context['smileys'][$location] = array( |
|
| 1422 | + foreach (array_keys($context['smileys']) as $location) { |
|
| 1423 | + $context['smileys'][$location] = array( |
|
| 1365 | 1424 | 'id' => $location, |
| 1366 | 1425 | 'title' => $location == 'postform' ? $txt['smileys_location_form'] : $txt['smileys_location_popup'], |
| 1367 | 1426 | 'description' => $location == 'postform' ? $txt['smileys_location_form_description'] : $txt['smileys_location_popup_description'], |
| 1368 | 1427 | 'last_row' => count($context['smileys'][$location]['rows']), |
| 1369 | 1428 | 'rows' => array_values($context['smileys'][$location]['rows']), |
| 1370 | 1429 | ); |
| 1430 | + } |
|
| 1371 | 1431 | |
| 1372 | 1432 | // Check & fix smileys that are not ordered properly in the database. |
| 1373 | 1433 | foreach (array_keys($context['smileys']) as $location) |
@@ -1392,8 +1452,8 @@ discard block |
||
| 1392 | 1452 | $context['smileys'][$location]['rows'][$id][0]['row'] = $id; |
| 1393 | 1453 | } |
| 1394 | 1454 | // Make sure the smiley order is always sequential. |
| 1395 | - foreach ($smiley_row as $order_id => $smiley) |
|
| 1396 | - if ($order_id != $smiley['order']) |
|
| 1455 | + foreach ($smiley_row as $order_id => $smiley) { |
|
| 1456 | + if ($order_id != $smiley['order']) |
|
| 1397 | 1457 | $smcFunc['db_query']('', ' |
| 1398 | 1458 | UPDATE {db_prefix}smileys |
| 1399 | 1459 | SET smiley_order = {int:new_order} |
@@ -1403,6 +1463,7 @@ discard block |
||
| 1403 | 1463 | 'current_smiley' => $smiley['id'], |
| 1404 | 1464 | ) |
| 1405 | 1465 | ); |
| 1466 | + } |
|
| 1406 | 1467 | } |
| 1407 | 1468 | } |
| 1408 | 1469 | |
@@ -1436,19 +1497,20 @@ discard block |
||
| 1436 | 1497 | |
| 1437 | 1498 | // Check that the smiley is from simplemachines.org, for now... maybe add mirroring later. |
| 1438 | 1499 | // @ TODO: Our current xml files serve http links. Allowing both for now until we serve https. |
| 1439 | - if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) |
|
| 1440 | - fatal_lang_error('not_on_simplemachines'); |
|
| 1500 | + if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) { |
|
| 1501 | + fatal_lang_error('not_on_simplemachines'); |
|
| 1502 | + } |
|
| 1441 | 1503 | |
| 1442 | 1504 | $destination = $packagesdir . '/' . $base_name; |
| 1443 | 1505 | |
| 1444 | - if (file_exists($destination)) |
|
| 1445 | - fatal_lang_error('package_upload_error_exists'); |
|
| 1506 | + if (file_exists($destination)) { |
|
| 1507 | + fatal_lang_error('package_upload_error_exists'); |
|
| 1508 | + } |
|
| 1446 | 1509 | |
| 1447 | 1510 | // Let's copy it to the Packages directory |
| 1448 | 1511 | file_put_contents($destination, fetch_web_data($_REQUEST['set_gz'])); |
| 1449 | 1512 | $testing = true; |
| 1450 | - } |
|
| 1451 | - elseif (isset($_REQUEST['package'])) |
|
| 1513 | + } elseif (isset($_REQUEST['package'])) |
|
| 1452 | 1514 | { |
| 1453 | 1515 | $base_name = basename($_REQUEST['package']); |
| 1454 | 1516 | $name = $smcFunc['htmlspecialchars'](strtok(basename($_REQUEST['package']), '.')); |
@@ -1457,12 +1519,14 @@ discard block |
||
| 1457 | 1519 | $destination = $packagesdir . '/' . basename($_REQUEST['package']); |
| 1458 | 1520 | } |
| 1459 | 1521 | |
| 1460 | - if (empty($destination) || !file_exists($destination)) |
|
| 1461 | - fatal_lang_error('package_no_file', false); |
|
| 1522 | + if (empty($destination) || !file_exists($destination)) { |
|
| 1523 | + fatal_lang_error('package_no_file', false); |
|
| 1524 | + } |
|
| 1462 | 1525 | |
| 1463 | 1526 | // Make sure temp directory exists and is empty. |
| 1464 | - if (file_exists($packagesdir . '/temp')) |
|
| 1465 | - deltree($packagesdir . '/temp', false); |
|
| 1527 | + if (file_exists($packagesdir . '/temp')) { |
|
| 1528 | + deltree($packagesdir . '/temp', false); |
|
| 1529 | + } |
|
| 1466 | 1530 | |
| 1467 | 1531 | if (!mktree($packagesdir . '/temp', 0755)) |
| 1468 | 1532 | { |
@@ -1474,31 +1538,37 @@ discard block |
||
| 1474 | 1538 | create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=smileys;sa=install;set_gz=' . $_REQUEST['set_gz'], 'crash_on_error' => true)); |
| 1475 | 1539 | |
| 1476 | 1540 | deltree($packagesdir . '/temp', false); |
| 1477 | - if (!mktree($packagesdir . '/temp', 0777)) |
|
| 1478 | - fatal_lang_error('package_cant_download', false); |
|
| 1541 | + if (!mktree($packagesdir . '/temp', 0777)) { |
|
| 1542 | + fatal_lang_error('package_cant_download', false); |
|
| 1543 | + } |
|
| 1479 | 1544 | } |
| 1480 | 1545 | } |
| 1481 | 1546 | |
| 1482 | 1547 | $extracted = read_tgz_file($destination, $packagesdir . '/temp'); |
| 1483 | - if (!$extracted) |
|
| 1484 | - fatal_lang_error('packageget_unable', false, array('https://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name)); |
|
| 1485 | - if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) |
|
| 1486 | - foreach ($extracted as $file) |
|
| 1548 | + if (!$extracted) { |
|
| 1549 | + fatal_lang_error('packageget_unable', false, array('https://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name)); |
|
| 1550 | + } |
|
| 1551 | + if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) { |
|
| 1552 | + foreach ($extracted as $file) |
|
| 1487 | 1553 | if (basename($file['filename']) == 'package-info.xml') |
| 1488 | 1554 | { |
| 1489 | 1555 | $base_path = dirname($file['filename']) . '/'; |
| 1556 | + } |
|
| 1490 | 1557 | break; |
| 1491 | 1558 | } |
| 1492 | 1559 | |
| 1493 | - if (!isset($base_path)) |
|
| 1494 | - $base_path = ''; |
|
| 1560 | + if (!isset($base_path)) { |
|
| 1561 | + $base_path = ''; |
|
| 1562 | + } |
|
| 1495 | 1563 | |
| 1496 | - if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) |
|
| 1497 | - fatal_lang_error('package_get_error_missing_xml', false); |
|
| 1564 | + if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) { |
|
| 1565 | + fatal_lang_error('package_get_error_missing_xml', false); |
|
| 1566 | + } |
|
| 1498 | 1567 | |
| 1499 | 1568 | $smileyInfo = getPackageInfo($context['filename']); |
| 1500 | - if (!is_array($smileyInfo)) |
|
| 1501 | - fatal_lang_error($smileyInfo); |
|
| 1569 | + if (!is_array($smileyInfo)) { |
|
| 1570 | + fatal_lang_error($smileyInfo); |
|
| 1571 | + } |
|
| 1502 | 1572 | |
| 1503 | 1573 | // See if it is installed? |
| 1504 | 1574 | $request = $smcFunc['db_query']('', ' |
@@ -1514,8 +1584,9 @@ discard block |
||
| 1514 | 1584 | ) |
| 1515 | 1585 | ); |
| 1516 | 1586 | |
| 1517 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
| 1518 | - fatal_lang_error('package_installed_warning1'); |
|
| 1587 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
| 1588 | + fatal_lang_error('package_installed_warning1'); |
|
| 1589 | + } |
|
| 1519 | 1590 | |
| 1520 | 1591 | // Everything is fine, now it's time to do something |
| 1521 | 1592 | $actions = parsePackageInfo($smileyInfo['xml'], true, 'install'); |
@@ -1530,23 +1601,23 @@ discard block |
||
| 1530 | 1601 | if ($action['type'] == 'readme' || $action['type'] == 'license') |
| 1531 | 1602 | { |
| 1532 | 1603 | $type = 'package_' . $action['type']; |
| 1533 | - if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) |
|
| 1534 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r")); |
|
| 1535 | - elseif (file_exists($action['filename'])) |
|
| 1536 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
| 1604 | + if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) { |
|
| 1605 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r")); |
|
| 1606 | + } elseif (file_exists($action['filename'])) { |
|
| 1607 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
| 1608 | + } |
|
| 1537 | 1609 | |
| 1538 | 1610 | if (!empty($action['parse_bbc'])) |
| 1539 | 1611 | { |
| 1540 | 1612 | require_once($sourcedir . '/Subs-Post.php'); |
| 1541 | 1613 | preparsecode($context[$type]); |
| 1542 | 1614 | $context[$type] = parse_bbc($context[$type]); |
| 1615 | + } else { |
|
| 1616 | + $context[$type] = nl2br($context[$type]); |
|
| 1543 | 1617 | } |
| 1544 | - else |
|
| 1545 | - $context[$type] = nl2br($context[$type]); |
|
| 1546 | 1618 | |
| 1547 | 1619 | continue; |
| 1548 | - } |
|
| 1549 | - elseif ($action['type'] == 'require-dir') |
|
| 1620 | + } elseif ($action['type'] == 'require-dir') |
|
| 1550 | 1621 | { |
| 1551 | 1622 | // Do this one... |
| 1552 | 1623 | $thisAction = array( |
@@ -1565,12 +1636,12 @@ discard block |
||
| 1565 | 1636 | ); |
| 1566 | 1637 | } |
| 1567 | 1638 | // @todo None given? |
| 1568 | - if (empty($thisAction['description'])) |
|
| 1569 | - $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
| 1639 | + if (empty($thisAction['description'])) { |
|
| 1640 | + $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
| 1641 | + } |
|
| 1570 | 1642 | |
| 1571 | 1643 | $context['actions'][] = $thisAction; |
| 1572 | - } |
|
| 1573 | - elseif ($action['type'] == 'credits') |
|
| 1644 | + } elseif ($action['type'] == 'credits') |
|
| 1574 | 1645 | { |
| 1575 | 1646 | // Time to build the billboard |
| 1576 | 1647 | $credits_tag = array( |
@@ -1630,12 +1701,14 @@ discard block |
||
| 1630 | 1701 | cache_put_data('posting_smileys', null, 480); |
| 1631 | 1702 | } |
| 1632 | 1703 | |
| 1633 | - if (file_exists($packagesdir . '/temp')) |
|
| 1634 | - deltree($packagesdir . '/temp'); |
|
| 1704 | + if (file_exists($packagesdir . '/temp')) { |
|
| 1705 | + deltree($packagesdir . '/temp'); |
|
| 1706 | + } |
|
| 1635 | 1707 | |
| 1636 | - if (!$testing) |
|
| 1637 | - redirectexit('action=admin;area=smileys'); |
|
| 1638 | -} |
|
| 1708 | + if (!$testing) { |
|
| 1709 | + redirectexit('action=admin;area=smileys'); |
|
| 1710 | + } |
|
| 1711 | + } |
|
| 1639 | 1712 | |
| 1640 | 1713 | /** |
| 1641 | 1714 | * A function to import new smileys from an existing directory into the database. |
@@ -1646,15 +1719,17 @@ discard block |
||
| 1646 | 1719 | { |
| 1647 | 1720 | global $modSettings, $smcFunc; |
| 1648 | 1721 | |
| 1649 | - if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) |
|
| 1650 | - fatal_lang_error('smiley_set_unable_to_import'); |
|
| 1722 | + if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) { |
|
| 1723 | + fatal_lang_error('smiley_set_unable_to_import'); |
|
| 1724 | + } |
|
| 1651 | 1725 | |
| 1652 | 1726 | $smileys = array(); |
| 1653 | 1727 | $dir = dir($modSettings['smileys_dir'] . '/' . $smileyPath); |
| 1654 | 1728 | while ($entry = $dir->read()) |
| 1655 | 1729 | { |
| 1656 | - if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
| 1657 | - $smileys[strtolower($entry)] = $entry; |
|
| 1730 | + if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
| 1731 | + $smileys[strtolower($entry)] = $entry; |
|
| 1732 | + } |
|
| 1658 | 1733 | } |
| 1659 | 1734 | $dir->close(); |
| 1660 | 1735 | |
@@ -1667,9 +1742,10 @@ discard block |
||
| 1667 | 1742 | 'smiley_list' => $smileys, |
| 1668 | 1743 | ) |
| 1669 | 1744 | ); |
| 1670 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1671 | - if (isset($smileys[strtolower($row['filename'])])) |
|
| 1745 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1746 | + if (isset($smileys[strtolower($row['filename'])])) |
|
| 1672 | 1747 | unset($smileys[strtolower($row['filename'])]); |
| 1748 | + } |
|
| 1673 | 1749 | $smcFunc['db_free_result']($request); |
| 1674 | 1750 | |
| 1675 | 1751 | $request = $smcFunc['db_query']('', ' |
@@ -1686,9 +1762,10 @@ discard block |
||
| 1686 | 1762 | $smcFunc['db_free_result']($request); |
| 1687 | 1763 | |
| 1688 | 1764 | $new_smileys = array(); |
| 1689 | - foreach ($smileys as $smiley) |
|
| 1690 | - if (strlen($smiley) <= 48) |
|
| 1765 | + foreach ($smileys as $smiley) { |
|
| 1766 | + if (strlen($smiley) <= 48) |
|
| 1691 | 1767 | $new_smileys[] = array(':' . strtok($smiley, '.') . ':', $smiley, strtok($smiley, '.'), 0, ++$smiley_order); |
| 1768 | + } |
|
| 1692 | 1769 | |
| 1693 | 1770 | if (!empty($new_smileys)) |
| 1694 | 1771 | { |
@@ -1753,8 +1830,9 @@ discard block |
||
| 1753 | 1830 | if (isset($_POST['delete']) && !empty($_POST['checked_icons'])) |
| 1754 | 1831 | { |
| 1755 | 1832 | $deleteIcons = array(); |
| 1756 | - foreach ($_POST['checked_icons'] as $icon) |
|
| 1757 | - $deleteIcons[] = (int) $icon; |
|
| 1833 | + foreach ($_POST['checked_icons'] as $icon) { |
|
| 1834 | + $deleteIcons[] = (int) $icon; |
|
| 1835 | + } |
|
| 1758 | 1836 | |
| 1759 | 1837 | // Do the actual delete! |
| 1760 | 1838 | $smcFunc['db_query']('', ' |
@@ -1771,35 +1849,41 @@ discard block |
||
| 1771 | 1849 | $_GET['icon'] = (int) $_GET['icon']; |
| 1772 | 1850 | |
| 1773 | 1851 | // Do some preperation with the data... like check the icon exists *somewhere* |
| 1774 | - if (strpos($_POST['icon_filename'], '.png') !== false) |
|
| 1775 | - $_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4); |
|
| 1776 | - if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) |
|
| 1777 | - fatal_lang_error('icon_not_found'); |
|
| 1852 | + if (strpos($_POST['icon_filename'], '.png') !== false) { |
|
| 1853 | + $_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4); |
|
| 1854 | + } |
|
| 1855 | + if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) { |
|
| 1856 | + fatal_lang_error('icon_not_found'); |
|
| 1857 | + } |
|
| 1778 | 1858 | // There is a 16 character limit on message icons... |
| 1779 | - elseif (strlen($_POST['icon_filename']) > 16) |
|
| 1780 | - fatal_lang_error('icon_name_too_long'); |
|
| 1781 | - elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) |
|
| 1782 | - fatal_lang_error('icon_after_itself'); |
|
| 1859 | + elseif (strlen($_POST['icon_filename']) > 16) { |
|
| 1860 | + fatal_lang_error('icon_name_too_long'); |
|
| 1861 | + } elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) { |
|
| 1862 | + fatal_lang_error('icon_after_itself'); |
|
| 1863 | + } |
|
| 1783 | 1864 | |
| 1784 | 1865 | // First do the sorting... if this is an edit reduce the order of everything after it by one ;) |
| 1785 | 1866 | if ($_GET['icon'] != 0) |
| 1786 | 1867 | { |
| 1787 | 1868 | $oldOrder = $context['icons'][$_GET['icon']]['true_order']; |
| 1788 | - foreach ($context['icons'] as $id => $data) |
|
| 1789 | - if ($data['true_order'] > $oldOrder) |
|
| 1869 | + foreach ($context['icons'] as $id => $data) { |
|
| 1870 | + if ($data['true_order'] > $oldOrder) |
|
| 1790 | 1871 | $context['icons'][$id]['true_order']--; |
| 1872 | + } |
|
| 1791 | 1873 | } |
| 1792 | 1874 | |
| 1793 | 1875 | // If there are no existing icons and this is a new one, set the id to 1 (mainly for non-mysql) |
| 1794 | - if (empty($_GET['icon']) && empty($context['icons'])) |
|
| 1795 | - $_GET['icon'] = 1; |
|
| 1876 | + if (empty($_GET['icon']) && empty($context['icons'])) { |
|
| 1877 | + $_GET['icon'] = 1; |
|
| 1878 | + } |
|
| 1796 | 1879 | |
| 1797 | 1880 | // Get the new order. |
| 1798 | 1881 | $newOrder = $_POST['icon_location'] == 0 ? 0 : $context['icons'][$_POST['icon_location']]['true_order'] + 1; |
| 1799 | 1882 | // Do the same, but with the one that used to be after this icon, done to avoid conflict. |
| 1800 | - foreach ($context['icons'] as $id => $data) |
|
| 1801 | - if ($data['true_order'] >= $newOrder) |
|
| 1883 | + foreach ($context['icons'] as $id => $data) { |
|
| 1884 | + if ($data['true_order'] >= $newOrder) |
|
| 1802 | 1885 | $context['icons'][$id]['true_order']++; |
| 1886 | + } |
|
| 1803 | 1887 | |
| 1804 | 1888 | // Finally set the current icon's position! |
| 1805 | 1889 | $context['icons'][$_GET['icon']]['true_order'] = $newOrder; |
@@ -1817,8 +1901,7 @@ discard block |
||
| 1817 | 1901 | if ($id != 0) |
| 1818 | 1902 | { |
| 1819 | 1903 | $iconInsert[] = array($id, $icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']); |
| 1820 | - } |
|
| 1821 | - else |
|
| 1904 | + } else |
|
| 1822 | 1905 | { |
| 1823 | 1906 | $iconInsert_new[] = array($icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']); |
| 1824 | 1907 | } |
@@ -1843,8 +1926,9 @@ discard block |
||
| 1843 | 1926 | } |
| 1844 | 1927 | |
| 1845 | 1928 | // Unless we're adding a new thing, we'll escape |
| 1846 | - if (!isset($_POST['add'])) |
|
| 1847 | - redirectexit('action=admin;area=smileys;sa=editicons'); |
|
| 1929 | + if (!isset($_POST['add'])) { |
|
| 1930 | + redirectexit('action=admin;area=smileys;sa=editicons'); |
|
| 1931 | + } |
|
| 1848 | 1932 | } |
| 1849 | 1933 | |
| 1850 | 1934 | $context[$context['admin_menu_name']]['current_subsection'] = 'editicons'; |
@@ -1954,8 +2038,9 @@ discard block |
||
| 1954 | 2038 | $context['new_icon'] = !isset($_GET['icon']); |
| 1955 | 2039 | |
| 1956 | 2040 | // Get the properties of the current icon from the icon list. |
| 1957 | - if (!$context['new_icon']) |
|
| 1958 | - $context['icon'] = $context['icons'][$_GET['icon']]; |
|
| 2041 | + if (!$context['new_icon']) { |
|
| 2042 | + $context['icon'] = $context['icons'][$_GET['icon']]; |
|
| 2043 | + } |
|
| 1959 | 2044 | |
| 1960 | 2045 | // Get a list of boards needed for assigning this icon to a specific board. |
| 1961 | 2046 | $boardListOptions = array( |
@@ -1989,8 +2074,9 @@ discard block |
||
| 1989 | 2074 | ); |
| 1990 | 2075 | |
| 1991 | 2076 | $message_icons = array(); |
| 1992 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1993 | - $message_icons[] = $row; |
|
| 2077 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2078 | + $message_icons[] = $row; |
|
| 2079 | + } |
|
| 1994 | 2080 | $smcFunc['db_free_result']($request); |
| 1995 | 2081 | |
| 1996 | 2082 | return $message_icons; |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 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 | * Outputs xml data representing recent information or a profile. |
@@ -37,8 +38,9 @@ discard block |
||
| 37 | 38 | global $query_this_board, $smcFunc, $forum_version, $settings; |
| 38 | 39 | |
| 39 | 40 | // If it's not enabled, die. |
| 40 | - if (empty($modSettings['xmlnews_enable'])) |
|
| 41 | - obExit(false); |
|
| 41 | + if (empty($modSettings['xmlnews_enable'])) { |
|
| 42 | + obExit(false); |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | loadLanguage('Stats'); |
| 44 | 46 | |
@@ -64,8 +66,9 @@ discard block |
||
| 64 | 66 | if (!empty($_REQUEST['c']) && empty($board)) |
| 65 | 67 | { |
| 66 | 68 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
| 67 | - foreach ($_REQUEST['c'] as $i => $c) |
|
| 68 | - $_REQUEST['c'][$i] = (int) $c; |
|
| 69 | + foreach ($_REQUEST['c'] as $i => $c) { |
|
| 70 | + $_REQUEST['c'][$i] = (int) $c; |
|
| 71 | + } |
|
| 69 | 72 | |
| 70 | 73 | if (count($_REQUEST['c']) == 1) |
| 71 | 74 | { |
@@ -101,18 +104,20 @@ discard block |
||
| 101 | 104 | } |
| 102 | 105 | $smcFunc['db_free_result']($request); |
| 103 | 106 | |
| 104 | - if (!empty($boards)) |
|
| 105 | - $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
| 107 | + if (!empty($boards)) { |
|
| 108 | + $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
| 109 | + } |
|
| 106 | 110 | |
| 107 | 111 | // Try to limit the number of messages we look through. |
| 108 | - if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) |
|
| 109 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5); |
|
| 110 | - } |
|
| 111 | - elseif (!empty($_REQUEST['boards'])) |
|
| 112 | + if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) { |
|
| 113 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5); |
|
| 114 | + } |
|
| 115 | + } elseif (!empty($_REQUEST['boards'])) |
|
| 112 | 116 | { |
| 113 | 117 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
| 114 | - foreach ($_REQUEST['boards'] as $i => $b) |
|
| 115 | - $_REQUEST['boards'][$i] = (int) $b; |
|
| 118 | + foreach ($_REQUEST['boards'] as $i => $b) { |
|
| 119 | + $_REQUEST['boards'][$i] = (int) $b; |
|
| 120 | + } |
|
| 116 | 121 | |
| 117 | 122 | $request = $smcFunc['db_query']('', ' |
| 118 | 123 | SELECT b.id_board, b.num_posts, b.name |
@@ -128,29 +133,32 @@ discard block |
||
| 128 | 133 | |
| 129 | 134 | // Either the board specified doesn't exist or you have no access. |
| 130 | 135 | $num_boards = $smcFunc['db_num_rows']($request); |
| 131 | - if ($num_boards == 0) |
|
| 132 | - fatal_lang_error('no_board'); |
|
| 136 | + if ($num_boards == 0) { |
|
| 137 | + fatal_lang_error('no_board'); |
|
| 138 | + } |
|
| 133 | 139 | |
| 134 | 140 | $total_posts = 0; |
| 135 | 141 | $boards = array(); |
| 136 | 142 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 137 | 143 | { |
| 138 | - if ($num_boards == 1) |
|
| 139 | - $feed_meta['title'] = ' - ' . strip_tags($row['name']); |
|
| 144 | + if ($num_boards == 1) { |
|
| 145 | + $feed_meta['title'] = ' - ' . strip_tags($row['name']); |
|
| 146 | + } |
|
| 140 | 147 | |
| 141 | 148 | $boards[] = $row['id_board']; |
| 142 | 149 | $total_posts += $row['num_posts']; |
| 143 | 150 | } |
| 144 | 151 | $smcFunc['db_free_result']($request); |
| 145 | 152 | |
| 146 | - if (!empty($boards)) |
|
| 147 | - $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
| 153 | + if (!empty($boards)) { |
|
| 154 | + $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
| 155 | + } |
|
| 148 | 156 | |
| 149 | 157 | // The more boards, the more we're going to look through... |
| 150 | - if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) |
|
| 151 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5); |
|
| 152 | - } |
|
| 153 | - elseif (!empty($board)) |
|
| 158 | + if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) { |
|
| 159 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5); |
|
| 160 | + } |
|
| 161 | + } elseif (!empty($board)) |
|
| 154 | 162 | { |
| 155 | 163 | $request = $smcFunc['db_query']('', ' |
| 156 | 164 | SELECT num_posts |
@@ -170,10 +178,10 @@ discard block |
||
| 170 | 178 | $query_this_board = 'b.id_board = ' . $board; |
| 171 | 179 | |
| 172 | 180 | // Try to look through just a few messages, if at all possible. |
| 173 | - if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) |
|
| 174 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5); |
|
| 175 | - } |
|
| 176 | - else |
|
| 181 | + if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) { |
|
| 182 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5); |
|
| 183 | + } |
|
| 184 | + } else |
|
| 177 | 185 | { |
| 178 | 186 | $query_this_board = '{query_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' |
| 179 | 187 | AND b.id_board != ' . $modSettings['recycle_board'] : ''); |
@@ -196,30 +204,35 @@ discard block |
||
| 196 | 204 | // Easy adding of sub actions |
| 197 | 205 | call_integration_hook('integrate_xmlfeeds', array(&$subActions)); |
| 198 | 206 | |
| 199 | - if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) |
|
| 200 | - $_GET['sa'] = 'recent'; |
|
| 207 | + if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) { |
|
| 208 | + $_GET['sa'] = 'recent'; |
|
| 209 | + } |
|
| 201 | 210 | |
| 202 | 211 | // We only want some information, not all of it. |
| 203 | 212 | $cachekey = array($xml_format, $_GET['action'], $_GET['limit'], $_GET['sa']); |
| 204 | - foreach (array('board', 'boards', 'c') as $var) |
|
| 205 | - if (isset($_REQUEST[$var])) |
|
| 213 | + foreach (array('board', 'boards', 'c') as $var) { |
|
| 214 | + if (isset($_REQUEST[$var])) |
|
| 206 | 215 | $cachekey[] = $_REQUEST[$var]; |
| 216 | + } |
|
| 207 | 217 | $cachekey = md5(json_encode($cachekey) . (!empty($query_this_board) ? $query_this_board : '')); |
| 208 | 218 | $cache_t = microtime(); |
| 209 | 219 | |
| 210 | 220 | // Get the associative array representing the xml. |
| 211 | - if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) |
|
| 212 | - $xml_data = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240); |
|
| 221 | + if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) { |
|
| 222 | + $xml_data = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240); |
|
| 223 | + } |
|
| 213 | 224 | if (empty($xml_data)) |
| 214 | 225 | { |
| 215 | 226 | $call = call_helper($subActions[$_GET['sa']][0], true); |
| 216 | 227 | |
| 217 | - if (!empty($call)) |
|
| 218 | - $xml_data = call_user_func($call, $xml_format); |
|
| 228 | + if (!empty($call)) { |
|
| 229 | + $xml_data = call_user_func($call, $xml_format); |
|
| 230 | + } |
|
| 219 | 231 | |
| 220 | 232 | if (!empty($modSettings['cache_enable']) && (($user_info['is_guest'] && $modSettings['cache_enable'] >= 3) |
| 221 | - || (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2)))) |
|
| 222 | - cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml_data, 240); |
|
| 233 | + || (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2)))) { |
|
| 234 | + cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml_data, 240); |
|
| 235 | + } |
|
| 223 | 236 | } |
| 224 | 237 | |
| 225 | 238 | $feed_meta['title'] = $smcFunc['htmlspecialchars'](strip_tags($context['forum_name'])) . (isset($feed_meta['title']) ? $feed_meta['title'] : ''); |
@@ -259,43 +272,49 @@ discard block |
||
| 259 | 272 | call_integration_hook('integrate_xml_data', array(&$xml_data, &$feed_meta, &$namespaces, &$extraFeedTags, &$forceCdataKeys, &$nsKeys, $xml_format, $_GET['sa'])); |
| 260 | 273 | |
| 261 | 274 | // These can't be empty |
| 262 | - foreach (array('title', 'desc', 'source') as $mkey) |
|
| 263 | - $feed_meta[$mkey] = !empty($feed_meta[$mkey]) ? $feed_meta[$mkey] : $orig_feed_meta[$mkey]; |
|
| 275 | + foreach (array('title', 'desc', 'source') as $mkey) { |
|
| 276 | + $feed_meta[$mkey] = !empty($feed_meta[$mkey]) ? $feed_meta[$mkey] : $orig_feed_meta[$mkey]; |
|
| 277 | + } |
|
| 264 | 278 | |
| 265 | 279 | // Sanitize basic feed metadata values |
| 266 | - foreach ($feed_meta as $mkey => $mvalue) |
|
| 267 | - $feed_meta[$mkey] = cdata_parse(strip_tags(fix_possible_url($feed_meta[$mkey]))); |
|
| 280 | + foreach ($feed_meta as $mkey => $mvalue) { |
|
| 281 | + $feed_meta[$mkey] = cdata_parse(strip_tags(fix_possible_url($feed_meta[$mkey]))); |
|
| 282 | + } |
|
| 268 | 283 | |
| 269 | 284 | $ns_string = ''; |
| 270 | 285 | if (!empty($namespaces[$xml_format])) |
| 271 | 286 | { |
| 272 | - foreach ($namespaces[$xml_format] as $nsprefix => $nsurl) |
|
| 273 | - $ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"'; |
|
| 287 | + foreach ($namespaces[$xml_format] as $nsprefix => $nsurl) { |
|
| 288 | + $ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"'; |
|
| 289 | + } |
|
| 274 | 290 | } |
| 275 | 291 | |
| 276 | 292 | $extraFeedTags_string = ''; |
| 277 | 293 | if (!empty($extraFeedTags[$xml_format])) |
| 278 | 294 | { |
| 279 | 295 | $indent = "\t" . ($xml_format !== 'atom' ? "\t" : ''); |
| 280 | - foreach ($extraFeedTags[$xml_format] as $extraTag) |
|
| 281 | - $extraFeedTags_string .= "\n" . $indent . $extraTag; |
|
| 296 | + foreach ($extraFeedTags[$xml_format] as $extraTag) { |
|
| 297 | + $extraFeedTags_string .= "\n" . $indent . $extraTag; |
|
| 298 | + } |
|
| 282 | 299 | } |
| 283 | 300 | |
| 284 | 301 | // This is an xml file.... |
| 285 | 302 | ob_end_clean(); |
| 286 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
| 287 | - @ob_start('ob_gzhandler'); |
|
| 288 | - else |
|
| 289 | - ob_start(); |
|
| 303 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
| 304 | + @ob_start('ob_gzhandler'); |
|
| 305 | + } else { |
|
| 306 | + ob_start(); |
|
| 307 | + } |
|
| 290 | 308 | |
| 291 | - if ($xml_format == 'smf' || isset($_REQUEST['debug'])) |
|
| 292 | - header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 293 | - elseif ($xml_format == 'rss' || $xml_format == 'rss2') |
|
| 294 | - header('Content-Type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 295 | - elseif ($xml_format == 'atom') |
|
| 296 | - header('Content-Type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 297 | - elseif ($xml_format == 'rdf') |
|
| 298 | - header('Content-Type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 309 | + if ($xml_format == 'smf' || isset($_REQUEST['debug'])) { |
|
| 310 | + header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 311 | + } elseif ($xml_format == 'rss' || $xml_format == 'rss2') { |
|
| 312 | + header('Content-Type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 313 | + } elseif ($xml_format == 'atom') { |
|
| 314 | + header('Content-Type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 315 | + } elseif ($xml_format == 'rdf') { |
|
| 316 | + header('Content-Type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 317 | + } |
|
| 299 | 318 | |
| 300 | 319 | // First, output the xml header. |
| 301 | 320 | echo '<?xml version="1.0" encoding="', $context['character_set'], '"?' . '>'; |
@@ -303,10 +322,11 @@ discard block |
||
| 303 | 322 | // Are we outputting an rss feed or one with more information? |
| 304 | 323 | if ($xml_format == 'rss' || $xml_format == 'rss2') |
| 305 | 324 | { |
| 306 | - if ($xml_format == 'rss2') |
|
| 307 | - foreach ($_REQUEST as $var => $val) |
|
| 325 | + if ($xml_format == 'rss2') { |
|
| 326 | + foreach ($_REQUEST as $var => $val) |
|
| 308 | 327 | if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
| 309 | 328 | $url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val); |
| 329 | + } |
|
| 310 | 330 | |
| 311 | 331 | // Start with an RSS 2.0 header. |
| 312 | 332 | echo ' |
@@ -327,9 +347,10 @@ discard block |
||
| 327 | 347 | <language>' . $feed_meta['language'] . '</language>' : ''; |
| 328 | 348 | |
| 329 | 349 | // RSS2 calls for this. |
| 330 | - if ($xml_format == 'rss2') |
|
| 331 | - echo ' |
|
| 350 | + if ($xml_format == 'rss2') { |
|
| 351 | + echo ' |
|
| 332 | 352 | <atom:link rel="self" type="application/rss+xml" href="', $scripturl, !empty($url_parts) ? '?' . implode(';', $url_parts) : '', '" />'; |
| 353 | + } |
|
| 333 | 354 | |
| 334 | 355 | echo $extraFeedTags_string; |
| 335 | 356 | |
@@ -340,12 +361,12 @@ discard block |
||
| 340 | 361 | echo ' |
| 341 | 362 | </channel> |
| 342 | 363 | </rss>'; |
| 343 | - } |
|
| 344 | - elseif ($xml_format == 'atom') |
|
| 364 | + } elseif ($xml_format == 'atom') |
|
| 345 | 365 | { |
| 346 | - foreach ($_REQUEST as $var => $val) |
|
| 347 | - if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
|
| 366 | + foreach ($_REQUEST as $var => $val) { |
|
| 367 | + if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
|
| 348 | 368 | $url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val); |
| 369 | + } |
|
| 349 | 370 | |
| 350 | 371 | echo ' |
| 351 | 372 | <feed', $ns_string, !empty($feed_meta['language']) ? ' xml:lang="' . $feed_meta['language'] . '"' : '', '> |
@@ -371,8 +392,7 @@ discard block |
||
| 371 | 392 | |
| 372 | 393 | echo ' |
| 373 | 394 | </feed>'; |
| 374 | - } |
|
| 375 | - elseif ($xml_format == 'rdf') |
|
| 395 | + } elseif ($xml_format == 'rdf') |
|
| 376 | 396 | { |
| 377 | 397 | echo ' |
| 378 | 398 | <rdf:RDF', $ns_string, '> |
@@ -437,13 +457,15 @@ discard block |
||
| 437 | 457 | { |
| 438 | 458 | global $modSettings, $context, $scripturl; |
| 439 | 459 | |
| 440 | - if (substr($val, 0, strlen($scripturl)) != $scripturl) |
|
| 441 | - return $val; |
|
| 460 | + if (substr($val, 0, strlen($scripturl)) != $scripturl) { |
|
| 461 | + return $val; |
|
| 462 | + } |
|
| 442 | 463 | |
| 443 | 464 | call_integration_hook('integrate_fix_url', array(&$val)); |
| 444 | 465 | |
| 445 | - if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) |
|
| 446 | - return $val; |
|
| 466 | + if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) { |
|
| 467 | + return $val; |
|
| 468 | + } |
|
| 447 | 469 | |
| 448 | 470 | $val = preg_replace_callback('~\b' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?$~', function($m) use ($scripturl) |
| 449 | 471 | { |
@@ -466,8 +488,9 @@ discard block |
||
| 466 | 488 | global $smcFunc; |
| 467 | 489 | |
| 468 | 490 | // Do we even need to do this? |
| 469 | - if (strpbrk($data, '<>&') == false && $force !== true) |
|
| 470 | - return $data; |
|
| 491 | + if (strpbrk($data, '<>&') == false && $force !== true) { |
|
| 492 | + return $data; |
|
| 493 | + } |
|
| 471 | 494 | |
| 472 | 495 | $cdata = '<, |
| 478 | 501 | $smcFunc['strpos']($data, ']', $pos), |
| 479 | 502 | ); |
| 480 | - if ($ns != '') |
|
| 481 | - $positions[] = $smcFunc['strpos']($data, '<', $pos); |
|
| 503 | + if ($ns != '') { |
|
| 504 | + $positions[] = $smcFunc['strpos']($data, '<', $pos); |
|
| 505 | + } |
|
| 482 | 506 | foreach ($positions as $k => $dummy) |
| 483 | 507 | { |
| 484 | - if ($dummy === false) |
|
| 485 | - unset($positions[$k]); |
|
| 508 | + if ($dummy === false) { |
|
| 509 | + unset($positions[$k]); |
|
| 510 | + } |
|
| 486 | 511 | } |
| 487 | 512 | |
| 488 | 513 | $old = $pos; |
| 489 | 514 | $pos = empty($positions) ? $n : min($positions); |
| 490 | 515 | |
| 491 | - if ($pos - $old > 0) |
|
| 492 | - $cdata .= $smcFunc['substr']($data, $old, $pos - $old); |
|
| 493 | - if ($pos >= $n) |
|
| 494 | - break; |
|
| 516 | + if ($pos - $old > 0) { |
|
| 517 | + $cdata .= $smcFunc['substr']($data, $old, $pos - $old); |
|
| 518 | + } |
|
| 519 | + if ($pos >= $n) { |
|
| 520 | + break; |
|
| 521 | + } |
|
| 495 | 522 | |
| 496 | 523 | if ($smcFunc['substr']($data, $pos, 1) == '<') |
| 497 | 524 | { |
| 498 | 525 | $pos2 = $smcFunc['strpos']($data, '>', $pos); |
| 499 | - if ($pos2 === false) |
|
| 500 | - $pos2 = $n; |
|
| 501 | - if ($smcFunc['substr']($data, $pos + 1, 1) == '/') |
|
| 502 | - $cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA['; |
|
| 503 | - else |
|
| 504 | - $cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '< == '/') { |
|
| 530 | + $cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA['; |
|
| 531 | + } else { |
|
| 532 | + $cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '< == ']') |
|
| 535 | + } elseif ($smcFunc['substr']($data, $pos, 1) == ']') |
|
| 508 | 536 | { |
| 509 | 537 | $cdata .= ']]>]< == '&') |
|
| 539 | + } elseif ($smcFunc['substr']($data, $pos, 1) == '&') |
|
| 513 | 540 | { |
| 514 | 541 | $pos2 = $smcFunc['strpos']($data, ';', $pos); |
| 515 | - if ($pos2 === false) |
|
| 516 | - $pos2 = $n; |
|
| 542 | + if ($pos2 === false) { |
|
| 543 | + $pos2 = $n; |
|
| 544 | + } |
|
| 517 | 545 | $ent = $smcFunc['substr']($data, $pos + 1, $pos2 - $pos - 1); |
| 518 | 546 | |
| 519 | - if ($smcFunc['substr']($data, $pos + 1, 1) == '#') |
|
| 520 | - $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
| 521 | - elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) |
|
| 522 | - $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '< == '#') { |
|
| 548 | + $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
| 549 | + } elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) { |
|
| 550 | + $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
| 551 | + } |
|
| 523 | 552 | |
| 524 | 553 | $pos = $pos2 + 1; |
| 525 | 554 | } |
@@ -558,8 +587,9 @@ discard block |
||
| 558 | 587 | 'gender', |
| 559 | 588 | 'blurb', |
| 560 | 589 | ); |
| 561 | - if ($xml_format != 'atom') |
|
| 562 | - $keysToCdata[] = 'category'; |
|
| 590 | + if ($xml_format != 'atom') { |
|
| 591 | + $keysToCdata[] = 'category'; |
|
| 592 | + } |
|
| 563 | 593 | |
| 564 | 594 | if (!empty($forceCdataKeys)) |
| 565 | 595 | { |
@@ -576,8 +606,9 @@ discard block |
||
| 576 | 606 | $attrs = isset($element['attributes']) ? $element['attributes'] : null; |
| 577 | 607 | |
| 578 | 608 | // Skip it, it's been set to null. |
| 579 | - if ($key === null || ($val === null && $attrs === null)) |
|
| 580 | - continue; |
|
| 609 | + if ($key === null || ($val === null && $attrs === null)) { |
|
| 610 | + continue; |
|
| 611 | + } |
|
| 581 | 612 | |
| 582 | 613 | $forceCdata = in_array($key, $forceCdataKeys); |
| 583 | 614 | $ns = !empty($nsKeys[$key]) ? $nsKeys[$key] : ''; |
@@ -590,16 +621,16 @@ discard block |
||
| 590 | 621 | |
| 591 | 622 | if (!empty($attrs)) |
| 592 | 623 | { |
| 593 | - foreach ($attrs as $attr_key => $attr_value) |
|
| 594 | - echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"'; |
|
| 624 | + foreach ($attrs as $attr_key => $attr_value) { |
|
| 625 | + echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"'; |
|
| 626 | + } |
|
| 595 | 627 | } |
| 596 | 628 | |
| 597 | 629 | // If it's empty, simply output an empty element. |
| 598 | 630 | if (empty($val)) |
| 599 | 631 | { |
| 600 | 632 | echo ' />'; |
| 601 | - } |
|
| 602 | - else |
|
| 633 | + } else |
|
| 603 | 634 | { |
| 604 | 635 | echo '>'; |
| 605 | 636 | |
@@ -611,11 +642,13 @@ discard block |
||
| 611 | 642 | echo "\n", str_repeat("\t", $i); |
| 612 | 643 | } |
| 613 | 644 | // A string with returns in it.... show this as a multiline element. |
| 614 | - elseif (strpos($val, "\n") !== false) |
|
| 615 | - echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i); |
|
| 645 | + elseif (strpos($val, "\n") !== false) { |
|
| 646 | + echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i); |
|
| 647 | + } |
|
| 616 | 648 | // A simple string. |
| 617 | - else |
|
| 618 | - echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val); |
|
| 649 | + else { |
|
| 650 | + echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val); |
|
| 651 | + } |
|
| 619 | 652 | |
| 620 | 653 | // Ending tag. |
| 621 | 654 | echo '</', $key, '>'; |
@@ -635,8 +668,9 @@ discard block |
||
| 635 | 668 | { |
| 636 | 669 | global $scripturl, $smcFunc; |
| 637 | 670 | |
| 638 | - if (!allowedTo('view_mlist')) |
|
| 639 | - return array(); |
|
| 671 | + if (!allowedTo('view_mlist')) { |
|
| 672 | + return array(); |
|
| 673 | + } |
|
| 640 | 674 | |
| 641 | 675 | // Find the most recent members. |
| 642 | 676 | $request = $smcFunc['db_query']('', ' |
@@ -655,8 +689,8 @@ discard block |
||
| 655 | 689 | $guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['date_registered']) . ':member=' . $row['id_member']; |
| 656 | 690 | |
| 657 | 691 | // Make the data look rss-ish. |
| 658 | - if ($xml_format == 'rss' || $xml_format == 'rss2') |
|
| 659 | - $data[] = array( |
|
| 692 | + if ($xml_format == 'rss' || $xml_format == 'rss2') { |
|
| 693 | + $data[] = array( |
|
| 660 | 694 | 'tag' => 'item', |
| 661 | 695 | 'content' => array( |
| 662 | 696 | array( |
@@ -684,8 +718,8 @@ discard block |
||
| 684 | 718 | ), |
| 685 | 719 | ), |
| 686 | 720 | ); |
| 687 | - elseif ($xml_format == 'rdf') |
|
| 688 | - $data[] = array( |
|
| 721 | + } elseif ($xml_format == 'rdf') { |
|
| 722 | + $data[] = array( |
|
| 689 | 723 | 'tag' => 'item', |
| 690 | 724 | 'attributes' => array('rdf:about' => $scripturl . '?action=profile;u=' . $row['id_member']), |
| 691 | 725 | 'content' => array( |
@@ -703,8 +737,8 @@ discard block |
||
| 703 | 737 | ), |
| 704 | 738 | ), |
| 705 | 739 | ); |
| 706 | - elseif ($xml_format == 'atom') |
|
| 707 | - $data[] = array( |
|
| 740 | + } elseif ($xml_format == 'atom') { |
|
| 741 | + $data[] = array( |
|
| 708 | 742 | 'tag' => 'entry', |
| 709 | 743 | 'content' => array( |
| 710 | 744 | array( |
@@ -733,9 +767,10 @@ discard block |
||
| 733 | 767 | ), |
| 734 | 768 | ), |
| 735 | 769 | ); |
| 770 | + } |
|
| 736 | 771 | // More logical format for the data, but harder to apply. |
| 737 | - else |
|
| 738 | - $data[] = array( |
|
| 772 | + else { |
|
| 773 | + $data[] = array( |
|
| 739 | 774 | 'tag' => 'member', |
| 740 | 775 | 'content' => array( |
| 741 | 776 | array( |
@@ -756,6 +791,7 @@ discard block |
||
| 756 | 791 | ), |
| 757 | 792 | ), |
| 758 | 793 | ); |
| 794 | + } |
|
| 759 | 795 | } |
| 760 | 796 | $smcFunc['db_free_result']($request); |
| 761 | 797 | |
@@ -816,22 +852,24 @@ discard block |
||
| 816 | 852 | if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit']) |
| 817 | 853 | { |
| 818 | 854 | $smcFunc['db_free_result']($request); |
| 819 | - if (empty($_REQUEST['boards']) && empty($board)) |
|
| 820 | - unset($context['optimize_msg']['lowest']); |
|
| 821 | - else |
|
| 822 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg'; |
|
| 855 | + if (empty($_REQUEST['boards']) && empty($board)) { |
|
| 856 | + unset($context['optimize_msg']['lowest']); |
|
| 857 | + } else { |
|
| 858 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg'; |
|
| 859 | + } |
|
| 823 | 860 | $context['optimize_msg']['highest'] = 'm.id_msg <= t.id_last_msg'; |
| 824 | 861 | $loops++; |
| 862 | + } else { |
|
| 863 | + $done = true; |
|
| 825 | 864 | } |
| 826 | - else |
|
| 827 | - $done = true; |
|
| 828 | 865 | } |
| 829 | 866 | $data = array(); |
| 830 | 867 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 831 | 868 | { |
| 832 | 869 | // Limit the length of the message, if the option is set. |
| 833 | - if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) |
|
| 834 | - $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
| 870 | + if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) { |
|
| 871 | + $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
| 872 | + } |
|
| 835 | 873 | |
| 836 | 874 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
| 837 | 875 | |
@@ -858,8 +896,9 @@ discard block |
||
| 858 | 896 | while ($attach = $smcFunc['db_fetch_assoc']($attach_request)) |
| 859 | 897 | { |
| 860 | 898 | // Include approved attachments only |
| 861 | - if ($attach['approved']) |
|
| 862 | - $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
| 899 | + if ($attach['approved']) { |
|
| 900 | + $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
| 901 | + } |
|
| 863 | 902 | } |
| 864 | 903 | $smcFunc['db_free_result']($attach_request); |
| 865 | 904 | |
@@ -867,16 +906,17 @@ discard block |
||
| 867 | 906 | if (!empty($loaded_attachments)) |
| 868 | 907 | { |
| 869 | 908 | uasort($loaded_attachments, function($a, $b) { |
| 870 | - if ($a['filesize'] == $b['filesize']) |
|
| 871 | - return 0; |
|
| 909 | + if ($a['filesize'] == $b['filesize']) { |
|
| 910 | + return 0; |
|
| 911 | + } |
|
| 872 | 912 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
| 873 | 913 | }); |
| 914 | + } else { |
|
| 915 | + $loaded_attachments = null; |
|
| 874 | 916 | } |
| 875 | - else |
|
| 876 | - $loaded_attachments = null; |
|
| 917 | + } else { |
|
| 918 | + $loaded_attachments = null; |
|
| 877 | 919 | } |
| 878 | - else |
|
| 879 | - $loaded_attachments = null; |
|
| 880 | 920 | |
| 881 | 921 | // Create a GUID for this topic using the tag URI scheme |
| 882 | 922 | $guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['poster_time']) . ':topic=' . $row['id_topic']; |
@@ -893,9 +933,9 @@ discard block |
||
| 893 | 933 | 'length' => $attachment['filesize'], |
| 894 | 934 | 'type' => $attachment['mime_type'], |
| 895 | 935 | ); |
| 936 | + } else { |
|
| 937 | + $enclosure = null; |
|
| 896 | 938 | } |
| 897 | - else |
|
| 898 | - $enclosure = null; |
|
| 899 | 939 | |
| 900 | 940 | $data[] = array( |
| 901 | 941 | 'tag' => 'item', |
@@ -941,8 +981,7 @@ discard block |
||
| 941 | 981 | ), |
| 942 | 982 | ), |
| 943 | 983 | ); |
| 944 | - } |
|
| 945 | - elseif ($xml_format == 'rdf') |
|
| 984 | + } elseif ($xml_format == 'rdf') |
|
| 946 | 985 | { |
| 947 | 986 | $data[] = array( |
| 948 | 987 | 'tag' => 'item', |
@@ -966,8 +1005,7 @@ discard block |
||
| 966 | 1005 | ), |
| 967 | 1006 | ), |
| 968 | 1007 | ); |
| 969 | - } |
|
| 970 | - elseif ($xml_format == 'atom') |
|
| 1008 | + } elseif ($xml_format == 'atom') |
|
| 971 | 1009 | { |
| 972 | 1010 | // Only one attachment allowed |
| 973 | 1011 | if (!empty($loaded_attachments)) |
@@ -979,9 +1017,9 @@ discard block |
||
| 979 | 1017 | 'length' => $attachment['filesize'], |
| 980 | 1018 | 'type' => $attachment['mime_type'], |
| 981 | 1019 | ); |
| 1020 | + } else { |
|
| 1021 | + $enclosure = null; |
|
| 982 | 1022 | } |
| 983 | - else |
|
| 984 | - $enclosure = null; |
|
| 985 | 1023 | |
| 986 | 1024 | $data[] = array( |
| 987 | 1025 | 'tag' => 'entry', |
@@ -1081,9 +1119,9 @@ discard block |
||
| 1081 | 1119 | ) |
| 1082 | 1120 | ); |
| 1083 | 1121 | } |
| 1122 | + } else { |
|
| 1123 | + $attachments = null; |
|
| 1084 | 1124 | } |
| 1085 | - else |
|
| 1086 | - $attachments = null; |
|
| 1087 | 1125 | |
| 1088 | 1126 | $data[] = array( |
| 1089 | 1127 | 'tag' => 'article', |
@@ -1201,22 +1239,25 @@ discard block |
||
| 1201 | 1239 | if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit']) |
| 1202 | 1240 | { |
| 1203 | 1241 | $smcFunc['db_free_result']($request); |
| 1204 | - if (empty($_REQUEST['boards']) && empty($board)) |
|
| 1205 | - unset($context['optimize_msg']['lowest']); |
|
| 1206 | - else |
|
| 1207 | - $context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2'; |
|
| 1242 | + if (empty($_REQUEST['boards']) && empty($board)) { |
|
| 1243 | + unset($context['optimize_msg']['lowest']); |
|
| 1244 | + } else { |
|
| 1245 | + $context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2'; |
|
| 1246 | + } |
|
| 1208 | 1247 | $loops++; |
| 1248 | + } else { |
|
| 1249 | + $done = true; |
|
| 1209 | 1250 | } |
| 1210 | - else |
|
| 1211 | - $done = true; |
|
| 1212 | 1251 | } |
| 1213 | 1252 | $messages = array(); |
| 1214 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1215 | - $messages[] = $row['id_msg']; |
|
| 1253 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1254 | + $messages[] = $row['id_msg']; |
|
| 1255 | + } |
|
| 1216 | 1256 | $smcFunc['db_free_result']($request); |
| 1217 | 1257 | |
| 1218 | - if (empty($messages)) |
|
| 1219 | - return array(); |
|
| 1258 | + if (empty($messages)) { |
|
| 1259 | + return array(); |
|
| 1260 | + } |
|
| 1220 | 1261 | |
| 1221 | 1262 | // Find the most recent posts this user can see. |
| 1222 | 1263 | $request = $smcFunc['db_query']('', ' |
@@ -1246,8 +1287,9 @@ discard block |
||
| 1246 | 1287 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1247 | 1288 | { |
| 1248 | 1289 | // Limit the length of the message, if the option is set. |
| 1249 | - if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) |
|
| 1250 | - $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
| 1290 | + if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) { |
|
| 1291 | + $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
| 1292 | + } |
|
| 1251 | 1293 | |
| 1252 | 1294 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
| 1253 | 1295 | |
@@ -1274,8 +1316,9 @@ discard block |
||
| 1274 | 1316 | while ($attach = $smcFunc['db_fetch_assoc']($attach_request)) |
| 1275 | 1317 | { |
| 1276 | 1318 | // Include approved attachments only |
| 1277 | - if ($attach['approved']) |
|
| 1278 | - $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
| 1319 | + if ($attach['approved']) { |
|
| 1320 | + $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
| 1321 | + } |
|
| 1279 | 1322 | } |
| 1280 | 1323 | $smcFunc['db_free_result']($attach_request); |
| 1281 | 1324 | |
@@ -1283,16 +1326,17 @@ discard block |
||
| 1283 | 1326 | if (!empty($loaded_attachments)) |
| 1284 | 1327 | { |
| 1285 | 1328 | uasort($loaded_attachments, function($a, $b) { |
| 1286 | - if ($a['filesize'] == $b['filesize']) |
|
| 1287 | - return 0; |
|
| 1329 | + if ($a['filesize'] == $b['filesize']) { |
|
| 1330 | + return 0; |
|
| 1331 | + } |
|
| 1288 | 1332 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
| 1289 | 1333 | }); |
| 1334 | + } else { |
|
| 1335 | + $loaded_attachments = null; |
|
| 1290 | 1336 | } |
| 1291 | - else |
|
| 1292 | - $loaded_attachments = null; |
|
| 1337 | + } else { |
|
| 1338 | + $loaded_attachments = null; |
|
| 1293 | 1339 | } |
| 1294 | - else |
|
| 1295 | - $loaded_attachments = null; |
|
| 1296 | 1340 | |
| 1297 | 1341 | // Create a GUID for this post using the tag URI scheme |
| 1298 | 1342 | $guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['poster_time']) . ':msg=' . $row['id_msg']; |
@@ -1309,9 +1353,9 @@ discard block |
||
| 1309 | 1353 | 'length' => $attachment['filesize'], |
| 1310 | 1354 | 'type' => $attachment['mime_type'], |
| 1311 | 1355 | ); |
| 1356 | + } else { |
|
| 1357 | + $enclosure = null; |
|
| 1312 | 1358 | } |
| 1313 | - else |
|
| 1314 | - $enclosure = null; |
|
| 1315 | 1359 | |
| 1316 | 1360 | $data[] = array( |
| 1317 | 1361 | 'tag' => 'item', |
@@ -1357,8 +1401,7 @@ discard block |
||
| 1357 | 1401 | ), |
| 1358 | 1402 | ), |
| 1359 | 1403 | ); |
| 1360 | - } |
|
| 1361 | - elseif ($xml_format == 'rdf') |
|
| 1404 | + } elseif ($xml_format == 'rdf') |
|
| 1362 | 1405 | { |
| 1363 | 1406 | $data[] = array( |
| 1364 | 1407 | 'tag' => 'item', |
@@ -1382,8 +1425,7 @@ discard block |
||
| 1382 | 1425 | ), |
| 1383 | 1426 | ), |
| 1384 | 1427 | ); |
| 1385 | - } |
|
| 1386 | - elseif ($xml_format == 'atom') |
|
| 1428 | + } elseif ($xml_format == 'atom') |
|
| 1387 | 1429 | { |
| 1388 | 1430 | // Only one attachment allowed |
| 1389 | 1431 | if (!empty($loaded_attachments)) |
@@ -1395,9 +1437,9 @@ discard block |
||
| 1395 | 1437 | 'length' => $attachment['filesize'], |
| 1396 | 1438 | 'type' => $attachment['mime_type'], |
| 1397 | 1439 | ); |
| 1440 | + } else { |
|
| 1441 | + $enclosure = null; |
|
| 1398 | 1442 | } |
| 1399 | - else |
|
| 1400 | - $enclosure = null; |
|
| 1401 | 1443 | |
| 1402 | 1444 | $data[] = array( |
| 1403 | 1445 | 'tag' => 'entry', |
@@ -1497,9 +1539,9 @@ discard block |
||
| 1497 | 1539 | ) |
| 1498 | 1540 | ); |
| 1499 | 1541 | } |
| 1542 | + } else { |
|
| 1543 | + $attachments = null; |
|
| 1500 | 1544 | } |
| 1501 | - else |
|
| 1502 | - $attachments = null; |
|
| 1503 | 1545 | |
| 1504 | 1546 | $data[] = array( |
| 1505 | 1547 | 'tag' => 'recent-post', |
@@ -1618,14 +1660,16 @@ discard block |
||
| 1618 | 1660 | global $scripturl, $memberContext, $user_profile, $user_info; |
| 1619 | 1661 | |
| 1620 | 1662 | // You must input a valid user.... |
| 1621 | - if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) |
|
| 1622 | - return array(); |
|
| 1663 | + if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) { |
|
| 1664 | + return array(); |
|
| 1665 | + } |
|
| 1623 | 1666 | |
| 1624 | 1667 | // Make sure the id is a number and not "I like trying to hack the database". |
| 1625 | 1668 | $_GET['u'] = (int) $_GET['u']; |
| 1626 | 1669 | // Load the member's contextual information! |
| 1627 | - if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) |
|
| 1628 | - return array(); |
|
| 1670 | + if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) { |
|
| 1671 | + return array(); |
|
| 1672 | + } |
|
| 1629 | 1673 | |
| 1630 | 1674 | // Okay, I admit it, I'm lazy. Stupid $_GET['u'] is long and hard to type. |
| 1631 | 1675 | $profile = &$memberContext[$_GET['u']]; |
@@ -1667,8 +1711,7 @@ discard block |
||
| 1667 | 1711 | ), |
| 1668 | 1712 | ) |
| 1669 | 1713 | ); |
| 1670 | - } |
|
| 1671 | - elseif ($xml_format == 'rdf') |
|
| 1714 | + } elseif ($xml_format == 'rdf') |
|
| 1672 | 1715 | { |
| 1673 | 1716 | $data[] = array( |
| 1674 | 1717 | 'tag' => 'item', |
@@ -1692,8 +1735,7 @@ discard block |
||
| 1692 | 1735 | ), |
| 1693 | 1736 | ) |
| 1694 | 1737 | ); |
| 1695 | - } |
|
| 1696 | - elseif ($xml_format == 'atom') |
|
| 1738 | + } elseif ($xml_format == 'atom') |
|
| 1697 | 1739 | { |
| 1698 | 1740 | $data[] = array( |
| 1699 | 1741 | 'tag' => 'entry', |
@@ -1746,8 +1788,7 @@ discard block |
||
| 1746 | 1788 | ), |
| 1747 | 1789 | ) |
| 1748 | 1790 | ); |
| 1749 | - } |
|
| 1750 | - else |
|
| 1791 | + } else |
|
| 1751 | 1792 | { |
| 1752 | 1793 | $data = array( |
| 1753 | 1794 | array( |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Add the file functions to the $smcFunc array. |
@@ -52,8 +53,9 @@ discard block |
||
| 52 | 53 | 'messages', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages', |
| 53 | 54 | 'pm_recipients', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys', |
| 54 | 55 | 'themes', 'topics'); |
| 55 | - foreach ($reservedTables as $k => $table_name) |
|
| 56 | - $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
| 56 | + foreach ($reservedTables as $k => $table_name) { |
|
| 57 | + $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
| 58 | + } |
|
| 57 | 59 | |
| 58 | 60 | // We in turn may need the extra stuff. |
| 59 | 61 | db_extend('extra'); |
@@ -105,8 +107,9 @@ discard block |
||
| 105 | 107 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 106 | 108 | |
| 107 | 109 | // First - no way do we touch SMF tables. |
| 108 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
| 109 | - return false; |
|
| 110 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
| 111 | + return false; |
|
| 112 | + } |
|
| 110 | 113 | |
| 111 | 114 | // Log that we'll want to remove this on uninstall. |
| 112 | 115 | $db_package_log[] = array('remove_table', $table_name); |
@@ -116,16 +119,18 @@ discard block |
||
| 116 | 119 | if (in_array($full_table_name, $tables)) |
| 117 | 120 | { |
| 118 | 121 | // This is a sad day... drop the table? If not, return false (error) by default. |
| 119 | - if ($if_exists == 'overwrite') |
|
| 120 | - $smcFunc['db_drop_table']($table_name); |
|
| 121 | - else |
|
| 122 | - return $if_exists == 'ignore'; |
|
| 122 | + if ($if_exists == 'overwrite') { |
|
| 123 | + $smcFunc['db_drop_table']($table_name); |
|
| 124 | + } else { |
|
| 125 | + return $if_exists == 'ignore'; |
|
| 126 | + } |
|
| 123 | 127 | } |
| 124 | 128 | |
| 125 | 129 | // Righty - let's do the damn thing! |
| 126 | 130 | $table_query = 'CREATE TABLE ' . $table_name . "\n" . '('; |
| 127 | - foreach ($columns as $column) |
|
| 128 | - $table_query .= "\n\t" . smf_db_create_query_column($column) . ','; |
|
| 131 | + foreach ($columns as $column) { |
|
| 132 | + $table_query .= "\n\t" . smf_db_create_query_column($column) . ','; |
|
| 133 | + } |
|
| 129 | 134 | |
| 130 | 135 | // Loop through the indexes next... |
| 131 | 136 | foreach ($indexes as $index) |
@@ -133,19 +138,21 @@ discard block |
||
| 133 | 138 | $columns = implode(',', $index['columns']); |
| 134 | 139 | |
| 135 | 140 | // Is it the primary? |
| 136 | - if (isset($index['type']) && $index['type'] == 'primary') |
|
| 137 | - $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
| 138 | - else |
|
| 141 | + if (isset($index['type']) && $index['type'] == 'primary') { |
|
| 142 | + $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
| 143 | + } else |
|
| 139 | 144 | { |
| 140 | - if (empty($index['name'])) |
|
| 141 | - $index['name'] = implode('_', $index['columns']); |
|
| 145 | + if (empty($index['name'])) { |
|
| 146 | + $index['name'] = implode('_', $index['columns']); |
|
| 147 | + } |
|
| 142 | 148 | $table_query .= "\n\t" . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : 'KEY') . ' ' . $index['name'] . ' (' . $columns . '),'; |
| 143 | 149 | } |
| 144 | 150 | } |
| 145 | 151 | |
| 146 | 152 | // No trailing commas! |
| 147 | - if (substr($table_query, -1) == ',') |
|
| 148 | - $table_query = substr($table_query, 0, -1); |
|
| 153 | + if (substr($table_query, -1) == ',') { |
|
| 154 | + $table_query = substr($table_query, 0, -1); |
|
| 155 | + } |
|
| 149 | 156 | |
| 150 | 157 | // Which engine do we want here? |
| 151 | 158 | if (empty($engines)) |
@@ -155,8 +162,9 @@ discard block |
||
| 155 | 162 | |
| 156 | 163 | while ($row = $smcFunc['db_fetch_assoc']($get_engines)) |
| 157 | 164 | { |
| 158 | - if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') |
|
| 159 | - $engines[] = $row['Engine']; |
|
| 165 | + if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') { |
|
| 166 | + $engines[] = $row['Engine']; |
|
| 167 | + } |
|
| 160 | 168 | } |
| 161 | 169 | |
| 162 | 170 | $smcFunc['db_free_result']($get_engines); |
@@ -170,8 +178,9 @@ discard block |
||
| 170 | 178 | } |
| 171 | 179 | |
| 172 | 180 | $table_query .= ') ENGINE=' . $parameters['engine']; |
| 173 | - if (!empty($db_character_set) && $db_character_set == 'utf8') |
|
| 174 | - $table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
| 181 | + if (!empty($db_character_set) && $db_character_set == 'utf8') { |
|
| 182 | + $table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
| 183 | + } |
|
| 175 | 184 | |
| 176 | 185 | // Create the table! |
| 177 | 186 | $smcFunc['db_query']('', $table_query, |
@@ -203,8 +212,9 @@ discard block |
||
| 203 | 212 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 204 | 213 | |
| 205 | 214 | // God no - dropping one of these = bad. |
| 206 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
| 207 | - return false; |
|
| 215 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
| 216 | + return false; |
|
| 217 | + } |
|
| 208 | 218 | |
| 209 | 219 | // Does it exist? |
| 210 | 220 | if (in_array($full_table_name, $smcFunc['db_list_tables']())) |
@@ -245,14 +255,16 @@ discard block |
||
| 245 | 255 | |
| 246 | 256 | // Does it exist - if so don't add it again! |
| 247 | 257 | $columns = $smcFunc['db_list_columns']($table_name, false); |
| 248 | - foreach ($columns as $column) |
|
| 249 | - if ($column == $column_info['name']) |
|
| 258 | + foreach ($columns as $column) { |
|
| 259 | + if ($column == $column_info['name']) |
|
| 250 | 260 | { |
| 251 | 261 | // If we're going to overwrite then use change column. |
| 252 | 262 | if ($if_exists == 'update') |
| 253 | 263 | return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
| 254 | - else |
|
| 255 | - return false; |
|
| 264 | + } |
|
| 265 | + else { |
|
| 266 | + return false; |
|
| 267 | + } |
|
| 256 | 268 | } |
| 257 | 269 | |
| 258 | 270 | // Get the specifics... |
@@ -288,8 +300,8 @@ discard block |
||
| 288 | 300 | |
| 289 | 301 | // Does it exist? |
| 290 | 302 | $columns = $smcFunc['db_list_columns']($table_name, true); |
| 291 | - foreach ($columns as $column) |
|
| 292 | - if ($column['name'] == $column_name) |
|
| 303 | + foreach ($columns as $column) { |
|
| 304 | + if ($column['name'] == $column_name) |
|
| 293 | 305 | { |
| 294 | 306 | $smcFunc['db_query']('', ' |
| 295 | 307 | ALTER TABLE ' . $table_name . ' |
@@ -298,6 +310,7 @@ discard block |
||
| 298 | 310 | 'security_override' => true, |
| 299 | 311 | ) |
| 300 | 312 | ); |
| 313 | + } |
|
| 301 | 314 | |
| 302 | 315 | return true; |
| 303 | 316 | } |
@@ -323,37 +336,47 @@ discard block |
||
| 323 | 336 | // Check it does exist! |
| 324 | 337 | $columns = $smcFunc['db_list_columns']($table_name, true); |
| 325 | 338 | $old_info = null; |
| 326 | - foreach ($columns as $column) |
|
| 327 | - if ($column['name'] == $old_column) |
|
| 339 | + foreach ($columns as $column) { |
|
| 340 | + if ($column['name'] == $old_column) |
|
| 328 | 341 | $old_info = $column; |
| 342 | + } |
|
| 329 | 343 | |
| 330 | 344 | // Nothing? |
| 331 | - if ($old_info == null) |
|
| 332 | - return false; |
|
| 345 | + if ($old_info == null) { |
|
| 346 | + return false; |
|
| 347 | + } |
|
| 333 | 348 | |
| 334 | 349 | // Get the right bits. |
| 335 | - if (!isset($column_info['name'])) |
|
| 336 | - $column_info['name'] = $old_column; |
|
| 337 | - if (!isset($column_info['default'])) |
|
| 338 | - $column_info['default'] = $old_info['default']; |
|
| 339 | - if (!isset($column_info['null'])) |
|
| 340 | - $column_info['null'] = $old_info['null']; |
|
| 341 | - if (!isset($column_info['auto'])) |
|
| 342 | - $column_info['auto'] = $old_info['auto']; |
|
| 343 | - if (!isset($column_info['type'])) |
|
| 344 | - $column_info['type'] = $old_info['type']; |
|
| 345 | - if (!isset($column_info['size']) || !is_numeric($column_info['size'])) |
|
| 346 | - $column_info['size'] = $old_info['size']; |
|
| 347 | - if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) |
|
| 348 | - $column_info['unsigned'] = ''; |
|
| 350 | + if (!isset($column_info['name'])) { |
|
| 351 | + $column_info['name'] = $old_column; |
|
| 352 | + } |
|
| 353 | + if (!isset($column_info['default'])) { |
|
| 354 | + $column_info['default'] = $old_info['default']; |
|
| 355 | + } |
|
| 356 | + if (!isset($column_info['null'])) { |
|
| 357 | + $column_info['null'] = $old_info['null']; |
|
| 358 | + } |
|
| 359 | + if (!isset($column_info['auto'])) { |
|
| 360 | + $column_info['auto'] = $old_info['auto']; |
|
| 361 | + } |
|
| 362 | + if (!isset($column_info['type'])) { |
|
| 363 | + $column_info['type'] = $old_info['type']; |
|
| 364 | + } |
|
| 365 | + if (!isset($column_info['size']) || !is_numeric($column_info['size'])) { |
|
| 366 | + $column_info['size'] = $old_info['size']; |
|
| 367 | + } |
|
| 368 | + if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) { |
|
| 369 | + $column_info['unsigned'] = ''; |
|
| 370 | + } |
|
| 349 | 371 | |
| 350 | 372 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); |
| 351 | 373 | |
| 352 | 374 | // Allow for unsigned integers (mysql only) |
| 353 | 375 | $unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column_info['unsigned']) ? 'unsigned ' : ''; |
| 354 | 376 | |
| 355 | - if ($size !== null) |
|
| 356 | - $type = $type . '(' . $size . ')'; |
|
| 377 | + if ($size !== null) { |
|
| 378 | + $type = $type . '(' . $size . ')'; |
|
| 379 | + } |
|
| 357 | 380 | |
| 358 | 381 | $smcFunc['db_query']('', ' |
| 359 | 382 | ALTER TABLE ' . $table_name . ' |
@@ -383,18 +406,20 @@ discard block |
||
| 383 | 406 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 384 | 407 | |
| 385 | 408 | // No columns = no index. |
| 386 | - if (empty($index_info['columns'])) |
|
| 387 | - return false; |
|
| 409 | + if (empty($index_info['columns'])) { |
|
| 410 | + return false; |
|
| 411 | + } |
|
| 388 | 412 | $columns = implode(',', $index_info['columns']); |
| 389 | 413 | |
| 390 | 414 | // No name - make it up! |
| 391 | 415 | if (empty($index_info['name'])) |
| 392 | 416 | { |
| 393 | 417 | // No need for primary. |
| 394 | - if (isset($index_info['type']) && $index_info['type'] == 'primary') |
|
| 395 | - $index_info['name'] = ''; |
|
| 396 | - else |
|
| 397 | - $index_info['name'] = implode('_', $index_info['columns']); |
|
| 418 | + if (isset($index_info['type']) && $index_info['type'] == 'primary') { |
|
| 419 | + $index_info['name'] = ''; |
|
| 420 | + } else { |
|
| 421 | + $index_info['name'] = implode('_', $index_info['columns']); |
|
| 422 | + } |
|
| 398 | 423 | } |
| 399 | 424 | |
| 400 | 425 | // Log that we are going to want to remove this! |
@@ -408,10 +433,11 @@ discard block |
||
| 408 | 433 | if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary')) |
| 409 | 434 | { |
| 410 | 435 | // If we want to overwrite simply remove the current one then continue. |
| 411 | - if ($if_exists != 'update' || $index['type'] == 'primary') |
|
| 412 | - return false; |
|
| 413 | - else |
|
| 414 | - $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
| 436 | + if ($if_exists != 'update' || $index['type'] == 'primary') { |
|
| 437 | + return false; |
|
| 438 | + } else { |
|
| 439 | + $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
| 440 | + } |
|
| 415 | 441 | } |
| 416 | 442 | } |
| 417 | 443 | |
@@ -425,8 +451,7 @@ discard block |
||
| 425 | 451 | 'security_override' => true, |
| 426 | 452 | ) |
| 427 | 453 | ); |
| 428 | - } |
|
| 429 | - else |
|
| 454 | + } else |
|
| 430 | 455 | { |
| 431 | 456 | $smcFunc['db_query']('', ' |
| 432 | 457 | ALTER TABLE ' . $table_name . ' |
@@ -510,8 +535,7 @@ discard block |
||
| 510 | 535 | $types = array( |
| 511 | 536 | 'inet' => 'varbinary', |
| 512 | 537 | ); |
| 513 | - } |
|
| 514 | - else |
|
| 538 | + } else |
|
| 515 | 539 | { |
| 516 | 540 | $types = array( |
| 517 | 541 | 'varbinary' => 'inet', |
@@ -525,16 +549,15 @@ discard block |
||
| 525 | 549 | { |
| 526 | 550 | $type_size = 16; |
| 527 | 551 | $type_name = 'varbinary'; |
| 528 | - } |
|
| 529 | - elseif ($type_name == 'varbinary' && $reverse && $type_size == 16) |
|
| 552 | + } elseif ($type_name == 'varbinary' && $reverse && $type_size == 16) |
|
| 530 | 553 | { |
| 531 | 554 | $type_name = 'inet'; |
| 532 | 555 | $type_size = null; |
| 556 | + } elseif ($type_name == 'varbinary') { |
|
| 557 | + $type_name = 'varbinary'; |
|
| 558 | + } else { |
|
| 559 | + $type_name = $types[$type_name]; |
|
| 533 | 560 | } |
| 534 | - elseif ($type_name == 'varbinary') |
|
| 535 | - $type_name = 'varbinary'; |
|
| 536 | - else |
|
| 537 | - $type_name = $types[$type_name]; |
|
| 538 | 561 | } |
| 539 | 562 | |
| 540 | 563 | return array($type_name, $type_size); |
@@ -601,8 +624,7 @@ discard block |
||
| 601 | 624 | if (!$detail) |
| 602 | 625 | { |
| 603 | 626 | $columns[] = $row['Field']; |
| 604 | - } |
|
| 605 | - else |
|
| 627 | + } else |
|
| 606 | 628 | { |
| 607 | 629 | // Is there an auto_increment? |
| 608 | 630 | $auto = strpos($row['Extra'], 'auto_increment') !== false ? true : false; |
@@ -612,10 +634,10 @@ discard block |
||
| 612 | 634 | { |
| 613 | 635 | $type = $matches[1]; |
| 614 | 636 | $size = $matches[2]; |
| 615 | - if (!empty($matches[3]) && $matches[3] == 'unsigned') |
|
| 616 | - $unsigned = true; |
|
| 617 | - } |
|
| 618 | - else |
|
| 637 | + if (!empty($matches[3]) && $matches[3] == 'unsigned') { |
|
| 638 | + $unsigned = true; |
|
| 639 | + } |
|
| 640 | + } else |
|
| 619 | 641 | { |
| 620 | 642 | $type = $row['Type']; |
| 621 | 643 | $size = null; |
@@ -666,19 +688,20 @@ discard block |
||
| 666 | 688 | $indexes = array(); |
| 667 | 689 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 668 | 690 | { |
| 669 | - if (!$detail) |
|
| 670 | - $indexes[] = $row['Key_name']; |
|
| 671 | - else |
|
| 691 | + if (!$detail) { |
|
| 692 | + $indexes[] = $row['Key_name']; |
|
| 693 | + } else |
|
| 672 | 694 | { |
| 673 | 695 | // What is the type? |
| 674 | - if ($row['Key_name'] == 'PRIMARY') |
|
| 675 | - $type = 'primary'; |
|
| 676 | - elseif (empty($row['Non_unique'])) |
|
| 677 | - $type = 'unique'; |
|
| 678 | - elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') |
|
| 679 | - $type = 'fulltext'; |
|
| 680 | - else |
|
| 681 | - $type = 'index'; |
|
| 696 | + if ($row['Key_name'] == 'PRIMARY') { |
|
| 697 | + $type = 'primary'; |
|
| 698 | + } elseif (empty($row['Non_unique'])) { |
|
| 699 | + $type = 'unique'; |
|
| 700 | + } elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') { |
|
| 701 | + $type = 'fulltext'; |
|
| 702 | + } else { |
|
| 703 | + $type = 'index'; |
|
| 704 | + } |
|
| 682 | 705 | |
| 683 | 706 | // This is the first column we've seen? |
| 684 | 707 | if (empty($indexes[$row['Key_name']])) |
@@ -691,10 +714,11 @@ discard block |
||
| 691 | 714 | } |
| 692 | 715 | |
| 693 | 716 | // Is it a partial index? |
| 694 | - if (!empty($row['Sub_part'])) |
|
| 695 | - $indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')'; |
|
| 696 | - else |
|
| 697 | - $indexes[$row['Key_name']]['columns'][] = $row['Column_name']; |
|
| 717 | + if (!empty($row['Sub_part'])) { |
|
| 718 | + $indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')'; |
|
| 719 | + } else { |
|
| 720 | + $indexes[$row['Key_name']]['columns'][] = $row['Column_name']; |
|
| 721 | + } |
|
| 698 | 722 | } |
| 699 | 723 | } |
| 700 | 724 | $smcFunc['db_free_result']($result); |
@@ -716,11 +740,11 @@ discard block |
||
| 716 | 740 | if (!empty($column['auto'])) |
| 717 | 741 | { |
| 718 | 742 | $default = 'auto_increment'; |
| 743 | + } elseif (isset($column['default']) && $column['default'] !== null) { |
|
| 744 | + $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
| 745 | + } else { |
|
| 746 | + $default = ''; |
|
| 719 | 747 | } |
| 720 | - elseif (isset($column['default']) && $column['default'] !== null) |
|
| 721 | - $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
| 722 | - else |
|
| 723 | - $default = ''; |
|
| 724 | 748 | |
| 725 | 749 | // Sort out the size... and stuff... |
| 726 | 750 | $column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null; |
@@ -729,8 +753,9 @@ discard block |
||
| 729 | 753 | // Allow unsigned integers (mysql only) |
| 730 | 754 | $unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column['unsigned']) ? 'unsigned ' : ''; |
| 731 | 755 | |
| 732 | - if ($size !== null) |
|
| 733 | - $type = $type . '(' . $size . ')'; |
|
| 756 | + if ($size !== null) { |
|
| 757 | + $type = $type . '(' . $size . ')'; |
|
| 758 | + } |
|
| 734 | 759 | |
| 735 | 760 | // Now just put it together! |
| 736 | 761 | return '`' . $column['name'] . '` ' . $type . ' ' . (!empty($unsigned) ? $unsigned : '') . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default; |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 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 | } |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 4 |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -if (!defined('SMF')) |
|
| 18 | +if (!defined('SMF')) { |
|
| 19 | 19 | die('No direct access...'); |
| 20 | +} |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * Takes a message and parses it, returning nothing. |
@@ -46,17 +47,19 @@ discard block |
||
| 46 | 47 | $message = preg_replace('~\.{100,}~', '...', $message); |
| 47 | 48 | |
| 48 | 49 | // Trim off trailing quotes - these often happen by accident. |
| 49 | - while (substr($message, -7) == '[quote]') |
|
| 50 | - $message = substr($message, 0, -7); |
|
| 51 | - while (substr($message, 0, 8) == '[/quote]') |
|
| 52 | - $message = substr($message, 8); |
|
| 50 | + while (substr($message, -7) == '[quote]') { |
|
| 51 | + $message = substr($message, 0, -7); |
|
| 52 | + } |
|
| 53 | + while (substr($message, 0, 8) == '[/quote]') { |
|
| 54 | + $message = substr($message, 8); |
|
| 55 | + } |
|
| 53 | 56 | |
| 54 | 57 | // Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed. |
| 55 | 58 | $in_tag = false; |
| 56 | 59 | $had_tag = false; |
| 57 | 60 | $codeopen = 0; |
| 58 | - if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) |
|
| 59 | - foreach ($matches[0] as $index => $dummy) |
|
| 61 | + if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) { |
|
| 62 | + foreach ($matches[0] as $index => $dummy) |
|
| 60 | 63 | { |
| 61 | 64 | // Closing? |
| 62 | 65 | if (!empty($matches[2][$index])) |
@@ -64,6 +67,7 @@ discard block |
||
| 64 | 67 | // If it's closing and we're not in a tag we need to open it... |
| 65 | 68 | if (!$in_tag) |
| 66 | 69 | $codeopen = true; |
| 70 | + } |
|
| 67 | 71 | // Either way we ain't in one any more. |
| 68 | 72 | $in_tag = false; |
| 69 | 73 | } |
@@ -72,17 +76,20 @@ discard block |
||
| 72 | 76 | { |
| 73 | 77 | $had_tag = true; |
| 74 | 78 | // If we're in a tag don't do nought! |
| 75 | - if (!$in_tag) |
|
| 76 | - $in_tag = true; |
|
| 79 | + if (!$in_tag) { |
|
| 80 | + $in_tag = true; |
|
| 81 | + } |
|
| 77 | 82 | } |
| 78 | 83 | } |
| 79 | 84 | |
| 80 | 85 | // If we have an open tag, close it. |
| 81 | - if ($in_tag) |
|
| 82 | - $message .= '[/code]'; |
|
| 86 | + if ($in_tag) { |
|
| 87 | + $message .= '[/code]'; |
|
| 88 | + } |
|
| 83 | 89 | // Open any ones that need to be open, only if we've never had a tag. |
| 84 | - if ($codeopen && !$had_tag) |
|
| 85 | - $message = '[code]' . $message; |
|
| 90 | + if ($codeopen && !$had_tag) { |
|
| 91 | + $message = '[code]' . $message; |
|
| 92 | + } |
|
| 86 | 93 | |
| 87 | 94 | // Now that we've fixed all the code tags, let's fix the img and url tags... |
| 88 | 95 | $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE); |
@@ -108,23 +115,26 @@ discard block |
||
| 108 | 115 | fixTags($message); |
| 109 | 116 | |
| 110 | 117 | // Replace /me.+?\n with [me=name]dsf[/me]\n. |
| 111 | - if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) |
|
| 112 | - $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message); |
|
| 113 | - else |
|
| 114 | - $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message); |
|
| 118 | + if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) { |
|
| 119 | + $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message); |
|
| 120 | + } else { |
|
| 121 | + $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message); |
|
| 122 | + } |
|
| 115 | 123 | |
| 116 | 124 | if (!$previewing && strpos($message, '[html]') !== false) |
| 117 | 125 | { |
| 118 | - if (allowedTo('admin_forum')) |
|
| 119 | - $message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) { |
|
| 126 | + if (allowedTo('admin_forum')) { |
|
| 127 | + $message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) { |
|
| 120 | 128 | return '[html]' . strtr(un_htmlspecialchars($m[1]), array("\n" => ' ', ' ' => '  ', '[' => '[', ']' => ']')) . '[/html]'; |
| 129 | + } |
|
| 121 | 130 | }, $message); |
| 122 | 131 | |
| 123 | 132 | // We should edit them out, or else if an admin edits the message they will get shown... |
| 124 | 133 | else |
| 125 | 134 | { |
| 126 | - while (strpos($message, '[html]') !== false) |
|
| 127 | - $message = preg_replace('~\[[/]?html\]~i', '', $message); |
|
| 135 | + while (strpos($message, '[html]') !== false) { |
|
| 136 | + $message = preg_replace('~\[[/]?html\]~i', '', $message); |
|
| 137 | + } |
|
| 128 | 138 | } |
| 129 | 139 | } |
| 130 | 140 | |
@@ -146,10 +156,12 @@ discard block |
||
| 146 | 156 | |
| 147 | 157 | $list_open = substr_count($message, '[list]') + substr_count($message, '[list '); |
| 148 | 158 | $list_close = substr_count($message, '[/list]'); |
| 149 | - if ($list_close - $list_open > 0) |
|
| 150 | - $message = str_repeat('[list]', $list_close - $list_open) . $message; |
|
| 151 | - if ($list_open - $list_close > 0) |
|
| 152 | - $message = $message . str_repeat('[/list]', $list_open - $list_close); |
|
| 159 | + if ($list_close - $list_open > 0) { |
|
| 160 | + $message = str_repeat('[list]', $list_close - $list_open) . $message; |
|
| 161 | + } |
|
| 162 | + if ($list_open - $list_close > 0) { |
|
| 163 | + $message = $message . str_repeat('[/list]', $list_open - $list_close); |
|
| 164 | + } |
|
| 153 | 165 | |
| 154 | 166 | $mistake_fixes = array( |
| 155 | 167 | // Find [table]s not followed by [tr]. |
@@ -198,8 +210,9 @@ discard block |
||
| 198 | 210 | ); |
| 199 | 211 | |
| 200 | 212 | // Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.) |
| 201 | - for ($j = 0; $j < 3; $j++) |
|
| 202 | - $message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message); |
|
| 213 | + for ($j = 0; $j < 3; $j++) { |
|
| 214 | + $message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message); |
|
| 215 | + } |
|
| 203 | 216 | |
| 204 | 217 | // Remove empty bbc from the sections outside the code tags |
| 205 | 218 | $allowedEmpty = array( |
@@ -209,24 +222,28 @@ discard block |
||
| 209 | 222 | |
| 210 | 223 | require_once($sourcedir . '/Subs.php'); |
| 211 | 224 | |
| 212 | - foreach (($codes = parse_bbc(false)) as $code) |
|
| 213 | - if (!in_array($code['tag'], $allowedEmpty)) |
|
| 225 | + foreach (($codes = parse_bbc(false)) as $code) { |
|
| 226 | + if (!in_array($code['tag'], $allowedEmpty)) |
|
| 214 | 227 | $alltags[] = $code['tag']; |
| 228 | + } |
|
| 215 | 229 | |
| 216 | 230 | $alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b'; |
| 217 | 231 | |
| 218 | - while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) |
|
| 219 | - $message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message); |
|
| 232 | + while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) { |
|
| 233 | + $message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message); |
|
| 234 | + } |
|
| 220 | 235 | |
| 221 | 236 | // Restore code blocks |
| 222 | - if (!empty($code_tags)) |
|
| 223 | - $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
| 237 | + if (!empty($code_tags)) { |
|
| 238 | + $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
| 239 | + } |
|
| 224 | 240 | |
| 225 | 241 | // Restore white space entities |
| 226 | - if (!$previewing) |
|
| 227 | - $message = strtr($message, array(' ' => ' ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
| 228 | - else |
|
| 229 | - $message = strtr($message, array(' ' => ' ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
| 242 | + if (!$previewing) { |
|
| 243 | + $message = strtr($message, array(' ' => ' ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
| 244 | + } else { |
|
| 245 | + $message = strtr($message, array(' ' => ' ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
| 246 | + } |
|
| 230 | 247 | |
| 231 | 248 | // Now let's quickly clean up things that will slow our parser (which are common in posted code.) |
| 232 | 249 | $message = strtr($message, array('[]' => '[]', '['' => '['')); |
@@ -269,8 +286,9 @@ discard block |
||
| 269 | 286 | return "[time]" . timeformat("$m[1]", false) . "[/time]"; |
| 270 | 287 | }, $message); |
| 271 | 288 | |
| 272 | - if (!empty($code_tags)) |
|
| 273 | - $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
| 289 | + if (!empty($code_tags)) { |
|
| 290 | + $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
| 291 | + } |
|
| 274 | 292 | |
| 275 | 293 | // Change breaks back to \n's and &nsbp; back to spaces. |
| 276 | 294 | return preg_replace('~<br( /)?' . '>~', "\n", str_replace(' ', ' ', $message)); |
@@ -351,8 +369,9 @@ discard block |
||
| 351 | 369 | ); |
| 352 | 370 | |
| 353 | 371 | // Fix each type of tag. |
| 354 | - foreach ($fixArray as $param) |
|
| 355 | - fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra'])); |
|
| 372 | + foreach ($fixArray as $param) { |
|
| 373 | + fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra'])); |
|
| 374 | + } |
|
| 356 | 375 | |
| 357 | 376 | // Now fix possible security problems with images loading links automatically... |
| 358 | 377 | $message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function($m) |
@@ -388,16 +407,19 @@ discard block |
||
| 388 | 407 | $desired_height = $height; |
| 389 | 408 | } |
| 390 | 409 | // Scale it to the width... |
| 391 | - elseif (empty($desired_width) && !empty($height)) |
|
| 392 | - $desired_width = (int) (($desired_height * $width) / $height); |
|
| 410 | + elseif (empty($desired_width) && !empty($height)) { |
|
| 411 | + $desired_width = (int) (($desired_height * $width) / $height); |
|
| 412 | + } |
|
| 393 | 413 | // Scale if to the height. |
| 394 | - elseif (!empty($width)) |
|
| 395 | - $desired_height = (int) (($desired_width * $height) / $width); |
|
| 414 | + elseif (!empty($width)) { |
|
| 415 | + $desired_height = (int) (($desired_width * $height) / $width); |
|
| 416 | + } |
|
| 396 | 417 | } |
| 397 | 418 | |
| 398 | 419 | // If the width and height are fine, just continue along... |
| 399 | - if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) |
|
| 400 | - continue; |
|
| 420 | + if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) { |
|
| 421 | + continue; |
|
| 422 | + } |
|
| 401 | 423 | |
| 402 | 424 | // Too bad, it's too wide. Make it as wide as the maximum. |
| 403 | 425 | if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width'])) |
@@ -417,8 +439,9 @@ discard block |
||
| 417 | 439 | } |
| 418 | 440 | |
| 419 | 441 | // If any img tags were actually changed... |
| 420 | - if (!empty($replaces)) |
|
| 421 | - $message = strtr($message, $replaces); |
|
| 442 | + if (!empty($replaces)) { |
|
| 443 | + $message = strtr($message, $replaces); |
|
| 444 | + } |
|
| 422 | 445 | } |
| 423 | 446 | } |
| 424 | 447 | |
@@ -437,10 +460,11 @@ discard block |
||
| 437 | 460 | { |
| 438 | 461 | global $boardurl, $scripturl; |
| 439 | 462 | |
| 440 | - if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) |
|
| 441 | - $domain_url = $match[1]; |
|
| 442 | - else |
|
| 443 | - $domain_url = $boardurl . '/'; |
|
| 463 | + if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) { |
|
| 464 | + $domain_url = $match[1]; |
|
| 465 | + } else { |
|
| 466 | + $domain_url = $boardurl . '/'; |
|
| 467 | + } |
|
| 444 | 468 | |
| 445 | 469 | $replaces = array(); |
| 446 | 470 | |
@@ -448,11 +472,11 @@ discard block |
||
| 448 | 472 | { |
| 449 | 473 | $quoted = preg_match('~\[(' . $myTag . ')="~', $message); |
| 450 | 474 | preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '"(.*?)"' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
| 475 | + } elseif ($hasEqualSign) { |
|
| 476 | + preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
|
| 477 | + } else { |
|
| 478 | + preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches); |
|
| 451 | 479 | } |
| 452 | - elseif ($hasEqualSign) |
|
| 453 | - preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
|
| 454 | - else |
|
| 455 | - preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches); |
|
| 456 | 480 | |
| 457 | 481 | foreach ($matches[0] as $k => $dummy) |
| 458 | 482 | { |
@@ -465,49 +489,53 @@ discard block |
||
| 465 | 489 | foreach ($protocols as $protocol) |
| 466 | 490 | { |
| 467 | 491 | $found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0; |
| 468 | - if ($found) |
|
| 469 | - break; |
|
| 492 | + if ($found) { |
|
| 493 | + break; |
|
| 494 | + } |
|
| 470 | 495 | } |
| 471 | 496 | |
| 472 | 497 | if (!$found && $protocols[0] == 'http') |
| 473 | 498 | { |
| 474 | - if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') |
|
| 475 | - $replace = $domain_url . $replace; |
|
| 476 | - elseif (substr($replace, 0, 1) == '?') |
|
| 477 | - $replace = $scripturl . $replace; |
|
| 478 | - elseif (substr($replace, 0, 1) == '#' && $embeddedUrl) |
|
| 499 | + if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') { |
|
| 500 | + $replace = $domain_url . $replace; |
|
| 501 | + } elseif (substr($replace, 0, 1) == '?') { |
|
| 502 | + $replace = $scripturl . $replace; |
|
| 503 | + } elseif (substr($replace, 0, 1) == '#' && $embeddedUrl) |
|
| 479 | 504 | { |
| 480 | 505 | $replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1)); |
| 481 | 506 | $this_tag = 'iurl'; |
| 482 | 507 | $this_close = 'iurl'; |
| 508 | + } elseif (substr($replace, 0, 2) != '//') { |
|
| 509 | + $replace = $protocols[0] . '://' . $replace; |
|
| 483 | 510 | } |
| 484 | - elseif (substr($replace, 0, 2) != '//') |
|
| 485 | - $replace = $protocols[0] . '://' . $replace; |
|
| 486 | - } |
|
| 487 | - elseif (!$found && $protocols[0] == 'ftp') |
|
| 488 | - $replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace); |
|
| 489 | - elseif (!$found) |
|
| 490 | - $replace = $protocols[0] . '://' . $replace; |
|
| 491 | - |
|
| 492 | - if ($hasEqualSign && $embeddedUrl) |
|
| 493 | - $replaces[$matches[0][$k]] = '[' . $this_tag . '="' . $replace . '"]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']'); |
|
| 494 | - elseif ($hasEqualSign) |
|
| 495 | - $replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']'; |
|
| 496 | - elseif ($embeddedUrl) |
|
| 497 | - $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']'; |
|
| 498 | - else |
|
| 499 | - $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']'; |
|
| 511 | + } elseif (!$found && $protocols[0] == 'ftp') { |
|
| 512 | + $replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace); |
|
| 513 | + } elseif (!$found) { |
|
| 514 | + $replace = $protocols[0] . '://' . $replace; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + if ($hasEqualSign && $embeddedUrl) { |
|
| 518 | + $replaces[$matches[0][$k]] = '[' . $this_tag . '="' . $replace . '"]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']'); |
|
| 519 | + } elseif ($hasEqualSign) { |
|
| 520 | + $replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']'; |
|
| 521 | + } elseif ($embeddedUrl) { |
|
| 522 | + $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']'; |
|
| 523 | + } else { |
|
| 524 | + $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']'; |
|
| 525 | + } |
|
| 500 | 526 | } |
| 501 | 527 | |
| 502 | 528 | foreach ($replaces as $k => $v) |
| 503 | 529 | { |
| 504 | - if ($k == $v) |
|
| 505 | - unset($replaces[$k]); |
|
| 530 | + if ($k == $v) { |
|
| 531 | + unset($replaces[$k]); |
|
| 532 | + } |
|
| 506 | 533 | } |
| 507 | 534 | |
| 508 | - if (!empty($replaces)) |
|
| 509 | - $message = strtr($message, $replaces); |
|
| 510 | -} |
|
| 535 | + if (!empty($replaces)) { |
|
| 536 | + $message = strtr($message, $replaces); |
|
| 537 | + } |
|
| 538 | + } |
|
| 511 | 539 | |
| 512 | 540 | /** |
| 513 | 541 | * This function sends an email to the specified recipient(s). |
@@ -551,8 +579,9 @@ discard block |
||
| 551 | 579 | } |
| 552 | 580 | |
| 553 | 581 | // Nothing left? Nothing else to do |
| 554 | - if (empty($to_array)) |
|
| 555 | - return true; |
|
| 582 | + if (empty($to_array)) { |
|
| 583 | + return true; |
|
| 584 | + } |
|
| 556 | 585 | |
| 557 | 586 | // Once upon a time, Hotmail could not interpret non-ASCII mails. |
| 558 | 587 | // In honour of those days, it's still called the 'hotmail fix'. |
@@ -569,15 +598,17 @@ discard block |
||
| 569 | 598 | } |
| 570 | 599 | |
| 571 | 600 | // Call this function recursively for the hotmail addresses. |
| 572 | - if (!empty($hotmail_to)) |
|
| 573 | - $mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private); |
|
| 601 | + if (!empty($hotmail_to)) { |
|
| 602 | + $mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private); |
|
| 603 | + } |
|
| 574 | 604 | |
| 575 | 605 | // The remaining addresses no longer need the fix. |
| 576 | 606 | $hotmail_fix = false; |
| 577 | 607 | |
| 578 | 608 | // No other addresses left? Return instantly. |
| 579 | - if (empty($to_array)) |
|
| 580 | - return $mail_result; |
|
| 609 | + if (empty($to_array)) { |
|
| 610 | + return $mail_result; |
|
| 611 | + } |
|
| 581 | 612 | } |
| 582 | 613 | |
| 583 | 614 | // Get rid of entities. |
@@ -602,13 +633,15 @@ discard block |
||
| 602 | 633 | $headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break; |
| 603 | 634 | $headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break; |
| 604 | 635 | |
| 605 | - if ($message_id !== null && empty($modSettings['mail_no_message_id'])) |
|
| 606 | - $headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break; |
|
| 636 | + if ($message_id !== null && empty($modSettings['mail_no_message_id'])) { |
|
| 637 | + $headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break; |
|
| 638 | + } |
|
| 607 | 639 | $headers .= 'X-Mailer: SMF' . $line_break; |
| 608 | 640 | |
| 609 | 641 | // Pass this to the integration before we start modifying the output -- it'll make it easier later. |
| 610 | - if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) |
|
| 611 | - return false; |
|
| 642 | + if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) { |
|
| 643 | + return false; |
|
| 644 | + } |
|
| 612 | 645 | |
| 613 | 646 | // Save the original message... |
| 614 | 647 | $orig_message = $message; |
@@ -657,17 +690,19 @@ discard block |
||
| 657 | 690 | } |
| 658 | 691 | |
| 659 | 692 | // Are we using the mail queue, if so this is where we butt in... |
| 660 | - if ($priority != 0) |
|
| 661 | - return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private); |
|
| 693 | + if ($priority != 0) { |
|
| 694 | + return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private); |
|
| 695 | + } |
|
| 662 | 696 | |
| 663 | 697 | // If it's a priority mail, send it now - note though that this should NOT be used for sending many at once. |
| 664 | 698 | elseif (!empty($modSettings['mail_limit'])) |
| 665 | 699 | { |
| 666 | 700 | list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']); |
| 667 | - if (empty($mails_this_minute) || time() > $last_mail_time + 60) |
|
| 668 | - $new_queue_stat = time() . '|' . 1; |
|
| 669 | - else |
|
| 670 | - $new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1); |
|
| 701 | + if (empty($mails_this_minute) || time() > $last_mail_time + 60) { |
|
| 702 | + $new_queue_stat = time() . '|' . 1; |
|
| 703 | + } else { |
|
| 704 | + $new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1); |
|
| 705 | + } |
|
| 671 | 706 | |
| 672 | 707 | updateSettings(array('mail_recent' => $new_queue_stat)); |
| 673 | 708 | } |
@@ -692,12 +727,13 @@ discard block |
||
| 692 | 727 | |
| 693 | 728 | // Wait, wait, I'm still sending here! |
| 694 | 729 | @set_time_limit(300); |
| 695 | - if (function_exists('apache_reset_timeout')) |
|
| 696 | - @apache_reset_timeout(); |
|
| 730 | + if (function_exists('apache_reset_timeout')) { |
|
| 731 | + @apache_reset_timeout(); |
|
| 732 | + } |
|
| 697 | 733 | } |
| 734 | + } else { |
|
| 735 | + $mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers); |
|
| 698 | 736 | } |
| 699 | - else |
|
| 700 | - $mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers); |
|
| 701 | 737 | |
| 702 | 738 | // Everything go smoothly? |
| 703 | 739 | return $mail_result; |
@@ -723,8 +759,9 @@ discard block |
||
| 723 | 759 | static $cur_insert = array(); |
| 724 | 760 | static $cur_insert_len = 0; |
| 725 | 761 | |
| 726 | - if ($cur_insert_len == 0) |
|
| 727 | - $cur_insert = array(); |
|
| 762 | + if ($cur_insert_len == 0) { |
|
| 763 | + $cur_insert = array(); |
|
| 764 | + } |
|
| 728 | 765 | |
| 729 | 766 | // If we're flushing, make the final inserts - also if we're near the MySQL length limit! |
| 730 | 767 | if (($flush || $cur_insert_len > 800000) && !empty($cur_insert)) |
@@ -799,8 +836,9 @@ discard block |
||
| 799 | 836 | } |
| 800 | 837 | |
| 801 | 838 | // If they are using SSI there is a good chance obExit will never be called. So lets be nice and flush it for them. |
| 802 | - if (SMF === 'SSI' || SMF === 'BACKGROUND') |
|
| 803 | - return AddMailQueue(true); |
|
| 839 | + if (SMF === 'SSI' || SMF === 'BACKGROUND') { |
|
| 840 | + return AddMailQueue(true); |
|
| 841 | + } |
|
| 804 | 842 | |
| 805 | 843 | return true; |
| 806 | 844 | } |
@@ -831,23 +869,26 @@ discard block |
||
| 831 | 869 | 'sent' => array() |
| 832 | 870 | ); |
| 833 | 871 | |
| 834 | - if ($from === null) |
|
| 835 | - $from = array( |
|
| 872 | + if ($from === null) { |
|
| 873 | + $from = array( |
|
| 836 | 874 | 'id' => $user_info['id'], |
| 837 | 875 | 'name' => $user_info['name'], |
| 838 | 876 | 'username' => $user_info['username'] |
| 839 | 877 | ); |
| 878 | + } |
|
| 840 | 879 | |
| 841 | 880 | // This is the one that will go in their inbox. |
| 842 | 881 | $htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES); |
| 843 | 882 | preparsecode($htmlmessage); |
| 844 | 883 | $htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => '')); |
| 845 | - if ($smcFunc['strlen']($htmlsubject) > 100) |
|
| 846 | - $htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100); |
|
| 884 | + if ($smcFunc['strlen']($htmlsubject) > 100) { |
|
| 885 | + $htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100); |
|
| 886 | + } |
|
| 847 | 887 | |
| 848 | 888 | // Make sure is an array |
| 849 | - if (!is_array($recipients)) |
|
| 850 | - $recipients = array($recipients); |
|
| 889 | + if (!is_array($recipients)) { |
|
| 890 | + $recipients = array($recipients); |
|
| 891 | + } |
|
| 851 | 892 | |
| 852 | 893 | // Integrated PMs |
| 853 | 894 | call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message)); |
@@ -875,21 +916,23 @@ discard block |
||
| 875 | 916 | 'usernames' => array_keys($usernames), |
| 876 | 917 | ) |
| 877 | 918 | ); |
| 878 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 879 | - if (isset($usernames[$smcFunc['strtolower']($row['member_name'])])) |
|
| 919 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 920 | + if (isset($usernames[$smcFunc['strtolower']($row['member_name'])])) |
|
| 880 | 921 | $usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member']; |
| 922 | + } |
|
| 881 | 923 | $smcFunc['db_free_result']($request); |
| 882 | 924 | |
| 883 | 925 | // Replace the usernames with IDs. Drop usernames that couldn't be found. |
| 884 | - foreach ($recipients as $rec_type => $rec) |
|
| 885 | - foreach ($rec as $id => $member) |
|
| 926 | + foreach ($recipients as $rec_type => $rec) { |
|
| 927 | + foreach ($rec as $id => $member) |
|
| 886 | 928 | { |
| 887 | 929 | if (is_numeric($recipients[$rec_type][$id])) |
| 888 | 930 | continue; |
| 931 | + } |
|
| 889 | 932 | |
| 890 | - if (!empty($usernames[$member])) |
|
| 891 | - $recipients[$rec_type][$id] = $usernames[$member]; |
|
| 892 | - else |
|
| 933 | + if (!empty($usernames[$member])) { |
|
| 934 | + $recipients[$rec_type][$id] = $usernames[$member]; |
|
| 935 | + } else |
|
| 893 | 936 | { |
| 894 | 937 | $log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]); |
| 895 | 938 | unset($recipients[$rec_type][$id]); |
@@ -927,8 +970,9 @@ discard block |
||
| 927 | 970 | $delete = false; |
| 928 | 971 | foreach ($criteria as $criterium) |
| 929 | 972 | { |
| 930 | - if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) |
|
| 931 | - $delete = true; |
|
| 973 | + if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) { |
|
| 974 | + $delete = true; |
|
| 975 | + } |
|
| 932 | 976 | // If we're adding and one criteria don't match then we stop! |
| 933 | 977 | elseif (!$row['is_or']) |
| 934 | 978 | { |
@@ -936,8 +980,9 @@ discard block |
||
| 936 | 980 | break; |
| 937 | 981 | } |
| 938 | 982 | } |
| 939 | - if ($delete) |
|
| 940 | - $deletes[$row['id_member']] = 1; |
|
| 983 | + if ($delete) { |
|
| 984 | + $deletes[$row['id_member']] = 1; |
|
| 985 | + } |
|
| 941 | 986 | } |
| 942 | 987 | $smcFunc['db_free_result']($request); |
| 943 | 988 | |
@@ -952,8 +997,9 @@ discard block |
||
| 952 | 997 | array( |
| 953 | 998 | ) |
| 954 | 999 | ); |
| 955 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 956 | - $message_limit_cache[$row['id_group']] = $row['max_messages']; |
|
| 1000 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1001 | + $message_limit_cache[$row['id_group']] = $row['max_messages']; |
|
| 1002 | + } |
|
| 957 | 1003 | $smcFunc['db_free_result']($request); |
| 958 | 1004 | } |
| 959 | 1005 | |
@@ -961,8 +1007,9 @@ discard block |
||
| 961 | 1007 | require_once($sourcedir . '/Subs-Members.php'); |
| 962 | 1008 | $pmReadGroups = groupsAllowedTo('pm_read'); |
| 963 | 1009 | |
| 964 | - if (empty($modSettings['permission_enable_deny'])) |
|
| 965 | - $pmReadGroups['denied'] = array(); |
|
| 1010 | + if (empty($modSettings['permission_enable_deny'])) { |
|
| 1011 | + $pmReadGroups['denied'] = array(); |
|
| 1012 | + } |
|
| 966 | 1013 | |
| 967 | 1014 | // Load their alert preferences |
| 968 | 1015 | require_once($sourcedir . '/Subs-Notify.php'); |
@@ -994,8 +1041,9 @@ discard block |
||
| 994 | 1041 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 995 | 1042 | { |
| 996 | 1043 | // Don't do anything for members to be deleted! |
| 997 | - if (isset($deletes[$row['id_member']])) |
|
| 998 | - continue; |
|
| 1044 | + if (isset($deletes[$row['id_member']])) { |
|
| 1045 | + continue; |
|
| 1046 | + } |
|
| 999 | 1047 | |
| 1000 | 1048 | // Load the preferences for this member (if any) |
| 1001 | 1049 | $prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array(); |
@@ -1016,8 +1064,9 @@ discard block |
||
| 1016 | 1064 | { |
| 1017 | 1065 | foreach ($groups as $id) |
| 1018 | 1066 | { |
| 1019 | - if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) |
|
| 1020 | - $message_limit = $message_limit_cache[$id]; |
|
| 1067 | + if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) { |
|
| 1068 | + $message_limit = $message_limit_cache[$id]; |
|
| 1069 | + } |
|
| 1021 | 1070 | } |
| 1022 | 1071 | |
| 1023 | 1072 | if ($message_limit > 0 && $message_limit <= $row['instant_messages']) |
@@ -1065,8 +1114,9 @@ discard block |
||
| 1065 | 1114 | $smcFunc['db_free_result']($request); |
| 1066 | 1115 | |
| 1067 | 1116 | // Only 'send' the message if there are any recipients left. |
| 1068 | - if (empty($all_to)) |
|
| 1069 | - return $log; |
|
| 1117 | + if (empty($all_to)) { |
|
| 1118 | + return $log; |
|
| 1119 | + } |
|
| 1070 | 1120 | |
| 1071 | 1121 | // Insert the message itself and then grab the last insert id. |
| 1072 | 1122 | $id_pm = $smcFunc['db_insert']('', |
@@ -1087,8 +1137,8 @@ discard block |
||
| 1087 | 1137 | if (!empty($id_pm)) |
| 1088 | 1138 | { |
| 1089 | 1139 | // If this is new we need to set it part of it's own conversation. |
| 1090 | - if (empty($pm_head)) |
|
| 1091 | - $smcFunc['db_query']('', ' |
|
| 1140 | + if (empty($pm_head)) { |
|
| 1141 | + $smcFunc['db_query']('', ' |
|
| 1092 | 1142 | UPDATE {db_prefix}personal_messages |
| 1093 | 1143 | SET id_pm_head = {int:id_pm_head} |
| 1094 | 1144 | WHERE id_pm = {int:id_pm_head}', |
@@ -1096,6 +1146,7 @@ discard block |
||
| 1096 | 1146 | 'id_pm_head' => $id_pm, |
| 1097 | 1147 | ) |
| 1098 | 1148 | ); |
| 1149 | + } |
|
| 1099 | 1150 | |
| 1100 | 1151 | // Some people think manually deleting personal_messages is fun... it's not. We protect against it though :) |
| 1101 | 1152 | $smcFunc['db_query']('', ' |
@@ -1111,8 +1162,9 @@ discard block |
||
| 1111 | 1162 | foreach ($all_to as $to) |
| 1112 | 1163 | { |
| 1113 | 1164 | $insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1); |
| 1114 | - if (!in_array($to, $recipients['bcc'])) |
|
| 1115 | - $to_list[] = $to; |
|
| 1165 | + if (!in_array($to, $recipients['bcc'])) { |
|
| 1166 | + $to_list[] = $to; |
|
| 1167 | + } |
|
| 1116 | 1168 | } |
| 1117 | 1169 | |
| 1118 | 1170 | $smcFunc['db_insert']('insert', |
@@ -1130,9 +1182,9 @@ discard block |
||
| 1130 | 1182 | { |
| 1131 | 1183 | censorText($message); |
| 1132 | 1184 | $message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '[' => '[', ']' => ']'))))); |
| 1185 | + } else { |
|
| 1186 | + $message = ''; |
|
| 1133 | 1187 | } |
| 1134 | - else |
|
| 1135 | - $message = ''; |
|
| 1136 | 1188 | |
| 1137 | 1189 | $to_names = array(); |
| 1138 | 1190 | if (count($to_list) > 1) |
@@ -1145,8 +1197,9 @@ discard block |
||
| 1145 | 1197 | 'to_members' => $to_list, |
| 1146 | 1198 | ) |
| 1147 | 1199 | ); |
| 1148 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1149 | - $to_names[] = un_htmlspecialchars($row['real_name']); |
|
| 1200 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1201 | + $to_names[] = un_htmlspecialchars($row['real_name']); |
|
| 1202 | + } |
|
| 1150 | 1203 | $smcFunc['db_free_result']($request); |
| 1151 | 1204 | } |
| 1152 | 1205 | $replacements = array( |
@@ -1174,11 +1227,13 @@ discard block |
||
| 1174 | 1227 | loadLanguage('index+PersonalMessage'); |
| 1175 | 1228 | |
| 1176 | 1229 | // Add one to their unread and read message counts. |
| 1177 | - foreach ($all_to as $k => $id) |
|
| 1178 | - if (isset($deletes[$id])) |
|
| 1230 | + foreach ($all_to as $k => $id) { |
|
| 1231 | + if (isset($deletes[$id])) |
|
| 1179 | 1232 | unset($all_to[$k]); |
| 1180 | - if (!empty($all_to)) |
|
| 1181 | - updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1)); |
|
| 1233 | + } |
|
| 1234 | + if (!empty($all_to)) { |
|
| 1235 | + updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1)); |
|
| 1236 | + } |
|
| 1182 | 1237 | |
| 1183 | 1238 | return $log; |
| 1184 | 1239 | } |
@@ -1208,15 +1263,17 @@ discard block |
||
| 1208 | 1263 | // Let's, for now, assume there are only 'ish characters. |
| 1209 | 1264 | $simple = true; |
| 1210 | 1265 | |
| 1211 | - foreach ($matches[1] as $entity) |
|
| 1212 | - if ($entity > 128) |
|
| 1266 | + foreach ($matches[1] as $entity) { |
|
| 1267 | + if ($entity > 128) |
|
| 1213 | 1268 | $simple = false; |
| 1269 | + } |
|
| 1214 | 1270 | unset($matches); |
| 1215 | 1271 | |
| 1216 | - if ($simple) |
|
| 1217 | - $string = preg_replace_callback('~&#(\d{3,8});~', function($m) |
|
| 1272 | + if ($simple) { |
|
| 1273 | + $string = preg_replace_callback('~&#(\d{3,8});~', function($m) |
|
| 1218 | 1274 | { |
| 1219 | 1275 | return chr("$m[1]"); |
| 1276 | + } |
|
| 1220 | 1277 | }, $string); |
| 1221 | 1278 | else |
| 1222 | 1279 | { |
@@ -1224,8 +1281,9 @@ discard block |
||
| 1224 | 1281 | if (!$context['utf8'] && function_exists('iconv')) |
| 1225 | 1282 | { |
| 1226 | 1283 | $newstring = @iconv($context['character_set'], 'UTF-8', $string); |
| 1227 | - if ($newstring) |
|
| 1228 | - $string = $newstring; |
|
| 1284 | + if ($newstring) { |
|
| 1285 | + $string = $newstring; |
|
| 1286 | + } |
|
| 1229 | 1287 | } |
| 1230 | 1288 | |
| 1231 | 1289 | $string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string); |
@@ -1241,23 +1299,25 @@ discard block |
||
| 1241 | 1299 | if (!$context['utf8'] && function_exists('iconv')) |
| 1242 | 1300 | { |
| 1243 | 1301 | $newstring = @iconv($context['character_set'], 'UTF-8', $string); |
| 1244 | - if ($newstring) |
|
| 1245 | - $string = $newstring; |
|
| 1302 | + if ($newstring) { |
|
| 1303 | + $string = $newstring; |
|
| 1304 | + } |
|
| 1246 | 1305 | } |
| 1247 | 1306 | |
| 1248 | 1307 | $entityConvert = function($m) |
| 1249 | 1308 | { |
| 1250 | 1309 | $c = $m[1]; |
| 1251 | - if (strlen($c) === 1 && ord($c[0]) <= 0x7F) |
|
| 1252 | - return $c; |
|
| 1253 | - elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) |
|
| 1254 | - return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";"; |
|
| 1255 | - elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) |
|
| 1256 | - return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";"; |
|
| 1257 | - elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) |
|
| 1258 | - return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";"; |
|
| 1259 | - else |
|
| 1260 | - return ""; |
|
| 1310 | + if (strlen($c) === 1 && ord($c[0]) <= 0x7F) { |
|
| 1311 | + return $c; |
|
| 1312 | + } elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) { |
|
| 1313 | + return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";"; |
|
| 1314 | + } elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) { |
|
| 1315 | + return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";"; |
|
| 1316 | + } elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) { |
|
| 1317 | + return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";"; |
|
| 1318 | + } else { |
|
| 1319 | + return ""; |
|
| 1320 | + } |
|
| 1261 | 1321 | }; |
| 1262 | 1322 | |
| 1263 | 1323 | // Convert all 'special' characters to HTML entities. |
@@ -1271,19 +1331,20 @@ discard block |
||
| 1271 | 1331 | $string = base64_encode($string); |
| 1272 | 1332 | |
| 1273 | 1333 | // Show the characterset and the transfer-encoding for header strings. |
| 1274 | - if ($with_charset) |
|
| 1275 | - $string = '=?' . $charset . '?B?' . $string . '?='; |
|
| 1334 | + if ($with_charset) { |
|
| 1335 | + $string = '=?' . $charset . '?B?' . $string . '?='; |
|
| 1336 | + } |
|
| 1276 | 1337 | |
| 1277 | 1338 | // Break it up in lines (mail body). |
| 1278 | - else |
|
| 1279 | - $string = chunk_split($string, 76, $line_break); |
|
| 1339 | + else { |
|
| 1340 | + $string = chunk_split($string, 76, $line_break); |
|
| 1341 | + } |
|
| 1280 | 1342 | |
| 1281 | 1343 | return array($charset, $string, 'base64'); |
| 1344 | + } else { |
|
| 1345 | + return array($charset, $string, '7bit'); |
|
| 1346 | + } |
|
| 1282 | 1347 | } |
| 1283 | - |
|
| 1284 | - else |
|
| 1285 | - return array($charset, $string, '7bit'); |
|
| 1286 | -} |
|
| 1287 | 1348 | |
| 1288 | 1349 | /** |
| 1289 | 1350 | * Sends mail, like mail() but over SMTP. |
@@ -1307,8 +1368,9 @@ discard block |
||
| 1307 | 1368 | if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') |
| 1308 | 1369 | { |
| 1309 | 1370 | $socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2); |
| 1310 | - if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) |
|
| 1311 | - $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2); |
|
| 1371 | + if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) { |
|
| 1372 | + $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2); |
|
| 1373 | + } |
|
| 1312 | 1374 | |
| 1313 | 1375 | if ($socket) |
| 1314 | 1376 | { |
@@ -1329,8 +1391,9 @@ discard block |
||
| 1329 | 1391 | // Maybe we can still save this? The port might be wrong. |
| 1330 | 1392 | if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25)) |
| 1331 | 1393 | { |
| 1332 | - if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) |
|
| 1333 | - log_error($txt['smtp_port_ssl']); |
|
| 1394 | + if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) { |
|
| 1395 | + log_error($txt['smtp_port_ssl']); |
|
| 1396 | + } |
|
| 1334 | 1397 | } |
| 1335 | 1398 | |
| 1336 | 1399 | // Unable to connect! Don't show any error message, but just log one and try to continue anyway. |
@@ -1342,20 +1405,23 @@ discard block |
||
| 1342 | 1405 | } |
| 1343 | 1406 | |
| 1344 | 1407 | // Wait for a response of 220, without "-" continuer. |
| 1345 | - if (!server_parse(null, $socket, '220')) |
|
| 1346 | - return false; |
|
| 1408 | + if (!server_parse(null, $socket, '220')) { |
|
| 1409 | + return false; |
|
| 1410 | + } |
|
| 1347 | 1411 | |
| 1348 | 1412 | // Try and determine the servers name, fall back to the mail servers if not found |
| 1349 | 1413 | $helo = false; |
| 1350 | - if (function_exists('gethostname') && gethostname() !== false) |
|
| 1351 | - $helo = gethostname(); |
|
| 1352 | - elseif (function_exists('php_uname')) |
|
| 1353 | - $helo = php_uname('n'); |
|
| 1354 | - elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) |
|
| 1355 | - $helo = $_SERVER['SERVER_NAME']; |
|
| 1414 | + if (function_exists('gethostname') && gethostname() !== false) { |
|
| 1415 | + $helo = gethostname(); |
|
| 1416 | + } elseif (function_exists('php_uname')) { |
|
| 1417 | + $helo = php_uname('n'); |
|
| 1418 | + } elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) { |
|
| 1419 | + $helo = $_SERVER['SERVER_NAME']; |
|
| 1420 | + } |
|
| 1356 | 1421 | |
| 1357 | - if (empty($helo)) |
|
| 1358 | - $helo = $modSettings['smtp_host']; |
|
| 1422 | + if (empty($helo)) { |
|
| 1423 | + $helo = $modSettings['smtp_host']; |
|
| 1424 | + } |
|
| 1359 | 1425 | |
| 1360 | 1426 | // SMTP = 1, SMTP - STARTTLS = 2 |
| 1361 | 1427 | if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') |
@@ -1367,33 +1433,39 @@ discard block |
||
| 1367 | 1433 | if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response)) |
| 1368 | 1434 | { |
| 1369 | 1435 | // Send STARTTLS to enable encryption |
| 1370 | - if (!server_parse('STARTTLS', $socket, '220')) |
|
| 1371 | - return false; |
|
| 1436 | + if (!server_parse('STARTTLS', $socket, '220')) { |
|
| 1437 | + return false; |
|
| 1438 | + } |
|
| 1372 | 1439 | // Enable the encryption |
| 1373 | - if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) |
|
| 1374 | - return false; |
|
| 1440 | + if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { |
|
| 1441 | + return false; |
|
| 1442 | + } |
|
| 1375 | 1443 | // Send the EHLO command again |
| 1376 | - if (!server_parse('EHLO ' . $helo, $socket, null) == '250') |
|
| 1377 | - return false; |
|
| 1444 | + if (!server_parse('EHLO ' . $helo, $socket, null) == '250') { |
|
| 1445 | + return false; |
|
| 1446 | + } |
|
| 1378 | 1447 | } |
| 1379 | 1448 | |
| 1380 | - if (!server_parse('AUTH LOGIN', $socket, '334')) |
|
| 1381 | - return false; |
|
| 1449 | + if (!server_parse('AUTH LOGIN', $socket, '334')) { |
|
| 1450 | + return false; |
|
| 1451 | + } |
|
| 1382 | 1452 | // Send the username and password, encoded. |
| 1383 | - if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) |
|
| 1384 | - return false; |
|
| 1453 | + if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) { |
|
| 1454 | + return false; |
|
| 1455 | + } |
|
| 1385 | 1456 | // The password is already encoded ;) |
| 1386 | - if (!server_parse($modSettings['smtp_password'], $socket, '235')) |
|
| 1387 | - return false; |
|
| 1457 | + if (!server_parse($modSettings['smtp_password'], $socket, '235')) { |
|
| 1458 | + return false; |
|
| 1459 | + } |
|
| 1460 | + } elseif (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
| 1461 | + return false; |
|
| 1388 | 1462 | } |
| 1389 | - elseif (!server_parse('HELO ' . $helo, $socket, '250')) |
|
| 1390 | - return false; |
|
| 1391 | - } |
|
| 1392 | - else |
|
| 1463 | + } else |
|
| 1393 | 1464 | { |
| 1394 | 1465 | // Just say "helo". |
| 1395 | - if (!server_parse('HELO ' . $helo, $socket, '250')) |
|
| 1396 | - return false; |
|
| 1466 | + if (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
| 1467 | + return false; |
|
| 1468 | + } |
|
| 1397 | 1469 | } |
| 1398 | 1470 | |
| 1399 | 1471 | // Fix the message for any lines beginning with a period! (the first is ignored, you see.) |
@@ -1406,31 +1478,38 @@ discard block |
||
| 1406 | 1478 | // Reset the connection to send another email. |
| 1407 | 1479 | if ($i != 0) |
| 1408 | 1480 | { |
| 1409 | - if (!server_parse('RSET', $socket, '250')) |
|
| 1410 | - return false; |
|
| 1481 | + if (!server_parse('RSET', $socket, '250')) { |
|
| 1482 | + return false; |
|
| 1483 | + } |
|
| 1411 | 1484 | } |
| 1412 | 1485 | |
| 1413 | 1486 | // From, to, and then start the data... |
| 1414 | - if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) |
|
| 1415 | - return false; |
|
| 1416 | - if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) |
|
| 1417 | - return false; |
|
| 1418 | - if (!server_parse('DATA', $socket, '354')) |
|
| 1419 | - return false; |
|
| 1487 | + if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) { |
|
| 1488 | + return false; |
|
| 1489 | + } |
|
| 1490 | + if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) { |
|
| 1491 | + return false; |
|
| 1492 | + } |
|
| 1493 | + if (!server_parse('DATA', $socket, '354')) { |
|
| 1494 | + return false; |
|
| 1495 | + } |
|
| 1420 | 1496 | fputs($socket, 'Subject: ' . $subject . "\r\n"); |
| 1421 | - if (strlen($mail_to) > 0) |
|
| 1422 | - fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
| 1497 | + if (strlen($mail_to) > 0) { |
|
| 1498 | + fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
| 1499 | + } |
|
| 1423 | 1500 | fputs($socket, $headers . "\r\n\r\n"); |
| 1424 | 1501 | fputs($socket, $message . "\r\n"); |
| 1425 | 1502 | |
| 1426 | 1503 | // Send a ., or in other words "end of data". |
| 1427 | - if (!server_parse('.', $socket, '250')) |
|
| 1428 | - return false; |
|
| 1504 | + if (!server_parse('.', $socket, '250')) { |
|
| 1505 | + return false; |
|
| 1506 | + } |
|
| 1429 | 1507 | |
| 1430 | 1508 | // Almost done, almost done... don't stop me just yet! |
| 1431 | 1509 | @set_time_limit(300); |
| 1432 | - if (function_exists('apache_reset_timeout')) |
|
| 1433 | - @apache_reset_timeout(); |
|
| 1510 | + if (function_exists('apache_reset_timeout')) { |
|
| 1511 | + @apache_reset_timeout(); |
|
| 1512 | + } |
|
| 1434 | 1513 | } |
| 1435 | 1514 | fputs($socket, 'QUIT' . "\r\n"); |
| 1436 | 1515 | fclose($socket); |
@@ -1454,8 +1533,9 @@ discard block |
||
| 1454 | 1533 | { |
| 1455 | 1534 | global $txt; |
| 1456 | 1535 | |
| 1457 | - if ($message !== null) |
|
| 1458 | - fputs($socket, $message . "\r\n"); |
|
| 1536 | + if ($message !== null) { |
|
| 1537 | + fputs($socket, $message . "\r\n"); |
|
| 1538 | + } |
|
| 1459 | 1539 | |
| 1460 | 1540 | // No response yet. |
| 1461 | 1541 | $server_response = ''; |
@@ -1471,8 +1551,9 @@ discard block |
||
| 1471 | 1551 | $response .= $server_response; |
| 1472 | 1552 | } |
| 1473 | 1553 | |
| 1474 | - if ($code === null) |
|
| 1475 | - return substr($server_response, 0, 3); |
|
| 1554 | + if ($code === null) { |
|
| 1555 | + return substr($server_response, 0, 3); |
|
| 1556 | + } |
|
| 1476 | 1557 | |
| 1477 | 1558 | if (substr($server_response, 0, 3) != $code) |
| 1478 | 1559 | { |
@@ -1502,8 +1583,9 @@ discard block |
||
| 1502 | 1583 | // Create a pspell or enchant dictionary resource |
| 1503 | 1584 | $dict = spell_init(); |
| 1504 | 1585 | |
| 1505 | - if (!isset($_POST['spellstring']) || !$dict) |
|
| 1506 | - die; |
|
| 1586 | + if (!isset($_POST['spellstring']) || !$dict) { |
|
| 1587 | + die; |
|
| 1588 | + } |
|
| 1507 | 1589 | |
| 1508 | 1590 | // Construct a bit of Javascript code. |
| 1509 | 1591 | $context['spell_js'] = ' |
@@ -1521,8 +1603,9 @@ discard block |
||
| 1521 | 1603 | $check_word = explode('|', $alphas[$i]); |
| 1522 | 1604 | |
| 1523 | 1605 | // If the word is a known word, or spelled right... |
| 1524 | - if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) |
|
| 1525 | - continue; |
|
| 1606 | + if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) { |
|
| 1607 | + continue; |
|
| 1608 | + } |
|
| 1526 | 1609 | |
| 1527 | 1610 | // Find the word, and move up the "last occurrence" to here. |
| 1528 | 1611 | $found_words = true; |
@@ -1536,20 +1619,23 @@ discard block |
||
| 1536 | 1619 | if (!empty($suggestions)) |
| 1537 | 1620 | { |
| 1538 | 1621 | // But first check they aren't going to be censored - no naughty words! |
| 1539 | - foreach ($suggestions as $k => $word) |
|
| 1540 | - if ($suggestions[$k] != censorText($word)) |
|
| 1622 | + foreach ($suggestions as $k => $word) { |
|
| 1623 | + if ($suggestions[$k] != censorText($word)) |
|
| 1541 | 1624 | unset($suggestions[$k]); |
| 1625 | + } |
|
| 1542 | 1626 | |
| 1543 | - if (!empty($suggestions)) |
|
| 1544 | - $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
| 1627 | + if (!empty($suggestions)) { |
|
| 1628 | + $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
| 1629 | + } |
|
| 1545 | 1630 | } |
| 1546 | 1631 | |
| 1547 | 1632 | $context['spell_js'] .= ']),'; |
| 1548 | 1633 | } |
| 1549 | 1634 | |
| 1550 | 1635 | // If words were found, take off the last comma. |
| 1551 | - if ($found_words) |
|
| 1552 | - $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
| 1636 | + if ($found_words) { |
|
| 1637 | + $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
| 1638 | + } |
|
| 1553 | 1639 | |
| 1554 | 1640 | $context['spell_js'] .= ' |
| 1555 | 1641 | );'; |
@@ -1584,11 +1670,13 @@ discard block |
||
| 1584 | 1670 | global $user_info, $smcFunc; |
| 1585 | 1671 | |
| 1586 | 1672 | // Can't do it if there's no topics. |
| 1587 | - if (empty($topics)) |
|
| 1588 | - return; |
|
| 1673 | + if (empty($topics)) { |
|
| 1674 | + return; |
|
| 1675 | + } |
|
| 1589 | 1676 | // It must be an array - it must! |
| 1590 | - if (!is_array($topics)) |
|
| 1591 | - $topics = array($topics); |
|
| 1677 | + if (!is_array($topics)) { |
|
| 1678 | + $topics = array($topics); |
|
| 1679 | + } |
|
| 1592 | 1680 | |
| 1593 | 1681 | // Get the subject and body... |
| 1594 | 1682 | $result = $smcFunc['db_query']('', ' |
@@ -1636,14 +1724,15 @@ discard block |
||
| 1636 | 1724 | } |
| 1637 | 1725 | $smcFunc['db_free_result']($result); |
| 1638 | 1726 | |
| 1639 | - if (!empty($task_rows)) |
|
| 1640 | - $smcFunc['db_insert']('', |
|
| 1727 | + if (!empty($task_rows)) { |
|
| 1728 | + $smcFunc['db_insert']('', |
|
| 1641 | 1729 | '{db_prefix}background_tasks', |
| 1642 | 1730 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 1643 | 1731 | $task_rows, |
| 1644 | 1732 | array('id_task') |
| 1645 | 1733 | ); |
| 1646 | -} |
|
| 1734 | + } |
|
| 1735 | + } |
|
| 1647 | 1736 | |
| 1648 | 1737 | /** |
| 1649 | 1738 | * Create a post, either as new topic (id_topic = 0) or in an existing one. |
@@ -1681,9 +1770,9 @@ discard block |
||
| 1681 | 1770 | $msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true; |
| 1682 | 1771 | |
| 1683 | 1772 | // We need to know if the topic is approved. If we're told that's great - if not find out. |
| 1684 | - if (!$modSettings['postmod_active']) |
|
| 1685 | - $topicOptions['is_approved'] = true; |
|
| 1686 | - elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
| 1773 | + if (!$modSettings['postmod_active']) { |
|
| 1774 | + $topicOptions['is_approved'] = true; |
|
| 1775 | + } elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
| 1687 | 1776 | { |
| 1688 | 1777 | $request = $smcFunc['db_query']('', ' |
| 1689 | 1778 | SELECT approved |
@@ -1706,8 +1795,7 @@ discard block |
||
| 1706 | 1795 | $posterOptions['id'] = 0; |
| 1707 | 1796 | $posterOptions['name'] = $txt['guest_title']; |
| 1708 | 1797 | $posterOptions['email'] = ''; |
| 1709 | - } |
|
| 1710 | - elseif ($posterOptions['id'] != $user_info['id']) |
|
| 1798 | + } elseif ($posterOptions['id'] != $user_info['id']) |
|
| 1711 | 1799 | { |
| 1712 | 1800 | $request = $smcFunc['db_query']('', ' |
| 1713 | 1801 | SELECT member_name, email_address |
@@ -1725,12 +1813,11 @@ discard block |
||
| 1725 | 1813 | $posterOptions['id'] = 0; |
| 1726 | 1814 | $posterOptions['name'] = $txt['guest_title']; |
| 1727 | 1815 | $posterOptions['email'] = ''; |
| 1816 | + } else { |
|
| 1817 | + list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
| 1728 | 1818 | } |
| 1729 | - else |
|
| 1730 | - list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
| 1731 | 1819 | $smcFunc['db_free_result']($request); |
| 1732 | - } |
|
| 1733 | - else |
|
| 1820 | + } else |
|
| 1734 | 1821 | { |
| 1735 | 1822 | $posterOptions['name'] = $user_info['name']; |
| 1736 | 1823 | $posterOptions['email'] = $user_info['email']; |
@@ -1740,8 +1827,9 @@ discard block |
||
| 1740 | 1827 | if (!empty($modSettings['enable_mentions'])) |
| 1741 | 1828 | { |
| 1742 | 1829 | $msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']); |
| 1743 | - if (!empty($msgOptions['mentioned_members'])) |
|
| 1744 | - $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
| 1830 | + if (!empty($msgOptions['mentioned_members'])) { |
|
| 1831 | + $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
| 1832 | + } |
|
| 1745 | 1833 | } |
| 1746 | 1834 | |
| 1747 | 1835 | // It's do or die time: forget any user aborts! |
@@ -1774,12 +1862,13 @@ discard block |
||
| 1774 | 1862 | ); |
| 1775 | 1863 | |
| 1776 | 1864 | // Something went wrong creating the message... |
| 1777 | - if (empty($msgOptions['id'])) |
|
| 1778 | - return false; |
|
| 1865 | + if (empty($msgOptions['id'])) { |
|
| 1866 | + return false; |
|
| 1867 | + } |
|
| 1779 | 1868 | |
| 1780 | 1869 | // Fix the attachments. |
| 1781 | - if (!empty($msgOptions['attachments'])) |
|
| 1782 | - $smcFunc['db_query']('', ' |
|
| 1870 | + if (!empty($msgOptions['attachments'])) { |
|
| 1871 | + $smcFunc['db_query']('', ' |
|
| 1783 | 1872 | UPDATE {db_prefix}attachments |
| 1784 | 1873 | SET id_msg = {int:id_msg} |
| 1785 | 1874 | WHERE id_attach IN ({array_int:attachment_list})', |
@@ -1788,6 +1877,7 @@ discard block |
||
| 1788 | 1877 | 'id_msg' => $msgOptions['id'], |
| 1789 | 1878 | ) |
| 1790 | 1879 | ); |
| 1880 | + } |
|
| 1791 | 1881 | |
| 1792 | 1882 | // What if we want to export new posts out to a CMS? |
| 1793 | 1883 | call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters)); |
@@ -1864,20 +1954,23 @@ discard block |
||
| 1864 | 1954 | 'id_topic' => $topicOptions['id'], |
| 1865 | 1955 | 'counter_increment' => 1, |
| 1866 | 1956 | ); |
| 1867 | - if ($msgOptions['approved']) |
|
| 1868 | - $topics_columns = array( |
|
| 1957 | + if ($msgOptions['approved']) { |
|
| 1958 | + $topics_columns = array( |
|
| 1869 | 1959 | 'id_member_updated = {int:poster_id}', |
| 1870 | 1960 | 'id_last_msg = {int:id_msg}', |
| 1871 | 1961 | 'num_replies = num_replies + {int:counter_increment}', |
| 1872 | 1962 | ); |
| 1873 | - else |
|
| 1874 | - $topics_columns = array( |
|
| 1963 | + } else { |
|
| 1964 | + $topics_columns = array( |
|
| 1875 | 1965 | 'unapproved_posts = unapproved_posts + {int:counter_increment}', |
| 1876 | 1966 | ); |
| 1877 | - if ($topicOptions['lock_mode'] !== null) |
|
| 1878 | - $topics_columns[] = 'locked = {int:locked}'; |
|
| 1879 | - if ($topicOptions['sticky_mode'] !== null) |
|
| 1880 | - $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
| 1967 | + } |
|
| 1968 | + if ($topicOptions['lock_mode'] !== null) { |
|
| 1969 | + $topics_columns[] = 'locked = {int:locked}'; |
|
| 1970 | + } |
|
| 1971 | + if ($topicOptions['sticky_mode'] !== null) { |
|
| 1972 | + $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
| 1973 | + } |
|
| 1881 | 1974 | |
| 1882 | 1975 | call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions)); |
| 1883 | 1976 | |
@@ -1906,8 +1999,8 @@ discard block |
||
| 1906 | 1999 | ); |
| 1907 | 2000 | |
| 1908 | 2001 | // Increase the number of posts and topics on the board. |
| 1909 | - if ($msgOptions['approved']) |
|
| 1910 | - $smcFunc['db_query']('', ' |
|
| 2002 | + if ($msgOptions['approved']) { |
|
| 2003 | + $smcFunc['db_query']('', ' |
|
| 1911 | 2004 | UPDATE {db_prefix}boards |
| 1912 | 2005 | SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . ' |
| 1913 | 2006 | WHERE id_board = {int:id_board}', |
@@ -1915,7 +2008,7 @@ discard block |
||
| 1915 | 2008 | 'id_board' => $topicOptions['board'], |
| 1916 | 2009 | ) |
| 1917 | 2010 | ); |
| 1918 | - else |
|
| 2011 | + } else |
|
| 1919 | 2012 | { |
| 1920 | 2013 | $smcFunc['db_query']('', ' |
| 1921 | 2014 | UPDATE {db_prefix}boards |
@@ -1985,8 +2078,8 @@ discard block |
||
| 1985 | 2078 | } |
| 1986 | 2079 | } |
| 1987 | 2080 | |
| 1988 | - if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) |
|
| 1989 | - $smcFunc['db_insert']('', |
|
| 2081 | + if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) { |
|
| 2082 | + $smcFunc['db_insert']('', |
|
| 1990 | 2083 | '{db_prefix}background_tasks', |
| 1991 | 2084 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 1992 | 2085 | array( |
@@ -1998,19 +2091,22 @@ discard block |
||
| 1998 | 2091 | ), |
| 1999 | 2092 | array('id_task') |
| 2000 | 2093 | ); |
| 2094 | + } |
|
| 2001 | 2095 | |
| 2002 | 2096 | // If there's a custom search index, it may need updating... |
| 2003 | 2097 | require_once($sourcedir . '/Search.php'); |
| 2004 | 2098 | $searchAPI = findSearchAPI(); |
| 2005 | - if (is_callable(array($searchAPI, 'postCreated'))) |
|
| 2006 | - $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
| 2099 | + if (is_callable(array($searchAPI, 'postCreated'))) { |
|
| 2100 | + $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
| 2101 | + } |
|
| 2007 | 2102 | |
| 2008 | 2103 | // Increase the post counter for the user that created the post. |
| 2009 | 2104 | if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved']) |
| 2010 | 2105 | { |
| 2011 | 2106 | // Are you the one that happened to create this post? |
| 2012 | - if ($user_info['id'] == $posterOptions['id']) |
|
| 2013 | - $user_info['posts']++; |
|
| 2107 | + if ($user_info['id'] == $posterOptions['id']) { |
|
| 2108 | + $user_info['posts']++; |
|
| 2109 | + } |
|
| 2014 | 2110 | updateMemberData($posterOptions['id'], array('posts' => '+')); |
| 2015 | 2111 | } |
| 2016 | 2112 | |
@@ -2018,19 +2114,21 @@ discard block |
||
| 2018 | 2114 | $_SESSION['last_read_topic'] = 0; |
| 2019 | 2115 | |
| 2020 | 2116 | // Better safe than sorry. |
| 2021 | - if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) |
|
| 2022 | - $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
| 2117 | + if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) { |
|
| 2118 | + $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
| 2119 | + } |
|
| 2023 | 2120 | |
| 2024 | 2121 | // Update all the stats so everyone knows about this new topic and message. |
| 2025 | 2122 | updateStats('message', true, $msgOptions['id']); |
| 2026 | 2123 | |
| 2027 | 2124 | // Update the last message on the board assuming it's approved AND the topic is. |
| 2028 | - if ($msgOptions['approved']) |
|
| 2029 | - updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
| 2125 | + if ($msgOptions['approved']) { |
|
| 2126 | + updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
| 2127 | + } |
|
| 2030 | 2128 | |
| 2031 | 2129 | // Queue createPost background notification |
| 2032 | - if ($msgOptions['send_notifications'] && $msgOptions['approved']) |
|
| 2033 | - $smcFunc['db_insert']('', |
|
| 2130 | + if ($msgOptions['send_notifications'] && $msgOptions['approved']) { |
|
| 2131 | + $smcFunc['db_insert']('', |
|
| 2034 | 2132 | '{db_prefix}background_tasks', |
| 2035 | 2133 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 2036 | 2134 | array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array( |
@@ -2041,6 +2139,7 @@ discard block |
||
| 2041 | 2139 | )), 0), |
| 2042 | 2140 | array('id_task') |
| 2043 | 2141 | ); |
| 2142 | + } |
|
| 2044 | 2143 | |
| 2045 | 2144 | // Alright, done now... we can abort now, I guess... at least this much is done. |
| 2046 | 2145 | ignore_user_abort($previous_ignore_user_abort); |
@@ -2067,14 +2166,18 @@ discard block |
||
| 2067 | 2166 | |
| 2068 | 2167 | // This is longer than it has to be, but makes it so we only set/change what we have to. |
| 2069 | 2168 | $messages_columns = array(); |
| 2070 | - if (isset($posterOptions['name'])) |
|
| 2071 | - $messages_columns['poster_name'] = $posterOptions['name']; |
|
| 2072 | - if (isset($posterOptions['email'])) |
|
| 2073 | - $messages_columns['poster_email'] = $posterOptions['email']; |
|
| 2074 | - if (isset($msgOptions['icon'])) |
|
| 2075 | - $messages_columns['icon'] = $msgOptions['icon']; |
|
| 2076 | - if (isset($msgOptions['subject'])) |
|
| 2077 | - $messages_columns['subject'] = $msgOptions['subject']; |
|
| 2169 | + if (isset($posterOptions['name'])) { |
|
| 2170 | + $messages_columns['poster_name'] = $posterOptions['name']; |
|
| 2171 | + } |
|
| 2172 | + if (isset($posterOptions['email'])) { |
|
| 2173 | + $messages_columns['poster_email'] = $posterOptions['email']; |
|
| 2174 | + } |
|
| 2175 | + if (isset($msgOptions['icon'])) { |
|
| 2176 | + $messages_columns['icon'] = $msgOptions['icon']; |
|
| 2177 | + } |
|
| 2178 | + if (isset($msgOptions['subject'])) { |
|
| 2179 | + $messages_columns['subject'] = $msgOptions['subject']; |
|
| 2180 | + } |
|
| 2078 | 2181 | if (isset($msgOptions['body'])) |
| 2079 | 2182 | { |
| 2080 | 2183 | $messages_columns['body'] = $msgOptions['body']; |
@@ -2101,8 +2204,9 @@ discard block |
||
| 2101 | 2204 | $messages_columns['modified_reason'] = $msgOptions['modify_reason']; |
| 2102 | 2205 | $messages_columns['id_msg_modified'] = $modSettings['maxMsgID']; |
| 2103 | 2206 | } |
| 2104 | - if (isset($msgOptions['smileys_enabled'])) |
|
| 2105 | - $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
| 2207 | + if (isset($msgOptions['smileys_enabled'])) { |
|
| 2208 | + $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
| 2209 | + } |
|
| 2106 | 2210 | |
| 2107 | 2211 | // Which columns need to be ints? |
| 2108 | 2212 | $messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled'); |
@@ -2120,23 +2224,27 @@ discard block |
||
| 2120 | 2224 | { |
| 2121 | 2225 | preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match); |
| 2122 | 2226 | |
| 2123 | - if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) |
|
| 2124 | - foreach ($match[1] as $i => $oldID) |
|
| 2227 | + if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) { |
|
| 2228 | + foreach ($match[1] as $i => $oldID) |
|
| 2125 | 2229 | $oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]); |
| 2230 | + } |
|
| 2126 | 2231 | |
| 2127 | - if (empty($modSettings['search_custom_index_config'])) |
|
| 2128 | - unset($msgOptions['old_body']); |
|
| 2232 | + if (empty($modSettings['search_custom_index_config'])) { |
|
| 2233 | + unset($msgOptions['old_body']); |
|
| 2234 | + } |
|
| 2129 | 2235 | } |
| 2130 | 2236 | |
| 2131 | 2237 | $mentions = Mentions::getMentionedMembers($msgOptions['body']); |
| 2132 | 2238 | $messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions); |
| 2133 | 2239 | |
| 2134 | 2240 | // Remove the poster. |
| 2135 | - if (isset($mentions[$user_info['id']])) |
|
| 2136 | - unset($mentions[$user_info['id']]); |
|
| 2241 | + if (isset($mentions[$user_info['id']])) { |
|
| 2242 | + unset($mentions[$user_info['id']]); |
|
| 2243 | + } |
|
| 2137 | 2244 | |
| 2138 | - if (isset($oldmentions[$user_info['id']])) |
|
| 2139 | - unset($oldmentions[$user_info['id']]); |
|
| 2245 | + if (isset($oldmentions[$user_info['id']])) { |
|
| 2246 | + unset($oldmentions[$user_info['id']]); |
|
| 2247 | + } |
|
| 2140 | 2248 | |
| 2141 | 2249 | if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions)) |
| 2142 | 2250 | { |
@@ -2166,8 +2274,9 @@ discard block |
||
| 2166 | 2274 | } |
| 2167 | 2275 | |
| 2168 | 2276 | // Nothing to do? |
| 2169 | - if (empty($messages_columns)) |
|
| 2170 | - return true; |
|
| 2277 | + if (empty($messages_columns)) { |
|
| 2278 | + return true; |
|
| 2279 | + } |
|
| 2171 | 2280 | |
| 2172 | 2281 | // Change the post. |
| 2173 | 2282 | $smcFunc['db_query']('', ' |
@@ -2228,8 +2337,9 @@ discard block |
||
| 2228 | 2337 | // If there's a custom search index, it needs to be modified... |
| 2229 | 2338 | require_once($sourcedir . '/Search.php'); |
| 2230 | 2339 | $searchAPI = findSearchAPI(); |
| 2231 | - if (is_callable(array($searchAPI, 'postModified'))) |
|
| 2232 | - $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
| 2340 | + if (is_callable(array($searchAPI, 'postModified'))) { |
|
| 2341 | + $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
| 2342 | + } |
|
| 2233 | 2343 | |
| 2234 | 2344 | if (isset($msgOptions['subject'])) |
| 2235 | 2345 | { |
@@ -2243,14 +2353,16 @@ discard block |
||
| 2243 | 2353 | 'id_first_msg' => $msgOptions['id'], |
| 2244 | 2354 | ) |
| 2245 | 2355 | ); |
| 2246 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
| 2247 | - updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
| 2356 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
| 2357 | + updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
| 2358 | + } |
|
| 2248 | 2359 | $smcFunc['db_free_result']($request); |
| 2249 | 2360 | } |
| 2250 | 2361 | |
| 2251 | 2362 | // Finally, if we are setting the approved state we need to do much more work :( |
| 2252 | - if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) |
|
| 2253 | - approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
| 2363 | + if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) { |
|
| 2364 | + approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
| 2365 | + } |
|
| 2254 | 2366 | |
| 2255 | 2367 | return true; |
| 2256 | 2368 | } |
@@ -2267,11 +2379,13 @@ discard block |
||
| 2267 | 2379 | { |
| 2268 | 2380 | global $smcFunc; |
| 2269 | 2381 | |
| 2270 | - if (!is_array($msgs)) |
|
| 2271 | - $msgs = array($msgs); |
|
| 2382 | + if (!is_array($msgs)) { |
|
| 2383 | + $msgs = array($msgs); |
|
| 2384 | + } |
|
| 2272 | 2385 | |
| 2273 | - if (empty($msgs)) |
|
| 2274 | - return false; |
|
| 2386 | + if (empty($msgs)) { |
|
| 2387 | + return false; |
|
| 2388 | + } |
|
| 2275 | 2389 | |
| 2276 | 2390 | // May as well start at the beginning, working out *what* we need to change. |
| 2277 | 2391 | $request = $smcFunc['db_query']('', ' |
@@ -2303,20 +2417,22 @@ discard block |
||
| 2303 | 2417 | $topics[] = $row['id_topic']; |
| 2304 | 2418 | |
| 2305 | 2419 | // Ensure our change array exists already. |
| 2306 | - if (!isset($topic_changes[$row['id_topic']])) |
|
| 2307 | - $topic_changes[$row['id_topic']] = array( |
|
| 2420 | + if (!isset($topic_changes[$row['id_topic']])) { |
|
| 2421 | + $topic_changes[$row['id_topic']] = array( |
|
| 2308 | 2422 | 'id_last_msg' => $row['id_last_msg'], |
| 2309 | 2423 | 'approved' => $row['topic_approved'], |
| 2310 | 2424 | 'replies' => 0, |
| 2311 | 2425 | 'unapproved_posts' => 0, |
| 2312 | 2426 | ); |
| 2313 | - if (!isset($board_changes[$row['id_board']])) |
|
| 2314 | - $board_changes[$row['id_board']] = array( |
|
| 2427 | + } |
|
| 2428 | + if (!isset($board_changes[$row['id_board']])) { |
|
| 2429 | + $board_changes[$row['id_board']] = array( |
|
| 2315 | 2430 | 'posts' => 0, |
| 2316 | 2431 | 'topics' => 0, |
| 2317 | 2432 | 'unapproved_posts' => 0, |
| 2318 | 2433 | 'unapproved_topics' => 0, |
| 2319 | 2434 | ); |
| 2435 | + } |
|
| 2320 | 2436 | |
| 2321 | 2437 | // If it's the first message then the topic state changes! |
| 2322 | 2438 | if ($row['id_msg'] == $row['id_first_msg']) |
@@ -2337,14 +2453,13 @@ discard block |
||
| 2337 | 2453 | 'poster' => $row['id_member'], |
| 2338 | 2454 | 'new_topic' => true, |
| 2339 | 2455 | ); |
| 2340 | - } |
|
| 2341 | - else |
|
| 2456 | + } else |
|
| 2342 | 2457 | { |
| 2343 | 2458 | $topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1; |
| 2344 | 2459 | |
| 2345 | 2460 | // This will be a post... but don't notify unless it's not followed by approved ones. |
| 2346 | - if ($row['id_msg'] > $row['id_last_msg']) |
|
| 2347 | - $notification_posts[$row['id_topic']] = array( |
|
| 2461 | + if ($row['id_msg'] > $row['id_last_msg']) { |
|
| 2462 | + $notification_posts[$row['id_topic']] = array( |
|
| 2348 | 2463 | 'id' => $row['id_msg'], |
| 2349 | 2464 | 'body' => $row['body'], |
| 2350 | 2465 | 'subject' => $row['subject'], |
@@ -2355,28 +2470,33 @@ discard block |
||
| 2355 | 2470 | 'new_topic' => false, |
| 2356 | 2471 | 'msg' => $row['id_msg'], |
| 2357 | 2472 | ); |
| 2473 | + } |
|
| 2358 | 2474 | } |
| 2359 | 2475 | |
| 2360 | 2476 | // If this is being approved and id_msg is higher than the current id_last_msg then it changes. |
| 2361 | - if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) |
|
| 2362 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
| 2477 | + if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) { |
|
| 2478 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
| 2479 | + } |
|
| 2363 | 2480 | // If this is being unapproved, and it's equal to the id_last_msg we need to find a new one! |
| 2364 | - elseif (!$approve) |
|
| 2365 | - // Default to the first message and then we'll override in a bit ;) |
|
| 2481 | + elseif (!$approve) { |
|
| 2482 | + // Default to the first message and then we'll override in a bit ;) |
|
| 2366 | 2483 | $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg']; |
| 2484 | + } |
|
| 2367 | 2485 | |
| 2368 | 2486 | $topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1; |
| 2369 | 2487 | $board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1; |
| 2370 | 2488 | $board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1; |
| 2371 | 2489 | |
| 2372 | 2490 | // Post count for the user? |
| 2373 | - if ($row['id_member'] && empty($row['count_posts'])) |
|
| 2374 | - $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
| 2491 | + if ($row['id_member'] && empty($row['count_posts'])) { |
|
| 2492 | + $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
| 2493 | + } |
|
| 2375 | 2494 | } |
| 2376 | 2495 | $smcFunc['db_free_result']($request); |
| 2377 | 2496 | |
| 2378 | - if (empty($msgs)) |
|
| 2379 | - return; |
|
| 2497 | + if (empty($msgs)) { |
|
| 2498 | + return; |
|
| 2499 | + } |
|
| 2380 | 2500 | |
| 2381 | 2501 | // Now we have the differences make the changes, first the easy one. |
| 2382 | 2502 | $smcFunc['db_query']('', ' |
@@ -2403,14 +2523,15 @@ discard block |
||
| 2403 | 2523 | 'approved' => 1, |
| 2404 | 2524 | ) |
| 2405 | 2525 | ); |
| 2406 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2407 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
| 2526 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2527 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
| 2528 | + } |
|
| 2408 | 2529 | $smcFunc['db_free_result']($request); |
| 2409 | 2530 | } |
| 2410 | 2531 | |
| 2411 | 2532 | // ... next the topics... |
| 2412 | - foreach ($topic_changes as $id => $changes) |
|
| 2413 | - $smcFunc['db_query']('', ' |
|
| 2533 | + foreach ($topic_changes as $id => $changes) { |
|
| 2534 | + $smcFunc['db_query']('', ' |
|
| 2414 | 2535 | UPDATE {db_prefix}topics |
| 2415 | 2536 | SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
| 2416 | 2537 | num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg} |
@@ -2423,10 +2544,11 @@ discard block |
||
| 2423 | 2544 | 'id_topic' => $id, |
| 2424 | 2545 | ) |
| 2425 | 2546 | ); |
| 2547 | + } |
|
| 2426 | 2548 | |
| 2427 | 2549 | // ... finally the boards... |
| 2428 | - foreach ($board_changes as $id => $changes) |
|
| 2429 | - $smcFunc['db_query']('', ' |
|
| 2550 | + foreach ($board_changes as $id => $changes) { |
|
| 2551 | + $smcFunc['db_query']('', ' |
|
| 2430 | 2552 | UPDATE {db_prefix}boards |
| 2431 | 2553 | SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
| 2432 | 2554 | num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics} |
@@ -2439,13 +2561,14 @@ discard block |
||
| 2439 | 2561 | 'id_board' => $id, |
| 2440 | 2562 | ) |
| 2441 | 2563 | ); |
| 2564 | + } |
|
| 2442 | 2565 | |
| 2443 | 2566 | // Finally, least importantly, notifications! |
| 2444 | 2567 | if ($approve) |
| 2445 | 2568 | { |
| 2446 | 2569 | $task_rows = array(); |
| 2447 | - foreach (array_merge($notification_topics, $notification_posts) as $topic) |
|
| 2448 | - $task_rows[] = array( |
|
| 2570 | + foreach (array_merge($notification_topics, $notification_posts) as $topic) { |
|
| 2571 | + $task_rows[] = array( |
|
| 2449 | 2572 | '$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array( |
| 2450 | 2573 | 'msgOptions' => array( |
| 2451 | 2574 | 'id' => $topic['msg'], |
@@ -2463,14 +2586,16 @@ discard block |
||
| 2463 | 2586 | 'type' => $topic['new_topic'] ? 'topic' : 'reply', |
| 2464 | 2587 | )), 0 |
| 2465 | 2588 | ); |
| 2589 | + } |
|
| 2466 | 2590 | |
| 2467 | - if ($notify) |
|
| 2468 | - $smcFunc['db_insert']('', |
|
| 2591 | + if ($notify) { |
|
| 2592 | + $smcFunc['db_insert']('', |
|
| 2469 | 2593 | '{db_prefix}background_tasks', |
| 2470 | 2594 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 2471 | 2595 | $task_rows, |
| 2472 | 2596 | array('id_task') |
| 2473 | 2597 | ); |
| 2598 | + } |
|
| 2474 | 2599 | |
| 2475 | 2600 | $smcFunc['db_query']('', ' |
| 2476 | 2601 | DELETE FROM {db_prefix}approval_queue |
@@ -2486,8 +2611,9 @@ discard block |
||
| 2486 | 2611 | else |
| 2487 | 2612 | { |
| 2488 | 2613 | $msgInserts = array(); |
| 2489 | - foreach ($msgs as $msg) |
|
| 2490 | - $msgInserts[] = array($msg); |
|
| 2614 | + foreach ($msgs as $msg) { |
|
| 2615 | + $msgInserts[] = array($msg); |
|
| 2616 | + } |
|
| 2491 | 2617 | |
| 2492 | 2618 | $smcFunc['db_insert']('ignore', |
| 2493 | 2619 | '{db_prefix}approval_queue', |
@@ -2501,9 +2627,10 @@ discard block |
||
| 2501 | 2627 | updateLastMessages(array_keys($board_changes)); |
| 2502 | 2628 | |
| 2503 | 2629 | // Post count for the members? |
| 2504 | - if (!empty($member_post_changes)) |
|
| 2505 | - foreach ($member_post_changes as $id_member => $count_change) |
|
| 2630 | + if (!empty($member_post_changes)) { |
|
| 2631 | + foreach ($member_post_changes as $id_member => $count_change) |
|
| 2506 | 2632 | updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change)); |
| 2633 | + } |
|
| 2507 | 2634 | |
| 2508 | 2635 | return true; |
| 2509 | 2636 | } |
@@ -2520,11 +2647,13 @@ discard block |
||
| 2520 | 2647 | { |
| 2521 | 2648 | global $smcFunc; |
| 2522 | 2649 | |
| 2523 | - if (!is_array($topics)) |
|
| 2524 | - $topics = array($topics); |
|
| 2650 | + if (!is_array($topics)) { |
|
| 2651 | + $topics = array($topics); |
|
| 2652 | + } |
|
| 2525 | 2653 | |
| 2526 | - if (empty($topics)) |
|
| 2527 | - return false; |
|
| 2654 | + if (empty($topics)) { |
|
| 2655 | + return false; |
|
| 2656 | + } |
|
| 2528 | 2657 | |
| 2529 | 2658 | $approve_type = $approve ? 0 : 1; |
| 2530 | 2659 | |
@@ -2540,8 +2669,9 @@ discard block |
||
| 2540 | 2669 | ) |
| 2541 | 2670 | ); |
| 2542 | 2671 | $msgs = array(); |
| 2543 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2544 | - $msgs[] = $row['id_msg']; |
|
| 2672 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2673 | + $msgs[] = $row['id_msg']; |
|
| 2674 | + } |
|
| 2545 | 2675 | $smcFunc['db_free_result']($request); |
| 2546 | 2676 | |
| 2547 | 2677 | return approvePosts($msgs, $approve); |
@@ -2564,11 +2694,13 @@ discard block |
||
| 2564 | 2694 | global $board_info, $board, $smcFunc; |
| 2565 | 2695 | |
| 2566 | 2696 | // Please - let's be sane. |
| 2567 | - if (empty($setboards)) |
|
| 2568 | - return false; |
|
| 2697 | + if (empty($setboards)) { |
|
| 2698 | + return false; |
|
| 2699 | + } |
|
| 2569 | 2700 | |
| 2570 | - if (!is_array($setboards)) |
|
| 2571 | - $setboards = array($setboards); |
|
| 2701 | + if (!is_array($setboards)) { |
|
| 2702 | + $setboards = array($setboards); |
|
| 2703 | + } |
|
| 2572 | 2704 | |
| 2573 | 2705 | // If we don't know the id_msg we need to find it. |
| 2574 | 2706 | if (!$id_msg) |
@@ -2586,15 +2718,16 @@ discard block |
||
| 2586 | 2718 | ) |
| 2587 | 2719 | ); |
| 2588 | 2720 | $lastMsg = array(); |
| 2589 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2590 | - $lastMsg[$row['id_board']] = $row['id_msg']; |
|
| 2721 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2722 | + $lastMsg[$row['id_board']] = $row['id_msg']; |
|
| 2723 | + } |
|
| 2591 | 2724 | $smcFunc['db_free_result']($request); |
| 2592 | - } |
|
| 2593 | - else |
|
| 2725 | + } else |
|
| 2594 | 2726 | { |
| 2595 | 2727 | // Just to note - there should only be one board passed if we are doing this. |
| 2596 | - foreach ($setboards as $id_board) |
|
| 2597 | - $lastMsg[$id_board] = $id_msg; |
|
| 2728 | + foreach ($setboards as $id_board) { |
|
| 2729 | + $lastMsg[$id_board] = $id_msg; |
|
| 2730 | + } |
|
| 2598 | 2731 | } |
| 2599 | 2732 | |
| 2600 | 2733 | $parent_boards = array(); |
@@ -2609,10 +2742,11 @@ discard block |
||
| 2609 | 2742 | $lastModified[$id_board] = 0; |
| 2610 | 2743 | } |
| 2611 | 2744 | |
| 2612 | - if (!empty($board) && $id_board == $board) |
|
| 2613 | - $parents = $board_info['parent_boards']; |
|
| 2614 | - else |
|
| 2615 | - $parents = getBoardParents($id_board); |
|
| 2745 | + if (!empty($board) && $id_board == $board) { |
|
| 2746 | + $parents = $board_info['parent_boards']; |
|
| 2747 | + } else { |
|
| 2748 | + $parents = getBoardParents($id_board); |
|
| 2749 | + } |
|
| 2616 | 2750 | |
| 2617 | 2751 | // Ignore any parents on the top child level. |
| 2618 | 2752 | // @todo Why? |
@@ -2621,10 +2755,11 @@ discard block |
||
| 2621 | 2755 | if ($parent['level'] != 0) |
| 2622 | 2756 | { |
| 2623 | 2757 | // If we're already doing this one as a board, is this a higher last modified? |
| 2624 | - if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) |
|
| 2625 | - $lastModified[$id] = $lastModified[$id_board]; |
|
| 2626 | - elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) |
|
| 2627 | - $parent_boards[$id] = $lastModified[$id_board]; |
|
| 2758 | + if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) { |
|
| 2759 | + $lastModified[$id] = $lastModified[$id_board]; |
|
| 2760 | + } elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) { |
|
| 2761 | + $parent_boards[$id] = $lastModified[$id_board]; |
|
| 2762 | + } |
|
| 2628 | 2763 | } |
| 2629 | 2764 | } |
| 2630 | 2765 | } |
@@ -2637,23 +2772,24 @@ discard block |
||
| 2637 | 2772 | // Finally, to save on queries make the changes... |
| 2638 | 2773 | foreach ($parent_boards as $id => $msg) |
| 2639 | 2774 | { |
| 2640 | - if (!isset($parent_updates[$msg])) |
|
| 2641 | - $parent_updates[$msg] = array($id); |
|
| 2642 | - else |
|
| 2643 | - $parent_updates[$msg][] = $id; |
|
| 2775 | + if (!isset($parent_updates[$msg])) { |
|
| 2776 | + $parent_updates[$msg] = array($id); |
|
| 2777 | + } else { |
|
| 2778 | + $parent_updates[$msg][] = $id; |
|
| 2779 | + } |
|
| 2644 | 2780 | } |
| 2645 | 2781 | |
| 2646 | 2782 | foreach ($lastMsg as $id => $msg) |
| 2647 | 2783 | { |
| 2648 | - if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) |
|
| 2649 | - $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
| 2784 | + if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) { |
|
| 2785 | + $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
| 2650 | 2786 | 'id' => $msg, |
| 2651 | 2787 | 'updated' => $lastModified[$id], |
| 2652 | 2788 | 'boards' => array($id) |
| 2653 | 2789 | ); |
| 2654 | - |
|
| 2655 | - else |
|
| 2656 | - $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
| 2790 | + } else { |
|
| 2791 | + $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
| 2792 | + } |
|
| 2657 | 2793 | } |
| 2658 | 2794 | |
| 2659 | 2795 | // Now commit the changes! |
@@ -2745,11 +2881,13 @@ discard block |
||
| 2745 | 2881 | global $txt, $mbname, $scripturl, $settings; |
| 2746 | 2882 | |
| 2747 | 2883 | // First things first, load up the email templates language file, if we need to. |
| 2748 | - if ($loadLang) |
|
| 2749 | - loadLanguage('EmailTemplates', $lang); |
|
| 2884 | + if ($loadLang) { |
|
| 2885 | + loadLanguage('EmailTemplates', $lang); |
|
| 2886 | + } |
|
| 2750 | 2887 | |
| 2751 | - if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) |
|
| 2752 | - fatal_lang_error('email_no_template', 'template', array($template)); |
|
| 2888 | + if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) { |
|
| 2889 | + fatal_lang_error('email_no_template', 'template', array($template)); |
|
| 2890 | + } |
|
| 2753 | 2891 | |
| 2754 | 2892 | $ret = array( |
| 2755 | 2893 | 'subject' => $txt[$template . '_subject'], |
@@ -2799,17 +2937,18 @@ discard block |
||
| 2799 | 2937 | function user_info_callback($matches) |
| 2800 | 2938 | { |
| 2801 | 2939 | global $user_info; |
| 2802 | - if (empty($matches[1])) |
|
| 2803 | - return ''; |
|
| 2940 | + if (empty($matches[1])) { |
|
| 2941 | + return ''; |
|
| 2942 | + } |
|
| 2804 | 2943 | |
| 2805 | 2944 | $use_ref = true; |
| 2806 | 2945 | $ref = &$user_info; |
| 2807 | 2946 | |
| 2808 | 2947 | foreach (explode('.', $matches[1]) as $index) |
| 2809 | 2948 | { |
| 2810 | - if ($use_ref && isset($ref[$index])) |
|
| 2811 | - $ref = &$ref[$index]; |
|
| 2812 | - else |
|
| 2949 | + if ($use_ref && isset($ref[$index])) { |
|
| 2950 | + $ref = &$ref[$index]; |
|
| 2951 | + } else |
|
| 2813 | 2952 | { |
| 2814 | 2953 | $use_ref = false; |
| 2815 | 2954 | break; |
@@ -2846,8 +2985,7 @@ discard block |
||
| 2846 | 2985 | if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale)) |
| 2847 | 2986 | { |
| 2848 | 2987 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale); |
| 2849 | - } |
|
| 2850 | - elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
| 2988 | + } elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
| 2851 | 2989 | { |
| 2852 | 2990 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']); |
| 2853 | 2991 | } |
@@ -2857,8 +2995,7 @@ discard block |
||
| 2857 | 2995 | { |
| 2858 | 2996 | $context['provider'] = 'enchant'; |
| 2859 | 2997 | return $enchant_link; |
| 2860 | - } |
|
| 2861 | - else |
|
| 2998 | + } else |
|
| 2862 | 2999 | { |
| 2863 | 3000 | // Free up any resources used... |
| 2864 | 3001 | @enchant_broker_free($context['enchant_broker']); |
@@ -2879,8 +3016,9 @@ discard block |
||
| 2879 | 3016 | $pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER); |
| 2880 | 3017 | |
| 2881 | 3018 | // Most people don't have anything but English installed... So we use English as a last resort. |
| 2882 | - if (!$pspell_link) |
|
| 2883 | - $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
| 3019 | + if (!$pspell_link) { |
|
| 3020 | + $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
| 3021 | + } |
|
| 2884 | 3022 | |
| 2885 | 3023 | error_reporting($old); |
| 2886 | 3024 | ob_end_clean(); |
@@ -2920,8 +3058,7 @@ discard block |
||
| 2920 | 3058 | $word = iconv($txt['lang_character_set'], 'UTF-8', $word); |
| 2921 | 3059 | } |
| 2922 | 3060 | return enchant_dict_check($dict, $word); |
| 2923 | - } |
|
| 2924 | - elseif ($context['provider'] == 'pspell') |
|
| 3061 | + } elseif ($context['provider'] == 'pspell') |
|
| 2925 | 3062 | { |
| 2926 | 3063 | return pspell_check($dict, $word); |
| 2927 | 3064 | } |
@@ -2957,13 +3094,11 @@ discard block |
||
| 2957 | 3094 | } |
| 2958 | 3095 | |
| 2959 | 3096 | return $suggestions; |
| 2960 | - } |
|
| 2961 | - else |
|
| 3097 | + } else |
|
| 2962 | 3098 | { |
| 2963 | 3099 | return enchant_dict_suggest($dict, $word); |
| 2964 | 3100 | } |
| 2965 | - } |
|
| 2966 | - elseif ($context['provider'] == 'pspell') |
|
| 3101 | + } elseif ($context['provider'] == 'pspell') |
|
| 2967 | 3102 | { |
| 2968 | 3103 | return pspell_suggest($dict, $word); |
| 2969 | 3104 | } |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 4 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * The news dispatcher; doesn't do anything, just delegates. |
@@ -67,8 +68,9 @@ discard block |
||
| 67 | 68 | ); |
| 68 | 69 | |
| 69 | 70 | // Force the right area... |
| 70 | - if (substr($_REQUEST['sa'], 0, 7) == 'mailing') |
|
| 71 | - $context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers'; |
|
| 71 | + if (substr($_REQUEST['sa'], 0, 7) == 'mailing') { |
|
| 72 | + $context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers'; |
|
| 73 | + } |
|
| 72 | 74 | |
| 73 | 75 | call_helper($subActions[$_REQUEST['sa']][0]); |
| 74 | 76 | } |
@@ -99,9 +101,10 @@ discard block |
||
| 99 | 101 | $temp_news = explode("\n", $modSettings['news']); |
| 100 | 102 | |
| 101 | 103 | // Remove the items that were selected. |
| 102 | - foreach ($temp_news as $i => $news) |
|
| 103 | - if (in_array($i, $_POST['remove'])) |
|
| 104 | + foreach ($temp_news as $i => $news) { |
|
| 105 | + if (in_array($i, $_POST['remove'])) |
|
| 104 | 106 | unset($temp_news[$i]); |
| 107 | + } |
|
| 105 | 108 | |
| 106 | 109 | // Update the database. |
| 107 | 110 | updateSettings(array('news' => implode("\n", $temp_news))); |
@@ -117,9 +120,9 @@ discard block |
||
| 117 | 120 | |
| 118 | 121 | foreach ($_POST['news'] as $i => $news) |
| 119 | 122 | { |
| 120 | - if (trim($news) == '') |
|
| 121 | - unset($_POST['news'][$i]); |
|
| 122 | - else |
|
| 123 | + if (trim($news) == '') { |
|
| 124 | + unset($_POST['news'][$i]); |
|
| 125 | + } else |
|
| 123 | 126 | { |
| 124 | 127 | $_POST['news'][$i] = $smcFunc['htmlspecialchars']($_POST['news'][$i], ENT_QUOTES); |
| 125 | 128 | preparsecode($_POST['news'][$i]); |
@@ -154,11 +157,12 @@ discard block |
||
| 154 | 157 | 'data' => array( |
| 155 | 158 | 'function' => function($news) |
| 156 | 159 | { |
| 157 | - if (is_numeric($news['id'])) |
|
| 158 | - return '<textarea id="data_' . $news['id'] . '" rows="3" cols="50" name="news[]" class="padding block">' . $news['unparsed'] . '</textarea> |
|
| 160 | + if (is_numeric($news['id'])) { |
|
| 161 | + return '<textarea id="data_' . $news['id'] . '" rows="3" cols="50" name="news[]" class="padding block">' . $news['unparsed'] . '</textarea> |
|
| 159 | 162 | <div class="floatleft" id="preview_' . $news['id'] . '"></div>'; |
| 160 | - else |
|
| 161 | - return $news['unparsed']; |
|
| 163 | + } else { |
|
| 164 | + return $news['unparsed']; |
|
| 165 | + } |
|
| 162 | 166 | }, |
| 163 | 167 | 'style' => 'width: 50%;', |
| 164 | 168 | ), |
@@ -183,10 +187,11 @@ discard block |
||
| 183 | 187 | 'data' => array( |
| 184 | 188 | 'function' => function($news) |
| 185 | 189 | { |
| 186 | - if (is_numeric($news['id'])) |
|
| 187 | - return '<input type="checkbox" name="remove[]" value="' . $news['id'] . '" class="input_check">'; |
|
| 188 | - else |
|
| 189 | - return ''; |
|
| 190 | + if (is_numeric($news['id'])) { |
|
| 191 | + return '<input type="checkbox" name="remove[]" value="' . $news['id'] . '" class="input_check">'; |
|
| 192 | + } else { |
|
| 193 | + return ''; |
|
| 194 | + } |
|
| 190 | 195 | }, |
| 191 | 196 | 'class' => 'centercol', |
| 192 | 197 | ), |
@@ -280,12 +285,13 @@ discard block |
||
| 280 | 285 | |
| 281 | 286 | $admin_current_news = array(); |
| 282 | 287 | // Ready the current news. |
| 283 | - foreach (explode("\n", $modSettings['news']) as $id => $line) |
|
| 284 | - $admin_current_news[$id] = array( |
|
| 288 | + foreach (explode("\n", $modSettings['news']) as $id => $line) { |
|
| 289 | + $admin_current_news[$id] = array( |
|
| 285 | 290 | 'id' => $id, |
| 286 | 291 | 'unparsed' => un_preparsecode($line), |
| 287 | 292 | 'parsed' => preg_replace('~<([/]?)form[^>]*?[>]*>~i', '<em class="smalltext"><$1form></em>', parse_bbc($line)), |
| 288 | 293 | ); |
| 294 | + } |
|
| 289 | 295 | |
| 290 | 296 | $admin_current_news['last'] = array( |
| 291 | 297 | 'id' => 'last', |
@@ -352,10 +358,11 @@ discard block |
||
| 352 | 358 | 'member_count' => 0, |
| 353 | 359 | ); |
| 354 | 360 | |
| 355 | - if ($row['min_posts'] == -1) |
|
| 356 | - $normalGroups[$row['id_group']] = $row['id_group']; |
|
| 357 | - else |
|
| 358 | - $postGroups[$row['id_group']] = $row['id_group']; |
|
| 361 | + if ($row['min_posts'] == -1) { |
|
| 362 | + $normalGroups[$row['id_group']] = $row['id_group']; |
|
| 363 | + } else { |
|
| 364 | + $postGroups[$row['id_group']] = $row['id_group']; |
|
| 365 | + } |
|
| 359 | 366 | } |
| 360 | 367 | $smcFunc['db_free_result']($request); |
| 361 | 368 | |
@@ -371,8 +378,9 @@ discard block |
||
| 371 | 378 | 'post_group_list' => $postGroups, |
| 372 | 379 | ) |
| 373 | 380 | ); |
| 374 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
| 375 | - $context['groups'][$row['id_group']]['member_count'] += $row['member_count']; |
|
| 381 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
| 382 | + $context['groups'][$row['id_group']]['member_count'] += $row['member_count']; |
|
| 383 | + } |
|
| 376 | 384 | $smcFunc['db_free_result']($query); |
| 377 | 385 | } |
| 378 | 386 | |
@@ -388,8 +396,9 @@ discard block |
||
| 388 | 396 | 'normal_group_list' => $normalGroups, |
| 389 | 397 | ) |
| 390 | 398 | ); |
| 391 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
| 392 | - $context['groups'][$row['id_group']]['member_count'] += $row['member_count']; |
|
| 399 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
| 400 | + $context['groups'][$row['id_group']]['member_count'] += $row['member_count']; |
|
| 401 | + } |
|
| 393 | 402 | $smcFunc['db_free_result']($query); |
| 394 | 403 | |
| 395 | 404 | // Also do those who have it as an additional membergroup - this ones more yucky... |
@@ -406,8 +415,9 @@ discard block |
||
| 406 | 415 | 'blank_string' => '', |
| 407 | 416 | ) |
| 408 | 417 | ); |
| 409 | - while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
| 410 | - $context['groups'][$row['id_group']]['member_count'] += $row['member_count']; |
|
| 418 | + while ($row = $smcFunc['db_fetch_assoc']($query)) { |
|
| 419 | + $context['groups'][$row['id_group']]['member_count'] += $row['member_count']; |
|
| 420 | + } |
|
| 411 | 421 | $smcFunc['db_free_result']($query); |
| 412 | 422 | } |
| 413 | 423 | |
@@ -458,10 +468,11 @@ discard block |
||
| 458 | 468 | { |
| 459 | 469 | $context[$key] = !empty($_REQUEST[$post]) ? $_REQUEST[$post] : ''; |
| 460 | 470 | |
| 461 | - if (empty($context[$key]) && empty($_REQUEST['xml'])) |
|
| 462 | - $context['post_error']['messages'][] = $txt['error_no_' . $post]; |
|
| 463 | - elseif (!empty($_REQUEST['xml'])) |
|
| 464 | - continue; |
|
| 471 | + if (empty($context[$key]) && empty($_REQUEST['xml'])) { |
|
| 472 | + $context['post_error']['messages'][] = $txt['error_no_' . $post]; |
|
| 473 | + } elseif (!empty($_REQUEST['xml'])) { |
|
| 474 | + continue; |
|
| 475 | + } |
|
| 465 | 476 | |
| 466 | 477 | preparsecode($context[$key]); |
| 467 | 478 | if ($html) |
@@ -540,10 +551,12 @@ discard block |
||
| 540 | 551 | |
| 541 | 552 | // Start by finding any members! |
| 542 | 553 | $toClean = array(); |
| 543 | - if (!empty($_POST['members'])) |
|
| 544 | - $toClean[] = 'members'; |
|
| 545 | - if (!empty($_POST['exclude_members'])) |
|
| 546 | - $toClean[] = 'exclude_members'; |
|
| 554 | + if (!empty($_POST['members'])) { |
|
| 555 | + $toClean[] = 'members'; |
|
| 556 | + } |
|
| 557 | + if (!empty($_POST['exclude_members'])) { |
|
| 558 | + $toClean[] = 'exclude_members'; |
|
| 559 | + } |
|
| 547 | 560 | if (!empty($toClean)) |
| 548 | 561 | { |
| 549 | 562 | require_once($sourcedir . '/Subs-Auth.php'); |
@@ -555,11 +568,13 @@ discard block |
||
| 555 | 568 | preg_match_all('~"([^"]+)"~', $_POST[$type], $matches); |
| 556 | 569 | $_POST[$type] = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST[$type])))); |
| 557 | 570 | |
| 558 | - foreach ($_POST[$type] as $index => $member) |
|
| 559 | - if (strlen(trim($member)) > 0) |
|
| 571 | + foreach ($_POST[$type] as $index => $member) { |
|
| 572 | + if (strlen(trim($member)) > 0) |
|
| 560 | 573 | $_POST[$type][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($member))); |
| 561 | - else |
|
| 562 | - unset($_POST[$type][$index]); |
|
| 574 | + } |
|
| 575 | + else { |
|
| 576 | + unset($_POST[$type][$index]); |
|
| 577 | + } |
|
| 563 | 578 | |
| 564 | 579 | // Find the members |
| 565 | 580 | $_POST[$type] = implode(',', array_keys(findMembers($_POST[$type]))); |
@@ -569,16 +584,18 @@ discard block |
||
| 569 | 584 | if (isset($_POST['member_list']) && is_array($_POST['member_list'])) |
| 570 | 585 | { |
| 571 | 586 | $members = array(); |
| 572 | - foreach ($_POST['member_list'] as $member_id) |
|
| 573 | - $members[] = (int) $member_id; |
|
| 587 | + foreach ($_POST['member_list'] as $member_id) { |
|
| 588 | + $members[] = (int) $member_id; |
|
| 589 | + } |
|
| 574 | 590 | $_POST['members'] = implode(',', $members); |
| 575 | 591 | } |
| 576 | 592 | |
| 577 | 593 | if (isset($_POST['exclude_member_list']) && is_array($_POST['exclude_member_list'])) |
| 578 | 594 | { |
| 579 | 595 | $members = array(); |
| 580 | - foreach ($_POST['exclude_member_list'] as $member_id) |
|
| 581 | - $members[] = (int) $member_id; |
|
| 596 | + foreach ($_POST['exclude_member_list'] as $member_id) { |
|
| 597 | + $members[] = (int) $member_id; |
|
| 598 | + } |
|
| 582 | 599 | $_POST['exclude_members'] = implode(',', $members); |
| 583 | 600 | } |
| 584 | 601 | |
@@ -602,8 +619,9 @@ discard block |
||
| 602 | 619 | 'current_time' => time(), |
| 603 | 620 | ) |
| 604 | 621 | ); |
| 605 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 606 | - $context['recipients']['exclude_members'][] = $row['id_member']; |
|
| 622 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 623 | + $context['recipients']['exclude_members'][] = $row['id_member']; |
|
| 624 | + } |
|
| 607 | 625 | $smcFunc['db_free_result']($request); |
| 608 | 626 | |
| 609 | 627 | $request = $smcFunc['db_query']('', ' |
@@ -638,8 +656,9 @@ discard block |
||
| 638 | 656 | WHERE email_address IN(' . implode(', ', $condition_array) . ')', |
| 639 | 657 | $condition_array_params |
| 640 | 658 | ); |
| 641 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 642 | - $context['recipients']['exclude_members'][] = $row['id_member']; |
|
| 659 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 660 | + $context['recipients']['exclude_members'][] = $row['id_member']; |
|
| 661 | + } |
|
| 643 | 662 | $smcFunc['db_free_result']($request); |
| 644 | 663 | } |
| 645 | 664 | |
@@ -657,10 +676,11 @@ discard block |
||
| 657 | 676 | ); |
| 658 | 677 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 659 | 678 | { |
| 660 | - if (in_array(3, $context['recipients'])) |
|
| 661 | - $context['recipients']['exclude_members'][] = $row['identifier']; |
|
| 662 | - else |
|
| 663 | - $context['recipients']['members'][] = $row['identifier']; |
|
| 679 | + if (in_array(3, $context['recipients'])) { |
|
| 680 | + $context['recipients']['exclude_members'][] = $row['identifier']; |
|
| 681 | + } else { |
|
| 682 | + $context['recipients']['members'][] = $row['identifier']; |
|
| 683 | + } |
|
| 664 | 684 | } |
| 665 | 685 | $smcFunc['db_free_result']($request); |
| 666 | 686 | } |
@@ -707,8 +727,9 @@ discard block |
||
| 707 | 727 | $num_at_once = 1000; |
| 708 | 728 | |
| 709 | 729 | // If by PM's I suggest we half the above number. |
| 710 | - if (!empty($_POST['send_pm'])) |
|
| 711 | - $num_at_once /= 2; |
|
| 730 | + if (!empty($_POST['send_pm'])) { |
|
| 731 | + $num_at_once /= 2; |
|
| 732 | + } |
|
| 712 | 733 | |
| 713 | 734 | checkSession(); |
| 714 | 735 | |
@@ -731,8 +752,7 @@ discard block |
||
| 731 | 752 | ); |
| 732 | 753 | list ($context['total_members']) = $smcFunc['db_fetch_row']($request); |
| 733 | 754 | $smcFunc['db_free_result']($request); |
| 734 | - } |
|
| 735 | - else |
|
| 755 | + } else |
|
| 736 | 756 | { |
| 737 | 757 | $context['total_members'] = (int) $_REQUEST['total_members']; |
| 738 | 758 | } |
@@ -750,32 +770,35 @@ discard block |
||
| 750 | 770 | if (!empty($_POST['exclude_members'])) |
| 751 | 771 | { |
| 752 | 772 | $members = explode(',', $_POST['exclude_members']); |
| 753 | - foreach ($members as $member) |
|
| 754 | - if ($member >= $context['start']) |
|
| 773 | + foreach ($members as $member) { |
|
| 774 | + if ($member >= $context['start']) |
|
| 755 | 775 | $context['recipients']['exclude_members'][] = (int) $member; |
| 776 | + } |
|
| 756 | 777 | } |
| 757 | 778 | |
| 758 | 779 | // What about members we *must* do? |
| 759 | 780 | if (!empty($_POST['members'])) |
| 760 | 781 | { |
| 761 | 782 | $members = explode(',', $_POST['members']); |
| 762 | - foreach ($members as $member) |
|
| 763 | - if ($member >= $context['start']) |
|
| 783 | + foreach ($members as $member) { |
|
| 784 | + if ($member >= $context['start']) |
|
| 764 | 785 | $context['recipients']['members'][] = (int) $member; |
| 786 | + } |
|
| 765 | 787 | } |
| 766 | 788 | // Cleaning groups is simple - although deal with both checkbox and commas. |
| 767 | 789 | if (isset($_POST['groups'])) |
| 768 | 790 | { |
| 769 | 791 | if (is_array($_POST['groups'])) |
| 770 | 792 | { |
| 771 | - foreach ($_POST['groups'] as $group => $dummy) |
|
| 772 | - $context['recipients']['groups'][] = (int) $group; |
|
| 773 | - } |
|
| 774 | - else |
|
| 793 | + foreach ($_POST['groups'] as $group => $dummy) { |
|
| 794 | + $context['recipients']['groups'][] = (int) $group; |
|
| 795 | + } |
|
| 796 | + } else |
|
| 775 | 797 | { |
| 776 | 798 | $groups = explode(',', $_POST['groups']); |
| 777 | - foreach ($groups as $group) |
|
| 778 | - $context['recipients']['groups'][] = (int) $group; |
|
| 799 | + foreach ($groups as $group) { |
|
| 800 | + $context['recipients']['groups'][] = (int) $group; |
|
| 801 | + } |
|
| 779 | 802 | } |
| 780 | 803 | } |
| 781 | 804 | // Same for excluded groups |
@@ -783,15 +806,17 @@ discard block |
||
| 783 | 806 | { |
| 784 | 807 | if (is_array($_POST['exclude_groups'])) |
| 785 | 808 | { |
| 786 | - foreach ($_POST['exclude_groups'] as $group => $dummy) |
|
| 787 | - $context['recipients']['exclude_groups'][] = (int) $group; |
|
| 809 | + foreach ($_POST['exclude_groups'] as $group => $dummy) { |
|
| 810 | + $context['recipients']['exclude_groups'][] = (int) $group; |
|
| 811 | + } |
|
| 788 | 812 | } |
| 789 | 813 | // Ignore an empty string - we don't want to exclude "Regular Members" unless it's specifically selected |
| 790 | 814 | elseif ($_POST['exclude_groups'] != '') |
| 791 | 815 | { |
| 792 | 816 | $groups = explode(',', $_POST['exclude_groups']); |
| 793 | - foreach ($groups as $group) |
|
| 794 | - $context['recipients']['exclude_groups'][] = (int) $group; |
|
| 817 | + foreach ($groups as $group) { |
|
| 818 | + $context['recipients']['exclude_groups'][] = (int) $group; |
|
| 819 | + } |
|
| 795 | 820 | } |
| 796 | 821 | } |
| 797 | 822 | // Finally - emails! |
@@ -801,14 +826,16 @@ discard block |
||
| 801 | 826 | foreach ($addressed as $curmem) |
| 802 | 827 | { |
| 803 | 828 | $curmem = trim($curmem); |
| 804 | - if ($curmem != '' && filter_var($curmem, FILTER_VALIDATE_EMAIL)) |
|
| 805 | - $context['recipients']['emails'][$curmem] = $curmem; |
|
| 829 | + if ($curmem != '' && filter_var($curmem, FILTER_VALIDATE_EMAIL)) { |
|
| 830 | + $context['recipients']['emails'][$curmem] = $curmem; |
|
| 831 | + } |
|
| 806 | 832 | } |
| 807 | 833 | } |
| 808 | 834 | |
| 809 | 835 | // If we're only cleaning drop out here. |
| 810 | - if ($clean_only) |
|
| 811 | - return; |
|
| 836 | + if ($clean_only) { |
|
| 837 | + return; |
|
| 838 | + } |
|
| 812 | 839 | |
| 813 | 840 | require_once($sourcedir . '/Subs-Post.php'); |
| 814 | 841 | |
@@ -824,16 +851,18 @@ discard block |
||
| 824 | 851 | if (!$context['send_pm'] && !empty($_POST['send_html'])) |
| 825 | 852 | { |
| 826 | 853 | // Prepare the message for HTML. |
| 827 | - if (!empty($_POST['parse_html'])) |
|
| 828 | - $_POST['message'] = str_replace(array("\n", ' '), array('<br>' . "\n", ' '), $_POST['message']); |
|
| 854 | + if (!empty($_POST['parse_html'])) { |
|
| 855 | + $_POST['message'] = str_replace(array("\n", ' '), array('<br>' . "\n", ' '), $_POST['message']); |
|
| 856 | + } |
|
| 829 | 857 | |
| 830 | 858 | // This is here to prevent spam filters from tagging this as spam. |
| 831 | 859 | if (preg_match('~\<html~i', $_POST['message']) == 0) |
| 832 | 860 | { |
| 833 | - if (preg_match('~\<body~i', $_POST['message']) == 0) |
|
| 834 | - $_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>'; |
|
| 835 | - else |
|
| 836 | - $_POST['message'] = '<html>' . $_POST['message'] . '</html>'; |
|
| 861 | + if (preg_match('~\<body~i', $_POST['message']) == 0) { |
|
| 862 | + $_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>'; |
|
| 863 | + } else { |
|
| 864 | + $_POST['message'] = '<html>' . $_POST['message'] . '</html>'; |
|
| 865 | + } |
|
| 837 | 866 | } |
| 838 | 867 | } |
| 839 | 868 | |
@@ -887,15 +916,17 @@ discard block |
||
| 887 | 916 | foreach ($context['recipients']['emails'] as $k => $email) |
| 888 | 917 | { |
| 889 | 918 | // Done as many as we can? |
| 890 | - if ($i >= $num_at_once) |
|
| 891 | - break; |
|
| 919 | + if ($i >= $num_at_once) { |
|
| 920 | + break; |
|
| 921 | + } |
|
| 892 | 922 | |
| 893 | 923 | // Don't sent it twice! |
| 894 | 924 | unset($context['recipients']['emails'][$k]); |
| 895 | 925 | |
| 896 | 926 | // Dammit - can't PM emails! |
| 897 | - if ($context['send_pm']) |
|
| 898 | - continue; |
|
| 927 | + if ($context['send_pm']) { |
|
| 928 | + continue; |
|
| 929 | + } |
|
| 899 | 930 | |
| 900 | 931 | $to_member = array( |
| 901 | 932 | $email, |
@@ -929,8 +960,9 @@ discard block |
||
| 929 | 960 | $queryBuild[] = 'mem.id_post_group = {int:group_' . $group . '}'; |
| 930 | 961 | } |
| 931 | 962 | } |
| 932 | - if (!empty($queryBuild)) |
|
| 933 | - $sendQuery .= implode(' OR ', $queryBuild); |
|
| 963 | + if (!empty($queryBuild)) { |
|
| 964 | + $sendQuery .= implode(' OR ', $queryBuild); |
|
| 965 | + } |
|
| 934 | 966 | } |
| 935 | 967 | if (!empty($context['recipients']['members'])) |
| 936 | 968 | { |
@@ -949,8 +981,9 @@ discard block |
||
| 949 | 981 | } |
| 950 | 982 | |
| 951 | 983 | // Anything to exclude? |
| 952 | - if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups'])) |
|
| 953 | - $sendQuery .= ' AND mem.id_group != {int:regular_group}'; |
|
| 984 | + if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups'])) { |
|
| 985 | + $sendQuery .= ' AND mem.id_group != {int:regular_group}'; |
|
| 986 | + } |
|
| 954 | 987 | if (!empty($context['recipients']['exclude_members'])) |
| 955 | 988 | { |
| 956 | 989 | $sendQuery .= ' AND mem.id_member NOT IN ({array_int:exclude_members})'; |
@@ -986,21 +1019,24 @@ discard block |
||
| 986 | 1019 | foreach ($rows as $row) |
| 987 | 1020 | { |
| 988 | 1021 | // Force them to have it? |
| 989 | - if (empty($context['email_force']) && empty($prefs[$row['id_member']]['announcements'])) |
|
| 990 | - continue; |
|
| 1022 | + if (empty($context['email_force']) && empty($prefs[$row['id_member']]['announcements'])) { |
|
| 1023 | + continue; |
|
| 1024 | + } |
|
| 991 | 1025 | |
| 992 | 1026 | // What groups are we looking at here? |
| 993 | - if (empty($row['additional_groups'])) |
|
| 994 | - $groups = array($row['id_group'], $row['id_post_group']); |
|
| 995 | - else |
|
| 996 | - $groups = array_merge( |
|
| 1027 | + if (empty($row['additional_groups'])) { |
|
| 1028 | + $groups = array($row['id_group'], $row['id_post_group']); |
|
| 1029 | + } else { |
|
| 1030 | + $groups = array_merge( |
|
| 997 | 1031 | array($row['id_group'], $row['id_post_group']), |
| 998 | 1032 | explode(',', $row['additional_groups']) |
| 999 | 1033 | ); |
| 1034 | + } |
|
| 1000 | 1035 | |
| 1001 | 1036 | // Excluded groups? |
| 1002 | - if (array_intersect($groups, $context['recipients']['exclude_groups'])) |
|
| 1003 | - continue; |
|
| 1037 | + if (array_intersect($groups, $context['recipients']['exclude_groups'])) { |
|
| 1038 | + continue; |
|
| 1039 | + } |
|
| 1004 | 1040 | |
| 1005 | 1041 | // We might need this |
| 1006 | 1042 | $cleanMemberName = empty($_POST['send_html']) || $context['send_pm'] ? un_htmlspecialchars($row['real_name']) : $row['real_name']; |
@@ -1023,10 +1059,11 @@ discard block |
||
| 1023 | 1059 | ), $_POST['subject']); |
| 1024 | 1060 | |
| 1025 | 1061 | // Send the actual email - or a PM! |
| 1026 | - if (!$context['send_pm']) |
|
| 1027 | - sendmail($row['email_address'], $subject, $message, null, 'news', !empty($_POST['send_html']), 5); |
|
| 1028 | - else |
|
| 1029 | - sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message); |
|
| 1062 | + if (!$context['send_pm']) { |
|
| 1063 | + sendmail($row['email_address'], $subject, $message, null, 'news', !empty($_POST['send_html']), 5); |
|
| 1064 | + } else { |
|
| 1065 | + sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message); |
|
| 1066 | + } |
|
| 1030 | 1067 | } |
| 1031 | 1068 | } |
| 1032 | 1069 | |
@@ -1076,8 +1113,9 @@ discard block |
||
| 1076 | 1113 | |
| 1077 | 1114 | call_integration_hook('integrate_modify_news_settings', array(&$config_vars)); |
| 1078 | 1115 | |
| 1079 | - if ($return_config) |
|
| 1080 | - return $config_vars; |
|
| 1116 | + if ($return_config) { |
|
| 1117 | + return $config_vars; |
|
| 1118 | + } |
|
| 1081 | 1119 | |
| 1082 | 1120 | $context['page_title'] = $txt['admin_edit_news'] . ' - ' . $txt['settings']; |
| 1083 | 1121 | $context['sub_template'] = 'show_settings'; |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 4 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /* The contents of this file handle the deletion of topics, posts, and related |
| 21 | 22 | paraphernalia. It has the following functions: |
@@ -37,8 +38,9 @@ discard block |
||
| 37 | 38 | require_once($sourcedir . '/Subs-Post.php'); |
| 38 | 39 | |
| 39 | 40 | // Trying to fool us around, are we? |
| 40 | - if (empty($topic)) |
|
| 41 | - redirectexit(); |
|
| 41 | + if (empty($topic)) { |
|
| 42 | + redirectexit(); |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | removeDeleteConcurrence(); |
| 44 | 46 | |
@@ -55,20 +57,23 @@ discard block |
||
| 55 | 57 | list ($starter, $subject, $approved, $locked) = $smcFunc['db_fetch_row']($request); |
| 56 | 58 | $smcFunc['db_free_result']($request); |
| 57 | 59 | |
| 58 | - if ($starter == $user_info['id'] && !allowedTo('remove_any')) |
|
| 59 | - isAllowedTo('remove_own'); |
|
| 60 | - else |
|
| 61 | - isAllowedTo('remove_any'); |
|
| 60 | + if ($starter == $user_info['id'] && !allowedTo('remove_any')) { |
|
| 61 | + isAllowedTo('remove_own'); |
|
| 62 | + } else { |
|
| 63 | + isAllowedTo('remove_any'); |
|
| 64 | + } |
|
| 62 | 65 | |
| 63 | 66 | // Can they see the topic? |
| 64 | - if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id']) |
|
| 65 | - isAllowedTo('approve_posts'); |
|
| 67 | + if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id']) { |
|
| 68 | + isAllowedTo('approve_posts'); |
|
| 69 | + } |
|
| 66 | 70 | |
| 67 | 71 | // Ok, we got that far, but is it locked? |
| 68 | 72 | if ($locked) |
| 69 | 73 | { |
| 70 | - if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any'))) |
|
| 71 | - fatal_lang_error('cannot_remove_locked', 'user'); |
|
| 74 | + if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any'))) { |
|
| 75 | + fatal_lang_error('cannot_remove_locked', 'user'); |
|
| 76 | + } |
|
| 72 | 77 | } |
| 73 | 78 | |
| 74 | 79 | // Notify people that this topic has been removed. |
@@ -77,8 +82,9 @@ discard block |
||
| 77 | 82 | removeTopics($topic); |
| 78 | 83 | |
| 79 | 84 | // Note, only log topic ID in native form if it's not gone forever. |
| 80 | - if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id'])) |
|
| 81 | - logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board)); |
|
| 85 | + if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id'])) { |
|
| 86 | + logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board)); |
|
| 87 | + } |
|
| 82 | 88 | |
| 83 | 89 | redirectexit('board=' . $board . '.0'); |
| 84 | 90 | } |
@@ -96,8 +102,9 @@ discard block |
||
| 96 | 102 | $_REQUEST['msg'] = (int) $_REQUEST['msg']; |
| 97 | 103 | |
| 98 | 104 | // Is $topic set? |
| 99 | - if (empty($topic) && isset($_REQUEST['topic'])) |
|
| 100 | - $topic = (int) $_REQUEST['topic']; |
|
| 105 | + if (empty($topic) && isset($_REQUEST['topic'])) { |
|
| 106 | + $topic = (int) $_REQUEST['topic']; |
|
| 107 | + } |
|
| 101 | 108 | |
| 102 | 109 | removeDeleteConcurrence(); |
| 103 | 110 | |
@@ -116,44 +123,48 @@ discard block |
||
| 116 | 123 | $smcFunc['db_free_result']($request); |
| 117 | 124 | |
| 118 | 125 | // Verify they can see this! |
| 119 | - if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id']) |
|
| 120 | - isAllowedTo('approve_posts'); |
|
| 126 | + if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id']) { |
|
| 127 | + isAllowedTo('approve_posts'); |
|
| 128 | + } |
|
| 121 | 129 | |
| 122 | 130 | if ($poster == $user_info['id']) |
| 123 | 131 | { |
| 124 | 132 | if (!allowedTo('delete_own')) |
| 125 | 133 | { |
| 126 | - if ($starter == $user_info['id'] && !allowedTo('delete_any')) |
|
| 127 | - isAllowedTo('delete_replies'); |
|
| 128 | - elseif (!allowedTo('delete_any')) |
|
| 129 | - isAllowedTo('delete_own'); |
|
| 134 | + if ($starter == $user_info['id'] && !allowedTo('delete_any')) { |
|
| 135 | + isAllowedTo('delete_replies'); |
|
| 136 | + } elseif (!allowedTo('delete_any')) { |
|
| 137 | + isAllowedTo('delete_own'); |
|
| 138 | + } |
|
| 139 | + } elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time()) { |
|
| 140 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 130 | 141 | } |
| 131 | - elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time()) |
|
| 132 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 142 | + } elseif ($starter == $user_info['id'] && !allowedTo('delete_any')) { |
|
| 143 | + isAllowedTo('delete_replies'); |
|
| 144 | + } else { |
|
| 145 | + isAllowedTo('delete_any'); |
|
| 133 | 146 | } |
| 134 | - elseif ($starter == $user_info['id'] && !allowedTo('delete_any')) |
|
| 135 | - isAllowedTo('delete_replies'); |
|
| 136 | - else |
|
| 137 | - isAllowedTo('delete_any'); |
|
| 138 | 147 | |
| 139 | 148 | // If the full topic was removed go back to the board. |
| 140 | 149 | $full_topic = removeMessage($_REQUEST['msg']); |
| 141 | 150 | |
| 142 | - if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id'])) |
|
| 143 | - logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board)); |
|
| 151 | + if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id'])) { |
|
| 152 | + logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board)); |
|
| 153 | + } |
|
| 144 | 154 | |
| 145 | 155 | // We want to redirect back to recent action. |
| 146 | - if (isset($_REQUEST['modcenter'])) |
|
| 147 | - redirectexit('action=moderate;area=reportedposts;done'); |
|
| 148 | - elseif (isset($_REQUEST['recent'])) |
|
| 149 | - redirectexit('action=recent'); |
|
| 150 | - elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u'])) |
|
| 151 | - redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']); |
|
| 152 | - elseif ($full_topic) |
|
| 153 | - redirectexit('board=' . $board . '.0'); |
|
| 154 | - else |
|
| 155 | - redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
| 156 | -} |
|
| 156 | + if (isset($_REQUEST['modcenter'])) { |
|
| 157 | + redirectexit('action=moderate;area=reportedposts;done'); |
|
| 158 | + } elseif (isset($_REQUEST['recent'])) { |
|
| 159 | + redirectexit('action=recent'); |
|
| 160 | + } elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u'])) { |
|
| 161 | + redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']); |
|
| 162 | + } elseif ($full_topic) { |
|
| 163 | + redirectexit('board=' . $board . '.0'); |
|
| 164 | + } else { |
|
| 165 | + redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
| 166 | + } |
|
| 167 | + } |
|
| 157 | 168 | |
| 158 | 169 | /** |
| 159 | 170 | * So long as you are sure... all old posts will be gone. |
@@ -167,8 +178,9 @@ discard block |
||
| 167 | 178 | checkSession('post', 'admin'); |
| 168 | 179 | |
| 169 | 180 | // No boards at all? Forget it then :/. |
| 170 | - if (empty($_POST['boards'])) |
|
| 171 | - redirectexit('action=admin;area=maintain;sa=topics'); |
|
| 181 | + if (empty($_POST['boards'])) { |
|
| 182 | + redirectexit('action=admin;area=maintain;sa=topics'); |
|
| 183 | + } |
|
| 172 | 184 | |
| 173 | 185 | // This should exist, but we can make sure. |
| 174 | 186 | $_POST['delete_type'] = isset($_POST['delete_type']) ? $_POST['delete_type'] : 'nothing'; |
@@ -222,8 +234,9 @@ discard block |
||
| 222 | 234 | $condition_params |
| 223 | 235 | ); |
| 224 | 236 | $topics = array(); |
| 225 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 226 | - $topics[] = $row['id_topic']; |
|
| 237 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 238 | + $topics[] = $row['id_topic']; |
|
| 239 | + } |
|
| 227 | 240 | $smcFunc['db_free_result']($request); |
| 228 | 241 | |
| 229 | 242 | removeTopics($topics, false, true); |
@@ -247,11 +260,13 @@ discard block |
||
| 247 | 260 | global $sourcedir, $modSettings, $smcFunc; |
| 248 | 261 | |
| 249 | 262 | // Nothing to do? |
| 250 | - if (empty($topics)) |
|
| 251 | - return; |
|
| 263 | + if (empty($topics)) { |
|
| 264 | + return; |
|
| 265 | + } |
|
| 252 | 266 | // Only a single topic. |
| 253 | - if (is_numeric($topics)) |
|
| 254 | - $topics = array($topics); |
|
| 267 | + if (is_numeric($topics)) { |
|
| 268 | + $topics = array($topics); |
|
| 269 | + } |
|
| 255 | 270 | |
| 256 | 271 | $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
| 257 | 272 | |
@@ -276,8 +291,9 @@ discard block |
||
| 276 | 291 | ); |
| 277 | 292 | if ($smcFunc['db_num_rows']($requestMembers) > 0) |
| 278 | 293 | { |
| 279 | - while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers)) |
|
| 280 | - updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts'])); |
|
| 294 | + while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers)) { |
|
| 295 | + updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts'])); |
|
| 296 | + } |
|
| 281 | 297 | } |
| 282 | 298 | $smcFunc['db_free_result']($requestMembers); |
| 283 | 299 | } |
@@ -303,8 +319,9 @@ discard block |
||
| 303 | 319 | $recycleTopics = array(); |
| 304 | 320 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 305 | 321 | { |
| 306 | - if (function_exists('apache_reset_timeout')) |
|
| 307 | - @apache_reset_timeout(); |
|
| 322 | + if (function_exists('apache_reset_timeout')) { |
|
| 323 | + @apache_reset_timeout(); |
|
| 324 | + } |
|
| 308 | 325 | |
| 309 | 326 | $recycleTopics[] = $row['id_topic']; |
| 310 | 327 | |
@@ -346,20 +363,22 @@ discard block |
||
| 346 | 363 | |
| 347 | 364 | // Topics that were recycled don't need to be deleted, so subtract them. |
| 348 | 365 | $topics = array_diff($topics, $recycleTopics); |
| 366 | + } else { |
|
| 367 | + $smcFunc['db_free_result']($request); |
|
| 349 | 368 | } |
| 350 | - else |
|
| 351 | - $smcFunc['db_free_result']($request); |
|
| 352 | 369 | } |
| 353 | 370 | |
| 354 | 371 | // Still topics left to delete? |
| 355 | - if (empty($topics)) |
|
| 356 | - return; |
|
| 372 | + if (empty($topics)) { |
|
| 373 | + return; |
|
| 374 | + } |
|
| 357 | 375 | |
| 358 | 376 | // Callback for search APIs to do their thing |
| 359 | 377 | require_once($sourcedir . '/Search.php'); |
| 360 | 378 | $searchAPI = findSearchAPI(); |
| 361 | - if ($searchAPI->supportsMethod('topicsRemoved')) |
|
| 362 | - $searchAPI->topicsRemoved($topics); |
|
| 379 | + if ($searchAPI->supportsMethod('topicsRemoved')) { |
|
| 380 | + $searchAPI->topicsRemoved($topics); |
|
| 381 | + } |
|
| 363 | 382 | |
| 364 | 383 | $adjustBoards = array(); |
| 365 | 384 | |
@@ -391,10 +410,11 @@ discard block |
||
| 391 | 410 | $adjustBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts']; |
| 392 | 411 | |
| 393 | 412 | // Add the topics to the right type. |
| 394 | - if ($row['approved']) |
|
| 395 | - $adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics']; |
|
| 396 | - else |
|
| 397 | - $adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics']; |
|
| 413 | + if ($row['approved']) { |
|
| 414 | + $adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics']; |
|
| 415 | + } else { |
|
| 416 | + $adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics']; |
|
| 417 | + } |
|
| 398 | 418 | } |
| 399 | 419 | $smcFunc['db_free_result']($request); |
| 400 | 420 | |
@@ -403,8 +423,9 @@ discard block |
||
| 403 | 423 | // Decrease the posts/topics... |
| 404 | 424 | foreach ($adjustBoards as $stats) |
| 405 | 425 | { |
| 406 | - if (function_exists('apache_reset_timeout')) |
|
| 407 | - @apache_reset_timeout(); |
|
| 426 | + if (function_exists('apache_reset_timeout')) { |
|
| 427 | + @apache_reset_timeout(); |
|
| 428 | + } |
|
| 408 | 429 | |
| 409 | 430 | $smcFunc['db_query']('', ' |
| 410 | 431 | UPDATE {db_prefix}boards |
@@ -438,8 +459,9 @@ discard block |
||
| 438 | 459 | ) |
| 439 | 460 | ); |
| 440 | 461 | $polls = array(); |
| 441 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 442 | - $polls[] = $row['id_poll']; |
|
| 462 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 463 | + $polls[] = $row['id_poll']; |
|
| 464 | + } |
|
| 443 | 465 | $smcFunc['db_free_result']($request); |
| 444 | 466 | |
| 445 | 467 | if (!empty($polls)) |
@@ -492,8 +514,9 @@ discard block |
||
| 492 | 514 | ); |
| 493 | 515 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 494 | 516 | { |
| 495 | - if (function_exists('apache_reset_timeout')) |
|
| 496 | - @apache_reset_timeout(); |
|
| 517 | + if (function_exists('apache_reset_timeout')) { |
|
| 518 | + @apache_reset_timeout(); |
|
| 519 | + } |
|
| 497 | 520 | |
| 498 | 521 | $words = array_merge($words, text2words($row['body'], $customIndexSettings['bytes_per_word'], true)); |
| 499 | 522 | $messages[] = $row['id_msg']; |
@@ -501,8 +524,8 @@ discard block |
||
| 501 | 524 | $smcFunc['db_free_result']($request); |
| 502 | 525 | $words = array_unique($words); |
| 503 | 526 | |
| 504 | - if (!empty($words) && !empty($messages)) |
|
| 505 | - $smcFunc['db_query']('', ' |
|
| 527 | + if (!empty($words) && !empty($messages)) { |
|
| 528 | + $smcFunc['db_query']('', ' |
|
| 506 | 529 | DELETE FROM {db_prefix}log_search_words |
| 507 | 530 | WHERE id_word IN ({array_int:word_list}) |
| 508 | 531 | AND id_msg IN ({array_int:message_list})', |
@@ -511,6 +534,7 @@ discard block |
||
| 511 | 534 | 'message_list' => $messages, |
| 512 | 535 | ) |
| 513 | 536 | ); |
| 537 | + } |
|
| 514 | 538 | } |
| 515 | 539 | |
| 516 | 540 | // Delete anything related to the topic. |
@@ -569,8 +593,9 @@ discard block |
||
| 569 | 593 | |
| 570 | 594 | require_once($sourcedir . '/Subs-Post.php'); |
| 571 | 595 | $updates = array(); |
| 572 | - foreach ($adjustBoards as $stats) |
|
| 573 | - $updates[] = $stats['id_board']; |
|
| 596 | + foreach ($adjustBoards as $stats) { |
|
| 597 | + $updates[] = $stats['id_board']; |
|
| 598 | + } |
|
| 574 | 599 | updateLastMessages($updates); |
| 575 | 600 | } |
| 576 | 601 | |
@@ -587,8 +612,9 @@ discard block |
||
| 587 | 612 | { |
| 588 | 613 | global $board, $sourcedir, $modSettings, $user_info, $smcFunc; |
| 589 | 614 | |
| 590 | - if (empty($message) || !is_numeric($message)) |
|
| 591 | - return false; |
|
| 615 | + if (empty($message) || !is_numeric($message)) { |
|
| 616 | + return false; |
|
| 617 | + } |
|
| 592 | 618 | |
| 593 | 619 | $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
| 594 | 620 | |
@@ -607,8 +633,9 @@ discard block |
||
| 607 | 633 | 'id_msg' => $message, |
| 608 | 634 | ) |
| 609 | 635 | ); |
| 610 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 611 | - return false; |
|
| 636 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 637 | + return false; |
|
| 638 | + } |
|
| 612 | 639 | $row = $smcFunc['db_fetch_assoc']($request); |
| 613 | 640 | $smcFunc['db_free_result']($request); |
| 614 | 641 | |
@@ -629,54 +656,57 @@ discard block |
||
| 629 | 656 | { |
| 630 | 657 | if ($row['id_member_poster'] == $user_info['id']) |
| 631 | 658 | { |
| 632 | - if (!$delete_replies) |
|
| 633 | - fatal_lang_error('cannot_delete_replies', 'permission'); |
|
| 659 | + if (!$delete_replies) { |
|
| 660 | + fatal_lang_error('cannot_delete_replies', 'permission'); |
|
| 661 | + } |
|
| 662 | + } else { |
|
| 663 | + fatal_lang_error('cannot_delete_own', 'permission'); |
|
| 634 | 664 | } |
| 635 | - else |
|
| 636 | - fatal_lang_error('cannot_delete_own', 'permission'); |
|
| 665 | + } elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) { |
|
| 666 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 637 | 667 | } |
| 638 | - elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) |
|
| 639 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 640 | - } |
|
| 641 | - elseif ($row['id_member_poster'] == $user_info['id']) |
|
| 668 | + } elseif ($row['id_member_poster'] == $user_info['id']) |
|
| 642 | 669 | { |
| 643 | - if (!$delete_replies) |
|
| 644 | - fatal_lang_error('cannot_delete_replies', 'permission'); |
|
| 670 | + if (!$delete_replies) { |
|
| 671 | + fatal_lang_error('cannot_delete_replies', 'permission'); |
|
| 672 | + } |
|
| 673 | + } else { |
|
| 674 | + fatal_lang_error('cannot_delete_any', 'permission'); |
|
| 645 | 675 | } |
| 646 | - else |
|
| 647 | - fatal_lang_error('cannot_delete_any', 'permission'); |
|
| 648 | 676 | } |
| 649 | 677 | |
| 650 | 678 | // Can't delete an unapproved message, if you can't see it! |
| 651 | 679 | if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !(in_array(0, $delete_any) || in_array($row['id_board'], $delete_any))) |
| 652 | 680 | { |
| 653 | 681 | $approve_posts = boardsAllowedTo('approve_posts'); |
| 654 | - if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts)) |
|
| 655 | - return false; |
|
| 682 | + if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts)) { |
|
| 683 | + return false; |
|
| 684 | + } |
|
| 656 | 685 | } |
| 657 | - } |
|
| 658 | - else |
|
| 686 | + } else |
|
| 659 | 687 | { |
| 660 | 688 | // Check permissions to delete this message. |
| 661 | 689 | if ($row['id_member'] == $user_info['id']) |
| 662 | 690 | { |
| 663 | 691 | if (!allowedTo('delete_own')) |
| 664 | 692 | { |
| 665 | - if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) |
|
| 666 | - isAllowedTo('delete_replies'); |
|
| 667 | - elseif (!allowedTo('delete_any')) |
|
| 668 | - isAllowedTo('delete_own'); |
|
| 693 | + if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) { |
|
| 694 | + isAllowedTo('delete_replies'); |
|
| 695 | + } elseif (!allowedTo('delete_any')) { |
|
| 696 | + isAllowedTo('delete_own'); |
|
| 697 | + } |
|
| 698 | + } elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) { |
|
| 699 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 669 | 700 | } |
| 670 | - elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) |
|
| 671 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 701 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) { |
|
| 702 | + isAllowedTo('delete_replies'); |
|
| 703 | + } else { |
|
| 704 | + isAllowedTo('delete_any'); |
|
| 672 | 705 | } |
| 673 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) |
|
| 674 | - isAllowedTo('delete_replies'); |
|
| 675 | - else |
|
| 676 | - isAllowedTo('delete_any'); |
|
| 677 | 706 | |
| 678 | - if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own')) |
|
| 679 | - isAllowedTo('approve_posts'); |
|
| 707 | + if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own')) { |
|
| 708 | + isAllowedTo('approve_posts'); |
|
| 709 | + } |
|
| 680 | 710 | } |
| 681 | 711 | |
| 682 | 712 | // Delete the *whole* topic, but only if the topic consists of one message. |
@@ -692,31 +722,34 @@ discard block |
||
| 692 | 722 | $remove_own = in_array(0, $remove_own) || in_array($row['id_board'], $remove_own); |
| 693 | 723 | } |
| 694 | 724 | |
| 695 | - if ($row['id_member'] != $user_info['id'] && !$remove_any) |
|
| 696 | - fatal_lang_error('cannot_remove_any', 'permission'); |
|
| 697 | - elseif (!$remove_any && !$remove_own) |
|
| 698 | - fatal_lang_error('cannot_remove_own', 'permission'); |
|
| 699 | - } |
|
| 700 | - else |
|
| 725 | + if ($row['id_member'] != $user_info['id'] && !$remove_any) { |
|
| 726 | + fatal_lang_error('cannot_remove_any', 'permission'); |
|
| 727 | + } elseif (!$remove_any && !$remove_own) { |
|
| 728 | + fatal_lang_error('cannot_remove_own', 'permission'); |
|
| 729 | + } |
|
| 730 | + } else |
|
| 701 | 731 | { |
| 702 | 732 | // Check permissions to delete a whole topic. |
| 703 | - if ($row['id_member'] != $user_info['id']) |
|
| 704 | - isAllowedTo('remove_any'); |
|
| 705 | - elseif (!allowedTo('remove_any')) |
|
| 706 | - isAllowedTo('remove_own'); |
|
| 733 | + if ($row['id_member'] != $user_info['id']) { |
|
| 734 | + isAllowedTo('remove_any'); |
|
| 735 | + } elseif (!allowedTo('remove_any')) { |
|
| 736 | + isAllowedTo('remove_own'); |
|
| 737 | + } |
|
| 707 | 738 | } |
| 708 | 739 | |
| 709 | 740 | // ...if there is only one post. |
| 710 | - if (!empty($row['num_replies'])) |
|
| 711 | - fatal_lang_error('delFirstPost', false); |
|
| 741 | + if (!empty($row['num_replies'])) { |
|
| 742 | + fatal_lang_error('delFirstPost', false); |
|
| 743 | + } |
|
| 712 | 744 | |
| 713 | 745 | removeTopics($row['id_topic']); |
| 714 | 746 | return true; |
| 715 | 747 | } |
| 716 | 748 | |
| 717 | 749 | // Deleting a recycled message can not lower anyone's post count. |
| 718 | - if (!empty($recycle_board) && $row['id_board'] == $recycle_board) |
|
| 719 | - $decreasePostCount = false; |
|
| 750 | + if (!empty($recycle_board) && $row['id_board'] == $recycle_board) { |
|
| 751 | + $decreasePostCount = false; |
|
| 752 | + } |
|
| 720 | 753 | |
| 721 | 754 | // This is the last post, update the last post on the board. |
| 722 | 755 | if ($row['id_last_msg'] == $message) |
@@ -755,8 +788,8 @@ discard block |
||
| 755 | 788 | ); |
| 756 | 789 | } |
| 757 | 790 | // Only decrease post counts. |
| 758 | - else |
|
| 759 | - $smcFunc['db_query']('', ' |
|
| 791 | + else { |
|
| 792 | + $smcFunc['db_query']('', ' |
|
| 760 | 793 | UPDATE {db_prefix}topics |
| 761 | 794 | SET ' . ($row['approved'] ? ' |
| 762 | 795 | num_replies = CASE WHEN num_replies = {int:no_replies} THEN 0 ELSE num_replies - 1 END' : ' |
@@ -768,6 +801,7 @@ discard block |
||
| 768 | 801 | 'id_topic' => $row['id_topic'], |
| 769 | 802 | ) |
| 770 | 803 | ); |
| 804 | + } |
|
| 771 | 805 | |
| 772 | 806 | // Default recycle to false. |
| 773 | 807 | $recycle = false; |
@@ -787,8 +821,9 @@ discard block |
||
| 787 | 821 | 'recycle_board' => $modSettings['recycle_board'], |
| 788 | 822 | ) |
| 789 | 823 | ); |
| 790 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 791 | - fatal_lang_error('recycle_no_valid_board'); |
|
| 824 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 825 | + fatal_lang_error('recycle_no_valid_board'); |
|
| 826 | + } |
|
| 792 | 827 | list ($isRead, $last_board_msg) = $smcFunc['db_fetch_row']($request); |
| 793 | 828 | $smcFunc['db_free_result']($request); |
| 794 | 829 | |
@@ -807,8 +842,8 @@ discard block |
||
| 807 | 842 | $smcFunc['db_free_result']($request); |
| 808 | 843 | |
| 809 | 844 | // Insert a new topic in the recycle board if $id_recycle_topic is empty. |
| 810 | - if (empty($id_recycle_topic)) |
|
| 811 | - $id_topic = $smcFunc['db_insert']('', |
|
| 845 | + if (empty($id_recycle_topic)) { |
|
| 846 | + $id_topic = $smcFunc['db_insert']('', |
|
| 812 | 847 | '{db_prefix}topics', |
| 813 | 848 | array( |
| 814 | 849 | 'id_board' => 'int', 'id_member_started' => 'int', 'id_member_updated' => 'int', 'id_first_msg' => 'int', |
@@ -821,6 +856,7 @@ discard block |
||
| 821 | 856 | array('id_topic'), |
| 822 | 857 | 1 |
| 823 | 858 | ); |
| 859 | + } |
|
| 824 | 860 | |
| 825 | 861 | // Capture the ID of the new topic... |
| 826 | 862 | $topicID = empty($id_recycle_topic) ? $id_topic : $id_recycle_topic; |
@@ -858,22 +894,24 @@ discard block |
||
| 858 | 894 | ); |
| 859 | 895 | |
| 860 | 896 | // Mark recycled topic as read. |
| 861 | - if (!$user_info['is_guest']) |
|
| 862 | - $smcFunc['db_insert']('replace', |
|
| 897 | + if (!$user_info['is_guest']) { |
|
| 898 | + $smcFunc['db_insert']('replace', |
|
| 863 | 899 | '{db_prefix}log_topics', |
| 864 | 900 | array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int', 'unwatched' => 'int'), |
| 865 | 901 | array($topicID, $user_info['id'], $modSettings['maxMsgID'], 0), |
| 866 | 902 | array('id_topic', 'id_member') |
| 867 | 903 | ); |
| 904 | + } |
|
| 868 | 905 | |
| 869 | 906 | // Mark recycle board as seen, if it was marked as seen before. |
| 870 | - if (!empty($isRead) && !$user_info['is_guest']) |
|
| 871 | - $smcFunc['db_insert']('replace', |
|
| 907 | + if (!empty($isRead) && !$user_info['is_guest']) { |
|
| 908 | + $smcFunc['db_insert']('replace', |
|
| 872 | 909 | '{db_prefix}log_boards', |
| 873 | 910 | array('id_board' => 'int', 'id_member' => 'int', 'id_msg' => 'int'), |
| 874 | 911 | array($modSettings['recycle_board'], $user_info['id'], $modSettings['maxMsgID']), |
| 875 | 912 | array('id_board', 'id_member') |
| 876 | 913 | ); |
| 914 | + } |
|
| 877 | 915 | |
| 878 | 916 | // Add one topic and post to the recycle bin board. |
| 879 | 917 | $smcFunc['db_query']('', ' |
@@ -891,8 +929,8 @@ discard block |
||
| 891 | 929 | ); |
| 892 | 930 | |
| 893 | 931 | // Lets increase the num_replies, and the first/last message ID as appropriate. |
| 894 | - if (!empty($id_recycle_topic)) |
|
| 895 | - $smcFunc['db_query']('', ' |
|
| 932 | + if (!empty($id_recycle_topic)) { |
|
| 933 | + $smcFunc['db_query']('', ' |
|
| 896 | 934 | UPDATE {db_prefix}topics |
| 897 | 935 | SET num_replies = num_replies + 1' . |
| 898 | 936 | ($message > $last_topic_msg ? ', id_last_msg = {int:id_merged_msg}' : '') . |
@@ -903,6 +941,7 @@ discard block |
||
| 903 | 941 | 'id_merged_msg' => $message, |
| 904 | 942 | ) |
| 905 | 943 | ); |
| 944 | + } |
|
| 906 | 945 | |
| 907 | 946 | // Make sure this message isn't getting deleted later on. |
| 908 | 947 | $recycle = true; |
@@ -912,8 +951,8 @@ discard block |
||
| 912 | 951 | } |
| 913 | 952 | |
| 914 | 953 | // If it wasn't approved don't keep it in the queue. |
| 915 | - if (!$row['approved']) |
|
| 916 | - $smcFunc['db_query']('', ' |
|
| 954 | + if (!$row['approved']) { |
|
| 955 | + $smcFunc['db_query']('', ' |
|
| 917 | 956 | DELETE FROM {db_prefix}approval_queue |
| 918 | 957 | WHERE id_msg = {int:id_msg} |
| 919 | 958 | AND id_attach = {int:id_attach}', |
@@ -922,6 +961,7 @@ discard block |
||
| 922 | 961 | 'id_attach' => 0, |
| 923 | 962 | ) |
| 924 | 963 | ); |
| 964 | + } |
|
| 925 | 965 | } |
| 926 | 966 | |
| 927 | 967 | $smcFunc['db_query']('', ' |
@@ -939,8 +979,9 @@ discard block |
||
| 939 | 979 | |
| 940 | 980 | // If the poster was registered and the board this message was on incremented |
| 941 | 981 | // the member's posts when it was posted, decrease his or her post count. |
| 942 | - if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved']) |
|
| 943 | - updateMemberData($row['id_member'], array('posts' => '-')); |
|
| 982 | + if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved']) { |
|
| 983 | + updateMemberData($row['id_member'], array('posts' => '-')); |
|
| 984 | + } |
|
| 944 | 985 | |
| 945 | 986 | // Only remove posts if they're not recycled. |
| 946 | 987 | if (!$recycle) |
@@ -948,8 +989,9 @@ discard block |
||
| 948 | 989 | // Callback for search APIs to do their thing |
| 949 | 990 | require_once($sourcedir . '/Search.php'); |
| 950 | 991 | $searchAPI = findSearchAPI(); |
| 951 | - if ($searchAPI->supportsMethod('postRemoved')) |
|
| 952 | - $searchAPI->postRemoved($message); |
|
| 992 | + if ($searchAPI->supportsMethod('postRemoved')) { |
|
| 993 | + $searchAPI->postRemoved($message); |
|
| 994 | + } |
|
| 953 | 995 | |
| 954 | 996 | // Remove the message! |
| 955 | 997 | $smcFunc['db_query']('', ' |
@@ -964,8 +1006,8 @@ discard block |
||
| 964 | 1006 | { |
| 965 | 1007 | $customIndexSettings = smf_json_decode($modSettings['search_custom_index_config'], true); |
| 966 | 1008 | $words = text2words($row['body'], $customIndexSettings['bytes_per_word'], true); |
| 967 | - if (!empty($words)) |
|
| 968 | - $smcFunc['db_query']('', ' |
|
| 1009 | + if (!empty($words)) { |
|
| 1010 | + $smcFunc['db_query']('', ' |
|
| 969 | 1011 | DELETE FROM {db_prefix}log_search_words |
| 970 | 1012 | WHERE id_word IN ({array_int:word_list}) |
| 971 | 1013 | AND id_msg = {int:id_msg}', |
@@ -974,6 +1016,7 @@ discard block |
||
| 974 | 1016 | 'id_msg' => $message, |
| 975 | 1017 | ) |
| 976 | 1018 | ); |
| 1019 | + } |
|
| 977 | 1020 | } |
| 978 | 1021 | |
| 979 | 1022 | // Delete attachment(s) if they exist. |
@@ -997,10 +1040,11 @@ discard block |
||
| 997 | 1040 | |
| 998 | 1041 | // And now to update the last message of each board we messed with. |
| 999 | 1042 | require_once($sourcedir . '/Subs-Post.php'); |
| 1000 | - if ($recycle) |
|
| 1001 | - updateLastMessages(array($row['id_board'], $modSettings['recycle_board'])); |
|
| 1002 | - else |
|
| 1003 | - updateLastMessages($row['id_board']); |
|
| 1043 | + if ($recycle) { |
|
| 1044 | + updateLastMessages(array($row['id_board'], $modSettings['recycle_board'])); |
|
| 1045 | + } else { |
|
| 1046 | + updateLastMessages($row['id_board']); |
|
| 1047 | + } |
|
| 1004 | 1048 | |
| 1005 | 1049 | // Close any moderation reports for this message. |
| 1006 | 1050 | $smcFunc['db_query']('', ' |
@@ -1033,8 +1077,9 @@ discard block |
||
| 1033 | 1077 | checkSession('get'); |
| 1034 | 1078 | |
| 1035 | 1079 | // Is recycled board enabled? |
| 1036 | - if (empty($modSettings['recycle_enable'])) |
|
| 1037 | - fatal_lang_error('restored_disabled', 'critical'); |
|
| 1080 | + if (empty($modSettings['recycle_enable'])) { |
|
| 1081 | + fatal_lang_error('restored_disabled', 'critical'); |
|
| 1082 | + } |
|
| 1038 | 1083 | |
| 1039 | 1084 | // Can we be in here? |
| 1040 | 1085 | isAllowedTo('move_any', $modSettings['recycle_board']); |
@@ -1049,8 +1094,9 @@ discard block |
||
| 1049 | 1094 | if (!empty($_REQUEST['msgs'])) |
| 1050 | 1095 | { |
| 1051 | 1096 | $msgs = explode(',', $_REQUEST['msgs']); |
| 1052 | - foreach ($msgs as $k => $msg) |
|
| 1053 | - $msgs[$k] = (int) $msg; |
|
| 1097 | + foreach ($msgs as $k => $msg) { |
|
| 1098 | + $msgs[$k] = (int) $msg; |
|
| 1099 | + } |
|
| 1054 | 1100 | |
| 1055 | 1101 | // Get the id_previous_board and id_previous_topic. |
| 1056 | 1102 | $request = $smcFunc['db_query']('', ' |
@@ -1084,8 +1130,8 @@ discard block |
||
| 1084 | 1130 | } |
| 1085 | 1131 | |
| 1086 | 1132 | $previous_topics[] = $row['id_previous_topic']; |
| 1087 | - if (empty($actioned_messages[$row['id_previous_topic']])) |
|
| 1088 | - $actioned_messages[$row['id_previous_topic']] = array( |
|
| 1133 | + if (empty($actioned_messages[$row['id_previous_topic']])) { |
|
| 1134 | + $actioned_messages[$row['id_previous_topic']] = array( |
|
| 1089 | 1135 | 'msgs' => array(), |
| 1090 | 1136 | 'count_posts' => $row['count_posts'], |
| 1091 | 1137 | 'subject' => $row['subject'], |
@@ -1095,17 +1141,20 @@ discard block |
||
| 1095 | 1141 | 'current_board' => $row['id_board'], |
| 1096 | 1142 | 'members' => array(), |
| 1097 | 1143 | ); |
| 1144 | + } |
|
| 1098 | 1145 | |
| 1099 | 1146 | $actioned_messages[$row['id_previous_topic']]['msgs'][$row['id_msg']] = $row['subject']; |
| 1100 | - if ($row['id_member']) |
|
| 1101 | - $actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member']; |
|
| 1147 | + if ($row['id_member']) { |
|
| 1148 | + $actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member']; |
|
| 1149 | + } |
|
| 1102 | 1150 | } |
| 1103 | 1151 | $smcFunc['db_free_result']($request); |
| 1104 | 1152 | |
| 1105 | 1153 | // Check for topics we are going to fully restore. |
| 1106 | - foreach ($actioned_messages as $topic => $data) |
|
| 1107 | - if (in_array($topic, $topics_to_restore)) |
|
| 1154 | + foreach ($actioned_messages as $topic => $data) { |
|
| 1155 | + if (in_array($topic, $topics_to_restore)) |
|
| 1108 | 1156 | unset($actioned_messages[$topic]); |
| 1157 | + } |
|
| 1109 | 1158 | |
| 1110 | 1159 | // Load any previous topics to check they exist. |
| 1111 | 1160 | if (!empty($previous_topics)) |
@@ -1120,11 +1169,12 @@ discard block |
||
| 1120 | 1169 | ) |
| 1121 | 1170 | ); |
| 1122 | 1171 | $previous_topics = array(); |
| 1123 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1124 | - $previous_topics[$row['id_topic']] = array( |
|
| 1172 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1173 | + $previous_topics[$row['id_topic']] = array( |
|
| 1125 | 1174 | 'board' => $row['id_board'], |
| 1126 | 1175 | 'subject' => $row['subject'], |
| 1127 | 1176 | ); |
| 1177 | + } |
|
| 1128 | 1178 | $smcFunc['db_free_result']($request); |
| 1129 | 1179 | } |
| 1130 | 1180 | |
@@ -1146,11 +1196,11 @@ discard block |
||
| 1146 | 1196 | // Log em. |
| 1147 | 1197 | logAction('restore_posts', array('topic' => $topic, 'subject' => $previous_topics[$topic]['subject'], 'board' => empty($data['previous_board']) ? $data['possible_prev_board'] : $data['previous_board'])); |
| 1148 | 1198 | $messages = array_merge(array_keys($data['msgs']), $messages); |
| 1149 | - } |
|
| 1150 | - else |
|
| 1199 | + } else |
|
| 1151 | 1200 | { |
| 1152 | - foreach ($data['msgs'] as $msg) |
|
| 1153 | - $unfound_messages[$msg['id']] = $msg['subject']; |
|
| 1201 | + foreach ($data['msgs'] as $msg) { |
|
| 1202 | + $unfound_messages[$msg['id']] = $msg['subject']; |
|
| 1203 | + } |
|
| 1154 | 1204 | } |
| 1155 | 1205 | } |
| 1156 | 1206 | } |
@@ -1159,8 +1209,9 @@ discard block |
||
| 1159 | 1209 | if (!empty($_REQUEST['topics'])) |
| 1160 | 1210 | { |
| 1161 | 1211 | $topics = explode(',', $_REQUEST['topics']); |
| 1162 | - foreach ($topics as $id) |
|
| 1163 | - $topics_to_restore[] = (int) $id; |
|
| 1212 | + foreach ($topics as $id) { |
|
| 1213 | + $topics_to_restore[] = (int) $id; |
|
| 1214 | + } |
|
| 1164 | 1215 | } |
| 1165 | 1216 | |
| 1166 | 1217 | if (!empty($topics_to_restore)) |
@@ -1214,8 +1265,9 @@ discard block |
||
| 1214 | 1265 | ) |
| 1215 | 1266 | ); |
| 1216 | 1267 | |
| 1217 | - while ($member = $smcFunc['db_fetch_assoc']($request2)) |
|
| 1218 | - updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count'])); |
|
| 1268 | + while ($member = $smcFunc['db_fetch_assoc']($request2)) { |
|
| 1269 | + updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count'])); |
|
| 1270 | + } |
|
| 1219 | 1271 | $smcFunc['db_free_result']($request2); |
| 1220 | 1272 | } |
| 1221 | 1273 | |
@@ -1226,8 +1278,9 @@ discard block |
||
| 1226 | 1278 | } |
| 1227 | 1279 | |
| 1228 | 1280 | // Didn't find some things? |
| 1229 | - if (!empty($unfound_messages)) |
|
| 1230 | - fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages))); |
|
| 1281 | + if (!empty($unfound_messages)) { |
|
| 1282 | + fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages))); |
|
| 1283 | + } |
|
| 1231 | 1284 | |
| 1232 | 1285 | // Just send them to the index if they get here. |
| 1233 | 1286 | redirectexit(); |
@@ -1247,12 +1300,14 @@ discard block |
||
| 1247 | 1300 | //!!! This really needs to be rewritten to take a load of messages from ANY topic, it's also inefficient. |
| 1248 | 1301 | |
| 1249 | 1302 | // Is it an array? |
| 1250 | - if (!is_array($msgs)) |
|
| 1251 | - $msgs = array($msgs); |
|
| 1303 | + if (!is_array($msgs)) { |
|
| 1304 | + $msgs = array($msgs); |
|
| 1305 | + } |
|
| 1252 | 1306 | |
| 1253 | 1307 | // Lets make sure they are int. |
| 1254 | - foreach ($msgs as $key => $msg) |
|
| 1255 | - $msgs[$key] = (int) $msg; |
|
| 1308 | + foreach ($msgs as $key => $msg) { |
|
| 1309 | + $msgs[$key] = (int) $msg; |
|
| 1310 | + } |
|
| 1256 | 1311 | |
| 1257 | 1312 | // Get the source information. |
| 1258 | 1313 | $request = $smcFunc['db_query']('', ' |
@@ -1295,8 +1350,9 @@ discard block |
||
| 1295 | 1350 | ) |
| 1296 | 1351 | ); |
| 1297 | 1352 | |
| 1298 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1299 | - updateMemberData($row['id_member'], array('posts' => '+')); |
|
| 1353 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1354 | + updateMemberData($row['id_member'], array('posts' => '+')); |
|
| 1355 | + } |
|
| 1300 | 1356 | } |
| 1301 | 1357 | |
| 1302 | 1358 | // Time to move the messages. |
@@ -1332,13 +1388,15 @@ discard block |
||
| 1332 | 1388 | ); |
| 1333 | 1389 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1334 | 1390 | { |
| 1335 | - if ($row['id_first_msg'] < $target_topic_data['id_first_msg']) |
|
| 1336 | - $target_topic_data['id_first_msg'] = $row['id_first_msg']; |
|
| 1391 | + if ($row['id_first_msg'] < $target_topic_data['id_first_msg']) { |
|
| 1392 | + $target_topic_data['id_first_msg'] = $row['id_first_msg']; |
|
| 1393 | + } |
|
| 1337 | 1394 | $target_topic_data['id_last_msg'] = $row['id_last_msg']; |
| 1338 | - if (!$row['approved']) |
|
| 1339 | - $target_topic_data['unapproved_posts'] = $row['message_count']; |
|
| 1340 | - else |
|
| 1341 | - $target_topic_data['num_replies'] = max(0, $row['message_count'] - 1); |
|
| 1395 | + if (!$row['approved']) { |
|
| 1396 | + $target_topic_data['unapproved_posts'] = $row['message_count']; |
|
| 1397 | + } else { |
|
| 1398 | + $target_topic_data['num_replies'] = max(0, $row['message_count'] - 1); |
|
| 1399 | + } |
|
| 1342 | 1400 | } |
| 1343 | 1401 | $smcFunc['db_free_result']($request); |
| 1344 | 1402 | |
@@ -1397,13 +1455,15 @@ discard block |
||
| 1397 | 1455 | ); |
| 1398 | 1456 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1399 | 1457 | { |
| 1400 | - if ($row['id_first_msg'] < $source_topic_data['id_first_msg']) |
|
| 1401 | - $source_topic_data['id_first_msg'] = $row['id_first_msg']; |
|
| 1458 | + if ($row['id_first_msg'] < $source_topic_data['id_first_msg']) { |
|
| 1459 | + $source_topic_data['id_first_msg'] = $row['id_first_msg']; |
|
| 1460 | + } |
|
| 1402 | 1461 | $source_topic_data['id_last_msg'] = $row['id_last_msg']; |
| 1403 | - if (!$row['approved']) |
|
| 1404 | - $source_topic_data['unapproved_posts'] = $row['message_count']; |
|
| 1405 | - else |
|
| 1406 | - $source_topic_data['num_replies'] = max(0, $row['message_count'] - 1); |
|
| 1462 | + if (!$row['approved']) { |
|
| 1463 | + $source_topic_data['unapproved_posts'] = $row['message_count']; |
|
| 1464 | + } else { |
|
| 1465 | + $source_topic_data['num_replies'] = max(0, $row['message_count'] - 1); |
|
| 1466 | + } |
|
| 1407 | 1467 | } |
| 1408 | 1468 | $smcFunc['db_free_result']($request); |
| 1409 | 1469 | |
@@ -1467,10 +1527,12 @@ discard block |
||
| 1467 | 1527 | |
| 1468 | 1528 | // Subject cache? |
| 1469 | 1529 | $cache_updates = array(); |
| 1470 | - if ($target_first_msg != $target_topic_data['id_first_msg']) |
|
| 1471 | - $cache_updates[] = $target_topic_data['id_first_msg']; |
|
| 1472 | - if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg']) |
|
| 1473 | - $cache_updates[] = $source_topic_data['id_first_msg']; |
|
| 1530 | + if ($target_first_msg != $target_topic_data['id_first_msg']) { |
|
| 1531 | + $cache_updates[] = $target_topic_data['id_first_msg']; |
|
| 1532 | + } |
|
| 1533 | + if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg']) { |
|
| 1534 | + $cache_updates[] = $source_topic_data['id_first_msg']; |
|
| 1535 | + } |
|
| 1474 | 1536 | |
| 1475 | 1537 | if (!empty($cache_updates)) |
| 1476 | 1538 | { |
@@ -1482,8 +1544,9 @@ discard block |
||
| 1482 | 1544 | 'first_messages' => $cache_updates, |
| 1483 | 1545 | ) |
| 1484 | 1546 | ); |
| 1485 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1486 | - updateStats('subject', $row['id_topic'], $row['subject']); |
|
| 1547 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1548 | + updateStats('subject', $row['id_topic'], $row['subject']); |
|
| 1549 | + } |
|
| 1487 | 1550 | $smcFunc['db_free_result']($request); |
| 1488 | 1551 | } |
| 1489 | 1552 | |
@@ -1499,22 +1562,26 @@ discard block |
||
| 1499 | 1562 | global $modSettings, $board, $scripturl, $context; |
| 1500 | 1563 | |
| 1501 | 1564 | // No recycle no need to go further |
| 1502 | - if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board'])) |
|
| 1503 | - return false; |
|
| 1565 | + if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board'])) { |
|
| 1566 | + return false; |
|
| 1567 | + } |
|
| 1504 | 1568 | |
| 1505 | 1569 | // If it's confirmed go on and delete (from recycle) |
| 1506 | - if (isset($_GET['confirm_delete'])) |
|
| 1507 | - return true; |
|
| 1570 | + if (isset($_GET['confirm_delete'])) { |
|
| 1571 | + return true; |
|
| 1572 | + } |
|
| 1508 | 1573 | |
| 1509 | - if (empty($board)) |
|
| 1510 | - return false; |
|
| 1574 | + if (empty($board)) { |
|
| 1575 | + return false; |
|
| 1576 | + } |
|
| 1511 | 1577 | |
| 1512 | - if ($modSettings['recycle_board'] != $board) |
|
| 1513 | - return true; |
|
| 1514 | - elseif (isset($_REQUEST['msg'])) |
|
| 1515 | - $confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
|
| 1516 | - else |
|
| 1517 | - $confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']; |
|
| 1578 | + if ($modSettings['recycle_board'] != $board) { |
|
| 1579 | + return true; |
|
| 1580 | + } elseif (isset($_REQUEST['msg'])) { |
|
| 1581 | + $confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
|
| 1582 | + } else { |
|
| 1583 | + $confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']; |
|
| 1584 | + } |
|
| 1518 | 1585 | |
| 1519 | 1586 | fatal_lang_error('post_already_deleted', false, array($confirm_url)); |
| 1520 | 1587 | } |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 4 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('No direct access...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Generates the query to determine the list of available boards for a user |
@@ -25,8 +26,9 @@ discard block |
||
| 25 | 26 | { |
| 26 | 27 | global $smcFunc, $sourcedir; |
| 27 | 28 | |
| 28 | - if (isset($boardListOptions['excluded_boards']) && isset($boardListOptions['included_boards'])) |
|
| 29 | - trigger_error('getBoardList(): Setting both excluded_boards and included_boards is not allowed.', E_USER_ERROR); |
|
| 29 | + if (isset($boardListOptions['excluded_boards']) && isset($boardListOptions['included_boards'])) { |
|
| 30 | + trigger_error('getBoardList(): Setting both excluded_boards and included_boards is not allowed.', E_USER_ERROR); |
|
| 31 | + } |
|
| 30 | 32 | |
| 31 | 33 | $where = array(); |
| 32 | 34 | $where_parameters = array(); |
@@ -42,11 +44,11 @@ discard block |
||
| 42 | 44 | $where_parameters['included_boards'] = $boardListOptions['included_boards']; |
| 43 | 45 | } |
| 44 | 46 | |
| 45 | - if (!empty($boardListOptions['ignore_boards'])) |
|
| 46 | - $where[] = '{query_wanna_see_board}'; |
|
| 47 | - |
|
| 48 | - elseif (!empty($boardListOptions['use_permissions'])) |
|
| 49 | - $where[] = '{query_see_board}'; |
|
| 47 | + if (!empty($boardListOptions['ignore_boards'])) { |
|
| 48 | + $where[] = '{query_wanna_see_board}'; |
|
| 49 | + } elseif (!empty($boardListOptions['use_permissions'])) { |
|
| 50 | + $where[] = '{query_see_board}'; |
|
| 51 | + } |
|
| 50 | 52 | |
| 51 | 53 | if (!empty($boardListOptions['not_redirection'])) |
| 52 | 54 | { |
@@ -68,12 +70,13 @@ discard block |
||
| 68 | 70 | { |
| 69 | 71 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 70 | 72 | { |
| 71 | - if (!isset($return_value[$row['id_cat']])) |
|
| 72 | - $return_value[$row['id_cat']] = array( |
|
| 73 | + if (!isset($return_value[$row['id_cat']])) { |
|
| 74 | + $return_value[$row['id_cat']] = array( |
|
| 73 | 75 | 'id' => $row['id_cat'], |
| 74 | 76 | 'name' => $row['cat_name'], |
| 75 | 77 | 'boards' => array(), |
| 76 | 78 | ); |
| 79 | + } |
|
| 77 | 80 | |
| 78 | 81 | $return_value[$row['id_cat']]['boards'][$row['id_board']] = array( |
| 79 | 82 | 'id' => $row['id_board'], |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 4 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('Hacking attempt...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Interface cache_api_interface |
@@ -183,8 +184,9 @@ discard block |
||
| 183 | 184 | { |
| 184 | 185 | global $cache_enable; |
| 185 | 186 | |
| 186 | - if ($test) |
|
| 187 | - return true; |
|
| 187 | + if ($test) { |
|
| 188 | + return true; |
|
| 189 | + } |
|
| 188 | 190 | return !empty($cache_enable); |
| 189 | 191 | } |
| 190 | 192 | |
@@ -203,10 +205,11 @@ discard block |
||
| 203 | 205 | global $boardurl, $cachedir; |
| 204 | 206 | |
| 205 | 207 | // Set the default if no prefix was specified. |
| 206 | - if (empty($prefix)) |
|
| 207 | - $this->prefix = md5($boardurl . filemtime($cachedir . '/' . 'index.php')) . '-SMF-'; |
|
| 208 | - else |
|
| 209 | - $this->prefix = $prefix; |
|
| 208 | + if (empty($prefix)) { |
|
| 209 | + $this->prefix = md5($boardurl . filemtime($cachedir . '/' . 'index.php')) . '-SMF-'; |
|
| 210 | + } else { |
|
| 211 | + $this->prefix = $prefix; |
|
| 212 | + } |
|
| 210 | 213 | |
| 211 | 214 | return true; |
| 212 | 215 | } |
@@ -269,8 +272,9 @@ discard block |
||
| 269 | 272 | |
| 270 | 273 | // Invalidate cache, to be sure! |
| 271 | 274 | // ... as long as index.php can be modified, anyway. |
| 272 | - if (is_writable($cachedir . '/' . 'index.php')) |
|
| 273 | - @touch($cachedir . '/' . 'index.php'); |
|
| 275 | + if (is_writable($cachedir . '/' . 'index.php')) { |
|
| 276 | + @touch($cachedir . '/' . 'index.php'); |
|
| 277 | + } |
|
| 274 | 278 | |
| 275 | 279 | return true; |
| 276 | 280 | } |