@@ -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 | * !!!Compatibility!!! |
@@ -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); |
@@ -107,8 +110,9 @@ discard block |
||
| 107 | 110 | $text = preg_replace('~</p>\s*(?!<)~i', '</p><br>', $text); |
| 108 | 111 | |
| 109 | 112 | // Safari/webkit wraps lines in Wysiwyg in <div>'s. |
| 110 | - if (isBrowser('webkit')) |
|
| 111 | - $text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text); |
|
| 113 | + if (isBrowser('webkit')) { |
|
| 114 | + $text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text); |
|
| 115 | + } |
|
| 112 | 116 | |
| 113 | 117 | // If there's a trailing break get rid of it - Firefox tends to add one. |
| 114 | 118 | $text = preg_replace('~<br\s?/?' . '>$~i', '', $text); |
@@ -123,8 +127,9 @@ discard block |
||
| 123 | 127 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
| 124 | 128 | { |
| 125 | 129 | // Value of 2 means we're inside the tag. |
| 126 | - if ($i % 4 == 2) |
|
| 127 | - $parts[$i] = strip_tags($parts[$i]); |
|
| 130 | + if ($i % 4 == 2) { |
|
| 131 | + $parts[$i] = strip_tags($parts[$i]); |
|
| 132 | + } |
|
| 128 | 133 | } |
| 129 | 134 | |
| 130 | 135 | $text = strtr(implode('', $parts), array('#smf_br_spec_grudge_cool!#' => '<br>')); |
@@ -150,18 +155,19 @@ discard block |
||
| 150 | 155 | { |
| 151 | 156 | $found = array_search($file, $smileysto); |
| 152 | 157 | // Note the weirdness here is to stop double spaces between smileys. |
| 153 | - if ($found) |
|
| 154 | - $matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#'; |
|
| 155 | - else |
|
| 156 | - $matches[1][$k] = ''; |
|
| 158 | + if ($found) { |
|
| 159 | + $matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#'; |
|
| 160 | + } else { |
|
| 161 | + $matches[1][$k] = ''; |
|
| 162 | + } |
|
| 157 | 163 | } |
| 158 | - } |
|
| 159 | - else |
|
| 164 | + } else |
|
| 160 | 165 | { |
| 161 | 166 | // Load all the smileys. |
| 162 | 167 | $names = array(); |
| 163 | - foreach ($matches[1] as $file) |
|
| 164 | - $names[] = $file; |
|
| 168 | + foreach ($matches[1] as $file) { |
|
| 169 | + $names[] = $file; |
|
| 170 | + } |
|
| 165 | 171 | $names = array_unique($names); |
| 166 | 172 | |
| 167 | 173 | if (!empty($names)) |
@@ -175,13 +181,15 @@ discard block |
||
| 175 | 181 | ) |
| 176 | 182 | ); |
| 177 | 183 | $mappings = array(); |
| 178 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 179 | - $mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']); |
|
| 184 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 185 | + $mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']); |
|
| 186 | + } |
|
| 180 | 187 | $smcFunc['db_free_result']($request); |
| 181 | 188 | |
| 182 | - foreach ($matches[1] as $k => $file) |
|
| 183 | - if (isset($mappings[$file])) |
|
| 189 | + foreach ($matches[1] as $k => $file) { |
|
| 190 | + if (isset($mappings[$file])) |
|
| 184 | 191 | $matches[1][$k] = '-[]-smf_smily_start#|#' . $mappings[$file] . '-[]-smf_smily_end#|#'; |
| 192 | + } |
|
| 185 | 193 | } |
| 186 | 194 | } |
| 187 | 195 | |
@@ -193,8 +201,9 @@ discard block |
||
| 193 | 201 | } |
| 194 | 202 | |
| 195 | 203 | // Only try to buy more time if the client didn't quit. |
| 196 | - if (connection_aborted() && $context['server']['is_apache']) |
|
| 197 | - @apache_reset_timeout(); |
|
| 204 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
| 205 | + @apache_reset_timeout(); |
|
| 206 | + } |
|
| 198 | 207 | |
| 199 | 208 | $parts = preg_split('~(<[A-Za-z]+\s*[^<>]*?style="?[^<>"]+"?[^<>]*?(?:/?)>|</[A-Za-z]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE); |
| 200 | 209 | $replacement = ''; |
@@ -205,9 +214,9 @@ discard block |
||
| 205 | 214 | if (preg_match('~(<([A-Za-z]+)\s*[^<>]*?)style="?([^<>"]+)"?([^<>]*?(/?)>)~', $part, $matches) === 1) |
| 206 | 215 | { |
| 207 | 216 | // If it's being closed instantly, we can't deal with it...yet. |
| 208 | - if ($matches[5] === '/') |
|
| 209 | - continue; |
|
| 210 | - else |
|
| 217 | + if ($matches[5] === '/') { |
|
| 218 | + continue; |
|
| 219 | + } else |
|
| 211 | 220 | { |
| 212 | 221 | // Get an array of styles that apply to this element. (The strtr is there to combat HTML generated by Word.) |
| 213 | 222 | $styles = explode(';', strtr($matches[3], array('"' => ''))); |
@@ -223,8 +232,9 @@ discard block |
||
| 223 | 232 | $clean_type_value_pair = strtolower(strtr(trim($type_value_pair), '=', ':')); |
| 224 | 233 | |
| 225 | 234 | // Something like 'font-weight: bold' is expected here. |
| 226 | - if (strpos($clean_type_value_pair, ':') === false) |
|
| 227 | - continue; |
|
| 235 | + if (strpos($clean_type_value_pair, ':') === false) { |
|
| 236 | + continue; |
|
| 237 | + } |
|
| 228 | 238 | |
| 229 | 239 | // Capture the elements of a single style item (e.g. 'font-weight' and 'bold'). |
| 230 | 240 | list ($style_type, $style_value) = explode(':', $type_value_pair); |
@@ -246,8 +256,7 @@ discard block |
||
| 246 | 256 | { |
| 247 | 257 | $curCloseTags .= '[/u]'; |
| 248 | 258 | $replacement .= '[u]'; |
| 249 | - } |
|
| 250 | - elseif ($style_value == 'line-through') |
|
| 259 | + } elseif ($style_value == 'line-through') |
|
| 251 | 260 | { |
| 252 | 261 | $curCloseTags .= '[/s]'; |
| 253 | 262 | $replacement .= '[s]'; |
@@ -259,13 +268,11 @@ discard block |
||
| 259 | 268 | { |
| 260 | 269 | $curCloseTags .= '[/left]'; |
| 261 | 270 | $replacement .= '[left]'; |
| 262 | - } |
|
| 263 | - elseif ($style_value == 'center') |
|
| 271 | + } elseif ($style_value == 'center') |
|
| 264 | 272 | { |
| 265 | 273 | $curCloseTags .= '[/center]'; |
| 266 | 274 | $replacement .= '[center]'; |
| 267 | - } |
|
| 268 | - elseif ($style_value == 'right') |
|
| 275 | + } elseif ($style_value == 'right') |
|
| 269 | 276 | { |
| 270 | 277 | $curCloseTags .= '[/right]'; |
| 271 | 278 | $replacement .= '[right]'; |
@@ -287,8 +294,9 @@ discard block |
||
| 287 | 294 | |
| 288 | 295 | case 'font-size': |
| 289 | 296 | // Sometimes people put decimals where decimals should not be. |
| 290 | - if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) |
|
| 291 | - $style_value = $dec_matches[1] . $dec_matches[2]; |
|
| 297 | + if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) { |
|
| 298 | + $style_value = $dec_matches[1] . $dec_matches[2]; |
|
| 299 | + } |
|
| 292 | 300 | |
| 293 | 301 | $curCloseTags .= '[/size]'; |
| 294 | 302 | $replacement .= '[size=' . $style_value . ']'; |
@@ -296,8 +304,9 @@ discard block |
||
| 296 | 304 | |
| 297 | 305 | case 'font-family': |
| 298 | 306 | // Only get the first freaking font if there's a list! |
| 299 | - if (strpos($style_value, ',') !== false) |
|
| 300 | - $style_value = substr($style_value, 0, strpos($style_value, ',')); |
|
| 307 | + if (strpos($style_value, ',') !== false) { |
|
| 308 | + $style_value = substr($style_value, 0, strpos($style_value, ',')); |
|
| 309 | + } |
|
| 301 | 310 | |
| 302 | 311 | $curCloseTags .= '[/font]'; |
| 303 | 312 | $replacement .= '[font=' . strtr($style_value, array("'" => '')) . ']'; |
@@ -306,13 +315,15 @@ discard block |
||
| 306 | 315 | // This is a hack for images with dimensions embedded. |
| 307 | 316 | case 'width': |
| 308 | 317 | case 'height': |
| 309 | - if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) |
|
| 310 | - $extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"'; |
|
| 318 | + if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) { |
|
| 319 | + $extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"'; |
|
| 320 | + } |
|
| 311 | 321 | break; |
| 312 | 322 | |
| 313 | 323 | case 'list-style-type': |
| 314 | - 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) |
|
| 315 | - $extra_attr .= ' listtype="' . $listType[0] . '"'; |
|
| 324 | + 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) { |
|
| 325 | + $extra_attr .= ' listtype="' . $listType[0] . '"'; |
|
| 326 | + } |
|
| 316 | 327 | break; |
| 317 | 328 | } |
| 318 | 329 | } |
@@ -325,18 +336,17 @@ discard block |
||
| 325 | 336 | } |
| 326 | 337 | |
| 327 | 338 | // If there's something that still needs closing, push it to the stack. |
| 328 | - if (!empty($curCloseTags)) |
|
| 329 | - array_push($stack, array( |
|
| 339 | + if (!empty($curCloseTags)) { |
|
| 340 | + array_push($stack, array( |
|
| 330 | 341 | 'element' => strtolower($curElement), |
| 331 | 342 | 'closeTags' => $curCloseTags |
| 332 | 343 | ) |
| 333 | 344 | ); |
| 334 | - elseif (!empty($extra_attr)) |
|
| 335 | - $replacement .= $precedingStyle . $extra_attr . $afterStyle; |
|
| 345 | + } elseif (!empty($extra_attr)) { |
|
| 346 | + $replacement .= $precedingStyle . $extra_attr . $afterStyle; |
|
| 347 | + } |
|
| 336 | 348 | } |
| 337 | - } |
|
| 338 | - |
|
| 339 | - elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1) |
|
| 349 | + } elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1) |
|
| 340 | 350 | { |
| 341 | 351 | // Is this the element that we've been waiting for to be closed? |
| 342 | 352 | if (!empty($stack) && strtolower($matches[1]) === $stack[count($stack) - 1]['element']) |
@@ -346,28 +356,32 @@ discard block |
||
| 346 | 356 | } |
| 347 | 357 | |
| 348 | 358 | // Must've been something else. |
| 349 | - else |
|
| 350 | - $replacement .= $part; |
|
| 359 | + else { |
|
| 360 | + $replacement .= $part; |
|
| 361 | + } |
|
| 351 | 362 | } |
| 352 | 363 | // In all other cases, just add the part to the replacement. |
| 353 | - else |
|
| 354 | - $replacement .= $part; |
|
| 364 | + else { |
|
| 365 | + $replacement .= $part; |
|
| 366 | + } |
|
| 355 | 367 | } |
| 356 | 368 | |
| 357 | 369 | // Now put back the replacement in the text. |
| 358 | 370 | $text = $replacement; |
| 359 | 371 | |
| 360 | 372 | // We are not finished yet, request more time. |
| 361 | - if (connection_aborted() && $context['server']['is_apache']) |
|
| 362 | - @apache_reset_timeout(); |
|
| 373 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
| 374 | + @apache_reset_timeout(); |
|
| 375 | + } |
|
| 363 | 376 | |
| 364 | 377 | // Let's pull out any legacy alignments. |
| 365 | 378 | while (preg_match('~<([A-Za-z]+)\s+[^<>]*?(align="*(left|center|right)"*)[^<>]*?(/?)>~i', $text, $matches) === 1) |
| 366 | 379 | { |
| 367 | 380 | // Find the position in the text of this tag over again. |
| 368 | 381 | $start_pos = strpos($text, $matches[0]); |
| 369 | - if ($start_pos === false) |
|
| 370 | - break; |
|
| 382 | + if ($start_pos === false) { |
|
| 383 | + break; |
|
| 384 | + } |
|
| 371 | 385 | |
| 372 | 386 | // End tag? |
| 373 | 387 | if ($matches[4] != '/' && strpos($text, '</' . $matches[1] . '>', $start_pos) !== false) |
@@ -382,8 +396,7 @@ discard block |
||
| 382 | 396 | |
| 383 | 397 | // Put the tags back into the body. |
| 384 | 398 | $text = substr($text, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($text, $end_pos); |
| 385 | - } |
|
| 386 | - else |
|
| 399 | + } else |
|
| 387 | 400 | { |
| 388 | 401 | // Just get rid of this evil tag. |
| 389 | 402 | $text = substr($text, 0, $start_pos) . substr($text, $start_pos + strlen($matches[0])); |
@@ -396,8 +409,9 @@ discard block |
||
| 396 | 409 | // Find the position of this again. |
| 397 | 410 | $start_pos = strpos($text, $matches[0]); |
| 398 | 411 | $end_pos = false; |
| 399 | - if ($start_pos === false) |
|
| 400 | - break; |
|
| 412 | + if ($start_pos === false) { |
|
| 413 | + break; |
|
| 414 | + } |
|
| 401 | 415 | |
| 402 | 416 | // This must have an end tag - and we must find the right one. |
| 403 | 417 | $lower_text = strtolower($text); |
@@ -430,8 +444,9 @@ discard block |
||
| 430 | 444 | break; |
| 431 | 445 | } |
| 432 | 446 | } |
| 433 | - if ($end_pos === false) |
|
| 434 | - break; |
|
| 447 | + if ($end_pos === false) { |
|
| 448 | + break; |
|
| 449 | + } |
|
| 435 | 450 | |
| 436 | 451 | // Now work out what the attributes are. |
| 437 | 452 | $attribs = fetchTagAttributes($matches[1]); |
@@ -445,11 +460,11 @@ discard block |
||
| 445 | 460 | $v = (int) trim($v); |
| 446 | 461 | $v = empty($v) ? 1 : $v; |
| 447 | 462 | $tags[] = array('[size=' . $sizes_equivalence[$v] . ']', '[/size]'); |
| 463 | + } elseif ($s == 'face') { |
|
| 464 | + $tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]'); |
|
| 465 | + } elseif ($s == 'color') { |
|
| 466 | + $tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]'); |
|
| 448 | 467 | } |
| 449 | - elseif ($s == 'face') |
|
| 450 | - $tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]'); |
|
| 451 | - elseif ($s == 'color') |
|
| 452 | - $tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]'); |
|
| 453 | 468 | } |
| 454 | 469 | |
| 455 | 470 | // As before add in our tags. |
@@ -457,8 +472,9 @@ discard block |
||
| 457 | 472 | foreach ($tags as $tag) |
| 458 | 473 | { |
| 459 | 474 | $before .= $tag[0]; |
| 460 | - if (isset($tag[1])) |
|
| 461 | - $after = $tag[1] . $after; |
|
| 475 | + if (isset($tag[1])) { |
|
| 476 | + $after = $tag[1] . $after; |
|
| 477 | + } |
|
| 462 | 478 | } |
| 463 | 479 | |
| 464 | 480 | // Remove the tag so it's never checked again. |
@@ -469,8 +485,9 @@ discard block |
||
| 469 | 485 | } |
| 470 | 486 | |
| 471 | 487 | // Almost there, just a little more time. |
| 472 | - if (connection_aborted() && $context['server']['is_apache']) |
|
| 473 | - @apache_reset_timeout(); |
|
| 488 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
| 489 | + @apache_reset_timeout(); |
|
| 490 | + } |
|
| 474 | 491 | |
| 475 | 492 | if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $text, null, PREG_SPLIT_DELIM_CAPTURE)) > 1) |
| 476 | 493 | { |
@@ -526,12 +543,13 @@ discard block |
||
| 526 | 543 | { |
| 527 | 544 | $inList = true; |
| 528 | 545 | |
| 529 | - if ($tag === 'ol') |
|
| 530 | - $listType = 'decimal'; |
|
| 531 | - elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) |
|
| 532 | - $listType = $listTypeMapping[$match[1]]; |
|
| 533 | - else |
|
| 534 | - $listType = null; |
|
| 546 | + if ($tag === 'ol') { |
|
| 547 | + $listType = 'decimal'; |
|
| 548 | + } elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) { |
|
| 549 | + $listType = $listTypeMapping[$match[1]]; |
|
| 550 | + } else { |
|
| 551 | + $listType = null; |
|
| 552 | + } |
|
| 535 | 553 | |
| 536 | 554 | $listDepth++; |
| 537 | 555 | |
@@ -595,9 +613,7 @@ discard block |
||
| 595 | 613 | $parts[$i + 1] = ''; |
| 596 | 614 | $parts[$i + 2] = str_repeat("\t", $listDepth) . '[/list]'; |
| 597 | 615 | $parts[$i + 3] = ''; |
| 598 | - } |
|
| 599 | - |
|
| 600 | - else |
|
| 616 | + } else |
|
| 601 | 617 | { |
| 602 | 618 | // We're in a list item. |
| 603 | 619 | if ($listDepth > 0) |
@@ -634,9 +650,7 @@ discard block |
||
| 634 | 650 | $parts[$i + 1] = ''; |
| 635 | 651 | $parts[$i + 2] = ''; |
| 636 | 652 | $parts[$i + 3] = ''; |
| 637 | - } |
|
| 638 | - |
|
| 639 | - else |
|
| 653 | + } else |
|
| 640 | 654 | { |
| 641 | 655 | // Remove the trailing breaks from the list item. |
| 642 | 656 | $parts[$i] = preg_replace('~\s*<br\s*' . '/?' . '>\s*$~', '', $parts[$i]); |
@@ -674,8 +688,9 @@ discard block |
||
| 674 | 688 | $text .= str_repeat("\t", $listDepth) . '[/list]'; |
| 675 | 689 | } |
| 676 | 690 | |
| 677 | - for ($i = $listDepth; $i > 0; $i--) |
|
| 678 | - $text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]'; |
|
| 691 | + for ($i = $listDepth; $i > 0; $i--) { |
|
| 692 | + $text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]'; |
|
| 693 | + } |
|
| 679 | 694 | |
| 680 | 695 | } |
| 681 | 696 | |
@@ -684,8 +699,9 @@ discard block |
||
| 684 | 699 | { |
| 685 | 700 | // Find the position of the image. |
| 686 | 701 | $start_pos = strpos($text, $matches[0]); |
| 687 | - if ($start_pos === false) |
|
| 688 | - break; |
|
| 702 | + if ($start_pos === false) { |
|
| 703 | + break; |
|
| 704 | + } |
|
| 689 | 705 | $end_pos = $start_pos + strlen($matches[0]); |
| 690 | 706 | |
| 691 | 707 | $params = ''; |
@@ -694,12 +710,13 @@ discard block |
||
| 694 | 710 | $attrs = fetchTagAttributes($matches[1]); |
| 695 | 711 | foreach ($attrs as $attrib => $value) |
| 696 | 712 | { |
| 697 | - if (in_array($attrib, array('width', 'height'))) |
|
| 698 | - $params .= ' ' . $attrib . '=' . (int) $value; |
|
| 699 | - elseif ($attrib == 'alt' && trim($value) != '') |
|
| 700 | - $params .= ' alt=' . trim($value); |
|
| 701 | - elseif ($attrib == 'src') |
|
| 702 | - $src = trim($value); |
|
| 713 | + if (in_array($attrib, array('width', 'height'))) { |
|
| 714 | + $params .= ' ' . $attrib . '=' . (int) $value; |
|
| 715 | + } elseif ($attrib == 'alt' && trim($value) != '') { |
|
| 716 | + $params .= ' alt=' . trim($value); |
|
| 717 | + } elseif ($attrib == 'src') { |
|
| 718 | + $src = trim($value); |
|
| 719 | + } |
|
| 703 | 720 | } |
| 704 | 721 | |
| 705 | 722 | $tag = ''; |
@@ -710,10 +727,11 @@ discard block |
||
| 710 | 727 | { |
| 711 | 728 | $baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']); |
| 712 | 729 | |
| 713 | - if (substr($src, 0, 1) === '/') |
|
| 714 | - $src = $baseURL . $src; |
|
| 715 | - else |
|
| 716 | - $src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src; |
|
| 730 | + if (substr($src, 0, 1) === '/') { |
|
| 731 | + $src = $baseURL . $src; |
|
| 732 | + } else { |
|
| 733 | + $src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src; |
|
| 734 | + } |
|
| 717 | 735 | } |
| 718 | 736 | |
| 719 | 737 | $tag = '[img' . $params . ']' . $src . '[/img]'; |
@@ -891,20 +909,23 @@ discard block |
||
| 891 | 909 | }, |
| 892 | 910 | ); |
| 893 | 911 | |
| 894 | - foreach ($tags as $tag => $replace) |
|
| 895 | - $text = preg_replace_callback($tag, $replace, $text); |
|
| 912 | + foreach ($tags as $tag => $replace) { |
|
| 913 | + $text = preg_replace_callback($tag, $replace, $text); |
|
| 914 | + } |
|
| 896 | 915 | |
| 897 | 916 | // Please give us just a little more time. |
| 898 | - if (connection_aborted() && $context['server']['is_apache']) |
|
| 899 | - @apache_reset_timeout(); |
|
| 917 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
| 918 | + @apache_reset_timeout(); |
|
| 919 | + } |
|
| 900 | 920 | |
| 901 | 921 | // What about URL's - the pain in the ass of the tag world. |
| 902 | 922 | while (preg_match('~<a\s+([^<>]*)>([^<>]*)</a>~i', $text, $matches) === 1) |
| 903 | 923 | { |
| 904 | 924 | // Find the position of the URL. |
| 905 | 925 | $start_pos = strpos($text, $matches[0]); |
| 906 | - if ($start_pos === false) |
|
| 907 | - break; |
|
| 926 | + if ($start_pos === false) { |
|
| 927 | + break; |
|
| 928 | + } |
|
| 908 | 929 | $end_pos = $start_pos + strlen($matches[0]); |
| 909 | 930 | |
| 910 | 931 | $tag_type = 'url'; |
@@ -918,8 +939,9 @@ discard block |
||
| 918 | 939 | $href = trim($value); |
| 919 | 940 | |
| 920 | 941 | // Are we dealing with an FTP link? |
| 921 | - if (preg_match('~^ftps?://~', $href) === 1) |
|
| 922 | - $tag_type = 'ftp'; |
|
| 942 | + if (preg_match('~^ftps?://~', $href) === 1) { |
|
| 943 | + $tag_type = 'ftp'; |
|
| 944 | + } |
|
| 923 | 945 | |
| 924 | 946 | // Or is this a link to an email address? |
| 925 | 947 | elseif (substr($href, 0, 7) == 'mailto:') |
@@ -933,28 +955,31 @@ discard block |
||
| 933 | 955 | { |
| 934 | 956 | $baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']); |
| 935 | 957 | |
| 936 | - if (substr($href, 0, 1) === '/') |
|
| 937 | - $href = $baseURL . $href; |
|
| 938 | - else |
|
| 939 | - $href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href; |
|
| 958 | + if (substr($href, 0, 1) === '/') { |
|
| 959 | + $href = $baseURL . $href; |
|
| 960 | + } else { |
|
| 961 | + $href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href; |
|
| 962 | + } |
|
| 940 | 963 | } |
| 941 | 964 | } |
| 942 | 965 | |
| 943 | 966 | // External URL? |
| 944 | 967 | if ($attrib == 'target' && $tag_type == 'url') |
| 945 | 968 | { |
| 946 | - if (trim($value) == '_blank') |
|
| 947 | - $tag_type == 'iurl'; |
|
| 969 | + if (trim($value) == '_blank') { |
|
| 970 | + $tag_type == 'iurl'; |
|
| 971 | + } |
|
| 948 | 972 | } |
| 949 | 973 | } |
| 950 | 974 | |
| 951 | 975 | $tag = ''; |
| 952 | 976 | if ($href != '') |
| 953 | 977 | { |
| 954 | - if ($matches[2] == $href) |
|
| 955 | - $tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']'; |
|
| 956 | - else |
|
| 957 | - $tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']'; |
|
| 978 | + if ($matches[2] == $href) { |
|
| 979 | + $tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']'; |
|
| 980 | + } else { |
|
| 981 | + $tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']'; |
|
| 982 | + } |
|
| 958 | 983 | } |
| 959 | 984 | |
| 960 | 985 | // Replace the tag |
@@ -993,17 +1018,18 @@ discard block |
||
| 993 | 1018 | // We're either moving from the key to the attribute or we're in a string and this is fine. |
| 994 | 1019 | if ($text[$i] == '=') |
| 995 | 1020 | { |
| 996 | - if ($tag_state == 0) |
|
| 997 | - $tag_state = 1; |
|
| 998 | - elseif ($tag_state == 2) |
|
| 999 | - $value .= '='; |
|
| 1021 | + if ($tag_state == 0) { |
|
| 1022 | + $tag_state = 1; |
|
| 1023 | + } elseif ($tag_state == 2) { |
|
| 1024 | + $value .= '='; |
|
| 1025 | + } |
|
| 1000 | 1026 | } |
| 1001 | 1027 | // A space is either moving from an attribute back to a potential key or in a string is fine. |
| 1002 | 1028 | elseif ($text[$i] == ' ') |
| 1003 | 1029 | { |
| 1004 | - if ($tag_state == 2) |
|
| 1005 | - $value .= ' '; |
|
| 1006 | - elseif ($tag_state == 1) |
|
| 1030 | + if ($tag_state == 2) { |
|
| 1031 | + $value .= ' '; |
|
| 1032 | + } elseif ($tag_state == 1) |
|
| 1007 | 1033 | { |
| 1008 | 1034 | $attribs[$key] = $value; |
| 1009 | 1035 | $key = $value = ''; |
@@ -1014,24 +1040,27 @@ discard block |
||
| 1014 | 1040 | elseif ($text[$i] == '"') |
| 1015 | 1041 | { |
| 1016 | 1042 | // Must be either going into or out of a string. |
| 1017 | - if ($tag_state == 1) |
|
| 1018 | - $tag_state = 2; |
|
| 1019 | - else |
|
| 1020 | - $tag_state = 1; |
|
| 1043 | + if ($tag_state == 1) { |
|
| 1044 | + $tag_state = 2; |
|
| 1045 | + } else { |
|
| 1046 | + $tag_state = 1; |
|
| 1047 | + } |
|
| 1021 | 1048 | } |
| 1022 | 1049 | // Otherwise it's fine. |
| 1023 | 1050 | else |
| 1024 | 1051 | { |
| 1025 | - if ($tag_state == 0) |
|
| 1026 | - $key .= $text[$i]; |
|
| 1027 | - else |
|
| 1028 | - $value .= $text[$i]; |
|
| 1052 | + if ($tag_state == 0) { |
|
| 1053 | + $key .= $text[$i]; |
|
| 1054 | + } else { |
|
| 1055 | + $value .= $text[$i]; |
|
| 1056 | + } |
|
| 1029 | 1057 | } |
| 1030 | 1058 | } |
| 1031 | 1059 | |
| 1032 | 1060 | // Anything left? |
| 1033 | - if ($key != '' && $value != '') |
|
| 1034 | - $attribs[$key] = $value; |
|
| 1061 | + if ($key != '' && $value != '') { |
|
| 1062 | + $attribs[$key] = $value; |
|
| 1063 | + } |
|
| 1035 | 1064 | |
| 1036 | 1065 | return $attribs; |
| 1037 | 1066 | } |
@@ -1047,15 +1076,17 @@ discard block |
||
| 1047 | 1076 | global $modSettings; |
| 1048 | 1077 | |
| 1049 | 1078 | // Don't care about the texts that are too short. |
| 1050 | - if (strlen($text) < 3) |
|
| 1051 | - return $text; |
|
| 1079 | + if (strlen($text) < 3) { |
|
| 1080 | + return $text; |
|
| 1081 | + } |
|
| 1052 | 1082 | |
| 1053 | 1083 | // A list of tags that's disabled by the admin. |
| 1054 | 1084 | $disabled = empty($modSettings['disabledBBC']) ? array() : array_flip(explode(',', strtolower($modSettings['disabledBBC']))); |
| 1055 | 1085 | |
| 1056 | 1086 | // Add flash if it's disabled as embedded tag. |
| 1057 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
| 1058 | - $disabled['flash'] = true; |
|
| 1087 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
| 1088 | + $disabled['flash'] = true; |
|
| 1089 | + } |
|
| 1059 | 1090 | |
| 1060 | 1091 | // Get a list of all the tags that are not disabled. |
| 1061 | 1092 | $all_tags = parse_bbc(false); |
@@ -1063,10 +1094,12 @@ discard block |
||
| 1063 | 1094 | $self_closing_tags = array(); |
| 1064 | 1095 | foreach ($all_tags as $tag) |
| 1065 | 1096 | { |
| 1066 | - if (!isset($disabled[$tag['tag']])) |
|
| 1067 | - $valid_tags[$tag['tag']] = !empty($tag['block_level']); |
|
| 1068 | - if (isset($tag['type']) && $tag['type'] == 'closed') |
|
| 1069 | - $self_closing_tags[] = $tag['tag']; |
|
| 1097 | + if (!isset($disabled[$tag['tag']])) { |
|
| 1098 | + $valid_tags[$tag['tag']] = !empty($tag['block_level']); |
|
| 1099 | + } |
|
| 1100 | + if (isset($tag['type']) && $tag['type'] == 'closed') { |
|
| 1101 | + $self_closing_tags[] = $tag['tag']; |
|
| 1102 | + } |
|
| 1070 | 1103 | } |
| 1071 | 1104 | |
| 1072 | 1105 | // 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! |
@@ -1093,16 +1126,19 @@ discard block |
||
| 1093 | 1126 | $tagName = substr($match, $isClosingTag ? 2 : 1, -1); |
| 1094 | 1127 | |
| 1095 | 1128 | // We're closing the exact same tag that we opened. |
| 1096 | - if ($isClosingTag && $insideTag === $tagName) |
|
| 1097 | - $insideTag = null; |
|
| 1129 | + if ($isClosingTag && $insideTag === $tagName) { |
|
| 1130 | + $insideTag = null; |
|
| 1131 | + } |
|
| 1098 | 1132 | |
| 1099 | 1133 | // We're opening a tag and we're not yet inside one either |
| 1100 | - elseif (!$isClosingTag && $insideTag === null) |
|
| 1101 | - $insideTag = $tagName; |
|
| 1134 | + elseif (!$isClosingTag && $insideTag === null) { |
|
| 1135 | + $insideTag = $tagName; |
|
| 1136 | + } |
|
| 1102 | 1137 | |
| 1103 | 1138 | // In all other cases, this tag must be invalid |
| 1104 | - else |
|
| 1105 | - unset($matches[$i]); |
|
| 1139 | + else { |
|
| 1140 | + unset($matches[$i]); |
|
| 1141 | + } |
|
| 1106 | 1142 | } |
| 1107 | 1143 | |
| 1108 | 1144 | // The next one is gonna be the other one. |
@@ -1110,8 +1146,9 @@ discard block |
||
| 1110 | 1146 | } |
| 1111 | 1147 | |
| 1112 | 1148 | // We're still inside a tag and had no chance for closure? |
| 1113 | - if ($insideTag !== null) |
|
| 1114 | - $matches[] = '[/' . $insideTag . ']'; |
|
| 1149 | + if ($insideTag !== null) { |
|
| 1150 | + $matches[] = '[/' . $insideTag . ']'; |
|
| 1151 | + } |
|
| 1115 | 1152 | |
| 1116 | 1153 | // And a complete text string again. |
| 1117 | 1154 | $text = implode('', $matches); |
@@ -1120,8 +1157,9 @@ discard block |
||
| 1120 | 1157 | // Quickly remove any tags which are back to back. |
| 1121 | 1158 | $backToBackPattern = '~\\[(' . implode('|', array_diff(array_keys($valid_tags), array('td', 'anchor'))) . ')[^<>\\[\\]]*\\]\s*\\[/\\1\\]~'; |
| 1122 | 1159 | $lastlen = 0; |
| 1123 | - while (strlen($text) !== $lastlen) |
|
| 1124 | - $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
| 1160 | + while (strlen($text) !== $lastlen) { |
|
| 1161 | + $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
| 1162 | + } |
|
| 1125 | 1163 | |
| 1126 | 1164 | // Need to sort the tags my name length. |
| 1127 | 1165 | uksort($valid_tags, 'sort_array_length'); |
@@ -1158,8 +1196,9 @@ discard block |
||
| 1158 | 1196 | $isCompetingTag = in_array($tag, $competing_tags); |
| 1159 | 1197 | |
| 1160 | 1198 | // Check if this might be one of those cleaned out tags. |
| 1161 | - if ($tag === '') |
|
| 1162 | - continue; |
|
| 1199 | + if ($tag === '') { |
|
| 1200 | + continue; |
|
| 1201 | + } |
|
| 1163 | 1202 | |
| 1164 | 1203 | // Special case: inside [code] blocks any code is left untouched. |
| 1165 | 1204 | elseif ($tag === 'code') |
@@ -1170,8 +1209,9 @@ discard block |
||
| 1170 | 1209 | $inCode = false; |
| 1171 | 1210 | |
| 1172 | 1211 | // Reopen tags that were closed before the code block. |
| 1173 | - if (!empty($inlineElements)) |
|
| 1174 | - $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
| 1212 | + if (!empty($inlineElements)) { |
|
| 1213 | + $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
| 1214 | + } |
|
| 1175 | 1215 | } |
| 1176 | 1216 | |
| 1177 | 1217 | // We're outside a coding and nobbc block and opening it. |
@@ -1200,8 +1240,9 @@ discard block |
||
| 1200 | 1240 | $inNoBbc = false; |
| 1201 | 1241 | |
| 1202 | 1242 | // Some inline elements might've been closed that need reopening. |
| 1203 | - if (!empty($inlineElements)) |
|
| 1204 | - $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
| 1243 | + if (!empty($inlineElements)) { |
|
| 1244 | + $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
| 1245 | + } |
|
| 1205 | 1246 | } |
| 1206 | 1247 | |
| 1207 | 1248 | // We're outside a nobbc and coding block and opening it. |
@@ -1221,8 +1262,9 @@ discard block |
||
| 1221 | 1262 | } |
| 1222 | 1263 | |
| 1223 | 1264 | // So, we're inside one of the special blocks: ignore any tag. |
| 1224 | - elseif ($inCode || $inNoBbc) |
|
| 1225 | - continue; |
|
| 1265 | + elseif ($inCode || $inNoBbc) { |
|
| 1266 | + continue; |
|
| 1267 | + } |
|
| 1226 | 1268 | |
| 1227 | 1269 | // We're dealing with an opening tag. |
| 1228 | 1270 | if ($isOpeningTag) |
@@ -1263,8 +1305,9 @@ discard block |
||
| 1263 | 1305 | if ($parts[$j + 3] === $tag) |
| 1264 | 1306 | { |
| 1265 | 1307 | // If it's an opening tag, increase the level. |
| 1266 | - if ($parts[$j + 2] === '') |
|
| 1267 | - $curLevel++; |
|
| 1308 | + if ($parts[$j + 2] === '') { |
|
| 1309 | + $curLevel++; |
|
| 1310 | + } |
|
| 1268 | 1311 | |
| 1269 | 1312 | // A closing tag, decrease the level. |
| 1270 | 1313 | else |
@@ -1287,13 +1330,15 @@ discard block |
||
| 1287 | 1330 | { |
| 1288 | 1331 | if ($isCompetingTag) |
| 1289 | 1332 | { |
| 1290 | - if (!isset($competingElements[$tag])) |
|
| 1291 | - $competingElements[$tag] = array(); |
|
| 1333 | + if (!isset($competingElements[$tag])) { |
|
| 1334 | + $competingElements[$tag] = array(); |
|
| 1335 | + } |
|
| 1292 | 1336 | |
| 1293 | 1337 | $competingElements[$tag][] = $parts[$i + 4]; |
| 1294 | 1338 | |
| 1295 | - if (count($competingElements[$tag]) > 1) |
|
| 1296 | - $parts[$i] .= '[/' . $tag . ']'; |
|
| 1339 | + if (count($competingElements[$tag]) > 1) { |
|
| 1340 | + $parts[$i] .= '[/' . $tag . ']'; |
|
| 1341 | + } |
|
| 1297 | 1342 | } |
| 1298 | 1343 | |
| 1299 | 1344 | $inlineElements[$elementContent] = $tag; |
@@ -1314,15 +1359,17 @@ discard block |
||
| 1314 | 1359 | $addClosingTags = array(); |
| 1315 | 1360 | while ($element = array_pop($blockElements)) |
| 1316 | 1361 | { |
| 1317 | - if ($element === $tag) |
|
| 1318 | - break; |
|
| 1362 | + if ($element === $tag) { |
|
| 1363 | + break; |
|
| 1364 | + } |
|
| 1319 | 1365 | |
| 1320 | 1366 | // Still a block tag was open not equal to this tag. |
| 1321 | 1367 | $addClosingTags[] = $element['type']; |
| 1322 | 1368 | } |
| 1323 | 1369 | |
| 1324 | - if (!empty($addClosingTags)) |
|
| 1325 | - $parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1]; |
|
| 1370 | + if (!empty($addClosingTags)) { |
|
| 1371 | + $parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1]; |
|
| 1372 | + } |
|
| 1326 | 1373 | |
| 1327 | 1374 | // Apparently the closing tag was not found on the stack. |
| 1328 | 1375 | if (!is_string($element) || $element !== $tag) |
@@ -1332,8 +1379,7 @@ discard block |
||
| 1332 | 1379 | $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
| 1333 | 1380 | continue; |
| 1334 | 1381 | } |
| 1335 | - } |
|
| 1336 | - else |
|
| 1382 | + } else |
|
| 1337 | 1383 | { |
| 1338 | 1384 | // Get rid of this closing tag! |
| 1339 | 1385 | $parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
@@ -1362,53 +1408,62 @@ discard block |
||
| 1362 | 1408 | unset($inlineElements[$tagContentToBeClosed]); |
| 1363 | 1409 | |
| 1364 | 1410 | // Was this the tag we were looking for? |
| 1365 | - if ($tagToBeClosed === $tag) |
|
| 1366 | - break; |
|
| 1411 | + if ($tagToBeClosed === $tag) { |
|
| 1412 | + break; |
|
| 1413 | + } |
|
| 1367 | 1414 | |
| 1368 | 1415 | // Nope, close it and look further! |
| 1369 | - else |
|
| 1370 | - $parts[$i] .= '[/' . $tagToBeClosed . ']'; |
|
| 1416 | + else { |
|
| 1417 | + $parts[$i] .= '[/' . $tagToBeClosed . ']'; |
|
| 1418 | + } |
|
| 1371 | 1419 | } |
| 1372 | 1420 | |
| 1373 | 1421 | if ($isCompetingTag && !empty($competingElements[$tag])) |
| 1374 | 1422 | { |
| 1375 | 1423 | array_pop($competingElements[$tag]); |
| 1376 | 1424 | |
| 1377 | - if (count($competingElements[$tag]) > 0) |
|
| 1378 | - $parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5]; |
|
| 1425 | + if (count($competingElements[$tag]) > 0) { |
|
| 1426 | + $parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5]; |
|
| 1427 | + } |
|
| 1379 | 1428 | } |
| 1380 | 1429 | } |
| 1381 | 1430 | |
| 1382 | 1431 | // Unexpected closing tag, ex-ter-mi-nate. |
| 1383 | - else |
|
| 1384 | - $parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
|
| 1432 | + else { |
|
| 1433 | + $parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
|
| 1434 | + } |
|
| 1385 | 1435 | } |
| 1386 | 1436 | } |
| 1387 | 1437 | } |
| 1388 | 1438 | |
| 1389 | 1439 | // Close the code tags. |
| 1390 | - if ($inCode) |
|
| 1391 | - $parts[$i] .= '[/code]'; |
|
| 1440 | + if ($inCode) { |
|
| 1441 | + $parts[$i] .= '[/code]'; |
|
| 1442 | + } |
|
| 1392 | 1443 | |
| 1393 | 1444 | // The same for nobbc tags. |
| 1394 | - elseif ($inNoBbc) |
|
| 1395 | - $parts[$i] .= '[/nobbc]'; |
|
| 1445 | + elseif ($inNoBbc) { |
|
| 1446 | + $parts[$i] .= '[/nobbc]'; |
|
| 1447 | + } |
|
| 1396 | 1448 | |
| 1397 | 1449 | // Still inline tags left unclosed? Close them now, better late than never. |
| 1398 | - elseif (!empty($inlineElements)) |
|
| 1399 | - $parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']'; |
|
| 1450 | + elseif (!empty($inlineElements)) { |
|
| 1451 | + $parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']'; |
|
| 1452 | + } |
|
| 1400 | 1453 | |
| 1401 | 1454 | // Now close the block elements. |
| 1402 | - if (!empty($blockElements)) |
|
| 1403 | - $parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']'; |
|
| 1455 | + if (!empty($blockElements)) { |
|
| 1456 | + $parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']'; |
|
| 1457 | + } |
|
| 1404 | 1458 | |
| 1405 | 1459 | $text = implode('', $parts); |
| 1406 | 1460 | } |
| 1407 | 1461 | |
| 1408 | 1462 | // Final clean up of back to back tags. |
| 1409 | 1463 | $lastlen = 0; |
| 1410 | - while (strlen($text) !== $lastlen) |
|
| 1411 | - $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
| 1464 | + while (strlen($text) !== $lastlen) { |
|
| 1465 | + $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
| 1466 | + } |
|
| 1412 | 1467 | |
| 1413 | 1468 | return $text; |
| 1414 | 1469 | } |
@@ -1437,22 +1492,25 @@ discard block |
||
| 1437 | 1492 | $context['template_layers'] = array(); |
| 1438 | 1493 | // Lets make sure we aren't going to output anything nasty. |
| 1439 | 1494 | @ob_end_clean(); |
| 1440 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
| 1441 | - @ob_start('ob_gzhandler'); |
|
| 1442 | - else |
|
| 1443 | - @ob_start(); |
|
| 1495 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
| 1496 | + @ob_start('ob_gzhandler'); |
|
| 1497 | + } else { |
|
| 1498 | + @ob_start(); |
|
| 1499 | + } |
|
| 1444 | 1500 | |
| 1445 | 1501 | // If we don't have any locale better avoid broken js |
| 1446 | - if (empty($txt['lang_locale'])) |
|
| 1447 | - die(); |
|
| 1502 | + if (empty($txt['lang_locale'])) { |
|
| 1503 | + die(); |
|
| 1504 | + } |
|
| 1448 | 1505 | |
| 1449 | 1506 | $file_data = '(function ($) { |
| 1450 | 1507 | \'use strict\'; |
| 1451 | 1508 | |
| 1452 | 1509 | $.sceditor.locale[' . javaScriptEscape($txt['lang_locale']) . '] = {'; |
| 1453 | - foreach ($editortxt as $key => $val) |
|
| 1454 | - $file_data .= ' |
|
| 1510 | + foreach ($editortxt as $key => $val) { |
|
| 1511 | + $file_data .= ' |
|
| 1455 | 1512 | ' . javaScriptEscape($key) . ': ' . javaScriptEscape($val) . ','; |
| 1513 | + } |
|
| 1456 | 1514 | |
| 1457 | 1515 | $file_data .= ' |
| 1458 | 1516 | dateFormat: "day.month.year" |
@@ -1520,8 +1578,9 @@ discard block |
||
| 1520 | 1578 | ) |
| 1521 | 1579 | ); |
| 1522 | 1580 | $icon_data = array(); |
| 1523 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1524 | - $icon_data[] = $row; |
|
| 1581 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1582 | + $icon_data[] = $row; |
|
| 1583 | + } |
|
| 1525 | 1584 | $smcFunc['db_free_result']($request); |
| 1526 | 1585 | |
| 1527 | 1586 | $icons = array(); |
@@ -1536,9 +1595,9 @@ discard block |
||
| 1536 | 1595 | } |
| 1537 | 1596 | |
| 1538 | 1597 | cache_put_data('posting_icons-' . $board_id, $icons, 480); |
| 1598 | + } else { |
|
| 1599 | + $icons = $temp; |
|
| 1539 | 1600 | } |
| 1540 | - else |
|
| 1541 | - $icons = $temp; |
|
| 1542 | 1601 | } |
| 1543 | 1602 | call_integration_hook('integrate_load_message_icons', array(&$icons)); |
| 1544 | 1603 | |
@@ -1579,8 +1638,9 @@ discard block |
||
| 1579 | 1638 | { |
| 1580 | 1639 | // Some general stuff. |
| 1581 | 1640 | $settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set']; |
| 1582 | - if (!empty($context['drafts_autosave'])) |
|
| 1583 | - $context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000; |
|
| 1641 | + if (!empty($context['drafts_autosave'])) { |
|
| 1642 | + $context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000; |
|
| 1643 | + } |
|
| 1584 | 1644 | |
| 1585 | 1645 | // This really has some WYSIWYG stuff. |
| 1586 | 1646 | loadCSSFile('jquery.sceditor.css', array('force_current' => false, 'validate' => true), 'smf_jquery_sceditor'); |
@@ -1596,8 +1656,9 @@ discard block |
||
| 1596 | 1656 | var bbc_quote = \'' . addcslashes($txt['quote'], "'") . '\'; |
| 1597 | 1657 | var bbc_search_on = \'' . addcslashes($txt['search_on'], "'") . '\';'); |
| 1598 | 1658 | // editor language file |
| 1599 | - if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') |
|
| 1600 | - loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language'); |
|
| 1659 | + if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') { |
|
| 1660 | + loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language'); |
|
| 1661 | + } |
|
| 1601 | 1662 | |
| 1602 | 1663 | $context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) ? '_drafts' : '') . (stripos($_SERVER['HTTP_USER_AGENT'], 'Macintosh') !== false ? '_mac' : (isBrowser('is_firefox') ? '_firefox' : ''))]; |
| 1603 | 1664 | $context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv')))); |
@@ -1606,11 +1667,12 @@ discard block |
||
| 1606 | 1667 | loadJavaScriptFile('spellcheck.js', array(), 'smf_spellcheck'); |
| 1607 | 1668 | |
| 1608 | 1669 | // Some hidden information is needed in order to make the spell checking work. |
| 1609 | - if (!isset($_REQUEST['xml'])) |
|
| 1610 | - $context['insert_after_template'] .= ' |
|
| 1670 | + if (!isset($_REQUEST['xml'])) { |
|
| 1671 | + $context['insert_after_template'] .= ' |
|
| 1611 | 1672 | <form name="spell_form" id="spell_form" method="post" accept-charset="' . $context['character_set'] . '" target="spellWindow" action="' . $scripturl . '?action=spellcheck"> |
| 1612 | 1673 | <input type="hidden" name="spellstring" value=""> |
| 1613 | 1674 | </form>'; |
| 1675 | + } |
|
| 1614 | 1676 | } |
| 1615 | 1677 | } |
| 1616 | 1678 | |
@@ -1776,10 +1838,12 @@ discard block |
||
| 1776 | 1838 | |
| 1777 | 1839 | // Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this. |
| 1778 | 1840 | $disabled_tags = array(); |
| 1779 | - if (!empty($modSettings['disabledBBC'])) |
|
| 1780 | - $disabled_tags = explode(',', $modSettings['disabledBBC']); |
|
| 1781 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
| 1782 | - $disabled_tags[] = 'flash'; |
|
| 1841 | + if (!empty($modSettings['disabledBBC'])) { |
|
| 1842 | + $disabled_tags = explode(',', $modSettings['disabledBBC']); |
|
| 1843 | + } |
|
| 1844 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
| 1845 | + $disabled_tags[] = 'flash'; |
|
| 1846 | + } |
|
| 1783 | 1847 | |
| 1784 | 1848 | foreach ($disabled_tags as $tag) |
| 1785 | 1849 | { |
@@ -1789,9 +1853,10 @@ discard block |
||
| 1789 | 1853 | $context['disabled_tags']['orderedlist'] = true; |
| 1790 | 1854 | } |
| 1791 | 1855 | |
| 1792 | - foreach ($editor_tag_map as $thisTag => $tagNameBBC) |
|
| 1793 | - if ($tag === $thisTag) |
|
| 1856 | + foreach ($editor_tag_map as $thisTag => $tagNameBBC) { |
|
| 1857 | + if ($tag === $thisTag) |
|
| 1794 | 1858 | $context['disabled_tags'][$tagNameBBC] = true; |
| 1859 | + } |
|
| 1795 | 1860 | |
| 1796 | 1861 | $context['disabled_tags'][trim($tag)] = true; |
| 1797 | 1862 | } |
@@ -1801,19 +1866,21 @@ discard block |
||
| 1801 | 1866 | $context['bbc_toolbar'] = array(); |
| 1802 | 1867 | foreach ($context['bbc_tags'] as $row => $tagRow) |
| 1803 | 1868 | { |
| 1804 | - if (!isset($context['bbc_toolbar'][$row])) |
|
| 1805 | - $context['bbc_toolbar'][$row] = array(); |
|
| 1869 | + if (!isset($context['bbc_toolbar'][$row])) { |
|
| 1870 | + $context['bbc_toolbar'][$row] = array(); |
|
| 1871 | + } |
|
| 1806 | 1872 | $tagsRow = array(); |
| 1807 | 1873 | foreach ($tagRow as $tag) |
| 1808 | 1874 | { |
| 1809 | 1875 | if ((!empty($tag['code'])) && empty($context['disabled_tags'][$tag['code']])) |
| 1810 | 1876 | { |
| 1811 | 1877 | $tagsRow[] = $tag['code']; |
| 1812 | - if (isset($tag['image'])) |
|
| 1813 | - $bbcodes_styles .= ' |
|
| 1878 | + if (isset($tag['image'])) { |
|
| 1879 | + $bbcodes_styles .= ' |
|
| 1814 | 1880 | .sceditor-button-' . $tag['code'] . ' div { |
| 1815 | 1881 | background: url(\'' . $settings['default_theme_url'] . '/images/bbc/' . $tag['image'] . '.png\'); |
| 1816 | 1882 | }'; |
| 1883 | + } |
|
| 1817 | 1884 | if (isset($tag['before'])) |
| 1818 | 1885 | { |
| 1819 | 1886 | $context['bbcodes_handlers'] .= ' |
@@ -1827,8 +1894,7 @@ discard block |
||
| 1827 | 1894 | });'; |
| 1828 | 1895 | } |
| 1829 | 1896 | |
| 1830 | - } |
|
| 1831 | - else |
|
| 1897 | + } else |
|
| 1832 | 1898 | { |
| 1833 | 1899 | $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
| 1834 | 1900 | $tagsRow = array(); |
@@ -1839,14 +1905,16 @@ discard block |
||
| 1839 | 1905 | { |
| 1840 | 1906 | $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
| 1841 | 1907 | $tagsRow = array(); |
| 1842 | - if (!isset($context['disabled_tags']['font'])) |
|
| 1843 | - $tagsRow[] = 'font'; |
|
| 1844 | - if (!isset($context['disabled_tags']['size'])) |
|
| 1845 | - $tagsRow[] = 'size'; |
|
| 1846 | - if (!isset($context['disabled_tags']['color'])) |
|
| 1847 | - $tagsRow[] = 'color'; |
|
| 1848 | - } |
|
| 1849 | - elseif ($row == 1 && empty($modSettings['disable_wysiwyg'])) |
|
| 1908 | + if (!isset($context['disabled_tags']['font'])) { |
|
| 1909 | + $tagsRow[] = 'font'; |
|
| 1910 | + } |
|
| 1911 | + if (!isset($context['disabled_tags']['size'])) { |
|
| 1912 | + $tagsRow[] = 'size'; |
|
| 1913 | + } |
|
| 1914 | + if (!isset($context['disabled_tags']['color'])) { |
|
| 1915 | + $tagsRow[] = 'color'; |
|
| 1916 | + } |
|
| 1917 | + } elseif ($row == 1 && empty($modSettings['disable_wysiwyg'])) |
|
| 1850 | 1918 | { |
| 1851 | 1919 | $tmp = array(); |
| 1852 | 1920 | $tagsRow[] = 'removeformat'; |
@@ -1857,13 +1925,15 @@ discard block |
||
| 1857 | 1925 | } |
| 1858 | 1926 | } |
| 1859 | 1927 | |
| 1860 | - if (!empty($tagsRow)) |
|
| 1861 | - $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
|
| 1928 | + if (!empty($tagsRow)) { |
|
| 1929 | + $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
|
| 1930 | + } |
|
| 1862 | 1931 | } |
| 1863 | - if (!empty($bbcodes_styles)) |
|
| 1864 | - $context['html_headers'] .= ' |
|
| 1932 | + if (!empty($bbcodes_styles)) { |
|
| 1933 | + $context['html_headers'] .= ' |
|
| 1865 | 1934 | <style>' . $bbcodes_styles . ' |
| 1866 | 1935 | </style>'; |
| 1936 | + } |
|
| 1867 | 1937 | } |
| 1868 | 1938 | |
| 1869 | 1939 | // Initialize smiley array... if not loaded before. |
@@ -1875,8 +1945,8 @@ discard block |
||
| 1875 | 1945 | ); |
| 1876 | 1946 | |
| 1877 | 1947 | // Load smileys - don't bother to run a query if we're not using the database's ones anyhow. |
| 1878 | - if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') |
|
| 1879 | - $context['smileys']['postform'][] = array( |
|
| 1948 | + if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') { |
|
| 1949 | + $context['smileys']['postform'][] = array( |
|
| 1880 | 1950 | 'smileys' => array( |
| 1881 | 1951 | array( |
| 1882 | 1952 | 'code' => ':)', |
@@ -1962,7 +2032,7 @@ discard block |
||
| 1962 | 2032 | ), |
| 1963 | 2033 | 'isLast' => true, |
| 1964 | 2034 | ); |
| 1965 | - elseif ($user_info['smiley_set'] != 'none') |
|
| 2035 | + } elseif ($user_info['smiley_set'] != 'none') |
|
| 1966 | 2036 | { |
| 1967 | 2037 | if (($temp = cache_get_data('posting_smileys', 480)) == null) |
| 1968 | 2038 | { |
@@ -1985,17 +2055,19 @@ discard block |
||
| 1985 | 2055 | |
| 1986 | 2056 | foreach ($context['smileys'] as $section => $smileyRows) |
| 1987 | 2057 | { |
| 1988 | - foreach ($smileyRows as $rowIndex => $smileys) |
|
| 1989 | - $context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true; |
|
| 2058 | + foreach ($smileyRows as $rowIndex => $smileys) { |
|
| 2059 | + $context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true; |
|
| 2060 | + } |
|
| 1990 | 2061 | |
| 1991 | - if (!empty($smileyRows)) |
|
| 1992 | - $context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true; |
|
| 2062 | + if (!empty($smileyRows)) { |
|
| 2063 | + $context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true; |
|
| 2064 | + } |
|
| 1993 | 2065 | } |
| 1994 | 2066 | |
| 1995 | 2067 | cache_put_data('posting_smileys', $context['smileys'], 480); |
| 2068 | + } else { |
|
| 2069 | + $context['smileys'] = $temp; |
|
| 1996 | 2070 | } |
| 1997 | - else |
|
| 1998 | - $context['smileys'] = $temp; |
|
| 1999 | 2071 | } |
| 2000 | 2072 | } |
| 2001 | 2073 | |
@@ -2021,8 +2093,9 @@ discard block |
||
| 2021 | 2093 | loadTemplate('GenericControls'); |
| 2022 | 2094 | |
| 2023 | 2095 | // Some javascript ma'am? |
| 2024 | - if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) |
|
| 2025 | - loadJavaScriptFile('captcha.js', array(), 'smf_captcha'); |
|
| 2096 | + if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) { |
|
| 2097 | + loadJavaScriptFile('captcha.js', array(), 'smf_captcha'); |
|
| 2098 | + } |
|
| 2026 | 2099 | |
| 2027 | 2100 | $context['use_graphic_library'] = in_array('gd', get_loaded_extensions()); |
| 2028 | 2101 | |
@@ -2035,8 +2108,8 @@ discard block |
||
| 2035 | 2108 | $isNew = !isset($context['controls']['verification'][$verificationOptions['id']]); |
| 2036 | 2109 | |
| 2037 | 2110 | // Log this into our collection. |
| 2038 | - if ($isNew) |
|
| 2039 | - $context['controls']['verification'][$verificationOptions['id']] = array( |
|
| 2111 | + if ($isNew) { |
|
| 2112 | + $context['controls']['verification'][$verificationOptions['id']] = array( |
|
| 2040 | 2113 | 'id' => $verificationOptions['id'], |
| 2041 | 2114 | 'empty_field' => empty($verificationOptions['no_empty_field']), |
| 2042 | 2115 | 'show_visual' => !empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])), |
@@ -2047,13 +2120,15 @@ discard block |
||
| 2047 | 2120 | 'questions' => array(), |
| 2048 | 2121 | 'can_recaptcha' => !empty($modSettings['recaptcha_enabled']) && !empty($modSettings['recaptcha_site_key']) && !empty($modSettings['recaptcha_secret_key']), |
| 2049 | 2122 | ); |
| 2123 | + } |
|
| 2050 | 2124 | $thisVerification = &$context['controls']['verification'][$verificationOptions['id']]; |
| 2051 | 2125 | |
| 2052 | 2126 | // Is there actually going to be anything? |
| 2053 | - if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) |
|
| 2054 | - return false; |
|
| 2055 | - elseif (!$isNew && !$do_test) |
|
| 2056 | - return true; |
|
| 2127 | + if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) { |
|
| 2128 | + return false; |
|
| 2129 | + } elseif (!$isNew && !$do_test) { |
|
| 2130 | + return true; |
|
| 2131 | + } |
|
| 2057 | 2132 | |
| 2058 | 2133 | // Sanitize reCAPTCHA fields? |
| 2059 | 2134 | if ($thisVerification['can_recaptcha']) |
@@ -2066,11 +2141,12 @@ discard block |
||
| 2066 | 2141 | } |
| 2067 | 2142 | |
| 2068 | 2143 | // Add javascript for the object. |
| 2069 | - if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) |
|
| 2070 | - $context['insert_after_template'] .= ' |
|
| 2144 | + if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) { |
|
| 2145 | + $context['insert_after_template'] .= ' |
|
| 2071 | 2146 | <script> |
| 2072 | 2147 | var verification' . $verificationOptions['id'] . 'Handle = new smfCaptcha("' . $thisVerification['image_href'] . '", "' . $verificationOptions['id'] . '", ' . ($context['use_graphic_library'] ? 1 : 0) . '); |
| 2073 | 2148 | </script>'; |
| 2149 | + } |
|
| 2074 | 2150 | |
| 2075 | 2151 | // If we want questions do we have a cache of all the IDs? |
| 2076 | 2152 | if (!empty($thisVerification['number_questions']) && empty($modSettings['question_id_cache'])) |
@@ -2093,8 +2169,9 @@ discard block |
||
| 2093 | 2169 | unset ($row['id_question']); |
| 2094 | 2170 | // Make them all lowercase. We can't directly use $smcFunc['strtolower'] with array_walk, so do it manually, eh? |
| 2095 | 2171 | $row['answers'] = smf_json_decode($row['answers'], true); |
| 2096 | - foreach ($row['answers'] as $k => $v) |
|
| 2097 | - $row['answers'][$k] = $smcFunc['strtolower']($v); |
|
| 2172 | + foreach ($row['answers'] as $k => $v) { |
|
| 2173 | + $row['answers'][$k] = $smcFunc['strtolower']($v); |
|
| 2174 | + } |
|
| 2098 | 2175 | |
| 2099 | 2176 | $modSettings['question_id_cache']['questions'][$id_question] = $row; |
| 2100 | 2177 | $modSettings['question_id_cache']['langs'][$row['lngfile']][] = $id_question; |
@@ -2105,35 +2182,42 @@ discard block |
||
| 2105 | 2182 | } |
| 2106 | 2183 | } |
| 2107 | 2184 | |
| 2108 | - if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) |
|
| 2109 | - $_SESSION[$verificationOptions['id'] . '_vv'] = array(); |
|
| 2185 | + if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) { |
|
| 2186 | + $_SESSION[$verificationOptions['id'] . '_vv'] = array(); |
|
| 2187 | + } |
|
| 2110 | 2188 | |
| 2111 | 2189 | // Do we need to refresh the verification? |
| 2112 | - 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'])) |
|
| 2113 | - $force_refresh = true; |
|
| 2114 | - else |
|
| 2115 | - $force_refresh = false; |
|
| 2190 | + 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'])) { |
|
| 2191 | + $force_refresh = true; |
|
| 2192 | + } else { |
|
| 2193 | + $force_refresh = false; |
|
| 2194 | + } |
|
| 2116 | 2195 | |
| 2117 | 2196 | // This can also force a fresh, although unlikely. |
| 2118 | - if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) |
|
| 2119 | - $force_refresh = true; |
|
| 2197 | + if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) { |
|
| 2198 | + $force_refresh = true; |
|
| 2199 | + } |
|
| 2120 | 2200 | |
| 2121 | 2201 | $verification_errors = array(); |
| 2122 | 2202 | // Start with any testing. |
| 2123 | 2203 | if ($do_test) |
| 2124 | 2204 | { |
| 2125 | 2205 | // This cannot happen! |
| 2126 | - if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) |
|
| 2127 | - fatal_lang_error('no_access', false); |
|
| 2206 | + if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) { |
|
| 2207 | + fatal_lang_error('no_access', false); |
|
| 2208 | + } |
|
| 2128 | 2209 | // ... nor this! |
| 2129 | - if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) |
|
| 2130 | - fatal_lang_error('no_access', false); |
|
| 2210 | + if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) { |
|
| 2211 | + fatal_lang_error('no_access', false); |
|
| 2212 | + } |
|
| 2131 | 2213 | // Hmm, it's requested but not actually declared. This shouldn't happen. |
| 2132 | - if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) |
|
| 2133 | - fatal_lang_error('no_access', false); |
|
| 2214 | + if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) { |
|
| 2215 | + fatal_lang_error('no_access', false); |
|
| 2216 | + } |
|
| 2134 | 2217 | // While we're here, did the user do something bad? |
| 2135 | - if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) |
|
| 2136 | - $verification_errors[] = 'wrong_verification_answer'; |
|
| 2218 | + if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) { |
|
| 2219 | + $verification_errors[] = 'wrong_verification_answer'; |
|
| 2220 | + } |
|
| 2137 | 2221 | |
| 2138 | 2222 | if ($thisVerification['can_recaptcha']) |
| 2139 | 2223 | { |
@@ -2144,22 +2228,25 @@ discard block |
||
| 2144 | 2228 | { |
| 2145 | 2229 | $resp = $reCaptcha->verify($_POST['g-recaptcha-response'], $user_info['ip']); |
| 2146 | 2230 | |
| 2147 | - if (!$resp->isSuccess()) |
|
| 2148 | - $verification_errors[] = 'wrong_verification_code'; |
|
| 2231 | + if (!$resp->isSuccess()) { |
|
| 2232 | + $verification_errors[] = 'wrong_verification_code'; |
|
| 2233 | + } |
|
| 2234 | + } else { |
|
| 2235 | + $verification_errors[] = 'wrong_verification_code'; |
|
| 2149 | 2236 | } |
| 2150 | - else |
|
| 2151 | - $verification_errors[] = 'wrong_verification_code'; |
|
| 2152 | 2237 | } |
| 2153 | - 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'])) |
|
| 2154 | - $verification_errors[] = 'wrong_verification_code'; |
|
| 2238 | + 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'])) { |
|
| 2239 | + $verification_errors[] = 'wrong_verification_code'; |
|
| 2240 | + } |
|
| 2155 | 2241 | if ($thisVerification['number_questions']) |
| 2156 | 2242 | { |
| 2157 | 2243 | $incorrectQuestions = array(); |
| 2158 | 2244 | foreach ($_SESSION[$verificationOptions['id'] . '_vv']['q'] as $q) |
| 2159 | 2245 | { |
| 2160 | 2246 | // We don't have this question any more, thus no answers. |
| 2161 | - if (!isset($modSettings['question_id_cache']['questions'][$q])) |
|
| 2162 | - continue; |
|
| 2247 | + if (!isset($modSettings['question_id_cache']['questions'][$q])) { |
|
| 2248 | + continue; |
|
| 2249 | + } |
|
| 2163 | 2250 | // This is quite complex. We have our question but it might have multiple answers. |
| 2164 | 2251 | // First, did they actually answer this question? |
| 2165 | 2252 | if (!isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) || trim($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) == '') |
@@ -2171,24 +2258,28 @@ discard block |
||
| 2171 | 2258 | else |
| 2172 | 2259 | { |
| 2173 | 2260 | $given_answer = trim($smcFunc['htmlspecialchars'](strtolower($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]))); |
| 2174 | - if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) |
|
| 2175 | - $incorrectQuestions[] = $q; |
|
| 2261 | + if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) { |
|
| 2262 | + $incorrectQuestions[] = $q; |
|
| 2263 | + } |
|
| 2176 | 2264 | } |
| 2177 | 2265 | } |
| 2178 | 2266 | |
| 2179 | - if (!empty($incorrectQuestions)) |
|
| 2180 | - $verification_errors[] = 'wrong_verification_answer'; |
|
| 2267 | + if (!empty($incorrectQuestions)) { |
|
| 2268 | + $verification_errors[] = 'wrong_verification_answer'; |
|
| 2269 | + } |
|
| 2181 | 2270 | } |
| 2182 | 2271 | } |
| 2183 | 2272 | |
| 2184 | 2273 | // Any errors means we refresh potentially. |
| 2185 | 2274 | if (!empty($verification_errors)) |
| 2186 | 2275 | { |
| 2187 | - if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) |
|
| 2188 | - $_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0; |
|
| 2276 | + if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) { |
|
| 2277 | + $_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0; |
|
| 2278 | + } |
|
| 2189 | 2279 | // Too many errors? |
| 2190 | - elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) |
|
| 2191 | - $force_refresh = true; |
|
| 2280 | + elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) { |
|
| 2281 | + $force_refresh = true; |
|
| 2282 | + } |
|
| 2192 | 2283 | |
| 2193 | 2284 | // Keep a track of these. |
| 2194 | 2285 | $_SESSION[$verificationOptions['id'] . '_vv']['errors']++; |
@@ -2221,8 +2312,9 @@ discard block |
||
| 2221 | 2312 | // Are we overriding the range? |
| 2222 | 2313 | $character_range = !empty($verificationOptions['override_range']) ? $verificationOptions['override_range'] : $context['standard_captcha_range']; |
| 2223 | 2314 | |
| 2224 | - for ($i = 0; $i < 6; $i++) |
|
| 2225 | - $_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)]; |
|
| 2315 | + for ($i = 0; $i < 6; $i++) { |
|
| 2316 | + $_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)]; |
|
| 2317 | + } |
|
| 2226 | 2318 | } |
| 2227 | 2319 | |
| 2228 | 2320 | // Getting some new questions? |
@@ -2230,8 +2322,9 @@ discard block |
||
| 2230 | 2322 | { |
| 2231 | 2323 | // Attempt to try the current page's language, followed by the user's preference, followed by the site default. |
| 2232 | 2324 | $possible_langs = array(); |
| 2233 | - if (isset($_SESSION['language'])) |
|
| 2234 | - $possible_langs[] = strtr($_SESSION['language'], array('-utf8' => '')); |
|
| 2325 | + if (isset($_SESSION['language'])) { |
|
| 2326 | + $possible_langs[] = strtr($_SESSION['language'], array('-utf8' => '')); |
|
| 2327 | + } |
|
| 2235 | 2328 | if (!empty($user_info['language'])); |
| 2236 | 2329 | $possible_langs[] = $user_info['language']; |
| 2237 | 2330 | $possible_langs[] = $language; |
@@ -2250,8 +2343,7 @@ discard block |
||
| 2250 | 2343 | } |
| 2251 | 2344 | } |
| 2252 | 2345 | } |
| 2253 | - } |
|
| 2254 | - else |
|
| 2346 | + } else |
|
| 2255 | 2347 | { |
| 2256 | 2348 | // Same questions as before. |
| 2257 | 2349 | $questionIDs = !empty($_SESSION[$verificationOptions['id'] . '_vv']['q']) ? $_SESSION[$verificationOptions['id'] . '_vv']['q'] : array(); |
@@ -2261,8 +2353,9 @@ discard block |
||
| 2261 | 2353 | // If we do have an empty field, it would be nice to hide it from legitimate users who shouldn't be populating it anyway. |
| 2262 | 2354 | if (!empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) |
| 2263 | 2355 | { |
| 2264 | - if (!isset($context['html_headers'])) |
|
| 2265 | - $context['html_headers'] = ''; |
|
| 2356 | + if (!isset($context['html_headers'])) { |
|
| 2357 | + $context['html_headers'] = ''; |
|
| 2358 | + } |
|
| 2266 | 2359 | $context['html_headers'] .= '<style>.vv_special { display:none; }</style>'; |
| 2267 | 2360 | } |
| 2268 | 2361 | |
@@ -2288,11 +2381,13 @@ discard block |
||
| 2288 | 2381 | $_SESSION[$verificationOptions['id'] . '_vv']['count'] = empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) ? 1 : $_SESSION[$verificationOptions['id'] . '_vv']['count'] + 1; |
| 2289 | 2382 | |
| 2290 | 2383 | // Return errors if we have them. |
| 2291 | - if (!empty($verification_errors)) |
|
| 2292 | - return $verification_errors; |
|
| 2384 | + if (!empty($verification_errors)) { |
|
| 2385 | + return $verification_errors; |
|
| 2386 | + } |
|
| 2293 | 2387 | // If we had a test that one, make a note. |
| 2294 | - elseif ($do_test) |
|
| 2295 | - $_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true; |
|
| 2388 | + elseif ($do_test) { |
|
| 2389 | + $_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true; |
|
| 2390 | + } |
|
| 2296 | 2391 | |
| 2297 | 2392 | // Say that everything went well chaps. |
| 2298 | 2393 | return true; |
@@ -2317,8 +2412,9 @@ discard block |
||
| 2317 | 2412 | call_integration_hook('integrate_autosuggest', array(&$searchTypes)); |
| 2318 | 2413 | |
| 2319 | 2414 | // If we're just checking the callback function is registered return true or false. |
| 2320 | - if ($checkRegistered != null) |
|
| 2321 | - return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered); |
|
| 2415 | + if ($checkRegistered != null) { |
|
| 2416 | + return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered); |
|
| 2417 | + } |
|
| 2322 | 2418 | |
| 2323 | 2419 | checkSession('get'); |
| 2324 | 2420 | loadTemplate('Xml'); |
@@ -2469,24 +2565,27 @@ discard block |
||
| 2469 | 2565 | foreach ($possible_versions as $ver) |
| 2470 | 2566 | { |
| 2471 | 2567 | $ver = trim($ver); |
| 2472 | - if (strpos($ver, 'SMF') === 0) |
|
| 2473 | - $versions[] = $ver; |
|
| 2568 | + if (strpos($ver, 'SMF') === 0) { |
|
| 2569 | + $versions[] = $ver; |
|
| 2570 | + } |
|
| 2474 | 2571 | } |
| 2475 | 2572 | } |
| 2476 | 2573 | $smcFunc['db_free_result']($request); |
| 2477 | 2574 | |
| 2478 | 2575 | // Just in case we don't have ANYthing. |
| 2479 | - if (empty($versions)) |
|
| 2480 | - $versions = array('SMF 2.0'); |
|
| 2576 | + if (empty($versions)) { |
|
| 2577 | + $versions = array('SMF 2.0'); |
|
| 2578 | + } |
|
| 2481 | 2579 | |
| 2482 | - foreach ($versions as $id => $version) |
|
| 2483 | - if (strpos($version, strtoupper($_REQUEST['search'])) !== false) |
|
| 2580 | + foreach ($versions as $id => $version) { |
|
| 2581 | + if (strpos($version, strtoupper($_REQUEST['search'])) !== false) |
|
| 2484 | 2582 | $xml_data['items']['children'][] = array( |
| 2485 | 2583 | 'attributes' => array( |
| 2486 | 2584 | 'id' => $id, |
| 2487 | 2585 | ), |
| 2488 | 2586 | 'value' => $version, |
| 2489 | 2587 | ); |
| 2588 | + } |
|
| 2490 | 2589 | |
| 2491 | 2590 | return $xml_data; |
| 2492 | 2591 | } |