From 3c4c1ce8c010273c08abe2fad4a85baed7fd741d Mon Sep 17 00:00:00 2001 From: Thomas T Date: Wed, 30 Sep 2020 21:41:46 +0200 Subject: [PATCH 1/5] Added custom user-agent --- src/OpenGraph.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OpenGraph.php b/src/OpenGraph.php index a182657..1c7bf4b 100644 --- a/src/OpenGraph.php +++ b/src/OpenGraph.php @@ -7,9 +7,9 @@ class OpenGraph { - public function fetch($url, $allMeta = null, $lang = null, $options = LIBXML_NOWARNING | LIBXML_NOERROR) + public function fetch($url, $allMeta = null, $lang = null, $options = LIBXML_NOWARNING | LIBXML_NOERROR, $userAgent = 'Curl') { - $html = $this->curl_get_contents($url, $lang); + $html = $this->curl_get_contents($url, $lang, $userAgent); /** * parsing starts here:. */ @@ -54,12 +54,12 @@ public function fetch($url, $allMeta = null, $lang = null, $options = LIBXML_NOW return $metadata; } - protected function curl_get_contents($url, $lang) + protected function curl_get_contents($url, $lang, $userAgent) { $headers = [ 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Cache-Control: no-cache', - 'User-Agent: Curl', + 'User-Agent: ' . $userAgent, ]; if ($lang) { From 8a54e1323fc7be16d183f28a7a7174dfaa39552c Mon Sep 17 00:00:00 2001 From: Thomas T Date: Wed, 30 Sep 2020 22:07:19 +0200 Subject: [PATCH 2/5] Moved parameter position --- src/OpenGraph.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenGraph.php b/src/OpenGraph.php index 1c7bf4b..751bda9 100644 --- a/src/OpenGraph.php +++ b/src/OpenGraph.php @@ -7,7 +7,7 @@ class OpenGraph { - public function fetch($url, $allMeta = null, $lang = null, $options = LIBXML_NOWARNING | LIBXML_NOERROR, $userAgent = 'Curl') + public function fetch($url, $allMeta = null, $lang = null, $userAgent = 'Curl', $options = LIBXML_NOWARNING | LIBXML_NOERROR) { $html = $this->curl_get_contents($url, $lang, $userAgent); /** From 0f8231854d04afc3edd8ffa06d13d4121c1d0b54 Mon Sep 17 00:00:00 2001 From: Thomas T Date: Thu, 1 Oct 2020 06:48:41 +0200 Subject: [PATCH 3/5] Style fix --- src/OpenGraph.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenGraph.php b/src/OpenGraph.php index 751bda9..9f079d2 100644 --- a/src/OpenGraph.php +++ b/src/OpenGraph.php @@ -59,7 +59,7 @@ protected function curl_get_contents($url, $lang, $userAgent) $headers = [ 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Cache-Control: no-cache', - 'User-Agent: ' . $userAgent, + 'User-Agent: '.$userAgent ]; if ($lang) { From 73b62ec9de09523c6b3d7d63c867230385304450 Mon Sep 17 00:00:00 2001 From: Thomas T Date: Thu, 1 Oct 2020 06:50:53 +0200 Subject: [PATCH 4/5] Style fix for real --- src/OpenGraph.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenGraph.php b/src/OpenGraph.php index 9f079d2..1348a01 100644 --- a/src/OpenGraph.php +++ b/src/OpenGraph.php @@ -59,7 +59,7 @@ protected function curl_get_contents($url, $lang, $userAgent) $headers = [ 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Cache-Control: no-cache', - 'User-Agent: '.$userAgent + 'User-Agent: '.$userAgent, ]; if ($lang) { From 85763a0221beb6e1ef52dcc2adce73cc62ca3588 Mon Sep 17 00:00:00 2001 From: Thomas T Date: Thu, 1 Oct 2020 07:55:23 +0200 Subject: [PATCH 5/5] Moved parameter and added description in readme --- README.md | 4 ++++ src/OpenGraph.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c826728..20ee165 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,10 @@ If you do run the package on Laravel 5.5+, package auto-discovery takes care of ``` $data = OpenGraph::fetch($url, $allMeta, $language, $options); ``` + You can use the fifth parameter to set the user-agent ($userAgent) of the request. The default is 'Curl'. + ``` + $data = OpenGraph::fetch($url, $allMeta, $language, $options, $userAgent); + ``` ### Exception Handling diff --git a/src/OpenGraph.php b/src/OpenGraph.php index 1348a01..03eef9e 100644 --- a/src/OpenGraph.php +++ b/src/OpenGraph.php @@ -7,7 +7,7 @@ class OpenGraph { - public function fetch($url, $allMeta = null, $lang = null, $userAgent = 'Curl', $options = LIBXML_NOWARNING | LIBXML_NOERROR) + public function fetch($url, $allMeta = null, $lang = null, $options = LIBXML_NOWARNING | LIBXML_NOERROR, $userAgent = 'Curl') { $html = $this->curl_get_contents($url, $lang, $userAgent); /**