diff --git a/.gitignore b/.gitignore index a1ff0c1680..97b4fe0852 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ twentynineteen/ theme-dev-utils/ theme-dev-utils vendor/ +# Don't ignore blockbase/vendor, which has package code needed by the theme +!blockbase/vendor *.DS_Store *.zip *.rej diff --git a/blockbase/composer.json b/blockbase/composer.json new file mode 100644 index 0000000000..a261b4bed8 --- /dev/null +++ b/blockbase/composer.json @@ -0,0 +1,9 @@ +{ + "name": "automattic/blockbase", + "description": "A universal WordPress theme that bridges classic and block-based themes", + "type": "project", + "require": { + "automattic/jetpack-google-fonts-provider": "^0.3.0" + }, + "license": "GPL-2.0-or-later" +} diff --git a/blockbase/composer.lock b/blockbase/composer.lock new file mode 100644 index 0000000000..2f0e125354 --- /dev/null +++ b/blockbase/composer.lock @@ -0,0 +1,65 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "c4626a994d9535042254e67ce1633371", + "packages": [ + { + "name": "automattic/jetpack-google-fonts-provider", + "version": "v0.3.0", + "source": { + "type": "git", + "url": "https://github.com/Automattic/jetpack-google-fonts-provider.git", + "reference": "cc26c71d0156bcdce80552cb7f084c23b5fe7be4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Automattic/jetpack-google-fonts-provider/zipball/cc26c71d0156bcdce80552cb7f084c23b5fe7be4", + "reference": "cc26c71d0156bcdce80552cb7f084c23b5fe7be4", + "shasum": "" + }, + "require-dev": { + "automattic/jetpack-changelogger": "^3.1", + "brain/monkey": "2.6.1", + "yoast/phpunit-polyfills": "1.0.3" + }, + "type": "jetpack-library", + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-google-fonts-provider", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-google-fonts-provider/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-master": "0.3.x-dev" + }, + "textdomain": "jetpack-google-fonts-provider" + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "WordPress Webfonts provider for Google Fonts", + "support": { + "source": "https://github.com/Automattic/jetpack-google-fonts-provider/tree/v0.3.0" + }, + "time": "2022-04-26T14:33:32+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.2.0" +} diff --git a/blockbase/functions.php b/blockbase/functions.php index 25ed464d74..465da73f3b 100644 --- a/blockbase/functions.php +++ b/blockbase/functions.php @@ -1,4 +1,9 @@ get( 'Version' ) ); // Add the child theme CSS if it exists. if ( file_exists( get_stylesheet_directory() . '/assets/theme.css' ) ) { wp_enqueue_style( 'blockbase-child-styles', get_stylesheet_directory_uri() . '/assets/theme.css', array('blockbase-ponyfill'), wp_get_theme()->get( 'Version' ) ); } -} -add_action( 'wp_enqueue_scripts', 'blockbase_scripts' ); - -/** - * Add Google webfonts - * - * @return $fonts_url - */ - -function blockbase_fonts_url() { - if ( ! class_exists( 'WP_Theme_JSON_Resolver_Gutenberg' ) ) { - return ''; - } - $theme_data = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data()->get_settings(); - if ( empty( $theme_data ) || empty( $theme_data['typography'] ) || empty( $theme_data['typography']['fontFamilies'] ) ) { - return ''; + if ( function_exists( 'blockbase_enqueue_default_fonts' ) ) { + blockbase_enqueue_default_fonts(); } - - $font_families = []; - if ( ! empty( $theme_data['typography']['fontFamilies']['custom'] ) ) { - foreach( $theme_data['typography']['fontFamilies']['custom'] as $font ) { - if ( ! empty( $font['google'] ) ) { - $font_families[] = $font['google']; - } - } - - // NOTE: This should be removed once Gutenberg 12.1 lands stably in all environments - } else if ( ! empty( $theme_data['typography']['fontFamilies']['user'] ) ) { - foreach( $theme_data['typography']['fontFamilies']['user'] as $font ) { - if ( ! empty( $font['google'] ) ) { - $font_families[] = $font['google']; - } - } - // End Gutenberg < 12.1 compatibility patch - - } else { - if ( ! empty( $theme_data['typography']['fontFamilies']['theme'] ) ) { - foreach( $theme_data['typography']['fontFamilies']['theme'] as $font ) { - if ( ! empty( $font['google'] ) ) { - $font_families[] = $font['google']; - } - } - } - } - - if ( empty( $font_families ) ) { - return ''; - } - - // Make a single request for the theme or user fonts. - return esc_url_raw( 'https://fonts.googleapis.com/css2?' . implode( '&', array_unique( $font_families ) ) . '&display=swap' ); } +add_action( 'wp_enqueue_scripts', 'blockbase_scripts' ); /** * Customize Global Styles @@ -152,10 +101,13 @@ function blockbase_fonts_url() { if ( class_exists( 'WP_Theme_JSON_Resolver_Gutenberg' ) ) { require get_template_directory() . '/inc/customizer/wp-customize-colors.php'; require get_template_directory() . '/inc/customizer/wp-customize-color-palettes.php'; - require get_template_directory() . '/inc/customizer/wp-customize-fonts.php'; require get_template_directory() . '/inc/social-navigation.php'; + require get_template_directory() . '/inc/custom-google-fonts.php'; } +// Font settings migration and deprecation message. Fonts now set in Global Styles. +require get_template_directory() . '/inc/customizer/wp-customize-fonts.php'; + // Force menus to reload add_action( 'customize_controls_enqueue_scripts', diff --git a/blockbase/inc/custom-google-fonts.php b/blockbase/inc/custom-google-fonts.php new file mode 100644 index 0000000000..4650a98d3e --- /dev/null +++ b/blockbase/inc/custom-google-fonts.php @@ -0,0 +1,130 @@ + array( 'font_family' => 'Arvo'), + 'bodoni-moda' => array( 'font_family' => 'Bodoni Moda'), + 'cabin' => array( 'font_family' => 'Cabin'), + 'chivo' => array( 'font_family' => 'Chivo'), + 'courier-prime' => array( 'font_family' => 'Courier Prime'), + 'dm-sans' => array( 'font_family' => 'DM Sans' ), + 'domine' => array( 'font_family' => 'Domine'), + 'eb-garamond' => array( 'font_family' => 'EB Garamond'), + 'fira-sans' => array( 'font_family' => 'Fira Sans'), + 'ibm-plex-sans' => array( 'font_family' => 'IBM Plex Sans'), + 'ibm-plex-mono' => array( 'font_family' => 'IBM Plex Mono'), + 'inter' => array( 'font_family' => 'Inter'), + 'josefin-sans' => array( 'font_family' => 'Josefin Sans'), + 'jost' => array( 'font_family' => 'Jost'), + 'libre-baskerville' => array( 'font_family' => 'Libre Baskerville'), + 'libre-franklin' => array( 'font_family' => 'Libre Franklin'), + 'literata' => array( 'font_family' => 'Literata'), + 'lora' => array( 'font_family' => 'Lora'), + 'merriweather' => array( 'font_family' => 'Merriweather'), + 'montserrat' => array( 'font_family' => 'Montserrat'), + 'newsreader' => array( 'font_family' => 'Newsreader'), + 'nunito' => array( 'font_family' => 'Nunito'), + 'open-sans' => array( 'font_family' => 'Open Sans'), + 'overpass' => array( 'font_family' => 'Overpass'), + 'playfair-display' => array( 'font_family' => 'Playfair Display'), + 'poppins' => array( 'font_family' => 'Poppins'), + 'raleway' => array( 'font_family' => 'Raleway'), + 'red-hat-display' => array( 'font_family' => 'Red Hat Display'), + 'roboto' => array( 'font_family' => 'Roboto'), + 'roboto-slab' => array( 'font_family' => 'Roboto Slab'), + 'rubik' => array( 'font_family' => 'Rubik'), + 'source-sans-pro' => array( 'font_family' => 'Source Sans Pro'), + 'source-serif-pro' => array( 'font_family' => 'Source Serif Pro'), + 'space-mono' => array( 'font_family' => 'Space Mono'), + 'texturina' => array( 'font_family' => 'Texturina'), + 'work-sans' => array( 'font_family' => 'Work Sans'), +); + +/** + * Register a curated selection of Google Fonts. + * + * @return void + */ +function blockbase_register_google_fonts() { + // Use jetpack's implementation of custom google fonts if it is already active + if ( method_exists( 'Jetpack', 'is_module_active' ) && Jetpack::is_module_active( 'google-fonts' ) ) { + return; + } + + if ( ! function_exists( 'wp_register_webfont_provider' ) || ! function_exists( 'wp_register_webfonts' ) ) { + return; + } + + wp_register_webfont_provider( 'blockbase-google-fonts', '\Automattic\Jetpack\Fonts\Google_Fonts_Provider' ); + + /** + * Curated list of Google Fonts. + * + * @module google-fonts + * + * @since 10.8 + * + * @param array $fonts_to_register Array of Google Font names to register. + */ + $fonts_to_register = apply_filters( 'blockbase_google_fonts_list', BLOCKBASE_GOOGLE_FONTS_LIST ); + + foreach ( $fonts_to_register as $font_settings ) { + $font_family = $font_settings['font_family']; + + wp_register_webfonts( + array( + array( + 'font-family' => $font_family, + 'font-weight' => '100 900', + 'font-style' => 'normal', + 'font-display' => 'swap', + 'provider' => 'blockbase-google-fonts', + ), + array( + 'font-family' => $font_family, + 'font-weight' => '100 900', + 'font-style' => 'italic', + 'font-display' => 'swap', + 'provider' => 'blockbase-google-fonts', + ), + ) + ); + } + + add_filter( 'wp_resource_hints', '\Automattic\Jetpack\Fonts\Utils::font_source_resource_hint', 10, 2 ); + add_filter( 'pre_render_block', '\Automattic\Jetpack\Fonts\Introspectors\Blocks::enqueue_block_fonts', 10, 2 ); + add_action( 'init', '\Automattic\Jetpack\Fonts\Introspectors\Global_Styles::enqueue_global_styles_fonts' ); +} +add_action( 'after_setup_theme', 'blockbase_register_google_fonts' ); + +/** + * Automatically enqueues default blockbase theme google fonts + * + * @return void + */ +function blockbase_enqueue_default_fonts() { + if ( ! function_exists( 'wp_enqueue_webfont' ) ) { + return; + } + + $font_settings = wp_get_global_settings( array( 'typography', 'fontFamilies' ), 'base' ); + + if ( ! isset( $font_settings['theme'] ) ) { + return; + } + + foreach( $font_settings['theme'] as $font_setting ) { + if ( ! isset( $font_setting['fontSlug'] ) ) { + continue; + } + + $font_slug = $font_setting['fontSlug']; + + if ( $font_slug && isset( BLOCKBASE_GOOGLE_FONTS_LIST[$font_slug] ) ) { + $font_family = BLOCKBASE_GOOGLE_FONTS_LIST[$font_slug]['font_family']; + wp_enqueue_webfont( $font_family ); + } + } +} \ No newline at end of file diff --git a/blockbase/inc/customizer/wp-customize-fonts-control.js b/blockbase/inc/customizer/wp-customize-fonts-control.js deleted file mode 100644 index 27d1dac1f9..0000000000 --- a/blockbase/inc/customizer/wp-customize-fonts-control.js +++ /dev/null @@ -1,91 +0,0 @@ -wp.customize.bind( 'ready', () => { - let resetButton; - let fontBodyControl; - let fontHeadingControl; - - wp.customize.control( - 'customize-global-styles-fonts-reset-button', - ( control ) => { - control.container - .find( '.button' ) - .on( 'click', resetFontSelection ); - resetButton = control.container[ 0 ]; - resetButton.hidden = determineIfSetToDetault(); - } - ); - - // If the body and heading controls are null then the font customization is using - // the old format. We need to hide these controls so that the user is forced to - // reset to defaults before making other changes. - wp.customize.control( 'customize-global-styles-fontsbody', ( control ) => { - fontBodyControl = control.container[ 0 ]; - fontBodyControl.hidden = determineIfNull(); - } ); - wp.customize.control( - 'customize-global-styles-fontsheading', - ( control ) => { - fontHeadingControl = control.container[ 0 ]; - fontHeadingControl.hidden = determineIfNull(); - } - ); - - wp.customize( - 'customize-global-styles-fontsbody', - bindControlToHideResetButton - ); - wp.customize( - 'customize-global-styles-fontsheading', - bindControlToHideResetButton - ); - - function bindControlToHideResetButton( control ) { - control.bind( () => { - resetButton.hidden = false; - fontHeadingControl.hidden = false; - fontBodyControl.hidden = false; - } ); - } - - function determineIfSetToDetault() { - return ( - fontControlDefaultBody[ 0 ] === - wp.customize.settings.settings[ - 'customize-global-styles-fontsbody' - ].value && - fontControlDefaultHeading[ 0 ] === - wp.customize.settings.settings[ - 'customize-global-styles-fontsheading' - ].value - ); - } - - function determineIfNull() { - return ! ( - wp.customize.settings.settings[ - 'customize-global-styles-fontsbody' - ].value && - wp.customize.settings.settings[ - 'customize-global-styles-fontsheading' - ].value - ); - } - - function resetFontSelection() { - const shouldWeReload = determineIfNull(); - wp.customize( 'customize-global-styles-fontsbody', ( item ) => { - item.set( fontControlDefaultBody[ 0 ] ); - } ); - wp.customize( 'customize-global-styles-fontsheading', ( item ) => { - item.set( fontControlDefaultHeading[ 0 ] ); - } ); - resetButton.hidden = true; - - // If the body and heading controls are null then the font customization is using - // the old format. We need to get the user to reset to default and then reload - // before they make other customizations. - if ( shouldWeReload ) { - wp.customize.previewer.save(); - wp.customize.previewer.refresh(); - } - } -} ); diff --git a/blockbase/inc/customizer/wp-customize-fonts-preview.js b/blockbase/inc/customizer/wp-customize-fonts-preview.js deleted file mode 100644 index b889856a35..0000000000 --- a/blockbase/inc/customizer/wp-customize-fonts-preview.js +++ /dev/null @@ -1,26 +0,0 @@ -if ( fontSettings ) { - Object.keys( fontSettings ).forEach( function ( selector ) { - wp.customize( 'customize-global-styles-fonts' + selector, function ( - control - ) { - control.bind( ( newFont ) => { - fontFamily = googleFonts[ newFont ][ 'fontFamily' ]; - fontSettings[ selector ] = fontFamily; - blockBaseUpdateFontPreview(); - } ); - } ); - } ); -} - -function blockBaseUpdateFontPreview() { - let innerHTML = 'body {'; - innerHTML += `--wp--preset--font-family--body-font:${ fontSettings[ 'body' ] };`; - innerHTML += `--wp--preset--font-family--heading-font:${ fontSettings[ 'heading' ] };`; - innerHTML += '}'; - - // Inject them into the body. - const styleElement = document.getElementById( - 'global-styles-fonts-customizations-inline-css' - ); - styleElement.innerHTML = innerHTML; -} diff --git a/blockbase/inc/customizer/wp-customize-fonts.php b/blockbase/inc/customizer/wp-customize-fonts.php index c2457292f2..86fdb68803 100644 --- a/blockbase/inc/customizer/wp-customize-fonts.php +++ b/blockbase/inc/customizer/wp-customize-fonts.php @@ -3,552 +3,178 @@ require_once( __DIR__ . '/wp-customize-global-styles-setting.php' ); require_once( __DIR__ . '/wp-customize-utils.php' ); -class GlobalStylesFontsCustomizer { - - private $section_key = 'customize-global-styles-fonts'; - - private $font_settings; - - private $font_control_default_body; - private $font_control_default_heading; - - //Not all fonts support v2 of the API that allows for the shorter URls - //list of supported fonts: https://fonts.google.com/variablefonts - private $fonts = array( - 'system-font' => array( - 'fontFamily' => '-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif', - 'slug' => 'system-font', - 'name' => 'System Font', - ), - 'arvo' => array( - 'fontFamily' => '"Arvo", serif', - 'slug' => 'arvo', - 'name' => 'Arvo', - 'google' => 'family=Arvo:ital,wght@0,400;0,700;1,400;1,700', - ), - 'bodoni-moda' => array( - 'fontFamily' => '"Bodoni Moda", serif', - 'slug' => 'bodoni-moda', - 'name' => 'Bodoni Moda', - 'google' => 'family=Bodoni+Moda:ital,wght@0,400..900;1,400..900', - ), - 'cabin' => array( - 'fontFamily' => '"Cabin", sans-serif', - 'slug' => 'cabin', - 'name' => 'Cabin', - 'google' => 'family=Cabin:ital,wght@0,400..700;1,400..700', - ), - 'chivo' => array( - 'fontFamily' => '"Chivo", sans-serif', - 'slug' => 'chivo', - 'name' => 'Chivo', - 'google' => 'family=Chivo:ital,wght@0,300;0,400;0,700;0,900;1,300;1,400;1,700;1,900', - ), - 'courier-prime' => array( - 'fontFamily' => '"Courier Prime", serif', - 'slug' => 'courier-prime', - 'name' => 'Courier Prime', - 'google' => 'family=Courier+Prime:ital,wght@0,400;0,700;1,400;1,700', - ), - 'dm-sans' => array( - 'fontFamily' => '"DM Sans", sans-serif', - 'slug' => 'dm-sans', - 'name' => 'DM Sans', - 'google' => 'family=DM+Sans:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700"', - ), - 'domine' => array( - 'fontFamily' => '"Domine", serif', - 'slug' => 'domine', - 'name' => 'Domine', - 'google' => 'family=Domine:wght@400..700', - ), - 'eb-garamond' => array( - 'fontFamily' => '"EB Garamond", serif', - 'slug' => 'eb-garamond', - 'name' => 'EB Garamond', - 'google' => 'family=EB+Garamond:ital,wght@0,400..800;1,400..800', - ), - 'fira-sans' => array( - 'fontFamily' => '"Fira Sans", sans-serif', - 'slug' => 'fira-sans', - 'name' => 'Fira Sans', - 'google' => 'family=Fira+Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900', - ), - 'ibm-plex-mono' => array( - 'fontFamily' => '"IBM Plex Mono", monospace', - 'slug' => 'ibm-plex-mono', - 'name' => 'IBM Plex Mono', - 'google' => 'family=IBM+Plex+Mono:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,400;1,500;1,600;1,700', - ), - 'inter' => array( - 'fontFamily' => '"Inter", sans-serif', - 'slug' => 'inter', - 'name' => 'Inter', - 'google' => 'family=Inter:wght@100..900', - ), - 'josefin-sans' => array( - 'fontFamily' => '"Josefin Sans", sans-serif', - 'slug' => 'josefin-sans', - 'name' => 'Josefin Sans', - 'google' => 'family=Josefin+Sans:ital,wght@0,100..700;1,100..700', - ), - 'libre-baskerville' => array( - 'fontFamily' => '"Libre Baskerville", serif', - 'slug' => 'libre-baskerville', - 'name' => 'Libre Baskerville', - 'google' => 'family=Libre+Baskerville:ital,wght@0,400;0,700;1,400', - ), - 'libre-franklin' => array( - 'fontFamily' => '"Libre Franklin", sans-serif', - 'slug' => 'libre-franklin', - 'name' => 'Libre Franklin', - 'google' => 'family=Libre+Franklin:ital,wght@0,100..900;1,100..900', - ), - 'lora' => array( - 'fontFamily' => '"Lora", serif', - 'slug' => 'lora', - 'name' => 'Lora', - 'google' => 'family=Lora:ital,wght@0,400..700;1,400..700', - ), - 'merriweather' => array( - 'fontFamily' => '"Merriweather", serif', - 'slug' => 'merriweather', - 'name' => 'Merriweather', - 'google' => 'family=Merriweather:ital,wght@0,300;0,400;0,700;0,900;1,300;1,400;1,700;1,900', - ), - 'montserrat' => array( - 'fontFamily' => '"Montserrat", sans-serif', - 'slug' => 'montserrat', - 'name' => 'Montserrat', - 'google' => 'family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900', - ), - 'nunito' => array( - 'fontFamily' => '"Nunito", sans-serif', - 'slug' => 'nunito', - 'name' => 'Nunito', - 'google' => 'family=Nunito:ital,wght@0,200;0,300;0,400;0,600;0,700;0,800;0,900;1,200;1,300;1,400;1,600;1,700;1,800;1,900', - ), - 'open-sans' => array( - 'fontFamily' => '"Open Sans", sans-serif', - 'slug' => 'open-sans', - 'name' => 'Open Sans', - 'google' => 'family=Open+Sans:ital,wght@0,300;0,400;0,600;0,700;0,800;1,300;1,400;1,600;1,700;1,800', - ), - 'overpass' => array( - 'fontFamily' => '"Overpass", sans-serif', - 'slug' => 'overpass', - 'name' => 'Overpass', - 'google' => 'family=Overpass:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900', - ), - 'playfair-display' => array( - 'fontFamily' => '"Playfair Display", serif', - 'slug' => 'playfair-display', - 'name' => 'Playfair Display', - 'google' => 'family=Playfair+Display:ital,wght@0,400..900;1,400..900', - ), - 'poppins' => array( - 'fontFamily' => '"Poppins", sans-serif', - 'slug' => 'poppins', - 'name' => 'Poppins', - 'google' => 'family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900', - ), - 'raleway' => array( - 'fontFamily' => '"Raleway", sans-serif', - 'slug' => 'raleway', - 'name' => 'Raleway', - 'google' => 'family=Raleway:ital,wght@0,100..900;1,100..900', - ), - 'red-hat-display' => array( - 'fontFamily' => '"Red Hat Display", sans-serif', - 'slug' => 'red-hat-display', - 'name' => 'Red Hat Display', - 'google' => 'family=Red+Hat+Display:ital,wght@0,400;0,500;0,700;0,900;1,400;1,500;1,700;1,900', - ), - 'roboto' => array( - 'fontFamily' => '"Roboto", sans-serif', - 'slug' => 'roboto', - 'name' => 'Roboto', - 'google' => 'family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,800;1,900', - ), - 'roboto-slab' => array( - 'fontFamily' => '"Roboto Slab", sans-serif', - 'slug' => 'roboto-slab', - 'name' => 'Roboto Slab', - 'google' => 'family=Roboto+Slab:wght@100..900', - ), - 'rubik' => array( - 'fontFamily' => '"Rubik", sans-serif', - 'slug' => 'rubik', - 'name' => 'Rubik', - 'google' => 'family=Rubik:ital,wght@0,300..900;1,300..900', - ), - 'source-sans-pro' => array( - 'fontFamily' => '"Source Sans Pro", sans-serif', - 'slug' => 'source-sans-pro', - 'name' => 'Source Sans Pro', - 'google' => 'family=Source+Sans+Pro:ital,wght@0,200;0,300;0,400;0,600;0,700;0,900;1,200;1,300;1,400;1,600;1,700;1,900', - ), - 'source-serif-pro' => array( - 'fontFamily' => '"Source Serif Pro", serif', - 'slug' => 'source-serif-pro', - 'name' => 'Source Serif Pro', - 'google' => 'family=Source+Serif+Pro:ital,wght@0,200;0,300;0,400;0,600;0,700;0,900;1,200;1,300;1,400;1,600;1,700;1,900', - ), - 'space-mono' => array( - 'fontFamily' => '"Space Mono", sans-serif', - 'slug' => 'space-mono', - 'name' => 'Space Mono', - 'google' => 'family=Space+Mono:ital,wght@0,400;0,700;1,400;1,700', - ), - 'work-sans' => array( - 'fontFamily' => '"Work Sans", sans-serif', - 'slug' => 'work-sans', - 'name' => 'Work Sans', - 'google' => 'family=Work+Sans:ital,wght@0,100..900;1,100..900', - ), - ); +// Use an early priority to migrate legacy font settings before registering Google Fonts in `blockbase_register_google_fonts`. +add_action( 'after_setup_theme', 'migrate_blockbase_custom_fonts', 0 ); - function __construct() { - add_action( 'customize_register', array( $this, 'initialize' ) ); - add_action( 'customize_preview_init', array( $this, 'handle_customize_preview_init' ) ); - add_action( 'customize_register', array( $this, 'enqueue_google_fonts' ) ); - add_action( 'customize_save_after', array( $this, 'handle_customize_save_after' ) ); - add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_control_js' ) ); +function migrate_blockbase_custom_fonts() { + // The data has already been transformed + if ( get_theme_mod( 'blockbase_legacy_font_settings' ) ) { + return; } - function handle_customize_preview_init( $wp_customize ) { - $this->update_font_settings( $wp_customize ); - $this->customize_preview_js( $wp_customize ); - $this->create_customization_style_element( $wp_customize ); - } + $font_settings = wp_get_global_settings( array( 'typography', 'fontFamilies' ) ); - function customize_preview_js( $wp_customize ) { - if ( $this->fonts && $this->font_settings ) { - wp_enqueue_script( 'customizer-preview-fonts', get_template_directory_uri() . '/inc/customizer/wp-customize-fonts-preview.js', array( 'customize-preview' ) ); - wp_localize_script( 'customizer-preview-fonts', 'googleFonts', $this->fonts ); - wp_localize_script( 'customizer-preview-fonts', 'fontSettings', $this->font_settings ); - } + // No Customizer font settings found. Mark as transformed and hide the Customizer UI for fonts. + if ( ! isset( $font_settings['custom'] ) || ! is_array( $font_settings['custom'] ) ) { + set_theme_mod( 'blockbase_legacy_font_settings', '[]' ); + return; } - function customize_control_js() { - if ( $this->font_control_default_body && $this->font_control_default_heading ) { - wp_enqueue_script( 'customizer-font-control', get_template_directory_uri() . '/inc/customizer/wp-customize-fonts-control.js', array( 'customize-controls' ), null, true ); - wp_localize_script( 'customizer-font-control', 'fontControlDefaultBody', array( $this->font_control_default_body ) ); - wp_localize_script( 'customizer-font-control', 'fontControlDefaultHeading', array( $this->font_control_default_heading ) ); + // Extract font slugs from legacy data structure + $heading_font_slug = ''; + $body_font_slug = ''; + foreach ( $font_settings['custom'] as $font_setting ) { + if ( strpos( $font_setting['slug'], 'heading' ) !== false ) { + $heading_font_slug = $font_setting['fontSlug']; } - } - - function enqueue_google_fonts() { - wp_enqueue_style( 'blockbase-google-fonts', $this->google_fonts_url(), array(), null ); - } - function create_customization_style_element( $wp_customize ) { - if ( $this->font_settings ) { - wp_enqueue_style( 'global-styles-fonts-customizations', ' ', array( 'global-styles' ) ); // This needs to load after global_styles, hence the dependency - $css = 'body {'; - $css .= '--wp--preset--font-family--body-font:' . $this->font_settings['body'] . ';'; - $css .= '--wp--preset--font-family--heading-font:' . $this->font_settings['heading'] . ';'; - $css .= '}'; - wp_add_inline_style( 'global-styles-fonts-customizations', $css ); + if ( strpos( $font_setting['slug'], 'body' ) !== false ) { + $body_font_slug = $font_setting['fontSlug']; } } - function update_font_settings( $wp_customize ) { - $body_setting = $wp_customize->get_setting( $this->section_key . 'body' ); - $heading_setting = $wp_customize->get_setting( $this->section_key . 'heading' ); - if ( $body_setting && $heading_setting ) { - $body_value = $body_setting->post_value(); - if ( $body_value ) { - $body_font_setting = $this->fonts[ $body_value ]; - $this->font_settings['body'] = $body_font_setting['fontFamily']; - } + // Get the user's global styles CPT id + $user_custom_post_type_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id(); + $global_styles_controller = new WP_REST_Global_Styles_Controller(); + $global_styles = fetch_global_styles( $user_custom_post_type_id, $global_styles_controller ); + $blockbase_legacy_font_settings = $global_styles->data['settings']['typography']['fontFamilies']['custom']; - $heading_value = $heading_setting->post_value(); - if ( $heading_value ) { - $heading_font_setting = $this->fonts[ $heading_value ]; - $this->font_settings['heading'] = $heading_font_setting['fontFamily']; - } - } - } - - function google_fonts_url() { - $font_families = array(); - foreach ( $this->fonts as $font ) { - if ( ! empty( $font['google'] ) ) { - $font_families[] = $font['google']; - } - } - $font_families[] = 'display=swap'; + // converts data to array (in some cases settings and styles are objects insted of arrays) + $new_settings = (array) $global_styles->data['settings']; + $new_styles = (array) $global_styles->data['styles']; - // Make a single request for the theme fonts. - return esc_url_raw( 'https://fonts.googleapis.com/css2?' . implode( '&', $font_families ) ); + // Set new typography settings + if ( isset( $new_settings['typography']['fontFamilies'] ) ) { + unset( $new_settings['typography']['fontFamilies'] ); } - function initialize( $wp_customize ) { - $theme = wp_get_theme(); - - //Add a Section to the Customizer for these bits - $wp_customize->add_section( - $this->section_key, + if ( $body_font_slug ) { + $new_styles = array_merge( + $new_styles, array( - 'capability' => 'edit_theme_options', - 'description' => sprintf( __( 'Font Customization for %1$s', 'blockbase' ), $theme->name ), - 'title' => __( 'Fonts', 'blockbase' ), + 'typography' => array( + 'fontFamily' => "var:preset|font-family|$body_font_slug", + ), ) ); + } - $merged_json = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data()->get_raw_data(); - $theme_font_families = $merged_json['settings']['typography']['fontFamilies']['theme']; - $body_font_default_array = array_filter( - $theme_font_families, - function( $font_family ) { - return 'body-font' === $font_family['slug']; - } - ); - $body_font_default = array_shift( $body_font_default_array ); - $heading_font_default_array = array_filter( - $theme_font_families, - function( $font_family ) { - return 'heading-font' === $font_family['slug']; - } + if ( $heading_font_slug ) { + $new_styles = array_merge( + $new_styles, + array( + 'blocks' => array( + 'core/post-title' => array( + 'typography' => array( + 'fontFamily' => "var:preset|font-family|$heading_font_slug", + ), + ), + 'core/heading' => array( + 'typography' => array( + 'fontFamily' => "var:preset|font-family|$heading_font_slug", + ), + ), + ), + ) ); - $heading_font_default = array_shift( $heading_font_default_array ); - - // See if the child theme has been updated. If not then show a notice. - if ( ! $body_font_default && ! $heading_font_default ) { - $wp_customize->add_control( - $this->section_key . '-v1-blockbase-format-notice', - array( - 'type' => 'hidden', - 'description' => '
-

' . __( 'Your theme needs to be updated before you can customize fonts', 'blockbase' ) . '

-
', - 'settings' => array(), - 'section' => $this->section_key, - ) - ); - - return; - } - - if ( array_key_exists( 'custom', $merged_json['settings']['typography']['fontFamilies'] ) ) { - $merged_font_families = $merged_json['settings']['typography']['fontFamilies']['custom']; - $body_font_selected_array = array_filter( - $merged_font_families, - function( $font_family ) { - return 'body-font' === $font_family['slug']; - } - ); - $body_font_selected = array_shift( $body_font_selected_array ); - - $heading_font_selected_array = array_filter( - $merged_font_families, - function( $font_family ) { - return 'heading-font' === $font_family['slug']; - } - ); - $heading_font_selected = array_shift( $heading_font_selected_array ); + } - // NOTE: This should be removed once Gutenberg 12.1 lands stably in all environments - } elseif ( array_key_exists( 'user', $merged_json['settings']['typography']['fontFamilies'] ) ) { - $merged_font_families = $merged_json['settings']['typography']['fontFamilies']['user']; + update_global_styles( $new_settings, $new_styles, $user_custom_post_type_id, $global_styles_controller ); - $body_font_selected_array = array_filter( - $merged_font_families, - function( $font_family ) { - return 'body-font' === $font_family['slug']; - } - ); - $body_font_selected = array_shift( $body_font_selected_array ); + set_theme_mod( 'blockbase_legacy_font_settings', json_encode( $blockbase_legacy_font_settings ) ); +} - $heading_font_selected_array = array_filter( - $merged_font_families, - function( $font_family ) { - return 'heading-font' === $font_family['slug']; - } - ); - $heading_font_selected = array_shift( $heading_font_selected_array ); - // End Gutenberg < 12.1 compatibility patch +/** + * Updates the global styles CPT. + * + * @param array $new_settings New global styles to update. + * @param array $new_styles New global styles settings to update. + * @param int $user_custom_post_type_id ID of global styles CPT. + * @param object $global_styles_controller Controller that handles REST requests for global styles. + * + * @return void + */ +function update_global_styles( $new_settings, $new_styles, $user_custom_post_type_id, $global_styles_controller ) { + $update_request = new WP_REST_Request( 'PUT', '/wp/v2/global-styles/' ); + $update_request->set_param( 'id', $user_custom_post_type_id ); + $update_request->set_param( 'settings', $new_settings ); + $update_request->set_param( 'styles', $new_styles ); + + $global_styles_controller->update_item( $update_request ); + delete_transient( 'global_styles' ); + delete_transient( 'global_styles_' . get_stylesheet() ); + delete_transient( 'gutenberg_global_styles' ); + delete_transient( 'gutenberg_global_styles_' . get_stylesheet() ); +} - } else { - $body_font_selected = $body_font_default; - $heading_font_selected = $heading_font_default; - } +/** + * Retrieves the global styles cpt. + * + * @param int $user_custom_post_type_id ID of global styles CPT. + * @param object $global_styles_controller Controller that handles REST requests for global styles. + * + * @return array + */ +function fetch_global_styles( $user_custom_post_type_id, $global_styles_controller ) { + $get_request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' ); + $get_request->set_param( 'id', $user_custom_post_type_id ); + $global_styles = $global_styles_controller->get_item( $get_request ); + + return $global_styles; +} - // If there's no selected font then the user is probably using the old format for font customization - if ( $body_font_selected && $heading_font_selected ) { - $body_font_selected_font_family = $body_font_selected['fontFamily']; - $body_font_selected_font_slug = $body_font_selected['fontSlug']; - $heading_font_selected_font_family = $heading_font_selected['fontFamily']; - $heading_font_selected_font_slug = $heading_font_selected['fontSlug']; - } else { - $body_font_selected_font_family = null; - $body_font_selected_font_slug = null; - $heading_font_selected_font_family = null; - $heading_font_selected_font_slug = null; - } +// --------- - $this->font_settings = array( - 'body' => $body_font_selected_font_family, - 'heading' => $heading_font_selected_font_family, - ); +class GlobalStylesFontsCustomizer { - // Add a reset button - $this->font_control_default_body = $body_font_default['fontSlug']; - $this->font_control_default_heading = $heading_font_default['fontSlug']; - $wp_customize->add_control( - $this->section_key . '-reset-button', - array( - 'type' => 'button', - 'settings' => array(), - 'section' => $this->section_key, - 'input_attrs' => array( - 'value' => __( 'Reset to Default', 'blockbase' ), - 'class' => 'button button-link', - ), - ) - ); + private $section_key = 'customize-global-styles-fonts'; - $this->add_setting_and_control( $wp_customize, 'body', __( 'Body font', 'blockbase' ), $body_font_default['fontSlug'], $body_font_selected_font_slug, 'sanitize_title' ); - $this->add_setting_and_control( $wp_customize, 'heading', __( 'Heading font', 'blockbase' ), $heading_font_default['fontSlug'], $heading_font_selected_font_slug, 'sanitize_title' ); + function __construct() { + add_action( 'customize_register', array( $this, 'init_deprecation_notice' ) ); } - function get_font_family( $array, $configuration ) { - $variable = get_settings_array( $array, $configuration ); - $slug = preg_replace( '/var\(--wp--preset--font-family--(.*)\)/', '$1', $variable ); - if ( ! isset( $this->fonts[ $slug ] ) ) { - $this->fonts[ $slug ] = $this->build_font_from_theme_data( $slug, $configuration ); + function generate_deprecation_message() { + if ( ! defined( 'GUTENBERG_VERSION' ) || version_compare( GUTENBERG_VERSION, '13.3', '<=' ) ) { + return __( 'Please activate or update Gutenberg to use the custom fonts feature.', 'blockbase' ); } - return $this->fonts[ $slug ]; - } - function build_font_from_theme_data( $slug, $configuration ) { - $new_font = array(); - $font_families = $configuration['settings']['typography']['fontFamilies']['theme']; - foreach ( $font_families as $font_family ) { - if ( $font_family['slug'] === $slug ) { - $new_font['fontFamily'] = $font_family['fontFamily']; - $new_font['name'] = $font_family['name']; - if ( ! empty( $font_family['google'] ) ) { - $new_font['google'] = $font_family['google']; - } - } - } - $new_font['slug'] = $slug; - return $new_font; + return sprintf( + __( 'Updating fonts for this theme is now even easier! Use the site editor to select and preview different font families. More information.', 'blockbase' ), + __('https://wordpress.com/support/custom-fonts/') + ); } - function add_setting_and_control( $wp_customize, $name, $label, $default, $user_value, $sanitize_callback ) { - $setting_name = $this->section_key . $name; - $global_styles_setting = new WP_Customize_Global_Styles_Setting( - $wp_customize, - $setting_name, + function init_deprecation_notice( $wp_customize ) { + $wp_customize->add_section( + $this->section_key, array( - 'default' => $default, - 'user_value' => $user_value, + 'capability' => 'edit_theme_options', + 'title' => __( 'Fonts', 'blockbase' ), ) ); - $wp_customize->add_setting( - $global_styles_setting, + + $wp_customize->add_control( + $this->section_key . '-v1-blockbase-font-deprecation-notice', array( - 'sanitize_callback' => $sanitize_callback, + 'type' => 'hidden', + 'description' => '
+

' . $this->generate_deprecation_message() . '

+
', + 'settings' => array(), + 'section' => $this->section_key, ) ); - $choices = array(); - foreach ( $this->fonts as $font_slug => $font_setting ) { - $choices[ $font_slug ] = $font_setting['name']; - } - $wp_customize->add_control( - $setting_name, + $this->section_key . '-site-editor-button', array( - 'section' => $this->section_key, - 'label' => $label, - 'type' => 'select', - 'choices' => $choices, + 'type' => 'hidden', + 'description' => sprintf( 'Use Site Editor', esc_url( admin_url( 'site-editor.php?styles=open' ) ) ), + 'settings' => array(), + 'section' => $this->section_key, ) ); - - // Update the setting to the dirty value. - // This is needed to preserve the settings when other Customizer settings change. - $dirty_value = $wp_customize->get_setting( $setting_name )->post_value(); - if ( ! empty( $dirty_value ) ) { - $wp_customize->get_setting( $setting_name )->user_value = $dirty_value; - } - } - - function handle_customize_save_after( $wp_customize ) { - $body_value = $wp_customize->get_setting( $this->section_key . 'body' )->value(); - $heading_value = $wp_customize->get_setting( $this->section_key . 'heading' )->value(); - - if ( ! isset( $body_value ) && ! isset( $heading_value ) ) { - return; - } - - $body_default = $wp_customize->get_setting( $this->section_key . 'body' )->default; - $heading_default = $wp_customize->get_setting( $this->section_key . 'heading' )->default; - - if ( ! isset( $body_value ) ) { - $body_value = $body_default; - } - - if ( ! isset( $heading_value ) ) { - $heading_value = $heading_default; - } - - $body_setting = $this->fonts[ $body_value ]; - $body_setting['name'] = 'Body (' . $body_setting['name'] . ')'; - $body_setting['fontSlug'] = $body_setting['slug']; - $body_setting['slug'] = 'body-font'; - - $heading_setting = $this->fonts[ $heading_value ]; - $heading_setting['name'] = 'Heading (' . $heading_setting['name'] . ')'; - $heading_setting['fontSlug'] = $heading_setting['slug']; - $heading_setting['slug'] = 'heading-font'; - - // Set up variables for the theme.json. - $font_families = array( - $body_setting, - $heading_setting, - ); - - $body_font_family_variable = 'var(--wp--preset--font-family--' . $body_setting['slug'] . ')'; - $heading_font_family_variable = 'var(--wp--preset--font-family--' . $heading_setting['slug'] . ')'; - - // Get the user's global styles CPT id - $user_custom_post_type_id = WP_Theme_JSON_Resolver_Gutenberg::get_user_global_styles_post_id(); - - // API request to get global styles - $get_request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' ); - $get_request->set_param( 'id', $user_custom_post_type_id ); - - $global_styles_controller = new Gutenberg_REST_Global_Styles_Controller(); - $global_styles = $global_styles_controller->get_item( $get_request ); - - // converts data to array (in some cases settings and styles are objects insted of arrays) - $new_settings = (array) $global_styles->data['settings']; - $new_styles = (array) $global_styles->data['styles']; - - // Set new typography settings - if ( $font_families ) { - $new_settings['typography']['fontFamilies']['custom'] = $font_families; - } - - // Add the updated global styles to the update request - $update_request = new WP_REST_Request( 'PUT', '/wp/v2/global-styles/' ); - $update_request->set_param( 'id', $user_custom_post_type_id ); - $update_request->set_param( 'settings', $new_settings ); - $update_request->set_param( 'styles', $new_styles ); - - // Update the theme.json with the new settings. - $updated_global_styles = $global_styles_controller->update_item( $update_request ); - delete_transient( 'global_styles' ); - delete_transient( 'global_styles_' . get_stylesheet() ); - delete_transient( 'gutenberg_global_styles' ); - delete_transient( 'gutenberg_global_styles_' . get_stylesheet() ); } - } new GlobalStylesFontsCustomizer; diff --git a/blockbase/vendor/autoload.php b/blockbase/vendor/autoload.php new file mode 100644 index 0000000000..34e531d230 --- /dev/null +++ b/blockbase/vendor/autoload.php @@ -0,0 +1,7 @@ + +Copyright (C) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + +Gnomovision version 69, Copyright (C) year name of author +Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. +This is free software, and you are welcome to redistribute it +under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in the program +`Gnomovision' (which makes passes at compilers) written by James Hacker. + +, 1 April 1989 +Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/blockbase/vendor/automattic/jetpack-google-fonts-provider/README.md b/blockbase/vendor/automattic/jetpack-google-fonts-provider/README.md new file mode 100644 index 0000000000..6e2fa6f983 --- /dev/null +++ b/blockbase/vendor/automattic/jetpack-google-fonts-provider/README.md @@ -0,0 +1,61 @@ +# Jetpack Google Fonts Provider Package + +WordPress Webfonts provider for Google Fonts + +## How to install google-fonts-provider + +Package is published in [Packagist](https://packagist.org/packages/automattic/jetpack-google-fonts-provider). We recommend using the latest version there. You can install it in a composer managed project with `composer require automattic/jetpack-google-fonts-provider`. + +You can also test with the latest development versions like below: + +```json +"require": { + "automattic/jetpack-google-fonts-provider": "dev-master" +} +``` + +## Usage + +The WordPress Webfonts API is available by activating the Gutenberg plugin and is planned to be included in WordPress 6.0. + +### Register the provider + +This package contains the provider class, but the provider needs to be registered before it can be used. + +```php +wp_register_webfont_provider( 'google-fonts', '\Automattic\Jetpack\Fonts\Google_Fonts_Provider' ); +``` + +### Register fonts + +After registering the provider, you can register any of the fonts available in the [Google Fonts catalog](https://fonts.google.com) to make them available for use in the block editor typography settings, Global styles, and your site's CSS. + +```php +wp_register_webfont( + array( + 'font-family' => 'Lato', + 'provider' => 'google-fonts', + ), +); +``` + +### Add preconnect link + +Adding a preconnect link to the `` of the page will help make sure the font files load as soon as possible, and reduce the layout shift when they are displayed. See [this list of webfont best practices](https://web.dev/font-best-practices/#preconnect-to-critical-third-party-origins) for more details. To do so, we can rely on WordPress' `wp_resource_hints` filter like so: + +```php +add_filter( 'wp_resource_hints', '\Automattic\Jetpack\Fonts\Utils::font_source_resource_hint', 10, 2 ); +``` + +### Additional info + +For a discussion about the Webfonts API in WordPress, see https://make.wordpress.org/core/2021/09/28/implementing-a-webfonts-api-in-wordpress-core/. + +## Security + +Need to report a security vulnerability? Go to [https://automattic.com/security/](https://automattic.com/security/) or directly to our security bug bounty site [https://hackerone.com/automattic](https://hackerone.com/automattic). + +## License + +Jetpack Google Fonts Provider is licensed under [GNU General Public License v2 (or later)](./LICENSE.txt) + diff --git a/blockbase/vendor/automattic/jetpack-google-fonts-provider/SECURITY.md b/blockbase/vendor/automattic/jetpack-google-fonts-provider/SECURITY.md new file mode 100644 index 0000000000..b4b46c0ee2 --- /dev/null +++ b/blockbase/vendor/automattic/jetpack-google-fonts-provider/SECURITY.md @@ -0,0 +1,38 @@ +# Security Policy + +Full details of the Automattic Security Policy can be found on [automattic.com](https://automattic.com/security/). + +## Supported Versions + +Generally, only the latest version of Jetpack has continued support. If a critical vulnerability is found in the current version of Jetpack, we may opt to backport any patches to previous versions. + +## Reporting a Vulnerability + +[Jetpack](https://jetpack.com/) is an open-source plugin for WordPress. Our HackerOne program covers the plugin software, as well as a variety of related projects and infrastructure. + +**For responsible disclosure of security issues and to be eligible for our bug bounty program, please submit your report via the [HackerOne](https://hackerone.com/automattic) portal.** + +Our most critical targets are: + +* Jetpack and the Jetpack composer packages (all within this repo) +* Jetpack.com -- the primary marketing site. +* cloud.jetpack.com -- a management site. +* wordpress.com -- the shared management site for both Jetpack and WordPress.com sites. + +For more targets, see the `In Scope` section on [HackerOne](https://hackerone.com/automattic). + +_Please note that the **WordPress software is a separate entity** from Automattic. Please report vulnerabilities for WordPress through [the WordPress Foundation's HackerOne page](https://hackerone.com/wordpress)._ + +## Guidelines + +We're committed to working with security researchers to resolve the vulnerabilities they discover. You can help us by following these guidelines: + +* Follow [HackerOne's disclosure guidelines](https://www.hackerone.com/disclosure-guidelines). +* Pen-testing Production: + * Please **setup a local environment** instead whenever possible. Most of our code is open source (see above). + * If that's not possible, **limit any data access/modification** to the bare minimum necessary to reproduce a PoC. + * **_Don't_ automate form submissions!** That's very annoying for us, because it adds extra work for the volunteers who manage those systems, and reduces the signal/noise ratio in our communication channels. + * To be eligible for a bounty, all of these guidelines must be followed. +* Be Patient - Give us a reasonable time to correct the issue before you disclose the vulnerability. + +We also expect you to comply with all applicable laws. You're responsible to pay any taxes associated with your bounties. diff --git a/blockbase/vendor/automattic/jetpack-google-fonts-provider/composer.json b/blockbase/vendor/automattic/jetpack-google-fonts-provider/composer.json new file mode 100644 index 0000000000..c765946e54 --- /dev/null +++ b/blockbase/vendor/automattic/jetpack-google-fonts-provider/composer.json @@ -0,0 +1,41 @@ +{ + "name": "automattic/jetpack-google-fonts-provider", + "description": "WordPress Webfonts provider for Google Fonts", + "type": "jetpack-library", + "license": "GPL-2.0-or-later", + "require": {}, + "require-dev": { + "yoast/phpunit-polyfills": "1.0.3", + "automattic/jetpack-changelogger": "^3.1", + "brain/monkey": "2.6.1" + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "scripts": { + "phpunit": [ + "./vendor/phpunit/phpunit/phpunit --colors=always" + ], + "test-coverage": [ + "php -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\"" + ], + "test-php": [ + "@composer phpunit" + ] + }, + "minimum-stability": "dev", + "prefer-stable": true, + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-google-fonts-provider", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-google-fonts-provider/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-master": "0.3.x-dev" + }, + "textdomain": "jetpack-google-fonts-provider" + } +} diff --git a/blockbase/vendor/automattic/jetpack-google-fonts-provider/src/class-google-fonts-provider.php b/blockbase/vendor/automattic/jetpack-google-fonts-provider/src/class-google-fonts-provider.php new file mode 100644 index 0000000000..c2006a54f3 --- /dev/null +++ b/blockbase/vendor/automattic/jetpack-google-fonts-provider/src/class-google-fonts-provider.php @@ -0,0 +1,359 @@ + + + get_remote_styles( $url ); + + /* + * Early return if the request failed. + * Cache an empty string for 60 seconds to avoid bottlenecks. + */ + if ( empty( $css ) ) { + \set_site_transient( $id, '', MINUTE_IN_SECONDS ); + return ''; + } + + // Cache the CSS for a month. + \set_site_transient( $id, $css, MONTH_IN_SECONDS ); + } + + return $css; + } + + /** + * Gets styles from the remote font service via the given URL. + * + * @param string $url The URL to fetch. + + * @return string The styles on success. Empty string on failure. + */ + protected function get_remote_styles( $url ) { + // Use a modern user-agent, to get woff2 files. + $args = array( 'user-agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0' ); + + // Get the remote URL contents. + $response = \wp_safe_remote_get( $url, $args ); + + // Early return if the request failed. + if ( \is_wp_error( $response ) || 200 !== \wp_remote_retrieve_response_code( $response ) ) { + return ''; + } + + // Get the response body. + return \wp_remote_retrieve_body( $response ); + } + + /** + * Gets the `@font-face` CSS styles for Google Fonts. + * + * This method does the following processing tasks: + * 1. Orchestrates an optimized Google Fonts API URL for each font-family. + * 2. Caches each URL, if not already cached. + * 3. Does a remote request to the Google Fonts API service to fetch the styles. + * 4. Generates the `@font-face` for all its webfonts. + * + * @return string The `@font-face` CSS. + */ + public function get_css() { + $css = ''; + $urls = $this->build_collection_api_urls(); + + foreach ( $urls as $url ) { + $css .= $this->get_cached_remote_styles( 'jetpack_google_fonts_' . md5( $url ), $url ); + } + + return $css; + } + + /** + * Builds the Google Fonts URL for a collection of webfonts. + * + * For example, if given the following webfonts: + * ``` + * array( + * array( + * 'font-family' => 'Source Serif Pro', + * 'font-style' => 'normal', + * 'font-weight' => '200 400', + * ), + * array( + * 'font-family' => 'Source Serif Pro', + * 'font-style' => 'italic', + * 'font-weight' => '400 600', + * ), + * ) + * ``` + * then the returned collection would be: + * ``` + * array( + * 'https://fonts.googleapis.com/css2?family=Source+Serif+Pro:ital,wght@0,200;0,300;0,400;1,400;1,500;1,600&display=fallback' + * ) + * ``` + * + * @return array Collection of font-family urls. + */ + private function build_collection_api_urls() { + $font_families_urls = array(); + + /* + * Iterate over each font-family group to build the Google Fonts API URL + * for that specific family. Each is added to the collection of URLs to be + * returned to the `get_css()` method for making the remote request. + */ + foreach ( $this->organize_webfonts() as $font_display => $font_families ) { + $url_parts = array(); + foreach ( $font_families as $font_family => $webfonts ) { + list( $normal_weights, $italic_weights ) = $this->collect_font_weights( $webfonts ); + + // Build the font-style with its font-weights. + $url_part = rawurlencode( $font_family ); + if ( empty( $italic_weights ) && ! empty( $normal_weights ) ) { + $url_part .= ':wght@' . implode( ';', $normal_weights ); + } elseif ( ! empty( $italic_weights ) && empty( $normal_weights ) ) { + $url_part .= ':ital,wght@1,' . implode( ';', $normal_weights ); + } elseif ( ! empty( $italic_weights ) && ! empty( $normal_weights ) ) { + $url_part .= ':ital,wght@0,' . implode( ';0,', $normal_weights ) . ';1,' . implode( ';1,', $italic_weights ); + } + + // Add it to the collection. + $url_parts[] = $url_part; + } + + // Build the URL for this font-family and add it to the collection. + $font_families_urls[] = $this->root_url . '?family=' . implode( '&family=', $url_parts ) . '&display=' . $font_display; + } + + return $font_families_urls; + } + + /** + * Organizes the webfonts by font-display and then font-family. + * + * To optimizing building the URL for the Google Fonts API request, + * this method organizes the webfonts first by font-display and then + * by font-family. + * + * For example, if given the following webfonts: + * ``` + * array( + * array( + * 'font-family' => 'Source Serif Pro', + * 'font-style' => 'normal', + * 'font-weight' => '200 400', + * ), + * array( + * 'font-family' => 'Source Serif Pro', + * 'font-style' => 'italic', + * 'font-weight' => '400 600', + * ), + * ) + * ``` + * then the returned collection would be: + * ``` + * array( + * 'fallback' => array( + * 'Source Serif Pro' => array( + * array( + * 'font-family' => 'Source Serif Pro', + * 'font-style' => 'normal', + * 'font-weight' => '200 400', + * ), + * array( + * 'font-family' => 'Source Serif Pro', + * 'font-style' => 'italic', + * 'font-weight' => '400 600', + * ), + * ), + * ), + * ) + * + * @return array[][] Webfonts organized by font-display and then font-family. + */ + private function organize_webfonts() { + $font_display_groups = array(); + + /* + * Group by font-display. + * Each font-display will need to be a separate request. + */ + foreach ( $this->webfonts as $webfont ) { + if ( ! isset( $font_display_groups[ $webfont['font-display'] ] ) ) { + $font_display_groups[ $webfont['font-display'] ] = array(); + } + $font_display_groups[ $webfont['font-display'] ][] = $webfont; + } + + /* + * Iterate over each font-display group and group by font-family. + * Multiple font-families can be combined in the same request, + * but their params need to be grouped. + */ + foreach ( $font_display_groups as $font_display => $font_display_group ) { + $font_families = array(); + + foreach ( $font_display_group as $webfont ) { + if ( ! isset( $font_families[ $webfont['font-family'] ] ) ) { + $font_families[ $webfont['font-family'] ] = array(); + } + $font_families[ $webfont['font-family'] ][] = $webfont; + } + + $font_display_groups[ $font_display ] = $font_families; + } + + return $font_display_groups; + } + + /** + * Collects all font-weights grouped by 'normal' and 'italic' font-style. + * + * For example, if given the following webfonts: + * ``` + * array( + * array( + * 'font-family' => 'Source Serif Pro', + * 'font-style' => 'normal', + * 'font-weight' => '200 400', + * ), + * array( + * 'font-family' => 'Source Serif Pro', + * 'font-style' => 'italic', + * 'font-weight' => '400 600', + * ), + * ) + * ``` + * Then the returned collection would be: + * ``` + * array( + * array( 200, 300, 400 ), + * array( 400, 500, 600 ), + * ) + * ``` + * + * @param array $webfonts Webfonts to process. + * @return array[] { + * The font-weights grouped by font-style. + * + * @type array $normal_weights Individual font-weight values for 'normal' font-style. + * @type array $italic_weights Individual font-weight values for 'italic' font-style. + * } + */ + private function collect_font_weights( array $webfonts ) { + $normal_weights = array(); + $italic_weights = array(); + + foreach ( $webfonts as $webfont ) { + $font_weights = $this->get_font_weights( $webfont['font-weight'] ); + // Skip this webfont if it does not have a font-weight defined. + if ( empty( $font_weights ) ) { + continue; + } + + // Add the individual font-weights to the end of font-style array. + if ( 'italic' === $webfont['font-style'] ) { + array_push( $italic_weights, ...$font_weights ); + } else { + array_push( $normal_weights, ...$font_weights ); + } + } + + // Remove duplicates. + $normal_weights = array_unique( $normal_weights ); + $italic_weights = array_unique( $italic_weights ); + + return array( $normal_weights, $italic_weights ); + } + + /** + * Converts the given string of font-weight into an array of individual weight values. + * + * When given a single font-weight, the value is wrapped into an array. + * + * A range of font-weights is specified as '400 600' with the lightest value first, + * a space, and then the heaviest value last. + * + * When given a range of font-weight values, the range is converted into individual + * font-weight values. For example, a range of '400 600' is converted into + * `array( 400, 500, 600 )`. + * + * @param string $font_weights The font-weights string. + * @return array The font-weights array. + */ + private function get_font_weights( $font_weights ) { + $font_weights = trim( $font_weights ); + + // A single font-weight. + if ( false === strpos( $font_weights, ' ' ) ) { + return array( $font_weights ); + } + + // Process a range of font-weight values that are delimited by ' '. + $font_weights = explode( ' ', $font_weights ); + + // If there are 2 values, treat them as a range. + if ( 2 === count( $font_weights ) ) { + $font_weights = range( (int) $font_weights[0], (int) $font_weights[1], 100 ); + } + + return $font_weights; + } +} diff --git a/blockbase/vendor/automattic/jetpack-google-fonts-provider/src/class-utils.php b/blockbase/vendor/automattic/jetpack-google-fonts-provider/src/class-utils.php new file mode 100644 index 0000000000..3ea69559de --- /dev/null +++ b/blockbase/vendor/automattic/jetpack-google-fonts-provider/src/class-utils.php @@ -0,0 +1,57 @@ + 'https://fonts.gstatic.com', + 'crossorigin', + ); + } + + return $urls; + } + + /** + * Check if a font family is registered (verifying that it can be enqueued). + * + * This function will not be needed if/when WP_Webfonts provides this functionality. + * + * @link https://github.com/WordPress/gutenberg/pull/39988 + * @link https://github.com/WordPress/gutenberg/blob/e94fffae0684aa5a6dc370ce3eba262cb77071d9/lib/experimental/class-wp-webfonts.php#L217 + * + * @param string $font_family_name Name of font family. + * @return boolean|void Whether the font family is registered, or void if WP_Webfonts is not available. + */ + public static function is_font_family_registered( $font_family_name ) { + if ( ! function_exists( 'wp_webfonts' ) || ! method_exists( 'WP_Webfonts', 'get_font_slug' ) ) { + return; + } + + $wp_webfonts = wp_webfonts(); + + $slug = \WP_Webfonts::get_font_slug( $font_family_name ); + + return isset( $wp_webfonts->get_registered_webfonts()[ $slug ] ); + } +} diff --git a/blockbase/vendor/automattic/jetpack-google-fonts-provider/src/introspectors/class-blocks.php b/blockbase/vendor/automattic/jetpack-google-fonts-provider/src/introspectors/class-blocks.php new file mode 100644 index 0000000000..f715bfdf0a --- /dev/null +++ b/blockbase/vendor/automattic/jetpack-google-fonts-provider/src/introspectors/class-blocks.php @@ -0,0 +1,37 @@ +.+)\)$/', $font_family, $matches ); + + if ( isset( $matches['slug'] ) ) { + return $matches['slug']; + } + + // Full string: var:preset|font-family|slug + // We do not care about the origin of the font, only its slug. + preg_match( '/font-family\|(?P.+)$/', $font_family, $matches ); + + if ( isset( $matches['slug'] ) ) { + return $matches['slug']; + } + + return $font_family; + } +} diff --git a/blockbase/vendor/composer/ClassLoader.php b/blockbase/vendor/composer/ClassLoader.php new file mode 100644 index 0000000000..afef3fa2ad --- /dev/null +++ b/blockbase/vendor/composer/ClassLoader.php @@ -0,0 +1,572 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier + * @author Jordi Boggiano + * @see https://www.php-fig.org/psr/psr-0/ + * @see https://www.php-fig.org/psr/psr-4/ + */ +class ClassLoader +{ + /** @var ?string */ + private $vendorDir; + + // PSR-4 + /** + * @var array[] + * @psalm-var array> + */ + private $prefixLengthsPsr4 = array(); + /** + * @var array[] + * @psalm-var array> + */ + private $prefixDirsPsr4 = array(); + /** + * @var array[] + * @psalm-var array + */ + private $fallbackDirsPsr4 = array(); + + // PSR-0 + /** + * @var array[] + * @psalm-var array> + */ + private $prefixesPsr0 = array(); + /** + * @var array[] + * @psalm-var array + */ + private $fallbackDirsPsr0 = array(); + + /** @var bool */ + private $useIncludePath = false; + + /** + * @var string[] + * @psalm-var array + */ + private $classMap = array(); + + /** @var bool */ + private $classMapAuthoritative = false; + + /** + * @var bool[] + * @psalm-var array + */ + private $missingClasses = array(); + + /** @var ?string */ + private $apcuPrefix; + + /** + * @var self[] + */ + private static $registeredLoaders = array(); + + /** + * @param ?string $vendorDir + */ + public function __construct($vendorDir = null) + { + $this->vendorDir = $vendorDir; + } + + /** + * @return string[] + */ + public function getPrefixes() + { + if (!empty($this->prefixesPsr0)) { + return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); + } + + return array(); + } + + /** + * @return array[] + * @psalm-return array> + */ + public function getPrefixesPsr4() + { + return $this->prefixDirsPsr4; + } + + /** + * @return array[] + * @psalm-return array + */ + public function getFallbackDirs() + { + return $this->fallbackDirsPsr0; + } + + /** + * @return array[] + * @psalm-return array + */ + public function getFallbackDirsPsr4() + { + return $this->fallbackDirsPsr4; + } + + /** + * @return string[] Array of classname => path + * @psalm-return array + */ + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param string[] $classMap Class to filename map + * @psalm-param array $classMap + * + * @return void + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, either + * appending or prepending to the ones previously set for this prefix. + * + * @param string $prefix The prefix + * @param string[]|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories + * + * @return void + */ + public function add($prefix, $paths, $prepend = false) + { + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + (array) $paths, + $this->fallbackDirsPsr0 + ); + } else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + (array) $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = (array) $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + (array) $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, either + * appending or prepending to the ones previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param string[]|string $paths The PSR-4 base directories + * @param bool $prepend Whether to prepend the directories + * + * @throws \InvalidArgumentException + * + * @return void + */ + public function addPsr4($prefix, $paths, $prepend = false) + { + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + (array) $paths, + $this->fallbackDirsPsr4 + ); + } else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + (array) $paths + ); + } + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + (array) $paths, + $this->prefixDirsPsr4[$prefix] + ); + } else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, + * replacing any others previously set for this prefix. + * + * @param string $prefix The prefix + * @param string[]|string $paths The PSR-0 base directories + * + * @return void + */ + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, + * replacing any others previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param string[]|string $paths The PSR-4 base directories + * + * @throws \InvalidArgumentException + * + * @return void + */ + public function setPsr4($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + * + * @return void + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Turns off searching the prefix and fallback directories for classes + * that have not been registered with the class map. + * + * @param bool $classMapAuthoritative + * + * @return void + */ + public function setClassMapAuthoritative($classMapAuthoritative) + { + $this->classMapAuthoritative = $classMapAuthoritative; + } + + /** + * Should class lookup fail if not found in the current class map? + * + * @return bool + */ + public function isClassMapAuthoritative() + { + return $this->classMapAuthoritative; + } + + /** + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. + * + * @param string|null $apcuPrefix + * + * @return void + */ + public function setApcuPrefix($apcuPrefix) + { + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; + } + + /** + * The APCu prefix in use, or null if APCu caching is not enabled. + * + * @return string|null + */ + public function getApcuPrefix() + { + return $this->apcuPrefix; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + * + * @return void + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + + if (null === $this->vendorDir) { + return; + } + + if ($prepend) { + self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders; + } else { + unset(self::$registeredLoaders[$this->vendorDir]); + self::$registeredLoaders[$this->vendorDir] = $this; + } + } + + /** + * Unregisters this instance as an autoloader. + * + * @return void + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + + if (null !== $this->vendorDir) { + unset(self::$registeredLoaders[$this->vendorDir]); + } + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return true|null True if loaded, null otherwise + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + includeFile($file); + + return true; + } + + return null; + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) + { + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { + return false; + } + if (null !== $this->apcuPrefix) { + $file = apcu_fetch($this->apcuPrefix.$class, $hit); + if ($hit) { + return $file; + } + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if (false === $file && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if (null !== $this->apcuPrefix) { + apcu_add($this->apcuPrefix.$class, $file); + } + + if (false === $file) { + // Remember that this class does not exist. + $this->missingClasses[$class] = true; + } + + return $file; + } + + /** + * Returns the currently registered loaders indexed by their corresponding vendor directories. + * + * @return self[] + */ + public static function getRegisteredLoaders() + { + return self::$registeredLoaders; + } + + /** + * @param string $class + * @param string $ext + * @return string|false + */ + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + $subPath = $class; + while (false !== $lastPos = strrpos($subPath, '\\')) { + $subPath = substr($subPath, 0, $lastPos); + $search = $subPath . '\\'; + if (isset($this->prefixDirsPsr4[$search])) { + $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); + foreach ($this->prefixDirsPsr4[$search] as $dir) { + if (file_exists($file = $dir . $pathEnd)) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + } else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + + return false; + } +} + +/** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + * + * @param string $file + * @return void + * @private + */ +function includeFile($file) +{ + include $file; +} diff --git a/blockbase/vendor/composer/InstalledVersions.php b/blockbase/vendor/composer/InstalledVersions.php new file mode 100644 index 0000000000..d50e0c9fcc --- /dev/null +++ b/blockbase/vendor/composer/InstalledVersions.php @@ -0,0 +1,350 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer; + +use Composer\Autoload\ClassLoader; +use Composer\Semver\VersionParser; + +/** + * This class is copied in every Composer installed project and available to all + * + * See also https://getcomposer.org/doc/07-runtime.md#installed-versions + * + * To require its presence, you can require `composer-runtime-api ^2.0` + */ +class InstalledVersions +{ + /** + * @var mixed[]|null + * @psalm-var array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array}|array{}|null + */ + private static $installed; + + /** + * @var bool|null + */ + private static $canGetVendors; + + /** + * @var array[] + * @psalm-var array}> + */ + private static $installedByVendor = array(); + + /** + * Returns a list of all package names which are present, either by being installed, replaced or provided + * + * @return string[] + * @psalm-return list + */ + public static function getInstalledPackages() + { + $packages = array(); + foreach (self::getInstalled() as $installed) { + $packages[] = array_keys($installed['versions']); + } + + if (1 === \count($packages)) { + return $packages[0]; + } + + return array_keys(array_flip(\call_user_func_array('array_merge', $packages))); + } + + /** + * Returns a list of all package names with a specific type e.g. 'library' + * + * @param string $type + * @return string[] + * @psalm-return list + */ + public static function getInstalledPackagesByType($type) + { + $packagesByType = array(); + + foreach (self::getInstalled() as $installed) { + foreach ($installed['versions'] as $name => $package) { + if (isset($package['type']) && $package['type'] === $type) { + $packagesByType[] = $name; + } + } + } + + return $packagesByType; + } + + /** + * Checks whether the given package is installed + * + * This also returns true if the package name is provided or replaced by another package + * + * @param string $packageName + * @param bool $includeDevRequirements + * @return bool + */ + public static function isInstalled($packageName, $includeDevRequirements = true) + { + foreach (self::getInstalled() as $installed) { + if (isset($installed['versions'][$packageName])) { + return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']); + } + } + + return false; + } + + /** + * Checks whether the given package satisfies a version constraint + * + * e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call: + * + * Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3') + * + * @param VersionParser $parser Install composer/semver to have access to this class and functionality + * @param string $packageName + * @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package + * @return bool + */ + public static function satisfies(VersionParser $parser, $packageName, $constraint) + { + $constraint = $parser->parseConstraints($constraint); + $provided = $parser->parseConstraints(self::getVersionRanges($packageName)); + + return $provided->matches($constraint); + } + + /** + * Returns a version constraint representing all the range(s) which are installed for a given package + * + * It is easier to use this via isInstalled() with the $constraint argument if you need to check + * whether a given version of a package is installed, and not just whether it exists + * + * @param string $packageName + * @return string Version constraint usable with composer/semver + */ + public static function getVersionRanges($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + $ranges = array(); + if (isset($installed['versions'][$packageName]['pretty_version'])) { + $ranges[] = $installed['versions'][$packageName]['pretty_version']; + } + if (array_key_exists('aliases', $installed['versions'][$packageName])) { + $ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']); + } + if (array_key_exists('replaced', $installed['versions'][$packageName])) { + $ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']); + } + if (array_key_exists('provided', $installed['versions'][$packageName])) { + $ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']); + } + + return implode(' || ', $ranges); + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present + */ + public static function getVersion($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + if (!isset($installed['versions'][$packageName]['version'])) { + return null; + } + + return $installed['versions'][$packageName]['version']; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present + */ + public static function getPrettyVersion($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + if (!isset($installed['versions'][$packageName]['pretty_version'])) { + return null; + } + + return $installed['versions'][$packageName]['pretty_version']; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference + */ + public static function getReference($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + if (!isset($installed['versions'][$packageName]['reference'])) { + return null; + } + + return $installed['versions'][$packageName]['reference']; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path. + */ + public static function getInstallPath($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @return array + * @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string} + */ + public static function getRootPackage() + { + $installed = self::getInstalled(); + + return $installed[0]['root']; + } + + /** + * Returns the raw installed.php data for custom implementations + * + * @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect. + * @return array[] + * @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array} + */ + public static function getRawData() + { + @trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED); + + if (null === self::$installed) { + // only require the installed.php file if this file is loaded from its dumped location, + // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 + if (substr(__DIR__, -8, 1) !== 'C') { + self::$installed = include __DIR__ . '/installed.php'; + } else { + self::$installed = array(); + } + } + + return self::$installed; + } + + /** + * Returns the raw data of all installed.php which are currently loaded for custom implementations + * + * @return array[] + * @psalm-return list}> + */ + public static function getAllRawData() + { + return self::getInstalled(); + } + + /** + * Lets you reload the static array from another file + * + * This is only useful for complex integrations in which a project needs to use + * this class but then also needs to execute another project's autoloader in process, + * and wants to ensure both projects have access to their version of installed.php. + * + * A typical case would be PHPUnit, where it would need to make sure it reads all + * the data it needs from this class, then call reload() with + * `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure + * the project in which it runs can then also use this class safely, without + * interference between PHPUnit's dependencies and the project's dependencies. + * + * @param array[] $data A vendor/composer/installed.php data set + * @return void + * + * @psalm-param array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array} $data + */ + public static function reload($data) + { + self::$installed = $data; + self::$installedByVendor = array(); + } + + /** + * @return array[] + * @psalm-return list}> + */ + private static function getInstalled() + { + if (null === self::$canGetVendors) { + self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders'); + } + + $installed = array(); + + if (self::$canGetVendors) { + foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) { + if (isset(self::$installedByVendor[$vendorDir])) { + $installed[] = self::$installedByVendor[$vendorDir]; + } elseif (is_file($vendorDir.'/composer/installed.php')) { + $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php'; + if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { + self::$installed = $installed[count($installed) - 1]; + } + } + } + } + + if (null === self::$installed) { + // only require the installed.php file if this file is loaded from its dumped location, + // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 + if (substr(__DIR__, -8, 1) !== 'C') { + self::$installed = require __DIR__ . '/installed.php'; + } else { + self::$installed = array(); + } + } + $installed[] = self::$installed; + + return $installed; + } +} diff --git a/blockbase/vendor/composer/LICENSE b/blockbase/vendor/composer/LICENSE new file mode 100644 index 0000000000..f27399a042 --- /dev/null +++ b/blockbase/vendor/composer/LICENSE @@ -0,0 +1,21 @@ + +Copyright (c) Nils Adermann, Jordi Boggiano + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/blockbase/vendor/composer/autoload_classmap.php b/blockbase/vendor/composer/autoload_classmap.php new file mode 100644 index 0000000000..63bb56a6a4 --- /dev/null +++ b/blockbase/vendor/composer/autoload_classmap.php @@ -0,0 +1,14 @@ + $vendorDir . '/automattic/jetpack-google-fonts-provider/src/class-google-fonts-provider.php', + 'Automattic\\Jetpack\\Fonts\\Introspectors\\Blocks' => $vendorDir . '/automattic/jetpack-google-fonts-provider/src/introspectors/class-blocks.php', + 'Automattic\\Jetpack\\Fonts\\Introspectors\\Global_Styles' => $vendorDir . '/automattic/jetpack-google-fonts-provider/src/introspectors/class-global-styles.php', + 'Automattic\\Jetpack\\Fonts\\Utils' => $vendorDir . '/automattic/jetpack-google-fonts-provider/src/class-utils.php', + 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', +); diff --git a/blockbase/vendor/composer/autoload_namespaces.php b/blockbase/vendor/composer/autoload_namespaces.php new file mode 100644 index 0000000000..b7fc0125db --- /dev/null +++ b/blockbase/vendor/composer/autoload_namespaces.php @@ -0,0 +1,9 @@ += 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); + if ($useStaticLoader) { + require __DIR__ . '/autoload_static.php'; + + call_user_func(\Composer\Autoload\ComposerStaticInit0777abd23b9615aca0bf30e3e2b460bb::getInitializer($loader)); + } else { + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } + + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + } + + $loader->register(true); + + return $loader; + } +} diff --git a/blockbase/vendor/composer/autoload_static.php b/blockbase/vendor/composer/autoload_static.php new file mode 100644 index 0000000000..dd682563a7 --- /dev/null +++ b/blockbase/vendor/composer/autoload_static.php @@ -0,0 +1,24 @@ + __DIR__ . '/..' . '/automattic/jetpack-google-fonts-provider/src/class-google-fonts-provider.php', + 'Automattic\\Jetpack\\Fonts\\Introspectors\\Blocks' => __DIR__ . '/..' . '/automattic/jetpack-google-fonts-provider/src/introspectors/class-blocks.php', + 'Automattic\\Jetpack\\Fonts\\Introspectors\\Global_Styles' => __DIR__ . '/..' . '/automattic/jetpack-google-fonts-provider/src/introspectors/class-global-styles.php', + 'Automattic\\Jetpack\\Fonts\\Utils' => __DIR__ . '/..' . '/automattic/jetpack-google-fonts-provider/src/class-utils.php', + 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + $loader->classMap = ComposerStaticInit0777abd23b9615aca0bf30e3e2b460bb::$classMap; + + }, null, ClassLoader::class); + } +} diff --git a/blockbase/vendor/composer/installed.json b/blockbase/vendor/composer/installed.json new file mode 100644 index 0000000000..e5d0938a13 --- /dev/null +++ b/blockbase/vendor/composer/installed.json @@ -0,0 +1,55 @@ +{ + "packages": [ + { + "name": "automattic/jetpack-google-fonts-provider", + "version": "v0.3.0", + "version_normalized": "0.3.0.0", + "source": { + "type": "git", + "url": "https://github.com/Automattic/jetpack-google-fonts-provider.git", + "reference": "cc26c71d0156bcdce80552cb7f084c23b5fe7be4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Automattic/jetpack-google-fonts-provider/zipball/cc26c71d0156bcdce80552cb7f084c23b5fe7be4", + "reference": "cc26c71d0156bcdce80552cb7f084c23b5fe7be4", + "shasum": "" + }, + "require-dev": { + "automattic/jetpack-changelogger": "^3.1", + "brain/monkey": "2.6.1", + "yoast/phpunit-polyfills": "1.0.3" + }, + "time": "2022-04-26T14:33:32+00:00", + "type": "jetpack-library", + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-google-fonts-provider", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-google-fonts-provider/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-master": "0.3.x-dev" + }, + "textdomain": "jetpack-google-fonts-provider" + }, + "installation-source": "dist", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "WordPress Webfonts provider for Google Fonts", + "support": { + "source": "https://github.com/Automattic/jetpack-google-fonts-provider/tree/v0.3.0" + }, + "install-path": "../automattic/jetpack-google-fonts-provider" + } + ], + "dev": true, + "dev-package-names": [] +} diff --git a/blockbase/vendor/composer/installed.php b/blockbase/vendor/composer/installed.php new file mode 100644 index 0000000000..26a47beedb --- /dev/null +++ b/blockbase/vendor/composer/installed.php @@ -0,0 +1,32 @@ + array( + 'pretty_version' => 'dev-trunk', + 'version' => 'dev-trunk', + 'type' => 'project', + 'install_path' => __DIR__ . '/../../', + 'aliases' => array(), + 'reference' => '090426a9c2af3d685443c079e5e3368550a4d51c', + 'name' => 'automattic/blockbase', + 'dev' => true, + ), + 'versions' => array( + 'automattic/blockbase' => array( + 'pretty_version' => 'dev-trunk', + 'version' => 'dev-trunk', + 'type' => 'project', + 'install_path' => __DIR__ . '/../../', + 'aliases' => array(), + 'reference' => '090426a9c2af3d685443c079e5e3368550a4d51c', + 'dev_requirement' => false, + ), + 'automattic/jetpack-google-fonts-provider' => array( + 'pretty_version' => 'v0.3.0', + 'version' => '0.3.0.0', + 'type' => 'jetpack-library', + 'install_path' => __DIR__ . '/../automattic/jetpack-google-fonts-provider', + 'aliases' => array(), + 'reference' => 'cc26c71d0156bcdce80552cb7f084c23b5fe7be4', + 'dev_requirement' => false, + ), + ), +); diff --git a/meraki/theme.json b/meraki/theme.json index 80f5b85da6..36a6f13bd1 100644 --- a/meraki/theme.json +++ b/meraki/theme.json @@ -61,7 +61,7 @@ }, { "fontFamily": "Jost, sans-serif", - "slug": "heading-font", + "slug": "jost", "name": "Headings (Jost)", "fontFace": [ { @@ -140,7 +140,7 @@ }, "core/navigation-link": { "typography": { - "fontFamily": "var(--wp--preset--font-family--heading-font)", + "fontFamily": "var(--wp--preset--font-family--jost)", "letterSpacing": "0.05em", "fontSize": "var(--wp--preset--font-size--tiny)", "textTransform": "uppercase" @@ -166,7 +166,7 @@ }, "core/site-tagline": { "typography": { - "fontFamily": "var(--wp--preset--font-family--heading-font)", + "fontFamily": "var(--wp--preset--font-family--jost)", "fontSize": "var(--wp--preset--font-size--small)" } }