@@ -1112,7 +1112,7 @@ |
||
| 1112 | 1112 | $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
| 1113 | 1113 | |
| 1114 | 1114 | // Need to sort the tags by name length. |
| 1115 | - uksort($valid_tags, function ($a, $b) { |
|
| 1115 | + uksort($valid_tags, function($a, $b) { |
|
| 1116 | 1116 | return strlen($a) < strlen($b) ? 1 : -1; |
| 1117 | 1117 | }); |
| 1118 | 1118 | |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 4 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * As of SMF 2.1, this is unused. But it is available if any mod wants to use it. |
@@ -30,8 +31,9 @@ discard block |
||
| 30 | 31 | { |
| 31 | 32 | global $modSettings; |
| 32 | 33 | |
| 33 | - if (!$compat_mode) |
|
| 34 | - return $text; |
|
| 34 | + if (!$compat_mode) { |
|
| 35 | + return $text; |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | // Turn line breaks back into br's. |
| 37 | 39 | $text = strtr($text, array("\r" => '', "\n" => '<br>')); |
@@ -48,8 +50,9 @@ discard block |
||
| 48 | 50 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
| 49 | 51 | { |
| 50 | 52 | // Value of 2 means we're inside the tag. |
| 51 | - if ($i % 4 == 2) |
|
| 52 | - $parts[$i] = strtr($parts[$i], array('[' => '[', ']' => ']', "'" => "'")); |
|
| 53 | + if ($i % 4 == 2) { |
|
| 54 | + $parts[$i] = strtr($parts[$i], array('[' => '[', ']' => ']', "'" => "'")); |
|
| 55 | + } |
|
| 53 | 56 | } |
| 54 | 57 | // Put our humpty dumpty message back together again. |
| 55 | 58 | $text = implode('', $parts); |
@@ -104,8 +107,9 @@ discard block |
||
| 104 | 107 | $text = preg_replace('~</p>\s*(?!<)~i', '</p><br>', $text); |
| 105 | 108 | |
| 106 | 109 | // Safari/webkit wraps lines in Wysiwyg in <div>'s. |
| 107 | - if (isBrowser('webkit')) |
|
| 108 | - $text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text); |
|
| 110 | + if (isBrowser('webkit')) { |
|
| 111 | + $text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text); |
|
| 112 | + } |
|
| 109 | 113 | |
| 110 | 114 | // If there's a trailing break get rid of it - Firefox tends to add one. |
| 111 | 115 | $text = preg_replace('~<br\s?/?' . '>$~i', '', $text); |
@@ -120,8 +124,9 @@ discard block |
||
| 120 | 124 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
| 121 | 125 | { |
| 122 | 126 | // Value of 2 means we're inside the tag. |
| 123 | - if ($i % 4 == 2) |
|
| 124 | - $parts[$i] = strip_tags($parts[$i]); |
|
| 127 | + if ($i % 4 == 2) { |
|
| 128 | + $parts[$i] = strip_tags($parts[$i]); |
|
| 129 | + } |
|
| 125 | 130 | } |
| 126 | 131 | |
| 127 | 132 | $text = strtr(implode('', $parts), array('#smf_br_spec_grudge_cool!#' => '<br>')); |
@@ -147,18 +152,19 @@ discard block |
||
| 147 | 152 | { |
| 148 | 153 | $found = array_search($file, $smileysto); |
| 149 | 154 | // Note the weirdness here is to stop double spaces between smileys. |
| 150 | - if ($found) |
|
| 151 | - $matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#'; |
|
| 152 | - else |
|
| 153 | - $matches[1][$k] = ''; |
|
| 155 | + if ($found) { |
|
| 156 | + $matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#'; |
|
| 157 | + } else { |
|
| 158 | + $matches[1][$k] = ''; |
|
| 159 | + } |
|
| 154 | 160 | } |
| 155 | - } |
|
| 156 | - else |
|
| 161 | + } else |
|
| 157 | 162 | { |
| 158 | 163 | // Load all the smileys. |
| 159 | 164 | $names = array(); |
| 160 | - foreach ($matches[1] as $file) |
|
| 161 | - $names[] = $file; |
|
| 165 | + foreach ($matches[1] as $file) { |
|
| 166 | + $names[] = $file; |
|
| 167 | + } |
|
| 162 | 168 | $names = array_unique($names); |
| 163 | 169 | |
| 164 | 170 | if (!empty($names)) |
@@ -172,13 +178,15 @@ discard block |
||
| 172 | 178 | ) |
| 173 | 179 | ); |
| 174 | 180 | $mappings = array(); |
| 175 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 176 | - $mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']); |
|
| 181 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 182 | + $mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']); |
|
| 183 | + } |
|
| 177 | 184 | $smcFunc['db_free_result']($request); |
| 178 | 185 | |
| 179 | - foreach ($matches[1] as $k => $file) |
|
| 180 | - if (isset($mappings[$file])) |
|
| 186 | + foreach ($matches[1] as $k => $file) { |
|
| 187 | + if (isset($mappings[$file])) |
|
| 181 | 188 | $matches[1][$k] = '-[]-smf_smily_start#|#' . $mappings[$file] . '-[]-smf_smily_end#|#'; |
| 189 | + } |
|
| 182 | 190 | } |
| 183 | 191 | } |
| 184 | 192 | |
@@ -190,8 +198,9 @@ discard block |
||
| 190 | 198 | } |
| 191 | 199 | |
| 192 | 200 | // Only try to buy more time if the client didn't quit. |
| 193 | - if (connection_aborted() && $context['server']['is_apache']) |
|
| 194 | - @apache_reset_timeout(); |
|
| 201 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
| 202 | + @apache_reset_timeout(); |
|
| 203 | + } |
|
| 195 | 204 | |
| 196 | 205 | $parts = preg_split('~(<[A-Za-z]+\s*[^<>]*?style="?[^<>"]+"?[^<>]*?(?:/?)>|</[A-Za-z]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE); |
| 197 | 206 | $replacement = ''; |
@@ -202,9 +211,9 @@ discard block |
||
| 202 | 211 | if (preg_match('~(<([A-Za-z]+)\s*[^<>]*?)style="?([^<>"]+)"?([^<>]*?(/?)>)~', $part, $matches) === 1) |
| 203 | 212 | { |
| 204 | 213 | // If it's being closed instantly, we can't deal with it...yet. |
| 205 | - if ($matches[5] === '/') |
|
| 206 | - continue; |
|
| 207 | - else |
|
| 214 | + if ($matches[5] === '/') { |
|
| 215 | + continue; |
|
| 216 | + } else |
|
| 208 | 217 | { |
| 209 | 218 | // Get an array of styles that apply to this element. (The strtr is there to combat HTML generated by Word.) |
| 210 | 219 | $styles = explode(';', strtr($matches[3], array('"' => ''))); |
@@ -220,8 +229,9 @@ discard block |
||
| 220 | 229 | $clean_type_value_pair = strtolower(strtr(trim($type_value_pair), '=', ':')); |
| 221 | 230 | |
| 222 | 231 | // Something like 'font-weight: bold' is expected here. |
| 223 | - if (strpos($clean_type_value_pair, ':') === false) |
|
| 224 | - continue; |
|
| 232 | + if (strpos($clean_type_value_pair, ':') === false) { |
|
| 233 | + continue; |
|
| 234 | + } |
|
| 225 | 235 | |
| 226 | 236 | // Capture the elements of a single style item (e.g. 'font-weight' and 'bold'). |
| 227 | 237 | list ($style_type, $style_value) = explode(':', $type_value_pair); |
@@ -243,8 +253,7 @@ discard block |
||
| 243 | 253 | { |
| 244 | 254 | $curCloseTags .= '[/u]'; |
| 245 | 255 | $replacement .= '[u]'; |
| 246 | - } |
|
| 247 | - elseif ($style_value == 'line-through') |
|
| 256 | + } elseif ($style_value == 'line-through') |
|
| 248 | 257 | { |
| 249 | 258 | $curCloseTags .= '[/s]'; |
| 250 | 259 | $replacement .= '[s]'; |
@@ -256,13 +265,11 @@ discard block |
||
| 256 | 265 | { |
| 257 | 266 | $curCloseTags .= '[/left]'; |
| 258 | 267 | $replacement .= '[left]'; |
| 259 | - } |
|
| 260 | - elseif ($style_value == 'center') |
|
| 268 | + } elseif ($style_value == 'center') |
|
| 261 | 269 | { |
| 262 | 270 | $curCloseTags .= '[/center]'; |
| 263 | 271 | $replacement .= '[center]'; |
| 264 | - } |
|
| 265 | - elseif ($style_value == 'right') |
|
| 272 | + } elseif ($style_value == 'right') |
|
| 266 | 273 | { |
| 267 | 274 | $curCloseTags .= '[/right]'; |
| 268 | 275 | $replacement .= '[right]'; |
@@ -284,8 +291,9 @@ discard block |
||
| 284 | 291 | |
| 285 | 292 | case 'font-size': |
| 286 | 293 | // Sometimes people put decimals where decimals should not be. |
| 287 | - if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) |
|
| 288 | - $style_value = $dec_matches[1] . $dec_matches[2]; |
|
| 294 | + if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) { |
|
| 295 | + $style_value = $dec_matches[1] . $dec_matches[2]; |
|
| 296 | + } |
|
| 289 | 297 | |
| 290 | 298 | $curCloseTags .= '[/size]'; |
| 291 | 299 | $replacement .= '[size=' . $style_value . ']'; |
@@ -293,8 +301,9 @@ discard block |
||
| 293 | 301 | |
| 294 | 302 | case 'font-family': |
| 295 | 303 | // Only get the first freaking font if there's a list! |
| 296 | - if (strpos($style_value, ',') !== false) |
|
| 297 | - $style_value = substr($style_value, 0, strpos($style_value, ',')); |
|
| 304 | + if (strpos($style_value, ',') !== false) { |
|
| 305 | + $style_value = substr($style_value, 0, strpos($style_value, ',')); |
|
| 306 | + } |
|
| 298 | 307 | |
| 299 | 308 | $curCloseTags .= '[/font]'; |
| 300 | 309 | $replacement .= '[font=' . strtr($style_value, array("'" => '')) . ']'; |
@@ -303,13 +312,15 @@ discard block |
||
| 303 | 312 | // This is a hack for images with dimensions embedded. |
| 304 | 313 | case 'width': |
| 305 | 314 | case 'height': |
| 306 | - if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) |
|
| 307 | - $extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"'; |
|
| 315 | + if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) { |
|
| 316 | + $extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"'; |
|
| 317 | + } |
|
| 308 | 318 | break; |
| 309 | 319 | |
| 310 | 320 | case 'list-style-type': |
| 311 | - if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) |
|
| 312 | - $extra_attr .= ' listtype="' . $listType[0] . '"'; |
|
| 321 | + if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) { |
|
| 322 | + $extra_attr .= ' listtype="' . $listType[0] . '"'; |
|
| 323 | + } |
|
| 313 | 324 | break; |
| 314 | 325 | } |
| 315 | 326 | } |
@@ -322,18 +333,17 @@ discard block |
||
| 322 | 333 | } |
| 323 | 334 | |
| 324 | 335 | // If there's something that still needs closing, push it to the stack. |
| 325 | - if (!empty($curCloseTags)) |
|
| 326 | - array_push($stack, array( |
|
| 336 | + if (!empty($curCloseTags)) { |
|
| 337 | + array_push($stack, array( |
|
| 327 | 338 | 'element' => strtolower($curElement), |
| 328 | 339 | 'closeTags' => $curCloseTags |
| 329 | 340 | ) |
| 330 | 341 | ); |
| 331 | - elseif (!empty($extra_attr)) |
|
| 332 | - $replacement .= $precedingStyle . $extra_attr . $afterStyle; |
|
| 342 | + } elseif (!empty($extra_attr)) { |
|
| 343 | + $replacement .= $precedingStyle . $extra_attr . $afterStyle; |
|
| 344 | + } |
|
| 333 | 345 | } |
| 334 | - } |
|
| 335 | - |
|
| 336 | - elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1) |
|
| 346 | + } elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1) |
|
| 337 | 347 | { |
| 338 | 348 | // Is this the element that we've been waiting for to be closed? |
| 339 | 349 | if (!empty($stack) && strtolower($matches[1]) === $stack[count($stack) - 1]['element']) |
@@ -343,28 +353,32 @@ discard block |
||
| 343 | 353 | } |
| 344 | 354 | |
| 345 | 355 | // Must've been something else. |
| 346 | - else |
|
| 347 | - $replacement .= $part; |
|
| 356 | + else { |
|
| 357 | + $replacement .= $part; |
|
| 358 | + } |
|
| 348 | 359 | } |
| 349 | 360 | // In all other cases, just add the part to the replacement. |
| 350 | - else |
|
| 351 | - $replacement .= $part; |
|
| 361 | + else { |
|
| 362 | + $replacement .= $part; |
|
| 363 | + } |
|
| 352 | 364 | } |
| 353 | 365 | |
| 354 | 366 | // Now put back the replacement in the text. |
| 355 | 367 | $text = $replacement; |
| 356 | 368 | |
| 357 | 369 | // We are not finished yet, request more time. |
| 358 | - if (connection_aborted() && $context['server']['is_apache']) |
|
| 359 | - @apache_reset_timeout(); |
|
| 370 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
| 371 | + @apache_reset_timeout(); |
|
| 372 | + } |
|
| 360 | 373 | |
| 361 | 374 | // Let's pull out any legacy alignments. |
| 362 | 375 | while (preg_match('~<([A-Za-z]+)\s+[^<>]*?(align="*(left|center|right)"*)[^<>]*?(/?)>~i', $text, $matches) === 1) |
| 363 | 376 | { |
| 364 | 377 | // Find the position in the text of this tag over again. |
| 365 | 378 | $start_pos = strpos($text, $matches[0]); |
| 366 | - if ($start_pos === false) |
|
| 367 | - break; |
|
| 379 | + if ($start_pos === false) { |
|
| 380 | + break; |
|
| 381 | + } |
|
| 368 | 382 | |
| 369 | 383 | // End tag? |
| 370 | 384 | if ($matches[4] != '/' && strpos($text, '</' . $matches[1] . '>', $start_pos) !== false) |
@@ -378,8 +392,7 @@ discard block |
||
| 378 | 392 | |
| 379 | 393 | // Put the tags back into the body. |
| 380 | 394 | $text = substr($text, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($text, $end_pos); |
| 381 | - } |
|
| 382 | - else |
|
| 395 | + } else |
|
| 383 | 396 | { |
| 384 | 397 | // Just get rid of this evil tag. |
| 385 | 398 | $text = substr($text, 0, $start_pos) . substr($text, $start_pos + strlen($matches[0])); |
@@ -392,8 +405,9 @@ discard block |
||
| 392 | 405 | // Find the position of this again. |
| 393 | 406 | $start_pos = strpos($text, $matches[0]); |
| 394 | 407 | $end_pos = false; |
| 395 | - if ($start_pos === false) |
|
| 396 | - break; |
|
| 408 | + if ($start_pos === false) { |
|
| 409 | + break; |
|
| 410 | + } |
|
| 397 | 411 | |
| 398 | 412 | // This must have an end tag - and we must find the right one. |
| 399 | 413 | $lower_text = strtolower($text); |
@@ -426,8 +440,9 @@ discard block |
||
| 426 | 440 | break; |
| 427 | 441 | } |
| 428 | 442 | } |
| 429 | - if ($end_pos === false) |
|
| 430 | - break; |
|
| 443 | + if ($end_pos === false) { |
|
| 444 | + break; |
|
| 445 | + } |
|
| 431 | 446 | |
| 432 | 447 | // Now work out what the attributes are. |
| 433 | 448 | $attribs = fetchTagAttributes($matches[1]); |
@@ -441,11 +456,11 @@ discard block |
||
| 441 | 456 | $v = (int) trim($v); |
| 442 | 457 | $v = empty($v) ? 1 : $v; |
| 443 | 458 | $tags[] = array('[size=' . $sizes_equivalence[$v] . ']', '[/size]'); |
| 459 | + } elseif ($s == 'face') { |
|
| 460 | + $tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]'); |
|
| 461 | + } elseif ($s == 'color') { |
|
| 462 | + $tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]'); |
|
| 444 | 463 | } |
| 445 | - elseif ($s == 'face') |
|
| 446 | - $tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]'); |
|
| 447 | - elseif ($s == 'color') |
|
| 448 | - $tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]'); |
|
| 449 | 464 | } |
| 450 | 465 | |
| 451 | 466 | // As before add in our tags. |
@@ -453,8 +468,9 @@ discard block |
||
| 453 | 468 | foreach ($tags as $tag) |
| 454 | 469 | { |
| 455 | 470 | $before .= $tag[0]; |
| 456 | - if (isset($tag[1])) |
|
| 457 | - $after = $tag[1] . $after; |
|
| 471 | + if (isset($tag[1])) { |
|
| 472 | + $after = $tag[1] . $after; |
|
| 473 | + } |
|
| 458 | 474 | } |
| 459 | 475 | |
| 460 | 476 | // Remove the tag so it's never checked again. |
@@ -465,8 +481,9 @@ discard block |
||
| 465 | 481 | } |
| 466 | 482 | |
| 467 | 483 | // Almost there, just a little more time. |
| 468 | - if (connection_aborted() && $context['server']['is_apache']) |
|
| 469 | - @apache_reset_timeout(); |
|
| 484 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
| 485 | + @apache_reset_timeout(); |
|
| 486 | + } |
|
| 470 | 487 | |
| 471 | 488 | if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $text, null, PREG_SPLIT_DELIM_CAPTURE)) > 1) |
| 472 | 489 | { |
@@ -522,12 +539,13 @@ discard block |
||
| 522 | 539 | { |
| 523 | 540 | $inList = true; |
| 524 | 541 | |
| 525 | - if ($tag === 'ol') |
|
| 526 | - $listType = 'decimal'; |
|
| 527 | - elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) |
|
| 528 | - $listType = $listTypeMapping[$match[1]]; |
|
| 529 | - else |
|
| 530 | - $listType = null; |
|
| 542 | + if ($tag === 'ol') { |
|
| 543 | + $listType = 'decimal'; |
|
| 544 | + } elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) { |
|
| 545 | + $listType = $listTypeMapping[$match[1]]; |
|
| 546 | + } else { |
|
| 547 | + $listType = null; |
|
| 548 | + } |
|
| 531 | 549 | |
| 532 | 550 | $listDepth++; |
| 533 | 551 | |
@@ -591,9 +609,7 @@ discard block |
||
| 591 | 609 | $parts[$i + 1] = ''; |
| 592 | 610 | $parts[$i + 2] = str_repeat("\t", $listDepth) . '[/list]'; |
| 593 | 611 | $parts[$i + 3] = ''; |
| 594 | - } |
|
| 595 | - |
|
| 596 | - else |
|
| 612 | + } else |
|
| 597 | 613 | { |
| 598 | 614 | // We're in a list item. |
| 599 | 615 | if ($listDepth > 0) |
@@ -630,9 +646,7 @@ discard block |
||
| 630 | 646 | $parts[$i + 1] = ''; |
| 631 | 647 | $parts[$i + 2] = ''; |
| 632 | 648 | $parts[$i + 3] = ''; |
| 633 | - } |
|
| 634 | - |
|
| 635 | - else |
|
| 649 | + } else |
|
| 636 | 650 | { |
| 637 | 651 | // Remove the trailing breaks from the list item. |
| 638 | 652 | $parts[$i] = preg_replace('~\s*<br\s*' . '/?' . '>\s*$~', '', $parts[$i]); |
@@ -670,8 +684,9 @@ discard block |
||
| 670 | 684 | $text .= str_repeat("\t", $listDepth) . '[/list]'; |
| 671 | 685 | } |
| 672 | 686 | |
| 673 | - for ($i = $listDepth; $i > 0; $i--) |
|
| 674 | - $text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]'; |
|
| 687 | + for ($i = $listDepth; $i > 0; $i--) { |
|
| 688 | + $text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]'; |
|
| 689 | + } |
|
| 675 | 690 | } |
| 676 | 691 | |
| 677 | 692 | // I love my own image... |
@@ -679,8 +694,9 @@ discard block |
||
| 679 | 694 | { |
| 680 | 695 | // Find the position of the image. |
| 681 | 696 | $start_pos = strpos($text, $matches[0]); |
| 682 | - if ($start_pos === false) |
|
| 683 | - break; |
|
| 697 | + if ($start_pos === false) { |
|
| 698 | + break; |
|
| 699 | + } |
|
| 684 | 700 | $end_pos = $start_pos + strlen($matches[0]); |
| 685 | 701 | |
| 686 | 702 | $params = ''; |
@@ -689,12 +705,13 @@ discard block |
||
| 689 | 705 | $attrs = fetchTagAttributes($matches[1]); |
| 690 | 706 | foreach ($attrs as $attrib => $value) |
| 691 | 707 | { |
| 692 | - if (in_array($attrib, array('width', 'height'))) |
|
| 693 | - $params .= ' ' . $attrib . '=' . (int) $value; |
|
| 694 | - elseif ($attrib == 'alt' && trim($value) != '') |
|
| 695 | - $params .= ' alt=' . trim($value); |
|
| 696 | - elseif ($attrib == 'src') |
|
| 697 | - $src = trim($value); |
|
| 708 | + if (in_array($attrib, array('width', 'height'))) { |
|
| 709 | + $params .= ' ' . $attrib . '=' . (int) $value; |
|
| 710 | + } elseif ($attrib == 'alt' && trim($value) != '') { |
|
| 711 | + $params .= ' alt=' . trim($value); |
|
| 712 | + } elseif ($attrib == 'src') { |
|
| 713 | + $src = trim($value); |
|
| 714 | + } |
|
| 698 | 715 | } |
| 699 | 716 | |
| 700 | 717 | $tag = ''; |
@@ -705,10 +722,11 @@ discard block |
||
| 705 | 722 | { |
| 706 | 723 | $baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']); |
| 707 | 724 | |
| 708 | - if (substr($src, 0, 1) === '/') |
|
| 709 | - $src = $baseURL . $src; |
|
| 710 | - else |
|
| 711 | - $src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src; |
|
| 725 | + if (substr($src, 0, 1) === '/') { |
|
| 726 | + $src = $baseURL . $src; |
|
| 727 | + } else { |
|
| 728 | + $src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src; |
|
| 729 | + } |
|
| 712 | 730 | } |
| 713 | 731 | |
| 714 | 732 | $tag = '[img' . $params . ']' . $src . '[/img]'; |
@@ -886,20 +904,23 @@ discard block |
||
| 886 | 904 | }, |
| 887 | 905 | ); |
| 888 | 906 | |
| 889 | - foreach ($tags as $tag => $replace) |
|
| 890 | - $text = preg_replace_callback($tag, $replace, $text); |
|
| 907 | + foreach ($tags as $tag => $replace) { |
|
| 908 | + $text = preg_replace_callback($tag, $replace, $text); |
|
| 909 | + } |
|
| 891 | 910 | |
| 892 | 911 | // Please give us just a little more time. |
| 893 | - if (connection_aborted() && $context['server']['is_apache']) |
|
| 894 | - @apache_reset_timeout(); |
|
| 912 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
| 913 | + @apache_reset_timeout(); |
|
| 914 | + } |
|
| 895 | 915 | |
| 896 | 916 | // What about URL's - the pain in the ass of the tag world. |
| 897 | 917 | while (preg_match('~<a\s+([^<>]*)>([^<>]*)</a>~i', $text, $matches) === 1) |
| 898 | 918 | { |
| 899 | 919 | // Find the position of the URL. |
| 900 | 920 | $start_pos = strpos($text, $matches[0]); |
| 901 | - if ($start_pos === false) |
|
| 902 | - break; |
|
| 921 | + if ($start_pos === false) { |
|
| 922 | + break; |
|
| 923 | + } |
|
| 903 | 924 | $end_pos = $start_pos + strlen($matches[0]); |
| 904 | 925 | |
| 905 | 926 | $tag_type = 'url'; |
@@ -913,8 +934,9 @@ discard block |
||
| 913 | 934 | $href = trim($value); |
| 914 | 935 | |
| 915 | 936 | // Are we dealing with an FTP link? |
| 916 | - if (preg_match('~^ftps?://~', $href) === 1) |
|
| 917 | - $tag_type = 'ftp'; |
|
| 937 | + if (preg_match('~^ftps?://~', $href) === 1) { |
|
| 938 | + $tag_type = 'ftp'; |
|
| 939 | + } |
|
| 918 | 940 | |
| 919 | 941 | // Or is this a link to an email address? |
| 920 | 942 | elseif (substr($href, 0, 7) == 'mailto:') |
@@ -928,28 +950,31 @@ discard block |
||
| 928 | 950 | { |
| 929 | 951 | $baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']); |
| 930 | 952 | |
| 931 | - if (substr($href, 0, 1) === '/') |
|
| 932 | - $href = $baseURL . $href; |
|
| 933 | - else |
|
| 934 | - $href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href; |
|
| 953 | + if (substr($href, 0, 1) === '/') { |
|
| 954 | + $href = $baseURL . $href; |
|
| 955 | + } else { |
|
| 956 | + $href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href; |
|
| 957 | + } |
|
| 935 | 958 | } |
| 936 | 959 | } |
| 937 | 960 | |
| 938 | 961 | // External URL? |
| 939 | 962 | if ($attrib == 'target' && $tag_type == 'url') |
| 940 | 963 | { |
| 941 | - if (trim($value) == '_blank') |
|
| 942 | - $tag_type == 'iurl'; |
|
| 964 | + if (trim($value) == '_blank') { |
|
| 965 | + $tag_type == 'iurl'; |
|
| 966 | + } |
|
| 943 | 967 | } |
| 944 | 968 | } |
| 945 | 969 | |
| 946 | 970 | $tag = ''; |
| 947 | 971 | if ($href != '') |
| 948 | 972 | { |
| 949 | - if ($matches[2] == $href) |
|
| 950 | - $tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']'; |
|
| 951 | - else |
|
| 952 | - $tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']'; |
|
| 973 | + if ($matches[2] == $href) { |
|
| 974 | + $tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']'; |
|
| 975 | + } else { |
|
| 976 | + $tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']'; |
|
| 977 | + } |
|
| 953 | 978 | } |
| 954 | 979 | |
| 955 | 980 | // Replace the tag |
@@ -985,17 +1010,18 @@ discard block |
||
| 985 | 1010 | // We're either moving from the key to the attribute or we're in a string and this is fine. |
| 986 | 1011 | if ($text[$i] == '=') |
| 987 | 1012 | { |
| 988 | - if ($tag_state == 0) |
|
| 989 | - $tag_state = 1; |
|
| 990 | - elseif ($tag_state == 2) |
|
| 991 | - $value .= '='; |
|
| 1013 | + if ($tag_state == 0) { |
|
| 1014 | + $tag_state = 1; |
|
| 1015 | + } elseif ($tag_state == 2) { |
|
| 1016 | + $value .= '='; |
|
| 1017 | + } |
|
| 992 | 1018 | } |
| 993 | 1019 | // A space is either moving from an attribute back to a potential key or in a string is fine. |
| 994 | 1020 | elseif ($text[$i] == ' ') |
| 995 | 1021 | { |
| 996 | - if ($tag_state == 2) |
|
| 997 | - $value .= ' '; |
|
| 998 | - elseif ($tag_state == 1) |
|
| 1022 | + if ($tag_state == 2) { |
|
| 1023 | + $value .= ' '; |
|
| 1024 | + } elseif ($tag_state == 1) |
|
| 999 | 1025 | { |
| 1000 | 1026 | $attribs[$key] = $value; |
| 1001 | 1027 | $key = $value = ''; |
@@ -1006,24 +1032,27 @@ discard block |
||
| 1006 | 1032 | elseif ($text[$i] == '"') |
| 1007 | 1033 | { |
| 1008 | 1034 | // Must be either going into or out of a string. |
| 1009 | - if ($tag_state == 1) |
|
| 1010 | - $tag_state = 2; |
|
| 1011 | - else |
|
| 1012 | - $tag_state = 1; |
|
| 1035 | + if ($tag_state == 1) { |
|
| 1036 | + $tag_state = 2; |
|
| 1037 | + } else { |
|
| 1038 | + $tag_state = 1; |
|
| 1039 | + } |
|
| 1013 | 1040 | } |
| 1014 | 1041 | // Otherwise it's fine. |
| 1015 | 1042 | else |
| 1016 | 1043 | { |
| 1017 | - if ($tag_state == 0) |
|
| 1018 | - $key .= $text[$i]; |
|
| 1019 | - else |
|
| 1020 | - $value .= $text[$i]; |
|
| 1044 | + if ($tag_state == 0) { |
|
| 1045 | + $key .= $text[$i]; |
|
| 1046 | + } else { |
|
| 1047 | + $value .= $text[$i]; |
|
| 1048 | + } |
|
| 1021 | 1049 | } |
| 1022 | 1050 | } |
| 1023 | 1051 | |
| 1024 | 1052 | // Anything left? |
| 1025 | - if ($key != '' && $value != '') |
|
| 1026 | - $attribs[$key] = $value; |
|
| 1053 | + if ($key != '' && $value != '') { |
|
| 1054 | + $attribs[$key] = $value; |
|
| 1055 | + } |
|
| 1027 | 1056 | |
| 1028 | 1057 | return $attribs; |
| 1029 | 1058 | } |
@@ -1039,8 +1068,9 @@ discard block |
||
| 1039 | 1068 | global $modSettings; |
| 1040 | 1069 | |
| 1041 | 1070 | // Don't care about the texts that are too short. |
| 1042 | - if (strlen($text) < 3) |
|
| 1043 | - return $text; |
|
| 1071 | + if (strlen($text) < 3) { |
|
| 1072 | + return $text; |
|
| 1073 | + } |
|
| 1044 | 1074 | |
| 1045 | 1075 | // A list of tags that's disabled by the admin. |
| 1046 | 1076 | $disabled = empty($modSettings['disabledBBC']) ? array() : array_flip(explode(',', strtolower($modSettings['disabledBBC']))); |
@@ -1051,10 +1081,12 @@ discard block |
||
| 1051 | 1081 | $self_closing_tags = array(); |
| 1052 | 1082 | foreach ($all_tags as $tag) |
| 1053 | 1083 | { |
| 1054 | - if (!isset($disabled[$tag['tag']])) |
|
| 1055 | - $valid_tags[$tag['tag']] = !empty($tag['block_level']); |
|
| 1056 | - if (isset($tag['type']) && $tag['type'] == 'closed') |
|
| 1057 | - $self_closing_tags[] = $tag['tag']; |
|
| 1084 | + if (!isset($disabled[$tag['tag']])) { |
|
| 1085 | + $valid_tags[$tag['tag']] = !empty($tag['block_level']); |
|
| 1086 | + } |
|
| 1087 | + if (isset($tag['type']) && $tag['type'] == 'closed') { |
|
| 1088 | + $self_closing_tags[] = $tag['tag']; |
|
| 1089 | + } |
|
| 1058 | 1090 | } |
| 1059 | 1091 | |
| 1060 | 1092 | // Right - we're going to start by going through the whole lot to make sure we don't have align stuff crossed as this happens load and is stupid! |
@@ -1081,16 +1113,19 @@ discard block |
||
| 1081 | 1113 | $tagName = substr($match, $isClosingTag ? 2 : 1, -1); |
| 1082 | 1114 | |
| 1083 | 1115 | // We're closing the exact same tag that we opened. |
| 1084 | - if ($isClosingTag && $insideTag === $tagName) |
|
| 1085 | - $insideTag = null; |
|
| 1116 | + if ($isClosingTag && $insideTag === $tagName) { |
|
| 1117 | + $insideTag = null; |
|
| 1118 | + } |
|
| 1086 | 1119 | |
| 1087 | 1120 | // We're opening a tag and we're not yet inside one either |
| 1088 | - elseif (!$isClosingTag && $insideTag === null) |
|
| 1089 | - $insideTag = $tagName; |
|
| 1121 | + elseif (!$isClosingTag && $insideTag === null) { |
|
| 1122 | + $insideTag = $tagName; |
|
| 1123 | + } |
|
| 1090 | 1124 | |
| 1091 | 1125 | // In all other cases, this tag must be invalid |
| 1092 | - else |
|
| 1093 | - unset($matches[$i]); |
|
| 1126 | + else { |
|
| 1127 | + unset($matches[$i]); |
|
| 1128 | + } |
|
| 1094 | 1129 | } |
| 1095 | 1130 | |
| 1096 | 1131 | // The next one is gonna be the other one. |
@@ -1098,8 +1133,9 @@ discard block |
||
| 1098 | 1133 | } |
| 1099 | 1134 | |
| 1100 | 1135 | // We're still inside a tag and had no chance for closure? |
| 1101 | - if ($insideTag !== null) |
|
| 1102 | - $matches[] = '[/' . $insideTag . ']'; |
|
| 1136 | + if ($insideTag !== null) { |
|
| 1137 | + $matches[] = '[/' . $insideTag . ']'; |
|
| 1138 | + } |
|
| 1103 | 1139 | |
| 1104 | 1140 | // And a complete text string again. |
| 1105 | 1141 | $text = implode('', $matches); |
@@ -1108,8 +1144,9 @@ discard block |
||
| 1108 | 1144 | // Quickly remove any tags which are back to back. |
| 1109 | 1145 | $backToBackPattern = '~\\[(' . implode('|', array_diff(array_keys($valid_tags), array('td', 'anchor'))) . ')[^<>\\[\\]]*\\]\s*\\[/\\1\\]~'; |
| 1110 | 1146 | $lastlen = 0; |
| 1111 | - while (strlen($text) !== $lastlen) |
|
| 1112 | - $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
| 1147 | + while (strlen($text) !== $lastlen) { |
|
| 1148 | + $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
| 1149 | + } |
|
| 1113 | 1150 | |
| 1114 | 1151 | // Need to sort the tags by name length. |
| 1115 | 1152 | uksort($valid_tags, function ($a, $b) { |
@@ -1148,8 +1185,9 @@ discard block |
||
| 1148 | 1185 | $isCompetingTag = in_array($tag, $competing_tags); |
| 1149 | 1186 | |
| 1150 | 1187 | // Check if this might be one of those cleaned out tags. |
| 1151 | - if ($tag === '') |
|
| 1152 | - continue; |
|
| 1188 | + if ($tag === '') { |
|
| 1189 | + continue; |
|
| 1190 | + } |
|
| 1153 | 1191 | |
| 1154 | 1192 | // Special case: inside [code] blocks any code is left untouched. |
| 1155 | 1193 | elseif ($tag === 'code') |
@@ -1160,8 +1198,9 @@ discard block |
||
| 1160 | 1198 | $inCode = false; |
| 1161 | 1199 | |
| 1162 | 1200 | // Reopen tags that were closed before the code block. |
| 1163 | - if (!empty($inlineElements)) |
|
| 1164 | - $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
| 1201 | + if (!empty($inlineElements)) { |
|
| 1202 | + $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
| 1203 | + } |
|
| 1165 | 1204 | } |
| 1166 | 1205 | |
| 1167 | 1206 | // We're outside a coding and nobbc block and opening it. |
@@ -1190,8 +1229,9 @@ discard block |
||
| 1190 | 1229 | $inNoBbc = false; |
| 1191 | 1230 | |
| 1192 | 1231 | // Some inline elements might've been closed that need reopening. |
| 1193 | - if (!empty($inlineElements)) |
|
| 1194 | - $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
| 1232 | + if (!empty($inlineElements)) { |
|
| 1233 | + $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
| 1234 | + } |
|
| 1195 | 1235 | } |
| 1196 | 1236 | |
| 1197 | 1237 | // We're outside a nobbc and coding block and opening it. |
@@ -1211,8 +1251,9 @@ discard block |
||
| 1211 | 1251 | } |
| 1212 | 1252 | |
| 1213 | 1253 | // So, we're inside one of the special blocks: ignore any tag. |
| 1214 | - elseif ($inCode || $inNoBbc) |
|
| 1215 | - continue; |
|
| 1254 | + elseif ($inCode || $inNoBbc) { |
|
| 1255 | + continue; |
|
| 1256 | + } |
|
| 1216 | 1257 | |
| 1217 | 1258 | // We're dealing with an opening tag. |
| 1218 | 1259 | if ($isOpeningTag) |
@@ -1253,8 +1294,9 @@ discard block |
||
| 1253 | 1294 | if ($parts[$j + 3] === $tag) |
| 1254 | 1295 | { |
| 1255 | 1296 | // If it's an opening tag, increase the level. |
| 1256 | - if ($parts[$j + 2] === '') |
|
| 1257 | - $curLevel++; |
|
| 1297 | + if ($parts[$j + 2] === '') { |
|
| 1298 | + $curLevel++; |
|
| 1299 | + } |
|
| 1258 | 1300 | |
| 1259 | 1301 | // A closing tag, decrease the level. |
| 1260 | 1302 | else |
@@ -1277,13 +1319,15 @@ discard block |
||
| 1277 | 1319 | { |
| 1278 | 1320 | if ($isCompetingTag) |
| 1279 | 1321 | { |
| 1280 | - if (!isset($competingElements[$tag])) |
|
| 1281 | - $competingElements[$tag] = array(); |
|
| 1322 | + if (!isset($competingElements[$tag])) { |
|
| 1323 | + $competingElements[$tag] = array(); |
|
| 1324 | + } |
|
| 1282 | 1325 | |
| 1283 | 1326 | $competingElements[$tag][] = $parts[$i + 4]; |
| 1284 | 1327 | |
| 1285 | - if (count($competingElements[$tag]) > 1) |
|
| 1286 | - $parts[$i] .= '[/' . $tag . ']'; |
|
| 1328 | + if (count($competingElements[$tag]) > 1) { |
|
| 1329 | + $parts[$i] .= '[/' . $tag . ']'; |
|
| 1330 | + } |
|
| 1287 | 1331 | } |
| 1288 | 1332 | |
| 1289 | 1333 | $inlineElements[$elementContent] = $tag; |
@@ -1303,15 +1347,17 @@ discard block |
||
| 1303 | 1347 | $addClosingTags = array(); |
| 1304 | 1348 | while ($element = array_pop($blockElements)) |
| 1305 | 1349 | { |
| 1306 | - if ($element === $tag) |
|
| 1307 | - break; |
|
| 1350 | + if ($element === $tag) { |
|
| 1351 | + break; |
|
| 1352 | + } |
|
| 1308 | 1353 | |
| 1309 | 1354 | // Still a block tag was open not equal to this tag. |
| 1310 | 1355 | $addClosingTags[] = $element['type']; |
| 1311 | 1356 | } |
| 1312 | 1357 | |
| 1313 | - if (!empty($addClosingTags)) |
|
| 1314 | - $parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1]; |
|
| 1358 | + if (!empty($addClosingTags)) { |
|
| 1359 | + $parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1]; |
|
| 1360 | + } |
|
| 1315 | 1361 | |
| 1316 | 1362 | // Apparently the closing tag was not found on the stack. |
| 1317 | 1363 | if (!is_string($element) || $element !== $tag) |
@@ -1321,8 +1367,7 @@ discard block |
||
| 1321 | 1367 | $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
| 1322 | 1368 | continue; |
| 1323 | 1369 | } |
| 1324 | - } |
|
| 1325 | - else |
|
| 1370 | + } else |
|
| 1326 | 1371 | { |
| 1327 | 1372 | // Get rid of this closing tag! |
| 1328 | 1373 | $parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
@@ -1351,53 +1396,62 @@ discard block |
||
| 1351 | 1396 | unset($inlineElements[$tagContentToBeClosed]); |
| 1352 | 1397 | |
| 1353 | 1398 | // Was this the tag we were looking for? |
| 1354 | - if ($tagToBeClosed === $tag) |
|
| 1355 | - break; |
|
| 1399 | + if ($tagToBeClosed === $tag) { |
|
| 1400 | + break; |
|
| 1401 | + } |
|
| 1356 | 1402 | |
| 1357 | 1403 | // Nope, close it and look further! |
| 1358 | - else |
|
| 1359 | - $parts[$i] .= '[/' . $tagToBeClosed . ']'; |
|
| 1404 | + else { |
|
| 1405 | + $parts[$i] .= '[/' . $tagToBeClosed . ']'; |
|
| 1406 | + } |
|
| 1360 | 1407 | } |
| 1361 | 1408 | |
| 1362 | 1409 | if ($isCompetingTag && !empty($competingElements[$tag])) |
| 1363 | 1410 | { |
| 1364 | 1411 | array_pop($competingElements[$tag]); |
| 1365 | 1412 | |
| 1366 | - if (count($competingElements[$tag]) > 0) |
|
| 1367 | - $parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5]; |
|
| 1413 | + if (count($competingElements[$tag]) > 0) { |
|
| 1414 | + $parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5]; |
|
| 1415 | + } |
|
| 1368 | 1416 | } |
| 1369 | 1417 | } |
| 1370 | 1418 | |
| 1371 | 1419 | // Unexpected closing tag, ex-ter-mi-nate. |
| 1372 | - else |
|
| 1373 | - $parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
|
| 1420 | + else { |
|
| 1421 | + $parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
|
| 1422 | + } |
|
| 1374 | 1423 | } |
| 1375 | 1424 | } |
| 1376 | 1425 | } |
| 1377 | 1426 | |
| 1378 | 1427 | // Close the code tags. |
| 1379 | - if ($inCode) |
|
| 1380 | - $parts[$i] .= '[/code]'; |
|
| 1428 | + if ($inCode) { |
|
| 1429 | + $parts[$i] .= '[/code]'; |
|
| 1430 | + } |
|
| 1381 | 1431 | |
| 1382 | 1432 | // The same for nobbc tags. |
| 1383 | - elseif ($inNoBbc) |
|
| 1384 | - $parts[$i] .= '[/nobbc]'; |
|
| 1433 | + elseif ($inNoBbc) { |
|
| 1434 | + $parts[$i] .= '[/nobbc]'; |
|
| 1435 | + } |
|
| 1385 | 1436 | |
| 1386 | 1437 | // Still inline tags left unclosed? Close them now, better late than never. |
| 1387 | - elseif (!empty($inlineElements)) |
|
| 1388 | - $parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']'; |
|
| 1438 | + elseif (!empty($inlineElements)) { |
|
| 1439 | + $parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']'; |
|
| 1440 | + } |
|
| 1389 | 1441 | |
| 1390 | 1442 | // Now close the block elements. |
| 1391 | - if (!empty($blockElements)) |
|
| 1392 | - $parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']'; |
|
| 1443 | + if (!empty($blockElements)) { |
|
| 1444 | + $parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']'; |
|
| 1445 | + } |
|
| 1393 | 1446 | |
| 1394 | 1447 | $text = implode('', $parts); |
| 1395 | 1448 | } |
| 1396 | 1449 | |
| 1397 | 1450 | // Final clean up of back to back tags. |
| 1398 | 1451 | $lastlen = 0; |
| 1399 | - while (strlen($text) !== $lastlen) |
|
| 1400 | - $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
| 1452 | + while (strlen($text) !== $lastlen) { |
|
| 1453 | + $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
| 1454 | + } |
|
| 1401 | 1455 | |
| 1402 | 1456 | return $text; |
| 1403 | 1457 | } |
@@ -1414,22 +1468,25 @@ discard block |
||
| 1414 | 1468 | $context['template_layers'] = array(); |
| 1415 | 1469 | // Lets make sure we aren't going to output anything nasty. |
| 1416 | 1470 | @ob_end_clean(); |
| 1417 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
| 1418 | - @ob_start('ob_gzhandler'); |
|
| 1419 | - else |
|
| 1420 | - @ob_start(); |
|
| 1471 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
| 1472 | + @ob_start('ob_gzhandler'); |
|
| 1473 | + } else { |
|
| 1474 | + @ob_start(); |
|
| 1475 | + } |
|
| 1421 | 1476 | |
| 1422 | 1477 | // If we don't have any locale better avoid broken js |
| 1423 | - if (empty($txt['lang_locale'])) |
|
| 1424 | - die(); |
|
| 1478 | + if (empty($txt['lang_locale'])) { |
|
| 1479 | + die(); |
|
| 1480 | + } |
|
| 1425 | 1481 | |
| 1426 | 1482 | $file_data = '(function ($) { |
| 1427 | 1483 | \'use strict\'; |
| 1428 | 1484 | |
| 1429 | 1485 | $.sceditor.locale[' . JavaScriptEscape($txt['lang_locale']) . '] = {'; |
| 1430 | - foreach ($editortxt as $key => $val) |
|
| 1431 | - $file_data .= ' |
|
| 1486 | + foreach ($editortxt as $key => $val) { |
|
| 1487 | + $file_data .= ' |
|
| 1432 | 1488 | ' . JavaScriptEscape($key) . ': ' . JavaScriptEscape($val) . ','; |
| 1489 | + } |
|
| 1433 | 1490 | |
| 1434 | 1491 | $file_data .= ' |
| 1435 | 1492 | dateFormat: "day.month.year" |
@@ -1497,8 +1554,9 @@ discard block |
||
| 1497 | 1554 | ) |
| 1498 | 1555 | ); |
| 1499 | 1556 | $icon_data = array(); |
| 1500 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1501 | - $icon_data[] = $row; |
|
| 1557 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1558 | + $icon_data[] = $row; |
|
| 1559 | + } |
|
| 1502 | 1560 | $smcFunc['db_free_result']($request); |
| 1503 | 1561 | |
| 1504 | 1562 | $icons = array(); |
@@ -1513,9 +1571,9 @@ discard block |
||
| 1513 | 1571 | } |
| 1514 | 1572 | |
| 1515 | 1573 | cache_put_data('posting_icons-' . $board_id, $icons, 480); |
| 1574 | + } else { |
|
| 1575 | + $icons = $temp; |
|
| 1516 | 1576 | } |
| 1517 | - else |
|
| 1518 | - $icons = $temp; |
|
| 1519 | 1577 | } |
| 1520 | 1578 | call_integration_hook('integrate_load_message_icons', array(&$icons)); |
| 1521 | 1579 | |
@@ -1544,8 +1602,9 @@ discard block |
||
| 1544 | 1602 | { |
| 1545 | 1603 | // Some general stuff. |
| 1546 | 1604 | $settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set']; |
| 1547 | - if (!empty($context['drafts_autosave'])) |
|
| 1548 | - $context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000; |
|
| 1605 | + if (!empty($context['drafts_autosave'])) { |
|
| 1606 | + $context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000; |
|
| 1607 | + } |
|
| 1549 | 1608 | |
| 1550 | 1609 | // This really has some WYSIWYG stuff. |
| 1551 | 1610 | loadCSSFile('jquery.sceditor.css', array('force_current' => false, 'validate' => true), 'smf_jquery_sceditor'); |
@@ -1562,8 +1621,9 @@ discard block |
||
| 1562 | 1621 | var bbc_quote = \'' . addcslashes($txt['quote'], "'") . '\'; |
| 1563 | 1622 | var bbc_search_on = \'' . addcslashes($txt['search_on'], "'") . '\';'); |
| 1564 | 1623 | // editor language file |
| 1565 | - if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') |
|
| 1566 | - loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language'); |
|
| 1624 | + if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') { |
|
| 1625 | + loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language'); |
|
| 1626 | + } |
|
| 1567 | 1627 | |
| 1568 | 1628 | $context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) ? '_drafts' : '') . (stripos($_SERVER['HTTP_USER_AGENT'], 'Macintosh') !== false ? '_mac' : (isBrowser('is_firefox') ? '_firefox' : ''))]; |
| 1569 | 1629 | $context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_character_set'] == 'UTF-8' || function_exists('iconv')))); |
@@ -1572,11 +1632,12 @@ discard block |
||
| 1572 | 1632 | loadJavaScriptFile('spellcheck.js', array('minimize' => true), 'smf_spellcheck'); |
| 1573 | 1633 | |
| 1574 | 1634 | // Some hidden information is needed in order to make the spell checking work. |
| 1575 | - if (!isset($_REQUEST['xml'])) |
|
| 1576 | - $context['insert_after_template'] .= ' |
|
| 1635 | + if (!isset($_REQUEST['xml'])) { |
|
| 1636 | + $context['insert_after_template'] .= ' |
|
| 1577 | 1637 | <form name="spell_form" id="spell_form" method="post" accept-charset="' . $context['character_set'] . '" target="spellWindow" action="' . $scripturl . '?action=spellcheck"> |
| 1578 | 1638 | <input type="hidden" name="spellstring" value=""> |
| 1579 | 1639 | </form>'; |
| 1640 | + } |
|
| 1580 | 1641 | } |
| 1581 | 1642 | } |
| 1582 | 1643 | |
@@ -1768,8 +1829,9 @@ discard block |
||
| 1768 | 1829 | |
| 1769 | 1830 | // Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this. |
| 1770 | 1831 | $disabled_tags = array(); |
| 1771 | - if (!empty($modSettings['disabledBBC'])) |
|
| 1772 | - $disabled_tags = explode(',', $modSettings['disabledBBC']); |
|
| 1832 | + if (!empty($modSettings['disabledBBC'])) { |
|
| 1833 | + $disabled_tags = explode(',', $modSettings['disabledBBC']); |
|
| 1834 | + } |
|
| 1773 | 1835 | |
| 1774 | 1836 | foreach ($disabled_tags as $tag) |
| 1775 | 1837 | { |
@@ -1781,9 +1843,10 @@ discard block |
||
| 1781 | 1843 | $context['disabled_tags']['orderedlist'] = true; |
| 1782 | 1844 | } |
| 1783 | 1845 | |
| 1784 | - foreach ($editor_tag_map as $thisTag => $tagNameBBC) |
|
| 1785 | - if ($tag === $thisTag) |
|
| 1846 | + foreach ($editor_tag_map as $thisTag => $tagNameBBC) { |
|
| 1847 | + if ($tag === $thisTag) |
|
| 1786 | 1848 | $context['disabled_tags'][$tagNameBBC] = true; |
| 1849 | + } |
|
| 1787 | 1850 | |
| 1788 | 1851 | $context['disabled_tags'][$tag] = true; |
| 1789 | 1852 | } |
@@ -1794,8 +1857,9 @@ discard block |
||
| 1794 | 1857 | |
| 1795 | 1858 | foreach ($context['bbc_tags'] as $row => $tagRow) |
| 1796 | 1859 | { |
| 1797 | - if (!isset($context['bbc_toolbar'][$row])) |
|
| 1798 | - $context['bbc_toolbar'][$row] = array(); |
|
| 1860 | + if (!isset($context['bbc_toolbar'][$row])) { |
|
| 1861 | + $context['bbc_toolbar'][$row] = array(); |
|
| 1862 | + } |
|
| 1799 | 1863 | |
| 1800 | 1864 | $tagsRow = array(); |
| 1801 | 1865 | |
@@ -1831,20 +1895,21 @@ discard block |
||
| 1831 | 1895 | |
| 1832 | 1896 | $context['bbcodes_handlers'] .= ' |
| 1833 | 1897 | });'; |
| 1834 | - } |
|
| 1835 | - else |
|
| 1898 | + } else |
|
| 1836 | 1899 | { |
| 1837 | 1900 | $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
| 1838 | 1901 | $tagsRow = array(); |
| 1839 | 1902 | } |
| 1840 | 1903 | } |
| 1841 | 1904 | |
| 1842 | - if (!empty($tagsRow)) |
|
| 1843 | - $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
|
| 1905 | + if (!empty($tagsRow)) { |
|
| 1906 | + $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
|
| 1907 | + } |
|
| 1844 | 1908 | } |
| 1845 | 1909 | |
| 1846 | - if (!empty($bbcodes_styles)) |
|
| 1847 | - addInlineCss($bbcodes_styles); |
|
| 1910 | + if (!empty($bbcodes_styles)) { |
|
| 1911 | + addInlineCss($bbcodes_styles); |
|
| 1912 | + } |
|
| 1848 | 1913 | } |
| 1849 | 1914 | |
| 1850 | 1915 | // Initialize smiley array... if not loaded before. |
@@ -1856,8 +1921,8 @@ discard block |
||
| 1856 | 1921 | ); |
| 1857 | 1922 | |
| 1858 | 1923 | // Load smileys - don't bother to run a query if we're not using the database's ones anyhow. |
| 1859 | - if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') |
|
| 1860 | - $context['smileys']['postform'][] = array( |
|
| 1924 | + if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') { |
|
| 1925 | + $context['smileys']['postform'][] = array( |
|
| 1861 | 1926 | 'smileys' => array( |
| 1862 | 1927 | array( |
| 1863 | 1928 | 'code' => ':)', |
@@ -1943,7 +2008,7 @@ discard block |
||
| 1943 | 2008 | ), |
| 1944 | 2009 | 'isLast' => true, |
| 1945 | 2010 | ); |
| 1946 | - elseif ($user_info['smiley_set'] != 'none') |
|
| 2011 | + } elseif ($user_info['smiley_set'] != 'none') |
|
| 1947 | 2012 | { |
| 1948 | 2013 | if (($temp = cache_get_data('posting_smileys', 480)) == null) |
| 1949 | 2014 | { |
@@ -1966,17 +2031,19 @@ discard block |
||
| 1966 | 2031 | |
| 1967 | 2032 | foreach ($context['smileys'] as $section => $smileyRows) |
| 1968 | 2033 | { |
| 1969 | - foreach ($smileyRows as $rowIndex => $smileys) |
|
| 1970 | - $context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true; |
|
| 2034 | + foreach ($smileyRows as $rowIndex => $smileys) { |
|
| 2035 | + $context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true; |
|
| 2036 | + } |
|
| 1971 | 2037 | |
| 1972 | - if (!empty($smileyRows)) |
|
| 1973 | - $context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true; |
|
| 2038 | + if (!empty($smileyRows)) { |
|
| 2039 | + $context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true; |
|
| 2040 | + } |
|
| 1974 | 2041 | } |
| 1975 | 2042 | |
| 1976 | 2043 | cache_put_data('posting_smileys', $context['smileys'], 480); |
| 2044 | + } else { |
|
| 2045 | + $context['smileys'] = $temp; |
|
| 1977 | 2046 | } |
| 1978 | - else |
|
| 1979 | - $context['smileys'] = $temp; |
|
| 1980 | 2047 | } |
| 1981 | 2048 | } |
| 1982 | 2049 | |
@@ -1992,12 +2059,15 @@ discard block |
||
| 1992 | 2059 | 'plugins' => '', |
| 1993 | 2060 | 'bbcodeTrim' => true, |
| 1994 | 2061 | ); |
| 1995 | - if (!empty($context['controls']['richedit'][$editorOptions['id']]['locale'])) |
|
| 1996 | - $sce_options['locale'] = $context['controls']['richedit'][$editorOptions['id']]['locale']; |
|
| 1997 | - if (!empty($context['right_to_left'])) |
|
| 1998 | - $sce_options['rtl'] = true; |
|
| 1999 | - if ($editorOptions['id'] != 'quickReply') |
|
| 2000 | - $sce_options['autofocus'] = true; |
|
| 2062 | + if (!empty($context['controls']['richedit'][$editorOptions['id']]['locale'])) { |
|
| 2063 | + $sce_options['locale'] = $context['controls']['richedit'][$editorOptions['id']]['locale']; |
|
| 2064 | + } |
|
| 2065 | + if (!empty($context['right_to_left'])) { |
|
| 2066 | + $sce_options['rtl'] = true; |
|
| 2067 | + } |
|
| 2068 | + if ($editorOptions['id'] != 'quickReply') { |
|
| 2069 | + $sce_options['autofocus'] = true; |
|
| 2070 | + } |
|
| 2001 | 2071 | |
| 2002 | 2072 | $sce_options['emoticons'] = array(); |
| 2003 | 2073 | $sce_options['emoticonsDescriptions'] = array(); |
@@ -2014,10 +2084,11 @@ discard block |
||
| 2014 | 2084 | $countLocations--; |
| 2015 | 2085 | |
| 2016 | 2086 | unset($smiley_location); |
| 2017 | - if ($location == 'postform') |
|
| 2018 | - $smiley_location = &$sce_options['emoticons']['dropdown']; |
|
| 2019 | - elseif ($location == 'popup') |
|
| 2020 | - $smiley_location = &$sce_options['emoticons']['popup']; |
|
| 2087 | + if ($location == 'postform') { |
|
| 2088 | + $smiley_location = &$sce_options['emoticons']['dropdown']; |
|
| 2089 | + } elseif ($location == 'popup') { |
|
| 2090 | + $smiley_location = &$sce_options['emoticons']['popup']; |
|
| 2091 | + } |
|
| 2021 | 2092 | |
| 2022 | 2093 | $numRows = count($smileyRows); |
| 2023 | 2094 | |
@@ -2031,8 +2102,9 @@ discard block |
||
| 2031 | 2102 | $sce_options['emoticonsDescriptions'][$smiley['code']] = $smiley['description']; |
| 2032 | 2103 | } |
| 2033 | 2104 | |
| 2034 | - if (empty($smileyRow['isLast']) && $numRows != 1) |
|
| 2035 | - $smiley_location['-' . $emptyPlaceholder++] = ''; |
|
| 2105 | + if (empty($smileyRow['isLast']) && $numRows != 1) { |
|
| 2106 | + $smiley_location['-' . $emptyPlaceholder++] = ''; |
|
| 2107 | + } |
|
| 2036 | 2108 | } |
| 2037 | 2109 | } |
| 2038 | 2110 | } |
@@ -2047,8 +2119,9 @@ discard block |
||
| 2047 | 2119 | |
| 2048 | 2120 | $count_tags--; |
| 2049 | 2121 | |
| 2050 | - if (!empty($count_tags)) |
|
| 2051 | - $sce_options['toolbar'] .= '||'; |
|
| 2122 | + if (!empty($count_tags)) { |
|
| 2123 | + $sce_options['toolbar'] .= '||'; |
|
| 2124 | + } |
|
| 2052 | 2125 | } |
| 2053 | 2126 | } |
| 2054 | 2127 | |
@@ -2076,8 +2149,9 @@ discard block |
||
| 2076 | 2149 | loadTemplate('GenericControls'); |
| 2077 | 2150 | |
| 2078 | 2151 | // Some javascript ma'am? |
| 2079 | - if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) |
|
| 2080 | - loadJavaScriptFile('captcha.js', array('minimize' => true), 'smf_captcha'); |
|
| 2152 | + if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) { |
|
| 2153 | + loadJavaScriptFile('captcha.js', array('minimize' => true), 'smf_captcha'); |
|
| 2154 | + } |
|
| 2081 | 2155 | |
| 2082 | 2156 | $context['use_graphic_library'] = in_array('gd', get_loaded_extensions()); |
| 2083 | 2157 | |
@@ -2090,8 +2164,8 @@ discard block |
||
| 2090 | 2164 | $isNew = !isset($context['controls']['verification'][$verificationOptions['id']]); |
| 2091 | 2165 | |
| 2092 | 2166 | // Log this into our collection. |
| 2093 | - if ($isNew) |
|
| 2094 | - $context['controls']['verification'][$verificationOptions['id']] = array( |
|
| 2167 | + if ($isNew) { |
|
| 2168 | + $context['controls']['verification'][$verificationOptions['id']] = array( |
|
| 2095 | 2169 | 'id' => $verificationOptions['id'], |
| 2096 | 2170 | 'empty_field' => empty($verificationOptions['no_empty_field']), |
| 2097 | 2171 | 'show_visual' => !empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])), |
@@ -2102,13 +2176,15 @@ discard block |
||
| 2102 | 2176 | 'questions' => array(), |
| 2103 | 2177 | 'can_recaptcha' => !empty($modSettings['recaptcha_enabled']) && !empty($modSettings['recaptcha_site_key']) && !empty($modSettings['recaptcha_secret_key']), |
| 2104 | 2178 | ); |
| 2179 | + } |
|
| 2105 | 2180 | $thisVerification = &$context['controls']['verification'][$verificationOptions['id']]; |
| 2106 | 2181 | |
| 2107 | 2182 | // Is there actually going to be anything? |
| 2108 | - if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) |
|
| 2109 | - return false; |
|
| 2110 | - elseif (!$isNew && !$do_test) |
|
| 2111 | - return true; |
|
| 2183 | + if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) { |
|
| 2184 | + return false; |
|
| 2185 | + } elseif (!$isNew && !$do_test) { |
|
| 2186 | + return true; |
|
| 2187 | + } |
|
| 2112 | 2188 | |
| 2113 | 2189 | // Sanitize reCAPTCHA fields? |
| 2114 | 2190 | if ($thisVerification['can_recaptcha']) |
@@ -2121,11 +2197,12 @@ discard block |
||
| 2121 | 2197 | } |
| 2122 | 2198 | |
| 2123 | 2199 | // Add javascript for the object. |
| 2124 | - if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) |
|
| 2125 | - $context['insert_after_template'] .= ' |
|
| 2200 | + if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) { |
|
| 2201 | + $context['insert_after_template'] .= ' |
|
| 2126 | 2202 | <script> |
| 2127 | 2203 | var verification' . $verificationOptions['id'] . 'Handle = new smfCaptcha("' . $thisVerification['image_href'] . '", "' . $verificationOptions['id'] . '", ' . ($context['use_graphic_library'] ? 1 : 0) . '); |
| 2128 | 2204 | </script>'; |
| 2205 | + } |
|
| 2129 | 2206 | |
| 2130 | 2207 | // If we want questions do we have a cache of all the IDs? |
| 2131 | 2208 | if (!empty($thisVerification['number_questions']) && empty($modSettings['question_id_cache'])) |
@@ -2148,8 +2225,9 @@ discard block |
||
| 2148 | 2225 | unset ($row['id_question']); |
| 2149 | 2226 | // Make them all lowercase. We can't directly use $smcFunc['strtolower'] with array_walk, so do it manually, eh? |
| 2150 | 2227 | $row['answers'] = $smcFunc['json_decode']($row['answers'], true); |
| 2151 | - foreach ($row['answers'] as $k => $v) |
|
| 2152 | - $row['answers'][$k] = $smcFunc['strtolower']($v); |
|
| 2228 | + foreach ($row['answers'] as $k => $v) { |
|
| 2229 | + $row['answers'][$k] = $smcFunc['strtolower']($v); |
|
| 2230 | + } |
|
| 2153 | 2231 | |
| 2154 | 2232 | $modSettings['question_id_cache']['questions'][$id_question] = $row; |
| 2155 | 2233 | $modSettings['question_id_cache']['langs'][$row['lngfile']][] = $id_question; |
@@ -2160,35 +2238,42 @@ discard block |
||
| 2160 | 2238 | } |
| 2161 | 2239 | } |
| 2162 | 2240 | |
| 2163 | - if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) |
|
| 2164 | - $_SESSION[$verificationOptions['id'] . '_vv'] = array(); |
|
| 2241 | + if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) { |
|
| 2242 | + $_SESSION[$verificationOptions['id'] . '_vv'] = array(); |
|
| 2243 | + } |
|
| 2165 | 2244 | |
| 2166 | 2245 | // Do we need to refresh the verification? |
| 2167 | - if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) |
|
| 2168 | - $force_refresh = true; |
|
| 2169 | - else |
|
| 2170 | - $force_refresh = false; |
|
| 2246 | + if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) { |
|
| 2247 | + $force_refresh = true; |
|
| 2248 | + } else { |
|
| 2249 | + $force_refresh = false; |
|
| 2250 | + } |
|
| 2171 | 2251 | |
| 2172 | 2252 | // This can also force a fresh, although unlikely. |
| 2173 | - if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) |
|
| 2174 | - $force_refresh = true; |
|
| 2253 | + if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) { |
|
| 2254 | + $force_refresh = true; |
|
| 2255 | + } |
|
| 2175 | 2256 | |
| 2176 | 2257 | $verification_errors = array(); |
| 2177 | 2258 | // Start with any testing. |
| 2178 | 2259 | if ($do_test) |
| 2179 | 2260 | { |
| 2180 | 2261 | // This cannot happen! |
| 2181 | - if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) |
|
| 2182 | - fatal_lang_error('no_access', false); |
|
| 2262 | + if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) { |
|
| 2263 | + fatal_lang_error('no_access', false); |
|
| 2264 | + } |
|
| 2183 | 2265 | // ... nor this! |
| 2184 | - if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) |
|
| 2185 | - fatal_lang_error('no_access', false); |
|
| 2266 | + if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) { |
|
| 2267 | + fatal_lang_error('no_access', false); |
|
| 2268 | + } |
|
| 2186 | 2269 | // Hmm, it's requested but not actually declared. This shouldn't happen. |
| 2187 | - if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) |
|
| 2188 | - fatal_lang_error('no_access', false); |
|
| 2270 | + if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) { |
|
| 2271 | + fatal_lang_error('no_access', false); |
|
| 2272 | + } |
|
| 2189 | 2273 | // While we're here, did the user do something bad? |
| 2190 | - if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) |
|
| 2191 | - $verification_errors[] = 'wrong_verification_answer'; |
|
| 2274 | + if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) { |
|
| 2275 | + $verification_errors[] = 'wrong_verification_answer'; |
|
| 2276 | + } |
|
| 2192 | 2277 | |
| 2193 | 2278 | if ($thisVerification['can_recaptcha']) |
| 2194 | 2279 | { |
@@ -2199,22 +2284,25 @@ discard block |
||
| 2199 | 2284 | { |
| 2200 | 2285 | $resp = $reCaptcha->verify($_POST['g-recaptcha-response'], $user_info['ip']); |
| 2201 | 2286 | |
| 2202 | - if (!$resp->isSuccess()) |
|
| 2203 | - $verification_errors[] = 'wrong_verification_code'; |
|
| 2287 | + if (!$resp->isSuccess()) { |
|
| 2288 | + $verification_errors[] = 'wrong_verification_code'; |
|
| 2289 | + } |
|
| 2290 | + } else { |
|
| 2291 | + $verification_errors[] = 'wrong_verification_code'; |
|
| 2204 | 2292 | } |
| 2205 | - else |
|
| 2206 | - $verification_errors[] = 'wrong_verification_code'; |
|
| 2207 | 2293 | } |
| 2208 | - if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) |
|
| 2209 | - $verification_errors[] = 'wrong_verification_code'; |
|
| 2294 | + if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) { |
|
| 2295 | + $verification_errors[] = 'wrong_verification_code'; |
|
| 2296 | + } |
|
| 2210 | 2297 | if ($thisVerification['number_questions']) |
| 2211 | 2298 | { |
| 2212 | 2299 | $incorrectQuestions = array(); |
| 2213 | 2300 | foreach ($_SESSION[$verificationOptions['id'] . '_vv']['q'] as $q) |
| 2214 | 2301 | { |
| 2215 | 2302 | // We don't have this question any more, thus no answers. |
| 2216 | - if (!isset($modSettings['question_id_cache']['questions'][$q])) |
|
| 2217 | - continue; |
|
| 2303 | + if (!isset($modSettings['question_id_cache']['questions'][$q])) { |
|
| 2304 | + continue; |
|
| 2305 | + } |
|
| 2218 | 2306 | // This is quite complex. We have our question but it might have multiple answers. |
| 2219 | 2307 | // First, did they actually answer this question? |
| 2220 | 2308 | if (!isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) || trim($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) == '') |
@@ -2226,24 +2314,28 @@ discard block |
||
| 2226 | 2314 | else |
| 2227 | 2315 | { |
| 2228 | 2316 | $given_answer = trim($smcFunc['htmlspecialchars'](strtolower($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]))); |
| 2229 | - if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) |
|
| 2230 | - $incorrectQuestions[] = $q; |
|
| 2317 | + if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) { |
|
| 2318 | + $incorrectQuestions[] = $q; |
|
| 2319 | + } |
|
| 2231 | 2320 | } |
| 2232 | 2321 | } |
| 2233 | 2322 | |
| 2234 | - if (!empty($incorrectQuestions)) |
|
| 2235 | - $verification_errors[] = 'wrong_verification_answer'; |
|
| 2323 | + if (!empty($incorrectQuestions)) { |
|
| 2324 | + $verification_errors[] = 'wrong_verification_answer'; |
|
| 2325 | + } |
|
| 2236 | 2326 | } |
| 2237 | 2327 | } |
| 2238 | 2328 | |
| 2239 | 2329 | // Any errors means we refresh potentially. |
| 2240 | 2330 | if (!empty($verification_errors)) |
| 2241 | 2331 | { |
| 2242 | - if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) |
|
| 2243 | - $_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0; |
|
| 2332 | + if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) { |
|
| 2333 | + $_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0; |
|
| 2334 | + } |
|
| 2244 | 2335 | // Too many errors? |
| 2245 | - elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) |
|
| 2246 | - $force_refresh = true; |
|
| 2336 | + elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) { |
|
| 2337 | + $force_refresh = true; |
|
| 2338 | + } |
|
| 2247 | 2339 | |
| 2248 | 2340 | // Keep a track of these. |
| 2249 | 2341 | $_SESSION[$verificationOptions['id'] . '_vv']['errors']++; |
@@ -2276,8 +2368,9 @@ discard block |
||
| 2276 | 2368 | // Are we overriding the range? |
| 2277 | 2369 | $character_range = !empty($verificationOptions['override_range']) ? $verificationOptions['override_range'] : $context['standard_captcha_range']; |
| 2278 | 2370 | |
| 2279 | - for ($i = 0; $i < 6; $i++) |
|
| 2280 | - $_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)]; |
|
| 2371 | + for ($i = 0; $i < 6; $i++) { |
|
| 2372 | + $_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)]; |
|
| 2373 | + } |
|
| 2281 | 2374 | } |
| 2282 | 2375 | |
| 2283 | 2376 | // Getting some new questions? |
@@ -2285,8 +2378,9 @@ discard block |
||
| 2285 | 2378 | { |
| 2286 | 2379 | // Attempt to try the current page's language, followed by the user's preference, followed by the site default. |
| 2287 | 2380 | $possible_langs = array(); |
| 2288 | - if (isset($_SESSION['language'])) |
|
| 2289 | - $possible_langs[] = strtr($_SESSION['language'], array('-utf8' => '')); |
|
| 2381 | + if (isset($_SESSION['language'])) { |
|
| 2382 | + $possible_langs[] = strtr($_SESSION['language'], array('-utf8' => '')); |
|
| 2383 | + } |
|
| 2290 | 2384 | if (!empty($user_info['language'])); |
| 2291 | 2385 | $possible_langs[] = $user_info['language']; |
| 2292 | 2386 | $possible_langs[] = $language; |
@@ -2305,8 +2399,7 @@ discard block |
||
| 2305 | 2399 | } |
| 2306 | 2400 | } |
| 2307 | 2401 | } |
| 2308 | - } |
|
| 2309 | - else |
|
| 2402 | + } else |
|
| 2310 | 2403 | { |
| 2311 | 2404 | // Same questions as before. |
| 2312 | 2405 | $questionIDs = !empty($_SESSION[$verificationOptions['id'] . '_vv']['q']) ? $_SESSION[$verificationOptions['id'] . '_vv']['q'] : array(); |
@@ -2316,8 +2409,9 @@ discard block |
||
| 2316 | 2409 | // If we do have an empty field, it would be nice to hide it from legitimate users who shouldn't be populating it anyway. |
| 2317 | 2410 | if (!empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) |
| 2318 | 2411 | { |
| 2319 | - if (!isset($context['html_headers'])) |
|
| 2320 | - $context['html_headers'] = ''; |
|
| 2412 | + if (!isset($context['html_headers'])) { |
|
| 2413 | + $context['html_headers'] = ''; |
|
| 2414 | + } |
|
| 2321 | 2415 | $context['html_headers'] .= '<style>.vv_special { display:none; }</style>'; |
| 2322 | 2416 | } |
| 2323 | 2417 | |
@@ -2343,11 +2437,13 @@ discard block |
||
| 2343 | 2437 | $_SESSION[$verificationOptions['id'] . '_vv']['count'] = empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) ? 1 : $_SESSION[$verificationOptions['id'] . '_vv']['count'] + 1; |
| 2344 | 2438 | |
| 2345 | 2439 | // Return errors if we have them. |
| 2346 | - if (!empty($verification_errors)) |
|
| 2347 | - return $verification_errors; |
|
| 2440 | + if (!empty($verification_errors)) { |
|
| 2441 | + return $verification_errors; |
|
| 2442 | + } |
|
| 2348 | 2443 | // If we had a test that one, make a note. |
| 2349 | - elseif ($do_test) |
|
| 2350 | - $_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true; |
|
| 2444 | + elseif ($do_test) { |
|
| 2445 | + $_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true; |
|
| 2446 | + } |
|
| 2351 | 2447 | |
| 2352 | 2448 | // Say that everything went well chaps. |
| 2353 | 2449 | return true; |
@@ -2372,8 +2468,9 @@ discard block |
||
| 2372 | 2468 | call_integration_hook('integrate_autosuggest', array(&$searchTypes)); |
| 2373 | 2469 | |
| 2374 | 2470 | // If we're just checking the callback function is registered return true or false. |
| 2375 | - if ($checkRegistered != null) |
|
| 2376 | - return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered); |
|
| 2471 | + if ($checkRegistered != null) { |
|
| 2472 | + return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered); |
|
| 2473 | + } |
|
| 2377 | 2474 | |
| 2378 | 2475 | checkSession('get'); |
| 2379 | 2476 | loadTemplate('Xml'); |
@@ -2524,24 +2621,27 @@ discard block |
||
| 2524 | 2621 | foreach ($possible_versions as $ver) |
| 2525 | 2622 | { |
| 2526 | 2623 | $ver = trim($ver); |
| 2527 | - if (strpos($ver, 'SMF') === 0) |
|
| 2528 | - $versions[] = $ver; |
|
| 2624 | + if (strpos($ver, 'SMF') === 0) { |
|
| 2625 | + $versions[] = $ver; |
|
| 2626 | + } |
|
| 2529 | 2627 | } |
| 2530 | 2628 | } |
| 2531 | 2629 | $smcFunc['db_free_result']($request); |
| 2532 | 2630 | |
| 2533 | 2631 | // Just in case we don't have ANYthing. |
| 2534 | - if (empty($versions)) |
|
| 2535 | - $versions = array('SMF 2.0'); |
|
| 2632 | + if (empty($versions)) { |
|
| 2633 | + $versions = array('SMF 2.0'); |
|
| 2634 | + } |
|
| 2536 | 2635 | |
| 2537 | - foreach ($versions as $id => $version) |
|
| 2538 | - if (strpos($version, strtoupper($_REQUEST['search'])) !== false) |
|
| 2636 | + foreach ($versions as $id => $version) { |
|
| 2637 | + if (strpos($version, strtoupper($_REQUEST['search'])) !== false) |
|
| 2539 | 2638 | $xml_data['items']['children'][] = array( |
| 2540 | 2639 | 'attributes' => array( |
| 2541 | 2640 | 'id' => $id, |
| 2542 | 2641 | ), |
| 2543 | 2642 | 'value' => $version, |
| 2544 | 2643 | ); |
| 2644 | + } |
|
| 2545 | 2645 | |
| 2546 | 2646 | return $xml_data; |
| 2547 | 2647 | } |