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,126 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Tracking
*/
use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional;
/**
* Represents the addon option data.
*/
class WPSEO_Tracking_Addon_Data implements WPSEO_Collection {
/**
* The local options we want to track.
*
* @var string[] The option_names for the options we want to track.
*/
private $local_include_list = [
'use_multiple_locations',
'multiple_locations_same_organization',
'business_type',
'woocommerce_local_pickup_setting',
];
/**
* The woo options we want to track.
*
* @var string[] The option_names for the options we want to track.
*/
private $woo_include_list = [];
/**
* The news options we want to track.
*
* @var string[] The option_names for the options we want to track.
*/
private $news_include_list = [];
/**
* The video options we want to track.
*
* @var string[] The option_names for the options we want to track.
*/
private $video_include_list = [];
/**
* Returns the collection data.
*
* @return array The collection data.
*/
public function get() {
$addon_settings = [];
$addon_manager = new WPSEO_Addon_Manager();
if ( $addon_manager->is_installed( WPSEO_Addon_Manager::LOCAL_SLUG ) ) {
$addon_settings = $this->get_local_addon_settings( $addon_settings, 'wpseo_local', WPSEO_Addon_Manager::LOCAL_SLUG, $this->local_include_list );
}
if ( $addon_manager->is_installed( WPSEO_Addon_Manager::WOOCOMMERCE_SLUG ) ) {
$addon_settings = $this->get_addon_settings( $addon_settings, 'wpseo_woo', WPSEO_Addon_Manager::WOOCOMMERCE_SLUG, $this->woo_include_list );
}
if ( $addon_manager->is_installed( WPSEO_Addon_Manager::NEWS_SLUG ) ) {
$addon_settings = $this->get_addon_settings( $addon_settings, 'wpseo_news', WPSEO_Addon_Manager::NEWS_SLUG, $this->news_include_list );
}
if ( $addon_manager->is_installed( WPSEO_Addon_Manager::VIDEO_SLUG ) ) {
$addon_settings = $this->get_addon_settings( $addon_settings, 'wpseo_video', WPSEO_Addon_Manager::VIDEO_SLUG, $this->video_include_list );
}
return $addon_settings;
}
/**
* Gets the tracked options from the addon
*
* @param array $addon_settings The current list of addon settings.
* @param string $source_name The option key of the addon.
* @param string $slug The addon slug.
* @param array $option_include_list All the options to be included in tracking.
*
* @return array
*/
public function get_addon_settings( array $addon_settings, $source_name, $slug, $option_include_list ) {
$source_options = \get_option( $source_name, [] );
if ( ! \is_array( $source_options ) || empty( $source_options ) ) {
return $addon_settings;
}
$addon_settings[ $slug ] = \array_intersect_key( $source_options, \array_flip( $option_include_list ) );
return $addon_settings;
}
/**
* Filter business_type in local addon settings.
*
* Remove the business_type setting when 'multiple_locations_shared_business_info' setting is turned off.
*
* @param array $addon_settings The current list of addon settings.
* @param string $source_name The option key of the addon.
* @param string $slug The addon slug.
* @param array $option_include_list All the options to be included in tracking.
*
* @return array
*/
public function get_local_addon_settings( array $addon_settings, $source_name, $slug, $option_include_list ) {
$source_options = \get_option( $source_name, [] );
if ( ! \is_array( $source_options ) || empty( $source_options ) ) {
return $addon_settings;
}
$addon_settings[ $slug ] = \array_intersect_key( $source_options, \array_flip( $option_include_list ) );
if ( \array_key_exists( 'use_multiple_locations', $source_options ) && \array_key_exists( 'business_type', $addon_settings[ $slug ] ) && $source_options['use_multiple_locations'] === 'on' && $source_options['multiple_locations_shared_business_info'] === 'off' ) {
$addon_settings[ $slug ]['business_type'] = 'multiple_locations';
}
if ( ! ( new WooCommerce_Conditional() )->is_met() ) {
unset( $addon_settings[ $slug ]['woocommerce_local_pickup_setting'] );
}
return $addon_settings;
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Tracking
*/
/**
* Represents the default data.
*/
class WPSEO_Tracking_Default_Data implements WPSEO_Collection {
/**
* Returns the collection data.
*
* @return array The collection data.
*/
public function get() {
return [
'siteTitle' => get_option( 'blogname' ),
'@timestamp' => (int) gmdate( 'Uv' ),
'wpVersion' => $this->get_wordpress_version(),
'homeURL' => home_url(),
'adminURL' => admin_url(),
'isMultisite' => is_multisite(),
'siteLanguage' => get_bloginfo( 'language' ),
'gmt_offset' => get_option( 'gmt_offset' ),
'timezoneString' => get_option( 'timezone_string' ),
'migrationStatus' => get_option( 'yoast_migrations_free' ),
'countPosts' => $this->get_post_count( 'post' ),
'countPages' => $this->get_post_count( 'page' ),
];
}
/**
* Returns the number of posts of a certain type.
*
* @param string $post_type The post type return the count for.
*
* @return int The count for this post type.
*/
protected function get_post_count( $post_type ) {
$count = wp_count_posts( $post_type );
if ( isset( $count->publish ) ) {
return $count->publish;
}
return 0;
}
/**
* Returns the WordPress version.
*
* @return string The version.
*/
protected function get_wordpress_version() {
global $wp_version;
return $wp_version;
}
}

View File

@ -0,0 +1,90 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Tracking
*/
/**
* Represents the plugin data.
*/
class WPSEO_Tracking_Plugin_Data implements WPSEO_Collection {
/**
* Plugins with auto updating enabled.
*
* @var array
*/
private $auto_update_plugin_list;
/**
* Returns the collection data.
*
* @return array The collection data.
*/
public function get() {
return [
'plugins' => $this->get_plugin_data(),
];
}
/**
* Returns all plugins.
*
* @return array The formatted plugins.
*/
protected function get_plugin_data() {
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$plugins = wp_get_active_and_valid_plugins();
$plugins = array_map( 'get_plugin_data', $plugins );
$this->set_auto_update_plugin_list();
$plugins = array_map( [ $this, 'format_plugin' ], $plugins );
$plugin_data = [];
foreach ( $plugins as $plugin ) {
$plugin_key = sanitize_title( $plugin['name'] );
$plugin_data[ $plugin_key ] = $plugin;
}
return $plugin_data;
}
/**
* Sets all auto updating plugin data so it can be used in the tracking list.
*
* @return void
*/
public function set_auto_update_plugin_list() {
$auto_update_plugins = [];
$auto_update_plugin_files = \get_option( 'auto_update_plugins' );
if ( $auto_update_plugin_files ) {
foreach ( $auto_update_plugin_files as $auto_update_plugin ) {
$data = get_plugin_data( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $auto_update_plugin );
$auto_update_plugins[ $data['Name'] ] = $data;
}
}
$this->auto_update_plugin_list = $auto_update_plugins;
}
/**
* Formats the plugin array.
*
* @param array $plugin The plugin details.
*
* @return array The formatted array.
*/
protected function format_plugin( array $plugin ) {
return [
'name' => $plugin['Name'],
'version' => $plugin['Version'],
'auto_updating' => \array_key_exists( $plugin['Name'], $this->auto_update_plugin_list ),
];
}
}

View File

@ -0,0 +1,85 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Tracking
*/
/**
* Represents the server data.
*/
class WPSEO_Tracking_Server_Data implements WPSEO_Collection {
/**
* Returns the collection data.
*
* @return array The collection data.
*/
public function get() {
return [
'server' => $this->get_server_data(),
];
}
/**
* Returns the values with server details.
*
* @return array Array with the value.
*/
protected function get_server_data() {
$server_data = [];
// Validate if the server address is a valid IP-address.
$ipaddress = isset( $_SERVER['SERVER_ADDR'] ) ? filter_var( wp_unslash( $_SERVER['SERVER_ADDR'] ), FILTER_VALIDATE_IP ) : '';
if ( $ipaddress ) {
$server_data['ip'] = $ipaddress;
$server_data['Hostname'] = gethostbyaddr( $ipaddress );
}
$server_data['os'] = function_exists( 'php_uname' ) ? php_uname() : PHP_OS;
$server_data['PhpVersion'] = PHP_VERSION;
$server_data['CurlVersion'] = $this->get_curl_info();
$server_data['PhpExtensions'] = $this->get_php_extensions();
return $server_data;
}
/**
* Returns details about the curl version.
*
* @return array|null The curl info. Or null when curl isn't available..
*/
protected function get_curl_info() {
if ( ! function_exists( 'curl_version' ) ) {
return null;
}
$curl = curl_version();
$ssl_support = true;
if ( ! $curl['features'] && CURL_VERSION_SSL ) {
$ssl_support = false;
}
return [
'version' => $curl['version'],
'sslSupport' => $ssl_support,
];
}
/**
* Returns a list with php extensions.
*
* @return array Returns the state of the php extensions.
*/
protected function get_php_extensions() {
return [
'imagick' => extension_loaded( 'imagick' ),
'filter' => extension_loaded( 'filter' ),
'bcmath' => extension_loaded( 'bcmath' ),
'pcre' => extension_loaded( 'pcre' ),
'xml' => extension_loaded( 'xml' ),
'pdo_mysql' => extension_loaded( 'pdo_mysql' ),
];
}
}

View File

@ -0,0 +1,275 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Tracking
*/
/**
* Collects anonymized settings data.
*/
class WPSEO_Tracking_Settings_Data implements WPSEO_Collection {
/**
* The options that need to be anonymized before they can be sent elsewhere.
*
* @var array All of the option_names which need to be
* anonymized before they can be sent elsewhere.
*/
private $anonymous_settings = [
'baiduverify',
'googleverify',
'msverify',
'yandexverify',
'myyoast-oauth',
'website_name',
'alternate_website_name',
'company_logo',
'company_name',
'company_alternate_name',
'person_name',
'person_logo',
'person_logo_id',
'company_logo_id',
'facebook_site',
'instagram_url',
'linkedin_url',
'myspace_url',
'og_default_image',
'og_default_image_id',
'og_frontpage_title',
'og_frontpage_desc',
'og_frontpage_image',
'og_frontpage_image_id',
'open_graph_frontpage_title',
'open_graph_frontpage_desc',
'open_graph_frontpage_image',
'open_graph_frontpage_image_id',
'other_social_urls',
'mastodon_url',
'pinterest_url',
'pinterestverify',
'twitter_site',
'youtube_url',
'wikipedia_url',
'semrush_tokens',
'zapier_api_key',
'wincher_tokens',
'wincher_website_id',
'least_readability_ignore_list',
'least_seo_score_ignore_list',
'most_linked_ignore_list',
'least_linked_ignore_list',
'indexables_page_reading_list',
'publishing_principles_id',
'ownership_funding_info_id',
'actionable_feedback_policy_id',
'corrections_policy_id',
'ethics_policy_id',
'diversity_policy_id',
'diversity_staffing_report_id',
];
/**
* The options we want to track.
*
* @var array The option_names for the options we want to track.
*/
private $include_list = [
'ms_defaults_set',
'version',
'disableadvanced_meta',
'ryte_indexability',
'baiduverify',
'googleverify',
'msverify',
'yandexverify',
'site_type',
'has_multiple_authors',
'environment_type',
'content_analysis_active',
'keyword_analysis_active',
'inclusive_language_analysis_active',
'enable_admin_bar_menu',
'enable_cornerstone_content',
'enable_xml_sitemap',
'enable_text_link_counter',
'show_onboarding_notice',
'first_activated_on',
'myyoast-oauth',
'dynamic_permalinks',
'website_name',
'alternate_website_name',
'company_logo',
'company_name',
'company_or_person',
'person_name',
'forcerewritetitle',
'separator',
'title-home-wpseo',
'title-author-wpseo',
'title-archive-wpseo',
'title-search-wpseo',
'title-404-wpseo',
'metadesc-home-wpseo',
'metadesc-author-wpseo',
'metadesc-archive-wpseo',
'rssbefore',
'rssafter',
'noindex-author-wpseo',
'noindex-author-noposts-wpseo',
'noindex-archive-wpseo',
'disable-author',
'disable-date',
'disable-post_format',
'disable-attachment',
'breadcrumbs-404crumb',
'breadcrumbs-display-blog-page',
'breadcrumbs-boldlast',
'breadcrumbs-archiveprefix',
'breadcrumbs-enable',
'breadcrumbs-home',
'breadcrumbs-prefix',
'breadcrumbs-searchprefix',
'breadcrumbs-sep',
'person_logo',
'person_logo_id',
'company_logo_id',
'company_or_person_user_id',
'stripcategorybase',
'noindex-post',
'display-metabox-pt-post',
'noindex-page',
'display-metabox-pt-page',
'noindex-attachment',
'display-metabox-pt-attachment',
'display-metabox-tax-category',
'noindex-tax-category',
'display-metabox-tax-post_tag',
'noindex-tax-post_tag',
'display-metabox-tax-post_format',
'noindex-tax-post_format',
'taxonomy-category-ptparent',
'taxonomy-post_tag-ptparent',
'taxonomy-post_format-ptparent',
'breadcrumbs-blog-remove',
'hideeditbox-post',
'hideeditbox-page',
'hideeditbox-attachment',
'hideeditbox-tax-category',
'hideeditbox-tax-post_tag',
'hideeditbox-tax-post_format',
'facebook_site',
'instagram_url',
'linkedin_url',
'myspace_url',
'og_default_image',
'og_default_image_id',
'og_frontpage_title',
'og_frontpage_desc',
'og_frontpage_image',
'og_frontpage_image_id',
'open_graph_frontpage_title',
'open_graph_frontpage_desc',
'open_graph_frontpage_image',
'open_graph_frontpage_image_id',
'opengraph',
'pinterest_url',
'pinterestverify',
'twitter',
'twitter_site',
'twitter_card_type',
'youtube_url',
'wikipedia_url',
'mastodon_url',
'indexables_indexing_completed',
'semrush_integration_active',
'semrush_tokens',
'semrush_country_code',
'enable_enhanced_slack_sharing',
'zapier_integration_active',
'zapier_api_key',
'enable_metabox_insights',
'enable_link_suggestions',
'enable_index_now',
'enable_ai_generator',
'workouts',
'wincher_integration_active',
'wincher_tokens',
'wincher_website_id',
'wincher_automatically_add_keyphrases',
'first_time_install',
'other_social_urls',
'remove_feed_global',
'remove_feed_global_comments',
'remove_feed_post_comments',
'remove_feed_authors',
'remove_feed_categories',
'remove_feed_tags',
'remove_feed_custom_taxonomies',
'remove_feed_post_types',
'remove_feed_search',
'remove_atom_rdf_feeds',
'remove_shortlinks',
'remove_rest_api_links',
'remove_rsd_wlw_links',
'remove_oembed_links',
'remove_generator',
'remove_emoji_scripts',
'remove_powered_by_header',
'remove_pingback_header',
'clean_campaign_tracking_urls',
'clean_permalinks',
'clean_permalinks_extra_variables',
'search_cleanup',
'search_cleanup_emoji',
'search_cleanup_patterns',
'search_character_limit',
'redirect_search_pretty_urls',
'wordproof_integration_active',
'indexables_overview_state',
'deny_search_crawling',
'deny_wp_json_crawling',
'deny_adsbot_crawling',
'last_known_no_unindexed',
];
/**
* Returns the collection data.
*
* @return array The collection data.
*/
public function get() {
/**
* Filter: 'wpseo_tracking_settings_include_list' - Allow filtering the settings included in tracking.
*
* @api string $include_list the list with included setting names.
*/
$this->include_list = apply_filters( 'wpseo_tracking_settings_include_list', $this->include_list );
$options = WPSEO_Options::get_all();
// Returns the settings of which the keys intersect with the values of the include list.
$options = array_intersect_key( $options, array_flip( $this->include_list ) );
return [
'settings' => $this->anonymize_settings( $options ),
];
}
/**
* Anonimizes the WPSEO_Options array by replacing all $anonymous_settings values to 'used'.
*
* @param array $settings The settings.
*
* @return array The anonymized settings.
*/
private function anonymize_settings( $settings ) {
foreach ( $this->anonymous_settings as $setting ) {
if ( ! empty( $settings[ $setting ] ) ) {
$settings[ $setting ] = 'used';
}
}
return $settings;
}
}

View File

@ -0,0 +1,51 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Tracking
*/
/**
* Represents the theme data.
*/
class WPSEO_Tracking_Theme_Data implements WPSEO_Collection {
/**
* Returns the collection data.
*
* @return array The collection data.
*/
public function get() {
$theme = wp_get_theme();
return [
'theme' => [
'name' => $theme->get( 'Name' ),
'url' => $theme->get( 'ThemeURI' ),
'version' => $theme->get( 'Version' ),
'author' => [
'name' => $theme->get( 'Author' ),
'url' => $theme->get( 'AuthorURI' ),
],
'parentTheme' => $this->get_parent_theme( $theme ),
'blockTemplateSupport' => current_theme_supports( 'block-templates' ),
'isBlockTheme' => function_exists( 'wp_is_block_theme' ) && wp_is_block_theme(),
],
];
}
/**
* Returns the name of the parent theme.
*
* @param WP_Theme $theme The theme object.
*
* @return string|null The name of the parent theme or null.
*/
private function get_parent_theme( WP_Theme $theme ) {
if ( is_child_theme() ) {
return $theme->get( 'Template' );
}
return null;
}
}

View File

@ -0,0 +1,236 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Tracking
*/
use Yoast\WP\SEO\Analytics\Application\Missing_Indexables_Collector;
use Yoast\WP\SEO\Analytics\Application\To_Be_Cleaned_Indexables_Collector;
/**
* This class handles the tracking routine.
*/
class WPSEO_Tracking implements WPSEO_WordPress_Integration {
/**
* The tracking option name.
*
* @var string
*/
protected $option_name = 'wpseo_tracking_last_request';
/**
* The limit for the option.
*
* @var int
*/
protected $threshold = 0;
/**
* The endpoint to send the data to.
*
* @var string
*/
protected $endpoint = '';
/**
* The current time.
*
* @var int
*/
private $current_time;
/**
* WPSEO_Tracking constructor.
*
* @param string $endpoint The endpoint to send the data to.
* @param int $threshold The limit for the option.
*/
public function __construct( $endpoint, $threshold ) {
if ( ! $this->tracking_enabled() ) {
return;
}
$this->endpoint = $endpoint;
$this->threshold = $threshold;
$this->current_time = time();
}
/**
* Registers all hooks to WordPress.
*/
public function register_hooks() {
if ( ! $this->tracking_enabled() ) {
return;
}
// Send tracking data on `admin_init`.
add_action( 'admin_init', [ $this, 'send' ], 1 );
// Add an action hook that will be triggered at the specified time by `wp_schedule_single_event()`.
add_action( 'wpseo_send_tracking_data_after_core_update', [ $this, 'send' ] );
// Call `wp_schedule_single_event()` after a WordPress core update.
add_action( 'upgrader_process_complete', [ $this, 'schedule_tracking_data_sending' ], 10, 2 );
}
/**
* Schedules a new sending of the tracking data after a WordPress core update.
*
* @param bool|WP_Upgrader $upgrader Optional. WP_Upgrader instance or false.
* Depending on context, it might be a Theme_Upgrader,
* Plugin_Upgrader, Core_Upgrade, or Language_Pack_Upgrader.
* instance. Default false.
* @param array $data Array of update data.
*
* @return void
*/
public function schedule_tracking_data_sending( $upgrader = false, $data = [] ) {
// Return if it's not a WordPress core update.
if ( ! $upgrader || ! isset( $data['type'] ) || $data['type'] !== 'core' ) {
return;
}
/*
* To uniquely identify the scheduled cron event, `wp_next_scheduled()`
* needs to receive the same arguments as those used when originally
* scheduling the event otherwise it will always return false.
*/
if ( ! wp_next_scheduled( 'wpseo_send_tracking_data_after_core_update', [ true ] ) ) {
/*
* Schedule sending of data tracking 6 hours after a WordPress core
* update. Pass a `true` parameter for the callback `$force` argument.
*/
wp_schedule_single_event( ( time() + ( HOUR_IN_SECONDS * 6 ) ), 'wpseo_send_tracking_data_after_core_update', [ true ] );
}
}
/**
* Sends the tracking data.
*
* @param bool $force Whether to send the tracking data ignoring the two
* weeks time threshold. Default false.
*/
public function send( $force = false ) {
if ( ! $this->should_send_tracking( $force ) ) {
return;
}
// Set a 'content-type' header of 'application/json'.
$tracking_request_args = [
'headers' => [
'content-type:' => 'application/json',
],
];
$collector = $this->get_collector();
$request = new WPSEO_Remote_Request( $this->endpoint, $tracking_request_args );
$request->set_body( $collector->get_as_json() );
$request->send();
update_option( $this->option_name, $this->current_time, 'yes' );
}
/**
* Determines whether to send the tracking data.
*
* Returns false if tracking is disabled or the current page is one of the
* admin plugins pages. Returns true when there's no tracking data stored or
* the data was sent more than two weeks ago. The two weeks interval is set
* when instantiating the class.
*
* @param bool $ignore_time_treshhold Whether to send the tracking data ignoring
* the two weeks time treshhold. Default false.
*
* @return bool True when tracking data should be sent.
*/
protected function should_send_tracking( $ignore_time_treshhold = false ) {
global $pagenow;
// Only send tracking on the main site of a multi-site instance. This returns true on non-multisite installs.
if ( is_network_admin() || ! is_main_site() ) {
return false;
}
// Because we don't want to possibly block plugin actions with our routines.
if ( in_array( $pagenow, [ 'plugins.php', 'plugin-install.php', 'plugin-editor.php' ], true ) ) {
return false;
}
$last_time = get_option( $this->option_name );
// When tracking data haven't been sent yet or when sending data is forced.
if ( ! $last_time || $ignore_time_treshhold ) {
return true;
}
return $this->exceeds_treshhold( $this->current_time - $last_time );
}
/**
* Checks if the given amount of seconds exceeds the set threshold.
*
* @param int $seconds The amount of seconds to check.
*
* @return bool True when seconds is bigger than threshold.
*/
protected function exceeds_treshhold( $seconds ) {
return ( $seconds > $this->threshold );
}
/**
* Returns the collector for collecting the data.
*
* @return WPSEO_Collector The instance of the collector.
*/
public function get_collector() {
$collector = new WPSEO_Collector();
$collector->add_collection( new WPSEO_Tracking_Default_Data() );
$collector->add_collection( new WPSEO_Tracking_Server_Data() );
$collector->add_collection( new WPSEO_Tracking_Theme_Data() );
$collector->add_collection( new WPSEO_Tracking_Plugin_Data() );
$collector->add_collection( new WPSEO_Tracking_Settings_Data() );
$collector->add_collection( new WPSEO_Tracking_Addon_Data() );
$collector->add_collection( YoastSEO()->classes->get( Missing_Indexables_Collector::class ) );
$collector->add_collection( YoastSEO()->classes->get( To_Be_Cleaned_Indexables_Collector::class ) );
return $collector;
}
/**
* See if we should run tracking at all.
*
* @return bool True when we can track, false when we can't.
*/
private function tracking_enabled() {
// Check if we're allowing tracking.
$tracking = WPSEO_Options::get( 'tracking' );
if ( $tracking === false ) {
return false;
}
// Save this state.
if ( $tracking === null ) {
/**
* Filter: 'wpseo_enable_tracking' - Enables the data tracking of Yoast SEO Premium and add-ons.
*
* @api string $is_enabled The enabled state. Default is false.
*/
$tracking = apply_filters( 'wpseo_enable_tracking', false );
WPSEO_Options::set( 'tracking', $tracking );
}
if ( $tracking === false ) {
return false;
}
if ( ! YoastSEO()->helpers->environment->is_production_mode() ) {
return false;
}
return true;
}
}