SimpleCalendarWidgetsCalendar

Calendar widget.

Defined (1)

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

/includes/widgets/calendar.php  
  1. class Calendar extends \WP_Widget implements Widget { 
  2.  
  3. /** 
  4. * Calendar feeds. 
  5. * @access public 
  6. * @var array 
  7. */ 
  8. public $calendars = array(); 
  9.  
  10. /** 
  11. * Calendar view. 
  12. * @access public 
  13. * @var Calendar_View 
  14. */ 
  15. public $view = null; 
  16.  
  17. /** 
  18. * Constructor. 
  19. * @since 3.0.0 
  20. */ 
  21. public function __construct() { 
  22.  
  23. $id_base = 'gce_widget'; // old id kept for legacy reasons 
  24. $name = __( 'Simple Calendar', 'google-calendar-events' ); 
  25. $widget_options = array( 
  26. 'description' => __( 'Display a calendar of events from one of your calendar feeds.', 'google-calendar-events' ) 
  27. ); 
  28.  
  29. parent::__construct( $id_base, $name, $widget_options ); 
  30.  
  31. if ( is_admin() ) { 
  32. if ( ! defined( 'DOING_AJAX' ) ) { 
  33. $this->calendars = simcal_get_calendars(); 
  34. } else { 
  35. $this->calendars = get_transient( '_simple-calendar_feed_ids' ); 
  36.  
  37. /** 
  38. * Print the widget content. 
  39. * @since 3.0.0 
  40. * @param array $args Display arguments. 
  41. * @param array $instance The settings for the particular instance of the widget. 
  42. */ 
  43. public function widget( $args, $instance ) { 
  44.  
  45. echo $args['before_widget']; 
  46.  
  47. if ( ! empty( $instance['title'] ) ) { 
  48.  
  49. echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title']; 
  50.  
  51. $id = isset( $instance['calendar_id'] ) ? absint( $instance['calendar_id'] ) : 0; 
  52. if ( $id > 0 ) { 
  53. simcal_print_calendar( $id ); 
  54.  
  55. echo $args['after_widget']; 
  56.  
  57. /** 
  58. * Update a particular instance of the widget. 
  59. * This function should check that $new_instance is set correctly. 
  60. * The newly-calculated value of `$instance` should be returned. 
  61. * If false is returned, the instance won't be saved/updated. 
  62. * @since 3.0.0 
  63. * @param array $new_instance New settings for this instance as input by the user via 
  64. * @param array $old_instance Old settings for this instance. 
  65. * @return array Settings to save or bool false to cancel saving. 
  66. */ 
  67. public function update( $new_instance, $old_instance ) { 
  68.  
  69. $instance = array(); 
  70.  
  71. $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( $new_instance['title'] ) : ''; 
  72. $instance['calendar_id'] = ( ! empty( $new_instance['calendar_id'] ) ) ? absint( $new_instance['calendar_id'] ) : ''; 
  73.  
  74. return $instance; 
  75.  
  76. /** 
  77. * Print the settings update form. 
  78. * @since 3.0.0 
  79. * @param array $instance Current settings. 
  80. * @return string 
  81. */ 
  82. public function form( $instance ) { 
  83.  
  84. $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : __( 'Calendar', 'google-calendar-events' ); 
  85. $calendar_id = isset( $instance['calendar_id'] ) ? esc_attr( $instance['calendar_id'] ) : ''; 
  86.  
  87. ?> 
  88. <div class="simcal-calendar-widget-settings"> 
  89.  
  90. <p> 
  91. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'google-calendar-events' ); ?></label> 
  92. <br> 
  93. <input type="text" 
  94. name="<?php echo $this->get_field_name( 'title' ); ?>" 
  95. id="<?php echo $this->get_field_id( 'title' ); ?>" 
  96. class="widefat simcal-field simcal-field-standard simcal-field-text" 
  97. value="<?php echo $title; ?>"> 
  98. </p> 
  99.  
  100. <p> 
  101. <label for="<?php echo $this->get_field_id( 'calendar_id' ); ?>"><?php _e( 'Calendar:', 'google-calendar-events' ); ?></label> 
  102. <br> 
  103. <?php $multiselect = count( $this->calendars ) > 15 ? ' simcal-field-select-enhanced' : ''; ?> 
  104. <select name="<?php echo $this->get_field_name( 'calendar_id' ) ?>" 
  105. id="<?php echo $this->get_field_id( 'calendar_id' ) ?>" 
  106. class="simcal-field simcal-field-select<?php echo $multiselect; ?>" 
  107. data-noresults="<?php __( 'No calendars found.', 'google-calendar-events' ); ?>"> 
  108. <?php foreach ( $this->calendars as $id => $name ) : ?> 
  109. <option value="<?php echo $id; ?>" <?php selected( $id, $calendar_id, true ); ?>><?php echo $name; ?></option> 
  110. <?php endforeach; ?> 
  111. </select> 
  112. </p> 
  113.  
  114. </div> 
  115. <?php 
  116.  
  117.