diff --git a/README.txt b/README.txt index 4642b4f..ac148e4 100644 --- a/README.txt +++ b/README.txt @@ -1,13 +1,13 @@ === PDF Compressor & Watermark - iLovePDF === Plugin Name: Image Compressor & Optimizer - iLovePDF -Version: 2.1.6 +Version: 2.1.7 Author: iLovePDF Author URI: https://www.ilovepdf.com/ Contributors: iLovePDF Tags: compress, watermark, optimize, performance, pdf optimizer Requires at least: 5.3 Tested up to: 6.7 -Stable tag: 2.1.6 +Stable tag: 2.1.7 Requires PHP: 7.4 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -81,6 +81,15 @@ We will send you an email before limit is reached. When limit is reached, no mor == Changelog == += 2.1.7 = +Fixed +* In the file preview in grid mode, the restore button now works correctly. +* When auto-compressing or auto-watermarking a file that was being uploaded, an error message was incorrectly displayed. + +Improved +* The regeneration of subimages has been improved. +* The error message for authentication in the watermark function has been improved. + = 2.1.6 = Improved * Update Libraries. diff --git a/admin/functions-compress.php b/admin/functions-compress.php index 3445b78..205a0fb 100644 --- a/admin/functions-compress.php +++ b/admin/functions-compress.php @@ -185,6 +185,7 @@ function ilove_pdf_compress_pdf( $id_file, $auto = false, $bulk = false ) { * * @since 1.0.0 * @param int $attachment_id File ID. + * @throws \Exception Returns an error in case the compression process fails. */ function ilove_pdf_handle_file_upload_compress( $attachment_id ) { if ( get_post_mime_type( $attachment_id ) === 'application/pdf' ) { @@ -193,45 +194,47 @@ function ilove_pdf_handle_file_upload_compress( $attachment_id ) { if ( isset( $options['ilove_pdf_compress_autocompress_new'] ) && ! ilove_pdf_is_file_compressed( $attachment_id ) && ! isset( $options_watermark['ilove_pdf_watermark_auto'] ) ) { - $html = ilove_pdf_compress_pdf( $attachment_id, true ); - - if ( ! ilove_pdf_is_file_watermarked( $attachment_id ) && get_user_option( 'media_library_mode', get_current_user_id() ) === 'list' && ! wp_doing_ajax() ) { - - echo ''; - echo '' . esc_html( get_the_title( $attachment_id ) ) . 'ID: '; - - ?> - wp_strip_all_tags( $html ) ); - wp_send_json_error( $return ); - } else { - $attachment = wp_prepare_attachment_for_js( $attachment_id ); - $attachment['message'] = 'PDF Compressed!'; - wp_send_json_success( $attachment ); + try { + $html = ilove_pdf_compress_pdf( $attachment_id, true ); + + if ( ! ilove_pdf_is_file_watermarked( $attachment_id ) && get_user_option( 'media_library_mode', get_current_user_id() ) === 'list' && ! wp_doing_ajax() ) { + + echo ''; + echo '' . esc_html( get_the_title( $attachment_id ) ) . 'ID: '; + + ?> + $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()), true)); // phpcs:ignore + } } } } diff --git a/admin/functions-processed-files.php b/admin/functions-processed-files.php index 90dba19..a76ec0c 100644 --- a/admin/functions-processed-files.php +++ b/admin/functions-processed-files.php @@ -74,10 +74,11 @@ function ilove_pdf_upload_compress_file( $filename, $attachment_id ) { * Upload Watermark File. * * @since 1.0.0 - * @param string $filename File Name. - * @param int $attachment_id File ID. + * @param string $filename File Name. + * @param int $attachment_id File ID. + * @param boolean $generate_manual_attachment_thubnails Allows you to generate the images for the file again. */ -function ilove_pdf_upload_watermark_file( $filename, $attachment_id ) { +function ilove_pdf_upload_watermark_file( $filename, $attachment_id, $generate_manual_attachment_thubnails = true ) { $wp_upload_dir = wp_upload_dir(); if ( ! ilove_pdf_is_file_compressed( $attachment_id ) ) { $original_file_size = filesize( get_attached_file( $attachment_id ) ); @@ -96,7 +97,9 @@ function ilove_pdf_upload_watermark_file( $filename, $attachment_id ) { copy( $wp_upload_dir['basedir'] . '/pdf/watermark/' . basename( get_attached_file( $attachment_id ) ), get_attached_file( $attachment_id ) ); // Regenerate attachment metadata - ilove_pdf_regenerate_attachment_data( $attachment_id ); + if ( $generate_manual_attachment_thubnails ) { + ilove_pdf_regenerate_attachment_data( $attachment_id ); + } if ( get_option( 'ilovepdf_watermarked_files' ) || get_option( 'ilovepdf_watermarked_files' ) === '0' ) { $n_watermarked_files = intval( get_option( 'ilovepdf_watermarked_files' ) ) + 1; @@ -206,6 +209,7 @@ function ilove_pdf_handle_delete_file( $attachment_id ) { * * @since 1.0.0 * @param int $attachment_id File ID. + * @throws \Exception Returns an error in case the compressing or wartermarking process fails. */ function ilove_pdf_handle_file_upload_compress_watermark( $attachment_id ) { if ( get_post_mime_type( $attachment_id ) === 'application/pdf' ) { @@ -214,66 +218,70 @@ function ilove_pdf_handle_file_upload_compress_watermark( $attachment_id ) { Ilove_Pdf::update_option( 'ilovepdf_initial_pdf_files_size', get_option( 'ilovepdf_initial_pdf_files_size' ) + filesize( get_attached_file( $attachment_id ) ) ); if ( isset( $options_compress['ilove_pdf_compress_autocompress_new'] ) && isset( $options_watermark['ilove_pdf_watermark_auto'] ) ) { - $html_compress = ilove_pdf_compress_pdf( $attachment_id, true ); - $html_watermark = ilove_pdf_watermark_pdf( $attachment_id, true ); - - if ( get_user_option( 'media_library_mode', get_current_user_id() ) === 'list' && ! wp_doing_ajax() ) { - - echo ''; - echo '' . esc_html( get_the_title( $attachment_id ) ) . 'ID: '; - - ?> - wp_strip_all_tags( $html_compress ) ); - } - if ( '1' !== $html_watermark ) { - $return = array( 'message' => wp_strip_all_tags( $html_watermark ) ); + try { + $html_compress = ilove_pdf_compress_pdf( $attachment_id, true ); + $html_watermark = ilove_pdf_watermark_pdf( $attachment_id, true, false, false ); + + if ( get_user_option( 'media_library_mode', get_current_user_id() ) === 'list' && ! wp_doing_ajax() ) { + + echo ''; + echo '' . esc_html( get_the_title( $attachment_id ) ) . 'ID: '; + + ?> + $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()), true)); // phpcs:ignore + } } } } diff --git a/admin/functions-watermark.php b/admin/functions-watermark.php index dfa9317..3e7eac2 100644 --- a/admin/functions-watermark.php +++ b/admin/functions-watermark.php @@ -18,8 +18,9 @@ * @param int|null $id_file File ID. * @param boolean $auto Auto compress. * @param boolean $bulk Bulk. + * @param boolean $generate_manual_attachment_thubnails Allows you to generate the images for the file again. */ -function ilove_pdf_watermark_pdf( $id_file, $auto = false, $bulk = false ) { +function ilove_pdf_watermark_pdf( $id_file, $auto = false, $bulk = false, $generate_manual_attachment_thubnails = true ) { $general_options_watermark = get_option( 'ilove_pdf_display_settings_watermark' ); $options = get_option( 'ilove_pdf_display_settings_format_watermark' ); $html = true; @@ -134,10 +135,10 @@ function ilove_pdf_watermark_pdf( $id_file, $auto = false, $bulk = false ) { } if ( null !== $id_file ) { - ilove_pdf_upload_watermark_file( get_attached_file( $id_file ), $id_file ); + ilove_pdf_upload_watermark_file( get_attached_file( $id_file ), $id_file, $generate_manual_attachment_thubnails ); } else { foreach ( $files_pdf as $file_pdf ) { - ilove_pdf_upload_watermark_file( get_attached_file( $file_pdf->ID ), $file_pdf->ID ); + ilove_pdf_upload_watermark_file( get_attached_file( $file_pdf->ID ), $file_pdf->ID, $generate_manual_attachment_thubnails ); } } @@ -168,13 +169,14 @@ function ilove_pdf_watermark_pdf( $id_file, $auto = false, $bulk = false ) { $html = 'error_auth'; - if ( $bulk ) { + if ( $bulk || $auto ) { $html = 'error_auth'; } - if ( $auto ) { - $html = 'error_auth'; + if ( 'Unauthorized (Key may not be empty)' === $e->getMessage() ) { + $html = 'Check your credentials in the plugin settings page. If you recently deleted a project in your iloveapi account, try switching to another project to correctly save your API Keys.'; } + // Uploading files errors } catch ( \Ilovepdf\Exceptions\UploadException $e ) { @@ -238,6 +240,7 @@ function ilove_pdf_watermark_pdf( $id_file, $auto = false, $bulk = false ) { * * @since 1.0.0 * @param int $attachment_id File ID. + * @throws \Exception Returns an error in case the wartermarking process fails. */ function ilove_pdf_handle_file_upload_watermark( $attachment_id ) { if ( get_post_mime_type( $attachment_id ) === 'application/pdf' ) { @@ -246,46 +249,48 @@ function ilove_pdf_handle_file_upload_watermark( $attachment_id ) { if ( isset( $options['ilove_pdf_watermark_auto'] ) && ! ilove_pdf_is_file_watermarked( $attachment_id ) && ! isset( $options_compress['ilove_pdf_compress_autocompress_new'] ) ) { - $html = ilove_pdf_watermark_pdf( $attachment_id, true ); - - if ( ! ilove_pdf_is_file_compressed( $attachment_id ) && get_user_option( 'media_library_mode', get_current_user_id() ) === 'list' && ! wp_doing_ajax() ) { - - echo ''; - echo '' . esc_html( get_the_title( $attachment_id ) ) . 'ID: '; - - ?> - wp_strip_all_tags( $html ) ); - wp_send_json_error( $return ); - } else { - $attachment = wp_prepare_attachment_for_js( $attachment_id ); - $attachment['message'] = 'PDF Stamped!'; - wp_send_json_success( $attachment ); + try { + $html = ilove_pdf_watermark_pdf( $attachment_id, true, false, false ); + + if ( ! ilove_pdf_is_file_compressed( $attachment_id ) && get_user_option( 'media_library_mode', get_current_user_id() ) === 'list' && ! wp_doing_ajax() ) { + + echo ''; + echo '' . esc_html( get_the_title( $attachment_id ) ) . 'ID: '; + + ?> + $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()), true)); // phpcs:ignore } } } diff --git a/assets/js/main.min.js b/assets/js/main.min.js index 5fc8f40..7fe9e23 100644 --- a/assets/js/main.min.js +++ b/assets/js/main.min.js @@ -6,4 +6,4 @@ - `;n(".btn-restore").on("click",function(e){var i=n(this);e.preventDefault(),n(this).parent().append(c);let t=document.getElementById("ilovepdf-restore-dialog");var e=document.getElementById("ilovepdf-dialog-aceptted"),s=document.getElementById("ilovepdf-dialog-close");t.showModal(),e.addEventListener("click",e=>{e.preventDefault(),t.close(),n(this).hide(),n(this).prev().hide(),n(this).nextAll(".loading").show(),n(this).parent().prevAll(".row-compress-tool").hide(),n(this).parent().prevAll(".row-watermark-tool").hide(),n.post(n(this).prop("href")+"&ajax=1",function(e){var t;i.nextAll(".loading").hide(),(""===e?i.nextAll(".success"):((t=document.createElement("div")).innerHTML=e,i.nextAll(".error").html(t.innerText))).show()})}),s.addEventListener("click",e=>{e.preventDefault(),t.close()})}),n(".ilovepdf--meta-box-container .link-restore, .compat-field-iLovePDF-tools .link-restore").on("click",function(e){let t=n(this),i=t[0].href,s=(e.preventDefault(),n(".ilovepdf--meta-box-container").append(c),document.getElementById("ilovepdf-restore-dialog"));var e=document.getElementById("ilovepdf-dialog-aceptted"),r=document.getElementById("ilovepdf-dialog-close");s.showModal(),e.addEventListener("click",e=>{e.preventDefault(),s.close(),location.href=i}),r.addEventListener("click",e=>{e.preventDefault(),s.close()})})})(jQuery); \ No newline at end of file + `;n(".btn-restore").on("click",function(e){var i=n(this);e.preventDefault(),n(this).parent().append(c);let t=document.getElementById("ilovepdf-restore-dialog");var e=document.getElementById("ilovepdf-dialog-aceptted"),s=document.getElementById("ilovepdf-dialog-close");t.showModal(),e.addEventListener("click",e=>{e.preventDefault(),t.close(),n(this).hide(),n(this).prev().hide(),n(this).nextAll(".loading").show(),n(this).parent().prevAll(".row-compress-tool").hide(),n(this).parent().prevAll(".row-watermark-tool").hide(),n.post(n(this).prop("href")+"&ajax=1",function(e){var t;i.nextAll(".loading").hide(),(""===e?i.nextAll(".success"):((t=document.createElement("div")).innerHTML=e,i.nextAll(".error").html(t.innerText))).show()})}),s.addEventListener("click",e=>{e.preventDefault(),t.close()})}),n(".ilovepdf--meta-box-container .link-restore, .compat-field-iLovePDF-tools .link-restore").on("click",function(e){let t=n(this),i=t[0].href,s=(e.preventDefault(),n(".ilovepdf--meta-box-container, .compat-field-iLovePDF-tools .field").append(c),document.getElementById("ilovepdf-restore-dialog"));var e=document.getElementById("ilovepdf-dialog-aceptted"),r=document.getElementById("ilovepdf-dialog-close");s.showModal(),e.addEventListener("click",e=>{e.preventDefault(),s.close(),location.href=i}),r.addEventListener("click",e=>{e.preventDefault(),s.close()})})})(jQuery); \ No newline at end of file diff --git a/dev/js/main.js b/dev/js/main.js index c775479..1679631 100644 --- a/dev/js/main.js +++ b/dev/js/main.js @@ -499,7 +499,7 @@ e.preventDefault(); - $('.ilovepdf--meta-box-container').append(dialogComponent) + $('.ilovepdf--meta-box-container, .compat-field-iLovePDF-tools .field').append(dialogComponent) const dialogElem = document.getElementById("ilovepdf-restore-dialog") const btnConfirmDialog = document.getElementById("ilovepdf-dialog-aceptted") diff --git a/ilove-pdf.php b/ilove-pdf.php index 57d93d0..dfacdbd 100644 --- a/ilove-pdf.php +++ b/ilove-pdf.php @@ -10,7 +10,7 @@ * Plugin Name: iLovePDF * Plugin URI: https://iloveapi.com/ * Description: Compress your PDF files and Stamp Images or text into PDF files. This is the Official iLovePDF plugin for WordPress. You can optimize all your PDF and stamp them automatically as you do in ilovepdf.com. - * Version: 2.1.6 + * Version: 2.1.7 * Requires at least: 5.3 * Requires PHP: 7.4 * Author: ILovePDF diff --git a/includes/Ilove_Pdf.php b/includes/Ilove_Pdf.php index 46cba9e..3d4d37d 100644 --- a/includes/Ilove_Pdf.php +++ b/includes/Ilove_Pdf.php @@ -74,7 +74,7 @@ class Ilove_Pdf { public function __construct() { $this->plugin_name = 'ilove-pdf'; - $this->version = 'wp.2.1.6'; + $this->version = 'wp.2.1.7'; $this->load_dependencies(); $this->set_locale();