private function parse_html_images($content)
{
$images = array();
if (!class_exists('DOMDocument')) {
return $images;
}
if (empty($content)) {
return $images;
}
// Prevent DOMDocument from bubbling warnings about invalid HTML.
libxml_use_internal_errors(true);
$post_dom = new DOMDocument();
$post_dom->loadHTML('<?xml encoding="' . $this->charset . '">' . $content);
// Clear the errors, so they don't get kept in memory.
libxml_clear_errors();
/** @var DOMElement $img */
foreach ($post_dom->getElementsByTagName('img') as $img) {
$src = $img->getAttribute('src');
if (empty($src)) {
continue;
}
$class = $img->getAttribute('class');
if (!empty($class) && false === strpos($class, 'size-full') && preg_match('|wp-image-(?P<id>\\d+)|', $class, $matches) && get_post_status($matches['id'])) {
$src = $this->image_url($matches['id']);
}
$src = $this->get_absolute_url($src);
if (strpos($src, $this->host) === false) {
continue;
}
if ($src !== esc_url($src)) {
continue;
}
$images[] = array('src' => $src, 'title' => $img->getAttribute('title'), 'alt' => $img->getAttribute('alt'));
}
return $images;
}