Completed
Push — master ( 6fce2f...9d108c )
by mains
16:33
created

get-posts-ajax.php (1 issue)

Upgrade to new PHP Analysis Engine

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

1
<?php
2
error_reporting(-1);
3
4
include 'php/jodel-web.php';
5
6
$location = new Location();
7
$location->setLat('52.5134288');
8
$location->setLng('13.2746394');
9
$location->setCityName('Berlin');
10
11
$accessToken;
12
$accessToken_forId1;
13
$deviceUid;
14
15
setcookie("JodelId", "", time()-3600);
16
17 View Code Duplication
if(!isset($_COOKIE["JodelDeviceId"]))
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...
18
{
19
	$deviceUid = createAccount();
20
	setcookie("JodelDeviceId", $deviceUid, time()+60*60*24*365*10);
21
	
22
}
23
else
24
{
25
	$deviceUid = $db->real_escape_string($_COOKIE["JodelDeviceId"]);
26
}
27
28
$location = getLocationByDeviceUid($deviceUid);
29
$newPositionStatus = $location->getCityName();
30
$accessToken = isTokenFreshByDeviceUid($location, $deviceUid);
31
//Acc is fresh. token and location is set
32
33
$accessToken_forId1 = isTokenFresh($location);
34
35
36
37 View Code Duplication
	if(isset($_GET['view']))
38
	{
39
		switch ($_GET['view']) {
40
			case 'comment':
41
				$view = 'comment';
42
				break;
43
			
44
			case 'upVote':
45
				$view = 'upVote';
46
				break;
47
48
			default:
49
				$view = 'time';
50
				break;
51
		}
52
	}
53
	else
54
	{
55
		$view = 'time';
56
	}
57
58
	if($view=='comment')
59
	{
60
		$url = "/v2/posts/location/discussed/";
61
	}
62
	else
63
	{
64
		if($view=='upVote')
65
		{
66
			$url = "/v2/posts/location/popular/";
67
		}
68
		else
69
		{
70
			$url = "/v2/posts/location/";
71
		}
72
	}
73
74
	if(isset($_GET['lastPostId']))
75
	{
76
		$lastPostId = htmlspecialchars($_GET['lastPostId']);
77
		
78
		$posts = getPosts($lastPostId, $accessToken, $url)['posts'];
79
		$loops = 29;
80
		$showCommentIcon = TRUE;
81
		?>
82
		<div class="nextPosts">
83
		<?php
84 View Code Duplication
		for($i = 0; $i<$loops; $i++)
85
		{
86
			if(isset($posts[$i]))
87
			{
88
				$lastPostId = $posts[$i]['post_id'];
89
				jodelToHtml($posts[$i], $view);	
90
			}
91
		}
92
		?>
93
		</div>
94
		<div class="lastPostId">
95
		<?php echo $lastPostId; ?>
96
		</div>
97
		<?php
98
	}
99