-
Notifications
You must be signed in to change notification settings - Fork 4
/
google-calendar.php
executable file
·45 lines (33 loc) · 1.23 KB
/
google-calendar.php
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
<?php
/*
* This file is intended to retrieve Calendar items from Google Calendar.
*/
//Few needed strings
$today = date('Y-m-d');
if ($force == TRUE) {
$time = urlencode('T'.date('H:i:s'));
} else {
$time = urlencode('T00:00:01');
}
$uri = urlencode($r['url']);
$min = $today . $time;
$max = $today . urlencode('T23:59:59');
$url = "http://www.google.com/calendar/feeds/{$uri}/public/full?alt=json&orderby=starttime&singleevents=true&sortorder=ascending&start-min={$min}&start-max={$max}";
//JSON request
$json = file_get_contents($url);
$obj = json_decode($json);
//Parse JSON
foreach ($obj->feed->entry as $o) {
$endtime = $o->{'gd$when'}[0]->endTime;
$starttime = $o->{'gd$when'}[0]->startTime;
$title = $o->title->{'$t'};
$title = trim('$title');
$endtime = date("Y-m-d H:i:s", strtotime($endtime));
$starttime = date("Y-m-d H:i:s", strtotime($starttime));
//assuming still connected to database
$query = "INSERT INTO events (EventName, Start, End, Room, Grp, Bldg) VALUES (?,?,?,?,?,?)";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, "ssssss", $title, $starttime, $endtime, $r['name'], $r['group'], $r['bldg']);
/* Execute the statement */
mysqli_stmt_execute($stmt);
}