Completed
Push — master ( 285880...d65ec1 )
by mains
02:43
created

index.php (4 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('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
	$newPostionStatus;
16
	
17 View Code Duplication
	if ($result->num_rows > 0)
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
	{
19
		// output data of each row
20
		while($row = $result->fetch_assoc())
21
		{
22
			$accessToken = $row["access_token"];
23
		}
24
	}
25
	else
26
	{
27
		echo "Error: 0 results";
28
	}
29
	
30
	
31
	//createAccount();
32
	
33
	//Set Location
34
	if(isset($_GET['city'])) {
35
		
36
		$url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . $_GET['city'] . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w';
37
		$result = Requests::post($url);
38
		if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS')
39
		{
40
			$newPostionStatus = "0 results";
41
		}
42
		else
43
		{
44
			$location = new Location();
45
			$location->setLat(json_decode($result->body, true)['results']['0']['geometry']['location']['lat']);
46
			$location->setLng(json_decode($result->body, true)['results']['0']['geometry']['location']['lng']);
47
			$location->setCityName($_GET['city']);
48
			$accountCreator = new UpdateLocation();
49
			$accountCreator->setLocation($location);
50
			$accountCreator->setAccessToken($accessToken);
51
			$data = $accountCreator->execute();
52
		}
53
	}
54
	
55
	//Vote
56
	if(isset($_GET['vote']) && isset($_GET['postID'])) {
57
		if($_GET['vote'] == "up") {
58
			$accountCreator = new Upvote();
59
		}
60
		else if($_GET['vote'] == "down") {
61
			$accountCreator = new Downvote();
62
		}
63
		$accountCreator->setAccessToken($accessToken);
64
		$data = $accountCreator->execute();
65
66
		header("Location: index.php#postId-" . $_GET['postID']);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Location: index.php#postId- 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...
67
		die();
68
	}
69
	
70
	
71
	//SendJodel
72
	if(isset($_POST['message'])) {
73
		$ancestor;
74
		if(isset($_POST['ancestor']))
75
		{
76
			$ancestor = $_POST['ancestor'];
77
		}
78
		
79
		$location = new Location();
80
		$location->setLat('0.1');
81
		$location->setLng('0.1');
82
		$location->setCityName('Munich');
83
		$accountCreator = new SendJodel();
84
		$accountCreator->setLocation($location);
85
		$accountCreator->setAncestor($ancestor);
86
		$accountCreator->setAccessToken($accessToken);
87
		$data = $accountCreator->execute();
88
	}
89
?>
90
<!DOCTYPE html>
91
<html lang="de">
92
	<head>
93
		<title>JodelBlue WebClient - </title>
94
		
95
		<meta charset="utf8" />
96
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
97
		<meta http-equiv="x-ua-compatible" content="ie=edge">
98
		
99
		<meta name="description" content=""/>
100
		<meta name="keywords" content=""/>
101
		
102
		<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">
103
		<link rel="stylesheet" href="css/font-awesome.min.css">
104
		<link rel="stylesheet" href="style.css" type="text/css">
105
		
106
		<link rel="shortcut icon" href="img/favicon/favicon.ico" type="image/x-icon">
107
		<link rel="icon" href="img/favicon/favicon.ico" type="image/x-icon">	
108
	</head>
109
	
110
	<body>
111
		
112
		<div class="mainContent container">
113
114
			<header class="mainHeader">
115
				<a href="index.php">
116
					<h1>
117
						JodelBlue
118
						<?php if(!isset($_GET['postID']) && !isset($_GET['getPostDetails'])) echo '<i class="fa fa-refresh fa-1x"></i>';?>
119
					</h1>					
120
				</a>
121
				<div class="clear"></div>
122
			</header>
123
		
124
			<div class="content row">
125
				<article class="topContent col-sm-8">
126
127
					<content id="posts">
128
						<?php
129
							$posts;
130
131
							//Get Post Details
132
							if(isset($_GET['postID']) && isset($_GET['getPostDetails'])) {
133
								//Header Nav in Comment View
134
								?>
135
								<a id="comment-back" href="index.php#postId-<?php echo $_GET['postID'];?>">
136
									<i class="fa fa-angle-left fa-3x"></i>
137
								</a>
138
139
								<a id="comment-refresh" href="index.php?getPostDetails=<?php echo $_GET['getPostDetails'];?>&postID=<?php echo $_GET['postID'];?>">
140
									<i class="fa fa-refresh fa-2x"></i>
141
								</a>
142
								<?php
143
144
145
								$accountCreator = new GetPostDetails();
146
								$accountCreator->setAccessToken($accessToken);
147
								$data = $accountCreator->execute();
148
								
149
								$posts[0] = $data;
150
								if(isset($data['children'])) {
151
									foreach($data['children'] as $child) {
152
										array_push($posts, $child);
153
									}
154
									$loops = $data['child_count'] + 1;
155
								}
156
								else $loops = 1;
157
								$showCommentIcon = FALSE;
158
							}
159
							//Get Posts
160
							else {
161 View Code Duplication
								if(isset($_GET['commentView']))
162
								{
163
									$commentView = true;
164
									$url = "/v2/posts/location/discussed/";
165
								}
166
								else
167
								{
168
									if(isset($_GET['upVoteView']))
169
									{
170
										$upVoteView = true;
171
										$url = "/v2/posts/location/popular/";
172
									}
173
									else
174
									{
175
										$timeView = true;
176
										$url = "/v2/posts";
177
									}
178
								}
179
180
								$posts = getPosts($lastPostId, $accessToken, $url)['posts'];
181
								$loops = 29;
182
								$showCommentIcon = TRUE;
183
							}
184
							
185
186
							for($i = 0; $i<$loops; $i++) {
187
							
188
							if(isset($posts[$i])) {
189
							$lastPostId = $posts[$i]['post_id'];
190
191
							
192
							$now = new DateTime();
193
							$d = new DateTime($posts[$i]["created_at"]);
194
							
195
							
196
							//Time to time difference
197
							$timediff = $now->diff($d);
198
199
							$timediff_inSeconds = (string)$timediff->format('%s');
200
							$timediff_inMinutes = (string)$timediff->format('%i');
201
							$timediff_inHours = (string)$timediff->format('%h');
202
							$timediff_inDays = (string)$timediff->format('%d');
203
							$timediff_inMonth = (string)$timediff->format('%m');
204 View Code Duplication
							if($timediff_inMonth!=0) {
205
									$timediff = $timediff_inMonth . "m";
206
							}
207
							else
208
							{
209
								if($timediff_inDays!=0)
210
								{
211
									$timediff = $timediff_inDays . "d";
212
								}
213
								else
214
								{
215
									if($timediff_inHours!=0)
216
									{
217
										$timediff = $timediff_inHours . "h";
218
									}
219
									else
220
									{
221
										if($timediff_inMinutes!=0)
222
										{
223
											$timediff = $timediff_inMinutes . "m";
224
										}
225
										else
226
										{
227
											$timediff = $timediff_inSeconds . "s";
228
										}
229
									}
230
								}
231
							}
232
						?>
233
						
234
						<article id ="postId-<?php echo $posts[$i]["post_id"]; ?>" class="jodel" style="background-color: #<?php echo $posts[$i]["color"];?>;">
235
							<content>
236
								<?php 
237 View Code Duplication
								if(isset($posts[$i]["image_url"])) {
238
									echo '<img src="' . $posts[$i]["image_url"] . '">';
239
								}
240
								else {
241
									echo nl2br($posts[$i]["message"]);
242
								}
243
								?>
244
							</content>
245
							<aside>
246
								<a href="index.php?vote=up&postID=<?php echo $posts[$i]["post_id"];?>">
247
									<i class="fa fa-angle-up fa-3x"></i>
248
								</a>	
249
									<br />
250
								<?php echo $posts[$i]["vote_count"];?><br />
251
								<a href="index.php?vote=down&postID=<?php echo $posts[$i]["post_id"];?>">
252
									<i class="fa fa-angle-down fa-3x"></i>
253
								</a>
254
							</aside>
255
						
256
							<footer>
257
								<table>
258
									<tr>
259
										<td class="time">
260
											<span data-tooltip="Time">
261
												<i class="fa fa-clock-o"></i>
262
												<?php echo $timediff;?>
263
											</span> 
264
										</td>
265
										<td class="comments">
266 View Code Duplication
											<?php if($showCommentIcon) {?>
267
											<span data-tooltip="Comments">
268
												<a href="index.php?getPostDetails=true&postID=<?php echo $posts[$i]["post_id"];?>">
269
													<i class="fa fa-commenting-o"></i>
270
													<?php if(array_key_exists("child_count", $posts[$i])) {
271
																echo $posts[$i]["child_count"];
272
															} else echo "0";
273
													?>
274
													</a>
275
											</span>
276
											<?php } ?>
277
										</td>
278
										<td class="distance">
279
											<span data-tooltip="Distance">
280
												<i class="fa fa-map-marker"></i>
281
												<?php echo $posts[$i]["distance"];?> km
282
											</span>
283
										</td>
284
									</tr>
285
								</table>
286
							</footer>
287
						</article>
288
						
289
290
						
291
						<?php }
292
						} ?>
293
294
					</content>
295
					
296
					<?php if(!isset($_GET['postID']) && !isset($_GET['getPostDetails'])) { ?>
297
						<p id="loading">
298
							Loading…
299
						</p>
300
					<?php } ?>
301
				</article>
302
			
303
				<aside class="topSidebar col-sm-4 sidebar-outer">
304
					<article>
305
						<h2>Position</h2>
306
						<form method="get">
307
							<input type="text" id="city" name="city" placeholder="<?php if(isset($newPositionStatus)) echo $newPositionStatus; else echo $posts[0]["location"]["name"]; ?>" required>
308
309
							<input type="submit" value="Set Location" /> 
310
						</form>
311
						
312
					</article>
313
314
					<article>
315
						<h2>Karma</h2>
316
						<?php echo getKarma($accessToken); ?>
317
					</article>
318
319
					<article>
320 View Code Duplication
						<?php if(isset($_GET['postID']) && isset($_GET['getPostDetails'])) { ?>
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
321
						<h2>Comment on Jodel</h2>
322
						<form method="POST">				
323
								<input type="hidden" name="ancestor" value="<?php echo $_GET['postID'];?>" />
324
								<textarea id="message" name="message" placeholder="Send a comment on a Jodel to all students within 10km" required></textarea> 
325
							<br />
326
							<input type="submit" value="SEND" /> 
327
						</form>
328
							<?php } else { ?>
329
						<h2>New Jodel</h2>
330
						<form method="POST">
331
							<textarea id="message" name="message" placeholder="Send a Jodel to all students within 10km" required></textarea> 
332
							<br />
333
							<input type="submit" value="SEND" /> 
334
						</form>
335
						<?php } ?>
336
337
					</article>
338
						
339
					<article>
340
						<h2>Login</h2>
341
					</article>
342
				</aside>
343
			</div>
344
			<div id="sortJodelBy" class="row">
345
				<div class="col-sm-12">
346
					<div class="row">
347
						<div class="col-sm-3">
348
							<a href="index.php" <?php if(isset($timeView)) echo 'class="active"';?>><i class="fa fa-clock-o fa-3x"></i></a>
349
						</div>
350
						<div class="col-sm-3">
351
							<a href="index.php?commentView=true" <?php if(isset($commentView)) echo 'class="active"';?>><i class="fa fa-commenting-o fa-3x"></i></a>
352
						</div>
353
						<div class="col-sm-3">
354
							<a href="index.php?upVoteView=true" <?php if(isset($upVoteView)) echo 'class="active"';?>><i class="fa fa-angle-up fa-3x"></i></a>
355
						</div>
356
						<div class="col-sm-3">
357
							<nav>
358
								<a href="./impressum.html">Impressum</a> | <a href="./datenschutz.html">Datenschutz</a>
359
							</nav>
360
						</div>
361
					</div>
362
				</div>	
363
			</div>
364
		</div>
365
		
366
		
367
		<!-- jQuery, Tether and Bootstrap JS -->
368
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha384-3ceskX3iaEnIogmQchP8opvBy3Mi7Ce34nWjpBIwVTHfGYWQS9jwHDVRnpKKHJg7" crossorigin="anonymous"></script>
369
    	<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.3.7/js/tether.min.js" integrity="sha384-XTs3FgkjiBgo8qjEjBk0tGmf3wPrWtA6coPfQDfFEY8AnYJwjalXCiosYRBIBZX8" crossorigin="anonymous"></script>
370
    	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/js/bootstrap.min.js" integrity="sha384-BLiI7JTZm+JWlgKa0M0kGRpJbF2J8q+qreVrKBC47e3K6BW78kGLrCkeRX6I9RoK" crossorigin="anonymous"></script>
371
372
		<script>
373
			$('a').on('click', function(){
374
			    $('a').removeClass('selected');
375
			    $(this).addClass('selected');
376
			});
377
378 View Code Duplication
			<?php if(!isset($_GET['postID']) && !isset($_GET['getPostDetails'])) { ?>
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
379
			$(document).ready(function() {
380
				var win = $(window);
381
				var lastPostId = "<?php echo $lastPostId; ?>";
382
				var old_lastPostId = "";
383
				var morePostsAvailable = true;
384
				// Each time the user scrolls
385
				win.scroll(function() {
386
					// End of the document reached?
387
					if (($(document).height() - win.height() == win.scrollTop()) && morePostsAvailable) {
388
						$('#loading').show();
389
390
						
391
						
392
						$.ajax({
393
							url: 'get-posts-ajax.php?lastPostId=' + lastPostId,
394
							dataType: 'html',
395
							async: true,
396
							success: function(html) {
397
								var div = document.createElement('div');
398
								div.innerHTML = html;
399
								var elements = div.childNodes;
400
								old_lastPostId = lastPostId;
401
								lastPostId = elements[3].textContent;
402
								lastPostId = lastPostId.replace(/\s+/g, '');
403
								//alert('Neu: ' + lastPostId + " Alt: " + old_lastPostId);
404
								if(lastPostId == old_lastPostId) {
405
									
406
									//morePostsAvailable = false;
407
								}
408
								else {
409
									//alert(elements[3].textContent);
410
									$('#posts').append(elements[1].innerHTML);
411
								}
412
								$('#loading').hide();
413
							}
414
						});
415
					}
416
				});
417
			});	
418
		<?php } ?>
419
		</script>
420
421
	</body>
422
</html>
423
424