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 & Pages', 'jetpack' ) ), array( 'description' => __( 'Shows your most viewed posts and pages.', 'jetpack' ), ) ); $this->default_title = __( 'Top Posts & 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 || 10 < $count ) { $count = 10; } if ( isset( $instance['display'] ) && in_array( $instance['display'], array( 'grid', 'list', 'text' ) ) ) { $display = $instance['display']; } else { $display = 'text'; } ?>
' . sprintf( __( 'There are no posts to display. Want more traffic?', 'jetpack' ), 'http://en.support.wordpress.com/getting-more-site-traffic/' ) . '
'; } 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'], array( 'fallback_to_avatars' => true ) ); $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 "