diff --git a/src/classes/emebd-uri-interface.php b/src/classes/emebd-uri-interface.php new file mode 100644 index 00000000..c6e37356 --- /dev/null +++ b/src/classes/emebd-uri-interface.php @@ -0,0 +1,39 @@ +extractor->getOEmbed(); + + return $oembed->url('url') + ?: $oembed->url('web_page') + ?: $this->getCanonical() + ?: $this->extractor->getUri(); + } + + protected function getCanonical(): ?UriInterface + { + $document = $this->extractor->getDocument(); + + foreach ($document->select('.//link[@canonical]')->nodes() as $node) { + $href = $node->getAttribute('href'); + + if ($href) { + return $this->extractor->resolveUri($href); + } + } + + return null; + } +}