From 3746ff51f35e6e1c1ac07d74029ee8bf59174405 Mon Sep 17 00:00:00 2001 From: Jayenne Montana Date: Thu, 14 Oct 2021 10:15:53 +0100 Subject: [PATCH 1/3] Update OpenGraph.php Added `title` tag to the metadata. This will be overwritten should the uri include a mata tag by the name `title` (which is arguably preferred as an owner given meta title). --- src/OpenGraph.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/OpenGraph.php b/src/OpenGraph.php index a3e69e3..1780517 100644 --- a/src/OpenGraph.php +++ b/src/OpenGraph.php @@ -27,6 +27,12 @@ public function fetch($url, $allMeta = null, $lang = null, $options = LIBXML_NOW $tags = $doc->getElementsByTagName('meta'); $metadata = []; + + if ($allMeta) { + $title = $doc->getElementsByTagName('title'); + $metadata['title'] = $title->length > 0 ? $title->item(0)->textContent : null ; + } + foreach ($tags as $tag) { $metaproperty = ($tag->hasAttribute('property')) ? $tag->getAttribute('property') : $tag->getAttribute('name'); if (!$allMeta && $metaproperty && strpos($tag->getAttribute('property'), 'og:') === 0) { From 875ba6d6406632f3c233db6a3124be1c28fd39b1 Mon Sep 17 00:00:00 2001 From: Jayenne Montana Date: Thu, 14 Oct 2021 15:38:04 +0100 Subject: [PATCH 2/3] Add default $metadata['title'] from tag. --- src/OpenGraph.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenGraph.php b/src/OpenGraph.php index 1780517..fac1a01 100644 --- a/src/OpenGraph.php +++ b/src/OpenGraph.php @@ -28,7 +28,7 @@ public function fetch($url, $allMeta = null, $lang = null, $options = LIBXML_NOW $tags = $doc->getElementsByTagName('meta'); $metadata = []; - if ($allMeta) { + if ($allMeta && !empty($doc->getElementsByTagName('title'))) { $title = $doc->getElementsByTagName('title'); $metadata['title'] = $title->length > 0 ? $title->item(0)->textContent : null ; } From 2ab903833182d6bc86f76c48dcfbd0af292e1460 Mon Sep 17 00:00:00 2001 From: Jayenne Montana <jayenne@hotmail.com> Date: Thu, 14 Oct 2021 15:42:21 +0100 Subject: [PATCH 3/3] no message --- src/OpenGraph.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenGraph.php b/src/OpenGraph.php index fac1a01..5b86ff2 100644 --- a/src/OpenGraph.php +++ b/src/OpenGraph.php @@ -30,7 +30,7 @@ public function fetch($url, $allMeta = null, $lang = null, $options = LIBXML_NOW if ($allMeta && !empty($doc->getElementsByTagName('title'))) { $title = $doc->getElementsByTagName('title'); - $metadata['title'] = $title->length > 0 ? $title->item(0)->textContent : null ; + $metadata['title'] = $title->length > 0 ? $title->item(0)->textContent : null; } foreach ($tags as $tag) {