Skip to content

Commit

Permalink
version 1.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Volkmar Kantor committed Oct 24, 2024
1 parent 778f787 commit 68dcf83
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 78 deletions.
2 changes: 1 addition & 1 deletion __dev/proxyStubs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
const STUBS = [
{
url: '/fake-ajax-url/crop_thumbnails/v1/crop?imageId=123&posttype=',
url: '/fake-ajax-url/crop_thumbnails/v1/crop?imageId=123',
method: 'GET',
content: {
"options": {
Expand Down
36 changes: 25 additions & 11 deletions __dev/src/components/CropEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@
<div>
<button type="button" class="button" v-if="cropData.options.debug_js" @click="showDebugClick('js')">show JS-Debug</button>
<button type="button" class="button" v-if="cropData.options.debug_data && dataDebug!==null" @click="showDebugClick('data')">show Data-Debug</button>
<pre v-if="showDebugType==='data'">{{ dataDebug }}</pre>
<pre v-if="showDebugType==='js'"><br />cropImage:{{cropImage}}<br />cropData:{{ cropData }}</pre>
<pre class="cropThumbnailDebug" v-if="showDebugType==='data'">{{ dataDebug }}
<button class="copyDebug" @click="copyToClipboard(dataDebug)">Copy</button>
</pre>
<pre class="cropThumbnailDebug" v-if="showDebugType==='js'">{{ cropData }}
<button class="copyDebug" @click="copyToClipboard(cropData)">Copy</button>
</pre>
</div>
</div>
</div>
Expand Down Expand Up @@ -127,7 +131,6 @@ export default {
dataDebug : null,//will be filled after the crop request finished
sameRatioMode : null,// can be NULL, "select" or "group"
sameRatioModeOptions: [],
cropOptions: null,
largeHandles: false,
Expand Down Expand Up @@ -212,13 +215,18 @@ export default {
},
hasSettingsSameRatioMode() {
return this.options?.same_ratio_mode ?? false;
},
sameRatioModeOptions() {
if(!this.lang) return [];
return [
{ value: null, text: this.lang.label_same_ratio_mode_nothing },
{ value: 'select', text: this.lang.label_same_ratio_mode_select },
{ value: 'group', text: this.lang.label_same_ratio_mode_group },
];
}
},
methods:{
doSetup() {
if(typeof this.imageId === 'string') {
this.imageId = parseInt(this.imageId);
}
this.loadCropData();
},
cropAreaLoaded() {
Expand All @@ -237,11 +245,6 @@ export default {
},
setupRatioMode() {
if(this.errorMessage) return;
this.sameRatioModeOptions = [
{ value: null, text: this.lang.label_same_ratio_mode_nothing },
{ value: 'select', text: this.lang.label_same_ratio_mode_select },
{ value: 'group', text: this.lang.label_same_ratio_mode_group },
];
try { this.sameRatioMode = localStorage.getItem('cpt_same_ratio_mode'); } catch(e) {}
if(this.hasSettingsSameRatioMode) {
Expand Down Expand Up @@ -459,6 +462,17 @@ export default {
this.loading = false;
});
}
},
copyToClipboard(text) {
try {
if(typeof text === 'object') text = JSON.stringify(text, null, "\t");
//use the clipboard API
navigator.clipboard.writeText(text).then(() => {
alert('Text copied to clipboard');
});
} catch (error) {
alert('Error while try to copy to clipboard');
}
}
}
}
Expand Down
28 changes: 16 additions & 12 deletions __dev/src/style/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
/**** MODAL ****/
/* @see https://www.w3schools.com/howto/howto_css_modals.asp */
body.cpt_ModalIsOpen { overflow: hidden; }
#cpt_Modal { display: block; position: fixed; z-index: 99999999; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; padding:0; box-sizing: border-box; background-color: rgba(0,0,0,0.4);
#cpt_Modal { display: block; position: fixed; z-index: 99999999; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; padding:0; box-sizing: border-box; background-color: rgba(0,0,0,0.4);
@media(min-width:900px) { padding:40px; }

.cpt_ModalDialog { position: relative; background-color: #fff; overflow: hidden; margin: auto; padding: 0px; width: 100%; max-width: 100%; height: 100%; margin-top:0; box-shadow: 0 0 20px rgba(0,0,0,0.5); }
.cpt_ModalHeader { height: 40px; }
.cpt_ModalHeader .cpt_ModalTitle { font-size:20px; font-weight: 300; line-height: 1; padding: 10px 50px 10px 20px; background: #eee; color:#000; }
.cpt_ModalContent { width:100%; height: 100%; padding-top:40px; margin-top:-40px; box-sizing: border-box; }

/* The Close Button */
.cpt_ModalClose { color: #000; border:none; background: transparent; position: absolute; right:0; top:0; font-size: 38px; font-weight: 300; padding:0px 8px 10px 8px; line-height: 30px; }
.cpt_ModalClose:hover,
Expand Down Expand Up @@ -56,17 +56,17 @@ body.cpt_ModalIsOpen { overflow: hidden; }
.cptEditorInner { position: relative; overflow-y: auto; height: 100%; }
.cptEditorInner.loading { overflow-y: hidden; }

.cptSelectionPaneInner .cptToolbar { display:flex; align-items: flex-start; padding: 5px 10px;
.cptSelectionPaneInner .cptToolbar { display:flex; align-items: flex-start; padding: 5px 10px;
label { display: inline-block; margin-right: 0.3em; }
}

.cptImageSizelist { border-top: 3px solid #efefef; margin-top:0; padding:3px; display: flex; flex-wrap: wrap;
.CropImageSize { cursor:pointer; position: relative; float: left; padding: 8px; margin: 0; color: #444; cursor: pointer; list-style: none; text-align: center; box-sizing: border-box; box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 6px transparent; transition:box-shadow .5s ease; }
.CropImageSize.active { box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 6px #0073aa; }
.CropImageSize:hover,
.CropImageSize:focus {background: #eee; }

.CropImageSize { width: 50%;
.CropImageSize { width: 50%;
@media(min-width:520px) { width: 33.32%; }
@media(min-width:760px) { width: 50%; }
@media(min-width:1100px) { width: 33.32%; }
Expand All @@ -75,20 +75,24 @@ body.cpt_ModalIsOpen { overflow: hidden; }
}
}

pre.cropThumbnailDebug { background-color: #f0f0f0; overflow-x: scroll; padding:5px; font-size: .8em; position: relative;
.copyDebug { position: absolute; top:0; right:0; padding: 5px; background: #fff; cursor: pointer; border:1px solid #444; }
}


.CropImageSize { line-height: 1.4;
header,
.dimensions,
.ratio { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

header { font-size:1em; font-weight: bold; }
.dimensions { font-size:0.8em; }
.ratio { font-size:0.8em; }
.lowResWarning,
.notYetCropped { color: #fff; position: absolute; bottom: 12px; left: 12px; background: #ea6c00; width: 30px; height: 30px; line-height: 28px; font-size: 23px; font-weight: 600; z-index: 1; border: 2px solid #fff; box-shadow: 0 0 10px rgba(0,0,0,0.3);
.notYetCropped { color: #fff; position: absolute; bottom: 12px; left: 12px; background: #ea6c00; width: 30px; height: 30px; line-height: 28px; font-size: 23px; font-weight: 600; z-index: 1; border: 2px solid #fff; box-shadow: 0 0 10px rgba(0,0,0,0.3);
span { text-shadow: 1px 1px 1px rgba(0,0,0,0.3); }
}
.notYetCropped { background: #ea2f00; left:auto; right: 12px;
.notYetCropped { background: #ea2f00; left:auto; right: 12px;
span { line-height: 30px; }
}

Expand All @@ -101,14 +105,14 @@ body.cpt_ModalIsOpen { overflow: hidden; }
.cptImagesAreSelected li:focus .cptImageBgContainer { filter:grayscale(0%); }


.loadingcontainer { position: relative;
.loadingcontainer { position: relative;
.loadingMsg { opacity: 0; position: absolute; width: 100%; height: 100%; top:0; left:0; background: #fff; transition: opacity .4s linear; }
.cptLoadingSpinner { position: absolute; top:50%; left:50%; margin-left: -15px; margin-top: -15px; }
&.loading .loadingMsg { opacity: 1; }
&.loading .cptImageBgContainer { background: none !important; }
.fade-enter-active,
.fade-enter-active,
.fade-leave-active { transition: opacity .5s }
.fade-enter,
.fade-enter,
.fade-leave-to { opacity: 0; }
}

Expand Down Expand Up @@ -155,7 +159,7 @@ body.cpt_ModalIsOpen { overflow: hidden; }
animation-duration: 0.75s;
animation-iteration-count: infinite;
animation-name: cptRotateForever;
animation-timing-function: linear;
animation-timing-function: linear;
}
.cptLoadingSpinner.small { vertical-align: middle; height: 20px; width: 20px; margin:0 1em; }
@keyframes cptRotateForever {
Expand Down
2 changes: 1 addition & 1 deletion app/main.css

Large diffs are not rendered by default.

46 changes: 25 additions & 21 deletions app/main.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions crop-thumbnails.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Plugin URI: https://wordpress.org/extend/plugins/crop-thumbnails/
* Author: Volkmar Kantor
* Author URI: https://www.totalmedial.de
* Version: 1.9.2
* Version: 1.9.3
* Description: The easy way to adjust your cropped image sizes.
*
*
Expand All @@ -27,7 +27,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

define('CROP_THUMBNAILS_VERSION','1.9.2');
define('CROP_THUMBNAILS_VERSION','1.9.3');

include_once __DIR__.'/functions/enqueuejsmodule.php';
include_once __DIR__.'/functions/helper.php';
Expand Down
2 changes: 1 addition & 1 deletion functions/enqueuejsmodule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
return str_replace("<script ", "<script type='module' ", $tag);
}
}, 10, 3);
}
}
52 changes: 27 additions & 25 deletions functions/rest.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,12 @@ public static function rest_pluginTest() {

$report = [];
$doDeleteAttachement = false;
$doDeleteTempFile = false;
$attachmentId = -1;
$testComplete = false;

$sourceFile = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'test_image.jpg';
$tempFile = $GLOBALS['CROP_THUMBNAILS_HELPER']->getUploadDir().DIRECTORY_SEPARATOR.'testfile.jpg';
try {
$report[] = '<strong class="info">INFO</strong> Crop-Thumbnails '.CROP_THUMBNAILS_VERSION;
$report[] = '<strong class="info">INFO</strong> PHP '.phpversion();
$report[] = '<strong class="info">INFO</strong> PHP memory limit '.ini_get('memory_limit');
$report[] = '<strong class="info">INFO</strong> Server '.(!empty($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : $_ENV['SERVER_SOFTWARE']);
$report[] = '<strong class="info">INFO</strong> '._wp_image_editor_choose(['mime_type' => 'image/jpeg']).' <small>(choosed Wordpress imageeditor class for jpg)</small>';

//check if tmp-folder can be generated
if(is_dir($GLOBALS['CROP_THUMBNAILS_HELPER']->getUploadDir())) {
$report[] = '<strong class="success">SUCCESS</strong> Temporary directory exists';
Expand All @@ -219,11 +213,10 @@ public static function rest_pluginTest() {
}

//creating the testfile in temporary directory
if(!@copy($sourceFile,$tempFile)) {
throw new \Exception('<strong class="fails">FAIL</strong> Copy testfile to temporary directory | is the tmp-directory writable with PHP?');
if(!@copy($sourceFile, $tempFile)) {
throw new \Exception('<strong class="fails">FAIL</strong> Copy testfile to temporary directory | is the tmp-directory writable with PHP? ['.$sourceFile.' --> '.$tempFile.']');
} else {
$report[] = '<strong class="success">SUCCESS</strong> Copy testfile to temporary directory';
$doDeleteTempFile = true;
}


Expand All @@ -236,7 +229,7 @@ public static function rest_pluginTest() {
'size' => 102610
];
$attachmentId = media_handle_upload( 'cpt_quicktest', 0, [], ['test_form' => false, 'action'=>'test'] );
$doDeleteTempFile = false;//is be deleted automatically

if ( is_wp_error( $attachmentId ) ) {
throw new \Exception('<strong class="fails">FAIL</strong> Adding testfile to media-library ('.$attachmentId->get_error_message().') | is the upload-directory writable with PHP?');
} else {
Expand All @@ -246,8 +239,9 @@ public static function rest_pluginTest() {


//try to crop with the same function as the plugin does
$src = wp_get_original_image_path($attachmentId);
$cropResult = wp_crop_image( // * @return string|WP_Error|false New filepath on success, WP_Error or false on failure.
$attachmentId, // * @param string|int $src The source file or Attachment ID.
$src, // * @param string|int $src The source file or Attachment ID.
130, // * @param int $src_x The start x position to crop from.
275, // * @param int $src_y The start y position to crop from.
945, // * @param int $src_w The width to crop.
Expand All @@ -261,7 +255,6 @@ public static function rest_pluginTest() {
throw new \Exception('<strong class="fails">FAIL</strong> Cropping the file ('.$cropResult->get_error_message().')');
} else {
$report[] = '<strong class="success">SUCCESS</strong> Cropping the file';
$doDeleteTempFile = true;
$doDeleteAttachement = true;
}

Expand Down Expand Up @@ -298,25 +291,34 @@ public static function rest_pluginTest() {
}


//deleting testfile form temporary directory
if($doDeleteTempFile) {
if(!@unlink($tempFile)) {
$report[] = '<strong class="fails">FAIL</strong> Remove testfile from temporary directory';
} else {
$report[] = '<strong class="success">SUCCESS</strong> Remove testfile from temporary directory';
}
}

$report[] = '<strong class="info">INFO</strong> Tests complete';
self::appendSystemInfo($report);
return $report;
$testComplete = true;
} catch (\Throwable $th) {
$report[] = $th->getMessage();
}

//deleting testfile form temporary directory
if(file_exists($tempFile)) {
if(!@unlink($tempFile)) {
$report[] = '<strong class="fails">FAIL</strong> Remove testfile from temporary directory';
} else {
$report[] = '<strong class="success">SUCCESS</strong> Remove testfile from temporary directory';
}
}

if($testComplete) $report[] = '<strong class="info">INFO</strong> Tests complete';

self::appendSystemInfo($report);
return $report;
}

private static function appendSystemInfo(&$report) {
$report[] = '<strong class="info">INFO</strong> ----- System -----';
$report[] = '<strong class="info">INFO</strong> Crop-Thumbnails '.CROP_THUMBNAILS_VERSION;
$report[] = '<strong class="info">INFO</strong> PHP '.phpversion();
$report[] = '<strong class="info">INFO</strong> PHP memory limit '.ini_get('memory_limit');
$report[] = '<strong class="info">INFO</strong> Server '.(!empty($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : $_ENV['SERVER_SOFTWARE']);
$report[] = '<strong class="info">INFO</strong> '._wp_image_editor_choose(['mime_type' => 'image/jpeg']).' <small>(choosed Wordpress imageeditor class for jpg)</small>';

// get all plugins
$activePlugins = get_option('active_plugins');

Expand Down
7 changes: 4 additions & 3 deletions functions/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ public static function saveThumbnail($request) {
self::addDebug("delete old image:".$oldFile_toDelete);
@unlink($currentFilePathInfo['dirname'].DIRECTORY_SEPARATOR.$oldFile_toDelete);
}
if(!@copy($resultWpCropImage, $currentFilePath)) {
if(!@rename($resultWpCropImage, $currentFilePath)) {
$_processing_error[$activeImageSize->name][] = __("Can't copy temporary file to media library.", 'crop-thumbnails');
$_error = true;
}
if(!@unlink($resultWpCropImage)) {
if(file_exists($resultWpCropImage) && !@unlink($resultWpCropImage)) {
$_processing_error[$activeImageSize->name][] = __("Can't delete temporary file.", 'crop-thumbnails');
$_error = true;
}
Expand All @@ -138,7 +138,8 @@ public static function saveThumbnail($request) {
//otherwise new sizes will not be updated
$imageMetadata = apply_filters('crop_thumbnails_before_update_metadata', $imageMetadata, $input->sourceImageId);
wp_update_attachment_metadata( $input->sourceImageId, $imageMetadata);
self::addDebug('metadata updated: '.print_r($imageMetadata,true));
self::addDebug('metadata updated:');
self::addDebug($imageMetadata);

//generate result;
if(!empty($changedImageName)) {
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: post-thumbnails, images, media library
Requires at least: 5.0
Tested up to: 6.6.2
Requires PHP: 7.4.0
Stable tag: 1.9.2
Stable tag: 1.9.3
License: GPL v3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -124,6 +124,10 @@ If you fork and planning to publish the forked plugin, please contact me.
5. Quicktest on settings-page, to check if your system is correct setup.

== Changelog ==
= 1.9.3 =
* use rename instead of copy-unlink to move the files from the temporary directory
* improve logging

= 1.9.2 =
* hardend the crop solution by calculating the crop region in the frontend
* lower the minimal wordpress version to 5.0 (add a fallback for wp_enqueue_script_module)
Expand Down

0 comments on commit 68dcf83

Please sign in to comment.