| 1 |
<?php |
| 2 |
namespace Elementor\Core\Files\Assets\Svg; |
| 3 |
|
| 4 |
use Elementor\Core\Files\Assets\Files_Upload_Handler; |
| 5 |
use Elementor\Core\Files\File_Types\Svg; |
| 6 |
use Elementor\Core\Files\Uploads_Manager; |
| 7 |
use Elementor\Plugin; |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly. |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* SVG Handler |
| 15 |
* |
| 16 |
* Deprecated, use Elementor\Core\Files\File_Types\Svg instead, accessed by calling: |
| 17 |
* `Plugin::$instance->uploads_manager->get_file_type_handlers( 'svg' );` |
| 18 |
* |
| 19 |
* @deprecated 3.5.0 |
| 20 |
*/ |
| 21 |
class Svg_Handler extends Files_Upload_Handler { |
| 22 |
/** |
| 23 |
* Inline svg attachment meta key |
| 24 |
*/ |
| 25 |
const META_KEY = '_elementor_inline_svg'; |
| 26 |
|
| 27 |
const SCRIPT_REGEX = '/(?:\w+script|data):/xi'; |
| 28 |
|
| 29 |
/** |
| 30 |
* Attachment ID. |
| 31 |
* |
| 32 |
* Holds the current attachment ID. |
| 33 |
* |
| 34 |
* @var int |
| 35 |
*/ |
| 36 |
private $attachment_id; |
| 37 |
|
| 38 |
public static function get_name() { |
| 39 |
return 'svg-handler'; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* get_meta |
| 44 |
* |
| 45 |
* @deprecated 3.5.0 |
| 46 |
* |
| 47 |
* @return mixed |
| 48 |
*/ |
| 49 |
protected function get_meta() { |
| 50 |
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0' ); |
| 51 |
|
| 52 |
return get_post_meta( $this->attachment_id, self::META_KEY, true ); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* update_meta |
| 57 |
* |
| 58 |
* @deprecated 3.5.0 |
| 59 |
* |
| 60 |
* @param $meta |
| 61 |
*/ |
| 62 |
protected function update_meta( $meta ) { |
| 63 |
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0' ); |
| 64 |
|
| 65 |
update_post_meta( $this->attachment_id, self::META_KEY, $meta ); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* delete_meta |
| 70 |
* |
| 71 |
* @deprecated 3.5.0 |
| 72 |
*/ |
| 73 |
protected function delete_meta() { |
| 74 |
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0' ); |
| 75 |
|
| 76 |
delete_post_meta( $this->attachment_id, self::META_KEY ); |
| 77 |
} |
| 78 |
|
| 79 |
public function get_mime_type() { |
| 80 |
return 'image/svg+xml'; |
| 81 |
} |
| 82 |
|
| 83 |
public function get_file_type() { |
| 84 |
return 'svg'; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* delete_meta_cache |
| 89 |
* |
| 90 |
* @deprecated 3.5.0 |
| 91 |
*/ |
| 92 |
public function delete_meta_cache() { |
| 93 |
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0', 'Plugin::$instance->uploads_manager->get_file_type_handlers( \'svg\' )->delete_meta_cache()' ); |
| 94 |
|
| 95 |
/** @var Svg $svg_handler */ |
| 96 |
$svg_handler = Plugin::$instance->uploads_manager->get_file_type_handlers( 'svg' ); |
| 97 |
|
| 98 |
$svg_handler->delete_meta_cache(); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* get_inline_svg |
| 103 |
* |
| 104 |
* @deprecated 3.5.0 |
| 105 |
* |
| 106 |
* @param $attachment_id |
| 107 |
* |
| 108 |
* @return bool|mixed|string |
| 109 |
*/ |
| 110 |
public static function get_inline_svg( $attachment_id ) { |
| 111 |
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0', 'Elementor\Core\Files\File_Types\Svg::get_inline_svg()' ); |
| 112 |
|
| 113 |
return Svg::get_inline_svg( $attachment_id ); |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* sanitize_svg |
| 118 |
* |
| 119 |
* @deprecated 3.5.0 |
| 120 |
* |
| 121 |
* @param $filename |
| 122 |
* |
| 123 |
* @return bool |
| 124 |
*/ |
| 125 |
public function sanitize_svg( $filename ) { |
| 126 |
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0', 'Plugin::$instance->uploads_manager->get_file_type_handlers( \'svg\' )->delete_meta_cache()->sanitize_svg()' ); |
| 127 |
|
| 128 |
/** @var Svg $svg_handler */ |
| 129 |
$svg_handler = Plugin::$instance->uploads_manager->get_file_type_handlers( 'svg' ); |
| 130 |
|
| 131 |
return $svg_handler->sanitize_svg( $filename ); |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* sanitizer |
| 136 |
* |
| 137 |
* @deprecated 3.5.0 |
| 138 |
* |
| 139 |
* @param $content |
| 140 |
* |
| 141 |
* @return bool|string |
| 142 |
*/ |
| 143 |
public function sanitizer( $content ) { |
| 144 |
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0', 'Plugin::$instance->uploads_manager->get_file_type_handlers( \'svg\' )->sanitizer()' ); |
| 145 |
|
| 146 |
/** @var Svg $svg_handler */ |
| 147 |
$svg_handler = Plugin::$instance->uploads_manager->get_file_type_handlers( 'svg' ); |
| 148 |
|
| 149 |
return $svg_handler->sanitizer( $content ); |
| 150 |
} |
| 151 |
|
| 152 |
/** |
| 153 |
* wp_prepare_attachment_for_js |
| 154 |
* |
| 155 |
* @deprecated 3.5.0 |
| 156 |
* |
| 157 |
* @param $attachment_data |
| 158 |
* @param $attachment |
| 159 |
* @param $meta |
| 160 |
* |
| 161 |
* @return mixed |
| 162 |
*/ |
| 163 |
public function wp_prepare_attachment_for_js( $attachment_data, $attachment, $meta ) { |
| 164 |
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0', 'Plugin::$instance->uploads_manager->get_file_type_handlers( \'svg\' )->wp_prepare_attachment_for_js()' ); |
| 165 |
|
| 166 |
/** @var Svg $svg_handler */ |
| 167 |
$svg_handler = Plugin::$instance->uploads_manager->get_file_type_handlers( 'svg' ); |
| 168 |
|
| 169 |
return $svg_handler->wp_prepare_attachment_for_js( $attachment_data, $attachment, $meta ); |
| 170 |
} |
| 171 |
|
| 172 |
/** |
| 173 |
* set_attachment_id |
| 174 |
* |
| 175 |
* @deprecated 3.5.0 |
| 176 |
* |
| 177 |
* @param $attachment_id |
| 178 |
* |
| 179 |
* @return int |
| 180 |
*/ |
| 181 |
public function set_attachment_id( $attachment_id ) { |
| 182 |
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0' ); |
| 183 |
|
| 184 |
$this->attachment_id = $attachment_id; |
| 185 |
return $this->attachment_id; |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* get_attachment_id |
| 190 |
* |
| 191 |
* @deprecated 3.5.0 |
| 192 |
* |
| 193 |
* @return int |
| 194 |
*/ |
| 195 |
public function get_attachment_id() { |
| 196 |
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0' ); |
| 197 |
|
| 198 |
return $this->attachment_id; |
| 199 |
} |
| 200 |
|
| 201 |
/** |
| 202 |
* set_svg_meta_data |
| 203 |
* |
| 204 |
* @deprecated 3.5.0 |
| 205 |
* |
| 206 |
* @return mixed |
| 207 |
*/ |
| 208 |
public function set_svg_meta_data( $data, $id ) { |
| 209 |
Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0', 'Plugin::$instance->uploads_manager->get_file_type_handlers( \'svg\' )->set_svg_meta_data()' ); |
| 210 |
|
| 211 |
/** @var Svg $svg_handler */ |
| 212 |
$svg_handler = Plugin::$instance->uploads_manager->get_file_type_handlers( 'svg' ); |
| 213 |
|
| 214 |
return $svg_handler->set_svg_meta_data( $data, $id ); |
| 215 |
} |
| 216 |
|
| 217 |
/** |
| 218 |
* handle_upload_prefilter |
| 219 |
* |
| 220 |
* @deprecated 3.5.0 |
| 221 |
* |
| 222 |
* @param $file |
| 223 |
* |
| 224 |
* @return mixed |
| 225 |
*/ |
| 226 |
public function handle_upload_prefilter( $file ) { |
| 227 |
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()' ); |
| 228 |
|
| 229 |
return Plugin::$instance->uploads_manager->handle_elementor_wp_media_upload( $file ); |
| 230 |
} |
| 231 |
} |
| 232 |
|