Пример #1
0
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 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;
}