forked from codepo8/calendar-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
realapi.php
64 lines (53 loc) · 1.57 KB
/
realapi.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
$now = '';
$day = 0;
$data = '';
if (isset($_GET['day'])) {
$day = +($_GET['day']);
if ($day > 24) { $day = 24; }
// if (+date('m') < 12 || $day > +date('d')) {
// $day = 0;
// }
$url = 'https://docs.google.com/spreadsheet/pub?'.
'key=0AhphLklK1Ve4dEp5X2tBNHFPM0hQSHpZQnBjYl9NLUE&output=csv';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$output = curl_exec($ch);
curl_close($ch);
$csvdata = csv_to_array($output);
$now = $csvdata[($day-1)];
if ($now) {
$data .= '<h1><a href="'.$now[0].'">'.$now[1].'</a></h1>'.
'<p>'.$now[2].'</p>';
if ($now[3] !== '') {
$data .= '<p>You can also <a href="'.$now[3].
'">see it in action here</a>.</p>';
}
} else {
$data .= '<h1><a href="http://developer.mozilla.com">Not yet!</a></h1>'.
'<p>You have to wait, like all the others.</p>';
}
}
$data .= '<a id="close" href="index.php">x</a>';
if (isset($_GET['ajax'])) { echo $data; }
function csv_to_array($input, $delimiter=',') {
$header = null;
$data = array();
$csvData = str_getcsv($input, "\n");
foreach($csvData as $csvLine) {
if (is_null($header)) {
$header = explode($delimiter, $csvLine);
} else {
$items = explode($delimiter, $csvLine);
for($n = 0, $m = count($header); $n < $m; $n++){
$prepareData[$n] = $items[$n];
}
$data[] = $prepareData;
}
}
return $data;
}
?>