Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F803963
D36.id293.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
Wed, Feb 26, 9:02 AM
Size
5 KB
Mime Type
text/x-diff
Expires
Thu, Feb 27, 9:02 AM (7 h, 49 m)
Engine
blob
Format
Raw Data
Handle
576683
Attached To
D36: INP-1400 - Store resized images from theme under /system folder
D36.id293.diff
View Options
Index: branches/5.2.x/core/install/upgrades.php
===================================================================
--- branches/5.2.x/core/install/upgrades.php
+++ branches/5.2.x/core/install/upgrades.php
@@ -2338,4 +2338,43 @@
$this->Conn->doUpdate($fields_hash, TABLE_PREFIX . 'Users', 'PortalUserId = ' . $user_id);
}
}
- }
\ No newline at end of file
+
+ /**
+ * Update to 5.2.2-B1
+ *
+ * @param string $mode when called mode {before, after)
+ */
+ public function Upgrade_5_2_2_B1($mode)
+ {
+ if ( $mode != 'after' ) {
+ return;
+ }
+
+ $this->deleteThumbnails();
+ }
+
+ /**
+ * Deletes folders, containing thumbnails recursively.
+ *
+ * @param string $folder Folder.
+ *
+ * @return void
+ */
+ protected function deleteThumbnails($folder = WRITEABLE)
+ {
+ foreach ( glob($folder . '/*', GLOB_ONLYDIR) as $sub_folder ) {
+ if ( $sub_folder === WRITEABLE . '/cache' ) {
+ continue;
+ }
+
+ if ( basename($sub_folder) === 'resized' ) {
+ $files = glob($sub_folder . '/*');
+ array_map('unlink', $files);
+ rmdir($sub_folder);
+ }
+ else {
+ $this->deleteThumbnails($sub_folder);
+ }
+ }
+ }
+ }
Index: branches/5.2.x/core/kernel/constants.php
===================================================================
--- branches/5.2.x/core/kernel/constants.php
+++ branches/5.2.x/core/kernel/constants.php
@@ -75,6 +75,8 @@
// place for product file uploads (sort of "/system/images" but for all other files)
define('ITEM_FILES_PATH', WRITEBALE_BASE . '/downloads/');
+ define('THUMBS_PATH', WRITEBALE_BASE . '/thumbs');
+
class MailingList {
const NOT_PROCESSED = 1;
const PARTIALLY_PROCESSED = 2;
Index: branches/5.2.x/core/kernel/db/db_event_handler.php
===================================================================
--- branches/5.2.x/core/kernel/db/db_event_handler.php
+++ branches/5.2.x/core/kernel/db/db_event_handler.php
@@ -3181,8 +3181,11 @@
$this->deleteTempFiles($tmp_path);
- if ( file_exists($tmp_path . 'resized/') ) {
- $this->deleteTempFiles($tmp_path . 'resized/');
+ $thumbs_path = preg_replace('/^' . preg_quote(FULL_PATH, '/') . '/', '', $tmp_path, 1);
+ $thumbs_path = FULL_PATH . THUMBS_PATH . $thumbs_path;
+
+ if ( file_exists($thumbs_path) ) {
+ $this->deleteTempFiles($thumbs_path);
}
}
@@ -3215,12 +3218,12 @@
$files = glob($path . '*.*');
$max_file_date = strtotime('-1 day');
- foreach ($files as $file) {
- if (filemtime($file) < $max_file_date) {
+ foreach ( $files as $file ) {
+ if ( filemtime($file) < $max_file_date ) {
unlink($file);
}
}
- }
+ }
/**
* Checks, that flash uploader is allowed to perform upload
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
@@ -61,8 +61,15 @@
}
elseif (preg_match('/^fill:(.*)$/', $format_part, $regs)) {
$res['fill'] = $regs[1];
- } elseif (preg_match('/^default:(.*)$/', $format_part, $regs)) {
- $res['default'] = FULL_PATH.THEMES_PATH.'/'.$regs[1];
+ }
+ elseif ( preg_match('/^default:(.*)$/', $format_part, $regs) ) {
+ $default_image = FULL_PATH . THEMES_PATH . '/' . $regs[1];
+
+ if ( strpos($default_image, '../') !== false ) {
+ $default_image = realpath($default_image);
+ }
+
+ $res['default'] = $default_image;
}
}
@@ -126,10 +133,14 @@
$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_path_escaped . '\\1_' . $params_hash . '.\\2',
$src_image
);
+ // Keep resized version of all images under "/system/thumbs/" folder.
+ $dst_image = preg_replace('/^' . preg_quote(FULL_PATH, '/') . '/', '', $dst_image, 1);
+ $dst_image = FULL_PATH . THUMBS_PATH . $dst_image;
+
$this->fileHelper->CheckFolder( dirname($dst_image) );
if (!file_exists($dst_image) || filemtime($src_image) > filemtime($dst_image)) {
Index: branches/5.2.x/core/units/images/image_event_handler.php
===================================================================
--- branches/5.2.x/core/units/images/image_event_handler.php
+++ branches/5.2.x/core/units/images/image_event_handler.php
@@ -29,7 +29,6 @@
$permissions = Array (
'OnCleanImages' => Array ('subitem' => true),
- 'OnCleanResizedImages' => Array ('subitem' => true),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
@@ -472,25 +471,4 @@
}
}
- /**
- * [SCHEDULED TASK] Remove all images from "/system/images/resized" and "/system/images/pending/resized" folders
- *
- * @param kEvent $event
- */
- function OnCleanResizedImages($event)
- {
- $images = glob(FULL_PATH . IMAGES_PATH . 'resized/*.*');
- if ($images) {
- foreach ($images as $image) {
- unlink($image);
- }
- }
-
- $images = glob(FULL_PATH . IMAGES_PENDING_PATH . 'resized/*.*');
- if ($images) {
- foreach ($images as $image) {
- unlink($image);
- }
- }
- }
-}
\ No newline at end of file
+}
Index: branches/5.2.x/core/units/images/images_config.php
===================================================================
--- branches/5.2.x/core/units/images/images_config.php
+++ branches/5.2.x/core/units/images/images_config.php
@@ -71,7 +71,6 @@
'ScheduledTasks' => Array (
'clean_catalog_images' => Array ('EventName' => 'OnCleanImages', 'RunSchedule' => '0 0 * * 0', 'Status' => STATUS_DISABLED),
- 'clean_resized_catalog_images' => Array ('EventName' => 'OnCleanResizedImages', 'RunSchedule' => '0 0 1 * *', 'Status' => STATUS_DISABLED),
),
'IDField' => 'ImageId',
@@ -181,4 +180,4 @@
),
),
),
- );
\ No newline at end of file
+ );
Event Timeline
Log In to Comment