/** * Adds support for the new [gcal] shortcode * * Supports the old [google-calendar-events] shortcode * * @since 2.0.0 */ function gce_gcal_shortcode($attr) { extract(shortcode_atts(array('id' => null, 'display' => '', 'max' => 0, 'order' => 'asc', 'title' => null, 'type' => null), $attr, 'gce_feed')); // If no ID is specified then return if (empty($id)) { return; } $feed_ids = explode(',', $id); foreach ($feed_ids as $k => $v) { // Check for an old ID attached to this feed ID first $q = new WP_Query("post_type=gce_feed&meta_key=old_gce_id&meta_value={$v}&order=ASC"); if ($q->have_posts()) { $q->the_post(); // Set our ID to the old ID if found $feed_ids[$k] = get_the_ID(); $v = get_the_ID(); } if (empty($display)) { $display = get_post_meta($v, 'gce_display_mode', true); } } // Port over old options if ($type != null) { if ('ajax' == $type) { $display = 'grid'; } else { $display = $type; } } $args = array('title_text' => $title, 'max_events' => $max, 'sort' => $order, 'grouped' => $display == 'list-grouped' ? 1 : 0, 'month' => null, 'year' => null, 'widget' => 0); $feed_ids = implode('-', $feed_ids); return gce_print_calendar($feed_ids, $display, $args); }
/** * Widget HTML output * * @since 2.0.0 */ function widget($args, $instance) { extract($args); //Output before widget stuff echo $before_widget; // Check whether any feeds have been added yet if (wp_count_posts('gce_feed')->publish > 0) { //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 (!empty($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 (false !== get_post_meta($feed_id)) { $no_feeds_exist = false; } } } else { 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'); } } //Check that at least one valid feed id has been entered if (!empty($feed_ids)) { //Turns feed_ids back into string or feed ids delimited by '-' ('1-2-3-4' for example) $feed_ids = implode('-', $feed_ids); $title_text = !empty($instance['display_title_text']) ? $instance['display_title_text'] : null; $max_events = isset($instance['max_events']) ? $instance['max_events'] : 0; $sort_order = isset($instance['order']) ? $instance['order'] : 'asc'; $args = array('title_text' => $title_text, 'max_events' => $max_events, 'sort' => $sort_order, 'month' => null, 'year' => null, 'widget' => 1); if ('list-grouped' == $instance['display_type']) { $args['grouped'] = 1; } $markup = gce_print_calendar($feed_ids, $instance['display_type'], $args, true); echo $markup; } } else { if (current_user_can('manage_options')) { _e('You have not added any feeds yet.', 'gce'); } else { return; } } //Output after widget stuff echo $after_widget; }
/** * AJAX function for grid pagination * * @since 2.0.0 */ 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; $args = array('title_text' => $title, 'max_events' => $max, 'month' => $month, 'year' => $year); if ('page' == $_GET['gce_type']) { echo gce_print_calendar($ids, 'grid', $args); } elseif ('widget' == $_GET['gce_type']) { $args['widget'] = 1; echo gce_print_calendar($ids, 'grid', $args); } } die; }
/** * Widget HTML output * * @since 2.0.0 */ function widget($args, $instance) { extract($args); //Output before widget stuff echo $before_widget; $paging = isset($instance['paging']) ? $instance['paging'] : null; $max_num = isset($instance['per_page_num']) ? $instance['per_page_num'] : null; $max_length = isset($instance['events_per_page']) ? $instance['events_per_page'] : null; $max_events = null; $display_type = isset($instance['display_type']) ? $instance['display_type'] : null; // Start offset $offset_num = isset($instance['list_start_offset_num']) ? $instance['list_start_offset_num'] : 0; $offset_length = 86400; $offset_direction = isset($instance['list_start_offset_direction']) ? $instance['list_start_offset_direction'] : null; $invalid_id = false; // Get custom date range if set if ('date-range-list' == $display_type || 'date-range-grid' == $display_type) { $range_start = isset($instance['feed_range_start']) ? $instance['feed_range_start'] : null; $range_end = isset($instance['feed_range_end']) ? $instance['feed_range_end'] : null; if ($range_start !== null && !empty($range_start)) { $range_start = gce_date_unix($range_start); } if ($range_end !== null && !empty($range_end)) { $range_end = gce_date_unix($range_end); } } if (!isset($instance['show_tooltips'])) { $show_tooltips = 1; } else { $show_tooltips = isset($instance['show_tooltips']) ? $instance['show_tooltips'] : 'false'; } if ($offset_direction == 'back') { $offset_direction = -1; } else { $offset_direction = 1; } $start_offset = $offset_num * $offset_length * $offset_direction; $paging_interval = null; if ($display_type == 'date-range-list' || $display_type == 'date-range-grid') { $max_length = 'date-range'; } if ($max_length == 'days') { $paging_interval = $max_num * 86400; } else { if ($max_length == 'events') { $max_events = $max_num; } else { if ($max_length == 'week') { $paging_interval = 604800; } else { if ($max_length == 'month') { $paging_interval = 2629743; } } } } // Check whether any feeds have been added yet if (wp_count_posts('gce_feed')->publish > 0) { //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 (!empty($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 (!('publish' == get_post_status($feed_id))) { $invalid_id = true; } } //If at least one of the feed ids entered exists, set no_feeds_exist to false foreach ($feed_ids as $feed_id) { if (false !== get_post_meta($feed_id)) { $no_feeds_exist = false; } } foreach ($feed_ids as $feed_id) { if ($paging) { update_post_meta($feed_id, 'gce_paging_widget', true); } else { delete_post_meta($feed_id, 'gce_paging_widget'); } update_post_meta($feed_id, 'gce_widget_paging_interval', $paging_interval); } } else { 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'); } } //Check that at least one valid feed id has been entered if (!empty($feed_ids)) { //Turns feed_ids back into string or feed ids delimited by '-' ('1-2-3-4' for example) $feed_ids = implode('-', $feed_ids); $title_text = !empty($instance['display_title_text']) ? $instance['display_title_text'] : null; $sort_order = isset($instance['order']) ? $instance['order'] : 'asc'; $args = array('title_text' => $title_text, 'sort' => $sort_order, 'month' => null, 'year' => null, 'widget' => 1, 'max_events' => $max_events, 'start_offset' => $start_offset, 'paging_type' => $max_length, 'max_num' => $max_num, 'show_tooltips' => $show_tooltips); if ('list-grouped' == $display_type) { $args['grouped'] = 1; } if ('date-range-list' == $display_type) { $args['max_events'] = INF; $args['max_num'] = INF; } $markup = gce_print_calendar($feed_ids, $display_type, $args, true); if (!$invalid_id) { echo $markup; } else { if (current_user_can('manage_options')) { echo '<p>' . __('There was a problem with one or more of your feed IDs. Please check your widget settings and make sure they are correct.', 'gce') . '</p>'; } } } } else { if (current_user_can('manage_options')) { _e('You have not added any feeds yet.', 'gce'); } else { echo ''; } } //Output after widget stuff echo $after_widget; }
/** * AJAX function for grid pagination * * @since 2.0.0 */ function gce_ajax() { $uid = esc_html($_POST['gce_uid']); $ids = esc_html($_POST['gce_feed_ids']); $title = esc_html($_POST['gce_title_text']); $month = esc_html($_POST['gce_month']); $year = esc_html($_POST['gce_year']); $paging = esc_html($_POST['gce_paging']); $type = esc_html($_POST['gce_type']); // Split ID and pass as UID to function $uid = explode('-', $uid); $title = 'null' == $title ? null : $title; $args = array('title_text' => $title, 'month' => $month, 'year' => $year, 'paging' => $paging); if ('page' == $type) { echo gce_print_calendar($ids, 'grid', $args, 0, $uid[1]); } elseif ('widget' == $type) { $args['widget'] = 1; echo gce_print_calendar($ids, 'grid', $args, 1, $uid[1]); } die; }
/** * Adds support for the new [gcal] shortcode * * Supports the old [google-calendar-events] shortcode * * @since 2.0.0 * * @param array $attr * @return string */ function gce_gcal_shortcode($attr) { extract(shortcode_atts(array('id' => null, 'display' => '', 'order' => 'asc', 'title' => null, 'type' => null, 'paging' => null, 'interval' => null, 'interval_count' => null, 'offset_interval_count' => null, 'offset_direction' => null, 'show_tooltips' => null), $attr, 'gce_feed')); if (!$id || is_null($id)) { return ''; } $invalid_id = false; $paging_interval = null; $max_events = null; $feed_ids = explode(',', str_replace(' ', '', $id)); foreach ($feed_ids as $k => $v) { // Check for an old ID attached to this feed ID first $q = new WP_Query("post_type=gce_feed&meta_key=old_gce_id&meta_value={$v}&order=ASC"); if ($q->have_posts()) { $q->the_post(); // Set our ID to the old ID if found $feed_ids[$k] = get_the_ID(); $v = get_the_ID(); } wp_reset_postdata(); if (empty($display)) { $display = get_post_meta($v, 'gce_display_mode', true); } if ($interval == null) { $interval = get_post_meta($v, 'gce_events_per_page', true); } if ($interval_count == null) { $interval_count = get_post_meta($v, 'gce_per_page_num', true); } if ($offset_interval_count == null) { $offset_interval_count = get_post_meta($v, 'gce_list_start_offset_num', true); } if ($offset_direction == null) { $offset_direction = get_post_meta($v, 'gce_list_start_offset_direction', true); } if ($paging == null) { $paging = get_post_meta($v, 'gce_paging', true); } if ($show_tooltips == null) { $show_tooltips = get_post_meta($v, 'gce_show_tooltips', true); } if (!('publish' == get_post_status($v))) { $invalid_id = true; } } if ($invalid_id) { if (current_user_can('manage_options')) { return '<p>' . __('There was a problem with one or more of your feed IDs. Please check your shortcode settings and make sure they are correct.', 'gce') . '</p>'; } } if ($paging == 'false') { $paging = 0; } else { if ($paging == 'true') { $paging = 1; } } if ($offset_direction == 'back') { $offset_direction = -1; } else { $offset_direction = 1; } $start_offset = $offset_interval_count * 86400 * $offset_direction; if ($interval == 'days') { $paging_interval = $interval_count * 86400; $paging_type = 'days'; } else { if ($interval == 'events') { $max_events = $interval_count; $paging_type = 'events'; } else { if ($interval == 'week') { $paging_interval = 604800; } else { if ($interval == 'month') { $paging_interval = 2629743; } } } } // Port over old options if ($type != null) { if ('ajax' == $type) { $display = 'grid'; } else { $display = $type; } } if ($display == 'grouped-list') { $display = 'list-grouped'; } $args = array('title_text' => $title, 'sort' => $order, 'grouped' => $display == 'list-grouped' ? 1 : 0, 'month' => null, 'year' => null, 'widget' => 0, 'paging_interval' => $paging_interval, 'max_events' => $max_events, 'paging' => $paging, 'show_tooltips' => $show_tooltips); $args['start_offset'] = $start_offset; if (!empty($paging_type)) { $args['paging_type'] = $paging_type; } $feed_ids = implode('-', $feed_ids); return gce_print_calendar($feed_ids, $display, $args); }