Completed
Push — master ( 5edd0c...906cba )
by mains
03:02
created

admin.php (9 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;
22
	$result = $db->query("SELECT access_token FROM accounts");
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
			
31
			$location = getLocationByAccessToken($accessToken);
32
33
			isTokenFreshByAccessToken($location, $accessToken);
34
35 View Code Duplication
			if($_POST['vote'] == "up") {
36
				$accountCreator = new Upvote();
37
			}
38
			else if($_POST['vote'] == "down") {
39
				$accountCreator = new Downvote();
40
			}
41
42
			$accountCreator->setAccessToken($accessToken);
43
			$accountCreator->postId = $_POST['postId'];
44
			$data = $accountCreator->execute();
45
			$i++;
46
		}
47
	}
48
	else
49
	{
50
		echo "Error: 0 results";
51
	}
52
}
53
54
55
?>
56
<!DOCTYPE html>
57
<html lang="en">
58
	<head>
59
		<title>Backend - JodelBlue WebClient</title>
60
		
61
		<meta charset="utf8">
62
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
63
		<meta http-equiv="x-ua-compatible" content="ie=edge">
64
		
65
		<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.">
66
		<meta name="keywords" content="jodelblue, jodel, blue, webclient, web, client">
67
		
68
		<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">
69
		<link rel="stylesheet" href="css/font-awesome.min.css">
70
		<link rel="stylesheet" href="style.css" type="text/css">
71
		
72
		<link rel="shortcut icon" type="image/x-icon" href="./img/favicon/favicon.ico">
73
		<link rel="icon" type="image/x-icon" href="./img/favicon/favicon.ico">
74
		<link rel="icon" type="image/gif" href="./img/favicon/favicon.gif">
75
		<link rel="icon" type="image/png" href="./img/favicon/favicon.png">
76
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon.png">
77
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-57x57.png" sizes="57x57">
78
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-60x60.png" sizes="60x60">
79
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-72x72.png" sizes="72x72">
80
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-76x76.png" sizes="76x76">
81
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-114x114.png" sizes="114x114">
82
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-120x120.png" sizes="120x120">
83
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-128x128.png" sizes="128x128">
84
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-144x144.png" sizes="144x144">
85
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-152x152.png" sizes="152x152">
86
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-180x180.png" sizes="180x180">
87
		<link rel="apple-touch-icon" href="./img/favicon/apple-touch-icon-precomposed.png">
88
		<link rel="icon" type="image/png" href="./img/favicon/favicon-16x16.png" sizes="16x16">
89
		<link rel="icon" type="image/png" href="./img/favicon/favicon-32x32.png" sizes="32x32">
90
		<link rel="icon" type="image/png" href="./img/favicon/favicon-96x96.png" sizes="96x96">
91
		<link rel="icon" type="image/png" href="./img/favicon/favicon-160x160.png" sizes="160x160">
92
		<link rel="icon" type="image/png" href="./img/favicon/favicon-192x192.png" sizes="192x192">
93
		<link rel="icon" type="image/png" href="./img/favicon/favicon-196x196.png" sizes="196x196">
94
		<meta name="msapplication-TileImage" content="./img/favicon/win8-tile-144x144.png"> 
95
		<meta name="msapplication-TileColor" content="#5682a3"> 
96
		<meta name="msapplication-navbutton-color" content="#5682a3"> 
97
		<meta name="application-name" content="JodelBlue"/> 
98
		<meta name="msapplication-tooltip" content="JodelBlue"/> 
99
		<meta name="apple-mobile-web-app-title" content="JodelBlue"/> 
100
		<meta name="msapplication-square70x70logo" content="./img/favicon/win8-tile-70x70.png"> 
101
		<meta name="msapplication-square144x144logo" content="./img/favicon/win8-tile-144x144.png"> 
102
		<meta name="msapplication-square150x150logo" content="./img/favicon/win8-tile-150x150.png"> 
103
		<meta name="msapplication-wide310x150logo" content="./img/favicon/win8-tile-310x150.png"> 
104
		<meta name="msapplication-square310x310logo" content="./img/favicon/win8-tile-310x310.png"> 
105
	</head>
106
	
107
	<body>
108
		<header>
109
			<nav class="navbar navbar-full navbar-dark navbar-fixed-top">
110
				<div class="container">					
111
						<?php
112 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...
113
							{
114
								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...
115
								echo '<i class="fa fa-angle-left fa-3x"></i>';
116
								echo '</a>';
117
								echo '<h1>';
118
								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...
119
							}
120
							else
121
							{
122
								echo '<h1>';	
123
								echo '<a href="./" class="spinnable">';
124
							}
125
						?>
126
						JodelBlue <i class="fa fa-refresh fa-1x"></i></a>
127
					</h1>					
128
				</div>
129
			</nav>
130
		</header>
131
		
132
		<div class="mainContent container">		
133
			<div class="content row">
134
				<article class="topContent col-sm-8">
135
136
					<content id="posts">
137
						<form method="post">
138
							<button type="submit" name="createAccount" value="TRUE">Create new Account</button>
139
						</form>
140
141
						<form method="post">
142
							quantity<input type="number" name="quantity">
143
							postId<input type="text" name="postId">
144
							<button type="submit" name="vote" value="up">Upvote</button>
145
							<button type="submit" name="vote" value="down">Downvote</button>
146
						</form>
147
					</content>
148
				</article>
149
			
150
				<aside class="topSidebar col-sm-4 sidebar-outer">
151
					<div class="fixed">
152
						<article>
153
							<div>
154
								<h2>Position</h2>
155
								<form method="get">
156
									<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...
157
158
									<input type="submit" value="Set Location" /> 
159
								</form>
160
							</div>
161
						</article>
162
163
						<article>
164
							<div>
165
								<h2>Karma</h2>
166
								<?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...
167
							</div>
168
						</article>
169
170
						<article>
171
							<div>
172 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...
173
								<h2>Comment on Jodel</h2>
174
								<form method="POST">				
175
										<input type="hidden" name="ancestor" value="<?php echo htmlspecialchars($_GET['postID']);?>" />
176
										<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...
177
									<br />
178
									<input type="submit" value="SEND" /> 
179
								</form>
180
									<?php } else { ?>
181
								<h2>New Jodel</h2>
182
								<form method="POST">
183
									<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...
184
									<br />
185
									<select id="postColorPicker" name="color">
186
										<option value="06A3CB">Blue</option>
187
										<option value="8ABDB0">Teal</option>
188
										<option value="9EC41C">Green</option>
189
										<option value="FFBA00">Yellow</option>
190
										<option value="DD5F5F">Red</option>
191
										<option value="FF9908">Orange</option>
192
									</select> 
193
									<br />
194
									<input type="submit" value="SEND" /> 
195
								</form>
196
								<?php } ?>
197
							</div>
198
						</article>
199
							
200
						<article>
201
							<div>
202
								<h2>Login</h2>
203
							</div>
204
						</article>
205
					</div>
206
				</aside>
207
			</div>
208
			<div id="sortJodelBy" class="row">
209
				<div class="col-sm-12">
210
					<div class="row">
211
						
212
					</div>
213
				</div>	
214
			</div>
215
		</div>
216
		
217
		
218
		<!-- jQuery, Tether, Bootstrap JS and own-->
219
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha384-3ceskX3iaEnIogmQchP8opvBy3Mi7Ce34nWjpBIwVTHfGYWQS9jwHDVRnpKKHJg7" crossorigin="anonymous"></script>
220
    	<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.3.7/js/tether.min.js" integrity="sha384-XTs3FgkjiBgo8qjEjBk0tGmf3wPrWtA6coPfQDfFEY8AnYJwjalXCiosYRBIBZX8" crossorigin="anonymous"></script>
221
    	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/js/bootstrap.min.js" integrity="sha384-BLiI7JTZm+JWlgKa0M0kGRpJbF2J8q+qreVrKBC47e3K6BW78kGLrCkeRX6I9RoK" crossorigin="anonymous"></script>
222
    	<script src="js/jQueryEmoji.js"></script>
223
224
		<script>
225
			//BackButton
226
			function goBack()
227
			{
228
				window.history.back();
229
			}
230
231
			$(document).ready(function()
232
			{
233
234
235
				//Transform UTF-8 Emoji to img
236
				$('.jodel > content').Emoji();
237
238
				$('a').on('click', function(){
239
				    $('a').removeClass('selected');
240
				    $(this).addClass('selected');
241
				});
242
243
				function scrollToAnchor(aid){
244
				    var aTag = $("article[id='"+ aid +"']");
245
				    $('html,body').animate({scrollTop: aTag.offset().top-90},'slow');
246
				}
247
248 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...
249
250
				
251
252
253
254
				var win = $(window);
255
				var lastPostId = "<?php echo $lastPostId; ?>";
256
				var view = "<?php echo $view; ?>"
257
				var old_lastPostId = "";
258
				var morePostsAvailable = true;
259
260
				if(window.location.hash)
261
				{
262
					var hash = window.location.hash.slice(1);
263
264
					if(!$("article[id='"+ hash +"']").length)
265
					{
266
						for (var i = 5; i >= 0; i--)
267
						{
268
							if(!$("article[id='"+ hash +"']").length)
269
							{
270
								$.ajax({
271
									url: 'get-posts-ajax.php?lastPostId=' + lastPostId + '&view=' + view,
272
									dataType: 'html',
273
									async: false,
274
									success: function(html) {
275
										var div = document.createElement('div');
276
										div.innerHTML = html;
277
										var elements = div.childNodes;
278
										old_lastPostId = lastPostId;
279
										lastPostId = elements[3].textContent;
280
										lastPostId = lastPostId.replace(/\s+/g, '');
281
										//alert('Neu: ' + lastPostId + " Alt: " + old_lastPostId);
282
										if(lastPostId == old_lastPostId) {
283
											
284
											//morePostsAvailable = false;
285
										}
286
										else {
287
											//alert(elements[3].textContent);
288
											$('#posts').append(elements[1].innerHTML);
289
											$('#posts').hide().show(0);
290
										}
291
										$('#loading').hide();
292
									}
293
								});
294
295
								$('.jodel > content').Emoji();
296
							}
297
							
298
						}
299
						scrollToAnchor(hash);
300
301
					}						
302
				}
303
304
				// Each time the user scrolls
305
				win.scroll(function() {
306
307
308
					// End of the document reached?
309
					if (($(document).height() - win.height() == win.scrollTop()) && morePostsAvailable) {
310
						$('#loading').show();
311
312
						
313
						
314
						$.ajax({
315
							url: 'get-posts-ajax.php?lastPostId=' + lastPostId + '&view=' + view,
316
							dataType: 'html',
317
							async: false,
318
							success: function(html) {
319
								var div = document.createElement('div');
320
								div.innerHTML = html;
321
								var elements = div.childNodes;
322
								old_lastPostId = lastPostId;
323
								lastPostId = elements[3].textContent;
324
								lastPostId = lastPostId.replace(/\s+/g, '');
325
								//alert('Neu: ' + lastPostId + " Alt: " + old_lastPostId);
326
								if(lastPostId == old_lastPostId)
327
								{
328
									
329
									//morePostsAvailable = false;
330
								}
331
								else
332
								{
333
									//alert(elements[3].textContent);
334
									$('#posts').append(elements[1].innerHTML);
335
								}
336
								$('#loading').hide();
337
							}
338
						});
339
340
						$('.jodel > content').Emoji();
341
					}
342
				});
343
			<?php } ?>
344
			});	
345
346
		</script>
347
	</body>
348
</html>