@$dom->loadHTML('<?xml encoding="UTF-8">' .$html);
$imgs= $dom->getElementsByTagName('img');
- $test = array();
-
- foreach ($imgs as $i=>$img) {
- $url = $img->getAttribute('src');
- if (preg_match('#^cid:#', $url)) {
- continue;
- }
- $me = $img->getAttribute('mailembed');
- if ($me == 'no') {
- continue;
- }
- $test[] = $url;
- }
-
- print_R($test);exit;
+ $urls = array();
foreach ($imgs as $i=>$img) {
$url = $img->getAttribute('src');
continue;
}
- $conv = $this->fetchImage($url);
- $this->images[$conv['contentid']] = $conv;
+ if(!array_key_exists($url, $urls)){
+ $conv = $this->fetchImage($url);
+ $urls[$url] = $conv;
+ $this->images[$conv['contentid']] = $conv;
+ } else {
+ $conv = $urls[$url];
+ }
$img->setAttribute('src', 'cid:' . $conv['contentid']);
-
-
}
- return $dom->saveHTML();
-
+ return $dom->saveHTML();
}
function htmlbodyCssEmbed($html)
$body = $dom->getElementsByTagName('body');
- $class = $dom->createAttribute('class');
- $class->value = $cls;
- $body->item(0)->appendChild($class);
+ $body->setAttribute('class', $cls);
+
return $dom->saveHTML();
}