1
|
|
|
<?php |
|
|
|
|
2
|
|
|
error_reporting(-1); |
3
|
|
|
include 'php/DatabaseConnect.php'; |
4
|
|
|
include 'php/Requests/AbstractRequest.php'; |
5
|
|
|
include 'php/Requests/CreateUser.php'; |
6
|
|
|
include 'php/AccountData.php'; |
7
|
|
|
include 'php/Location.php'; |
8
|
|
|
include 'php/Requests/GetPosts.php'; |
9
|
|
|
include 'php/Requests/GetKarma.php'; |
10
|
|
|
include 'php/Requests/UpdateLocation.php'; |
11
|
|
|
include 'php/Requests/Upvote.php'; |
12
|
|
|
include 'php/Requests/Downvote.php'; |
13
|
|
|
include 'php/Requests/GetPostDetails.php'; |
14
|
|
|
include 'php/Requests/SendJodel.php'; |
15
|
|
|
include 'php/Requests/GetCaptcha.php'; |
16
|
|
|
include 'php/Requests/PostCaptcha.php'; |
17
|
|
|
include 'php/Requests/GetUserConfig.php'; |
18
|
|
|
|
19
|
|
|
require_once 'php/Requests/libary/Requests.php'; |
20
|
|
|
Requests::register_autoloader(); |
21
|
|
|
|
22
|
|
|
$lastPostId = ''; |
23
|
|
|
|
24
|
|
|
function isAccountVerified($accessToken_forId1) |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
$accountCreator = new GetUserConfig(); |
27
|
|
|
$accountCreator->setAccessToken($accessToken_forId1); |
28
|
|
|
$data = $accountCreator->execute(); |
29
|
|
|
|
30
|
|
|
return $data['verified']; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function getCaptcha($accessToken_forId1) |
34
|
|
|
{ |
35
|
|
|
$accountCreator = new GetCaptcha(); |
36
|
|
|
$accountCreator->setAccessToken($accessToken_forId1); |
37
|
|
|
$captcha = $accountCreator->execute(); |
38
|
|
|
|
39
|
|
|
return array("image_url" => $captcha['image_url'], "key" => $captcha['key']); |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
function showCaptcha($accessToken_forId1) |
43
|
|
|
{ |
44
|
|
|
$accountCreator = new GetCaptcha(); |
45
|
|
|
$accountCreator->setAccessToken($accessToken_forId1); |
46
|
|
|
$captcha = $accountCreator->execute(); |
47
|
|
|
|
48
|
|
|
echo $captcha['image_url']; |
49
|
|
|
echo('<br><img width="100%" src="' . $captcha['image_url'] . '">'); |
50
|
|
|
echo "<br>Key: " . $captcha['key']; |
|
|
|
|
51
|
|
|
echo "<br>"; |
|
|
|
|
52
|
|
|
|
53
|
|
|
//Form |
54
|
|
|
|
55
|
|
|
echo '<form method="get">'; |
56
|
|
|
echo '<p>Enter Key (copy pasta from top): <input type="text" value="' . $captcha['key'] . '" name="key" /></p>'; |
57
|
|
|
echo '<p>Find the Coons (example: they are on picture 3, 4 and 5. You enter 2-3-4. Becouse we start counting at 0): <input type="text" name="solution" /></p>'; |
|
|
|
|
58
|
|
|
echo '<p><input type="submit" /></p>'; |
59
|
|
|
echo '</form>'; |
60
|
|
|
|
61
|
|
|
die(); |
|
|
|
|
62
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
function verifyCaptcha($accessToken_forId1) |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
$solution = $_GET['solution']; |
68
|
|
|
$solution = array_map('intval', explode('-', $solution)); |
69
|
|
|
|
70
|
|
|
$accountCreator = new PostCaptcha(); |
71
|
|
|
$accountCreator->setAccessToken($accessToken_forId1); |
72
|
|
|
$accountCreator->captchaKey = $_GET['key']; |
|
|
|
|
73
|
|
|
$accountCreator->captchaSolution = $solution; |
74
|
|
|
$verified = $accountCreator->execute(); |
|
|
|
|
75
|
|
|
|
76
|
|
|
return $verified['verified']; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
function setLocation($accessToken, $deviceUid) |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
$url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($_GET['city']) . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w'; |
|
|
|
|
82
|
|
|
$result = Requests::post($url); |
83
|
|
|
if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST') |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
return "0 results"; |
|
|
|
|
86
|
|
|
} |
87
|
|
|
else |
88
|
|
|
{ |
89
|
|
|
$name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name']; |
90
|
|
|
$lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat']; |
|
|
|
|
91
|
|
|
$lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng']; |
|
|
|
|
92
|
|
|
|
93
|
|
|
$location = new Location(); |
94
|
|
|
$location->setLat($lat); |
95
|
|
|
$location->setLng($lng); |
96
|
|
|
$location->setCityName($name); |
97
|
|
|
$accountCreator = new UpdateLocation(); |
98
|
|
|
$accountCreator->setLocation($location); |
99
|
|
|
$accountCreator->setAccessToken($accessToken); |
100
|
|
|
$data = $accountCreator->execute(); |
101
|
|
|
|
102
|
|
|
//safe location to db |
103
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
104
|
|
|
|
105
|
|
|
if($data == 'Success') |
106
|
|
|
{ |
107
|
|
|
$result = $db->query("UPDATE accounts |
108
|
|
|
SET name='" . $name . "', |
109
|
|
|
lat='" . $lat . "', |
110
|
|
|
lng='" . $lng . "' |
111
|
|
|
WHERE access_token='" . $accessToken . "'"); |
112
|
|
|
|
113
|
|
|
if($result === false) |
114
|
|
|
{ |
115
|
|
|
echo "Updating location failed: (" . $db->errno . ") " . $db->error; |
|
|
|
|
116
|
|
|
} |
117
|
|
|
else |
118
|
|
|
{ |
119
|
|
|
error_log('User with JodelDeviceId:' . $deviceUid . ' [' . $_SERVER['REMOTE_ADDR'] . '][' . $_SERVER ['HTTP_USER_AGENT'] . '] changed to Location: ' . $name); |
|
|
|
|
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return $name; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
function votePostId($deviceUid_forId1, $accessToken_forId1) |
|
|
|
|
128
|
|
|
{ |
129
|
|
|
if(!isAccountVerified($accessToken_forId1)) |
130
|
|
|
{ |
131
|
|
|
showCaptcha($accessToken_forId1); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
if(!deviceUidHasVotedThisPostId($deviceUid_forId1, $_GET['postID'])) |
135
|
|
|
{ |
136
|
|
View Code Duplication |
if($_GET['vote'] == "up") |
|
|
|
|
137
|
|
|
{ |
138
|
|
|
$accountCreator = new Upvote(); |
139
|
|
|
} |
140
|
|
|
else if($_GET['vote'] == "down") |
|
|
|
|
141
|
|
|
{ |
142
|
|
|
$accountCreator = new Downvote(); |
143
|
|
|
} |
144
|
|
|
$accountCreator->setAccessToken($accessToken_forId1); |
|
|
|
|
145
|
|
|
$accountCreator->postId = htmlspecialchars($_GET['postID']); |
146
|
|
|
$data = $accountCreator->execute(); |
|
|
|
|
147
|
|
|
|
148
|
|
|
|
149
|
|
|
addVoteWithPostIdAndTypeToDeviceUid($_GET['postID'], $_GET['vote'], $deviceUid_forId1); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
if(isset($_GET['getPostDetails']) && isset($_GET['getPostDetails'])) |
154
|
|
|
{ |
155
|
|
|
header('Location: index.php?getPostDetails=true&postID=' . htmlspecialchars($_GET['postID_parent']) . '#postId-' . htmlspecialchars($_GET['postID'])); |
|
|
|
|
156
|
|
|
} |
157
|
|
|
else |
158
|
|
|
{ |
159
|
|
|
header("Location: index.php#postId-" . htmlspecialchars($_GET['postID'])); |
|
|
|
|
160
|
|
|
} |
161
|
|
|
die(); |
|
|
|
|
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
function sendJodel($location, $accessToken_forId1) |
|
|
|
|
165
|
|
|
{ |
166
|
|
|
if(!isAccountVerified($accessToken_forId1)) |
167
|
|
|
{ |
168
|
|
|
showCaptcha($accessToken_forId1); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
$accountCreator = new SendJodel(); |
172
|
|
|
|
173
|
|
|
if(isset($_POST['ancestor'])) |
174
|
|
|
{ |
175
|
|
|
$ancestor = $_POST['ancestor']; |
|
|
|
|
176
|
|
|
$accountCreator->ancestor = $ancestor; |
177
|
|
|
} |
178
|
|
|
if(isset($_POST['color'])) |
179
|
|
|
{ |
180
|
|
|
$color = $_POST['color']; |
181
|
|
|
switch ($color) { |
182
|
|
|
case '8ABDB0': |
183
|
|
|
$color = '8ABDB0'; |
184
|
|
|
break; |
185
|
|
|
case '9EC41C': |
186
|
|
|
$color = '9EC41C'; |
187
|
|
|
break; |
188
|
|
|
case '06A3CB': |
189
|
|
|
$color = '06A3CB'; |
190
|
|
|
break; |
191
|
|
|
case 'FFBA00': |
192
|
|
|
$color = 'FFBA00'; |
193
|
|
|
break; |
194
|
|
|
case 'DD5F5F': |
195
|
|
|
$color = 'DD5F5F'; |
196
|
|
|
break; |
197
|
|
|
case 'FF9908': |
198
|
|
|
$color = 'FF9908'; |
199
|
|
|
break; |
200
|
|
|
default: |
201
|
|
|
$color = '8ABDB0'; |
202
|
|
|
break; |
203
|
|
|
} |
204
|
|
|
$accountCreator->color = $color; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
$accountCreatorLocation = new UpdateLocation(); |
|
|
|
|
208
|
|
|
$accountCreatorLocation->setLocation($location); |
209
|
|
|
$accountCreatorLocation->setAccessToken($accessToken_forId1); |
210
|
|
|
$data = $accountCreatorLocation->execute(); |
|
|
|
|
211
|
|
|
|
212
|
|
|
$accountCreator->location = $location; |
213
|
|
|
|
214
|
|
|
$accountCreator->setAccessToken($accessToken_forId1); |
215
|
|
|
$data = $accountCreator->execute(); |
216
|
|
|
|
217
|
|
|
if(isset($_POST['ancestor'])) |
218
|
|
|
{ |
219
|
|
|
$actual_link = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
220
|
|
|
header('Location: ' . $actual_link . '#postId-' . htmlspecialchars($data['post_id'])); |
221
|
|
|
exit; |
|
|
|
|
222
|
|
|
} |
223
|
|
|
else |
224
|
|
|
{ |
225
|
|
|
header('Location: ./#'); |
226
|
|
|
exit; |
|
|
|
|
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
function isDeviceUidInDatabase($deviceUid) |
231
|
|
|
{ |
232
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
233
|
|
|
$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid . "'"); |
234
|
|
|
|
235
|
|
|
if ($result->num_rows > 0) |
|
|
|
|
236
|
|
|
{ |
237
|
|
|
return TRUE; |
238
|
|
|
} |
239
|
|
|
else |
240
|
|
|
{ |
241
|
|
|
return FALSE; |
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
|
245
|
|
View Code Duplication |
function isTokenFresh(Location $location) |
|
|
|
|
246
|
|
|
{ |
247
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
248
|
|
|
$result = $db->query("SELECT * FROM accounts WHERE id='1'"); |
249
|
|
|
|
250
|
|
|
$access_token; |
|
|
|
|
251
|
|
|
|
252
|
|
|
if ($result->num_rows > 0) |
253
|
|
|
{ |
254
|
|
|
// output data of each row |
255
|
|
|
while($row = $result->fetch_assoc()) { |
256
|
|
|
//$access_token = $row["access_token"]; |
|
|
|
|
257
|
|
|
$expiration_date = $row["expiration_date"]; |
|
|
|
|
258
|
|
|
$deviceUid = $row["device_uid"]; |
|
|
|
|
259
|
|
|
$access_token = $row["access_token"]; |
|
|
|
|
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
else |
263
|
|
|
{ |
264
|
|
|
echo '0 results'; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
if($expiration_date <= time()) { |
|
|
|
|
268
|
|
|
$accountCreator = new CreateUser(); |
269
|
|
|
$accountCreator->setAccessToken($access_token);//$accountData->getAccessToken()); |
|
|
|
|
270
|
|
|
$accountCreator->setDeviceUid($deviceUid); |
|
|
|
|
271
|
|
|
$accountCreator->setLocation($location); |
272
|
|
|
$data = $accountCreator->execute(); |
273
|
|
|
|
274
|
|
|
$access_token = (string)$data[0]['access_token']; |
|
|
|
|
275
|
|
|
$expiration_date = $data[0]['expiration_date']; |
276
|
|
|
$device_uid = (string)$data[1]; |
|
|
|
|
277
|
|
|
|
278
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
279
|
|
|
$result = $db->query("UPDATE accounts |
280
|
|
|
SET access_token='" . $access_token . "', |
281
|
|
|
expiration_date='" . $expiration_date . "' |
282
|
|
|
WHERE device_uid='" . $device_uid . "'"); |
283
|
|
|
|
284
|
|
|
if($result === false){ |
285
|
|
|
echo "Adding account failed: (" . $db->errno . ") " . $db->error; |
|
|
|
|
286
|
|
|
} |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
return $access_token; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
View Code Duplication |
function isTokenFreshByAccessToken(Location $location, $accessToken) |
|
|
|
|
293
|
|
|
{ |
294
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
295
|
|
|
$result = $db->query("SELECT * FROM accounts WHERE access_token='" . $accessToken . "'"); |
296
|
|
|
|
297
|
|
|
if ($result->num_rows > 0) |
298
|
|
|
{ |
299
|
|
|
// output data of each row |
300
|
|
|
while($row = $result->fetch_assoc()) { |
301
|
|
|
//$access_token = $row["access_token"]; |
|
|
|
|
302
|
|
|
$expiration_date = $row["expiration_date"]; |
|
|
|
|
303
|
|
|
$deviceUid = $row["device_uid"]; |
|
|
|
|
304
|
|
|
$access_token = $row["access_token"]; |
|
|
|
|
305
|
|
|
} |
306
|
|
|
} |
307
|
|
|
else |
308
|
|
|
{ |
309
|
|
|
echo '0 results'; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
if($expiration_date <= time()) { |
|
|
|
|
313
|
|
|
$accountCreator = new CreateUser(); |
314
|
|
|
$accountCreator->setAccessToken($access_token);//$accountData->getAccessToken()); |
|
|
|
|
315
|
|
|
$accountCreator->setDeviceUid($deviceUid); |
|
|
|
|
316
|
|
|
$accountCreator->setLocation($location); |
317
|
|
|
$data = $accountCreator->execute(); |
318
|
|
|
|
319
|
|
|
$access_token = (string)$data[0]['access_token']; |
|
|
|
|
320
|
|
|
$expiration_date = $data[0]['expiration_date']; |
321
|
|
|
$device_uid = (string)$data[1]; |
|
|
|
|
322
|
|
|
|
323
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
324
|
|
|
$result = $db->query("UPDATE accounts |
325
|
|
|
SET access_token='" . $access_token . "', |
326
|
|
|
expiration_date='" . $expiration_date . "' |
327
|
|
|
WHERE device_uid='" . $device_uid . "'"); |
328
|
|
|
|
329
|
|
|
if($result === false){ |
330
|
|
|
echo "Adding account failed: (" . $db->errno . ") " . $db->error; |
|
|
|
|
331
|
|
|
} |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
return $access_token; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
View Code Duplication |
function isTokenFreshByDeviceUid(Location $location, $deviceUid) |
|
|
|
|
338
|
|
|
{ |
339
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
340
|
|
|
$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid . "'"); |
341
|
|
|
|
342
|
|
|
$access_token; |
|
|
|
|
343
|
|
|
|
344
|
|
|
if ($result->num_rows > 0) |
345
|
|
|
{ |
346
|
|
|
// output data of each row |
347
|
|
|
while($row = $result->fetch_assoc()) { |
348
|
|
|
//$access_token = $row["access_token"]; |
|
|
|
|
349
|
|
|
$expiration_date = $row["expiration_date"]; |
|
|
|
|
350
|
|
|
$deviceUid = $row["device_uid"]; |
|
|
|
|
351
|
|
|
$access_token = $row["access_token"]; |
|
|
|
|
352
|
|
|
} |
353
|
|
|
} |
354
|
|
|
else |
355
|
|
|
{ |
356
|
|
|
echo '0 results'; |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
if($expiration_date <= time()) { |
|
|
|
|
360
|
|
|
$accountCreator = new CreateUser(); |
361
|
|
|
$accountCreator->setAccessToken($access_token); |
|
|
|
|
362
|
|
|
$accountCreator->setDeviceUid($deviceUid); |
363
|
|
|
$accountCreator->setLocation($location); |
364
|
|
|
$data = $accountCreator->execute(); |
365
|
|
|
|
366
|
|
|
$access_token = (string)$data[0]['access_token']; |
|
|
|
|
367
|
|
|
$expiration_date = $data[0]['expiration_date']; |
368
|
|
|
$device_uid = (string)$data[1]; |
|
|
|
|
369
|
|
|
|
370
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
371
|
|
|
$result = $db->query("UPDATE accounts |
372
|
|
|
SET access_token='" . $access_token . "', |
373
|
|
|
expiration_date='" . $expiration_date . "' |
374
|
|
|
WHERE device_uid='" . $device_uid . "'"); |
375
|
|
|
|
376
|
|
|
if($result === false){ |
377
|
|
|
echo "Adding account failed: (" . $db->errno . ") " . $db->error; |
|
|
|
|
378
|
|
|
} |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
return $access_token; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
View Code Duplication |
function getLocationByAccessToken($accessToken) |
|
|
|
|
385
|
|
|
{ |
386
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
387
|
|
|
$result = $db->query("SELECT * FROM accounts WHERE access_token='" . $accessToken . "'"); |
388
|
|
|
|
389
|
|
|
$location = new Location(); |
390
|
|
|
|
391
|
|
|
if ($result->num_rows > 0) |
392
|
|
|
{ |
393
|
|
|
// output data of each row |
394
|
|
|
while($row = $result->fetch_assoc()) |
395
|
|
|
{ |
396
|
|
|
$location->setLat($row['lat']); |
397
|
|
|
$location->setLng($row['lng']); |
398
|
|
|
$location->setCityName($row['name']); |
399
|
|
|
} |
400
|
|
|
} |
401
|
|
|
else |
402
|
|
|
{ |
403
|
|
|
echo "Error: 0 results"; |
|
|
|
|
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
return $location; |
407
|
|
|
} |
408
|
|
|
|
409
|
|
View Code Duplication |
function getLocationByDeviceUid($deviceUid) |
|
|
|
|
410
|
|
|
{ |
411
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
412
|
|
|
$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid . "'"); |
413
|
|
|
|
414
|
|
|
$location = new Location(); |
415
|
|
|
|
416
|
|
|
if ($result->num_rows > 0) |
417
|
|
|
{ |
418
|
|
|
// output data of each row |
419
|
|
|
while($row = $result->fetch_assoc()) |
420
|
|
|
{ |
421
|
|
|
$location->setLat($row['lat']); |
422
|
|
|
$location->setLng($row['lng']); |
423
|
|
|
$location->setCityName($row['name']); |
424
|
|
|
} |
425
|
|
|
} |
426
|
|
|
else |
427
|
|
|
{ |
428
|
|
|
echo "Error: 0 results"; |
|
|
|
|
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
return $location; |
432
|
|
|
} |
433
|
|
|
|
434
|
|
View Code Duplication |
function getDeviceUidByAccessToken($accesstoken) |
|
|
|
|
435
|
|
|
{ |
436
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
437
|
|
|
$result = $db->query("SELECT device_uid FROM accounts WHERE access_token='" . $accesstoken . "'"); |
438
|
|
|
|
439
|
|
|
$deviceUid; |
|
|
|
|
440
|
|
|
|
441
|
|
|
if ($result->num_rows > 0) |
442
|
|
|
{ |
443
|
|
|
// output data of each row |
444
|
|
|
while($row = $result->fetch_assoc()) |
445
|
|
|
{ |
446
|
|
|
$deviceUid = $row['device_uid']; |
447
|
|
|
} |
448
|
|
|
} |
449
|
|
|
else |
450
|
|
|
{ |
451
|
|
|
echo "Error: 0 results"; |
|
|
|
|
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
return $deviceUid; |
|
|
|
|
455
|
|
|
} |
456
|
|
|
|
457
|
|
View Code Duplication |
function getAccessTokenByDeviceUid($deviceUid) |
|
|
|
|
458
|
|
|
{ |
459
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
460
|
|
|
$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid . "'"); |
461
|
|
|
|
462
|
|
|
$accessToken; |
|
|
|
|
463
|
|
|
|
464
|
|
|
if ($result->num_rows > 0) |
465
|
|
|
{ |
466
|
|
|
// output data of each row |
467
|
|
|
while($row = $result->fetch_assoc()) |
468
|
|
|
{ |
469
|
|
|
$accessToken = $row['access_token']; |
470
|
|
|
} |
471
|
|
|
} |
472
|
|
|
else |
473
|
|
|
{ |
474
|
|
|
echo "Error: 0 results"; |
|
|
|
|
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
return $accessToken; |
|
|
|
|
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
|
481
|
|
|
function getKarma($accessToken) |
|
|
|
|
482
|
|
|
{ |
483
|
|
|
$accountCreator = new GetKarma(); |
484
|
|
|
$accountCreator->setAccessToken($accessToken); |
485
|
|
|
$data = $accountCreator->execute(); |
486
|
|
|
|
487
|
|
|
return $data["karma"]; |
|
|
|
|
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
function deviceUidHasVotedThisPostId($deviceUid, $postId) |
491
|
|
|
{ |
492
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
493
|
|
|
|
494
|
|
|
$postId = $db->real_escape_string($postId); |
|
|
|
|
495
|
|
|
|
496
|
|
|
$result = $db->query("SELECT id |
497
|
|
|
FROM votes |
498
|
|
|
WHERE (postId = '" . $postId . "' AND device_uid = '" . $deviceUid . "')"); |
499
|
|
|
|
500
|
|
View Code Duplication |
if($result === false) |
|
|
|
|
501
|
|
|
{ |
502
|
|
|
$error = db_error(); |
503
|
|
|
echo $error; |
504
|
|
|
echo "Adding Vote failed: (" . $result->errno . ") " . $result->error; |
|
|
|
|
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
if($result->num_rows == 0) |
|
|
|
|
508
|
|
|
{ |
509
|
|
|
return FALSE; |
510
|
|
|
} |
511
|
|
|
else |
512
|
|
|
{ |
513
|
|
|
return TRUE; |
514
|
|
|
} |
515
|
|
|
} |
516
|
|
|
|
517
|
|
|
function addVoteWithPostIdAndTypeToDeviceUid($postId, $voteType, $device_uid) |
518
|
|
|
{ |
519
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
520
|
|
|
|
521
|
|
|
$postId = $db->real_escape_string($postId); |
|
|
|
|
522
|
|
|
$voteType = $db->real_escape_string($voteType); |
|
|
|
|
523
|
|
|
|
524
|
|
|
if(deviceUidHasVotedThisPostId($device_uid, $postId)) |
525
|
|
|
{ |
526
|
|
|
return "Already voted"; |
|
|
|
|
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
$result = $db->query("INSERT INTO votes (device_uid, postId, type) |
530
|
|
|
VALUES ('" . $device_uid . "','" . $postId . "','" . $voteType . "')"); |
531
|
|
|
|
532
|
|
View Code Duplication |
if($result === false){ |
|
|
|
|
533
|
|
|
$error = db_error(); |
534
|
|
|
echo $error; |
535
|
|
|
echo "Adding Vote failed: (" . $result->errno . ") " . $result->error; |
|
|
|
|
536
|
|
|
} |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
function registerAccount(Location $location) { |
540
|
|
|
$accountCreator = new CreateUser(); |
541
|
|
|
$accountCreator->setLocation($location); |
542
|
|
|
$data = $accountCreator->execute(); |
543
|
|
|
|
544
|
|
|
$access_token = (string)$data[0]['access_token']; |
|
|
|
|
545
|
|
|
$refresh_token = (string)$data[0]['refresh_token']; |
|
|
|
|
546
|
|
|
$token_type = (string)$data[0]['token_type']; |
|
|
|
|
547
|
|
|
$expires_in = $data[0]['expires_in']; |
|
|
|
|
548
|
|
|
$expiration_date = $data[0]['expiration_date']; |
549
|
|
|
$distinct_id = (string)$data[0]['distinct_id']; |
|
|
|
|
550
|
|
|
$device_uid = (string)$data[1]; |
|
|
|
|
551
|
|
|
|
552
|
|
|
$name = $location->cityName; |
553
|
|
|
$lat = $location->lat; |
|
|
|
|
554
|
|
|
$lng = $location->lng; |
|
|
|
|
555
|
|
|
|
556
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
557
|
|
|
$result = $db->query("INSERT INTO accounts (access_token, refresh_token, token_type, |
558
|
|
|
expires_in, expiration_date, distinct_id, device_uid, name, lat, lng) |
559
|
|
|
VALUES ('" . $access_token . "','" . $refresh_token . "','" . $token_type . |
560
|
|
|
"','" . $expires_in . "','" . $expiration_date . "','" . $distinct_id . |
561
|
|
|
"','" . $device_uid . "','" . $name . "','" . $lat . "','" . $lng . "') "); |
562
|
|
|
|
563
|
|
|
$success = TRUE; |
|
|
|
|
564
|
|
View Code Duplication |
if($result === false){ |
|
|
|
|
565
|
|
|
$error = db_error(); |
566
|
|
|
echo $error; |
567
|
|
|
echo "Adding account failed: (" . $result->errno . ") " . $result->error; |
|
|
|
|
568
|
|
|
$success = FALSE; |
|
|
|
|
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
return $device_uid; |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
function getPosts($lastPostId, $accessToken, $url, $version = 'v2') |
575
|
|
|
{ |
576
|
|
|
$accountCreator = new GetPosts(); |
577
|
|
|
$accountCreator->setLastPostId($lastPostId); |
578
|
|
|
$accountCreator->setAccessToken($accessToken); |
579
|
|
|
$accountCreator->setUrl($url); |
580
|
|
|
$accountCreator->version = $version; |
581
|
|
|
|
582
|
|
|
$config = parse_ini_file('config/config.ini.php'); |
|
|
|
|
583
|
|
|
$location = new Location(); |
584
|
|
|
$location->setLat($config['default_lat']); |
585
|
|
|
$location->setLng($config['default_lng']); |
586
|
|
|
$location->setCityName($config['default_location']); |
587
|
|
|
$accountCreator->location = $location; |
588
|
|
|
$data = $accountCreator->execute(); |
|
|
|
|
589
|
|
|
|
590
|
|
|
return $data; |
591
|
|
|
} |
592
|
|
|
|
593
|
|
|
function createAccount() |
594
|
|
|
{ |
595
|
|
|
$config = parse_ini_file('config/config.ini.php'); |
|
|
|
|
596
|
|
|
$location = new Location(); |
597
|
|
|
$location->setLat($config['default_lat']); |
598
|
|
|
$location->setLng($config['default_lng']); |
599
|
|
|
$location->setCityName($config['default_location']); |
600
|
|
|
|
601
|
|
|
$device_uid = registerAccount($location); |
602
|
|
|
|
603
|
|
|
return $device_uid; |
604
|
|
|
} |
605
|
|
|
|
606
|
|
|
function isUserBot() |
|
|
|
|
607
|
|
|
{ |
608
|
|
|
preg_match('/bot|spider|google|twitter/i', $_SERVER['HTTP_USER_AGENT'], $matches); |
609
|
|
|
|
610
|
|
|
return (isset($matches[0])) ? true : false; |
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
function botDeviceUidIsSet($config) |
614
|
|
|
{ |
615
|
|
|
if(!array_key_exists('botDeviceUid', $config) || !isset($config['botDeviceUid']) || $config['botDeviceUid'] == '' || $config['botDeviceUid'] == 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') |
|
|
|
|
616
|
|
|
{ |
617
|
|
|
return FALSE; |
618
|
|
|
} |
619
|
|
|
else |
620
|
|
|
{ |
621
|
|
|
return TRUE; |
622
|
|
|
} |
623
|
|
|
} |
624
|
|
|
|
625
|
|
|
/** |
626
|
|
|
* Compute HTML Code |
627
|
|
|
*/ |
628
|
|
|
|
629
|
|
|
/** |
630
|
|
|
* Gets the title. |
631
|
|
|
* |
632
|
|
|
* @return string The title. |
633
|
|
|
*/ |
634
|
|
|
function getTitle($post, $view = 'time', $isDetailedView = FALSE) |
|
|
|
|
635
|
|
|
{ |
636
|
|
|
$title = 'JodelBlue - Web-App and Browser-Client'; |
637
|
|
|
|
638
|
|
|
if($isDetailedView) |
639
|
|
|
{ |
640
|
|
|
$title = 'JodelBlue: ' . substr(htmlspecialchars($post['message']), 0, 44); |
641
|
|
|
} |
642
|
|
|
|
643
|
|
|
return $title; |
644
|
|
|
} |
645
|
|
|
|
646
|
|
|
/** |
647
|
|
|
* Gets the meta description. |
648
|
|
|
* |
649
|
|
|
* @return string The meta description. |
650
|
|
|
*/ |
651
|
|
|
function getMetaDescription($post, $view = 'time', $isDetailedView = FALSE) |
|
|
|
|
652
|
|
|
{ |
653
|
|
|
$description = 'JodelBlue is a Web-App and Browser-Client for the Jodel App. No registration required! Browse Jodels all over the world. Send your own Jodels or upvote others.'; |
|
|
|
|
654
|
|
|
|
655
|
|
|
if($isDetailedView) |
656
|
|
|
{ |
657
|
|
|
$description = 'On JodelBlue with ' . htmlspecialchars($post['vote_count']) . ' Upvotes: ' . substr(htmlspecialchars($post['message']), 0, 140); |
|
|
|
|
658
|
|
|
} |
659
|
|
|
|
660
|
|
|
return $description; |
661
|
|
|
} |
662
|
|
|
|
663
|
|
|
function jodelToHtml($post, $view = 'time', $isDetailedView = FALSE) |
|
|
|
|
664
|
|
|
{ //ToDO |
|
|
|
|
665
|
|
|
//Replace # with link |
666
|
|
|
//preg_replace('~(\#)([^\s!,. /()"\'?]+)~', '<a href="tag/$2">#$2</a>', $text); |
|
|
|
|
667
|
|
|
|
668
|
|
|
//Time to time difference |
669
|
|
|
$now = new DateTime(); |
|
|
|
|
670
|
|
|
$d = new DateTime($post['created_at']); |
|
|
|
|
671
|
|
|
$timediff = $now->diff($d); |
672
|
|
|
|
673
|
|
|
$timediff_inSeconds = (string)$timediff->format('%s'); |
674
|
|
|
$timediff_inMinutes = (string)$timediff->format('%i'); |
675
|
|
|
$timediff_inHours = (string)$timediff->format('%h'); |
|
|
|
|
676
|
|
|
$timediff_inDays = (string)$timediff->format('%d'); |
|
|
|
|
677
|
|
|
$timediff_inMonth = (string)$timediff->format('%m'); |
|
|
|
|
678
|
|
|
|
679
|
|
|
if($timediff_inMonth!=0) |
680
|
|
|
{ |
681
|
|
|
$timediff = $timediff_inMonth . "m"; |
|
|
|
|
682
|
|
|
} |
683
|
|
|
else |
684
|
|
|
{ |
685
|
|
|
if($timediff_inDays!=0) |
686
|
|
|
{ |
687
|
|
|
$timediff = $timediff_inDays . "d"; |
|
|
|
|
688
|
|
|
} |
689
|
|
|
else |
690
|
|
|
{ |
691
|
|
|
if($timediff_inHours!=0) |
692
|
|
|
{ |
693
|
|
|
$timediff = $timediff_inHours . "h"; |
|
|
|
|
694
|
|
|
} |
695
|
|
|
else |
696
|
|
|
{ |
697
|
|
|
if($timediff_inMinutes!=0) |
698
|
|
|
{ |
699
|
|
|
$timediff = $timediff_inMinutes . "m"; |
|
|
|
|
700
|
|
|
} |
701
|
|
|
else |
702
|
|
|
{ |
703
|
|
|
$timediff = $timediff_inSeconds . "s"; |
|
|
|
|
704
|
|
|
} |
705
|
|
|
} |
706
|
|
|
} |
707
|
|
|
} |
708
|
|
|
|
709
|
|
|
|
710
|
|
|
?> |
711
|
|
|
<article id ="postId-<?php echo $post['post_id']; ?>" class="jodel" style="background-color: #<?php echo $post['color'];?>;"> |
|
|
|
|
712
|
|
|
<content> |
713
|
|
|
<?php |
714
|
|
|
if(isset($post['image_url'])) |
715
|
|
|
{ |
716
|
|
|
$regexRest = '/[^\w$ .!?-]+/u'; |
717
|
|
|
|
718
|
|
|
echo '<img src="' . $post['image_url'] . '" alt="' . htmlspecialchars(preg_replace($regexRest, '', $post['message'])) . '">'; |
|
|
|
|
719
|
|
|
} |
720
|
|
|
else { |
721
|
|
|
echo str_replace(' ', ' ', nl2br(htmlspecialchars($post['message']))); |
722
|
|
|
} |
723
|
|
|
?> |
724
|
|
|
</content> |
725
|
|
|
<aside> |
726
|
|
|
<?php |
727
|
|
View Code Duplication |
if($isDetailedView) |
|
|
|
|
728
|
|
|
{?> |
729
|
|
|
<a href="index.php?vote=up&getPostDetails=true&postID=<?php echo $post['post_id'];?>&postID_parent=<?php echo htmlspecialchars($_GET['postID']);?>" rel="nofollow"> |
|
|
|
|
730
|
|
|
<?php } |
731
|
|
|
else |
732
|
|
|
{?> |
733
|
|
|
<a href="index.php?vote=up&postID=<?php echo $post['post_id'];?>" rel="nofollow"> |
734
|
|
|
<?php } ?> |
735
|
|
|
<i class="fa fa-angle-up fa-3x"></i> |
736
|
|
|
</a> |
737
|
|
|
<br /> |
738
|
|
|
<?php echo $post["vote_count"];?><br /> |
|
|
|
|
739
|
|
|
<?php |
740
|
|
View Code Duplication |
if($isDetailedView) |
|
|
|
|
741
|
|
|
{?> |
742
|
|
|
<a href="index.php?vote=down&getPostDetails=true&postID=<?php echo $post['post_id'];?>&postID_parent=<?php echo htmlspecialchars($_GET['postID']);?>" rel="nofollow"> |
|
|
|
|
743
|
|
|
<?php } |
744
|
|
|
else |
745
|
|
|
{?> |
746
|
|
|
<a href="index.php?vote=down&postID=<?php echo $post['post_id'];?>" rel="nofollow"> |
747
|
|
|
<?php } ?> |
748
|
|
|
<i class="fa fa-angle-down fa-3x"></i> |
749
|
|
|
</a> |
750
|
|
|
</aside> |
751
|
|
|
|
752
|
|
|
<footer> |
753
|
|
|
<table> |
754
|
|
|
<tr> |
755
|
|
|
<td class="time"> |
756
|
|
|
<span class="tip" data-tooltip="Time"> |
757
|
|
|
<i class="fa fa-clock-o"></i> |
758
|
|
|
<?php echo $timediff;?> |
759
|
|
|
<span class="tiptext"><?php echo $d->format('Y-m-d H:i:s');?></span> |
760
|
|
|
</span> |
761
|
|
|
</td> |
762
|
|
|
<td class="comments"> |
763
|
|
|
<?php if(!$isDetailedView) {?> |
764
|
|
|
<span data-tooltip="Comments"> |
765
|
|
|
<a href="index.php?getPostDetails=true&view=<?php echo $view;?>&postID=<?php echo $post["post_id"];?>"> |
|
|
|
|
766
|
|
|
<i class="fa fa-commenting-o"></i> |
767
|
|
|
<?php if(array_key_exists("child_count", $post)) { |
|
|
|
|
768
|
|
|
echo $post["child_count"]; |
|
|
|
|
769
|
|
|
} else echo "0"; |
|
|
|
|
770
|
|
|
?> |
771
|
|
|
</a> |
772
|
|
|
</span> |
773
|
|
|
<?php } ?> |
774
|
|
|
</td> |
775
|
|
|
<td class="distance"> |
776
|
|
|
<?php |
777
|
|
|
if($isDetailedView) |
778
|
|
|
{ |
779
|
|
|
if(isset($post["parent_creator"]) && $post["parent_creator"] == 1) |
|
|
|
|
780
|
|
|
{ |
781
|
|
|
?> |
782
|
|
|
<span data-tooltip="Author"> |
783
|
|
|
<i class="fa fa-user-o"></i> OJ | |
784
|
|
|
</span> |
785
|
|
|
<?php |
786
|
|
|
} |
787
|
|
|
else |
788
|
|
|
{ |
789
|
|
|
//Is not parent Jodel in detailed View |
790
|
|
|
if(!array_key_exists('child_count', $post) && array_key_exists('parent_creator', $post)) |
791
|
|
|
{ |
792
|
|
|
?> |
793
|
|
|
<span data-tooltip="Author"> |
794
|
|
|
<i class="fa fa-user-o"></i> #<?php echo $post["user_handle"];?> | |
|
|
|
|
795
|
|
|
</span> |
796
|
|
|
<?php |
797
|
|
|
} |
798
|
|
|
} |
799
|
|
|
} |
800
|
|
|
?> |
801
|
|
|
|
802
|
|
|
<span class="tip" data-tooltip="Distance"> |
803
|
|
|
<i class="fa fa-map-marker"></i> |
804
|
|
|
<?php echo $post['distance'];?> km |
805
|
|
|
<span class="tiptext"><?php echo $post['location']['name'];?></span> |
806
|
|
|
</span> |
807
|
|
|
</td> |
808
|
|
|
</tr> |
809
|
|
|
</table> |
810
|
|
|
</footer> |
811
|
|
|
</article> |
812
|
|
|
<?php |
813
|
|
|
} |
|
|
|
|
814
|
|
|
|
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.