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