diff options
Diffstat (limited to 'plugins/jetpack/modules/widgets/twitter-timeline.php')
-rw-r--r-- | plugins/jetpack/modules/widgets/twitter-timeline.php | 71 |
1 files changed, 53 insertions, 18 deletions
diff --git a/plugins/jetpack/modules/widgets/twitter-timeline.php b/plugins/jetpack/modules/widgets/twitter-timeline.php index 75235294..e794b8fa 100644 --- a/plugins/jetpack/modules/widgets/twitter-timeline.php +++ b/plugins/jetpack/modules/widgets/twitter-timeline.php @@ -29,11 +29,29 @@ class Jetpack_Twitter_Timeline_Widget extends WP_Widget { ); if ( is_active_widget( false, false, $this->id_base ) || is_active_widget( false, false, 'monster' ) ) { - wp_enqueue_script( 'twitter-widgets', '//platform.twitter.com/widgets.js', '', '', true ); + add_action( 'wp_footer', array( $this, 'library' ) ); } } /** + * Enqueue Twitter's widget library + */ + public function library() { + ?> + <script type="text/javascript"> + !function(d,s,id){ + var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https'; + if(!d.getElementById(id)){ + js=d.createElement(s); + js.id=id;js.src=p+"://platform.twitter.com/widgets.js"; + fjs.parentNode.insertBefore(js,fjs); + } + }(document,"script","twitter-wjs"); + </script> + <?php + } + + /** * Front-end display of widget. * * @see WP_Widget::widget() @@ -72,7 +90,21 @@ class Jetpack_Twitter_Timeline_Widget extends WP_Widget { echo ' ' . esc_attr( $att ) . '="' . esc_attr( $instance[$att] ) . '"'; } - echo '>' . esc_html__( 'My Tweets', 'jetpack' ) . '</a>'; + echo '>'; + + $timeline_placeholder = __( 'My Tweets', 'jetpack' ); + + /** + * Filter the Timeline placeholder text + * + * @since 3.4 + * + * @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']; @@ -92,14 +124,14 @@ class Jetpack_Twitter_Timeline_Widget extends WP_Widget { * @return array Updated safe values to be saved. */ public function update( $new_instance, $old_instance ) { - $non_hex_regex = '/[^a-f0-9]/'; - $instance = array(); - $instance['title'] = sanitize_text_field( $new_instance['title'] ); - $instance['width'] = (int) $new_instance['width']; - $instance['height'] = (int) $new_instance['height']; - $instance['width'] = ( 0 !== (int) $new_instance['width'] ) ? (int) $new_instance['width'] : 225; - $instance['height'] = ( 0 !== (int) $new_instance['height'] ) ? (int) $new_instance['height'] : 400; - $instance['tweet-limit'] = (int) $new_instance['tweet-limit']; + $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'] ) ) { @@ -112,9 +144,11 @@ class Jetpack_Twitter_Timeline_Widget extends WP_Widget { $instance['widget-id'] = is_numeric( $instance['widget-id'] ) ? $instance['widget-id'] : ''; foreach ( array( 'link-color', 'border-color' ) as $color ) { - $clean = preg_replace( $non_hex_regex, '', sanitize_text_field( $new_instance[$color] ) ); - if ( $clean ) - $instance[$color] = '#' . $clean; + $new_color = sanitize_text_field( $new_instance[$color] ); + if ( preg_match( $hex_regex, $new_color ) ) { + $instance[$color] = $new_color; + } + } $instance['theme'] = 'light'; @@ -151,6 +185,7 @@ class Jetpack_Twitter_Timeline_Widget extends WP_Widget { 'border-color' => '#e8e8e8', 'theme' => 'light', 'chrome' => array(), + 'tweet-limit' => null, ); $instance = wp_parse_args( (array) $instance, $defaults ); @@ -171,10 +206,10 @@ class Jetpack_Twitter_Timeline_Widget extends WP_Widget { <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="text" value="<?php echo esc_attr( $instance['tweet-limit'] ); ?>" /> - </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 @@ -197,7 +232,7 @@ class Jetpack_Twitter_Timeline_Widget extends WP_Widget { <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( '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> |