コード例 #1
0
ファイル: tidy.php プロジェクト: hunter2814/reason_package
/**
 * Turn a string or array into valid, standards-compliant (x)HTML
 *
 * Uses configuraton options in tidy.conf - which should minimally have show-body-only set to yes
 *
 * @param mixed $text The data to be tidied up
 * @return mixed $result Tidied data
 */
function tidy($text)
{
    static $tidy_funcs;
    static $tidy_conf;
    if (!isset($tidy_conf)) {
        $tidy_conf = SETTINGS_INC . 'tidy.conf';
    }
    if (is_array($text)) {
        $result = array();
        foreach (array_keys($text) as $key) {
            $result[$key] = tidy($text[$key]);
        }
        return $result;
    }
    // determine what tidy libraries are available
    if (empty($tidy_funcs)) {
        $tidy_funcs = get_extension_funcs('tidy');
    }
    $tidy_1_lib_available = !empty($tidy_funcs) && array_search('tidy_setopt', $tidy_funcs) !== false;
    $tidy_2_lib_available = !empty($tidy_funcs) && array_search('tidy_setopt', $tidy_funcs) === false;
    $tidy_command_line_available = TIDY_EXE ? file_exists(TIDY_EXE) : false;
    $text = protect_string_from_tidy($text);
    $text = '<html><body>' . $text . '</body></html>';
    if ($tidy_2_lib_available) {
        $tidy = new tidy();
        $tidy->parseString($text, $tidy_conf, 'utf8');
        $tidy->cleanRepair();
        $result = $tidy;
    } elseif ($tidy_1_lib_available) {
        tidy_load_config($tidy_conf);
        tidy_set_encoding('utf8');
        tidy_parse_string($text);
        tidy_clean_repair();
        $result = tidy_get_output();
    } elseif ($tidy_command_line_available) {
        $arg = escapeshellarg($text);
        // escape the bad stuff in the text
        $cmd = 'echo ' . $arg . ' | ' . TIDY_EXE . ' -q -config ' . $tidy_conf . ' 2> /dev/null';
        // the actual command - pipes the input to tidy which diverts its output to the random file
        $result = shell_exec($cmd);
        // execute the command
    } else {
        trigger_error('tidy does not appear to be available within php or at the command line - no tidying is taking place.');
        $result = $text;
    }
    return trim($result);
}
コード例 #2
0
ファイル: Tidy.php プロジェクト: Jobava/diacritice-meta-repo
 /**
  * Use the HTML tidy PECL extension to use the tidy library in-process,
  * saving the overhead of spawning a new process. Currently written to
  * the PHP 4.3.x version of the extension, may not work on PHP 5.
  *
  * 'pear install tidy' should be able to compile the extension module.
  */
 private static function internal($text)
 {
     global $wgTidyConf;
     $fname = 'Parser::internalTidy';
     wfProfileIn($fname);
     tidy_load_config($wgTidyConf);
     tidy_set_encoding('utf8');
     tidy_parse_string($text);
     tidy_clean_repair();
     if (tidy_get_status() == 2) {
         // 2 is magic number for fatal error
         // http://www.php.net/manual/en/function.tidy-get-status.php
         $cleansource = null;
     } else {
         $cleansource = tidy_get_output();
     }
     wfProfileOut($fname);
     return $cleansource;
 }
コード例 #3
0
ファイル: bbcode.php プロジェクト: esokullu/grou.ps
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;
}
コード例 #4
0
ファイル: HTMLCleaner.php プロジェクト: ergun805/eOgr
 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;
     }
 }
コード例 #5
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;
 }
コード例 #6
0
 /**
  * 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);
     }
 }