PluginProbe
Elementor Website Builder – more than just a page builder / 3.4.0-dev9
Elementor Website Builder – more than just a page builder v3.4.0-dev9
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
← All changes | core/files/assets/files-upload-handler.php +63 -65 4.1.33.4.0-dev9 View file →
@@ -1,100 +1,95 @@
1 1 <?php
2 2
3 3 namespace Elementor\Core\Files\Assets;
4 4
5 -use Elementor\Core\Files\File_Types\Svg;
6 -use Elementor\Core\Files\Uploads_Manager;
7 -use Elementor\Plugin;
8 -
9 5 if ( ! defined( 'ABSPATH' ) ) {
10 6 exit; // Exit if accessed directly.
11 7 }
12 8
13 -/**
14 - * Files Upload Handler
15 - *
16 - * @deprecated 3.5.0 Use `Elementor\Core\Files\Uploads_Manager` class instead.
17 - */
18 9 abstract class Files_Upload_Handler {
10 + const OPTION_KEY = 'elementor_unfiltered_files_upload';
19 11
20 - /**
21 - * @deprecated 3.5.0
22 - */
23 - const OPTION_KEY = 'elementor_unfiltered_files_upload';
12 + public function __construct() {
13 + add_filter( 'upload_mimes', [ $this, 'support_unfiltered_files_upload' ] );
14 + add_filter( 'wp_handle_upload_prefilter', [ $this, 'handle_upload_prefilter' ] );
15 + add_filter( 'wp_check_filetype_and_ext', [ $this, 'check_filetype_and_ext' ], 10, 4 );
16 + }
24 17
25 - /**
26 - * @deprecated 3.5.0
27 - */
28 18 abstract public function get_mime_type();
29 19
30 - /**
31 - * @deprecated 3.5.0
32 - */
33 20 abstract public function get_file_type();
34 21
35 22 /**
36 - * Is Elementor Media Upload
37 - *
38 - * @deprecated 3.5.0 Use `Elementor\Plugin::$instance->uploads_manager->are_unfiltered_uploads_enabled()` instead.
39 - *
23 + * is_elementor_media_upload
40 24 * @return bool
41 25 */
42 26 private function is_elementor_media_upload() {
43 - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0', 'Elementor\Plugin::$instance->uploads_manager->are_unfiltered_uploads_enabled()' );
44 -
45 - return Plugin::$instance->uploads_manager->is_elementor_media_upload();
27 + return isset( $_POST['uploadTypeCaller'] ) && 'elementor-wp-media-upload' === $_POST['uploadTypeCaller']; // phpcs:ignore
46 28 }
47 29
48 30 /**
49 - * Is Enabled
50 - *
51 - * @deprecated 3.5.0 Use `Elementor\Plugin::$instance->uploads_manager->are_unfiltered_uploads_enabled()` instead.
52 - *
53 31 * @return bool
54 32 */
55 33 final public static function is_enabled() {
56 - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0', 'Elementor\Plugin::$instance->uploads_manager->are_unfiltered_uploads_enabled()' );
34 + $enabled = ! ! get_option( self::OPTION_KEY ) && self::file_sanitizer_can_run();
57 35
58 - return Plugin::$instance->uploads_manager->are_unfiltered_uploads_enabled();
36 + /**
37 + * @deprecated 3.0.0 Use `elementor/document/urls/edit` filter instead.
38 + */
39 + $enabled = apply_filters( 'elementor/files/svg/enabled', $enabled );
40 +
41 + /**
42 + * Allow Unfiltered Files Upload.
43 + *
44 + * Determines whether to enable unfiltered file uploads.
45 + *
46 + * @since 3.0.0
47 + *
48 + * @param bool $enabled Whether upload is enabled or not.
49 + */
50 + $enabled = apply_filters( 'elementor/files/allow_unfiltered_upload', $enabled );
51 +
52 + return $enabled;
59 53 }
60 54
61 - /**
62 - * @deprecated 3.5.0 Use `Elementor\Plugin::$instance->uploads_manager->are_unfiltered_uploads_enabled()` instead.
63 - */
64 55 final public function support_unfiltered_files_upload( $existing_mimes ) {
65 - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0', 'Elementor\Plugin::$instance->uploads_manager->support_unfiltered_file_uploads()' );
56 + if ( $this->is_elementor_media_upload() && $this->is_enabled() ) {
57 + $existing_mimes[ $this->get_file_type() ] = $this->get_mime_type();
58 + }
66 59
67 - return Plugin::$instance->uploads_manager->support_unfiltered_elementor_file_uploads( $existing_mimes );
60 + return $existing_mimes;
68 61 }
69 62
70 63 /**
71 - * Handle_upload_prefilter
72 - *
73 - * @deprecated 3.5.0 Use `Elementor\Plugin::$instance->uploads_manager->handle_elementor_wp_media_upload()` instead.
74 - *
64 + * handle_upload_prefilter
75 65 * @param $file
76 66 *
77 67 * @return mixed
78 68 */
79 69 public function handle_upload_prefilter( $file ) {
80 - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0', 'Elementor\Plugin::$instance->uploads_manager->handle_elementor_wp_media_upload()' );
70 + if ( ! $this->is_file_should_handled( $file ) ) {
71 + return $file;
72 + }
81 73
82 - return Plugin::$instance->uploads_manager->handle_elementor_wp_media_upload( $file );
74 + $ext = pathinfo( $file['name'], PATHINFO_EXTENSION );
75 + $file_type = $this->get_file_type();
76 + $display_type = strtoupper( $file_type );
77 +
78 + if ( $file_type !== $ext ) {
79 + $file['error'] = sprintf( esc_html__( 'The uploaded %1$s file is not supported. Please upload a valid %2$s file', 'elementor' ), $ext, $display_type );
80 + return $file;
81 + }
82 +
83 + if ( ! self::is_enabled() ) {
84 + $file['error'] = sprintf( esc_html__( '%1$s file is not allowed for security reasons', 'elementor' ), $display_type );
85 + return $file;
86 + }
87 +
88 + return $file;
83 89 }
84 90
85 - /**
86 - * Is_file_should_handled
87 - *
88 - * @deprecated 3.5.0
89 - *
90 - * @param $file
91 - *
92 - * @return bool
93 - */
94 91 protected function is_file_should_handled( $file ) {
95 - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0' );
96 -
97 92 $ext = pathinfo( $file['name'], PATHINFO_EXTENSION );
98 93
99 94 return $this->is_elementor_media_upload() && $this->get_file_type() === $ext;
100 95 }
@@ -99,18 +94,13 @@
99 94 return $this->is_elementor_media_upload() && $this->get_file_type() === $ext;
100 95 }
101 96
102 97 /**
103 - * File_sanitizer_can_run
104 - *
105 - * @deprecated 3.5.0 Use `Elementor\Core\Files\File_Types\Svg::file_sanitizer_can_run()` instead.
106 - *
98 + * file_sanitizer_can_run
107 99 * @return bool
108 100 */
109 101 public static function file_sanitizer_can_run() {
110 - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0', 'Elementor\Core\Files\File_Types\Svg::file_sanitizer_can_run()' );
111 -
112 - return Svg::file_sanitizer_can_run();
102 + return class_exists( 'DOMDocument' ) && class_exists( 'SimpleXMLElement' );
113 103 }
114 104
115 105 /**
116 106 * Check filetype and ext
@@ -119,10 +109,8 @@
119 109 * with inconsistent reporting behaviour.
120 110 * ref: https://core.trac.wordpress.org/ticket/39550
121 111 * ref: https://core.trac.wordpress.org/ticket/40175
122 112 *
123 - * @deprecated 3.5.0 Use `Elementor\Plugin::$instance->uploads_manager->check_filetype_and_ext()` instead.
124 - *
125 113 * @param $data
126 114 * @param $file
127 115 * @param $filename
128 116 * @param $mimes
@@ -129,9 +117,19 @@
129 117 *
130 118 * @return mixed
131 119 */
132 120 public function check_filetype_and_ext( $data, $file, $filename, $mimes ) {
133 - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0', 'Elementor\Plugin::$instance->uploads_manager->check_filetype_and_ext()' );
121 + if ( ! empty( $data['ext'] ) && ! empty( $data['type'] ) ) {
122 + return $data;
123 + }
134 124
135 - Plugin::$instance->uploads_manager->check_filetype_and_ext( $data, $file, $filename, $mimes );
125 + $wp_file_type = wp_check_filetype( $filename, $mimes );
126 + $file_type = strtolower( $this->get_file_type() );
127 +
128 + if ( $file_type === $wp_file_type['ext'] ) {
129 + $data['ext'] = $file_type;
130 + $data['type'] = $this->get_mime_type();
131 + }
132 +
133 + return $data;
136 134 }
137 135 }