]> git.mxchange.org Git - friendica-addons.git/commitdiff
twitter: Better detection if a picture is posted.
authorMichael Vogel <icarus@dabo.de>
Mon, 22 Jul 2013 23:09:19 +0000 (01:09 +0200)
committerMichael Vogel <icarus@dabo.de>
Mon, 22 Jul 2013 23:09:19 +0000 (01:09 +0200)
twitter/twitter.php

index e4fbaa6a3c0ba414a940691ccb93254effd33b01..997f30a96a886e1fba6909d13bbf79271b8da272 100755 (executable)
@@ -451,8 +451,16 @@ function twitter_shortenmsg($b) {
        while (strpos($msg, "  ") !== false)
                $msg = str_replace("  ", " ", $msg);
 
-       if ($image == $orig_link)
-               return(array("msg"=>trim($msg), "image"=>$image));
+       // Looking if the link points to an image
+       $img_str = fetch_url($orig_link);
+
+       $tempfile = tempnam(get_config("system","temppath"), "cache");
+       file_put_contents($tempfile, $img_str);
+       $mime = image_type_to_mime_type(exif_imagetype($tempfile));
+       unlink($tempfile);
+
+       if (($image == $orig_link) OR (substr($mime, 0, 6) == "image/"))
+               return(array("msg"=>trim($msg), "image"=>$orig_link));
        else
                return(array("msg"=>trim($msg."\n".$orig_link), "image"=>""));
 }