Example #1
0
 public function preprocess($html)
 {
     $obj = $this->delegate();
     if (isset($obj) and method_exists($obj, 'fixHtml')) {
         $html = $obj->fixHtml($html);
     }
     require_once 'inc/SweteTools.php';
     try {
         $doc = SweteTools::loadHtml($html);
     } catch (Exception $ex) {
         return $html;
     }
     if (isset($obj) and method_exists($obj, 'preprocess')) {
         $obj->preprocess($doc);
     }
     $xpath = new DOMXPath($doc);
     $txt = $xpath->query('//text()');
     if ($txt->length > 0) {
         foreach ($txt as $txtEl) {
             if (in_array(strtolower($txtEl->parentNode->tagName), array('style', 'title', 'script'))) {
                 continue;
             }
             if ($txtEl->parentNode->getAttribute('data-swete-text-filter') === 'disabled') {
                 continue;
             }
             if (!trim($txtEl->nodeValue)) {
                 continue;
             }
             $count = 0;
             $nodeValue = $this->_processText(htmlspecialchars($txtEl->nodeValue), 0, $count);
             if ($count > 0) {
                 $f = $doc->createDocumentFragment();
                 $fres = $f->appendXML($nodeValue);
                 $txtEl->parentNode->replaceChild($f, $txtEl);
             }
         }
     }
     return $doc->saveHtml();
 }
Example #2
0
 public function htmlToJson(array &$json, $html)
 {
     $doc = SweteTools::loadHtml($html);
     $keys = $this->_getJsonKeys($json);
     $this->_htmlToJson($doc, $json, $keys['text'], $keys['html']);
     $this->_scriptStack = array();
     return json_encode($json);
 }