$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) {
if (!$src|| !strlen(trim($src))) {
continue;
}
-
+
if (0 === strpos($src, 'data:')) {
if (!$obj) {
HTML_FlexyFramework::get()->page->jerr("no object to attach data url");
}
- $anchors = $doc->getElementsByTagName('a');
+ $anchors = $dom->getElementsByTagName('a');
$result = array();
preg_match_all('/<a\s+[^>]+>/i',$html, $result);
$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;
}
$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';
}
}
+
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)