| @@ -1,6 +1,10 @@ | ||
| 1 | 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | 2 | |
| 3 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 4 | + exit( 0 ); | |
| 5 | +} | |
| 6 | + | |
| 3 | 7 | // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. |
| 4 | 8 | |
| 5 | 9 | /** |
| 6 | 10 | * Social Icons Widget. |
| @@ -52,14 +56,8 @@ | ||
| 52 | 56 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); |
| 53 | 57 | add_action( 'admin_print_footer_scripts', array( $this, 'render_admin_js' ) ); |
| 54 | 58 | } |
| 55 | 59 | |
| 56 | - // Enqueue scripts and styles for the display of the widget, on the frontend or in the customizer. | |
| 57 | - if ( is_active_widget( false, $this->id, $this->id_base, true ) || is_customize_preview() ) { | |
| 58 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_icon_scripts' ) ); | |
| 59 | - add_action( 'wp_footer', array( $this, 'include_svg_icons' ), 9999 ); | |
| 60 | - } | |
| 61 | - | |
| 62 | 60 | add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_widget_in_block_editor' ) ); |
| 63 | 61 | } |
| 64 | 62 | |
| 65 | 63 | /** |
| @@ -115,18 +113,39 @@ | ||
| 115 | 113 | */ |
| 116 | 114 | public function include_svg_icons() { |
| 117 | 115 | // Define SVG sprite file in Jetpack. |
| 118 | 116 | $svg_icons = dirname( __DIR__ ) . '/theme-tools/social-menu/social-menu.svg'; |
| 119 | - $svg_icons = class_exists( 'Automattic\Jetpack\Classic_Theme_Helper\Main' ) ? JETPACK__PLUGIN_DIR . 'jetpack-vendor/automattic/jetpack-classic-theme-helper/src/social-menu/social-menu.svg' : dirname( __DIR__ ) . '/theme-tools/social-menu/social-menu.svg'; | |
| 117 | + $svg_icons = class_exists( 'Automattic\Jetpack\Classic_Theme_Helper\Main' ) ? JETPACK__PLUGIN_DIR . 'jetpack_vendor/automattic/jetpack-classic-theme-helper/src/social-menu/social-menu.svg' : dirname( __DIR__ ) . '/theme-tools/social-menu/social-menu.svg'; | |
| 120 | 118 | // Define SVG sprite file in WPCOM. |
| 121 | 119 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
| 122 | - $svg_icons = class_exists( 'Automattic\Jetpack\Classic_Theme_Helper\Main' ) ? JETPACK__PLUGIN_DIR . 'jetpack-vendor/automattic/jetpack-classic-theme-helper/src/social-menu/social-menu.svg' : dirname( __DIR__ ) . '/social-menu/social-menu.svg'; | |
| 120 | + $svg_icons = class_exists( 'Automattic\Jetpack\Classic_Theme_Helper\Main' ) ? JETPACK__PLUGIN_DIR . 'jetpack_vendor/automattic/jetpack-classic-theme-helper/src/social-menu/social-menu.svg' : dirname( __DIR__ ) . '/social-menu/social-menu.svg'; | |
| 123 | 121 | } |
| 124 | 122 | |
| 125 | 123 | // If it exists, include it. |
| 126 | 124 | if ( is_file( $svg_icons ) ) { |
| 127 | - require_once $svg_icons; | |
| 125 | + $svg_contents = file_get_contents( $svg_icons ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Only reading a local file. | |
| 128 | 126 | } |
| 127 | + | |
| 128 | + if ( ! empty( $svg_contents ) ) { | |
| 129 | + $allowed_tags = array( | |
| 130 | + 'svg' => array( | |
| 131 | + 'style' => true, | |
| 132 | + 'version' => true, | |
| 133 | + 'xmlns' => true, | |
| 134 | + 'xmlns:xlink' => true, | |
| 135 | + ), | |
| 136 | + 'defs' => array(), | |
| 137 | + 'symbol' => array( | |
| 138 | + 'id' => true, | |
| 139 | + 'viewbox' => true, | |
| 140 | + ), | |
| 141 | + 'path' => array( | |
| 142 | + 'd' => true, | |
| 143 | + 'style' => true, | |
| 144 | + ), | |
| 145 | + ); | |
| 146 | + echo wp_kses( $svg_contents, $allowed_tags ); | |
| 147 | + } | |
| 129 | 148 | } |
| 130 | 149 | |
| 131 | 150 | /** |
| 132 | 151 | * Front-end display of widget. |
| @@ -138,8 +157,12 @@ | ||
| 138 | 157 | */ |
| 139 | 158 | public function widget( $args, $instance ) { |
| 140 | 159 | $instance = wp_parse_args( $instance, $this->defaults ); |
| 141 | 160 | |
| 161 | + // Enqueue front end assets. | |
| 162 | + $this->enqueue_icon_scripts(); | |
| 163 | + add_action( 'wp_footer', array( $this, 'include_svg_icons' ), 9999 ); | |
| 164 | + | |
| 142 | 165 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
| 143 | 166 | $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
| 144 | 167 | |
| 145 | 168 | echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| @@ -164,9 +187,9 @@ | ||
| 164 | 187 | <li class="jetpack-social-widget-item"> |
| 165 | 188 | <?php |
| 166 | 189 | printf( |
| 167 | 190 | '<a href="%1$s" %2$s>', |
| 168 | - esc_url( $icon['url'], array( 'http', 'https', 'mailto', 'skype', 'sms' ) ), | |
| 191 | + esc_url( $icon['url'], array( 'http', 'https', 'mailto', 'sms' ) ), | |
| 169 | 192 | true === $instance['new-tab'] ? |
| 170 | 193 | 'target="_blank" rel="noopener noreferrer"' : |
| 171 | 194 | 'target="_self"' |
| 172 | 195 | ); |
| @@ -323,19 +346,21 @@ | ||
| 323 | 346 | </button> |
| 324 | 347 | </p> |
| 325 | 348 | |
| 326 | 349 | <?php |
| 327 | - switch ( get_locale() ) { | |
| 350 | + $lang = strtolower( substr( get_locale(), 0, 2 ) ); | |
| 351 | + switch ( $lang ) { | |
| 328 | 352 | case 'es': |
| 329 | - $support = 'https://es.support.wordpress.com/social-media-icons-widget/#iconos-disponibles'; | |
| 353 | + $support = 'https://wordpress.com/es/support/wordpress-editor/blocks/social-icons-block/display-social-profiles/#iconos-sociales-compatibles'; | |
| 330 | 354 | break; |
| 331 | 355 | |
| 332 | - case 'pt-br': | |
| 333 | - $support = 'https://br.support.wordpress.com/widgets/widget-de-icones-sociais/#ícones-disponíveis'; | |
| 356 | + case 'pt': | |
| 357 | + $support = 'https://wordpress.com/pt-br/support/exibir-perfis-de-redes-sociais/#icones-de-redes-sociais-compativeis'; | |
| 334 | 358 | break; |
| 335 | 359 | |
| 336 | 360 | default: |
| 337 | - $support = 'https://en.support.wordpress.com/widgets/social-media-icons-widget/#available-icons'; | |
| 361 | + $support = 'https://wordpress.com/support/wordpress-editor/blocks/social-icons-block/display-social-profiles/#supported-social-icons'; | |
| 362 | + break; | |
| 338 | 363 | } |
| 339 | 364 | ?> |
| 340 | 365 | |
| 341 | 366 | <p> |
| @@ -377,9 +402,9 @@ | ||
| 377 | 402 | '<input class="widefat" id="%1$s" name="%2$s[]" type="text" placeholder="%3$s" value="%4$s"/>', |
| 378 | 403 | esc_attr( $args['url-icon-id'] ), |
| 379 | 404 | esc_attr( $args['url-icon-name'] ), |
| 380 | 405 | esc_attr__( 'Account URL', 'jetpack' ), |
| 381 | - esc_url( $args['url-value'], array( 'http', 'https', 'mailto', 'skype', 'sms' ) ) | |
| 406 | + esc_url( $args['url-value'], array( 'http', 'https', 'mailto', 'sms' ) ) | |
| 382 | 407 | ); |
| 383 | 408 | ?> |
| 384 | 409 | </p> |
| 385 | 410 | |
| @@ -418,9 +443,9 @@ | ||
| 418 | 443 | // Parse args. |
| 419 | 444 | $args = wp_parse_args( $args, $defaults ); |
| 420 | 445 | |
| 421 | 446 | // Define an icon. |
| 422 | - if ( false === array_key_exists( 'icon', $args ) ) { | |
| 447 | + if ( ! array_key_exists( 'icon', $args ) ) { | |
| 423 | 448 | return esc_html__( 'Please define an SVG icon filename.', 'jetpack' ); |
| 424 | 449 | } |
| 425 | 450 | |
| 426 | 451 | // Set aria hidden. |
| @@ -615,13 +640,8 @@ | ||
| 615 | 640 | 'icon' => 'pinterest', |
| 616 | 641 | 'label' => 'Pinterest', |
| 617 | 642 | ), |
| 618 | 643 | array( |
| 619 | - 'url' => array( 'getpocket.com' ), | |
| 620 | - 'icon' => 'pocket', | |
| 621 | - 'label' => 'Pocket', | |
| 622 | - ), | |
| 623 | - array( | |
| 624 | 644 | 'url' => array( 'ravelry.com' ), |
| 625 | 645 | 'icon' => 'ravelry', |
| 626 | 646 | 'label' => 'Ravelry', |
| 627 | 647 | ), |
| @@ -630,18 +650,8 @@ | ||
| 630 | 650 | 'icon' => 'reddit', |
| 631 | 651 | 'label' => 'Reddit', |
| 632 | 652 | ), |
| 633 | 653 | array( |
| 634 | - 'url' => array( 'skype.com' ), | |
| 635 | - 'icon' => 'skype', | |
| 636 | - 'label' => 'Skype', | |
| 637 | - ), | |
| 638 | - array( | |
| 639 | - 'url' => array( 'skype:' ), | |
| 640 | - 'icon' => 'skype', | |
| 641 | - 'label' => 'Skype', | |
| 642 | - ), | |
| 643 | - array( | |
| 644 | 654 | 'url' => array( 'slideshare.net' ), |
| 645 | 655 | 'icon' => 'slideshare', |
| 646 | 656 | 'label' => 'SlideShare', |
| 647 | 657 | ), |
| @@ -705,13 +715,8 @@ | ||
| 705 | 715 | 'icon' => 'twitch', |
| 706 | 716 | 'label' => 'Twitch', |
| 707 | 717 | ), |
| 708 | 718 | array( |
| 709 | - 'url' => array( 'twitter.com' ), | |
| 710 | - 'icon' => 'twitter', | |
| 711 | - 'label' => 'Twitter', | |
| 712 | - ), | |
| 713 | - array( | |
| 714 | 719 | 'url' => array( 'vimeo.com' ), |
| 715 | 720 | 'icon' => 'vimeo', |
| 716 | 721 | 'label' => 'Vimeo', |
| 717 | 722 | ), |
| @@ -740,9 +745,9 @@ | ||
| 740 | 745 | 'icon' => 'yelp', |
| 741 | 746 | 'label' => 'Yelp', |
| 742 | 747 | ), |
| 743 | 748 | array( |
| 744 | - 'url' => array( 'x.com' ), | |
| 749 | + 'url' => array( '#^https?:\/\/(www\.)?(twitter|x)\.com#' ), | |
| 745 | 750 | 'icon' => 'x', |
| 746 | 751 | 'label' => 'X', |
| 747 | 752 | ), |
| 748 | 753 | array( |