| @@ -1,8 +1,12 @@ | ||
| 1 | 1 | <?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | 2 | |
| 3 | 3 | use Automattic\Jetpack\Assets; |
| 4 | 4 | |
| 5 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 6 | + exit( 0 ); | |
| 7 | +} | |
| 8 | + | |
| 5 | 9 | /** |
| 6 | 10 | * Embed recipe 'cards' in post, with basic styling and print functionality |
| 7 | 11 | * |
| 8 | 12 | * To Do |
| @@ -15,8 +19,10 @@ | ||
| 15 | 19 | */ |
| 16 | 20 | |
| 17 | 21 | /** |
| 18 | 22 | * Register and display Recipes in posts. |
| 23 | + * | |
| 24 | + * @phan-constructor-used-for-side-effects | |
| 19 | 25 | */ |
| 20 | 26 | class Jetpack_Recipes { |
| 21 | 27 | |
| 22 | 28 | /** |
| @@ -110,20 +116,20 @@ | ||
| 110 | 116 | if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { |
| 111 | 117 | return; |
| 112 | 118 | } |
| 113 | 119 | |
| 114 | - wp_enqueue_script( | |
| 115 | - 'jetpack-recipes-printthis', | |
| 116 | - Assets::get_file_url_for_environment( '_inc/build/shortcodes/js/recipes-printthis.min.js', 'modules/shortcodes/js/recipes-printthis.js' ), | |
| 120 | + wp_register_script( | |
| 121 | + 'jetpack-shortcode-deps', | |
| 122 | + plugins_url( '_inc/build/shortcodes/js/dependencies.min.js', JETPACK__PLUGIN_FILE ), | |
| 117 | 123 | array( 'jquery' ), |
| 118 | - '20170202', | |
| 119 | - false | |
| 124 | + '20250905', | |
| 125 | + true | |
| 120 | 126 | ); |
| 121 | 127 | |
| 122 | 128 | wp_enqueue_script( |
| 123 | 129 | 'jetpack-recipes-js', |
| 124 | 130 | Assets::get_file_url_for_environment( '_inc/build/shortcodes/js/recipes.min.js', 'modules/shortcodes/js/recipes.js' ), |
| 125 | - array( 'jquery', 'jetpack-recipes-printthis' ), | |
| 131 | + array( 'jquery', 'jetpack-shortcode-deps' ), | |
| 126 | 132 | '20131230', |
| 127 | 133 | false |
| 128 | 134 | ); |
| 129 | 135 | |
| @@ -477,13 +483,8 @@ | ||
| 477 | 483 | $list_item_replacement = '<li class="jetpack-recipe-nutrition">${1}</li>'; |
| 478 | 484 | $itemprop = ' itemprop="nutrition"'; |
| 479 | 485 | $listtype = 'ul'; |
| 480 | 486 | break; |
| 481 | - case 'nutrition': | |
| 482 | - $list_item_replacement = '<li class="jetpack-recipe-nutrition nutrition">${1}</li>'; | |
| 483 | - $itemprop = ' itemprop="nutrition"'; | |
| 484 | - $listtype = 'ul'; | |
| 485 | - break; | |
| 486 | 487 | default: |
| 487 | 488 | $list_item_replacement = '<li class="jetpack-recipe-notes">${1}</li>'; |
| 488 | 489 | $itemprop = ''; |
| 489 | 490 | $listtype = 'ul'; |
| @@ -490,15 +491,15 @@ | ||
| 490 | 491 | } |
| 491 | 492 | |
| 492 | 493 | // Check to see if the user is trying to use shortened formatting. |
| 493 | 494 | if ( |
| 494 | - strpos( $content, '–' ) !== false || | |
| 495 | - strpos( $content, '—' ) !== false || | |
| 496 | - strpos( $content, '-' ) !== false || | |
| 497 | - strpos( $content, '*' ) !== false || | |
| 498 | - strpos( $content, '#' ) !== false || | |
| 499 | - strpos( $content, '–' ) !== false || // ndash. | |
| 500 | - strpos( $content, '—' ) !== false || // mdash. | |
| 495 | + str_contains( $content, '–' ) || | |
| 496 | + str_contains( $content, '—' ) || | |
| 497 | + str_contains( $content, '-' ) || | |
| 498 | + str_contains( $content, '*' ) || | |
| 499 | + str_contains( $content, '#' ) || | |
| 500 | + str_contains( $content, '–' ) || // ndash. | |
| 501 | + str_contains( $content, '—' ) || // mdash. | |
| 501 | 502 | preg_match( '/\d+\.\s/', $content ) |
| 502 | 503 | ) { |
| 503 | 504 | // Remove breaks and extra whitespace. |
| 504 | 505 | $content = str_replace( "<br />\n", "\n", $content ); |
| @@ -509,11 +510,11 @@ | ||
| 509 | 510 | |
| 510 | 511 | preg_match_all( $ul_pattern, $content, $ul_matches ); |
| 511 | 512 | preg_match_all( $ol_pattern, $content, $ol_matches ); |
| 512 | 513 | |
| 513 | - if ( 0 !== count( $ul_matches[0] ) || 0 !== count( $ol_matches[0] ) ) { | |
| 514 | + if ( ( is_countable( $ul_matches[0] ) && count( $ul_matches[0] ) > 0 ) || ( is_countable( $ol_matches[0] ) && count( $ol_matches[0] ) > 0 ) ) { | |
| 514 | 515 | |
| 515 | - if ( 0 !== count( $ol_matches[0] ) ) { | |
| 516 | + if ( is_countable( $ol_matches[0] ) && count( $ol_matches[0] ) > 0 ) { | |
| 516 | 517 | $listtype = 'ol'; |
| 517 | 518 | $list_item_pattern = $ol_pattern; |
| 518 | 519 | } else { |
| 519 | 520 | $listtype = 'ul'; |
| @@ -634,12 +635,9 @@ | ||
| 634 | 635 | 'class' => 'jetpack-recipe-image u-photo photo', |
| 635 | 636 | 'itemprop' => 'image', |
| 636 | 637 | ); |
| 637 | 638 | |
| 638 | - if ( | |
| 639 | - function_exists( 'wp_lazy_loading_enabled' ) | |
| 640 | - && wp_lazy_loading_enabled( 'img', 'wp_get_attachment_image' ) | |
| 641 | - ) { | |
| 639 | + if ( wp_lazy_loading_enabled( 'img', 'wp_get_attachment_image' ) ) { | |
| 642 | 640 | $image_attrs['loading'] = 'lazy'; |
| 643 | 641 | } |
| 644 | 642 | |
| 645 | 643 | // If it's numeric, this may be an attachment. |
| @@ -653,9 +651,9 @@ | ||
| 653 | 651 | } |
| 654 | 652 | |
| 655 | 653 | // Check if it's an absolute or relative URL, and return if not. |
| 656 | 654 | if ( |
| 657 | - 0 !== strpos( $src, '/' ) | |
| 655 | + ! str_starts_with( $src, '/' ) | |
| 658 | 656 | && false === filter_var( $src, FILTER_VALIDATE_URL ) |
| 659 | 657 | ) { |
| 660 | 658 | return ''; |
| 661 | 659 | } |
| @@ -685,15 +683,16 @@ | ||
| 685 | 683 | public function themecolor_styles() { |
| 686 | 684 | global $themecolors; |
| 687 | 685 | $style = ''; |
| 688 | 686 | |
| 689 | - if ( isset( $themecolors ) ) { | |
| 687 | + if ( isset( $themecolors['border'] ) ) { | |
| 690 | 688 | $style .= '.jetpack-recipe { border-color: #' . esc_attr( $themecolors['border'] ) . '; }'; |
| 689 | + } | |
| 690 | + if ( isset( $themecolors['link'] ) ) { | |
| 691 | 691 | $style .= '.jetpack-recipe-title { border-bottom-color: #' . esc_attr( $themecolors['link'] ) . '; }'; |
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | return $style; |
| 695 | 695 | } |
| 696 | - | |
| 697 | 696 | } |
| 698 | 697 | |
| 699 | 698 | new Jetpack_Recipes(); |