Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F726963
D35.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jan 6, 3:54 AM
Size
3 KB
Mime Type
text/x-diff
Expires
Tue, Jan 7, 3:54 AM (3 d, 18 m ago)
Engine
blob
Format
Raw Data
Handle
537039
Attached To
D35: INP-1399 - Use relative paths during hash calculations
D35.diff
View Options
Index: branches/5.2.x/core/units/helpers/file_helper.php
===================================================================
--- branches/5.2.x/core/units/helpers/file_helper.php
+++ branches/5.2.x/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: branches/5.2.x/core/units/helpers/image_helper.php
===================================================================
--- branches/5.2.x/core/units/helpers/image_helper.php
+++ branches/5.2.x/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 "\<number>"
- $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 "\<number>".
+ $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: branches/5.2.x/core/units/helpers/minifiers/minify_helper.php
===================================================================
--- branches/5.2.x/core/units/helpers/minifiers/minify_helper.php
+++ branches/5.2.x/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
+ }
Event Timeline
Log In to Comment