esc_html__( 'Display your recent Flickr photos.', 'jetpack' ),
'customize_selective_refresh' => true,
),
array()
);
if ( is_active_widget( false, false, $this->id_base ) || is_customize_preview() ) {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) );
}
}
/**
* Enqueue style.
*/
function enqueue_style() {
wp_enqueue_style( 'flickr-widget-style', plugins_url( 'flickr/style.css', __FILE__ ), array(), '20170405' );
}
/**
* Return an associative array of default values.
*
* These values are used in new widgets.
*
* @return array Default values for the widget options.
*/
public function defaults() {
return array(
'title' => esc_html__( 'Flickr Photos', 'jetpack' ),
'items' => 3,
'flickr_image_size' => 'thumbnail',
'flickr_rss_url' => ''
);
}
/**
* Front-end display of the widget.
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget( $args, $instance ) {
$instance = wp_parse_args( $instance, $this->defaults() );
$image_size_string = 'small' == $instance['flickr_image_size'] ? '_m.jpg' : '_t.jpg';
if ( ! empty( $instance['flickr_rss_url'] ) ) {
/*
* Parse the URL, and rebuild a URL that's sure to display images.
* Some Flickr Feeds do not display images by default.
*/
$flickr_parameters = parse_url( htmlspecialchars_decode( $instance['flickr_rss_url'] ) );
// Is it a Flickr Feed.
if (
! empty( $flickr_parameters['host'] )
&& ! empty( $flickr_parameters['query'] )
&& false !== strpos( $flickr_parameters['host'], 'flickr' )
) {
parse_str( $flickr_parameters['query'], $vars );
// Do we have an ID in the feed? Let's continue.
if ( isset( $vars['id'] ) ) {
// Flickr Feeds can be used for groups or for individuals.
if (
! empty( $flickr_parameters['path'] )
&& false !== strpos( $flickr_parameters['path'], 'groups' )
) {
$feed_url = 'https://api.flickr.com/services/feeds/groups_pool.gne';
} else {
$feed_url = 'https://api.flickr.com/services/feeds/photos_public.gne';
}
// Build our new RSS feed.
$rss_url = sprintf(
'%1$s?id=%2$s&format=rss_200_enc',
esc_url( $feed_url ),
esc_attr( $vars['id'] )
);
}
}
} // End if().
// Still no RSS feed URL? Get a default feed from Flickr to grab interesting photos.
if ( empty( $rss_url ) ) {
$rss_url = 'https://api.flickr.com/services/feeds/photos_interesting.gne?format=rss_200';
}
$rss = fetch_feed( $rss_url );
$photos = '';
if ( ! is_wp_error( $rss ) ) {
foreach ( $rss->get_items( 0, $instance['items'] ) as $photo ) {
if ( $enclosure = $photo->get_enclosure() ) {
$src = str_replace( '_s.jpg', $image_size_string, $enclosure->get_thumbnail() );
} else {
$src = preg_match( '/src="(.*?)"/i', $photo->get_description(), $p );
$src = str_replace( '_m.jpg', $image_size_string, $p[1] );
}
$photos .= '';
$photos .= 'get_title() ) . '" ';
$photos .= 'border="0" ';
$photos .= 'title="' . esc_attr( $photo->get_title() ) . '" ';
$photos .= ' />
';
}
if ( ! empty( $photos ) && class_exists( 'Jetpack_Photon' ) && Jetpack::is_module_active( 'photon' ) ) {
$photos = Jetpack_Photon::filter_the_content( $photos );
}
$flickr_home = $rss->get_link();
}
echo $args['before_widget'];
if ( empty( $photos ) ) {
if ( current_user_can( 'edit_theme_options' ) ) {
printf(
'
%1$s
%2$s