]> git.mxchange.org Git - friendica.git/commitdiff
Remove duplicate curl call in Network\Probe::getFeedLink
authorHypolite Petovan <hypolite@mrpetovan.com>
Thu, 21 May 2020 04:23:14 +0000 (00:23 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 21 May 2020 04:25:48 +0000 (00:25 -0400)
- Add page body argument instead
- Expand method scope to allow tests

src/Network/Probe.php

index edcb9f4c342c0e2989d605ec64a9e22a425b7e5f..65ce67d6bf89e6e8fdf53f5116b596dcef7de8b5 100644 (file)
@@ -1756,25 +1756,20 @@ class Probe
        }
 
        /**
-        * Check page for feed link
+        * Checks HTML page for RSS feed link
         *
-        * @param string $url Page link
-        *
-        * @return string feed link
+        * @param string $url  Page link
+        * @param string $body Page body string
+        * @return string|false Feed link or false if body was invalid HTML document
         */
-       private static function getFeedLink($url)
+       public static function getFeedLink(string $url, string $body)
        {
-               $curlResult = Network::curl($url);
-               if (!$curlResult->isSuccess()) {
-                       return false;
-               }
-
                $doc = new DOMDocument();
-               if (!@$doc->loadHTML($curlResult->getBody())) {
+               if (!@$doc->loadHTML($body)) {
                        return false;
                }
 
-               $xpath = new DomXPath($doc);
+               $xpath = new DOMXPath($doc);
 
                //$feeds = $xpath->query("/html/head/link[@type='application/rss+xml']");
                $feeds = $xpath->query("/html/head/link[@type='application/rss+xml' and @rel='alternate']");
@@ -1826,7 +1821,7 @@ class Probe
                                return false;
                        }
 
-                       $feed_url = self::getFeedLink($url);
+                       $feed_url = self::getFeedLink($url, $feed);
 
                        if (!$feed_url) {
                                return false;