Exemple #1
0
 public function saveHtml($refresh = true)
 {
     if (extension_loaded('xml') and class_exists('DomXpath')) {
         if (get_parent_class($this) === __CLASS__) {
             $node = $this->node;
         } elseif (get_parent_class($this) === false) {
             $node = $this;
         } else {
             return false;
         }
         if (!is_a($node, jqmel)) {
             return false;
         }
         if ($node->_length === false) {
             return false;
         }
         $docm = jqm_use($node->_parentElement);
         //$docm->__documentRaw = preg_replace('/\s+/',' ',$docm->__documentRaw);
         $doc = $docm->_DOM;
         if ($doc->doctype) {
             $doc->removeChild($doc->doctype);
         }
         $k = key($this->_domId);
         if ($refresh == true) {
             $this->refresh();
             $node->_attributes['data-dom-id'] = $k;
         } else {
             if ($this->_domId[$k] === NULL) {
                 $attr = $node->_attributes;
                 unset($attr['data-dom-id']);
                 $node->_attributes = $attr;
             } else {
                 $node->_attributes['data-dom-id'] = $this->_domId[$k];
             }
         }
         $newdoc = new domDocument();
         $dom = $node->dom()->get();
         $newdoc->loadhtml(mb_convert_encoding($dom->lastdom, 'HTML-ENTITIES', 'UTF-8'));
         $newdoc->removeChild($newdoc->doctype);
         $newdoc_get = $newdoc->getElementsByTagName($node->_name);
         //Finder
         $xpath = new DomXpath($doc);
         $find = $xpath->query($node->_path);
         if ($find->length > 0) {
             $frag = $doc->importNode($newdoc_get->item(0), true);
             if ($find->item(0)->parentNode) {
                 $find->item(0)->parentNode->replaceChild($frag, $find->item(0));
             }
             /* $output = $doc->saveHTML();
             					
             					$hasHTML = (strip_tags($docm->__documentRaw,'<html>') !==$docm->__documentRaw);
             					
             			if($hasHTML===false){
             				
             				//Return just a partial html
             				$docm->__documentRaw = str_ireplace(array('<html>','<body>','</html>','</body>','<head>','</head>'),'',$output);
             			}else{
             				$docm->__documentRaw = $output;
             			} */
             $node->_attributes['data-dom-id'] = $this->_domId[$k];
             return $frag->getNodepath();
         }
     }
 }