#551: Minimal implementation of a Tidy HTML filter
-----------------------------+----------------------------------------------
Reporter: [EMAIL PROTECTED] | Owner: david
Type: defect | Status: new
Priority: lowest | Milestone: 1.0
Component: filter | Version: 0.11.0RC5
Severity: trivial | Keywords: html validation cleanup tidy
global filter content output response
-----------------------------+----------------------------------------------
This is a minimal implementation of a Tidy-based HTML filter. It requires
the Tidy extension to be installed. It does not do extensive error
checking and it does not have parameters. With current settings, the HTML
is cleaned, repaired and indented to 132 characters.
<?php
/**
* HtmlTidyFilter is a primitive filter that uses Tidy to clean up your
HTML output.
*
* @author Mike Seth <[EMAIL PROTECTED]>
* @copyright Mike Seth <[EMAIL PROTECTED]>
* @version $Id$
*/
class HtmlTidyFilter extends AgaviFilter implements AgaviIGlobalFilter
{
public function executeOnce(AgaviFilterChain $filterChain,
AgaviExecutionContainer $container)
{
$filterChain->execute($container);
$response = $container->getResponse();
if(!$response->isContentMutable() || !($output =
$response->getContent()) || !class_exists('Tidy')) {
return;
}
$html = $output;
$config = array('indent' => true, 'output-xhtml' => true,
'wrap' => 132);
$tidy = new Tidy;
if (! $tidy->parseString($output, $config, 'utf8'))
throw new AgaviException("Tidy parsing failed.");
if (! $tidy->cleanRepair())
throw new AgaviException("Tidy cleanup failed.");
$response->setContent((string) $tidy);
}
}
--
Ticket URL: <http://trac.agavi.org/ticket/551>
Agavi <http://www.agavi.org/>
An MVC Framework for PHP5
_______________________________________________
Agavi Tickets Mailing List
[email protected]
http://lists.agavi.org/mailman/listinfo/tickets