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('0.1'); |
||
7 | $location->setLng('0.1'); |
||
8 | $location->setCityName('Munich'); |
||
9 | |||
10 | isTokenFresh($location); |
||
11 | |||
12 | $result = $db->query("SELECT * FROM accounts WHERE id='1'"); |
||
13 | |||
14 | $accessToken; |
||
15 | $newPostionStatus; |
||
16 | |||
17 | View Code Duplication | if ($result->num_rows > 0) |
|
0 ignored issues
–
show
|
|||
18 | { |
||
19 | // output data of each row |
||
20 | while($row = $result->fetch_assoc()) |
||
21 | { |
||
22 | $accessToken = $row["access_token"]; |
||
23 | } |
||
24 | } |
||
25 | else |
||
26 | { |
||
27 | echo "Error: 0 results"; |
||
28 | } |
||
29 | |||
30 | |||
31 | createAccount(); |
||
32 | |||
33 | //Set Location |
||
34 | if(isset($_GET['city'])) { |
||
35 | |||
36 | $url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . $_GET['city'] . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w'; |
||
37 | $result = Requests::post($url); |
||
38 | if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS') |
||
39 | { |
||
40 | $newPostionStatus = "0 results"; |
||
41 | } |
||
42 | else |
||
43 | { |
||
44 | $location = new Location(); |
||
45 | $location->setLat(json_decode($result->body, true)['results']['0']['geometry']['location']['lat']); |
||
46 | $location->setLng(json_decode($result->body, true)['results']['0']['geometry']['location']['lng']); |
||
47 | $location->setCityName($_GET['city']); |
||
48 | $accountCreator = new UpdateLocation(); |
||
49 | $accountCreator->setLocation($location); |
||
50 | $accountCreator->setAccessToken($accessToken); |
||
51 | $data = $accountCreator->execute(); |
||
52 | } |
||
53 | } |
||
54 | |||
55 | //Vote |
||
56 | if(isset($_GET['vote']) && isset($_GET['postID'])) { |
||
57 | if($_GET['vote'] == "up") { |
||
58 | $accountCreator = new Upvote(); |
||
59 | } |
||
60 | else if($_GET['vote'] == "down") { |
||
61 | $accountCreator = new Downvote(); |
||
62 | } |
||
63 | $accountCreator->setAccessToken($accessToken); |
||
64 | $data = $accountCreator->execute(); |
||
65 | |||
66 | header("Location: index.php#postId-" . $_GET['postID']); |
||
67 | die(); |
||
68 | } |
||
69 | |||
70 | |||
71 | //SendJodel |
||
72 | if(isset($_POST['message'])) { |
||
73 | $ancestor; |
||
74 | if(isset($_POST['ancestor'])) |
||
75 | { |
||
76 | $ancestor = $_POST['ancestor']; |
||
77 | } |
||
78 | |||
79 | $location = new Location(); |
||
80 | $location->setLat('0.1'); |
||
81 | $location->setLng('0.1'); |
||
82 | $location->setCityName('Munich'); |
||
83 | $accountCreator = new SendJodel(); |
||
84 | $accountCreator->setLocation($location); |
||
85 | $accountCreator->setAncestor($ancestor); |
||
86 | $accountCreator->setAccessToken($accessToken); |
||
87 | $data = $accountCreator->execute(); |
||
88 | } |
||
89 | ?> |
||
90 | <!DOCTYPE html> |
||
91 | <html lang="de"> |
||
92 | <head> |
||
93 | <title>Jodel WebClient - </title> |
||
94 | |||
95 | <meta charset="utf8" /> |
||
96 | <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
||
97 | |||
98 | <meta name="description" content=""/> |
||
99 | <meta name="keywords" content=""/> |
||
100 | |||
101 | <link rel="stylesheet" href="css/font-awesome.min.css"> |
||
102 | <link href="css/least.min.css" rel="stylesheet" /> |
||
103 | <link rel="stylesheet" href="style.css" type="text/css" /> |
||
104 | |||
105 | <link rel="shortcut icon" href="img/favicon/favicon.ico" type="image/x-icon"> |
||
106 | <link rel="icon" href="img/favicon/favicon.ico" type="image/x-icon"> |
||
107 | |||
108 | </head> |
||
109 | |||
110 | <body> |
||
111 | |||
112 | <header class="mainHeader"> |
||
113 | <a href="index.php"> |
||
114 | <h1> |
||
115 | Jodel WebClient |
||
116 | <?php if(!isset($_GET['postID']) && !isset($_GET['getPostDetails'])) echo '<i class="fa fa-refresh fa-1x"></i>';?> |
||
117 | </h1> |
||
118 | </a> |
||
119 | <div class="clear"></div> |
||
120 | </header> |
||
121 | |||
122 | <div class="mainContent"> |
||
123 | <div class="content"> |
||
124 | <article class="topContent"> |
||
125 | |||
126 | <content id="posts"> |
||
127 | <?php |
||
128 | $posts; |
||
129 | |||
130 | //Get Post Details |
||
131 | if(isset($_GET['postID']) && isset($_GET['getPostDetails'])) { |
||
132 | //Header Nav in Comment View |
||
133 | ?> |
||
134 | <a id="comment-back" href="index.php#postId-<?php echo $_GET['postID'];?>"> |
||
135 | <i class="fa fa-angle-left fa-3x"></i> |
||
136 | </a> |
||
137 | |||
138 | <a id="comment-refresh" href="index.php?getPostDetails=<?php echo $_GET['getPostDetails'];?>&postID=<?php echo $_GET['postID'];?>"> |
||
139 | <i class="fa fa-refresh fa-2x"></i> |
||
140 | </a> |
||
141 | <?php |
||
142 | |||
143 | |||
144 | $accountCreator = new GetPostDetails(); |
||
145 | $accountCreator->setAccessToken($accessToken); |
||
146 | $data = $accountCreator->execute(); |
||
147 | |||
148 | $posts[0] = $data; |
||
149 | if(isset($data['children'])) { |
||
150 | foreach($data['children'] as $child) { |
||
151 | array_push($posts, $child); |
||
152 | } |
||
153 | $loops = $data['child_count'] + 1; |
||
154 | } |
||
155 | else $loops = 1; |
||
156 | $showCommentIcon = FALSE; |
||
157 | } |
||
158 | //Get Posts |
||
159 | else { |
||
160 | View Code Duplication | if(isset($_GET['commentView'])) |
|
161 | { |
||
162 | $commentView = true; |
||
163 | $url = "/v2/posts/location/discussed/"; |
||
164 | } |
||
165 | else |
||
166 | { |
||
167 | if(isset($_GET['upVoteView'])) |
||
168 | { |
||
169 | $upVoteView = true; |
||
170 | $url = "/v2/posts/location/popular/"; |
||
171 | } |
||
172 | else |
||
173 | { |
||
174 | $timeView = true; |
||
175 | $url = "/v2/posts"; |
||
176 | } |
||
177 | } |
||
178 | |||
179 | $posts = getPosts($lastPostId, $accessToken, $url)['posts']; |
||
180 | $loops = 29; |
||
181 | $showCommentIcon = TRUE; |
||
182 | } |
||
183 | |||
184 | |||
185 | for($i = 0; $i<$loops; $i++) { |
||
186 | |||
187 | if(isset($posts[$i])) { |
||
188 | $lastPostId = $posts[$i]['post_id']; |
||
189 | |||
190 | |||
191 | $now = new DateTime(); |
||
192 | $d = new DateTime($posts[$i]["created_at"]); |
||
193 | |||
194 | |||
195 | //Time to time difference |
||
196 | $timediff = $now->diff($d); |
||
197 | |||
198 | $timediff_inSeconds = (string)$timediff->format('%s'); |
||
199 | $timediff_inMinutes = (string)$timediff->format('%i'); |
||
200 | $timediff_inHours = (string)$timediff->format('%h'); |
||
201 | $timediff_inDays = (string)$timediff->format('%d'); |
||
202 | $timediff_inMonth = (string)$timediff->format('%m'); |
||
203 | View Code Duplication | if($timediff_inMonth!=0) { |
|
204 | $timediff = $timediff_inMonth . "m"; |
||
205 | } |
||
206 | else |
||
207 | { |
||
208 | if($timediff_inDays!=0) |
||
209 | { |
||
210 | $timediff = $timediff_inDays . "d"; |
||
211 | } |
||
212 | else |
||
213 | { |
||
214 | if($timediff_inHours!=0) |
||
215 | { |
||
216 | $timediff = $timediff_inHours . "h"; |
||
217 | } |
||
218 | else |
||
219 | { |
||
220 | if($timediff_inMinutes!=0) |
||
221 | { |
||
222 | $timediff = $timediff_inMinutes . "m"; |
||
223 | } |
||
224 | else |
||
225 | { |
||
226 | $timediff = $timediff_inSeconds . "s"; |
||
227 | } |
||
228 | } |
||
229 | } |
||
230 | } |
||
231 | ?> |
||
232 | |||
233 | <article id ="postId-<?php echo $posts[$i]["post_id"]; ?>" class="jodel" style="background-color: #<?php echo $posts[$i]["color"];?>;"> |
||
234 | <content> |
||
235 | <?php |
||
236 | View Code Duplication | if(isset($posts[$i]["image_url"])) { |
|
237 | echo '<img src="' . $posts[$i]["image_url"] . '">'; |
||
238 | } |
||
239 | else { |
||
240 | echo nl2br($posts[$i]["message"]); |
||
241 | } |
||
242 | ?> |
||
243 | </content> |
||
244 | <aside> |
||
245 | <a href="index.php?vote=up&postID=<?php echo $posts[$i]["post_id"];?>"> |
||
246 | <i class="fa fa-angle-up fa-3x"></i> |
||
247 | </a> |
||
248 | <br /> |
||
249 | <?php echo $posts[$i]["vote_count"];?><br /> |
||
250 | <a href="index.php?vote=down&postID=<?php echo $posts[$i]["post_id"];?>"> |
||
251 | <i class="fa fa-angle-down fa-3x"></i> |
||
252 | </a> |
||
253 | </aside> |
||
254 | |||
255 | <footer> |
||
256 | <table> |
||
257 | <tr> |
||
258 | <td class="time"> |
||
259 | <span data-tooltip="Time"> |
||
260 | <i class="fa fa-clock-o"></i> |
||
261 | <?php echo $timediff;?> |
||
262 | </span> |
||
263 | </td> |
||
264 | <td class="comments"> |
||
265 | View Code Duplication | <?php if($showCommentIcon) {?> |
|
266 | <span data-tooltip="Comments"> |
||
267 | <a href="index.php?getPostDetails=true&postID=<?php echo $posts[$i]["post_id"];?>"> |
||
268 | <i class="fa fa-commenting-o"></i> |
||
269 | <?php if(array_key_exists("child_count", $posts[$i])) { |
||
270 | echo $posts[$i]["child_count"]; |
||
271 | } else echo "0"; |
||
272 | ?> |
||
273 | </a> |
||
274 | </span> |
||
275 | <?php } ?> |
||
276 | </td> |
||
277 | <td class="distance"> |
||
278 | <span data-tooltip="Distance"> |
||
279 | <i class="fa fa-map-marker"></i> |
||
280 | <?php echo $posts[$i]["distance"];?> km |
||
281 | </span> |
||
282 | </td> |
||
283 | </tr> |
||
284 | </table> |
||
285 | </footer> |
||
286 | </article> |
||
287 | |||
288 | |||
289 | |||
290 | <?php } |
||
291 | } ?> |
||
292 | </content> |
||
293 | |||
294 | </article> |
||
295 | <?php if(!isset($_GET['postID']) && !isset($_GET['getPostDetails'])) { ?> |
||
296 | <p id="loading"> |
||
297 | <img src="images/loading.gif" alt="Loading…" /> |
||
298 | </p> |
||
299 | <?php } ?> |
||
300 | <nav id="sortJodelBy"> |
||
301 | <a href="index.php" <?php if(isset($timeView)) echo 'class="active"';?>><i class="fa fa-clock-o fa-3x"></i></a> |
||
302 | <a href="index.php?commentView=true" <?php if(isset($commentView)) echo 'class="active"';?>><i class="fa fa-commenting-o fa-3x"></i></a> |
||
303 | <a href="index.php?upVoteView=true" <?php if(isset($upVoteView)) echo 'class="active"';?>><i class="fa fa-angle-up fa-3x"></i></a> |
||
304 | </nav> |
||
305 | </div> |
||
306 | |||
307 | <aside class="topSidebar"> |
||
308 | <article> |
||
309 | <h3>Position</h3> |
||
310 | <form method="get"> |
||
311 | <input type="text" id="city" name="city" placeholder="<?php if(isset($newPositionStatus)) echo $newPositionStatus; else echo $posts[0]["location"]["name"]; ?>" required> |
||
312 | |||
313 | <input type="submit" value="Set Location" /> |
||
314 | </form> |
||
315 | |||
316 | </article> |
||
317 | |||
318 | <article> |
||
319 | <h2>Karma</h2> |
||
320 | <?php echo getKarma($accessToken); ?> |
||
321 | </article> |
||
322 | |||
323 | <article> |
||
324 | View Code Duplication | <?php if(isset($_GET['postID']) && isset($_GET['getPostDetails'])) { ?> |
|
325 | <h2>Comment on Jodel</h2> |
||
326 | <form method="POST"> |
||
327 | <input type="hidden" name="ancestor" value="<?php echo $_GET['postID'];?>" /> |
||
328 | <textarea id="message" name="message" placeholder="Send a comment on a Jodel to all students within 10km" required></textarea> |
||
329 | <br /> |
||
330 | <input type="submit" value="SEND" /> |
||
331 | </form> |
||
332 | <?php } else { ?> |
||
333 | <h2>New Jodel</h2> |
||
334 | <form method="POST"> |
||
335 | <textarea id="message" name="message" placeholder="Send a Jodel to all students within 10km" required></textarea> |
||
336 | <br /> |
||
337 | <input type="submit" value="SEND" /> |
||
338 | </form> |
||
339 | <?php } ?> |
||
340 | |||
341 | </article> |
||
342 | </aside> |
||
343 | |||
344 | </div> |
||
345 | |||
346 | <footer class="mainFooter"> |
||
347 | <p> |
||
348 | <span class="float-right-footer"><a href="./impressum.html">Impressum</a></span> |
||
349 | </p> |
||
350 | </footer> |
||
351 | |||
352 | |||
353 | <!-- jQuery library --> |
||
354 | <script src="js/libs/jquery/2.0.2/jquery.min.js"></script> |
||
355 | <script> |
||
356 | $('a').on('click', function(){ |
||
357 | $('a').removeClass('selected'); |
||
358 | $(this).addClass('selected'); |
||
359 | }); |
||
360 | |||
361 | View Code Duplication | <?php if(!isset($_GET['postID']) && !isset($_GET['getPostDetails'])) { ?> |
|
362 | $(document).ready(function() { |
||
363 | var win = $(window); |
||
364 | var lastPostId = "<?php echo $lastPostId; ?>"; |
||
365 | var old_lastPostId = ""; |
||
366 | var morePostsAvailable = true; |
||
367 | // Each time the user scrolls |
||
368 | win.scroll(function() { |
||
369 | // End of the document reached? |
||
370 | if (($(document).height() - win.height() == win.scrollTop()) && morePostsAvailable) { |
||
371 | $('#loading').show(); |
||
372 | |||
373 | |||
374 | |||
375 | $.ajax({ |
||
376 | url: 'get-posts-ajax.php?lastPostId=' + lastPostId, |
||
377 | dataType: 'html', |
||
378 | async: true, |
||
379 | success: function(html) { |
||
380 | var div = document.createElement('div'); |
||
381 | div.innerHTML = html; |
||
382 | var elements = div.childNodes; |
||
383 | old_lastPostId = lastPostId; |
||
384 | lastPostId = elements[3].textContent; |
||
385 | lastPostId = lastPostId.replace(/\s+/g, ''); |
||
386 | //alert('Neu: ' + lastPostId + " Alt: " + old_lastPostId); |
||
387 | if(lastPostId == old_lastPostId) { |
||
388 | |||
389 | //morePostsAvailable = false; |
||
390 | } |
||
391 | else { |
||
392 | //alert(elements[3].textContent); |
||
393 | $('#posts').append(elements[1].innerHTML); |
||
394 | } |
||
395 | $('#loading').hide(); |
||
396 | } |
||
397 | }); |
||
398 | } |
||
399 | }); |
||
400 | }); |
||
401 | <?php } ?> |
||
402 | </script> |
||
403 | |||
404 | </body> |
||
405 | </html> |
||
406 | |||
407 |
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.