aboutsummaryrefslogtreecommitdiffstats
path: root/i.php
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2012-01-01 21:10:43 +0000
committerrvelices <rv-github@modusoptimus.com>2012-01-01 21:10:43 +0000
commit95a78ca0d3412ffa1d54e13c9caab7bc8b6b0e13 (patch)
treee6fe20dc51fbd1efefbd0d11aa9d0893b470891e /i.php
parentec82ebbdccf9340d9168d8c061e94e52100aa8f1 (diff)
feature 2541 multisize
- admin GUI for choosing derivative parameters + persistence git-svn-id: http://piwigo.org/svn/trunk@12820 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--i.php58
1 files changed, 37 insertions, 21 deletions
diff --git a/i.php b/i.php
index 29909ec3b..515876535 100644
--- a/i.php
+++ b/i.php
@@ -167,7 +167,7 @@ function parse_request()
{
try
{
- $page['derivative_params'] = ImageParams::from_url_tokens($deriv);
+ $page['derivative_params'] = DerivativeParams::from_url_tokens($deriv);
}
catch (Exception $e)
{
@@ -184,6 +184,33 @@ function parse_request()
}
+function send_derivative($expires)
+{
+ global $page;
+ $fp = fopen($page['derivative_path'], 'rb');
+
+ $fstat = fstat($fp);
+ header('Last-Modified: '.gmdate('D, d M Y H:i:s', $fstat['mtime']).' GMT');
+ if ($expires!==false)
+ {
+ header('Expires: '.gmdate('D, d M Y H:i:s', $expires).' GMT');
+ }
+ header('Content-length: '.$fstat['size']);
+ header('Connection: close');
+
+ $ctype="application/octet-stream";
+ switch (strtolower($page['derivative_ext']))
+ {
+ case ".jpe": case ".jpeg": case ".jpg": $ctype="image/jpeg"; break;
+ case ".png": $ctype="image/png"; break;
+ case ".gif": $ctype="image/gif"; break;
+ }
+ header("Content-Type: $ctype");
+
+ fpassthru($fp);
+ fclose($fp);
+}
+
$page=array();
@@ -221,6 +248,13 @@ if ($derivative_mtime === false or
$need_generate = true;
}
+$expires=false;
+$now = time();
+if ( $now > (max($src_mtime, $params->last_mod_time) + 24*3600) )
+{// somehow arbitrary - if derivative params or src didn't change for the last 24 hours, we send an expire header for several days
+ $expires = $now + 10*24*3600;
+}
+
if (!$need_generate)
{
if ( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] )
@@ -230,7 +264,7 @@ if (!$need_generate)
header('Expires: '.gmdate('D, d M Y H:i:s', time()+10*24*3600).' GMT', true, 304);
exit;
}
- // todo send pass-through
+ send_derivative($expires);
}
@@ -270,23 +304,5 @@ if (!$changes)
$image->write( $page['derivative_path'] );
$image->destroy();
-$fp = fopen($page['derivative_path'], 'rb');
-
-$fstat = fstat($fp);
-header('Last-Modified: '.gmdate('D, d M Y H:i:s', $fstat['mtime']).' GMT');
-header('Expires: '.gmdate('D, d M Y H:i:s', time()+10*24*3600).' GMT');
-header('Content-length: '.$fstat['size']);
-header('Connection: close');
-
-$ctype="application/octet-stream";
-switch (strtolower($page['derivative_ext']))
-{
- case ".jpe": case ".jpeg": case ".jpg": $ctype="image/jpeg"; break;
- case ".png": $ctype="image/png"; break;
- case ".gif": $ctype="image/gif"; break;
-}
-header("Content-Type: $ctype");
-
-fpassthru($fp);
-fclose($fp);
+send_derivative($expires);
?> \ No newline at end of file