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