This repository has been archived by the owner on Sep 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
228 lines (194 loc) · 10.5 KB
/
index.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<!DOCTYPE html>
<html lang="en">
<!-- Start Page Header -->
<head>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="css/materialize.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="js/materialize.js"></script>
</head>
<!-- End Page Header -->
<!-- Start Body -->
<body>
<!-- Fullscreen Slider -->
<div class="slider fullscreen">
<ul class="slides" id="slides">
<?php
include "token.php";
function get_events($url){
$events = file_get_contents($url);
return $events;
}
function build_slide($main,$secondary,$third){
$html = "";
$html .= "<li>";
//tries to get an url and convert it to an image
$content = file_get_contents('https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=http%3A%2F%2Fwww.google.com%2F&choe=UTF-8');
// It breaks with the new update. TODO: Find higher resolution cover
// $html .= '<img src="' . $event['photos']['data'][0]['images'][0]['source'] . '">';
$html .= "<table>";
$html .= "<tr>";
$html .= '<td colspan="2" class="event_info_column_big">';
$html .= '<h2 class="light grey-text text-lighten-3"><b>' . $main['name'] . '</b></h2>';
$html .= '<h5 class="light grey-text text-lighten-3"><b>' . date('d-m-Y H:i', strtotime($main['start_time'])) . '</b></h5>';
$html .= '<h5 class="light grey-text text-lighten-3">' . $main['description'] . '</h5>';
$html .= "</td>";
$html .= '<td class="next_event_column no-top-border">';
$html .= '<h3 class="light grey-text text-lighten-3"><b>' . $secondary['name'] . '</b></h4>';
$html .= '<img id="secondary" src="' . $secondary['cover']['source'] . '" >';
$html .= "</td>";
$html .= "</tr>";
$html .= '<tr>';
$html .= '<td class="qr_code_column">';
$html .= "<div>";
$html .= '<h5 style="font-size: 23px;" class = "light grey-text text-lighten-3" >Check it out on Facebook!</h5>';
$html .= '<img src="https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=http%3A%2F%2Fwww.facebook.com/' . $main['id'] . '%2F&choe=UTF-8" >';
$html .= "</div>";
$html .= "</td>";
$html .= '<td class="event_info_column">';
$html .= '<img id="main" src="' . $main['cover']['source'] . '" >';
$html .= "</td>";
$html .= '<td class="next_event_column">';
$html .= '<h3 class="light grey-text text-lighten-3"><b>' . $third['name'] . '</b></h4>';
$html .= '<img id="third" src="' . $third['cover']['source'] . '" >';
$html .= "</td>";
$html .= "</tr>";
$html .= "</table>";
$html .= "</li>";
return $html;
}
function build_two_slide($main,$secondary){
$html = "";
$html .= "<li>";
//tries to get an url and convert it to an image
$content = file_get_contents('https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=http%3A%2F%2Fwww.google.com%2F&choe=UTF-8');
// It breaks with the new update. TODO: Find higher resolution cover
// $html .= '<img src="' . $event['photos']['data'][0]['images'][0]['source'] . '">';
$html .= "<table>";
$html .= "<tr>";
$html .= '<td colspan="2" class="event_info_column_big">';
$html .= '<h2 class="light grey-text text-lighten-3"><b>' . $main['name'] . '</b></h2>';
$html .= '<h5 class="light grey-text text-lighten-3"><b>' . date('d-m-Y H:i', strtotime($main['start_time'])) . '</b></h5>';
$html .= '<h5 class="light grey-text text-lighten-3">' . $main['description'] . '</h5>';
$html .= "</td>";
$html .= '<td class="next_event_column no-top-border">';
$html .= '<h3 class="light grey-text text-lighten-3"><b>' . $secondary['name'] . '</b></h4>';
$html .= '<img id="secondary" src="' . $secondary['cover']['source'] . '" >';
$html .= "</td>";
$html .= "</tr>";
$html .= '<tr>';
$html .= '<td class="qr_code_column">';
$html .= "<div>";
$html .= '<h5 style="font-size: 23px;" class = "light grey-text text-lighten-3" >Check it out on Facebook!</h5>';
$html .= '<img src="https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=http%3A%2F%2Fwww.facebook.com/' . $main['id'] . '%2F&choe=UTF-8" >';
$html .= "</div>";
$html .= "</td>";
$html .= '<td class="event_info_column">';
$html .= '<img id="main" src="' . $main['cover']['source'] . '" >';
$html .= "</td>";
$html .= '<td class="next_event_column no-top-border">';
$html .= "</td>";
$html .= "</tr>";
$html .= "</table>";
$html .= "</li>";
return $html;
}
function build_one_slide($main){
$html = "";
$html .= "<li>";
//tries to get an url and convert it to an image
$content = file_get_contents('https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=http%3A%2F%2Fwww.google.com%2F&choe=UTF-8');
// It breaks with the new update. TODO: Find higher resolution cover
// $html .= '<img src="' . $event['photos']['data'][0]['images'][0]['source'] . '">';
$html .= "<table class='push-to-front'>";
$html .= "<tr>";
$html .= '<td colspan="2" class="event_info_column_big">';
$html .= '<h2 class="light grey-text text-lighten-3"><b>' . $main['name'] . '</b></h2>';
$html .= '<h5 class="light grey-text text-lighten-3"><b>' . date('d-m-Y H:i', strtotime($main['start_time'])) . '</b></h5>';
$html .= '<h5 class="light grey-text text-lighten-3">' . $main['description'] . '</h5>';
$html .= "</td>";
$html .= "</tr>";
$html .= '<tr>';
$html .= '<td class="qr_code_column">';
$html .= "<div>";
$html .= '<h5 style="font-size: 23px;" class = "light grey-text text-lighten-3" >Check it out on Facebook!</h5>';
$html .= '<img src="https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=http%3A%2F%2Fwww.facebook.com/' . $main['id'] . '%2F&choe=UTF-8" >';
$html .= "</div>";
$html .= "</td>";
$html .= '<td class="event_info_column">';
$html .= '<img id="main" src="' . $main['cover']['source'] . '" >';
$html .= "</td>";
$html .= "</tr>";
$html .= "</table>";
$html .= "</li>";
return $html;
}
function build_zero_slide(){
$html = "";
$html = "<div style='text-align:center; width:100%; margin-top:35vh'><p style='width:50%; margin:0 auto; font-size:24px;'>It looks like no upcoming events were found... Might as well turn off the monitor so people don't see this ugly message :) </p></div>";
return $html;
}
function get_number_of_events($events) {
$eventCount = 0;
foreach($events["events"]["data"] as $event) {
$eventCount++;
}
return $eventCount;
}
$base = "https://graph.facebook.com/";
$version = "v3.1/";
# Facebook access token is stored in a separate file, ask the repo admins for it or include your own (and then modify the query as well)
$query = "372136979547549/?fields=events.time_filter(upcoming){name,description,start_time,cover,photos{images}}&access_token=";
$url = $base . $version . $query . $access_token;
$html_out = '';
$raw_events = get_events($url);
$events = json_decode($raw_events, true);
$eventCount = get_number_of_events($events);
$eventTrack = array();
$counter = 0;
foreach ($events["events"]["data"] as $event){
#Retrieve higher resolution images
$images_query = $event["cover"]["id"] . "?fields=images&access_token=";
$images_url = $base . $version . $images_query . $access_token;
$raw_images = file_get_contents($images_url);
$images = json_decode($raw_images, true);
$event['cover']['source'] = $images["images"][0]["source"];
array_push($eventTrack,$event);
}
// $eventCount = 1;
if($eventCount==0){
$html_out .= build_zero_slide();
} else if($eventCount==1) {
$html_out .= build_one_slide($eventTrack[0]);
} else if($eventCount==2) {
$html_out .= build_two_slide($eventTrack[0],$eventTrack[1]);
} else {
for($i = 0; $i < $eventCount; $i++) {
if($i==$eventCount-2) {
$main = $eventTrack[$i];
$secondary = $eventTrack[$i+1];
$third = $eventTrack[0];
} else if($i==$eventCount-1) {
$main = $eventTrack[$i];
$secondary = $eventTrack[0];
$third = $eventTrack[1];
} else {
$main = $eventTrack[$i];
$secondary = $eventTrack[$i+1];
$third = $eventTrack[$i+2];
}
$html_out .= build_slide($main,$secondary,$third);
}
}
echo $html_out;
?>
</ul>
</div>
<div class="progress"> <div class="determinate" style="width: 0%"></div>
</div>
<!-- Initalize slider plugin -->
<script src="js/init_slider.js"></script>
</body>
<!-- End Body -->
</html>