コード例 #1
0
function mc_plugin_activated()
{
    flush_rewrite_rules();
    if (my_calendar_exists()) {
        mc_upgrade_db();
    }
    check_my_calendar();
}
コード例 #2
0
function my_calendar($name, $format, $category, $time = 'month', $ltype = '', $lvalue = '', $id = 'jd-calendar', $template = '', $content = '', $author = null, $host = null, $above = '', $below = '')
{
    check_my_calendar();
    apply_filters("debug", "my_calendar( {$name} ) draw");
    $mc_toporder = array('nav', 'toggle', 'jump', 'print', 'timeframe');
    $mc_bottomorder = array('key', 'feeds');
    if ($above != '' || $below != '') {
        $aboves = $above == 'none' ? array() : array_map('trim', explode(',', $above));
        $belows = $below == 'none' ? array() : array_map('trim', explode(',', $below));
    } else {
        $aboves = $mc_toporder;
        $belows = $mc_bottomorder;
    }
    $used = array_merge($aboves, $belows);
    if (isset($_GET['format']) && in_array($_GET['format'], array('list', 'mini'))) {
        $format = esc_attr($_GET['format']);
    } else {
        $format = esc_attr($format);
    }
    if (isset($_GET['time']) && in_array($_GET['time'], array('day', 'week', 'month')) && $format != 'mini') {
        $time = esc_attr($_GET['time']);
    } else {
        $time = esc_attr($time);
    }
    global $wpdb;
    $mcdb = $wpdb;
    $offset = 60 * 60 * get_option('gmt_offset');
    if (get_option('mc_remote') == 'true' && function_exists('mc_remote_db')) {
        $mcdb = mc_remote_db();
    }
    $my_calendar_body = '';
    /* filter */
    if ($time == 'day') {
        $format = 'list';
    }
    $args = array('name' => $name, 'format' => $format, 'category' => $category, 'above' => $above, 'below' => $below, 'time' => $time, 'ltype' => $ltype, 'lvalue' => $lvalue, 'author' => $author, 'id' => $id);
    $my_calendar_body .= apply_filters('mc_before_calendar', '', $args);
    $main_class = $name != '' ? sanitize_title($name) : 'all';
    $cid = isset($_GET['cid']) ? esc_attr(strip_tags($_GET['cid'])) : $main_class;
    // mc body wrapper
    $mc_wrapper = "<div id=\"{$id}\" class=\"mc-main {$format} {$time} {$main_class}\" aria-live='assertive' aria-atomic='true'>";
    $mc_closer = "</div>";
    if (get_option('mc_convert') == 'true') {
        $format = mc_is_mobile() ? 'list' : $format;
    }
    $format = apply_filters('mc_display_format', $format, $args);
    $date_format = get_option('mc_date_format') != '' ? get_option('mc_date_format') : get_option('date_format');
    if (isset($_GET['mc_id']) && $format != 'mini') {
        // single event, main calendar only.
        $mc_id = (int) $_GET['mc_id'];
        $my_calendar_body .= mc_get_event($mc_id, 'html');
    } else {
        if ($category == "") {
            $category = null;
        }
        // Deal with the week not starting on a monday
        $name_days = array(__('<abbr title="Sunday">Sun</abbr>', 'my-calendar'), __('<abbr title="Monday">Mon</abbr>', 'my-calendar'), __('<abbr title="Tuesday">Tues</abbr>', 'my-calendar'), __('<abbr title="Wednesday">Wed</abbr>', 'my-calendar'), __('<abbr title="Thursday">Thur</abbr>', 'my-calendar'), __('<abbr title="Friday">Fri</abbr>', 'my-calendar'), __('<abbr title="Saturday">Sat</abbr>', 'my-calendar'));
        $abbrevs = array('sun', 'mon', 'tues', 'wed', 'thur', 'fri', 'sat');
        if ($format == "mini") {
            $name_days = array(__('<abbr title="Sunday">S</abbr>', 'my-calendar'), __('<abbr title="Monday">M</abbr>', 'my-calendar'), __('<abbr title="Tuesday">T</abbr>', 'my-calendar'), __('<abbr title="Wednesday">W</abbr>', 'my-calendar'), __('<abbr title="Thursday">T</abbr>', 'my-calendar'), __('<abbr title="Friday">F</abbr>', 'my-calendar'), __('<abbr title="Saturday">S</abbr>', 'my-calendar'));
        }
        $start_of_week = get_option('start_of_week') == 1 ? 1 : 7;
        // convert start of week to ISO 8601 (Monday/Sunday)
        $end_of_week = $start_of_week == 1 ? 7 : 6;
        $start_of_week = get_option('mc_show_weekends') == 'true' ? $start_of_week : 1;
        //$start_of_week = ( $start_of_week==1||$start_of_week==0)?$start_of_week:0;
        if ($start_of_week == '1') {
            $first = array_shift($name_days);
            $afirst = array_shift($abbrevs);
            $name_days[] = $first;
            $abbrevs[] = $afirst;
        }
        // If we don't pass arguments we want a calendar that is relevant to today (current time period)
        $c_m = 0;
        if (isset($_GET['dy']) && $main_class == $cid && ($time == 'day' || $time == 'week')) {
            //
            $c_day = (int) $_GET['dy'];
        } else {
            if ($time == 'week') {
                $dm = first_day_of_week();
                $c_day = $dm[0];
                $c_m = $dm[1];
            } else {
                if ($time == 'day') {
                    $c_day = date("d", time() + $offset);
                } else {
                    $c_day = 1;
                }
            }
        }
        if (isset($_GET['month']) && $main_class == $cid) {
            $c_month = (int) $_GET['month'];
            if (!isset($_GET['dy'])) {
                $c_day = 1;
            }
        } else {
            $xnow = date('Y-m-d', time() + $offset);
            $c_month = $c_m == 0 ? date("m", time() + $offset) : date("m", strtotime($xnow . ' -1 month'));
        }
        $is_start_of_week = date('N', current_time('timestamp')) == get_option('start_of_week') ? true : false;
        if (isset($_GET['yr']) && $main_class == $cid) {
            $c_year = (int) $_GET['yr'];
        } else {
            // weeks suck. seriously.
            if (date("Y", current_time('timestamp')) == date("Y", strtotime(date('Y-m-d', current_time('timestamp')) . '- 6 days')) || $is_start_of_week) {
                $c_year = date("Y", current_time('timestamp'));
            } else {
                $c_year = date("Y", current_time('timestamp')) - 1;
            }
        }
        // Years get funny if we exceed 3000, so we use this check
        if (!($c_year <= 3000 && $c_year >= 0)) {
            // No valid year causes the calendar to default to today
            $c_year = date("Y", time() + $offset);
            $c_month = date("m", time() + $offset);
            $c_day = date("d", time() + $offset);
        }
        if (!(isset($_GET['yr']) || isset($_GET['month']) || isset($_GET['dy']))) {
            $c_year = apply_filters('mc_filter_year', $c_year, $args);
            $c_month = apply_filters('mc_filter_month', $c_month, $args);
            $c_day = apply_filters('mc_filter_day', $c_day, $args);
        }
        $c_day = $c_day == 0 ? 1 : $c_day;
        // c_day can't equal 0.
        $n_month = $c_month + 1 > 12 ? 1 : $c_month + 1;
        $p_month = $c_month - 1 < 1 ? 12 : $c_month - 1;
        $current_date = mktime(0, 0, 0, $c_month, $c_day, $c_year);
        $c_month = str_pad($c_month, 2, '0', STR_PAD_LEFT);
        $n_month = str_pad($n_month, 2, '0', STR_PAD_LEFT);
        $p_month = str_pad($p_month, 2, '0', STR_PAD_LEFT);
        //echo "<p>Debug:<br />Day: $c_day<br />Month: $c_month<br />Year: $c_year<br />Date: ".date('Y-m-d',$current_date)."</p>";
        $num = get_option('mc_show_months') - 1;
        // the value is total months to show; need additional months to show.
        if ($format == "list" && $time != 'week') {
            // grid calendar can't show multiple months
            if ($num > 0 && $time != 'day' && $time != 'week') {
                $from = date('Y-m-d', mktime(0, 0, 0, $c_month, 1, $c_year));
                $next = strtotime("+{$num} months", mktime(0, 0, 0, $c_month, 1, $c_year));
                $last = date('t', $next);
                $to = date('Y-m', $next) . '-' . $last;
            } else {
                $from = date('Y-m-d', mktime(0, 0, 0, $c_month, 1, $c_year));
                $to = date('Y-m-d', mktime(0, 0, 0, $c_month, date('t', mktime(0, 0, 0, $c_month, 1, $c_year)), $c_year));
            }
            $this_dates = array('from' => $from, 'to' => $to);
        } else {
            $this_dates = mc_date_array($current_date, $time, $num);
        }
        $from = $this_dates['from'];
        $to = $this_dates['to'];
        //echo "<pre>$num $from, $to ($c_month,$c_day,$c_year)</pre>";
        apply_filters("debug", "my_calendar( {$name} ) pre get events");
        $event_array = my_calendar_events($from, $to, $category, $ltype, $lvalue, 'calendar', $author, $host);
        $no_events = empty($event_array) ? true : false;
        apply_filters("debug", "my_calendar( {$name} ) post get events");
        // define navigation element strings
        $timeframe = $nav = $feeds = $jump = $mc_topnav = $mc_bottomnav = '';
        // setup print link
        $add = array('time' => $time, 'ltype' => $ltype, 'lvalue' => $lvalue, 'mcat' => $category, 'yr' => $c_year, 'month' => $c_month, 'dy' => $c_day, 'cid' => 'print');
        $subtract = array();
        if ($ltype == '') {
            $subtract[] = 'ltype';
            unset($add['ltype']);
        }
        if ($lvalue == '') {
            $subtract[] = 'lvalue';
            unset($add['lvalue']);
        }
        if ($category == 'all') {
            $subtract[] = 'mcat';
            unset($add['mcat']);
        }
        $mc_print_url = mc_build_url($add, $subtract, mc_feed_base() . 'my-calendar-print');
        $print = "<div class='mc-print'><a href='{$mc_print_url}'>" . __('Print View', 'my-calendar') . "</a></div>";
        // set up format toggle
        $toggle = in_array('toggle', $used) ? mc_format_toggle($format, 'yes') : '';
        // set up time toggle
        if (in_array('timeframe', $used)) {
            // if dy parameter not set, use today's date instead of first day of month.
            if (isset($_GET['dy'])) {
                $weeks_day = first_day_of_week($current_date);
            } else {
                $weeks_day = first_day_of_week(current_time('timestamp'));
            }
            $day = $weeks_day[0];
            if (isset($_GET['time']) && $_GET['time'] == 'day') {
                // don't adjust day if viewing day format
            } else {
                if ($day > 20) {
                    $day = date('j', strtotime("{$from} + 1 week"));
                }
            }
            $timeframe = mc_time_toggle($format, $time, 'yes', $day, $c_month, $c_year);
        }
        // set up category key
        $key = in_array('key', $used) ? my_category_key($category) : '';
        // set up navigation links
        if (in_array('nav', $used)) {
            $pLink = my_calendar_prev_link($c_year, $c_month, $c_day, $format, $time);
            $nLink = my_calendar_next_link($c_year, $c_month, $c_day, $format, $time);
            $prevLink = mc_build_url(array('yr' => $pLink['yr'], 'month' => $pLink['month'], 'dy' => $pLink['day'], 'cid' => $main_class), array());
            $nextLink = mc_build_url(array('yr' => $nLink['yr'], 'month' => $nLink['month'], 'dy' => $nLink['day'], 'cid' => $main_class), array());
            $previous_link = apply_filters('mc_previous_link', '		<li class="my-calendar-prev"><a href="' . $prevLink . '" rel="' . $id . '">' . $pLink['label'] . '</a></li>', $pLink);
            $next_link = apply_filters('mc_next_link', '		<li class="my-calendar-next"><a href="' . $nextLink . '" rel="' . $id . '">' . $nLink['label'] . '</a></li>', $nLink);
            $nav = '
				<div class="my-calendar-nav">
					<ul>
						' . $previous_link . '
						' . $next_link . '
					</ul>
				</div>';
        }
        // set up rss feeds
        if ($format != 'mini') {
            $ical_m = isset($_GET['month']) ? (int) $_GET['month'] : date('n');
            $ical_y = isset($_GET['yr']) ? (int) $_GET['yr'] : date('Y');
            $feeds = mc_rss_links($ical_y, $ical_m, $nLink);
        }
        // set up date switcher
        if (in_array('jump', $used)) {
            $jump = $time != 'week' && $time != 'day' ? mc_build_date_switcher($format, $main_class) : '';
        }
        // set up above-calendar order of fields
        if (get_option('mc_topnav') != '') {
            $mc_toporder = explode(',', get_option('mc_topnav'));
        }
        if ($above != '') {
            $mc_toporder = explode(',', $above);
        }
        foreach ($mc_toporder as $value) {
            if ($value != 'none') {
                $value = trim($value);
                $mc_topnav .= ${$value};
            }
        }
        if ($mc_topnav != '') {
            $mc_topnav = '<div class="my-calendar-header">' . $mc_topnav . '</div>';
        }
        if (get_option('mc_bottomnav') != '') {
            $mc_bottomorder = explode(',', get_option('mc_bottomnav'));
        }
        if ($below != '') {
            $mc_bottomorder = explode(',', $below);
        }
        foreach ($mc_bottomorder as $value) {
            if ($value != 'none' && $value != 'stop') {
                $value = trim($value);
                $mc_bottomnav .= ${$value};
            }
        }
        if ($mc_bottomnav != '') {
            $mc_bottomnav = "<div class='mc_bottomnav'>{$mc_bottomnav}</div>";
        }
        if ($time == 'day') {
            apply_filters("debug", "my_calendar( {$name} ) pre single-day parsing");
            $my_calendar_body .= "<div class='mc-main {$format} {$time}'>" . $mc_topnav;
            // single day uses independent cycling.
            $dayclass = strtolower(date_i18n('D', mktime(0, 0, 0, $c_month, $c_day, $c_year)));
            $from = $to = "{$c_year}-{$c_month}-{$c_day}";
            //echo "<p>Debug: $from, $to, $category, $ltype, $lvalue, $author</p>";
            $events = my_calendar_grab_events($from, $to, $category, $ltype, $lvalue, 'calendar', $author, $host);
            if (!get_option('mc_skip_holidays_category') || get_option('mc_skip_holidays_category') == '') {
                $holidays = array();
            } else {
                $holidays = my_calendar_grab_events($from, $to, get_option('mc_skip_holidays_category'), $ltype, $lvalue, 'calendar', $author, $host, 'holidays');
            }
            //echo "<pre>".print_r($events,1)."</pre>";
            $events_class = mc_events_class($events);
            $dateclass = mc_dateclass(time() + $offset, mktime(0, 0, 0, $c_month, $c_day, $c_year));
            $mc_events = '';
            if (is_array($events) && count($events) > 0) {
                if (is_array($holidays) && count($holidays) > 0) {
                    $mc_events .= my_calendar_draw_events($holidays, $format, $from, $time, $template);
                } else {
                    $mc_events .= my_calendar_draw_events($events, $format, $from, $time, $template);
                }
            } else {
                $mc_events .= __('No events scheduled for today!', 'my-calendar');
            }
            $heading_level = apply_filters('mc_heading_level', 'h3', $format, $time, $template);
            $my_calendar_body .= "\n\t\t\t\t<{$heading_level} class='mc-single'>" . date_i18n(apply_filters('mc_date_format', $date_format, 'grid'), strtotime("{$c_year}-{$c_month}-{$c_day}")) . "</{$heading_level}>" . '
				<div id="mc-day" class="' . $dayclass . ' ' . $dateclass . ' ' . $events_class . '">' . "{$mc_events}\n</div>\n\t\t\t</div>";
            apply_filters("debug", "my_calendar( {$name} ) post single-day parsing");
        } else {
            apply_filters("debug", "my_calendar( {$name} ) pre full parsing");
            // if showing multiple months, figure out how far we're going.
            $num_months = $time == 'week' ? 1 : get_option('mc_show_months');
            $through_date = mktime(0, 0, 0, $c_month + ($num_months - 1), $c_day, $c_year);
            $month_format = get_option('mc_month_format') == '' ? 'F Y' : get_option('mc_month_format');
            $current_date_header = date_i18n($month_format, $current_date);
            $current_month_header = date('Y', $current_date) == date('Y', $through_date) ? date_i18n('F', $current_date) : date_i18n('F Y', $current_date);
            $through_month_header = date_i18n($month_format, $through_date);
            // Adjust the days of the week if week start is not Monday
            $and = __("and", 'my-calendar');
            $category_label = $category != "" && $category != "all" ? str_replace("|", " {$and} ", $category) . ' ' : '';
            // Add the calendar table and heading
            $caption_text = ' ' . stripslashes(trim(get_option('mc_caption')));
            // this option should be replaced JCD TODO
            $my_calendar_body .= $mc_topnav;
            if ($format == "calendar" || $format == "mini") {
                $my_calendar_body .= "\n<table class=\"my-calendar-table\">\n";
                $values = array('date' => date('Y-m-d', $current_date));
                $week_template = get_option('mc_week_caption') != '' ? get_option('mc_week_caption') : 'Week of {date format="M jS"}';
                $week_caption = jd_draw_template($values, stripslashes($week_template));
                $caption_heading = $time != 'week' ? $current_date_header . $caption_text : $week_caption . $caption_text;
                $my_calendar_body .= "<caption class=\"my-calendar-{$time}\">" . $caption_heading . "</caption>\n";
            } else {
                // determine which header text to show depending on number of months displayed;
                if ($time != 'week' && $time != 'day') {
                    $list_heading = $num_months <= 1 ? __('Events in', 'my-calendar') . ' ' . $current_date_header . $caption_text . "\n" : $current_month_header . '&ndash;' . $through_month_header . $caption_text;
                } else {
                    $values = array('date' => date('Y-m-d', $current_date));
                    $list_heading = jd_draw_template($values, stripslashes(get_option('mc_week_caption')));
                }
                $my_calendar_body .= "<h3 class=\"my-calendar-{$time}\">{$list_heading}</h3>\n";
            }
            // If not a valid time or layout format, skip.
            if (in_array($format, array('calendar', 'mini', 'list')) && in_array($time, array('day', 'week', 'month'))) {
                // If in a calendar format, print the headings of the days of the week
                if ($format == "list") {
                    if ($id == 'jd-calendar') {
                        $list_id = 'calendar-list';
                    } else {
                        $list_id = "list-{$id}";
                    }
                    $my_calendar_body .= "<ul id='{$list_id}' class='mc-list'>";
                } else {
                    $my_calendar_body .= "<thead>\n<tr>\n";
                    for ($i = 0; $i <= 6; $i++) {
                        if ($start_of_week == 0) {
                            $class = $i < 6 && $i > 0 ? 'day-heading' : 'weekend-heading';
                        } else {
                            $class = $i < 5 ? 'day-heading' : 'weekend-heading';
                        }
                        $dayclass = strtolower(strip_tags($abbrevs[$i]));
                        if ($class == 'weekend-heading' && get_option('mc_show_weekends') == 'true' || $class != 'weekend-heading') {
                            $my_calendar_body .= "<th scope='col' class='{$class} {$dayclass}'>" . $name_days[$i] . "</th>\n";
                        }
                    }
                    $my_calendar_body .= "\n</tr>\n</thead>\n<tbody>";
                }
                $odd = 'odd';
                // get and display all the events
                $show_all = false;
                // show all dates in list format.
                if ($no_events && $format == "list" && $show_all == false) {
                    // if there are no events in list format, just display that info.
                    $no_events = $content == '' ? __('There are no events scheduled during this period.', 'my-calendar') : $content;
                    $my_calendar_body .= "<li class='no-events'>{$no_events}</li>";
                } else {
                    $start = strtotime($from);
                    $end = strtotime($to);
                    do {
                        $date = date('Y-m-d', $start);
                        $enddate = date('Y-m-d', $end);
                        $is_weekend = date('N', $start) < 6 ? false : true;
                        if (get_option('mc_show_weekends') == 'true' || get_option('mc_show_weekends') != 'true' && !$is_weekend) {
                            if (date('N', $start) == $start_of_week && $format != "list") {
                                $my_calendar_body .= "<tr>";
                            }
                            // date-based classes
                            $monthclass = date('n', $start) == $c_month || $time != 'month' ? '' : 'nextmonth';
                            $dateclass = mc_dateclass(time() + $offset, $start);
                            $dayclass = strtolower(date_i18n('D', $start));
                            $week_format = get_option('mc_week_format') == '' ? 'M j, \'y' : get_option('mc_week_format');
                            $week_date_format = date_i18n($week_format, $start);
                            $thisday_heading = $time == 'week' ? "<small>{$week_date_format}</small>" : date('j', $start);
                            $events = isset($event_array[$date]) ? $event_array[$date] : array();
                            if (!empty($events)) {
                                $event_output = my_calendar_draw_events($events, $format, $date, $time, $template);
                                if ($event_output === true) {
                                    $event_output = ' ';
                                }
                                $events_class = $event_output != '' ? mc_events_class($events) : 'no-events';
                                if ($format == 'mini' && $event_output != '') {
                                    if (get_option('mc_open_day_uri') == 'true' || get_option('mc_open_day_uri') == 'false') {
                                        // yes, this is weird. it's from some old settings...
                                        $target = array('yr' => date('Y', $start), 'month' => date('m', $start), 'dy' => date('j', $start), 'time' => 'day');
                                        if ($category != '') {
                                            $target['mcat'] = $category;
                                        }
                                        $day_url = mc_build_url($target, array('month', 'dy', 'yr', 'ltype', 'loc', 'mcat', 'cid', 'mc_id'), apply_filters('mc_modify_day_uri', get_option('mc_uri')));
                                        $link = get_option('mc_uri') != '' && !is_numeric(get_option('mc_uri')) ? $day_url : '#';
                                    } else {
                                        $atype = str_replace('anchor', '', get_option('mc_open_day_uri'));
                                        $ad = str_pad(date('j', $start), 2, '0', STR_PAD_LEFT);
                                        // need to match format in ID
                                        $am = str_pad($c_month, 2, '0', STR_PAD_LEFT);
                                        $date_url = mc_build_url(array('yr' => $c_year, 'month' => $c_month, 'dy' => date('j', $start)), array('month', 'dy', 'yr', 'ltype', 'loc', 'mcat', 'cid', 'mc_id'), get_option('mc_mini_uri'));
                                        $link = get_option('mc_mini_uri') != '' ? $date_url . '#' . $atype . '-' . $c_year . '-' . $am . '-' . $ad : '#';
                                    }
                                    $element = "a href='{$link}'";
                                    $close = 'a';
                                    $trigger = 'trigger';
                                } else {
                                    $element = 'span';
                                    $close = 'span';
                                    $trigger = '';
                                }
                                // set up events
                                if ($is_weekend && get_option('mc_show_weekends') == 'true' || !$is_weekend) {
                                    $weekend_class = $is_weekend ? 'weekend' : '';
                                    if ($format == "list") {
                                        if (get_option('mc_list_javascript') != 1) {
                                            $is_anchor = "<a href='#'>";
                                            $is_close_anchor = "</a>";
                                        } else {
                                            $is_anchor = $is_close_anchor = "";
                                        }
                                        if (get_option('mc_show_list_info') == 'true') {
                                            $title = ' - ' . $is_anchor . mc_list_title($events) . $is_close_anchor;
                                        } else {
                                            $title = '';
                                        }
                                        //if ( $monthclass != 'nextmonth' ) { // only show current month in list view.
                                        if ($event_output != '') {
                                            $my_calendar_body .= "\n\t\t\t\t\t\t\t\t\t\t\t\t<li id='{$format}-{$date}' class='mc-events {$dayclass} {$dateclass} {$events_class} {$odd}'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<strong class=\"event-date\">{$is_anchor}" . date_i18n(apply_filters('mc_date_format', $date_format, 'list'), $start) . "{$is_close_anchor}" . "{$title}</strong>" . $event_output . "\n\t\t\t\t\t\t\t\t\t\t\t\t</li>";
                                            $odd = $odd == 'odd' ? 'even' : 'odd';
                                        }
                                        //}
                                    } else {
                                        $my_calendar_body .= "\n\t\t\t\t\t\t\t\t\t\t\t\t<td id='{$format}-{$date}' class='{$dayclass} {$dateclass} {$weekend_class} {$monthclass} {$events_class} day-with-date'>" . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t<{$element} class='mc-date {$trigger}'>{$thisday_heading}</{$close}>" . $event_output . "\n\t\t\t\t\t\t\t\t\t\t\t\t</td>\n";
                                    }
                                }
                            } else {
                                // set up no events
                                if ($format != "list") {
                                    $weekend_class = $is_weekend ? 'weekend' : '';
                                    $my_calendar_body .= "\n\t\t\t\t\t\t\t\t\t\t\t\t<td class='no-events {$dayclass} {$dateclass} {$weekend_class} {$monthclass} day-with-date'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<span class='mc-date no-events'>{$thisday_heading}</span>\n\t\t\t\t\t\t\t\t\t\t\t\t</td>\n";
                                } else {
                                    if ($show_all == true) {
                                        $my_calendar_body .= "\n\t\t\t\t\t\t\t\t\t\t\t<li id='{$format}-{$date}' class='no-events {$dayclass} {$dateclass} {$events_class} {$odd}'>\n\t\t\t\t\t\t\t\t\t\t\t\t<strong class=\"event-date\">{$is_anchor}" . date_i18n($date_format, $start) . "{$is_close_anchor}</strong></li>";
                                        $odd = $odd == 'odd' ? 'even' : 'odd';
                                    }
                                }
                            }
                            if (date('N', $start) == $end_of_week && $format != "list") {
                                $my_calendar_body .= "</tr>\n";
                                // end of 'is beginning of week'
                            }
                        }
                        $start = strtotime("+1 day", $start);
                    } while ($start <= $end);
                }
                $my_calendar_body .= $format == "list" ? "\n</ul>" : "\n</tbody>\n</table>";
            } else {
                if (!in_array($format, array('list', 'calendar', 'mini'))) {
                    $my_calendar_body .= "<p class='mc-error-format'>" . __("Unrecognized calendar format. Please use one of 'list', 'calendar', or 'mini'.", 'my-calendar') . "</p>";
                }
                if (!in_array($time, array('day', 'week', 'month'))) {
                    $my_calendar_body .= "<p class='mc-error-time'>" . __("Unrecognized calendar time period. Please use one of 'day', 'week', or 'month'.", 'my-calendar') . "</p>";
                }
            }
            $my_calendar_body .= $mc_bottomnav;
            apply_filters("debug", "my_calendar( {$name} ) post full parsing");
        }
    }
    // The actual printing is done by the shortcode function.
    $my_calendar_body .= apply_filters('mc_after_calendar', '', $args);
    apply_filters("debug", "my_calendar( {$name} ) draw completed");
    return $mc_wrapper . apply_filters('my_calendar_body', $my_calendar_body) . $mc_closer;
}
コード例 #3
0
function edit_my_calendar_config()
{
    global $wpdb;
    $mcdb = $wpdb;
    check_my_calendar();
    if (!empty($_POST)) {
        $nonce = $_REQUEST['_wpnonce'];
        if (!wp_verify_nonce($nonce, 'my-calendar-nonce')) {
            die("Security check failed");
        }
        if (isset($_POST['remigrate'])) {
            echo "<div class='updated fade'><ol>";
            echo "<li>" . __('Dropping occurrences database table', 'my-calendar') . "</li>";
            mc_drop_table('my_calendar_event_table');
            sleep(1);
            echo "<li>" . __('Reinstalling occurrences database table.', 'my-calendar') . "</li>";
            mc_upgrade_db();
            sleep(1);
            echo "<li>" . __('Generating event occurrences.', 'my-calendar') . "</li>";
            mc_migrate_db();
            echo "<li>" . __('Event generation completed.', 'my-calendar') . "</li>";
            echo "</ol></div>";
        }
    }
    if (isset($_POST['mc_manage'])) {
        // management
        $clear = '';
        $mc_event_approve = !empty($_POST['mc_event_approve']) && $_POST['mc_event_approve'] == 'on' ? 'true' : 'false';
        $mc_api_enabled = !empty($_POST['mc_api_enabled']) && $_POST['mc_api_enabled'] == 'on' ? 'true' : 'false';
        $mc_remote = !empty($_POST['mc_remote']) && $_POST['mc_remote'] == 'on' ? 'true' : 'false';
        if (isset($_POST['mc_clear_cache']) && $_POST['mc_clear_cache'] == 'clear') {
            mc_delete_cache();
            $clear = __('My Calendar Cache cleared', 'my-calendar');
        }
        update_option('mc_event_approve', $mc_event_approve);
        update_option('mc_api_enabled', $mc_api_enabled);
        update_option('mc_remote', $mc_remote);
        update_option('mc_default_sort', $_POST['mc_default_sort']);
        if (get_site_option('mc_multisite') == 2) {
            $mc_current_table = (int) $_POST['mc_current_table'];
            update_option('mc_current_table', $mc_current_table);
        }
        echo "<div class='updated'><p><strong>" . __('My Calendar Management Settings saved', 'my-calendar') . ". {$clear}</strong></p></div>";
    }
    if (isset($_POST['mc_permissions'])) {
        $perms = $_POST['mc_caps'];
        $caps = array('mc_add_events' => __('Add Events', 'my-calendar'), 'mc_approve_events' => __('Approve Events', 'my-calendar'), 'mc_manage_events' => __('Manage Events', 'my-calendar'), 'mc_edit_cats' => __('Edit Categories', 'my-calendar'), 'mc_edit_locations' => __('Edit Locations', 'my-calendar'), 'mc_edit_styles' => __('Edit Styles', 'my-calendar'), 'mc_edit_behaviors' => __('Edit Behaviors', 'my-calendar'), 'mc_edit_templates' => __('Edit Templates', 'my-calendar'), 'mc_edit_settings' => __('Edit Settings', 'my-calendar'), 'mc_view_help' => __('View Help', 'my-calendar'));
        foreach ($perms as $key => $value) {
            $role = get_role($key);
            if (is_object($role)) {
                foreach ($caps as $k => $v) {
                    if (isset($value[$k])) {
                        $role->add_cap($k);
                    } else {
                        $role->remove_cap($k);
                    }
                }
            }
        }
        echo "<div class='updated'><p><strong>" . __('My Calendar Permissions Updated', 'my-calendar') . "</strong></p></div>";
    }
    // output
    if (isset($_POST['mc_show_months'])) {
        $mc_open_day_uri = !empty($_POST['mc_open_day_uri']) ? $_POST['mc_open_day_uri'] : '';
        update_option('mc_uri', $_POST['mc_uri']);
        update_option('mc_use_permalinks', !empty($_POST['mc_use_permalinks']) ? 'true' : 'false');
        update_option('mc_open_uri', !empty($_POST['mc_open_uri']) && $_POST['mc_open_uri'] == 'on' && get_option('mc_uri') != '' ? 'true' : 'false');
        update_option('mc_mini_uri', $_POST['mc_mini_uri']);
        update_option('mc_open_day_uri', $mc_open_day_uri);
        update_option('mc_skip_holidays', !empty($_POST['mc_skip_holidays']) && $_POST['mc_skip_holidays'] == 'on' ? 'true' : 'false');
        update_option('mc_display_author', !empty($_POST['mc_display_author']) && $_POST['mc_display_author'] == 'on' ? 'true' : 'false');
        update_option('mc_show_event_vcal', !empty($_POST['mc_show_event_vcal']) && $_POST['mc_show_event_vcal'] == 'on' ? 'true' : 'false');
        update_option('mc_show_gcal', !empty($_POST['mc_show_gcal']) && $_POST['mc_show_gcal'] == 'on' ? 'true' : 'false');
        update_option('mc_display_jump', !empty($_POST['mc_display_jump']) && $_POST['mc_display_jump'] == 'on' ? 'true' : 'false');
        update_option('mc_show_list_info', !empty($_POST['mc_show_list_info']) && $_POST['mc_show_list_info'] == 'on' ? 'true' : 'false');
        update_option('mc_show_months', (int) $_POST['mc_show_months']);
        // calculate sequence for navigation elements
        $top = $bottom = array();
        $nav = $_POST['mc_nav'];
        $set = 'top';
        foreach ($nav as $n) {
            if ($n == 'calendar') {
                $set = 'bottom';
            } else {
                if ($set == 'top') {
                    $top[] = $n;
                } else {
                    $bottom[] = $n;
                }
            }
            if ($n == 'stop') {
                break;
            }
        }
        update_option('mc_bottomnav', implode(',', $bottom));
        update_option('mc_topnav', implode(',', $top));
        update_option('mc_show_map', !empty($_POST['mc_show_map']) && $_POST['mc_show_map'] == 'on' ? 'true' : 'false');
        update_option('mc_gmap', !empty($_POST['mc_gmap']) && $_POST['mc_gmap'] == 'on' ? 'true' : 'false');
        update_option('mc_show_address', !empty($_POST['mc_show_address']) && $_POST['mc_show_address'] == 'on' ? 'true' : 'false');
        update_option('mc_hide_icons', !empty($_POST['mc_hide_icons']) && $_POST['mc_hide_icons'] == 'on' ? 'true' : 'false');
        update_option('mc_event_link_expires', !empty($_POST['mc_event_link_expires']) && $_POST['mc_event_link_expires'] == 'on' ? 'true' : 'false');
        update_option('mc_apply_color', $_POST['mc_apply_color']);
        update_option('mc_event_registration', !empty($_POST['mc_event_registration']) && $_POST['mc_event_registration'] == 'on' ? 'true' : 'false');
        update_option('mc_inverse_color', !empty($_POST['mc_inverse_color']) && $_POST['mc_inverse_color'] == 'on' ? 'true' : 'false');
        update_option('mc_short', !empty($_POST['mc_short']) && $_POST['mc_short'] == 'on' ? 'true' : 'false');
        update_option('mc_desc', !empty($_POST['mc_desc']) && $_POST['mc_desc'] == 'on' ? 'true' : 'false');
        update_option('mc_process_shortcodes', !empty($_POST['mc_process_shortcodes']) && $_POST['mc_process_shortcodes'] == 'on' ? 'true' : 'false');
        update_option('mc_details', !empty($_POST['mc_details']) && $_POST['mc_details'] == 'on' ? 'true' : 'false');
        update_option('mc_event_link', !empty($_POST['mc_event_link']) && $_POST['mc_event_link'] == 'on' ? 'true' : 'false');
        update_option('mc_show_weekends', !empty($_POST['mc_show_weekends']) && $_POST['mc_show_weekends'] == 'on' ? 'true' : 'false');
        update_option('mc_convert', !empty($_POST['mc_convert']) && $_POST['mc_convert'] == 'on' ? 'true' : 'false');
        update_option('mc_no_fifth_week', !empty($_POST['mc_no_fifth_week']) && $_POST['mc_no_fifth_week'] == 'on' ? 'true' : 'false');
        echo "<div class=\"updated\"><p><strong>" . __('Output Settings saved', 'my-calendar') . "</strong></p></div>";
    }
    // input
    if (isset($_POST['mc_dates'])) {
        update_option('mc_date_format', stripslashes($_POST['mc_date_format']));
        update_option('mc_week_format', stripslashes($_POST['mc_week_format']));
        update_option('mc_time_format', stripslashes($_POST['mc_time_format']));
        update_option('mc_month_format', stripslashes($_POST['mc_month_format']));
        $mc_ical_utc = !empty($_POST['mc_ical_utc']) && $_POST['mc_ical_utc'] == 'on' ? 'true' : 'false';
        update_option('mc_ical_utc', $mc_ical_utc);
        echo "<div class=\"updated\"><p><strong>" . __('Date/Time Format Settings saved', 'my-calendar') . "</strong></p></div>";
    }
    if (isset($_POST['mc_input'])) {
        $mc_input_options_administrators = !empty($_POST['mc_input_options_administrators']) && $_POST['mc_input_options_administrators'] == 'on' ? 'true' : 'false';
        $mc_input_options = array('event_short' => !empty($_POST['mci_event_short']) && $_POST['mci_event_short'] ? 'on' : '', 'event_desc' => !empty($_POST['mci_event_desc']) && $_POST['mci_event_desc'] ? 'on' : '', 'event_category' => !empty($_POST['mci_event_category']) && $_POST['mci_event_category'] ? 'on' : '', 'event_image' => !empty($_POST['mci_event_image']) && $_POST['mci_event_image'] ? 'on' : '', 'event_link' => !empty($_POST['mci_event_link']) && $_POST['mci_event_link'] ? 'on' : '', 'event_recurs' => !empty($_POST['mci_event_recurs']) && $_POST['mci_event_recurs'] ? 'on' : '', 'event_open' => !empty($_POST['mci_event_open']) && $_POST['mci_event_open'] ? 'on' : '', 'event_location' => !empty($_POST['mci_event_location']) && $_POST['mci_event_location'] ? 'on' : '', 'event_location_dropdown' => !empty($_POST['mci_event_location_dropdown']) && $_POST['mci_event_location_dropdown'] ? 'on' : '', 'event_specials' => !empty($_POST['mci_event_specials']) && $_POST['mci_event_specials'] ? 'on' : '', 'event_access' => !empty($_POST['mci_event_access']) && $_POST['mci_event_access'] ? 'on' : '');
        update_option('mc_input_options', $mc_input_options);
        update_option('mc_input_options_administrators', $mc_input_options_administrators);
        echo "<div class=\"updated\"><p><strong>" . __('Input Settings saved', 'my-calendar') . ".</strong></p></div>";
    }
    if (current_user_can('manage_network')) {
        if (isset($_POST['mc_network'])) {
            $mc_multisite = (int) $_POST['mc_multisite'];
            update_site_option('mc_multisite', $mc_multisite);
            $mc_multisite_show = (int) $_POST['mc_multisite_show'];
            update_site_option('mc_multisite_show', $mc_multisite_show);
            echo "<div class=\"updated\"><p><strong>" . __('Multisite settings saved', 'my-calendar') . ".</strong></p></div>";
        }
    }
    // custom text
    if (isset($_POST['mc_previous_events'])) {
        $mc_title_template = $_POST['mc_title_template'];
        $mc_details_label = $_POST['mc_details_label'];
        $mc_link_label = $_POST['mc_link_label'];
        $mc_event_title_template = $_POST['mc_event_title_template'];
        $mc_notime_text = $_POST['mc_notime_text'];
        $mc_previous_events = $_POST['mc_previous_events'];
        $mc_next_events = $_POST['mc_next_events'];
        $mc_event_open = $_POST['mc_event_open'];
        $mc_event_closed = $_POST['mc_event_closed'];
        $mc_week_caption = $_POST['mc_week_caption'];
        $mc_caption = $_POST['mc_caption'];
        $templates = get_option('mc_templates');
        $templates['title'] = $mc_title_template;
        $templates['label'] = $mc_details_label;
        $templates['link'] = $mc_link_label;
        update_option('mc_templates', $templates);
        update_option('mc_event_title_template', $mc_event_title_template);
        update_option('mc_notime_text', $mc_notime_text);
        update_option('mc_week_caption', $mc_week_caption);
        update_option('mc_next_events', $mc_next_events);
        update_option('mc_previous_events', $mc_previous_events);
        update_option('mc_caption', $mc_caption);
        update_option('mc_event_open', $mc_event_open);
        update_option('mc_event_closed', $mc_event_closed);
        echo "<div class=\"updated\"><p><strong>" . __('Custom text settings saved', 'my-calendar') . ".</strong></p></div>";
    }
    // Mail function by Roland
    if (isset($_POST['mc_email'])) {
        $mc_event_mail = !empty($_POST['mc_event_mail']) && $_POST['mc_event_mail'] == 'on' ? 'true' : 'false';
        $mc_html_email = !empty($_POST['mc_html_email']) && $_POST['mc_html_email'] == 'on' ? 'true' : 'false';
        $mc_event_mail_to = $_POST['mc_event_mail_to'];
        $mc_event_mail_from = $_POST['mc_event_mail_from'];
        $mc_event_mail_subject = $_POST['mc_event_mail_subject'];
        $mc_event_mail_message = $_POST['mc_event_mail_message'];
        update_option('mc_event_mail_to', $mc_event_mail_to);
        update_option('mc_event_mail_from', $mc_event_mail_from);
        update_option('mc_event_mail_subject', $mc_event_mail_subject);
        update_option('mc_event_mail_message', $mc_event_mail_message);
        update_option('mc_event_mail', $mc_event_mail);
        update_option('mc_html_email', $mc_html_email);
        echo "<div class=\"updated\"><p><strong>" . __('Email notice settings saved', 'my-calendar') . ".</strong></p></div>";
    }
    // Custom User Settings
    apply_filters('mc_save_settings', '', $_POST);
    // pull templates for passing into functions.
    $templates = get_option('mc_templates');
    $mc_title_template = esc_attr(stripslashes($templates['title']));
    $mc_details_label = esc_attr(stripslashes($templates['label']));
    $mc_link_label = esc_attr(stripslashes($templates['link']));
    ?>
 

<div class="wrap jd-my-calendar mc-settings-page" id="mc_settings">
<?php 
    my_calendar_check_db();
    ?>
    <div id="icon-options-general" class="icon32"><br /></div>
	<h2><?php 
    _e('My Calendar Options', 'my-calendar');
    ?>
</h2>
<div class="postbox-container jcd-wide">
<div class="metabox-holder">
  <?php 
    //update_option( 'ko_calendar_imported','false' ); // for testing importing.
    if (isset($_POST['import']) && $_POST['import'] == 'true') {
        $nonce = $_REQUEST['_wpnonce'];
        if (!wp_verify_nonce($nonce, 'my-calendar-nonce')) {
            die("Security check failed");
        }
        my_calendar_import();
    }
    if (get_option('ko_calendar_imported') != 'true') {
        if (function_exists('check_calendar')) {
            ?>
	<div class='import upgrade-db'>
	<p>
	<?php 
            _e('My Calendar has identified that you have the Calendar plugin by Kieran O\'Shea installed. You can import those events and categories into the My Calendar database. Would you like to import these events?', 'my-calendar');
            ?>
	</p>
		<form method="post" action="<?php 
            echo admin_url("admin.php?page=my-calendar-config");
            ?>
">
		<div><input type="hidden" name="_wpnonce" value="<?php 
            echo wp_create_nonce('my-calendar-nonce');
            ?>
" /></div>		
		<div>
		<input type="hidden" name="import" value="true" />
		<input type="submit" value="<?php 
            _e('Import from Calendar', 'my-calendar');
            ?>
" name="import-calendar" class="button-primary" />
		</div>
		</form>
	</div>
<?php 
        }
    }
    ?>

<div class="ui-sortable meta-box-sortables">   
<div class="postbox">
	<h3><?php 
    _e('My Calendar Settings', 'my-calendar');
    ?>
</h3>
	<div class="inside">
	<ul class="mc-settings checkboxes">
		<li><a href="#my-calendar-manage"><?php 
    _e('Management', 'my-calendar');
    ?>
</a></li>
		<li><a href="#my-calendar-text"><?php 
    _e('Customizable Text', 'my-calendar');
    ?>
</a></li>
		<li><a href="#my-calendar-output"><?php 
    _e('Output', 'my-calendar');
    ?>
</a></li>
		<li><a href="#my-calendar-time"><?php 
    _e('Date/Time', 'my-calendar');
    ?>
</a></li>
		<li><a href="#my-calendar-input"><?php 
    _e('Input', 'my-calendar');
    ?>
</a></li>
		<?php 
    if (current_user_can('manage_network')) {
        ?>
		<li><a href="#my-calendar-multisite"><?php 
        _e('Multi-site', 'my-calendar');
        ?>
</a></li>		
		<?php 
    }
    ?>
		<li><a href="#my-calendar-permissions"><?php 
    _e('Permissions', 'my-calendar');
    ?>
</a></li>
		<li><a href="#my-calendar-email"><?php 
    _e('Email Notifications', 'my-calendar');
    ?>
</a></li>
		<?php 
    echo apply_filters('mc_settings_section_links', '');
    ?>
	</ul>
	</div>
</div>
</div>

<div class="ui-sortable meta-box-sortables">   
<div class="postbox" id="my-calendar-manage">
	<h3><?php 
    _e('My Calendar Management', 'my-calendar');
    ?>
</h3>
	<div class="inside">
	<?php 
    if (current_user_can('administrator')) {
        ?>
    <form method="post" action="<?php 
        echo admin_url("admin.php?page=my-calendar-config");
        ?>
">
	<div><input type="hidden" name="_wpnonce" value="<?php 
        echo wp_create_nonce('my-calendar-nonce');
        ?>
" /></div> 	
	<fieldset>
    <legend><?php 
        _e('Management', 'my-calendar');
        ?>
</legend>
    <ul>
	<li><?php 
        mc_settings_field('mc_remote', __('Get data (events, categories and locations) from a remote database.', 'my-calendar'), '', '', array(), 'checkbox-single');
        ?>
</li>
	<?php 
        if (get_option('mc_remote') == 'true') {
            ?>
	<li><?php 
            _e('Add this code to your theme\'s <code>functions.php</code> file:', 'my-calendar');
            ?>
<pre>function mc_remote_db() {
	$mcdb = new wpdb('DB_USER','DB_PASSWORD','DB_NAME','DB_ADDRESS');
	return $mcdb;
}</pre>
		<?php 
            _e('You will need to allow remote connections from this site to the site hosting your My Calendar events. Replace the above placeholders with the host-site information. The two sites must have the same WP table prefix. While this option is enabled, you may not enter or edit events through this installation.', 'my-calendar');
            ?>
	</li>	
	<?php 
        }
        ?>
	<li><?php 
        mc_settings_field('mc_event_approve', __('Enable approval options.', 'my-calendar'), '', '', array(), 'checkbox-single');
        ?>
</li>
	<li><?php 
        mc_settings_field('mc_api_enabled', __('Enable external API.', 'my-calendar'), '', '', array(), 'checkbox-single');
        ?>
</li>	
	<?php 
        if (apply_filters('mc_caching_clear', false)) {
            ?>
	<li><?php 
            mc_settings_field('mc_clear_cache', __('Clear current cache. (Necessary if you edit shortcodes to change displayed categories, for example.)', 'my-calendar'), '', '', array(), 'checkbox-single');
            ?>
</li>	
	<?php 
        }
        ?>
	<li><?php 
        mc_settings_field('mc_default_sort', __('Default Sort order for Admin Events List', 'my-calendar'), array('1' => __('Event ID', 'my-calendar'), '2' => __('Title', 'my-calendar'), '3' => __('Description', 'my-calendar'), '4' => __('Start Date', 'my-calendar'), '5' => __('Author', 'my-calendar'), '6' => __('Category', 'my-calendar'), '7' => __('Location Name', 'my-calendar')), '', array(), 'select');
        ?>
</li>
	<?php 
        if (get_site_option('mc_multisite') == 2 && MY_CALENDAR_TABLE != MY_CALENDAR_GLOBAL_TABLE) {
            mc_settings_field('mc_current_table', array('0' => __('Currently editing my local calendar', 'my-calendar'), '1' => __('Currently editing the network calendar', 'my-calendar')), '0', '', array(), 'radio');
        } else {
            if (get_option('mc_remote') != 'true' && current_user_can('manage_network')) {
                ?>
			<li><?php 
                _e('You are currently working in the primary site for this network; your local calendar is also the global table.', 'my-calendar');
                ?>
</li><?php 
            }
        }
        ?>
	<li><?php 
        mc_settings_field('remigrate', __('Re-generate event occurrences table.', 'my-calendar'), '', '', array(), 'checkbox-single');
        ?>
</li>
	</ul>
	</fieldset>
		<p>
		<input type="submit" name="mc_manage" class="button-primary" value="<?php 
        _e('Save Management Settings', 'my-calendar');
        ?>
" />
		</p>
	</form>
	<?php 
    } else {
        ?>
		<?php 
        _e('My Calendar management settings are only available to administrators.', 'my-calendar');
        ?>
	<?php 
    }
    ?>
	</div>
</div>
</div>

<div class="ui-sortable meta-box-sortables">   
<div class="postbox" id="my-calendar-text">
	<h3><?php 
    _e('Text Settings', 'my-calendar');
    ?>
</h3>
	<div class="inside">
	    <form method="post" action="<?php 
    echo admin_url("admin.php?page=my-calendar-config");
    ?>
">
	<div><input type="hidden" name="_wpnonce" value="<?php 
    echo wp_create_nonce('my-calendar-nonce');
    ?>
" /></div>		
<fieldset>
	<legend><?php 
    _e('Customize Text Fields', 'my-calendar');
    ?>
</legend>
	<ul>
	<li><?php 
    mc_settings_field('mc_notime_text', __('Label for all-day events', 'my-calendar'), 'N/A');
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_previous_events', __('Previous events link', 'my-calendar'), __('Previous', 'my-calendar'), __('Use <code>{date}</code> to display date in navigation.', 'my-calendar'));
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_next_events', __('Next events link', 'my-calendar'), __('Next', 'my-calendar'), __('Use <code>{date}</code> to display date in navigation.', 'my-calendar'));
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_event_open', __('If events are open', 'my-calendar'), __('Registration is open', 'my-calendar'));
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_event_closed', __('If events are closed', 'my-calendar'), __('Registration is closed', 'my-calendar'));
    ?>
</li>	
	<li><?php 
    mc_settings_field('mc_week_caption', __('Week view caption:', 'my-calendar'), '', __('Available tag: <code>{date format=""}</code>', 'my-calendar'));
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_caption', __('Extended caption:', 'my-calendar'), '', __('Follows month/year in list views.', 'my-calendar'));
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_title_template', __('Event title template', 'my-calendar'), $mc_title_template, "<a href='" . admin_url("admin.php?page=my-calendar-help#templates") . "'>" . __("Templating Help", 'my-calendar') . '</a>');
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_details_label', __('Event details link text', 'my-calendar'), $mc_details_label, __('Tags: <code>{title}</code>, <code>{location}</code>, <code>{color}</code>, <code>{icon}</code>, <code>{date}</code>, <code>{time}</code>.', 'my-calendar'));
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_link_label', __('Event URL link text', 'my-calendar'), $mc_link_label, "<a href='" . admin_url("admin.php?page=my-calendar-help#templates") . "'>" . __("Templating Help", 'my-calendar') . '</a>');
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_event_title_template', __('Title element template', 'my-calendar'), '{title} &raquo; {date}', __('Current: %s', 'my-calendar'));
    ?>
</li>		
	</ul>
	</fieldset>	
		<p>
		<input type="submit" name="save" class="button-primary" value="<?php 
    _e('Save Custom Text Settings', 'my-calendar');
    ?>
" />
	</p>
	</form>
</div>
</div>
</div>

<div class="ui-sortable meta-box-sortables">   
<div class="postbox" id="my-calendar-output">
	<h3><?php 
    _e('Output Settings', 'my-calendar');
    ?>
</h3>
	<div class="inside">
	<form method="post" action="<?php 
    echo admin_url("admin.php?page=my-calendar-config");
    ?>
">
	<div><input type="hidden" name="_wpnonce" value="<?php 
    echo wp_create_nonce('my-calendar-nonce');
    ?>
" /></div>
	<fieldset>
	<legend><?php 
    _e('Calendar Link Targets', 'my-calendar');
    ?>
</legend>
	<ul>
	<?php 
    /* <li><?php mc_settings_field( 'mc_use_permalinks', __( 'Use Pretty Permalinks for Events','my-calendar' ), '', '', array(), 'checkbox-single' ); ?></li> This just isn't ready; add in a point release. */
    ?>
	<?php 
    $guess = mc_guess_calendar();
    ?>
	<li><?php 
    mc_settings_field('mc_uri', __('Where is your main calendar page?', 'my-calendar'), '', "<br /><small>" . __('Can be any Page or Post which includes the <code>[my_calendar]</code> shortcode.', 'my-calendar') . " {$guess}</small>", array('size' => '60'), 'url');
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_mini_uri', __('Target <abbr title="Uniform resource locator">URL</abbr> for mini calendar date links:', 'my-calendar'), '', "<br /><small>" . __('Can be any Page or Post which includes the <code>[my_calendar]</code> shortcode.', 'my-calendar') . "</small>", array('size' => '60'), 'url');
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_open_uri', __('Open calendar links to event details URL', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
	<?php 
    $disabled = !get_option('mc_uri') && !get_option('mc_mini_uri') ? array('disabled' => 'disabled') : array();
    ?>
	<li><?php 
    mc_settings_field('mc_open_day_uri', __('Mini calendar widget date links to:', 'my-calendar'), array('false' => __('jQuery pop-up view', 'my-calendar'), 'true' => __('daily view page (above)', 'my-calendar'), 'listanchor' => __('in-page anchor on main calendar page (list)', 'my-calendar'), 'calendaranchor' => __('in-page anchor on main calendar page (grid)', 'my-calendar')), '', $disabled, 'select');
    ?>
</li>
	</ul>
	<?php 
    // End General Options //
    ?>
	</fieldset>
	
	<fieldset> 
	<legend><?php 
    _e('Set Default Navigation Element Order (can be overridden in shortcodes)', 'my-calendar');
    ?>
</legend>
	<?php 
    $topnav = explode(',', get_option('mc_topnav'));
    $calendar = array('calendar');
    $botnav = explode(',', get_option('mc_bottomnav'));
    $order = array_merge($topnav, $calendar, $botnav);
    $nav_elements = array('nav' => '<div class="dashicons dashicons-arrow-left-alt2"></div> <div class="dashicons dashicons-arrow-right-alt2"></div> ' . __('Primary Previous/Next Buttons', 'my-calendar'), 'toggle' => '<div class="dashicons dashicons-list-view"></div> <div class="dashicons dashicons-calendar"></div> ' . __('Switch between list and grid views', 'my-calendar'), 'jump' => '<div class="dashicons dashicons-redo"></div> ' . __('Jump to any other month/year', 'my-calendar'), 'print' => '<div class="dashicons dashicons-list-view"></div> ' . __('Link to printable view', 'my-calendar'), 'timeframe' => '<div class="dashicons dashicons-clock"></div> ' . __('Toggle between day, week, and month view', 'my-calendar'), 'calendar' => '<div class="dashicons dashicons-calendar"></div> ' . __('The calendar', 'my-calendar'), 'key' => '<div class="dashicons dashicons-admin-network"></div> ' . __('Categories', 'my-calendar'), 'feeds' => '<div class="dashicons dashicons-rss"></div> ' . __('Links to RSS and iCal output', 'my-calendar'), 'stop' => '<div class="dashicons dashicons-no"></div> ' . __('Elements below here will be hidden.'));
    echo "<div id='mc-sortable-update' aria-live='polite'></div>";
    echo "<ul id='mc-sortable'>";
    foreach ($order as $k) {
        $k = trim($k);
        $v = isset($nav_elements[$k]) ? $nav_elements[$k] : false;
        if ($v !== false) {
            $inserted[$k] = $v;
            echo "<li class='ui-state-default mc-{$k}'><button class='up'><i class='dashicons dashicons-arrow-up'></i><span class='screen-reader-text'>Up</span></button> <button class='down'><i class='dashicons dashicons-arrow-down'></i><span class='screen-reader-text'>Down</span></button> <code>{$k}</code> {$v} <input type='hidden' name='mc_nav[]' value='{$k}' /></li>";
        }
    }
    $missed = array_diff($nav_elements, $inserted);
    foreach ($missed as $k => $v) {
        echo "<li class='ui-state-default mc-{$k}'><button class='up'><i class='dashicons dashicons-arrow-up'></i><span class='screen-reader-text'>Up</span></button> <button class='down'><i class='dashicons dashicons-arrow-down'></i><span class='screen-reader-text'>Down</span></button> <code>{$k}</code> {$v} <input type='hidden' name='mc_nav[]' value='{$k}' /></li>";
    }
    echo "</ul>";
    ?>
	</fieldset>	
	
	<fieldset>
	<legend><?php 
    _e('Grid Layout Options', 'my-calendar');
    ?>
</legend>
	<ul>
	<li><?php 
    mc_settings_field('mc_show_weekends', __('Show Weekends on Calendar', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_convert', __('Switch to list view on mobile devices', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>	
	</ul>	
	<?php 
    // End Grid Options //
    ?>
	</fieldset>	
	
	<fieldset>
	<legend><?php 
    _e('List Layout Options', 'my-calendar');
    ?>
</legend>
	<ul>
	<li><?php 
    mc_settings_field('mc_show_months', __('How many months of events to show at a time:', 'my-calendar'), '', '', array('size' => '3'), 'text');
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_show_list_info', __('Show the first event\'s title and the number of events that day next to the date.', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>	
	</ul>	
	<?php 
    // End List Options //
    ?>
	</fieldset>	

	<fieldset>
	<legend><?php 
    _e('Event Details Pop-up', 'my-calendar');
    ?>
</legend>
		<p><?php 
    _e('The checked items will be shown in your event details view. Does not apply if you are using a custom template', 'my-calendar');
    ?>
		<ul class="checkboxes">
			<li><?php 
    mc_settings_field('mc_display_author', __('Author\'s name', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_show_event_vcal', __('Link to single event iCal download', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_show_gcal', __('Link to submit event to Google Calendar', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>		
			<li><?php 
    mc_settings_field('mc_hide_icons', __('Hide Category icons', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_show_map', __('Link to Google Map', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_gmap', __('Google Map (single event view only)', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>			
			<li><?php 
    mc_settings_field('mc_show_address', __('Event Address', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_short', __('Short description', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_desc', __('Full description', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_process_shortcodes', __('Process WordPress shortcodes in descriptions', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>	
			<li><?php 
    mc_settings_field('mc_details', __('Link to event details (requires <a href=\'#mc_uri\'>URL</a>)', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_event_link', __('External link', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_event_registration', __('Registration info', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
		</ul>
	</fieldset>
	<fieldset>
	<legend><?php 
    _e('Event Category Display', 'my-calendar');
    ?>
</legend>
		<ul class='checkboxes'>
			<?php 
    mc_settings_field('mc_apply_color', array('default' => __('No category colors with titles.', 'my-calendar'), 'font' => __('Titles are in category colors.', 'my-calendar'), 'background' => __('Titles have category color as background.', 'my-calendar')), 'default', '', array(), 'radio');
    ?>
			<li><?php 
    mc_settings_field('mc_inverse_color', __('Optimize contrast for category colors.', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
		</ul>	
	<?php 
    // End Event Options //
    ?>
	</fieldset>
	<fieldset>
	<legend><?php 
    _e('Event Scheduling Defaults', 'my-calendar');
    ?>
</legend>
		<ul>
			<li><?php 
    mc_settings_field('mc_event_link_expires', __('Event links expire after event passes.', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>	
			<li><?php 
    mc_settings_field('mc_no_fifth_week', __('If a recurring event falls on a date that doesn\'t exist (like the 5th Wednesday in February), move it back one week.', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
			<li><?php 
    mc_settings_field('mc_skip_holidays', __('If an event coincides with an event in the designated "Holiday" category, do not show the event.', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
		</ul>	
	<?php 
    // End Scheduling Options //
    ?>
	</fieldset>
	<p><input type="submit" name="save" class="button-primary" value="<?php 
    _e('Save Output Settings', 'my-calendar');
    ?>
" /></p>
</form>
</div>
</div>
</div>

<div class="ui-sortable meta-box-sortables">
<div class="postbox" id="my-calendar-time">
	<h3><?php 
    _e('Calendar Time Formats', 'my-calendar');
    ?>
</h3>
	<div class="inside">
	<form method="post" action="<?php 
    echo admin_url("admin.php?page=my-calendar-config");
    ?>
">
	<div><input type="hidden" name="_wpnonce" value="<?php 
    echo wp_create_nonce('my-calendar-nonce');
    ?>
" /></div>
	<fieldset>
	<legend><?php 
    _e('Set default date/time formats', 'my-calendar');
    ?>
</legend>
	<div><input type='hidden' name='mc_dates' value='true' /></div>
	<ul>	
	<?php 
    $month_format = get_option('mc_month_format') == '' ? date_i18n('F Y') : date_i18n(get_option('mc_month_format'));
    $time_format = get_option('mc_time_format') == '' ? date_i18n(get_option('time_format')) : date_i18n(get_option('mc_time_format'));
    $week_format = get_option('mc_week_format') == '' ? date_i18n('M j, \'y') : date_i18n(get_option('mc_week_format'));
    $date_format = get_option('mc_date_format') == '' ? date_i18n(get_option('date_format')) : date_i18n(get_option('mc_date_format'));
    ?>
	<li><?php 
    mc_settings_field('mc_month_format', __('Month format (calendar headings)', 'my-calendar'), '', $month_format);
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_time_format', __('Time format', 'my-calendar'), '', $time_format);
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_week_format', __('Date in grid mode, week view', 'my-calendar'), '', $week_format);
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_date_format', __('Date Format in other views', 'my-calendar'), '', $date_format);
    ?>
</li>
	<li>
	<?php 
    _e('Date formats use syntax from the <a href="http://php.net/date">PHP <code>date()</code> function</a>. Save to update sample output.', 'my-calendar');
    ?>
	</li>
	<li><?php 
    mc_settings_field('mc_ical_utc', __('iCal times are UTC', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
	</ul>
	</fieldset>
		<p>
		<input type="submit" name="save" class="button-primary" value="<?php 
    _e('Save Date/Time Settings', 'my-calendar');
    ?>
" />
		</p>
	</form>	
	</div>
</div>
</div>


<div class="ui-sortable meta-box-sortables">   
<div class="postbox" id="my-calendar-input">
	<h3><?php 
    _e('Calendar Input Settings', 'my-calendar');
    ?>
</h3>
	<div class="inside">
<form method="post" action="<?php 
    echo admin_url("admin.php?page=my-calendar-config");
    ?>
">
	<div><input type="hidden" name="_wpnonce" value="<?php 
    echo wp_create_nonce('my-calendar-nonce');
    ?>
" /></div>
	<fieldset>
	<legend><?php 
    _e('Select which input fields will be available when adding or editing events.', 'my-calendar');
    ?>
</legend>
	<div><input type='hidden' name='mc_input' value='true' /></div>
	<ul class="checkboxes">
	<?php 
    $input_options = get_option('mc_input_options');
    $input_labels = array('event_location_dropdown' => __('Event Location Dropdown Menu', 'my-calendar'), 'event_short' => __('Event Short Description field', 'my-calendar'), 'event_desc' => __('Event Description Field', 'my-calendar'), 'event_category' => __('Event Category field', 'my-calendar'), 'event_image' => __('Event Image field', 'my-calendar'), 'event_link' => __('Event Link field', 'my-calendar'), 'event_recurs' => __('Event Recurrence Options', 'my-calendar'), 'event_open' => __('Event Registration options', 'my-calendar'), 'event_location' => __('Event Location fields', 'my-calendar'), 'event_specials' => __('Set Special Scheduling options', 'my-calendar'), 'event_access' => __("Event Accessibility", 'my-calendar'));
    $output = '';
    // if input options isn't an array, we'll assume that this plugin wasn't upgraded properly, and reset them to the default.
    if (!is_array($input_options)) {
        update_option('mc_input_options', array('event_short' => 'on', 'event_desc' => 'on', 'event_category' => 'on', 'event_image' => 'on', 'event_link' => 'on', 'event_recurs' => 'on', 'event_open' => 'on', 'event_location' => 'on', 'event_location_dropdown' => 'on', 'event_specials' => 'on', 'event_access' => 'on'));
    }
    foreach ($input_options as $key => $value) {
        $checked = $value == 'on' ? "checked='checked'" : '';
        if (isset($input_labels[$key])) {
            $output .= "<li><input type=\"checkbox\" id=\"mci_{$key}\" name=\"mci_{$key}\" {$checked} /> <label for=\"mci_{$key}\">{$input_labels[$key]}</label></li>";
        }
    }
    echo $output;
    ?>
	<li><?php 
    mc_settings_field('mc_input_options_administrators', __('Administrators see all input options', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
	</ul>
	</fieldset>
		<p>
		<input type="submit" name="save" class="button-primary" value="<?php 
    _e('Save Input Settings', 'my-calendar');
    ?>
" />
		</p>
</form>
</div>
</div>
</div>

<?php 
    if (current_user_can('manage_network')) {
        ?>
<div class="ui-sortable meta-box-sortables">   
<div class="postbox" id="my-calendar-multisite">
	<h3><?php 
        _e('Multisite Settings (Network Administrators only)', 'my-calendar');
        ?>
</h3>
	<div class="inside">
	<form method="post" action="<?php 
        echo admin_url("admin.php?page=my-calendar-config");
        ?>
">
	<div><input type="hidden" name="_wpnonce" value="<?php 
        echo wp_create_nonce('my-calendar-nonce');
        ?>
" /></div>	
	<div><input type='hidden' name='mc_network' value='true' /></div>	
	<fieldset>
	<legend><?php 
        _e('WP MultiSite configurations', 'my-calendar');
        ?>
</legend>
	<p><?php 
        _e('The central calendar is the calendar associated with the primary site in your WordPress Multisite network.', 'my-calendar');
        ?>
</p>	
	<ul>
	<li><input type="radio" value="0" id="ms0" name="mc_multisite"<?php 
        echo jd_option_selected(get_site_option('mc_multisite'), '0');
        ?>
 /> <label for="ms0"><?php 
        _e('Site owners may only post to their local calendar', 'my-calendar');
        ?>
</label></li>
	<li><input type="radio" value="1" id="ms1" name="mc_multisite"<?php 
        echo jd_option_selected(get_site_option('mc_multisite'), '1');
        ?>
 /> <label for="ms1"><?php 
        _e('Site owners may only post to the central calendar', 'my-calendar');
        ?>
</label></li>
	<li><input type="radio" value="2" id="ms2" name="mc_multisite"<?php 
        echo jd_option_selected(get_site_option('mc_multisite'), 2);
        ?>
 /> <label for="ms2"><?php 
        _e('Site owners may manage either calendar', 'my-calendar');
        ?>
</label></li>
	</ul>
	<p class="notice"><strong>*</strong> <?php 
        _e('Changes only effect input permissions. Public-facing calendars will be unchanged.', 'my-calendar');
        ?>
</p>
	<ul>
	<li><input type="radio" value="0" id="mss0" name="mc_multisite_show"<?php 
        echo jd_option_selected(get_site_option('mc_multisite_show'), '0');
        ?>
 /> <label for="mss0"><?php 
        _e('Sub-site calendars show events from their local calendar.', 'my-calendar');
        ?>
</label></li>
	<li><input type="radio" value="1" id="mss1" name="mc_multisite_show"<?php 
        echo jd_option_selected(get_site_option('mc_multisite_show'), '1');
        ?>
 /> <label for="mss1"><?php 
        _e('Sub-site calendars show events from the central calendar.', 'my-calendar');
        ?>
</label></li>
	</ul>
	</fieldset>
		<p>
		<input type="submit" name="save" class="button-primary" value="<?php 
        _e('Save Multisite Settings', 'my-calendar');
        ?>
" />
		</p>
</form>	
	</div>
</div>
</div>
<?php 
    }
    ?>

<div class="ui-sortable meta-box-sortables">   
<div class="postbox" id="my-calendar-permissions">
	<h3><?php 
    _e('My Calendar Permissions', 'my-calendar');
    ?>
</h3>
	<div class="inside mc-tabs">	
	<?php 
    if (current_user_can('administrator')) {
        ?>

    <form method="post" action="<?php 
        echo admin_url("admin.php?page=my-calendar-config");
        ?>
">
	<div><input type="hidden" name="_wpnonce" value="<?php 
        echo wp_create_nonce('my-calendar-nonce');
        ?>
" /></div> 	
	<?php 
        function mc_check_caps($role, $cap)
        {
            $role = get_role($role);
            if ($role->has_cap($cap)) {
                return " checked='checked'";
            }
        }
        function mc_cap_checkbox($role, $cap, $name)
        {
            return "<li><input type='checkbox' id='mc_caps_{$role}_{$cap}' name='mc_caps[{$role}][{$cap}]' value='on'" . mc_check_caps($role, $cap) . " /> <label for='mc_caps_{$role}_{$cap}'>{$name}</label></li>";
        }
        global $wp_roles;
        $roles = $wp_roles->get_names();
        $caps = array('mc_add_events' => __('Add Events', 'my-calendar'), 'mc_approve_events' => __('Approve Events', 'my-calendar'), 'mc_manage_events' => __('Manage Events', 'my-calendar'), 'mc_edit_cats' => __('Edit Categories', 'my-calendar'), 'mc_edit_locations' => __('Edit Locations', 'my-calendar'), 'mc_edit_styles' => __('Edit Styles', 'my-calendar'), 'mc_edit_behaviors' => __('Edit Behaviors', 'my-calendar'), 'mc_edit_templates' => __('Edit Templates', 'my-calendar'), 'mc_edit_settings' => __('Edit Settings', 'my-calendar'), 'mc_view_help' => __('View Help', 'my-calendar'));
        $role_tabs = $role_container = '';
        foreach ($roles as $role => $rolename) {
            if ($role == 'administrator') {
                continue;
            }
            $role_tabs .= "<li><a href='#mc_{$role}'>{$rolename}</a></li>\n";
            $role_container .= "<div class='wptab mc_{$role}' id='mc_{$role}' aria-live='polite'><fieldset id='mc_{$role}' class='roles'><legend>{$rolename}</legend>";
            $role_container .= "<input type='hidden' value='none' name='mc_caps[" . $role . "][none]' />\n\t\t\t<ul class='mc-settings checkboxes'>";
            foreach ($caps as $cap => $name) {
                $role_container .= mc_cap_checkbox($role, $cap, $name);
            }
            $role_container .= "\n\t\t\t</ul></fieldset></div>\n";
        }
        echo "\n\t\t<ul class='tabs'>\n\t\t\t{$role_tabs}\n\t\t</ul>\n\t\t{$role_container}";
        ?>
	
		<p>
		<input type="submit" name="mc_permissions" class="button-primary" value="<?php 
        _e('Save Permissions', 'my-calendar');
        ?>
" />
		</p>
	</form>
	<?php 
    } else {
        ?>
		<?php 
        _e('My Calendar permission settings are only available to administrators.', 'my-calendar');
        ?>
	<?php 
    }
    ?>
	
	</div>
</div>
</div>

<div class="ui-sortable meta-box-sortables">   
<div class="postbox" id="my-calendar-email">
	<h3><?php 
    _e('Calendar Email Settings', 'my-calendar');
    ?>
</h3>
	<div class="inside">
<form method="post" action="<?php 
    echo admin_url("admin.php?page=my-calendar-config");
    ?>
">
	<div><input type="hidden" name="_wpnonce" value="<?php 
    echo wp_create_nonce('my-calendar-nonce');
    ?>
" /></div>
	<fieldset>
	<legend><?php 
    _e('Email Notifications', 'my-calendar');
    ?>
</legend>
	<div><input type='hidden' name='mc_email' value='true' /></div>
	<ul>
	<li><?php 
    mc_settings_field('mc_event_mail', __('Send Email Notifications when new events are scheduled or reserved.', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_event_mail_to', __('Notification messages are sent to:', 'my-calendar'), get_bloginfo('admin_email'));
    ?>
</li>	
	<li><?php 
    mc_settings_field('mc_event_mail_from', __('Notification messages are sent from:', 'my-calendar'), get_bloginfo('admin_email'));
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_event_mail_subject', __('Email subject', 'my-calendar'), get_bloginfo('name') . ': ' . __('New event added', 'my-calendar'), '', array('size' => 60));
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_event_mail_message', __('Message Body', 'my-calendar'), __('New Event:', 'my-calendar') . "\n{title}: {date}, {time} - {event_status}", "<br /><a href='" . admin_url("admin.php?page=my-calendar-help#templates") . "'>" . __("Templating Help", 'my-calendar') . '</a>', array('cols' => 60, 'rows' => 6), 'textarea');
    ?>
</li>
	<li><?php 
    mc_settings_field('mc_html_email', __('Send HTML email', 'my-calendar'), '', '', array(), 'checkbox-single');
    ?>
</li>
	</ul>
	</fieldset>
		<p>
		<input type="submit" name="save" class="button-primary" value="<?php 
    _e('Save Email Settings', 'my-calendar');
    ?>
" />
		</p>
</form>
</div>
</div>
</div>

<?php 
    echo apply_filters('mc_after_settings', '');
    ?>

</div>
</div>

	<?php 
    mc_show_sidebar();
    ?>

</div>
<?php 
}
コード例 #4
0
function manage_my_calendar()
{
    check_my_calendar();
    global $wpdb;
    $mcdb = $wpdb;
    if (isset($_GET['mode']) && $_GET['mode'] == 'delete') {
        $event_id = isset($_GET['event_id']) ? intval($_GET['event_id']) : false;
        $sql = "SELECT event_title, event_author FROM " . my_calendar_table() . " WHERE event_id={$event_id}";
        $result = $mcdb->get_results($sql, ARRAY_A);
        if (mc_can_edit_event($event_id)) {
            if (isset($_GET['date'])) {
                $event_instance = (int) $_GET['date'];
                $sql = "SELECT occur_begin FROM " . my_calendar_event_table() . " WHERE occur_id=" . $event_instance;
                $inst = $mcdb->get_var($sql);
                $instance_date = '(' . date('Y-m-d', strtotime($inst)) . ')';
            } else {
                $instance_date = '';
            }
            ?>
			<div class="error">
			<form action="<?php 
            echo admin_url('admin.php?page=my-calendar-manage');
            ?>
" method="post">
				<p><strong><?php 
            _e('Delete Event', 'my-calendar');
            ?>
						:</strong> <?php 
            _e('Are you sure you want to delete this event?', 'my-calendar');
            ?>
					<input type="hidden" name="_wpnonce" value="<?php 
            echo wp_create_nonce('my-calendar-nonce');
            ?>
"/>
					<input type="hidden" value="delete" name="event_action"/>
					<?php 
            if (!empty($_GET['date'])) {
                ?>
						<input type="hidden" name="event_instance" value="<?php 
                echo (int) $_GET['date'];
                ?>
"/>
					<?php 
            }
            ?>
					<?php 
            if (isset($_GET['ref'])) {
                ?>
						<input type="hidden" name="ref" value="<?php 
                echo esc_url($_GET['ref']);
                ?>
"/>
					<?php 
            }
            ?>

					<input type="hidden" name="event_id" value="<?php 
            echo $event_id;
            ?>
"/>
					<input type="submit" name="submit" class="button-secondary delete"
					       value="<?php 
            _e('Delete', 'my-calendar');
            echo " &quot;" . stripslashes($result[0]['event_title']) . "&quot; {$instance_date}";
            ?>
"/>
			</form>
			</div><?php 
        } else {
            ?>
			<div class="error">
			<p><strong><?php 
            _e('You do not have permission to delete that event.', 'my-calendar');
            ?>
</strong></p>
			</div><?php 
        }
    }
    // Approve and show an Event ...originally by Roland
    if (isset($_GET['mode']) && $_GET['mode'] == 'publish') {
        if (current_user_can('mc_approve_events')) {
            $sql = "UPDATE " . my_calendar_table() . " SET event_approved = 1 WHERE event_id=" . (int) $_GET['event_id'];
            $mcdb->get_results($sql, ARRAY_A);
            mc_delete_cache();
        } else {
            ?>
			<div class="error">
				<p><strong><?php 
            _e('You do not have permission to approve that event.', 'my-calendar');
            ?>
</strong>
				</p>
			</div>
		<?php 
        }
    }
    // Reject and hide an Event ...by Roland
    if (isset($_GET['mode']) && $_GET['mode'] == 'reject') {
        if (current_user_can('mc_approve_events')) {
            $sql = "UPDATE " . my_calendar_table() . " SET event_approved = 2 WHERE event_id=" . (int) $_GET['event_id'];
            $mcdb->get_results($sql, ARRAY_A);
            mc_delete_cache();
        } else {
            ?>
			<div class="error">
				<p><strong><?php 
            _e('You do not have permission to reject that event.', 'my-calendar');
            ?>
</strong>
				</p>
			</div>
		<?php 
        }
    }
    if (!empty($_POST['mass_edit']) && isset($_POST['mass_delete'])) {
        $nonce = $_REQUEST['_wpnonce'];
        if (!wp_verify_nonce($nonce, 'my-calendar-nonce')) {
            die("Security check failed");
        }
        $events = $_POST['mass_edit'];
        $i = $total = 0;
        $deleted = $ids = array();
        foreach ($events as $value) {
            $value = (int) $value;
            $ea = "SELECT event_author FROM " . my_calendar_table() . " WHERE event_id = {$value}";
            $result = $mcdb->get_results($ea, ARRAY_A);
            $total = count($events);
            if (mc_can_edit_event($value)) {
                $delete_occurrences = "DELETE FROM " . my_calendar_event_table() . " WHERE occur_event_id = {$value}";
                $mcdb->query($delete_occurrences);
                $ids[] = (int) $value;
                $deleted[] = $value;
                $i++;
            }
        }
        $statement = implode(',', $ids);
        $sql = 'DELETE FROM ' . my_calendar_table() . " WHERE event_id IN ({$statement})";
        $result = $mcdb->query($sql);
        if ($result !== 0 && $result !== false) {
            mc_delete_cache();
            // argument: array of event IDs
            do_action('mc_mass_delete_events', $deleted);
            $message = "<div class='updated'><p>" . sprintf(__('%1$d events deleted successfully out of %2$d selected', 'my-calendar'), $i, $total) . "</p></div>";
        } else {
            $message = "<div class='error'><p><strong>" . __('Error', 'my-calendar') . ":</strong>" . __('Your events have not been deleted. Please investigate.', 'my-calendar') . "</p></div>";
        }
        echo $message;
    }
    if (!empty($_POST['mass_edit']) && isset($_POST['mass_approve'])) {
        $nonce = $_REQUEST['_wpnonce'];
        if (!wp_verify_nonce($nonce, 'my-calendar-nonce')) {
            die("Security check failed");
        }
        $events = $_POST['mass_edit'];
        $sql = 'UPDATE ' . my_calendar_table() . ' SET event_approved = 1 WHERE event_id IN (';
        $i = 0;
        $approved = array();
        foreach ($events as $value) {
            $value = (int) $value;
            $total = count($events);
            if (current_user_can('mc_approve_events')) {
                $sql .= (int) $value . ',';
                $approved[] = $value;
                $i++;
            }
        }
        $sql = substr($sql, 0, -1);
        $sql .= ')';
        $result = $mcdb->query($sql);
        if ($result == 0 || $result == false) {
            $message = "<div class='error'><p><strong>" . __('Error', 'my-calendar') . ":</strong>" . __('Your events have not been approved. Please investigate.', 'my-calendar') . "</p></div>";
        } else {
            mc_delete_cache();
            // argument: array of event IDs
            do_action('mc_mass_approve_events', $approved);
            $message = "<div class='updated'><p>" . sprintf(__('%1$d events approved successfully out of %2$d selected', 'my-calendar'), $i, $total) . "</p></div>";
        }
        echo $message;
    }
    if (!empty($_POST['mass_edit']) && isset($_POST['mass_archive'])) {
        $nonce = $_REQUEST['_wpnonce'];
        if (!wp_verify_nonce($nonce, 'my-calendar-nonce')) {
            die("Security check failed");
        }
        $events = $_POST['mass_edit'];
        $sql = 'UPDATE ' . my_calendar_table() . ' SET event_status = 0 WHERE event_id IN (';
        $i = $total = 0;
        $archived = array();
        foreach ($events as $value) {
            $total = count($events);
            $sql .= (int) $value . ',';
            $archived[] = $value;
            $i++;
        }
        $sql = substr($sql, 0, -1);
        $sql .= ')';
        $result = $mcdb->query($sql);
        if ($result == 0 || $result == false) {
            $message = "<div class='error'><p><strong>" . __('Error', 'my-calendar') . ":</strong>" . __('Could not archive those events.', 'my-calendar') . "</p></div>";
        } else {
            mc_delete_cache();
            // argument: array of event IDs
            do_action('mc_mass_archive_events', $archived);
            $message = "<div class='updated'><p>" . sprintf(__('%1$d events archived successfully out of %2$d selected.', 'my-calendar'), $i, $total) . ' ' . __('Archived events remain on your calendar, but are removed from the event manager.', 'my-calendar') . "</p></div>";
        }
        echo $message;
    }
    if (!empty($_POST['mass_edit']) && isset($_POST['mass_undo_archive'])) {
        $nonce = $_REQUEST['_wpnonce'];
        if (!wp_verify_nonce($nonce, 'my-calendar-nonce')) {
            die("Security check failed");
        }
        $events = $_POST['mass_edit'];
        $sql = 'UPDATE ' . my_calendar_table() . ' SET event_status = 1 WHERE event_id IN (';
        $i = $total = 0;
        $archived = array();
        foreach ($events as $value) {
            $total = count($events);
            $sql .= (int) $value . ',';
            $archived[] = $value;
            $i++;
        }
        $sql = substr($sql, 0, -1);
        $sql .= ')';
        $result = $mcdb->query($sql);
        if ($result == 0 || $result == false) {
            $message = "<div class='error'><p><strong>" . __('Error', 'my-calendar') . ":</strong>" . __('Could not undo the archive status on those events.', 'my-calendar') . "</p></div>";
        } else {
            mc_delete_cache();
            // argument: array of event IDs
            do_action('mc_mass_undo_archive_events', $archived);
            $message = "<div class='updated'><p>" . sprintf(__('%1$d events removed from archive successfully out of %2$d selected.', 'my-calendar'), $i, $total) . "</p></div>";
        }
        echo $message;
    }
    ?>
	<div class='wrap jd-my-calendar'>
		<h1 id="mc-manage" class="wp-heading-inline"><?php 
    _e('Manage Events', 'my-calendar');
    ?>
</h1>
		<a href="<?php 
    echo admin_url("admin.php?page=my-calendar");
    ?>
" class="page-title-action"><?php 
    _e('Add New', 'my-calendar');
    ?>
</a> 
		<hr class="wp-header-end">
		
		<div class="postbox-container jcd-wide">
			<div class="metabox-holder">
				<div class="ui-sortable meta-box-sortables">
					<div class="postbox">
						<h2><?php 
    _e('My Events', 'my-calendar');
    ?>
</h2>

						<div class="inside">
							<?php 
    mc_list_events();
    ?>
						</div>
					</div>
				</div>
			</div>
		</div>

		<?php 
    mc_show_sidebar();
    ?>
	</div>
<?php 
}
コード例 #5
0
function my_calendar($name, $format, $category, $time = 'month', $ltype = '', $lvalue = '', $id = '', $template = '', $content = '', $author = null, $host = null, $above = '', $below = '', $syear = false, $smonth = false, $sday = false, $source = 'shortcode', $site = false)
{
    if ($site) {
        $site = $site == 'global' ? BLOG_ID_CURRENT_SITE : $site;
        switch_to_blog($site);
    }
    check_my_calendar();
    // category key needs to receive the original category settings.
    $original_category = $category;
    $category = isset($_GET['mcat']) ? (int) $_GET['mcat'] : $category;
    $mc_toporder = array('nav', 'toggle', 'jump', 'print', 'timeframe');
    $mc_bottomorder = array('key', 'feeds');
    if ($above != '' || $below != '') {
        $aboves = $above == 'none' ? array() : array_map('trim', explode(',', $above));
        $belows = $below == 'none' ? array() : array_map('trim', explode(',', $below));
    } else {
        $aboves = $mc_toporder;
        $belows = $mc_bottomorder;
    }
    $used = array_merge($aboves, $belows);
    if (isset($_GET['format']) && in_array($_GET['format'], array('list', 'mini')) && $format != 'mini') {
        $format = esc_attr($_GET['format']);
    } else {
        $format = esc_attr($format);
    }
    if (isset($_GET['time']) && in_array($_GET['time'], array('day', 'week', 'month', 'month+1')) && $format != 'mini') {
        $time = esc_attr($_GET['time']);
    } else {
        $time = esc_attr($time);
    }
    $offset = 60 * 60 * get_option('gmt_offset');
    $my_calendar_body = '';
    /* filter */
    if ($time == 'day') {
        $format = 'list';
    }
    $args = array('name' => $name, 'format' => $format, 'category' => $category, 'above' => $above, 'below' => $below, 'time' => $time, 'ltype' => $ltype, 'lvalue' => $lvalue, 'author' => $author, 'id' => $id, 'above' => $above, 'below' => $below, 'host' => $host, 'syear' => $syear, 'smonth' => $smonth, 'sday' => $sday);
    // args used in Md5 hash cannot include 'time' or 'format', since those can be changed by navigation.
    $hash_args = array('name' => $name, 'category' => $category, 'above' => $above, 'below' => $below, 'ltype' => $ltype, 'lvalue' => $lvalue, 'author' => $author, 'id' => $id, 'above' => $above, 'below' => $below, 'host' => $host, 'syear' => $syear, 'smonth' => $smonth, 'sday' => $sday);
    $hash = md5(implode(',', $hash_args));
    $my_calendar_body .= apply_filters('mc_before_calendar', '', $args);
    $id = !$id ? "mc-{$hash}" : $id;
    $main_class = $id != '' ? sanitize_title($id) : 'all';
    $cid = isset($_GET['cid']) ? esc_attr(strip_tags($_GET['cid'])) : $main_class;
    if (get_option('mc_convert') == 'true') {
        $format = mc_is_mobile() && $format == 'calendar' ? 'list' : $format;
    } else {
        if (get_option('mc_convert') == 'mini') {
            $format = mc_is_mobile() ? 'mini' : $format;
        }
    }
    $format = apply_filters('mc_display_format', $format, $args);
    // mc body wrapper
    $mc_wrapper = "<div id=\"{$id}\" class=\"mc-main {$format} {$time} {$main_class}\" aria-live='assertive' aria-atomic='true'>";
    $mc_closer = "</div>";
    $date_format = get_option('mc_date_format') != '' ? get_option('mc_date_format') : get_option('date_format');
    if (isset($_GET['mc_id']) && $source != 'widget') {
        // single event, main calendar only.
        $mc_id = is_numeric($_GET['mc_id']) ? $_GET['mc_id'] : false;
        if ($mc_id) {
            $my_calendar_body .= mc_get_event($mc_id, 'html');
        }
    } else {
        if ($category == "") {
            $category = 'all';
        }
        // Deal with the week not starting on a monday
        $name_days = array("<abbr title='" . date_i18n('l', strtotime('Sunday')) . "' aria-hidden='true'>" . date_i18n('D', strtotime('Sunday')) . "</abbr><span class='screen-reader-text'>" . date_i18n('l', strtotime('Sunday')) . "</span>", "<abbr title='" . date_i18n('l', strtotime('Monday')) . "' aria-hidden='true'>" . date_i18n('D', strtotime('Monday')) . "</abbr><span class='screen-reader-text'>" . date_i18n('l', strtotime('Monday')) . "</span>", "<abbr title='" . date_i18n('l', strtotime('Tuesday')) . "' aria-hidden='true'>" . date_i18n('D', strtotime('Tuesday')) . "</abbr><span class='screen-reader-text'>" . date_i18n('l', strtotime('Tuesday')) . "</span>", "<abbr title='" . date_i18n('l', strtotime('Wednesday')) . "' aria-hidden='true'>" . date_i18n('D', strtotime('Wednesday')) . "</abbr><span class='screen-reader-text'>" . date_i18n('l', strtotime('Wednesday')) . "</span>", "<abbr title='" . date_i18n('l', strtotime('Thursday')) . "' aria-hidden='true'>" . date_i18n('D', strtotime('Thursday')) . "</abbr><span class='screen-reader-text'>" . date_i18n('l', strtotime('Thursday')) . "</span>", "<abbr title='" . date_i18n('l', strtotime('Friday')) . "' aria-hidden='true'>" . date_i18n('D', strtotime('Friday')) . "</abbr><span class='screen-reader-text'>" . date_i18n('l', strtotime('Friday')) . "</span>", "<abbr title='" . date_i18n('l', strtotime('Saturday')) . "' aria-hidden='true'>" . date_i18n('D', strtotime('Saturday')) . "</abbr><span class='screen-reader-text'>" . date_i18n('l', strtotime('Saturday')) . "</span>");
        $abbrevs = array('sun', 'mon', 'tues', 'wed', 'thur', 'fri', 'sat');
        if ($format == 'mini') {
            // PHP doesn't have a single letter abbreviation, so this has to be a translatable.
            $name_days = array("<span aria-hidden='true'>" . __('<abbr title="Sunday">S</abbr>', 'my-calendar') . "</span><span class='screen-reader-text'>" . date_i18n('l', strtotime('Sunday')) . "</span>", "<span aria-hidden='true'>" . __('<abbr title="Monday">M</abbr>', 'my-calendar') . "</span><span class='screen-reader-text'>" . date_i18n('l', strtotime('Monday')) . "</span>", "<span aria-hidden='true'>" . __('<abbr title="Tuesday">T</abbr>', 'my-calendar') . "</span><span class='screen-reader-text'>" . date_i18n('l', strtotime('Tuesday')) . "</span>", "<span aria-hidden='true'>" . __('<abbr title="Wednesday">W</abbr>', 'my-calendar') . "</span><span class='screen-reader-text'>" . date_i18n('l', strtotime('Wednesday')) . "</span>", "<span aria-hidden='true'>" . __('<abbr title="Thursday">T</abbr>', 'my-calendar') . "</span><span class='screen-reader-text'>" . date_i18n('l', strtotime('Thursday')) . "</span>", "<span aria-hidden='true'>" . __('<abbr title="Friday">F</abbr>', 'my-calendar') . "</span><span class='screen-reader-text'>" . date_i18n('l', strtotime('Friday')) . "</span>", "<span aria-hidden='true'>" . __('<abbr title="Saturday">S</abbr>', 'my-calendar') . "</span><span class='screen-reader-text'>" . date_i18n('l', strtotime('Saturday')) . "</span>");
        }
        $start_of_week = get_option('start_of_week') == 1 ? 1 : 7;
        // convert start of week to ISO 8601 (Monday/Sunday)
        $end_of_week = $start_of_week == 1 ? 7 : 6;
        $start_of_week = get_option('mc_show_weekends') == 'true' ? $start_of_week : 1;
        //$start_of_week = ( $start_of_week==1||$start_of_week==0)?$start_of_week:0;
        if ($start_of_week == '1') {
            $first = array_shift($name_days);
            $afirst = array_shift($abbrevs);
            $name_days[] = $first;
            $abbrevs[] = $afirst;
        }
        // If we don't pass arguments we want a calendar that is relevant to today (current time period)
        $c_m = 0;
        if (isset($_GET['dy']) && $main_class == $cid && ($time == 'day' || $time == 'week')) {
            //
            $c_day = (int) $_GET['dy'];
        } else {
            if ($time == 'week') {
                $dm = first_day_of_week();
                $c_day = $dm[0];
                $c_m = $dm[1];
            } else {
                if ($time == 'day') {
                    $c_day = date("d", time() + $offset);
                } else {
                    $c_day = 1;
                }
            }
        }
        if (isset($_GET['month']) && $main_class == $cid) {
            $c_month = (int) $_GET['month'];
            if (!isset($_GET['dy'])) {
                $c_day = 1;
            }
        } else {
            $xnow = date('Y-m-d', time() + $offset);
            $c_month = $c_m == 0 ? date("m", time() + $offset) : date("m", strtotime($xnow . ' -1 month'));
        }
        $is_start_of_week = date('N', current_time('timestamp')) == get_option('start_of_week') ? true : false;
        if (isset($_GET['yr']) && $main_class == $cid) {
            $c_year = (int) $_GET['yr'];
        } else {
            // weeks suck. seriously.
            if ($time == 'week' && !isset($_GET['dy'])) {
                if ($is_start_of_week) {
                    $c_year = date("Y", current_time('timestamp'));
                } else {
                    $current_year = date('Y', current_time('timestamp'));
                    $c_year = $dm[1] == 0 ? $current_year : false;
                    if (!$c_year) {
                        $c_year = date('Y', strtotime('-1 month')) == $current_year ? $current_year : $current_year - 1;
                    }
                }
            } else {
                $c_year = date("Y", current_time('timestamp'));
            }
        }
        // Years get funny if we exceed 3000, so we use this check
        if (!($c_year <= 3000 && $c_year >= 0)) {
            // No valid year causes the calendar to default to today
            $c_year = date("Y", time() + $offset);
            $c_month = date("m", time() + $offset);
            $c_day = date("d", time() + $offset);
        }
        if (!(isset($_GET['yr']) || isset($_GET['month']) || isset($_GET['dy']))) {
            // month/year based on shortcode
            $shortcode_month = $smonth != false ? $smonth : $c_month;
            $shortcode_year = $syear != false ? $syear : $c_year;
            $shortcode_day = $sday != false ? $sday : $c_day;
            // override with filters
            $c_year = apply_filters('mc_filter_year', $shortcode_year, $args);
            $c_month = apply_filters('mc_filter_month', $shortcode_month, $args);
            $c_day = apply_filters('mc_filter_day', $shortcode_day, $args);
        }
        $c_day = $c_day == 0 ? 1 : $c_day;
        // c_day can't equal 0.
        $current_date = mktime(0, 0, 0, $c_month, $c_day, $c_year);
        $c_month = str_pad($c_month, 2, '0', STR_PAD_LEFT);
        $mc_show_months = apply_filters('mc_show_months', get_option('mc_show_months'), $args);
        $num = $mc_show_months - 1;
        // the value is total months to show; need additional months to show.
        if ($format == "list" && $time != 'week') {
            // grid calendar can't show multiple months
            if ($num > 0 && $time != 'day' && $time != 'week') {
                // grid calendar date calculation
                if ($time == 'month+1') {
                    $from = date('Y-m-d', strtotime('+1 month', mktime(0, 0, 0, $c_month, 1, $c_year)));
                    $next = strtotime("+{$num} months", strtotime('+1 month', mktime(0, 0, 0, $c_month, 1, $c_year)));
                } else {
                    $from = date('Y-m-d', mktime(0, 0, 0, $c_month, 1, $c_year));
                    $next = strtotime("+{$num} months", mktime(0, 0, 0, $c_month, 1, $c_year));
                }
                $last = date('t', $next);
                $to = date('Y-m', $next) . '-' . $last;
            } else {
                $from = date('Y-m-d', mktime(0, 0, 0, $c_month, 1, $c_year));
                $to = date('Y-m-d', mktime(0, 0, 0, $c_month, date('t', mktime(0, 0, 0, $c_month, 1, $c_year)), $c_year));
            }
            $this_dates = array('from' => $from, 'to' => $to);
        } else {
            $this_dates = mc_date_array($current_date, $time);
        }
        $from = apply_filters('mc_from_date', $this_dates['from']);
        $to = apply_filters('mc_to_date', $this_dates['to']);
        $event_array = my_calendar_events($from, $to, $category, $ltype, $lvalue, 'calendar', $author, $host, '', $site);
        $no_events = empty($event_array) ? true : false;
        // define navigation element strings
        // These variables are used by reference {$value}
        $timeframe = $print = $toggle = $nav = $feeds = $jump = $mc_topnav = $mc_bottomnav = '';
        // setup print link
        $add = array('time' => $time, 'ltype' => $ltype, 'lvalue' => $lvalue, 'mcat' => $category, 'yr' => $c_year, 'month' => $c_month, 'dy' => $c_day, 'href' => urlencode(mc_get_current_url()));
        $subtract = array();
        if ($ltype == '') {
            $subtract[] = 'ltype';
            unset($add['ltype']);
        }
        if ($lvalue == '') {
            $subtract[] = 'lvalue';
            unset($add['lvalue']);
        }
        if ($category == 'all') {
            $subtract[] = 'mcat';
            unset($add['mcat']);
        }
        $print_add = array_merge($add, array('cid' => 'mc-print-view'));
        $mc_print_url = mc_build_url($print_add, $subtract, home_url());
        $print = "<div class='mc-print'><a href='{$mc_print_url}'>" . __('Print<span class="maybe-hide"> View</span>', 'my-calendar') . "</a></div>";
        // set up format toggle
        $toggle = in_array('toggle', $used) ? mc_format_toggle($format, 'yes', $time) : '';
        // set up time toggle
        if (in_array('timeframe', $used)) {
            // if dy parameter not set, use today's date instead of first day of month.
            if (isset($_GET['dy'])) {
                $current_day = absint($_GET['dy']);
                $current_set = mktime(0, 0, 0, $c_month, $current_day, $c_year);
                if (date('N', $current_set) == $start_of_week) {
                    $weeks_day = first_day_of_week($current_set);
                } else {
                    $weeks_day = first_day_of_week($current_date);
                }
            } else {
                $weeks_day = first_day_of_week(current_time('timestamp'));
            }
            $day = $weeks_day[0];
            if (isset($_GET['time']) && $_GET['time'] == 'day') {
                // don't adjust day if viewing day format
            } else {
                if (!isset($_GET['dy']) && $day > 20) {
                    $day = date('j', strtotime("{$from} + 1 week"));
                }
            }
            $timeframe = mc_time_toggle($format, $time, 'yes', $day, $c_month, $c_year);
        }
        // set up category key
        $key = in_array('key', $used) ? my_category_key($original_category) : '';
        // set up navigation links
        if (in_array('nav', $used)) {
            $pLink = my_calendar_prev_link($c_year, $c_month, $c_day, $format, $time, $mc_show_months);
            $nLink = my_calendar_next_link($c_year, $c_month, $c_day, $format, $time, $mc_show_months);
            $prevLink = mc_build_url(array('yr' => $pLink['yr'], 'month' => $pLink['month'], 'dy' => $pLink['day'], 'cid' => $main_class), array());
            $nextLink = mc_build_url(array('yr' => $nLink['yr'], 'month' => $nLink['month'], 'dy' => $nLink['day'], 'cid' => $main_class), array());
            $previous_link = apply_filters('mc_previous_link', '<li class="my-calendar-prev"><a href="' . $prevLink . '" rel="nofollow" data-rel="' . $id . '">' . $pLink['label'] . '</a></li>', $pLink);
            $next_link = apply_filters('mc_next_link', '<li class="my-calendar-next"><a href="' . $nextLink . '" rel="nofollow" data-rel="' . $id . '">' . $nLink['label'] . '</a></li>', $nLink);
            $nav = '
				<div class="my-calendar-nav">
					<ul>
						' . $previous_link . $next_link . '
					</ul>
				</div>';
        }
        // set up rss feeds
        if (in_array('feeds', $used)) {
            $ical_m = isset($_GET['month']) ? (int) $_GET['month'] : date('n');
            $ical_y = isset($_GET['yr']) ? (int) $_GET['yr'] : date('Y');
            if (!isset($nLink)) {
                $nLink = my_calendar_next_link($c_year, $c_month, $c_day, $format, $time, $mc_show_months);
            }
            $feeds = mc_rss_links($ical_y, $ical_m, $nLink, $add, $subtract);
        }
        // set up date switcher
        if (in_array('jump', $used)) {
            $jump = $time != 'week' ? mc_build_date_switcher($format, $main_class, $time) : '';
        }
        // set up above-calendar order of fields
        if (get_option('mc_topnav') != '') {
            $mc_toporder = explode(',', get_option('mc_topnav'));
        }
        if ($above != '') {
            $mc_toporder = explode(',', $above);
        }
        foreach ($mc_toporder as $value) {
            if ($value != 'none' && in_array($value, $used)) {
                $value = trim($value);
                $mc_topnav .= @${$value};
            }
        }
        if ($mc_topnav != '') {
            $mc_topnav = '<div class="my-calendar-header">' . $mc_topnav . '</div>';
        }
        if (get_option('mc_bottomnav') != '') {
            $mc_bottomorder = explode(',', get_option('mc_bottomnav'));
        }
        if ($below != '') {
            $mc_bottomorder = explode(',', $below);
        }
        foreach ($mc_bottomorder as $value) {
            if ($value != 'none' && $value != 'stop' && in_array($value, $used)) {
                $value = trim($value);
                $mc_bottomnav .= @${$value};
            }
        }
        if ($mc_bottomnav != '') {
            $mc_bottomnav = "<div class='mc_bottomnav'>{$mc_bottomnav}</div>";
        }
        if ($time == 'day') {
            $my_calendar_body .= "<div class='mc-main {$format} {$time}'>" . $mc_topnav;
            // single day uses independent cycling.
            $dayclass = strtolower(date('D', mktime(0, 0, 0, $c_month, $c_day, $c_year)));
            $from = $to = "{$c_year}-{$c_month}-{$c_day}";
            //echo "<p>Debug: $from, $to, $category, $ltype, $lvalue, $author</p>";
            $events = my_calendar_grab_events($from, $to, $category, $ltype, $lvalue, 'calendar', $author, $host, null, '', $site);
            if (!get_option('mc_skip_holidays_category') || get_option('mc_skip_holidays_category') == '') {
                $holidays = array();
            } else {
                $holidays = my_calendar_grab_events($from, $to, get_option('mc_skip_holidays_category'), $ltype, $lvalue, 'calendar', $author, $host, 'holidays', '', $site);
            }
            $events_class = mc_events_class($events, $from);
            $dateclass = mc_dateclass(time() + $offset, mktime(0, 0, 0, $c_month, $c_day, $c_year));
            $mc_events = '';
            if (is_array($events) && count($events) > 0) {
                if (is_array($holidays) && count($holidays) > 0) {
                    $mc_events .= my_calendar_draw_events($holidays, $format, $from, $time, $template);
                } else {
                    $mc_events .= my_calendar_draw_events($events, $format, $from, $time, $template);
                }
            } else {
                $mc_events .= __('No events scheduled for today!', 'my-calendar');
            }
            $hl = apply_filters('mc_heading_level', 'h3', $format, $time, $template);
            $datetime = date_i18n(apply_filters('mc_date_format', $date_format, $format, $time), strtotime("{$c_year}-{$c_month}-{$c_day}"));
            $my_calendar_body .= "\r\n\t\t\t\t<{$hl} class='mc-single'>" . apply_filters('mc_heading', $datetime, $format, $time) . "</{$hl}>" . '
				<div id="mc-day" class="' . esc_attr($dayclass . ' ' . $dateclass . ' ' . $events_class) . '">' . "{$mc_events}\n</div>\r\n\t\t\t</div>";
        } else {
            // if showing multiple months, figure out how far we're going.
            $num_months = $time == 'week' ? 1 : $mc_show_months;
            $through_date = mktime(0, 0, 0, $c_month + ($num_months - 1), $c_day, $c_year);
            $month_format = get_option('mc_month_format') == '' ? 'F Y' : get_option('mc_month_format');
            if ($time == 'month+1') {
                $current_date_header = date_i18n($month_format, strtotime('+1 month', $current_date));
            } else {
                $current_date_header = date_i18n($month_format, $current_date);
            }
            $current_month_header = date('Y', $current_date) == date('Y', $through_date) ? date_i18n('F', $current_date) : date_i18n('F Y', $current_date);
            $through_month_header = date_i18n($month_format, $through_date);
            $values = array('date' => date('Y-m-d', $current_date));
            // Add the calendar table and heading
            $caption_text = ' ' . stripslashes(trim(get_option('mc_caption')));
            $my_calendar_body .= $mc_topnav;
            if ($format == "calendar" || $format == "mini") {
                $table = apply_filters('mc_grid_wrapper', 'table', $format);
                $my_calendar_body .= "\n<{$table} class=\"my-calendar-table\">\n";
                $week_template = get_option('mc_week_caption') != '' ? get_option('mc_week_caption') : 'Week of {date format="M jS"}';
                $week_caption = jd_draw_template($values, stripslashes($week_template));
                $caption_heading = $time != 'week' ? $current_date_header . $caption_text : $week_caption . $caption_text;
                $caption = apply_filters('mc_grid_caption', 'caption', $format);
                $my_calendar_body .= "<{$caption} class=\"heading my-calendar-{$time}\">" . $caption_heading . "</{$caption}>\n";
            } else {
                // determine which header text to show depending on number of months displayed;
                if ($time != 'week' && $time != 'day') {
                    $list_heading = $num_months <= 1 ? $current_date_header . $caption_text . "\n" : $current_month_header . '&ndash;' . $through_month_header . $caption_text;
                    $list_heading = sprintf(__('Events in %s', 'my-calendar'), $list_heading);
                } else {
                    $list_heading = jd_draw_template($values, stripslashes(get_option('mc_week_caption')));
                }
                $h2 = apply_filters('mc_list_header_level', 'h2');
                $my_calendar_body .= "<{$h2} class=\"heading my-calendar-{$time}\">{$list_heading}</{$h2}>\n";
            }
            // If not a valid time or layout format, skip.
            if (in_array($format, array('calendar', 'mini', 'list')) && in_array($time, array('day', 'week', 'month', 'month+1'))) {
                $tr = apply_filters('mc_grid_week_wrapper', 'tr', $format);
                $th = apply_filters('mc_grid_header_wrapper', 'th', $format);
                $close_th = $th == 'th' ? 'th' : $th;
                $th .= $th == 'th' ? ' scope="col"' : '';
                // If in a calendar format, print the headings of the days of the week
                if ($format == "list") {
                    $my_calendar_body .= "<ul id='list-{$id}' class='mc-list'>";
                } else {
                    $my_calendar_body .= $tr == 'tr' ? "<thead>\n" : '<div class="mc-table-body">';
                    $my_calendar_body .= "<{$tr} class='mc-row'>\n";
                    for ($i = 0; $i <= 6; $i++) {
                        if ($start_of_week == 0) {
                            $class = $i < 6 && $i > 0 ? 'day-heading' : 'weekend-heading';
                        } else {
                            $class = $i < 5 ? 'day-heading' : 'weekend-heading';
                        }
                        $dayclass = strtolower(strip_tags($abbrevs[$i]));
                        if ($class == 'weekend-heading' && get_option('mc_show_weekends') == 'true' || $class != 'weekend-heading') {
                            $my_calendar_body .= "<{$th} class='{$class} {$dayclass}'>" . $name_days[$i] . "</{$close_th}>\n";
                        }
                    }
                    $my_calendar_body .= "\n</{$tr}>\n";
                    $my_calendar_body .= $tr == 'tr' ? "</thead>\n<tbody>" : '';
                }
                $odd = 'odd';
                // get and display all the events
                $show_all = false;
                // show all dates in list format.
                if ($no_events && $format == "list" && $show_all == false) {
                    // if there are no events in list format, just display that info.
                    $no_events = $content == '' ? __('There are no events scheduled during this period.', 'my-calendar') : $content;
                    $my_calendar_body .= "<li class='mc-events no-events'>{$no_events}</li>";
                } else {
                    $start = strtotime($from);
                    $end = strtotime($to);
                    do {
                        $date = date('Y-m-d', $start);
                        $is_weekend = date('N', $start) < 6 ? false : true;
                        if (get_option('mc_show_weekends') == 'true' || get_option('mc_show_weekends') != 'true' && !$is_weekend) {
                            if (date('N', $start) == $start_of_week && $format != "list") {
                                $my_calendar_body .= "<{$tr} class='mc-row'>";
                            }
                            // date-based classes
                            $monthclass = date('n', $start) == $c_month || $time != 'month' ? '' : 'nextmonth';
                            $dateclass = mc_dateclass(time() + $offset, $start);
                            $dayclass = strtolower(date_i18n('D', $start));
                            $week_format = get_option('mc_week_format') == '' ? 'M j, \'y' : get_option('mc_week_format');
                            $week_date_format = date_i18n($week_format, $start);
                            $thisday_heading = $time == 'week' ? "<small>{$week_date_format}</small>" : date('j', $start);
                            $events = isset($event_array[$date]) ? $event_array[$date] : array();
                            $events_class = mc_events_class($events, $date);
                            if (get_option('mc_list_javascript') != 1) {
                                $is_anchor = "<button type='button' class='mc-text-button'>";
                                $is_close_anchor = "</button>";
                            } else {
                                $is_anchor = $is_close_anchor = "";
                            }
                            $td = apply_filters('mc_grid_day_wrapper', 'td', $format);
                            if (!empty($events)) {
                                $hide_nextmonth = apply_filters('mc_hide_nextmonth', false);
                                if ($hide_nextmonth == true && $monthclass == 'nextmonth') {
                                    $event_output = ' ';
                                } else {
                                    $event_output = my_calendar_draw_events($events, $format, $date, $time, $template);
                                }
                                if ($event_output === true) {
                                    $event_output = ' ';
                                }
                                if ($format == 'mini' && $event_output != '') {
                                    if (get_option('mc_open_day_uri') == 'true' || get_option('mc_open_day_uri') == 'false') {
                                        // yes, this is weird. it's from some old settings...
                                        $target = array('yr' => date('Y', $start), 'month' => date('m', $start), 'dy' => date('j', $start), 'time' => 'day');
                                        if ($category != '') {
                                            $target['mcat'] = $category;
                                        }
                                        $day_url = mc_build_url($target, array('month', 'dy', 'yr', 'ltype', 'loc', 'mcat', 'cid', 'mc_id'), apply_filters('mc_modify_day_uri', get_option('mc_uri')));
                                        $link = get_option('mc_uri') != '' && !is_numeric(get_option('mc_uri')) ? $day_url : '#';
                                    } else {
                                        $atype = str_replace('anchor', '', get_option('mc_open_day_uri'));
                                        $ad = str_pad(date('j', $start), 2, '0', STR_PAD_LEFT);
                                        // need to match format in ID
                                        $am = str_pad($c_month, 2, '0', STR_PAD_LEFT);
                                        $date_url = mc_build_url(array('yr' => $c_year, 'month' => $c_month, 'dy' => date('j', $start)), array('month', 'dy', 'yr', 'ltype', 'loc', 'mcat', 'cid', 'mc_id'), get_option('mc_mini_uri'));
                                        $link = esc_url(get_option('mc_mini_uri') != '' ? $date_url . '#' . $atype . '-' . $c_year . '-' . $am . '-' . $ad : '#');
                                    }
                                    $element = "a href='{$link}'";
                                    $close = 'a';
                                    $trigger = 'trigger';
                                } else {
                                    $element = 'span';
                                    $close = 'span';
                                    $trigger = '';
                                }
                                // set up events
                                if ($is_weekend && get_option('mc_show_weekends') == 'true' || !$is_weekend) {
                                    $weekend_class = $is_weekend ? 'weekend' : '';
                                    if ($format == "list") {
                                        if (get_option('mc_show_list_info') == 'true') {
                                            $title = ' - ' . $is_anchor . "<span class='mc-list-details'>" . mc_list_title($events) . "</span>" . $is_close_anchor;
                                        } else {
                                            $title = '';
                                        }
                                        if ($event_output != '') {
                                            $my_calendar_body .= "\r\n\t\t\t\t\t\t\t\t\t\t\t\t<li id='{$format}-{$date}' class='mc-events " . esc_attr("{$dayclass} {$dateclass} {$events_class} {$odd}") . "'>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t<strong class=\"event-date\">{$is_anchor}" . date_i18n(apply_filters('mc_date_format', $date_format, 'list'), $start) . "{$is_close_anchor}" . "{$title}</strong>" . $event_output . "\r\n\t\t\t\t\t\t\t\t\t\t\t\t</li>";
                                            $odd = $odd == 'odd' ? 'even' : 'odd';
                                        }
                                    } else {
                                        $my_calendar_body .= "\r\n\t\t\t\t\t\t\t\t\t\t\t\t<{$td} id='{$format}-{$date}' class='" . esc_attr("{$dayclass} {$dateclass} {$weekend_class} {$monthclass} {$events_class}") . " day-with-date'>" . "\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t<{$element} class='mc-date {$trigger}'><span aria-hidden='true'>{$thisday_heading}</span><span class='screen-reader-text'>" . date_i18n(get_option('mc_date_format'), strtotime($date)) . "</span></{$close}>" . $event_output . "\r\n\t\t\t\t\t\t\t\t\t\t\t\t</{$td}>\n";
                                    }
                                }
                            } else {
                                // set up no events
                                if ($format != "list") {
                                    $weekend_class = $is_weekend ? 'weekend' : '';
                                    $my_calendar_body .= "\r\n\t\t\t\t\t\t\t\t\t\t\t\t<{$td} class='no-events {$dayclass} {$dateclass} {$weekend_class} {$monthclass} day-with-date'>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t<span class='mc-date no-events'><span aria-hidden='true'>{$thisday_heading}</span><span class='screen-reader-text'>" . date_i18n(get_option('mc_date_format'), strtotime($date)) . "</span></span>\r\n\t\t\t\t\t\t\t\t\t\t\t\t</{$td}>\n";
                                } else {
                                    if ($show_all == true) {
                                        $my_calendar_body .= "\r\n\t\t\t\t\t\t\t\t\t\t\t<li id='{$format}-{$date}' class='no-events {$dayclass} {$dateclass} {$events_class} {$odd}'>\r\n\t\t\t\t\t\t\t\t\t\t\t\t<strong class=\"event-date\">{$is_anchor}" . date_i18n($date_format, $start) . "{$is_close_anchor}</strong></li>";
                                        $odd = $odd == 'odd' ? 'even' : 'odd';
                                    }
                                }
                            }
                            if (date('N', $start) == $end_of_week && $format != "list") {
                                $my_calendar_body .= "</{$tr}>\n";
                                // end of 'is beginning of week'
                            }
                        }
                        $start = strtotime("+1 day", $start);
                    } while ($start <= $end);
                }
                $table = apply_filters('mc_grid_wrapper', 'table', $format);
                $end = $table == 'table' ? "\n</tbody>\n</table>" : "</div></{$table}>";
                $my_calendar_body .= $format == "list" ? "\n</ul>" : $end;
            } else {
                // only show error message if user has permissions
                if (current_user_can('manage_options')) {
                    if (!in_array($format, array('list', 'calendar', 'mini'))) {
                        $yours = sprintf(esc_html__("Your format: %s", 'my-calendar'), $format);
                        $my_calendar_body .= "<p class='mc-error-format'>" . __("Unrecognized calendar format. Please use one of 'list', 'calendar', or 'mini'.", 'my-calendar') . "{$yours}</p>";
                    }
                    if (!in_array($time, array('day', 'week', 'month', 'month+1'))) {
                        $yours = sprintf(esc_html__("Your time period: %s", 'my-calendar'), $time);
                        $my_calendar_body .= "<p class='mc-error-time'>" . __("Unrecognized calendar time period. Please use one of 'day', 'week', or 'month'.", 'my-calendar') . "{$yours}</p>";
                    }
                }
            }
            $my_calendar_body .= $mc_bottomnav;
        }
    }
    // The actual printing is done by the shortcode function.
    $my_calendar_body .= apply_filters('mc_after_calendar', '', $args);
    if ($site) {
        restore_current_blog();
    }
    return $mc_wrapper . apply_filters('my_calendar_body', $my_calendar_body) . $mc_closer;
}
コード例 #6
0
ファイル: my-calendar.php プロジェクト: newmight2015/psmpsm
function mc_plugin_activated()
{
    flush_rewrite_rules();
    mc_upgrade_db();
    check_my_calendar();
}