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