Envato Elements – Template Kits (Beta) - Version 2.0.11

Version Description

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

Release Info

Developer dtbaker
Plugin Icon 128x128 Envato Elements – Template Kits (Beta)
Version 2.0.11
Comparing to
See all releases

Code changes from version 2.0.10 to 2.0.11

envato-elements.php CHANGED
@@ -4,11 +4,11 @@
4
  * Description: Access beautifully designed Template Kits + Photos from Envato Elements.
5
  * Author: Envato
6
  * Author URI: https://elements.envato.com/extensions/wordpress/?utm_source=extensions&utm_medium=referral&utm_campaign=elements_extensions_wpplugins
7
- * Version: 2.0.10
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: envato-elements
14
  *
@@ -30,7 +30,7 @@ if ( ! defined( 'ABSPATH' ) ) {
30
  }
31
 
32
  define( 'ENVATO_ELEMENTS_SLUG', 'envato-elements' );
33
- define( 'ENVATO_ELEMENTS_VER', '2.0.10' );
34
  define( 'ENVATO_ELEMENTS_FILE', __FILE__ );
35
  define( 'ENVATO_ELEMENTS_DIR', plugin_dir_path( ENVATO_ELEMENTS_FILE ) );
36
  define( 'ENVATO_ELEMENTS_URI', plugins_url( '/', ENVATO_ELEMENTS_FILE ) );
4
  * Description: Access beautifully designed Template Kits + Photos from Envato Elements.
5
  * Author: Envato
6
  * Author URI: https://elements.envato.com/extensions/wordpress/?utm_source=extensions&utm_medium=referral&utm_campaign=elements_extensions_wpplugins
7
+ * Version: 2.0.11
8
  * License: GPLv3 or later
9
  * License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
+ * Elementor tested up to: 3.7.1
11
+ * Elementor Pro tested up to: 3.7.3
12
  *
13
  * Text Domain: envato-elements
14
  *
30
  }
31
 
32
  define( 'ENVATO_ELEMENTS_SLUG', 'envato-elements' );
33
+ define( 'ENVATO_ELEMENTS_VER', '2.0.11' );
34
  define( 'ENVATO_ELEMENTS_FILE', __FILE__ );
35
  define( 'ENVATO_ELEMENTS_DIR', plugin_dir_path( ENVATO_ELEMENTS_FILE ) );
36
  define( 'ENVATO_ELEMENTS_URI', plugins_url( '/', ENVATO_ELEMENTS_FILE ) );
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: envato
3
  Tags: elementor, elements, templates, template kit
4
  Requires at least: 4.6
5
- Tested up to: 5.8
6
  Requires PHP: 5.6
7
- Stable tag: 2.0.10
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -79,6 +79,9 @@ If you have any questions or feedback for the team, please send an email to exte
79
 
80
  == Changelog ==
81
 
 
 
 
82
  = 2.0.10 - 2021-09-17 =
83
  * Feature: Better compatibility with Elementor Kits
84
 
2
  Contributors: envato
3
  Tags: elementor, elements, templates, template kit
4
  Requires at least: 4.6
5
+ Tested up to: 6.0
6
  Requires PHP: 5.6
7
+ Stable tag: 2.0.11
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
 
79
 
80
  == Changelog ==
81
 
82
+ = 2.0.11 - 2021-10-21 =
83
+ * Fix: Swap to using ZipArchive for Template Kit extraction
84
+
85
  = 2.0.10 - 2021-09-17 =
86
  * Feature: Better compatibility with Elementor Kits
87
 
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' );