05.21 php saved
Sliv
Tags add more
bakery tidy html fil  
Note
A modified approach to http://bakery.cakephp.org/articles/view/tidy-output-filtering
  1. <?php
  2. class TidyHelper extends AppHelper {
  3.  
  4.     function __construct() {
  5.         if (class_exists('Tidy')) {
  6.             ob_start();
  7.         }
  8.     }
  9.  
  10.     function __destruct() {
  11.         if (class_exists('Tidy')) {
  12.             $output = ob_get_clean();
  13.             $Tidy = new Tidy();
  14.             $tidyConfig = array(
  15.                 'doctype' => 'strict',
  16.                 'drop-empty-paras' => true,
  17.                 'drop-font-tags' => true,
  18.                 'drop-proprietary-attributes' => true,
  19.                 'enclose-block-text' => true,
  20.                 'enclose-text' => true,
  21.                 'hide-comments' => false,
  22.                 'hide-endtags' => true,
  23.                 'indent' => true,
  24.                 'logical-emphasis' => true,
  25.                 'lower-literals' => true,
  26.                 'markup' => true,
  27.                 'output-xhtml' => true,
  28.                 'quote-ampersand' => true,
  29.                 'quote-marks' => true,
  30.                 'quote-nbsp' => true,
  31.                 'show-warnings' => true,
  32.                 'wrap' => 150
  33.             );
  34.             $Tidy->parseString($output, $tidyConfig, 'utf8');
  35.             $Tidy->diagnose();
  36.             $Tidy->cleanRepair();
  37.             $output = tidy_get_output($Tidy);
  38.             if ($Tidy->errorBuffer && Configure::read('debug') > 0) {
  39.                 $output = str_replace('</body>', '<pre id="tidy">' . htmlspecialchars($Tidy->errorBuffer) . "</pre>\n</body>", $output);
  40.             }
  41.             ob_start();
  42.             echo $output;
  43.         }
  44.     }
  45.  
  46. }
  47. ?>
Parsed in 0.092 seconds, using GeSHi 1.0.7.14

Modify this Paste