diff options
Diffstat (limited to 'plugins/jetpack/class.jetpack.php')
-rw-r--r-- | plugins/jetpack/class.jetpack.php | 310 |
1 files changed, 198 insertions, 112 deletions
diff --git a/plugins/jetpack/class.jetpack.php b/plugins/jetpack/class.jetpack.php index 5c0f846d..0e9ce9ab 100644 --- a/plugins/jetpack/class.jetpack.php +++ b/plugins/jetpack/class.jetpack.php @@ -327,77 +327,17 @@ class Jetpack { * Must never be called statically */ function plugin_upgrade() { - // Upgrade: 1.1 -> 1.2 - if ( get_option( 'jetpack_id' ) ) { - // Move individual jetpack options to single array of options - $options = array(); - foreach ( Jetpack_Options::get_option_names() as $option ) { - if ( false !== $value = get_option( "jetpack_$option" ) ) { - $options[$option] = $value; - } - } - - if ( $options ) { - Jetpack_Options::update_options( $options ); - - foreach ( array_keys( $options ) as $option ) { - delete_option( "jetpack_$option" ); - } - } - - // Add missing version and old_version options - if ( ! $version = Jetpack_Options::get_option( 'version' ) ) { - $version = $old_version = '1.1:' . time(); - /** - * Fires on update, before bumping version numbers up to a new version. - * - * @since 3.4.0 - * - * @param string $version Jetpack version number. - * @param bool false Does an old version exist. Default is false. - */ - do_action( 'updating_jetpack_version', $version, false ); - Jetpack_Options::update_options( compact( 'version', 'old_version' ) ); - } - } - - // Upgrade from a single user token to a user_id-indexed array and a master_user ID - if ( ! Jetpack_Options::get_option( 'user_tokens' ) ) { - if ( $user_token = Jetpack_Options::get_option( 'user_token' ) ) { - $token_parts = explode( '.', $user_token ); - if ( isset( $token_parts[2] ) ) { - $master_user = $token_parts[2]; - $user_tokens = array( $master_user => $user_token ); - Jetpack_Options::update_options( compact( 'master_user', 'user_tokens' ) ); - Jetpack_Options::delete_option( 'user_token' ); - } else { - // @todo: is this even possible? - trigger_error( sprintf( 'Jetpack::plugin_upgrade found no user_id in user_token "%s"', $user_token ), E_USER_WARNING ); - } - } - } - - // Clean up legacy G+ Authorship data. - if ( get_option( 'gplus_authors' ) ) { - delete_option( 'gplus_authors' ); - delete_option( 'hide_gplus' ); - delete_metadata( 'post', 0, 'gplus_authorship_disabled', null, true ); - } - - if ( ! get_option( 'jetpack_private_options' ) ) { - $jetpack_options = get_option( 'jetpack_options', array() ); - foreach( Jetpack_Options::get_option_names( 'private' ) as $option_name ) { - if ( isset( $jetpack_options[ $option_name ] ) ) { - Jetpack_Options::update_option( $option_name, $jetpack_options[ $option_name ] ); - unset( $jetpack_options[ $option_name ] ); - } - } - update_option( 'jetpack_options', $jetpack_options ); - } - if ( Jetpack::is_active() ) { list( $version ) = explode( ':', Jetpack_Options::get_option( 'version' ) ); if ( JETPACK__VERSION != $version ) { + + // Check which active modules actually exist and remove others from active_modules list + $unfiltered_modules = Jetpack::get_active_modules(); + $modules = array_filter( $unfiltered_modules, array( 'Jetpack', 'is_module' ) ); + if ( array_diff( $unfiltered_modules, $modules ) ) { + Jetpack_Options::update_option( 'active_modules', $modules ); + } + add_action( 'init', array( __CLASS__, 'activate_new_modules' ) ); /** * Fires when synchronizing all registered options and constants. @@ -406,25 +346,7 @@ class Jetpack { */ do_action( 'jetpack_sync_all_registered_options' ); } - - //if Jetpack is connected check if jetpack_unique_connection exists and if not then set it - $jetpack_unique_connection = get_option( 'jetpack_unique_connection' ); - $is_unique_connection = $jetpack_unique_connection && array_key_exists( 'version', $jetpack_unique_connection ); - if ( ! $is_unique_connection ) { - $jetpack_unique_connection = array( - 'connected' => 1, - 'disconnected' => -1, - 'version' => '3.6.1' - ); - update_option( 'jetpack_unique_connection', $jetpack_unique_connection ); - } - } - - if ( get_option( 'jetpack_json_api_full_management' ) ) { - delete_option( 'jetpack_json_api_full_management' ); - self::activate_manage(); } - } static function activate_manage( ) { @@ -630,6 +552,9 @@ class Jetpack { add_action( 'wp_ajax_jetpack_admin_ajax', array( $this, 'jetpack_admin_ajax_callback' ) ); add_action( 'wp_ajax_jetpack_admin_ajax_refresh', array( $this, 'jetpack_admin_ajax_refresh_data' ) ); + // Universal ajax callback for all tracking events triggered via js + add_action( 'wp_ajax_jetpack_tracks', array( $this, 'jetpack_admin_ajax_tracks_callback' ) ); + add_action( 'wp_loaded', array( $this, 'register_assets' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'devicepx' ) ); add_action( 'customize_controls_enqueue_scripts', array( $this, 'devicepx' ) ); @@ -700,6 +625,26 @@ class Jetpack { } } + function jetpack_admin_ajax_tracks_callback() { + // Check for nonce + if ( ! isset( $_REQUEST['tracksNonce'] ) || ! wp_verify_nonce( $_REQUEST['tracksNonce'], 'jp-tracks-ajax-nonce' ) ) { + wp_die( 'Permissions check failed.' ); + } + + if ( ! isset( $_REQUEST['tracksEventName'] ) || ! isset( $_REQUEST['tracksEventType'] ) ) { + wp_die( 'No valid event name or type.' ); + } + + $tracks_data = array(); + if ( 'click' === $_REQUEST['tracksEventType'] && isset( $_REQUEST['tracksEventProp'] ) ) { + $tracks_data = array( 'clicked' => $_REQUEST['tracksEventProp'] ); + } + + JetpackTracking::record_user_event( $_REQUEST['tracksEventName'], $tracks_data ); + wp_send_json_success(); + wp_die(); + } + function jetpack_admin_ajax_callback() { // Check for nonce if ( ! isset( $_REQUEST['adminNonce'] ) || ! wp_verify_nonce( $_REQUEST['adminNonce'], 'jetpack-admin-nonce' ) || ! current_user_can( 'jetpack_manage_modules' ) ) { @@ -1043,6 +988,28 @@ class Jetpack { wp_register_script( 'jetpack-gallery-settings', plugins_url( '_inc/gallery-settings.js', JETPACK__PLUGIN_FILE ), array( 'media-views' ), '20121225' ); } + if ( ! wp_script_is( 'jetpack-twitter-timeline', 'registered' ) ) { + wp_register_script( 'jetpack-twitter-timeline', plugins_url( '_inc/twitter-timeline.js', JETPACK__PLUGIN_FILE ) , array( 'jquery' ), '3.10', true ); + } + + if ( ! wp_script_is( 'jetpack-facebook-embed', 'registered' ) ) { + wp_register_script( 'jetpack-facebook-embed', plugins_url( '_inc/facebook-embed.js', __FILE__ ), array( 'jquery' ), null, true ); + + /** This filter is documented in modules/sharedaddy/sharing-sources.php */ + $fb_app_id = apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ); + if ( ! is_numeric( $fb_app_id ) ) { + $fb_app_id = ''; + } + wp_localize_script( + 'jetpack-facebook-embed', + 'jpfbembed', + array( + 'appid' => $fb_app_id, + 'locale' => $this->get_locale(), + ) + ); + } + /** * As jetpack_register_genericons is by default fired off a hook, * the hook may have already fired by this point. @@ -1056,6 +1023,67 @@ class Jetpack { } /** + * Guess locale from language code. + * + * @param string $lang Language code. + * @return string|bool + */ + function guess_locale_from_lang( $lang ) { + if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) { + return 'en_US'; + } + + if ( ! class_exists( 'GP_Locales' ) ) { + if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { + return false; + } + + require JETPACK__GLOTPRESS_LOCALES_PATH; + } + + if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { + // WP.com: get_locale() returns 'it' + $locale = GP_Locales::by_slug( $lang ); + } else { + // Jetpack: get_locale() returns 'it_IT'; + $locale = GP_Locales::by_field( 'facebook_locale', $lang ); + } + + if ( ! $locale ) { + return false; + } + + if ( empty( $locale->facebook_locale ) ) { + if ( empty( $locale->wp_locale ) ) { + return false; + } else { + // Facebook SDK is smart enough to fall back to en_US if a + // locale isn't supported. Since supported Facebook locales + // can fall out of sync, we'll attempt to use the known + // wp_locale value and rely on said fallback. + return $locale->wp_locale; + } + } + + return $locale->facebook_locale; + } + + /** + * Get the locale. + * + * @return string|bool + */ + function get_locale() { + $locale = $this->guess_locale_from_lang( get_locale() ); + + if ( ! $locale ) { + $locale = 'en_US'; + } + + return $locale; + } + + /** * Device Pixels support * This improves the resolution of gravatars and wordpress.com uploads on hi-res and zoomed browsers. */ @@ -1473,7 +1501,7 @@ class Jetpack { /** * Filters Jetpack's development mode. * - * @see http://jetpack.me/support/development-mode/ + * @see http://jetpack.com/support/development-mode/ * * @since 2.2.1 * @@ -1494,19 +1522,19 @@ class Jetpack { $notice = sprintf( /* translators: %s is a URL */ __( 'In <a href="%s" target="_blank">Development Mode</a>, via the JETPACK_DEV_DEBUG constant being defined in wp-config.php or elsewhere.', 'jetpack' ), - 'http://jetpack.me/support/development-mode/' + 'http://jetpack.com/support/development-mode/' ); } elseif ( site_url() && false === strpos( site_url(), '.' ) ) { $notice = sprintf( /* translators: %s is a URL */ __( 'In <a href="%s" target="_blank">Development Mode</a>, via site URL lacking a dot (e.g. http://localhost).', 'jetpack' ), - 'http://jetpack.me/support/development-mode/' + 'http://jetpack.com/support/development-mode/' ); } else { $notice = sprintf( /* translators: %s is a URL */ __( 'In <a href="%s" target="_blank">Development Mode</a>, via the jetpack_development_mode filter.', 'jetpack' ), - 'http://jetpack.me/support/development-mode/' + 'http://jetpack.com/support/development-mode/' ); } @@ -1516,7 +1544,14 @@ class Jetpack { // Throw up a notice if using a development version and as for feedback. if ( Jetpack::is_development_version() ) { /* translators: %s is a URL */ - $notice = sprintf( __( 'You are currently running a development version of Jetpack. <a href="%s" target="_blank">Submit your feedback</a>', 'jetpack' ), 'https://jetpack.me/contact-support/beta-group/' ); + $notice = sprintf( __( 'You are currently running a development version of Jetpack. <a href="%s" target="_blank">Submit your feedback</a>', 'jetpack' ), 'https://jetpack.com/contact-support/beta-group/' ); + + echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; + } + // Throw up a notice if using staging mode + if ( Jetpack::is_staging_site() ) { + /* translators: %s is a URL */ + $notice = sprintf( __( 'You are running Jetpack on a <a href="%s" target="_blank">staging server</a>.', 'jetpack' ), 'https://jetpack.com/support/staging-sites/' ); echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; } @@ -1601,6 +1636,7 @@ class Jetpack { wp_oembed_add_provider( 'https://me.sh/*', 'https://me.sh/oembed?format=json' ); wp_oembed_add_provider( '#https?://(www\.)?gfycat\.com/.*#i', 'https://api.gfycat.com/v1/oembed', true ); wp_oembed_add_provider( '#https?://[^.]+\.(wistia\.com|wi\.st)/(medias|embed)/.*#', 'https://fast.wistia.com/oembed', true ); + wp_oembed_add_provider( '#https?://sketchfab\.com/.*#i', 'https://sketchfab.com/oembed', true ); } /** @@ -1694,7 +1730,7 @@ class Jetpack { $is_development_mode = Jetpack::is_development_mode(); - foreach ( $modules as $module ) { + foreach ( $modules as $index => $module ) { // If we're in dev mode, disable modules requiring a connection if ( $is_development_mode ) { // Prime the pump if we need to @@ -1711,7 +1747,12 @@ class Jetpack { continue; } - require Jetpack::get_module_path( $module ); + if ( ! @include( Jetpack::get_module_path( $module ) ) ) { + unset( $modules[ $index ] ); + Jetpack_Options::update_option( 'active_modules', array_values( $modules ) ); + continue; + } + /** * Fires when a specific module is loaded. * The dynamic part of the hook, $module, is the module slug. @@ -2537,10 +2578,38 @@ class Jetpack { return $data; } - public static function translate_module_tag( $untranslated_tag ) { - // Tags are aggregated by tools/build-module-headings-translations.php - // and output in modules/module-headings.php - return _x( $untranslated_tag, 'Module Tag', 'jetpack' ); + /** + * Return translated module tag. + * + * @param string $tag Tag as it appears in each module heading. + * + * @return mixed + */ + public static function translate_module_tag( $tag ) { + return jetpack_get_module_i18n_tag( $tag ); + } + + /** + * Return module name translation. Uses matching string created in modules/module-headings.php. + * + * @since 3.9.2 + * + * @param array $modules + * + * @return string|void + */ + public static function get_translated_modules( $modules ) { + foreach ( $modules as $index => $module ) { + $i18n_module = jetpack_get_module_i18n( $module['module'] ); + if ( isset( $module['name'] ) ) { + $modules[ $index ]['name'] = $i18n_module['name']; + } + if ( isset( $module['description'] ) ) { + $modules[ $index ]['description'] = $i18n_module['description']; + $modules[ $index ]['short_description'] = $i18n_module['description']; + } + } + return $modules; } /** @@ -3550,8 +3619,8 @@ p { // Help Sidebar $current_screen->set_help_sidebar( '<p><strong>' . __( 'For more information:', 'jetpack' ) . '</strong></p>' . - '<p><a href="http://jetpack.me/faq/" target="_blank">' . __( 'Jetpack FAQ', 'jetpack' ) . '</a></p>' . - '<p><a href="http://jetpack.me/support/" target="_blank">' . __( 'Jetpack Support', 'jetpack' ) . '</a></p>' . + '<p><a href="http://jetpack.com/faq/" target="_blank">' . __( 'Jetpack FAQ', 'jetpack' ) . '</a></p>' . + '<p><a href="http://jetpack.com/support/" target="_blank">' . __( 'Jetpack Support', 'jetpack' ) . '</a></p>' . '<p><a href="' . Jetpack::admin_url( array( 'page' => 'jetpack-debugger' ) ) .'">' . __( 'Jetpack Debugging Center', 'jetpack' ) . '</a></p>' ); } @@ -3643,7 +3712,7 @@ p { <p><?php _e( 'Connect now to enable features like Stats, Likes, and Social Sharing.', 'jetpack' ); ?></p> </div> <div class="jp-banner__action-container is-connection"> - <a href="<?php echo $this->build_connect_url() ?>" class="jp-banner__button" id="wpcom-connect"><?php _e( 'Connect to WordPress.com', 'jetpack' ); ?></a> + <a href="<?php echo $this->build_connect_url( false, false, 'banner' ) ?>" class="jp-banner__button" id="wpcom-connect"><?php _e( 'Connect to WordPress.com', 'jetpack' ); ?></a> </div> <?php else : ?> <div class="jp-banner__content"> @@ -3692,7 +3761,7 @@ p { <a class="jp-banner__dismiss" href="<?php echo esc_url( $opt_out_url ); ?>" title="<?php esc_attr_e( 'Dismiss this notice for now.', 'jetpack' ); ?>"></a> <div class="jp-banner__content"> <h2><?php esc_html_e( 'New in Jetpack: Centralized Site Management', 'jetpack' ); ?></h2> - <p><?php printf( __( 'Manage multiple sites from one dashboard at wordpress.com/sites. Enabling allows all existing, connected Administrators to modify your site from WordPress.com. <a href="%s" target="_blank">Learn More</a>.', 'jetpack' ), 'http://jetpack.me/support/site-management' ); ?></p> + <p><?php printf( __( 'Manage multiple sites from one dashboard at wordpress.com/sites. Enabling allows all existing, connected Administrators to modify your site from WordPress.com. <a href="%s" target="_blank">Learn More</a>.', 'jetpack' ), 'http://jetpack.com/support/site-management' ); ?></p> </div> <div class="jp-banner__action-container is-opt-in"> <a href="<?php echo esc_url( $opt_in_url ); ?>" class="jp-banner__button" id="wpcom-connect"><?php _e( 'Activate now', 'jetpack' ); ?></a> @@ -3721,7 +3790,7 @@ p { ?> <div class="wrap"> <div id="message" class="jetpack-message is-opt-in"> - <?php echo sprintf( __( '<p><a href="%1$s" title="Opt in to WordPress.com Site Management" >Activate Site Management</a> to manage multiple sites from our centralized dashboard at wordpress.com/sites. <a href="%2$s" target="_blank">Learn more</a>.</p><a href="%1$s" class="jp-button">Activate Now</a>', 'jetpack' ), $this->opt_in_jetpack_manage_url(), 'http://jetpack.me/support/site-management' ); ?> + <?php echo sprintf( __( '<p><a href="%1$s" title="Opt in to WordPress.com Site Management" >Activate Site Management</a> to manage multiple sites from our centralized dashboard at wordpress.com/sites. <a href="%2$s" target="_blank">Learn more</a>.</p><a href="%1$s" class="jp-button">Activate Now</a>', 'jetpack' ), $this->opt_in_jetpack_manage_url(), 'http://jetpack.com/support/site-management' ); ?> </div> </div> <?php @@ -3813,7 +3882,7 @@ p { <br /> <?php echo sprintf( __( 'Would you tell us why? Just <a href="%1$s" target="%2$s">answering two simple questions</a> would help us improve Jetpack.', 'jetpack' ), - 'https://jetpack.me/survey-disconnected/', + 'https://jetpack.com/survey-disconnected/', '_blank' ); ?> </h2> @@ -3874,7 +3943,7 @@ p { if ( isset( $_GET['connect_url_redirect'] ) ) { // User clicked in the iframe to link their accounts if ( ! Jetpack::is_user_connected() ) { - $connect_url = $this->build_connect_url( true ); + $connect_url = $this->build_connect_url( true, false, 'iframe' ); if ( isset( $_GET['notes_iframe'] ) ) $connect_url .= '¬es_iframe'; wp_redirect( $connect_url ); @@ -3914,7 +3983,7 @@ p { break; } - wp_redirect( $this->build_connect_url( true ) ); + wp_redirect( $this->build_connect_url( true, false, 'error-desc' ) ); exit; case 'activate' : if ( ! current_user_can( 'jetpack_activate_modules' ) ) { @@ -3959,7 +4028,7 @@ p { check_admin_referer( 'jetpack-reconnect' ); Jetpack::log( 'reconnect' ); $this->disconnect(); - wp_redirect( $this->build_connect_url( true ) ); + wp_redirect( $this->build_connect_url( true, false, 'reconnect' ) ); exit; case 'deactivate' : if ( ! current_user_can( 'jetpack_deactivate_modules' ) ) { @@ -4515,7 +4584,20 @@ p { return $role . ':' . hash_hmac( 'md5', "{$role}|{$user_id}", $token->secret ); } - function build_connect_url( $raw = false, $redirect = false ) { + + /** + * Builds a URL to the Jetpack connection auth page + * + * @since 3.9.5 + * + * @param bool $raw If true, URL will not be escaped. + * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. + * If string, will be a custom redirect. + * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. + * + * @return string Connect URL + */ + function build_connect_url( $raw = false, $redirect = false, $from = false ) { if ( ! Jetpack_Options::get_option( 'blog_token' ) || ! Jetpack_Options::get_option( 'id' ) ) { $url = Jetpack::nonce_url_no_esc( Jetpack::admin_url( 'action=register' ), 'jetpack-register' ); if( is_network_admin() ) { @@ -4558,6 +4640,9 @@ p { $url = add_query_arg( $args, Jetpack::api_url( 'authorize' ) ); } + if ( $from ) { + $url = add_query_arg( 'from', $from, $url ); + } return $raw ? $url : esc_url( $url ); } @@ -4745,7 +4830,7 @@ p { $activate_url = Jetpack::init()->opt_in_jetpack_manage_url(); - $info['description'] = sprintf( __( 'Manage your multiple Jetpack sites from our centralized dashboard at wordpress.com/sites. <a href="%s" target="_blank">Learn more</a>.', 'jetpack' ), 'http://jetpack.me/support/site-management' ); + $info['description'] = sprintf( __( 'Manage your multiple Jetpack sites from our centralized dashboard at wordpress.com/sites. <a href="%s" target="_blank">Learn more</a>.', 'jetpack' ), 'http://jetpack.com/support/site-management' ); // $extra = __( 'To use Site Management, you need to first activate JSON API to allow remote management of your site. ', 'jetpack' ); } ?> @@ -6035,6 +6120,7 @@ p { ), 'constants' => array( 'IS_WPE_SNAPSHOT', + 'JETPACK_STAGING_MODE', ) ); /** @@ -6228,7 +6314,7 @@ p { <div class="banner-content"> <p><?php /* translators: %s is a URL */ - printf( __( 'Our records show that this site does not have a valid connection to WordPress.com. Please reset your connection to fix this. <a href="%s" target="_blank">What caused this?</a>', 'jetpack' ), 'https://jetpack.me/support/no-valid-wordpress-com-connection/' ); + printf( __( 'Our records show that this site does not have a valid connection to WordPress.com. Please reset your connection to fix this. <a href="%s" target="_blank">What caused this?</a>', 'jetpack' ), 'https://jetpack.com/support/no-valid-wordpress-com-connection/' ); ?></p> </div> <div class="jp-btn-group"> @@ -6257,13 +6343,13 @@ p { ), $errors[ $key ], (string) get_option( $key ), - 'https://jetpack.me/support/what-does-resetting-the-connection-mean/' + 'https://jetpack.com/support/what-does-resetting-the-connection-mean/' ); ?></p> </div> <div class="jp-btn-group"> <a href="#" class="reset-connection"><?php _e( 'Reset the connection', 'jetpack' ); ?></a> <span class="idc-separator">|</span> <a href="#" class="is-dev-env"><?php _e( 'This is a development environment', 'jetpack' ); ?></a> <span class="idc-separator">|</span> - <a href="https://jetpack.me/contact-support/" class="contact-support"><?php _e( 'Submit a support ticket', 'jetpack' ); ?></a> + <a href="https://jetpack.com/contact-support/" class="contact-support"><?php _e( 'Submit a support ticket', 'jetpack' ); ?></a> <span class="spinner"></span> </div> </div> @@ -6948,7 +7034,7 @@ p { <p><?php echo wp_kses( __( 'Connecting Jetpack will show you <strong>stats</strong> about your traffic, <strong>protect</strong> you from brute force attacks, <strong>speed up</strong> your images and photos, and enable other <strong>traffic and security</strong> features.', 'jetpack' ), 'jetpack' ) ?></p> <div class="actions"> - <a href="<?php echo $this->build_connect_url() ?>" class="button button-primary"> + <a href="<?php echo $this->build_connect_url( false, false, 'widget-btn' ); ?>" class="button button-primary"> <?php esc_html_e( 'Connect Jetpack', 'jetpack' ); ?> </a> </div> |