function mc_add_inner_box() { global $post; $event_id = get_post_meta($post->ID, '_mc_event_id', true); if ($event_id) { $url = admin_url('admin.php?page=my-calendar&mode=edit&event_id=' . $event_id); $event = mc_get_event_core($event_id); $content = "<p><strong>" . mc_kses_post($event->event_title) . '</strong><br />' . $event->event_begin . ' @ ' . $event->event_time . "</p>"; if ($event->event_label != '') { $content .= "<p>" . sprintf(__('<strong>Location:</strong> %s', 'my-calendar'), mc_kses_post($event->event_label)) . "</p>"; } $content .= "<p>" . sprintf(__('<a href="%s">Edit event</a>.', 'my-calendar'), $url) . "</p>"; echo $content; } }
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 mc_hcard($event, $address = 'true', $map = 'true', $source = 'event', $context = 'event') { $the_map = mc_maplink($event, 'url', $source); $event = mc_clean_location($event, $source); $url = $source == 'event' ? $event->event_url : $event->location_url; $url = esc_url($url); $label = mc_kses_post(stripslashes($source == 'event' ? $event->event_label : $event->location_label)); $street = mc_kses_post(stripslashes($source == 'event' ? $event->event_street : $event->location_street)); $street2 = mc_kses_post(stripslashes($source == 'event' ? $event->event_street2 : $event->location_street2)); $city = mc_kses_post(stripslashes($source == 'event' ? $event->event_city : $event->location_city)); $state = mc_kses_post(stripslashes($source == 'event' ? $event->event_state : $event->location_state)); $state = mc_kses_post(stripslashes($source == 'event' ? $event->event_state : $event->location_state)); $zip = mc_kses_post(stripslashes($source == 'event' ? $event->event_postcode : $event->location_postcode)); $zip = mc_kses_post(stripslashes($source == 'event' ? $event->event_postcode : $event->location_postcode)); $country = mc_kses_post(stripslashes($source == 'event' ? $event->event_country : $event->location_country)); $country = mc_kses_post(stripslashes($source == 'event' ? $event->event_country : $event->location_country)); $phone = mc_kses_post(stripslashes($source == 'event' ? $event->event_phone : $event->location_phone)); if (!$url && !$label && !$street && !$street2 && !$city && !$state && !$zip && !$country && !$phone) { return ''; } $link = $url != '' ? "<a href='{$url}' class='location-link external'>{$label}</a>" : $label; $hcard = "<div class=\"address vcard\">"; if ($address == 'true') { $hcard .= "<div class=\"adr\">"; $hcard .= $label != '' ? "<strong class=\"org\">" . $link . "</strong><br />" : ''; $hcard .= $street . $street2 . $city . $state . $zip . $country . $phone == '' ? '' : "<div class='sub-address'>"; $hcard .= $street != "" ? "<div class=\"street-address\">" . $street . "</div>" : ''; $hcard .= $street2 != "" ? "<div class=\"street-address\">" . $street2 . "</div>" : ''; $hcard .= $city . $state . $zip != '' ? "<div>" : ''; $hcard .= $city != "" ? "<span class=\"locality\">" . $city . "</span><span class='sep'>, </span>" : ''; $hcard .= $state != "" ? "<span class=\"region\">" . $state . "</span> " : ''; $hcard .= $zip != "" ? " <span class=\"postal-code\">" . $zip . "</span>" : ''; $hcard .= $city . $state . $zip != '' ? "</div>" : ''; $hcard .= $country != "" ? "<div class=\"country-name\">" . $country . "</div>" : ''; $hcard .= $phone != "" ? "<div class=\"tel\">" . $phone . "</div>" : ''; $hcard .= $street . $street2 . $city . $state . $zip . $country . $phone == '' ? '' : "</div>"; $hcard .= "</div>"; } if ($map == 'true') { $the_map = "<a href='{$the_map}' class='url external'>" . __('Map', 'my-calendar') . "<span class='screen-reader-text fn'> {$label}</span></a>"; $hcard .= $the_map != '' ? "<div class='map'>{$the_map}</div>" : ''; } $hcard .= "</div>"; return apply_filters('mc_hcard', $hcard, $event, $address, $map, $source, $context); }
function mc_list_groups() { global $wpdb; $mcdb = $wpdb; $current_user = wp_get_current_user(); $user = $current_user->ID; $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']); $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('Date/Time', 'my-calendar'); ?> </a> </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) . "'>" . mc_kses_post($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_id)) { ?> <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 strip_tags(stripslashes($title)); ?> <?php if (mc_can_edit_event($event->event_id)) { echo "</a>"; } ?> </strong> <div class='row-actions' style="visibility:visible;"> <?php if (mc_can_edit_event($event->event_id)) { ?> <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 strip_tags(stripslashes($event->event_label)); ?> </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><?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 strip_tags(strpos($this_cat->category_color, '#') !== 0 ? '#' : ''); echo $this_cat->category_color; ?> ;"></div> <?php echo mc_kses_post(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_location_select($location = false) { global $wpdb; $mcdb = $wpdb; if (get_option('mc_remote') == 'true' && function_exists('mc_remote_db')) { $mcdb = mc_remote_db(); } // Grab all locations and list them $list = ''; $sql = "SELECT location_id, location_label FROM " . my_calendar_locations_table() . " ORDER BY location_label ASC"; $locs = $mcdb->get_results($sql); foreach ($locs as $loc) { $l = '<option value="' . $loc->location_id . '"'; if ($location) { if ($location == $loc->location_id) { $l .= ' selected="selected"'; } } $l .= '>' . mc_kses_post(stripslashes($loc->location_label)) . '</option>'; $list .= $l; } return $list; }
function update($new, $instance) { $instance['my_calendar_mini_title'] = mc_kses_post($new['my_calendar_mini_title']); $instance['my_calendar_mini_time'] = mc_kses_post($new['my_calendar_mini_time']); $instance['my_calendar_mini_category'] = mc_kses_post($new['my_calendar_mini_category']); $instance['above'] = isset($new['above']) && $new['above'] != '' ? $new['above'] : 'none'; $instance['mc_link'] = $new['mc_link']; $instance['below'] = isset($new['below']) && $new['below'] != '' ? $new['below'] : 'none'; $author = $host = ''; if (isset($new['author'])) { $author = implode(',', $new['author']); } if (isset($new['host'])) { $host = implode(',', $new['host']); } $instance['author'] = $author; $instance['host'] = $host; $instance['site'] = $new['site']; return $instance; }
function mc_manage_categories() { global $wpdb; $mcdb = $wpdb; ?> <h1><?php _e('Manage Categories', 'my-calendar'); ?> </h1><?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'; if ($cat->category_icon != '') { $icon_src = mc_file_exists($cat->category_icon) ? mc_get_file($cat->category_icon, 'url') : plugins_url('my-calendar/images/icons/' . $cat->category_icon); } else { $icon_src = false; } $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(mc_kses_post($cat->category_name)); if ($cat->category_id == get_option('mc_default_category')) { echo ' <strong>' . __('(Default)') . '</strong>'; } if ($cat->category_id == get_option('mc_skip_holidays_category')) { echo ' <strong>' . __('(Holiday)') . '</strong>'; } ?> </td> <td style="background-color:<?php echo $background; ?> ;color: <?php echo $foreground; ?> "><?php echo $icon_src ? "<img src='{$icon_src}' alt='' />" : ''; ?> <?php echo $background != '#' ? $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 printf(__('Edit %s', 'my-calendar'), '<span class="screen-reader-text">' . stripslashes(mc_kses_post($cat->category_name)) . '</span>'); ?> </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 printf(__('Delete %s', 'my-calendar'), '<span class="screen-reader-text">' . stripslashes(mc_kses_post($cat->category_name)) . '</span>'); ?> </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 my_calendar_locations_list($show = 'list', $type = 'saved', $datatype = 'name', $group = 'single') { global $wpdb; $mcdb = $wpdb; if (get_option('mc_remote') == 'true' && function_exists('mc_remote_db')) { $mcdb = mc_remote_db(); } $output = ''; if (isset($_GET['mc_id'])) { return ''; } if ($type == 'saved') { switch ($datatype) { case "name": $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 "region": $data = "location_region"; break; default: $data = "location_label"; } } else { $data = $datatype; } $current_url = mc_get_current_url(); if ($type == 'saved') { $locations = $mcdb->get_results("SELECT DISTINCT {$data} FROM " . my_calendar_locations_table() . " ORDER BY {$data} ASC", ARRAY_A); } else { $data = get_option('mc_user_settings'); $locations = $data['my_calendar_location_default']['values']; $datatype = str_replace('event_', '', get_option('mc_location_type')); $datatype = $datatype == 'label' ? 'name' : $datatype; $datatype = $datatype == 'postcode' ? 'zip' : $datatype; } if (count($locations) > 1) { if ($show == 'list') { $url = mc_build_url(array('loc' => 'all', 'ltype' => 'all'), array()); $output .= "<ul id='mc-locations-list'>\r\n\t\t\t<li class='mc-show-all'><a href='{$url}'>" . __('Show all', 'my-calendar') . "</a></li>\n"; } else { $ltype = !isset($_GET['ltype']) ? $datatype : $_GET['ltype']; $output .= "<div id='mc_locations'>"; $output .= $group == 'single' ? "\r\n\t\t<form action='" . $current_url . "' method='get'>\r\n\t\t<div>" : ''; $output .= "<input type='hidden' name='ltype' value='" . esc_attr($ltype) . "' />"; if ($group == 'single') { $qsa = array(); if (isset($_SERVER['QUERY_STRING'])) { parse_str($_SERVER['QUERY_STRING'], $qsa); } if (!isset($_GET['cid'])) { $output .= '<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 != 'loc' && $name != 'ltype') { $output .= "\n\t\t" . '<input type="hidden" name="' . $name . '" value="' . $argument . '" />'; } } } $output .= "\r\n\t\t\t<label for='mc-locations-list'>" . __('Location', 'my-calendar') . "</label>\r\n\t\t\t<select name='loc' id='mc-locations-list'>\r\n\t\t\t<option value='all'>" . __('Show all', 'my-calendar') . "</option>\n"; } foreach ($locations as $key => $location) { if ($type == 'saved') { foreach ($location as $k => $value) { $vt = urlencode(trim($value)); $value = mc_kses_post(stripcslashes($value)); if ($value == '') { continue; } if (empty($_GET['loc'])) { $loc = ''; } else { $loc = $_GET['loc']; } if ($show == 'list') { $selected = $vt == $loc ? " class='selected'" : ''; $this_url = esc_url(mc_build_url(array('loc' => $vt, 'ltype' => $datatype), array())); $output .= "\t\t\t<li{$selected}><a rel='nofollow' href='{$this_url}'>{$value}</a></li>\n"; } else { $selected = $vt == $loc ? " selected='selected'" : ''; if ($value != '') { $output .= "\t\t\t<option value='" . esc_attr($vt) . "'{$selected}>{$value}</option>\n"; } } } } else { $vk = urlencode(trim($key)); $location = mc_kses_post(trim($location)); if ($location == '') { continue; } if ($show == 'list') { $selected = $vk == $_GET['loc'] ? " class='selected'" : ''; $this_url = esc_url(mc_build_url(array('loc' => $vk, 'ltype' => $datatype), array())); $output .= "\t\t\t<li{$selected}><a rel='nofollow' href='{$this_url}'>{$location}</a></li>\n"; } else { $selected = $vk == $_GET['loc'] ? " selected='selected'" : ''; $output .= "\t\t\t<option value='" . esc_attr($vk) . "'{$selected}>{$location}</option>\n"; } } } if ($show == 'list') { $output .= "</ul>"; } else { $output .= "</select>"; $output .= $group == 'single' ? "<input type='submit' value=" . __('Submit', 'my-calendar') . " />\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</form>" : ''; $output .= "\r\n\t\t\t</div>"; } $output = apply_filters('mc_location_selector', $output, $locations); return $output; } else { return ''; } }