From e5f55a591965df7bc4b65fda5cc8005f0ca148ae Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 12 Nov 2016 20:23:00 +0000 Subject: [PATCH 1/3] Improved handling with wrong formatted urls and fetchinfo --- include/items.php | 11 ++++++++++- mod/parse_url.php | 17 +++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/items.php b/include/items.php index 93df36fb39..f7ec9d64d4 100644 --- a/include/items.php +++ b/include/items.php @@ -150,8 +150,9 @@ function add_page_info_data($data) { is_string($data["text"]) AND (sizeof($data["images"]) > 0)) $data["type"] = "link"; - if ((($data["type"] != "link") AND ($data["type"] != "video") AND ($data["type"] != "photo")) OR ($data["title"] == $url)) + if ((($data["type"] != "link") AND ($data["type"] != "video") AND ($data["type"] != "photo")) OR ($data["title"] == $data["url"])) { return(""); + } if ($no_photos AND ($data["type"] == "photo")) return(""); @@ -167,6 +168,14 @@ function add_page_info_data($data) { $text = "[attachment type='".$data["type"]."'"; + if ($data["text"] == "") { + $data["text"] = $data["title"]; + } + + if ($data["text"] == "") { + $data["text"] = $data["url"]; + } + if ($data["url"] != "") $text .= " url='".$data["url"]."'"; if ($data["title"] != "") diff --git a/mod/parse_url.php b/mod/parse_url.php index baf8677501..23075ad775 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -89,6 +89,13 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co $siteinfo = array(); + // Check if the URL does contain a scheme + $scheme = parse_url($url, PHP_URL_SCHEME); + + if ($scheme == "") { + $url = "http://".trim($url, "/"); + } + if ($count > 10) { logger("parseurl_getsiteinfo: Endless loop detected for ".$url, LOGGER_DEBUG); return($siteinfo); @@ -102,6 +109,8 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co $siteinfo["url"] = $url; $siteinfo["type"] = "link"; + $check_cert = get_config('system','verifyssl'); + $stamp1 = microtime(true); $ch = curl_init(); @@ -110,8 +119,9 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 3); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent()); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false)); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, (($check_cert) ? 2 : false)); $header = curl_exec($ch); $curl_info = @curl_getinfo($ch); @@ -142,8 +152,9 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co $oembed_data = oembed_fetch_url($url); - if ($oembed_data->type != "error") + if (!in_array($oembed_data->type, array("error", "rich"))) { $siteinfo["type"] = $oembed_data->type; + } if (($oembed_data->type == "link") AND ($siteinfo["type"] != "photo")) { if (isset($oembed_data->title)) @@ -165,6 +176,8 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent()); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false)); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, (($check_cert) ? 2 : false)); $header = curl_exec($ch); $curl_info = @curl_getinfo($ch); From 2937df21ad597423201403b3d098ddb0a27214a6 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Nov 2016 08:50:01 +0000 Subject: [PATCH 2/3] Standard stuff --- include/items.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/items.php b/include/items.php index f7ec9d64d4..fe3f1ff113 100644 --- a/include/items.php +++ b/include/items.php @@ -151,7 +151,7 @@ function add_page_info_data($data) { $data["type"] = "link"; if ((($data["type"] != "link") AND ($data["type"] != "video") AND ($data["type"] != "photo")) OR ($data["title"] == $data["url"])) { - return(""); + return ""; } if ($no_photos AND ($data["type"] == "photo")) From 6dfaa5a95fe8559316507447b4b5bcc7c0f2f402 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Nov 2016 19:09:47 +0000 Subject: [PATCH 3/3] Some more standard stuff --- include/items.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/include/items.php b/include/items.php index fe3f1ff113..a0fe59bf17 100644 --- a/include/items.php +++ b/include/items.php @@ -147,20 +147,23 @@ function add_page_info_data($data) { // It maybe is a rich content, but if it does have everything that a link has, // then treat it that way if (($data["type"] == "rich") AND is_string($data["title"]) AND - is_string($data["text"]) AND (sizeof($data["images"]) > 0)) + is_string($data["text"]) AND (sizeof($data["images"]) > 0)) { $data["type"] = "link"; + } if ((($data["type"] != "link") AND ($data["type"] != "video") AND ($data["type"] != "photo")) OR ($data["title"] == $data["url"])) { return ""; } - if ($no_photos AND ($data["type"] == "photo")) - return(""); + if ($no_photos AND ($data["type"] == "photo")) { + return ""; + } - if (sizeof($data["images"]) > 0) + if (sizeof($data["images"]) > 0) { $preview = $data["images"][0]; - else + } else { $preview = ""; + } // Escape some bad characters $data["url"] = str_replace(array("[", "]"), array("[", "]"), htmlentities($data["url"], ENT_QUOTES, 'UTF-8', false)); @@ -176,19 +179,25 @@ function add_page_info_data($data) { $data["text"] = $data["url"]; } - if ($data["url"] != "") + if ($data["url"] != "") { $text .= " url='".$data["url"]."'"; - if ($data["title"] != "") + } + + if ($data["title"] != "") { $text .= " title='".$data["title"]."'"; + } + if (sizeof($data["images"]) > 0) { $preview = str_replace(array("[", "]"), array("[", "]"), htmlentities($data["images"][0]["src"], ENT_QUOTES, 'UTF-8', false)); // if the preview picture is larger than 500 pixels then show it in a larger mode // But only, if the picture isn't higher than large (To prevent huge posts) - if (($data["images"][0]["width"] >= 500) AND ($data["images"][0]["width"] >= $data["images"][0]["height"])) + if (($data["images"][0]["width"] >= 500) AND ($data["images"][0]["width"] >= $data["images"][0]["height"])) { $text .= " image='".$preview."'"; - else + } else { $text .= " preview='".$preview."'"; + } } + $text .= "]".$data["text"]."[/attachment]"; $hashtags = "";