function gce_ajax()
 {
     if (isset($_GET['gce_feed_ids'])) {
         $ids = $_GET['gce_feed_ids'];
         $title = $_GET['gce_title_text'];
         $max = $_GET['gce_max_events'];
         $month = $_GET['gce_month'];
         $year = $_GET['gce_year'];
         $title = 'null' == $title ? null : $title;
         if ('page' == $_GET['gce_type']) {
             //The page grid markup to be returned via AJAX
             echo gce_print_grid($ids, $title, $max, true, $month, $year);
         } elseif ('widget' == $_GET['gce_type']) {
             $widget = esc_html($_GET['gce_widget_id']);
             //The widget grid markup to be returned via AJAX
             gce_widget_content_grid($ids, $title, $max, $widget, true, $month, $year);
         }
     }
     die;
 }
Example #2
0
 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;
         }
         $no_feeds_exist = true;
         $feed_ids = array();
         if ('' != $instance['id']) {
             //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 (0 == absint($feed_id)) {
                     unset($feed_ids[$key]);
                 }
             }
             //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;
                 }
             }
         } else {
             foreach ($options as $feed) {
                 $feed_ids[] = $feed['id'];
             }
             $no_feeds_exist = false;
         }
         //Check that at least one valid feed id has been entered
         if (empty($feed_ids) || $no_feeds_exist) {
             if (current_user_can('manage_options')) {
                 _e('No valid Feed IDs have been entered for this widget. Please check that you have entered the IDs correctly in the widget settings (Appearance > Widgets), and that the Feeds have not been deleted.', GCE_TEXT_DOMAIN);
             } else {
                 $options = get_option(GCE_GENERAL_OPTIONS_NAME);
                 echo $options['error'];
             }
         } 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 = isset($instance['max_events']) ? $instance['max_events'] : 0;
             $sort_order = isset($instance['order']) ? $instance['order'] : 'asc';
             //Output correct widget content based on display type chosen
             switch ($instance['display_type']) {
                 case 'grid':
                     echo '<div class="gce-widget-grid" id="' . $args['widget_id'] . '-container">';
                     //Output main widget content as grid (no AJAX)
                     gce_widget_content_grid($feed_ids, $title_text, $max_events, $args['widget_id'] . '-container');
                     echo '</div>';
                     break;
                 case 'ajax':
                     echo '<div class="gce-widget-grid" id="' . $args['widget_id'] . '-container">';
                     //Output main widget content as grid (with AJAX)
                     gce_widget_content_grid($feed_ids, $title_text, $max_events, $args['widget_id'] . '-container', true);
                     echo '</div>';
                     break;
                 case 'list':
                     echo '<div class="gce-widget-list" id="' . $args['widget_id'] . '-container">';
                     //Output main widget content as list
                     gce_widget_content_list($feed_ids, $title_text, $max_events, $sort_order);
                     echo '</div>';
                     break;
                 case 'list-grouped':
                     echo '<div class="gce-widget-list" id="' . $args['widget_id'] . '-container">';
                     //Output main widget content as a grouped list
                     gce_widget_content_list($feed_ids, $title_text, $max_events, $sort_order, true);
                     echo '</div>';
                     break;
             }
         }
     } else {
         if (current_user_can('manage_options')) {
             _e('No feeds have been added yet. You can add a feed in the Google Calendar Events settings.', GCE_TEXT_DOMAIN);
         } else {
             $options = get_option(GCE_GENERAL_OPTIONS_NAME);
             echo $options['error'];
         }
     }
     //Output after widget stuff
     echo $after_widget;
 }