@@ -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. |
@@ -23,14 +24,15 @@ discard block |
||
| 23 | 24 | { |
| 24 | 25 | global $smcFunc; |
| 25 | 26 | |
| 26 | - if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_query') |
|
| 27 | - $smcFunc += array( |
|
| 27 | + if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_query') { |
|
| 28 | + $smcFunc += array( |
|
| 28 | 29 | 'db_search_query' => 'smf_db_query', |
| 29 | 30 | 'db_search_support' => 'smf_db_search_support', |
| 30 | 31 | 'db_create_word_search' => 'smf_db_create_word_search', |
| 31 | 32 | 'db_support_ignore' => true, |
| 32 | 33 | ); |
| 33 | -} |
|
| 34 | + } |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | /** |
| 36 | 38 | * This function will tell you whether this database type supports this search type. |
@@ -54,12 +56,13 @@ discard block |
||
| 54 | 56 | { |
| 55 | 57 | global $smcFunc; |
| 56 | 58 | |
| 57 | - if ($size == 'small') |
|
| 58 | - $size = 'smallint(5)'; |
|
| 59 | - elseif ($size == 'medium') |
|
| 60 | - $size = 'mediumint(8)'; |
|
| 61 | - else |
|
| 62 | - $size = 'int(10)'; |
|
| 59 | + if ($size == 'small') { |
|
| 60 | + $size = 'smallint(5)'; |
|
| 61 | + } elseif ($size == 'medium') { |
|
| 62 | + $size = 'mediumint(8)'; |
|
| 63 | + } else { |
|
| 64 | + $size = 'int(10)'; |
|
| 65 | + } |
|
| 63 | 66 | |
| 64 | 67 | $smcFunc['db_query']('', ' |
| 65 | 68 | CREATE TABLE {db_prefix}log_search_words ( |
@@ -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 | * Turn off/on notification for a particular board. |
@@ -34,8 +35,9 @@ discard block |
||
| 34 | 35 | is_not_guest(); |
| 35 | 36 | |
| 36 | 37 | // You have to specify a board to turn notifications on! |
| 37 | - if (empty($board)) |
|
| 38 | - fatal_lang_error('no_board', false); |
|
| 38 | + if (empty($board)) { |
|
| 39 | + fatal_lang_error('no_board', false); |
|
| 40 | + } |
|
| 39 | 41 | |
| 40 | 42 | // No subaction: find out what to do. |
| 41 | 43 | if (isset($_GET['mode'])) |
@@ -48,16 +50,16 @@ discard block |
||
| 48 | 50 | require_once($sourcedir . '/Subs-Notify.php'); |
| 49 | 51 | setNotifyPrefs($user_info['id'], array('board_notify_' . $board => $alertPref)); |
| 50 | 52 | |
| 51 | - if ($mode > 1) |
|
| 52 | - // Turn notification on. (note this just blows smoke if it's already on.) |
|
| 53 | + if ($mode > 1) { |
|
| 54 | + // Turn notification on. (note this just blows smoke if it's already on.) |
|
| 53 | 55 | $smcFunc['db_insert']('ignore', |
| 54 | 56 | '{db_prefix}log_notify', |
| 55 | 57 | array('id_member' => 'int', 'id_board' => 'int'), |
| 56 | 58 | array($user_info['id'], $board), |
| 57 | 59 | array('id_member', 'id_board') |
| 58 | 60 | ); |
| 59 | - else |
|
| 60 | - $smcFunc['db_query']('', ' |
|
| 61 | + } else { |
|
| 62 | + $smcFunc['db_query']('', ' |
|
| 61 | 63 | DELETE FROM {db_prefix}log_notify |
| 62 | 64 | WHERE id_member = {int:current_member} |
| 63 | 65 | AND id_board = {int:current_board}', |
@@ -66,6 +68,7 @@ discard block |
||
| 66 | 68 | 'current_member' => $user_info['id'], |
| 67 | 69 | ) |
| 68 | 70 | ); |
| 71 | + } |
|
| 69 | 72 | |
| 70 | 73 | } |
| 71 | 74 | |
@@ -81,10 +84,10 @@ discard block |
||
| 81 | 84 | ), |
| 82 | 85 | ); |
| 83 | 86 | $context['sub_template'] = 'generic_xml'; |
| 87 | + } else { |
|
| 88 | + redirectexit('board=' . $board . '.' . $_REQUEST['start']); |
|
| 89 | + } |
|
| 84 | 90 | } |
| 85 | - else |
|
| 86 | - redirectexit('board=' . $board . '.' . $_REQUEST['start']); |
|
| 87 | -} |
|
| 88 | 91 | |
| 89 | 92 | /** |
| 90 | 93 | * Turn off/on unread replies subscription for a topic as well as sets individual topic's alert preferences |
@@ -108,8 +111,9 @@ discard block |
||
| 108 | 111 | $mode = (int) $_GET['mode']; |
| 109 | 112 | $alertPref = $mode <= 1 ? 0 : ($mode == 2 ? 1 : 3); |
| 110 | 113 | |
| 111 | - if (empty($mode)) |
|
| 112 | - $mode = 1; |
|
| 114 | + if (empty($mode)) { |
|
| 115 | + $mode = 1; |
|
| 116 | + } |
|
| 113 | 117 | |
| 114 | 118 | $request = $smcFunc['db_query']('', ' |
| 115 | 119 | SELECT id_member, id_topic, id_msg, unwatched |
@@ -132,8 +136,7 @@ discard block |
||
| 132 | 136 | 'id_msg' => 0, |
| 133 | 137 | 'unwatched' => empty($mode) ? 1 : 0, |
| 134 | 138 | ); |
| 135 | - } |
|
| 136 | - else |
|
| 139 | + } else |
|
| 137 | 140 | { |
| 138 | 141 | $insert = false; |
| 139 | 142 | $log['unwatched'] = empty($mode) ? 1 : 0; |
@@ -160,9 +163,8 @@ discard block |
||
| 160 | 163 | array($user_info['id'], $log['id_topic']), |
| 161 | 164 | array('id_member', 'id_board') |
| 162 | 165 | ); |
| 163 | - } |
|
| 164 | - else |
|
| 165 | - $smcFunc['db_query']('', ' |
|
| 166 | + } else { |
|
| 167 | + $smcFunc['db_query']('', ' |
|
| 166 | 168 | DELETE FROM {db_prefix}log_notify |
| 167 | 169 | WHERE id_topic = {int:topic} |
| 168 | 170 | AND id_member = {int:member}', |
@@ -170,6 +172,7 @@ discard block |
||
| 170 | 172 | 'topic' => $log['id_topic'], |
| 171 | 173 | 'member' => $user_info['id'], |
| 172 | 174 | )); |
| 175 | + } |
|
| 173 | 176 | |
| 174 | 177 | } |
| 175 | 178 | } |
@@ -186,9 +189,9 @@ discard block |
||
| 186 | 189 | ), |
| 187 | 190 | ); |
| 188 | 191 | $context['sub_template'] = 'generic_xml'; |
| 192 | + } else { |
|
| 193 | + redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
| 194 | + } |
|
| 189 | 195 | } |
| 190 | - else |
|
| 191 | - redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
| 192 | -} |
|
| 193 | 196 | |
| 194 | 197 | ?> |
| 195 | 198 | \ No newline at end of file |
@@ -13,8 +13,9 @@ discard block |
||
| 13 | 13 | * @version 2.1 Beta 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * Update some basic statistics. |
@@ -122,10 +123,11 @@ discard block |
||
| 122 | 123 | $smcFunc['db_free_result']($result); |
| 123 | 124 | |
| 124 | 125 | // Add this to the number of unapproved members |
| 125 | - if (!empty($changes['unapprovedMembers'])) |
|
| 126 | - $changes['unapprovedMembers'] += $coppa_approvals; |
|
| 127 | - else |
|
| 128 | - $changes['unapprovedMembers'] = $coppa_approvals; |
|
| 126 | + if (!empty($changes['unapprovedMembers'])) { |
|
| 127 | + $changes['unapprovedMembers'] += $coppa_approvals; |
|
| 128 | + } else { |
|
| 129 | + $changes['unapprovedMembers'] = $coppa_approvals; |
|
| 130 | + } |
|
| 129 | 131 | } |
| 130 | 132 | } |
| 131 | 133 | } |
@@ -133,9 +135,9 @@ discard block |
||
| 133 | 135 | break; |
| 134 | 136 | |
| 135 | 137 | case 'message': |
| 136 | - if ($parameter1 === true && $parameter2 !== null) |
|
| 137 | - updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
| 138 | - else |
|
| 138 | + if ($parameter1 === true && $parameter2 !== null) { |
|
| 139 | + updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
| 140 | + } else |
|
| 139 | 141 | { |
| 140 | 142 | // SUM and MAX on a smaller table is better for InnoDB tables. |
| 141 | 143 | $result = $smcFunc['db_query']('', ' |
@@ -175,23 +177,25 @@ discard block |
||
| 175 | 177 | $parameter2 = text2words($parameter2); |
| 176 | 178 | |
| 177 | 179 | $inserts = array(); |
| 178 | - foreach ($parameter2 as $word) |
|
| 179 | - $inserts[] = array($word, $parameter1); |
|
| 180 | + foreach ($parameter2 as $word) { |
|
| 181 | + $inserts[] = array($word, $parameter1); |
|
| 182 | + } |
|
| 180 | 183 | |
| 181 | - if (!empty($inserts)) |
|
| 182 | - $smcFunc['db_insert']('ignore', |
|
| 184 | + if (!empty($inserts)) { |
|
| 185 | + $smcFunc['db_insert']('ignore', |
|
| 183 | 186 | '{db_prefix}log_search_subjects', |
| 184 | 187 | array('word' => 'string', 'id_topic' => 'int'), |
| 185 | 188 | $inserts, |
| 186 | 189 | array('word', 'id_topic') |
| 187 | 190 | ); |
| 191 | + } |
|
| 188 | 192 | } |
| 189 | 193 | break; |
| 190 | 194 | |
| 191 | 195 | case 'topic': |
| 192 | - if ($parameter1 === true) |
|
| 193 | - updateSettings(array('totalTopics' => true), true); |
|
| 194 | - else |
|
| 196 | + if ($parameter1 === true) { |
|
| 197 | + updateSettings(array('totalTopics' => true), true); |
|
| 198 | + } else |
|
| 195 | 199 | { |
| 196 | 200 | // Get the number of topics - a SUM is better for InnoDB tables. |
| 197 | 201 | // We also ignore the recycle bin here because there will probably be a bunch of one-post topics there. |
@@ -212,8 +216,9 @@ discard block |
||
| 212 | 216 | |
| 213 | 217 | case 'postgroups': |
| 214 | 218 | // Parameter two is the updated columns: we should check to see if we base groups off any of these. |
| 215 | - if ($parameter2 !== null && !in_array('posts', $parameter2)) |
|
| 216 | - return; |
|
| 219 | + if ($parameter2 !== null && !in_array('posts', $parameter2)) { |
|
| 220 | + return; |
|
| 221 | + } |
|
| 217 | 222 | |
| 218 | 223 | $postgroups = cache_get_data('updateStats:postgroups', 360); |
| 219 | 224 | if ($postgroups == null || $parameter1 == null) |
@@ -228,8 +233,9 @@ discard block |
||
| 228 | 233 | ) |
| 229 | 234 | ); |
| 230 | 235 | $postgroups = array(); |
| 231 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 232 | - $postgroups[$row['id_group']] = $row['min_posts']; |
|
| 236 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 237 | + $postgroups[$row['id_group']] = $row['min_posts']; |
|
| 238 | + } |
|
| 233 | 239 | $smcFunc['db_free_result']($request); |
| 234 | 240 | |
| 235 | 241 | // Sort them this way because if it's done with MySQL it causes a filesort :(. |
@@ -239,8 +245,9 @@ discard block |
||
| 239 | 245 | } |
| 240 | 246 | |
| 241 | 247 | // Oh great, they've screwed their post groups. |
| 242 | - if (empty($postgroups)) |
|
| 243 | - return; |
|
| 248 | + if (empty($postgroups)) { |
|
| 249 | + return; |
|
| 250 | + } |
|
| 244 | 251 | |
| 245 | 252 | // Set all membergroups from most posts to least posts. |
| 246 | 253 | $conditions = ''; |
@@ -298,10 +305,9 @@ discard block |
||
| 298 | 305 | { |
| 299 | 306 | $condition = 'id_member IN ({array_int:members})'; |
| 300 | 307 | $parameters['members'] = $members; |
| 301 | - } |
|
| 302 | - elseif ($members === null) |
|
| 303 | - $condition = '1=1'; |
|
| 304 | - else |
|
| 308 | + } elseif ($members === null) { |
|
| 309 | + $condition = '1=1'; |
|
| 310 | + } else |
|
| 305 | 311 | { |
| 306 | 312 | $condition = 'id_member = {int:member}'; |
| 307 | 313 | $parameters['member'] = $members; |
@@ -341,9 +347,9 @@ discard block |
||
| 341 | 347 | if (count($vars_to_integrate) != 0) |
| 342 | 348 | { |
| 343 | 349 | // Fetch a list of member_names if necessary |
| 344 | - if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) |
|
| 345 | - $member_names = array($user_info['username']); |
|
| 346 | - else |
|
| 350 | + if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) { |
|
| 351 | + $member_names = array($user_info['username']); |
|
| 352 | + } else |
|
| 347 | 353 | { |
| 348 | 354 | $member_names = array(); |
| 349 | 355 | $request = $smcFunc['db_query']('', ' |
@@ -352,14 +358,16 @@ discard block |
||
| 352 | 358 | WHERE ' . $condition, |
| 353 | 359 | $parameters |
| 354 | 360 | ); |
| 355 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 356 | - $member_names[] = $row['member_name']; |
|
| 361 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 362 | + $member_names[] = $row['member_name']; |
|
| 363 | + } |
|
| 357 | 364 | $smcFunc['db_free_result']($request); |
| 358 | 365 | } |
| 359 | 366 | |
| 360 | - if (!empty($member_names)) |
|
| 361 | - foreach ($vars_to_integrate as $var) |
|
| 367 | + if (!empty($member_names)) { |
|
| 368 | + foreach ($vars_to_integrate as $var) |
|
| 362 | 369 | call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats)); |
| 370 | + } |
|
| 363 | 371 | } |
| 364 | 372 | } |
| 365 | 373 | |
@@ -367,16 +375,17 @@ discard block |
||
| 367 | 375 | foreach ($data as $var => $val) |
| 368 | 376 | { |
| 369 | 377 | $type = 'string'; |
| 370 | - if (in_array($var, $knownInts)) |
|
| 371 | - $type = 'int'; |
|
| 372 | - elseif (in_array($var, $knownFloats)) |
|
| 373 | - $type = 'float'; |
|
| 374 | - elseif ($var == 'birthdate') |
|
| 375 | - $type = 'date'; |
|
| 376 | - elseif ($var == 'member_ip') |
|
| 377 | - $type = 'inet'; |
|
| 378 | - elseif ($var == 'member_ip2') |
|
| 379 | - $type = 'inet'; |
|
| 378 | + if (in_array($var, $knownInts)) { |
|
| 379 | + $type = 'int'; |
|
| 380 | + } elseif (in_array($var, $knownFloats)) { |
|
| 381 | + $type = 'float'; |
|
| 382 | + } elseif ($var == 'birthdate') { |
|
| 383 | + $type = 'date'; |
|
| 384 | + } elseif ($var == 'member_ip') { |
|
| 385 | + $type = 'inet'; |
|
| 386 | + } elseif ($var == 'member_ip2') { |
|
| 387 | + $type = 'inet'; |
|
| 388 | + } |
|
| 380 | 389 | |
| 381 | 390 | // Doing an increment? |
| 382 | 391 | if ($type == 'int' && ($val === '+' || $val === '-')) |
@@ -390,8 +399,9 @@ discard block |
||
| 390 | 399 | { |
| 391 | 400 | if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match)) |
| 392 | 401 | { |
| 393 | - if ($match[1] != '+ ') |
|
| 394 | - $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
| 402 | + if ($match[1] != '+ ') { |
|
| 403 | + $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
| 404 | + } |
|
| 395 | 405 | $type = 'raw'; |
| 396 | 406 | } |
| 397 | 407 | } |
@@ -412,8 +422,9 @@ discard block |
||
| 412 | 422 | // Clear any caching? |
| 413 | 423 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members)) |
| 414 | 424 | { |
| 415 | - if (!is_array($members)) |
|
| 416 | - $members = array($members); |
|
| 425 | + if (!is_array($members)) { |
|
| 426 | + $members = array($members); |
|
| 427 | + } |
|
| 417 | 428 | |
| 418 | 429 | foreach ($members as $member) |
| 419 | 430 | { |
@@ -446,29 +457,32 @@ discard block |
||
| 446 | 457 | { |
| 447 | 458 | global $modSettings, $smcFunc; |
| 448 | 459 | |
| 449 | - if (empty($changeArray) || !is_array($changeArray)) |
|
| 450 | - return; |
|
| 460 | + if (empty($changeArray) || !is_array($changeArray)) { |
|
| 461 | + return; |
|
| 462 | + } |
|
| 451 | 463 | |
| 452 | 464 | $toRemove = array(); |
| 453 | 465 | |
| 454 | 466 | // Go check if there is any setting to be removed. |
| 455 | - foreach ($changeArray as $k => $v) |
|
| 456 | - if ($v === null) |
|
| 467 | + foreach ($changeArray as $k => $v) { |
|
| 468 | + if ($v === null) |
|
| 457 | 469 | { |
| 458 | 470 | // Found some, remove them from the original array and add them to ours. |
| 459 | 471 | unset($changeArray[$k]); |
| 472 | + } |
|
| 460 | 473 | $toRemove[] = $k; |
| 461 | 474 | } |
| 462 | 475 | |
| 463 | 476 | // Proceed with the deletion. |
| 464 | - if (!empty($toRemove)) |
|
| 465 | - $smcFunc['db_query']('', ' |
|
| 477 | + if (!empty($toRemove)) { |
|
| 478 | + $smcFunc['db_query']('', ' |
|
| 466 | 479 | DELETE FROM {db_prefix}settings |
| 467 | 480 | WHERE variable IN ({array_string:remove})', |
| 468 | 481 | array( |
| 469 | 482 | 'remove' => $toRemove, |
| 470 | 483 | ) |
| 471 | 484 | ); |
| 485 | + } |
|
| 472 | 486 | |
| 473 | 487 | // In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs. |
| 474 | 488 | if ($update) |
@@ -497,19 +511,22 @@ discard block |
||
| 497 | 511 | foreach ($changeArray as $variable => $value) |
| 498 | 512 | { |
| 499 | 513 | // Don't bother if it's already like that ;). |
| 500 | - if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) |
|
| 501 | - continue; |
|
| 514 | + if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) { |
|
| 515 | + continue; |
|
| 516 | + } |
|
| 502 | 517 | // If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it. |
| 503 | - elseif (!isset($modSettings[$variable]) && empty($value)) |
|
| 504 | - continue; |
|
| 518 | + elseif (!isset($modSettings[$variable]) && empty($value)) { |
|
| 519 | + continue; |
|
| 520 | + } |
|
| 505 | 521 | |
| 506 | 522 | $replaceArray[] = array($variable, $value); |
| 507 | 523 | |
| 508 | 524 | $modSettings[$variable] = $value; |
| 509 | 525 | } |
| 510 | 526 | |
| 511 | - if (empty($replaceArray)) |
|
| 512 | - return; |
|
| 527 | + if (empty($replaceArray)) { |
|
| 528 | + return; |
|
| 529 | + } |
|
| 513 | 530 | |
| 514 | 531 | $smcFunc['db_insert']('replace', |
| 515 | 532 | '{db_prefix}settings', |
@@ -555,14 +572,17 @@ discard block |
||
| 555 | 572 | $start_invalid = $start < 0; |
| 556 | 573 | |
| 557 | 574 | // Make sure $start is a proper variable - not less than 0. |
| 558 | - if ($start_invalid) |
|
| 559 | - $start = 0; |
|
| 575 | + if ($start_invalid) { |
|
| 576 | + $start = 0; |
|
| 577 | + } |
|
| 560 | 578 | // Not greater than the upper bound. |
| 561 | - elseif ($start >= $max_value) |
|
| 562 | - $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
| 579 | + elseif ($start >= $max_value) { |
|
| 580 | + $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
| 581 | + } |
|
| 563 | 582 | // And it has to be a multiple of $num_per_page! |
| 564 | - else |
|
| 565 | - $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
| 583 | + else { |
|
| 584 | + $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
| 585 | + } |
|
| 566 | 586 | |
| 567 | 587 | $context['current_page'] = $start / $num_per_page; |
| 568 | 588 | |
@@ -592,77 +612,87 @@ discard block |
||
| 592 | 612 | |
| 593 | 613 | // Show all the pages. |
| 594 | 614 | $display_page = 1; |
| 595 | - for ($counter = 0; $counter < $max_value; $counter += $num_per_page) |
|
| 596 | - $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
| 615 | + for ($counter = 0; $counter < $max_value; $counter += $num_per_page) { |
|
| 616 | + $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
| 617 | + } |
|
| 597 | 618 | |
| 598 | 619 | // Show the right arrow. |
| 599 | 620 | $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page); |
| 600 | - if ($start != $counter - $max_value && !$start_invalid) |
|
| 601 | - $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
| 602 | - } |
|
| 603 | - else |
|
| 621 | + if ($start != $counter - $max_value && !$start_invalid) { |
|
| 622 | + $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
| 623 | + } |
|
| 624 | + } else |
|
| 604 | 625 | { |
| 605 | 626 | // If they didn't enter an odd value, pretend they did. |
| 606 | 627 | $PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2; |
| 607 | 628 | |
| 608 | 629 | // Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page) |
| 609 | - if (!empty($start) && $show_prevnext) |
|
| 610 | - $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
| 611 | - else |
|
| 612 | - $pageindex .= ''; |
|
| 630 | + if (!empty($start) && $show_prevnext) { |
|
| 631 | + $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
| 632 | + } else { |
|
| 633 | + $pageindex .= ''; |
|
| 634 | + } |
|
| 613 | 635 | |
| 614 | 636 | // Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15) |
| 615 | - if ($start > $num_per_page * $PageContiguous) |
|
| 616 | - $pageindex .= sprintf($base_link, 0, '1'); |
|
| 637 | + if ($start > $num_per_page * $PageContiguous) { |
|
| 638 | + $pageindex .= sprintf($base_link, 0, '1'); |
|
| 639 | + } |
|
| 617 | 640 | |
| 618 | 641 | // Show the ... after the first page. (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page) |
| 619 | - if ($start > $num_per_page * ($PageContiguous + 1)) |
|
| 620 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 642 | + if ($start > $num_per_page * ($PageContiguous + 1)) { |
|
| 643 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 621 | 644 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
| 622 | 645 | '{FIRST_PAGE}' => $num_per_page, |
| 623 | 646 | '{LAST_PAGE}' => $start - $num_per_page * $PageContiguous, |
| 624 | 647 | '{PER_PAGE}' => $num_per_page, |
| 625 | 648 | )); |
| 649 | + } |
|
| 626 | 650 | |
| 627 | 651 | // Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page) |
| 628 | - for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) |
|
| 629 | - if ($start >= $num_per_page * $nCont) |
|
| 652 | + for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) { |
|
| 653 | + if ($start >= $num_per_page * $nCont) |
|
| 630 | 654 | { |
| 631 | 655 | $tmpStart = $start - $num_per_page * $nCont; |
| 656 | + } |
|
| 632 | 657 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
| 633 | 658 | } |
| 634 | 659 | |
| 635 | 660 | // Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page) |
| 636 | - if (!$start_invalid) |
|
| 637 | - $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
| 638 | - else |
|
| 639 | - $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
| 661 | + if (!$start_invalid) { |
|
| 662 | + $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
| 663 | + } else { |
|
| 664 | + $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
| 665 | + } |
|
| 640 | 666 | |
| 641 | 667 | // Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page) |
| 642 | 668 | $tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page; |
| 643 | - for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) |
|
| 644 | - if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
| 669 | + for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) { |
|
| 670 | + if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
| 645 | 671 | { |
| 646 | 672 | $tmpStart = $start + $num_per_page * $nCont; |
| 673 | + } |
|
| 647 | 674 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
| 648 | 675 | } |
| 649 | 676 | |
| 650 | 677 | // Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page) |
| 651 | - if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) |
|
| 652 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 678 | + if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) { |
|
| 679 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
| 653 | 680 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
| 654 | 681 | '{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1), |
| 655 | 682 | '{LAST_PAGE}' => $tmpMaxPages, |
| 656 | 683 | '{PER_PAGE}' => $num_per_page, |
| 657 | 684 | )); |
| 685 | + } |
|
| 658 | 686 | |
| 659 | 687 | // Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15< next page) |
| 660 | - if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) |
|
| 661 | - $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
| 688 | + if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) { |
|
| 689 | + $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
| 690 | + } |
|
| 662 | 691 | |
| 663 | 692 | // Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<) |
| 664 | - if ($start != $tmpMaxPages && $show_prevnext) |
|
| 665 | - $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
| 693 | + if ($start != $tmpMaxPages && $show_prevnext) { |
|
| 694 | + $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
| 695 | + } |
|
| 666 | 696 | } |
| 667 | 697 | $pageindex .= $settings['page_index']['extra_after']; |
| 668 | 698 | |
@@ -688,8 +718,9 @@ discard block |
||
| 688 | 718 | if ($decimal_separator === null) |
| 689 | 719 | { |
| 690 | 720 | // Not set for whatever reason? |
| 691 | - if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) |
|
| 692 | - return $number; |
|
| 721 | + if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) { |
|
| 722 | + return $number; |
|
| 723 | + } |
|
| 693 | 724 | |
| 694 | 725 | // Cache these each load... |
| 695 | 726 | $thousands_separator = $matches[1]; |
@@ -721,17 +752,20 @@ discard block |
||
| 721 | 752 | static $non_twelve_hour; |
| 722 | 753 | |
| 723 | 754 | // Offset the time. |
| 724 | - if (!$offset_type) |
|
| 725 | - $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
| 755 | + if (!$offset_type) { |
|
| 756 | + $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
| 757 | + } |
|
| 726 | 758 | // Just the forum offset? |
| 727 | - elseif ($offset_type == 'forum') |
|
| 728 | - $time = $log_time + $modSettings['time_offset'] * 3600; |
|
| 729 | - else |
|
| 730 | - $time = $log_time; |
|
| 759 | + elseif ($offset_type == 'forum') { |
|
| 760 | + $time = $log_time + $modSettings['time_offset'] * 3600; |
|
| 761 | + } else { |
|
| 762 | + $time = $log_time; |
|
| 763 | + } |
|
| 731 | 764 | |
| 732 | 765 | // We can't have a negative date (on Windows, at least.) |
| 733 | - if ($log_time < 0) |
|
| 734 | - $log_time = 0; |
|
| 766 | + if ($log_time < 0) { |
|
| 767 | + $log_time = 0; |
|
| 768 | + } |
|
| 735 | 769 | |
| 736 | 770 | // Today and Yesterday? |
| 737 | 771 | if ($modSettings['todayMod'] >= 1 && $show_today === true) |
@@ -748,46 +782,53 @@ discard block |
||
| 748 | 782 | { |
| 749 | 783 | $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l'; |
| 750 | 784 | $today_fmt = $h . ':%M' . $s . ' %p'; |
| 785 | + } else { |
|
| 786 | + $today_fmt = '%H:%M' . $s; |
|
| 751 | 787 | } |
| 752 | - else |
|
| 753 | - $today_fmt = '%H:%M' . $s; |
|
| 754 | 788 | |
| 755 | 789 | // Same day of the year, same year.... Today! |
| 756 | - if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) |
|
| 757 | - return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 790 | + if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) { |
|
| 791 | + return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 792 | + } |
|
| 758 | 793 | |
| 759 | 794 | // Day-of-year is one less and same year, or it's the first of the year and that's the last of the year... |
| 760 | - if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) |
|
| 761 | - return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 795 | + if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) { |
|
| 796 | + return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
| 797 | + } |
|
| 762 | 798 | } |
| 763 | 799 | |
| 764 | 800 | $str = !is_bool($show_today) ? $show_today : $user_info['time_format']; |
| 765 | 801 | |
| 766 | 802 | if (setlocale(LC_TIME, $txt['lang_locale'])) |
| 767 | 803 | { |
| 768 | - if (!isset($non_twelve_hour)) |
|
| 769 | - $non_twelve_hour = trim(strftime('%p')) === ''; |
|
| 770 | - if ($non_twelve_hour && strpos($str, '%p') !== false) |
|
| 771 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 804 | + if (!isset($non_twelve_hour)) { |
|
| 805 | + $non_twelve_hour = trim(strftime('%p')) === ''; |
|
| 806 | + } |
|
| 807 | + if ($non_twelve_hour && strpos($str, '%p') !== false) { |
|
| 808 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 809 | + } |
|
| 772 | 810 | |
| 773 | - foreach (array('%a', '%A', '%b', '%B') as $token) |
|
| 774 | - if (strpos($str, $token) !== false) |
|
| 811 | + foreach (array('%a', '%A', '%b', '%B') as $token) { |
|
| 812 | + if (strpos($str, $token) !== false) |
|
| 775 | 813 | $str = str_replace($token, strftime($token, $time), $str); |
| 776 | - } |
|
| 777 | - else |
|
| 814 | + } |
|
| 815 | + } else |
|
| 778 | 816 | { |
| 779 | 817 | // Do-it-yourself time localization. Fun. |
| 780 | - foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) |
|
| 781 | - if (strpos($str, $token) !== false) |
|
| 818 | + foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) { |
|
| 819 | + if (strpos($str, $token) !== false) |
|
| 782 | 820 | $str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str); |
| 821 | + } |
|
| 783 | 822 | |
| 784 | - if (strpos($str, '%p') !== false) |
|
| 785 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 823 | + if (strpos($str, '%p') !== false) { |
|
| 824 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
| 825 | + } |
|
| 786 | 826 | } |
| 787 | 827 | |
| 788 | 828 | // Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that. |
| 789 | - if ($context['server']['is_windows'] && strpos($str, '%e') !== false) |
|
| 790 | - $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
| 829 | + if ($context['server']['is_windows'] && strpos($str, '%e') !== false) { |
|
| 830 | + $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
| 831 | + } |
|
| 791 | 832 | |
| 792 | 833 | // Format any other characters.. |
| 793 | 834 | return strftime($str, $time); |
@@ -809,16 +850,19 @@ discard block |
||
| 809 | 850 | static $translation = array(); |
| 810 | 851 | |
| 811 | 852 | // Determine the character set... Default to UTF-8 |
| 812 | - if (empty($context['character_set'])) |
|
| 813 | - $charset = 'UTF-8'; |
|
| 853 | + if (empty($context['character_set'])) { |
|
| 854 | + $charset = 'UTF-8'; |
|
| 855 | + } |
|
| 814 | 856 | // Use ISO-8859-1 in place of non-supported ISO-8859 charsets... |
| 815 | - elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) |
|
| 816 | - $charset = 'ISO-8859-1'; |
|
| 817 | - else |
|
| 818 | - $charset = $context['character_set']; |
|
| 857 | + elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) { |
|
| 858 | + $charset = 'ISO-8859-1'; |
|
| 859 | + } else { |
|
| 860 | + $charset = $context['character_set']; |
|
| 861 | + } |
|
| 819 | 862 | |
| 820 | - if (empty($translation)) |
|
| 821 | - $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
| 863 | + if (empty($translation)) { |
|
| 864 | + $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
| 865 | + } |
|
| 822 | 866 | |
| 823 | 867 | return strtr($string, $translation); |
| 824 | 868 | } |
@@ -840,8 +884,9 @@ discard block |
||
| 840 | 884 | global $smcFunc; |
| 841 | 885 | |
| 842 | 886 | // It was already short enough! |
| 843 | - if ($smcFunc['strlen']($subject) <= $len) |
|
| 844 | - return $subject; |
|
| 887 | + if ($smcFunc['strlen']($subject) <= $len) { |
|
| 888 | + return $subject; |
|
| 889 | + } |
|
| 845 | 890 | |
| 846 | 891 | // Shorten it by the length it was too long, and strip off junk from the end. |
| 847 | 892 | return $smcFunc['substr']($subject, 0, $len) . '...'; |
@@ -860,10 +905,11 @@ discard block |
||
| 860 | 905 | { |
| 861 | 906 | global $user_info, $modSettings; |
| 862 | 907 | |
| 863 | - if ($timestamp === null) |
|
| 864 | - $timestamp = time(); |
|
| 865 | - elseif ($timestamp == 0) |
|
| 866 | - return 0; |
|
| 908 | + if ($timestamp === null) { |
|
| 909 | + $timestamp = time(); |
|
| 910 | + } elseif ($timestamp == 0) { |
|
| 911 | + return 0; |
|
| 912 | + } |
|
| 867 | 913 | |
| 868 | 914 | return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600; |
| 869 | 915 | } |
@@ -892,8 +938,9 @@ discard block |
||
| 892 | 938 | $array[$i] = $array[$j]; |
| 893 | 939 | $array[$j] = $temp; |
| 894 | 940 | |
| 895 | - for ($i = 1; $p[$i] == 0; $i++) |
|
| 896 | - $p[$i] = 1; |
|
| 941 | + for ($i = 1; $p[$i] == 0; $i++) { |
|
| 942 | + $p[$i] = 1; |
|
| 943 | + } |
|
| 897 | 944 | |
| 898 | 945 | $orders[] = $array; |
| 899 | 946 | } |
@@ -925,12 +972,14 @@ discard block |
||
| 925 | 972 | static $disabled; |
| 926 | 973 | |
| 927 | 974 | // Don't waste cycles |
| 928 | - if ($message === '') |
|
| 929 | - return ''; |
|
| 975 | + if ($message === '') { |
|
| 976 | + return ''; |
|
| 977 | + } |
|
| 930 | 978 | |
| 931 | 979 | // Just in case it wasn't determined yet whether UTF-8 is enabled. |
| 932 | - if (!isset($context['utf8'])) |
|
| 933 | - $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
| 980 | + if (!isset($context['utf8'])) { |
|
| 981 | + $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
| 982 | + } |
|
| 934 | 983 | |
| 935 | 984 | // Clean up any cut/paste issues we may have |
| 936 | 985 | $message = sanitizeMSCutPaste($message); |
@@ -942,13 +991,15 @@ discard block |
||
| 942 | 991 | return $message; |
| 943 | 992 | } |
| 944 | 993 | |
| 945 | - if ($smileys !== null && ($smileys == '1' || $smileys == '0')) |
|
| 946 | - $smileys = (bool) $smileys; |
|
| 994 | + if ($smileys !== null && ($smileys == '1' || $smileys == '0')) { |
|
| 995 | + $smileys = (bool) $smileys; |
|
| 996 | + } |
|
| 947 | 997 | |
| 948 | 998 | if (empty($modSettings['enableBBC']) && $message !== false) |
| 949 | 999 | { |
| 950 | - if ($smileys === true) |
|
| 951 | - parsesmileys($message); |
|
| 1000 | + if ($smileys === true) { |
|
| 1001 | + parsesmileys($message); |
|
| 1002 | + } |
|
| 952 | 1003 | |
| 953 | 1004 | return $message; |
| 954 | 1005 | } |
@@ -961,8 +1012,9 @@ discard block |
||
| 961 | 1012 | } |
| 962 | 1013 | |
| 963 | 1014 | // Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker |
| 964 | - if (!empty($modSettings['autoLinkUrls'])) |
|
| 965 | - set_tld_regex(); |
|
| 1015 | + if (!empty($modSettings['autoLinkUrls'])) { |
|
| 1016 | + set_tld_regex(); |
|
| 1017 | + } |
|
| 966 | 1018 | |
| 967 | 1019 | // Allow mods access before entering the main parse_bbc loop |
| 968 | 1020 | call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
@@ -976,12 +1028,14 @@ discard block |
||
| 976 | 1028 | |
| 977 | 1029 | $temp = explode(',', strtolower($modSettings['disabledBBC'])); |
| 978 | 1030 | |
| 979 | - foreach ($temp as $tag) |
|
| 980 | - $disabled[trim($tag)] = true; |
|
| 1031 | + foreach ($temp as $tag) { |
|
| 1032 | + $disabled[trim($tag)] = true; |
|
| 1033 | + } |
|
| 981 | 1034 | } |
| 982 | 1035 | |
| 983 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
| 984 | - $disabled['flash'] = true; |
|
| 1036 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
| 1037 | + $disabled['flash'] = true; |
|
| 1038 | + } |
|
| 985 | 1039 | |
| 986 | 1040 | /* The following bbc are formatted as an array, with keys as follows: |
| 987 | 1041 | |
@@ -1102,8 +1156,9 @@ discard block |
||
| 1102 | 1156 | $returnContext = ''; |
| 1103 | 1157 | |
| 1104 | 1158 | // BBC or the entire attachments feature is disabled |
| 1105 | - if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) |
|
| 1106 | - return $data; |
|
| 1159 | + if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) { |
|
| 1160 | + return $data; |
|
| 1161 | + } |
|
| 1107 | 1162 | |
| 1108 | 1163 | // Save the attach ID. |
| 1109 | 1164 | $attachID = $data; |
@@ -1114,8 +1169,9 @@ discard block |
||
| 1114 | 1169 | $currentAttachment = parseAttachBBC($attachID); |
| 1115 | 1170 | |
| 1116 | 1171 | // parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do. |
| 1117 | - if (is_string($currentAttachment)) |
|
| 1118 | - return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
| 1172 | + if (is_string($currentAttachment)) { |
|
| 1173 | + return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
| 1174 | + } |
|
| 1119 | 1175 | |
| 1120 | 1176 | if (!empty($currentAttachment['is_image'])) |
| 1121 | 1177 | { |
@@ -1131,15 +1187,17 @@ discard block |
||
| 1131 | 1187 | $height = ' height="' . $currentAttachment['height'] . '"'; |
| 1132 | 1188 | } |
| 1133 | 1189 | |
| 1134 | - if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) |
|
| 1135 | - $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '" alt="' . $currentAttachment['name'] . '" id="thumb_'. $currentAttachment['id']. '"></a>'; |
|
| 1136 | - else |
|
| 1137 | - $returnContext .= '<img src="' . $currentAttachment['href'] . ';image" alt="' . $currentAttachment['name'] . '"' . $width . $height . '/>'; |
|
| 1190 | + if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) { |
|
| 1191 | + $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '" alt="' . $currentAttachment['name'] . '" id="thumb_'. $currentAttachment['id']. '"></a>'; |
|
| 1192 | + } else { |
|
| 1193 | + $returnContext .= '<img src="' . $currentAttachment['href'] . ';image" alt="' . $currentAttachment['name'] . '"' . $width . $height . '/>'; |
|
| 1194 | + } |
|
| 1138 | 1195 | } |
| 1139 | 1196 | |
| 1140 | 1197 | // No image. Show a link. |
| 1141 | - else |
|
| 1142 | - $returnContext .= $currentAttachment['link']; |
|
| 1198 | + else { |
|
| 1199 | + $returnContext .= $currentAttachment['link']; |
|
| 1200 | + } |
|
| 1143 | 1201 | |
| 1144 | 1202 | // Gotta append what we just did. |
| 1145 | 1203 | $data = $returnContext; |
@@ -1170,8 +1228,9 @@ discard block |
||
| 1170 | 1228 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
| 1171 | 1229 | { |
| 1172 | 1230 | // Do PHP code coloring? |
| 1173 | - if ($php_parts[$php_i] != '<?php') |
|
| 1174 | - continue; |
|
| 1231 | + if ($php_parts[$php_i] != '<?php') { |
|
| 1232 | + continue; |
|
| 1233 | + } |
|
| 1175 | 1234 | |
| 1176 | 1235 | $php_string = ''; |
| 1177 | 1236 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1187,8 +1246,9 @@ discard block |
||
| 1187 | 1246 | $data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data); |
| 1188 | 1247 | |
| 1189 | 1248 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
| 1190 | - if ($context['browser']['is_opera']) |
|
| 1191 | - $data .= ' '; |
|
| 1249 | + if ($context['browser']['is_opera']) { |
|
| 1250 | + $data .= ' '; |
|
| 1251 | + } |
|
| 1192 | 1252 | } |
| 1193 | 1253 | }, |
| 1194 | 1254 | 'block_level' => true, |
@@ -1207,8 +1267,9 @@ discard block |
||
| 1207 | 1267 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
| 1208 | 1268 | { |
| 1209 | 1269 | // Do PHP code coloring? |
| 1210 | - if ($php_parts[$php_i] != '<?php') |
|
| 1211 | - continue; |
|
| 1270 | + if ($php_parts[$php_i] != '<?php') { |
|
| 1271 | + continue; |
|
| 1272 | + } |
|
| 1212 | 1273 | |
| 1213 | 1274 | $php_string = ''; |
| 1214 | 1275 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1224,8 +1285,9 @@ discard block |
||
| 1224 | 1285 | $data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]); |
| 1225 | 1286 | |
| 1226 | 1287 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
| 1227 | - if ($context['browser']['is_opera']) |
|
| 1228 | - $data[0] .= ' '; |
|
| 1288 | + if ($context['browser']['is_opera']) { |
|
| 1289 | + $data[0] .= ' '; |
|
| 1290 | + } |
|
| 1229 | 1291 | } |
| 1230 | 1292 | }, |
| 1231 | 1293 | 'block_level' => true, |
@@ -1263,11 +1325,13 @@ discard block |
||
| 1263 | 1325 | 'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">', |
| 1264 | 1326 | 'validate' => function (&$tag, &$data, $disabled) |
| 1265 | 1327 | { |
| 1266 | - if (isset($disabled['url'])) |
|
| 1267 | - $tag['content'] = '$1'; |
|
| 1328 | + if (isset($disabled['url'])) { |
|
| 1329 | + $tag['content'] = '$1'; |
|
| 1330 | + } |
|
| 1268 | 1331 | $scheme = parse_url($data[0], PHP_URL_SCHEME); |
| 1269 | - if (empty($scheme)) |
|
| 1270 | - $data[0] = '//' . ltrim($data[0], ':/'); |
|
| 1332 | + if (empty($scheme)) { |
|
| 1333 | + $data[0] = '//' . ltrim($data[0], ':/'); |
|
| 1334 | + } |
|
| 1271 | 1335 | }, |
| 1272 | 1336 | 'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>', |
| 1273 | 1337 | ), |
@@ -1314,14 +1378,16 @@ discard block |
||
| 1314 | 1378 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1315 | 1379 | if ($image_proxy_enabled) |
| 1316 | 1380 | { |
| 1317 | - if (empty($scheme)) |
|
| 1318 | - $data = 'http://' . ltrim($data, ':/'); |
|
| 1381 | + if (empty($scheme)) { |
|
| 1382 | + $data = 'http://' . ltrim($data, ':/'); |
|
| 1383 | + } |
|
| 1319 | 1384 | |
| 1320 | - if ($scheme != 'https') |
|
| 1321 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1385 | + if ($scheme != 'https') { |
|
| 1386 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1387 | + } |
|
| 1388 | + } elseif (empty($scheme)) { |
|
| 1389 | + $data = '//' . ltrim($data, ':/'); |
|
| 1322 | 1390 | } |
| 1323 | - elseif (empty($scheme)) |
|
| 1324 | - $data = '//' . ltrim($data, ':/'); |
|
| 1325 | 1391 | }, |
| 1326 | 1392 | 'disabled_content' => '($1)', |
| 1327 | 1393 | ), |
@@ -1337,14 +1403,16 @@ discard block |
||
| 1337 | 1403 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1338 | 1404 | if ($image_proxy_enabled) |
| 1339 | 1405 | { |
| 1340 | - if (empty($scheme)) |
|
| 1341 | - $data = 'http://' . ltrim($data, ':/'); |
|
| 1406 | + if (empty($scheme)) { |
|
| 1407 | + $data = 'http://' . ltrim($data, ':/'); |
|
| 1408 | + } |
|
| 1342 | 1409 | |
| 1343 | - if ($scheme != 'https') |
|
| 1344 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1410 | + if ($scheme != 'https') { |
|
| 1411 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
| 1412 | + } |
|
| 1413 | + } elseif (empty($scheme)) { |
|
| 1414 | + $data = '//' . ltrim($data, ':/'); |
|
| 1345 | 1415 | } |
| 1346 | - elseif (empty($scheme)) |
|
| 1347 | - $data = '//' . ltrim($data, ':/'); |
|
| 1348 | 1416 | }, |
| 1349 | 1417 | 'disabled_content' => '($1)', |
| 1350 | 1418 | ), |
@@ -1356,8 +1424,9 @@ discard block |
||
| 1356 | 1424 | { |
| 1357 | 1425 | $data = strtr($data, array('<br>' => '')); |
| 1358 | 1426 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1359 | - if (empty($scheme)) |
|
| 1360 | - $data = '//' . ltrim($data, ':/'); |
|
| 1427 | + if (empty($scheme)) { |
|
| 1428 | + $data = '//' . ltrim($data, ':/'); |
|
| 1429 | + } |
|
| 1361 | 1430 | }, |
| 1362 | 1431 | ), |
| 1363 | 1432 | array( |
@@ -1368,13 +1437,14 @@ discard block |
||
| 1368 | 1437 | 'after' => '</a>', |
| 1369 | 1438 | 'validate' => function (&$tag, &$data, $disabled) |
| 1370 | 1439 | { |
| 1371 | - if (substr($data, 0, 1) == '#') |
|
| 1372 | - $data = '#post_' . substr($data, 1); |
|
| 1373 | - else |
|
| 1440 | + if (substr($data, 0, 1) == '#') { |
|
| 1441 | + $data = '#post_' . substr($data, 1); |
|
| 1442 | + } else |
|
| 1374 | 1443 | { |
| 1375 | 1444 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1376 | - if (empty($scheme)) |
|
| 1377 | - $data = '//' . ltrim($data, ':/'); |
|
| 1445 | + if (empty($scheme)) { |
|
| 1446 | + $data = '//' . ltrim($data, ':/'); |
|
| 1447 | + } |
|
| 1378 | 1448 | } |
| 1379 | 1449 | }, |
| 1380 | 1450 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
@@ -1452,8 +1522,9 @@ discard block |
||
| 1452 | 1522 | { |
| 1453 | 1523 | $add_begin = substr(trim($data), 0, 5) != '<?'; |
| 1454 | 1524 | $data = highlight_php_code($add_begin ? '<?php ' . $data . '?>' : $data); |
| 1455 | - if ($add_begin) |
|
| 1456 | - $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
| 1525 | + if ($add_begin) { |
|
| 1526 | + $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
| 1527 | + } |
|
| 1457 | 1528 | } |
| 1458 | 1529 | }, |
| 1459 | 1530 | 'block_level' => false, |
@@ -1584,10 +1655,11 @@ discard block |
||
| 1584 | 1655 | 'content' => '$1', |
| 1585 | 1656 | 'validate' => function (&$tag, &$data, $disabled) |
| 1586 | 1657 | { |
| 1587 | - if (is_numeric($data)) |
|
| 1588 | - $data = timeformat($data); |
|
| 1589 | - else |
|
| 1590 | - $tag['content'] = '[time]$1[/time]'; |
|
| 1658 | + if (is_numeric($data)) { |
|
| 1659 | + $data = timeformat($data); |
|
| 1660 | + } else { |
|
| 1661 | + $tag['content'] = '[time]$1[/time]'; |
|
| 1662 | + } |
|
| 1591 | 1663 | }, |
| 1592 | 1664 | ), |
| 1593 | 1665 | array( |
@@ -1614,8 +1686,9 @@ discard block |
||
| 1614 | 1686 | { |
| 1615 | 1687 | $data = strtr($data, array('<br>' => '')); |
| 1616 | 1688 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1617 | - if (empty($scheme)) |
|
| 1618 | - $data = '//' . ltrim($data, ':/'); |
|
| 1689 | + if (empty($scheme)) { |
|
| 1690 | + $data = '//' . ltrim($data, ':/'); |
|
| 1691 | + } |
|
| 1619 | 1692 | }, |
| 1620 | 1693 | ), |
| 1621 | 1694 | array( |
@@ -1627,8 +1700,9 @@ discard block |
||
| 1627 | 1700 | 'validate' => function (&$tag, &$data, $disabled) |
| 1628 | 1701 | { |
| 1629 | 1702 | $scheme = parse_url($data, PHP_URL_SCHEME); |
| 1630 | - if (empty($scheme)) |
|
| 1631 | - $data = '//' . ltrim($data, ':/'); |
|
| 1703 | + if (empty($scheme)) { |
|
| 1704 | + $data = '//' . ltrim($data, ':/'); |
|
| 1705 | + } |
|
| 1632 | 1706 | }, |
| 1633 | 1707 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
| 1634 | 1708 | 'disabled_after' => ' ($1)', |
@@ -1648,8 +1722,9 @@ discard block |
||
| 1648 | 1722 | // This is mainly for the bbc manager, so it's easy to add tags above. Custom BBC should be added above this line. |
| 1649 | 1723 | if ($message === false) |
| 1650 | 1724 | { |
| 1651 | - if (isset($temp_bbc)) |
|
| 1652 | - $bbc_codes = $temp_bbc; |
|
| 1725 | + if (isset($temp_bbc)) { |
|
| 1726 | + $bbc_codes = $temp_bbc; |
|
| 1727 | + } |
|
| 1653 | 1728 | usort($codes, function ($a, $b) { |
| 1654 | 1729 | return strcmp($a['tag'], $b['tag']); |
| 1655 | 1730 | }); |
@@ -1669,8 +1744,9 @@ discard block |
||
| 1669 | 1744 | ); |
| 1670 | 1745 | if (!isset($disabled['li']) && !isset($disabled['list'])) |
| 1671 | 1746 | { |
| 1672 | - foreach ($itemcodes as $c => $dummy) |
|
| 1673 | - $bbc_codes[$c] = array(); |
|
| 1747 | + foreach ($itemcodes as $c => $dummy) { |
|
| 1748 | + $bbc_codes[$c] = array(); |
|
| 1749 | + } |
|
| 1674 | 1750 | } |
| 1675 | 1751 | |
| 1676 | 1752 | // Shhhh! |
@@ -1691,12 +1767,14 @@ discard block |
||
| 1691 | 1767 | foreach ($codes as $code) |
| 1692 | 1768 | { |
| 1693 | 1769 | // Make it easier to process parameters later |
| 1694 | - if (!empty($code['parameters'])) |
|
| 1695 | - ksort($code['parameters'], SORT_STRING); |
|
| 1770 | + if (!empty($code['parameters'])) { |
|
| 1771 | + ksort($code['parameters'], SORT_STRING); |
|
| 1772 | + } |
|
| 1696 | 1773 | |
| 1697 | 1774 | // If we are not doing every tag only do ones we are interested in. |
| 1698 | - if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) |
|
| 1699 | - $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
| 1775 | + if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) { |
|
| 1776 | + $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
| 1777 | + } |
|
| 1700 | 1778 | } |
| 1701 | 1779 | $codes = null; |
| 1702 | 1780 | } |
@@ -1707,8 +1785,9 @@ discard block |
||
| 1707 | 1785 | // It's likely this will change if the message is modified. |
| 1708 | 1786 | $cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . json_encode($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']); |
| 1709 | 1787 | |
| 1710 | - if (($temp = cache_get_data($cache_key, 240)) != null) |
|
| 1711 | - return $temp; |
|
| 1788 | + if (($temp = cache_get_data($cache_key, 240)) != null) { |
|
| 1789 | + return $temp; |
|
| 1790 | + } |
|
| 1712 | 1791 | |
| 1713 | 1792 | $cache_t = microtime(); |
| 1714 | 1793 | } |
@@ -1740,8 +1819,9 @@ discard block |
||
| 1740 | 1819 | $disabled['flash'] = true; |
| 1741 | 1820 | |
| 1742 | 1821 | // @todo Change maybe? |
| 1743 | - if (!isset($_GET['images'])) |
|
| 1744 | - $disabled['img'] = true; |
|
| 1822 | + if (!isset($_GET['images'])) { |
|
| 1823 | + $disabled['img'] = true; |
|
| 1824 | + } |
|
| 1745 | 1825 | |
| 1746 | 1826 | // @todo Interface/setting to add more? |
| 1747 | 1827 | } |
@@ -1767,8 +1847,9 @@ discard block |
||
| 1767 | 1847 | $pos = isset($matches[0][1]) ? $matches[0][1] : false; |
| 1768 | 1848 | |
| 1769 | 1849 | // Failsafe. |
| 1770 | - if ($pos === false || $last_pos > $pos) |
|
| 1771 | - $pos = strlen($message) + 1; |
|
| 1850 | + if ($pos === false || $last_pos > $pos) { |
|
| 1851 | + $pos = strlen($message) + 1; |
|
| 1852 | + } |
|
| 1772 | 1853 | |
| 1773 | 1854 | // Can't have a one letter smiley, URL, or email! (sorry.) |
| 1774 | 1855 | if ($last_pos < $pos - 1) |
@@ -1787,8 +1868,9 @@ discard block |
||
| 1787 | 1868 | |
| 1788 | 1869 | // <br> should be empty. |
| 1789 | 1870 | $empty_tags = array('br', 'hr'); |
| 1790 | - foreach ($empty_tags as $tag) |
|
| 1791 | - $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
| 1871 | + foreach ($empty_tags as $tag) { |
|
| 1872 | + $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
| 1873 | + } |
|
| 1792 | 1874 | |
| 1793 | 1875 | // b, u, i, s, pre... basic tags. |
| 1794 | 1876 | $closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote'); |
@@ -1797,8 +1879,9 @@ discard block |
||
| 1797 | 1879 | $diff = substr_count($data, '<' . $tag . '>') - substr_count($data, '</' . $tag . '>'); |
| 1798 | 1880 | $data = strtr($data, array('<' . $tag . '>' => '<' . $tag . '>', '</' . $tag . '>' => '</' . $tag . '>')); |
| 1799 | 1881 | |
| 1800 | - if ($diff > 0) |
|
| 1801 | - $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
| 1882 | + if ($diff > 0) { |
|
| 1883 | + $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
| 1884 | + } |
|
| 1802 | 1885 | } |
| 1803 | 1886 | |
| 1804 | 1887 | // Do <img ...> - with security... action= -> action-. |
@@ -1811,8 +1894,9 @@ discard block |
||
| 1811 | 1894 | $alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^"|"$~', '', $matches[3][$match]); |
| 1812 | 1895 | |
| 1813 | 1896 | // Remove action= from the URL - no funny business, now. |
| 1814 | - if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) |
|
| 1815 | - $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
| 1897 | + if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) { |
|
| 1898 | + $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
| 1899 | + } |
|
| 1816 | 1900 | |
| 1817 | 1901 | // Check if the image is larger than allowed. |
| 1818 | 1902 | if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height'])) |
@@ -1833,9 +1917,9 @@ discard block |
||
| 1833 | 1917 | |
| 1834 | 1918 | // Set the new image tag. |
| 1835 | 1919 | $replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]'; |
| 1920 | + } else { |
|
| 1921 | + $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
| 1836 | 1922 | } |
| 1837 | - else |
|
| 1838 | - $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
| 1839 | 1923 | } |
| 1840 | 1924 | |
| 1841 | 1925 | $data = strtr($data, $replaces); |
@@ -1848,16 +1932,18 @@ discard block |
||
| 1848 | 1932 | $no_autolink_area = false; |
| 1849 | 1933 | if (!empty($open_tags)) |
| 1850 | 1934 | { |
| 1851 | - foreach ($open_tags as $open_tag) |
|
| 1852 | - if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
| 1935 | + foreach ($open_tags as $open_tag) { |
|
| 1936 | + if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
| 1853 | 1937 | $no_autolink_area = true; |
| 1938 | + } |
|
| 1854 | 1939 | } |
| 1855 | 1940 | |
| 1856 | 1941 | // Don't go backwards. |
| 1857 | 1942 | // @todo Don't think is the real solution.... |
| 1858 | 1943 | $lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0; |
| 1859 | - if ($pos < $lastAutoPos) |
|
| 1860 | - $no_autolink_area = true; |
|
| 1944 | + if ($pos < $lastAutoPos) { |
|
| 1945 | + $no_autolink_area = true; |
|
| 1946 | + } |
|
| 1861 | 1947 | $lastAutoPos = $pos; |
| 1862 | 1948 | |
| 1863 | 1949 | if (!$no_autolink_area) |
@@ -1966,17 +2052,19 @@ discard block |
||
| 1966 | 2052 | if ($scheme == 'mailto') |
| 1967 | 2053 | { |
| 1968 | 2054 | $email_address = str_replace('mailto:', '', $url); |
| 1969 | - if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) |
|
| 1970 | - return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
| 1971 | - else |
|
| 1972 | - return $url; |
|
| 2055 | + if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) { |
|
| 2056 | + return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
| 2057 | + } else { |
|
| 2058 | + return $url; |
|
| 2059 | + } |
|
| 1973 | 2060 | } |
| 1974 | 2061 | |
| 1975 | 2062 | // Are we linking a schemeless URL or naked domain name (e.g. "example.com")? |
| 1976 | - if (empty($scheme)) |
|
| 1977 | - $fullUrl = '//' . ltrim($url, ':/'); |
|
| 1978 | - else |
|
| 1979 | - $fullUrl = $url; |
|
| 2063 | + if (empty($scheme)) { |
|
| 2064 | + $fullUrl = '//' . ltrim($url, ':/'); |
|
| 2065 | + } else { |
|
| 2066 | + $fullUrl = $url; |
|
| 2067 | + } |
|
| 1980 | 2068 | |
| 1981 | 2069 | return '[url="' . str_replace(array('[', ']'), array('[', ']'), $fullUrl) . '"]' . $url . '[/url]'; |
| 1982 | 2070 | }, $data); |
@@ -2025,16 +2113,18 @@ discard block |
||
| 2025 | 2113 | } |
| 2026 | 2114 | |
| 2027 | 2115 | // Are we there yet? Are we there yet? |
| 2028 | - if ($pos >= strlen($message) - 1) |
|
| 2029 | - break; |
|
| 2116 | + if ($pos >= strlen($message) - 1) { |
|
| 2117 | + break; |
|
| 2118 | + } |
|
| 2030 | 2119 | |
| 2031 | 2120 | $tags = strtolower($message[$pos + 1]); |
| 2032 | 2121 | |
| 2033 | 2122 | if ($tags == '/' && !empty($open_tags)) |
| 2034 | 2123 | { |
| 2035 | 2124 | $pos2 = strpos($message, ']', $pos + 1); |
| 2036 | - if ($pos2 == $pos + 2) |
|
| 2037 | - continue; |
|
| 2125 | + if ($pos2 == $pos + 2) { |
|
| 2126 | + continue; |
|
| 2127 | + } |
|
| 2038 | 2128 | |
| 2039 | 2129 | $look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2)); |
| 2040 | 2130 | |
@@ -2044,8 +2134,9 @@ discard block |
||
| 2044 | 2134 | do |
| 2045 | 2135 | { |
| 2046 | 2136 | $tag = array_pop($open_tags); |
| 2047 | - if (!$tag) |
|
| 2048 | - break; |
|
| 2137 | + if (!$tag) { |
|
| 2138 | + break; |
|
| 2139 | + } |
|
| 2049 | 2140 | |
| 2050 | 2141 | if (!empty($tag['block_level'])) |
| 2051 | 2142 | { |
@@ -2059,10 +2150,11 @@ discard block |
||
| 2059 | 2150 | // The idea is, if we are LOOKING for a block level tag, we can close them on the way. |
| 2060 | 2151 | if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]])) |
| 2061 | 2152 | { |
| 2062 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
| 2063 | - if ($temp['tag'] == $look_for) |
|
| 2153 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
| 2154 | + if ($temp['tag'] == $look_for) |
|
| 2064 | 2155 | { |
| 2065 | 2156 | $block_level = !empty($temp['block_level']); |
| 2157 | + } |
|
| 2066 | 2158 | break; |
| 2067 | 2159 | } |
| 2068 | 2160 | } |
@@ -2084,15 +2176,15 @@ discard block |
||
| 2084 | 2176 | { |
| 2085 | 2177 | $open_tags = $to_close; |
| 2086 | 2178 | continue; |
| 2087 | - } |
|
| 2088 | - elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
| 2179 | + } elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
| 2089 | 2180 | { |
| 2090 | 2181 | if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]])) |
| 2091 | 2182 | { |
| 2092 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
| 2093 | - if ($temp['tag'] == $look_for) |
|
| 2183 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
| 2184 | + if ($temp['tag'] == $look_for) |
|
| 2094 | 2185 | { |
| 2095 | 2186 | $block_level = !empty($temp['block_level']); |
| 2187 | + } |
|
| 2096 | 2188 | break; |
| 2097 | 2189 | } |
| 2098 | 2190 | } |
@@ -2100,8 +2192,9 @@ discard block |
||
| 2100 | 2192 | // We're not looking for a block level tag (or maybe even a tag that exists...) |
| 2101 | 2193 | if (!$block_level) |
| 2102 | 2194 | { |
| 2103 | - foreach ($to_close as $tag) |
|
| 2104 | - array_push($open_tags, $tag); |
|
| 2195 | + foreach ($to_close as $tag) { |
|
| 2196 | + array_push($open_tags, $tag); |
|
| 2197 | + } |
|
| 2105 | 2198 | continue; |
| 2106 | 2199 | } |
| 2107 | 2200 | } |
@@ -2113,10 +2206,12 @@ discard block |
||
| 2113 | 2206 | $pos2 = $pos - 1; |
| 2114 | 2207 | |
| 2115 | 2208 | // See the comment at the end of the big loop - just eating whitespace ;). |
| 2116 | - if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>') |
|
| 2117 | - $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
| 2118 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) |
|
| 2119 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2209 | + if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>') { |
|
| 2210 | + $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
| 2211 | + } |
|
| 2212 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) { |
|
| 2213 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2214 | + } |
|
| 2120 | 2215 | } |
| 2121 | 2216 | |
| 2122 | 2217 | if (!empty($to_close)) |
@@ -2129,8 +2224,9 @@ discard block |
||
| 2129 | 2224 | } |
| 2130 | 2225 | |
| 2131 | 2226 | // No tags for this character, so just keep going (fastest possible course.) |
| 2132 | - if (!isset($bbc_codes[$tags])) |
|
| 2133 | - continue; |
|
| 2227 | + if (!isset($bbc_codes[$tags])) { |
|
| 2228 | + continue; |
|
| 2229 | + } |
|
| 2134 | 2230 | |
| 2135 | 2231 | $inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1]; |
| 2136 | 2232 | $tag = null; |
@@ -2139,44 +2235,52 @@ discard block |
||
| 2139 | 2235 | $pt_strlen = strlen($possible['tag']); |
| 2140 | 2236 | |
| 2141 | 2237 | // Not a match? |
| 2142 | - if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) |
|
| 2143 | - continue; |
|
| 2238 | + if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) { |
|
| 2239 | + continue; |
|
| 2240 | + } |
|
| 2144 | 2241 | |
| 2145 | 2242 | $next_c = $message[$pos + 1 + $pt_strlen]; |
| 2146 | 2243 | |
| 2147 | 2244 | // A test validation? |
| 2148 | - if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) |
|
| 2149 | - continue; |
|
| 2245 | + if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) { |
|
| 2246 | + continue; |
|
| 2247 | + } |
|
| 2150 | 2248 | // Do we want parameters? |
| 2151 | 2249 | elseif (!empty($possible['parameters'])) |
| 2152 | 2250 | { |
| 2153 | - if ($next_c != ' ') |
|
| 2154 | - continue; |
|
| 2155 | - } |
|
| 2156 | - elseif (isset($possible['type'])) |
|
| 2251 | + if ($next_c != ' ') { |
|
| 2252 | + continue; |
|
| 2253 | + } |
|
| 2254 | + } elseif (isset($possible['type'])) |
|
| 2157 | 2255 | { |
| 2158 | 2256 | // Do we need an equal sign? |
| 2159 | - if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') |
|
| 2160 | - continue; |
|
| 2257 | + if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') { |
|
| 2258 | + continue; |
|
| 2259 | + } |
|
| 2161 | 2260 | // Maybe we just want a /... |
| 2162 | - if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') |
|
| 2163 | - continue; |
|
| 2261 | + if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') { |
|
| 2262 | + continue; |
|
| 2263 | + } |
|
| 2164 | 2264 | // An immediate ]? |
| 2165 | - if ($possible['type'] == 'unparsed_content' && $next_c != ']') |
|
| 2166 | - continue; |
|
| 2265 | + if ($possible['type'] == 'unparsed_content' && $next_c != ']') { |
|
| 2266 | + continue; |
|
| 2267 | + } |
|
| 2167 | 2268 | } |
| 2168 | 2269 | // No type means 'parsed_content', which demands an immediate ] without parameters! |
| 2169 | - elseif ($next_c != ']') |
|
| 2170 | - continue; |
|
| 2270 | + elseif ($next_c != ']') { |
|
| 2271 | + continue; |
|
| 2272 | + } |
|
| 2171 | 2273 | |
| 2172 | 2274 | // Check allowed tree? |
| 2173 | - if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) |
|
| 2174 | - continue; |
|
| 2175 | - elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) |
|
| 2176 | - continue; |
|
| 2275 | + if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) { |
|
| 2276 | + continue; |
|
| 2277 | + } elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) { |
|
| 2278 | + continue; |
|
| 2279 | + } |
|
| 2177 | 2280 | // If this is in the list of disallowed child tags, don't parse it. |
| 2178 | - elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) |
|
| 2179 | - continue; |
|
| 2281 | + elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) { |
|
| 2282 | + continue; |
|
| 2283 | + } |
|
| 2180 | 2284 | |
| 2181 | 2285 | $pos1 = $pos + 1 + $pt_strlen + 1; |
| 2182 | 2286 | |
@@ -2188,8 +2292,9 @@ discard block |
||
| 2188 | 2292 | foreach ($open_tags as $open_quote) |
| 2189 | 2293 | { |
| 2190 | 2294 | // Every parent quote this quote has flips the styling |
| 2191 | - if ($open_quote['tag'] == 'quote') |
|
| 2192 | - $quote_alt = !$quote_alt; |
|
| 2295 | + if ($open_quote['tag'] == 'quote') { |
|
| 2296 | + $quote_alt = !$quote_alt; |
|
| 2297 | + } |
|
| 2193 | 2298 | } |
| 2194 | 2299 | // Add a class to the quote to style alternating blockquotes |
| 2195 | 2300 | $possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">')); |
@@ -2200,8 +2305,9 @@ discard block |
||
| 2200 | 2305 | { |
| 2201 | 2306 | // Build a regular expression for each parameter for the current tag. |
| 2202 | 2307 | $preg = array(); |
| 2203 | - foreach ($possible['parameters'] as $p => $info) |
|
| 2204 | - $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
| 2308 | + foreach ($possible['parameters'] as $p => $info) { |
|
| 2309 | + $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
| 2310 | + } |
|
| 2205 | 2311 | |
| 2206 | 2312 | // Extract the string that potentially holds our parameters. |
| 2207 | 2313 | $blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos)); |
@@ -2221,24 +2327,27 @@ discard block |
||
| 2221 | 2327 | |
| 2222 | 2328 | $match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0; |
| 2223 | 2329 | |
| 2224 | - if ($match) |
|
| 2225 | - $blob_counter = count($blobs) + 1; |
|
| 2330 | + if ($match) { |
|
| 2331 | + $blob_counter = count($blobs) + 1; |
|
| 2332 | + } |
|
| 2226 | 2333 | } |
| 2227 | 2334 | |
| 2228 | 2335 | // Didn't match our parameter list, try the next possible. |
| 2229 | - if (!$match) |
|
| 2230 | - continue; |
|
| 2336 | + if (!$match) { |
|
| 2337 | + continue; |
|
| 2338 | + } |
|
| 2231 | 2339 | |
| 2232 | 2340 | $params = array(); |
| 2233 | 2341 | for ($i = 1, $n = count($matches); $i < $n; $i += 2) |
| 2234 | 2342 | { |
| 2235 | 2343 | $key = strtok(ltrim($matches[$i]), '='); |
| 2236 | - if (isset($possible['parameters'][$key]['value'])) |
|
| 2237 | - $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
| 2238 | - elseif (isset($possible['parameters'][$key]['validate'])) |
|
| 2239 | - $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
| 2240 | - else |
|
| 2241 | - $params['{' . $key . '}'] = $matches[$i + 1]; |
|
| 2344 | + if (isset($possible['parameters'][$key]['value'])) { |
|
| 2345 | + $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
| 2346 | + } elseif (isset($possible['parameters'][$key]['validate'])) { |
|
| 2347 | + $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
| 2348 | + } else { |
|
| 2349 | + $params['{' . $key . '}'] = $matches[$i + 1]; |
|
| 2350 | + } |
|
| 2242 | 2351 | |
| 2243 | 2352 | // Just to make sure: replace any $ or { so they can't interpolate wrongly. |
| 2244 | 2353 | $params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '$', '{' => '{')); |
@@ -2246,23 +2355,26 @@ discard block |
||
| 2246 | 2355 | |
| 2247 | 2356 | foreach ($possible['parameters'] as $p => $info) |
| 2248 | 2357 | { |
| 2249 | - if (!isset($params['{' . $p . '}'])) |
|
| 2250 | - $params['{' . $p . '}'] = ''; |
|
| 2358 | + if (!isset($params['{' . $p . '}'])) { |
|
| 2359 | + $params['{' . $p . '}'] = ''; |
|
| 2360 | + } |
|
| 2251 | 2361 | } |
| 2252 | 2362 | |
| 2253 | 2363 | $tag = $possible; |
| 2254 | 2364 | |
| 2255 | 2365 | // Put the parameters into the string. |
| 2256 | - if (isset($tag['before'])) |
|
| 2257 | - $tag['before'] = strtr($tag['before'], $params); |
|
| 2258 | - if (isset($tag['after'])) |
|
| 2259 | - $tag['after'] = strtr($tag['after'], $params); |
|
| 2260 | - if (isset($tag['content'])) |
|
| 2261 | - $tag['content'] = strtr($tag['content'], $params); |
|
| 2366 | + if (isset($tag['before'])) { |
|
| 2367 | + $tag['before'] = strtr($tag['before'], $params); |
|
| 2368 | + } |
|
| 2369 | + if (isset($tag['after'])) { |
|
| 2370 | + $tag['after'] = strtr($tag['after'], $params); |
|
| 2371 | + } |
|
| 2372 | + if (isset($tag['content'])) { |
|
| 2373 | + $tag['content'] = strtr($tag['content'], $params); |
|
| 2374 | + } |
|
| 2262 | 2375 | |
| 2263 | 2376 | $pos1 += strlen($given_param_string); |
| 2264 | - } |
|
| 2265 | - else |
|
| 2377 | + } else |
|
| 2266 | 2378 | { |
| 2267 | 2379 | $tag = $possible; |
| 2268 | 2380 | $params = array(); |
@@ -2273,8 +2385,9 @@ discard block |
||
| 2273 | 2385 | // Item codes are complicated buggers... they are implicit [li]s and can make [list]s! |
| 2274 | 2386 | if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li'])) |
| 2275 | 2387 | { |
| 2276 | - if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) |
|
| 2277 | - continue; |
|
| 2388 | + if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) { |
|
| 2389 | + continue; |
|
| 2390 | + } |
|
| 2278 | 2391 | |
| 2279 | 2392 | $tag = $itemcodes[$message[$pos + 1]]; |
| 2280 | 2393 | |
@@ -2295,9 +2408,9 @@ discard block |
||
| 2295 | 2408 | { |
| 2296 | 2409 | array_pop($open_tags); |
| 2297 | 2410 | $code = '</li>'; |
| 2411 | + } else { |
|
| 2412 | + $code = ''; |
|
| 2298 | 2413 | } |
| 2299 | - else |
|
| 2300 | - $code = ''; |
|
| 2301 | 2414 | |
| 2302 | 2415 | // Now we open a new tag. |
| 2303 | 2416 | $open_tags[] = array( |
@@ -2344,12 +2457,14 @@ discard block |
||
| 2344 | 2457 | } |
| 2345 | 2458 | |
| 2346 | 2459 | // No tag? Keep looking, then. Silly people using brackets without actual tags. |
| 2347 | - if ($tag === null) |
|
| 2348 | - continue; |
|
| 2460 | + if ($tag === null) { |
|
| 2461 | + continue; |
|
| 2462 | + } |
|
| 2349 | 2463 | |
| 2350 | 2464 | // Propagate the list to the child (so wrapping the disallowed tag won't work either.) |
| 2351 | - if (isset($inside['disallow_children'])) |
|
| 2352 | - $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
| 2465 | + if (isset($inside['disallow_children'])) { |
|
| 2466 | + $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
| 2467 | + } |
|
| 2353 | 2468 | |
| 2354 | 2469 | // Is this tag disabled? |
| 2355 | 2470 | if (isset($disabled[$tag['tag']])) |
@@ -2359,14 +2474,13 @@ discard block |
||
| 2359 | 2474 | $tag['before'] = !empty($tag['block_level']) ? '<div>' : ''; |
| 2360 | 2475 | $tag['after'] = !empty($tag['block_level']) ? '</div>' : ''; |
| 2361 | 2476 | $tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1'); |
| 2362 | - } |
|
| 2363 | - elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
| 2477 | + } elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
| 2364 | 2478 | { |
| 2365 | 2479 | $tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : ''); |
| 2366 | 2480 | $tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : ''); |
| 2481 | + } else { |
|
| 2482 | + $tag['content'] = $tag['disabled_content']; |
|
| 2367 | 2483 | } |
| 2368 | - else |
|
| 2369 | - $tag['content'] = $tag['disabled_content']; |
|
| 2370 | 2484 | } |
| 2371 | 2485 | |
| 2372 | 2486 | // we use this a lot |
@@ -2376,8 +2490,9 @@ discard block |
||
| 2376 | 2490 | if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level'])) |
| 2377 | 2491 | { |
| 2378 | 2492 | $n = count($open_tags) - 1; |
| 2379 | - while (empty($open_tags[$n]['block_level']) && $n >= 0) |
|
| 2380 | - $n--; |
|
| 2493 | + while (empty($open_tags[$n]['block_level']) && $n >= 0) { |
|
| 2494 | + $n--; |
|
| 2495 | + } |
|
| 2381 | 2496 | |
| 2382 | 2497 | // Close all the non block level tags so this tag isn't surrounded by them. |
| 2383 | 2498 | for ($i = count($open_tags) - 1; $i > $n; $i--) |
@@ -2388,10 +2503,12 @@ discard block |
||
| 2388 | 2503 | $pos1 += $ot_strlen + 2; |
| 2389 | 2504 | |
| 2390 | 2505 | // Trim or eat trailing stuff... see comment at the end of the big loop. |
| 2391 | - if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>') |
|
| 2392 | - $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
| 2393 | - if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) |
|
| 2394 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2506 | + if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>') { |
|
| 2507 | + $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
| 2508 | + } |
|
| 2509 | + if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) { |
|
| 2510 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
| 2511 | + } |
|
| 2395 | 2512 | |
| 2396 | 2513 | array_pop($open_tags); |
| 2397 | 2514 | } |
@@ -2409,16 +2526,19 @@ discard block |
||
| 2409 | 2526 | elseif ($tag['type'] == 'unparsed_content') |
| 2410 | 2527 | { |
| 2411 | 2528 | $pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1); |
| 2412 | - if ($pos2 === false) |
|
| 2413 | - continue; |
|
| 2529 | + if ($pos2 === false) { |
|
| 2530 | + continue; |
|
| 2531 | + } |
|
| 2414 | 2532 | |
| 2415 | 2533 | $data = substr($message, $pos1, $pos2 - $pos1); |
| 2416 | 2534 | |
| 2417 | - if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') |
|
| 2418 | - $data = substr($data, 4); |
|
| 2535 | + if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') { |
|
| 2536 | + $data = substr($data, 4); |
|
| 2537 | + } |
|
| 2419 | 2538 | |
| 2420 | - if (isset($tag['validate'])) |
|
| 2421 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2539 | + if (isset($tag['validate'])) { |
|
| 2540 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2541 | + } |
|
| 2422 | 2542 | |
| 2423 | 2543 | $code = strtr($tag['content'], array('$1' => $data)); |
| 2424 | 2544 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen); |
@@ -2434,34 +2554,40 @@ discard block |
||
| 2434 | 2554 | if (isset($tag['quoted'])) |
| 2435 | 2555 | { |
| 2436 | 2556 | $quoted = substr($message, $pos1, 6) == '"'; |
| 2437 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
| 2438 | - continue; |
|
| 2557 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
| 2558 | + continue; |
|
| 2559 | + } |
|
| 2439 | 2560 | |
| 2440 | - if ($quoted) |
|
| 2441 | - $pos1 += 6; |
|
| 2561 | + if ($quoted) { |
|
| 2562 | + $pos1 += 6; |
|
| 2563 | + } |
|
| 2564 | + } else { |
|
| 2565 | + $quoted = false; |
|
| 2442 | 2566 | } |
| 2443 | - else |
|
| 2444 | - $quoted = false; |
|
| 2445 | 2567 | |
| 2446 | 2568 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
| 2447 | - if ($pos2 === false) |
|
| 2448 | - continue; |
|
| 2569 | + if ($pos2 === false) { |
|
| 2570 | + continue; |
|
| 2571 | + } |
|
| 2449 | 2572 | |
| 2450 | 2573 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
| 2451 | - if ($pos3 === false) |
|
| 2452 | - continue; |
|
| 2574 | + if ($pos3 === false) { |
|
| 2575 | + continue; |
|
| 2576 | + } |
|
| 2453 | 2577 | |
| 2454 | 2578 | $data = array( |
| 2455 | 2579 | substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))), |
| 2456 | 2580 | substr($message, $pos1, $pos2 - $pos1) |
| 2457 | 2581 | ); |
| 2458 | 2582 | |
| 2459 | - if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') |
|
| 2460 | - $data[0] = substr($data[0], 4); |
|
| 2583 | + if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') { |
|
| 2584 | + $data[0] = substr($data[0], 4); |
|
| 2585 | + } |
|
| 2461 | 2586 | |
| 2462 | 2587 | // Validation for my parking, please! |
| 2463 | - if (isset($tag['validate'])) |
|
| 2464 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2588 | + if (isset($tag['validate'])) { |
|
| 2589 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2590 | + } |
|
| 2465 | 2591 | |
| 2466 | 2592 | $code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1])); |
| 2467 | 2593 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
@@ -2478,23 +2604,27 @@ discard block |
||
| 2478 | 2604 | elseif ($tag['type'] == 'unparsed_commas_content') |
| 2479 | 2605 | { |
| 2480 | 2606 | $pos2 = strpos($message, ']', $pos1); |
| 2481 | - if ($pos2 === false) |
|
| 2482 | - continue; |
|
| 2607 | + if ($pos2 === false) { |
|
| 2608 | + continue; |
|
| 2609 | + } |
|
| 2483 | 2610 | |
| 2484 | 2611 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
| 2485 | - if ($pos3 === false) |
|
| 2486 | - continue; |
|
| 2612 | + if ($pos3 === false) { |
|
| 2613 | + continue; |
|
| 2614 | + } |
|
| 2487 | 2615 | |
| 2488 | 2616 | // We want $1 to be the content, and the rest to be csv. |
| 2489 | 2617 | $data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1)); |
| 2490 | 2618 | $data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1); |
| 2491 | 2619 | |
| 2492 | - if (isset($tag['validate'])) |
|
| 2493 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2620 | + if (isset($tag['validate'])) { |
|
| 2621 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2622 | + } |
|
| 2494 | 2623 | |
| 2495 | 2624 | $code = $tag['content']; |
| 2496 | - foreach ($data as $k => $d) |
|
| 2497 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2625 | + foreach ($data as $k => $d) { |
|
| 2626 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2627 | + } |
|
| 2498 | 2628 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
| 2499 | 2629 | $pos += strlen($code) - 1 + 2; |
| 2500 | 2630 | } |
@@ -2502,24 +2632,28 @@ discard block |
||
| 2502 | 2632 | elseif ($tag['type'] == 'unparsed_commas') |
| 2503 | 2633 | { |
| 2504 | 2634 | $pos2 = strpos($message, ']', $pos1); |
| 2505 | - if ($pos2 === false) |
|
| 2506 | - continue; |
|
| 2635 | + if ($pos2 === false) { |
|
| 2636 | + continue; |
|
| 2637 | + } |
|
| 2507 | 2638 | |
| 2508 | 2639 | $data = explode(',', substr($message, $pos1, $pos2 - $pos1)); |
| 2509 | 2640 | |
| 2510 | - if (isset($tag['validate'])) |
|
| 2511 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2641 | + if (isset($tag['validate'])) { |
|
| 2642 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2643 | + } |
|
| 2512 | 2644 | |
| 2513 | 2645 | // Fix after, for disabled code mainly. |
| 2514 | - foreach ($data as $k => $d) |
|
| 2515 | - $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
| 2646 | + foreach ($data as $k => $d) { |
|
| 2647 | + $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
| 2648 | + } |
|
| 2516 | 2649 | |
| 2517 | 2650 | $open_tags[] = $tag; |
| 2518 | 2651 | |
| 2519 | 2652 | // Replace them out, $1, $2, $3, $4, etc. |
| 2520 | 2653 | $code = $tag['before']; |
| 2521 | - foreach ($data as $k => $d) |
|
| 2522 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2654 | + foreach ($data as $k => $d) { |
|
| 2655 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
| 2656 | + } |
|
| 2523 | 2657 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1); |
| 2524 | 2658 | $pos += strlen($code) - 1 + 2; |
| 2525 | 2659 | } |
@@ -2530,28 +2664,33 @@ discard block |
||
| 2530 | 2664 | if (isset($tag['quoted'])) |
| 2531 | 2665 | { |
| 2532 | 2666 | $quoted = substr($message, $pos1, 6) == '"'; |
| 2533 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
| 2534 | - continue; |
|
| 2667 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
| 2668 | + continue; |
|
| 2669 | + } |
|
| 2535 | 2670 | |
| 2536 | - if ($quoted) |
|
| 2537 | - $pos1 += 6; |
|
| 2671 | + if ($quoted) { |
|
| 2672 | + $pos1 += 6; |
|
| 2673 | + } |
|
| 2674 | + } else { |
|
| 2675 | + $quoted = false; |
|
| 2538 | 2676 | } |
| 2539 | - else |
|
| 2540 | - $quoted = false; |
|
| 2541 | 2677 | |
| 2542 | 2678 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
| 2543 | - if ($pos2 === false) |
|
| 2544 | - continue; |
|
| 2679 | + if ($pos2 === false) { |
|
| 2680 | + continue; |
|
| 2681 | + } |
|
| 2545 | 2682 | |
| 2546 | 2683 | $data = substr($message, $pos1, $pos2 - $pos1); |
| 2547 | 2684 | |
| 2548 | 2685 | // Validation for my parking, please! |
| 2549 | - if (isset($tag['validate'])) |
|
| 2550 | - $tag['validate']($tag, $data, $disabled, $params); |
|
| 2686 | + if (isset($tag['validate'])) { |
|
| 2687 | + $tag['validate']($tag, $data, $disabled, $params); |
|
| 2688 | + } |
|
| 2551 | 2689 | |
| 2552 | 2690 | // For parsed content, we must recurse to avoid security problems. |
| 2553 | - if ($tag['type'] != 'unparsed_equals') |
|
| 2554 | - $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
| 2691 | + if ($tag['type'] != 'unparsed_equals') { |
|
| 2692 | + $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
| 2693 | + } |
|
| 2555 | 2694 | |
| 2556 | 2695 | $tag['after'] = strtr($tag['after'], array('$1' => $data)); |
| 2557 | 2696 | |
@@ -2563,34 +2702,40 @@ discard block |
||
| 2563 | 2702 | } |
| 2564 | 2703 | |
| 2565 | 2704 | // If this is block level, eat any breaks after it. |
| 2566 | - if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') |
|
| 2567 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
| 2705 | + if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') { |
|
| 2706 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
| 2707 | + } |
|
| 2568 | 2708 | |
| 2569 | 2709 | // Are we trimming outside this tag? |
| 2570 | - if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) |
|
| 2571 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
| 2710 | + if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) { |
|
| 2711 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
| 2712 | + } |
|
| 2572 | 2713 | } |
| 2573 | 2714 | |
| 2574 | 2715 | // Close any remaining tags. |
| 2575 | - while ($tag = array_pop($open_tags)) |
|
| 2576 | - $message .= "\n" . $tag['after'] . "\n"; |
|
| 2716 | + while ($tag = array_pop($open_tags)) { |
|
| 2717 | + $message .= "\n" . $tag['after'] . "\n"; |
|
| 2718 | + } |
|
| 2577 | 2719 | |
| 2578 | 2720 | // Parse the smileys within the parts where it can be done safely. |
| 2579 | 2721 | if ($smileys === true) |
| 2580 | 2722 | { |
| 2581 | 2723 | $message_parts = explode("\n", $message); |
| 2582 | - for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) |
|
| 2583 | - parsesmileys($message_parts[$i]); |
|
| 2724 | + for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) { |
|
| 2725 | + parsesmileys($message_parts[$i]); |
|
| 2726 | + } |
|
| 2584 | 2727 | |
| 2585 | 2728 | $message = implode('', $message_parts); |
| 2586 | 2729 | } |
| 2587 | 2730 | |
| 2588 | 2731 | // No smileys, just get rid of the markers. |
| 2589 | - else |
|
| 2590 | - $message = strtr($message, array("\n" => '')); |
|
| 2732 | + else { |
|
| 2733 | + $message = strtr($message, array("\n" => '')); |
|
| 2734 | + } |
|
| 2591 | 2735 | |
| 2592 | - if ($message !== '' && $message[0] === ' ') |
|
| 2593 | - $message = ' ' . substr($message, 1); |
|
| 2736 | + if ($message !== '' && $message[0] === ' ') { |
|
| 2737 | + $message = ' ' . substr($message, 1); |
|
| 2738 | + } |
|
| 2594 | 2739 | |
| 2595 | 2740 | // Cleanup whitespace. |
| 2596 | 2741 | $message = strtr($message, array(' ' => ' ', "\r" => '', "\n" => '<br>', '<br> ' => '<br> ', ' ' => "\n")); |
@@ -2599,15 +2744,16 @@ discard block |
||
| 2599 | 2744 | call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
| 2600 | 2745 | |
| 2601 | 2746 | // Cache the output if it took some time... |
| 2602 | - if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) |
|
| 2603 | - cache_put_data($cache_key, $message, 240); |
|
| 2747 | + if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) { |
|
| 2748 | + cache_put_data($cache_key, $message, 240); |
|
| 2749 | + } |
|
| 2604 | 2750 | |
| 2605 | 2751 | // If this was a force parse revert if needed. |
| 2606 | 2752 | if (!empty($parse_tags)) |
| 2607 | 2753 | { |
| 2608 | - if (empty($temp_bbc)) |
|
| 2609 | - $bbc_codes = array(); |
|
| 2610 | - else |
|
| 2754 | + if (empty($temp_bbc)) { |
|
| 2755 | + $bbc_codes = array(); |
|
| 2756 | + } else |
|
| 2611 | 2757 | { |
| 2612 | 2758 | $bbc_codes = $temp_bbc; |
| 2613 | 2759 | unset($temp_bbc); |
@@ -2634,8 +2780,9 @@ discard block |
||
| 2634 | 2780 | static $smileyPregSearch = null, $smileyPregReplacements = array(); |
| 2635 | 2781 | |
| 2636 | 2782 | // No smiley set at all?! |
| 2637 | - if ($user_info['smiley_set'] == 'none' || trim($message) == '') |
|
| 2638 | - return; |
|
| 2783 | + if ($user_info['smiley_set'] == 'none' || trim($message) == '') { |
|
| 2784 | + return; |
|
| 2785 | + } |
|
| 2639 | 2786 | |
| 2640 | 2787 | // If smileyPregSearch hasn't been set, do it now. |
| 2641 | 2788 | if (empty($smileyPregSearch)) |
@@ -2646,8 +2793,7 @@ discard block |
||
| 2646 | 2793 | $smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)'); |
| 2647 | 2794 | $smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif'); |
| 2648 | 2795 | $smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', ''); |
| 2649 | - } |
|
| 2650 | - else |
|
| 2796 | + } else |
|
| 2651 | 2797 | { |
| 2652 | 2798 | // Load the smileys in reverse order by length so they don't get parsed wrong. |
| 2653 | 2799 | if (($temp = cache_get_data('parsing_smileys', 480)) == null) |
@@ -2671,9 +2817,9 @@ discard block |
||
| 2671 | 2817 | $smcFunc['db_free_result']($result); |
| 2672 | 2818 | |
| 2673 | 2819 | cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480); |
| 2820 | + } else { |
|
| 2821 | + list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
| 2674 | 2822 | } |
| 2675 | - else |
|
| 2676 | - list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
| 2677 | 2823 | } |
| 2678 | 2824 | |
| 2679 | 2825 | // The non-breaking-space is a complex thing... |
@@ -2750,35 +2896,41 @@ discard block |
||
| 2750 | 2896 | global $scripturl, $context, $modSettings, $db_show_debug, $db_cache; |
| 2751 | 2897 | |
| 2752 | 2898 | // In case we have mail to send, better do that - as obExit doesn't always quite make it... |
| 2753 | - if (!empty($context['flush_mail'])) |
|
| 2754 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2899 | + if (!empty($context['flush_mail'])) { |
|
| 2900 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2755 | 2901 | AddMailQueue(true); |
| 2902 | + } |
|
| 2756 | 2903 | |
| 2757 | 2904 | $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:'; |
| 2758 | 2905 | |
| 2759 | - if ($add) |
|
| 2760 | - $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
| 2906 | + if ($add) { |
|
| 2907 | + $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
| 2908 | + } |
|
| 2761 | 2909 | |
| 2762 | 2910 | // Put the session ID in. |
| 2763 | - if (defined('SID') && SID != '') |
|
| 2764 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
| 2911 | + if (defined('SID') && SID != '') { |
|
| 2912 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
| 2913 | + } |
|
| 2765 | 2914 | // Keep that debug in their for template debugging! |
| 2766 | - elseif (isset($_GET['debug'])) |
|
| 2767 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
| 2915 | + elseif (isset($_GET['debug'])) { |
|
| 2916 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
| 2917 | + } |
|
| 2768 | 2918 | |
| 2769 | 2919 | if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed']))) |
| 2770 | 2920 | { |
| 2771 | - if (defined('SID') && SID != '') |
|
| 2772 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
| 2921 | + if (defined('SID') && SID != '') { |
|
| 2922 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
| 2773 | 2923 | function ($m) use ($scripturl) |
| 2774 | 2924 | { |
| 2775 | 2925 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); |
| 2926 | + } |
|
| 2776 | 2927 | }, $setLocation); |
| 2777 | - else |
|
| 2778 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
| 2928 | + else { |
|
| 2929 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
| 2779 | 2930 | function ($m) use ($scripturl) |
| 2780 | 2931 | { |
| 2781 | 2932 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); |
| 2933 | + } |
|
| 2782 | 2934 | }, $setLocation); |
| 2783 | 2935 | } |
| 2784 | 2936 | |
@@ -2789,8 +2941,9 @@ discard block |
||
| 2789 | 2941 | header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302); |
| 2790 | 2942 | |
| 2791 | 2943 | // Debugging. |
| 2792 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 2793 | - $_SESSION['debug_redirect'] = $db_cache; |
|
| 2944 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 2945 | + $_SESSION['debug_redirect'] = $db_cache; |
|
| 2946 | + } |
|
| 2794 | 2947 | |
| 2795 | 2948 | obExit(false); |
| 2796 | 2949 | } |
@@ -2809,51 +2962,60 @@ discard block |
||
| 2809 | 2962 | |
| 2810 | 2963 | // Attempt to prevent a recursive loop. |
| 2811 | 2964 | ++$level; |
| 2812 | - if ($level > 1 && !$from_fatal_error && !$has_fatal_error) |
|
| 2813 | - exit; |
|
| 2814 | - if ($from_fatal_error) |
|
| 2815 | - $has_fatal_error = true; |
|
| 2965 | + if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { |
|
| 2966 | + exit; |
|
| 2967 | + } |
|
| 2968 | + if ($from_fatal_error) { |
|
| 2969 | + $has_fatal_error = true; |
|
| 2970 | + } |
|
| 2816 | 2971 | |
| 2817 | 2972 | // Clear out the stat cache. |
| 2818 | 2973 | trackStats(); |
| 2819 | 2974 | |
| 2820 | 2975 | // If we have mail to send, send it. |
| 2821 | - if (!empty($context['flush_mail'])) |
|
| 2822 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2976 | + if (!empty($context['flush_mail'])) { |
|
| 2977 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
| 2823 | 2978 | AddMailQueue(true); |
| 2979 | + } |
|
| 2824 | 2980 | |
| 2825 | 2981 | $do_header = $header === null ? !$header_done : $header; |
| 2826 | - if ($do_footer === null) |
|
| 2827 | - $do_footer = $do_header; |
|
| 2982 | + if ($do_footer === null) { |
|
| 2983 | + $do_footer = $do_header; |
|
| 2984 | + } |
|
| 2828 | 2985 | |
| 2829 | 2986 | // Has the template/header been done yet? |
| 2830 | 2987 | if ($do_header) |
| 2831 | 2988 | { |
| 2832 | 2989 | // Was the page title set last minute? Also update the HTML safe one. |
| 2833 | - if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) |
|
| 2834 | - $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
| 2990 | + if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { |
|
| 2991 | + $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
| 2992 | + } |
|
| 2835 | 2993 | |
| 2836 | 2994 | // Start up the session URL fixer. |
| 2837 | 2995 | ob_start('ob_sessrewrite'); |
| 2838 | 2996 | |
| 2839 | - if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) |
|
| 2840 | - $buffers = explode(',', $settings['output_buffers']); |
|
| 2841 | - elseif (!empty($settings['output_buffers'])) |
|
| 2842 | - $buffers = $settings['output_buffers']; |
|
| 2843 | - else |
|
| 2844 | - $buffers = array(); |
|
| 2997 | + if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) { |
|
| 2998 | + $buffers = explode(',', $settings['output_buffers']); |
|
| 2999 | + } elseif (!empty($settings['output_buffers'])) { |
|
| 3000 | + $buffers = $settings['output_buffers']; |
|
| 3001 | + } else { |
|
| 3002 | + $buffers = array(); |
|
| 3003 | + } |
|
| 2845 | 3004 | |
| 2846 | - if (isset($modSettings['integrate_buffer'])) |
|
| 2847 | - $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
| 3005 | + if (isset($modSettings['integrate_buffer'])) { |
|
| 3006 | + $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
| 3007 | + } |
|
| 2848 | 3008 | |
| 2849 | - if (!empty($buffers)) |
|
| 2850 | - foreach ($buffers as $function) |
|
| 3009 | + if (!empty($buffers)) { |
|
| 3010 | + foreach ($buffers as $function) |
|
| 2851 | 3011 | { |
| 2852 | 3012 | $call = call_helper($function, true); |
| 3013 | + } |
|
| 2853 | 3014 | |
| 2854 | 3015 | // Is it valid? |
| 2855 | - if (!empty($call)) |
|
| 2856 | - ob_start($call); |
|
| 3016 | + if (!empty($call)) { |
|
| 3017 | + ob_start($call); |
|
| 3018 | + } |
|
| 2857 | 3019 | } |
| 2858 | 3020 | |
| 2859 | 3021 | // Display the screen in the logical order. |
@@ -2865,8 +3027,9 @@ discard block |
||
| 2865 | 3027 | loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); |
| 2866 | 3028 | |
| 2867 | 3029 | // Anything special to put out? |
| 2868 | - if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) |
|
| 2869 | - echo $context['insert_after_template']; |
|
| 3030 | + if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) { |
|
| 3031 | + echo $context['insert_after_template']; |
|
| 3032 | + } |
|
| 2870 | 3033 | |
| 2871 | 3034 | // Just so we don't get caught in an endless loop of errors from the footer... |
| 2872 | 3035 | if (!$footer_done) |
@@ -2875,14 +3038,16 @@ discard block |
||
| 2875 | 3038 | template_footer(); |
| 2876 | 3039 | |
| 2877 | 3040 | // (since this is just debugging... it's okay that it's after </html>.) |
| 2878 | - if (!isset($_REQUEST['xml'])) |
|
| 2879 | - displayDebug(); |
|
| 3041 | + if (!isset($_REQUEST['xml'])) { |
|
| 3042 | + displayDebug(); |
|
| 3043 | + } |
|
| 2880 | 3044 | } |
| 2881 | 3045 | } |
| 2882 | 3046 | |
| 2883 | 3047 | // Remember this URL in case someone doesn't like sending HTTP_REFERER. |
| 2884 | - if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) |
|
| 2885 | - $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
| 3048 | + if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { |
|
| 3049 | + $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
| 3050 | + } |
|
| 2886 | 3051 | |
| 2887 | 3052 | // For session check verification.... don't switch browsers... |
| 2888 | 3053 | $_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT']; |
@@ -2891,9 +3056,10 @@ discard block |
||
| 2891 | 3056 | call_integration_hook('integrate_exit', array($do_footer)); |
| 2892 | 3057 | |
| 2893 | 3058 | // Don't exit if we're coming from index.php; that will pass through normally. |
| 2894 | - if (!$from_index) |
|
| 2895 | - exit; |
|
| 2896 | -} |
|
| 3059 | + if (!$from_index) { |
|
| 3060 | + exit; |
|
| 3061 | + } |
|
| 3062 | + } |
|
| 2897 | 3063 | |
| 2898 | 3064 | /** |
| 2899 | 3065 | * Get the size of a specified image with better error handling. |
@@ -2912,8 +3078,9 @@ discard block |
||
| 2912 | 3078 | $url = str_replace(' ', '%20', $url); |
| 2913 | 3079 | |
| 2914 | 3080 | // Can we pull this from the cache... please please? |
| 2915 | - if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) |
|
| 2916 | - return $temp; |
|
| 3081 | + if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) { |
|
| 3082 | + return $temp; |
|
| 3083 | + } |
|
| 2917 | 3084 | $t = microtime(); |
| 2918 | 3085 | |
| 2919 | 3086 | // Get the host to pester... |
@@ -2923,12 +3090,10 @@ discard block |
||
| 2923 | 3090 | if ($url == '' || $url == 'http://' || $url == 'https://') |
| 2924 | 3091 | { |
| 2925 | 3092 | return false; |
| 2926 | - } |
|
| 2927 | - elseif (!isset($match[1])) |
|
| 3093 | + } elseif (!isset($match[1])) |
|
| 2928 | 3094 | { |
| 2929 | 3095 | $size = @getimagesize($url); |
| 2930 | - } |
|
| 2931 | - else |
|
| 3096 | + } else |
|
| 2932 | 3097 | { |
| 2933 | 3098 | // Try to connect to the server... give it half a second. |
| 2934 | 3099 | $temp = 0; |
@@ -2967,12 +3132,14 @@ discard block |
||
| 2967 | 3132 | } |
| 2968 | 3133 | |
| 2969 | 3134 | // If we didn't get it, we failed. |
| 2970 | - if (!isset($size)) |
|
| 2971 | - $size = false; |
|
| 3135 | + if (!isset($size)) { |
|
| 3136 | + $size = false; |
|
| 3137 | + } |
|
| 2972 | 3138 | |
| 2973 | 3139 | // If this took a long time, we may never have to do it again, but then again we might... |
| 2974 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) |
|
| 2975 | - cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
| 3140 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) { |
|
| 3141 | + cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
| 3142 | + } |
|
| 2976 | 3143 | |
| 2977 | 3144 | // Didn't work. |
| 2978 | 3145 | return $size; |
@@ -2990,8 +3157,9 @@ discard block |
||
| 2990 | 3157 | |
| 2991 | 3158 | // Under SSI this function can be called more then once. That can cause some problems. |
| 2992 | 3159 | // So only run the function once unless we are forced to run it again. |
| 2993 | - if ($loaded && !$forceload) |
|
| 2994 | - return; |
|
| 3160 | + if ($loaded && !$forceload) { |
|
| 3161 | + return; |
|
| 3162 | + } |
|
| 2995 | 3163 | |
| 2996 | 3164 | $loaded = true; |
| 2997 | 3165 | |
@@ -3003,14 +3171,16 @@ discard block |
||
| 3003 | 3171 | $context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))))); |
| 3004 | 3172 | for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++) |
| 3005 | 3173 | { |
| 3006 | - if (trim($context['news_lines'][$i]) == '') |
|
| 3007 | - continue; |
|
| 3174 | + if (trim($context['news_lines'][$i]) == '') { |
|
| 3175 | + continue; |
|
| 3176 | + } |
|
| 3008 | 3177 | |
| 3009 | 3178 | // Clean it up for presentation ;). |
| 3010 | 3179 | $context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i); |
| 3011 | 3180 | } |
| 3012 | - if (!empty($context['news_lines'])) |
|
| 3013 | - $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
| 3181 | + if (!empty($context['news_lines'])) { |
|
| 3182 | + $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
| 3183 | + } |
|
| 3014 | 3184 | |
| 3015 | 3185 | if (!$user_info['is_guest']) |
| 3016 | 3186 | { |
@@ -3019,40 +3189,48 @@ discard block |
||
| 3019 | 3189 | $context['user']['alerts'] = &$user_info['alerts']; |
| 3020 | 3190 | |
| 3021 | 3191 | // Personal message popup... |
| 3022 | - if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) |
|
| 3023 | - $context['user']['popup_messages'] = true; |
|
| 3024 | - else |
|
| 3025 | - $context['user']['popup_messages'] = false; |
|
| 3192 | + if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) { |
|
| 3193 | + $context['user']['popup_messages'] = true; |
|
| 3194 | + } else { |
|
| 3195 | + $context['user']['popup_messages'] = false; |
|
| 3196 | + } |
|
| 3026 | 3197 | $_SESSION['unread_messages'] = $user_info['unread_messages']; |
| 3027 | 3198 | |
| 3028 | - if (allowedTo('moderate_forum')) |
|
| 3029 | - $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
| 3199 | + if (allowedTo('moderate_forum')) { |
|
| 3200 | + $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
| 3201 | + } |
|
| 3030 | 3202 | |
| 3031 | 3203 | $context['user']['avatar'] = array(); |
| 3032 | 3204 | |
| 3033 | 3205 | // Check for gravatar first since we might be forcing them... |
| 3034 | 3206 | if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride'])) |
| 3035 | 3207 | { |
| 3036 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) |
|
| 3037 | - $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
| 3038 | - else |
|
| 3039 | - $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
| 3208 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) { |
|
| 3209 | + $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
| 3210 | + } else { |
|
| 3211 | + $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
| 3212 | + } |
|
| 3040 | 3213 | } |
| 3041 | 3214 | // Uploaded? |
| 3042 | - elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) |
|
| 3043 | - $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; |
|
| 3215 | + elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) { |
|
| 3216 | + $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; |
|
| 3217 | + } |
|
| 3044 | 3218 | // Full URL? |
| 3045 | - elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) |
|
| 3046 | - $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
| 3219 | + elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) { |
|
| 3220 | + $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
| 3221 | + } |
|
| 3047 | 3222 | // Otherwise we assume it's server stored. |
| 3048 | - elseif ($user_info['avatar']['url'] != '') |
|
| 3049 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
| 3223 | + elseif ($user_info['avatar']['url'] != '') { |
|
| 3224 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
| 3225 | + } |
|
| 3050 | 3226 | // No avatar at all? Fine, we have a big fat default avatar ;) |
| 3051 | - else |
|
| 3052 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
| 3227 | + else { |
|
| 3228 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
| 3229 | + } |
|
| 3053 | 3230 | |
| 3054 | - if (!empty($context['user']['avatar'])) |
|
| 3055 | - $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
| 3231 | + if (!empty($context['user']['avatar'])) { |
|
| 3232 | + $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
| 3233 | + } |
|
| 3056 | 3234 | |
| 3057 | 3235 | // Figure out how long they've been logged in. |
| 3058 | 3236 | $context['user']['total_time_logged_in'] = array( |
@@ -3060,8 +3238,7 @@ discard block |
||
| 3060 | 3238 | 'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600), |
| 3061 | 3239 | 'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60) |
| 3062 | 3240 | ); |
| 3063 | - } |
|
| 3064 | - else |
|
| 3241 | + } else |
|
| 3065 | 3242 | { |
| 3066 | 3243 | $context['user']['messages'] = 0; |
| 3067 | 3244 | $context['user']['unread_messages'] = 0; |
@@ -3069,12 +3246,14 @@ discard block |
||
| 3069 | 3246 | $context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0); |
| 3070 | 3247 | $context['user']['popup_messages'] = false; |
| 3071 | 3248 | |
| 3072 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) |
|
| 3073 | - $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
| 3249 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) { |
|
| 3250 | + $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
| 3251 | + } |
|
| 3074 | 3252 | |
| 3075 | 3253 | // If we've upgraded recently, go easy on the passwords. |
| 3076 | - if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) |
|
| 3077 | - $context['disable_login_hashing'] = true; |
|
| 3254 | + if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) { |
|
| 3255 | + $context['disable_login_hashing'] = true; |
|
| 3256 | + } |
|
| 3078 | 3257 | } |
| 3079 | 3258 | |
| 3080 | 3259 | // Setup the main menu items. |
@@ -3087,8 +3266,8 @@ discard block |
||
| 3087 | 3266 | $context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm'); |
| 3088 | 3267 | |
| 3089 | 3268 | // 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array. |
| 3090 | - if ($context['show_pm_popup']) |
|
| 3091 | - addInlineJavaScript(' |
|
| 3269 | + if ($context['show_pm_popup']) { |
|
| 3270 | + addInlineJavaScript(' |
|
| 3092 | 3271 | jQuery(document).ready(function($) { |
| 3093 | 3272 | new smc_Popup({ |
| 3094 | 3273 | heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ', |
@@ -3096,15 +3275,17 @@ discard block |
||
| 3096 | 3275 | icon_class: \'generic_icons mail_new\' |
| 3097 | 3276 | }); |
| 3098 | 3277 | });'); |
| 3278 | + } |
|
| 3099 | 3279 | |
| 3100 | 3280 | // Add a generic "Are you sure?" confirmation message. |
| 3101 | 3281 | addInlineJavaScript(' |
| 3102 | 3282 | var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); |
| 3103 | 3283 | |
| 3104 | 3284 | // Now add the capping code for avatars. |
| 3105 | - if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') |
|
| 3106 | - addInlineCss(' |
|
| 3285 | + if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') { |
|
| 3286 | + addInlineCss(' |
|
| 3107 | 3287 | img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }'); |
| 3288 | + } |
|
| 3108 | 3289 | |
| 3109 | 3290 | // This looks weird, but it's because BoardIndex.php references the variable. |
| 3110 | 3291 | $context['common_stats']['latest_member'] = array( |
@@ -3121,11 +3302,13 @@ discard block |
||
| 3121 | 3302 | ); |
| 3122 | 3303 | $context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']); |
| 3123 | 3304 | |
| 3124 | - if (empty($settings['theme_version'])) |
|
| 3125 | - addJavaScriptVar('smf_scripturl', $scripturl); |
|
| 3305 | + if (empty($settings['theme_version'])) { |
|
| 3306 | + addJavaScriptVar('smf_scripturl', $scripturl); |
|
| 3307 | + } |
|
| 3126 | 3308 | |
| 3127 | - if (!isset($context['page_title'])) |
|
| 3128 | - $context['page_title'] = ''; |
|
| 3309 | + if (!isset($context['page_title'])) { |
|
| 3310 | + $context['page_title'] = ''; |
|
| 3311 | + } |
|
| 3129 | 3312 | |
| 3130 | 3313 | // Set some specific vars. |
| 3131 | 3314 | $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
@@ -3135,21 +3318,23 @@ discard block |
||
| 3135 | 3318 | $context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']); |
| 3136 | 3319 | $context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']); |
| 3137 | 3320 | |
| 3138 | - if (!empty($context['meta_keywords'])) |
|
| 3139 | - $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
| 3321 | + if (!empty($context['meta_keywords'])) { |
|
| 3322 | + $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
| 3323 | + } |
|
| 3140 | 3324 | |
| 3141 | - if (!empty($context['canonical_url'])) |
|
| 3142 | - $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
| 3325 | + if (!empty($context['canonical_url'])) { |
|
| 3326 | + $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
| 3327 | + } |
|
| 3143 | 3328 | |
| 3144 | - if (!empty($settings['og_image'])) |
|
| 3145 | - $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
| 3329 | + if (!empty($settings['og_image'])) { |
|
| 3330 | + $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
| 3331 | + } |
|
| 3146 | 3332 | |
| 3147 | 3333 | if (!empty($context['meta_description'])) |
| 3148 | 3334 | { |
| 3149 | 3335 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']); |
| 3150 | 3336 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']); |
| 3151 | - } |
|
| 3152 | - else |
|
| 3337 | + } else |
|
| 3153 | 3338 | { |
| 3154 | 3339 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']); |
| 3155 | 3340 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']); |
@@ -3175,8 +3360,9 @@ discard block |
||
| 3175 | 3360 | $memory_needed = memoryReturnBytes($needed); |
| 3176 | 3361 | |
| 3177 | 3362 | // should we account for how much is currently being used? |
| 3178 | - if ($in_use) |
|
| 3179 | - $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
| 3363 | + if ($in_use) { |
|
| 3364 | + $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
| 3365 | + } |
|
| 3180 | 3366 | |
| 3181 | 3367 | // if more is needed, request it |
| 3182 | 3368 | if ($memory_current < $memory_needed) |
@@ -3199,8 +3385,9 @@ discard block |
||
| 3199 | 3385 | */ |
| 3200 | 3386 | function memoryReturnBytes($val) |
| 3201 | 3387 | { |
| 3202 | - if (is_integer($val)) |
|
| 3203 | - return $val; |
|
| 3388 | + if (is_integer($val)) { |
|
| 3389 | + return $val; |
|
| 3390 | + } |
|
| 3204 | 3391 | |
| 3205 | 3392 | // Separate the number from the designator |
| 3206 | 3393 | $val = trim($val); |
@@ -3236,10 +3423,11 @@ discard block |
||
| 3236 | 3423 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
| 3237 | 3424 | |
| 3238 | 3425 | // Are we debugging the template/html content? |
| 3239 | - if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) |
|
| 3240 | - header('Content-Type: application/xhtml+xml'); |
|
| 3241 | - elseif (!isset($_REQUEST['xml'])) |
|
| 3242 | - header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3426 | + if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) { |
|
| 3427 | + header('Content-Type: application/xhtml+xml'); |
|
| 3428 | + } elseif (!isset($_REQUEST['xml'])) { |
|
| 3429 | + header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3430 | + } |
|
| 3243 | 3431 | } |
| 3244 | 3432 | |
| 3245 | 3433 | header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
@@ -3248,8 +3436,9 @@ discard block |
||
| 3248 | 3436 | if ($context['in_maintenance'] && $context['user']['is_admin']) |
| 3249 | 3437 | { |
| 3250 | 3438 | $position = array_search('body', $context['template_layers']); |
| 3251 | - if ($position === false) |
|
| 3252 | - $position = array_search('main', $context['template_layers']); |
|
| 3439 | + if ($position === false) { |
|
| 3440 | + $position = array_search('main', $context['template_layers']); |
|
| 3441 | + } |
|
| 3253 | 3442 | |
| 3254 | 3443 | if ($position !== false) |
| 3255 | 3444 | { |
@@ -3277,15 +3466,15 @@ discard block |
||
| 3277 | 3466 | |
| 3278 | 3467 | foreach ($securityFiles as $i => $securityFile) |
| 3279 | 3468 | { |
| 3280 | - if (!file_exists($boarddir . '/' . $securityFile)) |
|
| 3281 | - unset($securityFiles[$i]); |
|
| 3469 | + if (!file_exists($boarddir . '/' . $securityFile)) { |
|
| 3470 | + unset($securityFiles[$i]); |
|
| 3471 | + } |
|
| 3282 | 3472 | } |
| 3283 | 3473 | |
| 3284 | 3474 | // We are already checking so many files...just few more doesn't make any difference! :P |
| 3285 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
| 3286 | - $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
| 3287 | - |
|
| 3288 | - else |
|
| 3475 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
| 3476 | + $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
| 3477 | + } else |
|
| 3289 | 3478 | { |
| 3290 | 3479 | $path = $modSettings['attachmentUploadDir']; |
| 3291 | 3480 | $id_folder_thumb = 1; |
@@ -3294,8 +3483,9 @@ discard block |
||
| 3294 | 3483 | secureDirectory($cachedir); |
| 3295 | 3484 | |
| 3296 | 3485 | // If agreement is enabled, at least the english version shall exists |
| 3297 | - if ($modSettings['requireAgreement']) |
|
| 3298 | - $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
| 3486 | + if ($modSettings['requireAgreement']) { |
|
| 3487 | + $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
| 3488 | + } |
|
| 3299 | 3489 | |
| 3300 | 3490 | if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement)) |
| 3301 | 3491 | { |
@@ -3310,18 +3500,21 @@ discard block |
||
| 3310 | 3500 | echo ' |
| 3311 | 3501 | ', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>'; |
| 3312 | 3502 | |
| 3313 | - if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') |
|
| 3314 | - echo ' |
|
| 3503 | + if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') { |
|
| 3504 | + echo ' |
|
| 3315 | 3505 | ', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>'; |
| 3506 | + } |
|
| 3316 | 3507 | } |
| 3317 | 3508 | |
| 3318 | - if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) |
|
| 3319 | - echo ' |
|
| 3509 | + if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) { |
|
| 3510 | + echo ' |
|
| 3320 | 3511 | <strong>', $txt['cache_writable'], '</strong><br>'; |
| 3512 | + } |
|
| 3321 | 3513 | |
| 3322 | - if (!empty($agreement)) |
|
| 3323 | - echo ' |
|
| 3514 | + if (!empty($agreement)) { |
|
| 3515 | + echo ' |
|
| 3324 | 3516 | <strong>', $txt['agreement_missing'], '</strong><br>'; |
| 3517 | + } |
|
| 3325 | 3518 | |
| 3326 | 3519 | echo ' |
| 3327 | 3520 | </p> |
@@ -3336,16 +3529,18 @@ discard block |
||
| 3336 | 3529 | <div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;"> |
| 3337 | 3530 | ', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']); |
| 3338 | 3531 | |
| 3339 | - if (!empty($_SESSION['ban']['cannot_post']['reason'])) |
|
| 3340 | - echo ' |
|
| 3532 | + if (!empty($_SESSION['ban']['cannot_post']['reason'])) { |
|
| 3533 | + echo ' |
|
| 3341 | 3534 | <div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>'; |
| 3535 | + } |
|
| 3342 | 3536 | |
| 3343 | - if (!empty($_SESSION['ban']['expire_time'])) |
|
| 3344 | - echo ' |
|
| 3537 | + if (!empty($_SESSION['ban']['expire_time'])) { |
|
| 3538 | + echo ' |
|
| 3345 | 3539 | <div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>'; |
| 3346 | - else |
|
| 3347 | - echo ' |
|
| 3540 | + } else { |
|
| 3541 | + echo ' |
|
| 3348 | 3542 | <div>', $txt['your_ban_expires_never'], '</div>'; |
| 3543 | + } |
|
| 3349 | 3544 | |
| 3350 | 3545 | echo ' |
| 3351 | 3546 | </div>'; |
@@ -3361,8 +3556,9 @@ discard block |
||
| 3361 | 3556 | global $forum_copyright, $software_year, $forum_version; |
| 3362 | 3557 | |
| 3363 | 3558 | // Don't display copyright for things like SSI. |
| 3364 | - if (!isset($forum_version) || !isset($software_year)) |
|
| 3365 | - return; |
|
| 3559 | + if (!isset($forum_version) || !isset($software_year)) { |
|
| 3560 | + return; |
|
| 3561 | + } |
|
| 3366 | 3562 | |
| 3367 | 3563 | // Put in the version... |
| 3368 | 3564 | printf($forum_copyright, $forum_version, $software_year); |
@@ -3380,9 +3576,10 @@ discard block |
||
| 3380 | 3576 | $context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3)); |
| 3381 | 3577 | $context['load_queries'] = $db_count; |
| 3382 | 3578 | |
| 3383 | - foreach (array_reverse($context['template_layers']) as $layer) |
|
| 3384 | - loadSubTemplate($layer . '_below', true); |
|
| 3385 | -} |
|
| 3579 | + foreach (array_reverse($context['template_layers']) as $layer) { |
|
| 3580 | + loadSubTemplate($layer . '_below', true); |
|
| 3581 | + } |
|
| 3582 | + } |
|
| 3386 | 3583 | |
| 3387 | 3584 | /** |
| 3388 | 3585 | * Output the Javascript files |
@@ -3413,8 +3610,7 @@ discard block |
||
| 3413 | 3610 | { |
| 3414 | 3611 | echo ' |
| 3415 | 3612 | var ', $key, ';'; |
| 3416 | - } |
|
| 3417 | - else |
|
| 3613 | + } else |
|
| 3418 | 3614 | { |
| 3419 | 3615 | echo ' |
| 3420 | 3616 | var ', $key, ' = ', $value, ';'; |
@@ -3429,26 +3625,27 @@ discard block |
||
| 3429 | 3625 | foreach ($context['javascript_files'] as $id => $js_file) |
| 3430 | 3626 | { |
| 3431 | 3627 | // Last minute call! allow theme authors to disable single files. |
| 3432 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
| 3433 | - continue; |
|
| 3628 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
| 3629 | + continue; |
|
| 3630 | + } |
|
| 3434 | 3631 | |
| 3435 | 3632 | // By default all files don't get minimized unless the file explicitly says so! |
| 3436 | 3633 | if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
| 3437 | 3634 | { |
| 3438 | - if ($do_deferred && !empty($js_file['options']['defer'])) |
|
| 3439 | - $toMinifyDefer[] = $js_file; |
|
| 3440 | - |
|
| 3441 | - elseif (!$do_deferred && empty($js_file['options']['defer'])) |
|
| 3442 | - $toMinify[] = $js_file; |
|
| 3635 | + if ($do_deferred && !empty($js_file['options']['defer'])) { |
|
| 3636 | + $toMinifyDefer[] = $js_file; |
|
| 3637 | + } elseif (!$do_deferred && empty($js_file['options']['defer'])) { |
|
| 3638 | + $toMinify[] = $js_file; |
|
| 3639 | + } |
|
| 3443 | 3640 | |
| 3444 | 3641 | // Grab a random seed. |
| 3445 | - if (!isset($minSeed)) |
|
| 3446 | - $minSeed = $js_file['options']['seed']; |
|
| 3447 | - } |
|
| 3448 | - |
|
| 3449 | - elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) |
|
| 3450 | - echo ' |
|
| 3642 | + if (!isset($minSeed)) { |
|
| 3643 | + $minSeed = $js_file['options']['seed']; |
|
| 3644 | + } |
|
| 3645 | + } elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) { |
|
| 3646 | + echo ' |
|
| 3451 | 3647 | <script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>'; |
| 3648 | + } |
|
| 3452 | 3649 | } |
| 3453 | 3650 | |
| 3454 | 3651 | if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer))) |
@@ -3456,14 +3653,14 @@ discard block |
||
| 3456 | 3653 | $result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred); |
| 3457 | 3654 | |
| 3458 | 3655 | // Minify process couldn't work, print each individual files. |
| 3459 | - if (!empty($result) && is_array($result)) |
|
| 3460 | - foreach ($result as $minFailedFile) |
|
| 3656 | + if (!empty($result) && is_array($result)) { |
|
| 3657 | + foreach ($result as $minFailedFile) |
|
| 3461 | 3658 | echo ' |
| 3462 | 3659 | <script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>'; |
| 3463 | - |
|
| 3464 | - else |
|
| 3465 | - echo ' |
|
| 3660 | + } else { |
|
| 3661 | + echo ' |
|
| 3466 | 3662 | <script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>'; |
| 3663 | + } |
|
| 3467 | 3664 | } |
| 3468 | 3665 | |
| 3469 | 3666 | // Inline JavaScript - Actually useful some times! |
@@ -3474,8 +3671,9 @@ discard block |
||
| 3474 | 3671 | echo ' |
| 3475 | 3672 | <script>'; |
| 3476 | 3673 | |
| 3477 | - foreach ($context['javascript_inline']['defer'] as $js_code) |
|
| 3478 | - echo $js_code; |
|
| 3674 | + foreach ($context['javascript_inline']['defer'] as $js_code) { |
|
| 3675 | + echo $js_code; |
|
| 3676 | + } |
|
| 3479 | 3677 | |
| 3480 | 3678 | echo ' |
| 3481 | 3679 | </script>'; |
@@ -3486,8 +3684,9 @@ discard block |
||
| 3486 | 3684 | echo ' |
| 3487 | 3685 | <script>'; |
| 3488 | 3686 | |
| 3489 | - foreach ($context['javascript_inline']['standard'] as $js_code) |
|
| 3490 | - echo $js_code; |
|
| 3687 | + foreach ($context['javascript_inline']['standard'] as $js_code) { |
|
| 3688 | + echo $js_code; |
|
| 3689 | + } |
|
| 3491 | 3690 | |
| 3492 | 3691 | echo ' |
| 3493 | 3692 | </script>'; |
@@ -3512,8 +3711,9 @@ discard block |
||
| 3512 | 3711 | foreach ($context['css_files'] as $id => $file) |
| 3513 | 3712 | { |
| 3514 | 3713 | // Last minute call! allow theme authors to disable single files. |
| 3515 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
| 3516 | - continue; |
|
| 3714 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
| 3715 | + continue; |
|
| 3716 | + } |
|
| 3517 | 3717 | |
| 3518 | 3718 | // By default all files don't get minimized unless the file explicitly says so! |
| 3519 | 3719 | if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
@@ -3521,12 +3721,12 @@ discard block |
||
| 3521 | 3721 | $toMinify[] = $file; |
| 3522 | 3722 | |
| 3523 | 3723 | // Grab a random seed. |
| 3524 | - if (!isset($minSeed)) |
|
| 3525 | - $minSeed = $file['options']['seed']; |
|
| 3724 | + if (!isset($minSeed)) { |
|
| 3725 | + $minSeed = $file['options']['seed']; |
|
| 3726 | + } |
|
| 3727 | + } else { |
|
| 3728 | + $normal[] = $file['fileUrl']; |
|
| 3526 | 3729 | } |
| 3527 | - |
|
| 3528 | - else |
|
| 3529 | - $normal[] = $file['fileUrl']; |
|
| 3530 | 3730 | } |
| 3531 | 3731 | |
| 3532 | 3732 | if (!empty($toMinify)) |
@@ -3534,28 +3734,30 @@ discard block |
||
| 3534 | 3734 | $result = custMinify($toMinify, 'css'); |
| 3535 | 3735 | |
| 3536 | 3736 | // Minify process couldn't work, print each individual files. |
| 3537 | - if (!empty($result) && is_array($result)) |
|
| 3538 | - foreach ($result as $minFailedFile) |
|
| 3737 | + if (!empty($result) && is_array($result)) { |
|
| 3738 | + foreach ($result as $minFailedFile) |
|
| 3539 | 3739 | echo ' |
| 3540 | 3740 | <link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">'; |
| 3541 | - |
|
| 3542 | - else |
|
| 3543 | - echo ' |
|
| 3741 | + } else { |
|
| 3742 | + echo ' |
|
| 3544 | 3743 | <link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">'; |
| 3744 | + } |
|
| 3545 | 3745 | } |
| 3546 | 3746 | |
| 3547 | 3747 | // Print the rest after the minified files. |
| 3548 | - if (!empty($normal)) |
|
| 3549 | - foreach ($normal as $nf) |
|
| 3748 | + if (!empty($normal)) { |
|
| 3749 | + foreach ($normal as $nf) |
|
| 3550 | 3750 | echo ' |
| 3551 | 3751 | <link rel="stylesheet" href="', $nf ,'">'; |
| 3752 | + } |
|
| 3552 | 3753 | |
| 3553 | 3754 | if ($db_show_debug === true) |
| 3554 | 3755 | { |
| 3555 | 3756 | // Try to keep only what's useful. |
| 3556 | 3757 | $repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => ''); |
| 3557 | - foreach ($context['css_files'] as $file) |
|
| 3558 | - $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
| 3758 | + foreach ($context['css_files'] as $file) { |
|
| 3759 | + $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
| 3760 | + } |
|
| 3559 | 3761 | } |
| 3560 | 3762 | |
| 3561 | 3763 | if (!empty($context['css_header'])) |
@@ -3563,9 +3765,10 @@ discard block |
||
| 3563 | 3765 | echo ' |
| 3564 | 3766 | <style>'; |
| 3565 | 3767 | |
| 3566 | - foreach ($context['css_header'] as $css) |
|
| 3567 | - echo $css .' |
|
| 3768 | + foreach ($context['css_header'] as $css) { |
|
| 3769 | + echo $css .' |
|
| 3568 | 3770 | '; |
| 3771 | + } |
|
| 3569 | 3772 | |
| 3570 | 3773 | echo' |
| 3571 | 3774 | </style>'; |
@@ -3590,15 +3793,17 @@ discard block |
||
| 3590 | 3793 | $data = !empty($data) ? $data : false; |
| 3591 | 3794 | $minFailed = array(); |
| 3592 | 3795 | |
| 3593 | - if (empty($type) || empty($data)) |
|
| 3594 | - return false; |
|
| 3796 | + if (empty($type) || empty($data)) { |
|
| 3797 | + return false; |
|
| 3798 | + } |
|
| 3595 | 3799 | |
| 3596 | 3800 | // Did we already did this? |
| 3597 | 3801 | $toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400); |
| 3598 | 3802 | |
| 3599 | 3803 | // Already done? |
| 3600 | - if (!empty($toCache)) |
|
| 3601 | - return true; |
|
| 3804 | + if (!empty($toCache)) { |
|
| 3805 | + return true; |
|
| 3806 | + } |
|
| 3602 | 3807 | |
| 3603 | 3808 | // Yep, need a bunch of files. |
| 3604 | 3809 | require_once($sourcedir . '/minify/src/Minify.php'); |
@@ -3686,8 +3891,9 @@ discard block |
||
| 3686 | 3891 | global $modSettings, $smcFunc; |
| 3687 | 3892 | |
| 3688 | 3893 | // Just make up a nice hash... |
| 3689 | - if ($new) |
|
| 3690 | - return sha1(md5($filename . time()) . mt_rand()); |
|
| 3894 | + if ($new) { |
|
| 3895 | + return sha1(md5($filename . time()) . mt_rand()); |
|
| 3896 | + } |
|
| 3691 | 3897 | |
| 3692 | 3898 | // Grab the file hash if it wasn't added. |
| 3693 | 3899 | // Left this for legacy. |
@@ -3701,23 +3907,25 @@ discard block |
||
| 3701 | 3907 | 'id_attach' => $attachment_id, |
| 3702 | 3908 | )); |
| 3703 | 3909 | |
| 3704 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 3705 | - return false; |
|
| 3910 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 3911 | + return false; |
|
| 3912 | + } |
|
| 3706 | 3913 | |
| 3707 | 3914 | list ($file_hash) = $smcFunc['db_fetch_row']($request); |
| 3708 | 3915 | $smcFunc['db_free_result']($request); |
| 3709 | 3916 | } |
| 3710 | 3917 | |
| 3711 | 3918 | // Still no hash? mmm... |
| 3712 | - if (empty($file_hash)) |
|
| 3713 | - $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
| 3919 | + if (empty($file_hash)) { |
|
| 3920 | + $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
| 3921 | + } |
|
| 3714 | 3922 | |
| 3715 | 3923 | // Are we using multiple directories? |
| 3716 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
| 3717 | - $path = $modSettings['attachmentUploadDir'][$dir]; |
|
| 3718 | - |
|
| 3719 | - else |
|
| 3720 | - $path = $modSettings['attachmentUploadDir']; |
|
| 3924 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
| 3925 | + $path = $modSettings['attachmentUploadDir'][$dir]; |
|
| 3926 | + } else { |
|
| 3927 | + $path = $modSettings['attachmentUploadDir']; |
|
| 3928 | + } |
|
| 3721 | 3929 | |
| 3722 | 3930 | return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; |
| 3723 | 3931 | } |
@@ -3732,8 +3940,9 @@ discard block |
||
| 3732 | 3940 | function ip2range($fullip) |
| 3733 | 3941 | { |
| 3734 | 3942 | // Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.) |
| 3735 | - if ($fullip == 'unknown') |
|
| 3736 | - $fullip = '255.255.255.255'; |
|
| 3943 | + if ($fullip == 'unknown') { |
|
| 3944 | + $fullip = '255.255.255.255'; |
|
| 3945 | + } |
|
| 3737 | 3946 | |
| 3738 | 3947 | $ip_parts = explode('-', $fullip); |
| 3739 | 3948 | $ip_array = array(); |
@@ -3757,10 +3966,11 @@ discard block |
||
| 3757 | 3966 | $ip_array['low'] = $ip_parts[0]; |
| 3758 | 3967 | $ip_array['high'] = $ip_parts[1]; |
| 3759 | 3968 | return $ip_array; |
| 3760 | - } |
|
| 3761 | - elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.* |
|
| 3969 | + } elseif (count($ip_parts) == 2) { |
|
| 3970 | + // if ip 22.22.*-22.22.* |
|
| 3762 | 3971 | { |
| 3763 | 3972 | $valid_low = isValidIP($ip_parts[0]); |
| 3973 | + } |
|
| 3764 | 3974 | $valid_high = isValidIP($ip_parts[1]); |
| 3765 | 3975 | $count = 0; |
| 3766 | 3976 | $mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); |
@@ -3775,7 +3985,9 @@ discard block |
||
| 3775 | 3985 | $ip_parts[0] .= $mode . $min; |
| 3776 | 3986 | $valid_low = isValidIP($ip_parts[0]); |
| 3777 | 3987 | $count++; |
| 3778 | - if ($count > 9) break; |
|
| 3988 | + if ($count > 9) { |
|
| 3989 | + break; |
|
| 3990 | + } |
|
| 3779 | 3991 | } |
| 3780 | 3992 | } |
| 3781 | 3993 | |
@@ -3789,7 +4001,9 @@ discard block |
||
| 3789 | 4001 | $ip_parts[1] .= $mode . $max; |
| 3790 | 4002 | $valid_high = isValidIP($ip_parts[1]); |
| 3791 | 4003 | $count++; |
| 3792 | - if ($count > 9) break; |
|
| 4004 | + if ($count > 9) { |
|
| 4005 | + break; |
|
| 4006 | + } |
|
| 3793 | 4007 | } |
| 3794 | 4008 | } |
| 3795 | 4009 | |
@@ -3814,46 +4028,54 @@ discard block |
||
| 3814 | 4028 | { |
| 3815 | 4029 | global $modSettings; |
| 3816 | 4030 | |
| 3817 | - if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) |
|
| 3818 | - return $host; |
|
| 4031 | + if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) { |
|
| 4032 | + return $host; |
|
| 4033 | + } |
|
| 3819 | 4034 | $t = microtime(); |
| 3820 | 4035 | |
| 3821 | 4036 | // Try the Linux host command, perhaps? |
| 3822 | 4037 | if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1) |
| 3823 | 4038 | { |
| 3824 | - if (!isset($modSettings['host_to_dis'])) |
|
| 3825 | - $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
| 3826 | - else |
|
| 3827 | - $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
| 4039 | + if (!isset($modSettings['host_to_dis'])) { |
|
| 4040 | + $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
| 4041 | + } else { |
|
| 4042 | + $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
| 4043 | + } |
|
| 3828 | 4044 | |
| 3829 | 4045 | // Did host say it didn't find anything? |
| 3830 | - if (strpos($test, 'not found') !== false) |
|
| 3831 | - $host = ''; |
|
| 4046 | + if (strpos($test, 'not found') !== false) { |
|
| 4047 | + $host = ''; |
|
| 4048 | + } |
|
| 3832 | 4049 | // Invalid server option? |
| 3833 | - elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) |
|
| 3834 | - updateSettings(array('host_to_dis' => 1)); |
|
| 4050 | + elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) { |
|
| 4051 | + updateSettings(array('host_to_dis' => 1)); |
|
| 4052 | + } |
|
| 3835 | 4053 | // Maybe it found something, after all? |
| 3836 | - elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) |
|
| 3837 | - $host = $match[1]; |
|
| 4054 | + elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) { |
|
| 4055 | + $host = $match[1]; |
|
| 4056 | + } |
|
| 3838 | 4057 | } |
| 3839 | 4058 | |
| 3840 | 4059 | // This is nslookup; usually only Windows, but possibly some Unix? |
| 3841 | 4060 | if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1) |
| 3842 | 4061 | { |
| 3843 | 4062 | $test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip)); |
| 3844 | - if (strpos($test, 'Non-existent domain') !== false) |
|
| 3845 | - $host = ''; |
|
| 3846 | - elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) |
|
| 3847 | - $host = $match[1]; |
|
| 4063 | + if (strpos($test, 'Non-existent domain') !== false) { |
|
| 4064 | + $host = ''; |
|
| 4065 | + } elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) { |
|
| 4066 | + $host = $match[1]; |
|
| 4067 | + } |
|
| 3848 | 4068 | } |
| 3849 | 4069 | |
| 3850 | 4070 | // This is the last try :/. |
| 3851 | - if (!isset($host) || $host === false) |
|
| 3852 | - $host = @gethostbyaddr($ip); |
|
| 4071 | + if (!isset($host) || $host === false) { |
|
| 4072 | + $host = @gethostbyaddr($ip); |
|
| 4073 | + } |
|
| 3853 | 4074 | |
| 3854 | 4075 | // It took a long time, so let's cache it! |
| 3855 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) |
|
| 3856 | - cache_put_data('hostlookup-' . $ip, $host, 600); |
|
| 4076 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) { |
|
| 4077 | + cache_put_data('hostlookup-' . $ip, $host, 600); |
|
| 4078 | + } |
|
| 3857 | 4079 | |
| 3858 | 4080 | return $host; |
| 3859 | 4081 | } |
@@ -3889,20 +4111,21 @@ discard block |
||
| 3889 | 4111 | { |
| 3890 | 4112 | $encrypted = substr(crypt($word, 'uk'), 2, $max_chars); |
| 3891 | 4113 | $total = 0; |
| 3892 | - for ($i = 0; $i < $max_chars; $i++) |
|
| 3893 | - $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
| 4114 | + for ($i = 0; $i < $max_chars; $i++) { |
|
| 4115 | + $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
| 4116 | + } |
|
| 3894 | 4117 | $returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total; |
| 3895 | 4118 | } |
| 3896 | 4119 | } |
| 3897 | 4120 | return array_unique($returned_ints); |
| 3898 | - } |
|
| 3899 | - else |
|
| 4121 | + } else |
|
| 3900 | 4122 | { |
| 3901 | 4123 | // Trim characters before and after and add slashes for database insertion. |
| 3902 | 4124 | $returned_words = array(); |
| 3903 | - foreach ($words as $word) |
|
| 3904 | - if (($word = trim($word, '-_\'')) !== '') |
|
| 4125 | + foreach ($words as $word) { |
|
| 4126 | + if (($word = trim($word, '-_\'')) !== '') |
|
| 3905 | 4127 | $returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars); |
| 4128 | + } |
|
| 3906 | 4129 | |
| 3907 | 4130 | // Filter out all words that occur more than once. |
| 3908 | 4131 | return array_unique($returned_words); |
@@ -3924,16 +4147,18 @@ discard block |
||
| 3924 | 4147 | global $settings, $txt; |
| 3925 | 4148 | |
| 3926 | 4149 | // Does the current loaded theme have this and we are not forcing the usage of this function? |
| 3927 | - if (function_exists('template_create_button') && !$force_use) |
|
| 3928 | - return template_create_button($name, $alt, $label = '', $custom = ''); |
|
| 4150 | + if (function_exists('template_create_button') && !$force_use) { |
|
| 4151 | + return template_create_button($name, $alt, $label = '', $custom = ''); |
|
| 4152 | + } |
|
| 3929 | 4153 | |
| 3930 | - if (!$settings['use_image_buttons']) |
|
| 3931 | - return $txt[$alt]; |
|
| 3932 | - elseif (!empty($settings['use_buttons'])) |
|
| 3933 | - return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
| 3934 | - else |
|
| 3935 | - return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
| 3936 | -} |
|
| 4154 | + if (!$settings['use_image_buttons']) { |
|
| 4155 | + return $txt[$alt]; |
|
| 4156 | + } elseif (!empty($settings['use_buttons'])) { |
|
| 4157 | + return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
| 4158 | + } else { |
|
| 4159 | + return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
| 4160 | + } |
|
| 4161 | + } |
|
| 3937 | 4162 | |
| 3938 | 4163 | /** |
| 3939 | 4164 | * Sets up all of the top menu buttons |
@@ -3976,9 +4201,10 @@ discard block |
||
| 3976 | 4201 | var user_menus = new smc_PopupMenu(); |
| 3977 | 4202 | user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); |
| 3978 | 4203 | user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); |
| 3979 | - if ($context['allow_pm']) |
|
| 3980 | - addInlineJavaScript(' |
|
| 4204 | + if ($context['allow_pm']) { |
|
| 4205 | + addInlineJavaScript(' |
|
| 3981 | 4206 | user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); |
| 4207 | + } |
|
| 3982 | 4208 | |
| 3983 | 4209 | if (!empty($modSettings['enable_ajax_alerts'])) |
| 3984 | 4210 | { |
@@ -4138,88 +4364,96 @@ discard block |
||
| 4138 | 4364 | |
| 4139 | 4365 | // Now we put the buttons in the context so the theme can use them. |
| 4140 | 4366 | $menu_buttons = array(); |
| 4141 | - foreach ($buttons as $act => $button) |
|
| 4142 | - if (!empty($button['show'])) |
|
| 4367 | + foreach ($buttons as $act => $button) { |
|
| 4368 | + if (!empty($button['show'])) |
|
| 4143 | 4369 | { |
| 4144 | 4370 | $button['active_button'] = false; |
| 4371 | + } |
|
| 4145 | 4372 | |
| 4146 | 4373 | // This button needs some action. |
| 4147 | - if (isset($button['action_hook'])) |
|
| 4148 | - $needs_action_hook = true; |
|
| 4374 | + if (isset($button['action_hook'])) { |
|
| 4375 | + $needs_action_hook = true; |
|
| 4376 | + } |
|
| 4149 | 4377 | |
| 4150 | 4378 | // Make sure the last button truly is the last button. |
| 4151 | 4379 | if (!empty($button['is_last'])) |
| 4152 | 4380 | { |
| 4153 | - if (isset($last_button)) |
|
| 4154 | - unset($menu_buttons[$last_button]['is_last']); |
|
| 4381 | + if (isset($last_button)) { |
|
| 4382 | + unset($menu_buttons[$last_button]['is_last']); |
|
| 4383 | + } |
|
| 4155 | 4384 | $last_button = $act; |
| 4156 | 4385 | } |
| 4157 | 4386 | |
| 4158 | 4387 | // Go through the sub buttons if there are any. |
| 4159 | - if (!empty($button['sub_buttons'])) |
|
| 4160 | - foreach ($button['sub_buttons'] as $key => $subbutton) |
|
| 4388 | + if (!empty($button['sub_buttons'])) { |
|
| 4389 | + foreach ($button['sub_buttons'] as $key => $subbutton) |
|
| 4161 | 4390 | { |
| 4162 | 4391 | if (empty($subbutton['show'])) |
| 4163 | 4392 | unset($button['sub_buttons'][$key]); |
| 4393 | + } |
|
| 4164 | 4394 | |
| 4165 | 4395 | // 2nd level sub buttons next... |
| 4166 | 4396 | if (!empty($subbutton['sub_buttons'])) |
| 4167 | 4397 | { |
| 4168 | 4398 | foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2) |
| 4169 | 4399 | { |
| 4170 | - if (empty($sub_button2['show'])) |
|
| 4171 | - unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
| 4400 | + if (empty($sub_button2['show'])) { |
|
| 4401 | + unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
| 4402 | + } |
|
| 4172 | 4403 | } |
| 4173 | 4404 | } |
| 4174 | 4405 | } |
| 4175 | 4406 | |
| 4176 | 4407 | // Does this button have its own icon? |
| 4177 | - if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) |
|
| 4178 | - $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4179 | - elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) |
|
| 4180 | - $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4181 | - elseif (isset($button['icon'])) |
|
| 4182 | - $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
| 4183 | - else |
|
| 4184 | - $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
| 4408 | + if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) { |
|
| 4409 | + $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4410 | + } elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) { |
|
| 4411 | + $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
| 4412 | + } elseif (isset($button['icon'])) { |
|
| 4413 | + $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
| 4414 | + } else { |
|
| 4415 | + $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
| 4416 | + } |
|
| 4185 | 4417 | |
| 4186 | 4418 | $menu_buttons[$act] = $button; |
| 4187 | 4419 | } |
| 4188 | 4420 | |
| 4189 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 4190 | - cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
| 4421 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 4422 | + cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
| 4423 | + } |
|
| 4191 | 4424 | } |
| 4192 | 4425 | |
| 4193 | 4426 | $context['menu_buttons'] = $menu_buttons; |
| 4194 | 4427 | |
| 4195 | 4428 | // Logging out requires the session id in the url. |
| 4196 | - if (isset($context['menu_buttons']['logout'])) |
|
| 4197 | - $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
| 4429 | + if (isset($context['menu_buttons']['logout'])) { |
|
| 4430 | + $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
| 4431 | + } |
|
| 4198 | 4432 | |
| 4199 | 4433 | // Figure out which action we are doing so we can set the active tab. |
| 4200 | 4434 | // Default to home. |
| 4201 | 4435 | $current_action = 'home'; |
| 4202 | 4436 | |
| 4203 | - if (isset($context['menu_buttons'][$context['current_action']])) |
|
| 4204 | - $current_action = $context['current_action']; |
|
| 4205 | - elseif ($context['current_action'] == 'search2') |
|
| 4206 | - $current_action = 'search'; |
|
| 4207 | - elseif ($context['current_action'] == 'theme') |
|
| 4208 | - $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
| 4209 | - elseif ($context['current_action'] == 'register2') |
|
| 4210 | - $current_action = 'register'; |
|
| 4211 | - elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) |
|
| 4212 | - $current_action = 'login'; |
|
| 4213 | - elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) |
|
| 4214 | - $current_action = 'moderate'; |
|
| 4437 | + if (isset($context['menu_buttons'][$context['current_action']])) { |
|
| 4438 | + $current_action = $context['current_action']; |
|
| 4439 | + } elseif ($context['current_action'] == 'search2') { |
|
| 4440 | + $current_action = 'search'; |
|
| 4441 | + } elseif ($context['current_action'] == 'theme') { |
|
| 4442 | + $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
| 4443 | + } elseif ($context['current_action'] == 'register2') { |
|
| 4444 | + $current_action = 'register'; |
|
| 4445 | + } elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) { |
|
| 4446 | + $current_action = 'login'; |
|
| 4447 | + } elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) { |
|
| 4448 | + $current_action = 'moderate'; |
|
| 4449 | + } |
|
| 4215 | 4450 | |
| 4216 | 4451 | // There are certain exceptions to the above where we don't want anything on the menu highlighted. |
| 4217 | 4452 | if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner'])) |
| 4218 | 4453 | { |
| 4219 | 4454 | $current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile'; |
| 4220 | 4455 | $context[$current_action] = true; |
| 4221 | - } |
|
| 4222 | - elseif ($context['current_action'] == 'pm') |
|
| 4456 | + } elseif ($context['current_action'] == 'pm') |
|
| 4223 | 4457 | { |
| 4224 | 4458 | $current_action = 'self_pm'; |
| 4225 | 4459 | $context['self_pm'] = true; |
@@ -4262,12 +4496,14 @@ discard block |
||
| 4262 | 4496 | } |
| 4263 | 4497 | |
| 4264 | 4498 | // Not all actions are simple. |
| 4265 | - if (!empty($needs_action_hook)) |
|
| 4266 | - call_integration_hook('integrate_current_action', array(&$current_action)); |
|
| 4499 | + if (!empty($needs_action_hook)) { |
|
| 4500 | + call_integration_hook('integrate_current_action', array(&$current_action)); |
|
| 4501 | + } |
|
| 4267 | 4502 | |
| 4268 | - if (isset($context['menu_buttons'][$current_action])) |
|
| 4269 | - $context['menu_buttons'][$current_action]['active_button'] = true; |
|
| 4270 | -} |
|
| 4503 | + if (isset($context['menu_buttons'][$current_action])) { |
|
| 4504 | + $context['menu_buttons'][$current_action]['active_button'] = true; |
|
| 4505 | + } |
|
| 4506 | + } |
|
| 4271 | 4507 | |
| 4272 | 4508 | /** |
| 4273 | 4509 | * Generate a random seed and ensure it's stored in settings. |
@@ -4291,16 +4527,19 @@ discard block |
||
| 4291 | 4527 | global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug; |
| 4292 | 4528 | global $context, $txt; |
| 4293 | 4529 | |
| 4294 | - if ($db_show_debug === true) |
|
| 4295 | - $context['debug']['hooks'][] = $hook; |
|
| 4530 | + if ($db_show_debug === true) { |
|
| 4531 | + $context['debug']['hooks'][] = $hook; |
|
| 4532 | + } |
|
| 4296 | 4533 | |
| 4297 | 4534 | // Need to have some control. |
| 4298 | - if (!isset($context['instances'])) |
|
| 4299 | - $context['instances'] = array(); |
|
| 4535 | + if (!isset($context['instances'])) { |
|
| 4536 | + $context['instances'] = array(); |
|
| 4537 | + } |
|
| 4300 | 4538 | |
| 4301 | 4539 | $results = array(); |
| 4302 | - if (empty($modSettings[$hook])) |
|
| 4303 | - return $results; |
|
| 4540 | + if (empty($modSettings[$hook])) { |
|
| 4541 | + return $results; |
|
| 4542 | + } |
|
| 4304 | 4543 | |
| 4305 | 4544 | // Define some needed vars. |
| 4306 | 4545 | $function = false; |
@@ -4310,14 +4549,16 @@ discard block |
||
| 4310 | 4549 | foreach ($functions as $function) |
| 4311 | 4550 | { |
| 4312 | 4551 | // Hook has been marked as "disabled". Skip it! |
| 4313 | - if (strpos($function, '!') !== false) |
|
| 4314 | - continue; |
|
| 4552 | + if (strpos($function, '!') !== false) { |
|
| 4553 | + continue; |
|
| 4554 | + } |
|
| 4315 | 4555 | |
| 4316 | 4556 | $call = call_helper($function, true); |
| 4317 | 4557 | |
| 4318 | 4558 | // Is it valid? |
| 4319 | - if (!empty($call)) |
|
| 4320 | - $results[$function] = call_user_func_array($call, $parameters); |
|
| 4559 | + if (!empty($call)) { |
|
| 4560 | + $results[$function] = call_user_func_array($call, $parameters); |
|
| 4561 | + } |
|
| 4321 | 4562 | |
| 4322 | 4563 | // Whatever it was suppose to call, it failed :( |
| 4323 | 4564 | elseif (!empty($function)) |
@@ -4333,8 +4574,9 @@ discard block |
||
| 4333 | 4574 | } |
| 4334 | 4575 | |
| 4335 | 4576 | // "Assume" the file resides on $boarddir somewhere... |
| 4336 | - else |
|
| 4337 | - log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
| 4577 | + else { |
|
| 4578 | + log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
| 4579 | + } |
|
| 4338 | 4580 | } |
| 4339 | 4581 | } |
| 4340 | 4582 | |
@@ -4356,12 +4598,14 @@ discard block |
||
| 4356 | 4598 | global $smcFunc, $modSettings; |
| 4357 | 4599 | |
| 4358 | 4600 | // Any objects? |
| 4359 | - if ($object) |
|
| 4360 | - $function = $function . '#'; |
|
| 4601 | + if ($object) { |
|
| 4602 | + $function = $function . '#'; |
|
| 4603 | + } |
|
| 4361 | 4604 | |
| 4362 | 4605 | // Any files to load? |
| 4363 | - if (!empty($file) && is_string($file)) |
|
| 4364 | - $function = $file . (!empty($function) ? '|' . $function : ''); |
|
| 4606 | + if (!empty($file) && is_string($file)) { |
|
| 4607 | + $function = $file . (!empty($function) ? '|' . $function : ''); |
|
| 4608 | + } |
|
| 4365 | 4609 | |
| 4366 | 4610 | // Get the correct string. |
| 4367 | 4611 | $integration_call = $function; |
@@ -4383,13 +4627,14 @@ discard block |
||
| 4383 | 4627 | if (!empty($current_functions)) |
| 4384 | 4628 | { |
| 4385 | 4629 | $current_functions = explode(',', $current_functions); |
| 4386 | - if (in_array($integration_call, $current_functions)) |
|
| 4387 | - return; |
|
| 4630 | + if (in_array($integration_call, $current_functions)) { |
|
| 4631 | + return; |
|
| 4632 | + } |
|
| 4388 | 4633 | |
| 4389 | 4634 | $permanent_functions = array_merge($current_functions, array($integration_call)); |
| 4635 | + } else { |
|
| 4636 | + $permanent_functions = array($integration_call); |
|
| 4390 | 4637 | } |
| 4391 | - else |
|
| 4392 | - $permanent_functions = array($integration_call); |
|
| 4393 | 4638 | |
| 4394 | 4639 | updateSettings(array($hook => implode(',', $permanent_functions))); |
| 4395 | 4640 | } |
@@ -4398,8 +4643,9 @@ discard block |
||
| 4398 | 4643 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
| 4399 | 4644 | |
| 4400 | 4645 | // Do nothing, if it's already there. |
| 4401 | - if (in_array($integration_call, $functions)) |
|
| 4402 | - return; |
|
| 4646 | + if (in_array($integration_call, $functions)) { |
|
| 4647 | + return; |
|
| 4648 | + } |
|
| 4403 | 4649 | |
| 4404 | 4650 | $functions[] = $integration_call; |
| 4405 | 4651 | $modSettings[$hook] = implode(',', $functions); |
@@ -4422,12 +4668,14 @@ discard block |
||
| 4422 | 4668 | global $smcFunc, $modSettings; |
| 4423 | 4669 | |
| 4424 | 4670 | // Any objects? |
| 4425 | - if ($object) |
|
| 4426 | - $function = $function . '#'; |
|
| 4671 | + if ($object) { |
|
| 4672 | + $function = $function . '#'; |
|
| 4673 | + } |
|
| 4427 | 4674 | |
| 4428 | 4675 | // Any files to load? |
| 4429 | - if (!empty($file) && is_string($file)) |
|
| 4430 | - $function = $file . '|' . $function; |
|
| 4676 | + if (!empty($file) && is_string($file)) { |
|
| 4677 | + $function = $file . '|' . $function; |
|
| 4678 | + } |
|
| 4431 | 4679 | |
| 4432 | 4680 | // Get the correct string. |
| 4433 | 4681 | $integration_call = $function; |
@@ -4448,16 +4696,18 @@ discard block |
||
| 4448 | 4696 | { |
| 4449 | 4697 | $current_functions = explode(',', $current_functions); |
| 4450 | 4698 | |
| 4451 | - if (in_array($integration_call, $current_functions)) |
|
| 4452 | - updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
| 4699 | + if (in_array($integration_call, $current_functions)) { |
|
| 4700 | + updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
| 4701 | + } |
|
| 4453 | 4702 | } |
| 4454 | 4703 | |
| 4455 | 4704 | // Turn the function list into something usable. |
| 4456 | 4705 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
| 4457 | 4706 | |
| 4458 | 4707 | // You can only remove it if it's available. |
| 4459 | - if (!in_array($integration_call, $functions)) |
|
| 4460 | - return; |
|
| 4708 | + if (!in_array($integration_call, $functions)) { |
|
| 4709 | + return; |
|
| 4710 | + } |
|
| 4461 | 4711 | |
| 4462 | 4712 | $functions = array_diff($functions, array($integration_call)); |
| 4463 | 4713 | $modSettings[$hook] = implode(',', $functions); |
@@ -4478,17 +4728,20 @@ discard block |
||
| 4478 | 4728 | global $context, $smcFunc, $txt, $db_show_debug; |
| 4479 | 4729 | |
| 4480 | 4730 | // Really? |
| 4481 | - if (empty($string)) |
|
| 4482 | - return false; |
|
| 4731 | + if (empty($string)) { |
|
| 4732 | + return false; |
|
| 4733 | + } |
|
| 4483 | 4734 | |
| 4484 | 4735 | // An array? should be a "callable" array IE array(object/class, valid_callable). |
| 4485 | 4736 | // A closure? should be a callable one. |
| 4486 | - if (is_array($string) || $string instanceof Closure) |
|
| 4487 | - return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
| 4737 | + if (is_array($string) || $string instanceof Closure) { |
|
| 4738 | + return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
| 4739 | + } |
|
| 4488 | 4740 | |
| 4489 | 4741 | // No full objects, sorry! pass a method or a property instead! |
| 4490 | - if (is_object($string)) |
|
| 4491 | - return false; |
|
| 4742 | + if (is_object($string)) { |
|
| 4743 | + return false; |
|
| 4744 | + } |
|
| 4492 | 4745 | |
| 4493 | 4746 | // Stay vitaminized my friends... |
| 4494 | 4747 | $string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string)); |
@@ -4500,8 +4753,9 @@ discard block |
||
| 4500 | 4753 | $string = load_file($string); |
| 4501 | 4754 | |
| 4502 | 4755 | // Loaded file failed |
| 4503 | - if (empty($string)) |
|
| 4504 | - return false; |
|
| 4756 | + if (empty($string)) { |
|
| 4757 | + return false; |
|
| 4758 | + } |
|
| 4505 | 4759 | |
| 4506 | 4760 | // Found a method. |
| 4507 | 4761 | if (strpos($string, '::') !== false) |
@@ -4522,8 +4776,9 @@ discard block |
||
| 4522 | 4776 | // Add another one to the list. |
| 4523 | 4777 | if ($db_show_debug === true) |
| 4524 | 4778 | { |
| 4525 | - if (!isset($context['debug']['instances'])) |
|
| 4526 | - $context['debug']['instances'] = array(); |
|
| 4779 | + if (!isset($context['debug']['instances'])) { |
|
| 4780 | + $context['debug']['instances'] = array(); |
|
| 4781 | + } |
|
| 4527 | 4782 | |
| 4528 | 4783 | $context['debug']['instances'][$class] = $class; |
| 4529 | 4784 | } |
@@ -4533,13 +4788,15 @@ discard block |
||
| 4533 | 4788 | } |
| 4534 | 4789 | |
| 4535 | 4790 | // Right then. This is a call to a static method. |
| 4536 | - else |
|
| 4537 | - $func = array($class, $method); |
|
| 4791 | + else { |
|
| 4792 | + $func = array($class, $method); |
|
| 4793 | + } |
|
| 4538 | 4794 | } |
| 4539 | 4795 | |
| 4540 | 4796 | // Nope! just a plain regular function. |
| 4541 | - else |
|
| 4542 | - $func = $string; |
|
| 4797 | + else { |
|
| 4798 | + $func = $string; |
|
| 4799 | + } |
|
| 4543 | 4800 | |
| 4544 | 4801 | // Right, we got what we need, time to do some checks. |
| 4545 | 4802 | if (!is_callable($func, false, $callable_name)) |
@@ -4555,17 +4812,18 @@ discard block |
||
| 4555 | 4812 | else |
| 4556 | 4813 | { |
| 4557 | 4814 | // What are we gonna do about it? |
| 4558 | - if ($return) |
|
| 4559 | - return $func; |
|
| 4815 | + if ($return) { |
|
| 4816 | + return $func; |
|
| 4817 | + } |
|
| 4560 | 4818 | |
| 4561 | 4819 | // If this is a plain function, avoid the heat of calling call_user_func(). |
| 4562 | 4820 | else |
| 4563 | 4821 | { |
| 4564 | - if (is_array($func)) |
|
| 4565 | - call_user_func($func); |
|
| 4566 | - |
|
| 4567 | - else |
|
| 4568 | - $func(); |
|
| 4822 | + if (is_array($func)) { |
|
| 4823 | + call_user_func($func); |
|
| 4824 | + } else { |
|
| 4825 | + $func(); |
|
| 4826 | + } |
|
| 4569 | 4827 | } |
| 4570 | 4828 | } |
| 4571 | 4829 | } |
@@ -4582,31 +4840,34 @@ discard block |
||
| 4582 | 4840 | { |
| 4583 | 4841 | global $sourcedir, $txt, $boarddir, $settings; |
| 4584 | 4842 | |
| 4585 | - if (empty($string)) |
|
| 4586 | - return false; |
|
| 4843 | + if (empty($string)) { |
|
| 4844 | + return false; |
|
| 4845 | + } |
|
| 4587 | 4846 | |
| 4588 | 4847 | if (strpos($string, '|') !== false) |
| 4589 | 4848 | { |
| 4590 | 4849 | list ($file, $string) = explode('|', $string); |
| 4591 | 4850 | |
| 4592 | 4851 | // Match the wildcards to their regular vars. |
| 4593 | - if (empty($settings['theme_dir'])) |
|
| 4594 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
| 4595 | - |
|
| 4596 | - else |
|
| 4597 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
| 4852 | + if (empty($settings['theme_dir'])) { |
|
| 4853 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
| 4854 | + } else { |
|
| 4855 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
| 4856 | + } |
|
| 4598 | 4857 | |
| 4599 | 4858 | // Load the file if it can be loaded. |
| 4600 | - if (file_exists($absPath)) |
|
| 4601 | - require_once($absPath); |
|
| 4859 | + if (file_exists($absPath)) { |
|
| 4860 | + require_once($absPath); |
|
| 4861 | + } |
|
| 4602 | 4862 | |
| 4603 | 4863 | // No? try a fallback to $sourcedir |
| 4604 | 4864 | else |
| 4605 | 4865 | { |
| 4606 | 4866 | $absPath = $sourcedir .'/'. $file; |
| 4607 | 4867 | |
| 4608 | - if (file_exists($absPath)) |
|
| 4609 | - require_once($absPath); |
|
| 4868 | + if (file_exists($absPath)) { |
|
| 4869 | + require_once($absPath); |
|
| 4870 | + } |
|
| 4610 | 4871 | |
| 4611 | 4872 | // Sorry, can't do much for you at this point. |
| 4612 | 4873 | else |
@@ -4633,8 +4894,9 @@ discard block |
||
| 4633 | 4894 | global $user_info, $smcFunc; |
| 4634 | 4895 | |
| 4635 | 4896 | // Make sure we have something to work with. |
| 4636 | - if (empty($topic)) |
|
| 4637 | - return array(); |
|
| 4897 | + if (empty($topic)) { |
|
| 4898 | + return array(); |
|
| 4899 | + } |
|
| 4638 | 4900 | |
| 4639 | 4901 | |
| 4640 | 4902 | // We already know the number of likes per message, we just want to know whether the current user liked it or not. |
@@ -4657,8 +4919,9 @@ discard block |
||
| 4657 | 4919 | 'topic' => $topic, |
| 4658 | 4920 | ) |
| 4659 | 4921 | ); |
| 4660 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 4661 | - $temp[] = (int) $row['content_id']; |
|
| 4922 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 4923 | + $temp[] = (int) $row['content_id']; |
|
| 4924 | + } |
|
| 4662 | 4925 | |
| 4663 | 4926 | cache_put_data($cache_key, $temp, $ttl); |
| 4664 | 4927 | } |
@@ -4679,8 +4942,9 @@ discard block |
||
| 4679 | 4942 | { |
| 4680 | 4943 | global $context; |
| 4681 | 4944 | |
| 4682 | - if (empty($string)) |
|
| 4683 | - return $string; |
|
| 4945 | + if (empty($string)) { |
|
| 4946 | + return $string; |
|
| 4947 | + } |
|
| 4684 | 4948 | |
| 4685 | 4949 | // UTF-8 occurences of MS special characters |
| 4686 | 4950 | $findchars_utf8 = array( |
@@ -4721,10 +4985,11 @@ discard block |
||
| 4721 | 4985 | '--', // — |
| 4722 | 4986 | ); |
| 4723 | 4987 | |
| 4724 | - if ($context['utf8']) |
|
| 4725 | - $string = str_replace($findchars_utf8, $replacechars, $string); |
|
| 4726 | - else |
|
| 4727 | - $string = str_replace($findchars_iso, $replacechars, $string); |
|
| 4988 | + if ($context['utf8']) { |
|
| 4989 | + $string = str_replace($findchars_utf8, $replacechars, $string); |
|
| 4990 | + } else { |
|
| 4991 | + $string = str_replace($findchars_iso, $replacechars, $string); |
|
| 4992 | + } |
|
| 4728 | 4993 | |
| 4729 | 4994 | return $string; |
| 4730 | 4995 | } |
@@ -4743,49 +5008,59 @@ discard block |
||
| 4743 | 5008 | { |
| 4744 | 5009 | global $context; |
| 4745 | 5010 | |
| 4746 | - if (!isset($matches[2])) |
|
| 4747 | - return ''; |
|
| 5011 | + if (!isset($matches[2])) { |
|
| 5012 | + return ''; |
|
| 5013 | + } |
|
| 4748 | 5014 | |
| 4749 | 5015 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
| 4750 | 5016 | |
| 4751 | 5017 | // remove left to right / right to left overrides |
| 4752 | - if ($num === 0x202D || $num === 0x202E) |
|
| 4753 | - return ''; |
|
| 5018 | + if ($num === 0x202D || $num === 0x202E) { |
|
| 5019 | + return ''; |
|
| 5020 | + } |
|
| 4754 | 5021 | |
| 4755 | 5022 | // Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced |
| 4756 | - if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) |
|
| 4757 | - return '&#' . $num . ';'; |
|
| 5023 | + if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) { |
|
| 5024 | + return '&#' . $num . ';'; |
|
| 5025 | + } |
|
| 4758 | 5026 | |
| 4759 | 5027 | if (empty($context['utf8'])) |
| 4760 | 5028 | { |
| 4761 | 5029 | // no control characters |
| 4762 | - if ($num < 0x20) |
|
| 4763 | - return ''; |
|
| 5030 | + if ($num < 0x20) { |
|
| 5031 | + return ''; |
|
| 5032 | + } |
|
| 4764 | 5033 | // text is text |
| 4765 | - elseif ($num < 0x80) |
|
| 4766 | - return chr($num); |
|
| 5034 | + elseif ($num < 0x80) { |
|
| 5035 | + return chr($num); |
|
| 5036 | + } |
|
| 4767 | 5037 | // all others get html-ised |
| 4768 | - else |
|
| 4769 | - return '&#' . $matches[2] . ';'; |
|
| 4770 | - } |
|
| 4771 | - else |
|
| 5038 | + else { |
|
| 5039 | + return '&#' . $matches[2] . ';'; |
|
| 5040 | + } |
|
| 5041 | + } else |
|
| 4772 | 5042 | { |
| 4773 | 5043 | // <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set |
| 4774 | 5044 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text) |
| 4775 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) |
|
| 4776 | - return ''; |
|
| 5045 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) { |
|
| 5046 | + return ''; |
|
| 5047 | + } |
|
| 4777 | 5048 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
| 4778 | - elseif ($num < 0x80) |
|
| 4779 | - return chr($num); |
|
| 5049 | + elseif ($num < 0x80) { |
|
| 5050 | + return chr($num); |
|
| 5051 | + } |
|
| 4780 | 5052 | // <0x800 (2048) |
| 4781 | - elseif ($num < 0x800) |
|
| 4782 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5053 | + elseif ($num < 0x800) { |
|
| 5054 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5055 | + } |
|
| 4783 | 5056 | // < 0x10000 (65536) |
| 4784 | - elseif ($num < 0x10000) |
|
| 4785 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5057 | + elseif ($num < 0x10000) { |
|
| 5058 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5059 | + } |
|
| 4786 | 5060 | // <= 0x10FFFF (1114111) |
| 4787 | - else |
|
| 4788 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5061 | + else { |
|
| 5062 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5063 | + } |
|
| 4789 | 5064 | } |
| 4790 | 5065 | } |
| 4791 | 5066 | |
@@ -4801,28 +5076,34 @@ discard block |
||
| 4801 | 5076 | */ |
| 4802 | 5077 | function fixchar__callback($matches) |
| 4803 | 5078 | { |
| 4804 | - if (!isset($matches[1])) |
|
| 4805 | - return ''; |
|
| 5079 | + if (!isset($matches[1])) { |
|
| 5080 | + return ''; |
|
| 5081 | + } |
|
| 4806 | 5082 | |
| 4807 | 5083 | $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1]; |
| 4808 | 5084 | |
| 4809 | 5085 | // <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set |
| 4810 | 5086 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides |
| 4811 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) |
|
| 4812 | - return ''; |
|
| 5087 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) { |
|
| 5088 | + return ''; |
|
| 5089 | + } |
|
| 4813 | 5090 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
| 4814 | - elseif ($num < 0x80) |
|
| 4815 | - return chr($num); |
|
| 5091 | + elseif ($num < 0x80) { |
|
| 5092 | + return chr($num); |
|
| 5093 | + } |
|
| 4816 | 5094 | // <0x800 (2048) |
| 4817 | - elseif ($num < 0x800) |
|
| 4818 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5095 | + elseif ($num < 0x800) { |
|
| 5096 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5097 | + } |
|
| 4819 | 5098 | // < 0x10000 (65536) |
| 4820 | - elseif ($num < 0x10000) |
|
| 4821 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5099 | + elseif ($num < 0x10000) { |
|
| 5100 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5101 | + } |
|
| 4822 | 5102 | // <= 0x10FFFF (1114111) |
| 4823 | - else |
|
| 4824 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 4825 | -} |
|
| 5103 | + else { |
|
| 5104 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5105 | + } |
|
| 5106 | + } |
|
| 4826 | 5107 | |
| 4827 | 5108 | /** |
| 4828 | 5109 | * Strips out invalid html entities, replaces others with html style { codes |
@@ -4835,17 +5116,19 @@ discard block |
||
| 4835 | 5116 | */ |
| 4836 | 5117 | function entity_fix__callback($matches) |
| 4837 | 5118 | { |
| 4838 | - if (!isset($matches[2])) |
|
| 4839 | - return ''; |
|
| 5119 | + if (!isset($matches[2])) { |
|
| 5120 | + return ''; |
|
| 5121 | + } |
|
| 4840 | 5122 | |
| 4841 | 5123 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
| 4842 | 5124 | |
| 4843 | 5125 | // we don't allow control characters, characters out of range, byte markers, etc |
| 4844 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) |
|
| 4845 | - return ''; |
|
| 4846 | - else |
|
| 4847 | - return '&#' . $num . ';'; |
|
| 4848 | -} |
|
| 5126 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) { |
|
| 5127 | + return ''; |
|
| 5128 | + } else { |
|
| 5129 | + return '&#' . $num . ';'; |
|
| 5130 | + } |
|
| 5131 | + } |
|
| 4849 | 5132 | |
| 4850 | 5133 | /** |
| 4851 | 5134 | * Return a Gravatar URL based on |
@@ -4869,18 +5152,23 @@ discard block |
||
| 4869 | 5152 | $ratings = array('G', 'PG', 'R', 'X'); |
| 4870 | 5153 | $defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'); |
| 4871 | 5154 | $url_params = array(); |
| 4872 | - if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) |
|
| 4873 | - $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
| 4874 | - if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) |
|
| 4875 | - $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
| 4876 | - if (!empty($modSettings['avatar_max_width_external'])) |
|
| 4877 | - $size_string = (int) $modSettings['avatar_max_width_external']; |
|
| 4878 | - if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) |
|
| 4879 | - if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
| 5155 | + if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) { |
|
| 5156 | + $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
| 5157 | + } |
|
| 5158 | + if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) { |
|
| 5159 | + $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
| 5160 | + } |
|
| 5161 | + if (!empty($modSettings['avatar_max_width_external'])) { |
|
| 5162 | + $size_string = (int) $modSettings['avatar_max_width_external']; |
|
| 5163 | + } |
|
| 5164 | + if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) { |
|
| 5165 | + if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
| 4880 | 5166 | $size_string = $modSettings['avatar_max_height_external']; |
| 5167 | + } |
|
| 4881 | 5168 | |
| 4882 | - if (!empty($size_string)) |
|
| 4883 | - $url_params[] = 's=' . $size_string; |
|
| 5169 | + if (!empty($size_string)) { |
|
| 5170 | + $url_params[] = 's=' . $size_string; |
|
| 5171 | + } |
|
| 4884 | 5172 | } |
| 4885 | 5173 | $http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www'; |
| 4886 | 5174 | |
@@ -4991,8 +5279,9 @@ discard block |
||
| 4991 | 5279 | */ |
| 4992 | 5280 | function inet_ptod($ip_address) |
| 4993 | 5281 | { |
| 4994 | - if (!isValidIP($ip_address)) |
|
| 4995 | - return $ip_address; |
|
| 5282 | + if (!isValidIP($ip_address)) { |
|
| 5283 | + return $ip_address; |
|
| 5284 | + } |
|
| 4996 | 5285 | |
| 4997 | 5286 | $bin = inet_pton($ip_address); |
| 4998 | 5287 | return $bin; |
@@ -5004,13 +5293,15 @@ discard block |
||
| 5004 | 5293 | */ |
| 5005 | 5294 | function inet_dtop($bin) |
| 5006 | 5295 | { |
| 5007 | - if(empty($bin)) |
|
| 5008 | - return ''; |
|
| 5296 | + if(empty($bin)) { |
|
| 5297 | + return ''; |
|
| 5298 | + } |
|
| 5009 | 5299 | |
| 5010 | 5300 | global $db_type; |
| 5011 | 5301 | |
| 5012 | - if ($db_type == 'postgresql') |
|
| 5013 | - return $bin; |
|
| 5302 | + if ($db_type == 'postgresql') { |
|
| 5303 | + return $bin; |
|
| 5304 | + } |
|
| 5014 | 5305 | |
| 5015 | 5306 | $ip_address = inet_ntop($bin); |
| 5016 | 5307 | |
@@ -5035,26 +5326,32 @@ discard block |
||
| 5035 | 5326 | */ |
| 5036 | 5327 | function _safe_serialize($value) |
| 5037 | 5328 | { |
| 5038 | - if(is_null($value)) |
|
| 5039 | - return 'N;'; |
|
| 5329 | + if(is_null($value)) { |
|
| 5330 | + return 'N;'; |
|
| 5331 | + } |
|
| 5040 | 5332 | |
| 5041 | - if(is_bool($value)) |
|
| 5042 | - return 'b:'. (int) $value .';'; |
|
| 5333 | + if(is_bool($value)) { |
|
| 5334 | + return 'b:'. (int) $value .';'; |
|
| 5335 | + } |
|
| 5043 | 5336 | |
| 5044 | - if(is_int($value)) |
|
| 5045 | - return 'i:'. $value .';'; |
|
| 5337 | + if(is_int($value)) { |
|
| 5338 | + return 'i:'. $value .';'; |
|
| 5339 | + } |
|
| 5046 | 5340 | |
| 5047 | - if(is_float($value)) |
|
| 5048 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
| 5341 | + if(is_float($value)) { |
|
| 5342 | + return 'd:'. str_replace(',', '.', $value) .';'; |
|
| 5343 | + } |
|
| 5049 | 5344 | |
| 5050 | - if(is_string($value)) |
|
| 5051 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
| 5345 | + if(is_string($value)) { |
|
| 5346 | + return 's:'. strlen($value) .':"'. $value .'";'; |
|
| 5347 | + } |
|
| 5052 | 5348 | |
| 5053 | 5349 | if(is_array($value)) |
| 5054 | 5350 | { |
| 5055 | 5351 | $out = ''; |
| 5056 | - foreach($value as $k => $v) |
|
| 5057 | - $out .= _safe_serialize($k) . _safe_serialize($v); |
|
| 5352 | + foreach($value as $k => $v) { |
|
| 5353 | + $out .= _safe_serialize($k) . _safe_serialize($v); |
|
| 5354 | + } |
|
| 5058 | 5355 | |
| 5059 | 5356 | return 'a:'. count($value) .':{'. $out .'}'; |
| 5060 | 5357 | } |
@@ -5080,8 +5377,9 @@ discard block |
||
| 5080 | 5377 | |
| 5081 | 5378 | $out = _safe_serialize($value); |
| 5082 | 5379 | |
| 5083 | - if (isset($mbIntEnc)) |
|
| 5084 | - mb_internal_encoding($mbIntEnc); |
|
| 5380 | + if (isset($mbIntEnc)) { |
|
| 5381 | + mb_internal_encoding($mbIntEnc); |
|
| 5382 | + } |
|
| 5085 | 5383 | |
| 5086 | 5384 | return $out; |
| 5087 | 5385 | } |
@@ -5098,8 +5396,9 @@ discard block |
||
| 5098 | 5396 | function _safe_unserialize($str) |
| 5099 | 5397 | { |
| 5100 | 5398 | // Input is not a string. |
| 5101 | - if(empty($str) || !is_string($str)) |
|
| 5102 | - return false; |
|
| 5399 | + if(empty($str) || !is_string($str)) { |
|
| 5400 | + return false; |
|
| 5401 | + } |
|
| 5103 | 5402 | |
| 5104 | 5403 | $stack = array(); |
| 5105 | 5404 | $expected = array(); |
@@ -5115,43 +5414,38 @@ discard block |
||
| 5115 | 5414 | while($state != 1) |
| 5116 | 5415 | { |
| 5117 | 5416 | $type = isset($str[0]) ? $str[0] : ''; |
| 5118 | - if($type == '}') |
|
| 5119 | - $str = substr($str, 1); |
|
| 5120 | - |
|
| 5121 | - else if($type == 'N' && $str[1] == ';') |
|
| 5417 | + if($type == '}') { |
|
| 5418 | + $str = substr($str, 1); |
|
| 5419 | + } else if($type == 'N' && $str[1] == ';') |
|
| 5122 | 5420 | { |
| 5123 | 5421 | $value = null; |
| 5124 | 5422 | $str = substr($str, 2); |
| 5125 | - } |
|
| 5126 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
| 5423 | + } else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
| 5127 | 5424 | { |
| 5128 | 5425 | $value = $matches[1] == '1' ? true : false; |
| 5129 | 5426 | $str = substr($str, 4); |
| 5130 | - } |
|
| 5131 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
| 5427 | + } else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
| 5132 | 5428 | { |
| 5133 | 5429 | $value = (int)$matches[1]; |
| 5134 | 5430 | $str = $matches[2]; |
| 5135 | - } |
|
| 5136 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
| 5431 | + } else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
| 5137 | 5432 | { |
| 5138 | 5433 | $value = (float)$matches[1]; |
| 5139 | 5434 | $str = $matches[3]; |
| 5140 | - } |
|
| 5141 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
| 5435 | + } else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
| 5142 | 5436 | { |
| 5143 | 5437 | $value = substr($matches[2], 0, (int)$matches[1]); |
| 5144 | 5438 | $str = substr($matches[2], (int)$matches[1] + 2); |
| 5145 | - } |
|
| 5146 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
| 5439 | + } else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
| 5147 | 5440 | { |
| 5148 | 5441 | $expectedLength = (int)$matches[1]; |
| 5149 | 5442 | $str = $matches[2]; |
| 5150 | 5443 | } |
| 5151 | 5444 | |
| 5152 | 5445 | // Object or unknown/malformed type. |
| 5153 | - else |
|
| 5154 | - return false; |
|
| 5446 | + else { |
|
| 5447 | + return false; |
|
| 5448 | + } |
|
| 5155 | 5449 | |
| 5156 | 5450 | switch($state) |
| 5157 | 5451 | { |
@@ -5179,8 +5473,9 @@ discard block |
||
| 5179 | 5473 | if($type == '}') |
| 5180 | 5474 | { |
| 5181 | 5475 | // Array size is less than expected. |
| 5182 | - if(count($list) < end($expected)) |
|
| 5183 | - return false; |
|
| 5476 | + if(count($list) < end($expected)) { |
|
| 5477 | + return false; |
|
| 5478 | + } |
|
| 5184 | 5479 | |
| 5185 | 5480 | unset($list); |
| 5186 | 5481 | $list = &$stack[count($stack)-1]; |
@@ -5189,8 +5484,9 @@ discard block |
||
| 5189 | 5484 | // Go to terminal state if we're at the end of the root array. |
| 5190 | 5485 | array_pop($expected); |
| 5191 | 5486 | |
| 5192 | - if(count($expected) == 0) |
|
| 5193 | - $state = 1; |
|
| 5487 | + if(count($expected) == 0) { |
|
| 5488 | + $state = 1; |
|
| 5489 | + } |
|
| 5194 | 5490 | |
| 5195 | 5491 | break; |
| 5196 | 5492 | } |
@@ -5198,8 +5494,9 @@ discard block |
||
| 5198 | 5494 | if($type == 'i' || $type == 's') |
| 5199 | 5495 | { |
| 5200 | 5496 | // Array size exceeds expected length. |
| 5201 | - if(count($list) >= end($expected)) |
|
| 5202 | - return false; |
|
| 5497 | + if(count($list) >= end($expected)) { |
|
| 5498 | + return false; |
|
| 5499 | + } |
|
| 5203 | 5500 | |
| 5204 | 5501 | $key = $value; |
| 5205 | 5502 | $state = 3; |
@@ -5233,8 +5530,9 @@ discard block |
||
| 5233 | 5530 | } |
| 5234 | 5531 | |
| 5235 | 5532 | // Trailing data in input. |
| 5236 | - if(!empty($str)) |
|
| 5237 | - return false; |
|
| 5533 | + if(!empty($str)) { |
|
| 5534 | + return false; |
|
| 5535 | + } |
|
| 5238 | 5536 | |
| 5239 | 5537 | return $data; |
| 5240 | 5538 | } |
@@ -5257,8 +5555,9 @@ discard block |
||
| 5257 | 5555 | |
| 5258 | 5556 | $out = _safe_unserialize($str); |
| 5259 | 5557 | |
| 5260 | - if (isset($mbIntEnc)) |
|
| 5261 | - mb_internal_encoding($mbIntEnc); |
|
| 5558 | + if (isset($mbIntEnc)) { |
|
| 5559 | + mb_internal_encoding($mbIntEnc); |
|
| 5560 | + } |
|
| 5262 | 5561 | |
| 5263 | 5562 | return $out; |
| 5264 | 5563 | } |
@@ -5273,12 +5572,14 @@ discard block |
||
| 5273 | 5572 | function smf_chmod($file, $value = 0) |
| 5274 | 5573 | { |
| 5275 | 5574 | // No file? no checks! |
| 5276 | - if (empty($file)) |
|
| 5277 | - return false; |
|
| 5575 | + if (empty($file)) { |
|
| 5576 | + return false; |
|
| 5577 | + } |
|
| 5278 | 5578 | |
| 5279 | 5579 | // Already writable? |
| 5280 | - if (is_writable($file)) |
|
| 5281 | - return true; |
|
| 5580 | + if (is_writable($file)) { |
|
| 5581 | + return true; |
|
| 5582 | + } |
|
| 5282 | 5583 | |
| 5283 | 5584 | // Do we have a file or a dir? |
| 5284 | 5585 | $isDir = is_dir($file); |
@@ -5294,10 +5595,9 @@ discard block |
||
| 5294 | 5595 | { |
| 5295 | 5596 | $isWritable = true; |
| 5296 | 5597 | break; |
| 5598 | + } else { |
|
| 5599 | + @chmod($file, $val); |
|
| 5297 | 5600 | } |
| 5298 | - |
|
| 5299 | - else |
|
| 5300 | - @chmod($file, $val); |
|
| 5301 | 5601 | } |
| 5302 | 5602 | |
| 5303 | 5603 | return $isWritable; |
@@ -5316,8 +5616,9 @@ discard block |
||
| 5316 | 5616 | global $txt; |
| 5317 | 5617 | |
| 5318 | 5618 | // Come on... |
| 5319 | - if (empty($json) || !is_string($json)) |
|
| 5320 | - return array(); |
|
| 5619 | + if (empty($json) || !is_string($json)) { |
|
| 5620 | + return array(); |
|
| 5621 | + } |
|
| 5321 | 5622 | |
| 5322 | 5623 | $returnArray = array(); |
| 5323 | 5624 | $jsonError = false; |
@@ -5358,11 +5659,11 @@ discard block |
||
| 5358 | 5659 | $jsonDebug = $jsonDebug[0]; |
| 5359 | 5660 | loadLanguage('Errors'); |
| 5360 | 5661 | |
| 5361 | - if (!empty($jsonDebug)) |
|
| 5362 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
| 5363 | - |
|
| 5364 | - else |
|
| 5365 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
| 5662 | + if (!empty($jsonDebug)) { |
|
| 5663 | + log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
| 5664 | + } else { |
|
| 5665 | + log_error($txt['json_'. $jsonError], 'critical'); |
|
| 5666 | + } |
|
| 5366 | 5667 | |
| 5367 | 5668 | // Everyone expects an array. |
| 5368 | 5669 | return array(); |
@@ -5392,8 +5693,9 @@ discard block |
||
| 5392 | 5693 | global $db_show_debug, $modSettings; |
| 5393 | 5694 | |
| 5394 | 5695 | // Defensive programming anyone? |
| 5395 | - if (empty($data)) |
|
| 5396 | - return false; |
|
| 5696 | + if (empty($data)) { |
|
| 5697 | + return false; |
|
| 5698 | + } |
|
| 5397 | 5699 | |
| 5398 | 5700 | // Don't need extra stuff... |
| 5399 | 5701 | $db_show_debug = false; |
@@ -5401,11 +5703,11 @@ discard block |
||
| 5401 | 5703 | // Kill anything else. |
| 5402 | 5704 | ob_end_clean(); |
| 5403 | 5705 | |
| 5404 | - if (!empty($modSettings['CompressedOutput'])) |
|
| 5405 | - @ob_start('ob_gzhandler'); |
|
| 5406 | - |
|
| 5407 | - else |
|
| 5408 | - ob_start(); |
|
| 5706 | + if (!empty($modSettings['CompressedOutput'])) { |
|
| 5707 | + @ob_start('ob_gzhandler'); |
|
| 5708 | + } else { |
|
| 5709 | + ob_start(); |
|
| 5710 | + } |
|
| 5409 | 5711 | |
| 5410 | 5712 | // Set the header. |
| 5411 | 5713 | header($type); |
@@ -5437,8 +5739,9 @@ discard block |
||
| 5437 | 5739 | static $done = false; |
| 5438 | 5740 | |
| 5439 | 5741 | // If we don't need to do anything, don't |
| 5440 | - if (!$update && $done) |
|
| 5441 | - return; |
|
| 5742 | + if (!$update && $done) { |
|
| 5743 | + return; |
|
| 5744 | + } |
|
| 5442 | 5745 | |
| 5443 | 5746 | // Should we get a new copy of the official list of TLDs? |
| 5444 | 5747 | if ($update) |
@@ -5459,10 +5762,11 @@ discard block |
||
| 5459 | 5762 | // Clean $tlds and convert it to an array |
| 5460 | 5763 | $tlds = array_filter(explode("\n", strtolower($tlds)), function($line) { |
| 5461 | 5764 | $line = trim($line); |
| 5462 | - if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) |
|
| 5463 | - return false; |
|
| 5464 | - else |
|
| 5465 | - return true; |
|
| 5765 | + if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) { |
|
| 5766 | + return false; |
|
| 5767 | + } else { |
|
| 5768 | + return true; |
|
| 5769 | + } |
|
| 5466 | 5770 | }); |
| 5467 | 5771 | |
| 5468 | 5772 | // Convert Punycode to Unicode |
@@ -5516,8 +5820,9 @@ discard block |
||
| 5516 | 5820 | $idx += $digit * $w; |
| 5517 | 5821 | $t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias)); |
| 5518 | 5822 | |
| 5519 | - if ($digit < $t) |
|
| 5520 | - break; |
|
| 5823 | + if ($digit < $t) { |
|
| 5824 | + break; |
|
| 5825 | + } |
|
| 5521 | 5826 | |
| 5522 | 5827 | $w = (int) ($w * ($base - $t)); |
| 5523 | 5828 | } |
@@ -5526,8 +5831,9 @@ discard block |
||
| 5526 | 5831 | $delta = intval($is_first ? ($delta / $damp) : ($delta / 2)); |
| 5527 | 5832 | $delta += intval($delta / ($deco_len + 1)); |
| 5528 | 5833 | |
| 5529 | - for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) |
|
| 5530 | - $delta = intval($delta / ($base - $tmin)); |
|
| 5834 | + for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) { |
|
| 5835 | + $delta = intval($delta / ($base - $tmin)); |
|
| 5836 | + } |
|
| 5531 | 5837 | |
| 5532 | 5838 | $bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew)); |
| 5533 | 5839 | $is_first = false; |
@@ -5536,8 +5842,9 @@ discard block |
||
| 5536 | 5842 | |
| 5537 | 5843 | if ($deco_len > 0) |
| 5538 | 5844 | { |
| 5539 | - for ($i = $deco_len; $i > $idx; $i--) |
|
| 5540 | - $decoded[$i] = $decoded[($i - 1)]; |
|
| 5845 | + for ($i = $deco_len; $i > $idx; $i--) { |
|
| 5846 | + $decoded[$i] = $decoded[($i - 1)]; |
|
| 5847 | + } |
|
| 5541 | 5848 | } |
| 5542 | 5849 | $decoded[$idx++] = $char; |
| 5543 | 5850 | } |
@@ -5545,24 +5852,29 @@ discard block |
||
| 5545 | 5852 | foreach ($decoded as $k => $v) |
| 5546 | 5853 | { |
| 5547 | 5854 | // 7bit are transferred literally |
| 5548 | - if ($v < 128) |
|
| 5549 | - $output .= chr($v); |
|
| 5855 | + if ($v < 128) { |
|
| 5856 | + $output .= chr($v); |
|
| 5857 | + } |
|
| 5550 | 5858 | |
| 5551 | 5859 | // 2 bytes |
| 5552 | - elseif ($v < (1 << 11)) |
|
| 5553 | - $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
| 5860 | + elseif ($v < (1 << 11)) { |
|
| 5861 | + $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
| 5862 | + } |
|
| 5554 | 5863 | |
| 5555 | 5864 | // 3 bytes |
| 5556 | - elseif ($v < (1 << 16)) |
|
| 5557 | - $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 5865 | + elseif ($v < (1 << 16)) { |
|
| 5866 | + $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 5867 | + } |
|
| 5558 | 5868 | |
| 5559 | 5869 | // 4 bytes |
| 5560 | - elseif ($v < (1 << 21)) |
|
| 5561 | - $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 5870 | + elseif ($v < (1 << 21)) { |
|
| 5871 | + $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 5872 | + } |
|
| 5562 | 5873 | |
| 5563 | 5874 | // 'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k |
| 5564 | - else |
|
| 5565 | - $output .= $safe_char; |
|
| 5875 | + else { |
|
| 5876 | + $output .= $safe_char; |
|
| 5877 | + } |
|
| 5566 | 5878 | } |
| 5567 | 5879 | |
| 5568 | 5880 | $output_parts[] = $output; |
@@ -5657,8 +5969,7 @@ discard block |
||
| 5657 | 5969 | |
| 5658 | 5970 | $strlen = 'mb_strlen'; |
| 5659 | 5971 | $substr = 'mb_substr'; |
| 5660 | - } |
|
| 5661 | - else |
|
| 5972 | + } else |
|
| 5662 | 5973 | { |
| 5663 | 5974 | $strlen = $smcFunc['strlen']; |
| 5664 | 5975 | $substr = $smcFunc['substr']; |
@@ -5672,20 +5983,21 @@ discard block |
||
| 5672 | 5983 | |
| 5673 | 5984 | $first = $substr($string, 0, 1); |
| 5674 | 5985 | |
| 5675 | - if (empty($index[$first])) |
|
| 5676 | - $index[$first] = array(); |
|
| 5986 | + if (empty($index[$first])) { |
|
| 5987 | + $index[$first] = array(); |
|
| 5988 | + } |
|
| 5677 | 5989 | |
| 5678 | 5990 | if ($strlen($string) > 1) |
| 5679 | 5991 | { |
| 5680 | 5992 | // Sanity check on recursion |
| 5681 | - if ($depth > 99) |
|
| 5682 | - $index[$first][$substr($string, 1)] = ''; |
|
| 5683 | - |
|
| 5684 | - else |
|
| 5685 | - $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
| 5993 | + if ($depth > 99) { |
|
| 5994 | + $index[$first][$substr($string, 1)] = ''; |
|
| 5995 | + } else { |
|
| 5996 | + $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
| 5997 | + } |
|
| 5998 | + } else { |
|
| 5999 | + $index[$first][''] = ''; |
|
| 5686 | 6000 | } |
| 5687 | - else |
|
| 5688 | - $index[$first][''] = ''; |
|
| 5689 | 6001 | |
| 5690 | 6002 | $depth--; |
| 5691 | 6003 | return $index; |
@@ -5708,9 +6020,9 @@ discard block |
||
| 5708 | 6020 | $key_regex = preg_quote($key, $delim); |
| 5709 | 6021 | $new_key = $key; |
| 5710 | 6022 | |
| 5711 | - if (empty($value)) |
|
| 5712 | - $sub_regex = ''; |
|
| 5713 | - else |
|
| 6023 | + if (empty($value)) { |
|
| 6024 | + $sub_regex = ''; |
|
| 6025 | + } else |
|
| 5714 | 6026 | { |
| 5715 | 6027 | $sub_regex = $index_to_regex($value, $delim); |
| 5716 | 6028 | |
@@ -5718,22 +6030,22 @@ discard block |
||
| 5718 | 6030 | { |
| 5719 | 6031 | $new_key_array = explode('(?'.'>', $sub_regex); |
| 5720 | 6032 | $new_key .= $new_key_array[0]; |
| 6033 | + } else { |
|
| 6034 | + $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
| 5721 | 6035 | } |
| 5722 | - else |
|
| 5723 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
| 5724 | 6036 | } |
| 5725 | 6037 | |
| 5726 | - if ($depth > 1) |
|
| 5727 | - $regex[$new_key] = $key_regex . $sub_regex; |
|
| 5728 | - else |
|
| 6038 | + if ($depth > 1) { |
|
| 6039 | + $regex[$new_key] = $key_regex . $sub_regex; |
|
| 6040 | + } else |
|
| 5729 | 6041 | { |
| 5730 | 6042 | if (($length += strlen($key_regex) + 1) < $max_length || empty($regex)) |
| 5731 | 6043 | { |
| 5732 | 6044 | $regex[$new_key] = $key_regex . $sub_regex; |
| 5733 | 6045 | unset($index[$key]); |
| 6046 | + } else { |
|
| 6047 | + break; |
|
| 5734 | 6048 | } |
| 5735 | - else |
|
| 5736 | - break; |
|
| 5737 | 6049 | } |
| 5738 | 6050 | } |
| 5739 | 6051 | |
@@ -5742,10 +6054,11 @@ discard block |
||
| 5742 | 6054 | $l1 = $strlen($k1); |
| 5743 | 6055 | $l2 = $strlen($k2); |
| 5744 | 6056 | |
| 5745 | - if ($l1 == $l2) |
|
| 5746 | - return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
| 5747 | - else |
|
| 5748 | - return $l1 > $l2 ? -1 : 1; |
|
| 6057 | + if ($l1 == $l2) { |
|
| 6058 | + return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
| 6059 | + } else { |
|
| 6060 | + return $l1 > $l2 ? -1 : 1; |
|
| 6061 | + } |
|
| 5749 | 6062 | }); |
| 5750 | 6063 | |
| 5751 | 6064 | $depth--; |
@@ -5756,15 +6069,18 @@ discard block |
||
| 5756 | 6069 | $index = array(); |
| 5757 | 6070 | $regexes = array(); |
| 5758 | 6071 | |
| 5759 | - foreach ($strings as $string) |
|
| 5760 | - $index = $add_string_to_index($string, $index); |
|
| 6072 | + foreach ($strings as $string) { |
|
| 6073 | + $index = $add_string_to_index($string, $index); |
|
| 6074 | + } |
|
| 5761 | 6075 | |
| 5762 | - while (!empty($index)) |
|
| 5763 | - $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
| 6076 | + while (!empty($index)) { |
|
| 6077 | + $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
| 6078 | + } |
|
| 5764 | 6079 | |
| 5765 | 6080 | // Restore PHP's internal character encoding to whatever it was originally |
| 5766 | - if (!empty($current_encoding)) |
|
| 5767 | - mb_internal_encoding($current_encoding); |
|
| 6081 | + if (!empty($current_encoding)) { |
|
| 6082 | + mb_internal_encoding($current_encoding); |
|
| 6083 | + } |
|
| 5768 | 6084 | |
| 5769 | 6085 | return $regexes; |
| 5770 | 6086 | } |
@@ -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 main 'Attachments and Avatars' management function. |
@@ -63,10 +64,11 @@ discard block |
||
| 63 | 64 | call_integration_hook('integrate_manage_attachments', array(&$subActions)); |
| 64 | 65 | |
| 65 | 66 | // Pick the correct sub-action. |
| 66 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
| 67 | - $context['sub_action'] = $_REQUEST['sa']; |
|
| 68 | - else |
|
| 69 | - $context['sub_action'] = 'browse'; |
|
| 67 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
| 68 | + $context['sub_action'] = $_REQUEST['sa']; |
|
| 69 | + } else { |
|
| 70 | + $context['sub_action'] = 'browse'; |
|
| 71 | + } |
|
| 70 | 72 | |
| 71 | 73 | // Default page title is good. |
| 72 | 74 | $context['page_title'] = $txt['attachments_avatars']; |
@@ -94,20 +96,20 @@ discard block |
||
| 94 | 96 | $context['attachmentUploadDir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
| 95 | 97 | |
| 96 | 98 | // If not set, show a default path for the base directory |
| 97 | - if (!isset($_GET['save']) && empty($modSettings['basedirectory_for_attachments'])) |
|
| 98 | - if (is_dir($modSettings['attachmentUploadDir'][1])) |
|
| 99 | + if (!isset($_GET['save']) && empty($modSettings['basedirectory_for_attachments'])) { |
|
| 100 | + if (is_dir($modSettings['attachmentUploadDir'][1])) |
|
| 99 | 101 | $modSettings['basedirectory_for_attachments'] = $modSettings['attachmentUploadDir'][1]; |
| 100 | - |
|
| 101 | - else |
|
| 102 | - $modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir']; |
|
| 102 | + } else { |
|
| 103 | + $modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir']; |
|
| 104 | + } |
|
| 103 | 105 | |
| 104 | 106 | $context['valid_upload_dir'] = is_dir($context['attachmentUploadDir']) && is_writable($context['attachmentUploadDir']); |
| 105 | 107 | |
| 106 | - if (!empty($modSettings['automanage_attachments'])) |
|
| 107 | - $context['valid_basedirectory'] = !empty($modSettings['basedirectory_for_attachments']) && is_writable($modSettings['basedirectory_for_attachments']); |
|
| 108 | - |
|
| 109 | - else |
|
| 110 | - $context['valid_basedirectory'] = true; |
|
| 108 | + if (!empty($modSettings['automanage_attachments'])) { |
|
| 109 | + $context['valid_basedirectory'] = !empty($modSettings['basedirectory_for_attachments']) && is_writable($modSettings['basedirectory_for_attachments']); |
|
| 110 | + } else { |
|
| 111 | + $context['valid_basedirectory'] = true; |
|
| 112 | + } |
|
| 111 | 113 | |
| 112 | 114 | // A bit of razzle dazzle with the $txt strings. :) |
| 113 | 115 | $txt['attachment_path'] = $context['attachmentUploadDir']; |
@@ -185,8 +187,9 @@ discard block |
||
| 185 | 187 | |
| 186 | 188 | call_integration_hook('integrate_modify_attachment_settings', array(&$config_vars)); |
| 187 | 189 | |
| 188 | - if ($return_config) |
|
| 189 | - return $config_vars; |
|
| 190 | + if ($return_config) { |
|
| 191 | + return $config_vars; |
|
| 192 | + } |
|
| 190 | 193 | |
| 191 | 194 | // These are very likely to come in handy! (i.e. without them we're doomed!) |
| 192 | 195 | require_once($sourcedir . '/ManagePermissions.php'); |
@@ -197,21 +200,24 @@ discard block |
||
| 197 | 200 | { |
| 198 | 201 | checkSession(); |
| 199 | 202 | |
| 200 | - if (isset($_POST['attachmentUploadDir'])) |
|
| 201 | - unset($_POST['attachmentUploadDir']); |
|
| 203 | + if (isset($_POST['attachmentUploadDir'])) { |
|
| 204 | + unset($_POST['attachmentUploadDir']); |
|
| 205 | + } |
|
| 202 | 206 | |
| 203 | 207 | if (!empty($_POST['use_subdirectories_for_attachments'])) |
| 204 | 208 | { |
| 205 | - if (isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments'])) |
|
| 206 | - $_POST['basedirectory_for_attachments'] = (!empty($modSettings['basedirectory_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
|
| 209 | + if (isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments'])) { |
|
| 210 | + $_POST['basedirectory_for_attachments'] = (!empty($modSettings['basedirectory_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
|
| 211 | + } |
|
| 207 | 212 | |
| 208 | 213 | if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($modSettings['attachment_basedirectories'])) |
| 209 | 214 | { |
| 210 | - if (!is_array($modSettings['attachment_basedirectories'])) |
|
| 211 | - $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 215 | + if (!is_array($modSettings['attachment_basedirectories'])) { |
|
| 216 | + $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 217 | + } |
|
| 218 | + } else { |
|
| 219 | + $modSettings['attachment_basedirectories'] = array(); |
|
| 212 | 220 | } |
| 213 | - else |
|
| 214 | - $modSettings['attachment_basedirectories'] = array(); |
|
| 215 | 221 | |
| 216 | 222 | if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($_POST['basedirectory_for_attachments']) && !in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories'])) |
| 217 | 223 | { |
@@ -219,8 +225,9 @@ discard block |
||
| 219 | 225 | |
| 220 | 226 | if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachmentUploadDir'])) |
| 221 | 227 | { |
| 222 | - if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments'])) |
|
| 223 | - $_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments']; |
|
| 228 | + if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments'])) { |
|
| 229 | + $_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments']; |
|
| 230 | + } |
|
| 224 | 231 | } |
| 225 | 232 | |
| 226 | 233 | if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories'])) |
@@ -336,8 +343,9 @@ discard block |
||
| 336 | 343 | |
| 337 | 344 | call_integration_hook('integrate_modify_avatar_settings', array(&$config_vars)); |
| 338 | 345 | |
| 339 | - if ($return_config) |
|
| 340 | - return $config_vars; |
|
| 346 | + if ($return_config) { |
|
| 347 | + return $config_vars; |
|
| 348 | + } |
|
| 341 | 349 | |
| 342 | 350 | // We need this file for the settings template. |
| 343 | 351 | require_once($sourcedir . '/ManageServer.php'); |
@@ -348,17 +356,21 @@ discard block |
||
| 348 | 356 | checkSession(); |
| 349 | 357 | |
| 350 | 358 | // These settings cannot be left empty! |
| 351 | - if (empty($_POST['custom_avatar_dir'])) |
|
| 352 | - $_POST['custom_avatar_dir'] = $boarddir .'/custom_avatar'; |
|
| 359 | + if (empty($_POST['custom_avatar_dir'])) { |
|
| 360 | + $_POST['custom_avatar_dir'] = $boarddir .'/custom_avatar'; |
|
| 361 | + } |
|
| 353 | 362 | |
| 354 | - if (empty($_POST['custom_avatar_url'])) |
|
| 355 | - $_POST['custom_avatar_url'] = $boardurl .'/custom_avatar'; |
|
| 363 | + if (empty($_POST['custom_avatar_url'])) { |
|
| 364 | + $_POST['custom_avatar_url'] = $boardurl .'/custom_avatar'; |
|
| 365 | + } |
|
| 356 | 366 | |
| 357 | - if (empty($_POST['avatar_directory'])) |
|
| 358 | - $_POST['avatar_directory'] = $boarddir .'/avatars'; |
|
| 367 | + if (empty($_POST['avatar_directory'])) { |
|
| 368 | + $_POST['avatar_directory'] = $boarddir .'/avatars'; |
|
| 369 | + } |
|
| 359 | 370 | |
| 360 | - if (empty($_POST['avatar_url'])) |
|
| 361 | - $_POST['avatar_url'] = $boardurl .'/avatars'; |
|
| 371 | + if (empty($_POST['avatar_url'])) { |
|
| 372 | + $_POST['avatar_url'] = $boardurl .'/avatars'; |
|
| 373 | + } |
|
| 362 | 374 | |
| 363 | 375 | call_integration_hook('integrate_save_avatar_settings'); |
| 364 | 376 | |
@@ -406,11 +418,13 @@ discard block |
||
| 406 | 418 | $list_title = $txt['attachment_manager_browse_files'] . ': '; |
| 407 | 419 | foreach ($titles as $browse_type => $details) |
| 408 | 420 | { |
| 409 | - if ($browse_type != 'attachments') |
|
| 410 | - $list_title .= ' | '; |
|
| 421 | + if ($browse_type != 'attachments') { |
|
| 422 | + $list_title .= ' | '; |
|
| 423 | + } |
|
| 411 | 424 | |
| 412 | - if ($context['browse_type'] == $browse_type) |
|
| 413 | - $list_title .= '<img src="' . $settings['images_url'] . '/selected.png" alt=">"> '; |
|
| 425 | + if ($context['browse_type'] == $browse_type) { |
|
| 426 | + $list_title .= '<img src="' . $settings['images_url'] . '/selected.png" alt=">"> '; |
|
| 427 | + } |
|
| 414 | 428 | |
| 415 | 429 | $list_title .= '<a href="' . $scripturl . $details[0] . '">' . $details[1] . '</a>'; |
| 416 | 430 | } |
@@ -446,28 +460,33 @@ discard block |
||
| 446 | 460 | $link = '<a href="'; |
| 447 | 461 | |
| 448 | 462 | // In case of a custom avatar URL attachments have a fixed directory. |
| 449 | - if ($rowData['attachment_type'] == 1) |
|
| 450 | - $link .= sprintf('%1$s/%2$s', $modSettings['custom_avatar_url'], $rowData['filename']); |
|
| 463 | + if ($rowData['attachment_type'] == 1) { |
|
| 464 | + $link .= sprintf('%1$s/%2$s', $modSettings['custom_avatar_url'], $rowData['filename']); |
|
| 465 | + } |
|
| 451 | 466 | |
| 452 | 467 | // By default avatars are downloaded almost as attachments. |
| 453 | - elseif ($context['browse_type'] == 'avatars') |
|
| 454 | - $link .= sprintf('%1$s?action=dlattach;type=avatar;attach=%2$d', $scripturl, $rowData['id_attach']); |
|
| 468 | + elseif ($context['browse_type'] == 'avatars') { |
|
| 469 | + $link .= sprintf('%1$s?action=dlattach;type=avatar;attach=%2$d', $scripturl, $rowData['id_attach']); |
|
| 470 | + } |
|
| 455 | 471 | |
| 456 | 472 | // Normal attachments are always linked to a topic ID. |
| 457 | - else |
|
| 458 | - $link .= sprintf('%1$s?action=dlattach;topic=%2$d.0;attach=%3$d', $scripturl, $rowData['id_topic'], $rowData['id_attach']); |
|
| 473 | + else { |
|
| 474 | + $link .= sprintf('%1$s?action=dlattach;topic=%2$d.0;attach=%3$d', $scripturl, $rowData['id_topic'], $rowData['id_attach']); |
|
| 475 | + } |
|
| 459 | 476 | |
| 460 | 477 | $link .= '"'; |
| 461 | 478 | |
| 462 | 479 | // Show a popup on click if it's a picture and we know its dimensions. |
| 463 | - if (!empty($rowData['width']) && !empty($rowData['height'])) |
|
| 464 | - $link .= sprintf(' onclick="return reqWin(this.href' . ($rowData['attachment_type'] == 1 ? '' : ' + \';image\'') . ', %1$d, %2$d, true);"', $rowData['width'] + 20, $rowData['height'] + 20); |
|
| 480 | + if (!empty($rowData['width']) && !empty($rowData['height'])) { |
|
| 481 | + $link .= sprintf(' onclick="return reqWin(this.href' . ($rowData['attachment_type'] == 1 ? '' : ' + \';image\'') . ', %1$d, %2$d, true);"', $rowData['width'] + 20, $rowData['height'] + 20); |
|
| 482 | + } |
|
| 465 | 483 | |
| 466 | 484 | $link .= sprintf('>%1$s</a>', preg_replace('~&#(\\\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\\\1;', $smcFunc['htmlspecialchars']($rowData['filename']))); |
| 467 | 485 | |
| 468 | 486 | // Show the dimensions. |
| 469 | - if (!empty($rowData['width']) && !empty($rowData['height'])) |
|
| 470 | - $link .= sprintf(' <span class="smalltext">%1$dx%2$d</span>', $rowData['width'], $rowData['height']); |
|
| 487 | + if (!empty($rowData['width']) && !empty($rowData['height'])) { |
|
| 488 | + $link .= sprintf(' <span class="smalltext">%1$dx%2$d</span>', $rowData['width'], $rowData['height']); |
|
| 489 | + } |
|
| 471 | 490 | |
| 472 | 491 | return $link; |
| 473 | 492 | }, |
@@ -500,12 +519,14 @@ discard block |
||
| 500 | 519 | 'function' => function ($rowData) use ($scripturl, $smcFunc) |
| 501 | 520 | { |
| 502 | 521 | // In case of an attachment, return the poster of the attachment. |
| 503 | - if (empty($rowData['id_member'])) |
|
| 504 | - return $smcFunc['htmlspecialchars']($rowData['poster_name']); |
|
| 522 | + if (empty($rowData['id_member'])) { |
|
| 523 | + return $smcFunc['htmlspecialchars']($rowData['poster_name']); |
|
| 524 | + } |
|
| 505 | 525 | |
| 506 | 526 | // Otherwise it must be an avatar, return the link to the owner of it. |
| 507 | - else |
|
| 508 | - return sprintf('<a href="%1$s?action=profile;u=%2$d">%3$s</a>', $scripturl, $rowData['id_member'], $rowData['poster_name']); |
|
| 527 | + else { |
|
| 528 | + return sprintf('<a href="%1$s?action=profile;u=%2$d">%3$s</a>', $scripturl, $rowData['id_member'], $rowData['poster_name']); |
|
| 529 | + } |
|
| 509 | 530 | }, |
| 510 | 531 | ), |
| 511 | 532 | 'sort' => array( |
@@ -524,8 +545,9 @@ discard block |
||
| 524 | 545 | $date = empty($rowData['poster_time']) ? $txt['never'] : timeformat($rowData['poster_time']); |
| 525 | 546 | |
| 526 | 547 | // Add a link to the topic in case of an attachment. |
| 527 | - if ($context['browse_type'] !== 'avatars') |
|
| 528 | - $date .= sprintf('<br>%1$s <a href="%2$s?topic=%3$d.msg%4$d#msg%4$d">%5$s</a>', $txt['in'], $scripturl, $rowData['id_topic'], $rowData['id_msg'], $rowData['subject']); |
|
| 548 | + if ($context['browse_type'] !== 'avatars') { |
|
| 549 | + $date .= sprintf('<br>%1$s <a href="%2$s?topic=%3$d.msg%4$d#msg%4$d">%5$s</a>', $txt['in'], $scripturl, $rowData['id_topic'], $rowData['id_msg'], $rowData['subject']); |
|
| 550 | + } |
|
| 529 | 551 | |
| 530 | 552 | return $date; |
| 531 | 553 | }, |
@@ -610,8 +632,8 @@ discard block |
||
| 610 | 632 | global $smcFunc, $txt; |
| 611 | 633 | |
| 612 | 634 | // Choose a query depending on what we are viewing. |
| 613 | - if ($browse_type === 'avatars') |
|
| 614 | - $request = $smcFunc['db_query']('', ' |
|
| 635 | + if ($browse_type === 'avatars') { |
|
| 636 | + $request = $smcFunc['db_query']('', ' |
|
| 615 | 637 | SELECT |
| 616 | 638 | {string:blank_text} AS id_msg, COALESCE(mem.real_name, {string:not_applicable_text}) AS poster_name, |
| 617 | 639 | mem.last_login AS poster_time, 0 AS id_topic, a.id_member, a.id_attach, a.filename, a.file_hash, a.attachment_type, |
@@ -630,8 +652,8 @@ discard block |
||
| 630 | 652 | 'per_page' => $items_per_page, |
| 631 | 653 | ) |
| 632 | 654 | ); |
| 633 | - else |
|
| 634 | - $request = $smcFunc['db_query']('', ' |
|
| 655 | + } else { |
|
| 656 | + $request = $smcFunc['db_query']('', ' |
|
| 635 | 657 | SELECT |
| 636 | 658 | m.id_msg, COALESCE(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_topic, m.id_member, |
| 637 | 659 | a.id_attach, a.filename, a.file_hash, a.attachment_type, a.size, a.width, a.height, a.downloads, mf.subject, t.id_board |
@@ -650,9 +672,11 @@ discard block |
||
| 650 | 672 | 'per_page' => $items_per_page, |
| 651 | 673 | ) |
| 652 | 674 | ); |
| 675 | + } |
|
| 653 | 676 | $files = array(); |
| 654 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 655 | - $files[] = $row; |
|
| 677 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 678 | + $files[] = $row; |
|
| 679 | + } |
|
| 656 | 680 | $smcFunc['db_free_result']($request); |
| 657 | 681 | |
| 658 | 682 | return $files; |
@@ -670,8 +694,8 @@ discard block |
||
| 670 | 694 | global $smcFunc; |
| 671 | 695 | |
| 672 | 696 | // Depending on the type of file, different queries are used. |
| 673 | - if ($browse_type === 'avatars') |
|
| 674 | - $request = $smcFunc['db_query']('', ' |
|
| 697 | + if ($browse_type === 'avatars') { |
|
| 698 | + $request = $smcFunc['db_query']('', ' |
|
| 675 | 699 | SELECT COUNT(*) |
| 676 | 700 | FROM {db_prefix}attachments |
| 677 | 701 | WHERE id_member != {int:guest_id_member}', |
@@ -679,8 +703,8 @@ discard block |
||
| 679 | 703 | 'guest_id_member' => 0, |
| 680 | 704 | ) |
| 681 | 705 | ); |
| 682 | - else |
|
| 683 | - $request = $smcFunc['db_query']('', ' |
|
| 706 | + } else { |
|
| 707 | + $request = $smcFunc['db_query']('', ' |
|
| 684 | 708 | SELECT COUNT(*) AS num_attach |
| 685 | 709 | FROM {db_prefix}attachments AS a |
| 686 | 710 | INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) |
@@ -693,6 +717,7 @@ discard block |
||
| 693 | 717 | 'guest_id_member' => 0, |
| 694 | 718 | ) |
| 695 | 719 | ); |
| 720 | + } |
|
| 696 | 721 | |
| 697 | 722 | list ($num_files) = $smcFunc['db_fetch_row']($request); |
| 698 | 723 | $smcFunc['db_free_result']($request); |
@@ -775,12 +800,14 @@ discard block |
||
| 775 | 800 | $current_dir_size /= 1024; |
| 776 | 801 | |
| 777 | 802 | // If they specified a limit only.... |
| 778 | - if (!empty($modSettings['attachmentDirSizeLimit'])) |
|
| 779 | - $context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2); |
|
| 803 | + if (!empty($modSettings['attachmentDirSizeLimit'])) { |
|
| 804 | + $context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2); |
|
| 805 | + } |
|
| 780 | 806 | $context['attachment_current_size'] = comma_format($current_dir_size, 2); |
| 781 | 807 | |
| 782 | - if (!empty($modSettings['attachmentDirFileLimit'])) |
|
| 783 | - $context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0); |
|
| 808 | + if (!empty($modSettings['attachmentDirFileLimit'])) { |
|
| 809 | + $context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0); |
|
| 810 | + } |
|
| 784 | 811 | $context['attachment_current_files'] = comma_format($current_dir_files, 0); |
| 785 | 812 | |
| 786 | 813 | $context['attach_multiple_dirs'] = count($attach_dirs) > 1 ? true : false; |
@@ -817,8 +844,8 @@ discard block |
||
| 817 | 844 | $messages = removeAttachments(array('attachment_type' => 0, 'poster_time' => (time() - 24 * 60 * 60 * $_POST['age'])), 'messages', true); |
| 818 | 845 | |
| 819 | 846 | // Update the messages to reflect the change. |
| 820 | - if (!empty($messages) && !empty($_POST['notice'])) |
|
| 821 | - $smcFunc['db_query']('', ' |
|
| 847 | + if (!empty($messages) && !empty($_POST['notice'])) { |
|
| 848 | + $smcFunc['db_query']('', ' |
|
| 822 | 849 | UPDATE {db_prefix}messages |
| 823 | 850 | SET body = CONCAT(body, {string:notice}) |
| 824 | 851 | WHERE id_msg IN ({array_int:messages})', |
@@ -827,8 +854,8 @@ discard block |
||
| 827 | 854 | 'notice' => '<br><br>' . $_POST['notice'], |
| 828 | 855 | ) |
| 829 | 856 | ); |
| 830 | - } |
|
| 831 | - else |
|
| 857 | + } |
|
| 858 | + } else |
|
| 832 | 859 | { |
| 833 | 860 | // Remove all the old avatars. |
| 834 | 861 | removeAttachments(array('not_id_member' => 0, 'last_login' => (time() - 24 * 60 * 60 * $_POST['age'])), 'members'); |
@@ -853,8 +880,8 @@ discard block |
||
| 853 | 880 | $messages = removeAttachments(array('attachment_type' => 0, 'size' => 1024 * $_POST['size']), 'messages', true); |
| 854 | 881 | |
| 855 | 882 | // And make a note on the post. |
| 856 | - if (!empty($messages) && !empty($_POST['notice'])) |
|
| 857 | - $smcFunc['db_query']('', ' |
|
| 883 | + if (!empty($messages) && !empty($_POST['notice'])) { |
|
| 884 | + $smcFunc['db_query']('', ' |
|
| 858 | 885 | UPDATE {db_prefix}messages |
| 859 | 886 | SET body = CONCAT(body, {string:notice}) |
| 860 | 887 | WHERE id_msg IN ({array_int:messages})', |
@@ -863,6 +890,7 @@ discard block |
||
| 863 | 890 | 'notice' => '<br><br>' . $_POST['notice'], |
| 864 | 891 | ) |
| 865 | 892 | ); |
| 893 | + } |
|
| 866 | 894 | |
| 867 | 895 | redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
| 868 | 896 | } |
@@ -882,16 +910,17 @@ discard block |
||
| 882 | 910 | { |
| 883 | 911 | $attachments = array(); |
| 884 | 912 | // There must be a quicker way to pass this safety test?? |
| 885 | - foreach ($_POST['remove'] as $removeID => $dummy) |
|
| 886 | - $attachments[] = (int) $removeID; |
|
| 913 | + foreach ($_POST['remove'] as $removeID => $dummy) { |
|
| 914 | + $attachments[] = (int) $removeID; |
|
| 915 | + } |
|
| 887 | 916 | |
| 888 | 917 | // If the attachments are from a 3rd party, let them remove it. Hooks should remove their ids from the array. |
| 889 | 918 | $filesRemoved = false; |
| 890 | 919 | call_integration_hook('integrate_attachment_remove', array(&$filesRemoved, $attachments)); |
| 891 | 920 | |
| 892 | - if ($_REQUEST['type'] == 'avatars' && !empty($attachments)) |
|
| 893 | - removeAttachments(array('id_attach' => $attachments)); |
|
| 894 | - else if (!empty($attachments)) |
|
| 921 | + if ($_REQUEST['type'] == 'avatars' && !empty($attachments)) { |
|
| 922 | + removeAttachments(array('id_attach' => $attachments)); |
|
| 923 | + } else if (!empty($attachments)) |
|
| 895 | 924 | { |
| 896 | 925 | $messages = removeAttachments(array('id_attach' => $attachments), 'messages', true); |
| 897 | 926 | |
@@ -930,12 +959,13 @@ discard block |
||
| 930 | 959 | |
| 931 | 960 | $messages = removeAttachments(array('attachment_type' => 0), '', true); |
| 932 | 961 | |
| 933 | - if (!isset($_POST['notice'])) |
|
| 934 | - $_POST['notice'] = $txt['attachment_delete_admin']; |
|
| 962 | + if (!isset($_POST['notice'])) { |
|
| 963 | + $_POST['notice'] = $txt['attachment_delete_admin']; |
|
| 964 | + } |
|
| 935 | 965 | |
| 936 | 966 | // Add the notice on the end of the changed messages. |
| 937 | - if (!empty($messages)) |
|
| 938 | - $smcFunc['db_query']('', ' |
|
| 967 | + if (!empty($messages)) { |
|
| 968 | + $smcFunc['db_query']('', ' |
|
| 939 | 969 | UPDATE {db_prefix}messages |
| 940 | 970 | SET body = CONCAT(body, {string:deleted_message}) |
| 941 | 971 | WHERE id_msg IN ({array_int:messages})', |
@@ -944,6 +974,7 @@ discard block |
||
| 944 | 974 | 'deleted_message' => '<br><br>' . $_POST['notice'], |
| 945 | 975 | ) |
| 946 | 976 | ); |
| 977 | + } |
|
| 947 | 978 | |
| 948 | 979 | redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
| 949 | 980 | } |
@@ -982,24 +1013,26 @@ discard block |
||
| 982 | 1013 | $is_not = substr($real_type, 0, 4) == 'not_'; |
| 983 | 1014 | $type = $is_not ? substr($real_type, 4) : $real_type; |
| 984 | 1015 | |
| 985 | - if (in_array($type, array('id_member', 'id_attach', 'id_msg'))) |
|
| 986 | - $new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
| 987 | - elseif ($type == 'attachment_type') |
|
| 988 | - $new_condition[] = 'a.attachment_type = {int:' . $real_type . '}'; |
|
| 989 | - elseif ($type == 'poster_time') |
|
| 990 | - $new_condition[] = 'm.poster_time < {int:' . $real_type . '}'; |
|
| 991 | - elseif ($type == 'last_login') |
|
| 992 | - $new_condition[] = 'mem.last_login < {int:' . $real_type . '}'; |
|
| 993 | - elseif ($type == 'size') |
|
| 994 | - $new_condition[] = 'a.size > {int:' . $real_type . '}'; |
|
| 995 | - elseif ($type == 'id_topic') |
|
| 996 | - $new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
| 1016 | + if (in_array($type, array('id_member', 'id_attach', 'id_msg'))) { |
|
| 1017 | + $new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
| 1018 | + } elseif ($type == 'attachment_type') { |
|
| 1019 | + $new_condition[] = 'a.attachment_type = {int:' . $real_type . '}'; |
|
| 1020 | + } elseif ($type == 'poster_time') { |
|
| 1021 | + $new_condition[] = 'm.poster_time < {int:' . $real_type . '}'; |
|
| 1022 | + } elseif ($type == 'last_login') { |
|
| 1023 | + $new_condition[] = 'mem.last_login < {int:' . $real_type . '}'; |
|
| 1024 | + } elseif ($type == 'size') { |
|
| 1025 | + $new_condition[] = 'a.size > {int:' . $real_type . '}'; |
|
| 1026 | + } elseif ($type == 'id_topic') { |
|
| 1027 | + $new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
| 1028 | + } |
|
| 997 | 1029 | |
| 998 | 1030 | // Add the parameter! |
| 999 | 1031 | $query_parameter[$real_type] = $restriction; |
| 1000 | 1032 | |
| 1001 | - if ($type == 'do_logging') |
|
| 1002 | - $do_logging = $condition['id_attach']; |
|
| 1033 | + if ($type == 'do_logging') { |
|
| 1034 | + $do_logging = $condition['id_attach']; |
|
| 1035 | + } |
|
| 1003 | 1036 | } |
| 1004 | 1037 | $condition = implode(' AND ', $new_condition); |
| 1005 | 1038 | } |
@@ -1031,15 +1064,15 @@ discard block |
||
| 1031 | 1064 | // wasn't it obvious? :P |
| 1032 | 1065 | // @todo look again at this. |
| 1033 | 1066 | @unlink($modSettings['custom_avatar_dir'] . '/' . $row['filename']); |
| 1034 | - } |
|
| 1035 | - else |
|
| 1067 | + } else |
|
| 1036 | 1068 | { |
| 1037 | 1069 | $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
| 1038 | 1070 | @unlink($filename); |
| 1039 | 1071 | |
| 1040 | 1072 | // If this was a thumb, the parent attachment should know about it. |
| 1041 | - if (!empty($row['id_parent'])) |
|
| 1042 | - $parents[] = $row['id_parent']; |
|
| 1073 | + if (!empty($row['id_parent'])) { |
|
| 1074 | + $parents[] = $row['id_parent']; |
|
| 1075 | + } |
|
| 1043 | 1076 | |
| 1044 | 1077 | // If this attachments has a thumb, remove it as well. |
| 1045 | 1078 | if (!empty($row['id_thumb']) && $autoThumbRemoval) |
@@ -1051,8 +1084,9 @@ discard block |
||
| 1051 | 1084 | } |
| 1052 | 1085 | |
| 1053 | 1086 | // Make a list. |
| 1054 | - if ($return_affected_messages && empty($row['attachment_type'])) |
|
| 1055 | - $msgs[] = $row['id_msg']; |
|
| 1087 | + if ($return_affected_messages && empty($row['attachment_type'])) { |
|
| 1088 | + $msgs[] = $row['id_msg']; |
|
| 1089 | + } |
|
| 1056 | 1090 | |
| 1057 | 1091 | $attach[] = $row['id_attach']; |
| 1058 | 1092 | } |
@@ -1060,8 +1094,8 @@ discard block |
||
| 1060 | 1094 | |
| 1061 | 1095 | // Removed attachments don't have to be updated anymore. |
| 1062 | 1096 | $parents = array_diff($parents, $attach); |
| 1063 | - if (!empty($parents)) |
|
| 1064 | - $smcFunc['db_query']('', ' |
|
| 1097 | + if (!empty($parents)) { |
|
| 1098 | + $smcFunc['db_query']('', ' |
|
| 1065 | 1099 | UPDATE {db_prefix}attachments |
| 1066 | 1100 | SET id_thumb = {int:no_thumb} |
| 1067 | 1101 | WHERE id_attach IN ({array_int:parent_attachments})', |
@@ -1070,6 +1104,7 @@ discard block |
||
| 1070 | 1104 | 'no_thumb' => 0, |
| 1071 | 1105 | ) |
| 1072 | 1106 | ); |
| 1107 | + } |
|
| 1073 | 1108 | |
| 1074 | 1109 | if (!empty($do_logging)) |
| 1075 | 1110 | { |
@@ -1086,31 +1121,34 @@ discard block |
||
| 1086 | 1121 | ) |
| 1087 | 1122 | ); |
| 1088 | 1123 | |
| 1089 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1090 | - logAction( |
|
| 1124 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1125 | + logAction( |
|
| 1091 | 1126 | 'remove_attach', |
| 1092 | 1127 | array( |
| 1093 | 1128 | 'message' => $row['id_msg'], |
| 1094 | 1129 | 'filename' => preg_replace('~&#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($row['filename'])), |
| 1095 | 1130 | ) |
| 1096 | 1131 | ); |
| 1132 | + } |
|
| 1097 | 1133 | $smcFunc['db_free_result']($request); |
| 1098 | 1134 | } |
| 1099 | 1135 | |
| 1100 | - if (!empty($attach)) |
|
| 1101 | - $smcFunc['db_query']('', ' |
|
| 1136 | + if (!empty($attach)) { |
|
| 1137 | + $smcFunc['db_query']('', ' |
|
| 1102 | 1138 | DELETE FROM {db_prefix}attachments |
| 1103 | 1139 | WHERE id_attach IN ({array_int:attachment_list})', |
| 1104 | 1140 | array( |
| 1105 | 1141 | 'attachment_list' => $attach, |
| 1106 | 1142 | ) |
| 1107 | 1143 | ); |
| 1144 | + } |
|
| 1108 | 1145 | |
| 1109 | 1146 | call_integration_hook('integrate_remove_attachments', array($attach)); |
| 1110 | 1147 | |
| 1111 | - if ($return_affected_messages) |
|
| 1112 | - return array_unique($msgs); |
|
| 1113 | -} |
|
| 1148 | + if ($return_affected_messages) { |
|
| 1149 | + return array_unique($msgs); |
|
| 1150 | + } |
|
| 1151 | + } |
|
| 1114 | 1152 | |
| 1115 | 1153 | /** |
| 1116 | 1154 | * This function should find attachments in the database that no longer exist and clear them, and fix filesize issues. |
@@ -1122,8 +1160,9 @@ discard block |
||
| 1122 | 1160 | checkSession('get'); |
| 1123 | 1161 | |
| 1124 | 1162 | // If we choose cancel, redirect right back. |
| 1125 | - if (isset($_POST['cancel'])) |
|
| 1126 | - redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
| 1163 | + if (isset($_POST['cancel'])) { |
|
| 1164 | + redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
| 1165 | + } |
|
| 1127 | 1166 | |
| 1128 | 1167 | // Try give us a while to sort this out... |
| 1129 | 1168 | @set_time_limit(600); |
@@ -1140,13 +1179,15 @@ discard block |
||
| 1140 | 1179 | if (isset($_GET['fixErrors'])) |
| 1141 | 1180 | { |
| 1142 | 1181 | // Nothing? |
| 1143 | - if (empty($_POST['to_fix'])) |
|
| 1144 | - redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
| 1182 | + if (empty($_POST['to_fix'])) { |
|
| 1183 | + redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
| 1184 | + } |
|
| 1145 | 1185 | |
| 1146 | 1186 | $_SESSION['attachments_to_fix'] = array(); |
| 1147 | 1187 | // @todo No need to do this I think. |
| 1148 | - foreach ($_POST['to_fix'] as $value) |
|
| 1149 | - $_SESSION['attachments_to_fix'][] = $value; |
|
| 1188 | + foreach ($_POST['to_fix'] as $value) { |
|
| 1189 | + $_SESSION['attachments_to_fix'][] = $value; |
|
| 1190 | + } |
|
| 1150 | 1191 | } |
| 1151 | 1192 | } |
| 1152 | 1193 | |
@@ -1213,13 +1254,14 @@ discard block |
||
| 1213 | 1254 | } |
| 1214 | 1255 | } |
| 1215 | 1256 | } |
| 1216 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1217 | - $to_fix[] = 'missing_thumbnail_parent'; |
|
| 1257 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1258 | + $to_fix[] = 'missing_thumbnail_parent'; |
|
| 1259 | + } |
|
| 1218 | 1260 | $smcFunc['db_free_result']($result); |
| 1219 | 1261 | |
| 1220 | 1262 | // Do we need to delete what we have? |
| 1221 | - if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) |
|
| 1222 | - $smcFunc['db_query']('', ' |
|
| 1263 | + if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) { |
|
| 1264 | + $smcFunc['db_query']('', ' |
|
| 1223 | 1265 | DELETE FROM {db_prefix}attachments |
| 1224 | 1266 | WHERE id_attach IN ({array_int:to_remove}) |
| 1225 | 1267 | AND attachment_type = {int:attachment_type}', |
@@ -1228,6 +1270,7 @@ discard block |
||
| 1228 | 1270 | 'attachment_type' => 3, |
| 1229 | 1271 | ) |
| 1230 | 1272 | ); |
| 1273 | + } |
|
| 1231 | 1274 | |
| 1232 | 1275 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
| 1233 | 1276 | } |
@@ -1272,13 +1315,14 @@ discard block |
||
| 1272 | 1315 | $to_update[] = $row['id_attach']; |
| 1273 | 1316 | $context['repair_errors']['parent_missing_thumbnail']++; |
| 1274 | 1317 | } |
| 1275 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1276 | - $to_fix[] = 'parent_missing_thumbnail'; |
|
| 1318 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1319 | + $to_fix[] = 'parent_missing_thumbnail'; |
|
| 1320 | + } |
|
| 1277 | 1321 | $smcFunc['db_free_result']($result); |
| 1278 | 1322 | |
| 1279 | 1323 | // Do we need to delete what we have? |
| 1280 | - if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix)) |
|
| 1281 | - $smcFunc['db_query']('', ' |
|
| 1324 | + if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix)) { |
|
| 1325 | + $smcFunc['db_query']('', ' |
|
| 1282 | 1326 | UPDATE {db_prefix}attachments |
| 1283 | 1327 | SET id_thumb = {int:no_thumb} |
| 1284 | 1328 | WHERE id_attach IN ({array_int:to_update})', |
@@ -1287,6 +1331,7 @@ discard block |
||
| 1287 | 1331 | 'no_thumb' => 0, |
| 1288 | 1332 | ) |
| 1289 | 1333 | ); |
| 1334 | + } |
|
| 1290 | 1335 | |
| 1291 | 1336 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
| 1292 | 1337 | } |
@@ -1324,10 +1369,11 @@ discard block |
||
| 1324 | 1369 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 1325 | 1370 | { |
| 1326 | 1371 | // Get the filename. |
| 1327 | - if ($row['attachment_type'] == 1) |
|
| 1328 | - $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
| 1329 | - else |
|
| 1330 | - $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
| 1372 | + if ($row['attachment_type'] == 1) { |
|
| 1373 | + $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
| 1374 | + } else { |
|
| 1375 | + $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
| 1376 | + } |
|
| 1331 | 1377 | |
| 1332 | 1378 | // File doesn't exist? |
| 1333 | 1379 | if (!file_exists($filename)) |
@@ -1339,15 +1385,16 @@ discard block |
||
| 1339 | 1385 | $attachment_name = $row['id_attach'] . '_' . $row['file_hash'] .'.dat'; |
| 1340 | 1386 | |
| 1341 | 1387 | // Loop through the other folders. |
| 1342 | - foreach ($modSettings['attachmentUploadDir'] as $id => $dir) |
|
| 1343 | - if (file_exists($dir . '/' . $attachment_name)) |
|
| 1388 | + foreach ($modSettings['attachmentUploadDir'] as $id => $dir) { |
|
| 1389 | + if (file_exists($dir . '/' . $attachment_name)) |
|
| 1344 | 1390 | { |
| 1345 | 1391 | $context['repair_errors']['wrong_folder']++; |
| 1392 | + } |
|
| 1346 | 1393 | $errors_found[] = 'wrong_folder'; |
| 1347 | 1394 | |
| 1348 | 1395 | // Are we going to fix this now? |
| 1349 | - if ($fix_errors && in_array('wrong_folder', $to_fix)) |
|
| 1350 | - $smcFunc['db_query']('', ' |
|
| 1396 | + if ($fix_errors && in_array('wrong_folder', $to_fix)) { |
|
| 1397 | + $smcFunc['db_query']('', ' |
|
| 1351 | 1398 | UPDATE {db_prefix}attachments |
| 1352 | 1399 | SET id_folder = {int:new_folder} |
| 1353 | 1400 | WHERE id_attach = {int:id_attach}', |
@@ -1356,6 +1403,7 @@ discard block |
||
| 1356 | 1403 | 'id_attach' => $row['id_attach'], |
| 1357 | 1404 | ) |
| 1358 | 1405 | ); |
| 1406 | + } |
|
| 1359 | 1407 | |
| 1360 | 1408 | continue 2; |
| 1361 | 1409 | } |
@@ -1364,8 +1412,7 @@ discard block |
||
| 1364 | 1412 | $to_remove[] = $row['id_attach']; |
| 1365 | 1413 | $context['repair_errors']['file_missing_on_disk']++; |
| 1366 | 1414 | $errors_found[] = 'file_missing_on_disk'; |
| 1367 | - } |
|
| 1368 | - elseif (filesize($filename) == 0) |
|
| 1415 | + } elseif (filesize($filename) == 0) |
|
| 1369 | 1416 | { |
| 1370 | 1417 | $context['repair_errors']['file_size_of_zero']++; |
| 1371 | 1418 | $errors_found[] = 'file_size_of_zero'; |
@@ -1376,8 +1423,7 @@ discard block |
||
| 1376 | 1423 | $to_remove[] = $row['id_attach']; |
| 1377 | 1424 | @unlink($filename); |
| 1378 | 1425 | } |
| 1379 | - } |
|
| 1380 | - elseif (filesize($filename) != $row['size']) |
|
| 1426 | + } elseif (filesize($filename) != $row['size']) |
|
| 1381 | 1427 | { |
| 1382 | 1428 | $context['repair_errors']['file_wrong_size']++; |
| 1383 | 1429 | $errors_found[] = 'file_wrong_size'; |
@@ -1398,14 +1444,18 @@ discard block |
||
| 1398 | 1444 | } |
| 1399 | 1445 | } |
| 1400 | 1446 | |
| 1401 | - if (in_array('file_missing_on_disk', $errors_found)) |
|
| 1402 | - $to_fix[] = 'file_missing_on_disk'; |
|
| 1403 | - if (in_array('file_size_of_zero', $errors_found)) |
|
| 1404 | - $to_fix[] = 'file_size_of_zero'; |
|
| 1405 | - if (in_array('file_wrong_size', $errors_found)) |
|
| 1406 | - $to_fix[] = 'file_wrong_size'; |
|
| 1407 | - if (in_array('wrong_folder', $errors_found)) |
|
| 1408 | - $to_fix[] = 'wrong_folder'; |
|
| 1447 | + if (in_array('file_missing_on_disk', $errors_found)) { |
|
| 1448 | + $to_fix[] = 'file_missing_on_disk'; |
|
| 1449 | + } |
|
| 1450 | + if (in_array('file_size_of_zero', $errors_found)) { |
|
| 1451 | + $to_fix[] = 'file_size_of_zero'; |
|
| 1452 | + } |
|
| 1453 | + if (in_array('file_wrong_size', $errors_found)) { |
|
| 1454 | + $to_fix[] = 'file_wrong_size'; |
|
| 1455 | + } |
|
| 1456 | + if (in_array('wrong_folder', $errors_found)) { |
|
| 1457 | + $to_fix[] = 'wrong_folder'; |
|
| 1458 | + } |
|
| 1409 | 1459 | $smcFunc['db_free_result']($result); |
| 1410 | 1460 | |
| 1411 | 1461 | // Do we need to delete what we have? |
@@ -1475,20 +1525,22 @@ discard block |
||
| 1475 | 1525 | // If we are repairing remove the file from disk now. |
| 1476 | 1526 | if ($fix_errors && in_array('avatar_no_member', $to_fix)) |
| 1477 | 1527 | { |
| 1478 | - if ($row['attachment_type'] == 1) |
|
| 1479 | - $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
| 1480 | - else |
|
| 1481 | - $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
| 1528 | + if ($row['attachment_type'] == 1) { |
|
| 1529 | + $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
| 1530 | + } else { |
|
| 1531 | + $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
| 1532 | + } |
|
| 1482 | 1533 | @unlink($filename); |
| 1483 | 1534 | } |
| 1484 | 1535 | } |
| 1485 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1486 | - $to_fix[] = 'avatar_no_member'; |
|
| 1536 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1537 | + $to_fix[] = 'avatar_no_member'; |
|
| 1538 | + } |
|
| 1487 | 1539 | $smcFunc['db_free_result']($result); |
| 1488 | 1540 | |
| 1489 | 1541 | // Do we need to delete what we have? |
| 1490 | - if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix)) |
|
| 1491 | - $smcFunc['db_query']('', ' |
|
| 1542 | + if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix)) { |
|
| 1543 | + $smcFunc['db_query']('', ' |
|
| 1492 | 1544 | DELETE FROM {db_prefix}attachments |
| 1493 | 1545 | WHERE id_attach IN ({array_int:to_remove}) |
| 1494 | 1546 | AND id_member != {int:no_member} |
@@ -1499,6 +1551,7 @@ discard block |
||
| 1499 | 1551 | 'no_msg' => 0, |
| 1500 | 1552 | ) |
| 1501 | 1553 | ); |
| 1554 | + } |
|
| 1502 | 1555 | |
| 1503 | 1556 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
| 1504 | 1557 | } |
@@ -1554,13 +1607,14 @@ discard block |
||
| 1554 | 1607 | @unlink($filename); |
| 1555 | 1608 | } |
| 1556 | 1609 | } |
| 1557 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1558 | - $to_fix[] = 'attachment_no_msg'; |
|
| 1610 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1611 | + $to_fix[] = 'attachment_no_msg'; |
|
| 1612 | + } |
|
| 1559 | 1613 | $smcFunc['db_free_result']($result); |
| 1560 | 1614 | |
| 1561 | 1615 | // Do we need to delete what we have? |
| 1562 | - if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix)) |
|
| 1563 | - $smcFunc['db_query']('', ' |
|
| 1616 | + if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix)) { |
|
| 1617 | + $smcFunc['db_query']('', ' |
|
| 1564 | 1618 | DELETE FROM {db_prefix}attachments |
| 1565 | 1619 | WHERE id_attach IN ({array_int:to_remove}) |
| 1566 | 1620 | AND id_member = {int:no_member} |
@@ -1571,6 +1625,7 @@ discard block |
||
| 1571 | 1625 | 'no_msg' => 0, |
| 1572 | 1626 | ) |
| 1573 | 1627 | ); |
| 1628 | + } |
|
| 1574 | 1629 | |
| 1575 | 1630 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
| 1576 | 1631 | } |
@@ -1594,8 +1649,9 @@ discard block |
||
| 1594 | 1649 | { |
| 1595 | 1650 | while ($file = readdir($dir)) |
| 1596 | 1651 | { |
| 1597 | - if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) |
|
| 1598 | - continue; |
|
| 1652 | + if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) { |
|
| 1653 | + continue; |
|
| 1654 | + } |
|
| 1599 | 1655 | |
| 1600 | 1656 | if ($files_checked <= $current_check) |
| 1601 | 1657 | { |
@@ -1603,8 +1659,9 @@ discard block |
||
| 1603 | 1659 | if (strpos($file, 'post_tmp_') !== false) |
| 1604 | 1660 | { |
| 1605 | 1661 | // Temp file is more than 5 hours old! |
| 1606 | - if (filemtime($attach_dir . '/' . $file) < time() - 18000) |
|
| 1607 | - @unlink($attach_dir . '/' . $file); |
|
| 1662 | + if (filemtime($attach_dir . '/' . $file) < time() - 18000) { |
|
| 1663 | + @unlink($attach_dir . '/' . $file); |
|
| 1664 | + } |
|
| 1608 | 1665 | } |
| 1609 | 1666 | // That should be an attachment, let's check if we have it in the database |
| 1610 | 1667 | elseif (strpos($file, '_') !== false) |
@@ -1626,8 +1683,7 @@ discard block |
||
| 1626 | 1683 | if ($fix_errors && in_array('files_without_attachment', $to_fix)) |
| 1627 | 1684 | { |
| 1628 | 1685 | @unlink($attach_dir . '/' . $file); |
| 1629 | - } |
|
| 1630 | - else |
|
| 1686 | + } else |
|
| 1631 | 1687 | { |
| 1632 | 1688 | $context['repair_errors']['files_without_attachment']++; |
| 1633 | 1689 | $to_fix[] = 'files_without_attachment'; |
@@ -1635,14 +1691,12 @@ discard block |
||
| 1635 | 1691 | } |
| 1636 | 1692 | $smcFunc['db_free_result']($request); |
| 1637 | 1693 | } |
| 1638 | - } |
|
| 1639 | - else |
|
| 1694 | + } else |
|
| 1640 | 1695 | { |
| 1641 | 1696 | if ($fix_errors && in_array('files_without_attachment', $to_fix)) |
| 1642 | 1697 | { |
| 1643 | 1698 | @unlink($attach_dir . '/' . $file); |
| 1644 | - } |
|
| 1645 | - else |
|
| 1699 | + } else |
|
| 1646 | 1700 | { |
| 1647 | 1701 | $context['repair_errors']['files_without_attachment']++; |
| 1648 | 1702 | $to_fix[] = 'files_without_attachment'; |
@@ -1651,8 +1705,9 @@ discard block |
||
| 1651 | 1705 | } |
| 1652 | 1706 | $current_check++; |
| 1653 | 1707 | $_GET['substep'] = $current_check; |
| 1654 | - if ($current_check - $files_checked >= $max_checks) |
|
| 1655 | - pauseAttachmentMaintenance($to_fix); |
|
| 1708 | + if ($current_check - $files_checked >= $max_checks) { |
|
| 1709 | + pauseAttachmentMaintenance($to_fix); |
|
| 1710 | + } |
|
| 1656 | 1711 | } |
| 1657 | 1712 | closedir($dir); |
| 1658 | 1713 | } |
@@ -1688,12 +1743,14 @@ discard block |
||
| 1688 | 1743 | |
| 1689 | 1744 | // Try get more time... |
| 1690 | 1745 | @set_time_limit(600); |
| 1691 | - if (function_exists('apache_reset_timeout')) |
|
| 1692 | - @apache_reset_timeout(); |
|
| 1746 | + if (function_exists('apache_reset_timeout')) { |
|
| 1747 | + @apache_reset_timeout(); |
|
| 1748 | + } |
|
| 1693 | 1749 | |
| 1694 | 1750 | // Have we already used our maximum time? |
| 1695 | - if (time() - array_sum(explode(' ', $time_start)) < 3 || $context['starting_substep'] == $_GET['substep']) |
|
| 1696 | - return; |
|
| 1751 | + if (time() - array_sum(explode(' ', $time_start)) < 3 || $context['starting_substep'] == $_GET['substep']) { |
|
| 1752 | + return; |
|
| 1753 | + } |
|
| 1697 | 1754 | |
| 1698 | 1755 | $context['continue_get_data'] = '?action=admin;area=manageattachments;sa=repair' . (isset($_GET['fixErrors']) ? ';fixErrors' : '') . ';step=' . $_GET['step'] . ';substep=' . $_GET['substep'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
| 1699 | 1756 | $context['page_title'] = $txt['not_done_title']; |
@@ -1705,10 +1762,11 @@ discard block |
||
| 1705 | 1762 | $context[$context['admin_menu_name']]['current_subsection'] = 'maintenance'; |
| 1706 | 1763 | |
| 1707 | 1764 | // Change these two if more steps are added! |
| 1708 | - if (empty($max_substep)) |
|
| 1709 | - $context['continue_percent'] = round(($_GET['step'] * 100) / 25); |
|
| 1710 | - else |
|
| 1711 | - $context['continue_percent'] = round(($_GET['step'] * 100 + ($_GET['substep'] * 100) / $max_substep) / 25); |
|
| 1765 | + if (empty($max_substep)) { |
|
| 1766 | + $context['continue_percent'] = round(($_GET['step'] * 100) / 25); |
|
| 1767 | + } else { |
|
| 1768 | + $context['continue_percent'] = round(($_GET['step'] * 100 + ($_GET['substep'] * 100) / $max_substep) / 25); |
|
| 1769 | + } |
|
| 1712 | 1770 | |
| 1713 | 1771 | // Never more than 100%! |
| 1714 | 1772 | $context['continue_percent'] = min($context['continue_percent'], 100); |
@@ -1750,15 +1808,17 @@ discard block |
||
| 1750 | 1808 | 'attachment_type' => 0, |
| 1751 | 1809 | ) |
| 1752 | 1810 | ); |
| 1753 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1754 | - $attachments[] = $row['id_attach']; |
|
| 1811 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1812 | + $attachments[] = $row['id_attach']; |
|
| 1813 | + } |
|
| 1755 | 1814 | $smcFunc['db_free_result']($request); |
| 1815 | + } elseif (!empty($_GET['aid'])) { |
|
| 1816 | + $attachments[] = (int) $_GET['aid']; |
|
| 1756 | 1817 | } |
| 1757 | - elseif (!empty($_GET['aid'])) |
|
| 1758 | - $attachments[] = (int) $_GET['aid']; |
|
| 1759 | 1818 | |
| 1760 | - if (empty($attachments)) |
|
| 1761 | - fatal_lang_error('no_access', false); |
|
| 1819 | + if (empty($attachments)) { |
|
| 1820 | + fatal_lang_error('no_access', false); |
|
| 1821 | + } |
|
| 1762 | 1822 | |
| 1763 | 1823 | // Now we have some ID's cleaned and ready to approve, but first - let's check we have permission! |
| 1764 | 1824 | $allowed_boards = boardsAllowedTo('approve_posts'); |
@@ -1791,17 +1851,18 @@ discard block |
||
| 1791 | 1851 | } |
| 1792 | 1852 | $smcFunc['db_free_result']($request); |
| 1793 | 1853 | |
| 1794 | - if (empty($attachments)) |
|
| 1795 | - fatal_lang_error('no_access', false); |
|
| 1854 | + if (empty($attachments)) { |
|
| 1855 | + fatal_lang_error('no_access', false); |
|
| 1856 | + } |
|
| 1796 | 1857 | |
| 1797 | 1858 | // Finally, we are there. Follow through! |
| 1798 | 1859 | if ($is_approve) |
| 1799 | 1860 | { |
| 1800 | 1861 | // Checked and deemed worthy. |
| 1801 | 1862 | ApproveAttachments($attachments); |
| 1863 | + } else { |
|
| 1864 | + removeAttachments(array('id_attach' => $attachments, 'do_logging' => true)); |
|
| 1802 | 1865 | } |
| 1803 | - else |
|
| 1804 | - removeAttachments(array('id_attach' => $attachments, 'do_logging' => true)); |
|
| 1805 | 1866 | |
| 1806 | 1867 | // Return to the topic.... |
| 1807 | 1868 | redirectexit($redirect); |
@@ -1817,8 +1878,9 @@ discard block |
||
| 1817 | 1878 | { |
| 1818 | 1879 | global $smcFunc; |
| 1819 | 1880 | |
| 1820 | - if (empty($attachments)) |
|
| 1821 | - return 0; |
|
| 1881 | + if (empty($attachments)) { |
|
| 1882 | + return 0; |
|
| 1883 | + } |
|
| 1822 | 1884 | |
| 1823 | 1885 | // For safety, check for thumbnails... |
| 1824 | 1886 | $request = $smcFunc['db_query']('', ' |
@@ -1837,15 +1899,17 @@ discard block |
||
| 1837 | 1899 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1838 | 1900 | { |
| 1839 | 1901 | // Update the thumbnail too... |
| 1840 | - if (!empty($row['id_thumb'])) |
|
| 1841 | - $attachments[] = $row['id_thumb']; |
|
| 1902 | + if (!empty($row['id_thumb'])) { |
|
| 1903 | + $attachments[] = $row['id_thumb']; |
|
| 1904 | + } |
|
| 1842 | 1905 | |
| 1843 | 1906 | $attachments[] = $row['id_attach']; |
| 1844 | 1907 | } |
| 1845 | 1908 | $smcFunc['db_free_result']($request); |
| 1846 | 1909 | |
| 1847 | - if (empty($attachments)) |
|
| 1848 | - return 0; |
|
| 1910 | + if (empty($attachments)) { |
|
| 1911 | + return 0; |
|
| 1912 | + } |
|
| 1849 | 1913 | |
| 1850 | 1914 | // Approving an attachment is not hard - it's easy. |
| 1851 | 1915 | $smcFunc['db_query']('', ' |
@@ -1871,14 +1935,15 @@ discard block |
||
| 1871 | 1935 | ) |
| 1872 | 1936 | ); |
| 1873 | 1937 | |
| 1874 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1875 | - logAction( |
|
| 1938 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1939 | + logAction( |
|
| 1876 | 1940 | 'approve_attach', |
| 1877 | 1941 | array( |
| 1878 | 1942 | 'message' => $row['id_msg'], |
| 1879 | 1943 | 'filename' => preg_replace('~&#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($row['filename'])), |
| 1880 | 1944 | ) |
| 1881 | 1945 | ); |
| 1946 | + } |
|
| 1882 | 1947 | $smcFunc['db_free_result']($request); |
| 1883 | 1948 | |
| 1884 | 1949 | // Remove from the approval queue. |
@@ -1901,11 +1966,11 @@ discard block |
||
| 1901 | 1966 | global $modSettings, $scripturl, $context, $txt, $sourcedir, $boarddir, $smcFunc, $settings; |
| 1902 | 1967 | |
| 1903 | 1968 | // Since this needs to be done eventually. |
| 1904 | - if (!isset($modSettings['attachment_basedirectories'])) |
|
| 1905 | - $modSettings['attachment_basedirectories'] = array(); |
|
| 1906 | - |
|
| 1907 | - elseif (!is_array($modSettings['attachment_basedirectories'])) |
|
| 1908 | - $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 1969 | + if (!isset($modSettings['attachment_basedirectories'])) { |
|
| 1970 | + $modSettings['attachment_basedirectories'] = array(); |
|
| 1971 | + } elseif (!is_array($modSettings['attachment_basedirectories'])) { |
|
| 1972 | + $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 1973 | + } |
|
| 1909 | 1974 | |
| 1910 | 1975 | $errors = array(); |
| 1911 | 1976 | |
@@ -1920,8 +1985,9 @@ discard block |
||
| 1920 | 1985 | { |
| 1921 | 1986 | $error = ''; |
| 1922 | 1987 | $id = (int) $id; |
| 1923 | - if ($id < 1) |
|
| 1924 | - continue; |
|
| 1988 | + if ($id < 1) { |
|
| 1989 | + continue; |
|
| 1990 | + } |
|
| 1925 | 1991 | |
| 1926 | 1992 | // Sorry, these dirs are NOT valid |
| 1927 | 1993 | $invalid_dirs = array($boarddir, $settings['default_theme_dir'], $sourcedir); |
@@ -1940,8 +2006,7 @@ discard block |
||
| 1940 | 2006 | { |
| 1941 | 2007 | $errors[] = $path . ': ' . $txt['attach_dir_duplicate_msg']; |
| 1942 | 2008 | continue; |
| 1943 | - } |
|
| 1944 | - elseif (empty($path)) |
|
| 2009 | + } elseif (empty($path)) |
|
| 1945 | 2010 | { |
| 1946 | 2011 | // Ignore this and set $id to one less |
| 1947 | 2012 | continue; |
@@ -1949,10 +2014,11 @@ discard block |
||
| 1949 | 2014 | |
| 1950 | 2015 | // OK, so let's try to create it then. |
| 1951 | 2016 | require_once($sourcedir . '/Subs-Attachments.php'); |
| 1952 | - if (automanage_attachments_create_directory($path)) |
|
| 1953 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 1954 | - else |
|
| 1955 | - $errors[] = $path . ': ' . $txt[$context['dir_creation_error']]; |
|
| 2017 | + if (automanage_attachments_create_directory($path)) { |
|
| 2018 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2019 | + } else { |
|
| 2020 | + $errors[] = $path . ': ' . $txt[$context['dir_creation_error']]; |
|
| 2021 | + } |
|
| 1956 | 2022 | } |
| 1957 | 2023 | |
| 1958 | 2024 | // Changing a directory name? |
@@ -1965,8 +2031,7 @@ discard block |
||
| 1965 | 2031 | $errors[] = $path . ': ' . $txt['attach_dir_no_rename']; |
| 1966 | 2032 | $path = $modSettings['attachmentUploadDir'][$id]; |
| 1967 | 2033 | } |
| 1968 | - } |
|
| 1969 | - else |
|
| 2034 | + } else |
|
| 1970 | 2035 | { |
| 1971 | 2036 | $errors[] = $path . ': ' . $txt['attach_dir_exists_msg']; |
| 1972 | 2037 | $path = $modSettings['attachmentUploadDir'][$id]; |
@@ -1991,12 +2056,13 @@ discard block |
||
| 1991 | 2056 | $path = $modSettings['attachmentUploadDir'][$id]; |
| 1992 | 2057 | |
| 1993 | 2058 | // It's not a good idea to delete the current directory. |
| 1994 | - if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir'])) |
|
| 1995 | - $errors[] = $path . ': ' . $txt['attach_dir_is_current']; |
|
| 2059 | + if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir'])) { |
|
| 2060 | + $errors[] = $path . ': ' . $txt['attach_dir_is_current']; |
|
| 2061 | + } |
|
| 1996 | 2062 | // Or the current base directory |
| 1997 | - elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id]) |
|
| 1998 | - $errors[] = $path . ': ' . $txt['attach_dir_is_current_bd']; |
|
| 1999 | - else |
|
| 2063 | + elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id]) { |
|
| 2064 | + $errors[] = $path . ': ' . $txt['attach_dir_is_current_bd']; |
|
| 2065 | + } else |
|
| 2000 | 2066 | { |
| 2001 | 2067 | // Let's not try to delete a path with files in it. |
| 2002 | 2068 | $request = $smcFunc['db_query']('', ' |
@@ -2015,17 +2081,18 @@ discard block |
||
| 2015 | 2081 | if (!empty($modSettings['attachment_basedirectories'])) |
| 2016 | 2082 | { |
| 2017 | 2083 | // Count any sub-folders. |
| 2018 | - foreach ($modSettings['attachmentUploadDir'] as $sub) |
|
| 2019 | - if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false) |
|
| 2084 | + foreach ($modSettings['attachmentUploadDir'] as $sub) { |
|
| 2085 | + if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false) |
|
| 2020 | 2086 | $num_attach++; |
| 2087 | + } |
|
| 2021 | 2088 | } |
| 2022 | 2089 | |
| 2023 | 2090 | // It's safe to delete. So try to delete the folder also |
| 2024 | 2091 | if ($num_attach == 0) |
| 2025 | 2092 | { |
| 2026 | - if (is_dir($path)) |
|
| 2027 | - $doit = true; |
|
| 2028 | - elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path)) |
|
| 2093 | + if (is_dir($path)) { |
|
| 2094 | + $doit = true; |
|
| 2095 | + } elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path)) |
|
| 2029 | 2096 | { |
| 2030 | 2097 | $doit = true; |
| 2031 | 2098 | $path = $boarddir . DIRECTORY_SEPARATOR . $path; |
@@ -2035,8 +2102,9 @@ discard block |
||
| 2035 | 2102 | { |
| 2036 | 2103 | unlink($path . '/.htaccess'); |
| 2037 | 2104 | unlink($path . '/index.php'); |
| 2038 | - if (!@rmdir($path)) |
|
| 2039 | - $error = $path . ': ' . $txt['attach_dir_no_delete']; |
|
| 2105 | + if (!@rmdir($path)) { |
|
| 2106 | + $error = $path . ': ' . $txt['attach_dir_no_delete']; |
|
| 2107 | + } |
|
| 2040 | 2108 | } |
| 2041 | 2109 | |
| 2042 | 2110 | // Remove it from the base directory list. |
@@ -2046,14 +2114,15 @@ discard block |
||
| 2046 | 2114 | updateSettings(array('attachment_basedirectories' => json_encode($modSettings['attachment_basedirectories']))); |
| 2047 | 2115 | $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
| 2048 | 2116 | } |
| 2117 | + } else { |
|
| 2118 | + $error = $path . ': ' . $txt['attach_dir_no_remove']; |
|
| 2049 | 2119 | } |
| 2050 | - else |
|
| 2051 | - $error = $path . ': ' . $txt['attach_dir_no_remove']; |
|
| 2052 | 2120 | |
| 2053 | - if (empty($error)) |
|
| 2054 | - continue; |
|
| 2055 | - else |
|
| 2056 | - $errors[] = $error; |
|
| 2121 | + if (empty($error)) { |
|
| 2122 | + continue; |
|
| 2123 | + } else { |
|
| 2124 | + $errors[] = $error; |
|
| 2125 | + } |
|
| 2057 | 2126 | } |
| 2058 | 2127 | } |
| 2059 | 2128 | |
@@ -2061,23 +2130,26 @@ discard block |
||
| 2061 | 2130 | } |
| 2062 | 2131 | |
| 2063 | 2132 | // We need to make sure the current directory is right. |
| 2064 | - if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir'])) |
|
| 2065 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2133 | + if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir'])) { |
|
| 2134 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2135 | + } |
|
| 2066 | 2136 | |
| 2067 | 2137 | // Find the current directory if there's no value carried, |
| 2068 | 2138 | if (empty($_POST['current_dir']) || empty($new_dirs[$_POST['current_dir']])) |
| 2069 | 2139 | { |
| 2070 | - if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir'])) |
|
| 2071 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2072 | - else |
|
| 2073 | - $_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir'])); |
|
| 2140 | + if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir'])) { |
|
| 2141 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2142 | + } else { |
|
| 2143 | + $_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir'])); |
|
| 2144 | + } |
|
| 2074 | 2145 | } |
| 2075 | 2146 | |
| 2076 | 2147 | // If the user wishes to go back, update the last_dir array |
| 2077 | 2148 | if ($_POST['current_dir'] != $modSettings['currentAttachmentUploadDir']&& !empty($modSettings['last_attachments_directory']) && (isset($modSettings['last_attachments_directory'][$_POST['current_dir']]) || isset($modSettings['last_attachments_directory'][0]))) |
| 2078 | 2149 | { |
| 2079 | - if (!is_array($modSettings['last_attachments_directory'])) |
|
| 2080 | - $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
| 2150 | + if (!is_array($modSettings['last_attachments_directory'])) { |
|
| 2151 | + $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
| 2152 | + } |
|
| 2081 | 2153 | $num = substr(strrchr($modSettings['attachmentUploadDir'][$_POST['current_dir']], '_'), 1); |
| 2082 | 2154 | |
| 2083 | 2155 | if (is_numeric($num)) |
@@ -2085,16 +2157,18 @@ discard block |
||
| 2085 | 2157 | // Need to find the base folder. |
| 2086 | 2158 | $bid = -1; |
| 2087 | 2159 | $use_subdirectories_for_attachments = 0; |
| 2088 | - if (!empty($modSettings['attachment_basedirectories'])) |
|
| 2089 | - foreach ($modSettings['attachment_basedirectories'] as $bid => $base) |
|
| 2160 | + if (!empty($modSettings['attachment_basedirectories'])) { |
|
| 2161 | + foreach ($modSettings['attachment_basedirectories'] as $bid => $base) |
|
| 2090 | 2162 | if (strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $base . DIRECTORY_SEPARATOR) !==false) |
| 2091 | 2163 | { |
| 2092 | 2164 | $use_subdirectories_for_attachments = 1; |
| 2165 | + } |
|
| 2093 | 2166 | break; |
| 2094 | 2167 | } |
| 2095 | 2168 | |
| 2096 | - if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false) |
|
| 2097 | - $bid = 0; |
|
| 2169 | + if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false) { |
|
| 2170 | + $bid = 0; |
|
| 2171 | + } |
|
| 2098 | 2172 | |
| 2099 | 2173 | $modSettings['last_attachments_directory'][$bid] = (int) $num; |
| 2100 | 2174 | $modSettings['basedirectory_for_attachments'] = !empty($modSettings['basedirectory_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : ''; |
@@ -2113,8 +2187,8 @@ discard block |
||
| 2113 | 2187 | // We might need to reset the paths. This loop will just loop through once. |
| 2114 | 2188 | foreach ($new_dirs as $id => $dir) |
| 2115 | 2189 | { |
| 2116 | - if ($id != 1) |
|
| 2117 | - $smcFunc['db_query']('', ' |
|
| 2190 | + if ($id != 1) { |
|
| 2191 | + $smcFunc['db_query']('', ' |
|
| 2118 | 2192 | UPDATE {db_prefix}attachments |
| 2119 | 2193 | SET id_folder = {int:default_folder} |
| 2120 | 2194 | WHERE id_folder = {int:current_folder}', |
@@ -2123,14 +2197,14 @@ discard block |
||
| 2123 | 2197 | 'current_folder' => $id, |
| 2124 | 2198 | ) |
| 2125 | 2199 | ); |
| 2200 | + } |
|
| 2126 | 2201 | |
| 2127 | 2202 | $update = array( |
| 2128 | 2203 | 'currentAttachmentUploadDir' => 1, |
| 2129 | 2204 | 'attachmentUploadDir' => json_encode(array(1 => $dir)), |
| 2130 | 2205 | ); |
| 2131 | 2206 | } |
| 2132 | - } |
|
| 2133 | - else |
|
| 2207 | + } else |
|
| 2134 | 2208 | { |
| 2135 | 2209 | // Save it to the database. |
| 2136 | 2210 | $update = array( |
@@ -2139,11 +2213,13 @@ discard block |
||
| 2139 | 2213 | ); |
| 2140 | 2214 | } |
| 2141 | 2215 | |
| 2142 | - if (!empty($update)) |
|
| 2143 | - updateSettings($update); |
|
| 2216 | + if (!empty($update)) { |
|
| 2217 | + updateSettings($update); |
|
| 2218 | + } |
|
| 2144 | 2219 | |
| 2145 | - if (!empty($errors)) |
|
| 2146 | - $_SESSION['errors']['dir'] = $errors; |
|
| 2220 | + if (!empty($errors)) { |
|
| 2221 | + $_SESSION['errors']['dir'] = $errors; |
|
| 2222 | + } |
|
| 2147 | 2223 | |
| 2148 | 2224 | redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']); |
| 2149 | 2225 | } |
@@ -2157,10 +2233,11 @@ discard block |
||
| 2157 | 2233 | $_POST['current_base_dir'] = isset($_POST['current_base_dir']) ? (int) $_POST['current_base_dir'] : 1; |
| 2158 | 2234 | if (empty($_POST['new_base_dir']) && !empty($_POST['current_base_dir'])) |
| 2159 | 2235 | { |
| 2160 | - if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']]) |
|
| 2161 | - $update = (array( |
|
| 2236 | + if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']]) { |
|
| 2237 | + $update = (array( |
|
| 2162 | 2238 | 'basedirectory_for_attachments' => $modSettings['attachmentUploadDir'][$_POST['current_base_dir']], |
| 2163 | 2239 | )); |
| 2240 | + } |
|
| 2164 | 2241 | } |
| 2165 | 2242 | |
| 2166 | 2243 | if (isset($_POST['base_dir'])) |
@@ -2208,13 +2285,15 @@ discard block |
||
| 2208 | 2285 | |
| 2209 | 2286 | if (!in_array($_POST['new_base_dir'], $modSettings['attachmentUploadDir'])) |
| 2210 | 2287 | { |
| 2211 | - if (!automanage_attachments_create_directory($_POST['new_base_dir'])) |
|
| 2212 | - $errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create']; |
|
| 2288 | + if (!automanage_attachments_create_directory($_POST['new_base_dir'])) { |
|
| 2289 | + $errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create']; |
|
| 2290 | + } |
|
| 2213 | 2291 | } |
| 2214 | 2292 | |
| 2215 | 2293 | $modSettings['currentAttachmentUploadDir'] = array_search($_POST['new_base_dir'], $modSettings['attachmentUploadDir']); |
| 2216 | - if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories'])) |
|
| 2217 | - $modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir']; |
|
| 2294 | + if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories'])) { |
|
| 2295 | + $modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir']; |
|
| 2296 | + } |
|
| 2218 | 2297 | ksort($modSettings['attachment_basedirectories']); |
| 2219 | 2298 | |
| 2220 | 2299 | $update = (array( |
@@ -2224,11 +2303,13 @@ discard block |
||
| 2224 | 2303 | )); |
| 2225 | 2304 | } |
| 2226 | 2305 | |
| 2227 | - if (!empty($errors)) |
|
| 2228 | - $_SESSION['errors']['base'] = $errors; |
|
| 2306 | + if (!empty($errors)) { |
|
| 2307 | + $_SESSION['errors']['base'] = $errors; |
|
| 2308 | + } |
|
| 2229 | 2309 | |
| 2230 | - if (!empty($update)) |
|
| 2231 | - updateSettings($update); |
|
| 2310 | + if (!empty($update)) { |
|
| 2311 | + updateSettings($update); |
|
| 2312 | + } |
|
| 2232 | 2313 | |
| 2233 | 2314 | redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']); |
| 2234 | 2315 | } |
@@ -2238,13 +2319,15 @@ discard block |
||
| 2238 | 2319 | if (is_array($_SESSION['errors'])) |
| 2239 | 2320 | { |
| 2240 | 2321 | $errors = array(); |
| 2241 | - if (!empty($_SESSION['errors']['dir'])) |
|
| 2242 | - foreach ($_SESSION['errors']['dir'] as $error) |
|
| 2322 | + if (!empty($_SESSION['errors']['dir'])) { |
|
| 2323 | + foreach ($_SESSION['errors']['dir'] as $error) |
|
| 2243 | 2324 | $errors['dir'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES); |
| 2325 | + } |
|
| 2244 | 2326 | |
| 2245 | - if (!empty($_SESSION['errors']['base'])) |
|
| 2246 | - foreach ($_SESSION['errors']['base'] as $error) |
|
| 2327 | + if (!empty($_SESSION['errors']['base'])) { |
|
| 2328 | + foreach ($_SESSION['errors']['base'] as $error) |
|
| 2247 | 2329 | $errors['base'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES); |
| 2330 | + } |
|
| 2248 | 2331 | } |
| 2249 | 2332 | unset($_SESSION['errors']); |
| 2250 | 2333 | } |
@@ -2454,8 +2537,9 @@ discard block |
||
| 2454 | 2537 | foreach ($modSettings['attachmentUploadDir'] as $id => $dir) |
| 2455 | 2538 | { |
| 2456 | 2539 | // If there aren't any attachments in this directory this won't exist. |
| 2457 | - if (!isset($expected_files[$id])) |
|
| 2458 | - $expected_files[$id] = 0; |
|
| 2540 | + if (!isset($expected_files[$id])) { |
|
| 2541 | + $expected_files[$id] = 0; |
|
| 2542 | + } |
|
| 2459 | 2543 | |
| 2460 | 2544 | // Check if the directory is doing okay. |
| 2461 | 2545 | list ($status, $error, $files) = attachDirStatus($dir, $expected_files[$id]); |
@@ -2468,10 +2552,11 @@ discard block |
||
| 2468 | 2552 | $is_base_dir = in_array($dir, $modSettings['attachment_basedirectories']); |
| 2469 | 2553 | |
| 2470 | 2554 | // Count any sub-folders. |
| 2471 | - foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) |
|
| 2472 | - if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
| 2555 | + foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) { |
|
| 2556 | + if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
| 2473 | 2557 | { |
| 2474 | 2558 | $expected_files[$id]++; |
| 2559 | + } |
|
| 2475 | 2560 | $sub_dirs++; |
| 2476 | 2561 | } |
| 2477 | 2562 | } |
@@ -2489,8 +2574,8 @@ discard block |
||
| 2489 | 2574 | } |
| 2490 | 2575 | |
| 2491 | 2576 | // Just stick a new directory on at the bottom. |
| 2492 | - if (isset($_REQUEST['new_path'])) |
|
| 2493 | - $attachdirs[] = array( |
|
| 2577 | + if (isset($_REQUEST['new_path'])) { |
|
| 2578 | + $attachdirs[] = array( |
|
| 2494 | 2579 | 'id' => max(array_merge(array_keys($expected_files), array_keys($modSettings['attachmentUploadDir']))) + 1, |
| 2495 | 2580 | 'current' => false, |
| 2496 | 2581 | 'path' => '', |
@@ -2498,6 +2583,7 @@ discard block |
||
| 2498 | 2583 | 'num_files' => '', |
| 2499 | 2584 | 'status' => '', |
| 2500 | 2585 | ); |
| 2586 | + } |
|
| 2501 | 2587 | |
| 2502 | 2588 | return $attachdirs; |
| 2503 | 2589 | } |
@@ -2510,8 +2596,9 @@ discard block |
||
| 2510 | 2596 | { |
| 2511 | 2597 | global $modSettings, $txt; |
| 2512 | 2598 | |
| 2513 | - if (empty($modSettings['attachment_basedirectories'])) |
|
| 2514 | - return; |
|
| 2599 | + if (empty($modSettings['attachment_basedirectories'])) { |
|
| 2600 | + return; |
|
| 2601 | + } |
|
| 2515 | 2602 | |
| 2516 | 2603 | $basedirs = array(); |
| 2517 | 2604 | // Get a list of the base directories. |
@@ -2519,16 +2606,18 @@ discard block |
||
| 2519 | 2606 | { |
| 2520 | 2607 | // Loop through the attach directory array to count any sub-directories |
| 2521 | 2608 | $expected_dirs = 0; |
| 2522 | - foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) |
|
| 2523 | - if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
| 2609 | + foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) { |
|
| 2610 | + if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
| 2524 | 2611 | $expected_dirs++; |
| 2612 | + } |
|
| 2525 | 2613 | |
| 2526 | - if (!is_dir($dir)) |
|
| 2527 | - $status = 'does_not_exist'; |
|
| 2528 | - elseif (!is_writeable($dir)) |
|
| 2529 | - $status = 'not_writable'; |
|
| 2530 | - else |
|
| 2531 | - $status = 'ok'; |
|
| 2614 | + if (!is_dir($dir)) { |
|
| 2615 | + $status = 'does_not_exist'; |
|
| 2616 | + } elseif (!is_writeable($dir)) { |
|
| 2617 | + $status = 'not_writable'; |
|
| 2618 | + } else { |
|
| 2619 | + $status = 'ok'; |
|
| 2620 | + } |
|
| 2532 | 2621 | |
| 2533 | 2622 | $basedirs[] = array( |
| 2534 | 2623 | 'id' => $id, |
@@ -2539,14 +2628,15 @@ discard block |
||
| 2539 | 2628 | ); |
| 2540 | 2629 | } |
| 2541 | 2630 | |
| 2542 | - if (isset($_REQUEST['new_base_path'])) |
|
| 2543 | - $basedirs[] = array( |
|
| 2631 | + if (isset($_REQUEST['new_base_path'])) { |
|
| 2632 | + $basedirs[] = array( |
|
| 2544 | 2633 | 'id' => '', |
| 2545 | 2634 | 'current' => false, |
| 2546 | 2635 | 'path' => '<input type="text" name="new_base_dir" value="" size="40">', |
| 2547 | 2636 | 'num_dirs' => '', |
| 2548 | 2637 | 'status' => '', |
| 2549 | 2638 | ); |
| 2639 | + } |
|
| 2550 | 2640 | |
| 2551 | 2641 | return $basedirs; |
| 2552 | 2642 | } |
@@ -2562,10 +2652,11 @@ discard block |
||
| 2562 | 2652 | */ |
| 2563 | 2653 | function attachDirStatus($dir, $expected_files) |
| 2564 | 2654 | { |
| 2565 | - if (!is_dir($dir)) |
|
| 2566 | - return array('does_not_exist', true, ''); |
|
| 2567 | - elseif (!is_writable($dir)) |
|
| 2568 | - return array('not_writable', true, ''); |
|
| 2655 | + if (!is_dir($dir)) { |
|
| 2656 | + return array('does_not_exist', true, ''); |
|
| 2657 | + } elseif (!is_writable($dir)) { |
|
| 2658 | + return array('not_writable', true, ''); |
|
| 2659 | + } |
|
| 2569 | 2660 | |
| 2570 | 2661 | // Everything is okay so far, start to scan through the directory. |
| 2571 | 2662 | $num_files = 0; |
@@ -2573,22 +2664,26 @@ discard block |
||
| 2573 | 2664 | while ($file = $dir_handle->read()) |
| 2574 | 2665 | { |
| 2575 | 2666 | // Now do we have a real file here? |
| 2576 | - if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) |
|
| 2577 | - continue; |
|
| 2667 | + if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) { |
|
| 2668 | + continue; |
|
| 2669 | + } |
|
| 2578 | 2670 | |
| 2579 | 2671 | $num_files++; |
| 2580 | 2672 | } |
| 2581 | 2673 | $dir_handle->close(); |
| 2582 | 2674 | |
| 2583 | - if ($num_files < $expected_files) |
|
| 2584 | - return array('files_missing', true, $num_files); |
|
| 2675 | + if ($num_files < $expected_files) { |
|
| 2676 | + return array('files_missing', true, $num_files); |
|
| 2677 | + } |
|
| 2585 | 2678 | // Empty? |
| 2586 | - elseif ($expected_files == 0) |
|
| 2587 | - return array('unused', false, $num_files); |
|
| 2679 | + elseif ($expected_files == 0) { |
|
| 2680 | + return array('unused', false, $num_files); |
|
| 2681 | + } |
|
| 2588 | 2682 | // All good! |
| 2589 | - else |
|
| 2590 | - return array('ok', false, $num_files); |
|
| 2591 | -} |
|
| 2683 | + else { |
|
| 2684 | + return array('ok', false, $num_files); |
|
| 2685 | + } |
|
| 2686 | + } |
|
| 2592 | 2687 | |
| 2593 | 2688 | /** |
| 2594 | 2689 | * Maintance function to move attachments from one directory to another |
@@ -2600,10 +2695,11 @@ discard block |
||
| 2600 | 2695 | checkSession(); |
| 2601 | 2696 | |
| 2602 | 2697 | $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
| 2603 | - if (!empty($modSettings['attachment_basedirectories'])) |
|
| 2604 | - $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 2605 | - else |
|
| 2606 | - $modSettings['basedirectory_for_attachments'] = array(); |
|
| 2698 | + if (!empty($modSettings['attachment_basedirectories'])) { |
|
| 2699 | + $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 2700 | + } else { |
|
| 2701 | + $modSettings['basedirectory_for_attachments'] = array(); |
|
| 2702 | + } |
|
| 2607 | 2703 | |
| 2608 | 2704 | $_POST['from'] = (int) $_POST['from']; |
| 2609 | 2705 | $_POST['auto'] = !empty($_POST['auto']) ? (int) $_POST['auto'] : 0; |
@@ -2617,11 +2713,13 @@ discard block |
||
| 2617 | 2713 | $total_moved = 0; |
| 2618 | 2714 | $total_not_moved = 0; |
| 2619 | 2715 | |
| 2620 | - if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to']))) |
|
| 2621 | - $results[] = $txt['attachment_transfer_no_dir']; |
|
| 2716 | + if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to']))) { |
|
| 2717 | + $results[] = $txt['attachment_transfer_no_dir']; |
|
| 2718 | + } |
|
| 2622 | 2719 | |
| 2623 | - if ($_POST['from'] == $_POST['to']) |
|
| 2624 | - $results[] = $txt['attachment_transfer_same_dir']; |
|
| 2720 | + if ($_POST['from'] == $_POST['to']) { |
|
| 2721 | + $results[] = $txt['attachment_transfer_same_dir']; |
|
| 2722 | + } |
|
| 2625 | 2723 | |
| 2626 | 2724 | if (empty($results)) |
| 2627 | 2725 | { |
@@ -2640,8 +2738,9 @@ discard block |
||
| 2640 | 2738 | $smcFunc['db_free_result']($request); |
| 2641 | 2739 | $total_progress -= $start; |
| 2642 | 2740 | |
| 2643 | - if ($total_progress < 1) |
|
| 2644 | - $results[] = $txt['attachment_transfer_no_find']; |
|
| 2741 | + if ($total_progress < 1) { |
|
| 2742 | + $results[] = $txt['attachment_transfer_no_find']; |
|
| 2743 | + } |
|
| 2645 | 2744 | } |
| 2646 | 2745 | |
| 2647 | 2746 | if (empty($results)) |
@@ -2657,9 +2756,9 @@ discard block |
||
| 2657 | 2756 | |
| 2658 | 2757 | automanage_attachments_check_directory(); |
| 2659 | 2758 | $new_dir = $modSettings['currentAttachmentUploadDir']; |
| 2759 | + } else { |
|
| 2760 | + $new_dir = $_POST['to']; |
|
| 2660 | 2761 | } |
| 2661 | - else |
|
| 2662 | - $new_dir = $_POST['to']; |
|
| 2663 | 2762 | |
| 2664 | 2763 | $modSettings['currentAttachmentUploadDir'] = $new_dir; |
| 2665 | 2764 | |
@@ -2667,8 +2766,9 @@ discard block |
||
| 2667 | 2766 | while ($break == false) |
| 2668 | 2767 | { |
| 2669 | 2768 | @set_time_limit(300); |
| 2670 | - if (function_exists('apache_reset_timeout')) |
|
| 2671 | - @apache_reset_timeout(); |
|
| 2769 | + if (function_exists('apache_reset_timeout')) { |
|
| 2770 | + @apache_reset_timeout(); |
|
| 2771 | + } |
|
| 2672 | 2772 | |
| 2673 | 2773 | // If limits are set, get the file count and size for the destination folder |
| 2674 | 2774 | if ($dir_files <= 0 && (!empty($modSettings['attachmentDirSizeLimit']) || !empty($modSettings['attachmentDirFileLimit']))) |
@@ -2704,13 +2804,15 @@ discard block |
||
| 2704 | 2804 | |
| 2705 | 2805 | if ($smcFunc['db_num_rows']($request) === 0) |
| 2706 | 2806 | { |
| 2707 | - if (empty($current_progress)) |
|
| 2708 | - $results[] = $txt['attachment_transfer_no_find']; |
|
| 2807 | + if (empty($current_progress)) { |
|
| 2808 | + $results[] = $txt['attachment_transfer_no_find']; |
|
| 2809 | + } |
|
| 2709 | 2810 | break; |
| 2710 | 2811 | } |
| 2711 | 2812 | |
| 2712 | - if ($smcFunc['db_num_rows']($request) < $limit) |
|
| 2713 | - $break = true; |
|
| 2813 | + if ($smcFunc['db_num_rows']($request) < $limit) { |
|
| 2814 | + $break = true; |
|
| 2815 | + } |
|
| 2714 | 2816 | |
| 2715 | 2817 | // Move them |
| 2716 | 2818 | $moved = array(); |
@@ -2734,8 +2836,9 @@ discard block |
||
| 2734 | 2836 | automanage_attachments_by_space(); |
| 2735 | 2837 | |
| 2736 | 2838 | $results[] = sprintf($txt['attachments_transferred'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]); |
| 2737 | - if (!empty($total_not_moved)) |
|
| 2738 | - $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
| 2839 | + if (!empty($total_not_moved)) { |
|
| 2840 | + $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
| 2841 | + } |
|
| 2739 | 2842 | |
| 2740 | 2843 | $dir_files = 0; |
| 2741 | 2844 | $total_moved = 0; |
@@ -2743,8 +2846,7 @@ discard block |
||
| 2743 | 2846 | |
| 2744 | 2847 | $break = false; |
| 2745 | 2848 | break; |
| 2746 | - } |
|
| 2747 | - else |
|
| 2849 | + } else |
|
| 2748 | 2850 | { |
| 2749 | 2851 | // Hmm, not in auto. Time to bail out then... |
| 2750 | 2852 | $results[] = $txt['attachment_transfer_no_room']; |
@@ -2759,9 +2861,9 @@ discard block |
||
| 2759 | 2861 | $total_moved++; |
| 2760 | 2862 | $current_progress++; |
| 2761 | 2863 | $moved[] = $row['id_attach']; |
| 2864 | + } else { |
|
| 2865 | + $total_not_moved++; |
|
| 2762 | 2866 | } |
| 2763 | - else |
|
| 2764 | - $total_not_moved++; |
|
| 2765 | 2867 | } |
| 2766 | 2868 | $smcFunc['db_free_result']($request); |
| 2767 | 2869 | |
@@ -2800,13 +2902,15 @@ discard block |
||
| 2800 | 2902 | } |
| 2801 | 2903 | |
| 2802 | 2904 | $results[] = sprintf($txt['attachments_transferred'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]); |
| 2803 | - if (!empty($total_not_moved)) |
|
| 2804 | - $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
| 2905 | + if (!empty($total_not_moved)) { |
|
| 2906 | + $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
| 2907 | + } |
|
| 2805 | 2908 | } |
| 2806 | 2909 | |
| 2807 | 2910 | $_SESSION['results'] = $results; |
| 2808 | - if (file_exists($boarddir . '/progress.php')) |
|
| 2809 | - unlink($boarddir . '/progress.php'); |
|
| 2911 | + if (file_exists($boarddir . '/progress.php')) { |
|
| 2912 | + unlink($boarddir . '/progress.php'); |
|
| 2913 | + } |
|
| 2810 | 2914 | |
| 2811 | 2915 | redirectexit('action=admin;area=manageattachments;sa=maintenance#transfer'); |
| 2812 | 2916 | } |
@@ -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 | class Attachments |
| 20 | 21 | { |
@@ -70,16 +71,18 @@ discard block |
||
| 70 | 71 | |
| 71 | 72 | $this->_sa = !empty($_REQUEST['sa']) ? $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_REQUEST['sa'])) : false; |
| 72 | 73 | |
| 73 | - if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) |
|
| 74 | - $this->{$this->_sa}(); |
|
| 74 | + if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) { |
|
| 75 | + $this->{$this->_sa}(); |
|
| 76 | + } |
|
| 75 | 77 | |
| 76 | 78 | // Just send a generic message. |
| 77 | - else |
|
| 78 | - $this->setResponse(array( |
|
| 79 | + else { |
|
| 80 | + $this->setResponse(array( |
|
| 79 | 81 | 'text' => $this->_sa == 'add' ? 'attach_error_title' : 'attached_file_deleted_error', |
| 80 | 82 | 'type' => 'error', |
| 81 | 83 | 'data' => false, |
| 82 | 84 | )); |
| 85 | + } |
|
| 83 | 86 | |
| 84 | 87 | // Back to the future, oh, to the browser! |
| 85 | 88 | $this->sendResponse(); |
@@ -95,12 +98,13 @@ discard block |
||
| 95 | 98 | $attachID = !empty($_REQUEST['attach']) && is_numeric($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : 0; |
| 96 | 99 | |
| 97 | 100 | // Need something to work with. |
| 98 | - if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) |
|
| 99 | - return $this->setResponse(array( |
|
| 101 | + if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) { |
|
| 102 | + return $this->setResponse(array( |
|
| 100 | 103 | 'text' => 'attached_file_deleted_error', |
| 101 | 104 | 'type' => 'error', |
| 102 | 105 | 'data' => false, |
| 103 | 106 | )); |
| 107 | + } |
|
| 104 | 108 | |
| 105 | 109 | // Lets pass some params and see what happens :P |
| 106 | 110 | $affectedMessage = removeAttachments(array('id_attach' => $attachID), '', true, true); |
@@ -121,19 +125,21 @@ discard block |
||
| 121 | 125 | $result = array(); |
| 122 | 126 | |
| 123 | 127 | // You gotta be able to post attachments. |
| 124 | - if (!$this->_canPostAttachment) |
|
| 125 | - return $this->setResponse(array( |
|
| 128 | + if (!$this->_canPostAttachment) { |
|
| 129 | + return $this->setResponse(array( |
|
| 126 | 130 | 'text' => 'attached_file_cannot', |
| 127 | 131 | 'type' => 'error', |
| 128 | 132 | 'data' => false, |
| 129 | 133 | )); |
| 134 | + } |
|
| 130 | 135 | |
| 131 | 136 | // Process them at once! |
| 132 | 137 | $this->processAttachments(); |
| 133 | 138 | |
| 134 | 139 | // The attachments was created and moved the the right folder, time to update the DB. |
| 135 | - if (!empty($_SESSION['temp_attachments'])) |
|
| 136 | - $this->createAtttach(); |
|
| 140 | + if (!empty($_SESSION['temp_attachments'])) { |
|
| 141 | + $this->createAtttach(); |
|
| 142 | + } |
|
| 137 | 143 | |
| 138 | 144 | // Set the response. |
| 139 | 145 | $this->setResponse(); |
@@ -146,8 +152,9 @@ discard block |
||
| 146 | 152 | { |
| 147 | 153 | global $context, $modSettings, $smcFunc, $user_info, $txt; |
| 148 | 154 | |
| 149 | - if (!isset($_FILES['attachment']['name'])) |
|
| 150 | - $_FILES['attachment']['tmp_name'] = array(); |
|
| 155 | + if (!isset($_FILES['attachment']['name'])) { |
|
| 156 | + $_FILES['attachment']['tmp_name'] = array(); |
|
| 157 | + } |
|
| 151 | 158 | |
| 152 | 159 | // If there are attachments, calculate the total size and how many. |
| 153 | 160 | $context['attachments']['total_size'] = 0; |
@@ -157,25 +164,30 @@ discard block |
||
| 157 | 164 | if (isset($_REQUEST['msg'])) |
| 158 | 165 | { |
| 159 | 166 | $context['attachments']['quantity'] = count($context['current_attachments']); |
| 160 | - foreach ($context['current_attachments'] as $attachment) |
|
| 161 | - $context['attachments']['total_size'] += $attachment['size']; |
|
| 167 | + foreach ($context['current_attachments'] as $attachment) { |
|
| 168 | + $context['attachments']['total_size'] += $attachment['size']; |
|
| 169 | + } |
|
| 162 | 170 | } |
| 163 | 171 | |
| 164 | 172 | // A bit of house keeping first. |
| 165 | - if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) |
|
| 166 | - unset($_SESSION['temp_attachments']); |
|
| 173 | + if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) { |
|
| 174 | + unset($_SESSION['temp_attachments']); |
|
| 175 | + } |
|
| 167 | 176 | |
| 168 | 177 | // Our infamous SESSION var, we are gonna have soo much fun with it! |
| 169 | - if (!isset($_SESSION['temp_attachments'])) |
|
| 170 | - $_SESSION['temp_attachments'] = array(); |
|
| 178 | + if (!isset($_SESSION['temp_attachments'])) { |
|
| 179 | + $_SESSION['temp_attachments'] = array(); |
|
| 180 | + } |
|
| 171 | 181 | |
| 172 | 182 | // Make sure we're uploading to the right place. |
| 173 | - if (!empty($modSettings['automanage_attachments'])) |
|
| 174 | - automanage_attachments_check_directory(); |
|
| 183 | + if (!empty($modSettings['automanage_attachments'])) { |
|
| 184 | + automanage_attachments_check_directory(); |
|
| 185 | + } |
|
| 175 | 186 | |
| 176 | 187 | // Is the attachments folder actually there? |
| 177 | - if (!empty($context['dir_creation_error'])) |
|
| 178 | - $this->_generalErrors[] = $context['dir_creation_error']; |
|
| 188 | + if (!empty($context['dir_creation_error'])) { |
|
| 189 | + $this->_generalErrors[] = $context['dir_creation_error']; |
|
| 190 | + } |
|
| 179 | 191 | |
| 180 | 192 | // The current attach folder ha some issues... |
| 181 | 193 | elseif (!is_dir($this->_attchDir)) |
@@ -200,13 +212,12 @@ discard block |
||
| 200 | 212 | ); |
| 201 | 213 | list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request); |
| 202 | 214 | $smcFunc['db_free_result']($request); |
| 203 | - } |
|
| 204 | - |
|
| 205 | - else |
|
| 206 | - $context['attachments'] = array( |
|
| 215 | + } else { |
|
| 216 | + $context['attachments'] = array( |
|
| 207 | 217 | 'quantity' => 0, |
| 208 | 218 | 'total_size' => 0, |
| 209 | 219 | ); |
| 220 | + } |
|
| 210 | 221 | |
| 211 | 222 | // Check for other general errors here. |
| 212 | 223 | |
@@ -214,9 +225,10 @@ discard block |
||
| 214 | 225 | if (!empty($this->_generalErrors)) |
| 215 | 226 | { |
| 216 | 227 | // And delete the files 'cos they ain't going nowhere. |
| 217 | - foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
|
| 218 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 228 | + foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) { |
|
| 229 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 219 | 230 | unlink($_FILES['attachment']['tmp_name'][$n]); |
| 231 | + } |
|
| 220 | 232 | |
| 221 | 233 | $_FILES['attachment']['tmp_name'] = array(); |
| 222 | 234 | |
@@ -227,26 +239,29 @@ discard block |
||
| 227 | 239 | // Loop through $_FILES['attachment'] array and move each file to the current attachments folder. |
| 228 | 240 | foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
| 229 | 241 | { |
| 230 | - if ($_FILES['attachment']['name'][$n] == '') |
|
| 231 | - continue; |
|
| 242 | + if ($_FILES['attachment']['name'][$n] == '') { |
|
| 243 | + continue; |
|
| 244 | + } |
|
| 232 | 245 | |
| 233 | 246 | // First, let's first check for PHP upload errors. |
| 234 | 247 | $errors = array(); |
| 235 | 248 | if (!empty($_FILES['attachment']['error'][$n])) |
| 236 | 249 | { |
| 237 | - if ($_FILES['attachment']['error'][$n] == 2) |
|
| 238 | - $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
| 239 | - |
|
| 240 | - else |
|
| 241 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
| 250 | + if ($_FILES['attachment']['error'][$n] == 2) { |
|
| 251 | + $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
| 252 | + } else { |
|
| 253 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
| 254 | + } |
|
| 242 | 255 | |
| 243 | 256 | // Log this one, because... |
| 244 | - if ($_FILES['attachment']['error'][$n] == 6) |
|
| 245 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
| 257 | + if ($_FILES['attachment']['error'][$n] == 6) { |
|
| 258 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
| 259 | + } |
|
| 246 | 260 | |
| 247 | 261 | // Weird, no errors were cached, still fill out a generic one. |
| 248 | - if (empty($errors)) |
|
| 249 | - $errors[] = 'attach_php_error'; |
|
| 262 | + if (empty($errors)) { |
|
| 263 | + $errors[] = 'attach_php_error'; |
|
| 264 | + } |
|
| 250 | 265 | } |
| 251 | 266 | |
| 252 | 267 | // Try to move and rename the file before doing any more checks on it. |
@@ -266,16 +281,18 @@ discard block |
||
| 266 | 281 | ); |
| 267 | 282 | |
| 268 | 283 | // Move the file to the attachments folder with a temp name for now. |
| 269 | - if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) |
|
| 270 | - smf_chmod($destName, 0644); |
|
| 284 | + if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) { |
|
| 285 | + smf_chmod($destName, 0644); |
|
| 286 | + } |
|
| 271 | 287 | |
| 272 | 288 | // This is madness!! |
| 273 | 289 | else |
| 274 | 290 | { |
| 275 | 291 | // File couldn't be moved. |
| 276 | 292 | $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout'; |
| 277 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 278 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 293 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
| 294 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 295 | + } |
|
| 279 | 296 | } |
| 280 | 297 | } |
| 281 | 298 | |
@@ -288,13 +305,15 @@ discard block |
||
| 288 | 305 | 'errors' => $errors, |
| 289 | 306 | ); |
| 290 | 307 | |
| 291 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 292 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 308 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
| 309 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 310 | + } |
|
| 293 | 311 | } |
| 294 | 312 | |
| 295 | 313 | // If there's no errors to this point. We still do need to apply some additional checks before we are finished. |
| 296 | - if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
|
| 297 | - attachmentChecks($attachID); |
|
| 314 | + if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) { |
|
| 315 | + attachmentChecks($attachID); |
|
| 316 | + } |
|
| 298 | 317 | } |
| 299 | 318 | |
| 300 | 319 | // Mod authors, finally a hook to hang an alternate attachment upload system upon |
@@ -333,23 +352,24 @@ discard block |
||
| 333 | 352 | 'errors' => $attachment['errors'], |
| 334 | 353 | ); |
| 335 | 354 | |
| 336 | - if (empty($attachment['errors'])) |
|
| 337 | - if (createAttachment($attachmentOptions)) |
|
| 355 | + if (empty($attachment['errors'])) { |
|
| 356 | + if (createAttachment($attachmentOptions)) |
|
| 338 | 357 | { |
| 339 | 358 | // Avoid JS getting confused. |
| 340 | 359 | $attachmentOptions['attachID'] = $attachmentOptions['id']; |
| 360 | + } |
|
| 341 | 361 | unset($attachmentOptions['id']); |
| 342 | 362 | |
| 343 | 363 | $_SESSION['already_attached'][$attachmentOptions['attachID']] = $attachmentOptions['attachID']; |
| 344 | 364 | |
| 345 | - if (!empty($attachmentOptions['thumb'])) |
|
| 346 | - $_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb']; |
|
| 347 | - |
|
| 348 | - if ($this->_msg) |
|
| 349 | - assignAttachments($_SESSION['already_attached'], $this->_msg); |
|
| 350 | - } |
|
| 365 | + if (!empty($attachmentOptions['thumb'])) { |
|
| 366 | + $_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb']; |
|
| 367 | + } |
|
| 351 | 368 | |
| 352 | - elseif (!empty($attachmentOptions['errors'])) |
|
| 369 | + if ($this->_msg) { |
|
| 370 | + assignAttachments($_SESSION['already_attached'], $this->_msg); |
|
| 371 | + } |
|
| 372 | + } elseif (!empty($attachmentOptions['errors'])) |
|
| 353 | 373 | { |
| 354 | 374 | // Sort out the errors for display and delete any associated files. |
| 355 | 375 | $log_these = array('attachments_no_create', 'attachments_no_write', 'attach_timeout', 'ran_out_of_space', 'cant_access_upload_path', 'attach_0_byte_file'); |
@@ -361,14 +381,16 @@ discard block |
||
| 361 | 381 | if (!is_array($error)) |
| 362 | 382 | { |
| 363 | 383 | $attachmentOptions['errors'][] = $txt[$error]; |
| 364 | - if (in_array($error, $log_these)) |
|
| 365 | - log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
| 384 | + if (in_array($error, $log_these)) { |
|
| 385 | + log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
| 386 | + } |
|
| 387 | + } else { |
|
| 388 | + $attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]); |
|
| 366 | 389 | } |
| 367 | - else |
|
| 368 | - $attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]); |
|
| 369 | 390 | } |
| 370 | - if (file_exists($attachment['tmp_name'])) |
|
| 371 | - unlink($attachment['tmp_name']); |
|
| 391 | + if (file_exists($attachment['tmp_name'])) { |
|
| 392 | + unlink($attachment['tmp_name']); |
|
| 393 | + } |
|
| 372 | 394 | } |
| 373 | 395 | |
| 374 | 396 | // Regardless of errors, pass the results. |
@@ -376,8 +398,9 @@ discard block |
||
| 376 | 398 | } |
| 377 | 399 | |
| 378 | 400 | // Temp save this on the db. |
| 379 | - if (!empty($_SESSION['already_attached'])) |
|
| 380 | - $this->_attachSuccess = $_SESSION['already_attached']; |
|
| 401 | + if (!empty($_SESSION['already_attached'])) { |
|
| 402 | + $this->_attachSuccess = $_SESSION['already_attached']; |
|
| 403 | + } |
|
| 381 | 404 | |
| 382 | 405 | unset($_SESSION['temp_attachments']); |
| 383 | 406 | } |
@@ -397,14 +420,16 @@ discard block |
||
| 397 | 420 | if ($this->_sa == 'add') |
| 398 | 421 | { |
| 399 | 422 | // Is there any generic errors? made some sense out of them! |
| 400 | - if ($this->_generalErrors) |
|
| 401 | - foreach ($this->_generalErrors as $k => $v) |
|
| 423 | + if ($this->_generalErrors) { |
|
| 424 | + foreach ($this->_generalErrors as $k => $v) |
|
| 402 | 425 | $this->_generalErrors[$k] = (is_array($v) ? vsprintf($txt[$v[0]], $v[1]) : $txt[$v]); |
| 426 | + } |
|
| 403 | 427 | |
| 404 | 428 | // Gotta urlencode the filename. |
| 405 | - if ($this->_attachResults) |
|
| 406 | - foreach ($this->_attachResults as $k => $v) |
|
| 429 | + if ($this->_attachResults) { |
|
| 430 | + foreach ($this->_attachResults as $k => $v) |
|
| 407 | 431 | $this->_attachResults[$k]['name'] = urlencode($this->_attachResults[$k]['name']); |
| 432 | + } |
|
| 408 | 433 | |
| 409 | 434 | $this->_response = array( |
| 410 | 435 | 'files' => $this->_attachResults ? $this->_attachResults : false, |
@@ -413,9 +438,10 @@ discard block |
||
| 413 | 438 | } |
| 414 | 439 | |
| 415 | 440 | // Rest of us mere mortals gets no special treatment... |
| 416 | - elseif (!empty($data)) |
|
| 417 | - if (!empty($data['text']) && !empty($txt[$data['text']])) |
|
| 441 | + elseif (!empty($data)) { |
|
| 442 | + if (!empty($data['text']) && !empty($txt[$data['text']])) |
|
| 418 | 443 | $this->_response['text'] = $txt[$data['text']]; |
| 444 | + } |
|
| 419 | 445 | } |
| 420 | 446 | |
| 421 | 447 | protected function sendResponse() |
@@ -424,11 +450,11 @@ discard block |
||
| 424 | 450 | |
| 425 | 451 | ob_end_clean(); |
| 426 | 452 | |
| 427 | - if (!empty($modSettings['CompressedOutput'])) |
|
| 428 | - @ob_start('ob_gzhandler'); |
|
| 429 | - |
|
| 430 | - else |
|
| 431 | - ob_start(); |
|
| 453 | + if (!empty($modSettings['CompressedOutput'])) { |
|
| 454 | + @ob_start('ob_gzhandler'); |
|
| 455 | + } else { |
|
| 456 | + ob_start(); |
|
| 457 | + } |
|
| 432 | 458 | |
| 433 | 459 | // Set the header. |
| 434 | 460 | header('Content-Type: application/json; charset='. $context['character_set'] .''); |
@@ -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 | /** |
@@ -44,8 +45,9 @@ discard block |
||
| 44 | 45 | $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('manage_membergroups') ? 'index' : 'settings'); |
| 45 | 46 | |
| 46 | 47 | // Is it elsewhere? |
| 47 | - if (isset($subActions[$_REQUEST['sa']][2])) |
|
| 48 | - require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]); |
|
| 48 | + if (isset($subActions[$_REQUEST['sa']][2])) { |
|
| 49 | + require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]); |
|
| 50 | + } |
|
| 49 | 51 | |
| 50 | 52 | // Do the permission check, you might not be allowed her. |
| 51 | 53 | isAllowedTo($subActions[$_REQUEST['sa']][1]); |
@@ -104,19 +106,20 @@ discard block |
||
| 104 | 106 | 'function' => function ($rowData) use ($scripturl) |
| 105 | 107 | { |
| 106 | 108 | // Since the moderator group has no explicit members, no link is needed. |
| 107 | - if ($rowData['id_group'] == 3) |
|
| 108 | - $group_name = $rowData['group_name']; |
|
| 109 | - else |
|
| 109 | + if ($rowData['id_group'] == 3) { |
|
| 110 | + $group_name = $rowData['group_name']; |
|
| 111 | + } else |
|
| 110 | 112 | { |
| 111 | 113 | $color_style = empty($rowData['online_color']) ? '' : sprintf(' style="color: %1$s;"', $rowData['online_color']); |
| 112 | 114 | $group_name = sprintf('<a href="%1$s?action=admin;area=membergroups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']); |
| 113 | 115 | } |
| 114 | 116 | |
| 115 | 117 | // Add a help option for moderator and administrator. |
| 116 | - if ($rowData['id_group'] == 1) |
|
| 117 | - $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
| 118 | - elseif ($rowData['id_group'] == 3) |
|
| 119 | - $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
| 118 | + if ($rowData['id_group'] == 1) { |
|
| 119 | + $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
| 120 | + } elseif ($rowData['id_group'] == 3) { |
|
| 121 | + $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
| 122 | + } |
|
| 120 | 123 | |
| 121 | 124 | return $group_name; |
| 122 | 125 | }, |
@@ -330,12 +333,14 @@ discard block |
||
| 330 | 333 | call_integration_hook('integrate_add_membergroup', array($id_group, $postCountBasedGroup)); |
| 331 | 334 | |
| 332 | 335 | // Update the post groups now, if this is a post group! |
| 333 | - if (isset($_POST['min_posts'])) |
|
| 334 | - updateStats('postgroups'); |
|
| 336 | + if (isset($_POST['min_posts'])) { |
|
| 337 | + updateStats('postgroups'); |
|
| 338 | + } |
|
| 335 | 339 | |
| 336 | 340 | // You cannot set permissions for post groups if they are disabled. |
| 337 | - if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups'])) |
|
| 338 | - $_POST['perm_type'] = ''; |
|
| 341 | + if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups'])) { |
|
| 342 | + $_POST['perm_type'] = ''; |
|
| 343 | + } |
|
| 339 | 344 | |
| 340 | 345 | if ($_POST['perm_type'] == 'predefined') |
| 341 | 346 | { |
@@ -365,8 +370,9 @@ discard block |
||
| 365 | 370 | $smcFunc['db_free_result']($request); |
| 366 | 371 | |
| 367 | 372 | // Protected groups are... well, protected! |
| 368 | - if ($copy_type == 1) |
|
| 369 | - fatal_lang_error('membergroup_does_not_exist'); |
|
| 373 | + if ($copy_type == 1) { |
|
| 374 | + fatal_lang_error('membergroup_does_not_exist'); |
|
| 375 | + } |
|
| 370 | 376 | } |
| 371 | 377 | |
| 372 | 378 | // Don't allow copying of a real priviledged person! |
@@ -384,18 +390,20 @@ discard block |
||
| 384 | 390 | $inserts = array(); |
| 385 | 391 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 386 | 392 | { |
| 387 | - if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions'])) |
|
| 388 | - $inserts[] = array($id_group, $row['permission'], $row['add_deny']); |
|
| 393 | + if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions'])) { |
|
| 394 | + $inserts[] = array($id_group, $row['permission'], $row['add_deny']); |
|
| 395 | + } |
|
| 389 | 396 | } |
| 390 | 397 | $smcFunc['db_free_result']($request); |
| 391 | 398 | |
| 392 | - if (!empty($inserts)) |
|
| 393 | - $smcFunc['db_insert']('insert', |
|
| 399 | + if (!empty($inserts)) { |
|
| 400 | + $smcFunc['db_insert']('insert', |
|
| 394 | 401 | '{db_prefix}permissions', |
| 395 | 402 | array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'), |
| 396 | 403 | $inserts, |
| 397 | 404 | array('id_group', 'permission') |
| 398 | 405 | ); |
| 406 | + } |
|
| 399 | 407 | |
| 400 | 408 | $request = $smcFunc['db_query']('', ' |
| 401 | 409 | SELECT id_profile, permission, add_deny |
@@ -406,17 +414,19 @@ discard block |
||
| 406 | 414 | ) |
| 407 | 415 | ); |
| 408 | 416 | $inserts = array(); |
| 409 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 410 | - $inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']); |
|
| 417 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 418 | + $inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']); |
|
| 419 | + } |
|
| 411 | 420 | $smcFunc['db_free_result']($request); |
| 412 | 421 | |
| 413 | - if (!empty($inserts)) |
|
| 414 | - $smcFunc['db_insert']('insert', |
|
| 422 | + if (!empty($inserts)) { |
|
| 423 | + $smcFunc['db_insert']('insert', |
|
| 415 | 424 | '{db_prefix}board_permissions', |
| 416 | 425 | array('id_group' => 'int', 'id_profile' => 'int', 'permission' => 'string', 'add_deny' => 'int'), |
| 417 | 426 | $inserts, |
| 418 | 427 | array('id_group', 'id_profile', 'permission') |
| 419 | 428 | ); |
| 429 | + } |
|
| 420 | 430 | |
| 421 | 431 | // Also get some membergroup information if we're copying and not copying from guests... |
| 422 | 432 | if ($copy_id > 0 && $_POST['perm_type'] == 'copy') |
@@ -469,14 +479,15 @@ discard block |
||
| 469 | 479 | $changed_boards['allow'] = array(); |
| 470 | 480 | $changed_boards['deny'] = array(); |
| 471 | 481 | $changed_boards['ignore'] = array(); |
| 472 | - foreach ($accesses as $group_id => $action) |
|
| 473 | - $changed_boards[$action][] = (int) $group_id; |
|
| 482 | + foreach ($accesses as $group_id => $action) { |
|
| 483 | + $changed_boards[$action][] = (int) $group_id; |
|
| 484 | + } |
|
| 474 | 485 | |
| 475 | 486 | foreach (array('allow', 'deny') as $board_action) |
| 476 | 487 | { |
| 477 | 488 | // Only do this if they have special access requirements. |
| 478 | - if (!empty($changed_boards[$board_action])) |
|
| 479 | - $smcFunc['db_query']('', ' |
|
| 489 | + if (!empty($changed_boards[$board_action])) { |
|
| 490 | + $smcFunc['db_query']('', ' |
|
| 480 | 491 | UPDATE {db_prefix}boards |
| 481 | 492 | SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END |
| 482 | 493 | WHERE id_board IN ({array_int:board_list})', |
@@ -488,11 +499,13 @@ discard block |
||
| 488 | 499 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
| 489 | 500 | ) |
| 490 | 501 | ); |
| 502 | + } |
|
| 491 | 503 | } |
| 492 | 504 | |
| 493 | 505 | // If this is joinable then set it to show group membership in people's profiles. |
| 494 | - if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1) |
|
| 495 | - updateSettings(array('show_group_membership' => 1)); |
|
| 506 | + if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1) { |
|
| 507 | + updateSettings(array('show_group_membership' => 1)); |
|
| 508 | + } |
|
| 496 | 509 | |
| 497 | 510 | // Rebuild the group cache. |
| 498 | 511 | updateSettings(array( |
@@ -513,8 +526,9 @@ discard block |
||
| 513 | 526 | $context['undefined_group'] = !isset($_REQUEST['postgroup']) && !isset($_REQUEST['generalgroup']); |
| 514 | 527 | $context['allow_protected'] = allowedTo('admin_forum'); |
| 515 | 528 | |
| 516 | - if (!empty($modSettings['deny_boards_access'])) |
|
| 517 | - loadLanguage('ManagePermissions'); |
|
| 529 | + if (!empty($modSettings['deny_boards_access'])) { |
|
| 530 | + loadLanguage('ManagePermissions'); |
|
| 531 | + } |
|
| 518 | 532 | |
| 519 | 533 | $result = $smcFunc['db_query']('', ' |
| 520 | 534 | SELECT id_group, group_name |
@@ -531,11 +545,12 @@ discard block |
||
| 531 | 545 | ) |
| 532 | 546 | ); |
| 533 | 547 | $context['groups'] = array(); |
| 534 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
| 535 | - $context['groups'][] = array( |
|
| 548 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
| 549 | + $context['groups'][] = array( |
|
| 536 | 550 | 'id' => $row['id_group'], |
| 537 | 551 | 'name' => $row['group_name'] |
| 538 | 552 | ); |
| 553 | + } |
|
| 539 | 554 | $smcFunc['db_free_result']($result); |
| 540 | 555 | |
| 541 | 556 | $request = $smcFunc['db_query']('', ' |
@@ -552,12 +567,13 @@ discard block |
||
| 552 | 567 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 553 | 568 | { |
| 554 | 569 | // This category hasn't been set up yet.. |
| 555 | - if (!isset($context['categories'][$row['id_cat']])) |
|
| 556 | - $context['categories'][$row['id_cat']] = array( |
|
| 570 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
| 571 | + $context['categories'][$row['id_cat']] = array( |
|
| 557 | 572 | 'id' => $row['id_cat'], |
| 558 | 573 | 'name' => $row['cat_name'], |
| 559 | 574 | 'boards' => array() |
| 560 | 575 | ); |
| 576 | + } |
|
| 561 | 577 | |
| 562 | 578 | // Set this board up, and let the template know when it's a child. (indent them..) |
| 563 | 579 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -605,8 +621,9 @@ discard block |
||
| 605 | 621 | require_once($sourcedir . '/Subs-Membergroups.php'); |
| 606 | 622 | $result = deleteMembergroups((int) $_REQUEST['group']); |
| 607 | 623 | // Need to throw a warning if it went wrong, but this is the only one we have a message for... |
| 608 | - if ($result === 'group_cannot_delete_sub') |
|
| 609 | - fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
| 624 | + if ($result === 'group_cannot_delete_sub') { |
|
| 625 | + fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
| 626 | + } |
|
| 610 | 627 | |
| 611 | 628 | // Go back to the membergroup index. |
| 612 | 629 | redirectexit('action=admin;area=membergroups;'); |
@@ -628,8 +645,9 @@ discard block |
||
| 628 | 645 | |
| 629 | 646 | $_REQUEST['group'] = isset($_REQUEST['group']) && $_REQUEST['group'] > 0 ? (int) $_REQUEST['group'] : 0; |
| 630 | 647 | |
| 631 | - if (!empty($modSettings['deny_boards_access'])) |
|
| 632 | - loadLanguage('ManagePermissions'); |
|
| 648 | + if (!empty($modSettings['deny_boards_access'])) { |
|
| 649 | + loadLanguage('ManagePermissions'); |
|
| 650 | + } |
|
| 633 | 651 | |
| 634 | 652 | // Make sure this group is editable. |
| 635 | 653 | if (!empty($_REQUEST['group'])) |
@@ -651,8 +669,9 @@ discard block |
||
| 651 | 669 | } |
| 652 | 670 | |
| 653 | 671 | // Now, do we have a valid id? |
| 654 | - if (empty($_REQUEST['group'])) |
|
| 655 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
| 672 | + if (empty($_REQUEST['group'])) { |
|
| 673 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
| 674 | + } |
|
| 656 | 675 | |
| 657 | 676 | // People who can manage boards are a bit special. |
| 658 | 677 | require_once($sourcedir . '/Subs-Members.php'); |
@@ -683,8 +702,9 @@ discard block |
||
| 683 | 702 | require_once($sourcedir . '/Subs-Membergroups.php'); |
| 684 | 703 | $result = deleteMembergroups($_REQUEST['group']); |
| 685 | 704 | // Need to throw a warning if it went wrong, but this is the only one we have a message for... |
| 686 | - if ($result === 'group_cannot_delete_sub') |
|
| 687 | - fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
| 705 | + if ($result === 'group_cannot_delete_sub') { |
|
| 706 | + fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
| 707 | + } |
|
| 688 | 708 | |
| 689 | 709 | redirectexit('action=admin;area=membergroups;'); |
| 690 | 710 | } |
@@ -761,16 +781,18 @@ discard block |
||
| 761 | 781 | $request = $smcFunc['db_query']('', ' |
| 762 | 782 | SELECT id_board |
| 763 | 783 | FROM {db_prefix}boards'); |
| 764 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 765 | - $accesses[(int) $row['id_board']] = 'allow'; |
|
| 784 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 785 | + $accesses[(int) $row['id_board']] = 'allow'; |
|
| 786 | + } |
|
| 766 | 787 | $smcFunc['db_free_result']($request); |
| 767 | 788 | } |
| 768 | 789 | |
| 769 | 790 | $changed_boards['allow'] = array(); |
| 770 | 791 | $changed_boards['deny'] = array(); |
| 771 | 792 | $changed_boards['ignore'] = array(); |
| 772 | - foreach ($accesses as $group_id => $action) |
|
| 773 | - $changed_boards[$action][] = (int) $group_id; |
|
| 793 | + foreach ($accesses as $group_id => $action) { |
|
| 794 | + $changed_boards[$action][] = (int) $group_id; |
|
| 795 | + } |
|
| 774 | 796 | |
| 775 | 797 | foreach (array('allow', 'deny') as $board_action) |
| 776 | 798 | { |
@@ -786,8 +808,8 @@ discard block |
||
| 786 | 808 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
| 787 | 809 | ) |
| 788 | 810 | ); |
| 789 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 790 | - $smcFunc['db_query']('', ' |
|
| 811 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 812 | + $smcFunc['db_query']('', ' |
|
| 791 | 813 | UPDATE {db_prefix}boards |
| 792 | 814 | SET {raw:column} = {string:member_group_access} |
| 793 | 815 | WHERE id_board = {int:current_board}', |
@@ -797,11 +819,12 @@ discard block |
||
| 797 | 819 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
| 798 | 820 | ) |
| 799 | 821 | ); |
| 822 | + } |
|
| 800 | 823 | $smcFunc['db_free_result']($request); |
| 801 | 824 | |
| 802 | 825 | // Add the membergroup to all boards that hadn't been set yet. |
| 803 | - if (!empty($changed_boards[$board_action])) |
|
| 804 | - $smcFunc['db_query']('', ' |
|
| 826 | + if (!empty($changed_boards[$board_action])) { |
|
| 827 | + $smcFunc['db_query']('', ' |
|
| 805 | 828 | UPDATE {db_prefix}boards |
| 806 | 829 | SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END |
| 807 | 830 | WHERE id_board IN ({array_int:board_list}) |
@@ -815,6 +838,7 @@ discard block |
||
| 815 | 838 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
| 816 | 839 | ) |
| 817 | 840 | ); |
| 841 | + } |
|
| 818 | 842 | } |
| 819 | 843 | } |
| 820 | 844 | |
@@ -840,12 +864,14 @@ discard block |
||
| 840 | 864 | ) |
| 841 | 865 | ); |
| 842 | 866 | $updates = array(); |
| 843 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 844 | - $updates[$row['additional_groups']][] = $row['id_member']; |
|
| 867 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 868 | + $updates[$row['additional_groups']][] = $row['id_member']; |
|
| 869 | + } |
|
| 845 | 870 | $smcFunc['db_free_result']($request); |
| 846 | 871 | |
| 847 | - foreach ($updates as $additional_groups => $memberArray) |
|
| 848 | - updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group']))))); |
|
| 872 | + foreach ($updates as $additional_groups => $memberArray) { |
|
| 873 | + updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group']))))); |
|
| 874 | + } |
|
| 849 | 875 | |
| 850 | 876 | // Sorry, but post groups can't moderate boards |
| 851 | 877 | $request = $smcFunc['db_query']('', ' |
@@ -855,8 +881,7 @@ discard block |
||
| 855 | 881 | 'current_group' => (int) $_REQUEST['group'], |
| 856 | 882 | ) |
| 857 | 883 | ); |
| 858 | - } |
|
| 859 | - elseif ($_REQUEST['group'] != 3) |
|
| 884 | + } elseif ($_REQUEST['group'] != 3) |
|
| 860 | 885 | { |
| 861 | 886 | // Making it a hidden group? If so remove everyone with it as primary group (Actually, just make them additional). |
| 862 | 887 | if ($_POST['group_hidden'] == 2) |
@@ -871,8 +896,9 @@ discard block |
||
| 871 | 896 | ) |
| 872 | 897 | ); |
| 873 | 898 | $updates = array(); |
| 874 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 875 | - $updates[$row['additional_groups']][] = $row['id_member']; |
|
| 899 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 900 | + $updates[$row['additional_groups']][] = $row['id_member']; |
|
| 901 | + } |
|
| 876 | 902 | $smcFunc['db_free_result']($request); |
| 877 | 903 | |
| 878 | 904 | foreach ($updates as $additional_groups => $memberArray) |
@@ -914,8 +940,9 @@ discard block |
||
| 914 | 940 | $smcFunc['db_free_result']($request); |
| 915 | 941 | |
| 916 | 942 | // Do we need to update the setting? |
| 917 | - if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable)) |
|
| 918 | - updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0)); |
|
| 943 | + if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable)) { |
|
| 944 | + updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0)); |
|
| 945 | + } |
|
| 919 | 946 | } |
| 920 | 947 | |
| 921 | 948 | // Do we need to set inherited permissions? |
@@ -948,8 +975,9 @@ discard block |
||
| 948 | 975 | { |
| 949 | 976 | $moderators[$k] = trim($moderators[$k]); |
| 950 | 977 | |
| 951 | - if (strlen($moderators[$k]) == 0) |
|
| 952 | - unset($moderators[$k]); |
|
| 978 | + if (strlen($moderators[$k]) == 0) { |
|
| 979 | + unset($moderators[$k]); |
|
| 980 | + } |
|
| 953 | 981 | } |
| 954 | 982 | |
| 955 | 983 | // Find all the id_member's for the member_name's in the list. |
@@ -965,8 +993,9 @@ discard block |
||
| 965 | 993 | 'count' => count($moderators), |
| 966 | 994 | ) |
| 967 | 995 | ); |
| 968 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 969 | - $group_moderators[] = $row['id_member']; |
|
| 996 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 997 | + $group_moderators[] = $row['id_member']; |
|
| 998 | + } |
|
| 970 | 999 | $smcFunc['db_free_result']($request); |
| 971 | 1000 | } |
| 972 | 1001 | } |
@@ -974,8 +1003,9 @@ discard block |
||
| 974 | 1003 | if (!empty($_POST['moderator_list'])) |
| 975 | 1004 | { |
| 976 | 1005 | $moderators = array(); |
| 977 | - foreach ($_POST['moderator_list'] as $moderator) |
|
| 978 | - $moderators[] = (int) $moderator; |
|
| 1006 | + foreach ($_POST['moderator_list'] as $moderator) { |
|
| 1007 | + $moderators[] = (int) $moderator; |
|
| 1008 | + } |
|
| 979 | 1009 | |
| 980 | 1010 | if (!empty($moderators)) |
| 981 | 1011 | { |
@@ -989,8 +1019,9 @@ discard block |
||
| 989 | 1019 | 'num_moderators' => count($moderators), |
| 990 | 1020 | ) |
| 991 | 1021 | ); |
| 992 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 993 | - $group_moderators[] = $row['id_member']; |
|
| 1022 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1023 | + $group_moderators[] = $row['id_member']; |
|
| 1024 | + } |
|
| 994 | 1025 | $smcFunc['db_free_result']($request); |
| 995 | 1026 | } |
| 996 | 1027 | } |
@@ -1002,8 +1033,9 @@ discard block |
||
| 1002 | 1033 | if (!empty($group_moderators)) |
| 1003 | 1034 | { |
| 1004 | 1035 | $mod_insert = array(); |
| 1005 | - foreach ($group_moderators as $moderator) |
|
| 1006 | - $mod_insert[] = array($_REQUEST['group'], $moderator); |
|
| 1036 | + foreach ($group_moderators as $moderator) { |
|
| 1037 | + $mod_insert[] = array($_REQUEST['group'], $moderator); |
|
| 1038 | + } |
|
| 1007 | 1039 | |
| 1008 | 1040 | $smcFunc['db_insert']('insert', |
| 1009 | 1041 | '{db_prefix}group_moderators', |
@@ -1037,8 +1069,9 @@ discard block |
||
| 1037 | 1069 | 'current_group' => (int) $_REQUEST['group'], |
| 1038 | 1070 | ) |
| 1039 | 1071 | ); |
| 1040 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1041 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
| 1072 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1073 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
| 1074 | + } |
|
| 1042 | 1075 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1043 | 1076 | $smcFunc['db_free_result']($request); |
| 1044 | 1077 | |
@@ -1075,14 +1108,16 @@ discard block |
||
| 1075 | 1108 | ) |
| 1076 | 1109 | ); |
| 1077 | 1110 | $context['group']['moderators'] = array(); |
| 1078 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1079 | - $context['group']['moderators'][$row['id_member']] = $row['real_name']; |
|
| 1111 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1112 | + $context['group']['moderators'][$row['id_member']] = $row['real_name']; |
|
| 1113 | + } |
|
| 1080 | 1114 | $smcFunc['db_free_result']($request); |
| 1081 | 1115 | |
| 1082 | 1116 | $context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '"' . implode('", "', $context['group']['moderators']) . '"'; |
| 1083 | 1117 | |
| 1084 | - if (!empty($context['group']['moderators'])) |
|
| 1085 | - list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1); |
|
| 1118 | + if (!empty($context['group']['moderators'])) { |
|
| 1119 | + list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1); |
|
| 1120 | + } |
|
| 1086 | 1121 | |
| 1087 | 1122 | // Get a list of boards this membergroup is allowed to see. |
| 1088 | 1123 | $context['boards'] = array(); |
@@ -1102,12 +1137,13 @@ discard block |
||
| 1102 | 1137 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1103 | 1138 | { |
| 1104 | 1139 | // This category hasn't been set up yet.. |
| 1105 | - if (!isset($context['categories'][$row['id_cat']])) |
|
| 1106 | - $context['categories'][$row['id_cat']] = array( |
|
| 1140 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
| 1141 | + $context['categories'][$row['id_cat']] = array( |
|
| 1107 | 1142 | 'id' => $row['id_cat'], |
| 1108 | 1143 | 'name' => $row['cat_name'], |
| 1109 | 1144 | 'boards' => array() |
| 1110 | 1145 | ); |
| 1146 | + } |
|
| 1111 | 1147 | |
| 1112 | 1148 | // Set this board up, and let the template know when it's a child. (indent them..) |
| 1113 | 1149 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -1135,8 +1171,9 @@ discard block |
||
| 1135 | 1171 | } |
| 1136 | 1172 | |
| 1137 | 1173 | $max_boards = ceil(count($temp_boards) / 2); |
| 1138 | - if ($max_boards == 1) |
|
| 1139 | - $max_boards = 2; |
|
| 1174 | + if ($max_boards == 1) { |
|
| 1175 | + $max_boards = 2; |
|
| 1176 | + } |
|
| 1140 | 1177 | } |
| 1141 | 1178 | |
| 1142 | 1179 | // Get a list of all the image formats we can select. |
@@ -1159,19 +1196,22 @@ discard block |
||
| 1159 | 1196 | $image_info = getimagesize($settings['default_theme_dir'] . '/images/membericons/' . $value); |
| 1160 | 1197 | |
| 1161 | 1198 | // If this is bigger than 128 in width or 32 in height, skip this one. |
| 1162 | - if ($image_info == false || $image_info[0] > 128 || $image_info[1] > 32) |
|
| 1163 | - continue; |
|
| 1199 | + if ($image_info == false || $image_info[0] > 128 || $image_info[1] > 32) { |
|
| 1200 | + continue; |
|
| 1201 | + } |
|
| 1164 | 1202 | |
| 1165 | 1203 | // Else it's valid. Add it in. |
| 1166 | - else |
|
| 1167 | - $context['possible_icons'][] = $value; |
|
| 1204 | + else { |
|
| 1205 | + $context['possible_icons'][] = $value; |
|
| 1206 | + } |
|
| 1168 | 1207 | } |
| 1169 | 1208 | } |
| 1170 | 1209 | } |
| 1171 | 1210 | |
| 1172 | 1211 | // Insert our JS, if we have possible icons. |
| 1173 | - if (!empty($context['possible_icons'])) |
|
| 1174 | - loadJavaScriptFile('icondropdown.js', array('validate' => true), 'smf_icondropdown'); |
|
| 1212 | + if (!empty($context['possible_icons'])) { |
|
| 1213 | + loadJavaScriptFile('icondropdown.js', array('validate' => true), 'smf_icondropdown'); |
|
| 1214 | + } |
|
| 1175 | 1215 | |
| 1176 | 1216 | loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
| 1177 | 1217 | |
@@ -1193,8 +1233,9 @@ discard block |
||
| 1193 | 1233 | ) |
| 1194 | 1234 | ); |
| 1195 | 1235 | $context['inheritable_groups'] = array(); |
| 1196 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1197 | - $context['inheritable_groups'][$row['id_group']] = $row['group_name']; |
|
| 1236 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1237 | + $context['inheritable_groups'][$row['id_group']] = $row['group_name']; |
|
| 1238 | + } |
|
| 1198 | 1239 | $smcFunc['db_free_result']($request); |
| 1199 | 1240 | |
| 1200 | 1241 | call_integration_hook('integrate_view_membergroup'); |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 3 |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -if (!defined('SMF')) |
|
| 18 | +if (!defined('SMF')) { |
|
| 19 | 19 | die('No direct access...'); |
| 20 | +} |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * Creates a wave file that spells the letters of $word. |
@@ -32,8 +33,9 @@ discard block |
||
| 32 | 33 | global $settings, $user_info; |
| 33 | 34 | |
| 34 | 35 | // Allow max 2 requests per 20 seconds. |
| 35 | - if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2) |
|
| 36 | - die(header('HTTP/1.1 400 Bad Request')); |
|
| 36 | + if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2) { |
|
| 37 | + die(header('HTTP/1.1 400 Bad Request')); |
|
| 38 | + } |
|
| 37 | 39 | cache_put_data('wave_file/' . $user_info['ip'], $ip ? $ip + 1 : 1, 20); |
| 38 | 40 | cache_put_data('wave_file/' . $user_info['ip2'], $ip2 ? $ip2 + 1 : 1, 20); |
| 39 | 41 | |
@@ -41,16 +43,19 @@ discard block |
||
| 41 | 43 | mt_srand(end(unpack('n', md5($word . session_id())))); |
| 42 | 44 | |
| 43 | 45 | // Try to see if there's a sound font in the user's language. |
| 44 | - if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) |
|
| 45 | - $sound_language = $user_info['language']; |
|
| 46 | + if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) { |
|
| 47 | + $sound_language = $user_info['language']; |
|
| 48 | + } |
|
| 46 | 49 | |
| 47 | 50 | // English should be there. |
| 48 | - elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) |
|
| 49 | - $sound_language = 'english'; |
|
| 51 | + elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) { |
|
| 52 | + $sound_language = 'english'; |
|
| 53 | + } |
|
| 50 | 54 | |
| 51 | 55 | // Guess not... |
| 52 | - else |
|
| 53 | - return false; |
|
| 56 | + else { |
|
| 57 | + return false; |
|
| 58 | + } |
|
| 54 | 59 | |
| 55 | 60 | // File names are in lower case so lets make sure that we are only using a lower case string |
| 56 | 61 | $word = strtolower($word); |
@@ -60,21 +65,26 @@ discard block |
||
| 60 | 65 | for ($i = 0; $i < strlen($word); $i++) |
| 61 | 66 | { |
| 62 | 67 | $sound_letter = implode('', file($settings['default_theme_dir'] . '/fonts/sound/' . $word{$i} . '.' . $sound_language . '.wav')); |
| 63 | - if (strpos($sound_letter, 'data') === false) |
|
| 64 | - return false; |
|
| 68 | + if (strpos($sound_letter, 'data') === false) { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 65 | 71 | |
| 66 | 72 | $sound_letter = substr($sound_letter, strpos($sound_letter, 'data') + 8); |
| 67 | 73 | switch ($word{$i} === 's' ? 0 : mt_rand(0, 2)) |
| 68 | 74 | { |
| 69 | 75 | case 0: |
| 70 | - for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) |
|
| 71 | - for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) |
|
| 72 | - $sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF))); |
|
| 76 | + for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) { |
|
| 77 | + for ($k = 0, $m = round(mt_rand(15, 25) / 10); |
|
| 78 | + } |
|
| 79 | + $k < $m; $k++) { |
|
| 80 | + $sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF))); |
|
| 81 | + } |
|
| 73 | 82 | break; |
| 74 | 83 | |
| 75 | 84 | case 1: |
| 76 | - for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) |
|
| 77 | - $sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : ''); |
|
| 85 | + for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) { |
|
| 86 | + $sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : ''); |
|
| 87 | + } |
|
| 78 | 88 | $sound_word .= str_repeat($sound_letter{$n}, 2); |
| 79 | 89 | break; |
| 80 | 90 | |
@@ -82,10 +92,12 @@ discard block |
||
| 82 | 92 | $shift = 0; |
| 83 | 93 | for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) |
| 84 | 94 | { |
| 85 | - if (mt_rand(0, 10) === 0) |
|
| 86 | - $shift += mt_rand(-3, 3); |
|
| 87 | - for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) |
|
| 88 | - $sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF)); |
|
| 95 | + if (mt_rand(0, 10) === 0) { |
|
| 96 | + $shift += mt_rand(-3, 3); |
|
| 97 | + } |
|
| 98 | + for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) { |
|
| 99 | + $sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF)); |
|
| 100 | + } |
|
| 89 | 101 | } |
| 90 | 102 | break; |
| 91 | 103 | |
@@ -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 |
@@ -29,8 +30,9 @@ discard block |
||
| 29 | 30 | |
| 30 | 31 | $supported = function_exists('zend_shm_cache_fetch') || function_exists('output_cache_get'); |
| 31 | 32 | |
| 32 | - if ($test) |
|
| 33 | - return $supported; |
|
| 33 | + if ($test) { |
|
| 34 | + return $supported; |
|
| 35 | + } |
|
| 34 | 36 | return parent::isSupported() && $supported; |
| 35 | 37 | } |
| 36 | 38 | |
@@ -42,10 +44,11 @@ discard block |
||
| 42 | 44 | $key = $this->prefix . strtr($key, ':/', '-_'); |
| 43 | 45 | |
| 44 | 46 | // Zend's pricey stuff. |
| 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); |
|
| 47 | + if (function_exists('zend_shm_cache_fetch')) { |
|
| 48 | + return zend_shm_cache_fetch('SMF::' . $key); |
|
| 49 | + } elseif (function_exists('output_cache_get')) { |
|
| 50 | + return output_cache_get($key, $ttl); |
|
| 51 | + } |
|
| 49 | 52 | } |
| 50 | 53 | |
| 51 | 54 | /** |
@@ -55,10 +58,11 @@ discard block |
||
| 55 | 58 | { |
| 56 | 59 | $key = $this->prefix . strtr($key, ':/', '-_'); |
| 57 | 60 | |
| 58 | - if (function_exists('zend_shm_cache_store')) |
|
| 59 | - return zend_shm_cache_store('SMF::' . $key, $value, $ttl); |
|
| 60 | - elseif (function_exists('output_cache_put')) |
|
| 61 | - return output_cache_put($key, $value); |
|
| 61 | + if (function_exists('zend_shm_cache_store')) { |
|
| 62 | + return zend_shm_cache_store('SMF::' . $key, $value, $ttl); |
|
| 63 | + } elseif (function_exists('output_cache_put')) { |
|
| 64 | + return output_cache_put($key, $value); |
|
| 65 | + } |
|
| 62 | 66 | } |
| 63 | 67 | |
| 64 | 68 | /** |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 3 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('No direct access...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Used for the "custom search index" option |
@@ -54,8 +55,9 @@ discard block |
||
| 54 | 55 | return; |
| 55 | 56 | } |
| 56 | 57 | |
| 57 | - if (empty($modSettings['search_custom_index_config'])) |
|
| 58 | - return; |
|
| 58 | + if (empty($modSettings['search_custom_index_config'])) { |
|
| 59 | + return; |
|
| 60 | + } |
|
| 59 | 61 | |
| 60 | 62 | $this->indexSettings = smf_json_decode($modSettings['search_custom_index_config'], true); |
| 61 | 63 | |
@@ -118,21 +120,23 @@ discard block |
||
| 118 | 120 | |
| 119 | 121 | $subwords = text2words($word, $this->min_word_length, true); |
| 120 | 122 | |
| 121 | - if (empty($modSettings['search_force_index'])) |
|
| 122 | - $wordsSearch['words'][] = $word; |
|
| 123 | + if (empty($modSettings['search_force_index'])) { |
|
| 124 | + $wordsSearch['words'][] = $word; |
|
| 125 | + } |
|
| 123 | 126 | |
| 124 | 127 | // Excluded phrases don't benefit from being split into subwords. |
| 125 | - if (count($subwords) > 1 && $isExcluded) |
|
| 126 | - return; |
|
| 127 | - else |
|
| 128 | + if (count($subwords) > 1 && $isExcluded) { |
|
| 129 | + return; |
|
| 130 | + } else |
|
| 128 | 131 | { |
| 129 | 132 | foreach ($subwords as $subword) |
| 130 | 133 | { |
| 131 | 134 | if ($smcFunc['strlen']($subword) >= $this->min_word_length && !in_array($subword, $this->bannedWords)) |
| 132 | 135 | { |
| 133 | 136 | $wordsSearch['indexed_words'][] = $subword; |
| 134 | - if ($isExcluded) |
|
| 135 | - $wordsExclude[] = $subword; |
|
| 137 | + if ($isExcluded) { |
|
| 138 | + $wordsExclude[] = $subword; |
|
| 139 | + } |
|
| 136 | 140 | } |
| 137 | 141 | } |
| 138 | 142 | } |
@@ -153,8 +157,9 @@ discard block |
||
| 153 | 157 | $query_where = array(); |
| 154 | 158 | $query_params = $search_data['params']; |
| 155 | 159 | |
| 156 | - if ($query_params['id_search']) |
|
| 157 | - $query_select['id_search'] = '{int:id_search}'; |
|
| 160 | + if ($query_params['id_search']) { |
|
| 161 | + $query_select['id_search'] = '{int:id_search}'; |
|
| 162 | + } |
|
| 158 | 163 | |
| 159 | 164 | $count = 0; |
| 160 | 165 | foreach ($words['words'] as $regularWord) |
@@ -163,30 +168,37 @@ discard block |
||
| 163 | 168 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
| 164 | 169 | } |
| 165 | 170 | |
| 166 | - if ($query_params['user_query']) |
|
| 167 | - $query_where[] = '{raw:user_query}'; |
|
| 168 | - if ($query_params['board_query']) |
|
| 169 | - $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 171 | + if ($query_params['user_query']) { |
|
| 172 | + $query_where[] = '{raw:user_query}'; |
|
| 173 | + } |
|
| 174 | + if ($query_params['board_query']) { |
|
| 175 | + $query_where[] = 'm.id_board {raw:board_query}'; |
|
| 176 | + } |
|
| 170 | 177 | |
| 171 | - if ($query_params['topic']) |
|
| 172 | - $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 173 | - if ($query_params['min_msg_id']) |
|
| 174 | - $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 175 | - if ($query_params['max_msg_id']) |
|
| 176 | - $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 178 | + if ($query_params['topic']) { |
|
| 179 | + $query_where[] = 'm.id_topic = {int:topic}'; |
|
| 180 | + } |
|
| 181 | + if ($query_params['min_msg_id']) { |
|
| 182 | + $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
| 183 | + } |
|
| 184 | + if ($query_params['max_msg_id']) { |
|
| 185 | + $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
| 186 | + } |
|
| 177 | 187 | |
| 178 | 188 | $count = 0; |
| 179 | - if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
|
| 180 | - foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 189 | + if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) { |
|
| 190 | + foreach ($query_params['excluded_phrases'] as $phrase) |
|
| 181 | 191 | { |
| 182 | 192 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_phrase_' . $count . '}'; |
| 193 | + } |
|
| 183 | 194 | $query_params['exclude_subject_phrase_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($phrase, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $phrase), '\\\'') . '[[:>:]]'; |
| 184 | 195 | } |
| 185 | 196 | $count = 0; |
| 186 | - if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
|
| 187 | - foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 197 | + if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) { |
|
| 198 | + foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
| 188 | 199 | { |
| 189 | 200 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_words_' . $count . '}'; |
| 201 | + } |
|
| 190 | 202 | $query_params['exclude_subject_words_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($excludedWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $excludedWord), '\\\'') . '[[:>:]]'; |
| 191 | 203 | } |
| 192 | 204 | |
@@ -199,8 +211,7 @@ discard block |
||
| 199 | 211 | { |
| 200 | 212 | $query_left_join[] = '{db_prefix}log_search_words AS lsw' . $numTables . ' ON (lsw' . $numTables . '.id_word = ' . $indexedWord . ' AND lsw' . $numTables . '.id_msg = m.id_msg)'; |
| 201 | 213 | $query_where[] = '(lsw' . $numTables . '.id_word IS NULL)'; |
| 202 | - } |
|
| 203 | - else |
|
| 214 | + } else |
|
| 204 | 215 | { |
| 205 | 216 | $query_inner_join[] = '{db_prefix}log_search_words AS lsw' . $numTables . ' ON (lsw' . $numTables . '.id_msg = ' . ($prev_join === 0 ? 'm' : 'lsw' . $prev_join) . '.id_msg)'; |
| 206 | 217 | $query_where[] = 'lsw' . $numTables . '.id_word = ' . $indexedWord; |
@@ -236,16 +247,18 @@ discard block |
||
| 236 | 247 | $customIndexSettings = smf_json_decode($modSettings['search_custom_index_config'], true); |
| 237 | 248 | |
| 238 | 249 | $inserts = array(); |
| 239 | - foreach (text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true) as $word) |
|
| 240 | - $inserts[] = array($word, $msgOptions['id']); |
|
| 250 | + foreach (text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true) as $word) { |
|
| 251 | + $inserts[] = array($word, $msgOptions['id']); |
|
| 252 | + } |
|
| 241 | 253 | |
| 242 | - if (!empty($inserts)) |
|
| 243 | - $smcFunc['db_insert']('ignore', |
|
| 254 | + if (!empty($inserts)) { |
|
| 255 | + $smcFunc['db_insert']('ignore', |
|
| 244 | 256 | '{db_prefix}log_search_words', |
| 245 | 257 | array('id_word' => 'int', 'id_msg' => 'int'), |
| 246 | 258 | $inserts, |
| 247 | 259 | array('id_word', 'id_msg') |
| 248 | 260 | ); |
| 261 | + } |
|
| 249 | 262 | } |
| 250 | 263 | |
| 251 | 264 | /** |
@@ -288,8 +301,9 @@ discard block |
||
| 288 | 301 | if (!empty($inserted_words)) |
| 289 | 302 | { |
| 290 | 303 | $inserts = array(); |
| 291 | - foreach ($inserted_words as $word) |
|
| 292 | - $inserts[] = array($word, $msgOptions['id']); |
|
| 304 | + foreach ($inserted_words as $word) { |
|
| 305 | + $inserts[] = array($word, $msgOptions['id']); |
|
| 306 | + } |
|
| 293 | 307 | $smcFunc['db_insert']('insert', |
| 294 | 308 | '{db_prefix}log_search_words', |
| 295 | 309 | array('id_word' => 'string', 'id_msg' => 'int'), |