From adb0219e1077e7d632ec133c62c0936e7ec4fe33 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 23 Jul 2013 01:09:19 +0200 Subject: [PATCH] twitter: Better detection if a picture is posted. --- twitter/twitter.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/twitter/twitter.php b/twitter/twitter.php index e4fbaa6a..997f30a9 100755 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -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"=>"")); }