summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack')
-rw-r--r--plugins/jetpack/_inc/genericons.css149
-rw-r--r--plugins/jetpack/class.jetpack-bbpress-json-api-compat.php108
-rw-r--r--plugins/jetpack/class.jetpack-client-server.php219
-rw-r--r--plugins/jetpack/class.jetpack-client.php215
-rw-r--r--plugins/jetpack/class.jetpack-data.php42
-rw-r--r--plugins/jetpack/class.jetpack-debugger.php353
-rw-r--r--plugins/jetpack/class.jetpack-error.php3
-rw-r--r--plugins/jetpack/class.jetpack-heartbeat.php131
-rw-r--r--plugins/jetpack/class.jetpack-options.php143
-rw-r--r--plugins/jetpack/class.jetpack-sync.php713
-rw-r--r--plugins/jetpack/class.jetpack.php3684
-rw-r--r--plugins/jetpack/languages/jetpack-uk.mobin0 -> 9961 bytes
-rw-r--r--plugins/jetpack/modules/contact-form/css/menu-alter.css56
-rw-r--r--plugins/jetpack/modules/contact-form/css/rtl/grunion-rtl.css12
-rw-r--r--plugins/jetpack/modules/contact-form/css/rtl/menu-alter-rtl.css62
-rw-r--r--plugins/jetpack/modules/contact-form/grunion-omnisearch.php65
-rw-r--r--plugins/jetpack/modules/contact-form/js/grunion-frontend.js3
-rw-r--r--plugins/jetpack/modules/custom-css/custom-css/css/ace.css25
-rw-r--r--plugins/jetpack/modules/custom-css/custom-css/css/css-editor.css24
-rw-r--r--plugins/jetpack/modules/custom-css/custom-css/js/ace/mode-less.js1
-rw-r--r--plugins/jetpack/modules/custom-css/custom-css/js/ace/mode-scss.js1
-rw-r--r--plugins/jetpack/modules/custom-css/custom-css/js/css-editor.js81
-rw-r--r--plugins/jetpack/modules/infinite-scroll/themes/twentythirteen.css90
-rw-r--r--plugins/jetpack/modules/infinite-scroll/themes/twentythirteen.php26
-rw-r--r--plugins/jetpack/modules/likes/post-count.js69
-rw-r--r--plugins/jetpack/modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.eotbin0 -> 7475 bytes
-rw-r--r--plugins/jetpack/modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.svg81
-rw-r--r--plugins/jetpack/modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.ttfbin0 -> 13516 bytes
-rw-r--r--plugins/jetpack/modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.woffbin0 -> 8676 bytes
-rw-r--r--plugins/jetpack/modules/omnisearch.php14
-rw-r--r--plugins/jetpack/modules/omnisearch/omnisearch-comments.php48
-rw-r--r--plugins/jetpack/modules/omnisearch/omnisearch-core.php181
-rw-r--r--plugins/jetpack/modules/omnisearch/omnisearch-jetpack.css35
-rw-r--r--plugins/jetpack/modules/omnisearch/omnisearch-plugins.php61
-rw-r--r--plugins/jetpack/modules/omnisearch/omnisearch-posts.php122
-rw-r--r--plugins/jetpack/modules/omnisearch/omnisearch.css126
-rw-r--r--plugins/jetpack/modules/omnisearch/rtl/omnisearch-jetpack-rtl.css37
-rw-r--r--plugins/jetpack/modules/omnisearch/rtl/omnisearch-rtl.css128
-rw-r--r--plugins/jetpack/modules/sharedaddy/images/kindle.pngbin0 -> 1843 bytes
-rw-r--r--plugins/jetpack/modules/sharedaddy/images/kindle@2x.pngbin0 -> 1563 bytes
-rw-r--r--plugins/jetpack/modules/sharedaddy/images/pocket.pngbin0 -> 1288 bytes
-rw-r--r--plugins/jetpack/modules/sharedaddy/images/pocket@2x.pngbin0 -> 1425 bytes
-rw-r--r--plugins/jetpack/modules/sharedaddy/images/smart-pocket.pngbin0 -> 1494 bytes
-rw-r--r--plugins/jetpack/modules/sharedaddy/images/smart-pocket@2x.pngbin0 -> 2125 bytes
-rw-r--r--plugins/jetpack/modules/shortcodes/bandcamp.php142
-rw-r--r--plugins/jetpack/modules/social-links.php10
-rw-r--r--plugins/jetpack/modules/social-links/social-links.php169
-rw-r--r--plugins/jetpack/modules/widgets/twitter-timeline.php214
48 files changed, 7643 insertions, 0 deletions
diff --git a/plugins/jetpack/_inc/genericons.css b/plugins/jetpack/_inc/genericons.css
new file mode 100644
index 00000000..599002c0
--- /dev/null
+++ b/plugins/jetpack/_inc/genericons.css
@@ -0,0 +1,149 @@
+/* =Webfont, thanks to FontSquirrel.com for conversion!
+-------------------------------------------------------------- */
+@font-face {
+ font-family: 'Genericons';
+ src: url('../modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.eot');
+ src: url('../modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.eot?#iefix') format('embedded-opentype'),
+ url('../modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.woff') format('woff'),
+ url('../modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.ttf') format('truetype'),
+ url('../modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.svg#genericonsregular') format('svg');
+ font-weight: normal;
+ font-style: normal;
+}
+
+/**
+ * All Genericons
+ */
+
+.genericon {
+ display: inline-block;
+ width: 16px;
+ height: 16px;
+ -webkit-font-smoothing: antialiased;
+ font-size: 16px;
+ line-height: 1;
+ font-family: 'Genericons';
+ text-decoration: inherit;
+ font-weight: normal;
+ font-style: normal;
+ vertical-align: top;
+}
+
+/**
+ * IE7 and IE6 hacks
+ */
+
+.genericon {
+ *overflow: auto;
+ *zoom: 1;
+ *display: inline;
+}
+
+/**
+ * Individual icons
+ */
+
+/* Post formats */
+.genericon-standard:before { content: '\f100'; }
+.genericon-aside:before { content: '\f101'; }
+.genericon-image:before { content: '\f102'; }
+.genericon-gallery:before { content: '\f103'; }
+.genericon-video:before { content: '\f104'; }
+.genericon-status:before { content: '\f105'; }
+.genericon-quote:before { content: '\f106'; }
+.genericon-link:before { content: '\f107'; }
+.genericon-chat:before { content: '\f108'; }
+.genericon-audio:before { content: '\f109'; }
+
+/* Social icons */
+.genericon-github:before { content: '\f200'; }
+.genericon-dribbble:before { content: '\f201'; }
+.genericon-twitter:before { content: '\f202'; }
+.genericon-facebook:before { content: '\f203'; }
+.genericon-facebook-alt:before { content: '\f204'; }
+.genericon-wordpress:before { content: '\f205'; }
+.genericon-googleplus:before { content: '\f206'; }
+.genericon-linkedin:before { content: '\f207'; }
+.genericon-linkedin-alt:before { content: '\f208'; }
+.genericon-pinterest:before { content: '\f209'; }
+.genericon-pinterest-alt:before { content: '\f210'; }
+.genericon-flickr:before { content: '\f211'; }
+.genericon-vimeo:before { content: '\f212'; }
+.genericon-youtube:before { content: '\f213'; }
+.genericon-tumblr:before { content: '\f214'; }
+.genericon-instagram:before { content: '\f215'; }
+.genericon-codepen:before { content: '\f216'; }
+
+/* Meta icons */
+.genericon-comment:before { content: '\f300'; }
+.genericon-category:before { content: '\f301'; }
+.genericon-tag:before { content: '\f302'; }
+.genericon-time:before { content: '\f303'; }
+.genericon-user:before { content: '\f304'; }
+.genericon-day:before { content: '\f305'; }
+.genericon-week:before { content: '\f306'; }
+.genericon-month:before { content: '\f307'; }
+.genericon-pinned:before { content: '\f308'; }
+
+/* Other icons */
+.genericon-search:before { content: '\f400'; }
+.genericon-unzoom:before { content: '\f401'; }
+.genericon-zoom:before { content: '\f402'; }
+.genericon-show:before { content: '\f403'; }
+.genericon-hide:before { content: '\f404'; }
+.genericon-close:before { content: '\f405'; }
+.genericon-close-alt:before { content: '\f406'; }
+.genericon-trash:before { content: '\f407'; }
+.genericon-star:before { content: '\f408'; }
+.genericon-home:before { content: '\f409'; }
+.genericon-mail:before { content: '\f410'; }
+.genericon-edit:before { content: '\f411'; }
+.genericon-reply:before { content: '\f412'; }
+.genericon-feed:before { content: '\f413'; }
+.genericon-warning:before { content: '\f414'; }
+.genericon-share:before { content: '\f415'; }
+.genericon-attachment:before { content: '\f416'; }
+.genericon-location:before { content: '\f417'; }
+.genericon-checkmark:before { content: '\f418'; }
+.genericon-menu:before { content: '\f419'; }
+.genericon-top:before { content: '\f420'; }
+.genericon-minimize:before { content: '\f421'; }
+.genericon-maximize:before { content: '\f422'; }
+.genericon-404:before { content: '\f423'; }
+.genericon-spam:before { content: '\f424'; }
+.genericon-summary:before { content: '\f425'; }
+.genericon-cloud:before { content: '\f426'; }
+.genericon-key:before { content: '\f427'; }
+.genericon-dot:before { content: '\f428'; }
+.genericon-next:before { content: '\f429'; }
+.genericon-previous:before { content: '\f430'; }
+.genericon-expand:before { content: '\f431'; }
+.genericon-collapse:before { content: '\f432'; }
+.genericon-dropdown:before { content: '\f433'; }
+.genericon-dropdown-left:before { content: '\f434'; }
+.genericon-top:before { content: '\f435'; }
+.genericon-draggable:before { content: '\f436'; }
+.genericon-phone:before { content: '\f437'; }
+.genericon-send-to-phone:before { content: '\f438'; }
+.genericon-plugin:before { content: '\f439'; }
+.genericon-cloud-download:before { content: '\f440'; }
+.genericon-cloud-upload:before { content: '\f441'; }
+.genericon-external:before { content: '\f442'; }
+.genericon-document:before { content: '\f443'; }
+.genericon-book:before { content: '\f444'; }
+.genericon-cog:before { content: '\f445'; }
+.genericon-unapprove:before { content: '\f446'; }
+.genericon-cart:before { content: '\f447'; }
+.genericon-pause:before { content: '\f448'; }
+.genericon-stop:before { content: '\f449'; }
+.genericon-skip-back:before { content: '\f450'; }
+.genericon-skip-ahead:before { content: '\f451'; }
+.genericon-play:before { content: '\f452'; }
+.genericon-tablet:before { content: '\f453'; }
+.genericon-send-to-tablet:before { content: '\f454'; }
+
+/* Generic shapes */
+.genericon-uparrow:before { content: '\f500'; }
+.genericon-rightarrow:before { content: '\f501'; }
+.genericon-downarrow:before { content: '\f502'; }
+.genericon-leftarrow:before { content: '\f503'; }
diff --git a/plugins/jetpack/class.jetpack-bbpress-json-api-compat.php b/plugins/jetpack/class.jetpack-bbpress-json-api-compat.php
new file mode 100644
index 00000000..3c7935df
--- /dev/null
+++ b/plugins/jetpack/class.jetpack-bbpress-json-api-compat.php
@@ -0,0 +1,108 @@
+<?php
+/**
+* bbPress & Jetpack REST API Compatibility
+* Enables bbPress to work with the Jetpack REST API
+*/
+class bbPress_Jetpack_REST_API {
+
+ private static $instance;
+
+ public static function instance() {
+ if ( isset( self::$instance ) )
+ return self::$instance;
+
+ self::$instance = new self;
+ }
+
+ private function __construct() {
+ add_filter( 'rest_api_allowed_post_types', array( $this, 'allow_bbpress_post_types' ) );
+ add_filter( 'bbp_map_meta_caps', array( $this, 'adjust_meta_caps' ), 10, 4 );
+ add_filter( 'rest_api_allowed_public_metadata', array( $this, 'allow_bbpress_public_metadata' ) );
+ }
+
+ function allow_bbpress_post_types( $allowed_post_types ) {
+
+ // only run for REST API requests
+ if ( ! defined( 'REST_API_REQUEST' ) || ! REST_API_REQUEST )
+ return $allowed_post_types;
+
+ $allowed_post_types[] = 'forum';
+ $allowed_post_types[] = 'topic';
+ $allowed_post_types[] = 'reply';
+ return $allowed_post_types;
+ }
+
+ function allow_bbpress_public_metadata( $allowed_meta_keys ) {
+
+ // only run for REST API requests
+ if ( ! defined( 'REST_API_REQUEST' ) || ! REST_API_REQUEST )
+ return $allowed_meta_keys;
+
+ $allowed_meta_keys[] = '_bbp_forum_id';
+ $allowed_meta_keys[] = '_bbp_topic_id';
+ $allowed_meta_keys[] = '_bbp_status';
+ $allowed_meta_keys[] = '_bbp_forum_type';
+ $allowed_meta_keys[] = '_bbp_forum_subforum_count';
+ $allowed_meta_keys[] = '_bbp_reply_count';
+ $allowed_meta_keys[] = '_bbp_total_reply_count';
+ $allowed_meta_keys[] = '_bbp_topic_count';
+ $allowed_meta_keys[] = '_bbp_total_topic_count';
+ $allowed_meta_keys[] = '_bbp_topic_count_hidden';
+ $allowed_meta_keys[] = '_bbp_last_topic_id';
+ $allowed_meta_keys[] = '_bbp_last_reply_id';
+ $allowed_meta_keys[] = '_bbp_last_active_time';
+ $allowed_meta_keys[] = '_bbp_last_active_id';
+ $allowed_meta_keys[] = '_bbp_sticky_topics';
+ $allowed_meta_keys[] = '_bbp_voice_count';
+ $allowed_meta_keys[] = '_bbp_reply_count_hidden';
+ $allowed_meta_keys[] = '_bbp_anonymous_reply_count';
+
+ return $allowed_meta_keys;
+ }
+
+ function adjust_meta_caps( $caps, $cap, $user_id, $args ) {
+
+ // only run for REST API requests
+ if ( ! defined( 'REST_API_REQUEST' ) || ! REST_API_REQUEST )
+ return $caps;
+
+ // only modify caps for meta caps and for bbPress meta keys
+ if ( ! in_array( $cap, array( 'edit_post_meta', 'delete_post_meta', 'add_post_meta' ) ) || empty( $args[1] ) || false === strpos( $args[1], '_bbp_' ) )
+ return $caps;
+
+ // $args[0] could be a post ID or a post_type string
+ if ( is_int( $args[0] ) ) {
+ $_post = get_post( $args[0] );
+ if ( ! empty( $_post ) ) {
+ $post_type = get_post_type_object( $_post->post_type );
+ }
+ } elseif ( is_string( $args[0] ) ) {
+ $post_type = get_post_type_object( $args[0] );
+ }
+
+ // no post type found, bail
+ if ( empty( $post_type ) )
+ return $caps;
+
+ // reset the needed caps
+ $caps = array();
+
+ // Add 'do_not_allow' cap if user is spam or deleted
+ if ( bbp_is_user_inactive( $user_id ) ) {
+ $caps[] = 'do_not_allow';
+
+ // Moderators can always edit meta
+ } elseif ( user_can( $user_id, 'moderate' ) ) {
+ $caps[] = 'moderate';
+
+ // Unknown so map to edit_posts
+ } else {
+ $caps[] = $post_type->cap->edit_posts;
+ }
+
+ return $caps;
+ }
+
+}
+
+bbPress_Jetpack_REST_API::instance();
diff --git a/plugins/jetpack/class.jetpack-client-server.php b/plugins/jetpack/class.jetpack-client-server.php
new file mode 100644
index 00000000..1c0fe25e
--- /dev/null
+++ b/plugins/jetpack/class.jetpack-client-server.php
@@ -0,0 +1,219 @@
+<?php
+
+/**
+ * Client = Plugin
+ * Client Server = API Methods the Plugin must respond to
+ *
+ * @todo Roll this into Jetpack? There's only one 'public' method now: ::authorize().
+ */
+class Jetpack_Client_Server {
+ function authorize() {
+ $data = stripslashes_deep( $_GET );
+
+ $args = array();
+
+ $redirect = isset( $data['redirect'] ) ? esc_url_raw( (string) $data['redirect'] ) : '';
+
+ do {
+ $jetpack = Jetpack::init();
+ $role = $jetpack->translate_current_user_to_role();
+ if ( !$role ) {
+ Jetpack::state( 'error', 'no_role' );
+ break;
+ }
+
+ $cap = $jetpack->translate_role_to_cap( $role );
+ if ( !$cap ) {
+ Jetpack::state( 'error', 'no_cap' );
+ break;
+ }
+
+ check_admin_referer( "jetpack-authorize_{$role}_{$redirect}" );
+
+ if ( !empty( $data['error'] ) ) {
+ Jetpack::state( 'error', $data['error'] );
+ break;
+ }
+
+ if ( empty( $data['state'] ) ) {
+ Jetpack::state( 'error', 'no_state' );
+ break;
+ }
+
+ if ( !ctype_digit( $data['state'] ) ) {
+ Jetpack::state( 'error', 'invalid_state' );
+ break;
+ }
+
+ $current_user_id = get_current_user_id();
+ if ( $current_user_id != $data['state'] ) {
+ Jetpack::state( 'error', 'wrong_state' );
+ break;
+ }
+
+ if ( empty( $data['code'] ) ) {
+ Jetpack::state( 'error', 'no_code' );
+ break;
+ }
+
+ $token = $this->get_token( $data );
+
+ if ( is_wp_error( $token ) ) {
+ if ( $error = $token->get_error_code() )
+ Jetpack::state( 'error', $error );
+ else
+ Jetpack::state( 'error', 'invalid_token' );
+
+ Jetpack::state( 'error_description', $token->get_error_message() );
+
+ break;
+ }
+
+ if ( !$token ) {
+ Jetpack::state( 'error', 'no_token' );
+ break;
+ }
+
+ $is_master_user = ! Jetpack::is_active();
+
+ Jetpack::update_user_token( $current_user_id, sprintf( '%s.%d', $token, $current_user_id ), $is_master_user );
+
+
+ if ( $is_master_user ) {
+ Jetpack::state( 'message', 'authorized' );
+ } else {
+ Jetpack::state( 'message', 'linked' );
+ // Don't activate anything since we are just connecting a user.
+ break;
+ }
+
+ if ( $active_modules = Jetpack::get_option( 'active_modules' ) ) {
+ Jetpack::delete_option( 'active_modules' );
+
+ Jetpack::activate_default_modules( 999, 1, $active_modules );
+ } else {
+ Jetpack::activate_default_modules();
+ }
+
+ $jetpack->sync->register( 'noop' ); // Spawn a sync to make sure the Jetpack Servers know what modules are active.
+
+ // Start nonce cleaner
+ wp_clear_scheduled_hook( 'jetpack_clean_nonces' );
+ wp_schedule_event( time(), 'hourly', 'jetpack_clean_nonces' );
+ } while ( false );
+
+ if ( wp_validate_redirect( $redirect ) ) {
+ wp_safe_redirect( $redirect );
+ } else {
+ wp_safe_redirect( Jetpack::admin_url() );
+ }
+
+ exit;
+ }
+
+ public static function deactivate_plugin( $probable_file, $probable_title ) {
+ if ( is_plugin_active( $probable_file ) ) {
+ deactivate_plugins( $probable_file );
+ return 1;
+ } else {
+ // If the plugin is not in the usual place, try looking through all active plugins.
+ $active_plugins = get_option( 'active_plugins', array() );
+ foreach ( $active_plugins as $plugin ) {
+ $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
+ if ( $data['Name'] == $probable_title ) {
+ deactivate_plugins( $plugin );
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+ }
+
+ /**
+ * @return object|WP_Error
+ */
+ function get_token( $data ) {
+ $jetpack = Jetpack::init();
+ $role = $jetpack->translate_current_user_to_role();
+
+ if ( !$role ) {
+ return new Jetpack_Error( 'role', __( 'An administrator for this blog must set up the Jetpack connection.', 'jetpack' ) );
+ }
+
+ $client_secret = Jetpack_Data::get_access_token();
+ if ( !$client_secret ) {
+ return new Jetpack_Error( 'client_secret', __( 'You need to register your Jetpack before connecting it.', 'jetpack' ) );
+ }
+
+ $redirect = isset( $data['redirect'] ) ? esc_url_raw( (string) $data['redirect'] ) : '';
+
+ $body = array(
+ 'client_id' => Jetpack::get_option( 'id' ),
+ 'client_secret' => $client_secret->secret,
+ 'grant_type' => 'authorization_code',
+ 'code' => $data['code'],
+ 'redirect_uri' => add_query_arg( array(
+ 'action' => 'authorize',
+ '_wpnonce' => wp_create_nonce( "jetpack-authorize_{$role}_{$redirect}" ),
+ 'redirect' => $redirect ? urlencode( $redirect ) : false,
+ ), menu_page_url( 'jetpack', false ) ),
+ );
+
+ $args = array(
+ 'method' => 'POST',
+ 'body' => $body,
+ 'headers' => array(
+ 'Accept' => 'application/json',
+ ),
+ );
+ $response = Jetpack_Client::_wp_remote_request( Jetpack::fix_url_for_bad_hosts( Jetpack::api_url( 'token' ), $args ), $args );
+
+ if ( is_wp_error( $response ) ) {
+ return new Jetpack_Error( 'token_http_request_failed', $response->get_error_message() );
+ }
+
+ $code = wp_remote_retrieve_response_code( $response );
+ $entity = wp_remote_retrieve_body( $response );
+
+ if ( $entity )
+ $json = json_decode( $entity );
+ else
+ $json = false;
+
+ if ( 200 != $code || !empty( $json->error ) ) {
+ if ( empty( $json->error ) )
+ return new Jetpack_Error( 'unknown', '', $code );
+
+ $error_description = isset( $json->error_description ) ? sprintf( __( 'Error Details: %s', 'jetpack' ), (string) $json->error_description ) : '';
+
+ return new Jetpack_Error( (string) $json->error, $error_description, $code );
+ }
+
+ if ( empty( $json->access_token ) || !is_scalar( $json->access_token ) ) {
+ return new Jetpack_Error( 'access_token', '', $code );
+ }
+
+ if ( empty( $json->token_type ) || 'X_JETPACK' != strtoupper( $json->token_type ) ) {
+ return new Jetpack_Error( 'token_type', '', $code );
+ }
+
+ if ( empty( $json->scope ) ) {
+ return new Jetpack_Error( 'scope', 'No Scope', $code );
+ }
+ @list( $role, $hmac ) = explode( ':', $json->scope );
+ if ( empty( $role ) || empty( $hmac ) ) {
+ return new Jetpack_Error( 'scope', 'Malformed Scope', $code );
+ }
+ if ( $jetpack->sign_role( $role ) !== $json->scope ) {
+ return new Jetpack_Error( 'scope', 'Invalid Scope', $code );
+ }
+
+ if ( !$cap = $jetpack->translate_role_to_cap( $role ) )
+ return new Jetpack_Error( 'scope', 'No Cap', $code );
+ if ( !current_user_can( $cap ) )
+ return new Jetpack_Error( 'scope', 'current_user_cannot', $code );
+
+ return (string) $json->access_token;
+ }
+}
diff --git a/plugins/jetpack/class.jetpack-client.php b/plugins/jetpack/class.jetpack-client.php
new file mode 100644
index 00000000..c414e086
--- /dev/null
+++ b/plugins/jetpack/class.jetpack-client.php
@@ -0,0 +1,215 @@
+<?php
+
+class Jetpack_Client {
+ /**
+ * Makes an authorized remote request using Jetpack_Signature
+ *
+ * @return array|WP_Error WP HTTP response on success
+ */
+ public static function remote_request( $args, $body = null ) {
+ $defaults = array(
+ 'url' => '',
+ 'user_id' => 0,
+ 'blog_id' => 0,
+ 'auth_location' => JETPACK_CLIENT__AUTH_LOCATION,
+ 'method' => 'POST',
+ 'timeout' => 10,
+ 'redirection' => 0,
+ );
+
+ $args = wp_parse_args( $args, $defaults );
+
+ $args['blog_id'] = (int) $args['blog_id'];
+
+ if ( 'header' != $args['auth_location'] ) {
+ $args['auth_location'] = 'query_string';
+ }
+
+ $token = Jetpack_Data::get_access_token( $args['user_id'] );
+ if ( !$token ) {
+ return new Jetpack_Error( 'missing_token' );
+ }
+
+ $method = strtoupper( $args['method'] );
+
+ $timeout = intval( $args['timeout'] );
+
+ $redirection = $args['redirection'];
+
+ $request = compact( 'method', 'body', 'timeout', 'redirection' );
+
+ @list( $token_key, $secret ) = explode( '.', $token->secret );
+ if ( empty( $token ) || empty( $secret ) ) {
+ return new Jetpack_Error( 'malformed_token' );
+ }
+
+ $token_key = sprintf( '%s:%d:%d', $token_key, JETPACK__API_VERSION, $token->external_user_id );
+
+ require_once dirname( __FILE__ ) . '/class.jetpack-signature.php';
+
+ $time_diff = (int) Jetpack::get_option( 'time_diff' );
+ $jetpack_signature = new Jetpack_Signature( $token->secret, $time_diff );
+
+ $timestamp = time() + $time_diff;
+ $nonce = wp_generate_password( 10, false );
+
+ // Kind of annoying. Maybe refactor Jetpack_Signature to handle body-hashing
+ if ( is_null( $body ) ) {
+ $body_hash = '';
+ } else {
+ if ( !is_string( $body ) ) {
+ return new Jetpack_Error( 'invalid_body', 'Body is malformed.' );
+ }
+ $body_hash = jetpack_sha1_base64( $body );
+ }
+
+ $auth = array(
+ 'token' => $token_key,
+ 'timestamp' => $timestamp,
+ 'nonce' => $nonce,
+ 'body-hash' => $body_hash,
+ );
+
+ if ( false !== strpos( $args['url'], 'xmlrpc.php' ) ) {
+ $url_args = array(
+ 'for' => 'jetpack',
+ 'blog_id' => $args['blog_id'],
+ );
+ } else {
+ $url_args = array();
+ }
+
+ if ( 'header' != $args['auth_location'] ) {
+ $url_args += $auth;
+ }
+
+ $url = add_query_arg( urlencode_deep( $url_args ), $args['url'] );
+ $url = Jetpack::fix_url_for_bad_hosts( $url, $request );
+
+ $signature = $jetpack_signature->sign_request( $token_key, $timestamp, $nonce, $body_hash, $method, $url, $body, false );
+
+ if ( !$signature || is_wp_error( $signature ) ) {
+ return $signature;
+ }
+
+ // Send an Authorization header so various caches/proxies do the right thing
+ $auth['signature'] = $signature;
+ $auth['version'] = JETPACK__VERSION;
+ $header_pieces = array();
+ foreach ( $auth as $key => $value ) {
+ $header_pieces[] = sprintf( '%s="%s"', $key, $value );
+ }
+ $request['headers'] = array(
+ 'Authorization' => "X_JETPACK " . join( ' ', $header_pieces ),
+ );
+
+ if ( 'header' != $args['auth_location'] ) {
+ $url = add_query_arg( 'signature', urlencode( $signature ), $url );
+ }
+
+ return Jetpack_Client::_wp_remote_request( $url, $request );
+ }
+
+ /**
+ * Wrapper for wp_remote_request(). Turns off SSL verification for certain SSL errors.
+ * This is lame, but many, many, many hosts have misconfigured SSL.
+ *
+ * When Jetpack is registered, the jetpack_fallback_no_verify_ssl_certs option is set to the current time if:
+ * 1. a certificate error is found AND
+ * 2. not verifying the certificate works around the problem.
+ *
+ * The option is checked on each request.
+ *
+ * @internal
+ * @todo: Better fallbacks (bundled certs?), feedback, UI, ....
+ * @see Jetpack::fix_url_for_bad_hosts()
+ *
+ * @return array|WP_Error WP HTTP response on success
+ */
+ public static function _wp_remote_request( $url, $args, $set_fallback = false ) {
+ $fallback = Jetpack::get_option( 'fallback_no_verify_ssl_certs' );
+ if ( false === $fallback ) {
+ Jetpack::update_option( 'fallback_no_verify_ssl_certs', 0 );
+ }
+
+ if ( (int) $fallback ) {
+ // We're flagged to fallback
+ $args['sslverify'] = false;
+ }
+
+ $response = wp_remote_request( $url, $args );
+
+ if (
+ !$set_fallback // We're not allowed to set the flag on this request, so whatever happens happens
+ ||
+ isset( $args['sslverify'] ) && !$args['sslverify'] // No verification - no point in doing it again
+ ||
+ !is_wp_error( $response ) // Let it ride
+ ) {
+ Jetpack_Client::set_time_diff( $response, $set_fallback );
+ return $response;
+ }
+
+ // At this point, we're not flagged to fallback and we are allowed to set the flag on this request.
+
+ $message = $response->get_error_message();
+
+ // Is it an SSL Certificate verification error?
+ if (
+ false === strpos( $message, '14090086' ) // OpenSSL SSL3 certificate error
+ &&
+ false === strpos( $message, '1407E086' ) // OpenSSL SSL2 certificate error
+ &&
+ false === strpos( $message, 'error setting certificate verify locations' ) // cURL CA bundle not found
+ &&
+ false === strpos( $message, 'Peer certificate cannot be authenticated with' ) // cURL CURLE_SSL_CACERT: CA bundle found, but not helpful
+ // different versions of curl have different error messages
+ // this string should catch them all
+ &&
+ false === strpos( $message, 'Problem with the SSL CA cert' ) // cURL CURLE_SSL_CACERT_BADFILE: probably access rights
+ ) {
+ // No, it is not.
+ return $response;
+ }
+
+ // Redo the request without SSL certificate verification.
+ $args['sslverify'] = false;
+ $response = wp_remote_request( $url, $args );
+
+ if ( !is_wp_error( $response ) ) {
+ // The request went through this time, flag for future fallbacks
+ Jetpack::update_option( 'fallback_no_verify_ssl_certs', time() );
+ Jetpack_Client::set_time_diff( $response, $set_fallback );
+ }
+
+ return $response;
+ }
+
+ public static function set_time_diff( &$response, $force_set = false ) {
+ $code = wp_remote_retrieve_response_code( $response );
+
+ // Only trust the Date header on some responses
+ if ( 200 != $code && 304 != $code && 400 != $code && 401 != $code ) {
+ return;
+ }
+
+ if ( !$date = wp_remote_retrieve_header( $response, 'date' ) ) {
+ return;
+ }
+
+ if ( 0 >= $time = (int) strtotime( $date ) ) {
+ return;
+ }
+
+ $time_diff = $time - time();
+
+ if ( $force_set ) { // during register
+ Jetpack::update_option( 'time_diff', $time_diff );
+ } else { // otherwise
+ $old_diff = Jetpack::get_option( 'time_diff' );
+ if ( false === $old_diff || abs( $time_diff - (int) $old_diff ) > 10 ) {
+ Jetpack::update_option( 'time_diff', $time_diff );
+ }
+ }
+ }
+}
diff --git a/plugins/jetpack/class.jetpack-data.php b/plugins/jetpack/class.jetpack-data.php
new file mode 100644
index 00000000..b43e6a47
--- /dev/null
+++ b/plugins/jetpack/class.jetpack-data.php
@@ -0,0 +1,42 @@
+<?php
+
+class Jetpack_Data {
+ /**
+ * Gets locally stored token
+ *
+ * @return object|false
+ */
+ public static function get_access_token( $user_id = false ) {
+ if ( $user_id ) {
+ if ( !$tokens = Jetpack::get_option( 'user_tokens' ) ) {
+ return false;
+ }
+ if ( $user_id === JETPACK_MASTER_USER ) {
+ if ( !$user_id = Jetpack::get_option( 'master_user' ) ) {
+ return false;
+ }
+ }
+ if ( !isset( $tokens[$user_id] ) || !$token = $tokens[$user_id] ) {
+ return false;
+ }
+ $token_chunks = explode( '.', $token );
+ if ( empty( $token_chunks[1] ) || empty( $token_chunks[2] ) ) {
+ return false;
+ }
+ if ( $user_id != $token_chunks[2] ) {
+ return false;
+ }
+ $token = "{$token_chunks[0]}.{$token_chunks[1]}";
+ } else {
+ $token = Jetpack::get_option( 'blog_token' );
+ if ( empty( $token ) ) {
+ return false;
+ }
+ }
+
+ return (object) array(
+ 'secret' => $token,
+ 'external_user_id' => (int) $user_id,
+ );
+ }
+}
diff --git a/plugins/jetpack/class.jetpack-debugger.php b/plugins/jetpack/class.jetpack-debugger.php
new file mode 100644
index 00000000..01c71e20
--- /dev/null
+++ b/plugins/jetpack/class.jetpack-debugger.php
@@ -0,0 +1,353 @@
+<?php
+
+function is_jetpack_support_open() {
+ try {
+ $response = wp_remote_request( "http://jetpack.me/is-support-open" );
+ $body = wp_remote_retrieve_body( $response );
+ $json = json_decode( $body );
+ return ( ( bool )$json->is_support_open );
+ }
+ catch ( Exception $e ) {
+ return true;
+ }
+}
+
+function jetpack_increase_timeout($time) {
+ $time = 20; //seconds
+ return $time;
+}
+
+
+function jetpack_debug_display_handler() {
+ if ( ! current_user_can( 'manage_options' ) )
+ wp_die( esc_html__('You do not have sufficient permissions to access this page.', 'jetpack' ) );
+
+ global $current_user;
+ get_currentuserinfo();
+
+ $user_id = get_current_user_id();
+ $user_tokens = Jetpack::get_option( 'user_tokens' );
+ if ( is_array( $user_tokens ) && array_key_exists( $user_id, $user_tokens ) ) {
+ $user_token = $user_tokens[$user_id];
+ } else {
+ $user_token = '[this user has no token]';
+ }
+ unset( $user_tokens );
+
+ $debug_info = "\r\n";
+ foreach ( array(
+ 'CLIENT_ID' => 'id',
+ 'BLOG_TOKEN' => 'blog_token',
+ 'MASTER_USER' => 'master_user',
+ 'CERT' => 'fallback_no_verify_ssl_certs',
+ 'TIME_DIFF' => 'time_diff',
+ 'VERSION' => 'version',
+ 'OLD_VERSION' => 'old_version',
+ 'PUBLIC' => 'public',
+ ) as $label => $option_name ) {
+ $debug_info .= "\r\n" . esc_html( $label . ": " . Jetpack::get_option( $option_name ) );
+ }
+
+ $debug_info .= "\r\n" . esc_html( "USER_ID: " . $user_id );
+ $debug_info .= "\r\n" . esc_html( "USER_TOKEN: " . $user_token );
+ $debug_info .= "\r\n" . esc_html( "PHP_VERSION: " . PHP_VERSION );
+ $debug_info .= "\r\n" . esc_html( "WORDPRESS_VERSION: " . $GLOBALS['wp_version'] );
+ $debug_info .= "\r\n" . esc_html( "JETPACK__VERSION: " . JETPACK__VERSION );
+ $debug_info .= "\r\n" . esc_html( "JETPACK__PLUGIN_DIR: " . JETPACK__PLUGIN_DIR );
+ $debug_info .= "\r\n" . esc_html( "SITE_URL: " . site_url() );
+ $debug_info .= "\r\n" . esc_html( "HOME_URL: " . home_url() );
+
+ $debug_info .= "\r\n\r\nTEST RESULTS:\r\n\r\n";
+ $debug_raw_info = '';
+
+
+ $tests = array();
+
+ $tests['HTTP']['result'] = wp_remote_get( preg_replace( '/^https:/', 'http:', JETPACK__API_BASE ) . 'test/1/' );
+ $tests['HTTP']['fail_message'] = esc_html__( 'Your site isn’t reaching the Jetpack servers.', 'jetpack' );
+
+ $tests['HTTPS']['result'] = wp_remote_get( preg_replace( '/^http:/', 'https:', JETPACK__API_BASE ) . 'test/1/' );
+ $tests['HTTPS']['fail_message'] = esc_html__( 'Your site isn’t securely reaching the Jetpack servers.', 'jetpack' );
+
+
+ $self_xml_rpc_url = site_url( 'xmlrpc.php' );
+
+ $args = array();
+ $testsite_url = Jetpack::fix_url_for_bad_hosts( JETPACK__API_BASE . 'testsite/1/?url=', $args );
+
+ add_filter( 'http_request_timeout', 'jetpack_increase_timeout' );
+
+ $tests['SELF']['result'] = wp_remote_get( $testsite_url . $self_xml_rpc_url );
+ $tests['SELF']['fail_message'] = esc_html__( 'It looks like your site can not communicate properly with Jetpack.', 'jetpack' );
+
+ remove_filter( 'http_request_timeout', 'jetpack_increase_timeout' );
+
+ ?>
+ <div class="wrap">
+ <h2><?php esc_html_e( 'Jetpack Debugging Center', 'jetpack' ); ?></h2>
+ <h3><?php _e( "Testing your site's compatibily with Jetpack...", 'jetpack' ); ?></h3>
+ <div class="jetpack-debug-test-container">
+ <?php
+ ob_start();
+ foreach ( $tests as $test_name => $test_info ) :
+ if ( is_wp_error( $test_info['result'] ) ||
+ false == ( $response_code = wp_remote_retrieve_response_code( $test_info['result'] ) ) ||
+ '200' != $response_code ) {
+ $debug_info .= $test_name . ": FAIL\r\n";
+ ?>
+ <div class="jetpack-test-error">
+ <p>
+ <a class="jetpack-test-heading" href="#"><?php echo $test_info['fail_message']; ?>
+ <span class="noticon noticon-collapse"></span>
+ </a>
+ </p>
+ <pre class="jetpack-test-details"><?php esc_html_e( $test_name , 'jetpack'); ?>:
+<?php esc_html_e( is_wp_error( $test_info['result'] ) ? $test_info['result']->get_error_message() : print_r( $test_info['result'], 1 ) ); ?></pre>
+ </div><?php
+ } else {
+ $debug_info .= $test_name . ": PASS\r\n";
+ }
+ $debug_raw_info .= "\r\n\r\n" . $test_name . "\r\n" . esc_html( print_r( $test_info['result'], 1 ) );
+ ?>
+ <?php endforeach;
+ $html = ob_get_clean();
+
+ if ( '' == trim( $html ) ) {
+ echo '<div class="jetpack-tests-succed">' . esc_html__( 'Your Jetpack setup looks a-okay!', 'jetpack' ) . '</div>';
+ }
+ else {
+ echo '<h3>' . esc_html__( 'There seems to be a problem with your site’s ability to communicate with Jetpack!', 'jetpack' ) . '</h3>';
+ echo $html;
+ }
+ $debug_info .= "\r\n\r\nRAW TEST RESULTS:" . $debug_raw_info ."\r\n";
+ ?>
+ </div>
+ <div class="entry-content">
+ <h3><?php esc_html_e( 'Trouble with Jetpack?', 'jetpack' ); ?></h3>
+ <h4><?php esc_html_e( 'It may be caused by one of these issues, which you can diagnose yourself:', 'jetpack' ); ?></h4>
+ <ol>
+ <li><b><em><?php esc_html_e( 'A known issue.', 'jetpack' ); ?></em></b> <?php echo sprintf( __( 'Some themes and plugins have <a href="%1$s" target="_blank">known conflicts</a> with Jetpack – check the <a href="%2$s" target="_blank">list</a>. (You can also browse the <a href="%3$s">Jetpack support pages</a> or <a href="%4$s">Jetpack support forum</a> to see if others have experienced and solved the problem.)', 'jetpack' ), 'http://jetpack.me/known-issues/', 'http://jetpack.me/known-issues/', 'http://jetpack.me/support/', 'http://wordpress.org/support/plugin/jetpack' ); ?></li>
+ <li><b><em><?php esc_html_e( 'An incompatible plugin.', 'jetpack' ); ?></em></b> <?php esc_html_e( "Find out by disabling all plugins except Jetpack. If the problem persists, it's not a plugin issue. If the problem is solved, turn your plugins on one by one until the problem pops up again – there's the culprit! Let us know, and we'll try to help.", 'jetpack' ); ?></li>
+ <li><b><em><?php esc_html_e( 'A theme conflict.', 'jetpack' ); ?></em></b> <?php esc_html_e( "If your problem isn't known or caused by a plugin, try activating Twenty Twelve (the default WordPress theme). If this solves the problem, something in your theme is probably broken – let the theme's author know.", 'jetpack' ); ?></li>
+ <li><b><em><?php esc_html_e( 'A problem with your XMLRPC file.', 'jetpack' ); ?></em></b> <?php echo sprintf( __( 'Load your <a href="%s">XMLRPC file</a>. It should say “XML-RPC server accepts POST requests only.” on a line by itself.', 'jetpack' ), site_url( 'xmlrpc.php' ) ); ?>
+ <ul>
+ <li>- <?php esc_html_e( "If it's not by itself, a theme or plugin is displaying extra characters. Try steps 2 and 3.", 'jetpack' ); ?></li>
+ <li>- <?php esc_html_e( "If you get a 404 message, contact your web host. Their security may block XMLRPC.", 'jetpack' ); ?></li>
+ </ul>
+ </li>
+ </ol>
+ <p class="jetpack-show-contact-form"><?php _e( 'If none of these help you find a solution, <a href="#">click here to contact Jetpack support</a>. Tell us as much as you can about the issue and what steps you\'ve tried to resolve it, and one of our Happiness Engineers will be in touch to help.', 'jetpack' ); ?>
+ </p>
+ </div>
+ <div id="contact-message" style="display:none">
+ <?php if ( is_jetpack_support_open() ): ?>
+ <form id="contactme" method="post" action="http://jetpack.me/contact-support/">
+ <input type="hidden" name="action" value="submit">
+ <input type="hidden" name="jetpack" value="needs-service">
+
+ <input type="hidden" name="contact_form" id="contact_form" value="1">
+ <input type="hidden" name="blog_url" id="blog_url" value="<?php echo esc_attr( site_url() ); ?>">
+ <input type="hidden" name="subject" id="subject" value="from: <?php echo esc_attr( site_url() ); ?> Jetpack contact form">
+ <div class="formbox">
+ <label for="message" class="h"><?php esc_html_e( 'Please describe the problem you are having.', 'jetpack' ); ?></label>
+ <textarea name="message" cols="40" rows="7" id="did"></textarea>
+ </div>
+
+ <div id="name_div" class="formbox">
+ <label class="h" for="your_name"><?php esc_html_e( 'Name', 'jetpack' ); ?></label>
+ <span class="errormsg"><?php esc_html_e( 'Let us know your name.', 'jetpack' ); ?></span>
+ <input name="your_name" type="text" id="your_name" value="<?php esc_html_e( $current_user->display_name , 'jetpack'); ?>" size="40">
+ </div>
+
+ <div id="email_div" class="formbox">
+ <label class="h" for="your_email"><?php esc_html_e( 'E-mail', 'jetpack' ); ?></label>
+ <span class="errormsg"><?php esc_html_e( 'Use a valid email address.', 'jetpack' ); ?></span>
+ <input name="your_email" type="text" id="your_email" value="<?php esc_html_e( $current_user->user_email , 'jetpack'); ?>" size="40">
+ </div>
+
+ <div id="toggle_debug_info" class="formbox">
+ <p><?php _e( 'The test results and some other useful debug information will be sent to the support team. Please feel free to <a href="#">review/modify</a> this information.', 'jetpack' ); ?></p>
+ </div>
+
+ <div id="debug_info_div" class="formbox" style="display:none">
+ <label class="h" for="debug_info"><?php esc_html_e( 'Debug Info', 'jetpack' ); ?></label>
+ <textarea name="debug_info" cols="40" rows="7" id="debug_info"><?php echo esc_attr( $debug_info ); ?></textarea>
+ </div>
+
+ <div style="clear: both;"></div>
+
+ <div id="blog_div" class="formbox">
+ <div id="submit_div" class="contact-support">
+ <input type="submit" name="submit" value="Contact Support">
+ </div>
+ </div>
+ <div style="clear: both;"></div>
+ </form>
+ <?php endif; ?>
+ </div>
+ </div>
+<?php
+}
+
+function jetpack_debug_admin_head() {
+ ?>
+ <style type="text/css">
+
+ .jetpack-debug-test-container {
+ margin-top: 20px;
+ margin-bottom: 30px;
+ }
+
+ .jetpack-tests-succed {
+ font-size: large;
+ color: #8BAB3E;
+ }
+
+ .jetpack-test-details {
+ margin: 4px 6px;
+ padding: 10px;
+ overflow: auto;
+ display: none;
+ }
+
+ .jetpack-test-error {
+ margin-bottom: 10px;
+ background: #FFEBE8;
+ border: solid 1px #C00;
+ border-radius: 3px;
+ }
+
+ .jetpack-test-error p {
+ margin: 0;
+ padding: 0;
+ }
+
+ .jetpack-test-error a.jetpack-test-heading {
+ padding: 4px 6px;
+ display: block;
+ text-decoration: none;
+ color: inherit;
+ }
+
+ .jetpack-test-error .noticon {
+ float: right;
+ }
+
+ form#contactme {
+ border: 1px solid #dfdfdf;
+ background: #eaf3fa;
+ padding: 20px;
+ margin: 10px;
+ background-color: #eaf3fa;
+ border-radius: 5px;
+ font-size: 15px;
+ font-family: "Open Sans", "Helvetica Neue", sans-serif;
+ }
+
+ form#contactme label.h {
+ color: #444;
+ display: block;
+ font-weight: bold;
+ margin: 0 0 7px 10px;
+ text-shadow: 1px 1px 0 #fff;
+ }
+
+ .formbox {
+ margin: 0 0 25px 0;
+ }
+
+ .formbox input[type="text"], .formbox input[type="email"], .formbox input[type="url"], .formbox textarea {
+ border: 1px solid #e5e5e5;
+ border-radius: 11px;
+ box-shadow: inset 0 1px 1px rgba(0,0,0,0.1);
+ color: #666;
+ font-size: 14px;
+ padding: 10px;
+ width: 97%;
+ }
+ .formbox .contact-support input[type="submit"] {
+ float: right;
+ margin: 0 !important;
+ border-radius: 20px !important;
+ cursor: pointer;
+ font-size: 13pt !important;
+ height: auto !important;
+ margin: 0 0 2em 10px !important;
+ padding: 8px 16px !important;
+ background-color: #ddd;
+ border: 1px solid rgba(0,0,0,0.05);
+ border-top-color: rgba(255,255,255,0.1);
+ border-bottom-color: rgba(0,0,0,0.15);
+ color: #333;
+ font-weight: 400;
+ display: inline-block;
+ text-align: center;
+ text-decoration: none;
+ }
+
+ .formbox span.errormsg {
+ margin: 0 0 10px 10px;
+ color: #d00;
+ display: none;
+ }
+
+ .formbox.error span.errormsg {
+ display: block;
+ }
+
+ #contact-message ul {
+ margin: 0 0 20px 10px;
+ }
+
+ #contact-message li {
+ margin: 0 0 10px 10px;
+ list-style: disc;
+ display: list-item;
+ }
+
+ </style>
+ <script type="text/javascript">
+ jQuery( document ).ready( function($) {
+
+ $('#debug_info').prepend('jQuery version: ' + jQuery.fn.jquery + "\r\n");
+
+ $( '.jetpack-test-error .jetpack-test-heading' ).on( 'click', function() {
+ $( this ).parents( '.jetpack-test-error' ).find( '.jetpack-test-details' ).slideToggle();
+ return false;
+ } );
+
+ $( '.jetpack-show-contact-form a' ).on( 'click', function() {
+ $('#contact-message').slideToggle();
+ return false;
+ } );
+
+ $( '#toggle_debug_info a' ).on( 'click', function() {
+ $('#debug_info_div').slideToggle();
+ return false;
+ } );
+
+ $('form#contactme').on("submit", function(e){
+ var form = $(this);
+ var message = form.find('#did');
+ var name = form.find('#your_name');
+ var email = form.find('#your_email')
+ var validation_error = false;
+ if( !name.val() ) {
+ name.parents('.formbox').addClass('error');
+ validation_error = true;
+ }
+ if( !email.val() ) {
+ email.parents('.formbox').addClass('error');
+ validation_error = true;
+ }
+ if ( validation_error ) {
+ return false;
+ }
+ message.val(message.val() + "\r\n\r\n----------------------------------------------\r\n\r\nDEBUG INFO:\r\n" + $('#debug_info').val() );
+ return true;
+ });
+
+ } );
+ </script>
+ <?php
+}
diff --git a/plugins/jetpack/class.jetpack-error.php b/plugins/jetpack/class.jetpack-error.php
new file mode 100644
index 00000000..9b7725ad
--- /dev/null
+++ b/plugins/jetpack/class.jetpack-error.php
@@ -0,0 +1,3 @@
+<?php
+
+class Jetpack_Error extends WP_Error {}
diff --git a/plugins/jetpack/class.jetpack-heartbeat.php b/plugins/jetpack/class.jetpack-heartbeat.php
new file mode 100644
index 00000000..40daf2a9
--- /dev/null
+++ b/plugins/jetpack/class.jetpack-heartbeat.php
@@ -0,0 +1,131 @@
+<?php
+
+class Jetpack_Heartbeat {
+
+ /**
+ * Jetpack object
+ *
+ * @since 2.3.3
+ * @var Jetpack
+ */
+ var $jetpack = null;
+
+ /**
+ * Holds the singleton instance of this class
+ *
+ * @since 2.3.3
+ * @var Jetpack_Heartbeat
+ */
+ static $instance = false;
+
+ private $cron_name = 'jetpack_heartbeat';
+
+ /**
+ * Singleton
+ *
+ * @since 2.3.3
+ * @static
+ * @return Jetpack_Heartbeat
+ */
+ public static function init() {
+ if ( ! self::$instance ) {
+ self::$instance = new Jetpack_Heartbeat;
+ }
+
+ return self::$instance;
+ }
+
+ /**
+ * Constructor for singleton
+ *
+ * @since 2.3.3
+ * @return Jetpack_Heartbeat
+ */
+ private function __construct() {
+ $this->jetpack = Jetpack::init();
+
+ // Add weekly interval for wp-cron
+ add_filter('cron_schedules', array( $this, 'add_cron_intervals' ) );
+
+ // Schedule the task
+ add_action( $this->cron_name, array( $this, 'cron_exec' ) );
+
+ if (!wp_next_scheduled( $this->cron_name ) ) {
+ wp_schedule_event( time(), 'jetpack_weekly', $this->cron_name );
+ }
+ }
+
+ /**
+ * Method that gets executed on the wp-cron call
+ *
+ * @since 2.3.3
+ * @global string $wp_version
+ */
+ public function cron_exec() {
+
+ /*
+ * Check for an identity crisis
+ *
+ * If one exists:
+ * - Bump stat for ID crisis
+ * - Email site admin about potential ID crisis
+ */
+
+
+
+ /**
+ * Setup an array of items that will eventually be stringified
+ * and sent off to the Jetpack API
+ *
+ * Associative array with format group => values
+ * - values should be an array that will be imploded to a string
+ */
+
+ $jetpack = $this->jetpack;
+
+ $jetpack->stat( 'active-modules', implode( ',', $this->jetpack->get_active_modules() ) );
+ $jetpack->stat( 'active', JETPACK__VERSION );
+ $jetpack->stat( 'wp-version', get_bloginfo( 'version' ) );
+ $jetpack->stat( 'php-version', PHP_VERSION );
+ $jetpack->stat( 'ssl', $jetpack->permit_ssl() );
+ $jetpack->stat( 'language', get_bloginfo( 'language' ) );
+ $jetpack->stat( 'charset', get_bloginfo( 'charset' ) );
+ $jetpack->stat( 'qty-posts', wp_count_posts()->publish );
+ $jetpack->stat( 'qty-pages', wp_count_posts( 'page' )->publish );
+ $jetpack->stat( 'qty-comments', wp_count_comments()->approved );
+ $jetpack->stat( 'is-multisite', is_multisite() ? 'multisite' : 'singlesite' );
+
+ // Only check a few plugins, to see if they're currently active.
+ $plugins_to_check = array(
+ 'vaultpress/vaultpress.php',
+ 'akismet/akismet.php',
+ 'wp-super-cache/wp-cache.php',
+ );
+ $plugins = array_intersect( $plugins_to_check, get_option( 'active_plugins', array() ) );
+ foreach( $plugins as $plugin ) {
+ $jetpack->stat( 'plugins', $plugin );
+ }
+
+ $jetpack->do_stats( 'server_side' );
+ }
+
+ /**
+ * Adds additional Jetpack specific intervals to wp-cron
+ *
+ * @since 2.3.3
+ * @return array
+ */
+ public function add_cron_intervals( $schedules ) {
+ $schedules['jetpack_weekly'] = array(
+ 'interval' => WEEK_IN_SECONDS,
+ 'display' => __('Jetpack weekly')
+ );
+ return $schedules;
+ }
+
+ public function deactivate() {
+ $timestamp = wp_next_scheduled( $this->cron_name );
+ wp_unschedule_event($timestamp, $this->cron_name );
+ }
+
+}// end class
diff --git a/plugins/jetpack/class.jetpack-options.php b/plugins/jetpack/class.jetpack-options.php
new file mode 100644
index 00000000..f480f308
--- /dev/null
+++ b/plugins/jetpack/class.jetpack-options.php
@@ -0,0 +1,143 @@
+<?php
+
+class Jetpack_Options {
+
+ public static function get_option_names( $type = 'compact' ) {
+ switch ( $type ) {
+ case 'non-compact' :
+ case 'non_compact' :
+ return array(
+ 'register',
+ 'activated',
+ 'active_modules',
+ 'do_activate',
+ 'publicize',
+ 'widget_twitter',
+ );
+ }
+
+ return array(
+ 'id', // (int) The Client ID/WP.com Blog ID of this site.
+ 'blog_token', // (string) The Client Secret/Blog Token of this site.
+ 'user_token', // (string) The User Token of this site. (deprecated)
+ 'publicize_connections', // (array) An array of Publicize connections from WordPress.com
+ 'master_user', // (int) The local User ID of the user who connected this site to jetpack.wordpress.com.
+ 'user_tokens', // (array) User Tokens for each user of this site who has connected to jetpack.wordpress.com.
+ 'version', // (string) Used during upgrade procedure to auto-activate new modules. version:time
+ 'old_version', // (string) Used to determine which modules are the most recently added. previous_version:time
+ 'fallback_no_verify_ssl_certs', // (int) Flag for determining if this host must skip SSL Certificate verification due to misconfigured SSL.
+ 'time_diff', // (int) Offset between Jetpack server's clocks and this server's clocks. Jetpack Server Time = time() + (int) Jetpack_Options::get_option( 'time_diff' )
+ 'public', // (int|bool) If we think this site is public or not (1, 0), false if we haven't yet tried to figure it out.
+ 'is_network_site', // (int|bool) If we think this site is a network or a single blog (1, 0), false if we haven't yet tried to figue it out.
+ 'social_links', // (array) The specified links for each social networking site.
+ );
+ }
+
+ /**
+ * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate.
+ *
+ * @param string $name Option name
+ * @param mixed $default (optional)
+ */
+ public static function get_option( $name, $default = false ) {
+ if ( in_array( $name, self::get_option_names( 'non_compact' ) ) ) {
+ return get_option( "jetpack_$name" );
+ } else if ( !in_array( $name, self::get_option_names() ) ) {
+ trigger_error( sprintf( 'Invalid Jetpack option name: %s', $name ), E_USER_WARNING );
+ return false;
+ }
+
+ $options = get_option( 'jetpack_options' );
+ if ( is_array( $options ) && isset( $options[$name] ) ) {
+ return $options[$name];
+ }
+
+ return $default;
+ }
+
+ /**
+ * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate.
+ *
+ * @param string $name Option name
+ * @param mixed $value Option value
+ */
+ public static function update_option( $name, $value ) {
+ if ( in_array( $name, self::get_option_names( 'non_compact' ) ) ) {
+ return update_option( "jetpack_$name", $value );
+ } else if ( !in_array( $name, self::get_option_names() ) ) {
+ trigger_error( sprintf( 'Invalid Jetpack option name: %s', $name ), E_USER_WARNING );
+ return false;
+ }
+
+ $options = get_option( 'jetpack_options' );
+ if ( !is_array( $options ) ) {
+ $options = array();
+ }
+
+ $options[$name] = $value;
+
+ return update_option( 'jetpack_options', $options );
+ }
+
+ /**
+ * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate.
+ *
+ * @param array $array array( option name => option value, ... )
+ */
+ public static function update_options( $array ) {
+ $names = array_keys( $array );
+
+ foreach ( array_diff( $names, self::get_option_names(), self::get_option_names( 'non_compact' ) ) as $unknown_name ) {
+ trigger_error( sprintf( 'Invalid Jetpack option name: %s', $unknown_name ), E_USER_WARNING );
+ unset( $array[$unknown_name] );
+ }
+
+ foreach ( array_intersect( $names, self::get_option_names( 'non_compact' ) ) as $name ) {
+ update_option( "jetpack_$name", $array[$name] );
+ unset( $array[$name] );
+ }
+
+ $options = get_option( 'jetpack_options' );
+ if ( !is_array( $options ) ) {
+ $options = array();
+ }
+
+ return update_option( 'jetpack_options', array_merge( $options, $array ) );
+ }
+
+ /**
+ * Deletes the given option. May be passed multiple option names as an array.
+ * Updates jetpack_options and/or deletes jetpack_$name as appropriate.
+ *
+ * @param string|array $names
+ */
+ public static function delete_option( $names ) {
+ $names = (array) $names;
+
+ foreach ( array_diff( $names, self::get_option_names(), self::get_option_names( 'non_compact' ) ) as $unknown_name ) {
+ trigger_error( sprintf( 'Invalid Jetpack option name: %s', $unknown_name ), E_USER_WARNING );
+ }
+
+ foreach ( array_intersect( $names, self::get_option_names( 'non_compact' ) ) as $name ) {
+ delete_option( "jetpack_$name" );
+ }
+
+ $options = get_option( 'jetpack_options' );
+ if ( !is_array( $options ) ) {
+ $options = array();
+ }
+
+ $to_delete = array_intersect( $names, self::get_option_names(), array_keys( $options ) );
+ if ( $to_delete ) {
+ foreach ( $to_delete as $name ) {
+ unset( $options[$name] );
+ }
+
+ return update_option( 'jetpack_options', $options );
+ }
+
+ return true;
+ }
+
+}
+
diff --git a/plugins/jetpack/class.jetpack-sync.php b/plugins/jetpack/class.jetpack-sync.php
new file mode 100644
index 00000000..2ff9dfb4
--- /dev/null
+++ b/plugins/jetpack/class.jetpack-sync.php
@@ -0,0 +1,713 @@
+<?php
+
+/**
+ * Request that a piece of data on this WordPress install be synced back to the
+ * Jetpack server for remote processing/notifications/etc
+ */
+class Jetpack_Sync {
+ // What modules want to sync what content
+ var $sync_conditions = array( 'posts' => array(), 'comments' => array() );
+
+ // We keep track of all the options registered for sync so that we can sync them all if needed
+ var $sync_options = array();
+
+ // Keep trac of status transitions, which we wouldn't always know about on the Jetpack Servers but are important when deciding what to do with the sync.
+ var $post_transitions = array();
+ var $comment_transitions = array();
+
+ // Objects to sync
+ var $sync = array();
+
+ function __construct() {
+ // WP Cron action. Only used on upgrade
+ add_action( 'jetpack_sync_all_registered_options', array( $this, 'sync_all_registered_options' ) );
+ }
+
+/* Static Methods for Modules */
+
+ /**
+ * @param string $file __FILE__
+ * @param array settings:
+ * post_types => array( post_type slugs ): The post types to sync. Default: post, page
+ * post_stati => array( post_status slugs ): The post stati to sync. Default: publish
+ */
+ static function sync_posts( $file, array $settings = null ) {
+ $jetpack = Jetpack::init();
+ $args = func_get_args();
+ return call_user_func_array( array( $jetpack->sync, 'posts' ), $args );
+ }
+
+ /**
+ * @param string $file __FILE__
+ * @param array settings:
+ * post_types => array( post_type slugs ): The post types to sync. Default: post, page
+ * post_stati => array( post_status slugs ): The post stati to sync. Default: publish
+ * comment_types => array( comment_type slugs ): The comment types to sync. Default: '', comment, trackback, pingback
+ * comment_stati => array( comment_status slugs ): The comment stati to sync. Default: approved
+ */
+ static function sync_comments( $file, array $settings = null ) {
+ $jetpack = Jetpack::init();
+ $args = func_get_args();
+ return call_user_func_array( array( $jetpack->sync, 'comments' ), $args );
+ }
+
+ /**
+ * @param string $file __FILE__
+ * @param string $option, Option name to sync
+ * @param string $option ...
+ */
+ static function sync_options( $file, $option /*, $option, ... */ ) {
+ $jetpack = Jetpack::init();
+ $args = func_get_args();
+ return call_user_func_array( array( $jetpack->sync, 'options' ), $args );
+ }
+
+/* Internal Methods */
+
+ /**
+ * Create a sync object/request
+ *
+ * @param string $object Type of object to sync -- [ post | comment | option ]
+ * @param int $id Unique identifier
+ * @param array $settings
+ */
+ function register( $object, $id = false, array $settings = null ) {
+ // Since we've registered something for sync, hook it up to execute on shutdown if we haven't already
+ if ( !$this->sync ) {
+ ignore_user_abort( true );
+ add_action( 'shutdown', array( $this, 'sync' ), 9 ); // Right before async XML-RPC
+ }
+
+ $defaults = array(
+ 'on_behalf_of' => array(), // What modules want this data
+ );
+ $settings = wp_parse_args( $settings, $defaults );
+
+ if ( !isset( $this->sync[$object] ) ) {
+ $this->sync[$object] = array();
+ }
+
+ // Store the settings for this object
+ if (
+ // First time for this object
+ !isset( $this->sync[$object][$id] )
+ ) {
+ // Easy: store the current settings
+ $this->sync[$object][$id] = $settings;
+ } else {
+ // Not as easy: we have to manually merge the settings from previous runs for this object with the settings for this run
+
+ $this->sync[$object][$id]['on_behalf_of'] = array_unique( array_merge( $this->sync[$object][$id]['on_behalf_of'], $settings['on_behalf_of'] ) );
+ }
+
+ $delete_prefix = 'delete_';
+ if ( 0 === strpos( $object, $delete_prefix ) ) {
+ $unset_object = substr( $object, strlen( $delete_prefix ) );
+ } else {
+ $unset_object = "{$delete_prefix}{$object}";
+ }
+
+ // Ensure post ... delete_post yields a delete operation
+ // Ensure delete_post ... post yields a sync post operation
+ // Ensure update_option() ... delete_option() ends up as a delete
+ // Ensure delete_option() ... update_option() ends up as an update
+ // Etc.
+ unset( $this->sync[$unset_object][$id] );
+
+ return true;
+ }
+
+ function get_common_sync_data() {
+ $available_modules = Jetpack::get_available_modules();
+ $active_modules = Jetpack::get_active_modules();
+ $modules = array();
+ foreach ( $available_modules as $available_module ) {
+ $modules[$available_module] = in_array( $available_module, $active_modules );
+ }
+ $modules['vaultpress'] = class_exists( 'VaultPress' ) || function_exists( 'vaultpress_contact_service' );
+
+ $sync_data = array(
+ 'modules' => $modules,
+ 'version' => JETPACK__VERSION,
+ );
+
+ return $sync_data;
+ }
+
+ /**
+ * Set up all the data and queue it for the outgoing XML-RPC request
+ */
+ function sync() {
+ if ( !$this->sync ) {
+ return false;
+ }
+
+ $sync_data = $this->get_common_sync_data();
+
+ $wp_importing = defined( 'WP_IMPORTING' ) && WP_IMPORTING;
+
+ foreach ( $this->sync as $sync_operation_type => $sync_operations ) {
+ switch ( $sync_operation_type ) {
+ case 'post':
+ if ( $wp_importing ) {
+ break;
+ }
+
+ $global_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null;
+ $GLOBALS['post'] = null;
+ foreach ( $sync_operations as $post_id => $settings ) {
+ $sync_data['post'][$post_id] = $this->get_post( $post_id );
+ if ( isset( $this->post_transitions[$post_id] ) ) {
+ $sync_data['post'][$post_id]['transitions'] = $this->post_transitions[$post_id];
+ } else {
+ $sync_data['post'][$post_id]['transitions'] = array( false, false );
+ }
+ $sync_data['post'][$post_id]['on_behalf_of'] = $settings['on_behalf_of'];
+ }
+ $GLOBALS['post'] = $global_post;
+ unset( $global_post );
+ break;
+ case 'comment':
+ if ( $wp_importing ) {
+ break;
+ }
+
+ $global_comment = isset( $GLOBALS['comment'] ) ? $GLOBALS['comment'] : null;
+ unset( $GLOBALS['comment'] );
+ foreach ( $sync_operations as $comment_id => $settings ) {
+ $sync_data['comment'][$comment_id] = $this->get_comment( $comment_id );
+ if ( isset( $this->comment_transitions[$comment_id] ) ) {
+ $sync_data['comment'][$comment_id]['transitions'] = $this->comment_transitions[$comment_id];
+ } else {
+ $sync_data['comment'][$comment_id]['transitions'] = array( false, false );
+ }
+ $sync_data['comment'][$comment_id]['on_behalf_of'] = $settings['on_behalf_of'];
+ }
+ $GLOBALS['comment'] = $global_comment;
+ unset( $global_comment );
+ break;
+ case 'option' :
+ foreach ( $sync_operations as $option => $settings ) {
+ $sync_data['option'][$option] = array( 'value' => get_option( $option ) );
+ }
+ break;
+
+ case 'delete_post':
+ case 'delete_comment':
+ foreach ( $sync_operations as $object_id => $settings ) {
+ $sync_data[$sync_operation_type][$object_id] = array( 'on_behalf_of' => $settings['on_behalf_of'] );
+ }
+ break;
+ case 'delete_option' :
+ foreach ( $sync_operations as $object_id => $settings ) {
+ $sync_data[$sync_operation_type][$object_id] = true;
+ }
+ break;
+ }
+ }
+
+ Jetpack::xmlrpc_async_call( 'jetpack.syncContent', $sync_data );
+ }
+
+ /**
+ * Format and return content data from a direct xmlrpc request for it.
+ *
+ * @param array $content_ids: array( 'posts' => array of ids, 'comments' => array of ids, 'options' => array of options )
+ */
+ function get_content( $content_ids ) {
+ $sync_data = $this->get_common_sync_data();
+
+ if ( isset( $content_ids['posts'] ) ) {
+ foreach ( $content_ids['posts'] as $id ) {
+ $sync_data['post'][$id] = $this->get_post( $id );
+ }
+ }
+
+ if ( isset( $content_ids['comments'] ) ) {
+ foreach ( $content_ids['comments'] as $id ) {
+ $sync_data['comment'][$id] = $this->get_post( $id );
+ }
+ }
+
+ if ( isset( $content_ids['options'] ) ) {
+ foreach ( $content_ids['options'] as $option ) {
+ $sync_data['option'][$option] = array( 'value' => get_option( $option ) );
+ }
+ }
+
+ return $sync_data;
+ }
+
+ /**
+ * Helper method for registering a post for sync
+ *
+ * @param int $id wp_posts.ID
+ * @param array $settings Sync data
+ */
+ function register_post( $id, array $settings = null ) {
+ $id = (int) $id;
+ if ( !$id ) {
+ return false;
+ }
+
+ $post = get_post( $id );
+ if ( !$post ) {
+ return false;
+ }
+
+ $settings = wp_parse_args( $settings, array(
+ 'on_behalf_of' => array(),
+ ) );
+
+ return $this->register( 'post', $id, $settings );
+ }
+
+ /**
+ * Helper method for registering a comment for sync
+ *
+ * @param int $id wp_comments.comment_ID
+ * @param array $settings Sync data
+ */
+ function register_comment( $id, array $settings = null ) {
+ $id = (int) $id;
+ if ( !$id ) {
+ return false;
+ }
+
+ $comment = get_comment( $id );
+ if ( !$comment || empty( $comment->comment_post_ID ) ) {
+ return false;
+ }
+
+ $post = get_post( $comment->comment_post_ID );
+ if ( !$post ) {
+ return false;
+ }
+
+ $settings = wp_parse_args( $settings, array(
+ 'on_behalf_of' => array(),
+ ) );
+
+ return $this->register( 'comment', $id, $settings );
+ }
+
+/* Posts Sync */
+
+ function posts( $file, array $settings = null ) {
+ $module_slug = Jetpack::get_module_slug( $file );
+
+ $defaults = array(
+ 'post_types' => array( 'post', 'page' ),
+ 'post_stati' => array( 'publish' ),
+ );
+
+ $this->sync_conditions['posts'][$module_slug] = wp_parse_args( $settings, $defaults );
+
+ add_action( 'transition_post_status', array( $this, 'transition_post_status_action' ), 10, 3 );
+ add_action( 'delete_post', array( $this, 'delete_post_action' ) );
+ }
+
+ function delete_post_action( $post_id ) {
+ $post = get_post( $post_id );
+ if ( !$post ) {
+ return $this->register( 'delete_post', (int) $post_id );
+ }
+
+ $this->transition_post_status_action( 'delete', $post->post_status, $post );
+ }
+
+ function transition_post_status_action( $new_status, $old_status, $post ) {
+ $sync = $this->get_post_sync_operation( $new_status, $old_status, $post, $this->sync_conditions['posts'] );
+ if ( !$sync ) {
+ // No module wants to sync this post
+ return false;
+ }
+
+ // Track post transitions
+ if ( isset( $this->post_transitions[$post->ID] ) ) {
+ // status changed more than once - keep tha most recent $new_status
+ $this->post_transitions[$post->ID][0] = $new_status;
+ } else {
+ $this->post_transitions[$post->ID] = array( $new_status, $old_status );
+ }
+
+ $operation = $sync['operation'];
+ unset( $sync['operation'] );
+
+ switch ( $operation ) {
+ case 'delete' :
+ return $this->register( 'delete_post', (int) $post->ID, $sync );
+ case 'submit' :
+ return $this->register_post( (int) $post->ID, $sync );
+ }
+ }
+
+ function get_post_sync_operation( $new_status, $old_status, $post, $module_conditions ) {
+ $delete_on_behalf_of = array();
+ $submit_on_behalf_of = array();
+ $delete_stati = array( 'delete' );
+
+ foreach ( $module_conditions as $module => $conditions ) {
+ if ( !in_array( $post->post_type, $conditions['post_types'] ) ) {
+ continue;
+ }
+
+ $deleted_post = in_array( $new_status, $delete_stati );
+
+ if ( $deleted_post ) {
+ $delete_on_behalf_of[] = $module;
+ } else {
+ clean_post_cache( $post->ID );
+ $new_status = get_post_status( $post->ID ); // Inherited status is resolved here
+ }
+
+ $old_status_in_stati = in_array( $old_status, $conditions['post_stati'] );
+ $new_status_in_stati = in_array( $new_status, $conditions['post_stati'] );
+
+ if ( $old_status_in_stati && !$new_status_in_stati ) {
+ // Jetpack no longer needs the post
+ if ( !$deleted_post ) {
+ $delete_on_behalf_of[] = $module;
+ } // else, we've already flagged it above
+ continue;
+ }
+
+ if ( !$new_status_in_stati ) {
+ continue;
+ }
+
+ // At this point, we know we want to sync the post, not delete it
+ $submit_on_behalf_of[] = $module;
+ }
+
+ if ( !empty( $submit_on_behalf_of ) ) {
+ return array( 'operation' => 'submit', 'on_behalf_of' => $submit_on_behalf_of );
+ }
+
+ if ( !empty( $delete_on_behalf_of ) ) {
+ return array( 'operation' => 'delete', 'on_behalf_of' => $delete_on_behalf_of );
+ }
+
+ return false;
+ }
+
+ /**
+ * Get a post and associated data in the standard JP format.
+ * Cannot be called statically
+ *
+ * @param int $id Post ID
+ * @return Array containing full post details
+ */
+ function get_post( $id ) {
+ $post_obj = get_post( $id );
+ if ( !$post_obj )
+ return false;
+
+ if ( is_callable( $post_obj, 'to_array' ) ) {
+ // WP >= 3.5
+ $post = $post_obj->to_array();
+ } else {
+ // WP < 3.5
+ $post = get_object_vars( $post_obj );
+ }
+
+ if ( 0 < strlen( $post['post_password'] ) ) {
+ $post['post_password'] = 'auto-' . wp_generate_password( 10, false ); // We don't want the real password. Just pass something random.
+ }
+
+ // local optimizations
+ unset(
+ $post['filter'],
+ $post['ancestors'],
+ $post['post_content_filtered'],
+ $post['to_ping'],
+ $post['pinged']
+ );
+
+ if ( $this->is_post_public( $post ) ) {
+ $post['post_is_public'] = Jetpack::get_option( 'public' );
+ } else {
+ //obscure content
+ $post['post_content'] = '';
+ $post['post_excerpt'] = '';
+ $post['post_is_public'] = false;
+ }
+ $post_type_obj = get_post_type_object( $post['post_type'] );
+ $post['post_is_excluded_from_search'] = $post_type_obj->exclude_from_search;
+
+ $post['tax'] = array();
+ $taxonomies = get_object_taxonomies( $post_obj );
+ foreach ( $taxonomies as $taxonomy ) {
+ $terms = get_object_term_cache( $post_obj->ID, $taxonomy );
+ if ( empty( $terms ) )
+ $terms = wp_get_object_terms( $post_obj->ID, $taxonomy );
+ $term_names = array();
+ foreach ( $terms as $term ) {
+ $term_names[] = $term->name;
+ }
+ $post['tax'][$taxonomy] = $term_names;
+ }
+
+ $meta = get_post_meta( $post_obj->ID, false );
+ $post['meta'] = array();
+ foreach ( $meta as $key => $value ) {
+ $post['meta'][$key] = array_map( 'maybe_unserialize', $value );
+ }
+
+ $post['extra'] = array(
+ 'author' => get_the_author_meta( 'display_name', $post_obj->post_author ),
+ 'author_email' => get_the_author_meta( 'email', $post_obj->post_author ),
+ );
+
+ if ( $fid = get_post_thumbnail_id( $id ) ) {
+ $feature = wp_get_attachment_image_src( $fid, 'large' );
+ if ( !empty( $feature[0] ) )
+ $post['extra']['featured_image'] = $feature[0];
+ }
+
+ $post['permalink'] = get_permalink( $post_obj->ID );
+ $post['shortlink'] = wp_get_shortlink( $post_obj->ID );
+ return $post;
+ }
+
+ /**
+ * Decide whether a post/page/attachment is visible to the public.
+ *
+ * @param array $post
+ * @return bool
+ */
+ function is_post_public( $post ) {
+ if ( !is_array( $post ) ) {
+ $post = (array) $post;
+ }
+
+ if ( 0 < strlen( $post['post_password'] ) )
+ return false;
+ if ( ! in_array( $post['post_type'], get_post_types( array( 'public' => true ) ) ) )
+ return false;
+ $post_status = get_post_status( $post['ID'] ); // Inherited status is resolved here.
+ if ( ! in_array( $post_status, get_post_stati( array( 'public' => true ) ) ) )
+ return false;
+ return true;
+ }
+
+/* Comments Sync */
+
+ function comments( $file, array $settings = null ) {
+ $module_slug = Jetpack::get_module_slug( $file );
+
+ $defaults = array(
+ 'post_types' => array( 'post', 'page' ), // For what post types will we sync comments?
+ 'post_stati' => array( 'publish' ), // For what post stati will we sync comments?
+ 'comment_types' => array( '', 'comment', 'trackback', 'pingback' ), // What comment types will we sync?
+ 'comment_stati' => array( 'approved' ), // What comment stati will we sync?
+ );
+
+ $settings = wp_parse_args( $settings, $defaults );
+
+ $this->sync_conditions['comments'][$module_slug] = $settings;
+
+ add_action( 'wp_insert_comment', array( $this, 'wp_insert_comment_action' ), 10, 2 );
+ add_action( 'transition_comment_status', array( $this, 'transition_comment_status_action' ), 10, 3 );
+ add_action( 'edit_comment', array( $this, 'edit_comment_action' ) );
+ }
+
+ /*
+ * This is really annoying. If you edit a comment, but don't change the status, WordPress doesn't fire the transition_comment_status hook.
+ * That means we have to catch these comments on the edit_comment hook, but ignore comments on that hook when the transition_comment_status does fire.
+ */
+ function edit_comment_action( $comment_id ) {
+ $comment = get_comment( $comment_id );
+ $new_status = $this->translate_comment_status( $comment->comment_approved );
+ add_action( "comment_{$new_status}_{$comment->comment_type}", array( $this, 'transition_comment_status_for_comments_whose_status_does_not_change' ), 10, 2 );
+ }
+
+ function wp_insert_comment_action( $comment_id, $comment ) {
+ $this->transition_comment_status_action( $comment->comment_approved, 'new', $comment );
+ }
+
+ function transition_comment_status_for_comments_whose_status_does_not_change( $comment_id, $comment ) {
+ if ( isset( $this->comment_transitions[$comment_id] ) ) {
+ return $this->transition_comment_status_action( $comment->comment_approved, $this->comment_transitions[$comment_id][1], $comment );
+ }
+
+ return $this->transition_comment_status_action( $comment->comment_approved, $comment->comment_approved, $comment );
+ }
+
+ function translate_comment_status( $status ) {
+ switch ( (string) $status ) {
+ case '0' :
+ case 'hold' :
+ return 'unapproved';
+ case '1' :
+ case 'approve' :
+ return 'approved';
+ }
+
+ return $status;
+ }
+
+ function transition_comment_status_action( $new_status, $old_status, $comment ) {
+ $post = get_post( $comment->comment_post_ID );
+ if ( !$post ) {
+ return false;
+ }
+
+ foreach ( array( 'new_status', 'old_status' ) as $_status ) {
+ $$_status = $this->translate_comment_status( $$_status );
+ }
+
+ // Track comment transitions
+ if ( isset( $this->comment_transitions[$comment->comment_ID] ) ) {
+ // status changed more than once - keep tha most recent $new_status
+ $this->comment_transitions[$comment->comment_ID][0] = $new_status;
+ } else {
+ $this->comment_transitions[$comment->comment_ID] = array( $new_status, $old_status );
+ }
+
+ $post_sync = $this->get_post_sync_operation( $post->post_status, '_jetpack_test_sync', $post, $this->sync_conditions['comments'] );
+
+ if ( !$post_sync ) {
+ // No module wants to sync this comment because its post doesn't match any sync conditions
+ return false;
+ }
+
+ if ( 'delete' == $post_sync['operation'] ) {
+ // Had we been looking at post sync operations (instead of comment sync operations),
+ // this comment's post would have been deleted. Don't sync the comment.
+ return false;
+ }
+
+ $delete_on_behalf_of = array();
+ $submit_on_behalf_of = array();
+ $delete_stati = array( 'delete' );
+
+ foreach ( $this->sync_conditions['comments'] as $module => $conditions ) {
+ if ( !in_array( $comment->comment_type, $conditions['comment_types'] ) ) {
+ continue;
+ }
+
+ $deleted_comment = in_array( $new_status, $delete_stati );
+
+ if ( $deleted_comment ) {
+ $delete_on_behalf_of[] = $module;
+ }
+
+ $old_status_in_stati = in_array( $old_status, $conditions['comment_stati'] );
+ $new_status_in_stati = in_array( $new_status, $conditions['comment_stati'] );
+
+ if ( $old_status_in_stati && !$new_status_in_stati ) {
+ // Jetpack no longer needs the comment
+ if ( !$deleted_comment ) {
+ $delete_on_behalf_of[] = $module;
+ } // else, we've already flagged it above
+ continue;
+ }
+
+ if ( !$new_status_in_stati ) {
+ continue;
+ }
+
+ // At this point, we know we want to sync the comment, not delete it
+ $submit_on_behalf_of[] = $module;
+ }
+
+ if ( ! empty( $submit_on_behalf_of ) ) {
+ $this->register_post( $comment->comment_post_ID, array( 'on_behalf_of' => $submit_on_behalf_of ) );
+ return $this->register_comment( $comment->comment_ID, array( 'on_behalf_of' => $submit_on_behalf_of ) );
+ }
+
+ if ( !empty( $delete_on_behalf_of ) ) {
+ return $this->register( 'delete_comment', $comment->comment_ID, array( 'on_behalf_of' => $delete_on_behalf_of ) );
+ }
+
+ return false;
+ }
+
+ /**
+ * Get a comment and associated data in the standard JP format.
+ * Cannot be called statically
+ *
+ * @param int $id Comment ID
+ * @return Array containing full comment details
+ */
+ function get_comment( $id ) {
+ $comment_obj = get_comment( $id );
+ if ( !$comment_obj )
+ return false;
+ $comment = get_object_vars( $comment_obj );
+
+ $meta = get_comment_meta( $id, false );
+ $comment['meta'] = array();
+ foreach ( $meta as $key => $value ) {
+ $comment['meta'][$key] = array_map( 'maybe_unserialize', $value );
+ }
+
+ return $comment;
+ }
+
+/* Options Sync */
+
+ /* Ah... so much simpler than Posts and Comments :) */
+ function options( $file, $option /*, $option, ... */ ) {
+ $options = func_get_args();
+ $file = array_shift( $options );
+
+ $module_slug = Jetpack::get_module_slug( $file );
+
+ if ( !isset( $this->sync_options[$module_slug] ) ) {
+ $this->sync_options[$module_slug] = array();
+ }
+
+ foreach ( $options as $option ) {
+ $this->sync_options[$module_slug][] = $option;
+ add_action( "delete_option_{$option}", array( $this, 'deleted_option_action' ) );
+ add_action( "update_option_{$option}", array( $this, 'updated_option_action' ) );
+ add_action( "add_option_{$option}", array( $this, 'added_option_action' ) );
+ }
+
+ $this->sync_options[$module_slug] = array_unique( $this->sync_options[$module_slug] );
+ }
+
+ function deleted_option_action( $option ) {
+ $this->register( 'delete_option', $option );
+ }
+
+ function updated_option_action( $old_value ) {
+ // The value of $option isn't passed to the filter
+ // Calculate it
+ $option = current_filter();
+ $prefix = 'update_option_';
+ if ( 0 !== strpos( $option, $prefix ) ) {
+ return;
+ }
+ $option = substr( $option, strlen( $prefix ) );
+
+ $this->added_option_action( $option );
+ }
+
+ function added_option_action( $option ) {
+ $this->register( 'option', $option );
+ }
+
+ function sync_all_module_options( $module_slug ) {
+ if ( empty( $this->sync_options[$module_slug] ) ) {
+ return;
+ }
+
+ foreach ( $this->sync_options[$module_slug] as $option ) {
+ $this->added_option_action( $option );
+ }
+ }
+
+ function sync_all_registered_options( $options = array() ) {
+ if ( 'jetpack_sync_all_registered_options' == current_filter() ) {
+ $all_registered_options = array_unique( call_user_func_array( 'array_merge', $this->sync_options ) );
+ foreach ( $all_registered_options as $option ) {
+ $this->added_option_action( $option );
+ }
+ } else {
+ wp_schedule_single_event( time(), 'jetpack_sync_all_registered_options', array( $this->sync_options ) );
+ }
+ }
+}
diff --git a/plugins/jetpack/class.jetpack.php b/plugins/jetpack/class.jetpack.php
new file mode 100644
index 00000000..229d0835
--- /dev/null
+++ b/plugins/jetpack/class.jetpack.php
@@ -0,0 +1,3684 @@
+<?php
+
+/*
+Options:
+jetpack_options (array)
+ An array of options.
+ @see Jetpack::get_option_names()
+
+jetpack_register (string)
+ Temporary verification secrets.
+
+jetpack_activated (int)
+ 1: the plugin was activated normally
+ 2: the plugin was activated on this site because of a network-wide activation
+ 3: the plugin was auto-installed
+ 4: the plugin was manually disconnected (but is still installed)
+
+jetpack_active_modules (array)
+ Array of active module slugs.
+
+jetpack_do_activate (bool)
+ Flag for "activating" the plugin on sites where the activation hook never fired (auto-installs)
+*/
+
+class Jetpack {
+ var $xmlrpc_server = null;
+
+ var $HTTP_RAW_POST_DATA = null; // copy of $GLOBALS['HTTP_RAW_POST_DATA']
+
+ var $plugins_to_deactivate = array(
+ 'stats' => array( 'stats/stats.php', 'WordPress.com Stats' ),
+ 'shortlinks' => array( 'stats/stats.php', 'WordPress.com Stats' ),
+ 'sharedaddy' => array( 'sharedaddy/sharedaddy.php', 'Sharedaddy' ),
+ 'twitter-widget' => array( 'wickett-twitter-widget/wickett-twitter-widget.php', 'Wickett Twitter Widget' ),
+ 'after-the-deadline' => array( 'after-the-deadline/after-the-deadline.php', 'After The Deadline' ),
+ 'contact-form' => array( 'grunion-contact-form/grunion-contact-form.php', 'Grunion Contact Form' ),
+ 'custom-css' => array( 'safecss/safecss.php', 'WordPress.com Custom CSS' ),
+ );
+
+ var $capability_translations = array(
+ 'administrator' => 'manage_options',
+ 'editor' => 'edit_others_posts',
+ 'author' => 'publish_posts',
+ 'contributor' => 'edit_posts',
+ 'subscriber' => 'read',
+ );
+
+ /**
+ * Message to display in admin_notice
+ * @var string
+ */
+ var $message = '';
+
+ /**
+ * Error to display in admin_notice
+ * @var string
+ */
+ var $error = '';
+
+ /**
+ * Modules that need more privacy description.
+ * @var string
+ */
+ var $privacy_checks = '';
+
+ /**
+ * Stats to record once the page loads
+ *
+ * @var array
+ */
+ var $stats = array();
+
+ /**
+ * Jetpack_Sync object
+ */
+ var $sync;
+
+ /**
+ * Verified data for JSON authorization request
+ */
+ var $json_api_authorization_request = array();
+
+ /**
+ * Holds the singleton instance of this class
+ * @since 2.3.3
+ * @var Jetpack
+ */
+ static $instance = false;
+
+ /**
+ * Singleton
+ * @static
+ */
+ public static function init() {
+ if ( ! self::$instance ) {
+ if ( did_action( 'plugins_loaded' ) )
+ self::plugin_textdomain();
+ else
+ add_action( 'plugins_loaded', array( __CLASS__, 'plugin_textdomain' ) );
+
+ self::$instance = new Jetpack;
+
+ self::$instance->plugin_upgrade();
+ }
+
+ return self::$instance;
+ }
+
+ /**
+ * 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::get_option_names() as $option ) {
+ if ( false !== $value = get_option( "jetpack_$option" ) ) {
+ $options[$option] = $value;
+ }
+ }
+
+ if ( $options ) {
+ Jetpack::update_options( $options );
+
+ foreach ( array_keys( $options ) as $option ) {
+ delete_option( "jetpack_$option" );
+ }
+ }
+
+ // Add missing version and old_version options
+ if ( !$version = Jetpack::get_option( 'version' ) ) {
+ $version = $old_version = '1.1:' . time();
+ Jetpack::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::get_option( 'user_tokens' ) ) {
+ if ( $user_token = Jetpack::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::update_options( compact( 'master_user', 'user_tokens' ) );
+ Jetpack::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 );
+ }
+ }
+ }
+ }
+
+ /**
+ * Constructor. Initializes WordPress hooks
+ */
+ private function Jetpack() {
+ $this->sync = new Jetpack_Sync;
+
+ // Modules should do Jetpack_Sync::sync_options( __FILE__, $option, ... ); instead
+ // We access the "internal" method here only because the Jetpack object isn't instantiated yet
+ $this->sync->options( __FILE__,
+ 'home',
+ 'siteurl',
+ 'blogname',
+ 'gmt_offset',
+ 'timezone_string'
+ );
+
+ if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST && isset( $_GET['for'] ) && 'jetpack' == $_GET['for'] ) {
+ @ini_set( 'display_errors', false ); // Display errors can cause the XML to be not well formed.
+
+ require_once dirname( __FILE__ ) . '/class.jetpack-xmlrpc-server.php';
+ $this->xmlrpc_server = new Jetpack_XMLRPC_Server();
+
+ $this->require_jetpack_authentication();
+
+ if ( Jetpack::is_active() ) {
+ // Hack to preserve $HTTP_RAW_POST_DATA
+ add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ) );
+
+ // The actual API methods.
+ add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'xmlrpc_methods' ) );
+ } else {
+ // The bootstrap API methods.
+ add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'bootstrap_xmlrpc_methods' ) );
+ }
+
+ // Now that no one can authenticate, and we're whitelisting all XML-RPC methods, force enable_xmlrpc on.
+ add_filter( 'pre_option_enable_xmlrpc', '__return_true' );
+ } elseif ( is_admin() && isset( $_POST['action'] ) && 'jetpack_upload_file' == $_POST['action'] ) {
+ $this->require_jetpack_authentication();
+ $this->add_remote_request_handlers();
+ } else {
+ if ( Jetpack::is_active() ) {
+ add_action( 'login_form_jetpack_json_api_authorization', array( &$this, 'login_form_json_api_authorization' ) );
+ }
+ }
+
+ add_action( 'jetpack_clean_nonces', array( 'Jetpack', 'clean_nonces' ) );
+ if ( !wp_next_scheduled( 'jetpack_clean_nonces' ) ) {
+ wp_schedule_event( time(), 'hourly', 'jetpack_clean_nonces' );
+ }
+
+ add_filter( 'xmlrpc_blog_options', array( $this, 'xmlrpc_options' ) );
+
+ add_action( 'admin_menu', array( $this, 'admin_menu' ), 999 ); // run late so that other plugins hooking into this menu don't get left out
+ add_action( 'admin_init', array( $this, 'admin_init' ) );
+ add_action( 'admin_init', array( $this, 'dismiss_jetpack_notice' ) );
+
+ add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
+
+ add_action( 'wp_ajax_jetpack-check-news-subscription', array( $this, 'check_news_subscription' ) );
+ add_action( 'wp_ajax_jetpack-subscribe-to-news', array( $this, 'subscribe_to_news' ) );
+
+ 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' ) );
+ add_action( 'admin_enqueue_scripts', array( $this, 'devicepx' ) );
+
+ // add_action( 'jetpack_admin_menu', array( $this, 'admin_menu_modules' ) );
+
+ add_action( 'jetpack_activate_module', array( $this, 'activate_module_actions' ) );
+
+ /**
+ * These actions run checks to load additional files.
+ * They check for external files or plugins, so thef need to run as late as possible.
+ */
+ add_action( 'plugins_loaded', array( $this, 'check_open_graph' ), 999 );
+ add_action( 'plugins_loaded', array( $this, 'check_rest_api_compat' ), 1000 );
+ }
+
+ /**
+ * If there are any stats that need to be pushed, but haven't been, push them now.
+ */
+ function __destruct() {
+ if ( ! empty( $this->stats ) ) {
+ $this->do_stats( 'server_side' );
+ }
+ }
+
+ function require_jetpack_authentication() {
+ // Don't let anyone authenticate
+ $_COOKIE = array();
+ remove_all_filters( 'authenticate' );
+
+ if ( Jetpack::is_active() ) {
+ // Allow Jetpack authentication
+ add_filter( 'authenticate', array( $this, 'authenticate_jetpack' ), 10, 3 );
+ }
+ }
+
+ /**
+ * Load language files
+ */
+ public static function plugin_textdomain() {
+ load_plugin_textdomain( 'jetpack', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
+ }
+
+ /**
+ * Register assets for use in various modules and the Jetpack admin page.
+ *
+ * @uses wp_script_is, wp_register_script, plugins_url
+ * @action wp_loaded
+ * @return null
+ */
+ public function register_assets() {
+ if ( ! wp_script_is( 'spin', 'registered' ) )
+ wp_register_script( 'spin', plugins_url( '_inc/spin.js', __FILE__ ), false, '1.3' );
+
+ if ( ! wp_script_is( 'jquery.spin', 'registered' ) )
+ wp_register_script( 'jquery.spin', plugins_url( '_inc/jquery.spin.js', __FILE__ ) , array( 'jquery', 'spin' ), '1.3' );
+
+ if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) )
+ wp_register_script( 'jetpack-gallery-settings', plugins_url( '_inc/gallery-settings.js', __FILE__ ), array( 'media-views' ), '20121225' );
+
+ if ( ! wp_style_is( 'genericons', 'registered' ) )
+ wp_register_style( 'genericons', plugins_url( '_inc/genericons.css', __FILE__ ), false, JETPACK__VERSION );
+ }
+
+ /**
+ * Device Pixels support
+ * This improves the resolution of gravatars and wordpress.com uploads on hi-res and zoomed browsers.
+ */
+ function devicepx() {
+ wp_enqueue_script( 'devicepx', ( is_ssl() ? 'https' : 'http' ) . '://s0.wp.com/wp-content/js/devicepx-jetpack.js', array(), gmdate('oW'), true );
+ }
+
+ /**
+ * Is Jetpack active?
+ */
+ public static function is_active() {
+ return (bool) Jetpack_Data::get_access_token( JETPACK_MASTER_USER );
+ }
+
+ /**
+ * Is Jetpack in development (offline) mode?
+ */
+ public static function is_development_mode() {
+ $development_mode = false;
+
+ if ( defined( 'JETPACK_DEV_DEBUG' ) ) {
+ $development_mode = JETPACK_DEV_DEBUG;
+ }
+
+ elseif ( site_url() && false === strpos( site_url(), '.' ) ) {
+ $development_mode = true;
+ }
+
+ return apply_filters( 'jetpack_development_mode', $development_mode );
+ }
+
+ /**
+ * Is a given user (or the current user if none is specified) linked to a WordPress.com user?
+ */
+ public static function is_user_connected( $user_id = false ) {
+ $user_id = false === $user_id ? get_current_user_id() : absint( $user_id );
+ if ( !$user_id ) {
+ return false;
+ }
+ return (bool) Jetpack_Data::get_access_token( $user_id );
+ }
+
+ function current_user_is_connection_owner() {
+ $user_token = Jetpack_Data::get_access_token( JETPACK_MASTER_USER );
+ return $user_token && is_object( $user_token ) && isset( $user_token->external_user_id ) && get_current_user_id() === $user_token->external_user_id;
+ }
+
+ /**
+ * Synchronize connected user role changes
+ */
+ function user_role_change( $user_id ) {
+ if ( Jetpack::is_active() && Jetpack::is_user_connected( $user_id ) ) {
+
+ $current_user_id = get_current_user_id();
+ wp_set_current_user( $user_id );
+ $role = $this->translate_current_user_to_role();
+ $signed_role = $this->sign_role( $role );
+ wp_set_current_user( $current_user_id );
+
+ $master_token = Jetpack_Data::get_access_token( JETPACK_MASTER_USER );
+ $master_user_id = absint( $master_token->external_user_id );
+
+ if ( !$master_user_id )
+ return; // this shouldn't happen
+
+ Jetpack::xmlrpc_async_call( 'jetpack.updateRole', $user_id, $signed_role );
+ //@todo retry on failure
+
+ //try to choose a new master if we're demoting the current one
+ if ( $user_id == $master_user_id && 'administrator' != $role ) {
+ $query = new WP_User_Query( array(
+ 'fields' => array( 'id' ),
+ 'role' => 'administrator',
+ 'orderby' => 'id',
+ 'exclude' => array( $master_user_id ),
+ )
+ );
+ $new_master = false;
+ foreach ( $query->results as $result ) {
+ $uid = absint( $result->id );
+ if ( $uid && Jetpack::is_user_connected( $uid ) ) {
+ $new_master = $uid;
+ break;
+ }
+ }
+
+ if ( $new_master ) {
+ Jetpack::update_option( 'master_user', $new_master );
+ }
+ // else disconnect..?
+ }
+ }
+ }
+
+ /**
+ * Loads the currently active modules.
+ */
+ public static function load_modules() {
+
+ /*
+ if ( ! Jetpack::is_active() && ! Jetpack::is_development_mode() ) {
+ return;
+ }
+ */
+
+ $version = Jetpack::get_option( 'version' );
+ if ( !$version ) {
+ $version = $old_version = JETPACK__VERSION . ':' . time();
+ Jetpack::update_options( compact( 'version', 'old_version' ) );
+ }
+ list( $version ) = explode( ':', $version );
+
+ $modules = array_filter( Jetpack::get_active_modules(), array( 'Jetpack', 'is_module' ) );
+
+ $modules_data = array();
+
+ // Don't load modules that have had "Major" changes since the stored version until they have been deactivated/reactivated through the lint check.
+ if ( version_compare( $version, JETPACK__VERSION, '<' ) ) {
+ $updated_modules = array();
+ foreach ( $modules as $module ) {
+ $modules_data[ $module ] = Jetpack::get_module( $module );
+ if ( ! isset( $modules_data[ $module ]['changed'] ) ) {
+ continue;
+ }
+
+ if ( version_compare( $modules_data[ $module ]['changed'], $version, '<=' ) ) {
+ continue;
+ }
+
+ $updated_modules[] = $module;
+ }
+
+ $modules = array_diff( $modules, $updated_modules );
+ }
+
+ foreach ( $modules as $module ) {
+ // If not connected and we're in dev mode, disable modules requiring a connection
+ if ( ! Jetpack::is_active() ) {
+ if ( empty( $modules_data[ $module ] ) ) {
+ $modules_data[ $module ] = Jetpack::get_module( $module );
+ }
+ if ( $modules_data[ $module ]['requires_connection'] || ! Jetpack::is_development_mode() ) {
+ continue;
+ }
+ }
+
+ if ( did_action( 'jetpack_module_loaded_' . $module ) ) {
+ continue;
+ }
+
+ require Jetpack::get_module_path( $module );
+ do_action( 'jetpack_module_loaded_' . $module );
+ }
+
+ do_action( 'jetpack_modules_loaded' );
+
+ // Load module-specific code that is needed even when a module isn't active. Loaded here because code contained therein may need actions such as setup_theme.
+ require_once( dirname( __FILE__ ) . '/modules/module-extras.php' );
+ }
+
+ /**
+ * Check if Jetpack's REST API compat file should be included
+ * @action plugins_loaded
+ * @return null
+ */
+ public function check_rest_api_compat() {
+ $_jetpack_rest_api_compat_includes = apply_filters( 'jetpack_rest_api_compat', array() );
+
+ if ( function_exists( 'bbpress' ) )
+ $_jetpack_rest_api_compat_includes[] = dirname( __FILE__ ) . '/class.jetpack-bbpress-json-api-compat.php';
+
+ foreach ( $_jetpack_rest_api_compat_includes as $_jetpack_rest_api_compat_include )
+ require_once $_jetpack_rest_api_compat_include;
+ }
+
+ /**
+ * Check if Jetpack's Open Graph tags should be used.
+ * If certain plugins are active, Jetpack's og tags are suppressed.
+ *
+ * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters
+ * @action plugins_loaded
+ * @return null
+ */
+ public function check_open_graph() {
+ if ( in_array( 'publicize', Jetpack::get_active_modules() ) || in_array( 'sharedaddy', Jetpack::get_active_modules() ) )
+ add_filter( 'jetpack_enable_open_graph', '__return_true', 0 );
+
+ $active_plugins = get_option( 'active_plugins', array() );
+
+ if ( is_multisite() ) {
+ // Due to legacy code, active_sitewide_plugins stores them in the keys,
+ // whereas active_plugins stores them in the values.
+ $network_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
+ if ( $network_plugins ) {
+ $active_plugins = array_merge( $active_plugins, $network_plugins );
+ }
+ }
+
+ $conflicting_plugins = array(
+ 'facebook/facebook.php', // Official Facebook plugin
+ 'wordpress-seo/wp-seo.php', // WordPress SEO by Yoast
+ 'add-link-to-facebook/add-link-to-facebook.php', // Add Link to Facebook
+ 'facebook-awd/AWD_facebook.php', // Facebook AWD All in one
+ 'header-footer/plugin.php', // Header and Footer
+ 'nextgen-facebook/nextgen-facebook.php', // NextGEN Facebook OG
+ 'seo-facebook-comments/seofacebook.php', // SEO Facebook Comments
+ 'seo-ultimate/seo-ultimate.php', // SEO Ultimate
+ 'sexybookmarks/sexy-bookmarks.php', // Shareaholic
+ 'shareaholic/sexy-bookmarks.php', // Shareaholic
+ 'social-discussions/social-discussions.php', // Social Discussions
+ 'social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php', // NextScripts SNAP
+ 'wordbooker/wordbooker.php', // Wordbooker
+ 'socialize/socialize.php', // Socialize
+ 'simple-facebook-connect/sfc.php', // Simple Facebook Connect
+ 'social-sharing-toolkit/social_sharing_toolkit.php', // Social Sharing Toolkit
+ 'wp-facebook-open-graph-protocol/wp-facebook-ogp.php', // WP Facebook Open Graph protocol
+ 'opengraph/opengraph.php', // Open Graph
+ 'sharepress/sharepress.php', // SharePress
+ 'wp-facebook-like-send-open-graph-meta/wp-facebook-like-send-open-graph-meta.php', // WP Facebook Like Send & Open Graph Meta
+ 'network-publisher/networkpub.php', // Network Publisher
+ 'wp-ogp/wp-ogp.php', // WP-OGP
+ );
+
+ foreach ( $conflicting_plugins as $plugin ) {
+ if ( in_array( $plugin, $active_plugins ) ) {
+ add_filter( 'jetpack_enable_open_graph', '__return_false', 99 );
+ break;
+ }
+ }
+
+ if ( apply_filters( 'jetpack_enable_open_graph', false ) )
+ require_once dirname( __FILE__ ) . '/functions.opengraph.php';
+ }
+
+/* Jetpack Options API */
+
+ public static function get_option_names( $type = 'compact' ) {
+ return Jetpack_Options::get_option_names( $type );
+ }
+
+ /**
+ * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate.
+ *
+ * @param string $name Option name
+ * @param mixed $default (optional)
+ */
+ public static function get_option( $name, $default = false ) {
+ return Jetpack_Options::get_option( $name, $default );
+ }
+
+ /**
+ * Stores two secrets and a timestamp so WordPress.com can make a request back and verify an action
+ * Does some extra verification so urls (such as those to public-api, register, etc) cant just be crafted
+ * $name must be a registered option name.
+ */
+ public static function create_nonce( $name ) {
+ $secret = wp_generate_password( 32, false ) . ':' . wp_generate_password( 32, false ) . ':' . ( time() + 600 );
+
+ Jetpack::update_option( $name, $secret );
+ @list( $secret_1, $secret_2, $eol ) = explode( ':', Jetpack::get_option( $name ) );
+ if ( empty( $secret_1 ) || empty( $secret_2 ) || $eol < time() )
+ return new Jetpack_Error( 'missing_secrets' );
+
+ return array(
+ 'secret_1' => $secret_1,
+ 'secret_2' => $secret_2,
+ 'eol' => $eol,
+ );
+ }
+
+ /**
+ * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate.
+ *
+ * @param string $name Option name
+ * @param mixed $value Option value
+ */
+ public static function update_option( $name, $value ) {
+ return Jetpack_Options::update_option( $name, $value );
+ }
+
+ /**
+ * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate.
+ *
+ * @param array $array array( option name => option value, ... )
+ */
+ public static function update_options( $array ) {
+ return Jetpack_Options::update_options( $array );
+ }
+
+ /**
+ * Deletes the given option. May be passed multiple option names as an array.
+ * Updates jetpack_options and/or deletes jetpack_$name as appropriate.
+ *
+ * @param string|array $names
+ */
+ public static function delete_option( $names ) {
+ return Jetpack_Options::delete_option( $names );
+ }
+
+ /**
+ * Enters a user token into the user_tokens option
+ *
+ * @param int $user_id
+ * @param string $token
+ * return bool
+ */
+ public static function update_user_token( $user_id, $token, $is_master_user ) {
+ // not designed for concurrent updates
+ $user_tokens = Jetpack::get_option( 'user_tokens' );
+ if ( ! is_array( $user_tokens ) )
+ $user_tokens = array();
+ $user_tokens[$user_id] = $token;
+ if ( $is_master_user ) {
+ $master_user = $user_id;
+ $options = compact('user_tokens', 'master_user');
+ } else {
+ $options = compact('user_tokens');
+ }
+ return Jetpack::update_options( $options );
+ }
+
+ /**
+ * Returns an array of all PHP files in the specified absolute path.
+ * Equivalent to glob( "$absolute_path/*.php" ).
+ *
+ * @param string $absolute_path The absolute path of the directory to search.
+ * @return array Array of absolute paths to the PHP files.
+ */
+ public static function glob_php( $absolute_path ) {
+ $absolute_path = untrailingslashit( $absolute_path );
+ $files = array();
+ if ( !$dir = @opendir( $absolute_path ) ) {
+ return $files;
+ }
+
+ while ( false !== $file = readdir( $dir ) ) {
+ if ( '.' == substr( $file, 0, 1 ) || '.php' != substr( $file, -4 ) ) {
+ continue;
+ }
+
+ $file = "$absolute_path/$file";
+
+ if ( !is_file( $file ) ) {
+ continue;
+ }
+
+ $files[] = $file;
+ }
+
+ closedir( $dir );
+
+ return $files;
+ }
+
+ public function activate_new_modules() {
+ if ( ! Jetpack::is_active() && ! Jetpack::is_development_mode() ) {
+ return;
+ }
+
+ $jetpack_old_version = Jetpack::get_option( 'version' ); // [sic]
+ if ( !$jetpack_old_version ) {
+ $jetpack_old_version = $version = $old_version = '1.1:' . time();
+ Jetpack::update_options( compact( 'version', 'old_version' ) );
+ }
+
+ list( $jetpack_version ) = explode( ':', $jetpack_old_version ); // [sic]
+
+ if ( version_compare( JETPACK__VERSION, $jetpack_version, '<=' ) ) {
+ return;
+ }
+
+ $active_modules = Jetpack::get_active_modules();
+ $reactivate_modules = array();
+ foreach ( $active_modules as $active_module ) {
+ $module = Jetpack::get_module( $active_module );
+ if ( !isset( $module['changed'] ) ) {
+ continue;
+ }
+
+ if ( version_compare( $module['changed'], $jetpack_version, '<=' ) ) {
+ continue;
+ }
+
+ $reactivate_modules[] = $active_module;
+ Jetpack::deactivate_module( $active_module );
+ }
+
+ if ( version_compare( $jetpack_version, '1.9.2', '<' ) && version_compare( '1.9-something', JETPACK__VERSION, '<' ) ) {
+ add_action( 'jetpack_activate_default_modules', array( $this->sync, 'sync_all_registered_options' ), 1000 );
+ }
+
+ Jetpack::update_options( array(
+ 'version' => JETPACK__VERSION . ':' . time(),
+ 'old_version' => $jetpack_old_version,
+ ) );
+
+ Jetpack::state( 'message', 'modules_activated' );
+ Jetpack::activate_default_modules( $jetpack_version, JETPACK__VERSION, $reactivate_modules );
+ wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) );
+ exit;
+ }
+
+ /**
+ * List available Jetpack modules. Simply lists .php files in /modules/.
+ * Make sure to tuck away module "library" files in a sub-directory.
+ */
+ public static function get_available_modules( $min_version = false, $max_version = false ) {
+ static $modules = null;
+
+ if ( !isset( $modules ) ) {
+ $files = Jetpack::glob_php( dirname( __FILE__ ) . '/modules' );
+
+ $modules = array();
+
+ foreach ( $files as $file ) {
+ if ( !$headers = Jetpack::get_module( $file ) ) {
+ continue;
+ }
+
+ $modules[ Jetpack::get_module_slug( $file ) ] = $headers['introduced'];
+ }
+ }
+
+ if ( !$min_version && !$max_version ) {
+ return array_keys( $modules );
+ }
+
+ $r = array();
+ foreach ( $modules as $slug => $introduced ) {
+ if ( $min_version && version_compare( $min_version, $introduced, '>=' ) ) {
+ continue;
+ }
+
+ if ( $max_version && version_compare( $max_version, $introduced, '<' ) ) {
+ continue;
+ }
+
+ $r[] = $slug;
+ }
+
+ return $r;
+ }
+
+ /**
+ * Default modules loaded on activation.
+ */
+ public static function get_default_modules( $min_version = false, $max_version = false ) {
+ $return = array();
+
+ foreach ( Jetpack::get_available_modules( $min_version, $max_version ) as $module ) {
+ // Add special cases here for modules to avoid auto-activation
+ switch ( $module ) {
+
+ // These modules are default off: they change things blog-side
+ case 'comments' :
+ case 'carousel' :
+ case 'minileven':
+ case 'infinite-scroll' :
+ case 'photon' :
+ case 'tiled-gallery' :
+ case 'likes' :
+ break;
+
+ // These modules are default off if we think the site is a private one
+ case 'enhanced-distribution' :
+ case 'json-api' :
+ if ( !Jetpack::get_option( 'public' ) ) {
+ break;
+ }
+ // else no break
+ // The rest are default on
+ default :
+ $return[] = $module;
+ }
+ }
+
+ return $return;
+ }
+
+ /**
+ * Extract a module's slug from its full path.
+ */
+ public static function get_module_slug( $file ) {
+ return str_replace( '.php', '', basename( $file ) );
+ }
+
+ /**
+ * Generate a module's path from its slug.
+ */
+ public static function get_module_path( $slug ) {
+ return dirname( __FILE__ ) . "/modules/$slug.php";
+ }
+
+ /**
+ * Load module data from module file. Headers differ from WordPress
+ * plugin headers to avoid them being identified as standalone
+ * plugins on the WordPress plugins page.
+ */
+ public static function get_module( $module ) {
+ $headers = array(
+ 'name' => 'Module Name',
+ 'description' => 'Module Description',
+ 'sort' => 'Sort Order',
+ 'introduced' => 'First Introduced',
+ 'changed' => 'Major Changes In',
+ 'deactivate' => 'Deactivate',
+ 'free' => 'Free',
+ 'requires_connection' => 'Requires Connection',
+ );
+
+ $file = Jetpack::get_module_path( Jetpack::get_module_slug( $module ) );
+ if ( !file_exists( $file ) )
+ return false;
+
+ $mod = get_file_data( $file, $headers );
+ if ( empty( $mod['name'] ) )
+ return false;
+
+ $mod['name'] = translate( $mod['name'], 'jetpack' );
+ $mod['description'] = translate( $mod['description'], 'jetpack' );
+ if ( empty( $mod['sort'] ) )
+ $mod['sort'] = 10;
+ $mod['deactivate'] = empty( $mod['deactivate'] );
+ $mod['free'] = empty( $mod['free'] );
+ $mod['requires_connection'] = ( ! empty( $mod['requires_connection'] ) && 'No' == $mod['requires_connection'] ) ? false : true;
+ return $mod;
+ }
+
+ /**
+ * Get a list of activated modules as an array of module slugs.
+ */
+ public static function get_active_modules() {
+ $active = Jetpack::get_option( 'active_modules' );
+ if ( !is_array( $active ) )
+ $active = array();
+ if ( is_admin() ) {
+ $active[] = 'vaultpress';
+ } else {
+ $active = array_diff( $active, array( 'vaultpress' ) );
+ }
+ return array_unique( $active );
+ }
+
+ /**
+ * Check whether or not a Jetpack module is active.
+ *
+ * @param string $module The slug of a Jetpack module.
+ * @return bool
+ *
+ * @static
+ */
+ public static function is_module_active( $module ) {
+ return in_array( $module, self::get_active_modules() );
+ }
+
+ public static function is_module( $module ) {
+ return !empty( $module ) && !validate_file( $module, Jetpack::get_available_modules() );
+ }
+
+ /**
+ * Catches PHP errors. Must be used in conjunction with output buffering.
+ *
+ * @param bool $catch True to start catching, False to stop.
+ *
+ * @static
+ */
+ public static function catch_errors( $catch ) {
+ static $display_errors, $error_reporting;
+
+ if ( $catch ) {
+ $display_errors = @ini_set( 'display_errors', 1 );
+ $error_reporting = @error_reporting( E_ALL );
+ add_action( 'shutdown', array( 'Jetpack', 'catch_errors_on_shutdown' ), 0 );
+ } else {
+ @ini_set( 'display_errors', $display_errors );
+ @error_reporting( $error_reporting );
+ remove_action( 'shutdown', array( 'Jetpack', 'catch_errors_on_shutdown' ), 1 );
+ }
+ }
+
+ /**
+ * Saves any generated PHP errors in ::state( 'php_errors', {errors} )
+ */
+ public static function catch_errors_on_shutdown() {
+ Jetpack::state( 'php_errors', ob_get_clean() );
+ }
+
+ public static function activate_default_modules( $min_version = false, $max_version = false, $other_modules = array() ) {
+ $jetpack = Jetpack::init();
+
+ $modules = Jetpack::get_default_modules( $min_version, $max_version );
+ $modules = array_merge( $other_modules, $modules );
+
+ // Look for standalone plugins and disable if active.
+
+ $to_deactivate = array();
+ foreach ( $modules as $module ) {
+ if ( isset( $jetpack->plugins_to_deactivate[$module] ) ) {
+ $to_deactivate[$module] = $jetpack->plugins_to_deactivate[$module];
+ }
+ }
+
+ $deactivated = array();
+ foreach ( $to_deactivate as $module => $deactivate_me ) {
+ list( $probable_file, $probable_title ) = $deactivate_me;
+ if ( Jetpack_Client_Server::deactivate_plugin( $probable_file, $probable_title ) ) {
+ $deactivated[] = $module;
+ }
+ }
+
+ if ( $deactivated ) {
+ Jetpack::state( 'deactivated_plugins', join( ',', $deactivated ) );
+
+ $url = add_query_arg( array(
+ 'action' => 'activate_default_modules',
+ '_wpnonce' => wp_create_nonce( 'activate_default_modules' ),
+ ), add_query_arg( compact( 'min_version', 'max_version', 'other_modules' ), Jetpack::admin_url( 'page=jetpack' ) ) );
+ wp_safe_redirect( $url );
+ exit;
+ }
+
+ do_action( 'jetpack_before_activate_default_modules', $min_version, $max_version, $other_modules );
+
+ // Check each module for fatal errors, a la wp-admin/plugins.php::activate before activating
+ $redirect = menu_page_url( 'jetpack', false );
+ Jetpack::restate();
+ Jetpack::catch_errors( true );
+ foreach ( $modules as $module ) {
+ if ( did_action( "jetpack_module_loaded_$module" ) ) {
+ $active[] = $module;
+ Jetpack::update_option( 'active_modules', array_unique( $active ) );
+ continue;
+ }
+ $active = Jetpack::get_active_modules();
+ if ( in_array( $module, $active ) ) {
+ $module_info = Jetpack::get_module( $module );
+ if ( !$module_info['deactivate'] ) {
+ $state = in_array( $module, $other_modules ) ? 'reactivated_modules' : 'activated_modules';
+ if ( $active_state = Jetpack::state( $state ) ) {
+ $active_state = explode( ',', $active_state );
+ } else {
+ $active_state = array();
+ }
+ $active_state[] = $module;
+ Jetpack::state( $state, implode( ',', $active_state ) );
+ }
+ continue;
+ }
+
+ $file = Jetpack::get_module_path( $module );
+ if ( !file_exists( $file ) ) {
+ continue;
+ }
+
+ // we'll override this later if the plugin can be included without fatal error
+ wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) );
+ Jetpack::state( 'error', 'module_activation_failed' );
+ Jetpack::state( 'module', $module );
+ ob_start();
+ require $file;
+ do_action( 'jetpack_activate_module', $module );
+ $active[] = $module;
+ $state = in_array( $module, $other_modules ) ? 'reactivated_modules' : 'activated_modules';
+ if ( $active_state = Jetpack::state( $state ) ) {
+ $active_state = explode( ',', $active_state );
+ } else {
+ $active_state = array();
+ }
+ $active_state[] = $module;
+ Jetpack::state( $state, implode( ',', $active_state ) );
+ Jetpack::update_option( 'active_modules', array_unique( $active ) );
+ ob_end_clean();
+ }
+ Jetpack::state( 'error', false );
+ Jetpack::state( 'module', false );
+ Jetpack::catch_errors( false );
+ do_action( 'jetpack_activate_default_modules', $min_version, $max_version, $other_modules );
+ }
+
+ public static function activate_module( $module, $exit = true ) {
+ $jetpack = Jetpack::init();
+
+ if ( ! strlen( $module ) )
+ return false;
+
+ if ( ! Jetpack::is_module( $module ) )
+ return false;
+
+ // If it's already active, then don't do it again
+ $active = Jetpack::get_active_modules();
+ foreach ( $active as $act ) {
+ if ( $act == $module )
+ return true;
+ }
+
+ $module_data = Jetpack::get_module( $module );
+
+ if ( ! Jetpack::is_active() ) {
+ if ( ! Jetpack::is_development_mode() )
+ return false;
+
+ // If we're not connected but in development mode, make sure the module doesn't require a connection
+ if ( Jetpack::is_development_mode() && $module_data['requires_connection'] )
+ return false;
+ }
+
+ // Check and see if the old plugin is active
+ if ( isset( $jetpack->plugins_to_deactivate[$module] ) ) {
+ // Deactivate the old plugin
+ if ( Jetpack_Client_Server::deactivate_plugin( $jetpack->plugins_to_deactivate[$module][0], $jetpack->plugins_to_deactivate[$module][1] ) ) {
+ // If we deactivated the old plugin, remembere that with ::state() and redirect back to this page to activate the module
+ // We can't activate the module on this page load since the newly deactivated old plugin is still loaded on this page load.
+ Jetpack::state( 'deactivated_plugins', $module );
+ wp_safe_redirect( add_query_arg( 'jetpack_restate', 1 ) );
+ exit;
+ }
+ }
+
+ // Check the file for fatal errors, a la wp-admin/plugins.php::activate
+ Jetpack::state( 'module', $module );
+ Jetpack::state( 'error', 'module_activation_failed' ); // we'll override this later if the plugin can be included without fatal error
+ wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) );
+
+ Jetpack::catch_errors( true );
+ ob_start();
+ require Jetpack::get_module_path( $module );
+ do_action( 'jetpack_activate_module', $module );
+ $active[] = $module;
+ Jetpack::update_option( 'active_modules', array_unique( $active ) );
+ Jetpack::state( 'error', false ); // the override
+ Jetpack::state( 'message', 'module_activated' );
+ Jetpack::state( 'module', $module );
+ ob_end_clean();
+ Jetpack::catch_errors( false );
+
+ if ( $exit ) {
+ exit;
+ }
+ }
+
+ function activate_module_actions( $module ) {
+ do_action( "jetpack_activate_module_$module" );
+
+ $this->sync->sync_all_module_options( $module );
+ }
+
+ public static function deactivate_module( $module ) {
+ $active = Jetpack::get_active_modules();
+ $new = array();
+ foreach ( $active as $check ) {
+ if ( !empty( $check ) && $module != $check )
+ $new[] = $check;
+ }
+
+ do_action( "jetpack_deactivate_module_$module" );
+ return Jetpack::update_option( 'active_modules', array_unique( $new ) );
+ }
+
+ public static function enable_module_configurable( $module ) {
+ $module = Jetpack::get_module_slug( $module );
+ add_filter( 'jetpack_module_configurable_' . $module, '__return_true' );
+ }
+
+ public static function module_configuration_url( $module ) {
+ $module = Jetpack::get_module_slug( $module );
+ return Jetpack::admin_url( array( 'page' => 'jetpack', 'configure' => $module ) );
+ }
+
+ public static function module_configuration_load( $module, $method ) {
+ $module = Jetpack::get_module_slug( $module );
+ add_action( 'jetpack_module_configuration_load_' . $module, $method );
+ }
+
+ public static function module_configuration_head( $module, $method ) {
+ $module = Jetpack::get_module_slug( $module );
+ add_action( 'jetpack_module_configuration_head_' . $module, $method );
+ }
+
+ public static function module_configuration_screen( $module, $method ) {
+ $module = Jetpack::get_module_slug( $module );
+ add_action( 'jetpack_module_configuration_screen_' . $module, $method );
+ }
+
+/* Installation */
+
+ public static function bail_on_activation( $message, $deactivate = true ) {
+?>
+<!doctype html>
+<html>
+<head>
+<meta charset="<?php bloginfo( 'charset' ); ?>">
+<style>
+* {
+ text-align: center;
+ margin: 0;
+ padding: 0;
+ font-family: "Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif;
+}
+p {
+ margin-top: 1em;
+ font-size: 18px;
+}
+</style>
+<body>
+<p><?php echo esc_html( $message ); ?></p>
+</body>
+</html>
+<?php
+ if ( $deactivate ) {
+ $plugins = get_option( 'active_plugins' );
+ $jetpack = plugin_basename( __FILE__ );
+ $update = false;
+ foreach ( $plugins as $i => $plugin ) {
+ if ( $plugin === $jetpack ) {
+ $plugins[$i] = false;
+ $update = true;
+ }
+ }
+
+ if ( $update ) {
+ update_option( 'active_plugins', array_filter( $plugins ) );
+ }
+ }
+ exit;
+ }
+
+ /**
+ * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook()
+ * @static
+ */
+ public static function plugin_activation( $network_wide ) {
+ Jetpack::update_option( 'activated', 1 );
+
+ if ( version_compare( $GLOBALS['wp_version'], JETPACK__MINIMUM_WP_VERSION, '<' ) ) {
+ Jetpack::bail_on_activation( sprintf( __( 'Jetpack requires WordPress version %s or later.', 'jetpack' ), JETPACK__MINIMUM_WP_VERSION ) );
+ }
+
+ if ( $network_wide )
+ Jetpack::state( 'network_nag', true );
+
+ Jetpack::plugin_initialize();
+ }
+
+ /**
+ * Sets the internal version number and activation state.
+ * @static
+ */
+ public static function plugin_initialize() {
+ if ( !Jetpack::get_option( 'activated' ) ) {
+ Jetpack::update_option( 'activated', 2 );
+ }
+
+ if ( !Jetpack::get_option( 'version' ) ) {
+ $version = $old_version = JETPACK__VERSION . ':' . time();
+ Jetpack::update_options( compact( 'version', 'old_version' ) );
+ }
+
+ Jetpack::load_modules();
+
+ Jetpack::delete_option( 'do_activate' );
+ }
+
+ /**
+ * Removes all connection options
+ * @static
+ */
+ public static function plugin_deactivation( ) {
+ Jetpack::disconnect( false );
+
+ Jetpack_Heartbeat::init()->deactivate();
+ }
+
+ /**
+ * Disconnects from the Jetpack servers.
+ * Forgets all connection details and tells the Jetpack servers to do the same.
+ * @static
+ */
+ public static function disconnect( $update_activated_state = true ) {
+ wp_clear_scheduled_hook( 'jetpack_clean_nonces' );
+ Jetpack::clean_nonces( true );
+
+ Jetpack::load_xml_rpc_client();
+ $xml = new Jetpack_IXR_Client();
+ $xml->query( 'jetpack.deregister' );
+
+ Jetpack::delete_option( array(
+ 'register',
+ 'blog_token',
+ 'user_token',
+ 'user_tokens',
+ 'master_user',
+ 'time_diff',
+ 'fallback_no_verify_ssl_certs',
+ ) );
+
+ if ( $update_activated_state ) {
+ Jetpack::update_option( 'activated', 4 );
+ }
+ }
+
+ /**
+ * Unlinks the current user from the linked WordPress.com user
+ */
+ function unlink_user() {
+ if ( !$tokens = Jetpack::get_option( 'user_tokens' ) )
+ return false;
+
+ $user_id = get_current_user_id();
+
+ if ( Jetpack::get_option( 'master_user' ) == $user_id )
+ return false;
+
+ if ( !isset( $tokens[$user_id] ) )
+ return false;
+
+ Jetpack::load_xml_rpc_client();
+ $xml = new Jetpack_IXR_Client( compact( 'user_id' ) );
+ $xml->query( 'jetpack.unlink_user', $user_id );
+
+ unset( $tokens[$user_id] );
+
+ Jetpack::update_option( 'user_tokens', $tokens );
+
+ return true;
+ }
+
+ /**
+ * Attempts Jetpack registration. If it fail, a state flag is set: @see ::admin_page_load()
+ */
+ public static function try_registration() {
+ $result = Jetpack::register();
+
+ // If there was an error with registration and the site was not registered, record this so we can show a message.
+ if ( !$result || is_wp_error( $result ) ) {
+ return $result;
+ } else {
+ return true;
+ }
+ }
+
+/* Admin Pages */
+
+ function admin_init() {
+ // If the plugin is not connected, display a connect message.
+ if (
+ // the plugin was auto-activated and needs its candy
+ Jetpack::get_option( 'do_activate' )
+ ||
+ // the plugin is active, but was never activated. Probably came from a site-wide network activation
+ !Jetpack::get_option( 'activated' )
+ ) {
+ Jetpack::plugin_initialize();
+ }
+
+ if ( !Jetpack::is_active() && ! Jetpack::is_development_mode() ) {
+ if ( 4 != Jetpack::get_option( 'activated' ) ) {
+ // Show connect notice on dashboard and plugins pages
+ add_action( 'load-index.php', array( $this, 'prepare_connect_notice' ) );
+ add_action( 'load-plugins.php', array( $this, 'prepare_connect_notice' ) );
+ }
+ } elseif ( false === Jetpack::get_option( 'fallback_no_verify_ssl_certs' ) ) {
+ // Upgrade: 1.1 -> 1.1.1
+ // Check and see if host can verify the Jetpack servers' SSL certificate
+ $args = array();
+ Jetpack_Client::_wp_remote_request(
+ Jetpack::fix_url_for_bad_hosts( Jetpack::api_url( 'test' ), $args ),
+ $args,
+ true
+ );
+ }
+/* Toggle this off as it's not ready for prime time just yet.
+ if( current_user_can( 'manage_options' ) && self::check_identity_crisis() ) {
+ add_action( 'admin_notices', array( $this, 'alert_identity_crisis' ) );
+ }
+/**/
+
+ if ( current_user_can( 'manage_options' ) && 'ALWAYS' == JETPACK_CLIENT__HTTPS && ! self::permit_ssl() ) {
+ add_action( 'admin_notices', array( $this, 'alert_required_ssl_fail' ) );
+ }
+
+ add_action( 'load-plugins.php', array( $this, 'intercept_plugin_error_scrape_init' ) );
+ add_action( 'admin_head', array( $this, 'admin_menu_css' ) );
+ add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
+
+ if ( Jetpack::is_active() || Jetpack::is_development_mode() ) {
+ // Artificially throw errors in certain whitelisted cases during plugin activation
+ add_action( 'activate_plugin', array( $this, 'throw_error_on_activate_plugin' ) );
+
+ // Kick off synchronization of user role when it changes
+ add_action( 'set_user_role', array( $this, 'user_role_change' ) );
+
+ // Add retina images hotfix to admin
+ global $wp_db_version;
+ if ( ( $wp_db_version > 19470 ) && ( $wp_db_version < 22441 ) ) {
+ // WP 3.4.x
+ // DB Version 22441 = WP 3.5
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_retina_scripts' ) );
+ // /wp-admin/customize.php omits the action above.
+ add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_retina_scripts' ) );
+ }
+ }
+ }
+
+ function admin_body_class( $admin_body_class = '' ) {
+ if ( self::is_active() ) {
+ $admin_body_class .= ' jetpack-connected';
+ } else {
+ $admin_body_class .= ' jetpack-disconnected';
+ }
+ return $admin_body_class;
+ }
+
+ function prepare_connect_notice() {
+ add_action( 'admin_print_styles', array( $this, 'admin_styles' ) );
+
+ add_action( 'admin_notices', array( $this, 'admin_connect_notice' ) );
+
+ if ( Jetpack::state( 'network_nag' ) )
+ add_action( 'network_admin_notices', array( $this, 'network_connect_notice' ) );
+ }
+
+ /**
+ * Sometimes a plugin can activate without causing errors, but it will cause errors on the next page load.
+ * This function artificially throws errors for such cases (whitelisted).
+ *
+ * @param string $plugin The activated plugin.
+ */
+ function throw_error_on_activate_plugin( $plugin ) {
+ $active_modules = Jetpack::get_active_modules();
+
+ // The Shortlinks module and the Stats plugin conflict, but won't cause errors on activation because of some function_exists() checks.
+ if ( function_exists( 'stats_get_api_key' ) && in_array( 'shortlinks', $active_modules ) ) {
+ $throw = false;
+
+ // Try and make sure it really was the stats plugin
+ if ( !class_exists( 'ReflectionFunction' ) ) {
+ if ( 'stats.php' == basename( $plugin ) ) {
+ $throw = true;
+ }
+ } else {
+ $reflection = new ReflectionFunction( 'stats_get_api_key' );
+ if ( basename( $plugin ) == basename( $reflection->getFileName() ) ) {
+ $throw = true;
+ }
+ }
+
+ if ( $throw ) {
+ trigger_error( sprintf( __( 'Jetpack contains the most recent version of the old &#8220;%1$s&#8221; plugin.', 'jetpack' ), 'WordPress.com Stats' ), E_USER_ERROR );
+ }
+ }
+ }
+
+ function intercept_plugin_error_scrape_init() {
+ add_action( 'check_admin_referer', array( $this, 'intercept_plugin_error_scrape' ), 10, 2 );
+ }
+
+ function intercept_plugin_error_scrape( $action, $result ) {
+ if ( !$result ) {
+ return;
+ }
+
+ foreach ( $this->plugins_to_deactivate as $module => $deactivate_me ) {
+ if ( "plugin-activation-error_{$deactivate_me[0]}" == $action ) {
+ Jetpack::bail_on_activation( sprintf( __( 'Jetpack contains the most recent version of the old &#8220;%1$s&#8221; plugin.', 'jetpack' ), $deactivate_me[1] ), false );
+ }
+ }
+ }
+
+ function admin_menu() {
+ list( $jetpack_version ) = explode( ':', Jetpack::get_option( 'version' ) );
+ if (
+ $jetpack_version
+ &&
+ $jetpack_version != JETPACK__VERSION
+ &&
+ ( $new_modules = Jetpack::get_default_modules( $jetpack_version, JETPACK__VERSION ) )
+ &&
+ is_array( $new_modules )
+ &&
+ ( $new_modules_count = count( $new_modules ) )
+ &&
+ ( Jetpack::is_active() || Jetpack::is_development_mode() )
+ ) {
+ $new_modules_count_i18n = number_format_i18n( $new_modules_count );
+ $span_title = esc_attr( sprintf( _n( 'One New Jetpack Module', '%s New Jetpack Modules', $new_modules_count, 'jetpack' ), $new_modules_count_i18n ) );
+ $title = sprintf( 'Jetpack %s', "<span class='update-plugins count-{$new_modules_count}' title='$span_title'><span class='update-count'>$new_modules_count_i18n</span></span>" );
+ } else {
+ $title = __( 'Jetpack', 'jetpack' );
+ }
+
+ $hook = add_menu_page( 'Jetpack', $title, 'read', 'jetpack', array( $this, 'admin_page' ), 'div' );
+
+ $debugger_hook = add_submenu_page( 'jetpack', 'Jetpack Debugging Center', '', 'manage_options', 'jetpack-debugger', array( $this, 'debugger_page' ) );
+ add_action( "admin_head-$debugger_hook", 'jetpack_debug_admin_head' );
+
+
+ add_action( "load-$hook", array( $this, 'admin_page_load' ) );
+
+ if ( version_compare( $GLOBALS['wp_version'], '3.3', '<' ) ) {
+ if ( isset( $_GET['page'] ) && 'jetpack' == $_GET['page'] ) {
+ add_contextual_help( $hook, $this->jetpack_help() );
+ }
+ } else {
+ add_action( "load-$hook", array( $this, 'admin_help' ) );
+ }
+ add_action( "admin_head-$hook", array( $this, 'admin_head' ) );
+ add_filter( 'custom_menu_order', array( $this, 'admin_menu_order' ) );
+ add_filter( 'menu_order', array( $this, 'jetpack_menu_order' ) );
+
+ add_action( "admin_print_styles-$hook", array( $this, 'admin_styles' ) );
+
+ add_action( "admin_print_scripts-$hook", array( $this, 'admin_scripts' ) );
+
+ do_action( 'jetpack_admin_menu' );
+ }
+/*
+ function admin_menu_modules() {
+ $hook = add_submenu_page( 'jetpack', __( 'Jetpack Modules', 'jetpack' ), __( 'Modules', 'jetpack' ), 'edit_posts', 'jetpack_modules', array( $this, 'admin_page_modules' ) );
+
+ add_action( "load-$hook", array( $this, 'admin_page_load' ) );
+ add_action( "load-$hook", array( $this, 'admin_help' ) );
+ add_action( "admin_head-$hook", array( $this, 'admin_head' ) );
+ add_action( "admin_print_styles-$hook", array( $this, 'admin_styles' ) );
+ add_action( "admin_print_scripts-$hook", array( $this, 'admin_scripts' ) );
+ }
+/**/
+ function add_remote_request_handlers() {
+ add_action( 'wp_ajax_nopriv_jetpack_upload_file', array( $this, 'remote_request_handlers' ) );
+ }
+
+ function remote_request_handlers() {
+ switch ( current_filter() ) {
+ case 'wp_ajax_nopriv_jetpack_upload_file' :
+ $response = $this->upload_handler();
+ break;
+ default :
+ $response = new Jetpack_Error( 'unknown_handler', 'Unknown Handler', 400 );
+ break;
+ }
+
+ if ( !$response ) {
+ $response = new Jetpack_Error( 'unknown_error', 'Unknown Error', 400 );
+ }
+
+ if ( is_wp_error( $response ) ) {
+ $status_code = $response->get_error_data();
+ $error = $response->get_error_code();
+ $error_description = $response->get_error_message();
+
+ if ( !is_int( $status_code ) ) {
+ $status_code = 400;
+ }
+
+ status_header( $status_code );
+ die( json_encode( (object) compact( 'error', 'error_description' ) ) );
+ }
+
+ status_header( 200 );
+ if ( true === $response ) {
+ exit;
+ }
+
+ die( json_encode( (object) $response ) );
+ }
+
+ function upload_handler() {
+ if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
+ return new Jetpack_Error( 405, get_status_header_desc( 405 ), 405 );
+ }
+
+ $user = wp_authenticate( '', '' );
+ if ( !$user || is_wp_error( $user ) ) {
+ return new Jetpack_Error( 403, get_status_header_desc( 403 ), 403 );
+ }
+
+ wp_set_current_user( $user->ID );
+
+ if ( !current_user_can( 'upload_files' ) ) {
+ return new Jetpack_Error( 'cannot_upload_files', 'User does not have permission to upload files', 403 );
+ }
+
+ if ( empty( $_FILES ) ) {
+ return new Jetpack_Error( 'no_files_uploaded', 'No files were uploaded: nothing to process', 400 );
+ }
+
+ foreach ( array_keys( $_FILES ) as $files_key ) {
+ if ( !isset( $_POST["_jetpack_file_hmac_{$files_key}"] ) ) {
+ return new Jetpack_Error( 'missing_hmac', 'An HMAC for one or more files is missing', 400 );
+ }
+ }
+
+ $media_keys = array_keys( $_FILES['media'] );
+
+ $token = Jetpack_Data::get_access_token( get_current_user_id() );
+ if ( !$token || is_wp_error( $token ) ) {
+ return new Jetpack_Error( 'unknown_token', 'Unknown Jetpack token', 403 );
+ }
+
+ $uploaded_files = array();
+ $global_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null;
+ unset( $GLOBALS['post'] );
+ foreach ( $_FILES['media']['name'] as $index => $name ) {
+ $file = array();
+ foreach ( $media_keys as $media_key ) {
+ $file[$media_key] = $_FILES['media'][$media_key][$index];
+ }
+
+ list( $hmac_provided, $salt ) = explode( ':', $_POST['_jetpack_file_hmac_media'][$index] );
+
+ $hmac_file = hash_hmac_file( 'sha1', $file['tmp_name'], $salt . $token->secret );
+ if ( $hmac_provided !== $hmac_file ) {
+ $uploaded_files[$index] = (object) array( 'error' => 'invalid_hmac', 'error_description' => 'The corresponding HMAC for this file does not match' );
+ continue;
+ }
+
+ $_FILES['.jetpack.upload.'] = $file;
+ $post_id = isset( $_POST['post_id'][$index] ) ? absint( $_POST['post_id'][$index] ) : 0;
+ if ( !current_user_can( 'edit_post', $post_id ) ) {
+ $post_id = 0;
+ }
+ $attachment_id = media_handle_upload( '.jetpack.upload.', $post_id, array(), array(
+ 'action' => 'jetpack_upload_file',
+ ) );
+
+ if ( !$attachment_id ) {
+ $uploaded_files[$index] = (object) array( 'error' => 'unknown', 'error_description' => 'An unknown problem occurred processing the upload on the Jetpack site' );
+ } elseif ( is_wp_error( $attachment_id ) ) {
+ $uploaded_files[$index] = (object) array( 'error' => 'attachment_' . $attachment_id->get_error_code(), 'error_description' => $attachment_id->get_error_message() );
+ } else {
+ $attachment = get_post( $attachment_id );
+ $uploaded_files[$index] = (object) array(
+ 'id' => (string) $attachment_id,
+ 'file' => $attachment->post_title,
+ 'url' => wp_get_attachment_url( $attachment_id ),
+ 'type' => $attachment->post_mime_type,
+ 'meta' => wp_get_attachment_metadata( $attachment_id ),
+ );
+ }
+ }
+ if ( !is_null( $global_post ) ) {
+ $GLOBALS['post'] = $global_post;
+ }
+
+ return $uploaded_files;
+ }
+
+ /**
+ * Add help to the Jetpack page
+ *
+ * Deprecated. Remove when Jetpack requires WP 3.3+
+ */
+ function jetpack_help() {
+ return
+ '<p><strong>' . __( 'Jetpack by WordPress.com', 'jetpack' ) . '</strong></p>' .
+ '<p>' . __( 'Jetpack supercharges your self-hosted WordPress site with the awesome cloud power of WordPress.com.', 'jetpack' ) . '</p>' .
+ '<p>' . __( 'On this page, you are able to view the modules available within Jetpack, learn more about them, and activate or deactivate them as needed.', 'jetpack' ) . '</p>' .
+ '<p><strong>' . __( 'Jetpack Module Options', 'jetpack' ) . '</strong></p>' .
+ '<p>' . __( '<strong>To Activate/Deactivate a Module</strong> - Click on Learn More. An Activate or Deactivate button will now appear next to the Learn More button. Click the Activate/Deactivate button.', 'jetpack' ) . '</p>' .
+ '<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>';
+ }
+
+ /**
+ * Add help to the Jetpack page
+ *
+ * @since Jetpack (1.2.3)
+ * @return false if not the Jetpack page
+ */
+ function admin_help() {
+ $current_screen = get_current_screen();
+
+ // Overview
+ $current_screen->add_help_tab( array(
+ 'id' => 'overview',
+ 'title' => __( 'Overview', 'jetpack' ),
+ 'content' =>
+ '<p><strong>' . __( 'Jetpack by WordPress.com', 'jetpack' ) . '</strong></p>' .
+ '<p>' . __( 'Jetpack supercharges your self-hosted WordPress site with the awesome cloud power of WordPress.com.', 'jetpack' ) . '</p>' .
+ '<p>' . __( 'On this page, you are able to view the modules available within Jetpack, learn more about them, and activate or deactivate them as needed.', 'jetpack' ) . '</p>'
+ ) );
+
+ // Screen Content
+ if ( current_user_can( 'manage_options' ) ) {
+ $current_screen->add_help_tab( array(
+ 'id' => 'modules',
+ 'title' => __( 'Modules', 'jetpack' ),
+ 'content' =>
+ '<p><strong>' . __( 'Jetpack by WordPress.com', 'jetpack' ) . '</strong></p>' .
+ '<p>' . __( 'You can activate or deactivate individual Jetpack modules to suit your needs.', 'jetpack' ) . '</p>' .
+ '<ol>' .
+ '<li>' . __( 'Find the component you want to manage', 'jetpack' ) . '</li>' .
+ '<li>' . __( 'Click on Learn More', 'jetpack' ) . '</li>' .
+ '<li>' . __( 'An Activate or Deactivate button will appear', 'jetpack' ) . '</li>' .
+ '<li>' . __( 'If additional settings are available, a link to them will appear', 'jetpack' ) . '</li>' .
+ '</ol>'
+ ) );
+ }
+
+ // 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="' . Jetpack::admin_url( array( 'page' => 'jetpack-debugger' ) ) .'">' . __( 'Jetpack Debugging Center', 'jetpack' ) . '</a></p>'
+
+ );
+ }
+
+ function admin_menu_css() { ?>
+ <style type="text/css" id="jetpack-menu-css">
+ #toplevel_page_jetpack .wp-menu-image {
+ background: url( <?php echo plugins_url( basename( dirname( __FILE__ ) ) . '/_inc/images/menuicon-sprite.png' ) ?> ) 0 90% no-repeat;
+ }
+ /* Retina Jetpack Menu Icon */
+ @media only screen and (-moz-min-device-pixel-ratio: 1.5), only screen and (-o-min-device-pixel-ratio: 3/2), only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min-device-pixel-ratio: 1.5) {
+ #toplevel_page_jetpack .wp-menu-image {
+ background: url( <?php echo plugins_url( basename( dirname( __FILE__ ) ) . '/_inc/images/menuicon-sprite-2x.png' ) ?> ) 0 90% no-repeat;
+ background-size:30px 64px;
+ }
+ }
+ #toplevel_page_jetpack.current .wp-menu-image,
+ #toplevel_page_jetpack.wp-has-current-submenu .wp-menu-image,
+ #toplevel_page_jetpack:hover .wp-menu-image {
+ background-position: top left;
+ }
+ </style><?php
+ }
+
+ function admin_menu_order() {
+ return true;
+ }
+
+ function jetpack_menu_order( $menu_order ) {
+ $jp_menu_order = array();
+
+ foreach ( $menu_order as $index => $item ) {
+ if ( $item != 'jetpack' )
+ $jp_menu_order[] = $item;
+
+ if ( $index == 0 )
+ $jp_menu_order[] = 'jetpack';
+ }
+
+ return $jp_menu_order;
+ }
+
+ function admin_head() {
+ if ( isset( $_GET['configure'] ) && Jetpack::is_module( $_GET['configure'] ) && current_user_can( 'manage_options' ) )
+ do_action( 'jetpack_module_configuration_head_' . $_GET['configure'] );
+ }
+
+ function admin_styles() {
+ global $wp_styles;
+ wp_enqueue_style( 'jetpack', plugins_url( basename( dirname( __FILE__ ) ) . '/_inc/jetpack.css' ), false, JETPACK__VERSION . '-20121016' );
+ $wp_styles->add_data( 'jetpack', 'rtl', true );
+ }
+
+ function admin_scripts() {
+ wp_enqueue_script( 'jetpack-js', plugins_url( basename( dirname( __FILE__ ) ) ) . '/_inc/jetpack.js', array( 'jquery' ), JETPACK__VERSION . '-20121111' );
+ wp_localize_script( 'jetpack-js', 'jetpackL10n', array(
+ 'ays_disconnect' => "This will deactivate all Jetpack modules.\nAre you sure you want to disconnect?",
+ 'ays_unlink' => "This will prevent user-specific modules such as Publicize, Notifications and Post By Email from working.\nAre you sure you want to unlink?",
+ 'ays_dismiss' => "This will deactivate Jetpack.\nAre you sure you want to deactivate Jetpack?",
+ ) );
+ add_action( 'admin_footer', array( $this, 'do_stats' ) );
+ }
+
+ function enqueue_retina_scripts() {
+ wp_enqueue_style( 'jetpack-retina', plugins_url( basename( dirname( __FILE__ ) ) . '/_inc/jetpack-retina.css' ), false, JETPACK__VERSION . '-20120730' );
+ }
+
+ function plugin_action_links( $actions ) {
+ return array_merge(
+ array( 'settings' => sprintf( '<a href="%s">%s</a>', Jetpack::admin_url(), __( 'Settings', 'jetpack' ) ) ),
+ $actions
+ );
+ return $actions;
+ }
+
+ function admin_connect_notice() {
+ // Don't show the connect notice on the jetpack settings page. @todo: must be a better way?
+ if ( false !== strpos( $_SERVER['QUERY_STRING'], 'page=jetpack' ) )
+ return;
+
+ if ( !current_user_can( 'manage_options' ) )
+ return;
+ ?>
+
+ <div id="message" class="updated jetpack-message jp-connect">
+ <div id="jp-dismiss" class="jetpack-close-button-container">
+ <a class="jetpack-close-button" href="?page=jetpack&jetpack-notice=dismiss" title="<?php _e( 'Dismiss this notice and deactivate Jetpack.', 'jetpack' ); ?>"><?php _e( 'Dismiss this notice and deactivate Jetpack.', 'jetpack' ); ?></a>
+ </div>
+ <div class="jetpack-wrap-container">
+ <div class="jetpack-text-container">
+ <h4>
+ <?php if ( 1 == Jetpack::get_option( 'activated' ) ) : ?>
+ <p><?php _e( '<strong>Your Jetpack is almost ready</strong> &#8211; A connection to WordPress.com is needed to enable features like Stats, Contact Forms, and Subscriptions. Connect now to get fueled up!', 'jetpack' ); ?></p>
+ <?php else : ?>
+ <p><?php _e( '<strong>Jetpack is installed</strong> and ready to bring awesome, WordPress.com cloud-powered features to your site.', 'jetpack' ) ?></p>
+ <?php endif; ?>
+ </h4>
+ </div>
+ <div class="jetpack-install-container">
+ <?php if ( 1 == Jetpack::get_option( 'activated' ) ) : ?>
+ <p class="submit"><a href="<?php echo $this->build_connect_url() ?>" class="button-connector" id="wpcom-connect"><?php _e( 'Connect to WordPress.com', 'jetpack' ); ?></a></p>
+ <?php else : ?>
+ <p class="submit"><a href="<?php echo Jetpack::admin_url() ?>" class="button-connector" id="wpcom-connect"><?php _e( 'Learn More', 'jetpack' ); ?></a></p>
+ <?php endif; ?>
+ </div>
+ </div>
+ </div>
+
+ <?php
+ }
+
+ function network_connect_notice() {
+ ?>
+ <div id="message" class="updated jetpack-message">
+ <div class="squeezer">
+ <h4><?php _e( '<strong>Jetpack is activated!</strong> Each site on your network must be connected individually by an admin on that site.', 'jetpack' ) ?></h4>
+ </div>
+ </div>
+ <?php
+ }
+
+ public static function jetpack_comment_notice() {
+ if ( in_array( 'comments', Jetpack::get_active_modules() ) ) {
+ return '';
+ }
+
+ $jetpack_old_version = explode( ':', Jetpack::get_option( 'old_version' ) );
+ $jetpack_new_version = explode( ':', Jetpack::get_option( 'version' ) );
+
+ if ( $jetpack_old_version ) {
+ if ( version_compare( $jetpack_old_version[0], '1.4', '>=' ) ) {
+ return '';
+ }
+ }
+
+ if ( $jetpack_new_version ) {
+ if ( version_compare( $jetpack_new_version[0], '1.4-something', '<' ) ) {
+ return '';
+ }
+ }
+
+ return '<br /><br />' . sprintf(
+ __( 'Jetpack now includes Jetpack Comments, which enables your visitors to use their WordPress.com, Twitter, or Facebook accounts when commenting on your site. To activate Jetpack Comments, <a href="%s">%s</a>.', 'jetpack' ),
+ wp_nonce_url(
+ Jetpack::admin_url( array(
+ 'page' => 'jetpack',
+ 'action' => 'activate',
+ 'module' => 'comments',
+ ) ),
+ "jetpack_activate-comments"
+ ),
+ __( 'click here', 'jetpack' )
+ );
+ }
+
+ /*
+ * Registration flow:
+ * 1 - ::admin_page_load() action=register
+ * 2 - ::try_registration()
+ * 3 - ::register()
+ * - Creates jetpack_register option containing two secrets and a timestamp
+ * - Calls https://jetpack.wordpress.com/jetpack.register/1/ with
+ * siteurl, home, gmt_offset, timezone_string, site_name, secret_1, secret_2, site_lang, timeout, stats_id
+ * - That request to jetpack.wordpress.com does not immediately respond. It first makes a request BACK to this site's
+ * xmlrpc.php?for=jetpack: RPC method: jetpack.verifyRegistration, Parameters: secret_1
+ * - The XML-RPC request verifies secret_1, deletes both secrets and responds with: secret_2
+ * - https://jetpack.wordpress.com/jetpack.register/1/ verifies that XML-RPC response (secret_2) then finally responds itself with
+ * jetpack_id, jetpack_secret, jetpack_public
+ * - ::register() then stores jetpack_options: id => jetpack_id, blog_token => jetpack_secret
+ * 4 - redirect to https://jetpack.wordpress.com/jetpack.authorize/1/
+ * 5 - user logs in with WP.com account
+ * 6 - redirect to this site's wp-admin/index.php?page=jetpack&action=authorize with
+ * code <-- OAuth2 style authorization code
+ * 7 - ::admin_page_load() action=authorize
+ * 8 - Jetpack_Client_Server::authorize()
+ * 9 - Jetpack_Client_Server::get_token()
+ * 10- GET https://jetpack.wordpress.com/jetpack.token/1/ with
+ * client_id, client_secret, grant_type, code, redirect_uri:action=authorize, state, scope, user_email, user_login
+ * 11- which responds with
+ * access_token, token_type, scope
+ * 12- Jetpack_Client_Server::authorize() stores jetpack_options: user_token => access_token.$user_id
+ * 13- Jetpack::activate_default_modules()
+ * Deactivates deprecated plugins
+ * Activates all default modules
+ * Catches errors: redirects to wp-admin/index.php?page=jetpack state:error=something
+ * 14- redirect to this site's wp-admin/index.php?page=jetpack with state:message=authorized
+ * Done!
+ */
+
+ /**
+ * Handles the page load events for the Jetpack admin page
+ */
+ function admin_page_load() {
+ $error = false;
+
+ if ( !empty( $_GET['jetpack_restate'] ) ) {
+ // Should only be used in intermediate redirects to preserve state across redirects
+ Jetpack::restate();
+ }
+
+ 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 );
+ if ( isset( $_GET['notes_iframe'] ) )
+ $connect_url .= '&notes_iframe';
+ wp_redirect( $connect_url );
+ exit;
+ } else {
+ Jetpack::state( 'message', 'already_authorized' );
+ wp_safe_redirect( Jetpack::admin_url() );
+ exit;
+ }
+ }
+
+ if ( isset( $_GET['action'] ) ) {
+ switch ( $_GET['action'] ) {
+ case 'authorize' :
+ if ( Jetpack::is_active() && Jetpack::is_user_connected() ) {
+ Jetpack::state( 'message', 'already_authorized' );
+ wp_safe_redirect( Jetpack::admin_url() );
+ exit;
+ }
+ $client_server = new Jetpack_Client_Server;
+ $client_server->authorize();
+ exit;
+ case 'register' :
+ check_admin_referer( 'jetpack-register' );
+ $registered = Jetpack::try_registration();
+ if ( is_wp_error( $registered ) ) {
+ $error = $registered->get_error_code();
+ Jetpack::state( 'error_description', $registered->get_error_message() );
+ break;
+ }
+
+ wp_redirect( $this->build_connect_url( true ) );
+ exit;
+ case 'activate' :
+ if ( ! current_user_can( 'activate_plugins' ) ) {
+ $error = 'cheatin';
+ break;
+ }
+
+ $module = stripslashes( $_GET['module'] );
+ check_admin_referer( "jetpack_activate-$module" );
+ Jetpack::activate_module( $module );
+ // The following two lines will rarely happen, as Jetpack::activate_module normally exits at the end.
+ wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) );
+ exit;
+ case 'activate_default_modules' :
+ check_admin_referer( 'activate_default_modules' );
+ Jetpack::restate();
+ $min_version = isset( $_GET['min_version'] ) ? $_GET['min_version'] : false;
+ $max_version = isset( $_GET['max_version'] ) ? $_GET['max_version'] : false;
+ $other_modules = isset( $_GET['other_modules'] ) && is_array( $_GET['other_modules'] ) ? $_GET['other_modules'] : array();
+ Jetpack::activate_default_modules( $min_version, $max_version, $other_modules );
+ wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) );
+ exit;
+ case 'disconnect' :
+ check_admin_referer( 'jetpack-disconnect' );
+ Jetpack::disconnect();
+ wp_safe_redirect( Jetpack::admin_url() );
+ exit;
+ case 'reconnect' :
+ if ( ! current_user_can( 'manage_options' ) ) {
+ $error = 'cheatin';
+ break;
+ }
+
+ check_admin_referer( 'jetpack-reconnect' );
+ $this->disconnect();
+ wp_redirect( $this->build_connect_url( true ) );
+ exit;
+ case 'deactivate' :
+ if ( ! current_user_can( 'activate_plugins' ) ) {
+ $error = 'cheatin';
+ break;
+ }
+
+ $modules = stripslashes( $_GET['module'] );
+ check_admin_referer( "jetpack_deactivate-$modules" );
+ foreach ( explode( ',', $modules ) as $module ) {
+ Jetpack::deactivate_module( $module );
+ Jetpack::state( 'message', 'module_deactivated' );
+ }
+ Jetpack::state( 'module', $modules );
+ wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) );
+ exit;
+ case 'unlink' :
+ check_admin_referer( 'jetpack-unlink' );
+ $this->unlink_user();
+ Jetpack::state( 'message', 'unlinked' );
+ wp_safe_redirect( Jetpack::admin_url() );
+ exit;
+ }
+ }
+
+ if ( !$error = $error ? $error : Jetpack::state( 'error' ) ) {
+ $this->activate_new_modules();
+ }
+
+ switch ( $error ) {
+ case 'cheatin' :
+ $this->error = __( 'Cheatin&#8217; uh?', 'jetpack' );
+ break;
+ case 'access_denied' :
+ $this->error = __( 'You need to authorize the Jetpack connection between your site and WordPress.com to enable the awesome features.', 'jetpack' );
+ break;
+ case 'wrong_state' :
+ $this->error = __( "Don&#8217;t cross the streams! You need to stay logged in to your WordPress blog while you authorize Jetpack.", 'jetpack' );
+ break;
+ case 'invalid_client' :
+ // @todo re-register instead of deactivate/reactivate
+ $this->error = __( 'Return to sender. Whoops! It looks like you got the wrong Jetpack in the mail; deactivate then reactivate the Jetpack plugin to get a new one.', 'jetpack' );
+ break;
+ case 'invalid_grant' :
+ $this->error = __( "Wrong size. Hm&#8230; it seems your Jetpack doesn&#8217;t quite fit. Have you lost weight? Click &#8220;Connect to WordPress.com&#8221; again to get your Jetpack adjusted.", 'jetpack' );
+ break;
+ case 'site_inaccessible' :
+ case 'site_requires_authorization' :
+ $this->error = sprintf( __( 'Your website needs to be publicly accessible to use Jetpack: %s', 'jetpack' ), "<code>$error</code>" );
+ break;
+ case 'module_activation_failed' :
+ $module = Jetpack::state( 'module' );
+ if ( !empty( $module ) && $mod = Jetpack::get_module( $module ) ) {
+ $this->error = sprintf( __( '%s could not be activated because it triggered a <strong>fatal error</strong>. Perhaps there is a conflict with another plugin you have installed?', 'jetpack' ), $mod['name'] );
+ if ( isset( $this->plugins_to_deactivate[$module] ) ) {
+ $this->error .= ' ' . sprintf( __( 'Do you still have the %s plugin installed?', 'jetpack' ), $this->plugins_to_deactivate[$module][1] );
+ }
+ } else {
+ $this->error = __( 'Module could not be activated because it triggered a <strong>fatal error</strong>. Perhaps there is a conflict with another plugin you have installed?', 'jetpack' );
+ }
+ if ( $php_errors = Jetpack::state( 'php_errors' ) ) {
+ $this->error .= "<br />\n";
+ $this->error .= $php_errors;
+ }
+ break;
+ case 'not_public' :
+ $this->error = __( "<strong>Your Jetpack has a glitch.</strong> Connecting this site with WordPress.com is not possible. This usually means your site is not publicly accessible (localhost).", 'jetpack' );
+ break;
+ case 'wpcom_408' :
+ case 'wpcom_5??' :
+ case 'wpcom_bad_response' :
+ case 'wpcom_outage' :
+ $this->error = __( 'WordPress.com is currently having problems and is unable to fuel up your Jetpack. Please try again later.', 'jetpack' );
+ break;
+ case 'register_http_request_failed' :
+ case 'token_http_request_failed' :
+ $this->error = sprintf( __( 'Jetpack could not contact WordPress.com: %s. This usually means something is incorrectly configured on your web host.', 'jetpack' ), "<code>$error</code>" );
+ break;
+ default :
+ if ( empty( $error ) ) {
+ break;
+ }
+ $error = trim( substr( strip_tags( $error ), 0, 20 ) );
+ // no break: fall through
+ case 'no_role' :
+ case 'no_cap' :
+ case 'no_code' :
+ case 'no_state' :
+ case 'invalid_state' :
+ case 'invalid_request' :
+ case 'invalid_scope' :
+ case 'unsupported_response_type' :
+ case 'invalid_token' :
+ case 'no_token' :
+ case 'missing_secrets' :
+ case 'home_missing' :
+ case 'siteurl_missing' :
+ case 'gmt_offset_missing' :
+ case 'site_name_missing' :
+ case 'secret_1_missing' :
+ case 'secret_2_missing' :
+ case 'site_lang_missing' :
+ case 'home_malformed' :
+ case 'siteurl_malformed' :
+ case 'gmt_offset_malformed' :
+ case 'timezone_string_malformed' :
+ case 'site_name_malformed' :
+ case 'secret_1_malformed' :
+ case 'secret_2_malformed' :
+ case 'site_lang_malformed' :
+ case 'secrets_mismatch' :
+ case 'verify_secret_1_missing' :
+ case 'verify_secret_1_malformed' :
+ case 'verify_secrets_missing' :
+ case 'verify_secrets_mismatch' :
+ $error = esc_html( $error );
+ $this->error = sprintf( __( "<strong>Your Jetpack has a glitch.</strong> Something went wrong that&#8217;s never supposed to happen. Guess you&#8217;re just lucky: %s", 'jetpack' ), "<code>$error</code>" );
+ if ( !Jetpack::is_active() ) {
+ $this->error .= '<br />';
+ $this->error .= sprintf( __( 'Try connecting again.', 'jetpack' ) );
+ }
+ break;
+ }
+
+ $message_code = Jetpack::state( 'message' );
+
+ $active_state = Jetpack::state( 'activated_modules' );
+ if ( !empty( $active_state ) ) {
+ $available = Jetpack::get_available_modules();
+ $active_state = explode( ',', $active_state );
+ $active_state = array_intersect( $active_state, $available );
+ if ( count( $active_state ) ) {
+ foreach ( $active_state as $mod ) {
+ $this->stat( 'module-activated', $mod );
+ }
+ } else {
+ $active_state = false;
+ }
+ }
+
+ switch ( $message_code ) {
+ case 'modules_activated' :
+ $this->message = sprintf(
+ __( 'Welcome to <strong>Jetpack %s</strong>!', 'jetpack' ),
+ JETPACK__VERSION
+ );
+
+ if ( $active_state ) {
+ $titles = array();
+ foreach ( $active_state as $mod ) {
+ if ( $mod_headers = Jetpack::get_module( $mod ) ) {
+ $titles[] = '<strong>' . preg_replace( '/\s+(?![^<>]++>)/', '&nbsp;', $mod_headers['name'] ) . '</strong>';
+ }
+ }
+ if ( $titles ) {
+ $this->message .= '<br /><br />' . wp_sprintf( __( 'The following new modules have been activated: %l.', 'jetpack' ), $titles );
+ }
+ }
+
+ if ( $reactive_state = Jetpack::state( 'reactivated_modules' ) ) {
+ $titles = array();
+ foreach ( explode( ',', $reactive_state ) as $mod ) {
+ if ( $mod_headers = Jetpack::get_module( $mod ) ) {
+ $titles[] = '<strong>' . preg_replace( '/\s+(?![^<>]++>)/', '&nbsp;', $mod_headers['name'] ) . '</strong>';
+ }
+ }
+ if ( $titles ) {
+ $this->message .= '<br /><br />' . wp_sprintf( __( 'The following modules have been updated: %l.', 'jetpack' ), $titles );
+ }
+ }
+
+ $this->message .= Jetpack::jetpack_comment_notice();
+ break;
+
+ case 'module_activated' :
+ if ( $module = Jetpack::get_module( Jetpack::state( 'module' ) ) ) {
+ $this->message = sprintf( __( '<strong>%s Activated!</strong> You can deactivate at any time by clicking Learn More and then Deactivate on the module card.', 'jetpack' ), $module['name'] );
+ $this->stat( 'module-activated', Jetpack::state( 'module' ) );
+ }
+ break;
+
+ case 'module_deactivated' :
+ $modules = Jetpack::state( 'module' );
+ if ( !$modules ) {
+ break;
+ }
+
+ $module_names = array();
+ foreach ( explode( ',', $modules ) as $module_slug ) {
+ $module = Jetpack::get_module( $module_slug );
+ if ( $module ) {
+ $module_names[] = $module['name'];
+ }
+
+ $this->stat( 'module-deactivated', $module_slug );
+ }
+
+ if ( !$module_names ) {
+ break;
+ }
+
+ $this->message = wp_sprintf(
+ _nx(
+ '<strong>%l Deactivated!</strong> You can activate it again at any time using the activate button on the module card.',
+ '<strong>%l Deactivated!</strong> You can activate them again at any time using the activate buttons on their module cards.',
+ count( $module_names ),
+ '%l = list of Jetpack module/feature names',
+ 'jetpack'
+ ),
+ $module_names
+ );
+ break;
+
+ case 'module_configured' :
+ $this->message = __( '<strong>Module settings were saved.</strong> ', 'jetpack' );
+ break;
+
+ case 'already_authorized' :
+ $this->message = __( '<strong>Your Jetpack is already connected.</strong> ', 'jetpack' );
+ break;
+
+ case 'authorized' :
+ $this->message = __( "<strong>You&#8217;re fueled up and ready to go.</strong> ", 'jetpack' );
+ $this->message .= "<br />\n";
+ $this->message .= __( 'The features below are now active. Click the learn more buttons to explore each feature.', 'jetpack' );
+ $this->message .= Jetpack::jetpack_comment_notice();
+ break;
+
+ case 'linked' :
+ $this->message = __( "<strong>You&#8217;re fueled up and ready to go.</strong> ", 'jetpack' );
+ $this->message .= Jetpack::jetpack_comment_notice();
+ break;
+
+ case 'unlinked' :
+ $user = wp_get_current_user();
+ $this->message = sprintf( __( '<strong>You have unlinked your account (%s) from WordPress.com.</strong>', 'jetpack' ), $user->user_login );
+ break;
+ }
+
+ $deactivated_plugins = Jetpack::state( 'deactivated_plugins' );
+
+ if ( !empty( $deactivated_plugins ) ) {
+ $deactivated_plugins = explode( ',', $deactivated_plugins );
+ $deactivated_titles = array();
+ foreach ( $deactivated_plugins as $deactivated_plugin ) {
+ if ( !isset( $this->plugins_to_deactivate[$deactivated_plugin] ) ) {
+ continue;
+ }
+
+ $deactivated_titles[] = '<strong>' . str_replace( ' ', '&nbsp;', $this->plugins_to_deactivate[$deactivated_plugin][1] ) . '</strong>';
+ }
+
+ if ( $deactivated_titles ) {
+ if ( $this->message ) {
+ $this->message .= "<br /><br />\n";
+ }
+
+ $this->message .= wp_sprintf( _n(
+ 'Jetpack contains the most recent version of the old %l plugin.',
+ 'Jetpack contains the most recent versions of the old %l plugins.',
+ count( $deactivated_titles ),
+ 'jetpack'
+ ), $deactivated_titles );
+
+ $this->message .= "<br />\n";
+
+ $this->message .= _n(
+ 'The old version has been deactivated and can be removed from your site.',
+ 'The old versions have been deactivated and can be removed from your site.',
+ count( $deactivated_titles ),
+ 'jetpack'
+ );
+ }
+ }
+
+ $this->privacy_checks = Jetpack::state( 'privacy_checks' );
+
+ if ( $this->message || $this->error || $this->privacy_checks ) {
+ add_action( 'jetpack_notices', array( $this, 'admin_notices' ) );
+ }
+
+ if ( isset( $_GET['configure'] ) && Jetpack::is_module( $_GET['configure'] ) && current_user_can( 'manage_options' ) ) {
+ do_action( 'jetpack_module_configuration_load_' . $_GET['configure'] );
+ }
+
+ add_filter( 'jetpack_short_module_description', 'wptexturize' );
+ }
+
+ function admin_notices() {
+
+ if ( $this->error ) {
+?>
+<div id="message" class="jetpack-message jetpack-err">
+ <div class="squeezer">
+ <h4><?php echo wp_kses( $this->error, array( 'code' => true, 'strong' => true, 'br' => true, 'b' => true ) ); ?></h4>
+<?php if ( $desc = Jetpack::state( 'error_description' ) ) : ?>
+ <p><?php echo esc_html( stripslashes( $desc ) ); ?></p>
+<?php endif; ?>
+ </div>
+</div>
+<?php
+ }
+
+ if ( $this->message ) {
+?>
+<div id="message" class="jetpack-message">
+ <div class="squeezer">
+ <h4><?php echo wp_kses( $this->message, array( 'strong' => array(), 'a' => array( 'href' => true ), 'br' => true ) ); ?></h4>
+ </div>
+</div>
+<?php
+
+ }
+
+ if ( $this->privacy_checks ) :
+ $module_names = $module_slugs = array();
+
+ $privacy_checks = explode( ',', $this->privacy_checks );
+ foreach ( $privacy_checks as $module_slug ) {
+ $module = Jetpack::get_module( $module_slug );
+ if ( !$module ) {
+ continue;
+ }
+
+ $module_slugs[] = $module_slug;
+ $module_names[] = "<strong>{$module['name']}</strong>";
+ }
+
+ $module_slugs = join( ',', $module_slugs );
+?>
+<div id="message" class="jetpack-message jetpack-err">
+ <div class="squeezer">
+ <h4><strong><?php esc_html_e( 'Is this site private?', 'jetpack' ); ?></strong></h4><br />
+ <p><?php
+ echo wp_kses( wptexturize( wp_sprintf(
+ _nx(
+ "Like your site's RSS feeds, %l allows access to your posts and other content to third parties.",
+ "Like your site's RSS feeds, %l allow access to your posts and other content to third parties.",
+ count( $privacy_checks ),
+ '%l = list of Jetpack module/feature names',
+ 'jetpack'
+ ),
+ $module_names
+ ) ), array( 'strong' => true ) );
+
+ echo "\n<br />\n";
+
+ echo wp_kses( sprintf(
+ _nx(
+ 'If your site is not publicly accessible, consider <a href="%1$s" title="%2$s">deactivating this feature</a>.',
+ 'If your site is not publicly accessible, consider <a href="%1$s" title="%2$s">deactivating these features</a>.',
+ count( $privacy_checks ),
+ '%1$s = deactivation URL, %2$s = "Deactivate {list of Jetpack module/feature names}',
+ 'jetpack'
+ ),
+ wp_nonce_url(
+ Jetpack::admin_url( array(
+ 'page' => 'jetpack',
+ 'action' => 'deactivate',
+ 'module' => urlencode( $module_slugs ),
+ ) ),
+ "jetpack_deactivate-$module_slugs"
+ ),
+ esc_attr( wp_kses( wp_sprintf( _x( 'Deactivate %l', '%l = list of Jetpack module/feature names', 'jetpack' ), $module_names ), array() ) )
+ ), array( 'a' => array( 'href' => true, 'title' => true ) ) );
+ ?></p>
+ </div>
+</div>
+<?php
+ endif;
+ }
+
+ /**
+ * Record a stat for later output. This will only currently output in the admin_footer.
+ */
+ function stat( $group, $detail ) {
+ if ( !isset( $this->stats[ $group ] ) )
+ $this->stats[ $group ] = array();
+ $this->stats[ $group ][] = $detail;
+ }
+
+ /**
+ * Load stats pixels. $group is auto-prefixed with "x_jetpack-"
+ */
+ function do_stats( $method = '' ) {
+ if ( is_array( $this->stats ) && count( $this->stats ) ) {
+ foreach ( $this->stats as $group => $stats ) {
+ if ( is_array( $stats ) && count( $stats ) ) {
+ $args = array( "x_jetpack-{$group}" => implode( ',', $stats ) );
+ if ( 'server_side' === $method ) {
+ self::do_server_side_stat( $args );
+ } else {
+ echo '<img src="' . esc_url( self::build_stats_url( $args ) ) . '" width="1" height="1" style="display:none;" />';
+ }
+ }
+ unset( $this->stats[ $group ] );
+ }
+ }
+ }
+
+ /**
+ * Runs stats code for a one-off, server-side.
+ *
+ * @param $args array|string The arguments to append to the URL. Should include `x_jetpack-{$group}={$stats}` or whatever we want to store.
+ *
+ * @return bool If it worked.
+ */
+ static function do_server_side_stat( $args ) {
+ $response = wp_remote_get( self::build_stats_url( $args ) );
+ if ( is_wp_error( $response ) )
+ return false;
+
+ if ( 200 !== wp_remote_retrieve_response_code( $response ) )
+ return false;
+
+ return true;
+ }
+
+ /**
+ * Builds the stats url.
+ *
+ * @param $args array|string The arguments to append to the URL.
+ *
+ * @return string The URL to be pinged.
+ */
+ static function build_stats_url( $args ) {
+ $defaults = array(
+ 'v' => 'wpcom2',
+ 'rand' => md5( mt_rand( 0, 999 ) . time() ),
+ );
+ $args = wp_parse_args( $args, $defaults );
+ $base_url = apply_filters( 'jetpack_stats_base_url', ( is_ssl() ? 'https' : 'http' ) . '://stats.wordpress.com/g.gif' );
+ $url = add_query_arg( $args, $base_url );
+ return $url;
+ }
+
+ function translate_current_user_to_role() {
+ foreach ( $this->capability_translations as $role => $cap ) {
+ if ( current_user_can( $role ) || current_user_can( $cap ) ) {
+ return $role;
+ }
+ }
+
+ return false;
+ }
+
+ function translate_role_to_cap( $role ) {
+ if ( !isset( $this->capability_translations[$role] ) ) {
+ return false;
+ }
+
+ return $this->capability_translations[$role];
+ }
+
+ function sign_role( $role ) {
+ if ( !$user_id = (int) get_current_user_id() ) {
+ return false;
+ }
+
+ $token = Jetpack_Data::get_access_token();
+ if ( !$token || is_wp_error( $token ) ) {
+ return false;
+ }
+
+ return $role . ':' . hash_hmac( 'md5', "{$role}|{$user_id}", $token->secret );
+ }
+
+ function build_connect_url( $raw = false, $redirect = false ) {
+ if ( !Jetpack::get_option( 'blog_token' ) ) {
+ $url = $this->nonce_url_no_esc( $this->admin_url( 'action=register' ), 'jetpack-register' );
+ } else {
+ $role = $this->translate_current_user_to_role();
+ $signed_role = $this->sign_role( $role );
+
+ $user = wp_get_current_user();
+
+ $redirect = $redirect ? esc_url_raw( $redirect ) : '';
+
+ $args = urlencode_deep( array(
+ 'response_type' => 'code',
+ 'client_id' => Jetpack::get_option( 'id' ),
+ 'redirect_uri' => add_query_arg( array(
+ 'action' => 'authorize',
+ '_wpnonce' => wp_create_nonce( "jetpack-authorize_{$role}_{$redirect}" ),
+ 'redirect' => $redirect ? urlencode( $redirect ) : false,
+ ), menu_page_url( 'jetpack', false ) ),
+ 'state' => $user->ID,
+ 'scope' => $signed_role,
+ 'user_email' => $user->user_email,
+ 'user_login' => $user->user_login,
+ 'is_active' => Jetpack::is_active(),
+ ) );
+
+ $url = add_query_arg( $args, Jetpack::api_url( 'authorize' ) );
+ }
+
+ return $raw ? $url : esc_url( $url );
+ }
+
+ function build_reconnect_url( $raw = false ) {
+ $url = wp_nonce_url( $this->admin_url( 'action=reconnect' ), 'jetpack-reconnect' );
+ return $raw ? $url : esc_url( $url );
+ }
+
+ public static function admin_url( $args = null ) {
+ $args = wp_parse_args( $args, array( 'page' => 'jetpack' ) );
+ $url = add_query_arg( $args, admin_url( 'admin.php' ) );
+ return $url;
+ }
+
+ public static function nonce_url_no_esc( $actionurl, $action = -1, $name = '_wpnonce' ) {
+ $actionurl = str_replace( '&amp;', '&', $actionurl );
+ return add_query_arg( $name, wp_create_nonce( $action ), $actionurl );
+ }
+
+ function dismiss_jetpack_notice() {
+ if ( isset( $_GET['jetpack-notice'] ) && 'dismiss' == $_GET['jetpack-notice'] && ! is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
+
+ deactivate_plugins( plugin_basename( __FILE__ ), false, false );
+
+ wp_safe_redirect( admin_url() . 'plugins.php?deactivate=true&plugin_status=all&paged=1&s=' );
+ exit;
+ }
+ }
+
+ function admin_page() {
+ global $current_user;
+
+ $role = $this->translate_current_user_to_role();
+ $is_connected = Jetpack::is_active();
+ $user_token = Jetpack_Data::get_access_token($current_user->ID);
+ $is_user_connected = $user_token && !is_wp_error($user_token);
+ $is_master_user = $current_user->ID == Jetpack::get_option( 'master_user' );
+ $module = false;
+ ?>
+ <div class="wrap" id="jetpack-settings">
+
+ <h2 style="display: none"></h2> <!-- For WP JS message relocation -->
+
+ <div id="jp-header"<?php if ( $is_connected ) : ?> class="small"<?php endif; ?>>
+ <div id="jp-clouds">
+ <?php if ( $is_connected ) : ?>
+ <div id="jp-disconnectors">
+ <?php if ( current_user_can( 'manage_options' ) ) : ?>
+ <div id="jp-disconnect" class="jp-disconnect">
+ <a href="<?php echo wp_nonce_url( Jetpack::admin_url( 'action=disconnect' ), 'jetpack-disconnect' ); ?>"><div class="deftext"><?php _e( 'Connected to WordPress.com', 'jetpack' ); ?></div><div class="hovertext"><?php _e( 'Disconnect from WordPress.com', 'jetpack' ) ?></div></a>
+ </div>
+ <?php endif; ?>
+ <?php if ( $is_user_connected && !$is_master_user ) : ?>
+ <div id="jp-unlink" class="jp-disconnect">
+ <a href="<?php echo wp_nonce_url( Jetpack::admin_url( 'action=unlink' ), 'jetpack-unlink' ); ?>"><div class="deftext"><?php _e( 'User linked to WordPress.com', 'jetpack' ); ?></div><div class="hovertext"><?php _e( 'Unlink user from WordPress.com', 'jetpack' ) ?></div></a>
+ </div>
+ <?php endif; ?>
+ </div>
+ <?php endif; ?>
+ <h3><?php _e( 'Jetpack by WordPress.com', 'jetpack' ) ?></h3>
+ <?php if ( !$is_connected ) : ?>
+ <div id="jp-notice">
+ <p><?php _e( 'Jetpack supercharges your self-hosted WordPress site with the awesome cloud power of WordPress.com.', 'jetpack' ); ?></p>
+ </div>
+ <?php endif; ?>
+ </div>
+ </div>
+
+ <?php if ( isset( $_GET['jetpack-notice'] ) && 'dismiss' == $_GET['jetpack-notice'] ) : ?>
+ <div id="message" class="error">
+ <p><?php _e( 'Jetpack is network activated and notices can not be dismissed.', 'jetpack' ); ?></p>
+ </div>
+ <?php endif; ?>
+
+ <?php do_action( 'jetpack_notices' ) ?>
+
+ <?php
+ // If the connection has not been made then show the marketing text.
+ if ( ! Jetpack::is_development_mode() ) :
+ ?>
+ <?php if ( ! $is_connected ) : ?>
+
+ <div id="message" class="updated jetpack-message jp-connect">
+ <div id="jp-dismiss" class="jetpack-close-button-container">
+ <a class="jetpack-close-button" href="?page=jetpack&jetpack-notice=dismiss" title="<?php _e( 'Dismiss this notice.', 'jetpack' ); ?>"><?php _e( 'Dismiss this notice.', 'jetpack' ); ?></a>
+ </div>
+ <div class="jetpack-wrap-container">
+ <div class="jetpack-text-container">
+ <h4>
+ <p><?php _e( "To enable all of the Jetpack features you&#8217;ll need to connect your website to WordPress.com using the button to the right. Once you&#8217;ve made the connection you&#8217;ll activate all the delightful features below.", 'jetpack' ) ?></p>
+ </h4>
+ </div>
+ <div class="jetpack-install-container">
+ <p class="submit"><a href="<?php echo $this->build_connect_url() ?>" class="button-connector" id="wpcom-connect"><?php _e( 'Connect to WordPress.com', 'jetpack' ); ?></a></p>
+ </div>
+ </div>
+ </div>
+
+ <?php elseif ( ! $is_user_connected ) : ?>
+
+ <div id="message" class="updated jetpack-message jp-connect">
+ <div class="jetpack-wrap-container">
+ <div class="jetpack-text-container">
+ <h4>
+ <p><?php _e( "To enable all of the Jetpack features you&#8217;ll need to link your account here to your WordPress.com account using the button to the right.", 'jetpack' ) ?></p>
+ </h4>
+ </div>
+ <div class="jetpack-install-container">
+ <p class="submit"><a href="<?php echo $this->build_connect_url() ?>" class="button-connector" id="wpcom-connect"><?php _e( 'Link account with WordPress.com', 'jetpack' ); ?></a></p>
+ </div>
+ </div>
+ </div>
+
+ <?php else /* blog and user are connected */ : ?>
+ <?php /* TODO: if not master user, show user disconnect button? */ ?>
+ <?php endif; ?>
+ <?php endif; // ! Jetpack::is_development_mode() ?>
+
+ <?php
+ if ( isset( $_GET['configure'] ) && Jetpack::is_module( $_GET['configure'] ) && current_user_can( 'manage_options' ) ) {
+ $this->admin_screen_configure_module( $_GET['configure'] );
+ } else {
+ $this->admin_screen_list_modules();
+ }
+ ?>
+
+ <div id="survey" class="jp-survey">
+ <div class="jp-survey-container">
+ <div class="jp-survey-text">
+ <h4><?php _e( 'Have feedback on Jetpack?', 'jetpack' ); ?></h4>
+ <br />
+ <?php _e( 'Answer a short survey to let us know how we&#8217;re doing and what to add in the future.', 'jetpack' ); ?>
+ </div>
+ <div class="jp-survey-button-container">
+ <p class="submit"><?php printf( '<a id="jp-survey-button" class="button-primary" target="_blank" href="%1$s">%2$s</a>', 'http://jetpack.me/survey/?rel=' . JETPACK__VERSION, __( 'Take Survey', 'jetpack' ) ); ?></p>
+ </div>
+ </div>
+ </div>
+
+ <?php if ( $is_connected && $this->current_user_is_connection_owner() ) : ?>
+ <p id="news-sub"><?php _e( 'Checking email updates status&hellip;', 'jetpack' ); ?></p>
+ <script type="text/javascript">
+ jQuery(document).ready(function($){
+ $.get( ajaxurl, { action: 'jetpack-check-news-subscription', rand: jQuery.now().toString() + Math.random().toString() }, function( data ) {
+ if ( 'subscribed' == data ) {
+ $( '#news-sub' ).html( '<?php printf(
+ esc_js( _x( 'You are currently subscribed to email updates. %s', '%s = Unsubscribe link', 'jetpack' ) ),
+ '<a href="#" class="jp-news-link button">' . esc_js( __( 'Unsubscribe', 'jetpack' ) ) . '</a>'
+ ); ?>' );
+ } else {
+ $( '#news-sub' ).html( '<?php printf(
+ esc_js( _x( 'Want to receive updates about Jetpack by email? %s', '%s = Subscribe link', 'jetpack' ) ),
+ '<a href="#" class="jp-news-link button-primary">' . esc_js( __( 'Subscribe', 'jetpack' ) ) . '</a>'
+ ); ?>' );
+ }
+ $( '.jp-news-link' ).click( function() {
+ $( '#news-sub' ).append( ' <img src="<?php echo esc_js( esc_url( admin_url( 'images/loading.gif' ) ) ); ?>" align="absmiddle" id="jp-news-loading" />' );
+ $.get( ajaxurl, { action: 'jetpack-subscribe-to-news', rand: jQuery.now().toString() + Math.random().toString() }, function( data ) {
+ if ( 'subscribed' == data ) {
+ $( '#news-sub' ).text( '<?php echo esc_js( __( 'You have been subscribed to receive email updates.', 'jetpack' ) ); ?>' );
+ } else {
+ $( '#news-sub' ).text( '<?php echo esc_js( __( 'You will no longer receive email updates about Jetpack.', 'jetpack' ) ); ?>' );
+ }
+ $( '#jp-news-loading' ).remove();
+ } );
+ return false;
+ } );
+ } );
+ } );
+ </script>
+ <?php endif; ?>
+
+ <div id="jp-footer">
+ <p class="automattic"><?php _e( 'An <span>Automattic</span> Airline', 'jetpack' ) ?></p>
+ <p class="small">
+ <a href="http://jetpack.me/" target="_blank">Jetpack <?php echo esc_html( JETPACK__VERSION ); ?></a> |
+ <a href="http://automattic.com/privacy/" target="_blank"><?php _e( 'Privacy Policy', 'jetpack' ); ?></a> |
+ <a href="http://wordpress.com/tos/" target="_blank"><?php _e( 'Terms of Service', 'jetpack' ); ?></a> |
+<?php if ( current_user_can( 'manage_options' ) ) : ?>
+ <a href="<?php echo Jetpack::admin_url( array( 'page' => 'jetpack-debugger' ) ); ?>"><?php _e( 'Debug', 'jetpack' ); ?></a> |
+<?php endif; ?>
+ <a href="http://jetpack.me/support/" target="_blank"><?php _e( 'Support', 'jetpack' ); ?></a>
+ </p>
+ </div>
+
+ <div id="jetpack-configuration" style="display:none;">
+ <p><img width="16" src="<?php echo esc_url( plugins_url( '_inc/images/wpspin_light-2x.gif', __FILE__ ) ); ?>" alt="Loading ..." /></p>
+ </div>
+ </div>
+ <?php
+ }
+/*
+ function admin_page_modules() {
+ global $current_user;
+
+ $role = $this->translate_current_user_to_role();
+ $is_connected = Jetpack::is_active();
+ $user_token = Jetpack_Data::get_access_token($current_user->ID);
+ $is_user_connected = $user_token && !is_wp_error($user_token);
+ $is_master_user = $current_user->ID == Jetpack::get_option( 'master_user' );
+ $module = false;
+ ?>
+ <div class="wrap" id="jetpack-settings">
+
+ <h2 style="display: none"></h2> <!-- For WP JS message relocation -->
+
+ <div id="jp-header"<?php if ( $is_connected ) : ?> class="small"<?php endif; ?>>
+ <div id="jp-clouds">
+ <?php if ( $is_connected ) : ?>
+ <div id="jp-disconnectors">
+ <?php if ( current_user_can( 'manage_options' ) ) : ?>
+ <div id="jp-disconnect" class="jp-disconnect">
+ <a href="<?php echo wp_nonce_url( Jetpack::admin_url( 'action=disconnect' ), 'jetpack-disconnect' ); ?>"><div class="deftext"><?php _e( 'Connected to WordPress.com', 'jetpack' ); ?></div><div class="hovertext"><?php _e( 'Disconnect from WordPress.com', 'jetpack' ) ?></div></a>
+ </div>
+ <?php endif; ?>
+ <?php if ( $is_user_connected && !$is_master_user ) : ?>
+ <div id="jp-unlink" class="jp-disconnect">
+ <a href="<?php echo wp_nonce_url( Jetpack::admin_url( 'action=unlink' ), 'jetpack-unlink' ); ?>"><div class="deftext"><?php _e( 'User linked to WordPress.com', 'jetpack' ); ?></div><div class="hovertext"><?php _e( 'Unlink user from WordPress.com', 'jetpack' ) ?></div></a>
+ </div>
+ <?php endif; ?>
+ </div>
+ <?php endif; ?>
+ <h3><?php _e( 'Jetpack by WordPress.com', 'jetpack' ) ?></h3>
+ <?php if ( !$is_connected ) : ?>
+ <div id="jp-notice">
+ <p><?php _e( 'Jetpack supercharges your self-hosted WordPress site with the awesome cloud power of WordPress.com.', 'jetpack' ); ?></p>
+ </div>
+ <?php endif; ?>
+ </div>
+ </div>
+
+ <?php if ( isset( $_GET['jetpack-notice'] ) && 'dismiss' == $_GET['jetpack-notice'] ) : ?>
+ <div id="message" class="error">
+ <p><?php _e( 'Jetpack is network activated and notices can not be dismissed.', 'jetpack' ); ?></p>
+ </div>
+ <?php endif; ?>
+
+ <?php do_action( 'jetpack_notices' ) ?>
+
+ <?php
+ // If the connection has not been made then show the marketing text.
+ if ( ! Jetpack::is_development_mode() ) :
+ ?>
+ <?php if ( ! $is_connected ) : ?>
+
+ <div id="message" class="updated jetpack-message jp-connect">
+ <div id="jp-dismiss" class="jetpack-close-button-container">
+ <a class="jetpack-close-button" href="?page=jetpack&jetpack-notice=dismiss" title="<?php _e( 'Dismiss this notice.', 'jetpack' ); ?>"><?php _e( 'Dismiss this notice.', 'jetpack' ); ?></a>
+ </div>
+ <div class="jetpack-wrap-container">
+ <div class="jetpack-text-container">
+ <h4>
+ <p><?php _e( "To enable all of the Jetpack features you&#8217;ll need to connect your website to WordPress.com using the button to the right. Once you&#8217;ve made the connection you&#8217;ll activate all the delightful features below.", 'jetpack' ) ?></p>
+ </h4>
+ </div>
+ <div class="jetpack-install-container">
+ <p class="submit"><a href="<?php echo $this->build_connect_url() ?>" class="button-connector" id="wpcom-connect"><?php _e( 'Connect to WordPress.com', 'jetpack' ); ?></a></p>
+ </div>
+ </div>
+ </div>
+
+ <?php elseif ( ! $is_user_connected ) : ?>
+
+ <div id="message" class="updated jetpack-message jp-connect">
+ <div class="jetpack-wrap-container">
+ <div class="jetpack-text-container">
+ <h4>
+ <p><?php _e( "To enable all of the Jetpack features you&#8217;ll need to link your account here to your WordPress.com account using the button to the right.", 'jetpack' ) ?></p>
+ </h4>
+ </div>
+ <div class="jetpack-install-container">
+ <p class="submit"><a href="<?php echo $this->build_connect_url() ?>" class="button-connector" id="wpcom-connect"><?php _e( 'Link account with WordPress.com', 'jetpack' ); ?></a></p>
+ </div>
+ </div>
+ </div>
+
+ <?php else: // blog and user are connected ?>
+ <?php // TODO: if not master user, show user disconnect button? ?>
+ <?php endif; ?>
+ <?php endif; // ! Jetpack::is_development_mode() ?>
+
+ <?php
+ if ( isset( $_GET['configure'] ) && Jetpack::is_module( $_GET['configure'] ) && current_user_can( 'manage_options' ) ) {
+ $this->admin_screen_configure_module( $_GET['configure'] );
+ } else {
+ $this->admin_screen_list_modules();
+ }
+ ?>
+
+ </div>
+ <?php
+ }
+/**/
+ function debugger_page() {
+ nocache_headers();
+ if ( !current_user_can( 'manage_options' ) ) {
+ die( '-1' );
+ }
+ jetpack_debug_display_handler();
+ exit;
+ }
+
+ function admin_screen_configure_module( $module_id ) {
+ if ( !in_array( $module_id, Jetpack::get_active_modules() ) || !current_user_can( 'manage_options' ) )
+ return false; ?>
+
+ <div id="jp-settings-screen" style="position: relative">
+ <h3>
+ <?php
+ $module = Jetpack::get_module( $module_id );
+ echo '<a href="' . menu_page_url( 'jetpack', false ) . '">' . __( 'Jetpack by WordPress.com', 'jetpack' ) . '</a> &rarr; ';
+ printf( __( 'Configure %s', 'jetpack' ), $module['name'] );
+ ?>
+ </h3>
+
+ <?php do_action( 'jetpack_module_configuration_screen_' . $module_id ); ?>
+ </div><?php
+ }
+
+ public static function sort_modules( $a, $b ) {
+ if ( $a['sort'] == $b['sort'] )
+ return 0;
+
+ return ( $a['sort'] < $b['sort'] ) ? -1 : 1;
+ }
+
+ function admin_screen_list_modules() {
+ require_once dirname( __FILE__ ) . '/modules/module-info.php';
+ $jetpack_connected = true;
+ if ( !Jetpack::is_active() )
+ $jetpack_connected = false;
+
+ ?>
+ <div class="module-container">
+ <?php
+
+ $avail_raw = Jetpack::get_available_modules();
+ $available = array();
+ $active = Jetpack::get_active_modules();
+ $counter = 0;
+
+ foreach ( (array) $avail_raw as $module ) {
+ if ( $plugin = Jetpack::get_module( $module ) ) {
+ $plugin['module'] = $module;
+ $available[] = $plugin;
+ }
+ }
+ unset( $avail_raw );
+ usort( $available, array( 'Jetpack', 'sort_modules' ) );
+ $jetpack_version = Jetpack::get_option( 'version' );
+ if ( $jetpack_version ) {
+ list( $jetpack_version, $jetpack_version_time ) = explode( ':', $jetpack_version );
+ } else {
+ $jetpack_version = 0;
+ $jetpack_version_time = 0;
+ }
+
+ $jetpack_old_version = Jetpack::get_option( 'old_version' );
+ if ( $jetpack_old_version ) {
+ list( $jetpack_old_version ) = explode( ':', $jetpack_old_version );
+ } else {
+ $jetpack_old_version = 0;
+ }
+ $now = time();
+
+ foreach ( (array) $available as $module_data ) {
+ $module = $module_data['module'];
+ $activated = in_array( $module, $active );
+ if ( $activated ) {
+ $css = 'active';
+ $toggle = __( 'Deactivate', 'jetpack' );
+ $toggle_url = wp_nonce_url(
+ Jetpack::admin_url( array(
+ 'page' => 'jetpack',
+ 'action' => 'deactivate',
+ 'module' => $module
+ ) ),
+ "jetpack_deactivate-$module"
+ );
+ } else {
+ $css = 'inactive';
+ $toggle = __( 'Activate', 'jetpack' );
+ $toggle_url = wp_nonce_url(
+ Jetpack::admin_url( array(
+ 'page' => 'jetpack',
+ 'action' => 'activate',
+ 'module' => $module
+ ) ),
+ "jetpack_activate-$module"
+ );
+ }
+
+ if ( $counter % 4 == 0 ) {
+ $classes = $css . ' jetpack-newline';
+ $counter = 0;
+ } else {
+ $classes = $css;
+ }
+
+ $free_text = esc_html( $module_data['free'] ? __( 'Free', 'jetpack' ) : __( 'Purchase', 'jetpack' ) );
+ $free_text = apply_filters( 'jetpack_module_free_text_' . $module, $free_text );
+ $badge_text = $free_text;
+
+ if ( ( ! $jetpack_connected && ! Jetpack::is_development_mode() ) ) {
+ $classes = 'x disabled';
+ } else if ( $jetpack_version_time + 604800 > $now ) { // 1 week
+ if ( version_compare( $module_data['introduced'], $jetpack_old_version, '>' ) ) {
+ $badge_text = esc_html__( 'New', 'jetpack' );
+ $classes .= ' jetpack-new-module';
+ } elseif ( isset( $module_data['changed'] ) && version_compare( $module_data['changed'], $jetpack_old_version, '>' ) ) {
+ $badge_text = esc_html__( 'Updated', 'jetpack' );
+ $classes .= ' jetpack-updated-module';
+ } else {
+ $badge_text = $free_text;
+ }
+ }
+
+ ?>
+ <div class="jetpack-module jetpack-<?php echo $classes; ?>" id="<?php echo $module ?>">
+ <h3><?php echo $module_data['name']; ?></h3>
+ <div class="jetpack-module-description">
+ <div class="module-image">
+ <p><span class="module-image-badge"><?php echo $badge_text; ?></span><span class="module-image-free" style="display: none"><?php echo $free_text; ?></span></p>
+ </div>
+
+ <p><?php echo apply_filters( 'jetpack_short_module_description', $module_data['description'], $module ); ?></p>
+ </div>
+
+ <div class="jetpack-module-actions">
+ <?php if ( $jetpack_connected || ( Jetpack::is_development_mode() && ! $module_data['requires_connection'] ) ) : ?>
+ <?php if ( !$activated && current_user_can( 'manage_options' ) && apply_filters( 'jetpack_can_activate_' . $module, true ) ) : ?>
+ <a href="<?php echo esc_url( $toggle_url ); ?>" class="<?php echo ( 'inactive' == $css ? ' button-primary' : ' button-secondary' ); ?>"><?php echo $toggle; ?></a>&nbsp;
+ <?php endif; ?>
+
+ <?php do_action( 'jetpack_learn_more_button_' . $module ) ?>
+
+ <?php
+ if ( current_user_can( 'manage_options' ) && apply_filters( 'jetpack_module_configurable_' . $module, false ) ) {
+ echo '<a href="' . esc_url( Jetpack::module_configuration_url( $module ) ) . '" class="jetpack-configure-button button-secondary">' . __( 'Configure', 'jetpack' ) . '</a>';
+ }
+ ?><?php if ( $activated && $module_data['deactivate'] && current_user_can( 'manage_options' ) ) : ?><a style="display: none;" href="<?php echo esc_url( $toggle_url ); ?>" class="jetpack-deactivate-button button-secondary"><?php echo $toggle; ?></a>&nbsp;<?php endif; ?>
+
+ <?php else : ?>
+ <?php do_action( 'jetpack_learn_more_button_' . $module ) ?>
+ <?php endif; ?>
+ </div>
+ </div>
+ <?php if ( 'inactive' == $css && $jetpack_connected && current_user_can( 'manage_options' ) && apply_filters( 'jetpack_can_activate_' . $module, true ) ) : ?>
+ <script type="text/javascript">
+ jQuery( '#<?php echo esc_js( $module ); ?>' ).bind( 'click', function(e){
+ if ( !jQuery(e.target).hasClass('more-info-link') )
+ document.location.href = '<?php echo str_replace( '&amp;', '&', esc_js( esc_url( $toggle_url ) ) ); ?>';
+ } );
+ </script>
+ <?php else: ?>
+ <style>
+ #<?php echo $module; ?> { cursor: default; }
+ </style>
+ <?php endif; ?>
+
+ <div id="jp-more-info-<?php echo esc_attr( $module ); ?>" style="display:none;">
+ <?php
+ if ( $jetpack_connected && has_action( 'jetpack_module_more_info_connected_' . $module ) )
+ do_action( 'jetpack_module_more_info_connected_' . $module );
+ else
+ do_action( 'jetpack_module_more_info_' . $module );
+ ?>
+ </div>
+
+ <?php
+ $counter++;
+ }
+
+ // Add in some "Coming soon..." placeholders to fill up the current row and one more
+ for ( $i = 0; $i < 4; $i++ ) { ?>
+ <div class="jetpack-module placeholder"<?php if ( $i > 8 - $counter ) echo ' style="display: none;"'; ?>>
+ <h3><?php _e( 'Coming soon&#8230;', 'jetpack' ) ?></h3>
+ </div>
+ <?php
+ }
+
+ echo '</div><!-- .module-container -->';
+ }
+
+ function check_news_subscription() {
+ if ( !$this->current_user_is_connection_owner() ) {
+ exit;
+ }
+
+ Jetpack::load_xml_rpc_client();
+ $xml = new Jetpack_IXR_Client( array(
+ 'user_id' => JETPACK_MASTER_USER,
+ ) );
+ $xml->query( 'jetpack.checkNewsSubscription' );
+ if ( $xml->isError() ) {
+ printf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() );
+ } else {
+ print_r( $xml->getResponse() );
+ }
+ exit;
+ }
+
+ function subscribe_to_news() {
+ if ( !$this->current_user_is_connection_owner() ) {
+ exit;
+ }
+
+ Jetpack::load_xml_rpc_client();
+ $xml = new Jetpack_IXR_Client( array(
+ 'user_id' => JETPACK_MASTER_USER,
+ ) );
+ $xml->query( 'jetpack.subscribeToNews' );
+ if ( $xml->isError() ) {
+ printf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() );
+ } else {
+ print_r( $xml->getResponse() );
+ }
+ exit;
+ }
+
+/* Client API */
+
+ /**
+ * Returns the requested Jetpack API URL
+ *
+ * @return string
+ */
+ public static function api_url( $relative_url ) {
+ return trailingslashit( JETPACK__API_BASE . $relative_url ) . JETPACK__API_VERSION . '/';
+ }
+
+ /**
+ * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requsets
+ */
+ public static function fix_url_for_bad_hosts( $url, &$args ) {
+ if ( 0 !== strpos( $url, 'https://' ) ) {
+ return $url;
+ }
+
+ switch ( JETPACK_CLIENT__HTTPS ) {
+ case 'ALWAYS' :
+ return $url;
+ case 'NEVER' :
+ return self::force_url_to_non_ssl( $url );
+ // default : case 'AUTO' :
+ }
+
+ $jetpack = Jetpack::init();
+
+ // Yay! Your host is good!
+ if ( self::permit_ssl() && wp_http_supports( array( 'ssl' => true ) ) ) {
+ return $url;
+ }
+
+ // Boo! Your host is bad and makes Jetpack cry!
+ return self::force_url_to_non_ssl( $url );
+ }
+
+ /**
+ * Checks to see if the URL is using SSL to connect with Jetpack
+ *
+ * @since 2.3.3
+ * @return boolean
+ */
+ public static function permit_ssl( $force_recheck = false ) {
+ // Do some fancy tests to see if ssl is being supported
+ if ( $force_recheck || false === ( $ssl = get_transient( 'jetpack_https_test' ) ) ) {
+
+ if ( 'https' !== substr( JETPACK__API_BASE, 0, 5 ) ) {
+ $ssl = 0;
+ } else {
+ switch ( JETPACK_CLIENT__HTTPS ) {
+ case 'NEVER':
+ $ssl = 0;
+ break;
+ case 'ALWAYS':
+ case 'AUTO':
+ default:
+ $ssl = 1;
+ break;
+ }
+
+ // If it's not 'NEVER', test to see
+ if ( $ssl ) {
+ $response = wp_remote_get( JETPACK__API_BASE . 'test/1/' );
+ if ( is_wp_error( $response ) || ( 'OK' !== wp_remote_retrieve_body( $response ) ) ) {
+ $ssl = 0;
+ }
+ }
+ }
+ set_transient( 'jetpack_https_test', $ssl, DAY_IN_SECONDS );
+ }
+
+ return (bool) $ssl;
+ }
+
+ /**
+ * Take any URL, and if it starts with https:// change it to http://
+ */
+ public static function force_url_to_non_ssl( $url ) {
+ return preg_replace( '#^https://#i', 'http://', $url );
+ }
+
+ /*
+ * Displays an admin_notice, alerting the user to their JETPACK_CLIENT__HTTPS constant being 'ALWAYS' but SSL isn't working.
+ */
+ public function alert_required_ssl_fail() {
+ if ( ! current_user_can( 'manage_options' ) )
+ return;
+ ?>
+
+ <div id="message" class="error jetpack-message jp-identity-crisis">
+ <div class="jetpack-wrap-container">
+ <div class="jetpack-text-container">
+ <h3><?php _e( 'Something is being cranky!', 'jetpack' ); ?></h3>
+ <p><?php _e( 'Your site is configured to only permit SSL connections to Jetpack, but SSL connections don\'t seem to be functional!', 'jetpack' ); ?></p>
+ </div>
+ </div>
+ </div>
+
+ <?php
+ }
+
+ /**
+ * Returns the Jetpack XML-RPC API
+ *
+ * @return string
+ */
+ public static function xmlrpc_api_url() {
+ $base = preg_replace( '#(https?://[^?/]+)(/?.*)?$#', '\\1', JETPACK__API_BASE );
+ return untrailingslashit( $base ) . '/xmlrpc.php';
+ }
+
+ /**
+ * @return bool|WP_Error
+ */
+ public static function register() {
+ Jetpack::update_option( 'register', wp_generate_password( 32, false ) . ':' . wp_generate_password( 32, false ) . ':' . ( time() + 600 ) );
+
+ @list( $secret_1, $secret_2, $secret_eol ) = explode( ':', Jetpack::get_option( 'register' ) );
+ if ( empty( $secret_1 ) || empty( $secret_2 ) || empty( $secret_eol ) || $secret_eol < time() )
+ return new Jetpack_Error( 'missing_secrets' );
+
+ $timeout = (int) ini_get( 'max_execution_time' );
+ if ( !$timeout )
+ $timeout = 30;
+ $timeout = intval( $timeout / 2 );
+
+ $gmt_offset = get_option( 'gmt_offset' );
+ if ( !$gmt_offset ) {
+ $gmt_offset = 0;
+ }
+
+ $stats_options = get_option( 'stats_options' );
+ $stats_id = isset($stats_options['blog_id']) ? $stats_options['blog_id'] : null;
+
+ $args = array(
+ 'method' => 'POST',
+ 'body' => array(
+ 'siteurl' => site_url(),
+ 'home' => home_url(),
+ 'gmt_offset' => $gmt_offset,
+ 'timezone_string' => (string) get_option( 'timezone_string' ),
+ 'site_name' => (string) get_option( 'blogname' ),
+ 'secret_1' => $secret_1,
+ 'secret_2' => $secret_2,
+ 'site_lang' => get_locale(),
+ 'timeout' => $timeout,
+ 'stats_id' => $stats_id,
+ ),
+ 'headers' => array(
+ 'Accept' => 'application/json',
+ ),
+ 'timeout' => $timeout,
+ );
+ $response = Jetpack_Client::_wp_remote_request( Jetpack::fix_url_for_bad_hosts( Jetpack::api_url( 'register' ), $args ), $args, true );
+
+ if ( is_wp_error( $response ) ) {
+ return new Jetpack_Error( 'register_http_request_failed', $response->get_error_message() );
+ }
+
+ $code = wp_remote_retrieve_response_code( $response );
+ $entity = wp_remote_retrieve_body( $response );
+
+ if ( $entity )
+ $json = json_decode( $entity );
+ else
+ $json = false;
+
+ $code_type = intval( $code / 100 );
+ if ( 5 == $code_type ) {
+ return new Jetpack_Error( 'wpcom_5??', sprintf( __( 'Error Details: %s', 'jetpack' ), $code ), $code );
+ } elseif ( 408 == $code ) {
+ return new Jetpack_Error( 'wpcom_408', sprintf( __( 'Error Details: %s', 'jetpack' ), $code ), $code );
+ } elseif ( !empty( $json->error ) ) {
+ $error_description = isset( $json->error_description ) ? sprintf( __( 'Error Details: %s', 'jetpack' ), (string) $json->error_description ) : '';
+ return new Jetpack_Error( (string) $json->error, $error_description, $code );
+ } elseif ( 200 != $code ) {
+ return new Jetpack_Error( 'wpcom_bad_response', sprintf( __( 'Error Details: %s', 'jetpack' ), $code ), $code );
+ }
+
+ // Jetpack ID error block
+ if ( empty( $json->jetpack_id ) ) {
+ return new Jetpack_Error( 'jetpack_id', sprintf( __( 'Error Details: Jetpack ID is empty. Do not publicly post this error message! %s', 'jetpack' ), $entity ), $entity );
+ } elseif ( ! is_scalar( $json->jetpack_id ) ) {
+ return new Jetpack_Error( 'jetpack_id', sprintf( __( 'Error Details: Jetpack ID is not a scalar. Do not publicly post this error message! %s', 'jetpack' ) , $entity ), $entity );
+ } elseif ( preg_match( '/[^0-9]/', $json->jetpack_id ) ) {
+ return new Jetpack_Error( 'jetpack_id', sprintf( __( 'Error Details: Jetpack ID begins with a numeral. Do not publicly post this error message! %s', 'jetpack' ) , $entity ), $entity);
+ }
+
+ if ( empty( $json->jetpack_secret ) || !is_string( $json->jetpack_secret ) )
+ return new Jetpack_Error( 'jetpack_secret', '', $code );
+
+ if ( isset( $json->jetpack_public ) ) {
+ $jetpack_public = (int) $json->jetpack_public;
+ } else {
+ $jetpack_public = false;
+ }
+
+ Jetpack::update_options( array(
+ 'id' => (int) $json->jetpack_id,
+ 'blog_token' => (string) $json->jetpack_secret,
+ 'public' => $jetpack_public,
+ ) );
+
+ return true;
+ }
+
+
+/* Client Server API */
+
+ /**
+ * Loads the Jetpack XML-RPC client
+ */
+ public static function load_xml_rpc_client() {
+ require_once ABSPATH . WPINC . '/class-IXR.php';
+ require_once dirname( __FILE__ ) . '/class.jetpack-ixr-client.php';
+ }
+
+ /**
+ * Authenticates XML-RPC and other requests from the Jetpack Server
+ */
+ function authenticate_jetpack( $user, $username, $password ) {
+ if ( is_a( $user, 'WP_User' ) ) {
+ return $user;
+ }
+
+ // It's not for us
+ if ( !isset( $_GET['token'] ) || empty( $_GET['signature'] ) ) {
+ return $user;
+ }
+
+ @list( $token_key, $version, $user_id ) = explode( ':', $_GET['token'] );
+ if (
+ empty( $token_key )
+ ||
+ empty( $version ) || strval( JETPACK__API_VERSION ) !== $version
+ ||
+ empty( $user_id ) || !ctype_digit( $user_id ) || !get_userdata( $user_id ) // only handle user_tokens for now, not blog_tokens
+ ) {
+ return $user;
+ }
+
+ $token = Jetpack_Data::get_access_token( $user_id );
+ if ( !$token ) {
+ return $user;
+ }
+
+ if ( 0 !== strpos( $token->secret, "$token_key." ) ) {
+ return $user;
+ }
+
+ require_once dirname( __FILE__ ) . '/class.jetpack-signature.php';
+
+ $jetpack_signature = new Jetpack_Signature( $token->secret, (int) Jetpack::get_option( 'time_diff' ) );
+ if ( isset( $_POST['_jetpack_is_multipart'] ) ) {
+ $post_data = $_POST;
+ $file_hashes = array();
+ foreach ( $post_data as $post_data_key => $post_data_value ) {
+ if ( 0 !== strpos( $post_data_key, '_jetpack_file_hmac_' ) ) {
+ continue;
+ }
+ $post_data_key = substr( $post_data_key, strlen( '_jetpack_file_hmac_' ) );
+ $file_hashes[$post_data_key] = $post_data_value;
+ }
+
+ foreach ( $file_hashes as $post_data_key => $post_data_value ) {
+ unset( $post_data["_jetpack_file_hmac_{$post_data_key}"] );
+ $post_data[$post_data_key] = $post_data_value;
+ }
+
+ ksort( $post_data );
+
+ $body = http_build_query( stripslashes_deep( $post_data ) );
+ } elseif ( is_null( $this->HTTP_RAW_POST_DATA ) ) {
+ $body = file_get_contents( 'php://input' );
+ } else {
+ $body = null;
+ }
+ $signature = $jetpack_signature->sign_current_request( array(
+ 'body' => is_null( $body ) ? $this->HTTP_RAW_POST_DATA : $body
+ ) );
+
+ if ( !$signature ) {
+ return $user;
+ } else if ( is_wp_error( $signature ) ) {
+ return $signature;
+ } else if ( $signature !== $_GET['signature'] ) {
+ return $user;
+ }
+
+ $timestamp = (int) $_GET['timestamp'];
+ $nonce = stripslashes( (string) $_GET['nonce'] );
+
+ if ( !$this->add_nonce( $timestamp, $nonce ) ) {
+ return $user;
+ }
+
+ nocache_headers();
+
+ return new WP_User( $token->external_user_id );
+ }
+
+ function add_nonce( $timestamp, $nonce ) {
+ global $wpdb;
+ static $nonces_used_this_request = array();
+
+ if ( isset( $nonces_used_this_request["$timestamp:$nonce"] ) ) {
+ return $nonces_used_this_request["$timestamp:$nonce"];
+ }
+
+ // This should always have gone through Jetpack_Signature::sign_request() first to check $timestamp an $nonce
+ $timestamp = (int) $timestamp;
+ $nonce = $wpdb->escape( $nonce );
+
+ // Raw query so we can avoid races: add_option will also update
+ $show_errors = $wpdb->show_errors( false );
+ $return = $wpdb->query( $wpdb->prepare(
+ "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s)",
+ "jetpack_nonce_{$timestamp}_{$nonce}",
+ time(),
+ 'no'
+ ) );
+ $wpdb->show_errors( $show_errors );
+
+ $nonces_used_this_request["$timestamp:$nonce"] = $return;
+
+ return $return;
+ }
+
+ /**
+ * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths since it is passed by reference to various methods.
+ * Capture it here so we can verify the signature later.
+ */
+ function xmlrpc_methods( $methods ) {
+ $this->HTTP_RAW_POST_DATA = $GLOBALS['HTTP_RAW_POST_DATA'];
+ return $methods;
+ }
+
+ function xmlrpc_options( $options ) {
+ $options['jetpack_version'] = array(
+ 'desc' => __( 'Jetpack Plugin Version' , 'jetpack'),
+ 'readonly' => true,
+ 'value' => JETPACK__VERSION,
+ );
+
+ $options['jetpack_client_id'] = array(
+ 'desc' => __( 'The Client ID/WP.com Blog ID of this site' , 'jetpack'),
+ 'readonly' => true,
+ 'value' => Jetpack::get_option( 'id' ),
+ );
+ return $options;
+ }
+
+ public static function clean_nonces( $all = false ) {
+ global $wpdb;
+
+ $sql = "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE %s";
+ $sql_args = array( like_escape( 'jetpack_nonce_' ) . '%' );
+
+ if ( true !== $all ) {
+ $sql .= ' AND CAST( `option_value` AS UNSIGNED ) < %d';
+ $sql_args[] = time() - 3600;
+ }
+
+ $sql .= ' LIMIT 100';
+
+ $sql = $wpdb->prepare( $sql, $sql_args );
+
+ for ( $i = 0; $i < 1000; $i++ ) {
+ if ( !$wpdb->query( $sql ) ) {
+ break;
+ }
+ }
+ }
+
+ /**
+ * State is passed via cookies from one request to the next, but never to subsequent requests.
+ * SET: state( $key, $value );
+ * GET: $value = state( $key );
+ *
+ * @param string $key
+ * @param string $value
+ * @param bool $restate private
+ */
+ public static function state( $key = null, $value = null, $restate = false ) {
+ static $state = array();
+ static $path, $domain;
+ if ( !isset( $path ) ) {
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
+ $admin_url = Jetpack::admin_url();
+ $bits = parse_url( $admin_url );
+
+ if ( is_array( $bits ) ) {
+ $path = ( isset( $bits['path'] ) ) ? dirname( $bits['path'] ) : null;
+ $domain = ( isset( $bits['host'] ) ) ? $bits['host'] : null;
+ } else {
+ $path = $domain = null;
+ }
+ }
+
+ // Extract state from cookies and delete cookies
+ if ( isset( $_COOKIE[ 'jetpackState' ] ) && is_array( $_COOKIE[ 'jetpackState' ] ) ) {
+ $yum = $_COOKIE[ 'jetpackState' ];
+ unset( $_COOKIE[ 'jetpackState' ] );
+ foreach ( $yum as $k => $v ) {
+ if ( strlen( $v ) )
+ $state[ $k ] = $v;
+ setcookie( "jetpackState[$k]", false, 0, $path, $domain );
+ }
+ }
+
+ if ( $restate ) {
+ foreach ( $state as $k => $v ) {
+ setcookie( "jetpackState[$k]", $v, 0, $path, $domain );
+ }
+ return;
+ }
+
+ // Get a state variable
+ if ( isset( $key ) && !isset( $value ) ) {
+ if ( array_key_exists( $key, $state ) )
+ return $state[ $key ];
+ return null;
+ }
+
+ // Set a state variable
+ if ( isset ( $key ) && isset( $value ) ) {
+ $state[ $key ] = $value;
+ setcookie( "jetpackState[$key]", $value, 0, $path, $domain );
+ }
+ }
+
+ public static function restate() {
+ Jetpack::state( null, null, true );
+ }
+
+ public static function check_privacy( $file ) {
+ static $is_site_publicly_accessible = null;
+
+ if ( is_null( $is_site_publicly_accessible ) ) {
+ $is_site_publicly_accessible = false;
+
+ Jetpack::load_xml_rpc_client();
+ $rpc = new Jetpack_IXR_Client();
+
+ $success = $rpc->query( 'jetpack.isSitePubliclyAccessible', home_url() );
+ if ( $success ) {
+ $response = $rpc->getResponse();
+ if ( $response ) {
+ $is_site_publicly_accessible = true;
+ }
+ }
+
+ Jetpack::update_option( 'public', (int) $is_site_publicly_accessible );
+ }
+
+ if ( $is_site_publicly_accessible ) {
+ return;
+ }
+
+ $module_slug = self::get_module_slug( $file );
+
+ $privacy_checks = Jetpack::state( 'privacy_checks' );
+ if ( !$privacy_checks ) {
+ $privacy_checks = $module_slug;
+ } else {
+ $privacy_checks .= ",$module_slug";
+ }
+
+ Jetpack::state( 'privacy_checks', $privacy_checks );
+ }
+
+ /**
+ * Helper method for multicall XMLRPC.
+ */
+ public static function xmlrpc_async_call() {
+ global $blog_id;
+ static $clients = array();
+
+ $client_blog_id = is_multisite() ? $blog_id : 0;
+
+ if ( !isset( $clients[$client_blog_id] ) ) {
+ Jetpack::load_xml_rpc_client();
+ $clients[$client_blog_id] = new Jetpack_IXR_ClientMulticall( array(
+ 'user_id' => JETPACK_MASTER_USER,
+ ) );
+ ignore_user_abort( true );
+ add_action( 'shutdown', array( 'Jetpack', 'xmlrpc_async_call' ) );
+ }
+
+ $args = func_get_args();
+
+ if ( !empty( $args[0] ) ) {
+ call_user_func_array( array( $clients[$client_blog_id], 'addCall' ), $args );
+ } elseif ( is_multisite() ) {
+ foreach ( $clients as $client_blog_id => $client ) {
+ if ( !$client_blog_id || empty( $client->calls ) ) {
+ continue;
+ }
+
+ $switch_success = switch_to_blog( $client_blog_id, true );
+ if ( !$switch_success ) {
+ continue;
+ }
+
+ flush();
+ $client->query();
+
+ restore_current_blog();
+ }
+ } else {
+ if ( isset( $clients[0] ) && !empty( $clients[0]->calls ) ) {
+ flush();
+ $clients[0]->query();
+ }
+ }
+ }
+
+ public static function staticize_subdomain( $url ) {
+ $host = parse_url( $url, PHP_URL_HOST );
+ if ( !preg_match( '/.?(?:wordpress|wp)\.com$/', $host ) ) {
+ return $url;
+ }
+
+ if ( is_ssl() ) {
+ return preg_replace( '|https?://[^/]++/|', 'https://s-ssl.wordpress.com/', $url );
+ }
+
+ srand( crc32( basename( $url ) ) );
+ $static_counter = rand( 0, 2 );
+ srand(); // this resets everything that relies on this, like array_rand() and shuffle()
+
+ return preg_replace( '|://[^/]+?/|', "://s$static_counter.wp.com/", $url );
+ }
+
+/* JSON API Authorization */
+
+ /**
+ * Handles the login action for Authorizing the JSON API
+ */
+ function login_form_json_api_authorization() {
+ $this->verify_json_api_authorization_request();
+
+ add_action( 'wp_login', array( &$this, 'store_json_api_authorization_token' ), 10, 2 );
+
+ add_action( 'login_message', array( &$this, 'login_message_json_api_authorization' ) );
+ add_action( 'login_form', array( &$this, 'preserve_action_in_login_form_for_json_api_authorization' ) );
+ add_filter( 'site_url', array( &$this, 'post_login_form_to_signed_url' ), 10, 3 );
+ }
+
+ // Make sure the login form is POSTed to the signed URL so we can reverify the request
+ function post_login_form_to_signed_url( $url, $path, $scheme ) {
+ if ( 'wp-login.php' !== $path || 'login_post' !== $scheme ) {
+ return $url;
+ }
+
+ return "$url?{$_SERVER['QUERY_STRING']}";
+ }
+
+ // Make sure the POSTed request is handled by the same action
+ function preserve_action_in_login_form_for_json_api_authorization() {
+ echo "<input type='hidden' name='action' value='jetpack_json_api_authorization' />\n";
+ }
+
+ // If someone logs in to approve API access, store the Access Code in usermeta
+ function store_json_api_authorization_token( $user_login, $user ) {
+ add_filter( 'login_redirect', array( &$this, 'add_token_to_login_redirect_json_api_authorization' ), 10, 3 );
+ add_filter( 'allowed_redirect_hosts', array( &$this, 'allow_wpcom_public_api_domain' ) );
+ $token = wp_generate_password( 32, false );
+ update_user_meta( $user->ID, 'jetpack_json_api_' . $this->json_api_authorization_request['client_id'], $token );
+ }
+
+ // Add public-api.wordpress.com to the safe redirect whitelist - only added when someone allows API access
+ function allow_wpcom_public_api_domain( $domains ) {
+ $domains[] = 'public-api.wordpress.com';
+ return $domains;
+ }
+
+ // Add the Access Code details to the public-api.wordpress.com redirect
+ function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) {
+ return add_query_arg( urlencode_deep( array(
+ 'jetpack-code' => get_user_meta( $user->ID, 'jetpack_json_api_' . $this->json_api_authorization_request['client_id'], true ),
+ 'jetpack-user-id' => (int) $user->ID,
+ 'jetpack-state' => $this->json_api_authorization_request['state'],
+ ) ), $redirect_to );
+ }
+
+ // Verifies the request by checking the signature
+ function verify_json_api_authorization_request() {
+ require_once dirname( __FILE__ ) . '/class.jetpack-signature.php';
+
+ $token = Jetpack_Data::get_access_token( JETPACK_MASTER_USER );
+ if ( !$token || empty( $token->secret ) ) {
+ wp_die( __( 'You must connect your Jetpack plugin to WordPress.com to use this feature.' , 'jetpack') );
+ }
+
+ $die_error = __( 'Someone may be trying to trick you into giving them access to your site. Or it could be you just encountered a bug :). Either way, please close this window.', 'jetpack' );
+
+ $jetpack_signature = new Jetpack_Signature( $token->secret, (int) Jetpack::get_option( 'time_diff' ) );
+ $signature = $jetpack_signature->sign_current_request( array( 'body' => null, 'method' => 'GET' ) );
+ if ( !$signature ) {
+ wp_die( $die_error );
+ } else if ( is_wp_error( $signature ) ) {
+ wp_die( $die_error );
+ } else if ( $signature !== $_GET['signature'] ) {
+ if ( is_ssl() ) {
+ // If we signed an HTTP request on the Jetpack Servers, but got redirected to HTTPS by the local blog, check the HTTP signature as well
+ $signature = $jetpack_signature->sign_current_request( array( 'scheme' => 'http', 'body' => null, 'method' => 'GET' ) );
+ if ( !$signature || is_wp_error( $signature ) || $signature !== $_GET['signature'] ) {
+ wp_die( $die_error );
+ }
+ } else {
+ wp_die( $die_error );
+ }
+ }
+
+ $timestamp = (int) $_GET['timestamp'];
+ $nonce = stripslashes( (string) $_GET['nonce'] );
+
+ if ( !$this->add_nonce( $timestamp, $nonce ) ) {
+ // De-nonce the nonce, at least for 5 minutes.
+ // We have to reuse this nonce at least once (used the first time when the initial request is made, used a second time when the login form is POSTed)
+ $old_nonce_time = get_option( "jetpack_nonce_{$timestamp}_{$nonce}" );
+ if ( $old_nonce_time < time() - 300 ) {
+ wp_die( __( 'The authorization process expired. Please go back and try again.' , 'jetpack') );
+ }
+ }
+
+ $data = json_decode( base64_decode( stripslashes( $_GET['data'] ) ) );
+ $data_filters = array(
+ 'state' => 'opaque',
+ 'client_id' => 'int',
+ 'client_title' => 'string',
+ 'client_image' => 'url',
+ );
+
+ foreach ( $data_filters as $key => $sanitation ) {
+ if ( !isset( $data->$key ) ) {
+ wp_die( $die_error );
+ }
+
+ switch ( $sanitation ) {
+ case 'int' :
+ $this->json_api_authorization_request[$key] = (int) $data->$key;
+ break;
+ case 'opaque' :
+ $this->json_api_authorization_request[$key] = (string) $data->$key;
+ break;
+ case 'string' :
+ $this->json_api_authorization_request[$key] = wp_kses( (string) $data->$key, array() );
+ break;
+ case 'url' :
+ $this->json_api_authorization_request[$key] = esc_url_raw( (string) $data->$key );
+ break;
+ }
+ }
+
+ if ( empty( $this->json_api_authorization_request['client_id'] ) ) {
+ wp_die( $die_error );
+ }
+ }
+
+ function login_message_json_api_authorization( $message ) {
+ return '<p class="message">' . sprintf(
+ esc_html__( '%s wants to access your site&#8217;s data. Log in to authorize that access.' , 'jetpack'),
+ '<strong>' . esc_html( $this->json_api_authorization_request['client_title'] ) . '</strong>'
+ ) . '<img src="' . esc_url( $this->json_api_authorization_request['client_image'] ) . '" /></p>';
+ }
+
+ /**
+ * Get $content_width, but with a <s>twist</s> filter.
+ */
+ public static function get_content_width() {
+ return apply_filters( 'jetpack_content_width', $GLOBALS['content_width'] );
+ }
+
+ /**
+ * Centralize the function here until it gets added to core.
+ *
+ * @param int|string|object $id_or_email A user ID, email address, or comment object
+ * @param int $size Size of the avatar image
+ * @param string $default URL to a default image to use if no avatar is available
+ * @param bool $force_display Whether to force it to return an avatar even if show_avatars is disabled
+ *
+ * @return array First element is the URL, second is the class.
+ */
+ public static function get_avatar_url( $id_or_email, $size = 96, $default = '', $force_display = false ) {
+ // Don't bother adding the __return_true filter if it's already there.
+ $has_filter = has_filter( 'pre_option_show_avatars', '__return_true' );
+
+ if ( $force_display && ! $has_filter )
+ add_filter( 'pre_option_show_avatars', '__return_true' );
+
+ $avatar = get_avatar( $id_or_email, $size, $default );
+
+ if ( $force_display && ! $has_filter )
+ remove_filter( 'pre_option_show_avatars', '__return_true' );
+
+ // If no data, fail out.
+ if ( is_wp_error( $avatar ) || ! $avatar )
+ return array( null, null );
+
+ // Pull out the URL. If it's not there, fail out.
+ if ( ! preg_match( '/src=["\']([^"\']+)["\']/', $avatar, $url_matches ) )
+ return array( null, null );
+ $url = wp_specialchars_decode( $url_matches[1], ENT_QUOTES );
+
+ // Pull out the class, but it's not a big deal if it's missing.
+ $class = '';
+ if ( preg_match( '/class=["\']([^"\']+)["\']/', $avatar, $class_matches ) )
+ $class = wp_specialchars_decode( $class_matches[1], ENT_QUOTES );
+
+ return array( $url, $class );
+ }
+
+ /*
+ * Pings the WordPress.com Mirror Site for the specified options.
+ *
+ * @param string|array $option_names The option names to request from the WordPress.com Mirror Site
+ *
+ * @return array An associative array of the option values as stored in the WordPress.com Mirror Site
+ */
+ public static function get_cloud_site_options( $option_names ) {
+ $option_names = array_filter( (array) $option_names, 'is_string' );
+
+ Jetpack::load_xml_rpc_client();
+ $xml = new Jetpack_IXR_Client( array(
+ 'user_id' => get_current_user_id(),
+ ) );
+ $xml->query( 'jetpack.fetchSiteOptions', $option_names );
+ if ( $xml->isError() ) {
+ return array_flip( $option_names );
+ }
+ $cloud_site_options = $xml->getResponse();
+
+ // If we want to intentionally jumble the results to test it ...
+ if( isset( $_GET['spoof_identity_crisis'] ) ) {
+ foreach( $cloud_site_options as $key => $value ) {
+ $cloud_site_options[ $key ] = wp_generate_password();
+ }
+ }
+ return $cloud_site_options;
+ }
+
+ /*
+ * Checks to make sure that local options have the same values as remote options. Will cache the results for up to 24 hours.
+ *
+ * @param bool $force_recheck Whether to ignore any cached transient and manually re-check.
+ *
+ * @return array An array of options that do not match. If everything is good, it will evaluate to false.
+ */
+ public static function check_identity_crisis( $force_recheck = false ) {
+ if ( ! current_user_can( 'manage_options' ) )
+ return false;
+
+ if ( ! Jetpack::is_active() || Jetpack::is_development_mode() )
+ return false;
+
+ if ( isset( $_GET['spoof_identity_crisis'] ) )
+ $force_recheck = true;
+
+ if ( $force_recheck || false === ( $errors = get_transient( 'jetpack_has_identity_crisis' ) ) ) {
+ $options_to_check = array(
+ 'siteurl',
+ 'home',
+ );
+ $cloud_options = self::get_cloud_site_options( $options_to_check );
+ $errors = array();
+ foreach ( $cloud_options as $cloud_key => $cloud_value ) {
+ if ( $cloud_value !== get_option( $cloud_key ) ) {
+ $errors[ $cloud_key ] = $cloud_value;
+ }
+ }
+ // Make sure if we're spoofing it, that we don't let the spoof spill over.
+ if ( ! isset( $_GET['spoof_identity_crisis'] ) ) {
+ set_transient( 'jetpack_has_identity_crisis', $errors, DAY_IN_SECONDS );
+ }
+ }
+ return apply_filters( 'jetpack_has_identity_crisis', $errors, $force_recheck );
+ }
+
+ /*
+ * Displays an admin_notice, alerting the user to an identity crisis.
+ */
+ public function alert_identity_crisis() {
+ if ( ! current_user_can( 'manage_options' ) )
+ return;
+
+ if ( ! $errors = self::check_identity_crisis() )
+ return;
+ ?>
+
+ <div id="message" class="updated jetpack-message jp-identity-crisis">
+ <div class="jetpack-wrap-container">
+ <div class="jetpack-text-container">
+ <h3><?php _e( 'Something has gotten mixed up!', 'jetpack' ); ?></h3>
+ <?php foreach ( $errors as $key => $value ) : ?>
+ <p><?php printf( __( 'Your <code>%1$s</code> option is set up as <strong>%2$s</strong>, but your WordPress.com connection lists it as <strong>%3$s</strong>!', 'jetpack' ), $key, (string) get_option( $key ), $value ); ?></p>
+ <?php endforeach; ?>
+ <p><?php _e( 'This problem can often be resolved by disconnecting, then reconnecting to WordPress.com.', 'jetpack' ); ?> <a href="<?php echo $this->build_reconnect_url() ?>" class="button-connector" id="wpcom-connect"><?php _e( 'Disconnect and Reconnect to WordPress.com', 'jetpack' ); ?></a></p>
+ </div>
+ </div>
+ </div>
+
+ <?php
+ }
+}
diff --git a/plugins/jetpack/languages/jetpack-uk.mo b/plugins/jetpack/languages/jetpack-uk.mo
new file mode 100644
index 00000000..e1c6c29c
--- /dev/null
+++ b/plugins/jetpack/languages/jetpack-uk.mo
Binary files differ
diff --git a/plugins/jetpack/modules/contact-form/css/menu-alter.css b/plugins/jetpack/modules/contact-form/css/menu-alter.css
new file mode 100644
index 00000000..d0b175e0
--- /dev/null
+++ b/plugins/jetpack/modules/contact-form/css/menu-alter.css
@@ -0,0 +1,56 @@
+#menu-posts-feedback .wp-menu-image img {
+ display: none;
+}
+
+#adminmenu .menu-icon-feedback:hover div.wp-menu-image,
+#adminmenu .menu-icon-feedback.wp-has-current-submenu div.wp-menu-image,
+#adminmenu .menu-icon-feedback.current div.wp-menu-image {
+ background: url(../images/grunion-menu-hover.png) no-repeat 7px 7px !important;
+}
+
+#adminmenu .menu-icon-feedback div.wp-menu-image {
+ background: url(../images/grunion-menu.png) no-repeat 7px 7px !important;
+}
+
+body.admin-color-mp6 #adminmenu .menu-icon-feedback div.wp-menu-image {
+ background: none !important;
+}
+
+body.admin-color-mp6 #adminmenu .menu-icon-feedback div.wp-menu-image:before {
+ content: '\f175';
+ margin-left: -1px;
+}
+
+.jetpack-contact-form-icon {
+ background: url(../images/grunion-form.png) no-repeat;
+ width: 16px;
+ height: 16px;
+ display: inline-block;
+ vertical-align: middle;
+}
+
+@media only screen and (-moz-min-device-pixel-ratio: 1.5),
+ only screen and (-o-min-device-pixel-ratio: 3/2),
+ only screen and (-webkit-min-device-pixel-ratio: 1.5),
+ only screen and (min-device-pixel-ratio: 1.5) {
+
+ #adminmenu .menu-icon-feedback:hover div.wp-menu-image,
+ #adminmenu .menu-icon-feedback.wp-has-current-submenu div.wp-menu-image,
+ #adminmenu .menu-icon-feedback.current div.wp-menu-image {
+ background: url(../images/grunion-menu-hover-2x.png) no-repeat 7px 7px !important;
+ background-size: 15px 16px !important;
+ }
+
+ #adminmenu .menu-icon-feedback div.wp-menu-image {
+ background: url(../images/grunion-menu-2x.png) no-repeat 7px 7px !important;
+ background-size: 15px 16px !important;
+ }
+
+ .jetpack-contact-form-icon {
+ background-image: url(../images/grunion-form-2x.png);
+ background-size: 13px 12px !important;
+ vertical-align: bottom;
+ }
+
+}
+
diff --git a/plugins/jetpack/modules/contact-form/css/rtl/grunion-rtl.css b/plugins/jetpack/modules/contact-form/css/rtl/grunion-rtl.css
new file mode 100644
index 00000000..5b1ae1ba
--- /dev/null
+++ b/plugins/jetpack/modules/contact-form/css/rtl/grunion-rtl.css
@@ -0,0 +1,12 @@
+/* This file was automatically generated on Feb 27 2013 21:33:34 */
+
+.contact-form .clear-form { clear: both; }
+.contact-form input[type='text'], .contact-form input[type='email'] { width: 300px; max-width: 98%; margin-bottom: 13px; }
+.contact-form select { margin-bottom: 13px; }
+.contact-form textarea { height: 200px; width: 80%; float: none; margin-bottom: 13px; }
+.contact-form input[type='radio'], .contact-form input[type='checkbox'] { float: none; margin-bottom: 13px; }
+.contact-form label { margin-bottom: 3px; float: none; font-weight: bold; display: block; }
+.contact-form label.checkbox, .contact-form label.radio { margin-bottom: 3px; float: none; font-weight: bold; display: inline-block; }
+.contact-form label span { color: #AAA; margin-right: 4px; font-weight: normal; }
+.form-errors .form-error-message { color: red; }
+.textwidget input[type='text'], .textwidget input[type='email'], .textwidget textarea { width: 250px; max-width: 98%; }
diff --git a/plugins/jetpack/modules/contact-form/css/rtl/menu-alter-rtl.css b/plugins/jetpack/modules/contact-form/css/rtl/menu-alter-rtl.css
new file mode 100644
index 00000000..fe824007
--- /dev/null
+++ b/plugins/jetpack/modules/contact-form/css/rtl/menu-alter-rtl.css
@@ -0,0 +1,62 @@
+/* This file was automatically generated on Jun 19 2013 15:20:57 */
+
+#menu-posts-feedback .wp-menu-image img {
+ display: none;
+}
+
+#adminmenu .menu-icon-feedback:hover div.wp-menu-image,
+#adminmenu .menu-icon-feedback.wp-has-current-submenu div.wp-menu-image,
+#adminmenu .menu-icon-feedback.current div.wp-menu-image {
+ background: url(../../images/grunion-menu-hover.png) no-repeat 7px 7px !important;
+}
+
+#adminmenu .menu-icon-feedback div.wp-menu-image {
+ background: url(../../images/grunion-menu.png) no-repeat 7px 7px !important;
+}
+
+body.admin-color-mp6 #adminmenu .toplevel_page_feedback div.wp-menu-image img {
+ display: none;
+}
+
+body.admin-color-mp6 #adminmenu .menu-icon-feedback div.wp-menu-image, body.admin-color-mp6 #adminmenu .toplevel_page_feedback div.wp-menu-image {
+ background: none !important;
+}
+
+body.admin-color-mp6 #adminmenu .menu-icon-feedback div.wp-menu-image:before, body.admin-color-mp6 #adminmenu .toplevel_page_feedback div.wp-menu-image:before {
+ content: '\f175';
+ margin-right: -1px;
+}
+
+.jetpack-contact-form-icon {
+ background: url(../../images/grunion-form.png) no-repeat;
+ width: 16px;
+ height: 16px;
+ display: inline-block;
+ vertical-align: middle;
+}
+
+@media only screen and (-moz-min-device-pixel-ratio: 1.5),
+ only screen and (-o-min-device-pixel-ratio: 3/2),
+ only screen and (-webkit-min-device-pixel-ratio: 1.5),
+ only screen and (min-device-pixel-ratio: 1.5) {
+
+ #adminmenu .menu-icon-feedback:hover div.wp-menu-image,
+ #adminmenu .menu-icon-feedback.wp-has-current-submenu div.wp-menu-image,
+ #adminmenu .menu-icon-feedback.current div.wp-menu-image {
+ background: url(../../images/grunion-menu-hover-2x.png) no-repeat 7px 7px !important;
+ background-size: 15px 16px !important;
+ }
+
+ #adminmenu .menu-icon-feedback div.wp-menu-image {
+ background: url(../../images/grunion-menu-2x.png) no-repeat 7px 7px !important;
+ background-size: 15px 16px !important;
+ }
+
+ .jetpack-contact-form-icon {
+ background-image: url(../../images/grunion-form-2x.png);
+ background-size: 13px 12px !important;
+ vertical-align: bottom;
+ }
+
+}
+
diff --git a/plugins/jetpack/modules/contact-form/grunion-omnisearch.php b/plugins/jetpack/modules/contact-form/grunion-omnisearch.php
new file mode 100644
index 00000000..16221152
--- /dev/null
+++ b/plugins/jetpack/modules/contact-form/grunion-omnisearch.php
@@ -0,0 +1,65 @@
+<?php
+
+if( ! class_exists( 'WP_List_Table' ) )
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
+
+class Jetpack_Omnisearch_Grunion extends WP_List_Table {
+ static $instance;
+ var $post_type = 'feedback';
+
+ function __construct() {
+ self::$instance = $this;
+ add_filter( 'omnisearch_results', array( $this, 'search'), 12, 2 );
+ }
+
+ function search( $results, $search_term ) {
+ parent::__construct();
+
+ $this->post_type_obj = get_post_type_object( $this->post_type );
+
+ $search_url = esc_url( admin_url( sprintf( 'edit.php?post_type=%s&s=%s', urlencode( $this->post_type_obj->name ), urlencode( $search_term ) ) ) );
+ $search_link = sprintf( ' <a href="%s" class="add-new-h2">%s</a>', $search_url, esc_html( $this->post_type_obj->labels->search_items ) );
+ $html = '<h2>' . esc_html( $this->post_type_obj->labels->name ) . $search_link .'</h2>';
+
+ $this->prepare_items( $search_term );
+
+ ob_start();
+ $this->display();
+ $html .= ob_get_clean();
+
+ $results[ $this->post_type_obj->labels->name ] = $html;
+ return $results;
+ }
+
+ function get_columns() {
+ $columns = array(
+ 'feedback_from' => __('From', 'jetpack'),
+ 'feedback_message' => __('Message', 'jetpack'),
+ 'feedback_date' => __('Date', 'jetpack'),
+ );
+ return $columns;
+ }
+
+ function prepare_items( $search_term = '' ) {
+ $this->_column_headers = array( $this->get_columns(), array(), array() );
+ $num_results = apply_filters( 'omnisearch_num_results', 5 );
+ $this->items = get_posts( array(
+ 's' => $search_term,
+ 'post_type' => $this->post_type,
+ 'posts_per_page' => $num_results,
+ ) );
+ }
+
+ function column_default( $post, $column_name ) {
+ switch ( $column_name ) {
+ case 'feedback_from':
+ case 'feedback_message':
+ case 'feedback_date':
+ ob_start();
+ grunion_manage_post_columns( $column_name, $post->ID );
+ return ob_get_clean();
+ default:
+ return '<pre>' . print_r( $post, true ) . '</pre>';
+ }
+ }
+}
diff --git a/plugins/jetpack/modules/contact-form/js/grunion-frontend.js b/plugins/jetpack/modules/contact-form/js/grunion-frontend.js
new file mode 100644
index 00000000..c87c1640
--- /dev/null
+++ b/plugins/jetpack/modules/contact-form/js/grunion-frontend.js
@@ -0,0 +1,3 @@
+jQuery( function ( $ ) {
+ $( '.contact-form input[type="date"]' ).datepicker( { dateFormat : 'yy-mm-dd' } );
+} ); \ No newline at end of file
diff --git a/plugins/jetpack/modules/custom-css/custom-css/css/ace.css b/plugins/jetpack/modules/custom-css/custom-css/css/ace.css
new file mode 100644
index 00000000..e9418935
--- /dev/null
+++ b/plugins/jetpack/modules/custom-css/custom-css/css/ace.css
@@ -0,0 +1,25 @@
+#safecss-container {
+ position: relative;
+ width: 99.5%;
+ height: 400px;
+ border: 1px solid #dfdfdf;
+ border-radius: 3px;
+}
+
+#safecss, #safecss-container .ace_editor, #safecss-container .ace_editor * {
+ font-family: Consolas, Monaco, Courier, monospace !important;
+}
+
+#safecss-ace {
+ width: 100%;
+ height: 100%;
+ display: none; /* Hide on load otherwise it looks weird */
+}
+
+#safecss-ace.ace_editor {
+ display: block;
+}
+
+#safecss-container .ace-tm .ace_gutter {
+ background-color: #ededed;
+}
diff --git a/plugins/jetpack/modules/custom-css/custom-css/css/css-editor.css b/plugins/jetpack/modules/custom-css/custom-css/css/css-editor.css
new file mode 100644
index 00000000..4dec4125
--- /dev/null
+++ b/plugins/jetpack/modules/custom-css/custom-css/css/css-editor.css
@@ -0,0 +1,24 @@
+#revision-field-post_title, #revision-field-post_excerpt {
+ display: none;
+}
+
+#safecssform {
+ position: relative;
+}
+
+#poststuff {
+ padding-top: 0;
+}
+
+#safecss {
+ min-height: 250px;
+ width: 100%;
+}
+
+.misc-pub-section > span {
+ font-weight: bold;
+}
+
+.misc-pub-section > div {
+ margin-top: 3px;
+} \ No newline at end of file
diff --git a/plugins/jetpack/modules/custom-css/custom-css/js/ace/mode-less.js b/plugins/jetpack/modules/custom-css/custom-css/js/ace/mode-less.js
new file mode 100644
index 00000000..68b4ca74
--- /dev/null
+++ b/plugins/jetpack/modules/custom-css/custom-css/js/ace/mode-less.js
@@ -0,0 +1 @@
+ace.define("ace/mode/less",["require","exports","module","ace/lib/oop","ace/mode/text","ace/tokenizer","ace/mode/less_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/folding/cstyle"],function(e,t,n){var r=e("../lib/oop"),i=e("./text").Mode,s=e("../tokenizer").Tokenizer,o=e("./less_highlight_rules").LessHighlightRules,u=e("./matching_brace_outdent").MatchingBraceOutdent,a=e("./folding/cstyle").FoldMode,f=function(){this.$tokenizer=new s((new o).getRules(),"i"),this.$outdent=new u,this.foldingRules=new a};r.inherits(f,i),function(){this.getNextLineIndent=function(e,t,n){var r=this.$getIndent(t),i=this.$tokenizer.getLineTokens(t,e).tokens;if(i.length&&i[i.length-1].type=="comment")return r;var s=t.match(/^.*\{\s*$/);return s&&(r+=n),r},this.checkOutdent=function(e,t,n){return this.$outdent.checkOutdent(t,n)},this.autoOutdent=function(e,t,n){this.$outdent.autoOutdent(t,n)}}.call(f.prototype),t.Mode=f}),ace.define("ace/mode/less_highlight_rules",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text_highlight_rules"],function(e,t,n){var r=e("../lib/oop"),i=e("../lib/lang"),s=e("./text_highlight_rules").TextHighlightRules,o=function(){var e=i.arrayToMap(function(){var e="-webkit-|-moz-|-o-|-ms-|-svg-|-pie-|-khtml-".split("|"),t="appearance|background-clip|background-inline-policy|background-origin|background-size|binding|border-bottom-colors|border-left-colors|border-right-colors|border-top-colors|border-end|border-end-color|border-end-style|border-end-width|border-image|border-start|border-start-color|border-start-style|border-start-width|box-align|box-direction|box-flex|box-flexgroup|box-ordinal-group|box-orient|box-pack|box-sizing|column-count|column-gap|column-width|column-rule|column-rule-width|column-rule-style|column-rule-color|float-edge|font-feature-settings|font-language-override|force-broken-image-icon|image-region|margin-end|margin-start|opacity|outline|outline-color|outline-offset|outline-radius|outline-radius-bottomleft|outline-radius-bottomright|outline-radius-topleft|outline-radius-topright|outline-style|outline-width|padding-end|padding-start|stack-sizing|tab-size|text-blink|text-decoration-color|text-decoration-line|text-decoration-style|transform|transform-origin|transition|transition-delay|transition-duration|transition-property|transition-timing-function|user-focus|user-input|user-modify|user-select|window-shadow|border-radius".split("|"),n="azimuth|background-attachment|background-color|background-image|background-position|background-repeat|background|border-bottom-color|border-bottom-style|border-bottom-width|border-bottom|border-collapse|border-color|border-left-color|border-left-style|border-left-width|border-left|border-right-color|border-right-style|border-right-width|border-right|border-spacing|border-style|border-top-color|border-top-style|border-top-width|border-top|border-width|border|bottom|box-sizing|caption-side|clear|clip|color|content|counter-increment|counter-reset|cue-after|cue-before|cue|cursor|direction|display|elevation|empty-cells|float|font-family|font-size-adjust|font-size|font-stretch|font-style|font-variant|font-weight|font|height|left|letter-spacing|line-height|list-style-image|list-style-position|list-style-type|list-style|margin-bottom|margin-left|margin-right|margin-top|marker-offset|margin|marks|max-height|max-width|min-height|min-width|opacity|orphans|outline-color|outline-style|outline-width|outline|overflow|overflow-x|overflow-y|padding-bottom|padding-left|padding-right|padding-top|padding|page-break-after|page-break-before|page-break-inside|page|pause-after|pause-before|pause|pitch-range|pitch|play-during|position|quotes|richness|right|size|speak-header|speak-numeral|speak-punctuation|speech-rate|speak|stress|table-layout|text-align|text-decoration|text-indent|text-shadow|text-transform|top|unicode-bidi|vertical-align|visibility|voice-family|volume|white-space|widows|width|word-spacing|z-index".split("|"),r=[];for(var i=0,s=e.length;i<s;i++)Array.prototype.push.apply(r,(e[i]+t.join("|"+e[i])).split("|"));return Array.prototype.push.apply(r,t),Array.prototype.push.apply(r,n),r}()),t=i.arrayToMap("hsl|hsla|rgb|rgba|url|attr|counter|counters|lighten|darken|saturate|desaturate|fadein|fadeout|fade|spin|mix|hue|saturation|lightness|alpha|round|ceil|floor|percentage|color|iscolor|isnumber|isstring|iskeyword|isurl|ispixel|ispercentage|isem".split("|")),n=i.arrayToMap("absolute|all-scroll|always|armenian|auto|baseline|below|bidi-override|block|bold|bolder|border-box|both|bottom|break-all|break-word|capitalize|center|char|circle|cjk-ideographic|col-resize|collapse|content-box|crosshair|dashed|decimal-leading-zero|decimal|default|disabled|disc|distribute-all-lines|distribute-letter|distribute-space|distribute|dotted|double|e-resize|ellipsis|fixed|georgian|groove|hand|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|ideograph-alpha|ideograph-numeric|ideograph-parenthesis|ideograph-space|inactive|inherit|inline-block|inline|inset|inside|inter-ideograph|inter-word|italic|justify|katakana-iroha|katakana|keep-all|left|lighter|line-edge|line-through|line|list-item|loose|lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|medium|middle|move|n-resize|ne-resize|newspaper|no-drop|no-repeat|nw-resize|none|normal|not-allowed|nowrap|oblique|outset|outside|overline|pointer|progress|relative|repeat-x|repeat-y|repeat|right|ridge|row-resize|rtl|s-resize|scroll|se-resize|separate|small-caps|solid|square|static|strict|super|sw-resize|table-footer-group|table-header-group|tb-rl|text-bottom|text-top|text|thick|thin|top|transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|zero".split("|")),r=i.arrayToMap("aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow".split("|")),s=i.arrayToMap("@mixin|@extend|@include|@import|@media|@debug|@warn|@if|@for|@each|@while|@else|@font-face|@-webkit-keyframes|if|and|!default|module|def|end|declare|when|not|and".split("|")),o=i.arrayToMap("a|abbr|acronym|address|applet|area|article|aside|audio|b|base|basefont|bdo|big|blockquote|body|br|button|canvas|caption|center|cite|code|col|colgroup|command|datalist|dd|del|details|dfn|dir|div|dl|dt|em|embed|fieldset|figcaption|figure|font|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hgroup|hr|html|i|iframe|img|input|ins|keygen|kbd|label|legend|li|link|map|mark|menu|meta|meter|nav|noframes|noscript|object|ol|optgroup|option|output|p|param|pre|progress|q|rp|rt|ruby|s|samp|script|section|select|small|source|span|strike|strong|style|sub|summary|sup|table|tbody|td|textarea|tfoot|th|thead|time|title|tr|tt|u|ul|var|video|wbr|xmp".split("|")),u="\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";this.$rules={start:[{token:"comment",regex:"\\/\\/.*$"},{token:"comment",merge:!0,regex:"\\/\\*",next:"comment"},{token:"string",regex:'["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'},{token:"string",regex:"['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"},{token:"constant.numeric",regex:u+"(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)"},{token:"constant.numeric",regex:"#[a-f0-9]{6}"},{token:"constant.numeric",regex:"#[a-f0-9]{3}"},{token:"constant.numeric",regex:u},{token:function(e){return s.hasOwnProperty(e)?"keyword":"variable"},regex:"@[a-z0-9_\\-@]*\\b"},{token:function(i){return e.hasOwnProperty(i.toLowerCase())?"support.type":s.hasOwnProperty(i)?"keyword":n.hasOwnProperty(i)?"constant.language":t.hasOwnProperty(i)?"support.function":r.hasOwnProperty(i.toLowerCase())?"support.constant.color":o.hasOwnProperty(i.toLowerCase())?"variable.language":"text"},regex:"\\-?[@a-z_][@a-z0-9_\\-]*"},{token:"variable.language",regex:"#[a-z0-9-_]+"},{token:"variable.language",regex:"\\.[a-z0-9-_]+"},{token:"variable.language",regex:":[a-z0-9-_]+"},{token:"constant",regex:"[a-z0-9-_]+"},{token:"keyword.operator",regex:"<|>|<=|>=|==|!=|-|%|#|\\+|\\$|\\+|\\*"},{token:"paren.lparen",regex:"[[({]"},{token:"paren.rparen",regex:"[\\])}]"},{token:"text",regex:"\\s+"}],comment:[{token:"comment",regex:".*?\\*\\/",next:"start"},{token:"comment",merge:!0,regex:".+"}]}};r.inherits(o,s),t.LessHighlightRules=o}),ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"],function(e,t,n){var r=e("../range").Range,i=function(){};(function(){this.checkOutdent=function(e,t){return/^\s+$/.test(e)?/^\s*\}/.test(t):!1},this.autoOutdent=function(e,t){var n=e.getLine(t),i=n.match(/^(\s*\})/);if(!i)return 0;var s=i[1].length,o=e.findMatchingBracket({row:t,column:s});if(!o||o.row==t)return 0;var u=this.$getIndent(e.getLine(o.row));e.replace(new r(t,0,t,s-1),u)},this.$getIndent=function(e){var t=e.match(/^(\s+)/);return t?t[1]:""}}).call(i.prototype),t.MatchingBraceOutdent=i}),ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"],function(e,t,n){var r=e("../../lib/oop"),i=e("../../range").Range,s=e("./fold_mode").FoldMode,o=t.FoldMode=function(){};r.inherits(o,s),function(){this.foldingStartMarker=/(\{|\[)[^\}\]]*$|^\s*(\/\*)/,this.foldingStopMarker=/^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/,this.getFoldWidgetRange=function(e,t,n){var r=e.getLine(n),i=r.match(this.foldingStartMarker);if(i){var s=i.index;return i[1]?this.openingBracketBlock(e,i[1],n,s):e.getCommentFoldRange(n,s+i[0].length,1)}if(t!=="markbeginend")return;var i=r.match(this.foldingStopMarker);if(i){var s=i.index+i[0].length;return i[1]?this.closingBracketBlock(e,i[1],n,s):e.getCommentFoldRange(n,s,-1)}}}.call(o.prototype)}) \ No newline at end of file
diff --git a/plugins/jetpack/modules/custom-css/custom-css/js/ace/mode-scss.js b/plugins/jetpack/modules/custom-css/custom-css/js/ace/mode-scss.js
new file mode 100644
index 00000000..eca01605
--- /dev/null
+++ b/plugins/jetpack/modules/custom-css/custom-css/js/ace/mode-scss.js
@@ -0,0 +1 @@
+ace.define("ace/mode/scss",["require","exports","module","ace/lib/oop","ace/mode/text","ace/tokenizer","ace/mode/scss_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/folding/cstyle"],function(e,t,n){var r=e("../lib/oop"),i=e("./text").Mode,s=e("../tokenizer").Tokenizer,o=e("./scss_highlight_rules").ScssHighlightRules,u=e("./matching_brace_outdent").MatchingBraceOutdent,a=e("./folding/cstyle").FoldMode,f=function(){this.$tokenizer=new s((new o).getRules(),"i"),this.$outdent=new u,this.foldingRules=new a};r.inherits(f,i),function(){this.getNextLineIndent=function(e,t,n){var r=this.$getIndent(t),i=this.$tokenizer.getLineTokens(t,e).tokens;if(i.length&&i[i.length-1].type=="comment")return r;var s=t.match(/^.*\{\s*$/);return s&&(r+=n),r},this.checkOutdent=function(e,t,n){return this.$outdent.checkOutdent(t,n)},this.autoOutdent=function(e,t,n){this.$outdent.autoOutdent(t,n)}}.call(f.prototype),t.Mode=f}),ace.define("ace/mode/scss_highlight_rules",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text_highlight_rules"],function(e,t,n){var r=e("../lib/oop"),i=e("../lib/lang"),s=e("./text_highlight_rules").TextHighlightRules,o=function(){var e=i.arrayToMap(function(){var e="-webkit-|-moz-|-o-|-ms-|-svg-|-pie-|-khtml-".split("|"),t="appearance|background-clip|background-inline-policy|background-origin|background-size|binding|border-bottom-colors|border-left-colors|border-right-colors|border-top-colors|border-end|border-end-color|border-end-style|border-end-width|border-image|border-start|border-start-color|border-start-style|border-start-width|box-align|box-direction|box-flex|box-flexgroup|box-ordinal-group|box-orient|box-pack|box-sizing|column-count|column-gap|column-width|column-rule|column-rule-width|column-rule-style|column-rule-color|float-edge|font-feature-settings|font-language-override|force-broken-image-icon|image-region|margin-end|margin-start|opacity|outline|outline-color|outline-offset|outline-radius|outline-radius-bottomleft|outline-radius-bottomright|outline-radius-topleft|outline-radius-topright|outline-style|outline-width|padding-end|padding-start|stack-sizing|tab-size|text-blink|text-decoration-color|text-decoration-line|text-decoration-style|transform|transform-origin|transition|transition-delay|transition-duration|transition-property|transition-timing-function|user-focus|user-input|user-modify|user-select|window-shadow|border-radius".split("|"),n="azimuth|background-attachment|background-color|background-image|background-position|background-repeat|background|border-bottom-color|border-bottom-style|border-bottom-width|border-bottom|border-collapse|border-color|border-left-color|border-left-style|border-left-width|border-left|border-right-color|border-right-style|border-right-width|border-right|border-spacing|border-style|border-top-color|border-top-style|border-top-width|border-top|border-width|border|bottom|box-sizing|caption-side|clear|clip|color|content|counter-increment|counter-reset|cue-after|cue-before|cue|cursor|direction|display|elevation|empty-cells|float|font-family|font-size-adjust|font-size|font-stretch|font-style|font-variant|font-weight|font|height|left|letter-spacing|line-height|list-style-image|list-style-position|list-style-type|list-style|margin-bottom|margin-left|margin-right|margin-top|marker-offset|margin|marks|max-height|max-width|min-height|min-width|opacity|orphans|outline-color|outline-style|outline-width|outline|overflow|overflow-x|overflow-y|padding-bottom|padding-left|padding-right|padding-top|padding|page-break-after|page-break-before|page-break-inside|page|pause-after|pause-before|pause|pitch-range|pitch|play-during|position|quotes|richness|right|size|speak-header|speak-numeral|speak-punctuation|speech-rate|speak|stress|table-layout|text-align|text-decoration|text-indent|text-shadow|text-transform|top|unicode-bidi|vertical-align|visibility|voice-family|volume|white-space|widows|width|word-spacing|z-index".split("|"),r=[];for(var i=0,s=e.length;i<s;i++)Array.prototype.push.apply(r,(e[i]+t.join("|"+e[i])).split("|"));return Array.prototype.push.apply(r,t),Array.prototype.push.apply(r,n),r}()),t=i.arrayToMap("hsl|hsla|rgb|rgba|url|attr|counter|counters|abs|adjust_color|adjust_hue|alpha|join|blue|ceil|change_color|comparable|complement|darken|desaturate|floor|grayscale|green|hue|if|invert|join|length|lighten|lightness|mix|nth|opacify|opacity|percentage|quote|red|round|saturate|saturation|scale_color|transparentize|type_of|unit|unitless|unqoute".split("|")),n=i.arrayToMap("absolute|all-scroll|always|armenian|auto|baseline|below|bidi-override|block|bold|bolder|border-box|both|bottom|break-all|break-word|capitalize|center|char|circle|cjk-ideographic|col-resize|collapse|content-box|crosshair|dashed|decimal-leading-zero|decimal|default|disabled|disc|distribute-all-lines|distribute-letter|distribute-space|distribute|dotted|double|e-resize|ellipsis|fixed|georgian|groove|hand|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|ideograph-alpha|ideograph-numeric|ideograph-parenthesis|ideograph-space|inactive|inherit|inline-block|inline|inset|inside|inter-ideograph|inter-word|italic|justify|katakana-iroha|katakana|keep-all|left|lighter|line-edge|line-through|line|list-item|loose|lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|medium|middle|move|n-resize|ne-resize|newspaper|no-drop|no-repeat|nw-resize|none|normal|not-allowed|nowrap|oblique|outset|outside|overline|pointer|progress|relative|repeat-x|repeat-y|repeat|right|ridge|row-resize|rtl|s-resize|scroll|se-resize|separate|small-caps|solid|square|static|strict|super|sw-resize|table-footer-group|table-header-group|tb-rl|text-bottom|text-top|text|thick|thin|top|transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|zero".split("|")),r=i.arrayToMap("aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow".split("|")),s=i.arrayToMap("@mixin|@extend|@include|@import|@media|@debug|@warn|@if|@for|@each|@while|@else|@font-face|@-webkit-keyframes|if|and|!default|module|def|end|declare".split("|")),o=i.arrayToMap("a|abbr|acronym|address|applet|area|article|aside|audio|b|base|basefont|bdo|big|blockquote|body|br|button|canvas|caption|center|cite|code|col|colgroup|command|datalist|dd|del|details|dfn|dir|div|dl|dt|em|embed|fieldset|figcaption|figure|font|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hgroup|hr|html|i|iframe|img|input|ins|keygen|kbd|label|legend|li|link|map|mark|menu|meta|meter|nav|noframes|noscript|object|ol|optgroup|option|output|p|param|pre|progress|q|rp|rt|ruby|s|samp|script|section|select|small|source|span|strike|strong|style|sub|summary|sup|table|tbody|td|textarea|tfoot|th|thead|time|title|tr|tt|u|ul|var|video|wbr|xmp".split("|")),u="\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";this.$rules={start:[{token:"comment",regex:"\\/\\/.*$"},{token:"comment",merge:!0,regex:"\\/\\*",next:"comment"},{token:"string",regex:'["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'},{token:"string",merge:!0,regex:'["].*\\\\$',next:"qqstring"},{token:"string",regex:"['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"},{token:"string",merge:!0,regex:"['].*\\\\$",next:"qstring"},{token:"constant.numeric",regex:u+"(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)"},{token:"constant.numeric",regex:"#[a-f0-9]{6}"},{token:"constant.numeric",regex:"#[a-f0-9]{3}"},{token:"constant.numeric",regex:u},{token:function(i){return e.hasOwnProperty(i.toLowerCase())?"support.type":s.hasOwnProperty(i)?"keyword":n.hasOwnProperty(i)?"constant.language":t.hasOwnProperty(i)?"support.function":r.hasOwnProperty(i.toLowerCase())?"support.constant.color":o.hasOwnProperty(i.toLowerCase())?"variable.language":"text"},regex:"\\-?[@a-z_][@a-z0-9_\\-]*"},{token:"variable",regex:"[a-z_\\-$][a-z0-9_\\-$]*\\b"},{token:"variable.language",regex:"#[a-z0-9-_]+"},{token:"variable.language",regex:"\\.[a-z0-9-_]+"},{token:"variable.language",regex:":[a-z0-9-_]+"},{token:"constant",regex:"[a-z0-9-_]+"},{token:"keyword.operator",regex:"<|>|<=|>=|==|!=|-|%|#|\\+|\\$|\\+|\\*"},{token:"paren.lparen",regex:"[[({]"},{token:"paren.rparen",regex:"[\\])}]"},{token:"text",regex:"\\s+"}],comment:[{token:"comment",regex:".*?\\*\\/",next:"start"},{token:"comment",merge:!0,regex:".+"}],qqstring:[{token:"string",regex:'(?:(?:\\\\.)|(?:[^"\\\\]))*?"',next:"start"},{token:"string",merge:!0,regex:".+"}],qstring:[{token:"string",regex:"(?:(?:\\\\.)|(?:[^'\\\\]))*?'",next:"start"},{token:"string",merge:!0,regex:".+"}]}};r.inherits(o,s),t.ScssHighlightRules=o}),ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"],function(e,t,n){var r=e("../range").Range,i=function(){};(function(){this.checkOutdent=function(e,t){return/^\s+$/.test(e)?/^\s*\}/.test(t):!1},this.autoOutdent=function(e,t){var n=e.getLine(t),i=n.match(/^(\s*\})/);if(!i)return 0;var s=i[1].length,o=e.findMatchingBracket({row:t,column:s});if(!o||o.row==t)return 0;var u=this.$getIndent(e.getLine(o.row));e.replace(new r(t,0,t,s-1),u)},this.$getIndent=function(e){var t=e.match(/^(\s+)/);return t?t[1]:""}}).call(i.prototype),t.MatchingBraceOutdent=i}),ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"],function(e,t,n){var r=e("../../lib/oop"),i=e("../../range").Range,s=e("./fold_mode").FoldMode,o=t.FoldMode=function(){};r.inherits(o,s),function(){this.foldingStartMarker=/(\{|\[)[^\}\]]*$|^\s*(\/\*)/,this.foldingStopMarker=/^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/,this.getFoldWidgetRange=function(e,t,n){var r=e.getLine(n),i=r.match(this.foldingStartMarker);if(i){var s=i.index;return i[1]?this.openingBracketBlock(e,i[1],n,s):e.getCommentFoldRange(n,s+i[0].length,1)}if(t!=="markbeginend")return;var i=r.match(this.foldingStopMarker);if(i){var s=i.index+i[0].length;return i[1]?this.closingBracketBlock(e,i[1],n,s):e.getCommentFoldRange(n,s,-1)}}}.call(o.prototype)}) \ No newline at end of file
diff --git a/plugins/jetpack/modules/custom-css/custom-css/js/css-editor.js b/plugins/jetpack/modules/custom-css/custom-css/js/css-editor.js
new file mode 100644
index 00000000..6d4f0824
--- /dev/null
+++ b/plugins/jetpack/modules/custom-css/custom-css/js/css-editor.js
@@ -0,0 +1,81 @@
+( function ( $ ) {
+ var safe, win, safecssResize, safecssInit;
+
+ safecssResize = function () {
+ safe.height( win.height() - safe.offset().top - 250 );
+ };
+
+ safecssInit = function() {
+ safe = $( '#safecss' );
+ win = $( window );
+
+ postboxes.add_postbox_toggles( 'editcss' );
+ safecssResize();
+
+ // Bound on a parent to ensure that this click event executes last.
+ $( '#safecssform' ).on( 'click', '#preview', function ( e ) {
+ e.preventDefault();
+
+ document.forms["safecssform"].target = "csspreview";
+ document.forms["safecssform"].action.value = 'preview';
+ document.forms["safecssform"].submit();
+ document.forms["safecssform"].target = "";
+ document.forms["safecssform"].action.value = 'save';
+ } );
+ };
+
+ window.onresize = safecssResize;
+ addLoadEvent( safecssInit );
+} )( jQuery );
+
+jQuery( function ( $ ) {
+ $( '.edit-preprocessor' ).bind( 'click', function ( e ) {
+ e.preventDefault();
+
+ $( '#preprocessor-select' ).slideDown();
+ $( this ).hide();
+ } );
+
+ $( '.cancel-preprocessor' ).bind( 'click', function ( e ) {
+ e.preventDefault();
+
+ $( '#preprocessor-select' ).slideUp( function () {
+ $( '.edit-preprocessor' ).show();
+ $( '#preprocessor_choices' ).val( $( '#custom_css_preprocessor' ).val() );
+ } );
+ } );
+
+ $( '.save-preprocessor' ).bind( 'click', function ( e ) {
+ e.preventDefault();
+
+ $( '#preprocessor-select' ).slideUp();
+ $( '#preprocessor-display' ).text( $( '#preprocessor_choices option:selected' ).text() );
+ $( '#custom_css_preprocessor' ).val( $( '#preprocessor_choices' ).val() ).change();
+ $( '.edit-preprocessor' ).show();
+ } );
+
+ $( '.edit-css-mode' ).bind( 'click', function ( e ) {
+ e.preventDefault();
+
+ $( '#css-mode-select' ).slideDown();
+ $( this ).hide();
+ } );
+
+ $( '.cancel-css-mode' ).bind( 'click', function ( e ) {
+ e.preventDefault();
+
+ $( '#css-mode-select' ).slideUp( function () {
+ $( '.edit-css-mode' ).show();
+ $( 'input[name=add_to_existing_display][value=' + $( '#add_to_existing' ).val() + ']' ).attr( 'checked', true );
+ } );
+ } );
+
+ $( '.save-css-mode' ).bind( 'click', function ( e ) {
+ e.preventDefault();
+
+ $( '#css-mode-select' ).slideUp();
+ $( '#css-mode-display' ).text( $( 'input[name=add_to_existing_display]:checked' ).val() == 'true' ? 'Add-on' : 'Replacement' );
+ $( '#add_to_existing' ).val( $( 'input[name=add_to_existing_display]:checked' ).val() );
+ $( '.edit-css-mode' ).show();
+ } );
+} ); \ No newline at end of file
diff --git a/plugins/jetpack/modules/infinite-scroll/themes/twentythirteen.css b/plugins/jetpack/modules/infinite-scroll/themes/twentythirteen.css
new file mode 100644
index 00000000..ba169b35
--- /dev/null
+++ b/plugins/jetpack/modules/infinite-scroll/themes/twentythirteen.css
@@ -0,0 +1,90 @@
+/* =Infinite Scroll
+-------------------------------------------------------------- */
+
+.infinite-wrap {
+ border-top: 0;
+}
+
+/* Spinner */
+.infinite-loader {
+ background-color: #e8e5ce;
+ padding: 40px 0;
+}
+.infinite-loader .spinner {
+ margin: 0 auto;
+ width: 34px;
+ height: 34px;
+}
+.sidebar .infinite-loader .spinner {
+ padding-right: 376px;
+}
+.rtl.sidebar .infinite-loader .spinner {
+ padding-left: 376px;
+ padding-right: 0;
+}
+
+/* Click-to-load */
+#infinite-handle {
+ background-color: #e8e5ce;
+ padding: 40px 0;
+ text-align: center;
+}
+.sidebar #infinite-handle {
+ padding-right: 376px;
+}
+.rtl.sidebar #infinite-handle {
+ padding-left: 376px;
+ padding-right: 0;
+}
+#infinite-handle span {
+ background: #e05d22; /* Old browsers */
+ background: -webkit-linear-gradient(top, #e05d22 0%, #d94412 100%); /* Chrome 10+, Safari 5.1+ */
+ background: linear-gradient(to bottom, #e05d22 0%, #d94412 100%); /* W3C */
+ border: none;
+ border-bottom: 3px solid #b93207;
+ border-radius: 2px;
+ display: inline-block;
+ color: #fff;
+ font-size: 100%;
+ padding: 11px 24px 10px;
+ text-decoration: none;
+}
+#infinite-handle span:hover {
+ background: #ed6a31; /* Old browsers */
+ background: -webkit-linear-gradient(top, #ed6a31 0%, #e55627 100%); /* Chrome 10+, Safari 5.1+ */
+ background: linear-gradient(to bottom, #ed6a31 0%, #e55627 100%); /* W3C */
+ outline: none;
+}
+#infinite-handle span:active {
+ background: #d94412; /* Old browsers */
+ background: -webkit-linear-gradient(top, #d94412 0%, #e05d22 100%); /* Chrome 10+, Safari 5.1+ */
+ background: linear-gradient(to bottom, #d94412 0%, #e05d22 100%); /* W3C */
+ border: none;
+ border-top: 3px solid #b93207;
+ padding: 10px 24px 11px;
+}
+
+/* Elements to hide: post navigation, normal footer. */
+.infinite-scroll .paging-navigation,
+.infinite-scroll.neverending #colophon {
+ display: none;
+}
+
+/* Hooks to infinity-end body class to restore footer. */
+.infinity-end.neverending #colophon {
+ display: block;
+}
+
+/* For small viewports. */
+@media (max-width: 999px) {
+ .sidebar .infinite-loader .spinner,
+ .rtl.sidebar .infinite-loader .spinner {
+ padding-right: 0;
+ padding-left: 0;
+ }
+ .infinite-scroll #infinite-handle,
+ .rtl.sidebar #infinite-handle {
+ padding-right: 0;
+ padding-left: 0;
+ }
+} \ No newline at end of file
diff --git a/plugins/jetpack/modules/infinite-scroll/themes/twentythirteen.php b/plugins/jetpack/modules/infinite-scroll/themes/twentythirteen.php
new file mode 100644
index 00000000..dbc18c70
--- /dev/null
+++ b/plugins/jetpack/modules/infinite-scroll/themes/twentythirteen.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * Infinite Scroll Theme Assets
+ *
+ * Register support for Twenty Thirteen.
+ */
+
+/**
+ * Add theme support for infinite scroll
+ */
+function twentythirteen_infinite_scroll_init() {
+ add_theme_support( 'infinite-scroll', array(
+ 'container' => 'content',
+ 'footer' => 'page',
+ 'footer_widgets' => array( 'sidebar-1' )
+ ) );
+}
+add_action( 'after_setup_theme', 'twentythirteen_infinite_scroll_init' );
+
+/**
+ * Enqueue CSS stylesheet with theme styles for Infinite Scroll.
+ */
+function twentythirteen_infinite_scroll_enqueue_styles() {
+ wp_enqueue_style( 'infinity-twentythirteen', plugins_url( 'twentythirteen.css', __FILE__ ), array( 'the-neverending-homepage' ), '20130409' );
+}
+add_action( 'wp_enqueue_scripts', 'twentythirteen_infinite_scroll_enqueue_styles', 25 ); \ No newline at end of file
diff --git a/plugins/jetpack/modules/likes/post-count.js b/plugins/jetpack/modules/likes/post-count.js
new file mode 100644
index 00000000..d93b8859
--- /dev/null
+++ b/plugins/jetpack/modules/likes/post-count.js
@@ -0,0 +1,69 @@
+var wpPostLikeCount;
+
+(function($) {
+
+ wpPostLikeCount = {
+
+ jsonAPIbase: 'https://public-api.wordpress.com/rest/v1',
+ APIqueue: [],
+
+ wpPostLikeCount: function() {
+ $( '.post-like-count' ).each( function() {
+ var post_id = $(this).attr( 'data-post-id' );
+ var blog_id = $(this).attr( 'data-blog-id' );
+ wpPostLikeCount.APIqueue.push( '/sites/' + blog_id + '/posts/' + post_id + '/likes' );
+ } );
+ wpPostLikeCount.getCounts();
+ },
+
+ showCount: function( post_id, count ) {
+ $( '#post-like-count-' + post_id ).find( '.comment-count' ).hide();
+ $( '#post-like-count-' + post_id ).find( '.comment-count' ).text( count );
+ $( '#post-like-count-' + post_id ).find( '.comment-count' ).fadeIn();
+ },
+
+ getCounts: function() {
+ var batchRequest = {
+ path: '/batch',
+ data: '',
+ success: function( response ) {
+ for ( var path in response ) {
+ if ( ! response[path]['error_data'] ) {
+ var urlPieces = path.split( '/' ); // pieces[4] = post id;
+ var post_id = urlPieces[4];
+ wpPostLikeCount.showCount( post_id, response[path].found );
+ }
+ }
+ },
+ error: function( response ) {
+ }
+ };
+
+ var amp = '';
+ for( var i = 0; i < wpPostLikeCount.APIqueue.length; i++ ) {
+ if ( i > 0 )
+ amp = '&';
+ batchRequest.data += amp + 'urls[]=' + wpPostLikeCount.APIqueue[i];
+ }
+
+ wpPostLikeCount.request( batchRequest );
+ },
+
+ request: function( options ) {
+ return $.ajax( {
+ type: 'GET',
+ url: wpPostLikeCount.jsonAPIbase + options.path,
+ dataType : "jsonp",
+ data: options.data,
+ success: function( response ) { options.success( response ) },
+ error: function( response ) { options.error( response ) }
+ } )
+ }
+
+ };
+
+})(jQuery);
+
+jQuery(document).ready(function($) {
+ wpPostLikeCount.wpPostLikeCount();
+}); \ No newline at end of file
diff --git a/plugins/jetpack/modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.eot b/plugins/jetpack/modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.eot
new file mode 100644
index 00000000..5a60506a
--- /dev/null
+++ b/plugins/jetpack/modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.eot
Binary files differ
diff --git a/plugins/jetpack/modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.svg b/plugins/jetpack/modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.svg
new file mode 100644
index 00000000..3dce209e
--- /dev/null
+++ b/plugins/jetpack/modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.svg
@@ -0,0 +1,81 @@
+<?xml version="1.0" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
+<svg xmlns="http://www.w3.org/2000/svg">
+<metadata></metadata>
+<defs>
+<font id="genericonsregular" horiz-adv-x="2048" >
+<font-face units-per-em="2048" ascent="1638" descent="-410" />
+<missing-glyph horiz-adv-x="500" />
+<glyph unicode="&#x2000;" horiz-adv-x="1024" />
+<glyph unicode="&#x2001;" />
+<glyph unicode="&#x2002;" horiz-adv-x="1024" />
+<glyph unicode="&#x2003;" />
+<glyph unicode="&#x2004;" horiz-adv-x="682" />
+<glyph unicode="&#x2005;" horiz-adv-x="512" />
+<glyph unicode="&#x2006;" horiz-adv-x="341" />
+<glyph unicode="&#x2007;" horiz-adv-x="341" />
+<glyph unicode="&#x2008;" horiz-adv-x="256" />
+<glyph unicode="&#x2009;" horiz-adv-x="409" />
+<glyph unicode="&#x200a;" horiz-adv-x="113" />
+<glyph unicode="&#x202f;" horiz-adv-x="409" />
+<glyph unicode="&#x205f;" horiz-adv-x="512" />
+<glyph unicode="&#xe000;" horiz-adv-x="500" d="M0 0z" />
+<glyph unicode="&#xf100;" d="M512 512v128h768v-128h-768zM512 768v128h256v-128h-256zM512 1024v128h640v-128h-640zM512 1280v128h1024v-128h-1024zM896 768v128h640v-128h-640zM1280 1024v128h256v-128h-256z" />
+<glyph unicode="&#xf101;" d="M256 1024q0 209 103 385.5t279.5 279.5t385.5 103t385.5 -103t279.5 -279.5t103 -385.5t-103 -385.5t-279.5 -279.5t-385.5 -103t-385.5 103t-279.5 279.5t-103 385.5zM768 1024q0 -106 75 -181t181 -75t181 75t75 181t-75 181t-181 75t-181 -75t-75 -181z" />
+<glyph unicode="&#xf102;" d="M128 384v896l512 128l128 256h512l128 -256h512v-1024h-1792zM256 1440v160h256v-96zM576 960q0 -185 131.5 -316.5t316.5 -131.5q186 0 317 131.5t131 316.5t-131 316.5t-317 131.5q-185 0 -316.5 -131.5t-131.5 -316.5zM704 960q0 133 93.5 226.5t226.5 93.5 t226.5 -93.5t93.5 -226.5t-93.5 -226.5t-226.5 -93.5t-226.5 93.5t-93.5 226.5z" />
+<glyph unicode="&#xf103;" d="M128 512v384h384v-384h-384zM128 1024v384h896v-384h-896zM640 512v384h384v-384h-384zM1152 512v896h896v-896h-896z" />
+<glyph unicode="&#xf104;" d="M512 384v1280l1152 -640z" />
+<glyph unicode="&#xf105;" d="M640 1408q0 159 112.5 271.5t271.5 112.5t271.5 -112.5t112.5 -271.5q0 -124 -71.5 -222t-184.5 -138v-536l-256 -128v664q-113 40 -184.5 138t-71.5 222z" />
+<glyph unicode="&#xf106;" d="M384 640l128 768h512l-256 -768h-384zM1152 640l128 768h512l-256 -768h-384z" />
+<glyph unicode="&#xf107;" d="M376 852q0 108 72 204l160 128l96 -96l-160 -128q-48 -96 0 -192l96 -96q96 -48 192 0l128 160l96 -96l-128 -160q-96 -72 -204 -72t-180 72l-96 96q-72 72 -72 180zM736 960l352 352l96 -96l-352 -352zM864 1440l128 160q96 72 204 72t180 -72l96 -96q72 -72 72 -180 t-72 -204l-160 -128l-96 96l160 128q48 96 0 192l-96 96q-96 48 -192 0l-128 -160z" />
+<glyph unicode="&#xf108;" d="M0 1152v384q0 96 80 176t176 80h1024q96 0 176 -80t80 -176v-384q0 -96 -80 -176t-176 -80h-448l-448 -448v448h-128q-96 0 -176 80t-80 176zM768 640l128 128h384q168 0 276 108t108 276v384q96 0 176 -80t80 -176v-384q0 -96 -80 -176t-176 -80h-128v-448l-448 448 h-320z" />
+<glyph unicode="&#xf109;" d="M256 768v512h384l384 384v-1280l-384 384h-384zM1216 832q21 43 32 66.5t21.5 59.5t10.5 66t-10.5 66t-21.5 59.5t-32 66.5l96 96q96 -144 96 -288q0 -160 -96 -256zM1376 672q74 74 117 166t43 186t-43 186t-117 166l96 96q95 -71 143.5 -186.5t48.5 -261.5 t-48.5 -261.5t-143.5 -186.5z" />
+<glyph unicode="&#xf200;" d="M0 1024q0 212 79.5 402t216 326.5t326.5 216t402 79.5t402 -79.5t326.5 -216t216 -326.5t79.5 -402t-79.5 -402t-216 -326.5t-326.5 -216t-402 -79.5t-402 79.5t-326.5 216t-216 326.5t-79.5 402zM128 1024q0 -307 173.5 -536.5t466.5 -327.5v224q0 224 128 224 q-125 0 -213.5 16t-146.5 47t-91.5 83t-47 115.5t-13.5 154.5q0 100 25 187t71 133q-28 71 -28 143t14 109l14 36q7 0 18 -1t44 -7.5t63 -18.5t67 -38.5t64 -62.5q144 24 300 24t276 -24q27 36 60 62.5t60.5 38.5t51.5 18.5t38 7.5l14 1q4 -5 10 -14.5t19 -40.5t20 -63 t4 -78.5t-21 -91.5q96 -144 96 -320q0 -113 -21 -187.5t-75 -128t-147.5 -77t-236.5 -23.5q49 -25 72.5 -77.5t23.5 -146.5v-224q293 98 466.5 327.5t173.5 536.5q0 176 -73 341.5t-194.5 287t-287 194.5t-341.5 73t-341.5 -73t-287 -194.5t-194.5 -287t-73 -341.5z" />
+<glyph unicode="&#xf201;" d="M0 1024q0 206 82 395.5t219.5 327t327 219.5t395.5 82t395.5 -82t327 -219.5t219.5 -327t82 -395.5t-82 -395.5t-219.5 -327t-327 -219.5t-395.5 -82t-395.5 82t-327 219.5t-219.5 327t-82 395.5zM128 1024q0 -167 58 -319.5t166 -272.5q125 205 339 360t445 232 q-16 48 -80 176q-282 -86 -481.5 -111t-446.5 -1v-64zM160 1232q194 -22 444 14t388 82q-141 282 -320 528q-194 -85 -329.5 -247.5t-182.5 -376.5zM480 320q216 -192 544 -192q181 0 368 80q-33 300 -208 688q-222 -74 -410 -225.5t-294 -350.5zM832 1904 q102 -166 304 -512q6 2 86 31t118.5 45t108 47t122 64t93.5 69q-126 126 -290.5 199t-349.5 73q-32 0 -96 -8t-96 -8zM1200 1248q22 -29 36.5 -54.5t34 -67.5t25.5 -54q170 33 336 30t288 -30q-26 285 -160 464q-71 -57 -162 -104.5t-214.5 -100.5t-183.5 -83zM1344 928 q14 -27 43 -103t74.5 -231t74.5 -306q156 108 258 278t126 362q-276 46 -576 0z" />
+<glyph unicode="&#xf202;" d="M0 381q50 -6 100 -6q293 0 522 180q-137 2 -244.5 83t-147.5 208q44 -7 79 -7q57 0 110 15q-145 29 -241 144.5t-96 267.5v5q86 -48 191 -53q-86 58 -136.5 150t-50.5 200q0 113 57 211q158 -194 383 -310t483 -129q-11 49 -11 96q0 174 123 297t297 123q89 0 168.5 -35 t138.5 -97q142 27 266 102q-47 -150 -184 -233q124 15 241 66q-84 -127 -210 -217q2 -36 2 -55q0 -168 -49 -337t-150 -323.5t-241 -273.5t-336 -190t-420 -71q-351 0 -644 189z" />
+<glyph unicode="&#xf203;" d="M0 117q0 -48 34.5 -82.5t82.5 -34.5h1814q48 0 82.5 34.5t34.5 82.5v1814q0 48 -34.5 82.5t-82.5 34.5h-1814q-48 0 -82.5 -34.5t-34.5 -82.5v-1814zM900 969v303h222v258q0 78 26 147t77 124t136.5 87t194.5 32q55 0 108 -3t79 -6l26 -3l-7 -282h-193q-76 0 -101.5 -32 t-25.5 -101v-3v-2v-9v-207h329l-14 -303h-315v-841h-320v841h-222z" />
+<glyph unicode="&#xf204;" d="M640 969v303h222v258q0 78 26 147t77 124t136.5 87t194.5 32q55 0 108 -3t79 -6l26 -3l-7 -282h-193q-76 0 -101.5 -32t-25.5 -101v-3v-2v-9v-207h329l-14 -303h-315v-841h-320v841h-222z" />
+<glyph unicode="&#xf205;" d="M0 1024q0 208 81 397.5t218.5 327t327 218.5t397.5 81t398 -81t327 -218.5t218 -327t81 -397.5q0 -209 -81 -398.5t-218 -326.5t-326.5 -218t-398.5 -81q-208 0 -397.5 81t-327 218t-218.5 327t-81 398zM128 1024q0 -259 135.5 -473.5t359.5 -327.5l-421 1156 q-74 -168 -74 -355zM285 1530q4 0 13.5 -0.5t15.5 -0.5q70 0 127.5 2.5t80.5 4.5l22 3q29 2 46.5 -16t19.5 -40.5t-13 -43t-44 -24.5q-27 -4 -70 -8l295 -877l198 591l-104 283l-90 11q-38 2 -51.5 34t4.5 62t56 28q54 -10 201 -10q70 0 127.5 2.5t80.5 4.5l22 3 q38 2 56.5 -27t5 -60.5t-51.5 -36.5q-27 -4 -69 -8l293 -870l90 301q69 177 69 293q0 51 -14 107q-18 45 -40 81q-2 3 -15 24t-15.5 25t-13 22t-13 24.5t-10 22t-10 24.5t-6.5 22t-5 25t-1 24q0 63 42 110.5t106 49.5q-121 108 -274.5 168t-321.5 60q-226 0 -421 -105 t-318 -285zM772 165q123 -37 252 -37q152 0 296 51q0 1 -1 1l-1 2l-278 763zM1485 256q199 120 317 324t118 444q0 216 -99 409q4 -44 4 -68q0 -153 -69 -324z" />
+<glyph unicode="&#xf206;" d="M128 486v485q125 -127 330 -127q30 0 59 3q-32 -61 -32 -118q0 -33 13 -63t28.5 -48.5t45.5 -47.5q-18 0 -54.5 -0.5t-55.5 -0.5q-183 0 -334 -83zM128 1599v97q0 93 65.5 158.5t158.5 65.5h1344q93 0 158.5 -65.5t65.5 -158.5v-224h-280v280h-140v-280h-280v-140h280 v-280h140v280h280v-980q0 -93 -65.5 -158.5t-158.5 -65.5h-539q5 28 5 50q0 143 -46.5 230t-189.5 194q-3 2 -20.5 15t-25 19t-25.5 20t-27.5 22.5t-24 22t-23 23.5t-17 22t-12.5 22.5t-4 20.5q0 52 23 87t99 94q180 141 180 324q0 113 -45 204.5t-128 139.5h160l135 142 h-607q-127 0 -241.5 -49t-194.5 -132zM134 301q56 89 166.5 143.5t241.5 53.5q84 -1 158 -26q19 -13 62 -42.5t61 -42t48 -37t44.5 -41.5t29 -41.5t21.5 -49.5q7 -29 7 -66q0 -16 -1 -24h-620q-79 0 -140 49t-78 124zM228 1307q-21 161 50.5 269.5t194.5 104.5 q121 -4 215.5 -118.5t116.5 -277.5q21 -160 -43 -256t-187 -92q-125 4 -225.5 108t-121.5 262z" />
+<glyph unicode="&#xf207;" d="M384 1422q0 -58 40.5 -97.5t105.5 -39.5h1q67 0 108.5 39.5t41.5 97.5q-2 60 -42 98.5t-106 38.5q-67 0 -108 -39t-41 -98zM400 384h263v793h-263v-793zM809 384h264v443q0 45 8 64q16 40 50.5 68t85.5 28q133 0 133 -179v-424h264v455q0 175 -83.5 266t-220.5 91 q-50 0 -90.5 -12t-68.5 -34t-45 -41t-33 -44v112h-264v-793z" />
+<glyph unicode="&#xf208;" d="M128 384v1280q0 106 75 181t181 75h1280q106 0 181 -75t75 -181v-1280q0 -106 -75 -181t-181 -75h-1280q-106 0 -181 75t-75 181zM384 1422q0 -58 40.5 -97.5t105.5 -39.5h1q67 0 108.5 39.5t41.5 97.5q-2 60 -42 98.5t-106 38.5q-67 0 -108 -39t-41 -98zM400 384h263 v793h-263v-793zM809 384h264v443q0 45 8 64q16 40 50.5 68t85.5 28q133 0 133 -179v-424h264v455q0 175 -83.5 266t-220.5 91q-50 0 -90.5 -12t-68.5 -34t-45 -41t-33 -44v112h-264v-793z" />
+<glyph unicode="&#xf209;" d="M171 1260q0 109 35.5 219t110 213t179 182t254 126.5t323.5 47.5q176 0 327.5 -60.5t253.5 -161t160 -231t58 -270.5q0 -246 -85 -443t-241 -309.5t-355 -112.5q-99 0 -186.5 46.5t-121.5 110.5q-73 -290 -89 -347q-34 -123 -127 -270l-149 54q-7 167 22 290l162 688 q-40 81 -40 200q0 139 70.5 232.5t172.5 93.5q83 0 127 -53.5t44 -135.5q0 -51 -18.5 -124t-49 -170t-44.5 -154q-23 -99 37.5 -171t161.5 -72q117 0 209.5 92t142 244.5t49.5 334.5q0 214 -139 349t-387 135q-139 0 -257.5 -49.5t-197 -133t-122.5 -193t-44 -229.5 q0 -147 83 -247q18 -21 21.5 -34t-3.5 -37q-16 -61 -25 -101q-7 -24 -24.5 -32t-39.5 1q-127 51 -192.5 181.5t-65.5 300.5z" />
+<glyph unicode="&#xf210;" d="M0 1024q0 208 81 398t218.5 327t327 218t397.5 81q209 0 398.5 -81t326.5 -218t218 -326.5t81 -398.5t-81 -398.5t-218 -326.5t-326.5 -218t-398.5 -81q-147 0 -290 42q74 116 103 219l72 282q28 -53 99 -90.5t151 -37.5q162 0 288.5 91.5t195.5 251t69 359.5 q0 114 -47 220t-130 187.5t-206.5 130.5t-265.5 49q-141 0 -262 -38.5t-205.5 -103t-145.5 -147.5t-89.5 -172.5t-28.5 -178.5q0 -138 53 -243.5t156 -147.5q18 -8 32.5 -1t18.5 26q2 9 10 41t11 41q5 19 2.5 30t-16.5 28q-68 78 -68 200q0 97 35.5 186t99.5 156.5t160 108 t209 40.5q201 0 313.5 -109.5t112.5 -283.5q0 -148 -40 -271.5t-115 -198t-169 -74.5q-82 0 -131.5 58.5t-30.5 138.5q11 46 35.5 125t39.5 138t15 101q0 66 -35.5 109.5t-102.5 43.5q-82 0 -139.5 -76t-57.5 -189q0 -43 8 -83.5t16 -59.5l9 -19q-113 -475 -132 -558 q-24 -97 -18 -235q-275 120 -444 374t-169 564z" />
+<glyph unicode="&#xf211;" d="M160 1024q0 -172 122 -294t294 -122t294 122t122 294t-122 294t-294 122t-294 -122t-122 -294zM1056 1024q0 -172 122 -294t294 -122t294 122t122 294t-122 294t-294 122t-294 -122t-122 -294z" />
+<glyph unicode="&#xf300;" d="M256 896v384q0 106 75 181t181 75h1024q106 0 181 -75t75 -181v-384q0 -106 -75 -181t-181 -75h-448l-448 -448v448h-128q-106 0 -181 75t-75 181z" />
+<glyph unicode="&#xf301;" d="M384 512v1024h384l64 -128h448v-128h-640l-128 -256h128l64 128h960l-256 -640h-1024z" />
+<glyph unicode="&#xf302;" d="M256 768l768 768h512v-512l-768 -768zM1152 1280q0 -53 37.5 -90.5t90.5 -37.5t90.5 37.5t37.5 90.5t-37.5 90.5t-90.5 37.5t-90.5 -37.5t-37.5 -90.5z" />
+<glyph unicode="&#xf303;" d="M256 1088q0 143 55.5 273.5t150 225t225 150t273.5 55.5t273.5 -55.5t225 -150t150 -225t55.5 -273.5t-55.5 -273.5t-150 -225t-225 -150t-273.5 -55.5t-273.5 55.5t-225 150t-150 225t-55.5 273.5zM384 1088q0 -117 45.5 -223.5t123 -184t184 -123t223.5 -45.5 t223.5 45.5t184 123t123 184t45.5 223.5t-45.5 223.5t-123 184t-184 123t-223.5 45.5t-223.5 -45.5t-184 -123t-123 -184t-45.5 -223.5zM896 1062v474h128v-421l298 -298l-90 -91z" />
+<glyph unicode="&#xf304;" d="M512 384v256q0 159 112.5 271.5t271.5 112.5h256q159 0 271.5 -112.5t112.5 -271.5v-256h-1024zM768 1408q0 106 75 181t181 75t181 -75t75 -181t-75 -181t-181 -75t-181 75t-75 181z" />
+<glyph unicode="&#xf305;" d="M256 384v1280h256v128h128v-128h640v128h128v-128h256v-1280h-1408zM384 640q0 -53 37.5 -90.5t90.5 -37.5h896q53 0 90.5 37.5t37.5 90.5v640q0 53 -37.5 90.5t-90.5 37.5h-896q-53 0 -90.5 -37.5t-37.5 -90.5v-640zM768 1216q0 26 19 45t45 19h128q26 0 45 -19t19 -45 v-512q0 -26 -19 -45t-45 -19t-45 19t-19 45v448h-64q-26 0 -45 19t-19 45z" />
+<glyph unicode="&#xf306;" d="M256 384v1280h256v128h128v-128h640v128h128v-128h256v-1280h-1408zM384 640q0 -53 37.5 -90.5t90.5 -37.5h896q53 0 90.5 37.5t37.5 90.5v640q0 53 -37.5 90.5t-90.5 37.5h-896q-53 0 -90.5 -37.5t-37.5 -90.5v-640zM768 1216q0 26 19 45t45 19h256h2h1h3 q22 -2 38.5 -18t19.5 -39v-2v-2v-1v-2q0 -5 -2 -15l-128 -512q-6 -26 -28.5 -40t-48.5 -7q-26 6 -40 28.5t-7 48.5l108 433h-174q-26 0 -45 19t-19 45z" />
+<glyph unicode="&#xf307;" d="M256 384v1280h256v128h128v-128h640v128h128v-128h256v-1280h-1408zM384 640q0 -53 37.5 -90.5t90.5 -37.5h896q53 0 90.5 37.5t37.5 90.5v640q0 53 -37.5 90.5t-90.5 37.5h-896q-53 0 -90.5 -37.5t-37.5 -90.5v-640zM512 640v128h128v-128h-128zM512 896v128h128v-128 h-128zM768 640v128h128v-128h-128zM768 896v128h128v-128h-128zM768 1152v128h128v-128h-128zM1024 640v128h128v-128h-128zM1024 896v128h128v-128h-128zM1024 1152v128h128v-128h-128zM1280 896v128h128v-128h-128zM1280 1152v128h128v-128h-128z" />
+<glyph unicode="&#xf400;" d="M256 1216q0 117 45.5 223.5t123 184t184 123t223.5 45.5t223.5 -45.5t184 -123t123 -184t45.5 -223.5q0 -184 -111 -337l495 -495l-128 -128l-495 495q-153 -111 -337 -111q-117 0 -223.5 45.5t-184 123t-123 184t-45.5 223.5zM384 1216q0 -185 131.5 -316.5 t316.5 -131.5q186 0 317 131.5t131 316.5t-131 316.5t-317 131.5q-185 0 -316.5 -131.5t-131.5 -316.5z" />
+<glyph unicode="&#xf401;" d="M256 1216q0 117 45.5 223.5t123 184t184 123t223.5 45.5t223.5 -45.5t184 -123t123 -184t45.5 -223.5q0 -184 -111 -337l495 -495l-128 -128l-495 495q-153 -111 -337 -111q-117 0 -223.5 45.5t-184 123t-123 184t-45.5 223.5zM384 1216q0 -185 131.5 -316.5 t316.5 -131.5q186 0 317 131.5t131 316.5t-131 316.5t-317 131.5q-185 0 -316.5 -131.5t-131.5 -316.5zM512 1152v128h640v-128h-640z" />
+<glyph unicode="&#xf402;" d="M256 1216q0 117 45.5 223.5t123 184t184 123t223.5 45.5t223.5 -45.5t184 -123t123 -184t45.5 -223.5q0 -184 -111 -337l495 -495l-128 -128l-495 495q-153 -111 -337 -111q-117 0 -223.5 45.5t-184 123t-123 184t-45.5 223.5zM384 1216q0 -185 131.5 -316.5 t316.5 -131.5q186 0 317 131.5t131 316.5t-131 316.5t-317 131.5q-185 0 -316.5 -131.5t-131.5 -316.5zM512 1152v128h256v256h128v-256h256v-128h-256v-256h-128v256h-256z" />
+<glyph unicode="&#xf403;" d="M0 1024l506 506q101 103 234.5 160.5t283.5 57.5t283.5 -57.5t233.5 -159.5l507 -507l-506 -507q-101 -103 -234.5 -160t-283.5 -57t-283.5 57.5t-233.5 160.5zM272 1024l370 -371q77 -78 175.5 -119.5t206.5 -41.5t206 41.5t174 118.5l373 372l-371 371 q-158 161 -382 161q-108 0 -206.5 -41t-173.5 -119zM640 1024q0 159 112.5 271.5t271.5 112.5t271.5 -112.5t112.5 -271.5t-112.5 -271.5t-271.5 -112.5t-271.5 112.5t-112.5 271.5zM1024 1152q0 -53 37.5 -90.5t90.5 -37.5t90.5 37.5t37.5 90.5t-37.5 90.5t-90.5 37.5 t-90.5 -37.5t-37.5 -90.5z" />
+<glyph unicode="&#xf404;" d="M0 1024l506 506q101 103 234.5 160.5t283.5 57.5q193 0 358 -95l-143 -143q-103 46 -215 46q-108 0 -206.5 -41t-173.5 -119l-372 -372l240 -240l-136 -136zM339 429l90 -90l1280 1280l-90 90zM640 1024q0 159 112.5 271.5t271.5 112.5q44 0 98 -14l-468 -468 q-14 54 -14 98zM666 395l143 143q103 -46 215 -46q108 0 206 41.5t174 118.5l373 372l-241 241l136 135l376 -376l-506 -507q-101 -103 -234.5 -160t-283.5 -57q-193 0 -358 95zM926 654l468 468q14 -54 14 -98q0 -159 -112.5 -271.5t-271.5 -112.5q-44 0 -98 14z" />
+<glyph unicode="&#xf405;" d="M640 768l320 320l-320 320l128 128l320 -320l320 320l128 -128l-320 -320l320 -320l-128 -128l-320 320l-320 -320z" />
+<glyph unicode="&#xf406;" d="M128 256l832 832l-832 832l128 128l832 -832l832 832l128 -128l-832 -832l832 -832l-128 -128l-832 832l-832 -832z" />
+<glyph unicode="&#xf407;" d="M384 1280q0 106 75 181t181 75h140q20 56 69.5 92t110.5 36q62 0 111 -35.5t69 -92.5h140q106 0 181 -75t75 -181h-128v-768q0 -53 -37.5 -90.5t-90.5 -37.5h-640q-53 0 -90.5 37.5t-37.5 90.5v768h-128zM640 576q0 -26 19 -45t45 -19t45 19t19 45v640q0 26 -19 45 t-45 19t-45 -19t-19 -45v-640zM896 576q0 -26 19 -45t45 -19t45 19t19 45v640q0 26 -19 45t-45 19t-45 -19t-19 -45v-640zM1152 576q0 -26 19 -45t45 -19t45 19t19 45v640q0 26 -19 45t-45 19t-45 -19t-19 -45v-640z" />
+<glyph unicode="&#xf408;" d="M256 1151l476 -330l-183 -535l475 332l475 -332l-183 535l476 329h-587l-181 535l-180 -534h-588z" />
+<glyph unicode="&#xf409;" d="M384 1024l640 640l640 -640l-128 -128l-512 512l-512 -512zM640 512v384l384 384l384 -384v-384h-256v384h-256v-384h-256z" />
+<glyph unicode="&#xf410;" d="M0 384l640 640l384 -384l384 384l640 -640h-2048zM0 512v1152l576 -576zM0 1792h2048l-1024 -1024zM1472 1088l576 576v-1152z" />
+<glyph unicode="&#xf411;" d="M384 384v448l896 896l448 -448l-896 -896h-448zM512 768l256 -256l128 128l-256 256zM685 941l96 -96l595 595l-96 96zM845 781l96 -96l595 595l-96 96z" />
+<glyph unicode="&#xf412;" d="M256 640v704l384 384v-704h640v448l640 -640l-640 -640v448h-1024z" />
+<glyph unicode="&#xf413;" d="M128 384q0 106 75 181t181 75t181 -75t75 -181t-75 -181t-181 -75t-181 75t-75 181zM128 971v345q240 0 459 -94t377.5 -253.5t252.5 -379.5t94 -461h-345q0 170 -63.5 324t-181.5 273q-119 119 -272 182.5t-321 63.5zM129 1582v345q243 0 475 -64.5t428.5 -181 t362 -282.5t281 -363.5t180 -430.5t64.5 -477h-345q0 197 -52 385.5t-145.5 348t-227 294t-292 228t-346 146t-383.5 52.5z" />
+<glyph unicode="&#xf414;" d="M21 230q-57 102 31 244l760 1237q57 93 134.5 126.5t155 0t135.5 -126.5l759 -1237q88 -142 31 -244t-224 -102h-1557q-168 0 -225 102zM896 512q0 -53 37.5 -90.5t90.5 -37.5t90.5 37.5t37.5 90.5t-37.5 90.5t-90.5 37.5t-90.5 -37.5t-37.5 -90.5zM896 896 q0 -53 37.5 -90.5t90.5 -37.5t90.5 37.5t37.5 90.5v384q0 53 -37.5 90.5t-90.5 37.5t-90.5 -37.5t-37.5 -90.5v-384z" />
+<glyph unicode="&#xf415;" d="M128 1024h400q45 0 79.5 27.5t44.5 69.5q33 125 136.5 206t235.5 81q154 0 270 -114q38 -38 90.5 -38t90.5 38q37 38 37 91t-37 90q-88 89 -204.5 139t-246.5 50q-194 0 -353 -106t-234 -278h-309v-256zM536 663q0 -53 37 -90q89 -89 205 -139t246 -50q194 0 353 106 t234 278h309v256h-400q-45 0 -79.5 -27.5t-44.5 -69.5q-33 -125 -136.5 -206t-235.5 -81q-156 0 -269 115q-38 37 -91 37t-91 -38q-37 -38 -37 -91zM768 1024q0 -106 75 -181t181 -75t181 75t75 181t-75 181t-181 75t-181 -75t-75 -181z" />
+<glyph unicode="&#xf416;" d="M512 832v320h128v-320q0 -133 93.5 -226.5t226.5 -93.5t226.5 93.5t93.5 226.5v640q0 80 -56 136t-136 56t-136 -56t-56 -136v-512q0 -26 19 -45t45 -19t45 19t19 45v452h128v-452q0 -80 -56 -136t-136 -56t-136 56t-56 136v512q0 133 93.5 226.5t226.5 93.5t226.5 -93.5 t93.5 -226.5v-640q0 -185 -131.5 -316.5t-316.5 -131.5t-316.5 131.5t-131.5 316.5z" />
+<glyph unicode="&#xf417;" d="M384 1216q0 117 45.5 223.5t123 184t184 123t223.5 45.5t223.5 -45.5t184 -123t123 -184t45.5 -223.5t-44.5 -222.5t-124.5 -185.5l-407 -406l-407 406q-80 80 -124.5 185.5t-44.5 222.5zM640 1216q0 -133 93.5 -226.5t226.5 -93.5t226.5 93.5t93.5 226.5t-93.5 226.5 t-226.5 93.5t-226.5 -93.5t-93.5 -226.5z" />
+<glyph unicode="&#xf418;" d="M608 1056l128 128l224 -192l448 512l128 -96l-512 -768h-128z" />
+<glyph unicode="&#xf419;" d="M0 256v256h2048v-256h-2048zM0 896v256h2048v-256h-2048zM0 1536v256h2048v-256h-2048z" />
+<glyph unicode="&#xf420;" d="M384 512l640 640l640 -640h-1280zM384 1280v128h1280v-128h-1280z" />
+<glyph unicode="&#xf421;" d="M384 896v256h1152v-256h-1152z" />
+<glyph unicode="&#xf422;" d="M384 512v1024h1152v-1024h-1152zM512 640h896v640h-896v-640z" />
+<glyph unicode="&#xf500;" d="M128 0l960 960l960 -960h-1920z" />
+<glyph unicode="&#xf501;" d="M0 128l960 960l-960 960v-1920z" />
+<glyph unicode="&#xf502;" d="M128 2048l960 -960l960 960h-1920z" />
+<glyph unicode="&#xf503;" d="M1088 1088l960 960v-1920z" />
+</font>
+</defs></svg> \ No newline at end of file
diff --git a/plugins/jetpack/modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.ttf b/plugins/jetpack/modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.ttf
new file mode 100644
index 00000000..45228d9e
--- /dev/null
+++ b/plugins/jetpack/modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.ttf
Binary files differ
diff --git a/plugins/jetpack/modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.woff b/plugins/jetpack/modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.woff
new file mode 100644
index 00000000..a64be4b1
--- /dev/null
+++ b/plugins/jetpack/modules/minileven/theme/pub/minileven/inc/fonts/genericons-regular-webfont.woff
Binary files differ
diff --git a/plugins/jetpack/modules/omnisearch.php b/plugins/jetpack/modules/omnisearch.php
new file mode 100644
index 00000000..a5db2a5d
--- /dev/null
+++ b/plugins/jetpack/modules/omnisearch.php
@@ -0,0 +1,14 @@
+<?php
+
+/**
+ * Module Name: Omnisearch
+ * Module Description: A single search box, that lets you search many different things.
+ * Sort Order: 8
+ * First Introduced: 2.3
+ * Requires Connection: No
+ */
+
+// Only do Jetpack Omnisearch if there isn't already a Core WP_Omnisearch Class.
+if ( ! class_exists( 'WP_Omnisearch' ) )
+ require_once( dirname( __FILE__ ) . '/omnisearch/omnisearch-core.php' );
+
diff --git a/plugins/jetpack/modules/omnisearch/omnisearch-comments.php b/plugins/jetpack/modules/omnisearch/omnisearch-comments.php
new file mode 100644
index 00000000..7f770ef6
--- /dev/null
+++ b/plugins/jetpack/modules/omnisearch/omnisearch-comments.php
@@ -0,0 +1,48 @@
+<?php
+
+if( ! class_exists( 'WP_Comments_List_Table' ) )
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-comments-list-table.php' );
+
+class Jetpack_Omnisearch_Comments extends WP_Comments_List_Table {
+ static $instance;
+ var $checkbox = false;
+
+ function __construct() {
+ self::$instance = $this;
+ add_filter( 'omnisearch_results', array( $this, 'search'), 10, 2 );
+ }
+
+ function search( $results, $search_term ) {
+ $search_url = esc_url( admin_url( sprintf( 'edit-comments.php?s=%s', urlencode( $search_term ) ) ) );
+ $search_link = sprintf( ' <a href="%s" class="add-new-h2">%s</a>', $search_url, esc_html__('Search Comments', 'jetpack') );
+ $html = '<h2>' . esc_html__('Comments', 'jetpack') . $search_link . '</h2>';
+ parent::__construct();
+
+ ob_start();
+ $this->prepare_items();
+ $this->_column_headers = array( $this->get_columns(), array(), array() );
+ $this->display();
+ $html .= ob_get_clean();
+
+ $label = __( 'Comments', 'jetpack' );
+ $results[ $label ] = $html;
+ return $results;
+ }
+
+ function get_per_page( $comment_status = 'all' ) {
+ return apply_filters( 'omnisearch_num_results', 5 );
+ }
+
+ function get_sortable_columns() {
+ return array();
+ }
+
+ function get_bulk_actions() {
+ return array();
+ }
+
+ function pagination( $which ) {}
+
+ function extra_tablenav( $which ) {}
+}
+
diff --git a/plugins/jetpack/modules/omnisearch/omnisearch-core.php b/plugins/jetpack/modules/omnisearch/omnisearch-core.php
new file mode 100644
index 00000000..1b19a466
--- /dev/null
+++ b/plugins/jetpack/modules/omnisearch/omnisearch-core.php
@@ -0,0 +1,181 @@
+<?php
+
+// Include this here so that other plugins can extend it if they like.
+require_once( dirname(__FILE__) . '/omnisearch-posts.php' );
+
+class Jetpack_Omnisearch {
+ static $instance;
+ static $num_results = 5;
+
+ function __construct() {
+ self::$instance = $this;
+ add_action( 'wp_loaded', array( $this, 'wp_loaded' ) );
+ add_action( 'admin_init', array( $this, 'add_providers' ) );
+ add_action( 'jetpack_admin_menu', array( $this, 'jetpack_admin_menu' ) );
+ add_action( 'admin_menu', array( $this, 'admin_menu' ), 20 );
+ if( ! jetpack_is_mobile() ) {
+ add_action( 'admin_bar_menu', array( $this, 'admin_bar_search' ), 4 );
+ }
+ add_filter( 'omnisearch_num_results', array( $this, 'omnisearch_num_results' ) );
+ }
+
+ static function add_providers() {
+ // omnisearch-posts.php is included above, so that other plugins can more easily extend it.
+ new Jetpack_Omnisearch_Posts;
+ new Jetpack_Omnisearch_Posts( 'page' );
+
+ require_once( dirname(__FILE__) . '/omnisearch-comments.php' );
+ new Jetpack_Omnisearch_Comments;
+
+ if ( current_user_can( 'install_plugins' ) ) {
+ require_once( dirname(__FILE__) . '/omnisearch-plugins.php' );
+ new Jetpack_Omnisearch_Plugins;
+ }
+
+ do_action( 'omnisearch_add_providers' );
+ }
+
+ static function omnisearch_num_results( $num ) {
+ return self::$num_results;
+ }
+
+ function wp_loaded() {
+ $deps = null;
+ if ( wp_style_is( 'genericons', 'registered' ) ) {
+ $deps = array( 'genericons' );
+ }
+
+ wp_register_style( 'omnisearch-admin', plugins_url( 'omnisearch.css', __FILE__ ), $deps );
+ wp_register_style( 'omnisearch-jetpack', plugins_url( 'omnisearch-jetpack.css', __FILE__ ) );
+ }
+
+ function jetpack_admin_menu() {
+ remove_submenu_page( 'index.php', 'omnisearch' );
+ $this->slug = add_submenu_page( 'jetpack', __('Omnisearch', 'jetpack'), __('Omnisearch', 'jetpack'), 'edit_posts', 'omnisearch', array( $this, 'omnisearch_page' ) );
+ add_action( "admin_print_styles-{$this->slug}", array( $this, 'admin_print_styles_jetpack' ) );
+ }
+
+ function admin_menu() {
+ $this->slug = add_dashboard_page( __('Omnisearch', 'jetpack'), __('Omnisearch', 'jetpack'), 'edit_posts', 'omnisearch', array( $this, 'omnisearch_page' ) );
+ add_action( "admin_print_styles-{$this->slug}", array( $this, 'admin_print_styles' ) );
+ }
+
+ function admin_print_styles() {
+ wp_enqueue_style( 'omnisearch-admin' );
+ }
+
+ function admin_print_styles_jetpack() {
+ wp_enqueue_style( 'omnisearch-admin' );
+ wp_enqueue_style( 'omnisearch-jetpack' );
+ }
+
+ function omnisearch_page() {
+ $results = array();
+ $s = isset( $_GET['s'] ) ? $_GET['s'] : '';
+ if( $s ) {
+ $results = apply_filters( 'omnisearch_results', $results, $s );
+ }
+ ?>
+ <div class="wrap">
+ <h2 class="page-title"><?php esc_html_e('Omnisearch', 'jetpack'); ?> <small><?php esc_html_e('search everything', 'jetpack'); ?></small></h2>
+ <br class="clear" />
+ <?php echo self::get_omnisearch_form( array(
+ 'form_class' => 'omnisearch-form',
+ 'search_class' => 'omnisearch',
+ 'search_placeholder' => '',
+ 'submit_class' => 'omnisearch-submit',
+ 'alternate_submit' => true,
+ ) ); ?>
+ <?php if( ! empty( $results ) ): ?>
+ <h3 id="results-title"><?php esc_html_e('Results:', 'jetpack'); ?></h3>
+ <div class="jump-to"><strong><?php esc_html_e('Jump to:', 'jetpack'); ?></strong>
+ <?php foreach( $results as $label => $result ) : ?>
+ <a href="#result-<?php echo sanitize_title( $label ); ?>"><?php echo esc_html( $label ); ?></a>
+ <?php endforeach; ?>
+ </div>
+ <br class="clear" />
+ <script>var search_term = '<?php echo esc_js( $s ); ?>', num_results = <?php echo intval( apply_filters( 'omnisearch_num_results', 5 ) ); ?>;</script>
+ <ul class="omnisearch-results">
+ <?php foreach( $results as $label => $result ) : ?>
+ <li id="result-<?php echo sanitize_title( $label ); ?>" data-label="<?php echo esc_attr( $label ); ?>">
+ <?php echo $result; ?>
+ <a class="back-to-top" href="#results-title"><?php esc_html_e('Back to Top &uarr;', 'jetpack'); ?></a>
+ </li>
+ <?php endforeach; ?>
+ </ul>
+ <?php endif; ?>
+ </div><!-- /wrap -->
+ <?php
+ }
+
+ function admin_bar_search( $wp_admin_bar ) {
+ if( ! is_admin() || ! current_user_can( 'edit_posts' ) )
+ return;
+
+ $form = self::get_omnisearch_form( array(
+ 'form_id' => 'adminbarsearch',
+ 'search_id' => 'adminbar-search',
+ 'search_class' => 'adminbar-input',
+ 'submit_class' => 'adminbar-button',
+ ) );
+
+ $form .= "<style>
+ #adminbar-search::-webkit-input-placeholder,
+ #adminbar-search:-moz-placeholder,
+ #adminbar-search::-moz-placeholder,
+ #adminbar-search:-ms-input-placeholder {
+ text-shadow: none;
+ }
+ </style>";
+
+ $wp_admin_bar->add_menu( array(
+ 'parent' => 'top-secondary',
+ 'id' => 'search',
+ 'title' => $form,
+ 'meta' => array(
+ 'class' => 'admin-bar-search',
+ 'tabindex' => -1,
+ )
+ ) );
+ }
+
+ static function get_omnisearch_form( $args = array() ) {
+ $defaults = array(
+ 'form_id' => null,
+ 'form_class' => null,
+ 'search_class' => null,
+ 'search_id' => null,
+ 'search_value' => isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : null,
+ 'search_placeholder' => __( 'Search Everything', 'jetpack' ),
+ 'submit_class' => 'button',
+ 'submit_value' => __( 'Search', 'jetpack' ),
+ 'alternate_submit' => false,
+ );
+ extract( array_map( 'esc_attr', wp_parse_args( $args, $defaults ) ) );
+
+ $rand = rand();
+ if( empty( $form_id ) )
+ $form_id = "omnisearch_form_$rand";
+ if( empty( $search_id ) )
+ $search_id = "omnisearch_search_$rand";
+
+ ob_start();
+ ?>
+
+ <form action="<?php echo esc_url( admin_url( 'admin.php' ) ); ?>" method="get" class="<?php echo $form_class; ?>" id="<?php echo $form_id; ?>">
+ <input type="hidden" name="page" value="omnisearch" />
+ <input name="s" type="search" class="<?php echo $search_class; ?>" id="<?php echo $search_id; ?>" value="<?php echo $search_value; ?>" placeholder="<?php echo $search_placeholder; ?>" />
+ <?php if ( $alternate_submit ) : ?>
+ <button type="submit" class="<?php echo $submit_class; ?>"><span><?php echo $submit_value; ?></span></button>
+ <?php else : ?>
+ <input type="submit" class="<?php echo $submit_class; ?>" value="<?php echo $submit_value; ?>" />
+ <?php endif; ?>
+ </form>
+
+ <?php
+ return apply_filters( 'get_omnisearch_form', ob_get_clean(), $args, $defaults );
+ }
+
+}
+new Jetpack_Omnisearch;
+
diff --git a/plugins/jetpack/modules/omnisearch/omnisearch-jetpack.css b/plugins/jetpack/modules/omnisearch/omnisearch-jetpack.css
new file mode 100644
index 00000000..d100c403
--- /dev/null
+++ b/plugins/jetpack/modules/omnisearch/omnisearch-jetpack.css
@@ -0,0 +1,35 @@
+
+.wp-admin #wpwrap {
+ background: url('../../_inc/images/header-clouds.png') 200% 0 repeat-x;
+}
+
+@media print,
+ (-o-min-device-pixel-ratio: 5/4),
+ (-webkit-min-device-pixel-ratio: 1.25),
+ (min-resolution: 120dpi) {
+ #wpwrap {
+ background: url('../../_inc/images/header-clouds-2x.png') 0 0 repeat-x;
+ background-size: 1600px 400px;
+ }
+}
+
+ul#adminmenu a.wp-has-current-submenu:after,
+ul#adminmenu > li.current > a.current:after {
+ border-right-color:#8da94c;
+ display: none;
+}
+
+h2.page-title {
+ color: #fff;
+ text-shadow: 0 1px 1px rgba(0,0,0,0.5);
+}
+
+#results-title,
+.jump-to {
+ color: #fff;
+ text-shadow: 0 1px 1px rgba(0,0,0,0.5);
+}
+
+.omnisearch-results > li:first-child > h2 {
+ text-shadow: none;
+}
diff --git a/plugins/jetpack/modules/omnisearch/omnisearch-plugins.php b/plugins/jetpack/modules/omnisearch/omnisearch-plugins.php
new file mode 100644
index 00000000..76df6081
--- /dev/null
+++ b/plugins/jetpack/modules/omnisearch/omnisearch-plugins.php
@@ -0,0 +1,61 @@
+<?php
+
+if( ! class_exists( 'WP_Plugin_Install_List_Table' ) )
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-plugin-install-list-table.php' );
+
+class Jetpack_Omnisearch_Plugins extends WP_Plugin_Install_List_Table {
+ static $instance;
+
+ function __construct() {
+ self::$instance = $this;
+ add_filter( 'omnisearch_results', array( $this, 'search'), 10, 2 );
+ add_action( 'wp_ajax_omnisearch_plugins', array( $this, 'wp_ajax_omnisearch_plugins' ) );
+ }
+
+ function search( $results, $search_term ) {
+ wp_enqueue_script( 'plugin-install' );
+ add_thickbox();
+
+ $search_url = esc_url( admin_url( sprintf( 'plugin-install.php?tab=search&s=%s', urlencode( $search_term ) ) ) );
+ $search_link = sprintf( ' <a href="%s" class="add-new-h2">%s</a>', $search_url, esc_html__('Search Plugins', 'jetpack') );
+ $html = '<h2>' . esc_html__('Plugins', 'jetpack') . $search_link . '</h2>';
+
+ $html .= '<div id="' . __CLASS__ . '_results">' . esc_html__('Loading &hellip;', 'jetpack') . '</div>';
+ $html .= '<script>jQuery("#' . __CLASS__ . '_results").load(ajaxurl,{action:"omnisearch_plugins",search_term:search_term,num_results:num_results});</script>';
+
+ $label = __( 'Plugins', 'jetpack' );
+ $results[ $label ] = $html;
+ return $results;
+ }
+
+ function results_html( $search_term, $num_results = null ) {
+ $_GET['tab'] = 'search';
+ $GLOBALS['hook_suffix'] = 'foo';
+ $_REQUEST['s'] = $search_term;
+ parent::__construct();
+
+ ob_start();
+ $this->prepare_items();
+ $num_results = intval( $num_results ) ? intval( $num_results ) : apply_filters( 'omnisearch_num_results', 5 );
+ $this->items = array_slice( $this->items, 0, $num_results );
+ remove_action( 'install_plugins_table_header', 'install_search_form' );
+ $this->display();
+ $html = ob_get_clean();
+
+ return $html;
+ }
+
+ function wp_ajax_omnisearch_plugins() {
+ $search_term = $_REQUEST['search_term'];
+ $num_results = isset( $_REQUEST['num_results'] ) ? $_REQUEST['num_results'] : null;
+ echo $this->results_html( $search_term, $num_results );
+ exit;
+ }
+
+ function get_bulk_actions() {
+ return array();
+ }
+
+ function pagination( $which ) {}
+}
+
diff --git a/plugins/jetpack/modules/omnisearch/omnisearch-posts.php b/plugins/jetpack/modules/omnisearch/omnisearch-posts.php
new file mode 100644
index 00000000..61b3347d
--- /dev/null
+++ b/plugins/jetpack/modules/omnisearch/omnisearch-posts.php
@@ -0,0 +1,122 @@
+<?php
+
+if( ! class_exists( 'WP_List_Table' ) )
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
+
+class Jetpack_Omnisearch_Posts extends WP_List_Table {
+ var $post_type = 'post',
+ $post_type_object;
+
+ function __construct( $post_type = 'post' ) {
+ $this->post_type = $post_type;
+ add_filter( 'omnisearch_results', array( $this, 'search'), 10, 2 );
+ }
+
+ function search( $results, $search_term ) {
+ if( ! post_type_exists( $this->post_type ) )
+ return $results;
+
+ parent::__construct();
+
+ $this->post_type_obj = get_post_type_object( $this->post_type );
+
+ $search_url = esc_url( admin_url( sprintf( 'edit.php?post_type=%s&s=%s', urlencode( $this->post_type_obj->name ), urlencode( $search_term ) ) ) );
+ $search_link = sprintf( ' <a href="%s" class="add-new-h2">%s</a>', $search_url, esc_html( $this->post_type_obj->labels->search_items ) );
+ $html = '<h2>' . esc_html( $this->post_type_obj->labels->name ) . $search_link .'</h2>';
+
+ $num_results = apply_filters( 'omnisearch_num_results', 5 );
+
+ $this->posts = get_posts( array( 's' => $search_term, 'post_type' => $this->post_type, 'posts_per_page' => $num_results, 'post_status' => 'any' ) );
+
+ $this->prepare_items();
+
+ ob_start();
+ $this->display();
+ $html .= ob_get_clean();
+
+ $results[ $this->post_type_obj->labels->name ] = $html;
+ return $results;
+ }
+
+ function get_columns() {
+ $columns = array(
+ # 'id' => __('ID', 'jetpack'),
+ 'post_title' => __('Title', 'jetpack'),
+ 'snippet' => __('Snippet', 'jetpack'),
+ 'date' => __('Date', 'jetpack'),
+ );
+ return $columns;
+ }
+
+ function prepare_items() {
+ $columns = $this->get_columns();
+ $hidden = array();
+ $sortable = array();
+ $this->_column_headers = array( $columns, $hidden, $sortable );
+ $this->items = $this->posts;
+ }
+
+ function column_post_title( $post ) {
+ $actions = array();
+ if ( current_user_can( $this->post_type_obj->cap->edit_post, $post ) ) {
+ $actions['edit'] = sprintf( '<a href="%s">%s</a>', esc_url( get_edit_post_link( $post->ID ) ), esc_html( $this->post_type_obj->labels->edit_item ) );
+ }
+ if ( current_user_can( $this->post_type_obj->cap->delete_post, $post ) ) {
+ $actions['delete'] = sprintf( '<a href="%s">%s</a>', esc_url( get_delete_post_link( $post->ID ) ), esc_html__('Trash', 'jetpack') );
+ }
+ $actions['view'] = sprintf( '<a href="%s">%s</a>', esc_url( get_permalink( $post->ID ) ), esc_html( $this->post_type_obj->labels->view_item ) );
+ return wptexturize( $post->post_title ) . $this->row_actions( $actions );
+ }
+
+ function column_date( $post ) {
+ $html = '';
+
+ if ( '0000-00-00 00:00:00' == $post->post_date ) {
+ $t_time = $h_time = __('Unpublished', 'jetpack');
+ $time_diff = 0;
+ } else {
+ $t_time = date( __('Y/m/d g:i:s A', 'jetpack'), mysql2date( 'G', $post->post_date ) );
+ $m_time = $post->post_date;
+ $time = get_post_time( 'G', true, $post );
+
+ $time_diff = time() - $time;
+
+ if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS )
+ $h_time = sprintf( __('%s ago', 'jetpack'), human_time_diff( $time ) );
+ else
+ $h_time = mysql2date( __('Y/m/d', 'jetpack'), $m_time );
+ }
+
+ $html .= '<abbr title="' . esc_attr( $t_time ) . '">' . esc_html( $h_time ) . '</abbr>';
+ $html .= '<br />';
+ if ( 'publish' == $post->post_status ) {
+ $html .= esc_html__('Published', 'jetpack');
+ } elseif ( 'future' == $post->post_status ) {
+ if ( $time_diff > 0 )
+ $html .= '<strong class="attention">' . esc_html__('Missed schedule', 'jetpack') . '</strong>';
+ else
+ $html .= esc_html__('Scheduled', 'jetpack');
+ } else {
+ $html .= esc_html__('Last Modified', 'jetpack');
+ }
+ return $html;
+ }
+
+ function column_default( $post, $column_name ) {
+ switch ( $column_name ) {
+ case 'id':
+ return $post->ID;
+ case 'post_title': // Will never happen, class method overrides.
+ return $post->post_title;
+ case 'snippet':
+ return wp_trim_words( $post->post_content, 55 );
+ case 'date': // Will never happen, class method overrides.
+ $d = get_option('date_format');
+ $t = get_option('time_format');
+ return get_post_modified_time( $d, 0, $post, 1 ) . ' @ ' . get_post_modified_time( $t, 0, $post, 1 );
+ default:
+ return print_r( $post, true );
+ }
+ }
+}
+
diff --git a/plugins/jetpack/modules/omnisearch/omnisearch.css b/plugins/jetpack/modules/omnisearch/omnisearch.css
new file mode 100644
index 00000000..f0265b70
--- /dev/null
+++ b/plugins/jetpack/modules/omnisearch/omnisearch.css
@@ -0,0 +1,126 @@
+
+h2.page-title small {
+ font-size: 0.6em;
+ font-weight: 300;
+ font-style: italic;
+ opacity: 0.6;
+ margin-left: 0.5em;
+}
+
+form.omnisearch-form {
+ position: relative;
+}
+
+input.omnisearch {
+ border-radius: 0.25em;
+ font-size: 2.2em;
+ line-height: 1.25;
+ padding: 0.25em 2em 0.25em 0.5em;
+ width: 100%;
+}
+
+.admin-color-mp6 input.omnisearch {
+ line-height: 1.35;
+}
+
+input.omnisearch::-webkit-search-cancel-button {
+ display: none;
+}
+
+button.omnisearch-submit {
+ background: transparent;
+ border: 0;
+ cursor: pointer;
+ display: block;
+ font-size: 2.45em;
+ padding: 0.25em 0.5em 0;
+ text-align: center;
+ position: absolute;
+ right: 0;
+ bottom: 0;
+}
+
+.admin-color-mp6 button.omnisearch-submit {
+ padding: 0.3em 0.5em 0.1em;
+}
+
+button.omnisearch-submit::before {
+ font-family: 'Genericons', Noticons;
+ content: '\f400';
+}
+
+button.omnisearch-submit span {
+ display: none;
+}
+
+#results-title,
+.jump-to {
+ font-size: 1.2em;
+ line-height: 1.5;
+ float: left;
+ margin-top: 0;
+ padding-top: 2em;
+}
+
+#results-title,
+.jump-to strong {
+ font-weight: 600;
+}
+
+.jump-to {
+ float: right;
+ text-align: right;
+}
+
+.jump-to strong,
+.jump-to a {
+ color: inherit;
+ margin-left: 0.5em;
+ text-decoration: none;
+}
+
+.jump-to a:hover {
+ text-decoration: underline;
+}
+
+.back-to-top {
+ display: block;
+ float: right;
+ margin-top: 2.5em;
+}
+
+.omnisearch-results {
+
+}
+
+.omnisearch-results > li {
+ padding-top: 2.5em;
+}
+
+.omnisearch-results > li:first-child {
+ padding-top: 0;
+}
+
+.omnisearch-results .add-new-h2 {
+ display: inline;
+}
+
+.wp-list-table .column-snippet {
+ width: 65%;
+}
+
+.wp-list-table .column-date {
+ width: 15%;
+}
+
+.comments .column-author {
+ width: 20%;
+}
+
+.tablenav {
+ height: 0;
+}
+
+.omnisearch-results .tablenav.top {
+ margin: 5px 0;
+}
diff --git a/plugins/jetpack/modules/omnisearch/rtl/omnisearch-jetpack-rtl.css b/plugins/jetpack/modules/omnisearch/rtl/omnisearch-jetpack-rtl.css
new file mode 100644
index 00000000..7ddf1404
--- /dev/null
+++ b/plugins/jetpack/modules/omnisearch/rtl/omnisearch-jetpack-rtl.css
@@ -0,0 +1,37 @@
+/* This file was automatically generated on Jun 19 2013 20:14:22 */
+
+
+.wp-admin #wpwrap {
+ background: url('../../../_inc/images/header-clouds.png') -100% 0 repeat-x;
+}
+
+@media print,
+ (-o-min-device-pixel-ratio: 5/4),
+ (-webkit-min-device-pixel-ratio: 1.25),
+ (min-resolution: 120dpi) {
+ #wpwrap {
+ background: url('../../../_inc/images/header-clouds-2x.png') 0 0 repeat-x;
+ background-size: 1600px 400px;
+ }
+}
+
+ul#adminmenu a.wp-has-current-submenu:after,
+ul#adminmenu > li.current > a.current:after {
+ border-left-color:#8da94c;
+ display: none;
+}
+
+h2.page-title {
+ color: #fff;
+ text-shadow: 0 1px 1px rgba(0,0,0,0.5);
+}
+
+#results-title,
+.jump-to {
+ color: #fff;
+ text-shadow: 0 1px 1px rgba(0,0,0,0.5);
+}
+
+.omnisearch-results > li:first-child > h2 {
+ text-shadow: none;
+}
diff --git a/plugins/jetpack/modules/omnisearch/rtl/omnisearch-rtl.css b/plugins/jetpack/modules/omnisearch/rtl/omnisearch-rtl.css
new file mode 100644
index 00000000..2a5de7e1
--- /dev/null
+++ b/plugins/jetpack/modules/omnisearch/rtl/omnisearch-rtl.css
@@ -0,0 +1,128 @@
+/* This file was automatically generated on Jun 19 2013 20:38:31 */
+
+
+h2.page-title small {
+ font-size: 0.6em;
+ font-weight: 300;
+ font-style: italic;
+ opacity: 0.6;
+ margin-right: 0.5em;
+}
+
+form.omnisearch-form {
+ position: relative;
+}
+
+input.omnisearch {
+ border-radius: 0.25em;
+ font-size: 2.2em;
+ line-height: 1.25;
+ padding: 0.25em 0.5em 0.25em 2em;
+ width: 100%;
+}
+
+.admin-color-mp6 input.omnisearch {
+ line-height: 1.35;
+}
+
+input.omnisearch::-webkit-search-cancel-button {
+ display: none;
+}
+
+button.omnisearch-submit {
+ background: transparent;
+ border: 0;
+ cursor: pointer;
+ display: block;
+ font-size: 2.45em;
+ padding: 0.25em 0.5em 0;
+ text-align: center;
+ position: absolute;
+ left: 0;
+ bottom: 0;
+}
+
+.admin-color-mp6 button.omnisearch-submit {
+ padding: 0.3em 0.5em 0.1em;
+}
+
+button.omnisearch-submit::before {
+ font-family: 'Genericons', Noticons;
+ content: '\f400';
+}
+
+button.omnisearch-submit span {
+ display: none;
+}
+
+#results-title,
+.jump-to {
+ font-size: 1.2em;
+ line-height: 1.5;
+ float: right;
+ margin-top: 0;
+ padding-top: 2em;
+}
+
+#results-title,
+.jump-to strong {
+ font-weight: 600;
+}
+
+.jump-to {
+ float: left;
+ text-align: left;
+}
+
+.jump-to strong,
+.jump-to a {
+ color: inherit;
+ margin-right: 0.5em;
+ text-decoration: none;
+}
+
+.jump-to a:hover {
+ text-decoration: underline;
+}
+
+.back-to-top {
+ display: block;
+ float: left;
+ margin-top: 2.5em;
+}
+
+.omnisearch-results {
+
+}
+
+.omnisearch-results > li {
+ padding-top: 2.5em;
+}
+
+.omnisearch-results > li:first-child {
+ padding-top: 0;
+}
+
+.omnisearch-results .add-new-h2 {
+ display: inline;
+}
+
+.wp-list-table .column-snippet {
+ width: 65%;
+}
+
+.wp-list-table .column-date {
+ width: 15%;
+}
+
+.comments .column-author {
+ width: 20%;
+}
+
+.tablenav {
+ height: 0;
+}
+
+.omnisearch-results .tablenav.top {
+ margin: 5px 0;
+}
diff --git a/plugins/jetpack/modules/sharedaddy/images/kindle.png b/plugins/jetpack/modules/sharedaddy/images/kindle.png
new file mode 100644
index 00000000..4756d459
--- /dev/null
+++ b/plugins/jetpack/modules/sharedaddy/images/kindle.png
Binary files differ
diff --git a/plugins/jetpack/modules/sharedaddy/images/kindle@2x.png b/plugins/jetpack/modules/sharedaddy/images/kindle@2x.png
new file mode 100644
index 00000000..66fa00f8
--- /dev/null
+++ b/plugins/jetpack/modules/sharedaddy/images/kindle@2x.png
Binary files differ
diff --git a/plugins/jetpack/modules/sharedaddy/images/pocket.png b/plugins/jetpack/modules/sharedaddy/images/pocket.png
new file mode 100644
index 00000000..e6e11849
--- /dev/null
+++ b/plugins/jetpack/modules/sharedaddy/images/pocket.png
Binary files differ
diff --git a/plugins/jetpack/modules/sharedaddy/images/pocket@2x.png b/plugins/jetpack/modules/sharedaddy/images/pocket@2x.png
new file mode 100644
index 00000000..72fdbfe3
--- /dev/null
+++ b/plugins/jetpack/modules/sharedaddy/images/pocket@2x.png
Binary files differ
diff --git a/plugins/jetpack/modules/sharedaddy/images/smart-pocket.png b/plugins/jetpack/modules/sharedaddy/images/smart-pocket.png
new file mode 100644
index 00000000..69721f79
--- /dev/null
+++ b/plugins/jetpack/modules/sharedaddy/images/smart-pocket.png
Binary files differ
diff --git a/plugins/jetpack/modules/sharedaddy/images/smart-pocket@2x.png b/plugins/jetpack/modules/sharedaddy/images/smart-pocket@2x.png
new file mode 100644
index 00000000..9257926b
--- /dev/null
+++ b/plugins/jetpack/modules/sharedaddy/images/smart-pocket@2x.png
Binary files differ
diff --git a/plugins/jetpack/modules/shortcodes/bandcamp.php b/plugins/jetpack/modules/shortcodes/bandcamp.php
new file mode 100644
index 00000000..cfaedb9c
--- /dev/null
+++ b/plugins/jetpack/modules/shortcodes/bandcamp.php
@@ -0,0 +1,142 @@
+<?php
+// shortcode handler for [bandcamp], which inserts a bandcamp.com
+// music player (embedded flash object)
+//
+// [bandcamp album=119385304]
+// [bandcamp album=3462839126 bgcol=FFFFFF linkcol=4285BB size=venti]
+// [bandcamp track=2446959313]
+//
+function shortcode_handler_bandcamp( $atts ) {
+ // there are no default values, but specify here anyway
+ // to explicitly list supported atts
+ $attributes = shortcode_atts( array(
+ 'album' => null, // integer album id
+ 'track' => null, // integer track id
+ 'size' => 'venti', // one of the supported sizes
+ 'bgcol' => 'FFFFFF', // hex, no '#' prefix
+ 'linkcol' => null, // hex, no '#' prefix
+ 'layout' => null, // encoded layout url
+ 'width' => null, // integer with optional "%"
+ 'height' => null, // integer with optional "%"
+ 'notracklist' => null, // may be string "true" (defaults false)
+ 'artwork' => null, // may be string "false" (defaults true)
+ 'theme' => null, // may be theme identifier string ("light"|"dark" so far)
+ 'package' => null, // integer package id
+ 't' => null // integer track number
+ ), $atts );
+
+ $sizes = array(
+ 'venti' => array( 'width' => 400, 'height' => 100 ),
+ 'grande' => array( 'width' => 300, 'height' => 100 ),
+ 'grande2' => array( 'width' => 300, 'height' => 355 ),
+ 'grande3' => array( 'width' => 300, 'height' => 415 ),
+ 'tall_album' => array( 'width' => 150, 'height' => 295 ),
+ 'tall_track' => array( 'width' => 150, 'height' => 270 ),
+ 'tall2' => array( 'width' => 150, 'height' => 450 ),
+ 'short' => array( 'width' => 46, 'height' => 23 ),
+ 'large' => array( 'width' => 350, 'height' => 470 ),
+ 'medium' => array( 'width' => 450, 'height' => 120 ),
+ 'small' => array( 'width' => 350, 'height' => 42 )
+ );
+
+ $sizekey = $attributes['size'];
+ $height = null;
+ $width = null;
+
+ // Build iframe url. Args are appended as
+ // extra path segments for historical reasons having to
+ // do with an IE-only flash bug which required this URL
+ // to contain no querystring
+
+ $url = "http://bandcamp.com/EmbeddedPlayer/v=2/";
+ if ( isset( $attributes['track'] ) ) {
+ $track = (int) $attributes['track'];
+ $url .= "track={$track}";
+
+ if ( $sizekey == 'tall' ) {
+ $sizekey .= '_track';
+ }
+ } elseif ( isset( $attributes['album'] ) ) {
+ $album = (int) $attributes['album'];
+ $url .= "album={$album}";
+ $type = 'album';
+
+ if ( $sizekey == 'tall' ) {
+ $sizekey .= '_album';
+ }
+ } else {
+ return "[bandcamp: shortcode must include track or album id]";
+ }
+
+ // if size specified that we don't recognize, fall back on venti
+ if ( empty( $sizes[$sizekey] ) ) {
+ $sizekey = 'venti';
+ $attributes['size'] = 'venti';
+ }
+
+ // use strict regex for digits + optional % instead of absint for height/width
+ // 'width' and 'height' params in the iframe url get the exact string from the shortcode
+ // args, whereas the inline style attribute must have "px" added to it if it has no "%"
+ if ( isset( $attributes['width'] ) && preg_match( "|^([0-9]+)(%)?$|", $attributes['width'], $matches ) ) {
+ $width = $csswidth = $attributes['width'];
+ if ( sizeof( $matches ) < 3 ) {
+ $csswidth .= "px";
+ }
+ }
+ if ( isset( $attributes['height'] ) && preg_match( "|^([0-9]+)(%)?$|", $attributes['height'], $matches ) ) {
+ $height = $cssheight = $attributes['height'];
+ if ( sizeof( $matches ) < 3 ) {
+ $cssheight .= "px";
+ }
+ }
+
+ if ( !$height ) {
+ $height = $sizes[$sizekey]['height'];
+ $cssheight = $height . "px";
+ }
+
+ if ( !$width ) {
+ $width = $sizes[$sizekey]['width'];
+ $csswidth = $width . "px";
+ }
+
+ if ( isset( $attributes['layout'] ) ) {
+ $url .= "/layout={$attributes['layout']}";
+ } elseif ( isset( $attributes['size'] ) && preg_match( "|^[a-zA-Z0-9]+$|", $attributes['size'] ) ) {
+ $url .= "/size={$attributes['size']}";
+ }
+
+ if ( isset( $attributes['bgcol'] ) && preg_match( "|^[0-9A-Fa-f]+$|", $attributes['bgcol'] ) ) {
+ $url .= "/bgcol={$attributes['bgcol']}";
+ }
+
+ if ( isset( $attributes['linkcol'] ) && preg_match( "|^[0-9A-Fa-f]+$|", $attributes['linkcol'] ) ) {
+ $url .= "/linkcol={$attributes['linkcol']}";
+ }
+
+ if ( isset( $attributes['package'] ) && preg_match( "|^[0-9]+$|", $attributes['package'] ) ) {
+ $url .= "/package={$attributes['package']}";
+ }
+
+ if ( isset( $attributes['t'] ) && preg_match( "|^[0-9]+$|", $attributes['t'] ) ) {
+ $url .= "/t={$attributes['t']}";
+ }
+
+ if ( $attributes['notracklist'] == "true" ) {
+ $url .= "/notracklist=true";
+ }
+
+ if ( $attributes['artwork'] == "false" ) {
+ $url .= "/artwork=false";
+ }
+
+ if ( isset( $attributes['theme'] ) && preg_match( "|^[a-zA-Z_]+$|", $attributes['theme'] ) ) {
+ $url .= "/theme={$attributes['theme']}";
+ }
+
+ $url .= '/';
+
+ return "<iframe width='" . esc_attr( $width ) . "' height='" . esc_attr( $height ) . "' style='position: relative; display: block; width: " . esc_attr( $csswidth ) . "; height: " . esc_attr( $cssheight ) . ";' src='" . esc_url( $url ) . "' allowtransparency='true' frameborder='0'></iframe>";
+}
+
+add_shortcode( 'bandcamp', 'shortcode_handler_bandcamp' );
diff --git a/plugins/jetpack/modules/social-links.php b/plugins/jetpack/modules/social-links.php
new file mode 100644
index 00000000..f87b9f82
--- /dev/null
+++ b/plugins/jetpack/modules/social-links.php
@@ -0,0 +1,10 @@
+<?php
+/**
+ * Themes must declare that they support this module by adding
+ * add_theme_support( 'social-links' ); on 'after_setup_theme'.
+ */
+function jetpack_load_additional_modules() {
+ if ( current_theme_supports( 'social-links' ) )
+ require_once 'social-links/social-links.php';
+}
+add_action( 'init', 'jetpack_load_additional_modules' );
diff --git a/plugins/jetpack/modules/social-links/social-links.php b/plugins/jetpack/modules/social-links/social-links.php
new file mode 100644
index 00000000..b84aff93
--- /dev/null
+++ b/plugins/jetpack/modules/social-links/social-links.php
@@ -0,0 +1,169 @@
+<?php
+
+/**
+ * Social Links.
+ *
+ * This feature will only be activated for themes that declare their support.
+ * This can be done by adding code similar to the following during the
+ * 'after_setup_theme' action:
+ *
+ * add_theme_support( 'social-links', array(
+ * 'facebook', 'twitter', 'linkedin', 'tumblr',
+ * ) );
+ */
+class Social_Links {
+
+ /**
+ * The links the user set for each service.
+ *
+ * @var array
+ */
+ private $links;
+
+ /**
+ * A Publicize object.
+ *
+ * @var Publicize
+ */
+ private $publicize;
+
+ /**
+ * An array with all services that are supported by both Publicize and the
+ * currently active theme.
+ *
+ * @var array
+ */
+ private $services = array();
+
+ /**
+ * Constructor.
+ */
+ public function __construct() {
+ $theme_support = get_theme_support( 'social-links' );
+
+ /* An array of named arguments must be passed as the second parameter
+ * of add_theme_support().
+ */
+ if ( ! isset( $theme_support[0] ) || empty( $theme_support[0] ) )
+ return;
+
+ $this->links = Jetpack_Options::get_option( 'social_links', array() );
+
+ global $publicize;
+
+ if ( is_a( $publicize, 'Publicize' ) ) {
+ $this->publicize = $publicize;
+ $this->services = array_intersect(
+ array_keys( $this->publicize->get_services( 'connected' ) ),
+ $theme_support[0]
+ );
+
+ add_action( 'customize_register', array( $this, 'customize_register' ) );
+ add_filter( 'sanitize_option_jetpack_options', array( $this, 'sanitize_link' ) );
+ }
+
+ add_filter( 'jetpack_has_social_links', array( $this, 'has_social_links' ) );
+ add_filter( 'jetpack_get_social_links', array( $this, 'get_social_links' ) );
+
+ foreach ( $theme_support[0] as $service ) {
+ add_filter( "pre_option_jetpack-$service", array( $this, 'get_social_link_filter' ) ); // get_option( 'jetpack-service' );
+ add_filter( "theme_mod_jetpack-$service", array( $this, 'get_social_link_filter' ) ); // get_theme_mod( 'jetpack-service' );
+ }
+ }
+
+ /**
+ * Add social link dropdown to the Customizer.
+ *
+ * @param WP_Customize_Manager $wp_customize Theme Customizer object.
+ */
+ public function customize_register( $wp_customize ) {
+ $wp_customize->add_section( 'jetpack_social_links', array(
+ 'title' => __( 'Connect', 'jetpack' ),
+ 'priority' => 35,
+ ) );
+
+ foreach ( $this->services as $service ) {
+ $wp_customize->add_setting( "jetpack_options[social_links][$service]", array(
+ 'type' => 'option',
+ 'default' => '',
+ ) );
+
+ $wp_customize->add_control( "jetpack-$service", array(
+ 'label' => $this->publicize->get_service_label( $service ),
+ 'section' => 'jetpack_social_links',
+ 'settings' => "jetpack_options[social_links][$service]",
+ 'type' => 'select',
+ 'choices' => $this->get_customize_select( $service ),
+ ) );
+ }
+ }
+
+ /**
+ * Sanitizes social links.
+ *
+ * @param array $option The incoming values to be sanitized.
+ * @returns array
+ */
+ public function sanitize_link( $option ) {
+ foreach ( $this->services as $service ) {
+ if ( ! empty( $option['social_links'][ $service ] ) )
+ $option['social_links'][ $service ] = esc_url_raw( $option['social_links'][ $service ] );
+ else
+ unset( $option['social_links'][ $service ] );
+ }
+
+ return $option;
+ }
+
+ /**
+ * Returns whether there are any social links set.
+ *
+ * @returns bool
+ */
+ public function has_social_links() {
+ return ! empty( $this->links );
+ }
+
+ /**
+ * Return available social links.
+ *
+ * @returns array
+ */
+ public function get_social_links() {
+ return $this->links;
+ }
+
+ /**
+ * Short-circuits get_option and get_theme_mod calls.
+ *
+ * @param string $link The incoming value to be replaced.
+ * @returns string $link The social link that we've got.
+ */
+ public function get_social_link_filter( $link ) {
+ if ( preg_match( '/_jetpack-(.+)$/i', current_filter(), $matches ) && ! empty( $this->links[ $matches[1] ] ) )
+ return $this->links[ $matches[1] ];
+
+ return $link;
+ }
+
+ /**
+ * Puts together an array of choices for a specific service.
+ *
+ * @param string $service The social service.
+ * @return array An associative array with profile links and display names.
+ */
+ private function get_customize_select( $service ) {
+ $choices = array(
+ '' => __( '&mdash; Select &mdash;', 'jetpack' )
+ );
+
+ $connected_services = $this->publicize->get_services( 'connected' );
+ if ( isset( $connected_services[ $service ] ) )
+ foreach ( $connected_services[ $service ] as $c )
+ $choices[ $this->publicize->get_profile_link( $service, $c ) ] = $this->publicize->get_display_name( $service, $c );
+
+ return $choices;
+ }
+}
+
+$jetpack_social_links = new Social_Links;
diff --git a/plugins/jetpack/modules/widgets/twitter-timeline.php b/plugins/jetpack/modules/widgets/twitter-timeline.php
new file mode 100644
index 00000000..4ab6fcb4
--- /dev/null
+++ b/plugins/jetpack/modules/widgets/twitter-timeline.php
@@ -0,0 +1,214 @@
+<?php
+
+/*
+ * Based on Evolution Twitter Timeline (http://wordpress.org/extend/plugins/evolution-twitter-timeline/)
+ * See: https://twitter.com/settings/widgets and https://dev.twitter.com/docs/embedded-timelines for details on Twitter Timelines
+ */
+
+/**
+ * Register the widget for use in Appearance -> Widgets
+ */
+add_action( 'widgets_init', 'jetpack_twitter_timeline_widget_init' );
+
+function jetpack_twitter_timeline_widget_init() {
+ register_widget( 'Jetpack_Twitter_Timeline_Widget' );
+}
+
+class Jetpack_Twitter_Timeline_Widget extends WP_Widget {
+ /**
+ * Register widget with WordPress.
+ */
+ public function __construct() {
+ parent::__construct(
+ 'twitter_timeline',
+ apply_filters( 'jetpack_widget_name', esc_html__( 'Twitter Timeline', 'jetpack' ) ),
+ array(
+ 'classname' => 'widget_twitter_timeline',
+ 'description' => __( 'Display an official Twitter Embedded Timeline widget.', 'jetpack' )
+ )
+ );
+
+ if ( is_active_widget( false, false, $this->id_base ) || is_active_widget( false, false, 'monster' ) ) {
+ wp_enqueue_script( 'twitter-widgets', '//platform.twitter.com/widgets.js', '', '', true );
+ }
+ }
+
+ /**
+ * Front-end display of widget.
+ *
+ * @see WP_Widget::widget()
+ *
+ * @param array $args Widget arguments.
+ * @param array $instance Saved values from database.
+ */
+ public function widget( $args, $instance ) {
+ $instance['lang'] = substr( strtoupper( get_locale() ), 0, 2 );
+
+ echo $args['before_widget'];
+
+ if ( $instance['title'] )
+ echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
+
+ $data_attribs = array( 'widget-id', 'theme', 'link-color', 'border-color', 'chrome' );
+ $attribs = array( 'width', 'height', 'lang' );
+
+ // Start tag output
+ echo '<a class="twitter-timeline"';
+
+ foreach ( $data_attribs as $att ) {
+ if ( !empty( $instance[$att] ) ) {
+ if ( is_array( $instance[$att] ) )
+ echo ' data-' . esc_attr( $att ) . '="' . esc_attr( join( ' ', $instance['chrome'] ) ) . '"';
+ else
+ echo ' data-' . esc_attr( $att ) . '="' . esc_attr( $instance[$att] ) . '"';
+ }
+ }
+
+ foreach ( $attribs as $att ) {
+ if ( !empty( $instance[$att] ) )
+ echo ' ' . esc_attr( $att ) . '="' . esc_attr( $instance[$att] ) . '"';
+ }
+
+ echo '>' . esc_html__( 'My Tweets', 'jetpack' ) . '</a>';
+ // End tag output
+
+ echo $args['after_widget'];
+
+ do_action( 'jetpack_bump_stats_extras', 'widget', 'twitter_timeline' );
+ }
+
+
+ /**
+ * Sanitize widget form values as they are saved.
+ *
+ * @see WP_Widget::update()
+ *
+ * @param array $new_instance Values just sent to be saved.
+ * @param array $old_instance Previously saved values from database.
+ *
+ * @return array Updated safe values to be saved.
+ */
+ public function update( $new_instance, $old_instance ) {
+ $non_hex_regex = '/[^a-f0-9]/';
+ $instance = array();
+ $instance['title'] = sanitize_text_field( $new_instance['title'] );
+ $instance['width'] = (int) $new_instance['width'];
+ $instance['height'] = (int) $new_instance['height'];
+ $instance['width'] = ( 0 !== (int) $instance['width'] ) ? (int) $instance['width'] : 225;
+ $instance['height'] = ( 0 !== (int) $instance['height'] ) ? (int) $instance['height'] : 400;
+
+ // If they entered something that might be a full URL, try to parse it out
+ if ( is_string( $new_instance['widget-id'] ) ) {
+ if ( preg_match( '#https?://twitter\.com/settings/widgets/(\d+)#s', $new_instance['widget-id'], $matches ) ) {
+ $new_instance['widget-id'] = $matches[1];
+ }
+ }
+
+ $instance['widget-id'] = sanitize_text_field( $new_instance['widget-id'] );
+ $instance['widget-id'] = is_numeric( $instance['widget-id'] ) ? $instance['widget-id'] : '';
+
+ foreach ( array( 'link-color', 'border-color' ) as $color ) {
+ $clean = preg_replace( $non_hex_regex, '', sanitize_text_field( $new_instance[$color] ) );
+ if ( $clean )
+ $instance[$color] = '#' . $clean;
+ }
+
+ $instance['theme'] = 'light';
+ if ( in_array( $new_instance['theme'], array( 'light', 'dark' ) ) )
+ $instance['theme'] = $new_instance['theme'];
+
+ $instance['chrome'] = array();
+ if ( isset( $new_instance['chrome'] ) ) {
+ foreach ( $new_instance['chrome'] as $chrome ) {
+ if ( in_array( $chrome, array( 'noheader', 'nofooter', 'noborders', 'noscrollbar', 'transparent' ) ) ) {
+ $instance['chrome'][] = $chrome;
+ }
+ }
+ }
+
+ return $instance;
+ }
+
+
+ /**
+ * Back-end widget form.
+ *
+ * @see WP_Widget::form()
+ *
+ * @param array $instance Previously saved values from database.
+ */
+ public function form( $instance ) {
+ $defaults = array(
+ 'title' => esc_html__( 'Follow me on Twitter', 'jetpack' ),
+ 'width' => '',
+ 'height' => '400',
+ 'widget-id' => '',
+ 'link-color' => '#f96e5b',
+ 'border-color' => '#e8e8e8',
+ 'theme' => 'light',
+ 'chrome' => array(),
+ );
+
+ $instance = wp_parse_args( (array) $instance, $defaults );
+ ?>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'jetpack' ); ?></label>
+ <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" />
+ </p>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'width' ); ?>"><?php esc_html_e( 'Width (px):', 'jetpack' ); ?></label>
+ <input class="widefat" id="<?php echo $this->get_field_id( 'width' ); ?>" name="<?php echo $this->get_field_name( 'width' ); ?>" type="text" value="<?php echo esc_attr( $instance['width'] ); ?>" />
+ </p>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'height' ); ?>"><?php esc_html_e( 'Height (px):', 'jetpack' ); ?></label>
+ <input class="widefat" id="<?php echo $this->get_field_id( 'height' ); ?>" name="<?php echo $this->get_field_name( 'height' ); ?>" type="text" value="<?php echo esc_attr( $instance['height'] ); ?>" />
+ </p>
+
+ <p><small>
+ <?php
+ echo wp_kses_post(
+ sprintf(
+ __( 'You need to <a href="%1$s" target="_blank">create a widget at Twitter.com</a>, and then enter your widget id (the long number found in the URL of your widget\'s config page) in the field below. <a href="%2$s" target="_blank">Read more</a>.', 'jetpack' ),
+ 'https://twitter.com/settings/widgets/new/user',
+ 'http://support.wordpress.com/widgets/twitter-timeline-widget/'
+ )
+ );
+ ?>
+ </small></p>
+ <p>
+ <label for="<?php echo $this->get_field_id( 'widget-id' ); ?>"><?php esc_html_e( 'Widget ID:', 'jetpack' ); ?> <a href="http://support.wordpress.com/widgets/twitter-timeline-widget/#widget-id" target="_blank">( ? )</a></label>
+ <input class="widefat" id="<?php echo $this->get_field_id( 'widget-id' ); ?>" name="<?php echo $this->get_field_name( 'widget-id' ); ?>" type="text" value="<?php echo esc_attr( $instance['widget-id'] ); ?>" />
+ </p>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'chrome-noheader' ); ?>"><?php esc_html_e( 'Layout Options:', 'jetpack' ); ?></label><br />
+ <input type="checkbox"<?php checked( in_array( 'noheader', $instance['chrome'] ) ); ?> id="<?php echo $this->get_field_id( 'chrome-noheader' ); ?>" name="<?php echo $this->get_field_name( 'chrome' ); ?>[]" value="noheader" /> <label for="<?php echo $this->get_field_id( 'chrome-noheader' ); ?>"><?php esc_html_e( 'No Header', 'jetpack' ); ?></label><br />
+ <input type="checkbox"<?php checked( in_array( 'nofooter', $instance['chrome'] ) ); ?> id="<?php echo $this->get_field_id( 'chrome-nofooter' ); ?>" name="<?php echo $this->get_field_name( 'chrome' ); ?>[]" value="nofooter" /> <label for="<?php echo $this->get_field_id( 'chrome-nofooter' ); ?>"><?php esc_html_e( 'No Footer', 'jetpack' ); ?></label><br />
+ <input type="checkbox"<?php checked( in_array( 'noborders', $instance['chrome'] ) ); ?> id="<?php echo $this->get_field_id( 'chrome-noborders' ); ?>" name="<?php echo $this->get_field_name( 'chrome' ); ?>[]" value="noborders" /> <label for="<?php echo $this->get_field_id( 'chrome-noborders' ); ?>"><?php esc_html_e( 'No Borders', 'jetpack' ); ?></label><br />
+ <input type="checkbox"<?php checked( in_array( 'noscrollbar', $instance['chrome'] ) ); ?> id="<?php echo $this->get_field_id( 'chrome-noscrollbar' ); ?>" name="<?php echo $this->get_field_name( 'chrome' ); ?>[]" value="noscrollbar" /> <label for="<?php echo $this->get_field_id( 'chrome-noscrollbar' ); ?>"><?php esc_html_e( 'No Scrollbar', 'jetpack' ); ?></label><br />
+ <input type="checkbox"<?php checked( in_array( 'transparent', $instance['chrome'] ) ); ?> id="<?php echo $this->get_field_id( 'chrome-transparent' ); ?>" name="<?php echo $this->get_field_name( 'chrome' ); ?>[]" value="transparent" /> <label for="<?php echo $this->get_field_id( 'chrome-transparent' ); ?>"><?php esc_html_e( 'Transparent Background', 'jetpack' ); ?></label>
+ </p>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'link-color' ); ?>"><?php _e( 'Link Color (hex):', 'jetpack' ); ?></label>
+ <input class="widefat" id="<?php echo $this->get_field_id( 'link-color' ); ?>" name="<?php echo $this->get_field_name( 'link-color' ); ?>" type="text" value="<?php echo esc_attr( $instance['link-color'] ); ?>" />
+ </p>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'border-color' ); ?>"><?php _e( 'Border Color (hex):', 'jetpack' ); ?></label>
+ <input class="widefat" id="<?php echo $this->get_field_id( 'border-color' ); ?>" name="<?php echo $this->get_field_name( 'border-color' ); ?>" type="text" value="<?php echo esc_attr( $instance['border-color'] ); ?>" />
+ </p>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'theme' ); ?>"><?php _e( 'Timeline Theme:', 'jetpack' ); ?></label>
+ <select name="<?php echo $this->get_field_name( 'theme' ); ?>" id="<?php echo $this->get_field_id( 'theme' ); ?>" class="widefat">
+ <option value="light"<?php selected( $instance['theme'], 'light' ); ?>><?php esc_html_e( 'Light', 'jetpack' ); ?></option>
+ <option value="dark"<?php selected( $instance['theme'], 'dark' ); ?>><?php esc_html_e( 'Dark', 'jetpack' ); ?></option>
+ </select>
+ </p>
+ <?php
+ }
+}