]> git.mxchange.org Git - friendica.git/blobdiff - mod/parse_url.php
Merge pull request #5620 from annando/fix-remove
[friendica.git] / mod / parse_url.php
index 0888db1012e395591a67a2ad1be426d024f49bae..3309a74b9f0d22041a9e529924e96f3c94f28343 100644 (file)
  * @see ParseUrl::getSiteinfo() for more information about scraping embeddable content
 */
 
-use \Friendica\ParseUrl;
+use Friendica\App;
+use Friendica\Core\Addon;
+use Friendica\Util\Network;
+use Friendica\Util\ParseUrl;
 
 require_once("include/items.php");
 
@@ -21,21 +24,21 @@ function parse_url_content(App $a) {
 
        $br = "\n";
 
-       if (x($_GET,"binurl")) {
+       if (!empty($_GET["binurl"])) {
                $url = trim(hex2bin($_GET["binurl"]));
        } else {
                $url = trim($_GET["url"]);
        }
 
-       if ($_GET["title"]) {
+       if (!empty($_GET["title"])) {
                $title = strip_tags(trim($_GET["title"]));
        }
 
-       if ($_GET["description"]) {
+       if (!empty($_GET["description"])) {
                $text = strip_tags(trim($_GET["description"]));
        }
 
-       if ($_GET["tags"]) {
+       if (!empty($_GET["tags"])) {
                $arr_tags = ParseUrl::convertTagsToArray($_GET["tags"]);
                if (count($arr_tags)) {
                        $str_tags = $br . implode(" ", $arr_tags) . $br;
@@ -58,20 +61,23 @@ function parse_url_content(App $a) {
        // the URL with the corresponding BBCode media tag
        $redirects = 0;
        // Fetch the header of the URL
-       $result = z_fetch_url($url, false, $redirects, array("novalidate" => true, "nobody" => true));
-       if ($result["success"]) {
+       $result = Network::curl($url, false, $redirects, ["novalidate" => true, "nobody" => true]);
+       if($result["success"]) {
                // Convert the header fields into an array
-               $hdrs = array();
+               $hdrs = [];
                $h = explode("\n", $result["header"]);
                foreach ($h as $l) {
-                       list($k,$v) = array_map("trim", explode(":", trim($l), 2));
-                       $hdrs[$k] = $v;
+                       $header = array_map("trim", explode(":", trim($l), 2));
+                       if (count($header) == 2) {
+                               list($k,$v) = $header;
+                               $hdrs[$k] = $v;
+                       }
                }
                if (array_key_exists("Content-Type", $hdrs)) {
                        $type = $hdrs["Content-Type"];
                }
                if ($type) {
-                       if (stripos($type, "image/") !== false) {
+                       if(stripos($type, "image/") !== false) {
                                echo $br . "[img]" . $url . "[/img]" . $br;
                                killme();
                        }
@@ -88,20 +94,20 @@ function parse_url_content(App $a) {
 
        $template = "[bookmark=%s]%s[/bookmark]%s";
 
-       $arr = array("url" => $url, "text" => "");
+       $arr = ["url" => $url, "text" => ""];
 
-       call_hooks("parse_link", $arr);
+       Addon::callHooks("parse_link", $arr);
 
        if (strlen($arr["text"])) {
                echo $arr["text"];
                killme();
        }
 
-       // If there is allready some content information submitted we don't
+       // If there is already some content information submitted we don't
        // need to parse the url for content.
-       if ($url && $title && $text) {
+       if (!empty($url) && !empty($title) && !empty($text)) {
 
-               $title = str_replace(array("\r","\n"),array("",""),$title);
+               $title = str_replace(["\r","\n"],["",""],$title);
 
                $text = "[quote]" . trim($text) . "[/quote]" . $br;