1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
<?php
/* DISPLAY - calendar
*
*/
function communievents_event_calendar($attr) {
wp_enqueue_script('communievents-fullcalendar-de');
wp_enqueue_style('communievents-fullcalendar');
$id = wp_unique_id('communievents-calendar-widget-');
wp_add_inline_script('communievents-fullcalendar',
"jQuery(function(\$) {" .
"\$('\#$id').fullCalendar({" .
"timeFormat:'HH:mm', " .
"events: '" .admin_url('admin-ajax.php') ."?action=communievents_calendar_data'," .
"height: 'auto'," .
"defaultView: window.innerWidth <= 600 ? 'listMonth' : 'month'," .
"windowResize: function(view) { " .
"if (window.innerWidth <= 600 && view.type != 'listMonth') { " .
"\$('\#$id').fullCalendar('changeView', 'listMonth');" .
"} else if (window.innerWidth > 600 && view.type != 'month') {" .
"\$('\#$id').fullCalendar('changeView', 'month');" .
"}" .
"}" .
"})" .
"});");
return "<div id='$id'></div>";
}
function communievents_calendar_ajax() {
global $wpdb;
$table_name = $wpdb->prefix . 'communievents_events';
$tz = new DateTimeZone(CommuniApi::TIMEZONE);
$start_dt = new DateTime($_REQUEST['start'], $tz);
$end_dt = new DateTime($_REQUEST['end'], $tz);
$retval = array();
$list = $wpdb->get_results($wpdb->prepare(
"SELECT * FROM $table_name WHERE official=1 AND start <= %s AND end >= %s ORDER BY start",
$end_dt->format('Y-m-d H:i:s'), $start_dt->format('Y-m-d H:i:s')));
if ($list) {
foreach ($list as $event) {
$start_dt = new DateTime($event->start, $tz);
$end_dt = new DateTime($event->end, $tz);
if ($event->allday) {
// end is non-inclusive! move it into the next day
$end_dt->modify('+1 minute');
$start_str = $start_dt->format('Y-m-d');
$end_str = $end_dt->format('Y-m-d');
} else {
$start_str = $start_dt->format('Y-m-d\TH:i:s');
$end_str = $end_dt->format('Y-m-d\TH:i:s');
}
$retval[] = array(
'title' => $event->title,
'start' => $start_str,
'end' => $end_str,
'url' => $event->url
);
}
}
wp_send_json($retval);
}
function communievents_setup_event_calendar() {
add_shortcode('communievents-event-calendar', 'communievents_event_calendar');
wp_register_script('communievents-momentjs', COMMUNIEVENTS_PLUGIN_URL . "js/moment.min.js", null, true);
wp_register_script('communievents-fullcalendar', COMMUNIEVENTS_PLUGIN_URL . "js/fullcalendar.min.js", array(
'jquery', 'communievents-momentjs'/*, 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-button'*/), null, true);
wp_register_script('communievents-fullcalendar-de', COMMUNIEVENTS_PLUGIN_URL . 'js/fullcalendar-de.js', array('communievents-fullcalendar'), null, true);
wp_register_style('communievents-fullcalendar', COMMUNIEVENTS_PLUGIN_URL . 'css/fullcalendar.min.css');
add_action('wp_ajax_nopriv_communievents_calendar_data', 'communievents_calendar_ajax');
add_action('wp_ajax_communievents_calendar_data', 'communievents_calendar_ajax');
}
|