The intention of this code is that an the HTML-attribute 'data-original-src' is added to the img-tag, in case of unsecure http:// URL's. But this attribute is not generated.
What's wrong, and what mistake do I overlook? Anyway, the str_replace() is working like a charm.
public function parse($string) {
if($this->settings['camo_enabled'] == true) {
$doc = new DOMDocument();
$doc->loadHTML($string);
$images = $doc->getElementsByTagName('img');
//$imgarray = array();
foreach ($images as $image) {
$url = $image->getAttribute('src');
if(substr($url, 0, 8) != 'https://') {
$image->setAttribute('data-original-src', $url);
$camo = $this->proxy_url($url);
$string = str_replace($image->getAttribute('src'), $camo, $string);
unset($url, $camo);
}
}
}
return $string;
}