Completed
Push — master ( 9d2f24...fd7e65 )
by mains
12:03
created

index.php (41 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
4
include 'php/jodel-web.php';
5
6
	$config = parse_ini_file('config/config.ini.php');
7
8
9
	$location = new Location();
10
	$location->setLat($config['default_lat']);
11
	$location->setLng($config['default_lng']);
12
	$location->setCityName($config['default_location']);
13
14
	$accessToken;
15
	$accessToken_forId1;
16
	$deviceUid;
17
	$isSpider = FALSE;
18
19
	//What is dude doing with my Server?
20
	if($_SERVER['REMOTE_ADDR'] == '94.231.103.52')
21
	{
22
		echo('You are flooting my Server! Pls enable Cookies in your script and contact me: [email protected]');
23
		die();
24
	}
25
26
27
	//Check if it's a Spider or Google Bot
28
	if(botDeviceUidIsSet($config) && isUserBot())
29
	{
30
		$isSpider = TRUE;
31
		error_log('Spider or Bot checked in!');
32
		
33
		//Change this to a free device_uid listed in your DB
34
		$deviceUid = $config['botDeviceUid'];
35
		$config = NULL;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
36
	}
37
	else
38
	{
39
		$config = NULL;
40
		if(!isset($_COOKIE['JodelDeviceId']))
41
		{
42
			$deviceUid = createAccount();
43
			setcookie('JodelDeviceId', $deviceUid, time()+60*60*24*365*10);
44
			error_log('Created account with JodelDeviceId:' . $deviceUid .  ' for [' . $_SERVER ['HTTP_USER_AGENT'] . ']');
45
			
46
		}
47
		else
48
		{
49
			$deviceUid = $db->real_escape_string($_COOKIE['JodelDeviceId']);
50
		}
51
	}
52
53
	$location = getLocationByDeviceUid($deviceUid);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
54
	$newPositionStatus = $location->getCityName();
55
	$accessToken = isTokenFreshByDeviceUid($location, $deviceUid);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
56
	//Acc is fresh. token and location is set
57
58
	$accessToken_forId1 = isTokenFresh($location);
59
60
61
	//Set View
62 View Code Duplication
	if(isset($_GET['view']))
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...
63
	{
64
		switch ($_GET['view']) {
65
			case 'comment':
66
				$view = 'comment';
67
				break;
68
			
69
			case 'upVote':
70
				$view = 'upVote';
71
				break;
72
73
			default:
74
				$view = 'time';
75
				break;
76
		}
77
	}
78
	else
79
	{
80
		$view = 'time';
81
	}
82
	
83
	//Set Location
84
	if(isset($_GET['city'])) {
85
		$url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($_GET['city']) . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w';
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
This line exceeds maximum limit of 120 characters; contains 153 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...
86
		$result = Requests::post($url);
87
		if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST')
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 133 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...
88
		{
89
			$newPositionStatus = "0 results";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 0 results 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...
90
		}
91
		else
92
		{
93
			$name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name'];
94
			$lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat'];
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
95
			$lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng'];
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
96
97
			$location = new Location();
98
			$location->setLat($lat);
99
			$location->setLng($lng);
100
			$location->setCityName($name);
101
			$accountCreator = new UpdateLocation();
102
			$accountCreator->setLocation($location);
103
			$accountCreator->setAccessToken($accessToken);
104
			$data = $accountCreator->execute();
105
106
			//safe location to db
107
			if($data == 'Success')
108
			{
109
				$result = $db->query("UPDATE accounts 
110
						SET name='" . $name . "',
111
							lat='" . $lat . "',
112
							lng='" . $lng . "'
113
						WHERE access_token='" . $accessToken . "'");
114
115
				if($result === false)
116
				{
117
						echo "Updating location failed: (" . $db->errno . ") " . $db->error;
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Updating location failed: ( 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...
Coding Style Comprehensibility introduced by
The string literal ) 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...
118
				}
119
				else
120
				{
121
					$newPositionStatus = $name;
122
					error_log('User with JodelDeviceId:' . $deviceUid .  ' [' . $_SERVER['REMOTE_ADDR'] . '][' . $_SERVER ['HTTP_USER_AGENT'] . '] changed to Location: ' . $name);
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 164 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...
123
				}
124
			}
125
		}
126
	}
127
	
128
	//Vote
129
	if(isset($_GET['vote']) && isset($_GET['postID']))
130
	{
131 View Code Duplication
		if($_GET['vote'] == "up")
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...
Coding Style Comprehensibility introduced by
The string literal up 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...
132
		{
133
			$accountCreator = new Upvote();
134
		}
135
		else if($_GET['vote'] == "down")
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal down 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...
136
		{
137
			$accountCreator = new Downvote();
138
		}
139
		$accountCreator->setAccessToken($accessToken_forId1);
140
		$accountCreator->postId = $_GET['postID'];
141
		$data = $accountCreator->execute();
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 19 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
142
143
		if(isset($_GET['getPostDetails']) && $_GET['getPostDetails'])
144
		{
145
			header('Location: index.php?getPostDetails=true&postID=' . htmlspecialchars($_GET['postID_parent']) . '#postId-' . htmlspecialchars($_GET['postID']));
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 153 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...
146
		}
147
		else
148
		{
149
			header("Location: index.php#postId-" . htmlspecialchars($_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...
150
		}	
151
		die();
152
	}
153
	
154
	
155
	//SendJodel
156
	if(isset($_POST['message']))
157
	{
158
		$accountCreator = new SendJodel();
159
160
		if(isset($_POST['ancestor']))
161
		{
162
			$ancestor = $_POST['ancestor'];
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 17 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
163
			$accountCreator->ancestor = $ancestor;
164
		}
165
		if(isset($_POST['color']))
166
		{
167
			$color = $_POST['color'];
168
			switch ($color) {
169
				case '8ABDB0':
170
					$color = '8ABDB0';
171
					break;
172
				case '9EC41C':
173
					$color = '9EC41C';
174
					break;
175
				case '06A3CB':
176
					$color = '06A3CB';
177
					break;
178
				case 'FFBA00':
179
					$color = 'FFBA00';
180
					break;
181
				case 'DD5F5F':
182
					$color = 'DD5F5F';
183
					break;
184
				case 'FF9908':
185
					$color = 'FF9908';
186
					break;
187
				
188
				default:
189
					$color = '8ABDB0';
190
					break;
191
			}
192
			$accountCreator->color = $color;
193
		}
194
		
195
		//$location = getLocationByAccessToken($accessToken);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
196
197
		$accountCreatorLocation = new UpdateLocation();
198
		$accountCreatorLocation->setLocation($location);
199
		$accountCreatorLocation->setAccessToken($accessToken_forId1);
200
		$data = $accountCreatorLocation->execute();
201
		
202
		$accountCreator->location = $location;
203
		
204
		$accountCreator->setAccessToken($accessToken_forId1);
205
		$data = $accountCreator->execute();
206
207
		if(isset($_POST['ancestor']))
208
		{
209
			$actual_link = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
210
			header('Location: ' . $actual_link . '#postId-' . htmlspecialchars($data['post_id']));
211
			exit;
212
		}
213
		else
214
		{
215
			header('Location: ./');
216
			exit;
217
		}
218
	}
219
?>
220
<!DOCTYPE html>
221
<html lang="en">
222
	<head>
223
		<title>JodelBlue - Web-App and Browser-Client</title>
224
		
225
		<meta charset="utf-8">
226
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
227
		<meta http-equiv="x-ua-compatible" content="ie=edge">
228
		
229
		<meta name="description" content="JodelBlue is a Web-App and Browser-Client 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 197 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...
230
		<meta name="keywords" content="jodelblue, jodel, blue, webclient, web, client, web-app, browser, app">
231
		
232
		<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">
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 218 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...
233
		<link rel="stylesheet" href="css/font-awesome.min.css">
234
		<link rel="stylesheet" href="style.css" type="text/css">
235
		
236
		<link rel="shortcut icon" type="image/x-icon" href="./img/favicon/favicon.ico">
237
		<link rel="icon" type="image/x-icon" href="./img/favicon/favicon.ico">
238
		<link rel="icon" type="image/gif" href="./img/favicon/favicon.gif">
239
		<link rel="icon" type="image/png" href="./img/favicon/favicon.png">
240
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon.png">
241
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-57x57.png" sizes="57x57">
242
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-60x60.png" sizes="60x60">
243
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-72x72.png" sizes="72x72">
244
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-76x76.png" sizes="76x76">
245
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-114x114.png" sizes="114x114">
246
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-120x120.png" sizes="120x120">
247
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-128x128.png" sizes="128x128">
248
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-144x144.png" sizes="144x144">
249
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-152x152.png" sizes="152x152">
250
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-180x180.png" sizes="180x180">
251
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-precomposed.png">
252
		<link rel="icon" type="image/png" href="./img/favicon/favicon-16x16.png" sizes="16x16">
253
		<link rel="icon" type="image/png" href="./img/favicon/favicon-32x32.png" sizes="32x32">
254
		<link rel="icon" type="image/png" href="./img/favicon/favicon-96x96.png" sizes="96x96">
255
		<link rel="icon" type="image/png" href="./img/favicon/favicon-160x160.png" sizes="160x160">
256
		<link rel="icon" type="image/png" href="./img/favicon/favicon-192x192.png" sizes="192x192">
257
		<link rel="icon" type="image/png" href="./img/favicon/favicon-196x196.png" sizes="196x196">
258
		<meta name="msapplication-TileImage" content="./img/favicon/win8-tile-144x144.png"> 
259
		<meta name="msapplication-TileColor" content="#5682a3"> 
260
		<meta name="msapplication-navbutton-color" content="#5682a3"> 
261
		<meta name="application-name" content="JodelBlue"/> 
262
		<meta name="msapplication-tooltip" content="JodelBlue"/> 
263
		<meta name="apple-mobile-web-app-title" content="JodelBlue"/> 
264
		<meta name="msapplication-square70x70logo" content="./img/favicon/win8-tile-70x70.png"> 
265
		<meta name="msapplication-square144x144logo" content="./img/favicon/win8-tile-144x144.png"> 
266
		<meta name="msapplication-square150x150logo" content="./img/favicon/win8-tile-150x150.png"> 
267
		<meta name="msapplication-wide310x150logo" content="./img/favicon/win8-tile-310x150.png"> 
268
		<meta name="msapplication-square310x310logo" content="./img/favicon/win8-tile-310x310.png"> 
269
	</head>
270
	
271
	<body>
272
		<header>
273
			<nav class="navbar navbar-full navbar-dark navbar-fixed-top">
274
				<div class="container">					
275
						<?php
276
							if(isset($_GET['postID']) && isset($_GET['getPostDetails']))
277
							{
278
								echo '<a id="comment-back" href="index.php?view=' . $view . '#postId-' . htmlspecialchars($_GET['postID']) . '">';
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 122 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...
279
								echo '<i class="fa fa-angle-left fa-3x"></i>';
280
								echo '</a>';
281
								echo '<h1>';
282
								echo '<a href="index.php?getPostDetails=' . htmlspecialchars($_GET['getPostDetails']) . '&postID=' . htmlspecialchars($_GET['postID']) . '" class="spinnable">';
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 168 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...
283
							}
284
							else
285
							{
286
								echo '<h1>';	
287
								echo '<a href="./" class="spinnable">';
288
							}
289
						?>
290
						JodelBlue <i class="fa fa-refresh fa-1x"></i></a>
291
					</h1>
292
293
					<div id="location_mobile" class="hidden-sm-up">
294
						<form method="get">
295
							<input type="text" id="city_mobile" name="city" placeholder="<?php if(isset($newPositionStatus)) echo $newPositionStatus; ?>" required>
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 142 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...
296
297
							<input type="submit" id="submit_mobile" class="fa" value="&#xf0ac;" />
298
						</form>
299
					</div>
300
				</div>
301
			</nav>
302
		</header>
303
		
304
		<div class="mainContent container">		
305
			<div class="content row">
306
				<article class="topContent col-sm-8">
307
308
					<content id="posts">
309
						<?php
310
							$posts;
311
312
							//Get Post Details
313
							if(isset($_GET['postID']) && isset($_GET['getPostDetails']))
314
							{
315
								$userHandleBuffer = [];
316
317
								$accountCreator = new GetPostDetails();
318
								$accountCreator->setAccessToken($accessToken);
319
								$data = $accountCreator->execute();
320
								
321
								$posts[0] = $data;
322
								if(array_key_exists('children', $data)) {
323
									foreach($data['children'] as $key => $child)
324
									{
325
										
326
										if(!$child["parent_creator"] == 1)
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal parent_creator 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...
327
										{
328
											$numberForUser = array_search($child['user_handle'], $userHandleBuffer);
329
											if($numberForUser === FALSE)
330
											{
331
												array_push($userHandleBuffer, $child['user_handle']);
332
												$data['children'][$key]['user_handle'] = count($userHandleBuffer);
333
											}
334
											else
335
											{
336
												$data['children'][$key]['user_handle'] = $numberForUser + 1;
337
											}
338
										}
339
340
										array_push($posts, $data['children'][$key]);
341
									}
342
									$loops = $data['child_count'] + 1;
343
								}
344
								else
345
								{
346
									$loops = 1;
347
								}
348
								$isDetailedView = TRUE;
349
							}
350
							//Get Posts
351
							else
352
							{
353
								$version = 'v2';
354
								if($view=='comment')
355
								{
356
									$url = "/v2/posts/location/discussed/";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal /v2/posts/location/discussed/ 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...
357
								}
358
								else
359
								{
360
									if($view=='upVote')
361
									{
362
										$url = "/v2/posts/location/popular/";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal /v2/posts/location/popular/ 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...
363
									}
364
									else
365
									{
366
										$url = "/v3/posts/location/combo/";
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
Coding Style Comprehensibility introduced by
The string literal /v3/posts/location/combo/ 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...
367
										$version = 'v3';
368
									}
369
								}
370
371
								if($version == 'v3')
372
								{
373
									$posts = getPosts($lastPostId, $accessToken, $url, $version)['recent'];
374
								}
375
								else
376
								{
377
									$posts = getPosts($lastPostId, $accessToken, $url, $version)['posts'];
378
								}
379
								$loops = 29;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
380
								$isDetailedView = FALSE;
381
							}
382
							
383
384
							for($i = 0; $i<$loops; $i++)
385
							{
386
								if(array_key_exists($i, $posts) && array_key_exists('post_id', $posts[$i]) && isset($posts[$i]['post_id']))
387
								{
388
									$lastPostId = $posts[$i]['post_id'];
389
390
									jodelToHtml($posts[$i], $view, $isDetailedView);
391
								}
392
							} ?>
393
394
					</content>
395
					
396
					<?php if(!isset($_GET['postID']) && !isset($_GET['getPostDetails'])) { ?>
397
						<p id="loading">
398
							Loading…
399
						</p>
400
					<?php } ?>
401
				</article>
402
			
403
				<aside class="topSidebar col-sm-4 sidebar-outer">
404
					<div class="fixed">
405
						<article>
406
							<div>
407
								<h2>Position</h2>
408
								<form method="get">
409
									<input type="text" id="city" name="city" placeholder="<?php if(isset($newPositionStatus)) echo $newPositionStatus; ?>" required>
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 137 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...
410
411
									<input type="submit" value="Set Location" /> 
412
								</form>
413
							</div>
414
						</article>
415
416
						<article>
417
							<div>
418
								<h2>Karma</h2>
419
								<?php echo getKarma($accessToken_forId1); ?>
420
							</div>
421
						</article>
422
423
						<article>
424
							<div>
425
								<?php if(isset($_GET['postID']) && isset($_GET['getPostDetails'])) { ?>
426
								<h2>Comment on Jodel</h2>
427
								<form method="POST">				
428
										<input type="hidden" name="ancestor" value="<?php echo htmlspecialchars($_GET['postID']);?>" />
429
										<textarea id="message" name="message" placeholder="Send a comment on a Jodel to all students within 10km" required></textarea> 
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 137 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...
430
									<br />
431
									<input type="submit" value="SEND" /> 
432
								</form>
433
									<?php } else { ?>
434
								<h2>New Jodel</h2>
435
								<form method="POST">
436
									<textarea id="message" name="message" placeholder="Send a Jodel to all students within 10km" required></textarea> 
0 ignored issues
show
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...
437
									<br />
438
									<select id="postColorPicker" name="color">
439
										<option value="06A3CB">Blue</option>
440
										<option value="8ABDB0">Teal</option>
441
										<option value="9EC41C">Green</option>
442
										<option value="FFBA00">Yellow</option>
443
										<option value="DD5F5F">Red</option>
444
										<option value="FF9908">Orange</option>
445
									</select> 
446
									<br />
447
									<input type="submit" value="SEND" /> 
448
								</form>
449
								<?php } ?>
450
							</div>
451
						</article>
452
							
453
						<article>
454
							<div>
455
								<h2>Login</h2>
456
							</div>
457
						</article>
458
					</div>
459
				</aside>
460
			</div>
461
			<div id="sortJodelBy" class="row">
462
				<div class="col-xs-12">
463
					<div class="row">
464
						<div class="col-xs-3">
465
							<a href="index.php" <?php if($view=='time') echo 'class="active"';?>><i class="fa fa-clock-o fa-3x"></i></a>
466
						</div>
467
						<div class="col-xs-3">
468
							<a href="index.php?view=comment" <?php if($view=='comment') echo 'class="active"';?>><i class="fa fa-commenting-o fa-3x"></i></a>
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 136 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...
469
						</div>
470
						<div class="col-xs-3">
471
							<a href="index.php?view=upVote" <?php if($view=='upVote') echo 'class="active"';?>><i class="fa fa-angle-up fa-3x"></i></a>
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 130 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...
472
						</div>
473
						<div class="col-xs-3">
474
							<nav>
475
								<a href="./about-us.html">about us</a>
476
							</nav>
477
						</div>
478
					</div>
479
				</div>	
480
			</div>
481
		</div>
482
		
483
		
484
		<!-- jQuery, Tether, Bootstrap JS and own-->
485
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha384-3ceskX3iaEnIogmQchP8opvBy3Mi7Ce34nWjpBIwVTHfGYWQS9jwHDVRnpKKHJg7" crossorigin="anonymous"></script>
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 198 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...
486
    	<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.3.7/js/tether.min.js" integrity="sha384-XTs3FgkjiBgo8qjEjBk0tGmf3wPrWtA6coPfQDfFEY8AnYJwjalXCiosYRBIBZX8" crossorigin="anonymous"></script>
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 205 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...
487
    	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/js/bootstrap.min.js" integrity="sha384-BLiI7JTZm+JWlgKa0M0kGRpJbF2J8q+qreVrKBC47e3K6BW78kGLrCkeRX6I9RoK" crossorigin="anonymous"></script>
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 212 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...
488
    	<script src="js/jQueryEmoji.js"></script>
489
490
		<script>
491
			//BackButton
492
			function goBack()
493
			{
494
				window.history.back();
495
			}
496
497
			$(document).ready(function()
498
			{
499
500
501
				//Transform UTF-8 Emoji to img
502
				$('.jodel > content').Emoji();
503
504
				$('a').on('click', function(){
505
				    $('a').removeClass('selected');
506
				    $(this).addClass('selected');
507
				});
508
509
				function scrollToAnchor(aid){
510
				    var aTag = $("article[id='"+ aid +"']");
511
				    $('html,body').animate({scrollTop: aTag.offset().top-90},'slow');
512
				}
513
514
				<?php if(!isset($_GET['postID']) && !isset($_GET['getPostDetails'])) { ?>
515
516
				
517
518
519
520
				var win = $(window);
521
				var lastPostId = "<?php echo $lastPostId; ?>";
522
				var view = "<?php echo $view; ?>"
523
				var old_lastPostId = "";
524
				var morePostsAvailable = true;
525
526
				if(window.location.hash)
527
				{
528
					var hash = window.location.hash.slice(1);
529
530
					if(!$("article[id='"+ hash +"']").length)
531
					{
532
						for (var i = 5; i >= 0; i--)
533
						{
534
							if(!$("article[id='"+ hash +"']").length)
535
							{
536
								$.ajax({
537
									url: 'get-posts-ajax.php?lastPostId=' + lastPostId + '&view=' + view,
538
									dataType: 'html',
539
									async: false,
540
									success: function(html) {
541
										var div = document.createElement('div');
542
										div.innerHTML = html;
543
										var elements = div.childNodes;
544
										old_lastPostId = lastPostId;
545
										lastPostId = elements[3].textContent;
546
										lastPostId = lastPostId.replace(/\s+/g, '');
547
										//alert('Neu: ' + lastPostId + " Alt: " + old_lastPostId);
548
										if(lastPostId == old_lastPostId) {
549
											
550
											//morePostsAvailable = false;
551
										}
552
										else {
553
											//alert(elements[3].textContent);
554
											$('#posts').append(elements[1].innerHTML);
555
											$('#posts').hide().show(0);
556
										}
557
										$('#loading').hide();
558
									}
559
								});
560
561
								$('.jodel > content').Emoji();
562
							}
563
							
564
						}
565
						scrollToAnchor(hash);
566
567
					}						
568
				}
569
570
				// Each time the user scrolls
571
				win.scroll(function() {
572
573
574
					// End of the document reached?
575
					if ($(window).scrollTop() + $(window).height() > $(document).height() - 100 && morePostsAvailable)
576
					{
577
						$('#loading').show();
578
579
						$.ajax({
580
							url: 'get-posts-ajax.php?lastPostId=' + lastPostId + '&view=' + view,
581
							dataType: 'html',
582
							async: false,
583
							success: function(html) {
584
								var div = document.createElement('div');
585
								div.innerHTML = html;
586
								var elements = div.childNodes;
587
								old_lastPostId = lastPostId;
588
								lastPostId = elements[3].textContent;
589
								lastPostId = lastPostId.replace(/\s+/g, '');
590
								//alert('Neu: ' + lastPostId + " Alt: " + old_lastPostId);
591
								if(lastPostId == old_lastPostId)
592
								{
593
									
594
									//morePostsAvailable = false;
595
								}
596
								else
597
								{
598
									//alert(elements[3].textContent);
599
									$('#posts').append(elements[1].innerHTML);
600
								}
601
								$('#loading').hide();
602
							}
603
						});
604
605
						$('.jodel > content').Emoji();
606
					}
607
				});
608
			<?php } ?>
609
			});	
610
611
		</script>
612
	</body>
613
</html>
614
0 ignored issues
show
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
615