function mc_create_tags($event, $context = 'filters')
{
    $event = mc_clean_location($event, 'event');
    $e = array();
    $e['post'] = $event->event_post;
    $date_format = get_option('mc_date_format') != '' ? get_option('mc_date_format') : get_option('date_format');
    $e = apply_filters('mc_insert_author_data', $e, $event);
    $e = apply_filters('mc_filter_image_data', $e, $event);
    $map = mc_maplink($event);
    $map_url = mc_maplink($event, 'url');
    $sitelink_html = "<div class='url link'><a href='{$event->event_url}' class='location-link external'>" . sprintf(__('Visit web site<span class="screen-reader-text">: %s</span>', 'my-calendar'), $event->event_label) . "</a></div>";
    $e['sitelink_html'] = $sitelink_html;
    $e['sitelink'] = $event->event_url;
    $e['access'] = mc_expand(get_post_meta($event->event_post, '_mc_event_access', true));
    // date & time fields
    $real_end_date = $event->occur_end;
    $dtstart = mc_format_timestamp(strtotime($event->occur_begin));
    $dtend = mc_format_timestamp(strtotime($real_end_date));
    $e['date_utc'] = date_i18n(apply_filters('mc_date_format', $date_format, 'template_begin_ts'), $event->ts_occur_begin);
    $e['date_end_utc'] = date_i18n(apply_filters('mc_date_format', $date_format, 'template_end_ts'), $event->ts_occur_end);
    $notime = mc_notime_label($event);
    $e['time'] = date('H:i:s', strtotime($event->occur_begin)) == '00:00:00' ? $notime : date(get_option('mc_time_format'), strtotime($event->occur_begin));
    $e['time24'] = date('G:i', strtotime($event->occur_begin)) == '00:00:00' ? $notime : date(get_option('mc_time_format'), strtotime($event->occur_begin));
    $endtime = $event->event_end == '23:59:59' ? '00:00:00' : date('H:i:s', strtotime($real_end_date));
    $e['endtime'] = $real_end_date == $event->occur_begin || $event->event_hide_end == 1 || date('H:i:s', strtotime($real_end_date)) == '23:59:59' ? '' : date_i18n(get_option('mc_time_format'), strtotime($endtime));
    $e['runtime'] = mc_runtime($event->ts_occur_begin, $event->ts_occur_end, $event);
    $e['dtstart'] = date('Y-m-d\\TH:i:s', strtotime($event->occur_begin));
    // hcal formatted
    $e['dtend'] = date('Y-m-d\\TH:i:s', strtotime($real_end_date));
    //hcal formatted end
    $e['rssdate'] = date('D, d M Y H:i:s +0000', strtotime($event->event_added));
    $date = date_i18n(apply_filters('mc_date_format', $date_format, 'template_begin'), strtotime($event->occur_begin));
    $date_end = date_i18n(apply_filters('mc_date_format', $date_format, 'template_end'), strtotime($real_end_date));
    $date_arr = array('occur_begin' => $event->occur_begin, 'occur_end' => $real_end_date);
    $date_obj = (object) $date_arr;
    if ($event->event_span == 1) {
        $dates = mc_event_date_span($event->event_group_id, $event->event_span, array(0 => $date_obj));
    } else {
        $dates = array();
    }
    $e['date'] = $event->event_span != 1 ? $date : mc_format_date_span($dates, 'simple', $date);
    $e['enddate'] = $date_end;
    $e['daterange'] = $date == $date_end ? $date : "<span class='mc_db'>{$date}</span> <span>&ndash;</span> <span class='mc_de'>{$date_end}</span>";
    $e['timerange'] = $e['time'] == $e['endtime'] || $event->event_hide_end == 1 || date('H:i:s', strtotime($real_end_date)) == '23:59:59' ? $e['time'] : "<span class='mc_tb'>" . $e['time'] . "</span> <span>&ndash;</span> <span class='mc_te'>" . $e['endtime'] . "</span>";
    $e['datespan'] = $event->event_span == 1 || $e['date'] != $e['enddate'] ? mc_format_date_span($dates) : $date;
    $e['multidate'] = mc_format_date_span($dates, 'complex', "<span class='fallback-date'>{$date}</span><span class='separator'>,</span> <span class='fallback-time'>{$e['time']}</span>&ndash;<span class='fallback-endtime'>{$e['endtime']}</span>");
    $e['began'] = $event->event_begin;
    // returns date of first occurrence of an event.
    $e['recurs'] = mc_event_recur_string($event);
    $e['repeats'] = $event->event_repeats;
    // category fields
    $e['cat_id'] = $event->event_category;
    $e['category'] = stripslashes($event->category_name);
    $e['icon'] = mc_category_icon($event, 'img');
    $e['icon_html'] = "<img src='{$e['icon']}' class='mc-category-icon' alt='" . __('Category', 'my-calendar') . ": " . esc_attr($event->category_name) . "' />";
    $e['color'] = $event->category_color;
    $e['color_css'] = "<span style='background-color: {$event->category_color}'>";
    // this is because widgets now strip out style attributes.
    $e['close_color_css'] = "</span>";
    // special
    $e['skip_holiday'] = $event->event_holiday == 0 ? 'false' : 'true';
    $e['event_status'] = $event->event_approved == 1 ? __('Published', 'my-calendar') : __('Reserved', 'my-calendar');
    // general text fields
    $e['title'] = stripslashes($event->event_title);
    $e['description'] = wpautop(stripslashes($event->event_desc));
    $e['description_raw'] = stripslashes($event->event_desc);
    $e['description_stripped'] = strip_tags(stripslashes($event->event_desc));
    $e['shortdesc'] = wpautop(stripslashes($event->event_short));
    $e['shortdesc_raw'] = stripslashes($event->event_short);
    $e['shortdesc_stripped'] = strip_tags(stripslashes($event->event_short));
    // registration fields
    $e['event_open'] = mc_event_open($event);
    $e['event_tickets'] = $event->event_tickets;
    $e['event_registration'] = stripslashes(wp_kses_data($event->event_registration));
    // links
    $templates = get_option('mc_templates');
    $e_template = !empty($templates['label']) ? stripcslashes($templates['label']) : __('Details about', 'my-calendar') . ' {title}';
    $tags = array("{title}", "{location}", "{color}", "{icon}", "{date}", "{time}");
    $replacements = array(stripslashes($event->event_title), stripslashes($event->event_label), $event->category_color, $event->category_icon, $e['date'], $e['time']);
    $e_label = str_replace($tags, $replacements, $e_template);
    //$e_label = mc_get_details_label( $event, $e ); // recursive...hmmmm.
    $e_link = mc_get_details_link($event);
    $e['link'] = mc_event_link($event);
    if ($e['link']) {
        $e['link_image'] = str_replace("alt=''", "alt='" . esc_attr($e['title']) . "'", "<a href='" . $e['link'] . "'>" . $e['image'] . "</a>");
        $e['link_title'] = "<a href='" . $event->event_link . "'>" . $e['title'] . "</a>";
    } else {
        $e['link_image'] = $e['image'];
        $e['link_title'] = $e['title'];
    }
    $e['details_link'] = get_option('mc_uri') != '' && !is_numeric(get_option('mc_uri')) ? $e_link : '';
    $e['details'] = get_option('mc_uri') != '' && !is_numeric(get_option('mc_uri')) ? "<a href='{$e_link}' class='mc-details'>{$e_label}</a>" : '';
    $e['linking'] = $e['link'] != '' ? $event->event_link : $e_link;
    $e['linking_title'] = $e['linking'] != '' ? "<a href='" . $e['linking'] . "'>" . $e['title'] . "</a>" : $e['title'];
    // location fields
    $strip_desc = mc_newline_replace(strip_tags($event->event_desc));
    $e['location'] = stripslashes($event->event_label);
    $e['street'] = stripslashes($event->event_street);
    $e['street2'] = stripslashes($event->event_street2);
    $e['phone'] = apply_filters('mc_phone_format', stripslashes($event->event_phone));
    $e['phone2'] = apply_filters('mc_phone_format', stripslashes($event->event_phone2));
    $e['city'] = stripslashes($event->event_city);
    $e['state'] = stripslashes($event->event_state);
    $e['postcode'] = stripslashes($event->event_postcode);
    $e['country'] = stripslashes($event->event_country);
    $e['hcard'] = stripslashes(mc_hcard($event));
    $e['link_map'] = $map;
    $e['map_url'] = $map_url;
    $e['map'] = mc_generate_map($event);
    $url = get_option('mc_uri') != '' && !is_numeric(get_option('mc_uri')) ? $e_link : $event->event_url;
    $e['gcal'] = mc_google_cal($dtstart, $dtend, $url, stripcslashes($event->event_title), mc_maplink($event, 'gcal'), $strip_desc);
    $e['gcal_link'] = "<a href='" . mc_google_cal($dtstart, $dtend, $url, stripcslashes($event->event_title), mc_maplink($event, 'gcal'), $strip_desc) . "' class='gcal external'>" . sprintf(__('Send <span class="screen-reader-text">%1$s </span>to Google Calendar', 'my-calendar'), stripcslashes($event->event_title)) . "</a>";
    $e['location_access'] = mc_expand(unserialize(mc_location_data('location_access', $event->event_location)));
    $e['location_source'] = $event->event_location;
    // IDs
    $e['dateid'] = $event->occur_id;
    // unique ID for this date of this event
    $e['id'] = $event->event_id;
    $e['group'] = $event->event_group_id;
    $e['event_span'] = $event->event_span;
    // RSS guid
    $e['region'] = $event->event_region;
    $e['guid'] = get_option('mc_uri') != '' && !is_numeric(get_option('mc_uri')) ? "<guid isPermaLink='true'>{$e_link}</guid>" : "<guid isPermalink='false'>{$e_link}</guid>";
    // iCAL
    $e['ical_location'] = $event->event_label . ' ' . $event->event_street . ' ' . $event->event_street2 . ' ' . $event->event_city . ' ' . $event->event_state . ' ' . $event->event_postcode;
    $e['ical_description'] = str_replace("\r", "=0D=0A=", $event->event_desc);
    $e['ical_desc'] = $strip_desc;
    $e['ical_start'] = $dtstart;
    $e['ical_end'] = $dtend;
    $ical_link = mc_build_url(array('vcal' => $event->occur_id), array('month', 'dy', 'yr', 'ltype', 'loc', 'mcat', 'format'), get_option('mc_uri'));
    $e['ical'] = $ical_link;
    $e['ical_html'] = "<a class='ical' rel='nofollow' href='{$ical_link}'>" . __('iCal', 'my-calendar') . "</a>";
    $e = apply_filters('mc_filter_shortcodes', $e, $event);
    return $e;
}
function my_calendar_show_locations($show = 'list', $datatype = 'name', $template = '')
{
    global $wpdb;
    $mcdb = $wpdb;
    if (get_option('mc_remote') == 'true' && function_exists('mc_remote_db')) {
        $mcdb = mc_remote_db();
    }
    switch ($datatype) {
        case "name":
        case "location":
            $data = "location_label";
            break;
        case "city":
            $data = "location_city";
            break;
        case "state":
            $data = "location_state";
            break;
        case "zip":
            $data = "location_postcode";
            break;
        case "country":
            $data = "location_country";
            break;
        case "hcard":
            $data = "location_label";
            break;
        case "region":
            $data = "location_region";
            break;
        default:
            $data = "location_label";
    }
    $locations = $mcdb->get_results("SELECT DISTINCT * FROM " . MY_CALENDAR_LOCATIONS_TABLE . " ORDER BY {$data} ASC");
    if ($locations) {
        $output = "<ul class='mc-locations'>";
        foreach ($locations as $key => $value) {
            $id = $value->location_id;
            if ($datatype != 'hcard' && $template == '') {
                $label = stripslashes($value->{$data});
                $url = mc_maplink($value, 'url', $source = 'location');
                if ($url) {
                    $output .= "<li>{$url}</li>";
                } else {
                    $output .= "<li>{$label}</li>";
                }
            } else {
                if ($datatype == 'hcard') {
                    $label = mc_hcard($value, true, true, 'location');
                    $output .= "<li>{$label}</li>";
                } else {
                    if ($template != '') {
                        $values = array('id' => $value->location_id, 'label' => $value->location_label, 'street' => $value->location_street, 'street2' => $value->location_street2, 'city' => $value->location_city, 'state' => $value->location_state, 'postcode' => $value->location_postcode, 'region' => $value->location_region, 'url' => $value->location_url, 'country' => $value->location_country, 'longitude' => $value->location_longitude, 'latitude' => $value->location_latitude, 'zoom' => $value->location_zoom, 'phone' => $value->location_phone);
                        $label = jd_draw_template($values, $template);
                        $output .= "<li>{$label}</li>";
                    }
                }
            }
        }
        $output .= "</ul>";
        $output = apply_filters('mc_location_list', $output, $locations);
        return $output;
    }
}