Esempio n. 1
0
function mc_search_results($query)
{
    $limits = true;
    $before = apply_filters('mc_past_search_results', 0);
    $after = apply_filters('mc_future_search_results', 10);
    // return only future events, nearest 10
    if (is_string($query)) {
        $select_category = $limit_string = $select_author = $select_host = '';
        $search = " MATCH(event_title,event_desc,event_short,event_label,event_city,event_postcode,event_registration) AGAINST ('{$query}' IN BOOLEAN MODE) AND ";
    } else {
        extract($query);
        $select_category = $category != 'default' ? mc_select_category($category) : '';
        $limit_string = mc_limit_string();
        $select_author = $author != 'default' ? mc_select_author($author) : '';
        $select_host = $host != 'default' ? mc_select_host($host) : '';
        $prefix = $select_category . $limit_string . $select_author . $select_host != '' ? ' AND' : '';
        $search = "{$prefix} MATCH(event_title,event_desc,event_short,event_label,event_city,event_postcode,event_registration) AGAINST ('{$query}' IN BOOLEAN MODE) AND ";
    }
    global $wpdb;
    $mcdb = $wpdb;
    if (get_option('mc_remote') == 'true' && function_exists('mc_remote_db')) {
        $mcdb = mc_remote_db();
    }
    $date = date('Y', current_time('timestamp')) . '-' . date('m', current_time('timestamp')) . '-' . date('d', current_time('timestamp'));
    // if a value is non-zero, I'll grab a handful of extra events so I can throw out holidays and others like that.
    if ($before > 0) {
        $before = $before + 5;
        $events1 = $mcdb->get_results("SELECT *, UNIX_TIMESTAMP(occur_begin) AS ts_occur_begin, UNIX_TIMESTAMP(occur_end) AS ts_occur_end \n\t\tFROM " . MY_CALENDAR_EVENTS_TABLE . " \n\t\tJOIN " . MY_CALENDAR_TABLE . " \n\t\tON (event_id=occur_event_id) \n\t\tJOIN " . MY_CALENDAR_CATEGORIES_TABLE . " \n\t\tON (event_category=category_id) WHERE {$select_category} {$select_author} {$select_host} {$limit_string} {$search} event_approved = 1 AND event_flagged <> 1 \n\t\tAND DATE(occur_begin) < '{$date}' ORDER BY occur_begin DESC LIMIT 0,{$before}");
    } else {
        $events1 = array();
    }
    $events3 = $mcdb->get_results("SELECT *, UNIX_TIMESTAMP(occur_begin) AS ts_occur_begin, UNIX_TIMESTAMP(occur_end) AS ts_occur_end \n\t\tFROM " . MY_CALENDAR_EVENTS_TABLE . " \n\t\tJOIN " . MY_CALENDAR_TABLE . " \n\t\tON (event_id=occur_event_id) \n\t\tJOIN " . MY_CALENDAR_CATEGORIES_TABLE . " \n\t\tON (event_category=category_id) WHERE {$select_category} {$select_author} {$select_host} {$limit_string} {$search} event_approved = 1 AND event_flagged <> 1 \n\t\tAND DATE(occur_begin) = '{$date}'");
    if ($after > 0) {
        $after = $after + 5;
        $events2 = $mcdb->get_results("SELECT *, UNIX_TIMESTAMP(occur_begin) AS ts_occur_begin, UNIX_TIMESTAMP(occur_end) AS ts_occur_end \n\t\tFROM " . MY_CALENDAR_EVENTS_TABLE . " \n\t\tJOIN " . MY_CALENDAR_TABLE . " \n\t\tON (event_id=occur_event_id) \n\t\tJOIN " . MY_CALENDAR_CATEGORIES_TABLE . " \n\t\tON (event_category=category_id) WHERE {$select_category} {$select_author} {$select_host} {$limit_string} {$search} event_approved = 1 AND event_flagged <> 1 \n\t\tAND DATE(occur_begin) > '{$date}' ORDER BY occur_begin ASC LIMIT 0,{$after}");
    } else {
        $events2 = array();
    }
    $arr_events = array();
    if (!empty($events1) || !empty($events2) || !empty($events3)) {
        $arr_events = array_merge($events1, $events3, $events2);
    }
    if (!get_option('mc_skip_holidays_category') || get_option('mc_skip_holidays_category') == '') {
        $holidays = array();
    } else {
        $holidays = mc_get_all_holidays($before, $after, 'yes');
        $holiday_array = mc_set_date_array($holidays);
    }
    if (is_array($arr_events) && !empty($arr_events)) {
        $no_events = false;
        $event_array = mc_set_date_array($arr_events);
        if (is_array($holidays) && count($holidays) > 0) {
            $event_array = mc_holiday_limit($event_array, $holiday_array);
            // if there are holidays, rejigger.
        }
    }
    if (!empty($event_array)) {
        $template = '<strong>{date}</strong> {title} {details}';
        $template = apply_filters('mc_search_template', $template);
        // no filters parameter prevents infinite looping on the_content filters.
        $output = mc_produce_upcoming_events($event_array, $template, 'list', 'ASC', 0, $before, $after, 'yes', 'nofilters');
    } else {
        $output = "<li class='no-results'>" . __('Sorry, your search produced no results.', 'my-calendar') . "</li>";
    }
    return "<ol class='mc-search-results'>{$output}</ol>";
}
function my_calendar_grab_events($from, $to, $category = null, $ltype = '', $lvalue = '', $source = 'calendar', $author = null, $host = null, $holidays = null, $search = '')
{
    global $wpdb;
    $mcdb = $wpdb;
    if (get_option('mc_remote') == 'true' && function_exists('mc_remote_db')) {
        $mcdb = mc_remote_db();
    }
    if ($holidays === null) {
        if (isset($_GET['mcat'])) {
            $ccategory = $_GET['mcat'];
        } else {
            $ccategory = $category;
        }
    } else {
        $ccategory = $category;
    }
    if (isset($_GET['ltype'])) {
        $cltype = $_GET['ltype'];
    } else {
        $cltype = $ltype;
    }
    if (isset($_GET['loc'])) {
        $clvalue = $_GET['loc'];
    } else {
        $clvalue = $lvalue;
    }
    if (isset($_GET['mc_auth'])) {
        $clauth = $_GET['mc_auth'];
    } else {
        $clauth = $author;
    }
    if (isset($_GET['mc_host'])) {
        $clhost = $_GET['mc_host'];
    } else {
        $clhost = $host;
    }
    if ($ccategory == '') {
        $ccategory = 'all';
    }
    if ($clvalue == '') {
        $clvalue = 'all';
    }
    if ($cltype == '') {
        $cltype = 'all';
    }
    if ($clvalue == 'all') {
        $cltype = 'all';
    }
    if ($clauth == '') {
        $clauth = 'all';
    }
    if ($clhost == '') {
        $clhost = 'all';
    }
    if (!mc_checkdate($from) || !mc_checkdate($to)) {
        return array();
    }
    // not valid dates
    $caching = apply_filters('mc_caching_enabled', false, $ccategory, $ltype, $lvalue, $author, $host);
    $hash = md5($from . $to . $ccategory . $cltype . $clvalue . $clauth . $clhost);
    if ($source != 'upcoming') {
        // no caching on upcoming events by days widgets or lists
        if ($caching) {
            $output = mc_check_cache($ccategory, $cltype, $clvalue, $clauth, $clhost, $hash);
            if ($output && $output != 'empty') {
                return $output;
            }
            if ($output == 'empty') {
                return array();
            }
        }
    }
    $select_category = $ccategory != 'all' ? mc_select_category($ccategory) : '';
    $select_author = $clauth != 'all' ? mc_select_author($clauth) : '';
    $select_host = $clhost != 'all' ? mc_select_host($clhost) : '';
    $select_location = mc_limit_string('grab', $cltype, $clvalue);
    if ($caching && $source != 'upcoming') {
        $select_category = '';
        $select_location = '';
        $select_author = '';
        $select_host = '';
    }
    // if caching, then need all categories/locations in cache. UNLESS this is an upcoming events list
    $arr_events = array();
    $limit_string = "event_flagged <> 1 AND event_approved = 1";
    $search = mc_prepare_search_query($search);
    $event_query = "SELECT *, UNIX_TIMESTAMP(occur_begin) AS ts_occur_begin, UNIX_TIMESTAMP(occur_end) AS ts_occur_end\n\t\t\t\t\tFROM " . MY_CALENDAR_EVENTS_TABLE . " \n\t\t\t\t\tJOIN " . MY_CALENDAR_TABLE . "\n\t\t\t\t\tON (event_id=occur_event_id) \t\t\t\t\t\n\t\t\t\t\tJOIN " . MY_CALENDAR_CATEGORIES_TABLE . " \n\t\t\t\t\tON (event_category=category_id) \n\t\t\t\t\tWHERE {$select_category} {$select_location} {$select_author} {$select_host} {$limit_string} {$search} \n\t\t\t\t\tAND ( DATE(occur_begin) BETWEEN '{$from} 00:00:00' AND '{$to} 23:59:59' \n\t\t\t\t\t\tOR DATE(occur_end) BETWEEN '{$from} 00:00:00' AND '{$to} 23:59:59' \n\t\t\t\t\t\tOR ( DATE('{$from}') BETWEEN DATE(occur_begin) AND DATE(occur_end) ) \n\t\t\t\t\t\tOR ( DATE('{$to}') BETWEEN DATE(occur_begin) AND DATE(occur_end) ) ) \n\t\t\t\t\tORDER BY " . apply_filters('mc_primary_sort', 'occur_begin') . ", " . apply_filters('mc_secondary_sort', 'event_title ASC');
    $events = $mcdb->get_results($event_query);
    if (!empty($events)) {
        foreach (array_keys($events) as $key) {
            $event =& $events[$key];
            $arr_events[] = $event;
        }
    }
    if ($source != 'upcoming' && $caching) {
        $new_cache = mc_create_cache($arr_events, $hash, $category, $ltype, $lvalue, $author, $host);
        if ($new_cache) {
            $output = mc_check_cache($ccategory, $cltype, $clvalue, $clauth, $clhost, $hash);
            return $output;
        } else {
            // need to clean cache if the cache is maxed.
            return mc_clean_cache($arr_events, $ccategory, $cltype, $clvalue, $clauth, $clhost);
        }
    } else {
        return $arr_events;
    }
}