PluginProbe
Elementor Website Builder – more than just a page builder / 3.0.6
Elementor Website Builder – more than just a page builder v3.0.6
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 +62 -68 4.2.23.0.6 View file →
@@ -1,116 +1,102 @@
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-editor-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 Weather 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 + $existing_mimes[ $this->get_file_type() ] = $this->get_mime_type();
66 57
67 - return Plugin::$instance->uploads_manager->support_unfiltered_elementor_file_uploads( $existing_mimes );
58 + return $existing_mimes;
68 59 }
69 60
70 61 /**
71 - * Handle_upload_prefilter
72 - *
73 - * @deprecated 3.5.0 Use `Elementor\Plugin::$instance->uploads_manager->handle_elementor_wp_media_upload()` instead.
74 - *
62 + * handle_upload_prefilter
75 63 * @param $file
76 64 *
77 65 * @return mixed
78 66 */
79 67 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()' );
68 + if ( ! $this->is_file_should_handled( $file ) ) {
69 + return $file;
70 + }
81 71
82 - return Plugin::$instance->uploads_manager->handle_elementor_wp_media_upload( $file );
72 + $ext = pathinfo( $file['name'], PATHINFO_EXTENSION );
73 + $file_type = $this->get_file_type();
74 + $display_type = strtoupper( $file_type );
75 +
76 + if ( $file_type !== $ext ) {
77 + $file['error'] = sprintf( __( 'The uploaded %1$s file is not supported. Please upload a valid %2$s file', 'elementor' ), $ext, $display_type );
78 + return $file;
79 + }
80 +
81 + if ( ! self::is_enabled() ) {
82 + $file['error'] = sprintf( __( '%1$s file is not allowed for security reasons', 'elementor' ), $display_type );
83 + return $file;
84 + }
85 +
86 + return $file;
83 87 }
84 88
85 - /**
86 - * Is_file_should_handled
87 - *
88 - * @deprecated 3.5.0
89 - *
90 - * @param $file
91 - *
92 - * @return bool
93 - */
94 89 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 - $ext = pathinfo( $file['name'], PATHINFO_EXTENSION );
98 -
99 - return $this->is_elementor_media_upload() && $this->get_file_type() === $ext;
90 + return $this->is_elementor_media_upload() && $this->get_mime_type() === $file['type'];
100 91 }
101 92
102 93 /**
103 - * File_sanitizer_can_run
104 - *
105 - * @deprecated 3.5.0 Use `Elementor\Core\Files\File_Types\Svg::file_sanitizer_can_run()` instead.
106 - *
94 + * file_sanitizer_can_run
107 95 * @return bool
108 96 */
109 97 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();
98 + return class_exists( 'DOMDocument' ) && class_exists( 'SimpleXMLElement' );
113 99 }
114 100
115 101 /**
116 102 * Check filetype and ext
@@ -119,10 +105,8 @@
119 105 * with inconsistent reporting behaviour.
120 106 * ref: https://core.trac.wordpress.org/ticket/39550
121 107 * ref: https://core.trac.wordpress.org/ticket/40175
122 108 *
123 - * @deprecated 3.5.0 Use `Elementor\Plugin::$instance->uploads_manager->check_filetype_and_ext()` instead.
124 - *
125 109 * @param $data
126 110 * @param $file
127 111 * @param $filename
128 112 * @param $mimes
@@ -129,9 +113,19 @@
129 113 *
130 114 * @return mixed
131 115 */
132 116 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()' );
117 + if ( ! empty( $data['ext'] ) && ! empty( $data['type'] ) ) {
118 + return $data;
119 + }
134 120
135 - Plugin::$instance->uploads_manager->check_filetype_and_ext( $data, $file, $filename, $mimes );
121 + $wp_file_type = wp_check_filetype( $filename, $mimes );
122 + $file_type = strtolower( $this->get_file_type() );
123 +
124 + if ( $file_type === $wp_file_type['ext'] ) {
125 + $data['ext'] = $file_type;
126 + $data['type'] = $this->get_mime_type();
127 + }
128 +
129 + return $data;
136 130 }
137 131 }