]> git.mxchange.org Git - friendica-addons.git/blobdiff - privacy_image_cache/privacy_image_cache.php
Setting "editplain", "page" and "privacy_image_cache" as deprecated. Using new cache...
[friendica-addons.git] / privacy_image_cache / privacy_image_cache.php
index 1fa6c5e6557762045b5cb262bdd57822ea83d8dc..8a303e7b069f14afa0adfe1eb468bbadf22e735b 100644 (file)
@@ -4,6 +4,7 @@
  * Name: Privacy Image Cache
  * Version: 0.1
  * Author: Tobias Hößl <https://github.com/CatoTH/>
+ * Status: Unsupported
  */
 
 define("PRIVACY_IMAGE_CACHE_DEFAULT_TIME", 86400); // 1 Day
@@ -61,6 +62,7 @@ function privacy_image_cache_init() {
        }
 
        $thumb = false;
+       $size = 1024;
 
        // If the cache path isn't there, try to create it
        if (!is_dir($_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache"))
@@ -79,6 +81,20 @@ function privacy_image_cache_init() {
                else
                        $url = $a->argv[1];
 
+               //$thumb = (isset($a->argv[3]) and ($a->argv[3] == "thumb"));
+               if (isset($a->argv[3]) and ($a->argv[3] == "thumb"))
+                       $size = 200;
+
+               // thumb, small, medium and large.
+               if (substr($url, -6) == ":thumb")
+                       $size = 150;
+               if (substr($url, -6) == ":small")
+                       $size = 340;
+               if (substr($url, -7) == ":medium")
+                       $size = 600;
+               if (substr($url, -6) == ":large")
+                       $size = 1024;
+
                $pos = strrpos($url, "=.");
                if ($pos)
                        $url = substr($url, 0, $pos+1);
@@ -89,7 +105,6 @@ function privacy_image_cache_init() {
 
                if ($url)
                        $_REQUEST['url'] = $url;
-               $thumb = (isset($a->argv[3]) and ($a->argv[3] == "thumb"));
        }
 
        if (!$direct_cache) {
@@ -142,7 +157,7 @@ function privacy_image_cache_init() {
                $redirects = 0;
                $img_str = fetch_url($_REQUEST['url'],true, $redirects, 10);
 
-               $tempfile = tempnam(get_config("system","temppath"), "cache");
+               $tempfile = tempnam(get_temppath(), "cache");
                file_put_contents($tempfile, $img_str);
                $mime = image_type_to_mime_type(exif_imagetype($tempfile));
                unlink($tempfile);
@@ -186,10 +201,10 @@ function privacy_image_cache_init() {
                                if (!$direct_cache AND ($cachefile == ""))
                                        $img->store(0, 0, $urlhash, $_REQUEST['url'], '', 100);
 
-                               if ($thumb) {
-                                       $img->scaleImage(200); // Test
-                                       $img_str = $img->imageString();
-                               }
+                               //if ($thumb) {
+                               //      $img->scaleImage(200); // Test
+                               //      $img_str = $img->imageString();
+                               //}
                        }
                        //$mime = "image/jpeg";
                }
@@ -199,7 +214,8 @@ function privacy_image_cache_init() {
        if ($mime != "image/gif") {
                $img = new Photo($img_str, $mime);
                if($img->is_valid()) {
-                       $img->scaleImage(1024); // Test
+                       //$img->scaleImage(1024); // Test
+                       $img->scaleImage($size);
                        $img_str = $img->imageString();
                }
        }
@@ -288,12 +304,12 @@ function privacy_image_cache_img_cb($matches) {
 
        // if the picture seems to be from another picture cache then take the original source
        $queryvar = privacy_image_cache_parse_query($matches[2]);
-       if ($queryvar['url'] != "")
+       if (($queryvar['url'] != "") AND (substr($queryvar['url'], 0, 4) == "http"))
                $matches[2] = urldecode($queryvar['url']);
 
        // if fetching facebook pictures don't fetch the thumbnail but the big one
-       if (strpos($matches[2], ".fbcdn.net/") and (substr($matches[2], -6) == "_s.jpg"))
-               $matches[2] = substr($matches[2], 0, -6)."_n.jpg";
+       //if (((strpos($matches[2], ".fbcdn.net/") OR strpos($matches[2], "/fbcdn-photos-"))) and (substr($matches[2], -6) == "_s.jpg"))
+       //      $matches[2] = substr($matches[2], 0, -6)."_n.jpg";
 
        // following line changed per bug #431
        if (privacy_image_cache_is_local_image($matches[2]))