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
|
|
View Code Duplication |
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/"; |
|
|
|
|
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
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.