|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class JodelAccount |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
public $accessToken; |
|
6
|
|
|
public $expirationDate; |
|
7
|
|
|
public $refreshToken; |
|
8
|
|
|
public $distinctId; |
|
9
|
|
|
public $deviceUid; |
|
10
|
|
|
|
|
11
|
|
|
//is the Account a Bot or Spider? |
|
12
|
|
|
public $isBot; |
|
13
|
|
|
|
|
14
|
|
|
// array of voted Jodels |
|
15
|
|
|
public $votes; |
|
16
|
|
|
|
|
17
|
|
|
//Location of the Account |
|
18
|
|
|
public $location; |
|
19
|
|
|
|
|
20
|
|
|
function __construct($deviceUid = NULL, $isBot = FALSE) |
|
|
|
|
|
|
21
|
|
|
{ |
|
22
|
|
|
if($deviceUid == NULL) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->deviceUid = $this->createAccount(); |
|
25
|
|
|
} |
|
26
|
|
|
else |
|
27
|
|
|
{ |
|
28
|
|
|
$this->deviceUid = $deviceUid; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$this->isBot = $isBot; |
|
|
|
|
|
|
32
|
|
|
$this->location = $this->getLocation(); |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
if(!$this->isTokenFresh()) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->refreshToken(); |
|
37
|
|
|
} |
|
38
|
|
|
$this->accessToken = $this->getAccessToken(); |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
/* if($this->isAccountVerified() != 1) |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
$this->showCaptcha(); |
|
43
|
|
|
//$this->verifyCaptcha(); |
|
44
|
|
|
}*/ |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
function showCaptcha() |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
$accountCreator = new GetCaptcha(); |
|
50
|
|
|
$accountCreator->setAccessToken($this->accessToken); |
|
51
|
|
|
$captcha = $accountCreator->execute(); |
|
52
|
|
|
|
|
53
|
|
|
echo $captcha['image_url']; |
|
54
|
|
|
echo('<br><img width="100%" src="' . $captcha['image_url'] . '">'); |
|
55
|
|
|
echo "<br>Key: " . $captcha['key']; |
|
|
|
|
|
|
56
|
|
|
echo "<br>"; |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
//Form |
|
59
|
|
|
|
|
60
|
|
|
echo '<form method="get">'; |
|
61
|
|
|
echo '<p>Enter Key (copy pasta from top): <input type="text" value="' . $captcha['key'] . '" name="key" /></p>'; |
|
|
|
|
|
|
62
|
|
|
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>'; |
|
|
|
|
|
|
63
|
|
|
echo '<input type="hidden" name="deviceUid" value="' . $this->deviceUid . '">'; |
|
64
|
|
|
echo '<input type="hidden" name="pw" value="upVote">'; |
|
65
|
|
|
echo '<p><input type="submit" /></p>'; |
|
66
|
|
|
echo '</form>'; |
|
67
|
|
|
|
|
68
|
|
|
die(); |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
function getCaptcha() |
|
|
|
|
|
|
73
|
|
|
{ |
|
74
|
|
|
$accountCreator = new GetCaptcha(); |
|
75
|
|
|
$accountCreator->setAccessToken($this->accessToken); |
|
76
|
|
|
$captcha = $accountCreator->execute(); |
|
77
|
|
|
|
|
78
|
|
|
return array("image_url" => $captcha['image_url'], "key" => $captcha['key']); |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
function isAccountVerified() |
|
|
|
|
|
|
82
|
|
|
{ |
|
83
|
|
|
$accountCreator = new GetUserConfig(); |
|
84
|
|
|
$accountCreator->setAccessToken($this->accessToken); |
|
85
|
|
|
$data = $accountCreator->execute(); |
|
86
|
|
|
|
|
87
|
|
|
//error_log(print_r($data, true)); |
|
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
return $data['verified']; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
function locationEquals($city) |
|
|
|
|
|
|
93
|
|
|
{ |
|
94
|
|
|
$url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($city) . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w'; |
|
|
|
|
|
|
95
|
|
|
$result = Requests::post($url); |
|
96
|
|
|
if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST') |
|
|
|
|
|
|
97
|
|
|
{ |
|
98
|
|
|
error_log('Error locationEquals'); |
|
99
|
|
|
return FALSE; |
|
100
|
|
|
} |
|
101
|
|
|
else |
|
102
|
|
|
{ |
|
103
|
|
|
$name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name']; |
|
104
|
|
|
$lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat']; |
|
|
|
|
|
|
105
|
|
|
$lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng']; |
|
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
|
|
109
|
|
|
$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
110
|
|
|
|
|
111
|
|
|
$location = new Location(); |
|
112
|
|
|
|
|
113
|
|
View Code Duplication |
if ($result->num_rows > 0) |
|
|
|
|
|
|
114
|
|
|
{ |
|
115
|
|
|
// output data of each row |
|
116
|
|
|
while($row = $result->fetch_assoc()) |
|
117
|
|
|
{ |
|
118
|
|
|
$location->setLat($row['lat']); |
|
119
|
|
|
$location->setLng($row['lng']); |
|
120
|
|
|
$location->setCityName($row['name']); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
else |
|
124
|
|
|
{ |
|
125
|
|
|
error_log("Error no Location found - getLocation"); |
|
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
if($location->getLat() == $lat && $location->getLng() == $lng && $location->getCityName() == $name) |
|
|
|
|
|
|
129
|
|
|
{ |
|
130
|
|
|
return TRUE; |
|
131
|
|
|
} |
|
132
|
|
|
else |
|
133
|
|
|
{ |
|
134
|
|
|
return FALSE; |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
function setLocation() |
|
|
|
|
|
|
139
|
|
|
{ |
|
140
|
|
|
//Is Channel or City |
|
141
|
|
|
if(substr($_GET['city'], 0, 1) === '#') |
|
142
|
|
|
{ |
|
143
|
|
|
return htmlspecialchars($_GET['city']) . " " . $this->location->cityName; |
|
|
|
|
|
|
144
|
|
|
} |
|
145
|
|
|
else |
|
146
|
|
|
{ |
|
147
|
|
|
$url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($_GET['city']) . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w'; |
|
|
|
|
|
|
148
|
|
|
$result = Requests::post($url); |
|
149
|
|
|
if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST') |
|
|
|
|
|
|
150
|
|
|
{ |
|
151
|
|
|
return "0 results"; |
|
|
|
|
|
|
152
|
|
|
} |
|
153
|
|
|
else |
|
154
|
|
|
{ |
|
155
|
|
|
$name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name']; |
|
156
|
|
|
$lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat']; |
|
|
|
|
|
|
157
|
|
|
$lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng']; |
|
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
$location = new Location(); |
|
160
|
|
|
$location->setLat($lat); |
|
161
|
|
|
$location->setLng($lng); |
|
162
|
|
|
$location->setCityName($name); |
|
163
|
|
|
$accountCreator = new UpdateLocation(); |
|
164
|
|
|
$accountCreator->setLocation($location); |
|
165
|
|
|
$accountCreator->setAccessToken($this->accessToken); |
|
166
|
|
|
$data = $accountCreator->execute(); |
|
167
|
|
|
|
|
168
|
|
|
//safe location to db |
|
169
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
if($data == 'Success') |
|
172
|
|
|
{ |
|
173
|
|
|
$result = $db->query("UPDATE accounts |
|
174
|
|
|
SET name='" . $name . "', |
|
175
|
|
|
lat='" . $lat . "', |
|
176
|
|
|
lng='" . $lng . "' |
|
177
|
|
|
WHERE access_token='" . $this->accessToken . "'"); |
|
178
|
|
|
|
|
179
|
|
|
if($result === false) |
|
180
|
|
|
{ |
|
181
|
|
|
echo "Updating location failed: (" . $db->errno . ") " . $db->error; |
|
|
|
|
|
|
182
|
|
|
} |
|
183
|
|
|
else |
|
184
|
|
|
{ |
|
185
|
|
|
user_log('User with JodelDeviceId:' . $this->deviceUid . ' [' . $_SERVER['REMOTE_ADDR'] . '][' . $_SERVER ['HTTP_USER_AGENT'] . '] changed to Location: ' . $name); |
|
|
|
|
|
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
return $name; |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
function getLocation() |
|
|
|
|
|
|
195
|
|
|
{ |
|
196
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
|
|
197
|
|
|
$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
198
|
|
|
|
|
199
|
|
|
$location = new Location(); |
|
200
|
|
|
|
|
201
|
|
View Code Duplication |
if ($result->num_rows > 0) |
|
|
|
|
|
|
202
|
|
|
{ |
|
203
|
|
|
// output data of each row |
|
204
|
|
|
while($row = $result->fetch_assoc()) |
|
205
|
|
|
{ |
|
206
|
|
|
$location->setLat($row['lat']); |
|
207
|
|
|
$location->setLng($row['lng']); |
|
208
|
|
|
$location->setCityName($row['name']); |
|
209
|
|
|
} |
|
210
|
|
|
} |
|
211
|
|
|
else |
|
212
|
|
|
{ |
|
213
|
|
|
echo "Error: 0 results"; |
|
|
|
|
|
|
214
|
|
|
error_log("Error no Location found - getLocation"); |
|
|
|
|
|
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
return $location; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
function verifyCaptcha() |
|
|
|
|
|
|
221
|
|
|
{ |
|
222
|
|
|
if(isset($_GET['deviceUid'])) |
|
223
|
|
|
{ |
|
224
|
|
|
$deviceUid = $_GET['deviceUid']; |
|
|
|
|
|
|
225
|
|
|
$jodelAccountForVerify = new JodelAccount($deviceUid); |
|
|
|
|
|
|
226
|
|
|
} |
|
227
|
|
|
else if(isset($_POST['deviceUid'])) |
|
228
|
|
|
{ |
|
229
|
|
|
$deviceUid = $_POST['deviceUid']; |
|
|
|
|
|
|
230
|
|
|
$jodelAccountForVerify = new JodelAccount($deviceUid); |
|
231
|
|
|
} |
|
232
|
|
|
else |
|
233
|
|
|
{ |
|
234
|
|
|
$deviceUid = $this->deviceUid; |
|
|
|
|
|
|
235
|
|
|
$jodelAccountForVerify = $this; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
$solution = $_GET['solution']; |
|
239
|
|
|
$solution = array_map('intval', explode('-', $solution)); |
|
240
|
|
|
|
|
241
|
|
|
$accountCreator = new PostCaptcha(); |
|
242
|
|
|
$accountCreator->setAccessToken($jodelAccountForVerify->accessToken); |
|
243
|
|
|
$accountCreator->captchaKey = $_GET['key']; |
|
|
|
|
|
|
244
|
|
|
$accountCreator->captchaSolution = $solution; |
|
245
|
|
|
$verified = $accountCreator->execute(); |
|
|
|
|
|
|
246
|
|
|
|
|
247
|
|
|
if(isset($verified->status_code)) |
|
248
|
|
|
{ |
|
249
|
|
|
return $verified->status_code; |
|
250
|
|
|
} |
|
251
|
|
|
return $verified['verified']; |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
//ToDo Spider Check |
|
|
|
|
|
|
255
|
|
|
function votePostId($postId, $vote) |
|
|
|
|
|
|
256
|
|
|
{ |
|
257
|
|
|
if(!$this->isBot) |
|
258
|
|
|
{ |
|
259
|
|
|
if(!$this->isAccountVerified()) |
|
260
|
|
|
{ |
|
261
|
|
|
$view = new View(); |
|
|
|
|
|
|
262
|
|
|
$this->showCaptcha(); |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
if(!$this->hasVoted($postId)) |
|
266
|
|
|
{ |
|
267
|
|
|
if($vote == "up") |
|
|
|
|
|
|
268
|
|
|
{ |
|
269
|
|
|
$accountCreator = new Upvote(); |
|
270
|
|
|
} |
|
271
|
|
|
else if($vote == "down") |
|
|
|
|
|
|
272
|
|
|
{ |
|
273
|
|
|
$accountCreator = new Downvote(); |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
$accountCreator->setAccessToken($this->accessToken); |
|
|
|
|
|
|
277
|
|
|
$accountCreator->postId = htmlspecialchars($postId); |
|
278
|
|
|
$data = $accountCreator->execute(); |
|
|
|
|
|
|
279
|
|
|
|
|
280
|
|
|
error_log('Could not vote: ' . print_r($data, true)); |
|
281
|
|
|
|
|
282
|
|
|
if(array_key_exists('post', $data)) |
|
283
|
|
|
{ |
|
284
|
|
|
$this->addVoteWithPostIdAndType($postId, $vote); |
|
285
|
|
|
return TRUE; |
|
286
|
|
|
} |
|
287
|
|
|
else if(array_key_exists('error', $data)) |
|
288
|
|
|
{ |
|
289
|
|
|
error_log('Could not vote - Error: ' . $data['error']); |
|
290
|
|
|
} |
|
291
|
|
|
else |
|
292
|
|
|
{ |
|
293
|
|
|
error_log('Could not vote: ' . print_r($data, true)); |
|
294
|
|
|
return FALSE; |
|
295
|
|
|
} |
|
296
|
|
|
} |
|
297
|
|
|
else |
|
298
|
|
|
{ |
|
299
|
|
|
return FALSE; |
|
300
|
|
|
} |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
return FALSE; |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
//ToDo Spider Check |
|
|
|
|
|
|
307
|
|
|
function sendJodel($location, $view) |
|
|
|
|
|
|
308
|
|
|
{ |
|
309
|
|
|
if(!$this->isAccountVerified()) |
|
310
|
|
|
{ |
|
311
|
|
|
$this->showCaptcha(); |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
$accountCreator = new SendJodel(); |
|
315
|
|
|
|
|
316
|
|
|
if(isset($_POST['ancestor'])) |
|
317
|
|
|
{ |
|
318
|
|
|
$ancestor = $_POST['ancestor']; |
|
|
|
|
|
|
319
|
|
|
$accountCreator->ancestor = $ancestor; |
|
320
|
|
|
} |
|
321
|
|
|
if(isset($_POST['color'])) |
|
322
|
|
|
{ |
|
323
|
|
|
$color = $_POST['color']; |
|
324
|
|
|
switch ($color) { |
|
325
|
|
|
case '8ABDB0': |
|
326
|
|
|
$color = '8ABDB0'; |
|
327
|
|
|
break; |
|
328
|
|
|
case '9EC41C': |
|
329
|
|
|
$color = '9EC41C'; |
|
330
|
|
|
break; |
|
331
|
|
|
case '06A3CB': |
|
332
|
|
|
$color = '06A3CB'; |
|
333
|
|
|
break; |
|
334
|
|
|
case 'FFBA00': |
|
335
|
|
|
$color = 'FFBA00'; |
|
336
|
|
|
break; |
|
337
|
|
|
case 'DD5F5F': |
|
338
|
|
|
$color = 'DD5F5F'; |
|
339
|
|
|
break; |
|
340
|
|
|
case 'FF9908': |
|
341
|
|
|
$color = 'FF9908'; |
|
342
|
|
|
break; |
|
343
|
|
|
default: |
|
344
|
|
|
$color = '8ABDB0'; |
|
345
|
|
|
break; |
|
346
|
|
|
} |
|
347
|
|
|
$accountCreator->color = $color; |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
$accountCreatorLocation = new UpdateLocation(); |
|
|
|
|
|
|
351
|
|
|
$accountCreatorLocation->setLocation($location); |
|
352
|
|
|
$accountCreatorLocation->setAccessToken($this->accessToken); |
|
353
|
|
|
$data = $accountCreatorLocation->execute(); |
|
354
|
|
|
|
|
355
|
|
|
if($data != 'Success') |
|
356
|
|
|
{ |
|
357
|
|
|
error_log('Could not set location befor Post: ' . print_r($data, true)); |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
$accountCreator->location = $this->location; |
|
361
|
|
|
|
|
362
|
|
|
$image = ''; |
|
363
|
|
|
if(isset($_FILES['image']) && $_FILES['image']['size'] > 0) |
|
364
|
|
|
{ |
|
365
|
|
|
$image = file_get_contents($_FILES['image']['tmp_name']); |
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
$accountCreator->image = $image; |
|
369
|
|
|
|
|
370
|
|
|
$accountCreator->setAccessToken($this->accessToken); |
|
371
|
|
|
$data = $accountCreator->execute(); |
|
372
|
|
|
|
|
373
|
|
|
error_log(print_r($data, true)); |
|
374
|
|
|
|
|
375
|
|
|
if(isset($_POST['ancestor'])) |
|
376
|
|
|
{ |
|
377
|
|
|
header('Location: ' . $view->toUrl()); |
|
378
|
|
|
exit; |
|
|
|
|
|
|
379
|
|
|
} |
|
380
|
|
|
else |
|
381
|
|
|
{ |
|
382
|
|
|
header('Location: ' . $view->baseUrl); |
|
383
|
|
|
exit; |
|
|
|
|
|
|
384
|
|
|
} |
|
385
|
|
|
} |
|
386
|
|
|
|
|
387
|
|
|
function isTokenFresh() |
|
|
|
|
|
|
388
|
|
|
{ |
|
389
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
|
|
390
|
|
|
$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
391
|
|
|
|
|
392
|
|
|
if ($result->num_rows > 0) |
|
393
|
|
|
{ |
|
394
|
|
|
// output data of each row |
|
395
|
|
|
while($row = $result->fetch_assoc()) |
|
396
|
|
|
{ |
|
397
|
|
|
$expiration_date = $row["expiration_date"]; |
|
|
|
|
|
|
398
|
|
|
} |
|
399
|
|
|
} |
|
400
|
|
|
else |
|
401
|
|
|
{ |
|
402
|
|
|
error_log('0 results'); |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
if($expiration_date <= time()) |
|
|
|
|
|
|
406
|
|
|
{ |
|
407
|
|
|
return FALSE; |
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
|
|
return TRUE; |
|
411
|
|
|
} |
|
412
|
|
|
|
|
413
|
|
|
function refreshToken() |
|
|
|
|
|
|
414
|
|
|
{ |
|
415
|
|
|
$accountCreator = new CreateUser(); |
|
416
|
|
|
$accountCreator->setAccessToken($this->accessToken); |
|
417
|
|
|
$accountCreator->setDeviceUid($this->deviceUid); |
|
418
|
|
|
$accountCreator->setLocation($this->location); |
|
419
|
|
|
$data = $accountCreator->execute(); |
|
420
|
|
|
|
|
421
|
|
|
$access_token = (string)$data[0]['access_token']; |
|
|
|
|
|
|
422
|
|
|
$expiration_date = $data[0]['expiration_date']; |
|
423
|
|
|
$device_uid = (string)$data[1]; |
|
|
|
|
|
|
424
|
|
|
|
|
425
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
|
|
426
|
|
|
$result = $db->query("UPDATE accounts |
|
427
|
|
|
SET access_token='" . $access_token . "', |
|
428
|
|
|
expiration_date='" . $expiration_date . "' |
|
429
|
|
|
WHERE device_uid='" . $device_uid . "'"); |
|
430
|
|
|
|
|
431
|
|
|
if($result === false){ |
|
432
|
|
|
error_log("Adding account failed: (" . $db->errno . ") " . $db->error); |
|
|
|
|
|
|
433
|
|
|
} |
|
434
|
|
|
} |
|
435
|
|
|
|
|
436
|
|
|
|
|
437
|
|
|
|
|
438
|
|
|
function getAccessToken() |
|
|
|
|
|
|
439
|
|
|
{ |
|
440
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
|
|
441
|
|
|
$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
442
|
|
|
|
|
443
|
|
|
$accessToken; |
|
|
|
|
|
|
444
|
|
|
|
|
445
|
|
|
if ($result->num_rows > 0) |
|
446
|
|
|
{ |
|
447
|
|
|
// output data of each row |
|
448
|
|
|
while($row = $result->fetch_assoc()) |
|
449
|
|
|
{ |
|
450
|
|
|
$accessToken = $row['access_token']; |
|
451
|
|
|
} |
|
452
|
|
|
} |
|
453
|
|
|
else |
|
454
|
|
|
{ |
|
455
|
|
|
error_log('Error: 0 results'); |
|
456
|
|
|
} |
|
457
|
|
|
|
|
458
|
|
|
return $accessToken; |
|
|
|
|
|
|
459
|
|
|
} |
|
460
|
|
|
|
|
461
|
|
|
|
|
462
|
|
|
function getKarma() |
|
|
|
|
|
|
463
|
|
|
{ |
|
464
|
|
|
$accountCreator = new GetKarma(); |
|
465
|
|
|
$accountCreator->setAccessToken($this->accessToken); |
|
466
|
|
|
$data = $accountCreator->execute(); |
|
467
|
|
|
|
|
468
|
|
|
return $data['karma']; |
|
469
|
|
|
} |
|
470
|
|
|
|
|
471
|
|
|
function hasVoted($postId) |
|
|
|
|
|
|
472
|
|
|
{ |
|
473
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
|
|
474
|
|
|
|
|
475
|
|
|
$postId = $db->real_escape_string($postId); |
|
|
|
|
|
|
476
|
|
|
|
|
477
|
|
|
$result = $db->query("SELECT id FROM votes WHERE (postId = '" . $postId . "' AND device_uid = '" . $this->deviceUid . "')"); |
|
|
|
|
|
|
478
|
|
|
|
|
479
|
|
View Code Duplication |
if($result === false) |
|
|
|
|
|
|
480
|
|
|
{ |
|
481
|
|
|
$error = db_error(); |
|
482
|
|
|
echo $error; |
|
483
|
|
|
error_log("Adding Vote failed: (" . $result->errno . ") " . $result->error); |
|
|
|
|
|
|
484
|
|
|
} |
|
485
|
|
|
|
|
486
|
|
|
if($result->num_rows == 0) |
|
|
|
|
|
|
487
|
|
|
{ |
|
488
|
|
|
return FALSE; |
|
489
|
|
|
} |
|
490
|
|
|
else |
|
491
|
|
|
{ |
|
492
|
|
|
return TRUE; |
|
493
|
|
|
} |
|
494
|
|
|
} |
|
495
|
|
|
|
|
496
|
|
|
function addVoteWithPostIdAndType($postId, $voteType) |
|
|
|
|
|
|
497
|
|
|
{ |
|
498
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
|
|
499
|
|
|
|
|
500
|
|
|
$postId = $db->real_escape_string($postId); |
|
|
|
|
|
|
501
|
|
|
$voteType = $db->real_escape_string($voteType); |
|
|
|
|
|
|
502
|
|
|
|
|
503
|
|
|
if($this->hasVoted($postId)) |
|
504
|
|
|
{ |
|
505
|
|
|
return "Already voted"; |
|
|
|
|
|
|
506
|
|
|
} |
|
507
|
|
|
|
|
508
|
|
|
$result = $db->query("INSERT INTO votes (device_uid, postId, type) |
|
509
|
|
|
VALUES ('" . $this->deviceUid . "','" . $postId . "','" . $voteType . "')"); |
|
510
|
|
|
|
|
511
|
|
View Code Duplication |
if($result === false){ |
|
|
|
|
|
|
512
|
|
|
$error = db_error(); |
|
513
|
|
|
echo $error; |
|
514
|
|
|
echo "Adding Vote failed: (" . $result->errno . ") " . $result->error; |
|
|
|
|
|
|
515
|
|
|
} |
|
516
|
|
|
} |
|
517
|
|
|
|
|
518
|
|
|
function registerAccount($location) { |
|
|
|
|
|
|
519
|
|
|
$accountCreator = new CreateUser(); |
|
520
|
|
|
$accountCreator->setLocation($location); |
|
521
|
|
|
$data = $accountCreator->execute(); |
|
522
|
|
|
|
|
523
|
|
|
$access_token = (string)$data[0]['access_token']; |
|
|
|
|
|
|
524
|
|
|
$refresh_token = (string)$data[0]['refresh_token']; |
|
|
|
|
|
|
525
|
|
|
$token_type = (string)$data[0]['token_type']; |
|
|
|
|
|
|
526
|
|
|
$expires_in = $data[0]['expires_in']; |
|
|
|
|
|
|
527
|
|
|
$expiration_date = $data[0]['expiration_date']; |
|
528
|
|
|
$distinct_id = (string)$data[0]['distinct_id']; |
|
|
|
|
|
|
529
|
|
|
$device_uid = (string)$data[1]; |
|
|
|
|
|
|
530
|
|
|
|
|
531
|
|
|
$name = $location->cityName; |
|
532
|
|
|
$lat = $location->lat; |
|
|
|
|
|
|
533
|
|
|
$lng = $location->lng; |
|
|
|
|
|
|
534
|
|
|
|
|
535
|
|
|
$db = new DatabaseConnect(); |
|
|
|
|
|
|
536
|
|
|
$result = $db->query("INSERT INTO accounts (access_token, refresh_token, token_type, |
|
537
|
|
|
expires_in, expiration_date, distinct_id, device_uid, name, lat, lng) |
|
538
|
|
|
VALUES ('" . $access_token . "','" . $refresh_token . "','" . $token_type . |
|
539
|
|
|
"','" . $expires_in . "','" . $expiration_date . "','" . $distinct_id . |
|
540
|
|
|
"','" . $device_uid . "','" . $name . "','" . $lat . "','" . $lng . "') "); |
|
541
|
|
|
|
|
542
|
|
|
$success = TRUE; |
|
|
|
|
|
|
543
|
|
View Code Duplication |
if($result === false){ |
|
|
|
|
|
|
544
|
|
|
$error = $db->error(); |
|
|
|
|
|
|
545
|
|
|
echo $error; |
|
546
|
|
|
echo "Adding account failed: (" . $result->errno . ") " . $result->error; |
|
|
|
|
|
|
547
|
|
|
$success = FALSE; |
|
|
|
|
|
|
548
|
|
|
} |
|
549
|
|
|
|
|
550
|
|
|
return $device_uid; |
|
551
|
|
|
} |
|
552
|
|
|
|
|
553
|
|
|
function createAccount() |
|
|
|
|
|
|
554
|
|
|
{ |
|
555
|
|
|
$config = parse_ini_file('config/config.ini.php'); |
|
|
|
|
|
|
556
|
|
|
$location = new Location(); |
|
557
|
|
|
$location->setLat($config['default_lat']); |
|
558
|
|
|
$location->setLng($config['default_lng']); |
|
559
|
|
|
$location->setCityName($config['default_location']); |
|
560
|
|
|
|
|
561
|
|
|
$deviceUid = $this->registerAccount($location); |
|
562
|
|
|
|
|
563
|
|
|
return $deviceUid; |
|
564
|
|
|
} |
|
565
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.