@@ -12,8 +12,9 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | // Don't do anything if SMF is already loaded. |
| 15 | -if (defined('SMF')) |
|
| 15 | +if (defined('SMF')) { |
|
| 16 | 16 | return true; |
| 17 | +} |
|
| 17 | 18 | |
| 18 | 19 | define('SMF', 'SSI'); |
| 19 | 20 | |
@@ -28,16 +29,18 @@ discard block |
||
| 28 | 29 | $time_start = microtime(); |
| 29 | 30 | |
| 30 | 31 | // Just being safe... |
| 31 | -foreach (array('db_character_set', 'cachedir') as $variable) |
|
| 32 | +foreach (array('db_character_set', 'cachedir') as $variable) { |
|
| 32 | 33 | if (isset($GLOBALS[$variable])) |
| 33 | 34 | unset($GLOBALS[$variable]); |
| 35 | +} |
|
| 34 | 36 | |
| 35 | 37 | // Get the forum's settings for database and file paths. |
| 36 | 38 | require_once(dirname(__FILE__) . '/Settings.php'); |
| 37 | 39 | |
| 38 | 40 | // Make absolutely sure the cache directory is defined. |
| 39 | -if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) |
|
| 41 | +if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) { |
|
| 40 | 42 | $cachedir = $boarddir . '/cache'; |
| 43 | +} |
|
| 41 | 44 | |
| 42 | 45 | $ssi_error_reporting = error_reporting(defined('E_STRICT') ? E_ALL | E_STRICT : E_ALL); |
| 43 | 46 | /* Set this to one of three values depending on what you want to happen in the case of a fatal error. |
@@ -48,12 +51,14 @@ discard block |
||
| 48 | 51 | $ssi_on_error_method = false; |
| 49 | 52 | |
| 50 | 53 | // Don't do john didley if the forum's been shut down completely. |
| 51 | -if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true)) |
|
| 54 | +if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true)) { |
|
| 52 | 55 | die($mmessage); |
| 56 | +} |
|
| 53 | 57 | |
| 54 | 58 | // Fix for using the current directory as a path. |
| 55 | -if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') |
|
| 59 | +if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') { |
|
| 56 | 60 | $sourcedir = dirname(__FILE__) . substr($sourcedir, 1); |
| 61 | +} |
|
| 57 | 62 | |
| 58 | 63 | // Load the important includes. |
| 59 | 64 | require_once($sourcedir . '/QueryString.php'); |
@@ -78,34 +83,38 @@ discard block |
||
| 78 | 83 | cleanRequest(); |
| 79 | 84 | |
| 80 | 85 | // Seed the random generator? |
| 81 | -if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) |
|
| 86 | +if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) { |
|
| 82 | 87 | smf_seed_generator(); |
| 88 | +} |
|
| 83 | 89 | |
| 84 | 90 | // Check on any hacking attempts. |
| 85 | -if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) |
|
| 91 | +if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) { |
|
| 86 | 92 | die('No direct access...'); |
| 87 | -elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme) |
|
| 93 | +} elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme) { |
|
| 88 | 94 | die('No direct access...'); |
| 89 | -elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme) |
|
| 95 | +} elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme) { |
|
| 90 | 96 | die('No direct access...'); |
| 91 | -elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers) |
|
| 97 | +} elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers) { |
|
| 92 | 98 | die('No direct access...'); |
| 93 | -if (isset($_REQUEST['context'])) |
|
| 99 | +} |
|
| 100 | +if (isset($_REQUEST['context'])) { |
|
| 94 | 101 | die('No direct access...'); |
| 102 | +} |
|
| 95 | 103 | |
| 96 | 104 | // Gzip output? (because it must be boolean and true, this can't be hacked.) |
| 97 | -if (isset($ssi_gzip) && $ssi_gzip === true && ini_get('zlib.output_compression') != '1' && ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>=')) |
|
| 105 | +if (isset($ssi_gzip) && $ssi_gzip === true && ini_get('zlib.output_compression') != '1' && ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>=')) { |
|
| 98 | 106 | ob_start('ob_gzhandler'); |
| 99 | -else |
|
| 107 | +} else { |
|
| 100 | 108 | $modSettings['enableCompressedOutput'] = '0'; |
| 109 | +} |
|
| 101 | 110 | |
| 102 | 111 | // Primarily, this is to fix the URLs... |
| 103 | 112 | ob_start('ob_sessrewrite'); |
| 104 | 113 | |
| 105 | 114 | // Start the session... known to scramble SSI includes in cases... |
| 106 | -if (!headers_sent()) |
|
| 115 | +if (!headers_sent()) { |
|
| 107 | 116 | loadSession(); |
| 108 | -else |
|
| 117 | +} else |
|
| 109 | 118 | { |
| 110 | 119 | if (isset($_COOKIE[session_name()]) || isset($_REQUEST[session_name()])) |
| 111 | 120 | { |
@@ -139,12 +148,14 @@ discard block |
||
| 139 | 148 | loadTheme(isset($ssi_theme) ? (int) $ssi_theme : 0); |
| 140 | 149 | |
| 141 | 150 | // @todo: probably not the best place, but somewhere it should be set... |
| 142 | -if (!headers_sent()) |
|
| 151 | +if (!headers_sent()) { |
|
| 143 | 152 | header('Content-Type: text/html; charset=' . (empty($modSettings['global_character_set']) ? (empty($txt['lang_character_set']) ? 'ISO-8859-1' : $txt['lang_character_set']) : $modSettings['global_character_set'])); |
| 153 | +} |
|
| 144 | 154 | |
| 145 | 155 | // Take care of any banning that needs to be done. |
| 146 | -if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true)) |
|
| 156 | +if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true)) { |
|
| 147 | 157 | is_not_banned(); |
| 158 | +} |
|
| 148 | 159 | |
| 149 | 160 | // Do we allow guests in here? |
| 150 | 161 | if (empty($ssi_guest_access) && empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && basename($_SERVER['PHP_SELF']) != 'SSI.php') |
@@ -159,17 +170,19 @@ discard block |
||
| 159 | 170 | { |
| 160 | 171 | $context['template_layers'] = $ssi_layers; |
| 161 | 172 | template_header(); |
| 162 | -} |
|
| 163 | -else |
|
| 173 | +} else { |
|
| 164 | 174 | setupThemeContext(); |
| 175 | +} |
|
| 165 | 176 | |
| 166 | 177 | // Make sure they didn't muss around with the settings... but only if it's not cli. |
| 167 | -if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '') |
|
| 178 | +if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '') { |
|
| 168 | 179 | trigger_error($txt['ssi_session_broken'], E_USER_NOTICE); |
| 180 | +} |
|
| 169 | 181 | |
| 170 | 182 | // Without visiting the forum this session variable might not be set on submit. |
| 171 | -if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote')) |
|
| 183 | +if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote')) { |
|
| 172 | 184 | $_SESSION['USER_AGENT'] = $_SERVER['HTTP_USER_AGENT']; |
| 185 | +} |
|
| 173 | 186 | |
| 174 | 187 | // Have the ability to easily add functions to SSI. |
| 175 | 188 | call_integration_hook('integrate_SSI'); |
@@ -178,11 +191,13 @@ discard block |
||
| 178 | 191 | if (basename($_SERVER['PHP_SELF']) == 'SSI.php') |
| 179 | 192 | { |
| 180 | 193 | // You shouldn't just access SSI.php directly by URL!! |
| 181 | - if (!isset($_GET['ssi_function'])) |
|
| 182 | - die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\'')); |
|
| 194 | + if (!isset($_GET['ssi_function'])) { |
|
| 195 | + die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\'')); |
|
| 196 | + } |
|
| 183 | 197 | // Call a function passed by GET. |
| 184 | - if (function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest'])) |
|
| 185 | - call_user_func('ssi_' . $_GET['ssi_function']); |
|
| 198 | + if (function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest'])) { |
|
| 199 | + call_user_func('ssi_' . $_GET['ssi_function']); |
|
| 200 | + } |
|
| 186 | 201 | exit; |
| 187 | 202 | } |
| 188 | 203 | |
@@ -199,9 +214,10 @@ discard block |
||
| 199 | 214 | */ |
| 200 | 215 | function ssi_shutdown() |
| 201 | 216 | { |
| 202 | - if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown') |
|
| 203 | - template_footer(); |
|
| 204 | -} |
|
| 217 | + if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown') { |
|
| 218 | + template_footer(); |
|
| 219 | + } |
|
| 220 | + } |
|
| 205 | 221 | |
| 206 | 222 | /** |
| 207 | 223 | * Display a welcome message, like: Hey, User, you have 0 messages, 0 are new. |
@@ -214,15 +230,17 @@ discard block |
||
| 214 | 230 | |
| 215 | 231 | if ($output_method == 'echo') |
| 216 | 232 | { |
| 217 | - if ($context['user']['is_guest']) |
|
| 218 | - echo sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup'); |
|
| 219 | - else |
|
| 220 | - echo $txt['hello_member'], ' <strong>', $context['user']['name'], '</strong>', allowedTo('pm_read') ? ', ' . (empty($context['user']['messages']) ? $txt['msg_alert_no_messages'] : (($context['user']['messages'] == 1 ? sprintf($txt['msg_alert_one_message'], $scripturl . '?action=pm') : sprintf($txt['msg_alert_many_message'], $scripturl . '?action=pm', $context['user']['messages'])) . ', ' . ($context['user']['unread_messages'] == 1 ? $txt['msg_alert_one_new'] : sprintf($txt['msg_alert_many_new'], $context['user']['unread_messages'])))) : ''; |
|
| 233 | + if ($context['user']['is_guest']) { |
|
| 234 | + echo sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup'); |
|
| 235 | + } else { |
|
| 236 | + echo $txt['hello_member'], ' <strong>', $context['user']['name'], '</strong>', allowedTo('pm_read') ? ', ' . (empty($context['user']['messages']) ? $txt['msg_alert_no_messages'] : (($context['user']['messages'] == 1 ? sprintf($txt['msg_alert_one_message'], $scripturl . '?action=pm') : sprintf($txt['msg_alert_many_message'], $scripturl . '?action=pm', $context['user']['messages'])) . ', ' . ($context['user']['unread_messages'] == 1 ? $txt['msg_alert_one_new'] : sprintf($txt['msg_alert_many_new'], $context['user']['unread_messages'])))) : ''; |
|
| 237 | + } |
|
| 221 | 238 | } |
| 222 | 239 | // Don't echo... then do what?! |
| 223 | - else |
|
| 224 | - return $context['user']; |
|
| 225 | -} |
|
| 240 | + else { |
|
| 241 | + return $context['user']; |
|
| 242 | + } |
|
| 243 | + } |
|
| 226 | 244 | |
| 227 | 245 | /** |
| 228 | 246 | * Display a menu bar, like is displayed at the top of the forum. |
@@ -233,12 +251,14 @@ discard block |
||
| 233 | 251 | { |
| 234 | 252 | global $context; |
| 235 | 253 | |
| 236 | - if ($output_method == 'echo') |
|
| 237 | - template_menu(); |
|
| 254 | + if ($output_method == 'echo') { |
|
| 255 | + template_menu(); |
|
| 256 | + } |
|
| 238 | 257 | // What else could this do? |
| 239 | - else |
|
| 240 | - return $context['menu_buttons']; |
|
| 241 | -} |
|
| 258 | + else { |
|
| 259 | + return $context['menu_buttons']; |
|
| 260 | + } |
|
| 261 | + } |
|
| 242 | 262 | |
| 243 | 263 | /** |
| 244 | 264 | * Show a logout link. |
@@ -250,20 +270,23 @@ discard block |
||
| 250 | 270 | { |
| 251 | 271 | global $context, $txt, $scripturl; |
| 252 | 272 | |
| 253 | - if ($redirect_to != '') |
|
| 254 | - $_SESSION['logout_url'] = $redirect_to; |
|
| 273 | + if ($redirect_to != '') { |
|
| 274 | + $_SESSION['logout_url'] = $redirect_to; |
|
| 275 | + } |
|
| 255 | 276 | |
| 256 | 277 | // Guests can't log out. |
| 257 | - if ($context['user']['is_guest']) |
|
| 258 | - return false; |
|
| 278 | + if ($context['user']['is_guest']) { |
|
| 279 | + return false; |
|
| 280 | + } |
|
| 259 | 281 | |
| 260 | 282 | $link = '<a href="' . $scripturl . '?action=logout;' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['logout'] . '</a>'; |
| 261 | 283 | |
| 262 | - if ($output_method == 'echo') |
|
| 263 | - echo $link; |
|
| 264 | - else |
|
| 265 | - return $link; |
|
| 266 | -} |
|
| 284 | + if ($output_method == 'echo') { |
|
| 285 | + echo $link; |
|
| 286 | + } else { |
|
| 287 | + return $link; |
|
| 288 | + } |
|
| 289 | + } |
|
| 267 | 290 | |
| 268 | 291 | /** |
| 269 | 292 | * Recent post list: [board] Subject by Poster Date |
@@ -279,17 +302,17 @@ discard block |
||
| 279 | 302 | global $modSettings, $context; |
| 280 | 303 | |
| 281 | 304 | // Excluding certain boards... |
| 282 | - if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) |
|
| 283 | - $exclude_boards = array($modSettings['recycle_board']); |
|
| 284 | - else |
|
| 285 | - $exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards)); |
|
| 305 | + if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) { |
|
| 306 | + $exclude_boards = array($modSettings['recycle_board']); |
|
| 307 | + } else { |
|
| 308 | + $exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards)); |
|
| 309 | + } |
|
| 286 | 310 | |
| 287 | 311 | // What about including certain boards - note we do some protection here as pre-2.0 didn't have this parameter. |
| 288 | 312 | if (is_array($include_boards) || (int) $include_boards === $include_boards) |
| 289 | 313 | { |
| 290 | 314 | $include_boards = is_array($include_boards) ? $include_boards : array($include_boards); |
| 291 | - } |
|
| 292 | - elseif ($include_boards != null) |
|
| 315 | + } elseif ($include_boards != null) |
|
| 293 | 316 | { |
| 294 | 317 | $include_boards = array(); |
| 295 | 318 | } |
@@ -326,8 +349,9 @@ discard block |
||
| 326 | 349 | { |
| 327 | 350 | global $modSettings; |
| 328 | 351 | |
| 329 | - if (empty($post_ids)) |
|
| 330 | - return; |
|
| 352 | + if (empty($post_ids)) { |
|
| 353 | + return; |
|
| 354 | + } |
|
| 331 | 355 | |
| 332 | 356 | // Allow the user to request more than one - why not? |
| 333 | 357 | $post_ids = is_array($post_ids) ? $post_ids : array($post_ids); |
@@ -362,8 +386,9 @@ discard block |
||
| 362 | 386 | global $scripturl, $txt, $user_info; |
| 363 | 387 | global $modSettings, $smcFunc, $context; |
| 364 | 388 | |
| 365 | - if (!empty($modSettings['enable_likes'])) |
|
| 366 | - $context['can_like'] = allowedTo('likes_like'); |
|
| 389 | + if (!empty($modSettings['enable_likes'])) { |
|
| 390 | + $context['can_like'] = allowedTo('likes_like'); |
|
| 391 | + } |
|
| 367 | 392 | |
| 368 | 393 | // Find all the posts. Newer ones will have higher IDs. |
| 369 | 394 | $request = $smcFunc['db_query']('substring', ' |
@@ -429,12 +454,13 @@ discard block |
||
| 429 | 454 | ); |
| 430 | 455 | |
| 431 | 456 | // Get the likes for each message. |
| 432 | - if (!empty($modSettings['enable_likes'])) |
|
| 433 | - $posts[$row['id_msg']]['likes'] = array( |
|
| 457 | + if (!empty($modSettings['enable_likes'])) { |
|
| 458 | + $posts[$row['id_msg']]['likes'] = array( |
|
| 434 | 459 | 'count' => $row['likes'], |
| 435 | 460 | 'you' => in_array($row['id_msg'], prepareLikesContext($row['id_topic'])), |
| 436 | 461 | 'can_like' => !$context['user']['is_guest'] && $row['id_member'] != $context['user']['id'] && !empty($context['can_like']), |
| 437 | 462 | ); |
| 463 | + } |
|
| 438 | 464 | } |
| 439 | 465 | $smcFunc['db_free_result']($request); |
| 440 | 466 | |
@@ -442,13 +468,14 @@ discard block |
||
| 442 | 468 | call_integration_hook('integrate_ssi_queryPosts', array(&$posts)); |
| 443 | 469 | |
| 444 | 470 | // Just return it. |
| 445 | - if ($output_method != 'echo' || empty($posts)) |
|
| 446 | - return $posts; |
|
| 471 | + if ($output_method != 'echo' || empty($posts)) { |
|
| 472 | + return $posts; |
|
| 473 | + } |
|
| 447 | 474 | |
| 448 | 475 | echo ' |
| 449 | 476 | <table style="border: none" class="ssi_table">'; |
| 450 | - foreach ($posts as $post) |
|
| 451 | - echo ' |
|
| 477 | + foreach ($posts as $post) { |
|
| 478 | + echo ' |
|
| 452 | 479 | <tr> |
| 453 | 480 | <td style="text-align: right; vertical-align: top; white-space: nowrap"> |
| 454 | 481 | [', $post['board']['link'], '] |
@@ -462,6 +489,7 @@ discard block |
||
| 462 | 489 | ', $post['time'], ' |
| 463 | 490 | </td> |
| 464 | 491 | </tr>'; |
| 492 | + } |
|
| 465 | 493 | echo ' |
| 466 | 494 | </table>'; |
| 467 | 495 | } |
@@ -479,25 +507,26 @@ discard block |
||
| 479 | 507 | global $settings, $scripturl, $txt, $user_info; |
| 480 | 508 | global $modSettings, $smcFunc, $context; |
| 481 | 509 | |
| 482 | - if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) |
|
| 483 | - $exclude_boards = array($modSettings['recycle_board']); |
|
| 484 | - else |
|
| 485 | - $exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards)); |
|
| 510 | + if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) { |
|
| 511 | + $exclude_boards = array($modSettings['recycle_board']); |
|
| 512 | + } else { |
|
| 513 | + $exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards)); |
|
| 514 | + } |
|
| 486 | 515 | |
| 487 | 516 | // Only some boards?. |
| 488 | 517 | if (is_array($include_boards) || (int) $include_boards === $include_boards) |
| 489 | 518 | { |
| 490 | 519 | $include_boards = is_array($include_boards) ? $include_boards : array($include_boards); |
| 491 | - } |
|
| 492 | - elseif ($include_boards != null) |
|
| 520 | + } elseif ($include_boards != null) |
|
| 493 | 521 | { |
| 494 | 522 | $output_method = $include_boards; |
| 495 | 523 | $include_boards = array(); |
| 496 | 524 | } |
| 497 | 525 | |
| 498 | 526 | $icon_sources = array(); |
| 499 | - foreach ($context['stable_icons'] as $icon) |
|
| 500 | - $icon_sources[$icon] = 'images_url'; |
|
| 527 | + foreach ($context['stable_icons'] as $icon) { |
|
| 528 | + $icon_sources[$icon] = 'images_url'; |
|
| 529 | + } |
|
| 501 | 530 | |
| 502 | 531 | // Find all the posts in distinct topics. Newer ones will have higher IDs. |
| 503 | 532 | $request = $smcFunc['db_query']('substring', ' |
@@ -522,13 +551,15 @@ discard block |
||
| 522 | 551 | ) |
| 523 | 552 | ); |
| 524 | 553 | $topics = array(); |
| 525 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 526 | - $topics[$row['id_topic']] = $row; |
|
| 554 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 555 | + $topics[$row['id_topic']] = $row; |
|
| 556 | + } |
|
| 527 | 557 | $smcFunc['db_free_result']($request); |
| 528 | 558 | |
| 529 | 559 | // Did we find anything? If not, bail. |
| 530 | - if (empty($topics)) |
|
| 531 | - return array(); |
|
| 560 | + if (empty($topics)) { |
|
| 561 | + return array(); |
|
| 562 | + } |
|
| 532 | 563 | |
| 533 | 564 | $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
| 534 | 565 | |
@@ -556,19 +587,22 @@ discard block |
||
| 556 | 587 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 557 | 588 | { |
| 558 | 589 | $row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br>' => ' '))); |
| 559 | - if ($smcFunc['strlen']($row['body']) > 128) |
|
| 560 | - $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...'; |
|
| 590 | + if ($smcFunc['strlen']($row['body']) > 128) { |
|
| 591 | + $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...'; |
|
| 592 | + } |
|
| 561 | 593 | |
| 562 | 594 | // Censor the subject. |
| 563 | 595 | censorText($row['subject']); |
| 564 | 596 | censorText($row['body']); |
| 565 | 597 | |
| 566 | 598 | // Recycled icon |
| 567 | - if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board']) |
|
| 568 | - $row['icon'] = 'recycled'; |
|
| 599 | + if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board']) { |
|
| 600 | + $row['icon'] = 'recycled'; |
|
| 601 | + } |
|
| 569 | 602 | |
| 570 | - if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) |
|
| 571 | - $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 603 | + if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) { |
|
| 604 | + $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 605 | + } |
|
| 572 | 606 | |
| 573 | 607 | // Build the array. |
| 574 | 608 | $posts[] = array( |
@@ -607,13 +641,14 @@ discard block |
||
| 607 | 641 | call_integration_hook('integrate_ssi_recentTopics', array(&$posts)); |
| 608 | 642 | |
| 609 | 643 | // Just return it. |
| 610 | - if ($output_method != 'echo' || empty($posts)) |
|
| 611 | - return $posts; |
|
| 644 | + if ($output_method != 'echo' || empty($posts)) { |
|
| 645 | + return $posts; |
|
| 646 | + } |
|
| 612 | 647 | |
| 613 | 648 | echo ' |
| 614 | 649 | <table style="border: none" class="ssi_table">'; |
| 615 | - foreach ($posts as $post) |
|
| 616 | - echo ' |
|
| 650 | + foreach ($posts as $post) { |
|
| 651 | + echo ' |
|
| 617 | 652 | <tr> |
| 618 | 653 | <td style="text-align: right; vertical-align: top; white-space: nowrap"> |
| 619 | 654 | [', $post['board']['link'], '] |
@@ -627,6 +662,7 @@ discard block |
||
| 627 | 662 | ', $post['time'], ' |
| 628 | 663 | </td> |
| 629 | 664 | </tr>'; |
| 665 | + } |
|
| 630 | 666 | echo ' |
| 631 | 667 | </table>'; |
| 632 | 668 | } |
@@ -651,27 +687,30 @@ discard block |
||
| 651 | 687 | ) |
| 652 | 688 | ); |
| 653 | 689 | $return = array(); |
| 654 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 655 | - $return[] = array( |
|
| 690 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 691 | + $return[] = array( |
|
| 656 | 692 | 'id' => $row['id_member'], |
| 657 | 693 | 'name' => $row['real_name'], |
| 658 | 694 | 'href' => $scripturl . '?action=profile;u=' . $row['id_member'], |
| 659 | 695 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>', |
| 660 | 696 | 'posts' => $row['posts'] |
| 661 | 697 | ); |
| 698 | + } |
|
| 662 | 699 | $smcFunc['db_free_result']($request); |
| 663 | 700 | |
| 664 | 701 | // If mods want to do somthing with this list of members, let them do that now. |
| 665 | 702 | call_integration_hook('integrate_ssi_topPoster', array(&$return)); |
| 666 | 703 | |
| 667 | 704 | // Just return all the top posters. |
| 668 | - if ($output_method != 'echo') |
|
| 669 | - return $return; |
|
| 705 | + if ($output_method != 'echo') { |
|
| 706 | + return $return; |
|
| 707 | + } |
|
| 670 | 708 | |
| 671 | 709 | // Make a quick array to list the links in. |
| 672 | 710 | $temp_array = array(); |
| 673 | - foreach ($return as $member) |
|
| 674 | - $temp_array[] = $member['link']; |
|
| 711 | + foreach ($return as $member) { |
|
| 712 | + $temp_array[] = $member['link']; |
|
| 713 | + } |
|
| 675 | 714 | |
| 676 | 715 | echo implode(', ', $temp_array); |
| 677 | 716 | } |
@@ -703,8 +742,8 @@ discard block |
||
| 703 | 742 | ) |
| 704 | 743 | ); |
| 705 | 744 | $boards = array(); |
| 706 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 707 | - $boards[] = array( |
|
| 745 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 746 | + $boards[] = array( |
|
| 708 | 747 | 'id' => $row['id_board'], |
| 709 | 748 | 'num_posts' => $row['num_posts'], |
| 710 | 749 | 'num_topics' => $row['num_topics'], |
@@ -713,14 +752,16 @@ discard block |
||
| 713 | 752 | 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', |
| 714 | 753 | 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>' |
| 715 | 754 | ); |
| 755 | + } |
|
| 716 | 756 | $smcFunc['db_free_result']($request); |
| 717 | 757 | |
| 718 | 758 | // If mods want to do somthing with this list of boards, let them do that now. |
| 719 | 759 | call_integration_hook('integrate_ssi_topBoards', array(&$boards)); |
| 720 | 760 | |
| 721 | 761 | // If we shouldn't output or have nothing to output, just jump out. |
| 722 | - if ($output_method != 'echo' || empty($boards)) |
|
| 723 | - return $boards; |
|
| 762 | + if ($output_method != 'echo' || empty($boards)) { |
|
| 763 | + return $boards; |
|
| 764 | + } |
|
| 724 | 765 | |
| 725 | 766 | echo ' |
| 726 | 767 | <table class="ssi_table"> |
@@ -729,13 +770,14 @@ discard block |
||
| 729 | 770 | <th style="text-align: left">', $txt['board_topics'], '</th> |
| 730 | 771 | <th style="text-align: left">', $txt['posts'], '</th> |
| 731 | 772 | </tr>'; |
| 732 | - foreach ($boards as $sBoard) |
|
| 733 | - echo ' |
|
| 773 | + foreach ($boards as $sBoard) { |
|
| 774 | + echo ' |
|
| 734 | 775 | <tr> |
| 735 | 776 | <td>', $sBoard['link'], $sBoard['new'] ? ' <a href="' . $sBoard['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>' : '', '</td> |
| 736 | 777 | <td style="text-align: right">', comma_format($sBoard['num_topics']), '</td> |
| 737 | 778 | <td style="text-align: right">', comma_format($sBoard['num_posts']), '</td> |
| 738 | 779 | </tr>'; |
| 780 | + } |
|
| 739 | 781 | echo ' |
| 740 | 782 | </table>'; |
| 741 | 783 | } |
@@ -768,12 +810,13 @@ discard block |
||
| 768 | 810 | ) |
| 769 | 811 | ); |
| 770 | 812 | $topic_ids = array(); |
| 771 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 772 | - $topic_ids[] = $row['id_topic']; |
|
| 813 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 814 | + $topic_ids[] = $row['id_topic']; |
|
| 815 | + } |
|
| 773 | 816 | $smcFunc['db_free_result']($request); |
| 817 | + } else { |
|
| 818 | + $topic_ids = array(); |
|
| 774 | 819 | } |
| 775 | - else |
|
| 776 | - $topic_ids = array(); |
|
| 777 | 820 | |
| 778 | 821 | $request = $smcFunc['db_query']('', ' |
| 779 | 822 | SELECT m.subject, m.id_topic, t.num_views, t.num_replies |
@@ -812,8 +855,9 @@ discard block |
||
| 812 | 855 | // If mods want to do somthing with this list of topics, let them do that now. |
| 813 | 856 | call_integration_hook('integrate_ssi_topTopics', array(&$topics, $type)); |
| 814 | 857 | |
| 815 | - if ($output_method != 'echo' || empty($topics)) |
|
| 816 | - return $topics; |
|
| 858 | + if ($output_method != 'echo' || empty($topics)) { |
|
| 859 | + return $topics; |
|
| 860 | + } |
|
| 817 | 861 | |
| 818 | 862 | echo ' |
| 819 | 863 | <table class="ssi_table"> |
@@ -822,8 +866,8 @@ discard block |
||
| 822 | 866 | <th style="text-align: left">', $txt['views'], '</th> |
| 823 | 867 | <th style="text-align: left">', $txt['replies'], '</th> |
| 824 | 868 | </tr>'; |
| 825 | - foreach ($topics as $sTopic) |
|
| 826 | - echo ' |
|
| 869 | + foreach ($topics as $sTopic) { |
|
| 870 | + echo ' |
|
| 827 | 871 | <tr> |
| 828 | 872 | <td style="text-align: left"> |
| 829 | 873 | ', $sTopic['link'], ' |
@@ -831,6 +875,7 @@ discard block |
||
| 831 | 875 | <td style="text-align: right">', comma_format($sTopic['num_views']), '</td> |
| 832 | 876 | <td style="text-align: right">', comma_format($sTopic['num_replies']), '</td> |
| 833 | 877 | </tr>'; |
| 878 | + } |
|
| 834 | 879 | echo ' |
| 835 | 880 | </table>'; |
| 836 | 881 | } |
@@ -866,12 +911,13 @@ discard block |
||
| 866 | 911 | { |
| 867 | 912 | global $txt, $context; |
| 868 | 913 | |
| 869 | - if ($output_method == 'echo') |
|
| 870 | - echo ' |
|
| 914 | + if ($output_method == 'echo') { |
|
| 915 | + echo ' |
|
| 871 | 916 | ', sprintf($txt['welcome_newest_member'], $context['common_stats']['latest_member']['link']), '<br>'; |
| 872 | - else |
|
| 873 | - return $context['common_stats']['latest_member']; |
|
| 874 | -} |
|
| 917 | + } else { |
|
| 918 | + return $context['common_stats']['latest_member']; |
|
| 919 | + } |
|
| 920 | + } |
|
| 875 | 921 | |
| 876 | 922 | /** |
| 877 | 923 | * Fetches a random member. |
@@ -920,8 +966,9 @@ discard block |
||
| 920 | 966 | } |
| 921 | 967 | |
| 922 | 968 | // Just to be sure put the random generator back to something... random. |
| 923 | - if ($random_type != '') |
|
| 924 | - mt_srand(time()); |
|
| 969 | + if ($random_type != '') { |
|
| 970 | + mt_srand(time()); |
|
| 971 | + } |
|
| 925 | 972 | |
| 926 | 973 | return $result; |
| 927 | 974 | } |
@@ -934,8 +981,9 @@ discard block |
||
| 934 | 981 | */ |
| 935 | 982 | function ssi_fetchMember($member_ids = array(), $output_method = 'echo') |
| 936 | 983 | { |
| 937 | - if (empty($member_ids)) |
|
| 938 | - return; |
|
| 984 | + if (empty($member_ids)) { |
|
| 985 | + return; |
|
| 986 | + } |
|
| 939 | 987 | |
| 940 | 988 | // Can have more than one member if you really want... |
| 941 | 989 | $member_ids = is_array($member_ids) ? $member_ids : array($member_ids); |
@@ -960,8 +1008,9 @@ discard block |
||
| 960 | 1008 | */ |
| 961 | 1009 | function ssi_fetchGroupMembers($group_id = null, $output_method = 'echo') |
| 962 | 1010 | { |
| 963 | - if ($group_id === null) |
|
| 964 | - return; |
|
| 1011 | + if ($group_id === null) { |
|
| 1012 | + return; |
|
| 1013 | + } |
|
| 965 | 1014 | |
| 966 | 1015 | $query_where = ' |
| 967 | 1016 | id_group = {int:id_group} |
@@ -988,8 +1037,9 @@ discard block |
||
| 988 | 1037 | { |
| 989 | 1038 | global $smcFunc, $memberContext; |
| 990 | 1039 | |
| 991 | - if ($query_where === null) |
|
| 992 | - return; |
|
| 1040 | + if ($query_where === null) { |
|
| 1041 | + return; |
|
| 1042 | + } |
|
| 993 | 1043 | |
| 994 | 1044 | // Fetch the members in question. |
| 995 | 1045 | $request = $smcFunc['db_query']('', ' |
@@ -1002,12 +1052,14 @@ discard block |
||
| 1002 | 1052 | )) |
| 1003 | 1053 | ); |
| 1004 | 1054 | $members = array(); |
| 1005 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1006 | - $members[] = $row['id_member']; |
|
| 1055 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1056 | + $members[] = $row['id_member']; |
|
| 1057 | + } |
|
| 1007 | 1058 | $smcFunc['db_free_result']($request); |
| 1008 | 1059 | |
| 1009 | - if (empty($members)) |
|
| 1010 | - return array(); |
|
| 1060 | + if (empty($members)) { |
|
| 1061 | + return array(); |
|
| 1062 | + } |
|
| 1011 | 1063 | |
| 1012 | 1064 | // If mods want to do somthing with this list of members, let them do that now. |
| 1013 | 1065 | call_integration_hook('integrate_ssi_queryMembers', array(&$members)); |
@@ -1016,23 +1068,25 @@ discard block |
||
| 1016 | 1068 | loadMemberData($members); |
| 1017 | 1069 | |
| 1018 | 1070 | // Draw the table! |
| 1019 | - if ($output_method == 'echo') |
|
| 1020 | - echo ' |
|
| 1071 | + if ($output_method == 'echo') { |
|
| 1072 | + echo ' |
|
| 1021 | 1073 | <table style="border: none" class="ssi_table">'; |
| 1074 | + } |
|
| 1022 | 1075 | |
| 1023 | 1076 | $query_members = array(); |
| 1024 | 1077 | foreach ($members as $member) |
| 1025 | 1078 | { |
| 1026 | 1079 | // Load their context data. |
| 1027 | - if (!loadMemberContext($member)) |
|
| 1028 | - continue; |
|
| 1080 | + if (!loadMemberContext($member)) { |
|
| 1081 | + continue; |
|
| 1082 | + } |
|
| 1029 | 1083 | |
| 1030 | 1084 | // Store this member's information. |
| 1031 | 1085 | $query_members[$member] = $memberContext[$member]; |
| 1032 | 1086 | |
| 1033 | 1087 | // Only do something if we're echo'ing. |
| 1034 | - if ($output_method == 'echo') |
|
| 1035 | - echo ' |
|
| 1088 | + if ($output_method == 'echo') { |
|
| 1089 | + echo ' |
|
| 1036 | 1090 | <tr> |
| 1037 | 1091 | <td style="text-align: right; vertical-align: top; white-space: nowrap"> |
| 1038 | 1092 | ', $query_members[$member]['link'], ' |
@@ -1040,12 +1094,14 @@ discard block |
||
| 1040 | 1094 | <br>', $query_members[$member]['avatar']['image'], ' |
| 1041 | 1095 | </td> |
| 1042 | 1096 | </tr>'; |
| 1097 | + } |
|
| 1043 | 1098 | } |
| 1044 | 1099 | |
| 1045 | 1100 | // End the table if appropriate. |
| 1046 | - if ($output_method == 'echo') |
|
| 1047 | - echo ' |
|
| 1101 | + if ($output_method == 'echo') { |
|
| 1102 | + echo ' |
|
| 1048 | 1103 | </table>'; |
| 1104 | + } |
|
| 1049 | 1105 | |
| 1050 | 1106 | // Send back the data. |
| 1051 | 1107 | return $query_members; |
@@ -1060,8 +1116,9 @@ discard block |
||
| 1060 | 1116 | { |
| 1061 | 1117 | global $txt, $scripturl, $modSettings, $smcFunc; |
| 1062 | 1118 | |
| 1063 | - if (!allowedTo('view_stats')) |
|
| 1064 | - return; |
|
| 1119 | + if (!allowedTo('view_stats')) { |
|
| 1120 | + return; |
|
| 1121 | + } |
|
| 1065 | 1122 | |
| 1066 | 1123 | $totals = array( |
| 1067 | 1124 | 'members' => $modSettings['totalMembers'], |
@@ -1090,8 +1147,9 @@ discard block |
||
| 1090 | 1147 | // If mods want to do somthing with the board stats, let them do that now. |
| 1091 | 1148 | call_integration_hook('integrate_ssi_boardStats', array(&$totals)); |
| 1092 | 1149 | |
| 1093 | - if ($output_method != 'echo') |
|
| 1094 | - return $totals; |
|
| 1150 | + if ($output_method != 'echo') { |
|
| 1151 | + return $totals; |
|
| 1152 | + } |
|
| 1095 | 1153 | |
| 1096 | 1154 | echo ' |
| 1097 | 1155 | ', $txt['total_members'], ': <a href="', $scripturl . '?action=mlist">', comma_format($totals['members']), '</a><br> |
@@ -1120,8 +1178,8 @@ discard block |
||
| 1120 | 1178 | call_integration_hook('integrate_ssi_whosOnline', array(&$return)); |
| 1121 | 1179 | |
| 1122 | 1180 | // Add some redundancy for backwards compatibility reasons. |
| 1123 | - if ($output_method != 'echo') |
|
| 1124 | - return $return + array( |
|
| 1181 | + if ($output_method != 'echo') { |
|
| 1182 | + return $return + array( |
|
| 1125 | 1183 | 'users' => $return['users_online'], |
| 1126 | 1184 | 'guests' => $return['num_guests'], |
| 1127 | 1185 | 'hidden' => $return['num_users_hidden'], |
@@ -1129,29 +1187,35 @@ discard block |
||
| 1129 | 1187 | 'num_users' => $return['num_users_online'], |
| 1130 | 1188 | 'total_users' => $return['num_users_online'] + $return['num_guests'], |
| 1131 | 1189 | ); |
| 1190 | + } |
|
| 1132 | 1191 | |
| 1133 | 1192 | echo ' |
| 1134 | 1193 | ', comma_format($return['num_guests']), ' ', $return['num_guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ', comma_format($return['num_users_online']), ' ', $return['num_users_online'] == 1 ? $txt['user'] : $txt['users']; |
| 1135 | 1194 | |
| 1136 | 1195 | $bracketList = array(); |
| 1137 | - if (!empty($user_info['buddies'])) |
|
| 1138 | - $bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']); |
|
| 1139 | - if (!empty($return['num_spiders'])) |
|
| 1140 | - $bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']); |
|
| 1141 | - if (!empty($return['num_users_hidden'])) |
|
| 1142 | - $bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden']; |
|
| 1196 | + if (!empty($user_info['buddies'])) { |
|
| 1197 | + $bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']); |
|
| 1198 | + } |
|
| 1199 | + if (!empty($return['num_spiders'])) { |
|
| 1200 | + $bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']); |
|
| 1201 | + } |
|
| 1202 | + if (!empty($return['num_users_hidden'])) { |
|
| 1203 | + $bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden']; |
|
| 1204 | + } |
|
| 1143 | 1205 | |
| 1144 | - if (!empty($bracketList)) |
|
| 1145 | - echo ' (' . implode(', ', $bracketList) . ')'; |
|
| 1206 | + if (!empty($bracketList)) { |
|
| 1207 | + echo ' (' . implode(', ', $bracketList) . ')'; |
|
| 1208 | + } |
|
| 1146 | 1209 | |
| 1147 | 1210 | echo '<br> |
| 1148 | 1211 | ', implode(', ', $return['list_users_online']); |
| 1149 | 1212 | |
| 1150 | 1213 | // Showing membergroups? |
| 1151 | - if (!empty($settings['show_group_key']) && !empty($return['membergroups'])) |
|
| 1152 | - echo '<br> |
|
| 1214 | + if (!empty($settings['show_group_key']) && !empty($return['membergroups'])) { |
|
| 1215 | + echo '<br> |
|
| 1153 | 1216 | [' . implode('] [', $return['membergroups']) . ']'; |
| 1154 | -} |
|
| 1217 | + } |
|
| 1218 | + } |
|
| 1155 | 1219 | |
| 1156 | 1220 | /** |
| 1157 | 1221 | * Just like whosOnline except it also logs the online presence. |
@@ -1162,11 +1226,12 @@ discard block |
||
| 1162 | 1226 | { |
| 1163 | 1227 | writeLog(); |
| 1164 | 1228 | |
| 1165 | - if ($output_method != 'echo') |
|
| 1166 | - return ssi_whosOnline($output_method); |
|
| 1167 | - else |
|
| 1168 | - ssi_whosOnline($output_method); |
|
| 1169 | -} |
|
| 1229 | + if ($output_method != 'echo') { |
|
| 1230 | + return ssi_whosOnline($output_method); |
|
| 1231 | + } else { |
|
| 1232 | + ssi_whosOnline($output_method); |
|
| 1233 | + } |
|
| 1234 | + } |
|
| 1170 | 1235 | |
| 1171 | 1236 | // Shows a login box. |
| 1172 | 1237 | /** |
@@ -1179,11 +1244,13 @@ discard block |
||
| 1179 | 1244 | { |
| 1180 | 1245 | global $scripturl, $txt, $user_info, $context; |
| 1181 | 1246 | |
| 1182 | - if ($redirect_to != '') |
|
| 1183 | - $_SESSION['login_url'] = $redirect_to; |
|
| 1247 | + if ($redirect_to != '') { |
|
| 1248 | + $_SESSION['login_url'] = $redirect_to; |
|
| 1249 | + } |
|
| 1184 | 1250 | |
| 1185 | - if ($output_method != 'echo' || !$user_info['is_guest']) |
|
| 1186 | - return $user_info['is_guest']; |
|
| 1251 | + if ($output_method != 'echo' || !$user_info['is_guest']) { |
|
| 1252 | + return $user_info['is_guest']; |
|
| 1253 | + } |
|
| 1187 | 1254 | |
| 1188 | 1255 | // Create a login token |
| 1189 | 1256 | createToken('login'); |
@@ -1235,8 +1302,9 @@ discard block |
||
| 1235 | 1302 | |
| 1236 | 1303 | $boardsAllowed = array_intersect(boardsAllowedTo('poll_view'), boardsAllowedTo('poll_vote')); |
| 1237 | 1304 | |
| 1238 | - if (empty($boardsAllowed)) |
|
| 1239 | - return array(); |
|
| 1305 | + if (empty($boardsAllowed)) { |
|
| 1306 | + return array(); |
|
| 1307 | + } |
|
| 1240 | 1308 | |
| 1241 | 1309 | $request = $smcFunc['db_query']('', ' |
| 1242 | 1310 | SELECT p.id_poll, p.question, t.id_topic, p.max_votes, p.guest_vote, p.hide_results, p.expire_time |
@@ -1269,12 +1337,14 @@ discard block |
||
| 1269 | 1337 | $smcFunc['db_free_result']($request); |
| 1270 | 1338 | |
| 1271 | 1339 | // This user has voted on all the polls. |
| 1272 | - if (empty($row) || !is_array($row)) |
|
| 1273 | - return array(); |
|
| 1340 | + if (empty($row) || !is_array($row)) { |
|
| 1341 | + return array(); |
|
| 1342 | + } |
|
| 1274 | 1343 | |
| 1275 | 1344 | // If this is a guest who's voted we'll through ourselves to show poll to show the results. |
| 1276 | - if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))))) |
|
| 1277 | - return ssi_showPoll($row['id_topic'], $output_method); |
|
| 1345 | + if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))))) { |
|
| 1346 | + return ssi_showPoll($row['id_topic'], $output_method); |
|
| 1347 | + } |
|
| 1278 | 1348 | |
| 1279 | 1349 | $request = $smcFunc['db_query']('', ' |
| 1280 | 1350 | SELECT COUNT(DISTINCT id_member) |
@@ -1338,8 +1408,9 @@ discard block |
||
| 1338 | 1408 | // If mods want to do somthing with this list of polls, let them do that now. |
| 1339 | 1409 | call_integration_hook('integrate_ssi_recentPoll', array(&$return, $topPollInstead)); |
| 1340 | 1410 | |
| 1341 | - if ($output_method != 'echo') |
|
| 1342 | - return $return; |
|
| 1411 | + if ($output_method != 'echo') { |
|
| 1412 | + return $return; |
|
| 1413 | + } |
|
| 1343 | 1414 | |
| 1344 | 1415 | if ($allow_view_results) |
| 1345 | 1416 | { |
@@ -1348,19 +1419,20 @@ discard block |
||
| 1348 | 1419 | <strong>', $return['question'], '</strong><br> |
| 1349 | 1420 | ', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br>' : ''; |
| 1350 | 1421 | |
| 1351 | - foreach ($return['options'] as $option) |
|
| 1352 | - echo ' |
|
| 1422 | + foreach ($return['options'] as $option) { |
|
| 1423 | + echo ' |
|
| 1353 | 1424 | <label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br>'; |
| 1425 | + } |
|
| 1354 | 1426 | |
| 1355 | 1427 | echo ' |
| 1356 | 1428 | <input type="submit" value="', $txt['poll_vote'], '" class="button_submit"> |
| 1357 | 1429 | <input type="hidden" name="poll" value="', $return['id'], '"> |
| 1358 | 1430 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
| 1359 | 1431 | </form>'; |
| 1432 | + } else { |
|
| 1433 | + echo $txt['poll_cannot_see']; |
|
| 1434 | + } |
|
| 1360 | 1435 | } |
| 1361 | - else |
|
| 1362 | - echo $txt['poll_cannot_see']; |
|
| 1363 | -} |
|
| 1364 | 1436 | |
| 1365 | 1437 | /** |
| 1366 | 1438 | * Shows the poll from the specified topic |
@@ -1374,13 +1446,15 @@ discard block |
||
| 1374 | 1446 | |
| 1375 | 1447 | $boardsAllowed = boardsAllowedTo('poll_view'); |
| 1376 | 1448 | |
| 1377 | - if (empty($boardsAllowed)) |
|
| 1378 | - return array(); |
|
| 1449 | + if (empty($boardsAllowed)) { |
|
| 1450 | + return array(); |
|
| 1451 | + } |
|
| 1379 | 1452 | |
| 1380 | - if ($topic === null && isset($_REQUEST['ssi_topic'])) |
|
| 1381 | - $topic = (int) $_REQUEST['ssi_topic']; |
|
| 1382 | - else |
|
| 1383 | - $topic = (int) $topic; |
|
| 1453 | + if ($topic === null && isset($_REQUEST['ssi_topic'])) { |
|
| 1454 | + $topic = (int) $_REQUEST['ssi_topic']; |
|
| 1455 | + } else { |
|
| 1456 | + $topic = (int) $topic; |
|
| 1457 | + } |
|
| 1384 | 1458 | |
| 1385 | 1459 | $request = $smcFunc['db_query']('', ' |
| 1386 | 1460 | SELECT |
@@ -1401,17 +1475,18 @@ discard block |
||
| 1401 | 1475 | ); |
| 1402 | 1476 | |
| 1403 | 1477 | // Either this topic has no poll, or the user cannot view it. |
| 1404 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1405 | - return array(); |
|
| 1478 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1479 | + return array(); |
|
| 1480 | + } |
|
| 1406 | 1481 | |
| 1407 | 1482 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1408 | 1483 | $smcFunc['db_free_result']($request); |
| 1409 | 1484 | |
| 1410 | 1485 | // Check if they can vote. |
| 1411 | 1486 | $already_voted = false; |
| 1412 | - if (!empty($row['expire_time']) && $row['expire_time'] < time()) |
|
| 1413 | - $allow_vote = false; |
|
| 1414 | - elseif ($user_info['is_guest']) |
|
| 1487 | + if (!empty($row['expire_time']) && $row['expire_time'] < time()) { |
|
| 1488 | + $allow_vote = false; |
|
| 1489 | + } elseif ($user_info['is_guest']) |
|
| 1415 | 1490 | { |
| 1416 | 1491 | // There's a difference between "allowed to vote" and "already voted"... |
| 1417 | 1492 | $allow_vote = $row['guest_vote']; |
@@ -1421,10 +1496,9 @@ discard block |
||
| 1421 | 1496 | { |
| 1422 | 1497 | $already_voted = true; |
| 1423 | 1498 | } |
| 1424 | - } |
|
| 1425 | - elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board'])) |
|
| 1426 | - $allow_vote = false; |
|
| 1427 | - else |
|
| 1499 | + } elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board'])) { |
|
| 1500 | + $allow_vote = false; |
|
| 1501 | + } else |
|
| 1428 | 1502 | { |
| 1429 | 1503 | $request = $smcFunc['db_query']('', ' |
| 1430 | 1504 | SELECT id_member |
@@ -1506,8 +1580,9 @@ discard block |
||
| 1506 | 1580 | // If mods want to do somthing with this poll, let them do that now. |
| 1507 | 1581 | call_integration_hook('integrate_ssi_showPoll', array(&$return)); |
| 1508 | 1582 | |
| 1509 | - if ($output_method != 'echo') |
|
| 1510 | - return $return; |
|
| 1583 | + if ($output_method != 'echo') { |
|
| 1584 | + return $return; |
|
| 1585 | + } |
|
| 1511 | 1586 | |
| 1512 | 1587 | if ($return['allow_vote']) |
| 1513 | 1588 | { |
@@ -1516,17 +1591,17 @@ discard block |
||
| 1516 | 1591 | <strong>', $return['question'], '</strong><br> |
| 1517 | 1592 | ', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br>' : ''; |
| 1518 | 1593 | |
| 1519 | - foreach ($return['options'] as $option) |
|
| 1520 | - echo ' |
|
| 1594 | + foreach ($return['options'] as $option) { |
|
| 1595 | + echo ' |
|
| 1521 | 1596 | <label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br>'; |
| 1597 | + } |
|
| 1522 | 1598 | |
| 1523 | 1599 | echo ' |
| 1524 | 1600 | <input type="submit" value="', $txt['poll_vote'], '" class="button_submit"> |
| 1525 | 1601 | <input type="hidden" name="poll" value="', $return['id'], '"> |
| 1526 | 1602 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
| 1527 | 1603 | </form>'; |
| 1528 | - } |
|
| 1529 | - else |
|
| 1604 | + } else |
|
| 1530 | 1605 | { |
| 1531 | 1606 | echo ' |
| 1532 | 1607 | <div class="ssi_poll"> |
@@ -1606,27 +1681,32 @@ discard block |
||
| 1606 | 1681 | 'is_approved' => 1, |
| 1607 | 1682 | ) |
| 1608 | 1683 | ); |
| 1609 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1610 | - die; |
|
| 1684 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1685 | + die; |
|
| 1686 | + } |
|
| 1611 | 1687 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1612 | 1688 | $smcFunc['db_free_result']($request); |
| 1613 | 1689 | |
| 1614 | - if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time'])) |
|
| 1615 | - redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1690 | + if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time'])) { |
|
| 1691 | + redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1692 | + } |
|
| 1616 | 1693 | |
| 1617 | 1694 | // Too many options checked? |
| 1618 | - if (count($_REQUEST['options']) > $row['max_votes']) |
|
| 1619 | - redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1695 | + if (count($_REQUEST['options']) > $row['max_votes']) { |
|
| 1696 | + redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1697 | + } |
|
| 1620 | 1698 | |
| 1621 | 1699 | // It's a guest who has already voted? |
| 1622 | 1700 | if ($user_info['is_guest']) |
| 1623 | 1701 | { |
| 1624 | 1702 | // Guest voting disabled? |
| 1625 | - if (!$row['guest_vote']) |
|
| 1626 | - redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1703 | + if (!$row['guest_vote']) { |
|
| 1704 | + redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1705 | + } |
|
| 1627 | 1706 | // Already voted? |
| 1628 | - elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))) |
|
| 1629 | - redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1707 | + elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))) { |
|
| 1708 | + redirectexit('topic=' . $row['id_topic'] . '.0'); |
|
| 1709 | + } |
|
| 1630 | 1710 | } |
| 1631 | 1711 | |
| 1632 | 1712 | $sOptions = array(); |
@@ -1680,11 +1760,13 @@ discard block |
||
| 1680 | 1760 | { |
| 1681 | 1761 | global $scripturl, $txt, $context; |
| 1682 | 1762 | |
| 1683 | - if (!allowedTo('search_posts')) |
|
| 1684 | - return; |
|
| 1763 | + if (!allowedTo('search_posts')) { |
|
| 1764 | + return; |
|
| 1765 | + } |
|
| 1685 | 1766 | |
| 1686 | - if ($output_method != 'echo') |
|
| 1687 | - return $scripturl . '?action=search'; |
|
| 1767 | + if ($output_method != 'echo') { |
|
| 1768 | + return $scripturl . '?action=search'; |
|
| 1769 | + } |
|
| 1688 | 1770 | |
| 1689 | 1771 | echo ' |
| 1690 | 1772 | <form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '"> |
@@ -1706,8 +1788,9 @@ discard block |
||
| 1706 | 1788 | // If mods want to do somthing with the news, let them do that now. Don't need to pass the news line itself, since it is already in $context. |
| 1707 | 1789 | call_integration_hook('integrate_ssi_news'); |
| 1708 | 1790 | |
| 1709 | - if ($output_method != 'echo') |
|
| 1710 | - return $context['random_news_line']; |
|
| 1791 | + if ($output_method != 'echo') { |
|
| 1792 | + return $context['random_news_line']; |
|
| 1793 | + } |
|
| 1711 | 1794 | |
| 1712 | 1795 | echo $context['random_news_line']; |
| 1713 | 1796 | } |
@@ -1721,8 +1804,9 @@ discard block |
||
| 1721 | 1804 | { |
| 1722 | 1805 | global $scripturl, $modSettings, $user_info; |
| 1723 | 1806 | |
| 1724 | - if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view') || !allowedTo('profile_view')) |
|
| 1725 | - return; |
|
| 1807 | + if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view') || !allowedTo('profile_view')) { |
|
| 1808 | + return; |
|
| 1809 | + } |
|
| 1726 | 1810 | |
| 1727 | 1811 | $eventOptions = array( |
| 1728 | 1812 | 'include_birthdays' => true, |
@@ -1733,13 +1817,15 @@ discard block |
||
| 1733 | 1817 | // The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary |
| 1734 | 1818 | call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions)); |
| 1735 | 1819 | |
| 1736 | - if ($output_method != 'echo') |
|
| 1737 | - return $return['calendar_birthdays']; |
|
| 1820 | + if ($output_method != 'echo') { |
|
| 1821 | + return $return['calendar_birthdays']; |
|
| 1822 | + } |
|
| 1738 | 1823 | |
| 1739 | - foreach ($return['calendar_birthdays'] as $member) |
|
| 1740 | - echo ' |
|
| 1824 | + foreach ($return['calendar_birthdays'] as $member) { |
|
| 1825 | + echo ' |
|
| 1741 | 1826 | <a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">' . $member['name'] . '</span>' . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>' . (!$member['is_last'] ? ', ' : ''); |
| 1742 | -} |
|
| 1827 | + } |
|
| 1828 | + } |
|
| 1743 | 1829 | |
| 1744 | 1830 | /** |
| 1745 | 1831 | * Shows today's holidays. |
@@ -1750,8 +1836,9 @@ discard block |
||
| 1750 | 1836 | { |
| 1751 | 1837 | global $modSettings, $user_info; |
| 1752 | 1838 | |
| 1753 | - if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) |
|
| 1754 | - return; |
|
| 1839 | + if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) { |
|
| 1840 | + return; |
|
| 1841 | + } |
|
| 1755 | 1842 | |
| 1756 | 1843 | $eventOptions = array( |
| 1757 | 1844 | 'include_holidays' => true, |
@@ -1762,8 +1849,9 @@ discard block |
||
| 1762 | 1849 | // The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary |
| 1763 | 1850 | call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions)); |
| 1764 | 1851 | |
| 1765 | - if ($output_method != 'echo') |
|
| 1766 | - return $return['calendar_holidays']; |
|
| 1852 | + if ($output_method != 'echo') { |
|
| 1853 | + return $return['calendar_holidays']; |
|
| 1854 | + } |
|
| 1767 | 1855 | |
| 1768 | 1856 | echo ' |
| 1769 | 1857 | ', implode(', ', $return['calendar_holidays']); |
@@ -1777,8 +1865,9 @@ discard block |
||
| 1777 | 1865 | { |
| 1778 | 1866 | global $modSettings, $user_info; |
| 1779 | 1867 | |
| 1780 | - if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) |
|
| 1781 | - return; |
|
| 1868 | + if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) { |
|
| 1869 | + return; |
|
| 1870 | + } |
|
| 1782 | 1871 | |
| 1783 | 1872 | $eventOptions = array( |
| 1784 | 1873 | 'include_events' => true, |
@@ -1789,14 +1878,16 @@ discard block |
||
| 1789 | 1878 | // The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary |
| 1790 | 1879 | call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions)); |
| 1791 | 1880 | |
| 1792 | - if ($output_method != 'echo') |
|
| 1793 | - return $return['calendar_events']; |
|
| 1881 | + if ($output_method != 'echo') { |
|
| 1882 | + return $return['calendar_events']; |
|
| 1883 | + } |
|
| 1794 | 1884 | |
| 1795 | 1885 | foreach ($return['calendar_events'] as $event) |
| 1796 | 1886 | { |
| 1797 | - if ($event['can_edit']) |
|
| 1798 | - echo ' |
|
| 1887 | + if ($event['can_edit']) { |
|
| 1888 | + echo ' |
|
| 1799 | 1889 | <a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> '; |
| 1890 | + } |
|
| 1800 | 1891 | echo ' |
| 1801 | 1892 | ' . $event['link'] . (!$event['is_last'] ? ', ' : ''); |
| 1802 | 1893 | } |
@@ -1811,8 +1902,9 @@ discard block |
||
| 1811 | 1902 | { |
| 1812 | 1903 | global $modSettings, $txt, $scripturl, $user_info; |
| 1813 | 1904 | |
| 1814 | - if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) |
|
| 1815 | - return; |
|
| 1905 | + if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) { |
|
| 1906 | + return; |
|
| 1907 | + } |
|
| 1816 | 1908 | |
| 1817 | 1909 | $eventOptions = array( |
| 1818 | 1910 | 'include_birthdays' => allowedTo('profile_view'), |
@@ -1825,19 +1917,22 @@ discard block |
||
| 1825 | 1917 | // The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary |
| 1826 | 1918 | call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions)); |
| 1827 | 1919 | |
| 1828 | - if ($output_method != 'echo') |
|
| 1829 | - return $return; |
|
| 1920 | + if ($output_method != 'echo') { |
|
| 1921 | + return $return; |
|
| 1922 | + } |
|
| 1830 | 1923 | |
| 1831 | - if (!empty($return['calendar_holidays'])) |
|
| 1832 | - echo ' |
|
| 1924 | + if (!empty($return['calendar_holidays'])) { |
|
| 1925 | + echo ' |
|
| 1833 | 1926 | <span class="holiday">' . $txt['calendar_prompt'] . ' ' . implode(', ', $return['calendar_holidays']) . '<br></span>'; |
| 1927 | + } |
|
| 1834 | 1928 | if (!empty($return['calendar_birthdays'])) |
| 1835 | 1929 | { |
| 1836 | 1930 | echo ' |
| 1837 | 1931 | <span class="birthday">' . $txt['birthdays_upcoming'] . '</span> '; |
| 1838 | - foreach ($return['calendar_birthdays'] as $member) |
|
| 1839 | - echo ' |
|
| 1932 | + foreach ($return['calendar_birthdays'] as $member) { |
|
| 1933 | + echo ' |
|
| 1840 | 1934 | <a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">', $member['name'], '</span>', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', !$member['is_last'] ? ', ' : ''; |
| 1935 | + } |
|
| 1841 | 1936 | echo ' |
| 1842 | 1937 | <br>'; |
| 1843 | 1938 | } |
@@ -1847,9 +1942,10 @@ discard block |
||
| 1847 | 1942 | <span class="event">' . $txt['events_upcoming'] . '</span> '; |
| 1848 | 1943 | foreach ($return['calendar_events'] as $event) |
| 1849 | 1944 | { |
| 1850 | - if ($event['can_edit']) |
|
| 1851 | - echo ' |
|
| 1945 | + if ($event['can_edit']) { |
|
| 1946 | + echo ' |
|
| 1852 | 1947 | <a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> '; |
| 1948 | + } |
|
| 1853 | 1949 | echo ' |
| 1854 | 1950 | ' . $event['link'] . (!$event['is_last'] ? ', ' : ''); |
| 1855 | 1951 | } |
@@ -1873,25 +1969,29 @@ discard block |
||
| 1873 | 1969 | loadLanguage('Stats'); |
| 1874 | 1970 | |
| 1875 | 1971 | // Must be integers.... |
| 1876 | - if ($limit === null) |
|
| 1877 | - $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5; |
|
| 1878 | - else |
|
| 1879 | - $limit = (int) $limit; |
|
| 1880 | - |
|
| 1881 | - if ($start === null) |
|
| 1882 | - $start = isset($_GET['start']) ? (int) $_GET['start'] : 0; |
|
| 1883 | - else |
|
| 1884 | - $start = (int) $start; |
|
| 1885 | - |
|
| 1886 | - if ($board !== null) |
|
| 1887 | - $board = (int) $board; |
|
| 1888 | - elseif (isset($_GET['board'])) |
|
| 1889 | - $board = (int) $_GET['board']; |
|
| 1890 | - |
|
| 1891 | - if ($length === null) |
|
| 1892 | - $length = isset($_GET['length']) ? (int) $_GET['length'] : 0; |
|
| 1893 | - else |
|
| 1894 | - $length = (int) $length; |
|
| 1972 | + if ($limit === null) { |
|
| 1973 | + $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5; |
|
| 1974 | + } else { |
|
| 1975 | + $limit = (int) $limit; |
|
| 1976 | + } |
|
| 1977 | + |
|
| 1978 | + if ($start === null) { |
|
| 1979 | + $start = isset($_GET['start']) ? (int) $_GET['start'] : 0; |
|
| 1980 | + } else { |
|
| 1981 | + $start = (int) $start; |
|
| 1982 | + } |
|
| 1983 | + |
|
| 1984 | + if ($board !== null) { |
|
| 1985 | + $board = (int) $board; |
|
| 1986 | + } elseif (isset($_GET['board'])) { |
|
| 1987 | + $board = (int) $_GET['board']; |
|
| 1988 | + } |
|
| 1989 | + |
|
| 1990 | + if ($length === null) { |
|
| 1991 | + $length = isset($_GET['length']) ? (int) $_GET['length'] : 0; |
|
| 1992 | + } else { |
|
| 1993 | + $length = (int) $length; |
|
| 1994 | + } |
|
| 1895 | 1995 | |
| 1896 | 1996 | $limit = max(0, $limit); |
| 1897 | 1997 | $start = max(0, $start); |
@@ -1909,17 +2009,19 @@ discard block |
||
| 1909 | 2009 | ); |
| 1910 | 2010 | if ($smcFunc['db_num_rows']($request) == 0) |
| 1911 | 2011 | { |
| 1912 | - if ($output_method == 'echo') |
|
| 1913 | - die($txt['ssi_no_guests']); |
|
| 1914 | - else |
|
| 1915 | - return array(); |
|
| 2012 | + if ($output_method == 'echo') { |
|
| 2013 | + die($txt['ssi_no_guests']); |
|
| 2014 | + } else { |
|
| 2015 | + return array(); |
|
| 2016 | + } |
|
| 1916 | 2017 | } |
| 1917 | 2018 | list ($board) = $smcFunc['db_fetch_row']($request); |
| 1918 | 2019 | $smcFunc['db_free_result']($request); |
| 1919 | 2020 | |
| 1920 | 2021 | $icon_sources = array(); |
| 1921 | - foreach ($context['stable_icons'] as $icon) |
|
| 1922 | - $icon_sources[$icon] = 'images_url'; |
|
| 2022 | + foreach ($context['stable_icons'] as $icon) { |
|
| 2023 | + $icon_sources[$icon] = 'images_url'; |
|
| 2024 | + } |
|
| 1923 | 2025 | |
| 1924 | 2026 | if (!empty($modSettings['enable_likes'])) |
| 1925 | 2027 | { |
@@ -1943,12 +2045,14 @@ discard block |
||
| 1943 | 2045 | ) |
| 1944 | 2046 | ); |
| 1945 | 2047 | $posts = array(); |
| 1946 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1947 | - $posts[] = $row['id_first_msg']; |
|
| 2048 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2049 | + $posts[] = $row['id_first_msg']; |
|
| 2050 | + } |
|
| 1948 | 2051 | $smcFunc['db_free_result']($request); |
| 1949 | 2052 | |
| 1950 | - if (empty($posts)) |
|
| 1951 | - return array(); |
|
| 2053 | + if (empty($posts)) { |
|
| 2054 | + return array(); |
|
| 2055 | + } |
|
| 1952 | 2056 | |
| 1953 | 2057 | // Find the posts. |
| 1954 | 2058 | $request = $smcFunc['db_query']('', ' |
@@ -1978,24 +2082,28 @@ discard block |
||
| 1978 | 2082 | $last_space = strrpos($row['body'], ' '); |
| 1979 | 2083 | $last_open = strrpos($row['body'], '<'); |
| 1980 | 2084 | $last_close = strrpos($row['body'], '>'); |
| 1981 | - if (empty($last_space) || ($last_space == $last_open + 3 && (empty($last_close) || (!empty($last_close) && $last_close < $last_open))) || $last_space < $last_open || $last_open == $length - 6) |
|
| 1982 | - $cutoff = $last_open; |
|
| 1983 | - elseif (empty($last_close) || $last_close < $last_open) |
|
| 1984 | - $cutoff = $last_space; |
|
| 2085 | + if (empty($last_space) || ($last_space == $last_open + 3 && (empty($last_close) || (!empty($last_close) && $last_close < $last_open))) || $last_space < $last_open || $last_open == $length - 6) { |
|
| 2086 | + $cutoff = $last_open; |
|
| 2087 | + } elseif (empty($last_close) || $last_close < $last_open) { |
|
| 2088 | + $cutoff = $last_space; |
|
| 2089 | + } |
|
| 1985 | 2090 | |
| 1986 | - if ($cutoff !== false) |
|
| 1987 | - $row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff); |
|
| 2091 | + if ($cutoff !== false) { |
|
| 2092 | + $row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff); |
|
| 2093 | + } |
|
| 1988 | 2094 | $row['body'] .= '...'; |
| 1989 | 2095 | } |
| 1990 | 2096 | |
| 1991 | 2097 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
| 1992 | 2098 | |
| 1993 | - if (!empty($recycle_board) && $row['id_board'] == $recycle_board) |
|
| 1994 | - $row['icon'] = 'recycled'; |
|
| 2099 | + if (!empty($recycle_board) && $row['id_board'] == $recycle_board) { |
|
| 2100 | + $row['icon'] = 'recycled'; |
|
| 2101 | + } |
|
| 1995 | 2102 | |
| 1996 | 2103 | // Check that this message icon is there... |
| 1997 | - if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) |
|
| 1998 | - $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 2104 | + if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) { |
|
| 2105 | + $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 2106 | + } |
|
| 1999 | 2107 | |
| 2000 | 2108 | censorText($row['subject']); |
| 2001 | 2109 | censorText($row['body']); |
@@ -2032,16 +2140,18 @@ discard block |
||
| 2032 | 2140 | } |
| 2033 | 2141 | $smcFunc['db_free_result']($request); |
| 2034 | 2142 | |
| 2035 | - if (empty($return)) |
|
| 2036 | - return $return; |
|
| 2143 | + if (empty($return)) { |
|
| 2144 | + return $return; |
|
| 2145 | + } |
|
| 2037 | 2146 | |
| 2038 | 2147 | $return[count($return) - 1]['is_last'] = true; |
| 2039 | 2148 | |
| 2040 | 2149 | // If mods want to do somthing with this list of posts, let them do that now. |
| 2041 | 2150 | call_integration_hook('integrate_ssi_boardNews', array(&$return)); |
| 2042 | 2151 | |
| 2043 | - if ($output_method != 'echo') |
|
| 2044 | - return $return; |
|
| 2152 | + if ($output_method != 'echo') { |
|
| 2153 | + return $return; |
|
| 2154 | + } |
|
| 2045 | 2155 | |
| 2046 | 2156 | foreach ($return as $news) |
| 2047 | 2157 | { |
@@ -2093,9 +2203,10 @@ discard block |
||
| 2093 | 2203 | echo ' |
| 2094 | 2204 | </div>'; |
| 2095 | 2205 | |
| 2096 | - if (!$news['is_last']) |
|
| 2097 | - echo ' |
|
| 2206 | + if (!$news['is_last']) { |
|
| 2207 | + echo ' |
|
| 2098 | 2208 | <hr>'; |
| 2209 | + } |
|
| 2099 | 2210 | } |
| 2100 | 2211 | } |
| 2101 | 2212 | |
@@ -2109,8 +2220,9 @@ discard block |
||
| 2109 | 2220 | { |
| 2110 | 2221 | global $user_info, $scripturl, $modSettings, $txt, $context, $smcFunc; |
| 2111 | 2222 | |
| 2112 | - if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) |
|
| 2113 | - return; |
|
| 2223 | + if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) { |
|
| 2224 | + return; |
|
| 2225 | + } |
|
| 2114 | 2226 | |
| 2115 | 2227 | // Find all events which are happening in the near future that the member can see. |
| 2116 | 2228 | $request = $smcFunc['db_query']('', ' |
@@ -2136,20 +2248,23 @@ discard block |
||
| 2136 | 2248 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2137 | 2249 | { |
| 2138 | 2250 | // Check if we've already come by an event linked to this same topic with the same title... and don't display it if we have. |
| 2139 | - if (!empty($duplicates[$row['title'] . $row['id_topic']])) |
|
| 2140 | - continue; |
|
| 2251 | + if (!empty($duplicates[$row['title'] . $row['id_topic']])) { |
|
| 2252 | + continue; |
|
| 2253 | + } |
|
| 2141 | 2254 | |
| 2142 | 2255 | // Censor the title. |
| 2143 | 2256 | censorText($row['title']); |
| 2144 | 2257 | |
| 2145 | - if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false))) |
|
| 2146 | - $date = strftime('%Y-%m-%d', forum_time(false)); |
|
| 2147 | - else |
|
| 2148 | - $date = $row['start_date']; |
|
| 2258 | + if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false))) { |
|
| 2259 | + $date = strftime('%Y-%m-%d', forum_time(false)); |
|
| 2260 | + } else { |
|
| 2261 | + $date = $row['start_date']; |
|
| 2262 | + } |
|
| 2149 | 2263 | |
| 2150 | 2264 | // If the topic it is attached to is not approved then don't link it. |
| 2151 | - if (!empty($row['id_first_msg']) && !$row['approved']) |
|
| 2152 | - $row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0; |
|
| 2265 | + if (!empty($row['id_first_msg']) && !$row['approved']) { |
|
| 2266 | + $row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0; |
|
| 2267 | + } |
|
| 2153 | 2268 | |
| 2154 | 2269 | $allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) ? true : false; |
| 2155 | 2270 | |
@@ -2175,24 +2290,27 @@ discard block |
||
| 2175 | 2290 | } |
| 2176 | 2291 | $smcFunc['db_free_result']($request); |
| 2177 | 2292 | |
| 2178 | - foreach ($return as $mday => $array) |
|
| 2179 | - $return[$mday][count($array) - 1]['is_last'] = true; |
|
| 2293 | + foreach ($return as $mday => $array) { |
|
| 2294 | + $return[$mday][count($array) - 1]['is_last'] = true; |
|
| 2295 | + } |
|
| 2180 | 2296 | |
| 2181 | 2297 | // If mods want to do somthing with this list of events, let them do that now. |
| 2182 | 2298 | call_integration_hook('integrate_ssi_recentEvents', array(&$return)); |
| 2183 | 2299 | |
| 2184 | - if ($output_method != 'echo' || empty($return)) |
|
| 2185 | - return $return; |
|
| 2300 | + if ($output_method != 'echo' || empty($return)) { |
|
| 2301 | + return $return; |
|
| 2302 | + } |
|
| 2186 | 2303 | |
| 2187 | 2304 | // Well the output method is echo. |
| 2188 | 2305 | echo ' |
| 2189 | 2306 | <span class="event">' . $txt['events'] . '</span> '; |
| 2190 | - foreach ($return as $mday => $array) |
|
| 2191 | - foreach ($array as $event) |
|
| 2307 | + foreach ($return as $mday => $array) { |
|
| 2308 | + foreach ($array as $event) |
|
| 2192 | 2309 | { |
| 2193 | 2310 | if ($event['can_edit']) |
| 2194 | 2311 | echo ' |
| 2195 | 2312 | <a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> '; |
| 2313 | + } |
|
| 2196 | 2314 | |
| 2197 | 2315 | echo ' |
| 2198 | 2316 | ' . $event['link'] . (!$event['is_last'] ? ', ' : ''); |
@@ -2211,8 +2329,9 @@ discard block |
||
| 2211 | 2329 | global $smcFunc; |
| 2212 | 2330 | |
| 2213 | 2331 | // If $id is null, this was most likely called from a query string and should do nothing. |
| 2214 | - if ($id === null) |
|
| 2215 | - return; |
|
| 2332 | + if ($id === null) { |
|
| 2333 | + return; |
|
| 2334 | + } |
|
| 2216 | 2335 | |
| 2217 | 2336 | $request = $smcFunc['db_query']('', ' |
| 2218 | 2337 | SELECT passwd, member_name, is_activated |
@@ -2244,8 +2363,9 @@ discard block |
||
| 2244 | 2363 | $attachments_boards = boardsAllowedTo('view_attachments'); |
| 2245 | 2364 | |
| 2246 | 2365 | // No boards? Adios amigo. |
| 2247 | - if (empty($attachments_boards)) |
|
| 2248 | - return array(); |
|
| 2366 | + if (empty($attachments_boards)) { |
|
| 2367 | + return array(); |
|
| 2368 | + } |
|
| 2249 | 2369 | |
| 2250 | 2370 | // Is it an array? |
| 2251 | 2371 | $attachment_ext = (array) $attachment_ext; |
@@ -2329,8 +2449,9 @@ discard block |
||
| 2329 | 2449 | call_integration_hook('integrate_ssi_recentAttachments', array(&$attachments)); |
| 2330 | 2450 | |
| 2331 | 2451 | // So you just want an array? Here you can have it. |
| 2332 | - if ($output_method == 'array' || empty($attachments)) |
|
| 2333 | - return $attachments; |
|
| 2452 | + if ($output_method == 'array' || empty($attachments)) { |
|
| 2453 | + return $attachments; |
|
| 2454 | + } |
|
| 2334 | 2455 | |
| 2335 | 2456 | // Give them the default. |
| 2336 | 2457 | echo ' |
@@ -2341,14 +2462,15 @@ discard block |
||
| 2341 | 2462 | <th style="text-align: left; padding: 2">', $txt['downloads'], '</th> |
| 2342 | 2463 | <th style="text-align: left; padding: 2">', $txt['filesize'], '</th> |
| 2343 | 2464 | </tr>'; |
| 2344 | - foreach ($attachments as $attach) |
|
| 2345 | - echo ' |
|
| 2465 | + foreach ($attachments as $attach) { |
|
| 2466 | + echo ' |
|
| 2346 | 2467 | <tr> |
| 2347 | 2468 | <td>', $attach['file']['link'], '</td> |
| 2348 | 2469 | <td>', $attach['member']['link'], '</td> |
| 2349 | 2470 | <td style="text-align: center">', $attach['file']['downloads'], '</td> |
| 2350 | 2471 | <td>', $attach['file']['filesize'], '</td> |
| 2351 | 2472 | </tr>'; |
| 2473 | + } |
|
| 2352 | 2474 | echo ' |
| 2353 | 2475 | </table>'; |
| 2354 | 2476 | } |
@@ -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 => $modAction) |
| 993 | 1034 | { |
| 994 | - if ($modAction['type'] == 'failure') |
|
| 995 | - $failed_steps[] = array( |
|
| 1035 | + if ($modAction['type'] == 'failure') { |
|
| 1036 | + $failed_steps[] = array( |
|
| 996 | 1037 | 'file' => $modAction['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($modAction['is_custom'])) |
|
| 1004 | - $themes_installed[] = $modAction['is_custom']; |
|
| 1045 | + if (!empty($modAction['is_custom'])) { |
|
| 1046 | + $themes_installed[] = $modAction['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 | // This defines two version types for checking the API's are compatible with this version of SMF. |
| 20 | 21 | $GLOBALS['search_versions'] = array( |
@@ -39,8 +40,9 @@ discard block |
||
| 39 | 40 | global $txt, $scripturl, $modSettings, $user_info, $context, $smcFunc, $sourcedir; |
| 40 | 41 | |
| 41 | 42 | // Is the load average too high to allow searching just now? |
| 42 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) |
|
| 43 | - fatal_lang_error('loadavg_search_disabled', false); |
|
| 43 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) { |
|
| 44 | + fatal_lang_error('loadavg_search_disabled', false); |
|
| 45 | + } |
|
| 44 | 46 | |
| 45 | 47 | loadLanguage('Search'); |
| 46 | 48 | // Don't load this in XML mode. |
@@ -88,23 +90,30 @@ discard block |
||
| 88 | 90 | @list ($k, $v) = explode('|\'|', $data); |
| 89 | 91 | $context['search_params'][$k] = $v; |
| 90 | 92 | } |
| 91 | - if (isset($context['search_params']['brd'])) |
|
| 92 | - $context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']); |
|
| 93 | + if (isset($context['search_params']['brd'])) { |
|
| 94 | + $context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']); |
|
| 95 | + } |
|
| 93 | 96 | } |
| 94 | 97 | |
| 95 | - if (isset($_REQUEST['search'])) |
|
| 96 | - $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']); |
|
| 98 | + if (isset($_REQUEST['search'])) { |
|
| 99 | + $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']); |
|
| 100 | + } |
|
| 97 | 101 | |
| 98 | - if (isset($context['search_params']['search'])) |
|
| 99 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
| 100 | - if (isset($context['search_params']['userspec'])) |
|
| 101 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
| 102 | - if (!empty($context['search_params']['searchtype'])) |
|
| 103 | - $context['search_params']['searchtype'] = 2; |
|
| 104 | - if (!empty($context['search_params']['minage'])) |
|
| 105 | - $context['search_params']['minage'] = (int) $context['search_params']['minage']; |
|
| 106 | - if (!empty($context['search_params']['maxage'])) |
|
| 107 | - $context['search_params']['maxage'] = (int) $context['search_params']['maxage']; |
|
| 102 | + if (isset($context['search_params']['search'])) { |
|
| 103 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
| 104 | + } |
|
| 105 | + if (isset($context['search_params']['userspec'])) { |
|
| 106 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
| 107 | + } |
|
| 108 | + if (!empty($context['search_params']['searchtype'])) { |
|
| 109 | + $context['search_params']['searchtype'] = 2; |
|
| 110 | + } |
|
| 111 | + if (!empty($context['search_params']['minage'])) { |
|
| 112 | + $context['search_params']['minage'] = (int) $context['search_params']['minage']; |
|
| 113 | + } |
|
| 114 | + if (!empty($context['search_params']['maxage'])) { |
|
| 115 | + $context['search_params']['maxage'] = (int) $context['search_params']['maxage']; |
|
| 116 | + } |
|
| 108 | 117 | |
| 109 | 118 | $context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']); |
| 110 | 119 | $context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']); |
@@ -116,11 +125,13 @@ discard block |
||
| 116 | 125 | $context['search_errors']['messages'] = array(); |
| 117 | 126 | foreach ($context['search_errors'] as $search_error => $dummy) |
| 118 | 127 | { |
| 119 | - if ($search_error === 'messages') |
|
| 120 | - continue; |
|
| 128 | + if ($search_error === 'messages') { |
|
| 129 | + continue; |
|
| 130 | + } |
|
| 121 | 131 | |
| 122 | - if ($search_error == 'string_too_long') |
|
| 123 | - $txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']); |
|
| 132 | + if ($search_error == 'string_too_long') { |
|
| 133 | + $txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']); |
|
| 134 | + } |
|
| 124 | 135 | |
| 125 | 136 | $context['search_errors']['messages'][] = $txt['error_' . $search_error]; |
| 126 | 137 | } |
@@ -143,12 +154,13 @@ discard block |
||
| 143 | 154 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 144 | 155 | { |
| 145 | 156 | // This category hasn't been set up yet.. |
| 146 | - if (!isset($context['categories'][$row['id_cat']])) |
|
| 147 | - $context['categories'][$row['id_cat']] = array( |
|
| 157 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
| 158 | + $context['categories'][$row['id_cat']] = array( |
|
| 148 | 159 | 'id' => $row['id_cat'], |
| 149 | 160 | 'name' => $row['cat_name'], |
| 150 | 161 | 'boards' => array() |
| 151 | 162 | ); |
| 163 | + } |
|
| 152 | 164 | |
| 153 | 165 | // Set this board up, and let the template know when it's a child. (indent them..) |
| 154 | 166 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -159,8 +171,9 @@ discard block |
||
| 159 | 171 | ); |
| 160 | 172 | |
| 161 | 173 | // If a board wasn't checked that probably should have been ensure the board selection is selected, yo! |
| 162 | - if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board'])) |
|
| 163 | - $context['boards_check_all'] = false; |
|
| 174 | + if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board'])) { |
|
| 175 | + $context['boards_check_all'] = false; |
|
| 176 | + } |
|
| 164 | 177 | } |
| 165 | 178 | $smcFunc['db_free_result']($request); |
| 166 | 179 | |
@@ -182,18 +195,20 @@ discard block |
||
| 182 | 195 | } |
| 183 | 196 | |
| 184 | 197 | $max_boards = ceil(count($temp_boards) / 2); |
| 185 | - if ($max_boards == 1) |
|
| 186 | - $max_boards = 2; |
|
| 198 | + if ($max_boards == 1) { |
|
| 199 | + $max_boards = 2; |
|
| 200 | + } |
|
| 187 | 201 | |
| 188 | 202 | // Now, alternate them so they can be shown left and right ;). |
| 189 | 203 | $context['board_columns'] = array(); |
| 190 | 204 | for ($i = 0; $i < $max_boards; $i++) |
| 191 | 205 | { |
| 192 | 206 | $context['board_columns'][] = $temp_boards[$i]; |
| 193 | - if (isset($temp_boards[$i + $max_boards])) |
|
| 194 | - $context['board_columns'][] = $temp_boards[$i + $max_boards]; |
|
| 195 | - else |
|
| 196 | - $context['board_columns'][] = array(); |
|
| 207 | + if (isset($temp_boards[$i + $max_boards])) { |
|
| 208 | + $context['board_columns'][] = $temp_boards[$i + $max_boards]; |
|
| 209 | + } else { |
|
| 210 | + $context['board_columns'][] = array(); |
|
| 211 | + } |
|
| 197 | 212 | } |
| 198 | 213 | |
| 199 | 214 | if (!empty($_REQUEST['topic'])) |
@@ -225,8 +240,9 @@ discard block |
||
| 225 | 240 | ) |
| 226 | 241 | ); |
| 227 | 242 | |
| 228 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 229 | - fatal_lang_error('topic_gone', false); |
|
| 243 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 244 | + fatal_lang_error('topic_gone', false); |
|
| 245 | + } |
|
| 230 | 246 | |
| 231 | 247 | list ($context['search_topic']['subject']) = $smcFunc['db_fetch_row']($request); |
| 232 | 248 | $smcFunc['db_free_result']($request); |
@@ -256,11 +272,13 @@ discard block |
||
| 256 | 272 | global $excludedWords, $participants, $smcFunc; |
| 257 | 273 | |
| 258 | 274 | // if comming from the quick search box, and we want to search on members, well we need to do that ;) |
| 259 | - if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members') |
|
| 260 | - redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search'])); |
|
| 275 | + if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members') { |
|
| 276 | + redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search'])); |
|
| 277 | + } |
|
| 261 | 278 | |
| 262 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) |
|
| 263 | - fatal_lang_error('loadavg_search_disabled', false); |
|
| 279 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) { |
|
| 280 | + fatal_lang_error('loadavg_search_disabled', false); |
|
| 281 | + } |
|
| 264 | 282 | |
| 265 | 283 | // No, no, no... this is a bit hard on the server, so don't you go prefetching it! |
| 266 | 284 | if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
@@ -307,8 +325,9 @@ discard block |
||
| 307 | 325 | } |
| 308 | 326 | |
| 309 | 327 | // Zero weight. Weightless :P. |
| 310 | - if (empty($weight_total)) |
|
| 311 | - fatal_lang_error('search_invalid_weights'); |
|
| 328 | + if (empty($weight_total)) { |
|
| 329 | + fatal_lang_error('search_invalid_weights'); |
|
| 330 | + } |
|
| 312 | 331 | |
| 313 | 332 | // These vars don't require an interface, they're just here for tweaking. |
| 314 | 333 | $recentPercentage = 0.30; |
@@ -326,11 +345,13 @@ discard block |
||
| 326 | 345 | $context['search_string_limit'] = 100; |
| 327 | 346 | |
| 328 | 347 | loadLanguage('Search'); |
| 329 | - if (!isset($_REQUEST['xml'])) |
|
| 330 | - loadTemplate('Search'); |
|
| 348 | + if (!isset($_REQUEST['xml'])) { |
|
| 349 | + loadTemplate('Search'); |
|
| 350 | + } |
|
| 331 | 351 | //If we're doing XML we need to use the results template regardless really. |
| 332 | - else |
|
| 333 | - $context['sub_template'] = 'results'; |
|
| 352 | + else { |
|
| 353 | + $context['sub_template'] = 'results'; |
|
| 354 | + } |
|
| 334 | 355 | |
| 335 | 356 | // Are you allowed? |
| 336 | 357 | isAllowedTo('search_posts'); |
@@ -363,34 +384,39 @@ discard block |
||
| 363 | 384 | $search_params[$k] = $v; |
| 364 | 385 | } |
| 365 | 386 | |
| 366 | - if (isset($search_params['brd'])) |
|
| 367 | - $search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']); |
|
| 387 | + if (isset($search_params['brd'])) { |
|
| 388 | + $search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']); |
|
| 389 | + } |
|
| 368 | 390 | } |
| 369 | 391 | |
| 370 | 392 | // Store whether simple search was used (needed if the user wants to do another query). |
| 371 | - if (!isset($search_params['advanced'])) |
|
| 372 | - $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1; |
|
| 393 | + if (!isset($search_params['advanced'])) { |
|
| 394 | + $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1; |
|
| 395 | + } |
|
| 373 | 396 | |
| 374 | 397 | // 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'. |
| 375 | - if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) |
|
| 376 | - $search_params['searchtype'] = 2; |
|
| 398 | + if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) { |
|
| 399 | + $search_params['searchtype'] = 2; |
|
| 400 | + } |
|
| 377 | 401 | |
| 378 | 402 | // Minimum age of messages. Default to zero (don't set param in that case). |
| 379 | - if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) |
|
| 380 | - $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage']; |
|
| 403 | + if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) { |
|
| 404 | + $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage']; |
|
| 405 | + } |
|
| 381 | 406 | |
| 382 | 407 | // Maximum age of messages. Default to infinite (9999 days: param not set). |
| 383 | - if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999)) |
|
| 384 | - $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage']; |
|
| 408 | + if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999)) { |
|
| 409 | + $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage']; |
|
| 410 | + } |
|
| 385 | 411 | |
| 386 | 412 | // Searching a specific topic? |
| 387 | 413 | if (!empty($_REQUEST['topic']) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'topic')) |
| 388 | 414 | { |
| 389 | 415 | $search_params['topic'] = empty($_REQUEST['search_selection']) ? (int) $_REQUEST['topic'] : (isset($_REQUEST['sd_topic']) ? (int) $_REQUEST['sd_topic'] : ''); |
| 390 | 416 | $search_params['show_complete'] = true; |
| 417 | + } elseif (!empty($search_params['topic'])) { |
|
| 418 | + $search_params['topic'] = (int) $search_params['topic']; |
|
| 391 | 419 | } |
| 392 | - elseif (!empty($search_params['topic'])) |
|
| 393 | - $search_params['topic'] = (int) $search_params['topic']; |
|
| 394 | 420 | |
| 395 | 421 | if (!empty($search_params['minage']) || !empty($search_params['maxage'])) |
| 396 | 422 | { |
@@ -408,19 +434,21 @@ discard block |
||
| 408 | 434 | ) |
| 409 | 435 | ); |
| 410 | 436 | list ($minMsgID, $maxMsgID) = $smcFunc['db_fetch_row']($request); |
| 411 | - if ($minMsgID < 0 || $maxMsgID < 0) |
|
| 412 | - $context['search_errors']['no_messages_in_time_frame'] = true; |
|
| 437 | + if ($minMsgID < 0 || $maxMsgID < 0) { |
|
| 438 | + $context['search_errors']['no_messages_in_time_frame'] = true; |
|
| 439 | + } |
|
| 413 | 440 | $smcFunc['db_free_result']($request); |
| 414 | 441 | } |
| 415 | 442 | |
| 416 | 443 | // Default the user name to a wildcard matching every user (*). |
| 417 | - if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) |
|
| 418 | - $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec']; |
|
| 444 | + if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) { |
|
| 445 | + $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec']; |
|
| 446 | + } |
|
| 419 | 447 | |
| 420 | 448 | // If there's no specific user, then don't mention it in the main query. |
| 421 | - if (empty($search_params['userspec'])) |
|
| 422 | - $userQuery = ''; |
|
| 423 | - else |
|
| 449 | + if (empty($search_params['userspec'])) { |
|
| 450 | + $userQuery = ''; |
|
| 451 | + } else |
|
| 424 | 452 | { |
| 425 | 453 | $userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('"' => '"')); |
| 426 | 454 | $userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')); |
@@ -432,19 +460,21 @@ discard block |
||
| 432 | 460 | { |
| 433 | 461 | $possible_users[$k] = trim($possible_users[$k]); |
| 434 | 462 | |
| 435 | - if (strlen($possible_users[$k]) == 0) |
|
| 436 | - unset($possible_users[$k]); |
|
| 463 | + if (strlen($possible_users[$k]) == 0) { |
|
| 464 | + unset($possible_users[$k]); |
|
| 465 | + } |
|
| 437 | 466 | } |
| 438 | 467 | |
| 439 | 468 | // Create a list of database-escaped search names. |
| 440 | 469 | $realNameMatches = array(); |
| 441 | - foreach ($possible_users as $possible_user) |
|
| 442 | - $realNameMatches[] = $smcFunc['db_quote']( |
|
| 470 | + foreach ($possible_users as $possible_user) { |
|
| 471 | + $realNameMatches[] = $smcFunc['db_quote']( |
|
| 443 | 472 | '{string:possible_user}', |
| 444 | 473 | array( |
| 445 | 474 | 'possible_user' => $possible_user |
| 446 | 475 | ) |
| 447 | 476 | ); |
| 477 | + } |
|
| 448 | 478 | |
| 449 | 479 | // Retrieve a list of possible members. |
| 450 | 480 | $request = $smcFunc['db_query']('', ' |
@@ -456,9 +486,9 @@ discard block |
||
| 456 | 486 | ) |
| 457 | 487 | ); |
| 458 | 488 | // Simply do nothing if there're too many members matching the criteria. |
| 459 | - if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) |
|
| 460 | - $userQuery = ''; |
|
| 461 | - elseif ($smcFunc['db_num_rows']($request) == 0) |
|
| 489 | + if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) { |
|
| 490 | + $userQuery = ''; |
|
| 491 | + } elseif ($smcFunc['db_num_rows']($request) == 0) |
|
| 462 | 492 | { |
| 463 | 493 | $userQuery = $smcFunc['db_quote']( |
| 464 | 494 | 'm.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})', |
@@ -467,12 +497,12 @@ discard block |
||
| 467 | 497 | 'match_possible_guest_names' => 'm.poster_name LIKE ' . implode(' OR m.poster_name LIKE ', $realNameMatches), |
| 468 | 498 | ) |
| 469 | 499 | ); |
| 470 | - } |
|
| 471 | - else |
|
| 500 | + } else |
|
| 472 | 501 | { |
| 473 | 502 | $memberlist = array(); |
| 474 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 475 | - $memberlist[] = $row['id_member']; |
|
| 503 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 504 | + $memberlist[] = $row['id_member']; |
|
| 505 | + } |
|
| 476 | 506 | $userQuery = $smcFunc['db_quote']( |
| 477 | 507 | '(m.id_member IN ({array_int:matched_members}) OR (m.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})))', |
| 478 | 508 | array( |
@@ -486,22 +516,25 @@ discard block |
||
| 486 | 516 | } |
| 487 | 517 | |
| 488 | 518 | // If the boards were passed by URL (params=), temporarily put them back in $_REQUEST. |
| 489 | - if (!empty($search_params['brd']) && is_array($search_params['brd'])) |
|
| 490 | - $_REQUEST['brd'] = $search_params['brd']; |
|
| 519 | + if (!empty($search_params['brd']) && is_array($search_params['brd'])) { |
|
| 520 | + $_REQUEST['brd'] = $search_params['brd']; |
|
| 521 | + } |
|
| 491 | 522 | |
| 492 | 523 | // Ensure that brd is an array. |
| 493 | 524 | if ((!empty($_REQUEST['brd']) && !is_array($_REQUEST['brd'])) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'board')) |
| 494 | 525 | { |
| 495 | - if (!empty($_REQUEST['brd'])) |
|
| 496 | - $_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']); |
|
| 497 | - else |
|
| 498 | - $_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array(); |
|
| 526 | + if (!empty($_REQUEST['brd'])) { |
|
| 527 | + $_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']); |
|
| 528 | + } else { |
|
| 529 | + $_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array(); |
|
| 530 | + } |
|
| 499 | 531 | } |
| 500 | 532 | |
| 501 | 533 | // Make sure all boards are integers. |
| 502 | - if (!empty($_REQUEST['brd'])) |
|
| 503 | - foreach ($_REQUEST['brd'] as $id => $brd) |
|
| 534 | + if (!empty($_REQUEST['brd'])) { |
|
| 535 | + foreach ($_REQUEST['brd'] as $id => $brd) |
|
| 504 | 536 | $_REQUEST['brd'][$id] = (int) $brd; |
| 537 | + } |
|
| 505 | 538 | |
| 506 | 539 | // Special case for boards: searching just one topic? |
| 507 | 540 | if (!empty($search_params['topic'])) |
@@ -520,17 +553,18 @@ discard block |
||
| 520 | 553 | ) |
| 521 | 554 | ); |
| 522 | 555 | |
| 523 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 524 | - fatal_lang_error('topic_gone', false); |
|
| 556 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 557 | + fatal_lang_error('topic_gone', false); |
|
| 558 | + } |
|
| 525 | 559 | |
| 526 | 560 | $search_params['brd'] = array(); |
| 527 | 561 | list ($search_params['brd'][0]) = $smcFunc['db_fetch_row']($request); |
| 528 | 562 | $smcFunc['db_free_result']($request); |
| 529 | 563 | } |
| 530 | 564 | // Select all boards you've selected AND are allowed to see. |
| 531 | - elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd']))) |
|
| 532 | - $search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd']; |
|
| 533 | - else |
|
| 565 | + elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd']))) { |
|
| 566 | + $search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd']; |
|
| 567 | + } else |
|
| 534 | 568 | { |
| 535 | 569 | $see_board = empty($search_params['advanced']) ? 'query_wanna_see_board' : 'query_see_board'; |
| 536 | 570 | $request = $smcFunc['db_query']('', ' |
@@ -548,19 +582,22 @@ discard block |
||
| 548 | 582 | ) |
| 549 | 583 | ); |
| 550 | 584 | $search_params['brd'] = array(); |
| 551 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 552 | - $search_params['brd'][] = $row['id_board']; |
|
| 585 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 586 | + $search_params['brd'][] = $row['id_board']; |
|
| 587 | + } |
|
| 553 | 588 | $smcFunc['db_free_result']($request); |
| 554 | 589 | |
| 555 | 590 | // This error should pro'bly only happen for hackers. |
| 556 | - if (empty($search_params['brd'])) |
|
| 557 | - $context['search_errors']['no_boards_selected'] = true; |
|
| 591 | + if (empty($search_params['brd'])) { |
|
| 592 | + $context['search_errors']['no_boards_selected'] = true; |
|
| 593 | + } |
|
| 558 | 594 | } |
| 559 | 595 | |
| 560 | 596 | if (count($search_params['brd']) != 0) |
| 561 | 597 | { |
| 562 | - foreach ($search_params['brd'] as $k => $v) |
|
| 563 | - $search_params['brd'][$k] = (int) $v; |
|
| 598 | + foreach ($search_params['brd'] as $k => $v) { |
|
| 599 | + $search_params['brd'][$k] = (int) $v; |
|
| 600 | + } |
|
| 564 | 601 | |
| 565 | 602 | // If we've selected all boards, this parameter can be left empty. |
| 566 | 603 | $request = $smcFunc['db_query']('', ' |
@@ -574,15 +611,16 @@ discard block |
||
| 574 | 611 | list ($num_boards) = $smcFunc['db_fetch_row']($request); |
| 575 | 612 | $smcFunc['db_free_result']($request); |
| 576 | 613 | |
| 577 | - if (count($search_params['brd']) == $num_boards) |
|
| 614 | + if (count($search_params['brd']) == $num_boards) { |
|
| 615 | + $boardQuery = ''; |
|
| 616 | + } elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd'])) { |
|
| 617 | + $boardQuery = '!= ' . $modSettings['recycle_board']; |
|
| 618 | + } else { |
|
| 619 | + $boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')'; |
|
| 620 | + } |
|
| 621 | + } else { |
|
| 578 | 622 | $boardQuery = ''; |
| 579 | - elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd'])) |
|
| 580 | - $boardQuery = '!= ' . $modSettings['recycle_board']; |
|
| 581 | - else |
|
| 582 | - $boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')'; |
|
| 583 | 623 | } |
| 584 | - else |
|
| 585 | - $boardQuery = ''; |
|
| 586 | 624 | |
| 587 | 625 | $search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']); |
| 588 | 626 | $search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']); |
@@ -596,11 +634,13 @@ discard block |
||
| 596 | 634 | 'id_msg', |
| 597 | 635 | ); |
| 598 | 636 | call_integration_hook('integrate_search_sort_columns', array(&$sort_columns)); |
| 599 | - if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) |
|
| 600 | - list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); |
|
| 637 | + if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) { |
|
| 638 | + list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); |
|
| 639 | + } |
|
| 601 | 640 | $search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'relevance'; |
| 602 | - if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies') |
|
| 603 | - $search_params['sort'] = 'id_msg'; |
|
| 641 | + if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies') { |
|
| 642 | + $search_params['sort'] = 'id_msg'; |
|
| 643 | + } |
|
| 604 | 644 | |
| 605 | 645 | // Sorting direction: descending unless stated otherwise. |
| 606 | 646 | $search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc'; |
@@ -624,17 +664,19 @@ discard block |
||
| 624 | 664 | // What are we searching for? |
| 625 | 665 | if (empty($search_params['search'])) |
| 626 | 666 | { |
| 627 | - if (isset($_GET['search'])) |
|
| 628 | - $search_params['search'] = un_htmlspecialchars($_GET['search']); |
|
| 629 | - elseif (isset($_POST['search'])) |
|
| 630 | - $search_params['search'] = $_POST['search']; |
|
| 631 | - else |
|
| 632 | - $search_params['search'] = ''; |
|
| 667 | + if (isset($_GET['search'])) { |
|
| 668 | + $search_params['search'] = un_htmlspecialchars($_GET['search']); |
|
| 669 | + } elseif (isset($_POST['search'])) { |
|
| 670 | + $search_params['search'] = $_POST['search']; |
|
| 671 | + } else { |
|
| 672 | + $search_params['search'] = ''; |
|
| 673 | + } |
|
| 633 | 674 | } |
| 634 | 675 | |
| 635 | 676 | // Nothing?? |
| 636 | - if (!isset($search_params['search']) || $search_params['search'] == '') |
|
| 637 | - $context['search_errors']['invalid_search_string'] = true; |
|
| 677 | + if (!isset($search_params['search']) || $search_params['search'] == '') { |
|
| 678 | + $context['search_errors']['invalid_search_string'] = true; |
|
| 679 | + } |
|
| 638 | 680 | // Too long? |
| 639 | 681 | elseif ($smcFunc['strlen']($search_params['search']) > $context['search_string_limit']) |
| 640 | 682 | { |
@@ -648,8 +690,9 @@ discard block |
||
| 648 | 690 | $stripped_query = un_htmlspecialchars($smcFunc['strtolower']($stripped_query)); |
| 649 | 691 | |
| 650 | 692 | // This (hidden) setting will do fulltext searching in the most basic way. |
| 651 | - if (!empty($modSettings['search_simple_fulltext'])) |
|
| 652 | - $stripped_query = strtr($stripped_query, array('"' => '')); |
|
| 693 | + if (!empty($modSettings['search_simple_fulltext'])) { |
|
| 694 | + $stripped_query = strtr($stripped_query, array('"' => '')); |
|
| 695 | + } |
|
| 653 | 696 | |
| 654 | 697 | $no_regexp = preg_match('~&#(?:\d{1,7}|x[0-9a-fA-F]{1,6});~', $stripped_query) === 1; |
| 655 | 698 | |
@@ -672,8 +715,9 @@ discard block |
||
| 672 | 715 | { |
| 673 | 716 | if ($word === '-') |
| 674 | 717 | { |
| 675 | - if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) |
|
| 676 | - $excludedWords[] = $word; |
|
| 718 | + if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) { |
|
| 719 | + $excludedWords[] = $word; |
|
| 720 | + } |
|
| 677 | 721 | unset($phraseArray[$index]); |
| 678 | 722 | } |
| 679 | 723 | } |
@@ -683,8 +727,9 @@ discard block |
||
| 683 | 727 | { |
| 684 | 728 | if (strpos(trim($word), '-') === 0) |
| 685 | 729 | { |
| 686 | - if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) |
|
| 687 | - $excludedWords[] = $word; |
|
| 730 | + if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) { |
|
| 731 | + $excludedWords[] = $word; |
|
| 732 | + } |
|
| 688 | 733 | unset($wordArray[$index]); |
| 689 | 734 | } |
| 690 | 735 | } |
@@ -697,8 +742,9 @@ discard block |
||
| 697 | 742 | foreach ($searchArray as $index => $value) |
| 698 | 743 | { |
| 699 | 744 | // Skip anything practically empty. |
| 700 | - if (($searchArray[$index] = trim($value, '-_\' ')) === '') |
|
| 701 | - unset($searchArray[$index]); |
|
| 745 | + if (($searchArray[$index] = trim($value, '-_\' ')) === '') { |
|
| 746 | + unset($searchArray[$index]); |
|
| 747 | + } |
|
| 702 | 748 | // Skip blacklisted words. Make sure to note we skipped them in case we end up with nothing. |
| 703 | 749 | elseif (in_array($searchArray[$index], $blacklisted_words)) |
| 704 | 750 | { |
@@ -716,31 +762,37 @@ discard block |
||
| 716 | 762 | |
| 717 | 763 | // Create an array of replacements for highlighting. |
| 718 | 764 | $context['mark'] = array(); |
| 719 | - foreach ($searchArray as $word) |
|
| 720 | - $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>'; |
|
| 765 | + foreach ($searchArray as $word) { |
|
| 766 | + $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>'; |
|
| 767 | + } |
|
| 721 | 768 | |
| 722 | 769 | // Initialize two arrays storing the words that have to be searched for. |
| 723 | 770 | $orParts = array(); |
| 724 | 771 | $searchWords = array(); |
| 725 | 772 | |
| 726 | 773 | // Make sure at least one word is being searched for. |
| 727 | - if (empty($searchArray)) |
|
| 728 | - $context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true; |
|
| 774 | + if (empty($searchArray)) { |
|
| 775 | + $context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true; |
|
| 776 | + } |
|
| 729 | 777 | // All words/sentences must match. |
| 730 | - elseif (empty($search_params['searchtype'])) |
|
| 731 | - $orParts[0] = $searchArray; |
|
| 778 | + elseif (empty($search_params['searchtype'])) { |
|
| 779 | + $orParts[0] = $searchArray; |
|
| 780 | + } |
|
| 732 | 781 | // Any word/sentence must match. |
| 733 | - else |
|
| 734 | - foreach ($searchArray as $index => $value) |
|
| 782 | + else { |
|
| 783 | + foreach ($searchArray as $index => $value) |
|
| 735 | 784 | $orParts[$index] = array($value); |
| 785 | + } |
|
| 736 | 786 | |
| 737 | 787 | // Don't allow duplicate error messages if one string is too short. |
| 738 | - if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string'])) |
|
| 739 | - unset($context['search_errors']['invalid_search_string']); |
|
| 788 | + if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string'])) { |
|
| 789 | + unset($context['search_errors']['invalid_search_string']); |
|
| 790 | + } |
|
| 740 | 791 | // Make sure the excluded words are in all or-branches. |
| 741 | - foreach ($orParts as $orIndex => $andParts) |
|
| 742 | - foreach ($excludedWords as $word) |
|
| 792 | + foreach ($orParts as $orIndex => $andParts) { |
|
| 793 | + foreach ($excludedWords as $word) |
|
| 743 | 794 | $orParts[$orIndex][] = $word; |
| 795 | + } |
|
| 744 | 796 | |
| 745 | 797 | // Determine the or-branches and the fulltext search words. |
| 746 | 798 | foreach ($orParts as $orIndex => $andParts) |
@@ -754,8 +806,9 @@ discard block |
||
| 754 | 806 | ); |
| 755 | 807 | |
| 756 | 808 | // Sort the indexed words (large words -> small words -> excluded words). |
| 757 | - if ($searchAPI->supportsMethod('searchSort')) |
|
| 758 | - usort($orParts[$orIndex], 'searchSort'); |
|
| 809 | + if ($searchAPI->supportsMethod('searchSort')) { |
|
| 810 | + usort($orParts[$orIndex], 'searchSort'); |
|
| 811 | + } |
|
| 759 | 812 | |
| 760 | 813 | foreach ($orParts[$orIndex] as $word) |
| 761 | 814 | { |
@@ -767,15 +820,17 @@ discard block |
||
| 767 | 820 | if (!$is_excluded || count($subjectWords) === 1) |
| 768 | 821 | { |
| 769 | 822 | $searchWords[$orIndex]['subject_words'] = array_merge($searchWords[$orIndex]['subject_words'], $subjectWords); |
| 770 | - if ($is_excluded) |
|
| 771 | - $excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords); |
|
| 823 | + if ($is_excluded) { |
|
| 824 | + $excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords); |
|
| 825 | + } |
|
| 826 | + } else { |
|
| 827 | + $excludedPhrases[] = $word; |
|
| 772 | 828 | } |
| 773 | - else |
|
| 774 | - $excludedPhrases[] = $word; |
|
| 775 | 829 | |
| 776 | 830 | // Have we got indexes to prepare? |
| 777 | - if ($searchAPI->supportsMethod('prepareIndexes')) |
|
| 778 | - $searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded); |
|
| 831 | + if ($searchAPI->supportsMethod('prepareIndexes')) { |
|
| 832 | + $searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded); |
|
| 833 | + } |
|
| 779 | 834 | } |
| 780 | 835 | |
| 781 | 836 | // Search_force_index requires all AND parts to have at least one fulltext word. |
@@ -783,8 +838,7 @@ discard block |
||
| 783 | 838 | { |
| 784 | 839 | $context['search_errors']['query_not_specific_enough'] = true; |
| 785 | 840 | break; |
| 786 | - } |
|
| 787 | - elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords)) |
|
| 841 | + } elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords)) |
|
| 788 | 842 | { |
| 789 | 843 | $context['search_errors']['query_not_specific_enough'] = true; |
| 790 | 844 | break; |
@@ -812,8 +866,9 @@ discard block |
||
| 812 | 866 | $found_misspelling = false; |
| 813 | 867 | foreach ($searchArray as $word) |
| 814 | 868 | { |
| 815 | - if (empty($link)) |
|
| 816 | - continue; |
|
| 869 | + if (empty($link)) { |
|
| 870 | + continue; |
|
| 871 | + } |
|
| 817 | 872 | |
| 818 | 873 | // Don't check phrases. |
| 819 | 874 | if (preg_match('~^\w+$~', $word) === 0) |
@@ -828,8 +883,7 @@ discard block |
||
| 828 | 883 | $did_you_mean['search'][] = $word; |
| 829 | 884 | $did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word); |
| 830 | 885 | continue; |
| 831 | - } |
|
| 832 | - elseif (spell_check($link, $word)) |
|
| 886 | + } elseif (spell_check($link, $word)) |
|
| 833 | 887 | { |
| 834 | 888 | $did_you_mean['search'][] = $word; |
| 835 | 889 | $did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word); |
@@ -840,11 +894,13 @@ discard block |
||
| 840 | 894 | foreach ($suggestions as $i => $s) |
| 841 | 895 | { |
| 842 | 896 | // Search is case insensitive. |
| 843 | - if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word)) |
|
| 844 | - unset($suggestions[$i]); |
|
| 897 | + if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word)) { |
|
| 898 | + unset($suggestions[$i]); |
|
| 899 | + } |
|
| 845 | 900 | // Plus, don't suggest something the user thinks is rude! |
| 846 | - elseif ($suggestions[$i] != censorText($s)) |
|
| 847 | - unset($suggestions[$i]); |
|
| 901 | + elseif ($suggestions[$i] != censorText($s)) { |
|
| 902 | + unset($suggestions[$i]); |
|
| 903 | + } |
|
| 848 | 904 | } |
| 849 | 905 | |
| 850 | 906 | // Anything found? If so, correct it! |
@@ -854,8 +910,7 @@ discard block |
||
| 854 | 910 | $did_you_mean['search'][] = $suggestions[0]; |
| 855 | 911 | $did_you_mean['display'][] = '<em><strong>' . $smcFunc['htmlspecialchars']($suggestions[0]) . '</strong></em>'; |
| 856 | 912 | $found_misspelling = true; |
| 857 | - } |
|
| 858 | - else |
|
| 913 | + } else |
|
| 859 | 914 | { |
| 860 | 915 | $did_you_mean['search'][] = $word; |
| 861 | 916 | $did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word); |
@@ -872,8 +927,7 @@ discard block |
||
| 872 | 927 | { |
| 873 | 928 | $temp_excluded['search'][] = '-"' . $word . '"'; |
| 874 | 929 | $temp_excluded['display'][] = '-"' . $smcFunc['htmlspecialchars']($word) . '"'; |
| 875 | - } |
|
| 876 | - else |
|
| 930 | + } else |
|
| 877 | 931 | { |
| 878 | 932 | $temp_excluded['search'][] = '-' . $word; |
| 879 | 933 | $temp_excluded['display'][] = '-' . $smcFunc['htmlspecialchars']($word); |
@@ -885,11 +939,13 @@ discard block |
||
| 885 | 939 | |
| 886 | 940 | $temp_params = $search_params; |
| 887 | 941 | $temp_params['search'] = implode(' ', $did_you_mean['search']); |
| 888 | - if (isset($temp_params['brd'])) |
|
| 889 | - $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
| 942 | + if (isset($temp_params['brd'])) { |
|
| 943 | + $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
| 944 | + } |
|
| 890 | 945 | $context['params'] = array(); |
| 891 | - foreach ($temp_params as $k => $v) |
|
| 892 | - $context['did_you_mean_params'][] = $k . '|\'|' . $v; |
|
| 946 | + foreach ($temp_params as $k => $v) { |
|
| 947 | + $context['did_you_mean_params'][] = $k . '|\'|' . $v; |
|
| 948 | + } |
|
| 893 | 949 | $context['did_you_mean_params'] = base64_encode(implode('|"|', $context['did_you_mean_params'])); |
| 894 | 950 | $context['did_you_mean'] = implode(' ', $did_you_mean['display']); |
| 895 | 951 | } |
@@ -897,18 +953,20 @@ discard block |
||
| 897 | 953 | |
| 898 | 954 | // Let the user adjust the search query, should they wish? |
| 899 | 955 | $context['search_params'] = $search_params; |
| 900 | - if (isset($context['search_params']['search'])) |
|
| 901 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
| 902 | - if (isset($context['search_params']['userspec'])) |
|
| 903 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
| 956 | + if (isset($context['search_params']['search'])) { |
|
| 957 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
| 958 | + } |
|
| 959 | + if (isset($context['search_params']['userspec'])) { |
|
| 960 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
| 961 | + } |
|
| 904 | 962 | |
| 905 | 963 | // Do we have captcha enabled? |
| 906 | 964 | if ($user_info['is_guest'] && !empty($modSettings['search_enable_captcha']) && empty($_SESSION['ss_vv_passed']) && (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search'])) |
| 907 | 965 | { |
| 908 | 966 | // If we come from another search box tone down the error... |
| 909 | - if (!isset($_REQUEST['search_vv'])) |
|
| 910 | - $context['search_errors']['need_verification_code'] = true; |
|
| 911 | - else |
|
| 967 | + if (!isset($_REQUEST['search_vv'])) { |
|
| 968 | + $context['search_errors']['need_verification_code'] = true; |
|
| 969 | + } else |
|
| 912 | 970 | { |
| 913 | 971 | require_once($sourcedir . '/Subs-Editor.php'); |
| 914 | 972 | $verificationOptions = array( |
@@ -918,12 +976,14 @@ discard block |
||
| 918 | 976 | |
| 919 | 977 | if (is_array($context['require_verification'])) |
| 920 | 978 | { |
| 921 | - foreach ($context['require_verification'] as $error) |
|
| 922 | - $context['search_errors'][$error] = true; |
|
| 979 | + foreach ($context['require_verification'] as $error) { |
|
| 980 | + $context['search_errors'][$error] = true; |
|
| 981 | + } |
|
| 923 | 982 | } |
| 924 | 983 | // Don't keep asking for it - they've proven themselves worthy. |
| 925 | - else |
|
| 926 | - $_SESSION['ss_vv_passed'] = true; |
|
| 984 | + else { |
|
| 985 | + $_SESSION['ss_vv_passed'] = true; |
|
| 986 | + } |
|
| 927 | 987 | } |
| 928 | 988 | } |
| 929 | 989 | |
@@ -931,19 +991,22 @@ discard block |
||
| 931 | 991 | |
| 932 | 992 | // All search params have been checked, let's compile them to a single string... made less simple by PHP 4.3.9 and below. |
| 933 | 993 | $temp_params = $search_params; |
| 934 | - if (isset($temp_params['brd'])) |
|
| 935 | - $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
| 994 | + if (isset($temp_params['brd'])) { |
|
| 995 | + $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
| 996 | + } |
|
| 936 | 997 | $context['params'] = array(); |
| 937 | - foreach ($temp_params as $k => $v) |
|
| 938 | - $context['params'][] = $k . '|\'|' . $v; |
|
| 998 | + foreach ($temp_params as $k => $v) { |
|
| 999 | + $context['params'][] = $k . '|\'|' . $v; |
|
| 1000 | + } |
|
| 939 | 1001 | |
| 940 | 1002 | if (!empty($context['params'])) |
| 941 | 1003 | { |
| 942 | 1004 | // Due to old IE's 2083 character limit, we have to compress long search strings |
| 943 | 1005 | $params = @gzcompress(implode('|"|', $context['params'])); |
| 944 | 1006 | // Gzcompress failed, use try non-gz |
| 945 | - if (empty($params)) |
|
| 946 | - $params = implode('|"|', $context['params']); |
|
| 1007 | + if (empty($params)) { |
|
| 1008 | + $params = implode('|"|', $context['params']); |
|
| 1009 | + } |
|
| 947 | 1010 | // Base64 encode, then replace +/= with uri safe ones that can be reverted |
| 948 | 1011 | $context['params'] = str_replace(array('+', '/', '='), array('-', '_', '.'), base64_encode($params)); |
| 949 | 1012 | } |
@@ -969,8 +1032,9 @@ discard block |
||
| 969 | 1032 | } |
| 970 | 1033 | |
| 971 | 1034 | // Spam me not, Spam-a-lot? |
| 972 | - if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']) |
|
| 973 | - spamProtection('search'); |
|
| 1035 | + if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']) { |
|
| 1036 | + spamProtection('search'); |
|
| 1037 | + } |
|
| 974 | 1038 | // Store the last search string to allow pages of results to be browsed. |
| 975 | 1039 | $_SESSION['last_ss'] = $search_params['search']; |
| 976 | 1040 | |
@@ -1030,8 +1094,9 @@ discard block |
||
| 1030 | 1094 | 'where' => array(), |
| 1031 | 1095 | ); |
| 1032 | 1096 | |
| 1033 | - if ($modSettings['postmod_active']) |
|
| 1034 | - $subject_query['where'][] = 't.approved = {int:is_approved}'; |
|
| 1097 | + if ($modSettings['postmod_active']) { |
|
| 1098 | + $subject_query['where'][] = 't.approved = {int:is_approved}'; |
|
| 1099 | + } |
|
| 1035 | 1100 | |
| 1036 | 1101 | $numTables = 0; |
| 1037 | 1102 | $prev_join = 0; |
@@ -1043,8 +1108,7 @@ discard block |
||
| 1043 | 1108 | { |
| 1044 | 1109 | $subject_query['left_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}') . ' AND subj' . $numTables . '.id_topic = t.id_topic)'; |
| 1045 | 1110 | $subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)'; |
| 1046 | - } |
|
| 1047 | - else |
|
| 1111 | + } else |
|
| 1048 | 1112 | { |
| 1049 | 1113 | $subject_query['inner_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.id_topic = ' . ($prev_join === 0 ? 't' : 'subj' . $prev_join) . '.id_topic)'; |
| 1050 | 1114 | $subject_query['where'][] = 'subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}'); |
@@ -1062,14 +1126,18 @@ discard block |
||
| 1062 | 1126 | } |
| 1063 | 1127 | $subject_query['where'][] = $userQuery; |
| 1064 | 1128 | } |
| 1065 | - if (!empty($search_params['topic'])) |
|
| 1066 | - $subject_query['where'][] = 't.id_topic = ' . $search_params['topic']; |
|
| 1067 | - if (!empty($minMsgID)) |
|
| 1068 | - $subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID; |
|
| 1069 | - if (!empty($maxMsgID)) |
|
| 1070 | - $subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID; |
|
| 1071 | - if (!empty($boardQuery)) |
|
| 1072 | - $subject_query['where'][] = 't.id_board ' . $boardQuery; |
|
| 1129 | + if (!empty($search_params['topic'])) { |
|
| 1130 | + $subject_query['where'][] = 't.id_topic = ' . $search_params['topic']; |
|
| 1131 | + } |
|
| 1132 | + if (!empty($minMsgID)) { |
|
| 1133 | + $subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID; |
|
| 1134 | + } |
|
| 1135 | + if (!empty($maxMsgID)) { |
|
| 1136 | + $subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID; |
|
| 1137 | + } |
|
| 1138 | + if (!empty($boardQuery)) { |
|
| 1139 | + $subject_query['where'][] = 't.id_board ' . $boardQuery; |
|
| 1140 | + } |
|
| 1073 | 1141 | if (!empty($excludedPhrases)) |
| 1074 | 1142 | { |
| 1075 | 1143 | if ($subject_query['from'] != '{db_prefix}messages AS m') |
@@ -1089,8 +1157,9 @@ discard block |
||
| 1089 | 1157 | foreach ($weight_factors as $type => $value) |
| 1090 | 1158 | { |
| 1091 | 1159 | $relevance .= $weight[$type]; |
| 1092 | - if (!empty($value['results'])) |
|
| 1093 | - $relevance .= ' * ' . $value['results']; |
|
| 1160 | + if (!empty($value['results'])) { |
|
| 1161 | + $relevance .= ' * ' . $value['results']; |
|
| 1162 | + } |
|
| 1094 | 1163 | $relevance .= ' + '; |
| 1095 | 1164 | } |
| 1096 | 1165 | $relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance'; |
@@ -1128,20 +1197,23 @@ discard block |
||
| 1128 | 1197 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
| 1129 | 1198 | { |
| 1130 | 1199 | // No duplicates! |
| 1131 | - if (isset($inserts[$row[1]])) |
|
| 1132 | - continue; |
|
| 1200 | + if (isset($inserts[$row[1]])) { |
|
| 1201 | + continue; |
|
| 1202 | + } |
|
| 1133 | 1203 | |
| 1134 | - foreach ($row as $key => $value) |
|
| 1135 | - $inserts[$row[1]][] = (int) $row[$key]; |
|
| 1204 | + foreach ($row as $key => $value) { |
|
| 1205 | + $inserts[$row[1]][] = (int) $row[$key]; |
|
| 1206 | + } |
|
| 1136 | 1207 | } |
| 1137 | 1208 | $smcFunc['db_free_result']($ignoreRequest); |
| 1138 | 1209 | $numSubjectResults = count($inserts); |
| 1210 | + } else { |
|
| 1211 | + $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
| 1139 | 1212 | } |
| 1140 | - else |
|
| 1141 | - $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
| 1142 | 1213 | |
| 1143 | - if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) |
|
| 1144 | - break; |
|
| 1214 | + if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) { |
|
| 1215 | + break; |
|
| 1216 | + } |
|
| 1145 | 1217 | } |
| 1146 | 1218 | |
| 1147 | 1219 | // If there's data to be inserted for non-IGNORE databases do it here! |
@@ -1156,8 +1228,7 @@ discard block |
||
| 1156 | 1228 | } |
| 1157 | 1229 | |
| 1158 | 1230 | $_SESSION['search_cache']['num_results'] = $numSubjectResults; |
| 1159 | - } |
|
| 1160 | - else |
|
| 1231 | + } else |
|
| 1161 | 1232 | { |
| 1162 | 1233 | $main_query = array( |
| 1163 | 1234 | 'select' => array( |
@@ -1189,8 +1260,7 @@ discard block |
||
| 1189 | 1260 | $main_query['weights'] = $weight_factors; |
| 1190 | 1261 | |
| 1191 | 1262 | $main_query['group_by'][] = 't.id_topic'; |
| 1192 | - } |
|
| 1193 | - else |
|
| 1263 | + } else |
|
| 1194 | 1264 | { |
| 1195 | 1265 | // This is outrageous! |
| 1196 | 1266 | $main_query['select']['id_topic'] = 'm.id_msg AS id_topic'; |
@@ -1211,8 +1281,9 @@ discard block |
||
| 1211 | 1281 | $main_query['where'][] = 't.id_topic = {int:topic}'; |
| 1212 | 1282 | $main_query['parameters']['topic'] = $search_params['topic']; |
| 1213 | 1283 | } |
| 1214 | - if (!empty($search_params['show_complete'])) |
|
| 1215 | - $main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg'; |
|
| 1284 | + if (!empty($search_params['show_complete'])) { |
|
| 1285 | + $main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg'; |
|
| 1286 | + } |
|
| 1216 | 1287 | } |
| 1217 | 1288 | |
| 1218 | 1289 | // *** Get the subject results. |
@@ -1239,14 +1310,15 @@ discard block |
||
| 1239 | 1310 | ) !== false; |
| 1240 | 1311 | |
| 1241 | 1312 | // Clean up some previous cache. |
| 1242 | - if (!$createTemporary) |
|
| 1243 | - $smcFunc['db_search_query']('delete_log_search_topics', ' |
|
| 1313 | + if (!$createTemporary) { |
|
| 1314 | + $smcFunc['db_search_query']('delete_log_search_topics', ' |
|
| 1244 | 1315 | DELETE FROM {db_prefix}log_search_topics |
| 1245 | 1316 | WHERE id_search = {int:search_id}', |
| 1246 | 1317 | array( |
| 1247 | 1318 | 'search_id' => $_SESSION['search_cache']['id_search'], |
| 1248 | 1319 | ) |
| 1249 | 1320 | ); |
| 1321 | + } |
|
| 1250 | 1322 | |
| 1251 | 1323 | foreach ($searchWords as $orIndex => $words) |
| 1252 | 1324 | { |
@@ -1278,8 +1350,7 @@ discard block |
||
| 1278 | 1350 | $subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)'; |
| 1279 | 1351 | $subject_query['where'][] = 'm.body NOT ' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:body_not_' . $count . '}'; |
| 1280 | 1352 | $subject_query['params']['body_not_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($subjectWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $subjectWord), '\\\'') . '[[:>:]]'; |
| 1281 | - } |
|
| 1282 | - else |
|
| 1353 | + } else |
|
| 1283 | 1354 | { |
| 1284 | 1355 | $subject_query['inner_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.id_topic = ' . ($prev_join === 0 ? 't' : 'subj' . $prev_join) . '.id_topic)'; |
| 1285 | 1356 | $subject_query['where'][] = 'subj' . $numTables . '.word LIKE {string:subject_like_' . $count . '}'; |
@@ -1334,8 +1405,9 @@ discard block |
||
| 1334 | 1405 | call_integration_hook('integrate_subject_search_query', array(&$subject_query)); |
| 1335 | 1406 | |
| 1336 | 1407 | // Nothing to search for? |
| 1337 | - if (empty($subject_query['where'])) |
|
| 1338 | - continue; |
|
| 1408 | + if (empty($subject_query['where'])) { |
|
| 1409 | + continue; |
|
| 1410 | + } |
|
| 1339 | 1411 | |
| 1340 | 1412 | $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? ( ' |
| 1341 | 1413 | INSERT IGNORE INTO {db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics |
@@ -1358,19 +1430,21 @@ discard block |
||
| 1358 | 1430 | { |
| 1359 | 1431 | $ind = $createTemporary ? 0 : 1; |
| 1360 | 1432 | // No duplicates! |
| 1361 | - if (isset($inserts[$row[$ind]])) |
|
| 1362 | - continue; |
|
| 1433 | + if (isset($inserts[$row[$ind]])) { |
|
| 1434 | + continue; |
|
| 1435 | + } |
|
| 1363 | 1436 | |
| 1364 | 1437 | $inserts[$row[$ind]] = $row; |
| 1365 | 1438 | } |
| 1366 | 1439 | $smcFunc['db_free_result']($ignoreRequest); |
| 1367 | 1440 | $numSubjectResults = count($inserts); |
| 1441 | + } else { |
|
| 1442 | + $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
| 1368 | 1443 | } |
| 1369 | - else |
|
| 1370 | - $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
| 1371 | 1444 | |
| 1372 | - if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) |
|
| 1373 | - break; |
|
| 1445 | + if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) { |
|
| 1446 | + break; |
|
| 1447 | + } |
|
| 1374 | 1448 | } |
| 1375 | 1449 | |
| 1376 | 1450 | // Got some non-MySQL data to plonk in? |
@@ -1388,8 +1462,9 @@ discard block |
||
| 1388 | 1462 | { |
| 1389 | 1463 | $main_query['weights']['subject']['search'] = 'CASE WHEN MAX(lst.id_topic) IS NULL THEN 0 ELSE 1 END'; |
| 1390 | 1464 | $main_query['left_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics AS lst ON (' . ($createTemporary ? '' : 'lst.id_search = {int:id_search} AND ') . 'lst.id_topic = t.id_topic)'; |
| 1391 | - if (!$createTemporary) |
|
| 1392 | - $main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search']; |
|
| 1465 | + if (!$createTemporary) { |
|
| 1466 | + $main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search']; |
|
| 1467 | + } |
|
| 1393 | 1468 | } |
| 1394 | 1469 | } |
| 1395 | 1470 | |
@@ -1417,14 +1492,15 @@ discard block |
||
| 1417 | 1492 | ) !== false; |
| 1418 | 1493 | |
| 1419 | 1494 | // Clear, all clear! |
| 1420 | - if (!$createTemporary) |
|
| 1421 | - $smcFunc['db_search_query']('delete_log_search_messages', ' |
|
| 1495 | + if (!$createTemporary) { |
|
| 1496 | + $smcFunc['db_search_query']('delete_log_search_messages', ' |
|
| 1422 | 1497 | DELETE FROM {db_prefix}log_search_messages |
| 1423 | 1498 | WHERE id_search = {int:id_search}', |
| 1424 | 1499 | array( |
| 1425 | 1500 | 'id_search' => $_SESSION['search_cache']['id_search'], |
| 1426 | 1501 | ) |
| 1427 | 1502 | ); |
| 1503 | + } |
|
| 1428 | 1504 | |
| 1429 | 1505 | foreach ($searchWords as $orIndex => $words) |
| 1430 | 1506 | { |
@@ -1458,19 +1534,21 @@ discard block |
||
| 1458 | 1534 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
| 1459 | 1535 | { |
| 1460 | 1536 | // No duplicates! |
| 1461 | - if (isset($inserts[$row[0]])) |
|
| 1462 | - continue; |
|
| 1537 | + if (isset($inserts[$row[0]])) { |
|
| 1538 | + continue; |
|
| 1539 | + } |
|
| 1463 | 1540 | |
| 1464 | 1541 | $inserts[$row[0]] = $row; |
| 1465 | 1542 | } |
| 1466 | 1543 | $smcFunc['db_free_result']($ignoreRequest); |
| 1467 | 1544 | $indexedResults = count($inserts); |
| 1545 | + } else { |
|
| 1546 | + $indexedResults += $smcFunc['db_affected_rows'](); |
|
| 1468 | 1547 | } |
| 1469 | - else |
|
| 1470 | - $indexedResults += $smcFunc['db_affected_rows'](); |
|
| 1471 | 1548 | |
| 1472 | - if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults) |
|
| 1473 | - break; |
|
| 1549 | + if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults) { |
|
| 1550 | + break; |
|
| 1551 | + } |
|
| 1474 | 1552 | } |
| 1475 | 1553 | } |
| 1476 | 1554 | |
@@ -1490,8 +1568,7 @@ discard block |
||
| 1490 | 1568 | $context['search_errors']['query_not_specific_enough'] = true; |
| 1491 | 1569 | $_REQUEST['params'] = $context['params']; |
| 1492 | 1570 | return PlushSearch1(); |
| 1493 | - } |
|
| 1494 | - elseif (!empty($indexedResults)) |
|
| 1571 | + } elseif (!empty($indexedResults)) |
|
| 1495 | 1572 | { |
| 1496 | 1573 | $main_query['inner_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_messages AS lsm ON (lsm.id_msg = m.id_msg)'; |
| 1497 | 1574 | if (!$createTemporary) |
@@ -1513,15 +1590,18 @@ discard block |
||
| 1513 | 1590 | foreach ($words['all_words'] as $regularWord) |
| 1514 | 1591 | { |
| 1515 | 1592 | $where[] = 'm.body' . (in_array($regularWord, $excludedWords) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}'; |
| 1516 | - if (in_array($regularWord, $excludedWords)) |
|
| 1517 | - $where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}'; |
|
| 1593 | + if (in_array($regularWord, $excludedWords)) { |
|
| 1594 | + $where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}'; |
|
| 1595 | + } |
|
| 1518 | 1596 | $main_query['parameters']['all_word_body_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
| 1519 | 1597 | } |
| 1520 | - if (!empty($where)) |
|
| 1521 | - $orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0]; |
|
| 1598 | + if (!empty($where)) { |
|
| 1599 | + $orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0]; |
|
| 1600 | + } |
|
| 1601 | + } |
|
| 1602 | + if (!empty($orWhere)) { |
|
| 1603 | + $main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0]; |
|
| 1522 | 1604 | } |
| 1523 | - if (!empty($orWhere)) |
|
| 1524 | - $main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0]; |
|
| 1525 | 1605 | |
| 1526 | 1606 | if (!empty($userQuery)) |
| 1527 | 1607 | { |
@@ -1559,8 +1639,9 @@ discard block |
||
| 1559 | 1639 | foreach ($main_query['weights'] as $type => $value) |
| 1560 | 1640 | { |
| 1561 | 1641 | $relevance .= $weight[$type]; |
| 1562 | - if (!empty($value['search'])) |
|
| 1563 | - $relevance .= ' * ' . $value['search']; |
|
| 1642 | + if (!empty($value['search'])) { |
|
| 1643 | + $relevance .= ' * ' . $value['search']; |
|
| 1644 | + } |
|
| 1564 | 1645 | $relevance .= ' + '; |
| 1565 | 1646 | $new_weight_total += $weight[$type]; |
| 1566 | 1647 | } |
@@ -1591,11 +1672,13 @@ discard block |
||
| 1591 | 1672 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
| 1592 | 1673 | { |
| 1593 | 1674 | // No duplicates! |
| 1594 | - if (isset($inserts[$row[2]])) |
|
| 1595 | - continue; |
|
| 1675 | + if (isset($inserts[$row[2]])) { |
|
| 1676 | + continue; |
|
| 1677 | + } |
|
| 1596 | 1678 | |
| 1597 | - foreach ($row as $key => $value) |
|
| 1598 | - $inserts[$row[2]][] = (int) $row[$key]; |
|
| 1679 | + foreach ($row as $key => $value) { |
|
| 1680 | + $inserts[$row[2]][] = (int) $row[$key]; |
|
| 1681 | + } |
|
| 1599 | 1682 | } |
| 1600 | 1683 | $smcFunc['db_free_result']($ignoreRequest); |
| 1601 | 1684 | |
@@ -1603,8 +1686,9 @@ discard block |
||
| 1603 | 1686 | if (!empty($inserts)) |
| 1604 | 1687 | { |
| 1605 | 1688 | $query_columns = array(); |
| 1606 | - foreach ($main_query['select'] as $k => $v) |
|
| 1607 | - $query_columns[$k] = 'int'; |
|
| 1689 | + foreach ($main_query['select'] as $k => $v) { |
|
| 1690 | + $query_columns[$k] = 'int'; |
|
| 1691 | + } |
|
| 1608 | 1692 | |
| 1609 | 1693 | $smcFunc['db_insert']('', |
| 1610 | 1694 | '{db_prefix}log_search_results', |
@@ -1614,21 +1698,23 @@ discard block |
||
| 1614 | 1698 | ); |
| 1615 | 1699 | } |
| 1616 | 1700 | $_SESSION['search_cache']['num_results'] += count($inserts); |
| 1701 | + } else { |
|
| 1702 | + $_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows'](); |
|
| 1617 | 1703 | } |
| 1618 | - else |
|
| 1619 | - $_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows'](); |
|
| 1620 | 1704 | } |
| 1621 | 1705 | |
| 1622 | 1706 | // Insert subject-only matches. |
| 1623 | 1707 | if ($_SESSION['search_cache']['num_results'] < $modSettings['search_max_results'] && $numSubjectResults !== 0) |
| 1624 | 1708 | { |
| 1625 | 1709 | $relevance = '1000 * ('; |
| 1626 | - foreach ($weight_factors as $type => $value) |
|
| 1627 | - if (isset($value['results'])) |
|
| 1710 | + foreach ($weight_factors as $type => $value) { |
|
| 1711 | + if (isset($value['results'])) |
|
| 1628 | 1712 | { |
| 1629 | 1713 | $relevance .= $weight[$type]; |
| 1630 | - if (!empty($value['results'])) |
|
| 1631 | - $relevance .= ' * ' . $value['results']; |
|
| 1714 | + } |
|
| 1715 | + if (!empty($value['results'])) { |
|
| 1716 | + $relevance .= ' * ' . $value['results']; |
|
| 1717 | + } |
|
| 1632 | 1718 | $relevance .= ' + '; |
| 1633 | 1719 | } |
| 1634 | 1720 | $relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance'; |
@@ -1662,8 +1748,9 @@ discard block |
||
| 1662 | 1748 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
| 1663 | 1749 | { |
| 1664 | 1750 | // No duplicates! |
| 1665 | - if (isset($usedIDs[$row[1]])) |
|
| 1666 | - continue; |
|
| 1751 | + if (isset($usedIDs[$row[1]])) { |
|
| 1752 | + continue; |
|
| 1753 | + } |
|
| 1667 | 1754 | |
| 1668 | 1755 | $usedIDs[$row[1]] = true; |
| 1669 | 1756 | $inserts[] = $row; |
@@ -1681,12 +1768,12 @@ discard block |
||
| 1681 | 1768 | ); |
| 1682 | 1769 | } |
| 1683 | 1770 | $_SESSION['search_cache']['num_results'] += count($inserts); |
| 1771 | + } else { |
|
| 1772 | + $_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows'](); |
|
| 1684 | 1773 | } |
| 1685 | - else |
|
| 1686 | - $_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows'](); |
|
| 1774 | + } elseif ($_SESSION['search_cache']['num_results'] == -1) { |
|
| 1775 | + $_SESSION['search_cache']['num_results'] = 0; |
|
| 1687 | 1776 | } |
| 1688 | - elseif ($_SESSION['search_cache']['num_results'] == -1) |
|
| 1689 | - $_SESSION['search_cache']['num_results'] = 0; |
|
| 1690 | 1777 | } |
| 1691 | 1778 | } |
| 1692 | 1779 | |
@@ -1756,14 +1843,16 @@ discard block |
||
| 1756 | 1843 | ) |
| 1757 | 1844 | ); |
| 1758 | 1845 | $posters = array(); |
| 1759 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1760 | - $posters[] = $row['id_member']; |
|
| 1846 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1847 | + $posters[] = $row['id_member']; |
|
| 1848 | + } |
|
| 1761 | 1849 | $smcFunc['db_free_result']($request); |
| 1762 | 1850 | |
| 1763 | 1851 | call_integration_hook('integrate_search_message_list', array(&$msg_list, &$posters)); |
| 1764 | 1852 | |
| 1765 | - if (!empty($posters)) |
|
| 1766 | - loadMemberData(array_unique($posters)); |
|
| 1853 | + if (!empty($posters)) { |
|
| 1854 | + loadMemberData(array_unique($posters)); |
|
| 1855 | + } |
|
| 1767 | 1856 | |
| 1768 | 1857 | // Get the messages out for the callback - select enough that it can be made to look just like Display. |
| 1769 | 1858 | $messages_request = $smcFunc['db_query']('', ' |
@@ -1797,8 +1886,9 @@ discard block |
||
| 1797 | 1886 | ); |
| 1798 | 1887 | |
| 1799 | 1888 | // If there are no results that means the things in the cache got deleted, so pretend we have no topics anymore. |
| 1800 | - if ($smcFunc['db_num_rows']($messages_request) == 0) |
|
| 1801 | - $context['topics'] = array(); |
|
| 1889 | + if ($smcFunc['db_num_rows']($messages_request) == 0) { |
|
| 1890 | + $context['topics'] = array(); |
|
| 1891 | + } |
|
| 1802 | 1892 | |
| 1803 | 1893 | // If we want to know who participated in what then load this now. |
| 1804 | 1894 | if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest']) |
@@ -1816,8 +1906,9 @@ discard block |
||
| 1816 | 1906 | 'limit' => count($participants), |
| 1817 | 1907 | ) |
| 1818 | 1908 | ); |
| 1819 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
| 1820 | - $participants[$row['id_topic']] = true; |
|
| 1909 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
| 1910 | + $participants[$row['id_topic']] = true; |
|
| 1911 | + } |
|
| 1821 | 1912 | $smcFunc['db_free_result']($result); |
| 1822 | 1913 | } |
| 1823 | 1914 | } |
@@ -1826,15 +1917,17 @@ discard block |
||
| 1826 | 1917 | $context['page_index'] = constructPageIndex($scripturl . '?action=search2;params=' . $context['params'], $_REQUEST['start'], $num_results, $modSettings['search_results_per_page'], false); |
| 1827 | 1918 | |
| 1828 | 1919 | // Consider the search complete! |
| 1829 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 1830 | - cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90); |
|
| 1920 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 1921 | + cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90); |
|
| 1922 | + } |
|
| 1831 | 1923 | |
| 1832 | 1924 | $context['key_words'] = &$searchArray; |
| 1833 | 1925 | |
| 1834 | 1926 | // Setup the default topic icons... for checking they exist and the like! |
| 1835 | 1927 | $context['icon_sources'] = array(); |
| 1836 | - foreach ($context['stable_icons'] as $icon) |
|
| 1837 | - $context['icon_sources'][$icon] = 'images_url'; |
|
| 1928 | + foreach ($context['stable_icons'] as $icon) { |
|
| 1929 | + $context['icon_sources'][$icon] = 'images_url'; |
|
| 1930 | + } |
|
| 1838 | 1931 | |
| 1839 | 1932 | $context['sub_template'] = 'results'; |
| 1840 | 1933 | $context['page_title'] = $txt['search_results']; |
@@ -1865,26 +1958,31 @@ discard block |
||
| 1865 | 1958 | global $boards_can, $participants, $smcFunc; |
| 1866 | 1959 | static $recycle_board = null; |
| 1867 | 1960 | |
| 1868 | - if ($recycle_board === null) |
|
| 1869 | - $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
|
| 1961 | + if ($recycle_board === null) { |
|
| 1962 | + $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
|
| 1963 | + } |
|
| 1870 | 1964 | |
| 1871 | 1965 | // Remember which message this is. (ie. reply #83) |
| 1872 | 1966 | static $counter = null; |
| 1873 | - if ($counter == null || $reset) |
|
| 1874 | - $counter = $_REQUEST['start'] + 1; |
|
| 1967 | + if ($counter == null || $reset) { |
|
| 1968 | + $counter = $_REQUEST['start'] + 1; |
|
| 1969 | + } |
|
| 1875 | 1970 | |
| 1876 | 1971 | // If the query returned false, bail. |
| 1877 | - if ($messages_request == false) |
|
| 1878 | - return false; |
|
| 1972 | + if ($messages_request == false) { |
|
| 1973 | + return false; |
|
| 1974 | + } |
|
| 1879 | 1975 | |
| 1880 | 1976 | // Start from the beginning... |
| 1881 | - if ($reset) |
|
| 1882 | - return @$smcFunc['db_data_seek']($messages_request, 0); |
|
| 1977 | + if ($reset) { |
|
| 1978 | + return @$smcFunc['db_data_seek']($messages_request, 0); |
|
| 1979 | + } |
|
| 1883 | 1980 | |
| 1884 | 1981 | // Attempt to get the next message. |
| 1885 | 1982 | $message = $smcFunc['db_fetch_assoc']($messages_request); |
| 1886 | - if (!$message) |
|
| 1887 | - return false; |
|
| 1983 | + if (!$message) { |
|
| 1984 | + return false; |
|
| 1985 | + } |
|
| 1888 | 1986 | |
| 1889 | 1987 | // Can't have an empty subject can we? |
| 1890 | 1988 | $message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject']; |
@@ -1923,9 +2021,9 @@ discard block |
||
| 1923 | 2021 | |
| 1924 | 2022 | if ($smcFunc['strlen']($message['body']) > $charLimit) |
| 1925 | 2023 | { |
| 1926 | - if (empty($context['key_words'])) |
|
| 1927 | - $message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>'; |
|
| 1928 | - else |
|
| 2024 | + if (empty($context['key_words'])) { |
|
| 2025 | + $message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>'; |
|
| 2026 | + } else |
|
| 1929 | 2027 | { |
| 1930 | 2028 | $matchString = ''; |
| 1931 | 2029 | $force_partial_word = false; |
@@ -1934,18 +2032,20 @@ discard block |
||
| 1934 | 2032 | $keyword = un_htmlspecialchars($keyword); |
| 1935 | 2033 | $keyword = preg_replace_callback('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', strtr($keyword, array('\\\'' => '\'', '&' => '&'))); |
| 1936 | 2034 | |
| 1937 | - if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0) |
|
| 1938 | - $force_partial_word = true; |
|
| 2035 | + if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0) { |
|
| 2036 | + $force_partial_word = true; |
|
| 2037 | + } |
|
| 1939 | 2038 | $matchString .= strtr(preg_quote($keyword, '/'), array('\*' => '.+?')) . '|'; |
| 1940 | 2039 | } |
| 1941 | 2040 | $matchString = un_htmlspecialchars(substr($matchString, 0, -1)); |
| 1942 | 2041 | |
| 1943 | 2042 | $message['body'] = un_htmlspecialchars(strtr($message['body'], array(' ' => ' ', '<br>' => "\n", '[' => '[', ']' => ']', ':' => ':', '@' => '@'))); |
| 1944 | 2043 | |
| 1945 | - if (empty($modSettings['search_method']) || $force_partial_word) |
|
| 1946 | - preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches); |
|
| 1947 | - else |
|
| 1948 | - preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches); |
|
| 2044 | + if (empty($modSettings['search_method']) || $force_partial_word) { |
|
| 2045 | + preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches); |
|
| 2046 | + } else { |
|
| 2047 | + preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches); |
|
| 2048 | + } |
|
| 1949 | 2049 | |
| 1950 | 2050 | $message['body'] = ''; |
| 1951 | 2051 | foreach ($matches[0] as $index => $match) |
@@ -1958,8 +2058,7 @@ discard block |
||
| 1958 | 2058 | // Re-fix the international characters. |
| 1959 | 2059 | $message['body'] = preg_replace_callback('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', $message['body']); |
| 1960 | 2060 | } |
| 1961 | - } |
|
| 1962 | - else |
|
| 2061 | + } else |
|
| 1963 | 2062 | { |
| 1964 | 2063 | // Run BBC interpreter on the message. |
| 1965 | 2064 | $message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']); |
@@ -1978,21 +2077,26 @@ discard block |
||
| 1978 | 2077 | // Sadly, we need to check the icon ain't broke. |
| 1979 | 2078 | if (!empty($modSettings['messageIconChecks_enable'])) |
| 1980 | 2079 | { |
| 1981 | - if (!isset($context['icon_sources'][$message['first_icon']])) |
|
| 1982 | - $context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1983 | - if (!isset($context['icon_sources'][$message['last_icon']])) |
|
| 1984 | - $context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1985 | - if (!isset($context['icon_sources'][$message['icon']])) |
|
| 1986 | - $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1987 | - } |
|
| 1988 | - else |
|
| 2080 | + if (!isset($context['icon_sources'][$message['first_icon']])) { |
|
| 2081 | + $context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 2082 | + } |
|
| 2083 | + if (!isset($context['icon_sources'][$message['last_icon']])) { |
|
| 2084 | + $context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 2085 | + } |
|
| 2086 | + if (!isset($context['icon_sources'][$message['icon']])) { |
|
| 2087 | + $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 2088 | + } |
|
| 2089 | + } else |
|
| 1989 | 2090 | { |
| 1990 | - if (!isset($context['icon_sources'][$message['first_icon']])) |
|
| 1991 | - $context['icon_sources'][$message['first_icon']] = 'images_url'; |
|
| 1992 | - if (!isset($context['icon_sources'][$message['last_icon']])) |
|
| 1993 | - $context['icon_sources'][$message['last_icon']] = 'images_url'; |
|
| 1994 | - if (!isset($context['icon_sources'][$message['icon']])) |
|
| 1995 | - $context['icon_sources'][$message['icon']] = 'images_url'; |
|
| 2091 | + if (!isset($context['icon_sources'][$message['first_icon']])) { |
|
| 2092 | + $context['icon_sources'][$message['first_icon']] = 'images_url'; |
|
| 2093 | + } |
|
| 2094 | + if (!isset($context['icon_sources'][$message['last_icon']])) { |
|
| 2095 | + $context['icon_sources'][$message['last_icon']] = 'images_url'; |
|
| 2096 | + } |
|
| 2097 | + if (!isset($context['icon_sources'][$message['icon']])) { |
|
| 2098 | + $context['icon_sources'][$message['icon']] = 'images_url'; |
|
| 2099 | + } |
|
| 1996 | 2100 | } |
| 1997 | 2101 | |
| 1998 | 2102 | // Do we have quote tag enabled? |
@@ -2002,12 +2106,14 @@ discard block |
||
| 2002 | 2106 | $colorClass = 'windowbg'; |
| 2003 | 2107 | |
| 2004 | 2108 | // Sticky topics should get a different color, too. |
| 2005 | - if ($message['is_sticky']) |
|
| 2006 | - $colorClass .= ' sticky'; |
|
| 2109 | + if ($message['is_sticky']) { |
|
| 2110 | + $colorClass .= ' sticky'; |
|
| 2111 | + } |
|
| 2007 | 2112 | |
| 2008 | 2113 | // Locked topics get special treatment as well. |
| 2009 | - if ($message['locked']) |
|
| 2010 | - $colorClass .= ' locked'; |
|
| 2114 | + if ($message['locked']) { |
|
| 2115 | + $colorClass .= ' locked'; |
|
| 2116 | + } |
|
| 2011 | 2117 | |
| 2012 | 2118 | $output = array_merge($context['topics'][$message['id_msg']], array( |
| 2013 | 2119 | 'id' => $message['id_topic'], |
@@ -2151,8 +2257,9 @@ discard block |
||
| 2151 | 2257 | |
| 2152 | 2258 | // Load up the search API we are going to use. |
| 2153 | 2259 | $modSettings['search_index'] = empty($modSettings['search_index']) ? 'standard' : $modSettings['search_index']; |
| 2154 | - if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php')) |
|
| 2155 | - fatal_lang_error('search_api_missing'); |
|
| 2260 | + if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php')) { |
|
| 2261 | + fatal_lang_error('search_api_missing'); |
|
| 2262 | + } |
|
| 2156 | 2263 | require_once($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php'); |
| 2157 | 2264 | |
| 2158 | 2265 | // Create an instance of the search API and check it is valid for this version of SMF. |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Add the file functions to the $smcFunc array. |
@@ -52,8 +53,9 @@ discard block |
||
| 52 | 53 | 'messages', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages', |
| 53 | 54 | 'pm_recipients', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys', |
| 54 | 55 | 'themes', 'topics'); |
| 55 | - foreach ($reservedTables as $k => $table_name) |
|
| 56 | - $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
| 56 | + foreach ($reservedTables as $k => $table_name) { |
|
| 57 | + $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
| 58 | + } |
|
| 57 | 59 | |
| 58 | 60 | // We in turn may need the extra stuff. |
| 59 | 61 | db_extend('extra'); |
@@ -105,8 +107,9 @@ discard block |
||
| 105 | 107 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 106 | 108 | |
| 107 | 109 | // First - no way do we touch SMF tables. |
| 108 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
| 109 | - return false; |
|
| 110 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
| 111 | + return false; |
|
| 112 | + } |
|
| 110 | 113 | |
| 111 | 114 | // Log that we'll want to remove this on uninstall. |
| 112 | 115 | $db_package_log[] = array('remove_table', $table_name); |
@@ -116,16 +119,18 @@ discard block |
||
| 116 | 119 | if (in_array($full_table_name, $tables)) |
| 117 | 120 | { |
| 118 | 121 | // This is a sad day... drop the table? If not, return false (error) by default. |
| 119 | - if ($if_exists == 'overwrite') |
|
| 120 | - $smcFunc['db_drop_table']($table_name); |
|
| 121 | - else |
|
| 122 | - return $if_exists == 'ignore'; |
|
| 122 | + if ($if_exists == 'overwrite') { |
|
| 123 | + $smcFunc['db_drop_table']($table_name); |
|
| 124 | + } else { |
|
| 125 | + return $if_exists == 'ignore'; |
|
| 126 | + } |
|
| 123 | 127 | } |
| 124 | 128 | |
| 125 | 129 | // Righty - let's do the damn thing! |
| 126 | 130 | $table_query = 'CREATE TABLE ' . $table_name . "\n" . '('; |
| 127 | - foreach ($columns as $column) |
|
| 128 | - $table_query .= "\n\t" . smf_db_create_query_column($column) . ','; |
|
| 131 | + foreach ($columns as $column) { |
|
| 132 | + $table_query .= "\n\t" . smf_db_create_query_column($column) . ','; |
|
| 133 | + } |
|
| 129 | 134 | |
| 130 | 135 | // Loop through the indexes next... |
| 131 | 136 | foreach ($indexes as $index) |
@@ -133,19 +138,21 @@ discard block |
||
| 133 | 138 | $columns = implode(',', $index['columns']); |
| 134 | 139 | |
| 135 | 140 | // Is it the primary? |
| 136 | - if (isset($index['type']) && $index['type'] == 'primary') |
|
| 137 | - $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
| 138 | - else |
|
| 141 | + if (isset($index['type']) && $index['type'] == 'primary') { |
|
| 142 | + $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
| 143 | + } else |
|
| 139 | 144 | { |
| 140 | - if (empty($index['name'])) |
|
| 141 | - $index['name'] = implode('_', $index['columns']); |
|
| 145 | + if (empty($index['name'])) { |
|
| 146 | + $index['name'] = implode('_', $index['columns']); |
|
| 147 | + } |
|
| 142 | 148 | $table_query .= "\n\t" . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : 'KEY') . ' ' . $index['name'] . ' (' . $columns . '),'; |
| 143 | 149 | } |
| 144 | 150 | } |
| 145 | 151 | |
| 146 | 152 | // No trailing commas! |
| 147 | - if (substr($table_query, -1) == ',') |
|
| 148 | - $table_query = substr($table_query, 0, -1); |
|
| 153 | + if (substr($table_query, -1) == ',') { |
|
| 154 | + $table_query = substr($table_query, 0, -1); |
|
| 155 | + } |
|
| 149 | 156 | |
| 150 | 157 | // Which engine do we want here? |
| 151 | 158 | if (empty($engines)) |
@@ -155,8 +162,9 @@ discard block |
||
| 155 | 162 | |
| 156 | 163 | while ($row = $smcFunc['db_fetch_assoc']($get_engines)) |
| 157 | 164 | { |
| 158 | - if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') |
|
| 159 | - $engines[] = $row['Engine']; |
|
| 165 | + if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') { |
|
| 166 | + $engines[] = $row['Engine']; |
|
| 167 | + } |
|
| 160 | 168 | } |
| 161 | 169 | |
| 162 | 170 | $smcFunc['db_free_result']($get_engines); |
@@ -170,8 +178,9 @@ discard block |
||
| 170 | 178 | } |
| 171 | 179 | |
| 172 | 180 | $table_query .= ') ENGINE=' . $parameters['engine']; |
| 173 | - if (!empty($db_character_set) && $db_character_set == 'utf8') |
|
| 174 | - $table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
| 181 | + if (!empty($db_character_set) && $db_character_set == 'utf8') { |
|
| 182 | + $table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
| 183 | + } |
|
| 175 | 184 | |
| 176 | 185 | // Create the table! |
| 177 | 186 | $smcFunc['db_query']('', $table_query, |
@@ -203,8 +212,9 @@ discard block |
||
| 203 | 212 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 204 | 213 | |
| 205 | 214 | // God no - dropping one of these = bad. |
| 206 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
| 207 | - return false; |
|
| 215 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
| 216 | + return false; |
|
| 217 | + } |
|
| 208 | 218 | |
| 209 | 219 | // Does it exist? |
| 210 | 220 | if (in_array($full_table_name, $smcFunc['db_list_tables']())) |
@@ -245,14 +255,16 @@ discard block |
||
| 245 | 255 | |
| 246 | 256 | // Does it exist - if so don't add it again! |
| 247 | 257 | $columns = $smcFunc['db_list_columns']($table_name, false); |
| 248 | - foreach ($columns as $column) |
|
| 249 | - if ($column == $column_info['name']) |
|
| 258 | + foreach ($columns as $column) { |
|
| 259 | + if ($column == $column_info['name']) |
|
| 250 | 260 | { |
| 251 | 261 | // If we're going to overwrite then use change column. |
| 252 | 262 | if ($if_exists == 'update') |
| 253 | 263 | return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
| 254 | - else |
|
| 255 | - return false; |
|
| 264 | + } |
|
| 265 | + else { |
|
| 266 | + return false; |
|
| 267 | + } |
|
| 256 | 268 | } |
| 257 | 269 | |
| 258 | 270 | // Get the specifics... |
@@ -288,8 +300,8 @@ discard block |
||
| 288 | 300 | |
| 289 | 301 | // Does it exist? |
| 290 | 302 | $columns = $smcFunc['db_list_columns']($table_name, true); |
| 291 | - foreach ($columns as $column) |
|
| 292 | - if ($column['name'] == $column_name) |
|
| 303 | + foreach ($columns as $column) { |
|
| 304 | + if ($column['name'] == $column_name) |
|
| 293 | 305 | { |
| 294 | 306 | $smcFunc['db_query']('', ' |
| 295 | 307 | ALTER TABLE ' . $table_name . ' |
@@ -298,6 +310,7 @@ discard block |
||
| 298 | 310 | 'security_override' => true, |
| 299 | 311 | ) |
| 300 | 312 | ); |
| 313 | + } |
|
| 301 | 314 | |
| 302 | 315 | return true; |
| 303 | 316 | } |
@@ -323,37 +336,47 @@ discard block |
||
| 323 | 336 | // Check it does exist! |
| 324 | 337 | $columns = $smcFunc['db_list_columns']($table_name, true); |
| 325 | 338 | $old_info = null; |
| 326 | - foreach ($columns as $column) |
|
| 327 | - if ($column['name'] == $old_column) |
|
| 339 | + foreach ($columns as $column) { |
|
| 340 | + if ($column['name'] == $old_column) |
|
| 328 | 341 | $old_info = $column; |
| 342 | + } |
|
| 329 | 343 | |
| 330 | 344 | // Nothing? |
| 331 | - if ($old_info == null) |
|
| 332 | - return false; |
|
| 345 | + if ($old_info == null) { |
|
| 346 | + return false; |
|
| 347 | + } |
|
| 333 | 348 | |
| 334 | 349 | // Get the right bits. |
| 335 | - if (!isset($column_info['name'])) |
|
| 336 | - $column_info['name'] = $old_column; |
|
| 337 | - if (!isset($column_info['default'])) |
|
| 338 | - $column_info['default'] = $old_info['default']; |
|
| 339 | - if (!isset($column_info['null'])) |
|
| 340 | - $column_info['null'] = $old_info['null']; |
|
| 341 | - if (!isset($column_info['auto'])) |
|
| 342 | - $column_info['auto'] = $old_info['auto']; |
|
| 343 | - if (!isset($column_info['type'])) |
|
| 344 | - $column_info['type'] = $old_info['type']; |
|
| 345 | - if (!isset($column_info['size']) || !is_numeric($column_info['size'])) |
|
| 346 | - $column_info['size'] = $old_info['size']; |
|
| 347 | - if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) |
|
| 348 | - $column_info['unsigned'] = ''; |
|
| 350 | + if (!isset($column_info['name'])) { |
|
| 351 | + $column_info['name'] = $old_column; |
|
| 352 | + } |
|
| 353 | + if (!isset($column_info['default'])) { |
|
| 354 | + $column_info['default'] = $old_info['default']; |
|
| 355 | + } |
|
| 356 | + if (!isset($column_info['null'])) { |
|
| 357 | + $column_info['null'] = $old_info['null']; |
|
| 358 | + } |
|
| 359 | + if (!isset($column_info['auto'])) { |
|
| 360 | + $column_info['auto'] = $old_info['auto']; |
|
| 361 | + } |
|
| 362 | + if (!isset($column_info['type'])) { |
|
| 363 | + $column_info['type'] = $old_info['type']; |
|
| 364 | + } |
|
| 365 | + if (!isset($column_info['size']) || !is_numeric($column_info['size'])) { |
|
| 366 | + $column_info['size'] = $old_info['size']; |
|
| 367 | + } |
|
| 368 | + if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) { |
|
| 369 | + $column_info['unsigned'] = ''; |
|
| 370 | + } |
|
| 349 | 371 | |
| 350 | 372 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); |
| 351 | 373 | |
| 352 | 374 | // Allow for unsigned integers (mysql only) |
| 353 | 375 | $unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column_info['unsigned']) ? 'unsigned ' : ''; |
| 354 | 376 | |
| 355 | - if ($size !== null) |
|
| 356 | - $type = $type . '(' . $size . ')'; |
|
| 377 | + if ($size !== null) { |
|
| 378 | + $type = $type . '(' . $size . ')'; |
|
| 379 | + } |
|
| 357 | 380 | |
| 358 | 381 | $smcFunc['db_query']('', ' |
| 359 | 382 | ALTER TABLE ' . $table_name . ' |
@@ -383,18 +406,20 @@ discard block |
||
| 383 | 406 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 384 | 407 | |
| 385 | 408 | // No columns = no index. |
| 386 | - if (empty($index_info['columns'])) |
|
| 387 | - return false; |
|
| 409 | + if (empty($index_info['columns'])) { |
|
| 410 | + return false; |
|
| 411 | + } |
|
| 388 | 412 | $columns = implode(',', $index_info['columns']); |
| 389 | 413 | |
| 390 | 414 | // No name - make it up! |
| 391 | 415 | if (empty($index_info['name'])) |
| 392 | 416 | { |
| 393 | 417 | // No need for primary. |
| 394 | - if (isset($index_info['type']) && $index_info['type'] == 'primary') |
|
| 395 | - $index_info['name'] = ''; |
|
| 396 | - else |
|
| 397 | - $index_info['name'] = implode('_', $index_info['columns']); |
|
| 418 | + if (isset($index_info['type']) && $index_info['type'] == 'primary') { |
|
| 419 | + $index_info['name'] = ''; |
|
| 420 | + } else { |
|
| 421 | + $index_info['name'] = implode('_', $index_info['columns']); |
|
| 422 | + } |
|
| 398 | 423 | } |
| 399 | 424 | |
| 400 | 425 | // Log that we are going to want to remove this! |
@@ -408,10 +433,11 @@ discard block |
||
| 408 | 433 | if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary')) |
| 409 | 434 | { |
| 410 | 435 | // If we want to overwrite simply remove the current one then continue. |
| 411 | - if ($if_exists != 'update' || $index['type'] == 'primary') |
|
| 412 | - return false; |
|
| 413 | - else |
|
| 414 | - $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
| 436 | + if ($if_exists != 'update' || $index['type'] == 'primary') { |
|
| 437 | + return false; |
|
| 438 | + } else { |
|
| 439 | + $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
| 440 | + } |
|
| 415 | 441 | } |
| 416 | 442 | } |
| 417 | 443 | |
@@ -425,8 +451,7 @@ discard block |
||
| 425 | 451 | 'security_override' => true, |
| 426 | 452 | ) |
| 427 | 453 | ); |
| 428 | - } |
|
| 429 | - else |
|
| 454 | + } else |
|
| 430 | 455 | { |
| 431 | 456 | $smcFunc['db_query']('', ' |
| 432 | 457 | ALTER TABLE ' . $table_name . ' |
@@ -510,8 +535,7 @@ discard block |
||
| 510 | 535 | $types = array( |
| 511 | 536 | 'inet' => 'varbinary', |
| 512 | 537 | ); |
| 513 | - } |
|
| 514 | - else |
|
| 538 | + } else |
|
| 515 | 539 | { |
| 516 | 540 | $types = array( |
| 517 | 541 | 'varbinary' => 'inet', |
@@ -525,16 +549,15 @@ discard block |
||
| 525 | 549 | { |
| 526 | 550 | $type_size = 16; |
| 527 | 551 | $type_name = 'varbinary'; |
| 528 | - } |
|
| 529 | - elseif ($type_name == 'varbinary' && $reverse && $type_size == 16) |
|
| 552 | + } elseif ($type_name == 'varbinary' && $reverse && $type_size == 16) |
|
| 530 | 553 | { |
| 531 | 554 | $type_name = 'inet'; |
| 532 | 555 | $type_size = null; |
| 556 | + } elseif ($type_name == 'varbinary') { |
|
| 557 | + $type_name = 'varbinary'; |
|
| 558 | + } else { |
|
| 559 | + $type_name = $types[$type_name]; |
|
| 533 | 560 | } |
| 534 | - elseif ($type_name == 'varbinary') |
|
| 535 | - $type_name = 'varbinary'; |
|
| 536 | - else |
|
| 537 | - $type_name = $types[$type_name]; |
|
| 538 | 561 | } |
| 539 | 562 | |
| 540 | 563 | return array($type_name, $type_size); |
@@ -602,8 +625,7 @@ discard block |
||
| 602 | 625 | if (!$detail) |
| 603 | 626 | { |
| 604 | 627 | $columns[] = $row['Field']; |
| 605 | - } |
|
| 606 | - else |
|
| 628 | + } else |
|
| 607 | 629 | { |
| 608 | 630 | // Is there an auto_increment? |
| 609 | 631 | $auto = strpos($row['Extra'], 'auto_increment') !== false ? true : false; |
@@ -613,10 +635,10 @@ discard block |
||
| 613 | 635 | { |
| 614 | 636 | $type = $matches[1]; |
| 615 | 637 | $size = $matches[2]; |
| 616 | - if (!empty($matches[3]) && $matches[3] == 'unsigned') |
|
| 617 | - $unsigned = true; |
|
| 618 | - } |
|
| 619 | - else |
|
| 638 | + if (!empty($matches[3]) && $matches[3] == 'unsigned') { |
|
| 639 | + $unsigned = true; |
|
| 640 | + } |
|
| 641 | + } else |
|
| 620 | 642 | { |
| 621 | 643 | $type = $row['Type']; |
| 622 | 644 | $size = null; |
@@ -667,19 +689,20 @@ discard block |
||
| 667 | 689 | $indexes = array(); |
| 668 | 690 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 669 | 691 | { |
| 670 | - if (!$detail) |
|
| 671 | - $indexes[] = $row['Key_name']; |
|
| 672 | - else |
|
| 692 | + if (!$detail) { |
|
| 693 | + $indexes[] = $row['Key_name']; |
|
| 694 | + } else |
|
| 673 | 695 | { |
| 674 | 696 | // What is the type? |
| 675 | - if ($row['Key_name'] == 'PRIMARY') |
|
| 676 | - $type = 'primary'; |
|
| 677 | - elseif (empty($row['Non_unique'])) |
|
| 678 | - $type = 'unique'; |
|
| 679 | - elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') |
|
| 680 | - $type = 'fulltext'; |
|
| 681 | - else |
|
| 682 | - $type = 'index'; |
|
| 697 | + if ($row['Key_name'] == 'PRIMARY') { |
|
| 698 | + $type = 'primary'; |
|
| 699 | + } elseif (empty($row['Non_unique'])) { |
|
| 700 | + $type = 'unique'; |
|
| 701 | + } elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') { |
|
| 702 | + $type = 'fulltext'; |
|
| 703 | + } else { |
|
| 704 | + $type = 'index'; |
|
| 705 | + } |
|
| 683 | 706 | |
| 684 | 707 | // This is the first column we've seen? |
| 685 | 708 | if (empty($indexes[$row['Key_name']])) |
@@ -692,10 +715,11 @@ discard block |
||
| 692 | 715 | } |
| 693 | 716 | |
| 694 | 717 | // Is it a partial index? |
| 695 | - if (!empty($row['Sub_part'])) |
|
| 696 | - $indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')'; |
|
| 697 | - else |
|
| 698 | - $indexes[$row['Key_name']]['columns'][] = $row['Column_name']; |
|
| 718 | + if (!empty($row['Sub_part'])) { |
|
| 719 | + $indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')'; |
|
| 720 | + } else { |
|
| 721 | + $indexes[$row['Key_name']]['columns'][] = $row['Column_name']; |
|
| 722 | + } |
|
| 699 | 723 | } |
| 700 | 724 | } |
| 701 | 725 | $smcFunc['db_free_result']($result); |
@@ -717,11 +741,11 @@ discard block |
||
| 717 | 741 | if (!empty($column['auto'])) |
| 718 | 742 | { |
| 719 | 743 | $default = 'auto_increment'; |
| 744 | + } elseif (isset($column['default']) && $column['default'] !== null) { |
|
| 745 | + $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
| 746 | + } else { |
|
| 747 | + $default = ''; |
|
| 720 | 748 | } |
| 721 | - elseif (isset($column['default']) && $column['default'] !== null) |
|
| 722 | - $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
| 723 | - else |
|
| 724 | - $default = ''; |
|
| 725 | 749 | |
| 726 | 750 | // Sort out the size... and stuff... |
| 727 | 751 | $column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null; |
@@ -730,8 +754,9 @@ discard block |
||
| 730 | 754 | // Allow unsigned integers (mysql only) |
| 731 | 755 | $unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column['unsigned']) ? 'unsigned ' : ''; |
| 732 | 756 | |
| 733 | - if ($size !== null) |
|
| 734 | - $type = $type . '(' . $size . ')'; |
|
| 757 | + if ($size !== null) { |
|
| 758 | + $type = $type . '(' . $size . ')'; |
|
| 759 | + } |
|
| 735 | 760 | |
| 736 | 761 | // Now just put it together! |
| 737 | 762 | return '`' . $column['name'] . '` ' . $type . ' ' . (!empty($unsigned) ? $unsigned : '') . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default; |
@@ -94,12 +94,12 @@ discard block |
||
| 94 | 94 | public $headers; |
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | - * Start the curl object |
|
| 98 | - * - allow for user override values |
|
| 99 | - * |
|
| 100 | - * @param array $options An array of cURL options |
|
| 101 | - * @param int $max_redirect Maximum number of redirects |
|
| 102 | - */ |
|
| 97 | + * Start the curl object |
|
| 98 | + * - allow for user override values |
|
| 99 | + * |
|
| 100 | + * @param array $options An array of cURL options |
|
| 101 | + * @param int $max_redirect Maximum number of redirects |
|
| 102 | + */ |
|
| 103 | 103 | public function __construct($options = array(), $max_redirect = 3) |
| 104 | 104 | { |
| 105 | 105 | // Initialize class variables |
@@ -108,16 +108,16 @@ discard block |
||
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
| 111 | - * Main calling function, |
|
| 112 | - * - will request the page data from a given $url |
|
| 113 | - * - optionally will post data to the page form if post data is supplied |
|
| 114 | - * - passed arrays will be converted to a post string joined with &'s |
|
| 115 | - * - calls set_options to set the curl opts array values based on the defaults and user input |
|
| 116 | - * |
|
| 117 | - * @param string $url the site we are going to fetch |
|
| 118 | - * @param array $post_data any post data as form name => value |
|
| 119 | - * @return object An instance of the curl_fetch_web_data class |
|
| 120 | - */ |
|
| 111 | + * Main calling function, |
|
| 112 | + * - will request the page data from a given $url |
|
| 113 | + * - optionally will post data to the page form if post data is supplied |
|
| 114 | + * - passed arrays will be converted to a post string joined with &'s |
|
| 115 | + * - calls set_options to set the curl opts array values based on the defaults and user input |
|
| 116 | + * |
|
| 117 | + * @param string $url the site we are going to fetch |
|
| 118 | + * @param array $post_data any post data as form name => value |
|
| 119 | + * @return object An instance of the curl_fetch_web_data class |
|
| 120 | + */ |
|
| 121 | 121 | public function get_url_data($url, $post_data = array()) |
| 122 | 122 | { |
| 123 | 123 | // POSTing some data perhaps? |
@@ -134,14 +134,14 @@ discard block |
||
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
| 137 | - * Makes the actual cURL call |
|
| 138 | - * - stores responses (url, code, error, headers, body) in the response array |
|
| 139 | - * - detects 301, 302, 307 codes and will redirect to the given response header location |
|
| 140 | - * |
|
| 141 | - * @param string $url The site to fetch |
|
| 142 | - * @param bool $redirect Whether or not this was a redirect request |
|
| 143 | - * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
| 144 | - */ |
|
| 137 | + * Makes the actual cURL call |
|
| 138 | + * - stores responses (url, code, error, headers, body) in the response array |
|
| 139 | + * - detects 301, 302, 307 codes and will redirect to the given response header location |
|
| 140 | + * |
|
| 141 | + * @param string $url The site to fetch |
|
| 142 | + * @param bool $redirect Whether or not this was a redirect request |
|
| 143 | + * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
| 144 | + */ |
|
| 145 | 145 | private function curl_request($url, $redirect = false) |
| 146 | 146 | { |
| 147 | 147 | // we do have a url I hope |
@@ -193,12 +193,12 @@ discard block |
||
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
| 196 | - * Used if being redirected to ensure we have a fully qualified address |
|
| 197 | - * |
|
| 198 | - * @param string $last_url The URL we went to |
|
| 199 | - * @param string $new_url The URL we were redirected to |
|
| 200 | - * @return string The new URL that was in the HTTP header |
|
| 201 | - */ |
|
| 196 | + * Used if being redirected to ensure we have a fully qualified address |
|
| 197 | + * |
|
| 198 | + * @param string $last_url The URL we went to |
|
| 199 | + * @param string $new_url The URL we were redirected to |
|
| 200 | + * @return string The new URL that was in the HTTP header |
|
| 201 | + */ |
|
| 202 | 202 | private function get_redirect_url($last_url = '', $new_url = '') |
| 203 | 203 | { |
| 204 | 204 | // Get the elements for these urls |
@@ -216,13 +216,13 @@ discard block |
||
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
| 219 | - * Used to return the results to the calling program |
|
| 220 | - * - called as ->result() will return the full final array |
|
| 221 | - * - called as ->result('body') to just return the page source of the result |
|
| 222 | - * |
|
| 223 | - * @param string $area Used to return an area such as body, header, error |
|
| 224 | - * @return string The response |
|
| 225 | - */ |
|
| 219 | + * Used to return the results to the calling program |
|
| 220 | + * - called as ->result() will return the full final array |
|
| 221 | + * - called as ->result('body') to just return the page source of the result |
|
| 222 | + * |
|
| 223 | + * @param string $area Used to return an area such as body, header, error |
|
| 224 | + * @return string The response |
|
| 225 | + */ |
|
| 226 | 226 | public function result($area = '') |
| 227 | 227 | { |
| 228 | 228 | $max_result = count($this->response) - 1; |
@@ -235,13 +235,13 @@ discard block |
||
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
| 238 | - * Will return all results from all loops (redirects) |
|
| 239 | - * - Can be called as ->result_raw(x) where x is a specific loop results. |
|
| 240 | - * - Call as ->result_raw() for everything. |
|
| 241 | - * |
|
| 242 | - * @param string $response_number Which response we want to get |
|
| 243 | - * @return array|string The entire response array or just the specified response |
|
| 244 | - */ |
|
| 238 | + * Will return all results from all loops (redirects) |
|
| 239 | + * - Can be called as ->result_raw(x) where x is a specific loop results. |
|
| 240 | + * - Call as ->result_raw() for everything. |
|
| 241 | + * |
|
| 242 | + * @param string $response_number Which response we want to get |
|
| 243 | + * @return array|string The entire response array or just the specified response |
|
| 244 | + */ |
|
| 245 | 245 | public function result_raw($response_number = '') |
| 246 | 246 | { |
| 247 | 247 | if (!is_numeric($response_number)) |
@@ -254,13 +254,13 @@ discard block |
||
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
| 257 | - * Takes supplied POST data and url encodes it |
|
| 258 | - * - forms the date (for post) in to a string var=xyz&var2=abc&var3=123 |
|
| 259 | - * - drops vars with @ since we don't support sending files (uploading) |
|
| 260 | - * |
|
| 261 | - * @param array|string $post_data The raw POST data |
|
| 262 | - * @return string A string of post data |
|
| 263 | - */ |
|
| 257 | + * Takes supplied POST data and url encodes it |
|
| 258 | + * - forms the date (for post) in to a string var=xyz&var2=abc&var3=123 |
|
| 259 | + * - drops vars with @ since we don't support sending files (uploading) |
|
| 260 | + * |
|
| 261 | + * @param array|string $post_data The raw POST data |
|
| 262 | + * @return string A string of post data |
|
| 263 | + */ |
|
| 264 | 264 | private function build_post_data($post_data) |
| 265 | 265 | { |
| 266 | 266 | if (is_array($post_data)) |
@@ -279,11 +279,11 @@ discard block |
||
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
| 282 | - * Sets the final cURL options for the current call |
|
| 283 | - * - overwrites our default values with user supplied ones or appends new user ones to what we have |
|
| 284 | - * - sets the callback function now that $this is existing |
|
| 285 | - * @return void |
|
| 286 | - */ |
|
| 282 | + * Sets the final cURL options for the current call |
|
| 283 | + * - overwrites our default values with user supplied ones or appends new user ones to what we have |
|
| 284 | + * - sets the callback function now that $this is existing |
|
| 285 | + * @return void |
|
| 286 | + */ |
|
| 287 | 287 | private function set_options() |
| 288 | 288 | { |
| 289 | 289 | // Callback to parse the returned headers, if any |
@@ -308,12 +308,12 @@ discard block |
||
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | /** |
| 311 | - * Called to initiate a redirect from a 301, 302 or 307 header |
|
| 312 | - * - resets the cURL options for the loop, sets the referrer flag |
|
| 313 | - * |
|
| 314 | - * @param string $target_url The URL we want to redirect to |
|
| 315 | - * @param string $referer_url The URL that we're redirecting from |
|
| 316 | - */ |
|
| 311 | + * Called to initiate a redirect from a 301, 302 or 307 header |
|
| 312 | + * - resets the cURL options for the loop, sets the referrer flag |
|
| 313 | + * |
|
| 314 | + * @param string $target_url The URL we want to redirect to |
|
| 315 | + * @param string $referer_url The URL that we're redirecting from |
|
| 316 | + */ |
|
| 317 | 317 | private function redirect($target_url, $referer_url) |
| 318 | 318 | { |
| 319 | 319 | // no no I last saw that over there ... really, 301, 302, 307 |
@@ -10,8 +10,9 @@ discard block |
||
| 10 | 10 | * @version 2.1 Beta 3 |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -if (!defined('SMF')) |
|
| 13 | +if (!defined('SMF')) { |
|
| 14 | 14 | die('No direct access...'); |
| 15 | +} |
|
| 15 | 16 | |
| 16 | 17 | /** |
| 17 | 18 | * Class curl_fetch_web_data |
@@ -121,10 +122,11 @@ discard block |
||
| 121 | 122 | public function get_url_data($url, $post_data = array()) |
| 122 | 123 | { |
| 123 | 124 | // POSTing some data perhaps? |
| 124 | - if (!empty($post_data) && is_array($post_data)) |
|
| 125 | - $this->post_data = $this->build_post_data($post_data); |
|
| 126 | - elseif (!empty($post_data)) |
|
| 127 | - $this->post_data = trim($post_data); |
|
| 125 | + if (!empty($post_data) && is_array($post_data)) { |
|
| 126 | + $this->post_data = $this->build_post_data($post_data); |
|
| 127 | + } elseif (!empty($post_data)) { |
|
| 128 | + $this->post_data = trim($post_data); |
|
| 129 | + } |
|
| 128 | 130 | |
| 129 | 131 | // set the options and get it |
| 130 | 132 | $this->set_options(); |
@@ -145,10 +147,11 @@ discard block |
||
| 145 | 147 | private function curl_request($url, $redirect = false) |
| 146 | 148 | { |
| 147 | 149 | // we do have a url I hope |
| 148 | - if ($url == '') |
|
| 149 | - return false; |
|
| 150 | - else |
|
| 151 | - $this->options[CURLOPT_URL] = $url; |
|
| 150 | + if ($url == '') { |
|
| 151 | + return false; |
|
| 152 | + } else { |
|
| 153 | + $this->options[CURLOPT_URL] = $url; |
|
| 154 | + } |
|
| 152 | 155 | |
| 153 | 156 | // if we have not already been redirected, set it up so we can if needed |
| 154 | 157 | if (!$redirect) |
@@ -228,10 +231,11 @@ discard block |
||
| 228 | 231 | $max_result = count($this->response) - 1; |
| 229 | 232 | |
| 230 | 233 | // just return a specifed area or the entire result? |
| 231 | - if ($area == '') |
|
| 232 | - return $this->response[$max_result]; |
|
| 233 | - else |
|
| 234 | - return isset($this->response[$max_result][$area]) ? $this->response[$max_result][$area] : $this->response[$max_result]; |
|
| 234 | + if ($area == '') { |
|
| 235 | + return $this->response[$max_result]; |
|
| 236 | + } else { |
|
| 237 | + return isset($this->response[$max_result][$area]) ? $this->response[$max_result][$area] : $this->response[$max_result]; |
|
| 238 | + } |
|
| 235 | 239 | } |
| 236 | 240 | |
| 237 | 241 | /** |
@@ -244,9 +248,9 @@ discard block |
||
| 244 | 248 | */ |
| 245 | 249 | public function result_raw($response_number = '') |
| 246 | 250 | { |
| 247 | - if (!is_numeric($response_number)) |
|
| 248 | - return $this->response; |
|
| 249 | - else |
|
| 251 | + if (!is_numeric($response_number)) { |
|
| 252 | + return $this->response; |
|
| 253 | + } else |
|
| 250 | 254 | { |
| 251 | 255 | $response_number = min($response_number, count($this->response) - 1); |
| 252 | 256 | return $this->response[$response_number]; |
@@ -268,13 +272,14 @@ discard block |
||
| 268 | 272 | $postvars = array(); |
| 269 | 273 | |
| 270 | 274 | // build the post data, drop ones with leading @'s since those can be used to send files, we don't support that. |
| 271 | - foreach ($post_data as $name => $value) |
|
| 272 | - $postvars[] = $name . '=' . urlencode($value[0] == '@' ? '' : $value); |
|
| 275 | + foreach ($post_data as $name => $value) { |
|
| 276 | + $postvars[] = $name . '=' . urlencode($value[0] == '@' ? '' : $value); |
|
| 277 | + } |
|
| 273 | 278 | |
| 274 | 279 | return implode('&', $postvars); |
| 280 | + } else { |
|
| 281 | + return $post_data; |
|
| 275 | 282 | } |
| 276 | - else |
|
| 277 | - return $post_data; |
|
| 278 | 283 | |
| 279 | 284 | } |
| 280 | 285 | |
@@ -295,9 +300,9 @@ discard block |
||
| 295 | 300 | $keys = array_merge(array_keys($this->default_options), array_keys($this->user_options)); |
| 296 | 301 | $vals = array_merge($this->default_options, $this->user_options); |
| 297 | 302 | $this->options = array_combine($keys, $vals); |
| 303 | + } else { |
|
| 304 | + $this->options = $this->default_options; |
|
| 298 | 305 | } |
| 299 | - else |
|
| 300 | - $this->options = $this->default_options; |
|
| 301 | 306 | |
| 302 | 307 | // POST data options, here we don't allow any overide |
| 303 | 308 | if (isset($this->post_data)) |
@@ -32,16 +32,18 @@ discard block |
||
| 32 | 32 | ob_start(); |
| 33 | 33 | |
| 34 | 34 | // Do some cleaning, just in case. |
| 35 | -foreach (array('db_character_set', 'cachedir') as $variable) |
|
| 35 | +foreach (array('db_character_set', 'cachedir') as $variable) { |
|
| 36 | 36 | if (isset($GLOBALS[$variable])) |
| 37 | 37 | unset($GLOBALS[$variable], $GLOBALS[$variable]); |
| 38 | +} |
|
| 38 | 39 | |
| 39 | 40 | // Load the settings... |
| 40 | 41 | require_once(dirname(__FILE__) . '/Settings.php'); |
| 41 | 42 | |
| 42 | 43 | // Make absolutely sure the cache directory is defined. |
| 43 | -if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) |
|
| 44 | +if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) { |
|
| 44 | 45 | $cachedir = $boarddir . '/cache'; |
| 46 | +} |
|
| 45 | 47 | |
| 46 | 48 | // Without those we can't go anywhere |
| 47 | 49 | require_once($sourcedir . '/QueryString.php'); |
@@ -51,8 +53,9 @@ discard block |
||
| 51 | 53 | require_once($sourcedir . '/Load.php'); |
| 52 | 54 | |
| 53 | 55 | // If $maintenance is set specifically to 2, then we're upgrading or something. |
| 54 | -if (!empty($maintenance) && $maintenance == 2) |
|
| 56 | +if (!empty($maintenance) && $maintenance == 2) { |
|
| 55 | 57 | display_maintenance_message(); |
| 58 | +} |
|
| 56 | 59 | |
| 57 | 60 | // Create a variable to store some SMF specific functions in. |
| 58 | 61 | $smcFunc = array(); |
@@ -67,8 +70,9 @@ discard block |
||
| 67 | 70 | cleanRequest(); |
| 68 | 71 | |
| 69 | 72 | // Seed the random generator. |
| 70 | -if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) |
|
| 73 | +if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) { |
|
| 71 | 74 | smf_seed_generator(); |
| 75 | +} |
|
| 72 | 76 | |
| 73 | 77 | // Before we get carried away, are we doing a scheduled task? If so save CPU cycles by jumping out! |
| 74 | 78 | if (isset($_GET['scheduled'])) |
@@ -88,9 +92,9 @@ discard block |
||
| 88 | 92 | if (!empty($modSettings['enableCompressedOutput']) && !headers_sent()) |
| 89 | 93 | { |
| 90 | 94 | // If zlib is being used, turn off output compression. |
| 91 | - if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler') |
|
| 92 | - $modSettings['enableCompressedOutput'] = '0'; |
|
| 93 | - else |
|
| 95 | + if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler') { |
|
| 96 | + $modSettings['enableCompressedOutput'] = '0'; |
|
| 97 | + } else |
|
| 94 | 98 | { |
| 95 | 99 | ob_end_clean(); |
| 96 | 100 | ob_start('ob_gzhandler'); |
@@ -182,18 +186,21 @@ discard block |
||
| 182 | 186 | loadPermissions(); |
| 183 | 187 | |
| 184 | 188 | // Attachments don't require the entire theme to be loaded. |
| 185 | - if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach') |
|
| 186 | - detectBrowser(); |
|
| 189 | + if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach') { |
|
| 190 | + detectBrowser(); |
|
| 191 | + } |
|
| 187 | 192 | // Load the current theme. (note that ?theme=1 will also work, may be used for guest theming.) |
| 188 | - else |
|
| 189 | - loadTheme(); |
|
| 193 | + else { |
|
| 194 | + loadTheme(); |
|
| 195 | + } |
|
| 190 | 196 | |
| 191 | 197 | // Check if the user should be disallowed access. |
| 192 | 198 | is_not_banned(); |
| 193 | 199 | |
| 194 | 200 | // If we are in a topic and don't have permission to approve it then duck out now. |
| 195 | - if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest'])) |
|
| 196 | - fatal_lang_error('not_a_topic', false); |
|
| 201 | + if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest'])) { |
|
| 202 | + fatal_lang_error('not_a_topic', false); |
|
| 203 | + } |
|
| 197 | 204 | |
| 198 | 205 | $no_stat_actions = array('clock', 'dlattach', 'findmember', 'jsoption', 'likes', 'loadeditorlocale', 'modifycat', 'requestmembers', 'smstats', 'suggest', 'about:unknown', '.xml', 'xmlhttp', 'verificationcode', 'viewquery', 'viewsmfile'); |
| 199 | 206 | call_integration_hook('integrate_pre_log_stats', array(&$no_stat_actions)); |
@@ -204,8 +211,9 @@ discard block |
||
| 204 | 211 | writeLog(); |
| 205 | 212 | |
| 206 | 213 | // Track forum statistics and hits...? |
| 207 | - if (!empty($modSettings['hitStats'])) |
|
| 208 | - trackStats(array('hits' => '+')); |
|
| 214 | + if (!empty($modSettings['hitStats'])) { |
|
| 215 | + trackStats(array('hits' => '+')); |
|
| 216 | + } |
|
| 209 | 217 | } |
| 210 | 218 | unset($no_stat_actions); |
| 211 | 219 | |
@@ -219,13 +227,14 @@ discard block |
||
| 219 | 227 | return ($_REQUEST['action'] == 'login2' ? 'Login2' : ($_REQUEST['action'] == 'logintfa' ? 'LoginTFA' : 'Logout')); |
| 220 | 228 | } |
| 221 | 229 | // Don't even try it, sonny. |
| 222 | - else |
|
| 223 | - return 'InMaintenance'; |
|
| 230 | + else { |
|
| 231 | + return 'InMaintenance'; |
|
| 232 | + } |
|
| 224 | 233 | } |
| 225 | 234 | // If guest access is off, a guest can only do one of the very few following actions. |
| 226 | - elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2')))) |
|
| 227 | - return 'KickGuest'; |
|
| 228 | - elseif (empty($_REQUEST['action'])) |
|
| 235 | + elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2')))) { |
|
| 236 | + return 'KickGuest'; |
|
| 237 | + } elseif (empty($_REQUEST['action'])) |
|
| 229 | 238 | { |
| 230 | 239 | // Action and board are both empty... BoardIndex! Unless someone else wants to do something different. |
| 231 | 240 | if (empty($board) && empty($topic)) |
@@ -239,8 +248,9 @@ discard block |
||
| 239 | 248 | |
| 240 | 249 | $call = call_helper($defaultAction, true); |
| 241 | 250 | |
| 242 | - if (!empty($call)) |
|
| 243 | - return $call; |
|
| 251 | + if (!empty($call)) { |
|
| 252 | + return $call; |
|
| 253 | + } |
|
| 244 | 254 | } |
| 245 | 255 | |
| 246 | 256 | // No default action huh? then go to our good old BoardIndex. |
@@ -370,8 +380,9 @@ discard block |
||
| 370 | 380 | |
| 371 | 381 | $call = call_helper($fallbackAction, true); |
| 372 | 382 | |
| 373 | - if (!empty($call)) |
|
| 374 | - return $call; |
|
| 383 | + if (!empty($call)) { |
|
| 384 | + return $call; |
|
| 385 | + } |
|
| 375 | 386 | } |
| 376 | 387 | |
| 377 | 388 | // No fallback action, huh? |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | * |
| 174 | 174 | * @param string $post_errors A string of info about errors encountered trying to save this draft |
| 175 | 175 | * @param array $recipientList An array of data about who this PM is being sent to |
| 176 | - * @return boolean false if you can't save the draft, true if we're doing this via XML more than 5 seconds after the last save, nothing otherwise |
|
| 176 | + * @return boolean|null false if you can't save the draft, true if we're doing this via XML more than 5 seconds after the last save, nothing otherwise |
|
| 177 | 177 | */ |
| 178 | 178 | function SavePMDraft(&$post_errors, $recipientList) |
| 179 | 179 | { |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | * |
| 389 | 389 | * @param int $id_draft The ID of the draft to delete |
| 390 | 390 | * @param boolean $check Whether or not to check that the draft belongs to the current user |
| 391 | - * @return boolean False if it couldn't be deleted (doesn't return anything otherwise) |
|
| 391 | + * @return false|null False if it couldn't be deleted (doesn't return anything otherwise) |
|
| 392 | 392 | */ |
| 393 | 393 | function DeleteDraft($id_draft, $check = true) |
| 394 | 394 | { |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | * @param int $member_id ID of the member to show drafts for |
| 423 | 423 | * @param boolean|integer If $type is 1, this can be set to only load drafts for posts in the specific topic |
| 424 | 424 | * @param int $draft_type The type of drafts to show - 0 for post drafts, 1 for PM drafts |
| 425 | - * @return boolean False if the drafts couldn't be loaded, nothing otherwise |
|
| 425 | + * @return false|null False if the drafts couldn't be loaded, nothing otherwise |
|
| 426 | 426 | */ |
| 427 | 427 | function ShowDrafts($member_id, $topic = false, $draft_type = 0) |
| 428 | 428 | { |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | * - caches the formatting data from the setting for optimization. |
| 677 | 677 | * |
| 678 | 678 | * @param float $number A number |
| 679 | - * @param bool|int $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined |
|
| 679 | + * @param integer $override_decimal_count If set, will use the specified number of decimal places. Otherwise it's automatically determined |
|
| 680 | 680 | * @return string A formatted number |
| 681 | 681 | */ |
| 682 | 682 | function comma_format($number, $override_decimal_count = false) |
@@ -5530,7 +5530,7 @@ discard block |
||
| 5530 | 5530 | * It assumes the data is already a string. |
| 5531 | 5531 | * @param string $data The data to print |
| 5532 | 5532 | * @param string $type The content type. Defaults to Json. |
| 5533 | - * @return void |
|
| 5533 | + * @return false|null |
|
| 5534 | 5534 | */ |
| 5535 | 5535 | function smf_serverResponse($data = '', $type = 'Content-Type: application/json') |
| 5536 | 5536 | { |
@@ -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 | * Update some basic statistics. |
@@ -122,10 +123,11 @@ discard block |
||
| 122 | 123 | $smcFunc['db_free_result']($result); |
| 123 | 124 | |
| 124 | 125 | // Add this to the number of unapproved members |
| 125 | - if (!empty($changes['unapprovedMembers'])) |
|
| 126 | - $changes['unapprovedMembers'] += $coppa_approvals; |
|
| 127 | - else |
|
| 128 | - $changes['unapprovedMembers'] = $coppa_approvals; |
|
| 126 | + if (!empty($changes['unapprovedMembers'])) { |
|
| 127 | + $changes['unapprovedMembers'] += $coppa_approvals; |
|
| 128 | + } else { |
|
| 129 | + $changes['unapprovedMembers'] = $coppa_approvals; |
|
| 130 | + } |
|
| 129 | 131 | } |
| 130 | 132 | } |
| 131 | 133 | } |
@@ -133,9 +135,9 @@ discard block |
||
| 133 | 135 | break; |
| 134 | 136 | |
| 135 | 137 | case 'message': |
| 136 | - if ($parameter1 === true && $parameter2 !== null) |
|
| 137 | - updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
| 138 | - else |
|
| 138 | + if ($parameter1 === true && $parameter2 !== null) { |
|
| 139 | + updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
| 140 | + } else |
|
| 139 | 141 | { |
| 140 | 142 | // SUM and MAX on a smaller table is better for InnoDB tables. |
| 141 | 143 | $result = $smcFunc['db_query']('', ' |
@@ -175,23 +177,25 @@ discard block |
||
| 175 | 177 | $parameter2 = text2words($parameter2); |
| 176 | 178 | |
| 177 | 179 | $inserts = array(); |
| 178 | - foreach ($parameter2 as $word) |
|
| 179 | - $inserts[] = array($word, $parameter1); |
|
| 180 | + foreach ($parameter2 as $word) { |
|
| 181 | + $inserts[] = array($word, $parameter1); |
|
| 182 | + } |
|
| 180 | 183 | |
| 181 | - if (!empty($inserts)) |
|
| 182 | - $smcFunc['db_insert']('ignore', |
|
| 184 | + if (!empty($inserts)) { |
|
| 185 | + $smcFunc['db_insert']('ignore', |
|
| 183 | 186 | '{db_prefix}log_search_subjects', |
| 184 | 187 | array('word' => 'string', 'id_topic' => 'int'), |
| 185 | 188 | $inserts, |
| 186 | 189 | array('word', 'id_topic') |
| 187 | 190 | ); |
| 191 | + } |
|
| 188 | 192 | } |
| 189 | 193 | break; |
| 190 | 194 | |
| 191 | 195 | case 'topic': |
| 192 | - if ($parameter1 === true) |
|
| 193 | - updateSettings(array('totalTopics' => true), true); |
|
| 194 | - else |
|
| 196 | + if ($parameter1 === true) { |
|
| 197 | + updateSettings(array('totalTopics' => true), true); |
|
| 198 | + } else |
|
| 195 | 199 | { |
| 196 | 200 | // Get the number of topics - a SUM is better for InnoDB tables. |
| 197 | 201 | // We also ignore the recycle bin here because there will probably be a bunch of one-post topics there. |
@@ -212,8 +216,9 @@ discard block |
||
| 212 | 216 | |
| 213 | 217 | case 'postgroups': |
| 214 | 218 | // Parameter two is the updated columns: we should check to see if we base groups off any of these. |
| 215 | - if ($parameter2 !== null && !in_array('posts', $parameter2)) |
|
| 216 | - return; |
|
| 219 | + if ($parameter2 !== null && !in_array('posts', $parameter2)) { |
|
| 220 | + return; |
|
| 221 | + } |
|
| 217 | 222 | |
| 218 | 223 | $postgroups = cache_get_data('updateStats:postgroups', 360); |
| 219 | 224 | if ($postgroups == null || $parameter1 == null) |
@@ -228,8 +233,9 @@ discard block |
||
| 228 | 233 | ) |
| 229 | 234 | ); |
| 230 | 235 | $postgroups = array(); |
| 231 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 232 | - $postgroups[$row['id_group']] = $row['min_posts']; |
|
| 236 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 237 | + $postgroups[$row['id_group']] = $row['min_posts']; |
|
| 238 | + } |
|
| 233 | 239 | $smcFunc['db_free_result']($request); |
| 234 | 240 | |
| 235 | 241 | // Sort them this way because if it's done with MySQL it causes a filesort :(. |
@@ -239,8 +245,9 @@ discard block |
||
| 239 | 245 | } |
| 240 | 246 | |
| 241 | 247 | // Oh great, they've screwed their post groups. |
| 242 | - if (empty($postgroups)) |
|
| 243 | - return; |
|
| 248 | + if (empty($postgroups)) { |
|
| 249 | + return; |
|
| 250 | + } |
|
| 244 | 251 | |
| 245 | 252 | // Set all membergroups from most posts to least posts. |
| 246 | 253 | $conditions = ''; |
@@ -298,10 +305,9 @@ discard block |
||
| 298 | 305 | { |
| 299 | 306 | $condition = 'id_member IN ({array_int:members})'; |
| 300 | 307 | $parameters['members'] = $members; |
| 301 | - } |
|
| 302 | - elseif ($members === null) |
|
| 303 | - $condition = '1=1'; |
|
| 304 | - else |
|
| 308 | + } elseif ($members === null) { |
|
| 309 | + $condition = '1=1'; |
|
| 310 | + } else |
|
| 305 | 311 | { |
| 306 | 312 | $condition = 'id_member = {int:member}'; |
| 307 | 313 | $parameters['member'] = $members; |
@@ -341,9 +347,9 @@ discard block |
||
| 341 | 347 | if (count($vars_to_integrate) != 0) |
| 342 | 348 | { |
| 343 | 349 | // Fetch a list of member_names if necessary |
| 344 | - if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) |
|
| 345 | - $member_names = array($user_info['username']); |
|
| 346 | - else |
|
| 350 | + if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) { |
|
| 351 | + $member_names = array($user_info['username']); |
|
| 352 | + } else |
|
| 347 | 353 | { |
| 348 | 354 | $member_names = array(); |
| 349 | 355 | $request = $smcFunc['db_query']('', ' |
@@ -352,14 +358,16 @@ discard block |
||
| 352 | 358 | WHERE ' . $condition, |
| 353 | 359 | $parameters |
| 354 | 360 | ); |
| 355 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 356 | - $member_names[] = $row['member_name']; |
|
| 361 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 362 | + $member_names[] = $row['member_name']; |
|
| 363 | + } |
|
| 357 | 364 | $smcFunc['db_free_result']($request); |
| 358 | 365 | } |
| 359 | 366 | |
| 360 | - if (!empty($member_names)) |
|
| 361 | - foreach ($vars_to_integrate as $var) |
|
| 367 | + if (!empty($member_names)) { |
|
| 368 | + foreach ($vars_to_integrate as $var) |
|
| 362 | 369 | call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats)); |
| 370 | + } |
|
| 363 | 371 | } |
| 364 | 372 | } |
| 365 | 373 | |
@@ -367,16 +375,17 @@ discard block |
||
| 367 | 375 | foreach ($data as $var => $val) |
| 368 | 376 | { |
| 369 | 377 | $type = 'string'; |
| 370 | - if (in_array($var, $knownInts)) |
|
| 371 | - $type = 'int'; |
|
| 372 | - elseif (in_array($var, $knownFloats)) |
|
| 373 | - $type = 'float'; |
|
| 374 | - elseif ($var == 'birthdate') |
|
| 375 | - $type = 'date'; |
|
| 376 | - elseif ($var == 'member_ip') |
|
| 377 | - $type = 'inet'; |
|
| 378 | - elseif ($var == 'member_ip2') |
|
| 379 | - $type = 'inet'; |
|
| 378 | + if (in_array($var, $knownInts)) { |
|
| 379 | + $type = 'int'; |
|
| 380 | + } elseif (in_array($var, $knownFloats)) { |
|
| 381 | + $type = 'float'; |
|
| 382 | + } elseif ($var == 'birthdate') { |
|
| 383 | + $type = 'date'; |
|
| 384 | + } elseif ($var == 'member_ip') { |
|
| 385 | + $type = 'inet'; |
|
| 386 | + } elseif ($var == 'member_ip2') { |
|
| 387 | + $type = 'inet'; |
|
| 388 | + } |
|
| 380 | 389 | |
| 381 | 390 | // Doing an increment? |
| 382 | 391 | if ($type == 'int' && ($val === '+' || $val === '-')) |
@@ -390,8 +399,9 @@ discard block |
||
| 390 | 399 | { |
| 391 | 400 | if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match)) |
| 392 | 401 | { |
| 393 | - if ($match[1] != '+ ') |
|
| 394 | - $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
| 402 | + if ($match[1] != '+ ') { |
|
| 403 | + $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
| 404 | + } |
|
| 395 | 405 | $type = 'raw'; |
| 396 | 406 | } |
| 397 | 407 | } |
@@ -412,8 +422,9 @@ discard block |
||
| 412 | 422 | // Clear any caching? |
| 413 | 423 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members)) |
| 414 | 424 | { |
| 415 | - if (!is_array($members)) |
|
| 416 | - $members = array($members); |
|
| 425 | + if (!is_array($members)) { |
|
| 426 | + $members = array($members); |
|
| 427 | + } |
|
| 417 | 428 | |
| 418 | 429 | foreach ($members as $member) |
| 419 | 430 | { |
@@ -446,29 +457,32 @@ discard block |
||
| 446 | 457 | { |
| 447 | 458 | global $modSettings, $smcFunc; |
| 448 | 459 | |
| 449 | - if (empty($changeArray) || !is_array($changeArray)) |
|
| 450 | - return; |
|
| 460 | + if (empty($changeArray) || !is_array($changeArray)) { |
|
| 461 | + return; |
|
| 462 | + } |
|
| 451 | 463 | |
| 452 | 464 | $toRemove = array(); |
| 453 | 465 | |
| 454 | 466 | // Go check if there is any setting to be removed. |
| 455 | - foreach ($changeArray as $k => $v) |
|
| 456 | - if ($v === null) |
|
| 467 | + foreach ($changeArray as $k => $v) { |
|
| 468 | + if ($v === null) |
|
| 457 | 469 | { |
| 458 | 470 | // Found some, remove them from the original array and add them to ours. |
| 459 | 471 | unset($changeArray[$k]); |
| 472 | + } |
|
| 460 | 473 | $toRemove[] = $k; |
| 461 | 474 | } |
| 462 | 475 | |
| 463 | 476 | // Proceed with the deletion. |
| 464 | - if (!empty($toRemove)) |
|
| 465 | - $smcFunc['db_query']('', ' |
|
| 477 | + if (!empty($toRemove)) { |
|
| 478 | + $smcFunc['db_query']('', ' |
|
| 466 | 479 | DELETE FROM {db_prefix}settings |
| 467 | 480 | WHERE variable IN ({array_string:remove})', |
| 468 | 481 | array( |
| 469 | 482 | 'remove' => $toRemove, |
| 470 | 483 | ) |
| 471 | 484 | ); |
| 485 | + } |
|
| 472 | 486 | |
| 473 | 487 | // In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs. |
| 474 | 488 | if ($update) |
@@ -497,19 +511,22 @@ discard block |
||
| 497 | 511 | foreach ($changeArray as $variable => $value) |
| 498 | 512 | { |
| 499 | 513 | // Don't bother if it's already like that ;). |
| 500 | - if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) |
|
| 501 | - continue; |
|
| 514 | + if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) { |
|
| 515 | + continue; |
|
| 516 | + } |
|
| 502 | 517 | // If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it. |
| 503 | - elseif (!isset($modSettings[$variable]) && empty($value)) |
|
| 504 | - continue; |
|
| 518 | + elseif (!isset($modSettings[$variable]) && empty($value)) { |
|
| 519 | + continue; |
|
| 520 | + } |
|
| 505 | 521 | |
| 506 | 522 | $replaceArray[] = array($variable, $value); |
| 507 | 523 | |
| 508 | 524 | $modSettings[$variable] = $value; |
| 509 | 525 | } |
| 510 | 526 | |
| 511 | - if (empty($replaceArray)) |
|
| 512 | - return; |
|
| 527 | + if (empty($replaceArray)) { |
|
| 528 | + return; |
|
| 529 | + } |
|
| 513 | 530 | |
| 514 | 531 | $smcFunc['db_insert']('replace', |
| 515 | 532 | '{db_prefix}settings', |
@@ -555,14 +572,17 @@ discard block |
||
| 555 | 572 | $start_invalid = $start < 0; |
| 556 | 573 | |
| 557 | 574 | // Make sure $start is a proper variable - not less than 0. |
| 558 | - if ($start_invalid) |
|
| 559 | - $start = 0; |
|
| 575 | + if ($start_invalid) { |
|
| 576 | + $start = 0; |
|
| 577 | + } |
|
| 560 | 578 | // Not greater than the upper bound. |
| 561 | - elseif ($start >= $max_value) |
|
| 562 | - $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
| 579 | + elseif ($start >= $max_value) { |
|
| 580 | + $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
| 581 | + } |
|
| 563 | 582 | // And it has to be a multiple of $num_per_page! |
| 564 | - else |
|
| 565 | - $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
| 583 | + else { |
|
| 584 | + $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
| 585 | + } |
|
| 566 | 586 | |
| 567 | 587 | $context['current_page'] = $start / $num_per_page; |
| 568 | 588 | |
@@ -592,77 +612,87 @@ discard block |
||
| 592 | 612 | |
| 593 | 613 | // Show all the pages. |
| 594 | 614 | $display_page = 1; |
| 595 | - for ($counter = 0; $counter < $max_value; $counter += $num_per_page) |
|
| 596 | - $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
| 615 | + for ($counter = 0; $counter < $max_value; $counter += $num_per_page) { |
|
| 616 | + $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
| 617 | + } |
|
| 597 | 618 | |
| 598 | 619 | // Show the right arrow. |
| 599 | 620 | $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page); |
| 600 | - if ($start != $counter - $max_value && !$start_invalid) |
|
| 601 | - $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
| 602 | - } |
|
| 603 | - else |
|
| 621 | + if ($start != $counter - $max_value && !$start_invalid) { |
|
| 622 | + $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
| 623 | + } |
|
| 624 | + } else |
|
| 604 | 625 | { |
| 605 | 626 | // If they didn't enter an odd value, pretend they did. |
| 606 | 627 | $PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2; |
| 607 | 628 | |
| 608 | 629 | // Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page) |
| 609 | - if (!empty($start) && $show_prevnext) |
|
| 610 | - $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
| 611 | - else |
|
| 612 | - $pageindex .= ''; |
|
| 630 | + if (!empty($start) && $show_prevnext) { |
|
| 631 | + $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
| 632 | + } else { |
|
| 633 | + $pageindex .= ''; |
|
| 634 | + } |
|
| 613 | 635 | |
| 614 | 636 | // Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15) |
| 615 | - if ($start > $num_per_page * $PageContiguous) |
|
| 616 | - $pageindex .= sprintf($base_link, 0, '1'); |
|
| 637 | + if ($start > $num_per_page * $PageContiguous) { |
|
| 638 | + $pageindex .= sprintf($base_link, 0, '1'); |
|
| 639 | + } |
|
| 617 | 640 | |
| 618 | 641 | // Show the ... after the first page. (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page) |
| 619 | - if ($start > $num_per_page * ($PageContiguous + 1)) |
|
| 620 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 642 | + if ($start > $num_per_page * ($PageContiguous + 1)) { |
|
| 643 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 621 | 644 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
| 622 | 645 | '{FIRST_PAGE}' => $num_per_page, |
| 623 | 646 | '{LAST_PAGE}' => $start - $num_per_page * $PageContiguous, |
| 624 | 647 | '{PER_PAGE}' => $num_per_page, |
| 625 | 648 | )); |
| 649 | + } |
|
| 626 | 650 | |
| 627 | 651 | // Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page) |
| 628 | - for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) |
|
| 629 | - if ($start >= $num_per_page * $nCont) |
|
| 652 | + for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) { |
|
| 653 | + if ($start >= $num_per_page * $nCont) |
|
| 630 | 654 | { |
| 631 | 655 | $tmpStart = $start - $num_per_page * $nCont; |
| 656 | + } |
|
| 632 | 657 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
| 633 | 658 | } |
| 634 | 659 | |
| 635 | 660 | // Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page) |
| 636 | - if (!$start_invalid) |
|
| 637 | - $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
| 638 | - else |
|
| 639 | - $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
| 661 | + if (!$start_invalid) { |
|
| 662 | + $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
| 663 | + } else { |
|
| 664 | + $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
| 665 | + } |
|
| 640 | 666 | |
| 641 | 667 | // Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page) |
| 642 | 668 | $tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page; |
| 643 | - for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) |
|
| 644 | - if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
| 669 | + for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) { |
|
| 670 | + if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
| 645 | 671 | { |
| 646 | 672 | $tmpStart = $start + $num_per_page * $nCont; |
| 673 | + } |
|
| 647 | 674 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
| 648 | 675 | } |
| 649 | 676 | |
| 650 | 677 | // Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page) |
| 651 | - if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) |
|
| 652 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 678 | + if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) { |
|
| 679 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 653 | 680 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
| 654 | 681 | '{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1), |
| 655 | 682 | '{LAST_PAGE}' => $tmpMaxPages, |
| 656 | 683 | '{PER_PAGE}' => $num_per_page, |
| 657 | 684 | )); |
| 685 | + } |
|
| 658 | 686 | |
| 659 | 687 | // Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15< next page) |
| 660 | - if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) |
|
| 661 | - $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
| 688 | + if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) { |
|
| 689 | + $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
| 690 | + } |
|
| 662 | 691 | |
| 663 | 692 | // Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<) |
| 664 | - if ($start != $tmpMaxPages && $show_prevnext) |
|
| 665 | - $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
| 693 | + if ($start != $tmpMaxPages && $show_prevnext) { |
|
| 694 | + $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
| 695 | + } |
|
| 666 | 696 | } |
| 667 | 697 | $pageindex .= $settings['page_index']['extra_after']; |
| 668 | 698 | |
@@ -688,8 +718,9 @@ discard block |
||
| 688 | 718 | if ($decimal_separator === null) |
| 689 | 719 | { |
| 690 | 720 | // Not set for whatever reason? |
| 691 | - if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) |
|
| 692 | - return $number; |
|
| 721 | + if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) { |
|
| 722 | + return $number; |
|
| 723 | + } |
|
| 693 | 724 | |
| 694 | 725 | // Cache these each load... |
| 695 | 726 | $thousands_separator = $matches[1]; |
@@ -721,17 +752,20 @@ discard block |
||
| 721 | 752 | static $non_twelve_hour; |
| 722 | 753 | |
| 723 | 754 | // Offset the time. |
| 724 | - if (!$offset_type) |
|
| 725 | - $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
| 755 | + if (!$offset_type) { |
|
| 756 | + $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
| 757 | + } |
|
| 726 | 758 | // Just the forum offset? |
| 727 | - elseif ($offset_type == 'forum') |
|
| 728 | - $time = $log_time + $modSettings['time_offset'] * 3600; |
|
| 729 | - else |
|
| 730 | - $time = $log_time; |
|
| 759 | + elseif ($offset_type == 'forum') { |
|
| 760 | + $time = $log_time + $modSettings['time_offset'] * 3600; |
|
| 761 | + } else { |
|
| 762 | + $time = $log_time; |
|
| 763 | + } |
|
| 731 | 764 | |
| 732 | 765 | // We can't have a negative date (on Windows, at least.) |
| 733 | - if ($log_time < 0) |
|
| 734 | - $log_time = 0; |
|
| 766 | + if ($log_time < 0) { |
|
| 767 | + $log_time = 0; |
|
| 768 | + } |
|
| 735 | 769 | |
| 736 | 770 | // Today and Yesterday? |
| 737 | 771 | if ($modSettings['todayMod'] >= 1 && $show_today === true) |
@@ -748,46 +782,53 @@ discard block |
||
| 748 | 782 | { |
| 749 | 783 | $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l'; |
| 750 | 784 | $today_fmt = $h . ':%M' . $s . ' %p'; |
| 785 | + } else { |
|
| 786 | + $today_fmt = '%H:%M' . $s; |
|
| 751 | 787 | } |
| 752 | - else |
|
| 753 | - $today_fmt = '%H:%M' . $s; |
|
| 754 | 788 | |
| 755 | 789 | // Same day of the year, same year.... Today! |
| 756 | - if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) |
|
| 757 | - return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 790 | + if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) { |
|
| 791 | + return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 792 | + } |
|
| 758 | 793 | |
| 759 | 794 | // Day-of-year is one less and same year, or it's the first of the year and that's the last of the year... |
| 760 | - if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) |
|
| 761 | - return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 795 | + if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) { |
|
| 796 | + return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 797 | + } |
|
| 762 | 798 | } |
| 763 | 799 | |
| 764 | 800 | $str = !is_bool($show_today) ? $show_today : $user_info['time_format']; |
| 765 | 801 | |
| 766 | 802 | if (setlocale(LC_TIME, $txt['lang_locale'])) |
| 767 | 803 | { |
| 768 | - if (!isset($non_twelve_hour)) |
|
| 769 | - $non_twelve_hour = trim(strftime('%p')) === ''; |
|
| 770 | - if ($non_twelve_hour && strpos($str, '%p') !== false) |
|
| 771 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 804 | + if (!isset($non_twelve_hour)) { |
|
| 805 | + $non_twelve_hour = trim(strftime('%p')) === ''; |
|
| 806 | + } |
|
| 807 | + if ($non_twelve_hour && strpos($str, '%p') !== false) { |
|
| 808 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 809 | + } |
|
| 772 | 810 | |
| 773 | - foreach (array('%a', '%A', '%b', '%B') as $token) |
|
| 774 | - if (strpos($str, $token) !== false) |
|
| 811 | + foreach (array('%a', '%A', '%b', '%B') as $token) { |
|
| 812 | + if (strpos($str, $token) !== false) |
|
| 775 | 813 | $str = str_replace($token, strftime($token, $time), $str); |
| 776 | - } |
|
| 777 | - else |
|
| 814 | + } |
|
| 815 | + } else |
|
| 778 | 816 | { |
| 779 | 817 | // Do-it-yourself time localization. Fun. |
| 780 | - foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) |
|
| 781 | - if (strpos($str, $token) !== false) |
|
| 818 | + foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) { |
|
| 819 | + if (strpos($str, $token) !== false) |
|
| 782 | 820 | $str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str); |
| 821 | + } |
|
| 783 | 822 | |
| 784 | - if (strpos($str, '%p') !== false) |
|
| 785 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 823 | + if (strpos($str, '%p') !== false) { |
|
| 824 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 825 | + } |
|
| 786 | 826 | } |
| 787 | 827 | |
| 788 | 828 | // Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that. |
| 789 | - if ($context['server']['is_windows'] && strpos($str, '%e') !== false) |
|
| 790 | - $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
| 829 | + if ($context['server']['is_windows'] && strpos($str, '%e') !== false) { |
|
| 830 | + $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
| 831 | + } |
|
| 791 | 832 | |
| 792 | 833 | // Format any other characters.. |
| 793 | 834 | return strftime($str, $time); |
@@ -809,16 +850,19 @@ discard block |
||
| 809 | 850 | static $translation = array(); |
| 810 | 851 | |
| 811 | 852 | // Determine the character set... Default to UTF-8 |
| 812 | - if (empty($context['character_set'])) |
|
| 813 | - $charset = 'UTF-8'; |
|
| 853 | + if (empty($context['character_set'])) { |
|
| 854 | + $charset = 'UTF-8'; |
|
| 855 | + } |
|
| 814 | 856 | // Use ISO-8859-1 in place of non-supported ISO-8859 charsets... |
| 815 | - elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) |
|
| 816 | - $charset = 'ISO-8859-1'; |
|
| 817 | - else |
|
| 818 | - $charset = $context['character_set']; |
|
| 857 | + elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) { |
|
| 858 | + $charset = 'ISO-8859-1'; |
|
| 859 | + } else { |
|
| 860 | + $charset = $context['character_set']; |
|
| 861 | + } |
|
| 819 | 862 | |
| 820 | - if (empty($translation)) |
|
| 821 | - $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
| 863 | + if (empty($translation)) { |
|
| 864 | + $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
| 865 | + } |
|
| 822 | 866 | |
| 823 | 867 | return strtr($string, $translation); |
| 824 | 868 | } |
@@ -840,8 +884,9 @@ discard block |
||
| 840 | 884 | global $smcFunc; |
| 841 | 885 | |
| 842 | 886 | // It was already short enough! |
| 843 | - if ($smcFunc['strlen']($subject) <= $len) |
|
| 844 | - return $subject; |
|
| 887 | + if ($smcFunc['strlen']($subject) <= $len) { |
|
| 888 | + return $subject; |
|
| 889 | + } |
|
| 845 | 890 | |
| 846 | 891 | // Shorten it by the length it was too long, and strip off junk from the end. |
| 847 | 892 | return $smcFunc['substr']($subject, 0, $len) . '...'; |
@@ -860,10 +905,11 @@ discard block |
||
| 860 | 905 | { |
| 861 | 906 | global $user_info, $modSettings; |
| 862 | 907 | |
| 863 | - if ($timestamp === null) |
|
| 864 | - $timestamp = time(); |
|
| 865 | - elseif ($timestamp == 0) |
|
| 866 | - return 0; |
|
| 908 | + if ($timestamp === null) { |
|
| 909 | + $timestamp = time(); |
|
| 910 | + } elseif ($timestamp == 0) { |
|
| 911 | + return 0; |
|
| 912 | + } |
|
| 867 | 913 | |
| 868 | 914 | return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600; |
| 869 | 915 | } |
@@ -892,8 +938,9 @@ discard block |
||
| 892 | 938 | $array[$i] = $array[$j]; |
| 893 | 939 | $array[$j] = $temp; |
| 894 | 940 | |
| 895 | - for ($i = 1; $p[$i] == 0; $i++) |
|
| 896 | - $p[$i] = 1; |
|
| 941 | + for ($i = 1; $p[$i] == 0; $i++) { |
|
| 942 | + $p[$i] = 1; |
|
| 943 | + } |
|
| 897 | 944 | |
| 898 | 945 | $orders[] = $array; |
| 899 | 946 | } |
@@ -925,12 +972,14 @@ discard block |
||
| 925 | 972 | static $disabled; |
| 926 | 973 | |
| 927 | 974 | // Don't waste cycles |
| 928 | - if ($message === '') |
|
| 929 | - return ''; |
|
| 975 | + if ($message === '') { |
|
| 976 | + return ''; |
|
| 977 | + } |
|
| 930 | 978 | |
| 931 | 979 | // Just in case it wasn't determined yet whether UTF-8 is enabled. |
| 932 | - if (!isset($context['utf8'])) |
|
| 933 | - $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
| 980 | + if (!isset($context['utf8'])) { |
|
| 981 | + $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
| 982 | + } |
|
| 934 | 983 | |
| 935 | 984 | // Clean up any cut/paste issues we may have |
| 936 | 985 | $message = sanitizeMSCutPaste($message); |
@@ -942,13 +991,15 @@ discard block |
||
| 942 | 991 | return $message; |
| 943 | 992 | } |
| 944 | 993 | |
| 945 | - if ($smileys !== null && ($smileys == '1' || $smileys == '0')) |
|
| 946 | - $smileys = (bool) $smileys; |
|
| 994 | + if ($smileys !== null && ($smileys == '1' || $smileys == '0')) { |
|
| 995 | + $smileys = (bool) $smileys; |
|
| 996 | + } |
|
| 947 | 997 | |
| 948 | 998 | if (empty($modSettings['enableBBC']) && $message !== false) |
| 949 | 999 | { |
| 950 | - if ($smileys === true) |
|
| 951 | - parsesmileys($message); |
|
| 1000 | + if ($smileys === true) { |
|
| 1001 | + parsesmileys($message); |
|
| 1002 | + } |
|
| 952 | 1003 | |
| 953 | 1004 | return $message; |
| 954 | 1005 | } |
@@ -961,8 +1012,9 @@ discard block |
||
| 961 | 1012 | } |
| 962 | 1013 | |
| 963 | 1014 | // Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker |
| 964 | - if (!empty($modSettings['autoLinkUrls'])) |
|
| 965 | - set_tld_regex(); |
|
| 1015 | + if (!empty($modSettings['autoLinkUrls'])) { |
|
| 1016 | + set_tld_regex(); |
|
| 1017 | + } |
|
| 966 | 1018 | |
| 967 | 1019 | // Allow mods access before entering the main parse_bbc loop |
| 968 | 1020 | call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
@@ -976,12 +1028,14 @@ discard block |
||
| 976 | 1028 | |
| 977 | 1029 | $temp = explode(',', strtolower($modSettings['disabledBBC'])); |
| 978 | 1030 | |
| 979 | - foreach ($temp as $tag) |
|
| 980 | - $disabled[trim($tag)] = true; |
|
| 1031 | + foreach ($temp as $tag) { |
|
| 1032 | + $disabled[trim($tag)] = true; |
|
| 1033 | + } |
|
| 981 | 1034 | } |
| 982 | 1035 | |
| 983 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
| 984 | - $disabled['flash'] = true; |
|
| 1036 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
| 1037 | + $disabled['flash'] = true; |
|
| 1038 | + } |
|
| 985 | 1039 | |
| 986 | 1040 | /* The following bbc are formatted as an array, with keys as follows: |
| 987 | 1041 | |
@@ -1102,8 +1156,9 @@ discard block |
||
| 1102 | 1156 | $returnContext = ''; |
| 1103 | 1157 | |
| 1104 | 1158 | // BBC or the entire attachments feature is disabled |
| 1105 | - if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) |
|
| 1106 | - return $data; |
|
| 1159 | + if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) { |
|
| 1160 | + return $data; |
|
| 1161 | + } |
|
| 1107 | 1162 | |
| 1108 | 1163 | // Save the attach ID. |
| 1109 | 1164 | $attachID = $data; |
@@ -1114,8 +1169,9 @@ discard block |
||
| 1114 | 1169 | $currentAttachment = parseAttachBBC($attachID); |
| 1115 | 1170 | |
| 1116 | 1171 | // parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do. |
| 1117 | - if (is_string($currentAttachment)) |
|
| 1118 | - return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
| 1172 | + if (is_string($currentAttachment)) { |
|
| 1173 | + return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
| 1174 | + } |
|
| 1119 | 1175 | |
| 1120 | 1176 | if (!empty($currentAttachment['is_image'])) |
| 1121 | 1177 | { |
@@ -1131,15 +1187,17 @@ discard block |
||
| 1131 | 1187 | $height = ' height="' . $currentAttachment['height'] . '"'; |
| 1132 | 1188 | } |
| 1133 | 1189 | |
| 1134 | - if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) |
|
| 1135 | - $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>'; |
|
| 1136 | - else |
|
| 1137 | - $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
|
| 1190 | + if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) { |
|
| 1191 | + $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>'; |
|
| 1192 | + } else { |
|
| 1193 | + $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>'; |
|
| 1194 | + } |
|
| 1138 | 1195 | } |
| 1139 | 1196 | |
| 1140 | 1197 | // No image. Show a link. |
| 1141 | - else |
|
| 1142 | - $returnContext .= $currentAttachment['link']; |
|
| 1198 | + else { |
|
| 1199 | + $returnContext .= $currentAttachment['link']; |
|
| 1200 | + } |
|
| 1143 | 1201 | |
| 1144 | 1202 | // Gotta append what we just did. |
| 1145 | 1203 | $data = $returnContext; |
@@ -1170,8 +1228,9 @@ discard block |
||
| 1170 | 1228 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
| 1171 | 1229 | { |
| 1172 | 1230 | // Do PHP code coloring? |
| 1173 | - if ($php_parts[$php_i] != '<?php') |
|
| 1174 | - continue; |
|
| 1231 | + if ($php_parts[$php_i] != '<?php') { |
|
| 1232 | + continue; |
|
| 1233 | + } |
|
| 1175 | 1234 | |
| 1176 | 1235 | $php_string = ''; |
| 1177 | 1236 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1187,8 +1246,9 @@ discard block |
||
| 1187 | 1246 | $data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data); |
| 1188 | 1247 | |
| 1189 | 1248 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
| 1190 | - if ($context['browser']['is_opera']) |
|
| 1191 | - $data .= ' '; |
|
| 1249 | + if ($context['browser']['is_opera']) { |
|
| 1250 | + $data .= ' '; |
|
| 1251 | + } |
|
| 1192 | 1252 | } |
| 1193 | 1253 | }, |
| 1194 | 1254 | 'block_level' => true, |
@@ -1207,8 +1267,9 @@ discard block |
||
| 1207 | 1267 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
| 1208 | 1268 | { |
| 1209 | 1269 | // Do PHP code coloring? |
| 1210 | - if ($php_parts[$php_i] != '<?php') |
|
| 1211 | - continue; |
|
| 1270 | + if ($php_parts[$php_i] != '<?php') { |
|
| 1271 | + continue; |
|
| 1272 | + } |
|
| 1212 | 1273 | |
| 1213 | 1274 | $php_string = ''; |
| 1214 | 1275 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1224,8 +1285,9 @@ discard block |
||
| 1224 | 1285 | $data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]); |
| 1225 | 1286 | |
| 1226 | 1287 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
| 1227 | - if ($context['browser']['is_opera']) |
|
| 1228 | - $data[0] .= ' '; |
|
| 1288 | + if ($context['browser']['is_opera']) { |
|
| 1289 | + $data[0] .= ' '; |
|
| 1290 | + } |
|
| 1229 | 1291 | } |
| 1230 | 1292 | }, |
| 1231 | 1293 | 'block_level' => true, |
@@ -1263,11 +1325,13 @@ discard block |
||
| 1263 | 1325 | 'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">', |
| 1264 | 1326 | 'validate' => function (&$tag, &$data, $disabled) |
| 1265 | 1327 | { |
| 1266 | - if (isset($disabled['url'])) |
|
| 1267 | - $tag['content'] = '$1'; |
|
| 1328 | + if (isset($disabled['url'])) { |
|
| 1329 | + $tag['content'] = '$1'; |
|
| 1330 | + } |
|
| 1268 | 1331 | $scheme = parse_url($data[0], PHP_URL_SCHEME); |
| 1269 | - if (empty($scheme)) |
|
| 1270 | - $data[0] = '//' . ltrim($data[0], ':/'); |
|
| 1332 | + if (empty($scheme)) { |
|
| 1333 | + $data[0] = '//' . ltrim($data[0], ':/'); |
|
| 1334 | + } |
|
| 1271 | 1335 | }, |
| 1272 | 1336 | 'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>', |
| 1273 | 1337 | ), |
@@ -1281,10 +1345,11 @@ discard block |
||
| 1281 | 1345 | { |
| 1282 | 1346 | $class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"'; |
| 1283 | 1347 | |
| 1284 | - if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) |
|
| 1285 | - $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; |
|
| 1286 | - else |
|
| 1287 | - $css = ''; |
|
| 1348 | + if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) { |
|
| 1349 | + $css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"'; |
|
| 1350 | + } else { |
|
| 1351 | + $css = ''; |
|
| 1352 | + } |
|
| 1288 | 1353 | |
| 1289 | 1354 | $data = $class . $css; |
| 1290 | 1355 | }, |
@@ -1334,14 +1399,16 @@ discard block |
||
| 1334 | 1399 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1335 | 1400 | if ($image_proxy_enabled) |
| 1336 | 1401 | { |
| 1337 | - if (empty($scheme)) |
|
| 1338 | - $data = 'http://' . ltrim($data, ':/'); |
|
| 1402 | + if (empty($scheme)) { |
|
| 1403 | + $data = 'http://' . ltrim($data, ':/'); |
|
| 1404 | + } |
|
| 1339 | 1405 | |
| 1340 | - if ($scheme != 'https') |
|
| 1341 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1406 | + if ($scheme != 'https') { |
|
| 1407 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1408 | + } |
|
| 1409 | + } elseif (empty($scheme)) { |
|
| 1410 | + $data = '//' . ltrim($data, ':/'); |
|
| 1342 | 1411 | } |
| 1343 | - elseif (empty($scheme)) |
|
| 1344 | - $data = '//' . ltrim($data, ':/'); |
|
| 1345 | 1412 | }, |
| 1346 | 1413 | 'disabled_content' => '($1)', |
| 1347 | 1414 | ), |
@@ -1357,14 +1424,16 @@ discard block |
||
| 1357 | 1424 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1358 | 1425 | if ($image_proxy_enabled) |
| 1359 | 1426 | { |
| 1360 | - if (empty($scheme)) |
|
| 1361 | - $data = 'http://' . ltrim($data, ':/'); |
|
| 1427 | + if (empty($scheme)) { |
|
| 1428 | + $data = 'http://' . ltrim($data, ':/'); |
|
| 1429 | + } |
|
| 1362 | 1430 | |
| 1363 | - if ($scheme != 'https') |
|
| 1364 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1431 | + if ($scheme != 'https') { |
|
| 1432 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1433 | + } |
|
| 1434 | + } elseif (empty($scheme)) { |
|
| 1435 | + $data = '//' . ltrim($data, ':/'); |
|
| 1365 | 1436 | } |
| 1366 | - elseif (empty($scheme)) |
|
| 1367 | - $data = '//' . ltrim($data, ':/'); |
|
| 1368 | 1437 | }, |
| 1369 | 1438 | 'disabled_content' => '($1)', |
| 1370 | 1439 | ), |
@@ -1376,8 +1445,9 @@ discard block |
||
| 1376 | 1445 | { |
| 1377 | 1446 | $data = strtr($data, array('<br>' => '')); |
| 1378 | 1447 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1379 | - if (empty($scheme)) |
|
| 1380 | - $data = '//' . ltrim($data, ':/'); |
|
| 1448 | + if (empty($scheme)) { |
|
| 1449 | + $data = '//' . ltrim($data, ':/'); |
|
| 1450 | + } |
|
| 1381 | 1451 | }, |
| 1382 | 1452 | ), |
| 1383 | 1453 | array( |
@@ -1388,13 +1458,14 @@ discard block |
||
| 1388 | 1458 | 'after' => '</a>', |
| 1389 | 1459 | 'validate' => function (&$tag, &$data, $disabled) |
| 1390 | 1460 | { |
| 1391 | - if (substr($data, 0, 1) == '#') |
|
| 1392 | - $data = '#post_' . substr($data, 1); |
|
| 1393 | - else |
|
| 1461 | + if (substr($data, 0, 1) == '#') { |
|
| 1462 | + $data = '#post_' . substr($data, 1); |
|
| 1463 | + } else |
|
| 1394 | 1464 | { |
| 1395 | 1465 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1396 | - if (empty($scheme)) |
|
| 1397 | - $data = '//' . ltrim($data, ':/'); |
|
| 1466 | + if (empty($scheme)) { |
|
| 1467 | + $data = '//' . ltrim($data, ':/'); |
|
| 1468 | + } |
|
| 1398 | 1469 | } |
| 1399 | 1470 | }, |
| 1400 | 1471 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
@@ -1472,8 +1543,9 @@ discard block |
||
| 1472 | 1543 | { |
| 1473 | 1544 | $add_begin = substr(trim($data), 0, 5) != '<?'; |
| 1474 | 1545 | $data = highlight_php_code($add_begin ? '<?php ' . $data . '?>' : $data); |
| 1475 | - if ($add_begin) |
|
| 1476 | - $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
| 1546 | + if ($add_begin) { |
|
| 1547 | + $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
| 1548 | + } |
|
| 1477 | 1549 | } |
| 1478 | 1550 | }, |
| 1479 | 1551 | 'block_level' => false, |
@@ -1604,10 +1676,11 @@ discard block |
||
| 1604 | 1676 | 'content' => '$1', |
| 1605 | 1677 | 'validate' => function (&$tag, &$data, $disabled) |
| 1606 | 1678 | { |
| 1607 | - if (is_numeric($data)) |
|
| 1608 | - $data = timeformat($data); |
|
| 1609 | - else |
|
| 1610 | - $tag['content'] = '[time]$1[/time]'; |
|
| 1679 | + if (is_numeric($data)) { |
|
| 1680 | + $data = timeformat($data); |
|
| 1681 | + } else { |
|
| 1682 | + $tag['content'] = '[time]$1[/time]'; |
|
| 1683 | + } |
|
| 1611 | 1684 | }, |
| 1612 | 1685 | ), |
| 1613 | 1686 | array( |
@@ -1634,8 +1707,9 @@ discard block |
||
| 1634 | 1707 | { |
| 1635 | 1708 | $data = strtr($data, array('<br>' => '')); |
| 1636 | 1709 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1637 | - if (empty($scheme)) |
|
| 1638 | - $data = '//' . ltrim($data, ':/'); |
|
| 1710 | + if (empty($scheme)) { |
|
| 1711 | + $data = '//' . ltrim($data, ':/'); |
|
| 1712 | + } |
|
| 1639 | 1713 | }, |
| 1640 | 1714 | ), |
| 1641 | 1715 | array( |
@@ -1647,8 +1721,9 @@ discard block |
||
| 1647 | 1721 | 'validate' => function (&$tag, &$data, $disabled) |
| 1648 | 1722 | { |
| 1649 | 1723 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1650 | - if (empty($scheme)) |
|
| 1651 | - $data = '//' . ltrim($data, ':/'); |
|
| 1724 | + if (empty($scheme)) { |
|
| 1725 | + $data = '//' . ltrim($data, ':/'); |
|
| 1726 | + } |
|
| 1652 | 1727 | }, |
| 1653 | 1728 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
| 1654 | 1729 | 'disabled_after' => ' ($1)', |
@@ -1668,8 +1743,9 @@ discard block |
||
| 1668 | 1743 | // This is mainly for the bbc manager, so it's easy to add tags above. Custom BBC should be added above this line. |
| 1669 | 1744 | if ($message === false) |
| 1670 | 1745 | { |
| 1671 | - if (isset($temp_bbc)) |
|
| 1672 | - $bbc_codes = $temp_bbc; |
|
| 1746 | + if (isset($temp_bbc)) { |
|
| 1747 | + $bbc_codes = $temp_bbc; |
|
| 1748 | + } |
|
| 1673 | 1749 | usort($codes, function ($a, $b) { |
| 1674 | 1750 | return strcmp($a['tag'], $b['tag']); |
| 1675 | 1751 | }); |
@@ -1689,8 +1765,9 @@ discard block |
||
| 1689 | 1765 | ); |
| 1690 | 1766 | if (!isset($disabled['li']) && !isset($disabled['list'])) |
| 1691 | 1767 | { |
| 1692 | - foreach ($itemcodes as $c => $dummy) |
|
| 1693 | - $bbc_codes[$c] = array(); |
|
| 1768 | + foreach ($itemcodes as $c => $dummy) { |
|
| 1769 | + $bbc_codes[$c] = array(); |
|
| 1770 | + } |
|
| 1694 | 1771 | } |
| 1695 | 1772 | |
| 1696 | 1773 | // Shhhh! |
@@ -1711,12 +1788,14 @@ discard block |
||
| 1711 | 1788 | foreach ($codes as $code) |
| 1712 | 1789 | { |
| 1713 | 1790 | // Make it easier to process parameters later |
| 1714 | - if (!empty($code['parameters'])) |
|
| 1715 | - ksort($code['parameters'], SORT_STRING); |
|
| 1791 | + if (!empty($code['parameters'])) { |
|
| 1792 | + ksort($code['parameters'], SORT_STRING); |
|
| 1793 | + } |
|
| 1716 | 1794 | |
| 1717 | 1795 | // If we are not doing every tag only do ones we are interested in. |
| 1718 | - if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) |
|
| 1719 | - $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
| 1796 | + if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) { |
|
| 1797 | + $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
| 1798 | + } |
|
| 1720 | 1799 | } |
| 1721 | 1800 | $codes = null; |
| 1722 | 1801 | } |
@@ -1727,8 +1806,9 @@ discard block |
||
| 1727 | 1806 | // It's likely this will change if the message is modified. |
| 1728 | 1807 | $cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . json_encode($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']); |
| 1729 | 1808 | |
| 1730 | - if (($temp = cache_get_data($cache_key, 240)) != null) |
|
| 1731 | - return $temp; |
|
| 1809 | + if (($temp = cache_get_data($cache_key, 240)) != null) { |
|
| 1810 | + return $temp; |
|
| 1811 | + } |
|
| 1732 | 1812 | |
| 1733 | 1813 | $cache_t = microtime(); |
| 1734 | 1814 | } |
@@ -1760,8 +1840,9 @@ discard block |
||
| 1760 | 1840 | $disabled['flash'] = true; |
| 1761 | 1841 | |
| 1762 | 1842 | // @todo Change maybe? |
| 1763 | - if (!isset($_GET['images'])) |
|
| 1764 | - $disabled['img'] = true; |
|
| 1843 | + if (!isset($_GET['images'])) { |
|
| 1844 | + $disabled['img'] = true; |
|
| 1845 | + } |
|
| 1765 | 1846 | |
| 1766 | 1847 | // @todo Interface/setting to add more? |
| 1767 | 1848 | } |
@@ -1785,8 +1866,9 @@ discard block |
||
| 1785 | 1866 | $pos = isset($matches[0][1]) ? $matches[0][1] : false; |
| 1786 | 1867 | |
| 1787 | 1868 | // Failsafe. |
| 1788 | - if ($pos === false || $last_pos > $pos) |
|
| 1789 | - $pos = strlen($message) + 1; |
|
| 1869 | + if ($pos === false || $last_pos > $pos) { |
|
| 1870 | + $pos = strlen($message) + 1; |
|
| 1871 | + } |
|
| 1790 | 1872 | |
| 1791 | 1873 | // Can't have a one letter smiley, URL, or email! (sorry.) |
| 1792 | 1874 | if ($last_pos < $pos - 1) |
@@ -1805,8 +1887,9 @@ discard block |
||
| 1805 | 1887 | |
| 1806 | 1888 | // <br> should be empty. |
| 1807 | 1889 | $empty_tags = array('br', 'hr'); |
| 1808 | - foreach ($empty_tags as $tag) |
|
| 1809 | - $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
| 1890 | + foreach ($empty_tags as $tag) { |
|
| 1891 | + $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
| 1892 | + } |
|
| 1810 | 1893 | |
| 1811 | 1894 | // b, u, i, s, pre... basic tags. |
| 1812 | 1895 | $closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote'); |
@@ -1815,8 +1898,9 @@ discard block |
||
| 1815 | 1898 | $diff = substr_count($data, '<' . $tag . '>') - substr_count($data, '</' . $tag . '>'); |
| 1816 | 1899 | $data = strtr($data, array('<' . $tag . '>' => '<' . $tag . '>', '</' . $tag . '>' => '</' . $tag . '>')); |
| 1817 | 1900 | |
| 1818 | - if ($diff > 0) |
|
| 1819 | - $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
| 1901 | + if ($diff > 0) { |
|
| 1902 | + $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
| 1903 | + } |
|
| 1820 | 1904 | } |
| 1821 | 1905 | |
| 1822 | 1906 | // Do <img ...> - with security... action= -> action-. |
@@ -1829,8 +1913,9 @@ discard block |
||
| 1829 | 1913 | $alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^"|"$~', '', $matches[3][$match]); |
| 1830 | 1914 | |
| 1831 | 1915 | // Remove action= from the URL - no funny business, now. |
| 1832 | - if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) |
|
| 1833 | - $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
| 1916 | + if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) { |
|
| 1917 | + $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
| 1918 | + } |
|
| 1834 | 1919 | |
| 1835 | 1920 | // Check if the image is larger than allowed. |
| 1836 | 1921 | if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height'])) |
@@ -1851,9 +1936,9 @@ discard block |
||
| 1851 | 1936 | |
| 1852 | 1937 | // Set the new image tag. |
| 1853 | 1938 | $replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]'; |
| 1939 | + } else { |
|
| 1940 | + $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
| 1854 | 1941 | } |
| 1855 | - else |
|
| 1856 | - $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
| 1857 | 1942 | } |
| 1858 | 1943 | |
| 1859 | 1944 | $data = strtr($data, $replaces); |
@@ -1866,16 +1951,18 @@ discard block |
||
| 1866 | 1951 | $no_autolink_area = false; |
| 1867 | 1952 | if (!empty($open_tags)) |
| 1868 | 1953 | { |
| 1869 | - foreach ($open_tags as $open_tag) |
|
| 1870 | - if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
| 1954 | + foreach ($open_tags as $open_tag) { |
|
| 1955 | + if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
| 1871 | 1956 | $no_autolink_area = true; |
| 1957 | + } |
|
| 1872 | 1958 | } |
| 1873 | 1959 | |
| 1874 | 1960 | // Don't go backwards. |
| 1875 | 1961 | // @todo Don't think is the real solution.... |
| 1876 | 1962 | $lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0; |
| 1877 | - if ($pos < $lastAutoPos) |
|
| 1878 | - $no_autolink_area = true; |
|
| 1963 | + if ($pos < $lastAutoPos) { |
|
| 1964 | + $no_autolink_area = true; |
|
| 1965 | + } |
|
| 1879 | 1966 | $lastAutoPos = $pos; |
| 1880 | 1967 | |
| 1881 | 1968 | if (!$no_autolink_area) |
@@ -1984,17 +2071,19 @@ discard block |
||
| 1984 | 2071 | if ($scheme == 'mailto') |
| 1985 | 2072 | { |
| 1986 | 2073 | $email_address = str_replace('mailto:', '', $url); |
| 1987 | - if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) |
|
| 1988 | - return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
| 1989 | - else |
|
| 1990 | - return $url; |
|
| 2074 | + if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) { |
|
| 2075 | + return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
| 2076 | + } else { |
|
| 2077 | + return $url; |
|
| 2078 | + } |
|
| 1991 | 2079 | } |
| 1992 | 2080 | |
| 1993 | 2081 | // Are we linking a schemeless URL or naked domain name (e.g. "example.com")? |
| 1994 | - if (empty($scheme)) |
|
| 1995 | - $fullUrl = '//' . ltrim($url, ':/'); |
|
| 1996 | - else |
|
| 1997 | - $fullUrl = $url; |
|
| 2082 | + if (empty($scheme)) { |
|
| 2083 | + $fullUrl = '//' . ltrim($url, ':/'); |
|
| 2084 | + } else { |
|
| 2085 | + $fullUrl = $url; |
|
| 2086 | + } |
|
| 1998 | 2087 | |
| 1999 | 2088 | return '[url="' . str_replace(array('[', ']'), array('[', ']'), $fullUrl) . '"]' . $url . '[/url]'; |
| 2000 | 2089 | }, $data); |
@@ -2043,16 +2132,18 @@ discard block |
||
| 2043 | 2132 | } |
| 2044 | 2133 | |
| 2045 | 2134 | // Are we there yet? Are we there yet? |
| 2046 | - if ($pos >= strlen($message) - 1) |
|
| 2047 | - break; |
|
| 2135 | + if ($pos >= strlen($message) - 1) { |
|
| 2136 | + break; |
|
| 2137 | + } |
|
| 2048 | 2138 | |
| 2049 | 2139 | $tags = strtolower($message[$pos + 1]); |
| 2050 | 2140 | |
| 2051 | 2141 | if ($tags == '/' && !empty($open_tags)) |
| 2052 | 2142 | { |
| 2053 | 2143 | $pos2 = strpos($message, ']', $pos + 1); |
| 2054 | - if ($pos2 == $pos + 2) |
|
| 2055 | - continue; |
|
| 2144 | + if ($pos2 == $pos + 2) { |
|
| 2145 | + continue; |
|
| 2146 | + } |
|
| 2056 | 2147 | |
| 2057 | 2148 | $look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2)); |
| 2058 | 2149 | |
@@ -2062,8 +2153,9 @@ discard block |
||
| 2062 | 2153 | do |
| 2063 | 2154 | { |
| 2064 | 2155 | $tag = array_pop($open_tags); |
| 2065 | - if (!$tag) |
|
| 2066 | - break; |
|
| 2156 | + if (!$tag) { |
|
| 2157 | + break; |
|
| 2158 | + } |
|
| 2067 | 2159 | |
| 2068 | 2160 | if (!empty($tag['block_level'])) |
| 2069 | 2161 | { |
@@ -2077,10 +2169,11 @@ discard block |
||
| 2077 | 2169 | // The idea is, if we are LOOKING for a block level tag, we can close them on the way. |
| 2078 | 2170 | if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]])) |
| 2079 | 2171 | { |
| 2080 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
| 2081 | - if ($temp['tag'] == $look_for) |
|
| 2172 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
| 2173 | + if ($temp['tag'] == $look_for) |
|
| 2082 | 2174 | { |
| 2083 | 2175 | $block_level = !empty($temp['block_level']); |
| 2176 | + } |
|
| 2084 | 2177 | break; |
| 2085 | 2178 | } |
| 2086 | 2179 | } |
@@ -2102,15 +2195,15 @@ discard block |
||
| 2102 | 2195 | { |
| 2103 | 2196 | $open_tags = $to_close; |
| 2104 | 2197 | continue; |
| 2105 | - } |
|
| 2106 | - elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
| 2198 | + } elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
| 2107 | 2199 | { |
| 2108 | 2200 | if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]])) |
| 2109 | 2201 | { |
| 2110 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
| 2111 | - if ($temp['tag'] == $look_for) |
|
| 2202 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
| 2203 | + if ($temp['tag'] == $look_for) |
|
| 2112 | 2204 | { |
| 2113 | 2205 | $block_level = !empty($temp['block_level']); |
| 2206 | + } |
|
| 2114 | 2207 | break; |
| 2115 | 2208 | } |
| 2116 | 2209 | } |
@@ -2118,8 +2211,9 @@ discard block |
||
| 2118 | 2211 | // We're not looking for a block level tag (or maybe even a tag that exists...) |
| 2119 | 2212 | if (!$block_level) |
| 2120 | 2213 | { |
| 2121 | - foreach ($to_close as $tag) |
|
| 2122 | - array_push($open_tags, $tag); |
|
| 2214 | + foreach ($to_close as $tag) { |
|
| 2215 | + array_push($open_tags, $tag); |
|
| 2216 | + } |
|
| 2123 | 2217 | continue; |
| 2124 | 2218 | } |
| 2125 | 2219 | } |
@@ -2132,14 +2226,17 @@ discard block |
||
| 2132 | 2226 | |
| 2133 | 2227 | // See the comment at the end of the big loop - just eating whitespace ;). |
| 2134 | 2228 | $whitespace_regex = ''; |
| 2135 | - if (!empty($tag['block_level'])) |
|
| 2136 | - $whitespace_regex .= '( |\s)*<br>'; |
|
| 2229 | + if (!empty($tag['block_level'])) { |
|
| 2230 | + $whitespace_regex .= '( |\s)*<br>'; |
|
| 2231 | + } |
|
| 2137 | 2232 | // Trim one line of whitespace after unnested tags, but all of it after nested ones |
| 2138 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') |
|
| 2139 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
| 2233 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside') { |
|
| 2234 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
| 2235 | + } |
|
| 2140 | 2236 | |
| 2141 | - if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) |
|
| 2142 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2237 | + if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { |
|
| 2238 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2239 | + } |
|
| 2143 | 2240 | } |
| 2144 | 2241 | |
| 2145 | 2242 | if (!empty($to_close)) |
@@ -2152,8 +2249,9 @@ discard block |
||
| 2152 | 2249 | } |
| 2153 | 2250 | |
| 2154 | 2251 | // No tags for this character, so just keep going (fastest possible course.) |
| 2155 | - if (!isset($bbc_codes[$tags])) |
|
| 2156 | - continue; |
|
| 2252 | + if (!isset($bbc_codes[$tags])) { |
|
| 2253 | + continue; |
|
| 2254 | + } |
|
| 2157 | 2255 | |
| 2158 | 2256 | $inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1]; |
| 2159 | 2257 | $tag = null; |
@@ -2162,44 +2260,52 @@ discard block |
||
| 2162 | 2260 | $pt_strlen = strlen($possible['tag']); |
| 2163 | 2261 | |
| 2164 | 2262 | // Not a match? |
| 2165 | - if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) |
|
| 2166 | - continue; |
|
| 2263 | + if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) { |
|
| 2264 | + continue; |
|
| 2265 | + } |
|
| 2167 | 2266 | |
| 2168 | 2267 | $next_c = $message[$pos + 1 + $pt_strlen]; |
| 2169 | 2268 | |
| 2170 | 2269 | // A test validation? |
| 2171 | - if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) |
|
| 2172 | - continue; |
|
| 2270 | + if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) { |
|
| 2271 | + continue; |
|
| 2272 | + } |
|
| 2173 | 2273 | // Do we want parameters? |
| 2174 | 2274 | elseif (!empty($possible['parameters'])) |
| 2175 | 2275 | { |
| 2176 | - if ($next_c != ' ') |
|
| 2177 | - continue; |
|
| 2178 | - } |
|
| 2179 | - elseif (isset($possible['type'])) |
|
| 2276 | + if ($next_c != ' ') { |
|
| 2277 | + continue; |
|
| 2278 | + } |
|
| 2279 | + } elseif (isset($possible['type'])) |
|
| 2180 | 2280 | { |
| 2181 | 2281 | // Do we need an equal sign? |
| 2182 | - if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') |
|
| 2183 | - continue; |
|
| 2282 | + if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') { |
|
| 2283 | + continue; |
|
| 2284 | + } |
|
| 2184 | 2285 | // Maybe we just want a /... |
| 2185 | - if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') |
|
| 2186 | - continue; |
|
| 2286 | + if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') { |
|
| 2287 | + continue; |
|
| 2288 | + } |
|
| 2187 | 2289 | // An immediate ]? |
| 2188 | - if ($possible['type'] == 'unparsed_content' && $next_c != ']') |
|
| 2189 | - continue; |
|
| 2290 | + if ($possible['type'] == 'unparsed_content' && $next_c != ']') { |
|
| 2291 | + continue; |
|
| 2292 | + } |
|
| 2190 | 2293 | } |
| 2191 | 2294 | // No type means 'parsed_content', which demands an immediate ] without parameters! |
| 2192 | - elseif ($next_c != ']') |
|
| 2193 | - continue; |
|
| 2295 | + elseif ($next_c != ']') { |
|
| 2296 | + continue; |
|
| 2297 | + } |
|
| 2194 | 2298 | |
| 2195 | 2299 | // Check allowed tree? |
| 2196 | - if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) |
|
| 2197 | - continue; |
|
| 2198 | - elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) |
|
| 2199 | - continue; |
|
| 2300 | + if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) { |
|
| 2301 | + continue; |
|
| 2302 | + } elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) { |
|
| 2303 | + continue; |
|
| 2304 | + } |
|
| 2200 | 2305 | // If this is in the list of disallowed child tags, don't parse it. |
| 2201 | - elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) |
|
| 2202 | - continue; |
|
| 2306 | + elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) { |
|
| 2307 | + continue; |
|
| 2308 | + } |
|
| 2203 | 2309 | |
| 2204 | 2310 | $pos1 = $pos + 1 + $pt_strlen + 1; |
| 2205 | 2311 | |
@@ -2211,8 +2317,9 @@ discard block |
||
| 2211 | 2317 | foreach ($open_tags as $open_quote) |
| 2212 | 2318 | { |
| 2213 | 2319 | // Every parent quote this quote has flips the styling |
| 2214 | - if ($open_quote['tag'] == 'quote') |
|
| 2215 | - $quote_alt = !$quote_alt; |
|
| 2320 | + if ($open_quote['tag'] == 'quote') { |
|
| 2321 | + $quote_alt = !$quote_alt; |
|
| 2322 | + } |
|
| 2216 | 2323 | } |
| 2217 | 2324 | // Add a class to the quote to style alternating blockquotes |
| 2218 | 2325 | $possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">')); |
@@ -2223,8 +2330,9 @@ discard block |
||
| 2223 | 2330 | { |
| 2224 | 2331 | // Build a regular expression for each parameter for the current tag. |
| 2225 | 2332 | $preg = array(); |
| 2226 | - foreach ($possible['parameters'] as $p => $info) |
|
| 2227 | - $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
| 2333 | + foreach ($possible['parameters'] as $p => $info) { |
|
| 2334 | + $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
| 2335 | + } |
|
| 2228 | 2336 | |
| 2229 | 2337 | // Extract the string that potentially holds our parameters. |
| 2230 | 2338 | $blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos)); |
@@ -2244,24 +2352,27 @@ discard block |
||
| 2244 | 2352 | |
| 2245 | 2353 | $match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0; |
| 2246 | 2354 | |
| 2247 | - if ($match) |
|
| 2248 | - $blob_counter = count($blobs) + 1; |
|
| 2355 | + if ($match) { |
|
| 2356 | + $blob_counter = count($blobs) + 1; |
|
| 2357 | + } |
|
| 2249 | 2358 | } |
| 2250 | 2359 | |
| 2251 | 2360 | // Didn't match our parameter list, try the next possible. |
| 2252 | - if (!$match) |
|
| 2253 | - continue; |
|
| 2361 | + if (!$match) { |
|
| 2362 | + continue; |
|
| 2363 | + } |
|
| 2254 | 2364 | |
| 2255 | 2365 | $params = array(); |
| 2256 | 2366 | for ($i = 1, $n = count($matches); $i < $n; $i += 2) |
| 2257 | 2367 | { |
| 2258 | 2368 | $key = strtok(ltrim($matches[$i]), '='); |
| 2259 | - if (isset($possible['parameters'][$key]['value'])) |
|
| 2260 | - $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
| 2261 | - elseif (isset($possible['parameters'][$key]['validate'])) |
|
| 2262 | - $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
| 2263 | - else |
|
| 2264 | - $params['{' . $key . '}'] = $matches[$i + 1]; |
|
| 2369 | + if (isset($possible['parameters'][$key]['value'])) { |
|
| 2370 | + $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
| 2371 | + } elseif (isset($possible['parameters'][$key]['validate'])) { |
|
| 2372 | + $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
| 2373 | + } else { |
|
| 2374 | + $params['{' . $key . '}'] = $matches[$i + 1]; |
|
| 2375 | + } |
|
| 2265 | 2376 | |
| 2266 | 2377 | // Just to make sure: replace any $ or { so they can't interpolate wrongly. |
| 2267 | 2378 | $params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '$', '{' => '{')); |
@@ -2269,23 +2380,26 @@ discard block |
||
| 2269 | 2380 | |
| 2270 | 2381 | foreach ($possible['parameters'] as $p => $info) |
| 2271 | 2382 | { |
| 2272 | - if (!isset($params['{' . $p . '}'])) |
|
| 2273 | - $params['{' . $p . '}'] = ''; |
|
| 2383 | + if (!isset($params['{' . $p . '}'])) { |
|
| 2384 | + $params['{' . $p . '}'] = ''; |
|
| 2385 | + } |
|
| 2274 | 2386 | } |
| 2275 | 2387 | |
| 2276 | 2388 | $tag = $possible; |
| 2277 | 2389 | |
| 2278 | 2390 | // Put the parameters into the string. |
| 2279 | - if (isset($tag['before'])) |
|
| 2280 | - $tag['before'] = strtr($tag['before'], $params); |
|
| 2281 | - if (isset($tag['after'])) |
|
| 2282 | - $tag['after'] = strtr($tag['after'], $params); |
|
| 2283 | - if (isset($tag['content'])) |
|
| 2284 | - $tag['content'] = strtr($tag['content'], $params); |
|
| 2391 | + if (isset($tag['before'])) { |
|
| 2392 | + $tag['before'] = strtr($tag['before'], $params); |
|
| 2393 | + } |
|
| 2394 | + if (isset($tag['after'])) { |
|
| 2395 | + $tag['after'] = strtr($tag['after'], $params); |
|
| 2396 | + } |
|
| 2397 | + if (isset($tag['content'])) { |
|
| 2398 | + $tag['content'] = strtr($tag['content'], $params); |
|
| 2399 | + } |
|
| 2285 | 2400 | |
| 2286 | 2401 | $pos1 += strlen($given_param_string); |
| 2287 | - } |
|
| 2288 | - else |
|
| 2402 | + } else |
|
| 2289 | 2403 | { |
| 2290 | 2404 | $tag = $possible; |
| 2291 | 2405 | $params = array(); |
@@ -2296,8 +2410,9 @@ discard block |
||
| 2296 | 2410 | // Item codes are complicated buggers... they are implicit [li]s and can make [list]s! |
| 2297 | 2411 | if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li'])) |
| 2298 | 2412 | { |
| 2299 | - if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) |
|
| 2300 | - continue; |
|
| 2413 | + if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) { |
|
| 2414 | + continue; |
|
| 2415 | + } |
|
| 2301 | 2416 | |
| 2302 | 2417 | $tag = $itemcodes[$message[$pos + 1]]; |
| 2303 | 2418 | |
@@ -2318,9 +2433,9 @@ discard block |
||
| 2318 | 2433 | { |
| 2319 | 2434 | array_pop($open_tags); |
| 2320 | 2435 | $code = '</li>'; |
| 2436 | + } else { |
|
| 2437 | + $code = ''; |
|
| 2321 | 2438 | } |
| 2322 | - else |
|
| 2323 | - $code = ''; |
|
| 2324 | 2439 | |
| 2325 | 2440 | // Now we open a new tag. |
| 2326 | 2441 | $open_tags[] = array( |
@@ -2367,12 +2482,14 @@ discard block |
||
| 2367 | 2482 | } |
| 2368 | 2483 | |
| 2369 | 2484 | // No tag? Keep looking, then. Silly people using brackets without actual tags. |
| 2370 | - if ($tag === null) |
|
| 2371 | - continue; |
|
| 2485 | + if ($tag === null) { |
|
| 2486 | + continue; |
|
| 2487 | + } |
|
| 2372 | 2488 | |
| 2373 | 2489 | // Propagate the list to the child (so wrapping the disallowed tag won't work either.) |
| 2374 | - if (isset($inside['disallow_children'])) |
|
| 2375 | - $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
| 2490 | + if (isset($inside['disallow_children'])) { |
|
| 2491 | + $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
| 2492 | + } |
|
| 2376 | 2493 | |
| 2377 | 2494 | // Is this tag disabled? |
| 2378 | 2495 | if (isset($disabled[$tag['tag']])) |
@@ -2382,14 +2499,13 @@ discard block |
||
| 2382 | 2499 | $tag['before'] = !empty($tag['block_level']) ? '<div>' : ''; |
| 2383 | 2500 | $tag['after'] = !empty($tag['block_level']) ? '</div>' : ''; |
| 2384 | 2501 | $tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1'); |
| 2385 | - } |
|
| 2386 | - elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
| 2502 | + } elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
| 2387 | 2503 | { |
| 2388 | 2504 | $tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : ''); |
| 2389 | 2505 | $tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : ''); |
| 2506 | + } else { |
|
| 2507 | + $tag['content'] = $tag['disabled_content']; |
|
| 2390 | 2508 | } |
| 2391 | - else |
|
| 2392 | - $tag['content'] = $tag['disabled_content']; |
|
| 2393 | 2509 | } |
| 2394 | 2510 | |
| 2395 | 2511 | // we use this a lot |
@@ -2399,8 +2515,9 @@ discard block |
||
| 2399 | 2515 | if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level'])) |
| 2400 | 2516 | { |
| 2401 | 2517 | $n = count($open_tags) - 1; |
| 2402 | - while (empty($open_tags[$n]['block_level']) && $n >= 0) |
|
| 2403 | - $n--; |
|
| 2518 | + while (empty($open_tags[$n]['block_level']) && $n >= 0) { |
|
| 2519 | + $n--; |
|
| 2520 | + } |
|
| 2404 | 2521 | |
| 2405 | 2522 | // Close all the non block level tags so this tag isn't surrounded by them. |
| 2406 | 2523 | for ($i = count($open_tags) - 1; $i > $n; $i--) |
@@ -2412,12 +2529,15 @@ discard block |
||
| 2412 | 2529 | |
| 2413 | 2530 | // Trim or eat trailing stuff... see comment at the end of the big loop. |
| 2414 | 2531 | $whitespace_regex = ''; |
| 2415 | - if (!empty($tag['block_level'])) |
|
| 2416 | - $whitespace_regex .= '( |\s)*<br>'; |
|
| 2417 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside') |
|
| 2418 | - $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
| 2419 | - if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) |
|
| 2420 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2532 | + if (!empty($tag['block_level'])) { |
|
| 2533 | + $whitespace_regex .= '( |\s)*<br>'; |
|
| 2534 | + } |
|
| 2535 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside') { |
|
| 2536 | + $whitespace_regex .= empty($tag['require_parents']) ? '( |\s)*' : '(<br>| |\s)*'; |
|
| 2537 | + } |
|
| 2538 | + if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) { |
|
| 2539 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2540 | + } |
|
| 2421 | 2541 | |
| 2422 | 2542 | array_pop($open_tags); |
| 2423 | 2543 | } |
@@ -2435,16 +2555,19 @@ discard block |
||
| 2435 | 2555 | elseif ($tag['type'] == 'unparsed_content') |
| 2436 | 2556 | { |
| 2437 | 2557 | $pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1); |
| 2438 | - if ($pos2 === false) |
|
| 2439 | - continue; |
|
| 2558 | + if ($pos2 === false) { |
|
| 2559 | + continue; |
|
| 2560 | + } |
|
| 2440 | 2561 | |
| 2441 | 2562 | $data = substr($message, $pos1, $pos2 - $pos1); |
| 2442 | 2563 | |
| 2443 | - if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') |
|
| 2444 | - $data = substr($data, 4); |
|
| 2564 | + if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') { |
|
| 2565 | + $data = substr($data, 4); |
|
| 2566 | + } |
|
| 2445 | 2567 | |
| 2446 | - if (isset($tag['validate'])) |
|
| 2447 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2568 | + if (isset($tag['validate'])) { |
|
| 2569 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2570 | + } |
|
| 2448 | 2571 | |
| 2449 | 2572 | $code = strtr($tag['content'], array('$1' => $data)); |
| 2450 | 2573 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen); |
@@ -2460,34 +2583,40 @@ discard block |
||
| 2460 | 2583 | if (isset($tag['quoted'])) |
| 2461 | 2584 | { |
| 2462 | 2585 | $quoted = substr($message, $pos1, 6) == '"'; |
| 2463 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
| 2464 | - continue; |
|
| 2586 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
| 2587 | + continue; |
|
| 2588 | + } |
|
| 2465 | 2589 | |
| 2466 | - if ($quoted) |
|
| 2467 | - $pos1 += 6; |
|
| 2590 | + if ($quoted) { |
|
| 2591 | + $pos1 += 6; |
|
| 2592 | + } |
|
| 2593 | + } else { |
|
| 2594 | + $quoted = false; |
|
| 2468 | 2595 | } |
| 2469 | - else |
|
| 2470 | - $quoted = false; |
|
| 2471 | 2596 | |
| 2472 | 2597 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
| 2473 | - if ($pos2 === false) |
|
| 2474 | - continue; |
|
| 2598 | + if ($pos2 === false) { |
|
| 2599 | + continue; |
|
| 2600 | + } |
|
| 2475 | 2601 | |
| 2476 | 2602 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
| 2477 | - if ($pos3 === false) |
|
| 2478 | - continue; |
|
| 2603 | + if ($pos3 === false) { |
|
| 2604 | + continue; |
|
| 2605 | + } |
|
| 2479 | 2606 | |
| 2480 | 2607 | $data = array( |
| 2481 | 2608 | substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))), |
| 2482 | 2609 | substr($message, $pos1, $pos2 - $pos1) |
| 2483 | 2610 | ); |
| 2484 | 2611 | |
| 2485 | - if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') |
|
| 2486 | - $data[0] = substr($data[0], 4); |
|
| 2612 | + if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') { |
|
| 2613 | + $data[0] = substr($data[0], 4); |
|
| 2614 | + } |
|
| 2487 | 2615 | |
| 2488 | 2616 | // Validation for my parking, please! |
| 2489 | - if (isset($tag['validate'])) |
|
| 2490 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2617 | + if (isset($tag['validate'])) { |
|
| 2618 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2619 | + } |
|
| 2491 | 2620 | |
| 2492 | 2621 | $code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1])); |
| 2493 | 2622 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
@@ -2504,23 +2633,27 @@ discard block |
||
| 2504 | 2633 | elseif ($tag['type'] == 'unparsed_commas_content') |
| 2505 | 2634 | { |
| 2506 | 2635 | $pos2 = strpos($message, ']', $pos1); |
| 2507 | - if ($pos2 === false) |
|
| 2508 | - continue; |
|
| 2636 | + if ($pos2 === false) { |
|
| 2637 | + continue; |
|
| 2638 | + } |
|
| 2509 | 2639 | |
| 2510 | 2640 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
| 2511 | - if ($pos3 === false) |
|
| 2512 | - continue; |
|
| 2641 | + if ($pos3 === false) { |
|
| 2642 | + continue; |
|
| 2643 | + } |
|
| 2513 | 2644 | |
| 2514 | 2645 | // We want $1 to be the content, and the rest to be csv. |
| 2515 | 2646 | $data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1)); |
| 2516 | 2647 | $data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1); |
| 2517 | 2648 | |
| 2518 | - if (isset($tag['validate'])) |
|
| 2519 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2649 | + if (isset($tag['validate'])) { |
|
| 2650 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2651 | + } |
|
| 2520 | 2652 | |
| 2521 | 2653 | $code = $tag['content']; |
| 2522 | - foreach ($data as $k => $d) |
|
| 2523 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2654 | + foreach ($data as $k => $d) { |
|
| 2655 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2656 | + } |
|
| 2524 | 2657 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
| 2525 | 2658 | $pos += strlen($code) - 1 + 2; |
| 2526 | 2659 | } |
@@ -2528,24 +2661,28 @@ discard block |
||
| 2528 | 2661 | elseif ($tag['type'] == 'unparsed_commas') |
| 2529 | 2662 | { |
| 2530 | 2663 | $pos2 = strpos($message, ']', $pos1); |
| 2531 | - if ($pos2 === false) |
|
| 2532 | - continue; |
|
| 2664 | + if ($pos2 === false) { |
|
| 2665 | + continue; |
|
| 2666 | + } |
|
| 2533 | 2667 | |
| 2534 | 2668 | $data = explode(',', substr($message, $pos1, $pos2 - $pos1)); |
| 2535 | 2669 | |
| 2536 | - if (isset($tag['validate'])) |
|
| 2537 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2670 | + if (isset($tag['validate'])) { |
|
| 2671 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2672 | + } |
|
| 2538 | 2673 | |
| 2539 | 2674 | // Fix after, for disabled code mainly. |
| 2540 | - foreach ($data as $k => $d) |
|
| 2541 | - $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
| 2675 | + foreach ($data as $k => $d) { |
|
| 2676 | + $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
| 2677 | + } |
|
| 2542 | 2678 | |
| 2543 | 2679 | $open_tags[] = $tag; |
| 2544 | 2680 | |
| 2545 | 2681 | // Replace them out, $1, $2, $3, $4, etc. |
| 2546 | 2682 | $code = $tag['before']; |
| 2547 | - foreach ($data as $k => $d) |
|
| 2548 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2683 | + foreach ($data as $k => $d) { |
|
| 2684 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2685 | + } |
|
| 2549 | 2686 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1); |
| 2550 | 2687 | $pos += strlen($code) - 1 + 2; |
| 2551 | 2688 | } |
@@ -2556,28 +2693,33 @@ discard block |
||
| 2556 | 2693 | if (isset($tag['quoted'])) |
| 2557 | 2694 | { |
| 2558 | 2695 | $quoted = substr($message, $pos1, 6) == '"'; |
| 2559 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
| 2560 | - continue; |
|
| 2696 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
| 2697 | + continue; |
|
| 2698 | + } |
|
| 2561 | 2699 | |
| 2562 | - if ($quoted) |
|
| 2563 | - $pos1 += 6; |
|
| 2700 | + if ($quoted) { |
|
| 2701 | + $pos1 += 6; |
|
| 2702 | + } |
|
| 2703 | + } else { |
|
| 2704 | + $quoted = false; |
|
| 2564 | 2705 | } |
| 2565 | - else |
|
| 2566 | - $quoted = false; |
|
| 2567 | 2706 | |
| 2568 | 2707 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
| 2569 | - if ($pos2 === false) |
|
| 2570 | - continue; |
|
| 2708 | + if ($pos2 === false) { |
|
| 2709 | + continue; |
|
| 2710 | + } |
|
| 2571 | 2711 | |
| 2572 | 2712 | $data = substr($message, $pos1, $pos2 - $pos1); |
| 2573 | 2713 | |
| 2574 | 2714 | // Validation for my parking, please! |
| 2575 | - if (isset($tag['validate'])) |
|
| 2576 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2715 | + if (isset($tag['validate'])) { |
|
| 2716 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2717 | + } |
|
| 2577 | 2718 | |
| 2578 | 2719 | // For parsed content, we must recurse to avoid security problems. |
| 2579 | - if ($tag['type'] != 'unparsed_equals') |
|
| 2580 | - $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
| 2720 | + if ($tag['type'] != 'unparsed_equals') { |
|
| 2721 | + $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
| 2722 | + } |
|
| 2581 | 2723 | |
| 2582 | 2724 | $tag['after'] = strtr($tag['after'], array('$1' => $data)); |
| 2583 | 2725 | |
@@ -2589,34 +2731,40 @@ discard block |
||
| 2589 | 2731 | } |
| 2590 | 2732 | |
| 2591 | 2733 | // If this is block level, eat any breaks after it. |
| 2592 | - if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') |
|
| 2593 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
| 2734 | + if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') { |
|
| 2735 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
| 2736 | + } |
|
| 2594 | 2737 | |
| 2595 | 2738 | // Are we trimming outside this tag? |
| 2596 | - if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) |
|
| 2597 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
| 2739 | + if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) { |
|
| 2740 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
| 2741 | + } |
|
| 2598 | 2742 | } |
| 2599 | 2743 | |
| 2600 | 2744 | // Close any remaining tags. |
| 2601 | - while ($tag = array_pop($open_tags)) |
|
| 2602 | - $message .= "\n" . $tag['after'] . "\n"; |
|
| 2745 | + while ($tag = array_pop($open_tags)) { |
|
| 2746 | + $message .= "\n" . $tag['after'] . "\n"; |
|
| 2747 | + } |
|
| 2603 | 2748 | |
| 2604 | 2749 | // Parse the smileys within the parts where it can be done safely. |
| 2605 | 2750 | if ($smileys === true) |
| 2606 | 2751 | { |
| 2607 | 2752 | $message_parts = explode("\n", $message); |
| 2608 | - for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) |
|
| 2609 | - parsesmileys($message_parts[$i]); |
|
| 2753 | + for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) { |
|
| 2754 | + parsesmileys($message_parts[$i]); |
|
| 2755 | + } |
|
| 2610 | 2756 | |
| 2611 | 2757 | $message = implode('', $message_parts); |
| 2612 | 2758 | } |
| 2613 | 2759 | |
| 2614 | 2760 | // No smileys, just get rid of the markers. |
| 2615 | - else |
|
| 2616 | - $message = strtr($message, array("\n" => '')); |
|
| 2761 | + else { |
|
| 2762 | + $message = strtr($message, array("\n" => '')); |
|
| 2763 | + } |
|
| 2617 | 2764 | |
| 2618 | - if ($message !== '' && $message[0] === ' ') |
|
| 2619 | - $message = ' ' . substr($message, 1); |
|
| 2765 | + if ($message !== '' && $message[0] === ' ') { |
|
| 2766 | + $message = ' ' . substr($message, 1); |
|
| 2767 | + } |
|
| 2620 | 2768 | |
| 2621 | 2769 | // Cleanup whitespace. |
| 2622 | 2770 | $message = strtr($message, array(' ' => ' ', "\r" => '', "\n" => '<br>', '<br> ' => '<br> ', ' ' => "\n")); |
@@ -2625,15 +2773,16 @@ discard block |
||
| 2625 | 2773 | call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
| 2626 | 2774 | |
| 2627 | 2775 | // Cache the output if it took some time... |
| 2628 | - if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) |
|
| 2629 | - cache_put_data($cache_key, $message, 240); |
|
| 2776 | + if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) { |
|
| 2777 | + cache_put_data($cache_key, $message, 240); |
|
| 2778 | + } |
|
| 2630 | 2779 | |
| 2631 | 2780 | // If this was a force parse revert if needed. |
| 2632 | 2781 | if (!empty($parse_tags)) |
| 2633 | 2782 | { |
| 2634 | - if (empty($temp_bbc)) |
|
| 2635 | - $bbc_codes = array(); |
|
| 2636 | - else |
|
| 2783 | + if (empty($temp_bbc)) { |
|
| 2784 | + $bbc_codes = array(); |
|
| 2785 | + } else |
|
| 2637 | 2786 | { |
| 2638 | 2787 | $bbc_codes = $temp_bbc; |
| 2639 | 2788 | unset($temp_bbc); |
@@ -2660,8 +2809,9 @@ discard block |
||
| 2660 | 2809 | static $smileyPregSearch = null, $smileyPregReplacements = array(); |
| 2661 | 2810 | |
| 2662 | 2811 | // No smiley set at all?! |
| 2663 | - if ($user_info['smiley_set'] == 'none' || trim($message) == '') |
|
| 2664 | - return; |
|
| 2812 | + if ($user_info['smiley_set'] == 'none' || trim($message) == '') { |
|
| 2813 | + return; |
|
| 2814 | + } |
|
| 2665 | 2815 | |
| 2666 | 2816 | // If smileyPregSearch hasn't been set, do it now. |
| 2667 | 2817 | if (empty($smileyPregSearch)) |
@@ -2672,8 +2822,7 @@ discard block |
||
| 2672 | 2822 | $smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)'); |
| 2673 | 2823 | $smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif'); |
| 2674 | 2824 | $smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', ''); |
| 2675 | - } |
|
| 2676 | - else |
|
| 2825 | + } else |
|
| 2677 | 2826 | { |
| 2678 | 2827 | // Load the smileys in reverse order by length so they don't get parsed wrong. |
| 2679 | 2828 | if (($temp = cache_get_data('parsing_smileys', 480)) == null) |
@@ -2697,9 +2846,9 @@ discard block |
||
| 2697 | 2846 | $smcFunc['db_free_result']($result); |
| 2698 | 2847 | |
| 2699 | 2848 | cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480); |
| 2849 | + } else { |
|
| 2850 | + list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
| 2700 | 2851 | } |
| 2701 | - else |
|
| 2702 | - list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
| 2703 | 2852 | } |
| 2704 | 2853 | |
| 2705 | 2854 | // The non-breaking-space is a complex thing... |
@@ -2776,35 +2925,41 @@ discard block |
||
| 2776 | 2925 | global $scripturl, $context, $modSettings, $db_show_debug, $db_cache; |
| 2777 | 2926 | |
| 2778 | 2927 | // In case we have mail to send, better do that - as obExit doesn't always quite make it... |
| 2779 | - if (!empty($context['flush_mail'])) |
|
| 2780 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2928 | + if (!empty($context['flush_mail'])) { |
|
| 2929 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2781 | 2930 | AddMailQueue(true); |
| 2931 | + } |
|
| 2782 | 2932 | |
| 2783 | 2933 | $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:'; |
| 2784 | 2934 | |
| 2785 | - if ($add) |
|
| 2786 | - $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
| 2935 | + if ($add) { |
|
| 2936 | + $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
| 2937 | + } |
|
| 2787 | 2938 | |
| 2788 | 2939 | // Put the session ID in. |
| 2789 | - if (defined('SID') && SID != '') |
|
| 2790 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
| 2940 | + if (defined('SID') && SID != '') { |
|
| 2941 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
| 2942 | + } |
|
| 2791 | 2943 | // Keep that debug in their for template debugging! |
| 2792 | - elseif (isset($_GET['debug'])) |
|
| 2793 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
| 2944 | + elseif (isset($_GET['debug'])) { |
|
| 2945 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
| 2946 | + } |
|
| 2794 | 2947 | |
| 2795 | 2948 | if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed']))) |
| 2796 | 2949 | { |
| 2797 | - if (defined('SID') && SID != '') |
|
| 2798 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
| 2950 | + if (defined('SID') && SID != '') { |
|
| 2951 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
| 2799 | 2952 | function ($m) use ($scripturl) |
| 2800 | 2953 | { |
| 2801 | 2954 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); |
| 2955 | + } |
|
| 2802 | 2956 | }, $setLocation); |
| 2803 | - else |
|
| 2804 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
| 2957 | + else { |
|
| 2958 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
| 2805 | 2959 | function ($m) use ($scripturl) |
| 2806 | 2960 | { |
| 2807 | 2961 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); |
| 2962 | + } |
|
| 2808 | 2963 | }, $setLocation); |
| 2809 | 2964 | } |
| 2810 | 2965 | |
@@ -2815,8 +2970,9 @@ discard block |
||
| 2815 | 2970 | header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302); |
| 2816 | 2971 | |
| 2817 | 2972 | // Debugging. |
| 2818 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 2819 | - $_SESSION['debug_redirect'] = $db_cache; |
|
| 2973 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 2974 | + $_SESSION['debug_redirect'] = $db_cache; |
|
| 2975 | + } |
|
| 2820 | 2976 | |
| 2821 | 2977 | obExit(false); |
| 2822 | 2978 | } |
@@ -2835,51 +2991,60 @@ discard block |
||
| 2835 | 2991 | |
| 2836 | 2992 | // Attempt to prevent a recursive loop. |
| 2837 | 2993 | ++$level; |
| 2838 | - if ($level > 1 && !$from_fatal_error && !$has_fatal_error) |
|
| 2839 | - exit; |
|
| 2840 | - if ($from_fatal_error) |
|
| 2841 | - $has_fatal_error = true; |
|
| 2994 | + if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { |
|
| 2995 | + exit; |
|
| 2996 | + } |
|
| 2997 | + if ($from_fatal_error) { |
|
| 2998 | + $has_fatal_error = true; |
|
| 2999 | + } |
|
| 2842 | 3000 | |
| 2843 | 3001 | // Clear out the stat cache. |
| 2844 | 3002 | trackStats(); |
| 2845 | 3003 | |
| 2846 | 3004 | // If we have mail to send, send it. |
| 2847 | - if (!empty($context['flush_mail'])) |
|
| 2848 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 3005 | + if (!empty($context['flush_mail'])) { |
|
| 3006 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2849 | 3007 | AddMailQueue(true); |
| 3008 | + } |
|
| 2850 | 3009 | |
| 2851 | 3010 | $do_header = $header === null ? !$header_done : $header; |
| 2852 | - if ($do_footer === null) |
|
| 2853 | - $do_footer = $do_header; |
|
| 3011 | + if ($do_footer === null) { |
|
| 3012 | + $do_footer = $do_header; |
|
| 3013 | + } |
|
| 2854 | 3014 | |
| 2855 | 3015 | // Has the template/header been done yet? |
| 2856 | 3016 | if ($do_header) |
| 2857 | 3017 | { |
| 2858 | 3018 | // Was the page title set last minute? Also update the HTML safe one. |
| 2859 | - if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) |
|
| 2860 | - $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
| 3019 | + if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { |
|
| 3020 | + $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
| 3021 | + } |
|
| 2861 | 3022 | |
| 2862 | 3023 | // Start up the session URL fixer. |
| 2863 | 3024 | ob_start('ob_sessrewrite'); |
| 2864 | 3025 | |
| 2865 | - if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) |
|
| 2866 | - $buffers = explode(',', $settings['output_buffers']); |
|
| 2867 | - elseif (!empty($settings['output_buffers'])) |
|
| 2868 | - $buffers = $settings['output_buffers']; |
|
| 2869 | - else |
|
| 2870 | - $buffers = array(); |
|
| 3026 | + if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) { |
|
| 3027 | + $buffers = explode(',', $settings['output_buffers']); |
|
| 3028 | + } elseif (!empty($settings['output_buffers'])) { |
|
| 3029 | + $buffers = $settings['output_buffers']; |
|
| 3030 | + } else { |
|
| 3031 | + $buffers = array(); |
|
| 3032 | + } |
|
| 2871 | 3033 | |
| 2872 | - if (isset($modSettings['integrate_buffer'])) |
|
| 2873 | - $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
| 3034 | + if (isset($modSettings['integrate_buffer'])) { |
|
| 3035 | + $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
| 3036 | + } |
|
| 2874 | 3037 | |
| 2875 | - if (!empty($buffers)) |
|
| 2876 | - foreach ($buffers as $function) |
|
| 3038 | + if (!empty($buffers)) { |
|
| 3039 | + foreach ($buffers as $function) |
|
| 2877 | 3040 | { |
| 2878 | 3041 | $call = call_helper($function, true); |
| 3042 | + } |
|
| 2879 | 3043 | |
| 2880 | 3044 | // Is it valid? |
| 2881 | - if (!empty($call)) |
|
| 2882 | - ob_start($call); |
|
| 3045 | + if (!empty($call)) { |
|
| 3046 | + ob_start($call); |
|
| 3047 | + } |
|
| 2883 | 3048 | } |
| 2884 | 3049 | |
| 2885 | 3050 | // Display the screen in the logical order. |
@@ -2891,8 +3056,9 @@ discard block |
||
| 2891 | 3056 | loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); |
| 2892 | 3057 | |
| 2893 | 3058 | // Anything special to put out? |
| 2894 | - if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) |
|
| 2895 | - echo $context['insert_after_template']; |
|
| 3059 | + if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) { |
|
| 3060 | + echo $context['insert_after_template']; |
|
| 3061 | + } |
|
| 2896 | 3062 | |
| 2897 | 3063 | // Just so we don't get caught in an endless loop of errors from the footer... |
| 2898 | 3064 | if (!$footer_done) |
@@ -2901,14 +3067,16 @@ discard block |
||
| 2901 | 3067 | template_footer(); |
| 2902 | 3068 | |
| 2903 | 3069 | // (since this is just debugging... it's okay that it's after </html>.) |
| 2904 | - if (!isset($_REQUEST['xml'])) |
|
| 2905 | - displayDebug(); |
|
| 3070 | + if (!isset($_REQUEST['xml'])) { |
|
| 3071 | + displayDebug(); |
|
| 3072 | + } |
|
| 2906 | 3073 | } |
| 2907 | 3074 | } |
| 2908 | 3075 | |
| 2909 | 3076 | // Remember this URL in case someone doesn't like sending HTTP_REFERER. |
| 2910 | - if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) |
|
| 2911 | - $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
| 3077 | + if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { |
|
| 3078 | + $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
| 3079 | + } |
|
| 2912 | 3080 | |
| 2913 | 3081 | // For session check verification.... don't switch browsers... |
| 2914 | 3082 | $_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT']; |
@@ -2917,9 +3085,10 @@ discard block |
||
| 2917 | 3085 | call_integration_hook('integrate_exit', array($do_footer)); |
| 2918 | 3086 | |
| 2919 | 3087 | // Don't exit if we're coming from index.php; that will pass through normally. |
| 2920 | - if (!$from_index) |
|
| 2921 | - exit; |
|
| 2922 | -} |
|
| 3088 | + if (!$from_index) { |
|
| 3089 | + exit; |
|
| 3090 | + } |
|
| 3091 | + } |
|
| 2923 | 3092 | |
| 2924 | 3093 | /** |
| 2925 | 3094 | * Get the size of a specified image with better error handling. |
@@ -2938,8 +3107,9 @@ discard block |
||
| 2938 | 3107 | $url = str_replace(' ', '%20', $url); |
| 2939 | 3108 | |
| 2940 | 3109 | // Can we pull this from the cache... please please? |
| 2941 | - if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) |
|
| 2942 | - return $temp; |
|
| 3110 | + if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) { |
|
| 3111 | + return $temp; |
|
| 3112 | + } |
|
| 2943 | 3113 | $t = microtime(); |
| 2944 | 3114 | |
| 2945 | 3115 | // Get the host to pester... |
@@ -2949,12 +3119,10 @@ discard block |
||
| 2949 | 3119 | if ($url == '' || $url == 'http://' || $url == 'https://') |
| 2950 | 3120 | { |
| 2951 | 3121 | return false; |
| 2952 | - } |
|
| 2953 | - elseif (!isset($match[1])) |
|
| 3122 | + } elseif (!isset($match[1])) |
|
| 2954 | 3123 | { |
| 2955 | 3124 | $size = @getimagesize($url); |
| 2956 | - } |
|
| 2957 | - else |
|
| 3125 | + } else |
|
| 2958 | 3126 | { |
| 2959 | 3127 | // Try to connect to the server... give it half a second. |
| 2960 | 3128 | $temp = 0; |
@@ -2993,12 +3161,14 @@ discard block |
||
| 2993 | 3161 | } |
| 2994 | 3162 | |
| 2995 | 3163 | // If we didn't get it, we failed. |
| 2996 | - if (!isset($size)) |
|
| 2997 | - $size = false; |
|
| 3164 | + if (!isset($size)) { |
|
| 3165 | + $size = false; |
|
| 3166 | + } |
|
| 2998 | 3167 | |
| 2999 | 3168 | // If this took a long time, we may never have to do it again, but then again we might... |
| 3000 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) |
|
| 3001 | - cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
| 3169 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) { |
|
| 3170 | + cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
| 3171 | + } |
|
| 3002 | 3172 | |
| 3003 | 3173 | // Didn't work. |
| 3004 | 3174 | return $size; |
@@ -3016,8 +3186,9 @@ discard block |
||
| 3016 | 3186 | |
| 3017 | 3187 | // Under SSI this function can be called more then once. That can cause some problems. |
| 3018 | 3188 | // So only run the function once unless we are forced to run it again. |
| 3019 | - if ($loaded && !$forceload) |
|
| 3020 | - return; |
|
| 3189 | + if ($loaded && !$forceload) { |
|
| 3190 | + return; |
|
| 3191 | + } |
|
| 3021 | 3192 | |
| 3022 | 3193 | $loaded = true; |
| 3023 | 3194 | |
@@ -3029,14 +3200,16 @@ discard block |
||
| 3029 | 3200 | $context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))))); |
| 3030 | 3201 | for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++) |
| 3031 | 3202 | { |
| 3032 | - if (trim($context['news_lines'][$i]) == '') |
|
| 3033 | - continue; |
|
| 3203 | + if (trim($context['news_lines'][$i]) == '') { |
|
| 3204 | + continue; |
|
| 3205 | + } |
|
| 3034 | 3206 | |
| 3035 | 3207 | // Clean it up for presentation ;). |
| 3036 | 3208 | $context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i); |
| 3037 | 3209 | } |
| 3038 | - if (!empty($context['news_lines'])) |
|
| 3039 | - $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
| 3210 | + if (!empty($context['news_lines'])) { |
|
| 3211 | + $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
| 3212 | + } |
|
| 3040 | 3213 | |
| 3041 | 3214 | if (!$user_info['is_guest']) |
| 3042 | 3215 | { |
@@ -3045,40 +3218,48 @@ discard block |
||
| 3045 | 3218 | $context['user']['alerts'] = &$user_info['alerts']; |
| 3046 | 3219 | |
| 3047 | 3220 | // Personal message popup... |
| 3048 | - if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) |
|
| 3049 | - $context['user']['popup_messages'] = true; |
|
| 3050 | - else |
|
| 3051 | - $context['user']['popup_messages'] = false; |
|
| 3221 | + if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) { |
|
| 3222 | + $context['user']['popup_messages'] = true; |
|
| 3223 | + } else { |
|
| 3224 | + $context['user']['popup_messages'] = false; |
|
| 3225 | + } |
|
| 3052 | 3226 | $_SESSION['unread_messages'] = $user_info['unread_messages']; |
| 3053 | 3227 | |
| 3054 | - if (allowedTo('moderate_forum')) |
|
| 3055 | - $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
| 3228 | + if (allowedTo('moderate_forum')) { |
|
| 3229 | + $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
| 3230 | + } |
|
| 3056 | 3231 | |
| 3057 | 3232 | $context['user']['avatar'] = array(); |
| 3058 | 3233 | |
| 3059 | 3234 | // Check for gravatar first since we might be forcing them... |
| 3060 | 3235 | if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride'])) |
| 3061 | 3236 | { |
| 3062 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) |
|
| 3063 | - $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
| 3064 | - else |
|
| 3065 | - $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
| 3237 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) { |
|
| 3238 | + $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
| 3239 | + } else { |
|
| 3240 | + $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
| 3241 | + } |
|
| 3066 | 3242 | } |
| 3067 | 3243 | // Uploaded? |
| 3068 | - elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) |
|
| 3069 | - $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; |
|
| 3244 | + elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) { |
|
| 3245 | + $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; |
|
| 3246 | + } |
|
| 3070 | 3247 | // Full URL? |
| 3071 | - elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) |
|
| 3072 | - $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
| 3248 | + elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) { |
|
| 3249 | + $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
| 3250 | + } |
|
| 3073 | 3251 | // Otherwise we assume it's server stored. |
| 3074 | - elseif ($user_info['avatar']['url'] != '') |
|
| 3075 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
| 3252 | + elseif ($user_info['avatar']['url'] != '') { |
|
| 3253 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
| 3254 | + } |
|
| 3076 | 3255 | // No avatar at all? Fine, we have a big fat default avatar ;) |
| 3077 | - else |
|
| 3078 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
| 3256 | + else { |
|
| 3257 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
| 3258 | + } |
|
| 3079 | 3259 | |
| 3080 | - if (!empty($context['user']['avatar'])) |
|
| 3081 | - $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
| 3260 | + if (!empty($context['user']['avatar'])) { |
|
| 3261 | + $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
| 3262 | + } |
|
| 3082 | 3263 | |
| 3083 | 3264 | // Figure out how long they've been logged in. |
| 3084 | 3265 | $context['user']['total_time_logged_in'] = array( |
@@ -3086,8 +3267,7 @@ discard block |
||
| 3086 | 3267 | 'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600), |
| 3087 | 3268 | 'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60) |
| 3088 | 3269 | ); |
| 3089 | - } |
|
| 3090 | - else |
|
| 3270 | + } else |
|
| 3091 | 3271 | { |
| 3092 | 3272 | $context['user']['messages'] = 0; |
| 3093 | 3273 | $context['user']['unread_messages'] = 0; |
@@ -3095,12 +3275,14 @@ discard block |
||
| 3095 | 3275 | $context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0); |
| 3096 | 3276 | $context['user']['popup_messages'] = false; |
| 3097 | 3277 | |
| 3098 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) |
|
| 3099 | - $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
| 3278 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) { |
|
| 3279 | + $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
| 3280 | + } |
|
| 3100 | 3281 | |
| 3101 | 3282 | // If we've upgraded recently, go easy on the passwords. |
| 3102 | - if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) |
|
| 3103 | - $context['disable_login_hashing'] = true; |
|
| 3283 | + if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) { |
|
| 3284 | + $context['disable_login_hashing'] = true; |
|
| 3285 | + } |
|
| 3104 | 3286 | } |
| 3105 | 3287 | |
| 3106 | 3288 | // Setup the main menu items. |
@@ -3113,8 +3295,8 @@ discard block |
||
| 3113 | 3295 | $context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm'); |
| 3114 | 3296 | |
| 3115 | 3297 | // 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array. |
| 3116 | - if ($context['show_pm_popup']) |
|
| 3117 | - addInlineJavaScript(' |
|
| 3298 | + if ($context['show_pm_popup']) { |
|
| 3299 | + addInlineJavaScript(' |
|
| 3118 | 3300 | jQuery(document).ready(function($) { |
| 3119 | 3301 | new smc_Popup({ |
| 3120 | 3302 | heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ', |
@@ -3122,15 +3304,17 @@ discard block |
||
| 3122 | 3304 | icon_class: \'generic_icons mail_new\' |
| 3123 | 3305 | }); |
| 3124 | 3306 | });'); |
| 3307 | + } |
|
| 3125 | 3308 | |
| 3126 | 3309 | // Add a generic "Are you sure?" confirmation message. |
| 3127 | 3310 | addInlineJavaScript(' |
| 3128 | 3311 | var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); |
| 3129 | 3312 | |
| 3130 | 3313 | // Now add the capping code for avatars. |
| 3131 | - if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') |
|
| 3132 | - addInlineCss(' |
|
| 3314 | + if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') { |
|
| 3315 | + addInlineCss(' |
|
| 3133 | 3316 | img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }'); |
| 3317 | + } |
|
| 3134 | 3318 | |
| 3135 | 3319 | // This looks weird, but it's because BoardIndex.php references the variable. |
| 3136 | 3320 | $context['common_stats']['latest_member'] = array( |
@@ -3147,11 +3331,13 @@ discard block |
||
| 3147 | 3331 | ); |
| 3148 | 3332 | $context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']); |
| 3149 | 3333 | |
| 3150 | - if (empty($settings['theme_version'])) |
|
| 3151 | - addJavaScriptVar('smf_scripturl', $scripturl); |
|
| 3334 | + if (empty($settings['theme_version'])) { |
|
| 3335 | + addJavaScriptVar('smf_scripturl', $scripturl); |
|
| 3336 | + } |
|
| 3152 | 3337 | |
| 3153 | - if (!isset($context['page_title'])) |
|
| 3154 | - $context['page_title'] = ''; |
|
| 3338 | + if (!isset($context['page_title'])) { |
|
| 3339 | + $context['page_title'] = ''; |
|
| 3340 | + } |
|
| 3155 | 3341 | |
| 3156 | 3342 | // Set some specific vars. |
| 3157 | 3343 | $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
@@ -3161,21 +3347,23 @@ discard block |
||
| 3161 | 3347 | $context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']); |
| 3162 | 3348 | $context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']); |
| 3163 | 3349 | |
| 3164 | - if (!empty($context['meta_keywords'])) |
|
| 3165 | - $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
| 3350 | + if (!empty($context['meta_keywords'])) { |
|
| 3351 | + $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
| 3352 | + } |
|
| 3166 | 3353 | |
| 3167 | - if (!empty($context['canonical_url'])) |
|
| 3168 | - $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
| 3354 | + if (!empty($context['canonical_url'])) { |
|
| 3355 | + $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
| 3356 | + } |
|
| 3169 | 3357 | |
| 3170 | - if (!empty($settings['og_image'])) |
|
| 3171 | - $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
| 3358 | + if (!empty($settings['og_image'])) { |
|
| 3359 | + $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
| 3360 | + } |
|
| 3172 | 3361 | |
| 3173 | 3362 | if (!empty($context['meta_description'])) |
| 3174 | 3363 | { |
| 3175 | 3364 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']); |
| 3176 | 3365 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']); |
| 3177 | - } |
|
| 3178 | - else |
|
| 3366 | + } else |
|
| 3179 | 3367 | { |
| 3180 | 3368 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']); |
| 3181 | 3369 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']); |
@@ -3200,8 +3388,9 @@ discard block |
||
| 3200 | 3388 | $memory_needed = memoryReturnBytes($needed); |
| 3201 | 3389 | |
| 3202 | 3390 | // should we account for how much is currently being used? |
| 3203 | - if ($in_use) |
|
| 3204 | - $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
| 3391 | + if ($in_use) { |
|
| 3392 | + $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
| 3393 | + } |
|
| 3205 | 3394 | |
| 3206 | 3395 | // if more is needed, request it |
| 3207 | 3396 | if ($memory_current < $memory_needed) |
@@ -3224,8 +3413,9 @@ discard block |
||
| 3224 | 3413 | */ |
| 3225 | 3414 | function memoryReturnBytes($val) |
| 3226 | 3415 | { |
| 3227 | - if (is_integer($val)) |
|
| 3228 | - return $val; |
|
| 3416 | + if (is_integer($val)) { |
|
| 3417 | + return $val; |
|
| 3418 | + } |
|
| 3229 | 3419 | |
| 3230 | 3420 | // Separate the number from the designator |
| 3231 | 3421 | $val = trim($val); |
@@ -3261,10 +3451,11 @@ discard block |
||
| 3261 | 3451 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
| 3262 | 3452 | |
| 3263 | 3453 | // Are we debugging the template/html content? |
| 3264 | - if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) |
|
| 3265 | - header('Content-Type: application/xhtml+xml'); |
|
| 3266 | - elseif (!isset($_REQUEST['xml'])) |
|
| 3267 | - header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3454 | + if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) { |
|
| 3455 | + header('Content-Type: application/xhtml+xml'); |
|
| 3456 | + } elseif (!isset($_REQUEST['xml'])) { |
|
| 3457 | + header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3458 | + } |
|
| 3268 | 3459 | } |
| 3269 | 3460 | |
| 3270 | 3461 | header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
@@ -3273,8 +3464,9 @@ discard block |
||
| 3273 | 3464 | if ($context['in_maintenance'] && $context['user']['is_admin']) |
| 3274 | 3465 | { |
| 3275 | 3466 | $position = array_search('body', $context['template_layers']); |
| 3276 | - if ($position === false) |
|
| 3277 | - $position = array_search('main', $context['template_layers']); |
|
| 3467 | + if ($position === false) { |
|
| 3468 | + $position = array_search('main', $context['template_layers']); |
|
| 3469 | + } |
|
| 3278 | 3470 | |
| 3279 | 3471 | if ($position !== false) |
| 3280 | 3472 | { |
@@ -3302,23 +3494,25 @@ discard block |
||
| 3302 | 3494 | |
| 3303 | 3495 | foreach ($securityFiles as $i => $securityFile) |
| 3304 | 3496 | { |
| 3305 | - if (!file_exists($boarddir . '/' . $securityFile)) |
|
| 3306 | - unset($securityFiles[$i]); |
|
| 3497 | + if (!file_exists($boarddir . '/' . $securityFile)) { |
|
| 3498 | + unset($securityFiles[$i]); |
|
| 3499 | + } |
|
| 3307 | 3500 | } |
| 3308 | 3501 | |
| 3309 | 3502 | // We are already checking so many files...just few more doesn't make any difference! :P |
| 3310 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
| 3311 | - $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
| 3312 | - |
|
| 3313 | - else |
|
| 3314 | - $path = $modSettings['attachmentUploadDir']; |
|
| 3503 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
| 3504 | + $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
| 3505 | + } else { |
|
| 3506 | + $path = $modSettings['attachmentUploadDir']; |
|
| 3507 | + } |
|
| 3315 | 3508 | |
| 3316 | 3509 | secureDirectory($path, true); |
| 3317 | 3510 | secureDirectory($cachedir); |
| 3318 | 3511 | |
| 3319 | 3512 | // If agreement is enabled, at least the english version shall exists |
| 3320 | - if ($modSettings['requireAgreement']) |
|
| 3321 | - $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
| 3513 | + if ($modSettings['requireAgreement']) { |
|
| 3514 | + $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
| 3515 | + } |
|
| 3322 | 3516 | |
| 3323 | 3517 | if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement)) |
| 3324 | 3518 | { |
@@ -3333,18 +3527,21 @@ discard block |
||
| 3333 | 3527 | echo ' |
| 3334 | 3528 | ', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>'; |
| 3335 | 3529 | |
| 3336 | - if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') |
|
| 3337 | - echo ' |
|
| 3530 | + if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') { |
|
| 3531 | + echo ' |
|
| 3338 | 3532 | ', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>'; |
| 3533 | + } |
|
| 3339 | 3534 | } |
| 3340 | 3535 | |
| 3341 | - if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) |
|
| 3342 | - echo ' |
|
| 3536 | + if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) { |
|
| 3537 | + echo ' |
|
| 3343 | 3538 | <strong>', $txt['cache_writable'], '</strong><br>'; |
| 3539 | + } |
|
| 3344 | 3540 | |
| 3345 | - if (!empty($agreement)) |
|
| 3346 | - echo ' |
|
| 3541 | + if (!empty($agreement)) { |
|
| 3542 | + echo ' |
|
| 3347 | 3543 | <strong>', $txt['agreement_missing'], '</strong><br>'; |
| 3544 | + } |
|
| 3348 | 3545 | |
| 3349 | 3546 | echo ' |
| 3350 | 3547 | </p> |
@@ -3359,16 +3556,18 @@ discard block |
||
| 3359 | 3556 | <div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;"> |
| 3360 | 3557 | ', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']); |
| 3361 | 3558 | |
| 3362 | - if (!empty($_SESSION['ban']['cannot_post']['reason'])) |
|
| 3363 | - echo ' |
|
| 3559 | + if (!empty($_SESSION['ban']['cannot_post']['reason'])) { |
|
| 3560 | + echo ' |
|
| 3364 | 3561 | <div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>'; |
| 3562 | + } |
|
| 3365 | 3563 | |
| 3366 | - if (!empty($_SESSION['ban']['expire_time'])) |
|
| 3367 | - echo ' |
|
| 3564 | + if (!empty($_SESSION['ban']['expire_time'])) { |
|
| 3565 | + echo ' |
|
| 3368 | 3566 | <div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>'; |
| 3369 | - else |
|
| 3370 | - echo ' |
|
| 3567 | + } else { |
|
| 3568 | + echo ' |
|
| 3371 | 3569 | <div>', $txt['your_ban_expires_never'], '</div>'; |
| 3570 | + } |
|
| 3372 | 3571 | |
| 3373 | 3572 | echo ' |
| 3374 | 3573 | </div>'; |
@@ -3384,8 +3583,9 @@ discard block |
||
| 3384 | 3583 | global $forum_copyright, $software_year, $forum_version; |
| 3385 | 3584 | |
| 3386 | 3585 | // Don't display copyright for things like SSI. |
| 3387 | - if (!isset($forum_version) || !isset($software_year)) |
|
| 3388 | - return; |
|
| 3586 | + if (!isset($forum_version) || !isset($software_year)) { |
|
| 3587 | + return; |
|
| 3588 | + } |
|
| 3389 | 3589 | |
| 3390 | 3590 | // Put in the version... |
| 3391 | 3591 | printf($forum_copyright, $forum_version, $software_year); |
@@ -3403,9 +3603,10 @@ discard block |
||
| 3403 | 3603 | $context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3)); |
| 3404 | 3604 | $context['load_queries'] = $db_count; |
| 3405 | 3605 | |
| 3406 | - foreach (array_reverse($context['template_layers']) as $layer) |
|
| 3407 | - loadSubTemplate($layer . '_below', true); |
|
| 3408 | -} |
|
| 3606 | + foreach (array_reverse($context['template_layers']) as $layer) { |
|
| 3607 | + loadSubTemplate($layer . '_below', true); |
|
| 3608 | + } |
|
| 3609 | + } |
|
| 3409 | 3610 | |
| 3410 | 3611 | /** |
| 3411 | 3612 | * Output the Javascript files |
@@ -3436,8 +3637,7 @@ discard block |
||
| 3436 | 3637 | { |
| 3437 | 3638 | echo ' |
| 3438 | 3639 | var ', $key, ';'; |
| 3439 | - } |
|
| 3440 | - else |
|
| 3640 | + } else |
|
| 3441 | 3641 | { |
| 3442 | 3642 | echo ' |
| 3443 | 3643 | var ', $key, ' = ', $value, ';'; |
@@ -3452,26 +3652,27 @@ discard block |
||
| 3452 | 3652 | foreach ($context['javascript_files'] as $id => $js_file) |
| 3453 | 3653 | { |
| 3454 | 3654 | // Last minute call! allow theme authors to disable single files. |
| 3455 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
| 3456 | - continue; |
|
| 3655 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
| 3656 | + continue; |
|
| 3657 | + } |
|
| 3457 | 3658 | |
| 3458 | 3659 | // By default all files don't get minimized unless the file explicitly says so! |
| 3459 | 3660 | if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
| 3460 | 3661 | { |
| 3461 | - if ($do_deferred && !empty($js_file['options']['defer'])) |
|
| 3462 | - $toMinifyDefer[] = $js_file; |
|
| 3463 | - |
|
| 3464 | - elseif (!$do_deferred && empty($js_file['options']['defer'])) |
|
| 3465 | - $toMinify[] = $js_file; |
|
| 3662 | + if ($do_deferred && !empty($js_file['options']['defer'])) { |
|
| 3663 | + $toMinifyDefer[] = $js_file; |
|
| 3664 | + } elseif (!$do_deferred && empty($js_file['options']['defer'])) { |
|
| 3665 | + $toMinify[] = $js_file; |
|
| 3666 | + } |
|
| 3466 | 3667 | |
| 3467 | 3668 | // Grab a random seed. |
| 3468 | - if (!isset($minSeed)) |
|
| 3469 | - $minSeed = $js_file['options']['seed']; |
|
| 3470 | - } |
|
| 3471 | - |
|
| 3472 | - elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) |
|
| 3473 | - echo ' |
|
| 3669 | + if (!isset($minSeed)) { |
|
| 3670 | + $minSeed = $js_file['options']['seed']; |
|
| 3671 | + } |
|
| 3672 | + } elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) { |
|
| 3673 | + echo ' |
|
| 3474 | 3674 | <script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>'; |
| 3675 | + } |
|
| 3475 | 3676 | } |
| 3476 | 3677 | |
| 3477 | 3678 | if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer))) |
@@ -3479,14 +3680,14 @@ discard block |
||
| 3479 | 3680 | $result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred); |
| 3480 | 3681 | |
| 3481 | 3682 | // Minify process couldn't work, print each individual files. |
| 3482 | - if (!empty($result) && is_array($result)) |
|
| 3483 | - foreach ($result as $minFailedFile) |
|
| 3683 | + if (!empty($result) && is_array($result)) { |
|
| 3684 | + foreach ($result as $minFailedFile) |
|
| 3484 | 3685 | echo ' |
| 3485 | 3686 | <script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>'; |
| 3486 | - |
|
| 3487 | - else |
|
| 3488 | - echo ' |
|
| 3687 | + } else { |
|
| 3688 | + echo ' |
|
| 3489 | 3689 | <script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>'; |
| 3690 | + } |
|
| 3490 | 3691 | } |
| 3491 | 3692 | |
| 3492 | 3693 | // Inline JavaScript - Actually useful some times! |
@@ -3497,8 +3698,9 @@ discard block |
||
| 3497 | 3698 | echo ' |
| 3498 | 3699 | <script>'; |
| 3499 | 3700 | |
| 3500 | - foreach ($context['javascript_inline']['defer'] as $js_code) |
|
| 3501 | - echo $js_code; |
|
| 3701 | + foreach ($context['javascript_inline']['defer'] as $js_code) { |
|
| 3702 | + echo $js_code; |
|
| 3703 | + } |
|
| 3502 | 3704 | |
| 3503 | 3705 | echo ' |
| 3504 | 3706 | </script>'; |
@@ -3509,8 +3711,9 @@ discard block |
||
| 3509 | 3711 | echo ' |
| 3510 | 3712 | <script>'; |
| 3511 | 3713 | |
| 3512 | - foreach ($context['javascript_inline']['standard'] as $js_code) |
|
| 3513 | - echo $js_code; |
|
| 3714 | + foreach ($context['javascript_inline']['standard'] as $js_code) { |
|
| 3715 | + echo $js_code; |
|
| 3716 | + } |
|
| 3514 | 3717 | |
| 3515 | 3718 | echo ' |
| 3516 | 3719 | </script>'; |
@@ -3535,8 +3738,9 @@ discard block |
||
| 3535 | 3738 | foreach ($context['css_files'] as $id => $file) |
| 3536 | 3739 | { |
| 3537 | 3740 | // Last minute call! allow theme authors to disable single files. |
| 3538 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
| 3539 | - continue; |
|
| 3741 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
| 3742 | + continue; |
|
| 3743 | + } |
|
| 3540 | 3744 | |
| 3541 | 3745 | // By default all files don't get minimized unless the file explicitly says so! |
| 3542 | 3746 | if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
@@ -3544,12 +3748,12 @@ discard block |
||
| 3544 | 3748 | $toMinify[] = $file; |
| 3545 | 3749 | |
| 3546 | 3750 | // Grab a random seed. |
| 3547 | - if (!isset($minSeed)) |
|
| 3548 | - $minSeed = $file['options']['seed']; |
|
| 3751 | + if (!isset($minSeed)) { |
|
| 3752 | + $minSeed = $file['options']['seed']; |
|
| 3753 | + } |
|
| 3754 | + } else { |
|
| 3755 | + $normal[] = $file['fileUrl']; |
|
| 3549 | 3756 | } |
| 3550 | - |
|
| 3551 | - else |
|
| 3552 | - $normal[] = $file['fileUrl']; |
|
| 3553 | 3757 | } |
| 3554 | 3758 | |
| 3555 | 3759 | if (!empty($toMinify)) |
@@ -3557,28 +3761,30 @@ discard block |
||
| 3557 | 3761 | $result = custMinify($toMinify, 'css'); |
| 3558 | 3762 | |
| 3559 | 3763 | // Minify process couldn't work, print each individual files. |
| 3560 | - if (!empty($result) && is_array($result)) |
|
| 3561 | - foreach ($result as $minFailedFile) |
|
| 3764 | + if (!empty($result) && is_array($result)) { |
|
| 3765 | + foreach ($result as $minFailedFile) |
|
| 3562 | 3766 | echo ' |
| 3563 | 3767 | <link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">'; |
| 3564 | - |
|
| 3565 | - else |
|
| 3566 | - echo ' |
|
| 3768 | + } else { |
|
| 3769 | + echo ' |
|
| 3567 | 3770 | <link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">'; |
| 3771 | + } |
|
| 3568 | 3772 | } |
| 3569 | 3773 | |
| 3570 | 3774 | // Print the rest after the minified files. |
| 3571 | - if (!empty($normal)) |
|
| 3572 | - foreach ($normal as $nf) |
|
| 3775 | + if (!empty($normal)) { |
|
| 3776 | + foreach ($normal as $nf) |
|
| 3573 | 3777 | echo ' |
| 3574 | 3778 | <link rel="stylesheet" href="', $nf ,'">'; |
| 3779 | + } |
|
| 3575 | 3780 | |
| 3576 | 3781 | if ($db_show_debug === true) |
| 3577 | 3782 | { |
| 3578 | 3783 | // Try to keep only what's useful. |
| 3579 | 3784 | $repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => ''); |
| 3580 | - foreach ($context['css_files'] as $file) |
|
| 3581 | - $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
| 3785 | + foreach ($context['css_files'] as $file) { |
|
| 3786 | + $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
| 3787 | + } |
|
| 3582 | 3788 | } |
| 3583 | 3789 | |
| 3584 | 3790 | if (!empty($context['css_header'])) |
@@ -3586,9 +3792,10 @@ discard block |
||
| 3586 | 3792 | echo ' |
| 3587 | 3793 | <style>'; |
| 3588 | 3794 | |
| 3589 | - foreach ($context['css_header'] as $css) |
|
| 3590 | - echo $css .' |
|
| 3795 | + foreach ($context['css_header'] as $css) { |
|
| 3796 | + echo $css .' |
|
| 3591 | 3797 | '; |
| 3798 | + } |
|
| 3592 | 3799 | |
| 3593 | 3800 | echo' |
| 3594 | 3801 | </style>'; |
@@ -3612,15 +3819,17 @@ discard block |
||
| 3612 | 3819 | $type = !empty($type) && in_array($type, $types) ? $type : false; |
| 3613 | 3820 | $data = !empty($data) ? $data : false; |
| 3614 | 3821 | |
| 3615 | - if (empty($type) || empty($data)) |
|
| 3616 | - return false; |
|
| 3822 | + if (empty($type) || empty($data)) { |
|
| 3823 | + return false; |
|
| 3824 | + } |
|
| 3617 | 3825 | |
| 3618 | 3826 | // Did we already did this? |
| 3619 | 3827 | $toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400); |
| 3620 | 3828 | |
| 3621 | 3829 | // Already done? |
| 3622 | - if (!empty($toCache)) |
|
| 3623 | - return true; |
|
| 3830 | + if (!empty($toCache)) { |
|
| 3831 | + return true; |
|
| 3832 | + } |
|
| 3624 | 3833 | |
| 3625 | 3834 | // No namespaces, sorry! |
| 3626 | 3835 | $classType = 'MatthiasMullie\\Minify\\'. strtoupper($type); |
@@ -3702,8 +3911,9 @@ discard block |
||
| 3702 | 3911 | global $modSettings, $smcFunc; |
| 3703 | 3912 | |
| 3704 | 3913 | // Just make up a nice hash... |
| 3705 | - if ($new) |
|
| 3706 | - return sha1(md5($filename . time()) . mt_rand()); |
|
| 3914 | + if ($new) { |
|
| 3915 | + return sha1(md5($filename . time()) . mt_rand()); |
|
| 3916 | + } |
|
| 3707 | 3917 | |
| 3708 | 3918 | // Just make sure that attachment id is only a int |
| 3709 | 3919 | $attachment_id = (int) $attachment_id; |
@@ -3720,23 +3930,25 @@ discard block |
||
| 3720 | 3930 | 'id_attach' => $attachment_id, |
| 3721 | 3931 | )); |
| 3722 | 3932 | |
| 3723 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 3724 | - return false; |
|
| 3933 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 3934 | + return false; |
|
| 3935 | + } |
|
| 3725 | 3936 | |
| 3726 | 3937 | list ($file_hash) = $smcFunc['db_fetch_row']($request); |
| 3727 | 3938 | $smcFunc['db_free_result']($request); |
| 3728 | 3939 | } |
| 3729 | 3940 | |
| 3730 | 3941 | // Still no hash? mmm... |
| 3731 | - if (empty($file_hash)) |
|
| 3732 | - $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
| 3942 | + if (empty($file_hash)) { |
|
| 3943 | + $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
| 3944 | + } |
|
| 3733 | 3945 | |
| 3734 | 3946 | // Are we using multiple directories? |
| 3735 | - if (is_array($modSettings['attachmentUploadDir'])) |
|
| 3736 | - $path = $modSettings['attachmentUploadDir'][$dir]; |
|
| 3737 | - |
|
| 3738 | - else |
|
| 3739 | - $path = $modSettings['attachmentUploadDir']; |
|
| 3947 | + if (is_array($modSettings['attachmentUploadDir'])) { |
|
| 3948 | + $path = $modSettings['attachmentUploadDir'][$dir]; |
|
| 3949 | + } else { |
|
| 3950 | + $path = $modSettings['attachmentUploadDir']; |
|
| 3951 | + } |
|
| 3740 | 3952 | |
| 3741 | 3953 | return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; |
| 3742 | 3954 | } |
@@ -3751,8 +3963,9 @@ discard block |
||
| 3751 | 3963 | function ip2range($fullip) |
| 3752 | 3964 | { |
| 3753 | 3965 | // Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.) |
| 3754 | - if ($fullip == 'unknown') |
|
| 3755 | - $fullip = '255.255.255.255'; |
|
| 3966 | + if ($fullip == 'unknown') { |
|
| 3967 | + $fullip = '255.255.255.255'; |
|
| 3968 | + } |
|
| 3756 | 3969 | |
| 3757 | 3970 | $ip_parts = explode('-', $fullip); |
| 3758 | 3971 | $ip_array = array(); |
@@ -3776,10 +3989,11 @@ discard block |
||
| 3776 | 3989 | $ip_array['low'] = $ip_parts[0]; |
| 3777 | 3990 | $ip_array['high'] = $ip_parts[1]; |
| 3778 | 3991 | return $ip_array; |
| 3779 | - } |
|
| 3780 | - elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.* |
|
| 3992 | + } elseif (count($ip_parts) == 2) { |
|
| 3993 | + // if ip 22.22.*-22.22.* |
|
| 3781 | 3994 | { |
| 3782 | 3995 | $valid_low = isValidIP($ip_parts[0]); |
| 3996 | + } |
|
| 3783 | 3997 | $valid_high = isValidIP($ip_parts[1]); |
| 3784 | 3998 | $count = 0; |
| 3785 | 3999 | $mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); |
@@ -3794,7 +4008,9 @@ discard block |
||
| 3794 | 4008 | $ip_parts[0] .= $mode . $min; |
| 3795 | 4009 | $valid_low = isValidIP($ip_parts[0]); |
| 3796 | 4010 | $count++; |
| 3797 | - if ($count > 9) break; |
|
| 4011 | + if ($count > 9) { |
|
| 4012 | + break; |
|
| 4013 | + } |
|
| 3798 | 4014 | } |
| 3799 | 4015 | } |
| 3800 | 4016 | |
@@ -3808,7 +4024,9 @@ discard block |
||
| 3808 | 4024 | $ip_parts[1] .= $mode . $max; |
| 3809 | 4025 | $valid_high = isValidIP($ip_parts[1]); |
| 3810 | 4026 | $count++; |
| 3811 | - if ($count > 9) break; |
|
| 4027 | + if ($count > 9) { |
|
| 4028 | + break; |
|
| 4029 | + } |
|
| 3812 | 4030 | } |
| 3813 | 4031 | } |
| 3814 | 4032 | |
@@ -3833,46 +4051,54 @@ discard block |
||
| 3833 | 4051 | { |
| 3834 | 4052 | global $modSettings; |
| 3835 | 4053 | |
| 3836 | - if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) |
|
| 3837 | - return $host; |
|
| 4054 | + if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) { |
|
| 4055 | + return $host; |
|
| 4056 | + } |
|
| 3838 | 4057 | $t = microtime(); |
| 3839 | 4058 | |
| 3840 | 4059 | // Try the Linux host command, perhaps? |
| 3841 | 4060 | if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1) |
| 3842 | 4061 | { |
| 3843 | - if (!isset($modSettings['host_to_dis'])) |
|
| 3844 | - $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
| 3845 | - else |
|
| 3846 | - $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
| 4062 | + if (!isset($modSettings['host_to_dis'])) { |
|
| 4063 | + $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
| 4064 | + } else { |
|
| 4065 | + $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
| 4066 | + } |
|
| 3847 | 4067 | |
| 3848 | 4068 | // Did host say it didn't find anything? |
| 3849 | - if (strpos($test, 'not found') !== false) |
|
| 3850 | - $host = ''; |
|
| 4069 | + if (strpos($test, 'not found') !== false) { |
|
| 4070 | + $host = ''; |
|
| 4071 | + } |
|
| 3851 | 4072 | // Invalid server option? |
| 3852 | - elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) |
|
| 3853 | - updateSettings(array('host_to_dis' => 1)); |
|
| 4073 | + elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) { |
|
| 4074 | + updateSettings(array('host_to_dis' => 1)); |
|
| 4075 | + } |
|
| 3854 | 4076 | // Maybe it found something, after all? |
| 3855 | - elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) |
|
| 3856 | - $host = $match[1]; |
|
| 4077 | + elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) { |
|
| 4078 | + $host = $match[1]; |
|
| 4079 | + } |
|
| 3857 | 4080 | } |
| 3858 | 4081 | |
| 3859 | 4082 | // This is nslookup; usually only Windows, but possibly some Unix? |
| 3860 | 4083 | if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1) |
| 3861 | 4084 | { |
| 3862 | 4085 | $test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip)); |
| 3863 | - if (strpos($test, 'Non-existent domain') !== false) |
|
| 3864 | - $host = ''; |
|
| 3865 | - elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) |
|
| 3866 | - $host = $match[1]; |
|
| 4086 | + if (strpos($test, 'Non-existent domain') !== false) { |
|
| 4087 | + $host = ''; |
|
| 4088 | + } elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) { |
|
| 4089 | + $host = $match[1]; |
|
| 4090 | + } |
|
| 3867 | 4091 | } |
| 3868 | 4092 | |
| 3869 | 4093 | // This is the last try :/. |
| 3870 | - if (!isset($host) || $host === false) |
|
| 3871 | - $host = @gethostbyaddr($ip); |
|
| 4094 | + if (!isset($host) || $host === false) { |
|
| 4095 | + $host = @gethostbyaddr($ip); |
|
| 4096 | + } |
|
| 3872 | 4097 | |
| 3873 | 4098 | // It took a long time, so let's cache it! |
| 3874 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) |
|
| 3875 | - cache_put_data('hostlookup-' . $ip, $host, 600); |
|
| 4099 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) { |
|
| 4100 | + cache_put_data('hostlookup-' . $ip, $host, 600); |
|
| 4101 | + } |
|
| 3876 | 4102 | |
| 3877 | 4103 | return $host; |
| 3878 | 4104 | } |
@@ -3908,20 +4134,21 @@ discard block |
||
| 3908 | 4134 | { |
| 3909 | 4135 | $encrypted = substr(crypt($word, 'uk'), 2, $max_chars); |
| 3910 | 4136 | $total = 0; |
| 3911 | - for ($i = 0; $i < $max_chars; $i++) |
|
| 3912 | - $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
| 4137 | + for ($i = 0; $i < $max_chars; $i++) { |
|
| 4138 | + $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
| 4139 | + } |
|
| 3913 | 4140 | $returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total; |
| 3914 | 4141 | } |
| 3915 | 4142 | } |
| 3916 | 4143 | return array_unique($returned_ints); |
| 3917 | - } |
|
| 3918 | - else |
|
| 4144 | + } else |
|
| 3919 | 4145 | { |
| 3920 | 4146 | // Trim characters before and after and add slashes for database insertion. |
| 3921 | 4147 | $returned_words = array(); |
| 3922 | - foreach ($words as $word) |
|
| 3923 | - if (($word = trim($word, '-_\'')) !== '') |
|
| 4148 | + foreach ($words as $word) { |
|
| 4149 | + if (($word = trim($word, '-_\'')) !== '') |
|
| 3924 | 4150 | $returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars); |
| 4151 | + } |
|
| 3925 | 4152 | |
| 3926 | 4153 | // Filter out all words that occur more than once. |
| 3927 | 4154 | return array_unique($returned_words); |
@@ -3943,16 +4170,18 @@ discard block |
||
| 3943 | 4170 | global $settings, $txt; |
| 3944 | 4171 | |
| 3945 | 4172 | // Does the current loaded theme have this and we are not forcing the usage of this function? |
| 3946 | - if (function_exists('template_create_button') && !$force_use) |
|
| 3947 | - return template_create_button($name, $alt, $label = '', $custom = ''); |
|
| 4173 | + if (function_exists('template_create_button') && !$force_use) { |
|
| 4174 | + return template_create_button($name, $alt, $label = '', $custom = ''); |
|
| 4175 | + } |
|
| 3948 | 4176 | |
| 3949 | - if (!$settings['use_image_buttons']) |
|
| 3950 | - return $txt[$alt]; |
|
| 3951 | - elseif (!empty($settings['use_buttons'])) |
|
| 3952 | - return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
| 3953 | - else |
|
| 3954 | - return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
| 3955 | -} |
|
| 4177 | + if (!$settings['use_image_buttons']) { |
|
| 4178 | + return $txt[$alt]; |
|
| 4179 | + } elseif (!empty($settings['use_buttons'])) { |
|
| 4180 | + return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
| 4181 | + } else { |
|
| 4182 | + return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
| 4183 | + } |
|
| 4184 | + } |
|
| 3956 | 4185 | |
| 3957 | 4186 | /** |
| 3958 | 4187 | * Sets up all of the top menu buttons |
@@ -3995,9 +4224,10 @@ discard block |
||
| 3995 | 4224 | var user_menus = new smc_PopupMenu(); |
| 3996 | 4225 | user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); |
| 3997 | 4226 | user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); |
| 3998 | - if ($context['allow_pm']) |
|
| 3999 | - addInlineJavaScript(' |
|
| 4227 | + if ($context['allow_pm']) { |
|
| 4228 | + addInlineJavaScript(' |
|
| 4000 | 4229 | user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); |
| 4230 | + } |
|
| 4001 | 4231 | |
| 4002 | 4232 | if (!empty($modSettings['enable_ajax_alerts'])) |
| 4003 | 4233 | { |
@@ -4157,88 +4387,96 @@ discard block |
||
| 4157 | 4387 | |
| 4158 | 4388 | // Now we put the buttons in the context so the theme can use them. |
| 4159 | 4389 | $menu_buttons = array(); |
| 4160 | - foreach ($buttons as $act => $button) |
|
| 4161 | - if (!empty($button['show'])) |
|
| 4390 | + foreach ($buttons as $act => $button) { |
|
| 4391 | + if (!empty($button['show'])) |
|
| 4162 | 4392 | { |
| 4163 | 4393 | $button['active_button'] = false; |
| 4394 | + } |
|
| 4164 | 4395 | |
| 4165 | 4396 | // This button needs some action. |
| 4166 | - if (isset($button['action_hook'])) |
|
| 4167 | - $needs_action_hook = true; |
|
| 4397 | + if (isset($button['action_hook'])) { |
|
| 4398 | + $needs_action_hook = true; |
|
| 4399 | + } |
|
| 4168 | 4400 | |
| 4169 | 4401 | // Make sure the last button truly is the last button. |
| 4170 | 4402 | if (!empty($button['is_last'])) |
| 4171 | 4403 | { |
| 4172 | - if (isset($last_button)) |
|
| 4173 | - unset($menu_buttons[$last_button]['is_last']); |
|
| 4404 | + if (isset($last_button)) { |
|
| 4405 | + unset($menu_buttons[$last_button]['is_last']); |
|
| 4406 | + } |
|
| 4174 | 4407 | $last_button = $act; |
| 4175 | 4408 | } |
| 4176 | 4409 | |
| 4177 | 4410 | // Go through the sub buttons if there are any. |
| 4178 | - if (!empty($button['sub_buttons'])) |
|
| 4179 | - foreach ($button['sub_buttons'] as $key => $subbutton) |
|
| 4411 | + if (!empty($button['sub_buttons'])) { |
|
| 4412 | + foreach ($button['sub_buttons'] as $key => $subbutton) |
|
| 4180 | 4413 | { |
| 4181 | 4414 | if (empty($subbutton['show'])) |
| 4182 | 4415 | unset($button['sub_buttons'][$key]); |
| 4416 | + } |
|
| 4183 | 4417 | |
| 4184 | 4418 | // 2nd level sub buttons next... |
| 4185 | 4419 | if (!empty($subbutton['sub_buttons'])) |
| 4186 | 4420 | { |
| 4187 | 4421 | foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2) |
| 4188 | 4422 | { |
| 4189 | - if (empty($sub_button2['show'])) |
|
| 4190 | - unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
| 4423 | + if (empty($sub_button2['show'])) { |
|
| 4424 | + unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
| 4425 | + } |
|
| 4191 | 4426 | } |
| 4192 | 4427 | } |
| 4193 | 4428 | } |
| 4194 | 4429 | |
| 4195 | 4430 | // Does this button have its own icon? |
| 4196 | - if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) |
|
| 4197 | - $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4198 | - elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) |
|
| 4199 | - $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4200 | - elseif (isset($button['icon'])) |
|
| 4201 | - $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
| 4202 | - else |
|
| 4203 | - $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
| 4431 | + if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) { |
|
| 4432 | + $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4433 | + } elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) { |
|
| 4434 | + $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4435 | + } elseif (isset($button['icon'])) { |
|
| 4436 | + $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
| 4437 | + } else { |
|
| 4438 | + $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
| 4439 | + } |
|
| 4204 | 4440 | |
| 4205 | 4441 | $menu_buttons[$act] = $button; |
| 4206 | 4442 | } |
| 4207 | 4443 | |
| 4208 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 4209 | - cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
| 4444 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 4445 | + cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
| 4446 | + } |
|
| 4210 | 4447 | } |
| 4211 | 4448 | |
| 4212 | 4449 | $context['menu_buttons'] = $menu_buttons; |
| 4213 | 4450 | |
| 4214 | 4451 | // Logging out requires the session id in the url. |
| 4215 | - if (isset($context['menu_buttons']['logout'])) |
|
| 4216 | - $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
| 4452 | + if (isset($context['menu_buttons']['logout'])) { |
|
| 4453 | + $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
| 4454 | + } |
|
| 4217 | 4455 | |
| 4218 | 4456 | // Figure out which action we are doing so we can set the active tab. |
| 4219 | 4457 | // Default to home. |
| 4220 | 4458 | $current_action = 'home'; |
| 4221 | 4459 | |
| 4222 | - if (isset($context['menu_buttons'][$context['current_action']])) |
|
| 4223 | - $current_action = $context['current_action']; |
|
| 4224 | - elseif ($context['current_action'] == 'search2') |
|
| 4225 | - $current_action = 'search'; |
|
| 4226 | - elseif ($context['current_action'] == 'theme') |
|
| 4227 | - $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
| 4228 | - elseif ($context['current_action'] == 'register2') |
|
| 4229 | - $current_action = 'register'; |
|
| 4230 | - elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) |
|
| 4231 | - $current_action = 'login'; |
|
| 4232 | - elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) |
|
| 4233 | - $current_action = 'moderate'; |
|
| 4460 | + if (isset($context['menu_buttons'][$context['current_action']])) { |
|
| 4461 | + $current_action = $context['current_action']; |
|
| 4462 | + } elseif ($context['current_action'] == 'search2') { |
|
| 4463 | + $current_action = 'search'; |
|
| 4464 | + } elseif ($context['current_action'] == 'theme') { |
|
| 4465 | + $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
| 4466 | + } elseif ($context['current_action'] == 'register2') { |
|
| 4467 | + $current_action = 'register'; |
|
| 4468 | + } elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) { |
|
| 4469 | + $current_action = 'login'; |
|
| 4470 | + } elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) { |
|
| 4471 | + $current_action = 'moderate'; |
|
| 4472 | + } |
|
| 4234 | 4473 | |
| 4235 | 4474 | // There are certain exceptions to the above where we don't want anything on the menu highlighted. |
| 4236 | 4475 | if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner'])) |
| 4237 | 4476 | { |
| 4238 | 4477 | $current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile'; |
| 4239 | 4478 | $context[$current_action] = true; |
| 4240 | - } |
|
| 4241 | - elseif ($context['current_action'] == 'pm') |
|
| 4479 | + } elseif ($context['current_action'] == 'pm') |
|
| 4242 | 4480 | { |
| 4243 | 4481 | $current_action = 'self_pm'; |
| 4244 | 4482 | $context['self_pm'] = true; |
@@ -4281,12 +4519,14 @@ discard block |
||
| 4281 | 4519 | } |
| 4282 | 4520 | |
| 4283 | 4521 | // Not all actions are simple. |
| 4284 | - if (!empty($needs_action_hook)) |
|
| 4285 | - call_integration_hook('integrate_current_action', array(&$current_action)); |
|
| 4522 | + if (!empty($needs_action_hook)) { |
|
| 4523 | + call_integration_hook('integrate_current_action', array(&$current_action)); |
|
| 4524 | + } |
|
| 4286 | 4525 | |
| 4287 | - if (isset($context['menu_buttons'][$current_action])) |
|
| 4288 | - $context['menu_buttons'][$current_action]['active_button'] = true; |
|
| 4289 | -} |
|
| 4526 | + if (isset($context['menu_buttons'][$current_action])) { |
|
| 4527 | + $context['menu_buttons'][$current_action]['active_button'] = true; |
|
| 4528 | + } |
|
| 4529 | + } |
|
| 4290 | 4530 | |
| 4291 | 4531 | /** |
| 4292 | 4532 | * Generate a random seed and ensure it's stored in settings. |
@@ -4310,30 +4550,35 @@ discard block |
||
| 4310 | 4550 | global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug; |
| 4311 | 4551 | global $context, $txt; |
| 4312 | 4552 | |
| 4313 | - if ($db_show_debug === true) |
|
| 4314 | - $context['debug']['hooks'][] = $hook; |
|
| 4553 | + if ($db_show_debug === true) { |
|
| 4554 | + $context['debug']['hooks'][] = $hook; |
|
| 4555 | + } |
|
| 4315 | 4556 | |
| 4316 | 4557 | // Need to have some control. |
| 4317 | - if (!isset($context['instances'])) |
|
| 4318 | - $context['instances'] = array(); |
|
| 4558 | + if (!isset($context['instances'])) { |
|
| 4559 | + $context['instances'] = array(); |
|
| 4560 | + } |
|
| 4319 | 4561 | |
| 4320 | 4562 | $results = array(); |
| 4321 | - if (empty($modSettings[$hook])) |
|
| 4322 | - return $results; |
|
| 4563 | + if (empty($modSettings[$hook])) { |
|
| 4564 | + return $results; |
|
| 4565 | + } |
|
| 4323 | 4566 | |
| 4324 | 4567 | $functions = explode(',', $modSettings[$hook]); |
| 4325 | 4568 | // Loop through each function. |
| 4326 | 4569 | foreach ($functions as $function) |
| 4327 | 4570 | { |
| 4328 | 4571 | // Hook has been marked as "disabled". Skip it! |
| 4329 | - if (strpos($function, '!') !== false) |
|
| 4330 | - continue; |
|
| 4572 | + if (strpos($function, '!') !== false) { |
|
| 4573 | + continue; |
|
| 4574 | + } |
|
| 4331 | 4575 | |
| 4332 | 4576 | $call = call_helper($function, true); |
| 4333 | 4577 | |
| 4334 | 4578 | // Is it valid? |
| 4335 | - if (!empty($call)) |
|
| 4336 | - $results[$function] = call_user_func_array($call, $parameters); |
|
| 4579 | + if (!empty($call)) { |
|
| 4580 | + $results[$function] = call_user_func_array($call, $parameters); |
|
| 4581 | + } |
|
| 4337 | 4582 | |
| 4338 | 4583 | // Whatever it was suppose to call, it failed :( |
| 4339 | 4584 | elseif (!empty($function)) |
@@ -4349,8 +4594,9 @@ discard block |
||
| 4349 | 4594 | } |
| 4350 | 4595 | |
| 4351 | 4596 | // "Assume" the file resides on $boarddir somewhere... |
| 4352 | - else |
|
| 4353 | - log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
| 4597 | + else { |
|
| 4598 | + log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
| 4599 | + } |
|
| 4354 | 4600 | } |
| 4355 | 4601 | } |
| 4356 | 4602 | |
@@ -4372,12 +4618,14 @@ discard block |
||
| 4372 | 4618 | global $smcFunc, $modSettings; |
| 4373 | 4619 | |
| 4374 | 4620 | // Any objects? |
| 4375 | - if ($object) |
|
| 4376 | - $function = $function . '#'; |
|
| 4621 | + if ($object) { |
|
| 4622 | + $function = $function . '#'; |
|
| 4623 | + } |
|
| 4377 | 4624 | |
| 4378 | 4625 | // Any files to load? |
| 4379 | - if (!empty($file) && is_string($file)) |
|
| 4380 | - $function = $file . (!empty($function) ? '|' . $function : ''); |
|
| 4626 | + if (!empty($file) && is_string($file)) { |
|
| 4627 | + $function = $file . (!empty($function) ? '|' . $function : ''); |
|
| 4628 | + } |
|
| 4381 | 4629 | |
| 4382 | 4630 | // Get the correct string. |
| 4383 | 4631 | $integration_call = $function; |
@@ -4399,13 +4647,14 @@ discard block |
||
| 4399 | 4647 | if (!empty($current_functions)) |
| 4400 | 4648 | { |
| 4401 | 4649 | $current_functions = explode(',', $current_functions); |
| 4402 | - if (in_array($integration_call, $current_functions)) |
|
| 4403 | - return; |
|
| 4650 | + if (in_array($integration_call, $current_functions)) { |
|
| 4651 | + return; |
|
| 4652 | + } |
|
| 4404 | 4653 | |
| 4405 | 4654 | $permanent_functions = array_merge($current_functions, array($integration_call)); |
| 4655 | + } else { |
|
| 4656 | + $permanent_functions = array($integration_call); |
|
| 4406 | 4657 | } |
| 4407 | - else |
|
| 4408 | - $permanent_functions = array($integration_call); |
|
| 4409 | 4658 | |
| 4410 | 4659 | updateSettings(array($hook => implode(',', $permanent_functions))); |
| 4411 | 4660 | } |
@@ -4414,8 +4663,9 @@ discard block |
||
| 4414 | 4663 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
| 4415 | 4664 | |
| 4416 | 4665 | // Do nothing, if it's already there. |
| 4417 | - if (in_array($integration_call, $functions)) |
|
| 4418 | - return; |
|
| 4666 | + if (in_array($integration_call, $functions)) { |
|
| 4667 | + return; |
|
| 4668 | + } |
|
| 4419 | 4669 | |
| 4420 | 4670 | $functions[] = $integration_call; |
| 4421 | 4671 | $modSettings[$hook] = implode(',', $functions); |
@@ -4438,12 +4688,14 @@ discard block |
||
| 4438 | 4688 | global $smcFunc, $modSettings; |
| 4439 | 4689 | |
| 4440 | 4690 | // Any objects? |
| 4441 | - if ($object) |
|
| 4442 | - $function = $function . '#'; |
|
| 4691 | + if ($object) { |
|
| 4692 | + $function = $function . '#'; |
|
| 4693 | + } |
|
| 4443 | 4694 | |
| 4444 | 4695 | // Any files to load? |
| 4445 | - if (!empty($file) && is_string($file)) |
|
| 4446 | - $function = $file . '|' . $function; |
|
| 4696 | + if (!empty($file) && is_string($file)) { |
|
| 4697 | + $function = $file . '|' . $function; |
|
| 4698 | + } |
|
| 4447 | 4699 | |
| 4448 | 4700 | // Get the correct string. |
| 4449 | 4701 | $integration_call = $function; |
@@ -4464,16 +4716,18 @@ discard block |
||
| 4464 | 4716 | { |
| 4465 | 4717 | $current_functions = explode(',', $current_functions); |
| 4466 | 4718 | |
| 4467 | - if (in_array($integration_call, $current_functions)) |
|
| 4468 | - updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
| 4719 | + if (in_array($integration_call, $current_functions)) { |
|
| 4720 | + updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
| 4721 | + } |
|
| 4469 | 4722 | } |
| 4470 | 4723 | |
| 4471 | 4724 | // Turn the function list into something usable. |
| 4472 | 4725 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
| 4473 | 4726 | |
| 4474 | 4727 | // You can only remove it if it's available. |
| 4475 | - if (!in_array($integration_call, $functions)) |
|
| 4476 | - return; |
|
| 4728 | + if (!in_array($integration_call, $functions)) { |
|
| 4729 | + return; |
|
| 4730 | + } |
|
| 4477 | 4731 | |
| 4478 | 4732 | $functions = array_diff($functions, array($integration_call)); |
| 4479 | 4733 | $modSettings[$hook] = implode(',', $functions); |
@@ -4494,17 +4748,20 @@ discard block |
||
| 4494 | 4748 | global $context, $smcFunc, $txt, $db_show_debug; |
| 4495 | 4749 | |
| 4496 | 4750 | // Really? |
| 4497 | - if (empty($string)) |
|
| 4498 | - return false; |
|
| 4751 | + if (empty($string)) { |
|
| 4752 | + return false; |
|
| 4753 | + } |
|
| 4499 | 4754 | |
| 4500 | 4755 | // An array? should be a "callable" array IE array(object/class, valid_callable). |
| 4501 | 4756 | // A closure? should be a callable one. |
| 4502 | - if (is_array($string) || $string instanceof Closure) |
|
| 4503 | - return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
| 4757 | + if (is_array($string) || $string instanceof Closure) { |
|
| 4758 | + return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
| 4759 | + } |
|
| 4504 | 4760 | |
| 4505 | 4761 | // No full objects, sorry! pass a method or a property instead! |
| 4506 | - if (is_object($string)) |
|
| 4507 | - return false; |
|
| 4762 | + if (is_object($string)) { |
|
| 4763 | + return false; |
|
| 4764 | + } |
|
| 4508 | 4765 | |
| 4509 | 4766 | // Stay vitaminized my friends... |
| 4510 | 4767 | $string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string)); |
@@ -4513,8 +4770,9 @@ discard block |
||
| 4513 | 4770 | $string = load_file($string); |
| 4514 | 4771 | |
| 4515 | 4772 | // Loaded file failed |
| 4516 | - if (empty($string)) |
|
| 4517 | - return false; |
|
| 4773 | + if (empty($string)) { |
|
| 4774 | + return false; |
|
| 4775 | + } |
|
| 4518 | 4776 | |
| 4519 | 4777 | // Found a method. |
| 4520 | 4778 | if (strpos($string, '::') !== false) |
@@ -4535,8 +4793,9 @@ discard block |
||
| 4535 | 4793 | // Add another one to the list. |
| 4536 | 4794 | if ($db_show_debug === true) |
| 4537 | 4795 | { |
| 4538 | - if (!isset($context['debug']['instances'])) |
|
| 4539 | - $context['debug']['instances'] = array(); |
|
| 4796 | + if (!isset($context['debug']['instances'])) { |
|
| 4797 | + $context['debug']['instances'] = array(); |
|
| 4798 | + } |
|
| 4540 | 4799 | |
| 4541 | 4800 | $context['debug']['instances'][$class] = $class; |
| 4542 | 4801 | } |
@@ -4546,13 +4805,15 @@ discard block |
||
| 4546 | 4805 | } |
| 4547 | 4806 | |
| 4548 | 4807 | // Right then. This is a call to a static method. |
| 4549 | - else |
|
| 4550 | - $func = array($class, $method); |
|
| 4808 | + else { |
|
| 4809 | + $func = array($class, $method); |
|
| 4810 | + } |
|
| 4551 | 4811 | } |
| 4552 | 4812 | |
| 4553 | 4813 | // Nope! just a plain regular function. |
| 4554 | - else |
|
| 4555 | - $func = $string; |
|
| 4814 | + else { |
|
| 4815 | + $func = $string; |
|
| 4816 | + } |
|
| 4556 | 4817 | |
| 4557 | 4818 | // Right, we got what we need, time to do some checks. |
| 4558 | 4819 | if (!is_callable($func, false, $callable_name)) |
@@ -4568,17 +4829,18 @@ discard block |
||
| 4568 | 4829 | else |
| 4569 | 4830 | { |
| 4570 | 4831 | // What are we gonna do about it? |
| 4571 | - if ($return) |
|
| 4572 | - return $func; |
|
| 4832 | + if ($return) { |
|
| 4833 | + return $func; |
|
| 4834 | + } |
|
| 4573 | 4835 | |
| 4574 | 4836 | // If this is a plain function, avoid the heat of calling call_user_func(). |
| 4575 | 4837 | else |
| 4576 | 4838 | { |
| 4577 | - if (is_array($func)) |
|
| 4578 | - call_user_func($func); |
|
| 4579 | - |
|
| 4580 | - else |
|
| 4581 | - $func(); |
|
| 4839 | + if (is_array($func)) { |
|
| 4840 | + call_user_func($func); |
|
| 4841 | + } else { |
|
| 4842 | + $func(); |
|
| 4843 | + } |
|
| 4582 | 4844 | } |
| 4583 | 4845 | } |
| 4584 | 4846 | } |
@@ -4595,31 +4857,34 @@ discard block |
||
| 4595 | 4857 | { |
| 4596 | 4858 | global $sourcedir, $txt, $boarddir, $settings; |
| 4597 | 4859 | |
| 4598 | - if (empty($string)) |
|
| 4599 | - return false; |
|
| 4860 | + if (empty($string)) { |
|
| 4861 | + return false; |
|
| 4862 | + } |
|
| 4600 | 4863 | |
| 4601 | 4864 | if (strpos($string, '|') !== false) |
| 4602 | 4865 | { |
| 4603 | 4866 | list ($file, $string) = explode('|', $string); |
| 4604 | 4867 | |
| 4605 | 4868 | // Match the wildcards to their regular vars. |
| 4606 | - if (empty($settings['theme_dir'])) |
|
| 4607 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
| 4608 | - |
|
| 4609 | - else |
|
| 4610 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
| 4869 | + if (empty($settings['theme_dir'])) { |
|
| 4870 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
| 4871 | + } else { |
|
| 4872 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
| 4873 | + } |
|
| 4611 | 4874 | |
| 4612 | 4875 | // Load the file if it can be loaded. |
| 4613 | - if (file_exists($absPath)) |
|
| 4614 | - require_once($absPath); |
|
| 4876 | + if (file_exists($absPath)) { |
|
| 4877 | + require_once($absPath); |
|
| 4878 | + } |
|
| 4615 | 4879 | |
| 4616 | 4880 | // No? try a fallback to $sourcedir |
| 4617 | 4881 | else |
| 4618 | 4882 | { |
| 4619 | 4883 | $absPath = $sourcedir .'/'. $file; |
| 4620 | 4884 | |
| 4621 | - if (file_exists($absPath)) |
|
| 4622 | - require_once($absPath); |
|
| 4885 | + if (file_exists($absPath)) { |
|
| 4886 | + require_once($absPath); |
|
| 4887 | + } |
|
| 4623 | 4888 | |
| 4624 | 4889 | // Sorry, can't do much for you at this point. |
| 4625 | 4890 | else |
@@ -4646,8 +4911,9 @@ discard block |
||
| 4646 | 4911 | global $user_info, $smcFunc; |
| 4647 | 4912 | |
| 4648 | 4913 | // Make sure we have something to work with. |
| 4649 | - if (empty($topic)) |
|
| 4650 | - return array(); |
|
| 4914 | + if (empty($topic)) { |
|
| 4915 | + return array(); |
|
| 4916 | + } |
|
| 4651 | 4917 | |
| 4652 | 4918 | |
| 4653 | 4919 | // We already know the number of likes per message, we just want to know whether the current user liked it or not. |
@@ -4670,8 +4936,9 @@ discard block |
||
| 4670 | 4936 | 'topic' => $topic, |
| 4671 | 4937 | ) |
| 4672 | 4938 | ); |
| 4673 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 4674 | - $temp[] = (int) $row['content_id']; |
|
| 4939 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 4940 | + $temp[] = (int) $row['content_id']; |
|
| 4941 | + } |
|
| 4675 | 4942 | |
| 4676 | 4943 | cache_put_data($cache_key, $temp, $ttl); |
| 4677 | 4944 | } |
@@ -4692,8 +4959,9 @@ discard block |
||
| 4692 | 4959 | { |
| 4693 | 4960 | global $context; |
| 4694 | 4961 | |
| 4695 | - if (empty($string)) |
|
| 4696 | - return $string; |
|
| 4962 | + if (empty($string)) { |
|
| 4963 | + return $string; |
|
| 4964 | + } |
|
| 4697 | 4965 | |
| 4698 | 4966 | // UTF-8 occurences of MS special characters |
| 4699 | 4967 | $findchars_utf8 = array( |
@@ -4734,10 +5002,11 @@ discard block |
||
| 4734 | 5002 | '--', // — |
| 4735 | 5003 | ); |
| 4736 | 5004 | |
| 4737 | - if ($context['utf8']) |
|
| 4738 | - $string = str_replace($findchars_utf8, $replacechars, $string); |
|
| 4739 | - else |
|
| 4740 | - $string = str_replace($findchars_iso, $replacechars, $string); |
|
| 5005 | + if ($context['utf8']) { |
|
| 5006 | + $string = str_replace($findchars_utf8, $replacechars, $string); |
|
| 5007 | + } else { |
|
| 5008 | + $string = str_replace($findchars_iso, $replacechars, $string); |
|
| 5009 | + } |
|
| 4741 | 5010 | |
| 4742 | 5011 | return $string; |
| 4743 | 5012 | } |
@@ -4756,49 +5025,59 @@ discard block |
||
| 4756 | 5025 | { |
| 4757 | 5026 | global $context; |
| 4758 | 5027 | |
| 4759 | - if (!isset($matches[2])) |
|
| 4760 | - return ''; |
|
| 5028 | + if (!isset($matches[2])) { |
|
| 5029 | + return ''; |
|
| 5030 | + } |
|
| 4761 | 5031 | |
| 4762 | 5032 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
| 4763 | 5033 | |
| 4764 | 5034 | // remove left to right / right to left overrides |
| 4765 | - if ($num === 0x202D || $num === 0x202E) |
|
| 4766 | - return ''; |
|
| 5035 | + if ($num === 0x202D || $num === 0x202E) { |
|
| 5036 | + return ''; |
|
| 5037 | + } |
|
| 4767 | 5038 | |
| 4768 | 5039 | // Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced |
| 4769 | - if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) |
|
| 4770 | - return '&#' . $num . ';'; |
|
| 5040 | + if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) { |
|
| 5041 | + return '&#' . $num . ';'; |
|
| 5042 | + } |
|
| 4771 | 5043 | |
| 4772 | 5044 | if (empty($context['utf8'])) |
| 4773 | 5045 | { |
| 4774 | 5046 | // no control characters |
| 4775 | - if ($num < 0x20) |
|
| 4776 | - return ''; |
|
| 5047 | + if ($num < 0x20) { |
|
| 5048 | + return ''; |
|
| 5049 | + } |
|
| 4777 | 5050 | // text is text |
| 4778 | - elseif ($num < 0x80) |
|
| 4779 | - return chr($num); |
|
| 5051 | + elseif ($num < 0x80) { |
|
| 5052 | + return chr($num); |
|
| 5053 | + } |
|
| 4780 | 5054 | // all others get html-ised |
| 4781 | - else |
|
| 4782 | - return '&#' . $matches[2] . ';'; |
|
| 4783 | - } |
|
| 4784 | - else |
|
| 5055 | + else { |
|
| 5056 | + return '&#' . $matches[2] . ';'; |
|
| 5057 | + } |
|
| 5058 | + } else |
|
| 4785 | 5059 | { |
| 4786 | 5060 | // <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set |
| 4787 | 5061 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text) |
| 4788 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) |
|
| 4789 | - return ''; |
|
| 5062 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) { |
|
| 5063 | + return ''; |
|
| 5064 | + } |
|
| 4790 | 5065 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
| 4791 | - elseif ($num < 0x80) |
|
| 4792 | - return chr($num); |
|
| 5066 | + elseif ($num < 0x80) { |
|
| 5067 | + return chr($num); |
|
| 5068 | + } |
|
| 4793 | 5069 | // <0x800 (2048) |
| 4794 | - elseif ($num < 0x800) |
|
| 4795 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5070 | + elseif ($num < 0x800) { |
|
| 5071 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5072 | + } |
|
| 4796 | 5073 | // < 0x10000 (65536) |
| 4797 | - elseif ($num < 0x10000) |
|
| 4798 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5074 | + elseif ($num < 0x10000) { |
|
| 5075 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5076 | + } |
|
| 4799 | 5077 | // <= 0x10FFFF (1114111) |
| 4800 | - else |
|
| 4801 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5078 | + else { |
|
| 5079 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5080 | + } |
|
| 4802 | 5081 | } |
| 4803 | 5082 | } |
| 4804 | 5083 | |
@@ -4814,28 +5093,34 @@ discard block |
||
| 4814 | 5093 | */ |
| 4815 | 5094 | function fixchar__callback($matches) |
| 4816 | 5095 | { |
| 4817 | - if (!isset($matches[1])) |
|
| 4818 | - return ''; |
|
| 5096 | + if (!isset($matches[1])) { |
|
| 5097 | + return ''; |
|
| 5098 | + } |
|
| 4819 | 5099 | |
| 4820 | 5100 | $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1]; |
| 4821 | 5101 | |
| 4822 | 5102 | // <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set |
| 4823 | 5103 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides |
| 4824 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) |
|
| 4825 | - return ''; |
|
| 5104 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) { |
|
| 5105 | + return ''; |
|
| 5106 | + } |
|
| 4826 | 5107 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
| 4827 | - elseif ($num < 0x80) |
|
| 4828 | - return chr($num); |
|
| 5108 | + elseif ($num < 0x80) { |
|
| 5109 | + return chr($num); |
|
| 5110 | + } |
|
| 4829 | 5111 | // <0x800 (2048) |
| 4830 | - elseif ($num < 0x800) |
|
| 4831 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5112 | + elseif ($num < 0x800) { |
|
| 5113 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5114 | + } |
|
| 4832 | 5115 | // < 0x10000 (65536) |
| 4833 | - elseif ($num < 0x10000) |
|
| 4834 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5116 | + elseif ($num < 0x10000) { |
|
| 5117 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5118 | + } |
|
| 4835 | 5119 | // <= 0x10FFFF (1114111) |
| 4836 | - else |
|
| 4837 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 4838 | -} |
|
| 5120 | + else { |
|
| 5121 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5122 | + } |
|
| 5123 | + } |
|
| 4839 | 5124 | |
| 4840 | 5125 | /** |
| 4841 | 5126 | * Strips out invalid html entities, replaces others with html style { codes |
@@ -4848,17 +5133,19 @@ discard block |
||
| 4848 | 5133 | */ |
| 4849 | 5134 | function entity_fix__callback($matches) |
| 4850 | 5135 | { |
| 4851 | - if (!isset($matches[2])) |
|
| 4852 | - return ''; |
|
| 5136 | + if (!isset($matches[2])) { |
|
| 5137 | + return ''; |
|
| 5138 | + } |
|
| 4853 | 5139 | |
| 4854 | 5140 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
| 4855 | 5141 | |
| 4856 | 5142 | // we don't allow control characters, characters out of range, byte markers, etc |
| 4857 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) |
|
| 4858 | - return ''; |
|
| 4859 | - else |
|
| 4860 | - return '&#' . $num . ';'; |
|
| 4861 | -} |
|
| 5143 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) { |
|
| 5144 | + return ''; |
|
| 5145 | + } else { |
|
| 5146 | + return '&#' . $num . ';'; |
|
| 5147 | + } |
|
| 5148 | + } |
|
| 4862 | 5149 | |
| 4863 | 5150 | /** |
| 4864 | 5151 | * Return a Gravatar URL based on |
@@ -4882,18 +5169,23 @@ discard block |
||
| 4882 | 5169 | $ratings = array('G', 'PG', 'R', 'X'); |
| 4883 | 5170 | $defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'); |
| 4884 | 5171 | $url_params = array(); |
| 4885 | - if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) |
|
| 4886 | - $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
| 4887 | - if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) |
|
| 4888 | - $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
| 4889 | - if (!empty($modSettings['avatar_max_width_external'])) |
|
| 4890 | - $size_string = (int) $modSettings['avatar_max_width_external']; |
|
| 4891 | - if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) |
|
| 4892 | - if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
| 5172 | + if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) { |
|
| 5173 | + $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
| 5174 | + } |
|
| 5175 | + if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) { |
|
| 5176 | + $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
| 5177 | + } |
|
| 5178 | + if (!empty($modSettings['avatar_max_width_external'])) { |
|
| 5179 | + $size_string = (int) $modSettings['avatar_max_width_external']; |
|
| 5180 | + } |
|
| 5181 | + if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) { |
|
| 5182 | + if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
| 4893 | 5183 | $size_string = $modSettings['avatar_max_height_external']; |
| 5184 | + } |
|
| 4894 | 5185 | |
| 4895 | - if (!empty($size_string)) |
|
| 4896 | - $url_params[] = 's=' . $size_string; |
|
| 5186 | + if (!empty($size_string)) { |
|
| 5187 | + $url_params[] = 's=' . $size_string; |
|
| 5188 | + } |
|
| 4897 | 5189 | } |
| 4898 | 5190 | $http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www'; |
| 4899 | 5191 | |
@@ -4912,22 +5204,26 @@ discard block |
||
| 4912 | 5204 | static $timezones = null, $lastwhen = null; |
| 4913 | 5205 | |
| 4914 | 5206 | // No point doing this over if we already did it once |
| 4915 | - if (!empty($timezones) && $when == $lastwhen) |
|
| 4916 | - return $timezones; |
|
| 4917 | - else |
|
| 4918 | - $lastwhen = $when; |
|
| 5207 | + if (!empty($timezones) && $when == $lastwhen) { |
|
| 5208 | + return $timezones; |
|
| 5209 | + } else { |
|
| 5210 | + $lastwhen = $when; |
|
| 5211 | + } |
|
| 4919 | 5212 | |
| 4920 | 5213 | // Parseable datetime string? |
| 4921 | - if (is_int($timestamp = strtotime($when))) |
|
| 4922 | - $when = $timestamp; |
|
| 5214 | + if (is_int($timestamp = strtotime($when))) { |
|
| 5215 | + $when = $timestamp; |
|
| 5216 | + } |
|
| 4923 | 5217 | |
| 4924 | 5218 | // A Unix timestamp? |
| 4925 | - elseif (is_numeric($when)) |
|
| 4926 | - $when = intval($when); |
|
| 5219 | + elseif (is_numeric($when)) { |
|
| 5220 | + $when = intval($when); |
|
| 5221 | + } |
|
| 4927 | 5222 | |
| 4928 | 5223 | // Invalid value? Just get current Unix timestamp. |
| 4929 | - else |
|
| 4930 | - $when = time(); |
|
| 5224 | + else { |
|
| 5225 | + $when = time(); |
|
| 5226 | + } |
|
| 4931 | 5227 | |
| 4932 | 5228 | // We'll need these too |
| 4933 | 5229 | $date_when = date_create('@' . $when); |
@@ -4991,8 +5287,9 @@ discard block |
||
| 4991 | 5287 | foreach ($priority_countries as $country) |
| 4992 | 5288 | { |
| 4993 | 5289 | $country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country))); |
| 4994 | - if (!empty($country_tzids)) |
|
| 4995 | - $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
| 5290 | + if (!empty($country_tzids)) { |
|
| 5291 | + $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
| 5292 | + } |
|
| 4996 | 5293 | } |
| 4997 | 5294 | |
| 4998 | 5295 | // Process the preferred timezones first, then the rest. |
@@ -5002,8 +5299,9 @@ discard block |
||
| 5002 | 5299 | foreach ($tzids as $tzid) |
| 5003 | 5300 | { |
| 5004 | 5301 | // We don't want UTC right now |
| 5005 | - if ($tzid == 'UTC') |
|
| 5006 | - continue; |
|
| 5302 | + if ($tzid == 'UTC') { |
|
| 5303 | + continue; |
|
| 5304 | + } |
|
| 5007 | 5305 | |
| 5008 | 5306 | $tz = timezone_open($tzid); |
| 5009 | 5307 | |
@@ -5018,12 +5316,14 @@ discard block |
||
| 5018 | 5316 | $tzgeo = timezone_location_get($tz); |
| 5019 | 5317 | |
| 5020 | 5318 | // Don't overwrite our preferred tzids |
| 5021 | - if (empty($zones[$tzkey]['tzid'])) |
|
| 5022 | - $zones[$tzkey]['tzid'] = $tzid; |
|
| 5319 | + if (empty($zones[$tzkey]['tzid'])) { |
|
| 5320 | + $zones[$tzkey]['tzid'] = $tzid; |
|
| 5321 | + } |
|
| 5023 | 5322 | |
| 5024 | 5323 | // A time zone from a prioritized country? |
| 5025 | - if (in_array($tzid, $priority_tzids)) |
|
| 5026 | - $priority_zones[$tzkey] = true; |
|
| 5324 | + if (in_array($tzid, $priority_tzids)) { |
|
| 5325 | + $priority_zones[$tzkey] = true; |
|
| 5326 | + } |
|
| 5027 | 5327 | |
| 5028 | 5328 | // Keep track of the location and offset for this tzid |
| 5029 | 5329 | $tzid_parts = explode('/', $tzid); |
@@ -5044,15 +5344,17 @@ discard block |
||
| 5044 | 5344 | |
| 5045 | 5345 | date_timezone_set($date_when, timezone_open($tzvalue['tzid'])); |
| 5046 | 5346 | |
| 5047 | - if (!empty($timezone_descriptions[$tzvalue['tzid']])) |
|
| 5048 | - $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
| 5049 | - else |
|
| 5050 | - $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
| 5347 | + if (!empty($timezone_descriptions[$tzvalue['tzid']])) { |
|
| 5348 | + $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
| 5349 | + } else { |
|
| 5350 | + $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
| 5351 | + } |
|
| 5051 | 5352 | |
| 5052 | - if (isset($priority_zones[$tzkey])) |
|
| 5053 | - $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
| 5054 | - else |
|
| 5055 | - $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
| 5353 | + if (isset($priority_zones[$tzkey])) { |
|
| 5354 | + $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
| 5355 | + } else { |
|
| 5356 | + $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
| 5357 | + } |
|
| 5056 | 5358 | } |
| 5057 | 5359 | |
| 5058 | 5360 | $timezones = array_merge( |
@@ -5106,9 +5408,9 @@ discard block |
||
| 5106 | 5408 | 'Indian/Kerguelen' => 'TFT', |
| 5107 | 5409 | ); |
| 5108 | 5410 | |
| 5109 | - if (!empty($missing_tz_abbrs[$tzid])) |
|
| 5110 | - $tz_abbrev = $missing_tz_abbrs[$tzid]; |
|
| 5111 | - else |
|
| 5411 | + if (!empty($missing_tz_abbrs[$tzid])) { |
|
| 5412 | + $tz_abbrev = $missing_tz_abbrs[$tzid]; |
|
| 5413 | + } else |
|
| 5112 | 5414 | { |
| 5113 | 5415 | // Russia likes to experiment with time zones often, and names them as offsets from Moscow |
| 5114 | 5416 | $tz_location = timezone_location_get(timezone_open($tzid)); |
@@ -5136,8 +5438,9 @@ discard block |
||
| 5136 | 5438 | */ |
| 5137 | 5439 | function inet_ptod($ip_address) |
| 5138 | 5440 | { |
| 5139 | - if (!isValidIP($ip_address)) |
|
| 5140 | - return $ip_address; |
|
| 5441 | + if (!isValidIP($ip_address)) { |
|
| 5442 | + return $ip_address; |
|
| 5443 | + } |
|
| 5141 | 5444 | |
| 5142 | 5445 | $bin = inet_pton($ip_address); |
| 5143 | 5446 | return $bin; |
@@ -5149,13 +5452,15 @@ discard block |
||
| 5149 | 5452 | */ |
| 5150 | 5453 | function inet_dtop($bin) |
| 5151 | 5454 | { |
| 5152 | - if(empty($bin)) |
|
| 5153 | - return ''; |
|
| 5455 | + if(empty($bin)) { |
|
| 5456 | + return ''; |
|
| 5457 | + } |
|
| 5154 | 5458 | |
| 5155 | 5459 | global $db_type; |
| 5156 | 5460 | |
| 5157 | - if ($db_type == 'postgresql') |
|
| 5158 | - return $bin; |
|
| 5461 | + if ($db_type == 'postgresql') { |
|
| 5462 | + return $bin; |
|
| 5463 | + } |
|
| 5159 | 5464 | |
| 5160 | 5465 | $ip_address = inet_ntop($bin); |
| 5161 | 5466 | |
@@ -5180,26 +5485,32 @@ discard block |
||
| 5180 | 5485 | */ |
| 5181 | 5486 | function _safe_serialize($value) |
| 5182 | 5487 | { |
| 5183 | - if(is_null($value)) |
|
| 5184 | - return 'N;'; |
|
| 5488 | + if(is_null($value)) { |
|
| 5489 | + return 'N;'; |
|
| 5490 | + } |
|
| 5185 | 5491 | |
| 5186 | - if(is_bool($value)) |
|
| 5187 | - return 'b:'. (int) $value .';'; |
|
| 5492 | + if(is_bool($value)) { |
|
| 5493 | + return 'b:'. (int) $value .';'; |
|
| 5494 | + } |
|
| 5188 | 5495 | |
| 5189 | - if(is_int($value)) |
|
| 5190 | - return 'i:'. $value .';'; |
|
| 5496 | + if(is_int($value)) { |
|
| 5497 | + return 'i:'. $value .';'; |
|
| 5498 | + } |
|
| 5191 | 5499 | |
| 5192 | - if(is_float($value)) |
|
| 5193 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
| 5500 | + if(is_float($value)) { |
|
| 5501 | + return 'd:'. str_replace(',', '.', $value) .';'; |
|
| 5502 | + } |
|
| 5194 | 5503 | |
| 5195 | - if(is_string($value)) |
|
| 5196 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
| 5504 | + if(is_string($value)) { |
|
| 5505 | + return 's:'. strlen($value) .':"'. $value .'";'; |
|
| 5506 | + } |
|
| 5197 | 5507 | |
| 5198 | 5508 | if(is_array($value)) |
| 5199 | 5509 | { |
| 5200 | 5510 | $out = ''; |
| 5201 | - foreach($value as $k => $v) |
|
| 5202 | - $out .= _safe_serialize($k) . _safe_serialize($v); |
|
| 5511 | + foreach($value as $k => $v) { |
|
| 5512 | + $out .= _safe_serialize($k) . _safe_serialize($v); |
|
| 5513 | + } |
|
| 5203 | 5514 | |
| 5204 | 5515 | return 'a:'. count($value) .':{'. $out .'}'; |
| 5205 | 5516 | } |
@@ -5225,8 +5536,9 @@ discard block |
||
| 5225 | 5536 | |
| 5226 | 5537 | $out = _safe_serialize($value); |
| 5227 | 5538 | |
| 5228 | - if (isset($mbIntEnc)) |
|
| 5229 | - mb_internal_encoding($mbIntEnc); |
|
| 5539 | + if (isset($mbIntEnc)) { |
|
| 5540 | + mb_internal_encoding($mbIntEnc); |
|
| 5541 | + } |
|
| 5230 | 5542 | |
| 5231 | 5543 | return $out; |
| 5232 | 5544 | } |
@@ -5243,8 +5555,9 @@ discard block |
||
| 5243 | 5555 | function _safe_unserialize($str) |
| 5244 | 5556 | { |
| 5245 | 5557 | // Input is not a string. |
| 5246 | - if(empty($str) || !is_string($str)) |
|
| 5247 | - return false; |
|
| 5558 | + if(empty($str) || !is_string($str)) { |
|
| 5559 | + return false; |
|
| 5560 | + } |
|
| 5248 | 5561 | |
| 5249 | 5562 | $stack = array(); |
| 5250 | 5563 | $expected = array(); |
@@ -5260,43 +5573,38 @@ discard block |
||
| 5260 | 5573 | while($state != 1) |
| 5261 | 5574 | { |
| 5262 | 5575 | $type = isset($str[0]) ? $str[0] : ''; |
| 5263 | - if($type == '}') |
|
| 5264 | - $str = substr($str, 1); |
|
| 5265 | - |
|
| 5266 | - else if($type == 'N' && $str[1] == ';') |
|
| 5576 | + if($type == '}') { |
|
| 5577 | + $str = substr($str, 1); |
|
| 5578 | + } else if($type == 'N' && $str[1] == ';') |
|
| 5267 | 5579 | { |
| 5268 | 5580 | $value = null; |
| 5269 | 5581 | $str = substr($str, 2); |
| 5270 | - } |
|
| 5271 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
| 5582 | + } else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
| 5272 | 5583 | { |
| 5273 | 5584 | $value = $matches[1] == '1' ? true : false; |
| 5274 | 5585 | $str = substr($str, 4); |
| 5275 | - } |
|
| 5276 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
| 5586 | + } else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
| 5277 | 5587 | { |
| 5278 | 5588 | $value = (int)$matches[1]; |
| 5279 | 5589 | $str = $matches[2]; |
| 5280 | - } |
|
| 5281 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
| 5590 | + } else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
| 5282 | 5591 | { |
| 5283 | 5592 | $value = (float)$matches[1]; |
| 5284 | 5593 | $str = $matches[3]; |
| 5285 | - } |
|
| 5286 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
| 5594 | + } else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
| 5287 | 5595 | { |
| 5288 | 5596 | $value = substr($matches[2], 0, (int)$matches[1]); |
| 5289 | 5597 | $str = substr($matches[2], (int)$matches[1] + 2); |
| 5290 | - } |
|
| 5291 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
| 5598 | + } else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
| 5292 | 5599 | { |
| 5293 | 5600 | $expectedLength = (int)$matches[1]; |
| 5294 | 5601 | $str = $matches[2]; |
| 5295 | 5602 | } |
| 5296 | 5603 | |
| 5297 | 5604 | // Object or unknown/malformed type. |
| 5298 | - else |
|
| 5299 | - return false; |
|
| 5605 | + else { |
|
| 5606 | + return false; |
|
| 5607 | + } |
|
| 5300 | 5608 | |
| 5301 | 5609 | switch($state) |
| 5302 | 5610 | { |
@@ -5324,8 +5632,9 @@ discard block |
||
| 5324 | 5632 | if($type == '}') |
| 5325 | 5633 | { |
| 5326 | 5634 | // Array size is less than expected. |
| 5327 | - if(count($list) < end($expected)) |
|
| 5328 | - return false; |
|
| 5635 | + if(count($list) < end($expected)) { |
|
| 5636 | + return false; |
|
| 5637 | + } |
|
| 5329 | 5638 | |
| 5330 | 5639 | unset($list); |
| 5331 | 5640 | $list = &$stack[count($stack)-1]; |
@@ -5334,8 +5643,9 @@ discard block |
||
| 5334 | 5643 | // Go to terminal state if we're at the end of the root array. |
| 5335 | 5644 | array_pop($expected); |
| 5336 | 5645 | |
| 5337 | - if(count($expected) == 0) |
|
| 5338 | - $state = 1; |
|
| 5646 | + if(count($expected) == 0) { |
|
| 5647 | + $state = 1; |
|
| 5648 | + } |
|
| 5339 | 5649 | |
| 5340 | 5650 | break; |
| 5341 | 5651 | } |
@@ -5343,8 +5653,9 @@ discard block |
||
| 5343 | 5653 | if($type == 'i' || $type == 's') |
| 5344 | 5654 | { |
| 5345 | 5655 | // Array size exceeds expected length. |
| 5346 | - if(count($list) >= end($expected)) |
|
| 5347 | - return false; |
|
| 5656 | + if(count($list) >= end($expected)) { |
|
| 5657 | + return false; |
|
| 5658 | + } |
|
| 5348 | 5659 | |
| 5349 | 5660 | $key = $value; |
| 5350 | 5661 | $state = 3; |
@@ -5378,8 +5689,9 @@ discard block |
||
| 5378 | 5689 | } |
| 5379 | 5690 | |
| 5380 | 5691 | // Trailing data in input. |
| 5381 | - if(!empty($str)) |
|
| 5382 | - return false; |
|
| 5692 | + if(!empty($str)) { |
|
| 5693 | + return false; |
|
| 5694 | + } |
|
| 5383 | 5695 | |
| 5384 | 5696 | return $data; |
| 5385 | 5697 | } |
@@ -5402,8 +5714,9 @@ discard block |
||
| 5402 | 5714 | |
| 5403 | 5715 | $out = _safe_unserialize($str); |
| 5404 | 5716 | |
| 5405 | - if (isset($mbIntEnc)) |
|
| 5406 | - mb_internal_encoding($mbIntEnc); |
|
| 5717 | + if (isset($mbIntEnc)) { |
|
| 5718 | + mb_internal_encoding($mbIntEnc); |
|
| 5719 | + } |
|
| 5407 | 5720 | |
| 5408 | 5721 | return $out; |
| 5409 | 5722 | } |
@@ -5418,12 +5731,14 @@ discard block |
||
| 5418 | 5731 | function smf_chmod($file, $value = 0) |
| 5419 | 5732 | { |
| 5420 | 5733 | // No file? no checks! |
| 5421 | - if (empty($file)) |
|
| 5422 | - return false; |
|
| 5734 | + if (empty($file)) { |
|
| 5735 | + return false; |
|
| 5736 | + } |
|
| 5423 | 5737 | |
| 5424 | 5738 | // Already writable? |
| 5425 | - if (is_writable($file)) |
|
| 5426 | - return true; |
|
| 5739 | + if (is_writable($file)) { |
|
| 5740 | + return true; |
|
| 5741 | + } |
|
| 5427 | 5742 | |
| 5428 | 5743 | // Do we have a file or a dir? |
| 5429 | 5744 | $isDir = is_dir($file); |
@@ -5439,10 +5754,9 @@ discard block |
||
| 5439 | 5754 | { |
| 5440 | 5755 | $isWritable = true; |
| 5441 | 5756 | break; |
| 5757 | + } else { |
|
| 5758 | + @chmod($file, $val); |
|
| 5442 | 5759 | } |
| 5443 | - |
|
| 5444 | - else |
|
| 5445 | - @chmod($file, $val); |
|
| 5446 | 5760 | } |
| 5447 | 5761 | |
| 5448 | 5762 | return $isWritable; |
@@ -5461,8 +5775,9 @@ discard block |
||
| 5461 | 5775 | global $txt; |
| 5462 | 5776 | |
| 5463 | 5777 | // Come on... |
| 5464 | - if (empty($json) || !is_string($json)) |
|
| 5465 | - return array(); |
|
| 5778 | + if (empty($json) || !is_string($json)) { |
|
| 5779 | + return array(); |
|
| 5780 | + } |
|
| 5466 | 5781 | |
| 5467 | 5782 | $returnArray = @json_decode($json, $returnAsArray); |
| 5468 | 5783 | |
@@ -5500,11 +5815,11 @@ discard block |
||
| 5500 | 5815 | $jsonDebug = $jsonDebug[0]; |
| 5501 | 5816 | loadLanguage('Errors'); |
| 5502 | 5817 | |
| 5503 | - if (!empty($jsonDebug)) |
|
| 5504 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
| 5505 | - |
|
| 5506 | - else |
|
| 5507 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
| 5818 | + if (!empty($jsonDebug)) { |
|
| 5819 | + log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
| 5820 | + } else { |
|
| 5821 | + log_error($txt['json_'. $jsonError], 'critical'); |
|
| 5822 | + } |
|
| 5508 | 5823 | |
| 5509 | 5824 | // Everyone expects an array. |
| 5510 | 5825 | return array(); |
@@ -5534,8 +5849,9 @@ discard block |
||
| 5534 | 5849 | global $db_show_debug, $modSettings; |
| 5535 | 5850 | |
| 5536 | 5851 | // Defensive programming anyone? |
| 5537 | - if (empty($data)) |
|
| 5538 | - return false; |
|
| 5852 | + if (empty($data)) { |
|
| 5853 | + return false; |
|
| 5854 | + } |
|
| 5539 | 5855 | |
| 5540 | 5856 | // Don't need extra stuff... |
| 5541 | 5857 | $db_show_debug = false; |
@@ -5543,11 +5859,11 @@ discard block |
||
| 5543 | 5859 | // Kill anything else. |
| 5544 | 5860 | ob_end_clean(); |
| 5545 | 5861 | |
| 5546 | - if (!empty($modSettings['CompressedOutput'])) |
|
| 5547 | - @ob_start('ob_gzhandler'); |
|
| 5548 | - |
|
| 5549 | - else |
|
| 5550 | - ob_start(); |
|
| 5862 | + if (!empty($modSettings['CompressedOutput'])) { |
|
| 5863 | + @ob_start('ob_gzhandler'); |
|
| 5864 | + } else { |
|
| 5865 | + ob_start(); |
|
| 5866 | + } |
|
| 5551 | 5867 | |
| 5552 | 5868 | // Set the header. |
| 5553 | 5869 | header($type); |
@@ -5579,8 +5895,9 @@ discard block |
||
| 5579 | 5895 | static $done = false; |
| 5580 | 5896 | |
| 5581 | 5897 | // If we don't need to do anything, don't |
| 5582 | - if (!$update && $done) |
|
| 5583 | - return; |
|
| 5898 | + if (!$update && $done) { |
|
| 5899 | + return; |
|
| 5900 | + } |
|
| 5584 | 5901 | |
| 5585 | 5902 | // Should we get a new copy of the official list of TLDs? |
| 5586 | 5903 | if ($update) |
@@ -5601,10 +5918,11 @@ discard block |
||
| 5601 | 5918 | // Clean $tlds and convert it to an array |
| 5602 | 5919 | $tlds = array_filter(explode("\n", strtolower($tlds)), function($line) { |
| 5603 | 5920 | $line = trim($line); |
| 5604 | - if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) |
|
| 5605 | - return false; |
|
| 5606 | - else |
|
| 5607 | - return true; |
|
| 5921 | + if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) { |
|
| 5922 | + return false; |
|
| 5923 | + } else { |
|
| 5924 | + return true; |
|
| 5925 | + } |
|
| 5608 | 5926 | }); |
| 5609 | 5927 | |
| 5610 | 5928 | // Convert Punycode to Unicode |
@@ -5658,8 +5976,9 @@ discard block |
||
| 5658 | 5976 | $idx += $digit * $w; |
| 5659 | 5977 | $t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias)); |
| 5660 | 5978 | |
| 5661 | - if ($digit < $t) |
|
| 5662 | - break; |
|
| 5979 | + if ($digit < $t) { |
|
| 5980 | + break; |
|
| 5981 | + } |
|
| 5663 | 5982 | |
| 5664 | 5983 | $w = (int) ($w * ($base - $t)); |
| 5665 | 5984 | } |
@@ -5668,8 +5987,9 @@ discard block |
||
| 5668 | 5987 | $delta = intval($is_first ? ($delta / $damp) : ($delta / 2)); |
| 5669 | 5988 | $delta += intval($delta / ($deco_len + 1)); |
| 5670 | 5989 | |
| 5671 | - for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) |
|
| 5672 | - $delta = intval($delta / ($base - $tmin)); |
|
| 5990 | + for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) { |
|
| 5991 | + $delta = intval($delta / ($base - $tmin)); |
|
| 5992 | + } |
|
| 5673 | 5993 | |
| 5674 | 5994 | $bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew)); |
| 5675 | 5995 | $is_first = false; |
@@ -5678,8 +5998,9 @@ discard block |
||
| 5678 | 5998 | |
| 5679 | 5999 | if ($deco_len > 0) |
| 5680 | 6000 | { |
| 5681 | - for ($i = $deco_len; $i > $idx; $i--) |
|
| 5682 | - $decoded[$i] = $decoded[($i - 1)]; |
|
| 6001 | + for ($i = $deco_len; $i > $idx; $i--) { |
|
| 6002 | + $decoded[$i] = $decoded[($i - 1)]; |
|
| 6003 | + } |
|
| 5683 | 6004 | } |
| 5684 | 6005 | $decoded[$idx++] = $char; |
| 5685 | 6006 | } |
@@ -5687,24 +6008,29 @@ discard block |
||
| 5687 | 6008 | foreach ($decoded as $k => $v) |
| 5688 | 6009 | { |
| 5689 | 6010 | // 7bit are transferred literally |
| 5690 | - if ($v < 128) |
|
| 5691 | - $output .= chr($v); |
|
| 6011 | + if ($v < 128) { |
|
| 6012 | + $output .= chr($v); |
|
| 6013 | + } |
|
| 5692 | 6014 | |
| 5693 | 6015 | // 2 bytes |
| 5694 | - elseif ($v < (1 << 11)) |
|
| 5695 | - $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
| 6016 | + elseif ($v < (1 << 11)) { |
|
| 6017 | + $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
| 6018 | + } |
|
| 5696 | 6019 | |
| 5697 | 6020 | // 3 bytes |
| 5698 | - elseif ($v < (1 << 16)) |
|
| 5699 | - $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 6021 | + elseif ($v < (1 << 16)) { |
|
| 6022 | + $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 6023 | + } |
|
| 5700 | 6024 | |
| 5701 | 6025 | // 4 bytes |
| 5702 | - elseif ($v < (1 << 21)) |
|
| 5703 | - $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 6026 | + elseif ($v < (1 << 21)) { |
|
| 6027 | + $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 6028 | + } |
|
| 5704 | 6029 | |
| 5705 | 6030 | // 'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k |
| 5706 | - else |
|
| 5707 | - $output .= $safe_char; |
|
| 6031 | + else { |
|
| 6032 | + $output .= $safe_char; |
|
| 6033 | + } |
|
| 5708 | 6034 | } |
| 5709 | 6035 | |
| 5710 | 6036 | $output_parts[] = $output; |
@@ -5799,8 +6125,7 @@ discard block |
||
| 5799 | 6125 | |
| 5800 | 6126 | $strlen = 'mb_strlen'; |
| 5801 | 6127 | $substr = 'mb_substr'; |
| 5802 | - } |
|
| 5803 | - else |
|
| 6128 | + } else |
|
| 5804 | 6129 | { |
| 5805 | 6130 | $strlen = $smcFunc['strlen']; |
| 5806 | 6131 | $substr = $smcFunc['substr']; |
@@ -5814,20 +6139,21 @@ discard block |
||
| 5814 | 6139 | |
| 5815 | 6140 | $first = $substr($string, 0, 1); |
| 5816 | 6141 | |
| 5817 | - if (empty($index[$first])) |
|
| 5818 | - $index[$first] = array(); |
|
| 6142 | + if (empty($index[$first])) { |
|
| 6143 | + $index[$first] = array(); |
|
| 6144 | + } |
|
| 5819 | 6145 | |
| 5820 | 6146 | if ($strlen($string) > 1) |
| 5821 | 6147 | { |
| 5822 | 6148 | // Sanity check on recursion |
| 5823 | - if ($depth > 99) |
|
| 5824 | - $index[$first][$substr($string, 1)] = ''; |
|
| 5825 | - |
|
| 5826 | - else |
|
| 5827 | - $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
| 6149 | + if ($depth > 99) { |
|
| 6150 | + $index[$first][$substr($string, 1)] = ''; |
|
| 6151 | + } else { |
|
| 6152 | + $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
| 6153 | + } |
|
| 6154 | + } else { |
|
| 6155 | + $index[$first][''] = ''; |
|
| 5828 | 6156 | } |
| 5829 | - else |
|
| 5830 | - $index[$first][''] = ''; |
|
| 5831 | 6157 | |
| 5832 | 6158 | $depth--; |
| 5833 | 6159 | return $index; |
@@ -5850,9 +6176,9 @@ discard block |
||
| 5850 | 6176 | $key_regex = preg_quote($key, $delim); |
| 5851 | 6177 | $new_key = $key; |
| 5852 | 6178 | |
| 5853 | - if (empty($value)) |
|
| 5854 | - $sub_regex = ''; |
|
| 5855 | - else |
|
| 6179 | + if (empty($value)) { |
|
| 6180 | + $sub_regex = ''; |
|
| 6181 | + } else |
|
| 5856 | 6182 | { |
| 5857 | 6183 | $sub_regex = $index_to_regex($value, $delim); |
| 5858 | 6184 | |
@@ -5860,22 +6186,22 @@ discard block |
||
| 5860 | 6186 | { |
| 5861 | 6187 | $new_key_array = explode('(?'.'>', $sub_regex); |
| 5862 | 6188 | $new_key .= $new_key_array[0]; |
| 6189 | + } else { |
|
| 6190 | + $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
| 5863 | 6191 | } |
| 5864 | - else |
|
| 5865 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
| 5866 | 6192 | } |
| 5867 | 6193 | |
| 5868 | - if ($depth > 1) |
|
| 5869 | - $regex[$new_key] = $key_regex . $sub_regex; |
|
| 5870 | - else |
|
| 6194 | + if ($depth > 1) { |
|
| 6195 | + $regex[$new_key] = $key_regex . $sub_regex; |
|
| 6196 | + } else |
|
| 5871 | 6197 | { |
| 5872 | 6198 | if (($length += strlen($key_regex) + 1) < $max_length || empty($regex)) |
| 5873 | 6199 | { |
| 5874 | 6200 | $regex[$new_key] = $key_regex . $sub_regex; |
| 5875 | 6201 | unset($index[$key]); |
| 6202 | + } else { |
|
| 6203 | + break; |
|
| 5876 | 6204 | } |
| 5877 | - else |
|
| 5878 | - break; |
|
| 5879 | 6205 | } |
| 5880 | 6206 | } |
| 5881 | 6207 | |
@@ -5884,10 +6210,11 @@ discard block |
||
| 5884 | 6210 | $l1 = $strlen($k1); |
| 5885 | 6211 | $l2 = $strlen($k2); |
| 5886 | 6212 | |
| 5887 | - if ($l1 == $l2) |
|
| 5888 | - return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
| 5889 | - else |
|
| 5890 | - return $l1 > $l2 ? -1 : 1; |
|
| 6213 | + if ($l1 == $l2) { |
|
| 6214 | + return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
| 6215 | + } else { |
|
| 6216 | + return $l1 > $l2 ? -1 : 1; |
|
| 6217 | + } |
|
| 5891 | 6218 | }); |
| 5892 | 6219 | |
| 5893 | 6220 | $depth--; |
@@ -5898,15 +6225,18 @@ discard block |
||
| 5898 | 6225 | $index = array(); |
| 5899 | 6226 | $regexes = array(); |
| 5900 | 6227 | |
| 5901 | - foreach ($strings as $string) |
|
| 5902 | - $index = $add_string_to_index($string, $index); |
|
| 6228 | + foreach ($strings as $string) { |
|
| 6229 | + $index = $add_string_to_index($string, $index); |
|
| 6230 | + } |
|
| 5903 | 6231 | |
| 5904 | - while (!empty($index)) |
|
| 5905 | - $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
| 6232 | + while (!empty($index)) { |
|
| 6233 | + $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
| 6234 | + } |
|
| 5906 | 6235 | |
| 5907 | 6236 | // Restore PHP's internal character encoding to whatever it was originally |
| 5908 | - if (!empty($current_encoding)) |
|
| 5909 | - mb_internal_encoding($current_encoding); |
|
| 6237 | + if (!empty($current_encoding)) { |
|
| 6238 | + mb_internal_encoding($current_encoding); |
|
| 6239 | + } |
|
| 5910 | 6240 | |
| 5911 | 6241 | return $regexes; |
| 5912 | 6242 | } |
@@ -31,67 +31,67 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class ReCaptcha |
| 33 | 33 | { |
| 34 | - /** |
|
| 35 | - * Version of this client library. |
|
| 36 | - * @const string |
|
| 37 | - */ |
|
| 38 | - const VERSION = 'php_1.1.2'; |
|
| 34 | + /** |
|
| 35 | + * Version of this client library. |
|
| 36 | + * @const string |
|
| 37 | + */ |
|
| 38 | + const VERSION = 'php_1.1.2'; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Shared secret for the site. |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 44 | - private $secret; |
|
| 40 | + /** |
|
| 41 | + * Shared secret for the site. |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | + private $secret; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Method used to communicate with service. Defaults to POST request. |
|
| 48 | - * @var RequestMethod |
|
| 49 | - */ |
|
| 50 | - private $requestMethod; |
|
| 46 | + /** |
|
| 47 | + * Method used to communicate with service. Defaults to POST request. |
|
| 48 | + * @var RequestMethod |
|
| 49 | + */ |
|
| 50 | + private $requestMethod; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Create a configured instance to use the reCAPTCHA service. |
|
| 54 | - * |
|
| 55 | - * @param string $secret shared secret between site and reCAPTCHA server. |
|
| 56 | - * @param RequestMethod $requestMethod method used to send the request. Defaults to POST. |
|
| 57 | - */ |
|
| 58 | - public function __construct($secret, RequestMethod $requestMethod = null) |
|
| 59 | - { |
|
| 60 | - if (empty($secret)) { |
|
| 61 | - throw new \RuntimeException('No secret provided'); |
|
| 62 | - } |
|
| 52 | + /** |
|
| 53 | + * Create a configured instance to use the reCAPTCHA service. |
|
| 54 | + * |
|
| 55 | + * @param string $secret shared secret between site and reCAPTCHA server. |
|
| 56 | + * @param RequestMethod $requestMethod method used to send the request. Defaults to POST. |
|
| 57 | + */ |
|
| 58 | + public function __construct($secret, RequestMethod $requestMethod = null) |
|
| 59 | + { |
|
| 60 | + if (empty($secret)) { |
|
| 61 | + throw new \RuntimeException('No secret provided'); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - if (!is_string($secret)) { |
|
| 65 | - throw new \RuntimeException('The provided secret must be a string'); |
|
| 66 | - } |
|
| 64 | + if (!is_string($secret)) { |
|
| 65 | + throw new \RuntimeException('The provided secret must be a string'); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - $this->secret = $secret; |
|
| 68 | + $this->secret = $secret; |
|
| 69 | 69 | |
| 70 | - if (!is_null($requestMethod)) { |
|
| 71 | - $this->requestMethod = $requestMethod; |
|
| 72 | - } else { |
|
| 73 | - $this->requestMethod = new RequestMethod\Post(); |
|
| 74 | - } |
|
| 75 | - } |
|
| 70 | + if (!is_null($requestMethod)) { |
|
| 71 | + $this->requestMethod = $requestMethod; |
|
| 72 | + } else { |
|
| 73 | + $this->requestMethod = new RequestMethod\Post(); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Calls the reCAPTCHA siteverify API to verify whether the user passes |
|
| 79 | - * CAPTCHA test. |
|
| 80 | - * |
|
| 81 | - * @param string $response The value of 'g-recaptcha-response' in the submitted form. |
|
| 82 | - * @param string $remoteIp The end user's IP address. |
|
| 83 | - * @return Response Response from the service. |
|
| 84 | - */ |
|
| 85 | - public function verify($response, $remoteIp = null) |
|
| 86 | - { |
|
| 87 | - // Discard empty solution submissions |
|
| 88 | - if (empty($response)) { |
|
| 89 | - $recaptchaResponse = new Response(false, array('missing-input-response')); |
|
| 90 | - return $recaptchaResponse; |
|
| 91 | - } |
|
| 77 | + /** |
|
| 78 | + * Calls the reCAPTCHA siteverify API to verify whether the user passes |
|
| 79 | + * CAPTCHA test. |
|
| 80 | + * |
|
| 81 | + * @param string $response The value of 'g-recaptcha-response' in the submitted form. |
|
| 82 | + * @param string $remoteIp The end user's IP address. |
|
| 83 | + * @return Response Response from the service. |
|
| 84 | + */ |
|
| 85 | + public function verify($response, $remoteIp = null) |
|
| 86 | + { |
|
| 87 | + // Discard empty solution submissions |
|
| 88 | + if (empty($response)) { |
|
| 89 | + $recaptchaResponse = new Response(false, array('missing-input-response')); |
|
| 90 | + return $recaptchaResponse; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - $params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION); |
|
| 94 | - $rawResponse = $this->requestMethod->submit($params); |
|
| 95 | - return Response::fromJson($rawResponse); |
|
| 96 | - } |
|
| 93 | + $params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION); |
|
| 94 | + $rawResponse = $this->requestMethod->submit($params); |
|
| 95 | + return Response::fromJson($rawResponse); |
|
| 96 | + } |
|
| 97 | 97 | } |