summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarrel O\'Pry2007-12-17 20:38:42 (GMT)
committer Darrel O\'Pry2007-12-17 20:38:42 (GMT)
commit12c7ea1766bd6c602947943d9f97a42338bb7666 (patch)
tree5f3f03ff094c69c8aa5a8bbd8a18aecaedd282f3
parent6928324519c2813ce6dbf402a2e00dac1ce6d26f (diff)
#201774 by jpetso, fix if-modified-since support and re add content-length header to imagecache
output/ #201762 by jpetso, doxygen fixes #201757 by jpetso, use basename in place of str_replace #201640 by jpetso, hook_requirments array key fix clean_urls should be imagetoolkist
-rw-r--r--imagecache.module48
-rw-r--r--imagecache_ui.module2
2 files changed, 44 insertions, 6 deletions
diff --git a/imagecache.module b/imagecache.module
index b89324d..f0a1d4b 100644
--- a/imagecache.module
+++ b/imagecache.module
@@ -310,7 +310,7 @@ function _imagecache_cache($presetname, $path) {
}
$dst = imagecache_create_path($preset['presetname'], $path);
- $tmp = file_directory_temp() .'/'. $preset['presetname'] . str_replace(dirname($src) .'/', '', $src);
+ $tmp = file_directory_temp() .'/'. $preset['presetname'] . basename($src);
global $imagecache_lock_file;
$imagecache_lock_file = $tmp;
@@ -360,14 +360,51 @@ function imagecache_transfer($path) {
$mime = $size['mime'];
}
$headers = array('Content-Type: '. mime_header_encode($mime));
+
if ($fileinfo = stat($path)) {
- $headers[] = 'Last-Modified: '. gmdate('D, d M Y H:i:s', $fileinfo[9]) .' GMT';
+ $headers[] = 'Content-Length: '. $fileinfo[7];
+ _imagecache_cache_set_cache_headers($fileinfo, $headers);
}
file_transfer($path, $headers);
exit;
}
/**
+ * Set file headers that handle "If-Modified-Since" correctly for the
+ * given fileinfo. Most code has been taken from drupal_page_cache_header().
+ */
+function _imagecache_cache_set_cache_headers($fileinfo, &$headers) {
+ // Set default values:
+ $last_modified = gmdate('D, d M Y H:i:s', $fileinfo[9]) .' GMT';
+ $etag = '"'. md5($last_modified) .'"';
+
+ // See if the client has provided the required HTTP headers:
+ $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])
+ ? stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE'])
+ : FALSE;
+ $if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH'])
+ ? stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])
+ : FALSE;
+
+ if ($if_modified_since && $if_none_match
+ && $if_none_match == $etag // etag must match
+ && $if_modified_since == $last_modified) { // if-modified-since must match
+ header('HTTP/1.1 304 Not Modified');
+ // All 304 responses must send an etag if the 200 response
+ // for the same object contained an etag
+ header('Etag: '. $etag);
+ // We must also set Last-Modified again, so that we overwrite Drupal's
+ // default Last-Modified header with the right one
+ header('Last-Modified: '. $last_modified);
+ exit;
+ }
+
+ // Send appropriate response:
+ $headers[] = 'Last-Modified: '. $last_modified;
+ $headers[] = 'ETag: '. $etag;
+}
+
+/**
* A recursive mkdir.
*/
function _imagecache_mkdir($dir) {
@@ -394,9 +431,10 @@ function _imagecache_mkdir($dir) {
/**
* build an image cache derivative
*
- * @param $actions, array of imagecache actions.
- * @param $source, source file.
- * @param $dest, $destination file.
+ * @param $actions Array of imagecache actions.
+ * @param $src Path of the source file.
+ * @param $dst Path of the destination file.
+ * @param $tmp Path of the temporary file used for manipulating the image.
* @return TRUE - derivative generated, FALSE - no derivative generated, NULL - derivative being generated
*/
function imagecache_build_derivative($actions, $src, $dst, $tmp) {
diff --git a/imagecache_ui.module b/imagecache_ui.module
index ed43c9f..6723091 100644
--- a/imagecache_ui.module
+++ b/imagecache_ui.module
@@ -153,7 +153,7 @@ function imagecache_ui_preset_add_form_submit($id, $form_values) {
$preset = array('presetname' => $form_values['presetname']);
$preset = imagecache_preset_save($preset);
drupal_set_message(t('Preset "%name" (ID: @id) Created.', array('%name' => $preset['presetname'], '@id' => $preset['presetid'])));
- return 'admin/build/imagecache';
+ return 'admin/build/imagecache/preset/'. $preset['presetid'];
}
function imagecache_element_presetname_validate($element) {