PageRenderTime 23ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/shop quần áo starloveshop.com/wp-content/plugins/jetpack/modules/widgets/twitter-timeline.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 244 lines | 165 code | 38 blank | 41 comment | 16 complexity | b0a6ff184569bab72f8045d6b9d5884b MD5 | raw file
  1. <?php
  2. /*
  3. * Based on Evolution Twitter Timeline (http://wordpress.org/extend/plugins/evolution-twitter-timeline/)
  4. * See: https://twitter.com/settings/widgets and https://dev.twitter.com/docs/embedded-timelines for details on Twitter Timelines
  5. */
  6. /**
  7. * Register the widget for use in Appearance -> Widgets
  8. */
  9. add_action( 'widgets_init', 'jetpack_twitter_timeline_widget_init' );
  10. function jetpack_twitter_timeline_widget_init() {
  11. register_widget( 'Jetpack_Twitter_Timeline_Widget' );
  12. }
  13. class Jetpack_Twitter_Timeline_Widget extends WP_Widget {
  14. /**
  15. * Register widget with WordPress.
  16. */
  17. public function __construct() {
  18. parent::__construct(
  19. 'twitter_timeline',
  20. apply_filters( 'jetpack_widget_name', esc_html__( 'Twitter Timeline', 'jetpack' ) ),
  21. array(
  22. 'classname' => 'widget_twitter_timeline',
  23. 'description' => __( 'Display an official Twitter Embedded Timeline widget.', 'jetpack' )
  24. )
  25. );
  26. if ( is_active_widget( false, false, $this->id_base ) || is_active_widget( false, false, 'monster' ) ) {
  27. add_action( 'wp_footer', array( $this, 'library' ) );
  28. }
  29. }
  30. /**
  31. * Enqueue Twitter's widget library
  32. */
  33. public function library() {
  34. ?>
  35. <script type="text/javascript">
  36. !function(d,s,id){
  37. var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';
  38. if(!d.getElementById(id)){
  39. js=d.createElement(s);
  40. js.id=id;js.src=p+"://platform.twitter.com/widgets.js";
  41. fjs.parentNode.insertBefore(js,fjs);
  42. }
  43. }(document,"script","twitter-wjs");
  44. </script>
  45. <?php
  46. }
  47. /**
  48. * Front-end display of widget.
  49. *
  50. * @see WP_Widget::widget()
  51. *
  52. * @param array $args Widget arguments.
  53. * @param array $instance Saved values from database.
  54. */
  55. public function widget( $args, $instance ) {
  56. $instance['lang'] = substr( strtoupper( get_locale() ), 0, 2 );
  57. echo $args['before_widget'];
  58. if ( $instance['title'] )
  59. echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
  60. $data_attribs = array( 'widget-id', 'theme', 'link-color', 'border-color', 'chrome', 'tweet-limit' );
  61. $attribs = array( 'width', 'height', 'lang' );
  62. // Start tag output
  63. echo '<a class="twitter-timeline"';
  64. foreach ( $data_attribs as $att ) {
  65. if ( !empty( $instance[$att] ) ) {
  66. if ( 'tweet-limit' == $att && 0 === $instance[$att] )
  67. continue;
  68. if ( is_array( $instance[$att] ) )
  69. echo ' data-' . esc_attr( $att ) . '="' . esc_attr( join( ' ', $instance['chrome'] ) ) . '"';
  70. else
  71. echo ' data-' . esc_attr( $att ) . '="' . esc_attr( $instance[$att] ) . '"';
  72. }
  73. }
  74. foreach ( $attribs as $att ) {
  75. if ( !empty( $instance[$att] ) )
  76. echo ' ' . esc_attr( $att ) . '="' . esc_attr( $instance[$att] ) . '"';
  77. }
  78. echo '>' . esc_html__( 'My Tweets', 'jetpack' ) . '</a>';
  79. // End tag output
  80. echo $args['after_widget'];
  81. do_action( 'jetpack_bump_stats_extras', 'widget', 'twitter_timeline' );
  82. }
  83. /**
  84. * Sanitize widget form values as they are saved.
  85. *
  86. * @see WP_Widget::update()
  87. *
  88. * @param array $new_instance Values just sent to be saved.
  89. * @param array $old_instance Previously saved values from database.
  90. *
  91. * @return array Updated safe values to be saved.
  92. */
  93. public function update( $new_instance, $old_instance ) {
  94. $hex_regex = '/#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?\b/';
  95. $instance = array();
  96. $instance['title'] = sanitize_text_field( $new_instance['title'] );
  97. $instance['width'] = (int) $new_instance['width'];
  98. $instance['height'] = (int) $new_instance['height'];
  99. $instance['width'] = ( 0 !== (int) $new_instance['width'] ) ? (int) $new_instance['width'] : 225;
  100. $instance['height'] = ( 0 !== (int) $new_instance['height'] ) ? (int) $new_instance['height'] : 400;
  101. $instance['tweet-limit'] = ( 0 !== (int) $new_instance['tweet-limit'] ) ? (int) $new_instance['tweet-limit'] : null;
  102. // If they entered something that might be a full URL, try to parse it out
  103. if ( is_string( $new_instance['widget-id'] ) ) {
  104. if ( preg_match( '#https?://twitter\.com/settings/widgets/(\d+)#s', $new_instance['widget-id'], $matches ) ) {
  105. $new_instance['widget-id'] = $matches[1];
  106. }
  107. }
  108. $instance['widget-id'] = sanitize_text_field( $new_instance['widget-id'] );
  109. $instance['widget-id'] = is_numeric( $instance['widget-id'] ) ? $instance['widget-id'] : '';
  110. foreach ( array( 'link-color', 'border-color' ) as $color ) {
  111. $new_color = sanitize_text_field( $new_instance[$color] );
  112. if ( preg_match( $hex_regex, $new_color ) ) {
  113. $instance[$color] = $new_color;
  114. }
  115. }
  116. $instance['theme'] = 'light';
  117. if ( in_array( $new_instance['theme'], array( 'light', 'dark' ) ) )
  118. $instance['theme'] = $new_instance['theme'];
  119. $instance['chrome'] = array();
  120. if ( isset( $new_instance['chrome'] ) ) {
  121. foreach ( $new_instance['chrome'] as $chrome ) {
  122. if ( in_array( $chrome, array( 'noheader', 'nofooter', 'noborders', 'noscrollbar', 'transparent' ) ) ) {
  123. $instance['chrome'][] = $chrome;
  124. }
  125. }
  126. }
  127. return $instance;
  128. }
  129. /**
  130. * Back-end widget form.
  131. *
  132. * @see WP_Widget::form()
  133. *
  134. * @param array $instance Previously saved values from database.
  135. */
  136. public function form( $instance ) {
  137. $defaults = array(
  138. 'title' => esc_html__( 'Follow me on Twitter', 'jetpack' ),
  139. 'width' => '',
  140. 'height' => '400',
  141. 'widget-id' => '',
  142. 'link-color' => '#f96e5b',
  143. 'border-color' => '#e8e8e8',
  144. 'theme' => 'light',
  145. 'chrome' => array(),
  146. 'tweet-limit' => null,
  147. );
  148. $instance = wp_parse_args( (array) $instance, $defaults );
  149. ?>
  150. <p>
  151. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'jetpack' ); ?></label>
  152. <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'] ); ?>" />
  153. </p>
  154. <p>
  155. <label for="<?php echo $this->get_field_id( 'width' ); ?>"><?php esc_html_e( 'Width (px):', 'jetpack' ); ?></label>
  156. <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'] ); ?>" />
  157. </p>
  158. <p>
  159. <label for="<?php echo $this->get_field_id( 'height' ); ?>"><?php esc_html_e( 'Height (px):', 'jetpack' ); ?></label>
  160. <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'] ); ?>" />
  161. </p>
  162. <p>
  163. <label for="<?php echo $this->get_field_id( 'tweet-limit' ); ?>"><?php esc_html_e( '# of Tweets Shown:', 'jetpack' ); ?></label>
  164. <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'] ); ?>" />
  165. </p>
  166. <p><small>
  167. <?php
  168. echo wp_kses_post(
  169. sprintf(
  170. __( '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' ),
  171. 'https://twitter.com/settings/widgets/new/user',
  172. 'http://support.wordpress.com/widgets/twitter-timeline-widget/'
  173. )
  174. );
  175. ?>
  176. </small></p>
  177. <p>
  178. <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>
  179. <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'] ); ?>" />
  180. </p>
  181. <p>
  182. <label for="<?php echo $this->get_field_id( 'chrome-noheader' ); ?>"><?php esc_html_e( 'Layout Options:', 'jetpack' ); ?></label><br />
  183. <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 />
  184. <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 />
  185. <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 />
  186. <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 />
  187. <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>
  188. </p>
  189. <p>
  190. <label for="<?php echo $this->get_field_id( 'link-color' ); ?>"><?php _e( 'Link Color (hex):', 'jetpack' ); ?></label>
  191. <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'] ); ?>" />
  192. </p>
  193. <p>
  194. <label for="<?php echo $this->get_field_id( 'border-color' ); ?>"><?php _e( 'Border Color (hex):', 'jetpack' ); ?></label>
  195. <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'] ); ?>" />
  196. </p>
  197. <p>
  198. <label for="<?php echo $this->get_field_id( 'theme' ); ?>"><?php _e( 'Timeline Theme:', 'jetpack' ); ?></label>
  199. <select name="<?php echo $this->get_field_name( 'theme' ); ?>" id="<?php echo $this->get_field_id( 'theme' ); ?>" class="widefat">
  200. <option value="light"<?php selected( $instance['theme'], 'light' ); ?>><?php esc_html_e( 'Light', 'jetpack' ); ?></option>
  201. <option value="dark"<?php selected( $instance['theme'], 'dark' ); ?>><?php esc_html_e( 'Dark', 'jetpack' ); ?></option>
  202. </select>
  203. </p>
  204. <?php
  205. }
  206. }