Skip to content

Commit

Permalink
Some improvements on David remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmigf committed Oct 17, 2023
1 parent 3220957 commit 473d53f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 40 deletions.
2 changes: 1 addition & 1 deletion assets/js/order-script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
jQuery( function( $ ) {

$( document.body ).on( 'click', '#doaction, #doaction2', function( e ) {
$( '.tablenav' ).on( 'click', '#doaction, #doaction2', function( e ) {
let actionselected = $( this ).attr( "id" ).substr( 2 );
let action = $( 'select[name="' + actionselected + '"]' ).val();

Expand Down
20 changes: 3 additions & 17 deletions includes/class-wcpdf-font-synchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct() {
* @return void
*/
public function sync( $destination, $merge_with_local = true ) {
$destination = trailingslashit( $this->normalize_path( $destination ) );
$destination = trailingslashit( wp_normalize_path( $destination ) );

$plugin_fonts = $this->get_plugin_fonts();
$dompdf_fonts = $this->get_dompdf_fonts();
Expand Down Expand Up @@ -91,7 +91,7 @@ public function sync( $destination, $merge_with_local = true ) {
* @return void
*/
public function delete_font_files( $filenames ) {
$plugin_folder = $this->normalize_path( WPO_WCPDF()->plugin_path() );
$plugin_folder = wp_normalize_path( WPO_WCPDF()->plugin_path() );
$extensions = array( '.ttf', '.ufm', '.ufm.php', '.afm', '.afm.php' );
foreach ( $filenames as $filename ) {
// never delete files in our own plugin folder
Expand Down Expand Up @@ -211,20 +211,6 @@ public function get_plugin_fonts() {
);
}

/**
* Normalize a filesystem path.
*
* @param string $path Path to normalize.
* @return string Normalized path.
*/
public function normalize_path( $path ) {
if ( ! empty( $path ) ) {
return function_exists( 'wp_normalize_path' ) ? wp_normalize_path( $path ) : str_replace( '\\', '/', $path );
} else {
return $path;
}
}

/**
* Apply path normalization to a font list
*
Expand All @@ -237,7 +223,7 @@ public function normalize_font_paths( $fonts ) {
continue;
}
foreach ( $filenames as $variant => $filename ) {
$fonts[$font_name][$variant] = $this->normalize_path( $filename );
$fonts[$font_name][$variant] = wp_normalize_path( $filename );
}
}
return $fonts;
Expand Down
32 changes: 12 additions & 20 deletions includes/class-wcpdf-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ public function get_output_mode() {
public function get_template_path() {
// return default path if no template selected
if ( empty( $this->general_settings['template_path'] ) ) {
return $this->normalize_path( WPO_WCPDF()->plugin_path() . '/templates/Simple' );
return wp_normalize_path( WPO_WCPDF()->plugin_path() . '/templates/Simple' );
}

$installed_templates = $this->get_installed_templates();
Expand All @@ -569,18 +569,18 @@ public function get_template_path() {
return array_search( $selected_template, $installed_templates );
} else {
// unknown template or full template path (filter override)
$template_path = $this->normalize_path( $selected_template );
$template_path = wp_normalize_path( $selected_template );

// add base path, checking if it's not already there
// alternative setups like Bedrock have WP_CONTENT_DIR & ABSPATH separated
if ( defined( 'WP_CONTENT_DIR' ) && ! empty( WP_CONTENT_DIR ) && false !== strpos( WP_CONTENT_DIR, ABSPATH ) ) {
$base_path = $this->normalize_path( ABSPATH );
$base_path = wp_normalize_path( ABSPATH );
} else {
$base_path = $this->normalize_path( WP_CONTENT_DIR );
$base_path = wp_normalize_path( WP_CONTENT_DIR );
}

if ( ! empty( $template_path ) && false === strpos( $template_path, $base_path ) ) {
$template_path = $this->normalize_path( $base_path . $template_path );
$template_path = wp_normalize_path( $base_path . $template_path );
}
}

Expand Down Expand Up @@ -616,7 +616,7 @@ public function get_installed_templates( $force_reload = false ) {
$dirs = (array) glob( $template_path . '*' , GLOB_ONLYDIR );

foreach ( $dirs as $dir ) {
$clean_dir = $this->normalize_path( $dir );
$clean_dir = wp_normalize_path( $dir );
$template_name = basename( $clean_dir );
// let child theme override parent theme
$group = ( $template_source == 'child-theme' ) ? 'theme' : $template_source;
Expand All @@ -626,7 +626,7 @@ public function get_installed_templates( $force_reload = false ) {

if ( empty( $installed_templates ) ) {
// fallback to Simple template for servers with glob() disabled
$simple_template_path = $this->normalize_path( $template_paths['default'] . 'Simple' );
$simple_template_path = wp_normalize_path( $template_paths['default'] . 'Simple' );
$installed_templates[$simple_template_path] = 'default/Simple';
}

Expand Down Expand Up @@ -709,19 +709,11 @@ public function maybe_delete_flush_rewrite_rules_transient() {

public function get_relative_template_path( $absolute_path ) {
if ( defined( 'WP_CONTENT_DIR' ) && ! empty( WP_CONTENT_DIR ) && false !== strpos( WP_CONTENT_DIR, ABSPATH ) ) {
$base_path = $this->normalize_path( ABSPATH );
$base_path = wp_normalize_path( ABSPATH );
} else {
$base_path = $this->normalize_path( WP_CONTENT_DIR );
}
return str_replace( $base_path, '', $this->normalize_path( $absolute_path ) );
}

public function normalize_path( $path ) {
if ( ! empty( $path ) ) {
return function_exists( 'wp_normalize_path' ) ? wp_normalize_path( $path ) : str_replace( '\\', '/', $path );
} else {
return $path;
$base_path = wp_normalize_path( WP_CONTENT_DIR );
}
return str_replace( $base_path, '', wp_normalize_path( $absolute_path ) );
}

public function maybe_migrate_template_paths( $settings_section = null ) {
Expand All @@ -731,12 +723,12 @@ public function maybe_migrate_template_paths( $settings_section = null ) {
}

$installed_templates = $this->get_installed_templates( true );
$selected_template = $this->normalize_path( $this->general_settings['template_path'] );
$selected_template = wp_normalize_path( $this->general_settings['template_path'] );
$template_match = '';
if ( ! in_array( $selected_template, $installed_templates ) && substr_count( $selected_template, '/' ) > 1 ) {
// search for path match
foreach ( $installed_templates as $path => $template_id ) {
$path = $this->normalize_path( $path );
$path = wp_normalize_path( $path );
// check if the last part of the path matches
if ( substr( $path, -strlen( $selected_template ) ) === $selected_template ) {
$template_match = $template_id;
Expand Down
4 changes: 2 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Contributors: pomegranate, alexmigf, yordansoares, kluver, dpeyou, dwpriv, jhosagid
Donate link: https://wpovernight.com/downloads/woocommerce-pdf-invoices-packing-slips-bundle/
Tags: woocommerce, pdf, ubl, invoices, packing slips, print, delivery notes, invoice, packing slip, export, email, bulk, automatic
Requires at least: 3.5
Requires at least: 4.4
Tested up to: 6.3
Requires PHP: 7.2
Stable tag: 3.7.0
Expand Down Expand Up @@ -43,7 +43,7 @@ In addition to a number of default settings (including a custom header/logo) and
= Minimum Requirements =

* WooCommerce 3.0 or later
* WordPress 3.5 or later
* WordPress 4.4 or later

= Automatic installation =
Automatic installation is the easiest option as WordPress handles the file transfers itself and you don't even need to leave your web browser. To do an automatic install of PDF Invoices & Packing Slips for WooCommerce, log in to your WordPress admin panel, navigate to the Plugins menu and click Add New.
Expand Down

0 comments on commit 473d53f

Please sign in to comment.