From e116b90116b3d61548ce2bcf8949deee5feb6b98 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Tue, 6 Nov 2018 13:37:50 +0100 Subject: 'Last-Modified' and 'Content-Length' HTTP headers added for better image caching --- Zotlabs/Module/Photo.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Photo.php b/Zotlabs/Module/Photo.php index f01909ff5..14def3a62 100644 --- a/Zotlabs/Module/Photo.php +++ b/Zotlabs/Module/Photo.php @@ -33,8 +33,6 @@ class Photo extends \Zotlabs\Web\Controller { $observer_xchan = get_observer_hash(); - $default = z_root() . '/' . get_default_profile_photo(); - if(isset($type)) { /** @@ -44,22 +42,24 @@ class Photo extends \Zotlabs\Web\Controller { if($type === 'profile') { switch($res) { - case 'm': $resolution = 5; - $default = z_root() . '/' . get_default_profile_photo(80); + $default = get_default_profile_photo(80); break; case 's': $resolution = 6; - $default = z_root() . '/' . get_default_profile_photo(48); + $default = get_default_profile_photo(48); break; case 'l': default: $resolution = 4; + $default = get_default_profile_photo(); break; } } + $modified = filemtime($default); + $default = z_root() . '/' . $default; $uid = $person; $d = [ 'imgscale' => $resolution, 'channel_id' => $uid, 'default' => $default, 'data' => '', 'mimetype' => '' ]; @@ -78,11 +78,13 @@ class Photo extends \Zotlabs\Web\Controller { intval(PHOTO_PROFILE) ); if($r) { + $modified = strtotime($r[0]['edited']); $data = dbunescbin($r[0]['content']); $mimetype = $r[0]['mimetype']; } - if(intval($r[0]['os_storage'])) + if(intval($r[0]['os_storage'])) { $data = file_get_contents($data); + } } if(! $data) { $data = fetch_image_from_url($default,$mimetype); @@ -164,6 +166,7 @@ class Photo extends \Zotlabs\Web\Controller { if($exists && $allowed) { $data = dbunescbin($e[0]['content']); $mimetype = $e[0]['mimetype']; + $modified = strtotime($e[0]['edited']); if(intval($e[0]['os_storage'])) { $streaming = $data; } @@ -183,7 +186,6 @@ class Photo extends \Zotlabs\Web\Controller { if(! isset($data)) { if(isset($resolution)) { switch($resolution) { - case 4: $data = fetch_image_from_url(z_root() . '/' . get_default_profile_photo(),$mimetype); break; @@ -210,10 +212,14 @@ class Photo extends \Zotlabs\Web\Controller { } } + // @FIXME Seems never invoked // Writing in cachefile - if (isset($cachefile) && $cachefile != '') + if (isset($cachefile) && $cachefile != '') { file_put_contents($cachefile, $data); - + $modified = filemtime($cachefile); + } + + if(function_exists('header_remove')) { header_remove('Pragma'); header_remove('pragma'); @@ -247,6 +253,7 @@ class Photo extends \Zotlabs\Web\Controller { } + // If it's a file resource, stream it. if($streaming && $channel) { @@ -262,6 +269,8 @@ class Photo extends \Zotlabs\Web\Controller { } } else { + header("Last-Modified: " . gmdate("D, d M Y H:i:s", $modified) . " GMT"); + header("Content-Length: " . strlen($data)); echo $data; } -- cgit v1.2.3 From c26f45b7c20c870fcc77258a0c282440ec3e0b5a Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Tue, 6 Nov 2018 13:39:36 +0100 Subject: Update Photo.php --- Zotlabs/Module/Photo.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Photo.php b/Zotlabs/Module/Photo.php index 14def3a62..8f85bdd69 100644 --- a/Zotlabs/Module/Photo.php +++ b/Zotlabs/Module/Photo.php @@ -39,7 +39,9 @@ class Photo extends \Zotlabs\Web\Controller { * Profile photos - Access controls on default profile photos are not honoured since they need to be exchanged with remote sites. * */ - + + $default = get_default_profile_photo(); + if($type === 'profile') { switch($res) { case 'm': @@ -53,7 +55,6 @@ class Photo extends \Zotlabs\Web\Controller { case 'l': default: $resolution = 4; - $default = get_default_profile_photo(); break; } } -- cgit v1.2.3 From 1828b6daab88041dbc85f11cc4e04efede6c993b Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Tue, 6 Nov 2018 13:41:41 +0100 Subject: Update Photo.php --- Zotlabs/Module/Photo.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Photo.php b/Zotlabs/Module/Photo.php index 8f85bdd69..07443bb83 100644 --- a/Zotlabs/Module/Photo.php +++ b/Zotlabs/Module/Photo.php @@ -83,9 +83,8 @@ class Photo extends \Zotlabs\Web\Controller { $data = dbunescbin($r[0]['content']); $mimetype = $r[0]['mimetype']; } - if(intval($r[0]['os_storage'])) { + if(intval($r[0]['os_storage'])) $data = file_get_contents($data); - } } if(! $data) { $data = fetch_image_from_url($default,$mimetype); @@ -168,9 +167,8 @@ class Photo extends \Zotlabs\Web\Controller { $data = dbunescbin($e[0]['content']); $mimetype = $e[0]['mimetype']; $modified = strtotime($e[0]['edited']); - if(intval($e[0]['os_storage'])) { + if(intval($e[0]['os_storage'])) $streaming = $data; - } } else { if(! $allowed) { -- cgit v1.2.3 From 3491c488d340b7d5b4e0610398427cb52c05bf8e Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Tue, 6 Nov 2018 13:51:01 +0100 Subject: Update Photo.php --- Zotlabs/Module/Photo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Photo.php b/Zotlabs/Module/Photo.php index 07443bb83..d76fca278 100644 --- a/Zotlabs/Module/Photo.php +++ b/Zotlabs/Module/Photo.php @@ -252,6 +252,8 @@ class Photo extends \Zotlabs\Web\Controller { } + header("Last-Modified: " . gmdate("D, d M Y H:i:s", $modified) . " GMT"); + header("Content-Length: " . strlen($data)); // If it's a file resource, stream it. @@ -268,8 +270,6 @@ class Photo extends \Zotlabs\Web\Controller { } } else { - header("Last-Modified: " . gmdate("D, d M Y H:i:s", $modified) . " GMT"); - header("Content-Length: " . strlen($data)); echo $data; } -- cgit v1.2.3 From 40d9277ef38ef1200db59cd2f8c6b9e2a80bc332 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Tue, 6 Nov 2018 16:22:34 +0100 Subject: remove 'Expiries' HTTP header --- Zotlabs/Module/Photo.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Photo.php b/Zotlabs/Module/Photo.php index d76fca278..0f47ee103 100644 --- a/Zotlabs/Module/Photo.php +++ b/Zotlabs/Module/Photo.php @@ -246,8 +246,7 @@ class Photo extends \Zotlabs\Web\Controller { // leave it alone. $cache = get_config('system','photo_cache_time', 86400); // 1 day by default - - header("Expires: " . gmdate("D, d M Y H:i:s", time() + $cache) . " GMT"); + header("Cache-Control: max-age=" . $cache); } -- cgit v1.2.3