__('Display a list or calendar grid of events from one or more Google Calendar feeds you have added', GCE_TEXT_DOMAIN))); } function widget($args, $instance){ extract($args); //Output before widget stuff echo $before_widget; //Get saved feed options $options = get_option(GCE_OPTIONS_NAME); //Check whether any feeds have been added yet if(is_array($options) && !empty($options)){ //Output title stuff $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']); if(!empty($title)) echo $before_title . $title . $after_title; //Break comma delimited list of feed ids into array $feed_ids = explode(',', str_replace(' ', '', $instance['id'])); //Check each id is an integer, if not, remove it from the array foreach($feed_ids as $key => $feed_id){ if(absint($feed_id) == 0) unset($feed_ids[$key]); } $no_feeds_exist = true; //If at least one of the feed ids entered exists, set no_feeds_exist to false foreach($feed_ids as $feed_id){ if(isset($options[$feed_id])) $no_feeds_exist = false; } //Check that at least one valid feed id has been entered if(count((array)$feed_ids) == 0 || $no_feeds_exist){ _e('No valid Feed IDs have been entered for this widget. Please check that you have entered the IDs correctly and that the Feeds have not been deleted.', GCE_TEXT_DOMAIN); }else{ //Turns feed_ids back into string or feed ids delimited by '-' ('1-2-3-4' for example) $feed_ids = implode('-', $feed_ids); $title_text = $instance['display_title'] ? $instance['display_title_text'] : null; $max_events = $instance['max_events']; //Output correct widget content based on display type chosen switch($instance['display_type']){ case 'grid': echo '
'; //Output main widget content as grid (no AJAX) gce_widget_content_grid($feed_ids, $title_text, $max_events, $args['widget_id'] . '-container'); echo '
'; break; case 'ajax': echo '
'; //Output main widget content as grid (with AJAX) gce_widget_content_grid($feed_ids, $title_text, $max_events, $args['widget_id'] . '-container', true); echo '
'; break; case 'list': echo '
'; //Output main widget content as list gce_widget_content_list($feed_ids, $title_text, $max_events); echo '
'; break; case 'list-grouped': echo '
'; //Output main widget content as a grouped list gce_widget_content_list($feed_ids, $title_text, $max_events, true); echo '
'; break; } } }else{ _e('No feeds have been added yet. You can add a feed in the Google Calendar Events settings.', GCE_TEXT_DOMAIN); } //Output after widget stuff echo $after_widget; } function update($new_instance, $old_instance){ $instance = $old_instance; $instance['title'] = esc_html($new_instance['title']); $instance['id'] = esc_html($new_instance['id']); $instance['display_type'] = esc_html($new_instance['display_type']); $instance['max_events'] = absint($new_instance['max_events']); $instance['display_title'] = $new_instance['display_title'] == 'on' ? true : false; $instance['display_title_text'] = wp_filter_kses($new_instance['display_title_text']); return $instance; } function form($instance){ //Get saved feed options $options = get_option(GCE_OPTIONS_NAME); if(empty($options)){ //If no feeds or groups ?>


value="on" />

get_errors()) == 0){ //Add AJAX script if required if($ajaxified) ?>get_grid($year, $month, $ajaxified); }else{ printf(__('The following feeds were not parsed successfully: %s. Please check that the feed URLs are correct and that the feeds have public sharing enabled.'), implode(', ', $grid->get_errors())); } } function gce_widget_content_list($feed_ids, $title_text, $max_events, $grouped = false){ //Create new GCE_Parser object, passing array of feed id(s) $list = new GCE_Parser(explode('-', $feed_ids), $title_text, $max_events); //If the feed(s) parsed ok, output the list markup, otherwise output an error message if(count($list->get_errors()) == 0){ echo $list->get_list($grouped); }else{ printf(__('The following feeds were not parsed successfully: %s. Please check that the feed URLs are correct and that the feeds have public sharing enabled.'), implode(', ', $list->get_errors())); } } ?>