Skip to content

Commit

Permalink
Merge branch 'main' into 903-upgrade-links-not-displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmigf committed Dec 13, 2024
2 parents 3169949 + 7b55afd commit c8ec38f
Show file tree
Hide file tree
Showing 18 changed files with 219 additions and 70 deletions.
6 changes: 6 additions & 0 deletions assets/css/settings-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@ body.woocommerce_page_wpo_wcpdf_options_page {
padding-top: 0.7em;
}

#wpo-wcpdf-preview-wrapper .sidebar .form-table > tbody > tr > td p.description > span.wpo-warning {
width: 100%;
box-sizing: border-box;
word-wrap: break-word;
}

#wpo-wcpdf-preview-wrapper .sidebar .form-table > tbody > tr > td > input[type="text"],
#wpo-wcpdf-preview-wrapper .sidebar .form-table > tbody > tr > td > input[type="url"],
#wpo-wcpdf-preview-wrapper .sidebar .form-table > tbody > tr > td > select,
Expand Down
2 changes: 1 addition & 1 deletion assets/css/settings-styles.min.css

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion assets/js/admin-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ jQuery( function( $ ) {
}
} ).trigger( 'change' );

// disable encrypted pdf option for non UBL 2.1 formats
$( "[name='wpo_wcpdf_documents_settings_invoice_ubl[ubl_format]']" ).on( 'change', function( event ) {
let $encryptedPdfCheckbox = $( this ).closest( 'form' ).find( "[name='wpo_wcpdf_documents_settings_invoice_ubl[include_encrypted_pdf]']" );

if ( $( this ).val() !== 'ubl_2_1' ) {
$encryptedPdfCheckbox.prop( 'checked', false ).prop( 'disabled', true );
} else {
$encryptedPdfCheckbox.prop( 'disabled', false );
}
} ).trigger( 'change' );

// enable settings document switch
$( '.wcpdf_document_settings_sections > h2' ).on( 'click', function() {
$( this ).parent().find( 'ul' ).toggleClass( 'active' );
Expand Down Expand Up @@ -373,7 +384,14 @@ jQuery( function( $ ) {
} );

// Trigger the Preview
function triggerPreview( timeoutDuration ) {
function triggerPreview( timeoutDuration = 0 ) {
$previewStates = $( '#wpo-wcpdf-preview-wrapper' ).data( 'preview-states' );

// Check if preview is disabled and return
if ( 'undefined' === $previewStates || 1 === $previewStates ) {
return;
}

timeoutDuration = typeof timeoutDuration == 'number' ? timeoutDuration : 0;

loadPreviewData();
Expand Down Expand Up @@ -430,6 +448,7 @@ jQuery( function( $ ) {

// Load the Preview with AJAX
function ajaxLoadPreview() {
console.log( 'Loading preview...' );
let worker = wpo_wcpdf_admin.pdfjs_worker;
let canvasId = 'preview-canvas';
let data = {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin-script.min.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions includes/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function instance() {

public function __construct() {
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'backend_scripts_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'backend_scripts_styles' ), 11 ); // after WC
}

/**
Expand Down Expand Up @@ -134,9 +134,13 @@ public function backend_scripts_styles ( $hook ) {
wp_enqueue_style( 'wp-pointer' );
}

if ( ! wp_script_is( 'jquery-tiptip', 'enqueued' ) ) {
wp_enqueue_script( 'jquery-tiptip' );
}

wp_enqueue_script(
'wpo-wcpdf-admin',
WPO_WCPDF()->plugin_url() . '/assets/js/admin-script'.$suffix.'.js',
WPO_WCPDF()->plugin_url() . '/assets/js/admin-script' . $suffix . '.js',
array( 'jquery', 'wc-enhanced-select', 'jquery-blockui', 'jquery-tiptip', 'wp-pointer' ),
WPO_WCPDF_VERSION
);
Expand Down
25 changes: 20 additions & 5 deletions includes/Documents/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public function get_ubl_settings_fields( $option_name ) {
$settings_fields = array(
array(
'type' => 'section',
'id' => $this->type.'_ubl',
'id' => $this->type . '_ubl',
'title' => '',
'callback' => 'section',
),
Expand All @@ -588,18 +588,32 @@ public function get_ubl_settings_fields( $option_name ) {
'id' => 'enabled',
'title' => __( 'Enable', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'checkbox',
'section' => $this->type.'_ubl',
'section' => $this->type . '_ubl',
'args' => array(
'option_name' => $option_name,
'id' => 'enabled',
)
),
array(
'type' => 'setting',
'id' => 'ubl_format',
'title' => __( 'Format', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'select',
'section' => $this->type . '_ubl',
'args' => array(
'option_name' => $option_name,
'id' => 'ubl_format',
'options' => apply_filters( 'wpo_wcpdf_document_ubl_settings_formats', array(
'ubl_2_1' => __( 'UBL 2.1' , 'woocommerce-pdf-invoices-packing-slips' ),
), $this ),
)
),
array(
'type' => 'setting',
'id' => 'attach_to_email_ids',
'title' => __( 'Attach to:', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'multiple_checkboxes',
'section' => $this->type.'_ubl',
'section' => $this->type . '_ubl',
'args' => array(
'option_name' => $option_name,
'id' => 'attach_to_email_ids',
Expand All @@ -613,11 +627,11 @@ public function get_ubl_settings_fields( $option_name ) {
'id' => 'include_encrypted_pdf',
'title' => __( 'Include encrypted PDF:', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'checkbox',
'section' => $this->type.'_ubl',
'section' => $this->type . '_ubl',
'args' => array(
'option_name' => $option_name,
'id' => 'include_encrypted_pdf',
'description' => __( 'Include the PDF Invoice file encrypted in the UBL file.', 'woocommerce-pdf-invoices-packing-slips' ),
'description' => __( 'Embed the encrypted PDF invoice file within the UBL document. Note that this option may not be supported by all UBL formats.', 'woocommerce-pdf-invoices-packing-slips' ),
)
),
);
Expand Down Expand Up @@ -687,6 +701,7 @@ public function get_settings_categories( string $output_format ): array {
'title' => __( 'General', 'woocommerce-pdf-invoices-packing-slips' ),
'members' => array(
'enabled',
'ubl_format',
'attach_to_email_ids',
'include_encrypted_pdf',
),
Expand Down
23 changes: 22 additions & 1 deletion includes/Documents/OrderDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,17 @@ public function is_enabled( $output_format = 'pdf' ) {

return apply_filters( 'wpo_wcpdf_document_is_enabled', $is_enabled, $this->type, $output_format );
}

/**
* Get the UBL format
*
* @return string|false
*/
public function get_ubl_format() {
$ubl_format = $this->get_setting( 'ubl_format', false, 'ubl' );

return apply_filters( 'wpo_wcpdf_document_ubl_format', $ubl_format, $this );
}

public function get_hook_prefix() {
return 'wpo_wcpdf_' . $this->slug . '_get_';
Expand Down Expand Up @@ -1130,7 +1141,7 @@ public function header_logo(): void {
$attachment_src = wp_get_attachment_image_url( $attachment_id, 'full' );
$attachment_path = wp_normalize_path( realpath( get_attached_file( $attachment_id ) ) );
$src = apply_filters( 'wpo_wcpdf_use_path', true ) ? $attachment_path : $attachment_src;

if ( empty( $src ) ) {
wcpdf_log_error( 'Header logo file not found.', 'critical' );
return;
Expand Down Expand Up @@ -1229,6 +1240,16 @@ public function shop_address() {
echo $this->get_shop_address();
}

/**
* Return/Show shop/company phone number if provided.
*/
public function get_shop_phone_number() {
return $this->get_settings_text( 'shop_phone_number', '', false );
}
public function shop_phone_number() {
echo $this->get_shop_phone_number();
}

/**
* Return/Show shop/company footer imprint, copyright etc.
*/
Expand Down
96 changes: 79 additions & 17 deletions includes/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -1265,16 +1265,44 @@ public function set_phpmailer_validator( $mailArray ) {
*
* @param object $document
* @param string $trigger
*
* @return void
*/
public function log_document_creation_to_order_notes( $document, $trigger ) {
public function log_document_creation_to_order_notes( object $document, string $trigger ) {
if ( empty( $document ) || empty( $trigger ) || ! isset( WPO_WCPDF()->settings->debug_settings['log_to_order_notes'] ) ) {
return;
}

$triggers = $this->get_document_triggers();
if ( ! empty( $document ) && isset( WPO_WCPDF()->settings->debug_settings['log_to_order_notes'] ) && ! empty( $trigger ) && array_key_exists( $trigger, $triggers ) ) {
/* translators: 1. document title, 2. creation trigger */
$message = __( 'PDF %1$s created via %2$s.', 'woocommerce-pdf-invoices-packing-slips' );
$note = sprintf( $message, $document->get_title(), $triggers[$trigger] );
$this->log_to_order_notes( $note, $document );

if ( ! array_key_exists( $trigger, $triggers ) ) {
return;
}

$user_note = '';
$manual_triggers = $this->get_document_triggers( 'manual' );

// Add user information if the trigger is manual.
if ( array_key_exists( $trigger, $manual_triggers ) ) {
$user = wp_get_current_user();

if ( ! empty( $user->user_login ) ) {
$user_note = sprintf(
' (%s: %s)',
__( 'User', 'woocommerce-pdf-invoices-packing-slips' ),
esc_html( $user->user_login )
);
}
}

$note = sprintf(
/* translators: 1. document title, 2. creation trigger */
__( 'PDF %1$s created via %2$s.', 'woocommerce-pdf-invoices-packing-slips' ),
$document->get_title(),
$triggers[ $trigger ]
);

$this->log_to_order_notes( $note . $user_note, $document );
}

/**
Expand All @@ -1286,10 +1314,24 @@ public function log_document_creation_to_order_notes( $document, $trigger ) {
*/
public function log_document_deletion_to_order_notes( object $document ): void {
if ( ! empty( WPO_WCPDF()->settings->debug_settings['log_to_order_notes'] ) ) {
/* translators: document title */
$message = __( 'PDF %s deleted.', 'woocommerce-pdf-invoices-packing-slips' );
$note = sprintf( $message, $document->get_title() );
$this->log_to_order_notes( $note, $document );
$user_note = '';
$user = wp_get_current_user();

if ( ! empty( $user->user_login ) ) {
$user_note = sprintf(
' (%s: %s)',
__( 'User', 'woocommerce-pdf-invoices-packing-slips' ),
esc_html( $user->user_login )
);
}

$note = sprintf(
/* translators: document title */
__( 'PDF %s deleted.', 'woocommerce-pdf-invoices-packing-slips' ),
$document->get_title()
);

$this->log_to_order_notes( $note . $user_note, $document );
}
}

Expand Down Expand Up @@ -1405,16 +1447,36 @@ public function log_document_creation_trigger_to_order_meta( $document, $trigger
/**
* Get the document triggers
*
* @param string $trigger_type The trigger type: 'manual', 'automatic', or 'all'. Defaults to 'all'.
*
* @return array
*/
public function get_document_triggers() {
return apply_filters( 'wpo_wcpdf_document_triggers', [
'single' => __( 'single order action', 'woocommerce-pdf-invoices-packing-slips' ),
'bulk' => __( 'bulk order action', 'woocommerce-pdf-invoices-packing-slips' ),
'my_account' => __( 'my account', 'woocommerce-pdf-invoices-packing-slips' ),
public function get_document_triggers( string $trigger_type = 'all' ): array {
$manual_triggers = apply_filters( 'wpo_wcpdf_manual_document_triggers', array(
'single' => __( 'single order action', 'woocommerce-pdf-invoices-packing-slips' ),
'bulk' => __( 'bulk order action', 'woocommerce-pdf-invoices-packing-slips' ),
'my_account' => __( 'my account', 'woocommerce-pdf-invoices-packing-slips' ),
'document_data' => __( 'order document data (number and/or date set manually)', 'woocommerce-pdf-invoices-packing-slips' ),
) );

$automatic_triggers = apply_filters( 'wpo_wcpdf_automatic_document_triggers', array(
'email_attachment' => __( 'email attachment', 'woocommerce-pdf-invoices-packing-slips' ),
'document_data' => __( 'order document data (number and/or date set manually)', 'woocommerce-pdf-invoices-packing-slips' ),
] );
) );

switch ( $trigger_type ) {
case 'manual':
$triggers = $manual_triggers;
break;
case 'automatic':
$triggers = $automatic_triggers;
break;
case 'all':
default:
$triggers = array_merge( $manual_triggers, $automatic_triggers );
break;
}

return apply_filters( 'wpo_wcpdf_document_triggers', $triggers, $trigger_type );
}

/**
Expand Down
49 changes: 20 additions & 29 deletions includes/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ public function __construct() {
// settings capabilities
add_filter( 'option_page_capability_wpo_wcpdf_general_settings', array( $this, 'user_settings_capability' ) );

// admin notice for auto_increment_increment
// add_action( 'admin_notices', array( $this, 'check_auto_increment_increment') );

// AJAX set number store
add_action( 'wp_ajax_wpo_wcpdf_set_next_number', array( $this, 'set_number_store' ) );

Expand Down Expand Up @@ -157,17 +154,6 @@ public function user_can_manage_settings() {
return current_user_can( $this->user_settings_capability() );
}

function check_auto_increment_increment() {
global $wpdb;
$row = $wpdb->get_row( "SHOW VARIABLES LIKE 'auto_increment_increment'" );
if ( ! empty( $row ) && ! empty( $row->Value ) && $row->Value != 1 ) {
/* translators: database row value */
$error = wp_kses_post( sprintf( __( "<strong>Warning!</strong> Your database has an AUTO_INCREMENT step size of %d, your invoice numbers may not be sequential. Enable the 'Calculate document numbers (slow)' setting in the Advanced tab to use an alternate method." , 'woocommerce-pdf-invoices-packing-slips' ), intval( $row->Value ) ) );
printf( '<div class="error"><p>%s</p></div>', $error );
}
}


public function settings_page() {
// feedback on settings save
settings_errors();
Expand Down Expand Up @@ -506,22 +492,27 @@ public function add_settings_fields( $settings_fields, $page, $option_group, $op

}

public function get_common_document_settings() {
$common_settings = array(
'paper_size' => isset( $this->general_settings['paper_size'] ) ? $this->general_settings['paper_size'] : '',
'font_subsetting' => isset( $this->general_settings['font_subsetting'] ) || ( defined("DOMPDF_ENABLE_FONTSUBSETTING") && DOMPDF_ENABLE_FONTSUBSETTING === true ) ? true : false,
'header_logo' => isset( $this->general_settings['header_logo'] ) ? $this->general_settings['header_logo'] : '',
'header_logo_height' => isset( $this->general_settings['header_logo_height'] ) ? $this->general_settings['header_logo_height'] : '',
'vat_number' => isset( $this->general_settings['vat_number'] ) ? $this->general_settings['vat_number'] : '',
'coc_number' => isset( $this->general_settings['coc_number'] ) ? $this->general_settings['coc_number'] : '',
'shop_name' => isset( $this->general_settings['shop_name'] ) ? $this->general_settings['shop_name'] : '',
'shop_address' => isset( $this->general_settings['shop_address'] ) ? $this->general_settings['shop_address'] : '',
'footer' => isset( $this->general_settings['footer'] ) ? $this->general_settings['footer'] : '',
'extra_1' => isset( $this->general_settings['extra_1'] ) ? $this->general_settings['extra_1'] : '',
'extra_2' => isset( $this->general_settings['extra_2'] ) ? $this->general_settings['extra_2'] : '',
'extra_3' => isset( $this->general_settings['extra_3'] ) ? $this->general_settings['extra_3'] : '',
/**
* Get document general settings.
*
* @return array
*/
public function get_common_document_settings(): array {
return array(
'paper_size' => $this->general_settings['paper_size'] ?? '',
'font_subsetting' => isset( $this->general_settings['font_subsetting'] ) || ( defined( "DOMPDF_ENABLE_FONTSUBSETTING" ) && DOMPDF_ENABLE_FONTSUBSETTING === true ),
'header_logo' => $this->general_settings['header_logo'] ?? '',
'header_logo_height' => $this->general_settings['header_logo_height'] ?? '',
'vat_number' => $this->general_settings['vat_number'] ?? '',
'coc_number' => $this->general_settings['coc_number'] ?? '',
'shop_name' => $this->general_settings['shop_name'] ?? '',
'shop_phone_number' => $this->general_settings['shop_phone_number'] ?? '',
'shop_address' => $this->general_settings['shop_address'] ?? '',
'footer' => $this->general_settings['footer'] ?? '',
'extra_1' => $this->general_settings['extra_1'] ?? '',
'extra_2' => $this->general_settings['extra_2'] ?? '',
'extra_3' => $this->general_settings['extra_3'] ?? '',
);
return $common_settings;
}

public function get_document_settings( $document_type, $output_format = 'pdf' ) {
Expand Down
Loading

0 comments on commit c8ec38f

Please sign in to comment.