Completed
Push — master ( a546a7...10dc14 )
by mains
02:38
created

admin.php (21 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
11
12
if(isset($_POST['createAccount']) && $_POST['createAccount'])
13
{
14
	createAccount();
15
}
16
17
18
//Vote
19
if(isset($_POST['vote']) && isset($_POST['postId']) && isset($_POST['quantity']))
20
{
21
	$i = 0;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 6 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...
22
	$result = $db->query("SELECT access_token FROM accounts");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal SELECT access_token FROM accounts 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...
23
24
	if ($result->num_rows > 0)
25
	{
26
		// output data of each row
27
		while(($row = $result->fetch_assoc()) && $i < $_POST['quantity'])
28
		{
29
			$accessToken = $row['access_token'];
30
			var_dump($accessToken);
31
			isTokenFreshByAccessToken($location, $accessToken);
32
33 View Code Duplication
			if($_POST['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...
34
				$accountCreator = new Upvote();
35
			}
36
			else if($_POST['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...
37
				$accountCreator = new Downvote();
38
			}
39
40
			$accountCreator->setAccessToken($accessToken);
41
			$accountCreator->postId = $_POST['postId'];
42
			$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...
43
			$i++;
44
		}
45
	}
46
	else
47
	{
48
		echo "Error: 0 results";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Error: 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...
49
	}
50
}
51
52
53
?>
54
<!DOCTYPE html>
55
<html lang="en">
56
	<head>
57
		<title>Backend - JodelBlue WebClient</title>
58
		
59
		<meta charset="utf8">
60
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
61
		<meta http-equiv="x-ua-compatible" content="ie=edge">
62
		
63
		<meta name="description" content="JodelBlue is a WebClient 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 180 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...
64
		<meta name="keywords" content="jodelblue, jodel, blue, webclient, web, client">
65
		
66
		<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...
67
		<link rel="stylesheet" href="css/font-awesome.min.css">
68
		<link rel="stylesheet" href="style.css" type="text/css">
69
		
70
		<link rel="shortcut icon" type="image/x-icon" href="./img/favicon/favicon.ico">
71
		<link rel="icon" type="image/x-icon" href="./img/favicon/favicon.ico">
72
		<link rel="icon" type="image/gif" href="./img/favicon/favicon.gif">
73
		<link rel="icon" type="image/png" href="./img/favicon/favicon.png">
74
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon.png">
75
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-57x57.png" sizes="57x57">
76
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-60x60.png" sizes="60x60">
77
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-72x72.png" sizes="72x72">
78
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-76x76.png" sizes="76x76">
79
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-114x114.png" sizes="114x114">
80
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-120x120.png" sizes="120x120">
81
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-128x128.png" sizes="128x128">
82
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-144x144.png" sizes="144x144">
83
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-152x152.png" sizes="152x152">
84
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-180x180.png" sizes="180x180">
85
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-precomposed.png">
86
		<link rel="icon" type="image/png" href="./img/favicon/favicon-16x16.png" sizes="16x16">
87
		<link rel="icon" type="image/png" href="./img/favicon/favicon-32x32.png" sizes="32x32">
88
		<link rel="icon" type="image/png" href="./img/favicon/favicon-96x96.png" sizes="96x96">
89
		<link rel="icon" type="image/png" href="./img/favicon/favicon-160x160.png" sizes="160x160">
90
		<link rel="icon" type="image/png" href="./img/favicon/favicon-192x192.png" sizes="192x192">
91
		<link rel="icon" type="image/png" href="./img/favicon/favicon-196x196.png" sizes="196x196">
92
		<meta name="msapplication-TileImage" content="./img/favicon/win8-tile-144x144.png"> 
93
		<meta name="msapplication-TileColor" content="#5682a3"> 
94
		<meta name="msapplication-navbutton-color" content="#5682a3"> 
95
		<meta name="application-name" content="JodelBlue"/> 
96
		<meta name="msapplication-tooltip" content="JodelBlue"/> 
97
		<meta name="apple-mobile-web-app-title" content="JodelBlue"/> 
98
		<meta name="msapplication-square70x70logo" content="./img/favicon/win8-tile-70x70.png"> 
99
		<meta name="msapplication-square144x144logo" content="./img/favicon/win8-tile-144x144.png"> 
100
		<meta name="msapplication-square150x150logo" content="./img/favicon/win8-tile-150x150.png"> 
101
		<meta name="msapplication-wide310x150logo" content="./img/favicon/win8-tile-310x150.png"> 
102
		<meta name="msapplication-square310x310logo" content="./img/favicon/win8-tile-310x310.png"> 
103
	</head>
104
	
105
	<body>
106
		<header>
107
			<nav class="navbar navbar-full navbar-dark navbar-fixed-top">
108
				<div class="container">					
109
						<?php
110 View Code Duplication
							if(isset($_GET['postID']) && isset($_GET['getPostDetails']))
0 ignored issues
show
This code seems to be duplicated across your project.

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

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

Loading history...
111
							{
112
								echo '<a id="comment-back" onclick="goBack()" href="index.php?view=' . $view . '#postId-' . htmlspecialchars($_GET['postID']) . '">';
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 141 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...
113
								echo '<i class="fa fa-angle-left fa-3x"></i>';
114
								echo '</a>';
115
								echo '<h1>';
116
								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...
117
							}
118
							else
119
							{
120
								echo '<h1>';	
121
								echo '<a href="./" class="spinnable">';
122
							}
123
						?>
124
						JodelBlue <i class="fa fa-refresh fa-1x"></i></a>
125
					</h1>					
126
				</div>
127
			</nav>
128
		</header>
129
		
130
		<div class="mainContent container">		
131
			<div class="content row">
132
				<article class="topContent col-sm-8">
133
134
					<content id="posts">
135
						<form method="post">
136
							<button type="submit" name="createAccount" value="TRUE">Create new Account</button>
137
						</form>
138
139
						<form method="post">
140
							quantity<input type="number" name="quantity">
141
							postId<input type="text" name="postId">
142
							<button type="submit" name="vote" value="up">Upvote</button>
143
							<button type="submit" name="vote" value="down">Downvote</button>
144
						</form>
145
					</content>
146
				</article>
147
			
148
				<aside class="topSidebar col-sm-4 sidebar-outer">
149
					<div class="fixed">
150
						<article>
151
							<div>
152
								<h2>Position</h2>
153
								<form method="get">
154
									<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...
155
156
									<input type="submit" value="Set Location" /> 
157
								</form>
158
							</div>
159
						</article>
160
161
						<article>
162
							<div>
163
								<h2>Karma</h2>
164
								<?php //echo getKarma($accessToken); ?>
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
165
							</div>
166
						</article>
167
168
						<article>
169
							<div>
170 View Code Duplication
								<?php if(isset($_GET['postID']) && isset($_GET['getPostDetails'])) { ?>
0 ignored issues
show
This code seems to be duplicated across your project.

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

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

Loading history...
171
								<h2>Comment on Jodel</h2>
172
								<form method="POST">				
173
										<input type="hidden" name="ancestor" value="<?php echo htmlspecialchars($_GET['postID']);?>" />
174
										<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...
175
									<br />
176
									<input type="submit" value="SEND" /> 
177
								</form>
178
									<?php } else { ?>
179
								<h2>New Jodel</h2>
180
								<form method="POST">
181
									<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...
182
									<br />
183
									<select id="postColorPicker" name="color">
184
										<option value="06A3CB">Blue</option>
185
										<option value="8ABDB0">Teal</option>
186
										<option value="9EC41C">Green</option>
187
										<option value="FFBA00">Yellow</option>
188
										<option value="DD5F5F">Red</option>
189
										<option value="FF9908">Orange</option>
190
									</select> 
191
									<br />
192
									<input type="submit" value="SEND" /> 
193
								</form>
194
								<?php } ?>
195
							</div>
196
						</article>
197
							
198
						<article>
199
							<div>
200
								<h2>Login</h2>
201
							</div>
202
						</article>
203
					</div>
204
				</aside>
205
			</div>
206
			<div id="sortJodelBy" class="row">
207
				<div class="col-sm-12">
208
					<div class="row">
209
						
210
					</div>
211
				</div>	
212
			</div>
213
		</div>
214
		
215
		
216
		<!-- jQuery, Tether, Bootstrap JS and own-->
217
		<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...
218
    	<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...
219
    	<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...
220
    	<script src="js/jQueryEmoji.js"></script>
221
222
		<script>
223
			//BackButton
224
			function goBack()
225
			{
226
				window.history.back();
227
			}
228
229
			$(document).ready(function()
230
			{
231
232
233
				//Transform UTF-8 Emoji to img
234
				$('.jodel > content').Emoji();
235
236
				$('a').on('click', function(){
237
				    $('a').removeClass('selected');
238
				    $(this).addClass('selected');
239
				});
240
241
				function scrollToAnchor(aid){
242
				    var aTag = $("article[id='"+ aid +"']");
243
				    $('html,body').animate({scrollTop: aTag.offset().top-90},'slow');
244
				}
245
246 View Code Duplication
				<?php if(!isset($_GET['postID']) && !isset($_GET['getPostDetails'])) { ?>
0 ignored issues
show
This code seems to be duplicated across your project.

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

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

Loading history...
247
248
				
249
250
251
252
				var win = $(window);
253
				var lastPostId = "<?php echo $lastPostId; ?>";
254
				var view = "<?php echo $view; ?>"
255
				var old_lastPostId = "";
256
				var morePostsAvailable = true;
257
258
				if(window.location.hash)
259
				{
260
					var hash = window.location.hash.slice(1);
261
262
					if(!$("article[id='"+ hash +"']").length)
263
					{
264
						for (var i = 5; i >= 0; i--)
265
						{
266
							if(!$("article[id='"+ hash +"']").length)
267
							{
268
								$.ajax({
269
									url: 'get-posts-ajax.php?lastPostId=' + lastPostId + '&view=' + view,
270
									dataType: 'html',
271
									async: false,
272
									success: function(html) {
273
										var div = document.createElement('div');
274
										div.innerHTML = html;
275
										var elements = div.childNodes;
276
										old_lastPostId = lastPostId;
277
										lastPostId = elements[3].textContent;
278
										lastPostId = lastPostId.replace(/\s+/g, '');
279
										//alert('Neu: ' + lastPostId + " Alt: " + old_lastPostId);
280
										if(lastPostId == old_lastPostId) {
281
											
282
											//morePostsAvailable = false;
283
										}
284
										else {
285
											//alert(elements[3].textContent);
286
											$('#posts').append(elements[1].innerHTML);
287
											$('#posts').hide().show(0);
288
										}
289
										$('#loading').hide();
290
									}
291
								});
292
293
								$('.jodel > content').Emoji();
294
							}
295
							
296
						}
297
						scrollToAnchor(hash);
298
299
					}						
300
				}
301
302
				// Each time the user scrolls
303
				win.scroll(function() {
304
305
306
					// End of the document reached?
307
					if (($(document).height() - win.height() == win.scrollTop()) && morePostsAvailable) {
308
						$('#loading').show();
309
310
						
311
						
312
						$.ajax({
313
							url: 'get-posts-ajax.php?lastPostId=' + lastPostId + '&view=' + view,
314
							dataType: 'html',
315
							async: false,
316
							success: function(html) {
317
								var div = document.createElement('div');
318
								div.innerHTML = html;
319
								var elements = div.childNodes;
320
								old_lastPostId = lastPostId;
321
								lastPostId = elements[3].textContent;
322
								lastPostId = lastPostId.replace(/\s+/g, '');
323
								//alert('Neu: ' + lastPostId + " Alt: " + old_lastPostId);
324
								if(lastPostId == old_lastPostId)
325
								{
326
									
327
									//morePostsAvailable = false;
328
								}
329
								else
330
								{
331
									//alert(elements[3].textContent);
332
									$('#posts').append(elements[1].innerHTML);
333
								}
334
								$('#loading').hide();
335
							}
336
						});
337
338
						$('.jodel > content').Emoji();
339
					}
340
				});
341
			<?php } ?>
342
			});	
343
344
		</script>
345
	</body>
346
</html>