示例#1
0
/**
 * Replaces the normal WPFC ajax and uses the EM query system to provide event specific results. 
 */
function wpfc_em_ajax()
{
    $_REQUEST['month'] = false;
    //no need for these two, they are the original month and year requested
    $_REQUEST['year'] = false;
    //get the year and month to show, which would be the month/year between start and end request params
    $month_diff = $_REQUEST['end'] - $_REQUEST['start'];
    $month_ts = $_REQUEST['start'] + $month_diff / 2;
    //get a 'mid-month' timestamp to get year and month
    $year = (int) date("Y", $month_ts);
    $month = (int) date("m", $month_ts);
    $args = array('month' => $month, 'year' => $year, 'owner' => false, 'status' => 1, 'orderby' => 'event_start_date, event_start_time');
    $args['number_of_weeks'] = 6;
    //WPFC always has 6 weeks
    $limit = $args['limit'] = get_option('wpfc_limit', 3);
    //do some corrections for EM query
    if (isset($_REQUEST[EM_TAXONOMY_CATEGORY]) || empty($_REQUEST['category'])) {
        $_REQUEST['category'] = !empty($_REQUEST[EM_TAXONOMY_CATEGORY]) ? $_REQUEST[EM_TAXONOMY_CATEGORY] : false;
    }
    $_REQUEST['tag'] = !empty($_REQUEST[EM_TAXONOMY_TAG]) ? $_REQUEST[EM_TAXONOMY_TAG] : false;
    $args = apply_filters('wpfc_fullcalendar_args', array_merge($_REQUEST, $args));
    $calendar_array = EM_Calendar::get($args);
    $parentArray = $events = $event_ids = $event_date_counts = $event_dates_more = $event_day_counts = array();
    //get day link template
    global $wp_rewrite;
    if (get_option("dbem_events_page") > 0) {
        $event_page_link = get_permalink(get_option("dbem_events_page"));
        //PAGE URI OF EM
        if ($wp_rewrite->using_permalinks()) {
            $event_page_link = trailingslashit($event_page_link);
        }
    } else {
        if ($wp_rewrite->using_permalinks()) {
            $event_page_link = trailingslashit(home_url()) . EM_POST_TYPE_EVENT_SLUG . '/';
            //don't use EM_URI here, since ajax calls this before EM_URI is defined.
        } else {
            $event_page_link = home_url() . '?post_type=' . EM_POST_TYPE_EVENT;
            //don't use EM_URI here, since ajax calls this before EM_URI is defined.
        }
    }
    if ($wp_rewrite->using_permalinks() && !defined('EM_DISABLE_PERMALINKS')) {
        $event_page_link .= "%s/";
    } else {
        $joiner = stristr($event_page_link, "?") ? "&" : "?";
        $event_page_link .= $joiner . "calendar_day=%s";
    }
    foreach ($calendar_array['cells'] as $date => $cell_data) {
        if (empty($event_day_counts[$date])) {
            $event_day_counts[$date] = 0;
        }
        /* @var $EM_Event EM_Event */
        $orig_color = get_option('dbem_category_default_color');
        foreach ($cell_data['events'] as $EM_Event) {
            $color = $borderColor = $orig_color;
            $textColor = '#fff';
            if (!empty($EM_Event->get_categories()->categories)) {
                foreach ($EM_Event->get_categories()->categories as $EM_Category) {
                    /* @var $EM_Category EM_Category */
                    if ($EM_Category->get_color() != '') {
                        $color = $borderColor = $EM_Category->get_color();
                        if (preg_match("/#fff(fff)?/i", $color)) {
                            $textColor = '#777';
                            $borderColor = '#ccc';
                        }
                        break;
                    }
                }
            }
            if (!in_array($EM_Event->event_id, $event_ids)) {
                //count events for all days this event may span
                if ($EM_Event->event_start_date != $EM_Event->event_end_date) {
                    for ($i = $EM_Event->start; $i <= $EM_Event->end; $i = $i + 86400) {
                        $idate = date('Y-m-d', $i);
                        empty($event_day_counts[$idate]) ? $event_day_counts[$idate] = 1 : $event_day_counts[$idate]++;
                    }
                } else {
                    $event_day_counts[$date]++;
                }
                if ($event_day_counts[$date] <= $limit) {
                    $title = $EM_Event->output(get_option('dbem_emfc_full_calendar_event_format', '#_EVENTNAME'), 'raw');
                    $event_array = array("title" => $title, "color" => $color, 'textColor' => $textColor, 'borderColor' => $borderColor, "start" => date('Y-m-d\\TH:i:s', $EM_Event->start), "end" => date('Y-m-d\\TH:i:s', $EM_Event->end), "url" => $EM_Event->get_permalink(), 'post_id' => $EM_Event->post_id, 'event_id' => $EM_Event->event_id, 'allDay' => $EM_Event->event_all_day == true);
                    $events[] = apply_filters('wpfc_events_event', $event_array, $EM_Event);
                    $event_ids[] = $EM_Event->event_id;
                }
            }
        }
        if ($cell_data['events_count'] > $limit) {
            $event_dates_more[$date] = 1;
            $day_ending = $date . "T23:59:59";
            $events[] = apply_filters('wpfc_events_more', array("title" => get_option('wpfc_limit_txt', 'more ...'), "color" => get_option('wpfc_limit_color', '#fbbe30'), "start" => $day_ending, "url" => str_replace('%s', $date, $event_page_link), 'post_id' => 0, 'event_id' => 0, 'allDay' => true), $date);
        }
    }
    echo EM_Object::json_encode(apply_filters('wpfc_events', $events));
    die;
}
示例#2
0
/**
 * Replaces the normal WPFC ajax and uses the EM query system to provide event specific results. 
 */
function wpfc_em_ajax()
{
    $_REQUEST['month'] = false;
    //no need for these two, they are the original month and year requested
    $_REQUEST['year'] = false;
    //get the month/year between the start/end dates and feed these to EM
    $scope_start = strtotime(substr($_REQUEST['start'], 0, 10));
    $scope_end = strtotime(substr($_REQUEST['end'], 0, 10));
    $scope_middle = $scope_start + ($scope_end - $scope_start) / 2;
    $month = date('n', $scope_middle);
    $year = date('Y', $scope_middle);
    $args = array('month' => $month, 'year' => $year, 'owner' => false, 'status' => 1, 'orderby' => 'event_start_time, event_name');
    //since wpfc handles date sorting we only care about time and name ordering here
    $args['number_of_weeks'] = 6;
    //WPFC always has 6 weeks
    $limit = $args['limit'] = get_option('wpfc_limit', 3);
    $args['long_events'] = isset($_REQUEST['long_events']) && $_REQUEST['long_events'] == 0 ? 0 : 1;
    //long events are enabled, unless explicitly told not to in the shortcode
    //do some corrections for EM query
    if (isset($_REQUEST[EM_TAXONOMY_CATEGORY]) || empty($_REQUEST['category'])) {
        $_REQUEST['category'] = !empty($_REQUEST[EM_TAXONOMY_CATEGORY]) ? $_REQUEST[EM_TAXONOMY_CATEGORY] : false;
    }
    $_REQUEST['tag'] = !empty($_REQUEST[EM_TAXONOMY_TAG]) ? $_REQUEST[EM_TAXONOMY_TAG] : false;
    $args = apply_filters('wpfc_fullcalendar_args', array_merge($_REQUEST, $args));
    $calendar_array = EM_Calendar::get($args);
    $parentArray = $events = $event_ids = $event_date_counts = $event_dates_more = $event_day_counts = array();
    //get day link template
    global $wp_rewrite;
    if (get_option("dbem_events_page") > 0) {
        $event_page_link = get_permalink(get_option("dbem_events_page"));
        //PAGE URI OF EM
        if ($wp_rewrite->using_permalinks()) {
            $event_page_link = trailingslashit($event_page_link);
        }
    } else {
        if ($wp_rewrite->using_permalinks()) {
            $event_page_link = trailingslashit(home_url()) . EM_POST_TYPE_EVENT_SLUG . '/';
            //don't use EM_URI here, since ajax calls this before EM_URI is defined.
        } else {
            $event_page_link = home_url() . '?post_type=' . EM_POST_TYPE_EVENT;
            //don't use EM_URI here, since ajax calls this before EM_URI is defined.
        }
    }
    if ($wp_rewrite->using_permalinks() && !defined('EM_DISABLE_PERMALINKS')) {
        $event_page_link .= "%s/";
    } else {
        $joiner = stristr($event_page_link, "?") ? "&" : "?";
        $event_page_link .= $joiner . "calendar_day=%s";
    }
    foreach ($calendar_array['cells'] as $date => $cell_data) {
        if (empty($event_day_counts[$date])) {
            $event_day_counts[$date] = 0;
        }
        /* @var $EM_Event EM_Event */
        $orig_color = get_option('dbem_category_default_color');
        foreach ($cell_data['events'] as $EM_Event) {
            $color = $borderColor = $orig_color;
            $textColor = '#fff';
            if (get_option('dbem_categories_enabled') && !empty($EM_Event->get_categories()->categories)) {
                foreach ($EM_Event->get_categories()->categories as $EM_Category) {
                    /* @var $EM_Category EM_Category */
                    if ($EM_Category->get_color() != '') {
                        $color = $borderColor = $EM_Category->get_color();
                        if (preg_match("/#fff(fff)?/i", $color)) {
                            $textColor = '#777';
                            $borderColor = '#ccc';
                        }
                        break;
                    }
                }
            }
            if (!in_array($EM_Event->event_id, $event_ids)) {
                //count events for all days this event may span
                if ($EM_Event->event_start_date != $EM_Event->event_end_date) {
                    for ($i = $EM_Event->start; $i <= $EM_Event->end; $i = $i + 86400) {
                        $idate = date('Y-m-d', $i);
                        empty($event_day_counts[$idate]) ? $event_day_counts[$idate] = 1 : $event_day_counts[$idate]++;
                    }
                } else {
                    $event_day_counts[$date]++;
                }
                if ($event_day_counts[$date] <= $limit) {
                    $title = $EM_Event->output(get_option('dbem_emfc_full_calendar_event_format', '#_EVENTNAME'), 'raw');
                    $allDay = $EM_Event->event_all_day == true;
                    if ($allDay) {
                        $start_date = date('Y-m-d\\TH:i:s', $EM_Event->start);
                        $end_date = date('Y-m-d\\T00:00:00', $EM_Event->end + 60 * 60 * 24);
                        //on all day events the end date/time is next day of end date at 00:00:00 - see end attribute on http://fullcalendar.io/docs/event_data/Event_Object/
                    } else {
                        $start_date = date('Y-m-d\\TH:i:s', $EM_Event->start);
                        $end_date = date('Y-m-d\\TH:i:s', $EM_Event->end);
                    }
                    $event_array = array("title" => $title, "color" => $color, 'textColor' => $textColor, 'borderColor' => $borderColor, "start" => $start_date, "end" => $end_date, "url" => $EM_Event->get_permalink(), 'post_id' => $EM_Event->post_id, 'event_id' => $EM_Event->event_id, 'allDay' => $allDay);
                    if ($args['long_events'] == 0) {
                        $event_array['end'] = $event_array['start'];
                    }
                    //if long events aren't wanted, make the end date same as start so it shows this way on the calendar
                    $events[] = apply_filters('wpfc_events_event', $event_array, $EM_Event);
                    $event_ids[] = $EM_Event->event_id;
                }
            }
        }
        if ($cell_data['events_count'] > $limit) {
            $event_dates_more[$date] = 1;
            $day_ending = $date . "T23:59:59";
            $events[] = apply_filters('wpfc_events_more', array("title" => get_option('wpfc_limit_txt', 'more ...'), "color" => get_option('wpfc_limit_color', '#fbbe30'), "start" => $day_ending, "url" => str_replace('%s', $date, $event_page_link), 'post_id' => 0, 'event_id' => 0, 'className' => 'wpfc-more'), $date);
        }
    }
    echo EM_Object::json_encode(apply_filters('wpfc_events', $events));
    die;
}
示例#3
0
/**
 * Replaces the normal WPFC ajax and uses the EM query system to provide event specific results. 
 */
function wpfc_em_ajax()
{
    $_REQUEST['month'] = false;
    //no need for these two
    $_REQUEST['year'] = false;
    $year = date("Y", $_REQUEST['start']);
    $temp = date("Y-m-d", $_REQUEST['start']);
    $tomorrow = mktime(0, 0, 0, date("m", strtotime($temp)) + 1, date("d", strtotime($temp)), date("Y", strtotime($temp)));
    $month = date("m", $tomorrow);
    $args = array('month' => $month, 'year' => $year, 'owner' => false, 'status' => 1, 'orderby' => 'event_start_date, event_start_time');
    $args['long_events'] = 0;
    //since fullcalendar takes the start-end dates for long events, we don't need long events
    $limit = $args['limit'] = get_option('wpfc_limit', 3);
    //do some corrections for EM query
    if (isset($_REQUEST[EM_TAXONOMY_CATEGORY]) || empty($_REQUEST['category'])) {
        $_REQUEST['category'] = !empty($_REQUEST[EM_TAXONOMY_CATEGORY]) ? $_REQUEST[EM_TAXONOMY_CATEGORY] : false;
    }
    $_REQUEST['tag'] = !empty($_REQUEST[EM_TAXONOMY_TAG]) ? $_REQUEST[EM_TAXONOMY_TAG] : false;
    $args = apply_filters('wpfc_fullcalendar_args', array_merge($_REQUEST, $args));
    $EM_Events = EM_Events::get($args);
    $calendar_array = EM_Calendar::get($args);
    $parentArray = array();
    $events = array();
    $event_date_counts = array();
    $event_dates_more = array();
    //get day link template
    global $wp_rewrite;
    if (get_option("dbem_events_page") > 0) {
        $event_page_link = get_permalink(get_option("dbem_events_page"));
        //PAGE URI OF EM
        if ($wp_rewrite->using_permalinks()) {
            $event_page_link = trailingslashit($event_page_link);
        }
    } else {
        if ($wp_rewrite->using_permalinks()) {
            $event_page_link = trailingslashit(home_url()) . EM_POST_TYPE_EVENT_SLUG . '/';
            //don't use EM_URI here, since ajax calls this before EM_URI is defined.
        } else {
            $event_page_link = home_url() . '?post_type=' . EM_POST_TYPE_EVENT;
            //don't use EM_URI here, since ajax calls this before EM_URI is defined.
        }
    }
    if ($wp_rewrite->using_permalinks() && !defined('EM_DISABLE_PERMALINKS')) {
        $event_page_link .= "%s/";
    } else {
        $joiner = stristr($event_page_link, "?") ? "&" : "?";
        $event_page_link .= $joiner . "calendar_day=%s";
    }
    $event_day_counts = array();
    foreach ($calendar_array['cells'] as $date => $cell_data) {
        if (empty($event_day_counts[$date])) {
            $event_day_counts[$date] = 0;
        }
        /* @var $EM_Event EM_Event */
        $color = "#a8d144";
        $textColor = '#fff';
        $borderColor = '#a8d144';
        foreach ($cell_data['events'] as $EM_Event) {
            if (!empty($EM_Event->get_categories()->categories)) {
                foreach ($EM_Event->get_categories()->categories as $EM_Category) {
                    /* @var $EM_Category EM_Category */
                    if ($EM_Category->get_color() != '') {
                        $color = $borderColor = $EM_Category->get_color();
                        if (preg_match("/#fff(fff)?/i", $color)) {
                            $textColor = '#777';
                            $borderColor = '#ccc';
                        }
                        break;
                    }
                }
            }
            //count events for all days this event may span
            if ($EM_Event->event_start_date != $EM_Event->event_end_date) {
                for ($i = $EM_Event->start; $i <= $EM_Event->end; $i = $i + 86400) {
                    $idate = date('Y-m-d', $i);
                    empty($event_day_counts[$idate]) ? $event_day_counts[$idate] = 1 : $event_day_counts[$idate]++;
                }
            } else {
                $event_day_counts[$date]++;
            }
            if ($event_day_counts[$date] <= $limit) {
                $title = $EM_Event->output(get_option('dbem_emfc_full_calendar_event_format', '#_EVENTNAME'), 'raw');
                $event_array = array("title" => $title, "color" => $color, 'textColor' => $textColor, 'borderColor' => $borderColor, "start" => date('Y-m-d\\TH:i:s', $EM_Event->start), "end" => date('Y-m-d\\TH:i:s', $EM_Event->end), "url" => $EM_Event->get_permalink(), 'post_id' => $EM_Event->post_id, 'event_id' => $EM_Event->event_id, 'allDay' => $EM_Event->event_all_day == true);
                $events[] = apply_filters('wpfc_events_event', $event_array, $EM_Event);
            }
        }
        if ($cell_data['events_count'] > $limit) {
            $event_dates_more[$date] = 1;
            $day_ending = $date . "T23:59:59";
            $events[] = apply_filters('wpfc_events_more', array("title" => get_option('wpfc_limit_txt', 'more ...'), "color" => get_option('wpfc_limit_color', '#fbbe30'), "start" => $day_ending, "url" => str_replace('%s', $date, $event_page_link), 'post_id' => 0, 'event_id' => 0, 'allDay' => true), $date);
        }
    }
    echo EM_Object::json_encode(apply_filters('wpfc_events', $events));
    die;
}