Completed
Push — master ( e39583...d1854b )
by mains
03:08
created

index.php (42 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
error_reporting(-1);
3
include 'php/jodel-web.php';
4
5
	$location = new Location();
6
	$location->setLat('52.5134288');
7
	$location->setLng('13.2746394');
8
	$location->setCityName('Berlin');
9
10
	$accessToken;
11
	$accessToken_forId1;
12
	$deviceUid;
13
14
	if(!isset($_COOKIE["JodelDeviceId"]))
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal JodelDeviceId 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...
15
	{
16
		$deviceUid = createAccount();
17
		setcookie('JodelDeviceId', $deviceUid, time()+60*60*24*365*10);
18
		error_log('Created account with JodelDeviceId:' . $deviceUid .  ' for ' . $_SERVER['REMOTE_ADDR']);
19
		
20
	}
21
	else
22
	{
23
		$deviceUid = $db->real_escape_string($_COOKIE["JodelDeviceId"]);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal JodelDeviceId 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...
24
	}
25
26
	$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...
27
	$newPositionStatus = $location->getCityName();
28
	$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...
29
	//Acc is fresh. token and location is set
30
31
	$accessToken_forId1 = isTokenFresh($location);
32
33
34
	//Set View
35 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...
36
	{
37
		switch ($_GET['view']) {
38
			case 'comment':
39
				$view = 'comment';
40
				break;
41
			
42
			case 'upVote':
43
				$view = 'upVote';
44
				break;
45
46
			default:
47
				$view = 'time';
48
				break;
49
		}
50
	}
51
	else
52
	{
53
		$view = 'time';
54
	}
55
	
56
	//Set Location
57
	if(isset($_GET['city'])) {
58
		$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...
59
		$result = Requests::post($url);
60
		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...
61
		{
62
			$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...
63
		}
64
		else
65
		{
66
			$name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name'];
67
			$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...
68
			$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...
69
70
			$location = new Location();
71
			$location->setLat($lat);
72
			$location->setLng($lng);
73
			$location->setCityName($name);
74
			$accountCreator = new UpdateLocation();
75
			$accountCreator->setLocation($location);
76
			$accountCreator->setAccessToken($accessToken);
77
			$data = $accountCreator->execute();
78
79
			//safe location to db
80
			if($data == "Success")
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Success 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...
81
			{
82
				$result = $db->query("UPDATE accounts 
83
						SET name='" . $name . "',
84
							lat='" . $lat . "',
85
							lng='" . $lng . "'
86
						WHERE access_token='" . $accessToken . "'");
87
88
				if($result === false)
89
				{
90
						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...
91
				}
92
				else
93
				{
94
					$newPositionStatus = $name;
95
				}
96
			}
97
		}
98
	}
99
	
100
	//Vote
101
	if(isset($_GET['vote']) && isset($_GET['postID'])) {
102 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...
103
			$accountCreator = new Upvote();
104
		}
105
		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...
106
			$accountCreator = new Downvote();
107
		}
108
		$accountCreator->setAccessToken($accessToken_forId1);
109
		$accountCreator->postId = $_GET['postID'];
110
		$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...
111
112
		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...
113
		die();
114
	}
115
	
116
	
117
	//SendJodel
118
	if(isset($_POST['message'])) {
119
		$accountCreator = new SendJodel();
120
121
		if(isset($_POST['ancestor']))
122
		{
123
			$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...
124
			$accountCreator->ancestor = $ancestor;
125
		}
126
		if(isset($_POST['color']))
127
		{
128
			$color = $_POST['color'];
129
			switch ($color) {
130
				case '8ABDB0':
131
					$color = '8ABDB0';
132
					break;
133
				case '9EC41C':
134
					$color = '9EC41C';
135
					break;
136
				case '06A3CB':
137
					$color = '06A3CB';
138
					break;
139
				case 'FFBA00':
140
					$color = 'FFBA00';
141
					break;
142
				case 'DD5F5F':
143
					$color = 'DD5F5F';
144
					break;
145
				case 'FF9908':
146
					$color = 'FF9908';
147
					break;
148
				
149
				default:
150
					$color = '8ABDB0';
151
					break;
152
			}
153
			$accountCreator->color = $color;
154
		}
155
		
156
		//$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...
157
158
		$accountCreatorLocation = new UpdateLocation();
159
		$accountCreatorLocation->setLocation($location);
160
		$accountCreatorLocation->setAccessToken($accessToken_forId1);
161
		$data = $accountCreatorLocation->execute();
162
		
163
		$accountCreator->location = $location;
164
		
165
		$accountCreator->setAccessToken($accessToken_forId1);
166
		$data = $accountCreator->execute();
167
168
		if(isset($_POST['ancestor']))
169
		{
170
			$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $_SERVER instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
171
			header('Location: ' . $actual_link . '#postId-' . htmlspecialchars($data['post_id']));
172
			exit;
173
		}
174
		else
175
		{
176
			header('Location: ./');
177
			exit;
178
		}
179
	}
180
?>
181
<!DOCTYPE html>
182
<html lang="en">
183
	<head>
184
		<title>JodelBlue - Web-App and Browser-Client</title>
185
		
186
		<meta charset="utf-8">
187
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
188
		<meta http-equiv="x-ua-compatible" content="ie=edge">
189
		
190
		<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...
191
		<meta name="keywords" content="jodelblue, jodel, blue, webclient, web, client, web-app, browser, app">
192
		
193
		<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...
194
		<link rel="stylesheet" href="css/font-awesome.min.css">
195
		<link rel="stylesheet" href="style.css" type="text/css">
196
		
197
		<link rel="shortcut icon" type="image/x-icon" href="./img/favicon/favicon.ico">
198
		<link rel="icon" type="image/x-icon" href="./img/favicon/favicon.ico">
199
		<link rel="icon" type="image/gif" href="./img/favicon/favicon.gif">
200
		<link rel="icon" type="image/png" href="./img/favicon/favicon.png">
201
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon.png">
202
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-57x57.png" sizes="57x57">
203
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-60x60.png" sizes="60x60">
204
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-72x72.png" sizes="72x72">
205
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-76x76.png" sizes="76x76">
206
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-114x114.png" sizes="114x114">
207
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-120x120.png" sizes="120x120">
208
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-128x128.png" sizes="128x128">
209
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-144x144.png" sizes="144x144">
210
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-152x152.png" sizes="152x152">
211
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-180x180.png" sizes="180x180">
212
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-precomposed.png">
213
		<link rel="icon" type="image/png" href="./img/favicon/favicon-16x16.png" sizes="16x16">
214
		<link rel="icon" type="image/png" href="./img/favicon/favicon-32x32.png" sizes="32x32">
215
		<link rel="icon" type="image/png" href="./img/favicon/favicon-96x96.png" sizes="96x96">
216
		<link rel="icon" type="image/png" href="./img/favicon/favicon-160x160.png" sizes="160x160">
217
		<link rel="icon" type="image/png" href="./img/favicon/favicon-192x192.png" sizes="192x192">
218
		<link rel="icon" type="image/png" href="./img/favicon/favicon-196x196.png" sizes="196x196">
219
		<meta name="msapplication-TileImage" content="./img/favicon/win8-tile-144x144.png"> 
220
		<meta name="msapplication-TileColor" content="#5682a3"> 
221
		<meta name="msapplication-navbutton-color" content="#5682a3"> 
222
		<meta name="application-name" content="JodelBlue"/> 
223
		<meta name="msapplication-tooltip" content="JodelBlue"/> 
224
		<meta name="apple-mobile-web-app-title" content="JodelBlue"/> 
225
		<meta name="msapplication-square70x70logo" content="./img/favicon/win8-tile-70x70.png"> 
226
		<meta name="msapplication-square144x144logo" content="./img/favicon/win8-tile-144x144.png"> 
227
		<meta name="msapplication-square150x150logo" content="./img/favicon/win8-tile-150x150.png"> 
228
		<meta name="msapplication-wide310x150logo" content="./img/favicon/win8-tile-310x150.png"> 
229
		<meta name="msapplication-square310x310logo" content="./img/favicon/win8-tile-310x310.png"> 
230
	</head>
231
	
232
	<body>
233
		<header>
234
			<nav class="navbar navbar-full navbar-dark navbar-fixed-top">
235
				<div class="container">					
236
						<?php
237
							if(isset($_GET['postID']) && isset($_GET['getPostDetails']))
238
							{
239
								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...
240
								echo '<i class="fa fa-angle-left fa-3x"></i>';
241
								echo '</a>';
242
								echo '<h1>';
243
								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...
244
							}
245
							else
246
							{
247
								echo '<h1>';	
248
								echo '<a href="./" class="spinnable">';
249
							}
250
						?>
251
						JodelBlue <i class="fa fa-refresh fa-1x"></i></a>
252
					</h1>					
253
				</div>
254
			</nav>
255
		</header>
256
		
257
		<div class="mainContent container">		
258
			<div class="content row">
259
				<article class="topContent col-sm-8">
260
261
					<content id="posts">
262
						<?php
263
							$posts;
264
265
							//Get Post Details
266
							if(isset($_GET['postID']) && isset($_GET['getPostDetails']))
267
							{
268
								$userHandleBuffer = [];
269
270
								$accountCreator = new GetPostDetails();
271
								$accountCreator->setAccessToken($accessToken);
272
								$data = $accountCreator->execute();
273
								
274
								$posts[0] = $data;
275
								if(array_key_exists('children', $data)) {
276
									foreach($data['children'] as $key => $child)
277
									{
278
										
279
										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...
280
										{
281
											$numberForUser = array_search($child['user_handle'], $userHandleBuffer);
282
											if($numberForUser === FALSE)
283
											{
284
												array_push($userHandleBuffer, $child['user_handle']);
285
												$data['children'][$key]['user_handle'] = count($userHandleBuffer);
286
											}
287
											else
288
											{
289
												$data['children'][$key]['user_handle'] = $numberForUser + 1;
290
											}
291
										}
292
293
										array_push($posts, $data['children'][$key]);
294
									}
295
									$loops = $data['child_count'] + 1;
296
								}
297
								else
298
								{
299
									$loops = 1;
300
								}
301
								$isDetailedView = TRUE;
302
							}
303
							//Get Posts
304
							else
305
							{
306
								$version = 'v2';
307
								if($view=='comment')
308
								{
309
									$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...
310
								}
311
								else
312
								{
313
									if($view=='upVote')
314
									{
315
										$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...
316
									}
317
									else
318
									{
319
										$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...
320
										$version = 'v3';
321
									}
322
								}
323
324
								if($version == 'v3')
325
								{
326
									$posts = getPosts($lastPostId, $accessToken, $url, $version)['recent'];
327
								}
328
								else
329
								{
330
									$posts = getPosts($lastPostId, $accessToken, $url, $version)['posts'];
331
								}
332
								$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...
333
								$isDetailedView = FALSE;
334
							}
335
							
336
337 View Code Duplication
							for($i = 0; $i<$loops; $i++)
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...
338
							{
339
								if(array_key_exists($i, $posts))
340
								{
341
									$lastPostId = $posts[$i]['post_id'];
342
343
									jodelToHtml($posts[$i], $view, $isDetailedView);
344
								}
345
							} ?>
346
347
					</content>
348
					
349
					<?php if(!isset($_GET['postID']) && !isset($_GET['getPostDetails'])) { ?>
350
						<p id="loading">
351
							Loading…
352
						</p>
353
					<?php } ?>
354
				</article>
355
			
356
				<aside class="topSidebar col-sm-4 sidebar-outer">
357
					<div class="fixed">
358
						<article>
359
							<div>
360
								<h2>Position</h2>
361
								<form method="get">
362
									<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...
363
364
									<input type="submit" value="Set Location" /> 
365
								</form>
366
							</div>
367
						</article>
368
369
						<article>
370
							<div>
371
								<h2>Karma</h2>
372
								<?php echo getKarma($accessToken_forId1); ?>
373
							</div>
374
						</article>
375
376
						<article>
377
							<div>
378
								<?php if(isset($_GET['postID']) && isset($_GET['getPostDetails'])) { ?>
379
								<h2>Comment on Jodel</h2>
380
								<form method="POST">				
381
										<input type="hidden" name="ancestor" value="<?php echo htmlspecialchars($_GET['postID']);?>" />
382
										<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...
383
									<br />
384
									<input type="submit" value="SEND" /> 
385
								</form>
386
									<?php } else { ?>
387
								<h2>New Jodel</h2>
388
								<form method="POST">
389
									<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...
390
									<br />
391
									<select id="postColorPicker" name="color">
392
										<option value="06A3CB">Blue</option>
393
										<option value="8ABDB0">Teal</option>
394
										<option value="9EC41C">Green</option>
395
										<option value="FFBA00">Yellow</option>
396
										<option value="DD5F5F">Red</option>
397
										<option value="FF9908">Orange</option>
398
									</select> 
399
									<br />
400
									<input type="submit" value="SEND" /> 
401
								</form>
402
								<?php } ?>
403
							</div>
404
						</article>
405
							
406
						<article>
407
							<div>
408
								<h2>Login</h2>
409
							</div>
410
						</article>
411
					</div>
412
				</aside>
413
			</div>
414
			<div id="sortJodelBy" class="row">
415
				<div class="col-sm-12">
416
					<div class="row">
417
						<div class="col-sm-3">
418
							<a href="index.php" <?php if($view=='time') echo 'class="active"';?>><i class="fa fa-clock-o fa-3x"></i></a>
419
						</div>
420
						<div class="col-sm-3">
421
							<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...
422
						</div>
423
						<div class="col-sm-3">
424
							<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...
425
						</div>
426
						<div class="col-sm-3">
427
							<nav>
428
								<a href="./about-us.html">about us</a>
429
							</nav>
430
						</div>
431
					</div>
432
				</div>	
433
			</div>
434
		</div>
435
		
436
		
437
		<!-- jQuery, Tether, Bootstrap JS and own-->
438
		<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...
439
    	<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...
440
    	<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...
441
    	<script src="js/jQueryEmoji.js"></script>
442
443
		<script>
444
			//BackButton
445
			function goBack()
446
			{
447
				window.history.back();
448
			}
449
450
			$(document).ready(function()
451
			{
452
453
454
				//Transform UTF-8 Emoji to img
455
				$('.jodel > content').Emoji();
456
457
				$('a').on('click', function(){
458
				    $('a').removeClass('selected');
459
				    $(this).addClass('selected');
460
				});
461
462
				function scrollToAnchor(aid){
463
				    var aTag = $("article[id='"+ aid +"']");
464
				    $('html,body').animate({scrollTop: aTag.offset().top-90},'slow');
465
				}
466
467
				<?php if(!isset($_GET['postID']) && !isset($_GET['getPostDetails'])) { ?>
468
469
				
470
471
472
473
				var win = $(window);
474
				var lastPostId = "<?php echo $lastPostId; ?>";
475
				var view = "<?php echo $view; ?>"
476
				var old_lastPostId = "";
477
				var morePostsAvailable = true;
478
479
				if(window.location.hash)
480
				{
481
					var hash = window.location.hash.slice(1);
482
483
					if(!$("article[id='"+ hash +"']").length)
484
					{
485
						for (var i = 5; i >= 0; i--)
486
						{
487
							if(!$("article[id='"+ hash +"']").length)
488
							{
489
								$.ajax({
490
									url: 'get-posts-ajax.php?lastPostId=' + lastPostId + '&view=' + view,
491
									dataType: 'html',
492
									async: false,
493
									success: function(html) {
494
										var div = document.createElement('div');
495
										div.innerHTML = html;
496
										var elements = div.childNodes;
497
										old_lastPostId = lastPostId;
498
										lastPostId = elements[3].textContent;
499
										lastPostId = lastPostId.replace(/\s+/g, '');
500
										//alert('Neu: ' + lastPostId + " Alt: " + old_lastPostId);
501
										if(lastPostId == old_lastPostId) {
502
											
503
											//morePostsAvailable = false;
504
										}
505
										else {
506
											//alert(elements[3].textContent);
507
											$('#posts').append(elements[1].innerHTML);
508
											$('#posts').hide().show(0);
509
										}
510
										$('#loading').hide();
511
									}
512
								});
513
514
								$('.jodel > content').Emoji();
515
							}
516
							
517
						}
518
						scrollToAnchor(hash);
519
520
					}						
521
				}
522
523
				// Each time the user scrolls
524
				win.scroll(function() {
525
526
527
					// End of the document reached?
528
					if (($(document).height() - win.height() == win.scrollTop()) && morePostsAvailable) {
529
						$('#loading').show();
530
531
						
532
						
533
						$.ajax({
534
							url: 'get-posts-ajax.php?lastPostId=' + lastPostId + '&view=' + view,
535
							dataType: 'html',
536
							async: false,
537
							success: function(html) {
538
								var div = document.createElement('div');
539
								div.innerHTML = html;
540
								var elements = div.childNodes;
541
								old_lastPostId = lastPostId;
542
								lastPostId = elements[3].textContent;
543
								lastPostId = lastPostId.replace(/\s+/g, '');
544
								//alert('Neu: ' + lastPostId + " Alt: " + old_lastPostId);
545
								if(lastPostId == old_lastPostId)
546
								{
547
									
548
									//morePostsAvailable = false;
549
								}
550
								else
551
								{
552
									//alert(elements[3].textContent);
553
									$('#posts').append(elements[1].innerHTML);
554
								}
555
								$('#loading').hide();
556
							}
557
						});
558
559
						$('.jodel > content').Emoji();
560
					}
561
				});
562
			<?php } ?>
563
			});	
564
565
		</script>
566
	</body>
567
</html>
568
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...
569