khaihihi
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?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) date( 'Uv' ),
|
||||
'wpVersion' => $this->get_wordpress_version(),
|
||||
'homeURL' => home_url(),
|
||||
'adminURL' => admin_url(),
|
||||
'isMultisite' => is_multisite(),
|
||||
'siteLanguage' => get_bloginfo( 'language' ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the WordPress version.
|
||||
*
|
||||
* @return string The version.
|
||||
*/
|
||||
protected function get_wordpress_version() {
|
||||
global $wp_version;
|
||||
|
||||
return $wp_version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* WPSEO plugin file.
|
||||
*
|
||||
* @package WPSEO\Admin\Tracking
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents the plugin data.
|
||||
*/
|
||||
class WPSEO_Tracking_Plugin_Data implements WPSEO_Collection {
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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 = filter_input( INPUT_SERVER, 'SERVER_ADDR', FILTER_VALIDATE_IP );
|
||||
if ( $ipaddress ) {
|
||||
$server_data['ip'] = $ipaddress;
|
||||
$server_data['Hostname'] = gethostbyaddr( $ipaddress );
|
||||
}
|
||||
|
||||
$server_data['os'] = php_uname();
|
||||
$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' ),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
<?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 $anonymous_settings 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',
|
||||
'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',
|
||||
'pinterest_url',
|
||||
'pinterestverify',
|
||||
'twitter_site',
|
||||
'youtube_url',
|
||||
'wikipedia_url',
|
||||
'fbadminapp',
|
||||
];
|
||||
|
||||
/**
|
||||
* The options we want to track.
|
||||
*
|
||||
* @var array $include_list The option_names for the options we want to track.
|
||||
*/
|
||||
private $include_list = [
|
||||
'ms_defaults_set',
|
||||
'version',
|
||||
'disableadvanced_meta',
|
||||
'onpage_indexability',
|
||||
'baiduverify',
|
||||
'googleverify',
|
||||
'msverify',
|
||||
'yandexverify',
|
||||
'site_type',
|
||||
'has_multiple_authors',
|
||||
'environment_type',
|
||||
'content_analysis_active',
|
||||
'keyword_analysis_active',
|
||||
'enable_admin_bar_menu',
|
||||
'enable_cornerstone_content',
|
||||
'enable_xml_sitemap',
|
||||
'enable_text_link_counter',
|
||||
'show_onboarding_notice',
|
||||
'first_activated_on',
|
||||
'myyoast-oauth',
|
||||
'website_name',
|
||||
'alternate_website_name',
|
||||
'company_logo',
|
||||
'company_name',
|
||||
'company_or_person',
|
||||
'person_name',
|
||||
'title_test',
|
||||
'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',
|
||||
'is-media-purge-relevant',
|
||||
'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',
|
||||
'showdate-post',
|
||||
'display-metabox-pt-post',
|
||||
'noindex-page',
|
||||
'showdate-page',
|
||||
'display-metabox-pt-page',
|
||||
'noindex-attachment',
|
||||
'showdate-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',
|
||||
'opengraph',
|
||||
'pinterest_url',
|
||||
'pinterestverify',
|
||||
'twitter',
|
||||
'twitter_site',
|
||||
'twitter_card_type',
|
||||
'youtube_url',
|
||||
'wikipedia_url',
|
||||
'fbadminapp',
|
||||
];
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?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 ),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the parent theme.
|
||||
*
|
||||
* @param WP_Theme $theme The theme object.
|
||||
*
|
||||
* @return null|string 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
/**
|
||||
* WPSEO plugin file.
|
||||
*
|
||||
* @package WPSEO\Admin\Tracking
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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 ) {
|
||||
$this->endpoint = $endpoint;
|
||||
$this->threshold = $threshold;
|
||||
$this->current_time = time();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all hooks to WordPress.
|
||||
*/
|
||||
public function register_hooks() {
|
||||
// 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 treshhold. Default false.
|
||||
*/
|
||||
public function send( $force = false ) {
|
||||
if ( ! $this->should_send_tracking( $force ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$collector = $this->get_collector();
|
||||
|
||||
$request = new WPSEO_Remote_Request( $this->endpoint );
|
||||
$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;
|
||||
|
||||
/**
|
||||
* Filter: 'wpseo_enable_tracking' - Enables the data tracking of Yoast SEO Premium.
|
||||
*
|
||||
* @api string $is_enabled The enabled state. Default is false.
|
||||
*/
|
||||
if ( apply_filters( 'wpseo_enable_tracking', false ) === false ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only send tracking on the main site of a multi-site instance. This returns true on non-multisite installs.
|
||||
if ( ! 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() );
|
||||
|
||||
return $collector;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user