aboutsummaryrefslogtreecommitdiff
path: root/index.php
blob: ef3944cbe0925c1dcd3f17b6da4464418c8f6b09 (plain)
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<?php

if(!ini_get('short_open_tag'))
	die('`short_open_tag = On` is required');

require_once('config.php');
require_once('lib/helper.php');

require_once('lib/PhpTemplate.php');
require_once('lib/Exceptions.php');
require_once('lib/less.php/Less.php');

require_once('model/ModelBase.php');
require_once('model/Conferences.php');
require_once('model/Conference.php');
require_once('model/GenericConference.php');
require_once('model/Feedback.php');
require_once('model/Schedule.php');
require_once('model/Subtitles.php');
require_once('model/Overview.php');
require_once('model/Room.php');
require_once('model/RoomTab.php');
require_once('model/RoomSelection.php');
require_once('model/Stream.php');
require_once('model/Relive.php');
require_once('model/Upcoming.php');


ob_start();
try {
	if(isset($_GET['htaccess']))
	{
		$route = @$_GET['route'];
	}
	elseif(isset($_SERVER["REQUEST_URI"]))
	{
		$route = ltrim(@$_SERVER["REQUEST_URI"], '/');

		// serve static
		if($route != '' && file_exists($_SERVER["DOCUMENT_ROOT"].'/'.$route))
		{
			return false;
		}

	}
	else $route = '';


	$pieces = parse_url($route);
	$route = isset($pieces['path']) ? $pieces['path'] : '';
	$route = rtrim($route, '/');

	$GLOBALS['forceopen'] = isset($_GET['forceopen']);

	// generic template
	$tpl = new PhpTemplate('template/page.phtml');
	$tpl->set(array(
		'baseurl' => forceslash(baseurl()),
		'route' => $route,
		'canonicalurl' => forceslash(baseurl()).forceslash($route),
		'assemblies' => 'template/assemblies/',
		'assets' => forceslash('assets'),
		'conference_assets' => '/',

		'conference' => new GenericConference(),
	));

	if(startswith('//', @$GLOBALS['CONFIG']['BASEURL']))
	{
		$tpl->set(array(
			'httpsurl' => forceslash(forceslash('https:'.$GLOBALS['CONFIG']['BASEURL']).@$GLOBALS['MANDATOR']).forceslash($route).url_params(),
			'httpurl' =>  forceslash(forceslash('http:'. $GLOBALS['CONFIG']['BASEURL']).@$GLOBALS['MANDATOR']).forceslash($route).url_params(),
		));
	}


	// GLOBAL ROUTES
	if($route == 'gen/main.css')
	{
		// global css (for conferences overview)
		handle_lesscss_request('assets/css/main.less', '../assets/css/');
		exit;
	}

	else if($route == 'streams/v1.json')
	{
		require('view/streams-json-v1.php');
		exit;
	}

	else if($route == 'about')
	{
		// global about-page
		require('view/about-global.php');
		exit;
	}

	@list($mandator, $route) = explode('/', $route, 2);
	if(!$mandator)
	{
		// root requested

		if(Conferences::getActiveConferencesCount() == 0)
		{
			// no clients
			//   error

			require('view/allclosed.php');
			exit;
		}
		else if(Conferences::getActiveConferencesCount() == 1)
		{
			// one client
			//   redirect

			$clients = Conferences::getActiveConferences();
			header('Location: '.joinpath([baseurl(), $clients[0]->getSlug()]));
			exit;
		}
		else
		{
			// multiple clients
			//   show overview

			require('view/allconferences.php');
			exit;
		}
	}
	else if(!Conferences::exists($mandator))
	{
		// old url OR wrong client OR
		// -> error
		require('view/404.php');
		exit;
	}
	else {
		// fallthrough through to the main mandator-based routes
	}
}
catch(Exception $e)
{
	ob_clean();
	try {
		require('view/500.php');
		exit;
	}
	catch(Exception $e) {
		header("HTTP/1.1 500 Internal Server Error");
		header("Content-Type: text/plain");
		print_r($e);
		exit;
	}
}


// PER-CONFERENCE CODE
ob_start();
try {
	$conference = Conferences::getConference($mandator);

	// update template information
	$tpl->set(array(
		'baseurl' => forceslash(baseurl()),
		'route' => $route,
		'canonicalurl' => joinpath([baseurl(), $mandator, $route]),
		'conference_assets' => forceslash($mandator),

		'conference' => $conference,
		'feedback' => $conference->getFeedback(),
		'schedule' => $conference->getSchedule(),
		'subtitles' => $conference->getSubtitles(),
	));

	// ALWAYS AVAILABLE ROUTES
	if($route == 'feedback/read')
	{
		require('view/feedback-read.php');
	}

	else if($route == 'schedule.json')
	{
		require('view/schedule-json.php');
	}

	else if($route == 'gen/main.css')
	{
		if(Conferences::hasCustomStyles($mandator))
		{
			handle_lesscss_request(
				Conferences::getCustomStyles($mandator),
				'../../'.Conferences::getCustomStylesDir($mandator)
			);
		}
		else {
			handle_lesscss_request('assets/css/main.less', '../../assets/css/');
		}
	}

	else if($route == 'multiview')
	{
		require('view/multiview.php');
	}

	else if($route == 'schedule')
	{
		require('view/schedule.php');
	}

	else if($route == 'multiview/audio')
	{
		$_GET['selection'] = 'audio';
		require('view/multiview.php');
	}

	else if($route == 'about')
	{
		require('view/about.php');
	}

	// HAS-NOT-BEGUN VIEW
	else if(!$conference->hasBegun())
	{
		require('view/not-started.php');
	}

	// ROUTES AVAILABLE AFTER BUT NOT BEFORE THE CONFERENCE
	else if(preg_match('@^relive/([0-9]+)$@', $route, $m))
	{
		$_GET = array(
			'id' => $m[1],
		);
		require('view/relive-player.php');
	}

	else if($route == 'relive')
	{
		require('view/relive.php');
	}


	// HAS-ENDED VIEW
	else if($conference->hasEnded())
	{
		require('view/closed.php');
	}

	// ROUTES AVAILABLE ONLY DURING THE CONFERENCE
	else if($route == '')
	{
		require('view/overview.php');
	}

	else if($route == 'feedback')
	{
		require('view/feedback.php');
	}

	else if(preg_match('@^([^/]+)$@', $route, $m))
	{
		$_GET = array(
			'room' => $m[1],
			'selection' => '',
			'language' => 'native',
		);
		require('view/room.php');
	}

	else if(preg_match('@^([^/]+)/translated$@', $route, $m))
	{
		$_GET = array(
			'room' => $m[1],
			'selection' => '',
			'language' => 'translated',
		);
		require('view/room.php');
	}

	else if(preg_match('@^([^/]+)/(sd|audio|slides)$@', $route, $m))
	{
		$_GET = array(
			'room' => $m[1],
			'selection' => $m[2],
			'language' => 'native',
		);
		require('view/room.php');
	}

	else if(preg_match('@^([^/]+)/(sd|audio|slides)/translated$@', $route, $m))
	{
		$_GET = array(
			'room' => $m[1],
			'selection' => $m[2],
			'language' => 'translated',
		);
		require('view/room.php');
	}

	else if(preg_match('@^embed/([^/]+)/(hd|sd|audio|slides)/(native|translated|stereo)(/no-autoplay)?$@', $route, $m))
	{
		$_GET = array(
			'room' => $m[1],
			'selection' => $m[2],
			'language' => $m[3],
			'autoplay' => !isset($m[4]),
		);
		require('view/embed.php');
	}

	// UNKNOWN ROUTE
	else
	{
		throw new NotFoundException();
	}

}
catch(NotFoundException $e)
{
	ob_clean();
	require('view/404.php');
}
catch(Exception $e)
{
	ob_clean();
	require('view/500.php');
}