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,167 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Notifiers
*/
/**
* Represents the logic for showing the notification.
*/
class WPSEO_Configuration_Notifier implements WPSEO_Listener {
/**
* @var string
*/
const META_NAME = 'wpseo-dismiss-configuration-notice';
/**
* @var string
*/
const META_VALUE = 'yes';
/**
* @var bool
*/
protected $show_notification;
/**
* Constructs the object by setting the show notification property based the given options.
*/
public function __construct() {
$this->show_notification = WPSEO_Options::get( 'show_onboarding_notice', false );
}
/**
* Returns the content of the notification.
*
* @return string A string with the notification HTML, or empty string when no notification is needed.
*/
public function notify() {
if ( ! $this->show_notification() ) {
return $this->re_run_notification();
}
return $this->first_time_notification();
}
/**
* Listens to an argument in the request URL. When triggered just set the notification to dismissed.
*
* @return void
*/
public function listen() {
if ( ! $this->show_notification() || ! $this->dismissal_is_triggered() ) {
return;
}
$this->set_dismissed();
}
/**
* Checks if the dismissal should be triggered.
*
* @return bool True when action has been triggered.
*/
protected function dismissal_is_triggered() {
return filter_input( INPUT_GET, 'dismiss_get_started' ) === '1';
}
/**
* Checks if the current user has dismissed the notification.
*
* @return bool True when the notification has been dismissed.
*/
protected function is_dismissed() {
return get_user_meta( get_current_user_id(), self::META_NAME, true ) === self::META_VALUE;
}
/**
* Sets the dismissed state for the current user.
*
* @return void
*/
protected function set_dismissed() {
update_user_meta( get_current_user_id(), self::META_NAME, self::META_VALUE );
}
/**
* Checks if the notification should be shown.
*
* @return bool True when notification should be shown.
*/
protected function show_notification() {
return $this->show_notification && ! $this->is_dismissed();
}
/**
* Returns the notification to re-run the config wizard.
*
* @return string The notification.
*/
private function re_run_notification() {
$content = sprintf(
/* translators: %1$s expands to Yoast SEO, %2$s is a link start tag to the Onboarding Wizard, %3$s is the link closing tag. */
esc_html__( 'Want to make sure your %1$s settings are still OK? %2$sOpen the configuration wizard again%3$s to validate them.', 'wordpress-seo' ),
'Yoast SEO',
'<a href="' . esc_url( admin_url( 'admin.php?page=' . WPSEO_Configuration_Page::PAGE_IDENTIFIER ) ) . '">',
'</a>'
);
return $this->notification( __( 'Check SEO configuration', 'wordpress-seo' ), $content );
}
/**
* Returns the notification to start the config wizard for the first time.
*
* @return string The notification.
*/
private function first_time_notification() {
$content = sprintf(
/* translators: %1$s expands to Yoast SEO, %2$s is a link start tag to the Onboarding Wizard, %3$s is the link closing tag. */
esc_html__( 'Get started quickly with the %1$s %2$sconfiguration wizard%3$s!', 'wordpress-seo' ),
'Yoast SEO',
'<a href="' . esc_url( admin_url( 'admin.php?page=' . WPSEO_Configuration_Page::PAGE_IDENTIFIER ) ) . '">',
'</a>'
);
return $this->notification( __( 'First-time SEO configuration', 'wordpress-seo' ), $content, true );
}
/**
* Returns a styled notification.
*
* @param string $title Title for the notification.
* @param string $content Content for the notification.
* @param bool $show_dismissal Whether to show the dismiss button or not.
*
* @return string The styled notification.
*/
private function notification( $title, $content, $show_dismissal = false ) {
$notification = '<div class="yoast-container yoast-container__configuration-wizard">';
$notification .= sprintf(
'<img src="%1$s" height="%2$s" width="%3$d" />',
esc_url( plugin_dir_url( WPSEO_FILE ) . 'images/new-to-configuration-notice.svg' ),
60,
60
);
$notification .= '<div class="yoast-container__configuration-wizard--content">';
$notification .= '<h3>' . esc_html( $title ) . '</h3>';
$notification .= '<p>';
$notification .= $content;
$notification .= '</p>';
$notification .= '</div>';
if ( $show_dismissal ) {
$notification .= sprintf(
'<a href="%1$s" style="" class="button dismiss yoast-container__configuration-wizard--dismiss"><span class="screen-reader-text">%2$s</span><span class="dashicons dashicons-no-alt"></span></a>',
esc_url( admin_url( 'admin.php?page=wpseo_dashboard&amp;dismiss_get_started=1' ) ),
esc_html__( 'Dismiss this item.', 'wordpress-seo' )
);
}
$notification .= '</div>';
return $notification;
}
}

View File

@ -0,0 +1,195 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Notifiers
*/
/**
* Represents the logic for showing the post type archive notification.
*/
class WPSEO_Post_Type_Archive_Notification_Handler extends WPSEO_Dismissible_Notification {
/**
* Defaults for the title option.
*
* @var array
*/
protected $option_defaults = array();
/**
* Sets the notification identifier.
*
* @codeCoverageIgnore
*
* @return void
*/
public function __construct() {
$this->notification_identifier = 'post-type-archive-notification';
}
/**
* Checks if the notice should be shown.
*
* @return bool True when applicable.
*/
protected function is_applicable() {
if ( $this->is_notice_dismissed() ) {
return false;
}
if ( $this->is_new_install() ) {
return false;
}
return $this->get_post_types() !== array();
}
/**
* Returns the notification.
*
* @return Yoast_Notification The notification for the notification center.
*
* @codeCoverageIgnore
*/
protected function get_notification() {
$post_types = $this->get_post_types();
$message = esc_html__(
'We\'ve recently improved the functionality of the Search Appearance settings. Unfortunately, we\'ve discovered that for some edge-cases, saving the settings for specific post type archives might have gone wrong.',
'wordpress-seo'
);
$message .= PHP_EOL . PHP_EOL;
$message .= sprintf(
/* translators: %1$s is the archive template link start tag, %2$s is the link closing tag, %3$s is a comma separated string with content types. */
_n(
'Please check the %1$sarchive template%2$s for the following content type: %3$s.',
'Please check the %1$sarchive templates%2$s for the following content types: %3$s.',
count( $post_types ),
'wordpress-seo'
),
'<a href="' . esc_url( admin_url( 'admin.php?page=wpseo_titles#top#post-types' ) ) . '">',
'</a>',
implode( ', ', $post_types )
);
$message .= PHP_EOL . PHP_EOL;
$message .= sprintf(
/* translators: %1$s is the notification dismissal link start tag, %2$s is the link closing tag. */
__( '%1$sRemove this message%2$s', 'wordpress-seo' ),
'<a class="button" href="' . admin_url( '?page=' . WPSEO_Admin::PAGE_IDENTIFIER . '&yoast_dismiss=' . $this->notification_identifier ) . '">',
'</a>'
);
$notification_options = array(
'type' => Yoast_Notification::WARNING,
'id' => 'wpseo-' . $this->notification_identifier,
'priority' => 1.0,
'capabilities' => 'wpseo_manage_options',
);
return new Yoast_Notification( $message, $notification_options );
}
/**
* Checks if the first activation is done before the release of 7.9.
*
* @return bool True when the install is 'new'.
*
* @codeCoverageIgnore
*/
protected function is_new_install() {
return WPSEO_Options::get( 'first_activated_on' ) >= strtotime( '2018-07-24' );
}
/**
* Returns all the post types which might have wrong archive settings.
*
* @return array The post types.
*
* @codeCoverageIgnore
*/
protected function get_post_types() {
static $post_types;
if ( $post_types === null ) {
$this->option_defaults = WPSEO_Option_Titles::get_instance()->get_defaults();
$post_types = get_post_types( array( 'public' => true ) );
$post_types = WPSEO_Post_Type::filter_attachment_post_type( $post_types );
$post_types = $this->filter_woocommerce_product_type( $post_types );
$post_types = array_filter( $post_types, array( $this, 'has_custom_archive_slug' ) );
$post_types = array_filter( $post_types, array( $this, 'has_default_templates_set' ) );
}
return $post_types;
}
/**
* Filters the WooCommerce product, when Woocommerce is active.
*
* @param array $post_types The post types to filter.
*
* @return array The filtere post types.
*
* @codeCoverageIgnore
*/
protected function filter_woocommerce_product_type( $post_types ) {
if ( WPSEO_Utils::is_woocommerce_active() ) {
unset( $post_types['product'] );
}
return $post_types;
}
/**
* Checks if the archive slug for the post type is overridden.
*
* @param string $post_type_name The post type's name.
*
* @return bool True when the archive slug is overridden.
*
* @codeCoverageIgnore
*/
protected function has_custom_archive_slug( $post_type_name ) {
$post_type = get_post_type_object( $post_type_name );
if ( $post_type === null || ! WPSEO_Post_Type::has_archive( $post_type ) ) {
return false;
}
// When the archive value is not TRUE it will be a custom archive slug.
return ( $post_type->has_archive !== true );
}
/**
* Checks if the default templates are set for given post type.
*
* @param string $post_type_name The post type name.
*
* @return bool True when the default templates are set.
*
* @codeCoverageIgnore
*/
protected function has_default_templates_set( $post_type_name ) {
$title_option_name = 'title-ptarchive-' . $post_type_name;
$metadesc_option_name = 'metadesc-ptarchive-' . $post_type_name;
return ( $this->is_equal_to_default( $title_option_name ) && $this->is_equal_to_default( $metadesc_option_name ) );
}
/**
* Checks if value for given option name is equal to the default value.
*
* @param string $option_name The option name to check.
*
* @return bool True when the option value is equal to the default value.
*
* @codeCoverageIgnore
*/
protected function is_equal_to_default( $option_name ) {
if ( ! isset( $this->option_defaults[ $option_name ] ) ) {
return false;
}
return ( WPSEO_Options::get( $option_name ) === $this->option_defaults[ $option_name ] );
}
}

View File

@ -0,0 +1,121 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Notifiers
*/
/**
* Abstract class representing a dismissible notification.
*/
abstract class WPSEO_Dismissible_Notification implements WPSEO_Listener, WPSEO_Notification_Handler {
/**
* The identifier for the notification.
*
* @var string
*/
protected $notification_identifier = '';
/**
* Retrieves instance of a notification.
*
* @return Yoast_Notification The notification.
*/
abstract protected function get_notification();
/**
* Listens to an argument in the request URL and triggers an action.
*
* @return void
*/
public function listen() {
if ( $this->get_listener_value() !== $this->notification_identifier ) {
return;
}
$this->dismiss();
}
/**
* Adds the notification if applicable, otherwise removes it.
*
* @param Yoast_Notification_Center $notification_center The notification center object.
*
* @return void
*/
public function handle( Yoast_Notification_Center $notification_center ) {
if ( $this->is_applicable() ) {
$notification = $this->get_notification();
$notification_center->add_notification( $notification );
return;
}
$notification_center->remove_notification_by_id( 'wpseo-' . $this->notification_identifier );
}
/**
* Listens to an argument in the request URL and triggers an action.
*
* @return void
*/
protected function dismiss() {
$this->set_dismissal_state();
$this->redirect_to_dashboard();
}
/**
* Checks if a notice is applicable.
*
* @return bool Whether a notice should be shown or not.
*/
protected function is_applicable() {
return $this->is_notice_dismissed() === false;
}
/**
* Checks whether the notification has been dismissed.
*
* @return bool True when notification is dismissed.
*
* @codeCoverageIgnore
*/
protected function is_notice_dismissed() {
return get_user_meta( get_current_user_id(), 'wpseo-remove-' . $this->notification_identifier, true ) === '1';
}
/**
* Retrieves the value where listener is listening for.
*
* @return string The listener value.
*
* @codeCoverageIgnore
*/
protected function get_listener_value() {
return filter_input( INPUT_GET, 'yoast_dismiss' );
}
/**
* Dismisses the notification.
*
* @return void
*
* @codeCoverageIgnore
*/
protected function set_dismissal_state() {
update_user_meta( get_current_user_id(), 'wpseo-remove-' . $this->notification_identifier, true );
}
/**
* Redirects the user back to the dashboard.
*
* @return void
*
* @codeCoverageIgnore
*/
protected function redirect_to_dashboard() {
wp_safe_redirect( admin_url( 'admin.php?page=wpseo_dashboard' ) );
exit;
}
}

View File

@ -0,0 +1,21 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Notifiers
*/
/**
* Dictates the required methods for a Notification Handler implementation.
*/
interface WPSEO_Notification_Handler {
/**
* Handles the notification object.
*
* @param Yoast_Notification_Center $notification_center The notification center object.
*
* @return void
*/
public function handle( Yoast_Notification_Center $notification_center );
}