summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Chatzimichos <tampakrap@gentoo.org>2013-03-10 12:10:26 +0100
committerTheo Chatzimichos <tampakrap@gentoo.org>2013-03-10 12:10:26 +0100
commit7aea9fc04bd42e2ac02a1925d3a02a76d391c3e7 (patch)
tree68c852c654cef340592f1001b6310e33827b130c /plugins/jetpack/modules/widgets
parentMake the script more silent (diff)
downloadblogs-gentoo-7aea9fc04bd42e2ac02a1925d3a02a76d391c3e7.tar.gz
blogs-gentoo-7aea9fc04bd42e2ac02a1925d3a02a76d391c3e7.tar.bz2
blogs-gentoo-7aea9fc04bd42e2ac02a1925d3a02a76d391c3e7.zip
update plugins
Diffstat (limited to 'plugins/jetpack/modules/widgets')
-rw-r--r--plugins/jetpack/modules/widgets/facebook-likebox.php57
-rw-r--r--plugins/jetpack/modules/widgets/gravatar-profile.css15
-rw-r--r--plugins/jetpack/modules/widgets/gravatar-profile.php128
-rw-r--r--plugins/jetpack/modules/widgets/image-widget.php2
-rw-r--r--plugins/jetpack/modules/widgets/readmill.php138
-rw-r--r--plugins/jetpack/modules/widgets/top-posts.php295
-rw-r--r--plugins/jetpack/modules/widgets/twitter.php407
-rw-r--r--plugins/jetpack/modules/widgets/widget-grid-and-list.css110
-rw-r--r--plugins/jetpack/modules/widgets/widgets.css13
9 files changed, 1099 insertions, 66 deletions
diff --git a/plugins/jetpack/modules/widgets/facebook-likebox.php b/plugins/jetpack/modules/widgets/facebook-likebox.php
index 64d03f8a..f8ab2512 100644
--- a/plugins/jetpack/modules/widgets/facebook-likebox.php
+++ b/plugins/jetpack/modules/widgets/facebook-likebox.php
@@ -1,6 +1,15 @@
<?php
/**
+ * Register the widget for use in Appearance -> Widgets
+ */
+add_action( 'widgets_init', 'jetpack_facebook_likebox_init' );
+
+function jetpack_facebook_likebox_init() {
+ register_widget( 'WPCOM_Widget_Facebook_LikeBox' );
+}
+
+/**
* Facebook Like Box widget class
* Display a Facebook Like Box as a widget
* http://developers.facebook.com/docs/reference/plugins/like-box/
@@ -17,7 +26,14 @@ class WPCOM_Widget_Facebook_LikeBox extends WP_Widget {
private $allowed_colorschemes = array( 'light', 'dark' );
function __construct() {
- parent::__construct( 'facebook-likebox', __( 'Facebook Like Box', 'jetpack' ), array( 'classname' => 'widget_facebook_likebox', 'description' => __( 'Display a Facebook Like Box to connect visitors to your Facebook Page', 'jetpack' ) ) );
+ parent::__construct(
+ 'facebook-likebox',
+ apply_filters( 'jetpack_widget_name', __( 'Facebook Like Box', 'jetpack' ) ),
+ array(
+ 'classname' => 'widget_facebook_likebox',
+ 'description' => __( 'Display a Facebook Like Box to connect visitors to your Facebook Page', 'jetpack' )
+ )
+ );
}
function widget( $args, $instance ) {
@@ -29,7 +45,7 @@ class WPCOM_Widget_Facebook_LikeBox extends WP_Widget {
if ( empty( $like_args['href'] ) || ! $this->is_valid_facebook_url( $like_args['href'] ) ) {
if ( current_user_can('edit_theme_options') ) {
echo $before_widget;
- echo '<p>' . sprintf( __( 'It looks like your Facebook URL is incorrectly configured. Please check it in your <a href="%s">widget settings</a>.' ), admin_url( 'widgets.php' ) ) . '</p>';
+ echo '<p>' . sprintf( __( 'It looks like your Facebook URL is incorrectly configured. Please check it in your <a href="%s">widget settings</a>.', 'jetpack' ), admin_url( 'widgets.php' ) ) . '</p>';
echo $after_widget;
}
echo '<!-- Invalid Facebook Page URL -->';
@@ -244,26 +260,33 @@ class WPCOM_Widget_Facebook_LikeBox extends WP_Widget {
}
function guess_locale_from_lang( $lang ) {
- $lang = strtolower( str_replace( '-', '_', $lang ) );
+ if ( 'en' == $lang || 'en_US' == $lang || !$lang ) {
+ return 'en_US';
+ }
+
+ if ( !class_exists( 'GP_Locales' ) ) {
+ if ( !defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || !file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) {
+ return false;
+ }
+
+ require JETPACK__GLOTPRESS_LOCALES_PATH;
+ }
- if ( 5 == strlen( $lang ) ) {
- $lang = substr( $lang, 0, 3 ) . strtoupper( substr( $lang, 3, 2 ) );
- } else if ( 3 == strlen( $lang ) ) {
- $lang = $lang;
+ if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
+ // WP.com: get_locale() returns 'it'
+ $locale = GP_Locales::by_slug( $lang );
} else {
- $lang = $lang . '_' . strtoupper( $lang );
+ // Jetpack: get_locale() returns 'it_IT';
+ $locale = GP_Locales::by_field( 'wp_locale', $lang );
}
-
- if ( 'en_EN' == $lang ) {
- $lang = 'en_US';
- } else if ( 'he_HE' == $lang ) {
- $lang = 'he_IL';
- } else if ( 'ja_JA' == $lang )
- $lang = 'ja_JP';
- return $lang;
+ if ( !$locale || empty( $locale->facebook_locale ) ) {
+ return false;
+ }
+
+ return $locale->facebook_locale;
}
-
+
function get_locale() {
return $this->guess_locale_from_lang( get_locale() );
}
diff --git a/plugins/jetpack/modules/widgets/gravatar-profile.css b/plugins/jetpack/modules/widgets/gravatar-profile.css
index 230a3b16..1663ae07 100644
--- a/plugins/jetpack/modules/widgets/gravatar-profile.css
+++ b/plugins/jetpack/modules/widgets/gravatar-profile.css
@@ -1,8 +1,7 @@
.widget-grofile {
}
.widget-grofile h4 {
- margin: 1em 0 1.2em;
- /*font-size: 1.2em;*/
+ margin: 1em 0 .5em;
}
.widget-grofile ul.grofile-urls {
margin-left: 0;
@@ -17,7 +16,7 @@
content: "" !important; /* Kubrick :( */
}
.widget-grofile .grofile-accounts-logo {
- background-image: url('http://0.gravatar.com/images/grav-share-sprite.png');
+ background-image: url('//0.gravatar.com/images/grav-share-sprite.png');
background-repeat: no-repeat;
/*background-position: -16px -16px;*/
width: 16px; /* So we don't show the topmost logo */
@@ -34,3 +33,13 @@
.grofile-thumbnail {
width: 100%;
}
+ @media
+only screen and (-webkit-min-device-pixel-ratio: 1.5),
+only screen and (-o-min-device-pixel-ratio: 3/2),
+only screen and (min--moz-device-pixel-ratio: 1.5),
+only screen and (min-device-pixel-ratio: 1.5) {
+ .widget-grofile .grofile-accounts-logo {
+ background-image: url('//0.gravatar.com/images/grav-share-sprite-2x.png');
+ background-size: 16px 784px;
+ }
+} \ No newline at end of file
diff --git a/plugins/jetpack/modules/widgets/gravatar-profile.php b/plugins/jetpack/modules/widgets/gravatar-profile.php
index c33e6996..190427fe 100644
--- a/plugins/jetpack/modules/widgets/gravatar-profile.php
+++ b/plugins/jetpack/modules/widgets/gravatar-profile.php
@@ -1,15 +1,29 @@
<?php
+
+/**
+ * Register the widget for use in Appearance -> Widgets
+ */
+add_action( 'widgets_init', 'jetpack_gravatar_profile_widget_init' );
+
+function jetpack_gravatar_profile_widget_init() {
+ register_widget( 'Jetpack_Gravatar_Profile_Widget' );
+}
+
/**
* Display a widgetized version of your Gravatar Profile
* http://blog.gravatar.com/2010/03/26/gravatar-profiles/
*/
class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
-
+
function __construct() {
- parent::__construct( 'grofile', __( 'Gravatar Profile', 'jetpack' ), array(
- 'classname' => 'widget-grofile grofile',
- 'description' => __( 'Display a mini version of your Gravatar Profile', 'jetpack' )
- ) );
+ parent::__construct(
+ 'grofile',
+ apply_filters( 'jetpack_widget_name', __( 'Gravatar Profile', 'jetpack' ) ),
+ array(
+ 'classname' => 'widget-grofile grofile',
+ 'description' => __( 'Display a mini version of your Gravatar Profile', 'jetpack' )
+ )
+ );
if ( is_admin() ) {
add_action( 'admin_footer-widgets.php', array( $this, 'admin_script' ) );
@@ -24,7 +38,7 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
echo $args['before_widget'];
if ( ! empty( $title ) )
echo $args['before_title'] . $title . $args['after_title'];
- echo '<p>' . sprintf( __( 'You need to select what to show in this <a href="%s">Gravatar Profile widget</a>.' ), admin_url( 'widgets.php' ) ) . '</p>';
+ echo '<p>' . sprintf( __( 'You need to select what to show in this <a href="%s">Gravatar Profile widget</a>.', 'jetpack' ), admin_url( 'widgets.php' ) ) . '</p>';
echo $args['after_widget'];
}
return;
@@ -35,24 +49,39 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
echo $args['before_title'] . $title . $args['after_title'];
$profile = $this->get_profile( $instance['email'] );
-
+
if( ! empty( $profile ) ) {
- $gravatar_url = add_query_arg( 's', 500, $profile['thumbnailUrl'] ); // the default grav returned by grofiles is super small
-
+ $profile = wp_parse_args( $profile, array(
+ 'thumbnailUrl' => '',
+ 'profileUrl' => '',
+ 'displayName' => '',
+ 'aboutMe' => '',
+ 'urls' => array(),
+ 'accounts' => array(),
+ ) );
+ $gravatar_url = add_query_arg( 's', 200, $profile['thumbnailUrl'] ); // the default grav returned by grofiles is super small
+
wp_enqueue_style(
'gravatar-profile-widget',
plugins_url( 'gravatar-profile.css', __FILE__ ),
array(),
'20120711'
);
-
+
+ wp_enqueue_style(
+ 'gravatar-card-services',
+ is_ssl() ? 'https://secure.gravatar.com/css/services.css' : 'http://s.gravatar.com/css/services.css',
+ array(),
+ defined( 'GROFILES__CACHE_BUSTER' ) ? GROFILES__CACHE_BUSTER : gmdate( 'YW' )
+ );
+
?>
- <img src="<?php echo esc_url( $gravatar_url ); ?>" class="grofile-thumbnail no-grav" />
+ <img src="<?php echo esc_url( $gravatar_url ); ?>" class="grofile-thumbnail no-grav" style="width: auto; max-width: 200px;" />
<div class="grofile-meta">
<h4><a href="<?php echo esc_url( $profile['profileUrl'] ); ?>"><?php echo esc_html( $profile['displayName'] ); ?></a></h4>
- <p><?php echo esc_html( wp_kses( $profile['aboutMe'], array() ) ); ?></p>
+ <p><?php echo wp_kses_data( $profile['aboutMe'] ); ?></p>
</div>
-
+
<?php
if( $instance['show_personal_links'] )
@@ -60,15 +89,15 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
if( $instance['show_account_links'] )
$this->display_accounts( (array) $profile['accounts'] );
-
+
?>
-
- <h4><a href="<?php echo esc_url( $profile['profileUrl'] ); ?>" class="grofile-full-link"><?php esc_html_e( 'View Full Profile &rarr;' ); ?></a></h4>
-
+
+ <h4><a href="<?php echo esc_url( $profile['profileUrl'] ); ?>" class="grofile-full-link"><?php esc_html_e( 'View Full Profile &rarr;', 'jetpack' ); ?></a></h4>
+
<?php
- do_action( 'jetpack_stats_extra', 'widgets', 'grofile' );
-
+ do_action( 'jetpack_stats_extra', 'widget', 'grofile' );
+
} else {
if ( current_user_can( 'edit_theme_options' ) ) {
echo '<p>' . esc_html__( 'Error loading profile', 'jetpack' ) . '</p>';
@@ -85,7 +114,7 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
<h4><?php esc_html_e( 'Personal Links', 'jetpack' ); ?></h4>
<ul class="grofile-urls grofile-links">
-
+
<?php foreach( $personal_links as $personal_link ) : ?>
<li>
<a href="<?php echo esc_url( $personal_link['value'] ); ?>">
@@ -98,30 +127,30 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
<?php
}
- function display_accounts( $accounts = array() ) {
+ function display_accounts( $accounts = array() ) {
if ( empty( $accounts ) )
return;
?>
-
+
<h4><?php esc_html_e( 'Verified Services', 'jetpack' ); ?></h4>
<ul class="grofile-urls grofile-accounts">
-
+
<?php foreach( $accounts as $account ) :
if( $account['verified'] != 'true' )
continue;
-
+
$sanitized_service_name = $this->get_sanitized_service_name( $account['shortname'] );
?>
-
+
<li>
<a href="<?php echo esc_url( $account['url'] ); ?>" title="<?php echo sprintf( _x( '%1$s on %2$s', '1: User Name, 2: Service Name (Facebook, Twitter, ...)', 'jetpack' ), esc_html( $account['display'] ), esc_html( $sanitized_service_name ) ); ?>">
<span class="grofile-accounts-logo grofile-accounts-<?php echo esc_attr( $account['shortname'] ); ?> accounts_<?php echo esc_attr( $account['shortname'] ); ?>"></span>
</a>
</li>
-
+
<?php endforeach; ?>
</ul>
-
+
<?php
}
@@ -133,6 +162,12 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
$show_personal_links = isset( $instance['show_personal_links'] ) ? (bool) $instance['show_personal_links'] : '';
$show_account_links = isset( $instance['show_account_links'] ) ? (bool) $instance['show_account_links'] : '';
+ if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
+ $profile_url = admin_url( 'profile.php' );
+ } else {
+ $profile_url = 'https://gravatar.com/profile/edit';
+ }
+
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>">
@@ -144,7 +179,7 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
<label for="<?php echo $this->get_field_id( 'email_user' ); ?>">
<?php esc_html_e( 'Select a user or pick "custom" and enter a custom email address.', 'jetpack' ); ?>
<br />
-
+
<?php wp_dropdown_users( array(
'show_option_none' => __( 'Custom', 'jetpack' ),
'selected' => $email_user,
@@ -154,13 +189,13 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
) );?>
</label>
</p>
-
+
<p class="gprofile-email-container <?php echo empty( $email_user ) || $email_user == -1 ? '' : 'hidden'; ?>">
<label for="<?php echo $this->get_field_id( 'email' ); ?>"><?php esc_html_e( 'Custom Email Address', 'jetpack' ); ?>
<input class="widefat" id="<?php echo $this->get_field_id('email'); ?>" name="<?php echo $this->get_field_name( 'email' ); ?>" type="text" value="<?php echo esc_attr( $email ); ?>" />
</label>
</p>
-
+
<p>
<label for="<?php echo $this->get_field_id( 'show_personal_links' ); ?>">
<input type="checkbox" name="<?php echo $this->get_field_name( 'show_personal_links' ); ?>" id="<?php echo $this->get_field_id( 'show_personal_links' ); ?>" <?php checked( $show_personal_links ); ?> />
@@ -178,8 +213,8 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
<small><?php esc_html_e( 'Links to services that you use across the web.', 'jetpack' ); ?></small>
</label>
</p>
-
- <p><a href="<?php echo admin_url( 'profile.php' ); ?>" target="_blank" title="<?php esc_attr_e( 'Opens in new window', 'jetpack' ); ?>"><?php esc_html_e( 'Edit Your Profile', 'jetpack' )?></a> | <a href="http://gravatar.com" target="_blank" title="<?php esc_attr_e( 'Opens in new window', 'jetpack' ); ?>"><?php esc_html_e( "What's a Gravatar?", 'jetpack' ); ?></a></p>
+
+ <p><a href="<?php echo esc_url( $profile_url ); ?>" target="_blank" title="<?php esc_attr_e( 'Opens in new window', 'jetpack' ); ?>"><?php esc_html_e( 'Edit Your Profile', 'jetpack' )?></a> | <a href="http://gravatar.com" target="_blank" title="<?php esc_attr_e( 'Opens in new window', 'jetpack' ); ?>"><?php esc_html_e( "What's a Gravatar?", 'jetpack' ); ?></a></p>
<?php
}
@@ -202,7 +237,7 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
}
function update( $new_instance, $old_instance ) {
-
+
$instance = array();
$instance['title'] = isset( $new_instance['title'] ) ? wp_kses( $new_instance['title'], array() ) : '';
@@ -216,42 +251,45 @@ class Jetpack_Gravatar_Profile_Widget extends WP_Widget {
$instance['email'] = $user->user_email;
}
+ $hashed_email = md5( strtolower( trim( $instance['email'] ) ) );
+ $cache_key = 'grofile-' . $hashed_email;
+ delete_transient( $cache_key );
+
return $instance;
}
-
+
private function get_profile( $email ) {
$hashed_email = md5( strtolower( trim( $email ) ) );
- $cache_key = 'widget-grofile-' . $hashed_email;
-
- if( ! $profile = get_transient( $cache_key, 'widget' ) ) {
-
+ $cache_key = 'grofile-' . $hashed_email;
+
+ if( ! $profile = get_transient( $cache_key ) ) {
$profile_url = esc_url_raw( sprintf( '%s.gravatar.com/%s.php', ( is_ssl() ? 'https://secure' : 'http://www' ), $hashed_email ), array( 'http', 'https' ) );
-
+
$expire = 300;
$response = wp_remote_get( $profile_url, array( 'User-Agent' => 'WordPress.com Gravatar Profile Widget' ) );
$response_code = wp_remote_retrieve_response_code( $response );
if ( 200 == $response_code ) {
$profile = wp_remote_retrieve_body( $response );
$profile = unserialize( $profile );
-
+
if ( is_array( $profile ) && ! empty( $profile['entry'] ) && is_array( $profile['entry'] ) ) {
$expire = 900; // cache for 15 minutes
$profile = $profile['entry'][0];
} else {
+ // Something strange happend. Cache for 5 minutes.
$profile = array();
}
-
+
} else {
- $expire =
+ $expire = 900; // cache for 15 minutes
$profile = array();
- set_transient( $cache_key . '-response-code', $response_code, $expire );
}
-
+
set_transient( $cache_key, $profile, $expire );
}
return $profile;
}
-
+
private function get_sanitized_service_name( $shortname ) {
// Some services have stylized or mixed cap names *cough* WP *cough*
switch( $shortname ) {
diff --git a/plugins/jetpack/modules/widgets/image-widget.php b/plugins/jetpack/modules/widgets/image-widget.php
index 0e7e227b..03d4d5c7 100644
--- a/plugins/jetpack/modules/widgets/image-widget.php
+++ b/plugins/jetpack/modules/widgets/image-widget.php
@@ -43,7 +43,7 @@ class Jetpack_Image_Widget extends WP_Widget {
if ( '' != $instance['caption'] )
$output = '[caption align="align' . esc_attr( $instance['align'] ) . '" width="' . esc_attr( $instance['img_width'] ) .'" caption="' . esc_attr( $instance['caption'] ) . '"]' . $output . '[/caption]';
- echo '<div style="overflow:hidden;">' . do_shortcode( $output ) . '</div>';
+ echo '<div class="jetpack-image-container">' . do_shortcode( $output ) . '</div>';
}
echo "\n" . $after_widget;
diff --git a/plugins/jetpack/modules/widgets/readmill.php b/plugins/jetpack/modules/widgets/readmill.php
new file mode 100644
index 00000000..7729ed3e
--- /dev/null
+++ b/plugins/jetpack/modules/widgets/readmill.php
@@ -0,0 +1,138 @@
+<?php
+class Jetpack_Readmill_Widget extends WP_Widget {
+ var $default_title, $default_size;
+
+ /**
+ * Registers the widget with WordPress.
+ */
+ function __construct() {
+ parent::__construct(
+ 'jetpack_readmill_widget', // Base ID
+ apply_filters( 'jetpack_widget_name', esc_html__( 'Send To Readmill', 'jetpack' ) ),
+ array(
+ 'description' => esc_html__( 'Readmill is the best book reader for phones and tablets. With this widget you can enable users to send a book to their device with one click.', 'jetpack' ),
+ )
+ );
+
+ if ( is_active_widget( false, false, $this->id_base ) || is_active_widget( false, false, 'monster' ) ) {
+ add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_script' ) );
+ }
+
+ $this->default_title = __( 'Send To Readmill', 'jetpack' );
+ $this->default_size = 'large';
+ }
+
+ function enqueue_script() {
+ wp_enqueue_script( 'readmill', 'https://platform.readmill.com/send.js', array(), '20130220', false );
+ }
+
+ /**
+ * Back-end widget form.
+ *
+ * @see WP_Widget::form()
+ *
+ * @param array $instance Previously saved values from database.
+ */
+ function form( $instance ) {
+ $title = isset( $instance['title' ] ) ? $instance['title'] : false;
+ if ( false === $title ) {
+ $title = $this->default_title;
+ }
+
+ $epub_link = isset( $instance['epub_link'] ) ? $instance['epub_link'] : '';
+ $buy_link = isset( $instance['buy_link'] ) ? $instance['buy_link'] : '';
+ $size = isset( $instance['size'] ) ? $instance['size'] : $this->default_size;
+ ?>
+
+ <p><?php printf( __( "Just enter the URL to your book, make sure it's a PDF or EPUB file, and you are ready to go. For more help, head to <a href='%s'>the Readmill WordPress Widget support page</a>." ), 'http://en.support.wordpress.com/widgets/readmill/' ); ?></p>
+
+ <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( $title ); ?>" />
+ </p>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'epub_link' ); ?>"><?php esc_html_e( 'Download URL:', 'jetpack' ); ?></label>
+ <input class="widefat" id="<?php echo $this->get_field_id( 'epub_link' ); ?>" name="<?php echo $this->get_field_name( 'epub_link' ); ?>" type="text" value="<?php echo esc_attr( $epub_link ); ?>" />
+ </p>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'buy_link' ); ?>"><?php esc_html_e( 'Item URL:', 'jetpack' ); ?></label>
+ <input class="widefat" id="<?php echo $this->get_field_id( 'buy_link' ); ?>" name="<?php echo $this->get_field_name( 'buy_link' ); ?>" type="text" value="<?php echo esc_attr( $buy_link ); ?>" />
+ </p>
+
+ <p>
+ <label><?php esc_html_e( 'What size icon?', 'jetpack' ); ?></label>
+ <ul>
+ <li><label><input id="<?php echo $this->get_field_id( 'size' ); ?>-few" name="<?php echo $this->get_field_name( 'size' ); ?>" type="radio" value="large" <?php checked( 'large', $size ); ?> /> <?php esc_html_e( 'Large', 'jetpack' ); ?></label></li>
+ <li><label><input id="<?php echo $this->get_field_id( 'size' ); ?>-lots" name="<?php echo $this->get_field_name( 'size' ); ?>" type="radio" value="small" <?php checked( 'small', $size ); ?> /> <?php esc_html_e( 'Small', 'jetpack' ); ?></label></li>
+ </ul>
+ </p>
+
+ <?php
+ }
+
+ /**
+ * 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.
+ */
+ function update( $new_instance, $old_instance ) {
+ $instance = array();
+ $instance['title'] = wp_kses( $new_instance['title'], array() );
+ $instance['epub_link'] = wp_kses( $new_instance['epub_link'], array() );
+ $instance['buy_link'] = wp_kses( $new_instance['buy_link'], array() );
+ $instance['size'] = wp_kses( $new_instance['size'], array() );
+
+ if ( $this->default_title === $instance['title'] ) {
+ $instance['title'] = false; // Store as false in case of language change
+ }
+
+ return $instance;
+ }
+
+ /**
+ * Front-end display of widget.
+ *
+ * @see WP_Widget::widget()
+ *
+ * @param array $args Widget arguments.
+ * @param array $instance Saved values from database.
+ */
+ function widget( $args, $instance ) {
+ $title = isset( $instance['title' ] ) ? $instance['title'] : false;
+
+ if ( false === $title )
+ $title = $this->default_title;
+
+ $title = apply_filters( 'widget_title', $title );
+
+ echo $args['before_widget'];
+
+ if ( ! empty( $title ) )
+ echo $args['before_title'] . $title . $args['after_title'];
+
+ $epub_link = isset( $instance['epub_link'] ) ? $instance['epub_link'] : '';
+ $buy_link = isset( $instance['buy_link'] ) ? $instance['buy_link'] : '';
+ $size = isset( $instance['size'] ) ? $instance['size'] : $this->default_size;
+
+ if ( empty( $epub_link ) && current_user_can( 'edit_theme_options' ) ) :
+ ?><p><?php esc_html_e( 'Your ePub link is empty. Provide an ePub link to display the Send to Readmill widget.', 'jetpack' ); ?></p><?php
+ else :
+ ?><a class="send-to-readmill" href="https://readmill.com" data-download-url="<?php echo esc_attr( $epub_link ); ?>" data-buy-url="<?php echo esc_attr( $epub_link ); ?>" data-display="<?php echo esc_attr( $size ); ?>">Send to Readmill</a><?php
+ endif;
+
+ echo $args['after_widget'];
+ }
+}
+
+function jetpack_readmill_widget_init() {
+ register_widget( 'Jetpack_Readmill_Widget' );
+}
+
+add_action( 'widgets_init', 'jetpack_readmill_widget_init' );
diff --git a/plugins/jetpack/modules/widgets/top-posts.php b/plugins/jetpack/modules/widgets/top-posts.php
new file mode 100644
index 00000000..b6f2c8d7
--- /dev/null
+++ b/plugins/jetpack/modules/widgets/top-posts.php
@@ -0,0 +1,295 @@
+<?php
+
+/*
+ * Currently, this widget depends on the Stats Module. To not load this file
+ * when the Stats Module is not active would potentially bypass Jetpack's
+ * fatal error detection on module activation, so we always load this file.
+ * Instead, we don't register the widget if the Stats Module isn't active.
+ */
+
+/**
+ * Register the widget for use in Appearance -> Widgets
+ */
+add_action( 'widgets_init', 'jetpack_top_posts_widget_init' );
+
+function jetpack_top_posts_widget_init() {
+ // Currently, this widget depends on the Stats Module
+ if (
+ ( !defined( 'IS_WPCOM' ) || !IS_WPCOM )
+ &&
+ !function_exists( 'stats_get_csv' )
+ ) {
+ return;
+ }
+
+ register_widget( 'Jetpack_Top_Posts_Widget' );
+}
+
+class Jetpack_Top_Posts_Widget extends WP_Widget {
+ var $alt_option_name = 'widget_stats_topposts';
+ var $default_title = '';
+
+ function __construct() {
+ parent::__construct(
+ 'top-posts',
+ apply_filters( 'jetpack_widget_name', __( 'Top Posts &amp; Pages', 'jetpack' ) ),
+ array(
+ 'description' => __( 'Shows your most viewed posts and pages.', 'jetpack' ),
+ )
+ );
+
+ $this->default_title = __( 'Top Posts &amp; Pages', 'jetpack' );
+
+ if ( is_active_widget( false, false, $this->id_base ) ) {
+ add_action( 'wp_print_styles', array( $this, 'enqueue_style' ) );
+ }
+ }
+
+ function enqueue_style() {
+ wp_register_style( 'widget-grid-and-list', plugins_url( 'widget-grid-and-list.css', __FILE__ ) );
+ wp_enqueue_style( 'widget-grid-and-list' );
+ }
+
+ function form( $instance ) {
+ $title = isset( $instance['title' ] ) ? $instance['title'] : false;
+ if ( false === $title ) {
+ $title = $this->default_title;
+ }
+
+ $count = isset( $instance['count'] ) ? (int) $instance['count'] : 10;
+ if ( $count < 1 || 20 < $count ) {
+ $count = 10;
+ }
+
+ if ( isset( $instance['display'] ) && in_array( $instance['display'], array( 'grid', 'list', 'text' ) ) ) {
+ $display = $instance['display'];
+ } else {
+ $display = 'text';
+ }
+
+ ?>
+
+ <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( $title ); ?>" />
+ </p>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'count' ); ?>"><?php esc_html_e( 'Number of posts to show:', 'jetpack' ); ?></label>
+ <input id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>" type="number" value="<?php echo (int) $count; ?>" min="1" max="20" />
+ </p>
+
+ <p>
+ <label><?php esc_html_e( 'Display as:', 'jetpack' ); ?></label>
+ <ul>
+ <li><label><input id="<?php echo $this->get_field_id( 'display' ); ?>-text" name="<?php echo $this->get_field_name( 'display' ); ?>" type="radio" value="text" <?php checked( 'text', $display ); ?> /> <?php esc_html_e( 'Text List', 'jetpack' ); ?></label></li>
+ <li><label><input id="<?php echo $this->get_field_id( 'display' ); ?>-list" name="<?php echo $this->get_field_name( 'display' ); ?>" type="radio" value="list" <?php checked( 'list', $display ); ?> /> <?php esc_html_e( 'Image List', 'jetpack' ); ?></label></li>
+ <li><label><input id="<?php echo $this->get_field_id( 'display' ); ?>-grid" name="<?php echo $this->get_field_name( 'display' ); ?>" type="radio" value="grid" <?php checked( 'grid', $display ); ?> /> <?php esc_html_e( 'Image Grid', 'jetpack' ); ?></label></li>
+ </ul>
+ </p>
+
+ <p><?php esc_html_e( 'Top Posts &amp; Pages by views are calculated from 24-48 hours of stats. They take a while to change.', 'jetpack' ); ?></p>
+
+ <?php
+ }
+
+ function update( $new_instance, $old_instance ) {
+ $instance = array();
+ $instance['title'] = wp_kses( $new_instance['title'], array() );
+ if ( $instance['title'] === $this->default_title ) {
+ $instance['title'] = false; // Store as false in case of language change
+ }
+
+ $instance['count'] = (int) $new_instance['count'];
+ if ( $instance['count'] < 1 || 20 < $instance['count'] ) {
+ $instance['count'] = 10;
+ }
+
+ if ( isset( $new_instance['display'] ) && in_array( $new_instance['display'], array( 'grid', 'list', 'text' ) ) ) {
+ $instance['display'] = $new_instance['display'];
+ } else {
+ $instance['display'] = 'text';
+ }
+
+ return $instance;
+ }
+
+ function widget( $args, $instance ) {
+ $title = isset( $instance['title' ] ) ? $instance['title'] : false;
+ if ( false === $title )
+ $title = $this->default_title;
+ $title = apply_filters( 'widget_title', $title );
+
+ $count = isset( $instance['count'] ) ? (int) $instance['count'] : false;
+ if ( $count < 1 || 20 < $count ) {
+ $count = 10;
+ }
+
+ if ( isset( $instance['display'] ) && in_array( $instance['display'], array( 'grid', 'list', 'text' ) ) ) {
+ $display = $instance['display'];
+ } else {
+ $display = 'text';
+ }
+
+ if ( 'text' != $display ) {
+ $get_image_options = array(
+ 'fallback_to_avatars' => true,
+ 'gravatar_default' => apply_filters( 'jetpack_static_url', is_ssl() ? 'https' : 'http' . '://en.wordpress.com/i/logo/white-gray-80.png' ),
+ );
+ if ( 'grid' == $display ) {
+ if ( $count %2 != 0 ) {
+ $count++;
+ }
+
+ $get_image_options['avatar_size'] = 200;
+ } else {
+ $get_image_options['avatar_size'] = 40;
+ }
+ $get_image_options = apply_filters( 'jetpack_top_posts_widget_image_options', $get_image_options );
+ }
+
+ $posts = $this->get_by_views( $count );
+
+ if ( !$posts ) {
+ $posts = $this->get_fallback_posts();
+ }
+
+ echo $args['before_widget'];
+ if ( ! empty( $title ) )
+ echo $args['before_title'] . $title . $args['after_title'];
+
+ if ( !$posts ) {
+ if ( current_user_can( 'edit_theme_options' ) ) {
+ echo '<p>' . sprintf(
+ __( 'There are no posts to display. <a href="%s">Want more traffic?</a>', 'jetpack' ),
+ 'http://en.support.wordpress.com/getting-more-site-traffic/'
+ ) . '</p>';
+ }
+
+ echo $args['after_widget'];
+ return;
+ }
+
+ switch ( $display ) {
+ case 'list' :
+ case 'grid' :
+ wp_enqueue_style( 'widget-grid-and-list' );
+ foreach ( $posts as &$post ) {
+ $image = Jetpack_PostImages::get_image( $post['post_id'] );
+ $post['image'] = $image['src'];
+ if ( 'blavatar' != $image['from'] && 'gravatar' != $image['from'] ) {
+ $size = (int) $get_image_options['avatar_size'];
+ $post['image'] = jetpack_photon_url( $post['image'], array( 'resize' => "$size,$size" ) );
+ }
+ }
+
+ unset( $post );
+
+ if ( 'grid' == $display ) {
+ echo "<div class='widgets-grid-layout no-grav'>\n";
+ foreach ( $posts as $post ) :
+ ?>
+ <div class="widget-grid-view-image">
+ <a href="<?php echo esc_url( $post['permalink'] ); ?>" title="<?php echo esc_attr( wp_kses( $post['title'], array() ) ); ?>" class="bump-view" data-bump-view="tp"><img src="<?php echo esc_url( $post['image'] ); ?>" /></a>
+ </div>
+
+ <?php
+ endforeach;
+ echo "</div>\n";
+ } else {
+ echo "<ul class='widgets-list-layout no-grav'>\n";
+ foreach ( $posts as $post ) :
+ ?>
+ <li>
+ <img src="<?php echo esc_url( $post['image'] ); ?>" class='widgets-list-layout-blavatar' />
+ <div class="widgets-list-layout-links"><a href="<?php echo esc_url( $post['permalink'] ); ?>" class="bump-view" data-bump-view="tp"><?php echo esc_html( wp_kses( $post['title'], array() ) ); ?></a></div>
+ </li>
+ <?php
+ endforeach;
+ echo "</ul>\n";
+ }
+ break;
+ default :
+ echo '<ul>';
+ foreach ( $posts as $post ) {
+ echo '<li><a href="' . esc_url( $post['permalink'] ) . '" class="bump-view" data-bump-view="tp">' . esc_html( $post['title'] ) . "</a></li>\n";
+ }
+ echo '</ul>';
+ }
+
+ echo $args['after_widget'];
+ }
+
+ function get_by_views( $count ) {
+ global $wpdb;
+ $post_view_posts = stats_get_csv( 'postviews', array( 'days' => 2, 'limit' => 10 ) );
+ if ( !$post_view_posts ) {
+ return array();
+ }
+
+ $post_view_ids = array_filter( wp_list_pluck( $post_view_posts, 'post_id' ) );
+ if ( !$post_view_ids ) {
+ return array();
+ }
+
+ return $this->get_posts( $post_view_ids, $count );
+ }
+
+ function get_fallback_posts() {
+ if ( current_user_can( 'edit_theme_options' ) ) {
+ return array();
+ }
+
+ $post_query = new WP_Query;
+
+ $posts = $post_query->query( array(
+ 'posts_per_page' => 1,
+ 'post_status' => 'publish',
+ 'post_type' => array( 'post', 'page' ),
+ 'no_found_rows' => true,
+ ) );
+
+ if ( !$posts ) {
+ return array();
+ }
+
+ $post = array_pop( $posts );
+
+ return $this->get_posts( $post->ID, 1 );
+ }
+
+ function get_posts( $post_ids, $count ) {
+ $counter = 0;
+
+ $posts = array();
+ foreach ( (array) $post_ids as $post_id ) {
+ $post = get_post( $post_id );
+
+ if ( !$post )
+ continue;
+
+ // hide private and password protected posts
+ if ( 'publish' != $post->post_status || !empty( $post->post_password ) || empty( $post->ID ) )
+ continue;
+
+ // Both get HTML stripped etc on display
+ if ( empty( $post->post_title ) ) {
+ $title_source = $post->post_content;
+ $title = wp_html_excerpt( $title_source, 50 );
+ $title .= '&hellip;';
+ } else {
+ $title = $post->post_title;
+ }
+
+ $permalink = get_permalink( $post->ID );
+
+ $posts[] = compact( 'title', 'permalink', 'post_id' );
+ $counter++;
+
+ if ( $counter == $count )
+ break; // only need to load and show x number of likes
+ }
+
+ return $posts;
+ }
+}
diff --git a/plugins/jetpack/modules/widgets/twitter.php b/plugins/jetpack/modules/widgets/twitter.php
new file mode 100644
index 00000000..ff49abf7
--- /dev/null
+++ b/plugins/jetpack/modules/widgets/twitter.php
@@ -0,0 +1,407 @@
+<?php
+
+/**
+ * Twitter widget class
+ * Display the latest N tweets from a Twitter screenname as a widget
+ * Customize screenname, maximum number of tweets displayed, show or hide @replies, and text displayed between tweet text and a timestamp
+ *
+ */
+
+/**
+ * Register the widget for use in Appearance -> Widgets
+ */
+add_action( 'widgets_init', 'jetpack_twitter_widget_init' );
+
+function jetpack_twitter_widget_init() {
+ register_widget( 'Jetpack_Widget_Twitter' );
+}
+
+class Jetpack_Widget_Twitter extends WP_Widget {
+
+ function __construct() {
+ parent::__construct(
+ 'twitter',
+ apply_filters( 'jetpack_widget_name', __( 'Twitter', 'jetpack' ) ),
+ array(
+ 'classname' => 'widget_twitter',
+ 'description' => __( 'Display your Tweets from Twitter', 'jetpack' )
+ )
+ );
+
+ if ( is_active_widget( false, false, $this->id_base ) || is_active_widget( false, false, 'monster' ) ) {
+ add_action( 'wp_head', array( $this, 'style' ) );
+ }
+ }
+
+ function style() {
+?>
+<style type="text/css">
+.widget_twitter li {
+ word-wrap: break-word;
+}
+</style>
+<?php
+ }
+
+ function widget( $args, $instance ) {
+ $account = trim( urlencode( $instance['account'] ) );
+
+ if ( empty( $account ) ) {
+ if ( current_user_can('edit_theme_options') ) {
+ echo $args['before_widget'];
+ echo '<p>' . sprintf( __( 'Please configure your Twitter username for the <a href="%s">Twitter Widget</a>.', 'jetpack' ), admin_url( 'widgets.php' ) ) . '</p>';
+ echo $args['after_widget'];
+ }
+
+ return;
+ }
+
+ $title = apply_filters( 'widget_title', $instance['title'] );
+
+ if ( empty( $title ) )
+ $title = __( 'Twitter Updates', 'jetpack' );
+
+ $show = absint( $instance['show'] ); // # of Updates to show
+
+ if ( $show > 200 ) // Twitter paginates at 200 max tweets. update() should not have accepted greater than 20
+ $show = 200;
+
+ $hidereplies = (bool) $instance['hidereplies'];
+ $hidepublicized = (bool) $instance['hidepublicized'];
+ $include_retweets = (bool) $instance['includeretweets'];
+ $follow_button = (bool) $instance['followbutton'];
+
+ echo "{$args['before_widget']}{$args['before_title']}<a href='" . esc_url( "http://twitter.com/{$account}" ) . "'>" . esc_html( $title ) . "</a>{$args['after_title']}";
+
+ $tweets = $this->fetch_twitter_user_stream( $account, $hidereplies, $show, $include_retweets );
+
+ if ( isset( $tweets['error'] ) && ( isset( $tweets['data'] ) && ! empty( $tweets['data'] ) ) )
+ $tweets['error'] = '';
+
+ if ( empty( $tweets['error'] ) ) {
+ $before_tweet = isset( $instance['beforetweet'] ) ? stripslashes( wp_filter_post_kses( $instance['beforetweet'] ) ) : '';
+ $before_timesince = ( isset( $instance['beforetimesince'] ) && ! empty( $instance['beforetimesince'] ) ) ? esc_html( $instance['beforetimesince'] ) : ' ';
+
+ $this->display_tweets( $show, $tweets['data'], $hidepublicized, $before_tweet, $before_timesince, $account );
+
+ if ( $follow_button )
+ $this->display_follow_button( $account );
+
+ add_action( 'wp_footer', array( $this, 'twitter_widget_script' ) );
+ } else {
+ echo $tweets['error'];
+ }
+
+ echo $args['after_widget'];
+ do_action( 'jetpack_bump_stats_extras', 'widget', 'twitter' );
+ }
+
+ function display_tweets( $show, $tweets, $hidepublicized, $before_tweet, $before_timesince, $account ) {
+ $tweets_out = 0;
+ ?><ul class='tweets'><?php
+
+ foreach( (array) $tweets as $tweet ) {
+ if ( $tweets_out >= $show )
+ break;
+
+ if ( empty( $tweet['text'] ) )
+ continue;
+
+ if( $hidepublicized && false !== strstr( $tweet['source'], 'http://publicize.wp.com/' ) )
+ continue;
+
+ $tweet['text'] = esc_html( $tweet['text'] ); // escape here so that Twitter handles in Tweets don't get mangled
+ $tweet = $this->expand_tco_links( $tweet );
+ $tweet['text'] = make_clickable( $tweet['text'] );
+
+ /*
+ * Create links from plain text based on Twitter patterns
+ * @link http://github.com/mzsanford/twitter-text-rb/blob/master/lib/regex.rb Official Twitter regex
+ */
+ $tweet['text'] = preg_replace_callback( '/(^|[^0-9A-Z&\/]+)(#|\xef\xbc\x83)([0-9A-Z_]*[A-Z_]+[a-z0-9_\xc0-\xd6\xd8-\xf6\xf8\xff]*)/iu', array( $this, '_jetpack_widget_twitter_hashtag' ), $tweet['text'] );
+ $tweet['text'] = preg_replace_callback( '/([^a-zA-Z0-9_]|^)([@\xef\xbc\xa0]+)([a-zA-Z0-9_]{1,20})(\/[a-zA-Z][a-zA-Z0-9\x80-\xff-]{0,79})?/u', array( $this, '_jetpack_widget_twitter_username' ), $tweet['text'] );
+
+ if ( isset( $tweet['id_str'] ) )
+ $tweet_id = urlencode( $tweet['id_str'] );
+ else
+ $tweet_id = urlencode( $tweet['id'] );
+
+ ?>
+
+ <li>
+ <?php echo esc_attr( $before_tweet ) . $tweet['text'] . esc_attr( $before_timesince ) ?>
+ <a href="<?php echo esc_url( "http://twitter.com/{$account}/statuses/{$tweet_id}" ); ?>" class="timesince"><?php echo esc_html( str_replace( ' ', '&nbsp;', $this->time_since( strtotime( $tweet['created_at'] ) ) ) ); ?>&nbsp;ago</a>
+ </li>
+
+ <?php
+
+ unset( $tweet_it );
+ $tweets_out++;
+ }
+
+ ?></ul><?php
+ }
+
+ function display_follow_button( $account ) {
+ global $themecolors;
+
+ $follow_colors = isset( $themecolors['link'] ) ? " data-link-color='#{$themecolors['link']}'" : '';
+ $follow_colors .= isset( $themecolors['text'] ) ? " data-text-color='#{$themecolors['text']}'" : '';
+ $follow_button_attrs = " class='twitter-follow-button' data-show-count='false'{$follow_colors}";
+
+ ?><a href="http://twitter.com/<?php echo esc_attr( $account ); ?>" <?php echo $follow_button_attrs; ?>>Follow @<?php echo esc_attr( $account ); ?></a><?php
+ }
+
+ function expand_tco_links( $tweet ) {
+ if ( ! empty( $tweet['entities']['urls'] ) && is_array( $tweet['entities']['urls'] ) ) {
+ foreach ( $tweet['entities']['urls'] as $entity_url ) {
+ if ( ! empty( $entity_url['expanded_url'] ) ) {
+ $tweet['text'] = str_replace(
+ $entity_url['url'],
+ '<a href="' . esc_url( $entity_url['expanded_url'] ) . '"> ' . esc_html( $entity_url['display_url'] ) . '</a>',
+ $tweet['text']
+ );
+ }
+ }
+ }
+
+ return $tweet;
+ }
+
+ function fetch_twitter_user_stream( $account, $hidereplies, $show, $include_retweets ) {
+ $tweets = get_transient( 'widget-twitter-' . $this->number );
+ $the_error = get_transient( 'widget-twitter-error-' . $this->number );
+
+ if ( ! $tweets ) {
+ $params = array(
+ 'screen_name' => $account, // Twitter account name
+ 'trim_user' => true, // only basic user data (slims the result)
+ 'include_entities' => true
+ );
+
+ // If combined with $count, $exclude_replies only filters that number of tweets (not all tweets up to the requested count).
+ if ( $hidereplies )
+ $params['exclude_replies'] = true;
+ else
+ $params['count'] = $show;
+
+ if ( $include_retweets )
+ $params['include_rts'] = true;
+
+ $twitter_json_url = esc_url_raw( 'http://api.twitter.com/1/statuses/user_timeline.json?' . http_build_query( $params ), array( 'http', 'https' ) );
+ unset( $params );
+
+ $response = wp_remote_get( $twitter_json_url, array( 'User-Agent' => 'WordPress.com Twitter Widget' ) );
+ $response_code = wp_remote_retrieve_response_code( $response );
+
+ switch( $response_code ) {
+ case 200 : // process tweets and display
+ $tweets = json_decode( wp_remote_retrieve_body( $response ), true );
+
+ if ( ! is_array( $tweets ) || isset( $tweets['error'] ) ) {
+ do_action( 'jetpack_bump_stats_extras', 'twitter_widget', "request-fail-{$response_code}-bad-data" );
+ $the_error = '<p>' . esc_html__( 'Error: Twitter did not respond. Please wait a few minutes and refresh this page.', 'jetpack' ) . '</p>';
+ $tweet_cache_expire = 300;
+ break;
+ } else {
+ set_transient( 'widget-twitter-backup-' . $this->number, $tweets, 86400 ); // A one day backup in case there is trouble talking to Twitter
+ }
+
+ do_action( 'jetpack_bump_stats_extras', 'twitter_widget', 'request-success' );
+ $tweet_cache_expire = 900;
+ break;
+ case 401 : // display private stream notice
+ do_action( 'jetpack_bump_stats_extras', 'twitter_widget', "request-fail-{$response_code}" );
+
+ $tweets = array();
+ $the_error = '<p>' . sprintf( esc_html__( 'Error: Please make sure the Twitter account is %1$spublic%2$s.', 'jetpack' ), '<a href="http://support.twitter.com/forums/10711/entries/14016">', '</a>' ) . '</p>';
+ $tweet_cache_expire = 300;
+ break;
+ default : // display an error message
+ do_action( 'jetpack_bump_stats_extras', 'twitter_widget', "request-fail-{$response_code}" );
+
+ $tweets = get_transient( 'widget-twitter-backup-' . $this->number );
+ $the_error = '<p>' . esc_html__( 'Error: Twitter did not respond. Please wait a few minutes and refresh this page.', 'jetpack' ) . '</p>';
+ $tweet_cache_expire = 300;
+ break;
+ }
+
+ set_transient( 'widget-twitter-' . $this->number, $tweets, $tweet_cache_expire );
+ set_transient( 'widget-twitter-error-' . $this->number, $the_error, $tweet_cache_expire );
+ }
+
+ return array( 'data' => $tweets, 'error' => $the_error );
+ }
+
+ function update( $new_instance, $old_instance ) {
+ $instance = array();
+
+ $instance['account'] = trim( wp_kses( $new_instance['account'], array() ) );
+ $instance['account'] = str_replace( array( 'http://twitter.com/', '/', '@', '#!', ), array( '', '', '', '', ), $instance['account'] );
+
+ $instance['title'] = wp_kses( $new_instance['title'], array() );
+ $instance['show'] = absint( $new_instance['show'] );
+ $instance['hidereplies'] = isset( $new_instance['hidereplies'] );
+ $instance['hidepublicized'] = isset( $new_instance['hidepublicized'] );
+ $instance['includeretweets'] = isset( $new_instance['includeretweets'] );
+
+ if ( $instance['followbutton'] != $new_instance['followbutton'] ) {
+ if ( $new_instance['followbutton'] )
+ do_action( 'jetpack_bump_stats_extras', 'twitter_widget', 'follow_button_enabled' );
+ else
+ do_action( 'jetpack_bump_stats_extras', 'twitter_widget', 'follow_button_disabled' );
+ }
+
+ $instance['followbutton'] = ! isset( $new_instance['followbutton'] ) ? 0 : 1;
+ $instance['beforetimesince'] = $new_instance['beforetimesince'];
+
+ delete_transient( 'widget-twitter-' . $this->number );
+ delete_transient( 'widget-twitter-error-' . $this->number );
+
+ return $instance;
+ }
+
+ function form( $instance ) {
+ //Defaults
+ $account = isset( $instance['account'] ) ? wp_kses( $instance['account'], array() ) : '';
+ $title = isset( $instance['title'] ) ? $instance['title'] : '';
+ $show = isset( $instance['show'] ) ? absint( $instance['show'] ) : 5;
+ $show = ( $show < 1 || 20 < $show ) ? 5 : $show;
+ $hidereplies = isset( $instance['hidereplies'] ) && ! empty( $instance['hidereplies'] ) ? (bool) $instance['hidereplies'] : false;
+ $hidepublicized = isset( $instance['hidepublicized'] ) && ! empty( $instance['hidepublicized'] ) ? (bool) $instance['hidepublicized'] : false;
+ $include_retweets = isset( $instance['includeretweets'] ) && ! empty( $instance['includeretweets'] ) ? (bool) $instance['includeretweets'] : false;
+ $follow_button = isset( $instance['followbutton'] ) && ! empty( $instance['followbutton'] ) ? 1 : 0;
+ $before_timesince = isset( $instance['beforetimesince'] ) && ! empty( $instance['beforetimesince'] ) ? esc_attr( $instance['beforetimesince'] ) : '';
+ ?>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>">
+ <?php esc_html_e( 'Title:', 'jetpack' )?>
+ <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( $title ); ?>" />
+ </label>
+ </p>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'account' ); ?>">
+ <?php esc_html_e( 'Twitter username:', 'jetpack' ); ?> <a href="http://support.wordpress.com/widgets/twitter-widget/#twitter-username" target="_blank">( ? )</a>
+ <input class="widefat" id="<?php echo $this->get_field_id( 'account' ); ?>" name="<?php echo $this->get_field_name( 'account' ); ?>" type="text" value="<?php echo esc_attr( $account ); ?>" />
+ </label>
+ </p>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'show' ); ?>">
+ <?php esc_html_e( 'Maximum number of Tweets to show:', 'jetpack' ); ?>
+ <select id="<?php echo $this->get_field_id( 'show' ); ?>" name="<?php echo $this->get_field_name( 'show' ); ?>">
+ <?php
+ for ( $i = 1; $i <= 20; ++$i ) :
+ ?><option value="<?php echo esc_attr( $i ); ?>" <?php selected( $show, $i ); ?>><?php echo esc_attr( $i ); ?></option><?php
+ endfor;
+ ?>
+ </select>
+ </label>
+ </p>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'hidereplies' ); ?>">
+ <input id="<?php echo $this->get_field_id( 'hidereplies' );?>" class="checkbox" type="checkbox" name="<?php echo $this->get_field_name( 'hidereplies' ); ?>" <?php checked( $hidereplies, true ); ?> />
+ <?php esc_html_e( 'Hide replies', 'jetpack' ); ?>
+ </label>
+ </p>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'hidepublicized' ); ?>">
+ <input id="<?php echo $this->get_field_id( 'hidepublicized' ); ?>" class="checkbox" type="checkbox" name="<?php echo $this->get_field_name( 'hidepublicized' ); ?>" <?php checked( $hidepublicized, true ); ?> />
+ <?php esc_html_e( 'Hide Tweets pushed by Publicize', 'jetpack' ); ?>
+ </label>
+ </p>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'includeretweets' ); ?>">
+ <input id="<?php echo $this->get_field_id( 'includeretweets' ); ?>" class="checkbox" type="checkbox" name="<?php echo $this->get_field_name( 'includeretweets' ); ?>" <?php checked( $include_retweets, true ); ?> />
+ <?php esc_html_e( 'Include retweets', 'jetpack' ); ?>
+ </label>
+ </p>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'followbutton' ); ?>">
+ <input id="<?php echo $this->get_field_id( 'followbutton' ); ?>" class="checkbox" type="checkbox" name="<?php echo $this->get_field_name( 'followbutton' ); ?>" <?php checked( $follow_button, 1 ); ?> />
+ <?php esc_html_e( 'Display Follow Button', 'jetpack' ); ?>
+ </label>
+ </p>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'beforetimesince' ); ?>">
+ <?php esc_html_e( 'Text to display between Tweet and timestamp:', 'jetpack' ); ?>
+ <input class="widefat" id="<?php echo $this->get_field_id( 'beforetimesince' ); ?>" name="<?php echo $this->get_field_name( 'beforetimesince' ); ?>" type="text" value="<?php echo esc_attr( $before_timesince ); ?>" />
+ </label>
+ </p>
+
+ <?php
+ }
+
+ function time_since( $original, $do_more = 0 ) {
+ // array of time period chunks
+ $chunks = array(
+ array(60 * 60 * 24 * 365 , 'year'),
+ array(60 * 60 * 24 * 30 , 'month'),
+ array(60 * 60 * 24 * 7, 'week'),
+ array(60 * 60 * 24 , 'day'),
+ array(60 * 60 , 'hour'),
+ array(60 , 'minute'),
+ );
+
+ $today = time();
+ $since = $today - $original;
+
+ for ($i = 0, $j = count($chunks); $i < $j; $i++) {
+ $seconds = $chunks[$i][0];
+ $name = $chunks[$i][1];
+
+ if (($count = floor($since / $seconds)) != 0)
+ break;
+ }
+
+ $print = ($count == 1) ? '1 '.$name : "$count {$name}s";
+
+ if ($i + 1 < $j) {
+ $seconds2 = $chunks[$i + 1][0];
+ $name2 = $chunks[$i + 1][1];
+
+ // add second item if it's greater than 0
+ if ( (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0) && $do_more )
+ $print .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$name2}s";
+ }
+ return $print;
+ }
+
+ /**
+ * Link a Twitter user mentioned in the tweet text to the user's page on Twitter.
+ *
+ * @param array $matches regex match
+ * @return string Tweet text with inserted @user link
+ */
+ function _jetpack_widget_twitter_username( array $matches ) { // $matches has already been through wp_specialchars
+ return "$matches[1]@<a href='" . esc_url( 'http://twitter.com/' . urlencode( $matches[3] ) ) . "'>$matches[3]</a>";
+ }
+
+ /**
+ * Link a Twitter hashtag with a search results page on Twitter.com
+ *
+ * @param array $matches regex match
+ * @return string Tweet text with inserted #hashtag link
+ */
+ function _jetpack_widget_twitter_hashtag( array $matches ) { // $matches has already been through wp_specialchars
+ return "$matches[1]<a href='" . esc_url( 'http://twitter.com/search?q=%23' . urlencode( $matches[3] ) ) . "'>#$matches[3]</a>";
+ }
+
+ function twitter_widget_script() {
+ if ( ! wp_script_is( 'twitter-widgets', 'registered' ) ) {
+ if ( is_ssl() )
+ $twitter_widget_js = 'https://platform.twitter.com/widgets.js';
+ else
+ $twitter_widget_js = 'http://platform.twitter.com/widgets.js';
+ wp_register_script( 'twitter-widgets', $twitter_widget_js, array(), '20111117', true );
+ wp_print_scripts( 'twitter-widgets' );
+ }
+ }
+}
diff --git a/plugins/jetpack/modules/widgets/widget-grid-and-list.css b/plugins/jetpack/modules/widgets/widget-grid-and-list.css
new file mode 100644
index 00000000..984016c9
--- /dev/null
+++ b/plugins/jetpack/modules/widgets/widget-grid-and-list.css
@@ -0,0 +1,110 @@
+/* 2-Column Grid Layout */
+
+.widgets-grid-layout {
+ width: 100%;
+}
+
+.widgets-grid-layout:before,
+.widgets-grid-layout:after {
+ content: " ";
+ display: table;
+}
+
+.widgets-grid-layout:after {
+ clear: both;
+}
+
+.widget-grid-view-image {
+ float: left;
+ max-width: 50%;
+}
+
+.widget-grid-view-image a {
+ display: block;
+ margin: 0 2px 4px 0;
+}
+
+.widget-grid-view-image:image:nth-child(even) {
+ float: right;
+}
+
+.widget-grid-view-image:nth-child(even) a {
+ margin: 0 0 4px 2px;
+}
+
+.widgets-grid-layout .widget-grid-view-image img {
+ max-width: 100%;
+ height: auto;
+}
+
+/* Multi-Column Grid Layout */
+
+.widgets-multi-column-grid ul {
+ overflow: hidden;
+ padding: 0;
+ margin: 0;
+ list-style-type: none;
+}
+
+.widgets-multi-column-grid ul li {
+ background: none;
+ clear: none;
+ float: left;
+ margin: 0 -5px -3px 0;
+ padding: 0 8px 6px 0;
+ border: none;
+ list-style-type: none !important;
+}
+
+.widgets-multi-column-grid ul li a {
+ background: none;
+ margin: 0;
+ padding: 0;
+ border: 0;
+}
+
+.widgets-multi-column-grid .avatar {
+ vertical-align: middle;
+}
+
+/* List Layout */
+
+.widgets-list-layout {
+ padding: 0;
+ margin: 0;
+ list-style-type: none;
+}
+
+.widgets-list-layout li:before,
+.widgets-list-layout li:after {
+ content:"";
+ display:table;
+}
+.widgets-list-layout li:after {
+ clear:both;
+}
+.widgets-list-layout li {
+ zoom:1;
+ margin-bottom: 1em;
+ list-style-type: none !important;
+}
+
+.widgets-list-layout .widgets-list-layout-blavatar {
+ float: left;
+ width: 21.276596%;
+ max-width: 40px;
+ height: auto;
+}
+
+.widgets-list-layout-links {
+ float: right;
+ width: 73.404255%;
+}
+
+.widgets-list-layout span {
+ opacity: 0.5;
+}
+
+.widgets-list-layout span:hover {
+ opacity: 0.8;
+}
diff --git a/plugins/jetpack/modules/widgets/widgets.css b/plugins/jetpack/modules/widgets/widgets.css
new file mode 100644
index 00000000..a2d62957
--- /dev/null
+++ b/plugins/jetpack/modules/widgets/widgets.css
@@ -0,0 +1,13 @@
+/*
+ * Widget styles for Jetpack
+ */
+
+/* Clear floats */
+.jetpack-image-container:after {
+ clear: both;
+}
+.jetpack-image-container:before,
+.jetpack-image-container:after {
+ display: table;
+ content: "";
+}