From cd8944cdccc96ed7697712b70ed64e48ffad022c Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 25 Jul 2012 21:37:48 +0200 Subject: [PATCH 1/4] privacy_image_cache: Adding a file cache statusnet/twitter: Adding detection of another recycle sign --- privacy_image_cache/privacy_image_cache.php | 31 +++++++++++++++++++-- statusnet/statusnet.php | 6 ++-- twitter/twitter.php | 6 ++-- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/privacy_image_cache/privacy_image_cache.php b/privacy_image_cache/privacy_image_cache.php index f0d8e39a..e74054e9 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'); @@ -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"; @@ -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(); } diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index b433f57b..46b3f03f 100755 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -460,9 +460,9 @@ function statusnet_post_hook(&$a,&$b) { // recycle 1 $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8'); $tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', $recycle.'$2', $tmp); - // recycle 2 - //$recycle = html_entity_decode("♻ ", ENT_QUOTES, 'UTF-8'); - //$tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', 'RT @$2:', $tmp); + // recycle 2 (test) + $recycle = html_entity_decode("◌ ", ENT_QUOTES, 'UTF-8'); + $tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', $recycle.'$2', $tmp); } // preserve links to webpages $tmp = preg_replace( '/\[url\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\](\w+.*?)\[\/url\]/i', '$2 $1', $tmp); diff --git a/twitter/twitter.php b/twitter/twitter.php index 04c1c87d..cb7b03bb 100755 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -326,9 +326,9 @@ function twitter_post_hook(&$a,&$b) { // recycle 1 $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8'); $tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', $recycle.'$2', $tmp); - // recycle 2 - //$recycle = html_entity_decode("♻ ", ENT_QUOTES, 'UTF-8'); - //$tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', 'RT @$2:', $tmp); + // recycle 2 (Test) + $recycle = html_entity_decode("◌ ", ENT_QUOTES, 'UTF-8'); + $tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', $recycle.'$2', $tmp); } $tmp = preg_replace( '/\[url\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\](\w+.*?)\[\/url\]/i', '$2 $1', $tmp); $tmp = preg_replace( '/\[bookmark\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\](\w+.*?)\[\/bookmark\]/i', '$2 $1', $tmp); From 88048bc18e7f449a28222c9cd681f24074f77e73 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 25 Jul 2012 23:44:57 +0200 Subject: [PATCH 2/4] privacy_image_cache: removed experimentual resize of pictures --- privacy_image_cache/privacy_image_cache.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/privacy_image_cache/privacy_image_cache.php b/privacy_image_cache/privacy_image_cache.php index e74054e9..963b8f77 100644 --- a/privacy_image_cache/privacy_image_cache.php +++ b/privacy_image_cache/privacy_image_cache.php @@ -80,13 +80,13 @@ function privacy_image_cache_init() { if ($mime == "") $mime = "image/jpeg"; // Test - if ($mime == "image/jpeg") { - $img = new Photo($img_str); - if($img->is_valid()) { - $img->scaleImage(1000); - $img_str = $img->imageString(); - } - } + //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']); From d33c56574590db597ed3340c8c23311125693f21 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 26 Jul 2012 00:25:43 +0200 Subject: [PATCH 3/4] privacy_image_cache: removed experimental resize --- privacy_image_cache/privacy_image_cache.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/privacy_image_cache/privacy_image_cache.php b/privacy_image_cache/privacy_image_cache.php index 963b8f77..2309ff22 100644 --- a/privacy_image_cache/privacy_image_cache.php +++ b/privacy_image_cache/privacy_image_cache.php @@ -48,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); @@ -129,7 +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->scaleImage(1000); // Test $img_str = $img->imageString(); } $mime = "image/jpeg"; From 14e10be1c4302b33cdc43ee00018ea78b618b6f2 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 2 Aug 2012 00:16:56 +0200 Subject: [PATCH 4/4] privacy_image_cache: checking if the cached file really is an image --- privacy_image_cache/privacy_image_cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/privacy_image_cache/privacy_image_cache.php b/privacy_image_cache/privacy_image_cache.php index 2309ff22..8c68ef9a 100644 --- a/privacy_image_cache/privacy_image_cache.php +++ b/privacy_image_cache/privacy_image_cache.php @@ -137,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");