Images.php
[Pman.Core] / Images.php
index 61d1f9a..327fa8c 100644 (file)
@@ -409,9 +409,9 @@ class Pman_Core_Images extends Pman
         $baseURL = $ff->Pman_Images['public_baseURL'];
         
         libxml_use_internal_errors(true);
-        $doc = new DOMDocument();
-        $doc->loadHTML($html);
-        $imgs = $doc->getElementsByTagName('img');
+        $dom = new DOMDocument();
+        $dom->loadHTML("<?xml encoding='utf-8'?> <div id='tmp_dom_wrapper'>{$html}</div>");
+        $imgs = $dom->getElementsByTagName('img');
        
         
         foreach($imgs as $img) {
@@ -419,7 +419,7 @@ class Pman_Core_Images extends Pman
             if (!$src|| !strlen(trim($src))) {
                 continue;
             }
-            
+             
             if (0 === strpos($src, 'data:')) {
                 if (!$obj) {
                     HTML_FlexyFramework::get()->page->jerr("no object to attach data url");
@@ -442,7 +442,7 @@ class Pman_Core_Images extends Pman
             
         }
         
-        $anchors = $doc->getElementsByTagName('a');
+        $anchors = $dom->getElementsByTagName('a');
         $result = array();
         preg_match_all('/<a\s+[^>]+>/i',$html, $result); 
 
@@ -455,6 +455,12 @@ class Pman_Core_Images extends Pman
             $anc->setAttribute('href', self::domImgUrl($baseURL, $href));
         }
         
+        
+        $inner = $dom->getElementById("tmp_dom_wrapper");
+        $html = '';
+        foreach ($inner->childNodes as $child) {
+            $html .= ($dom->saveHTML($child));
+        }
         return $html;
     }
     
@@ -491,13 +497,16 @@ class Pman_Core_Images extends Pman
             $provider = '/'.$umatch[1];
         }
         
-        if (!empty($attr['width']) || !empty($attr['height']) )
+        $w =  is_string($dom) ? false : $dom->getAttribute('width');
+        $h =  is_string($dom) ? false : $dom->getAttribute('width');
+        
+        if (!is_string($dom) && (!empty($w) || !empty($h)) )
         {
             // no support for %...
             $thumbsize =
-                (empty($attr['width']) ? '0' : $attr['width'] * 1) .
+                (empty($w) ? '0' : $w * 1) .
                 'x' .
-                (empty($attr['height']) ? '0' : $attr['height'] * 1);
+                (empty($h) ? '0' : $h * 1);
              $provider = '/Images/Thumb';
             
         }
@@ -524,9 +533,15 @@ class Pman_Core_Images extends Pman
         
          
     }
+    
     static function replaceDataUrl($baseURL, $img, $obj)
     {
+        $d = DB_DataObject::Factory('Images');
+        $d->object($obj);
+        
         
+        $d->createFromData($img->getAttribute('src'));
+        $img->setAttribute('src', $d->URL(-1, '/Images' , $baseURL));
     }
     
     static function replaceImgUrl($html, $baseURL, $tag, $attr, $attr_name)