]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/ParseUrl.php
[Scrutinizer] Fix undeclared variables in src/ (except Protocol/)
[friendica.git] / src / Util / ParseUrl.php
index 7154e0f4af94bd0354f0c8bac4e405eba1e512e3..b267c610864326ed216d7e90e9ed64a70435bee7 100644 (file)
@@ -6,7 +6,9 @@
 namespace Friendica\Util;
 
 use Friendica\Content\OEmbed;
+use Friendica\Core\Addon;
 use Friendica\Object\Image;
+use Friendica\Util\Network;
 use Friendica\Util\XML;
 
 use dba;
@@ -14,7 +16,6 @@ use DOMXPath;
 use DOMDocument;
 
 require_once 'include/dba.php';
-require_once "include/network.php";
 
 /**
  * @brief Class with methods for extracting certain content from an url
@@ -49,19 +50,11 @@ class ParseUrl
                        return false;
                }
 
-               $r = q(
-                       "SELECT * FROM `parsed_url` WHERE `url` = '%s' AND `guessing` = %d AND `oembed` = %d",
-                       dbesc(normalise_link($url)),
-                       intval(!$no_guessing),
-                       intval($do_oembed)
+               $parsed_url = dba::selectFirst('parsed_url', ['content'],
+                       ['url' => normalise_link($url), 'guessing' => !$no_guessing, 'oembed' => $do_oembed]
                );
-
-               if ($r) {
-                       $data = $r[0]["content"];
-               }
-
-               if (!is_null($data)) {
-                       $data = unserialize($data);
+               if (!empty($parsed_url['content'])) {
+                       $data = unserialize($parsed_url['content']);
                        return $data;
                }
 
@@ -69,10 +62,11 @@ class ParseUrl
 
                dba::insert(
                        'parsed_url',
-                       array(
+                       [
                                'url' => normalise_link($url), 'guessing' => !$no_guessing,
                                'oembed' => $do_oembed, 'content' => serialize($data),
-                               'created' => datetime_convert()),
+                               'created' => DateTimeFormat::utcNow()
+                       ],
                        true
                );
 
@@ -122,7 +116,7 @@ class ParseUrl
        {
                $a = get_app();
 
-               $siteinfo = array();
+               $siteinfo = [];
 
                // Check if the URL does contain a scheme
                $scheme = parse_url($url, PHP_URL_SCHEME);
@@ -139,12 +133,12 @@ class ParseUrl
                $url = trim($url, "'");
                $url = trim($url, '"');
 
-               $url = strip_tracking_query_params($url);
+               $url = Network::stripTrackingQueryParams($url);
 
                $siteinfo["url"] = $url;
                $siteinfo["type"] = "link";
 
-               $data = z_fetch_url($url);
+               $data = Network::curl($url);
                if (!$data['success']) {
                        return($siteinfo);
                }
@@ -165,7 +159,7 @@ class ParseUrl
                if ($do_oembed) {
                        $oembed_data = OEmbed::fetchURL($url);
 
-                       if (!in_array($oembed_data->type, array("error", "rich", ""))) {
+                       if (!in_array($oembed_data->type, ["error", "rich", ""])) {
                                $siteinfo["type"] = $oembed_data->type;
                        }
 
@@ -219,7 +213,7 @@ class ParseUrl
 
                $list = $xpath->query("//meta[@content]");
                foreach ($list as $node) {
-                       $attr = array();
+                       $attr = [];
                        if ($node->attributes->length) {
                                foreach ($node->attributes as $attribute) {
                                        $attr[$attribute->name] = $attribute->value;
@@ -250,7 +244,7 @@ class ParseUrl
                //$list = $xpath->query("head/meta[@name]");
                $list = $xpath->query("//meta[@name]");
                foreach ($list as $node) {
-                       $attr = array();
+                       $attr = [];
                        if ($node->attributes->length) {
                                foreach ($node->attributes as $attribute) {
                                        $attr[$attribute->name] = $attribute->value;
@@ -307,7 +301,7 @@ class ParseUrl
                }
 
                if (isset($keywords)) {
-                       $siteinfo["keywords"] = array();
+                       $siteinfo["keywords"] = [];
                        foreach ($keywords as $keyword) {
                                if (!in_array(trim($keyword), $siteinfo["keywords"])) {
                                        $siteinfo["keywords"][] = trim($keyword);
@@ -318,7 +312,7 @@ class ParseUrl
                //$list = $xpath->query("head/meta[@property]");
                $list = $xpath->query("//meta[@property]");
                foreach ($list as $node) {
-                       $attr = array();
+                       $attr = [];
                        if ($node->attributes->length) {
                                foreach ($node->attributes as $attribute) {
                                        $attr[$attribute->name] = $attribute->value;
@@ -345,7 +339,7 @@ class ParseUrl
                if ((@$siteinfo["image"] == "") && !$no_guessing) {
                        $list = $xpath->query("//img[@src]");
                        foreach ($list as $node) {
-                               $attr = array();
+                               $attr = [];
                                if ($node->attributes->length) {
                                        foreach ($node->attributes as $attribute) {
                                                $attr[$attribute->name] = $attribute->value;
@@ -364,9 +358,9 @@ class ParseUrl
                                                $photodata[0] = round($photodata[0] * (300 / $photodata[1]));
                                                $photodata[1] = 300;
                                        }
-                                       $siteinfo["images"][] = array("src" => $src,
+                                       $siteinfo["images"][] = ["src" => $src,
                                                                        "width" => $photodata[0],
-                                                                       "height" => $photodata[1]);
+                                                                       "height" => $photodata[1]];
                                }
                        }
                } elseif ($siteinfo["image"] != "") {
@@ -377,9 +371,9 @@ class ParseUrl
                        $photodata = Image::getInfoFromURL($src);
 
                        if (($photodata) && ($photodata[0] > 10) && ($photodata[1] > 10)) {
-                               $siteinfo["images"][] = array("src" => $src,
+                               $siteinfo["images"][] = ["src" => $src,
                                                                "width" => $photodata[0],
-                                                               "height" => $photodata[1]);
+                                                               "height" => $photodata[1]];
                        }
                }
 
@@ -413,7 +407,7 @@ class ParseUrl
                        }
 
                        if ($text != "") {
-                               $text = trim(str_replace(array("\n", "\r"), array(" ", " "), $text));
+                               $text = trim(str_replace(["\n", "\r"], [" ", " "], $text));
 
                                while (strpos($text, "  ")) {
                                        $text = trim(str_replace("  ", " ", $text));
@@ -425,7 +419,7 @@ class ParseUrl
 
                logger("parseurl_getsiteinfo: Siteinfo for ".$url." ".print_r($siteinfo, true), LOGGER_DEBUG);
 
-               call_hooks("getsiteinfo", $siteinfo);
+               Addon::callHooks("getsiteinfo", $siteinfo);
 
                return($siteinfo);
        }
@@ -441,7 +435,7 @@ class ParseUrl
                $arr_tags = str_getcsv($string);
                if (count($arr_tags)) {
                        // add the # sign to every tag
-                       array_walk($arr_tags, array("self", "arrAddHashes"));
+                       array_walk($arr_tags, ["self", "arrAddHashes"]);
 
                        return $arr_tags;
                }