@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Browse the list of package servers, add servers... |
@@ -43,13 +44,15 @@ discard block |
||
| 43 | 44 | ); |
| 44 | 45 | |
| 45 | 46 | // Now let's decide where we are taking this... |
| 46 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
| 47 | - $context['sub_action'] = $_REQUEST['sa']; |
|
| 47 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
| 48 | + $context['sub_action'] = $_REQUEST['sa']; |
|
| 49 | + } |
|
| 48 | 50 | // We need to support possible old javascript links... |
| 49 | - elseif (isset($_GET['pgdownload'])) |
|
| 50 | - $context['sub_action'] = 'download'; |
|
| 51 | - else |
|
| 52 | - $context['sub_action'] = 'servers'; |
|
| 51 | + elseif (isset($_GET['pgdownload'])) { |
|
| 52 | + $context['sub_action'] = 'download'; |
|
| 53 | + } else { |
|
| 54 | + $context['sub_action'] = 'servers'; |
|
| 55 | + } |
|
| 53 | 56 | |
| 54 | 57 | // We need to force the "Download" tab as selected. |
| 55 | 58 | $context['menu_data_' . $context['admin_menu_id']]['current_subsection'] = 'packageget'; |
@@ -141,17 +144,19 @@ discard block |
||
| 141 | 144 | { |
| 142 | 145 | require_once($sourcedir . '/Class-Package.php'); |
| 143 | 146 | $ftp = new ftp_connection(null); |
| 147 | + } elseif ($ftp->error !== false && !isset($ftp_error)) { |
|
| 148 | + $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 144 | 149 | } |
| 145 | - elseif ($ftp->error !== false && !isset($ftp_error)) |
|
| 146 | - $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 147 | 150 | |
| 148 | 151 | list ($username, $detect_path, $found_path) = $ftp->detect_path($packagesdir); |
| 149 | 152 | |
| 150 | - if ($found_path || !isset($_POST['ftp_path'])) |
|
| 151 | - $_POST['ftp_path'] = $detect_path; |
|
| 153 | + if ($found_path || !isset($_POST['ftp_path'])) { |
|
| 154 | + $_POST['ftp_path'] = $detect_path; |
|
| 155 | + } |
|
| 152 | 156 | |
| 153 | - if (!isset($_POST['ftp_username'])) |
|
| 154 | - $_POST['ftp_username'] = $username; |
|
| 157 | + if (!isset($_POST['ftp_username'])) { |
|
| 158 | + $_POST['ftp_username'] = $username; |
|
| 159 | + } |
|
| 155 | 160 | |
| 156 | 161 | $context['package_ftp'] = array( |
| 157 | 162 | 'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'), |
@@ -160,8 +165,7 @@ discard block |
||
| 160 | 165 | 'path' => $_POST['ftp_path'], |
| 161 | 166 | 'error' => empty($ftp_error) ? null : $ftp_error, |
| 162 | 167 | ); |
| 163 | - } |
|
| 164 | - else |
|
| 168 | + } else |
|
| 165 | 169 | { |
| 166 | 170 | $context['package_download_broken'] = false; |
| 167 | 171 | |
@@ -203,8 +207,9 @@ discard block |
||
| 203 | 207 | |
| 204 | 208 | if (isset($_GET['server'])) |
| 205 | 209 | { |
| 206 | - if ($_GET['server'] == '') |
|
| 207 | - redirectexit('action=admin;area=packages;get'); |
|
| 210 | + if ($_GET['server'] == '') { |
|
| 211 | + redirectexit('action=admin;area=packages;get'); |
|
| 212 | + } |
|
| 208 | 213 | |
| 209 | 214 | $server = (int) $_GET['server']; |
| 210 | 215 | |
@@ -222,17 +227,18 @@ discard block |
||
| 222 | 227 | $smcFunc['db_free_result']($request); |
| 223 | 228 | |
| 224 | 229 | // If the server does not exist, dump out. |
| 225 | - if (empty($url)) |
|
| 226 | - fatal_lang_error('couldnt_connect', false); |
|
| 230 | + if (empty($url)) { |
|
| 231 | + fatal_lang_error('couldnt_connect', false); |
|
| 232 | + } |
|
| 227 | 233 | |
| 228 | 234 | // If there is a relative link, append to the stored server url. |
| 229 | - if (isset($_GET['relative'])) |
|
| 230 | - $url = $url . (substr($url, -1) == '/' ? '' : '/') . $_GET['relative']; |
|
| 235 | + if (isset($_GET['relative'])) { |
|
| 236 | + $url = $url . (substr($url, -1) == '/' ? '' : '/') . $_GET['relative']; |
|
| 237 | + } |
|
| 231 | 238 | |
| 232 | 239 | // Clear any "absolute" URL. Since "server" is present, "absolute" is garbage. |
| 233 | 240 | unset($_GET['absolute']); |
| 234 | - } |
|
| 235 | - elseif (isset($_GET['absolute']) && $_GET['absolute'] != '') |
|
| 241 | + } elseif (isset($_GET['absolute']) && $_GET['absolute'] != '') |
|
| 236 | 242 | { |
| 237 | 243 | // Initialize the requried variables. |
| 238 | 244 | $server = ''; |
@@ -256,16 +262,19 @@ discard block |
||
| 256 | 262 | } |
| 257 | 263 | } |
| 258 | 264 | // Minimum required parameter did not exist so dump out. |
| 259 | - else |
|
| 260 | - fatal_lang_error('couldnt_connect', false); |
|
| 265 | + else { |
|
| 266 | + fatal_lang_error('couldnt_connect', false); |
|
| 267 | + } |
|
| 261 | 268 | |
| 262 | 269 | // Attempt to connect. If unsuccessful... try the URL. |
| 263 | - if (!isset($_GET['package']) || file_exists($_GET['package'])) |
|
| 264 | - $_GET['package'] = $url . '/packages.xml?language=' . $context['user']['language']; |
|
| 270 | + if (!isset($_GET['package']) || file_exists($_GET['package'])) { |
|
| 271 | + $_GET['package'] = $url . '/packages.xml?language=' . $context['user']['language']; |
|
| 272 | + } |
|
| 265 | 273 | |
| 266 | 274 | // Check to be sure the packages.xml file actually exists where it is should be... or dump out. |
| 267 | - if ((isset($_GET['absolute']) || isset($_GET['relative'])) && !url_exists($_GET['package'])) |
|
| 268 | - fatal_lang_error('packageget_unable', false, array($url . '/index.php')); |
|
| 275 | + if ((isset($_GET['absolute']) || isset($_GET['relative'])) && !url_exists($_GET['package'])) { |
|
| 276 | + fatal_lang_error('packageget_unable', false, array($url . '/index.php')); |
|
| 277 | + } |
|
| 269 | 278 | |
| 270 | 279 | // Might take some time. |
| 271 | 280 | @set_time_limit(600); |
@@ -275,8 +284,9 @@ discard block |
||
| 275 | 284 | $listing = new xmlArray(fetch_web_data($_GET['package']), true); |
| 276 | 285 | |
| 277 | 286 | // Errm.... empty file? Try the URL.... |
| 278 | - if (!$listing->exists('package-list')) |
|
| 279 | - fatal_lang_error('packageget_unable', false, array($url . '/index.php')); |
|
| 287 | + if (!$listing->exists('package-list')) { |
|
| 288 | + fatal_lang_error('packageget_unable', false, array($url . '/index.php')); |
|
| 289 | + } |
|
| 280 | 290 | |
| 281 | 291 | // List out the packages... |
| 282 | 292 | $context['package_list'] = array(); |
@@ -284,8 +294,9 @@ discard block |
||
| 284 | 294 | $listing = $listing->path('package-list[0]'); |
| 285 | 295 | |
| 286 | 296 | // Use the package list's name if it exists. |
| 287 | - if ($listing->exists('list-title')) |
|
| 288 | - $name = $smcFunc['htmlspecialchars']($listing->fetch('list-title')); |
|
| 297 | + if ($listing->exists('list-title')) { |
|
| 298 | + $name = $smcFunc['htmlspecialchars']($listing->fetch('list-title')); |
|
| 299 | + } |
|
| 289 | 300 | |
| 290 | 301 | // Pick the correct template. |
| 291 | 302 | $context['sub_template'] = 'package_list'; |
@@ -300,28 +311,32 @@ discard block |
||
| 300 | 311 | |
| 301 | 312 | $installed_mods = array(); |
| 302 | 313 | // Look through the list of installed mods... |
| 303 | - foreach ($instmods as $installed_mod) |
|
| 304 | - $installed_mods[$installed_mod['package_id']] = $installed_mod['version']; |
|
| 314 | + foreach ($instmods as $installed_mod) { |
|
| 315 | + $installed_mods[$installed_mod['package_id']] = $installed_mod['version']; |
|
| 316 | + } |
|
| 305 | 317 | |
| 306 | 318 | // Get default author and email if they exist. |
| 307 | 319 | if ($listing->exists('default-author')) |
| 308 | 320 | { |
| 309 | 321 | $default_author = $smcFunc['htmlspecialchars']($listing->fetch('default-author')); |
| 310 | - if ($listing->exists('default-author/@email') && filter_var($listing->fetch('default-author/@email'), FILTER_VALIDATE_EMAIL)) |
|
| 311 | - $default_email = $smcFunc['htmlspecialchars']($listing->fetch('default-author/@email')); |
|
| 322 | + if ($listing->exists('default-author/@email') && filter_var($listing->fetch('default-author/@email'), FILTER_VALIDATE_EMAIL)) { |
|
| 323 | + $default_email = $smcFunc['htmlspecialchars']($listing->fetch('default-author/@email')); |
|
| 324 | + } |
|
| 312 | 325 | } |
| 313 | 326 | |
| 314 | 327 | // Get default web site if it exists. |
| 315 | 328 | if ($listing->exists('default-website')) |
| 316 | 329 | { |
| 317 | 330 | $default_website = $smcFunc['htmlspecialchars']($listing->fetch('default-website')); |
| 318 | - if ($listing->exists('default-website/@title')) |
|
| 319 | - $default_title = $smcFunc['htmlspecialchars']($listing->fetch('default-website/@title')); |
|
| 331 | + if ($listing->exists('default-website/@title')) { |
|
| 332 | + $default_title = $smcFunc['htmlspecialchars']($listing->fetch('default-website/@title')); |
|
| 333 | + } |
|
| 320 | 334 | } |
| 321 | 335 | |
| 322 | 336 | $the_version = strtr($forum_version, array('SMF ' => '')); |
| 323 | - if (!empty($_SESSION['version_emulate'])) |
|
| 324 | - $the_version = $_SESSION['version_emulate']; |
|
| 337 | + if (!empty($_SESSION['version_emulate'])) { |
|
| 338 | + $the_version = $_SESSION['version_emulate']; |
|
| 339 | + } |
|
| 325 | 340 | |
| 326 | 341 | $packageNum = 0; |
| 327 | 342 | $packageSection = 0; |
@@ -342,11 +357,13 @@ discard block |
||
| 342 | 357 | 'type' => $thisPackage->name(), |
| 343 | 358 | ); |
| 344 | 359 | |
| 345 | - if (in_array($package['type'], array('title', 'text'))) |
|
| 346 | - $context['package_list'][$packageSection][$package['type']] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.')); |
|
| 360 | + if (in_array($package['type'], array('title', 'text'))) { |
|
| 361 | + $context['package_list'][$packageSection][$package['type']] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.')); |
|
| 362 | + } |
|
| 347 | 363 | // It's a Title, Heading, Rule or Text. |
| 348 | - elseif (in_array($package['type'], array('heading', 'rule'))) |
|
| 349 | - $package['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.')); |
|
| 364 | + elseif (in_array($package['type'], array('heading', 'rule'))) { |
|
| 365 | + $package['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('.')); |
|
| 366 | + } |
|
| 350 | 367 | // It's a Remote link. |
| 351 | 368 | elseif ($package['type'] == 'remote') |
| 352 | 369 | { |
@@ -354,20 +371,21 @@ discard block |
||
| 354 | 371 | |
| 355 | 372 | if ($remote_type == 'relative' && substr($thisPackage->fetch('@href'), 0, 7) != 'http://' && substr($thisPackage->fetch('@href'), 0, 8) != 'https://') |
| 356 | 373 | { |
| 357 | - if (isset($_GET['absolute'])) |
|
| 358 | - $current_url = $_GET['absolute'] . '/'; |
|
| 359 | - elseif (isset($_GET['relative'])) |
|
| 360 | - $current_url = $_GET['relative'] . '/'; |
|
| 361 | - else |
|
| 362 | - $current_url = ''; |
|
| 374 | + if (isset($_GET['absolute'])) { |
|
| 375 | + $current_url = $_GET['absolute'] . '/'; |
|
| 376 | + } elseif (isset($_GET['relative'])) { |
|
| 377 | + $current_url = $_GET['relative'] . '/'; |
|
| 378 | + } else { |
|
| 379 | + $current_url = ''; |
|
| 380 | + } |
|
| 363 | 381 | |
| 364 | 382 | $current_url .= $thisPackage->fetch('@href'); |
| 365 | - if (isset($_GET['absolute'])) |
|
| 366 | - $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url; |
|
| 367 | - else |
|
| 368 | - $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $context['package_server'] . ';relative=' . $current_url; |
|
| 369 | - } |
|
| 370 | - else |
|
| 383 | + if (isset($_GET['absolute'])) { |
|
| 384 | + $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url; |
|
| 385 | + } else { |
|
| 386 | + $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $context['package_server'] . ';relative=' . $current_url; |
|
| 387 | + } |
|
| 388 | + } else |
|
| 371 | 389 | { |
| 372 | 390 | $current_url = $thisPackage->fetch('@href'); |
| 373 | 391 | $package['href'] = $scripturl . '?action=admin;area=packages;get;sa=browse;absolute=' . $current_url; |
@@ -379,25 +397,28 @@ discard block |
||
| 379 | 397 | // It's a package... |
| 380 | 398 | else |
| 381 | 399 | { |
| 382 | - if (isset($_GET['absolute'])) |
|
| 383 | - $current_url = $_GET['absolute'] . '/'; |
|
| 384 | - elseif (isset($_GET['relative'])) |
|
| 385 | - $current_url = $_GET['relative'] . '/'; |
|
| 386 | - else |
|
| 387 | - $current_url = ''; |
|
| 400 | + if (isset($_GET['absolute'])) { |
|
| 401 | + $current_url = $_GET['absolute'] . '/'; |
|
| 402 | + } elseif (isset($_GET['relative'])) { |
|
| 403 | + $current_url = $_GET['relative'] . '/'; |
|
| 404 | + } else { |
|
| 405 | + $current_url = ''; |
|
| 406 | + } |
|
| 388 | 407 | |
| 389 | 408 | $server_att = $server != '' ? ';server=' . $server : ''; |
| 390 | 409 | |
| 391 | 410 | $package += $thisPackage->to_array(); |
| 392 | 411 | |
| 393 | - if (isset($package['website'])) |
|
| 394 | - unset($package['website']); |
|
| 412 | + if (isset($package['website'])) { |
|
| 413 | + unset($package['website']); |
|
| 414 | + } |
|
| 395 | 415 | $package['author'] = array(); |
| 396 | 416 | |
| 397 | - if ($package['description'] == '') |
|
| 398 | - $package['description'] = $txt['package_no_description']; |
|
| 399 | - else |
|
| 400 | - $package['description'] = parse_bbc(preg_replace('~\[[/]?html\]~i', '', $smcFunc['htmlspecialchars']($package['description']))); |
|
| 417 | + if ($package['description'] == '') { |
|
| 418 | + $package['description'] = $txt['package_no_description']; |
|
| 419 | + } else { |
|
| 420 | + $package['description'] = parse_bbc(preg_replace('~\[[/]?html\]~i', '', $smcFunc['htmlspecialchars']($package['description']))); |
|
| 421 | + } |
|
| 401 | 422 | |
| 402 | 423 | $package['is_installed'] = isset($installed_mods[$package['id']]); |
| 403 | 424 | $package['is_current'] = $package['is_installed'] && ($installed_mods[$package['id']] == $package['version']); |
@@ -406,12 +427,14 @@ discard block |
||
| 406 | 427 | // This package is either not installed, or installed but old. Is it supported on this version of SMF? |
| 407 | 428 | if (!$package['is_installed'] || (!$package['is_current'] && !$package['is_newer'])) |
| 408 | 429 | { |
| 409 | - if ($thisPackage->exists('version/@for')) |
|
| 410 | - $package['can_install'] = matchPackageVersion($the_version, $thisPackage->fetch('version/@for')); |
|
| 430 | + if ($thisPackage->exists('version/@for')) { |
|
| 431 | + $package['can_install'] = matchPackageVersion($the_version, $thisPackage->fetch('version/@for')); |
|
| 432 | + } |
|
| 411 | 433 | } |
| 412 | 434 | // Okay, it's already installed AND up to date. |
| 413 | - else |
|
| 414 | - $package['can_install'] = false; |
|
| 435 | + else { |
|
| 436 | + $package['can_install'] = false; |
|
| 437 | + } |
|
| 415 | 438 | |
| 416 | 439 | $already_exists = getPackageInfo(basename($package['filename'])); |
| 417 | 440 | $package['download_conflict'] = is_array($already_exists) && $already_exists['id'] == $package['id'] && $already_exists['version'] != $package['version']; |
@@ -423,40 +446,44 @@ discard block |
||
| 423 | 446 | |
| 424 | 447 | if ($thisPackage->exists('author') || isset($default_author)) |
| 425 | 448 | { |
| 426 | - if ($thisPackage->exists('author/@email') && filter_var($thisPackage->fetch('author/@email'), FILTER_VALIDATE_EMAIL)) |
|
| 427 | - $package['author']['email'] = $thisPackage->fetch('author/@email'); |
|
| 428 | - elseif (isset($default_email)) |
|
| 429 | - $package['author']['email'] = $default_email; |
|
| 430 | - |
|
| 431 | - if ($thisPackage->exists('author') && $thisPackage->fetch('author') != '') |
|
| 432 | - $package['author']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('author')); |
|
| 433 | - else |
|
| 434 | - $package['author']['name'] = $default_author; |
|
| 435 | - |
|
| 436 | - if (!empty($package['author']['email'])) |
|
| 437 | - $package['author']['link'] = '<a href="mailto:' . $package['author']['email'] . '">' . $package['author']['name'] . '</a>'; |
|
| 449 | + if ($thisPackage->exists('author/@email') && filter_var($thisPackage->fetch('author/@email'), FILTER_VALIDATE_EMAIL)) { |
|
| 450 | + $package['author']['email'] = $thisPackage->fetch('author/@email'); |
|
| 451 | + } elseif (isset($default_email)) { |
|
| 452 | + $package['author']['email'] = $default_email; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + if ($thisPackage->exists('author') && $thisPackage->fetch('author') != '') { |
|
| 456 | + $package['author']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('author')); |
|
| 457 | + } else { |
|
| 458 | + $package['author']['name'] = $default_author; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + if (!empty($package['author']['email'])) { |
|
| 462 | + $package['author']['link'] = '<a href="mailto:' . $package['author']['email'] . '">' . $package['author']['name'] . '</a>'; |
|
| 463 | + } |
|
| 438 | 464 | } |
| 439 | 465 | |
| 440 | 466 | if ($thisPackage->exists('website') || isset($default_website)) |
| 441 | 467 | { |
| 442 | - if ($thisPackage->exists('website') && $thisPackage->exists('website/@title')) |
|
| 443 | - $package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website/@title')); |
|
| 444 | - elseif (isset($default_title)) |
|
| 445 | - $package['author']['website']['name'] = $default_title; |
|
| 446 | - elseif ($thisPackage->exists('website')) |
|
| 447 | - $package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website')); |
|
| 448 | - else |
|
| 449 | - $package['author']['website']['name'] = $default_website; |
|
| 450 | - |
|
| 451 | - if ($thisPackage->exists('website') && $thisPackage->fetch('website') != '') |
|
| 452 | - $authorhompage = $smcFunc['htmlspecialchars']($thisPackage->fetch('website')); |
|
| 453 | - else |
|
| 454 | - $authorhompage = $default_website; |
|
| 468 | + if ($thisPackage->exists('website') && $thisPackage->exists('website/@title')) { |
|
| 469 | + $package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website/@title')); |
|
| 470 | + } elseif (isset($default_title)) { |
|
| 471 | + $package['author']['website']['name'] = $default_title; |
|
| 472 | + } elseif ($thisPackage->exists('website')) { |
|
| 473 | + $package['author']['website']['name'] = $smcFunc['htmlspecialchars']($thisPackage->fetch('website')); |
|
| 474 | + } else { |
|
| 475 | + $package['author']['website']['name'] = $default_website; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + if ($thisPackage->exists('website') && $thisPackage->fetch('website') != '') { |
|
| 479 | + $authorhompage = $smcFunc['htmlspecialchars']($thisPackage->fetch('website')); |
|
| 480 | + } else { |
|
| 481 | + $authorhompage = $default_website; |
|
| 482 | + } |
|
| 455 | 483 | |
| 456 | 484 | $package['author']['website']['href'] = $authorhompage; |
| 457 | 485 | $package['author']['website']['link'] = '<a href="' . $authorhompage . '">' . $package['author']['website']['name'] . '</a>'; |
| 458 | - } |
|
| 459 | - else |
|
| 486 | + } else |
|
| 460 | 487 | { |
| 461 | 488 | $package['author']['website']['href'] = ''; |
| 462 | 489 | $package['author']['website']['link'] = ''; |
@@ -472,11 +499,13 @@ discard block |
||
| 472 | 499 | $packageNum = in_array($package['type'], array('title', 'heading', 'text', 'remote', 'rule')) ? 0 : $packageNum + 1; |
| 473 | 500 | $package['count'] = $packageNum; |
| 474 | 501 | |
| 475 | - if (!in_array($package['type'], array('title', 'text'))) |
|
| 476 | - $context['package_list'][$packageSection]['items'][] = $package; |
|
| 502 | + if (!in_array($package['type'], array('title', 'text'))) { |
|
| 503 | + $context['package_list'][$packageSection]['items'][] = $package; |
|
| 504 | + } |
|
| 477 | 505 | |
| 478 | - if ($package['count'] > 1) |
|
| 479 | - $context['list_type'] = 'ol'; |
|
| 506 | + if ($package['count'] > 1) { |
|
| 507 | + $context['list_type'] = 'ol'; |
|
| 508 | + } |
|
| 480 | 509 | } |
| 481 | 510 | |
| 482 | 511 | $packageSection++; |
@@ -489,8 +518,9 @@ discard block |
||
| 489 | 518 | { |
| 490 | 519 | foreach ($packageSection['items'] as $i => $package) |
| 491 | 520 | { |
| 492 | - if ($package['count'] == 0 || isset($package['can_install'])) |
|
| 493 | - continue; |
|
| 521 | + if ($package['count'] == 0 || isset($package['can_install'])) { |
|
| 522 | + continue; |
|
| 523 | + } |
|
| 494 | 524 | |
| 495 | 525 | $context['package_list'][$ps_id]['items'][$i]['can_install'] = false; |
| 496 | 526 | |
@@ -539,8 +569,9 @@ discard block |
||
| 539 | 569 | checkSession('get'); |
| 540 | 570 | |
| 541 | 571 | // To download something, we need a valid server or url. |
| 542 | - if (empty($_GET['server']) && (!empty($_GET['get']) && !empty($_REQUEST['package']))) |
|
| 543 | - fatal_lang_error('package_get_error_is_zero', false); |
|
| 572 | + if (empty($_GET['server']) && (!empty($_GET['get']) && !empty($_REQUEST['package']))) { |
|
| 573 | + fatal_lang_error('package_get_error_is_zero', false); |
|
| 574 | + } |
|
| 544 | 575 | |
| 545 | 576 | if (isset($_GET['server'])) |
| 546 | 577 | { |
@@ -560,22 +591,23 @@ discard block |
||
| 560 | 591 | $smcFunc['db_free_result']($request); |
| 561 | 592 | |
| 562 | 593 | // If server does not exist then dump out. |
| 563 | - if (empty($url)) |
|
| 564 | - fatal_lang_error('couldnt_connect', false); |
|
| 594 | + if (empty($url)) { |
|
| 595 | + fatal_lang_error('couldnt_connect', false); |
|
| 596 | + } |
|
| 565 | 597 | |
| 566 | 598 | $url = $url . '/'; |
| 567 | - } |
|
| 568 | - else |
|
| 599 | + } else |
|
| 569 | 600 | { |
| 570 | 601 | // Initialize the requried variables. |
| 571 | 602 | $server = ''; |
| 572 | 603 | $url = ''; |
| 573 | 604 | } |
| 574 | 605 | |
| 575 | - if (isset($_REQUEST['byurl']) && !empty($_POST['filename'])) |
|
| 576 | - $package_name = basename($_REQUEST['filename']); |
|
| 577 | - else |
|
| 578 | - $package_name = basename($_REQUEST['package']); |
|
| 606 | + if (isset($_REQUEST['byurl']) && !empty($_POST['filename'])) { |
|
| 607 | + $package_name = basename($_REQUEST['filename']); |
|
| 608 | + } else { |
|
| 609 | + $package_name = basename($_REQUEST['package']); |
|
| 610 | + } |
|
| 579 | 611 | |
| 580 | 612 | if (isset($_REQUEST['conflict']) || (isset($_REQUEST['auto']) && file_exists($packagesdir . '/' . $package_name))) |
| 581 | 613 | { |
@@ -584,14 +616,15 @@ discard block |
||
| 584 | 616 | { |
| 585 | 617 | $ext = substr($package_name, strrpos(substr($package_name, 0, -3), '.')); |
| 586 | 618 | $package_name = substr($package_name, 0, strrpos(substr($package_name, 0, -3), '.')) . '_'; |
| 619 | + } else { |
|
| 620 | + $ext = ''; |
|
| 587 | 621 | } |
| 588 | - else |
|
| 589 | - $ext = ''; |
|
| 590 | 622 | |
| 591 | 623 | // Find the first available. |
| 592 | 624 | $i = 1; |
| 593 | - while (file_exists($packagesdir . '/' . $package_name . $i . $ext)) |
|
| 594 | - $i++; |
|
| 625 | + while (file_exists($packagesdir . '/' . $package_name . $i . $ext)) { |
|
| 626 | + $i++; |
|
| 627 | + } |
|
| 595 | 628 | |
| 596 | 629 | $package_name = $package_name . $i . $ext; |
| 597 | 630 | } |
@@ -601,25 +634,28 @@ discard block |
||
| 601 | 634 | package_put_contents($packagesdir . '/' . $package_name, fetch_web_data($url . $_REQUEST['package'])); |
| 602 | 635 | |
| 603 | 636 | // Done! Did we get this package automatically? |
| 604 | - if (preg_match('~^http://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['package']) == 1 && strpos($_REQUEST['package'], 'dlattach') === false && isset($_REQUEST['auto'])) |
|
| 605 | - redirectexit('action=admin;area=packages;sa=install;package=' . $package_name); |
|
| 637 | + if (preg_match('~^http://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['package']) == 1 && strpos($_REQUEST['package'], 'dlattach') === false && isset($_REQUEST['auto'])) { |
|
| 638 | + redirectexit('action=admin;area=packages;sa=install;package=' . $package_name); |
|
| 639 | + } |
|
| 606 | 640 | |
| 607 | 641 | // You just downloaded a mod from SERVER_NAME_GOES_HERE. |
| 608 | 642 | $context['package_server'] = $server; |
| 609 | 643 | |
| 610 | 644 | $context['package'] = getPackageInfo($package_name); |
| 611 | 645 | |
| 612 | - if (!is_array($context['package'])) |
|
| 613 | - fatal_lang_error('package_cant_download', false); |
|
| 646 | + if (!is_array($context['package'])) { |
|
| 647 | + fatal_lang_error('package_cant_download', false); |
|
| 648 | + } |
|
| 614 | 649 | |
| 615 | - if ($context['package']['type'] == 'modification') |
|
| 616 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>'; |
|
| 617 | - elseif ($context['package']['type'] == 'avatar') |
|
| 618 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>'; |
|
| 619 | - elseif ($context['package']['type'] == 'language') |
|
| 620 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>'; |
|
| 621 | - else |
|
| 622 | - $context['package']['install']['link'] = ''; |
|
| 650 | + if ($context['package']['type'] == 'modification') { |
|
| 651 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>'; |
|
| 652 | + } elseif ($context['package']['type'] == 'avatar') { |
|
| 653 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>'; |
|
| 654 | + } elseif ($context['package']['type'] == 'language') { |
|
| 655 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>'; |
|
| 656 | + } else { |
|
| 657 | + $context['package']['install']['link'] = ''; |
|
| 658 | + } |
|
| 623 | 659 | |
| 624 | 660 | // Does a 3rd party hook want to do some additional changes? |
| 625 | 661 | call_integration_hook('integrate_package_download'); |
@@ -645,16 +681,18 @@ discard block |
||
| 645 | 681 | // @todo Use FTP if the Packages directory is not writable. |
| 646 | 682 | |
| 647 | 683 | // Check the file was even sent! |
| 648 | - if (!isset($_FILES['package']['name']) || $_FILES['package']['name'] == '') |
|
| 649 | - fatal_lang_error('package_upload_error_nofile'); |
|
| 650 | - elseif (!is_uploaded_file($_FILES['package']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['package']['tmp_name']))) |
|
| 651 | - fatal_lang_error('package_upload_error_failed'); |
|
| 684 | + if (!isset($_FILES['package']['name']) || $_FILES['package']['name'] == '') { |
|
| 685 | + fatal_lang_error('package_upload_error_nofile'); |
|
| 686 | + } elseif (!is_uploaded_file($_FILES['package']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['package']['tmp_name']))) { |
|
| 687 | + fatal_lang_error('package_upload_error_failed'); |
|
| 688 | + } |
|
| 652 | 689 | |
| 653 | 690 | // Make sure it has a sane filename. |
| 654 | 691 | $_FILES['package']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['package']['name']); |
| 655 | 692 | |
| 656 | - if (strtolower(substr($_FILES['package']['name'], -4)) != '.zip' && strtolower(substr($_FILES['package']['name'], -4)) != '.tgz' && strtolower(substr($_FILES['package']['name'], -7)) != '.tar.gz') |
|
| 657 | - fatal_lang_error('package_upload_error_supports', false, array('zip, tgz, tar.gz')); |
|
| 693 | + if (strtolower(substr($_FILES['package']['name'], -4)) != '.zip' && strtolower(substr($_FILES['package']['name'], -4)) != '.tgz' && strtolower(substr($_FILES['package']['name'], -7)) != '.tar.gz') { |
|
| 694 | + fatal_lang_error('package_upload_error_supports', false, array('zip, tgz, tar.gz')); |
|
| 695 | + } |
|
| 658 | 696 | |
| 659 | 697 | // We only need the filename... |
| 660 | 698 | $packageName = basename($_FILES['package']['name']); |
@@ -662,8 +700,9 @@ discard block |
||
| 662 | 700 | // Setup the destination and throw an error if the file is already there! |
| 663 | 701 | $destination = $packagesdir . '/' . $packageName; |
| 664 | 702 | // @todo Maybe just roll it like we do for downloads? |
| 665 | - if (file_exists($destination)) |
|
| 666 | - fatal_lang_error('package_upload_error_exists'); |
|
| 703 | + if (file_exists($destination)) { |
|
| 704 | + fatal_lang_error('package_upload_error_exists'); |
|
| 705 | + } |
|
| 667 | 706 | |
| 668 | 707 | // Now move the file. |
| 669 | 708 | move_uploaded_file($_FILES['package']['tmp_name'], $destination); |
@@ -686,12 +725,14 @@ discard block |
||
| 686 | 725 | { |
| 687 | 726 | while ($package = readdir($dir)) |
| 688 | 727 | { |
| 689 | - if ($package == '.' || $package == '..' || $package == 'temp' || $package == $packageName || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) |
|
| 690 | - continue; |
|
| 728 | + if ($package == '.' || $package == '..' || $package == 'temp' || $package == $packageName || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) { |
|
| 729 | + continue; |
|
| 730 | + } |
|
| 691 | 731 | |
| 692 | 732 | $packageInfo = getPackageInfo($package); |
| 693 | - if (!is_array($packageInfo)) |
|
| 694 | - continue; |
|
| 733 | + if (!is_array($packageInfo)) { |
|
| 734 | + continue; |
|
| 735 | + } |
|
| 695 | 736 | |
| 696 | 737 | if ($packageInfo['id'] == $context['package']['id'] && $packageInfo['version'] == $context['package']['version']) |
| 697 | 738 | { |
@@ -703,14 +744,15 @@ discard block |
||
| 703 | 744 | closedir($dir); |
| 704 | 745 | } |
| 705 | 746 | |
| 706 | - if ($context['package']['type'] == 'modification') |
|
| 707 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>'; |
|
| 708 | - elseif ($context['package']['type'] == 'avatar') |
|
| 709 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>'; |
|
| 710 | - elseif ($context['package']['type'] == 'language') |
|
| 711 | - $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>'; |
|
| 712 | - else |
|
| 713 | - $context['package']['install']['link'] = ''; |
|
| 747 | + if ($context['package']['type'] == 'modification') { |
|
| 748 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['install_mod'] . ' ]</a>'; |
|
| 749 | + } elseif ($context['package']['type'] == 'avatar') { |
|
| 750 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['use_avatars'] . ' ]</a>'; |
|
| 751 | + } elseif ($context['package']['type'] == 'language') { |
|
| 752 | + $context['package']['install']['link'] = '<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $context['package']['filename'] . '">[ ' . $txt['add_languages'] . ' ]</a>'; |
|
| 753 | + } else { |
|
| 754 | + $context['package']['install']['link'] = ''; |
|
| 755 | + } |
|
| 714 | 756 | |
| 715 | 757 | // Does a 3rd party hook want to do some additional changes? |
| 716 | 758 | call_integration_hook('integrate_package_upload'); |
@@ -733,16 +775,18 @@ discard block |
||
| 733 | 775 | checkSession(); |
| 734 | 776 | |
| 735 | 777 | // If they put a slash on the end, get rid of it. |
| 736 | - if (substr($_POST['serverurl'], -1) == '/') |
|
| 737 | - $_POST['serverurl'] = substr($_POST['serverurl'], 0, -1); |
|
| 778 | + if (substr($_POST['serverurl'], -1) == '/') { |
|
| 779 | + $_POST['serverurl'] = substr($_POST['serverurl'], 0, -1); |
|
| 780 | + } |
|
| 738 | 781 | |
| 739 | 782 | // Are they both nice and clean? |
| 740 | 783 | $servername = trim($smcFunc['htmlspecialchars']($_POST['servername'])); |
| 741 | 784 | $serverurl = trim($smcFunc['htmlspecialchars']($_POST['serverurl'])); |
| 742 | 785 | |
| 743 | 786 | // Make sure the URL has the correct prefix. |
| 744 | - if (strpos($serverurl, 'http://') !== 0 && strpos($serverurl, 'https://') !== 0) |
|
| 745 | - $serverurl = 'http://' . $serverurl; |
|
| 787 | + if (strpos($serverurl, 'http://') !== 0 && strpos($serverurl, 'https://') !== 0) { |
|
| 788 | + $serverurl = 'http://' . $serverurl; |
|
| 789 | + } |
|
| 746 | 790 | |
| 747 | 791 | $smcFunc['db_insert']('', |
| 748 | 792 | '{db_prefix}package_servers', |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 3 |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -if (!defined('SMF')) |
|
| 18 | +if (!defined('SMF')) { |
|
| 19 | 19 | die('No direct access...'); |
| 20 | +} |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * Takes a message and parses it, returning nothing. |
@@ -52,17 +53,19 @@ discard block |
||
| 52 | 53 | $message = preg_replace('~\.{100,}~', '...', $message); |
| 53 | 54 | |
| 54 | 55 | // Trim off trailing quotes - these often happen by accident. |
| 55 | - while (substr($message, -7) == '[quote]') |
|
| 56 | - $message = substr($message, 0, -7); |
|
| 57 | - while (substr($message, 0, 8) == '[/quote]') |
|
| 58 | - $message = substr($message, 8); |
|
| 56 | + while (substr($message, -7) == '[quote]') { |
|
| 57 | + $message = substr($message, 0, -7); |
|
| 58 | + } |
|
| 59 | + while (substr($message, 0, 8) == '[/quote]') { |
|
| 60 | + $message = substr($message, 8); |
|
| 61 | + } |
|
| 59 | 62 | |
| 60 | 63 | // Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed. |
| 61 | 64 | $in_tag = false; |
| 62 | 65 | $had_tag = false; |
| 63 | 66 | $codeopen = 0; |
| 64 | - if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) |
|
| 65 | - foreach ($matches[0] as $index => $dummy) |
|
| 67 | + if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) { |
|
| 68 | + foreach ($matches[0] as $index => $dummy) |
|
| 66 | 69 | { |
| 67 | 70 | // Closing? |
| 68 | 71 | if (!empty($matches[2][$index])) |
@@ -70,6 +73,7 @@ discard block |
||
| 70 | 73 | // If it's closing and we're not in a tag we need to open it... |
| 71 | 74 | if (!$in_tag) |
| 72 | 75 | $codeopen = true; |
| 76 | + } |
|
| 73 | 77 | // Either way we ain't in one any more. |
| 74 | 78 | $in_tag = false; |
| 75 | 79 | } |
@@ -78,17 +82,20 @@ discard block |
||
| 78 | 82 | { |
| 79 | 83 | $had_tag = true; |
| 80 | 84 | // If we're in a tag don't do nought! |
| 81 | - if (!$in_tag) |
|
| 82 | - $in_tag = true; |
|
| 85 | + if (!$in_tag) { |
|
| 86 | + $in_tag = true; |
|
| 87 | + } |
|
| 83 | 88 | } |
| 84 | 89 | } |
| 85 | 90 | |
| 86 | 91 | // If we have an open tag, close it. |
| 87 | - if ($in_tag) |
|
| 88 | - $message .= '[/code]'; |
|
| 92 | + if ($in_tag) { |
|
| 93 | + $message .= '[/code]'; |
|
| 94 | + } |
|
| 89 | 95 | // Open any ones that need to be open, only if we've never had a tag. |
| 90 | - if ($codeopen && !$had_tag) |
|
| 91 | - $message = '[code]' . $message; |
|
| 96 | + if ($codeopen && !$had_tag) { |
|
| 97 | + $message = '[code]' . $message; |
|
| 98 | + } |
|
| 92 | 99 | |
| 93 | 100 | // Now that we've fixed all the code tags, let's fix the img and url tags... |
| 94 | 101 | $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE); |
@@ -114,23 +121,26 @@ discard block |
||
| 114 | 121 | fixTags($message); |
| 115 | 122 | |
| 116 | 123 | // Replace /me.+?\n with [me=name]dsf[/me]\n. |
| 117 | - if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) |
|
| 118 | - $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message); |
|
| 119 | - else |
|
| 120 | - $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message); |
|
| 124 | + if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) { |
|
| 125 | + $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message); |
|
| 126 | + } else { |
|
| 127 | + $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message); |
|
| 128 | + } |
|
| 121 | 129 | |
| 122 | 130 | if (!$previewing && strpos($message, '[html]') !== false) |
| 123 | 131 | { |
| 124 | - if (allowedTo('admin_forum')) |
|
| 125 | - $message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function ($m) { |
|
| 132 | + if (allowedTo('admin_forum')) { |
|
| 133 | + $message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function ($m) { |
|
| 126 | 134 | return '[html]' . strtr(un_htmlspecialchars($m), array("\n" => ' ', ' ' => '  ', '[' => '[', ']' => ']')) . '[/html]'; |
| 135 | + } |
|
| 127 | 136 | }, $message); |
| 128 | 137 | |
| 129 | 138 | // We should edit them out, or else if an admin edits the message they will get shown... |
| 130 | 139 | else |
| 131 | 140 | { |
| 132 | - while (strpos($message, '[html]') !== false) |
|
| 133 | - $message = preg_replace('~\[[/]?html\]~i', '', $message); |
|
| 141 | + while (strpos($message, '[html]') !== false) { |
|
| 142 | + $message = preg_replace('~\[[/]?html\]~i', '', $message); |
|
| 143 | + } |
|
| 134 | 144 | } |
| 135 | 145 | } |
| 136 | 146 | |
@@ -152,10 +162,12 @@ discard block |
||
| 152 | 162 | |
| 153 | 163 | $list_open = substr_count($message, '[list]') + substr_count($message, '[list '); |
| 154 | 164 | $list_close = substr_count($message, '[/list]'); |
| 155 | - if ($list_close - $list_open > 0) |
|
| 156 | - $message = str_repeat('[list]', $list_close - $list_open) . $message; |
|
| 157 | - if ($list_open - $list_close > 0) |
|
| 158 | - $message = $message . str_repeat('[/list]', $list_open - $list_close); |
|
| 165 | + if ($list_close - $list_open > 0) { |
|
| 166 | + $message = str_repeat('[list]', $list_close - $list_open) . $message; |
|
| 167 | + } |
|
| 168 | + if ($list_open - $list_close > 0) { |
|
| 169 | + $message = $message . str_repeat('[/list]', $list_open - $list_close); |
|
| 170 | + } |
|
| 159 | 171 | |
| 160 | 172 | $mistake_fixes = array( |
| 161 | 173 | // Find [table]s not followed by [tr]. |
@@ -204,8 +216,9 @@ discard block |
||
| 204 | 216 | ); |
| 205 | 217 | |
| 206 | 218 | // Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.) |
| 207 | - for ($j = 0; $j < 3; $j++) |
|
| 208 | - $message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message); |
|
| 219 | + for ($j = 0; $j < 3; $j++) { |
|
| 220 | + $message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message); |
|
| 221 | + } |
|
| 209 | 222 | |
| 210 | 223 | // Remove empty bbc from the sections outside the code tags |
| 211 | 224 | $message = preg_replace('~\[[bisu]\]\s*\[/[bisu]\]~', '', $message); |
@@ -213,14 +226,16 @@ discard block |
||
| 213 | 226 | $message = preg_replace('~\[color=(?:#[\da-fA-F]{3}|#[\da-fA-F]{6}|[A-Za-z]{1,20}|rgb\(\d{1,3}, ?\d{1,3}, ?\d{1,3}\))\]\s*\[/color\]~', '', $message); |
| 214 | 227 | |
| 215 | 228 | // Restore code blocks |
| 216 | - if (!empty($code_tags)) |
|
| 217 | - $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
| 229 | + if (!empty($code_tags)) { |
|
| 230 | + $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
| 231 | + } |
|
| 218 | 232 | |
| 219 | 233 | // Restore white space entities |
| 220 | - if (!$previewing) |
|
| 221 | - $message = strtr($message, array(' ' => ' ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
| 222 | - else |
|
| 223 | - $message = strtr($message, array(' ' => ' ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
| 234 | + if (!$previewing) { |
|
| 235 | + $message = strtr($message, array(' ' => ' ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
| 236 | + } else { |
|
| 237 | + $message = strtr($message, array(' ' => ' ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
| 238 | + } |
|
| 224 | 239 | |
| 225 | 240 | // Now let's quickly clean up things that will slow our parser (which are common in posted code.) |
| 226 | 241 | $message = strtr($message, array('[]' => '[]', '['' => '['')); |
@@ -263,8 +278,9 @@ discard block |
||
| 263 | 278 | return "[time]" . timeformat("$m[1]", false) . "[/time]"; |
| 264 | 279 | }, $message); |
| 265 | 280 | |
| 266 | - if (!empty($code_tags)) |
|
| 267 | - $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
| 281 | + if (!empty($code_tags)) { |
|
| 282 | + $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
| 283 | + } |
|
| 268 | 284 | |
| 269 | 285 | // Change breaks back to \n's and &nsbp; back to spaces. |
| 270 | 286 | return preg_replace('~<br( /)?' . '>~', "\n", str_replace(' ', ' ', $message)); |
@@ -345,8 +361,9 @@ discard block |
||
| 345 | 361 | ); |
| 346 | 362 | |
| 347 | 363 | // Fix each type of tag. |
| 348 | - foreach ($fixArray as $param) |
|
| 349 | - fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra'])); |
|
| 364 | + foreach ($fixArray as $param) { |
|
| 365 | + fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra'])); |
|
| 366 | + } |
|
| 350 | 367 | |
| 351 | 368 | // Now fix possible security problems with images loading links automatically... |
| 352 | 369 | $message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function ($m) |
@@ -382,16 +399,19 @@ discard block |
||
| 382 | 399 | $desired_height = $height; |
| 383 | 400 | } |
| 384 | 401 | // Scale it to the width... |
| 385 | - elseif (empty($desired_width) && !empty($height)) |
|
| 386 | - $desired_width = (int) (($desired_height * $width) / $height); |
|
| 402 | + elseif (empty($desired_width) && !empty($height)) { |
|
| 403 | + $desired_width = (int) (($desired_height * $width) / $height); |
|
| 404 | + } |
|
| 387 | 405 | // Scale if to the height. |
| 388 | - elseif (!empty($width)) |
|
| 389 | - $desired_height = (int) (($desired_width * $height) / $width); |
|
| 406 | + elseif (!empty($width)) { |
|
| 407 | + $desired_height = (int) (($desired_width * $height) / $width); |
|
| 408 | + } |
|
| 390 | 409 | } |
| 391 | 410 | |
| 392 | 411 | // If the width and height are fine, just continue along... |
| 393 | - if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) |
|
| 394 | - continue; |
|
| 412 | + if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) { |
|
| 413 | + continue; |
|
| 414 | + } |
|
| 395 | 415 | |
| 396 | 416 | // Too bad, it's too wide. Make it as wide as the maximum. |
| 397 | 417 | if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width'])) |
@@ -411,8 +431,9 @@ discard block |
||
| 411 | 431 | } |
| 412 | 432 | |
| 413 | 433 | // If any img tags were actually changed... |
| 414 | - if (!empty($replaces)) |
|
| 415 | - $message = strtr($message, $replaces); |
|
| 434 | + if (!empty($replaces)) { |
|
| 435 | + $message = strtr($message, $replaces); |
|
| 436 | + } |
|
| 416 | 437 | } |
| 417 | 438 | } |
| 418 | 439 | |
@@ -431,10 +452,11 @@ discard block |
||
| 431 | 452 | { |
| 432 | 453 | global $boardurl, $scripturl; |
| 433 | 454 | |
| 434 | - if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) |
|
| 435 | - $domain_url = $match[1]; |
|
| 436 | - else |
|
| 437 | - $domain_url = $boardurl . '/'; |
|
| 455 | + if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) { |
|
| 456 | + $domain_url = $match[1]; |
|
| 457 | + } else { |
|
| 458 | + $domain_url = $boardurl . '/'; |
|
| 459 | + } |
|
| 438 | 460 | |
| 439 | 461 | $replaces = array(); |
| 440 | 462 | |
@@ -442,11 +464,11 @@ discard block |
||
| 442 | 464 | { |
| 443 | 465 | $quoted = preg_match('~\[(' . $myTag . ')="~', $message); |
| 444 | 466 | preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '"(.*?)"' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
| 467 | + } elseif ($hasEqualSign) { |
|
| 468 | + preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
|
| 469 | + } else { |
|
| 470 | + preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches); |
|
| 445 | 471 | } |
| 446 | - elseif ($hasEqualSign) |
|
| 447 | - preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
|
| 448 | - else |
|
| 449 | - preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches); |
|
| 450 | 472 | |
| 451 | 473 | foreach ($matches[0] as $k => $dummy) |
| 452 | 474 | { |
@@ -459,49 +481,53 @@ discard block |
||
| 459 | 481 | foreach ($protocols as $protocol) |
| 460 | 482 | { |
| 461 | 483 | $found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0; |
| 462 | - if ($found) |
|
| 463 | - break; |
|
| 484 | + if ($found) { |
|
| 485 | + break; |
|
| 486 | + } |
|
| 464 | 487 | } |
| 465 | 488 | |
| 466 | 489 | if (!$found && $protocols[0] == 'http') |
| 467 | 490 | { |
| 468 | - if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') |
|
| 469 | - $replace = $domain_url . $replace; |
|
| 470 | - elseif (substr($replace, 0, 1) == '?') |
|
| 471 | - $replace = $scripturl . $replace; |
|
| 472 | - elseif (substr($replace, 0, 1) == '#' && $embeddedUrl) |
|
| 491 | + if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') { |
|
| 492 | + $replace = $domain_url . $replace; |
|
| 493 | + } elseif (substr($replace, 0, 1) == '?') { |
|
| 494 | + $replace = $scripturl . $replace; |
|
| 495 | + } elseif (substr($replace, 0, 1) == '#' && $embeddedUrl) |
|
| 473 | 496 | { |
| 474 | 497 | $replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1)); |
| 475 | 498 | $this_tag = 'iurl'; |
| 476 | 499 | $this_close = 'iurl'; |
| 500 | + } elseif (substr($replace, 0, 2) != '//') { |
|
| 501 | + $replace = $protocols[0] . '://' . $replace; |
|
| 477 | 502 | } |
| 478 | - elseif (substr($replace, 0, 2) != '//') |
|
| 479 | - $replace = $protocols[0] . '://' . $replace; |
|
| 480 | - } |
|
| 481 | - elseif (!$found && $protocols[0] == 'ftp') |
|
| 482 | - $replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace); |
|
| 483 | - elseif (!$found) |
|
| 484 | - $replace = $protocols[0] . '://' . $replace; |
|
| 485 | - |
|
| 486 | - if ($hasEqualSign && $embeddedUrl) |
|
| 487 | - $replaces[$matches[0][$k]] = '[' . $this_tag . '="' . $replace . '"]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']'); |
|
| 488 | - elseif ($hasEqualSign) |
|
| 489 | - $replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']'; |
|
| 490 | - elseif ($embeddedUrl) |
|
| 491 | - $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']'; |
|
| 492 | - else |
|
| 493 | - $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']'; |
|
| 503 | + } elseif (!$found && $protocols[0] == 'ftp') { |
|
| 504 | + $replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace); |
|
| 505 | + } elseif (!$found) { |
|
| 506 | + $replace = $protocols[0] . '://' . $replace; |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + if ($hasEqualSign && $embeddedUrl) { |
|
| 510 | + $replaces[$matches[0][$k]] = '[' . $this_tag . '="' . $replace . '"]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']'); |
|
| 511 | + } elseif ($hasEqualSign) { |
|
| 512 | + $replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']'; |
|
| 513 | + } elseif ($embeddedUrl) { |
|
| 514 | + $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']'; |
|
| 515 | + } else { |
|
| 516 | + $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']'; |
|
| 517 | + } |
|
| 494 | 518 | } |
| 495 | 519 | |
| 496 | 520 | foreach ($replaces as $k => $v) |
| 497 | 521 | { |
| 498 | - if ($k == $v) |
|
| 499 | - unset($replaces[$k]); |
|
| 522 | + if ($k == $v) { |
|
| 523 | + unset($replaces[$k]); |
|
| 524 | + } |
|
| 500 | 525 | } |
| 501 | 526 | |
| 502 | - if (!empty($replaces)) |
|
| 503 | - $message = strtr($message, $replaces); |
|
| 504 | -} |
|
| 527 | + if (!empty($replaces)) { |
|
| 528 | + $message = strtr($message, $replaces); |
|
| 529 | + } |
|
| 530 | + } |
|
| 505 | 531 | |
| 506 | 532 | /** |
| 507 | 533 | * This function sends an email to the specified recipient(s). |
@@ -545,8 +571,9 @@ discard block |
||
| 545 | 571 | } |
| 546 | 572 | |
| 547 | 573 | // Nothing left? Nothing else to do |
| 548 | - if (empty($to_array)) |
|
| 549 | - return true; |
|
| 574 | + if (empty($to_array)) { |
|
| 575 | + return true; |
|
| 576 | + } |
|
| 550 | 577 | |
| 551 | 578 | // Once upon a time, Hotmail could not interpret non-ASCII mails. |
| 552 | 579 | // In honour of those days, it's still called the 'hotmail fix'. |
@@ -563,15 +590,17 @@ discard block |
||
| 563 | 590 | } |
| 564 | 591 | |
| 565 | 592 | // Call this function recursively for the hotmail addresses. |
| 566 | - if (!empty($hotmail_to)) |
|
| 567 | - $mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private); |
|
| 593 | + if (!empty($hotmail_to)) { |
|
| 594 | + $mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private); |
|
| 595 | + } |
|
| 568 | 596 | |
| 569 | 597 | // The remaining addresses no longer need the fix. |
| 570 | 598 | $hotmail_fix = false; |
| 571 | 599 | |
| 572 | 600 | // No other addresses left? Return instantly. |
| 573 | - if (empty($to_array)) |
|
| 574 | - return $mail_result; |
|
| 601 | + if (empty($to_array)) { |
|
| 602 | + return $mail_result; |
|
| 603 | + } |
|
| 575 | 604 | } |
| 576 | 605 | |
| 577 | 606 | // Get rid of entities. |
@@ -596,13 +625,15 @@ discard block |
||
| 596 | 625 | $headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break; |
| 597 | 626 | $headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break; |
| 598 | 627 | |
| 599 | - if ($message_id !== null && empty($modSettings['mail_no_message_id'])) |
|
| 600 | - $headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break; |
|
| 628 | + if ($message_id !== null && empty($modSettings['mail_no_message_id'])) { |
|
| 629 | + $headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break; |
|
| 630 | + } |
|
| 601 | 631 | $headers .= 'X-Mailer: SMF' . $line_break; |
| 602 | 632 | |
| 603 | 633 | // Pass this to the integration before we start modifying the output -- it'll make it easier later. |
| 604 | - if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers)), true)) |
|
| 605 | - return false; |
|
| 634 | + if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers)), true)) { |
|
| 635 | + return false; |
|
| 636 | + } |
|
| 606 | 637 | |
| 607 | 638 | // Save the original message... |
| 608 | 639 | $orig_message = $message; |
@@ -651,17 +682,19 @@ discard block |
||
| 651 | 682 | } |
| 652 | 683 | |
| 653 | 684 | // Are we using the mail queue, if so this is where we butt in... |
| 654 | - if ($priority != 0) |
|
| 655 | - return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private); |
|
| 685 | + if ($priority != 0) { |
|
| 686 | + return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private); |
|
| 687 | + } |
|
| 656 | 688 | |
| 657 | 689 | // If it's a priority mail, send it now - note though that this should NOT be used for sending many at once. |
| 658 | 690 | elseif (!empty($modSettings['mail_limit'])) |
| 659 | 691 | { |
| 660 | 692 | list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']); |
| 661 | - if (empty($mails_this_minute) || time() > $last_mail_time + 60) |
|
| 662 | - $new_queue_stat = time() . '|' . 1; |
|
| 663 | - else |
|
| 664 | - $new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1); |
|
| 693 | + if (empty($mails_this_minute) || time() > $last_mail_time + 60) { |
|
| 694 | + $new_queue_stat = time() . '|' . 1; |
|
| 695 | + } else { |
|
| 696 | + $new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1); |
|
| 697 | + } |
|
| 665 | 698 | |
| 666 | 699 | updateSettings(array('mail_recent' => $new_queue_stat)); |
| 667 | 700 | } |
@@ -686,12 +719,13 @@ discard block |
||
| 686 | 719 | |
| 687 | 720 | // Wait, wait, I'm still sending here! |
| 688 | 721 | @set_time_limit(300); |
| 689 | - if (function_exists('apache_reset_timeout')) |
|
| 690 | - @apache_reset_timeout(); |
|
| 722 | + if (function_exists('apache_reset_timeout')) { |
|
| 723 | + @apache_reset_timeout(); |
|
| 724 | + } |
|
| 691 | 725 | } |
| 726 | + } else { |
|
| 727 | + $mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers); |
|
| 692 | 728 | } |
| 693 | - else |
|
| 694 | - $mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers); |
|
| 695 | 729 | |
| 696 | 730 | // Everything go smoothly? |
| 697 | 731 | return $mail_result; |
@@ -717,8 +751,9 @@ discard block |
||
| 717 | 751 | static $cur_insert = array(); |
| 718 | 752 | static $cur_insert_len = 0; |
| 719 | 753 | |
| 720 | - if ($cur_insert_len == 0) |
|
| 721 | - $cur_insert = array(); |
|
| 754 | + if ($cur_insert_len == 0) { |
|
| 755 | + $cur_insert = array(); |
|
| 756 | + } |
|
| 722 | 757 | |
| 723 | 758 | // If we're flushing, make the final inserts - also if we're near the MySQL length limit! |
| 724 | 759 | if (($flush || $cur_insert_len > 800000) && !empty($cur_insert)) |
@@ -793,8 +828,9 @@ discard block |
||
| 793 | 828 | } |
| 794 | 829 | |
| 795 | 830 | // If they are using SSI there is a good chance obExit will never be called. So lets be nice and flush it for them. |
| 796 | - if (SMF === 'SSI' || SMF === 'BACKGROUND') |
|
| 797 | - return AddMailQueue(true); |
|
| 831 | + if (SMF === 'SSI' || SMF === 'BACKGROUND') { |
|
| 832 | + return AddMailQueue(true); |
|
| 833 | + } |
|
| 798 | 834 | |
| 799 | 835 | return true; |
| 800 | 836 | } |
@@ -827,23 +863,26 @@ discard block |
||
| 827 | 863 | 'sent' => array() |
| 828 | 864 | ); |
| 829 | 865 | |
| 830 | - if ($from === null) |
|
| 831 | - $from = array( |
|
| 866 | + if ($from === null) { |
|
| 867 | + $from = array( |
|
| 832 | 868 | 'id' => $user_info['id'], |
| 833 | 869 | 'name' => $user_info['name'], |
| 834 | 870 | 'username' => $user_info['username'] |
| 835 | 871 | ); |
| 872 | + } |
|
| 836 | 873 | |
| 837 | 874 | // This is the one that will go in their inbox. |
| 838 | 875 | $htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES); |
| 839 | 876 | preparsecode($htmlmessage); |
| 840 | 877 | $htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => '')); |
| 841 | - if ($smcFunc['strlen']($htmlsubject) > 100) |
|
| 842 | - $htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100); |
|
| 878 | + if ($smcFunc['strlen']($htmlsubject) > 100) { |
|
| 879 | + $htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100); |
|
| 880 | + } |
|
| 843 | 881 | |
| 844 | 882 | // Make sure is an array |
| 845 | - if (!is_array($recipients)) |
|
| 846 | - $recipients = array($recipients); |
|
| 883 | + if (!is_array($recipients)) { |
|
| 884 | + $recipients = array($recipients); |
|
| 885 | + } |
|
| 847 | 886 | |
| 848 | 887 | // Integrated PMs |
| 849 | 888 | call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message)); |
@@ -871,21 +910,23 @@ discard block |
||
| 871 | 910 | 'usernames' => array_keys($usernames), |
| 872 | 911 | ) |
| 873 | 912 | ); |
| 874 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 875 | - if (isset($usernames[$smcFunc['strtolower']($row['member_name'])])) |
|
| 913 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 914 | + if (isset($usernames[$smcFunc['strtolower']($row['member_name'])])) |
|
| 876 | 915 | $usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member']; |
| 916 | + } |
|
| 877 | 917 | $smcFunc['db_free_result']($request); |
| 878 | 918 | |
| 879 | 919 | // Replace the usernames with IDs. Drop usernames that couldn't be found. |
| 880 | - foreach ($recipients as $rec_type => $rec) |
|
| 881 | - foreach ($rec as $id => $member) |
|
| 920 | + foreach ($recipients as $rec_type => $rec) { |
|
| 921 | + foreach ($rec as $id => $member) |
|
| 882 | 922 | { |
| 883 | 923 | if (is_numeric($recipients[$rec_type][$id])) |
| 884 | 924 | continue; |
| 925 | + } |
|
| 885 | 926 | |
| 886 | - if (!empty($usernames[$member])) |
|
| 887 | - $recipients[$rec_type][$id] = $usernames[$member]; |
|
| 888 | - else |
|
| 927 | + if (!empty($usernames[$member])) { |
|
| 928 | + $recipients[$rec_type][$id] = $usernames[$member]; |
|
| 929 | + } else |
|
| 889 | 930 | { |
| 890 | 931 | $log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]); |
| 891 | 932 | unset($recipients[$rec_type][$id]); |
@@ -924,8 +965,9 @@ discard block |
||
| 924 | 965 | foreach ($criteria as $criterium) |
| 925 | 966 | { |
| 926 | 967 | $match = false; |
| 927 | - 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)) |
|
| 928 | - $delete = true; |
|
| 968 | + 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)) { |
|
| 969 | + $delete = true; |
|
| 970 | + } |
|
| 929 | 971 | // If we're adding and one criteria don't match then we stop! |
| 930 | 972 | elseif (!$row['is_or']) |
| 931 | 973 | { |
@@ -933,8 +975,9 @@ discard block |
||
| 933 | 975 | break; |
| 934 | 976 | } |
| 935 | 977 | } |
| 936 | - if ($delete) |
|
| 937 | - $deletes[$row['id_member']] = 1; |
|
| 978 | + if ($delete) { |
|
| 979 | + $deletes[$row['id_member']] = 1; |
|
| 980 | + } |
|
| 938 | 981 | } |
| 939 | 982 | $smcFunc['db_free_result']($request); |
| 940 | 983 | |
@@ -949,8 +992,9 @@ discard block |
||
| 949 | 992 | array( |
| 950 | 993 | ) |
| 951 | 994 | ); |
| 952 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 953 | - $message_limit_cache[$row['id_group']] = $row['max_messages']; |
|
| 995 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 996 | + $message_limit_cache[$row['id_group']] = $row['max_messages']; |
|
| 997 | + } |
|
| 954 | 998 | $smcFunc['db_free_result']($request); |
| 955 | 999 | } |
| 956 | 1000 | |
@@ -958,8 +1002,9 @@ discard block |
||
| 958 | 1002 | require_once($sourcedir . '/Subs-Members.php'); |
| 959 | 1003 | $pmReadGroups = groupsAllowedTo('pm_read'); |
| 960 | 1004 | |
| 961 | - if (empty($modSettings['permission_enable_deny'])) |
|
| 962 | - $pmReadGroups['denied'] = array(); |
|
| 1005 | + if (empty($modSettings['permission_enable_deny'])) { |
|
| 1006 | + $pmReadGroups['denied'] = array(); |
|
| 1007 | + } |
|
| 963 | 1008 | |
| 964 | 1009 | // Load their alert preferences |
| 965 | 1010 | require_once($sourcedir . '/Subs-Notify.php'); |
@@ -991,8 +1036,9 @@ discard block |
||
| 991 | 1036 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 992 | 1037 | { |
| 993 | 1038 | // Don't do anything for members to be deleted! |
| 994 | - if (isset($deletes[$row['id_member']])) |
|
| 995 | - continue; |
|
| 1039 | + if (isset($deletes[$row['id_member']])) { |
|
| 1040 | + continue; |
|
| 1041 | + } |
|
| 996 | 1042 | |
| 997 | 1043 | // Load the preferences for this member (if any) |
| 998 | 1044 | $prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array(); |
@@ -1013,8 +1059,9 @@ discard block |
||
| 1013 | 1059 | { |
| 1014 | 1060 | foreach ($groups as $id) |
| 1015 | 1061 | { |
| 1016 | - if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) |
|
| 1017 | - $message_limit = $message_limit_cache[$id]; |
|
| 1062 | + if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) { |
|
| 1063 | + $message_limit = $message_limit_cache[$id]; |
|
| 1064 | + } |
|
| 1018 | 1065 | } |
| 1019 | 1066 | |
| 1020 | 1067 | if ($message_limit > 0 && $message_limit <= $row['instant_messages']) |
@@ -1062,8 +1109,9 @@ discard block |
||
| 1062 | 1109 | $smcFunc['db_free_result']($request); |
| 1063 | 1110 | |
| 1064 | 1111 | // Only 'send' the message if there are any recipients left. |
| 1065 | - if (empty($all_to)) |
|
| 1066 | - return $log; |
|
| 1112 | + if (empty($all_to)) { |
|
| 1113 | + return $log; |
|
| 1114 | + } |
|
| 1067 | 1115 | |
| 1068 | 1116 | // Insert the message itself and then grab the last insert id. |
| 1069 | 1117 | $smcFunc['db_insert']('', |
@@ -1084,8 +1132,8 @@ discard block |
||
| 1084 | 1132 | if (!empty($id_pm)) |
| 1085 | 1133 | { |
| 1086 | 1134 | // If this is new we need to set it part of it's own conversation. |
| 1087 | - if (empty($pm_head)) |
|
| 1088 | - $smcFunc['db_query']('', ' |
|
| 1135 | + if (empty($pm_head)) { |
|
| 1136 | + $smcFunc['db_query']('', ' |
|
| 1089 | 1137 | UPDATE {db_prefix}personal_messages |
| 1090 | 1138 | SET id_pm_head = {int:id_pm_head} |
| 1091 | 1139 | WHERE id_pm = {int:id_pm_head}', |
@@ -1093,6 +1141,7 @@ discard block |
||
| 1093 | 1141 | 'id_pm_head' => $id_pm, |
| 1094 | 1142 | ) |
| 1095 | 1143 | ); |
| 1144 | + } |
|
| 1096 | 1145 | |
| 1097 | 1146 | // Some people think manually deleting personal_messages is fun... it's not. We protect against it though :) |
| 1098 | 1147 | $smcFunc['db_query']('', ' |
@@ -1108,8 +1157,9 @@ discard block |
||
| 1108 | 1157 | foreach ($all_to as $to) |
| 1109 | 1158 | { |
| 1110 | 1159 | $insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1); |
| 1111 | - if (!in_array($to, $recipients['bcc'])) |
|
| 1112 | - $to_list[] = $to; |
|
| 1160 | + if (!in_array($to, $recipients['bcc'])) { |
|
| 1161 | + $to_list[] = $to; |
|
| 1162 | + } |
|
| 1113 | 1163 | } |
| 1114 | 1164 | |
| 1115 | 1165 | $smcFunc['db_insert']('insert', |
@@ -1127,9 +1177,9 @@ discard block |
||
| 1127 | 1177 | { |
| 1128 | 1178 | censorText($message); |
| 1129 | 1179 | $message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '[' => '[', ']' => ']'))))); |
| 1180 | + } else { |
|
| 1181 | + $message = ''; |
|
| 1130 | 1182 | } |
| 1131 | - else |
|
| 1132 | - $message = ''; |
|
| 1133 | 1183 | |
| 1134 | 1184 | $to_names = array(); |
| 1135 | 1185 | if (count($to_list) > 1) |
@@ -1142,8 +1192,9 @@ discard block |
||
| 1142 | 1192 | 'to_members' => $to_list, |
| 1143 | 1193 | ) |
| 1144 | 1194 | ); |
| 1145 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1146 | - $to_names[] = un_htmlspecialchars($row['real_name']); |
|
| 1195 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1196 | + $to_names[] = un_htmlspecialchars($row['real_name']); |
|
| 1197 | + } |
|
| 1147 | 1198 | $smcFunc['db_free_result']($request); |
| 1148 | 1199 | } |
| 1149 | 1200 | $replacements = array( |
@@ -1171,11 +1222,13 @@ discard block |
||
| 1171 | 1222 | loadLanguage('index+PersonalMessage'); |
| 1172 | 1223 | |
| 1173 | 1224 | // Add one to their unread and read message counts. |
| 1174 | - foreach ($all_to as $k => $id) |
|
| 1175 | - if (isset($deletes[$id])) |
|
| 1225 | + foreach ($all_to as $k => $id) { |
|
| 1226 | + if (isset($deletes[$id])) |
|
| 1176 | 1227 | unset($all_to[$k]); |
| 1177 | - if (!empty($all_to)) |
|
| 1178 | - updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1)); |
|
| 1228 | + } |
|
| 1229 | + if (!empty($all_to)) { |
|
| 1230 | + updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1)); |
|
| 1231 | + } |
|
| 1179 | 1232 | |
| 1180 | 1233 | return $log; |
| 1181 | 1234 | } |
@@ -1205,15 +1258,17 @@ discard block |
||
| 1205 | 1258 | // Let's, for now, assume there are only 'ish characters. |
| 1206 | 1259 | $simple = true; |
| 1207 | 1260 | |
| 1208 | - foreach ($matches[1] as $entity) |
|
| 1209 | - if ($entity > 128) |
|
| 1261 | + foreach ($matches[1] as $entity) { |
|
| 1262 | + if ($entity > 128) |
|
| 1210 | 1263 | $simple = false; |
| 1264 | + } |
|
| 1211 | 1265 | unset($matches); |
| 1212 | 1266 | |
| 1213 | - if ($simple) |
|
| 1214 | - $string = preg_replace_callback('~&#(\d{3,8});~', function ($m) |
|
| 1267 | + if ($simple) { |
|
| 1268 | + $string = preg_replace_callback('~&#(\d{3,8});~', function ($m) |
|
| 1215 | 1269 | { |
| 1216 | 1270 | return chr("$m[1]"); |
| 1271 | + } |
|
| 1217 | 1272 | }, $string); |
| 1218 | 1273 | else |
| 1219 | 1274 | { |
@@ -1221,8 +1276,9 @@ discard block |
||
| 1221 | 1276 | if (!$context['utf8'] && function_exists('iconv')) |
| 1222 | 1277 | { |
| 1223 | 1278 | $newstring = @iconv($context['character_set'], 'UTF-8', $string); |
| 1224 | - if ($newstring) |
|
| 1225 | - $string = $newstring; |
|
| 1279 | + if ($newstring) { |
|
| 1280 | + $string = $newstring; |
|
| 1281 | + } |
|
| 1226 | 1282 | } |
| 1227 | 1283 | |
| 1228 | 1284 | $string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string); |
@@ -1238,23 +1294,25 @@ discard block |
||
| 1238 | 1294 | if (!$context['utf8'] && function_exists('iconv')) |
| 1239 | 1295 | { |
| 1240 | 1296 | $newstring = @iconv($context['character_set'], 'UTF-8', $string); |
| 1241 | - if ($newstring) |
|
| 1242 | - $string = $newstring; |
|
| 1297 | + if ($newstring) { |
|
| 1298 | + $string = $newstring; |
|
| 1299 | + } |
|
| 1243 | 1300 | } |
| 1244 | 1301 | |
| 1245 | 1302 | $entityConvert = function ($m) |
| 1246 | 1303 | { |
| 1247 | 1304 | $c = $m[1]; |
| 1248 | - if (strlen($c) === 1 && ord($c[0]) <= 0x7F) |
|
| 1249 | - return $c; |
|
| 1250 | - elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) |
|
| 1251 | - return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";"; |
|
| 1252 | - elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) |
|
| 1253 | - return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";"; |
|
| 1254 | - elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) |
|
| 1255 | - return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";"; |
|
| 1256 | - else |
|
| 1257 | - return ""; |
|
| 1305 | + if (strlen($c) === 1 && ord($c[0]) <= 0x7F) { |
|
| 1306 | + return $c; |
|
| 1307 | + } elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) { |
|
| 1308 | + return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";"; |
|
| 1309 | + } elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) { |
|
| 1310 | + return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";"; |
|
| 1311 | + } elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) { |
|
| 1312 | + return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";"; |
|
| 1313 | + } else { |
|
| 1314 | + return ""; |
|
| 1315 | + } |
|
| 1258 | 1316 | }; |
| 1259 | 1317 | |
| 1260 | 1318 | // Convert all 'special' characters to HTML entities. |
@@ -1268,19 +1326,20 @@ discard block |
||
| 1268 | 1326 | $string = base64_encode($string); |
| 1269 | 1327 | |
| 1270 | 1328 | // Show the characterset and the transfer-encoding for header strings. |
| 1271 | - if ($with_charset) |
|
| 1272 | - $string = '=?' . $charset . '?B?' . $string . '?='; |
|
| 1329 | + if ($with_charset) { |
|
| 1330 | + $string = '=?' . $charset . '?B?' . $string . '?='; |
|
| 1331 | + } |
|
| 1273 | 1332 | |
| 1274 | 1333 | // Break it up in lines (mail body). |
| 1275 | - else |
|
| 1276 | - $string = chunk_split($string, 76, $line_break); |
|
| 1334 | + else { |
|
| 1335 | + $string = chunk_split($string, 76, $line_break); |
|
| 1336 | + } |
|
| 1277 | 1337 | |
| 1278 | 1338 | return array($charset, $string, 'base64'); |
| 1339 | + } else { |
|
| 1340 | + return array($charset, $string, '7bit'); |
|
| 1341 | + } |
|
| 1279 | 1342 | } |
| 1280 | - |
|
| 1281 | - else |
|
| 1282 | - return array($charset, $string, '7bit'); |
|
| 1283 | -} |
|
| 1284 | 1343 | |
| 1285 | 1344 | /** |
| 1286 | 1345 | * Sends mail, like mail() but over SMTP. |
@@ -1304,8 +1363,9 @@ discard block |
||
| 1304 | 1363 | if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') |
| 1305 | 1364 | { |
| 1306 | 1365 | $socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2); |
| 1307 | - if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) |
|
| 1308 | - $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2); |
|
| 1366 | + if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) { |
|
| 1367 | + $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2); |
|
| 1368 | + } |
|
| 1309 | 1369 | |
| 1310 | 1370 | if ($socket) |
| 1311 | 1371 | { |
@@ -1326,8 +1386,9 @@ discard block |
||
| 1326 | 1386 | // Maybe we can still save this? The port might be wrong. |
| 1327 | 1387 | if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25)) |
| 1328 | 1388 | { |
| 1329 | - if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) |
|
| 1330 | - log_error($txt['smtp_port_ssl']); |
|
| 1389 | + if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) { |
|
| 1390 | + log_error($txt['smtp_port_ssl']); |
|
| 1391 | + } |
|
| 1331 | 1392 | } |
| 1332 | 1393 | |
| 1333 | 1394 | // Unable to connect! Don't show any error message, but just log one and try to continue anyway. |
@@ -1339,20 +1400,23 @@ discard block |
||
| 1339 | 1400 | } |
| 1340 | 1401 | |
| 1341 | 1402 | // Wait for a response of 220, without "-" continuer. |
| 1342 | - if (!server_parse(null, $socket, '220')) |
|
| 1343 | - return false; |
|
| 1403 | + if (!server_parse(null, $socket, '220')) { |
|
| 1404 | + return false; |
|
| 1405 | + } |
|
| 1344 | 1406 | |
| 1345 | 1407 | // Try and determine the servers name, fall back to the mail servers if not found |
| 1346 | 1408 | $helo = false; |
| 1347 | - if (function_exists('gethostname') && gethostname() !== false) |
|
| 1348 | - $helo = gethostname(); |
|
| 1349 | - elseif (function_exists('php_uname')) |
|
| 1350 | - $helo = php_uname('n'); |
|
| 1351 | - elseif (array_key_exists('SERVER_NAME',$_SERVER) && !empty($_SERVER['SERVER_NAME'])) |
|
| 1352 | - $helo = $_SERVER['SERVER_NAME']; |
|
| 1409 | + if (function_exists('gethostname') && gethostname() !== false) { |
|
| 1410 | + $helo = gethostname(); |
|
| 1411 | + } elseif (function_exists('php_uname')) { |
|
| 1412 | + $helo = php_uname('n'); |
|
| 1413 | + } elseif (array_key_exists('SERVER_NAME',$_SERVER) && !empty($_SERVER['SERVER_NAME'])) { |
|
| 1414 | + $helo = $_SERVER['SERVER_NAME']; |
|
| 1415 | + } |
|
| 1353 | 1416 | |
| 1354 | - if (empty($helo)) |
|
| 1355 | - $helo = $modSettings['smtp_host']; |
|
| 1417 | + if (empty($helo)) { |
|
| 1418 | + $helo = $modSettings['smtp_host']; |
|
| 1419 | + } |
|
| 1356 | 1420 | |
| 1357 | 1421 | // SMTP = 1, SMTP - STARTTLS = 2 |
| 1358 | 1422 | if (in_array($modSettings['mail_type'], array(1,2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') |
@@ -1364,33 +1428,39 @@ discard block |
||
| 1364 | 1428 | if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response)) |
| 1365 | 1429 | { |
| 1366 | 1430 | // Send STARTTLS to enable encryption |
| 1367 | - if (!server_parse('STARTTLS', $socket, '220')) |
|
| 1368 | - return false; |
|
| 1431 | + if (!server_parse('STARTTLS', $socket, '220')) { |
|
| 1432 | + return false; |
|
| 1433 | + } |
|
| 1369 | 1434 | // Enable the encryption |
| 1370 | - if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) |
|
| 1371 | - return false; |
|
| 1435 | + if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { |
|
| 1436 | + return false; |
|
| 1437 | + } |
|
| 1372 | 1438 | // Send the EHLO command again |
| 1373 | - if (!server_parse('EHLO ' . $helo, $socket, null) == '250') |
|
| 1374 | - return false; |
|
| 1439 | + if (!server_parse('EHLO ' . $helo, $socket, null) == '250') { |
|
| 1440 | + return false; |
|
| 1441 | + } |
|
| 1375 | 1442 | } |
| 1376 | 1443 | |
| 1377 | - if (!server_parse('AUTH LOGIN', $socket, '334')) |
|
| 1378 | - return false; |
|
| 1444 | + if (!server_parse('AUTH LOGIN', $socket, '334')) { |
|
| 1445 | + return false; |
|
| 1446 | + } |
|
| 1379 | 1447 | // Send the username and password, encoded. |
| 1380 | - if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) |
|
| 1381 | - return false; |
|
| 1448 | + if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) { |
|
| 1449 | + return false; |
|
| 1450 | + } |
|
| 1382 | 1451 | // The password is already encoded ;) |
| 1383 | - if (!server_parse($modSettings['smtp_password'], $socket, '235')) |
|
| 1384 | - return false; |
|
| 1452 | + if (!server_parse($modSettings['smtp_password'], $socket, '235')) { |
|
| 1453 | + return false; |
|
| 1454 | + } |
|
| 1455 | + } elseif (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
| 1456 | + return false; |
|
| 1385 | 1457 | } |
| 1386 | - elseif (!server_parse('HELO ' . $helo, $socket, '250')) |
|
| 1387 | - return false; |
|
| 1388 | - } |
|
| 1389 | - else |
|
| 1458 | + } else |
|
| 1390 | 1459 | { |
| 1391 | 1460 | // Just say "helo". |
| 1392 | - if (!server_parse('HELO ' . $helo, $socket, '250')) |
|
| 1393 | - return false; |
|
| 1461 | + if (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
| 1462 | + return false; |
|
| 1463 | + } |
|
| 1394 | 1464 | } |
| 1395 | 1465 | |
| 1396 | 1466 | // Fix the message for any lines beginning with a period! (the first is ignored, you see.) |
@@ -1403,31 +1473,38 @@ discard block |
||
| 1403 | 1473 | // Reset the connection to send another email. |
| 1404 | 1474 | if ($i != 0) |
| 1405 | 1475 | { |
| 1406 | - if (!server_parse('RSET', $socket, '250')) |
|
| 1407 | - return false; |
|
| 1476 | + if (!server_parse('RSET', $socket, '250')) { |
|
| 1477 | + return false; |
|
| 1478 | + } |
|
| 1408 | 1479 | } |
| 1409 | 1480 | |
| 1410 | 1481 | // From, to, and then start the data... |
| 1411 | - if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) |
|
| 1412 | - return false; |
|
| 1413 | - if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) |
|
| 1414 | - return false; |
|
| 1415 | - if (!server_parse('DATA', $socket, '354')) |
|
| 1416 | - return false; |
|
| 1482 | + if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) { |
|
| 1483 | + return false; |
|
| 1484 | + } |
|
| 1485 | + if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) { |
|
| 1486 | + return false; |
|
| 1487 | + } |
|
| 1488 | + if (!server_parse('DATA', $socket, '354')) { |
|
| 1489 | + return false; |
|
| 1490 | + } |
|
| 1417 | 1491 | fputs($socket, 'Subject: ' . $subject . "\r\n"); |
| 1418 | - if (strlen($mail_to) > 0) |
|
| 1419 | - fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
| 1492 | + if (strlen($mail_to) > 0) { |
|
| 1493 | + fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
| 1494 | + } |
|
| 1420 | 1495 | fputs($socket, $headers . "\r\n\r\n"); |
| 1421 | 1496 | fputs($socket, $message . "\r\n"); |
| 1422 | 1497 | |
| 1423 | 1498 | // Send a ., or in other words "end of data". |
| 1424 | - if (!server_parse('.', $socket, '250')) |
|
| 1425 | - return false; |
|
| 1499 | + if (!server_parse('.', $socket, '250')) { |
|
| 1500 | + return false; |
|
| 1501 | + } |
|
| 1426 | 1502 | |
| 1427 | 1503 | // Almost done, almost done... don't stop me just yet! |
| 1428 | 1504 | @set_time_limit(300); |
| 1429 | - if (function_exists('apache_reset_timeout')) |
|
| 1430 | - @apache_reset_timeout(); |
|
| 1505 | + if (function_exists('apache_reset_timeout')) { |
|
| 1506 | + @apache_reset_timeout(); |
|
| 1507 | + } |
|
| 1431 | 1508 | } |
| 1432 | 1509 | fputs($socket, 'QUIT' . "\r\n"); |
| 1433 | 1510 | fclose($socket); |
@@ -1451,8 +1528,9 @@ discard block |
||
| 1451 | 1528 | { |
| 1452 | 1529 | global $txt; |
| 1453 | 1530 | |
| 1454 | - if ($message !== null) |
|
| 1455 | - fputs($socket, $message . "\r\n"); |
|
| 1531 | + if ($message !== null) { |
|
| 1532 | + fputs($socket, $message . "\r\n"); |
|
| 1533 | + } |
|
| 1456 | 1534 | |
| 1457 | 1535 | // No response yet. |
| 1458 | 1536 | $server_response = ''; |
@@ -1468,8 +1546,9 @@ discard block |
||
| 1468 | 1546 | $response .= $server_response; |
| 1469 | 1547 | } |
| 1470 | 1548 | |
| 1471 | - if ($code === null) |
|
| 1472 | - return substr($server_response, 0, 3); |
|
| 1549 | + if ($code === null) { |
|
| 1550 | + return substr($server_response, 0, 3); |
|
| 1551 | + } |
|
| 1473 | 1552 | |
| 1474 | 1553 | if (substr($server_response, 0, 3) != $code) |
| 1475 | 1554 | { |
@@ -1499,8 +1578,9 @@ discard block |
||
| 1499 | 1578 | // Create a pspell or enchant dictionary resource |
| 1500 | 1579 | $dict = spell_init(); |
| 1501 | 1580 | |
| 1502 | - if (!isset($_POST['spellstring']) || !$dict) |
|
| 1503 | - die; |
|
| 1581 | + if (!isset($_POST['spellstring']) || !$dict) { |
|
| 1582 | + die; |
|
| 1583 | + } |
|
| 1504 | 1584 | |
| 1505 | 1585 | // Construct a bit of Javascript code. |
| 1506 | 1586 | $context['spell_js'] = ' |
@@ -1518,8 +1598,9 @@ discard block |
||
| 1518 | 1598 | $check_word = explode('|', $alphas[$i]); |
| 1519 | 1599 | |
| 1520 | 1600 | // If the word is a known word, or spelled right... |
| 1521 | - if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) |
|
| 1522 | - continue; |
|
| 1601 | + if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) { |
|
| 1602 | + continue; |
|
| 1603 | + } |
|
| 1523 | 1604 | |
| 1524 | 1605 | // Find the word, and move up the "last occurrence" to here. |
| 1525 | 1606 | $found_words = true; |
@@ -1533,20 +1614,23 @@ discard block |
||
| 1533 | 1614 | if (!empty($suggestions)) |
| 1534 | 1615 | { |
| 1535 | 1616 | // But first check they aren't going to be censored - no naughty words! |
| 1536 | - foreach ($suggestions as $k => $word) |
|
| 1537 | - if ($suggestions[$k] != censorText($word)) |
|
| 1617 | + foreach ($suggestions as $k => $word) { |
|
| 1618 | + if ($suggestions[$k] != censorText($word)) |
|
| 1538 | 1619 | unset($suggestions[$k]); |
| 1620 | + } |
|
| 1539 | 1621 | |
| 1540 | - if (!empty($suggestions)) |
|
| 1541 | - $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
| 1622 | + if (!empty($suggestions)) { |
|
| 1623 | + $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
| 1624 | + } |
|
| 1542 | 1625 | } |
| 1543 | 1626 | |
| 1544 | 1627 | $context['spell_js'] .= ']),'; |
| 1545 | 1628 | } |
| 1546 | 1629 | |
| 1547 | 1630 | // If words were found, take off the last comma. |
| 1548 | - if ($found_words) |
|
| 1549 | - $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
| 1631 | + if ($found_words) { |
|
| 1632 | + $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
| 1633 | + } |
|
| 1550 | 1634 | |
| 1551 | 1635 | $context['spell_js'] .= ' |
| 1552 | 1636 | );'; |
@@ -1581,11 +1665,13 @@ discard block |
||
| 1581 | 1665 | global $user_info, $smcFunc; |
| 1582 | 1666 | |
| 1583 | 1667 | // Can't do it if there's no topics. |
| 1584 | - if (empty($topics)) |
|
| 1585 | - return; |
|
| 1668 | + if (empty($topics)) { |
|
| 1669 | + return; |
|
| 1670 | + } |
|
| 1586 | 1671 | // It must be an array - it must! |
| 1587 | - if (!is_array($topics)) |
|
| 1588 | - $topics = array($topics); |
|
| 1672 | + if (!is_array($topics)) { |
|
| 1673 | + $topics = array($topics); |
|
| 1674 | + } |
|
| 1589 | 1675 | |
| 1590 | 1676 | // Get the subject and body... |
| 1591 | 1677 | $result = $smcFunc['db_query']('', ' |
@@ -1633,14 +1719,15 @@ discard block |
||
| 1633 | 1719 | } |
| 1634 | 1720 | $smcFunc['db_free_result']($result); |
| 1635 | 1721 | |
| 1636 | - if (!empty($task_rows)) |
|
| 1637 | - $smcFunc['db_insert']('', |
|
| 1722 | + if (!empty($task_rows)) { |
|
| 1723 | + $smcFunc['db_insert']('', |
|
| 1638 | 1724 | '{db_prefix}background_tasks', |
| 1639 | 1725 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 1640 | 1726 | $task_rows, |
| 1641 | 1727 | array('id_task') |
| 1642 | 1728 | ); |
| 1643 | -} |
|
| 1729 | + } |
|
| 1730 | + } |
|
| 1644 | 1731 | |
| 1645 | 1732 | /** |
| 1646 | 1733 | * Create a post, either as new topic (id_topic = 0) or in an existing one. |
@@ -1678,9 +1765,9 @@ discard block |
||
| 1678 | 1765 | $msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true; |
| 1679 | 1766 | |
| 1680 | 1767 | // We need to know if the topic is approved. If we're told that's great - if not find out. |
| 1681 | - if (!$modSettings['postmod_active']) |
|
| 1682 | - $topicOptions['is_approved'] = true; |
|
| 1683 | - elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
| 1768 | + if (!$modSettings['postmod_active']) { |
|
| 1769 | + $topicOptions['is_approved'] = true; |
|
| 1770 | + } elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
| 1684 | 1771 | { |
| 1685 | 1772 | $request = $smcFunc['db_query']('', ' |
| 1686 | 1773 | SELECT approved |
@@ -1703,8 +1790,7 @@ discard block |
||
| 1703 | 1790 | $posterOptions['id'] = 0; |
| 1704 | 1791 | $posterOptions['name'] = $txt['guest_title']; |
| 1705 | 1792 | $posterOptions['email'] = ''; |
| 1706 | - } |
|
| 1707 | - elseif ($posterOptions['id'] != $user_info['id']) |
|
| 1793 | + } elseif ($posterOptions['id'] != $user_info['id']) |
|
| 1708 | 1794 | { |
| 1709 | 1795 | $request = $smcFunc['db_query']('', ' |
| 1710 | 1796 | SELECT member_name, email_address |
@@ -1722,12 +1808,11 @@ discard block |
||
| 1722 | 1808 | $posterOptions['id'] = 0; |
| 1723 | 1809 | $posterOptions['name'] = $txt['guest_title']; |
| 1724 | 1810 | $posterOptions['email'] = ''; |
| 1811 | + } else { |
|
| 1812 | + list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
| 1725 | 1813 | } |
| 1726 | - else |
|
| 1727 | - list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
| 1728 | 1814 | $smcFunc['db_free_result']($request); |
| 1729 | - } |
|
| 1730 | - else |
|
| 1815 | + } else |
|
| 1731 | 1816 | { |
| 1732 | 1817 | $posterOptions['name'] = $user_info['name']; |
| 1733 | 1818 | $posterOptions['email'] = $user_info['email']; |
@@ -1737,8 +1822,9 @@ discard block |
||
| 1737 | 1822 | if (!empty($modSettings['enable_mentions'])) |
| 1738 | 1823 | { |
| 1739 | 1824 | $msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']); |
| 1740 | - if (!empty($msgOptions['mentioned_members'])) |
|
| 1741 | - $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
| 1825 | + if (!empty($msgOptions['mentioned_members'])) { |
|
| 1826 | + $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
| 1827 | + } |
|
| 1742 | 1828 | } |
| 1743 | 1829 | |
| 1744 | 1830 | // It's do or die time: forget any user aborts! |
@@ -1771,12 +1857,13 @@ discard block |
||
| 1771 | 1857 | $msgOptions['id'] = $smcFunc['db_insert_id']('{db_prefix}messages', 'id_msg'); |
| 1772 | 1858 | |
| 1773 | 1859 | // Something went wrong creating the message... |
| 1774 | - if (empty($msgOptions['id'])) |
|
| 1775 | - return false; |
|
| 1860 | + if (empty($msgOptions['id'])) { |
|
| 1861 | + return false; |
|
| 1862 | + } |
|
| 1776 | 1863 | |
| 1777 | 1864 | // Fix the attachments. |
| 1778 | - if (!empty($msgOptions['attachments'])) |
|
| 1779 | - $smcFunc['db_query']('', ' |
|
| 1865 | + if (!empty($msgOptions['attachments'])) { |
|
| 1866 | + $smcFunc['db_query']('', ' |
|
| 1780 | 1867 | UPDATE {db_prefix}attachments |
| 1781 | 1868 | SET id_msg = {int:id_msg} |
| 1782 | 1869 | WHERE id_attach IN ({array_int:attachment_list})', |
@@ -1785,6 +1872,7 @@ discard block |
||
| 1785 | 1872 | 'id_msg' => $msgOptions['id'], |
| 1786 | 1873 | ) |
| 1787 | 1874 | ); |
| 1875 | + } |
|
| 1788 | 1876 | |
| 1789 | 1877 | // What if we want to export new posts out to a CMS? |
| 1790 | 1878 | call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters)); |
@@ -1862,20 +1950,23 @@ discard block |
||
| 1862 | 1950 | 'counter_increment' => 1, |
| 1863 | 1951 | ); |
| 1864 | 1952 | $topics_columns = array(); |
| 1865 | - if ($msgOptions['approved']) |
|
| 1866 | - $topics_columns = array( |
|
| 1953 | + if ($msgOptions['approved']) { |
|
| 1954 | + $topics_columns = array( |
|
| 1867 | 1955 | 'id_member_updated = {int:poster_id}', |
| 1868 | 1956 | 'id_last_msg = {int:id_msg}', |
| 1869 | 1957 | 'num_replies = num_replies + {int:counter_increment}', |
| 1870 | 1958 | ); |
| 1871 | - else |
|
| 1872 | - $topics_columns = array( |
|
| 1959 | + } else { |
|
| 1960 | + $topics_columns = array( |
|
| 1873 | 1961 | 'unapproved_posts = unapproved_posts + {int:counter_increment}', |
| 1874 | 1962 | ); |
| 1875 | - if ($topicOptions['lock_mode'] !== null) |
|
| 1876 | - $topics_columns[] = 'locked = {int:locked}'; |
|
| 1877 | - if ($topicOptions['sticky_mode'] !== null) |
|
| 1878 | - $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
| 1963 | + } |
|
| 1964 | + if ($topicOptions['lock_mode'] !== null) { |
|
| 1965 | + $topics_columns[] = 'locked = {int:locked}'; |
|
| 1966 | + } |
|
| 1967 | + if ($topicOptions['sticky_mode'] !== null) { |
|
| 1968 | + $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
| 1969 | + } |
|
| 1879 | 1970 | |
| 1880 | 1971 | call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions)); |
| 1881 | 1972 | |
@@ -1904,8 +1995,8 @@ discard block |
||
| 1904 | 1995 | ); |
| 1905 | 1996 | |
| 1906 | 1997 | // Increase the number of posts and topics on the board. |
| 1907 | - if ($msgOptions['approved']) |
|
| 1908 | - $smcFunc['db_query']('', ' |
|
| 1998 | + if ($msgOptions['approved']) { |
|
| 1999 | + $smcFunc['db_query']('', ' |
|
| 1909 | 2000 | UPDATE {db_prefix}boards |
| 1910 | 2001 | SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . ' |
| 1911 | 2002 | WHERE id_board = {int:id_board}', |
@@ -1913,7 +2004,7 @@ discard block |
||
| 1913 | 2004 | 'id_board' => $topicOptions['board'], |
| 1914 | 2005 | ) |
| 1915 | 2006 | ); |
| 1916 | - else |
|
| 2007 | + } else |
|
| 1917 | 2008 | { |
| 1918 | 2009 | $smcFunc['db_query']('', ' |
| 1919 | 2010 | UPDATE {db_prefix}boards |
@@ -1983,8 +2074,8 @@ discard block |
||
| 1983 | 2074 | } |
| 1984 | 2075 | } |
| 1985 | 2076 | |
| 1986 | - if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) |
|
| 1987 | - $smcFunc['db_insert']('', |
|
| 2077 | + if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) { |
|
| 2078 | + $smcFunc['db_insert']('', |
|
| 1988 | 2079 | '{db_prefix}background_tasks', |
| 1989 | 2080 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 1990 | 2081 | array( |
@@ -1996,19 +2087,22 @@ discard block |
||
| 1996 | 2087 | ), |
| 1997 | 2088 | array('id_task') |
| 1998 | 2089 | ); |
| 2090 | + } |
|
| 1999 | 2091 | |
| 2000 | 2092 | // If there's a custom search index, it may need updating... |
| 2001 | 2093 | require_once($sourcedir . '/Search.php'); |
| 2002 | 2094 | $searchAPI = findSearchAPI(); |
| 2003 | - if (is_callable(array($searchAPI, 'postCreated'))) |
|
| 2004 | - $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
| 2095 | + if (is_callable(array($searchAPI, 'postCreated'))) { |
|
| 2096 | + $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
| 2097 | + } |
|
| 2005 | 2098 | |
| 2006 | 2099 | // Increase the post counter for the user that created the post. |
| 2007 | 2100 | if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved']) |
| 2008 | 2101 | { |
| 2009 | 2102 | // Are you the one that happened to create this post? |
| 2010 | - if ($user_info['id'] == $posterOptions['id']) |
|
| 2011 | - $user_info['posts']++; |
|
| 2103 | + if ($user_info['id'] == $posterOptions['id']) { |
|
| 2104 | + $user_info['posts']++; |
|
| 2105 | + } |
|
| 2012 | 2106 | updateMemberData($posterOptions['id'], array('posts' => '+')); |
| 2013 | 2107 | } |
| 2014 | 2108 | |
@@ -2016,19 +2110,21 @@ discard block |
||
| 2016 | 2110 | $_SESSION['last_read_topic'] = 0; |
| 2017 | 2111 | |
| 2018 | 2112 | // Better safe than sorry. |
| 2019 | - if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) |
|
| 2020 | - $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
| 2113 | + if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) { |
|
| 2114 | + $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
| 2115 | + } |
|
| 2021 | 2116 | |
| 2022 | 2117 | // Update all the stats so everyone knows about this new topic and message. |
| 2023 | 2118 | updateStats('message', true, $msgOptions['id']); |
| 2024 | 2119 | |
| 2025 | 2120 | // Update the last message on the board assuming it's approved AND the topic is. |
| 2026 | - if ($msgOptions['approved']) |
|
| 2027 | - updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
| 2121 | + if ($msgOptions['approved']) { |
|
| 2122 | + updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
| 2123 | + } |
|
| 2028 | 2124 | |
| 2029 | 2125 | // Queue createPost background notification |
| 2030 | - if ($msgOptions['send_notifications'] && $msgOptions['approved']) |
|
| 2031 | - $smcFunc['db_insert']('', |
|
| 2126 | + if ($msgOptions['send_notifications'] && $msgOptions['approved']) { |
|
| 2127 | + $smcFunc['db_insert']('', |
|
| 2032 | 2128 | '{db_prefix}background_tasks', |
| 2033 | 2129 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 2034 | 2130 | array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array( |
@@ -2039,6 +2135,7 @@ discard block |
||
| 2039 | 2135 | )), 0), |
| 2040 | 2136 | array('id_task') |
| 2041 | 2137 | ); |
| 2138 | + } |
|
| 2042 | 2139 | |
| 2043 | 2140 | // Alright, done now... we can abort now, I guess... at least this much is done. |
| 2044 | 2141 | ignore_user_abort($previous_ignore_user_abort); |
@@ -2065,14 +2162,18 @@ discard block |
||
| 2065 | 2162 | |
| 2066 | 2163 | // This is longer than it has to be, but makes it so we only set/change what we have to. |
| 2067 | 2164 | $messages_columns = array(); |
| 2068 | - if (isset($posterOptions['name'])) |
|
| 2069 | - $messages_columns['poster_name'] = $posterOptions['name']; |
|
| 2070 | - if (isset($posterOptions['email'])) |
|
| 2071 | - $messages_columns['poster_email'] = $posterOptions['email']; |
|
| 2072 | - if (isset($msgOptions['icon'])) |
|
| 2073 | - $messages_columns['icon'] = $msgOptions['icon']; |
|
| 2074 | - if (isset($msgOptions['subject'])) |
|
| 2075 | - $messages_columns['subject'] = $msgOptions['subject']; |
|
| 2165 | + if (isset($posterOptions['name'])) { |
|
| 2166 | + $messages_columns['poster_name'] = $posterOptions['name']; |
|
| 2167 | + } |
|
| 2168 | + if (isset($posterOptions['email'])) { |
|
| 2169 | + $messages_columns['poster_email'] = $posterOptions['email']; |
|
| 2170 | + } |
|
| 2171 | + if (isset($msgOptions['icon'])) { |
|
| 2172 | + $messages_columns['icon'] = $msgOptions['icon']; |
|
| 2173 | + } |
|
| 2174 | + if (isset($msgOptions['subject'])) { |
|
| 2175 | + $messages_columns['subject'] = $msgOptions['subject']; |
|
| 2176 | + } |
|
| 2076 | 2177 | if (isset($msgOptions['body'])) |
| 2077 | 2178 | { |
| 2078 | 2179 | $messages_columns['body'] = $msgOptions['body']; |
@@ -2099,8 +2200,9 @@ discard block |
||
| 2099 | 2200 | $messages_columns['modified_reason'] = $msgOptions['modify_reason']; |
| 2100 | 2201 | $messages_columns['id_msg_modified'] = $modSettings['maxMsgID']; |
| 2101 | 2202 | } |
| 2102 | - if (isset($msgOptions['smileys_enabled'])) |
|
| 2103 | - $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
| 2203 | + if (isset($msgOptions['smileys_enabled'])) { |
|
| 2204 | + $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
| 2205 | + } |
|
| 2104 | 2206 | |
| 2105 | 2207 | // Which columns need to be ints? |
| 2106 | 2208 | $messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled'); |
@@ -2118,23 +2220,27 @@ discard block |
||
| 2118 | 2220 | { |
| 2119 | 2221 | preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match); |
| 2120 | 2222 | |
| 2121 | - if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) |
|
| 2122 | - foreach($match[1] as $i => $oldID) |
|
| 2223 | + if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) { |
|
| 2224 | + foreach($match[1] as $i => $oldID) |
|
| 2123 | 2225 | $oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]); |
| 2226 | + } |
|
| 2124 | 2227 | |
| 2125 | - if (empty($modSettings['search_custom_index_config'])) |
|
| 2126 | - unset($msgOptions['old_body']); |
|
| 2228 | + if (empty($modSettings['search_custom_index_config'])) { |
|
| 2229 | + unset($msgOptions['old_body']); |
|
| 2230 | + } |
|
| 2127 | 2231 | } |
| 2128 | 2232 | |
| 2129 | 2233 | $mentions = Mentions::getMentionedMembers($msgOptions['body']); |
| 2130 | 2234 | $messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions); |
| 2131 | 2235 | |
| 2132 | 2236 | // Remove the poster. |
| 2133 | - if(isset($mentions[$user_info['id']])) |
|
| 2134 | - unset($mentions[$user_info['id']]); |
|
| 2237 | + if(isset($mentions[$user_info['id']])) { |
|
| 2238 | + unset($mentions[$user_info['id']]); |
|
| 2239 | + } |
|
| 2135 | 2240 | |
| 2136 | - if(isset($oldmentions[$user_info['id']])) |
|
| 2137 | - unset($oldmentions[$user_info['id']]); |
|
| 2241 | + if(isset($oldmentions[$user_info['id']])) { |
|
| 2242 | + unset($oldmentions[$user_info['id']]); |
|
| 2243 | + } |
|
| 2138 | 2244 | |
| 2139 | 2245 | if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions)) |
| 2140 | 2246 | { |
@@ -2164,8 +2270,9 @@ discard block |
||
| 2164 | 2270 | } |
| 2165 | 2271 | |
| 2166 | 2272 | // Nothing to do? |
| 2167 | - if (empty($messages_columns)) |
|
| 2168 | - return true; |
|
| 2273 | + if (empty($messages_columns)) { |
|
| 2274 | + return true; |
|
| 2275 | + } |
|
| 2169 | 2276 | |
| 2170 | 2277 | // Change the post. |
| 2171 | 2278 | $smcFunc['db_query']('', ' |
@@ -2226,8 +2333,9 @@ discard block |
||
| 2226 | 2333 | // If there's a custom search index, it needs to be modified... |
| 2227 | 2334 | require_once($sourcedir . '/Search.php'); |
| 2228 | 2335 | $searchAPI = findSearchAPI(); |
| 2229 | - if (is_callable(array($searchAPI, 'postModified'))) |
|
| 2230 | - $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
| 2336 | + if (is_callable(array($searchAPI, 'postModified'))) { |
|
| 2337 | + $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
| 2338 | + } |
|
| 2231 | 2339 | |
| 2232 | 2340 | if (isset($msgOptions['subject'])) |
| 2233 | 2341 | { |
@@ -2241,14 +2349,16 @@ discard block |
||
| 2241 | 2349 | 'id_first_msg' => $msgOptions['id'], |
| 2242 | 2350 | ) |
| 2243 | 2351 | ); |
| 2244 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
| 2245 | - updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
| 2352 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
| 2353 | + updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
| 2354 | + } |
|
| 2246 | 2355 | $smcFunc['db_free_result']($request); |
| 2247 | 2356 | } |
| 2248 | 2357 | |
| 2249 | 2358 | // Finally, if we are setting the approved state we need to do much more work :( |
| 2250 | - if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) |
|
| 2251 | - approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
| 2359 | + if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) { |
|
| 2360 | + approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
| 2361 | + } |
|
| 2252 | 2362 | |
| 2253 | 2363 | return true; |
| 2254 | 2364 | } |
@@ -2265,11 +2375,13 @@ discard block |
||
| 2265 | 2375 | { |
| 2266 | 2376 | global $smcFunc; |
| 2267 | 2377 | |
| 2268 | - if (!is_array($msgs)) |
|
| 2269 | - $msgs = array($msgs); |
|
| 2378 | + if (!is_array($msgs)) { |
|
| 2379 | + $msgs = array($msgs); |
|
| 2380 | + } |
|
| 2270 | 2381 | |
| 2271 | - if (empty($msgs)) |
|
| 2272 | - return false; |
|
| 2382 | + if (empty($msgs)) { |
|
| 2383 | + return false; |
|
| 2384 | + } |
|
| 2273 | 2385 | |
| 2274 | 2386 | // May as well start at the beginning, working out *what* we need to change. |
| 2275 | 2387 | $request = $smcFunc['db_query']('', ' |
@@ -2301,20 +2413,22 @@ discard block |
||
| 2301 | 2413 | $topics[] = $row['id_topic']; |
| 2302 | 2414 | |
| 2303 | 2415 | // Ensure our change array exists already. |
| 2304 | - if (!isset($topic_changes[$row['id_topic']])) |
|
| 2305 | - $topic_changes[$row['id_topic']] = array( |
|
| 2416 | + if (!isset($topic_changes[$row['id_topic']])) { |
|
| 2417 | + $topic_changes[$row['id_topic']] = array( |
|
| 2306 | 2418 | 'id_last_msg' => $row['id_last_msg'], |
| 2307 | 2419 | 'approved' => $row['topic_approved'], |
| 2308 | 2420 | 'replies' => 0, |
| 2309 | 2421 | 'unapproved_posts' => 0, |
| 2310 | 2422 | ); |
| 2311 | - if (!isset($board_changes[$row['id_board']])) |
|
| 2312 | - $board_changes[$row['id_board']] = array( |
|
| 2423 | + } |
|
| 2424 | + if (!isset($board_changes[$row['id_board']])) { |
|
| 2425 | + $board_changes[$row['id_board']] = array( |
|
| 2313 | 2426 | 'posts' => 0, |
| 2314 | 2427 | 'topics' => 0, |
| 2315 | 2428 | 'unapproved_posts' => 0, |
| 2316 | 2429 | 'unapproved_topics' => 0, |
| 2317 | 2430 | ); |
| 2431 | + } |
|
| 2318 | 2432 | |
| 2319 | 2433 | // If it's the first message then the topic state changes! |
| 2320 | 2434 | if ($row['id_msg'] == $row['id_first_msg']) |
@@ -2335,14 +2449,13 @@ discard block |
||
| 2335 | 2449 | 'poster' => $row['id_member'], |
| 2336 | 2450 | 'new_topic' => true, |
| 2337 | 2451 | ); |
| 2338 | - } |
|
| 2339 | - else |
|
| 2452 | + } else |
|
| 2340 | 2453 | { |
| 2341 | 2454 | $topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1; |
| 2342 | 2455 | |
| 2343 | 2456 | // This will be a post... but don't notify unless it's not followed by approved ones. |
| 2344 | - if ($row['id_msg'] > $row['id_last_msg']) |
|
| 2345 | - $notification_posts[$row['id_topic']] = array( |
|
| 2457 | + if ($row['id_msg'] > $row['id_last_msg']) { |
|
| 2458 | + $notification_posts[$row['id_topic']] = array( |
|
| 2346 | 2459 | 'id' => $row['id_msg'], |
| 2347 | 2460 | 'body' => $row['body'], |
| 2348 | 2461 | 'subject' => $row['subject'], |
@@ -2353,28 +2466,33 @@ discard block |
||
| 2353 | 2466 | 'new_topic' => false, |
| 2354 | 2467 | 'msg' => $row['id_msg'], |
| 2355 | 2468 | ); |
| 2469 | + } |
|
| 2356 | 2470 | } |
| 2357 | 2471 | |
| 2358 | 2472 | // If this is being approved and id_msg is higher than the current id_last_msg then it changes. |
| 2359 | - if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) |
|
| 2360 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
| 2473 | + if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) { |
|
| 2474 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
| 2475 | + } |
|
| 2361 | 2476 | // If this is being unapproved, and it's equal to the id_last_msg we need to find a new one! |
| 2362 | - elseif (!$approve) |
|
| 2363 | - // Default to the first message and then we'll override in a bit ;) |
|
| 2477 | + elseif (!$approve) { |
|
| 2478 | + // Default to the first message and then we'll override in a bit ;) |
|
| 2364 | 2479 | $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg']; |
| 2480 | + } |
|
| 2365 | 2481 | |
| 2366 | 2482 | $topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1; |
| 2367 | 2483 | $board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1; |
| 2368 | 2484 | $board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1; |
| 2369 | 2485 | |
| 2370 | 2486 | // Post count for the user? |
| 2371 | - if ($row['id_member'] && empty($row['count_posts'])) |
|
| 2372 | - $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
| 2487 | + if ($row['id_member'] && empty($row['count_posts'])) { |
|
| 2488 | + $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
| 2489 | + } |
|
| 2373 | 2490 | } |
| 2374 | 2491 | $smcFunc['db_free_result']($request); |
| 2375 | 2492 | |
| 2376 | - if (empty($msgs)) |
|
| 2377 | - return; |
|
| 2493 | + if (empty($msgs)) { |
|
| 2494 | + return; |
|
| 2495 | + } |
|
| 2378 | 2496 | |
| 2379 | 2497 | // Now we have the differences make the changes, first the easy one. |
| 2380 | 2498 | $smcFunc['db_query']('', ' |
@@ -2401,14 +2519,15 @@ discard block |
||
| 2401 | 2519 | 'approved' => 1, |
| 2402 | 2520 | ) |
| 2403 | 2521 | ); |
| 2404 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2405 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
| 2522 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2523 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
| 2524 | + } |
|
| 2406 | 2525 | $smcFunc['db_free_result']($request); |
| 2407 | 2526 | } |
| 2408 | 2527 | |
| 2409 | 2528 | // ... next the topics... |
| 2410 | - foreach ($topic_changes as $id => $changes) |
|
| 2411 | - $smcFunc['db_query']('', ' |
|
| 2529 | + foreach ($topic_changes as $id => $changes) { |
|
| 2530 | + $smcFunc['db_query']('', ' |
|
| 2412 | 2531 | UPDATE {db_prefix}topics |
| 2413 | 2532 | SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
| 2414 | 2533 | num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg} |
@@ -2421,10 +2540,11 @@ discard block |
||
| 2421 | 2540 | 'id_topic' => $id, |
| 2422 | 2541 | ) |
| 2423 | 2542 | ); |
| 2543 | + } |
|
| 2424 | 2544 | |
| 2425 | 2545 | // ... finally the boards... |
| 2426 | - foreach ($board_changes as $id => $changes) |
|
| 2427 | - $smcFunc['db_query']('', ' |
|
| 2546 | + foreach ($board_changes as $id => $changes) { |
|
| 2547 | + $smcFunc['db_query']('', ' |
|
| 2428 | 2548 | UPDATE {db_prefix}boards |
| 2429 | 2549 | SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
| 2430 | 2550 | num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics} |
@@ -2437,13 +2557,14 @@ discard block |
||
| 2437 | 2557 | 'id_board' => $id, |
| 2438 | 2558 | ) |
| 2439 | 2559 | ); |
| 2560 | + } |
|
| 2440 | 2561 | |
| 2441 | 2562 | // Finally, least importantly, notifications! |
| 2442 | 2563 | if ($approve) |
| 2443 | 2564 | { |
| 2444 | 2565 | $task_rows = array(); |
| 2445 | - foreach (array_merge($notification_topics, $notification_posts) as $topic) |
|
| 2446 | - $task_rows[] = array( |
|
| 2566 | + foreach (array_merge($notification_topics, $notification_posts) as $topic) { |
|
| 2567 | + $task_rows[] = array( |
|
| 2447 | 2568 | '$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array( |
| 2448 | 2569 | 'msgOptions' => array( |
| 2449 | 2570 | 'id' => $topic['msg'], |
@@ -2461,14 +2582,16 @@ discard block |
||
| 2461 | 2582 | 'type' => $topic['new_topic'] ? 'topic' : 'reply', |
| 2462 | 2583 | )), 0 |
| 2463 | 2584 | ); |
| 2585 | + } |
|
| 2464 | 2586 | |
| 2465 | - if ($notify) |
|
| 2466 | - $smcFunc['db_insert']('', |
|
| 2587 | + if ($notify) { |
|
| 2588 | + $smcFunc['db_insert']('', |
|
| 2467 | 2589 | '{db_prefix}background_tasks', |
| 2468 | 2590 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 2469 | 2591 | $task_rows, |
| 2470 | 2592 | array('id_task') |
| 2471 | 2593 | ); |
| 2594 | + } |
|
| 2472 | 2595 | |
| 2473 | 2596 | $smcFunc['db_query']('', ' |
| 2474 | 2597 | DELETE FROM {db_prefix}approval_queue |
@@ -2484,8 +2607,9 @@ discard block |
||
| 2484 | 2607 | else |
| 2485 | 2608 | { |
| 2486 | 2609 | $msgInserts = array(); |
| 2487 | - foreach ($msgs as $msg) |
|
| 2488 | - $msgInserts[] = array($msg); |
|
| 2610 | + foreach ($msgs as $msg) { |
|
| 2611 | + $msgInserts[] = array($msg); |
|
| 2612 | + } |
|
| 2489 | 2613 | |
| 2490 | 2614 | $smcFunc['db_insert']('ignore', |
| 2491 | 2615 | '{db_prefix}approval_queue', |
@@ -2499,9 +2623,10 @@ discard block |
||
| 2499 | 2623 | updateLastMessages(array_keys($board_changes)); |
| 2500 | 2624 | |
| 2501 | 2625 | // Post count for the members? |
| 2502 | - if (!empty($member_post_changes)) |
|
| 2503 | - foreach ($member_post_changes as $id_member => $count_change) |
|
| 2626 | + if (!empty($member_post_changes)) { |
|
| 2627 | + foreach ($member_post_changes as $id_member => $count_change) |
|
| 2504 | 2628 | updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change)); |
| 2629 | + } |
|
| 2505 | 2630 | |
| 2506 | 2631 | return true; |
| 2507 | 2632 | } |
@@ -2518,11 +2643,13 @@ discard block |
||
| 2518 | 2643 | { |
| 2519 | 2644 | global $smcFunc; |
| 2520 | 2645 | |
| 2521 | - if (!is_array($topics)) |
|
| 2522 | - $topics = array($topics); |
|
| 2646 | + if (!is_array($topics)) { |
|
| 2647 | + $topics = array($topics); |
|
| 2648 | + } |
|
| 2523 | 2649 | |
| 2524 | - if (empty($topics)) |
|
| 2525 | - return false; |
|
| 2650 | + if (empty($topics)) { |
|
| 2651 | + return false; |
|
| 2652 | + } |
|
| 2526 | 2653 | |
| 2527 | 2654 | $approve_type = $approve ? 0 : 1; |
| 2528 | 2655 | |
@@ -2538,8 +2665,9 @@ discard block |
||
| 2538 | 2665 | ) |
| 2539 | 2666 | ); |
| 2540 | 2667 | $msgs = array(); |
| 2541 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2542 | - $msgs[] = $row['id_msg']; |
|
| 2668 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2669 | + $msgs[] = $row['id_msg']; |
|
| 2670 | + } |
|
| 2543 | 2671 | $smcFunc['db_free_result']($request); |
| 2544 | 2672 | |
| 2545 | 2673 | return approvePosts($msgs, $approve); |
@@ -2562,11 +2690,13 @@ discard block |
||
| 2562 | 2690 | global $board_info, $board, $smcFunc; |
| 2563 | 2691 | |
| 2564 | 2692 | // Please - let's be sane. |
| 2565 | - if (empty($setboards)) |
|
| 2566 | - return false; |
|
| 2693 | + if (empty($setboards)) { |
|
| 2694 | + return false; |
|
| 2695 | + } |
|
| 2567 | 2696 | |
| 2568 | - if (!is_array($setboards)) |
|
| 2569 | - $setboards = array($setboards); |
|
| 2697 | + if (!is_array($setboards)) { |
|
| 2698 | + $setboards = array($setboards); |
|
| 2699 | + } |
|
| 2570 | 2700 | |
| 2571 | 2701 | // If we don't know the id_msg we need to find it. |
| 2572 | 2702 | if (!$id_msg) |
@@ -2584,15 +2714,16 @@ discard block |
||
| 2584 | 2714 | ) |
| 2585 | 2715 | ); |
| 2586 | 2716 | $lastMsg = array(); |
| 2587 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2588 | - $lastMsg[$row['id_board']] = $row['id_msg']; |
|
| 2717 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2718 | + $lastMsg[$row['id_board']] = $row['id_msg']; |
|
| 2719 | + } |
|
| 2589 | 2720 | $smcFunc['db_free_result']($request); |
| 2590 | - } |
|
| 2591 | - else |
|
| 2721 | + } else |
|
| 2592 | 2722 | { |
| 2593 | 2723 | // Just to note - there should only be one board passed if we are doing this. |
| 2594 | - foreach ($setboards as $id_board) |
|
| 2595 | - $lastMsg[$id_board] = $id_msg; |
|
| 2724 | + foreach ($setboards as $id_board) { |
|
| 2725 | + $lastMsg[$id_board] = $id_msg; |
|
| 2726 | + } |
|
| 2596 | 2727 | } |
| 2597 | 2728 | |
| 2598 | 2729 | $parent_boards = array(); |
@@ -2607,10 +2738,11 @@ discard block |
||
| 2607 | 2738 | $lastModified[$id_board] = 0; |
| 2608 | 2739 | } |
| 2609 | 2740 | |
| 2610 | - if (!empty($board) && $id_board == $board) |
|
| 2611 | - $parents = $board_info['parent_boards']; |
|
| 2612 | - else |
|
| 2613 | - $parents = getBoardParents($id_board); |
|
| 2741 | + if (!empty($board) && $id_board == $board) { |
|
| 2742 | + $parents = $board_info['parent_boards']; |
|
| 2743 | + } else { |
|
| 2744 | + $parents = getBoardParents($id_board); |
|
| 2745 | + } |
|
| 2614 | 2746 | |
| 2615 | 2747 | // Ignore any parents on the top child level. |
| 2616 | 2748 | // @todo Why? |
@@ -2619,10 +2751,11 @@ discard block |
||
| 2619 | 2751 | if ($parent['level'] != 0) |
| 2620 | 2752 | { |
| 2621 | 2753 | // If we're already doing this one as a board, is this a higher last modified? |
| 2622 | - if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) |
|
| 2623 | - $lastModified[$id] = $lastModified[$id_board]; |
|
| 2624 | - elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) |
|
| 2625 | - $parent_boards[$id] = $lastModified[$id_board]; |
|
| 2754 | + if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) { |
|
| 2755 | + $lastModified[$id] = $lastModified[$id_board]; |
|
| 2756 | + } elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) { |
|
| 2757 | + $parent_boards[$id] = $lastModified[$id_board]; |
|
| 2758 | + } |
|
| 2626 | 2759 | } |
| 2627 | 2760 | } |
| 2628 | 2761 | } |
@@ -2635,23 +2768,24 @@ discard block |
||
| 2635 | 2768 | // Finally, to save on queries make the changes... |
| 2636 | 2769 | foreach ($parent_boards as $id => $msg) |
| 2637 | 2770 | { |
| 2638 | - if (!isset($parent_updates[$msg])) |
|
| 2639 | - $parent_updates[$msg] = array($id); |
|
| 2640 | - else |
|
| 2641 | - $parent_updates[$msg][] = $id; |
|
| 2771 | + if (!isset($parent_updates[$msg])) { |
|
| 2772 | + $parent_updates[$msg] = array($id); |
|
| 2773 | + } else { |
|
| 2774 | + $parent_updates[$msg][] = $id; |
|
| 2775 | + } |
|
| 2642 | 2776 | } |
| 2643 | 2777 | |
| 2644 | 2778 | foreach ($lastMsg as $id => $msg) |
| 2645 | 2779 | { |
| 2646 | - if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) |
|
| 2647 | - $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
| 2780 | + if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) { |
|
| 2781 | + $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
| 2648 | 2782 | 'id' => $msg, |
| 2649 | 2783 | 'updated' => $lastModified[$id], |
| 2650 | 2784 | 'boards' => array($id) |
| 2651 | 2785 | ); |
| 2652 | - |
|
| 2653 | - else |
|
| 2654 | - $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
| 2786 | + } else { |
|
| 2787 | + $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
| 2788 | + } |
|
| 2655 | 2789 | } |
| 2656 | 2790 | |
| 2657 | 2791 | // Now commit the changes! |
@@ -2743,11 +2877,13 @@ discard block |
||
| 2743 | 2877 | global $txt, $mbname, $scripturl, $settings; |
| 2744 | 2878 | |
| 2745 | 2879 | // First things first, load up the email templates language file, if we need to. |
| 2746 | - if ($loadLang) |
|
| 2747 | - loadLanguage('EmailTemplates', $lang); |
|
| 2880 | + if ($loadLang) { |
|
| 2881 | + loadLanguage('EmailTemplates', $lang); |
|
| 2882 | + } |
|
| 2748 | 2883 | |
| 2749 | - if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) |
|
| 2750 | - fatal_lang_error('email_no_template', 'template', array($template)); |
|
| 2884 | + if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) { |
|
| 2885 | + fatal_lang_error('email_no_template', 'template', array($template)); |
|
| 2886 | + } |
|
| 2751 | 2887 | |
| 2752 | 2888 | $ret = array( |
| 2753 | 2889 | 'subject' => $txt[$template . '_subject'], |
@@ -2797,17 +2933,18 @@ discard block |
||
| 2797 | 2933 | function user_info_callback($matches) |
| 2798 | 2934 | { |
| 2799 | 2935 | global $user_info; |
| 2800 | - if (empty($matches[1])) |
|
| 2801 | - return ''; |
|
| 2936 | + if (empty($matches[1])) { |
|
| 2937 | + return ''; |
|
| 2938 | + } |
|
| 2802 | 2939 | |
| 2803 | 2940 | $use_ref = true; |
| 2804 | 2941 | $ref = &$user_info; |
| 2805 | 2942 | |
| 2806 | 2943 | foreach (explode('.', $matches[1]) as $index) |
| 2807 | 2944 | { |
| 2808 | - if ($use_ref && isset($ref[$index])) |
|
| 2809 | - $ref = &$ref[$index]; |
|
| 2810 | - else |
|
| 2945 | + if ($use_ref && isset($ref[$index])) { |
|
| 2946 | + $ref = &$ref[$index]; |
|
| 2947 | + } else |
|
| 2811 | 2948 | { |
| 2812 | 2949 | $use_ref = false; |
| 2813 | 2950 | break; |
@@ -2844,8 +2981,7 @@ discard block |
||
| 2844 | 2981 | if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale)) |
| 2845 | 2982 | { |
| 2846 | 2983 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale); |
| 2847 | - } |
|
| 2848 | - elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
| 2984 | + } elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
| 2849 | 2985 | { |
| 2850 | 2986 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']); |
| 2851 | 2987 | } |
@@ -2855,8 +2991,7 @@ discard block |
||
| 2855 | 2991 | { |
| 2856 | 2992 | $context['provider'] = 'enchant'; |
| 2857 | 2993 | return $enchant_link; |
| 2858 | - } |
|
| 2859 | - else |
|
| 2994 | + } else |
|
| 2860 | 2995 | { |
| 2861 | 2996 | // Free up any resources used... |
| 2862 | 2997 | @enchant_broker_free($context['enchant_broker']); |
@@ -2877,8 +3012,9 @@ discard block |
||
| 2877 | 3012 | $pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER); |
| 2878 | 3013 | |
| 2879 | 3014 | // Most people don't have anything but English installed... So we use English as a last resort. |
| 2880 | - if (!$pspell_link) |
|
| 2881 | - $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
| 3015 | + if (!$pspell_link) { |
|
| 3016 | + $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
| 3017 | + } |
|
| 2882 | 3018 | |
| 2883 | 3019 | error_reporting($old); |
| 2884 | 3020 | ob_end_clean(); |
@@ -2918,8 +3054,7 @@ discard block |
||
| 2918 | 3054 | $word = iconv($txt['lang_character_set'], 'UTF-8', $word); |
| 2919 | 3055 | } |
| 2920 | 3056 | return enchant_dict_check($dict, $word); |
| 2921 | - } |
|
| 2922 | - elseif ($context['provider'] == 'pspell') |
|
| 3057 | + } elseif ($context['provider'] == 'pspell') |
|
| 2923 | 3058 | { |
| 2924 | 3059 | return pspell_check($dict, $word); |
| 2925 | 3060 | } |
@@ -2955,13 +3090,11 @@ discard block |
||
| 2955 | 3090 | } |
| 2956 | 3091 | |
| 2957 | 3092 | return $suggestions; |
| 2958 | - } |
|
| 2959 | - else |
|
| 3093 | + } else |
|
| 2960 | 3094 | { |
| 2961 | 3095 | return enchant_dict_suggest($dict, $word); |
| 2962 | 3096 | } |
| 2963 | - } |
|
| 2964 | - elseif ($context['provider'] == 'pspell') |
|
| 3097 | + } elseif ($context['provider'] == 'pspell') |
|
| 2965 | 3098 | { |
| 2966 | 3099 | return pspell_suggest($dict, $word); |
| 2967 | 3100 | } |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Class xmlArray |
@@ -65,8 +66,9 @@ discard block |
||
| 65 | 66 | } |
| 66 | 67 | |
| 67 | 68 | // Is the input an array? (ie. passed from file()?) |
| 68 | - if (is_array($data)) |
|
| 69 | - $data = implode('', $data); |
|
| 69 | + if (is_array($data)) { |
|
| 70 | + $data = implode('', $data); |
|
| 71 | + } |
|
| 70 | 72 | |
| 71 | 73 | // Remove any xml declaration or doctype, and parse out comments and CDATA. |
| 72 | 74 | $data = preg_replace('/<!--.*?-->/s', '', $this->_to_cdata(preg_replace(array('/^<\?xml.+?\?' . '>/is', '/<!DOCTYPE[^>]+?' . '>/s'), '', $data))); |
@@ -101,8 +103,9 @@ discard block |
||
| 101 | 103 | // Get the element, in array form. |
| 102 | 104 | $array = $this->path($path); |
| 103 | 105 | |
| 104 | - if ($array === false) |
|
| 105 | - return false; |
|
| 106 | + if ($array === false) { |
|
| 107 | + return false; |
|
| 108 | + } |
|
| 106 | 109 | |
| 107 | 110 | // Getting elements into this is a bit complicated... |
| 108 | 111 | if ($get_elements && !is_string($array)) |
@@ -113,8 +116,9 @@ discard block |
||
| 113 | 116 | foreach ($array->array as $val) |
| 114 | 117 | { |
| 115 | 118 | // Skip the name and any attributes. |
| 116 | - if (is_array($val)) |
|
| 117 | - $temp .= $this->_xml($val, null); |
|
| 119 | + if (is_array($val)) { |
|
| 120 | + $temp .= $this->_xml($val, null); |
|
| 121 | + } |
|
| 118 | 122 | } |
| 119 | 123 | |
| 120 | 124 | // Just get the XML data and then take out the CDATAs. |
@@ -156,32 +160,35 @@ discard block |
||
| 156 | 160 | elseif (substr($el, 0, 1) == '@') |
| 157 | 161 | { |
| 158 | 162 | // It simplifies things if the attribute is already there ;). |
| 159 | - if (isset($array[$el])) |
|
| 160 | - return $array[$el]; |
|
| 161 | - else |
|
| 163 | + if (isset($array[$el])) { |
|
| 164 | + return $array[$el]; |
|
| 165 | + } else |
|
| 162 | 166 | { |
| 163 | 167 | $trace = debug_backtrace(); |
| 164 | 168 | $i = 0; |
| 165 | - while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) |
|
| 166 | - $i++; |
|
| 169 | + while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) { |
|
| 170 | + $i++; |
|
| 171 | + } |
|
| 167 | 172 | $debug = ' (from ' . $trace[$i - 1]['file'] . ' on line ' . $trace[$i - 1]['line'] . ')'; |
| 168 | 173 | |
| 169 | 174 | // Cause an error. |
| 170 | - if ($this->debug_level & E_NOTICE) |
|
| 171 | - trigger_error('Undefined XML attribute: ' . substr($el, 1) . $debug, E_USER_NOTICE); |
|
| 175 | + if ($this->debug_level & E_NOTICE) { |
|
| 176 | + trigger_error('Undefined XML attribute: ' . substr($el, 1) . $debug, E_USER_NOTICE); |
|
| 177 | + } |
|
| 172 | 178 | return false; |
| 173 | 179 | } |
| 180 | + } else { |
|
| 181 | + $lvl = null; |
|
| 174 | 182 | } |
| 175 | - else |
|
| 176 | - $lvl = null; |
|
| 177 | 183 | |
| 178 | 184 | // Find this element. |
| 179 | 185 | $array = $this->_path($array, $el, $lvl); |
| 180 | 186 | } |
| 181 | 187 | |
| 182 | 188 | // Clean up after $lvl, for $return_full. |
| 183 | - if ($return_full && (!isset($array['name']) || substr($array['name'], -1) != ']')) |
|
| 184 | - $array = array('name' => $el . '[]', $array); |
|
| 189 | + if ($return_full && (!isset($array['name']) || substr($array['name'], -1) != ']')) { |
|
| 190 | + $array = array('name' => $el . '[]', $array); |
|
| 191 | + } |
|
| 185 | 192 | |
| 186 | 193 | // Create the right type of class... |
| 187 | 194 | $newClass = get_class($this); |
@@ -216,10 +223,11 @@ discard block |
||
| 216 | 223 | $el = substr($el, 0, strpos($el, '[')); |
| 217 | 224 | } |
| 218 | 225 | // Find an attribute. |
| 219 | - elseif (substr($el, 0, 1) == '@') |
|
| 220 | - return isset($array[$el]); |
|
| 221 | - else |
|
| 222 | - $lvl = null; |
|
| 226 | + elseif (substr($el, 0, 1) == '@') { |
|
| 227 | + return isset($array[$el]); |
|
| 228 | + } else { |
|
| 229 | + $lvl = null; |
|
| 230 | + } |
|
| 223 | 231 | |
| 224 | 232 | // Find this element. |
| 225 | 233 | $array = $this->_path($array, $el, $lvl, true); |
@@ -244,8 +252,9 @@ discard block |
||
| 244 | 252 | $i = 0; |
| 245 | 253 | foreach ($temp->array as $item) |
| 246 | 254 | { |
| 247 | - if (is_array($item)) |
|
| 248 | - $i++; |
|
| 255 | + if (is_array($item)) { |
|
| 256 | + $i++; |
|
| 257 | + } |
|
| 249 | 258 | } |
| 250 | 259 | |
| 251 | 260 | return $i; |
@@ -269,8 +278,9 @@ discard block |
||
| 269 | 278 | foreach ($xml->array as $val) |
| 270 | 279 | { |
| 271 | 280 | // Skip these, they aren't elements. |
| 272 | - if (!is_array($val) || $val['name'] == '!') |
|
| 273 | - continue; |
|
| 281 | + if (!is_array($val) || $val['name'] == '!') { |
|
| 282 | + continue; |
|
| 283 | + } |
|
| 274 | 284 | |
| 275 | 285 | // Create the right type of class... |
| 276 | 286 | $newClass = get_class($this); |
@@ -297,14 +307,16 @@ discard block |
||
| 297 | 307 | $path = $this->path($path); |
| 298 | 308 | |
| 299 | 309 | // The path was not found |
| 300 | - if ($path === false) |
|
| 301 | - return false; |
|
| 310 | + if ($path === false) { |
|
| 311 | + return false; |
|
| 312 | + } |
|
| 302 | 313 | |
| 303 | 314 | $path = $path->array; |
| 304 | 315 | } |
| 305 | 316 | // Just use the current array. |
| 306 | - else |
|
| 307 | - $path = $this->array; |
|
| 317 | + else { |
|
| 318 | + $path = $this->array; |
|
| 319 | + } |
|
| 308 | 320 | |
| 309 | 321 | // Add the xml declaration to the front. |
| 310 | 322 | return '<?xml version="1.0"?' . '>' . $this->_xml($path, 0); |
@@ -326,14 +338,16 @@ discard block |
||
| 326 | 338 | $path = $this->path($path); |
| 327 | 339 | |
| 328 | 340 | // The path was not found |
| 329 | - if ($path === false) |
|
| 330 | - return false; |
|
| 341 | + if ($path === false) { |
|
| 342 | + return false; |
|
| 343 | + } |
|
| 331 | 344 | |
| 332 | 345 | $path = $path->array; |
| 333 | 346 | } |
| 334 | 347 | // No, so just use the current array. |
| 335 | - else |
|
| 336 | - $path = $this->array; |
|
| 348 | + else { |
|
| 349 | + $path = $this->array; |
|
| 350 | + } |
|
| 337 | 351 | |
| 338 | 352 | return $this->_array($path); |
| 339 | 353 | } |
@@ -355,8 +369,9 @@ discard block |
||
| 355 | 369 | { |
| 356 | 370 | // Find and remove the next tag. |
| 357 | 371 | preg_match('/\A<([\w\-:]+)((?:\s+.+?)?)([\s]?\/)?' . '>/', $data, $match); |
| 358 | - if (isset($match[0])) |
|
| 359 | - $data = preg_replace('/' . preg_quote($match[0], '/') . '/s', '', $data, 1); |
|
| 372 | + if (isset($match[0])) { |
|
| 373 | + $data = preg_replace('/' . preg_quote($match[0], '/') . '/s', '', $data, 1); |
|
| 374 | + } |
|
| 360 | 375 | |
| 361 | 376 | // Didn't find a tag? Keep looping.... |
| 362 | 377 | if (!isset($match[1]) || $match[1] == '') |
@@ -367,11 +382,12 @@ discard block |
||
| 367 | 382 | $text_value = $this->_from_cdata($data); |
| 368 | 383 | $data = ''; |
| 369 | 384 | |
| 370 | - if ($text_value != '') |
|
| 371 | - $current[] = array( |
|
| 385 | + if ($text_value != '') { |
|
| 386 | + $current[] = array( |
|
| 372 | 387 | 'name' => '!', |
| 373 | 388 | 'value' => $text_value |
| 374 | 389 | ); |
| 390 | + } |
|
| 375 | 391 | } |
| 376 | 392 | // If the < isn't immediately next to the current position... more data. |
| 377 | 393 | elseif (strpos($data, '<') > 0) |
@@ -379,11 +395,12 @@ discard block |
||
| 379 | 395 | $text_value = $this->_from_cdata(substr($data, 0, strpos($data, '<'))); |
| 380 | 396 | $data = substr($data, strpos($data, '<')); |
| 381 | 397 | |
| 382 | - if ($text_value != '') |
|
| 383 | - $current[] = array( |
|
| 398 | + if ($text_value != '') { |
|
| 399 | + $current[] = array( |
|
| 384 | 400 | 'name' => '!', |
| 385 | 401 | 'value' => $text_value |
| 386 | 402 | ); |
| 403 | + } |
|
| 387 | 404 | } |
| 388 | 405 | // If we're looking at a </something> with no start, kill it. |
| 389 | 406 | elseif (strpos($data, '<') !== false && strpos($data, '<') == 0) |
@@ -393,22 +410,23 @@ discard block |
||
| 393 | 410 | $text_value = $this->_from_cdata(substr($data, 0, strpos($data, '<', 1))); |
| 394 | 411 | $data = substr($data, strpos($data, '<', 1)); |
| 395 | 412 | |
| 396 | - if ($text_value != '') |
|
| 397 | - $current[] = array( |
|
| 413 | + if ($text_value != '') { |
|
| 414 | + $current[] = array( |
|
| 398 | 415 | 'name' => '!', |
| 399 | 416 | 'value' => $text_value |
| 400 | 417 | ); |
| 401 | - } |
|
| 402 | - else |
|
| 418 | + } |
|
| 419 | + } else |
|
| 403 | 420 | { |
| 404 | 421 | $text_value = $this->_from_cdata($data); |
| 405 | 422 | $data = ''; |
| 406 | 423 | |
| 407 | - if ($text_value != '') |
|
| 408 | - $current[] = array( |
|
| 424 | + if ($text_value != '') { |
|
| 425 | + $current[] = array( |
|
| 409 | 426 | 'name' => '!', |
| 410 | 427 | 'value' => $text_value |
| 411 | 428 | ); |
| 429 | + } |
|
| 412 | 430 | } |
| 413 | 431 | } |
| 414 | 432 | |
@@ -425,8 +443,9 @@ discard block |
||
| 425 | 443 | { |
| 426 | 444 | // Because PHP 5.2.0+ seems to croak using regex, we'll have to do this the less fun way. |
| 427 | 445 | $last_tag_end = strpos($data, '</' . $match[1]. '>'); |
| 428 | - if ($last_tag_end === false) |
|
| 429 | - continue; |
|
| 446 | + if ($last_tag_end === false) { |
|
| 447 | + continue; |
|
| 448 | + } |
|
| 430 | 449 | |
| 431 | 450 | $offset = 0; |
| 432 | 451 | while (1 == 1) |
@@ -434,16 +453,17 @@ discard block |
||
| 434 | 453 | // Where is the next start tag? |
| 435 | 454 | $next_tag_start = strpos($data, '<' . $match[1], $offset); |
| 436 | 455 | // If the next start tag is after the last end tag then we've found the right close. |
| 437 | - if ($next_tag_start === false || $next_tag_start > $last_tag_end) |
|
| 438 | - break; |
|
| 456 | + if ($next_tag_start === false || $next_tag_start > $last_tag_end) { |
|
| 457 | + break; |
|
| 458 | + } |
|
| 439 | 459 | |
| 440 | 460 | // If not then find the next ending tag. |
| 441 | 461 | $next_tag_end = strpos($data, '</' . $match[1]. '>', $offset); |
| 442 | 462 | |
| 443 | 463 | // Didn't find one? Then just use the last and sod it. |
| 444 | - if ($next_tag_end === false) |
|
| 445 | - break; |
|
| 446 | - else |
|
| 464 | + if ($next_tag_end === false) { |
|
| 465 | + break; |
|
| 466 | + } else |
|
| 447 | 467 | { |
| 448 | 468 | $last_tag_end = $next_tag_end; |
| 449 | 469 | $offset = $next_tag_start + 1; |
@@ -457,16 +477,17 @@ discard block |
||
| 457 | 477 | if (!empty($inner_match)) |
| 458 | 478 | { |
| 459 | 479 | // Parse the inner data. |
| 460 | - if (strpos($inner_match, '<') !== false) |
|
| 461 | - $el += $this->_parse($inner_match); |
|
| 462 | - elseif (trim($inner_match) != '') |
|
| 480 | + if (strpos($inner_match, '<') !== false) { |
|
| 481 | + $el += $this->_parse($inner_match); |
|
| 482 | + } elseif (trim($inner_match) != '') |
|
| 463 | 483 | { |
| 464 | 484 | $text_value = $this->_from_cdata($inner_match); |
| 465 | - if ($text_value != '') |
|
| 466 | - $el[] = array( |
|
| 485 | + if ($text_value != '') { |
|
| 486 | + $el[] = array( |
|
| 467 | 487 | 'name' => '!', |
| 468 | 488 | 'value' => $text_value |
| 469 | 489 | ); |
| 490 | + } |
|
| 470 | 491 | } |
| 471 | 492 | } |
| 472 | 493 | } |
@@ -478,8 +499,9 @@ discard block |
||
| 478 | 499 | preg_match_all('/([\w:]+)="(.+?)"/', $match[2], $attr, PREG_SET_ORDER); |
| 479 | 500 | |
| 480 | 501 | // Set them as @attribute-name. |
| 481 | - foreach ($attr as $match_attr) |
|
| 482 | - $el['@' . $match_attr[1]] = $match_attr[2]; |
|
| 502 | + foreach ($attr as $match_attr) { |
|
| 503 | + $el['@' . $match_attr[1]] = $match_attr[2]; |
|
| 504 | + } |
|
| 483 | 505 | } |
| 484 | 506 | } |
| 485 | 507 | |
@@ -503,16 +525,18 @@ discard block |
||
| 503 | 525 | if (is_array($array) && !isset($array['name'])) |
| 504 | 526 | { |
| 505 | 527 | $temp = ''; |
| 506 | - foreach ($array as $val) |
|
| 507 | - $temp .= $this->_xml($val, $indent); |
|
| 528 | + foreach ($array as $val) { |
|
| 529 | + $temp .= $this->_xml($val, $indent); |
|
| 530 | + } |
|
| 508 | 531 | return $temp; |
| 509 | 532 | } |
| 510 | 533 | |
| 511 | 534 | // This is just text! |
| 512 | - if ($array['name'] == '!') |
|
| 513 | - return $indentation . '<![CDATA[' . $array['value'] . ']]>'; |
|
| 514 | - elseif (substr($array['name'], -2) == '[]') |
|
| 515 | - $array['name'] = substr($array['name'], 0, -2); |
|
| 535 | + if ($array['name'] == '!') { |
|
| 536 | + return $indentation . '<![CDATA[' . $array['value'] . ']]>'; |
|
| 537 | + } elseif (substr($array['name'], -2) == '[]') { |
|
| 538 | + $array['name'] = substr($array['name'], 0, -2); |
|
| 539 | + } |
|
| 516 | 540 | |
| 517 | 541 | // Start the element. |
| 518 | 542 | $output = $indentation . '<' . $array['name']; |
@@ -523,9 +547,9 @@ discard block |
||
| 523 | 547 | // Run through and recursively output all the elements or attrbutes inside this. |
| 524 | 548 | foreach ($array as $k => $v) |
| 525 | 549 | { |
| 526 | - if (substr($k, 0, 1) == '@') |
|
| 527 | - $output .= ' ' . substr($k, 1) . '="' . $v . '"'; |
|
| 528 | - elseif (is_array($v)) |
|
| 550 | + if (substr($k, 0, 1) == '@') { |
|
| 551 | + $output .= ' ' . substr($k, 1) . '="' . $v . '"'; |
|
| 552 | + } elseif (is_array($v)) |
|
| 529 | 553 | { |
| 530 | 554 | $output_el .= $this->_xml($v, $indent === null ? null : $indent + 1); |
| 531 | 555 | $inside_elements = true; |
@@ -533,10 +557,11 @@ discard block |
||
| 533 | 557 | } |
| 534 | 558 | |
| 535 | 559 | // Indent, if necessary.... then close the tag. |
| 536 | - if ($inside_elements) |
|
| 537 | - $output .= '>' . $output_el . $indentation . '</' . $array['name'] . '>'; |
|
| 538 | - else |
|
| 539 | - $output .= ' />'; |
|
| 560 | + if ($inside_elements) { |
|
| 561 | + $output .= '>' . $output_el . $indentation . '</' . $array['name'] . '>'; |
|
| 562 | + } else { |
|
| 563 | + $output .= ' />'; |
|
| 564 | + } |
|
| 540 | 565 | |
| 541 | 566 | return $output; |
| 542 | 567 | } |
@@ -553,19 +578,22 @@ discard block |
||
| 553 | 578 | $text = ''; |
| 554 | 579 | foreach ($array as $value) |
| 555 | 580 | { |
| 556 | - if (!is_array($value) || !isset($value['name'])) |
|
| 557 | - continue; |
|
| 581 | + if (!is_array($value) || !isset($value['name'])) { |
|
| 582 | + continue; |
|
| 583 | + } |
|
| 558 | 584 | |
| 559 | - if ($value['name'] == '!') |
|
| 560 | - $text .= $value['value']; |
|
| 561 | - else |
|
| 562 | - $return[$value['name']] = $this->_array($value); |
|
| 585 | + if ($value['name'] == '!') { |
|
| 586 | + $text .= $value['value']; |
|
| 587 | + } else { |
|
| 588 | + $return[$value['name']] = $this->_array($value); |
|
| 589 | + } |
|
| 563 | 590 | } |
| 564 | 591 | |
| 565 | - if (empty($return)) |
|
| 566 | - return $text; |
|
| 567 | - else |
|
| 568 | - return $return; |
|
| 592 | + if (empty($return)) { |
|
| 593 | + return $text; |
|
| 594 | + } else { |
|
| 595 | + return $return; |
|
| 596 | + } |
|
| 569 | 597 | } |
| 570 | 598 | |
| 571 | 599 | /** |
@@ -583,24 +611,28 @@ discard block |
||
| 583 | 611 | foreach ($parts as $part) |
| 584 | 612 | { |
| 585 | 613 | // Handle XML comments. |
| 586 | - if (!$inCdata && $part === '<!--') |
|
| 587 | - $inComment = true; |
|
| 588 | - if ($inComment && $part === '-->') |
|
| 589 | - $inComment = false; |
|
| 590 | - elseif ($inComment) |
|
| 591 | - continue; |
|
| 614 | + if (!$inCdata && $part === '<!--') { |
|
| 615 | + $inComment = true; |
|
| 616 | + } |
|
| 617 | + if ($inComment && $part === '-->') { |
|
| 618 | + $inComment = false; |
|
| 619 | + } elseif ($inComment) { |
|
| 620 | + continue; |
|
| 621 | + } |
|
| 592 | 622 | |
| 593 | 623 | // Handle Cdata blocks. |
| 594 | - elseif (!$inComment && $part === '<![CDATA[') |
|
| 595 | - $inCdata = true; |
|
| 596 | - elseif ($inCdata && $part === ']]>') |
|
| 597 | - $inCdata = false; |
|
| 598 | - elseif ($inCdata) |
|
| 599 | - $output .= htmlentities($part, ENT_QUOTES); |
|
| 624 | + elseif (!$inComment && $part === '<![CDATA[') { |
|
| 625 | + $inCdata = true; |
|
| 626 | + } elseif ($inCdata && $part === ']]>') { |
|
| 627 | + $inCdata = false; |
|
| 628 | + } elseif ($inCdata) { |
|
| 629 | + $output .= htmlentities($part, ENT_QUOTES); |
|
| 630 | + } |
|
| 600 | 631 | |
| 601 | 632 | // Everything else is kept as is. |
| 602 | - else |
|
| 603 | - $output .= $part; |
|
| 633 | + else { |
|
| 634 | + $output .= $part; |
|
| 635 | + } |
|
| 604 | 636 | } |
| 605 | 637 | |
| 606 | 638 | return $output; |
@@ -635,22 +667,26 @@ discard block |
||
| 635 | 667 | protected function _fetch($array) |
| 636 | 668 | { |
| 637 | 669 | // Don't return anything if this is just a string. |
| 638 | - if (is_string($array)) |
|
| 639 | - return ''; |
|
| 670 | + if (is_string($array)) { |
|
| 671 | + return ''; |
|
| 672 | + } |
|
| 640 | 673 | |
| 641 | 674 | $temp = ''; |
| 642 | 675 | foreach ($array as $text) |
| 643 | 676 | { |
| 644 | 677 | // This means it's most likely an attribute or the name itself. |
| 645 | - if (!isset($text['name'])) |
|
| 646 | - continue; |
|
| 678 | + if (!isset($text['name'])) { |
|
| 679 | + continue; |
|
| 680 | + } |
|
| 647 | 681 | |
| 648 | 682 | // This is text! |
| 649 | - if ($text['name'] == '!') |
|
| 650 | - $temp .= $text['value']; |
|
| 683 | + if ($text['name'] == '!') { |
|
| 684 | + $temp .= $text['value']; |
|
| 685 | + } |
|
| 651 | 686 | // Another element - dive in ;). |
| 652 | - else |
|
| 653 | - $temp .= $this->_fetch($text); |
|
| 687 | + else { |
|
| 688 | + $temp .= $this->_fetch($text); |
|
| 689 | + } |
|
| 654 | 690 | } |
| 655 | 691 | |
| 656 | 692 | // Return all the bits and pieces we've put together. |
@@ -669,12 +705,14 @@ discard block |
||
| 669 | 705 | protected function _path($array, $path, $level, $no_error = false) |
| 670 | 706 | { |
| 671 | 707 | // Is $array even an array? It might be false! |
| 672 | - if (!is_array($array)) |
|
| 673 | - return false; |
|
| 708 | + if (!is_array($array)) { |
|
| 709 | + return false; |
|
| 710 | + } |
|
| 674 | 711 | |
| 675 | 712 | // Asking for *no* path? |
| 676 | - if ($path == '' || $path == '.') |
|
| 677 | - return $array; |
|
| 713 | + if ($path == '' || $path == '.') { |
|
| 714 | + return $array; |
|
| 715 | + } |
|
| 678 | 716 | $paths = explode('|', $path); |
| 679 | 717 | |
| 680 | 718 | // A * means all elements of any name. |
@@ -685,16 +723,18 @@ discard block |
||
| 685 | 723 | // Check each element. |
| 686 | 724 | foreach ($array as $value) |
| 687 | 725 | { |
| 688 | - if (!is_array($value) || $value['name'] === '!') |
|
| 689 | - continue; |
|
| 726 | + if (!is_array($value) || $value['name'] === '!') { |
|
| 727 | + continue; |
|
| 728 | + } |
|
| 690 | 729 | |
| 691 | 730 | if ($show_all || in_array($value['name'], $paths)) |
| 692 | 731 | { |
| 693 | 732 | // Skip elements before "the one". |
| 694 | - if ($level !== null && $level > 0) |
|
| 695 | - $level--; |
|
| 696 | - else |
|
| 697 | - $results[] = $value; |
|
| 733 | + if ($level !== null && $level > 0) { |
|
| 734 | + $level--; |
|
| 735 | + } else { |
|
| 736 | + $results[] = $value; |
|
| 737 | + } |
|
| 698 | 738 | } |
| 699 | 739 | } |
| 700 | 740 | |
@@ -703,21 +743,25 @@ discard block |
||
| 703 | 743 | { |
| 704 | 744 | $trace = debug_backtrace(); |
| 705 | 745 | $i = 0; |
| 706 | - while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) |
|
| 707 | - $i++; |
|
| 746 | + while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) { |
|
| 747 | + $i++; |
|
| 748 | + } |
|
| 708 | 749 | $debug = ' from ' . $trace[$i - 1]['file'] . ' on line ' . $trace[$i - 1]['line']; |
| 709 | 750 | |
| 710 | 751 | // Cause an error. |
| 711 | - if ($this->debug_level & E_NOTICE && !$no_error) |
|
| 712 | - trigger_error('Undefined XML element: ' . $path . $debug, E_USER_NOTICE); |
|
| 752 | + if ($this->debug_level & E_NOTICE && !$no_error) { |
|
| 753 | + trigger_error('Undefined XML element: ' . $path . $debug, E_USER_NOTICE); |
|
| 754 | + } |
|
| 713 | 755 | return false; |
| 714 | 756 | } |
| 715 | 757 | // Only one result. |
| 716 | - elseif (count($results) == 1 || $level !== null) |
|
| 717 | - return $results[0]; |
|
| 758 | + elseif (count($results) == 1 || $level !== null) { |
|
| 759 | + return $results[0]; |
|
| 760 | + } |
|
| 718 | 761 | // Return the result set. |
| 719 | - else |
|
| 720 | - return $results + array('name' => $path . '[]'); |
|
| 762 | + else { |
|
| 763 | + return $results + array('name' => $path . '[]'); |
|
| 764 | + } |
|
| 721 | 765 | } |
| 722 | 766 | } |
| 723 | 767 | |
@@ -764,8 +808,9 @@ discard block |
||
| 764 | 808 | $this->error = false; |
| 765 | 809 | $this->pasv = array(); |
| 766 | 810 | |
| 767 | - if ($ftp_server !== null) |
|
| 768 | - $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass); |
|
| 811 | + if ($ftp_server !== null) { |
|
| 812 | + $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass); |
|
| 813 | + } |
|
| 769 | 814 | } |
| 770 | 815 | |
| 771 | 816 | /** |
@@ -778,14 +823,16 @@ discard block |
||
| 778 | 823 | */ |
| 779 | 824 | public function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = '[email protected]') |
| 780 | 825 | { |
| 781 | - if (strpos($ftp_server, 'ftp://') === 0) |
|
| 782 | - $ftp_server = substr($ftp_server, 6); |
|
| 783 | - elseif (strpos($ftp_server, 'ftps://') === 0) |
|
| 784 | - $ftp_server = 'ssl://' . substr($ftp_server, 7); |
|
| 785 | - if (strpos($ftp_server, 'http://') === 0) |
|
| 786 | - $ftp_server = substr($ftp_server, 7); |
|
| 787 | - elseif (strpos($ftp_server, 'https://') === 0) |
|
| 788 | - $ftp_server = substr($ftp_server, 8); |
|
| 826 | + if (strpos($ftp_server, 'ftp://') === 0) { |
|
| 827 | + $ftp_server = substr($ftp_server, 6); |
|
| 828 | + } elseif (strpos($ftp_server, 'ftps://') === 0) { |
|
| 829 | + $ftp_server = 'ssl://' . substr($ftp_server, 7); |
|
| 830 | + } |
|
| 831 | + if (strpos($ftp_server, 'http://') === 0) { |
|
| 832 | + $ftp_server = substr($ftp_server, 7); |
|
| 833 | + } elseif (strpos($ftp_server, 'https://') === 0) { |
|
| 834 | + $ftp_server = substr($ftp_server, 8); |
|
| 835 | + } |
|
| 789 | 836 | $ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => '')); |
| 790 | 837 | |
| 791 | 838 | // Connect to the FTP server. |
@@ -834,12 +881,14 @@ discard block |
||
| 834 | 881 | */ |
| 835 | 882 | public function chdir($ftp_path) |
| 836 | 883 | { |
| 837 | - if (!is_resource($this->connection)) |
|
| 838 | - return false; |
|
| 884 | + if (!is_resource($this->connection)) { |
|
| 885 | + return false; |
|
| 886 | + } |
|
| 839 | 887 | |
| 840 | 888 | // No slash on the end, please... |
| 841 | - if ($ftp_path !== '/' && substr($ftp_path, -1) === '/') |
|
| 842 | - $ftp_path = substr($ftp_path, 0, -1); |
|
| 889 | + if ($ftp_path !== '/' && substr($ftp_path, -1) === '/') { |
|
| 890 | + $ftp_path = substr($ftp_path, 0, -1); |
|
| 891 | + } |
|
| 843 | 892 | |
| 844 | 893 | fwrite($this->connection, 'CWD ' . $ftp_path . "\r\n"); |
| 845 | 894 | if (!$this->check_response(250)) |
@@ -860,11 +909,13 @@ discard block |
||
| 860 | 909 | */ |
| 861 | 910 | public function chmod($ftp_file, $chmod) |
| 862 | 911 | { |
| 863 | - if (!is_resource($this->connection)) |
|
| 864 | - return false; |
|
| 912 | + if (!is_resource($this->connection)) { |
|
| 913 | + return false; |
|
| 914 | + } |
|
| 865 | 915 | |
| 866 | - if ($ftp_file == '') |
|
| 867 | - $ftp_file = '.'; |
|
| 916 | + if ($ftp_file == '') { |
|
| 917 | + $ftp_file = '.'; |
|
| 918 | + } |
|
| 868 | 919 | |
| 869 | 920 | // Do we have a file or a dir? |
| 870 | 921 | $is_dir = is_dir($ftp_file); |
@@ -880,9 +931,7 @@ discard block |
||
| 880 | 931 | { |
| 881 | 932 | $is_writable = true; |
| 882 | 933 | break; |
| 883 | - } |
|
| 884 | - |
|
| 885 | - else |
|
| 934 | + } else |
|
| 886 | 935 | { |
| 887 | 936 | // Convert the chmod value from octal (0777) to text ("777"). |
| 888 | 937 | fwrite($this->connection, 'SITE CHMOD ' . decoct($val) . ' ' . $ftp_file . "\r\n"); |
@@ -905,8 +954,9 @@ discard block |
||
| 905 | 954 | public function unlink($ftp_file) |
| 906 | 955 | { |
| 907 | 956 | // We are actually connected, right? |
| 908 | - if (!is_resource($this->connection)) |
|
| 909 | - return false; |
|
| 957 | + if (!is_resource($this->connection)) { |
|
| 958 | + return false; |
|
| 959 | + } |
|
| 910 | 960 | |
| 911 | 961 | // Delete file X. |
| 912 | 962 | fwrite($this->connection, 'DELE ' . $ftp_file . "\r\n"); |
@@ -935,9 +985,9 @@ discard block |
||
| 935 | 985 | { |
| 936 | 986 | // Wait for a response that isn't continued with -, but don't wait too long. |
| 937 | 987 | $time = time(); |
| 938 | - do |
|
| 939 | - $this->last_message = fgets($this->connection, 1024); |
|
| 940 | - while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ', 3) !== 3) && time() - $time < 5); |
|
| 988 | + do { |
|
| 989 | + $this->last_message = fgets($this->connection, 1024); |
|
| 990 | + } while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ', 3) !== 3) && time() - $time < 5); |
|
| 941 | 991 | |
| 942 | 992 | // Was the desired response returned? |
| 943 | 993 | return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired; |
@@ -951,15 +1001,16 @@ discard block |
||
| 951 | 1001 | public function passive() |
| 952 | 1002 | { |
| 953 | 1003 | // We can't create a passive data connection without a primary one first being there. |
| 954 | - if (!is_resource($this->connection)) |
|
| 955 | - return false; |
|
| 1004 | + if (!is_resource($this->connection)) { |
|
| 1005 | + return false; |
|
| 1006 | + } |
|
| 956 | 1007 | |
| 957 | 1008 | // Request a passive connection - this means, we'll talk to you, you don't talk to us. |
| 958 | 1009 | @fwrite($this->connection, 'PASV' . "\r\n"); |
| 959 | 1010 | $time = time(); |
| 960 | - do |
|
| 961 | - $response = fgets($this->connection, 1024); |
|
| 962 | - while (strpos($response, ' ', 3) !== 3 && time() - $time < 5); |
|
| 1011 | + do { |
|
| 1012 | + $response = fgets($this->connection, 1024); |
|
| 1013 | + } while (strpos($response, ' ', 3) !== 3 && time() - $time < 5); |
|
| 963 | 1014 | |
| 964 | 1015 | // If it's not 227, we weren't given an IP and port, which means it failed. |
| 965 | 1016 | if (strpos($response, '227 ') !== 0) |
@@ -990,12 +1041,14 @@ discard block |
||
| 990 | 1041 | public function create_file($ftp_file) |
| 991 | 1042 | { |
| 992 | 1043 | // First, we have to be connected... very important. |
| 993 | - if (!is_resource($this->connection)) |
|
| 994 | - return false; |
|
| 1044 | + if (!is_resource($this->connection)) { |
|
| 1045 | + return false; |
|
| 1046 | + } |
|
| 995 | 1047 | |
| 996 | 1048 | // I'd like one passive mode, please! |
| 997 | - if (!$this->passive()) |
|
| 998 | - return false; |
|
| 1049 | + if (!$this->passive()) { |
|
| 1050 | + return false; |
|
| 1051 | + } |
|
| 999 | 1052 | |
| 1000 | 1053 | // Seems logical enough, so far... |
| 1001 | 1054 | fwrite($this->connection, 'STOR ' . $ftp_file . "\r\n"); |
@@ -1030,12 +1083,14 @@ discard block |
||
| 1030 | 1083 | public function list_dir($ftp_path = '', $search = false) |
| 1031 | 1084 | { |
| 1032 | 1085 | // Are we even connected...? |
| 1033 | - if (!is_resource($this->connection)) |
|
| 1034 | - return false; |
|
| 1086 | + if (!is_resource($this->connection)) { |
|
| 1087 | + return false; |
|
| 1088 | + } |
|
| 1035 | 1089 | |
| 1036 | 1090 | // Passive... non-agressive... |
| 1037 | - if (!$this->passive()) |
|
| 1038 | - return false; |
|
| 1091 | + if (!$this->passive()) { |
|
| 1092 | + return false; |
|
| 1093 | + } |
|
| 1039 | 1094 | |
| 1040 | 1095 | // Get the listing! |
| 1041 | 1096 | fwrite($this->connection, 'LIST -1' . ($search ? 'R' : '') . ($ftp_path == '' ? '' : ' ' . $ftp_path) . "\r\n"); |
@@ -1051,8 +1106,9 @@ discard block |
||
| 1051 | 1106 | |
| 1052 | 1107 | // Read in the file listing. |
| 1053 | 1108 | $data = ''; |
| 1054 | - while (!feof($fp)) |
|
| 1055 | - $data .= fread($fp, 4096); |
|
| 1109 | + while (!feof($fp)) { |
|
| 1110 | + $data .= fread($fp, 4096); |
|
| 1111 | + } |
|
| 1056 | 1112 | fclose($fp); |
| 1057 | 1113 | |
| 1058 | 1114 | // Everything go okay? |
@@ -1074,21 +1130,23 @@ discard block |
||
| 1074 | 1130 | */ |
| 1075 | 1131 | public function locate($file, $listing = null) |
| 1076 | 1132 | { |
| 1077 | - if ($listing === null) |
|
| 1078 | - $listing = $this->list_dir('', true); |
|
| 1133 | + if ($listing === null) { |
|
| 1134 | + $listing = $this->list_dir('', true); |
|
| 1135 | + } |
|
| 1079 | 1136 | $listing = explode("\n", $listing); |
| 1080 | 1137 | |
| 1081 | 1138 | @fwrite($this->connection, 'PWD' . "\r\n"); |
| 1082 | 1139 | $time = time(); |
| 1083 | - do |
|
| 1084 | - $response = fgets($this->connection, 1024); |
|
| 1085 | - while ($response[3] != ' ' && time() - $time < 5); |
|
| 1140 | + do { |
|
| 1141 | + $response = fgets($this->connection, 1024); |
|
| 1142 | + } while ($response[3] != ' ' && time() - $time < 5); |
|
| 1086 | 1143 | |
| 1087 | 1144 | // Check for 257! |
| 1088 | - if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0) |
|
| 1089 | - $current_dir = strtr($match[1], array('""' => '"')); |
|
| 1090 | - else |
|
| 1091 | - $current_dir = ''; |
|
| 1145 | + if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0) { |
|
| 1146 | + $current_dir = strtr($match[1], array('""' => '"')); |
|
| 1147 | + } else { |
|
| 1148 | + $current_dir = ''; |
|
| 1149 | + } |
|
| 1092 | 1150 | |
| 1093 | 1151 | for ($i = 0, $n = count($listing); $i < $n; $i++) |
| 1094 | 1152 | { |
@@ -1101,12 +1159,15 @@ discard block |
||
| 1101 | 1159 | // Okay, this file's name is: |
| 1102 | 1160 | $listing[$i] = $current_dir . '/' . trim(strlen($listing[$i]) > 30 ? strrchr($listing[$i], ' ') : $listing[$i]); |
| 1103 | 1161 | |
| 1104 | - if ($file[0] == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1)) |
|
| 1105 | - return $listing[$i]; |
|
| 1106 | - if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1)) |
|
| 1107 | - return $listing[$i]; |
|
| 1108 | - if (basename($listing[$i]) == $file || $listing[$i] == $file) |
|
| 1109 | - return $listing[$i]; |
|
| 1162 | + if ($file[0] == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1)) { |
|
| 1163 | + return $listing[$i]; |
|
| 1164 | + } |
|
| 1165 | + if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1)) { |
|
| 1166 | + return $listing[$i]; |
|
| 1167 | + } |
|
| 1168 | + if (basename($listing[$i]) == $file || $listing[$i] == $file) { |
|
| 1169 | + return $listing[$i]; |
|
| 1170 | + } |
|
| 1110 | 1171 | } |
| 1111 | 1172 | |
| 1112 | 1173 | return false; |
@@ -1121,8 +1182,9 @@ discard block |
||
| 1121 | 1182 | public function create_dir($ftp_dir) |
| 1122 | 1183 | { |
| 1123 | 1184 | // We must be connected to the server to do something. |
| 1124 | - if (!is_resource($this->connection)) |
|
| 1125 | - return false; |
|
| 1185 | + if (!is_resource($this->connection)) { |
|
| 1186 | + return false; |
|
| 1187 | + } |
|
| 1126 | 1188 | |
| 1127 | 1189 | // Make this new beautiful directory! |
| 1128 | 1190 | fwrite($this->connection, 'MKD ' . $ftp_dir . "\r\n"); |
@@ -1154,35 +1216,40 @@ discard block |
||
| 1154 | 1216 | |
| 1155 | 1217 | $path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => '')); |
| 1156 | 1218 | |
| 1157 | - if (substr($path, -1) == '/') |
|
| 1158 | - $path = substr($path, 0, -1); |
|
| 1219 | + if (substr($path, -1) == '/') { |
|
| 1220 | + $path = substr($path, 0, -1); |
|
| 1221 | + } |
|
| 1159 | 1222 | |
| 1160 | - if (strlen(dirname($_SERVER['PHP_SELF'])) > 1) |
|
| 1161 | - $path .= dirname($_SERVER['PHP_SELF']); |
|
| 1223 | + if (strlen(dirname($_SERVER['PHP_SELF'])) > 1) { |
|
| 1224 | + $path .= dirname($_SERVER['PHP_SELF']); |
|
| 1225 | + } |
|
| 1226 | + } elseif (strpos($filesystem_path, '/var/www/') === 0) { |
|
| 1227 | + $path = substr($filesystem_path, 8); |
|
| 1228 | + } else { |
|
| 1229 | + $path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => '')); |
|
| 1162 | 1230 | } |
| 1163 | - elseif (strpos($filesystem_path, '/var/www/') === 0) |
|
| 1164 | - $path = substr($filesystem_path, 8); |
|
| 1165 | - else |
|
| 1166 | - $path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => '')); |
|
| 1231 | + } else { |
|
| 1232 | + $path = ''; |
|
| 1167 | 1233 | } |
| 1168 | - else |
|
| 1169 | - $path = ''; |
|
| 1170 | 1234 | |
| 1171 | 1235 | if (is_resource($this->connection) && $this->list_dir($path) == '') |
| 1172 | 1236 | { |
| 1173 | 1237 | $data = $this->list_dir('', true); |
| 1174 | 1238 | |
| 1175 | - if ($lookup_file === null) |
|
| 1176 | - $lookup_file = $_SERVER['PHP_SELF']; |
|
| 1239 | + if ($lookup_file === null) { |
|
| 1240 | + $lookup_file = $_SERVER['PHP_SELF']; |
|
| 1241 | + } |
|
| 1177 | 1242 | |
| 1178 | 1243 | $found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data)); |
| 1179 | - if ($found_path == false) |
|
| 1180 | - $found_path = dirname($this->locate(basename($lookup_file))); |
|
| 1181 | - if ($found_path != false) |
|
| 1182 | - $path = $found_path; |
|
| 1244 | + if ($found_path == false) { |
|
| 1245 | + $found_path = dirname($this->locate(basename($lookup_file))); |
|
| 1246 | + } |
|
| 1247 | + if ($found_path != false) { |
|
| 1248 | + $path = $found_path; |
|
| 1249 | + } |
|
| 1250 | + } elseif (is_resource($this->connection)) { |
|
| 1251 | + $found_path = true; |
|
| 1183 | 1252 | } |
| 1184 | - elseif (is_resource($this->connection)) |
|
| 1185 | - $found_path = true; |
|
| 1186 | 1253 | |
| 1187 | 1254 | return array($username, $path, isset($found_path)); |
| 1188 | 1255 | } |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * Original module by Mach8 - We'll never forget you. |
| 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 | * splits a topic into two topics. |
@@ -30,15 +31,17 @@ discard block |
||
| 30 | 31 | global $topic, $sourcedir; |
| 31 | 32 | |
| 32 | 33 | // And... which topic were you splitting, again? |
| 33 | - if (empty($topic)) |
|
| 34 | - fatal_lang_error('numbers_one_to_nine', false); |
|
| 34 | + if (empty($topic)) { |
|
| 35 | + fatal_lang_error('numbers_one_to_nine', false); |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | // Are you allowed to split topics? |
| 37 | 39 | isAllowedTo('split_any'); |
| 38 | 40 | |
| 39 | 41 | // Load up the "dependencies" - the template, getMsgMemberID(), and sendNotifications(). |
| 40 | - if (!isset($_REQUEST['xml'])) |
|
| 41 | - loadTemplate('SplitTopics'); |
|
| 42 | + if (!isset($_REQUEST['xml'])) { |
|
| 43 | + loadTemplate('SplitTopics'); |
|
| 44 | + } |
|
| 42 | 45 | require_once($sourcedir . '/Subs-Boards.php'); |
| 43 | 46 | require_once($sourcedir . '/Subs-Post.php'); |
| 44 | 47 | |
@@ -50,12 +53,12 @@ discard block |
||
| 50 | 53 | ); |
| 51 | 54 | |
| 52 | 55 | // ?action=splittopics;sa=LETSBREAKIT won't work, sorry. |
| 53 | - if (empty($_REQUEST['sa']) || !isset($subActions[$_REQUEST['sa']])) |
|
| 54 | - SplitIndex(); |
|
| 55 | - |
|
| 56 | - else |
|
| 57 | - call_helper($subActions[$_REQUEST['sa']]); |
|
| 58 | -} |
|
| 56 | + if (empty($_REQUEST['sa']) || !isset($subActions[$_REQUEST['sa']])) { |
|
| 57 | + SplitIndex(); |
|
| 58 | + } else { |
|
| 59 | + call_helper($subActions[$_REQUEST['sa']]); |
|
| 60 | + } |
|
| 61 | + } |
|
| 59 | 62 | |
| 60 | 63 | /** |
| 61 | 64 | * screen shown before the actual split. |
@@ -71,8 +74,9 @@ discard block |
||
| 71 | 74 | global $txt, $topic, $context, $smcFunc, $modSettings; |
| 72 | 75 | |
| 73 | 76 | // Validate "at". |
| 74 | - if (empty($_GET['at'])) |
|
| 75 | - fatal_lang_error('numbers_one_to_nine', false); |
|
| 77 | + if (empty($_GET['at'])) { |
|
| 78 | + fatal_lang_error('numbers_one_to_nine', false); |
|
| 79 | + } |
|
| 76 | 80 | $_GET['at'] = (int) $_GET['at']; |
| 77 | 81 | |
| 78 | 82 | // Retrieve the subject and stuff of the specific topic/message. |
@@ -89,26 +93,31 @@ discard block |
||
| 89 | 93 | 'split_at' => $_GET['at'], |
| 90 | 94 | ) |
| 91 | 95 | ); |
| 92 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 93 | - fatal_lang_error('cant_find_messages'); |
|
| 96 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 97 | + fatal_lang_error('cant_find_messages'); |
|
| 98 | + } |
|
| 94 | 99 | list ($_REQUEST['subname'], $num_replies, $unapproved_posts, $id_first_msg, $approved) = $smcFunc['db_fetch_row']($request); |
| 95 | 100 | $smcFunc['db_free_result']($request); |
| 96 | 101 | |
| 97 | 102 | // If not approved validate they can see it. |
| 98 | - if ($modSettings['postmod_active'] && !$approved) |
|
| 99 | - isAllowedTo('approve_posts'); |
|
| 103 | + if ($modSettings['postmod_active'] && !$approved) { |
|
| 104 | + isAllowedTo('approve_posts'); |
|
| 105 | + } |
|
| 100 | 106 | |
| 101 | 107 | // If this topic has unapproved posts, we need to count them too... |
| 102 | - if ($modSettings['postmod_active'] && allowedTo('approve_posts')) |
|
| 103 | - $num_replies += $unapproved_posts - ($approved ? 0 : 1); |
|
| 108 | + if ($modSettings['postmod_active'] && allowedTo('approve_posts')) { |
|
| 109 | + $num_replies += $unapproved_posts - ($approved ? 0 : 1); |
|
| 110 | + } |
|
| 104 | 111 | |
| 105 | 112 | // Check if there is more than one message in the topic. (there should be.) |
| 106 | - if ($num_replies < 1) |
|
| 107 | - fatal_lang_error('topic_one_post', false); |
|
| 113 | + if ($num_replies < 1) { |
|
| 114 | + fatal_lang_error('topic_one_post', false); |
|
| 115 | + } |
|
| 108 | 116 | |
| 109 | 117 | // Check if this is the first message in the topic (if so, the first and second option won't be available) |
| 110 | - if ($id_first_msg == $_GET['at']) |
|
| 111 | - return SplitSelectTopics(); |
|
| 118 | + if ($id_first_msg == $_GET['at']) { |
|
| 119 | + return SplitSelectTopics(); |
|
| 120 | + } |
|
| 112 | 121 | |
| 113 | 122 | // Basic template information.... |
| 114 | 123 | $context['message'] = array( |
@@ -137,8 +146,9 @@ discard block |
||
| 137 | 146 | checkSession(); |
| 138 | 147 | |
| 139 | 148 | // Clean up the subject. |
| 140 | - if (!isset($_POST['subname']) || $_POST['subname'] == '') |
|
| 141 | - $_POST['subname'] = $txt['new_topic']; |
|
| 149 | + if (!isset($_POST['subname']) || $_POST['subname'] == '') { |
|
| 150 | + $_POST['subname'] = $txt['new_topic']; |
|
| 151 | + } |
|
| 142 | 152 | |
| 143 | 153 | // Redirect to the selector if they chose selective. |
| 144 | 154 | if ($_POST['step2'] == 'selective') |
@@ -163,16 +173,19 @@ discard block |
||
| 163 | 173 | 'split_at' => $_POST['at'], |
| 164 | 174 | ) |
| 165 | 175 | ); |
| 166 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 167 | - $messagesToBeSplit[] = $row['id_msg']; |
|
| 176 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 177 | + $messagesToBeSplit[] = $row['id_msg']; |
|
| 178 | + } |
|
| 168 | 179 | $smcFunc['db_free_result']($request); |
| 169 | 180 | } |
| 170 | 181 | // Only the selected message has to be split. That should be easy. |
| 171 | - elseif ($_POST['step2'] == 'onlythis') |
|
| 172 | - $messagesToBeSplit[] = $_POST['at']; |
|
| 182 | + elseif ($_POST['step2'] == 'onlythis') { |
|
| 183 | + $messagesToBeSplit[] = $_POST['at']; |
|
| 184 | + } |
|
| 173 | 185 | // There's another action?! |
| 174 | - else |
|
| 175 | - fatal_lang_error('no_access', false); |
|
| 186 | + else { |
|
| 187 | + fatal_lang_error('no_access', false); |
|
| 188 | + } |
|
| 176 | 189 | |
| 177 | 190 | $context['old_topic'] = $topic; |
| 178 | 191 | $context['new_topic'] = splitTopic($topic, $messagesToBeSplit, $_POST['subname']); |
@@ -199,8 +212,9 @@ discard block |
||
| 199 | 212 | $_SESSION['split_selection'][$topic] = empty($_SESSION['split_selection'][$topic]) ? array() : $_SESSION['split_selection'][$topic]; |
| 200 | 213 | |
| 201 | 214 | // This is a special case for split topics from quick-moderation checkboxes |
| 202 | - if (isset($_REQUEST['subname_enc'])) |
|
| 203 | - $_REQUEST['subname'] = urldecode($_REQUEST['subname_enc']); |
|
| 215 | + if (isset($_REQUEST['subname_enc'])) { |
|
| 216 | + $_REQUEST['subname'] = urldecode($_REQUEST['subname_enc']); |
|
| 217 | + } |
|
| 204 | 218 | |
| 205 | 219 | $context['not_selected'] = array( |
| 206 | 220 | 'num_messages' => 0, |
@@ -252,10 +266,12 @@ discard block |
||
| 252 | 266 | ) |
| 253 | 267 | ); |
| 254 | 268 | // You can't split the last message off. |
| 255 | - if (empty($context['not_selected']['start']) && $smcFunc['db_num_rows']($request) <= 1 && $_REQUEST['move'] == 'down') |
|
| 256 | - $_REQUEST['move'] = ''; |
|
| 257 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 258 | - $original_msgs['not_selected'][] = $row['id_msg']; |
|
| 269 | + if (empty($context['not_selected']['start']) && $smcFunc['db_num_rows']($request) <= 1 && $_REQUEST['move'] == 'down') { |
|
| 270 | + $_REQUEST['move'] = ''; |
|
| 271 | + } |
|
| 272 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 273 | + $original_msgs['not_selected'][] = $row['id_msg']; |
|
| 274 | + } |
|
| 259 | 275 | $smcFunc['db_free_result']($request); |
| 260 | 276 | if (!empty($_SESSION['split_selection'][$topic])) |
| 261 | 277 | { |
@@ -275,8 +291,9 @@ discard block |
||
| 275 | 291 | 'messages_per_page' => $context['messages_per_page'], |
| 276 | 292 | ) |
| 277 | 293 | ); |
| 278 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 279 | - $original_msgs['selected'][] = $row['id_msg']; |
|
| 294 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 295 | + $original_msgs['selected'][] = $row['id_msg']; |
|
| 296 | + } |
|
| 280 | 297 | $smcFunc['db_free_result']($request); |
| 281 | 298 | } |
| 282 | 299 | } |
@@ -286,12 +303,13 @@ discard block |
||
| 286 | 303 | { |
| 287 | 304 | $_REQUEST['msg'] = (int) $_REQUEST['msg']; |
| 288 | 305 | |
| 289 | - if ($_REQUEST['move'] == 'reset') |
|
| 290 | - $_SESSION['split_selection'][$topic] = array(); |
|
| 291 | - elseif ($_REQUEST['move'] == 'up') |
|
| 292 | - $_SESSION['split_selection'][$topic] = array_diff($_SESSION['split_selection'][$topic], array($_REQUEST['msg'])); |
|
| 293 | - else |
|
| 294 | - $_SESSION['split_selection'][$topic][] = $_REQUEST['msg']; |
|
| 306 | + if ($_REQUEST['move'] == 'reset') { |
|
| 307 | + $_SESSION['split_selection'][$topic] = array(); |
|
| 308 | + } elseif ($_REQUEST['move'] == 'up') { |
|
| 309 | + $_SESSION['split_selection'][$topic] = array_diff($_SESSION['split_selection'][$topic], array($_REQUEST['msg'])); |
|
| 310 | + } else { |
|
| 311 | + $_SESSION['split_selection'][$topic][] = $_REQUEST['msg']; |
|
| 312 | + } |
|
| 295 | 313 | } |
| 296 | 314 | |
| 297 | 315 | // Make sure the selection is still accurate. |
@@ -310,8 +328,9 @@ discard block |
||
| 310 | 328 | ) |
| 311 | 329 | ); |
| 312 | 330 | $_SESSION['split_selection'][$topic] = array(); |
| 313 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 314 | - $_SESSION['split_selection'][$topic][] = $row['id_msg']; |
|
| 331 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 332 | + $_SESSION['split_selection'][$topic][] = $row['id_msg']; |
|
| 333 | + } |
|
| 315 | 334 | $smcFunc['db_free_result']($request); |
| 316 | 335 | } |
| 317 | 336 | |
@@ -328,13 +347,15 @@ discard block |
||
| 328 | 347 | 'is_approved' => 1, |
| 329 | 348 | ) |
| 330 | 349 | ); |
| 331 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 332 | - $context[empty($row['is_selected']) || $row['is_selected'] == 'f' ? 'not_selected' : 'selected']['num_messages'] = $row['num_messages']; |
|
| 350 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 351 | + $context[empty($row['is_selected']) || $row['is_selected'] == 'f' ? 'not_selected' : 'selected']['num_messages'] = $row['num_messages']; |
|
| 352 | + } |
|
| 333 | 353 | $smcFunc['db_free_result']($request); |
| 334 | 354 | |
| 335 | 355 | // Fix an oversized starting page (to make sure both pageindexes are properly set). |
| 336 | - if ($context['selected']['start'] >= $context['selected']['num_messages']) |
|
| 337 | - $context['selected']['start'] = $context['selected']['num_messages'] <= $context['messages_per_page'] ? 0 : ($context['selected']['num_messages'] - (($context['selected']['num_messages'] % $context['messages_per_page']) == 0 ? $context['messages_per_page'] : ($context['selected']['num_messages'] % $context['messages_per_page']))); |
|
| 356 | + if ($context['selected']['start'] >= $context['selected']['num_messages']) { |
|
| 357 | + $context['selected']['start'] = $context['selected']['num_messages'] <= $context['messages_per_page'] ? 0 : ($context['selected']['num_messages'] - (($context['selected']['num_messages'] % $context['messages_per_page']) == 0 ? $context['messages_per_page'] : ($context['selected']['num_messages'] % $context['messages_per_page']))); |
|
| 358 | + } |
|
| 338 | 359 | |
| 339 | 360 | // Build a page list of the not-selected topics... |
| 340 | 361 | $context['not_selected']['page_index'] = constructPageIndex($scripturl . '?action=splittopics;sa=selectTopics;subname=' . strtr(urlencode($_REQUEST['subname']), array('%' => '%%')) . ';topic=' . $topic . '.%1$d;start2=' . $context['selected']['start'], $context['not_selected']['start'], $context['not_selected']['num_messages'], $context['messages_per_page'], true); |
@@ -434,11 +455,12 @@ discard block |
||
| 434 | 455 | ); |
| 435 | 456 | |
| 436 | 457 | $context['changes'] = array(); |
| 437 | - foreach ($changes as $change_type => $change_array) |
|
| 438 | - foreach ($change_array as $section => $msg_array) |
|
| 458 | + foreach ($changes as $change_type => $change_array) { |
|
| 459 | + foreach ($change_array as $section => $msg_array) |
|
| 439 | 460 | { |
| 440 | 461 | if (empty($msg_array)) |
| 441 | 462 | continue; |
| 463 | + } |
|
| 442 | 464 | |
| 443 | 465 | foreach ($msg_array as $id_msg) |
| 444 | 466 | { |
@@ -447,8 +469,9 @@ discard block |
||
| 447 | 469 | 'type' => $change_type, |
| 448 | 470 | 'section' => $section, |
| 449 | 471 | ); |
| 450 | - if ($change_type == 'insert') |
|
| 451 | - $context['changes']['insert' . $id_msg]['insert_value'] = $context[$section]['messages'][$id_msg]; |
|
| 472 | + if ($change_type == 'insert') { |
|
| 473 | + $context['changes']['insert' . $id_msg]['insert_value'] = $context[$section]['messages'][$id_msg]; |
|
| 474 | + } |
|
| 452 | 475 | } |
| 453 | 476 | } |
| 454 | 477 | } |
@@ -468,12 +491,14 @@ discard block |
||
| 468 | 491 | checkSession(); |
| 469 | 492 | |
| 470 | 493 | // Default the subject in case it's blank. |
| 471 | - if (!isset($_POST['subname']) || $_POST['subname'] == '') |
|
| 472 | - $_POST['subname'] = $txt['new_topic']; |
|
| 494 | + if (!isset($_POST['subname']) || $_POST['subname'] == '') { |
|
| 495 | + $_POST['subname'] = $txt['new_topic']; |
|
| 496 | + } |
|
| 473 | 497 | |
| 474 | 498 | // You must've selected some messages! Can't split out none! |
| 475 | - if (empty($_SESSION['split_selection'][$topic])) |
|
| 476 | - fatal_lang_error('no_posts_selected', false); |
|
| 499 | + if (empty($_SESSION['split_selection'][$topic])) { |
|
| 500 | + fatal_lang_error('no_posts_selected', false); |
|
| 501 | + } |
|
| 477 | 502 | |
| 478 | 503 | $context['old_topic'] = $topic; |
| 479 | 504 | $context['new_topic'] = splitTopic($topic, $_SESSION['split_selection'][$topic], $_POST['subname']); |
@@ -499,8 +524,9 @@ discard block |
||
| 499 | 524 | global $smcFunc, $txt, $sourcedir; |
| 500 | 525 | |
| 501 | 526 | // Nothing to split? |
| 502 | - if (empty($splitMessages)) |
|
| 503 | - fatal_lang_error('no_posts_selected', false); |
|
| 527 | + if (empty($splitMessages)) { |
|
| 528 | + fatal_lang_error('no_posts_selected', false); |
|
| 529 | + } |
|
| 504 | 530 | |
| 505 | 531 | // Get some board info. |
| 506 | 532 | $request = $smcFunc['db_query']('', ' |
@@ -532,8 +558,9 @@ discard block |
||
| 532 | 558 | ) |
| 533 | 559 | ); |
| 534 | 560 | // You can't select ALL the messages! |
| 535 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 536 | - fatal_lang_error('selected_all_posts', false); |
|
| 561 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 562 | + fatal_lang_error('selected_all_posts', false); |
|
| 563 | + } |
|
| 537 | 564 | |
| 538 | 565 | $split1_first_msg = null; |
| 539 | 566 | $split1_last_msg = null; |
@@ -541,24 +568,27 @@ discard block |
||
| 541 | 568 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 542 | 569 | { |
| 543 | 570 | // Get the right first and last message dependant on approved state... |
| 544 | - if (empty($split1_first_msg) || $row['myid_first_msg'] < $split1_first_msg) |
|
| 545 | - $split1_first_msg = $row['myid_first_msg']; |
|
| 546 | - if (empty($split1_last_msg) || $row['approved']) |
|
| 547 | - $split1_last_msg = $row['myid_last_msg']; |
|
| 571 | + if (empty($split1_first_msg) || $row['myid_first_msg'] < $split1_first_msg) { |
|
| 572 | + $split1_first_msg = $row['myid_first_msg']; |
|
| 573 | + } |
|
| 574 | + if (empty($split1_last_msg) || $row['approved']) { |
|
| 575 | + $split1_last_msg = $row['myid_last_msg']; |
|
| 576 | + } |
|
| 548 | 577 | |
| 549 | 578 | // Get the counts correct... |
| 550 | 579 | if ($row['approved']) |
| 551 | 580 | { |
| 552 | 581 | $split1_replies = $row['message_count'] - 1; |
| 553 | 582 | $split1_unapprovedposts = 0; |
| 554 | - } |
|
| 555 | - else |
|
| 583 | + } else |
|
| 556 | 584 | { |
| 557 | - if (!isset($split1_replies)) |
|
| 558 | - $split1_replies = 0; |
|
| 585 | + if (!isset($split1_replies)) { |
|
| 586 | + $split1_replies = 0; |
|
| 587 | + } |
|
| 559 | 588 | // If the topic isn't approved then num replies must go up by one... as first post wouldn't be counted. |
| 560 | - elseif (!$split1_approved) |
|
| 561 | - $split1_replies++; |
|
| 589 | + elseif (!$split1_approved) { |
|
| 590 | + $split1_replies++; |
|
| 591 | + } |
|
| 562 | 592 | |
| 563 | 593 | $split1_unapprovedposts = $row['message_count']; |
| 564 | 594 | } |
@@ -584,10 +614,12 @@ discard block |
||
| 584 | 614 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 585 | 615 | { |
| 586 | 616 | // As before get the right first and last message dependant on approved state... |
| 587 | - if (empty($split2_first_msg) || $row['myid_first_msg'] < $split2_first_msg) |
|
| 588 | - $split2_first_msg = $row['myid_first_msg']; |
|
| 589 | - if (empty($split2_last_msg) || $row['approved']) |
|
| 590 | - $split2_last_msg = $row['myid_last_msg']; |
|
| 617 | + if (empty($split2_first_msg) || $row['myid_first_msg'] < $split2_first_msg) { |
|
| 618 | + $split2_first_msg = $row['myid_first_msg']; |
|
| 619 | + } |
|
| 620 | + if (empty($split2_last_msg) || $row['approved']) { |
|
| 621 | + $split2_last_msg = $row['myid_last_msg']; |
|
| 622 | + } |
|
| 591 | 623 | |
| 592 | 624 | // Then do the counts again... |
| 593 | 625 | if ($row['approved']) |
@@ -595,18 +627,20 @@ discard block |
||
| 595 | 627 | $split2_approved = true; |
| 596 | 628 | $split2_replies = $row['message_count'] - 1; |
| 597 | 629 | $split2_unapprovedposts = 0; |
| 598 | - } |
|
| 599 | - else |
|
| 630 | + } else |
|
| 600 | 631 | { |
| 601 | 632 | // Should this one be approved?? |
| 602 | - if ($split2_first_msg == $row['myid_first_msg']) |
|
| 603 | - $split2_approved = false; |
|
| 633 | + if ($split2_first_msg == $row['myid_first_msg']) { |
|
| 634 | + $split2_approved = false; |
|
| 635 | + } |
|
| 604 | 636 | |
| 605 | - if (!isset($split2_replies)) |
|
| 606 | - $split2_replies = 0; |
|
| 637 | + if (!isset($split2_replies)) { |
|
| 638 | + $split2_replies = 0; |
|
| 639 | + } |
|
| 607 | 640 | // As before, fix number of replies. |
| 608 | - elseif (!$split2_approved) |
|
| 609 | - $split2_replies++; |
|
| 641 | + elseif (!$split2_approved) { |
|
| 642 | + $split2_replies++; |
|
| 643 | + } |
|
| 610 | 644 | |
| 611 | 645 | $split2_unapprovedposts = $row['message_count']; |
| 612 | 646 | } |
@@ -616,12 +650,14 @@ discard block |
||
| 616 | 650 | $split2_lastMem = getMsgMemberID($split2_last_msg); |
| 617 | 651 | |
| 618 | 652 | // No database changes yet, so let's double check to see if everything makes at least a little sense. |
| 619 | - if ($split1_first_msg <= 0 || $split1_last_msg <= 0 || $split2_first_msg <= 0 || $split2_last_msg <= 0 || $split1_replies < 0 || $split2_replies < 0 || $split1_unapprovedposts < 0 || $split2_unapprovedposts < 0 || !isset($split1_approved) || !isset($split2_approved)) |
|
| 620 | - fatal_lang_error('cant_find_messages'); |
|
| 653 | + if ($split1_first_msg <= 0 || $split1_last_msg <= 0 || $split2_first_msg <= 0 || $split2_last_msg <= 0 || $split1_replies < 0 || $split2_replies < 0 || $split1_unapprovedposts < 0 || $split2_unapprovedposts < 0 || !isset($split1_approved) || !isset($split2_approved)) { |
|
| 654 | + fatal_lang_error('cant_find_messages'); |
|
| 655 | + } |
|
| 621 | 656 | |
| 622 | 657 | // You cannot split off the first message of a topic. |
| 623 | - if ($split1_first_msg > $split2_first_msg) |
|
| 624 | - fatal_lang_error('split_first_post', false); |
|
| 658 | + if ($split1_first_msg > $split2_first_msg) { |
|
| 659 | + fatal_lang_error('split_first_post', false); |
|
| 660 | + } |
|
| 625 | 661 | |
| 626 | 662 | // We're off to insert the new topic! Use 0 for now to avoid UNIQUE errors. |
| 627 | 663 | $smcFunc['db_insert']('', |
@@ -644,14 +680,16 @@ discard block |
||
| 644 | 680 | array('id_topic') |
| 645 | 681 | ); |
| 646 | 682 | $split2_ID_TOPIC = $smcFunc['db_insert_id']('{db_prefix}topics', 'id_topic'); |
| 647 | - if ($split2_ID_TOPIC <= 0) |
|
| 648 | - fatal_lang_error('cant_insert_topic'); |
|
| 683 | + if ($split2_ID_TOPIC <= 0) { |
|
| 684 | + fatal_lang_error('cant_insert_topic'); |
|
| 685 | + } |
|
| 649 | 686 | |
| 650 | 687 | // Move the messages over to the other topic. |
| 651 | 688 | $new_subject = strtr($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($new_subject)), array("\r" => '', "\n" => '', "\t" => '')); |
| 652 | 689 | // Check the subject length. |
| 653 | - if ($smcFunc['strlen']($new_subject) > 100) |
|
| 654 | - $new_subject = $smcFunc['substr']($new_subject, 0, 100); |
|
| 690 | + if ($smcFunc['strlen']($new_subject) > 100) { |
|
| 691 | + $new_subject = $smcFunc['substr']($new_subject, 0, 100); |
|
| 692 | + } |
|
| 655 | 693 | // Valid subject? |
| 656 | 694 | if ($new_subject != '') |
| 657 | 695 | { |
@@ -722,8 +760,8 @@ discard block |
||
| 722 | 760 | ); |
| 723 | 761 | |
| 724 | 762 | // If the new topic isn't approved ensure the first message flags this just in case. |
| 725 | - if (!$split2_approved) |
|
| 726 | - $smcFunc['db_query']('', ' |
|
| 763 | + if (!$split2_approved) { |
|
| 764 | + $smcFunc['db_query']('', ' |
|
| 727 | 765 | UPDATE {db_prefix}messages |
| 728 | 766 | SET approved = {int:approved} |
| 729 | 767 | WHERE id_msg = {int:id_msg} |
@@ -734,6 +772,7 @@ discard block |
||
| 734 | 772 | 'id_topic' => $split2_ID_TOPIC, |
| 735 | 773 | ) |
| 736 | 774 | ); |
| 775 | + } |
|
| 737 | 776 | |
| 738 | 777 | // The board has more topics now (Or more unapproved ones!). |
| 739 | 778 | $smcFunc['db_query']('', ' |
@@ -760,8 +799,9 @@ discard block |
||
| 760 | 799 | if ($smcFunc['db_num_rows']($request) > 0) |
| 761 | 800 | { |
| 762 | 801 | $replaceEntries = array(); |
| 763 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 764 | - $replaceEntries[] = array($row['id_member'], $split2_ID_TOPIC, $row['id_msg'], $row['unwatched']); |
|
| 802 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 803 | + $replaceEntries[] = array($row['id_member'], $split2_ID_TOPIC, $row['id_msg'], $row['unwatched']); |
|
| 804 | + } |
|
| 765 | 805 | |
| 766 | 806 | $smcFunc['db_insert']('ignore', |
| 767 | 807 | '{db_prefix}log_topics', |
@@ -785,8 +825,9 @@ discard block |
||
| 785 | 825 | // If there's a search index that needs updating, update it... |
| 786 | 826 | require_once($sourcedir . '/Search.php'); |
| 787 | 827 | $searchAPI = findSearchAPI(); |
| 788 | - if (is_callable(array($searchAPI, 'topicSplit'))) |
|
| 789 | - $searchAPI->topicSplit($split2_ID_TOPIC, $splitMessages); |
|
| 828 | + if (is_callable(array($searchAPI, 'topicSplit'))) { |
|
| 829 | + $searchAPI->topicSplit($split2_ID_TOPIC, $splitMessages); |
|
| 830 | + } |
|
| 790 | 831 | |
| 791 | 832 | // Return the ID of the newly created topic. |
| 792 | 833 | return $split2_ID_TOPIC; |
@@ -812,12 +853,12 @@ discard block |
||
| 812 | 853 | ); |
| 813 | 854 | |
| 814 | 855 | // ?action=mergetopics;sa=LETSBREAKIT won't work, sorry. |
| 815 | - if (empty($_REQUEST['sa']) || !isset($subActions[$_REQUEST['sa']])) |
|
| 816 | - MergeIndex(); |
|
| 817 | - |
|
| 818 | - else |
|
| 819 | - call_helper($subActions[$_REQUEST['sa']]); |
|
| 820 | -} |
|
| 856 | + if (empty($_REQUEST['sa']) || !isset($subActions[$_REQUEST['sa']])) { |
|
| 857 | + MergeIndex(); |
|
| 858 | + } else { |
|
| 859 | + call_helper($subActions[$_REQUEST['sa']]); |
|
| 860 | + } |
|
| 861 | + } |
|
| 821 | 862 | |
| 822 | 863 | /** |
| 823 | 864 | * allows to pick a topic to merge the current topic with. |
@@ -831,8 +872,9 @@ discard block |
||
| 831 | 872 | global $txt, $board, $context, $smcFunc, $sourcedir; |
| 832 | 873 | global $scripturl, $modSettings; |
| 833 | 874 | |
| 834 | - if (!isset($_GET['from'])) |
|
| 835 | - fatal_lang_error('no_access', false); |
|
| 875 | + if (!isset($_GET['from'])) { |
|
| 876 | + fatal_lang_error('no_access', false); |
|
| 877 | + } |
|
| 836 | 878 | $_GET['from'] = (int) $_GET['from']; |
| 837 | 879 | |
| 838 | 880 | $_REQUEST['targetboard'] = isset($_REQUEST['targetboard']) ? (int) $_REQUEST['targetboard'] : $board; |
@@ -843,9 +885,9 @@ discard block |
||
| 843 | 885 | { |
| 844 | 886 | $can_approve_boards = boardsAllowedTo('approve_posts'); |
| 845 | 887 | $onlyApproved = $can_approve_boards !== array(0) && !in_array($_REQUEST['targetboard'], $can_approve_boards); |
| 888 | + } else { |
|
| 889 | + $onlyApproved = false; |
|
| 846 | 890 | } |
| 847 | - else |
|
| 848 | - $onlyApproved = false; |
|
| 849 | 891 | |
| 850 | 892 | // How many topics are on this board? (used for paging.) |
| 851 | 893 | $request = $smcFunc['db_query']('', ' |
@@ -879,8 +921,9 @@ discard block |
||
| 879 | 921 | 'is_approved' => 1, |
| 880 | 922 | ) |
| 881 | 923 | ); |
| 882 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 883 | - fatal_lang_error('no_board'); |
|
| 924 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 925 | + fatal_lang_error('no_board'); |
|
| 926 | + } |
|
| 884 | 927 | list ($subject) = $smcFunc['db_fetch_row']($request); |
| 885 | 928 | $smcFunc['db_free_result']($request); |
| 886 | 929 | |
@@ -893,8 +936,9 @@ discard block |
||
| 893 | 936 | // Check which boards you have merge permissions on. |
| 894 | 937 | $merge_boards = boardsAllowedTo('merge_any'); |
| 895 | 938 | |
| 896 | - if (empty($merge_boards)) |
|
| 897 | - fatal_lang_error('cannot_merge_any', 'user'); |
|
| 939 | + if (empty($merge_boards)) { |
|
| 940 | + fatal_lang_error('cannot_merge_any', 'user'); |
|
| 941 | + } |
|
| 898 | 942 | |
| 899 | 943 | // No sense in loading this if you can only merge on this board |
| 900 | 944 | if (count($merge_boards) > 1 || in_array(0, $merge_boards)) |
@@ -908,8 +952,9 @@ discard block |
||
| 908 | 952 | ); |
| 909 | 953 | |
| 910 | 954 | // Only include these boards in the list (0 means you're an admin') |
| 911 | - if (!in_array(0, $merge_boards)) |
|
| 912 | - $options['included_boards'] = $merge_boards; |
|
| 955 | + if (!in_array(0, $merge_boards)) { |
|
| 956 | + $options['included_boards'] = $merge_boards; |
|
| 957 | + } |
|
| 913 | 958 | |
| 914 | 959 | $context['merge_categories'] = getBoardList($options); |
| 915 | 960 | } |
@@ -955,8 +1000,9 @@ discard block |
||
| 955 | 1000 | } |
| 956 | 1001 | $smcFunc['db_free_result']($request); |
| 957 | 1002 | |
| 958 | - if (empty($context['topics']) && count($merge_boards) <= 1 && !in_array(0, $merge_boards)) |
|
| 959 | - fatal_lang_error('merge_need_more_topics'); |
|
| 1003 | + if (empty($context['topics']) && count($merge_boards) <= 1 && !in_array(0, $merge_boards)) { |
|
| 1004 | + fatal_lang_error('merge_need_more_topics'); |
|
| 1005 | + } |
|
| 960 | 1006 | |
| 961 | 1007 | $context['sub_template'] = 'merge'; |
| 962 | 1008 | } |
@@ -986,24 +1032,29 @@ discard block |
||
| 986 | 1032 | checkSession('request'); |
| 987 | 1033 | |
| 988 | 1034 | // Handle URLs from MergeIndex. |
| 989 | - if (!empty($_GET['from']) && !empty($_GET['to'])) |
|
| 990 | - $topics = array((int) $_GET['from'], (int) $_GET['to']); |
|
| 1035 | + if (!empty($_GET['from']) && !empty($_GET['to'])) { |
|
| 1036 | + $topics = array((int) $_GET['from'], (int) $_GET['to']); |
|
| 1037 | + } |
|
| 991 | 1038 | |
| 992 | 1039 | // If we came from a form, the topic IDs came by post. |
| 993 | - if (!empty($_POST['topics']) && is_array($_POST['topics'])) |
|
| 994 | - $topics = $_POST['topics']; |
|
| 1040 | + if (!empty($_POST['topics']) && is_array($_POST['topics'])) { |
|
| 1041 | + $topics = $_POST['topics']; |
|
| 1042 | + } |
|
| 995 | 1043 | |
| 996 | 1044 | // There's nothing to merge with just one topic... |
| 997 | - if (empty($topics) || !is_array($topics) || count($topics) == 1) |
|
| 998 | - fatal_lang_error('merge_need_more_topics'); |
|
| 1045 | + if (empty($topics) || !is_array($topics) || count($topics) == 1) { |
|
| 1046 | + fatal_lang_error('merge_need_more_topics'); |
|
| 1047 | + } |
|
| 999 | 1048 | |
| 1000 | 1049 | // Make sure every topic is numeric, or some nasty things could be done with the DB. |
| 1001 | - foreach ($topics as $id => $topic) |
|
| 1002 | - $topics[$id] = (int) $topic; |
|
| 1050 | + foreach ($topics as $id => $topic) { |
|
| 1051 | + $topics[$id] = (int) $topic; |
|
| 1052 | + } |
|
| 1003 | 1053 | |
| 1004 | 1054 | // Joy of all joys, make sure they're not messing about with unapproved topics they can't see :P |
| 1005 | - if ($modSettings['postmod_active']) |
|
| 1006 | - $can_approve_boards = boardsAllowedTo('approve_posts'); |
|
| 1055 | + if ($modSettings['postmod_active']) { |
|
| 1056 | + $can_approve_boards = boardsAllowedTo('approve_posts'); |
|
| 1057 | + } |
|
| 1007 | 1058 | |
| 1008 | 1059 | // Get info about the topics and polls that will be merged. |
| 1009 | 1060 | $request = $smcFunc['db_query']('', ' |
@@ -1024,8 +1075,9 @@ discard block |
||
| 1024 | 1075 | 'limit' => count($topics), |
| 1025 | 1076 | ) |
| 1026 | 1077 | ); |
| 1027 | - if ($smcFunc['db_num_rows']($request) < 2) |
|
| 1028 | - fatal_lang_error('no_topic_id'); |
|
| 1078 | + if ($smcFunc['db_num_rows']($request) < 2) { |
|
| 1079 | + fatal_lang_error('no_topic_id'); |
|
| 1080 | + } |
|
| 1029 | 1081 | $num_views = 0; |
| 1030 | 1082 | $is_sticky = 0; |
| 1031 | 1083 | $boardTotals = array(); |
@@ -1038,34 +1090,38 @@ discard block |
||
| 1038 | 1090 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1039 | 1091 | { |
| 1040 | 1092 | // Sorry, redirection topics can't be merged |
| 1041 | - if (!empty($row['id_redirect_topic'])) |
|
| 1042 | - fatal_lang_error('cannot_merge_redirect', false); |
|
| 1093 | + if (!empty($row['id_redirect_topic'])) { |
|
| 1094 | + fatal_lang_error('cannot_merge_redirect', false); |
|
| 1095 | + } |
|
| 1043 | 1096 | |
| 1044 | 1097 | // Make a note for the board counts... |
| 1045 | - if (!isset($boardTotals[$row['id_board']])) |
|
| 1046 | - $boardTotals[$row['id_board']] = array( |
|
| 1098 | + if (!isset($boardTotals[$row['id_board']])) { |
|
| 1099 | + $boardTotals[$row['id_board']] = array( |
|
| 1047 | 1100 | 'posts' => 0, |
| 1048 | 1101 | 'topics' => 0, |
| 1049 | 1102 | 'unapproved_posts' => 0, |
| 1050 | 1103 | 'unapproved_topics' => 0 |
| 1051 | 1104 | ); |
| 1105 | + } |
|
| 1052 | 1106 | |
| 1053 | 1107 | // We can't see unapproved topics here? |
| 1054 | 1108 | if ($modSettings['postmod_active'] && !$row['approved'] && $can_approve_boards != array(0) && in_array($row['id_board'], $can_approve_boards)) |
| 1055 | 1109 | { |
| 1056 | 1110 | unset($topics[$row['id_topic']]); // If we can't see it, we should not merge it and not adjust counts! Instead skip it. |
| 1057 | 1111 | continue; |
| 1058 | - }elseif (!$row['approved']) |
|
| 1059 | - $boardTotals[$row['id_board']]['unapproved_topics']++; |
|
| 1060 | - else |
|
| 1061 | - $boardTotals[$row['id_board']]['topics']++; |
|
| 1112 | + } elseif (!$row['approved']) { |
|
| 1113 | + $boardTotals[$row['id_board']]['unapproved_topics']++; |
|
| 1114 | + } else { |
|
| 1115 | + $boardTotals[$row['id_board']]['topics']++; |
|
| 1116 | + } |
|
| 1062 | 1117 | |
| 1063 | 1118 | $boardTotals[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts']; |
| 1064 | 1119 | $boardTotals[$row['id_board']]['posts'] += $row['num_replies'] + ($row['approved'] ? 1 : 0); |
| 1065 | 1120 | |
| 1066 | 1121 | // In the case of making a redirect, the topic count goes up by one due to the redirect topic. |
| 1067 | - if (isset($_POST['postRedirect'])) |
|
| 1068 | - $boardTotals[$row['id_board']]['topics']--; |
|
| 1122 | + if (isset($_POST['postRedirect'])) { |
|
| 1123 | + $boardTotals[$row['id_board']]['topics']--; |
|
| 1124 | + } |
|
| 1069 | 1125 | |
| 1070 | 1126 | $topic_data[$row['id_topic']] = array( |
| 1071 | 1127 | 'id' => $row['id_topic'], |
@@ -1091,11 +1147,13 @@ discard block |
||
| 1091 | 1147 | $boards[] = $row['id_board']; |
| 1092 | 1148 | |
| 1093 | 1149 | // If there's no poll, id_poll == 0... |
| 1094 | - if ($row['id_poll'] > 0) |
|
| 1095 | - $polls[] = $row['id_poll']; |
|
| 1150 | + if ($row['id_poll'] > 0) { |
|
| 1151 | + $polls[] = $row['id_poll']; |
|
| 1152 | + } |
|
| 1096 | 1153 | // Store the id_topic with the lowest id_first_msg. |
| 1097 | - if (empty($firstTopic)) |
|
| 1098 | - $firstTopic = $row['id_topic']; |
|
| 1154 | + if (empty($firstTopic)) { |
|
| 1155 | + $firstTopic = $row['id_topic']; |
|
| 1156 | + } |
|
| 1099 | 1157 | |
| 1100 | 1158 | // Lowest topic id gets selected as surviving topic id. We need to store this board so we can adjust the topic count (This one will not have a redirect topic) |
| 1101 | 1159 | if($row['id_topic'] < $lowestTopicId || empty($lowestTopicId) ) |
@@ -1109,11 +1167,13 @@ discard block |
||
| 1109 | 1167 | $smcFunc['db_free_result']($request); |
| 1110 | 1168 | |
| 1111 | 1169 | // If we didn't get any topics then they've been messing with unapproved stuff. |
| 1112 | - if (empty($topic_data)) |
|
| 1113 | - fatal_lang_error('no_topic_id'); |
|
| 1170 | + if (empty($topic_data)) { |
|
| 1171 | + fatal_lang_error('no_topic_id'); |
|
| 1172 | + } |
|
| 1114 | 1173 | |
| 1115 | - if (isset($_POST['postRedirect']) && !empty($lowestTopicBoard)) |
|
| 1116 | - $boardTotals[$lowestTopicBoard]['topics']++; |
|
| 1174 | + if (isset($_POST['postRedirect']) && !empty($lowestTopicBoard)) { |
|
| 1175 | + $boardTotals[$lowestTopicBoard]['topics']++; |
|
| 1176 | + } |
|
| 1117 | 1177 | |
| 1118 | 1178 | // Will this be approved? |
| 1119 | 1179 | $context['is_approved'] = $topic_data[$firstTopic]['approved']; |
@@ -1129,8 +1189,9 @@ discard block |
||
| 1129 | 1189 | |
| 1130 | 1190 | // Get the boards a user is allowed to merge in. |
| 1131 | 1191 | $merge_boards = boardsAllowedTo('merge_any'); |
| 1132 | - if (empty($merge_boards)) |
|
| 1133 | - fatal_lang_error('cannot_merge_any', 'user'); |
|
| 1192 | + if (empty($merge_boards)) { |
|
| 1193 | + fatal_lang_error('cannot_merge_any', 'user'); |
|
| 1194 | + } |
|
| 1134 | 1195 | |
| 1135 | 1196 | // Make sure they can see all boards.... |
| 1136 | 1197 | $request = $smcFunc['db_query']('', ' |
@@ -1147,8 +1208,9 @@ discard block |
||
| 1147 | 1208 | ) |
| 1148 | 1209 | ); |
| 1149 | 1210 | // If the number of boards that's in the output isn't exactly the same as we've put in there, you're in trouble. |
| 1150 | - if ($smcFunc['db_num_rows']($request) != count($boards)) |
|
| 1151 | - fatal_lang_error('no_board'); |
|
| 1211 | + if ($smcFunc['db_num_rows']($request) != count($boards)) { |
|
| 1212 | + fatal_lang_error('no_board'); |
|
| 1213 | + } |
|
| 1152 | 1214 | $smcFunc['db_free_result']($request); |
| 1153 | 1215 | |
| 1154 | 1216 | if (empty($_REQUEST['sa']) || $_REQUEST['sa'] == 'options') |
@@ -1167,8 +1229,8 @@ discard block |
||
| 1167 | 1229 | 'limit' => count($polls), |
| 1168 | 1230 | ) |
| 1169 | 1231 | ); |
| 1170 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1171 | - $context['polls'][] = array( |
|
| 1232 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1233 | + $context['polls'][] = array( |
|
| 1172 | 1234 | 'id' => $row['id_poll'], |
| 1173 | 1235 | 'topic' => array( |
| 1174 | 1236 | 'id' => $row['id_topic'], |
@@ -1177,6 +1239,7 @@ discard block |
||
| 1177 | 1239 | 'question' => $row['question'], |
| 1178 | 1240 | 'selected' => $row['id_topic'] == $firstTopic |
| 1179 | 1241 | ); |
| 1242 | + } |
|
| 1180 | 1243 | $smcFunc['db_free_result']($request); |
| 1181 | 1244 | } |
| 1182 | 1245 | if (count($boards) > 1) |
@@ -1192,18 +1255,20 @@ discard block |
||
| 1192 | 1255 | 'limit' => count($boards), |
| 1193 | 1256 | ) |
| 1194 | 1257 | ); |
| 1195 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1196 | - $context['boards'][] = array( |
|
| 1258 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1259 | + $context['boards'][] = array( |
|
| 1197 | 1260 | 'id' => $row['id_board'], |
| 1198 | 1261 | 'name' => $row['name'], |
| 1199 | 1262 | 'selected' => $row['id_board'] == $topic_data[$firstTopic]['board'] |
| 1200 | 1263 | ); |
| 1264 | + } |
|
| 1201 | 1265 | $smcFunc['db_free_result']($request); |
| 1202 | 1266 | } |
| 1203 | 1267 | |
| 1204 | 1268 | $context['topics'] = $topic_data; |
| 1205 | - foreach ($topic_data as $id => $topic) |
|
| 1206 | - $context['topics'][$id]['selected'] = $topic['id'] == $firstTopic; |
|
| 1269 | + foreach ($topic_data as $id => $topic) { |
|
| 1270 | + $context['topics'][$id]['selected'] = $topic['id'] == $firstTopic; |
|
| 1271 | + } |
|
| 1207 | 1272 | |
| 1208 | 1273 | $context['page_title'] = $txt['merge']; |
| 1209 | 1274 | $context['sub_template'] = 'merge_extra_options'; |
@@ -1212,13 +1277,15 @@ discard block |
||
| 1212 | 1277 | |
| 1213 | 1278 | // Determine target board. |
| 1214 | 1279 | $target_board = count($boards) > 1 ? (int) $_REQUEST['board'] : $boards[0]; |
| 1215 | - if (!in_array($target_board, $boards)) |
|
| 1216 | - fatal_lang_error('no_board'); |
|
| 1280 | + if (!in_array($target_board, $boards)) { |
|
| 1281 | + fatal_lang_error('no_board'); |
|
| 1282 | + } |
|
| 1217 | 1283 | |
| 1218 | 1284 | // Determine which poll will survive and which polls won't. |
| 1219 | 1285 | $target_poll = count($polls) > 1 ? (int) $_POST['poll'] : (count($polls) == 1 ? $polls[0] : 0); |
| 1220 | - if ($target_poll > 0 && !in_array($target_poll, $polls)) |
|
| 1221 | - fatal_lang_error('no_access', false); |
|
| 1286 | + if ($target_poll > 0 && !in_array($target_poll, $polls)) { |
|
| 1287 | + fatal_lang_error('no_access', false); |
|
| 1288 | + } |
|
| 1222 | 1289 | $deleted_polls = empty($target_poll) ? $polls : array_diff($polls, array($target_poll)); |
| 1223 | 1290 | |
| 1224 | 1291 | // Determine the subject of the newly merged topic - was a custom subject specified? |
@@ -1226,19 +1293,23 @@ discard block |
||
| 1226 | 1293 | { |
| 1227 | 1294 | $target_subject = strtr($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['custom_subject'])), array("\r" => '', "\n" => '', "\t" => '')); |
| 1228 | 1295 | // Keep checking the length. |
| 1229 | - if ($smcFunc['strlen']($target_subject) > 100) |
|
| 1230 | - $target_subject = $smcFunc['substr']($target_subject, 0, 100); |
|
| 1296 | + if ($smcFunc['strlen']($target_subject) > 100) { |
|
| 1297 | + $target_subject = $smcFunc['substr']($target_subject, 0, 100); |
|
| 1298 | + } |
|
| 1231 | 1299 | |
| 1232 | 1300 | // Nothing left - odd but pick the first topics subject. |
| 1233 | - if ($target_subject == '') |
|
| 1234 | - $target_subject = $topic_data[$firstTopic]['subject']; |
|
| 1301 | + if ($target_subject == '') { |
|
| 1302 | + $target_subject = $topic_data[$firstTopic]['subject']; |
|
| 1303 | + } |
|
| 1235 | 1304 | } |
| 1236 | 1305 | // A subject was selected from the list. |
| 1237 | - elseif (!empty($topic_data[(int) $_POST['subject']]['subject'])) |
|
| 1238 | - $target_subject = $topic_data[(int) $_POST['subject']]['subject']; |
|
| 1306 | + elseif (!empty($topic_data[(int) $_POST['subject']]['subject'])) { |
|
| 1307 | + $target_subject = $topic_data[(int) $_POST['subject']]['subject']; |
|
| 1308 | + } |
|
| 1239 | 1309 | // Nothing worked? Just take the subject of the first message. |
| 1240 | - else |
|
| 1241 | - $target_subject = $topic_data[$firstTopic]['subject']; |
|
| 1310 | + else { |
|
| 1311 | + $target_subject = $topic_data[$firstTopic]['subject']; |
|
| 1312 | + } |
|
| 1242 | 1313 | |
| 1243 | 1314 | // Get the first and last message and the number of messages.... |
| 1244 | 1315 | $request = $smcFunc['db_query']('', ' |
@@ -1264,15 +1335,13 @@ discard block |
||
| 1264 | 1335 | { |
| 1265 | 1336 | $num_replies = $row['message_count'] - 1; |
| 1266 | 1337 | $num_unapproved = 0; |
| 1267 | - } |
|
| 1268 | - else |
|
| 1338 | + } else |
|
| 1269 | 1339 | { |
| 1270 | 1340 | $topic_approved = 0; |
| 1271 | 1341 | $num_replies = 0; |
| 1272 | 1342 | $num_unapproved = $row['message_count']; |
| 1273 | 1343 | } |
| 1274 | - } |
|
| 1275 | - else |
|
| 1344 | + } else |
|
| 1276 | 1345 | { |
| 1277 | 1346 | // If this has a lower first_msg then the first post is not approved and hence the number of replies was wrong! |
| 1278 | 1347 | if ($first_msg > $row['first_msg']) |
@@ -1318,8 +1387,9 @@ discard block |
||
| 1318 | 1387 | list ($member_started) = $smcFunc['db_fetch_row']($request); |
| 1319 | 1388 | list ($member_updated) = $smcFunc['db_fetch_row']($request); |
| 1320 | 1389 | // First and last message are the same, so only row was returned. |
| 1321 | - if ($member_updated === NULL) |
|
| 1322 | - $member_updated = $member_started; |
|
| 1390 | + if ($member_updated === NULL) { |
|
| 1391 | + $member_updated = $member_started; |
|
| 1392 | + } |
|
| 1323 | 1393 | |
| 1324 | 1394 | $smcFunc['db_free_result']($request); |
| 1325 | 1395 | |
@@ -1332,8 +1402,9 @@ discard block |
||
| 1332 | 1402 | array( |
| 1333 | 1403 | 'topic_list' => $topics, |
| 1334 | 1404 | )); |
| 1335 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 1336 | - $affected_msgs[] = $row[0]; |
|
| 1405 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 1406 | + $affected_msgs[] = $row[0]; |
|
| 1407 | + } |
|
| 1337 | 1408 | $smcFunc['db_free_result']($request); |
| 1338 | 1409 | |
| 1339 | 1410 | // Assign the first topic ID to be the merged topic. |
@@ -1411,9 +1482,9 @@ discard block |
||
| 1411 | 1482 | // Grab the response prefix (like 'Re: ') in the default forum language. |
| 1412 | 1483 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
| 1413 | 1484 | { |
| 1414 | - if ($language === $user_info['language']) |
|
| 1415 | - $context['response_prefix'] = $txt['response_prefix']; |
|
| 1416 | - else |
|
| 1485 | + if ($language === $user_info['language']) { |
|
| 1486 | + $context['response_prefix'] = $txt['response_prefix']; |
|
| 1487 | + } else |
|
| 1417 | 1488 | { |
| 1418 | 1489 | loadLanguage('index', $language, false); |
| 1419 | 1490 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -1493,8 +1564,9 @@ discard block |
||
| 1493 | 1564 | if ($smcFunc['db_num_rows']($request) > 0) |
| 1494 | 1565 | { |
| 1495 | 1566 | $replaceEntries = array(); |
| 1496 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1497 | - $replaceEntries[] = array($row['id_member'], $id_topic, $row['new_id_msg'], $row['unwatched']); |
|
| 1567 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1568 | + $replaceEntries[] = array($row['id_member'], $id_topic, $row['new_id_msg'], $row['unwatched']); |
|
| 1569 | + } |
|
| 1498 | 1570 | |
| 1499 | 1571 | $smcFunc['db_insert']('replace', |
| 1500 | 1572 | '{db_prefix}log_topics', |
@@ -1531,8 +1603,9 @@ discard block |
||
| 1531 | 1603 | if ($smcFunc['db_num_rows']($request) > 0) |
| 1532 | 1604 | { |
| 1533 | 1605 | $replaceEntries = array(); |
| 1534 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1535 | - $replaceEntries[] = array($row['id_member'], $id_topic, 0, $row['sent']); |
|
| 1606 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1607 | + $replaceEntries[] = array($row['id_member'], $id_topic, 0, $row['sent']); |
|
| 1608 | + } |
|
| 1536 | 1609 | |
| 1537 | 1610 | $smcFunc['db_insert']('replace', |
| 1538 | 1611 | '{db_prefix}log_notify', |
@@ -1707,8 +1780,9 @@ discard block |
||
| 1707 | 1780 | // If there's a search index that needs updating, update it... |
| 1708 | 1781 | require_once($sourcedir . '/Search.php'); |
| 1709 | 1782 | $searchAPI = findSearchAPI(); |
| 1710 | - if (is_callable(array($searchAPI, 'topicMerge'))) |
|
| 1711 | - $searchAPI->topicMerge($id_topic, $topics, $affected_msgs, empty($_POST['enforce_subject']) ? null : array($context['response_prefix'], $target_subject)); |
|
| 1783 | + if (is_callable(array($searchAPI, 'topicMerge'))) { |
|
| 1784 | + $searchAPI->topicMerge($id_topic, $topics, $affected_msgs, empty($_POST['enforce_subject']) ? null : array($context['response_prefix'], $target_subject)); |
|
| 1785 | + } |
|
| 1712 | 1786 | |
| 1713 | 1787 | // Send them to the all done page. |
| 1714 | 1788 | redirectexit('action=mergetopics;sa=done;to=' . $id_topic . ';targetboard=' . $target_board); |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * The main dispatcher; doesn't do anything, just delegates. |
@@ -92,18 +93,19 @@ discard block |
||
| 92 | 93 | checkSession('get'); |
| 93 | 94 | validateToken('admin-bm-' . (int) $_REQUEST['src_board'], 'request'); |
| 94 | 95 | |
| 95 | - if ($_REQUEST['move_to'] === 'top') |
|
| 96 | - $boardOptions = array( |
|
| 96 | + if ($_REQUEST['move_to'] === 'top') { |
|
| 97 | + $boardOptions = array( |
|
| 97 | 98 | 'move_to' => $_REQUEST['move_to'], |
| 98 | 99 | 'target_category' => (int) $_REQUEST['target_cat'], |
| 99 | 100 | 'move_first_child' => true, |
| 100 | 101 | ); |
| 101 | - else |
|
| 102 | - $boardOptions = array( |
|
| 102 | + } else { |
|
| 103 | + $boardOptions = array( |
|
| 103 | 104 | 'move_to' => $_REQUEST['move_to'], |
| 104 | 105 | 'target_board' => (int) $_REQUEST['target_board'], |
| 105 | 106 | 'move_first_child' => true, |
| 106 | 107 | ); |
| 108 | + } |
|
| 107 | 109 | modifyBoard((int) $_REQUEST['src_board'], $boardOptions); |
| 108 | 110 | } |
| 109 | 111 | |
@@ -148,15 +150,16 @@ discard block |
||
| 148 | 150 | $security = $context['session_var'] . '=' . $context['session_id'] . ';' . $context['admin-bm-' . $context['move_board'] . '_token_var'] . '=' . $context['admin-bm-' . $context['move_board'] . '_token']; |
| 149 | 151 | foreach ($boardList[$catid] as $boardid) |
| 150 | 152 | { |
| 151 | - if (!isset($context['categories'][$catid]['move_link'])) |
|
| 152 | - $context['categories'][$catid]['move_link'] = array( |
|
| 153 | + if (!isset($context['categories'][$catid]['move_link'])) { |
|
| 154 | + $context['categories'][$catid]['move_link'] = array( |
|
| 153 | 155 | 'child_level' => 0, |
| 154 | 156 | 'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'', |
| 155 | 157 | 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_board=' . $boardid . ';move_to=before;' . $security, |
| 156 | 158 | ); |
| 159 | + } |
|
| 157 | 160 | |
| 158 | - if (!$context['categories'][$catid]['boards'][$boardid]['move']) |
|
| 159 | - $context['categories'][$catid]['boards'][$boardid]['move_links'] = array( |
|
| 161 | + if (!$context['categories'][$catid]['boards'][$boardid]['move']) { |
|
| 162 | + $context['categories'][$catid]['boards'][$boardid]['move_links'] = array( |
|
| 160 | 163 | array( |
| 161 | 164 | 'child_level' => $boards[$boardid]['level'], |
| 162 | 165 | 'label' => $txt['mboards_order_after'] . '\'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'', |
@@ -170,34 +173,39 @@ discard block |
||
| 170 | 173 | 'class' => 'here', |
| 171 | 174 | ), |
| 172 | 175 | ); |
| 176 | + } |
|
| 173 | 177 | |
| 174 | 178 | $difference = $boards[$boardid]['level'] - $prev_child_level; |
| 175 | - if ($difference == 1) |
|
| 176 | - array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null); |
|
| 177 | - elseif ($difference < 0) |
|
| 179 | + if ($difference == 1) { |
|
| 180 | + array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null); |
|
| 181 | + } elseif ($difference < 0) |
|
| 178 | 182 | { |
| 179 | - if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) |
|
| 180 | - $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array(); |
|
| 181 | - for ($i = 0; $i < -$difference; $i++) |
|
| 182 | - if (($temp = array_pop($stack)) != null) |
|
| 183 | + if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) { |
|
| 184 | + $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array(); |
|
| 185 | + } |
|
| 186 | + for ($i = 0; $i < -$difference; $i++) { |
|
| 187 | + if (($temp = array_pop($stack)) != null) |
|
| 183 | 188 | array_unshift($context['categories'][$catid]['boards'][$prev_board]['move_links'], $temp); |
| 189 | + } |
|
| 184 | 190 | } |
| 185 | 191 | |
| 186 | 192 | $prev_board = $boardid; |
| 187 | 193 | $prev_child_level = $boards[$boardid]['level']; |
| 188 | 194 | |
| 189 | 195 | } |
| 190 | - if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) |
|
| 191 | - $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']); |
|
| 192 | - elseif (!empty($stack)) |
|
| 193 | - $context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack; |
|
| 196 | + if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) { |
|
| 197 | + $context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']); |
|
| 198 | + } elseif (!empty($stack)) { |
|
| 199 | + $context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack; |
|
| 200 | + } |
|
| 194 | 201 | |
| 195 | - if (empty($boardList[$catid])) |
|
| 196 | - $context['categories'][$catid]['move_link'] = array( |
|
| 202 | + if (empty($boardList[$catid])) { |
|
| 203 | + $context['categories'][$catid]['move_link'] = array( |
|
| 197 | 204 | 'child_level' => 0, |
| 198 | 205 | 'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($tree['node']['name']) . '\'', |
| 199 | 206 | 'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_cat=' . $catid . ';move_to=top;' . $security, |
| 200 | 207 | ); |
| 208 | + } |
|
| 201 | 209 | } |
| 202 | 210 | } |
| 203 | 211 | |
@@ -253,9 +261,9 @@ discard block |
||
| 253 | 261 | ); |
| 254 | 262 | } |
| 255 | 263 | // Category doesn't exist, man... sorry. |
| 256 | - elseif (!isset($cat_tree[$_REQUEST['cat']])) |
|
| 257 | - redirectexit('action=admin;area=manageboards'); |
|
| 258 | - else |
|
| 264 | + elseif (!isset($cat_tree[$_REQUEST['cat']])) { |
|
| 265 | + redirectexit('action=admin;area=manageboards'); |
|
| 266 | + } else |
|
| 259 | 267 | { |
| 260 | 268 | $context['category'] = array( |
| 261 | 269 | 'id' => $_REQUEST['cat'], |
@@ -267,30 +275,31 @@ discard block |
||
| 267 | 275 | 'is_empty' => empty($cat_tree[$_REQUEST['cat']]['children']) |
| 268 | 276 | ); |
| 269 | 277 | |
| 270 | - foreach ($boardList[$_REQUEST['cat']] as $child_board) |
|
| 271 | - $context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name']; |
|
| 278 | + foreach ($boardList[$_REQUEST['cat']] as $child_board) { |
|
| 279 | + $context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name']; |
|
| 280 | + } |
|
| 272 | 281 | } |
| 273 | 282 | |
| 274 | 283 | $prevCat = 0; |
| 275 | 284 | foreach ($cat_tree as $catid => $tree) |
| 276 | 285 | { |
| 277 | - if ($catid == $_REQUEST['cat'] && $prevCat > 0) |
|
| 278 | - $context['category_order'][$prevCat]['selected'] = true; |
|
| 279 | - elseif ($catid != $_REQUEST['cat']) |
|
| 280 | - $context['category_order'][$catid] = array( |
|
| 286 | + if ($catid == $_REQUEST['cat'] && $prevCat > 0) { |
|
| 287 | + $context['category_order'][$prevCat]['selected'] = true; |
|
| 288 | + } elseif ($catid != $_REQUEST['cat']) { |
|
| 289 | + $context['category_order'][$catid] = array( |
|
| 281 | 290 | 'id' => $catid, |
| 282 | 291 | 'name' => $txt['mboards_order_after'] . $tree['node']['name'], |
| 283 | 292 | 'selected' => false, |
| 284 | 293 | 'true_name' => $tree['node']['name'] |
| 285 | 294 | ); |
| 295 | + } |
|
| 286 | 296 | $prevCat = $catid; |
| 287 | 297 | } |
| 288 | 298 | if (!isset($_REQUEST['delete'])) |
| 289 | 299 | { |
| 290 | 300 | $context['sub_template'] = 'modify_category'; |
| 291 | 301 | $context['page_title'] = $_REQUEST['sa'] == 'newcat' ? $txt['mboards_new_cat_name'] : $txt['catEdit']; |
| 292 | - } |
|
| 293 | - else |
|
| 302 | + } else |
|
| 294 | 303 | { |
| 295 | 304 | $context['sub_template'] = 'confirm_category_delete'; |
| 296 | 305 | $context['page_title'] = $txt['mboards_delete_cat']; |
@@ -327,8 +336,9 @@ discard block |
||
| 327 | 336 | { |
| 328 | 337 | $catOptions = array(); |
| 329 | 338 | |
| 330 | - if (isset($_POST['cat_order'])) |
|
| 331 | - $catOptions['move_after'] = (int) $_POST['cat_order']; |
|
| 339 | + if (isset($_POST['cat_order'])) { |
|
| 340 | + $catOptions['move_after'] = (int) $_POST['cat_order']; |
|
| 341 | + } |
|
| 332 | 342 | |
| 333 | 343 | // Change "This & That" to "This & That" but don't change "¢" to "&cent;"... |
| 334 | 344 | $catOptions['cat_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['cat_name']), false, '', $context['description_allowed_tags']); |
@@ -336,10 +346,11 @@ discard block |
||
| 336 | 346 | |
| 337 | 347 | $catOptions['is_collapsible'] = isset($_POST['collapse']); |
| 338 | 348 | |
| 339 | - if (isset($_POST['add'])) |
|
| 340 | - createCategory($catOptions); |
|
| 341 | - else |
|
| 342 | - modifyCategory($_POST['cat'], $catOptions); |
|
| 349 | + if (isset($_POST['add'])) { |
|
| 350 | + createCategory($catOptions); |
|
| 351 | + } else { |
|
| 352 | + modifyCategory($_POST['cat'], $catOptions); |
|
| 353 | + } |
|
| 343 | 354 | } |
| 344 | 355 | // If they want to delete - first give them confirmation. |
| 345 | 356 | elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['empty'])) |
@@ -353,13 +364,14 @@ discard block |
||
| 353 | 364 | // First off - check if we are moving all the current boards first - before we start deleting! |
| 354 | 365 | if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1) |
| 355 | 366 | { |
| 356 | - if (empty($_POST['cat_to'])) |
|
| 357 | - fatal_lang_error('mboards_delete_error'); |
|
| 367 | + if (empty($_POST['cat_to'])) { |
|
| 368 | + fatal_lang_error('mboards_delete_error'); |
|
| 369 | + } |
|
| 358 | 370 | |
| 359 | 371 | deleteCategories(array($_POST['cat']), (int) $_POST['cat_to']); |
| 372 | + } else { |
|
| 373 | + deleteCategories(array($_POST['cat'])); |
|
| 360 | 374 | } |
| 361 | - else |
|
| 362 | - deleteCategories(array($_POST['cat'])); |
|
| 363 | 375 | } |
| 364 | 376 | |
| 365 | 377 | redirectexit('action=admin;area=manageboards'); |
@@ -404,8 +416,9 @@ discard block |
||
| 404 | 416 | if ($_REQUEST['sa'] == 'newboard') |
| 405 | 417 | { |
| 406 | 418 | // Category doesn't exist, man... sorry. |
| 407 | - if (empty($_REQUEST['cat'])) |
|
| 408 | - redirectexit('action=admin;area=manageboards'); |
|
| 419 | + if (empty($_REQUEST['cat'])) { |
|
| 420 | + redirectexit('action=admin;area=manageboards'); |
|
| 421 | + } |
|
| 409 | 422 | |
| 410 | 423 | // Some things that need to be setup for a new board. |
| 411 | 424 | $curBoard = array( |
@@ -429,8 +442,7 @@ discard block |
||
| 429 | 442 | 'category' => (int) $_REQUEST['cat'], |
| 430 | 443 | 'no_children' => true, |
| 431 | 444 | ); |
| 432 | - } |
|
| 433 | - else |
|
| 445 | + } else |
|
| 434 | 446 | { |
| 435 | 447 | // Just some easy shortcuts. |
| 436 | 448 | $curBoard = &$boards[$_REQUEST['boardid']]; |
@@ -478,8 +490,9 @@ discard block |
||
| 478 | 490 | ); |
| 479 | 491 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 480 | 492 | { |
| 481 | - if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1) |
|
| 482 | - $curBoard['member_groups'][] = $row['id_group']; |
|
| 493 | + if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1) { |
|
| 494 | + $curBoard['member_groups'][] = $row['id_group']; |
|
| 495 | + } |
|
| 483 | 496 | |
| 484 | 497 | $context['groups'][(int) $row['id_group']] = array( |
| 485 | 498 | 'id' => $row['id_group'], |
@@ -492,8 +505,9 @@ discard block |
||
| 492 | 505 | $smcFunc['db_free_result']($request); |
| 493 | 506 | |
| 494 | 507 | // Category doesn't exist, man... sorry. |
| 495 | - if (!isset($boardList[$curBoard['category']])) |
|
| 496 | - redirectexit('action=admin;area=manageboards'); |
|
| 508 | + if (!isset($boardList[$curBoard['category']])) { |
|
| 509 | + redirectexit('action=admin;area=manageboards'); |
|
| 510 | + } |
|
| 497 | 511 | |
| 498 | 512 | foreach ($boardList[$curBoard['category']] as $boardid) |
| 499 | 513 | { |
@@ -507,8 +521,7 @@ discard block |
||
| 507 | 521 | 'is_child' => false, |
| 508 | 522 | 'selected' => true |
| 509 | 523 | ); |
| 510 | - } |
|
| 511 | - else |
|
| 524 | + } else |
|
| 512 | 525 | { |
| 513 | 526 | $context['board_order'][] = array( |
| 514 | 527 | 'id' => $boardid, |
@@ -525,19 +538,21 @@ discard block |
||
| 525 | 538 | $context['can_move_children'] = false; |
| 526 | 539 | $context['children'] = $boards[$_REQUEST['boardid']]['tree']['children']; |
| 527 | 540 | |
| 528 | - foreach ($context['board_order'] as $lBoard) |
|
| 529 | - if ($lBoard['is_child'] == false && $lBoard['selected'] == false) |
|
| 541 | + foreach ($context['board_order'] as $lBoard) { |
|
| 542 | + if ($lBoard['is_child'] == false && $lBoard['selected'] == false) |
|
| 530 | 543 | $context['can_move_children'] = true; |
| 544 | + } |
|
| 531 | 545 | } |
| 532 | 546 | |
| 533 | 547 | // Get other available categories. |
| 534 | 548 | $context['categories'] = array(); |
| 535 | - foreach ($cat_tree as $catID => $tree) |
|
| 536 | - $context['categories'][] = array( |
|
| 549 | + foreach ($cat_tree as $catID => $tree) { |
|
| 550 | + $context['categories'][] = array( |
|
| 537 | 551 | 'id' => $catID == $curBoard['category'] ? 0 : $catID, |
| 538 | 552 | 'name' => $tree['node']['name'], |
| 539 | 553 | 'selected' => $catID == $curBoard['category'] |
| 540 | 554 | ); |
| 555 | + } |
|
| 541 | 556 | |
| 542 | 557 | $request = $smcFunc['db_query']('', ' |
| 543 | 558 | SELECT mem.id_member, mem.real_name |
@@ -549,14 +564,16 @@ discard block |
||
| 549 | 564 | ) |
| 550 | 565 | ); |
| 551 | 566 | $context['board']['moderators'] = array(); |
| 552 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 553 | - $context['board']['moderators'][$row['id_member']] = $row['real_name']; |
|
| 567 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 568 | + $context['board']['moderators'][$row['id_member']] = $row['real_name']; |
|
| 569 | + } |
|
| 554 | 570 | $smcFunc['db_free_result']($request); |
| 555 | 571 | |
| 556 | 572 | $context['board']['moderator_list'] = empty($context['board']['moderators']) ? '' : '"' . implode('", "', $context['board']['moderators']) . '"'; |
| 557 | 573 | |
| 558 | - if (!empty($context['board']['moderators'])) |
|
| 559 | - list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1); |
|
| 574 | + if (!empty($context['board']['moderators'])) { |
|
| 575 | + list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1); |
|
| 576 | + } |
|
| 560 | 577 | |
| 561 | 578 | // Get all the groups assigned as moderators |
| 562 | 579 | $request = $smcFunc['db_query']('', ' |
@@ -568,14 +585,16 @@ discard block |
||
| 568 | 585 | ) |
| 569 | 586 | ); |
| 570 | 587 | $context['board']['moderator_groups'] = array(); |
| 571 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 572 | - $context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name']; |
|
| 588 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 589 | + $context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name']; |
|
| 590 | + } |
|
| 573 | 591 | $smcFunc['db_free_result']($request); |
| 574 | 592 | |
| 575 | 593 | $context['board']['moderator_groups_list'] = empty($context['board']['moderator_groups']) ? '' : '"' . implode('", &qout;', $context['board']['moderator_groups']) . '"'; |
| 576 | 594 | |
| 577 | - if (!empty($context['board']['moderator_groups'])) |
|
| 578 | - list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1); |
|
| 595 | + if (!empty($context['board']['moderator_groups'])) { |
|
| 596 | + list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1); |
|
| 597 | + } |
|
| 579 | 598 | |
| 580 | 599 | // Get all the themes... |
| 581 | 600 | $request = $smcFunc['db_query']('', ' |
@@ -587,8 +606,9 @@ discard block |
||
| 587 | 606 | ) |
| 588 | 607 | ); |
| 589 | 608 | $context['themes'] = array(); |
| 590 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 591 | - $context['themes'][] = $row; |
|
| 609 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 610 | + $context['themes'][] = $row; |
|
| 611 | + } |
|
| 592 | 612 | $smcFunc['db_free_result']($request); |
| 593 | 613 | |
| 594 | 614 | if (!isset($_REQUEST['delete'])) |
@@ -596,8 +616,7 @@ discard block |
||
| 596 | 616 | $context['sub_template'] = 'modify_board'; |
| 597 | 617 | $context['page_title'] = $txt['boardsEdit']; |
| 598 | 618 | loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
| 599 | - } |
|
| 600 | - else |
|
| 619 | + } else |
|
| 601 | 620 | { |
| 602 | 621 | $context['sub_template'] = 'confirm_board_delete'; |
| 603 | 622 | $context['page_title'] = $txt['mboards_delete_board']; |
@@ -641,8 +660,9 @@ discard block |
||
| 641 | 660 | // Change the boardorder of this board? |
| 642 | 661 | elseif (!empty($_POST['placement']) && !empty($_POST['board_order'])) |
| 643 | 662 | { |
| 644 | - if (!in_array($_POST['placement'], array('before', 'after', 'child'))) |
|
| 645 | - fatal_lang_error('mangled_post', false); |
|
| 663 | + if (!in_array($_POST['placement'], array('before', 'after', 'child'))) { |
|
| 664 | + fatal_lang_error('mangled_post', false); |
|
| 665 | + } |
|
| 646 | 666 | |
| 647 | 667 | $boardOptions['move_to'] = $_POST['placement']; |
| 648 | 668 | $boardOptions['target_board'] = (int) $_POST['board_order']; |
@@ -655,13 +675,14 @@ discard block |
||
| 655 | 675 | $boardOptions['access_groups'] = array(); |
| 656 | 676 | $boardOptions['deny_groups'] = array(); |
| 657 | 677 | |
| 658 | - if (!empty($_POST['groups'])) |
|
| 659 | - foreach ($_POST['groups'] as $group => $action) |
|
| 678 | + if (!empty($_POST['groups'])) { |
|
| 679 | + foreach ($_POST['groups'] as $group => $action) |
|
| 660 | 680 | { |
| 661 | 681 | if ($action == 'allow') |
| 662 | 682 | $boardOptions['access_groups'][] = (int) $group; |
| 663 | - elseif ($action == 'deny') |
|
| 664 | - $boardOptions['deny_groups'][] = (int) $group; |
|
| 683 | + } elseif ($action == 'deny') { |
|
| 684 | + $boardOptions['deny_groups'][] = (int) $group; |
|
| 685 | + } |
|
| 665 | 686 | } |
| 666 | 687 | |
| 667 | 688 | // People with manage-boards are special. |
@@ -673,8 +694,9 @@ discard block |
||
| 673 | 694 | // Secondly, make sure those with super cow powers (like apt-get, or in this case manage boards) are upgraded. |
| 674 | 695 | $boardOptions['access_groups'] = array_unique(array_merge($boardOptions['access_groups'], $board_managers)); |
| 675 | 696 | |
| 676 | - if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) |
|
| 677 | - fatal_lang_error('too_many_groups', false); |
|
| 697 | + if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) { |
|
| 698 | + fatal_lang_error('too_many_groups', false); |
|
| 699 | + } |
|
| 678 | 700 | |
| 679 | 701 | // Do not allow HTML tags. Parse the string. |
| 680 | 702 | $boardOptions['board_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['board_name']), false, '', $context['description_allowed_tags']); |
@@ -685,8 +707,9 @@ discard block |
||
| 685 | 707 | if (isset($_POST['moderator_list']) && is_array($_POST['moderator_list'])) |
| 686 | 708 | { |
| 687 | 709 | $moderators = array(); |
| 688 | - foreach ($_POST['moderator_list'] as $moderator) |
|
| 689 | - $moderators[(int) $moderator] = (int) $moderator; |
|
| 710 | + foreach ($_POST['moderator_list'] as $moderator) { |
|
| 711 | + $moderators[(int) $moderator] = (int) $moderator; |
|
| 712 | + } |
|
| 690 | 713 | $boardOptions['moderators'] = $moderators; |
| 691 | 714 | } |
| 692 | 715 | |
@@ -695,8 +718,9 @@ discard block |
||
| 695 | 718 | if (isset($_POST['moderator_group_list']) && is_array($_POST['moderator_group_list'])) |
| 696 | 719 | { |
| 697 | 720 | $moderator_groups = array(); |
| 698 | - foreach ($_POST['moderator_group_list'] as $moderator_group) |
|
| 699 | - $moderator_groups[(int) $moderator_group] = (int) $moderator_group; |
|
| 721 | + foreach ($_POST['moderator_group_list'] as $moderator_group) { |
|
| 722 | + $moderator_groups[(int) $moderator_group] = (int) $moderator_group; |
|
| 723 | + } |
|
| 700 | 724 | $boardOptions['moderator_groups'] = $moderator_groups; |
| 701 | 725 | } |
| 702 | 726 | |
@@ -722,56 +746,62 @@ discard block |
||
| 722 | 746 | $smcFunc['db_free_result']($request); |
| 723 | 747 | |
| 724 | 748 | // If we're turning redirection on check the board doesn't have posts in it - if it does don't make it a redirection board. |
| 725 | - if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts) |
|
| 726 | - unset($boardOptions['redirect']); |
|
| 749 | + if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts) { |
|
| 750 | + unset($boardOptions['redirect']); |
|
| 751 | + } |
|
| 727 | 752 | // Reset the redirection count when switching on/off. |
| 728 | - elseif (empty($boardOptions['redirect']) != empty($oldRedirect)) |
|
| 729 | - $boardOptions['num_posts'] = 0; |
|
| 753 | + elseif (empty($boardOptions['redirect']) != empty($oldRedirect)) { |
|
| 754 | + $boardOptions['num_posts'] = 0; |
|
| 755 | + } |
|
| 730 | 756 | // Resetting the count? |
| 731 | - elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect'])) |
|
| 732 | - $boardOptions['num_posts'] = 0; |
|
| 757 | + elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect'])) { |
|
| 758 | + $boardOptions['num_posts'] = 0; |
|
| 759 | + } |
|
| 733 | 760 | } |
| 734 | 761 | |
| 735 | 762 | // Create a new board... |
| 736 | 763 | if (isset($_POST['add'])) |
| 737 | 764 | { |
| 738 | 765 | // New boards by default go to the bottom of the category. |
| 739 | - if (empty($_POST['new_cat'])) |
|
| 740 | - $boardOptions['target_category'] = (int) $_POST['cur_cat']; |
|
| 741 | - if (!isset($boardOptions['move_to'])) |
|
| 742 | - $boardOptions['move_to'] = 'bottom'; |
|
| 766 | + if (empty($_POST['new_cat'])) { |
|
| 767 | + $boardOptions['target_category'] = (int) $_POST['cur_cat']; |
|
| 768 | + } |
|
| 769 | + if (!isset($boardOptions['move_to'])) { |
|
| 770 | + $boardOptions['move_to'] = 'bottom'; |
|
| 771 | + } |
|
| 743 | 772 | |
| 744 | 773 | createBoard($boardOptions); |
| 745 | 774 | } |
| 746 | 775 | |
| 747 | 776 | // ...or update an existing board. |
| 748 | - else |
|
| 749 | - modifyBoard($_POST['boardid'], $boardOptions); |
|
| 750 | - } |
|
| 751 | - elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children'])) |
|
| 777 | + else { |
|
| 778 | + modifyBoard($_POST['boardid'], $boardOptions); |
|
| 779 | + } |
|
| 780 | + } elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children'])) |
|
| 752 | 781 | { |
| 753 | 782 | EditBoard(); |
| 754 | 783 | return; |
| 755 | - } |
|
| 756 | - elseif (isset($_POST['delete'])) |
|
| 784 | + } elseif (isset($_POST['delete'])) |
|
| 757 | 785 | { |
| 758 | 786 | // First off - check if we are moving all the current child boards first - before we start deleting! |
| 759 | 787 | if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1) |
| 760 | 788 | { |
| 761 | - if (empty($_POST['board_to'])) |
|
| 762 | - fatal_lang_error('mboards_delete_board_error'); |
|
| 789 | + if (empty($_POST['board_to'])) { |
|
| 790 | + fatal_lang_error('mboards_delete_board_error'); |
|
| 791 | + } |
|
| 763 | 792 | |
| 764 | 793 | deleteBoards(array($_POST['boardid']), (int) $_POST['board_to']); |
| 794 | + } else { |
|
| 795 | + deleteBoards(array($_POST['boardid']), 0); |
|
| 765 | 796 | } |
| 766 | - else |
|
| 767 | - deleteBoards(array($_POST['boardid']), 0); |
|
| 768 | 797 | } |
| 769 | 798 | |
| 770 | - if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions') |
|
| 771 | - redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']); |
|
| 772 | - else |
|
| 773 | - redirectexit('action=admin;area=manageboards'); |
|
| 774 | -} |
|
| 799 | + if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions') { |
|
| 800 | + redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']); |
|
| 801 | + } else { |
|
| 802 | + redirectexit('action=admin;area=manageboards'); |
|
| 803 | + } |
|
| 804 | + } |
|
| 775 | 805 | |
| 776 | 806 | /** |
| 777 | 807 | * Used to retrieve data for modifying a board category |
@@ -808,8 +838,9 @@ discard block |
||
| 808 | 838 | $smcFunc['db_free_result']($request); |
| 809 | 839 | |
| 810 | 840 | // This would probably never happen, but just to be sure. |
| 811 | - if ($cat .= $allowed_sa[1]) |
|
| 812 | - die(str_replace(',', ' to', $cat)); |
|
| 841 | + if ($cat .= $allowed_sa[1]) { |
|
| 842 | + die(str_replace(',', ' to', $cat)); |
|
| 843 | + } |
|
| 813 | 844 | |
| 814 | 845 | redirectexit(); |
| 815 | 846 | } |
@@ -835,8 +866,9 @@ discard block |
||
| 835 | 866 | 'empty_string' => '', |
| 836 | 867 | ) |
| 837 | 868 | ); |
| 838 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 839 | - $recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name']; |
|
| 869 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 870 | + $recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name']; |
|
| 871 | + } |
|
| 840 | 872 | $smcFunc['db_free_result']($request); |
| 841 | 873 | |
| 842 | 874 | require_once($sourcedir . '/Subs-Boards.php'); |
@@ -860,8 +892,9 @@ discard block |
||
| 860 | 892 | |
| 861 | 893 | call_integration_hook('integrate_modify_board_settings', array(&$config_vars)); |
| 862 | 894 | |
| 863 | - if ($return_config) |
|
| 864 | - return $config_vars; |
|
| 895 | + if ($return_config) { |
|
| 896 | + return $config_vars; |
|
| 897 | + } |
|
| 865 | 898 | |
| 866 | 899 | // Needed for the settings template. |
| 867 | 900 | require_once($sourcedir . '/ManageServer.php'); |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 3 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('No direct access...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * View a summary. |
@@ -23,8 +24,9 @@ discard block |
||
| 23 | 24 | global $context, $memberContext, $txt, $modSettings, $user_profile, $sourcedir, $scripturl, $smcFunc; |
| 24 | 25 | |
| 25 | 26 | // Attempt to load the member's profile data. |
| 26 | - if (!loadMemberContext($memID) || !isset($memberContext[$memID])) |
|
| 27 | - fatal_lang_error('not_a_user', false, 404); |
|
| 27 | + if (!loadMemberContext($memID) || !isset($memberContext[$memID])) { |
|
| 28 | + fatal_lang_error('not_a_user', false, 404); |
|
| 29 | + } |
|
| 28 | 30 | |
| 29 | 31 | // Set up the stuff and load the user. |
| 30 | 32 | $context += array( |
@@ -49,19 +51,21 @@ discard block |
||
| 49 | 51 | |
| 50 | 52 | // See if they have broken any warning levels... |
| 51 | 53 | list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']); |
| 52 | - if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) |
|
| 53 | - $context['warning_status'] = $txt['profile_warning_is_muted']; |
|
| 54 | - elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) |
|
| 55 | - $context['warning_status'] = $txt['profile_warning_is_moderation']; |
|
| 56 | - elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) |
|
| 57 | - $context['warning_status'] = $txt['profile_warning_is_watch']; |
|
| 54 | + if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) { |
|
| 55 | + $context['warning_status'] = $txt['profile_warning_is_muted']; |
|
| 56 | + } elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) { |
|
| 57 | + $context['warning_status'] = $txt['profile_warning_is_moderation']; |
|
| 58 | + } elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) { |
|
| 59 | + $context['warning_status'] = $txt['profile_warning_is_watch']; |
|
| 60 | + } |
|
| 58 | 61 | |
| 59 | 62 | // They haven't even been registered for a full day!? |
| 60 | 63 | $days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24)); |
| 61 | - if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) |
|
| 62 | - $context['member']['posts_per_day'] = $txt['not_applicable']; |
|
| 63 | - else |
|
| 64 | - $context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3); |
|
| 64 | + if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) { |
|
| 65 | + $context['member']['posts_per_day'] = $txt['not_applicable']; |
|
| 66 | + } else { |
|
| 67 | + $context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3); |
|
| 68 | + } |
|
| 65 | 69 | |
| 66 | 70 | // Set the age... |
| 67 | 71 | if (empty($context['member']['birth_date'])) |
@@ -70,8 +74,7 @@ discard block |
||
| 70 | 74 | 'age' => $txt['not_applicable'], |
| 71 | 75 | 'today_is_birthday' => false |
| 72 | 76 | ); |
| 73 | - } |
|
| 74 | - else |
|
| 77 | + } else |
|
| 75 | 78 | { |
| 76 | 79 | list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d'); |
| 77 | 80 | $datearray = getdate(forum_time()); |
@@ -84,15 +87,16 @@ discard block |
||
| 84 | 87 | if (allowedTo('moderate_forum')) |
| 85 | 88 | { |
| 86 | 89 | // Make sure it's a valid ip address; otherwise, don't bother... |
| 87 | - if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) |
|
| 88 | - $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']); |
|
| 89 | - else |
|
| 90 | - $context['member']['hostname'] = ''; |
|
| 90 | + if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) { |
|
| 91 | + $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']); |
|
| 92 | + } else { |
|
| 93 | + $context['member']['hostname'] = ''; |
|
| 94 | + } |
|
| 91 | 95 | |
| 92 | 96 | $context['can_see_ip'] = true; |
| 97 | + } else { |
|
| 98 | + $context['can_see_ip'] = false; |
|
| 93 | 99 | } |
| 94 | - else |
|
| 95 | - $context['can_see_ip'] = false; |
|
| 96 | 100 | |
| 97 | 101 | // Are they hidden? |
| 98 | 102 | $context['member']['is_hidden'] = empty($user_profile[$memID]['show_online']); |
@@ -103,8 +107,9 @@ discard block |
||
| 103 | 107 | include_once($sourcedir . '/Who.php'); |
| 104 | 108 | $action = determineActions($user_profile[$memID]['url']); |
| 105 | 109 | |
| 106 | - if ($action !== false) |
|
| 107 | - $context['member']['action'] = $action; |
|
| 110 | + if ($action !== false) { |
|
| 111 | + $context['member']['action'] = $action; |
|
| 112 | + } |
|
| 108 | 113 | } |
| 109 | 114 | |
| 110 | 115 | // If the user is awaiting activation, and the viewer has permission - setup some activation context messages. |
@@ -167,13 +172,15 @@ discard block |
||
| 167 | 172 | { |
| 168 | 173 | // Work out what restrictions we actually have. |
| 169 | 174 | $ban_restrictions = array(); |
| 170 | - foreach (array('access', 'register', 'login', 'post') as $type) |
|
| 171 | - if ($row['cannot_' . $type]) |
|
| 175 | + foreach (array('access', 'register', 'login', 'post') as $type) { |
|
| 176 | + if ($row['cannot_' . $type]) |
|
| 172 | 177 | $ban_restrictions[] = $txt['ban_type_' . $type]; |
| 178 | + } |
|
| 173 | 179 | |
| 174 | 180 | // No actual ban in place? |
| 175 | - if (empty($ban_restrictions)) |
|
| 176 | - continue; |
|
| 181 | + if (empty($ban_restrictions)) { |
|
| 182 | + continue; |
|
| 183 | + } |
|
| 177 | 184 | |
| 178 | 185 | // Prepare the link for context. |
| 179 | 186 | $ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>'); |
@@ -196,9 +203,10 @@ discard block |
||
| 196 | 203 | $context['print_custom_fields'] = array(); |
| 197 | 204 | |
| 198 | 205 | // Any custom profile fields? |
| 199 | - if (!empty($context['custom_fields'])) |
|
| 200 | - foreach ($context['custom_fields'] as $custom) |
|
| 206 | + if (!empty($context['custom_fields'])) { |
|
| 207 | + foreach ($context['custom_fields'] as $custom) |
|
| 201 | 208 | $context['print_custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom; |
| 209 | + } |
|
| 202 | 210 | |
| 203 | 211 | } |
| 204 | 212 | |
@@ -242,14 +250,16 @@ discard block |
||
| 242 | 250 | $row['extra'] = !empty($row['extra']) ? smf_json_decode($row['extra'], true) : array(); |
| 243 | 251 | $alerts[$id_alert] = $row; |
| 244 | 252 | |
| 245 | - if (!empty($row['sender_id'])) |
|
| 246 | - $senders[] = $row['sender_id']; |
|
| 253 | + if (!empty($row['sender_id'])) { |
|
| 254 | + $senders[] = $row['sender_id']; |
|
| 255 | + } |
|
| 247 | 256 | } |
| 248 | 257 | $smcFunc['db_free_result']($request); |
| 249 | 258 | |
| 250 | 259 | $senders = loadMemberData($senders); |
| 251 | - foreach ($senders as $member) |
|
| 252 | - loadMemberContext($member); |
|
| 260 | + foreach ($senders as $member) { |
|
| 261 | + loadMemberContext($member); |
|
| 262 | + } |
|
| 253 | 263 | |
| 254 | 264 | // Now go through and actually make with the text. |
| 255 | 265 | loadLanguage('Alerts'); |
@@ -263,12 +273,15 @@ discard block |
||
| 263 | 273 | $msgs = array(); |
| 264 | 274 | foreach ($alerts as $id_alert => $alert) |
| 265 | 275 | { |
| 266 | - if (isset($alert['extra']['board'])) |
|
| 267 | - $boards[$alert['extra']['board']] = $txt['board_na']; |
|
| 268 | - if (isset($alert['extra']['topic'])) |
|
| 269 | - $topics[$alert['extra']['topic']] = $txt['topic_na']; |
|
| 270 | - if ($alert['content_type'] == 'msg') |
|
| 271 | - $msgs[$alert['content_id']] = $txt['topic_na']; |
|
| 276 | + if (isset($alert['extra']['board'])) { |
|
| 277 | + $boards[$alert['extra']['board']] = $txt['board_na']; |
|
| 278 | + } |
|
| 279 | + if (isset($alert['extra']['topic'])) { |
|
| 280 | + $topics[$alert['extra']['topic']] = $txt['topic_na']; |
|
| 281 | + } |
|
| 282 | + if ($alert['content_type'] == 'msg') { |
|
| 283 | + $msgs[$alert['content_id']] = $txt['topic_na']; |
|
| 284 | + } |
|
| 272 | 285 | } |
| 273 | 286 | |
| 274 | 287 | // Having figured out what boards etc. there are, let's now get the names of them if we can see them. If not, there's already a fallback set up. |
@@ -283,8 +296,9 @@ discard block |
||
| 283 | 296 | 'boards' => array_keys($boards), |
| 284 | 297 | ) |
| 285 | 298 | ); |
| 286 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 287 | - $boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
| 299 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 300 | + $boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
| 301 | + } |
|
| 288 | 302 | } |
| 289 | 303 | if (!empty($topics)) |
| 290 | 304 | { |
@@ -299,8 +313,9 @@ discard block |
||
| 299 | 313 | 'topics' => array_keys($topics), |
| 300 | 314 | ) |
| 301 | 315 | ); |
| 302 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 303 | - $topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>'; |
|
| 316 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 317 | + $topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>'; |
|
| 318 | + } |
|
| 304 | 319 | } |
| 305 | 320 | if (!empty($msgs)) |
| 306 | 321 | { |
@@ -315,26 +330,33 @@ discard block |
||
| 315 | 330 | 'msgs' => array_keys($msgs), |
| 316 | 331 | ) |
| 317 | 332 | ); |
| 318 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 319 | - $msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>'; |
|
| 333 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 334 | + $msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>'; |
|
| 335 | + } |
|
| 320 | 336 | } |
| 321 | 337 | |
| 322 | 338 | // Now to go back through the alerts, reattach this extra information and then try to build the string out of it (if a hook didn't already) |
| 323 | 339 | foreach ($alerts as $id_alert => $alert) |
| 324 | 340 | { |
| 325 | - if (!empty($alert['text'])) |
|
| 326 | - continue; |
|
| 327 | - if (isset($alert['extra']['board'])) |
|
| 328 | - $alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']]; |
|
| 329 | - if (isset($alert['extra']['topic'])) |
|
| 330 | - $alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']]; |
|
| 331 | - if ($alert['content_type'] == 'msg') |
|
| 332 | - $alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']]; |
|
| 333 | - if ($alert['content_type'] == 'profile') |
|
| 334 | - $alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>'; |
|
| 335 | - |
|
| 336 | - if (!empty($memberContext[$alert['sender_id']])) |
|
| 337 | - $alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']]; |
|
| 341 | + if (!empty($alert['text'])) { |
|
| 342 | + continue; |
|
| 343 | + } |
|
| 344 | + if (isset($alert['extra']['board'])) { |
|
| 345 | + $alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']]; |
|
| 346 | + } |
|
| 347 | + if (isset($alert['extra']['topic'])) { |
|
| 348 | + $alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']]; |
|
| 349 | + } |
|
| 350 | + if ($alert['content_type'] == 'msg') { |
|
| 351 | + $alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']]; |
|
| 352 | + } |
|
| 353 | + if ($alert['content_type'] == 'profile') { |
|
| 354 | + $alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>'; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + if (!empty($memberContext[$alert['sender_id']])) { |
|
| 358 | + $alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']]; |
|
| 359 | + } |
|
| 338 | 360 | |
| 339 | 361 | $string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action']; |
| 340 | 362 | if (isset($txt[$string])) |
@@ -422,11 +444,11 @@ discard block |
||
| 422 | 444 | checkSession('request'); |
| 423 | 445 | |
| 424 | 446 | // Call it! |
| 425 | - if ($action == 'remove') |
|
| 426 | - alert_delete($toMark, $memID); |
|
| 427 | - |
|
| 428 | - else |
|
| 429 | - alert_mark($memID, $toMark, $action == 'read' ? 1 : 0); |
|
| 447 | + if ($action == 'remove') { |
|
| 448 | + alert_delete($toMark, $memID); |
|
| 449 | + } else { |
|
| 450 | + alert_mark($memID, $toMark, $action == 'read' ? 1 : 0); |
|
| 451 | + } |
|
| 430 | 452 | |
| 431 | 453 | // Set a nice update message. |
| 432 | 454 | $_SESSION['update_message'] = true; |
@@ -476,23 +498,27 @@ discard block |
||
| 476 | 498 | ); |
| 477 | 499 | |
| 478 | 500 | // Set the page title |
| 479 | - if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title)) |
|
| 480 | - $context['page_title'] = $txt['show' . $title[$_GET['sa']]]; |
|
| 481 | - else |
|
| 482 | - $context['page_title'] = $txt['showPosts']; |
|
| 501 | + if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title)) { |
|
| 502 | + $context['page_title'] = $txt['show' . $title[$_GET['sa']]]; |
|
| 503 | + } else { |
|
| 504 | + $context['page_title'] = $txt['showPosts']; |
|
| 505 | + } |
|
| 483 | 506 | |
| 484 | 507 | $context['page_title'] .= ' - ' . $user_profile[$memID]['real_name']; |
| 485 | 508 | |
| 486 | 509 | // Is the load average too high to allow searching just now? |
| 487 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) |
|
| 488 | - fatal_lang_error('loadavg_show_posts_disabled', false); |
|
| 510 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) { |
|
| 511 | + fatal_lang_error('loadavg_show_posts_disabled', false); |
|
| 512 | + } |
|
| 489 | 513 | |
| 490 | 514 | // If we're specifically dealing with attachments use that function! |
| 491 | - if (isset($_GET['sa']) && $_GET['sa'] == 'attach') |
|
| 492 | - return showAttachments($memID); |
|
| 515 | + if (isset($_GET['sa']) && $_GET['sa'] == 'attach') { |
|
| 516 | + return showAttachments($memID); |
|
| 517 | + } |
|
| 493 | 518 | // Instead, if we're dealing with unwatched topics (and the feature is enabled) use that other function. |
| 494 | - elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics') |
|
| 495 | - return showUnwatched($memID); |
|
| 519 | + elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics') { |
|
| 520 | + return showUnwatched($memID); |
|
| 521 | + } |
|
| 496 | 522 | |
| 497 | 523 | // Are we just viewing topics? |
| 498 | 524 | $context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false; |
@@ -515,27 +541,30 @@ discard block |
||
| 515 | 541 | $smcFunc['db_free_result']($request); |
| 516 | 542 | |
| 517 | 543 | // Trying to remove a message that doesn't exist. |
| 518 | - if (empty($info)) |
|
| 519 | - redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); |
|
| 544 | + if (empty($info)) { |
|
| 545 | + redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); |
|
| 546 | + } |
|
| 520 | 547 | |
| 521 | 548 | // We can be lazy, since removeMessage() will check the permissions for us. |
| 522 | 549 | require_once($sourcedir . '/RemoveTopic.php'); |
| 523 | 550 | removeMessage((int) $_GET['delete']); |
| 524 | 551 | |
| 525 | 552 | // Add it to the mod log. |
| 526 | - if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) |
|
| 527 | - logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3])); |
|
| 553 | + if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) { |
|
| 554 | + logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3])); |
|
| 555 | + } |
|
| 528 | 556 | |
| 529 | 557 | // Back to... where we are now ;). |
| 530 | 558 | redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); |
| 531 | 559 | } |
| 532 | 560 | |
| 533 | 561 | // Default to 10. |
| 534 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
| 535 | - $_REQUEST['viewscount'] = '10'; |
|
| 562 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
| 563 | + $_REQUEST['viewscount'] = '10'; |
|
| 564 | + } |
|
| 536 | 565 | |
| 537 | - if ($context['is_topics']) |
|
| 538 | - $request = $smcFunc['db_query']('', ' |
|
| 566 | + if ($context['is_topics']) { |
|
| 567 | + $request = $smcFunc['db_query']('', ' |
|
| 539 | 568 | SELECT COUNT(*) |
| 540 | 569 | FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : ' |
| 541 | 570 | INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . ' |
@@ -548,8 +577,8 @@ discard block |
||
| 548 | 577 | 'board' => $board, |
| 549 | 578 | ) |
| 550 | 579 | ); |
| 551 | - else |
|
| 552 | - $request = $smcFunc['db_query']('', ' |
|
| 580 | + } else { |
|
| 581 | + $request = $smcFunc['db_query']('', ' |
|
| 553 | 582 | SELECT COUNT(*) |
| 554 | 583 | FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : ' |
| 555 | 584 | INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . ' |
@@ -562,6 +591,7 @@ discard block |
||
| 562 | 591 | 'board' => $board, |
| 563 | 592 | ) |
| 564 | 593 | ); |
| 594 | + } |
|
| 565 | 595 | list ($msgCount) = $smcFunc['db_fetch_row']($request); |
| 566 | 596 | $smcFunc['db_free_result']($request); |
| 567 | 597 | |
@@ -583,10 +613,11 @@ discard block |
||
| 583 | 613 | $reverse = false; |
| 584 | 614 | $range_limit = ''; |
| 585 | 615 | |
| 586 | - if ($context['is_topics']) |
|
| 587 | - $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics']; |
|
| 588 | - else |
|
| 589 | - $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
|
| 616 | + if ($context['is_topics']) { |
|
| 617 | + $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics']; |
|
| 618 | + } else { |
|
| 619 | + $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
|
| 620 | + } |
|
| 590 | 621 | |
| 591 | 622 | $maxIndex = $maxPerPage; |
| 592 | 623 | |
@@ -612,9 +643,9 @@ discard block |
||
| 612 | 643 | { |
| 613 | 644 | $margin *= 5; |
| 614 | 645 | $range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin); |
| 646 | + } else { |
|
| 647 | + $range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin); |
|
| 615 | 648 | } |
| 616 | - else |
|
| 617 | - $range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin); |
|
| 618 | 649 | } |
| 619 | 650 | |
| 620 | 651 | // Find this user's posts. The left join on categories somehow makes this faster, weird as it looks. |
@@ -646,8 +677,7 @@ discard block |
||
| 646 | 677 | 'max' => $maxIndex, |
| 647 | 678 | ) |
| 648 | 679 | ); |
| 649 | - } |
|
| 650 | - else |
|
| 680 | + } else |
|
| 651 | 681 | { |
| 652 | 682 | $request = $smcFunc['db_query']('', ' |
| 653 | 683 | SELECT |
@@ -676,8 +706,9 @@ discard block |
||
| 676 | 706 | } |
| 677 | 707 | |
| 678 | 708 | // Make sure we quit this loop. |
| 679 | - if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped) |
|
| 680 | - break; |
|
| 709 | + if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped) { |
|
| 710 | + break; |
|
| 711 | + } |
|
| 681 | 712 | $looped = true; |
| 682 | 713 | $range_limit = ''; |
| 683 | 714 | } |
@@ -721,19 +752,21 @@ discard block |
||
| 721 | 752 | 'css_class' => $row['approved'] ? 'windowbg' : 'approvebg', |
| 722 | 753 | ); |
| 723 | 754 | |
| 724 | - if ($user_info['id'] == $row['id_member_started']) |
|
| 725 | - $board_ids['own'][$row['id_board']][] = $counter; |
|
| 755 | + if ($user_info['id'] == $row['id_member_started']) { |
|
| 756 | + $board_ids['own'][$row['id_board']][] = $counter; |
|
| 757 | + } |
|
| 726 | 758 | $board_ids['any'][$row['id_board']][] = $counter; |
| 727 | 759 | } |
| 728 | 760 | $smcFunc['db_free_result']($request); |
| 729 | 761 | |
| 730 | 762 | // All posts were retrieved in reverse order, get them right again. |
| 731 | - if ($reverse) |
|
| 732 | - $context['posts'] = array_reverse($context['posts'], true); |
|
| 763 | + if ($reverse) { |
|
| 764 | + $context['posts'] = array_reverse($context['posts'], true); |
|
| 765 | + } |
|
| 733 | 766 | |
| 734 | 767 | // These are all the permissions that are different from board to board.. |
| 735 | - if ($context['is_topics']) |
|
| 736 | - $permissions = array( |
|
| 768 | + if ($context['is_topics']) { |
|
| 769 | + $permissions = array( |
|
| 737 | 770 | 'own' => array( |
| 738 | 771 | 'post_reply_own' => 'can_reply', |
| 739 | 772 | ), |
@@ -741,8 +774,8 @@ discard block |
||
| 741 | 774 | 'post_reply_any' => 'can_reply', |
| 742 | 775 | ) |
| 743 | 776 | ); |
| 744 | - else |
|
| 745 | - $permissions = array( |
|
| 777 | + } else { |
|
| 778 | + $permissions = array( |
|
| 746 | 779 | 'own' => array( |
| 747 | 780 | 'post_reply_own' => 'can_reply', |
| 748 | 781 | 'delete_own' => 'can_delete', |
@@ -752,6 +785,7 @@ discard block |
||
| 752 | 785 | 'delete_any' => 'can_delete', |
| 753 | 786 | ) |
| 754 | 787 | ); |
| 788 | + } |
|
| 755 | 789 | |
| 756 | 790 | // For every permission in the own/any lists... |
| 757 | 791 | foreach ($permissions as $type => $list) |
@@ -762,19 +796,22 @@ discard block |
||
| 762 | 796 | $boards = boardsAllowedTo($permission); |
| 763 | 797 | |
| 764 | 798 | // Hmm, they can do it on all boards, can they? |
| 765 | - if (!empty($boards) && $boards[0] == 0) |
|
| 766 | - $boards = array_keys($board_ids[$type]); |
|
| 799 | + if (!empty($boards) && $boards[0] == 0) { |
|
| 800 | + $boards = array_keys($board_ids[$type]); |
|
| 801 | + } |
|
| 767 | 802 | |
| 768 | 803 | // Now go through each board they can do the permission on. |
| 769 | 804 | foreach ($boards as $board_id) |
| 770 | 805 | { |
| 771 | 806 | // There aren't any posts displayed from this board. |
| 772 | - if (!isset($board_ids[$type][$board_id])) |
|
| 773 | - continue; |
|
| 807 | + if (!isset($board_ids[$type][$board_id])) { |
|
| 808 | + continue; |
|
| 809 | + } |
|
| 774 | 810 | |
| 775 | 811 | // Set the permission to true ;). |
| 776 | - foreach ($board_ids[$type][$board_id] as $counter) |
|
| 777 | - $context['posts'][$counter][$allowed] = true; |
|
| 812 | + foreach ($board_ids[$type][$board_id] as $counter) { |
|
| 813 | + $context['posts'][$counter][$allowed] = true; |
|
| 814 | + } |
|
| 778 | 815 | } |
| 779 | 816 | } |
| 780 | 817 | } |
@@ -805,8 +842,9 @@ discard block |
||
| 805 | 842 | $boardsAllowed = boardsAllowedTo('view_attachments'); |
| 806 | 843 | |
| 807 | 844 | // Make sure we can't actually see anything... |
| 808 | - if (empty($boardsAllowed)) |
|
| 809 | - $boardsAllowed = array(-1); |
|
| 845 | + if (empty($boardsAllowed)) { |
|
| 846 | + $boardsAllowed = array(-1); |
|
| 847 | + } |
|
| 810 | 848 | |
| 811 | 849 | require_once($sourcedir . '/Subs-List.php'); |
| 812 | 850 | |
@@ -957,8 +995,8 @@ discard block |
||
| 957 | 995 | ) |
| 958 | 996 | ); |
| 959 | 997 | $attachments = array(); |
| 960 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 961 | - $attachments[] = array( |
|
| 998 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 999 | + $attachments[] = array( |
|
| 962 | 1000 | 'id' => $row['id_attach'], |
| 963 | 1001 | 'filename' => $row['filename'], |
| 964 | 1002 | 'downloads' => $row['downloads'], |
@@ -970,6 +1008,7 @@ discard block |
||
| 970 | 1008 | 'board_name' => $row['name'], |
| 971 | 1009 | 'approved' => $row['approved'], |
| 972 | 1010 | ); |
| 1011 | + } |
|
| 973 | 1012 | |
| 974 | 1013 | $smcFunc['db_free_result']($request); |
| 975 | 1014 | |
@@ -1024,8 +1063,9 @@ discard block |
||
| 1024 | 1063 | global $txt, $user_info, $scripturl, $modSettings, $context, $sourcedir; |
| 1025 | 1064 | |
| 1026 | 1065 | // Only the owner can see the list (if the function is enabled of course) |
| 1027 | - if ($user_info['id'] != $memID) |
|
| 1028 | - return; |
|
| 1066 | + if ($user_info['id'] != $memID) { |
|
| 1067 | + return; |
|
| 1068 | + } |
|
| 1029 | 1069 | |
| 1030 | 1070 | require_once($sourcedir . '/Subs-List.php'); |
| 1031 | 1071 | |
@@ -1171,8 +1211,9 @@ discard block |
||
| 1171 | 1211 | ); |
| 1172 | 1212 | |
| 1173 | 1213 | $topics = array(); |
| 1174 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1175 | - $topics[] = $row['id_topic']; |
|
| 1214 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1215 | + $topics[] = $row['id_topic']; |
|
| 1216 | + } |
|
| 1176 | 1217 | |
| 1177 | 1218 | $smcFunc['db_free_result']($request); |
| 1178 | 1219 | |
@@ -1192,8 +1233,9 @@ discard block |
||
| 1192 | 1233 | 'topics' => $topics, |
| 1193 | 1234 | ) |
| 1194 | 1235 | ); |
| 1195 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1196 | - $topicsInfo[] = $row; |
|
| 1236 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1237 | + $topicsInfo[] = $row; |
|
| 1238 | + } |
|
| 1197 | 1239 | $smcFunc['db_free_result']($request); |
| 1198 | 1240 | } |
| 1199 | 1241 | |
@@ -1241,8 +1283,9 @@ discard block |
||
| 1241 | 1283 | $context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name']; |
| 1242 | 1284 | |
| 1243 | 1285 | // Is the load average too high to allow searching just now? |
| 1244 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) |
|
| 1245 | - fatal_lang_error('loadavg_userstats_disabled', false); |
|
| 1286 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) { |
|
| 1287 | + fatal_lang_error('loadavg_userstats_disabled', false); |
|
| 1288 | + } |
|
| 1246 | 1289 | |
| 1247 | 1290 | // General user statistics. |
| 1248 | 1291 | $timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400); |
@@ -1400,11 +1443,13 @@ discard block |
||
| 1400 | 1443 | } |
| 1401 | 1444 | $smcFunc['db_free_result']($result); |
| 1402 | 1445 | |
| 1403 | - if ($maxPosts > 0) |
|
| 1404 | - for ($hour = 0; $hour < 24; $hour++) |
|
| 1446 | + if ($maxPosts > 0) { |
|
| 1447 | + for ($hour = 0; |
|
| 1448 | + } |
|
| 1449 | + $hour < 24; $hour++) |
|
| 1405 | 1450 | { |
| 1406 | - if (!isset($context['posts_by_time'][$hour])) |
|
| 1407 | - $context['posts_by_time'][$hour] = array( |
|
| 1451 | + if (!isset($context['posts_by_time'][$hour])) { |
|
| 1452 | + $context['posts_by_time'][$hour] = array( |
|
| 1408 | 1453 | 'hour' => $hour, |
| 1409 | 1454 | 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)), |
| 1410 | 1455 | 'posts' => 0, |
@@ -1412,7 +1457,7 @@ discard block |
||
| 1412 | 1457 | 'relative_percent' => 0, |
| 1413 | 1458 | 'is_last' => $hour == 23, |
| 1414 | 1459 | ); |
| 1415 | - else |
|
| 1460 | + } else |
|
| 1416 | 1461 | { |
| 1417 | 1462 | $context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts); |
| 1418 | 1463 | $context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts); |
@@ -1445,8 +1490,9 @@ discard block |
||
| 1445 | 1490 | |
| 1446 | 1491 | foreach ($subActions as $sa => $action) |
| 1447 | 1492 | { |
| 1448 | - if (!allowedTo($action[2])) |
|
| 1449 | - unset($subActions[$sa]); |
|
| 1493 | + if (!allowedTo($action[2])) { |
|
| 1494 | + unset($subActions[$sa]); |
|
| 1495 | + } |
|
| 1450 | 1496 | } |
| 1451 | 1497 | |
| 1452 | 1498 | // Create the tabs for the template. |
@@ -1464,15 +1510,18 @@ discard block |
||
| 1464 | 1510 | ); |
| 1465 | 1511 | |
| 1466 | 1512 | // Moderation must be on to track edits. |
| 1467 | - if (empty($modSettings['userlog_enabled'])) |
|
| 1468 | - unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']); |
|
| 1513 | + if (empty($modSettings['userlog_enabled'])) { |
|
| 1514 | + unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']); |
|
| 1515 | + } |
|
| 1469 | 1516 | |
| 1470 | 1517 | // Group requests must be active to show it... |
| 1471 | - if (empty($modSettings['show_group_membership'])) |
|
| 1472 | - unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']); |
|
| 1518 | + if (empty($modSettings['show_group_membership'])) { |
|
| 1519 | + unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']); |
|
| 1520 | + } |
|
| 1473 | 1521 | |
| 1474 | - if (empty($subActions)) |
|
| 1475 | - fatal_lang_error('no_access', false); |
|
| 1522 | + if (empty($subActions)) { |
|
| 1523 | + fatal_lang_error('no_access', false); |
|
| 1524 | + } |
|
| 1476 | 1525 | |
| 1477 | 1526 | $keys = array_keys($subActions); |
| 1478 | 1527 | $default = array_shift($keys); |
@@ -1485,9 +1534,10 @@ discard block |
||
| 1485 | 1534 | $context['sub_template'] = $subActions[$context['tracking_area']][0]; |
| 1486 | 1535 | $call = call_helper($subActions[$context['tracking_area']][0], true); |
| 1487 | 1536 | |
| 1488 | - if (!empty($call)) |
|
| 1489 | - call_user_func($call, $memID); |
|
| 1490 | -} |
|
| 1537 | + if (!empty($call)) { |
|
| 1538 | + call_user_func($call, $memID); |
|
| 1539 | + } |
|
| 1540 | + } |
|
| 1491 | 1541 | |
| 1492 | 1542 | /** |
| 1493 | 1543 | * Handles tracking a user's activity |
@@ -1503,8 +1553,9 @@ discard block |
||
| 1503 | 1553 | isAllowedTo('moderate_forum'); |
| 1504 | 1554 | |
| 1505 | 1555 | $context['last_ip'] = $user_profile[$memID]['member_ip']; |
| 1506 | - if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) |
|
| 1507 | - $context['last_ip2'] = $user_profile[$memID]['member_ip2']; |
|
| 1556 | + if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) { |
|
| 1557 | + $context['last_ip2'] = $user_profile[$memID]['member_ip2']; |
|
| 1558 | + } |
|
| 1508 | 1559 | $context['member']['name'] = $user_profile[$memID]['real_name']; |
| 1509 | 1560 | |
| 1510 | 1561 | // Set the options for the list component. |
@@ -1670,8 +1721,9 @@ discard block |
||
| 1670 | 1721 | ) |
| 1671 | 1722 | ); |
| 1672 | 1723 | $message_members = array(); |
| 1673 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1674 | - $message_members[] = $row['id_member']; |
|
| 1724 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1725 | + $message_members[] = $row['id_member']; |
|
| 1726 | + } |
|
| 1675 | 1727 | $smcFunc['db_free_result']($request); |
| 1676 | 1728 | |
| 1677 | 1729 | // Fetch their names, cause of the GROUP BY doesn't like giving us that normally. |
@@ -1686,8 +1738,9 @@ discard block |
||
| 1686 | 1738 | 'ip_list' => $ips, |
| 1687 | 1739 | ) |
| 1688 | 1740 | ); |
| 1689 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1690 | - $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 1741 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1742 | + $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 1743 | + } |
|
| 1691 | 1744 | $smcFunc['db_free_result']($request); |
| 1692 | 1745 | } |
| 1693 | 1746 | |
@@ -1701,8 +1754,9 @@ discard block |
||
| 1701 | 1754 | 'ip_list' => $ips, |
| 1702 | 1755 | ) |
| 1703 | 1756 | ); |
| 1704 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1705 | - $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 1757 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1758 | + $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 1759 | + } |
|
| 1706 | 1760 | $smcFunc['db_free_result']($request); |
| 1707 | 1761 | } |
| 1708 | 1762 | } |
@@ -1762,8 +1816,8 @@ discard block |
||
| 1762 | 1816 | )) |
| 1763 | 1817 | ); |
| 1764 | 1818 | $error_messages = array(); |
| 1765 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1766 | - $error_messages[] = array( |
|
| 1819 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1820 | + $error_messages[] = array( |
|
| 1767 | 1821 | 'ip' => inet_dtop($row['ip']), |
| 1768 | 1822 | 'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'], |
| 1769 | 1823 | 'message' => strtr($row['message'], array('<span class="remove">' => '', '</span>' => '')), |
@@ -1771,6 +1825,7 @@ discard block |
||
| 1771 | 1825 | 'time' => timeformat($row['log_time']), |
| 1772 | 1826 | 'timestamp' => forum_time(true, $row['log_time']), |
| 1773 | 1827 | ); |
| 1828 | + } |
|
| 1774 | 1829 | $smcFunc['db_free_result']($request); |
| 1775 | 1830 | |
| 1776 | 1831 | return $error_messages; |
@@ -1833,8 +1888,8 @@ discard block |
||
| 1833 | 1888 | )) |
| 1834 | 1889 | ); |
| 1835 | 1890 | $messages = array(); |
| 1836 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1837 | - $messages[] = array( |
|
| 1891 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1892 | + $messages[] = array( |
|
| 1838 | 1893 | 'ip' => inet_dtop($row['poster_ip']), |
| 1839 | 1894 | 'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>', |
| 1840 | 1895 | 'board' => array( |
@@ -1847,6 +1902,7 @@ discard block |
||
| 1847 | 1902 | 'time' => timeformat($row['poster_time']), |
| 1848 | 1903 | 'timestamp' => forum_time(true, $row['poster_time']) |
| 1849 | 1904 | ); |
| 1905 | + } |
|
| 1850 | 1906 | $smcFunc['db_free_result']($request); |
| 1851 | 1907 | |
| 1852 | 1908 | return $messages; |
@@ -1873,19 +1929,20 @@ discard block |
||
| 1873 | 1929 | $context['sub_template'] = 'trackIP'; |
| 1874 | 1930 | $context['page_title'] = $txt['profile']; |
| 1875 | 1931 | $context['base_url'] = $scripturl . '?action=trackip'; |
| 1876 | - } |
|
| 1877 | - else |
|
| 1932 | + } else |
|
| 1878 | 1933 | { |
| 1879 | 1934 | $context['ip'] = $user_profile[$memID]['member_ip']; |
| 1880 | 1935 | $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID; |
| 1881 | 1936 | } |
| 1882 | 1937 | |
| 1883 | 1938 | // Searching? |
| 1884 | - if (isset($_REQUEST['searchip'])) |
|
| 1885 | - $context['ip'] = trim($_REQUEST['searchip']); |
|
| 1939 | + if (isset($_REQUEST['searchip'])) { |
|
| 1940 | + $context['ip'] = trim($_REQUEST['searchip']); |
|
| 1941 | + } |
|
| 1886 | 1942 | |
| 1887 | - if (isValidIP($context['ip']) === false) |
|
| 1888 | - fatal_lang_error('invalid_tracking_ip', false); |
|
| 1943 | + if (isValidIP($context['ip']) === false) { |
|
| 1944 | + fatal_lang_error('invalid_tracking_ip', false); |
|
| 1945 | + } |
|
| 1889 | 1946 | |
| 1890 | 1947 | //mysql didn't support like search with varbinary |
| 1891 | 1948 | //$ip_var = str_replace('*', '%', $context['ip']); |
@@ -1893,8 +1950,9 @@ discard block |
||
| 1893 | 1950 | $ip_var = $context['ip']; |
| 1894 | 1951 | $ip_string = '= {inet:ip_address}'; |
| 1895 | 1952 | |
| 1896 | - if (empty($context['tracking_area'])) |
|
| 1897 | - $context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip']; |
|
| 1953 | + if (empty($context['tracking_area'])) { |
|
| 1954 | + $context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip']; |
|
| 1955 | + } |
|
| 1898 | 1956 | |
| 1899 | 1957 | $request = $smcFunc['db_query']('', ' |
| 1900 | 1958 | SELECT id_member, real_name AS display_name, member_ip |
@@ -1905,8 +1963,9 @@ discard block |
||
| 1905 | 1963 | ) |
| 1906 | 1964 | ); |
| 1907 | 1965 | $context['ips'] = array(); |
| 1908 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1909 | - $context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>'; |
|
| 1966 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1967 | + $context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>'; |
|
| 1968 | + } |
|
| 1910 | 1969 | $smcFunc['db_free_result']($request); |
| 1911 | 1970 | |
| 1912 | 1971 | ksort($context['ips']); |
@@ -2135,8 +2194,9 @@ discard block |
||
| 2135 | 2194 | foreach ($context['whois_servers'] as $whois) |
| 2136 | 2195 | { |
| 2137 | 2196 | // Strip off the "decimal point" and anything following... |
| 2138 | - if (in_array((int) $context['ip'], $whois['range'])) |
|
| 2139 | - $context['auto_whois_server'] = $whois; |
|
| 2197 | + if (in_array((int) $context['ip'], $whois['range'])) { |
|
| 2198 | + $context['auto_whois_server'] = $whois; |
|
| 2199 | + } |
|
| 2140 | 2200 | } |
| 2141 | 2201 | } |
| 2142 | 2202 | } |
@@ -2153,10 +2213,11 @@ discard block |
||
| 2153 | 2213 | // Gonna want this for the list. |
| 2154 | 2214 | require_once($sourcedir . '/Subs-List.php'); |
| 2155 | 2215 | |
| 2156 | - if ($memID == 0) |
|
| 2157 | - $context['base_url'] = $scripturl . '?action=trackip'; |
|
| 2158 | - else |
|
| 2159 | - $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID; |
|
| 2216 | + if ($memID == 0) { |
|
| 2217 | + $context['base_url'] = $scripturl . '?action=trackip'; |
|
| 2218 | + } else { |
|
| 2219 | + $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID; |
|
| 2220 | + } |
|
| 2160 | 2221 | |
| 2161 | 2222 | // Start with the user messages. |
| 2162 | 2223 | $listOptions = array( |
@@ -2266,12 +2327,13 @@ discard block |
||
| 2266 | 2327 | ) |
| 2267 | 2328 | ); |
| 2268 | 2329 | $logins = array(); |
| 2269 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2270 | - $logins[] = array( |
|
| 2330 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2331 | + $logins[] = array( |
|
| 2271 | 2332 | 'time' => timeformat($row['time']), |
| 2272 | 2333 | 'ip' => inet_dtop($row['ip']), |
| 2273 | 2334 | 'ip2' => inet_dtop($row['ip2']), |
| 2274 | 2335 | ); |
| 2336 | + } |
|
| 2275 | 2337 | $smcFunc['db_free_result']($request); |
| 2276 | 2338 | |
| 2277 | 2339 | return $logins; |
@@ -2296,11 +2358,12 @@ discard block |
||
| 2296 | 2358 | ) |
| 2297 | 2359 | ); |
| 2298 | 2360 | $context['custom_field_titles'] = array(); |
| 2299 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2300 | - $context['custom_field_titles']['customfield_' . $row['col_name']] = array( |
|
| 2361 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2362 | + $context['custom_field_titles']['customfield_' . $row['col_name']] = array( |
|
| 2301 | 2363 | 'title' => $row['field_name'], |
| 2302 | 2364 | 'parse_bbc' => $row['bbc'], |
| 2303 | 2365 | ); |
| 2366 | + } |
|
| 2304 | 2367 | $smcFunc['db_free_result']($request); |
| 2305 | 2368 | |
| 2306 | 2369 | // Set the options for the error lists. |
@@ -2439,19 +2502,22 @@ discard block |
||
| 2439 | 2502 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2440 | 2503 | { |
| 2441 | 2504 | $extra = smf_json_decode($row['extra'], true); |
| 2442 | - if (!empty($extra['applicator'])) |
|
| 2443 | - $members[] = $extra['applicator']; |
|
| 2505 | + if (!empty($extra['applicator'])) { |
|
| 2506 | + $members[] = $extra['applicator']; |
|
| 2507 | + } |
|
| 2444 | 2508 | |
| 2445 | 2509 | // Work out what the name of the action is. |
| 2446 | - if (isset($txt['trackEdit_action_' . $row['action']])) |
|
| 2447 | - $action_text = $txt['trackEdit_action_' . $row['action']]; |
|
| 2448 | - elseif (isset($txt[$row['action']])) |
|
| 2449 | - $action_text = $txt[$row['action']]; |
|
| 2510 | + if (isset($txt['trackEdit_action_' . $row['action']])) { |
|
| 2511 | + $action_text = $txt['trackEdit_action_' . $row['action']]; |
|
| 2512 | + } elseif (isset($txt[$row['action']])) { |
|
| 2513 | + $action_text = $txt[$row['action']]; |
|
| 2514 | + } |
|
| 2450 | 2515 | // Custom field? |
| 2451 | - elseif (isset($context['custom_field_titles'][$row['action']])) |
|
| 2452 | - $action_text = $context['custom_field_titles'][$row['action']]['title']; |
|
| 2453 | - else |
|
| 2454 | - $action_text = $row['action']; |
|
| 2516 | + elseif (isset($context['custom_field_titles'][$row['action']])) { |
|
| 2517 | + $action_text = $context['custom_field_titles'][$row['action']]['title']; |
|
| 2518 | + } else { |
|
| 2519 | + $action_text = $row['action']; |
|
| 2520 | + } |
|
| 2455 | 2521 | |
| 2456 | 2522 | // Parse BBC? |
| 2457 | 2523 | $parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false; |
@@ -2483,13 +2549,15 @@ discard block |
||
| 2483 | 2549 | ) |
| 2484 | 2550 | ); |
| 2485 | 2551 | $members = array(); |
| 2486 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2487 | - $members[$row['id_member']] = $row['real_name']; |
|
| 2552 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2553 | + $members[$row['id_member']] = $row['real_name']; |
|
| 2554 | + } |
|
| 2488 | 2555 | $smcFunc['db_free_result']($request); |
| 2489 | 2556 | |
| 2490 | - foreach ($edits as $key => $value) |
|
| 2491 | - if (isset($members[$value['id_member']])) |
|
| 2557 | + foreach ($edits as $key => $value) { |
|
| 2558 | + if (isset($members[$value['id_member']])) |
|
| 2492 | 2559 | $edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>'; |
| 2560 | + } |
|
| 2493 | 2561 | } |
| 2494 | 2562 | |
| 2495 | 2563 | return $edits; |
@@ -2690,10 +2758,11 @@ discard block |
||
| 2690 | 2758 | $context['board'] = $board; |
| 2691 | 2759 | |
| 2692 | 2760 | // Determine which groups this user is in. |
| 2693 | - if (empty($user_profile[$memID]['additional_groups'])) |
|
| 2694 | - $curGroups = array(); |
|
| 2695 | - else |
|
| 2696 | - $curGroups = explode(',', $user_profile[$memID]['additional_groups']); |
|
| 2761 | + if (empty($user_profile[$memID]['additional_groups'])) { |
|
| 2762 | + $curGroups = array(); |
|
| 2763 | + } else { |
|
| 2764 | + $curGroups = explode(',', $user_profile[$memID]['additional_groups']); |
|
| 2765 | + } |
|
| 2697 | 2766 | $curGroups[] = $user_profile[$memID]['id_group']; |
| 2698 | 2767 | $curGroups[] = $user_profile[$memID]['id_post_group']; |
| 2699 | 2768 | |
@@ -2713,28 +2782,30 @@ discard block |
||
| 2713 | 2782 | $context['no_access_boards'] = array(); |
| 2714 | 2783 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2715 | 2784 | { |
| 2716 | - if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) |
|
| 2717 | - $context['no_access_boards'][] = array( |
|
| 2785 | + if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) { |
|
| 2786 | + $context['no_access_boards'][] = array( |
|
| 2718 | 2787 | 'id' => $row['id_board'], |
| 2719 | 2788 | 'name' => $row['name'], |
| 2720 | 2789 | 'is_last' => false, |
| 2721 | 2790 | ); |
| 2722 | - elseif ($row['id_profile'] != 1 || $row['is_mod']) |
|
| 2723 | - $context['boards'][$row['id_board']] = array( |
|
| 2791 | + } elseif ($row['id_profile'] != 1 || $row['is_mod']) { |
|
| 2792 | + $context['boards'][$row['id_board']] = array( |
|
| 2724 | 2793 | 'id' => $row['id_board'], |
| 2725 | 2794 | 'name' => $row['name'], |
| 2726 | 2795 | 'selected' => $board == $row['id_board'], |
| 2727 | 2796 | 'profile' => $row['id_profile'], |
| 2728 | 2797 | 'profile_name' => $context['profiles'][$row['id_profile']]['name'], |
| 2729 | 2798 | ); |
| 2799 | + } |
|
| 2730 | 2800 | } |
| 2731 | 2801 | $smcFunc['db_free_result']($request); |
| 2732 | 2802 | |
| 2733 | 2803 | require_once($sourcedir . '/Subs-Boards.php'); |
| 2734 | 2804 | sortBoards($context['boards']); |
| 2735 | 2805 | |
| 2736 | - if (!empty($context['no_access_boards'])) |
|
| 2737 | - $context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true; |
|
| 2806 | + if (!empty($context['no_access_boards'])) { |
|
| 2807 | + $context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true; |
|
| 2808 | + } |
|
| 2738 | 2809 | |
| 2739 | 2810 | $context['member']['permissions'] = array( |
| 2740 | 2811 | 'general' => array(), |
@@ -2743,8 +2814,9 @@ discard block |
||
| 2743 | 2814 | |
| 2744 | 2815 | // If you're an admin we know you can do everything, we might as well leave. |
| 2745 | 2816 | $context['member']['has_all_permissions'] = in_array(1, $curGroups); |
| 2746 | - if ($context['member']['has_all_permissions']) |
|
| 2747 | - return; |
|
| 2817 | + if ($context['member']['has_all_permissions']) { |
|
| 2818 | + return; |
|
| 2819 | + } |
|
| 2748 | 2820 | |
| 2749 | 2821 | $denied = array(); |
| 2750 | 2822 | |
@@ -2763,21 +2835,24 @@ discard block |
||
| 2763 | 2835 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 2764 | 2836 | { |
| 2765 | 2837 | // We don't know about this permission, it doesn't exist :P. |
| 2766 | - if (!isset($txt['permissionname_' . $row['permission']])) |
|
| 2767 | - continue; |
|
| 2838 | + if (!isset($txt['permissionname_' . $row['permission']])) { |
|
| 2839 | + continue; |
|
| 2840 | + } |
|
| 2768 | 2841 | |
| 2769 | - if (empty($row['add_deny'])) |
|
| 2770 | - $denied[] = $row['permission']; |
|
| 2842 | + if (empty($row['add_deny'])) { |
|
| 2843 | + $denied[] = $row['permission']; |
|
| 2844 | + } |
|
| 2771 | 2845 | |
| 2772 | 2846 | // Permissions that end with _own or _any consist of two parts. |
| 2773 | - if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) |
|
| 2774 | - $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']]; |
|
| 2775 | - else |
|
| 2776 | - $name = $txt['permissionname_' . $row['permission']]; |
|
| 2847 | + if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) { |
|
| 2848 | + $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']]; |
|
| 2849 | + } else { |
|
| 2850 | + $name = $txt['permissionname_' . $row['permission']]; |
|
| 2851 | + } |
|
| 2777 | 2852 | |
| 2778 | 2853 | // Add this permission if it doesn't exist yet. |
| 2779 | - if (!isset($context['member']['permissions']['general'][$row['permission']])) |
|
| 2780 | - $context['member']['permissions']['general'][$row['permission']] = array( |
|
| 2854 | + if (!isset($context['member']['permissions']['general'][$row['permission']])) { |
|
| 2855 | + $context['member']['permissions']['general'][$row['permission']] = array( |
|
| 2781 | 2856 | 'id' => $row['permission'], |
| 2782 | 2857 | 'groups' => array( |
| 2783 | 2858 | 'allowed' => array(), |
@@ -2787,6 +2862,7 @@ discard block |
||
| 2787 | 2862 | 'is_denied' => false, |
| 2788 | 2863 | 'is_global' => true, |
| 2789 | 2864 | ); |
| 2865 | + } |
|
| 2790 | 2866 | |
| 2791 | 2867 | // Add the membergroup to either the denied or the allowed groups. |
| 2792 | 2868 | $context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name']; |
@@ -2820,18 +2896,20 @@ discard block |
||
| 2820 | 2896 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2821 | 2897 | { |
| 2822 | 2898 | // We don't know about this permission, it doesn't exist :P. |
| 2823 | - if (!isset($txt['permissionname_' . $row['permission']])) |
|
| 2824 | - continue; |
|
| 2899 | + if (!isset($txt['permissionname_' . $row['permission']])) { |
|
| 2900 | + continue; |
|
| 2901 | + } |
|
| 2825 | 2902 | |
| 2826 | 2903 | // The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'. |
| 2827 | - if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) |
|
| 2828 | - $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']]; |
|
| 2829 | - else |
|
| 2830 | - $name = $txt['permissionname_' . $row['permission']]; |
|
| 2904 | + if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) { |
|
| 2905 | + $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']]; |
|
| 2906 | + } else { |
|
| 2907 | + $name = $txt['permissionname_' . $row['permission']]; |
|
| 2908 | + } |
|
| 2831 | 2909 | |
| 2832 | 2910 | // Create the structure for this permission. |
| 2833 | - if (!isset($context['member']['permissions']['board'][$row['permission']])) |
|
| 2834 | - $context['member']['permissions']['board'][$row['permission']] = array( |
|
| 2911 | + if (!isset($context['member']['permissions']['board'][$row['permission']])) { |
|
| 2912 | + $context['member']['permissions']['board'][$row['permission']] = array( |
|
| 2835 | 2913 | 'id' => $row['permission'], |
| 2836 | 2914 | 'groups' => array( |
| 2837 | 2915 | 'allowed' => array(), |
@@ -2841,6 +2919,7 @@ discard block |
||
| 2841 | 2919 | 'is_denied' => false, |
| 2842 | 2920 | 'is_global' => empty($board), |
| 2843 | 2921 | ); |
| 2922 | + } |
|
| 2844 | 2923 | |
| 2845 | 2924 | $context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name']; |
| 2846 | 2925 | |
@@ -2859,8 +2938,9 @@ discard block |
||
| 2859 | 2938 | global $modSettings, $context, $sourcedir, $txt, $scripturl; |
| 2860 | 2939 | |
| 2861 | 2940 | // Firstly, can we actually even be here? |
| 2862 | - if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) |
|
| 2863 | - fatal_lang_error('no_access', false); |
|
| 2941 | + if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) { |
|
| 2942 | + fatal_lang_error('no_access', false); |
|
| 2943 | + } |
|
| 2864 | 2944 | |
| 2865 | 2945 | // Make sure things which are disabled stay disabled. |
| 2866 | 2946 | $modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110; |
@@ -2947,9 +3027,10 @@ discard block |
||
| 2947 | 3027 | $modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'], |
| 2948 | 3028 | ); |
| 2949 | 3029 | $context['current_level'] = 0; |
| 2950 | - foreach ($context['level_effects'] as $limit => $dummy) |
|
| 2951 | - if ($context['member']['warning'] >= $limit) |
|
| 3030 | + foreach ($context['level_effects'] as $limit => $dummy) { |
|
| 3031 | + if ($context['member']['warning'] >= $limit) |
|
| 2952 | 3032 | $context['current_level'] = $limit; |
| 2953 | -} |
|
| 3033 | + } |
|
| 3034 | + } |
|
| 2954 | 3035 | |
| 2955 | 3036 | ?> |
| 2956 | 3037 | \ No newline at end of file |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * This is the notoriously defunct package manager..... :/. |
@@ -57,10 +58,11 @@ discard block |
||
| 57 | 58 | ); |
| 58 | 59 | |
| 59 | 60 | // Work out exactly who it is we are calling. |
| 60 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
| 61 | - $context['sub_action'] = $_REQUEST['sa']; |
|
| 62 | - else |
|
| 63 | - $context['sub_action'] = 'browse'; |
|
| 61 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
| 62 | + $context['sub_action'] = $_REQUEST['sa']; |
|
| 63 | + } else { |
|
| 64 | + $context['sub_action'] = 'browse'; |
|
| 65 | + } |
|
| 64 | 66 | |
| 65 | 67 | // Set up some tabs... |
| 66 | 68 | $context[$context['admin_menu_name']]['tab_data'] = array( |
@@ -82,8 +84,9 @@ discard block |
||
| 82 | 84 | ), |
| 83 | 85 | ); |
| 84 | 86 | |
| 85 | - if ($context['sub_action'] == 'browse') |
|
| 86 | - loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
|
| 87 | + if ($context['sub_action'] == 'browse') { |
|
| 88 | + loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
|
| 89 | + } |
|
| 87 | 90 | |
| 88 | 91 | call_integration_hook('integrate_manage_packages', array(&$subActions)); |
| 89 | 92 | |
@@ -99,8 +102,9 @@ discard block |
||
| 99 | 102 | global $boarddir, $txt, $context, $scripturl, $sourcedir, $packagesdir, $modSettings, $smcFunc, $settings; |
| 100 | 103 | |
| 101 | 104 | // You have to specify a file!! |
| 102 | - if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') |
|
| 103 | - redirectexit('action=admin;area=packages'); |
|
| 105 | + if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') { |
|
| 106 | + redirectexit('action=admin;area=packages'); |
|
| 107 | + } |
|
| 104 | 108 | $context['filename'] = preg_replace('~[\.]+~', '.', $_REQUEST['package']); |
| 105 | 109 | |
| 106 | 110 | // Do we have an existing id, for uninstalls and the like. |
@@ -112,8 +116,9 @@ discard block |
||
| 112 | 116 | create_chmod_control(); |
| 113 | 117 | |
| 114 | 118 | // Make sure temp directory exists and is empty. |
| 115 | - if (file_exists($packagesdir . '/temp')) |
|
| 116 | - deltree($packagesdir . '/temp', false); |
|
| 119 | + if (file_exists($packagesdir . '/temp')) { |
|
| 120 | + deltree($packagesdir . '/temp', false); |
|
| 121 | + } |
|
| 117 | 122 | |
| 118 | 123 | if (!mktree($packagesdir . '/temp', 0755)) |
| 119 | 124 | { |
@@ -124,8 +129,9 @@ discard block |
||
| 124 | 129 | create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package'], 'crash_on_error' => true)); |
| 125 | 130 | |
| 126 | 131 | deltree($packagesdir . '/temp', false); |
| 127 | - if (!mktree($packagesdir . '/temp', 0777)) |
|
| 128 | - fatal_lang_error('package_cant_download', false); |
|
| 132 | + if (!mktree($packagesdir . '/temp', 0777)) { |
|
| 133 | + fatal_lang_error('package_cant_download', false); |
|
| 134 | + } |
|
| 129 | 135 | } |
| 130 | 136 | } |
| 131 | 137 | |
@@ -151,25 +157,26 @@ discard block |
||
| 151 | 157 | { |
| 152 | 158 | $context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
| 153 | 159 | |
| 154 | - if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) |
|
| 155 | - foreach ($context['extracted_files'] as $file) |
|
| 160 | + if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) { |
|
| 161 | + foreach ($context['extracted_files'] as $file) |
|
| 156 | 162 | if (basename($file['filename']) == 'package-info.xml') |
| 157 | 163 | { |
| 158 | 164 | $context['base_path'] = dirname($file['filename']) . '/'; |
| 165 | + } |
|
| 159 | 166 | break; |
| 160 | 167 | } |
| 161 | 168 | |
| 162 | - if (!isset($context['base_path'])) |
|
| 163 | - $context['base_path'] = ''; |
|
| 164 | - } |
|
| 165 | - elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
| 169 | + if (!isset($context['base_path'])) { |
|
| 170 | + $context['base_path'] = ''; |
|
| 171 | + } |
|
| 172 | + } elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
| 166 | 173 | { |
| 167 | 174 | copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
| 168 | 175 | $context['extracted_files'] = listtree($packagesdir . '/temp'); |
| 169 | 176 | $context['base_path'] = ''; |
| 177 | + } else { |
|
| 178 | + fatal_lang_error('no_access', false); |
|
| 170 | 179 | } |
| 171 | - else |
|
| 172 | - fatal_lang_error('no_access', false); |
|
| 173 | 180 | |
| 174 | 181 | // Load up any custom themes we may want to install into... |
| 175 | 182 | $request = $smcFunc['db_query']('', ' |
@@ -185,15 +192,17 @@ discard block |
||
| 185 | 192 | ) |
| 186 | 193 | ); |
| 187 | 194 | $theme_paths = array(); |
| 188 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 189 | - $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
| 195 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 196 | + $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
| 197 | + } |
|
| 190 | 198 | $smcFunc['db_free_result']($request); |
| 191 | 199 | |
| 192 | 200 | // Get the package info... |
| 193 | 201 | $packageInfo = getPackageInfo($context['filename']); |
| 194 | 202 | |
| 195 | - if (!is_array($packageInfo)) |
|
| 196 | - fatal_lang_error($packageInfo); |
|
| 203 | + if (!is_array($packageInfo)) { |
|
| 204 | + fatal_lang_error($packageInfo); |
|
| 205 | + } |
|
| 197 | 206 | |
| 198 | 207 | $packageInfo['filename'] = $context['filename']; |
| 199 | 208 | $context['package_name'] = isset($packageInfo['name']) ? $packageInfo['name'] : $context['filename']; |
@@ -227,18 +236,19 @@ discard block |
||
| 227 | 236 | $smcFunc['db_free_result']($request); |
| 228 | 237 | |
| 229 | 238 | $context['database_changes'] = array(); |
| 230 | - if (isset($packageInfo['uninstall']['database'])) |
|
| 231 | - $context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database']; |
|
| 232 | - elseif (!empty($db_changes)) |
|
| 239 | + if (isset($packageInfo['uninstall']['database'])) { |
|
| 240 | + $context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database']; |
|
| 241 | + } elseif (!empty($db_changes)) |
|
| 233 | 242 | { |
| 234 | 243 | foreach ($db_changes as $change) |
| 235 | 244 | { |
| 236 | - if (isset($change[2]) && isset($txt['package_db_' . $change[0]])) |
|
| 237 | - $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]); |
|
| 238 | - elseif (isset($txt['package_db_' . $change[0]])) |
|
| 239 | - $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]); |
|
| 240 | - else |
|
| 241 | - $context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : ''); |
|
| 245 | + if (isset($change[2]) && isset($txt['package_db_' . $change[0]])) { |
|
| 246 | + $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]); |
|
| 247 | + } elseif (isset($txt['package_db_' . $change[0]])) { |
|
| 248 | + $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]); |
|
| 249 | + } else { |
|
| 250 | + $context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : ''); |
|
| 251 | + } |
|
| 242 | 252 | } |
| 243 | 253 | } |
| 244 | 254 | |
@@ -265,31 +275,33 @@ discard block |
||
| 265 | 275 | $context['themes_locked'] = true; |
| 266 | 276 | |
| 267 | 277 | // Only let them uninstall themes it was installed into. |
| 268 | - foreach ($theme_paths as $id => $data) |
|
| 269 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
| 278 | + foreach ($theme_paths as $id => $data) { |
|
| 279 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
| 270 | 280 | unset($theme_paths[$id]); |
| 271 | - } |
|
| 272 | - elseif (isset($old_version) && $old_version != $packageInfo['version']) |
|
| 281 | + } |
|
| 282 | + } elseif (isset($old_version) && $old_version != $packageInfo['version']) |
|
| 273 | 283 | { |
| 274 | 284 | // Look for an upgrade... |
| 275 | 285 | $actions = parsePackageInfo($packageInfo['xml'], true, 'upgrade', $old_version); |
| 276 | 286 | |
| 277 | 287 | // There was no upgrade.... |
| 278 | - if (empty($actions)) |
|
| 279 | - $context['is_installed'] = true; |
|
| 280 | - else |
|
| 288 | + if (empty($actions)) { |
|
| 289 | + $context['is_installed'] = true; |
|
| 290 | + } else |
|
| 281 | 291 | { |
| 282 | 292 | // Otherwise they can only upgrade themes from the first time around. |
| 283 | - foreach ($theme_paths as $id => $data) |
|
| 284 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
| 293 | + foreach ($theme_paths as $id => $data) { |
|
| 294 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
| 285 | 295 | unset($theme_paths[$id]); |
| 296 | + } |
|
| 286 | 297 | } |
| 298 | + } elseif (isset($old_version) && $old_version == $packageInfo['version']) { |
|
| 299 | + $context['is_installed'] = true; |
|
| 287 | 300 | } |
| 288 | - elseif (isset($old_version) && $old_version == $packageInfo['version']) |
|
| 289 | - $context['is_installed'] = true; |
|
| 290 | 301 | |
| 291 | - if (!isset($old_version) || $context['is_installed']) |
|
| 292 | - $actions = parsePackageInfo($packageInfo['xml'], true, 'install'); |
|
| 302 | + if (!isset($old_version) || $context['is_installed']) { |
|
| 303 | + $actions = parsePackageInfo($packageInfo['xml'], true, 'install'); |
|
| 304 | + } |
|
| 293 | 305 | |
| 294 | 306 | $context['actions'] = array(); |
| 295 | 307 | $context['ftp_needed'] = false; |
@@ -297,8 +309,9 @@ discard block |
||
| 297 | 309 | $chmod_files = array(); |
| 298 | 310 | |
| 299 | 311 | // no actions found, return so we can display an error |
| 300 | - if (empty($actions)) |
|
| 301 | - return; |
|
| 312 | + if (empty($actions)) { |
|
| 313 | + return; |
|
| 314 | + } |
|
| 302 | 315 | |
| 303 | 316 | // This will hold data about anything that can be installed in other themes. |
| 304 | 317 | $themeFinds = array( |
@@ -317,14 +330,14 @@ discard block |
||
| 317 | 330 | { |
| 318 | 331 | $chmod_files[] = $action['filename']; |
| 319 | 332 | continue; |
| 320 | - } |
|
| 321 | - elseif ($action['type'] == 'readme' || $action['type'] == 'license') |
|
| 333 | + } elseif ($action['type'] == 'readme' || $action['type'] == 'license') |
|
| 322 | 334 | { |
| 323 | 335 | $type = 'package_' . $action['type']; |
| 324 | - if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) |
|
| 325 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), "\n\r")); |
|
| 326 | - elseif (file_exists($action['filename'])) |
|
| 327 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
| 336 | + if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) { |
|
| 337 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), "\n\r")); |
|
| 338 | + } elseif (file_exists($action['filename'])) { |
|
| 339 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
| 340 | + } |
|
| 328 | 341 | |
| 329 | 342 | if (!empty($action['parse_bbc'])) |
| 330 | 343 | { |
@@ -332,24 +345,24 @@ discard block |
||
| 332 | 345 | $context[$type] = preg_replace('~\[[/]?html\]~i', '', $context[$type]); |
| 333 | 346 | preparsecode($context[$type]); |
| 334 | 347 | $context[$type] = parse_bbc($context[$type]); |
| 348 | + } else { |
|
| 349 | + $context[$type] = nl2br($context[$type]); |
|
| 335 | 350 | } |
| 336 | - else |
|
| 337 | - $context[$type] = nl2br($context[$type]); |
|
| 338 | 351 | |
| 339 | 352 | continue; |
| 340 | 353 | } |
| 341 | 354 | // Don't show redirects. |
| 342 | - elseif ($action['type'] == 'redirect') |
|
| 343 | - continue; |
|
| 344 | - elseif ($action['type'] == 'error') |
|
| 355 | + elseif ($action['type'] == 'redirect') { |
|
| 356 | + continue; |
|
| 357 | + } elseif ($action['type'] == 'error') |
|
| 345 | 358 | { |
| 346 | 359 | $context['has_failure'] = true; |
| 347 | - if (isset($action['error_msg']) && isset($action['error_var'])) |
|
| 348 | - $context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']); |
|
| 349 | - elseif (isset($action['error_msg'])) |
|
| 350 | - $context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg']; |
|
| 351 | - } |
|
| 352 | - elseif ($action['type'] == 'modification') |
|
| 360 | + if (isset($action['error_msg']) && isset($action['error_var'])) { |
|
| 361 | + $context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']); |
|
| 362 | + } elseif (isset($action['error_msg'])) { |
|
| 363 | + $context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg']; |
|
| 364 | + } |
|
| 365 | + } elseif ($action['type'] == 'modification') |
|
| 353 | 366 | { |
| 354 | 367 | if (!file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) |
| 355 | 368 | { |
@@ -361,52 +374,54 @@ discard block |
||
| 361 | 374 | 'description' => $txt['package_action_missing'], |
| 362 | 375 | 'failed' => true, |
| 363 | 376 | ); |
| 364 | - } |
|
| 365 | - else |
|
| 377 | + } else |
|
| 366 | 378 | { |
| 367 | 379 | |
| 368 | - if ($action['boardmod']) |
|
| 369 | - $mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths); |
|
| 370 | - else |
|
| 371 | - $mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths); |
|
| 380 | + if ($action['boardmod']) { |
|
| 381 | + $mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths); |
|
| 382 | + } else { |
|
| 383 | + $mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths); |
|
| 384 | + } |
|
| 372 | 385 | |
| 373 | - if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-') |
|
| 374 | - $mod_actions[0]['filename'] = $action['filename']; |
|
| 386 | + if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-') { |
|
| 387 | + $mod_actions[0]['filename'] = $action['filename']; |
|
| 388 | + } |
|
| 375 | 389 | |
| 376 | 390 | foreach ($mod_actions as $key => $mod_action) |
| 377 | 391 | { |
| 378 | 392 | // Lets get the last section of the file name. |
| 379 | - if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') |
|
| 380 | - $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']); |
|
| 381 | - elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) |
|
| 382 | - $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']); |
|
| 383 | - else |
|
| 384 | - $actual_filename = $key; |
|
| 385 | - |
|
| 386 | - if ($mod_action['type'] == 'opened') |
|
| 387 | - $failed = false; |
|
| 388 | - elseif ($mod_action['type'] == 'failure') |
|
| 393 | + if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') { |
|
| 394 | + $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']); |
|
| 395 | + } elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) { |
|
| 396 | + $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']); |
|
| 397 | + } else { |
|
| 398 | + $actual_filename = $key; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + if ($mod_action['type'] == 'opened') { |
|
| 402 | + $failed = false; |
|
| 403 | + } elseif ($mod_action['type'] == 'failure') |
|
| 389 | 404 | { |
| 390 | - if (empty($mod_action['is_custom'])) |
|
| 391 | - $context['has_failure'] = true; |
|
| 405 | + if (empty($mod_action['is_custom'])) { |
|
| 406 | + $context['has_failure'] = true; |
|
| 407 | + } |
|
| 392 | 408 | $failed = true; |
| 393 | - } |
|
| 394 | - elseif ($mod_action['type'] == 'chmod') |
|
| 409 | + } elseif ($mod_action['type'] == 'chmod') |
|
| 395 | 410 | { |
| 396 | 411 | $chmod_files[] = $mod_action['filename']; |
| 397 | - } |
|
| 398 | - elseif ($mod_action['type'] == 'saved') |
|
| 412 | + } elseif ($mod_action['type'] == 'saved') |
|
| 399 | 413 | { |
| 400 | 414 | if (!empty($mod_action['is_custom'])) |
| 401 | 415 | { |
| 402 | - if (!isset($context['theme_actions'][$mod_action['is_custom']])) |
|
| 403 | - $context['theme_actions'][$mod_action['is_custom']] = array( |
|
| 416 | + if (!isset($context['theme_actions'][$mod_action['is_custom']])) { |
|
| 417 | + $context['theme_actions'][$mod_action['is_custom']] = array( |
|
| 404 | 418 | 'name' => $theme_paths[$mod_action['is_custom']]['name'], |
| 405 | 419 | 'actions' => array(), |
| 406 | 420 | 'has_failure' => $failed, |
| 407 | 421 | ); |
| 408 | - else |
|
| 409 | - $context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed; |
|
| 422 | + } else { |
|
| 423 | + $context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed; |
|
| 424 | + } |
|
| 410 | 425 | |
| 411 | 426 | $context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename] = array( |
| 412 | 427 | 'type' => $txt['execute_modification'], |
@@ -414,8 +429,7 @@ discard block |
||
| 414 | 429 | 'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'], |
| 415 | 430 | 'failed' => $failed, |
| 416 | 431 | ); |
| 417 | - } |
|
| 418 | - elseif (!isset($context['actions'][$actual_filename])) |
|
| 432 | + } elseif (!isset($context['actions'][$actual_filename])) |
|
| 419 | 433 | { |
| 420 | 434 | $context['actions'][$actual_filename] = array( |
| 421 | 435 | 'type' => $txt['execute_modification'], |
@@ -423,22 +437,19 @@ discard block |
||
| 423 | 437 | 'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'], |
| 424 | 438 | 'failed' => $failed, |
| 425 | 439 | ); |
| 426 | - } |
|
| 427 | - else |
|
| 440 | + } else |
|
| 428 | 441 | { |
| 429 | 442 | $context['actions'][$actual_filename]['failed'] |= $failed; |
| 430 | 443 | $context['actions'][$actual_filename]['description'] = $context['actions'][$actual_filename]['failed'] ? $txt['package_action_failure'] : $txt['package_action_success']; |
| 431 | 444 | } |
| 432 | - } |
|
| 433 | - elseif ($mod_action['type'] == 'skipping') |
|
| 445 | + } elseif ($mod_action['type'] == 'skipping') |
|
| 434 | 446 | { |
| 435 | 447 | $context['actions'][$actual_filename] = array( |
| 436 | 448 | 'type' => $txt['execute_modification'], |
| 437 | 449 | 'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))), |
| 438 | 450 | 'description' => $txt['package_action_skipping'] |
| 439 | 451 | ); |
| 440 | - } |
|
| 441 | - elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom'])) |
|
| 452 | + } elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom'])) |
|
| 442 | 453 | { |
| 443 | 454 | $context['has_failure'] = true; |
| 444 | 455 | $context['actions'][$actual_filename] = array( |
@@ -447,32 +458,33 @@ discard block |
||
| 447 | 458 | 'description' => $txt['package_action_missing'], |
| 448 | 459 | 'failed' => true, |
| 449 | 460 | ); |
| 450 | - } |
|
| 451 | - elseif ($mod_action['type'] == 'error') |
|
| 452 | - $context['actions'][$actual_filename] = array( |
|
| 461 | + } elseif ($mod_action['type'] == 'error') { |
|
| 462 | + $context['actions'][$actual_filename] = array( |
|
| 453 | 463 | 'type' => $txt['execute_modification'], |
| 454 | 464 | 'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))), |
| 455 | 465 | 'description' => $txt['package_action_error'], |
| 456 | 466 | 'failed' => true, |
| 457 | 467 | ); |
| 468 | + } |
|
| 458 | 469 | } |
| 459 | 470 | |
| 460 | 471 | // We need to loop again just to get the operations down correctly. |
| 461 | 472 | foreach ($mod_actions as $operation_key => $mod_action) |
| 462 | 473 | { |
| 463 | 474 | // Lets get the last section of the file name. |
| 464 | - if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') |
|
| 465 | - $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']); |
|
| 466 | - elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) |
|
| 467 | - $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']); |
|
| 468 | - else |
|
| 469 | - $actual_filename = $key; |
|
| 475 | + if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') { |
|
| 476 | + $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']); |
|
| 477 | + } elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) { |
|
| 478 | + $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']); |
|
| 479 | + } else { |
|
| 480 | + $actual_filename = $key; |
|
| 481 | + } |
|
| 470 | 482 | |
| 471 | 483 | // We just need it for actual parse changes. |
| 472 | 484 | if (!in_array($mod_action['type'], array('error', 'result', 'opened', 'saved', 'end', 'missing', 'skipping', 'chmod'))) |
| 473 | 485 | { |
| 474 | - if (empty($mod_action['is_custom'])) |
|
| 475 | - $context['actions'][$actual_filename]['operations'][] = array( |
|
| 486 | + if (empty($mod_action['is_custom'])) { |
|
| 487 | + $context['actions'][$actual_filename]['operations'][] = array( |
|
| 476 | 488 | 'type' => $txt['execute_modification'], |
| 477 | 489 | 'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))), |
| 478 | 490 | 'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'], |
@@ -483,10 +495,11 @@ discard block |
||
| 483 | 495 | 'failed' => $mod_action['failed'], |
| 484 | 496 | 'ignore_failure' => !empty($mod_action['ignore_failure']), |
| 485 | 497 | ); |
| 498 | + } |
|
| 486 | 499 | |
| 487 | 500 | // Themes are under the saved type. |
| 488 | - if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']])) |
|
| 489 | - $context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array( |
|
| 501 | + if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']])) { |
|
| 502 | + $context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array( |
|
| 490 | 503 | 'type' => $txt['execute_modification'], |
| 491 | 504 | 'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))), |
| 492 | 505 | 'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'], |
@@ -497,59 +510,55 @@ discard block |
||
| 497 | 510 | 'failed' => $mod_action['failed'], |
| 498 | 511 | 'ignore_failure' => !empty($mod_action['ignore_failure']), |
| 499 | 512 | ); |
| 513 | + } |
|
| 500 | 514 | } |
| 501 | 515 | } |
| 502 | 516 | } |
| 503 | - } |
|
| 504 | - elseif ($action['type'] == 'code') |
|
| 517 | + } elseif ($action['type'] == 'code') |
|
| 505 | 518 | { |
| 506 | 519 | $thisAction = array( |
| 507 | 520 | 'type' => $txt['execute_code'], |
| 508 | 521 | 'action' => $smcFunc['htmlspecialchars']($action['filename']), |
| 509 | 522 | ); |
| 510 | - } |
|
| 511 | - elseif ($action['type'] == 'database') |
|
| 523 | + } elseif ($action['type'] == 'database') |
|
| 512 | 524 | { |
| 513 | 525 | $thisAction = array( |
| 514 | 526 | 'type' => $txt['execute_database_changes'], |
| 515 | 527 | 'action' => $smcFunc['htmlspecialchars']($action['filename']), |
| 516 | 528 | ); |
| 517 | - } |
|
| 518 | - elseif (in_array($action['type'], array('create-dir', 'create-file'))) |
|
| 529 | + } elseif (in_array($action['type'], array('create-dir', 'create-file'))) |
|
| 519 | 530 | { |
| 520 | 531 | $thisAction = array( |
| 521 | 532 | 'type' => $txt['package_create'] . ' ' . ($action['type'] == 'create-dir' ? $txt['package_tree'] : $txt['package_file']), |
| 522 | 533 | 'action' => $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.'))) |
| 523 | 534 | ); |
| 524 | - } |
|
| 525 | - elseif ($action['type'] == 'hook') |
|
| 535 | + } elseif ($action['type'] == 'hook') |
|
| 526 | 536 | { |
| 527 | 537 | $action['description'] = !isset($action['hook'], $action['function']) ? $txt['package_action_failure'] : $txt['package_action_success']; |
| 528 | 538 | |
| 529 | - if (!isset($action['hook'], $action['function'])) |
|
| 530 | - $context['has_failure'] = true; |
|
| 539 | + if (!isset($action['hook'], $action['function'])) { |
|
| 540 | + $context['has_failure'] = true; |
|
| 541 | + } |
|
| 531 | 542 | |
| 532 | 543 | $thisAction = array( |
| 533 | 544 | 'type' => $action['reverse'] ? $txt['execute_hook_remove'] : $txt['execute_hook_add'], |
| 534 | 545 | 'action' => sprintf($txt['execute_hook_action'. ($action['reverse'] ? '_inverse' : '')], $smcFunc['htmlspecialchars']($action['hook'])), |
| 535 | 546 | ); |
| 536 | - } |
|
| 537 | - elseif ($action['type'] == 'credits') |
|
| 547 | + } elseif ($action['type'] == 'credits') |
|
| 538 | 548 | { |
| 539 | 549 | $thisAction = array( |
| 540 | 550 | 'type' => $txt['execute_credits_add'], |
| 541 | 551 | 'action' => sprintf($txt['execute_credits_action'], $smcFunc['htmlspecialchars']($action['title'])), |
| 542 | 552 | ); |
| 543 | - } |
|
| 544 | - elseif ($action['type'] == 'requires') |
|
| 553 | + } elseif ($action['type'] == 'requires') |
|
| 545 | 554 | { |
| 546 | 555 | $installed = false; |
| 547 | 556 | $version = true; |
| 548 | 557 | |
| 549 | 558 | // package missing required values? |
| 550 | - if (!isset($action['id'])) |
|
| 551 | - $context['has_failure'] = true; |
|
| 552 | - else |
|
| 559 | + if (!isset($action['id'])) { |
|
| 560 | + $context['has_failure'] = true; |
|
| 561 | + } else |
|
| 553 | 562 | { |
| 554 | 563 | // See if this dependancy is installed |
| 555 | 564 | $request = $smcFunc['db_query']('', ' |
@@ -565,8 +574,9 @@ discard block |
||
| 565 | 574 | ) |
| 566 | 575 | ); |
| 567 | 576 | $installed = ($smcFunc['db_num_rows']($request) !== 0); |
| 568 | - if ($installed) |
|
| 569 | - list ($version) = $smcFunc['db_fetch_row']($request); |
|
| 577 | + if ($installed) { |
|
| 578 | + list ($version) = $smcFunc['db_fetch_row']($request); |
|
| 579 | + } |
|
| 570 | 580 | $smcFunc['db_free_result']($request); |
| 571 | 581 | |
| 572 | 582 | // do a version level check (if requested) in the most basic way |
@@ -581,8 +591,7 @@ discard block |
||
| 581 | 591 | 'type' => $txt['package_requires'], |
| 582 | 592 | 'action' => $txt['package_check_for'] . ' ' . $action['id'] . (isset($action['version']) ? (' / ' . ($version ? $action['version'] : '<span class="error">' . $action['version'] . '</span>')) : ''), |
| 583 | 593 | ); |
| 584 | - } |
|
| 585 | - elseif (in_array($action['type'], array('require-dir', 'require-file'))) |
|
| 594 | + } elseif (in_array($action['type'], array('require-dir', 'require-file'))) |
|
| 586 | 595 | { |
| 587 | 596 | // Do this one... |
| 588 | 597 | $thisAction = array( |
@@ -596,26 +605,29 @@ discard block |
||
| 596 | 605 | // Is the action already stated? |
| 597 | 606 | $theme_action = !empty($action['theme_action']) && in_array($action['theme_action'], array('no', 'yes', 'auto')) ? $action['theme_action'] : 'auto'; |
| 598 | 607 | // If it's not auto do we think we have something we can act upon? |
| 599 | - if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) |
|
| 600 | - $theme_action = ''; |
|
| 608 | + if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) { |
|
| 609 | + $theme_action = ''; |
|
| 610 | + } |
|
| 601 | 611 | // ... or if it's auto do we even want to do anything? |
| 602 | - elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') |
|
| 603 | - $theme_action = ''; |
|
| 612 | + elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') { |
|
| 613 | + $theme_action = ''; |
|
| 614 | + } |
|
| 604 | 615 | |
| 605 | 616 | // So, we still want to do something? |
| 606 | - if ($theme_action != '') |
|
| 607 | - $themeFinds['candidates'][] = $action; |
|
| 617 | + if ($theme_action != '') { |
|
| 618 | + $themeFinds['candidates'][] = $action; |
|
| 619 | + } |
|
| 608 | 620 | // Otherwise is this is going into another theme record it. |
| 609 | - elseif ($matches[1] == 'themes_dir') |
|
| 610 | - $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename'])); |
|
| 621 | + elseif ($matches[1] == 'themes_dir') { |
|
| 622 | + $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename'])); |
|
| 623 | + } |
|
| 611 | 624 | } |
| 612 | - } |
|
| 613 | - elseif (in_array($action['type'], array('move-dir', 'move-file'))) |
|
| 614 | - $thisAction = array( |
|
| 625 | + } elseif (in_array($action['type'], array('move-dir', 'move-file'))) { |
|
| 626 | + $thisAction = array( |
|
| 615 | 627 | 'type' => $txt['package_move'] . ' ' . ($action['type'] == 'move-dir' ? $txt['package_tree'] : $txt['package_file']), |
| 616 | 628 | 'action' => $smcFunc['htmlspecialchars'](strtr($action['source'], array($boarddir => '.'))) . ' => ' . $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.'))) |
| 617 | 629 | ); |
| 618 | - elseif (in_array($action['type'], array('remove-dir', 'remove-file'))) |
|
| 630 | + } elseif (in_array($action['type'], array('remove-dir', 'remove-file'))) |
|
| 619 | 631 | { |
| 620 | 632 | $thisAction = array( |
| 621 | 633 | 'type' => $txt['package_delete'] . ' ' . ($action['type'] == 'remove-dir' ? $txt['package_tree'] : $txt['package_file']), |
@@ -631,30 +643,36 @@ discard block |
||
| 631 | 643 | $action['unparsed_destination'] = $action['unparsed_filename']; |
| 632 | 644 | |
| 633 | 645 | // If it's not auto do we think we have something we can act upon? |
| 634 | - if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) |
|
| 635 | - $theme_action = ''; |
|
| 646 | + if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) { |
|
| 647 | + $theme_action = ''; |
|
| 648 | + } |
|
| 636 | 649 | // ... or if it's auto do we even want to do anything? |
| 637 | - elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') |
|
| 638 | - $theme_action = ''; |
|
| 650 | + elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') { |
|
| 651 | + $theme_action = ''; |
|
| 652 | + } |
|
| 639 | 653 | |
| 640 | 654 | // So, we still want to do something? |
| 641 | - if ($theme_action != '') |
|
| 642 | - $themeFinds['candidates'][] = $action; |
|
| 655 | + if ($theme_action != '') { |
|
| 656 | + $themeFinds['candidates'][] = $action; |
|
| 657 | + } |
|
| 643 | 658 | // Otherwise is this is going into another theme record it. |
| 644 | - elseif ($matches[1] == 'themes_dir') |
|
| 645 | - $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename'])); |
|
| 659 | + elseif ($matches[1] == 'themes_dir') { |
|
| 660 | + $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename'])); |
|
| 661 | + } |
|
| 646 | 662 | } |
| 647 | 663 | } |
| 648 | 664 | |
| 649 | - if (empty($thisAction)) |
|
| 650 | - continue; |
|
| 665 | + if (empty($thisAction)) { |
|
| 666 | + continue; |
|
| 667 | + } |
|
| 651 | 668 | |
| 652 | 669 | if (!in_array($action['type'], array('hook', 'credits'))) |
| 653 | 670 | { |
| 654 | - if ($context['uninstalling']) |
|
| 655 | - $file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : $packagesdir . '/temp/' . $context['base_path'] . $action['filename']; |
|
| 656 | - else |
|
| 657 | - $file = $packagesdir . '/temp/' . $context['base_path'] . $action['filename']; |
|
| 671 | + if ($context['uninstalling']) { |
|
| 672 | + $file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : $packagesdir . '/temp/' . $context['base_path'] . $action['filename']; |
|
| 673 | + } else { |
|
| 674 | + $file = $packagesdir . '/temp/' . $context['base_path'] . $action['filename']; |
|
| 675 | + } |
|
| 658 | 676 | } |
| 659 | 677 | |
| 660 | 678 | // Don't fail if a file/directory we're trying to create doesn't exist... |
@@ -669,8 +687,9 @@ discard block |
||
| 669 | 687 | } |
| 670 | 688 | |
| 671 | 689 | // @todo None given? |
| 672 | - if (empty($thisAction['description'])) |
|
| 673 | - $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
| 690 | + if (empty($thisAction['description'])) { |
|
| 691 | + $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
| 692 | + } |
|
| 674 | 693 | |
| 675 | 694 | $context['actions'][] = $thisAction; |
| 676 | 695 | } |
@@ -683,18 +702,21 @@ discard block |
||
| 683 | 702 | // Get the part of the file we'll be dealing with. |
| 684 | 703 | preg_match('~^\$(languagedir|languages_dir|imagesdir|themedir)(\\|/)*(.+)*~i', $action_data['unparsed_destination'], $matches); |
| 685 | 704 | |
| 686 | - if ($matches[1] == 'imagesdir') |
|
| 687 | - $path = '/' . basename($settings['default_images_url']); |
|
| 688 | - elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir') |
|
| 689 | - $path = '/languages'; |
|
| 690 | - else |
|
| 691 | - $path = ''; |
|
| 705 | + if ($matches[1] == 'imagesdir') { |
|
| 706 | + $path = '/' . basename($settings['default_images_url']); |
|
| 707 | + } elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir') { |
|
| 708 | + $path = '/languages'; |
|
| 709 | + } else { |
|
| 710 | + $path = ''; |
|
| 711 | + } |
|
| 692 | 712 | |
| 693 | - if (!empty($matches[3])) |
|
| 694 | - $path .= $matches[3]; |
|
| 713 | + if (!empty($matches[3])) { |
|
| 714 | + $path .= $matches[3]; |
|
| 715 | + } |
|
| 695 | 716 | |
| 696 | - if (!$context['uninstalling']) |
|
| 697 | - $path .= '/' . basename($action_data['filename']); |
|
| 717 | + if (!$context['uninstalling']) { |
|
| 718 | + $path .= '/' . basename($action_data['filename']); |
|
| 719 | + } |
|
| 698 | 720 | |
| 699 | 721 | // Loop through each custom theme to note it's candidacy! |
| 700 | 722 | foreach ($theme_paths as $id => $theme_data) |
@@ -710,36 +732,40 @@ discard block |
||
| 710 | 732 | if (!mktree(dirname($real_path), false)) |
| 711 | 733 | { |
| 712 | 734 | $temp = dirname($real_path); |
| 713 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 714 | - $temp = dirname($temp); |
|
| 735 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 736 | + $temp = dirname($temp); |
|
| 737 | + } |
|
| 715 | 738 | $chmod_files[] = $temp; |
| 716 | 739 | } |
| 717 | 740 | |
| 718 | - if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path)))) |
|
| 719 | - $chmod_files[] = $real_path; |
|
| 741 | + if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path)))) { |
|
| 742 | + $chmod_files[] = $real_path; |
|
| 743 | + } |
|
| 720 | 744 | |
| 721 | - if (!isset($context['theme_actions'][$id])) |
|
| 722 | - $context['theme_actions'][$id] = array( |
|
| 745 | + if (!isset($context['theme_actions'][$id])) { |
|
| 746 | + $context['theme_actions'][$id] = array( |
|
| 723 | 747 | 'name' => $theme_data['name'], |
| 724 | 748 | 'actions' => array(), |
| 725 | 749 | ); |
| 750 | + } |
|
| 726 | 751 | |
| 727 | - if ($context['uninstalling']) |
|
| 728 | - $context['theme_actions'][$id]['actions'][] = array( |
|
| 752 | + if ($context['uninstalling']) { |
|
| 753 | + $context['theme_actions'][$id]['actions'][] = array( |
|
| 729 | 754 | 'type' => $txt['package_delete'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']), |
| 730 | 755 | 'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')), |
| 731 | 756 | 'description' => '', |
| 732 | 757 | 'value' => base64_encode(json_encode(array('type' => $action_data['type'], 'orig' => $action_data['filename'], 'future' => $real_path, 'id' => $id))), |
| 733 | 758 | 'not_mod' => true, |
| 734 | 759 | ); |
| 735 | - else |
|
| 736 | - $context['theme_actions'][$id]['actions'][] = array( |
|
| 760 | + } else { |
|
| 761 | + $context['theme_actions'][$id]['actions'][] = array( |
|
| 737 | 762 | 'type' => $txt['package_extract'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']), |
| 738 | 763 | 'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')), |
| 739 | 764 | 'description' => '', |
| 740 | 765 | 'value' => base64_encode(json_encode(array('type' => $action_data['type'], 'orig' => $action_data['destination'], 'future' => $real_path, 'id' => $id))), |
| 741 | 766 | 'not_mod' => true, |
| 742 | 767 | ); |
| 768 | + } |
|
| 743 | 769 | } |
| 744 | 770 | } |
| 745 | 771 | } |
@@ -749,8 +775,9 @@ discard block |
||
| 749 | 775 | // Trash the cache... which will also check permissions for us! |
| 750 | 776 | package_flush_cache(true); |
| 751 | 777 | |
| 752 | - if (file_exists($packagesdir . '/temp')) |
|
| 753 | - deltree($packagesdir . '/temp'); |
|
| 778 | + if (file_exists($packagesdir . '/temp')) { |
|
| 779 | + deltree($packagesdir . '/temp'); |
|
| 780 | + } |
|
| 754 | 781 | |
| 755 | 782 | if (!empty($chmod_files)) |
| 756 | 783 | { |
@@ -775,8 +802,9 @@ discard block |
||
| 775 | 802 | checkSession(); |
| 776 | 803 | |
| 777 | 804 | // If there's no file, what are we installing? |
| 778 | - if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') |
|
| 779 | - redirectexit('action=admin;area=packages'); |
|
| 805 | + if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') { |
|
| 806 | + redirectexit('action=admin;area=packages'); |
|
| 807 | + } |
|
| 780 | 808 | $context['filename'] = $_REQUEST['package']; |
| 781 | 809 | |
| 782 | 810 | // If this is an uninstall, we'll have an id. |
@@ -797,51 +825,55 @@ discard block |
||
| 797 | 825 | |
| 798 | 826 | $context['sub_template'] = 'extract_package'; |
| 799 | 827 | |
| 800 | - if (!file_exists($packagesdir . '/' . $context['filename'])) |
|
| 801 | - fatal_lang_error('package_no_file', false); |
|
| 828 | + if (!file_exists($packagesdir . '/' . $context['filename'])) { |
|
| 829 | + fatal_lang_error('package_no_file', false); |
|
| 830 | + } |
|
| 802 | 831 | |
| 803 | 832 | // Load up the package FTP information? |
| 804 | 833 | create_chmod_control(array(), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package'])); |
| 805 | 834 | |
| 806 | 835 | // Make sure temp directory exists and is empty! |
| 807 | - if (file_exists($packagesdir . '/temp')) |
|
| 808 | - deltree($packagesdir . '/temp', false); |
|
| 809 | - else |
|
| 810 | - mktree($packagesdir . '/temp', 0777); |
|
| 836 | + if (file_exists($packagesdir . '/temp')) { |
|
| 837 | + deltree($packagesdir . '/temp', false); |
|
| 838 | + } else { |
|
| 839 | + mktree($packagesdir . '/temp', 0777); |
|
| 840 | + } |
|
| 811 | 841 | |
| 812 | 842 | // Let the unpacker do the work. |
| 813 | 843 | if (is_file($packagesdir . '/' . $context['filename'])) |
| 814 | 844 | { |
| 815 | 845 | $context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
| 816 | 846 | |
| 817 | - if (!file_exists($packagesdir . '/temp/package-info.xml')) |
|
| 818 | - foreach ($context['extracted_files'] as $file) |
|
| 847 | + if (!file_exists($packagesdir . '/temp/package-info.xml')) { |
|
| 848 | + foreach ($context['extracted_files'] as $file) |
|
| 819 | 849 | if (basename($file['filename']) == 'package-info.xml') |
| 820 | 850 | { |
| 821 | 851 | $context['base_path'] = dirname($file['filename']) . '/'; |
| 852 | + } |
|
| 822 | 853 | break; |
| 823 | 854 | } |
| 824 | 855 | |
| 825 | - if (!isset($context['base_path'])) |
|
| 826 | - $context['base_path'] = ''; |
|
| 827 | - } |
|
| 828 | - elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
| 856 | + if (!isset($context['base_path'])) { |
|
| 857 | + $context['base_path'] = ''; |
|
| 858 | + } |
|
| 859 | + } elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
| 829 | 860 | { |
| 830 | 861 | copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
| 831 | 862 | $context['extracted_files'] = listtree($packagesdir . '/temp'); |
| 832 | 863 | $context['base_path'] = ''; |
| 864 | + } else { |
|
| 865 | + fatal_lang_error('no_access', false); |
|
| 833 | 866 | } |
| 834 | - else |
|
| 835 | - fatal_lang_error('no_access', false); |
|
| 836 | 867 | |
| 837 | 868 | // Are we installing this into any custom themes? |
| 838 | 869 | $custom_themes = array(1); |
| 839 | 870 | $known_themes = explode(',', $modSettings['knownThemes']); |
| 840 | 871 | if (!empty($_POST['custom_theme'])) |
| 841 | 872 | { |
| 842 | - foreach ($_POST['custom_theme'] as $tid) |
|
| 843 | - if (in_array($tid, $known_themes)) |
|
| 873 | + foreach ($_POST['custom_theme'] as $tid) { |
|
| 874 | + if (in_array($tid, $known_themes)) |
|
| 844 | 875 | $custom_themes[] = (int) $tid; |
| 876 | + } |
|
| 845 | 877 | } |
| 846 | 878 | |
| 847 | 879 | // Now load up the paths of the themes that we need to know about. |
@@ -858,8 +890,9 @@ discard block |
||
| 858 | 890 | ); |
| 859 | 891 | $theme_paths = array(); |
| 860 | 892 | $themes_installed = array(1); |
| 861 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 862 | - $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
| 893 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 894 | + $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
| 895 | + } |
|
| 863 | 896 | $smcFunc['db_free_result']($request); |
| 864 | 897 | |
| 865 | 898 | // Are there any theme copying that we want to take place? |
@@ -871,11 +904,13 @@ discard block |
||
| 871 | 904 | { |
| 872 | 905 | foreach ($_POST['theme_changes'] as $change) |
| 873 | 906 | { |
| 874 | - if (empty($change)) |
|
| 875 | - continue; |
|
| 907 | + if (empty($change)) { |
|
| 908 | + continue; |
|
| 909 | + } |
|
| 876 | 910 | $theme_data = smf_json_decode(base64_decode($change), true); |
| 877 | - if (empty($theme_data['type'])) |
|
| 878 | - continue; |
|
| 911 | + if (empty($theme_data['type'])) { |
|
| 912 | + continue; |
|
| 913 | + } |
|
| 879 | 914 | |
| 880 | 915 | $themes_installed[] = $theme_data['id']; |
| 881 | 916 | $context['theme_copies'][$theme_data['type']][$theme_data['orig']][] = $theme_data['future']; |
@@ -884,8 +919,9 @@ discard block |
||
| 884 | 919 | |
| 885 | 920 | // Get the package info... |
| 886 | 921 | $packageInfo = getPackageInfo($context['filename']); |
| 887 | - if (!is_array($packageInfo)) |
|
| 888 | - fatal_lang_error($packageInfo); |
|
| 922 | + if (!is_array($packageInfo)) { |
|
| 923 | + fatal_lang_error($packageInfo); |
|
| 924 | + } |
|
| 889 | 925 | |
| 890 | 926 | $packageInfo['filename'] = $context['filename']; |
| 891 | 927 | |
@@ -897,8 +933,9 @@ discard block |
||
| 897 | 933 | { |
| 898 | 934 | $_SESSION['last_backup_for'] = $context['filename'] . ($context['uninstalling'] ? '$$' : '$'); |
| 899 | 935 | $result = package_create_backup(($context['uninstalling'] ? 'backup_' : 'before_') . strtok($context['filename'], '.')); |
| 900 | - if (!$result) |
|
| 901 | - fatal_lang_error('could_not_package_backup', false); |
|
| 936 | + if (!$result) { |
|
| 937 | + fatal_lang_error('could_not_package_backup', false); |
|
| 938 | + } |
|
| 902 | 939 | } |
| 903 | 940 | |
| 904 | 941 | // The mod isn't installed.... unless proven otherwise. |
@@ -938,35 +975,38 @@ discard block |
||
| 938 | 975 | $install_log = parsePackageInfo($packageInfo['xml'], false, 'uninstall'); |
| 939 | 976 | |
| 940 | 977 | // Gadzooks! There's no uninstaller at all!? |
| 941 | - if (empty($install_log)) |
|
| 942 | - fatal_lang_error('package_uninstall_cannot', false); |
|
| 978 | + if (empty($install_log)) { |
|
| 979 | + fatal_lang_error('package_uninstall_cannot', false); |
|
| 980 | + } |
|
| 943 | 981 | |
| 944 | 982 | // They can only uninstall from what it was originally installed into. |
| 945 | - foreach ($theme_paths as $id => $data) |
|
| 946 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
| 983 | + foreach ($theme_paths as $id => $data) { |
|
| 984 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
| 947 | 985 | unset($theme_paths[$id]); |
| 948 | - } |
|
| 949 | - elseif (isset($old_version) && $old_version != $packageInfo['version']) |
|
| 986 | + } |
|
| 987 | + } elseif (isset($old_version) && $old_version != $packageInfo['version']) |
|
| 950 | 988 | { |
| 951 | 989 | // Look for an upgrade... |
| 952 | 990 | $install_log = parsePackageInfo($packageInfo['xml'], false, 'upgrade', $old_version); |
| 953 | 991 | |
| 954 | 992 | // There was no upgrade.... |
| 955 | - if (empty($install_log)) |
|
| 956 | - $context['is_installed'] = true; |
|
| 957 | - else |
|
| 993 | + if (empty($install_log)) { |
|
| 994 | + $context['is_installed'] = true; |
|
| 995 | + } else |
|
| 958 | 996 | { |
| 959 | 997 | // Upgrade previous themes only! |
| 960 | - foreach ($theme_paths as $id => $data) |
|
| 961 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
| 998 | + foreach ($theme_paths as $id => $data) { |
|
| 999 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
| 962 | 1000 | unset($theme_paths[$id]); |
| 1001 | + } |
|
| 963 | 1002 | } |
| 1003 | + } elseif (isset($old_version) && $old_version == $packageInfo['version']) { |
|
| 1004 | + $context['is_installed'] = true; |
|
| 964 | 1005 | } |
| 965 | - elseif (isset($old_version) && $old_version == $packageInfo['version']) |
|
| 966 | - $context['is_installed'] = true; |
|
| 967 | 1006 | |
| 968 | - if (!isset($old_version) || $context['is_installed']) |
|
| 969 | - $install_log = parsePackageInfo($packageInfo['xml'], false, 'install'); |
|
| 1007 | + if (!isset($old_version) || $context['is_installed']) { |
|
| 1008 | + $install_log = parsePackageInfo($packageInfo['xml'], false, 'install'); |
|
| 1009 | + } |
|
| 970 | 1010 | |
| 971 | 1011 | $context['install_finished'] = false; |
| 972 | 1012 | |
@@ -983,37 +1023,39 @@ discard block |
||
| 983 | 1023 | |
| 984 | 1024 | if ($action['type'] == 'modification' && !empty($action['filename'])) |
| 985 | 1025 | { |
| 986 | - if ($action['boardmod']) |
|
| 987 | - $mod_actions = parseBoardMod(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); |
|
| 988 | - else |
|
| 989 | - $mod_actions = parseModification(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); |
|
| 1026 | + if ($action['boardmod']) { |
|
| 1027 | + $mod_actions = parseBoardMod(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); |
|
| 1028 | + } else { |
|
| 1029 | + $mod_actions = parseModification(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); |
|
| 1030 | + } |
|
| 990 | 1031 | |
| 991 | 1032 | // Any errors worth noting? |
| 992 | 1033 | foreach ($mod_actions as $key => $action) |
| 993 | 1034 | { |
| 994 | - if ($action['type'] == 'failure') |
|
| 995 | - $failed_steps[] = array( |
|
| 1035 | + if ($action['type'] == 'failure') { |
|
| 1036 | + $failed_steps[] = array( |
|
| 996 | 1037 | 'file' => $action['filename'], |
| 997 | 1038 | 'large_step' => $failed_count, |
| 998 | 1039 | 'sub_step' => $key, |
| 999 | 1040 | 'theme' => 1, |
| 1000 | 1041 | ); |
| 1042 | + } |
|
| 1001 | 1043 | |
| 1002 | 1044 | // Gather the themes we installed into. |
| 1003 | - if (!empty($action['is_custom'])) |
|
| 1004 | - $themes_installed[] = $action['is_custom']; |
|
| 1045 | + if (!empty($action['is_custom'])) { |
|
| 1046 | + $themes_installed[] = $action['is_custom']; |
|
| 1047 | + } |
|
| 1005 | 1048 | } |
| 1006 | - } |
|
| 1007 | - elseif ($action['type'] == 'code' && !empty($action['filename'])) |
|
| 1049 | + } elseif ($action['type'] == 'code' && !empty($action['filename'])) |
|
| 1008 | 1050 | { |
| 1009 | 1051 | // This is just here as reference for what is available. |
| 1010 | 1052 | global $txt, $boarddir, $sourcedir, $modSettings, $context, $settings, $forum_version, $smcFunc; |
| 1011 | 1053 | |
| 1012 | 1054 | // Now include the file and be done with it ;). |
| 1013 | - if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) |
|
| 1014 | - require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']); |
|
| 1015 | - } |
|
| 1016 | - elseif ($action['type'] == 'credits') |
|
| 1055 | + if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) { |
|
| 1056 | + require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']); |
|
| 1057 | + } |
|
| 1058 | + } elseif ($action['type'] == 'credits') |
|
| 1017 | 1059 | { |
| 1018 | 1060 | // Time to build the billboard |
| 1019 | 1061 | $credits_tag = array( |
@@ -1023,13 +1065,13 @@ discard block |
||
| 1023 | 1065 | 'copyright' => $action['copyright'], |
| 1024 | 1066 | 'title' => $action['title'], |
| 1025 | 1067 | ); |
| 1026 | - } |
|
| 1027 | - elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function'])) |
|
| 1068 | + } elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function'])) |
|
| 1028 | 1069 | { |
| 1029 | - if ($action['reverse']) |
|
| 1030 | - remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']); |
|
| 1031 | - else |
|
| 1032 | - add_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']); |
|
| 1070 | + if ($action['reverse']) { |
|
| 1071 | + remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']); |
|
| 1072 | + } else { |
|
| 1073 | + add_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']); |
|
| 1074 | + } |
|
| 1033 | 1075 | } |
| 1034 | 1076 | // Only do the database changes on uninstall if requested. |
| 1035 | 1077 | elseif ($action['type'] == 'database' && !empty($action['filename']) && (!$context['uninstalling'] || !empty($_POST['do_db_changes']))) |
@@ -1042,8 +1084,9 @@ discard block |
||
| 1042 | 1084 | db_extend('packages'); |
| 1043 | 1085 | |
| 1044 | 1086 | // Let the file work its magic ;) |
| 1045 | - if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) |
|
| 1046 | - require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']); |
|
| 1087 | + if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) { |
|
| 1088 | + require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']); |
|
| 1089 | + } |
|
| 1047 | 1090 | } |
| 1048 | 1091 | // Handle a redirect... |
| 1049 | 1092 | elseif ($action['type'] == 'redirect' && !empty($action['redirect_url'])) |
@@ -1125,8 +1168,9 @@ discard block |
||
| 1125 | 1168 | reloadSettings(); |
| 1126 | 1169 | |
| 1127 | 1170 | // Any db changes from older version? |
| 1128 | - if (!empty($old_db_changes)) |
|
| 1129 | - $db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log); |
|
| 1171 | + if (!empty($old_db_changes)) { |
|
| 1172 | + $db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log); |
|
| 1173 | + } |
|
| 1130 | 1174 | |
| 1131 | 1175 | // If there are some database changes we might want to remove then filter them out. |
| 1132 | 1176 | if (!empty($db_package_log)) |
@@ -1142,22 +1186,24 @@ discard block |
||
| 1142 | 1186 | */ |
| 1143 | 1187 | function sort_table_first($a, $b) |
| 1144 | 1188 | { |
| 1145 | - if ($a[0] == $b[0]) |
|
| 1146 | - return 0; |
|
| 1189 | + if ($a[0] == $b[0]) { |
|
| 1190 | + return 0; |
|
| 1191 | + } |
|
| 1147 | 1192 | return $a[0] == 'remove_table' ? -1 : 1; |
| 1148 | 1193 | } |
| 1149 | 1194 | usort($db_package_log, 'sort_table_first'); |
| 1150 | 1195 | foreach ($db_package_log as $k => $log) |
| 1151 | 1196 | { |
| 1152 | - if ($log[0] == 'remove_table') |
|
| 1153 | - $tables[] = $log[1]; |
|
| 1154 | - elseif (in_array($log[1], $tables)) |
|
| 1155 | - unset($db_package_log[$k]); |
|
| 1197 | + if ($log[0] == 'remove_table') { |
|
| 1198 | + $tables[] = $log[1]; |
|
| 1199 | + } elseif (in_array($log[1], $tables)) { |
|
| 1200 | + unset($db_package_log[$k]); |
|
| 1201 | + } |
|
| 1156 | 1202 | } |
| 1157 | 1203 | $db_changes = json_encode($db_package_log); |
| 1204 | + } else { |
|
| 1205 | + $db_changes = ''; |
|
| 1158 | 1206 | } |
| 1159 | - else |
|
| 1160 | - $db_changes = ''; |
|
| 1161 | 1207 | |
| 1162 | 1208 | // What themes did we actually install? |
| 1163 | 1209 | $themes_installed = array_unique($themes_installed); |
@@ -1206,18 +1252,20 @@ discard block |
||
| 1206 | 1252 | |
| 1207 | 1253 | foreach ($db_changes as $change) |
| 1208 | 1254 | { |
| 1209 | - if ($change[0] == 'remove_table' && isset($change[1])) |
|
| 1210 | - $smcFunc['db_drop_table']($change[1]); |
|
| 1211 | - elseif ($change[0] == 'remove_column' && isset($change[2])) |
|
| 1212 | - $smcFunc['db_remove_column']($change[1], $change[2]); |
|
| 1213 | - elseif ($change[0] == 'remove_index' && isset($change[2])) |
|
| 1214 | - $smcFunc['db_remove_index']($change[1], $change[2]); |
|
| 1255 | + if ($change[0] == 'remove_table' && isset($change[1])) { |
|
| 1256 | + $smcFunc['db_drop_table']($change[1]); |
|
| 1257 | + } elseif ($change[0] == 'remove_column' && isset($change[2])) { |
|
| 1258 | + $smcFunc['db_remove_column']($change[1], $change[2]); |
|
| 1259 | + } elseif ($change[0] == 'remove_index' && isset($change[2])) { |
|
| 1260 | + $smcFunc['db_remove_index']($change[1], $change[2]); |
|
| 1261 | + } |
|
| 1215 | 1262 | } |
| 1216 | 1263 | } |
| 1217 | 1264 | |
| 1218 | 1265 | // Clean house... get rid of the evidence ;). |
| 1219 | - if (file_exists($packagesdir . '/temp')) |
|
| 1220 | - deltree($packagesdir . '/temp'); |
|
| 1266 | + if (file_exists($packagesdir . '/temp')) { |
|
| 1267 | + deltree($packagesdir . '/temp'); |
|
| 1268 | + } |
|
| 1221 | 1269 | |
| 1222 | 1270 | // Log what we just did. |
| 1223 | 1271 | logAction($context['uninstalling'] ? 'uninstall_package' : (!empty($is_upgrade) ? 'upgrade_package' : 'install_package'), array('package' => $smcFunc['htmlspecialchars']($packageInfo['name']), 'version' => $smcFunc['htmlspecialchars']($packageInfo['version'])), 'admin'); |
@@ -1239,8 +1287,9 @@ discard block |
||
| 1239 | 1287 | require_once($sourcedir . '/Subs-Package.php'); |
| 1240 | 1288 | |
| 1241 | 1289 | // No package? Show him or her the door. |
| 1242 | - if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') |
|
| 1243 | - redirectexit('action=admin;area=packages'); |
|
| 1290 | + if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') { |
|
| 1291 | + redirectexit('action=admin;area=packages'); |
|
| 1292 | + } |
|
| 1244 | 1293 | |
| 1245 | 1294 | $context['linktree'][] = array( |
| 1246 | 1295 | 'url' => $scripturl . '?action=admin;area=packages;sa=list;package=' . $_REQUEST['package'], |
@@ -1253,11 +1302,12 @@ discard block |
||
| 1253 | 1302 | $context['filename'] = $_REQUEST['package']; |
| 1254 | 1303 | |
| 1255 | 1304 | // Let the unpacker do the work. |
| 1256 | - if (is_file($packagesdir . '/' . $context['filename'])) |
|
| 1257 | - $context['files'] = read_tgz_file($packagesdir . '/' . $context['filename'], null); |
|
| 1258 | - elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
| 1259 | - $context['files'] = listtree($packagesdir . '/' . $context['filename']); |
|
| 1260 | -} |
|
| 1305 | + if (is_file($packagesdir . '/' . $context['filename'])) { |
|
| 1306 | + $context['files'] = read_tgz_file($packagesdir . '/' . $context['filename'], null); |
|
| 1307 | + } elseif (is_dir($packagesdir . '/' . $context['filename'])) { |
|
| 1308 | + $context['files'] = listtree($packagesdir . '/' . $context['filename']); |
|
| 1309 | + } |
|
| 1310 | + } |
|
| 1261 | 1311 | |
| 1262 | 1312 | /** |
| 1263 | 1313 | * Display one of the files in a package. |
@@ -1269,22 +1319,25 @@ discard block |
||
| 1269 | 1319 | require_once($sourcedir . '/Subs-Package.php'); |
| 1270 | 1320 | |
| 1271 | 1321 | // No package? Show him or her the door. |
| 1272 | - if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') |
|
| 1273 | - redirectexit('action=admin;area=packages'); |
|
| 1322 | + if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') { |
|
| 1323 | + redirectexit('action=admin;area=packages'); |
|
| 1324 | + } |
|
| 1274 | 1325 | |
| 1275 | 1326 | // No file? Show him or her the door. |
| 1276 | - if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '') |
|
| 1277 | - redirectexit('action=admin;area=packages'); |
|
| 1327 | + if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '') { |
|
| 1328 | + redirectexit('action=admin;area=packages'); |
|
| 1329 | + } |
|
| 1278 | 1330 | |
| 1279 | 1331 | $_REQUEST['package'] = preg_replace('~[\.]+~', '.', strtr($_REQUEST['package'], array('/' => '_', '\\' => '_'))); |
| 1280 | 1332 | $_REQUEST['file'] = preg_replace('~[\.]+~', '.', $_REQUEST['file']); |
| 1281 | 1333 | |
| 1282 | 1334 | if (isset($_REQUEST['raw'])) |
| 1283 | 1335 | { |
| 1284 | - if (is_file($packagesdir . '/' . $_REQUEST['package'])) |
|
| 1285 | - echo read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true); |
|
| 1286 | - elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) |
|
| 1287 | - echo file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']); |
|
| 1336 | + if (is_file($packagesdir . '/' . $_REQUEST['package'])) { |
|
| 1337 | + echo read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true); |
|
| 1338 | + } elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) { |
|
| 1339 | + echo file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']); |
|
| 1340 | + } |
|
| 1288 | 1341 | |
| 1289 | 1342 | obExit(false); |
| 1290 | 1343 | } |
@@ -1301,17 +1354,19 @@ discard block |
||
| 1301 | 1354 | $context['filename'] = $_REQUEST['file']; |
| 1302 | 1355 | |
| 1303 | 1356 | // Let the unpacker do the work.... but make sure we handle images properly. |
| 1304 | - if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png'))) |
|
| 1305 | - $context['filedata'] = '<img src="' . $scripturl . '?action=admin;area=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw" alt="' . $_REQUEST['file'] . '">'; |
|
| 1306 | - else |
|
| 1357 | + if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png'))) { |
|
| 1358 | + $context['filedata'] = '<img src="' . $scripturl . '?action=admin;area=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw" alt="' . $_REQUEST['file'] . '">'; |
|
| 1359 | + } else |
|
| 1307 | 1360 | { |
| 1308 | - if (is_file($packagesdir . '/' . $_REQUEST['package'])) |
|
| 1309 | - $context['filedata'] = $smcFunc['htmlspecialchars'](read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true)); |
|
| 1310 | - elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) |
|
| 1311 | - $context['filedata'] = $smcFunc['htmlspecialchars'](file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file'])); |
|
| 1361 | + if (is_file($packagesdir . '/' . $_REQUEST['package'])) { |
|
| 1362 | + $context['filedata'] = $smcFunc['htmlspecialchars'](read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true)); |
|
| 1363 | + } elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) { |
|
| 1364 | + $context['filedata'] = $smcFunc['htmlspecialchars'](file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file'])); |
|
| 1365 | + } |
|
| 1312 | 1366 | |
| 1313 | - if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php') |
|
| 1314 | - $context['filedata'] = highlight_php_code($context['filedata']); |
|
| 1367 | + if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php') { |
|
| 1368 | + $context['filedata'] = highlight_php_code($context['filedata']); |
|
| 1369 | + } |
|
| 1315 | 1370 | } |
| 1316 | 1371 | } |
| 1317 | 1372 | |
@@ -1326,8 +1381,9 @@ discard block |
||
| 1326 | 1381 | checkSession('get'); |
| 1327 | 1382 | |
| 1328 | 1383 | // Ack, don't allow deletion of arbitrary files here, could become a security hole somehow! |
| 1329 | - if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'backups') |
|
| 1330 | - redirectexit('action=admin;area=packages;sa=browse'); |
|
| 1384 | + if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'backups') { |
|
| 1385 | + redirectexit('action=admin;area=packages;sa=browse'); |
|
| 1386 | + } |
|
| 1331 | 1387 | $_GET['package'] = preg_replace('~[\.]+~', '.', strtr($_GET['package'], array('/' => '_', '\\' => '_'))); |
| 1332 | 1388 | |
| 1333 | 1389 | // Can't delete what's not there. |
@@ -1335,9 +1391,9 @@ discard block |
||
| 1335 | 1391 | { |
| 1336 | 1392 | create_chmod_control(array($packagesdir . '/' . $_GET['package']), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=remove;package=' . $_GET['package'], 'crash_on_error' => true)); |
| 1337 | 1393 | |
| 1338 | - if (is_dir($packagesdir . '/' . $_GET['package'])) |
|
| 1339 | - deltree($packagesdir . '/' . $_GET['package']); |
|
| 1340 | - else |
|
| 1394 | + if (is_dir($packagesdir . '/' . $_GET['package'])) { |
|
| 1395 | + deltree($packagesdir . '/' . $_GET['package']); |
|
| 1396 | + } else |
|
| 1341 | 1397 | { |
| 1342 | 1398 | smf_chmod($packagesdir . '/' . $_GET['package'], 0777); |
| 1343 | 1399 | unlink($packagesdir . '/' . $_GET['package']); |
@@ -1385,8 +1441,9 @@ discard block |
||
| 1385 | 1441 | 'data' => array( |
| 1386 | 1442 | 'function' => function ($package_md5) use ($type, &$context) |
| 1387 | 1443 | { |
| 1388 | - if (isset($context['available_' . $type . ''][$package_md5])) |
|
| 1389 | - return $context['available_' . $type . ''][$package_md5]['sort_id']; |
|
| 1444 | + if (isset($context['available_' . $type . ''][$package_md5])) { |
|
| 1445 | + return $context['available_' . $type . ''][$package_md5]['sort_id']; |
|
| 1446 | + } |
|
| 1390 | 1447 | }, |
| 1391 | 1448 | ), |
| 1392 | 1449 | 'sort' => array( |
@@ -1402,8 +1459,9 @@ discard block |
||
| 1402 | 1459 | 'data' => array( |
| 1403 | 1460 | 'function' => function ($package_md5) use ($type, &$context) |
| 1404 | 1461 | { |
| 1405 | - if (isset($context['available_' . $type . ''][$package_md5])) |
|
| 1406 | - return $context['available_' . $type . ''][$package_md5]['name']; |
|
| 1462 | + if (isset($context['available_' . $type . ''][$package_md5])) { |
|
| 1463 | + return $context['available_' . $type . ''][$package_md5]['name']; |
|
| 1464 | + } |
|
| 1407 | 1465 | }, |
| 1408 | 1466 | ), |
| 1409 | 1467 | 'sort' => array( |
@@ -1418,8 +1476,9 @@ discard block |
||
| 1418 | 1476 | 'data' => array( |
| 1419 | 1477 | 'function' => function ($package_md5) use ($type, &$context) |
| 1420 | 1478 | { |
| 1421 | - if (isset($context['available_' . $type . ''][$package_md5])) |
|
| 1422 | - return $context['available_' . $type . ''][$package_md5]['version']; |
|
| 1479 | + if (isset($context['available_' . $type . ''][$package_md5])) { |
|
| 1480 | + return $context['available_' . $type . ''][$package_md5]['version']; |
|
| 1481 | + } |
|
| 1423 | 1482 | }, |
| 1424 | 1483 | ), |
| 1425 | 1484 | 'sort' => array( |
@@ -1434,8 +1493,9 @@ discard block |
||
| 1434 | 1493 | 'data' => array( |
| 1435 | 1494 | 'function' => function ($package_md5) use ($type, $txt, &$context) |
| 1436 | 1495 | { |
| 1437 | - if (isset($context['available_' . $type . ''][$package_md5])) |
|
| 1438 | - return !empty($context['available_' . $type . ''][$package_md5]['time_installed']) ? timeformat($context['available_' . $type . ''][$package_md5]['time_installed']) : $txt['not_applicable']; |
|
| 1496 | + if (isset($context['available_' . $type . ''][$package_md5])) { |
|
| 1497 | + return !empty($context['available_' . $type . ''][$package_md5]['time_installed']) ? timeformat($context['available_' . $type . ''][$package_md5]['time_installed']) : $txt['not_applicable']; |
|
| 1498 | + } |
|
| 1439 | 1499 | }, |
| 1440 | 1500 | 'class' => 'smalltext', |
| 1441 | 1501 | ), |
@@ -1451,28 +1511,30 @@ discard block |
||
| 1451 | 1511 | 'data' => array( |
| 1452 | 1512 | 'function' => function ($package_md5) use ($type, &$context, $scripturl, $txt) |
| 1453 | 1513 | { |
| 1454 | - if (!isset($context['available_' . $type . ''][$package_md5])) |
|
| 1455 | - return ''; |
|
| 1514 | + if (!isset($context['available_' . $type . ''][$package_md5])) { |
|
| 1515 | + return ''; |
|
| 1516 | + } |
|
| 1456 | 1517 | |
| 1457 | 1518 | // Rewrite shortcut |
| 1458 | 1519 | $package = $context['available_' . $type . ''][$package_md5]; |
| 1459 | 1520 | $return = ''; |
| 1460 | 1521 | |
| 1461 | - if ($package['can_uninstall']) |
|
| 1462 | - $return = ' |
|
| 1522 | + if ($package['can_uninstall']) { |
|
| 1523 | + $return = ' |
|
| 1463 | 1524 | <a href="' . $scripturl . '?action=admin;area=packages;sa=uninstall;package=' . $package['filename'] . ';pid=' . $package['installed_id'] . '" class="button">' . $txt['uninstall'] . '</a>'; |
| 1464 | - elseif ($package['can_emulate_uninstall']) |
|
| 1465 | - $return = ' |
|
| 1525 | + } elseif ($package['can_emulate_uninstall']) { |
|
| 1526 | + $return = ' |
|
| 1466 | 1527 | <a href="' . $scripturl . '?action=admin;area=packages;sa=uninstall;ve=' . $package['can_emulate_uninstall'] . ';package=' . $package['filename'] . ';pid=' . $package['installed_id'] . '" class="button">' . $txt['package_emulate_uninstall'] . ' ' . $package['can_emulate_uninstall'] . '</a>'; |
| 1467 | - elseif ($package['can_upgrade']) |
|
| 1468 | - $return = ' |
|
| 1528 | + } elseif ($package['can_upgrade']) { |
|
| 1529 | + $return = ' |
|
| 1469 | 1530 | <a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $package['filename'] . '" class="button">' . $txt['package_upgrade'] . '</a>'; |
| 1470 | - elseif ($package['can_install']) |
|
| 1471 | - $return = ' |
|
| 1531 | + } elseif ($package['can_install']) { |
|
| 1532 | + $return = ' |
|
| 1472 | 1533 | <a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $package['filename'] . '" class="button">' . $txt['install_mod'] . '</a>'; |
| 1473 | - elseif ($package['can_emulate_install']) |
|
| 1474 | - $return = ' |
|
| 1534 | + } elseif ($package['can_emulate_install']) { |
|
| 1535 | + $return = ' |
|
| 1475 | 1536 | <a href="' . $scripturl . '?action=admin;area=packages;sa=install;ve=' . $package['can_emulate_install'] . ';package=' . $package['filename'] . '" class="button">' . $txt['package_emulate_install'] . ' ' . $package['can_emulate_install'] . '</a>'; |
| 1537 | + } |
|
| 1476 | 1538 | |
| 1477 | 1539 | return $return . ' |
| 1478 | 1540 | <a href="' . $scripturl . '?action=admin;area=packages;sa=list;package=' . $package['filename'] . '" class="button">' . $txt['list_files'] . '</a> |
@@ -1537,12 +1599,14 @@ discard block |
||
| 1537 | 1599 | static $packages, $installed_mods; |
| 1538 | 1600 | |
| 1539 | 1601 | // Start things up |
| 1540 | - if (!isset($packages[$params])) |
|
| 1541 | - $packages[$params] = array(); |
|
| 1602 | + if (!isset($packages[$params])) { |
|
| 1603 | + $packages[$params] = array(); |
|
| 1604 | + } |
|
| 1542 | 1605 | |
| 1543 | 1606 | // We need the packages directory to be writable for this. |
| 1544 | - if (!@is_writable($packagesdir)) |
|
| 1545 | - create_chmod_control(array($packagesdir), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true)); |
|
| 1607 | + if (!@is_writable($packagesdir)) { |
|
| 1608 | + create_chmod_control(array($packagesdir), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true)); |
|
| 1609 | + } |
|
| 1546 | 1610 | |
| 1547 | 1611 | $the_version = strtr($forum_version, array('SMF ' => '')); |
| 1548 | 1612 | |
@@ -1550,41 +1614,44 @@ discard block |
||
| 1550 | 1614 | if (isset($_GET['version_emulate']) && strtr($_GET['version_emulate'], array('SMF ' => '')) == $the_version) |
| 1551 | 1615 | { |
| 1552 | 1616 | unset($_SESSION['version_emulate']); |
| 1553 | - } |
|
| 1554 | - elseif (isset($_GET['version_emulate'])) |
|
| 1617 | + } elseif (isset($_GET['version_emulate'])) |
|
| 1555 | 1618 | { |
| 1556 | - if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate'])) |
|
| 1557 | - unset($_SESSION['version_emulate']); |
|
| 1558 | - elseif ($_GET['version_emulate'] !== 0) |
|
| 1559 | - $_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', 'SMF ' => '')); |
|
| 1619 | + if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate'])) { |
|
| 1620 | + unset($_SESSION['version_emulate']); |
|
| 1621 | + } elseif ($_GET['version_emulate'] !== 0) { |
|
| 1622 | + $_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', 'SMF ' => '')); |
|
| 1623 | + } |
|
| 1560 | 1624 | } |
| 1561 | 1625 | if (!empty($_SESSION['version_emulate'])) |
| 1562 | 1626 | { |
| 1563 | 1627 | $context['forum_version'] = 'SMF ' . $_SESSION['version_emulate']; |
| 1564 | 1628 | $the_version = $_SESSION['version_emulate']; |
| 1565 | 1629 | } |
| 1566 | - if (isset($_SESSION['single_version_emulate'])) |
|
| 1567 | - unset($_SESSION['single_version_emulate']); |
|
| 1630 | + if (isset($_SESSION['single_version_emulate'])) { |
|
| 1631 | + unset($_SESSION['single_version_emulate']); |
|
| 1632 | + } |
|
| 1568 | 1633 | |
| 1569 | 1634 | if (empty($installed_mods)) |
| 1570 | 1635 | { |
| 1571 | 1636 | $instmods = loadInstalledPackages(); |
| 1572 | 1637 | $installed_mods = array(); |
| 1573 | 1638 | // Look through the list of installed mods... |
| 1574 | - foreach ($instmods as $installed_mod) |
|
| 1575 | - $installed_mods[$installed_mod['package_id']] = array( |
|
| 1639 | + foreach ($instmods as $installed_mod) { |
|
| 1640 | + $installed_mods[$installed_mod['package_id']] = array( |
|
| 1576 | 1641 | 'id' => $installed_mod['id'], |
| 1577 | 1642 | 'version' => $installed_mod['version'], |
| 1578 | 1643 | 'time_installed' => $installed_mod['time_installed'], |
| 1579 | 1644 | ); |
| 1645 | + } |
|
| 1580 | 1646 | |
| 1581 | 1647 | // Get a list of all the ids installed, so the latest packages won't include already installed ones. |
| 1582 | 1648 | $context['installed_mods'] = array_keys($installed_mods); |
| 1583 | 1649 | } |
| 1584 | 1650 | |
| 1585 | - if (empty($packages)) |
|
| 1586 | - foreach ($context['modification_types'] as $type) |
|
| 1651 | + if (empty($packages)) { |
|
| 1652 | + foreach ($context['modification_types'] as $type) |
|
| 1587 | 1653 | $packages[$type] = array(); |
| 1654 | + } |
|
| 1588 | 1655 | |
| 1589 | 1656 | if ($dir = @opendir($packagesdir)) |
| 1590 | 1657 | { |
@@ -1600,50 +1667,56 @@ discard block |
||
| 1600 | 1667 | |
| 1601 | 1668 | while ($package = readdir($dir)) |
| 1602 | 1669 | { |
| 1603 | - if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) |
|
| 1604 | - continue; |
|
| 1670 | + if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) { |
|
| 1671 | + continue; |
|
| 1672 | + } |
|
| 1605 | 1673 | |
| 1606 | 1674 | $skip = false; |
| 1607 | - foreach ($context['modification_types'] as $type) |
|
| 1608 | - if (isset($context['available_' . $type][md5($package)])) |
|
| 1675 | + foreach ($context['modification_types'] as $type) { |
|
| 1676 | + if (isset($context['available_' . $type][md5($package)])) |
|
| 1609 | 1677 | $skip = true; |
| 1678 | + } |
|
| 1610 | 1679 | |
| 1611 | - if ($skip) |
|
| 1612 | - continue; |
|
| 1680 | + if ($skip) { |
|
| 1681 | + continue; |
|
| 1682 | + } |
|
| 1613 | 1683 | |
| 1614 | 1684 | // Skip directories or files that are named the same. |
| 1615 | 1685 | if (is_dir($packagesdir . '/' . $package)) |
| 1616 | 1686 | { |
| 1617 | - if (in_array($package, $dirs)) |
|
| 1618 | - continue; |
|
| 1687 | + if (in_array($package, $dirs)) { |
|
| 1688 | + continue; |
|
| 1689 | + } |
|
| 1619 | 1690 | $dirs[] = $package; |
| 1620 | - } |
|
| 1621 | - elseif (substr(strtolower($package), -7) == '.tar.gz') |
|
| 1691 | + } elseif (substr(strtolower($package), -7) == '.tar.gz') |
|
| 1622 | 1692 | { |
| 1623 | - if (in_array(substr($package, 0, -7), $dirs)) |
|
| 1624 | - continue; |
|
| 1693 | + if (in_array(substr($package, 0, -7), $dirs)) { |
|
| 1694 | + continue; |
|
| 1695 | + } |
|
| 1625 | 1696 | $dirs[] = substr($package, 0, -7); |
| 1626 | - } |
|
| 1627 | - elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz') |
|
| 1697 | + } elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz') |
|
| 1628 | 1698 | { |
| 1629 | - if (in_array(substr($package, 0, -4), $dirs)) |
|
| 1630 | - continue; |
|
| 1699 | + if (in_array(substr($package, 0, -4), $dirs)) { |
|
| 1700 | + continue; |
|
| 1701 | + } |
|
| 1631 | 1702 | $dirs[] = substr($package, 0, -4); |
| 1632 | 1703 | } |
| 1633 | 1704 | |
| 1634 | 1705 | $packageInfo = getPackageInfo($package); |
| 1635 | - if (!is_array($packageInfo)) |
|
| 1636 | - continue; |
|
| 1706 | + if (!is_array($packageInfo)) { |
|
| 1707 | + continue; |
|
| 1708 | + } |
|
| 1637 | 1709 | |
| 1638 | 1710 | if (!empty($packageInfo)) |
| 1639 | 1711 | { |
| 1640 | 1712 | $packageInfo['installed_id'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['id'] : 0; |
| 1641 | 1713 | $packageInfo['time_installed'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['time_installed'] : 0; |
| 1642 | 1714 | |
| 1643 | - if (!isset($sort_id[$packageInfo['type']])) |
|
| 1644 | - $packageInfo['sort_id'] = $sort_id['unknown']; |
|
| 1645 | - else |
|
| 1646 | - $packageInfo['sort_id'] = $sort_id[$packageInfo['type']]; |
|
| 1715 | + if (!isset($sort_id[$packageInfo['type']])) { |
|
| 1716 | + $packageInfo['sort_id'] = $sort_id['unknown']; |
|
| 1717 | + } else { |
|
| 1718 | + $packageInfo['sort_id'] = $sort_id[$packageInfo['type']]; |
|
| 1719 | + } |
|
| 1647 | 1720 | |
| 1648 | 1721 | $packageInfo['is_installed'] = isset($installed_mods[$packageInfo['id']]); |
| 1649 | 1722 | $packageInfo['is_current'] = $packageInfo['is_installed'] && ($installed_mods[$packageInfo['id']]['version'] == $packageInfo['version']); |
@@ -1692,10 +1765,11 @@ discard block |
||
| 1692 | 1765 | foreach ($upgrades as $upgrade) |
| 1693 | 1766 | { |
| 1694 | 1767 | // Even if it is for this SMF, is it for the installed version of the mod? |
| 1695 | - if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for'))) |
|
| 1696 | - if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from'))) |
|
| 1768 | + if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for'))) { |
|
| 1769 | + if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from'))) |
|
| 1697 | 1770 | { |
| 1698 | 1771 | $packageInfo['can_upgrade'] = true; |
| 1772 | + } |
|
| 1699 | 1773 | break; |
| 1700 | 1774 | } |
| 1701 | 1775 | } |
@@ -1772,10 +1846,11 @@ discard block |
||
| 1772 | 1846 | |
| 1773 | 1847 | if (isset($_GET['type']) && $_GET['type'] == $params) |
| 1774 | 1848 | { |
| 1775 | - if (isset($_GET['desc'])) |
|
| 1776 | - krsort($packages[$params]); |
|
| 1777 | - else |
|
| 1778 | - ksort($packages[$params]); |
|
| 1849 | + if (isset($_GET['desc'])) { |
|
| 1850 | + krsort($packages[$params]); |
|
| 1851 | + } else { |
|
| 1852 | + ksort($packages[$params]); |
|
| 1853 | + } |
|
| 1779 | 1854 | } |
| 1780 | 1855 | |
| 1781 | 1856 | return $packages[$params]; |
@@ -1804,10 +1879,11 @@ discard block |
||
| 1804 | 1879 | redirectexit('action=admin;area=packages;sa=options'); |
| 1805 | 1880 | } |
| 1806 | 1881 | |
| 1807 | - if (preg_match('~^/home\d*/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match)) |
|
| 1808 | - $default_username = $match[1]; |
|
| 1809 | - else |
|
| 1810 | - $default_username = ''; |
|
| 1882 | + if (preg_match('~^/home\d*/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match)) { |
|
| 1883 | + $default_username = $match[1]; |
|
| 1884 | + } else { |
|
| 1885 | + $default_username = ''; |
|
| 1886 | + } |
|
| 1811 | 1887 | |
| 1812 | 1888 | $context['page_title'] = $txt['package_settings']; |
| 1813 | 1889 | $context['sub_template'] = 'install_options'; |
@@ -1836,8 +1912,9 @@ discard block |
||
| 1836 | 1912 | isAllowedTo('admin_forum'); |
| 1837 | 1913 | |
| 1838 | 1914 | // We need to know the operation key for the search and replace, mod file looking at, is it a board mod? |
| 1839 | - if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key'])) |
|
| 1840 | - fatal_lang_error('operation_invalid', 'general'); |
|
| 1915 | + if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key'])) { |
|
| 1916 | + fatal_lang_error('operation_invalid', 'general'); |
|
| 1917 | + } |
|
| 1841 | 1918 | |
| 1842 | 1919 | // Load the required file. |
| 1843 | 1920 | require_once($sourcedir . '/Subs-Package.php'); |
@@ -1853,18 +1930,19 @@ discard block |
||
| 1853 | 1930 | { |
| 1854 | 1931 | $context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
| 1855 | 1932 | |
| 1856 | - if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) |
|
| 1857 | - foreach ($context['extracted_files'] as $file) |
|
| 1933 | + if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) { |
|
| 1934 | + foreach ($context['extracted_files'] as $file) |
|
| 1858 | 1935 | if (basename($file['filename']) == 'package-info.xml') |
| 1859 | 1936 | { |
| 1860 | 1937 | $context['base_path'] = dirname($file['filename']) . '/'; |
| 1938 | + } |
|
| 1861 | 1939 | break; |
| 1862 | 1940 | } |
| 1863 | 1941 | |
| 1864 | - if (!isset($context['base_path'])) |
|
| 1865 | - $context['base_path'] = ''; |
|
| 1866 | - } |
|
| 1867 | - elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
| 1942 | + if (!isset($context['base_path'])) { |
|
| 1943 | + $context['base_path'] = ''; |
|
| 1944 | + } |
|
| 1945 | + } elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
| 1868 | 1946 | { |
| 1869 | 1947 | copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
| 1870 | 1948 | $context['extracted_files'] = listtree($packagesdir . '/temp'); |
@@ -1885,8 +1963,9 @@ discard block |
||
| 1885 | 1963 | ) |
| 1886 | 1964 | ); |
| 1887 | 1965 | $theme_paths = array(); |
| 1888 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1889 | - $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
| 1966 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1967 | + $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
| 1968 | + } |
|
| 1890 | 1969 | $smcFunc['db_free_result']($request); |
| 1891 | 1970 | |
| 1892 | 1971 | // If we're viewing uninstall operations, only consider themes that |
@@ -1911,19 +1990,21 @@ discard block |
||
| 1911 | 1990 | list ($old_themes) = $smcFunc['db_fetch_row']($request); |
| 1912 | 1991 | $old_themes = explode(',', $old_themes); |
| 1913 | 1992 | |
| 1914 | - foreach ($theme_paths as $id => $data) |
|
| 1915 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
| 1993 | + foreach ($theme_paths as $id => $data) { |
|
| 1994 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
| 1916 | 1995 | unset($theme_paths[$id]); |
| 1996 | + } |
|
| 1917 | 1997 | } |
| 1918 | 1998 | $smcFunc['db_free_result']($request); |
| 1919 | 1999 | } |
| 1920 | 2000 | } |
| 1921 | 2001 | |
| 1922 | 2002 | // Boardmod? |
| 1923 | - if (isset($_REQUEST['boardmod'])) |
|
| 1924 | - $mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); |
|
| 1925 | - else |
|
| 1926 | - $mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); |
|
| 2003 | + if (isset($_REQUEST['boardmod'])) { |
|
| 2004 | + $mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); |
|
| 2005 | + } else { |
|
| 2006 | + $mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); |
|
| 2007 | + } |
|
| 1927 | 2008 | |
| 1928 | 2009 | // Ok lets get the content of the file. |
| 1929 | 2010 | $context['operations'] = array( |
@@ -1979,9 +2060,9 @@ discard block |
||
| 1979 | 2060 | 'path' => $detect_path, |
| 1980 | 2061 | 'form_elements_only' => true, |
| 1981 | 2062 | ); |
| 2063 | + } else { |
|
| 2064 | + $context['ftp_connected'] = true; |
|
| 1982 | 2065 | } |
| 1983 | - else |
|
| 1984 | - $context['ftp_connected'] = true; |
|
| 1985 | 2066 | |
| 1986 | 2067 | // Define the template. |
| 1987 | 2068 | $context['page_title'] = $txt['package_file_perms']; |
@@ -2094,18 +2175,19 @@ discard block |
||
| 2094 | 2175 | { |
| 2095 | 2176 | unset($context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['attachments']); |
| 2096 | 2177 | |
| 2097 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
| 2098 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 2178 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
| 2179 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 2180 | + } |
|
| 2099 | 2181 | |
| 2100 | 2182 | // @todo Should we suggest non-current directories be read only? |
| 2101 | - foreach ($modSettings['attachmentUploadDir'] as $dir) |
|
| 2102 | - $context['file_tree'][strtr($dir, array('\\' => '/'))] = array( |
|
| 2183 | + foreach ($modSettings['attachmentUploadDir'] as $dir) { |
|
| 2184 | + $context['file_tree'][strtr($dir, array('\\' => '/'))] = array( |
|
| 2103 | 2185 | 'type' => 'dir', |
| 2104 | 2186 | 'writable_on' => 'restrictive', |
| 2105 | 2187 | ); |
| 2188 | + } |
|
| 2106 | 2189 | |
| 2107 | - } |
|
| 2108 | - elseif (substr($modSettings['attachmentUploadDir'], 0, strlen($boarddir)) != $boarddir) |
|
| 2190 | + } elseif (substr($modSettings['attachmentUploadDir'], 0, strlen($boarddir)) != $boarddir) |
|
| 2109 | 2191 | { |
| 2110 | 2192 | unset($context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['attachments']); |
| 2111 | 2193 | $context['file_tree'][strtr($modSettings['attachmentUploadDir'], array('\\' => '/'))] = array( |
@@ -2155,8 +2237,8 @@ discard block |
||
| 2155 | 2237 | ); |
| 2156 | 2238 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2157 | 2239 | { |
| 2158 | - if (substr(strtolower(strtr($row['value'], array('\\' => '/'))), 0, strlen($boarddir) + 7) == strtolower(strtr($boarddir, array('\\' => '/')) . '/Themes')) |
|
| 2159 | - $context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['Themes']['contents'][substr($row['value'], strlen($boarddir) + 8)] = array( |
|
| 2240 | + if (substr(strtolower(strtr($row['value'], array('\\' => '/'))), 0, strlen($boarddir) + 7) == strtolower(strtr($boarddir, array('\\' => '/')) . '/Themes')) { |
|
| 2241 | + $context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['Themes']['contents'][substr($row['value'], strlen($boarddir) + 8)] = array( |
|
| 2160 | 2242 | 'type' => 'dir_recursive', |
| 2161 | 2243 | 'list_contents' => true, |
| 2162 | 2244 | 'contents' => array( |
@@ -2166,7 +2248,7 @@ discard block |
||
| 2166 | 2248 | ), |
| 2167 | 2249 | ), |
| 2168 | 2250 | ); |
| 2169 | - else |
|
| 2251 | + } else |
|
| 2170 | 2252 | { |
| 2171 | 2253 | $context['file_tree'][strtr($row['value'], array('\\' => '/'))] = array( |
| 2172 | 2254 | 'type' => 'dir_recursive', |
@@ -2183,28 +2265,33 @@ discard block |
||
| 2183 | 2265 | $smcFunc['db_free_result']($request); |
| 2184 | 2266 | |
| 2185 | 2267 | // If we're submitting then let's move on to another function to keep things cleaner.. |
| 2186 | - if (isset($_POST['action_changes'])) |
|
| 2187 | - return PackagePermissionsAction(); |
|
| 2268 | + if (isset($_POST['action_changes'])) { |
|
| 2269 | + return PackagePermissionsAction(); |
|
| 2270 | + } |
|
| 2188 | 2271 | |
| 2189 | 2272 | $context['look_for'] = array(); |
| 2190 | 2273 | // Are we looking for a particular tree - normally an expansion? |
| 2191 | - if (!empty($_REQUEST['find'])) |
|
| 2192 | - $context['look_for'][] = base64_decode($_REQUEST['find']); |
|
| 2274 | + if (!empty($_REQUEST['find'])) { |
|
| 2275 | + $context['look_for'][] = base64_decode($_REQUEST['find']); |
|
| 2276 | + } |
|
| 2193 | 2277 | // Only that tree? |
| 2194 | 2278 | $context['only_find'] = isset($_GET['xml']) && !empty($_REQUEST['onlyfind']) ? $_REQUEST['onlyfind'] : ''; |
| 2195 | - if ($context['only_find']) |
|
| 2196 | - $context['look_for'][] = $context['only_find']; |
|
| 2279 | + if ($context['only_find']) { |
|
| 2280 | + $context['look_for'][] = $context['only_find']; |
|
| 2281 | + } |
|
| 2197 | 2282 | |
| 2198 | 2283 | // Have we got a load of back-catalogue trees to expand from a submit etc? |
| 2199 | 2284 | if (!empty($_GET['back_look'])) |
| 2200 | 2285 | { |
| 2201 | 2286 | $potententialTrees = smf_json_decode(base64_decode($_GET['back_look']), true); |
| 2202 | - foreach ($potententialTrees as $tree) |
|
| 2203 | - $context['look_for'][] = $tree; |
|
| 2287 | + foreach ($potententialTrees as $tree) { |
|
| 2288 | + $context['look_for'][] = $tree; |
|
| 2289 | + } |
|
| 2204 | 2290 | } |
| 2205 | 2291 | // ... maybe posted? |
| 2206 | - if (!empty($_POST['back_look'])) |
|
| 2207 | - $context['only_find'] = array_merge($context['only_find'], $_POST['back_look']); |
|
| 2292 | + if (!empty($_POST['back_look'])) { |
|
| 2293 | + $context['only_find'] = array_merge($context['only_find'], $_POST['back_look']); |
|
| 2294 | + } |
|
| 2208 | 2295 | |
| 2209 | 2296 | $context['back_look_data'] = base64_encode(json_encode(array_slice($context['look_for'], 0, 15))); |
| 2210 | 2297 | |
@@ -2243,9 +2330,9 @@ discard block |
||
| 2243 | 2330 | 'chmod' => @is_writable($path), |
| 2244 | 2331 | 'perms' => @fileperms($path), |
| 2245 | 2332 | ); |
| 2333 | + } else { |
|
| 2334 | + unset($context['file_tree'][$path]); |
|
| 2246 | 2335 | } |
| 2247 | - else |
|
| 2248 | - unset($context['file_tree'][$path]); |
|
| 2249 | 2336 | } |
| 2250 | 2337 | |
| 2251 | 2338 | // Is this actually xml? |
@@ -2269,22 +2356,25 @@ discard block |
||
| 2269 | 2356 | global $context; |
| 2270 | 2357 | |
| 2271 | 2358 | $isLikelyPath = false; |
| 2272 | - foreach ($context['look_for'] as $possiblePath) |
|
| 2273 | - if (substr($possiblePath, 0, strlen($path)) == $path) |
|
| 2359 | + foreach ($context['look_for'] as $possiblePath) { |
|
| 2360 | + if (substr($possiblePath, 0, strlen($path)) == $path) |
|
| 2274 | 2361 | $isLikelyPath = true; |
| 2362 | + } |
|
| 2275 | 2363 | |
| 2276 | 2364 | // Is this where we stop? |
| 2277 | - if (isset($_GET['xml']) && !empty($context['look_for']) && !$isLikelyPath) |
|
| 2278 | - return; |
|
| 2279 | - elseif ($level > $context['default_level'] && !$isLikelyPath) |
|
| 2280 | - return; |
|
| 2365 | + if (isset($_GET['xml']) && !empty($context['look_for']) && !$isLikelyPath) { |
|
| 2366 | + return; |
|
| 2367 | + } elseif ($level > $context['default_level'] && !$isLikelyPath) { |
|
| 2368 | + return; |
|
| 2369 | + } |
|
| 2281 | 2370 | |
| 2282 | 2371 | // Are we actually interested in saving this data? |
| 2283 | 2372 | $save_data = empty($context['only_find']) || $context['only_find'] == $path; |
| 2284 | 2373 | |
| 2285 | 2374 | // @todo Shouldn't happen - but better error message? |
| 2286 | - if (!is_dir($path)) |
|
| 2287 | - fatal_lang_error('no_access', false); |
|
| 2375 | + if (!is_dir($path)) { |
|
| 2376 | + fatal_lang_error('no_access', false); |
|
| 2377 | + } |
|
| 2288 | 2378 | |
| 2289 | 2379 | // This is where we put stuff we've found for sorting. |
| 2290 | 2380 | $foundData = array( |
@@ -2299,11 +2389,13 @@ discard block |
||
| 2299 | 2389 | if (is_file($path . '/' . $entry)) |
| 2300 | 2390 | { |
| 2301 | 2391 | // Are we listing PHP files in this directory? |
| 2302 | - if ($save_data && !empty($data['list_contents']) && substr($entry, -4) == '.php') |
|
| 2303 | - $foundData['files'][$entry] = true; |
|
| 2392 | + if ($save_data && !empty($data['list_contents']) && substr($entry, -4) == '.php') { |
|
| 2393 | + $foundData['files'][$entry] = true; |
|
| 2394 | + } |
|
| 2304 | 2395 | // A file we were looking for. |
| 2305 | - elseif ($save_data && isset($data['contents'][$entry])) |
|
| 2306 | - $foundData['files'][$entry] = true; |
|
| 2396 | + elseif ($save_data && isset($data['contents'][$entry])) { |
|
| 2397 | + $foundData['files'][$entry] = true; |
|
| 2398 | + } |
|
| 2307 | 2399 | } |
| 2308 | 2400 | // It's a directory - we're interested one way or another, probably... |
| 2309 | 2401 | elseif ($entry != '.' && $entry != '..') |
@@ -2311,32 +2403,36 @@ discard block |
||
| 2311 | 2403 | // Going further? |
| 2312 | 2404 | if ((!empty($data['type']) && $data['type'] == 'dir_recursive') || (isset($data['contents'][$entry]) && (!empty($data['contents'][$entry]['list_contents']) || (!empty($data['contents'][$entry]['type']) && $data['contents'][$entry]['type'] == 'dir_recursive')))) |
| 2313 | 2405 | { |
| 2314 | - if (!isset($data['contents'][$entry])) |
|
| 2315 | - $foundData['folders'][$entry] = 'dir_recursive'; |
|
| 2316 | - else |
|
| 2317 | - $foundData['folders'][$entry] = true; |
|
| 2406 | + if (!isset($data['contents'][$entry])) { |
|
| 2407 | + $foundData['folders'][$entry] = 'dir_recursive'; |
|
| 2408 | + } else { |
|
| 2409 | + $foundData['folders'][$entry] = true; |
|
| 2410 | + } |
|
| 2318 | 2411 | |
| 2319 | 2412 | // If this wasn't expected inherit the recusiveness... |
| 2320 | - if (!isset($data['contents'][$entry])) |
|
| 2321 | - // We need to do this as we will be going all recursive. |
|
| 2413 | + if (!isset($data['contents'][$entry])) { |
|
| 2414 | + // We need to do this as we will be going all recursive. |
|
| 2322 | 2415 | $data['contents'][$entry] = array( |
| 2323 | 2416 | 'type' => 'dir_recursive', |
| 2324 | 2417 | ); |
| 2418 | + } |
|
| 2325 | 2419 | |
| 2326 | 2420 | // Actually do the recursive stuff... |
| 2327 | 2421 | fetchPerms__recursive($path . '/' . $entry, $data['contents'][$entry], $level + 1); |
| 2328 | 2422 | } |
| 2329 | 2423 | // Maybe it is a folder we are not descending into. |
| 2330 | - elseif (isset($data['contents'][$entry])) |
|
| 2331 | - $foundData['folders'][$entry] = true; |
|
| 2424 | + elseif (isset($data['contents'][$entry])) { |
|
| 2425 | + $foundData['folders'][$entry] = true; |
|
| 2426 | + } |
|
| 2332 | 2427 | // Otherwise we stop here. |
| 2333 | 2428 | } |
| 2334 | 2429 | } |
| 2335 | 2430 | closedir($dh); |
| 2336 | 2431 | |
| 2337 | 2432 | // Nothing to see here? |
| 2338 | - if (!$save_data) |
|
| 2339 | - return; |
|
| 2433 | + if (!$save_data) { |
|
| 2434 | + return; |
|
| 2435 | + } |
|
| 2340 | 2436 | |
| 2341 | 2437 | // Now actually add the data, starting with the folders. |
| 2342 | 2438 | ksort($foundData['folders']); |
@@ -2348,8 +2444,9 @@ discard block |
||
| 2348 | 2444 | 'perms' => @fileperms($path . '/' . $folder), |
| 2349 | 2445 | ), |
| 2350 | 2446 | ); |
| 2351 | - if ($type !== true) |
|
| 2352 | - $additional_data['type'] = $type; |
|
| 2447 | + if ($type !== true) { |
|
| 2448 | + $additional_data['type'] = $type; |
|
| 2449 | + } |
|
| 2353 | 2450 | |
| 2354 | 2451 | // If there's an offset ignore any folders in XML mode. |
| 2355 | 2452 | if (isset($_GET['xml']) && $context['file_offset'] == 0) |
@@ -2368,13 +2465,13 @@ discard block |
||
| 2368 | 2465 | ), |
| 2369 | 2466 | 'value' => $folder, |
| 2370 | 2467 | ); |
| 2371 | - } |
|
| 2372 | - elseif (!isset($_GET['xml'])) |
|
| 2468 | + } elseif (!isset($_GET['xml'])) |
|
| 2373 | 2469 | { |
| 2374 | - if (isset($data['contents'][$folder])) |
|
| 2375 | - $data['contents'][$folder] = array_merge($data['contents'][$folder], $additional_data); |
|
| 2376 | - else |
|
| 2377 | - $data['contents'][$folder] = $additional_data; |
|
| 2470 | + if (isset($data['contents'][$folder])) { |
|
| 2471 | + $data['contents'][$folder] = array_merge($data['contents'][$folder], $additional_data); |
|
| 2472 | + } else { |
|
| 2473 | + $data['contents'][$folder] = $additional_data; |
|
| 2474 | + } |
|
| 2378 | 2475 | } |
| 2379 | 2476 | } |
| 2380 | 2477 | |
@@ -2386,11 +2483,13 @@ discard block |
||
| 2386 | 2483 | $counter++; |
| 2387 | 2484 | |
| 2388 | 2485 | // Have we reached our offset? |
| 2389 | - if ($context['file_offset'] > $counter) |
|
| 2390 | - continue; |
|
| 2486 | + if ($context['file_offset'] > $counter) { |
|
| 2487 | + continue; |
|
| 2488 | + } |
|
| 2391 | 2489 | // Gone too far? |
| 2392 | - if ($counter > ($context['file_offset'] + $context['file_limit'])) |
|
| 2393 | - continue; |
|
| 2490 | + if ($counter > ($context['file_offset'] + $context['file_limit'])) { |
|
| 2491 | + continue; |
|
| 2492 | + } |
|
| 2394 | 2493 | |
| 2395 | 2494 | $additional_data = array( |
| 2396 | 2495 | 'perms' => array( |
@@ -2416,13 +2515,13 @@ discard block |
||
| 2416 | 2515 | ), |
| 2417 | 2516 | 'value' => $file, |
| 2418 | 2517 | ); |
| 2419 | - } |
|
| 2420 | - elseif ($counter != ($context['file_offset'] + $context['file_limit'])) |
|
| 2518 | + } elseif ($counter != ($context['file_offset'] + $context['file_limit'])) |
|
| 2421 | 2519 | { |
| 2422 | - if (isset($data['contents'][$file])) |
|
| 2423 | - $data['contents'][$file] = array_merge($data['contents'][$file], $additional_data); |
|
| 2424 | - else |
|
| 2425 | - $data['contents'][$file] = $additional_data; |
|
| 2520 | + if (isset($data['contents'][$file])) { |
|
| 2521 | + $data['contents'][$file] = array_merge($data['contents'][$file], $additional_data); |
|
| 2522 | + } else { |
|
| 2523 | + $data['contents'][$file] = $additional_data; |
|
| 2524 | + } |
|
| 2426 | 2525 | } |
| 2427 | 2526 | } |
| 2428 | 2527 | } |
@@ -2444,8 +2543,9 @@ discard block |
||
| 2444 | 2543 | $context['back_look_data'] = isset($_POST['back_look']) ? $_POST['back_look'] : array(); |
| 2445 | 2544 | |
| 2446 | 2545 | // Skipping use of FTP? |
| 2447 | - if (empty($package_ftp)) |
|
| 2448 | - $context['skip_ftp'] = true; |
|
| 2546 | + if (empty($package_ftp)) { |
|
| 2547 | + $context['skip_ftp'] = true; |
|
| 2548 | + } |
|
| 2449 | 2549 | |
| 2450 | 2550 | // We'll start off in a good place, security. Make sure that if we're dealing with individual files that they seem in the right place. |
| 2451 | 2551 | if ($context['method'] == 'individual') |
@@ -2455,8 +2555,9 @@ discard block |
||
| 2455 | 2555 | $context['custom_value'] = (int) $_POST['custom_value']; |
| 2456 | 2556 | |
| 2457 | 2557 | // Continuing? |
| 2458 | - if (isset($_POST['toProcess'])) |
|
| 2459 | - $_POST['permStatus'] = smf_json_decode(base64_decode($_POST['toProcess']), true); |
|
| 2558 | + if (isset($_POST['toProcess'])) { |
|
| 2559 | + $_POST['permStatus'] = smf_json_decode(base64_decode($_POST['toProcess']), true); |
|
| 2560 | + } |
|
| 2460 | 2561 | |
| 2461 | 2562 | if (isset($_POST['permStatus'])) |
| 2462 | 2563 | { |
@@ -2465,22 +2566,27 @@ discard block |
||
| 2465 | 2566 | foreach ($_POST['permStatus'] as $path => $status) |
| 2466 | 2567 | { |
| 2467 | 2568 | // Nothing to see here? |
| 2468 | - if ($status == 'no_change') |
|
| 2469 | - continue; |
|
| 2569 | + if ($status == 'no_change') { |
|
| 2570 | + continue; |
|
| 2571 | + } |
|
| 2470 | 2572 | $legal = false; |
| 2471 | - foreach ($legal_roots as $root) |
|
| 2472 | - if (substr($path, 0, strlen($root)) == $root) |
|
| 2573 | + foreach ($legal_roots as $root) { |
|
| 2574 | + if (substr($path, 0, strlen($root)) == $root) |
|
| 2473 | 2575 | $legal = true; |
| 2576 | + } |
|
| 2474 | 2577 | |
| 2475 | - if (!$legal) |
|
| 2476 | - continue; |
|
| 2578 | + if (!$legal) { |
|
| 2579 | + continue; |
|
| 2580 | + } |
|
| 2477 | 2581 | |
| 2478 | 2582 | // Check it exists. |
| 2479 | - if (!file_exists($path)) |
|
| 2480 | - continue; |
|
| 2583 | + if (!file_exists($path)) { |
|
| 2584 | + continue; |
|
| 2585 | + } |
|
| 2481 | 2586 | |
| 2482 | - if ($status == 'custom') |
|
| 2483 | - $validate_custom = true; |
|
| 2587 | + if ($status == 'custom') { |
|
| 2588 | + $validate_custom = true; |
|
| 2589 | + } |
|
| 2484 | 2590 | |
| 2485 | 2591 | // Now add it. |
| 2486 | 2592 | $context['to_process'][$path] = $status; |
@@ -2490,17 +2596,20 @@ discard block |
||
| 2490 | 2596 | // Make sure the chmod status is valid? |
| 2491 | 2597 | if ($validate_custom) |
| 2492 | 2598 | { |
| 2493 | - if (preg_match('~^[4567][4567][4567]$~', $context['custom_value']) == false) |
|
| 2494 | - fatal_error($txt['chmod_value_invalid']); |
|
| 2599 | + if (preg_match('~^[4567][4567][4567]$~', $context['custom_value']) == false) { |
|
| 2600 | + fatal_error($txt['chmod_value_invalid']); |
|
| 2601 | + } |
|
| 2495 | 2602 | } |
| 2496 | 2603 | |
| 2497 | 2604 | // Nothing to do? |
| 2498 | - if (empty($context['to_process'])) |
|
| 2499 | - redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode(json_encode($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 2605 | + if (empty($context['to_process'])) { |
|
| 2606 | + redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode(json_encode($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 2607 | + } |
|
| 2500 | 2608 | } |
| 2501 | 2609 | // Should never get here, |
| 2502 | - else |
|
| 2503 | - fatal_lang_error('no_access', false); |
|
| 2610 | + else { |
|
| 2611 | + fatal_lang_error('no_access', false); |
|
| 2612 | + } |
|
| 2504 | 2613 | |
| 2505 | 2614 | // Setup the custom value. |
| 2506 | 2615 | $custom_value = octdec('0' . $context['custom_value']); |
@@ -2508,26 +2617,27 @@ discard block |
||
| 2508 | 2617 | // Start processing items. |
| 2509 | 2618 | foreach ($context['to_process'] as $path => $status) |
| 2510 | 2619 | { |
| 2511 | - if (in_array($status, array('execute', 'writable', 'read'))) |
|
| 2512 | - package_chmod($path, $status); |
|
| 2513 | - elseif ($status == 'custom' && !empty($custom_value)) |
|
| 2620 | + if (in_array($status, array('execute', 'writable', 'read'))) { |
|
| 2621 | + package_chmod($path, $status); |
|
| 2622 | + } elseif ($status == 'custom' && !empty($custom_value)) |
|
| 2514 | 2623 | { |
| 2515 | 2624 | // Use FTP if we have it. |
| 2516 | 2625 | if (!empty($package_ftp) && !empty($_SESSION['pack_ftp'])) |
| 2517 | 2626 | { |
| 2518 | 2627 | $ftp_file = strtr($path, array($_SESSION['pack_ftp']['root'] => '')); |
| 2519 | 2628 | $package_ftp->chmod($ftp_file, $custom_value); |
| 2629 | + } else { |
|
| 2630 | + smf_chmod($path, $custom_value); |
|
| 2520 | 2631 | } |
| 2521 | - else |
|
| 2522 | - smf_chmod($path, $custom_value); |
|
| 2523 | 2632 | } |
| 2524 | 2633 | |
| 2525 | 2634 | // This fish is fried... |
| 2526 | 2635 | unset($context['to_process'][$path]); |
| 2527 | 2636 | |
| 2528 | 2637 | // See if we're out of time? |
| 2529 | - if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) |
|
| 2530 | - return false; |
|
| 2638 | + if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) { |
|
| 2639 | + return false; |
|
| 2640 | + } |
|
| 2531 | 2641 | } |
| 2532 | 2642 | } |
| 2533 | 2643 | // If predefined this is a little different. |
@@ -2595,23 +2705,27 @@ discard block |
||
| 2595 | 2705 | { |
| 2596 | 2706 | global $context; |
| 2597 | 2707 | |
| 2598 | - if (!empty($data['writable_on'])) |
|
| 2599 | - if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive') |
|
| 2708 | + if (!empty($data['writable_on'])) { |
|
| 2709 | + if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive') |
|
| 2600 | 2710 | $context['special_files'][$path] = 1; |
| 2711 | + } |
|
| 2601 | 2712 | |
| 2602 | - if (!empty($data['contents'])) |
|
| 2603 | - foreach ($data['contents'] as $name => $contents) |
|
| 2713 | + if (!empty($data['contents'])) { |
|
| 2714 | + foreach ($data['contents'] as $name => $contents) |
|
| 2604 | 2715 | build_special_files__recursive($path . '/' . $name, $contents); |
| 2716 | + } |
|
| 2605 | 2717 | } |
| 2606 | 2718 | |
| 2607 | - foreach ($context['file_tree'] as $path => $data) |
|
| 2608 | - build_special_files__recursive($path, $data); |
|
| 2719 | + foreach ($context['file_tree'] as $path => $data) { |
|
| 2720 | + build_special_files__recursive($path, $data); |
|
| 2721 | + } |
|
| 2609 | 2722 | } |
| 2610 | 2723 | // Free doesn't need special files. |
| 2611 | - elseif ($context['predefined_type'] == 'free') |
|
| 2612 | - $context['special_files'] = array(); |
|
| 2613 | - else |
|
| 2614 | - $context['special_files'] = smf_json_decode(base64_decode($_POST['specialFiles']), true); |
|
| 2724 | + elseif ($context['predefined_type'] == 'free') { |
|
| 2725 | + $context['special_files'] = array(); |
|
| 2726 | + } else { |
|
| 2727 | + $context['special_files'] = smf_json_decode(base64_decode($_POST['specialFiles']), true); |
|
| 2728 | + } |
|
| 2615 | 2729 | |
| 2616 | 2730 | // Now we definitely know where we are, we need to go through again doing the chmod! |
| 2617 | 2731 | foreach ($context['directory_list'] as $path => $dummy) |
@@ -2656,8 +2770,9 @@ discard block |
||
| 2656 | 2770 | unset($context['directory_list'][$path]); |
| 2657 | 2771 | |
| 2658 | 2772 | // See if we're out of time? |
| 2659 | - if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) |
|
| 2660 | - return false; |
|
| 2773 | + if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) { |
|
| 2774 | + return false; |
|
| 2775 | + } |
|
| 2661 | 2776 | } |
| 2662 | 2777 | } |
| 2663 | 2778 | |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Entry point function, permission checks, admin bars, etc. |
@@ -99,27 +100,27 @@ discard block |
||
| 99 | 100 | 'function' => function ($rowData) use ($scripturl) |
| 100 | 101 | { |
| 101 | 102 | // Since the moderator group has no explicit members, no link is needed. |
| 102 | - if ($rowData['id_group'] == 3) |
|
| 103 | - $group_name = $rowData['group_name']; |
|
| 104 | - else |
|
| 103 | + if ($rowData['id_group'] == 3) { |
|
| 104 | + $group_name = $rowData['group_name']; |
|
| 105 | + } else |
|
| 105 | 106 | { |
| 106 | 107 | $color_style = empty($rowData['online_color']) ? '' : sprintf(' style="color: %1$s;"', $rowData['online_color']); |
| 107 | 108 | |
| 108 | 109 | if (allowedTo('manage_membergroups')) |
| 109 | 110 | { |
| 110 | 111 | $group_name = sprintf('<a href="%1$s?action=admin;area=membergroups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']); |
| 111 | - } |
|
| 112 | - else |
|
| 112 | + } else |
|
| 113 | 113 | { |
| 114 | 114 | $group_name = sprintf('<a href="%1$s?action=groups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']); |
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | // Add a help option for moderator and administrator. |
| 119 | - if ($rowData['id_group'] == 1) |
|
| 120 | - $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
| 121 | - elseif ($rowData['id_group'] == 3) |
|
| 122 | - $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
| 119 | + if ($rowData['id_group'] == 1) { |
|
| 120 | + $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
| 121 | + } elseif ($rowData['id_group'] == 3) { |
|
| 122 | + $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
| 123 | + } |
|
| 123 | 124 | |
| 124 | 125 | return $group_name; |
| 125 | 126 | }, |
@@ -198,8 +199,9 @@ discard block |
||
| 198 | 199 | $_REQUEST['group'] = isset($_REQUEST['group']) ? (int) $_REQUEST['group'] : 0; |
| 199 | 200 | |
| 200 | 201 | // No browsing of guests, membergroup 0 or moderators. |
| 201 | - if (in_array($_REQUEST['group'], array(-1, 0, 3))) |
|
| 202 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
| 202 | + if (in_array($_REQUEST['group'], array(-1, 0, 3))) { |
|
| 203 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
| 204 | + } |
|
| 203 | 205 | |
| 204 | 206 | // Load up the group details. |
| 205 | 207 | $request = $smcFunc['db_query']('', ' |
@@ -214,8 +216,9 @@ discard block |
||
| 214 | 216 | ) |
| 215 | 217 | ); |
| 216 | 218 | // Doesn't exist? |
| 217 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 218 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
| 219 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 220 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
| 221 | + } |
|
| 219 | 222 | $context['group'] = $smcFunc['db_fetch_assoc']($request); |
| 220 | 223 | $smcFunc['db_free_result']($request); |
| 221 | 224 | |
@@ -248,21 +251,25 @@ discard block |
||
| 248 | 251 | 'name' => $row['real_name'] |
| 249 | 252 | ); |
| 250 | 253 | |
| 251 | - if ($user_info['id'] == $row['id_member'] && $context['group']['group_type'] != 1) |
|
| 252 | - $context['group']['can_moderate'] = true; |
|
| 254 | + if ($user_info['id'] == $row['id_member'] && $context['group']['group_type'] != 1) { |
|
| 255 | + $context['group']['can_moderate'] = true; |
|
| 256 | + } |
|
| 253 | 257 | } |
| 254 | 258 | $smcFunc['db_free_result']($request); |
| 255 | 259 | |
| 256 | 260 | // If this group is hidden then it can only "exists" if the user can moderate it! |
| 257 | - if ($context['group']['hidden'] && !$context['group']['can_moderate']) |
|
| 258 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
| 261 | + if ($context['group']['hidden'] && !$context['group']['can_moderate']) { |
|
| 262 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
| 263 | + } |
|
| 259 | 264 | |
| 260 | 265 | // You can only assign membership if you are the moderator and/or can manage groups! |
| 261 | - if (!$context['group']['can_moderate']) |
|
| 262 | - $context['group']['assignable'] = 0; |
|
| 266 | + if (!$context['group']['can_moderate']) { |
|
| 267 | + $context['group']['assignable'] = 0; |
|
| 268 | + } |
|
| 263 | 269 | // Non-admins cannot assign admins. |
| 264 | - elseif ($context['group']['id'] == 1 && !allowedTo('admin_forum')) |
|
| 265 | - $context['group']['assignable'] = 0; |
|
| 270 | + elseif ($context['group']['id'] == 1 && !allowedTo('admin_forum')) { |
|
| 271 | + $context['group']['assignable'] = 0; |
|
| 272 | + } |
|
| 266 | 273 | |
| 267 | 274 | // Removing member from group? |
| 268 | 275 | if (isset($_POST['remove']) && !empty($_REQUEST['rem']) && is_array($_REQUEST['rem']) && $context['group']['assignable']) |
@@ -271,8 +278,9 @@ discard block |
||
| 271 | 278 | validateToken('mod-mgm'); |
| 272 | 279 | |
| 273 | 280 | // Make sure we're dealing with integers only. |
| 274 | - foreach ($_REQUEST['rem'] as $key => $group) |
|
| 275 | - $_REQUEST['rem'][$key] = (int) $group; |
|
| 281 | + foreach ($_REQUEST['rem'] as $key => $group) { |
|
| 282 | + $_REQUEST['rem'][$key] = (int) $group; |
|
| 283 | + } |
|
| 276 | 284 | |
| 277 | 285 | require_once($sourcedir . '/Subs-Membergroups.php'); |
| 278 | 286 | removeMembersFromGroups($_REQUEST['rem'], $_REQUEST['group'], true); |
@@ -295,16 +303,18 @@ discard block |
||
| 295 | 303 | { |
| 296 | 304 | $member_names[$index] = trim($smcFunc['strtolower']($member_names[$index])); |
| 297 | 305 | |
| 298 | - if (strlen($member_names[$index]) == 0) |
|
| 299 | - unset($member_names[$index]); |
|
| 306 | + if (strlen($member_names[$index]) == 0) { |
|
| 307 | + unset($member_names[$index]); |
|
| 308 | + } |
|
| 300 | 309 | } |
| 301 | 310 | |
| 302 | 311 | // Any passed by ID? |
| 303 | 312 | $member_ids = array(); |
| 304 | - if (!empty($_REQUEST['member_add'])) |
|
| 305 | - foreach ($_REQUEST['member_add'] as $id) |
|
| 313 | + if (!empty($_REQUEST['member_add'])) { |
|
| 314 | + foreach ($_REQUEST['member_add'] as $id) |
|
| 306 | 315 | if ($id > 0) |
| 307 | 316 | $member_ids[] = (int) $id; |
| 317 | + } |
|
| 308 | 318 | |
| 309 | 319 | // Construct the query pelements. |
| 310 | 320 | if (!empty($member_ids)) |
@@ -332,8 +342,9 @@ discard block |
||
| 332 | 342 | 'id_group' => $_REQUEST['group'], |
| 333 | 343 | )) |
| 334 | 344 | ); |
| 335 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 336 | - $members[] = $row['id_member']; |
|
| 345 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 346 | + $members[] = $row['id_member']; |
|
| 347 | + } |
|
| 337 | 348 | $smcFunc['db_free_result']($request); |
| 338 | 349 | } |
| 339 | 350 | |
@@ -372,10 +383,11 @@ discard block |
||
| 372 | 383 | $context['sort_direction'] = isset($_REQUEST['desc']) ? 'down' : 'up'; |
| 373 | 384 | |
| 374 | 385 | // The where on the query is interesting. Non-moderators should only see people who are in this group as primary. |
| 375 | - if ($context['group']['can_moderate']) |
|
| 376 | - $where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group} OR FIND_IN_SET({int:group}, additional_groups) != 0'; |
|
| 377 | - else |
|
| 378 | - $where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group}'; |
|
| 386 | + if ($context['group']['can_moderate']) { |
|
| 387 | + $where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group} OR FIND_IN_SET({int:group}, additional_groups) != 0'; |
|
| 388 | + } else { |
|
| 389 | + $where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group}'; |
|
| 390 | + } |
|
| 379 | 391 | |
| 380 | 392 | // Count members of the group. |
| 381 | 393 | $request = $smcFunc['db_query']('', ' |
@@ -416,8 +428,9 @@ discard block |
||
| 416 | 428 | $last_online = empty($row['last_login']) ? $txt['never'] : timeformat($row['last_login']); |
| 417 | 429 | |
| 418 | 430 | // Italicize the online note if they aren't activated. |
| 419 | - if ($row['is_activated'] % 10 != 1) |
|
| 420 | - $last_online = '<em title="' . $txt['not_activated'] . '">' . $last_online . '</em>'; |
|
| 431 | + if ($row['is_activated'] % 10 != 1) { |
|
| 432 | + $last_online = '<em title="' . $txt['not_activated'] . '">' . $last_online . '</em>'; |
|
| 433 | + } |
|
| 421 | 434 | |
| 422 | 435 | $context['members'][] = array( |
| 423 | 436 | 'id' => $row['id_member'], |
@@ -437,9 +450,10 @@ discard block |
||
| 437 | 450 | $context['page_title'] = $txt['membergroups_members_title'] . ': ' . $context['group']['name']; |
| 438 | 451 | createToken('mod-mgm'); |
| 439 | 452 | |
| 440 | - if ($context['group']['assignable']) |
|
| 441 | - loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
|
| 442 | -} |
|
| 453 | + if ($context['group']['assignable']) { |
|
| 454 | + loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
|
| 455 | + } |
|
| 456 | + } |
|
| 443 | 457 | |
| 444 | 458 | /** |
| 445 | 459 | * Show and manage all group requests. |
@@ -453,16 +467,18 @@ discard block |
||
| 453 | 467 | $context['sub_template'] = 'show_list'; |
| 454 | 468 | |
| 455 | 469 | // Verify we can be here. |
| 456 | - if ($user_info['mod_cache']['gq'] == '0=1') |
|
| 457 | - isAllowedTo('manage_membergroups'); |
|
| 470 | + if ($user_info['mod_cache']['gq'] == '0=1') { |
|
| 471 | + isAllowedTo('manage_membergroups'); |
|
| 472 | + } |
|
| 458 | 473 | |
| 459 | 474 | // Normally, we act normally... |
| 460 | 475 | $where = ($user_info['mod_cache']['gq'] == '1=1' || $user_info['mod_cache']['gq'] == '0=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']); |
| 461 | 476 | |
| 462 | - if (isset($_GET['closed'])) |
|
| 463 | - $where .= ' AND lgr.status != {int:status_open}'; |
|
| 464 | - else |
|
| 465 | - $where .= ' AND lgr.status = {int:status_open}'; |
|
| 477 | + if (isset($_GET['closed'])) { |
|
| 478 | + $where .= ' AND lgr.status != {int:status_open}'; |
|
| 479 | + } else { |
|
| 480 | + $where .= ' AND lgr.status = {int:status_open}'; |
|
| 481 | + } |
|
| 466 | 482 | |
| 467 | 483 | $where_parameters = array( |
| 468 | 484 | 'status_open' => 0, |
@@ -475,8 +491,9 @@ discard block |
||
| 475 | 491 | validateToken('mod-gr'); |
| 476 | 492 | |
| 477 | 493 | // Clean the values. |
| 478 | - foreach ($_POST['groupr'] as $k => $request) |
|
| 479 | - $_POST['groupr'][$k] = (int) $request; |
|
| 494 | + foreach ($_POST['groupr'] as $k => $request) { |
|
| 495 | + $_POST['groupr'][$k] = (int) $request; |
|
| 496 | + } |
|
| 480 | 497 | |
| 481 | 498 | $log_changes = array(); |
| 482 | 499 | |
@@ -513,8 +530,8 @@ discard block |
||
| 513 | 530 | $request_list = array(); |
| 514 | 531 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 515 | 532 | { |
| 516 | - if (!isset($log_changes[$row['id_request']])) |
|
| 517 | - $log_changes[$row['id_request']] = array( |
|
| 533 | + if (!isset($log_changes[$row['id_request']])) { |
|
| 534 | + $log_changes[$row['id_request']] = array( |
|
| 518 | 535 | 'id_request' => $row['id_request'], |
| 519 | 536 | 'status' => $_POST['req_action'] == 'approve' ? 1 : 2, // 1 = approved, 2 = rejected |
| 520 | 537 | 'id_member_acted' => $user_info['id'], |
@@ -522,6 +539,7 @@ discard block |
||
| 522 | 539 | 'time_acted' => time(), |
| 523 | 540 | 'act_reason' => $_POST['req_action'] != 'approve' && !empty($_POST['groupreason']) && !empty($_POST['groupreason'][$row['id_request']]) ? $smcFunc['htmlspecialchars']($_POST['groupreason'][$row['id_request']], ENT_QUOTES) : '', |
| 524 | 541 | ); |
| 542 | + } |
|
| 525 | 543 | $request_list[] = $row['id_request']; |
| 526 | 544 | } |
| 527 | 545 | $smcFunc['db_free_result']($request); |
@@ -744,21 +762,24 @@ discard block |
||
| 744 | 762 | $group_requests = array(); |
| 745 | 763 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 746 | 764 | { |
| 747 | - if (empty($row['reason'])) |
|
| 748 | - $reason = '<em>(' . $txt['mc_groupr_no_reason'] . ')</em>'; |
|
| 749 | - else |
|
| 750 | - $reason = censorText($row['reason']); |
|
| 765 | + if (empty($row['reason'])) { |
|
| 766 | + $reason = '<em>(' . $txt['mc_groupr_no_reason'] . ')</em>'; |
|
| 767 | + } else { |
|
| 768 | + $reason = censorText($row['reason']); |
|
| 769 | + } |
|
| 751 | 770 | |
| 752 | 771 | if (isset($_GET['closed'])) |
| 753 | 772 | { |
| 754 | - if ($row['status'] == 1) |
|
| 755 | - $reason .= '<br><br><strong>' . $txt['mc_groupr_approved'] . '</strong>'; |
|
| 756 | - elseif ($row['status'] == 2) |
|
| 757 | - $reason .= '<br><br><strong>' . $txt['mc_groupr_rejected'] . '</strong>'; |
|
| 773 | + if ($row['status'] == 1) { |
|
| 774 | + $reason .= '<br><br><strong>' . $txt['mc_groupr_approved'] . '</strong>'; |
|
| 775 | + } elseif ($row['status'] == 2) { |
|
| 776 | + $reason .= '<br><br><strong>' . $txt['mc_groupr_rejected'] . '</strong>'; |
|
| 777 | + } |
|
| 758 | 778 | |
| 759 | 779 | $reason .= ' (' . timeformat($row['time_acted']) . ')'; |
| 760 | - if (!empty($row['act_reason'])) |
|
| 761 | - $reason .= '<br><br>' . censorText($row['act_reason']); |
|
| 780 | + if (!empty($row['act_reason'])) { |
|
| 781 | + $reason .= '<br><br>' . censorText($row['act_reason']); |
|
| 782 | + } |
|
| 762 | 783 | } |
| 763 | 784 | |
| 764 | 785 | $group_requests[] = array( |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 3 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Ask them for their login information. (shows a page for the user to type |
@@ -29,8 +30,9 @@ discard block |
||
| 29 | 30 | global $txt, $context, $scripturl, $user_info; |
| 30 | 31 | |
| 31 | 32 | // You are already logged in, go take a tour of the boards |
| 32 | - if (!empty($user_info['id'])) |
|
| 33 | - redirectexit(); |
|
| 33 | + if (!empty($user_info['id'])) { |
|
| 34 | + redirectexit(); |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | // We need to load the Login template/language file. |
| 36 | 38 | loadLanguage('Login'); |
@@ -57,10 +59,11 @@ discard block |
||
| 57 | 59 | ); |
| 58 | 60 | |
| 59 | 61 | // Set the login URL - will be used when the login process is done (but careful not to send us to an attachment). |
| 60 | - if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) |
|
| 61 | - $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 62 | - elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) |
|
| 63 | - unset($_SESSION['login_url']); |
|
| 62 | + if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) { |
|
| 63 | + $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 64 | + } elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) { |
|
| 65 | + unset($_SESSION['login_url']); |
|
| 66 | + } |
|
| 64 | 67 | |
| 65 | 68 | // Create a one time token. |
| 66 | 69 | createToken('login'); |
@@ -83,8 +86,9 @@ discard block |
||
| 83 | 86 | global $cookiename, $modSettings, $context, $sourcedir, $maintenance; |
| 84 | 87 | |
| 85 | 88 | // Check to ensure we're forcing SSL for authentication |
| 86 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
| 87 | - fatal_lang_error('login_ssl_required'); |
|
| 89 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
| 90 | + fatal_lang_error('login_ssl_required'); |
|
| 91 | + } |
|
| 88 | 92 | |
| 89 | 93 | // Load cookie authentication stuff. |
| 90 | 94 | require_once($sourcedir . '/Subs-Auth.php'); |
@@ -102,19 +106,20 @@ discard block |
||
| 102 | 106 | list (, , $timeout) = smf_json_decode($_COOKIE[$cookiename], true); |
| 103 | 107 | |
| 104 | 108 | // That didn't work... Maybe it's using serialize? |
| 105 | - if (is_null($timeout)) |
|
| 106 | - list (, , $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
| 107 | - } |
|
| 108 | - elseif (isset($_SESSION['login_' . $cookiename])) |
|
| 109 | + if (is_null($timeout)) { |
|
| 110 | + list (, , $timeout) = safe_unserialize($_COOKIE[$cookiename]); |
|
| 111 | + } |
|
| 112 | + } elseif (isset($_SESSION['login_' . $cookiename])) |
|
| 109 | 113 | { |
| 110 | 114 | list (, , $timeout) = smf_json_decode($_SESSION['login_' . $cookiename]); |
| 111 | 115 | |
| 112 | 116 | // Try for old format |
| 113 | - if (is_null($timeout)) |
|
| 114 | - list (, , $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 117 | + if (is_null($timeout)) { |
|
| 118 | + list (, , $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
|
| 115 | 122 | } |
| 116 | - else |
|
| 117 | - trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR); |
|
| 118 | 123 | |
| 119 | 124 | $user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4); |
| 120 | 125 | updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt'])); |
@@ -125,16 +130,18 @@ discard block |
||
| 125 | 130 | $tfadata = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true); |
| 126 | 131 | |
| 127 | 132 | // If that didn't work, try unserialize instead... |
| 128 | - if (is_null($tfadata)) |
|
| 129 | - $tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']); |
|
| 133 | + if (is_null($tfadata)) { |
|
| 134 | + $tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']); |
|
| 135 | + } |
|
| 130 | 136 | |
| 131 | 137 | list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata; |
| 132 | 138 | |
| 133 | 139 | // If we're preserving the cookie, reset it with updated salt |
| 134 | - if ($preserve && time() < $exp) |
|
| 135 | - setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true); |
|
| 136 | - else |
|
| 137 | - setTFACookie(-3600, 0, ''); |
|
| 140 | + if ($preserve && time() < $exp) { |
|
| 141 | + setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true); |
|
| 142 | + } else { |
|
| 143 | + setTFACookie(-3600, 0, ''); |
|
| 144 | + } |
|
| 138 | 145 | } |
| 139 | 146 | |
| 140 | 147 | setLoginCookie($timeout - time(), $user_info['id'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
@@ -145,20 +152,20 @@ discard block |
||
| 145 | 152 | elseif (isset($_GET['sa']) && $_GET['sa'] == 'check') |
| 146 | 153 | { |
| 147 | 154 | // Strike! You're outta there! |
| 148 | - if ($_GET['member'] != $user_info['id']) |
|
| 149 | - fatal_lang_error('login_cookie_error', false); |
|
| 155 | + if ($_GET['member'] != $user_info['id']) { |
|
| 156 | + fatal_lang_error('login_cookie_error', false); |
|
| 157 | + } |
|
| 150 | 158 | |
| 151 | 159 | $user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap'])))); |
| 152 | 160 | |
| 153 | 161 | // Some whitelisting for login_url... |
| 154 | - if (empty($_SESSION['login_url'])) |
|
| 155 | - redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
| 156 | - elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
| 162 | + if (empty($_SESSION['login_url'])) { |
|
| 163 | + redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
|
| 164 | + } elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false)) |
|
| 157 | 165 | { |
| 158 | 166 | unset ($_SESSION['login_url']); |
| 159 | 167 | redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa'); |
| 160 | - } |
|
| 161 | - else |
|
| 168 | + } else |
|
| 162 | 169 | { |
| 163 | 170 | // Best not to clutter the session data too much... |
| 164 | 171 | $temp = $_SESSION['login_url']; |
@@ -169,8 +176,9 @@ discard block |
||
| 169 | 176 | } |
| 170 | 177 | |
| 171 | 178 | // Beyond this point you are assumed to be a guest trying to login. |
| 172 | - if (!$user_info['is_guest']) |
|
| 173 | - redirectexit(); |
|
| 179 | + if (!$user_info['is_guest']) { |
|
| 180 | + redirectexit(); |
|
| 181 | + } |
|
| 174 | 182 | |
| 175 | 183 | // Are you guessing with a script? |
| 176 | 184 | checkSession(); |
@@ -178,18 +186,21 @@ discard block |
||
| 178 | 186 | spamProtection('login'); |
| 179 | 187 | |
| 180 | 188 | // Set the login_url if it's not already set (but careful not to send us to an attachment). |
| 181 | - if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) |
|
| 182 | - $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 189 | + if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) { |
|
| 190 | + $_SESSION['login_url'] = $_SESSION['old_url']; |
|
| 191 | + } |
|
| 183 | 192 | |
| 184 | 193 | // Been guessing a lot, haven't we? |
| 185 | - if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) |
|
| 186 | - fatal_lang_error('login_threshold_fail', 'critical'); |
|
| 194 | + if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) { |
|
| 195 | + fatal_lang_error('login_threshold_fail', 'critical'); |
|
| 196 | + } |
|
| 187 | 197 | |
| 188 | 198 | // Set up the cookie length. (if it's invalid, just fall through and use the default.) |
| 189 | - if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) |
|
| 190 | - $modSettings['cookieTime'] = 3153600; |
|
| 191 | - elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) |
|
| 192 | - $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
| 199 | + if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) { |
|
| 200 | + $modSettings['cookieTime'] = 3153600; |
|
| 201 | + } elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) { |
|
| 202 | + $modSettings['cookieTime'] = (int) $_POST['cookielength']; |
|
| 203 | + } |
|
| 193 | 204 | |
| 194 | 205 | loadLanguage('Login'); |
| 195 | 206 | // Load the template stuff. |
@@ -301,8 +312,9 @@ discard block |
||
| 301 | 312 | $other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd'])); |
| 302 | 313 | |
| 303 | 314 | // Snitz style - SHA-256. Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway. |
| 304 | - if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) |
|
| 305 | - $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
| 315 | + if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) { |
|
| 316 | + $other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd'])); |
|
| 317 | + } |
|
| 306 | 318 | |
| 307 | 319 | // phpBB3 users new hashing. We now support it as well ;). |
| 308 | 320 | $other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']); |
@@ -322,27 +334,29 @@ discard block |
||
| 322 | 334 | // Some common md5 ones. |
| 323 | 335 | $other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']); |
| 324 | 336 | $other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']); |
| 325 | - } |
|
| 326 | - elseif (strlen($user_settings['passwd']) == 40) |
|
| 337 | + } elseif (strlen($user_settings['passwd']) == 40) |
|
| 327 | 338 | { |
| 328 | 339 | // Maybe they are using a hash from before the password fix. |
| 329 | 340 | // This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1 |
| 330 | 341 | $other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd'])); |
| 331 | 342 | |
| 332 | 343 | // BurningBoard3 style of hashing. |
| 333 | - if (!empty($modSettings['enable_password_conversion'])) |
|
| 334 | - $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
| 344 | + if (!empty($modSettings['enable_password_conversion'])) { |
|
| 345 | + $other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd']))); |
|
| 346 | + } |
|
| 335 | 347 | |
| 336 | 348 | // Perhaps we converted to UTF-8 and have a valid password being hashed differently. |
| 337 | 349 | if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8') |
| 338 | 350 | { |
| 339 | 351 | // Try iconv first, for no particular reason. |
| 340 | - if (function_exists('iconv')) |
|
| 341 | - $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
| 352 | + if (function_exists('iconv')) { |
|
| 353 | + $other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd']))); |
|
| 354 | + } |
|
| 342 | 355 | |
| 343 | 356 | // Say it aint so, iconv failed! |
| 344 | - if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) |
|
| 345 | - $other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet']))); |
|
| 357 | + if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) { |
|
| 358 | + $other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet']))); |
|
| 359 | + } |
|
| 346 | 360 | } |
| 347 | 361 | } |
| 348 | 362 | |
@@ -372,8 +386,9 @@ discard block |
||
| 372 | 386 | $_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1; |
| 373 | 387 | |
| 374 | 388 | // Hmm... don't remember it, do you? Here, try the password reminder ;). |
| 375 | - if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) |
|
| 376 | - redirectexit('action=reminder'); |
|
| 389 | + if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) { |
|
| 390 | + redirectexit('action=reminder'); |
|
| 391 | + } |
|
| 377 | 392 | // We'll give you another chance... |
| 378 | 393 | else |
| 379 | 394 | { |
@@ -384,8 +399,7 @@ discard block |
||
| 384 | 399 | return; |
| 385 | 400 | } |
| 386 | 401 | } |
| 387 | - } |
|
| 388 | - elseif (!empty($user_settings['passwd_flood'])) |
|
| 402 | + } elseif (!empty($user_settings['passwd_flood'])) |
|
| 389 | 403 | { |
| 390 | 404 | // Let's be sure they weren't a little hacker. |
| 391 | 405 | validatePasswordFlood($user_settings['id_member'], $user_settings['passwd_flood'], true); |
@@ -402,8 +416,9 @@ discard block |
||
| 402 | 416 | } |
| 403 | 417 | |
| 404 | 418 | // Check their activation status. |
| 405 | - if (!checkActivation()) |
|
| 406 | - return; |
|
| 419 | + if (!checkActivation()) { |
|
| 420 | + return; |
|
| 421 | + } |
|
| 407 | 422 | |
| 408 | 423 | DoLogin(); |
| 409 | 424 | } |
@@ -415,8 +430,9 @@ discard block |
||
| 415 | 430 | { |
| 416 | 431 | global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl; |
| 417 | 432 | |
| 418 | - if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) |
|
| 419 | - fatal_lang_error('no_access', false); |
|
| 433 | + if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) { |
|
| 434 | + fatal_lang_error('no_access', false); |
|
| 435 | + } |
|
| 420 | 436 | |
| 421 | 437 | loadLanguage('Profile'); |
| 422 | 438 | require_once($sourcedir . '/Class-TOTP.php'); |
@@ -424,8 +440,9 @@ discard block |
||
| 424 | 440 | $member = $context['tfa_member']; |
| 425 | 441 | |
| 426 | 442 | // Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA |
| 427 | - if (time() - $member['last_login'] < 120) |
|
| 428 | - fatal_lang_error('tfa_wait', false); |
|
| 443 | + if (time() - $member['last_login'] < 120) { |
|
| 444 | + fatal_lang_error('tfa_wait', false); |
|
| 445 | + } |
|
| 429 | 446 | |
| 430 | 447 | $totp = new \TOTP\Auth($member['tfa_secret']); |
| 431 | 448 | $totp->setRange(1); |
@@ -439,8 +456,9 @@ discard block |
||
| 439 | 456 | if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup'])) |
| 440 | 457 | { |
| 441 | 458 | // Check to ensure we're forcing SSL for authentication |
| 442 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
| 443 | - fatal_lang_error('login_ssl_required'); |
|
| 459 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
| 460 | + fatal_lang_error('login_ssl_required'); |
|
| 461 | + } |
|
| 444 | 462 | |
| 445 | 463 | $code = $_POST['tfa_code']; |
| 446 | 464 | |
@@ -450,20 +468,19 @@ discard block |
||
| 450 | 468 | |
| 451 | 469 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']), !empty($_POST['tfa_preserve'])); |
| 452 | 470 | redirectexit(); |
| 453 | - } |
|
| 454 | - else |
|
| 471 | + } else |
|
| 455 | 472 | { |
| 456 | 473 | validatePasswordFlood($member['id_member'], $member['passwd_flood'], false, true); |
| 457 | 474 | |
| 458 | 475 | $context['tfa_error'] = true; |
| 459 | 476 | $context['tfa_value'] = $_POST['tfa_code']; |
| 460 | 477 | } |
| 461 | - } |
|
| 462 | - elseif (!empty($_POST['tfa_backup'])) |
|
| 478 | + } elseif (!empty($_POST['tfa_backup'])) |
|
| 463 | 479 | { |
| 464 | 480 | // Check to ensure we're forcing SSL for authentication |
| 465 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
| 466 | - fatal_lang_error('login_ssl_required'); |
|
| 481 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
| 482 | + fatal_lang_error('login_ssl_required'); |
|
| 483 | + } |
|
| 467 | 484 | |
| 468 | 485 | $backup = $_POST['tfa_backup']; |
| 469 | 486 | |
@@ -477,8 +494,7 @@ discard block |
||
| 477 | 494 | )); |
| 478 | 495 | setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt'])); |
| 479 | 496 | redirectexit('action=profile;area=tfasetup;backup'); |
| 480 | - } |
|
| 481 | - else |
|
| 497 | + } else |
|
| 482 | 498 | { |
| 483 | 499 | validatePasswordFlood($member['id_member'], $member['passwd_flood'], false, true); |
| 484 | 500 | |
@@ -501,8 +517,9 @@ discard block |
||
| 501 | 517 | { |
| 502 | 518 | global $context, $txt, $scripturl, $user_settings, $modSettings; |
| 503 | 519 | |
| 504 | - if (!isset($context['login_errors'])) |
|
| 505 | - $context['login_errors'] = array(); |
|
| 520 | + if (!isset($context['login_errors'])) { |
|
| 521 | + $context['login_errors'] = array(); |
|
| 522 | + } |
|
| 506 | 523 | |
| 507 | 524 | // What is the true activation status of this account? |
| 508 | 525 | $activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated']; |
@@ -514,8 +531,9 @@ discard block |
||
| 514 | 531 | return false; |
| 515 | 532 | } |
| 516 | 533 | // Awaiting approval still? |
| 517 | - elseif ($activation_status == 3) |
|
| 518 | - fatal_lang_error('still_awaiting_approval', 'user'); |
|
| 534 | + elseif ($activation_status == 3) { |
|
| 535 | + fatal_lang_error('still_awaiting_approval', 'user'); |
|
| 536 | + } |
|
| 519 | 537 | // Awaiting deletion, changed their mind? |
| 520 | 538 | elseif ($activation_status == 4) |
| 521 | 539 | { |
@@ -523,8 +541,7 @@ discard block |
||
| 523 | 541 | { |
| 524 | 542 | updateMemberData($user_settings['id_member'], array('is_activated' => 1)); |
| 525 | 543 | updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0))); |
| 526 | - } |
|
| 527 | - else |
|
| 544 | + } else |
|
| 528 | 545 | { |
| 529 | 546 | $context['disable_login_hashing'] = true; |
| 530 | 547 | $context['login_errors'][] = $txt['awaiting_delete_account']; |
@@ -565,8 +582,9 @@ discard block |
||
| 565 | 582 | setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt'])); |
| 566 | 583 | |
| 567 | 584 | // Reset the login threshold. |
| 568 | - if (isset($_SESSION['failed_login'])) |
|
| 569 | - unset($_SESSION['failed_login']); |
|
| 585 | + if (isset($_SESSION['failed_login'])) { |
|
| 586 | + unset($_SESSION['failed_login']); |
|
| 587 | + } |
|
| 570 | 588 | |
| 571 | 589 | $user_info['is_guest'] = false; |
| 572 | 590 | $user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']); |
@@ -588,16 +606,18 @@ discard block |
||
| 588 | 606 | 'id_member' => $user_info['id'], |
| 589 | 607 | ) |
| 590 | 608 | ); |
| 591 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
| 592 | - $_SESSION['first_login'] = true; |
|
| 593 | - else |
|
| 594 | - unset($_SESSION['first_login']); |
|
| 609 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
| 610 | + $_SESSION['first_login'] = true; |
|
| 611 | + } else { |
|
| 612 | + unset($_SESSION['first_login']); |
|
| 613 | + } |
|
| 595 | 614 | $smcFunc['db_free_result']($request); |
| 596 | 615 | |
| 597 | 616 | // You've logged in, haven't you? |
| 598 | 617 | $update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']); |
| 599 | - if (empty($user_settings['tfa_secret'])) |
|
| 600 | - $update['last_login'] = time(); |
|
| 618 | + if (empty($user_settings['tfa_secret'])) { |
|
| 619 | + $update['last_login'] = time(); |
|
| 620 | + } |
|
| 601 | 621 | updateMemberData($user_info['id'], $update); |
| 602 | 622 | |
| 603 | 623 | // Get rid of the online entry for that old guest.... |
@@ -611,8 +631,8 @@ discard block |
||
| 611 | 631 | $_SESSION['log_time'] = 0; |
| 612 | 632 | |
| 613 | 633 | // Log this entry, only if we have it enabled. |
| 614 | - if (!empty($modSettings['loginHistoryDays'])) |
|
| 615 | - $smcFunc['db_insert']('insert', |
|
| 634 | + if (!empty($modSettings['loginHistoryDays'])) { |
|
| 635 | + $smcFunc['db_insert']('insert', |
|
| 616 | 636 | '{db_prefix}member_logins', |
| 617 | 637 | array( |
| 618 | 638 | 'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet', |
@@ -624,13 +644,15 @@ discard block |
||
| 624 | 644 | 'id_member', 'time' |
| 625 | 645 | ) |
| 626 | 646 | ); |
| 647 | + } |
|
| 627 | 648 | |
| 628 | 649 | // Just log you back out if it's in maintenance mode and you AREN'T an admin. |
| 629 | - if (empty($maintenance) || allowedTo('admin_forum')) |
|
| 630 | - redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
| 631 | - else |
|
| 632 | - redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
| 633 | -} |
|
| 650 | + if (empty($maintenance) || allowedTo('admin_forum')) { |
|
| 651 | + redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']); |
|
| 652 | + } else { |
|
| 653 | + redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']); |
|
| 654 | + } |
|
| 655 | + } |
|
| 634 | 656 | |
| 635 | 657 | /** |
| 636 | 658 | * Logs the current user out of their account. |
@@ -646,13 +668,15 @@ discard block |
||
| 646 | 668 | global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings; |
| 647 | 669 | |
| 648 | 670 | // Make sure they aren't being auto-logged out. |
| 649 | - if (!$internal) |
|
| 650 | - checkSession('get'); |
|
| 671 | + if (!$internal) { |
|
| 672 | + checkSession('get'); |
|
| 673 | + } |
|
| 651 | 674 | |
| 652 | 675 | require_once($sourcedir . '/Subs-Auth.php'); |
| 653 | 676 | |
| 654 | - if (isset($_SESSION['pack_ftp'])) |
|
| 655 | - $_SESSION['pack_ftp'] = null; |
|
| 677 | + if (isset($_SESSION['pack_ftp'])) { |
|
| 678 | + $_SESSION['pack_ftp'] = null; |
|
| 679 | + } |
|
| 656 | 680 | |
| 657 | 681 | // It won't be first login anymore. |
| 658 | 682 | unset($_SESSION['first_login']); |
@@ -680,24 +704,27 @@ discard block |
||
| 680 | 704 | |
| 681 | 705 | // And some other housekeeping while we're at it. |
| 682 | 706 | $salt = substr(md5(mt_rand()), 0, 4); |
| 683 | - if (!empty($user_info['id'])) |
|
| 684 | - updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
| 707 | + if (!empty($user_info['id'])) { |
|
| 708 | + updateMemberData($user_info['id'], array('password_salt' => $salt)); |
|
| 709 | + } |
|
| 685 | 710 | |
| 686 | 711 | if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa'])) |
| 687 | 712 | { |
| 688 | 713 | $tfadata = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true); |
| 689 | 714 | |
| 690 | 715 | // If that failed, try the old method |
| 691 | - if (is_null($tfadata)) |
|
| 692 | - $tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']); |
|
| 716 | + if (is_null($tfadata)) { |
|
| 717 | + $tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']); |
|
| 718 | + } |
|
| 693 | 719 | |
| 694 | 720 | list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata; |
| 695 | 721 | |
| 696 | 722 | // If we're preserving the cookie, reset it with updated salt |
| 697 | - if ($preserve && time() < $exp) |
|
| 698 | - setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true); |
|
| 699 | - else |
|
| 700 | - setTFACookie(-3600, 0, ''); |
|
| 723 | + if ($preserve && time() < $exp) { |
|
| 724 | + setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true); |
|
| 725 | + } else { |
|
| 726 | + setTFACookie(-3600, 0, ''); |
|
| 727 | + } |
|
| 701 | 728 | } |
| 702 | 729 | |
| 703 | 730 | session_destroy(); |
@@ -705,14 +732,13 @@ discard block |
||
| 705 | 732 | // Off to the merry board index we go! |
| 706 | 733 | if ($redirect) |
| 707 | 734 | { |
| 708 | - if (empty($_SESSION['logout_url'])) |
|
| 709 | - redirectexit('', $context['server']['needs_login_fix']); |
|
| 710 | - elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
| 735 | + if (empty($_SESSION['logout_url'])) { |
|
| 736 | + redirectexit('', $context['server']['needs_login_fix']); |
|
| 737 | + } elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false)) |
|
| 711 | 738 | { |
| 712 | 739 | unset ($_SESSION['logout_url']); |
| 713 | 740 | redirectexit(); |
| 714 | - } |
|
| 715 | - else |
|
| 741 | + } else |
|
| 716 | 742 | { |
| 717 | 743 | $temp = $_SESSION['logout_url']; |
| 718 | 744 | unset($_SESSION['logout_url']); |
@@ -745,8 +771,9 @@ discard block |
||
| 745 | 771 | function phpBB3_password_check($passwd, $passwd_hash) |
| 746 | 772 | { |
| 747 | 773 | // Too long or too short? |
| 748 | - if (strlen($passwd_hash) != 34) |
|
| 749 | - return; |
|
| 774 | + if (strlen($passwd_hash) != 34) { |
|
| 775 | + return; |
|
| 776 | + } |
|
| 750 | 777 | |
| 751 | 778 | // Range of characters allowed. |
| 752 | 779 | $range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
@@ -758,8 +785,9 @@ discard block |
||
| 758 | 785 | $salt = substr($passwd_hash, 4, 8); |
| 759 | 786 | |
| 760 | 787 | $hash = md5($salt . $passwd, true); |
| 761 | - for (; $count != 0; --$count) |
|
| 762 | - $hash = md5($hash . $passwd, true); |
|
| 788 | + for (; $count != 0; --$count) { |
|
| 789 | + $hash = md5($hash . $passwd, true); |
|
| 790 | + } |
|
| 763 | 791 | |
| 764 | 792 | $output = substr($passwd_hash, 0, 12); |
| 765 | 793 | $i = 0; |
@@ -768,21 +796,25 @@ discard block |
||
| 768 | 796 | $value = ord($hash[$i++]); |
| 769 | 797 | $output .= $range[$value & 0x3f]; |
| 770 | 798 | |
| 771 | - if ($i < 16) |
|
| 772 | - $value |= ord($hash[$i]) << 8; |
|
| 799 | + if ($i < 16) { |
|
| 800 | + $value |= ord($hash[$i]) << 8; |
|
| 801 | + } |
|
| 773 | 802 | |
| 774 | 803 | $output .= $range[($value >> 6) & 0x3f]; |
| 775 | 804 | |
| 776 | - if ($i++ >= 16) |
|
| 777 | - break; |
|
| 805 | + if ($i++ >= 16) { |
|
| 806 | + break; |
|
| 807 | + } |
|
| 778 | 808 | |
| 779 | - if ($i < 16) |
|
| 780 | - $value |= ord($hash[$i]) << 16; |
|
| 809 | + if ($i < 16) { |
|
| 810 | + $value |= ord($hash[$i]) << 16; |
|
| 811 | + } |
|
| 781 | 812 | |
| 782 | 813 | $output .= $range[($value >> 12) & 0x3f]; |
| 783 | 814 | |
| 784 | - if ($i++ >= 16) |
|
| 785 | - break; |
|
| 815 | + if ($i++ >= 16) { |
|
| 816 | + break; |
|
| 817 | + } |
|
| 786 | 818 | |
| 787 | 819 | $output .= $range[($value >> 18) & 0x3f]; |
| 788 | 820 | } |
@@ -813,8 +845,9 @@ discard block |
||
| 813 | 845 | require_once($sourcedir . '/Subs-Auth.php'); |
| 814 | 846 | setLoginCookie(-3600, 0); |
| 815 | 847 | |
| 816 | - if (isset($_SESSION['login_' . $cookiename])) |
|
| 817 | - unset($_SESSION['login_' . $cookiename]); |
|
| 848 | + if (isset($_SESSION['login_' . $cookiename])) { |
|
| 849 | + unset($_SESSION['login_' . $cookiename]); |
|
| 850 | + } |
|
| 818 | 851 | } |
| 819 | 852 | |
| 820 | 853 | // We need a member! |
@@ -828,8 +861,9 @@ discard block |
||
| 828 | 861 | } |
| 829 | 862 | |
| 830 | 863 | // Right, have we got a flood value? |
| 831 | - if ($password_flood_value !== false) |
|
| 832 | - @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
| 864 | + if ($password_flood_value !== false) { |
|
| 865 | + @list ($time_stamp, $number_tries) = explode('|', $password_flood_value); |
|
| 866 | + } |
|
| 833 | 867 | |
| 834 | 868 | // Timestamp or number of tries invalid? |
| 835 | 869 | if (empty($number_tries) || empty($time_stamp)) |
@@ -845,15 +879,17 @@ discard block |
||
| 845 | 879 | $number_tries = $time_stamp < time() - 20 ? 2 : $number_tries; |
| 846 | 880 | |
| 847 | 881 | // They are trying too fast, make them wait longer |
| 848 | - if ($time_stamp < time() - 10) |
|
| 849 | - $time_stamp = time(); |
|
| 882 | + if ($time_stamp < time() - 10) { |
|
| 883 | + $time_stamp = time(); |
|
| 884 | + } |
|
| 850 | 885 | } |
| 851 | 886 | |
| 852 | 887 | $number_tries++; |
| 853 | 888 | |
| 854 | 889 | // Broken the law? |
| 855 | - if ($number_tries > 5) |
|
| 856 | - fatal_lang_error('login_threshold_brute_fail', 'critical'); |
|
| 890 | + if ($number_tries > 5) { |
|
| 891 | + fatal_lang_error('login_threshold_brute_fail', 'critical'); |
|
| 892 | + } |
|
| 857 | 893 | |
| 858 | 894 | // Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it! |
| 859 | 895 | updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries)); |