@@ -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; |
@@ -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? |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 3 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * The central part of the board - topic display. |
@@ -34,8 +35,9 @@ discard block |
||
| 34 | 35 | global $messages_request, $language, $smcFunc; |
| 35 | 36 | |
| 36 | 37 | // What are you gonna display if these are empty?! |
| 37 | - if (empty($topic)) |
|
| 38 | - fatal_lang_error('no_board', false); |
|
| 38 | + if (empty($topic)) { |
|
| 39 | + fatal_lang_error('no_board', false); |
|
| 40 | + } |
|
| 39 | 41 | |
| 40 | 42 | // Load the proper template. |
| 41 | 43 | loadTemplate('Display'); |
@@ -52,15 +54,17 @@ discard block |
||
| 52 | 54 | $context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
| 53 | 55 | |
| 54 | 56 | // Let's do some work on what to search index. |
| 55 | - if (count($_GET) > 2) |
|
| 56 | - foreach ($_GET as $k => $v) |
|
| 57 | + if (count($_GET) > 2) { |
|
| 58 | + foreach ($_GET as $k => $v) |
|
| 57 | 59 | { |
| 58 | 60 | if (!in_array($k, array('topic', 'board', 'start', session_name()))) |
| 59 | 61 | $context['robot_no_index'] = true; |
| 62 | + } |
|
| 60 | 63 | } |
| 61 | 64 | |
| 62 | - if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) |
|
| 63 | - $context['robot_no_index'] = true; |
|
| 65 | + if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) { |
|
| 66 | + $context['robot_no_index'] = true; |
|
| 67 | + } |
|
| 64 | 68 | |
| 65 | 69 | // Find the previous or next topic. Make a fuss if there are no more. |
| 66 | 70 | if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next')) |
@@ -172,8 +176,9 @@ discard block |
||
| 172 | 176 | $topic_parameters |
| 173 | 177 | ); |
| 174 | 178 | |
| 175 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 176 | - fatal_lang_error('not_a_topic', false, 404); |
|
| 179 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 180 | + fatal_lang_error('not_a_topic', false, 404); |
|
| 181 | + } |
|
| 177 | 182 | $context['topicinfo'] = $smcFunc['db_fetch_assoc']($request); |
| 178 | 183 | $smcFunc['db_free_result']($request); |
| 179 | 184 | |
@@ -210,8 +215,9 @@ discard block |
||
| 210 | 215 | $context['topic_unwatched'] = isset($context['topicinfo']['unwatched']) ? $context['topicinfo']['unwatched'] : 0; |
| 211 | 216 | |
| 212 | 217 | // Add up unapproved replies to get real number of replies... |
| 213 | - if ($modSettings['postmod_active'] && $approve_posts) |
|
| 214 | - $context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1); |
|
| 218 | + if ($modSettings['postmod_active'] && $approve_posts) { |
|
| 219 | + $context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1); |
|
| 220 | + } |
|
| 215 | 221 | |
| 216 | 222 | // If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing. |
| 217 | 223 | if ($modSettings['postmod_active'] && $context['topicinfo']['unapproved_posts'] && !$user_info['is_guest'] && !$approve_posts) |
@@ -231,11 +237,11 @@ discard block |
||
| 231 | 237 | $smcFunc['db_free_result']($request); |
| 232 | 238 | |
| 233 | 239 | $context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($context['topicinfo']['approved'] ? 1 : 0); |
| 240 | + } elseif ($user_info['is_guest']) { |
|
| 241 | + $context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
| 242 | + } else { |
|
| 243 | + $context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
| 234 | 244 | } |
| 235 | - elseif ($user_info['is_guest']) |
|
| 236 | - $context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
| 237 | - else |
|
| 238 | - $context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0); |
|
| 239 | 245 | |
| 240 | 246 | // The start isn't a number; it's information about what to do, where to go. |
| 241 | 247 | if (!is_numeric($_REQUEST['start'])) |
@@ -248,8 +254,7 @@ discard block |
||
| 248 | 254 | { |
| 249 | 255 | $context['start_from'] = $context['total_visible_posts'] - 1; |
| 250 | 256 | $_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0; |
| 251 | - } |
|
| 252 | - else |
|
| 257 | + } else |
|
| 253 | 258 | { |
| 254 | 259 | // Find the earliest unread message in the topic. (the use of topics here is just for both tables.) |
| 255 | 260 | $request = $smcFunc['db_query']('', ' |
@@ -277,9 +282,9 @@ discard block |
||
| 277 | 282 | if (substr($_REQUEST['start'], 0, 4) == 'from') |
| 278 | 283 | { |
| 279 | 284 | $timestamp = (int) substr($_REQUEST['start'], 4); |
| 280 | - if ($timestamp === 0) |
|
| 281 | - $_REQUEST['start'] = 0; |
|
| 282 | - else |
|
| 285 | + if ($timestamp === 0) { |
|
| 286 | + $_REQUEST['start'] = 0; |
|
| 287 | + } else |
|
| 283 | 288 | { |
| 284 | 289 | // Find the number of messages posted before said time... |
| 285 | 290 | $request = $smcFunc['db_query']('', ' |
@@ -307,11 +312,11 @@ discard block |
||
| 307 | 312 | elseif (substr($_REQUEST['start'], 0, 3) == 'msg') |
| 308 | 313 | { |
| 309 | 314 | $virtual_msg = (int) substr($_REQUEST['start'], 3); |
| 310 | - if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) |
|
| 311 | - $context['start_from'] = $context['total_visible_posts'] - 1; |
|
| 312 | - elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) |
|
| 313 | - $context['start_from'] = 0; |
|
| 314 | - else |
|
| 315 | + if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) { |
|
| 316 | + $context['start_from'] = $context['total_visible_posts'] - 1; |
|
| 317 | + } elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) { |
|
| 318 | + $context['start_from'] = 0; |
|
| 319 | + } else |
|
| 315 | 320 | { |
| 316 | 321 | // Find the start value for that message...... |
| 317 | 322 | $request = $smcFunc['db_query']('', ' |
@@ -394,21 +399,25 @@ discard block |
||
| 394 | 399 | ); |
| 395 | 400 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 396 | 401 | { |
| 397 | - if (empty($row['id_member'])) |
|
| 398 | - continue; |
|
| 402 | + if (empty($row['id_member'])) { |
|
| 403 | + continue; |
|
| 404 | + } |
|
| 399 | 405 | |
| 400 | - if (!empty($row['online_color'])) |
|
| 401 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
| 402 | - else |
|
| 403 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 406 | + if (!empty($row['online_color'])) { |
|
| 407 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
| 408 | + } else { |
|
| 409 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
| 410 | + } |
|
| 404 | 411 | |
| 405 | 412 | $is_buddy = in_array($row['id_member'], $user_info['buddies']); |
| 406 | - if ($is_buddy) |
|
| 407 | - $link = '<strong>' . $link . '</strong>'; |
|
| 413 | + if ($is_buddy) { |
|
| 414 | + $link = '<strong>' . $link . '</strong>'; |
|
| 415 | + } |
|
| 408 | 416 | |
| 409 | 417 | // Add them both to the list and to the more detailed list. |
| 410 | - if (!empty($row['show_online']) || allowedTo('moderate_forum')) |
|
| 411 | - $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
|
| 418 | + if (!empty($row['show_online']) || allowedTo('moderate_forum')) { |
|
| 419 | + $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
|
| 420 | + } |
|
| 412 | 421 | $context['view_members'][$row['log_time'] . $row['member_name']] = array( |
| 413 | 422 | 'id' => $row['id_member'], |
| 414 | 423 | 'username' => $row['member_name'], |
@@ -420,8 +429,9 @@ discard block |
||
| 420 | 429 | 'hidden' => empty($row['show_online']), |
| 421 | 430 | ); |
| 422 | 431 | |
| 423 | - if (empty($row['show_online'])) |
|
| 424 | - $context['view_num_hidden']++; |
|
| 432 | + if (empty($row['show_online'])) { |
|
| 433 | + $context['view_num_hidden']++; |
|
| 434 | + } |
|
| 425 | 435 | } |
| 426 | 436 | |
| 427 | 437 | // The number of guests is equal to the rows minus the ones we actually used ;). |
@@ -435,11 +445,13 @@ discard block |
||
| 435 | 445 | |
| 436 | 446 | // If all is set, but not allowed... just unset it. |
| 437 | 447 | $can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages']; |
| 438 | - if (isset($_REQUEST['all']) && !$can_show_all) |
|
| 439 | - unset($_REQUEST['all']); |
|
| 448 | + if (isset($_REQUEST['all']) && !$can_show_all) { |
|
| 449 | + unset($_REQUEST['all']); |
|
| 450 | + } |
|
| 440 | 451 | // Otherwise, it must be allowed... so pretend start was -1. |
| 441 | - elseif (isset($_REQUEST['all'])) |
|
| 442 | - $_REQUEST['start'] = -1; |
|
| 452 | + elseif (isset($_REQUEST['all'])) { |
|
| 453 | + $_REQUEST['start'] = -1; |
|
| 454 | + } |
|
| 443 | 455 | |
| 444 | 456 | // Construct the page index, allowing for the .START method... |
| 445 | 457 | $context['page_index'] = constructPageIndex($scripturl . '?topic=' . $topic . '.%1$d', $_REQUEST['start'], $context['total_visible_posts'], $context['messages_per_page'], true); |
@@ -476,8 +488,9 @@ discard block |
||
| 476 | 488 | $_REQUEST['start'] = 0; |
| 477 | 489 | } |
| 478 | 490 | // They aren't using it, but the *option* is there, at least. |
| 479 | - else |
|
| 480 | - $context['page_index'] .= ' <a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> '; |
|
| 491 | + else { |
|
| 492 | + $context['page_index'] .= ' <a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> '; |
|
| 493 | + } |
|
| 481 | 494 | } |
| 482 | 495 | |
| 483 | 496 | // Build the link tree. |
@@ -493,14 +506,16 @@ discard block |
||
| 493 | 506 | if (!empty($board_info['moderators'])) |
| 494 | 507 | { |
| 495 | 508 | // Add a link for each moderator... |
| 496 | - foreach ($board_info['moderators'] as $mod) |
|
| 497 | - $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
|
| 509 | + foreach ($board_info['moderators'] as $mod) { |
|
| 510 | + $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
|
| 511 | + } |
|
| 498 | 512 | } |
| 499 | 513 | if (!empty($board_info['moderator_groups'])) |
| 500 | 514 | { |
| 501 | 515 | // Add a link for each moderator group as well... |
| 502 | - foreach ($board_info['moderator_groups'] as $mod_group) |
|
| 503 | - $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
|
| 516 | + foreach ($board_info['moderator_groups'] as $mod_group) { |
|
| 517 | + $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
|
| 518 | + } |
|
| 504 | 519 | } |
| 505 | 520 | |
| 506 | 521 | if (!empty($context['link_moderators'])) |
@@ -531,9 +546,9 @@ discard block |
||
| 531 | 546 | // For quick reply we need a response prefix in the default forum language. |
| 532 | 547 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600))) |
| 533 | 548 | { |
| 534 | - if ($language === $user_info['language']) |
|
| 535 | - $context['response_prefix'] = $txt['response_prefix']; |
|
| 536 | - else |
|
| 549 | + if ($language === $user_info['language']) { |
|
| 550 | + $context['response_prefix'] = $txt['response_prefix']; |
|
| 551 | + } else |
|
| 537 | 552 | { |
| 538 | 553 | loadLanguage('index', $language, false); |
| 539 | 554 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -565,8 +580,9 @@ discard block |
||
| 565 | 580 | list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row); |
| 566 | 581 | |
| 567 | 582 | // Sanity check |
| 568 | - if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) |
|
| 569 | - continue; |
|
| 583 | + if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) { |
|
| 584 | + continue; |
|
| 585 | + } |
|
| 570 | 586 | |
| 571 | 587 | $linked_calendar_event = array( |
| 572 | 588 | 'id' => $row['id_event'], |
@@ -615,8 +631,9 @@ discard block |
||
| 615 | 631 | } |
| 616 | 632 | $smcFunc['db_free_result']($request); |
| 617 | 633 | |
| 618 | - if (!empty($context['linked_calendar_events'])) |
|
| 619 | - $context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true; |
|
| 634 | + if (!empty($context['linked_calendar_events'])) { |
|
| 635 | + $context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true; |
|
| 636 | + } |
|
| 620 | 637 | } |
| 621 | 638 | |
| 622 | 639 | // Create the poll info if it exists. |
@@ -689,20 +706,21 @@ discard block |
||
| 689 | 706 | foreach ($guestinfo as $i => $guestvoted) |
| 690 | 707 | { |
| 691 | 708 | $guestvoted = explode(',', $guestvoted); |
| 692 | - if ($guestvoted[0] == $context['topicinfo']['id_poll']) |
|
| 693 | - break; |
|
| 709 | + if ($guestvoted[0] == $context['topicinfo']['id_poll']) { |
|
| 710 | + break; |
|
| 711 | + } |
|
| 694 | 712 | } |
| 695 | 713 | // Has the poll been reset since guest voted? |
| 696 | 714 | if ($pollinfo['reset_poll'] > $guestvoted[1]) |
| 697 | 715 | { |
| 698 | 716 | // Remove the poll info from the cookie to allow guest to vote again |
| 699 | 717 | unset($guestinfo[$i]); |
| 700 | - if (!empty($guestinfo)) |
|
| 701 | - $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo); |
|
| 702 | - else |
|
| 703 | - unset($_COOKIE['guest_poll_vote']); |
|
| 704 | - } |
|
| 705 | - else |
|
| 718 | + if (!empty($guestinfo)) { |
|
| 719 | + $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo); |
|
| 720 | + } else { |
|
| 721 | + unset($_COOKIE['guest_poll_vote']); |
|
| 722 | + } |
|
| 723 | + } else |
|
| 706 | 724 | { |
| 707 | 725 | // What did they vote for? |
| 708 | 726 | unset($guestvoted[0], $guestvoted[1]); |
@@ -816,23 +834,29 @@ discard block |
||
| 816 | 834 | // Build the poll moderation button array. |
| 817 | 835 | $context['poll_buttons'] = array(); |
| 818 | 836 | |
| 819 | - if ($context['allow_return_vote']) |
|
| 820 | - $context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']); |
|
| 837 | + if ($context['allow_return_vote']) { |
|
| 838 | + $context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']); |
|
| 839 | + } |
|
| 821 | 840 | |
| 822 | - if ($context['show_view_results_button']) |
|
| 823 | - $context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults'); |
|
| 841 | + if ($context['show_view_results_button']) { |
|
| 842 | + $context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults'); |
|
| 843 | + } |
|
| 824 | 844 | |
| 825 | - if ($context['allow_change_vote']) |
|
| 826 | - $context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 845 | + if ($context['allow_change_vote']) { |
|
| 846 | + $context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 847 | + } |
|
| 827 | 848 | |
| 828 | - if ($context['allow_lock_poll']) |
|
| 829 | - $context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 849 | + if ($context['allow_lock_poll']) { |
|
| 850 | + $context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 851 | + } |
|
| 830 | 852 | |
| 831 | - if ($context['allow_edit_poll']) |
|
| 832 | - $context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
| 853 | + if ($context['allow_edit_poll']) { |
|
| 854 | + $context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
| 855 | + } |
|
| 833 | 856 | |
| 834 | - if ($context['can_remove_poll']) |
|
| 835 | - $context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 857 | + if ($context['can_remove_poll']) { |
|
| 858 | + $context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 859 | + } |
|
| 836 | 860 | |
| 837 | 861 | // Allow mods to add additional buttons here |
| 838 | 862 | call_integration_hook('integrate_poll_buttons'); |
@@ -873,8 +897,9 @@ discard block |
||
| 873 | 897 | $all_posters = array(); |
| 874 | 898 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 875 | 899 | { |
| 876 | - if (!empty($row['id_member'])) |
|
| 877 | - $all_posters[$row['id_msg']] = $row['id_member']; |
|
| 900 | + if (!empty($row['id_member'])) { |
|
| 901 | + $all_posters[$row['id_msg']] = $row['id_member']; |
|
| 902 | + } |
|
| 878 | 903 | $messages[] = $row['id_msg']; |
| 879 | 904 | } |
| 880 | 905 | $smcFunc['db_free_result']($request); |
@@ -886,8 +911,9 @@ discard block |
||
| 886 | 911 | if (!$user_info['is_guest'] && !empty($messages)) |
| 887 | 912 | { |
| 888 | 913 | $mark_at_msg = max($messages); |
| 889 | - if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) |
|
| 890 | - $mark_at_msg = $modSettings['maxMsgID']; |
|
| 914 | + if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) { |
|
| 915 | + $mark_at_msg = $modSettings['maxMsgID']; |
|
| 916 | + } |
|
| 891 | 917 | if ($mark_at_msg >= $context['topicinfo']['new_from']) |
| 892 | 918 | { |
| 893 | 919 | $smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace', |
@@ -919,8 +945,9 @@ discard block |
||
| 919 | 945 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 920 | 946 | { |
| 921 | 947 | // Find if this topic is marked for notification... |
| 922 | - if (!empty($row['id_topic'])) |
|
| 923 | - $context['is_marked_notify'] = true; |
|
| 948 | + if (!empty($row['id_topic'])) { |
|
| 949 | + $context['is_marked_notify'] = true; |
|
| 950 | + } |
|
| 924 | 951 | |
| 925 | 952 | // Only do this once, but mark the notifications as "not sent yet" for next time. |
| 926 | 953 | if (!empty($row['sent']) && $do_once) |
@@ -942,8 +969,9 @@ discard block |
||
| 942 | 969 | } |
| 943 | 970 | |
| 944 | 971 | // Have we recently cached the number of new topics in this board, and it's still a lot? |
| 945 | - if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) |
|
| 946 | - $_SESSION['topicseen_cache'][$board]--; |
|
| 972 | + if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) { |
|
| 973 | + $_SESSION['topicseen_cache'][$board]--; |
|
| 974 | + } |
|
| 947 | 975 | // Mark board as seen if this is the only new topic. |
| 948 | 976 | elseif (isset($_REQUEST['topicseen'])) |
| 949 | 977 | { |
@@ -967,14 +995,16 @@ discard block |
||
| 967 | 995 | $smcFunc['db_free_result']($request); |
| 968 | 996 | |
| 969 | 997 | // If there're no real new topics in this board, mark the board as seen. |
| 970 | - if (empty($numNewTopics)) |
|
| 971 | - $_REQUEST['boardseen'] = true; |
|
| 972 | - else |
|
| 973 | - $_SESSION['topicseen_cache'][$board] = $numNewTopics; |
|
| 998 | + if (empty($numNewTopics)) { |
|
| 999 | + $_REQUEST['boardseen'] = true; |
|
| 1000 | + } else { |
|
| 1001 | + $_SESSION['topicseen_cache'][$board] = $numNewTopics; |
|
| 1002 | + } |
|
| 974 | 1003 | } |
| 975 | 1004 | // Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often. |
| 976 | - elseif (isset($_SESSION['topicseen_cache'][$board])) |
|
| 977 | - $_SESSION['topicseen_cache'][$board]--; |
|
| 1005 | + elseif (isset($_SESSION['topicseen_cache'][$board])) { |
|
| 1006 | + $_SESSION['topicseen_cache'][$board]--; |
|
| 1007 | + } |
|
| 978 | 1008 | |
| 979 | 1009 | // Mark board as seen if we came using last post link from BoardIndex. (or other places...) |
| 980 | 1010 | if (isset($_REQUEST['boardseen'])) |
@@ -1031,23 +1061,26 @@ discard block |
||
| 1031 | 1061 | $temp = array(); |
| 1032 | 1062 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1033 | 1063 | { |
| 1034 | - if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) |
|
| 1035 | - continue; |
|
| 1064 | + if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) { |
|
| 1065 | + continue; |
|
| 1066 | + } |
|
| 1036 | 1067 | |
| 1037 | 1068 | $temp[$row['id_attach']] = $row; |
| 1038 | 1069 | $temp[$row['id_attach']]['topic'] = $topic; |
| 1039 | 1070 | $temp[$row['id_attach']]['board'] = $board; |
| 1040 | 1071 | |
| 1041 | - if (!isset($context['loaded_attachments'][$row['id_msg']])) |
|
| 1042 | - $context['loaded_attachments'][$row['id_msg']] = array(); |
|
| 1072 | + if (!isset($context['loaded_attachments'][$row['id_msg']])) { |
|
| 1073 | + $context['loaded_attachments'][$row['id_msg']] = array(); |
|
| 1074 | + } |
|
| 1043 | 1075 | } |
| 1044 | 1076 | $smcFunc['db_free_result']($request); |
| 1045 | 1077 | |
| 1046 | 1078 | // This is better than sorting it with the query... |
| 1047 | 1079 | ksort($temp); |
| 1048 | 1080 | |
| 1049 | - foreach ($temp as $row) |
|
| 1050 | - $context['loaded_attachments'][$row['id_msg']][] = $row; |
|
| 1081 | + foreach ($temp as $row) { |
|
| 1082 | + $context['loaded_attachments'][$row['id_msg']][] = $row; |
|
| 1083 | + } |
|
| 1051 | 1084 | } |
| 1052 | 1085 | |
| 1053 | 1086 | $msg_parameters = array( |
@@ -1074,21 +1107,23 @@ discard block |
||
| 1074 | 1107 | ); |
| 1075 | 1108 | |
| 1076 | 1109 | // And the likes |
| 1077 | - if (!empty($modSettings['enable_likes'])) |
|
| 1078 | - $context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic); |
|
| 1110 | + if (!empty($modSettings['enable_likes'])) { |
|
| 1111 | + $context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic); |
|
| 1112 | + } |
|
| 1079 | 1113 | |
| 1080 | 1114 | // Go to the last message if the given time is beyond the time of the last message. |
| 1081 | - if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) |
|
| 1082 | - $context['start_from'] = $context['topicinfo']['num_replies']; |
|
| 1115 | + if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) { |
|
| 1116 | + $context['start_from'] = $context['topicinfo']['num_replies']; |
|
| 1117 | + } |
|
| 1083 | 1118 | |
| 1084 | 1119 | // Since the anchor information is needed on the top of the page we load these variables beforehand. |
| 1085 | 1120 | $context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0]; |
| 1086 | - if (empty($options['view_newest_first'])) |
|
| 1087 | - $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from']; |
|
| 1088 | - else |
|
| 1089 | - $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from']; |
|
| 1090 | - } |
|
| 1091 | - else |
|
| 1121 | + if (empty($options['view_newest_first'])) { |
|
| 1122 | + $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from']; |
|
| 1123 | + } else { |
|
| 1124 | + $context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from']; |
|
| 1125 | + } |
|
| 1126 | + } else |
|
| 1092 | 1127 | { |
| 1093 | 1128 | $messages_request = false; |
| 1094 | 1129 | $context['first_message'] = 0; |
@@ -1124,8 +1159,9 @@ discard block |
||
| 1124 | 1159 | 'can_see_likes' => 'likes_view', |
| 1125 | 1160 | 'can_like' => 'likes_like', |
| 1126 | 1161 | ); |
| 1127 | - foreach ($common_permissions as $contextual => $perm) |
|
| 1128 | - $context[$contextual] = allowedTo($perm); |
|
| 1162 | + foreach ($common_permissions as $contextual => $perm) { |
|
| 1163 | + $context[$contextual] = allowedTo($perm); |
|
| 1164 | + } |
|
| 1129 | 1165 | |
| 1130 | 1166 | // Permissions with _any/_own versions. $context[YYY] => ZZZ_any/_own. |
| 1131 | 1167 | $anyown_permissions = array( |
@@ -1138,8 +1174,9 @@ discard block |
||
| 1138 | 1174 | 'can_reply_unapproved' => 'post_unapproved_replies', |
| 1139 | 1175 | 'can_view_warning' => 'profile_warning', |
| 1140 | 1176 | ); |
| 1141 | - foreach ($anyown_permissions as $contextual => $perm) |
|
| 1142 | - $context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own')); |
|
| 1177 | + foreach ($anyown_permissions as $contextual => $perm) { |
|
| 1178 | + $context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own')); |
|
| 1179 | + } |
|
| 1143 | 1180 | |
| 1144 | 1181 | if (!$user_info['is_admin'] && !$modSettings['topic_move_any']) |
| 1145 | 1182 | { |
@@ -1185,8 +1222,9 @@ discard block |
||
| 1185 | 1222 | // Check if the draft functions are enabled and that they have permission to use them (for quick reply.) |
| 1186 | 1223 | $context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply']; |
| 1187 | 1224 | $context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']); |
| 1188 | - if (!empty($context['drafts_save'])) |
|
| 1189 | - loadLanguage('Drafts'); |
|
| 1225 | + if (!empty($context['drafts_save'])) { |
|
| 1226 | + loadLanguage('Drafts'); |
|
| 1227 | + } |
|
| 1190 | 1228 | |
| 1191 | 1229 | // When was the last time this topic was replied to? Should we warn them about it? |
| 1192 | 1230 | if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky'])) |
@@ -1247,26 +1285,31 @@ discard block |
||
| 1247 | 1285 | // Message icons - customized icons are off? |
| 1248 | 1286 | $context['icons'] = getMessageIcons($board); |
| 1249 | 1287 | |
| 1250 | - if (!empty($context['icons'])) |
|
| 1251 | - $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
| 1288 | + if (!empty($context['icons'])) { |
|
| 1289 | + $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
| 1290 | + } |
|
| 1252 | 1291 | |
| 1253 | 1292 | // Build the normal button array. |
| 1254 | 1293 | $context['normal_buttons'] = array(); |
| 1255 | 1294 | |
| 1256 | - if ($context['can_reply']) |
|
| 1257 | - $context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true); |
|
| 1295 | + if ($context['can_reply']) { |
|
| 1296 | + $context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true); |
|
| 1297 | + } |
|
| 1258 | 1298 | |
| 1259 | - if ($context['can_add_poll']) |
|
| 1260 | - $context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
| 1299 | + if ($context['can_add_poll']) { |
|
| 1300 | + $context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']); |
|
| 1301 | + } |
|
| 1261 | 1302 | |
| 1262 | - if ($context['can_mark_unread']) |
|
| 1263 | - $context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 1303 | + if ($context['can_mark_unread']) { |
|
| 1304 | + $context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 1305 | + } |
|
| 1264 | 1306 | |
| 1265 | - if ($context['can_print']) |
|
| 1266 | - $context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'); |
|
| 1307 | + if ($context['can_print']) { |
|
| 1308 | + $context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0'); |
|
| 1309 | + } |
|
| 1267 | 1310 | |
| 1268 | - if ($context['can_set_notify']) |
|
| 1269 | - $context['normal_buttons']['notify'] = array( |
|
| 1311 | + if ($context['can_set_notify']) { |
|
| 1312 | + $context['normal_buttons']['notify'] = array( |
|
| 1270 | 1313 | 'text' => 'notify_topic_' . $context['topic_notification_mode'], |
| 1271 | 1314 | 'sub_buttons' => array( |
| 1272 | 1315 | array( |
@@ -1288,38 +1331,47 @@ discard block |
||
| 1288 | 1331 | ), |
| 1289 | 1332 | ), |
| 1290 | 1333 | ); |
| 1334 | + } |
|
| 1291 | 1335 | |
| 1292 | 1336 | // Build the mod button array |
| 1293 | 1337 | $context['mod_buttons'] = array(); |
| 1294 | 1338 | |
| 1295 | - if ($context['can_move']) |
|
| 1296 | - $context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0'); |
|
| 1339 | + if ($context['can_move']) { |
|
| 1340 | + $context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0'); |
|
| 1341 | + } |
|
| 1297 | 1342 | |
| 1298 | - if ($context['can_delete']) |
|
| 1299 | - $context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']); |
|
| 1343 | + if ($context['can_delete']) { |
|
| 1344 | + $context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']); |
|
| 1345 | + } |
|
| 1300 | 1346 | |
| 1301 | - if ($context['can_lock']) |
|
| 1302 | - $context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 1347 | + if ($context['can_lock']) { |
|
| 1348 | + $context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 1349 | + } |
|
| 1303 | 1350 | |
| 1304 | - if ($context['can_sticky']) |
|
| 1305 | - $context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 1351 | + if ($context['can_sticky']) { |
|
| 1352 | + $context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 1353 | + } |
|
| 1306 | 1354 | |
| 1307 | - if ($context['can_merge']) |
|
| 1308 | - $context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']); |
|
| 1355 | + if ($context['can_merge']) { |
|
| 1356 | + $context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']); |
|
| 1357 | + } |
|
| 1309 | 1358 | |
| 1310 | - if ($context['calendar_post']) |
|
| 1311 | - $context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0'); |
|
| 1359 | + if ($context['calendar_post']) { |
|
| 1360 | + $context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0'); |
|
| 1361 | + } |
|
| 1312 | 1362 | |
| 1313 | 1363 | // Restore topic. eh? No monkey business. |
| 1314 | - if ($context['can_restore_topic']) |
|
| 1315 | - $context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 1364 | + if ($context['can_restore_topic']) { |
|
| 1365 | + $context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 1366 | + } |
|
| 1316 | 1367 | |
| 1317 | 1368 | // Show a message in case a recently posted message became unapproved. |
| 1318 | 1369 | $context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false; |
| 1319 | 1370 | |
| 1320 | 1371 | // Don't want to show this forever... |
| 1321 | - if ($context['becomesUnapproved']) |
|
| 1322 | - unset($_SESSION['becomesUnapproved']); |
|
| 1372 | + if ($context['becomesUnapproved']) { |
|
| 1373 | + unset($_SESSION['becomesUnapproved']); |
|
| 1374 | + } |
|
| 1323 | 1375 | |
| 1324 | 1376 | // Allow adding new mod buttons easily. |
| 1325 | 1377 | // Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used |
@@ -1328,12 +1380,14 @@ discard block |
||
| 1328 | 1380 | call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons'])); |
| 1329 | 1381 | |
| 1330 | 1382 | // Load the drafts js file |
| 1331 | - if ($context['drafts_autosave']) |
|
| 1332 | - loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts'); |
|
| 1383 | + if ($context['drafts_autosave']) { |
|
| 1384 | + loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts'); |
|
| 1385 | + } |
|
| 1333 | 1386 | |
| 1334 | 1387 | // Spellcheck |
| 1335 | - if ($context['show_spellchecking']) |
|
| 1336 | - loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); |
|
| 1388 | + if ($context['show_spellchecking']) { |
|
| 1389 | + loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); |
|
| 1390 | + } |
|
| 1337 | 1391 | |
| 1338 | 1392 | // topic.js |
| 1339 | 1393 | loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic'); |
@@ -1367,16 +1421,19 @@ discard block |
||
| 1367 | 1421 | static $counter = null; |
| 1368 | 1422 | |
| 1369 | 1423 | // If the query returned false, bail. |
| 1370 | - if ($messages_request == false) |
|
| 1371 | - return false; |
|
| 1424 | + if ($messages_request == false) { |
|
| 1425 | + return false; |
|
| 1426 | + } |
|
| 1372 | 1427 | |
| 1373 | 1428 | // Remember which message this is. (ie. reply #83) |
| 1374 | - if ($counter === null || $reset) |
|
| 1375 | - $counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start']; |
|
| 1429 | + if ($counter === null || $reset) { |
|
| 1430 | + $counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start']; |
|
| 1431 | + } |
|
| 1376 | 1432 | |
| 1377 | 1433 | // Start from the beginning... |
| 1378 | - if ($reset) |
|
| 1379 | - return @$smcFunc['db_data_seek']($messages_request, 0); |
|
| 1434 | + if ($reset) { |
|
| 1435 | + return @$smcFunc['db_data_seek']($messages_request, 0); |
|
| 1436 | + } |
|
| 1380 | 1437 | |
| 1381 | 1438 | // Attempt to get the next message. |
| 1382 | 1439 | $message = $smcFunc['db_fetch_assoc']($messages_request); |
@@ -1390,19 +1447,21 @@ discard block |
||
| 1390 | 1447 | if (empty($context['icon_sources'])) |
| 1391 | 1448 | { |
| 1392 | 1449 | $context['icon_sources'] = array(); |
| 1393 | - foreach ($context['stable_icons'] as $icon) |
|
| 1394 | - $context['icon_sources'][$icon] = 'images_url'; |
|
| 1450 | + foreach ($context['stable_icons'] as $icon) { |
|
| 1451 | + $context['icon_sources'][$icon] = 'images_url'; |
|
| 1452 | + } |
|
| 1395 | 1453 | } |
| 1396 | 1454 | |
| 1397 | 1455 | // Message Icon Management... check the images exist. |
| 1398 | 1456 | if (empty($modSettings['messageIconChecks_disable'])) |
| 1399 | 1457 | { |
| 1400 | 1458 | // If the current icon isn't known, then we need to do something... |
| 1401 | - if (!isset($context['icon_sources'][$message['icon']])) |
|
| 1402 | - $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1459 | + if (!isset($context['icon_sources'][$message['icon']])) { |
|
| 1460 | + $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
| 1461 | + } |
|
| 1462 | + } elseif (!isset($context['icon_sources'][$message['icon']])) { |
|
| 1463 | + $context['icon_sources'][$message['icon']] = 'images_url'; |
|
| 1403 | 1464 | } |
| 1404 | - elseif (!isset($context['icon_sources'][$message['icon']])) |
|
| 1405 | - $context['icon_sources'][$message['icon']] = 'images_url'; |
|
| 1406 | 1465 | |
| 1407 | 1466 | // If you're a lazy bum, you probably didn't give a subject... |
| 1408 | 1467 | $message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject']; |
@@ -1427,8 +1486,7 @@ discard block |
||
| 1427 | 1486 | $memberContext[$message['id_member']]['email'] = $message['poster_email']; |
| 1428 | 1487 | $memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum'); |
| 1429 | 1488 | $memberContext[$message['id_member']]['is_guest'] = true; |
| 1430 | - } |
|
| 1431 | - else |
|
| 1489 | + } else |
|
| 1432 | 1490 | { |
| 1433 | 1491 | // Define this here to make things a bit more readable |
| 1434 | 1492 | $can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own')); |
@@ -1451,8 +1509,9 @@ discard block |
||
| 1451 | 1509 | $message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']); |
| 1452 | 1510 | |
| 1453 | 1511 | // If it's in the recycle bin we need to override whatever icon we did have. |
| 1454 | - if (!empty($board_info['recycle'])) |
|
| 1455 | - $message['icon'] = 'recycled'; |
|
| 1512 | + if (!empty($board_info['recycle'])) { |
|
| 1513 | + $message['icon'] = 'recycled'; |
|
| 1514 | + } |
|
| 1456 | 1515 | |
| 1457 | 1516 | require_once($sourcedir . '/Subs-Attachments.php'); |
| 1458 | 1517 | |
@@ -1496,32 +1555,36 @@ discard block |
||
| 1496 | 1555 | } |
| 1497 | 1556 | |
| 1498 | 1557 | // Are likes enable? |
| 1499 | - if (!empty($modSettings['enable_likes'])) |
|
| 1500 | - $output['likes'] = array( |
|
| 1558 | + if (!empty($modSettings['enable_likes'])) { |
|
| 1559 | + $output['likes'] = array( |
|
| 1501 | 1560 | 'count' => $message['likes'], |
| 1502 | 1561 | 'you' => in_array($message['id_msg'], $context['my_likes']), |
| 1503 | 1562 | 'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']), |
| 1504 | 1563 | ); |
| 1564 | + } |
|
| 1505 | 1565 | |
| 1506 | 1566 | // Is this user the message author? |
| 1507 | 1567 | $output['is_message_author'] = $message['id_member'] == $user_info['id']; |
| 1508 | - if (!empty($output['modified']['name'])) |
|
| 1509 | - $output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']); |
|
| 1568 | + if (!empty($output['modified']['name'])) { |
|
| 1569 | + $output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']); |
|
| 1570 | + } |
|
| 1510 | 1571 | |
| 1511 | 1572 | // Did they give a reason for editing? |
| 1512 | - if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) |
|
| 1513 | - $output['modified']['last_edit_text'] .= ' ' . sprintf($txt['last_edit_reason'], $output['modified']['reason']); |
|
| 1573 | + if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) { |
|
| 1574 | + $output['modified']['last_edit_text'] .= ' ' . sprintf($txt['last_edit_reason'], $output['modified']['reason']); |
|
| 1575 | + } |
|
| 1514 | 1576 | |
| 1515 | 1577 | // Any custom profile fields? |
| 1516 | - if (!empty($memberContext[$message['id_member']]['custom_fields'])) |
|
| 1517 | - foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom) |
|
| 1578 | + if (!empty($memberContext[$message['id_member']]['custom_fields'])) { |
|
| 1579 | + foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom) |
|
| 1518 | 1580 | $output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom; |
| 1581 | + } |
|
| 1519 | 1582 | |
| 1520 | - if (empty($options['view_newest_first'])) |
|
| 1521 | - $counter++; |
|
| 1522 | - |
|
| 1523 | - else |
|
| 1524 | - $counter--; |
|
| 1583 | + if (empty($options['view_newest_first'])) { |
|
| 1584 | + $counter++; |
|
| 1585 | + } else { |
|
| 1586 | + $counter--; |
|
| 1587 | + } |
|
| 1525 | 1588 | |
| 1526 | 1589 | call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter)); |
| 1527 | 1590 | |
@@ -1547,21 +1610,23 @@ discard block |
||
| 1547 | 1610 | $context['no_last_modified'] = true; |
| 1548 | 1611 | |
| 1549 | 1612 | // Prevent a preview image from being displayed twice. |
| 1550 | - if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview')) |
|
| 1551 | - return; |
|
| 1613 | + if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview')) { |
|
| 1614 | + return; |
|
| 1615 | + } |
|
| 1552 | 1616 | |
| 1553 | 1617 | // Make sure some attachment was requested! |
| 1554 | - if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id'])) |
|
| 1555 | - fatal_lang_error('no_access', false); |
|
| 1618 | + if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id'])) { |
|
| 1619 | + fatal_lang_error('no_access', false); |
|
| 1620 | + } |
|
| 1556 | 1621 | |
| 1557 | 1622 | $_REQUEST['attach'] = isset($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : (int) $_REQUEST['id']; |
| 1558 | 1623 | |
| 1559 | 1624 | // Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request. |
| 1560 | 1625 | $attachRequest = null; |
| 1561 | 1626 | call_integration_hook('integrate_download_request', array(&$attachRequest)); |
| 1562 | - if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) |
|
| 1563 | - $request = $attachRequest; |
|
| 1564 | - else |
|
| 1627 | + if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) { |
|
| 1628 | + $request = $attachRequest; |
|
| 1629 | + } else |
|
| 1565 | 1630 | { |
| 1566 | 1631 | // This checks only the current board for $board/$topic's permissions. |
| 1567 | 1632 | isAllowedTo('view_attachments'); |
@@ -1582,19 +1647,21 @@ discard block |
||
| 1582 | 1647 | ); |
| 1583 | 1648 | } |
| 1584 | 1649 | |
| 1585 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1586 | - fatal_lang_error('no_access', false); |
|
| 1650 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1651 | + fatal_lang_error('no_access', false); |
|
| 1652 | + } |
|
| 1587 | 1653 | |
| 1588 | 1654 | list ($id_folder, $real_filename, $file_hash, $file_ext, $id_attach, $attachment_type, $mime_type, $is_approved, $id_member) = $smcFunc['db_fetch_row']($request); |
| 1589 | 1655 | $smcFunc['db_free_result']($request); |
| 1590 | 1656 | |
| 1591 | 1657 | // If it isn't yet approved, do they have permission to view it? |
| 1592 | - if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3)) |
|
| 1593 | - isAllowedTo('approve_posts'); |
|
| 1658 | + if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3)) { |
|
| 1659 | + isAllowedTo('approve_posts'); |
|
| 1660 | + } |
|
| 1594 | 1661 | |
| 1595 | 1662 | // Update the download counter (unless it's a thumbnail). |
| 1596 | - if ($attachment_type != 3) |
|
| 1597 | - $smcFunc['db_query']('attach_download_increase', ' |
|
| 1663 | + if ($attachment_type != 3) { |
|
| 1664 | + $smcFunc['db_query']('attach_download_increase', ' |
|
| 1598 | 1665 | UPDATE LOW_PRIORITY {db_prefix}attachments |
| 1599 | 1666 | SET downloads = downloads + 1 |
| 1600 | 1667 | WHERE id_attach = {int:id_attach}', |
@@ -1602,15 +1669,15 @@ discard block |
||
| 1602 | 1669 | 'id_attach' => $id_attach, |
| 1603 | 1670 | ) |
| 1604 | 1671 | ); |
| 1672 | + } |
|
| 1605 | 1673 | |
| 1606 | 1674 | $filename = getAttachmentFilename($real_filename, $_REQUEST['attach'], $id_folder, false, $file_hash); |
| 1607 | 1675 | |
| 1608 | 1676 | // This is done to clear any output that was made before now. |
| 1609 | 1677 | ob_end_clean(); |
| 1610 | - if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java'))) |
|
| 1611 | - @ob_start('ob_gzhandler'); |
|
| 1612 | - |
|
| 1613 | - else |
|
| 1678 | + if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java'))) { |
|
| 1679 | + @ob_start('ob_gzhandler'); |
|
| 1680 | + } else |
|
| 1614 | 1681 | { |
| 1615 | 1682 | ob_start(); |
| 1616 | 1683 | header('Content-Encoding: none'); |
@@ -1653,8 +1720,9 @@ discard block |
||
| 1653 | 1720 | // Send the attachment headers. |
| 1654 | 1721 | header('Pragma: '); |
| 1655 | 1722 | |
| 1656 | - if (!isBrowser('gecko')) |
|
| 1657 | - header('Content-Transfer-Encoding: binary'); |
|
| 1723 | + if (!isBrowser('gecko')) { |
|
| 1724 | + header('Content-Transfer-Encoding: binary'); |
|
| 1725 | + } |
|
| 1658 | 1726 | |
| 1659 | 1727 | header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT'); |
| 1660 | 1728 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filename)) . ' GMT'); |
@@ -1663,18 +1731,19 @@ discard block |
||
| 1663 | 1731 | header('ETag: ' . $eTag); |
| 1664 | 1732 | |
| 1665 | 1733 | // Make sure the mime type warrants an inline display. |
| 1666 | - if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0) |
|
| 1667 | - unset($_REQUEST['image']); |
|
| 1734 | + if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0) { |
|
| 1735 | + unset($_REQUEST['image']); |
|
| 1736 | + } |
|
| 1668 | 1737 | |
| 1669 | 1738 | // Does this have a mime type? |
| 1670 | - elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) |
|
| 1671 | - header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp'))); |
|
| 1672 | - |
|
| 1673 | - else |
|
| 1739 | + elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) { |
|
| 1740 | + header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp'))); |
|
| 1741 | + } else |
|
| 1674 | 1742 | { |
| 1675 | 1743 | header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream')); |
| 1676 | - if (isset($_REQUEST['image'])) |
|
| 1677 | - unset($_REQUEST['image']); |
|
| 1744 | + if (isset($_REQUEST['image'])) { |
|
| 1745 | + unset($_REQUEST['image']); |
|
| 1746 | + } |
|
| 1678 | 1747 | } |
| 1679 | 1748 | |
| 1680 | 1749 | // Convert the file to UTF-8, cuz most browsers dig that. |
@@ -1682,23 +1751,22 @@ discard block |
||
| 1682 | 1751 | $disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline'; |
| 1683 | 1752 | |
| 1684 | 1753 | // Different browsers like different standards... |
| 1685 | - if (isBrowser('firefox')) |
|
| 1686 | - header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
| 1687 | - |
|
| 1688 | - elseif (isBrowser('opera')) |
|
| 1689 | - header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
| 1690 | - |
|
| 1691 | - elseif (isBrowser('ie')) |
|
| 1692 | - header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
| 1693 | - |
|
| 1694 | - else |
|
| 1695 | - header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
| 1754 | + if (isBrowser('firefox')) { |
|
| 1755 | + header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
| 1756 | + } elseif (isBrowser('opera')) { |
|
| 1757 | + header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
| 1758 | + } elseif (isBrowser('ie')) { |
|
| 1759 | + header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
| 1760 | + } else { |
|
| 1761 | + header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
| 1762 | + } |
|
| 1696 | 1763 | |
| 1697 | 1764 | // If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE. |
| 1698 | - if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) |
|
| 1699 | - header('Cache-Control: no-cache'); |
|
| 1700 | - else |
|
| 1701 | - header('Cache-Control: max-age=' . (525600 * 60) . ', private'); |
|
| 1765 | + if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) { |
|
| 1766 | + header('Cache-Control: no-cache'); |
|
| 1767 | + } else { |
|
| 1768 | + header('Cache-Control: max-age=' . (525600 * 60) . ', private'); |
|
| 1769 | + } |
|
| 1702 | 1770 | |
| 1703 | 1771 | header('Content-Length: ' . filesize($filename)); |
| 1704 | 1772 | |
@@ -1708,20 +1776,23 @@ discard block |
||
| 1708 | 1776 | // Recode line endings for text files, if enabled. |
| 1709 | 1777 | if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file_ext, array('txt', 'css', 'htm', 'html', 'php', 'xml'))) |
| 1710 | 1778 | { |
| 1711 | - if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) |
|
| 1712 | - $callback = function($buffer) |
|
| 1779 | + if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) { |
|
| 1780 | + $callback = function($buffer) |
|
| 1713 | 1781 | { |
| 1714 | 1782 | return preg_replace('~[\r]?\n~', "\r\n", $buffer); |
| 1783 | + } |
|
| 1715 | 1784 | }; |
| 1716 | - elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) |
|
| 1717 | - $callback = function($buffer) |
|
| 1785 | + elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) { |
|
| 1786 | + $callback = function($buffer) |
|
| 1718 | 1787 | { |
| 1719 | 1788 | return preg_replace('~[\r]?\n~', "\r", $buffer); |
| 1789 | + } |
|
| 1720 | 1790 | }; |
| 1721 | - else |
|
| 1722 | - $callback = function($buffer) |
|
| 1791 | + else { |
|
| 1792 | + $callback = function($buffer) |
|
| 1723 | 1793 | { |
| 1724 | 1794 | return preg_replace('~[\r]?\n~', "\n", $buffer); |
| 1795 | + } |
|
| 1725 | 1796 | }; |
| 1726 | 1797 | } |
| 1727 | 1798 | |
@@ -1729,23 +1800,26 @@ discard block |
||
| 1729 | 1800 | if (filesize($filename) > 4194304) |
| 1730 | 1801 | { |
| 1731 | 1802 | // Forcibly end any output buffering going on. |
| 1732 | - while (@ob_get_level() > 0) |
|
| 1733 | - @ob_end_clean(); |
|
| 1803 | + while (@ob_get_level() > 0) { |
|
| 1804 | + @ob_end_clean(); |
|
| 1805 | + } |
|
| 1734 | 1806 | |
| 1735 | 1807 | $fp = fopen($filename, 'rb'); |
| 1736 | 1808 | while (!feof($fp)) |
| 1737 | 1809 | { |
| 1738 | - if (isset($callback)) |
|
| 1739 | - echo $callback(fread($fp, 8192)); |
|
| 1740 | - else |
|
| 1741 | - echo fread($fp, 8192); |
|
| 1810 | + if (isset($callback)) { |
|
| 1811 | + echo $callback(fread($fp, 8192)); |
|
| 1812 | + } else { |
|
| 1813 | + echo fread($fp, 8192); |
|
| 1814 | + } |
|
| 1742 | 1815 | flush(); |
| 1743 | 1816 | } |
| 1744 | 1817 | fclose($fp); |
| 1745 | 1818 | } |
| 1746 | 1819 | // On some of the less-bright hosts, readfile() is disabled. It's just a faster, more byte safe, version of what's in the if. |
| 1747 | - elseif (isset($callback) || @readfile($filename) === null) |
|
| 1748 | - echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename); |
|
| 1820 | + elseif (isset($callback) || @readfile($filename) === null) { |
|
| 1821 | + echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename); |
|
| 1822 | + } |
|
| 1749 | 1823 | |
| 1750 | 1824 | obExit(false); |
| 1751 | 1825 | } |
@@ -1758,8 +1832,9 @@ discard block |
||
| 1758 | 1832 | */ |
| 1759 | 1833 | function approved_attach_sort($a, $b) |
| 1760 | 1834 | { |
| 1761 | - if ($a['is_approved'] == $b['is_approved']) |
|
| 1762 | - return 0; |
|
| 1835 | + if ($a['is_approved'] == $b['is_approved']) { |
|
| 1836 | + return 0; |
|
| 1837 | + } |
|
| 1763 | 1838 | |
| 1764 | 1839 | return $a['is_approved'] > $b['is_approved'] ? -1 : 1; |
| 1765 | 1840 | } |
@@ -1776,16 +1851,19 @@ discard block |
||
| 1776 | 1851 | |
| 1777 | 1852 | require_once($sourcedir . '/RemoveTopic.php'); |
| 1778 | 1853 | |
| 1779 | - if (empty($_REQUEST['msgs'])) |
|
| 1780 | - redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
| 1854 | + if (empty($_REQUEST['msgs'])) { |
|
| 1855 | + redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
| 1856 | + } |
|
| 1781 | 1857 | |
| 1782 | 1858 | $messages = array(); |
| 1783 | - foreach ($_REQUEST['msgs'] as $dummy) |
|
| 1784 | - $messages[] = (int) $dummy; |
|
| 1859 | + foreach ($_REQUEST['msgs'] as $dummy) { |
|
| 1860 | + $messages[] = (int) $dummy; |
|
| 1861 | + } |
|
| 1785 | 1862 | |
| 1786 | 1863 | // We are restoring messages. We handle this in another place. |
| 1787 | - if (isset($_REQUEST['restore_selected'])) |
|
| 1788 | - redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 1864 | + if (isset($_REQUEST['restore_selected'])) { |
|
| 1865 | + redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
| 1866 | + } |
|
| 1789 | 1867 | if (isset($_REQUEST['split_selection'])) |
| 1790 | 1868 | { |
| 1791 | 1869 | $request = $smcFunc['db_query']('', ' |
@@ -1804,8 +1882,9 @@ discard block |
||
| 1804 | 1882 | } |
| 1805 | 1883 | |
| 1806 | 1884 | // Allowed to delete any message? |
| 1807 | - if (allowedTo('delete_any')) |
|
| 1808 | - $allowed_all = true; |
|
| 1885 | + if (allowedTo('delete_any')) { |
|
| 1886 | + $allowed_all = true; |
|
| 1887 | + } |
|
| 1809 | 1888 | // Allowed to delete replies to their messages? |
| 1810 | 1889 | elseif (allowedTo('delete_replies')) |
| 1811 | 1890 | { |
@@ -1822,13 +1901,14 @@ discard block |
||
| 1822 | 1901 | $smcFunc['db_free_result']($request); |
| 1823 | 1902 | |
| 1824 | 1903 | $allowed_all = $starter == $user_info['id']; |
| 1904 | + } else { |
|
| 1905 | + $allowed_all = false; |
|
| 1825 | 1906 | } |
| 1826 | - else |
|
| 1827 | - $allowed_all = false; |
|
| 1828 | 1907 | |
| 1829 | 1908 | // Make sure they're allowed to delete their own messages, if not any. |
| 1830 | - if (!$allowed_all) |
|
| 1831 | - isAllowedTo('delete_own'); |
|
| 1909 | + if (!$allowed_all) { |
|
| 1910 | + isAllowedTo('delete_own'); |
|
| 1911 | + } |
|
| 1832 | 1912 | |
| 1833 | 1913 | // Allowed to remove which messages? |
| 1834 | 1914 | $request = $smcFunc['db_query']('', ' |
@@ -1848,8 +1928,9 @@ discard block |
||
| 1848 | 1928 | $messages = array(); |
| 1849 | 1929 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1850 | 1930 | { |
| 1851 | - if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) |
|
| 1852 | - continue; |
|
| 1931 | + if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) { |
|
| 1932 | + continue; |
|
| 1933 | + } |
|
| 1853 | 1934 | |
| 1854 | 1935 | $messages[$row['id_msg']] = array($row['subject'], $row['id_member']); |
| 1855 | 1936 | } |
@@ -1872,17 +1953,20 @@ discard block |
||
| 1872 | 1953 | foreach ($messages as $message => $info) |
| 1873 | 1954 | { |
| 1874 | 1955 | // Just skip the first message - if it's not the last. |
| 1875 | - if ($message == $first_message && $message != $last_message) |
|
| 1876 | - continue; |
|
| 1956 | + if ($message == $first_message && $message != $last_message) { |
|
| 1957 | + continue; |
|
| 1958 | + } |
|
| 1877 | 1959 | // If the first message is going then don't bother going back to the topic as we're effectively deleting it. |
| 1878 | - elseif ($message == $first_message) |
|
| 1879 | - $topicGone = true; |
|
| 1960 | + elseif ($message == $first_message) { |
|
| 1961 | + $topicGone = true; |
|
| 1962 | + } |
|
| 1880 | 1963 | |
| 1881 | 1964 | removeMessage($message); |
| 1882 | 1965 | |
| 1883 | 1966 | // Log this moderation action ;). |
| 1884 | - if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) |
|
| 1885 | - logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board)); |
|
| 1967 | + if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) { |
|
| 1968 | + logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board)); |
|
| 1969 | + } |
|
| 1886 | 1970 | } |
| 1887 | 1971 | |
| 1888 | 1972 | redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']); |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 3 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('Hacking attempt...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Our Cache API class |
@@ -27,8 +28,9 @@ discard block |
||
| 27 | 28 | { |
| 28 | 29 | $supported = function_exists('zend_shm_cache_fetch') || function_exists('output_cache_get'); |
| 29 | 30 | |
| 30 | - if ($test) |
|
| 31 | - return $supported; |
|
| 31 | + if ($test) { |
|
| 32 | + return $supported; |
|
| 33 | + } |
|
| 32 | 34 | return parent::isSupported() && $supported; |
| 33 | 35 | } |
| 34 | 36 | |
@@ -40,10 +42,11 @@ discard block |
||
| 40 | 42 | $key = $this->prefix . strtr($key, ':/', '-_'); |
| 41 | 43 | |
| 42 | 44 | // Zend's pricey stuff. |
| 43 | - if (function_exists('zend_shm_cache_fetch')) |
|
| 44 | - return zend_shm_cache_fetch('SMF::' . $key); |
|
| 45 | - elseif (function_exists('output_cache_get')) |
|
| 46 | - return output_cache_get($key, $ttl); |
|
| 45 | + if (function_exists('zend_shm_cache_fetch')) { |
|
| 46 | + return zend_shm_cache_fetch('SMF::' . $key); |
|
| 47 | + } elseif (function_exists('output_cache_get')) { |
|
| 48 | + return output_cache_get($key, $ttl); |
|
| 49 | + } |
|
| 47 | 50 | } |
| 48 | 51 | |
| 49 | 52 | /** |
@@ -53,10 +56,11 @@ discard block |
||
| 53 | 56 | { |
| 54 | 57 | $key = $this->prefix . strtr($key, ':/', '-_'); |
| 55 | 58 | |
| 56 | - if (function_exists('zend_shm_cache_store')) |
|
| 57 | - return zend_shm_cache_store('SMF::' . $key, $value, $ttl); |
|
| 58 | - elseif (function_exists('output_cache_put')) |
|
| 59 | - return output_cache_put($key, $value); |
|
| 59 | + if (function_exists('zend_shm_cache_store')) { |
|
| 60 | + return zend_shm_cache_store('SMF::' . $key, $value, $ttl); |
|
| 61 | + } elseif (function_exists('output_cache_put')) { |
|
| 62 | + return output_cache_put($key, $value); |
|
| 63 | + } |
|
| 60 | 64 | } |
| 61 | 65 | |
| 62 | 66 | /** |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * This function works out what to do! |
@@ -24,9 +25,9 @@ discard block |
||
| 24 | 25 | global $time_start, $smcFunc; |
| 25 | 26 | |
| 26 | 27 | // Special case for doing the mail queue. |
| 27 | - if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') |
|
| 28 | - ReduceMailQueue(); |
|
| 29 | - else |
|
| 28 | + if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') { |
|
| 29 | + ReduceMailQueue(); |
|
| 30 | + } else |
|
| 30 | 31 | { |
| 31 | 32 | $task_string = ''; |
| 32 | 33 | |
@@ -53,18 +54,20 @@ discard block |
||
| 53 | 54 | |
| 54 | 55 | // How long in seconds it the gap? |
| 55 | 56 | $duration = $row['time_regularity']; |
| 56 | - if ($row['time_unit'] == 'm') |
|
| 57 | - $duration *= 60; |
|
| 58 | - elseif ($row['time_unit'] == 'h') |
|
| 59 | - $duration *= 3600; |
|
| 60 | - elseif ($row['time_unit'] == 'd') |
|
| 61 | - $duration *= 86400; |
|
| 62 | - elseif ($row['time_unit'] == 'w') |
|
| 63 | - $duration *= 604800; |
|
| 57 | + if ($row['time_unit'] == 'm') { |
|
| 58 | + $duration *= 60; |
|
| 59 | + } elseif ($row['time_unit'] == 'h') { |
|
| 60 | + $duration *= 3600; |
|
| 61 | + } elseif ($row['time_unit'] == 'd') { |
|
| 62 | + $duration *= 86400; |
|
| 63 | + } elseif ($row['time_unit'] == 'w') { |
|
| 64 | + $duration *= 604800; |
|
| 65 | + } |
|
| 64 | 66 | |
| 65 | 67 | // If we were really late running this task actually skip the next one. |
| 66 | - if (time() + ($duration / 2) > $next_time) |
|
| 67 | - $next_time += $duration; |
|
| 68 | + if (time() + ($duration / 2) > $next_time) { |
|
| 69 | + $next_time += $duration; |
|
| 70 | + } |
|
| 68 | 71 | |
| 69 | 72 | // Update it now, so no others run this! |
| 70 | 73 | $smcFunc['db_query']('', ' |
@@ -81,16 +84,19 @@ discard block |
||
| 81 | 84 | $affected_rows = $smcFunc['db_affected_rows'](); |
| 82 | 85 | |
| 83 | 86 | // What kind of task are we handling? |
| 84 | - if (!empty($row['callable'])) |
|
| 85 | - $task_string = $row['callable']; |
|
| 87 | + if (!empty($row['callable'])) { |
|
| 88 | + $task_string = $row['callable']; |
|
| 89 | + } |
|
| 86 | 90 | |
| 87 | 91 | // Default SMF task or old mods? |
| 88 | - elseif (function_exists('scheduled_' . $row['task'])) |
|
| 89 | - $task_string = 'scheduled_' . $row['task']; |
|
| 92 | + elseif (function_exists('scheduled_' . $row['task'])) { |
|
| 93 | + $task_string = 'scheduled_' . $row['task']; |
|
| 94 | + } |
|
| 90 | 95 | |
| 91 | 96 | // One last resource, the task name. |
| 92 | - elseif (!empty($row['task'])) |
|
| 93 | - $task_string = $row['task']; |
|
| 97 | + elseif (!empty($row['task'])) { |
|
| 98 | + $task_string = $row['task']; |
|
| 99 | + } |
|
| 94 | 100 | |
| 95 | 101 | // The function must exist or we are wasting our time, plus do some timestamp checking, and database check! |
| 96 | 102 | if (!empty($task_string) && (!isset($_GET['ts']) || $_GET['ts'] == $row['next_time']) && $affected_rows) |
@@ -101,11 +107,11 @@ discard block |
||
| 101 | 107 | $callable_task = call_helper($task_string, true); |
| 102 | 108 | |
| 103 | 109 | // Perform the task. |
| 104 | - if (!empty($callable_task)) |
|
| 105 | - $completed = call_user_func($callable_task); |
|
| 106 | - |
|
| 107 | - else |
|
| 108 | - $completed = false; |
|
| 110 | + if (!empty($callable_task)) { |
|
| 111 | + $completed = call_user_func($callable_task); |
|
| 112 | + } else { |
|
| 113 | + $completed = false; |
|
| 114 | + } |
|
| 109 | 115 | |
| 110 | 116 | // Log that we did it ;) |
| 111 | 117 | if ($completed) |
@@ -138,18 +144,20 @@ discard block |
||
| 138 | 144 | ) |
| 139 | 145 | ); |
| 140 | 146 | // No new task scheduled yet? |
| 141 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 142 | - $nextEvent = time() + 86400; |
|
| 143 | - else |
|
| 144 | - list ($nextEvent) = $smcFunc['db_fetch_row']($request); |
|
| 147 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 148 | + $nextEvent = time() + 86400; |
|
| 149 | + } else { |
|
| 150 | + list ($nextEvent) = $smcFunc['db_fetch_row']($request); |
|
| 151 | + } |
|
| 145 | 152 | $smcFunc['db_free_result']($request); |
| 146 | 153 | |
| 147 | 154 | updateSettings(array('next_task_time' => $nextEvent)); |
| 148 | 155 | } |
| 149 | 156 | |
| 150 | 157 | // Shall we return? |
| 151 | - if (!isset($_GET['scheduled'])) |
|
| 152 | - return true; |
|
| 158 | + if (!isset($_GET['scheduled'])) { |
|
| 159 | + return true; |
|
| 160 | + } |
|
| 153 | 161 | |
| 154 | 162 | // Finally, send some stuff... |
| 155 | 163 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -181,16 +189,18 @@ discard block |
||
| 181 | 189 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 182 | 190 | { |
| 183 | 191 | // If this is no longer around we'll ignore it. |
| 184 | - if (empty($row['id_topic'])) |
|
| 185 | - continue; |
|
| 192 | + if (empty($row['id_topic'])) { |
|
| 193 | + continue; |
|
| 194 | + } |
|
| 186 | 195 | |
| 187 | 196 | // What type is it? |
| 188 | - if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) |
|
| 189 | - $type = 'topic'; |
|
| 190 | - elseif ($row['id_attach']) |
|
| 191 | - $type = 'attach'; |
|
| 192 | - else |
|
| 193 | - $type = 'msg'; |
|
| 197 | + if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) { |
|
| 198 | + $type = 'topic'; |
|
| 199 | + } elseif ($row['id_attach']) { |
|
| 200 | + $type = 'attach'; |
|
| 201 | + } else { |
|
| 202 | + $type = 'msg'; |
|
| 203 | + } |
|
| 194 | 204 | |
| 195 | 205 | // Add it to the array otherwise. |
| 196 | 206 | $notices[$row['id_board']][$type][] = array( |
@@ -211,8 +221,9 @@ discard block |
||
| 211 | 221 | ); |
| 212 | 222 | |
| 213 | 223 | // If nothing quit now. |
| 214 | - if (empty($notices)) |
|
| 215 | - return true; |
|
| 224 | + if (empty($notices)) { |
|
| 225 | + return true; |
|
| 226 | + } |
|
| 216 | 227 | |
| 217 | 228 | // Now we need to think about finding out *who* can approve - this is hard! |
| 218 | 229 | |
@@ -231,14 +242,16 @@ discard block |
||
| 231 | 242 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 232 | 243 | { |
| 233 | 244 | // Sorry guys, but we have to ignore guests AND members - it would be too many otherwise. |
| 234 | - if ($row['id_group'] < 2) |
|
| 235 | - continue; |
|
| 245 | + if ($row['id_group'] < 2) { |
|
| 246 | + continue; |
|
| 247 | + } |
|
| 236 | 248 | |
| 237 | 249 | $perms[$row['id_profile']][$row['add_deny'] ? 'add' : 'deny'][] = $row['id_group']; |
| 238 | 250 | |
| 239 | 251 | // Anyone who can access has to be considered. |
| 240 | - if ($row['add_deny']) |
|
| 241 | - $addGroups[] = $row['id_group']; |
|
| 252 | + if ($row['add_deny']) { |
|
| 253 | + $addGroups[] = $row['id_group']; |
|
| 254 | + } |
|
| 242 | 255 | } |
| 243 | 256 | $smcFunc['db_free_result']($request); |
| 244 | 257 | |
@@ -283,8 +296,9 @@ discard block |
||
| 283 | 296 | if (!empty($row['mod_prefs'])) |
| 284 | 297 | { |
| 285 | 298 | list(,, $pref_binary) = explode('|', $row['mod_prefs']); |
| 286 | - if (!($pref_binary & 4)) |
|
| 287 | - continue; |
|
| 299 | + if (!($pref_binary & 4)) { |
|
| 300 | + continue; |
|
| 301 | + } |
|
| 288 | 302 | } |
| 289 | 303 | |
| 290 | 304 | $members[$row['id_member']] = array( |
@@ -309,8 +323,9 @@ discard block |
||
| 309 | 323 | $emailbody = ''; |
| 310 | 324 | |
| 311 | 325 | // Load the language file as required. |
| 312 | - if (empty($current_language) || $current_language != $member['language']) |
|
| 313 | - $current_language = loadLanguage('EmailTemplates', $member['language'], false); |
|
| 326 | + if (empty($current_language) || $current_language != $member['language']) { |
|
| 327 | + $current_language = loadLanguage('EmailTemplates', $member['language'], false); |
|
| 328 | + } |
|
| 314 | 329 | |
| 315 | 330 | // Loop through each notice... |
| 316 | 331 | foreach ($notices as $board => $notice) |
@@ -318,29 +333,34 @@ discard block |
||
| 318 | 333 | $access = false; |
| 319 | 334 | |
| 320 | 335 | // Can they mod in this board? |
| 321 | - if (isset($mods[$id][$board])) |
|
| 322 | - $access = true; |
|
| 336 | + if (isset($mods[$id][$board])) { |
|
| 337 | + $access = true; |
|
| 338 | + } |
|
| 323 | 339 | |
| 324 | 340 | // Do the group check... |
| 325 | 341 | if (!$access && isset($perms[$profiles[$board]]['add'])) |
| 326 | 342 | { |
| 327 | 343 | // They can access?! |
| 328 | - if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) |
|
| 329 | - $access = true; |
|
| 344 | + if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) { |
|
| 345 | + $access = true; |
|
| 346 | + } |
|
| 330 | 347 | |
| 331 | 348 | // If they have deny rights don't consider them! |
| 332 | - if (isset($perms[$profiles[$board]]['deny'])) |
|
| 333 | - if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups'])) |
|
| 349 | + if (isset($perms[$profiles[$board]]['deny'])) { |
|
| 350 | + if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups'])) |
|
| 334 | 351 | $access = false; |
| 352 | + } |
|
| 335 | 353 | } |
| 336 | 354 | |
| 337 | 355 | // Finally, fix it for admins! |
| 338 | - if (in_array(1, $member['groups'])) |
|
| 339 | - $access = true; |
|
| 356 | + if (in_array(1, $member['groups'])) { |
|
| 357 | + $access = true; |
|
| 358 | + } |
|
| 340 | 359 | |
| 341 | 360 | // If they can't access it then give it a break! |
| 342 | - if (!$access) |
|
| 343 | - continue; |
|
| 361 | + if (!$access) { |
|
| 362 | + continue; |
|
| 363 | + } |
|
| 344 | 364 | |
| 345 | 365 | foreach ($notice as $type => $items) |
| 346 | 366 | { |
@@ -348,15 +368,17 @@ discard block |
||
| 348 | 368 | $emailbody .= $txt['scheduled_approval_email_' . $type] . "\n" . |
| 349 | 369 | '------------------------------------------------------' . "\n"; |
| 350 | 370 | |
| 351 | - foreach ($items as $item) |
|
| 352 | - $emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n"; |
|
| 371 | + foreach ($items as $item) { |
|
| 372 | + $emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n"; |
|
| 373 | + } |
|
| 353 | 374 | |
| 354 | 375 | $emailbody .= "\n"; |
| 355 | 376 | } |
| 356 | 377 | } |
| 357 | 378 | |
| 358 | - if ($emailbody == '') |
|
| 359 | - continue; |
|
| 379 | + if ($emailbody == '') { |
|
| 380 | + continue; |
|
| 381 | + } |
|
| 360 | 382 | |
| 361 | 383 | $replacements = array( |
| 362 | 384 | 'REALNAME' => $member['name'], |
@@ -397,8 +419,9 @@ discard block |
||
| 397 | 419 | ) |
| 398 | 420 | ); |
| 399 | 421 | $members = array(); |
| 400 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 401 | - $members[$row['id_member']] = $row['warning']; |
|
| 422 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 423 | + $members[$row['id_member']] = $row['warning']; |
|
| 424 | + } |
|
| 402 | 425 | $smcFunc['db_free_result']($request); |
| 403 | 426 | |
| 404 | 427 | // Have some members to check? |
@@ -420,17 +443,18 @@ discard block |
||
| 420 | 443 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 421 | 444 | { |
| 422 | 445 | // More than 24 hours ago? |
| 423 | - if ($row['last_warning'] <= time() - 86400) |
|
| 424 | - $member_changes[] = array( |
|
| 446 | + if ($row['last_warning'] <= time() - 86400) { |
|
| 447 | + $member_changes[] = array( |
|
| 425 | 448 | 'id' => $row['id_recipient'], |
| 426 | 449 | 'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0, |
| 427 | 450 | ); |
| 451 | + } |
|
| 428 | 452 | } |
| 429 | 453 | $smcFunc['db_free_result']($request); |
| 430 | 454 | |
| 431 | 455 | // Have some members to change? |
| 432 | - if (!empty($member_changes)) |
|
| 433 | - foreach ($member_changes as $change) |
|
| 456 | + if (!empty($member_changes)) { |
|
| 457 | + foreach ($member_changes as $change) |
|
| 434 | 458 | $smcFunc['db_query']('', ' |
| 435 | 459 | UPDATE {db_prefix}members |
| 436 | 460 | SET warning = {int:warning} |
@@ -440,6 +464,7 @@ discard block |
||
| 440 | 464 | 'id_member' => $change['id'], |
| 441 | 465 | ) |
| 442 | 466 | ); |
| 467 | + } |
|
| 443 | 468 | } |
| 444 | 469 | } |
| 445 | 470 | |
@@ -452,16 +477,17 @@ discard block |
||
| 452 | 477 | |
| 453 | 478 | // Check the database version - for some buggy MySQL version. |
| 454 | 479 | $server_version = $smcFunc['db_server_info'](); |
| 455 | - if (($db_type == 'mysql') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) |
|
| 456 | - updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 457 | - elseif (!empty($modSettings['db_mysql_group_by_fix'])) |
|
| 458 | - $smcFunc['db_query']('', ' |
|
| 480 | + if (($db_type == 'mysql') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { |
|
| 481 | + updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 482 | + } elseif (!empty($modSettings['db_mysql_group_by_fix'])) { |
|
| 483 | + $smcFunc['db_query']('', ' |
|
| 459 | 484 | DELETE FROM {db_prefix}settings |
| 460 | 485 | WHERE variable = {string:mysql_fix}', |
| 461 | 486 | array( |
| 462 | 487 | 'mysql_fix' => 'db_mysql_group_by_fix', |
| 463 | 488 | ) |
| 464 | 489 | ); |
| 490 | + } |
|
| 465 | 491 | |
| 466 | 492 | // Clean up some old login history information. |
| 467 | 493 | $smcFunc['db_query']('', ' |
@@ -519,15 +545,17 @@ discard block |
||
| 519 | 545 | |
| 520 | 546 | // Store this useful data! |
| 521 | 547 | $boards[$row['id_board']] = $row['id_board']; |
| 522 | - if ($row['id_topic']) |
|
| 523 | - $notify['topics'][$row['id_topic']][] = $row['id_member']; |
|
| 524 | - else |
|
| 525 | - $notify['boards'][$row['id_board']][] = $row['id_member']; |
|
| 548 | + if ($row['id_topic']) { |
|
| 549 | + $notify['topics'][$row['id_topic']][] = $row['id_member']; |
|
| 550 | + } else { |
|
| 551 | + $notify['boards'][$row['id_board']][] = $row['id_member']; |
|
| 552 | + } |
|
| 526 | 553 | } |
| 527 | 554 | $smcFunc['db_free_result']($request); |
| 528 | 555 | |
| 529 | - if (empty($boards)) |
|
| 530 | - return true; |
|
| 556 | + if (empty($boards)) { |
|
| 557 | + return true; |
|
| 558 | + } |
|
| 531 | 559 | |
| 532 | 560 | // Just get the board names. |
| 533 | 561 | $request = $smcFunc['db_query']('', ' |
@@ -539,12 +567,14 @@ discard block |
||
| 539 | 567 | ) |
| 540 | 568 | ); |
| 541 | 569 | $boards = array(); |
| 542 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 543 | - $boards[$row['id_board']] = $row['name']; |
|
| 570 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 571 | + $boards[$row['id_board']] = $row['name']; |
|
| 572 | + } |
|
| 544 | 573 | $smcFunc['db_free_result']($request); |
| 545 | 574 | |
| 546 | - if (empty($boards)) |
|
| 547 | - return true; |
|
| 575 | + if (empty($boards)) { |
|
| 576 | + return true; |
|
| 577 | + } |
|
| 548 | 578 | |
| 549 | 579 | // Get the actual topics... |
| 550 | 580 | $request = $smcFunc['db_query']('', ' |
@@ -564,52 +594,57 @@ discard block |
||
| 564 | 594 | $types = array(); |
| 565 | 595 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 566 | 596 | { |
| 567 | - if (!isset($types[$row['note_type']][$row['id_board']])) |
|
| 568 | - $types[$row['note_type']][$row['id_board']] = array( |
|
| 597 | + if (!isset($types[$row['note_type']][$row['id_board']])) { |
|
| 598 | + $types[$row['note_type']][$row['id_board']] = array( |
|
| 569 | 599 | 'lines' => array(), |
| 570 | 600 | 'name' => $row['board_name'], |
| 571 | 601 | 'id' => $row['id_board'], |
| 572 | 602 | ); |
| 603 | + } |
|
| 573 | 604 | |
| 574 | 605 | if ($row['note_type'] == 'reply') |
| 575 | 606 | { |
| 576 | - if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) |
|
| 577 | - $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++; |
|
| 578 | - else |
|
| 579 | - $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array( |
|
| 607 | + if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) { |
|
| 608 | + $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++; |
|
| 609 | + } else { |
|
| 610 | + $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array( |
|
| 580 | 611 | 'id' => $row['id_topic'], |
| 581 | 612 | 'subject' => un_htmlspecialchars($row['subject']), |
| 582 | 613 | 'count' => 1, |
| 583 | 614 | ); |
| 584 | - } |
|
| 585 | - elseif ($row['note_type'] == 'topic') |
|
| 615 | + } |
|
| 616 | + } elseif ($row['note_type'] == 'topic') |
|
| 586 | 617 | { |
| 587 | - if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) |
|
| 588 | - $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array( |
|
| 618 | + if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) { |
|
| 619 | + $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array( |
|
| 589 | 620 | 'id' => $row['id_topic'], |
| 590 | 621 | 'subject' => un_htmlspecialchars($row['subject']), |
| 591 | 622 | ); |
| 592 | - } |
|
| 593 | - else |
|
| 623 | + } |
|
| 624 | + } else |
|
| 594 | 625 | { |
| 595 | - if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) |
|
| 596 | - $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array( |
|
| 626 | + if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) { |
|
| 627 | + $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array( |
|
| 597 | 628 | 'id' => $row['id_topic'], |
| 598 | 629 | 'subject' => un_htmlspecialchars($row['subject']), |
| 599 | 630 | 'starter' => $row['id_member_started'], |
| 600 | 631 | ); |
| 632 | + } |
|
| 601 | 633 | } |
| 602 | 634 | |
| 603 | 635 | $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array(); |
| 604 | - if (!empty($notify['topics'][$row['id_topic']])) |
|
| 605 | - $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]); |
|
| 606 | - if (!empty($notify['boards'][$row['id_board']])) |
|
| 607 | - $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]); |
|
| 636 | + if (!empty($notify['topics'][$row['id_topic']])) { |
|
| 637 | + $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]); |
|
| 638 | + } |
|
| 639 | + if (!empty($notify['boards'][$row['id_board']])) { |
|
| 640 | + $types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]); |
|
| 641 | + } |
|
| 608 | 642 | } |
| 609 | 643 | $smcFunc['db_free_result']($request); |
| 610 | 644 | |
| 611 | - if (empty($types)) |
|
| 612 | - return true; |
|
| 645 | + if (empty($types)) { |
|
| 646 | + return true; |
|
| 647 | + } |
|
| 613 | 648 | |
| 614 | 649 | // Let's load all the languages into a cache thingy. |
| 615 | 650 | $langtxt = array(); |
@@ -650,8 +685,9 @@ discard block |
||
| 650 | 685 | $notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1; |
| 651 | 686 | |
| 652 | 687 | // Did they not elect to choose this? |
| 653 | - if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) |
|
| 654 | - continue; |
|
| 688 | + if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) { |
|
| 689 | + continue; |
|
| 690 | + } |
|
| 655 | 691 | |
| 656 | 692 | // Right character set! |
| 657 | 693 | $context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set']; |
@@ -667,39 +703,43 @@ discard block |
||
| 667 | 703 | if (isset($types['topic'])) |
| 668 | 704 | { |
| 669 | 705 | $titled = false; |
| 670 | - foreach ($types['topic'] as $id => $board) |
|
| 671 | - foreach ($board['lines'] as $topic) |
|
| 706 | + foreach ($types['topic'] as $id => $board) { |
|
| 707 | + foreach ($board['lines'] as $topic) |
|
| 672 | 708 | if (in_array($mid, $topic['members'])) |
| 673 | 709 | { |
| 674 | 710 | if (!$titled) |
| 675 | 711 | { |
| 676 | 712 | $email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------'; |
| 713 | + } |
|
| 677 | 714 | $titled = true; |
| 678 | 715 | } |
| 679 | 716 | $email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']); |
| 680 | 717 | } |
| 681 | - if ($titled) |
|
| 682 | - $email['body'] .= "\n"; |
|
| 718 | + if ($titled) { |
|
| 719 | + $email['body'] .= "\n"; |
|
| 720 | + } |
|
| 683 | 721 | } |
| 684 | 722 | |
| 685 | 723 | // What about replies? |
| 686 | 724 | if (isset($types['reply'])) |
| 687 | 725 | { |
| 688 | 726 | $titled = false; |
| 689 | - foreach ($types['reply'] as $id => $board) |
|
| 690 | - foreach ($board['lines'] as $topic) |
|
| 727 | + foreach ($types['reply'] as $id => $board) { |
|
| 728 | + foreach ($board['lines'] as $topic) |
|
| 691 | 729 | if (in_array($mid, $topic['members'])) |
| 692 | 730 | { |
| 693 | 731 | if (!$titled) |
| 694 | 732 | { |
| 695 | 733 | $email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------'; |
| 734 | + } |
|
| 696 | 735 | $titled = true; |
| 697 | 736 | } |
| 698 | 737 | $email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject'])); |
| 699 | 738 | } |
| 700 | 739 | |
| 701 | - if ($titled) |
|
| 702 | - $email['body'] .= "\n"; |
|
| 740 | + if ($titled) { |
|
| 741 | + $email['body'] .= "\n"; |
|
| 742 | + } |
|
| 703 | 743 | } |
| 704 | 744 | |
| 705 | 745 | // Finally, moderation actions! |
@@ -708,24 +748,27 @@ discard block |
||
| 708 | 748 | $titled = false; |
| 709 | 749 | foreach ($types as $note_type => $type) |
| 710 | 750 | { |
| 711 | - if ($note_type == 'topic' || $note_type == 'reply') |
|
| 712 | - continue; |
|
| 751 | + if ($note_type == 'topic' || $note_type == 'reply') { |
|
| 752 | + continue; |
|
| 753 | + } |
|
| 713 | 754 | |
| 714 | - foreach ($type as $id => $board) |
|
| 715 | - foreach ($board['lines'] as $topic) |
|
| 755 | + foreach ($type as $id => $board) { |
|
| 756 | + foreach ($board['lines'] as $topic) |
|
| 716 | 757 | if (in_array($mid, $topic['members'])) |
| 717 | 758 | { |
| 718 | 759 | if (!$titled) |
| 719 | 760 | { |
| 720 | 761 | $email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------'; |
| 762 | + } |
|
| 721 | 763 | $titled = true; |
| 722 | 764 | } |
| 723 | 765 | $email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']); |
| 724 | 766 | } |
| 725 | 767 | } |
| 726 | 768 | } |
| 727 | - if ($titled) |
|
| 728 | - $email['body'] .= "\n"; |
|
| 769 | + if ($titled) { |
|
| 770 | + $email['body'] .= "\n"; |
|
| 771 | + } |
|
| 729 | 772 | |
| 730 | 773 | // Then just say our goodbyes! |
| 731 | 774 | $email['body'] .= "\n\n" . $txt['regards_team']; |
@@ -753,8 +796,7 @@ discard block |
||
| 753 | 796 | 'not_daily' => 0, |
| 754 | 797 | ) |
| 755 | 798 | ); |
| 756 | - } |
|
| 757 | - else |
|
| 799 | + } else |
|
| 758 | 800 | { |
| 759 | 801 | // Clear any only weekly ones, and stop us from sending daily again. |
| 760 | 802 | $smcFunc['db_query']('', ' |
@@ -816,16 +858,19 @@ discard block |
||
| 816 | 858 | global $modSettings, $smcFunc, $sourcedir; |
| 817 | 859 | |
| 818 | 860 | // Are we intending another script to be sending out the queue? |
| 819 | - if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) |
|
| 820 | - return false; |
|
| 861 | + if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) { |
|
| 862 | + return false; |
|
| 863 | + } |
|
| 821 | 864 | |
| 822 | 865 | // By default send 5 at once. |
| 823 | - if (!$number) |
|
| 824 | - $number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity']; |
|
| 866 | + if (!$number) { |
|
| 867 | + $number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity']; |
|
| 868 | + } |
|
| 825 | 869 | |
| 826 | 870 | // If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us. |
| 827 | - if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) |
|
| 828 | - return false; |
|
| 871 | + if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) { |
|
| 872 | + return false; |
|
| 873 | + } |
|
| 829 | 874 | |
| 830 | 875 | // By default move the next sending on by 10 seconds, and require an affected row. |
| 831 | 876 | if (!$override_limit) |
@@ -842,8 +887,9 @@ discard block |
||
| 842 | 887 | 'last_send' => $modSettings['mail_next_send'], |
| 843 | 888 | ) |
| 844 | 889 | ); |
| 845 | - if ($smcFunc['db_affected_rows']() == 0) |
|
| 846 | - return false; |
|
| 890 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
| 891 | + return false; |
|
| 892 | + } |
|
| 847 | 893 | $modSettings['mail_next_send'] = time() + $delay; |
| 848 | 894 | } |
| 849 | 895 | |
@@ -864,8 +910,9 @@ discard block |
||
| 864 | 910 | $mn += $number; |
| 865 | 911 | } |
| 866 | 912 | // No more I'm afraid, return! |
| 867 | - else |
|
| 868 | - return false; |
|
| 913 | + else { |
|
| 914 | + return false; |
|
| 915 | + } |
|
| 869 | 916 | |
| 870 | 917 | // Reflect that we're about to send some, do it now to be safe. |
| 871 | 918 | updateSettings(array('mail_recent' => $mt . '|' . $mn)); |
@@ -900,14 +947,15 @@ discard block |
||
| 900 | 947 | $smcFunc['db_free_result']($request); |
| 901 | 948 | |
| 902 | 949 | // Delete, delete, delete!!! |
| 903 | - if (!empty($ids)) |
|
| 904 | - $smcFunc['db_query']('', ' |
|
| 950 | + if (!empty($ids)) { |
|
| 951 | + $smcFunc['db_query']('', ' |
|
| 905 | 952 | DELETE FROM {db_prefix}mail_queue |
| 906 | 953 | WHERE id_mail IN ({array_int:mail_list})', |
| 907 | 954 | array( |
| 908 | 955 | 'mail_list' => $ids, |
| 909 | 956 | ) |
| 910 | 957 | ); |
| 958 | + } |
|
| 911 | 959 | |
| 912 | 960 | // Don't believe we have any left? |
| 913 | 961 | if (count($ids) < $number) |
@@ -925,11 +973,13 @@ discard block |
||
| 925 | 973 | ); |
| 926 | 974 | } |
| 927 | 975 | |
| 928 | - if (empty($ids)) |
|
| 929 | - return false; |
|
| 976 | + if (empty($ids)) { |
|
| 977 | + return false; |
|
| 978 | + } |
|
| 930 | 979 | |
| 931 | - if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') |
|
| 932 | - require_once($sourcedir . '/Subs-Post.php'); |
|
| 980 | + if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') { |
|
| 981 | + require_once($sourcedir . '/Subs-Post.php'); |
|
| 982 | + } |
|
| 933 | 983 | |
| 934 | 984 | // Send each email, yea! |
| 935 | 985 | $failed_emails = array(); |
@@ -949,15 +999,17 @@ discard block |
||
| 949 | 999 | |
| 950 | 1000 | // Try to stop a timeout, this would be bad... |
| 951 | 1001 | @set_time_limit(300); |
| 952 | - if (function_exists('apache_reset_timeout')) |
|
| 953 | - @apache_reset_timeout(); |
|
| 1002 | + if (function_exists('apache_reset_timeout')) { |
|
| 1003 | + @apache_reset_timeout(); |
|
| 1004 | + } |
|
| 1005 | + } else { |
|
| 1006 | + $result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']); |
|
| 954 | 1007 | } |
| 955 | - else |
|
| 956 | - $result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']); |
|
| 957 | 1008 | |
| 958 | 1009 | // Hopefully it sent? |
| 959 | - if (!$result) |
|
| 960 | - $failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']); |
|
| 1010 | + if (!$result) { |
|
| 1011 | + $failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']); |
|
| 1012 | + } |
|
| 961 | 1013 | } |
| 962 | 1014 | |
| 963 | 1015 | // Any emails that didn't send? |
@@ -972,8 +1024,8 @@ discard block |
||
| 972 | 1024 | ); |
| 973 | 1025 | |
| 974 | 1026 | // If we have failed to many times, tell mail to wait a bit and try again. |
| 975 | - if ($modSettings['mail_failed_attempts'] > 5) |
|
| 976 | - $smcFunc['db_query']('', ' |
|
| 1027 | + if ($modSettings['mail_failed_attempts'] > 5) { |
|
| 1028 | + $smcFunc['db_query']('', ' |
|
| 977 | 1029 | UPDATE {db_prefix}settings |
| 978 | 1030 | SET value = {string:next_mail_send} |
| 979 | 1031 | WHERE variable = {literal:mail_next_send} |
@@ -982,6 +1034,7 @@ discard block |
||
| 982 | 1034 | 'next_mail_send' => time() + 60, |
| 983 | 1035 | 'last_send' => $modSettings['mail_next_send'], |
| 984 | 1036 | )); |
| 1037 | + } |
|
| 985 | 1038 | |
| 986 | 1039 | // Add our email back to the queue, manually. |
| 987 | 1040 | $smcFunc['db_insert']('insert', |
@@ -994,8 +1047,8 @@ discard block |
||
| 994 | 1047 | return false; |
| 995 | 1048 | } |
| 996 | 1049 | // We where unable to send the email, clear our failed attempts. |
| 997 | - elseif (!empty($modSettings['mail_failed_attempts'])) |
|
| 998 | - $smcFunc['db_query']('', ' |
|
| 1050 | + elseif (!empty($modSettings['mail_failed_attempts'])) { |
|
| 1051 | + $smcFunc['db_query']('', ' |
|
| 999 | 1052 | UPDATE {db_prefix}settings |
| 1000 | 1053 | SET value = {string:zero} |
| 1001 | 1054 | WHERE variable = {string:mail_failed_attempts}', |
@@ -1003,6 +1056,7 @@ discard block |
||
| 1003 | 1056 | 'zero' => '0', |
| 1004 | 1057 | 'mail_failed_attempts' => 'mail_failed_attempts', |
| 1005 | 1058 | )); |
| 1059 | + } |
|
| 1006 | 1060 | |
| 1007 | 1061 | // Had something to send... |
| 1008 | 1062 | return true; |
@@ -1019,16 +1073,18 @@ discard block |
||
| 1019 | 1073 | global $modSettings, $smcFunc; |
| 1020 | 1074 | |
| 1021 | 1075 | $task_query = ''; |
| 1022 | - if (!is_array($tasks)) |
|
| 1023 | - $tasks = array($tasks); |
|
| 1076 | + if (!is_array($tasks)) { |
|
| 1077 | + $tasks = array($tasks); |
|
| 1078 | + } |
|
| 1024 | 1079 | |
| 1025 | 1080 | // Actually have something passed? |
| 1026 | 1081 | if (!empty($tasks)) |
| 1027 | 1082 | { |
| 1028 | - if (!isset($tasks[0]) || is_numeric($tasks[0])) |
|
| 1029 | - $task_query = ' AND id_task IN ({array_int:tasks})'; |
|
| 1030 | - else |
|
| 1031 | - $task_query = ' AND task IN ({array_string:tasks})'; |
|
| 1083 | + if (!isset($tasks[0]) || is_numeric($tasks[0])) { |
|
| 1084 | + $task_query = ' AND id_task IN ({array_int:tasks})'; |
|
| 1085 | + } else { |
|
| 1086 | + $task_query = ' AND task IN ({array_string:tasks})'; |
|
| 1087 | + } |
|
| 1032 | 1088 | } |
| 1033 | 1089 | $nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time']; |
| 1034 | 1090 | |
@@ -1049,20 +1105,22 @@ discard block |
||
| 1049 | 1105 | $next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']); |
| 1050 | 1106 | |
| 1051 | 1107 | // Only bother moving the task if it's out of place or we're forcing it! |
| 1052 | - if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) |
|
| 1053 | - $tasks[$row['id_task']] = $next_time; |
|
| 1054 | - else |
|
| 1055 | - $next_time = $row['next_time']; |
|
| 1108 | + if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) { |
|
| 1109 | + $tasks[$row['id_task']] = $next_time; |
|
| 1110 | + } else { |
|
| 1111 | + $next_time = $row['next_time']; |
|
| 1112 | + } |
|
| 1056 | 1113 | |
| 1057 | 1114 | // If this is sooner than the current next task, make this the next task. |
| 1058 | - if ($next_time < $nextTaskTime) |
|
| 1059 | - $nextTaskTime = $next_time; |
|
| 1115 | + if ($next_time < $nextTaskTime) { |
|
| 1116 | + $nextTaskTime = $next_time; |
|
| 1117 | + } |
|
| 1060 | 1118 | } |
| 1061 | 1119 | $smcFunc['db_free_result']($request); |
| 1062 | 1120 | |
| 1063 | 1121 | // Now make the changes! |
| 1064 | - foreach ($tasks as $id => $time) |
|
| 1065 | - $smcFunc['db_query']('', ' |
|
| 1122 | + foreach ($tasks as $id => $time) { |
|
| 1123 | + $smcFunc['db_query']('', ' |
|
| 1066 | 1124 | UPDATE {db_prefix}scheduled_tasks |
| 1067 | 1125 | SET next_time = {int:next_time} |
| 1068 | 1126 | WHERE id_task = {int:id_task}', |
@@ -1071,11 +1129,13 @@ discard block |
||
| 1071 | 1129 | 'id_task' => $id, |
| 1072 | 1130 | ) |
| 1073 | 1131 | ); |
| 1132 | + } |
|
| 1074 | 1133 | |
| 1075 | 1134 | // If the next task is now different update. |
| 1076 | - if ($modSettings['next_task_time'] != $nextTaskTime) |
|
| 1077 | - updateSettings(array('next_task_time' => $nextTaskTime)); |
|
| 1078 | -} |
|
| 1135 | + if ($modSettings['next_task_time'] != $nextTaskTime) { |
|
| 1136 | + updateSettings(array('next_task_time' => $nextTaskTime)); |
|
| 1137 | + } |
|
| 1138 | + } |
|
| 1079 | 1139 | |
| 1080 | 1140 | /** |
| 1081 | 1141 | * Simply returns a time stamp of the next instance of these time parameters. |
@@ -1088,8 +1148,9 @@ discard block |
||
| 1088 | 1148 | function next_time($regularity, $unit, $offset) |
| 1089 | 1149 | { |
| 1090 | 1150 | // Just in case! |
| 1091 | - if ($regularity == 0) |
|
| 1092 | - $regularity = 2; |
|
| 1151 | + if ($regularity == 0) { |
|
| 1152 | + $regularity = 2; |
|
| 1153 | + } |
|
| 1093 | 1154 | |
| 1094 | 1155 | $curMin = date('i', time()); |
| 1095 | 1156 | |
@@ -1099,15 +1160,16 @@ discard block |
||
| 1099 | 1160 | $off = date('i', $offset); |
| 1100 | 1161 | |
| 1101 | 1162 | // If it's now just pretend it ain't, |
| 1102 | - if ($off == $curMin) |
|
| 1103 | - $next_time = time() + $regularity; |
|
| 1104 | - else |
|
| 1163 | + if ($off == $curMin) { |
|
| 1164 | + $next_time = time() + $regularity; |
|
| 1165 | + } else |
|
| 1105 | 1166 | { |
| 1106 | 1167 | // Make sure that the offset is always in the past. |
| 1107 | 1168 | $off = $off > $curMin ? $off - 60 : $off; |
| 1108 | 1169 | |
| 1109 | - while ($off <= $curMin) |
|
| 1110 | - $off += $regularity; |
|
| 1170 | + while ($off <= $curMin) { |
|
| 1171 | + $off += $regularity; |
|
| 1172 | + } |
|
| 1111 | 1173 | |
| 1112 | 1174 | // Now we know when the time should be! |
| 1113 | 1175 | $next_time = time() + 60 * ($off - $curMin); |
@@ -1127,11 +1189,13 @@ discard block |
||
| 1127 | 1189 | // Default we'll jump in hours. |
| 1128 | 1190 | $applyOffset = 3600; |
| 1129 | 1191 | // 24 hours = 1 day. |
| 1130 | - if ($unit == 'd') |
|
| 1131 | - $applyOffset = 86400; |
|
| 1192 | + if ($unit == 'd') { |
|
| 1193 | + $applyOffset = 86400; |
|
| 1194 | + } |
|
| 1132 | 1195 | // Otherwise a week. |
| 1133 | - if ($unit == 'w') |
|
| 1134 | - $applyOffset = 604800; |
|
| 1196 | + if ($unit == 'w') { |
|
| 1197 | + $applyOffset = 604800; |
|
| 1198 | + } |
|
| 1135 | 1199 | |
| 1136 | 1200 | $applyOffset *= $regularity; |
| 1137 | 1201 | |
@@ -1168,8 +1232,9 @@ discard block |
||
| 1168 | 1232 | $settings[$row['variable']] = $row['value']; |
| 1169 | 1233 | |
| 1170 | 1234 | // Is this the default theme? |
| 1171 | - if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') |
|
| 1172 | - $settings['default_' . $row['variable']] = $row['value']; |
|
| 1235 | + if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') { |
|
| 1236 | + $settings['default_' . $row['variable']] = $row['value']; |
|
| 1237 | + } |
|
| 1173 | 1238 | } |
| 1174 | 1239 | $smcFunc['db_free_result']($result); |
| 1175 | 1240 | |
@@ -1179,12 +1244,14 @@ discard block |
||
| 1179 | 1244 | $settings['template_dirs'] = array($settings['theme_dir']); |
| 1180 | 1245 | |
| 1181 | 1246 | // Based on theme (if there is one). |
| 1182 | - if (!empty($settings['base_theme_dir'])) |
|
| 1183 | - $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
| 1247 | + if (!empty($settings['base_theme_dir'])) { |
|
| 1248 | + $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
| 1249 | + } |
|
| 1184 | 1250 | |
| 1185 | 1251 | // Lastly the default theme. |
| 1186 | - if ($settings['theme_dir'] != $settings['default_theme_dir']) |
|
| 1187 | - $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
| 1252 | + if ($settings['theme_dir'] != $settings['default_theme_dir']) { |
|
| 1253 | + $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
| 1254 | + } |
|
| 1188 | 1255 | } |
| 1189 | 1256 | |
| 1190 | 1257 | // Assume we want this. |
@@ -1330,8 +1397,9 @@ discard block |
||
| 1330 | 1397 | // Ok should we prune the logs? |
| 1331 | 1398 | if (!empty($modSettings['pruningOptions'])) |
| 1332 | 1399 | { |
| 1333 | - if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) |
|
| 1334 | - list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']); |
|
| 1400 | + if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) { |
|
| 1401 | + list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']); |
|
| 1402 | + } |
|
| 1335 | 1403 | |
| 1336 | 1404 | if (!empty($modSettings['pruneErrorLog'])) |
| 1337 | 1405 | { |
@@ -1397,8 +1465,9 @@ discard block |
||
| 1397 | 1465 | ) |
| 1398 | 1466 | ); |
| 1399 | 1467 | |
| 1400 | - while ($row = $smcFunc['db_fetch_row']($result)) |
|
| 1401 | - $reports[] = $row[0]; |
|
| 1468 | + while ($row = $smcFunc['db_fetch_row']($result)) { |
|
| 1469 | + $reports[] = $row[0]; |
|
| 1470 | + } |
|
| 1402 | 1471 | |
| 1403 | 1472 | $smcFunc['db_free_result']($result); |
| 1404 | 1473 | |
@@ -1560,8 +1629,9 @@ discard block |
||
| 1560 | 1629 | $emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']); |
| 1561 | 1630 | |
| 1562 | 1631 | // Send the actual email. |
| 1563 | - if ($notifyPrefs[$row['id_member']] & 0x02) |
|
| 1564 | - sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2); |
|
| 1632 | + if ($notifyPrefs[$row['id_member']] & 0x02) { |
|
| 1633 | + sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2); |
|
| 1634 | + } |
|
| 1565 | 1635 | |
| 1566 | 1636 | if ($notifyPrefs[$row['id_member']] & 0x01) |
| 1567 | 1637 | { |
@@ -1584,18 +1654,19 @@ discard block |
||
| 1584 | 1654 | } |
| 1585 | 1655 | |
| 1586 | 1656 | // Insert the alerts if any |
| 1587 | - if (!empty($alert_rows)) |
|
| 1588 | - $smcFunc['db_insert']('', |
|
| 1657 | + if (!empty($alert_rows)) { |
|
| 1658 | + $smcFunc['db_insert']('', |
|
| 1589 | 1659 | '{db_prefix}user_alerts', |
| 1590 | 1660 | array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string', |
| 1591 | 1661 | 'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'), |
| 1592 | 1662 | $alert_rows, |
| 1593 | 1663 | array() |
| 1594 | 1664 | ); |
| 1665 | + } |
|
| 1595 | 1666 | |
| 1596 | 1667 | // Mark the reminder as sent. |
| 1597 | - if (!empty($subs_reminded)) |
|
| 1598 | - $smcFunc['db_query']('', ' |
|
| 1668 | + if (!empty($subs_reminded)) { |
|
| 1669 | + $smcFunc['db_query']('', ' |
|
| 1599 | 1670 | UPDATE {db_prefix}log_subscribed |
| 1600 | 1671 | SET reminder_sent = {int:reminder_sent} |
| 1601 | 1672 | WHERE id_sublog IN ({array_int:subscription_list})', |
@@ -1604,6 +1675,7 @@ discard block |
||
| 1604 | 1675 | 'reminder_sent' => 1, |
| 1605 | 1676 | ) |
| 1606 | 1677 | ); |
| 1678 | + } |
|
| 1607 | 1679 | |
| 1608 | 1680 | return true; |
| 1609 | 1681 | } |
@@ -1619,13 +1691,13 @@ discard block |
||
| 1619 | 1691 | // We need to know where this thing is going. |
| 1620 | 1692 | if (!empty($modSettings['currentAttachmentUploadDir'])) |
| 1621 | 1693 | { |
| 1622 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
| 1623 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 1694 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
| 1695 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 1696 | + } |
|
| 1624 | 1697 | |
| 1625 | 1698 | // Just use the current path for temp files. |
| 1626 | 1699 | $attach_dirs = $modSettings['attachmentUploadDir']; |
| 1627 | - } |
|
| 1628 | - else |
|
| 1700 | + } else |
|
| 1629 | 1701 | { |
| 1630 | 1702 | $attach_dirs = array($modSettings['attachmentUploadDir']); |
| 1631 | 1703 | } |
@@ -1644,14 +1716,16 @@ discard block |
||
| 1644 | 1716 | |
| 1645 | 1717 | while ($file = readdir($dir)) |
| 1646 | 1718 | { |
| 1647 | - if ($file == '.' || $file == '..') |
|
| 1648 | - continue; |
|
| 1719 | + if ($file == '.' || $file == '..') { |
|
| 1720 | + continue; |
|
| 1721 | + } |
|
| 1649 | 1722 | |
| 1650 | 1723 | if (strpos($file, 'post_tmp_') !== false) |
| 1651 | 1724 | { |
| 1652 | 1725 | // Temp file is more than 5 hours old! |
| 1653 | - if (filemtime($attach_dir . '/' . $file) < time() - 18000) |
|
| 1654 | - @unlink($attach_dir . '/' . $file); |
|
| 1726 | + if (filemtime($attach_dir . '/' . $file) < time() - 18000) { |
|
| 1727 | + @unlink($attach_dir . '/' . $file); |
|
| 1728 | + } |
|
| 1655 | 1729 | } |
| 1656 | 1730 | } |
| 1657 | 1731 | closedir($dir); |
@@ -1684,8 +1758,9 @@ discard block |
||
| 1684 | 1758 | ) |
| 1685 | 1759 | ); |
| 1686 | 1760 | |
| 1687 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 1688 | - $topics[] = $row[0]; |
|
| 1761 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 1762 | + $topics[] = $row[0]; |
|
| 1763 | + } |
|
| 1689 | 1764 | $smcFunc['db_free_result']($request); |
| 1690 | 1765 | |
| 1691 | 1766 | // Zap, your gone |
@@ -1705,8 +1780,9 @@ discard block |
||
| 1705 | 1780 | { |
| 1706 | 1781 | global $smcFunc, $sourcedir, $modSettings; |
| 1707 | 1782 | |
| 1708 | - if (empty($modSettings['drafts_keep_days'])) |
|
| 1709 | - return true; |
|
| 1783 | + if (empty($modSettings['drafts_keep_days'])) { |
|
| 1784 | + return true; |
|
| 1785 | + } |
|
| 1710 | 1786 | |
| 1711 | 1787 | // init |
| 1712 | 1788 | $drafts = array(); |
@@ -1724,8 +1800,9 @@ discard block |
||
| 1724 | 1800 | ) |
| 1725 | 1801 | ); |
| 1726 | 1802 | |
| 1727 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 1728 | - $drafts[] = (int) $row[0]; |
|
| 1803 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 1804 | + $drafts[] = (int) $row[0]; |
|
| 1805 | + } |
|
| 1729 | 1806 | $smcFunc['db_free_result']($request); |
| 1730 | 1807 | |
| 1731 | 1808 | // If we have old one, remove them |