示例#1
0
 /**
  * tidy the data
  *
  * @access	public
  * @param	string		data
  * @return	string		compressed data
  */
 function apply($data)
 {
     if (!function_exists('tidy_parse_string')) {
         return $data;
     }
     /**
      * tidy 1.0
      */
     if (function_exists('tidy_setopt') && is_array($this->_params)) {
         foreach ($this->_params as $opt => $value) {
             tidy_setopt($opt, $value);
         }
         tidy_parse_string($data);
         tidy_clean_repair();
         $data = tidy_get_output();
     } else {
         $tidy = tidy_parse_string($data, $this->_params);
         tidy_clean_repair($tidy);
         $data = tidy_get_output($tidy);
     }
     return $data;
 }
示例#2
0
function return_parsed_bbcode($message, $nowrap = false)
{
    // never strip_tags here, see Page.Talks for details
    $message = str_replace("[b]", "<b>", $message);
    $message = str_replace("[/b]", "</b>", $message);
    $message = str_replace("[i]", "<i>", $message);
    $message = str_replace("[/i]", "</i>", $message);
    $message = str_replace("[u]", "<u>", $message);
    $message = str_replace("[/u]", "</u>", $message);
    $message = str_replace("[center]", "<div align=\"center\">", $message);
    $message = str_replace("[/center]", "</div>", $message);
    $message = str_replace("[left]", "<div align=\"left\">", $message);
    $message = str_replace("[/left]", "</div>", $message);
    $message = str_replace("[right]", "<div align=\"right\">", $message);
    $message = str_replace("[/right]", "</div>", $message);
    $message = str_replace("[ol]", "<ol>", $message);
    $message = str_replace("[ul]", "<ul>", $message);
    $message = str_replace("[li]", "<li>", $message);
    $message = str_replace("[/ol]", "</ol>", $message);
    $message = str_replace("[/ul]", "</ul>", $message);
    $message = str_replace("[br]", "<br>", $message);
    $message = eregi_replace("\\[img\\]([^\\[]*)\\[/img\\]", "<img src=\"\\1\" border=\"0\">", $message);
    $message = eregi_replace("\\[url\\](https?://[^\\[]*)\\[/url\\]", "<a href=\"\\1\">\\1</a>", $message);
    if (function_exists("tidy_get_output")) {
        if (!$nowrap) {
            $config = array('indent' => FALSE, 'output-xhtml' => TRUE, 'show-body-only' => TRUE, 'wrap' => 80);
        } else {
            $config = array('indent' => FALSE, 'output-xhtml' => TRUE, 'show-body-only' => TRUE);
        }
        tidy_set_encoding('UTF8');
        foreach ($config as $key => $value) {
            tidy_setopt($key, $value);
        }
        tidy_parse_string($message);
        tidy_clean_repair();
        $message = tidy_get_output();
    }
    return $message;
}
示例#3
0
 function TidyClean()
 {
     if (!class_exists('tidy')) {
         if (function_exists('tidy_parse_string')) {
             //use procedural style for compatibility with PHP 4.3
             tidy_set_encoding($this->Encoding);
             foreach ($this->TidyConfig as $key => $value) {
                 tidy_setopt($key, $value);
             }
             tidy_parse_string($this->html);
             tidy_clean_repair();
             $this->html = tidy_get_output();
         } else {
             print "<b>No tidy support. Please enable it in your php.ini.\r\nOnly basic cleaning is beeing applied\r\n</b>";
         }
     } else {
         //PHP 5 only !!!
         $tidy = new tidy();
         $tidy->parseString($this->html, $this->TidyConfig, $this->Encoding);
         $tidy->cleanRepair();
         $this->html = $tidy;
     }
 }
function tidy_html($input_string)
{
    // Detect if Tidy is in configured
    if (function_exists('tidy_get_release')) {
        # Tidy for PHP version 4
        if (substr(phpversion(), 0, 1) == 4) {
            tidy_setopt('uppercase-attributes', TRUE);
            tidy_setopt('wrap', 800);
            tidy_parse_string($input_string);
            $cleaned_html = tidy_get_output();
        }
        # Tidy for PHP version 5
        if (substr(phpversion(), 0, 1) == 5) {
            $config = array('uppercase-attributes' => true, 'wrap' => 800);
            $tidy = new tidy();
            $tidy->parseString($input_string, $config, 'utf8');
            $tidy->cleanRepair();
            $cleaned_html = tidy_get_output($tidy);
        }
    } else {
        # Tidy not configured for this computer
        $cleaned_html = $input_string;
    }
    return $cleaned_html;
}
示例#5
0
 static function tidyOptions($options)
 {
     foreach ($options as $key => $value) {
         tidy_setopt($key, $value);
     }
 }
示例#6
0
 /**
  * Generates HTML from an array of tokens.
  * @param $tokens Array of HTMLPurifier_Token
  * @param $config HTMLPurifier_Config object
  * @return Generated HTML
  */
 function generateFromTokens($tokens, $config, &$context)
 {
     $html = '';
     if (!$config) {
         $config = HTMLPurifier_Config::createDefault();
     }
     $this->_scriptFix = $config->get('Output', 'CommentScriptContents');
     $this->_def = $config->getHTMLDefinition();
     $this->_xhtml = $this->_def->doctype->xml;
     if (!$tokens) {
         return '';
     }
     for ($i = 0, $size = count($tokens); $i < $size; $i++) {
         if ($this->_scriptFix && $tokens[$i]->name === 'script' && $i + 2 < $size && $tokens[$i + 2]->type == 'end') {
             // script special case
             // the contents of the script block must be ONE token
             // for this to work
             $html .= $this->generateFromToken($tokens[$i++]);
             $html .= $this->generateScriptFromToken($tokens[$i++]);
             // We're not going to do this: it wouldn't be valid anyway
             //while ($tokens[$i]->name != 'script') {
             //    $html .= $this->generateScriptFromToken($tokens[$i++]);
             //}
         }
         $html .= $this->generateFromToken($tokens[$i]);
     }
     if ($config->get('Output', 'TidyFormat') && extension_loaded('tidy')) {
         $tidy_options = array('indent' => true, 'output-xhtml' => $this->_xhtml, 'show-body-only' => true, 'indent-spaces' => 2, 'wrap' => 68);
         if (version_compare(PHP_VERSION, '5', '<')) {
             tidy_set_encoding('utf8');
             foreach ($tidy_options as $key => $value) {
                 tidy_setopt($key, $value);
             }
             tidy_parse_string($html);
             tidy_clean_repair();
             $html = tidy_get_output();
         } else {
             $tidy = new Tidy();
             $tidy->parseString($html, $tidy_options, 'utf8');
             $tidy->cleanRepair();
             $html = (string) $tidy;
         }
     }
     // normalize newlines to system
     $nl = $config->get('Output', 'Newline');
     if ($nl === null) {
         $nl = PHP_EOL;
     }
     $html = str_replace("\n", $nl, $html);
     return $html;
 }
 /**
  * BlockenController()
  */
 function BlockenController()
 {
     if (BLOCKEN_DEBUG_MODE && (BLOCKEN_ALWAYS_DEBUG || BlockenCommon::isMember())) {
         $this->_fStart = BlockenCommon::getMicroTime();
     }
     if (function_exists('tidy_set_encoding')) {
         tidy_set_encoding('UTF8');
         tidy_setopt('input-xml', true);
     }
 }
示例#8
0
function tidy_html($input_string)
{
    // Detect if Tidy is in configured
    if (function_exists('tidy_get_release')) {
        # Tidy for PHP version 4
        if (substr(phpversion(), 0, 1) == 4) {
            tidy_setopt('uppercase-attributes', TRUE);
            tidy_setopt('wrap', 800);
            tidy_parse_string($input_string);
            $cleaned_html = tidy_get_output();
        }
        # Tidy for PHP version 5
        if (substr(phpversion(), 0, 1) == 5) {
            $config = array('uppercase-attributes' => true, 'wrap' => 800);
            $tidy = new tidy();
            $tidy->parseString($input_string, $config, 'utf8');
            $tidy->cleanRepair();
            $cleaned_html = tidy_get_output($tidy);
        }
    } else {
        fprintf(STDERR, "FATAL: TidyHTML not found\n");
        //SAH
        die("FATAL: TidyHTML not found\n");
        //SAH
        //# Tidy not configured for this computer
        //$cleaned_html = strtoupper($input_string); //Make it all uppercase (SAH)
    }
    return $cleaned_html;
}
示例#9
0
 function cleanXHTML($string)
 {
     if (!extension_loaded('tidy')) {
         if (!dl('tidy.so')) {
             return strip_tags($string, '<br><a>');
         }
     }
     tidy_setopt('output-xhtml', true);
     tidy_setopt('doctype', 'omit');
     tidy_setopt('show-body-only', true);
     tidy_parse_string($string);
     tidy_clean_repair();
     $clean = tidy_get_output();
     if (!$clean) {
         return strip_tags($string, '<br><a>');
     }
     return $clean;
 }