]> git.mxchange.org Git - friendica.git/blobdiff - mod/parse_url.php
Removed commented code
[friendica.git] / mod / parse_url.php
index bf111f143c69d053716da3ceb71671c1a69ff89b..23075ad775e64a6bc73b7c47a3b4f3726fff45b2 100644 (file)
@@ -72,8 +72,11 @@ function parseurl_getsiteinfo_cached($url, $no_guessing = false, $do_oembed = tr
 
        $data = parseurl_getsiteinfo($url, $no_guessing, $do_oembed);
 
-       q("INSERT INTO `parsed_url` (`url`, `guessing`, `oembed`, `content`, `created`) VALUES ('%s', %d, %d, '%s', '%s')",
-               dbesc(normalise_link($url)), intval(!$no_guessing), intval($do_oembed), dbesc(serialize($data)), dbesc(datetime_convert()));
+       q("INSERT INTO `parsed_url` (`url`, `guessing`, `oembed`, `content`, `created`) VALUES ('%s', %d, %d, '%s', '%s')
+                ON DUPLICATE KEY UPDATE `content` = '%s', `created` = '%s'",
+               dbesc(normalise_link($url)), intval(!$no_guessing), intval($do_oembed),
+               dbesc(serialize($data)), dbesc(datetime_convert()),
+               dbesc(serialize($data)), dbesc(datetime_convert()));
 
        return $data;
 }
@@ -86,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);
@@ -99,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();
@@ -107,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);
@@ -139,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))
@@ -162,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);
@@ -232,10 +248,9 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $co
                }
        }
 
-       //$list = $xpath->query("head/title");
        $list = $xpath->query("//title");
-       foreach ($list as $node)
-               $siteinfo["title"] =  html_entity_decode($node->nodeValue, ENT_QUOTES, "UTF-8");
+       if ($list->length > 0)
+               $siteinfo["title"] = $list->item(0)->nodeValue;
 
        //$list = $xpath->query("head/meta[@name]");
        $list = $xpath->query("//meta[@name]");
@@ -488,7 +503,14 @@ function parse_url_content(&$a) {
 
        unset($siteinfo["keywords"]);
 
-       echo add_page_info_data($siteinfo);
+       $info = add_page_info_data($siteinfo);
+
+       if (!$textmode)
+               // Replace ' with ’ - not perfect - but the richtext editor has problems otherwise
+               $info = str_replace(array("'"), array("’"), $info);
+
+       echo $info;
+
        killme();
 }
 ?>