replaceSpoilers() protected static method

Good for displaying excerpts from discussions and without showing the spoiler text.
protected static replaceSpoilers ( string $html, string $replaceWith = '(Spoiler)' ) : string
$html string An HTML-formatted string.
$replaceWith string The translation code to replace spoilers with.
return string Returns the html with spoilers removed.
Ejemplo n.º 1
0
 /**
  * Format a string as plain text.
  * @param string $Body The text to format.
  * @param string $Format The current format of the text.
  * @return string
  * @since 2.1
  */
 public static function plainText($Body, $Format = 'Html')
 {
     $Result = Gdn_Format::to($Body, $Format);
     $Result = Gdn_Format::replaceSpoilers($Result);
     if ($Format != 'Text') {
         // Remove returns and then replace html return tags with returns.
         $Result = str_replace(array("\n", "\r"), ' ', $Result);
         $Result = preg_replace('`<br\\s*/?>`', "\n", $Result);
         // Fix lists.
         $Result = str_replace('<li>', '* ', $Result);
         $Result = preg_replace('`</(?:li|ol|ul)>`', "\n", $Result);
         $Allblocks = '(?:div|table|dl|pre|blockquote|address|p|h[1-6]|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
         $Result = preg_replace('`</' . $Allblocks . '>`', "\n\n", $Result);
         // TODO: Fix hard returns within pre blocks.
         $Result = strip_tags($Result);
     }
     $Result = trim(html_entity_decode($Result, ENT_QUOTES, 'UTF-8'));
     return $Result;
 }