/**
  * Fill out the Calendar feed post type columns.
  *
  * @since  3.0.0
  *
  * @param  string $column_name Column identifier.
  * @param  int    $post_id     The calendar feed post id.
  *
  * @return void
  */
 public function calendar_feed_column_content($column_name, $post_id)
 {
     switch ($column_name) {
         case 'feed':
             $feed = simcal_get_feed($post_id);
             echo isset($feed->name) ? $feed->name : '—';
             break;
         case 'calendar':
             $info = '—';
             if ($terms = wp_get_object_terms($post_id, 'calendar_type')) {
                 $calendar_type = sanitize_title(current($terms)->name);
                 $calendar = simcal_get_calendar($calendar_type);
                 if ($calendar instanceof Calendar) {
                     $info = $calendar->name;
                     $views = get_post_meta($post_id, '_calendar_view', true);
                     $view = isset($views[$calendar->type]) ? $views[$calendar->type] : '';
                     if (isset($calendar->views[$view])) {
                         $info .= ' → ' . $calendar->views[$view];
                     }
                 }
             }
             echo $info;
             break;
         case 'shortcode':
             simcal_print_shortcode_tip($post_id);
             break;
     }
 }
 /**
  * Constructor.
  *
  * @since 3.0.0
  */
 public function __construct()
 {
     $this->id = 'feeds';
     $this->option_group = 'settings';
     $this->label = __('Event Sources', 'google-calendar-events');
     //$this->description  = __( 'Manage calendar event sources settings.', 'google-calendar-events' );
     $feeds_settings = array();
     $feeds = simcal_get_feed_types();
     if (!empty($feeds) && is_array($feeds)) {
         foreach ($feeds as $feed) {
             $feed_type = simcal_get_feed($feed);
             if ($feed_type instanceof Feed) {
                 $settings = $feed_type->settings_fields();
                 if (!empty($settings)) {
                     $feeds_settings[$feed] = $settings;
                 }
             }
         }
     }
     $this->feed_types = $feeds_settings;
     $this->sections = $this->add_sections();
     $this->fields = $this->add_fields();
 }
    /**
     * Print the meta box settings handle.
     *
     * @since  3.0.0
     * @access  private
     *
     * @param \WP_Post $post
     */
    private static function settings_handle($post)
    {
        $feed_options = $calendar_options = $calendar_views = array();
        $feed_types = simcal_get_feed_types();
        foreach ($feed_types as $feed_type) {
            $feed = simcal_get_feed($feed_type);
            if ($feed instanceof Feed) {
                $feed_options[$feed_type] = $feed->name;
            }
        }
        $calendar_types = simcal_get_calendar_types();
        foreach ($calendar_types as $calendar_type => $views) {
            $calendar = simcal_get_calendar($calendar_type);
            if ($calendar instanceof Calendar) {
                $calendar_options[$calendar_type] = $calendar->name;
                $calendar_views[$calendar_type] = $calendar->views;
            }
        }
        if ($feed_options) {
            if ($feed_types = wp_get_object_terms($post->ID, 'calendar_feed')) {
                $feed_type = sanitize_title(current($feed_types)->name);
            } else {
                $feed_type = apply_filters('simcal_default_feed_type', 'google');
            }
            ?>
			<label for="_feed_type"><span><?php 
            _e('Event Source', 'google-calendar-events');
            ?>
</span>
				<select name="_feed_type" id="_feed_type">
					<optgroup label="<?php 
            _ex('Get events from', 'From which calendar source to load events from', 'google-calendar-events');
            ?>
">
						<?php 
            foreach ($feed_options as $feed => $name) {
                ?>
							<option value="<?php 
                echo $feed;
                ?>
" <?php 
                selected($feed, $feed_type, true);
                ?>
><?php 
                echo $name;
                ?>
</option>
						<?php 
            }
            ?>
					</optgroup>
				</select>
			</label>
			<?php 
        }
        if ($calendar_options) {
            if ($calendar_types = wp_get_object_terms($post->ID, 'calendar_type')) {
                $calendar_type = sanitize_title(current($calendar_types)->name);
            } else {
                $calendar_type = apply_filters('simcal_default_calendar_type', 'default-calendar');
            }
            ?>
			<label for="_calendar_type"><span><?php 
            _e('Calendar', 'google-calendar-events');
            ?>
</span>
				<select name="_calendar_type" id="_calendar_type">
					<optgroup label="<?php 
            _e('Calendar to use', 'google-calendar-events');
            ?>
">
						<?php 
            foreach ($calendar_options as $calendar => $name) {
                ?>
							<option value="<?php 
                echo $calendar;
                ?>
" <?php 
                selected($calendar, $calendar_type, true);
                ?>
><?php 
                echo $name;
                ?>
</option>
						<?php 
            }
            ?>
					</optgroup>
				</select>
			</label>
			<?php 
            if ($calendar_views) {
                $calendar_view = get_post_meta($post->ID, '_calendar_view', true);
                foreach ($calendar_views as $calendar => $views) {
                    $calendar_type_view = isset($calendar_view[$calendar]) ? $calendar_view[$calendar] : '';
                    ?>
					<label for="_calendar_view_<?php 
                    echo $calendar;
                    ?>
"><span><?php 
                    _e('View', 'google-calendar-events');
                    ?>
</span>
						<select name="_calendar_view[<?php 
                    echo $calendar;
                    ?>
]" id="_calendar_view_<?php 
                    echo $calendar;
                    ?>
">
							<optgroup label="<?php 
                    _e('View to display', 'google-calendar-events');
                    ?>
">
								<?php 
                    foreach ($views as $view => $name) {
                        ?>
									<option value="<?php 
                        echo $view;
                        ?>
" <?php 
                        selected($view, $calendar_type_view, true);
                        ?>
><?php 
                        echo $name;
                        ?>
</option>
								<?php 
                    }
                    ?>
							</optgroup>
						</select>
					</label>
					<?php 
                }
            }
        }
    }
 /**
  * Constructor.
  *
  * @since 3.0.0
  *
  * @param int|object|\WP_Post|Calendar $calendar
  * @param string $view
  */
 public function __construct($calendar, $view = '')
 {
     // Set the post object.
     $this->set_post_object($calendar);
     if (!is_null($this->post)) {
         // Set calendar type and events source.
         $this->set_taxonomies();
         // Set calendar default datetime properties.
         $this->set_timezone();
         $this->set_start_of_week();
         $this->set_static();
         // Set calendar start.
         $this->set_start();
         // Set the events template.
         $this->set_events_template();
         // Get events source data.
         $feed = simcal_get_feed($this);
         if ($feed instanceof Feed) {
             if (!empty($feed->events)) {
                 if (is_array($feed->events)) {
                     $this->set_events($feed->events);
                     if ('use_calendar' == get_post_meta($this->id, '_feed_timezone_setting', true)) {
                         $this->timezone = $feed->timezone;
                         $this->set_start();
                     }
                 } elseif (is_string($feed->events)) {
                     $this->errors[] = $feed->events;
                 }
             }
         }
         // Set general purpose timestamps.
         $now = Carbon::now($this->timezone);
         $this->now = $now->getTimestamp();
         $this->today = $now->startOfDay()->getTimestamp();
         $this->offset = $now->getOffset();
         // Set date time formatting.
         $this->set_date_format();
         $this->set_time_format();
         $this->set_datetime_separator();
         // Set earliest and latest event timestamps.
         if ($this->events && is_array($this->events)) {
             $this->earliest_event = intval(current(array_keys($this->events)));
             $this->latest_event = intval(key(array_slice($this->events, -1, 1, true)));
         }
         // Set calendar end.
         $this->set_end();
         // Set view.
         if (!$view) {
             $calendar_view = get_post_meta($this->id, '_calendar_view', true);
             $calendar_view = isset($calendar_view[$this->type]) ? $calendar_view[$this->type] : '';
             $view = esc_attr($calendar_view);
         }
     }
     // Get view.
     $this->view = $this->get_view($view);
 }
 /**
  * Make a calendar grid.
  *
  * Outputs an html calendar according to month and year passed in arguments.
  * Loosely inspired by: http://davidwalsh.name/php-calendar
  * Adjusted by timezone and with an arbitrary week start day.
  *
  * @since  3.0.0
  * @access private
  *
  * @param  int $month The month to print (two digits).
  * @param  int $year  The corresponding year (four digits).
  * @param  int $id    The calendar id.
  *
  * @return string
  */
 private function draw_month($month, $year, $id = 0)
 {
     $calendar = $this->calendar;
     if (empty($calendar)) {
         $calendar = simcal_get_calendar(intval($id));
         if (!$calendar) {
             return '';
         }
     }
     $events = $calendar->events;
     $feed = simcal_get_feed($calendar);
     $feed_timezone = get_post_meta($feed->post_id, '_feed_timezone', true);
     // Variables to cycle days in current month and find today in calendar.
     $now = $calendar->now;
     $current = Carbon::create($year, $month, 1, 0, 0, 0, $calendar->timezone);
     $current_min = $current->getTimestamp();
     $current_max = $current->endOfDay()->getTimestamp();
     // Calendar grid variables.
     $week_starts = $calendar->week_starts;
     $week_of_year = $current->weekOfYear;
     // Relative count of the week number of the year.
     $month_starts = $current->dayOfWeek;
     // Day upon which the month starts.
     $days_in_month = $current->daysInMonth;
     // Number of days in the given month.
     // Set current month events timestamp boundaries.
     $this->start = $current_min;
     $this->end = $current->endOfMonth()->timestamp;
     // Get daily events for this month.
     if ($events && is_array($events)) {
         // Filter events within the boundaries previously set above.
         $timestamps = array_keys($events);
         $lower_bound = array_filter($timestamps, array($this, 'filter_events_before'));
         $higher_bound = array_filter($lower_bound, array($this, 'filter_events_after'));
         $filtered = is_array($events) && is_array($higher_bound) && !empty($events) && !empty($higher_bound) ? array_intersect_key($events, array_combine($higher_bound, $higher_bound)) : array();
         // Put resulting events in an associative array, with day of the month as key for easy retrieval in calendar days loop.
         $day_events = array();
         foreach ($filtered as $timestamp => $events_in_day) {
             foreach ($events_in_day as $event) {
                 if ($event instanceof Event) {
                     $day = intval(Carbon::createFromTimestamp($timestamp, $event->timezone)->endOfDay()->day);
                     $day_events[$day][] = $event;
                 }
             }
         }
         ksort($day_events, SORT_NUMERIC);
     }
     ob_start();
     echo '<tbody class="simcal-month simcal-month-' . $month . '">' . "\n";
     echo "\t" . '<tr class="simcal-week simcal-week-' . $week_of_year . '">';
     $days_in_row = 0;
     // Week may start on an arbitrary day (sun, 0 - sat, 6).
     $week_day = $week_starts;
     // This fixes a possible bug when a month starts by Sunday (0).
     if (0 !== $week_starts) {
         $b = $month_starts === 0 ? 7 : $month_starts;
     } else {
         $b = $month_starts;
     }
     // Void days in first week.
     for ($a = $week_starts; $a < $b; $a++) {
         $last_void_day_class = $a === $b - 1 ? 'simcal-day-void-last' : '';
         echo '<td class="simcal-day simcal-day-void ' . $last_void_day_class . '"></td>' . "\n";
         // Reset day of the week count (sun, 0 - sat, 6).
         if ($week_day === 6) {
             $week_day = -1;
         }
         $week_day++;
         $days_in_row++;
     }
     // Actual days of the month.
     for ($day = 1; $day <= $days_in_month; $day++) {
         $count = 0;
         $calendar_classes = array();
         $day_classes = 'simcal-day-' . $day . ' simcal-weekday-' . $week_day;
         $border_style = $bg_color = $color = '';
         // Is this the present, the past or the future, Doc?
         if ($current_min <= $now && $current_max >= $now) {
             $day_classes .= ' simcal-today simcal-present simcal-day';
             $the_color = new Color($calendar->today_color);
             $bg_color = '#' . $the_color->getHex();
             $color = $the_color->isDark() ? '#ffffff' : '#000000';
             $border_style = ' style="border: 1px solid ' . $bg_color . ';"';
         } elseif ($current_max < $now) {
             $day_classes .= ' simcal-past simcal-day';
         } elseif ($current_min > $now) {
             $day_classes .= ' simcal-future simcal-day';
         }
         // Print events for the current day in loop, if found any.
         if (isset($day_events[$day])) {
             $bullet_colors = array();
             $list_events = '<ul class="simcal-events">';
             foreach ($day_events[$day] as $event) {
                 $event_classes = $event_visibility = '';
                 if ($event instanceof Event) {
                     if ($feed->type == 'grouped-calendars') {
                         date_default_timezone_set($feed_timezone);
                     } else {
                         date_default_timezone_set($event->timezone);
                     }
                     // Store the calendar id where the event belongs (useful in grouped calendar feeds)
                     $calendar_class = 'simcal-events-calendar-' . strval($event->calendar);
                     $calendar_classes[] = $calendar_class;
                     $recurring = $event->recurrence ? 'simcal-event-recurring ' : '';
                     $has_location = $event->venue ? 'simcal-event-has-location ' : '';
                     $event_classes .= 'simcal-event ' . $recurring . $has_location . $calendar_class . ' simcal-tooltip';
                     // Toggle some events visibility if more than optional limit.
                     if ($calendar->events_limit > -1 && $count >= $calendar->events_limit) {
                         $event_classes .= ' simcal-event-toggled';
                         $event_visibility = ' style="display: none"';
                     }
                     // Event title in list.
                     $title = !empty($event->title) ? trim($event->title) : __('Event', 'google-calendar-events');
                     if ($calendar->trim_titles >= 1) {
                         $title = strlen($title) > $calendar->trim_titles ? mb_substr($title, 0, $calendar->trim_titles) . '&hellip;' : $title;
                     }
                     // Event color.
                     $bullet = '';
                     //$bullet_color = '#000';
                     $event_color = $event->get_color();
                     if (!empty($event_color)) {
                         $bullet = '<span style="color: ' . $event_color . ';">&#9632;</span> ';
                         $bullet_colors[] = $event_color;
                     } else {
                         $bullet_colors[] = '#000';
                     }
                     // Event contents.
                     $list_events .= "\t" . '<li class="' . $event_classes . '"' . $event_visibility . ' itemscope itemtype="http://schema.org/Event">' . "\n";
                     $list_events .= "\t\t" . '<span class="simcal-event-title">' . $bullet . $title . '</span>' . "\n";
                     $list_events .= "\t\t" . '<div class="simcal-event-details simcal-tooltip-content" style="display: none;">' . $calendar->get_event_html($event) . '</div>' . "\n";
                     $list_events .= "\t" . '</li>' . "\n";
                     $count++;
                 }
             }
             if ($current_min <= $now && $current_max >= $now) {
                 $day_classes .= ' simcal-today-has-events';
             }
             $day_classes .= ' simcal-day-has-events simcal-day-has-' . strval($count) . '-events';
             if ($calendar_classes) {
                 $day_classes .= ' ' . trim(implode(' ', array_unique($calendar_classes)));
             }
             $list_events .= '</ul>' . "\n";
             // Optional button to toggle hidden events in list.
             if ($calendar->events_limit > -1 && $count > $calendar->events_limit) {
                 $list_events .= '<button class="simcal-events-toggle"><i class="simcal-icon-down simcal-icon-animate"></i></button>';
             }
         } else {
             // Empty cell for day with no events.
             $list_events = '<span class="simcal-no-events"></span>';
         }
         // The actual days with numbers and events in each row cell.
         echo '<td class="' . $day_classes . '" data-events-count="' . strval($count) . '">' . "\n";
         if ($color) {
             $day_style = ' style="background-color: ' . $bg_color . '; color: ' . $color . '"';
         } elseif ($count > 0) {
             $the_color = new Color($calendar->days_events_color);
             $color = !$color ? $the_color->isDark() ? '#ffffff' : '#000000' : $color;
             $bg_color = !$bg_color ? '#' . $the_color->getHex() : $bg_color;
             $day_style = ' style="background-color: ' . $bg_color . '; color: ' . $color . '"';
         } else {
             $day_style = '';
         }
         echo "\t" . '<div' . $border_style . '>' . "\n";
         echo "\t\t" . '<span class="simcal-day-label simcal-day-number"' . $day_style . '>' . $day . '</span>' . "\n";
         echo "\t\t" . $list_events . "\n";
         echo "\t\t";
         echo '<span class="simcal-events-dots" style="display: none;">';
         // Event bullets for calendar mobile mode.
         for ($i = 0; $i < $count; $i++) {
             echo '<b style="color: ' . $bullet_colors[$i] . ';"> &bull; </b>';
         }
         echo '</span>' . "\n";
         echo "\t" . '</div>' . "\n";
         echo '</td>' . "\n";
         // Reset day of the week count (sun, 0 - sat, 6).
         if ($week_day === 6) {
             $week_day = -1;
         }
         $week_day++;
         // Reset count of days for this row (0-6).
         if ($days_in_row === 6) {
             // Close the week row.
             echo '</tr>';
             // Open a new week row.
             if ($day < $days_in_month) {
                 echo '<tr class="simcal-week simcal-week-' . $week_of_year++ . '">' . "\n";
             }
             $days_in_row = -1;
         }
         $days_in_row++;
         $current_min = Carbon::createFromTimestamp($current_min, $calendar->timezone)->addDay()->getTimestamp();
         $current_max = Carbon::createFromTimestamp($current_max, $calendar->timezone)->addDay()->getTimestamp();
     }
     // Void days at the end of the month.
     $remainder_days = 6 - $days_in_row;
     for ($i = 0; $i <= $remainder_days; $i++) {
         $last_void_day_class = $i == $remainder_days ? 'simcal-day-void-last' : '';
         echo '<td class="simcal-day simcal-day-void ' . $last_void_day_class . '"></td>' . "\n";
         $week_day++;
     }
     echo "\t" . '</tr>' . "\n";
     echo '</tbody>' . "\n";
     date_default_timezone_set($calendar->site_timezone);
     return ob_get_clean();
 }
    /**
     * Print the advanced settings panel.
     *
     * @since  3.0.0
     * @access private
     *
     * @param  \WP_Post $post
     */
    private static function advanced_settings_panel($post)
    {
        ?>
		<table>
			<thead>
			<tr><th colspan="2"><?php 
        _e('Date and Time', 'google-calendar-events');
        ?>
</th></tr>
			</thead>
			<tbody class="simcal-panel-section simcal-panel-datetime-formatting">
			<tr class="simcal-panel-field">
				<th><label for="_calendar_timezone_setting"><?php 
        _e('Timezone', 'google-calendar-events');
        ?>
</label></th>
				<td>
					<?php 
        $timezone_wordpress = simcal_get_wp_timezone();
        $timezone_default = $timezone_wordpress ? $timezone_wordpress : 'UTC';
        $timezone_setting = esc_attr(get_post_meta($post->ID, '_feed_timezone_setting', true));
        $timezone = esc_attr(get_post_meta($post->ID, '_feed_timezone', true));
        $timezone = $timezone ? $timezone : $timezone_default;
        $show_use_calendar = isset(simcal_get_feed($post)->type);
        if ($show_use_calendar) {
            $show_use_calendar = simcal_get_feed($post)->type !== 'grouped-calendars' ? 1 : 0;
        } else {
            $show_use_calendar = true;
        }
        ?>
					<select name="_feed_timezone_setting"
							id="_feed_timezone_setting"
							class="simcal-field simcal-field-select simcal-field-inline simcal-field-show-other"
							data-show-field-on-choice="true">
						<option value="use_site" <?php 
        selected('use_site', $timezone_setting, true);
        ?>
><?php 
        printf(_x('Site default', 'Use this site default setting', 'google-calendar-events') . ' (%s)', $timezone_default);
        ?>
</option>
						<?php 
        if ($show_use_calendar) {
            ?>
							<option id="use_calendar" value="use_calendar" data-show-field="_use_calendar_warning" <?php 
            selected('use_calendar', $timezone_setting, true);
            ?>
><?php 
            _ex('Events source default', 'Use the calendar default setting', 'google-calendar-events');
            ?>
</option>
						<?php 
        }
        ?>
						<option value="use_custom" data-show-field="_feed_timezone" <?php 
        selected('use_custom', $timezone_setting, true);
        ?>
><?php 
        _ex('Custom', 'Use a custom setting', 'google-calendar-events');
        ?>
</option>
					</select>
					<select name="_feed_timezone"
							id="_feed_timezone"
							class="simcal-field simcal-field-select simcal-field-inline"
						<?php 
        echo 'use_custom' != $timezone_setting ? 'style="display: none;"' : '';
        ?>
>
						<?php 
        echo wp_timezone_choice($timezone);
        ?>
					</select>
					<i class="simcal-icon-help simcal-help-tip" data-tip="<?php 
        _e('Using a different timezone may alter the date and time display of your calendar events. It is recommended to keep the calendar default timezone.', 'google-calendar-events');
        ?>
"></i>
					<p id="_use_calendar_warning" style="display: none;" class="simcal-field">
						<?php 
        printf(__('<strong>Warning:</strong> Using this option can return unexpected results if you have specified <a href="%s" target="_blank">event level</a> timezones.', 'google-calendar-events'), 'http://docs.simplecalendar.io/timezone-settings/');
        ?>
					</p>
				</td>
			</tr>
			<tr class="simcal-panel-field">
				<th><label for="_calendar_date_format_setting"><?php 
        _e('Date Format', 'google-calendar-events');
        ?>
</label></th>
				<td>
					<?php 
        $date_format_setting = esc_attr(get_post_meta($post->ID, '_calendar_date_format_setting', true));
        $date_format_default = esc_attr(get_option('date_format'));
        $date_format = esc_attr(get_post_meta($post->ID, '_calendar_date_format', true));
        $date_format_php = esc_attr(get_post_meta($post->ID, '_calendar_date_format_php', true));
        $date_format_php = $date_format_php ? $date_format_php : $date_format_default;
        ?>
					<select name="_calendar_date_format_setting"
							id="_calendar_date_format_setting"
							class="simcal-field simcal-field-select simcal-field-show-other">
						<option value="use_site" data-show-field="_calendar_date_format_default" <?php 
        selected('use_site', $date_format_setting, true);
        ?>
><?php 
        _ex('Site default', 'Use this site default setting', 'google-calendar-events');
        ?>
</option>
						<option value="use_custom" data-show-field="_calendar_date_format" <?php 
        selected('use_custom', $date_format_setting, true);
        ?>
><?php 
        _ex('Custom', 'Use a custom setting', 'google-calendar-events');
        ?>
</option>
						<option value="use_custom_php" data-show-field="_calendar_date_format_php_field" <?php 
        selected('use_custom_php', $date_format_setting, true);
        ?>
><?php 
        _e('Custom (PHP format)', 'google-calendar-events');
        ?>
</option>
					</select>
					<i class="simcal-icon-help simcal-help-tip" data-tip="<?php 
        _e('This option sets how calendars display event dates. It is recommended to keep your site default setting.', 'google-calendar-events');
        ?>
"></i>
					<p id="_calendar_date_format_default" style="<?php 
        echo $date_format_setting != 'use_site' ? 'display: none;' : '';
        ?>
">
						<em><?php 
        _e('Preview', 'google-calendar-events');
        ?>
:</em>&nbsp;&nbsp;
						<code><?php 
        echo date_i18n($date_format_default, time());
        ?>
</code>
					</p>
					<?php 
        simcal_print_field(array('type' => 'datetime-format', 'subtype' => 'date', 'name' => '_calendar_date_format', 'id' => '_calendar_date_format', 'value' => $date_format, 'style' => $date_format_setting != 'use_custom' ? array('display' => 'none') : ''));
        ?>
					<div class="simcal-field-datetime-format-php" id="_calendar_date_format_php_field" style="<?php 
        echo $date_format_setting != 'use_custom_php' ? 'display: none;' : '';
        ?>
">
						<br>
						<label for="_calendar_date_format_php">
							<input type="text"
								   name="_calendar_date_format_php"
								   id="_calendar_date_format_php"
								   class="simcal-field simcal-field-text simcal-field-small"
								   value="<?php 
        echo $date_format_php;
        ?>
" />
							<?php 
        printf(__('Enter a date format using %s values.', 'google-calendar-events'), '<a href="//php.net/manual/en/function.date.php" target="_blank">PHP</a>');
        ?>
						</label>
						<p>
							<em><?php 
        _e('Preview', 'google-calendar-events');
        ?>
:</em>&nbsp;&nbsp;
							<code><?php 
        echo date_i18n($date_format_php, time());
        ?>
</code>
						</p>
					</div>
				</td>
			</tr>
			<tr class="simcal-panel-field">
				<th><label for="_calendar_datetime_separator"><?php 
        _e('Separator', 'google-calendar-events');
        ?>
</label></th>
				<td>
					<?php 
        $separator = get_post_meta($post->ID, '_calendar_datetime_separator', true);
        $separator = false == $separator ? '@' : $separator;
        simcal_print_field(array('type' => 'standard', 'subtype' => 'text', 'name' => '_calendar_datetime_separator', 'id' => '_calendar_datetime_separator', 'value' => $separator, 'tooltip' => __('Used to divide date and time when both are shown.', 'google-calendar-events'), 'class' => array('simcal-field-tiny')));
        ?>
				</td>
			</tr>
			<tr class="simcal-panel-field">
				<th><label for="_calendar_time_format_setting"><?php 
        _e('Time Format', 'google-calendar-events');
        ?>
</label></th>
				<td>
					<?php 
        $time_format_setting = esc_attr(get_post_meta($post->ID, '_calendar_time_format_setting', true));
        $time_format_default = esc_attr(get_option('time_format'));
        $time_format = esc_attr(get_post_meta($post->ID, '_calendar_time_format', true));
        $time_format_php = esc_attr(get_post_meta($post->ID, '_calendar_time_format_php', true));
        $time_format_php = $time_format_php ? $time_format_php : $time_format_default;
        ?>
					<select name="_calendar_time_format_setting"
							id="_calendar_time_format_setting"
							class="simcal-field simcal-field-select simcal-field-show-other">
						<option value="use_site" data-show-field="_calendar_time_format_default" <?php 
        selected('use_site', $time_format_setting, true);
        ?>
><?php 
        _ex('Site default', 'Use this site default setting', 'google-calendar-events');
        ?>
</option>
						<option value="use_custom" data-show-field="_calendar_time_format" <?php 
        selected('use_custom', $time_format_setting, true);
        ?>
><?php 
        _ex('Custom', 'Use a custom setting', 'google-calendar-events');
        ?>
</option>
						<option value="use_custom_php" data-show-field="_calendar_time_format_php_field" <?php 
        selected('use_custom_php', $time_format_setting, true);
        ?>
><?php 
        _e('Custom (PHP format)', 'google-calendar-events');
        ?>
</option>
					</select>
					<i class="simcal-icon-help simcal-help-tip" data-tip="<?php 
        _e('This option sets how calendars display event times. It is recommended to keep your site default setting.', 'google-calendar-events');
        ?>
"></i>
					<p id="_calendar_time_format_default" style="<?php 
        echo $time_format_setting != 'use_site' ? 'display: none;' : '';
        ?>
">
						<em><?php 
        _e('Preview', 'google-calendar-events');
        ?>
:</em>&nbsp;&nbsp;
						<code><?php 
        echo date_i18n($time_format_default, time());
        ?>
</code>
					</p>
					<?php 
        simcal_print_field(array('type' => 'datetime-format', 'subtype' => 'time', 'name' => '_calendar_time_format', 'id' => '_calendar_time_format', 'value' => $time_format, 'style' => $time_format_setting != 'use_custom' ? array('display' => 'none') : ''));
        ?>
					<div class="simcal-field-datetime-format-php" id="_calendar_time_format_php_field" style="<?php 
        echo $time_format_setting != 'use_custom_php' ? 'display: none;' : '';
        ?>
">
						<br>
						<label for="_calendar_date_format_php">
							<input type="text"
								   name="_calendar_time_format_php"
								   id="_calendar_time_format_php"
								   class="simcal-field simcal-field-text simcal-field-small"
								   value="<?php 
        echo $time_format_php;
        ?>
"/>
							<?php 
        printf(__('Enter a time format using %s values.', 'google-calendar-events'), '<a href="//php.net/manual/en/function.date.php" target="_blank">PHP</a>');
        ?>
						</label>
						<p>
							<em><?php 
        _e('Preview', 'google-calendar-events');
        ?>
:</em>&nbsp;&nbsp;
							<code><?php 
        echo date_i18n($time_format_php, time());
        ?>
</code>
						</p>
					</div>
				</td>
			</tr>
			<tr class="simcal-panel-field">
				<th><label for="_calendar_week_starts_on_setting"><?php 
        _e('Week Starts On', 'google-calendar-events');
        ?>
</label></th>
				<td>
					<?php 
        $week_starts_setting = esc_attr(get_post_meta($post->ID, '_calendar_week_starts_on_setting', true));
        $week_starts_default = esc_attr(get_option('start_of_week'));
        $week_starts = intval(get_post_meta($post->ID, '_calendar_week_starts_on', true));
        $week_starts = is_numeric($week_starts) ? strval($week_starts) : $week_starts_default;
        ?>
					<select
						name="_calendar_week_starts_on_setting"
						id="_calendar_week_starts_on_setting"
						class="simcal-field simcal-field-select simcal-field-inline simcal-field-show-next"
						data-show-next-if-value="use_custom">
						<option value="use_site" <?php 
        selected('use_site', $week_starts_setting, true);
        ?>
><?php 
        printf(_x('Site default', 'Use this site default setting', 'google-calendar-events') . ' (%s)', date_i18n('l', strtotime("Sunday + {$week_starts_default} Days")));
        ?>
</option>
						<option value="use_custom" <?php 
        selected('use_custom', $week_starts_setting, true);
        ?>
><?php 
        _ex('Custom', 'Use a custom setting', 'google-calendar-events');
        ?>
</option>
					</select>
					<select
						name="_calendar_week_starts_on"
						id="_calendar_week_starts_on"
						class="simcal-field simcal-field-select simcal-field-inline"
						<?php 
        echo 'use_custom' != $week_starts_setting ? 'style="display: none;"' : '';
        ?>
>
						<?php 
        $day_names = simcal_get_calendar_names_i18n('day', 'full');
        ?>
						<?php 
        for ($i = 0; $i <= 6; $i++) {
            ?>
							<option value="<?php 
            echo $i;
            ?>
" <?php 
            selected($i, $week_starts, true);
            ?>
><?php 
            echo $day_names[$i];
            ?>
</option>
						<?php 
        }
        ?>
					</select>
					<i class="simcal-icon-help simcal-help-tip" data-tip="<?php 
        _e('Some calendars may use this setting to display the start of the week. It is recommended to keep the site default setting.', 'google-calendar-events');
        ?>
"></i>
				</td>
			</tr>
			</tbody>
		</table>
		<table>
			<thead>
			<tr><th colspan="2"><?php 
        _e('Cache', 'google-calendar-events');
        ?>
</th></tr>
			</thead>
			<tbody class="simcal-panel-section simcal-panel-section-cache">
			<?php 
        $cache_freq = esc_attr(get_post_meta($post->ID, '_feed_cache_user_amount', true));
        $cache_unit = esc_attr(get_post_meta($post->ID, '_feed_cache_user_unit', true));
        $cache_freq = intval($cache_freq) && $cache_freq >= 0 ? $cache_freq : 2;
        $cache_unit = $cache_unit ? $cache_unit : '3600';
        ?>
			<tr class="simcal-panel-field">
				<th><label for="_feed_cache_user_amount"><?php 
        _ex('Refresh Interval', 'Cache maximum interval', 'google-calendar-events');
        ?>
</label></th>
				<td>
					<input type="number"
						   name="_feed_cache_user_amount"
						   id="_feed_cache_user_amount"
						   class="simcal-field simcal-field-number simcal-field-tiny simcal-field-inline"
						   value="<?php 
        echo $cache_freq;
        ?>
"
						   min="0" />
					<select name="_feed_cache_user_unit"
							id="_feed_cache_user_unit"
							class="simcal-field simcalfield-select simcal-field-inline">
						<option value="60" <?php 
        selected('60', $cache_unit, true);
        ?>
><?php 
        _e('Minute(s)', 'google-calendar-events');
        ?>
</option>
						<option value="3600" <?php 
        selected('3600', $cache_unit, true);
        ?>
><?php 
        _e('Hour(s)', 'google-calendar-events');
        ?>
</option>
						<option value="86400" <?php 
        selected('86400', $cache_unit, true);
        ?>
><?php 
        _e('Day(s)', 'google-calendar-events');
        ?>
</option>
						<option value="604800" <?php 
        selected('604800', $cache_unit, true);
        ?>
><?php 
        _e('Week(s)', 'google-calendar-events');
        ?>
</option>
					</select>
					<i class="simcal-icon-help simcal-help-tip" data-tip="<?php 
        _e('If you add, edit or remove events in your calendar very often, you can set a lower interval to refresh the events displayed. Set a higher interval for best performance.', 'google-calendar-events');
        ?>
"></i>
				</td>
			</tr>
			</tbody>
		</table>
		<?php 
    }
 /**
  * Make a calendar list of events.
  *
  * Outputs a list of events according to events for the specified range.
  *
  * @since  3.0.0
  * @access private
  *
  * @param  int $timestamp
  * @param  int $id
  *
  * @return string
  */
 private function draw_list($timestamp, $id = 0)
 {
     $calendar = $this->calendar;
     if (empty($calendar)) {
         $calendar = $this->calendar = simcal_get_calendar(intval($id));
         if (!$calendar instanceof Default_Calendar) {
             return '';
         }
     }
     $feed = simcal_get_feed($calendar);
     $feed_timezone = get_post_meta($feed->post_id, '_feed_timezone', true);
     $now = $calendar->now;
     $current_events = $this->get_events($timestamp);
     $day_format = explode(' ', $calendar->date_format);
     ob_start();
     // Draw the events.
     $block_tag = $calendar->compact_list && !empty($current_events) ? 'div' : 'dl';
     $data_heading = '';
     $heading = $this->get_heading();
     foreach ($heading as $k => $v) {
         $data_heading .= ' data-heading-' . $k . '="' . $v . '"';
     }
     echo '<' . $block_tag . ' class="simcal-events-list-container"' . ' data-prev="' . $this->prev . '"' . ' data-next="' . $this->next . '"' . $data_heading . '>';
     if (!empty($current_events) && is_array($current_events)) {
         foreach ($current_events as $ymd => $events) {
             // This is where we can find out if an event is a multi-day event and if it needs to be shown.
             // Since this is for list view we are showing the event on the day viewed if it is part of that day even when
             // expand multi-day events are turned off.
             if (isset($events[0][0]->multiple_days) && $events[0][0]->multiple_days > 0) {
                 if ('current_day_only' == get_post_meta($calendar->id, '_default_calendar_expand_multi_day_events', true)) {
                     $year = substr($ymd, 0, 4);
                     $month = substr($ymd, 4, 2);
                     $day = substr($ymd, 6, 2);
                     $temp_date = Carbon::createFromDate($year, $month, $day);
                     if (!($temp_date < Carbon::now()->endOfDay())) {
                         continue;
                     }
                 }
             }
             $day_ts = Carbon::createFromFormat('Ymd', $ymd, $calendar->timezone)->getTimestamp();
             if (!$calendar->compact_list) {
                 $date = new Carbon('now', $calendar->timezone);
                 $date->setLocale(substr(get_locale(), 0, 2));
                 $date->setTimestamp($day_ts);
                 if ($date->isToday()) {
                     $the_color = new Color($calendar->today_color);
                 } else {
                     $the_color = new Color($calendar->days_events_color);
                 }
                 $bg_color = '#' . $the_color->getHex();
                 $color = $the_color->isDark() ? '#ffffff' : '#000000';
                 $border_style = ' style="border-bottom: 1px solid ' . $bg_color . ';" ';
                 $bg_style = ' style="background-color: ' . $bg_color . '; color: ' . $color . ';"';
                 echo "\t" . '<dt class="simcal-day-label"' . $border_style . '>';
                 echo '<span' . $bg_style . '>';
                 foreach ($day_format as $format) {
                     echo $format ? '<span class="simcal-date-format" data-date-format="' . $format . '">' . date_i18n($format, $day_ts) . '</span> ' : ' ';
                 }
                 echo '</span>';
                 echo '</dt>' . "\n";
             }
             $list_events = '<ul class="simcal-events">' . "\n";
             $calendar_classes = array();
             $day_classes = 'simcal-weekday-' . date('w', $day_ts);
             // Is this the present, the past or the future, Doc?
             if ($timestamp <= $now && $timestamp >= $now) {
                 $day_classes .= ' simcal-today simcal-present simcal-day';
             } elseif ($timestamp < $now) {
                 $day_classes .= ' simcal-past simcal-day';
             } elseif ($this->end > $now) {
                 $day_classes .= ' simcal-future simcal-day';
             }
             $count = 0;
             foreach ($events as $day_events) {
                 foreach ($day_events as $event) {
                     if ($event instanceof Event) {
                         if ($feed->type == 'grouped-calendars') {
                             date_default_timezone_set($feed_timezone);
                         } else {
                             date_default_timezone_set($event->timezone);
                         }
                         $event_classes = $event_visibility = '';
                         $calendar_class = 'simcal-events-calendar-' . strval($event->calendar);
                         $calendar_classes[] = $calendar_class;
                         $recurring = $event->recurrence ? 'simcal-event-recurring ' : '';
                         $has_location = $event->venue ? 'simcal-event-has-location ' : '';
                         $event_classes .= 'simcal-event ' . $recurring . $has_location . $calendar_class;
                         // Toggle some events visibility if more than optional limit.
                         if ($calendar->events_limit > -1 && $count >= $calendar->events_limit) {
                             $event_classes .= ' simcal-event-toggled';
                             $event_visibility = ' style="display: none"';
                         }
                         $event_color = '';
                         $bullet = '';
                         $event_color = $event->get_color();
                         if (!empty($event_color)) {
                             $side = is_rtl() ? 'right' : 'left';
                             $event_color = ' style="border-' . $side . ': 4px solid ' . $event_color . '; padding-' . $side . ': 8px;"';
                         }
                         $list_events .= "\t" . '<li class="' . $event_classes . '"' . $event_visibility . $event_color . ' itemscope itemtype="http://schema.org/Event">' . "\n";
                         $list_events .= "\t\t" . '<div class="simcal-event-details">' . $calendar->get_event_html($event) . '</div>' . "\n";
                         $list_events .= "\t" . '</li>' . "\n";
                         $count++;
                         // Event falls within today.
                         if ($this->end <= $now && $this->start >= $now) {
                             $day_classes .= ' simcal-today-has-events';
                         }
                         $day_classes .= ' simcal-day-has-events simcal-day-has-' . strval($count) . '-events';
                         if ($calendar_classes) {
                             $day_classes .= ' ' . trim(implode(' ', array_unique($calendar_classes)));
                         }
                     }
                 }
             }
             $list_events .= '</ul>' . "\n";
             // If events visibility is limited, print the button toggle.
             if ($calendar->events_limit > -1 && $count > $calendar->events_limit) {
                 $list_events .= '<button class="simcal-events-toggle"><i class="simcal-icon-down simcal-icon-animate"></i></button>';
             }
             // Print final list of events for the current day.
             $tag = $calendar->compact_list ? 'div' : 'dd';
             echo '<' . $tag . ' class="' . $day_classes . '" data-events-count="' . strval($count) . '">' . "\n";
             echo "\t" . $list_events . "\n";
             echo '</' . $tag . '>' . "\n";
         }
     } else {
         echo "\t" . '<p>';
         $message = get_post_meta($calendar->id, '_no_events_message', true);
         if ('events' == $calendar->group_type) {
             echo !empty($message) ? $message : __('Nothing to show.', 'google-calendar-events');
         } else {
             if (!empty($message)) {
                 echo $message;
             } else {
                 $from = Carbon::createFromTimestamp($this->start, $calendar->timezone)->getTimestamp();
                 $to = Carbon::createFromTimestamp($this->end, $calendar->timezone)->getTimestamp();
                 echo apply_filters('simcal_no_events_message', sprintf(__('Nothing from %1$s to %2$s.', 'google-calendar-events'), date_i18n($calendar->date_format, $from), date_i18n($calendar->date_format, $to)), $calendar->id, $from, $to);
             }
         }
         echo "\t" . '</p>' . "\n";
     }
     echo '</' . $block_tag . '>';
     date_default_timezone_set($calendar->site_timezone);
     return ob_get_clean();
 }