Completed
Push — master ( 50907f...5052c4 )
by mains
02:42
created

get-posts-ajax.php (7 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
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
	if ($result->num_rows > 0) {
30
		// output data of each row
31
		while($row = $result->fetch_assoc()) {
32
			$access_token = $row["access_token"];
33
		}
34
	}
35
	else
36
	{
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/";
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
Coding Style Comprehensibility introduced by
The string literal /posts/location/discussed/ does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
54
	}
55
	else
56
	{
57
		if(isset($_GET['upVoteView']))
58
		{
59
			$upVoteView = true;
60
			$url = "/posts/location/popular/";
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
Coding Style Comprehensibility introduced by
The string literal /posts/location/popular/ does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
61
		}
62
		else
63
		{
64
			$timeView = true;
65
			$url = "/v2/posts";
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
Coding Style Comprehensibility introduced by
The string literal /v2/posts does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
66
		}
67
	}
68
69
	if(isset($_GET['lastPostId'])) {
70
	
71
		$lastPostId = htmlspecialchars($_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 str_replace('  ', ' &nbsp;', nl2br(htmlspecialchars($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"];?>">
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal post_id does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
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