PressBooks\Modules\Import\Epub\Epub201::scrapeAndKneadImages PHP Метод

scrapeAndKneadImages() защищенный Метод

Parse HTML snippet, save all found tags using media_handle_sideload(), return the HTML with changed paths.
protected scrapeAndKneadImages ( DOMDocument $doc, string $href ) : DOMDocument
$doc DOMDocument
$href string original filename, with (relative) path
Результат DOMDocument
    protected function scrapeAndKneadImages(\DOMDocument $doc, $href)
    {
        $images = $doc->getElementsByTagName('img');
        foreach ($images as $image) {
            // Fetch image, change src
            $old_src = $image->getAttribute('src');
            $new_src = $this->fetchAndSaveUniqueImage($old_src, $href);
            if ($new_src) {
                // Replace with new image
                $image->setAttribute('src', $new_src);
            } else {
                // Tag broken image
                $image->setAttribute('src', "{$old_src}#fixme");
            }
        }
        return $doc;
    }