Completed
Push — master ( a546a7...10dc14 )
by mains
02:38
created

index.php (3 issues)

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
18
	isTokenFreshByAccessToken($location, $db->real_escape_string($_COOKIE["JodelId"]));
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal JodelId does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
19
20
	$result = $db->query("SELECT * FROM accounts WHERE access_token='" . $db->real_escape_string($_COOKIE["JodelId"])  . "'");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal JodelId does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
This line exceeds maximum limit of 120 characters; contains 123 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...
21
	
22
	$newPositionStatus;
23
	
24 View Code Duplication
	if ($result->num_rows > 0)
25
	{
26
		// output data of each row
27
		while($row = $result->fetch_assoc())
28
		{
29
			$accessToken = $row["access_token"];
30
			$newPositionStatus = $row['name'];
31
		}
32
	}
33
	else
34
	{
35
		echo "Error: 0 results";
36
	}
37
	
38
	
39
	//createAccount();
40
41
42
	//Set View
43 View Code Duplication
	if(isset($_GET['view']))
44
	{
45
		switch ($_GET['view']) {
46
			case 'comment':
47
				$view = 'comment';
48
				break;
49
			
50
			case 'upVote':
51
				$view = 'upVote';
52
				break;
53
54
			default:
55
				$view = 'time';
56
				break;
57
		}
58
	}
59
	else
60
	{
61
		$view = 'time';
62
	}
63
	
64
	//Set Location
65
	if(isset($_GET['city'])) {
66
		$url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($_GET['city']) . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w';
67
		$result = Requests::post($url);
68
		if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST')
69
		{
70
			$newPositionStatus = "0 results";
71
		}
72
		else
73
		{
74
			$name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name'];
75
			$lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat'];
76
			$lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng'];
77
78
			$location = new Location();
79
			$location->setLat($lat);
80
			$location->setLng($lng);
81
			$location->setCityName($name);
82
			$accountCreator = new UpdateLocation();
83
			$accountCreator->setLocation($location);
84
			$accountCreator->setAccessToken($accessToken);
85
			$data = $accountCreator->execute();
86
87
			//safe location to db
88
			if($data == "Success")
89
			{
90
				$result = $db->query("UPDATE accounts 
91
						SET name='" . $name . "',
92
							lat='" . $lat . "',
93
							lng='" . $lng . "'
94
						WHERE id='1'");
95
96
				if($result === false)
97
				{
98
						echo "Updating location failed: (" . $db->errno . ") " . $db->error;
99
				}
100
				else
101
				{
102
					$newPositionStatus = $name;
103
				}
104
			}
105
		}
106
	}
107
	
108
	//Vote
109
	if(isset($_GET['vote']) && isset($_GET['postID'])) {
110 View Code Duplication
		if($_GET['vote'] == "up") {
111
			$accountCreator = new Upvote();
112
		}
113
		else if($_GET['vote'] == "down") {
114
			$accountCreator = new Downvote();
115
		}
116
		$accountCreator->setAccessToken($accessToken);
117
		$accountCreator->postId = $_GET['postID'];
118
		$data = $accountCreator->execute();
119
120
		header("Location: index.php#postId-" . htmlspecialchars($_GET['postID']));
121
		die();
122
	}
123
	
124
	
125
	//SendJodel
126
	if(isset($_POST['message'])) {
127
		$accountCreator = new SendJodel();
128
129
		if(isset($_POST['ancestor']))
130
		{
131
			$ancestor = $_POST['ancestor'];
132
			$accountCreator->ancestor = $ancestor;
133
		}
134
		if(isset($_POST['color']))
135
		{
136
			$color = $_POST['color'];
137
			switch ($color) {
138
				case '8ABDB0':
139
					$color = '8ABDB0';
140
					break;
141
				case '9EC41C':
142
					$color = '9EC41C';
143
					break;
144
				case '06A3CB':
145
					$color = '06A3CB';
146
					break;
147
				case 'FFBA00':
148
					$color = 'FFBA00';
149
					break;
150
				case 'DD5F5F':
151
					$color = 'DD5F5F';
152
					break;
153
				case 'FF9908':
154
					$color = 'FF9908';
155
					break;
156
				
157
				default:
158
					$color = '8ABDB0';
159
					break;
160
			}
161
			$accountCreator->color = $color;
162
			echo "Setting color:" . $color;
163
		}
164
		
165
		$location = new Location();
166
		$location->setLat('0.1');
167
		$location->setLng('0.1');
168
		$location->setCityName('Munich');
169
		
170
		$accountCreator->location = $location;
171
		
172
		$accountCreator->setAccessToken($accessToken);
173
		$data = $accountCreator->execute();
174
		http_redirect();
175
	}
176
?>
177
<!DOCTYPE html>
178
<html lang="en">
179
	<head>
180
		<title>JodelBlue WebClient</title>
181
		
182
		<meta charset="utf8">
183
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
184
		<meta http-equiv="x-ua-compatible" content="ie=edge">
185
		
186
		<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.">
187
		<meta name="keywords" content="jodelblue, jodel, blue, webclient, web, client">
188
		
189
		<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">
190
		<link rel="stylesheet" href="css/font-awesome.min.css">
191
		<link rel="stylesheet" href="style.css" type="text/css">
192
		
193
		<link rel="shortcut icon" type="image/x-icon" href="./img/favicon/favicon.ico">
194
		<link rel="icon" type="image/x-icon" href="./img/favicon/favicon.ico">
195
		<link rel="icon" type="image/gif" href="./img/favicon/favicon.gif">
196
		<link rel="icon" type="image/png" href="./img/favicon/favicon.png">
197
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon.png">
198
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-57x57.png" sizes="57x57">
199
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-60x60.png" sizes="60x60">
200
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-72x72.png" sizes="72x72">
201
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-76x76.png" sizes="76x76">
202
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-114x114.png" sizes="114x114">
203
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-120x120.png" sizes="120x120">
204
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-128x128.png" sizes="128x128">
205
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-144x144.png" sizes="144x144">
206
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-152x152.png" sizes="152x152">
207
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-180x180.png" sizes="180x180">
208
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-precomposed.png">
209
		<link rel="icon" type="image/png" href="./img/favicon/favicon-16x16.png" sizes="16x16">
210
		<link rel="icon" type="image/png" href="./img/favicon/favicon-32x32.png" sizes="32x32">
211
		<link rel="icon" type="image/png" href="./img/favicon/favicon-96x96.png" sizes="96x96">
212
		<link rel="icon" type="image/png" href="./img/favicon/favicon-160x160.png" sizes="160x160">
213
		<link rel="icon" type="image/png" href="./img/favicon/favicon-192x192.png" sizes="192x192">
214
		<link rel="icon" type="image/png" href="./img/favicon/favicon-196x196.png" sizes="196x196">
215
		<meta name="msapplication-TileImage" content="./img/favicon/win8-tile-144x144.png"> 
216
		<meta name="msapplication-TileColor" content="#5682a3"> 
217
		<meta name="msapplication-navbutton-color" content="#5682a3"> 
218
		<meta name="application-name" content="JodelBlue"/> 
219
		<meta name="msapplication-tooltip" content="JodelBlue"/> 
220
		<meta name="apple-mobile-web-app-title" content="JodelBlue"/> 
221
		<meta name="msapplication-square70x70logo" content="./img/favicon/win8-tile-70x70.png"> 
222
		<meta name="msapplication-square144x144logo" content="./img/favicon/win8-tile-144x144.png"> 
223
		<meta name="msapplication-square150x150logo" content="./img/favicon/win8-tile-150x150.png"> 
224
		<meta name="msapplication-wide310x150logo" content="./img/favicon/win8-tile-310x150.png"> 
225
		<meta name="msapplication-square310x310logo" content="./img/favicon/win8-tile-310x310.png"> 
226
	</head>
227
	
228
	<body>
229
		<header>
230
			<nav class="navbar navbar-full navbar-dark navbar-fixed-top">
231
				<div class="container">					
232
						<?php
233 View Code Duplication
							if(isset($_GET['postID']) && isset($_GET['getPostDetails']))
234
							{
235
								echo '<a id="comment-back" href="index.php?view=' . $view . '#postId-' . htmlspecialchars($_GET['postID']) . '">';
236
								echo '<i class="fa fa-angle-left fa-3x"></i>';
237
								echo '</a>';
238
								echo '<h1>';
239
								echo '<a href="index.php?getPostDetails=' . htmlspecialchars($_GET['getPostDetails']) . '&postID=' . htmlspecialchars($_GET['postID']) . '" class="spinnable">';
240
							}
241
							else
242
							{
243
								echo '<h1>';	
244
								echo '<a href="./" class="spinnable">';
245
							}
246
						?>
247
						JodelBlue <i class="fa fa-refresh fa-1x"></i></a>
248
					</h1>					
249
				</div>
250
			</nav>
251
		</header>
252
		
253
		<div class="mainContent container">		
254
			<div class="content row">
255
				<article class="topContent col-sm-8">
256
257
					<content id="posts">
258
						<?php
259
							$posts;
260
261
							//Get Post Details
262
							if(isset($_GET['postID']) && isset($_GET['getPostDetails']))
263
							{
264
								$userHandleBuffer = [];
265
266
								$accountCreator = new GetPostDetails();
267
								$accountCreator->setAccessToken($accessToken);
268
								$data = $accountCreator->execute();
269
								
270
								$posts[0] = $data;
271
								if(isset($data['children'])) {
272
									foreach($data['children'] as $key => $child)
273
									{
274
										
275
										if(!$child["parent_creator"] == 1)
276
										{
277
											$numberForUser = array_search($child['user_handle'], $userHandleBuffer);
278
											if($numberForUser === FALSE)
279
											{
280
												array_push($userHandleBuffer, $child['user_handle']);
281
												$data['children'][$key]['user_handle'] = count($userHandleBuffer);
282
											}
283
											else
284
											{
285
												$data['children'][$key]['user_handle'] = $numberForUser + 1;
286
											}
287
										}
288
289
										array_push($posts, $data['children'][$key]);
290
									}
291
									$loops = $data['child_count'] + 1;
292
								}
293
								else $loops = 1;
294
								$isDetailedView = TRUE;
295
							}
296
							//Get Posts
297
							else
298
							{
299
								$version = 'v2';
300
								if($view=='comment')
301
								{
302
									$url = "/v2/posts/location/discussed/";
303
								}
304
								else
305
								{
306
									if($view=='upVote')
307
									{
308
										$url = "/v2/posts/location/popular/";
309
									}
310
									else
311
									{
312
										$url = "/v3/posts/location/combo/";
313
										$version = 'v3';
314
									}
315
								}
316
317
								if($version == 'v3')
318
								{
319
									$posts = getPosts($lastPostId, $accessToken, $url, $version)['recent'];
320
								}
321
								else
322
								{
323
									$posts = getPosts($lastPostId, $accessToken, $url, $version)['posts'];
324
								}
325
								$loops = 29;
326
								$isDetailedView = FALSE;
327
							}
328
							
329
330 View Code Duplication
							for($i = 0; $i<$loops; $i++)
331
							{
332
							
333
							if(isset($posts[$i]))
334
							{
335
								$lastPostId = $posts[$i]['post_id'];
336
337
								jodelToHtml($posts[$i], $view, $isDetailedView);
338
							}
339
						} ?>
340
341
					</content>
342
					
343
					<?php if(!isset($_GET['postID']) && !isset($_GET['getPostDetails'])) { ?>
344
						<p id="loading">
345
							Loading…
346
						</p>
347
					<?php } ?>
348
				</article>
349
			
350
				<aside class="topSidebar col-sm-4 sidebar-outer">
351
					<div class="fixed">
352
						<article>
353
							<div>
354
								<h2>Position</h2>
355
								<form method="get">
356
									<input type="text" id="city" name="city" placeholder="<?php if(isset($newPositionStatus)) echo $newPositionStatus; ?>" required>
357
358
									<input type="submit" value="Set Location" /> 
359
								</form>
360
							</div>
361
						</article>
362
363
						<article>
364
							<div>
365
								<h2>Karma</h2>
366
								<?php echo getKarma($accessToken); ?>
367
							</div>
368
						</article>
369
370
						<article>
371
							<div>
372 View Code Duplication
								<?php if(isset($_GET['postID']) && isset($_GET['getPostDetails'])) { ?>
373
								<h2>Comment on Jodel</h2>
374
								<form method="POST">				
375
										<input type="hidden" name="ancestor" value="<?php echo htmlspecialchars($_GET['postID']);?>" />
376
										<textarea id="message" name="message" placeholder="Send a comment on a Jodel to all students within 10km" required></textarea> 
377
									<br />
378
									<input type="submit" value="SEND" /> 
379
								</form>
380
									<?php } else { ?>
381
								<h2>New Jodel</h2>
382
								<form method="POST">
383
									<textarea id="message" name="message" placeholder="Send a Jodel to all students within 10km" required></textarea> 
384
									<br />
385
									<select id="postColorPicker" name="color">
386
										<option value="06A3CB">Blue</option>
387
										<option value="8ABDB0">Teal</option>
388
										<option value="9EC41C">Green</option>
389
										<option value="FFBA00">Yellow</option>
390
										<option value="DD5F5F">Red</option>
391
										<option value="FF9908">Orange</option>
392
									</select> 
393
									<br />
394
									<input type="submit" value="SEND" /> 
395
								</form>
396
								<?php } ?>
397
							</div>
398
						</article>
399
							
400
						<article>
401
							<div>
402
								<h2>Login</h2>
403
							</div>
404
						</article>
405
					</div>
406
				</aside>
407
			</div>
408
			<div id="sortJodelBy" class="row">
409
				<div class="col-sm-12">
410
					<div class="row">
411
						<div class="col-sm-3">
412
							<a href="index.php" <?php if($view=='time') echo 'class="active"';?>><i class="fa fa-clock-o fa-3x"></i></a>
413
						</div>
414
						<div class="col-sm-3">
415
							<a href="index.php?view=comment" <?php if($view=='comment') echo 'class="active"';?>><i class="fa fa-commenting-o fa-3x"></i></a>
416
						</div>
417
						<div class="col-sm-3">
418
							<a href="index.php?view=upVote" <?php if($view=='upVote') echo 'class="active"';?>><i class="fa fa-angle-up fa-3x"></i></a>
419
						</div>
420
						<div class="col-sm-3">
421
							<nav>
422
								<a href="./about-us.html">about us</a>
423
							</nav>
424
						</div>
425
					</div>
426
				</div>	
427
			</div>
428
		</div>
429
		
430
		
431
		<!-- jQuery, Tether, Bootstrap JS and own-->
432
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha384-3ceskX3iaEnIogmQchP8opvBy3Mi7Ce34nWjpBIwVTHfGYWQS9jwHDVRnpKKHJg7" crossorigin="anonymous"></script>
433
    	<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.3.7/js/tether.min.js" integrity="sha384-XTs3FgkjiBgo8qjEjBk0tGmf3wPrWtA6coPfQDfFEY8AnYJwjalXCiosYRBIBZX8" crossorigin="anonymous"></script>
434
    	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/js/bootstrap.min.js" integrity="sha384-BLiI7JTZm+JWlgKa0M0kGRpJbF2J8q+qreVrKBC47e3K6BW78kGLrCkeRX6I9RoK" crossorigin="anonymous"></script>
435
    	<script src="js/jQueryEmoji.js"></script>
436
437
		<script>
438
			//BackButton
439
			function goBack()
440
			{
441
				window.history.back();
442
			}
443
444
			$(document).ready(function()
445
			{
446
447
448
				//Transform UTF-8 Emoji to img
449
				$('.jodel > content').Emoji();
450
451
				$('a').on('click', function(){
452
				    $('a').removeClass('selected');
453
				    $(this).addClass('selected');
454
				});
455
456
				function scrollToAnchor(aid){
457
				    var aTag = $("article[id='"+ aid +"']");
458
				    $('html,body').animate({scrollTop: aTag.offset().top-90},'slow');
459
				}
460
461 View Code Duplication
				<?php if(!isset($_GET['postID']) && !isset($_GET['getPostDetails'])) { ?>
462
463
				
464
465
466
467
				var win = $(window);
468
				var lastPostId = "<?php echo $lastPostId; ?>";
469
				var view = "<?php echo $view; ?>"
470
				var old_lastPostId = "";
471
				var morePostsAvailable = true;
472
473
				if(window.location.hash)
474
				{
475
					var hash = window.location.hash.slice(1);
476
477
					if(!$("article[id='"+ hash +"']").length)
478
					{
479
						for (var i = 5; i >= 0; i--)
480
						{
481
							if(!$("article[id='"+ hash +"']").length)
482
							{
483
								$.ajax({
484
									url: 'get-posts-ajax.php?lastPostId=' + lastPostId + '&view=' + view,
485
									dataType: 'html',
486
									async: false,
487
									success: function(html) {
488
										var div = document.createElement('div');
489
										div.innerHTML = html;
490
										var elements = div.childNodes;
491
										old_lastPostId = lastPostId;
492
										lastPostId = elements[3].textContent;
493
										lastPostId = lastPostId.replace(/\s+/g, '');
494
										//alert('Neu: ' + lastPostId + " Alt: " + old_lastPostId);
495
										if(lastPostId == old_lastPostId) {
496
											
497
											//morePostsAvailable = false;
498
										}
499
										else {
500
											//alert(elements[3].textContent);
501
											$('#posts').append(elements[1].innerHTML);
502
											$('#posts').hide().show(0);
503
										}
504
										$('#loading').hide();
505
									}
506
								});
507
508
								$('.jodel > content').Emoji();
509
							}
510
							
511
						}
512
						scrollToAnchor(hash);
513
514
					}						
515
				}
516
517
				// Each time the user scrolls
518
				win.scroll(function() {
519
520
521
					// End of the document reached?
522
					if (($(document).height() - win.height() == win.scrollTop()) && morePostsAvailable) {
523
						$('#loading').show();
524
525
						
526
						
527
						$.ajax({
528
							url: 'get-posts-ajax.php?lastPostId=' + lastPostId + '&view=' + view,
529
							dataType: 'html',
530
							async: false,
531
							success: function(html) {
532
								var div = document.createElement('div');
533
								div.innerHTML = html;
534
								var elements = div.childNodes;
535
								old_lastPostId = lastPostId;
536
								lastPostId = elements[3].textContent;
537
								lastPostId = lastPostId.replace(/\s+/g, '');
538
								//alert('Neu: ' + lastPostId + " Alt: " + old_lastPostId);
539
								if(lastPostId == old_lastPostId)
540
								{
541
									
542
									//morePostsAvailable = false;
543
								}
544
								else
545
								{
546
									//alert(elements[3].textContent);
547
									$('#posts').append(elements[1].innerHTML);
548
								}
549
								$('#loading').hide();
550
							}
551
						});
552
553
						$('.jodel > content').Emoji();
554
					}
555
				});
556
			<?php } ?>
557
			});	
558
559
		</script>
560
	</body>
561
</html>
562
563