Updates bonanza

This commit is contained in:
nikolark committed 2014-07-24 14:38:32 +02:00
1 parent d26191c9f8
commit 9d480fc3c5
1366 files changed
+220321 -90180

No files matched your search

@@ -3,160 +3,237 @@
* @package Admin
*/
if ( !defined( 'WPSEO_VERSION' ) ) {
header( 'HTTP/1.0 403 Forbidden' );
die;
if ( ! defined( 'WPSEO_VERSION' ) ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit();
}
/**
* Class that creates the tracking functionality for WP SEO, as the core class might be used in more plugins,
* it's checked for existence first.
*
* NOTE: this functionality is opt-in. Disabling the tracking in the settings or saying no when asked will cause
* this file to not even be loaded.
*/
if ( !class_exists( 'Yoast_Tracking' ) ) {
if ( ! class_exists( 'Yoast_Tracking' ) ) {
/**
* Class that creates the tracking functionality for WP SEO, as the core class might be used in more plugins,
* it's checked for existence first.
*
* NOTE: this functionality is opt-in. Disabling the tracking in the settings or saying no when asked will cause
* this file to not even be loaded.
*
* @todo [JRF => testers] check if tracking still works if an old version of the Yoast Tracking class was loaded
* (i.e. another plugin loaded their version first)
*/
class Yoast_Tracking {
/**
* @var object Instance of this class
*/
public static $instance;
/**
* Class constructor
*/
function __construct() {
// The tracking checks daily, but only sends new data every 7 days.
if ( !wp_next_scheduled( 'yoast_tracking' ) ) {
wp_schedule_event( time(), 'daily', 'yoast_tracking' );
// Constructor is called from WP SEO
if ( current_filter( 'yoast_tracking' ) ) {
$this->tracking();
} // Backward compatibility - constructor is called from other Yoast plugin
elseif ( ! has_action( 'yoast_tracking', array( $this, 'tracking' ) ) ) {
add_action( 'yoast_tracking', array( $this, 'tracking' ) );
}
}
/**
* Get the singleton instance of this class
*
* @return object
*/
public static function get_instance() {
if ( ! ( self::$instance instanceof self ) ) {
self::$instance = new self();
}
add_action( 'yoast_tracking', array( $this, 'tracking' ) );
return self::$instance;
}
/**
* Main tracking function.
*/
function tracking() {
$transient_key = 'yoast_tracking_cache';
$data = get_transient( $transient_key );
// bail if transient is set and valid
if ( $data !== false ) {
return;
}
// Make sure to only send tracking data once a week
set_transient( $transient_key, 1, WEEK_IN_SECONDS );
// Start of Metrics
global $blog_id, $wpdb;
$hash = get_option( 'Yoast_Tracking_Hash' );
$hash = get_option( 'Yoast_Tracking_Hash', false );
if ( !isset( $hash ) || !$hash || empty( $hash ) ) {
if ( ! $hash || empty( $hash ) ) {
// create and store hash
$hash = md5( site_url() );
update_option( 'Yoast_Tracking_Hash', $hash );
}
$data = get_transient( 'yoast_tracking_cache' );
if ( !$data ) {
$pts = array();
foreach ( get_post_types( array( 'public' => true ) ) as $pt ) {
$count = wp_count_posts( $pt );
$pts[$pt] = $count->publish;
$pts = array();
$post_types = get_post_types( array( 'public' => true ) );
if ( is_array( $post_types ) && $post_types !== array() ) {
foreach ( $post_types as $post_type ) {
$count = wp_count_posts( $post_type );
$pts[ $post_type ] = $count->publish;
}
$comments_count = wp_count_comments();
// wp_get_theme was introduced in 3.4, for compatibility with older versions, let's do a workaround for now.
if ( function_exists( 'wp_get_theme' ) ) {
$theme_data = wp_get_theme();
$theme = array(
'name' => $theme_data->display( 'Name', false, false ),
'theme_uri' => $theme_data->display( 'ThemeURI', false, false ),
'version' => $theme_data->display( 'Version', false, false ),
'author' => $theme_data->display( 'Author', false, false ),
'author_uri' => $theme_data->display( 'AuthorURI', false, false ),
);
if ( isset( $theme_data->template ) && !empty( $theme_data->template ) && $theme_data->parent() ) {
$theme['template'] = array(
'version' => $theme_data->parent()->display( 'Version', false, false ),
'name' => $theme_data->parent()->display( 'Name', false, false ),
'theme_uri' => $theme_data->parent()->display( 'ThemeURI', false, false ),
'author' => $theme_data->parent()->display( 'Author', false, false ),
'author_uri' => $theme_data->parent()->display( 'AuthorURI', false, false ),
);
} else {
$theme['template'] = '';
}
} else {
$theme_data = (object) get_theme_data( get_stylesheet_directory() . '/style.css' );
$theme = array(
'version' => $theme_data->Version,
'name' => $theme_data->Name,
'author' => $theme_data->Author,
'template' => $theme_data->Template,
);
}
$plugins = array();
foreach ( get_option( 'active_plugins' ) as $plugin_path ) {
if ( !function_exists( 'get_plugin_data' ) )
require_once ABSPATH . 'wp-admin/includes/admin.php';
$plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_path );
$slug = str_replace( '/' . basename( $plugin_path ), '', $plugin_path );
$plugins[$slug] = array(
'version' => $plugin_info['Version'],
'name' => $plugin_info['Name'],
'plugin_uri' => $plugin_info['PluginURI'],
'author' => $plugin_info['AuthorName'],
'author_uri' => $plugin_info['AuthorURI'],
);
}
$data = array(
'site' => array(
'hash' => $hash,
'url' => site_url(),
'name' => get_bloginfo( 'name' ),
'version' => get_bloginfo( 'version' ),
'multisite' => is_multisite(),
'users' => $wpdb->get_var( "SELECT COUNT(*) FROM wp_users INNER JOIN wp_usermeta ON (wp_users.ID = wp_usermeta.user_id) WHERE 1 = 1 AND ( wp_usermeta.meta_key = 'wp_{$blog_id}_capabilities' ) " ),
'lang' => get_locale(),
),
'pts' => $pts,
'comments' => array(
'total' => $comments_count->total_comments,
'approved' => $comments_count->approved,
'spam' => $comments_count->spam,
'pings' => $wpdb->get_var( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_type = 'pingback'" ),
),
'options' => apply_filters( 'yoast_tracking_filters', array() ),
'theme' => $theme,
'plugins' => $plugins,
);
$args = array(
'body' => $data
);
wp_remote_post( 'https://tracking.yoast.com/', $args );
// Store for a week, then push data again.
set_transient( 'yoast_tracking_cache', true, 7 * 60 * 60 * 24 );
}
}
}
unset( $post_types );
$yoast_tracking = new Yoast_Tracking;
}
$comments_count = wp_count_comments();
$theme_data = wp_get_theme();
$theme = array(
'name' => $theme_data->display( 'Name', false, false ),
'theme_uri' => $theme_data->display( 'ThemeURI', false, false ),
'version' => $theme_data->display( 'Version', false, false ),
'author' => $theme_data->display( 'Author', false, false ),
'author_uri' => $theme_data->display( 'AuthorURI', false, false ),
);
$theme_template = $theme_data->get_template();
if ( $theme_template !== '' && $theme_data->parent() ) {
$theme['template'] = array(
'version' => $theme_data->parent()->display( 'Version', false, false ),
'name' => $theme_data->parent()->display( 'Name', false, false ),
'theme_uri' => $theme_data->parent()->display( 'ThemeURI', false, false ),
'author' => $theme_data->parent()->display( 'Author', false, false ),
'author_uri' => $theme_data->parent()->display( 'AuthorURI', false, false ),
);
} else {
$theme['template'] = '';
}
unset( $theme_template );
$plugins = array();
$active_plugin = get_option( 'active_plugins' );
foreach ( $active_plugin as $plugin_path ) {
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
$plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_path );
$slug = str_replace( '/' . basename( $plugin_path ), '', $plugin_path );
$plugins[ $slug ] = array(
'version' => $plugin_info['Version'],
'name' => $plugin_info['Name'],
'plugin_uri' => $plugin_info['PluginURI'],
'author' => $plugin_info['AuthorName'],
'author_uri' => $plugin_info['AuthorURI'],
);
}
unset( $active_plugins, $plugin_path );
$data = array(
'site' => array(
'hash' => $hash,
'version' => get_bloginfo( 'version' ),
'multisite' => is_multisite(),
'users' => $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->users INNER JOIN $wpdb->usermeta ON ({$wpdb->users}.ID = {$wpdb->usermeta}.user_id) WHERE 1 = 1 AND ( {$wpdb->usermeta}.meta_key = %s )", 'wp_' . $blog_id . '_capabilities' ) ),
'lang' => get_locale(),
),
'pts' => $pts,
'comments' => array(
'total' => $comments_count->total_comments,
'approved' => $comments_count->approved,
'spam' => $comments_count->spam,
'pings' => $wpdb->get_var( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_type = 'pingback'" ),
),
'options' => apply_filters( 'yoast_tracking_filters', array() ),
'theme' => $theme,
'plugins' => $plugins,
);
$args = array(
'body' => $data,
'blocking' => false,
'sslverify' => false,
);
wp_remote_post( 'https://tracking.yoast.com/', $args );
}
} /* End of class */
} /* End of class-exists wrapper */
/**
* Adds tracking parameters for WP SEO settings. Outside of the main class as the class could also be in use in other plugins.
*
* @param array $options
*
* @return array
*/
function wpseo_tracking_additions( $options ) {
$opt = get_wpseo_options();
if ( function_exists( 'curl_version' ) ) {
$curl = curl_version();
} else {
$curl = null;
}
$opt = WPSEO_Options::get_all();
$options['wpseo'] = array(
'xml_sitemaps' => isset( $opt['enablexmlsitemap'] ) ? 1 : 0,
'force_rewrite' => isset( $opt['forcerewritetitle'] ) ? 1 : 0,
'opengraph' => isset( $opt['opengraph'] ) ? 1 : 0,
'twitter' => isset( $opt['twitter'] ) ? 1 : 0,
'strip_category_base' => isset( $opt['stripcategorybase'] ) ? 1 : 0,
'on_front' => get_option( 'show_on_front' ),
'xml_sitemaps' => ( $opt['enablexmlsitemap'] === true ) ? 1 : 0,
'force_rewrite' => ( $opt['forcerewritetitle'] === true ) ? 1 : 0,
'opengraph' => ( $opt['opengraph'] === true ) ? 1 : 0,
'twitter' => ( $opt['twitter'] === true ) ? 1 : 0,
'strip_category_base' => ( $opt['stripcategorybase'] === true ) ? 1 : 0,
'on_front' => get_option( 'show_on_front' ),
'wmt_alexa' => ( ! empty( $opt['alexaverify'] ) ) ? 1 : 0,
'wmt_bing' => ( ! empty( $opt['msverify'] ) ) ? 1 : 0,
'wmt_google' => ( ! empty( $opt['googleverify'] ) ) ? 1 : 0,
'wmt_pinterest' => ( ! empty( $opt['pinterestverify'] ) ) ? 1 : 0,
'wmt_yandex' => ( ! empty( $opt['yandexverify'] ) ) ? 1 : 0,
'permalinks_clean' => ( $opt['cleanpermalinks'] == 1 ) ? 1 : 0,
'site_db_charset' => DB_CHARSET,
'webserver_apache' => wpseo_is_apache() ? 1 : 0,
'webserver_apache_version' => function_exists( 'apache_get_version' ) ? apache_get_version() : 0,
'webserver_nginx' => wpseo_is_nginx() ? 1 : 0,
'webserver_server_software' => $_SERVER['SERVER_SOFTWARE'],
'webserver_gateway_interface' => $_SERVER['GATEWAY_INTERFACE'],
'webserver_server_protocol' => $_SERVER['SERVER_PROTOCOL'],
'php_version' => phpversion(),
'php_max_execution_time' => ini_get( 'max_execution_time' ),
'php_memory_limit' => ini_get( 'memory_limit' ),
'php_open_basedir' => ini_get( 'open_basedir' ),
'php_bcmath_enabled' => extension_loaded( 'bcmath' ) ? 1 : 0,
'php_ctype_enabled' => extension_loaded( 'ctype' ) ? 1 : 0,
'php_curl_enabled' => extension_loaded( 'curl' ) ? 1 : 0,
'php_curl_version_a' => phpversion( 'curl' ),
'php_curl' => ( ! is_null( $curl ) ) ? $curl['version'] : 0,
'php_dom_enabled' => extension_loaded( 'dom' ) ? 1 : 0,
'php_dom_version' => phpversion( 'dom' ),
'php_filter_enabled' => extension_loaded( 'filter' ) ? 1 : 0,
'php_mbstring_enabled' => extension_loaded( 'mbstring' ) ? 1 : 0,
'php_mbstring_version' => phpversion( 'mbstring' ),
'php_pcre_enabled' => extension_loaded( 'pcre' ) ? 1 : 0,
'php_pcre_version' => phpversion( 'pcre' ),
'php_pcre_with_utf8_a' => @preg_match( '/^.{1}$/u', 'ñ', $UTF8_ar ),
'php_pcre_with_utf8_b' => defined( 'PREG_BAD_UTF8_ERROR' ),
'php_spl_enabled' => extension_loaded( 'spl' ) ? 1 : 0,
);
return $options;
}
add_filter( 'yoast_tracking_filters', 'wpseo_tracking_additions' );
add_filter( 'yoast_tracking_filters', 'wpseo_tracking_additions' );