Initial Commit

This commit is contained in:
Rumperuu 2018-03-21 18:19:20 +00:00
parent 4c352bf02e
commit 1ab6e5f0b0
1085 changed files with 195258 additions and 0 deletions

View file

@ -0,0 +1,295 @@
<?php
if ( ! class_exists( 'Jetpack_Contact_Info_Widget' ) ) {
//register Contact_Info_Widget widget
function jetpack_contact_info_widget_init() {
register_widget( 'Jetpack_Contact_Info_Widget' );
}
add_action( 'widgets_init', 'jetpack_contact_info_widget_init' );
/**
* Makes a custom Widget for displaying Resturant Location, Hours and Contact Info available.
*
* @package WordPress
*/
class Jetpack_Contact_Info_Widget extends WP_Widget {
/**
* Constructor
*
* @return void
**/
function __construct() {
$widget_ops = array(
'classname' => 'widget_contact_info',
'description' => __( 'Display your location, hours, and contact information.', 'jetpack' ),
'customize_selective_refresh' => true,
);
parent::__construct(
'widget_contact_info',
/** This filter is documented in modules/widgets/facebook-likebox.php */
apply_filters( 'jetpack_widget_name', __( 'Contact Info', 'jetpack' ) ),
$widget_ops
);
$this->alt_option_name = 'widget_contact_info';
if ( is_customize_preview() ) {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
}
}
/**
* Enqueue scripts and styles.
*/
public function enqueue_scripts() {
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'google-maps', 'https://maps.googleapis.com/maps/api/js?sensor=false' );
wp_enqueue_script( 'contact-info-map-js', plugins_url( 'contact-info/contact-info-map.js', __FILE__ ), array( 'jquery', 'google-maps' ), 20150127 );
wp_enqueue_style( 'contact-info-map-css', plugins_url( 'contact-info/contact-info-map.css', __FILE__ ), null, 20150127 );
}
/**
* Return an associative array of default values
*
* These values are used in new widgets.
*
* @return array Array of default values for the Widget's options
*/
public function defaults() {
return array(
'title' => __( 'Hours & Info', 'jetpack' ),
'address' => __( "3999 Mission Boulevard,\nSan Diego CA 92109", 'jetpack' ),
'phone' => _x( '1-202-555-1212', 'Example of a phone number', 'jetpack' ),
'hours' => __( "Lunch: 11am - 2pm \nDinner: M-Th 5pm - 11pm, Fri-Sat:5pm - 1am", 'jetpack' ),
'showmap' => 1,
'lat' => null,
'lon' => null
);
}
/**
* Outputs the HTML for this widget.
*
* @param array An array of standard parameters for widgets in this theme
* @param array An array of settings for this widget instance
* @return void Echoes it's output
**/
function widget( $args, $instance ) {
$instance = wp_parse_args( $instance, $this->defaults() );
extract( $args, EXTR_SKIP );
echo $before_widget;
if ( $instance['title'] != '' )
echo $before_title . $instance['title'] . $after_title;
/**
* Fires at the beginning of the Contact Info widget, after the title.
*
* @module widgets
*
* @since 3.9.2
*/
do_action( 'jetpack_contact_info_widget_start' );
$map_link = 0;
if ( $instance['address'] != '' ) {
$showmap = $instance['showmap'];
if ( $showmap && $this->has_good_map( $instance ) ) {
$lat = $instance['lat'];
$lon = $instance['lon'];
echo $this->build_map( $lat, $lon );
}
$map_link = $this->build_map_link( $instance['address'] );
echo '<div class="confit-address"><a href="' . esc_url( $map_link ) . '" target="_blank">' . str_replace( "\n", "<br/>", esc_html( $instance['address'] ) ) . "</a></div>";
}
if ( $instance['phone'] != '' ) {
if( wp_is_mobile() ) {
echo '<div class="confit-phone"><a href="'. esc_url( 'tel:'. $instance['phone'] ) . '">' . esc_html( $instance['phone'] ) . "</a></div>";
} else {
echo '<div class="confit-phone">' . esc_html( $instance['phone'] ) . '</div>';
}
}
if ( $instance['hours'] != '' ) {
echo '<div class="confit-hours">' . str_replace( "\n", "<br/>", esc_html( $instance['hours'] ) ) . "</div>";
}
/**
* Fires at the end of Contact Info widget.
*
* @module widgets
*
* @since 3.9.2
*/
do_action( 'jetpack_contact_info_widget_end' );
echo $after_widget;
}
/**
* Deals with the settings when they are saved by the admin. Here is
* where any validation should be dealt with.
**/
function update( $new_instance, $old_instance ) {
$update_lat_lon = false;
if ( $this->urlencode_address( $old_instance['address'] ) != $this->urlencode_address( $new_instance['address'] ) ) {
$update_lat_lon = true;
}
$instance = array();
$instance['title'] = wp_kses( $new_instance['title'], array() );
$instance['address'] = wp_kses( $new_instance['address'], array() );
$instance['phone'] = wp_kses( $new_instance['phone'], array() );
$instance['hours'] = wp_kses( $new_instance['hours'], array() );
$instance['lat'] = isset( $old_instance['lat'] ) ? floatval( $old_instance['lat'] ) : 0;
$instance['lon'] = isset( $old_instance['lon'] ) ? floatval( $old_instance['lon'] ) : 0;
if ( ! $instance['lat'] || ! $instance['lon'] ) {
$update_lat_lon = true;
}
if ( $instance['address'] && $update_lat_lon ) {
// Get the lat/lon of the user specified address.
$address = $this->urlencode_address( $instance['address'] );
$path = "http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=" . $address;
$json = wp_remote_retrieve_body( wp_remote_get( $path ) );
if ( ! $json ) {
// The read failed :(
esc_html_e( "There was a problem getting the data to display this address on a map. Please refresh your browser and try again.", 'jetpack' );
die();
}
$json_obj = json_decode( $json );
if ( $err = $json_obj->status == "ZERO_RESULTS" ) {
// The address supplied does not have a matching lat / lon.
// No map is available.
$instance['lat'] = "0";
$instance['lon'] = "0";
} else {
$loc = $json_obj->results[0]->geometry->location;
$lat = floatval( $loc->lat );
$lon = floatval( $loc->lng );
$instance['lat'] = "$lat";
$instance['lon'] = "$lon";
}
}
if ( ! isset( $new_instance['showmap'] ) ) {
$instance['showmap'] = 0;
} else {
$instance['showmap'] = intval( $new_instance['showmap'] );
}
return $instance;
}
/**
* Displays the form for this widget on the Widgets page of the WP Admin area.
**/
function form( $instance ) {
$instance = wp_parse_args( $instance, $this->defaults() );
extract( $instance );
$disabled = !$this->has_good_map( $instance );
?>
<p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'jetpack' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /></p>
<p><label for="<?php echo esc_attr( $this->get_field_id( 'address' ) ); ?>"><?php esc_html_e( 'Address:', 'jetpack' ); ?></label>
<textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'address' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'address' ) ); ?>"><?php echo esc_textarea( $address ); ?></textarea>
<?php
if ( $this->has_good_map( $instance ) ) {
?>
<input class="" id="<?php echo esc_attr( $this->get_field_id( 'showmap' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'showmap' ) ); ?>" value="1" type="checkbox" <?php checked( $showmap , 1); ?> />
<label for="<?php echo esc_attr( $this->get_field_id( 'showmap' ) ); ?>"><?php esc_html_e( 'Show map', 'jetpack' ); ?></label></p>
<?php
} else {
?>
<span class="error-message"><?php _e( 'Sorry. We can not plot this address. A map will not be displayed. Is the address formatted correctly?', 'jetpack' ); ?></span></p>
<input id="<?php echo esc_attr( $this->get_field_id( 'showmap' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'showmap' ) ); ?>" value="<?php echo( intval( $instance['showmap'] ) ); ?>" type="hidden" />
<?php
}
?>
<p><label for="<?php echo esc_attr( $this->get_field_id( 'phone' ) ); ?>"><?php esc_html_e( 'Phone:', 'jetpack' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'phone' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'phone' ) ); ?>" type="text" value="<?php echo esc_attr( $phone ); ?>" /></p>
<p><label for="<?php echo esc_attr( $this->get_field_id( 'hours' ) ); ?>"><?php esc_html_e( 'Hours:', 'jetpack' ); ?></label>
<textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'hours' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'hours' ) ); ?>"><?php echo esc_textarea( $hours ); ?></textarea></p>
<?php
}
function build_map_link( $address ) {
// Google map urls have lots of available params but zoom (z) and query (q) are enough.
return "http://maps.google.com/maps?z=16&q=" . $this->urlencode_address( $address );
}
function build_map( $lat, $lon ) {
$this->enqueue_scripts();
$lat = esc_attr( $lat );
$lon = esc_attr( $lon );
$html = <<<EOT
<div class="contact-map">
<input type="hidden" class="contact-info-map-lat" value="$lat" />
<input type="hidden" class="contact-info-map-lon" value="$lon" />
<div class="contact-info-map-canvas"></div></div>
EOT;
return $html;
}
function urlencode_address( $address ) {
$address = strtolower( $address );
$address = preg_replace( "/\s+/", " ", trim( $address ) ); // Get rid of any unwanted whitespace
$address = str_ireplace( " ", "+", $address ); // Use + not %20
urlencode( $address );
return $address;
}
function has_good_map( $instance ) {
// The lat and lon of an address that could not be plotted will have values of 0 and 0.
return ! ( $instance['lat'] == "0" && $instance['lon'] == "0" );
}
}
}

View file

@ -0,0 +1,11 @@
.contact-info-map-canvas {
height: 216px;
margin: 0;
padding: 0;
overflow: hidden;
}
/* Prevent Google maps controls from being hidden */
.gmnoprint img {
max-width: none !important;
}

View file

@ -0,0 +1,41 @@
/* global google */
/* jshint unused:false */
jQuery( function( $ ) {
function setupContactMaps( rootElement ) {
rootElement = $( rootElement || document.body );
rootElement.find( 'div.contact-map' ).each( function() {
// get lat and lon from hidden input values
var lat = jQuery(this).find('.contact-info-map-lat').val(),
lon = jQuery(this).find('.contact-info-map-lon').val(),
lat_lon = new google.maps.LatLng( lat, lon ),
mapOptions = {
zoom: 16,
center: lat_lon,
mapTypeId: google.maps.MapTypeId.ROADMAP
},
map = new google.maps.Map(jQuery(this).find('.contact-info-map-canvas')[0], mapOptions),
marker = new google.maps.Marker({
map: map,
position: lat_lon
});
google.maps.event.addListenerOnce(map, 'mouseover', function() {
google.maps.event.trigger(map, 'resize');
});
});
}
setupContactMaps();
if ( wp && wp.customize && wp.customizerHasPartialWidgetRefresh() ) {
wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function( placement ) {
if ( wp.isJetpackWidgetPlaced( placement, 'widget_contact_info' ) ) {
setupContactMaps( placement.container );
}
} );
}
} );

View file

@ -0,0 +1,76 @@
/* global gapi, FB, twttr */
/**
* Utilities to work with widgets in Customizer.
*/
/**
* Checks whether this Customizer supports partial widget refresh.
* @returns {boolean}
*/
wp.customizerHasPartialWidgetRefresh = function() {
return 'object' === typeof wp && 'function' === typeof wp.customize && 'object' === typeof wp.customize.selectiveRefresh && 'object' === typeof wp.customize.widgetsPreview && 'function' === typeof wp.customize.widgetsPreview.WidgetPartial;
};
/**
* Verifies that the placed widget ID contains the widget name.
* @param {object} placement
* @param {string} widgetName
* @returns {*|boolean}
*/
wp.isJetpackWidgetPlaced = function( placement, widgetName ) {
return placement.partial.widgetId && 0 === placement.partial.widgetId.indexOf( widgetName );
};
/**
* Bind events for selective refresh in Customizer.
*/
(function($){
$( document ).ready( function() {
if ( wp && wp.customize && wp.customizerHasPartialWidgetRefresh() ) {
// Refresh widget contents when a partial is rendered.
wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function ( placement ) {
if ( placement.container ) {
// Refresh Google+
if ( wp.isJetpackWidgetPlaced( placement, 'googleplus-badge' ) && 'object' === typeof gapi && gapi.person && 'function' === typeof gapi.person.go ) {
gapi.person.go( placement.container[0] );
}
// Refresh Facebook XFBML
else if ( wp.isJetpackWidgetPlaced( placement, 'facebook-likebox' ) && 'object' === typeof FB && 'object' === typeof FB.XFBML && 'function' === typeof FB.XFBML.parse ) {
FB.XFBML.parse( placement.container[0], function() {
var $fbContainer = $( placement.container[0] ).find( '.fb_iframe_widget' ),
fbWidth = $fbContainer.data( 'width' ),
fbHeight = $fbContainer.data( 'height' );
$fbContainer.find( 'span' ).css( { 'width': fbWidth, 'height': fbHeight } );
setTimeout( function() {
$fbContainer.find( 'iframe' ).css( { 'width': fbWidth, 'height': fbHeight, 'position': 'relative' } );
}, 1 );
} );
}
// Refresh Twitter
else if ( wp.isJetpackWidgetPlaced( placement, 'twitter_timeline' ) && 'object' === typeof twttr && 'object' === typeof twttr.widgets && 'function' === typeof twttr.widgets.load ) {
twttr.widgets.load( placement.container[0] );
}
}
} );
// Refresh widgets when they're moved.
wp.customize.selectiveRefresh.bind( 'partial-content-moved', function( placement ) {
if ( placement.container ) {
// Refresh Twitter timeline iframe, since it has to be re-built.
if ( wp.isJetpackWidgetPlaced( placement, 'twitter_timeline' ) && placement.container.find( 'iframe.twitter-timeline:not([src]):first' ).length ) {
placement.partial.refresh();
}
}
} );
}
});
})(jQuery);

View file

@ -0,0 +1,304 @@
<?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 Page Plugin (formely known as the Like Box)
* Display a Facebook Page Plugin as a widget (replaces the old like box plugin)
* https://developers.facebook.com/docs/plugins/page-plugin
*/
class WPCOM_Widget_Facebook_LikeBox extends WP_Widget {
private $default_height = 580;
private $default_width = 340;
private $max_width = 500;
private $min_width = 180;
private $max_height = 9999;
private $min_height = 130;
function __construct() {
parent::__construct(
'facebook-likebox',
/**
* Filter the name of a widget included in the Extra Sidebar Widgets module.
*
* @module widgets
*
* @since 2.1.2
*
* @param string $widget_name Widget title.
*/
apply_filters( 'jetpack_widget_name', __( 'Facebook Page Plugin', 'jetpack' ) ),
array(
'classname' => 'widget_facebook_likebox',
'description' => __( 'Use the Facebook Page Plugin to connect visitors to your Facebook Page', 'jetpack' ),
'customize_selective_refresh' => true,
)
);
if ( is_active_widget( false, false, $this->id_base ) || is_active_widget( false, false, 'monster' ) || is_customize_preview() ) {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
}
}
/**
* Enqueue scripts.
*/
public function enqueue_scripts() {
wp_enqueue_script( 'jetpack-facebook-embed' );
wp_enqueue_style( 'jetpack_facebook_likebox', plugins_url( 'facebook-likebox/style.css', __FILE__ ) );
wp_style_add_data( 'jetpack_facebook_likebox', 'jetpack-inline', true );
}
function widget( $args, $instance ) {
extract( $args );
$like_args = $this->normalize_facebook_args( $instance['like_args'] );
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>.', 'jetpack' ), admin_url( 'widgets.php' ) ) . '</p>';
echo $after_widget;
}
echo '<!-- Invalid Facebook Page URL -->';
return;
}
/** This filter is documented in core/src/wp-includes/default-widgets.php */
$title = apply_filters( 'widget_title', $instance['title'] );
$page_url = set_url_scheme( $like_args['href'], 'https' );
$like_args['show_faces'] = (bool) $like_args['show_faces'] ? 'true' : 'false';
$like_args['stream'] = (bool) $like_args['stream'] ? 'true' : 'false';
$like_args['cover'] = (bool) $like_args['cover'] ? 'false' : 'true';
echo $before_widget;
if ( ! empty( $title ) ) :
echo $before_title;
$likebox_widget_title = '<a href="' . esc_url( $page_url ) . '">' . esc_html( $title ) . '</a>';
/**
* Filter Facebook Likebox's widget title.
*
* @module widgets
*
* @since 3.3.0
*
* @param string $likebox_widget_title Likebox Widget title (including a link to the Page URL).
* @param string $title Widget title as set in the widget settings.
* @param string $page_url Facebook Page URL.
*/
echo apply_filters( 'jetpack_facebook_likebox_title', $likebox_widget_title, $title, $page_url );
echo $after_title;
endif;
?>
<div id="fb-root"></div>
<div class="fb-page" data-href="<?php echo esc_url( $page_url ); ?>" data-width="<?php echo intval( $like_args['width'] ); ?>" data-height="<?php echo intval( $like_args['height'] ); ?>" data-hide-cover="<?php echo esc_attr( $like_args['cover'] ); ?>" data-show-facepile="<?php echo esc_attr( $like_args['show_faces'] ); ?>" data-show-posts="<?php echo esc_attr( $like_args['stream'] ); ?>">
<div class="fb-xfbml-parse-ignore"><blockquote cite="<?php echo esc_url( $page_url ); ?>"><a href="<?php echo esc_url( $page_url ); ?>"><?php echo esc_html( $title ); ?></a></blockquote></div>
</div>
<?php
wp_enqueue_script( 'jetpack-facebook-embed' );
echo $after_widget;
/** This action is already documented in modules/widgets/gravatar-profile.php */
do_action( 'jetpack_stats_extra', 'widget', 'facebook-likebox' );
}
function update( $new_instance, $old_instance ) {
$instance = array(
'title' => '',
'like_args' => $this->get_default_args(),
);
$instance['title'] = trim( strip_tags( stripslashes( $new_instance['title'] ) ) );
// Set up widget values
$instance['like_args'] = array(
'href' => trim( strip_tags( stripslashes( $new_instance['href'] ) ) ),
'width' => (int) $new_instance['width'],
'height' => (int) $new_instance['height'],
'show_faces' => isset( $new_instance['show_faces'] ),
'stream' => isset( $new_instance['stream'] ),
'cover' => isset( $new_instance['cover'] ),
);
$instance['like_args'] = $this->normalize_facebook_args( $instance['like_args'] );
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array(
'title' => '',
'like_args' => $this->get_default_args()
) );
$like_args = $this->normalize_facebook_args( $instance['like_args'] );
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>">
<?php _e( 'Title', 'jetpack' ); ?>
<input type="text" name="<?php echo $this->get_field_name( 'title' ); ?>" id="<?php echo $this->get_field_id( 'title' ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat" />
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'href' ); ?>">
<?php _e( 'Facebook Page URL', 'jetpack' ); ?>
<input type="text" name="<?php echo $this->get_field_name( 'href' ); ?>" id="<?php echo $this->get_field_id( 'href' ); ?>" value="<?php echo esc_url( $like_args['href'] ); ?>" class="widefat" />
<br />
<small><?php _e( 'The widget only works with Facebook Pages.', 'jetpack' ); ?></small>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'width' ); ?>">
<?php _e( 'Width', 'jetpack' ); ?>
<input type="number" class="smalltext" min="1" max="999" maxlength="3" name="<?php echo $this->get_field_name( 'width' ); ?>" id="<?php echo $this->get_field_id( 'width' ); ?>" value="<?php echo esc_attr( $like_args['width'] ); ?>" style="text-align: center;" />px
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'height' ); ?>">
<?php _e( 'Height', 'jetpack' ); ?>
<input type="number" class="smalltext" min="1" max="999" maxlength="3" name="<?php echo $this->get_field_name( 'height' ); ?>" id="<?php echo $this->get_field_id( 'height' ); ?>" value="<?php echo esc_attr( $like_args['height'] ); ?>" style="text-align: center;" />px
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'show_faces' ); ?>">
<input type="checkbox" name="<?php echo $this->get_field_name( 'show_faces' ); ?>" id="<?php echo $this->get_field_id( 'show_faces' ); ?>" <?php checked( $like_args['show_faces'] ); ?> />
<?php _e( 'Show Faces', 'jetpack' ); ?>
<br />
<small><?php _e( 'Show profile photos in the plugin.', 'jetpack' ); ?></small>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'stream' ); ?>">
<input type="checkbox" name="<?php echo $this->get_field_name( 'stream' ); ?>" id="<?php echo $this->get_field_id( 'stream' ); ?>" <?php checked( $like_args['stream'] ); ?> />
<?php _e( 'Show Stream', 'jetpack' ); ?>
<br />
<small><?php _e( 'Show Page Posts.', 'jetpack' ); ?></small>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'cover' ); ?>">
<input type="checkbox" name="<?php echo $this->get_field_name( 'cover' ); ?>" id="<?php echo $this->get_field_id( 'cover' ); ?>" <?php checked( $like_args['cover'] ); ?> />
<?php _e( 'Show Cover Photo', 'jetpack' ); ?>
<br />
</label>
</p>
<?php
}
function get_default_args() {
$defaults = array(
'href' => '',
'width' => $this->default_width,
'height' => $this->default_height,
'show_faces' => 'true',
'stream' => '',
'cover' => 'true',
);
/**
* Filter Facebook Likebox default options.
*
* @module widgets
*
* @since 1.3.1
*
* @param array $defaults Array of default options.
*/
return apply_filters( 'jetpack_facebook_likebox_defaults', $defaults );
}
function normalize_facebook_args( $args ) {
$args = wp_parse_args( (array) $args, $this->get_default_args() );
// Validate the Facebook Page URL
if ( $this->is_valid_facebook_url( $args['href'] ) ) {
$temp = explode( '?', $args['href'] );
$args['href'] = str_replace( array( 'http://facebook.com', 'https://facebook.com' ), array( 'http://www.facebook.com', 'https://www.facebook.com' ), $temp[0] );
} else {
$args['href'] = '';
}
$args['width'] = $this->normalize_int_value( (int) $args['width'], $this->default_width, $this->max_width, $this->min_width );
$args['height'] = $this->normalize_int_value( (int) $args['height'], $this->default_height, $this->max_height, $this->min_height );
$args['show_faces'] = (bool) $args['show_faces'];
$args['stream'] = (bool) $args['stream'];
$args['cover'] = (bool) $args['cover'];
// The height used to be dependent on other widget settings
// If the user changes those settings but doesn't customize the height,
// let's intelligently assign a new height.
if ( in_array( $args['height'], array( 580, 110, 432 ) ) ) {
if ( $args['show_faces'] && $args['stream'] ) {
$args['height'] = 580;
} else if ( ! $args['show_faces'] && ! $args['stream'] ) {
$args['height'] = 130;
} else {
$args['height'] = 432;
}
}
return $args;
}
function is_valid_facebook_url( $url ) {
return ( FALSE !== strpos( $url, 'facebook.com' ) ) ? TRUE : FALSE;
}
function normalize_int_value( $value, $default = 0, $max = 0, $min = 0 ) {
$value = (int) $value;
if ( $max < $value || $min > $value )
$value = $default;
return (int) $value;
}
function normalize_text_value( $value, $default = '', $allowed = array() ) {
$allowed = (array) $allowed;
if ( empty( $value ) || ( ! empty( $allowed ) && ! in_array( $value, $allowed ) ) )
$value = $default;
return $value;
}
/**
* @deprecated
*/
function guess_locale_from_lang( $lang ) {
_deprecated_function( __METHOD__, '4.0.0', 'Jetpack::guess_locale_from_lang()' );
Jetpack::$instance->get_locale_from_lang( $lang );
}
/**
* @deprecated
*/
function get_locale() {
_deprecated_function( __METHOD__, '4.0.0', 'Jetpack::get_locale()' );
Jetpack::$instance->get_locale();
}
}
// END

View file

@ -0,0 +1,3 @@
.widget_facebook_likebox {
overflow: hidden;
}

View file

@ -0,0 +1,433 @@
<?php
/*
Plugin Name: Gallery
Description: Gallery widget
Author: Automattic, Inc.
Version: 1.0
Author URI: http://automattic.com
*/
class Jetpack_Gallery_Widget extends WP_Widget {
const THUMB_SIZE = 45;
const DEFAULT_WIDTH = 265;
protected $_instance_width ;
public function __construct() {
$widget_ops = array(
'classname' => 'widget-gallery',
'description' => __( 'Display a photo gallery or slideshow', 'jetpack' ),
'customize_selective_refresh' => true,
);
$control_ops = array( 'width' => 250 );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
parent::__construct(
'gallery',
/** This filter is documented in modules/widgets/facebook-likebox.php */
apply_filters( 'jetpack_widget_name', __( 'Gallery', 'jetpack' ) ),
$widget_ops,
$control_ops
);
if ( is_customize_preview() ) {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_scripts' ) );
if ( class_exists( 'Jetpack_Tiled_Gallery' ) ) {
$tiled_gallery = new Jetpack_Tiled_Gallery();
add_action( 'wp_enqueue_scripts', array( $tiled_gallery, 'default_scripts_and_styles' ) );
}
if ( class_exists( 'Jetpack_Slideshow_Shortcode' ) ) {
$slideshow = new Jetpack_Slideshow_Shortcode();
add_action( 'wp_enqueue_scripts', array( $slideshow, 'enqueue_scripts' ) );
}
if ( class_exists( 'Jetpack_Carousel' ) ) {
$carousel = new Jetpack_Carousel();
add_action( 'wp_enqueue_scripts', array( $carousel, 'enqueue_assets' ) );
}
}
}
/**
* @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
* @param array $instance The settings for the particular instance of the widget.
*/
public function widget( $args, $instance ) {
$instance = wp_parse_args( (array) $instance, $this->defaults() );
$this->enqueue_frontend_scripts();
extract( $args );
$instance['attachments'] = $this->get_attachments( $instance );
$classes = array();
$classes[] = 'widget-gallery-' . $instance['type'];
// Due to a bug in the carousel plugin, carousels will be triggered for all tiled galleries that exist on a page
// with other tiled galleries, regardless of whether or not the widget was set to Carousel mode. The onClick selector
// is simply too broad, since it was not written with widgets in mind. This special class prevents that behavior, via
// an override handler in gallery.js
if( 'carousel' != $instance['link'] && 'slideshow' != $instance['type'] )
$classes[] = 'no-carousel';
else
$classes[] = 'carousel';
$classes = implode( ' ', $classes );
if ( 'carousel' == $instance['link'] ) {
require_once plugin_dir_path( realpath( dirname( __FILE__ ) . '/../carousel/jetpack-carousel.php' ) ) . 'jetpack-carousel.php';
if ( class_exists( 'Jetpack_Carousel' ) ) {
// Create new carousel so we can use the enqueue_assets() method. Not ideal, but there is a decent amount
// of logic in that method that shouldn't be duplicated.
$carousel = new Jetpack_Carousel();
// First parameter is $output, which comes from filters, and causes bypass of the asset enqueuing. Passing null is correct.
$carousel->enqueue_assets( null );
}
}
echo $before_widget . "\n";
/** This filter is documented in core/src/wp-includes/default-widgets.php */
$title = apply_filters( 'widget_title', $instance['title'] );
if ( $title )
echo $before_title . esc_html( $title ) . $after_title . "\n";
echo '<div class="' . esc_attr( $classes ) . '">' . "\n";
$method = $instance['type'] . '_widget';
/**
* Allow the width of a gallery to be altered by themes or other code.
*
* @module widgets
*
* @since 2.5.0
*
* @param int self::DEFAULT_WIDTH Default gallery width. Default is 265.
* @param string $args Display arguments including before_title, after_title, before_widget, and after_widget.
* @param array $instance The settings for the particular instance of the widget.
*/
$this->_instance_width = apply_filters( 'gallery_widget_content_width', self::DEFAULT_WIDTH, $args, $instance );
// Register a filter to modify the tiled_gallery_content_width, so Jetpack_Tiled_Gallery
// can appropriately size the tiles.
add_filter( 'tiled_gallery_content_width', array( $this, 'tiled_gallery_content_width' ) );
if ( method_exists( $this, $method ) )
echo $this->$method( $args, $instance );
// Remove the stored $_instance_width, as it is no longer needed
$this->_instance_width = null;
// Remove the filter, so any Jetpack_Tiled_Gallery in a post is not affected
remove_filter( 'tiled_gallery_content_width', array( $this, 'tiled_gallery_content_width' ) );
echo "\n" . '</div>'; // .widget-gallery-$type
echo "\n" . $after_widget;
}
/**
* Fetch the images attached to the gallery Widget
*
* @param array $instance The Widget instance for which you'd like attachments
* @return array Array of attachment objects for the Widget in $instance
*/
public function get_attachments( $instance ){
$ids = explode( ',', $instance['ids'] );
if ( isset( $instance['random'] ) && 'on' == $instance['random'] ) {
shuffle( $ids );
}
$attachments_query = new WP_Query( array(
'post__in' => $ids,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'posts_per_page' => -1,
'orderby' => 'post__in',
) );
$attachments = $attachments_query->get_posts();
wp_reset_postdata();
return $attachments;
}
/**
* Generate HTML for a rectangular, tiled Widget
*
* @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
* @param array $instance The Widget instance to generate HTML for
* @return string String of HTML representing a rectangular gallery
*/
public function rectangular_widget( $args, $instance ) {
if ( ! class_exists( 'Jetpack_Tiled_Gallery' )
&& ! class_exists( 'Jetpack_Tiled_Gallery_Layout_Rectangular') ) {
return;
}
$widget_tiled_gallery = new Jetpack_Tiled_Gallery();
$widget_tiled_gallery->default_scripts_and_styles();
$layout = new Jetpack_Tiled_Gallery_Layout_Rectangular( $instance['attachments'], $instance['link'], false, 3 );
return $layout->HTML();
}
/**
* Generate HTML for a square (grid style) Widget
*
* @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
* @param array $instance The Widget instance to generate HTML for
* @return string String of HTML representing a square gallery
*/
public function square_widget( $args, $instance ) {
if ( ! class_exists( 'Jetpack_Tiled_Gallery' )
&& ! class_exists( 'Jetpack_Tiled_Gallery_Layout_Square') ) {
return;
}
$widget_tiled_gallery = new Jetpack_Tiled_Gallery();
$widget_tiled_gallery->default_scripts_and_styles();
$layout = new Jetpack_Tiled_Gallery_Layout_Square( $instance['attachments'], $instance['link'], false, 3 );
return $layout->HTML();
}
/**
* Generate HTML for a circular (grid style) Widget
*
* @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
* @param array $instance The Widget instance to generate HTML for
* @return string String of HTML representing a circular gallery
*/
public function circle_widget( $args, $instance ) {
if ( ! class_exists( 'Jetpack_Tiled_Gallery' )
&& ! class_exists( 'Jetpack_Tiled_Gallery_Layout_Circle') ) {
return;
}
$widget_tiled_gallery = new Jetpack_Tiled_Gallery();
$widget_tiled_gallery->default_scripts_and_styles();
$layout = new Jetpack_Tiled_Gallery_Layout_Circle( $instance['attachments'], $instance['link'], false, 3 );
return $layout->HTML();
}
/**
* Generate HTML for a slideshow Widget
*
* @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
* @param array $instance The Widget instance to generate HTML for
* @return string String of HTML representing a slideshow gallery
*/
public function slideshow_widget( $args, $instance ) {
global $content_width;
require_once plugin_dir_path( realpath( dirname( __FILE__ ) . '/../shortcodes/slideshow.php' ) ) . 'slideshow.php';
if ( ! class_exists( 'Jetpack_Slideshow_Shortcode' ) )
return;
if ( count( $instance['attachments'] ) < 1 )
return;
$slideshow = new Jetpack_Slideshow_Shortcode();
$slideshow->enqueue_scripts();
$gallery_instance = "widget-" . $args['widget_id'];
$gallery = array();
foreach ( $instance['attachments'] as $attachment ) {
$attachment_image_src = wp_get_attachment_image_src( $attachment->ID, 'full' );
$attachment_image_src = $attachment_image_src[0]; // [url, width, height]
$caption = wptexturize( strip_tags( $attachment->post_excerpt ) );
$gallery[] = (object) array(
'src' => (string) esc_url_raw( $attachment_image_src ),
'id' => (string) $attachment->ID,
'caption' => (string) $caption,
);
}
$max_width = intval( get_option( 'large_size_w' ) );
$max_height = 175;
if ( intval( $content_width ) > 0 )
$max_width = min( intval( $content_width ), $max_width );
$color = Jetpack_Options::get_option( 'slideshow_background_color', 'black' );
$autostart = isset( $attr['autostart'] ) ? $attr['autostart'] : true;
$js_attr = array(
'gallery' => $gallery,
'selector' => $gallery_instance,
'width' => $max_width,
'height' => $max_height,
'trans' => 'fade',
'color' => $color,
'autostart' => $autostart,
);
$html = $slideshow->slideshow_js( $js_attr );
return $html;
}
/**
* tiled_gallery_content_width filter
*
* Used to adjust the content width of Jetpack_Tiled_Gallery's in sidebars
*
* $this->_instance_width is filtered in widget() and this filter is added then removed in widget()
*
* @param int $width int The original width value
* @return int The filtered width
*/
public function tiled_gallery_content_width( $width ) {
return $this->_instance_width;
}
public function form( $instance ) {
$defaults = $this->defaults();
$allowed_values = $this->allowed_values();
$instance = wp_parse_args( (array) $instance, $defaults );
include dirname( __FILE__ ) . '/gallery/templates/form.php';
}
public function update( $new_instance, $old_instance ) {
$instance = $this->sanitize( $new_instance );
return $instance;
}
/**
* Sanitize the $instance's values to the set of allowed values. If a value is not acceptable,
* it is set to its default.
*
* Helps keep things nice and secure by whitelisting only allowed values
*
* @param array $instance The Widget instance to sanitize values for
* @return array $instance The Widget instance with values sanitized
*/
public function sanitize( $instance ) {
$allowed_values = $this->allowed_values();
$defaults = $this->defaults();
foreach ( $instance as $key => $value ) {
$value = trim( $value );
if ( isset( $allowed_values[ $key ] ) && $allowed_values[ $key ] && ! array_key_exists( $value, $allowed_values[ $key ] ) ) {
$instance[ $key ] = $defaults[ $key ];
} else {
$instance[ $key ] = sanitize_text_field( $value );
}
}
return $instance;
}
/**
* Return a multi-dimensional array of allowed values (and their labels) for all widget form
* elements
*
* To allow all values on an input, omit it from the returned array
*
* @return array Array of allowed values for each option
*/
public function allowed_values() {
$max_columns = 5;
// Create an associative array of allowed column values. This just automates the generation of
// column <option>s, from 1 to $max_columns
$allowed_columns = array_combine( range( 1, $max_columns ), range( 1, $max_columns ) );
return array(
'type' => array(
'rectangular' => __( 'Tiles', 'jetpack' ),
'square' => __( 'Square Tiles', 'jetpack' ),
'circle' => __( 'Circles', 'jetpack' ),
'slideshow' => __( 'Slideshow', 'jetpack' ),
),
'columns' => $allowed_columns,
'link' => array(
'carousel' => __( 'Carousel', 'jetpack' ),
'post' => __( 'Attachment Page', 'jetpack' ),
'file' => __( 'Media File', 'jetpack' ),
)
);
}
/**
* Return an associative array of default values
*
* These values are used in new widgets as well as when sanitizing input. If a given value is not allowed,
* as defined in allowed_values(), that input is set to the default value defined here.
*
* @return array Array of default values for the Widget's options
*/
public function defaults() {
return array(
'title' => '',
'type' => 'rectangular',
'ids' => '',
'columns' => 3,
'link' => 'carousel'
);
}
public function enqueue_frontend_scripts() {
wp_register_script( 'gallery-widget', plugins_url( '/gallery/js/gallery.js', __FILE__ ) );
wp_enqueue_script( 'gallery-widget' );
}
public function enqueue_admin_scripts() {
global $pagenow;
if ( 'widgets.php' == $pagenow || 'customize.php' == $pagenow ) {
wp_enqueue_media();
wp_enqueue_script( 'gallery-widget-admin', plugins_url( '/gallery/js/admin.js', __FILE__ ), array(
'media-models',
'media-views'
),
'20150501'
);
$js_settings = array(
'thumbSize' => self::THUMB_SIZE
);
wp_localize_script( 'gallery-widget-admin', '_wpGalleryWidgetAdminSettings', $js_settings );
if( is_rtl() ) {
wp_enqueue_style( 'gallery-widget-admin', plugins_url( '/gallery/css/rtl/admin-rtl.css', __FILE__ ) );
} else {
wp_enqueue_style( 'gallery-widget-admin', plugins_url( '/gallery/css/admin.css', __FILE__ ) );
}
}
}
}
add_action( 'widgets_init', 'jetpack_gallery_widget_init' );
function jetpack_gallery_widget_init() {
if ( ! method_exists( 'Jetpack', 'is_module_active' ) || Jetpack::is_module_active( 'tiled-gallery' ) )
register_widget( 'Jetpack_Gallery_Widget' );
}

View file

@ -0,0 +1,11 @@
.gallery-widget-thumbs-wrapper {
margin: -5px 0 0.3em 0;
}
.gallery-widget-thumbs img {
border: 1px solid #ccc;
padding: 2px;
background-color: #fff;
margin: 0 0 5px 5px;
float: right;
}

View file

@ -0,0 +1 @@
.gallery-widget-thumbs-wrapper{margin:-5px 0 .3em}.gallery-widget-thumbs img{border:1px solid #ccc;padding:2px;background-color:#fff;margin:0 0 5px 5px;float:right}

View file

@ -0,0 +1,11 @@
.gallery-widget-thumbs-wrapper {
margin: -5px 0 0.3em 0;
}
.gallery-widget-thumbs img {
border: 1px solid #ccc;
padding: 2px;
background-color: #fff;
margin: 0 5px 5px 0;
float: left;
}

View file

@ -0,0 +1 @@
.gallery-widget-thumbs-wrapper{margin:-5px 0 .3em}.gallery-widget-thumbs img{border:1px solid #ccc;padding:2px;background-color:#fff;margin:0 5px 5px 0;float:left}

View file

@ -0,0 +1,13 @@
/* This file was automatically generated on Mar 22 2013 21:33:14 */
.gallery-widget-thumbs-wrapper {
margin: -5px 0 0.3em 0;
}
.gallery-widget-thumbs img {
border: 1px solid #ccc;
padding: 2px;
background-color: #fff;
margin: 0 0 5px 5px;
float: right;
}

View file

@ -0,0 +1,225 @@
/* jshint onevar: false, multistr: true */
/* global _wpMediaViewsL10n, _wpGalleryWidgetAdminSettings */
(function($){
var $ids;
var $thumbs;
$(function(){
$( document.body ) .on( 'click', '.gallery-widget-choose-images', function( event ) {
event.preventDefault();
var widget_form = $( this ).closest( 'form, .form' );
$ids = widget_form.find( '.gallery-widget-ids' );
$thumbs = widget_form.find( '.gallery-widget-thumbs' );
var idsString = $ids.val();
var attachments = getAttachments( idsString );
var selection = null;
var editing = false;
if ( attachments ) {
selection = getSelection( attachments );
editing = true;
}
var options = {
state: 'gallery-edit',
title: wp.media.view.l10n.addMedia,
multiple: true,
editing: editing,
selection: selection
};
var workflow = getWorkflow( options );
workflow.open();
});
// Setup an onchange handler to toggle various options when changing style. The different style options
// require different form inputs to be presented in the widget; this event will keep the UI in sync
// with the selected style
$( '.widget-inside' ).on( 'change', '.gallery-widget-style', setupStyleOptions);
// Setup the Link To options for all forms currently on the page. Does the same as the onChange handler, but
// is called once to display the correct form inputs for each widget on the page
setupStyleOptions();
});
var media = wp.media,
l10n;
// Link any localized strings.
l10n = media.view.l10n = typeof _wpMediaViewsL10n === 'undefined' ? {} : _wpMediaViewsL10n;
/**
* wp.media.view.MediaFrame.GalleryWidget
*
* This behavior can be very nearly had by setting the workflow's state to 'gallery-edit', but
* we cannot use the custom WidgetGalleryEdit controller with it (must overide createStates(),
* which is necessary to disable the sidebar gallery settings in the media browser)
*/
media.view.MediaFrame.GalleryWidget = media.view.MediaFrame.Post.extend({
createStates: function() {
var options = this.options;
// `CollectionEdit` and `CollectionAdd` were only introduced in r27214-core,
// so they may not be available yet.
if ( 'CollectionEdit' in media.controller ) {
this.states.add([
new media.controller.CollectionEdit({
type: 'image',
collectionType: 'gallery',
title: l10n.editGalleryTitle,
SettingsView: media.view.Settings.Gallery,
library: options.selection,
editing: options.editing,
menu: 'gallery'
}),
new media.controller.CollectionAdd({
type: 'image',
collectionType: 'gallery',
title: l10n.addToGalleryTitle
})
]);
} else {
// If `CollectionEdit` is not available, then use the old approach.
if ( ! ( 'WidgetGalleryEdit' in media.controller ) ) {
// Remove the gallery settings sidebar when editing widgets.
media.controller.WidgetGalleryEdit = media.controller.GalleryEdit.extend({
gallerySettings: function( /*browser*/ ) {
return;
}
});
}
this.states.add([
new media.controller.WidgetGalleryEdit({
library: options.selection,
editing: options.editing,
menu: 'gallery'
}),
new media.controller.GalleryAdd({ })
]);
}
}
});
function setupStyleOptions(){
$( '.widget-inside .gallery-widget-style' ).each( function( /*i*/ ){
var style = $( this ).val();
var form = $( this ).parents( 'form' );
switch ( style ) {
case 'slideshow':
form.find( '.gallery-widget-link-wrapper' ).hide();
form.find( '.gallery-widget-columns-wrapper' ).hide();
break;
default:
form.find( '.gallery-widget-link-wrapper' ).show();
form.find( '.gallery-widget-columns-wrapper' ).show();
}
});
}
/**
* Take a given Selection of attachments and a thumbs wrapper div (jQuery object)
* and fill it with thumbnails
*/
function setupThumbs( selection, wrapper ){
wrapper.empty();
var imageSize = _wpGalleryWidgetAdminSettings.thumbSize;
selection.each( function( model ){
var sizedUrl = model.get('url') + '?w=' + imageSize + '&h=' + imageSize + '&crop=true';
var thumb = jQuery('<img>', { 'src' : sizedUrl, 'alt': model.get('title'), 'title': model.get('title'), 'width': imageSize, 'height': imageSize, 'class': 'thumb' });
wrapper.append( thumb );
});
}
/**
* Take a csv string of ids (as stored in db) and fetch a full Attachments collection
*/
function getAttachments( idsString ) {
if ( ! idsString ) {
return null;
}
// Found in /wp-includes/js/media-editor.js
var shortcode = wp.shortcode.next( 'gallery', '[gallery ids="' + idsString + '"]' );
// Ignore the rest of the match object, to give attachments() below what it expects
shortcode = shortcode.shortcode;
var attachments = wp.media.gallery.attachments( shortcode );
return attachments;
}
/**
* Take an Attachments collection and return a corresponding Selection model that can be
* passed to a MediaFrame to prepopulate the gallery picker
*/
function getSelection( attachments ) {
var selection = new wp.media.model.Selection( attachments.models, {
props: attachments.props.toJSON(),
multiple: true
});
selection.gallery = attachments.gallery;
// Fetch the query's attachments, and then break ties from the
// query to allow for sorting.
selection.more().done( function() {
// Break ties with the query.
selection.props.set( { query: false } );
selection.unmirror();
selection.props.unset( 'orderby' );
});
return selection;
}
/**
* Create a media 'workflow' (MediaFrame). This is the main entry point for the media picker
*/
function getWorkflow( options ) {
var workflow = new wp.media.view.MediaFrame.GalleryWidget( options );
workflow.on( 'update', function( selection ) {
var state = workflow.state();
selection = selection || state.get( 'selection' );
if ( ! selection ) {
return;
}
// Map the Models down into a simple array of ids that can be easily imploded to a csv string
var ids = selection.map( function( model ){
return model.get( 'id' );
} );
var id_string = ids.join( ',' );
$ids.val( id_string ).trigger( 'change' );
setupThumbs( selection, $thumbs );
}, this );
workflow.setState( workflow.options.state );
return workflow;
}
})(jQuery);

View file

@ -0,0 +1,10 @@
(function($){
// Fixes a bug with carousels being triggered even when a widget's Link To option is not set to carousel.
// Happens when another gallery is loaded on the page, either in a post or separate widget
$( 'body' ).on( 'click', '.widget-gallery .no-carousel .tiled-gallery-item a', function( event ){
// Have to trigger default, instead of carousel
event.stopPropagation();
return true;
});
})(jQuery);

View file

@ -0,0 +1,89 @@
<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( $instance['title'] ); ?>" />
</label>
</p>
<p>
<label>
<?php esc_html_e( 'Images:', 'jetpack' ); ?>
</label>
</p>
<div class="gallery-widget-thumbs-wrapper">
<div class="gallery-widget-thumbs">
<?php
// Add the thumbnails to the widget box
$attachments = $this->get_attachments( $instance );
foreach( $attachments as $attachment ){
$url = add_query_arg( array(
'w' => self::THUMB_SIZE,
'h' => self::THUMB_SIZE,
'crop' => 'true'
), wp_get_attachment_url( $attachment->ID ) );
?>
<img src="<?php echo esc_url( $url ); ?>" title="<?php echo esc_attr( $attachment->post_title ); ?>" alt="<?php echo esc_attr( $attachment->post_title ); ?>"
width="<?php echo self::THUMB_SIZE; ?>" height="<?php echo self::THUMB_SIZE; ?>" class="thumb" />
<?php } ?>
</div>
<div style="clear: both;"></div>
</div>
<p>
<a class="button gallery-widget-choose-images"><span class="wp-media-buttons-icon"></span> <?php esc_html_e( 'Choose Images', 'jetpack' ); ?></a>
</p>
<p class="gallery-widget-link-wrapper">
<label for="<?php echo $this->get_field_id( 'link' ); ?>"><?php esc_html_e( 'Link To:', 'jetpack' ); ?></label>
<select name="<?php echo $this->get_field_name( 'link' ); ?>" id="<?php echo $this->get_field_id( 'link' ); ?>" class="widefat">
<?php foreach ( $allowed_values['link'] as $key => $label ) {
$selected = '';
if ( $instance['link'] == $key ) {
$selected = "selected='selected' ";
} ?>
<option value="<?php echo $key; ?>" <?php echo $selected; ?>><?php echo esc_html( $label, 'jetpack' ); ?></option>
<?php } ?>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'random' ); ?>"><?php esc_html_e( 'Random Order:', 'jetpack' ); ?></label>
<?php $checked = '';
if ( isset( $instance['random'] ) && $instance['random'] )
$checked = 'checked="checked"';
?>
<input name="<?php echo $this->get_field_name( 'random' ); ?>" id="<?php echo $this->get_field_id( 'random' ); ?>" type="checkbox" <?php echo $checked; ?>>
</p>
<p class="gallery-widget-style-wrapper">
<label for="<?php echo $this->get_field_id( 'type' ); ?>"><?php esc_html_e( 'Style:', 'jetpack' ); ?></label>
<select name="<?php echo $this->get_field_name( 'type' ); ?>" id="<?php echo $this->get_field_id( 'type' ); ?>" class="widefat gallery-widget-style">
<?php foreach ( $allowed_values['type'] as $key => $label ) {
$selected = '';
if ( $instance['type'] == $key ) {
$selected = "selected='selected' ";
} ?>
<option value="<?php echo $key; ?>" <?php echo $selected; ?>><?php echo esc_html( $label, 'jetpack' ); ?></option>
<?php } ?>
</select>
</p>
<?php
?>
<?php // Hidden input to hold the selected image ids as a csv list ?>
<input type="hidden" class="gallery-widget-ids" name="<?php echo $this->get_field_name( 'ids' ); ?>" id="<?php echo $this->get_field_id( 'ids' ); ?>" value="<?php echo esc_attr( $instance['ids'] ); ?>" />

View file

@ -0,0 +1,143 @@
<?php
/**
* Register the widget for use in Appearance -> Widgets
*/
add_action( 'widgets_init', 'jetpack_goodreads_widget_init' );
function jetpack_goodreads_widget_init() {
register_widget( 'WPCOM_Widget_Goodreads' );
}
/**
* Goodreads widget class
* Display a user's Goodreads shelf.
* Customize user_id, title, and shelf
*
*/
class WPCOM_Widget_Goodreads extends WP_Widget {
private $goodreads_widget_id = 0;
function __construct() {
parent::__construct(
'wpcom-goodreads',
/** This filter is documented in modules/widgets/facebook-likebox.php */
apply_filters( 'jetpack_widget_name', __( 'Goodreads', 'jetpack' ) ),
array(
'classname' => 'widget_goodreads',
'description' => __( 'Display your books from Goodreads', 'jetpack' ),
'customize_selective_refresh' => true,
)
);
// For user input sanitization and display
$this->shelves = array(
'read' => _x( 'Read', 'past participle: books I have read', 'jetpack' ),
'currently-reading' => __( 'Currently Reading', 'jetpack' ),
'to-read' => _x( 'To Read', 'my list of books to read', 'jetpack' )
);
if ( is_active_widget( '', '', 'wpcom-goodreads' ) || is_customize_preview() ) {
add_action( 'wp_print_styles', array( $this, 'enqueue_style' ) );
}
}
function enqueue_style() {
if ( is_rtl() ) {
wp_enqueue_style( 'goodreads-widget', plugins_url( 'goodreads/css/rtl/goodreads-rtl.css', __FILE__ ) );
} else {
wp_enqueue_style( 'goodreads-widget', plugins_url( 'goodreads/css/goodreads.css', __FILE__ ) );
}
}
function widget( $args, $instance ) {
/** This filter is documented in core/src/wp-includes/default-widgets.php */
$title = apply_filters( 'widget_title', isset( $instance['title'] ) ? $instance['title'] : '' );
if ( empty( $instance['user_id'] ) || 'invalid' === $instance['user_id'] ) {
if ( current_user_can('edit_theme_options') ) {
echo $args['before_widget'];
echo '<p>' . sprintf(
__( 'You need to enter your numeric user ID for the <a href="%1$s">Goodreads Widget</a> to work correctly. <a href="%2$s" target="_blank">Full instructions</a>.', 'jetpack' ),
esc_url( admin_url( 'widgets.php' ) ),
'http://support.wordpress.com/widgets/goodreads-widget/#goodreads-user-id'
) . '</p>';
echo $args['after_widget'];
}
return;
}
if ( !array_key_exists( $instance['shelf'], $this->shelves ) )
return;
$instance['user_id'] = absint( $instance['user_id'] );
// Set widget ID based on shelf.
$this->goodreads_widget_id = $instance['user_id'] . '_' . $instance['shelf'];
if ( empty( $title ) ) $title = esc_html__( 'Goodreads', 'jetpack' );
echo $args['before_widget'];
echo $args['before_title'] . $title . $args['after_title'];
$goodreads_url = 'https://www.goodreads.com/review/custom_widget/' . urlencode( $instance['user_id'] ) . '.' . urlencode( $instance['title'] ) . ':%20' . urlencode( $instance['shelf'] ) . '?cover_position=&cover_size=small&num_books=5&order=d&shelf=' . urlencode( $instance['shelf'] ) . '&sort=date_added&widget_bg_transparent=&widget_id=' . esc_attr( $this->goodreads_widget_id ) ;
echo '<div class="gr_custom_widget" id="gr_custom_widget_' . esc_attr( $this->goodreads_widget_id ). '"></div>' . "\n";
echo '<script src="' . esc_url( $goodreads_url ) . '"></script>' . "\n";
echo $args['after_widget'];
/** This action is already documented in modules/widgets/gravatar-profile.php */
do_action( 'jetpack_stats_extra', 'widget', 'goodreads' );
}
function goodreads_user_id_exists( $user_id ) {
$url = "http://www.goodreads.com/user/show/$user_id/";
$response = wp_remote_head( $url, array( 'httpversion'=>'1.1', 'timeout'=>3, 'redirection'=> 2 ) );
if ( wp_remote_retrieve_response_code( $response ) === 200 )
return true;
else
return false;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['user_id'] = trim( wp_kses( stripslashes( $new_instance['user_id'] ), array() ) );
if ( ! empty( $instance['user_id'] ) && ( ! isset( $old_instance['user_id'] ) || $instance['user_id'] !== $old_instance['user_id'] ) ) {
if ( ! $this->goodreads_user_id_exists( $instance['user_id'] ) ) {
$instance['user_id'] = 'invalid';
}
}
$instance['title'] = wp_kses( stripslashes( $new_instance['title'] ), array() );
$shelf = wp_kses( stripslashes( $new_instance['shelf'] ), array() );
if ( array_key_exists( $shelf, $this->shelves ) )
$instance['shelf'] = $shelf;
return $instance;
}
function form( $instance ) {
//Defaults
$instance = wp_parse_args( (array) $instance, array( 'user_id' => '', 'title' => 'Goodreads', 'shelf' => 'read' ) );
echo '<p><label for="' . esc_attr( $this->get_field_id( 'title' ) ) . '">' . esc_html__( 'Title:', 'jetpack' ) . '
<input class="widefat" id="' . esc_attr( $this->get_field_id( 'title' ) ) . '" name="' . esc_attr( $this->get_field_name( 'title' ) ) . '" type="text" value="' . esc_attr( $instance['title'] ) . '" />
</label></p>
<p><label for="' . esc_attr( $this->get_field_id( 'user_id' ) ) . '">';
printf( __( 'Goodreads numeric user ID <a href="%s" target="_blank">(instructions)</a>:', 'jetpack' ), 'https://en.support.wordpress.com/widgets/goodreads-widget/#goodreads-user-id' );
if ( 'invalid' === $instance['user_id'] ) {
printf( '<br /><small class="error">%s</small>&nbsp;', __( 'Invalid User ID, please verify and re-enter your Goodreads numeric user ID.', 'jetpack' ) );
$instance['user_id'] = '';
}
echo '<input class="widefat" id="' . esc_attr( $this->get_field_id( 'user_id' ) ) . '" name="' . esc_attr( $this->get_field_name( 'user_id' ) ) . '" type="text" value="' . esc_attr( $instance['user_id'] ) . '" />
</label></p>
<p><label for="' . esc_attr( $this->get_field_id( 'shelf' ) ) . '">' . esc_html__( 'Shelf:', 'jetpack' ) . '
<select class="widefat" id="' . esc_attr( $this->get_field_id( 'shelf' ) ) . '" name="' . esc_attr( $this->get_field_name( 'shelf' ) ) . '" >';
foreach( $this->shelves as $_shelf_value => $_shelf_display ) {
echo "\t<option value='" . esc_attr( $_shelf_value ) . "'" . selected( $_shelf_value, $instance['shelf'] ) . ">" . $_shelf_display . "</option>\n";
}
echo '</select>
</label></p>
';
}
}

View file

@ -0,0 +1,48 @@
div[class^="gr_custom_container"] {
/* customize your Goodreads widget container here*/
border: 1px solid gray;
border-radius:10px;
padding: 10px 5px 10px 5px;
background-color: #FFF;
color: #000;
}
div[class^="gr_custom_container"] a {
color: #000;
}
h2[class^="gr_custom_header"] {
/* customize your Goodreads header here*/
display: none;
}
div[class^="gr_custom_each_container"] {
/* customize each individual book container here */
width: 100%;
clear: both;
margin-bottom: 10px;
overflow: auto;
padding-bottom: 4px;
border-bottom: 1px solid #aaa;
}
div[class^="gr_custom_book_container"] {
/* customize your book covers here */
float: right;
overflow: hidden;
height: 60px;
margin-left: 4px;
width: 39px;
}
div[class^="gr_custom_author"] {
/* customize your author names here */
font-size: 10px;
}
div[class^="gr_custom_tags"] {
/* customize your tags here */
font-size: 10px;
color: gray;
}
div[class^="gr_custom_review"] {
}
div[class^="gr_custom_rating"] {
display: none;
}

View file

@ -0,0 +1,50 @@
/* This file was automatically generated on Nov 19 2013 15:54:57 */
div[class^="gr_custom_container"] {
/* customize your Goodreads widget container here*/
border: 1px solid gray;
border-radius:10px;
padding: 10px 5px 10px 5px;
background-color: #FFF;
color: #000;
}
div[class^="gr_custom_container"] a {
color: #000;
}
h2[class^="gr_custom_header"] {
/* customize your Goodreads header here*/
display: none;
}
div[class^="gr_custom_each_container"] {
/* customize each individual book container here */
width: 100%;
clear: both;
margin-bottom: 10px;
overflow: auto;
padding-bottom: 4px;
border-bottom: 1px solid #aaa;
}
div[class^="gr_custom_book_container"] {
/* customize your book covers here */
float: left;
overflow: hidden;
height: 60px;
margin-right: 4px;
width: 39px;
}
div[class^="gr_custom_author"] {
/* customize your author names here */
font-size: 10px;
}
div[class^="gr_custom_tags"] {
/* customize your tags here */
font-size: 10px;
color: gray;
}
div[class^="gr_custom_review"] {
}
div[class^="gr_custom_rating"] {
display: none;
}

View file

@ -0,0 +1,22 @@
(function($) {
// For when adding widget via customizer
$( document ).on( 'widget-added', function() {
toggle_items();
});
$(function(){
$( document ).on( 'change', '.googleplus-badge-choose-type', toggle_items )
.on( 'widget-updated', toggle_items );
toggle_items();
});
function toggle_items() {
$( '.widget-inside .googleplus-badge-choose-type' ).each( function(){
var $widget_form = $( this ).parents( 'form' );
$widget_form.find( '[class^="googleplus-badge-only-"]' ).parent().hide();
$widget_form.find( '.googleplus-badge-only-' + $( this ).val() ).parent().show();
});
}
})(jQuery);

View file

@ -0,0 +1,311 @@
<?php
/**
* Register the widget for use in Appearance -> Widgets
*/
add_action( 'widgets_init', 'jetpack_googleplus_badge_init' );
function jetpack_googleplus_badge_init() {
register_widget( 'WPCOM_Widget_GooglePlus_Badge' );
}
/**
* Google+ Badge widget class
* Display a Google+ Badge as a widget
* https://developers.google.com/+/web/badge/
*/
class WPCOM_Widget_GooglePlus_Badge extends WP_Widget {
private $default_width = 220;
private $max_width = 450;
private $min_width_portrait = 180;
private $min_width_landscape = 273;
private $min_width;
private $default_theme = 'light';
private $allowed_themes = array( 'light', 'dark' );
private $default_layout = 'portrait';
private $allowed_layouts = array( 'landscape', 'portrait' );
private $default_type = 'person';
private $allowed_types = array();
function __construct() {
$this->min_width = min( $this->min_width_portrait, $this->min_width_landscape );
$this->allowed_types = array(
'person' => __( 'Person Widget', 'jetpack' ),
'page' => __( 'Page Widget', 'jetpack' ),
'community' => __( 'Community Widget', 'jetpack' ),
);
parent::__construct(
'googleplus-badge',
/** This filter is documented in modules/widgets/facebook-likebox.php */
apply_filters( 'jetpack_widget_name', __( 'Google+ Badge', 'jetpack' ) ),
array(
'classname' => 'widget_googleplus_badge',
'description' => __( 'Display a Google+ Badge to connect visitors to your Google+', 'jetpack' ),
'customize_selective_refresh' => true,
)
);
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
if ( is_active_widget( '', '', 'googleplus-badge' ) || is_customize_preview() ) {
add_action( 'wp_print_styles', array( $this, 'enqueue_script' ) );
add_filter( 'script_loader_tag', array( $this, 'replace_script_tag' ), 10, 2 );
}
}
function enqueue_script() {
wp_enqueue_script( 'googleplus-widget', 'https://apis.google.com/js/platform.js' );
}
function replace_script_tag( $tag, $handle ) {
if ( 'googleplus-widget' !== $handle ) {
return $tag;
}
return str_replace( ' src', ' async defer src', $tag );
}
function enqueue_admin_scripts() {
global $pagenow;
if ( 'widgets.php' == $pagenow || 'customize.php' == $pagenow ) {
wp_enqueue_script( 'googleplus-widget-admin', plugins_url( '/google-plus/js/admin.js', __FILE__ ), array( 'jquery' ) );
}
}
function widget( $args, $instance ) {
if ( empty( $instance['href'] ) || ! $this->is_valid_googleplus_url( $instance['href'] ) ) {
if ( current_user_can( 'edit_theme_options' ) ) {
echo $args['before_widget'];
echo '<p>' . sprintf(
__( 'It looks like your Google+ URL is incorrectly configured. Please check it in your <a href="%s">widget settings</a>.', 'jetpack' ),
admin_url( 'widgets.php' )
) . '</p>';
echo $args['after_widget'];
}
echo '<!-- Invalid Google+ URL -->';
return;
}
/** This filter is documented in core/src/wp-includes/default-widgets.php */
$title = apply_filters( 'widget_title', $instance['title'] );
echo $args['before_widget'];
echo $args['before_title'] . esc_html( $title ) . $args['after_title'];
switch( $instance['type'] ) {
case 'person':
case 'page':
printf(
'<div class="g-%s" data-href="%s" data-layout="%s" data-theme="%s" data-showcoverphoto="%s" data-showtagline="%s" data-width="%s"></div>',
$instance['type'],
esc_url( $instance['href'] ),
esc_attr( $instance['layout'] ),
esc_attr( $instance['theme'] ),
esc_attr( $instance['show_coverphoto'] ? 'true' : 'false' ),
esc_attr( $instance['show_tagline'] ? 'true' : 'false' ),
esc_attr( $instance['width'] )
);
break;
case 'community':
printf(
'<div class="g-%s" data-href="%s" data-layout="%s" data-theme="%s" data-showphoto="%s" data-showowners="%s" data-showtagline="%s" data-width="%s"></div>',
$instance['type'],
esc_url( $instance['href'] ),
esc_attr( $instance['layout'] ),
esc_attr( $instance['theme'] ),
esc_attr( $instance['show_photo'] ? 'true' : 'false' ),
esc_attr( $instance['show_owners'] ? 'true' : 'false' ),
esc_attr( $instance['show_tagline'] ? 'true' : 'false' ),
esc_attr( $instance['width'] )
);
break;
}
echo $args['after_widget'];
/** This action is already documented in modules/widgets/gravatar-profile.php */
do_action( 'jetpack_stats_extra', 'widget', 'googleplus-badge' );
}
function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = trim( strip_tags( stripslashes( $new_instance['title'] ) ) );
// Validate the Google+ URL
$instance['href'] = trim( strip_tags( stripslashes( $new_instance['href'] ) ) );
if ( $this->is_valid_googleplus_url( $instance['href'] ) ) {
$temp = explode( '?', $instance['href'] );
$instance['href'] = str_replace( array( 'http://plus.google.com', 'https://plus.google.com' ), 'https://plus.google.com', $temp[0] );
} else {
$instance['href'] = '';
}
$instance['theme'] = $this->filter_text( $new_instance['theme'], $this->default_theme, $this->allowed_themes );
$instance['layout'] = $this->filter_text( $new_instance['layout'], $this->default_layout, $this->allowed_layouts );
switch( $instance['layout'] ) {
case 'portrait':
$instance['width'] = filter_var( $new_instance['width'], FILTER_VALIDATE_INT, array( 'options' => array(
'min_range' => $this->min_width_portrait,
'max_range' => $this->max_width,
'default' => $this->default_width,
) ) );
break;
case 'landscape':
$instance['width'] = filter_var( $new_instance['width'], FILTER_VALIDATE_INT, array( 'options' => array(
'min_range' => $this->min_width_landscape,
'max_range' => $this->max_width,
'default' => $this->default_width,
) ) );
break;
}
if ( array_key_exists( $new_instance['type'], $this->allowed_types ) ) {
$instance['type'] = $new_instance['type'];
} else {
$instance['type'] = $this->default_type;
}
switch( $instance['type'] ) {
case 'person':
case 'page':
$instance['show_coverphoto'] = isset( $new_instance['show_coverphoto'] );
break;
case 'community':
$instance['show_photo'] = isset( $new_instance['show_photo'] );
$instance['show_owners'] = isset( $new_instance['show_owners'] );
break;
}
$instance['show_tagline'] = isset( $new_instance['show_tagline'] );
return $instance;
}
function form( $instance ) {
$defaults = array(
'title' => '',
'href' => '',
'width' => $this->default_width,
'layout' => $this->default_layout,
'theme' => $this->default_theme,
'show_coverphoto' => true,
'show_photo' => true,
'show_owners' => false,
'show_tagline' => true,
'type' => $this->default_type,
);
$instance = wp_parse_args( $instance, $defaults );
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>">
<?php _e( 'Title', 'jetpack' ); ?>
<input type="text" name="<?php echo $this->get_field_name( 'title' ); ?>" id="<?php echo $this->get_field_id( 'title' ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat" />
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'type' ); ?>">
<?php _e( 'Type of Widget', 'jetpack' ); ?>
<select name="<?php echo $this->get_field_name( 'type' ); ?>" id="<?php echo $this->get_field_id( 'type' ); ?>" class="widefat googleplus-badge-choose-type">
<?php
foreach( $this->allowed_types as $type_value => $type_display ) {
printf(
'<option value="%s"%s>%s</option>',
esc_attr( $type_value ),
selected( $type_value, $instance['type'], false ),
esc_attr( $type_display )
);
}
?>
</select>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'href' ); ?>">
<?php _e( 'Google+ URL', 'jetpack' ); ?>
<input type="text" name="<?php echo $this->get_field_name( 'href' ); ?>" id="<?php echo $this->get_field_id( 'href' ); ?>" value="<?php echo esc_url( $instance['href'] ); ?>" class="widefat" />
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'width' ); ?>">
<?php _e( 'Width', 'jetpack' ); ?>
<input type="number" class="smalltext" min="<?php echo esc_attr( $this->min_width ); ?>" max="<?php echo esc_attr( $this->max_width ); ?>" maxlength="3" name="<?php echo $this->get_field_name( 'width' ); ?>" id="<?php echo $this->get_field_id( 'width' ); ?>" value="<?php echo esc_attr( $instance['width'] ); ?>" style="text-align: center;" />px
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'layout' ); ?>">
<?php _e( 'Layout', 'jetpack' ); ?>
<select name="<?php echo $this->get_field_name( 'layout' ); ?>" id="<?php echo $this->get_field_id( 'layout' ); ?>">
<option value="landscape" <?php selected( $instance['layout'], 'landscape' ); ?>><?php _e( 'Landscape', 'jetpack' ); ?></option>
<option value="portrait" <?php selected( $instance['layout'], 'portrait' ); ?>><?php _e( 'Portrait', 'jetpack' ); ?></option>
</select>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'theme' ); ?>">
<?php _e( 'Theme', 'jetpack' ); ?>
<select name="<?php echo $this->get_field_name( 'theme' ); ?>" id="<?php echo $this->get_field_id( 'theme' ); ?>">
<option value="light" <?php selected( $instance['theme'], 'light' ); ?>><?php _e( 'Light', 'jetpack' ); ?></option>
<option value="dark" <?php selected( $instance['theme'], 'dark' ); ?>><?php _e( 'Dark', 'jetpack' ); ?></option>
</select>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'show_coverphoto' ); ?>">
<input type="checkbox" name="<?php echo $this->get_field_name( 'show_coverphoto' ); ?>" id="<?php echo $this->get_field_id( 'show_coverphoto' ); ?>" <?php checked( $instance['show_coverphoto'] ); ?> class="googleplus-badge-only-person googleplus-badge-only-page" />
<?php _e( 'Show Cover Photo', 'jetpack' ); ?>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'show_photo' ); ?>">
<input type="checkbox" name="<?php echo $this->get_field_name( 'show_photo' ); ?>" id="<?php echo $this->get_field_id( 'show_photo' ); ?>" <?php checked( $instance['show_photo'] ); ?> class="googleplus-badge-only-community" />
<?php _e( 'Show Photo', 'jetpack' ); ?>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'show_owners' ); ?>">
<input type="checkbox" name="<?php echo $this->get_field_name( 'show_owners' ); ?>" id="<?php echo $this->get_field_id( 'show_owners' ); ?>" <?php checked( $instance['show_owners'] ); ?> class="googleplus-badge-only-community" />
<?php _e( 'Show Owners', 'jetpack' ); ?>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'show_tagline' ); ?>">
<input type="checkbox" name="<?php echo $this->get_field_name( 'show_tagline' ); ?>" id="<?php echo $this->get_field_id( 'show_tagline' ); ?>" <?php checked( $instance['show_tagline'] ); ?> />
<?php _e( 'Show Tag Line', 'jetpack' ); ?>
</label>
</p>
<?php
}
function is_valid_googleplus_url( $url ) {
return ( FALSE !== strpos( $url, 'plus.google.com' ) ) ? TRUE : FALSE;
}
function filter_text( $value, $default = '', $allowed = array() ) {
$allowed = (array) $allowed;
if ( empty( $value ) || ( ! empty( $allowed ) && ! in_array( $value, $allowed ) ) )
$value = $default;
return $value;
}
}
// END

View file

@ -0,0 +1,46 @@
.widget-grofile {
}
.widget-grofile h4 {
margin: 1em 0 .5em;
}
.widget-grofile ul.grofile-urls {
margin-left: 0;
overflow: hidden;
}
.widget-grofile ul.grofile-accounts li {
list-style: none;
display: inline;
}
.widget-grofile ul.grofile-accounts li::before {
content: "" !important; /* Kubrick :( */
}
.widget-grofile .grofile-accounts-logo {
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 */
height: 16px; /* So we don't show the topmost logo */
float: left;
margin-right: 8px;
margin-bottom: 8px;
}
.rtl .widget-grofile .grofile-accounts-logo {
margin-left: 8px;
margin-right: 0;
}
.grofile-thumbnail {
width: 500px;
max-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;
}
}

View file

@ -0,0 +1,405 @@
<?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',
/** This filter is documented in modules/widgets/facebook-likebox.php */
apply_filters( 'jetpack_widget_name', __( 'Gravatar Profile', 'jetpack' ) ),
array(
'classname' => 'widget-grofile grofile',
'description' => __( 'Display a mini version of your Gravatar Profile', 'jetpack' ),
'customize_selective_refresh' => true,
)
);
if ( is_admin() ) {
add_action( 'admin_footer-widgets.php', array( $this, 'admin_script' ) );
}
if ( is_customize_preview() ) {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
}
}
function widget( $args, $instance ) {
$instance = wp_parse_args( $instance, array(
'title' => '',
'email' => ''
) );
/** This filter is documented in core/src/wp-includes/default-widgets.php */
$title = apply_filters( 'widget_title', $instance['title'] );
if ( !$instance['email'] ) {
if ( current_user_can( 'edit_theme_options' ) ) {
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>.', 'jetpack' ), admin_url( 'widgets.php' ) ) . '</p>';
echo $args['after_widget'];
}
return;
}
echo $args['before_widget'];
if ( ! empty( $title ) )
echo $args['before_title'] . $title . $args['after_title'];
$profile = $this->get_profile( $instance['email'] );
if( ! empty( $profile ) ) {
$profile = wp_parse_args( $profile, array(
'thumbnailUrl' => '',
'profileUrl' => '',
'displayName' => '',
'aboutMe' => '',
'urls' => array(),
'accounts' => array(),
) );
$gravatar_url = add_query_arg( 's', 320, $profile['thumbnailUrl'] ); // the default grav returned by grofiles is super small
// Enqueue front end assets.
$this->enqueue_scripts();
?>
<img src="<?php echo esc_url( $gravatar_url ); ?>" class="grofile-thumbnail no-grav" alt="<?php echo esc_attr( $profile['displayName'] ); ?>" />
<div class="grofile-meta">
<h4><a href="<?php echo esc_url( $profile['profileUrl'] ); ?>"><?php echo esc_html( $profile['displayName'] ); ?></a></h4>
<p><?php echo wp_kses_post( $profile['aboutMe'] ); ?></p>
</div>
<?php
if( $instance['show_personal_links'] )
$this->display_personal_links( (array) $profile['urls'] );
if( $instance['show_account_links'] )
$this->display_accounts( (array) $profile['accounts'] );
?>
<p><a href="<?php echo esc_url( $profile['profileUrl'] ); ?>" class="grofile-full-link">
<?php echo esc_html(
/**
* Filter the Gravatar Profile widget's profile link title.
*
* @module widgets
*
* @since 2.8.0
*
* @param string $str Profile link title.
*/
apply_filters(
'jetpack_gravatar_full_profile_title',
__( 'View Full Profile &rarr;', 'jetpack' )
)
); ?>
</a></p>
<?php
/**
* Fires when an item is displayed on the frontend.
*
* Can be used to track stats about the number of displays for a specific item
*
* @module widgets, shortcodes
*
* @since 1.6.0
*
* @param string widget Item type (e.g. widget, or embed).
* @param string grofile Item description (e.g. grofile, goodreads).
*/
do_action( 'jetpack_stats_extra', 'widget', 'grofile' );
} else {
if ( current_user_can( 'edit_theme_options' ) ) {
echo '<p>' . esc_html__( 'Error loading profile', 'jetpack' ) . '</p>';
}
}
echo $args['after_widget'];
}
function display_personal_links( $personal_links = array() ) {
if ( empty( $personal_links ) )
return;
?>
<h4><?php echo esc_html(
apply_filters(
/**
* Filter the Gravatar Profile widget's "Personal Links" section title.
*
* @module widgets
*
* @since 2.8.0
*
* @param string $str "Personal Links" section title.
*/
'jetpack_gravatar_personal_links_title',
__( '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'] ); ?>">
<?php
$link_title = ( ! empty( $personal_link['title'] ) ) ? $personal_link['title'] : $personal_link['value'];
echo esc_html( $link_title );
?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php
}
function display_accounts( $accounts = array() ) {
if ( empty( $accounts ) )
return;
?>
<h4><?php echo esc_html(
/**
* Filter the Gravatar Profile widget's "Verified Services" section title.
*
* @module widgets
*
* @since 2.8.0
*
* @param string $str "Verified Services" section title.
*/
apply_filters(
'jetpack_gravatar_verified_services_title',
__( '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
}
/**
* Enqueue CSS and JavaScript.
*
* @since 4.0.0
*/
function enqueue_scripts() {
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' )
);
}
function form( $instance ) {
$title = isset( $instance['title'] ) ? $instance['title'] : '';
$email = isset( $instance['email'] ) ? $instance['email'] : '';
$email_user = isset( $instance['email_user'] ) ? $instance['email_user'] : get_current_user_id();
$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'] : '';
$profile_url = 'https://gravatar.com/profile/edit';
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
$profile_url = admin_url( 'profile.php' );
if ( isset( $_REQUEST['calypso'] ) ) {
$profile_url = 'https://wordpress.com/me';
}
}
?>
<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( '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,
'name' => $this->get_field_name( 'email_user' ),
'id' => $this->get_field_id( 'email_user' ),
'class' => 'gravatar-profile-user-select',
) );?>
</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 ); ?> />
<?php esc_html_e( 'Show Personal Links', 'jetpack' ); ?>
<br />
<small><?php esc_html_e( 'Links to your websites, blogs, or any other sites that help describe who you are.', 'jetpack' ); ?></small>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'show_account_links' ); ?>">
<input type="checkbox" name="<?php echo $this->get_field_name( 'show_account_links' ); ?>" id="<?php echo $this->get_field_id( 'show_account_links' ); ?>" <?php checked( $show_account_links ); ?> />
<?php esc_html_e( 'Show Account Links', 'jetpack' ); ?>
<br />
<small><?php esc_html_e( 'Links to services that you use across the web.', 'jetpack' ); ?></small>
</label>
</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
}
function admin_script() {
?>
<script>
jQuery( function( $ ) {
$( '.wrap' ).on( 'change', '.gravatar-profile-user-select', function() {
var $input = $(this).closest('.widget-inside').find('.gprofile-email-container');
if ( '-1' === this.value.toLowerCase() ) {
$input.show();
} else {
$input.hide();
}
});
} );
</script>
<?php
}
function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = isset( $new_instance['title'] ) ? wp_kses( $new_instance['title'], array() ) : '';
$instance['email'] = isset( $new_instance['email'] ) ? wp_kses( $new_instance['email'], array() ) : '';
$instance['email_user'] = isset( $new_instance['email_user'] ) ? intval( $new_instance['email_user'] ) : -1;
$instance['show_personal_links'] = isset( $new_instance['show_personal_links'] ) ? (bool) $new_instance['show_personal_links'] : false;
$instance['show_account_links'] = isset( $new_instance['show_account_links'] ) ? (bool) $new_instance['show_account_links'] : false;
if ( $instance['email_user'] > 0 ) {
$user = get_userdata( $instance['email_user'] );
$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 = 'grofile-' . $hashed_email;
if( ! $profile = get_transient( $cache_key ) ) {
$profile_url = esc_url_raw( sprintf( '%s.gravatar.com/%s.json', ( 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 = json_decode( $profile, true );
if ( is_array( $profile ) && ! empty( $profile['entry'] ) && is_array( $profile['entry'] ) ) {
$expire = 900; // cache for 15 minutes
$profile = $profile['entry'][0];
} else {
// Something strange happened. Cache for 5 minutes.
$profile = array();
}
} else {
$expire = 900; // cache for 15 minutes
$profile = array();
}
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 ) {
case 'friendfeed':
return 'FriendFeed';
case 'linkedin':
return 'LinkedIn';
case 'yahoo':
return 'Yahoo!';
case 'youtube':
return 'YouTube';
case 'wordpress':
return 'WordPress';
case 'tripit':
return 'TripIt';
case 'myspace':
return 'MySpace';
case 'foursquare':
return 'foursquare';
case 'google':
return 'Google+';
default:
// Others don't
$shortname = ucwords( $shortname );
}
return $shortname;
}
}
// END

View file

@ -0,0 +1,245 @@
<?php
/**
* Module Name: Image Widget
* Module Description: Easily add images to your theme's sidebar.
* Sort Order: 20
* First Introduced: 1.2
*/
/**
* Register the widget for use in Appearance -> Widgets
*/
add_action( 'widgets_init', 'jetpack_image_widget_init' );
function jetpack_image_widget_init() {
register_widget( 'Jetpack_Image_Widget' );
}
class Jetpack_Image_Widget extends WP_Widget {
/**
* Register widget with WordPress.
*/
public function __construct() {
parent::__construct(
'image',
/** This filter is documented in modules/widgets/facebook-likebox.php */
apply_filters( 'jetpack_widget_name', esc_html__( 'Image', 'jetpack' ) ),
array(
'classname' => 'widget_image',
'description' => __( 'Display an image in your sidebar', 'jetpack' ),
'customize_selective_refresh' => true,
)
);
if ( is_active_widget( false, false, $this->id_base ) || is_active_widget( false, false, 'monster' ) || is_customize_preview() ) {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) );
}
}
/**
* Loads file for front-end widget style.
*
* @uses wp_enqueue_style(), plugins_url()
*/
public function enqueue_style() {
wp_enqueue_style( 'jetpack_image_widget', plugins_url( 'image-widget/style.css', __FILE__ ), array(), '20140808' );
}
/**
* 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 ) {
echo $args['before_widget'];
$instance = wp_parse_args( $instance, array(
'title' => '',
'img_url' => ''
) );
/** This filter is documented in core/src/wp-includes/default-widgets.php */
$title = apply_filters( 'widget_title', $instance['title'] );
if ( $title ) {
echo $args['before_title'] . esc_html( $title ) . $args['after_title'];
}
if ( '' != $instance['img_url'] ) {
$output = '<img src="' . esc_attr( $instance['img_url'] ) .'" ';
if ( '' != $instance['alt_text'] ) {
$output .= 'alt="' . esc_attr( $instance['alt_text'] ) .'" ';
}
if ( '' != $instance['img_title'] ) {
$output .= 'title="' . esc_attr( $instance['img_title'] ) .'" ';
}
if ( '' == $instance['caption'] ) {
$output .= 'class="align' . esc_attr( $instance['align'] ) . '" ';
}
if ( '' != $instance['img_width'] ) {
$output .= 'width="' . esc_attr( $instance['img_width'] ) .'" ';
}
if ( '' != $instance['img_height'] ) {
$output .= 'height="' . esc_attr( $instance['img_height'] ) .'" ';
}
$output .= '/>';
if ( '' != $instance['link'] && ! empty( $instance['link_target_blank'] ) ) {
$output = '<a target="_blank" href="' . esc_attr( $instance['link'] ) . '">' . $output . '</a>';
}
if ( '' != $instance['link'] && empty( $instance['link_target_blank'] ) ) {
$output = '<a href="' . esc_attr( $instance['link'] ) . '">' . $output . '</a>';
}
if ( '' != $instance['caption'] ) {
/** This filter is documented in core/src/wp-includes/default-widgets.php */
$caption = apply_filters( 'widget_text', $instance['caption'] );
$img_width = ( ! empty( $instance['img_width'] ) ? 'style="width: ' . esc_attr( $instance['img_width'] ) .'px"' : '' );
$output = '<figure ' . $img_width .' class="wp-caption align' . esc_attr( $instance['align'] ) . '">
' . $output . '
<figcaption class="wp-caption-text">' . $caption . '</figcaption>
</figure>'; // wp_kses_post caption on update
}
echo '<div class="jetpack-image-container">' . do_shortcode( $output ) . '</div>';
}
echo "\n" . $args['after_widget'];
}
/**
* 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 ) {
$allowed_caption_html = array(
'a' => array(
'href' => array(),
'title' => array(),
),
'b' => array(),
'em' => array(),
'i' => array(),
'p' => array(),
'strong' => array()
);
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['img_url'] = esc_url( $new_instance['img_url'], null, 'display' );
$instance['alt_text'] = strip_tags( $new_instance['alt_text'] );
$instance['img_title'] = strip_tags( $new_instance['img_title'] );
$instance['caption'] = wp_kses( stripslashes($new_instance['caption'] ), $allowed_caption_html );
$instance['align'] = $new_instance['align'];
$instance['img_width'] = absint( $new_instance['img_width'] );
$instance['img_height'] = absint( $new_instance['img_height'] );
$instance['link'] = esc_url( $new_instance['link'], null, 'display' );
$instance['link_target_blank'] = isset( $new_instance['link_target_blank'] ) ? (bool) $new_instance['link_target_blank'] : false;
return $instance;
}
/**
* Back-end widget form.
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*/
public function form( $instance ) {
// Defaults
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'img_url' => '', 'alt_text' => '', 'img_title' => '', 'caption' => '', 'align' => 'none', 'img_width' => '', 'img_height' => '', 'link' => '', 'link_target_blank' => false ) );
$title = esc_attr( $instance['title'] );
$img_url = esc_url( $instance['img_url'], null, 'display' );
$alt_text = esc_attr( $instance['alt_text'] );
$img_title = esc_attr( $instance['img_title'] );
$caption = esc_textarea( $instance['caption'] );
$align = esc_attr( $instance['align'] );
$img_width = esc_attr( $instance['img_width'] );
$img_height = esc_attr( $instance['img_height'] );
$link_target_blank = checked( $instance['link_target_blank'], true, false );
if ( !empty( $instance['img_url'] ) ) {
// Download the url to a local temp file and then process it with getimagesize so we can optimize browser layout
$tmp_file = download_url( $instance['img_url'], 10 );
if ( ! is_wp_error( $tmp_file ) ) {
$size = getimagesize( $tmp_file );
if ( '' == $instance['img_width'] ) {
$width = $size[0];
$img_width = $width;
} else {
$img_width = absint( $instance['img_width'] );
}
if ( '' == $instance['img_height'] ) {
$height = $size[1];
$img_height = $height;
} else {
$img_height = absint( $instance['img_height'] );
}
unlink( $tmp_file );
}
}
$link = esc_url( $instance['link'], null, 'display' );
echo '<p><label for="' . $this->get_field_id( 'title' ) . '">' . esc_html__( 'Widget title:', 'jetpack' ) . '
<input class="widefat" id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" type="text" value="' . $title . '" />
</label></p>
<p><label for="' . $this->get_field_id( 'img_url' ) . '">' . esc_html__( 'Image URL:', 'jetpack' ) . '
<input class="widefat" id="' . $this->get_field_id( 'img_url' ) . '" name="' . $this->get_field_name( 'img_url' ) . '" type="text" value="' . $img_url . '" />
</label></p>
<p><label for="' . $this->get_field_id( 'alt_text' ) . '">' . esc_html__( 'Alternate text:', 'jetpack' ) . ' <a href="http://support.wordpress.com/widgets/image-widget/#image-widget-alt-text" target="_blank">( ? )</a>
<input class="widefat" id="' . $this->get_field_id( 'alt_text' ) . '" name="' . $this->get_field_name( 'alt_text' ) . '" type="text" value="' . $alt_text . '" />
</label></p>
<p><label for="' . $this->get_field_id( 'img_title' ) . '">' . esc_html__( 'Image title:', 'jetpack' ) . ' <a href="http://support.wordpress.com/widgets/image-widget/#image-widget-title" target="_blank">( ? )</a>
<input class="widefat" id="' . $this->get_field_id( 'img_title' ) . '" name="' . $this->get_field_name( 'img_title' ) . '" type="text" value="' . $img_title . '" />
</label></p>
<p><label for="' . $this->get_field_id( 'caption' ) . '">' . esc_html__( 'Caption:', 'jetpack' ) . ' <a href="http://support.wordpress.com/widgets/image-widget/#image-widget-caption" target="_blank">( ? )</a>
<textarea class="widefat" id="' . $this->get_field_id( 'caption' ) . '" name="' . $this->get_field_name( 'caption' ) . '" rows="2" cols="20">' . $caption . '</textarea>
</label></p>';
$alignments = array(
'none' => __( 'None', 'jetpack' ),
'left' => __( 'Left', 'jetpack' ),
'center' => __( 'Center', 'jetpack' ),
'right' => __( 'Right', 'jetpack' ),
);
echo '<p><label for="' . $this->get_field_id( 'align' ) . '">' . esc_html__( 'Image Alignment:', 'jetpack' ) . '
<select id="' . $this->get_field_id( 'align' ) . '" name="' . $this->get_field_name( 'align' ) . '">';
foreach ( $alignments as $alignment => $alignment_name ) {
echo '<option value="' . esc_attr( $alignment ) . '" ';
if ( $alignment == $align )
echo 'selected="selected" ';
echo '>' . esc_html($alignment_name) . "</option>\n";
}
echo '</select></label></p>';
echo '<p><label for="' . $this->get_field_id( 'img_width' ) . '">' . esc_html__( 'Width:', 'jetpack' ) . '
<input size="3" id="' . $this->get_field_id( 'img_width' ) . '" name="' . $this->get_field_name( 'img_width' ) . '" type="text" value="' . $img_width . '" />
</label>
<label for="' . $this->get_field_id( 'img_height' ) . '">' . esc_html__( 'Height:', 'jetpack' ) . '
<input size="3" id="' . $this->get_field_id( 'img_height' ) . '" name="' . $this->get_field_name( 'img_height' ) . '" type="text" value="' . $img_height . '" />
</label><br />
<small>' . esc_html__( "If empty, we will attempt to determine the image size.", 'jetpack' ) . '</small></p>
<p><label for="' . $this->get_field_id( 'link' ) . '">' . esc_html__( 'Link URL (when the image is clicked):', 'jetpack' ) . '
<input class="widefat" id="' . $this->get_field_id( 'link' ) . '" name="' . $this->get_field_name( 'link' ) . '" type="text" value="' . $link . '" />
</label>
<label for="' . $this->get_field_id( 'link_target_blank' ) . '">
<input type="checkbox" name="' . $this->get_field_name( 'link_target_blank' ) . '" id="' . $this->get_field_id( 'link_target_blank' ) . '" value="1"' . $link_target_blank . '/>
' . esc_html__( 'Open link in a new window/tab', 'jetpack' ) . '
</label></p>';
}
} // Class Jetpack_Image_Widget

View file

@ -0,0 +1,13 @@
/*
* Image Widget styles for Jetpack
*/
/* Clear floats */
.jetpack-image-container:after {
clear: both;
}
.jetpack-image-container:before,
.jetpack-image-container:after {
display: table;
content: "";
}

View file

@ -0,0 +1,222 @@
<?php
/**
* Module Name: RSS Links Widget
* Module Description: Easily add RSS links to your theme's sidebar.
* Sort Order: 20
* First Introduced: 1.2
*/
class Jetpack_RSS_Links_Widget extends WP_Widget {
function __construct() {
$widget_ops = array(
'classname' => 'widget_rss_links',
'description' => __( "Links to your blog's RSS feeds", 'jetpack' ),
'customize_selective_refresh' => true,
);
parent::__construct(
'rss_links',
/** This filter is documented in modules/widgets/facebook-likebox.php */
apply_filters( 'jetpack_widget_name', __( 'RSS Links', 'jetpack' ) ),
$widget_ops
);
}
function widget( $args, $instance ) {
$instance = wp_parse_args( (array) $instance, $this->defaults() );
extract( $args );
/** This filter is documented in core/src/wp-includes/default-widgets.php */
$title = apply_filters( 'widget_title', $instance['title'] );
echo $before_widget;
if ( $title )
echo $before_title . stripslashes( $title ) . $after_title;
if ( 'text' == $instance['format'] ) echo '<ul>';
if ( 'posts' == $instance['display'] ) {
$this->_rss_link( 'posts', $instance);
} elseif ( 'comments' == $instance['display'] ) {
$this->_rss_link( 'comments', $instance);
} elseif ( 'posts-comments' == $instance['display'] ) {
$this->_rss_link( 'posts', $instance );
$this->_rss_link( 'comments', $instance );
}
if ( 'text' == $instance['format'] ) echo '</ul>';
echo "\n" . $after_widget;
}
/**
* Return an associative array of default values
* These values are used in new widgets as well as when sanitizing input.
*
* @return array Array of default values for the Widget's options
*/
function defaults() {
return array(
'title' => '',
'display' => 'posts-comments',
'format' => 'text'
);
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = wp_filter_nohtml_kses( $new_instance['title'] );
$instance['display'] = $new_instance['display'];
$instance['format'] = $new_instance['format'];
$instance['imagesize'] = $new_instance['imagesize'];
$instance['imagecolor'] = $new_instance['imagecolor'];
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, $this->defaults() );
$title = stripslashes( $instance['title'] );
$display = $instance['display'];
$format = $instance['format'];
$image_size = isset( $instance['imagesize'] ) ? $instance['imagesize'] : 0 ;
$image_color = isset( $instance['imagecolor'] ) ? $instance['imagecolor'] : 'red';
echo '<p><label for="' . $this->get_field_id( 'title' ) . '">' . esc_html__( 'Title:', 'jetpack' ) . '
<input class="widefat" id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" type="text" value="' . esc_attr( $title ) . '" />
</label></p>';
$displays = array(
'posts' => __( 'Posts', 'jetpack' ),
'comments' => __( 'Comments', 'jetpack' ),
'posts-comments' => __( 'Posts & Comments', 'jetpack' )
);
echo '<p><label for="' . $this->get_field_id( 'display' ) . '">' . esc_html__( 'Feed(s) to Display:', 'jetpack' ) . '
<select class="widefat" id="' . $this->get_field_id( 'display' ) . '" name="' . $this->get_field_name( 'display' ) . '">';
foreach ( $displays as $display_option => $label ) {
echo '<option value="' . esc_attr( $display_option ) . '"';
if ( $display_option == $display ) echo ' selected="selected"';
echo '>' . esc_html( $label ) . '</option>' . "\n";
}
echo '</select></label></p>';
$formats = array(
'text' => __( 'Text Link', 'jetpack' ),
'image' => __( 'Image Link', 'jetpack' ),
'text-image' => __( 'Text & Image Links', 'jetpack' )
);
echo '<p><label for="' . $this->get_field_id( 'format' ) . '">' . __( 'Format:', 'jetpack' ) . '
<select class="widefat" id="' . $this->get_field_id( 'format' ) . '" name="' . $this->get_field_name( 'format' ) . '" onchange="if ( this.value == \'text\' ) jQuery( \'#' . $this->get_field_id( 'image-settings' ) . '\' ).fadeOut(); else jQuery( \'#' . $this->get_field_id( 'image-settings' ) . '\' ).fadeIn();">';
foreach ( $formats as $format_option => $label ) {
echo '<option value="' . esc_attr( $format_option ) . '"';
if ( $format_option == $format ) echo ' selected="selected"';
echo '>' . esc_html( $label ) . '</option>' . "\n";
}
echo '</select></label></p>';
echo '<div id="' . $this->get_field_id( 'image-settings' ) . '"';
if ( 'text' == $format ) echo ' style="display: none;"';
echo '><h3>' . esc_html__( 'Image Settings:', 'jetpack' ) . '</h3>';
$sizes = array(
'small' => __( 'Small', 'jetpack' ),
'medium' => __( 'Medium', 'jetpack' ),
'large' => __( 'Large', 'jetpack' )
);
echo '<p><label for="' . $this->get_field_id( 'imagesize' ) . '">' . esc_html__( 'Image Size:', 'jetpack' ) . '
<select class="widefat" id="' . $this->get_field_id( 'imagesize' ) . '" name="' . $this->get_field_name( 'imagesize' ) . '">';
foreach ( $sizes as $size => $label ) {
echo '<option value="' . esc_attr( $size) . '"';
if ( $size == $image_size ) echo ' selected="selected"';
echo '>' . esc_html( $label ) . '</option>' . "\n";
}
echo '</select></label></p>';
$colors = array(
'red' => __( 'Red', 'jetpack' ),
'orange' => __( 'Orange', 'jetpack' ),
'green' => __( 'Green', 'jetpack' ),
'blue' => __( 'Blue', 'jetpack' ),
'purple' => __( 'Purple', 'jetpack' ),
'pink' => __( 'Pink', 'jetpack' ),
'silver' => __( 'Silver', 'jetpack' ),
);
echo '<p><label for="' . $this->get_field_id( 'imagecolor' ) . '">' . esc_html__( 'Image Color:', 'jetpack' ) . '
<select class="widefat" id="' . $this->get_field_id( 'imagecolor' ) . '" name="' . $this->get_field_name( 'imagecolor' ) . '">';
foreach ( $colors as $color => $label ) {
echo '<option value="' . esc_attr( $color) . '"';
if ( $color == $image_color ) echo ' selected="selected"';
echo '>' . esc_html( $label ) . '</option>' . "\n";
}
echo '</select></label></p></div>';
}
function _rss_link( $type = 'posts', $args ) {
if ( 'posts' == $type ) {
$type_text = __( 'Posts', 'jetpack' );
$rss_type = 'rss2_url';
} elseif ( 'comments' == $type ) {
$type_text = __( 'Comments', 'jetpack' );
$rss_type = 'comments_rss2_url';
}
$subscribe_to = sprintf( __( 'Subscribe to %s', 'jetpack' ), $type_text );
$link_item = '';
$format = $args['format'];
/**
* Filters the target link attribute for the RSS link in the RSS widget.
*
* @module widgets
*
* @since 3.4.0
*
* @param bool false Control whether the link should open in a new tab. Default to false.
*/
if ( apply_filters( 'jetpack_rsslinks_widget_target_blank', false ) ) {
$link_target = '_blank';
} else {
$link_target = '_self';
}
if ( 'image' == $format || 'text-image' == $format ) {
/**
* Filters the image used as RSS icon in the RSS widget.
*
* @module widgets
*
* @since 3.6.0
*
* @param string $var URL of RSS Widget icon.
*/
$link_image = apply_filters( 'jetpack_rss_widget_icon', plugins_url( 'images/rss/' . $args['imagecolor'] . '-' . $args['imagesize'] . '.png', dirname( dirname( __FILE__ ) ) ) );
$link_item = '<a target="' . $link_target . '" href="' . get_bloginfo( $rss_type ) . '" title="' . esc_attr( $subscribe_to ) . '"><img src="' . esc_url( $link_image ) . '" alt="RSS Feed" /></a>';
}
if ( 'text-image' == $format ) {
$link_item .= '&nbsp;<a target="' . $link_target . '" href="' . get_bloginfo( $rss_type ) . '" title="' . esc_attr( $subscribe_to ) . '">' . esc_html__( 'RSS - ' . $type_text, 'jetpack' ). '</a>';
}
if ( 'text' == $format ) {
$link_item = '<a target="' . $link_target . '" href="' . get_bloginfo( $rss_type ) . '" title="' . esc_attr( $subscribe_to ) . '">' . esc_html__( 'RSS - ' . $type_text, 'jetpack' ). '</a>';
}
if ( 'text' == $format )
echo '<li>';
else
echo '<p>';
echo $link_item;
if ( 'text' == $format )
echo '</li>';
else
echo '</p>';
}
} // Class Jetpack_RSS_Links_Widget
function jetpack_rss_links_widget_init() {
register_widget( 'Jetpack_RSS_Links_Widget' );
}
add_action( 'widgets_init', 'jetpack_rss_links_widget_init' );

View file

@ -0,0 +1,253 @@
<?php
/*
Plugin Name: Social Media Icons Widget
Description: A simple widget that displays social media icons
Author: Chris Rudzki
*/
// Creating the widget
class WPCOM_social_media_icons_widget extends WP_Widget {
private $defaults;
private $services;
public function __construct() {
parent::__construct(
'wpcom_social_media_icons_widget',
/** This filter is documented in modules/widgets/facebook-likebox.php */
apply_filters( 'jetpack_widget_name', esc_html__( 'Social Media Icons', 'jetpack' ) ),
array(
'description' => __( 'A simple widget that displays social media icons.', 'jetpack' ),
'customize_selective_refresh' => true,
)
);
$this->defaults = array(
'title' => __( 'Social', 'jetpack' ),
'facebook_username' => '',
'twitter_username' => '',
'instagram_username' => '',
'pinterest_username' => '',
'linkedin_username' => '',
'github_username' => '',
'youtube_username' => '',
'vimeo_username' => '',
'googleplus_username' => '',
);
$this->services = array(
'facebook' => array( 'Facebook', 'https://www.facebook.com/%s/' ),
'twitter' => array( 'Twitter', 'https://twitter.com/%s/' ),
'instagram' => array( 'Instagram', 'https://instagram.com/%s/' ),
'pinterest' => array( 'Pinterest', 'https://www.pinterest.com/%s/' ),
'linkedin' => array( 'LinkedIn', 'https://www.linkedin.com/in/%s/' ),
'github' => array( 'GitHub', 'https://github.com/%s/' ),
'youtube' => array( 'YouTube', 'https://www.youtube.com/%s/' ),
'vimeo' => array( 'Vimeo', 'https://vimeo.com/%s/' ),
'googleplus' => array( 'Google+', 'https://plus.google.com/u/0/%s/' ),
);
if ( is_active_widget( false, false, $this->id_base ) || is_customize_preview() ) {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) );
}
}
public function enqueue_style() {
wp_register_style( 'jetpack_social_media_icons_widget', plugins_url( 'social-media-icons/style.css', __FILE__ ), array(), '20150602' );
wp_enqueue_style( 'jetpack_social_media_icons_widget' );
}
private function check_genericons() {
global $wp_styles;
foreach ( $wp_styles->queue as $handle ) {
if ( false !== stristr( $handle, 'genericons' ) ) {
return $handle;
}
}
return false;
}
// front end
public function widget( $args, $instance ) {
$instance = wp_parse_args( (array) $instance, $this->defaults );
/** This filter is documented in core/src/wp-includes/default-widgets.php */
$instance['title'] = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
if ( ! $this->check_genericons() ) {
wp_enqueue_style( 'genericons' );
}
$index = 10;
$html = array();
$alt_text = esc_attr__( 'View %1$s&#8217;s profile on %2$s', 'jetpack' );
foreach ( $this->services as $service => $data ) {
list( $service_name, $url ) = $data;
if ( ! isset( $instance[ $service . '_username' ] ) ) {
continue;
}
$username = $link_username = $instance[ $service . '_username' ];
if ( empty( $username ) ) {
continue;
}
$index += 10;
if (
$service === 'googleplus'
&& ! is_numeric( $username )
&& substr( $username, 0, 1 ) !== "+"
) {
$link_username = "+" . $username;
}
if ( $service === 'youtube' && substr( $username, 0, 2 ) == 'UC' ) {
$link_username = "channel/" . $username;
} else if ( $service === 'youtube' ) {
$link_username = "user/" . $username;
}
/**
* Fires for each profile link in the social icons widget. Can be used
* to change the links for certain social networks if needed.
*
* @module widgets
*
* @since 3.8.0
*
* @param string $url the currently processed URL
* @param string $service the lowercase service slug, e.g. 'facebook', 'youtube', etc.
*/
$link = apply_filters( 'jetpack_social_media_icons_widget_profile_link', esc_url( sprintf( $url, $link_username ) ), $service );
$html[ $index ] =
'<a title="' . sprintf( $alt_text, esc_attr( $username ), $service_name )
. '" href="' . $link
. '" class="genericon genericon-' . $service . '" target="_blank"><span class="screen-reader-text">'
. sprintf( $alt_text, esc_html( $username ), $service_name )
. '</span></a>';
}
/**
* Fires at the end of the list of Social Media accounts.
* Can be used to add a new Social Media Site to the Social Media Icons Widget.
* The filter function passed the array of HTML entries that will be sorted
* by key, each wrapped in a list item element and output as an unsorted list.
*
* @module widgets
*
* @since 3.8.0
*
* @param array $html Associative array of HTML snippets per each icon.
*/
$html = apply_filters( 'jetpack_social_media_icons_widget_array', $html );
ksort( $html );
$html = '<ul><li>' . join( '</li><li>', $html ) . '</li></ul>';
if ( ! empty( $instance['title'] ) ) {
$html = $args['before_title'] . esc_html( $instance['title'] ) . $args['after_title'] . $html;
}
$html = $args['before_widget'] . $html . $args['after_widget'];
/**
* Filters the Social Media Icons widget output.
*
* @module widgets
*
* @since 3.6.0
*
* @param string $html Social Media Icons widget html output.
*/
echo apply_filters( 'jetpack_social_media_icons_widget_output', $html );
}
// backend
public function form( $instance ) {
$instance = wp_parse_args( (array) $instance, $this->defaults );
?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:', 'jetpack' ); ?></label>
<input
class="widefat"
id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
type="text"
value="<?php echo esc_attr( $instance['title'] ); ?>"
/>
</p>
<?php
foreach ( $this->services as $service => $data ) {
list( $service_name, $url ) = $data;
?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( $service . '_username' ) ); ?>">
<?php
/* translators: %s is a social network name, e.g. Facebook */
printf( __( '%s username:', 'jetpack' ), $service_name );
?>
</label>
<input
class="widefat"
id="<?php echo esc_attr( $this->get_field_id( $service . '_username' ) ); ?>"
name="<?php echo esc_attr( $this->get_field_name( $service . '_username' ) ); ?>"
type="text"
value="<?php echo esc_attr( $instance[ $service . '_username'] ); ?>"
/>
</p>
<?php
}
}
// updating widget settings
public function update( $new_instance, $old_instance ) {
$instance = (array) $old_instance;
foreach ( $new_instance as $field => $value ) {
$instance[$field] = sanitize_text_field( $new_instance[$field] );
}
// Stats
$stats = $instance;
unset( $stats['title'] );
$stats = array_filter( $stats );
$stats = array_keys( $stats );
$stats = array_map( array( $this, 'remove_username' ), $stats );
foreach ( $stats as $val ) {
/**
* Fires for each Social Media account being saved in the Social Media Widget settings.
*
* @module widgets
*
* @since 3.6.0
*
* @param string social-media-links-widget-svcs Type of action to track.
* @param string $val Name of the Social Media account being saved.
*/
do_action( 'jetpack_bump_stats_extras', 'social-media-links-widget-svcs', $val ) ;
}
return $instance;
}
// Remove username from value before to save stats
public function remove_username( $val ) {
return str_replace( '_username', '', $val );
}
} // class ends here
// register and load the widget
function wpcom_social_media_icons_widget_load_widget() {
register_widget( 'wpcom_social_media_icons_widget' );
}
add_action( 'widgets_init', 'wpcom_social_media_icons_widget_load_widget' );

View file

@ -0,0 +1,49 @@
.widget_wpcom_social_media_icons_widget ul {
list-style-type: none;
margin-left: 0;
}
.widget_wpcom_social_media_icons_widget li {
border: 0 none;
display: inline;
margin-right: 0.5em;
}
.widget_wpcom_social_media_icons_widget li a {
border: 0 none;
text-decoration: none;
}
.widget_wpcom_social_media_icons_widget .genericon {
font-family: 'Genericons';
}
.widget_wpcom_social_media_icons_widget .screen-reader-text {
clip: rect(1px, 1px, 1px, 1px);
position: absolute !important;
height: 1px;
width: 1px;
overflow: hidden;
}
.widget_wpcom_social_media_icons_widget .screen-reader-text:hover,
.widget_wpcom_social_media_icons_widget .screen-reader-text:active,
.widget_wpcom_social_media_icons_widget .screen-reader-text:focus {
background-color: #f1f1f1;
border-radius: 3px;
box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.6);
clip: auto !important;
color: #21759b;
display: block;
font-size: 14px;
font-size: 0.875rem;
font-weight: bold;
height: auto;
left: 5px;
line-height: normal;
padding: 15px 23px 14px;
text-decoration: none;
top: 5px;
width: auto;
z-index: 100000; /* Above WP toolbar. */
}

View file

@ -0,0 +1,585 @@
<?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 {
public $alt_option_name = 'widget_stats_topposts';
public $default_title = '';
function __construct() {
parent::__construct(
'top-posts',
/** This filter is documented in modules/widgets/facebook-likebox.php */
apply_filters( 'jetpack_widget_name', __( 'Top Posts &amp; Pages', 'jetpack' ) ),
array(
'description' => __( 'Shows your most viewed posts and pages.', 'jetpack' ),
'customize_selective_refresh' => true,
)
);
$this->default_title = __( 'Top Posts &amp; Pages', 'jetpack' );
if ( is_active_widget( false, false, $this->id_base ) || is_customize_preview() ) {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) );
}
/**
* Add explanation about how the statistics are calculated.
*
* @module widgets
*
* @since 3.9.3
*/
add_action( 'jetpack_widget_top_posts_after_fields', array( $this, 'stats_explanation' ) );
}
function enqueue_style() {
wp_register_style( 'jetpack-top-posts-widget', plugins_url( 'top-posts/style.css', __FILE__ ), array(), '20141013' );
wp_enqueue_style( 'jetpack-top-posts-widget' );
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, $this->defaults() );
$title = stripslashes( $instance['title'] );
$count = isset( $instance['count'] ) ? (int) $instance['count'] : 10;
if ( $count < 1 || 10 < $count ) {
$count = 10;
}
$allowed_post_types = array_values( get_post_types( array( 'public' => true ) ) );
$types = isset( $instance['types'] ) ? (array) $instance['types'] : array( 'post', 'page' );
// 'likes' are not available in Jetpack
$ordering = isset( $instance['ordering'] ) && 'likes' === $instance['ordering'] ? 'likes' : 'views';
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( 'Maximum number of posts to show (no more than 10):', '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="10" />
</p>
<?php if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) : ?>
<p>
<label><?php esc_html_e( 'Order Top Posts &amp; Pages By:', 'jetpack' ); ?></label>
<ul>
<li><label><input id="<?php echo $this->get_field_id( 'ordering' ); ?>-likes" name="<?php echo $this->get_field_name( 'ordering' ); ?>" type="radio" value="likes" <?php checked( 'likes', $ordering ); ?> /> <?php esc_html_e( 'Likes', 'jetpack' ); ?></label></li>
<li><label><input id="<?php echo $this->get_field_id( 'ordering' ); ?>-views" name="<?php echo $this->get_field_name( 'ordering' ); ?>" type="radio" value="views" <?php checked( 'views', $ordering ); ?> /> <?php esc_html_e( 'Views', 'jetpack' ); ?></label></li>
</ul>
</p>
<?php endif; ?>
<p>
<label for="<?php echo $this->get_field_id( 'types' ); ?>"><?php esc_html_e( 'Types of pages to display:', 'jetpack' ); ?></label>
<ul>
<?php foreach( $allowed_post_types as $type ) {
// Get the Post Type name to display next to the checkbox
$post_type_object = get_post_type_object( $type );
$label = $post_type_object->labels->name;
$checked = '';
if ( in_array( $type, $types ) ) {
$checked = 'checked="checked" ';
} ?>
<li><label>
<input value="<?php echo esc_attr( $type ); ?>" name="<?php echo $this->get_field_name( 'types' ); ?>[]" id="<?php echo $this->get_field_id( 'types' ); ?>-<?php echo $type; ?>" type="checkbox" <?php echo $checked; ?>>
<?php echo esc_html( $label ); ?>
</label></li>
<?php } // End foreach ?>
</ul>
</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><?php
/**
* Fires after the fields are displayed in the Top Posts Widget settings in wp-admin.
*
* Allow adding extra content after the fields are displayed.
*
* @module widgets
*
* @since 3.9.3
*
* @param array $args {
* @param array $instance The widget instance.
* @param object $this The class object.
* }
*/
do_action( 'jetpack_widget_top_posts_after_fields', array( $instance, $this ) );
}
/**
* Explains how the statics are calculated.
*/
function stats_explanation() {
?>
<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 || 10 < $instance['count'] ) {
$instance['count'] = 10;
}
// 'likes' are not available in Jetpack
$instance['ordering'] = isset( $new_instance['ordering'] ) && 'likes' == $new_instance['ordering'] ? 'likes' : 'views';
$allowed_post_types = array_values( get_post_types( array( 'public' => true ) ) );
$instance['types'] = $new_instance['types'];
foreach( $new_instance['types'] as $key => $type ) {
if ( ! in_array( $type, $allowed_post_types ) ) {
unset( $new_instance['types'][ $key ] );
}
}
if ( isset( $new_instance['display'] ) && in_array( $new_instance['display'], array( 'grid', 'list', 'text' ) ) ) {
$instance['display'] = $new_instance['display'];
} else {
$instance['display'] = 'text';
}
/**
* Filters Top Posts Widget settings before they're saved.
*
* @module widgets
*
* @since 3.9.3
*
* @param array $instance The santized widget instance. Only contains data processed by the current widget.
* @param array $new_instance The new widget instance before sanitization.
*/
$instance = apply_filters( 'jetpack_top_posts_saving', $instance, $new_instance );
return $instance;
}
function widget( $args, $instance ) {
$instance = wp_parse_args( (array) $instance, $this->defaults() );
$title = isset( $instance['title' ] ) ? $instance['title'] : false;
if ( false === $title ) {
$title = $this->default_title;
}
/** This filter is documented in core/src/wp-includes/default-widgets.php */
$title = apply_filters( 'widget_title', $title );
$count = isset( $instance['count'] ) ? (int) $instance['count'] : false;
if ( $count < 1 || 10 < $count ) {
$count = 10;
}
/**
* Control the number of displayed posts.
*
* @module widgets
*
* @since 3.3.0
*
* @param string $count Number of Posts displayed in the Top Posts widget. Default is 10.
*/
$count = apply_filters( 'jetpack_top_posts_widget_count', $count );
$types = isset( $instance['types'] ) ? (array) $instance['types'] : array( 'post', 'page' );
// 'likes' are not available in Jetpack
$ordering = isset( $instance['ordering'] ) && 'likes' == $instance['ordering'] ? 'likes' : 'views';
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,
/** This filter is documented in modules/shortcodes/audio.php */
'gravatar_default' => apply_filters( 'jetpack_static_url', set_url_scheme( 'http://en.wordpress.com/i/logo/white-gray-80.png' ) ),
);
if ( 'grid' == $display ) {
$get_image_options['avatar_size'] = 200;
} else {
$get_image_options['avatar_size'] = 40;
}
/**
* Top Posts Widget Image options.
*
* @module widgets
*
* @since 1.8.0
*
* @param array $get_image_options {
* Array of Image options.
* @type bool true Should we default to Gravatars when no image is found? Default is true.
* @type string $gravatar_default Default Image URL if no Gravatar is found.
* @type int $avatar_size Default Image size.
* }
*/
$get_image_options = apply_filters( 'jetpack_top_posts_widget_image_options', $get_image_options );
}
if ( function_exists( 'wpl_get_blogs_most_liked_posts' ) && 'likes' == $ordering ) {
$posts = $this->get_by_likes( $count );
} else {
$posts = $this->get_by_views( $count, $args );
}
// Filter the returned posts. Remove all posts that do not match the chosen Post Types.
if ( isset( $types ) ) {
foreach ( $posts as $k => $post ) {
if ( ! in_array( $post['post_type'], $types ) ) {
unset( $posts[$k] );
}
}
}
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" target="_blank">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'], 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 "<div class='widgets-grid-layout no-grav'>\n";
foreach ( $posts as $post ) :
?>
<div class="widget-grid-view-image">
<?php
/**
* Fires before each Top Post result, inside <li>.
*
* @module widgets
*
* @since 3.2.0
*
* @param string $post['post_id'] Post ID.
*/
do_action( 'jetpack_widget_top_posts_before_post', $post['post_id'] );
?>
<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">
<?php $size = (int) $get_image_options['avatar_size']; ?>
<img width="<?php echo absint( $size ); ?>" height="<?php echo absint( $size ); ?>" src="<?php echo esc_url( $post['image'] ); ?>" alt="<?php echo esc_attr( wp_kses( $post['title'], array() ) ); ?>" data-pin-nopin="true" />
</a>
<?php
/**
* Fires after each Top Post result, inside <li>.
*
* @module widgets
*
* @since 3.2.0
*
* @param string $post['post_id'] Post ID.
*/
do_action( 'jetpack_widget_top_posts_after_post', $post['post_id'] );
?>
</div>
<?php
endforeach;
echo "</div>\n";
} else {
echo "<ul class='widgets-list-layout no-grav'>\n";
foreach ( $posts as $post ) :
?>
<li>
<?php
/** This action is documented in modules/widgets/top-posts.php */
do_action( 'jetpack_widget_top_posts_before_post', $post['post_id'] );
?>
<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">
<?php $size = (int) $get_image_options['avatar_size']; ?>
<img width="<?php echo absint( $size ); ?>" height="<?php echo absint( $size ); ?>" src="<?php echo esc_url( $post['image'] ); ?>" class='widgets-list-layout-blavatar' alt="<?php echo esc_attr( wp_kses( $post['title'], array() ) ); ?>" data-pin-nopin="true" />
</a>
<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>
<?php
/** This action is documented in modules/widgets/top-posts.php */
do_action( 'jetpack_widget_top_posts_after_post', $post['post_id'] );
?>
</li>
<?php
endforeach;
echo "</ul>\n";
}
break;
default :
echo '<ul>';
foreach ( $posts as $post ) :
?>
<li>
<?php
/** This action is documented in modules/widgets/top-posts.php */
do_action( 'jetpack_widget_top_posts_before_post', $post['post_id'] );
?>
<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>
<?php
/** This action is documented in modules/widgets/top-posts.php */
do_action( 'jetpack_widget_top_posts_after_post', $post['post_id'] );
?>
</li>
<?php
endforeach;
echo '</ul>';
}
echo $args['after_widget'];
}
public static function defaults() {
return array(
'title' => esc_html__( 'Top Posts &amp; Pages', 'jetpack' ),
'count' => absint( 10 ),
'types' => array( 'post', 'page' ),
'ordering' => 'views',
'display' => 'text',
);
}
/*
* Get most liked posts
*
* ONLY TO BE USED IN WPCOM
*/
function get_by_likes( $count ) {
$post_likes = wpl_get_blogs_most_liked_posts();
if ( !$post_likes ) {
return array();
}
return $this->get_posts( array_keys( $post_likes ), $count );
}
function get_by_views( $count, $args ) {
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
global $wpdb;
$post_views = wp_cache_get( "get_top_posts_$count", 'stats' );
if ( false === $post_views ) {
$post_views = array_shift( stats_get_daily_history( false, get_current_blog_id(), 'postviews', 'post_id', false, 2, '', $count * 2 + 10, true ) );
unset( $post_views[0] );
wp_cache_add( "get_top_posts_$count", $post_views, 'stats', 1200);
}
return $this->get_posts( array_keys( $post_views ), $count );
}
/**
* Filter the number of days used to calculate Top Posts for the Top Posts widget.
*
* @module widgets
*
* @since 3.9.3
*
* @param int 2 Number of days. Default is 2.
* @param array $args The widget arguments.
*/
$days = (int) apply_filters( 'jetpack_top_posts_days', 2, $args );
if ( $days < 1 ) {
$days = 2;
}
if ( $days > 10 ) {
$days = 10;
}
$post_view_posts = stats_get_csv( 'postviews', array( 'days' => absint( $days ), 'limit' => 11 ) );
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 );
$post_type = $post->post_type;
$posts[] = compact( 'title', 'permalink', 'post_id', 'post_type' );
$counter++;
if ( $counter == $count ) {
break; // only need to load and show x number of likes
}
}
/**
* Filter the Top Posts and Pages.
*
* @module widgets
*
* @since 3.0.0
*
* @param array $posts Array of the most popular posts.
* @param array $post_ids Array of Post IDs.
* @param string $count Number of Top Posts we want to display.
*/
return apply_filters( 'jetpack_widget_get_top_posts', $posts, $post_ids, $count );
}
}
/**
* Create a shortcode to display the widget anywhere.
*
* @since 3.9.2
*/
function jetpack_do_top_posts_widget( $instance ) {
// Post Types can't be entered as an array in the shortcode parameters.
if ( isset( $instance['types'] ) && is_array( $instance['types'] ) ) {
$instance['types'] = implode( ',', $instance['types'] );
}
$instance = shortcode_atts(
Jetpack_Top_Posts_Widget::defaults(),
$instance,
'jetpack_top_posts_widget'
);
// Add a class to allow styling
$args = array(
'before_widget' => sprintf( '<div class="%s">', 'jetpack_top_posts_widget' ),
);
ob_start();
the_widget( 'Jetpack_Top_Posts_Widget', $instance, $args );
$output = ob_get_clean();
return $output;
}
add_shortcode( 'jetpack_top_posts_widget', 'jetpack_do_top_posts_widget' );

View file

@ -0,0 +1,114 @@
/*
* Top Posts Widget styles for Jetpack
*/
/* 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;
}

View file

@ -0,0 +1,264 @@
<?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',
/** This filter is documented in modules/widgets/facebook-likebox.php */
apply_filters( 'jetpack_widget_name', esc_html__( 'Twitter Timeline', 'jetpack' ) ),
array(
'classname' => 'widget_twitter_timeline',
'description' => __( 'Display an official Twitter Embedded Timeline widget.', 'jetpack' ),
'customize_selective_refresh' => true,
)
);
if ( is_active_widget( false, false, $this->id_base ) || is_active_widget( false, false, 'monster' ) || is_customize_preview() ) {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
}
}
/**
* Enqueue scripts.
*/
public function enqueue_scripts() {
wp_enqueue_script( 'jetpack-twitter-timeline' );
}
/**
* Enqueue Twitter's widget library.
*
* @deprecated
*/
public function library() {
_deprecated_function( __METHOD__, '4.0.0' );
wp_print_scripts( array( 'jetpack-twitter-timeline' ) );
}
/**
* 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'] ) {
/** This filter is documented in core/src/wp-includes/default-widgets.php */
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
}
$data_attribs = array( 'widget-id', 'theme', 'link-color', 'border-color', 'chrome', 'tweet-limit' );
$attribs = array( 'width', 'height', 'lang' );
// Start tag output
echo '<a class="twitter-timeline"';
foreach ( $data_attribs as $att ) {
if ( !empty( $instance[$att] ) ) {
if ( 'tweet-limit' == $att && 0 === $instance[$att] )
continue;
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 '>';
$timeline_placeholder = __( 'My Tweets', 'jetpack' );
/**
* Filter the Timeline placeholder text.
*
* @module widgets
*
* @since 3.4.0
*
* @param string $timeline_placeholder Timeline placeholder text.
*/
$timeline_placeholder = apply_filters( 'jetpack_twitter_timeline_placeholder', $timeline_placeholder );
echo esc_html( $timeline_placeholder ) . '</a>';
// End tag output
echo $args['after_widget'];
/** This action is documented in modules/widgets/social-media-icons.php */
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 ) {
$hex_regex = '/#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?\b/';
$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) $new_instance['width'] ) ? (int) $new_instance['width'] : '';
$instance['height'] = ( 0 !== (int) $new_instance['height'] ) ? (int) $new_instance['height'] : '';
$instance['tweet-limit'] = ( 0 !== (int) $new_instance['tweet-limit'] ) ? (int) $new_instance['tweet-limit'] : null;
// 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 ) {
$new_color = sanitize_text_field( $new_instance[$color] );
if ( preg_match( $hex_regex, $new_color ) ) {
$instance[$color] = $new_color;
}
}
$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(),
'tweet-limit' => null,
);
$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( 'Maximum 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>
<label for="<?php echo $this->get_field_id( 'tweet-limit' ); ?>"><?php esc_html_e( '# of Tweets Shown:', 'jetpack' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'tweet-limit' ); ?>" name="<?php echo $this->get_field_name( 'tweet-limit' ); ?>" type="number" min="1" max="20" value="<?php echo esc_attr( $instance['tweet-limit'] ); ?>" />
</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
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,24 @@
.jetpack-display-remote-posts {
margin: 5px 0 20px 0;
}
.jetpack-display-remote-posts h4 {
font-size: 90%;
margin: 5px 0;
padding: 0;
}
.jetpack-display-remote-posts h4 a {
text-decoration: none;
}
.jetpack-display-remote-posts p {
margin: 0 !important;
padding: 0;
line-height: 1.4em !important;
font-size: 90%;
}
.jetpack-display-remote-posts img {
max-width: 100%;
}