Completed
Push — master ( a872d3...fc7130 )
by mains
02:41
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
	$config = parse_ini_file('config/config.ini.php');
6
7
	$location = new Location();
8
	$location->setLat($config['default_lat']);
9
	$location->setLng($config['default_lng']);
10
	$location->setCityName($config['default_location']);
11
12
	$accessToken;
13
	$accessToken_forId1;
14
	$deviceUid;
15
	$isSpider = FALSE;
16
17
	//What is dude doing with my Server?
18
	if($_SERVER['REMOTE_ADDR'] == '94.231.103.52')
19
	{
20
		echo('You are flooting my Server! Pls enable Cookies in your script and contact me: [email protected]');
21
		die();
22
	}
23
24
	//Check if it's a Spider or Google Bot
25
	if(botDeviceUidIsSet($config) && isUserBot())
26
	{
27
		$isSpider = TRUE;
28
		error_log('Spider or Bot checked in!');
29
		
30
		$deviceUid = $config['botDeviceUid'];
31
		$config = NULL;
32
	}
33
	else
34
	{
35
		$config = NULL;
36
		if(!isset($_COOKIE['JodelDeviceId']) || !isDeviceUidInDatabase($_COOKIE['JodelDeviceId']))
37
		{
38
			$deviceUid = createAccount();
39
			setcookie('JodelDeviceId', $deviceUid, time()+60*60*24*365*10);
40
			error_log('Created account with JodelDeviceId:' . $deviceUid .  ' for [' . $_SERVER ['HTTP_USER_AGENT'] . ']');
41
			
42
		}
43
		else
44
		{
45
			$deviceUid = $_COOKIE['JodelDeviceId'];
46
		}
47
	}
48
49
	$location = getLocationByDeviceUid($deviceUid);
50
	$newPositionStatus = $location->getCityName();
51
	$accessToken = isTokenFreshByDeviceUid($location, $deviceUid);
52
	//Acc is fresh. token and location is set
53
54
	$accessToken_forId1 = isTokenFresh($location);
55
	$deviceUid_forId1 = getDeviceUidByAccessToken($accessToken_forId1);
56
57
	//Set View
58 View Code Duplication
	if(isset($_GET['view']))
59
	{
60
		switch ($_GET['view']) {
61
			case 'comment':
62
				$view = 'comment';
63
				break;
64
			
65
			case 'upVote':
66
				$view = 'upVote';
67
				break;
68
69
			default:
70
				$view = 'time';
71
				break;
72
		}
73
	}
74
	else
75
	{
76
		$view = 'time';
77
	}
78
	
79
	//Verify Account
80
	if(isset($_GET['solution']) && isset($_GET['key']))
81
	{
82
		verifyCaptcha($accessToken_forId1);
83
	}
84
85
	//Set Location
86
	if(isset($_GET['city']))
87
	{
88
		$newPositionStatus = setLocation($accessToken, $deviceUid, $location->getCityName());
89
	}
90
	
91
	//Vote
92
	if(isset($_GET['vote']) && isset($_GET['postID']))
93
	{
94
		/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
95
		if(!deviceUidHasVotedThisPostId($deviceUid_forId1, $_GET['postID']))
96
		{
97
			if($_GET['vote'] == "up")
98
			{
99
				$accountCreator = new Upvote();
100
			}
101
			else if($_GET['vote'] == "down")
102
			{
103
				$accountCreator = new Downvote();
104
			}
105
			$accountCreator->setAccessToken($accessToken_forId1);
106
			$accountCreator->postId = htmlspecialchars($_GET['postID']);
107
			$data = $accountCreator->execute();
108
		*/
109
		votePostId($deviceUid_forId1, $accessToken_forId1);
110
	}
111
	
112
	//SendJodel
113
	if(isset($_POST['message']))
114
	{
115
		sendJodel($location, $accessToken_forId1);
116
	}
117
118
119
120
	$posts;
121
	//Is Channel or City
122
	if(isset($_GET['city']) && substr($_GET['city'], 0, 1) === '#')
123
	{
124
		$channel = substr($_GET['city'], 1);
125
126
		$accountCreator = new GetChannel();
127
		$accountCreator->setAccessToken($accessToken);
128
		$accountCreator->channel = $channel;
129
		$posts = $accountCreator->execute();
130
		if(array_key_exists('recent', $posts))
131
		{
132
			$posts = $posts['recent'];
133 View Code Duplication
			if(!array_key_exists(0, $posts))
134
			{
135
				$posts[0] = array(
136
			    "post_id" => "0",
137
			    "discovered_by" => 0,
138
			    "message" => "Not found",
139
			    "created_at" => "2017-02-11T16:44:50.385Z",
140
			    "updated_at" => "2017-02-11T16:44:50.385Z",
141
			    "pin_count" => 0,
142
			    "color" => "FFBA00",
143
			    "got_thanks" => FALSE,
144
			    "post_own" => "friend",
145
			    "discovered" => 0,
146
			    "distance" => 9,
147
			    "vote_count" => 0,
148
			    "location" =>
149
			    array("name" => "Berlin",
150
			      "loc_coordinates" =>
151
			      array(
152
			        "lat" => 0,
153
			        "lng" => 0
154
			      ),
155
			      "loc_accuracy" => 0,
156
			      "country" => "",
157
			      "city" => "",
158
			    ),
159
			    "tags" =>
160
			    array(),
161
			    "user_handle" => "0"
162
			 );
163
			}
164
		}
165 View Code Duplication
		else
166
		{
167
			$posts = array();
168
			$posts[0] = 
169
			array(
170
			    "post_id" => "0",
171
			    "discovered_by" => 0,
172
			    "message" => "Bad Request",
173
			    "created_at" => "2017-02-11T16:44:50.385Z",
174
			    "updated_at" => "2017-02-11T16:44:50.385Z",
175
			    "pin_count" => 0,
176
			    "color" => "FFBA00",
177
			    "got_thanks" => FALSE,
178
			    "post_own" => "friend",
179
			    "discovered" => 0,
180
			    "distance" => 9,
181
			    "vote_count" => 0,
182
			    "location" =>
183
			    array("name" => "Berlin",
184
			      "loc_coordinates" =>
185
			      array(
186
			        "lat" => 0,
187
			        "lng" => 0
188
			      ),
189
			      "loc_accuracy" => 0,
190
			      "country" => "",
191
			      "city" => "",
192
			    ),
193
			    "tags" =>
194
			    array(),
195
			    "user_handle" => "0"
196
			 );
197
198
199
		}
200
		$loops = 29;
201
		$isDetailedView = FALSE;
202
	}
203
	else
204
	{
205
		//Get Post Details
206
		if(isset($_GET['postID']) && isset($_GET['getPostDetails']))
207
		{
208
			$userHandleBuffer = [];
209
210
			$accountCreator = new GetPostDetails();
211
			$accountCreator->setAccessToken($accessToken);
212
			$data = $accountCreator->execute();
213
214
			if(property_exists($data, 'status_code') && $data->status_code == 404)
215
			{
216
				header('HTTP/1.1 410 Gone');
217
				include './error-pages/410.html';
218
				exit;
219
			}
220
221
			$posts[0] = $data;
222
223
			if(array_key_exists('children', $data)) {
224
				foreach($data['children'] as $key => $child)
225
				{
226
					
227
					if(!$child["parent_creator"] == 1)
228
					{
229
						$numberForUser = array_search($child['user_handle'], $userHandleBuffer);
230
						if($numberForUser === FALSE)
231
						{
232
							array_push($userHandleBuffer, $child['user_handle']);
233
							$data['children'][$key]['user_handle'] = count($userHandleBuffer);
234
						}
235
						else
236
						{
237
							$data['children'][$key]['user_handle'] = $numberForUser + 1;
238
						}
239
					}
240
241
					array_push($posts, $data['children'][$key]);
242
				}
243
				$loops = $data['child_count'] + 1;
244
			}
245
			else
246
			{
247
				$loops = 1;
248
			}
249
			$isDetailedView = TRUE;
250
		}
251
		//Get Posts
252
		else
253
		{
254
			$version = 'v2';
255
			if($view=='comment')
256
			{
257
				$url = "/v2/posts/location/discussed/";
258
			}
259
			else
260
			{
261
				if($view=='upVote')
262
				{
263
					$url = "/v2/posts/location/popular/";
264
				}
265
				else
266
				{
267
					$url = "/v3/posts/location/combo/";
268
					$version = 'v3';
269
				}
270
			}
271
272
			if($version == 'v3')
273
			{
274
				$posts = getPosts($lastPostId, $accessToken, $url, $version)['recent'];
275
			}
276
			else
277
			{
278
				$posts = getPosts($lastPostId, $accessToken, $url, $version)['posts'];
279
			}
280
			$loops = 29;
281
			$isDetailedView = FALSE;
282
		}
283
	}
284
?>
285
<!DOCTYPE html>
286
<html lang="en">
287
	<head>
288
		<title><?php echo getTitle($posts[0], $view, $isDetailedView);?></title>
289
		
290
		<meta charset="utf-8">
291
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
292
		<meta http-equiv="x-ua-compatible" content="ie=edge">
293
		
294
		<meta name="description" content="<?php echo getMetaDescription($posts[0], $view, $isDetailedView);?>">
295
		<meta name="keywords" content="jodelblue, jodel, blue, webclient, web, client, web-app, browser, app">
296
		
297
		<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">
298
		<link rel="stylesheet" href="css/font-awesome.min.css">
299
		<link rel="stylesheet" href="style.css" type="text/css">
300
		
301
		<link rel="shortcut icon" type="image/x-icon" href="./img/favicon/favicon.ico">
302
		<link rel="icon" type="image/x-icon" href="./img/favicon/favicon.ico">
303
		<link rel="icon" type="image/gif" href="./img/favicon/favicon.gif">
304
		<link rel="icon" type="image/png" href="./img/favicon/favicon.png">
305
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon.png">
306
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-57x57.png" sizes="57x57">
307
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-60x60.png" sizes="60x60">
308
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-72x72.png" sizes="72x72">
309
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-76x76.png" sizes="76x76">
310
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-114x114.png" sizes="114x114">
311
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-120x120.png" sizes="120x120">
312
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-128x128.png" sizes="128x128">
313
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-144x144.png" sizes="144x144">
314
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-152x152.png" sizes="152x152">
315
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-180x180.png" sizes="180x180">
316
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-precomposed.png">
317
		<link rel="icon" type="image/png" href="./img/favicon/favicon-16x16.png" sizes="16x16">
318
		<link rel="icon" type="image/png" href="./img/favicon/favicon-32x32.png" sizes="32x32">
319
		<link rel="icon" type="image/png" href="./img/favicon/favicon-96x96.png" sizes="96x96">
320
		<link rel="icon" type="image/png" href="./img/favicon/favicon-160x160.png" sizes="160x160">
321
		<link rel="icon" type="image/png" href="./img/favicon/favicon-192x192.png" sizes="192x192">
322
		<link rel="icon" type="image/png" href="./img/favicon/favicon-196x196.png" sizes="196x196">
323
		<meta name="msapplication-TileImage" content="./img/favicon/win8-tile-144x144.png"> 
324
		<meta name="msapplication-TileColor" content="#5682a3"> 
325
		<meta name="msapplication-navbutton-color" content="#5682a3"> 
326
		<meta name="application-name" content="JodelBlue"/> 
327
		<meta name="msapplication-tooltip" content="JodelBlue"/> 
328
		<meta name="apple-mobile-web-app-title" content="JodelBlue"/> 
329
		<meta name="msapplication-square70x70logo" content="./img/favicon/win8-tile-70x70.png"> 
330
		<meta name="msapplication-square144x144logo" content="./img/favicon/win8-tile-144x144.png"> 
331
		<meta name="msapplication-square150x150logo" content="./img/favicon/win8-tile-150x150.png"> 
332
		<meta name="msapplication-wide310x150logo" content="./img/favicon/win8-tile-310x150.png"> 
333
		<meta name="msapplication-square310x310logo" content="./img/favicon/win8-tile-310x310.png"> 
334
	</head>
335
	
336
	<body>
337
		<header>
338
			<nav class="navbar navbar-full navbar-dark navbar-fixed-top">
339
				<div class="container">					
340
						<?php
341
342
							if(isset($_GET['postID']) && isset($_GET['getPostDetails']))
343
							{
344
								echo '<a id="comment-back" href="index.php?view=' . $view . '#postId-' . htmlspecialchars($_GET['postID']) . '">';
345
								echo '<i class="fa fa-angle-left fa-3x"></i>';
346
								echo '</a>';
347
								echo '<h1>';
348
								echo '<a href="index.php?getPostDetails=' . htmlspecialchars($_GET['getPostDetails']) . '&postID=' . htmlspecialchars($_GET['postID']) . '" class="spinnable">';
349
							}
350
							else
351
							{
352
								echo '<h1>';	
353
								echo '<a href="./" class="spinnable">';
354
							}
355
						?>
356
						JodelBlue <i class="fa fa-refresh fa-1x"></i></a>
357
					</h1>
358
359
					<div id="location_mobile" class="hidden-sm-up">
360
						<form method="get">
361
							<input type="text" id="city_mobile" name="city" placeholder="<?php if(isset($newPositionStatus)) echo $newPositionStatus; ?>" required>
362
363
							<input type="submit" id="submit_mobile" class="fa" value="&#xf0ac;" />
364
						</form>
365
					</div>
366
				</div>
367
			</nav>
368
		</header>
369
		
370
		<div class="mainContent container">		
371
			<div class="content row">
372
				<article class="topContent col-sm-8">
373
374
					<content id="posts">
375
						<?php
376
							for($i = 0; $i<$loops; $i++)
377
							{
378
								if(array_key_exists($i, $posts) && array_key_exists('post_id', $posts[$i]) && isset($posts[$i]['post_id']))
379
								{
380
									$lastPostId = $posts[$i]['post_id'];
381
382
									jodelToHtml($posts[$i], $view, $isDetailedView);
383
								}
384
							} ?>
385
386
					</content>
387
					
388
					<?php if(!isset($_GET['postID']) && !isset($_GET['getPostDetails'])) { ?>
389
						<p id="loading">
390
							Loading…
391
						</p>
392
					<?php } ?>
393
				</article>
394
			
395
				<aside class="topSidebar col-sm-4 sidebar-outer">
396
					<div class="fixed">
397
						<article>
398
							<div>
399
								<h2>Position / Hashtag</h2>
400
								<form method="get">
401
									<input type="text" id="city" name="city" placeholder="<?php if(isset($newPositionStatus)) echo $newPositionStatus; ?>" required>
402
									<label>try: #jhj</label><br>
403
									<input type="submit" value="Set Location" /> 
404
								</form>
405
							</div>
406
						</article>
407
408
						<article>
409
							<div>
410
								<h2>Karma</h2>
411
								<?php echo getKarma($accessToken_forId1); ?>
412
							</div>
413
						</article>
414
415
						<article>
416
							<div>
417
								<?php if(isset($_GET['postID']) && isset($_GET['getPostDetails'])) { ?>
418
								<h2>Comment on Jodel</h2>
419
								<form method="POST">				
420
										<input type="hidden" name="ancestor" value="<?php echo htmlspecialchars($_GET['postID']);?>" />
421
										<textarea id="message" name="message" placeholder="Send a comment on a Jodel to all students within 10km" required></textarea> 
422
									<br />
423
									<input type="submit" value="SEND" /> 
424
								</form>
425
									<?php } else { ?>
426
								<h2>New Jodel</h2>
427
								<form method="POST">
428
									<textarea id="message" name="message" placeholder="Send a Jodel to all students within 10km" required></textarea> 
429
									<br />
430
									<select id="postColorPicker" name="color">
431
										<option value="06A3CB">Blue</option>
432
										<option value="8ABDB0">Teal</option>
433
										<option value="9EC41C">Green</option>
434
										<option value="FFBA00">Yellow</option>
435
										<option value="DD5F5F">Red</option>
436
										<option value="FF9908">Orange</option>
437
									</select> 
438
									<br />
439
									<input type="submit" value="SEND" /> 
440
								</form>
441
								<?php } ?>
442
							</div>
443
						</article>
444
							
445
						<article>
446
							<div>
447
								<h2>Login</h2>
448
							</div>
449
						</article>
450
					</div>
451
				</aside>
452
			</div>
453
			<div id="sortJodelBy" class="row">
454
				<div class="col-xs-12">
455
					<div class="row">
456
						<div class="col-xs-3">
457
							<a href="index.php" <?php if($view=='time') echo 'class="active"';?>><i class="fa fa-clock-o fa-3x"></i></a>
458
						</div>
459
						<div class="col-xs-3">
460
							<a href="index.php?view=comment" <?php if($view=='comment') echo 'class="active"';?>><i class="fa fa-commenting-o fa-3x"></i></a>
461
						</div>
462
						<div class="col-xs-3">
463
							<a href="index.php?view=upVote" <?php if($view=='upVote') echo 'class="active"';?>><i class="fa fa-angle-up fa-3x"></i></a>
464
						</div>
465
						<div class="col-xs-3">
466
							<nav>
467
								<a href="./about-us.html">about us</a>
468
							</nav>
469
						</div>
470
					</div>
471
				</div>	
472
			</div>
473
		</div>
474
		
475
		
476
		<!-- jQuery, Tether, Bootstrap JS and own-->
477
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha384-3ceskX3iaEnIogmQchP8opvBy3Mi7Ce34nWjpBIwVTHfGYWQS9jwHDVRnpKKHJg7" crossorigin="anonymous"></script>
478
    	<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.3.7/js/tether.min.js" integrity="sha384-XTs3FgkjiBgo8qjEjBk0tGmf3wPrWtA6coPfQDfFEY8AnYJwjalXCiosYRBIBZX8" crossorigin="anonymous"></script>
479
    	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/js/bootstrap.min.js" integrity="sha384-BLiI7JTZm+JWlgKa0M0kGRpJbF2J8q+qreVrKBC47e3K6BW78kGLrCkeRX6I9RoK" crossorigin="anonymous"></script>
480
    	<script src="js/jQueryEmoji.js"></script>
481
482
		<script>
483
			//BackButton
484
			function goBack()
485
			{
486
				window.history.back();
487
			}
488
489
			$(document).ready(function()
490
			{
491
				//Transform UTF-8 Emoji to img
492
				$('.jodel > content').Emoji();
493
494
				$('a').on('click', function(){
495
				    $('a').removeClass('selected');
496
				    $(this).addClass('selected');
497
				});
498
499
				function scrollToAnchor(aid){
500
				    var aTag = $("article[id='"+ aid +"']");
501
				    $('html,body').animate({scrollTop: aTag.offset().top-90},'slow');
502
				}
503
504
				<?php if(!isset($_GET['postID']) && !isset($_GET['getPostDetails'])) { ?>
505
506
				
507
508
509
510
				var win = $(window);
511
				var lastPostId = "<?php echo $lastPostId; ?>";
512
				var view = "<?php echo $view; ?>"
513
				var old_lastPostId = "";
514
				var morePostsAvailable = true;
515
516
				if(window.location.hash)
517
				{
518
					var hash = window.location.hash.slice(1);
519
520
					if(!$("article[id='"+ hash +"']").length)
521
					{
522
						for (var i = 5; i >= 0; i--)
523
						{
524
							if(!$("article[id='"+ hash +"']").length)
525
							{
526
								$.ajax({
527
									url: 'get-posts-ajax.php?lastPostId=' + lastPostId + '&view=' + view,
528
									dataType: 'html',
529
									async: false,
530
									success: function(html) {
531
										var div = document.createElement('div');
532
										div.innerHTML = html;
533
										var elements = div.childNodes;
534
										old_lastPostId = lastPostId;
535
										lastPostId = elements[3].textContent;
536
										lastPostId = lastPostId.replace(/\s+/g, '');
537
										//alert('Neu: ' + lastPostId + " Alt: " + old_lastPostId);
538
										if(lastPostId == old_lastPostId) {
539
											
540
											//morePostsAvailable = false;
541
										}
542
										else {
543
											//alert(elements[3].textContent);
544
											$('#posts').append(elements[1].innerHTML);
545
											$('#posts').hide().show(0);
546
										}
547
										$('#loading').hide();
548
									}
549
								});
550
551
								$('.jodel > content').Emoji();
552
							}
553
							
554
						}
555
						scrollToAnchor(hash);
556
557
					}						
558
				}
559
560
				// Each time the user scrolls
561
				win.scroll(function() {
562
563
564
					// End of the document reached?
565
					if ($(window).scrollTop() + $(window).height() > $(document).height() - 100 && morePostsAvailable)
566
					{
567
						$('#loading').show();
568
569
						$.ajax({
570
							url: 'get-posts-ajax.php?lastPostId=' + lastPostId + '&view=' + view,
571
							dataType: 'html',
572
							async: false,
573
							success: function(html) {
574
								var div = document.createElement('div');
575
								div.innerHTML = html;
576
								var elements = div.childNodes;
577
								old_lastPostId = lastPostId;
578
								lastPostId = elements[3].textContent;
579
								lastPostId = lastPostId.replace(/\s+/g, '');
580
								//alert('Neu: ' + lastPostId + " Alt: " + old_lastPostId);
581
								if(lastPostId == old_lastPostId)
582
								{
583
									
584
									//morePostsAvailable = false;
585
								}
586
								else
587
								{
588
									//alert(elements[3].textContent);
589
									$('#posts').append(elements[1].innerHTML);
590
								}
591
								$('#loading').hide();
592
							}
593
						});
594
595
						$('.jodel > content').Emoji();
596
					}
597
				});
598
			<?php } ?>
599
			});	
600
601
		</script>
602
603
		<?php  
604
			if(is_file('./piwik-script.html'))
605
			{
606
			    require_once('./piwik-script.html');
607
			}
608
		?>
609
610
	</body>
611
</html>
612
613