From c500a3d9d88ec1bf4b80b8e6843acdcb3779119c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Rodrigo=20Cal=C3=B3gero?= Date: Tue, 6 Sep 2022 03:07:27 -0300 Subject: [PATCH 1/2] Added default user-agent (#16) Shopify doesn't accept a CURL without `CURLOPT_USERAGENT` option, it returns `403 Forbidden` instead. --- src/Feed.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Feed.php b/src/Feed.php index 8fcba58..3a59c27 100644 --- a/src/Feed.php +++ b/src/Feed.php @@ -218,6 +218,7 @@ private static function httpRequest($url, $user, $pass) curl_setopt($curl, CURLOPT_TIMEOUT, 20); curl_setopt($curl, CURLOPT_ENCODING, ''); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // no echo, just return result + curl_setopt($curl, CURLOPT_USERAGENT, ''); if (!ini_get('open_basedir')) { curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // sometime is useful :) } From ab13f8f82091d5c54206a3223e68178340a9bfc5 Mon Sep 17 00:00:00 2001 From: Zorn Date: Fri, 8 Sep 2023 16:41:09 -0600 Subject: [PATCH 2/2] feat: handle broken XML documents --- src/Feed.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Feed.php b/src/Feed.php index 3a59c27..6a46488 100644 --- a/src/Feed.php +++ b/src/Feed.php @@ -193,7 +193,14 @@ private static function loadXml($url, $user, $pass) throw new FeedException('Cannot load feed.'); } - return new SimpleXMLElement($data, LIBXML_NOWARNING | LIBXML_NOERROR | LIBXML_NOCDATA); + $doc = new DOMDocument(); + $doc->loadXML($data, LIBXML_NOWARNING | LIBXML_NOERROR | LIBXML_NOCDATA); + + if ($doc->documentElement !== NULL) { + return new SimpleXMLElement($doc->saveXML(), LIBXML_NOWARNING | LIBXML_NOERROR | LIBXML_NOCDATA); + } else { + return new SimpleXMLElement('', LIBXML_NOWARNING | LIBXML_NOERROR); + } }