/** * Extract information from the <link> elements * * @param \DOMDocument $html * @param Bag $bag */ protected static function extractFromLink(\DOMDocument $html, Bag $bag) { foreach (Utils::getLinks($html) as $link) { list($rel, $href, $element) = $link; if (empty($href)) { continue; } switch ($rel) { case 'favicon': case 'favico': case 'icon': case 'shortcut icon': case 'apple-touch-icon-precomposed': case 'apple-touch-icon': $bag->add('icons', $href); break; case 'image_src': $bag->add('images', $href); break; case 'alternate': switch ($element->getAttribute('type')) { case 'application/rss+xml': case 'application/atom+xml': $bag->add('feeds', $href); break; } break; default: $bag->set($rel, $href); } } }
/** * Extract oembed information from the <link rel="alternate"> elements * Note: Some sites use <meta rel="alternate"> instead * * @param \DOMDocument $html * * @return string|null */ protected static function getEndPointFromDom(\DOMDocument $html) { foreach (['link', 'meta'] as $tagName) { foreach (Utils::getLinks($html, $tagName) as $link) { list($rel, $href, $element) = $link; if (empty($href)) { continue; } if ($rel === 'alternate') { switch (strtolower($element->getAttribute('type'))) { case 'application/json+oembed': case 'application/xml+oembed': case 'text/json+oembed': case 'text/xml+oembed': return $href; } } } } }