Beispiel #1
0
 /**
  * Takes a mixed variable, filters unsafe html and returns it.
  *
  * @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 {
         $IsHtml = strpos($Mixed, '<') !== FALSE || (bool) preg_match('/&#?[a-z0-9]{1,10};/i', $Mixed);
         if ($IsHtml) {
             // The text contains html and must be purified.
             $Formatter = Gdn::Factory('HtmlFormatter');
             if (is_null($Formatter)) {
                 // If there is no HtmlFormatter then make sure that script injections won't work.
                 return self::Display($Mixed);
             }
             // Allow the code tag to keep all enclosed html encoded.
             $Mixed = preg_replace(array('/<code([^>]*)>(.+?)<\\/code>/sei'), array('\'<code\'.RemoveQuoteSlashes(\'\\1\').\'>\'.htmlspecialchars(RemoveQuoteSlashes(\'\\2\')).\'</code>\''), $Mixed);
             // Do HTML filtering before our special changes
             $Mixed = $Formatter->Format($Mixed);
             // Links
             $Mixed = Gdn_Format::Links($Mixed);
             // Mentions & Hashes
             $Mixed = Gdn_Format::Mentions($Mixed);
             $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, '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;
     }
 }
Beispiel #2
0
<?php

defined('APPLICATION') or exit;
$Session = Gdn::Session();
// Format page body.
$PageBody = $this->Page->Body;
if ($this->Page->Format === 'RawHtmlLineBreaks') {
    $PageBody = preg_replace("/(\r\n)|(\r)|(\n)/", "<br />", $PageBody);
    $PageBody = FixNl2Br($PageBody);
} else {
    if ($this->Page->Format !== 'RawHtml') {
        $PageBody = Gdn_Format::To($PageBody, $this->Page->Format);
    }
}
?>
<div id="Page_<?php 
echo $this->Page->PageID;
?>
" class="PageContent Page-<?php 
echo $this->Page->UrlCode;
?>
">
    <?php 
$this->FireEvent('BeforePageOptions');
?>
    <?php 
if ($Session->CheckPermission('Garden.Settings.Manage')) {
    ?>
        <div class="Options">
         <span class="ToggleFlyout OptionsMenu">
            <span class="OptionsTitle" title="<?php