Completed
Push — master ( 16e812...ea693b )
by mains
02:48
created
php/JodelAccount.php 1 patch
Indentation   +468 added lines, -468 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,513 +71,513 @@  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();
79
-
80
-        return array("image_url" => $captcha['image_url'], "key" => $captcha['key']);
81
-    }
82
-
83
-    function isAccountVerified()
84
-    {
85
-        $accountCreator = new GetUserConfig();
86
-        $accountCreator->setAccessToken($this->accessToken);
87
-        $data = $accountCreator->execute();
88
-
89
-        //error_log(print_r($data, true));
90
-
91
-        return $data['verified'];
92
-    }
93
-
94
-    function getGeocodingToken()
95
-    {
96
-        $config = parse_ini_file('config/config.ini.php');
97
-        if(!isset($config['geocodingToken']) ||
98
-            $config['geocodingToken'] == NULL ||
99
-            $config['geocodingToken'] == '' ||
100
-            $config['geocodingToken'] == 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
101
-        {
102
-            error_log("Please set a Google Maps Geocoding Token!");
103
-        }
104
-        else
105
-        {
106
-            return $config['geocodingToken'];
107
-        }
108
-    }
74
+	function getCaptcha()
75
+	{
76
+		$accountCreator = new GetCaptcha();
77
+		$accountCreator->setAccessToken($this->accessToken);
78
+		$captcha = $accountCreator->execute();
79
+
80
+		return array("image_url" => $captcha['image_url'], "key" => $captcha['key']);
81
+	}
82
+
83
+	function isAccountVerified()
84
+	{
85
+		$accountCreator = new GetUserConfig();
86
+		$accountCreator->setAccessToken($this->accessToken);
87
+		$data = $accountCreator->execute();
88
+
89
+		//error_log(print_r($data, true));
90
+
91
+		return $data['verified'];
92
+	}
93
+
94
+	function getGeocodingToken()
95
+	{
96
+		$config = parse_ini_file('config/config.ini.php');
97
+		if(!isset($config['geocodingToken']) ||
98
+			$config['geocodingToken'] == NULL ||
99
+			$config['geocodingToken'] == '' ||
100
+			$config['geocodingToken'] == 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
101
+		{
102
+			error_log("Please set a Google Maps Geocoding Token!");
103
+		}
104
+		else
105
+		{
106
+			return $config['geocodingToken'];
107
+		}
108
+	}
109 109
 
110
-    function locationEquals($city)
111
-    {
112
-        $db = new DatabaseConnect();
113
-        $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid  . "'");
110
+	function locationEquals($city)
111
+	{
112
+		$db = new DatabaseConnect();
113
+		$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid  . "'");
114 114
         
115
-        $location = new Location();
115
+		$location = new Location();
116 116
         
117
-        if ($result->num_rows > 0)
118
-        {
119
-            // output data of each row
120
-            while($row = $result->fetch_assoc())
121
-            {
122
-                $location->setLat($row['lat']);
123
-                $location->setLng($row['lng']);
124
-                $location->setCityName($row['name']);
125
-            }
126
-        }
127
-        else
128
-        {
129
-            error_log("Error no Location found - getLocation");
130
-        }
117
+		if ($result->num_rows > 0)
118
+		{
119
+			// output data of each row
120
+			while($row = $result->fetch_assoc())
121
+			{
122
+				$location->setLat($row['lat']);
123
+				$location->setLng($row['lng']);
124
+				$location->setCityName($row['name']);
125
+			}
126
+		}
127
+		else
128
+		{
129
+			error_log("Error no Location found - getLocation");
130
+		}
131 131
 
132
-        if($location->getCityName() == $city)
133
-        {
134
-            return TRUE;
135
-        }  
136
-        else
137
-        {
138
-            return FALSE;
139
-        }
140
-    }
132
+		if($location->getCityName() == $city)
133
+		{
134
+			return TRUE;
135
+		}  
136
+		else
137
+		{
138
+			return FALSE;
139
+		}
140
+	}
141 141
 
142
-    function setLocation()
143
-    {
144
-        //Is Channel or City
145
-        if(substr($_GET['city'], 0, 1) === '#')
146
-        {
147
-            return htmlspecialchars($_GET['city']) . " " . $this->location->cityName;
148
-        }                
149
-        else
150
-        {
151
-            $url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($_GET['city']) . '&key=' . $this->getGeocodingToken();
152
-            $result = Requests::post($url);
153
-            if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST')
154
-            {
155
-                return "0 results";
156
-            }
157
-            else
158
-            {
159
-                $name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name'];
160
-                $lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat'];
161
-                $lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng'];
162
-
163
-                $location = new Location();
164
-                $location->setLat($lat);
165
-                $location->setLng($lng);
166
-                $location->setCityName($name);
167
-                $accountCreator = new UpdateLocation();
168
-                $accountCreator->setLocation($location);
169
-                $accountCreator->setAccessToken($this->accessToken);
170
-                $data = $accountCreator->execute();
171
-
172
-                //safe location to db
173
-                $db = new DatabaseConnect();
174
-
175
-                if($data == 'Success')
176
-                {
177
-                    $result = $db->query("UPDATE accounts 
142
+	function setLocation()
143
+	{
144
+		//Is Channel or City
145
+		if(substr($_GET['city'], 0, 1) === '#')
146
+		{
147
+			return htmlspecialchars($_GET['city']) . " " . $this->location->cityName;
148
+		}                
149
+		else
150
+		{
151
+			$url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($_GET['city']) . '&key=' . $this->getGeocodingToken();
152
+			$result = Requests::post($url);
153
+			if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST')
154
+			{
155
+				return "0 results";
156
+			}
157
+			else
158
+			{
159
+				$name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name'];
160
+				$lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat'];
161
+				$lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng'];
162
+
163
+				$location = new Location();
164
+				$location->setLat($lat);
165
+				$location->setLng($lng);
166
+				$location->setCityName($name);
167
+				$accountCreator = new UpdateLocation();
168
+				$accountCreator->setLocation($location);
169
+				$accountCreator->setAccessToken($this->accessToken);
170
+				$data = $accountCreator->execute();
171
+
172
+				//safe location to db
173
+				$db = new DatabaseConnect();
174
+
175
+				if($data == 'Success')
176
+				{
177
+					$result = $db->query("UPDATE accounts 
178 178
                             SET name='" . $name . "',
179 179
                                 lat='" . $lat . "',
180 180
                                 lng='" . $lng . "'
181 181
                             WHERE access_token='" . $this->accessToken . "'");
182 182
 
183
-                    if($result === false)
184
-                    {
185
-                            echo "Updating location failed: (" . $db->errno . ") " . $db->error;
186
-                    }
187
-                    else
188
-                    {
189
-                        user_log('User with JodelDeviceId:' . $this->deviceUid .  ' [' . $_SERVER['REMOTE_ADDR'] . '][' . $_SERVER ['HTTP_USER_AGENT'] . '] changed to Location: ' . $name);
190
-                    }
191
-                }
192
-
193
-                return $name;
194
-            }
195
-        }
196
-    }
183
+					if($result === false)
184
+					{
185
+							echo "Updating location failed: (" . $db->errno . ") " . $db->error;
186
+					}
187
+					else
188
+					{
189
+						user_log('User with JodelDeviceId:' . $this->deviceUid .  ' [' . $_SERVER['REMOTE_ADDR'] . '][' . $_SERVER ['HTTP_USER_AGENT'] . '] changed to Location: ' . $name);
190
+					}
191
+				}
192
+
193
+				return $name;
194
+			}
195
+		}
196
+	}
197 197
 
198
-    function getLocation()
199
-    {
200
-        $db = new DatabaseConnect();
201
-        $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid  . "'");
198
+	function getLocation()
199
+	{
200
+		$db = new DatabaseConnect();
201
+		$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid  . "'");
202 202
         
203
-        $location = new Location();
203
+		$location = new Location();
204 204
         
205
-        if ($result->num_rows > 0)
206
-        {
207
-            // output data of each row
208
-            while($row = $result->fetch_assoc())
209
-            {
210
-                $location->setLat($row['lat']);
211
-                $location->setLng($row['lng']);
212
-                $location->setCityName($row['name']);
213
-            }
214
-        }
215
-        else
216
-        {
217
-            echo "Error: 0 results";
218
-            error_log("Error no Location found - getLocation");
219
-        }
205
+		if ($result->num_rows > 0)
206
+		{
207
+			// output data of each row
208
+			while($row = $result->fetch_assoc())
209
+			{
210
+				$location->setLat($row['lat']);
211
+				$location->setLng($row['lng']);
212
+				$location->setCityName($row['name']);
213
+			}
214
+		}
215
+		else
216
+		{
217
+			echo "Error: 0 results";
218
+			error_log("Error no Location found - getLocation");
219
+		}
220 220
 
221
-        return $location;
222
-    }
221
+		return $location;
222
+	}
223 223
 
224
-    function verifyCaptcha()
225
-    {
226
-        if(isset($_GET['deviceUid']))
227
-        {
228
-            $deviceUid = $_GET['deviceUid'];
229
-            $jodelAccountForVerify = new JodelAccount($deviceUid);
230
-        }
231
-        else if(isset($_POST['deviceUid']))
232
-        {
233
-            $deviceUid = $_POST['deviceUid'];
234
-            $jodelAccountForVerify = new JodelAccount($deviceUid);
235
-        }
236
-        else
237
-        {
238
-            $deviceUid = $this->deviceUid;
239
-            $jodelAccountForVerify = $this;
240
-        }
224
+	function verifyCaptcha()
225
+	{
226
+		if(isset($_GET['deviceUid']))
227
+		{
228
+			$deviceUid = $_GET['deviceUid'];
229
+			$jodelAccountForVerify = new JodelAccount($deviceUid);
230
+		}
231
+		else if(isset($_POST['deviceUid']))
232
+		{
233
+			$deviceUid = $_POST['deviceUid'];
234
+			$jodelAccountForVerify = new JodelAccount($deviceUid);
235
+		}
236
+		else
237
+		{
238
+			$deviceUid = $this->deviceUid;
239
+			$jodelAccountForVerify = $this;
240
+		}
241 241
 
242
-        $solution = $_GET['solution'];
243
-        $solution = array_map('intval', explode('-', $solution));
242
+		$solution = $_GET['solution'];
243
+		$solution = array_map('intval', explode('-', $solution));
244 244
 
245
-        $accountCreator = new PostCaptcha();
246
-        $accountCreator->setAccessToken($jodelAccountForVerify->accessToken);
247
-        $accountCreator->captchaKey = $_GET['key'];
248
-        $accountCreator->captchaSolution = $solution;
249
-        $verified = $accountCreator->execute();
245
+		$accountCreator = new PostCaptcha();
246
+		$accountCreator->setAccessToken($jodelAccountForVerify->accessToken);
247
+		$accountCreator->captchaKey = $_GET['key'];
248
+		$accountCreator->captchaSolution = $solution;
249
+		$verified = $accountCreator->execute();
250 250
 
251
-        if(isset($verified->status_code))
252
-        {
253
-            return $verified->status_code;
254
-        }
255
-        return $verified['verified'];
256
-    }
251
+		if(isset($verified->status_code))
252
+		{
253
+			return $verified->status_code;
254
+		}
255
+		return $verified['verified'];
256
+	}
257 257
 
258
-    //ToDo Spider Check
259
-    function votePostId($postId, $vote)
260
-    {
261
-        if(!$this->isBot)
262
-        {
263
-            if(!$this->isAccountVerified())
264
-            {
265
-                error_log('Account is not Verified! jodelAccount.php Line 279');
266
-                return FALSE;
267
-            }
268
-            else
269
-            {
258
+	//ToDo Spider Check
259
+	function votePostId($postId, $vote)
260
+	{
261
+		if(!$this->isBot)
262
+		{
263
+			if(!$this->isAccountVerified())
264
+			{
265
+				error_log('Account is not Verified! jodelAccount.php Line 279');
266
+				return FALSE;
267
+			}
268
+			else
269
+			{
270 270
                 
271
-            }
272
-
273
-            if(!$this->hasVoted($postId))
274
-            {
275
-                if($vote == "up")
276
-                {
277
-                    $accountCreator = new Upvote();
278
-                }
279
-                else if($vote == "down")
280
-                {
281
-                    $accountCreator = new Downvote();
282
-                }
283
-
284
-                $accountCreator->setAccessToken($this->accessToken);
285
-                $accountCreator->postId = htmlspecialchars($postId);
286
-                $data = $accountCreator->execute();
287
-
288
-                user_log('User voted: ' . print_r($data, true));
289
-
290
-                if(array_key_exists('post', $data))
291
-                {
292
-                    $this->addVoteWithPostIdAndType($postId, $vote);
293
-                    return TRUE;
294
-                }
295
-                else if(array_key_exists('error', $data))
296
-                {
297
-                    error_log('Could not vote - Error: ' . $data['error']);
298
-                    return FALSE;
299
-                }
300
-                else
301
-                {
302
-                    error_log('Could not vote: ' . print_r($data, true));
303
-                    return FALSE;
304
-                } 
305
-            }
306
-            else
307
-            {
308
-                return FALSE;
309
-            }
310
-        }
311
-        else
312
-        {
313
-            return FALSE;
314
-        }
315
-    }
271
+			}
272
+
273
+			if(!$this->hasVoted($postId))
274
+			{
275
+				if($vote == "up")
276
+				{
277
+					$accountCreator = new Upvote();
278
+				}
279
+				else if($vote == "down")
280
+				{
281
+					$accountCreator = new Downvote();
282
+				}
283
+
284
+				$accountCreator->setAccessToken($this->accessToken);
285
+				$accountCreator->postId = htmlspecialchars($postId);
286
+				$data = $accountCreator->execute();
287
+
288
+				user_log('User voted: ' . print_r($data, true));
289
+
290
+				if(array_key_exists('post', $data))
291
+				{
292
+					$this->addVoteWithPostIdAndType($postId, $vote);
293
+					return TRUE;
294
+				}
295
+				else if(array_key_exists('error', $data))
296
+				{
297
+					error_log('Could not vote - Error: ' . $data['error']);
298
+					return FALSE;
299
+				}
300
+				else
301
+				{
302
+					error_log('Could not vote: ' . print_r($data, true));
303
+					return FALSE;
304
+				} 
305
+			}
306
+			else
307
+			{
308
+				return FALSE;
309
+			}
310
+		}
311
+		else
312
+		{
313
+			return FALSE;
314
+		}
315
+	}
316 316
 
317
-    //ToDo Spider Check
318
-    function sendJodel($location, $view)
319
-    {
320
-        if($this->isAccountVerified() != 1)
321
-        {
322
-            $this->showCaptcha();
323
-            //$this->verifyCaptcha();
324
-        }
317
+	//ToDo Spider Check
318
+	function sendJodel($location, $view)
319
+	{
320
+		if($this->isAccountVerified() != 1)
321
+		{
322
+			$this->showCaptcha();
323
+			//$this->verifyCaptcha();
324
+		}
325 325
 
326
-        $accountCreator = new SendJodel();
326
+		$accountCreator = new SendJodel();
327 327
 
328
-        if(isset($_POST['ancestor']))
329
-        {
330
-            $ancestor = $_POST['ancestor'];
331
-            $accountCreator->ancestor = $ancestor;
332
-        }
333
-        if(isset($_POST['color']))
334
-        {
335
-            $color = $_POST['color'];
336
-            switch ($color) {
337
-                case '8ABDB0':
338
-                    $color = '8ABDB0';
339
-                    break;
340
-                case '9EC41C':
341
-                    $color = '9EC41C';
342
-                    break;
343
-                case '06A3CB':
344
-                    $color = '06A3CB';
345
-                    break;
346
-                case 'FFBA00':
347
-                    $color = 'FFBA00';
348
-                    break;
349
-                case 'DD5F5F':
350
-                    $color = 'DD5F5F';
351
-                    break;
352
-                case 'FF9908':
353
-                    $color = 'FF9908';
354
-                    break;
355
-                default:
356
-                    $color = '8ABDB0';
357
-                    break;
358
-            }
359
-            $accountCreator->color = $color;
360
-        }
361
-
362
-        $accountCreatorLocation = new UpdateLocation();
363
-        $accountCreatorLocation->setLocation($location);
364
-        $accountCreatorLocation->setAccessToken($this->accessToken);
365
-        $data = $accountCreatorLocation->execute();
328
+		if(isset($_POST['ancestor']))
329
+		{
330
+			$ancestor = $_POST['ancestor'];
331
+			$accountCreator->ancestor = $ancestor;
332
+		}
333
+		if(isset($_POST['color']))
334
+		{
335
+			$color = $_POST['color'];
336
+			switch ($color) {
337
+				case '8ABDB0':
338
+					$color = '8ABDB0';
339
+					break;
340
+				case '9EC41C':
341
+					$color = '9EC41C';
342
+					break;
343
+				case '06A3CB':
344
+					$color = '06A3CB';
345
+					break;
346
+				case 'FFBA00':
347
+					$color = 'FFBA00';
348
+					break;
349
+				case 'DD5F5F':
350
+					$color = 'DD5F5F';
351
+					break;
352
+				case 'FF9908':
353
+					$color = 'FF9908';
354
+					break;
355
+				default:
356
+					$color = '8ABDB0';
357
+					break;
358
+			}
359
+			$accountCreator->color = $color;
360
+		}
361
+
362
+		$accountCreatorLocation = new UpdateLocation();
363
+		$accountCreatorLocation->setLocation($location);
364
+		$accountCreatorLocation->setAccessToken($this->accessToken);
365
+		$data = $accountCreatorLocation->execute();
366 366
         
367 367
 		if($data != 'Success')
368 368
 		{
369 369
 			error_log('Could not set location befor Post: ' . print_r($data, true));
370 370
 		}
371 371
 
372
-        $accountCreator->location = $this->location;
372
+		$accountCreator->location = $this->location;
373 373
 
374
-        $image = '';
375
-        if(isset($_FILES['image']) && $_FILES['image']['size'] > 0)
376
-        {
377
-            $image = file_get_contents($_FILES['image']['tmp_name']);
378
-        }
374
+		$image = '';
375
+		if(isset($_FILES['image']) && $_FILES['image']['size'] > 0)
376
+		{
377
+			$image = file_get_contents($_FILES['image']['tmp_name']);
378
+		}
379 379
         
380
-        $accountCreator->image = $image;
380
+		$accountCreator->image = $image;
381 381
         
382
-        $accountCreator->setAccessToken($this->accessToken);
383
-        $data = $accountCreator->execute();
382
+		$accountCreator->setAccessToken($this->accessToken);
383
+		$data = $accountCreator->execute();
384 384
 
385
-        if(isset($data['error']) && $data['error'] == 'length')
386
-        {
387
-            $errorMsg = 'Error: The input was to long';
388
-            return $errorMsg;
389
-        }
385
+		if(isset($data['error']) && $data['error'] == 'length')
386
+		{
387
+			$errorMsg = 'Error: The input was to long';
388
+			return $errorMsg;
389
+		}
390 390
 
391
-        user_log('User posted: ' . print_r($data, true));
391
+		user_log('User posted: ' . print_r($data, true));
392 392
 
393
-        if(isset($_POST['ancestor']))
394
-        {
395
-            header('Location: ' . $view->toUrl());
396
-            exit;
397
-        }
398
-        else
399
-        {
400
-            header('Location: ' . $view->baseUrl);
401
-            exit;
402
-        }
403
-    }
393
+		if(isset($_POST['ancestor']))
394
+		{
395
+			header('Location: ' . $view->toUrl());
396
+			exit;
397
+		}
398
+		else
399
+		{
400
+			header('Location: ' . $view->baseUrl);
401
+			exit;
402
+		}
403
+	}
404 404
 
405
-    function isTokenFresh()
406
-    {
407
-        $db = new DatabaseConnect();  
408
-        $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'");
405
+	function isTokenFresh()
406
+	{
407
+		$db = new DatabaseConnect();  
408
+		$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'");
409 409
 
410
-        if ($result->num_rows > 0)
411
-        {
412
-            // output data of each row
413
-            while($row = $result->fetch_assoc())
414
-            {
415
-                    $expiration_date = $row["expiration_date"];
416
-            }
417
-        }
418
-        else
419
-        {
420
-            error_log('0 results');
421
-        }
410
+		if ($result->num_rows > 0)
411
+		{
412
+			// output data of each row
413
+			while($row = $result->fetch_assoc())
414
+			{
415
+					$expiration_date = $row["expiration_date"];
416
+			}
417
+		}
418
+		else
419
+		{
420
+			error_log('0 results');
421
+		}
422 422
 
423
-        if($expiration_date <= time())
424
-        {
425
-           return FALSE;
426
-        }
423
+		if($expiration_date <= time())
424
+		{
425
+		   return FALSE;
426
+		}
427 427
         
428
-        return TRUE;
429
-    }
430
-
431
-    function refreshToken()
432
-    {
433
-        $accountCreator = new CreateUser();
434
-        $accountCreator->setAccessToken($this->accessToken);
435
-        $accountCreator->setDeviceUid($this->deviceUid);
436
-        $accountCreator->setLocation($this->location);
437
-        $data = $accountCreator->execute();
438
-
439
-        $access_token = (string)$data[0]['access_token'];
440
-        $expiration_date = $data[0]['expiration_date'];
441
-        $device_uid = (string)$data[1];
428
+		return TRUE;
429
+	}
430
+
431
+	function refreshToken()
432
+	{
433
+		$accountCreator = new CreateUser();
434
+		$accountCreator->setAccessToken($this->accessToken);
435
+		$accountCreator->setDeviceUid($this->deviceUid);
436
+		$accountCreator->setLocation($this->location);
437
+		$data = $accountCreator->execute();
438
+
439
+		$access_token = (string)$data[0]['access_token'];
440
+		$expiration_date = $data[0]['expiration_date'];
441
+		$device_uid = (string)$data[1];
442 442
         
443
-        $db = new DatabaseConnect();  
444
-        $result = $db->query("UPDATE accounts 
443
+		$db = new DatabaseConnect();  
444
+		$result = $db->query("UPDATE accounts 
445 445
                                 SET access_token='" . $access_token . "',
446 446
                                     expiration_date='" . $expiration_date . "'
447 447
                                 WHERE device_uid='" . $device_uid . "'");
448 448
 
449
-        if($result === false){
450
-                error_log("Adding account failed: (" . $db->errno . ") " . $db->error);
451
-        }   
452
-    }
449
+		if($result === false){
450
+				error_log("Adding account failed: (" . $db->errno . ") " . $db->error);
451
+		}   
452
+	}
453 453
 
454 454
 
455 455
 
456
-    function getAccessToken()
457
-    {
458
-        $db = new DatabaseConnect();
459
-        $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid  . "'");
456
+	function getAccessToken()
457
+	{
458
+		$db = new DatabaseConnect();
459
+		$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid  . "'");
460 460
         
461
-        $accessToken;
461
+		$accessToken;
462 462
         
463
-        if ($result->num_rows > 0)
464
-        {
465
-            // output data of each row
466
-            while($row = $result->fetch_assoc())
467
-            {
468
-                $accessToken = $row['access_token'];
469
-            }
470
-        }
471
-        else
472
-        {
473
-            error_log('Error: 0 results');
474
-        }
463
+		if ($result->num_rows > 0)
464
+		{
465
+			// output data of each row
466
+			while($row = $result->fetch_assoc())
467
+			{
468
+				$accessToken = $row['access_token'];
469
+			}
470
+		}
471
+		else
472
+		{
473
+			error_log('Error: 0 results');
474
+		}
475 475
 
476
-        return $accessToken;
477
-    }
476
+		return $accessToken;
477
+	}
478 478
 
479 479
 
480
-    function getKarma()
481
-    {
482
-        $accountCreator = new GetKarma();
483
-        $accountCreator->setAccessToken($this->accessToken);
484
-        $data = $accountCreator->execute();
480
+	function getKarma()
481
+	{
482
+		$accountCreator = new GetKarma();
483
+		$accountCreator->setAccessToken($this->accessToken);
484
+		$data = $accountCreator->execute();
485 485
         
486
-        return $data['karma'];
487
-    }
486
+		return $data['karma'];
487
+	}
488 488
 
489
-    function hasVoted($postId)
490
-    {
491
-        $db = new DatabaseConnect();
489
+	function hasVoted($postId)
490
+	{
491
+		$db = new DatabaseConnect();
492 492
 
493
-        $postId = $db->real_escape_string($postId);
493
+		$postId = $db->real_escape_string($postId);
494 494
 
495
-        $result = $db->query("SELECT id FROM votes WHERE (postId = '" . $postId . "' AND device_uid = '" . $this->deviceUid . "')");
495
+		$result = $db->query("SELECT id FROM votes WHERE (postId = '" . $postId . "' AND device_uid = '" . $this->deviceUid . "')");
496 496
         
497
-        if($result === false)
498
-        {
499
-            $error = db_error();
500
-            echo $error;
501
-            error_log("Adding Vote failed: (" . $result->errno . ") " . $result->error);
502
-        }
497
+		if($result === false)
498
+		{
499
+			$error = db_error();
500
+			echo $error;
501
+			error_log("Adding Vote failed: (" . $result->errno . ") " . $result->error);
502
+		}
503 503
 
504
-        if($result->num_rows == 0)
505
-        {
506
-            return FALSE;
507
-        }
508
-        else
509
-        {
510
-            return TRUE;
511
-        }
512
-    }
504
+		if($result->num_rows == 0)
505
+		{
506
+			return FALSE;
507
+		}
508
+		else
509
+		{
510
+			return TRUE;
511
+		}
512
+	}
513 513
 
514
-    function addVoteWithPostIdAndType($postId, $voteType)
515
-    {
516
-        $db = new DatabaseConnect();
514
+	function addVoteWithPostIdAndType($postId, $voteType)
515
+	{
516
+		$db = new DatabaseConnect();
517 517
 
518
-        $postId = $db->real_escape_string($postId);
519
-        $voteType = $db->real_escape_string($voteType);
518
+		$postId = $db->real_escape_string($postId);
519
+		$voteType = $db->real_escape_string($voteType);
520 520
         
521
-        if($this->hasVoted($postId))
522
-        {
523
-            return "Already voted";
524
-        }
521
+		if($this->hasVoted($postId))
522
+		{
523
+			return "Already voted";
524
+		}
525 525
 
526
-        $result = $db->query("INSERT INTO votes (device_uid, postId, type)
526
+		$result = $db->query("INSERT INTO votes (device_uid, postId, type)
527 527
                         VALUES ('" . $this->deviceUid . "','" . $postId . "','" . $voteType . "')");
528 528
         
529
-        if($result === false){
530
-                $error = db_error();
531
-                echo $error;
532
-                echo "Adding Vote failed: (" . $result->errno . ") " . $result->error;
533
-        }       
534
-    }
535
-
536
-    function registerAccount($location) {
537
-        $accountCreator = new CreateUser();
538
-        $accountCreator->setLocation($location);
539
-        $data = $accountCreator->execute();
529
+		if($result === false){
530
+				$error = db_error();
531
+				echo $error;
532
+				echo "Adding Vote failed: (" . $result->errno . ") " . $result->error;
533
+		}       
534
+	}
535
+
536
+	function registerAccount($location) {
537
+		$accountCreator = new CreateUser();
538
+		$accountCreator->setLocation($location);
539
+		$data = $accountCreator->execute();
540 540
         
541
-        $access_token = (string)$data[0]['access_token'];
542
-        $refresh_token = (string)$data[0]['refresh_token'];
543
-        $token_type = (string)$data[0]['token_type'];
544
-        $expires_in = $data[0]['expires_in'];
545
-        $expiration_date = $data[0]['expiration_date'];
546
-        $distinct_id = (string)$data[0]['distinct_id'];
547
-        $device_uid = (string)$data[1];
548
-
549
-        $name = $location->cityName;
550
-        $lat = $location->lat;
551
-        $lng = $location->lng;
541
+		$access_token = (string)$data[0]['access_token'];
542
+		$refresh_token = (string)$data[0]['refresh_token'];
543
+		$token_type = (string)$data[0]['token_type'];
544
+		$expires_in = $data[0]['expires_in'];
545
+		$expiration_date = $data[0]['expiration_date'];
546
+		$distinct_id = (string)$data[0]['distinct_id'];
547
+		$device_uid = (string)$data[1];
548
+
549
+		$name = $location->cityName;
550
+		$lat = $location->lat;
551
+		$lng = $location->lng;
552 552
         
553
-        $db = new DatabaseConnect();  
554
-        $result = $db->query("INSERT INTO accounts (access_token, refresh_token, token_type,
553
+		$db = new DatabaseConnect();  
554
+		$result = $db->query("INSERT INTO accounts (access_token, refresh_token, token_type,
555 555
                         expires_in, expiration_date, distinct_id, device_uid, name, lat, lng)
556 556
                         VALUES ('" . $access_token . "','" . $refresh_token . "','" . $token_type .
557
-                        "','" .  $expires_in . "','" . $expiration_date . "','" . $distinct_id .
558
-                        "','" . $device_uid . "','" . $name . "','" . $lat . "','" . $lng . "') ");
559
-
560
-        $success = TRUE;
561
-        if($result === false){
562
-                $error = $db->error();
563
-                echo $error;
564
-                echo "Adding account failed: (" . $result->errno . ") " . $result->error;
565
-                $success = FALSE;
566
-        }   
557
+						"','" .  $expires_in . "','" . $expiration_date . "','" . $distinct_id .
558
+						"','" . $device_uid . "','" . $name . "','" . $lat . "','" . $lng . "') ");
559
+
560
+		$success = TRUE;
561
+		if($result === false){
562
+				$error = $db->error();
563
+				echo $error;
564
+				echo "Adding account failed: (" . $result->errno . ") " . $result->error;
565
+				$success = FALSE;
566
+		}   
567 567
         
568
-        return $device_uid;
569
-    }
568
+		return $device_uid;
569
+	}
570 570
 
571
-    function createAccount()
572
-    {
573
-        $config = parse_ini_file('config/config.ini.php');
574
-        $location = new Location();
575
-        $location->setLat($config['default_lat']);
576
-        $location->setLng($config['default_lng']);
577
-        $location->setCityName($config['default_location']);
571
+	function createAccount()
572
+	{
573
+		$config = parse_ini_file('config/config.ini.php');
574
+		$location = new Location();
575
+		$location->setLat($config['default_lat']);
576
+		$location->setLng($config['default_lng']);
577
+		$location->setCityName($config['default_location']);
578 578
 
579
-        $deviceUid = $this->registerAccount($location);
579
+		$deviceUid = $this->registerAccount($location);
580 580
 
581
-        return $deviceUid;
582
-    }
581
+		return $deviceUid;
582
+	}
583 583
 }
584 584
\ No newline at end of file
Please login to merge, or discard this patch.
php/View.php 1 patch
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -2,112 +2,112 @@  discard block
 block discarded – undo
2 2
 
3 3
 class View
4 4
 {
5
-    public $country;
6
-    public $city;
7
-    public $hashtag;
5
+	public $country;
6
+	public $city;
7
+	public $hashtag;
8 8
 	public $view;
9
-    public $postId;
10
-    public $isDetailedView;
11
-    public $baseUrl;
12
-    public $rights;
9
+	public $postId;
10
+	public $isDetailedView;
11
+	public $baseUrl;
12
+	public $rights;
13 13
 
14 14
 	public $lastPostId = '';
15 15
 
16
-    function __construct($baseUrl, $country, $city, $hashtag = '%23all', $view = 'time', $postId = '')
17
-    {
18
-        $this->baseUrl = $baseUrl;
19
-        $this->country = $country;
20
-        $this->city = $city;
21
-        $this->hashtag = urldecode($hashtag);
22
-        $this->view = $view;
23
-        $this->postId = $postId;
16
+	function __construct($baseUrl, $country, $city, $hashtag = '%23all', $view = 'time', $postId = '')
17
+	{
18
+		$this->baseUrl = $baseUrl;
19
+		$this->country = $country;
20
+		$this->city = $city;
21
+		$this->hashtag = urldecode($hashtag);
22
+		$this->view = $view;
23
+		$this->postId = $postId;
24 24
 
25
-        if(isUserAdmin())
26
-        {
27
-            $this->rights = 'admin';
28
-        }
29
-        else if(isUserVoter())
30
-        {
31
-            $this->rights = 'voter';
32
-        }
33
-        else
34
-        {
35
-            $this->rights = 'user';
36
-        }
25
+		if(isUserAdmin())
26
+		{
27
+			$this->rights = 'admin';
28
+		}
29
+		else if(isUserVoter())
30
+		{
31
+			$this->rights = 'voter';
32
+		}
33
+		else
34
+		{
35
+			$this->rights = 'user';
36
+		}
37 37
 
38
-        if($postId == '')
39
-        {
40
-            $this->isDetailedView = FALSE;
41
-        }
42
-        else
43
-        {
44
-            $this->isDetailedView = TRUE;
45
-        }
46
-    }
38
+		if($postId == '')
39
+		{
40
+			$this->isDetailedView = FALSE;
41
+		}
42
+		else
43
+		{
44
+			$this->isDetailedView = TRUE;
45
+		}
46
+	}
47 47
 	/**
48 48
 	 * Compute HTML Code
49 49
 	 */
50 50
  	function jodelToHtml($post)
51
-    {   //ToDO
52
-        //Replace # with link
53
-        //preg_replace('~(\#)([^\s!,. /()"\'?]+)~', '<a href="tag/$2">#$2</a>', $text);
51
+	{   //ToDO
52
+		//Replace # with link
53
+		//preg_replace('~(\#)([^\s!,. /()"\'?]+)~', '<a href="tag/$2">#$2</a>', $text);
54 54
 
55
-        //Time to time difference
56
-        $now = new DateTime();
57
-        $d = new DateTime($post['created_at']);
58
-        $timediff = $now->diff($d);
55
+		//Time to time difference
56
+		$now = new DateTime();
57
+		$d = new DateTime($post['created_at']);
58
+		$timediff = $now->diff($d);
59 59
 
60
-        $timediff_inSeconds = (string)$timediff->format('%s');
61
-        $timediff_inMinutes = (string)$timediff->format('%i');
62
-        $timediff_inHours = (string)$timediff->format('%h');
63
-        $timediff_inDays = (string)$timediff->format('%d');
64
-        $timediff_inMonth = (string)$timediff->format('%m');
60
+		$timediff_inSeconds = (string)$timediff->format('%s');
61
+		$timediff_inMinutes = (string)$timediff->format('%i');
62
+		$timediff_inHours = (string)$timediff->format('%h');
63
+		$timediff_inDays = (string)$timediff->format('%d');
64
+		$timediff_inMonth = (string)$timediff->format('%m');
65 65
 
66
-        if($timediff_inMonth!=0)
67
-        {
68
-                $timediff = $timediff_inMonth . "m";
69
-        }
70
-        else
71
-        {
72
-            if($timediff_inDays!=0)
73
-            {
74
-                $timediff = $timediff_inDays . "d";
75
-            }
76
-            else
77
-            {
78
-                if($timediff_inHours!=0)
79
-                {
80
-                    $timediff = $timediff_inHours . "h";
81
-                }
82
-                else
83
-                {
84
-                    if($timediff_inMinutes!=0)
85
-                    {
86
-                        $timediff = $timediff_inMinutes . "m";
87
-                    }
88
-                    else
89
-                    {
90
-                        $timediff = $timediff_inSeconds . "s";
91
-                    }
92
-                }
93
-            }
94
-        }
66
+		if($timediff_inMonth!=0)
67
+		{
68
+				$timediff = $timediff_inMonth . "m";
69
+		}
70
+		else
71
+		{
72
+			if($timediff_inDays!=0)
73
+			{
74
+				$timediff = $timediff_inDays . "d";
75
+			}
76
+			else
77
+			{
78
+				if($timediff_inHours!=0)
79
+				{
80
+					$timediff = $timediff_inHours . "h";
81
+				}
82
+				else
83
+				{
84
+					if($timediff_inMinutes!=0)
85
+					{
86
+						$timediff = $timediff_inMinutes . "m";
87
+					}
88
+					else
89
+					{
90
+						$timediff = $timediff_inSeconds . "s";
91
+					}
92
+				}
93
+			}
94
+		}
95 95
 
96 96
 
97
-        ?>
97
+		?>
98 98
         <article id ="postId-<?php echo $post['post_id']; ?>" class="jodel" style="background-color: #<?php echo $post['color'];?>;">
99 99
             <content>
100 100
                 <?php 
101
-                if(isset($post['image_url']))
102
-                {
103
-                    $regexRest = '/[^\w$ .!?-]+/u';
101
+				if(isset($post['image_url']))
102
+				{
103
+					$regexRest = '/[^\w$ .!?-]+/u';
104 104
 
105
-                    echo '<img src="' . $post['image_url'] . '" alt="' . htmlspecialchars(preg_replace($regexRest, '', $post['message'])) . '">';
106
-                }
107
-                else {
108
-                    echo str_replace('  ', ' &nbsp;', nl2br(htmlspecialchars($post['message'])));
109
-                }
110
-                ?>
105
+					echo '<img src="' . $post['image_url'] . '" alt="' . htmlspecialchars(preg_replace($regexRest, '', $post['message'])) . '">';
106
+				}
107
+				else {
108
+					echo str_replace('  ', ' &nbsp;', nl2br(htmlspecialchars($post['message'])));
109
+				}
110
+				?>
111 111
             </content>
112 112
             <aside>                    
113 113
                 <button onclick="vote('<?php echo $post['post_id'];?>', 'up', this)">
@@ -136,10 +136,10 @@  discard block
 block discarded – undo
136 136
                                 <a href="<?php echo $this->changePostId($post['post_id'])->toUrl();?>">
137 137
                                     <i class="fa fa-commenting-o"></i>
138 138
                                     <?php if(array_key_exists("child_count", $post))
139
-                                    {
140
-                                        echo $post["child_count"];
141
-                                    } else echo "0";
142
-                                    ?>
139
+									{
140
+										echo $post["child_count"];
141
+									} else echo "0";
142
+									?>
143 143
                                 </a>
144 144
                             </span>
145 145
                             
@@ -159,18 +159,18 @@  discard block
 block discarded – undo
159 159
 						?>
160 160
                         <span class="distance">
161 161
                             <?php
162
-                                if($this->isDetailedView)
163
-                                {
164
-                                    if(isset($post['user_handle']) && $post['user_handle'] == 'OJ')
165
-                                    {
166
-                                        ?>
162
+								if($this->isDetailedView)
163
+								{
164
+									if(isset($post['user_handle']) && $post['user_handle'] == 'OJ')
165
+									{
166
+										?>
167 167
                                         <span data-tooltip="Author">
168 168
                                             <i class="fa fa-user-o"></i> OJ |
169 169
                                         </span>
170 170
                                         <?php 
171
-                                    }
172
-                                }
173
-                                ?>
171
+									}
172
+								}
173
+								?>
174 174
 
175 175
                             <span class="tip" data-tooltip="Distance">
176 176
                                 <i class="fa fa-map-marker"></i>
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
             </footer>
184 184
         </article>
185 185
     <?php
186
-    }
186
+	}
187 187
 
188 188
 
189 189
 	/**
@@ -220,147 +220,147 @@  discard block
 block discarded – undo
220 220
 		return $description;
221 221
 	}
222 222
 
223
-    function toUrl($msg = '')
224
-    {
225
-        $url = $this->baseUrl . 'index.php?country=DE' .
226
-                            '&city=' . urlencode($this->city) .
227
-                            '&hashtag=' . urlencode($this->hashtag) . 
228
-                            '&view=' . $this->view;
229
-        if($this->postId != '')
230
-        {
231
-            $url .= '&postId=' . $this->postId . 
232
-                    '&getPostDetails=TRUE';
233
-        }
223
+	function toUrl($msg = '')
224
+	{
225
+		$url = $this->baseUrl . 'index.php?country=DE' .
226
+							'&city=' . urlencode($this->city) .
227
+							'&hashtag=' . urlencode($this->hashtag) . 
228
+							'&view=' . $this->view;
229
+		if($this->postId != '')
230
+		{
231
+			$url .= '&postId=' . $this->postId . 
232
+					'&getPostDetails=TRUE';
233
+		}
234 234
 
235
-        if($msg != '')
236
-        {
237
-            $url .= '&msg=' . urlencode($msg);
238
-        }
235
+		if($msg != '')
236
+		{
237
+			$url .= '&msg=' . urlencode($msg);
238
+		}
239 239
 
240
-        return $url;
241
-    }
240
+		return $url;
241
+	}
242 242
 
243
-    function changePostId($postId)
244
-    {
245
-        $tempView = clone $this;
246
-        $tempView->postId = $postId;
247
-        $tempView->isDetailedView = TRUE;
248
-        return $tempView;
249
-    }
243
+	function changePostId($postId)
244
+	{
245
+		$tempView = clone $this;
246
+		$tempView->postId = $postId;
247
+		$tempView->isDetailedView = TRUE;
248
+		return $tempView;
249
+	}
250 250
 
251
-    function back()
252
-    {
253
-        $tempView = clone $this;
254
-        $tempView->postId = '';
255
-        return $tempView;
256
-    }
251
+	function back()
252
+	{
253
+		$tempView = clone $this;
254
+		$tempView->postId = '';
255
+		return $tempView;
256
+	}
257 257
 
258
-    function changeView($view)
259
-    {
260
-        $tempView = clone $this;
261
-        $tempView->view = $view;
262
-        return $tempView;
263
-    }
258
+	function changeView($view)
259
+	{
260
+		$tempView = clone $this;
261
+		$tempView->view = $view;
262
+		return $tempView;
263
+	}
264 264
 
265 265
 	function getPosts($jodelAccount)
266 266
 	{
267
-        if($this->hashtag != '#all' && $this->hashtag != '' && $this->hashtag != NULL)
268
-        {
269
-            $accountCreator = new GetChannel();
270
-            $accountCreator->view = $this->view;
271
-            $accountCreator->setAccessToken($jodelAccount->accessToken);
272
-            $accountCreator->channel = $this->hashtag;
273
-            $accountCreator->lastPostId = $this->lastPostId;
274
-            $data = $accountCreator->execute();
275
-        }
276
-        else
277
-        {
278
-            if($this->lastPostId == '' && $this->view == 'combo')
279
-            {
280
-                $url = "/v3/posts/location/combo";
281
-            }
282
-            else
283
-            {
284
-                if($this->view == 'discussed')
285
-                {
286
-                    $url = "/v2/posts/location/discussed/";
287
-                }
288
-                else
289
-                {
290
-                    if($this->view == 'popular')
291
-                    {
292
-                        $url = "/v2/posts/location/popular/";
293
-                    }
294
-                    else
295
-                    {
296
-                        $url = "/v2/posts/location/";
297
-                    }
298
-                }
299
-            }
267
+		if($this->hashtag != '#all' && $this->hashtag != '' && $this->hashtag != NULL)
268
+		{
269
+			$accountCreator = new GetChannel();
270
+			$accountCreator->view = $this->view;
271
+			$accountCreator->setAccessToken($jodelAccount->accessToken);
272
+			$accountCreator->channel = $this->hashtag;
273
+			$accountCreator->lastPostId = $this->lastPostId;
274
+			$data = $accountCreator->execute();
275
+		}
276
+		else
277
+		{
278
+			if($this->lastPostId == '' && $this->view == 'combo')
279
+			{
280
+				$url = "/v3/posts/location/combo";
281
+			}
282
+			else
283
+			{
284
+				if($this->view == 'discussed')
285
+				{
286
+					$url = "/v2/posts/location/discussed/";
287
+				}
288
+				else
289
+				{
290
+					if($this->view == 'popular')
291
+					{
292
+						$url = "/v2/posts/location/popular/";
293
+					}
294
+					else
295
+					{
296
+						$url = "/v2/posts/location/";
297
+					}
298
+				}
299
+			}
300 300
 
301
-            $accountCreator = new GetPosts();
302
-            $accountCreator->setLastPostId($this->lastPostId);
303
-            $accountCreator->setAccessToken($jodelAccount->accessToken);
304
-            $accountCreator->setUrl($url);
305
-            $accountCreator->version = 'v3';
301
+			$accountCreator = new GetPosts();
302
+			$accountCreator->setLastPostId($this->lastPostId);
303
+			$accountCreator->setAccessToken($jodelAccount->accessToken);
304
+			$accountCreator->setUrl($url);
305
+			$accountCreator->version = 'v3';
306 306
 
307
-            $config = parse_ini_file('config/config.ini.php');
308
-            $location = new Location();
309
-            $location->setLat($config['default_lat']);
310
-            $location->setLng($config['default_lng']);
311
-            $location->setCityName($config['default_location']);
312
-            $accountCreator->location = $location;
313
-            $data = $accountCreator->execute();
314
-        }
315
-    	if(is_array($data) && array_key_exists('recent', $data) && array_key_exists(0, $data['recent']))
316
-        {
317
-            return $data['recent'];
318
-        }
319
-        else if(is_array($data) && array_key_exists('posts', $data)&& array_key_exists(0, $data['posts']))
320
-        {
321
-            return $data['posts'];
322
-        }
323
-        else
324
-        {
325
-            if($this->lastPostId == '')
326
-            {
327
-                error_log('Could not find Posts in: ' . $this->city . ' Error: ' . print_r($data, true));
328
-                //error_log(print_r($data, true));
307
+			$config = parse_ini_file('config/config.ini.php');
308
+			$location = new Location();
309
+			$location->setLat($config['default_lat']);
310
+			$location->setLng($config['default_lng']);
311
+			$location->setCityName($config['default_location']);
312
+			$accountCreator->location = $location;
313
+			$data = $accountCreator->execute();
314
+		}
315
+		if(is_array($data) && array_key_exists('recent', $data) && array_key_exists(0, $data['recent']))
316
+		{
317
+			return $data['recent'];
318
+		}
319
+		else if(is_array($data) && array_key_exists('posts', $data)&& array_key_exists(0, $data['posts']))
320
+		{
321
+			return $data['posts'];
322
+		}
323
+		else
324
+		{
325
+			if($this->lastPostId == '')
326
+			{
327
+				error_log('Could not find Posts in: ' . $this->city . ' Error: ' . print_r($data, true));
328
+				//error_log(print_r($data, true));
329 329
 
330
-                $notFound[0] = array(
331
-                    "post_id" => "0",
332
-                    "discovered_by" => 0,
333
-                    "message" => "No more Posts found",
334
-                    "created_at" => "2017-02-11T16:44:50.385Z",
335
-                    "updated_at" => "2017-02-11T16:44:50.385Z",
336
-                    "pin_count" => 0,
337
-                    "color" => "5682a3",
338
-                    "got_thanks" => FALSE,
339
-                    "post_own" => "friend",
340
-                    "discovered" => 0,
341
-                    "distance" => 9,
342
-                    "vote_count" => 0,
343
-                    "location" =>
344
-                    array("name" => "Berlin",
345
-                      "loc_coordinates" =>
346
-                      array(
347
-                        "lat" => 0,
348
-                        "lng" => 0
349
-                      ),
350
-                      "loc_accuracy" => 0,
351
-                      "country" => "",
352
-                      "city" => "",
353
-                    ),
354
-                    "tags" =>
355
-                    array(),
356
-                    "user_handle" => "0"
357
-                );
358
-                return $notFound;
359
-            }
360
-            else
361
-            {
362
-                return FALSE;
363
-            }
364
-        }
330
+				$notFound[0] = array(
331
+					"post_id" => "0",
332
+					"discovered_by" => 0,
333
+					"message" => "No more Posts found",
334
+					"created_at" => "2017-02-11T16:44:50.385Z",
335
+					"updated_at" => "2017-02-11T16:44:50.385Z",
336
+					"pin_count" => 0,
337
+					"color" => "5682a3",
338
+					"got_thanks" => FALSE,
339
+					"post_own" => "friend",
340
+					"discovered" => 0,
341
+					"distance" => 9,
342
+					"vote_count" => 0,
343
+					"location" =>
344
+					array("name" => "Berlin",
345
+					  "loc_coordinates" =>
346
+					  array(
347
+						"lat" => 0,
348
+						"lng" => 0
349
+					  ),
350
+					  "loc_accuracy" => 0,
351
+					  "country" => "",
352
+					  "city" => "",
353
+					),
354
+					"tags" =>
355
+					array(),
356
+					"user_handle" => "0"
357
+				);
358
+				return $notFound;
359
+			}
360
+			else
361
+			{
362
+				return FALSE;
363
+			}
364
+		}
365 365
 	}
366 366
 }
Please login to merge, or discard this patch.
php/Requests/AbstractRequest.php 1 patch
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -2,21 +2,21 @@  discard block
 block discarded – undo
2 2
 
3 3
 abstract class AbstractRequest
4 4
 {	
5
-    const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26';
6
-    const APIURL = 'https://api.go-tellm.com/api';
7
-    const SECRET = 'bJYlFZkrnLpLMVisrbstPDNsaYHPbzcKRSpqtjtt';
8
-    const USERAGENT = 'Jodel/4.42.4 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
9
-    const CLIENT_TYPE = 'android_4.42.4';
5
+	const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26';
6
+	const APIURL = 'https://api.go-tellm.com/api';
7
+	const SECRET = 'bJYlFZkrnLpLMVisrbstPDNsaYHPbzcKRSpqtjtt';
8
+	const USERAGENT = 'Jodel/4.42.4 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
9
+	const CLIENT_TYPE = 'android_4.42.4';
10 10
     
11
-    private $accessToken = null;
12
-    private $payLoad;
13
-    public $expects = '';
14
-    public $version = 'v2';
15
-    public $hasPayload = FALSE;
11
+	private $accessToken = null;
12
+	private $payLoad;
13
+	public $expects = '';
14
+	public $version = 'v2';
15
+	public $hasPayload = FALSE;
16 16
 
17
-    public function execute()
18
-    {
19
-        $result = new \stdClass();
17
+	public function execute()
18
+	{
19
+		$result = new \stdClass();
20 20
 		        
21 21
 		$this->payLoad = $this->getPayload();
22 22
 		$device_uid = '';
@@ -25,16 +25,16 @@  discard block
 block discarded – undo
25 25
 		}
26 26
 				
27 27
 				
28
-        $this->payLoad = json_encode($this->payLoad);
29
-        $header = $this->getSignHeaders();
30
-        $url = $this->getFullUrl();
28
+		$this->payLoad = json_encode($this->payLoad);
29
+		$header = $this->getSignHeaders();
30
+		$url = $this->getFullUrl();
31 31
 
32
-        if ($this->getAccessToken()) {
33
-            $header['Authorization'] = "Bearer " . $this->getAccessToken();
34
-        }
35
-        //Comment out to debug the Request:
32
+		if ($this->getAccessToken()) {
33
+			$header['Authorization'] = "Bearer " . $this->getAccessToken();
34
+		}
35
+		//Comment out to debug the Request:
36 36
 
37
-        /*
37
+		/*
38 38
         printf("URL: ");
39 39
         var_dump($url);
40 40
         echo "<br />";
@@ -45,124 +45,124 @@  discard block
 block discarded – undo
45 45
         var_dump($this->payLoad);
46 46
         echo "<br />";
47 47
         */
48
-        /*
48
+		/*
49 49
         $options = array(
50 50
             'timeout' => 100,
51 51
             'connect_timeout' => 100,
52 52
             'proxy' => '186.103.169.165:8080',
53 53
         );*/
54 54
 
55
-        switch ($this->getMethod()) {
56
-            case 'POST':
57
-                $result = Requests::post($url, $header, $this->payLoad);
58
-                break;
59
-            case 'GET':
60
-                if($this->hasPayload)
61
-                {
62
-                    $result = Requests::get($url, $header, $this->payLoad);
63
-                }
64
-                else
65
-                {
66
-                    $result = Requests::get($url, $header);
67
-                }
68
-                break;
69
-            case 'PUT':
70
-                $result = Requests::put($url, $header, $this->payLoad);
71
-                break;
72
-        }
55
+		switch ($this->getMethod()) {
56
+			case 'POST':
57
+				$result = Requests::post($url, $header, $this->payLoad);
58
+				break;
59
+			case 'GET':
60
+				if($this->hasPayload)
61
+				{
62
+					$result = Requests::get($url, $header, $this->payLoad);
63
+				}
64
+				else
65
+				{
66
+					$result = Requests::get($url, $header);
67
+				}
68
+				break;
69
+			case 'PUT':
70
+				$result = Requests::put($url, $header, $this->payLoad);
71
+				break;
72
+		}
73 73
 
74
-        http_response_code($result->status_code);
74
+		http_response_code($result->status_code);
75 75
 
76
-        switch ($result->status_code) {
77
-            case 200:
78
-                $result = json_decode($result->body, true);
79
-                break;
80
-            case 204:
81
-                $result = 'Success';
82
-                http_response_code(200);
83
-                break;
84
-            case 400:
85
-                $result = json_decode($result->body, true);
86
-                error_log('Error 400 - ' . print_r($result, true));
87
-                break;
88
-            case 401:
76
+		switch ($result->status_code) {
77
+			case 200:
78
+				$result = json_decode($result->body, true);
79
+				break;
80
+			case 204:
81
+				$result = 'Success';
82
+				http_response_code(200);
83
+				break;
84
+			case 400:
85
+				$result = json_decode($result->body, true);
86
+				error_log('Error 400 - ' . print_r($result, true));
87
+				break;
88
+			case 401:
89 89
 
90
-                if($result == "Unauthorized")
91
-                {
92
-                    error_log("Error 401: Unauthorized");
93
-                }
94
-                else
95
-                {
96
-                    $result = json_decode($result->body, true);
90
+				if($result == "Unauthorized")
91
+				{
92
+					error_log("Error 401: Unauthorized");
93
+				}
94
+				else
95
+				{
96
+					$result = json_decode($result->body, true);
97 97
 
98
-                    if(is_array($result) && $result['error'] == 'length')
99
-                    {
98
+					if(is_array($result) && $result['error'] == 'length')
99
+					{
100 100
 
101
-                    }
102
-                    else
103
-                    {
104
-                        error_log('Error 401 - ' . print_r($result, true));
105
-                    }
106
-                }
101
+					}
102
+					else
103
+					{
104
+						error_log('Error 401 - ' . print_r($result, true));
105
+					}
106
+				}
107 107
 
108 108
 
109
-                break;
110
-            case 404:
111
-                error_log('Error 404 - ' . print_r($result, true));
112
-                $result = json_decode($result->body, true);
113
-                break;
109
+				break;
110
+			case 404:
111
+				error_log('Error 404 - ' . print_r($result, true));
112
+				$result = json_decode($result->body, true);
113
+				break;
114 114
 			case 477:
115
-                $result = json_decode($result->body, true);
116
-                error_log('Error 477 - ' . print_r($result, true));
117
-                break;
118
-            case 429:
119
-                error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true));
120
-            	exit("Error 429: Too Many Requests");
121
-            	break;
122
-            case 403:
123
-                error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true));
124
-                $result = json_decode($result->body, true);
125
-                break;
126
-            case 502:
127
-                error_log('Error 502 - ' . print_r($result, true));
128
-                $result = json_decode($result->body, true);
129
-                header('location:'.$_SERVER['PHP_SELF']);
130
-                break;
131
-            case 503:
132
-                error_log('Error 503 - ' . print_r($result, true));
133
-                $result = json_decode($result->body, true);
115
+				$result = json_decode($result->body, true);
116
+				error_log('Error 477 - ' . print_r($result, true));
117
+				break;
118
+			case 429:
119
+				error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true));
120
+				exit("Error 429: Too Many Requests");
121
+				break;
122
+			case 403:
123
+				error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true));
124
+				$result = json_decode($result->body, true);
125
+				break;
126
+			case 502:
127
+				error_log('Error 502 - ' . print_r($result, true));
128
+				$result = json_decode($result->body, true);
129
+				header('location:'.$_SERVER['PHP_SELF']);
130
+				break;
131
+			case 503:
132
+				error_log('Error 503 - ' . print_r($result, true));
133
+				$result = json_decode($result->body, true);
134 134
 
135
-                if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable')
136
-                {
137
-                    header('location:'.$_SERVER['PHP_SELF']); 
138
-                }
139
-                break;
140
-            default:
141
-                error_log('Error '.$result->status_code.' - unknown error');
142
-                $result = json_decode($result->body, true);
143
-        }
135
+				if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable')
136
+				{
137
+					header('location:'.$_SERVER['PHP_SELF']); 
138
+				}
139
+				break;
140
+			default:
141
+				error_log('Error '.$result->status_code.' - unknown error');
142
+				$result = json_decode($result->body, true);
143
+		}
144 144
 
145
-        //important for account refresh
146
-        if($device_uid != '')
147
-        {
145
+		//important for account refresh
146
+		if($device_uid != '')
147
+		{
148 148
 			$result[0] = $result;
149 149
 			$result[1] = $device_uid;
150
-        }
150
+		}
151 151
 
152 152
         
153
-        /*
153
+		/*
154 154
         var_dump($result);
155 155
         */
156 156
         
157
-        return $result;
158
-    }
159
-    abstract function getPayload();
160
-    /**
161
-     * Gets Sign headers
162
-     * @return array headers
163
-     */
164
-    private function getSignHeaders()
165
-    {
157
+		return $result;
158
+	}
159
+	abstract function getPayload();
160
+	/**
161
+	 * Gets Sign headers
162
+	 * @return array headers
163
+	 */
164
+	private function getSignHeaders()
165
+	{
166 166
 			if($this->getAccessToken() == null) {
167 167
 				$payload_accessToken = "";
168 168
 			}
@@ -171,54 +171,54 @@  discard block
 block discarded – undo
171 171
 			}
172 172
 			
173 173
 			
174
-        $headers = array(
175
-            "Connection" => "keep-alive",
176
-            "Accept-Encoding" => "gzip",
177
-            "Content-Type" => "application/json; charset=UTF-8",
178
-            "User-Agent" => self::USERAGENT
179
-        );
180
-        $timestamp = new DateTime();
181
-        $timestamp = $timestamp->format(DateTime::ATOM);
182
-        $timestamp = substr($timestamp, 0, -6);
183
-        $timestamp .= "Z";
184
-        $urlParts = parse_url($this->getFullUrl());
185
-        $url2 = "";
186
-        $req = [$this->getMethod(),
187
-            $urlParts['host'],
188
-            "443",
189
-            $urlParts['path'],
190
-            $payload_accessToken,
191
-            $timestamp,
192
-            $url2,
193
-            $this->payLoad];
194
-        $reqString = implode("%", $req);
195
-        $secret = self::SECRET;
196
-        $signature = hash_hmac('sha1', $reqString, $secret);
197
-        $signature = strtoupper($signature);
198
-        $headers['X-Authorization'] = 'HMAC ' . $signature;
199
-        $headers['X-Client-Type'] = self::CLIENT_TYPE;
200
-        $headers['X-Timestamp'] = $timestamp;
201
-        $headers['X-Api-Version'] = '0.2';
202
-        return $headers;
203
-    }
204
-    private function getFullUrl()
205
-    {
206
-        return self::APIURL . $this->getApiEndPoint();
207
-    }
208
-    abstract function getApiEndPoint();
209
-    abstract function getMethod();
210
-    /**
211
-     * @return string
212
-     */
213
-    private function getAccessToken()
214
-    {
215
-        return $this->accessToken;
216
-    }
217
-    /**
218
-     * @param string $accessToken
219
-     */
220
-    public function setAccessToken($accessToken)
221
-    {
222
-        $this->accessToken = $accessToken;
223
-    }
174
+		$headers = array(
175
+			"Connection" => "keep-alive",
176
+			"Accept-Encoding" => "gzip",
177
+			"Content-Type" => "application/json; charset=UTF-8",
178
+			"User-Agent" => self::USERAGENT
179
+		);
180
+		$timestamp = new DateTime();
181
+		$timestamp = $timestamp->format(DateTime::ATOM);
182
+		$timestamp = substr($timestamp, 0, -6);
183
+		$timestamp .= "Z";
184
+		$urlParts = parse_url($this->getFullUrl());
185
+		$url2 = "";
186
+		$req = [$this->getMethod(),
187
+			$urlParts['host'],
188
+			"443",
189
+			$urlParts['path'],
190
+			$payload_accessToken,
191
+			$timestamp,
192
+			$url2,
193
+			$this->payLoad];
194
+		$reqString = implode("%", $req);
195
+		$secret = self::SECRET;
196
+		$signature = hash_hmac('sha1', $reqString, $secret);
197
+		$signature = strtoupper($signature);
198
+		$headers['X-Authorization'] = 'HMAC ' . $signature;
199
+		$headers['X-Client-Type'] = self::CLIENT_TYPE;
200
+		$headers['X-Timestamp'] = $timestamp;
201
+		$headers['X-Api-Version'] = '0.2';
202
+		return $headers;
203
+	}
204
+	private function getFullUrl()
205
+	{
206
+		return self::APIURL . $this->getApiEndPoint();
207
+	}
208
+	abstract function getApiEndPoint();
209
+	abstract function getMethod();
210
+	/**
211
+	 * @return string
212
+	 */
213
+	private function getAccessToken()
214
+	{
215
+		return $this->accessToken;
216
+	}
217
+	/**
218
+	 * @param string $accessToken
219
+	 */
220
+	public function setAccessToken($accessToken)
221
+	{
222
+		$this->accessToken = $accessToken;
223
+	}
224 224
 }
Please login to merge, or discard this patch.