Completed
Push — master ( 5edd0c...906cba )
by mains
03:02
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
13 View Code Duplication
if(!isset($_COOKIE["JodelId"]))
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...
14
{
15
	$accessToken = createAccount();
16
	setcookie("JodelId", $accessToken);
17
}
18
else
19
{
20
	$accessToken = $db->real_escape_string($_COOKIE["JodelId"]);
21
}
22
23
$location = getLocationByAccessToken($accessToken);
24
25
isTokenFreshByAccessToken($location, $accessToken);
26
27
$result = $db->query("SELECT * FROM accounts WHERE access_token='" . $accessToken  . "'");
28
29
$newPositionStatus;
30
31 View Code Duplication
if ($result->num_rows > 0)
32
{
33
	// output data of each row
34
	while($row = $result->fetch_assoc())
35
	{
36
		$accessToken = $row["access_token"];
37
	}
38
}
39
else
40
{
41
	echo "Error: 0 results";
42
}
43
44
45 View Code Duplication
	if(isset($_GET['view']))
46
	{
47
		switch ($_GET['view']) {
48
			case 'comment':
49
				$view = 'comment';
50
				break;
51
			
52
			case 'upVote':
53
				$view = 'upVote';
54
				break;
55
56
			default:
57
				$view = 'time';
58
				break;
59
		}
60
	}
61
	else
62
	{
63
		$view = 'time';
64
	}
65
66
	if($view=='comment')
67
	{
68
		$url = "/v2/posts/location/discussed/";
69
	}
70
	else
71
	{
72
		if($view=='upVote')
73
		{
74
			$url = "/v2/posts/location/popular/";
75
		}
76
		else
77
		{
78
			$url = "/v2/posts/location/";
79
		}
80
	}
81
82
	if(isset($_GET['lastPostId']))
83
	{
84
		$lastPostId = htmlspecialchars($_GET['lastPostId']);
85
		
86
		$posts = getPosts($lastPostId, $accessToken, $url)['posts'];
87
		$loops = 29;
88
		$showCommentIcon = TRUE;
89
		?>
90
		<div class="nextPosts">
91
		<?php
92 View Code Duplication
		for($i = 0; $i<$loops; $i++)
93
		{
94
			if(isset($posts[$i]))
95
			{
96
				$lastPostId = $posts[$i]['post_id'];
97
				jodelToHtml($posts[$i], $view);	
98
			}
99
		}
100
		?>
101
		</div>
102
		<div class="lastPostId">
103
		<?php echo $lastPostId; ?>
104
		</div>
105
		<?php
106
	}
107