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>–</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>–</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>–<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 mc_facebook($e, $event) { $e['facebook'] = "<a href='https://www.facebook.com/sharer.php?u='" . urlencode(mc_get_details_link($event)) . "'>Share on Facebook</a>"; return $e; }
function my_calendar_draw_event($event, $type = "calendar", $process_date, $time, $template = '') { // if event is not approved, return without processing if (get_option('mc_event_approve') == 'true' && (int) $event->event_approved !== 1) { return; } // if event ends at midnight today (e.g., very first thing of the day), exit without re-drawing if ($event->event_endtime == '00:00:00' && date('Y-m-d', strtotime($event->occur_end)) == $process_date && date('Y-m-d', strtotime($event->occur_begin)) != $process_date) { return; } global $wpdb; $url = plugin_dir_url(__FILE__); $mcdb = $wpdb; if (get_option('mc_remote') == 'true' && function_exists('mc_remote_db')) { $mcdb = mc_remote_db(); } if ($event->category_private == 1 && !is_user_logged_in()) { return; } // assign empty values to template sections $header = $address = $more = $author = $list_title = $title = $output = $container = $short = $description = $link = $vcal = $gcal = ''; $date_format = get_option('mc_date_format') != '' ? get_option('mc_date_format') : get_option('date_format'); $data = mc_create_tags($event); $details = apply_filters('mc_custom_template', false, $data, $event, $type, $process_date, $time, $template); $templates = get_option('mc_templates'); if ($details === false) { if ($template != '' && mc_file_exists(sanitize_file_name($template))) { $template = @file_get_contents(mc_get_file(sanitize_file_name($template))); $details = jd_draw_template($data, $template); } else { switch ($type) { case 'mini': $template = $templates['mini']; if (get_option('mc_use_mini_template') == 1) { $details = jd_draw_template($data, $template); } break; case 'list': $template = $templates['list']; if (get_option('mc_use_list_template') == 1) { $details = jd_draw_template($data, $template); } break; case 'single': $template = $templates['details']; if (get_option('mc_use_details_template') == 1) { $details = jd_draw_template($data, $template); } break; case 'calendar': default: $template = $templates['grid']; if (get_option('mc_use_grid_template') == 1) { $details = jd_draw_template($data, $template); } } } } $mc_display_author = get_option('mc_display_author'); $display_map = get_option('mc_show_map'); $display_address = get_option('mc_show_address'); $display_details = get_option('mc_details'); $uid = 'mc_' . $event->occur_id; $day_id = date('d', strtotime($process_date)); $mc_id = $event->occur_id; $this_category = $event->event_category; $image = mc_category_icon($event); $header .= "<div id='{$uid}-{$day_id}-{$type}' class='{$type}-event " . "mc_" . sanitize_title($event->category_name) . " vevent'>\n"; $title_template = $templates['title'] == '' ? '{title}' : $templates['title']; $event_title = jd_draw_template($data, $title_template); $event_title = $event_title == '' ? jd_draw_template($data, '{title}') : $event_title; //prevent empty titles if (strpos($event_title, 'http') === false && $type != 'mini' && $type != 'list') { if (get_option('mc_open_uri') == 'true') { $details_link = mc_get_details_link($event); $wrap = "<a href='{$details_link}'>"; $balance = "</a>"; } else { $wrap = "<a href='#{$uid}-{$day_id}-{$type}-details'>"; $balance = "</a>"; } } else { $wrap = $balance = ''; } $current_date = date_i18n(apply_filters('mc_date_format', $date_format, 'details'), strtotime($process_date)); $group_class = $event->event_span == 1 ? ' multidate group' . $event->event_group_id : ''; $heading_level = apply_filters('mc_heading_level_table', 'h3', $type, $time, $template); $header .= $type != 'single' && $type != 'list' ? "<{$heading_level} class='event-title summary{$group_class}'>{$wrap}{$image}{$event_title}{$balance}</{$heading_level}>\n" : ''; $event_title = $type == 'single' ? apply_filters('mc_single_event_title', $event_title, $event) : $event_title; $title = $type == 'single' && !is_singular('mc-events') ? "<h2 class='event-title summary'>{$image} {$event_title}</h2>\n" : ''; $title = apply_filters('mc_event_title', $title, $event, $event_title, $image); $header .= $title; if ($details === false) { $custom = false; // put together address information as vcard if ($display_address == 'true' || $display_map == 'true') { $address = mc_hcard($event, $display_address, $display_map); } // end vcard $close = $type == 'calendar' || $type == 'mini' ? "<a href=\"#{$uid}-{$day_id}-{$type}\" class='mc-toggle mc-close close'><img src=\"" . plugin_dir_url(__FILE__) . "images/event-close.png\" alt='" . __('Close', 'my-calendar') . "' /></a>" : ''; $time = mc_time_html($event, $type, $current_date); if ($type == "list") { $heading_level = apply_filters('mc_heading_level_list', 'h3', $type, $time, $template); $list_title = "<{$heading_level} class='event-title summary'>{$image}" . $event_title . "</{$heading_level}>\n"; } if ($mc_display_author == 'true') { if ($event->event_author != 0) { $e = get_userdata($event->event_author); $author = '<p class="event-author">' . __('Posted by', 'my-calendar') . ' <span class="author-name">' . $e->display_name . "</span></p>\n"; } } if ($display_details == 'true' && !isset($_GET['mc_id'])) { $details_label = mc_get_details_label($event, $data); $details_link = mc_get_details_link($event); $more = get_option('mc_uri') != '' ? "<p class='mc_details'><a href='{$details_link}'>{$details_label}</a></p>\n" : ''; } // handle link expiration $event_link = mc_event_link($event); if (function_exists('mc_google_cal') && get_option('mc_show_gcal') == 'true') { $gcal_link = "<p class='gcal'>" . jd_draw_template($data, '{gcal_link}') . "</p>"; $gcal = $gcal_link; } if (function_exists('my_calendar_generate_vcal') && get_option('mc_show_event_vcal') == 'true') { $nonce = wp_create_nonce('my-calendar-nonce'); $vcal_link = "<p class='ical'><a rel='nofollow' href='" . home_url() . "?vcal={$uid}" . "'>" . __('iCal', 'my-calendar') . "</a></p>\n"; $vcal = $vcal_link; } $default_size = apply_filters('mc_default_image_size', 'medium'); if (is_numeric($event->event_post) && $event->event_post != 0 && (isset($data[$default_size]) && $data[$default_size] != '')) { $atts = apply_filters('mc_post_thumbnail_atts', array('class' => 'mc-image')); $image = get_the_post_thumbnail($event->event_post, $default_size, $atts); } else { $image = $event->event_image != '' ? "<img src='{$event->event_image}' alt='' class='mc-image' />" : ''; } if (get_option('mc_desc') == 'true' || $type == 'single') { $description = get_option('mc_process_shortcodes') == 'true' ? apply_filters('the_content', stripcslashes($event->event_desc)) : wpautop(stripcslashes($event->event_desc), 1); $description = "<div class='longdesc'>{$description}</div>"; } if (get_option('mc_short') == 'true' && $type != 'single') { $short = get_option('mc_process_shortcodes') == 'true' ? apply_filters('the_content', stripcslashes($event->event_short)) : wpautop(stripcslashes($event->event_short), 1); $short = "<div class='shortdesc'>{$short}</div>"; } if (get_option('mc_event_registration') == 'true') { switch ($event->event_open) { case '0': $status = get_option('mc_event_closed'); break; case '1': $status = get_option('mc_event_open'); break; case '2': $status = ''; break; default: $status = ''; } } else { $status = ''; } // JCD TODO - this is really wonky. What was I thinking? // if the event is a member of a group of events, but not the first, note that. if ($event->event_group == 1) { $info = array(); $info[] = $event->event_id; update_option('mc_event_groups', $info); } if (is_array(get_option('mc_event_groups'))) { if (in_array($event->event_id, get_option('mc_event_groups'))) { if ($process_date != $event->event_begin) { $status = __("This event is in a series. Register for the first event in this series to attend.", 'my-calendar'); } } } $status = $status != '' ? "<p>{$status}</p>" : ''; $status = apply_filters('mc_registration_state', $status, $event); $return = $type == 'single' ? "<p><a href='" . get_option('mc_uri') . "'>" . __('View full calendar', 'my-calendar') . "</a></p>" : ''; if ($type == 'calendar' && get_option('mc_open_uri') == 'true' && $time != 'day') { $description = $short = $status = ''; } if (get_option('mc_gmap') == 'true') { $map = is_singular('mc-event') || $type == 'single' ? mc_generate_map($event) : ''; } else { $map = ''; } if ($event_link != '' && get_option('mc_event_link') != 'false') { $is_external = mc_external_link($event_link); $external_class = $is_external ? "class='{$type}-link external'" : "class='{$type}-link'"; $link_template = isset($templates['link']) ? $templates['link'] : '{title}'; $link_text = jd_draw_template($data, $link_template); $link = "<p><a href='{$event_link}' {$is_external}>" . $link_text . "</a></p>"; } $details = "\n" . $close . $time . $list_title . $image . "<div class='location'>" . $map . $address . "</div>" . $description . $short . $link . $status . $author . "<div class='sharing'>" . $vcal . $gcal . $more . "</div>" . $return; } else { $custom = true; // if a custom template is in use $toggle = $type == 'calendar' || $type == 'mini' ? "<a href=\"#{$uid}-{$day_id}-{$type}\" class='mc-toggle mc-close close'><img src=\"" . plugin_dir_url(__FILE__) . "images/event-close.png\" alt='" . __('Close', 'my-calendar') . "' /></a>" : ''; $details = $toggle . $details . "\n"; } $container = "<div id='{$uid}-{$day_id}-{$type}-details' class='details'>\n"; $container = apply_filters('mc_before_event', $container, $event, $type, $time); $details = $header . $container . $details; $details .= apply_filters('mc_after_event', '', $event, $type, $time); $details .= "</div><!--ends .details--></div>"; $details = apply_filters('mc_event_content', $details, $event, $type, $time); return $details; }
function mc_list_events() { global $wpdb; $mcdb = $wpdb; if (current_user_can('mc_approve_events') || current_user_can('mc_manage_events') || current_user_can('mc_add_events')) { $action = !empty($_POST['event_action']) ? $_POST['event_action'] : ''; $event_id = !empty($_POST['event_id']) ? $_POST['event_id'] : ''; if ($action == 'delete') { $message = mc_delete_event($event_id); echo $message; } if (isset($_GET['order'])) { $sortdir = isset($_GET['order']) && $_GET['order'] == 'ASC' ? 'ASC' : 'default'; $sortdir = isset($_GET['order']) && $_GET['order'] == 'DESC' ? 'DESC' : $sortdir; } else { $sortdir = 'default'; } $default_direction = get_option('mc_default_direction') == '' ? 'ASC' : get_option('mc_default_direction'); $sortbydirection = $sortdir == 'default' ? $default_direction : $sortdir; $sortby = isset($_GET['sort']) ? $_GET['sort'] : get_option('mc_default_sort'); if (empty($sortby)) { $sortbyvalue = 'event_begin'; } else { switch ($sortby) { case 1: $sortbyvalue = 'event_ID'; break; case 2: $sortbyvalue = 'event_title'; break; case 3: $sortbyvalue = 'event_desc'; break; case 4: $sortbyvalue = "event_begin {$sortbydirection}, event_time"; break; case 5: $sortbyvalue = 'event_author'; break; case 6: $sortbyvalue = 'event_category'; break; case 7: $sortbyvalue = 'event_label'; break; default: $sortbyvalue = "event_begin {$sortbydirection}, event_time"; } } $sorting = $sortbydirection == 'DESC' ? "&order=ASC" : '&order=DESC'; $allow_filters = true; $status = isset($_GET['limit']) ? $_GET['limit'] : 'all'; $restrict = isset($_GET['restrict']) ? $_GET['restrict'] : 'all'; switch ($status) { case 'all': $limit = ''; break; case 'reserved': $limit = 'WHERE event_approved <> 1'; break; case 'published': $limit = 'WHERE event_approved = 1'; break; default: $limit = ''; } switch ($restrict) { case 'all': $filter = ''; break; case 'where': $filter = isset($_GET['filter']) ? $_GET['filter'] : ''; $restrict = "event_label"; break; case 'author': $filter = isset($_GET['filter']) ? (int) $_GET['filter'] : ''; $restrict = "event_author"; break; case 'category': $filter = isset($_GET['filter']) ? (int) $_GET['filter'] : ''; $restrict = "event_category"; break; case 'flagged': $filter = isset($_GET['filter']) ? (int) $_GET['filter'] : ''; $restrict = "event_flagged"; break; default: $filter = ''; } if (!current_user_can('mc_manage_events') && !current_user_can('mc_approve_events')) { $restrict = 'event_author'; $filter = get_current_user_id(); $allow_filters = false; } $filter = esc_sql(urldecode($filter)); if ($restrict == "event_label") { $filter = "'{$filter}'"; } if ($limit == '' && $filter != '') { $limit = "WHERE {$restrict} = {$filter}"; } else { if ($limit != '' && $filter != '') { $limit .= "AND {$restrict} = {$filter}"; } } if ($filter == '' || !$allow_filters) { $filtered = ""; } else { $filtered = "<span class='dashicons dashicons-no'></span><a href='" . admin_url('admin.php?page=my-calendar-manage') . "'>" . __('Clear filters', 'my-calendar') . "</a>"; } $current = empty($_GET['paged']) ? 1 : intval($_GET['paged']); $user = get_current_user_id(); $screen = get_current_screen(); $option = $screen->get_option('per_page', 'option'); $items_per_page = get_user_meta($user, $option, true); if (empty($items_per_page) || $items_per_page < 1) { $items_per_page = $screen->get_option('per_page', 'default'); } // default limits if ($limit == '') { $limit .= $restrict != 'event_flagged' ? " WHERE event_flagged = 0" : ''; } else { $limit .= $restrict != 'event_flagged' ? " AND event_flagged = 0" : ''; } if (isset($_POST['mcs'])) { $query = $_POST['mcs']; $limit .= mc_prepare_search_query($query); } $limit .= $restrict != 'archived' ? " AND event_status = 1" : ' AND event_status = 0'; $events = $mcdb->get_results("SELECT SQL_CALC_FOUND_ROWS event_id FROM " . my_calendar_table() . " {$limit} ORDER BY {$sortbyvalue} {$sortbydirection} LIMIT " . ($current - 1) * $items_per_page . ", " . $items_per_page); $found_rows = $wpdb->get_col("SELECT FOUND_ROWS();"); $items = $found_rows[0]; if ((function_exists('akismet_http_post') || function_exists('bs_checker')) && $allow_filters) { ?> <ul class="links"> <li> <a <?php echo isset($_GET['restrict']) && $_GET['restrict'] == 'flagged' ? 'class="active-link"' : ''; ?> href="<?php echo admin_url('admin.php?page=my-calendar-manage&restrict=flagged&filter=1'); ?> "><?php _e('Spam', 'my-calendar'); ?> </a> </li> </ul><?php } ?> <div class='mc-search'> <form action="<?php echo esc_url(add_query_arg($_GET, admin_url('admin.php'))); ?> " method="post"> <div><input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('my-calendar-nonce'); ?> "/> </div> <div> <label for="mc_search" class='screen-reader-text'><?php _e('Search', 'my-calendar'); ?> </label> <input type='text' role='search' name='mcs' id='mc_search' value='<?php if (isset($_POST['mcs'])) { esc_attr_e($_POST['mcs']); } ?> '/> <input type='submit' value='<?php _e('Search Events', 'my-calendar'); ?> ' class='button-secondary'/> </div> </form> </div> <?php if (get_option('mc_event_approve') == 'true') { ?> <ul class="links"> <li> <a <?php echo isset($_GET['limit']) && $_GET['limit'] == 'published' ? 'class="active-link"' : ''; ?> href="<?php echo admin_url('admin.php?page=my-calendar-manage&limit=published'); ?> "><?php _e('Published', 'my-calendar'); ?> </a> </li> <li> <a <?php echo isset($_GET['limit']) && $_GET['limit'] == 'reserved' ? 'class="active-link"' : ''; ?> href="<?php echo admin_url('admin.php?page=my-calendar-manage&limit=reserved'); ?> "><?php _e('Reserved', 'my-calendar'); ?> </a> </li> <li> <a <?php echo isset($_GET['limit']) && $_GET['limit'] == 'all' || !isset($_GET['limit']) ? 'class="active-link"' : ''; ?> href="<?php echo admin_url('admin.php?page=my-calendar-manage&restrict=archived'); ?> "><?php _e('Archived', 'my-calendar'); ?> </a> </li> <li> <a <?php echo isset($_GET['limit']) && $_GET['limit'] == 'all' || !isset($_GET['limit']) ? 'class="active-link"' : ''; ?> href="<?php echo admin_url('admin.php?page=my-calendar-manage&limit=all'); ?> "><?php _e('All', 'my-calendar'); ?> </a> </li> </ul><?php } echo $filtered; $num_pages = ceil($items / $items_per_page); if ($num_pages > 1) { $page_links = paginate_links(array('base' => add_query_arg('paged', '%#%'), 'format' => '', 'prev_text' => __('« Previous<span class="screen-reader-text"> Events</span>', 'my-calendar'), 'next_text' => __('Next<span class="screen-reader-text"> Events</span> »', 'my-calendar'), 'total' => $num_pages, 'current' => $current, 'mid_size' => 1)); printf("<div class='tablenav'><div class='tablenav-pages'>%s</div></div>", $page_links); } if (!empty($events)) { ?> <form action="<?php echo esc_url(add_query_arg($_GET, admin_url('admin.php'))); ?> " method="post"> <div><input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('my-calendar-nonce'); ?> "/> </div> <div class='mc-actions'> <input type="submit" class="button-secondary delete" name="mass_delete" value="<?php _e('Delete events', 'my-calendar'); ?> "/> <?php if (current_user_can('mc_approve_events')) { ?> <input type="submit" class="button-secondary mc-approve" name="mass_approve" value="<?php _e('Approve events', 'my-calendar'); ?> "/> <?php } ?> <?php if (!(isset($_GET['restrict']) && $_GET['restrict'] == 'archived')) { ?> <input type="submit" class="button-secondary mc-archive" name="mass_archive" value="<?php _e('Archive events', 'my-calendar'); ?> "/> <?php } else { ?> <input type="submit" class="button-secondary mc-archive" name="mass_undo_archive" value="<?php _e('Remove from archive', 'my-calendar'); ?> "/> <?php } ?> </div> <table class="widefat wp-list-table" id="my-calendar-admin-table"> <thead> <tr> <th scope="col" style="width: 50px;"><input type='checkbox' class='selectall' id='mass_edit'/> <label for='mass_edit' class="screen-reader-text"><?php _e('Check/Uncheck all', 'my-calendar'); ?> </label> <a href="<?php echo admin_url("admin.php?page=my-calendar-manage&sort=1{$sorting}"); ?> "><?php _e('ID', 'my-calendar'); ?> </a> </th> <th scope="col"><a href="<?php echo admin_url("admin.php?page=my-calendar-manage&sort=2{$sorting}"); ?> "><?php _e('Title', 'my-calendar'); ?> </a> </th> <th scope="col"><a href="<?php echo admin_url("admin.php?page=my-calendar-manage&sort=7{$sorting}"); ?> "><?php _e('Location', 'my-calendar'); ?> </a> </th> <th scope="col"><a href="<?php echo admin_url("admin.php?page=my-calendar-manage&sort=4{$sorting}"); ?> "><?php _e('Date/Time', 'my-calendar'); ?> </a> </th> <th scope="col"><a href="<?php echo admin_url("admin.php?page=my-calendar-manage&sort=5{$sorting}"); ?> "><?php _e('Author', 'my-calendar'); ?> </a> </th> <th scope="col"><a href="<?php echo admin_url("admin.php?page=my-calendar-manage&sort=6{$sorting}"); ?> "><?php _e('Category', 'my-calendar'); ?> </a> </th> </tr> </thead> <?php $class = ''; $sql = "SELECT * FROM " . my_calendar_categories_table(); $categories = $mcdb->get_results($sql); foreach (array_keys($events) as $key) { $event =& $events[$key]; $event = mc_get_event_core($event->event_id); if (!is_object($event)) { continue; } $class = $class == 'alternate' ? 'even' : 'alternate'; $pending = $event->event_approved == 0 ? 'pending' : ''; $author = $event->event_author != 0 ? get_userdata($event->event_author) : 'Public Submitter'; if ($event->event_flagged == 1 && (isset($_GET['restrict']) && $_GET['restrict'] == 'flagged')) { $spam = 'spam'; $pending = ''; $spam_label = '<strong>' . __('Possible spam', 'my-calendar') . ':</strong> '; } else { $spam = ''; $spam_label = ''; } $edit_url = admin_url("admin.php?page=my-calendar&mode=edit&event_id={$event->event_id}"); $copy_url = admin_url("admin.php?page=my-calendar&mode=copy&event_id={$event->event_id}"); $view_url = mc_get_details_link($event); $group_url = admin_url("admin.php?page=my-calendar-groups&mode=edit&event_id={$event->event_id}&group_id={$event->event_group_id}"); $delete_url = admin_url("admin.php?page=my-calendar-manage&mode=delete&event_id={$event->event_id}"); $check = mc_test_occurrence_overlap($event, true); $problem = $check != '' ? 'problem' : ''; if (current_user_can('mc_manage_events') || current_user_can('mc_approve_events') || mc_can_edit_event($event->event_id)) { ?> <tr class="<?php echo "{$class} {$spam} {$pending} {$problem}"; ?> "> <th scope="row"> <input type="checkbox" value="<?php echo $event->event_id; ?> " name="mass_edit[]" id="mc<?php echo $event->event_id; ?> " <?php echo $event->event_flagged == 1 ? 'checked="checked"' : ''; ?> /> <label for="mc<?php echo $event->event_id; ?> "><?php echo $event->event_id; ?> </label> </th> <td title="<?php echo esc_attr(substr(strip_tags(stripslashes($event->event_desc)), 0, 240)); ?> "> <strong><?php if (mc_can_edit_event($event->event_id)) { ?> <a href="<?php echo $edit_url; ?> " class='edit'> <?php } ?> <?php echo $spam_label; echo strip_tags(stripslashes($event->event_title)); ?> <?php if (mc_can_edit_event($event->event_id)) { echo "</a>"; if ($check != '') { echo '<br /><strong class="error">' . sprintf(__('There is a problem with this event. <a href="%s">View</a>', 'my-calendar'), $edit_url) . '</strong>'; } } ?> </strong> <div class='row-actions' style="visibility:visible;"> <?php if (mc_event_published($event)) { ?> <a href="<?php echo $view_url; ?> " class='view'><?php _e('View', 'my-calendar'); ?> </a> | <?php } ?> <a href="<?php echo $copy_url; ?> " class='copy'><?php _e('Copy', 'my-calendar'); ?> </a> | <?php if (mc_can_edit_event($event->event_id)) { ?> <a href="<?php echo $edit_url; ?> " class='edit'><?php _e('Edit', 'my-calendar'); ?> </a> <?php if (mc_event_is_grouped($event->event_group_id)) { ?> | <a href="<?php echo $group_url; ?> " class='edit group'><?php _e('Edit Group', 'my-calendar'); ?> </a> <?php } ?> | <a href="<?php echo $delete_url; ?> " class="delete"><?php _e('Delete', 'my-calendar'); ?> </a> <?php } else { _e("Not editable.", 'my-calendar'); } if (get_option('mc_event_approve') == 'true') { ?> | <?php if (current_user_can('mc_approve_events')) { // Added by Roland P. if ($event->event_approved == '1') { $mo = 'reject'; $te = __('Reject', 'my-calendar'); } else { $mo = 'publish'; $te = __('Approve', 'my-calendar'); } ?> <a href="<?php echo admin_url("admin.php?page=my-calendar-manage&mode={$mo}&event_id={$event->event_id}"); ?> " class='<?php echo $mo; ?> '><?php echo $te; ?> </a> <?php } else { switch ($event->event_approved) { case 1: _e('Approved', 'my-calendar'); break; case 2: _e('Rejected', 'my-calendar'); break; default: _e('Awaiting Approval', 'my-calendar'); } } } ?> </div> </td> <td> <?php if ($event->event_label != '') { ?> <a class='mc_filter' href='<?php $elabel = urlencode($event->event_label); echo admin_url("admin.php?page=my-calendar-manage&filter={$elabel}&restrict=where"); ?> ' title="<?php _e('Filter by location', 'my-calendar'); ?> "><span class="screen-reader-text"><?php _e('Show only: ', 'my-calendar'); ?> </span><?php echo strip_tags(stripslashes($event->event_label)); ?> </a><?php } ?> </td> <?php if ($event->event_endtime != "23:59:59") { $eventTime = date_i18n(get_option('mc_time_format'), strtotime($event->event_time)); } else { $eventTime = mc_notime_label($event); } ?> <td><?php $date_format = get_option('mc_date_format') == '' ? get_option('date_format') : get_option('mc_date_format'); $begin = date_i18n($date_format, strtotime($event->event_begin)); echo "{$begin}, {$eventTime}"; ?> <div class="recurs"> <strong><?php _e('Recurs', 'my-calendar'); ?> </strong> <?php $recurs = str_split($event->event_recur, 1); $recur = $recurs[0]; $every = isset($recurs[1]) ? $recurs[1] : 1; // Interpret the DB values into something human readable switch ($recur) { case 'S': _e('Never', 'my-calendar'); break; case 'D': $every == 1 ? _e('Daily', 'my-calendar') : printf(__('Every %d days', 'my-calendar'), $every); break; case 'E': $every == 1 ? _e('Weekdays', 'my-calendar') : printf(__('Every %d weekdays', 'my-calendar'), $every); break; case 'W': $every == 1 ? _e('Weekly', 'my-calendar') : printf(__('Every %d weeks', 'my-calendar'), $every); break; case 'B': _e('Bi-Weekly', 'my-calendar'); break; case 'M': $every == 1 ? _e('Monthly (by date)', 'my-calendar') : printf(__('Every %d months (by date)', 'my-calendar'), $every); break; case 'U': _e('Monthly (by day)', 'my-calendar'); break; case 'Y': $every == 1 ? _e('Yearly', 'my-calendar') : printf(__('Every %d years', 'my-calendar'), $every); break; } $eternity = _mc_increment_values($recur); if ($recur == 'S') { } else { if ($event->event_repeats > 0) { printf(__('– %d Times', 'my-calendar'), $event->event_repeats); } else { if ($eternity) { printf(__('– %d Times', 'my-calendar'), $eternity); } } } ?> </div> </td> <td><a class='mc_filter' href="<?php $auth = is_object($author) ? $author->ID : 0; echo admin_url("admin.php?page=my-calendar-manage&filter={$auth}&restrict=author"); ?> " title="<?php _e('Filter by author', 'my-calendar'); ?> "><span class="screen-reader-text"><?php _e('Show only: ', 'my-calendar'); ?> </span><?php echo is_object($author) ? $author->display_name : $author; ?> </a></td> <?php if (!$event->event_category) { // events *must* have a category mc_update_event('event_category', 1, $event->event_id, '%d'); } $color = strip_tags(mc_get_category_detail($event->event_category, 'category_color')); ?> <td> <div class="category-color" style="background-color:<?php echo strpos($color, '#') !== 0 ? '#' : ''; echo $color; ?> ;"> </div> <a class='mc_filter' href='<?php echo admin_url("admin.php?page=my-calendar-manage&filter={$event->event_category}&restrict=category"); ?> ' title="<?php _e('Filter by category', 'my-calendar'); ?> "><span class="screen-reader-text"><?php _e('Show only: ', 'my-calendar'); ?> </span><?php echo mc_kses_post(mc_get_category_detail($event->event_category, 'category_name')); ?> </a></td> </tr> <?php } } ?> </table> <p> <input type="submit" class="button-secondary delete" name="mass_delete" value="<?php _e('Delete events', 'my-calendar'); ?> "/> <?php if (current_user_can('mc_approve_events')) { ?> <input type="submit" class="button-secondary mc-approve" name="mass_approve" value="<?php _e('Approve events', 'my-calendar'); ?> "/> <?php } ?> <?php if (!(isset($_GET['restrict']) && $_GET['restrict'] == 'archived')) { ?> <input type="submit" class="button-secondary mc-archive" name="mass_archive" value="<?php _e('Archive events', 'my-calendar'); ?> "/> <?php } ?> </p> <p> <?php if (!(isset($_GET['restrict']) && $_GET['restrict'] == 'archived')) { ?> <a class='mc_filter' href='<?php echo admin_url("admin.php?page=my-calendar-manage&restrict=archived"); ?> '><?php _e('View Archived Events', 'my-calendar'); ?> </a> <?php } else { ?> <a class='mc_filter' href='<?php echo admin_url("admin.php?page=my-calendar-manage"); ?> '><?php _e('Return to Manage Events', 'my-calendar'); ?> </a> <?php } ?> </p> </form> <?php } else { ?> <p class='mc-none'><?php _e("There are no events in the database meeting your current criteria.", 'my-calendar'); ?> </p><?php } } }
function my_calendar_draw_event($event, $type = "calendar", $process_date, $time, $template = '') { // if event is not approved, return without processing if (get_option('mc_event_approve') == 'true' && (int) $event->event_approved !== 1) { return ''; } // if event ends at midnight today (e.g., very first thing of the day), exit without re-drawing // or if event started yesterday & has event_hide_end checked. $ends_at_midnight = $event->event_endtime == '00:00:00' && date('Y-m-d', strtotime($event->occur_end)) == $process_date && date('Y-m-d', strtotime($event->occur_begin)) != $process_date ? true : false; // hides events if hiding end time & not first day. $hide_day_two = apply_filters('mc_hide_additional_days', false, $event) && date('Y-m-d', strtotime($event->occur_begin)) != date('Y-m-d', strtotime($process_date)) ? true : false; if ($ends_at_midnight || $hide_day_two) { return ''; } if ($event->category_private == 1 && !is_user_logged_in()) { return ''; } // assign empty values to template sections $header = $address = $more = $author = $list_title = $title = $output = $container = $short = $description = $link = $vcal = $gcal = ''; $date_format = get_option('mc_date_format') != '' ? get_option('mc_date_format') : get_option('date_format'); $data = mc_create_tags($event); $details = ''; if (mc_show_details($time, $type)) { $details = apply_filters('mc_custom_template', false, $data, $event, $type, $process_date, $time, $template); $template = apply_filters('mc_use_custom_template', $template, $data, $event, $type, $process_date, $time); if ($details === false) { if ($template != '' && mc_file_exists(sanitize_file_name($template))) { $template = @file_get_contents(mc_get_file(sanitize_file_name($template))); $details = jd_draw_template($data, $template); } else { if ($template != '' && mc_key_exists($template)) { $template = mc_get_custom_template($template); $details = jd_draw_template($data, $template); } else { switch ($type) { case 'mini': $template = mc_get_template('mini'); if (get_option('mc_use_mini_template') == 1) { $details = jd_draw_template($data, $template); } break; case 'list': $template = mc_get_template('list'); if (get_option('mc_use_list_template') == 1) { $details = jd_draw_template($data, $template); } break; case 'single': $template = mc_get_template('details'); if (get_option('mc_use_details_template') == 1) { $details = jd_draw_template($data, $template); } break; case 'calendar': default: $template = mc_get_template('grid'); if (get_option('mc_use_grid_template') == 1) { $details = jd_draw_template($data, $template); } } } } } } $mc_display_author = get_option('mc_display_author'); $display_map = get_option('mc_show_map'); $display_address = get_option('mc_show_address'); $mc_display_more = get_option('mc_display_more'); $uid = 'mc_' . $event->occur_id; $day_id = date('d', strtotime($process_date)); $image = mc_category_icon($event); $has_image = $image != '' ? ' has-image' : ''; $event_classes = mc_event_classes($event, $day_id, $type); $header .= "<div id='{$uid}-{$day_id}-{$type}' class='{$event_classes}'>\n"; switch ($type) { case 'calendar': $title_template = mc_get_template('title') == '' ? '{title}' : mc_get_template('title'); break; case 'list': $title_template = mc_get_template('title_list') == '' ? '{title}' : mc_get_template('title_list'); break; case 'single': $title_template = mc_get_template('title_solo') == '' ? '{title}' : mc_get_template('title_solo'); break; default: $title_template = mc_get_template('title') == '' ? '{title}' : mc_get_template('title'); } $event_title = jd_draw_template($data, $title_template); $event_title = $event_title == '' ? jd_draw_template($data, '{title}') : mc_kses_post($event_title); //prevent empty titles if (strpos($event_title, 'href') === false && $type != 'mini' && $type != 'list') { if (get_option('mc_open_uri') == 'true') { $details_link = esc_url(mc_get_details_link($event)); $wrap = "<a href='{$details_link}' class='url summary{$has_image}'>"; $balance = "</a>"; } else { $wrap = "<a href='#{$uid}-{$day_id}-{$type}-details' class='url summary{$has_image}'>"; $balance = "</a>"; } } else { $wrap = $balance = ''; } $current_date = date_i18n(apply_filters('mc_date_format', $date_format, 'details'), strtotime($process_date)); $group_class = $event->event_span == 1 ? ' multidate group' . $event->event_group_id : ''; $heading_level = apply_filters('mc_heading_level_table', 'h3', $type, $time, $template); $inner_heading = apply_filters('mc_heading_inner_title', $wrap . $image . trim($event_title) . $balance, $event_title, $event); $header .= $type != 'single' && $type != 'list' ? "<{$heading_level} class='event-title summary{$group_class}' id='{$uid}-{$day_id}-{$type}-title'>{$inner_heading}</{$heading_level}>\n" : ''; $event_title = $type == 'single' ? apply_filters('mc_single_event_title', $event_title, $event) : $event_title; $title = $type == 'single' && !is_singular('mc-events') ? "<h2 class='event-title summary'>{$image} {$event_title}</h2>\n" : '<span class="summary screen-reader-text">' . $event_title . '</span>'; $title = apply_filters('mc_event_title', $title, $event, $event_title, $image); $header .= '<span class="summary">' . $title . '</span>'; $close_image = apply_filters('mc_close_button', "<img src=\"" . plugin_dir_url(__FILE__) . "images/event-close.png\" alt='" . __('Close', 'my-calendar') . "' />"); $close_button = "<button type='button' aria-controls='{$uid}-{$day_id}-{$type}-details' class='mc-toggle close'>{$close_image}</button>"; if (mc_show_details($time, $type)) { $close = $type == 'calendar' || $type == 'mini' ? $close_button : ''; if ($details === false) { // put together address information as vcard if ($display_address == 'true' || $display_map == 'true') { $address = mc_hcard($event, $display_address, $display_map); } // end vcard $time_html = mc_time_html($event, $type, $current_date); if ($type == "list") { $heading_level = apply_filters('mc_heading_level_list', 'h3', $type, $time, $template); $list_title = "<{$heading_level} class='event-title summary' id='{$uid}-{$day_id}-{$type}-title'>{$image}" . $event_title . "</{$heading_level}>\n"; } if ($mc_display_author == 'true') { if ($event->event_author != 0) { $e = get_userdata($event->event_author); $author = '<p class="event-author">' . __('Posted by', 'my-calendar') . ' <span class="author-name">' . $e->display_name . "</span></p>\n"; } } if ($mc_display_more != 'false' && !isset($_GET['mc_id'])) { $details_label = mc_get_details_label($event, $data); $details_link = mc_get_details_link($event); if (_mc_is_url($details_link)) { $more = "<p class='mc_details'><a href='" . esc_url($details_link) . "'>{$details_label}</a></p>\n"; } else { $more = ''; } } $more = apply_filters('mc_details_grid_link', $more, $event); // handle link expiration $event_link = mc_event_link($event); if (function_exists('mc_google_cal') && get_option('mc_show_gcal') == 'true') { $gcal_link = "<p class='gcal'>" . jd_draw_template($data, '{gcal_link}') . "</p>"; $gcal = $gcal_link; } if (function_exists('my_calendar_generate_vcal') && get_option('mc_show_event_vcal') == 'true') { $url = add_query_arg('vcal', $uid, home_url()); $vcal_link = "<p class='ical'><a rel='nofollow' href='" . esc_url($url) . "'>" . __('iCal', 'my-calendar') . "</a></p>\n"; $vcal = $vcal_link; } $sizes = get_intermediate_image_sizes(); if (in_array('medium', $sizes)) { $default_size = 'medium'; } else { $default_size = 'thumbnail'; } $default_size = apply_filters('mc_default_image_size', $default_size); if (is_numeric($event->event_post) && $event->event_post != 0 && (isset($data[$default_size]) && $data[$default_size] != '')) { $atts = apply_filters('mc_post_thumbnail_atts', array('class' => 'mc-image photo')); $image = get_the_post_thumbnail($event->event_post, $default_size, $atts); } else { $image = $event->event_image != '' ? "<img src='{$event->event_image}' alt='' class='mc-image photo' />" : ''; } if (get_option('mc_desc') == 'true' || $type == 'single') { $description = wpautop(stripcslashes(mc_kses_post($event->event_desc)), 1); $description = "<div class='longdesc description'>{$description}</div>"; } if (get_option('mc_short') == 'true' && $type != 'single') { $short = wpautop(stripcslashes(mc_kses_post($event->event_short)), 1); $short = "<div class='shortdesc'>{$short}</div>"; } if (get_option('mc_event_registration') == 'true') { switch ($event->event_open) { case '0': $status = mc_kses_post(get_option('mc_event_closed')); break; case '1': $status = mc_kses_post(get_option('mc_event_open')); break; case '2': $status = ''; break; default: $status = ''; } } else { $status = ''; } $status = $status != '' ? "<p>{$status}</p>" : ''; $status = apply_filters('mc_registration_state', $status, $event); $return_url = apply_filters('mc_return_uri', get_option('mc_uri')); $return = $type == 'single' ? "<p class='view-full'><a href='{$return_url}'>" . __('View full calendar', 'my-calendar') . "</a></p>" : ''; if (!mc_show_details($time, $type)) { $description = $short = $status = ''; } if (get_option('mc_gmap') == 'true') { $map = is_singular('mc-events') || $type == 'single' ? mc_generate_map($event) : ''; } else { $map = ''; } if ($event_link != '' && get_option('mc_event_link') != 'false') { $is_external = mc_external_link($event_link); $external_class = $is_external ? "class='{$type}-link external url'" : "class='{$type}-link url'"; $link_template = mc_get_template('link') != '' ? mc_get_template('link') : '{title}'; $link_text = jd_draw_template($data, $link_template); $link = "<p><a href='" . esc_url($event_link) . "' {$external_class}>" . $link_text . "</a></p>"; } $details = "\n" . $close . $time_html . $list_title . $image . "<div class='location'>" . $map . $address . "</div>" . $description . $short . $link . $status . $author . "<div class='sharing'>" . $vcal . $gcal . $more . "</div>" . $return; } else { // if a custom template is in use $toggle = $type == 'calendar' || $type == 'mini' ? $close_button : ''; $details = $toggle . $details . "\n"; } $img_class = $image != '' ? ' has-image' : ' no-image'; $container = "<div id='{$uid}-{$day_id}-{$type}-details' class='details{$img_class}' role='alert' aria-labelledby='{$uid}-{$day_id}-{$type}-title'>\n"; $container = apply_filters('mc_before_event', $container, $event, $type, $time); $details = $header . $container . apply_filters('mc_inner_content', $details, $event, $type, $time); $details .= apply_filters('mc_after_event', '', $event, $type, $time); $details .= $close; // second close button $details .= "</div><!--ends .details--></div>"; $details = apply_filters('mc_event_content', $details, $event, $type, $time); } else { $details = apply_filters('mc_before_event_no_details', $container, $event, $type, $time) . $header . apply_filters('mc_after_event_no_details', '', $event, $type, $time) . "</div>"; } return $details; }
function my_calendar_save($action, $output, $event_id = false) { global $wpdb, $event_author; $mcdb = $wpdb; $proceed = $output[0]; $message = ''; $formats = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%f', '%f'); if (($action == 'add' || $action == 'copy') && $proceed == true) { $add = $output[2]; // add format here $add = apply_filters('mc_before_save_insert', $add); $result = $mcdb->insert(my_calendar_table(), $add, $formats); $event_id = $mcdb->insert_id; mc_increment_event($event_id); if (!$result) { $message = "<div class='error notice'><p><strong>" . __('Error', 'my-calendar') . ":</strong> " . __('I\'m sorry! I couldn\'t add that event to the database.', 'my-calendar') . "</p></div>"; } else { // do an action using the $action and processed event data $data = $add; do_action('mc_save_event', $action, $data, $event_id, $result); // Call mail function if (get_option('mc_event_mail') == 'true') { $event = mc_get_first_event($event_id); // insert_id is last occurrence inserted in the db my_calendar_send_email($event); } if ($add['event_approved'] == 0) { $message = "<div class='updated notice'><p>" . __('Event saved. An administrator will review and approve your event.', 'my-calendar') . "</p></div>"; } else { if (function_exists('jd_doTwitterAPIPost') && isset($_POST['mc_twitter']) && trim($_POST['mc_twitter']) != '') { jd_doTwitterAPIPost(stripslashes($_POST['mc_twitter'])); } if (get_option('mc_uri') != '') { $event_ids = mc_get_occurrences($event_id); //$event_link = mc_build_url( array( 'mc_id' => $event_ids[0]->occur_id ), array( 'page' ), get_option( 'mc_uri' ) ); //$event_link = add_query_arg( 'mc_id', $event_ids[0]->occur_id, get_option( 'mc_uri' ) ); $event_link = mc_get_details_link($event_ids[0]->occur_id); } else { $event_link = false; } $message = "<div class='updated notice'><p>" . __('Event added. It will now show on the calendar.', 'my-calendar'); if ($event_link !== false) { $message .= sprintf(__(' <a href="%s">View Event</a>', 'my-calendar'), $event_link); } $message .= "</p></div>"; } mc_delete_cache(); } } if ($action == 'edit' && $proceed == true) { $result = true; $url = get_option('mc_uri') != '' && !is_numeric(get_option('mc_uri')) ? '' . sprintf(__('View <a href="%s">your calendar</a>.', 'my-calendar'), get_option('mc_uri')) : ''; $event_author = (int) $_POST['event_author']; if (mc_can_edit_event($event_author)) { $update = $output[2]; $update = apply_filters('mc_before_save_update', $update, $event_id); $date_changed = $update['event_begin'] != $_POST['prev_event_begin'] || date("H:i:00", strtotime($update['event_time'])) != $_POST['prev_event_time'] || $update['event_end'] != $_POST['prev_event_end'] || date("H:i:00", strtotime($update['event_endtime'])) != $_POST['prev_event_endtime'] && ($_POST['prev_event_endtime'] != '' && date("H:i:00", strtotime($update['event_endtime'])) != '23:59:59') ? true : false; // this may need to be 00:00:00; will have to verify JCD TODO if (isset($_POST['event_instance'])) { $is_changed = mc_compare($update, $event_id); // compares the information sent to the information saved for a given event. $event_instance = (int) $_POST['event_instance']; if ($is_changed) { // if changed, create new event, match group id, update instance to reflect event connection, same group id. // if group ID == 0, need to add group ID to both records. // if a single instance is edited, it should *not* inherit the recurring settings from parent. $update['event_recur'] = 'S1'; if ($update['event_group_id'] == 0) { $update['event_group_id'] = $event_id; mc_update_data($event_id, 'event_group_id', $event_id); } $mcdb->insert(my_calendar_table(), $update, $formats); $new_event = $mcdb->insert_id; // need to get this variable into URL for form submit $result = mc_update_instance($event_instance, $new_event, $update); mc_delete_cache(); } else { if ($update['event_begin'][0] == $_POST['prev_event_begin'] && $update['event_end'][0] == $_POST['prev_event_end']) { // There were no changes at all. } else { $result = mc_update_instance($event_instance, $event_id, $update); // Only dates were changed $message = "<div class='updated notice'><p>" . __('Date/time information for this event has been updated.', 'my-calendar') . " {$url}</p></div>"; mc_delete_cache(); } } } else { $result = $mcdb->update(my_calendar_table(), $update, array('event_id' => $event_id), $formats, '%d'); $recur_changed = $update['event_repeats'] != $_POST['prev_event_repeats'] || $update['event_recur'] != $_POST['prev_event_recur'] ? true : false; if ($date_changed || $recur_changed) { mc_delete_instances($event_id); mc_increment_event($event_id); mc_delete_cache(); } } $data = $update; do_action('mc_save_event', $action, $data, $event_id, $result); if ($result === false) { $message = "<div class='error'><p><strong>" . __('Error', 'my-calendar') . ":</strong>" . __('Your event was not updated.', 'my-calendar') . " {$url}</p></div>"; } else { // do an action using the $action and processed event data $event_approved = isset($_POST['event_approved']) ? intval($_POST['event_approved']) : 0; do_action('mc_transition_event', (int) $_POST['prev_event_status'], $event_approved); $message = "<div class='updated'><p>" . __('Event updated successfully', 'my-calendar') . ". {$url}</p></div>"; mc_delete_cache(); } } else { $message = "<div class='error'><p><strong>" . __('You do not have sufficient permissions to edit that event.', 'my-calendar') . "</strong></p></div>"; } } $message = $message . "\n" . $output[3]; return array('event_id' => $event_id, 'message' => $message); }