|
HTMLPurifier 4.4.0
|
00001 <?php 00002 00006 class ConfigDoc_HTMLXSLTProcessor 00007 { 00008 00012 protected $xsltProcessor; 00013 00014 public function __construct($proc = false) { 00015 if ($proc === false) $proc = new XSLTProcessor(); 00016 $this->xsltProcessor = $proc; 00017 } 00018 00022 public function importStylesheet($xsl) { 00023 if (is_string($xsl)) { 00024 $xsl_file = $xsl; 00025 $xsl = new DOMDocument(); 00026 $xsl->load($xsl_file); 00027 } 00028 return $this->xsltProcessor->importStylesheet($xsl); 00029 } 00030 00037 public function transformToHTML($xml) { 00038 if (is_string($xml)) { 00039 $dom = new DOMDocument(); 00040 $dom->load($xml); 00041 } else { 00042 $dom = $xml; 00043 } 00044 $out = $this->xsltProcessor->transformToXML($dom); 00045 00046 // fudges for HTML backwards compatibility 00047 // assumes that document is XHTML 00048 $out = str_replace('/>', ' />', $out); // <br /> not <br/> 00049 $out = str_replace(' xmlns=""', '', $out); // rm unnecessary xmlns 00050 00051 if (class_exists('Tidy')) { 00052 // cleanup output 00053 $config = array( 00054 'indent' => true, 00055 'output-xhtml' => true, 00056 'wrap' => 80 00057 ); 00058 $tidy = new Tidy; 00059 $tidy->parseString($out, $config, 'utf8'); 00060 $tidy->cleanRepair(); 00061 $out = (string) $tidy; 00062 } 00063 00064 return $out; 00065 } 00066 00071 public function setParameters($options) { 00072 foreach ($options as $name => $value) { 00073 $this->xsltProcessor->setParameter('', $name, $value); 00074 } 00075 } 00076 00080 public function __call($name, $arguments) { 00081 call_user_func_array(array($this->xsltProcessor, $name), $arguments); 00082 } 00083 00084 } 00085 00086 // vim: et sw=4 sts=4