Example #1
0
 /**
  * Filter a \DOMNode according to this filter's logic
  *
  * @param \DOMNode $node
  * @return string|null If a string, it should be a GO or STOP message
  */
 public function filter(\DOMNode $node)
 {
     if ($this->_sanitize($node) == AbstractFilter::GO) {
         return AbstractFilter::GO;
     }
     $replacementText = Wibble\Utility::nodeToString($node);
     $replacementNode = $node->ownerDocument->createTextNode($replacementText);
     $parent = $node->parentNode;
     $parent->insertBefore($replacementNode, $node);
     $parent->removeChild($node);
 }
Example #2
0
 /**
  * Convert this Wibble\HTML\Document to serialised HTML/XHTML string
  *
  * @return string
  */
 public function toString()
 {
     $xpath = new \DOMXPath($this->getDOM());
     $result = $xpath->query('/html/body');
     if ($result->length == 0) {
         return '';
     }
     $output = $this->_getInnerHTML($result->item(0));
     $output = $this->_htmlEntityDecode($output, 'UTF-8');
     if (!class_exists('\\tidy') && !$this->_options['disable_tidy']) {
         throw new Wibble\Exception('It is highly recommended that Wibble operate with support from' . ' the PHP Tidy extension to ensure output wellformedness. If' . ' you are unable to install this extension you may explicitly' . ' disable Tidy support by setting the disable_tidy configuration' . ' option to FALSE. Without ext/tidy enabled, output is in no' . ' way guaranteed to comply entirely to the target HTML standard.');
     } elseif ($this->_options['disable_tidy']) {
         $output = Wibble\Utility::convertFromUTF8($output, $this->_options['output_encoding']);
         return $output;
     }
     $output = $this->_applyTidy($output, true);
     return $output = Wibble\Utility::convertFromUTF8($output, $this->_options['output_encoding']);
 }
Example #3
0
 /**
  * Based on instance parameters, load the source markup into a \DOMDocument
  *
  * @param string $markup
  * @return void
  */
 protected function _load($markup)
 {
     $markup = Wibble\Utility::convertToUTF8($markup, $this->_options['input_encoding']);
     $markup = Wibble\Utility::insertCharset($markup, 'UTF-8');
     $dom = new \DOMDocument();
     $dom->preserveWhitespace = false;
     libxml_use_internal_errors(true);
     $dom->loadHTML($markup);
     libxml_use_internal_errors(false);
     $this->_dom = $dom;
 }