X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=privacy_image_cache%2Fprivacy_image_cache.php;h=8c68ef9a4bf555a3b7f2d92151c8cdfa363c7594;hb=47396b1d284dffbb994233597cb9fca8a1e33be7;hp=f0d8e39ac55b24b2a5d4b31a1900d61911cc2bcc;hpb=4437c42fd4b490cf60834b8151be14bac21c9c64;p=friendica-addons.git diff --git a/privacy_image_cache/privacy_image_cache.php b/privacy_image_cache/privacy_image_cache.php index f0d8e39a..8c68ef9a 100644 --- a/privacy_image_cache/privacy_image_cache.php +++ b/privacy_image_cache/privacy_image_cache.php @@ -34,6 +34,9 @@ function privacy_image_cache_module() {} function privacy_image_cache_init() { global $a; + if ($a->config["system"]["db_log"] != "") + $stamp1 = microtime(true); + if(function_exists('header_remove')) { header_remove('Pragma'); header_remove('pragma'); @@ -45,7 +48,7 @@ function privacy_image_cache_init() { $cache = get_config('system','itemcache'); if (($cache != '') and is_dir($cache)) { - $cachefile = $cache."/".hash("md5", $urlhash); + $cachefile = $cache."/".hash("md5", $_REQUEST['url']); if (file_exists($cachefile)) { $img_str = file_get_contents($cachefile); @@ -57,18 +60,34 @@ function privacy_image_cache_init() { echo $img_str; + if ($a->config["system"]["db_log"] != "") { + $stamp2 = microtime(true); + $duration = round($stamp2-$stamp1, 3); + if ($duration > $a->config["system"]["db_loglimit"]) + @file_put_contents($a->config["system"]["db_log"], $duration."\t".strlen($img_str)."\t".$_REQUEST['url']."\n", FILE_APPEND); + } + killme(); } } + require_once("Photo.php"); + $r = q("SELECT * FROM `photo` WHERE `resource-id` in ('%s', '%s') LIMIT 1", $urlhash, $urlhash2); if (count($r)) { $img_str = $r[0]['data']; $mime = $r[0]["desc"]; if ($mime == "") $mime = "image/jpeg"; - } else { - require_once("Photo.php"); + // Test + //if ($mime == "image/jpeg") { + // $img = new Photo($img_str); + // if($img->is_valid()) { + // $img->scaleImage(1000); + // $img_str = $img->imageString(); + // } + //} + } else { // It shouldn't happen but it does - spaces in URL $_REQUEST['url'] = str_replace(" ", "+", $_REQUEST['url']); @@ -110,6 +129,7 @@ function privacy_image_cache_init() { $img = new Photo($img_str); if($img->is_valid()) { $img->store(0, 0, $urlhash, $_REQUEST['url'], '', 100); + //$img->scaleImage(1000); // Test $img_str = $img->imageString(); } $mime = "image/jpeg"; @@ -117,7 +137,7 @@ function privacy_image_cache_init() { } // Writing in cachefile - if (isset($cachefile) && $cachefile != '') + if (isset($cachefile) && ($cachefile != '') and (exif_imagetype($cachefile) > 0)) file_put_contents($cachefile, $img_str); header("Content-type: $mime"); @@ -126,6 +146,13 @@ function privacy_image_cache_init() { echo $img_str; + if ($a->config["system"]["db_log"] != "") { + $stamp2 = microtime(true); + $duration = round($stamp2-$stamp1, 3); + if ($duration > $a->config["system"]["db_loglimit"]) + @file_put_contents($a->config["system"]["db_log"], $duration."\t".strlen($img_str)."\t".$_REQUEST['url']."\n", FILE_APPEND); + } + killme(); }