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;
    }
}
Exemplo n.º 2
0
function my_category_key($category)
{
    global $wpdb;
    $url = plugin_dir_url(__FILE__);
    $dir = plugin_dir_path(__FILE__);
    $mcdb = $wpdb;
    $category_key = '';
    if (get_option('mc_remote') == 'true' && function_exists('mc_remote_db')) {
        $mcdb = mc_remote_db();
    }
    $cat_details = '';
    $cat_limit = mc_select_category($category, 'all', 'category');
    $sql = "SELECT * FROM " . MY_CALENDAR_CATEGORIES_TABLE . " {$cat_limit} ORDER BY category_name ASC";
    $cat_details = $mcdb->get_results($sql);
    $category_key .= '<div class="category-key">
			<h3>' . __('Categories', 'my-calendar') . "</h3>\n<ul>\n";
    $subpath = is_custom_icon() ? 'my-calendar-custom/' : 'my-calendar/images/icons/';
    $path = str_replace(basename($dir) . '/', '', $url) . $subpath;
    foreach ($cat_details as $cat_detail) {
        $hex = strpos($cat_detail->category_color, '#') !== 0 ? '#' : '';
        $title_class = sanitize_title($cat_detail->category_name);
        if ($cat_detail->category_private == 1) {
            $title_class .= " private";
        }
        $url = add_query_arg('mcat', $cat_detail->category_id, mc_get_current_url());
        if ($cat_detail->category_icon != "" && get_option('mc_hide_icons') != 'true') {
            $category_key .= '<li class="cat_' . $title_class . '"><a href="' . $url . '"><span class="category-color-sample"><img src="' . $path . $cat_detail->category_icon . '" alt="" style="background:' . $hex . $cat_detail->category_color . ';" /></span>' . stripcslashes($cat_detail->category_name) . "</a></li>\n";
        } else {
            $category_key .= '<li class="cat_' . $title_class . '"><a href="' . $url . '"><span class="category-color-sample no-icon" style="background:' . $hex . $cat_detail->category_color . ';"> &nbsp; </span>' . stripcslashes($cat_detail->category_name) . "</a></li>\n";
        }
    }
    if (isset($_GET['mcat'])) {
        $category_key .= "<li><a href='" . mc_get_current_url() . "'>" . __('All Categories', 'my-calendar') . "</a></li>";
    }
    $category_key .= "</ul>\n</div>";
    $category_key = apply_filters('mc_category_key', $category_key, $cat_details);
    return $category_key;
}
function my_category_key($category)
{
    global $wpdb;
    $url = plugin_dir_url(__FILE__);
    $mcdb = $wpdb;
    if (get_option('mc_remote') == 'true' && function_exists('mc_remote_db')) {
        $mcdb = mc_remote_db();
    }
    $key = '';
    $cat_limit = mc_select_category($category, 'all', 'category');
    $sql = "SELECT * FROM " . my_calendar_categories_table() . " {$cat_limit} ORDER BY category_name ASC";
    $categories = $mcdb->get_results($sql);
    $key .= '<div class="category-key">
	<h3>' . __('Categories', 'my-calendar') . "</h3>\n<ul>\n";
    $path = is_custom_icon() ? str_replace('my-calendar', 'my-calendar-custom', $url) : plugins_url('images/icons', __FILE__) . '/';
    foreach ($categories as $cat) {
        $hex = strpos($cat->category_color, '#') !== 0 ? '#' : '';
        $class = sanitize_title($cat->category_name);
        if (isset($_GET['mcat']) && $_GET['mcat'] == $cat->category_id) {
            $class .= " current";
        }
        if ($cat->category_private == 1) {
            $class .= " private";
        }
        $url = mc_build_url(array('mcat' => $cat->category_id), array('mcat'));
        if ($cat->category_icon != "" && get_option('mc_hide_icons') != 'true') {
            $key .= '<li class="cat_' . $class . '"><a href="' . $url . '"><span class="category-color-sample"><img src="' . $path . $cat->category_icon . '" alt="" style="background:' . $hex . $cat->category_color . ';" /></span>' . mc_kses_post(stripcslashes($cat->category_name)) . "</a></li>\n";
        } else {
            $key .= '<li class="cat_' . $class . '"><a href="' . $url . '"><span class="category-color-sample no-icon" style="background:' . $hex . $cat->category_color . ';"> &nbsp; </span>' . mc_kses_post(stripcslashes($cat->category_name)) . "</a></li>\n";
        }
    }
    if (isset($_GET['mcat'])) {
        $key .= "<li class='all-categories'><a href='" . esc_url(remove_query_arg('mcat', mc_get_current_url())) . "'>" . apply_filters('mc_text_all_categories', __('All Categories', 'my-calendar')) . "</a></li>";
    }
    $key .= "</ul>\n</div>";
    $key = apply_filters('mc_category_key', $key, $categories);
    return $key;
}