PDF rausgenommen

This commit is contained in:
aschwarz
2023-01-23 11:03:31 +01:00
parent 82d562a322
commit a6523903eb
28078 changed files with 4247552 additions and 2 deletions

View File

@ -0,0 +1,39 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Generates and displays a section containing metabox tabs that have been added by other plugins through the
* `wpseo_tab_header` and `wpseo_tab_content` actions.
*/
class WPSEO_Metabox_Addon_Tab_Section extends WPSEO_Metabox_Tab_Section {
/**
* Applies the actions for adding a tab to the metabox.
*/
public function display_content() {
?>
<div id="wpseo-meta-section-addons" class="wpseo-meta-section">
<div class="wpseo-metabox-tabs-div">
<ul class="wpseo-metabox-tabs">
<?php do_action( 'wpseo_tab_header' ); ?>
</ul>
<?php do_action( 'wpseo_tab_content' ); ?>
</div>
</div>
<?php
}
/**
* `WPSEO_Metabox_Addon_Section` always has "tabs", represented by registered actions. If this is not the case,
* it should not be instantiated.
*
* @return bool
*/
protected function has_tabs() {
return true;
}
}

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,69 @@
<?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() {
add_filter( 'mce_css', array( $this, 'add_css_inside_editor' ) );
add_filter( 'tiny_mce_before_init', array( $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();
/** @var WPSEO_Admin_Asset $inside_editor */
$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;
}
/**
* 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,119 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Generates the HTML for a metabox tab.
*/
class WPSEO_Metabox_Form_Tab implements WPSEO_Metabox_Tab {
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $content;
/**
* @var string
*/
private $link_content;
/**
* @var string
*/
private $tab_class;
/**
* @var string
*/
private $link_class;
/**
* @var string
*/
private $link_title;
/**
* @var string
*/
private $link_aria_label;
/**
* @var boolean
*/
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 = array() ) {
$default_options = array(
'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
*/
public function link() {
return null;
}
/**
* Returns the html for the tab content.
*
* @return string
*/
public function content() {
return null;
}
}

View File

@ -0,0 +1,101 @@
<?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;
/**
* 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 = array() ) {
$this->name = $name;
$this->content = $content;
$default_options = array(
'link_class' => '',
'link_aria_label' => '',
);
$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'];
}
/**
* Outputs the section link.
*
* @return void
*/
public function display_link() {
printf(
'<li><a href="#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 id="%1$s" class="wpseo-meta-section">', esc_attr( 'wpseo-meta-section-' . $this->name ) );
$html .= $this->content;
$html .= '<div id="wpseo-metabox-root" class="wpseo-metabox-root"></div>';
$html .= '</div>';
echo $html;
}
}

View File

@ -0,0 +1,178 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Generates and displays the HTML for a metabox section.
*/
class WPSEO_Metabox_Tab_Section implements WPSEO_Metabox_Section {
/**
* @var WPSEO_Metabox_Tab[]
*/
public $tabs = array();
/**
* @var string
*/
public $name;
/**
* @var string
*/
private $link_content;
/**
* @var string
*/
private $link_title;
/**
* @var string
*/
private $link_class;
/**
* @var string
*/
private $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 $tabs The metabox tabs (`WPSEO_Metabox_Tabs[]`) to be included in the section.
* @param array $options Optional link attributes.
*/
public function __construct( $name, $link_content, array $tabs = array(), array $options = array() ) {
$default_options = array(
'link_title' => '',
'link_class' => '',
'link_aria_label' => '',
);
$options = array_merge( $default_options, $options );
$this->name = $name;
// Filter out invalid tab instances.
$valid_tabs = array_filter( $tabs, array( $this, 'is_valid_tab' ) );
foreach ( $valid_tabs as $tab ) {
$this->add_tab( $tab );
}
$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'];
}
/**
* Determines whether the passed tab is considered valid.
*
* @param mixed $tab The potential tab that needs to be validated.
*
* @return bool Whether or not the tab is valid.
*/
protected function is_valid_tab( $tab ) {
if ( $tab instanceof WPSEO_Metabox_Tab && ! $tab instanceof WPSEO_Metabox_Null_Tab ) {
return true;
}
return false;
}
/**
* Outputs the section link if any tab has been added.
*/
public function display_link() {
if ( $this->has_tabs() ) {
printf(
'<li><a href="#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
);
}
}
/**
* Outputs the section content if any tab has been added.
*/
public function display_content() {
if ( $this->has_tabs() ) {
$html = '<div id="%1$s" class="wpseo-meta-section">';
$html .= '<div class="wpseo-metabox-tabs-div">';
$html .= '<ul class="wpseo-metabox-tabs %2$s">%3$s</ul>%4$s';
$html .= '</div></div>';
printf(
$html,
esc_attr( 'wpseo-meta-section-' . $this->name ),
esc_attr( 'wpseo-metabox-tab-' . $this->name ),
$this->tab_links(),
$this->tab_content()
);
}
}
/**
* Add a `WPSEO_Metabox_Tab` object to the tabs.
*
* @param WPSEO_Metabox_Tab $tab Tab to add.
*/
public function add_tab( WPSEO_Metabox_Tab $tab ) {
$this->tabs[] = $tab;
}
/**
* Checks if any tabs have been added to the section.
*
* @return bool
*/
protected function has_tabs() {
return ! empty( $this->tabs );
}
/**
* Concatenates all tabs' links into one html string.
*
* @return string
*/
private function tab_links() {
$links = '';
foreach ( $this->tabs as $tab ) {
$links .= $tab->link();
}
return $links;
}
/**
* Concatenates all tabs' content into one html string.
*
* @return string
*/
private function tab_content() {
$content = '';
foreach ( $this->tabs as $tab ) {
$content .= $tab->content();
}
return $content;
}
/**
* Gets the name of the tab section.
*
* @return string The name of the tab section.
*/
public function get_name() {
return $this->name;
}
}

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();
}