function my_event_email($details, $event, $type, $time) { if (my_calendar_date_xcomp($event->occur_end, date('Y-m-d', current_time('timestamp')))) { $data = mc_create_tags($event); // this is just a sample template; you'd want to customize it. $details = jd_draw_template($data, '<h2>{title}</h2>{image}'); } return $details; }
function my_calendar_ical() { $p = isset($_GET['span']) ? 'year' : false; $y = isset($_GET['yr']) ? $_GET['yr'] : date('Y'); $m = isset($_GET['month']) ? $_GET['month'] : date('n'); $ny = isset($_GET['nyr']) ? $_GET['nyr'] : $y; $nm = isset($_GET['nmonth']) ? $_GET['nmonth'] : $m; if ($p) { $from = "{$y}-1-1"; $to = "{$y}-12-31"; } else { $d = date('t', mktime(0, 0, 0, $m, 1, $y)); $from = "{$y}-{$m}-1"; $to = "{$ny}-{$nm}-{$d}"; } $from = apply_filters('mc_ical_download_from', $from, $p); $to = apply_filters('mc_ical_download_to', $to, $p); $atts = array('category' => null, 'ltype' => '', 'lvalue' => '', 'source' => 'calendar', 'author' => null, 'host' => null); $atts = apply_filters('mc_ical_attributes', $atts); extract($atts); global $mc_version; // establish template $template = "BEGIN:VEVENT\nUID:{dateid}-{id}\nLOCATION:{ical_location}\nSUMMARY:{title}\nDTSTAMP:{ical_start}\nORGANIZER;CN={host}:MAILTO:{host_email}\nDTSTART:{ical_start}\nDTEND:{ical_end}\nURL;VALUE=URI:{link}\nDESCRIPTION:{ical_desc}\nCATEGORIES:{category}\nEND:VEVENT"; // add ICAL headers $output = 'BEGIN:VCALENDAR VERSION:2.0 METHOD:PUBLISH PRODID:-//Accessible Web Design//My Calendar//http://www.joedolson.com//v' . $mc_version . '//EN'; // to do : add support for other arguments $events = my_calendar_grab_events($from, $to); if (is_array($events) && !empty($events)) { foreach (array_keys($events) as $key) { $event =& $events[$key]; if (is_object($event)) { if (!($event->category_private == 1 && !is_user_logged_in())) { $array = mc_create_tags($event); $output .= "\n" . jd_draw_template($array, $template, 'ical'); } } } } $output .= "\nEND:VCALENDAR"; $output = html_entity_decode(preg_replace("~(?<!\r)\n~", "\r\n", $output)); if (!(isset($_GET['sync']) && $_GET['sync'] == 'true')) { header("Content-Type: text/calendar; charset=" . get_bloginfo('charset')); header("Pragma: no-cache"); header("Expires: 0"); header("Content-Disposition: inline; filename=my-calendar.ics"); } echo $output; }
function mc_format_rss($events) { $template = "\n<item>\n\t\t<title>{rss_title}</title>\n\t\t<link>{details_link}</link>\n\t\t<pubDate>{rssdate}</pubDate>\n\t\t<dc:creator>{author}</dc:creator> \t\n\t\t<description><![CDATA[{rss_description}]]></description>\n\t\t<date>{dtstart}</date>\n\t\t<dateSubmitted>{rssdate}</dateSubmitted>\n\t\t<content:encoded><![CDATA[<div class='vevent'>\n\t\t<h1 class='summary'>{rss_title}</h1>\n\t\t<div class='description'>{rss_description}</div>\n\t\t<p class='dtstart' title='{ical_start}'>Begins: {time} on {date}</p>\n\t\t<p class='dtend' title='{ical_end}'>Ends: {endtime} on {enddate}</p>\t\n\t\t<p>Recurrance: {recurs}</p>\n\t\t<p>Repetition: {repeats} times</p>\n\t\t<div class='location'>{rss_hcard}</div>\n\t\t{rss_link_title}\n\t\t</div>]]></content:encoded>\n\t\t<dc:format xmlns:dc='http://purl.org/dc/elements/1.1/'>text/html</dc:format>\n\t\t<dc:source xmlns:dc='http://purl.org/dc/elements/1.1/'>" . home_url() . "</dc:source>\t\n\t\t{guid}\n\t </item>\n"; $charset = get_bloginfo('charset'); $output = '<?xml version="1.0" encoding="' . $charset . '"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" > <channel> <title>' . get_bloginfo('name') . ' Calendar</title> <link>' . home_url() . '</link> <description>' . get_bloginfo('description') . ': My Calendar Events</description> <language>' . get_bloginfo('language') . '</language> <managingEditor>' . get_bloginfo('admin_email') . ' (' . get_bloginfo('name') . ' Admin)</managingEditor> <generator>My Calendar WordPress Plugin http://www.joedolson.com/articles/my-calendar/</generator> <lastBuildDate>' . mysql2date('D, d M Y H:i:s +0000', current_time('timestamp')) . '</lastBuildDate> <atom:link href="' . htmlentities(add_query_arg($_GET, mc_get_current_url())) . '" rel="self" type="application/rss+xml" />'; foreach ($events as $date) { foreach (array_keys($date) as $key) { $event =& $date[$key]; $array = mc_create_tags($event); $output .= jd_draw_template($array, $template, 'rss'); } } $output .= '</channel> </rss>'; return mc_strip_to_xml($output); }
function mc_get_details_label($event, $e) { $templates = get_option('mc_templates'); $e_template = !empty($templates['label']) ? stripcslashes($templates['label']) : sprintf(__('Event Details %s', 'my-calendar'), '<span class="screen-reader-text">about {title}</span> »'); $e_label = wp_kses(jd_draw_template($e, $e_template), array('span' => array('class' => array('screen-reader-text')), 'em', 'strong')); return $e_label; }
function mcs_payment_form() { $ret = $form = ''; if (isset($_GET['response_code'])) { $mcs = $_GET['response_code']; $provider = get_option('mcs_gateway') == 2 ? 'Authorize.net' : 'PayPal'; switch ($mcs) { case 'thanks': $ret = "<p class='notice'>" . sprintf(__("Thank you for your purchase! You can view your purchase information at %s. You will receive an email with your payment key once your payment is finalized.", 'my-calendar-submissions'), $provider) . "</p>"; break; case 'cancel': $ret = __("Sorry that you decided to cancel your purchase! Contact us if you have any questions!", 'my-calendar-submissions'); break; } } if (mcs_payment_required()) { $price = mcs_get_price(is_user_logged_in()); $currency = get_option('mcs_currency'); $quantity = get_option('mcs_quantity'); $discounts = mcs_check_discount(); $discount_rate = (int) $discounts['rate']; $discount = $discount_rate != 0 ? true : false; if (isset($_GET['response_code'])) { $message = ''; } else { $message = wpautop(jd_draw_template(array('price' => $price, 'currency' => $currency, 'discount' => $discount_rate, 'begins' => $discounts['begins'], 'ends' => $discounts['ends']), get_option('mcs_payment_message'))); } $form = "<div class='mc-payments-form " . get_option('mcs_gateway') . "'>\n\t\t {$ret}\n\t\t {$message}"; $nonce = wp_create_nonce('mcs-payments-nonce'); if (get_option('mcs_gateway') == 'authorizenet') { if (get_option('mcs_quantity') != 'true' || (get_option('mcs_quantity') == 'true' && isset($_POST['mcs_quantity']) || isset($_GET['response_code']))) { require_once 'gateways/AuthorizeNet.php'; // The SDK $url = mcs_replace_http(add_query_arg('mcsipn', 'true', get_permalink())); $rand = time() . rand(100000, 999999); $mcs_quantity = isset($_POST['mcs_quantity']) ? (int) $_POST['mcs_quantity'] : 1; $price = mcs_calculate_price($mcs_quantity, $price, $discount, $discount_rate); $form .= AuthorizeNetDPM::directPost($url, $price, $rand, $nonce); } else { $form .= mcs_set_quantity_form($price); } } else { $form .= mcs_paypal_form($price, $currency, $discount_rate, $discounts, $discount, $quantity); } $form .= "</div>"; } return $form; }
function my_calendar_send_email($event) { $details = mc_create_tags($event); // shift to boolean $send_email_option = get_option('mc_event_mail') == 'true' ? true : false; $send_email = apply_filters('mc_send_notification', $send_email_option, $details); if ($send_email == true) { add_filter('wp_mail_content_type', create_function('', 'return "text/html";')); } if (get_option('mc_event_mail') == 'true') { $to = apply_filters('mc_event_mail_to', get_option('mc_event_mail_to'), $details); $from = get_option('mc_event_mail_from') == '' ? get_bloginfo('admin_email') : get_option('mc_event_mail_from'); $from = apply_filters('mc_event_mail_from', $from, $details); $from = "From: " . __('Event Notifications', 'my-calendar') . " <{$from}>"; $subject = jd_draw_template($details, get_option('mc_event_mail_subject')); $message = jd_draw_template($details, get_option('mc_event_mail_message')); $mail = wp_mail($to, $subject, $message, $from); } if (get_option('mc_html_email') == 'true') { remove_filter('wp_mail_content_type', create_function('', 'return "text/html";')); } }
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; } }
function my_calendar_events_now($category = 'default', $template = '<strong>{link_title}</strong> {timerange}') { global $wpdb; $mcdb = $wpdb; if (get_option('mc_remote') == 'true' && function_exists('mc_remote_db')) { $mcdb = mc_remote_db(); } $arr_events = array(); $limit_string = "event_flagged <> 1 AND event_approved = 1"; $select_category = $category != 'default' ? mc_select_category($category) : ''; // may add support for location/author/host later. $select_location = $select_author = $select_host = ''; $now = date('Y-m-d H:i:s', current_time('timestamp')); $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 . " AS e \n\t\t\t\t\tJOIN " . MY_CALENDAR_TABLE . " AS t \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 . " AS c \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} \n\t\t\t\t\tAND ( CAST('{$now}' AS DATETIME) BETWEEN occur_begin AND occur_end ) \n\t\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 (!empty($arr_events)) { $event = mc_create_tags($arr_events[0]); $output = jd_draw_template($event, apply_filters('mc_happening_now_template', $template, $event)); return get_option('mc_process_shortcodes') == 'true' ? do_shortcode($output) : $output; } else { return ''; } }
function mc_instance_list($id, $occur = false, $template = '<h3>{title}</h3>{description}', $list = '<li>{date}, {time}</li>', $before = "<ul>", $after = "</ul>", $instance = false) { global $wpdb; $id = (int) $id; $output = ''; if ($instance == true) { $sql = "SELECT * FROM " . my_calendar_event_table() . " WHERE occur_id={$id}"; } else { $sql = "SELECT * FROM " . my_calendar_event_table() . " WHERE occur_event_id={$id}"; } $results = $wpdb->get_results($sql); if (is_array($results) && is_admin()) { foreach ($results as $result) { $begin = "<span id='occur_date_{$result->occur_id}'>" . date_i18n(get_option('mc_date_format'), strtotime($result->occur_begin)) . ', ' . date(get_option('mc_time_format'), strtotime($result->occur_begin)) . "</span>"; if ($result->occur_id == $occur) { $form_control = ''; $edit = "<em>" . __('Editing Now', 'my-calendar') . "</em>"; } else { $form_control = "{$begin}: <button class='delete_occurrence' type='button' data-value='{$result->occur_id}' aria-describedby='occur_date_{$result->occur_id}' />" . __('Delete', 'my-calendar') . "</button> "; $edit = "<a href='" . admin_url('admin.php?page=my-calendar') . "&mode=edit&event_id={$id}&date={$result->occur_id}' aria-describedby='occur_date_{$result->occur_id}'>" . __('Edit', 'my-calendar') . "</a>"; } $output .= "<li>{$form_control}{$edit}</li>"; } } else { $details = ''; foreach ($results as $result) { $event_id = $result->occur_id; $event = mc_get_event($event_id); $array = mc_create_tags($event); if (in_array($template, array('details', 'grid', 'list', 'mini')) || mc_key_exists($template)) { if (get_option('mc_use_' . $template . '_template') == 1) { $template = mc_get_template($template); } else { if (mc_key_exists($template)) { $template = mc_get_custom_template($template); } else { $details = my_calendar_draw_event($event, $type = "single", $event->event_begin, $event->event_time, ''); } } } $item = $list != '' ? jd_draw_template($array, $list) : ''; if ($details == '') { $details = $template != '' ? jd_draw_template($array, $template) : ''; } $output .= $item; if ($list == '') { break; } } $output = $details . $before . $output . $after; } return get_option('mc_process_shortcodes') == 'true' ? do_shortcode($output) : $output; }
function my_calendar_send_email($event) { $details = mc_create_tags($event); $headers = array(); // shift to boolean $send_email_option = get_option('mc_event_mail') == 'true' ? true : false; $send_email = apply_filters('mc_send_notification', $send_email_option, $details); if ($send_email == true) { add_filter('wp_mail_content_type', create_function('', 'return "text/html";')); } if (get_option('mc_event_mail') == 'true') { $to = apply_filters('mc_event_mail_to', get_option('mc_event_mail_to'), $details); $from = get_option('mc_event_mail_from') == '' ? get_bloginfo('admin_email') : get_option('mc_event_mail_from'); $from = apply_filters('mc_event_mail_from', $from, $details); $headers[] = "From: " . __('Event Notifications', 'my-calendar') . " <{$from}>"; $bcc = apply_filters('mc_event_mail_bcc', get_option('mc_event_mail_bcc'), $details); if ($bcc) { $bcc = explode(PHP_EOL, $bcc); foreach ($bcc as $b) { $b = trim($b); if (is_email($b)) { $headers[] = "Bcc: {$b}"; } } } $headers = apply_filters('mc_customize_email_headers', $headers, $event); $subject = jd_draw_template($details, get_option('mc_event_mail_subject')); $message = jd_draw_template($details, get_option('mc_event_mail_message')); wp_mail($to, $subject, $message, $headers); } if (get_option('mc_html_email') == 'true') { remove_filter('wp_mail_content_type', create_function('', 'return "text/html";')); } }
function mc_event_filter($title, $sep = ' | ', $seplocation = 'right') { if (isset($_GET['mc_id'])) { $id = (int) $_GET['mc_id']; $event = mc_get_event($id); $array = mc_create_tags($event); $left_sep = $seplocation != 'right' ? ' ' . $sep . ' ' : ''; $right_sep = $seplocation != 'right' ? '' : ' ' . $sep . ' '; $template = get_option('mc_event_title_template') != '' ? stripslashes(get_option('mc_event_title_template')) : "{$left_sep} {title} {$sep} {date} {$right_sep} "; return strip_tags(jd_draw_template($array, $template)); } else { return $title; } }
function my_calendar_todays_events($category = 'default', $template = 'default', $substitute = '', $author = 'all', $host = 'all') { $caching = apply_filters('mc_cache_enabled', false); $todays_cache = $caching ? get_transient('mc_todays_cache') : ''; if ($caching && is_array($todays_cache) && @$todays_cache[$category]) { return @$todays_cache[$category]; } global $default_template; $output = ''; $defaults = get_option('mc_widget_defaults'); $template = $template == 'default' ? $defaults['today']['template'] : $template; if ($template == '') { $template = "{$default_template}"; } $category = $category == 'default' ? $defaults['today']['category'] : $category; $no_event_text = $substitute == '' ? $defaults['today']['text'] : $substitute; $from = $to = date('Y-m-d', current_time('timestamp')); $events = my_calendar_events($from, $to, $category, '', '', 'upcoming', $author, $host); $today = isset($events[$from]) ? $events[$from] : false; $header = "<ul id='todays-events'>"; $footer = "</ul>"; $groups = $todays_events = array(); // quick loop through all events today to check for holidays if (is_array($today)) { foreach ($today as $e) { if ($e->category_private == 1 && !is_user_logged_in()) { } else { if (!in_array($e->event_group_id, $groups)) { $event_details = mc_create_tags($e); $ts = $e->ts_occur_begin; if (get_option('mc_event_approve') == 'true') { if ($e->event_approved != 0) { $todays_events[$ts][] = "<li>" . jd_draw_template($event_details, $template) . "</li>"; } } else { $todays_events[$ts][] = "<li>" . jd_draw_template($event_details, $template) . "</li>"; } } } } $todays_events = apply_filters('mc_event_today', $todays_events, $events); foreach ($todays_events as $k => $t) { foreach ($t as $now) { $output .= $now; } } if (count($events) != 0) { $return = $header . $output . $footer; } else { $return = stripcslashes($no_event_text); } $time = strtotime(date('Y-m-d H:m:s', current_time('timestamp'))) - strtotime(date('Y-m-d', current_time('timestamp'))); $time_remaining = 24 * 60 * 60 - $time; $todays_cache[$category] = $caching ? $return : ''; if ($caching) { set_transient('mc_todays_cache', $todays_cache, $time_remaining); } } else { $return = stripcslashes($no_event_text); } return $return; }
function mcs_notify_submitter($name, $email, $event_id, $action) { if (preg_match('/\\s/', $name)) { @(list($fname, $lname) = preg_split('/\\s+(?=[^\\s]+$)/', $name, 2)); } else { $fname = $name; $lname = ''; } $event = mc_get_event_core($event_id); $array = array('first_name' => $fname, 'last_name' => $lname, 'email' => $email, 'title' => $event->event_title, 'date' => $event->event_begin, 'time' => $event->event_time, 'description' => $event->event_desc, 'short' => $event->event_short, 'image' => $event->event_image, 'url' => $event->event_link, 'location' => $event->event_label, 'street' => $event->event_street, 'city' => $event->event_city, 'phone' => $event->event_phone, 'blogname' => get_option('blogname'), 'edit_link' => mcs_submit_url($event_id)); // if event is flagged as spam, don't send email notification. // filter allows you to disable email notifications for various custom reasons. $dont_send_email = apply_filters('mcs_dont_send_submitter_email', false, $event_id, $array); if ($event->event_approved == 1 && get_option('mcs_dont_send_submitter_email') == 'true') { $dont_send_email = true; } if ($event->event_flagged == 1 || $dont_send_email == true) { return; } else { $subject = get_option('mcs_confirmation_subject') == '' ? 'New event on {blogname}' : get_option('mcs_confirmation_subject'); $edit_subject = get_option('mcs_edit_confirmation_subject') == '' ? 'Edited event on {blogname}' : get_option('mcs_edit_confirmation_subject'); $message = get_option('mcs_confirmation') == '' ? 'Thanks for proposing a new event, {first_name} {last_name}! {title}, {date}, {time}' : get_option('mcs_confirmation'); if ($action = 'edit') { $subject = $edit_subject; } $subject = jd_draw_template($array, $subject); $message = jd_draw_template($array, $message); $blogname = get_option('blogname'); $from = get_option('mcs_from') == '' ? get_bloginfo('admin_email') : get_option('mcs_from'); if (get_option('mcs_html_email') == 'true') { add_filter('wp_mail_content_type', create_function('', 'return "text/html";')); } $headers = array("From: {$from}"); $headers = apply_filters('mcs_notify_admin_headers', $headers); $mail = wp_mail($email, $subject, $message, $headers); if (get_option('mcs_html_email') == 'true') { remove_filter('wp_mail_content_type', create_function('', 'return "text/html";')); } } }
function my_event_post($action, $data, $new_event) { if (!get_option('mcs_create_post') == 'true') { return; } // if the event save was successful. $options = get_option('mcs_event_post'); switch ($options['content']) { case 'event': $content = "[my_calendar_event event='{$new_event}' template='details' list='']"; break; case 'custom': $content = isset($_POST['mcs_custom_content']) ? $_POST['mcs_custom_content'] : ''; break; default: $content = $data['event_desc']; break; } if ($options['content'] == 'custom') { $event = mc_get_first_event($new_event); $details = mc_create_tags($event); $content = jd_draw_template($details, apply_filters('mcs_new_post_template', $content, $event)); } switch ($options['title']) { case 'custom': $title = sprintf($options['custom_title'], $data['event_title']); break; default: $title = $data['event_title']; } switch ($options['author']) { case 'host': $auth = $data['event_host']; break; default: $auth = $data['event_author']; } switch ($options['excerpt']) { case 'event_short': $excerpt = $data['event_short']; break; case 'auto': $excerpt = wp_trim_words($data['event_desc']); break; case 'custom': $excerpt = isset($_POST['mcs_custom_content']) ? $_POST['mcs_custom_content'] : ''; break; default: $excerpt = $data['event_short']; } if ($options['excerpt'] == 'custom') { $event = mc_get_first_event($new_event); $details = mc_create_tags($event); $excerpt = jd_draw_template($details, apply_filters('mcs_new_post_template', $excerpt, $event)); } $status = isset($options['status']) ? $options['status'] : 'publish'; switch ($options['timestamp']) { case 'event': $date = strtotime($data['event_begin'] . ' ' . $data['event_time']); break; case 'custom': if ($options['custom_time'] < 0) { $date = strtotime($data['event_begin'] . ' ' . $data['event_time']) - intval($options['custom_time']); } else { $date = current_time('timestamp') + intval($options['custom_time']); } break; default: $date = current_time('timestamp'); } $type = isset($options['post_type']) ? $options['post_type'] : 'post'; if ($action == 'add' && !(isset($_POST['event_source']) && $_POST['event_source'] == 'post')) { $my_post = array('post_title' => $title, 'post_content' => $content, 'post_excerpt' => $excerpt, 'post_status' => $status, 'post_author' => $auth, 'post_name' => sanitize_title($title), 'post_date' => date('Y-m-d H:i:s', $date), 'post_type' => $type); $post_id = wp_insert_post($my_post); $attachment_id = isset($_POST['event_image_id']) && is_numeric($_POST['event_image_id']) ? $_POST['event_image_id'] : false; if ($attachment_id) { set_post_thumbnail($post_id, $attachment_id); } $category = mc_get_category_detail($data['event_category'], 'category_name'); $taxonomy = 'category'; wp_set_post_tags($post_id, $category); wp_set_post_terms($post_id, $category, $taxonomy); add_post_meta($post_id, '_mc_event_id', $new_event); $event = mc_get_first_event($new_event); $event_id = $event->event_post; add_post_meta($event_id, '_mc_related_post', $post_id); do_action('mcp_post_published', $post_id, $event); wp_publish_post($post_id); } }
function my_calendar_todays_events($category = 'default', $template = 'default', $substitute = '', $author = 'all', $host = 'all', $date = false, $site = false) { if ($site) { $site = $site == 'global' ? BLOG_ID_CURRENT_SITE : $site; switch_to_blog($site); } $caching = apply_filters('mc_cache_enabled', false); $todays_cache = $caching ? get_transient('mc_todays_cache') : ''; if ($caching && is_array($todays_cache) && @$todays_cache[$category]) { return @$todays_cache[$category]; } $args = array('category' => $category, 'template' => $template, 'substitute' => $substitute, 'author' => $author, 'host' => $host, 'date' => $date); $hash = md5(implode(',', $args)); global $default_template; $output = ''; // allow reference by file to external template. if ($template != '' && mc_file_exists(sanitize_file_name($template))) { $template = @file_get_contents(mc_get_file(sanitize_file_name($template))); } $defaults = get_option('mc_widget_defaults'); $template = $template == 'default' ? $defaults['today']['template'] : $template; $template = $template == '' ? $default_template : $template; if (mc_key_exists($template)) { $template = mc_get_custom_template($template); } $category = $category == 'default' ? $defaults['today']['category'] : $category; $no_event_text = $substitute == '' ? $defaults['today']['text'] : $substitute; if ($date) { $from = $to = date('Y-m-d', strtotime($date)); } else { $from = $to = date('Y-m-d', current_time('timestamp')); } $events = my_calendar_events($from, $to, $category, '', '', 'upcoming', $author, $host, '', $site); $today = isset($events[$from]) ? $events[$from] : false; $header = "<ul id='todays-events-{$hash}' class='todays-events'>"; $footer = "</ul>"; $groups = $todays_events = array(); // quick loop through all events today to check for holidays if (is_array($today)) { foreach ($today as $e) { if ($e->category_private == 1 && !is_user_logged_in()) { } else { if (!in_array($e->event_group_id, $groups)) { $event_details = mc_create_tags($e); $ts = $e->ts_occur_begin; $end = $e->ts_occur_end; $now = current_time('timestamp'); $category = 'mc_' . sanitize_title($e->category_name); if ($ts < $now && $end > $now) { $class = 'on-now'; } else { if ($now < $ts) { $class = 'future-event'; } else { if ($now > $ts) { $class = 'past-event'; } } } $prepend = apply_filters('mc_todays_events_before', "<li class='{$class} {$category}'>", $class, $category); $append = apply_filters('mc_todays_events_after', "</li>"); if (get_option('mc_event_approve') == 'true') { if ($e->event_approved != 0) { $todays_events[$ts][] = $prepend . jd_draw_template($event_details, $template) . $append; } } else { $todays_events[$ts][] = $prepend . jd_draw_template($event_details, $template) . $append; } } } } $todays_events = apply_filters('mc_event_today', $todays_events, $events); foreach ($todays_events as $k => $t) { foreach ($t as $now) { $output .= $now; } } if (count($events) != 0) { $return = apply_filters('mc_todays_events_header', $header) . $output . apply_filters('mc_todays_events_footer', $footer); } else { $return = stripcslashes($no_event_text); } $time = strtotime(date('Y-m-d H:m:s', current_time('timestamp'))) - strtotime(date('Y-m-d', current_time('timestamp'))); $time_remaining = 24 * 60 * 60 - $time; $todays_cache[$category] = $caching ? $return : ''; if ($caching) { set_transient('mc_todays_cache', $todays_cache, $time_remaining); } } else { $return = stripcslashes($no_event_text); } if ($site) { restore_current_blog(); } return get_option('mc_process_shortcodes') == 'true' ? do_shortcode($return) : $return; }
function mc_instance_list($id, $occur = false, $template = '<h3>{title}</h3>{description}', $list = '<li>{date}, {time}</li>', $before = "<ul>", $after = "</ul>") { global $wpdb; $id = (int) $id; $output = ''; $sql = "SELECT * FROM " . my_calendar_event_table() . " WHERE occur_event_id={$id}"; $results = $wpdb->get_results($sql); if (is_array($results) && is_admin()) { foreach ($results as $result) { if ($result->occur_id == $occur) { $form_control = ''; $current = "<em>" . __('Editing: ', 'my-calendar') . "</em>"; $end = ''; } else { $form_control = "<input type='checkbox' name='delete_occurrences[]' id='delete_{$result->occur_id}' value='{$result->occur_id}' aria-labelledby='occur_label occur_date' /> <label id='occur_label' for='delete_{$result->occur_id}'>Delete</label> "; $current = "<a href='" . admin_url('admin.php?page=my-calendar') . "&mode=edit&event_id={$id}&date={$result->occur_id}'>"; $end = "</a>"; } $begin = "<span id='occur_date'>" . date_i18n(get_option('mc_date_format'), strtotime($result->occur_begin)) . ', ' . date(get_option('mc_time_format'), strtotime($result->occur_begin)) . "</span>"; $output .= "<li>{$form_control}{$current}{$begin}{$end}</li>"; } } else { $details = ''; foreach ($results as $result) { $event_id = $result->occur_id; $event = mc_get_event($event_id); $array = mc_create_tags($event); if (in_array($template, array('details', 'grid', 'list', 'mini'))) { if (get_option('mc_use_' . $template . '_template') == 1) { $template = mc_get_template($template); } else { $template = false; $details = my_calendar_draw_event($event, $type = "single", $event->event_begin, $event->event_time, ''); } } $item = $list != '' ? jd_draw_template($array, $list) : ''; if ($details == '') { $details = $template != '' ? jd_draw_template($array, $template) : ''; } $output .= $item; } $output = $details . $before . $output . $after; } return $output; }