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,330 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Formatter
*/
use Yoast\WP\SEO\Conditionals\Third_Party\Polylang_Conditional;
use Yoast\WP\SEO\Conditionals\Third_Party\TranslatePress_Conditional;
use Yoast\WP\SEO\Conditionals\Third_Party\WPML_Conditional;
use Yoast\WP\SEO\Config\Schema_Types;
use Yoast\WP\SEO\Config\SEMrush_Client;
use Yoast\WP\SEO\Exceptions\OAuth\Authentication_Failed_Exception;
use Yoast\WP\SEO\Exceptions\OAuth\Tokens\Empty_Property_Exception;
use Yoast\WP\SEO\Exceptions\OAuth\Tokens\Empty_Token_Exception;
/**
* This class forces needed methods for the metabox localization.
*/
class WPSEO_Metabox_Formatter {
/**
* Object that provides formatted values.
*
* @var WPSEO_Metabox_Formatter_Interface
*/
private $formatter;
/**
* Setting the formatter property.
*
* @param WPSEO_Metabox_Formatter_Interface $formatter Object that provides the formatted values.
*/
public function __construct( WPSEO_Metabox_Formatter_Interface $formatter ) {
$this->formatter = $formatter;
}
/**
* Returns the values.
*
* @return array
*/
public function get_values() {
$defaults = $this->get_defaults();
$values = $this->formatter->get_values();
return ( $values + $defaults );
}
/**
* Returns array with all the values always needed by a scraper object.
*
* @return array Default settings for the metabox.
*/
private function get_defaults() {
$analysis_seo = new WPSEO_Metabox_Analysis_SEO();
$analysis_readability = new WPSEO_Metabox_Analysis_Readability();
$analysis_inclusive_language = new WPSEO_Metabox_Analysis_Inclusive_Language();
$schema_types = new Schema_Types();
$is_wincher_active = YoastSEO()->helpers->wincher->is_active();
$host = YoastSEO()->helpers->url->get_url_host( get_site_url() );
return [
'author_name' => get_the_author_meta( 'display_name' ),
'site_name' => YoastSEO()->meta->for_current_page()->site_name,
'sitewide_social_image' => WPSEO_Options::get( 'og_default_image' ),
'search_url' => '',
'post_edit_url' => '',
'base_url' => '',
'contentTab' => __( 'Readability', 'wordpress-seo' ),
'keywordTab' => __( 'Keyphrase:', 'wordpress-seo' ),
'removeKeyword' => __( 'Remove keyphrase', 'wordpress-seo' ),
'contentLocale' => get_locale(),
'userLocale' => \get_user_locale(),
'translations' => $this->get_translations(),
'keyword_usage' => [],
'title_template' => '',
'metadesc_template' => '',
'contentAnalysisActive' => $analysis_readability->is_enabled() ? 1 : 0,
'keywordAnalysisActive' => $analysis_seo->is_enabled() ? 1 : 0,
'inclusiveLanguageAnalysisActive' => $analysis_inclusive_language->is_enabled() ? 1 : 0,
'cornerstoneActive' => WPSEO_Options::get( 'enable_cornerstone_content', false ) ? 1 : 0,
'semrushIntegrationActive' => WPSEO_Options::get( 'semrush_integration_active', true ) ? 1 : 0,
'intl' => $this->get_content_analysis_component_translations(),
'isRtl' => is_rtl(),
'isPremium' => YoastSEO()->helpers->product->is_premium(),
'wordFormRecognitionActive' => YoastSEO()->helpers->language->is_word_form_recognition_active( WPSEO_Language_Utils::get_language( get_locale() ) ),
'siteIconUrl' => get_site_icon_url(),
'countryCode' => WPSEO_Options::get( 'semrush_country_code', false ),
'SEMrushLoginStatus' => WPSEO_Options::get( 'semrush_integration_active', true ) ? $this->get_semrush_login_status() : false,
'showSocial' => [
'facebook' => WPSEO_Options::get( 'opengraph', false ),
'twitter' => WPSEO_Options::get( 'twitter', false ),
],
'schema' => [
'displayFooter' => WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' ),
'pageTypeOptions' => $schema_types->get_page_type_options(),
'articleTypeOptions' => $schema_types->get_article_type_options(),
],
'twitterCardType' => 'summary_large_image',
/**
* Filter to determine if the markers should be enabled or not.
*
* @param bool $showMarkers Should the markers being enabled. Default = true.
*/
'show_markers' => apply_filters( 'wpseo_enable_assessment_markers', true ),
'publish_box' => [
'labels' => [
'keyword' => [
'na' => sprintf(
/* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the SEO score. */
__( '%1$sSEO%2$s: %3$s', 'wordpress-seo' ),
'<a href="#yoast-seo-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Not available', 'wordpress-seo' ) . '</strong>'
),
'bad' => sprintf(
/* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the SEO score. */
__( '%1$sSEO%2$s: %3$s', 'wordpress-seo' ),
'<a href="#yoast-seo-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Needs improvement', 'wordpress-seo' ) . '</strong>'
),
'ok' => sprintf(
/* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the SEO score. */
__( '%1$sSEO%2$s: %3$s', 'wordpress-seo' ),
'<a href="#yoast-seo-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'OK', 'wordpress-seo' ) . '</strong>'
),
'good' => sprintf(
/* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the SEO score. */
__( '%1$sSEO%2$s: %3$s', 'wordpress-seo' ),
'<a href="#yoast-seo-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Good', 'wordpress-seo' ) . '</strong>'
),
],
'content' => [
'na' => sprintf(
/* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the readability score. */
__( '%1$sReadability%2$s: %3$s', 'wordpress-seo' ),
'<a href="#yoast-readability-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Not available', 'wordpress-seo' ) . '</strong>'
),
'bad' => sprintf(
/* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the readability score. */
__( '%1$sReadability%2$s: %3$s', 'wordpress-seo' ),
'<a href="#yoast-readability-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Needs improvement', 'wordpress-seo' ) . '</strong>'
),
'ok' => sprintf(
/* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the readability score. */
__( '%1$sReadability%2$s: %3$s', 'wordpress-seo' ),
'<a href="#yoast-readability-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'OK', 'wordpress-seo' ) . '</strong>'
),
'good' => sprintf(
/* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the readability score. */
__( '%1$sReadability%2$s: %3$s', 'wordpress-seo' ),
'<a href="#yoast-readability-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Good', 'wordpress-seo' ) . '</strong>'
),
],
'inclusive-language' => [
'na' => sprintf(
/* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the inclusive language score. */
__( '%1$sInclusive language%2$s: %3$s', 'wordpress-seo' ),
'<a href="#yoast-inclusive-language-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Not available', 'wordpress-seo' ) . '</strong>'
),
'bad' => sprintf(
/* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the inclusive language score. */
__( '%1$sInclusive language%2$s: %3$s', 'wordpress-seo' ),
'<a href="#yoast-inclusive-language-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Needs improvement', 'wordpress-seo' ) . '</strong>'
),
'ok' => sprintf(
/* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the inclusive language score. */
__( '%1$sInclusive language%2$s: %3$s', 'wordpress-seo' ),
'<a href="#yoast-inclusive-language-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Potentially non-inclusive', 'wordpress-seo' ) . '</strong>'
),
'good' => sprintf(
/* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the inclusive language score. */
__( '%1$sInclusive language%2$s: %3$s', 'wordpress-seo' ),
'<a href="#yoast-inclusive-language-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Good', 'wordpress-seo' ) . '</strong>'
),
],
],
],
'markdownEnabled' => $this->is_markdown_enabled(),
'analysisHeadingTitle' => __( 'Analysis', 'wordpress-seo' ),
'zapierIntegrationActive' => WPSEO_Options::get( 'zapier_integration_active', false ) ? 1 : 0,
'zapierConnectedStatus' => ! empty( WPSEO_Options::get( 'zapier_subscription', [] ) ) ? 1 : 0,
'wincherIntegrationActive' => ( $is_wincher_active ) ? 1 : 0,
'wincherLoginStatus' => ( $is_wincher_active ) ? YoastSEO()->helpers->wincher->login_status() : false,
'wincherWebsiteId' => WPSEO_Options::get( 'wincher_website_id', '' ),
'wincherAutoAddKeyphrases' => WPSEO_Options::get( 'wincher_automatically_add_keyphrases', false ),
'wordproofIntegrationActive' => YoastSEO()->helpers->wordproof->is_active() ? 1 : 0,
'multilingualPluginActive' => $this->multilingual_plugin_active(),
/**
* Filter to determine whether the PreviouslyUsedKeyword assessment should run.
*
* @param bool $previouslyUsedKeywordActive Whether the PreviouslyUsedKeyword assessment should run.
*/
'previouslyUsedKeywordActive' => apply_filters( 'wpseo_previously_used_keyword_active', true ),
'getJetpackBoostPrePublishLink' => WPSEO_Shortlinker::get( 'https://yoa.st/jetpack-boost-get-prepublish?domain=' . $host ),
'upgradeJetpackBoostPrePublishLink' => WPSEO_Shortlinker::get( 'https://yoa.st/jetpack-boost-upgrade-prepublish?domain=' . $host ),
'woocommerceUpsellSchemaLink' => WPSEO_Shortlinker::get( 'https://yoa.st/product-schema-metabox' ),
'woocommerceUpsellGooglePreviewLink' => WPSEO_Shortlinker::get( 'https://yoa.st/product-google-preview-metabox' ),
];
}
/**
* Returns required yoast-component translations.
*
* @return array
*/
private function get_content_analysis_component_translations() {
// Esc_html is not needed because React already handles HTML in the (translations of) these strings.
return [
'locale' => \get_user_locale(),
'content-analysis.errors' => __( 'Errors', 'wordpress-seo' ),
'content-analysis.problems' => __( 'Problems', 'wordpress-seo' ),
'content-analysis.improvements' => __( 'Improvements', 'wordpress-seo' ),
'content-analysis.considerations' => __( 'Considerations', 'wordpress-seo' ),
'content-analysis.good' => __( 'Good results', 'wordpress-seo' ),
'content-analysis.highlight' => __( 'Highlight this result in the text', 'wordpress-seo' ),
'content-analysis.nohighlight' => __( 'Remove highlight from the text', 'wordpress-seo' ),
'content-analysis.disabledButton' => __( 'Marks are disabled in current view', 'wordpress-seo' ),
'a11yNotice.opensInNewTab' => __( '(Opens in a new browser tab)', 'wordpress-seo' ),
];
}
/**
* Returns Jed compatible YoastSEO.js translations.
*
* @return array
*/
private function get_translations() {
$locale = \get_user_locale();
$file = WPSEO_PATH . 'languages/wordpress-seo-' . $locale . '.json';
if ( file_exists( $file ) ) {
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Retrieving a local file.
$file = file_get_contents( $file );
if ( is_string( $file ) && $file !== '' ) {
return json_decode( $file, true );
}
}
return [];
}
/**
* Checks if Jetpack's markdown module is enabled.
* Can be extended to work with other plugins that parse markdown in the content.
*
* @return bool
*/
private function is_markdown_enabled() {
$is_markdown = false;
if ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'get_active_modules' ) ) {
$active_modules = Jetpack::get_active_modules();
// First at all, check if Jetpack's markdown module is active.
$is_markdown = in_array( 'markdown', $active_modules, true );
}
/**
* Filters whether markdown support is active in the readability- and seo-analysis.
*
* @since 11.3
*
* @param array $is_markdown Is markdown support for Yoast SEO active.
*/
return apply_filters( 'wpseo_is_markdown_enabled', $is_markdown );
}
/**
* Checks if the user is logged in to SEMrush.
*
* @return bool The SEMrush login status.
*/
private function get_semrush_login_status() {
try {
$semrush_client = YoastSEO()->classes->get( SEMrush_Client::class );
} catch ( Empty_Property_Exception $e ) {
// Return false if token is malformed (empty property).
return false;
}
// Get token (and refresh it if it's expired).
try {
$semrush_client->get_tokens();
} catch ( Authentication_Failed_Exception $e ) {
return false;
} catch ( Empty_Token_Exception $e ) {
return false;
}
return $semrush_client->has_valid_tokens();
}
/**
* Checks whether a multilingual plugin is currently active. Currently, we only check the following plugins: WPML, Polylang, and TranslatePress.
*
* @return bool Whether a multilingual plugin is currently active.
*/
private function multilingual_plugin_active() {
$wpml_active = YoastSEO()->classes->get( WPML_Conditional::class )->is_met();
$polylang_active = YoastSEO()->classes->get( Polylang_Conditional::class )->is_met();
$translatepress_active = YoastSEO()->classes->get( TranslatePress_Conditional::class )->is_met();
return ( $wpml_active || $polylang_active || $translatepress_active );
}
}

View File

@ -0,0 +1,318 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Formatter
*/
/**
* This class provides data for the post metabox by return its values for localization.
*/
class WPSEO_Post_Metabox_Formatter implements WPSEO_Metabox_Formatter_Interface {
/**
* Holds the WordPress Post.
*
* @var WP_Post
*/
private $post;
/**
* The permalink to follow.
*
* @var string
*/
private $permalink;
/**
* Whether we must return social templates values.
*
* @var bool
*/
private $use_social_templates = false;
/**
* Constructor.
*
* @param WP_Post|array $post Post object.
* @param array $options Title options to use.
* @param string $structure The permalink to follow.
*/
public function __construct( $post, array $options, $structure ) {
$this->post = $post;
$this->permalink = $structure;
$this->use_social_templates = $this->use_social_templates();
}
/**
* Determines whether the social templates should be used.
*
* @return bool Whether the social templates should be used.
*/
public function use_social_templates() {
return WPSEO_Options::get( 'opengraph', false ) === true;
}
/**
* Returns the translated values.
*
* @return array
*/
public function get_values() {
$values = [
'search_url' => $this->search_url(),
'post_edit_url' => $this->edit_url(),
'base_url' => $this->base_url_for_js(),
'metaDescriptionDate' => '',
];
if ( $this->post instanceof WP_Post ) {
$keyword_usage = $this->get_focus_keyword_usage();
$values_to_set = [
'keyword_usage' => $keyword_usage,
'keyword_usage_post_types' => $this->get_post_types_for_all_ids( $keyword_usage ),
'title_template' => $this->get_title_template(),
'title_template_no_fallback' => $this->get_title_template( false ),
'metadesc_template' => $this->get_metadesc_template(),
'metaDescriptionDate' => $this->get_metadesc_date(),
'first_content_image' => $this->get_image_url(),
'social_title_template' => $this->get_social_title_template(),
'social_description_template' => $this->get_social_description_template(),
'social_image_template' => $this->get_social_image_template(),
'isInsightsEnabled' => $this->is_insights_enabled(),
];
$values = ( $values_to_set + $values );
}
/**
* Filter: 'wpseo_post_edit_values' - Allows changing the values Yoast SEO uses inside the post editor.
*
* @api array $values The key-value map Yoast SEO uses inside the post editor.
*
* @param WP_Post $post The post opened in the editor.
*/
return \apply_filters( 'wpseo_post_edit_values', $values, $this->post );
}
/**
* Gets the image URL for the post's social preview.
*
* @return string|null The image URL for the social preview.
*/
protected function get_image_url() {
return WPSEO_Image_Utils::get_first_usable_content_image_for_post( $this->post->ID );
}
/**
* Returns the url to search for keyword for the post.
*
* @return string
*/
private function search_url() {
return admin_url( 'edit.php?seo_kw_filter={keyword}' );
}
/**
* Returns the url to edit the taxonomy.
*
* @return string
*/
private function edit_url() {
return admin_url( 'post.php?post={id}&action=edit' );
}
/**
* Returns a base URL for use in the JS, takes permalink structure into account.
*
* @return string
*/
private function base_url_for_js() {
global $pagenow;
// The default base is the home_url.
$base_url = home_url( '/', null );
if ( $pagenow === 'post-new.php' ) {
return $base_url;
}
// If %postname% is the last tag, just strip it and use that as a base.
if ( preg_match( '#%postname%/?$#', $this->permalink ) === 1 ) {
$base_url = preg_replace( '#%postname%/?$#', '', $this->permalink );
}
// If %pagename% is the last tag, just strip it and use that as a base.
if ( preg_match( '#%pagename%/?$#', $this->permalink ) === 1 ) {
$base_url = preg_replace( '#%pagename%/?$#', '', $this->permalink );
}
return $base_url;
}
/**
* Counts the number of given keywords used for other posts other than the given post_id.
*
* @return array The keyword and the associated posts that use it.
*/
private function get_focus_keyword_usage() {
$keyword = WPSEO_Meta::get_value( 'focuskw', $this->post->ID );
$usage = [ $keyword => $this->get_keyword_usage_for_current_post( $keyword ) ];
/**
* Allows enhancing the array of posts' that share their focus keywords with the post's related keywords.
*
* @param array $usage The array of posts' ids that share their focus keywords with the post.
* @param int $post_id The id of the post we're finding the usage of related keywords for.
*/
return apply_filters( 'wpseo_posts_for_related_keywords', $usage, $this->post->ID );
}
/**
* Retrieves the post types for the given post IDs.
*
* @param array $post_ids_per_keyword An associative array with keywords as keys and an array of post ids where those keywords are used.
* @return array The post types for the given post IDs.
*/
private function get_post_types_for_all_ids( $post_ids_per_keyword ) {
$post_type_per_keyword_result = [];
foreach ( $post_ids_per_keyword as $keyword => $post_ids ) {
$post_type_per_keyword_result[ $keyword ] = WPSEO_Meta::post_types_for_ids( $post_ids );
}
return $post_type_per_keyword_result;
}
/**
* Gets the keyword usage for the current post and the specified keyword.
*
* @param string $keyword The keyword to check the usage of.
*
* @return array The post IDs which use the passed keyword.
*/
protected function get_keyword_usage_for_current_post( $keyword ) {
return WPSEO_Meta::keyword_usage( $keyword, $this->post->ID );
}
/**
* Retrieves the title template.
*
* @param bool $fallback Whether to return the hardcoded fallback if the template value is empty.
*
* @return string The title template.
*/
private function get_title_template( $fallback = true ) {
$title = $this->get_template( 'title' );
if ( $title === '' && $fallback === true ) {
return '%%title%% %%page%% %%sep%% %%sitename%%';
}
return $title;
}
/**
* Retrieves the metadesc template.
*
* @return string The metadesc template.
*/
private function get_metadesc_template() {
return $this->get_template( 'metadesc' );
}
/**
* Retrieves the social title template.
*
* @return string The social title template.
*/
private function get_social_title_template() {
if ( $this->use_social_templates ) {
return $this->get_social_template( 'title' );
}
return '';
}
/**
* Retrieves the social description template.
*
* @return string The social description template.
*/
private function get_social_description_template() {
if ( $this->use_social_templates ) {
return $this->get_social_template( 'description' );
}
return '';
}
/**
* Retrieves the social image template.
*
* @return string The social description template.
*/
private function get_social_image_template() {
if ( $this->use_social_templates ) {
return $this->get_social_template( 'image-url' );
}
return '';
}
/**
* Retrieves a template.
*
* @param string $template_option_name The name of the option in which the template you want to get is saved.
*
* @return string
*/
private function get_template( $template_option_name ) {
$needed_option = $template_option_name . '-' . $this->post->post_type;
if ( WPSEO_Options::get( $needed_option, '' ) !== '' ) {
return WPSEO_Options::get( $needed_option );
}
return '';
}
/**
* Retrieves a social template.
*
* @param string $template_option_name The name of the option in which the template you want to get is saved.
*
* @return string
*/
private function get_social_template( $template_option_name ) {
/**
* Filters the social template value for a given post type.
*
* @param string $template The social template value, defaults to empty string.
* @param string $template_option_name The subname of the option in which the template you want to get is saved.
* @param string $post_type The name of the post type.
*/
return \apply_filters( 'wpseo_social_template_post_type', '', $template_option_name, $this->post->post_type );
}
/**
* Determines the date to be displayed in the snippet preview.
*
* @return string
*/
private function get_metadesc_date() {
return YoastSEO()->helpers->date->format_translated( $this->post->post_date, 'M j, Y' );
}
/**
* Determines whether the insights feature is enabled for this post.
*
* @return bool
*/
protected function is_insights_enabled() {
return WPSEO_Options::get( 'enable_metabox_insights', false );
}
}

View File

@ -0,0 +1,255 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Formatter
*/
/**
* This class provides data for the term metabox by return its values for localization.
*/
class WPSEO_Term_Metabox_Formatter implements WPSEO_Metabox_Formatter_Interface {
/**
* The term the metabox formatter is for.
*
* @var WP_Term|stdClass
*/
private $term;
/**
* The term's taxonomy.
*
* @var stdClass
*/
private $taxonomy;
/**
* Whether we must return social templates values.
*
* @var bool
*/
private $use_social_templates = false;
/**
* Array with the WPSEO_Titles options.
*
* @var array
*/
protected $options;
/**
* WPSEO_Taxonomy_Scraper constructor.
*
* @param stdClass $taxonomy Taxonomy.
* @param WP_Term|stdClass $term Term.
*/
public function __construct( $taxonomy, $term ) {
$this->taxonomy = $taxonomy;
$this->term = $term;
$this->use_social_templates = $this->use_social_templates();
}
/**
* Determines whether the social templates should be used.
*
* @return bool Whether the social templates should be used.
*/
public function use_social_templates() {
return WPSEO_Options::get( 'opengraph', false ) === true;
}
/**
* Returns the translated values.
*
* @return array
*/
public function get_values() {
$values = [];
// Todo: a column needs to be added on the termpages to add a filter for the keyword, so this can be used in the focus keyphrase doubles.
if ( is_object( $this->term ) && property_exists( $this->term, 'taxonomy' ) ) {
$values = [
'search_url' => $this->search_url(),
'post_edit_url' => $this->edit_url(),
'base_url' => $this->base_url_for_js(),
'taxonomy' => $this->term->taxonomy,
'keyword_usage' => $this->get_focus_keyword_usage(),
'title_template' => $this->get_title_template(),
'title_template_no_fallback' => $this->get_title_template( false ),
'metadesc_template' => $this->get_metadesc_template(),
'first_content_image' => $this->get_image_url(),
'semrushIntegrationActive' => 0,
'social_title_template' => $this->get_social_title_template(),
'social_description_template' => $this->get_social_description_template(),
'social_image_template' => $this->get_social_image_template(),
'wincherIntegrationActive' => 0,
'isInsightsEnabled' => $this->is_insights_enabled(),
];
}
return $values;
}
/**
* Gets the image URL for the term's social preview.
*
* @return string|null The image URL for the social preview.
*/
protected function get_image_url() {
return WPSEO_Image_Utils::get_first_content_image_for_term( $this->term->term_id );
}
/**
* Returns the url to search for keyword for the taxonomy.
*
* @return string
*/
private function search_url() {
return admin_url( 'edit-tags.php?taxonomy=' . $this->term->taxonomy . '&seo_kw_filter={keyword}' );
}
/**
* Returns the url to edit the taxonomy.
*
* @return string
*/
private function edit_url() {
return admin_url( 'term.php?action=edit&taxonomy=' . $this->term->taxonomy . '&tag_ID={id}' );
}
/**
* Returns a base URL for use in the JS, takes permalink structure into account.
*
* @return string
*/
private function base_url_for_js() {
$base_url = home_url( '/', null );
if ( ! WPSEO_Options::get( 'stripcategorybase', false ) ) {
if ( $this->taxonomy->rewrite ) {
$base_url = trailingslashit( $base_url . $this->taxonomy->rewrite['slug'] );
}
}
return $base_url;
}
/**
* Counting the number of given keyword used for other term than given term_id.
*
* @return array
*/
private function get_focus_keyword_usage() {
$focuskw = WPSEO_Taxonomy_Meta::get_term_meta( $this->term, $this->term->taxonomy, 'focuskw' );
return WPSEO_Taxonomy_Meta::get_keyword_usage( $focuskw, $this->term->term_id, $this->term->taxonomy );
}
/**
* Retrieves the title template.
*
* @param bool $fallback Whether to return the hardcoded fallback if the template value is empty.
*
* @return string The title template.
*/
private function get_title_template( $fallback = true ) {
$title = $this->get_template( 'title' );
if ( $title === '' && $fallback === true ) {
/* translators: %s expands to the variable used for term title. */
$archives = sprintf( __( '%s Archives', 'wordpress-seo' ), '%%term_title%%' );
return $archives . ' %%page%% %%sep%% %%sitename%%';
}
return $title;
}
/**
* Retrieves the metadesc template.
*
* @return string The metadesc template.
*/
private function get_metadesc_template() {
return $this->get_template( 'metadesc' );
}
/**
* Retrieves the social title template.
*
* @return string The social title template.
*/
private function get_social_title_template() {
if ( $this->use_social_templates ) {
return $this->get_social_template( 'title' );
}
return '';
}
/**
* Retrieves the social description template.
*
* @return string The social description template.
*/
private function get_social_description_template() {
if ( $this->use_social_templates ) {
return $this->get_social_template( 'description' );
}
return '';
}
/**
* Retrieves the social image template.
*
* @return string The social description template.
*/
private function get_social_image_template() {
if ( $this->use_social_templates ) {
return $this->get_social_template( 'image-url' );
}
return '';
}
/**
* Retrieves a template.
*
* @param string $template_option_name The name of the option in which the template you want to get is saved.
*
* @return string
*/
private function get_template( $template_option_name ) {
$needed_option = $template_option_name . '-tax-' . $this->term->taxonomy;
return WPSEO_Options::get( $needed_option, '' );
}
/**
* Retrieves a social template.
*
* @param string $template_option_name The name of the option in which the template you want to get is saved.
*
* @return string
*/
private function get_social_template( $template_option_name ) {
/**
* Filters the social template value for a given taxonomy.
*
* @param string $template The social template value, defaults to empty string.
* @param string $template_option_name The subname of the option in which the template you want to get is saved.
* @param string $taxonomy The name of the taxonomy.
*/
return \apply_filters( 'wpseo_social_template_taxonomy', '', $template_option_name, $this->term->taxonomy );
}
/**
* Determines whether the insights feature is enabled for this taxonomy.
*
* @return bool
*/
protected function is_insights_enabled() {
return WPSEO_Options::get( 'enable_metabox_insights', false );
}
}

View File

@ -0,0 +1,19 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Formatter
*/
/**
* Interface to force get_values.
*/
interface WPSEO_Metabox_Formatter_Interface {
/**
* Returns formatter values.
*
* @return array
*/
public function get_values();
}