]> git.mxchange.org Git - friendica-addons.git/commitdiff
Store animated GIFs unmodified; now works in environments where friendica is installe...
authorTobias Hößl <tobias@hoessl.eu>
Wed, 6 Jun 2012 19:49:06 +0000 (19:49 +0000)
committerTobias Hößl <tobias@hoessl.eu>
Wed, 6 Jun 2012 19:49:06 +0000 (19:49 +0000)
privacy_image_cache/privacy_image_cache.php

index 4153f7d94f50b3e8ce0b410c319974289584ca7c..f179a7ba21ab55bb1ccb4f7d08f42ff83c2bf3e7 100644 (file)
@@ -34,20 +34,48 @@ function privacy_image_cache_init() {
     $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' LIMIT 1", $urlhash );
     if (count($r)) {
         $img_str = $r[0]['data'];
+               $mime = $r[0]["desc"];
+               if ($mime == "") $mime = "image/jpeg";
     }
     else {
         require_once("Photo.php");
 
         $img_str = fetch_url($_REQUEST['url'],true);
-        $img = new Photo($img_str);
-        if($img->is_valid()) {
-            $img->store(0, 0, $urlhash, $_REQUEST['url'], '', 100);
-            $img_str = $img->imageString();
-        }
+               if (substr($img_str, 0, 6) == "GIF89a") {
+                       $mime = "image/gif";
+                       $image = @imagecreatefromstring($img_str);
+
+                       if($image === FALSE) die();
+
+                       q("INSERT INTO `photo`
+                       ( `uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, `album`, `height`, `width`, `desc`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )
+                       VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', %d, %d, '%s', '%s', '%s', '%s' )",
+                               0, 0, get_guid(), dbesc($urlhash),
+                               dbesc(datetime_convert()),
+                               dbesc(datetime_convert()),
+                               dbesc(basename(dbesc($_REQUEST["url"]))),
+                               dbesc(''),
+                               intval(imagesy($image)),
+                               intval(imagesx($image)),
+                               'image/gif',
+                               dbesc($img_str),
+                               100,
+                               intval(0),
+                               dbesc(''), dbesc(''), dbesc(''), dbesc('')
+                       );
+
+               } else {
+                       $img = new Photo($img_str);
+                       if($img->is_valid()) {
+                               $img->store(0, 0, $urlhash, $_REQUEST['url'], '', 100);
+                               $img_str = $img->imageString();
+                       }
+                       $mime = "image/jpeg";
+               }
     }
 
 
-    header("Content-type: image/jpeg");
+    header("Content-type: $mime");
     header("Expires: " . gmdate("D, d M Y H:i:s", time() + (3600*24)) . " GMT");
     header("Cache-Control: max-age=" . (3600*24));
 
@@ -75,7 +103,7 @@ function privacy_image_cache_is_local_image($url) {
 function privacy_image_cache_img_cb($matches) {
        // following line changed per bug #431
     if (privacy_image_cache_is_local_image($matches[2])) return $matches[1] . $matches[2] . $matches[3];
-    return $matches[1] . "/privacy_image_cache/?url=" . escape_tags(addslashes(rawurlencode($matches[2]))) . $matches[3];
+    return $matches[1] . get_app()->get_baseurl() . "/privacy_image_cache/?url=" . escape_tags(addslashes(rawurlencode($matches[2]))) . $matches[3];
 }
 
 /**
@@ -94,9 +122,9 @@ function privacy_image_cache_bbcode_hook(&$a, &$o) {
 function privacy_image_cache_display_item_hook(&$a, &$o) {
     if (isset($o["output"])) {
         if (isset($o["output"]["thumb"]) && !privacy_image_cache_is_local_image($o["output"]["thumb"]))
-            $o["output"]["thumb"] = "/privacy_image_cache/?url=" . escape_tags(addslashes(rawurlencode($o["output"]["thumb"])));
+            $o["output"]["thumb"] = $a->get_baseurl() . "/privacy_image_cache/?url=" . escape_tags(addslashes(rawurlencode($o["output"]["thumb"])));
         if (isset($o["output"]["author-avatar"]) && !privacy_image_cache_is_local_image($o["output"]["author-avatar"]))
-            $o["output"]["author-avatar"] = "/privacy_image_cache/?url=" . escape_tags(addslashes(rawurlencode($o["output"]["author-avatar"])));
+            $o["output"]["author-avatar"] = $a->get_baseurl() . "/privacy_image_cache/?url=" . escape_tags(addslashes(rawurlencode($o["output"]["author-avatar"])));
     }
 }
 
@@ -107,7 +135,7 @@ function privacy_image_cache_display_item_hook(&$a, &$o) {
  */
 function privacy_image_cache_ping_xmlize_hook(&$a, &$o) {
     if ($o["photo"] != "" && !privacy_image_cache_is_local_image($o["photo"]))
-        $o["photo"] = "/privacy_image_cache/?url=" . escape_tags(addslashes(rawurlencode($o["photo"])));
+        $o["photo"] = $a->get_baseurl() . "/privacy_image_cache/?url=" . escape_tags(addslashes(rawurlencode($o["photo"])));
 }