X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=privacy_image_cache%2Fprivacy_image_cache.php;h=0e241e7e36825b8aea73635b30aa5fdb396c05cf;hb=8c154ddd08a6ac8d6666bb1090107546afed2f24;hp=a47f0e1ac5294b7aa0cf405ed619afa4655f79f9;hpb=951df82c99d7a8d638d99bdddab469e12c6ca4ce;p=friendica-addons.git diff --git a/privacy_image_cache/privacy_image_cache.php b/privacy_image_cache/privacy_image_cache.php index a47f0e1a..0e241e7e 100644 --- a/privacy_image_cache/privacy_image_cache.php +++ b/privacy_image_cache/privacy_image_cache.php @@ -119,7 +119,17 @@ function privacy_image_cache_init() { // It shouldn't happen but it does - spaces in URL $_REQUEST['url'] = str_replace(" ", "+", $_REQUEST['url']); - $img_str = fetch_url($_REQUEST['url'],true); + // 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); $tempfile = tempnam(get_config("system","temppath"), "cache"); file_put_contents($tempfile, $img_str); @@ -132,9 +142,9 @@ function privacy_image_cache_init() { $mime = "image/png"; $cachefile = ""; // Clear the cachefile so that the dummy isn't stored $valid = false; - $img = new Photo($img_str); + $img = new Photo($img_str, "image/png"); if($img->is_valid()) { - $img->scaleImage(1); + $img->scaleImage(10); $img_str = $img->imageString(); } //} else if (substr($img_str, 0, 6) == "GIF89a") { @@ -226,13 +236,21 @@ function privacy_image_cache_cachename($url, $writemode = false) { * @return boolean */ function privacy_image_cache_is_local_image($url) { - if ($url[0] == '/') return true; + if ($url[0] == '/') return true; + if (strtolower(substr($url, 0, 5)) == "data:") return true; + // 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) + return true; + } + // links normalised - bug #431 - $baseurl = normalise_link(get_app()->get_baseurl()); + $baseurl = normalise_link(get_app()->get_baseurl()); $url = normalise_link($url); - return (substr($url, 0, strlen($baseurl)) == $baseurl); + return (substr($url, 0, strlen($baseurl)) == $baseurl); } /** @@ -311,13 +329,11 @@ function privacy_image_cache_cron(&$a = null, &$b = null) { logger("Purging old Cache of the Privacy Image Cache", LOGGER_DEBUG); q('DELETE FROM `photo` WHERE `uid` = 0 AND `resource-id` LIKE "pic:%%" AND `created` < NOW() - INTERVAL %d SECOND', $cachetime); - set_config('pi_cache', 'last_delete', $time); clear_cache($a->get_basepath(), $a->get_basepath()."/privacy_image_cache"); -} - - + set_config('pi_cache', 'last_delete', $time); +} /** * @param App $a @@ -364,3 +380,22 @@ function privacy_image_cache_plugin_admin_post(&$a = null, &$o = null){ q('DELETE FROM `photo` WHERE `uid` = 0 AND `resource-id` LIKE "pic:%%"'); } } + +function privacy_image_cache_parse_query($var) { + /** + * Use this function to parse out the query array element from + * the output of parse_url(). + */ + $var = parse_url($var, PHP_URL_QUERY); + $var = html_entity_decode($var); + $var = explode('&', $var); + $arr = array(); + + foreach($var as $val) { + $x = explode('=', $val); + $arr[$x[0]] = $x[1]; + } + + unset($val, $x, $var); + return $arr; +}