Skip to content

Commit

Permalink
Updates to 15.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoast committed Apr 24, 2024
1 parent 3934d4d commit 2f048ec
Show file tree
Hide file tree
Showing 199 changed files with 25,467 additions and 0 deletions.
104 changes: 104 additions & 0 deletions classes/admin/class-admin-help-panel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/

/**
* Generates the HTML for an inline Help Button and Panel.
*/
class WPSEO_Local_Admin_Help_Panel {

/**
* Unique identifier of the element the inline help refers to, used as an identifier in the html.
*
* @var string
*/
private $id;

/**
* The Help Button text. Needs a properly escaped string.
*
* @var string
*/
private $help_button_text;

/**
* The Help Panel content. Needs a properly escaped string (might contain HTML).
*
* @var string
*/
private $help_content;

/**
* Optional Whether to print out a container div element for the Help Panel, used for styling.
*
* @var string
*/
private $wrapper;

/**
* Constructor.
*
* @param string $id Unique identifier of the element the inline help refers to, used as
* an identifier in the html.
* @param string $help_button_text The Help Button text. Needs a properly escaped string.
* @param string $help_content The Help Panel content. Needs a properly escaped string (might contain HTML).
* @param string $wrapper Optional Whether to print out a container div element for the Help Panel,
* used for styling.
* Pass a `has-wrapper` value to print out the container. Default: no container.
*/
public function __construct( $id, $help_button_text, $help_content, $wrapper = '' ) {
$this->id = $id;
$this->help_button_text = $help_button_text;
$this->help_content = $help_content;
$this->wrapper = $wrapper;
}

/**
* Returns the html for the Help Button.
*
* @return string
*/
public function get_button_html() {

if ( ! $this->id || ! $this->help_button_text || ! $this->help_content ) {
return '';
}

return sprintf(
' <button type="button" class="yoast_help yoast-help-button dashicons" id="%1$s-help-toggle" aria-expanded="false" aria-controls="%1$s-help"><span class="yoast-help-icon" aria-hidden="true"></span><span class="screen-reader-text">%2$s</span></button>',
esc_attr( $this->id ),
$this->help_button_text
);
}

/**
* Returns the html for the Help Panel.
*
* @return string
*/
public function get_panel_html() {

if ( ! $this->id || ! $this->help_button_text || ! $this->help_content ) {
return '';
}

$wrapper_start = '';
$wrapper_end = '';

if ( $this->wrapper === 'has-wrapper' ) {
$wrapper_start = '<div class="yoast-seo-help-container">';
$wrapper_end = '</div>';
}

return sprintf(
'%1$s<p id="%2$s-help" class="yoast-help-panel">%3$s</p>%4$s',
$wrapper_start,
esc_attr( $this->id ),
$this->help_content,
$wrapper_end
);
}
}
259 changes: 259 additions & 0 deletions classes/admin/class-admin-local-assets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
<?php
/**
* Yoast SEO: Local plugin file.
*
* @package WPSEO_Local\Admin
*/

use Yoast\WP\Local\Repositories\Api_Keys_Repository;

/**
* This class holds the assets for Yoast Local SEO.
*/
class WPSEO_Local_Admin_Assets extends WPSEO_Admin_Asset_Manager {

/**
* Prefix for naming the assets.
*
* @var string
*/
public const PREFIX = 'wp-seo-local-';

/**
* Child constructor for WPSEO_Local_Admin_Assets
*/
public function __construct() {
parent::__construct( new WPSEO_Admin_Asset_SEO_Location( WPSEO_LOCAL_FILE ), self::PREFIX );
}

/**
* Returns the scripts that need to be registered.
*
* @return array Scripts that need to be registered.
*/
protected function scripts_to_be_registered() {
$flat_version = $this->flatten_version( WPSEO_LOCAL_VERSION );

$scripts = $this->load_select2_scripts();

$scripts['commons-bundle'] = [
'name' => 'commons-bundle',
'src' => self::PREFIX . 'vendor-' . $flat_version,
'deps' => [ 'react', 'react-dom' ],
];
$scripts['frontend'] = [
'name' => 'frontend',
'src' => self::PREFIX . 'frontend-' . $flat_version,
'deps' => [ 'jquery', self::PREFIX . 'commons-bundle' ],
];
$scripts['google-maps'] = [
'name' => 'google-maps',
'src' => $this->get_google_maps_url(),
'in_footer' => true,
'deps' => [ 'jquery', self::PREFIX . 'commons-bundle', self::PREFIX . 'frontend' ],
];
$scripts['seo-locations'] = [
'name' => 'seo-locations',
'src' => self::PREFIX . 'analysis-locations-' . $flat_version,
'in_footer' => true,
];
$scripts['seo-pages'] = [
'name' => 'seo-pages',
'src' => self::PREFIX . 'analysis-pages-' . $flat_version,
'in_footer' => true,
];
$scripts['global-script'] = [
'name' => 'global-script',
'src' => self::PREFIX . 'global-' . $flat_version,
'deps' => [ 'jquery', self::PREFIX . 'commons-bundle' ],
'in_footer' => true,
];
$scripts['geocoding-repository'] = [
'name' => 'geocoding-repository',
'src' => self::PREFIX . 'geocoding-repository-' . $flat_version,
'deps' => [ 'jquery', self::PREFIX . 'commons-bundle' ],
'in_footer' => true,
];
$scripts['locations'] = [
'name' => 'locations',
'src' => self::PREFIX . 'locations-' . $flat_version,
'deps' => [ 'wp-polyfill' ],
'in_footer' => true,
];
$scripts['location-settings'] = [
'name' => 'location-settings',
'src' => self::PREFIX . 'location-settings-' . $flat_version,
'version' => WPSEO_LOCAL_VERSION,
'deps' => [
'wp-polyfill',
'wp-element',
'wp-i18n',
'yoast-seo-editor-modules',
],
'in_footer' => true,
];
$scripts['store-locator'] = [
'name' => 'store-locator',
'src' => self::PREFIX . 'store-locator-' . $flat_version,
'deps' => [ 'wp-polyfill' ],
'in_footer' => true,
];
$scripts['checkout'] = [
'name' => 'checkout',
'src' => self::PREFIX . 'checkout-' . $flat_version,
'deps' => [ 'jquery' ],
];
$scripts['hipping-settings'] = [
'name' => 'shipping-settings',
'src' => self::PREFIX . 'shipping-settings-' . $flat_version,
'deps' => [ 'jquery' ],
];
$scripts['settings'] = [
'name' => 'settings',
'src' => self::PREFIX . 'settings-' . $flat_version,
'deps' => [ WPSEO_Admin_Asset_Manager::PREFIX . 'settings' ],
];
$scripts['blocks'] = [
'name' => 'blocks',
'src' => self::PREFIX . 'blocks-' . $flat_version,
'deps' => [ 'wp-blocks', 'wp-i18n', 'wp-element', 'react', 'react-dom' ],
];

return $scripts;
}

/**
* Returns the styles that need to be registered.
*
* @todo Data format is not self-documenting. Needs explanation inline. R.
*
* @return array Styles that need to be registered.
*/
protected function styles_to_be_registered() {
$flat_version = $this->flatten_version( WPSEO_LOCAL_VERSION );

return [
[
'name' => 'admin-css',
'src' => 'admin-' . $flat_version,
'rtl' => false,
],
[
'name' => 'select2',
'src' => 'select2/select2',
'suffix' => '.min',
'version' => '4.0.13',
'rtl' => false,
],
];
}

/**
* Get the Google Maps external library URL.
*
* @return string
*/
private function get_google_maps_url() {
$google_maps_url = 'https://maps.google.com/maps/api/js';
$api_repository = new Api_Keys_Repository();
$api_repository->initialize();

$api_key = $api_repository->get_api_key( 'browser' );
$query_args = [];
if ( ! empty( $api_key ) ) {
$query_args['key'] = $api_key;
}
$query_args['callback'] = 'wpseo_map_init';

// Load Maps API script.
$locale = get_locale();
$locale = explode( '_', $locale );

$multi_country_locales = [
'en',
'de',
'es',
'it',
'pt',
'ro',
'ru',
'sv',
'nl',
'zh',
'fr',
];

// Check if it might be a language spoken in more than one country.
if ( isset( $locale[1] ) && in_array( $locale[0], $multi_country_locales, true ) ) {
$language = $locale[0] . '-' . $locale[1];
}

if ( ! isset( $language ) ) {
$language = ( $locale[1] ?? $locale[0] );
}

if ( isset( $language ) ) {
$query_args['language'] = esc_attr( strtolower( $language ) );
}

if ( ! empty( $query_args ) ) {
$google_maps_url = add_query_arg( $query_args, $google_maps_url );
}

return $google_maps_url;
}

/**
* Loads the select2 scripts.
*
* @return array {
* The scripts to be registered.
*
* @type string $name The name of the asset.
* @type string $src The src of the asset.
* @type string[] $deps The dependenies of the asset.
* @type bool $in_footer Whether or not the asset should be in the footer.
* }
*/
protected function load_select2_scripts() {
$scripts = [];
$select2_language = 'en';
$user_locale = get_user_locale();
$language = WPSEO_Language_Utils::get_language( $user_locale );

if ( file_exists( WPSEO_LOCAL_PATH . "js/dist/select2/i18n/{$user_locale}.js" ) ) {
$select2_language = $user_locale; // Chinese and some others useful locale.
}
elseif ( file_exists( WPSEO_LOCAL_PATH . "js/dist/select2/i18n/{$language}.js" ) ) {
$select2_language = $language;
}

$scripts['select2'] = [
'name' => 'select2',
'src' => false,
'deps' => [
self::PREFIX . 'select2-translations',
self::PREFIX . 'select2-core',
],
];
$scripts['select2-core'] = [
'name' => 'select2-core',
'src' => 'select2/select2.full.min',
'deps' => [
'jquery',
],
'version' => '4.0.13',
];
$scripts['select2-translations'] = [
'name' => 'select2-translations',
'src' => 'select2/i18n/' . $select2_language,
'deps' => [
'jquery',
self::PREFIX . 'select2-core',
],
'version' => '4.0.13',
];

return $scripts;
}
}
Loading

0 comments on commit 2f048ec

Please sign in to comment.