Pressbooks\Modules\Export\Epub\Epub201::kneadHref PHP Метод

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

Change hrefs
protected kneadHref ( DOMDocument $doc, string $type, integer $pos ) : DOMDocument
$doc DOMDocument
$type string front-matter, part, chapter, back-matter, ...
$pos integer (optional) position of content, used when creating filenames like: chapter-001, chapter-002, ...
Результат DOMDocument
    protected function kneadHref(\DOMDocument $doc, $type, $pos)
    {
        $urls = $doc->getElementsByTagName('a');
        foreach ($urls as $url) {
            $current_url = '' . $url->getAttribute('href');
            // Stringify
            // Don't touch empty urls
            if (!trim($current_url)) {
                continue;
            }
            // WordPress auto wraps images in a href tags.
            // For example: <a href="some_image-original.png"><img src="some_image-300x200.png" /></a>
            // This causes an EPUB validation error of: hyperlink to non-standard resource ( of type 'image/...' )
            // We fix this by removing the href
            if ($url->childNodes->length) {
                foreach ($url->childNodes as $node) {
                    if ('img' == $node->nodeName && $this->fuzzyImageNameMatch($current_url, $node->getAttribute('src'))) {
                        $url->removeAttribute('href');
                        continue 2;
                    }
                }
            }
            // Determine if we are trying to link to our own internal content
            $internal_url = $this->fuzzyHrefMatch($current_url, $type, $pos);
            if (false !== $internal_url) {
                $url->setAttribute('href', $internal_url);
                continue;
            }
            // Canonicalize, fix typos, remove garbage
            if ('#' != @$current_url[0]) {
                $url->setAttribute('href', \Pressbooks\Sanitize\canonicalize_url($current_url));
            }
        }
        return $doc;
    }