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