Completed
Push — master ( 18a827...20d307 )
by mains
02:53
created

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('52.5134288');
7
	$location->setLng('13.2746394');
8
	$location->setCityName('Berlin');
9
10
	$accessToken;
11
12
	if(!isset($_COOKIE["JodelId"]))
13
	{
14
		$accessToken = createAccount();
15
		setcookie("JodelId", $accessToken);
16
	}
17
	else
18
	{
19
		$accessToken = $db->real_escape_string($_COOKIE["JodelId"]);
20
	}
21
22
	$location = getLocationByAccessToken($accessToken);
23
24
	isTokenFreshByAccessToken($location, $accessToken);
25
26
	$result = $db->query("SELECT * FROM accounts WHERE access_token='" . $accessToken  . "'");
27
	
28
	$newPositionStatus;
29
	
30 View Code Duplication
	if ($result->num_rows > 0)
31
	{
32
		// output data of each row
33
		while($row = $result->fetch_assoc())
34
		{
35
			$accessToken = $row["access_token"];
36
			$newPositionStatus = $row['name'];
37
		}
38
	}
39
	else
40
	{
41
		echo "Error: 0 results";
42
	}
43
	
44
	
45
	//createAccount();
46
47
48
	//Set View
49 View Code Duplication
	if(isset($_GET['view']))
50
	{
51
		switch ($_GET['view']) {
52
			case 'comment':
53
				$view = 'comment';
54
				break;
55
			
56
			case 'upVote':
57
				$view = 'upVote';
58
				break;
59
60
			default:
61
				$view = 'time';
62
				break;
63
		}
64
	}
65
	else
66
	{
67
		$view = 'time';
68
	}
69
	
70
	//Set Location
71
	if(isset($_GET['city'])) {
72
		$url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($_GET['city']) . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w';
73
		$result = Requests::post($url);
74
		if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST')
75
		{
76
			$newPositionStatus = "0 results";
77
		}
78
		else
79
		{
80
			$name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name'];
81
			$lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat'];
82
			$lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng'];
83
84
			$location = new Location();
85
			$location->setLat($lat);
86
			$location->setLng($lng);
87
			$location->setCityName($name);
88
			$accountCreator = new UpdateLocation();
89
			$accountCreator->setLocation($location);
90
			$accountCreator->setAccessToken($accessToken);
91
			$data = $accountCreator->execute();
92
93
			//safe location to db
94
			if($data == "Success")
95
			{
96
				$result = $db->query("UPDATE accounts 
97
						SET name='" . $name . "',
98
							lat='" . $lat . "',
99
							lng='" . $lng . "'
100
						WHERE access_token='" . $accessToken . "'");
101
102
				if($result === false)
103
				{
104
						echo "Updating location failed: (" . $db->errno . ") " . $db->error;
105
				}
106
				else
107
				{
108
					$newPositionStatus = $name;
109
				}
110
			}
111
		}
112
	}
113
	
114
	//Vote
115
	if(isset($_GET['vote']) && isset($_GET['postID'])) {
116 View Code Duplication
		if($_GET['vote'] == "up") {
117
			$accountCreator = new Upvote();
118
		}
119
		else if($_GET['vote'] == "down") {
120
			$accountCreator = new Downvote();
121
		}
122
		$accountCreator->setAccessToken($accessToken);
123
		$accountCreator->postId = $_GET['postID'];
124
		$data = $accountCreator->execute();
125
126
		header("Location: index.php#postId-" . htmlspecialchars($_GET['postID']));
127
		die();
128
	}
129
	
130
	
131
	//SendJodel
132
	if(isset($_POST['message'])) {
133
		$accountCreator = new SendJodel();
134
135
		if(isset($_POST['ancestor']))
136
		{
137
			$ancestor = $_POST['ancestor'];
138
			$accountCreator->ancestor = $ancestor;
139
		}
140
		if(isset($_POST['color']))
141
		{
142
			$color = $_POST['color'];
143
			switch ($color) {
144
				case '8ABDB0':
145
					$color = '8ABDB0';
146
					break;
147
				case '9EC41C':
148
					$color = '9EC41C';
149
					break;
150
				case '06A3CB':
151
					$color = '06A3CB';
152
					break;
153
				case 'FFBA00':
154
					$color = 'FFBA00';
155
					break;
156
				case 'DD5F5F':
157
					$color = 'DD5F5F';
158
					break;
159
				case 'FF9908':
160
					$color = 'FF9908';
161
					break;
162
				
163
				default:
164
					$color = '8ABDB0';
165
					break;
166
			}
167
			$accountCreator->color = $color;
168
		}
169
		
170
		$location = getLocationByAccessToken($accessToken);
171
		
172
		$accountCreator->location = $location;
173
		
174
		$accountCreator->setAccessToken($accessToken);
175
		$data = $accountCreator->execute();
176
177
		if(isset($_POST['ancestor']))
178
		{
179
			$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $_SERVER instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

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