/** * Takes a mixed variable, filters unsafe HTML and returns it. * Does "magic" formatting of links, mentions, link embeds, emoji, & linebreaks. * * @param mixed $Mixed An object, array, or string to be formatted. * @return string */ public static function html($Mixed) { if (!is_string($Mixed)) { return self::to($Mixed, 'Html'); } else { if (self::isHtml($Mixed)) { // Purify HTML $Mixed = Gdn_Format::htmlFilter($Mixed); // Links $Mixed = Gdn_Format::links($Mixed); // Mentions & Hashes $Mixed = Gdn_Format::mentions($Mixed); // Emoji $Mixed = Emoji::instance()->translateToHtml($Mixed); // nl2br if (C('Garden.Format.ReplaceNewlines', true)) { $Mixed = preg_replace("/(\r\n)|(\r)|(\n)/", "<br />", $Mixed); $Mixed = fixNl2Br($Mixed); } $Result = $Mixed; // $Result = $Result. // "<h3>Html</h3><pre>".nl2br(htmlspecialchars(str_replace("<br />", "\n", $Mixed)))."</pre>". // "<h3>Formatted</h3><pre>".nl2br(htmlspecialchars(str_replace("<br />", "\n", $Result)))."</pre>"; } else { // The text does not contain html and does not have to be purified. // This is an optimization because purifying is very slow and memory intense. $Result = htmlspecialchars($Mixed, ENT_NOQUOTES, C('Garden.Charset', 'UTF-8')); $Result = Gdn_Format::mentions($Result); $Result = Gdn_Format::links($Result); $Result = Emoji::instance()->translateToHtml($Result); if (C('Garden.Format.ReplaceNewlines', true)) { $Result = preg_replace("/(\r\n)|(\r)|(\n)/", "<br />", $Result); $Result = fixNl2Br($Result); } } return $Result; } }
/** * Takes a mixed variable, filters unsafe HTML and returns it. * * Does "magic" formatting of links, mentions, link embeds, emoji, & linebreaks. * * @param mixed $Mixed An object, array, or string to be formatted. * @return string HTML */ public static function html($Mixed) { if (!is_string($Mixed)) { return self::to($Mixed, 'Html'); } else { if (self::isHtml($Mixed)) { // Purify HTML $Mixed = Gdn_Format::htmlFilter($Mixed); // nl2br if (c('Garden.Format.ReplaceNewlines', true)) { $Mixed = preg_replace("/(\r\n)|(\r)|(\n)/", "<br />", $Mixed); $Mixed = fixNl2Br($Mixed); } $Result = Gdn_Format::processHTML($Mixed); } else { // The text does not contain HTML and does not have to be purified. // This is an optimization because purifying is very slow and memory intense. $Result = htmlspecialchars($Mixed, ENT_NOQUOTES, 'UTF-8'); if (c('Garden.Format.ReplaceNewlines', true)) { $Result = preg_replace("/(\r\n)|(\r)|(\n)/", "<br />", $Result); $Result = fixNl2Br($Result); } $Result = Gdn_Format::processHTML($Result); } return $Result; } }