This commit is contained in:
2024-05-20 15:37:46 +03:00
commit 00b7dbd0b7
10404 changed files with 3285853 additions and 0 deletions

View File

@ -0,0 +1,95 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Base class for metabox that consist of multiple sections.
*/
abstract class WPSEO_Abstract_Metabox_Tab_With_Sections implements WPSEO_Metabox_Section {
/**
* Holds the name of the tab.
*
* @var string
*/
public $name;
/**
* Holds the HTML of the tab header.
*
* @var string
*/
protected $link_content;
/**
* Holds the name of the tab header.
*
* @var string
*/
protected $link_title;
/**
* Holds the classname of the tab header.
*
* @var string
*/
protected $link_class;
/**
* Holds the aria label of the tab header.
*
* @var string
*/
protected $link_aria_label;
/**
* Constructor.
*
* @param string $name The name of the section, used as an identifier in the html.
* Can only contain URL safe characters.
* @param string $link_content The text content of the section link.
* @param array $options Optional link attributes.
*/
public function __construct( $name, $link_content, array $options = [] ) {
$default_options = [
'link_title' => '',
'link_class' => '',
'link_aria_label' => '',
];
$options = array_merge( $default_options, $options );
$this->name = $name;
$this->link_content = $link_content;
$this->link_title = $options['link_title'];
$this->link_class = $options['link_class'];
$this->link_aria_label = $options['link_aria_label'];
}
/**
* Outputs the section link if any section has been added.
*/
public function display_link() {
if ( $this->has_sections() ) {
printf(
'<li role="presentation"><a role="tab" href="#wpseo-meta-section-%1$s" id="wpseo-meta-tab-%1$s" aria-controls="wpseo-meta-section-%1$s" class="wpseo-meta-section-link %2$s"%3$s%4$s>%5$s</a></li>',
esc_attr( $this->name ),
esc_attr( $this->link_class ),
( $this->link_title !== '' ) ? ' title="' . esc_attr( $this->link_title ) . '"' : '',
( $this->link_aria_label !== '' ) ? ' aria-label="' . esc_attr( $this->link_aria_label ) . '"' : '',
$this->link_content
);
}
}
/**
* Checks whether the tab has any sections.
*
* @return bool Whether the tab has any sections
*/
abstract protected function has_sections();
}

View File

@ -0,0 +1,58 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Metabox
*/
/**
* Represents the inclusive language analysis.
*/
class WPSEO_Metabox_Analysis_Inclusive_Language implements WPSEO_Metabox_Analysis {
/**
* Whether this analysis is enabled.
*
* @return bool Whether or not this analysis is enabled.
*/
public function is_enabled() {
return $this->is_globally_enabled() && $this->is_user_enabled() && $this->is_current_version_supported()
&& YoastSEO()->helpers->language->has_inclusive_language_support( \WPSEO_Language_Utils::get_language( \get_locale() ) );
}
/**
* Whether or not this analysis is enabled by the user.
*
* @return bool Whether or not this analysis is enabled by the user.
*/
public function is_user_enabled() {
return ! get_the_author_meta( 'wpseo_inclusive_language_analysis_disable', get_current_user_id() );
}
/**
* Whether or not this analysis is enabled globally.
*
* @return bool Whether or not this analysis is enabled globally.
*/
public function is_globally_enabled() {
return WPSEO_Options::get( 'inclusive_language_analysis_active', false );
}
/**
* Whether the inclusive language analysis should be loaded in Free.
*
* It should always be loaded when Premium is not active. If Premium is active, it depends on the version. Some Premium
* versions also have inclusive language code (when it was still a Premium only feature) which would result in rendering
* the analysis twice. In those cases, the analysis should be only loaded from the Premium side.
*
* @return bool Whether or not the inclusive language analysis should be loaded.
*/
private function is_current_version_supported() {
$is_premium = YoastSEO()->helpers->product->is_premium();
$premium_version = YoastSEO()->helpers->product->get_premium_version();
return ! $is_premium
|| \version_compare( $premium_version, '19.6-RC0', '>=' )
|| \version_compare( $premium_version, '19.2', '==' );
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Metabox
*/
/**
* Represents the readability analysis.
*/
class WPSEO_Metabox_Analysis_Readability implements WPSEO_Metabox_Analysis {
/**
* Whether this analysis is enabled.
*
* @return bool Whether or not this analysis is enabled.
*/
public function is_enabled() {
return $this->is_globally_enabled() && $this->is_user_enabled();
}
/**
* Whether or not this analysis is enabled by the user.
*
* @return bool Whether or not this analysis is enabled by the user.
*/
public function is_user_enabled() {
return ! get_the_author_meta( 'wpseo_content_analysis_disable', get_current_user_id() );
}
/**
* Whether or not this analysis is enabled globally.
*
* @return bool Whether or not this analysis is enabled globally.
*/
public function is_globally_enabled() {
return WPSEO_Options::get( 'content_analysis_active', true );
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Metabox
*/
/**
* Represents the SEO analysis.
*/
class WPSEO_Metabox_Analysis_SEO implements WPSEO_Metabox_Analysis {
/**
* Whether this analysis is enabled.
*
* @return bool Whether or not this analysis is enabled.
*/
public function is_enabled() {
return $this->is_globally_enabled() && $this->is_user_enabled();
}
/**
* Whether or not this analysis is enabled by the user.
*
* @return bool Whether or not this analysis is enabled by the user.
*/
public function is_user_enabled() {
return ! get_the_author_meta( 'wpseo_keyword_analysis_disable', get_current_user_id() );
}
/**
* Whether or not this analysis is enabled globally.
*
* @return bool Whether or not this analysis is enabled globally.
*/
public function is_globally_enabled() {
return WPSEO_Options::get( 'keyword_analysis_active', true );
}
}

View File

@ -0,0 +1,84 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Generates the HTML for a metabox tab.
*/
class WPSEO_Metabox_Collapsible implements WPSEO_Metabox_Tab {
/**
* The collapsible's unique identifier.
*
* @var string
*/
private $name;
/**
* The content to be displayed inside the collapsible.
*
* @var string
*/
private $content;
/**
* The label.
*
* @var string
*/
private $link_content;
/**
* Constructor.
*
* @param string $name The name of the tab, used as an identifier in the html.
* @param string $content The tab content.
* @param string $link_content The text content of the tab link.
*/
public function __construct( $name, $content, $link_content ) {
$this->name = $name;
$this->content = $content;
$this->link_content = $link_content;
}
/**
* Returns the html for the tab link.
*
* @return string
*/
public function link() {
return $this->link_content;
}
/**
* Returns the html for the tab content.
*
* @return string
*/
public function content() {
$collapsible_paper = new WPSEO_Paper_Presenter(
$this->link(),
null,
[
'content' => $this->content,
'collapsible' => true,
'class' => 'metabox wpseo-form wpseo-collapsible-container',
'paper_id' => 'collapsible-' . $this->name,
]
);
return $collapsible_paper->get_output();
}
/**
* Returns the collapsible's unique identifier.
*
* @return string
*/
public function get_name() {
return $this->name;
}
}

View File

@ -0,0 +1,63 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Generates and displays a metabox tab that consists of collapsible sections.
*/
class WPSEO_Metabox_Collapsibles_Sections extends WPSEO_Abstract_Metabox_Tab_With_Sections {
/**
* Holds the tab's collapsibles.
*
* @var WPSEO_Metabox_Collapsible[]
*/
private $collapsibles = [];
/**
* Constructor.
*
* @param string $name The name of the section, used as an identifier in the html.
* Can only contain URL safe characters.
* @param string $link_content The text content of the section link.
* @param array $collapsibles The metabox collapsibles (`WPSEO_Metabox_Collapsible[]`) to be included in the section.
* @param array $options Optional link attributes.
*/
public function __construct( $name, $link_content, array $collapsibles = [], array $options = [] ) {
parent::__construct( $name, $link_content, $options );
$this->collapsibles = $collapsibles;
}
/**
* Outputs the section content if any tab has been added.
*/
public function display_content() {
if ( $this->has_sections() ) {
printf( '<div id="%1$s" class="wpseo-meta-section">', esc_attr( 'wpseo-meta-section-' . $this->name ) );
echo '<div class="wpseo_content_wrapper">';
add_filter( 'wp_kses_allowed_html', [ 'WPSEO_Utils', 'extend_kses_post_with_forms' ] );
add_filter( 'wp_kses_allowed_html', [ 'WPSEO_Utils', 'extend_kses_post_with_a11y' ] );
foreach ( $this->collapsibles as $collapsible ) {
echo wp_kses_post( $collapsible->content() );
}
remove_filter( 'wp_kses_allowed_html', [ 'WPSEO_Utils', 'extend_kses_post_with_forms' ] );
remove_filter( 'wp_kses_allowed_html', [ 'WPSEO_Utils', 'extend_kses_post_with_a11y' ] );
echo '</div></div>';
}
}
/**
* Checks whether the tab has any sections.
*
* @return bool Whether the tab has any sections
*/
protected function has_sections() {
return ! empty( $this->collapsibles );
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Metabox
*/
/**
* Handles all things with the metabox in combination with the WordPress editor.
*/
class WPSEO_Metabox_Editor {
/**
* Registers hooks to WordPress.
*
* @codeCoverageIgnore
*/
public function register_hooks() {
// For the Classic editor.
add_filter( 'mce_css', [ $this, 'add_css_inside_editor' ] );
// For the Block/Gutenberg editor.
// See https://github.com/danielbachhuber/gutenberg-migration-guide/blob/master/filter-mce-css.md.
add_action( 'enqueue_block_editor_assets', [ $this, 'add_editor_styles' ] );
add_filter( 'tiny_mce_before_init', [ $this, 'add_custom_element' ] );
}
/**
* Adds our inside the editor CSS file to the list of CSS files to be loaded inside the editor.
*
* @param string $css_files The CSS files that WordPress wants to load inside the editor.
* @return string The CSS files WordPress wants to load and our CSS file.
*/
public function add_css_inside_editor( $css_files ) {
$asset_manager = new WPSEO_Admin_Asset_Manager();
$styles = $asset_manager->special_styles();
$inside_editor = $styles['inside-editor'];
$asset_location = new WPSEO_Admin_Asset_SEO_Location( WPSEO_FILE );
$url = $asset_location->get_url( $inside_editor, WPSEO_Admin_Asset::TYPE_CSS );
if ( $css_files === '' ) {
$css_files = $url;
}
else {
$css_files .= ',' . $url;
}
return $css_files;
}
/**
* Enqueues the CSS to use in the TinyMCE editor.
*/
public function add_editor_styles() {
$asset_manager = new WPSEO_Admin_Asset_Manager();
$asset_manager->enqueue_style( 'inside-editor' );
}
/**
* Adds a custom element to the tinyMCE editor that we need for marking the content.
*
* @param array $tinymce_config The tinyMCE config as configured by WordPress.
*
* @return array The new tinyMCE config with our added custom elements.
*/
public function add_custom_element( $tinymce_config ) {
if ( ! empty( $tinymce_config['custom_elements'] ) ) {
$custom_elements = $tinymce_config['custom_elements'];
$custom_elements .= ',~yoastmark';
}
else {
$custom_elements = '~yoastmark';
}
$tinymce_config['custom_elements'] = $custom_elements;
return $tinymce_config;
}
}

View File

@ -0,0 +1,135 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Generates the HTML for a metabox tab.
*/
class WPSEO_Metabox_Form_Tab implements WPSEO_Metabox_Tab {
/**
* The tab identifier.
*
* @var string
*/
private $name;
/**
* The tab content.
*
* @var string
*/
private $content;
/**
* The tab link content.
*
* @var string
*/
private $link_content;
/**
* Additional tab content class.
*
* @var string
*/
private $tab_class;
/**
* Additional tab link class.
*
* @var string
*/
private $link_class;
/**
* Title attribute on the link span.
*
* @var string
*/
private $link_title;
/**
* Arial label attribute on the link span.
*
* @var string
*/
private $link_aria_label;
/**
* Does it contain a single tab.
*
* @var bool
*/
private $single;
/**
* Constructor.
*
* @param string $name The name of the tab, used as an identifier in the html.
* @param string $content The tab content.
* @param string $link_content The text content of the tab link.
* @param array $options Optional link attributes.
*/
public function __construct( $name, $content, $link_content, array $options = [] ) {
$default_options = [
'tab_class' => '',
'link_class' => '',
'link_title' => '',
'link_aria_label' => '',
'single' => false,
];
$options = array_merge( $default_options, $options );
$this->name = $name;
$this->content = $content;
$this->link_content = $link_content;
$this->tab_class = $options['tab_class'];
$this->link_class = $options['link_class'];
$this->link_title = $options['link_title'];
$this->link_aria_label = $options['link_aria_label'];
$this->single = $options['single'];
}
/**
* Returns the html for the tab link.
*
* @return string
*/
public function link() {
$html = '<li class="%1$s%2$s"><a class="wpseo_tablink%3$s" href="#wpseo_%1$s"%4$s%5$s>%6$s</a></li>';
if ( $this->single ) {
$html = '<li class="%1$s%2$s"><span class="wpseo_tablink%3$s"%4$s%5$s>%6$s</span></li>';
}
return sprintf(
$html,
esc_attr( $this->name ),
( $this->tab_class !== '' ) ? ' ' . esc_attr( $this->tab_class ) : '',
( $this->link_class !== '' ) ? ' ' . esc_attr( $this->link_class ) : '',
( $this->link_title !== '' ) ? ' title="' . esc_attr( $this->link_title ) . '"' : '',
( $this->link_aria_label !== '' ) ? ' aria-label="' . esc_attr( $this->link_aria_label ) . '"' : '',
$this->link_content
);
}
/**
* Returns the html for the tab content.
*
* @return string
*/
public function content() {
return sprintf(
'<div id="%1$s" class="wpseotab %2$s">%3$s</div>',
esc_attr( 'wpseo_' . $this->name ),
esc_attr( $this->name ),
$this->content
);
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Generates the HTML for a metabox tab.
*/
class WPSEO_Metabox_Null_Tab implements WPSEO_Metabox_Tab {
/**
* Returns the html for the tab link.
*
* @return string|null
*/
public function link() {
return null;
}
/**
* Returns the html for the tab content.
*
* @return string|null
*/
public function content() {
return null;
}
}

View File

@ -0,0 +1,109 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Metabox
*/
/**
* Generates and displays an additional metabox section.
*/
class WPSEO_Metabox_Section_Additional implements WPSEO_Metabox_Section {
/**
* Name of the section, used as an identifier in the HTML.
*
* @var string
*/
public $name;
/**
* Content of the tab's section.
*
* @var string
*/
public $content;
/**
* HTML to use in the tab header.
*
* @var string
*/
private $link_content;
/**
* Class to add to the link.
*
* @var string
*/
private $link_class;
/**
* Aria label to use for the link.
*
* @var string
*/
private $link_aria_label;
/**
* Represents the content class.
*
* @var string
*/
private $content_class;
/**
* Constructor.
*
* @param string $name The name of the section, used as an identifier in the html.
* Can only contain URL safe characters.
* @param string $link_content The text content of the section link.
* @param string $content Optional. Content to use above the React root element.
* @param array $options Optional link attributes.
*/
public function __construct( $name, $link_content, $content = '', array $options = [] ) {
$this->name = $name;
$this->content = $content;
$default_options = [
'link_class' => '',
'link_aria_label' => '',
'content_class' => 'wpseo-form',
];
$options = wp_parse_args( $options, $default_options );
$this->link_content = $link_content;
$this->link_class = $options['link_class'];
$this->link_aria_label = $options['link_aria_label'];
$this->content_class = $options['content_class'];
}
/**
* Outputs the section link.
*
* @return void
*/
public function display_link() {
printf(
'<li role="presentation"><a role="tab" href="#wpseo-meta-section-%1$s" id="wpseo-meta-tab-%1$s" aria-controls="wpseo-meta-section-%1$s" class="wpseo-meta-section-link %2$s"%3$s>%4$s</a></li>',
esc_attr( $this->name ),
esc_attr( $this->link_class ),
( $this->link_aria_label !== '' ) ? ' aria-label="' . esc_attr( $this->link_aria_label ) . '"' : '',
$this->link_content
);
}
/**
* Outputs the section content.
*
* @return void
*/
public function display_content() {
$html = sprintf(
'<div role="tabpanel" id="wpseo-meta-section-%1$s" aria-labelledby="wpseo-meta-tab-%1$s" tabindex="0" class="wpseo-meta-section %2$s">',
esc_attr( $this->name ),
esc_attr( $this->content_class )
);
$html .= $this->content;
$html .= '</div>';
echo $html;
}
}

View File

@ -0,0 +1,42 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Generates and displays the React root element for a metabox section.
*/
class WPSEO_Metabox_Section_Inclusive_Language implements WPSEO_Metabox_Section {
/**
* Name of the section, used as an identifier in the HTML.
*
* @var string
*/
public $name = 'inclusive-language';
/**
* Outputs the section link.
*/
public function display_link() {
printf(
'<li role="presentation"><a role="tab" href="#wpseo-meta-section-%1$s" id="wpseo-meta-tab-%1$s" aria-controls="wpseo-meta-section-%1$s" class="wpseo-meta-section-link">
<div class="wpseo-score-icon-container" id="wpseo-inclusive-language-score-icon"></div><span>%2$s</span></a></li>',
esc_attr( $this->name ),
esc_html__( 'Inclusive language', 'wordpress-seo' )
);
}
/**
* Outputs the section content.
*/
public function display_content() {
printf(
'<div role="tabpanel" id="wpseo-meta-section-%1$s" aria-labelledby="wpseo-meta-tab-%1$s" tabindex="0" class="wpseo-meta-section">',
esc_attr( $this->name )
);
echo '<div id="wpseo-metabox-inclusive-language-root" class="wpseo-metabox-root"></div>', '</div>';
}
}

View File

@ -0,0 +1,118 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Generates and displays the React root element for a metabox section.
*/
class WPSEO_Metabox_Section_React implements WPSEO_Metabox_Section {
/**
* Name of the section, used as an identifier in the HTML.
*
* @var string
*/
public $name;
/**
* Content to use before the React root node.
*
* @var string
*/
public $content;
/**
* Content to use to display the button to open this content block.
*
* @var string
*/
private $link_content;
/**
* Class to add to the link.
*
* @var string
*/
private $link_class;
/**
* Aria label to use for the link.
*
* @var string
*/
private $link_aria_label;
/**
* Additional html content to be displayed within the section.
*
* @var string
*/
private $html_after;
/**
* Constructor.
*
* @param string $name The name of the section, used as an identifier in the html.
* Can only contain URL safe characters.
* @param string $link_content The text content of the section link.
* @param string $content Optional. Content to use above the React root element.
* @param array $options Optional link attributes.
*/
public function __construct( $name, $link_content, $content = '', array $options = [] ) {
$this->name = $name;
$this->content = $content;
$default_options = [
'link_class' => '',
'link_aria_label' => '',
'html_after' => '',
];
$options = wp_parse_args( $options, $default_options );
$this->link_content = $link_content;
$this->link_class = $options['link_class'];
$this->link_aria_label = $options['link_aria_label'];
$this->html_after = $options['html_after'];
}
/**
* Outputs the section link.
*
* @return void
*/
public function display_link() {
printf(
'<li role="presentation"><a role="tab" href="#wpseo-meta-section-%1$s" id="wpseo-meta-tab-%1$s" aria-controls="wpseo-meta-section-%1$s" class="wpseo-meta-section-link %2$s"%3$s>%4$s</a></li>',
esc_attr( $this->name ),
esc_attr( $this->link_class ),
( $this->link_aria_label !== '' ) ? ' aria-label="' . esc_attr( $this->link_aria_label ) . '"' : '',
wp_kses_post( $this->link_content )
);
}
/**
* Outputs the section content.
*
* @return void
*/
public function display_content() {
add_filter( 'wp_kses_allowed_html', [ 'WPSEO_Utils', 'extend_kses_post_with_forms' ] );
add_filter( 'wp_kses_allowed_html', [ 'WPSEO_Utils', 'extend_kses_post_with_a11y' ] );
printf(
'<div role="tabpanel" id="wpseo-meta-section-%1$s" aria-labelledby="wpseo-meta-tab-%1$s" tabindex="0" class="wpseo-meta-section">',
esc_attr( $this->name )
);
echo wp_kses_post( $this->content );
echo '<div id="wpseo-metabox-root" class="wpseo-metabox-root"></div>';
echo wp_kses_post( $this->html_after );
echo '</div>';
remove_filter( 'wp_kses_allowed_html', [ 'WPSEO_Utils', 'extend_kses_post_with_forms' ] );
remove_filter( 'wp_kses_allowed_html', [ 'WPSEO_Utils', 'extend_kses_post_with_a11y' ] );
}
}

View File

@ -0,0 +1,42 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Generates and displays the React root element for a metabox section.
*/
class WPSEO_Metabox_Section_Readability implements WPSEO_Metabox_Section {
/**
* Name of the section, used as an identifier in the HTML.
*
* @var string
*/
public $name = 'readability';
/**
* Outputs the section link.
*/
public function display_link() {
printf(
'<li role="presentation"><a role="tab" href="#wpseo-meta-section-%1$s" id="wpseo-meta-tab-%1$s" aria-controls="wpseo-meta-section-%1$s" class="wpseo-meta-section-link">
<div class="wpseo-score-icon-container" id="wpseo-readability-score-icon"></div><span>%2$s</span></a></li>',
esc_attr( $this->name ),
esc_html__( 'Readability', 'wordpress-seo' )
);
}
/**
* Outputs the section content.
*/
public function display_content() {
printf(
'<div role="tabpanel" id="wpseo-meta-section-%1$s" aria-labelledby="wpseo-meta-tab-%1$s" tabindex="0" class="wpseo-meta-section">',
esc_attr( $this->name )
);
echo '<div id="wpseo-metabox-readability-root" class="wpseo-metabox-root"></div>', '</div>';
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,33 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Metabox
*/
/**
* Describes an interface for an analysis that can either be enabled or disabled.
*/
interface WPSEO_Metabox_Analysis {
/**
* Whether this analysis is enabled.
*
* @return bool Whether or not this analysis is enabled.
*/
public function is_enabled();
/**
* Whether or not this analysis is enabled by the user.
*
* @return bool Whether or not this analysis is enabled by the user.
*/
public function is_user_enabled();
/**
* Whether or not this analysis is enabled globally.
*
* @return bool Whether or not this analysis is enabled globally.
*/
public function is_globally_enabled();
}

View File

@ -0,0 +1,22 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Generates and displays the HTML for a metabox section.
*/
interface WPSEO_Metabox_Section {
/**
* Outputs the section link.
*/
public function display_link();
/**
* Outputs the section content.
*/
public function display_content();
}

View File

@ -0,0 +1,26 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Generates the HTML for a metabox tab.
*/
interface WPSEO_Metabox_Tab {
/**
* Returns the html for the tab link.
*
* @return string
*/
public function link();
/**
* Returns the html for the tab content.
*
* @return string
*/
public function content();
}