Completed
Push — master ( 5e0fa5...eff19f )
by mains
03:48
created

index.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
error_reporting(-1);
3
include 'php/jodel-web.php';
4
5
	$location = new Location();
6
	$location->setLat('0.1');
7
	$location->setLng('0.1');
8
	$location->setCityName('Munich');
9
10
	isTokenFresh($location);
11
12
	$result = $db->query("SELECT * FROM accounts WHERE id='1'");
13
	
14
	$accessToken;
15
	$newPositionStatus;
16
	
17
	if ($result->num_rows > 0)
18
	{
19
		// output data of each row
20
		while($row = $result->fetch_assoc())
21
		{
22
			$accessToken = $row["access_token"];
23
			$newPositionStatus = $row['name'];
24
		}
25
	}
26
	else
27
	{
28
		echo "Error: 0 results";
29
	}
30
	
31
	
32
	//createAccount();
33
34
35
	//Set View
36 View Code Duplication
	if(isset($_GET['view']))
37
	{
38
		switch ($_GET['view']) {
39
			case 'comment':
40
				$view = 'comment';
41
				break;
42
			
43
			case 'upVote':
44
				$view = 'upVote';
45
				break;
46
47
			default:
48
				$view = 'time';
49
				break;
50
		}
51
	}
52
	else
53
	{
54
		$view = 'time';
55
	}
56
	
57
	//Set Location
58
	if(isset($_GET['city'])) {
59
		$url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($_GET['city']) . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w';
60
		$result = Requests::post($url);
61
		if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST')
62
		{
63
			$newPositionStatus = "0 results";
64
		}
65
		else
66
		{
67
			$name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name'];
68
			$lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat'];
69
			$lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng'];
70
71
			$location = new Location();
72
			$location->setLat($lat);
73
			$location->setLng($lng);
74
			$location->setCityName($name);
75
			$accountCreator = new UpdateLocation();
76
			$accountCreator->setLocation($location);
77
			$accountCreator->setAccessToken($accessToken);
78
			$data = $accountCreator->execute();
79
80
			//safe location to db
81
			if($data == "Success")
82
			{
83
				$result = $db->query("UPDATE accounts 
84
						SET name='" . $name . "',
85
							lat='" . $lat . "',
86
							lng='" . $lng . "'
87
						WHERE id='1'");
88
89
				if($result === false)
90
				{
91
						echo "Updating location failed: (" . $db->errno . ") " . $db->error;
92
				}
93
				else
94
				{
95
					$newPositionStatus = $name;
96
				}
97
			}
98
		}
99
	}
100
	
101
	//Vote
102
	if(isset($_GET['vote']) && isset($_GET['postID'])) {
103
		if($_GET['vote'] == "up") {
104
			$accountCreator = new Upvote();
105
		}
106
		else if($_GET['vote'] == "down") {
107
			$accountCreator = new Downvote();
108
		}
109
		$accountCreator->setAccessToken($accessToken);
110
		$data = $accountCreator->execute();
111
112
		header("Location: index.php#postId-" . htmlspecialchars($_GET['postID']));
113
		die();
114
	}
115
	
116
	
117
	//SendJodel
118
	if(isset($_POST['message'])) {
119
		$accountCreator = new SendJodel();
120
121
		if(isset($_POST['ancestor']))
122
		{
123
			$ancestor = $_POST['ancestor'];
124
			$accountCreator->ancestor = $ancestor;
125
		}
126
		if(isset($_POST['color']))
127
		{
128
			$color = $_POST['color'];
129
			switch ($color) {
130
				case '8ABDB0':
131
					$color = '8ABDB0';
132
					break;
133
				case '9EC41C':
134
					$color = '9EC41C';
135
					break;
136
				case '06A3CB':
137
					$color = '06A3CB';
138
					break;
139
				case 'FFBA00':
140
					$color = 'FFBA00';
141
					break;
142
				case 'DD5F5F':
143
					$color = 'DD5F5F';
144
					break;
145
				case 'FF9908':
146
					$color = 'FF9908';
147
					break;
148
				
149
				default:
150
					$color = '8ABDB0';
151
					break;
152
			}
153
			$accountCreator->color = $color;
154
			echo "Setting color:" . $color;
155
		}
156
		
157
		$location = new Location();
158
		$location->setLat('0.1');
159
		$location->setLng('0.1');
160
		$location->setCityName('Munich');
161
		
162
		$accountCreator->location = $location;
163
		
164
		$accountCreator->setAccessToken($accessToken);
165
		$data = $accountCreator->execute();
166
	}
167
?>
168
<!DOCTYPE html>
169
<html lang="en">
170
	<head>
171
		<title>JodelBlue WebClient</title>
172
		
173
		<meta charset="utf8">
174
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
175
		<meta http-equiv="x-ua-compatible" content="ie=edge">
176
		
177
		<meta name="description" content="JodelBlue is a WebClient for the Jodel App. No registration required! Browse Jodels all over the world. Send your own Jodels or upvote others.">
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 180 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
178
		<meta name="keywords" content="jodelblue, jodel, blue, webclient, web, client">
179
		
180
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous">
181
		<link rel="stylesheet" href="css/font-awesome.min.css">
182
		<link rel="stylesheet" href="style.css" type="text/css">
183
		
184
		<link rel="shortcut icon" type="image/x-icon" href="./img/favicon/favicon.ico">
185
		<link rel="icon" type="image/x-icon" href="./img/favicon/favicon.ico">
186
		<link rel="icon" type="image/gif" href="./img/favicon/favicon.gif">
187
		<link rel="icon" type="image/png" href="./img/favicon/favicon.png">
188
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon.png">
189
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-57x57.png" sizes="57x57">
190
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-60x60.png" sizes="60x60">
191
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-72x72.png" sizes="72x72">
192
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-76x76.png" sizes="76x76">
193
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-114x114.png" sizes="114x114">
194
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-120x120.png" sizes="120x120">
195
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-128x128.png" sizes="128x128">
196
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-144x144.png" sizes="144x144">
197
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-152x152.png" sizes="152x152">
198
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-180x180.png" sizes="180x180">
199
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-precomposed.png">
200
		<link rel="icon" type="image/png" href="./img/favicon/favicon-16x16.png" sizes="16x16">
201
		<link rel="icon" type="image/png" href="./img/favicon/favicon-32x32.png" sizes="32x32">
202
		<link rel="icon" type="image/png" href="./img/favicon/favicon-96x96.png" sizes="96x96">
203
		<link rel="icon" type="image/png" href="./img/favicon/favicon-160x160.png" sizes="160x160">
204
		<link rel="icon" type="image/png" href="./img/favicon/favicon-192x192.png" sizes="192x192">
205
		<link rel="icon" type="image/png" href="./img/favicon/favicon-196x196.png" sizes="196x196">
206
		<meta name="msapplication-TileImage" content="./img/favicon/win8-tile-144x144.png"> 
207
		<meta name="msapplication-TileColor" content="#5682a3"> 
208
		<meta name="msapplication-navbutton-color" content="#5682a3"> 
209
		<meta name="application-name" content="JodelBlue"/> 
210
		<meta name="msapplication-tooltip" content="JodelBlue"/> 
211
		<meta name="apple-mobile-web-app-title" content="JodelBlue"/> 
212
		<meta name="msapplication-square70x70logo" content="./img/favicon/win8-tile-70x70.png"> 
213
		<meta name="msapplication-square144x144logo" content="./img/favicon/win8-tile-144x144.png"> 
214
		<meta name="msapplication-square150x150logo" content="./img/favicon/win8-tile-150x150.png"> 
215
		<meta name="msapplication-wide310x150logo" content="./img/favicon/win8-tile-310x150.png"> 
216
		<meta name="msapplication-square310x310logo" content="./img/favicon/win8-tile-310x310.png"> 
217
	</head>
218
	
219
	<body>
220
		<header>
221
			<nav class="navbar navbar-full navbar-dark navbar-fixed-top">
222
				<div class="container">					
223
						<?php
224
							if(isset($_GET['postID']) && isset($_GET['getPostDetails']))
225
							{
226
								echo '<a id="comment-back" href="index.php?view=' . $view . '#postId-' . htmlspecialchars($_GET['postID']) . '">';
227
								echo '<i class="fa fa-angle-left fa-3x"></i>';
228
								echo '</a>';
229
								echo '<h1>';
230
								echo '<a href="index.php?getPostDetails=' . htmlspecialchars($_GET['getPostDetails']) . '&postID=' . htmlspecialchars($_GET['postID']) . '" class="spinnable">';
231
							}
232
							else
233
							{
234
								echo '<h1>';	
235
								echo '<a href="./" class="spinnable">';
236
							}
237
						?>
238
						JodelBlue <i class="fa fa-refresh fa-1x"></i></a>
239
					</h1>					
240
				</div>
241
			</nav>
242
		</header>
243
		
244
		<div class="mainContent container">		
245
			<div class="content row">
246
				<article class="topContent col-sm-8">
247
248
					<content id="posts">
249
						<?php
250
							$posts;
251
252
							//Get Post Details
253
							if(isset($_GET['postID']) && isset($_GET['getPostDetails']))
254
							{
255
								$userHandleBuffer = [];
256
257
								$accountCreator = new GetPostDetails();
258
								$accountCreator->setAccessToken($accessToken);
259
								$data = $accountCreator->execute();
260
								
261
								$posts[0] = $data;
262
								if(isset($data['children'])) {
263
									foreach($data['children'] as $key => $child)
264
									{
265
										
266
										if(!$child["parent_creator"] == 1)
267
										{
268
											$numberForUser = array_search($child['user_handle'], $userHandleBuffer);
269
											if($numberForUser === FALSE)
270
											{
271
												array_push($userHandleBuffer, $child['user_handle']);
272
												$data['children'][$key]['user_handle'] = count($userHandleBuffer);
273
											}
274
											else
275
											{
276
												$data['children'][$key]['user_handle'] = $numberForUser + 1;
277
											}
278
										}
279
280
										array_push($posts, $data['children'][$key]);
281
									}
282
									$loops = $data['child_count'] + 1;
283
								}
284
								else $loops = 1;
285
								$isDetailedView = TRUE;
286
							}
287
							//Get Posts
288
							else
289
							{
290
								$version = 'v2';
291
								if($view=='comment')
292
								{
293
									$url = "/v2/posts/location/discussed/";
294
								}
295
								else
296
								{
297
									if($view=='upVote')
298
									{
299
										$url = "/v2/posts/location/popular/";
300
									}
301
									else
302
									{
303
										$url = "/v3/posts/location/combo/";
304
										$version = 'v3';
305
									}
306
								}
307
308
								if($version == 'v3')
309
								{
310
									$posts = getPosts($lastPostId, $accessToken, $url, $version)['recent'];
311
								}
312
								else
313
								{
314
									$posts = getPosts($lastPostId, $accessToken, $url, $version)['posts'];
315
								}
316
								$loops = 29;
317
								$isDetailedView = FALSE;
318
							}
319
							
320
321 View Code Duplication
							for($i = 0; $i<$loops; $i++)
322
							{
323
							
324
							if(isset($posts[$i]))
325
							{
326
								$lastPostId = $posts[$i]['post_id'];
327
328
								jodelToHtml($posts[$i], $view, $isDetailedView);
329
							}
330
						} ?>
331
332
					</content>
333
					
334
					<?php if(!isset($_GET['postID']) && !isset($_GET['getPostDetails'])) { ?>
335
						<p id="loading">
336
							Loading…
337
						</p>
338
					<?php } ?>
339
				</article>
340
			
341
				<aside class="topSidebar col-sm-4 sidebar-outer">
342
					<div class="fixed">
343
						<article>
344
							<div>
345
								<h2>Position</h2>
346
								<form method="get">
347
									<input type="text" id="city" name="city" placeholder="<?php if(isset($newPositionStatus)) echo $newPositionStatus; ?>" required>
348
349
									<input type="submit" value="Set Location" /> 
350
								</form>
351
							</div>
352
						</article>
353
354
						<article>
355
							<div>
356
								<h2>Karma</h2>
357
								<?php echo getKarma($accessToken); ?>
358
							</div>
359
						</article>
360
361
						<article>
362
							<div>
363
								<?php if(isset($_GET['postID']) && isset($_GET['getPostDetails'])) { ?>
364
								<h2>Comment on Jodel</h2>
365
								<form method="POST">				
366
										<input type="hidden" name="ancestor" value="<?php echo htmlspecialchars($_GET['postID']);?>" />
367
										<textarea id="message" name="message" placeholder="Send a comment on a Jodel to all students within 10km" required></textarea> 
368
									<br />
369
									<input type="submit" value="SEND" /> 
370
								</form>
371
									<?php } else { ?>
372
								<h2>New Jodel</h2>
373
								<form method="POST">
374
									<textarea id="message" name="message" placeholder="Send a Jodel to all students within 10km" required></textarea> 
375
									<br />
376
									<select id="postColorPicker" name="color">
377
										<option value="06A3CB">Blue</option>
378
										<option value="8ABDB0">Teal</option>
379
										<option value="9EC41C">Green</option>
380
										<option value="FFBA00">Yellow</option>
381
										<option value="DD5F5F">Red</option>
382
										<option value="FF9908">Orange</option>
383
									</select> 
384
									<br />
385
									<input type="submit" value="SEND" /> 
386
								</form>
387
								<?php } ?>
388
							</div>
389
						</article>
390
							
391
						<article>
392
							<div>
393
								<h2>Login</h2>
394
							</div>
395
						</article>
396
					</div>
397
				</aside>
398
			</div>
399
			<div id="sortJodelBy" class="row">
400
				<div class="col-sm-12">
401
					<div class="row">
402
						<div class="col-sm-3">
403
							<a href="index.php" <?php if($view=='time') echo 'class="active"';?>><i class="fa fa-clock-o fa-3x"></i></a>
404
						</div>
405
						<div class="col-sm-3">
406
							<a href="index.php?view=comment" <?php if($view=='comment') echo 'class="active"';?>><i class="fa fa-commenting-o fa-3x"></i></a>
407
						</div>
408
						<div class="col-sm-3">
409
							<a href="index.php?view=upVote" <?php if($view=='upVote') echo 'class="active"';?>><i class="fa fa-angle-up fa-3x"></i></a>
410
						</div>
411
						<div class="col-sm-3">
412
							<nav>
413
								<a href="./about-us.html">about us</a>
414
							</nav>
415
						</div>
416
					</div>
417
				</div>	
418
			</div>
419
		</div>
420
		
421
		
422
		<!-- jQuery, Tether, Bootstrap JS and own-->
423
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha384-3ceskX3iaEnIogmQchP8opvBy3Mi7Ce34nWjpBIwVTHfGYWQS9jwHDVRnpKKHJg7" crossorigin="anonymous"></script>
424
    	<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.3.7/js/tether.min.js" integrity="sha384-XTs3FgkjiBgo8qjEjBk0tGmf3wPrWtA6coPfQDfFEY8AnYJwjalXCiosYRBIBZX8" crossorigin="anonymous"></script>
425
    	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/js/bootstrap.min.js" integrity="sha384-BLiI7JTZm+JWlgKa0M0kGRpJbF2J8q+qreVrKBC47e3K6BW78kGLrCkeRX6I9RoK" crossorigin="anonymous"></script>
426
    	<script src="js/jQueryEmoji.js"></script>
427
428
		<script>
429
430
			$(document).ready(function() {
431
				//Transform UTF-8 Emoji to img
432
				$('.jodel > content').Emoji();
433
434
				$('a').on('click', function(){
435
				    $('a').removeClass('selected');
436
				    $(this).addClass('selected');
437
				});
438
439
				function scrollToAnchor(aid){
440
				    var aTag = $("article[id='"+ aid +"']");
441
				    $('html,body').animate({scrollTop: aTag.offset().top-90},'slow');
442
				}
443
444
				<?php if(!isset($_GET['postID']) && !isset($_GET['getPostDetails'])) { ?>
445
446
				
447
448
449
450
				var win = $(window);
451
				var lastPostId = "<?php echo $lastPostId; ?>";
452
				var view = "<?php echo $view; ?>"
453
				var old_lastPostId = "";
454
				var morePostsAvailable = true;
455
456
				if(window.location.hash)
457
				{
458
					var hash = window.location.hash.slice(1);
459
460
					if(!$("article[id='"+ hash +"']").length)
461
					{
462
						for (var i = 5; i >= 0; i--)
463
						{
464
							if(!$("article[id='"+ hash +"']").length)
465
							{
466
								$.ajax({
467
									url: 'get-posts-ajax.php?lastPostId=' + lastPostId + '&view=' + view,
468
									dataType: 'html',
469
									async: false,
470
									success: function(html) {
471
										var div = document.createElement('div');
472
										div.innerHTML = html;
473
										var elements = div.childNodes;
474
										old_lastPostId = lastPostId;
475
										lastPostId = elements[3].textContent;
476
										lastPostId = lastPostId.replace(/\s+/g, '');
477
										//alert('Neu: ' + lastPostId + " Alt: " + old_lastPostId);
478
										if(lastPostId == old_lastPostId) {
479
											
480
											//morePostsAvailable = false;
481
										}
482
										else {
483
											//alert(elements[3].textContent);
484
											$('#posts').append(elements[1].innerHTML);
485
											$('#posts').hide().show(0);
486
										}
487
										$('#loading').hide();
488
									}
489
								});
490
491
								$('.jodel > content').Emoji();
492
							}
493
							
494
						}
495
						scrollToAnchor(hash);
496
497
					}						
498
				}
499
500
				// Each time the user scrolls
501
				win.scroll(function() {
502
503
504
					// End of the document reached?
505
					if (($(document).height() - win.height() == win.scrollTop()) && morePostsAvailable) {
506
						$('#loading').show();
507
508
						
509
						
510
						$.ajax({
511
							url: 'get-posts-ajax.php?lastPostId=' + lastPostId + '&view=' + view,
512
							dataType: 'html',
513
							async: false,
514
							success: function(html) {
515
								var div = document.createElement('div');
516
								div.innerHTML = html;
517
								var elements = div.childNodes;
518
								old_lastPostId = lastPostId;
519
								lastPostId = elements[3].textContent;
520
								lastPostId = lastPostId.replace(/\s+/g, '');
521
								//alert('Neu: ' + lastPostId + " Alt: " + old_lastPostId);
522
								if(lastPostId == old_lastPostId)
523
								{
524
									
525
									//morePostsAvailable = false;
526
								}
527
								else
528
								{
529
									//alert(elements[3].textContent);
530
									$('#posts').append(elements[1].innerHTML);
531
								}
532
								$('#loading').hide();
533
							}
534
						});
535
536
						$('.jodel > content').Emoji();
537
					}
538
				});
539
			<?php } ?>
540
			});	
541
542
		</script>
543
544
	</body>
545
</html>
546
547