Skip to content

Commit

Permalink
Merge pull request #29 from ilovepdf/develop
Browse files Browse the repository at this point in the history
v2.1.0
  • Loading branch information
diegocrombie authored Apr 29, 2024
2 parents f2a03af + 99715ba commit b04beab
Show file tree
Hide file tree
Showing 32 changed files with 915 additions and 479 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
=== PDF Compressor & Watermark - iLovePDF ===
Plugin Name: Image Compressor & Optimizer - iLovePDF
Version: 2.0.5
Version: 2.1.0
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.4.3
Stable tag: 2.0.5
Tested up to: 6.5.2
Stable tag: 2.1.0
Requires PHP: 7.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down
22 changes: 19 additions & 3 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
=== PDF Compressor & Watermark - iLovePDF ===
Plugin Name: Image Compressor & Optimizer - iLovePDF
Version: 2.0.5
Version: 2.1.0
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.4.3
Stable tag: 2.0.5
Tested up to: 6.5.2
Stable tag: 2.1.0
Requires PHP: 7.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -82,6 +82,22 @@ We will send you an email before limit is reached. When limit is reached, no mor

== Changelog ==

== 2.1.0 ==
Added
* New Backup option added in General Settings. Now the backup works for all tools.
* Regenerate thumbnails when wattermark is applied.
* Added link to configuration page from plugins page.
* Added link to tools from page settings.

Improved
* Update Libraries.
* Update Library Ilovepdf-php to 1.2.4
* Removed unused file.
* On the individual page of a file, ilovepdf buttons are now displayed whenever the file is a PDF.

Fixed
* In some cases, when a user logged in, they could get a PHP error or warning.

== 2.0.5 ==
Improved
* Update Libraries.
Expand Down
24 changes: 22 additions & 2 deletions admin/Ilove_Pdf_Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,27 @@ public function enqueue_scripts() {
// Add the color picker css file
wp_enqueue_style( 'wp-color-picker' );

// Include our custom jQuery file with WordPress Color Picker dependency
wp_enqueue_script( 'ilove-pdf-admin', plugins_url( '/assets/js/main.min.js', __DIR__ ), array( 'wp-color-picker' ), '1.0.0', true );
global $pagenow;

if ( ( 'upload.php' === $pagenow || 'options-general.php' === $pagenow || 'media-new.php' === $pagenow || 'post.php' === $pagenow ) && get_current_screen()->post_type !== 'product' ) {
wp_enqueue_script( 'ilove-pdf-admin', plugins_url( '/assets/js/main.min.js', __DIR__ ), array( 'wp-color-picker', 'sweetalert-ilovepdf' ), '1.0.0', true );
wp_enqueue_script( 'sweetalert-ilovepdf', 'https://cdn.jsdelivr.net/npm/sweetalert2@11', array(), '11.10', true );
}
}

/**
* Add Link to page settings from Plugins List Page.
*
* @since 2.1.0
*
* @param array $actions An array of plugin action links.
*/
public function add_action_links( $actions ) {
$custom_links = array(
'<a href="' . admin_url( 'options-general.php?page=ilove-pdf-content-setting' ) . '">Settings</a>',
);
$actions = array_merge( $actions, $custom_links );

return $actions;
}
}
20 changes: 17 additions & 3 deletions admin/functions-processed-files.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ function ilove_pdf_upload_compress_file( $filename, $attachment_id ) {
update_post_meta( $attachment_id, '_wp_attached_original_size', $original_file_size );
}

$options_general_settings = get_option( 'ilove_pdf_display_general_settings' );

if ( (int) $options_general_settings['ilove_pdf_general_backup'] && ! get_post_meta( $attachment_id, '_wp_attached_file_backup', true ) ) {

copy( get_attached_file( $attachment_id ), $wp_upload_dir['basedir'] . '/pdf/backup/' . basename( get_attached_file( $attachment_id ) ) );
update_post_meta( $attachment_id, '_wp_attached_file_backup', get_post_meta( $attachment_id, '_wp_attached_file', true ) );

}

copy( $wp_upload_dir['basedir'] . '/pdf/compress/' . basename( get_attached_file( $attachment_id ) ), get_attached_file( $attachment_id ) );

if ( get_option( 'ilovepdf_compressed_files' ) || get_option( 'ilovepdf_compressed_files' ) === '0' ) {
Expand Down Expand Up @@ -73,9 +82,9 @@ function ilove_pdf_upload_watermark_file( $filename, $attachment_id ) {
update_post_meta( $attachment_id, '_wp_attached_original_size', $original_file_size );
}

$options = get_option( 'ilove_pdf_display_settings_watermark' );
$options_general_settings = get_option( 'ilove_pdf_display_general_settings' );

if ( $options['ilove_pdf_watermark_backup'] ) {
if ( (int) $options_general_settings['ilove_pdf_general_backup'] && ! get_post_meta( $attachment_id, '_wp_attached_file_backup', true ) ) {

copy( get_attached_file( $attachment_id ), $wp_upload_dir['basedir'] . '/pdf/backup/' . basename( get_attached_file( $attachment_id ) ) );
update_post_meta( $attachment_id, '_wp_attached_file_backup', get_post_meta( $attachment_id, '_wp_attached_file', true ) );
Expand All @@ -84,6 +93,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 ( get_option( 'ilovepdf_watermarked_files' ) || get_option( 'ilovepdf_watermarked_files' ) === '0' ) {
$n_watermarked_files = intval( get_option( 'ilovepdf_watermarked_files' ) ) + 1;
update_option( 'ilovepdf_watermarked_files', $n_watermarked_files );
Expand Down Expand Up @@ -124,11 +136,13 @@ function ilove_pdf_restore_pdf( $attachment_id ) {
if ( get_option( 'ilovepdf_watermarked_files' ) <= '0' ) {
delete_option( 'ilovepdf_watermarked_files' ); }
}
wp_delete_file( $wp_upload_dir['basedir'] . '/pdf/watermark/' . basename( get_attached_file( $attachment_id ) ) );
}

copy( $wp_upload_dir['basedir'] . '/pdf/backup/' . basename( get_attached_file( $attachment_id ) ), get_attached_file( $attachment_id ) );

// Regenerate attachment metadata
ilove_pdf_regenerate_attachment_data( $attachment_id );

delete_post_meta( $attachment_id, '_wp_attached_file_backup' );
delete_post_meta( $attachment_id, '_compressed_file' );
delete_post_meta( $attachment_id, '_watermarked_file' );
Expand Down
2 changes: 1 addition & 1 deletion admin/functions-watermark.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ function ilove_pdf_watermark_list_action() {
* @since 1.0.0
*/
function ilove_pdf_restore_action() {
if ( isset( $_GET['action'] ) && 'ilovepdf_restore' === $_GET['action'] && isset( $_GET['nonce_ilove_pdf_restore_watermark'] ) && wp_verify_nonce( sanitize_key( $_GET['nonce_ilove_pdf_restore_watermark'] ), 'admin-post' ) && isset( $_GET['id'] ) && intval( $_GET['id'] ) ) {
if ( isset( $_GET['action'] ) && 'ilovepdf_restore' === $_GET['action'] && isset( $_GET['nonce_ilove_pdf_restore'] ) && wp_verify_nonce( sanitize_key( $_GET['nonce_ilove_pdf_restore'] ), 'admin-post' ) && isset( $_GET['id'] ) && intval( $_GET['id'] ) ) {
ilove_pdf_restore_pdf( (int) sanitize_text_field( wp_unslash( $_GET['id'] ) ) );
}

Expand Down
69 changes: 69 additions & 0 deletions admin/general-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ function ilove_pdf_login_action() {
}

wp_safe_redirect( wp_get_referer() . '&response_code=' . $response['response']['code'] . '&nonce_ilove_pdf_response=' . wp_create_nonce() );
exit();
}

wp_safe_redirect( wp_get_referer() . '&response_code=' . $response . '&nonce_ilove_pdf_response=' . wp_create_nonce() );
exit();
}
add_action( 'admin_post_ilovepdf_login', 'ilove_pdf_login_action' );

Expand Down Expand Up @@ -159,3 +161,70 @@ function ilove_pdf_popup_buymore_action() {
</svg><div><a href="https://developer.ilovepdf.com/pricing" target="_blank" class="button button-primary">' . esc_html( __( 'Accept', 'ilove-pdf' ) ) . '</a> <a href="#" onClick="tb_remove();" class="button button-primary">' . esc_html( __( 'Cancel', 'ilove-pdf' ) ) . '</a></div></div></div>';
}
add_action( 'admin_footer', 'ilove_pdf_popup_buymore_action' );

/**
* Initialize Options for the general admin area.
*
* @since 2.1.0
*/
function ilove_pdf_initialize_general_options() {

if ( false === get_option( 'ilove_pdf_display_general_settings' ) ) {
add_option( 'ilove_pdf_display_general_settings' );
}

add_settings_section(
'general_settings_section',
'',
'ilove_pdf_general_options_callback',
'ilove_pdf_display_general_settings'
);

add_settings_field(
'ilove_pdf_general_backup',
__( 'Create backup of original files?', 'ilove-pdf' ),
'ilove_pdf_general_backup_callback',
'ilove_pdf_display_general_settings',
'general_settings_section',
array(
'No',
'Yes',
)
);

register_setting(
'ilove_pdf_display_general_settings',
'ilove_pdf_display_general_settings'
);
}
add_action( 'admin_init', 'ilove_pdf_initialize_general_options' );

/**
* Options General Callback.
*
* @since 2.1.0
*/
function ilove_pdf_general_options_callback() {
echo '<h3>' . esc_html( __( 'Configure your Tools settings.', 'ilove-pdf' ) ) . '</h3>';
}

/**
* Backup Original File Callback.
*
* @since 2.1.0
* @param array $args Arguments options.
*/
function ilove_pdf_general_backup_callback( $args ) {

$options = get_option( 'ilove_pdf_display_general_settings' );
$html = sprintf(
'<input type="radio" id="ilove_pdf_general_backup" name="ilove_pdf_display_general_settings[ilove_pdf_general_backup]" value="0" %s><label for="ilove_pdf_general_backup">%s</label>&nbsp;
<input type="radio" id="ilove_pdf_general_backup" name="ilove_pdf_display_general_settings[ilove_pdf_general_backup]" value="1" %s><label for="ilove_pdf_general_backup">%s</label><div><p><small>The backup files can be found on your server:</small></p><p><strong>wp-content/uploads/pdf/backup</strong></p></div>',
isset( $options['ilove_pdf_general_backup'] ) ? checked( 0, $options['ilove_pdf_general_backup'], false ) : '',
$args[0],
isset( $options['ilove_pdf_general_backup'] ) ? checked( 1, $options['ilove_pdf_general_backup'], false ) : 'checked="checked"',
$args[1]
);

echo wp_kses( $html, ilove_pdf_expanded_alowed_tags() );
}
Loading

0 comments on commit b04beab

Please sign in to comment.