1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Default Calendar - Grid View |
4
|
|
|
* |
5
|
|
|
* @package SimpleCalendar/Calendars |
6
|
|
|
*/ |
7
|
|
|
namespace SimpleCalendar\Calendars\Views; |
8
|
|
|
|
9
|
|
|
use Carbon\Carbon; |
10
|
|
|
use Mexitek\PHPColors\Color; |
11
|
|
|
use SimpleCalendar\Abstracts\Calendar; |
12
|
|
|
use SimpleCalendar\Abstracts\Calendar_View; |
13
|
|
|
use SimpleCalendar\Events\Event; |
14
|
|
|
use SimpleCalendar\Calendars\Default_Calendar; |
15
|
|
|
|
16
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
17
|
|
|
exit; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Default Calendar: Grid View. |
22
|
|
|
* |
23
|
|
|
* @since 3.0.0 |
24
|
|
|
*/ |
25
|
|
|
class Default_Calendar_Grid implements Calendar_View { |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Calendar. |
29
|
|
|
* |
30
|
|
|
* @access public |
31
|
|
|
* @var Default_Calendar |
32
|
|
|
*/ |
33
|
|
|
public $calendar = null; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Current display start. |
37
|
|
|
* |
38
|
|
|
* @access private |
39
|
|
|
* @var int |
40
|
|
|
*/ |
41
|
|
|
private $start = 0; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Current display end. |
45
|
|
|
* |
46
|
|
|
* @access private |
47
|
|
|
* @var int |
48
|
|
|
*/ |
49
|
|
|
private $end = 0; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Constructor. |
53
|
|
|
* |
54
|
|
|
* @since 3.0.0 |
55
|
|
|
* |
56
|
|
|
* @param string|Calendar $calendar |
57
|
|
|
*/ |
58
|
|
|
public function __construct( $calendar = '' ) { |
59
|
|
|
$this->calendar = $calendar; |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get the view parent calendar type. |
64
|
|
|
* |
65
|
|
|
* @since 3.0.0 |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function get_parent() { |
70
|
|
|
return 'default-calendar'; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get the view type. |
75
|
|
|
* |
76
|
|
|
* @since 3.0.0 |
77
|
|
|
* |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
public function get_type() { |
81
|
|
|
return 'grid'; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get the view name. |
86
|
|
|
* |
87
|
|
|
* @since 3.0.0 |
88
|
|
|
* |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function get_name() { |
92
|
|
|
return __( 'Grid', 'google-calendar-events' ); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Add ajax actions. |
97
|
|
|
* |
98
|
|
|
* @since 3.0.0 |
99
|
|
|
*/ |
100
|
|
|
public function add_ajax_actions() { |
101
|
|
|
add_action( 'wp_ajax_simcal_default_calendar_draw_grid', array( $this, 'draw_grid_ajax' ) ); |
102
|
|
|
add_action( 'wp_ajax_nopriv_simcal_default_calendar_draw_grid', array( $this, 'draw_grid_ajax' ) ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Default calendar grid scripts. |
107
|
|
|
* |
108
|
|
|
* Scripts to load when this view is displayed. |
109
|
|
|
* |
110
|
|
|
* @since 3.0.0 |
111
|
|
|
* |
112
|
|
|
* @param string $min |
113
|
|
|
* |
114
|
|
|
* @return array |
115
|
|
|
*/ |
116
|
|
|
public function scripts( $min = '' ) { |
117
|
|
|
return array( |
118
|
|
|
'simcal-qtip' => array( |
119
|
|
|
'src' => SIMPLE_CALENDAR_ASSETS . 'js/vendor/jquery.qtip' . $min . '.js', |
120
|
|
|
'deps' => array( 'jquery' ), |
121
|
|
|
'ver' => '2.2.1', |
122
|
|
|
'in_footer' => true, |
123
|
|
|
), |
124
|
|
|
'simcal-default-calendar' => array( |
125
|
|
|
'src' => SIMPLE_CALENDAR_ASSETS . 'js/default-calendar' . $min . '.js', |
126
|
|
|
'deps' => array( |
127
|
|
|
'jquery', |
128
|
|
|
'simcal-qtip', |
129
|
|
|
), |
130
|
|
|
'var' => SIMPLE_CALENDAR_VERSION, |
131
|
|
|
'in_footer' => true, |
132
|
|
|
'localize' => array( |
133
|
|
|
'simcal_default_calendar' => simcal_common_scripts_variables(), |
134
|
|
|
), |
135
|
|
|
), |
136
|
|
|
); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Default calendar grid styles. |
141
|
|
|
* |
142
|
|
|
* Stylesheets to load when this view is displayed. |
143
|
|
|
* |
144
|
|
|
* @since 3.0.0 |
145
|
|
|
* |
146
|
|
|
* @param string $min = '' |
147
|
|
|
* |
148
|
|
|
* @return array |
149
|
|
|
*/ |
150
|
|
|
public function styles( $min = '' ) { |
151
|
|
|
return array( |
152
|
|
|
'simcal-qtip' => array( |
153
|
|
|
'src' => SIMPLE_CALENDAR_ASSETS . 'css/vendor/jquery.qtip' . $min . '.css', |
154
|
|
|
'ver' => '2.2.1', |
155
|
|
|
'media' => 'all', |
156
|
|
|
), |
157
|
|
|
'simcal-default-calendar-grid' => array( |
158
|
|
|
'src' => SIMPLE_CALENDAR_ASSETS . 'css/default-calendar-grid' . $min . '.css', |
159
|
|
|
'deps' => array( |
160
|
|
|
'simcal-qtip', |
161
|
|
|
), |
162
|
|
|
'ver' => SIMPLE_CALENDAR_VERSION, |
163
|
|
|
'media' => 'all', |
164
|
|
|
), |
165
|
|
|
'simcal-default-calendar-list' => array( |
166
|
|
|
'src' => SIMPLE_CALENDAR_ASSETS . 'css/default-calendar-list' . $min . '.css', |
167
|
|
|
'deps' => array( |
168
|
|
|
'simcal-qtip', |
169
|
|
|
), |
170
|
|
|
'ver' => SIMPLE_CALENDAR_VERSION, |
171
|
|
|
'media' => 'all', |
172
|
|
|
), |
173
|
|
|
); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Default calendar grid markup. |
178
|
|
|
* |
179
|
|
|
* @since 3.0.0 |
180
|
|
|
*/ |
181
|
|
|
public function html() { |
182
|
|
|
|
183
|
|
|
$calendar = $this->calendar; |
184
|
|
|
|
185
|
|
|
if ( $calendar instanceof Default_Calendar ) { |
186
|
|
|
|
187
|
|
|
?> |
188
|
|
|
|
189
|
|
|
<?php edit_post_link( __( 'Edit Calendar', 'google-calendar-events' ), '<p class="simcal-align-right"><small>', '</small></p>', $calendar->id ); ?> |
190
|
|
|
|
191
|
|
|
<table class="simcal-calendar-grid" |
192
|
|
|
data-event-bubble-trigger="<?php echo $calendar->event_bubble_trigger; ?>"> |
193
|
|
|
<thead class="simcal-calendar-head"> |
194
|
|
|
<tr> |
195
|
|
|
<?php if ( ! $calendar->static ) { ?> |
196
|
|
|
<th class="simcal-nav simcal-prev-wrapper" colspan=colspan="<?php echo apply_filters( 'simcal_prev_cols', '1' ); ?>"> |
197
|
|
|
<button class="simcal-nav-button simcal-month-nav simcal-prev" title="<?php _e( 'Previous Month', 'google-calendar-events' ); ?>"><i class="simcal-icon-left"></i></button> |
198
|
|
|
</th> |
199
|
|
|
<?php } ?> |
200
|
|
|
<th colspan="<?php echo apply_filters( 'simcal_current_cols', $calendar->static ? '7' : '5' ); ?>" |
201
|
|
|
class="simcal-nav simcal-current" |
202
|
|
|
data-calendar-current="<?php echo $calendar->start; ?>"> |
203
|
|
|
<?php |
204
|
|
|
|
205
|
|
|
echo '<h3>'; |
206
|
|
|
|
207
|
|
|
// Display month and year according to user date format preference. |
208
|
|
|
|
209
|
|
|
$year_pos = strcspn( $calendar->date_format, 'Y y' ); |
210
|
|
|
$month_pos = strcspn( $calendar->date_format, 'F M m n' ); |
211
|
|
|
|
212
|
|
|
$current = array( 'month' => 'F', 'year' => 'Y' ); |
213
|
|
|
|
214
|
|
|
if ( $year_pos < $month_pos ) { |
215
|
|
|
$current = array_reverse( $current ); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
foreach ( $current as $k => $v ) { |
219
|
|
|
echo ' <span class="simcal-current-' . $k , '">' . date_i18n( $v, $calendar->start ) . '</span> '; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
echo '</h3>'; |
223
|
|
|
|
224
|
|
|
?> |
225
|
|
|
</th> |
226
|
|
|
<?php if ( ! $calendar->static ) { ?> |
227
|
|
|
<th class="simcal-nav simcal-next-wrapper" colspan="<?php echo apply_filters( 'simcal_next_cols', '1' ); ?>"> |
228
|
|
|
<button class="simcal-nav-button simcal-month-nav simcal-next" title="<?php _e( 'Next Month', 'google-calendar-events' ); ?>"><i class="simcal-icon-right"></i></button> |
229
|
|
|
</th> |
230
|
|
|
<?php } ?> |
231
|
|
|
</tr> |
232
|
|
|
<tr> |
233
|
|
|
<?php |
234
|
|
|
|
235
|
|
|
// Print day names in short or long form for different viewport sizes. |
236
|
|
|
|
237
|
|
|
$week_starts = $calendar->week_starts; |
238
|
|
|
$week_days_short = simcal_get_calendar_names_i18n( 'day', 'short' ); |
239
|
|
|
$week_days_full = simcal_get_calendar_names_i18n( 'day', 'full' ); |
240
|
|
|
|
241
|
|
|
for ( $i = $week_starts; $i <= 6; $i ++ ) : |
242
|
|
|
|
243
|
|
|
?> |
244
|
|
|
<th class="simcal-week-day simcal-week-day-<?php echo $i ?>" |
245
|
|
|
data-screen-small="<?php echo mb_substr( $week_days_short[ $i ], 0, 1, 'UTF-8' ); ?>" |
246
|
|
|
data-screen-medium="<?php echo $week_days_short[ $i ]; ?>" |
247
|
|
|
data-screen-large="<?php echo $week_days_full[ $i ]; ?>"><?php echo $week_days_short[ $i ]; ?></th> |
248
|
|
|
<?php |
249
|
|
|
|
250
|
|
|
endfor; |
251
|
|
|
|
252
|
|
|
if ( $week_starts !== 0 ) : |
|
|
|
|
253
|
|
|
for ( $i = 0; $i < $week_starts; $i ++ ) : |
254
|
|
|
|
255
|
|
|
?> |
256
|
|
|
<th class="simcal-week-day simcal-week-day-<?php echo $i ?>" |
257
|
|
|
data-screen-small="<?php echo mb_substr( $week_days_short[ $i ], 0, 1, 'UTF-8' ); ?>" |
258
|
|
|
data-screen-medium="<?php echo $week_days_short[ $i ]; ?>" |
259
|
|
|
data-screen-large="<?php echo $week_days_full[ $i ]; ?>"><?php echo $week_days_short[ $i ]; ?></th> |
260
|
|
|
<?php |
261
|
|
|
|
262
|
|
|
endfor; |
263
|
|
|
endif; |
264
|
|
|
|
265
|
|
|
?> |
266
|
|
|
</tr> |
267
|
|
|
</thead> |
268
|
|
|
|
269
|
|
|
<?php echo $this->draw_month( date( 'n', $calendar->start ), date( 'Y', $calendar->start ) ); ?> |
270
|
|
|
|
271
|
|
|
</table> |
272
|
|
|
|
273
|
|
|
<?php |
274
|
|
|
|
275
|
|
|
echo '<div class="simcal-ajax-loader simcal-spinner-top" style="display: none;"><i class="simcal-icon-spinner simcal-icon-spin"></i></div>'; |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Make a calendar grid. |
281
|
|
|
* |
282
|
|
|
* Outputs an html calendar according to month and year passed in arguments. |
283
|
|
|
* Loosely inspired by: http://davidwalsh.name/php-calendar |
284
|
|
|
* Adjusted by timezone and with an arbitrary week start day. |
285
|
|
|
* |
286
|
|
|
* @since 3.0.0 |
287
|
|
|
* @access private |
288
|
|
|
* |
289
|
|
|
* @param int $month The month to print (two digits). |
290
|
|
|
* @param int $year The corresponding year (four digits). |
291
|
|
|
* @param int $id The calendar id. |
292
|
|
|
* |
293
|
|
|
* @return string |
294
|
|
|
*/ |
295
|
|
|
private function draw_month( $month, $year, $id = 0 ) { |
296
|
|
|
|
297
|
|
|
$calendar = $this->calendar; |
298
|
|
|
if ( empty( $calendar ) ) { |
299
|
|
|
$calendar = simcal_get_calendar( intval( $id ) ); |
300
|
|
|
if ( ! $calendar ) { |
301
|
|
|
return ''; |
302
|
|
|
} |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
$events = $calendar->events; |
306
|
|
|
|
307
|
|
|
$feed = simcal_get_feed( $calendar ); |
308
|
|
|
$feed_timezone = get_post_meta( $feed->post_id, '_feed_timezone', true ); |
309
|
|
|
|
310
|
|
|
// Variables to cycle days in current month and find today in calendar. |
311
|
|
|
$now = $calendar->now; |
312
|
|
|
$current = Carbon::create( $year, $month, 1, 0, 0, 0, $calendar->timezone ); |
313
|
|
|
$current_min = $current->getTimestamp(); |
314
|
|
|
$current_max = $current->endOfDay()->getTimestamp(); |
315
|
|
|
|
316
|
|
|
// Calendar grid variables. |
317
|
|
|
$week_starts = $calendar->week_starts; |
318
|
|
|
$week_of_year = $current->weekOfYear; // Relative count of the week number of the year. |
319
|
|
|
$month_starts = $current->dayOfWeek; // Day upon which the month starts. |
320
|
|
|
$days_in_month = $current->daysInMonth; // Number of days in the given month. |
321
|
|
|
|
322
|
|
|
// Set current month events timestamp boundaries. |
323
|
|
|
$this->start = $current_min; |
324
|
|
|
$this->end = $current->endOfMonth()->timestamp; |
325
|
|
|
|
326
|
|
|
// Get daily events for this month. |
327
|
|
|
if ( $events && is_array( $events ) ) { |
328
|
|
|
|
329
|
|
|
// Filter events within the boundaries previously set above. |
330
|
|
|
$timestamps = array_keys( $events ); |
331
|
|
|
$lower_bound = array_filter( $timestamps, array( $this, 'filter_events_before' ) ); |
332
|
|
|
$higher_bound = array_filter( $lower_bound, array( $this, 'filter_events_after' ) ); |
333
|
|
|
$filtered = ( is_array( $events ) && is_array( $higher_bound) ) && ! empty( $events ) && ! empty( $higher_bound ) ? array_intersect_key( $events, array_combine( $higher_bound, $higher_bound ) ) : array(); |
|
|
|
|
334
|
|
|
|
335
|
|
|
// Put resulting events in an associative array, with day of the month as key for easy retrieval in calendar days loop. |
336
|
|
|
$day_events = array(); |
337
|
|
|
foreach ( $filtered as $timestamp => $events_in_day ) { |
338
|
|
|
foreach ( $events_in_day as $event ) { |
339
|
|
|
if ( $event instanceof Event ){ |
340
|
|
|
$day = intval( Carbon::createFromTimestamp( $timestamp, $event->timezone )->endOfDay()->day ); |
341
|
|
|
$day_events[ $day ][] = $event; |
342
|
|
|
} |
343
|
|
|
} |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
ksort( $day_events, SORT_NUMERIC ); |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
ob_start(); |
350
|
|
|
|
351
|
|
|
echo '<tbody class="simcal-month simcal-month-' . $month . '">' . "\n"; |
352
|
|
|
echo "\t" . '<tr class="simcal-week simcal-week-' . $week_of_year . '">'; |
353
|
|
|
|
354
|
|
|
$days_in_row = 0; |
355
|
|
|
// Week may start on an arbitrary day (sun, 0 - sat, 6). |
356
|
|
|
$week_day = $week_starts; |
357
|
|
|
|
358
|
|
|
// This fixes a possible bug when a month starts by Sunday (0). |
359
|
|
|
if ( 0 !== $week_starts ) { |
360
|
|
|
$b = $month_starts === 0 ? 7 : $month_starts; |
361
|
|
|
} else { |
362
|
|
|
$b = $month_starts; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
// Void days in first week. |
366
|
|
|
for ( $a = $week_starts; $a < $b; $a++ ) : |
367
|
|
|
|
368
|
|
|
$last_void_day_class = ( $a === ( $b - 1 ) ) ? 'simcal-day-void-last' : ''; |
369
|
|
|
|
370
|
|
|
echo '<td class="simcal-day simcal-day-void ' . $last_void_day_class . '"></td>' . "\n"; |
371
|
|
|
|
372
|
|
|
// Reset day of the week count (sun, 0 - sat, 6). |
373
|
|
|
if ( $week_day === 6 ) { |
|
|
|
|
374
|
|
|
$week_day = -1; |
375
|
|
|
} |
376
|
|
|
$week_day++; |
377
|
|
|
|
378
|
|
|
$days_in_row++; |
379
|
|
|
|
380
|
|
|
endfor; |
381
|
|
|
|
382
|
|
|
// Actual days of the month. |
383
|
|
|
for ( $day = 1; $day <= $days_in_month; $day++ ) : |
384
|
|
|
|
385
|
|
|
$count = 0; |
386
|
|
|
$calendar_classes = array(); |
387
|
|
|
$day_classes = 'simcal-day-' . $day . ' simcal-weekday-' . $week_day; |
388
|
|
|
|
389
|
|
|
$border_style = $bg_color = $color = ''; |
390
|
|
|
|
391
|
|
|
// Is this the present, the past or the future, Doc? |
392
|
|
|
if ( $current_min <= $now && $current_max >= $now ) { |
393
|
|
|
$day_classes .= ' simcal-today simcal-present simcal-day'; |
394
|
|
|
$the_color = new Color( $calendar->today_color ); |
395
|
|
|
$bg_color = '#' . $the_color->getHex(); |
396
|
|
|
$color = $the_color->isDark() ? '#ffffff' : '#000000'; |
397
|
|
|
$border_style = ' style="border: 1px solid ' . $bg_color . ';"'; |
398
|
|
|
} elseif ( $current_max < $now ) { |
399
|
|
|
$day_classes .= ' simcal-past simcal-day'; |
400
|
|
|
} elseif ( $current_min > $now ) { |
401
|
|
|
$day_classes .= ' simcal-future simcal-day'; |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
// Print events for the current day in loop, if found any. |
405
|
|
|
if ( isset( $day_events[ $day ] ) ) : |
406
|
|
|
|
407
|
|
|
$bullet_colors = array(); |
408
|
|
|
|
409
|
|
|
$list_events = '<ul class="simcal-events">'; |
410
|
|
|
|
411
|
|
|
foreach ( $day_events[ $day ] as $event ) : |
412
|
|
|
|
413
|
|
|
$event_classes = $event_visibility = ''; |
414
|
|
|
|
415
|
|
|
if ( $event instanceof Event ) : |
416
|
|
|
|
417
|
|
|
if ( $feed->type == 'grouped-calendars' ) { |
|
|
|
|
418
|
|
|
date_default_timezone_set( $feed_timezone ); |
|
|
|
|
419
|
|
|
} else { |
420
|
|
|
date_default_timezone_set( $event->timezone ); |
|
|
|
|
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
// Store the calendar id where the event belongs (useful in grouped calendar feeds) |
424
|
|
|
$calendar_class = 'simcal-events-calendar-' . strval( $event->calendar ); |
425
|
|
|
$calendar_classes[] = $calendar_class ; |
426
|
|
|
|
427
|
|
|
$recurring = $event->recurrence ? 'simcal-event-recurring ' : ''; |
428
|
|
|
$has_location = $event->venue ? 'simcal-event-has-location ' : ''; |
429
|
|
|
|
430
|
|
|
$event_classes .= 'simcal-event ' . $recurring . $has_location . $calendar_class . ' simcal-tooltip'; |
431
|
|
|
|
432
|
|
|
// Toggle some events visibility if more than optional limit. |
433
|
|
|
if ( ( $calendar->events_limit > -1 ) && ( $count >= $calendar->events_limit ) ) : |
434
|
|
|
$event_classes .= ' simcal-event-toggled'; |
435
|
|
|
$event_visibility = ' style="display: none"'; |
436
|
|
|
endif; |
437
|
|
|
|
438
|
|
|
// Event title in list. |
439
|
|
|
$title = ! empty( $event->title ) ? trim( $event->title ) : __( 'Event', 'google-calendar-events' ); |
440
|
|
|
if ( $calendar->trim_titles >= 1 ) { |
441
|
|
|
$title = strlen( $title ) > $calendar->trim_titles ? mb_substr( $title, 0, $calendar->trim_titles ) . '…' : $title; |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
// Event color. |
445
|
|
|
$bullet = ''; |
446
|
|
|
//$bullet_color = '#000'; |
447
|
|
|
$event_color = $event->get_color(); |
448
|
|
|
if ( ! empty( $event_color ) ) { |
449
|
|
|
$bullet = '<span style="color: ' . $event_color . ';">■</span> '; |
450
|
|
|
$bullet_colors[] = $event_color; |
451
|
|
|
} else { |
452
|
|
|
$bullet_colors[] = '#000'; |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
// Event contents. |
456
|
|
|
$list_events .= "\t" . '<li class="' . $event_classes . '"' . $event_visibility . ' itemscope itemtype="http://schema.org/Event">' . "\n"; |
457
|
|
|
$list_events .= "\t\t" . '<span class="simcal-event-title">' . $bullet . $title . '</span>' . "\n"; |
458
|
|
|
$list_events .= "\t\t" . '<div class="simcal-event-details simcal-tooltip-content" style="display: none;">' . $calendar->get_event_html( $event ) . '</div>' . "\n"; |
459
|
|
|
$list_events .= "\t" . '</li>' . "\n"; |
460
|
|
|
|
461
|
|
|
$count ++; |
462
|
|
|
|
463
|
|
|
endif; |
464
|
|
|
|
465
|
|
|
endforeach; |
466
|
|
|
|
467
|
|
|
if ( ( $current_min <= $now ) && ( $current_max >= $now ) ) { |
468
|
|
|
$day_classes .= ' simcal-today-has-events'; |
469
|
|
|
} |
470
|
|
|
$day_classes .= ' simcal-day-has-events simcal-day-has-' . strval( $count ) . '-events'; |
471
|
|
|
|
472
|
|
|
if ( $calendar_classes ) { |
473
|
|
|
$day_classes .= ' ' . trim( implode( ' ', array_unique( $calendar_classes ) ) ); |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
$list_events .= '</ul>' . "\n"; |
477
|
|
|
|
478
|
|
|
// Optional button to toggle hidden events in list. |
479
|
|
|
if ( ( $calendar->events_limit > -1 ) && ( $count > $calendar->events_limit ) ) : |
480
|
|
|
$list_events .= '<button class="simcal-events-toggle"><i class="simcal-icon-down simcal-icon-animate"></i></button>'; |
481
|
|
|
endif; |
482
|
|
|
|
483
|
|
|
else : |
484
|
|
|
|
485
|
|
|
// Empty cell for day with no events. |
486
|
|
|
$list_events = '<span class="simcal-no-events"></span>'; |
487
|
|
|
|
488
|
|
|
endif; |
489
|
|
|
|
490
|
|
|
// The actual days with numbers and events in each row cell. |
491
|
|
|
echo '<td class="' . $day_classes . '" data-events-count="' . strval( $count ) . '">' . "\n"; |
492
|
|
|
|
493
|
|
|
if ( $color ) { |
494
|
|
|
$day_style = ' style="background-color: ' . $bg_color . '; color: ' . $color .'"'; |
495
|
|
|
} elseif ( $count > 0 ) { |
496
|
|
|
$the_color = new Color( $calendar->days_events_color ); |
497
|
|
|
$color = ! $color ? ( $the_color->isDark() ? '#ffffff' : '#000000' ) : $color; |
498
|
|
|
$bg_color = ! $bg_color ? '#' . $the_color->getHex() : $bg_color; |
499
|
|
|
$day_style = ' style="background-color: ' . $bg_color . '; color: ' . $color .'"'; |
500
|
|
|
} else { |
501
|
|
|
$day_style = ''; |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
echo "\t" . '<div' . $border_style . '>' . "\n"; |
505
|
|
|
echo "\t\t" . '<span class="simcal-day-label simcal-day-number"' . $day_style . '>' . $day . '</span>' . "\n"; |
506
|
|
|
echo "\t\t" . $list_events . "\n"; |
507
|
|
|
echo "\t\t"; |
508
|
|
|
echo '<span class="simcal-events-dots" style="display: none;">'; |
509
|
|
|
|
510
|
|
|
// Event bullets for calendar mobile mode. |
511
|
|
|
for( $i = 0; $i < $count; $i++ ) { |
|
|
|
|
512
|
|
|
echo '<b style="color: ' . $bullet_colors[ $i ] . ';"> • </b>'; |
|
|
|
|
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
echo '</span>' . "\n"; |
516
|
|
|
echo "\t" . '</div>' . "\n"; |
517
|
|
|
echo '</td>' . "\n"; |
518
|
|
|
|
519
|
|
|
// Reset day of the week count (sun, 0 - sat, 6). |
520
|
|
|
if ( $week_day === 6 ) { |
|
|
|
|
521
|
|
|
$week_day = - 1; |
522
|
|
|
} |
523
|
|
|
$week_day++; |
524
|
|
|
|
525
|
|
|
// Reset count of days for this row (0-6). |
526
|
|
|
if ( $days_in_row === 6 ) : |
|
|
|
|
527
|
|
|
|
528
|
|
|
// Close the week row. |
529
|
|
|
echo '</tr>'; |
530
|
|
|
|
531
|
|
|
// Open a new week row. |
532
|
|
|
if ( $day < $days_in_month ) { |
533
|
|
|
echo '<tr class="simcal-week simcal-week-' . $week_of_year++ . '">' . "\n"; |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
$days_in_row = -1; |
537
|
|
|
|
538
|
|
|
endif; |
539
|
|
|
|
540
|
|
|
$days_in_row++; |
541
|
|
|
|
542
|
|
|
$current_min = Carbon::createFromTimestamp( $current_min, $calendar->timezone )->addDay()->getTimestamp(); |
543
|
|
|
$current_max = Carbon::createFromTimestamp( $current_max, $calendar->timezone )->addDay()->getTimestamp(); |
544
|
|
|
|
545
|
|
|
endfor; |
546
|
|
|
|
547
|
|
|
// Void days at the end of the month. |
548
|
|
|
$remainder_days = ( 6 - $days_in_row ); |
549
|
|
|
|
550
|
|
|
for ( $i = 0; $i <= $remainder_days; $i ++ ) { |
551
|
|
|
|
552
|
|
|
$last_void_day_class = ( $i == $remainder_days ) ? 'simcal-day-void-last' : ''; |
553
|
|
|
|
554
|
|
|
echo '<td class="simcal-day simcal-day-void ' . $last_void_day_class . '"></td>' . "\n"; |
555
|
|
|
|
556
|
|
|
$week_day++; |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
echo "\t" . '</tr>' . "\n"; |
560
|
|
|
echo '</tbody>' . "\n"; |
561
|
|
|
|
562
|
|
|
date_default_timezone_set( $calendar->site_timezone ); |
|
|
|
|
563
|
|
|
|
564
|
|
|
return ob_get_clean(); |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
/** |
568
|
|
|
* Ajax callback to request a new month. |
569
|
|
|
* |
570
|
|
|
* @since 3.0.0 |
571
|
|
|
*/ |
572
|
|
|
public function draw_grid_ajax() { |
573
|
|
|
|
574
|
|
|
if ( isset( $_POST['month'] ) && isset( $_POST['year'] ) && isset( $_POST['id'] ) ) { |
575
|
|
|
|
576
|
|
|
$month = absint( $_POST['month'] ); |
577
|
|
|
$year = absint( $_POST['year'] ); |
578
|
|
|
$id = absint( $_POST['id'] ); |
579
|
|
|
|
580
|
|
|
wp_send_json_success( $this->draw_month( $month, $year, $id ) ); |
581
|
|
|
|
582
|
|
|
} else { |
583
|
|
|
|
584
|
|
|
wp_send_json_error( 'Missing arguments in default calendar grid ajax request.' ); |
585
|
|
|
|
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
/** |
591
|
|
|
* Array filter callback. |
592
|
|
|
* |
593
|
|
|
* @since 3.0.0 |
594
|
|
|
* @access private |
595
|
|
|
* |
596
|
|
|
* @param int $event Timestamp. |
597
|
|
|
* |
598
|
|
|
* @return bool |
599
|
|
|
*/ |
600
|
|
|
private function filter_events_before( $event ) { |
601
|
|
|
return intval( $event ) >= intval( $this->start ); |
602
|
|
|
} |
603
|
|
|
|
604
|
|
|
/** |
605
|
|
|
* Array filter callback. |
606
|
|
|
* |
607
|
|
|
* @since 3.0.0 |
608
|
|
|
* @access private |
609
|
|
|
* |
610
|
|
|
* @param int $event Timestamp. |
611
|
|
|
* |
612
|
|
|
* @return bool |
613
|
|
|
*/ |
614
|
|
|
private function filter_events_after( $event ) { |
615
|
|
|
return intval( $event ) < intval( $this->end ); |
616
|
|
|
} |
617
|
|
|
|
618
|
|
|
} |
619
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..