Index: core/units/helpers/file_helper.php =================================================================== --- core/units/helpers/file_helper.php +++ core/units/helpers/file_helper.php @@ -418,6 +418,27 @@ } /** + * Makes given paths DocumentRoot agnostic. + * + * @param array $paths List of file paths. + * + * @return array + */ + public function makeRelative(array $paths) + { + foreach ( $paths as $index => $path ) { + $replaced_count = 0; + $relative_path = preg_replace('/^' . preg_quote(FULL_PATH, '/') . '/', '', $path, 1, $replaced_count); + + if ( $replaced_count === 1 ) { + $paths[$index] = $relative_path; + } + } + + return $paths; + } + + /** * Ensures, that new file will not overwrite any of previously created files with same name * * @param string $path Index: core/units/helpers/image_helper.php =================================================================== --- core/units/helpers/image_helper.php +++ core/units/helpers/image_helper.php @@ -119,10 +119,16 @@ $src_path = dirname($src_image); $transform_keys = Array ('crop_x', 'crop_y', 'fill', 'wm_filename'); - if ($needs_resize || array_intersect(array_keys($params), $transform_keys)) { - // resize required OR watermarking required -> change resulting image name ! - $src_path_escaped = preg_replace('/(\\\[\d]+)/', '\\\\\1', $src_path); // escape replacement patterns, like "\" - $dst_image = preg_replace('/^'.preg_quote($src_path, '/').'(.*)\.(.*)$/', $src_path_escaped . DIRECTORY_SEPARATOR . 'resized\\1_' . crc32(serialize($params)) . '.\\2', $src_image); + // Resize required OR watermarking required -> change resulting image name ! + if ( $needs_resize || array_intersect(array_keys($params), $transform_keys) ) { + // Escape replacement patterns, like "\". + $src_path_escaped = preg_replace('/(\\\[\d]+)/', '\\\\\1', $src_path); + $params_hash = kUtil::crc32(serialize($this->fileHelper->makeRelative($params))); + $dst_image = preg_replace( + '/^' . preg_quote($src_path, '/') . '(.*)\.(.*)$/', + $src_path_escaped . DIRECTORY_SEPARATOR . 'resized\\1_' . $params_hash . '.\\2', + $src_image + ); $this->fileHelper->CheckFolder( dirname($dst_image) ); Index: core/units/helpers/minifiers/minify_helper.php =================================================================== --- core/units/helpers/minifiers/minify_helper.php +++ core/units/helpers/minifiers/minify_helper.php @@ -77,11 +77,14 @@ $save_as = isset($params['save_as']) ? $params['save_as'] : false; $dst_file = $this->resourceFolder . DIRECTORY_SEPARATOR . ($this->debugMode ? 'd' : 'c') . '_'; + /** @var FileHelper $file_helper */ + $file_helper = $this->Application->recallObject('FileHelper'); + if ( $save_as ) { $dst_file .= $save_as . ( strpos($save_as, '.') === false ? '.' . $extension : '' ); } else { - $dst_file .= $this->_getHash($files) . '.' . $extension; + $dst_file .= $this->_getHash($file_helper->makeRelative($files)) . '.' . $extension; } $was_compressed = file_exists($dst_file); @@ -125,9 +128,6 @@ file_put_contents($dst_file, $string); } - $file_helper = $this->Application->recallObject('FileHelper'); - /* @var $file_helper FileHelper */ - return $file_helper->pathToUrl($dst_file) . '?ts=' . adodb_date('Y-m-d_H:i:s', filemtime($dst_file)); } @@ -169,7 +169,7 @@ array_unshift($hash, 'A:0;T:' . $this->Application->GetVar('m_theme')); } - return crc32( implode('|', $hash) ); + return kUtil::crc32(implode('|', $hash)); } /** @@ -312,4 +312,4 @@ return $ret; } - } \ No newline at end of file + }