本文整理汇总了PHP中tidy_clean_repair函数的典型用法代码示例。如果您正苦于以下问题:PHP tidy_clean_repair函数的具体用法?PHP tidy_clean_repair怎么用?PHP tidy_clean_repair使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tidy_clean_repair函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load_html
function load_html($html)
{
$tidy = tidy_parse_string($html);
tidy_clean_repair($tidy);
$html = tidy_get_html($tidy);
phpQuery::unloadDocuments();
return phpQuery::newDocumentHTML($html);
}
示例2: afterRender
public function afterRender($event, $view)
{
if (!extension_loaded('tidy')) {
return;
}
$options = array('hide-comments' => true, 'tidy-mark' => false, 'indent' => true, 'indent-spaces' => 4, 'new-blocklevel-tags' => 'article,header,footer,section,nav', 'new-inline-tags' => 'video,audio,canvas,ruby,rt,rp', 'doctype' => '<!DOCTYPE HTML>', 'sort-attributes' => 'alpha', 'vertical-space' => false, 'output-xhtml' => true, 'wrap' => 150, 'wrap-attributes' => false, 'break-before-br' => false);
$buffer = tidy_parse_string($view->getContent(), $options, 'utf8');
tidy_clean_repair($buffer);
$buffer = str_replace(array('<html lang="en" xmlns="http://www.w3.org/1999/xhtml">', '<html xmlns="http://www.w3.org/1999/xhtml">'), '<!DOCTYPE html>', $buffer);
$buffer = str_replace(">\n</script>", "></script>", $buffer);
$view->setContent((string) $buffer);
}
示例3: output
function output($title = '', $body = '', $head = '')
{
global $settings, $authid, $checkleft, $checkright, $head, $error, $error_die;
if (theme('output_error') != false) {
$body = theme('output_error');
$title = 'Error';
$panels = false;
$lowerpanel = false;
$panel = '';
unset($error_die);
} else {
$panels = true;
}
//display panels
if ($panels != false) {
$panel = theme('displaypanels');
$lowerpanel = theme('displaylowerpanel');
}
if (isset($error) && !empty($error)) {
$errors = '<br />' . theme('title', 'Error') . theme('start_content') . '<div class="errors"><ul>';
foreach ($error as $error1) {
$errors .= '<li>' . $error1 . '</li>';
}
$errors .= '</ul></div>' . theme('end_content');
unset($error);
} else {
$errors = '';
}
if (isset($_GET['page']) && $_GET['page'] > 1) {
$title = $title . ' - Page ' . $_GET['page'];
}
$output = theme('head', stripslashes($title), $head) . '<body>';
if ($settings['maintenance_mode'] == 'on') {
$output .= '<div class="titlebg">WARNING: Maintenance Mode is on</div>';
}
$output .= '<div id="container">
' . theme('top') . theme('links');
$output .= $panel;
//display the data
$output .= $errors . '<br />' . stripslashes($body);
$output .= $lowerpanel . theme('footer');
//SEO Friendly Links
include IN_PATH . '/functions/seofriendlyurls.php';
//Check if the tidy library is installed
if (extension_loaded('tidy')) {
//yay it is, lets clean up all the HTML, so it looks all nice in View Source in your browser :)
$options = array("indent" => true, 'wrap' => 0);
$output = tidy_parse_string($output, $options);
tidy_clean_repair($output);
}
die($output);
}
示例4: tidy
/**
* 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);
}
示例5: internal
/**
* 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;
}
示例6: apply
/**
* 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;
}
示例7: return_parsed_bbcode
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;
}
示例8: TidyClean
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;
}
}
示例9: tidy_output
function tidy_output($init)
{
$init->process();
ob_start();
ob_start();
$output = $init->run();
$tidy = 'xhtml';
if ($tidy == 'xhtml') {
$options = array('output-xhtml' => true, 'indent' => true, 'input-encoding' => 'utf8', 'output-encoding' => 'utf8');
$output = tidy_parse_string($output, $options);
tidy_clean_repair($output);
}
if ($tidy == 'html') {
$options = array('output-html' => true, 'indent' => true, 'input-encoding' => 'utf8', 'output-encoding' => 'utf8', 'clean' => true);
$output = tidy_parse_string($output, $options);
tidy_clean_repair($output);
}
echo $output;
ob_end_flush();
header('Content-Length: ' . ob_get_length());
ob_end_flush();
}
示例10: tidyThis
private function tidyThis($source)
{
switch ($this->tidy_mode) {
case 'exec':
$tmp_file = $this->tmp_dir . md5($source) . '.txt';
file_put_contents($tmp_file, $source);
exec("tidy -utf8 -indent -asxhtml -numeric -bare -quiet {$tmp_file}", $tidy);
unlink($tmp_file);
return implode("\n", $tidy);
break;
case 'php':
$tidy = tidy_parse_string($source);
return tidy_clean_repair($tidy);
break;
default:
return $source;
break;
}
}
示例11: tidyFix
/**
* Use HTML Tidy to validate the $text
* Only runs when $config['HTML_Tidy'] is off
*
* @param string $text The html content to be checked. Passed by reference
*/
static function tidyFix(&$text, $ignore_config = false)
{
global $config;
if (!$ignore_config) {
if (empty($config['HTML_Tidy']) || $config['HTML_Tidy'] == 'off') {
return true;
}
}
if (!function_exists('tidy_parse_string')) {
return false;
}
$options = array();
$options['wrap'] = 0;
//keeps tidy from wrapping... want the least amount of space changing as possible.. could get rid of spaces between words with the str_replaces below
$options['doctype'] = 'omit';
//omit, auto, strict, transitional, user
$options['drop-empty-paras'] = true;
//drop empty paragraphs
$options['output-xhtml'] = true;
//need this so that <br> will be <br/> .. etc
$options['show-body-only'] = true;
$options['hide-comments'] = false;
//$options['anchor-as-name'] = true; //default is true, but not alwasy availabel. When true, adds an id attribute to anchor; when false, removes the name attribute... poorly designed, but we need it to be true
//
// php4
//
if (function_exists('tidy_setopt')) {
$options['char-encoding'] = 'utf8';
gp_edit::tidyOptions($options);
$tidy = 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
$tidyErrors[] = 'Tidy found serious XHTML errors: <br/>' . nl2br(htmlspecialchars(tidy_get_error_buffer($tidy)));
return false;
}
$text = tidy_get_output();
//
// php5
//
} else {
$tidy = tidy_parse_string($text, $options, 'utf8');
tidy_clean_repair($tidy);
if (tidy_get_status($tidy) === 2) {
// 2 is magic number for fatal error
// http://www.php.net/manual/en/function.tidy-get-status.php
$tidyErrors[] = 'Tidy found serious XHTML errors: <br/>' . nl2br(htmlspecialchars(tidy_get_error_buffer($tidy)));
return false;
}
$text = tidy_get_output($tidy);
}
return true;
}
示例12: cleanXHTML
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;
}
示例13: process
public function process($html, $url, $smart_tidy = true)
{
$this->reset();
// use user submitted config and merge it with regular one
if (isset($this->userSubmittedConfig)) {
$this->debug('Using user-submitted site config');
$this->config = $this->userSubmittedConfig;
if ($this->config->autodetect_on_failure()) {
$this->debug('Merging user-submitted site config with site config files associated with this URL and/or content');
$this->config->append($this->buildSiteConfig($url, $html));
}
} else {
$this->config = $this->buildSiteConfig($url, $html);
}
// do string replacements
if (!empty($this->config->find_string)) {
if (count($this->config->find_string) == count($this->config->replace_string)) {
$html = str_replace($this->config->find_string, $this->config->replace_string, $html, $_count);
$this->debug("Strings replaced: {$_count} (find_string and/or replace_string)");
} else {
$this->debug('Skipped string replacement - incorrect number of find-replace strings in site config');
}
unset($_count);
}
// use tidy (if it exists)?
// This fixes problems with some sites which would otherwise
// trouble DOMDocument's HTML parsing. (Although sometimes it
// makes matters worse, which is why you can override it in site config files.)
$tidied = false;
if ($this->config->tidy() && function_exists('tidy_parse_string') && $smart_tidy) {
$this->debug('Using Tidy');
$tidy = tidy_parse_string($html, self::$tidy_config, 'UTF8');
if (tidy_clean_repair($tidy)) {
$original_html = $html;
$tidied = true;
$html = $tidy->value;
}
unset($tidy);
}
// load and parse html
if ($this->parserOverride) {
// from querystring: &parser=xxx
$_parser = $this->parserOverride;
} else {
// from site config file: parser: xxx
$_parser = $this->config->parser();
}
// for backword compatibility...
if ($_parser == 'html5lib') {
$_parser = 'html5php';
}
if (!in_array($_parser, $this->allowedParsers)) {
$this->debug("HTML parser {$_parser} not listed, using " . $this->defaultParser . " instead");
$_parser = $this->defaultParser;
}
$this->debug("Attempting to parse HTML with {$_parser}");
$this->readability = new Readability($html, $url, $_parser);
// we use xpath to find elements in the given HTML document
// see http://en.wikipedia.org/wiki/XPath_1.0
$xpath = new DOMXPath($this->readability->dom);
// try to get next page link
foreach ($this->config->next_page_link as $pattern) {
$elems = @$xpath->evaluate($pattern, $this->readability->dom);
if (is_string($elems)) {
$this->nextPageUrl = trim($elems);
break;
} elseif ($elems instanceof DOMNodeList && $elems->length > 0) {
foreach ($elems as $item) {
if ($item instanceof DOMElement && $item->hasAttribute('href')) {
$this->nextPageUrl = $item->getAttribute('href');
break 2;
} elseif ($item instanceof DOMAttr && $item->value) {
$this->nextPageUrl = $item->value;
break 2;
}
}
}
}
// check if this is a native ad
foreach ($this->config->native_ad_clue as $pattern) {
$elems = @$xpath->evaluate($pattern, $this->readability->dom);
if ($elems instanceof DOMNodeList && $elems->length > 0) {
$this->nativeAd = true;
break;
}
}
// try to get title
foreach ($this->config->title as $pattern) {
// $this->debug("Trying $pattern");
$elems = @$xpath->evaluate($pattern, $this->readability->dom);
if (is_string($elems)) {
$this->title = trim($elems);
$this->debug('Title expression evaluated as string: ' . $this->title);
$this->debug("...XPath match: {$pattern}");
break;
} elseif ($elems instanceof DOMNodeList && $elems->length > 0) {
$this->title = $elems->item(0)->textContent;
$this->debug('Title matched: ' . $this->title);
$this->debug("...XPath match: {$pattern}");
// remove title from document
//.........这里部分代码省略.........
示例14: __construct
/**
* Create instance of Readability
* @param string UTF-8 encoded string
* @param string (optional) URL associated with HTML (for footnotes)
* @param string (optional) Which parser to use for turning raw HTML into a DOMDocument
* @param boolean (optional) Use tidy
*/
function __construct($html, $url = null, $parser = 'libxml', $use_tidy = true)
{
$this->url = $url;
$this->debugText = 'Parsing URL: ' . $url . "\n";
if ($url) {
$this->domainRegExp = '/' . strtr(preg_replace('/www\\d*\\./', '', parse_url($url)['host']), array('.' => '\\.')) . '/';
}
mb_internal_encoding("UTF-8");
mb_http_output("UTF-8");
mb_regex_encoding("UTF-8");
$this->imageCache = new ImageCaching();
// HACK: dirty cleanup to replace some stuff; shouldn't use regexps with HTML but well...
if (!$this->flagIsActive(self::FLAG_DISABLE_PREFILTER)) {
try {
foreach ($this->pre_filters as $search => $replace) {
$html = preg_replace($search, $replace, $html);
}
unset($search, $replace);
} catch (Exception $e) {
$this->debugText .= "Cleaning raw HTML failed. Ignoring: " . $e->getMessage();
}
}
if (trim($html) === '') {
$html = '<html></html>';
}
/**
* Use tidy (if it exists).
* This fixes problems with some sites which would otherwise trouble DOMDocument's HTML parsing.
* Although sometimes it makes matters worse, which is why there is an option to disable it.
*
**/
if ($use_tidy && function_exists('tidy_parse_string')) {
$this->debugText .= 'Tidying document' . "\n";
$tidy = tidy_parse_string($html, $this->tidy_config, 'UTF8');
if (tidy_clean_repair($tidy)) {
$original_html = $html;
$this->tidied = true;
$html = $tidy->value;
$html = preg_replace('/<html[^>]+>/i', '<html>', $html);
$html = preg_replace('/[\\r\\n]+/is', "\n", $html);
}
unset($tidy);
}
$html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
if ($parser == 'html5lib' && ($this->dom = HTML5_Parser::parse($html))) {
// all good
} else {
libxml_use_internal_errors(true);
$this->dom = new DOMDocument();
$this->dom->preserveWhiteSpace = false;
@$this->dom->loadHTML($html, LIBXML_NOBLANKS | LIBXML_COMPACT | LIBXML_NOERROR);
}
$this->dom->registerNodeClass('DOMElement', 'JSLikeHTMLElement');
}
示例15: nexista_devBuffer
function nexista_devBuffer($init)
{
$init->process();
ob_start();
ob_start();
header('Cache-Control: no-cache, must-revalidate');
header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
nexista_development_console();
$output = $init->run();
if (isset($_GET['view_flow'])) {
if ($_GET['view_flow'] == 'true') {
nexista_view_flow();
}
}
if ($_GET['client_view_flow'] == 'true') {
$mynid = $_GET['nid'];
$_SESSION['client_view_flow'] = 'true';
} elseif ($_GET['client_view_flow'] == 'false') {
$mynid = $_GET['nid'];
$_SESSION['client_view_flow'] = 'false';
}
if ($_SESSION['client_view_flow'] == 'true') {
$flow_viewport = nexista_view_flow();
}
$output = str_replace('</body>', '', $output);
$output = str_replace('</html>', '', $output);
$output .= $flow_viewport;
$output .= nexista_final_notices($cache_type, 'dev');
$output .= '</body></html>';
$tidy = false;
if ($tidy == 'xhtml') {
$options = array('output-xhtml' => true, 'indent' => true, 'input-encoding' => 'utf8', 'output-encoding' => 'utf8', 'clean' => true);
$output = tidy_parse_string($output, $options);
tidy_clean_repair($output);
}
if ($tidy == 'html') {
$options = array('output-html' => true, 'indent' => true, 'input-encoding' => 'utf8', 'output-encoding' => 'utf8', 'clean' => true);
$output = tidy_parse_string($output, $options);
tidy_clean_repair($output);
}
echo $output;
ob_end_flush();
header('Content-Length: ' . ob_get_length());
ob_end_flush();
}