| @@ -2,9 +2,8 @@ | ||
| 2 | 2 | namespace Elementor; |
| 3 | 3 | |
| 4 | 4 | use Elementor\Core\Files\File_Types\Svg; |
| 5 | 5 | use Elementor\Core\Page_Assets\Data_Managers\Font_Icon_Svg\Manager as Font_Icon_Svg_Data_Manager; |
| 6 | -use Elementor\Utils; | |
| 7 | 6 | |
| 8 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | 8 | exit; // Exit if accessed directly. |
| 10 | 9 | } |
| @@ -23,9 +22,9 @@ | ||
| 23 | 22 | const FONT_ICON_SVG_CLASS_NAME = 'e-font-icon-svg'; |
| 24 | 23 | |
| 25 | 24 | const LOAD_FA4_SHIM_OPTION_KEY = 'elementor_load_fa4_shim'; |
| 26 | 25 | |
| 27 | - const ELEMENTOR_ICONS_VERSION = '5.53.0'; | |
| 26 | + const ELEMENTOR_ICONS_VERSION = '5.16.0'; | |
| 28 | 27 | |
| 29 | 28 | /** |
| 30 | 29 | * Tabs. |
| 31 | 30 | * |
| @@ -44,42 +43,9 @@ | ||
| 44 | 43 | return get_option( 'elementor_' . self::NEEDS_UPDATE_OPTION, null ); |
| 45 | 44 | } |
| 46 | 45 | |
| 47 | 46 | /** |
| 48 | - * @param array $icon | |
| 49 | - * @param array $attributes | |
| 50 | - * @param string $tag | |
| 51 | - * @return bool|mixed|string | |
| 52 | - */ | |
| 53 | - public static function try_get_icon_html( $icon, $attributes = [], $tag = 'i' ) { | |
| 54 | - if ( empty( $icon['library'] ) ) { | |
| 55 | - return ''; | |
| 56 | - } | |
| 57 | - | |
| 58 | - return static::get_icon_html( $icon, $attributes, $tag ); | |
| 59 | - } | |
| 60 | - | |
| 61 | - /** | |
| 62 | - * @param array $icon | |
| 63 | - * @param array $attributes | |
| 64 | - * @param string $tag | |
| 65 | - * @return bool|mixed|string | |
| 66 | - */ | |
| 67 | - private static function get_icon_html( array $icon, array $attributes, $tag ) { | |
| 68 | - /** | |
| 69 | - * When the library value is svg it means that it's a SVG media attachment uploaded by the user. | |
| 70 | - * Otherwise, it's the name of the font family that the icon belongs to. | |
| 71 | - */ | |
| 72 | - if ( 'svg' === $icon['library'] ) { | |
| 73 | - $output = self::render_uploaded_svg_icon( $icon['value'] ); | |
| 74 | - } else { | |
| 75 | - $output = self::render_font_icon( $icon, $attributes, $tag ); | |
| 76 | - } | |
| 77 | - return $output; | |
| 78 | - } | |
| 79 | - | |
| 80 | - /** | |
| 81 | - * Register styles | |
| 47 | + * register styles | |
| 82 | 48 | * |
| 83 | 49 | * Used to register all icon types stylesheets so they could be enqueued later by widgets |
| 84 | 50 | */ |
| 85 | 51 | public function register_styles() { |
| @@ -93,9 +59,9 @@ | ||
| 93 | 59 | } |
| 94 | 60 | $dependencies = []; |
| 95 | 61 | if ( ! empty( $icon_type['enqueue'] ) ) { |
| 96 | 62 | foreach ( (array) $icon_type['enqueue'] as $font_css_url ) { |
| 97 | - if ( ! in_array( $font_css_url, array_keys( $shared_styles ), true ) ) { | |
| 63 | + if ( ! in_array( $font_css_url, array_keys( $shared_styles ) ) ) { | |
| 98 | 64 | $style_handle = 'elementor-icons-shared-' . count( $shared_styles ); |
| 99 | 65 | wp_register_style( |
| 100 | 66 | $style_handle, |
| 101 | 67 | $font_css_url, |
| @@ -178,9 +144,8 @@ | ||
| 178 | 144 | } |
| 179 | 145 | |
| 180 | 146 | /** |
| 181 | 147 | * Get Icon Manager Tabs |
| 182 | - * | |
| 183 | 148 | * @return array |
| 184 | 149 | */ |
| 185 | 150 | public static function get_icon_manager_tabs() { |
| 186 | 151 | if ( self::is_font_icon_inline_svg() && ! Plugin::$instance->editor->is_edit_mode() && ! Plugin::$instance->preview->is_preview_mode() ) { |
| @@ -203,9 +168,8 @@ | ||
| 203 | 168 | return array_replace( self::$tabs, $additional_tabs ); |
| 204 | 169 | } |
| 205 | 170 | |
| 206 | 171 | public static function enqueue_shim() { |
| 207 | - //phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter | |
| 208 | 172 | wp_enqueue_script( |
| 209 | 173 | 'font-awesome-4-shim', |
| 210 | 174 | self::get_fa_asset_url( 'v4-shims', 'js' ), |
| 211 | 175 | [], |
| @@ -230,9 +194,9 @@ | ||
| 230 | 194 | |
| 231 | 195 | private static function get_fa_asset_url( $filename, $ext_type = 'css', $add_suffix = true ) { |
| 232 | 196 | static $is_test_mode = null; |
| 233 | 197 | if ( null === $is_test_mode ) { |
| 234 | - $is_test_mode = Utils::is_script_debug() || Utils::is_elementor_tests(); | |
| 198 | + $is_test_mode = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || defined( 'ELEMENTOR_TESTS' ) && ELEMENTOR_TESTS; | |
| 235 | 199 | } |
| 236 | 200 | $url = ELEMENTOR_ASSETS_URL . 'lib/font-awesome/' . $ext_type . '/' . $filename; |
| 237 | 201 | if ( ! $is_test_mode && $add_suffix ) { |
| 238 | 202 | $url .= '.min'; |
| @@ -253,8 +217,13 @@ | ||
| 253 | 217 | |
| 254 | 218 | return array_values( array_merge( $tabs, self::get_icon_manager_tabs() ) ); |
| 255 | 219 | } |
| 256 | 220 | |
| 221 | + /** | |
| 222 | + * is_font_awesome_inline | |
| 223 | + * | |
| 224 | + * @return bool | |
| 225 | + */ | |
| 257 | 226 | private static function is_font_icon_inline_svg() { |
| 258 | 227 | return Plugin::$instance->experiments->is_feature_active( 'e_font_icon_svg' ); |
| 259 | 228 | } |
| 260 | 229 | |
| @@ -268,9 +237,8 @@ | ||
| 268 | 237 | } |
| 269 | 238 | |
| 270 | 239 | /** |
| 271 | 240 | * Get font awesome svg. |
| 272 | - * | |
| 273 | 241 | * @param $icon array [ 'value' => string, 'library' => string ] |
| 274 | 242 | * |
| 275 | 243 | * @return bool|mixed|string |
| 276 | 244 | */ |
| @@ -329,12 +297,14 @@ | ||
| 329 | 297 | |
| 330 | 298 | if ( ! $content ) { |
| 331 | 299 | if ( empty( $attributes['class'] ) ) { |
| 332 | 300 | $attributes['class'] = $icon['value']; |
| 333 | - } elseif ( is_array( $attributes['class'] ) ) { | |
| 301 | + } else { | |
| 302 | + if ( is_array( $attributes['class'] ) ) { | |
| 334 | 303 | $attributes['class'][] = $icon['value']; |
| 335 | - } else { | |
| 336 | - $attributes['class'] .= ' ' . $icon['value']; | |
| 304 | + } else { | |
| 305 | + $attributes['class'] .= ' ' . $icon['value']; | |
| 306 | + } | |
| 337 | 307 | } |
| 338 | 308 | } |
| 339 | 309 | |
| 340 | 310 | return '<' . $tag . ' ' . Utils::render_html_attributes( $attributes ) . '>' . $content . '</' . $tag . '>'; |
| @@ -343,13 +313,12 @@ | ||
| 343 | 313 | /** |
| 344 | 314 | * Render Icon |
| 345 | 315 | * |
| 346 | 316 | * Used to render Icon for \Elementor\Controls_Manager::ICONS |
| 317 | + * @param array $icon Icon Type, Icon value | |
| 318 | + * @param array $attributes Icon HTML Attributes | |
| 319 | + * @param string $tag Icon HTML tag, defaults to <i> | |
| 347 | 320 | * |
| 348 | - * @param array $icon Icon Type, Icon value. | |
| 349 | - * @param array $attributes Icon HTML Attributes. | |
| 350 | - * @param string $tag Icon HTML tag, defaults to <i>. | |
| 351 | - * | |
| 352 | 321 | * @return mixed|string |
| 353 | 322 | */ |
| 354 | 323 | public static function render_icon( $icon, $attributes = [], $tag = 'i' ) { |
| 355 | 324 | if ( empty( $icon['library'] ) ) { |
| @@ -355,10 +324,20 @@ | ||
| 355 | 324 | if ( empty( $icon['library'] ) ) { |
| 356 | 325 | return false; |
| 357 | 326 | } |
| 358 | 327 | |
| 359 | - $output = static::get_icon_html( $icon, $attributes, $tag ); | |
| 328 | + $output = ''; | |
| 360 | 329 | |
| 330 | + /** | |
| 331 | + * When the library value is svg it means that it's a SVG media attachment uploaded by the user. | |
| 332 | + * Otherwise, it's the name of the font family that the icon belongs to. | |
| 333 | + */ | |
| 334 | + if ( 'svg' === $icon['library'] ) { | |
| 335 | + $output = self::render_uploaded_svg_icon( $icon['value'] ); | |
| 336 | + } else { | |
| 337 | + $output = self::render_font_icon( $icon, $attributes, $tag ); | |
| 338 | + } | |
| 339 | + | |
| 361 | 340 | Utils::print_unescaped_internal_string( $output ); |
| 362 | 341 | |
| 363 | 342 | return true; |
| 364 | 343 | } |
| @@ -365,9 +344,9 @@ | ||
| 365 | 344 | |
| 366 | 345 | /** |
| 367 | 346 | * Font Awesome 4 to font Awesome 5 Value Migration |
| 368 | 347 | * |
| 369 | - * Used to convert string value of Icon control to array value of Icons control | |
| 348 | + * used to convert string value of Icon control to array value of Icons control | |
| 370 | 349 | * ex: 'fa fa-star' => [ 'value' => 'fas fa-star', 'library' => 'fa-solid' ] |
| 371 | 350 | * |
| 372 | 351 | * @param $value |
| 373 | 352 | * |
| @@ -394,15 +373,14 @@ | ||
| 394 | 373 | ]; |
| 395 | 374 | } |
| 396 | 375 | |
| 397 | 376 | /** |
| 398 | - * On_import_migration | |
| 377 | + * on_import_migration | |
| 378 | + * @param array $element settings array | |
| 379 | + * @param string $old_control old control id | |
| 380 | + * @param string $new_control new control id | |
| 381 | + * @param bool $remove_old boolean weather to remove old control or not | |
| 399 | 382 | * |
| 400 | - * @param array $element settings array. | |
| 401 | - * @param string $old_control old control id. | |
| 402 | - * @param string $new_control new control id. | |
| 403 | - * @param bool $remove_old boolean whether to remove old control or not. | |
| 404 | - * | |
| 405 | 383 | * @return array |
| 406 | 384 | */ |
| 407 | 385 | public static function on_import_migration( array $element, $old_control = '', $new_control = '', $remove_old = false ) { |
| 408 | 386 | |
| @@ -422,9 +400,9 @@ | ||
| 422 | 400 | } |
| 423 | 401 | |
| 424 | 402 | $element['settings'][ $new_control ] = $new_value; |
| 425 | 403 | |
| 426 | - // remove old value | |
| 404 | + //remove old value | |
| 427 | 405 | if ( $remove_old ) { |
| 428 | 406 | unset( $element['settings'][ $old_control ] ); |
| 429 | 407 | } |
| 430 | 408 | |
| @@ -430,8 +408,12 @@ | ||
| 430 | 408 | |
| 431 | 409 | return $element; |
| 432 | 410 | } |
| 433 | 411 | |
| 412 | + /** | |
| 413 | + * is_migration_allowed | |
| 414 | + * @return bool | |
| 415 | + */ | |
| 434 | 416 | public static function is_migration_allowed() { |
| 435 | 417 | static $migration_allowed = false; |
| 436 | 418 | if ( false === $migration_allowed ) { |
| 437 | 419 | $migration_allowed = null === self::get_needs_upgrade_option(); |
| @@ -438,9 +420,9 @@ | ||
| 438 | 420 | |
| 439 | 421 | /** |
| 440 | 422 | * Is icon migration allowed. |
| 441 | 423 | * |
| 442 | - * Filters whether the icons migration allowed. | |
| 424 | + * Filters whther the icons migration allowed. | |
| 443 | 425 | * |
| 444 | 426 | * @param bool $migration_allowed Is icon migration is allowed. |
| 445 | 427 | */ |
| 446 | 428 | $migration_allowed = apply_filters( 'elementor/icons_manager/migration_allowed', $migration_allowed ); |
| @@ -450,10 +432,9 @@ | ||
| 450 | 432 | |
| 451 | 433 | /** |
| 452 | 434 | * Register_Admin Settings |
| 453 | 435 | * |
| 454 | - * Adds Font Awesome migration / update admin settings | |
| 455 | - * | |
| 436 | + * adds Font Awesome migration / update admin settings | |
| 456 | 437 | * @param Settings $settings |
| 457 | 438 | */ |
| 458 | 439 | public function register_admin_settings( Settings $settings ) { |
| 459 | 440 | $settings->add_field( |
| @@ -515,10 +496,9 @@ | ||
| 515 | 496 | * |
| 516 | 497 | * @return string |
| 517 | 498 | */ |
| 518 | 499 | public function get_upgrade_redirect_url() { |
| 519 | - | |
| 520 | - if ( ! wp_verify_nonce( Utils::get_super_global_value( $_GET, '_wpnonce' ), 'tools-page-from-editor' ) ) { | |
| 500 | + if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'tools-page-from-editor' ) ) { | |
| 521 | 501 | return ''; |
| 522 | 502 | } |
| 523 | 503 | |
| 524 | 504 | $document_id = ! empty( $_GET['redirect_to_document'] ) ? absint( $_GET['redirect_to_document'] ) : null; |
| @@ -541,12 +521,8 @@ | ||
| 541 | 521 | */ |
| 542 | 522 | public function ajax_upgrade_to_fa5() { |
| 543 | 523 | check_ajax_referer( self::NEEDS_UPDATE_OPTION, '_nonce' ); |
| 544 | 524 | |
| 545 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 546 | - wp_send_json_error( 'Permission denied' ); | |
| 547 | - } | |
| 548 | - | |
| 549 | 525 | delete_option( 'elementor_' . self::NEEDS_UPDATE_OPTION ); |
| 550 | 526 | |
| 551 | 527 | wp_send_json_success( [ 'message' => esc_html__( 'Hurray! The upgrade process to Font Awesome 5 was completed successfully.', 'elementor' ) ] ); |
| 552 | 528 | } |
| @@ -552,9 +528,8 @@ | ||
| 552 | 528 | } |
| 553 | 529 | |
| 554 | 530 | /** |
| 555 | 531 | * Add Update Needed Flag |
| 556 | - * | |
| 557 | 532 | * @param array $settings |
| 558 | 533 | * |
| 559 | 534 | * @return array; |
| 560 | 535 | */ |
| @@ -570,9 +545,9 @@ | ||
| 570 | 545 | $current_filter = current_filter(); |
| 571 | 546 | $load_shim = get_option( self::LOAD_FA4_SHIM_OPTION_KEY, false ); |
| 572 | 547 | if ( 'elementor/editor/after_enqueue_styles' === $current_filter ) { |
| 573 | 548 | self::enqueue_shim(); |
| 574 | - } elseif ( 'yes' === $load_shim ) { | |
| 549 | + } else if ( 'yes' === $load_shim ) { | |
| 575 | 550 | self::enqueue_shim(); |
| 576 | 551 | } |
| 577 | 552 | } |
| 578 | 553 | } |