function mc_category_select($data = false, $option = true) { global $wpdb; $mcdb = $wpdb; if (get_option('mc_remote') == 'true' && function_exists('mc_remote_db')) { $mcdb = mc_remote_db(); } // Grab all the categories and list them $list = $default = ''; $sql = "SELECT * FROM " . my_calendar_categories_table() . " ORDER BY category_name ASC"; $cats = $mcdb->get_results($sql); if (empty($cats)) { // need to have categories. Try to create again. $insert = "INSERT INTO " . my_calendar_categories_table() . " SET category_id=1, category_name='General', category_color='#ffffcc', category_icon='event.png'"; $mcdb->query($insert); $cats = $mcdb->get_results($sql); } if (!empty($cats)) { foreach ($cats as $cat) { $c = '<option value="' . $cat->category_id . '"'; if (!empty($data)) { if (!is_object($data)) { $category = $data; } else { $category = $data->event_category; } if ($category == $cat->category_id) { $c .= ' selected="selected"'; } } $c .= '>' . stripslashes($cat->category_name) . '</option>'; if ($cat->category_id != get_option('mc_default_category')) { $list .= $c; } else { $default = $c; } } } else { $category_url = admin_url('admin.php?page=my-calendar-categories'); echo "<div class='updated error'><p>" . sprintf(__('You do not have any categories created. Please <a href="%s">create at least one category!</a>', 'my-calendar'), $category_url) . "</p></div>"; } if (!$option) { $default = get_option('mc_default_category') ? get_option('mc_default_category') : 1; return is_object($data) ? $data->event_category : $default; } return $default . $list; }
function mc_transition_db() { // copy to post types. Don't do this if referencing remote sites. if (get_option('mc_remote') != 'true') { global $wpdb; $results = $wpdb->get_results('SELECT * FROM ' . my_calendar_locations_table(), ARRAY_A); $locations = array(); foreach ($results as $result) { $location_id = $result['location_id']; unset($result['location_id']); $hash = md5(serialize($result)); $locations[$location_id] = $result; } $results = $wpdb->get_results('SELECT * FROM ' . my_calendar_categories_table()); foreach ($results as $category) { $term = wp_insert_term($category->category_name, 'mc-event-category'); if (!is_wp_error($term)) { $term_id = $term['term_id']; mc_update_category('category_term', $term_id, $category->category_id); } else { if (isset($term->error_data['term_exists'])) { $term_id = $term->error_data['term_exists']; mc_update_category('category_term', $term_id, $category->category_id); } } } $results = $wpdb->get_results('SELECT * FROM ' . my_calendar_table(), ARRAY_A); foreach ($results as $event) { $post_id = mc_create_event_post($event, $event['event_id']); mc_update_event('event_post', $post_id, $event['event_id']); // false if not found, id if found. $location = mc_check_location_table($event, $locations); if ($location) { mc_update_event('event_location', $location, $event['event_id']); } else { if ($event['event_label'] == '' && $event['event_street'] == '' && $event['event_url'] == '' && $event['event_city'] == '' && $event['event_state'] == '' && $event['event_country'] == '') { // don't insert the row if location does not have basic data. } else { $add = array('location_label' => $event['event_label'], 'location_street' => $event['event_street'], 'location_street2' => $event['event_street2'], 'location_city' => $event['event_city'], 'location_state' => $event['event_state'], 'location_postcode' => $event['event_postcode'], 'location_region' => $event['event_region'], 'location_country' => $event['event_country'], 'location_url' => $event['event_url'], 'location_longitude' => $event['event_longitude'], 'location_latitude' => $event['event_latitude'], 'location_zoom' => $event['event_zoom'], 'location_phone' => $event['event_phone'], 'location_access' => ''); mc_insert_location($add); } // could add delete routine to allow user to select what location to use for events using a given location. } } } }
function mc_list_groups() { global $wpdb; $mcdb = $wpdb; $sortby = isset($_GET['sort']) ? (int) $_GET['sort'] : get_option('mc_default_sort'); if (isset($_GET['order'])) { $sortdir = isset($_GET['order']) && $_GET['order'] == 'ASC' ? 'ASC' : 'default'; } else { $sortdir = 'default'; } 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'; break; case 5: $sortbyvalue = 'event_author'; break; case 6: $sortbyvalue = 'event_category'; break; case 7: $sortbyvalue = 'event_label'; break; case 8: $sortbyvalue = 'group_id'; break; default: $sortbyvalue = 'event_begin'; } } $sortbydirection = $sortdir == 'default' ? 'DESC' : $sortdir; $sorting = $sortbydirection == 'DESC' ? "&order=ASC" : ''; $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'); } $limit = isset($_GET['limit']) ? $_GET['limit'] : 'all'; switch ($limit) { case 'all': $limit = ''; break; case 'grouped': $limit = 'WHERE event_group_id <> 0'; break; case 'ungrouped': $limit = 'WHERE event_group_id = 0'; break; default: $limit = ''; } $events = $mcdb->get_results("SELECT SQL_CALC_FOUND_ROWS * 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]; ?> <div class='inside'><?php if (get_option('mc_event_approve') == 'true') { ?> <ul class="links"> <li><a <?php echo isset($_GET['limit']) && $_GET['limit'] == 'groupeed' ? ' class="active-link"' : ''; ?> href="<?php echo admin_url('admin.php?page=my-calendar-groups&limit=grouped#my-calendar-admin-table'); ?> "><?php _e('Grouped Events', 'my-calendar'); ?> </a></li> <li><a <?php echo isset($_GET['limit']) && $_GET['limit'] == 'ungrouped' ? ' class="active-link"' : ''; ?> href="<?php echo admin_url('admin.php?page=my-calendar-groups&limit=ungrouped#my-calendar-admin-table'); ?> "><?php _e('Ungrouped Events', '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-groups#my-calendar-admin-table'); ?> "><?php _e('All', 'my-calendar'); ?> </a></li> </ul> <?php } ?> <p><?php _e('Check a set of events to group them for mass editing.', 'my-calendar'); ?> </p><?php $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 admin_url("admin.php?page=my-calendar-groups"); ?> " method="post"> <div> <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce('my-calendar-nonce'); ?> " /> <input type="hidden" name="event_action" value="group" /> </div> <p style="position:relative;display:inline-block;"> <input type="submit" class="button-primary group" value="<?php _e('Group checked events for mass editing', 'my-calendar'); ?> " /> </p> </div> <table class="widefat wp-list-table" id="my-calendar-admin-table"> <thead> <tr> <th scope="col" style="width: 50px;"><a href="<?php echo admin_url("admin.php?page=my-calendar-groups&sort=1{$sorting}"); ?> "><?php _e('ID', 'my-calendar'); ?> </a></th> <th scope="col"><a href="<?php echo admin_url("admin.php?page=my-calendar-groups&sort=8{$sorting}"); ?> "><?php _e('Group', 'my-calendar'); ?> </a></th> <th scope="col"><a href="<?php echo admin_url("admin.php?page=my-calendar-groups&sort=2{$sorting}"); ?> "><?php _e('Title', 'my-calendar'); ?> </a></th> <th scope="col"><a href="<?php echo admin_url("admin.php?page=my-calendar-groups&sort=7{$sorting}"); ?> "><?php _e('Where', 'my-calendar'); ?> </a></th> <th scope="col"><a href="<?php echo admin_url("admin.php?page=my-calendar-groups&sort=4{$sorting}"); ?> "><?php _e('Starts', 'my-calendar'); ?> </a></th> <th scope="col"><?php _e('Recurs', 'my-calendar'); ?> </th> <th scope="col"><a href="<?php echo admin_url("admin.php?page=my-calendar-groups&sort=5{$sorting}"); ?> "><?php _e('Author', 'my-calendar'); ?> </a></th> <th scope="col"><a href="<?php echo admin_url("admin.php?page=my-calendar-groups&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 ($events as $event) { $class = $class == 'alternate' ? '' : 'alternate'; $spam = $event->event_flagged == 1 ? ' spam' : ''; $spam_label = $event->event_flagged == 1 ? '<strong>Possible spam:</strong> ' : ''; $author = $event->event_author != 0 ? get_userdata($event->event_author) : 'Public Submitter'; if ($event->event_link != '') { $title = "<a href='" . esc_attr($event->event_link) . "'>{$event->event_title}</a>"; } else { $title = $event->event_title; } ?> <tr class="<?php echo $class; echo $spam; ?> " id="event<?php echo $event->event_id; ?> "> <th scope="row"><input type="checkbox" value="<?php echo $event->event_id; ?> " name="group[]" id="mc<?php echo $event->event_id; ?> " <?php echo mc_event_is_grouped($event->event_group_id) ? ' disabled="disabled"' : ''; ?> /> <label for="mc<?php echo $event->event_id; ?> "><?php echo $event->event_id; ?> </label></th> <th scope="row"><?php echo $event->event_group_id == 0 ? '-' : $event->event_group_id; ?> </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_author)) { ?> <a href="<?php echo admin_url("admin.php?page=my-calendar&mode=edit&event_id={$event->event_id}"); ?> " class='edit'> <?php } echo $spam_label; echo stripslashes($title); ?> <?php if (mc_can_edit_event($event->event_author)) { echo "</a>"; } ?> </strong> <div class='row-actions' style="visibility:visible;"> <?php if (mc_can_edit_event($event->event_author)) { ?> <a href="<?php echo admin_url("admin.php?page=my-calendar&mode=edit&event_id={$event->event_id}"); ?> " class='edit'><?php _e('Edit Event', 'my-calendar'); ?> </a> | <?php if (mc_event_is_grouped($event->event_group_id)) { ?> <a href="<?php echo admin_url("admin.php?page=my-calendar-groups&mode=edit&event_id={$event->event_id}&group_id={$event->event_group_id}"); ?> " class='edit group'><?php _e('Edit Group', 'my-calendar'); ?> </a> <?php } else { ?> <em><?php _e('Ungrouped', 'my-calendar'); ?> </em> <?php } } else { _e("Not editable.", 'my-calendar'); } ?> </div> </td> <td><?php echo stripslashes($event->event_label); ?> </td> <?php if ($event->event_time != "00:00:00") { $eventTime = date_i18n(get_option('mc_time_format'), strtotime($event->event_time)); } else { $eventTime = get_option('mc_notime_text'); } ?> <td><?php echo "{$event->event_begin}<br />{$eventTime}"; ?> </td> <td> <?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 if ($recur == 'S') { _e('Never', 'my-calendar'); } else { if ($recur == 'D') { _e('Daily', 'my-calendar'); } else { if ($recur == 'E') { _e('Weekdays', 'my-calendar'); } else { if ($recur == 'W') { _e('Weekly', 'my-calendar'); } else { if ($recur == 'B') { _e('Bi-Weekly', 'my-calendar'); } else { if ($recur == 'M') { _e('Monthly (by date)', 'my-calendar'); } else { if ($recur == 'U') { _e('Monthly (by day)', 'my-calendar'); } else { if ($recur == 'Y') { _e('Yearly', 'my-calendar'); } } } } } } } } ?> –<?php if ($recur == 'S') { _e('N/A', 'my-calendar'); } else { if (mc_event_repeats_forever($recur, $event->event_repeats)) { _e('Forever', 'my-calendar'); } else { if ($event->event_repeats > 0) { printf(__('%d Times', 'my-calendar'), $event->event_repeats); } } } ?> </td> <td><?php echo is_object($author) ? $author->display_name : $author; ?> </td> <?php $this_category = $event->event_category; foreach ($categories as $key => $value) { if ($value->category_id == $this_category) { $this_cat = $categories[$key]; } } ?> <td><div class="category-color" style="background-color:<?php echo strpos($this_cat->category_color, '#') !== 0 ? '#' : ''; echo $this_cat->category_color; ?> ;"> </div> <?php echo stripslashes($this_cat->category_name); ?> </td> <?php unset($this_cat); ?> </tr><?php } ?> </table> <div class="inside"> <p> <input type="submit" class="button-secondary group" value="<?php _e('Group checked events for mass editing', 'my-calendar'); ?> " /> </p> </div> </form><?php } else { ?> <div class="inside"><p><?php _e("There are no events in the database!", 'my-calendar'); ?> </p></div><?php } }
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_import() { if (get_option('ko_calendar_imported') != 'true') { global $wpdb; $mcdb = $wpdb; define('KO_CALENDAR_TABLE', $mcdb->prefix . 'calendar'); define('KO_CALENDAR_CATS', $mcdb->prefix . 'calendar_categories'); $events = $mcdb->get_results("SELECT * FROM " . KO_CALENDAR_TABLE, 'ARRAY_A'); $event_ids = array(); foreach ($events as $key) { $endtime = $key['event_time'] == '00:00:00' ? '00:00:00' : date('H:i:s', strtotime("{$key['event_time']} +1 hour")); $data = array('event_title' => $key['event_title'], 'event_desc' => $key['event_desc'], 'event_begin' => $key['event_begin'], 'event_end' => $key['event_end'], 'event_time' => $key['event_time'], 'event_endtime' => $endtime, 'event_recur' => $key['event_recur'], 'event_repeats' => $key['event_repeats'], 'event_author' => $key['event_author'], 'event_category' => $key['event_category'], 'event_hide_end' => 1, 'event_link' => isset($key['event_link']) ? $key['event_link'] : ''); $format = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%s'); $update = $mcdb->insert(my_calendar_table(), $data, $format); $events_results = $update ? true : false; $event_ids[] = $mcdb->insert_id; } foreach ($event_ids as $value) { // propagate event instances. $sql = "SELECT event_begin, event_time, event_end, event_endtime FROM " . my_calendar_table() . " WHERE event_id = {$value}"; $event = $wpdb->get_results($sql); $event = $event[0]; $dates = array('event_begin' => $event->event_begin, 'event_end' => $event->event_end, 'event_time' => $event->event_time, 'event_endtime' => $event->event_endtime); $event = mc_increment_event($value, $dates); } $cats = $mcdb->get_results("SELECT * FROM " . KO_CALENDAR_CATS, 'ARRAY_A'); $catsql = ""; foreach ($cats as $key) { $name = esc_sql($key['category_name']); $color = esc_sql($key['category_colour']); $id = (int) $key['category_id']; $catsql = "INSERT INTO " . my_calendar_categories_table() . " SET \n\t\t\t\tcategory_id='" . $id . "',\n\t\t\t\tcategory_name='" . $name . "', \n\t\t\t\tcategory_color='" . $color . "' \n\t\t\t\tON DUPLICATE KEY UPDATE \n\t\t\t\tcategory_name='" . $name . "', \n\t\t\t\tcategory_color='" . $color . "';\n\t\t\t\t"; $cats_results = $mcdb->query($catsql); } $message = $cats_results !== false ? __('Categories imported successfully.', 'my-calendar') : __('Categories not imported.', 'my-calendar'); $e_message = $events_results !== false ? __('Events imported successfully.', 'my-calendar') : __('Events not imported.', 'my-calendar'); $return = "<div id='message' class='updated fade'><ul><li>{$message}</li><li>{$e_message}</li></ul></div>"; echo $return; if ($cats_results !== false && $events_results !== false) { update_option('ko_calendar_imported', 'true'); } } }
function mcs_insert_category($string) { global $wpdb; $mcdb = $wpdb; $cat_id = false; $formats = array('%s', '%s', '%s', '%d', '%d'); $term = wp_insert_term($string, 'mc-event-category'); if (!is_wp_error($term)) { $term = $term['term_id']; } else { $term = false; } $add = array('category_name' => $string, 'category_color' => '#ffffcc', 'category_icon' => 'event.png', 'category_private' => 0, 'category_term' => $term); // actions and filters $results = $mcdb->insert(my_calendar_categories_table(), $add, $formats); $cat_ID = $mcdb->insert_id; return $cat_ID; }
function mc_manage_categories() { global $wpdb; $mcdb = $wpdb; ?> <h2><?php _e('Manage Categories', 'my-calendar'); ?> </h2><?php $co = !isset($_GET['co']) ? 1 : (int) $_GET['co']; switch ($co) { case 1: $cat_order = 'category_id'; break; case 2: $cat_order = 'category_name'; break; default: $cat_order = 'category_id'; } // We pull the categories from the database $categories = $mcdb->get_results("SELECT * FROM " . my_calendar_categories_table() . " ORDER BY {$cat_order} ASC"); if (!empty($categories)) { ?> <table class="widefat page fixed mc-categories" id="my-calendar-admin-table"> <thead> <tr> <th scope="col"><?php echo $co == 2 ? "<a href='" . admin_url("admin.php?page=my-calendar-categories&co=1") . "'>" : ''; _e('ID', 'my-calendar'); echo $co == 2 ? '</a>' : ''; ?> </th> <th scope="col"><?php echo $co == 1 ? "<a href='" . admin_url("admin.php?page=my-calendar-categories&co=2") . "'>" : ''; _e('Category Name', 'my-calendar'); echo $co == 1 ? '</a>' : ''; ?> </th> <th scope="col"><?php _e('Color/Icon', 'my-calendar'); ?> </th> <th scope="col"><?php _e('Private', 'my-calendar'); ?> </th> <th scope="col"><?php _e('Edit', 'my-calendar'); ?> </th> <th scope="col"><?php _e('Delete', 'my-calendar'); ?> </th> </tr> </thead> <?php $class = ''; foreach ($categories as $cat) { $class = $class == 'alternate' ? '' : 'alternate'; $icon_src = mc_file_exists($cat->category_icon) ? mc_get_file($cat->category_icon, 'url') : plugins_url('my-calendar/images/icons/' . $cat->category_icon); $background = strpos($cat->category_color, '#') !== 0 ? '#' : '' . $cat->category_color; $foreground = mc_inverse_color($background); ?> <tr class="<?php echo $class; ?> "> <th scope="row"><?php echo $cat->category_id; ?> </th> <td><?php echo stripslashes($cat->category_name); if ($cat->category_id == get_option('mc_default_category')) { echo ' ' . __('(Default)'); } if ($cat->category_id == get_option('mc_skip_holidays_category')) { echo ' ' . __('(Holiday)'); } ?> </td> <td style="background-color:<?php echo $background; ?> ;color: <?php echo $foreground; ?> "><img src="<?php echo $icon_src; ?> " alt=""/> <?php echo $background; ?> </td> <td><?php echo $cat->category_private == 1 ? __('Yes', 'my-calendar') : __('No', 'my-calendar'); ?> </td> <td><a href="<?php echo admin_url("admin.php?page=my-calendar-categories&mode=edit&category_id={$cat->category_id}"); ?> " class='edit'><?php _e('Edit', 'my-calendar'); ?> </a></td><?php if ($cat->category_id == 1) { echo '<td>' . __('N/A', 'my-calendar') . '</td>'; } else { ?> <td><a href="<?php echo admin_url("admin.php?page=my-calendar-categories&mode=delete&category_id={$cat->category_id}"); ?> " class="delete" onclick="return confirm('<?php _e('Are you sure you want to delete this category?', 'my-calendar'); ?> ')"><?php _e('Delete', 'my-calendar'); ?> </a> </td><?php } ?> </tr><?php } ?> </table><?php } else { echo '<p>' . __('There are no categories in the database - or something has gone wrong!', 'my-calendar') . '</p>'; } }
function mc_select_category($category, $type = 'event', $group = 'events') { $category = urldecode($category); global $wpdb; $mcdb = $wpdb; if (get_option('mc_remote') == 'true' && function_exists('mc_remote_db')) { $mcdb = mc_remote_db(); } $select_category = ''; $data = $group == 'category' ? 'category_id' : 'event_category'; if (preg_match('/^all$|^all,|,all$|,all,/i', $category) > 0) { return ''; } else { if (strpos($category, "|") || strpos($category, ",")) { if (strpos($category, "|")) { $categories = explode("|", $category); } else { $categories = explode(",", $category); } $numcat = count($categories); $i = 1; foreach ($categories as $key) { if (is_numeric($key)) { $key = (int) $key; if ($i == 1) { $select_category .= $type == 'all' ? " WHERE (" : ' ('; } $select_category .= " {$data} = {$key}"; if ($i < $numcat) { $select_category .= " OR "; } else { if ($i == $numcat) { $select_category .= $type == 'all' ? ") " : ' ) AND'; } } $i++; } else { $key = esc_sql(trim($key)); $cat = $mcdb->get_row("SELECT category_id FROM " . my_calendar_categories_table() . " WHERE category_name = '{$key}'"); if ($cat) { $category_id = $cat->category_id; if ($i == 1) { $select_category .= $type == 'all' ? " WHERE (" : ' ('; } $select_category .= " {$data} = {$category_id}"; if ($i < $numcat) { $select_category .= " OR "; } else { if ($i == $numcat) { $select_category .= $type == 'all' ? ") " : ' ) AND'; } } $i++; } else { return ''; } } } } else { if (is_numeric($category)) { $select_category = $type == 'all' ? " WHERE {$data} = {$category}" : " event_category = {$category} AND"; } else { $cat = $mcdb->get_row("SELECT category_id FROM " . my_calendar_categories_table() . " WHERE category_name = '{$category}'"); if (is_object($cat)) { $category_id = $cat->category_id; $select_category = $type == 'all' ? " WHERE {$data} = {$category_id}" : " {$data} = {$category_id} AND"; } else { $select_category = ''; } } } return $select_category; } }
function my_calendar_categories_list($show = 'list', $context = 'public', $group = 'single') { global $wpdb; $mcdb = $wpdb; if (get_option('mc_remote') == 'true' && function_exists('mc_remote_db')) { $mcdb = mc_remote_db(); } if (isset($_GET['mc_id'])) { return ''; } $output = ''; $current_url = mc_get_current_url(); $name = $context == 'public' ? 'mcat' : 'category'; $admin_fields = $context == 'public' ? ' name="' . $name . '"' : ' multiple="multiple" size="5" name="' . $name . '[]" '; $admin_label = $context == 'public' ? '' : __('(select to include)', 'my-calendar'); $form = $group == 'single' ? "<form action='" . $current_url . "' method='get'>\r\n\t\t\t\t<div>" : ''; if ($group == 'single') { $qsa = array(); if (isset($_SERVER['QUERY_STRING'])) { parse_str($_SERVER['QUERY_STRING'], $qsa); } if (!isset($_GET['cid'])) { $form .= '<input type="hidden" name="cid" value="all" />'; } foreach ($qsa as $name => $argument) { $name = esc_attr(strip_tags($name)); $argument = esc_attr(strip_tags($argument)); if ($name != 'mcat') { $form .= ' <input type="hidden" name="' . $name . '" value="' . $argument . '" />' . "\n"; } } } $form .= $show == 'list' || $group == 'group' ? '' : ' </div><p>'; $public_form = $context == 'public' ? $form : ''; $categories = $mcdb->get_results("SELECT * FROM " . my_calendar_categories_table() . " ORDER BY category_id ASC"); if (!empty($categories) && count($categories) >= 1) { $output = "<div id='mc_categories'>\n"; $url = mc_build_url(array('mcat' => 'all'), array()); $output .= $show == 'list' ? "\r\n\t\t<ul>\r\n\t\t\t<li><a href='{$url}'>" . __('All Categories', 'my-calendar') . "</a></li>" : $public_form . ' <label for="category">' . __('Categories', 'my-calendar') . ' ' . $admin_label . '</label> <select' . $admin_fields . ' id="category"> <option value="all" selected="selected">' . __('All Categories', 'my-calendar') . '</option>' . "\n"; foreach ($categories as $category) { $category_name = mc_kses_post(stripcslashes($category->category_name)); $mcat = empty($_GET['mcat']) ? '' : (int) $_GET['mcat']; if ($show == 'list') { $this_url = mc_build_url(array('mcat' => $category->category_id), array()); $selected = $category->category_id == $mcat ? ' class="selected"' : ''; $output .= "\t\t\t<li{$selected}><a rel='nofollow' href='{$this_url}'>{$category_name}</a></li>"; } else { $selected = $category->category_id == $mcat ? ' selected="selected"' : ''; $output .= "\t\t\t<option{$selected} value='{$category->category_id}'>{$category_name}</option>\n"; } } $output .= $show == 'list' ? '</ul>' : '</select>'; if ($context != 'admin' && $show != 'list') { if ($group == 'single') { $output .= "<input type='submit' value=" . __('Submit', 'my-calendar') . " /></p></form>"; } } $output .= "\n</div>"; } $output = apply_filters('mc_category_selector', $output, $categories); return $output; }
function my_calendar_grab_events($from, $to, $category = null, $ltype = '', $lvalue = '', $source = 'calendar', $author = null, $host = null, $holidays = null, $search = '', $site = false) { global $wpdb; $mcdb = $wpdb; if (get_option('mc_remote') == 'true' && function_exists('mc_remote_db')) { $mcdb = mc_remote_db(); } if ($holidays === null) { if (isset($_GET['mcat'])) { $ccategory = $_GET['mcat']; } else { $ccategory = $category; } } else { $ccategory = $category; } if (isset($_GET['ltype'])) { $cltype = $_GET['ltype']; } else { $cltype = $ltype; } if (isset($_GET['loc'])) { $clvalue = $_GET['loc']; } else { $clvalue = $lvalue; } if (isset($_GET['mc_auth'])) { $clauth = $_GET['mc_auth']; } else { $clauth = $author; } if (isset($_GET['mc_host'])) { $clhost = $_GET['mc_host']; } else { $clhost = $host; } if ($ccategory == '') { $ccategory = 'all'; } if ($clvalue == '') { $clvalue = 'all'; } if ($cltype == '') { $cltype = 'all'; } if ($clvalue == 'all') { $cltype = 'all'; } if ($clauth == '') { $clauth = 'all'; } if ($clhost == '') { $clhost = 'all'; } if (!mc_checkdate($from) || !mc_checkdate($to)) { return array(); } // not valid dates $caching = apply_filters('mc_caching_enabled', false, $ccategory, $ltype, $lvalue, $author, $host); $hash = md5($from . $to . $ccategory . $cltype . $clvalue . $clauth . $clhost); if ($source != 'upcoming') { // no caching on upcoming events by days widgets or lists if ($caching) { $output = mc_check_cache($ccategory, $cltype, $clvalue, $clauth, $clhost, $hash); if ($output && $output != 'empty') { return $output; } if ($output == 'empty') { return array(); } } } $select_category = $ccategory != 'all' ? mc_select_category($ccategory) : ''; $select_author = $clauth != 'all' ? mc_select_author($clauth) : ''; $select_host = $clhost != 'all' ? mc_select_host($clhost) : ''; $select_location = mc_limit_string('grab', $cltype, $clvalue); if ($caching && $source != 'upcoming') { $select_category = ''; $select_location = ''; $select_author = ''; $select_host = ''; } // if caching, then need all categories/locations in cache. UNLESS this is an upcoming events list $arr_events = array(); $limit_string = "event_flagged <> 1 AND event_approved = 1"; $search = mc_prepare_search_query($search); $event_query = "SELECT *, UNIX_TIMESTAMP(occur_begin) AS ts_occur_begin, UNIX_TIMESTAMP(occur_end) AS ts_occur_end\r\n\t\t\t\t\tFROM " . my_calendar_event_table($site) . " \r\n\t\t\t\t\tJOIN " . my_calendar_table($site) . "\r\n\t\t\t\t\tON (event_id=occur_event_id) \t\t\t\t\t\r\n\t\t\t\t\tJOIN " . my_calendar_categories_table($site) . " \r\n\t\t\t\t\tON (event_category=category_id) \r\n\t\t\t\t\tWHERE {$select_category} {$select_location} {$select_author} {$select_host} {$limit_string} {$search} \r\n\t\t\t\t\tAND ( DATE(occur_begin) BETWEEN '{$from} 00:00:00' AND '{$to} 23:59:59' \r\n\t\t\t\t\t\tOR DATE(occur_end) BETWEEN '{$from} 00:00:00' AND '{$to} 23:59:59' \r\n\t\t\t\t\t\tOR ( DATE('{$from}') BETWEEN DATE(occur_begin) AND DATE(occur_end) ) \r\n\t\t\t\t\t\tOR ( DATE('{$to}') BETWEEN DATE(occur_begin) AND DATE(occur_end) ) ) \r\n\t\t\t\t\tORDER BY " . apply_filters('mc_primary_sort', 'occur_begin') . ", " . apply_filters('mc_secondary_sort', 'event_title ASC'); $events = $mcdb->get_results($event_query); if (!empty($events)) { foreach (array_keys($events) as $key) { $event =& $events[$key]; $event->site_id = $site; $arr_events[] = $event; } } if ($source != 'upcoming' && $caching) { $new_cache = mc_create_cache($arr_events, $hash, $category, $ltype, $lvalue, $author, $host); if ($new_cache) { $output = mc_check_cache($ccategory, $cltype, $clvalue, $clauth, $clhost, $hash); return $output; } else { // need to clean cache if the cache is maxed. return mc_clean_cache($arr_events, $ccategory, $cltype, $clvalue, $clauth, $clhost); } } else { return $arr_events; } }