本文整理汇总了PHP中simcal_get_calendar函数的典型用法代码示例。如果您正苦于以下问题:PHP simcal_get_calendar函数的具体用法?PHP simcal_get_calendar怎么用?PHP simcal_get_calendar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了simcal_get_calendar函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: print_calendar
/**
* Print a calendar.
*
* @since 3.0.0
*
* @param array $attributes
*
* @return string
*/
public function print_calendar($attributes)
{
$args = shortcode_atts(array('id' => null), $attributes);
$id = absint($args['id']);
if ($id > 0) {
$calendar = simcal_get_calendar($id);
if ($calendar instanceof Calendar) {
ob_start();
$calendar->html();
return ob_get_clean();
}
}
return '';
}
示例2: __construct
/**
* Constructor.
*
* @since 3.0.0
*/
public function __construct()
{
$this->id = 'calendars';
$this->option_group = 'settings';
$this->label = __('Calendars', 'google-calendar-events');
//$this->description = __( 'Manage calendar preferences and calendar types settings and options.', 'google-calendar-events' );
$calendars = simcal_get_calendar_types();
$calendar_settings = array();
if (!empty($calendars) && is_array($calendars)) {
foreach ($calendars as $calendar => $views) {
$calendar_type = simcal_get_calendar($calendar);
if ($calendar_type instanceof Calendar) {
$settings = $calendar_type->settings_fields();
if (!empty($settings)) {
$calendar_settings[$calendar] = $settings;
}
}
}
}
$this->calendar_types = $calendar_settings;
$this->sections = $this->add_sections();
$this->fields = $this->add_fields();
}
示例3: simcal_delete_feed_transients
/**
* Clear feed transients cache.
*
* @since 3.0.0
*
* @param string|int|array|\WP_Post $id
*
* @return bool
*/
function simcal_delete_feed_transients($id = '')
{
$grouped_ids = get_post_meta($id, '_grouped_calendars_ids', true);
// If there are group IDs we need to construct an array to pass along with the grouped IDs + the original $post_id
if (is_array($grouped_ids)) {
$temp_id = $id;
$id = $grouped_ids;
$id[] = $temp_id;
}
if (is_numeric($id)) {
$id = intval($id) > 0 ? absint($id) : simcal_get_calendars();
} elseif ($id instanceof WP_Post) {
$id = $id->ID;
} elseif (is_array($id)) {
$id = array_map('absint', $id);
} else {
$id = simcal_get_calendars('', true);
}
$feed_types = simcal_get_feed_types();
if (is_array($id)) {
$posts = get_posts(array('post_type' => 'calendar', 'fields' => 'ids', 'post__in' => $id, 'nopaging' => true));
foreach ($posts as $post) {
$calendar = simcal_get_calendar($post);
if ($calendar instanceof \SimpleCalendar\Abstracts\Calendar) {
foreach ($feed_types as $feed_type) {
delete_transient('_simple-calendar_feed_id_' . strval($calendar->id) . '_' . $feed_type);
}
}
}
} else {
$post = get_post($id);
$calendar = simcal_get_calendar($post);
if ($calendar instanceof \SimpleCalendar\Abstracts\Calendar) {
foreach ($feed_types as $feed_type) {
delete_transient('_simple-calendar_feed_id_' . strval($calendar->id) . '_' . $feed_type);
}
}
}
return delete_transient('_simple-calendar_feed_ids');
}
示例4: draw_list
/**
* 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 '';
}
}
date_default_timezone_set($calendar->timezone);
$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) {
$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) {
$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 . ' itemprop="event" 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';
}
//.........这里部分代码省略.........
示例5: settings_handle
/**
* 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) {
//.........这里部分代码省略.........
示例6: draw_month
/**
* 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 '';
}
}
date_default_timezone_set($calendar->timezone);
$events = $calendar->events;
// Variables to cycle days in current month and find today in calendar.
$now = $calendar->now;
$current = Carbon::create($year, $month, 1, 0, 0, 59, $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 = array_intersect_key($events, array_combine($higher_bound, $higher_bound));
// 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';
//.........这里部分代码省略.........
示例7: simcal_print_calendar
/**
* Print a calendar.
*
* @since 3.0.0
*
* @param int|object|WP_Post $object
*
* @return void
*/
function simcal_print_calendar($object)
{
$calendar = simcal_get_calendar($object);
if ($calendar instanceof \SimpleCalendar\Abstracts\Calendar) {
$calendar->html();
}
}
示例8: get_events
/**
* Get events from multiple calendars.
*
* @since 3.0.0
*
* @return array
*/
public function get_events()
{
$ids = $this->calendars_ids;
$events = get_transient('_simple-calendar_feed_id_' . strval($this->post_id) . '_' . $this->type);
if (empty($events) && !empty($ids) && is_array($ids)) {
$events = array();
foreach ($ids as $cal_id) {
$calendar = simcal_get_calendar(intval($cal_id));
simcal_delete_feed_transients($cal_id);
if ($calendar instanceof Calendar) {
// Sometimes the calendars might have events at the same time from different calendars
// When merging the arrays together some of the events will be lost because the keys are the same and one will overwrite the other
// This snippet checks if the key already exists in the master events array and if it does it subtracts 1 from it to make the key unique and then unsets the original key.
foreach ($calendar->events as $k => $v) {
$calendar->events[$this->update_array_timestamp($events, $k)] = $v;
}
$events = is_array($calendar->events) ? $events + $calendar->events : $events;
}
}
if (!empty($events)) {
// Trim events to set the earliest one as specified in feed settings.
$earliest_event = intval($this->time_min);
if ($earliest_event > 0) {
$events = $this->array_filter_key($events, array($this, 'filter_events_before'));
}
// Trim events to set the latest one as specified in feed settings.
$latest_event = intval($this->time_max);
if ($latest_event > 0) {
$events = $this->array_filter_key($events, array($this, 'filter_events_after'));
}
set_transient('_simple-calendar_feed_id_' . strval($this->post_id) . '_' . $this->type, $events, absint($this->cache));
}
}
// Sort events by start time before returning
uasort($events, array($this, 'sort_by_start_time'));
return $events;
}
示例9: get_events
/**
* Get events from multiple calendars.
*
* @since 3.0.0
*
* @return array
*/
public function get_events()
{
$ids = $this->calendars_ids;
$events = get_transient('_simple-calendar_feed_id_' . strval($this->post_id) . '_' . $this->type);
if (empty($events) && !empty($ids) && is_array($ids)) {
$events = array();
foreach ($ids as $cal_id) {
$calendar = simcal_get_calendar(intval($cal_id));
if ($calendar instanceof Calendar) {
$events = is_array($calendar->events) ? $events + $calendar->events : $events;
}
}
if (!empty($events)) {
// Trim events to set the earliest one as specified in feed settings.
$earliest_event = intval($this->time_min);
if ($earliest_event > 0) {
$events = $this->array_filter_key($events, array($this, 'filter_events_before'));
}
// Trim events to set the latest one as specified in feed settings.
$latest_event = intval($this->time_max);
if ($latest_event > 0) {
$events = $this->array_filter_key($events, array($this, 'filter_events_after'));
}
set_transient('_simple-calendar_feed_id_' . strval($this->post_id) . '_' . $this->type, $events, absint($this->cache));
}
}
return $events;
}
示例10: simcal_delete_feed_transients
/**
* Clear feed transients cache.
*
* @since 3.0.0
*
* @param string|int|array|\WP_Post $id
*
* @return bool
*/
function simcal_delete_feed_transients($id = '')
{
if (is_numeric($id)) {
$id = intval($id) > 0 ? absint($id) : simcal_get_calendars();
} elseif ($id instanceof WP_Post) {
$id = $id->ID;
} elseif (is_array($id)) {
$id = array_map('absint', $id);
} else {
$id = simcal_get_calendars('', true);
}
$feed_types = simcal_get_feed_types();
if (is_array($id)) {
$posts = get_posts(array('post_type' => 'calendar', 'fields' => 'ids', 'post__in' => $id, 'nopaging' => true));
foreach ($posts as $post) {
$calendar = simcal_get_calendar($post);
if ($calendar instanceof \SimpleCalendar\Abstracts\Calendar) {
foreach ($feed_types as $feed_type) {
delete_transient('_simple-calendar_feed_id_' . strval($calendar->id) . '_' . $feed_type);
}
}
}
} else {
$post = get_post($id);
$calendar = simcal_get_calendar($post);
if ($calendar instanceof \SimpleCalendar\Abstracts\Calendar) {
foreach ($feed_types as $feed_type) {
delete_transient('_simple-calendar_feed_id_' . strval($calendar->id) . '_' . $feed_type);
}
}
}
return delete_transient('_simple-calendar_feed_ids');
}
示例11: draw_list
/**
* 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 '';
}
}
$now = $calendar->now;
$current_events = $this->get_events($timestamp);
$format = $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)) {
$last_event = null;
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.
$first_event = $events[0][0];
if (isset($first_event->multiple_days) && $first_event->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())) {
// Break here only if event already shown once.
if ($last_event == $first_event) {
continue;
} else {
// Save event as "last" for next time through, then break.
$last_event = $first_event;
}
}
}
}
// Add offset offset for list view day headings.
$day_date = Carbon::createFromFormat('Ymd', $ymd, $calendar->timezone);
$day_date_offset = clone $day_date;
$day_date_offset->addSeconds($day_date->offset);
$day_date_ts_offset = $day_date_offset->timestamp;
if (!$calendar->compact_list) {
if ($day_date_offset->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 . '>';
echo $format ? '<span class="simcal-date-format" data-date-format="' . $format . '">' . date_i18n($format, $day_date_ts_offset, strtotime($day_date_offset->toDateTimeString())) . '</span> ' : ' ';
echo '</span>';
echo '</dt>' . "\n";
}
$list_events = '<ul class="simcal-events">' . "\n";
$calendar_classes = array();
// Add day of week number to CSS class.
$day_classes = 'simcal-weekday-' . date('w', $day_date_ts_offset);
// 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) {
$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 ' : '';
//.........这里部分代码省略.........
示例12: calendar_feed_column_content
/**
* 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;
}
}