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