Jetpack_Upcoming_Events_Widget

The WordPress Core Jetpack Upcoming Events Widget class.

Defined (1)

The class is defined in the following location(s).

/modules/widgets/upcoming-events.php  
  1. class Jetpack_Upcoming_Events_Widget extends WP_Widget { 
  2. function __construct() { 
  3. parent::__construct( 
  4. 'upcoming_events_widget',  
  5. /** This filter is documented in modules/widgets/facebook-likebox.php */ 
  6. apply_filters( 'jetpack_widget_name', __( 'Upcoming Events', 'jetpack' ) ),  
  7. array( 
  8. 'description' => __( 'Display upcoming events from an iCalendar feed.', 'jetpack' ),  
  9. 'customize_selective_refresh' => true,  
  10. ); 
  11. if ( is_active_widget( false, false, $this->id_base ) ) { 
  12. add_action( 'wp_head', array( $this, 'css' ) ); 
  13.  
  14. function css() { 
  15. ?> 
  16. <style type="text/css"> 
  17. .upcoming-events li { 
  18. margin-bottom: 10px; 
  19. .upcoming-events li span { 
  20. display: block; 
  21. </style> 
  22. <?php 
  23.  
  24. function form( $instance ) { 
  25. $defaults = array( 
  26. 'title' => __( 'Upcoming Events', 'jetpack' ),  
  27. 'feed-url' => '',  
  28. 'count' => 3 
  29. ); 
  30. $instance = array_merge( $defaults, (array) $instance ); 
  31. ?> 
  32.  
  33. <p> 
  34. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'jetpack' ); ?></label> 
  35. <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'] ); ?>" /> 
  36. </p> 
  37.  
  38. <p> 
  39. <label for="<?php echo $this->get_field_id( 'feed-url' ); ?>"><?php _e( 'iCalendar Feed URL:', 'jetpack' ); ?></label> 
  40. <input class="widefat" id="<?php echo $this->get_field_id( 'feed-url' ); ?>" name="<?php echo $this->get_field_name( 'feed-url' ); ?>" type="text" value="<?php echo esc_attr( $instance['feed-url'] ); ?>" /> 
  41. </p> 
  42.  
  43. <p> 
  44. <label for="<?php echo $this->get_field_id( 'count' ); ?>"><?php _e( 'Items to show:', 'jetpack' ); ?></label> 
  45. <select id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>"> 
  46. <?php $i = 1; 
  47. while ( $i <= 10 ) { ?> 
  48. <option <?php selected( $instance['count'], $i ) ?>><?php echo $i; ?></option> 
  49. <?php $i++; } ?> 
  50. <option value="0" <?php selected( $instance['count'], 0 ) ?>><?php _e( 'All' , 'jetpack' ) ?></option> 
  51. </select> 
  52. </p> 
  53. <?php 
  54.  
  55. function update( $new_instance, $old_instance ) { 
  56. $instance['title'] = strip_tags( $new_instance['title'] ); 
  57. $instance['feed-url'] = strip_tags( $new_instance['feed-url'] ); 
  58. $instance['count'] = min( absint( $new_instance['count'] ), 10 ); // 10 or less 
  59. return $instance; 
  60.  
  61. function widget( $args, $instance ) { 
  62. jetpack_require_lib( 'icalendar-reader' ); 
  63.  
  64. $ical = new iCalendarReader(); 
  65. $events = $ical->get_events( $instance['feed-url'], $instance['count'] ); 
  66. $events = $this->apply_timezone_offset( $events ); 
  67. $ical->timezone = null; 
  68.  
  69. echo $args['before_widget']; 
  70. if ( ! empty( $instance['title'] ) ) { 
  71. echo $args['before_title']; 
  72. echo esc_html( $instance['title'] ); 
  73. echo $args['after_title']; 
  74.  
  75. if ( ! $events ) : // nothing to display? 
  76. ?> 
  77. <p><?php echo __( 'No upcoming events', 'jetpack' ) ?></p> 
  78. <?php 
  79. else : 
  80. ?> 
  81. <ul class="upcoming-events"> 
  82. <?php foreach ( $events as $event ) : ?> 
  83. <li> 
  84. <strong class="event-summary"><?php echo $ical->escape( stripslashes( $event['SUMMARY'] ) ); ?></strong> 
  85. <span class="event-when"><?php echo $ical->formatted_date( $event ); ?></span> 
  86. <?php if ( ! empty( $event['LOCATION'] ) ) : ?> 
  87. <span class="event-location"><?php echo $ical->escape( stripslashes( $event['LOCATION'] ) ); ?></span> 
  88. <?php endif; ?> 
  89. <?php if ( ! empty( $event['DESCRIPTION'] ) ) : ?> 
  90. <span class="event-description"><?php echo wp_trim_words( $ical->escape( stripcslashes( $event['DESCRIPTION'] ) ) ); ?></span> 
  91. <?php endif; ?> 
  92. </li> 
  93. <?php endforeach; ?> 
  94. </ul> 
  95. <?php 
  96. endif; 
  97.  
  98. echo $args['after_widget']; 
  99.  
  100. /** This action is documented in modules/widgets/gravatar-profile.php */ 
  101. do_action( 'jetpack_stats_extra', 'widget_view', 'grofile' ); 
  102.  
  103. // Left this function here for backward compatibility 
  104. // just incase a site using jetpack is also using this function 
  105. function apply_timezone_offset( $events ) { 
  106. jetpack_require_lib( 'icalendar-reader' ); 
  107.  
  108. $ical = new iCalendarReader(); 
  109. return $ical->apply_timezone_offset( $events );