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