Template Kit – Import - Version 1.0.14

Version Description

  • 2021-10-21 =
  • Fix: Swap to using ZipArchive for Template Kit extraction
Download this release

Release Info

Developer Brad Davis
Plugin Icon 128x128 Template Kit – Import
Version 1.0.14
Comparing to
See all releases

Code changes from version 1.0.13 to 1.0.14

readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: envato
3
  Tags: elementor, template, templates
4
  Requires at least: 5.3
5
- Tested up to: 5.8
6
  Requires PHP: 5.6
7
- Stable tag: 1.0.13
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -36,6 +36,9 @@ Create your own "Template Kit" for others with the "[Template Kit Export](https:
36
 
37
  == Changelog ==
38
 
 
 
 
39
  = 1.0.13 - 2021-09-17 =
40
  * Feature: Better compatibility with Elementor Kits
41
 
2
  Contributors: envato
3
  Tags: elementor, template, templates
4
  Requires at least: 5.3
5
+ Tested up to: 5.9
6
  Requires PHP: 5.6
7
+ Stable tag: 1.0.14
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
 
36
 
37
  == Changelog ==
38
 
39
+ = 1.0.14 - 2021-10-21 =
40
+ * Fix: Swap to using ZipArchive for Template Kit extraction
41
+
42
  = 1.0.13 - 2021-09-17 =
43
  * Feature: Better compatibility with Elementor Kits
44
 
template-kit-import.php CHANGED
@@ -4,11 +4,11 @@
4
  * Description: Import Template Kits to WordPress
5
  * Author: Envato
6
  * Author URI: https://envato.com
7
- * Version: 1.0.13
8
  * License: GPLv3 or later
9
  * License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
- * Elementor tested up to: 3.5.0
11
- * Elementor Pro tested up to: 3.5.0
12
  *
13
  * Text Domain: template-kit-import
14
  *
@@ -30,7 +30,7 @@ if ( ! defined( 'ABSPATH' ) ) {
30
  }
31
 
32
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_SLUG', 'template-kit-import' );
33
- define( 'ENVATO_TEMPLATE_KIT_IMPORT_VER', '1.0.13' );
34
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_FILE', __FILE__ );
35
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_DIR', plugin_dir_path( ENVATO_TEMPLATE_KIT_IMPORT_FILE ) );
36
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_URI', plugins_url( '/', ENVATO_TEMPLATE_KIT_IMPORT_FILE ) );
4
  * Description: Import Template Kits to WordPress
5
  * Author: Envato
6
  * Author URI: https://envato.com
7
+ * Version: 1.0.14
8
  * License: GPLv3 or later
9
  * License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
+ * Elementor tested up to: 3.5.5
11
+ * Elementor Pro tested up to: 3.6.2
12
  *
13
  * Text Domain: template-kit-import
14
  *
30
  }
31
 
32
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_SLUG', 'template-kit-import' );
33
+ define( 'ENVATO_TEMPLATE_KIT_IMPORT_VER', '1.0.14' );
34
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_FILE', __FILE__ );
35
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_DIR', plugin_dir_path( ENVATO_TEMPLATE_KIT_IMPORT_FILE ) );
36
  define( 'ENVATO_TEMPLATE_KIT_IMPORT_URI', plugins_url( '/', ENVATO_TEMPLATE_KIT_IMPORT_FILE ) );
vendor/template-kit-import/inc/class-importer.php CHANGED
@@ -42,8 +42,11 @@ class Importer extends Base {
42
  }
43
 
44
  /**
45
- * Called when we want to unpack a ZIP file into a folder.
46
- * Assumes the folder exists.
 
 
 
47
  *
48
  * @param string $temporary_zip_file
49
  * @param string $destination_folder
@@ -51,31 +54,39 @@ class Importer extends Base {
51
  * @return string|\WP_Error
52
  */
53
  private function unpack_template_kit_zip_to_folder( $temporary_zip_file, $destination_folder ) {
54
- global $wp_filesystem;
 
 
55
 
56
- require_once ABSPATH . '/wp-admin/includes/file.php';
57
- \WP_Filesystem();
58
 
59
- if ( ! $wp_filesystem instanceof \WP_Filesystem_Base ) {
60
- return new \WP_Error( 'zip_error', 'Failed to initialize WP Filesystem' );
61
- }
62
 
63
- $unzip_result = unzip_file( $temporary_zip_file, $destination_folder );
64
- if ( $unzip_result !== true ) {
65
- if ( is_wp_error( $unzip_result ) ) {
66
- return $unzip_result;
67
- }
68
 
69
- return new \WP_Error( 'zip_error', 'Failed to unzip zip file' );
 
 
 
 
 
 
 
70
  }
71
 
 
 
 
 
72
  $extracted_zip_files = scandir( $destination_folder );
73
  if ( $extracted_zip_files && is_array( $extracted_zip_files ) ) {
74
  $file_names = array_diff( $extracted_zip_files, array( '.', '..' ) );
75
  } else {
76
  $file_names = array();
77
  }
78
- if ( ! $file_names || ! in_array( 'manifest.json', $file_names, true ) || preg_grep( '/\.php/i', $file_names ) ) {
79
  $this->delete_template_kit_folder( $destination_folder );
80
 
81
  return new \WP_Error( 'zip_error', 'Please upload a valid Template Kit zip file' );
42
  }
43
 
44
  /**
45
+ * Extract
46
+ *
47
+ * Performs the extraction of the zip files to a temporary directory.
48
+ * Returns an error if for some reason the ZipArchive utility isn't available.
49
+ * Otherwise, Returns a strnig containing the temporary extraction directory
50
  *
51
  * @param string $temporary_zip_file
52
  * @param string $destination_folder
54
  * @return string|\WP_Error
55
  */
56
  private function unpack_template_kit_zip_to_folder( $temporary_zip_file, $destination_folder ) {
57
+ if ( ! class_exists( '\ZipArchive' ) ) {
58
+ return new \WP_Error( 'zip_error', 'PHP Zip extension not loaded' );
59
+ }
60
 
61
+ $allowed_file_types = [ 'json', 'jpg', 'png', 'css', 'html' ];
 
62
 
63
+ $zip = new \ZipArchive();
 
 
64
 
65
+ $zip->open( $temporary_zip_file );
66
+
67
+ $allowed_files = [];
 
 
68
 
69
+ // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
70
+ for ( $i = 0; $i < $zip->numFiles; $i ++ ) {
71
+ $filename = $zip->getNameIndex( $i );
72
+ $extension = pathinfo( $filename, PATHINFO_EXTENSION );
73
+
74
+ if ( in_array( $extension, $allowed_file_types, true ) ) {
75
+ $allowed_files[] = $filename;
76
+ }
77
  }
78
 
79
+ $zip->extractTo( $destination_folder, $allowed_files );
80
+
81
+ $zip->close();
82
+
83
  $extracted_zip_files = scandir( $destination_folder );
84
  if ( $extracted_zip_files && is_array( $extracted_zip_files ) ) {
85
  $file_names = array_diff( $extracted_zip_files, array( '.', '..' ) );
86
  } else {
87
  $file_names = array();
88
  }
89
+ if ( ! $file_names || ! in_array( 'manifest.json', $file_names, true ) ) {
90
  $this->delete_template_kit_folder( $destination_folder );
91
 
92
  return new \WP_Error( 'zip_error', 'Please upload a valid Template Kit zip file' );