]> git.mxchange.org Git - friendica.git/blobdiff - mod/parse_url.php
Merge pull request #463 from pixelroot/master
[friendica.git] / mod / parse_url.php
index 3d4018745c6e580f355e909d23fc09101509ce9f..083a39b55f9012d2733ad55118d41c664d1b38b6 100644 (file)
@@ -1,4 +1,18 @@
 <?php
+/* To-Do
+https://developers.google.com/+/plugins/snippet/
+
+<meta itemprop="name" content="Toller Titel">
+<meta itemprop="description" content="Eine tolle Beschreibung">
+<meta itemprop="image" content="http://maple.libertreeproject.org/images/tree-icon.png">
+
+<body itemscope itemtype="http://schema.org/Product">
+  <h1 itemprop="name">Shiny Trinket</h1>
+  <img itemprop="image" src="{image-url}" />
+  <p itemprop="description">Shiny trinkets are shiny.</p>
+</body>
+*/
+
 if(!function_exists('deletenode')) {
        function deletenode(&$doc, $node)
        {
@@ -22,6 +36,9 @@ function completeurl($url, $scheme) {
         if ($schemearr["port"] != "")
                 $complete .= ":".$schemearr["port"];
 
+               if(strpos($urlarr['path'],'/') !== 0)
+                       $complete .= '/';
+
         $complete .= $urlarr["path"];
 
         if ($urlarr["query"] != "")
@@ -135,17 +152,17 @@ function parseurl_getsiteinfo($url) {
        }
 
        if ($siteinfo["image"] == "") {
-                $list = $xpath->query("//img[@src]");
-                foreach ($list as $node) {
-                        $attr = array();
-                        if ($node->attributes->length)
-                                foreach ($node->attributes as $attribute)
-                                        $attr[$attribute->name] = $attribute->value;
+            $list = $xpath->query("//img[@src]");
+            foreach ($list as $node) {
+                $attr = array();
+                if ($node->attributes->length)
+                    foreach ($node->attributes as $attribute)
+                        $attr[$attribute->name] = $attribute->value;
 
                        $src = completeurl($attr["src"], $url);
-                       $photodata = getimagesize($src);
+                       $photodata = @getimagesize($src);
 
-                       if (($photodata[0] > 150) and ($photodata[1] > 150)) {
+                       if (($photodata) && ($photodata[0] > 150) and ($photodata[1] > 150)) {
                                if ($photodata[0] > 300) {
                                        $photodata[1] = round($photodata[1] * (300 / $photodata[0]));
                                        $photodata[0] = 300;
@@ -159,12 +176,15 @@ function parseurl_getsiteinfo($url) {
                                                                "height"=>$photodata[1]);
                        }
 
-                }
-        } else {
+               }
+    } else {
                $src = completeurl($siteinfo["image"], $url);
-               $photodata = getimagesize($src);
 
-               if (($photodata[0] > 10) and ($photodata[1] > 10))
+               unset($siteinfo["image"]);
+
+               $photodata = @getimagesize($src);
+
+               if (($photodata) && ($photodata[0] > 10) and ($photodata[1] > 10))
                        $siteinfo["images"][] = array("src"=>$src,
                                                        "width"=>$photodata[0],
                                                        "height"=>$photodata[1]);
@@ -278,8 +298,7 @@ function parse_url_content(&$a) {
        $siteinfo = parseurl_getsiteinfo($url);
 
        if($siteinfo["title"] == "") {
-               echo print_r($siteinfo, true);
-               //echo sprintf($template,$url,$url,'') . $str_tags;
+               echo sprintf($template,$url,$url,'') . $str_tags;
                killme();
        } else {
                $text = $siteinfo["text"];
@@ -288,11 +307,16 @@ function parse_url_content(&$a) {
 
        $image = "";
 
-       foreach ($siteinfo["images"] as $imagedata)
+        if(sizeof($siteinfo["images"]) > 0){
+            /*
+              Execute below code only if image is present in siteinfo
+             */
+            foreach ($siteinfo["images"] as $imagedata)
                if($textmode)
-                       $image .= '[img='.$imagedata["width"].'x'.$imagedata["height"].']'.$imagedata["src"].'[/img]';
+                    $image .= '[img='.$imagedata["width"].'x'.$imagedata["height"].']'.$imagedata["src"].'[/img]';
                else
-                       $image .= '<img height="'.$imagedata["height"].'" width="'.$imagedata["width"].'" src="'.$imagedata["src"].'" alt="photo" />';
+                    $image .= '<img height="'.$imagedata["height"].'" width="'.$imagedata["width"].'" src="'.$imagedata["src"].'" alt="photo" />';
+        }
 
        if(strlen($text)) {
                if($textmode)