Completed
Push — master ( af5052...240863 )
by mains
02:56
created

get-posts-ajax.php (1 issue)

Labels
Severity

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/DatabaseConnect.php';
5
include 'php/Requests/AbstractRequest.php';
6
include 'php/Requests/CreateUser.php';
7
include 'php/AccountData.php';
8
include 'php/Location.php';
9
include 'php/Requests/GetPosts.php';
10
include 'php/Requests/GetKarma.php';
11
include 'php/Requests/UpdateLocation.php';
12
include 'php/Requests/Upvote.php';
13
include 'php/Requests/Downvote.php';
14
include 'php/Requests/GetPostDetails.php';
15
include 'php/Requests/SendJodel.php';
16
17
require_once 'php/Requests/libary/Requests.php';
18
Requests::register_autoloader();
19
20
function getPosts($lastPostId, $url) {
21
	$db = new DatabaseConnect();
22
	if ($db->connect_errno) {
23
		echo 'Sorry, die Verbindung zu unserem superfetten endgeilen 
24
					Server ist hops gegangen. Wegen '. $db -> connect_error;
25
	}
26
	
27
	$result = $db->query("SELECT * FROM accounts WHERE id='1'");
28
	
29
	$access_token;
0 ignored issues
show
The variable $access_token seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
30
	
31
	if ($result->num_rows > 0) {
32
			// output data of each row
33
			while($row = $result->fetch_assoc()) {
34
					$access_token = $row["access_token"];
35
			}
36
	} else {
37
			echo "0 results";
38
	}
39
	
40
	$accountCreator = new GetPosts();
41
	$accountCreator->setLastPostID($lastPostId);
42
	$accountCreator->setUrl($url);
43
	$accountCreator->setAccessToken($access_token);
44
	$data = $accountCreator->execute();
45
46
	return $data;
47
}
48
	$posts;
49
50 View Code Duplication
	if(isset($_GET['commentView']))
51
	{
52
		$commentView = true;
53
		$url = "/posts/location/discussed/";
54
	}
55
	else
56
	{
57
		if(isset($_GET['upVoteView']))
58
		{
59
			$upVoteView = true;
60
			$url = "/posts/location/popular/";
61
		}
62
		else
63
		{
64
			$timeView = true;
65
			$url = "/v2/posts";
66
		}
67
	}
68
69
	if(isset($_GET['lastPostId'])) {
70
	
71
		$lastPostId = $_GET['lastPostId'];
72
		
73
		$posts = getPosts($lastPostId, $url)['posts'];
74
		$loops = 29;
75
		$showCommentIcon = TRUE;
76
		?>
77
		<div class="nextPosts">
78
		<?php
79
		for($i = 0; $i<$loops; $i++) {
80
		
81
			if(isset($posts[$i])) {
82
				$lastPostId = $posts[$i]['post_id'];
83
84
				
85
				$now = new DateTime();
86
				$d = new DateTime($posts[$i]["created_at"]);
87
				
88
				
89
				//Time to time difference
90
							$timediff = $now->diff($d);
91
92
							$timediff_inSeconds = (string)$timediff->format('%s');
93
							$timediff_inMinutes = (string)$timediff->format('%i');
94
							$timediff_inHours = (string)$timediff->format('%h');
95
							$timediff_inDays = (string)$timediff->format('%d');
96
							$timediff_inMonth = (string)$timediff->format('%m');
97 View Code Duplication
							if($timediff_inMonth!=0) {
98
									$timediff = $timediff_inMonth . "m";
99
							}
100
							else
101
							{
102
								if($timediff_inDays!=0)
103
								{
104
									$timediff = $timediff_inDays . "d";
105
								}
106
								else
107
								{
108
									if($timediff_inHours!=0)
109
									{
110
										$timediff = $timediff_inHours . "h";
111
									}
112
									else
113
									{
114
										if($timediff_inMinutes!=0)
115
										{
116
											$timediff = $timediff_inMinutes . "m";
117
										}
118
										else
119
										{
120
											$timediff = $timediff_inSeconds . "s";
121
										}
122
									}
123
								}
124
							}
125
						?>
126
127
				<article class="jodel" style="background-color: #<?php echo $posts[$i]["color"];?>;">
128
					<content>
129
						<?php 
130 View Code Duplication
						if(isset($posts[$i]["image_url"])) {
131
							echo '<img src="' . $posts[$i]["image_url"] . '">';
132
						}
133
						else {
134
							echo nl2br($posts[$i]["message"]);
135
						}
136
						?>
137
					</content>
138
					<aside>
139
						<a href="index.php?vote=up&postID=<?php echo $posts[$i]["post_id"];?>">
140
							<i class="fa fa-angle-up fa-3x"></i>
141
						</a>	
142
							<br />
143
						<?php echo $posts[$i]["vote_count"];?><br />
144
						<a href="index.php?vote=down&postID=<?php echo $posts[$i]["post_id"];?>">
145
							<i class="fa fa-angle-down fa-3x"></i>
146
						</a>
147
					</aside>
148
149
					<footer>
150
						<table>
151
							<tr>
152
								<td class="time">
153
									<span data-tooltip="Time">
154
										<i class="fa fa-clock-o"></i>
155
										<?php echo $timediff;?>
156
									</span> 
157
								</td>
158
								<td class="comments">
159 View Code Duplication
									<?php if($showCommentIcon) {?>
160
									<span data-tooltip="Comments">
161
										<a href="index.php?getPostDetails=true&postID=<?php echo $posts[$i]["post_id"];?>">
162
											<i class="fa fa-commenting-o"></i>
163
											<?php if(array_key_exists("child_count", $posts[$i])) {
164
														echo $posts[$i]["child_count"];
165
													} else echo "0";
166
											?>
167
											</a>
168
									</span>
169
									<?php } ?>
170
								</td>
171
								<td class="distance">
172
									<span data-tooltip="Distance">
173
										<i class="fa fa-map-marker"></i>
174
										<?php echo $posts[$i]["distance"];?> km
175
									</span>
176
								</td>
177
							</tr>
178
						</table>
179
					</footer>
180
				</article>
181
182
183
184
				<?php 
185
			}
186
		}
187
		?>
188
		</div>
189
		<div class="lastPostId">
190
		<?php echo $lastPostId; ?>
191
		</div>
192
		<?php
193
	}
194