From d420d97fe2e2f3cb5dd50047314838631d7916bc Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 13 Jan 2013 09:55:28 +0100 Subject: [PATCH 1/8] privacy_image_cache: The detection for facebook pictures is moved to a better location --- privacy_image_cache/privacy_image_cache.php | 22 +++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/privacy_image_cache/privacy_image_cache.php b/privacy_image_cache/privacy_image_cache.php index 0e241e7e..6e12a043 100644 --- a/privacy_image_cache/privacy_image_cache.php +++ b/privacy_image_cache/privacy_image_cache.php @@ -120,13 +120,13 @@ function privacy_image_cache_init() { $_REQUEST['url'] = str_replace(" ", "+", $_REQUEST['url']); // if the picture seems to be from another picture cache then take the original source - $queryvar = privacy_image_cache_parse_query($_REQUEST['url']); - if ($queryvar['url'] != "") - $_REQUEST['url'] = urldecode($queryvar['url']); + //$queryvar = privacy_image_cache_parse_query($_REQUEST['url']); + //if ($queryvar['url'] != "") + // $_REQUEST['url'] = urldecode($queryvar['url']); // if fetching facebook pictures don't fetch the thumbnail but the big one - if (strpos($_REQUEST['url'], ".fbcdn.net/") and (substr($_REQUEST['url'], -6) == "_s.jpg")) - $_REQUEST['url'] = substr($_REQUEST['url'], 0, -6)."_n.jpg"; + //if (strpos($_REQUEST['url'], ".fbcdn.net/") and (substr($_REQUEST['url'], -6) == "_s.jpg")) + // $_REQUEST['url'] = substr($_REQUEST['url'], 0, -6)."_n.jpg"; $redirects = 0; $img_str = fetch_url($_REQUEST['url'],true, $redirects, 10); @@ -243,7 +243,7 @@ function privacy_image_cache_is_local_image($url) { // Check if the cached path would be longer than 255 characters - apache doesn't like it if (is_dir($_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache")) { $cachedurl = get_app()->get_baseurl()."/privacy_image_cache/". privacy_image_cache_cachename($url); - if (strlen($url) > 255) + if (strlen($url) > 150) return true; } @@ -258,6 +258,16 @@ function privacy_image_cache_is_local_image($url) { * @return string */ 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'] != "") + $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"; + // following line changed per bug #431 if (privacy_image_cache_is_local_image($matches[2])) return $matches[1] . $matches[2] . $matches[3]; From daf3f9b8e88d6114bd4d8f5e9f34b1ebc0a06c69 Mon Sep 17 00:00:00 2001 From: "Michael - piratica.eu" Date: Sat, 26 Jan 2013 00:22:46 +0100 Subject: [PATCH 2/8] rendertime: New plugin to show the time that was needed to render a page --- rendertime/rendertime.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 rendertime/rendertime.php diff --git a/rendertime/rendertime.php b/rendertime/rendertime.php new file mode 100755 index 00000000..87a32901 --- /dev/null +++ b/rendertime/rendertime.php @@ -0,0 +1,35 @@ + + * + */ + +function rendertime_install() { + register_hook('init_1', 'addon/rendertime/rendertime.php', 'rendertime_init_1'); + register_hook('page_end', 'addon/rendertime/rendertime.php', 'rendertime_page_end'); +} + + +function rendertime_uninstall() { + unregister_hook('init_1', 'addon/rendertime/rendertime.php', 'rendertime_init_1'); + unregister_hook('page_end', 'addon/rendertime/rendertime.php', 'rendertime_page_end'); +} + +function rendertime_init_1(&$a) { + global $rendertime_start; + + $rendertime_start = microtime(true); +} + +function rendertime_page_end(&$a, &$o) { + global $rendertime_start; + + $duration = round(microtime(true)-$rendertime_start, 3); + + $o = $o.'
'.sprintf(t("This page took %s seconds to render"), $duration)."
"; +} From fb3e14331fb87ba029564b48adc7e45b45f04505 Mon Sep 17 00:00:00 2001 From: "Michael - piratica.eu" Date: Sat, 26 Jan 2013 16:48:04 +0100 Subject: [PATCH 3/8] rendertime: Adding more variables for measuring performance. --- rendertime/rendertime.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/rendertime/rendertime.php b/rendertime/rendertime.php index 87a32901..0792ce05 100755 --- a/rendertime/rendertime.php +++ b/rendertime/rendertime.php @@ -10,7 +10,6 @@ */ function rendertime_install() { - register_hook('init_1', 'addon/rendertime/rendertime.php', 'rendertime_init_1'); register_hook('page_end', 'addon/rendertime/rendertime.php', 'rendertime_page_end'); } @@ -21,15 +20,15 @@ function rendertime_uninstall() { } function rendertime_init_1(&$a) { - global $rendertime_start; - - $rendertime_start = microtime(true); } function rendertime_page_end(&$a, &$o) { - global $rendertime_start; - $duration = round(microtime(true)-$rendertime_start, 3); + $duration = round(microtime(true)-$a->performance["start"], 3); - $o = $o.'
'.sprintf(t("This page took %s seconds to render"), $duration)."
"; + $o = $o.'
'.sprintf(t("Rendertime: Database: %s, Network: %s, Rendering: %s, Total: %s"), + round($a->performance["database"], 3), + round($a->performance["network"], 3), + round($a->performance["rendering"], 3), + $duration)."
"; } From b57bc15e531e069ef202c740cb403ceb9b50e7fa Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 26 Jan 2013 18:36:10 +0100 Subject: [PATCH 4/8] Adding more parameters to rendertime --- rendertime/rendertime.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/rendertime/rendertime.php b/rendertime/rendertime.php index 0792ce05..e2c7352c 100755 --- a/rendertime/rendertime.php +++ b/rendertime/rendertime.php @@ -24,11 +24,15 @@ function rendertime_init_1(&$a) { function rendertime_page_end(&$a, &$o) { - $duration = round(microtime(true)-$a->performance["start"], 3); + $duration = microtime(true)-$a->performance["start"]; - $o = $o.'
'.sprintf(t("Rendertime: Database: %s, Network: %s, Rendering: %s, Total: %s"), + $o = $o.'
'.sprintf(t("Performance: Database: %s, Network: %s, Rendering: %s, Parser: %s, I/O: %s, Other: %s"), round($a->performance["database"], 3), round($a->performance["network"], 3), round($a->performance["rendering"], 3), - $duration)."
"; + round($a->performance["parser"], 3), + round($a->performance["file"], 3), + round($duration - $a->performance["database"] - $a->performance["network"] + - $a->performance["rendering"] - $a->performance["parser"] + - $a->performance["file"], 3))."
"; } From 19495c1e1156f2fefd124d87f1fb4348b3da9631 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 27 Jan 2013 14:00:28 +0100 Subject: [PATCH 5/8] rendertime: total sum is displayed --- rendertime/rendertime.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rendertime/rendertime.php b/rendertime/rendertime.php index e2c7352c..f73e0856 100755 --- a/rendertime/rendertime.php +++ b/rendertime/rendertime.php @@ -26,13 +26,16 @@ function rendertime_page_end(&$a, &$o) { $duration = microtime(true)-$a->performance["start"]; - $o = $o.'
'.sprintf(t("Performance: Database: %s, Network: %s, Rendering: %s, Parser: %s, I/O: %s, Other: %s"), + $o = $o.'
'.sprintf(t("Performance: Database: %s, Network: %s, Rendering: %s, Parser: %s, I/O: %s, Other: %s, Total: %s"), round($a->performance["database"], 3), round($a->performance["network"], 3), round($a->performance["rendering"], 3), round($a->performance["parser"], 3), round($a->performance["file"], 3), + //round($a->performance["markstart"], 3), round($duration - $a->performance["database"] - $a->performance["network"] - $a->performance["rendering"] - $a->performance["parser"] - - $a->performance["file"], 3))."
"; + - $a->performance["file"], 3), + round($duration, 3))."
"; + } From 395a419513399e9e914691e98f94f3305fdb47ba Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 6 Feb 2013 08:03:10 +0100 Subject: [PATCH 6/8] privacy_image_cache: Pictures will be compressed before the output --- privacy_image_cache/privacy_image_cache.php | 40 +++++++-------------- rendertime/rendertime.php | 6 ++-- 2 files changed, 16 insertions(+), 30 deletions(-) diff --git a/privacy_image_cache/privacy_image_cache.php b/privacy_image_cache/privacy_image_cache.php index 6e12a043..30155fab 100644 --- a/privacy_image_cache/privacy_image_cache.php +++ b/privacy_image_cache/privacy_image_cache.php @@ -9,6 +9,7 @@ define("PRIVACY_IMAGE_CACHE_DEFAULT_TIME", 86400); // 1 Day require_once('include/security.php'); +require_once("Photo.php"); function privacy_image_cache_install() { register_hook('prepare_body', 'addon/privacy_image_cache/privacy_image_cache.php', 'privacy_image_cache_prepare_body_hook'); @@ -83,7 +84,6 @@ function privacy_image_cache_init() { if ($cachefile != '') { if (file_exists($cachefile)) { $img_str = file_get_contents($cachefile); - $mime = image_type_to_mime_type(exif_imagetype($cachefile)); header("Content-type: $mime"); @@ -92,21 +92,19 @@ function privacy_image_cache_init() { header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT"); header("Cache-Control: max-age=31536000"); + $img = new Photo($img_str, $mime); + if($img->is_valid()) + $img_str = $img->imageString(); + 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); - //} + if (is_dir($_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache")) + file_put_contents($_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache/".privacy_image_cache_cachename($_REQUEST['url'], true), $img_str); killme(); } } - require_once("Photo.php"); - $valid = true; $r = q("SELECT * FROM `photo` WHERE `resource-id` in ('%s', '%s') LIMIT 1", $urlhash, $urlhash2); @@ -119,15 +117,6 @@ function privacy_image_cache_init() { // It shouldn't happen but it does - spaces in URL $_REQUEST['url'] = str_replace(" ", "+", $_REQUEST['url']); - // if the picture seems to be from another picture cache then take the original source - //$queryvar = privacy_image_cache_parse_query($_REQUEST['url']); - //if ($queryvar['url'] != "") - // $_REQUEST['url'] = urldecode($queryvar['url']); - - // if fetching facebook pictures don't fetch the thumbnail but the big one - //if (strpos($_REQUEST['url'], ".fbcdn.net/") and (substr($_REQUEST['url'], -6) == "_s.jpg")) - // $_REQUEST['url'] = substr($_REQUEST['url'], 0, -6)."_n.jpg"; - $redirects = 0; $img_str = fetch_url($_REQUEST['url'],true, $redirects, 10); @@ -147,7 +136,6 @@ function privacy_image_cache_init() { $img->scaleImage(10); $img_str = $img->imageString(); } - //} else if (substr($img_str, 0, 6) == "GIF89a") { } else if ($mime != "image/jpeg") { $image = @imagecreatefromstring($img_str); @@ -171,17 +159,20 @@ function privacy_image_cache_init() { ); } else { - $img = new Photo($img_str); + $img = new Photo($img_str, $mime); if($img->is_valid()) { $img->store(0, 0, $urlhash, $_REQUEST['url'], '', 100); if ($thumb) $img->scaleImage(200); // Test $img_str = $img->imageString(); } - $mime = "image/jpeg"; + //$mime = "image/jpeg"; } } + $img = new Photo($img_str, $mime); + if($img->is_valid()) + $img_str = $img->imageString(); // If there is a real existing directory then put the cache file there // advantage: real file access is really fast @@ -203,13 +194,6 @@ 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(); } diff --git a/rendertime/rendertime.php b/rendertime/rendertime.php index f73e0856..dcbfb411 100755 --- a/rendertime/rendertime.php +++ b/rendertime/rendertime.php @@ -32,10 +32,12 @@ function rendertime_page_end(&$a, &$o) { round($a->performance["rendering"], 3), round($a->performance["parser"], 3), round($a->performance["file"], 3), - //round($a->performance["markstart"], 3), round($duration - $a->performance["database"] - $a->performance["network"] - $a->performance["rendering"] - $a->performance["parser"] - $a->performance["file"], 3), - round($duration, 3)).""; + round($duration, 3) + //round($a->performance["markstart"], 3) + //round($a->performance["plugin"], 3) + ).""; } From 01292c59edc63333a4eed368f953df46c7fc6d7b Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 17 Feb 2013 12:37:32 +0100 Subject: [PATCH 7/8] privacy_image_cache: Only compress files that aren't GIFs --- privacy_image_cache/privacy_image_cache.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/privacy_image_cache/privacy_image_cache.php b/privacy_image_cache/privacy_image_cache.php index 30155fab..d228a734 100644 --- a/privacy_image_cache/privacy_image_cache.php +++ b/privacy_image_cache/privacy_image_cache.php @@ -48,9 +48,6 @@ function privacy_image_cache_init() { exit; } - //if ($a->config["system"]["db_log"] != "") - // $stamp1 = microtime(true); - if(function_exists('header_remove')) { header_remove('Pragma'); header_remove('pragma'); @@ -169,10 +166,12 @@ function privacy_image_cache_init() { //$mime = "image/jpeg"; } } - - $img = new Photo($img_str, $mime); - if($img->is_valid()) - $img_str = $img->imageString(); + // reduce quality - if it isn't a GIF + if ($mime != "image/gif") { + $img = new Photo($img_str, $mime); + if($img->is_valid()) + $img_str = $img->imageString(); + } // If there is a real existing directory then put the cache file there // advantage: real file access is really fast @@ -199,7 +198,9 @@ function privacy_image_cache_init() { function privacy_image_cache_cachename($url, $writemode = false) { global $_SERVER; - +// echo $url; +// $mime = image_type_to_mime_type(exif_imagetype($url)); +// echo $mime; $basepath = $_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache"; $path = substr(hash("md5", $url), 0, 2); From 6b124bf016cb263485a317337d8ad407dbbe4b52 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 17 Feb 2013 18:47:36 +0100 Subject: [PATCH 8/8] privacy_image_cache: the include path to "Photo.php" wasn't correct. --- privacy_image_cache/privacy_image_cache.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/privacy_image_cache/privacy_image_cache.php b/privacy_image_cache/privacy_image_cache.php index d228a734..b38cd5e7 100644 --- a/privacy_image_cache/privacy_image_cache.php +++ b/privacy_image_cache/privacy_image_cache.php @@ -9,7 +9,7 @@ define("PRIVACY_IMAGE_CACHE_DEFAULT_TIME", 86400); // 1 Day require_once('include/security.php'); -require_once("Photo.php"); +require_once("include/Photo.php"); function privacy_image_cache_install() { register_hook('prepare_body', 'addon/privacy_image_cache/privacy_image_cache.php', 'privacy_image_cache_prepare_body_hook'); @@ -89,9 +89,12 @@ function privacy_image_cache_init() { header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT"); header("Cache-Control: max-age=31536000"); - $img = new Photo($img_str, $mime); - if($img->is_valid()) - $img_str = $img->imageString(); + // reduce quality - if it isn't a GIF + if ($mime != "image/gif") { + $img = new Photo($img_str, $mime); + if($img->is_valid()) + $img_str = $img->imageString(); + } echo $img_str;