Add upstream

This commit is contained in:
root
2019-10-24 00:12:05 +02:00
parent 85d41e4216
commit ac980f592c
3504 changed files with 1049983 additions and 29971 deletions

View File

@@ -0,0 +1,62 @@
<?php
class Jetpack_PWA_Helpers {
public static function get_default_manifest_icon_sizes() {
// These icon sizes based on conversation here:
// https://github.com/GoogleChrome/lighthouse/issues/291
return array(
192,
512,
);
}
public static function site_icon_url( $size = 512 ) {
$url = get_site_icon_url( $size );
// Fall back to built-in WordPress icon
if ( ! $url && in_array( $size, self::get_default_manifest_icon_sizes() ) ) {
$url = esc_url_raw(
plugins_url( "modules/pwa/images/wp-$size.png", JETPACK__PLUGIN_FILE )
);
}
return $url;
}
public static function get_theme_color() {
$theme_color = false;
// if we have AMP enabled, use those colors?
if ( class_exists( 'AMP_Customizer_Settings' ) ) {
/* This filter is documented in wp-content/plugins/amp/includes/class-amp-post-template.php */
$amp_settings = apply_filters(
'amp_post_template_customizer_settings',
AMP_Customizer_Settings::get_settings(),
null
);
if ( isset( $amp_settings['header_background_color'] ) ) {
$theme_color = $amp_settings['header_background_color'];
}
}
if ( ! $theme_color && current_theme_supports( 'custom-background' ) ) {
$background_color = get_background_color(); // Returns hex key without hash or empty string
if ( $background_color ) {
$theme_color = "#$background_color";
}
}
if ( ! $theme_color ) {
$theme_color = '#fff';
}
/**
* Allows overriding the PWA theme color which is used when loading the app.
*
* @since 5.6.0
*
* @param string $theme_color
*/
return apply_filters( 'jetpack_pwa_background_color', $theme_color );
}
}

View File

@@ -0,0 +1,95 @@
<?php
class Jetpack_PWA_Manifest {
/**
* @var Jetpack_PWA_Manifest
*/
private static $__instance = null;
/**
* When this query var is present, display the PWA manifest.
*
* @var string
*/
const PWA_MANIFEST_QUERY_VAR = 'jetpack_app_manifest';
/**
* Singleton implementation
*
* @return Jetpack_PWA_Manifest
*/
public static function instance() {
if ( is_null( self::$__instance ) ) {
self::$__instance = new Jetpack_PWA_Manifest;
}
return self::$__instance;
}
/**
* Registers actions the first time that instance() is called.
*/
private function __construct() {
add_action( 'wp_head', array( $this, 'render_manifest_link' ) );
add_action( 'amp_post_template_head', array( $this, 'render_manifest_link' ) );
add_action( 'template_redirect', array( $this, 'render_manifest_json' ), 2 );
}
function render_manifest_link() {
?>
<link rel="manifest" href="<?php echo esc_url_raw( $this->get_manifest_url() ); ?>">
<meta name="theme-color" content="<?php echo esc_attr( Jetpack_PWA_Helpers::get_theme_color() ); ?>">
<?php
}
public function get_manifest_url() {
return add_query_arg(
self::PWA_MANIFEST_QUERY_VAR, '1', home_url()
);
}
function render_manifest_json() {
// Do not load manifest in multiple locations
if ( is_front_page() && isset( $_GET[ self::PWA_MANIFEST_QUERY_VAR ] ) && $_GET[ self::PWA_MANIFEST_QUERY_VAR ] ) {
@ini_set( 'display_errors', false ); // Display errors can cause the XML to be not well formed.
$theme_color = Jetpack_PWA_Helpers::get_theme_color();
$manifest = array(
'name' => get_bloginfo( 'name' ),
'start_url' => get_home_url(),
'short_name' => substr( get_bloginfo( 'name' ), 0, 12 ),
'display' => 'standalone',
'background_color' => $theme_color,
'theme_color' => $theme_color,
);
if ( $description = get_bloginfo( 'description' ) ) {
$manifest['description'] = $description;
}
$manifest['icons'] = array_map(
array( $this, 'build_icon_object' ),
Jetpack_PWA_Helpers::get_default_manifest_icon_sizes()
);
/**
* Allow overriding the manifest.
*
* @since 5.6.0
*
* @param array $manifest
*/
$manifest = apply_filters( 'jetpack_pwa_manifest', $manifest );
wp_send_json( $manifest );
}
}
function build_icon_object( $size ) {
return array(
'src' => Jetpack_PWA_Helpers::site_icon_url( $size ),
'sizes' => sprintf( '%1$dx%1$d', $size ),
);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB