Completed
Push — master ( 306300...8aacdd )
by mains
02:51
created
php/JodelAccount.php 1 patch
Indentation   +399 added lines, -399 removed lines patch added patch discarded remove patch
@@ -2,445 +2,445 @@
 block discarded – undo
2 2
 
3 3
 class JodelAccount
4 4
 {
5
-    public $accessToken;
6
-    public $expirationDate;
7
-    public $refreshToken;
8
-    public $distinctId;
9
-    public $deviceUid;
10
-
11
-    //is the Account a Bot or Spider?
12
-    public $isBot;
5
+	public $accessToken;
6
+	public $expirationDate;
7
+	public $refreshToken;
8
+	public $distinctId;
9
+	public $deviceUid;
10
+
11
+	//is the Account a Bot or Spider?
12
+	public $isBot;
13 13
     
14
-    // array of voted Jodels
15
-    public $votes;
16
-
17
-    //Location of the Account
18
-    public $location;
19
-
20
-    function __construct($deviceUid = NULL, $isBot = FALSE)
21
-    {
22
-        if($deviceUid == NULL)
23
-        {
24
-            $this->deviceUid = $this->createAccount();
25
-        }
26
-        else
27
-        {
28
-            $this->deviceUid = $deviceUid;
29
-        }
30
-
31
-        $this->isBot        = $isBot;
32
-        $this->location     = $this->getLocation();
33
-
34
-        if(!$this->isTokenFresh())
35
-        {
36
-            $this->refreshToken();
37
-        }
38
-        $this->accessToken  = $this->getAccessToken();
39
-    }
40
-
41
-    function isAccountVerified()
42
-    {
43
-        $accountCreator = new GetUserConfig();
44
-        $accountCreator->setAccessToken($this->accessToken);
45
-        $data = $accountCreator->execute();
46
-
47
-        return $data['verified'];
48
-    }
49
-
50
-    function setLocation()
51
-    {
52
-        //Is Channel or City
53
-        if(substr($_GET['city'], 0, 1) === '#')
54
-        {
55
-            return htmlspecialchars($_GET['city']) . " " . $this->location->cityName;
56
-        }                
57
-        else
58
-        {
59
-            $url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($_GET['city']) . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w';
60
-            $result = Requests::post($url);
61
-            if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST')
62
-            {
63
-                return "0 results";
64
-            }
65
-            else
66
-            {
67
-                $name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name'];
68
-                $lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat'];
69
-                $lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng'];
70
-
71
-                $location = new Location();
72
-                $location->setLat($lat);
73
-                $location->setLng($lng);
74
-                $location->setCityName($name);
75
-                $accountCreator = new UpdateLocation();
76
-                $accountCreator->setLocation($location);
77
-                $accountCreator->setAccessToken($this->accessToken);
78
-                $data = $accountCreator->execute();
79
-
80
-                //safe location to db
81
-                $db = new DatabaseConnect();
82
-
83
-                if($data == 'Success')
84
-                {
85
-                    $result = $db->query("UPDATE accounts 
14
+	// array of voted Jodels
15
+	public $votes;
16
+
17
+	//Location of the Account
18
+	public $location;
19
+
20
+	function __construct($deviceUid = NULL, $isBot = FALSE)
21
+	{
22
+		if($deviceUid == NULL)
23
+		{
24
+			$this->deviceUid = $this->createAccount();
25
+		}
26
+		else
27
+		{
28
+			$this->deviceUid = $deviceUid;
29
+		}
30
+
31
+		$this->isBot        = $isBot;
32
+		$this->location     = $this->getLocation();
33
+
34
+		if(!$this->isTokenFresh())
35
+		{
36
+			$this->refreshToken();
37
+		}
38
+		$this->accessToken  = $this->getAccessToken();
39
+	}
40
+
41
+	function isAccountVerified()
42
+	{
43
+		$accountCreator = new GetUserConfig();
44
+		$accountCreator->setAccessToken($this->accessToken);
45
+		$data = $accountCreator->execute();
46
+
47
+		return $data['verified'];
48
+	}
49
+
50
+	function setLocation()
51
+	{
52
+		//Is Channel or City
53
+		if(substr($_GET['city'], 0, 1) === '#')
54
+		{
55
+			return htmlspecialchars($_GET['city']) . " " . $this->location->cityName;
56
+		}                
57
+		else
58
+		{
59
+			$url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($_GET['city']) . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w';
60
+			$result = Requests::post($url);
61
+			if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST')
62
+			{
63
+				return "0 results";
64
+			}
65
+			else
66
+			{
67
+				$name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name'];
68
+				$lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat'];
69
+				$lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng'];
70
+
71
+				$location = new Location();
72
+				$location->setLat($lat);
73
+				$location->setLng($lng);
74
+				$location->setCityName($name);
75
+				$accountCreator = new UpdateLocation();
76
+				$accountCreator->setLocation($location);
77
+				$accountCreator->setAccessToken($this->accessToken);
78
+				$data = $accountCreator->execute();
79
+
80
+				//safe location to db
81
+				$db = new DatabaseConnect();
82
+
83
+				if($data == 'Success')
84
+				{
85
+					$result = $db->query("UPDATE accounts 
86 86
                             SET name='" . $name . "',
87 87
                                 lat='" . $lat . "',
88 88
                                 lng='" . $lng . "'
89 89
                             WHERE access_token='" . $this->accessToken . "'");
90 90
 
91
-                    if($result === false)
92
-                    {
93
-                            echo "Updating location failed: (" . $db->errno . ") " . $db->error;
94
-                    }
95
-                    else
96
-                    {
97
-                        error_log('User with JodelDeviceId:' . $this->deviceUid .  ' [' . $_SERVER['REMOTE_ADDR'] . '][' . $_SERVER ['HTTP_USER_AGENT'] . '] changed to Location: ' . $name);
98
-                    }
99
-                }
100
-
101
-                return $name;
102
-            }
103
-        }
104
-    }
105
-
106
-    function getLocation()
107
-    {
108
-        $db = new DatabaseConnect();
109
-        $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid  . "'");
91
+					if($result === false)
92
+					{
93
+							echo "Updating location failed: (" . $db->errno . ") " . $db->error;
94
+					}
95
+					else
96
+					{
97
+						error_log('User with JodelDeviceId:' . $this->deviceUid .  ' [' . $_SERVER['REMOTE_ADDR'] . '][' . $_SERVER ['HTTP_USER_AGENT'] . '] changed to Location: ' . $name);
98
+					}
99
+				}
100
+
101
+				return $name;
102
+			}
103
+		}
104
+	}
105
+
106
+	function getLocation()
107
+	{
108
+		$db = new DatabaseConnect();
109
+		$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid  . "'");
110 110
         
111
-        $location = new Location();
111
+		$location = new Location();
112 112
         
113
-        if ($result->num_rows > 0)
114
-        {
115
-            // output data of each row
116
-            while($row = $result->fetch_assoc())
117
-            {
118
-                $location->setLat($row['lat']);
119
-                $location->setLng($row['lng']);
120
-                $location->setCityName($row['name']);
121
-            }
122
-        }
123
-        else
124
-        {
125
-            echo "Error: 0 results";
126
-            error_log("Error no Location found - getLocation");
127
-        }
128
-
129
-        return $location;
130
-    }
131
-
132
-    function verifyCaptcha()
133
-    {
134
-        if(isset($_GET['deviceUid']))
135
-        {
136
-            $deviceUid = $_GET['deviceUid'];
137
-        }
138
-        if(isset($_POST['deviceUid']))
139
-        {
140
-            $deviceUid = $_POST['deviceUid'];
141
-        }
142
-        $jodelAccountForVerify = new JodelAccount($deviceUid);
143
-
144
-        $solution = $_GET['solution'];
145
-        $solution = array_map('intval', explode('-', $solution));
146
-
147
-        $accountCreator = new PostCaptcha();
148
-        $accountCreator->setAccessToken($jodelAccountForVerify->accessToken);
149
-        $accountCreator->captchaKey = $_GET['key'];
150
-        $accountCreator->captchaSolution = $solution;
151
-        $verified = $accountCreator->execute();
152
-
153
-        if(isset($verified->status_code))
154
-        {
155
-            return $verified->status_code;
156
-        }
157
-        return $verified['verified'];
158
-    }
159
-
160
-    //ToDo Spider Check
161
-    function votePostId($postId, $vote)
162
-    {
163
-        if(!$this->isAccountVerified())
164
-        {
165
-            $view = new View();
166
-            $view->showCaptcha($this->accessToken, $this->deviceUid);
167
-        }
168
-
169
-        if(!$this->deviceUidHasVotedThisPostId($postId))
170
-        {
171
-            if($vote == "up")
172
-            {
173
-                $accountCreator = new Upvote();
174
-            }
175
-            else if($vote == "down")
176
-            {
177
-                $accountCreator = new Downvote();
178
-            }
179
-            $accountCreator->setAccessToken($this->accessToken);
180
-            $accountCreator->postId = htmlspecialchars($postId);
181
-            $data = $accountCreator->execute();
182
-
183
-            if(array_key_exists('post', $data))
184
-            {
185
-                $this->addVoteWithPostIdAndTypeToDeviceUid($postId, $vote);
186
-                return TRUE;
187
-            }
188
-            else
189
-            {
190
-                return FALSE;
191
-                error_log("Could not vote: " . var_dump($data));
192
-            } 
193
-        }
194
-    }
195
-
196
-    //ToDo Spider Check
197
-    function sendJodel()
198
-    {
199
-        if(!$this->isAccountVerified())
200
-        {
201
-            showCaptcha($this->accessToken);
202
-        }
203
-
204
-        $accountCreator = new SendJodel();
205
-
206
-        if(isset($_POST['ancestor']))
207
-        {
208
-            $ancestor = $_POST['ancestor'];
209
-            $accountCreator->ancestor = $ancestor;
210
-        }
211
-        if(isset($_POST['color']))
212
-        {
213
-            $color = $_POST['color'];
214
-            switch ($color) {
215
-                case '8ABDB0':
216
-                    $color = '8ABDB0';
217
-                    break;
218
-                case '9EC41C':
219
-                    $color = '9EC41C';
220
-                    break;
221
-                case '06A3CB':
222
-                    $color = '06A3CB';
223
-                    break;
224
-                case 'FFBA00':
225
-                    $color = 'FFBA00';
226
-                    break;
227
-                case 'DD5F5F':
228
-                    $color = 'DD5F5F';
229
-                    break;
230
-                case 'FF9908':
231
-                    $color = 'FF9908';
232
-                    break;
233
-                default:
234
-                    $color = '8ABDB0';
235
-                    break;
236
-            }
237
-            $accountCreator->color = $color;
238
-        }
239
-
240
-        $accountCreatorLocation = new UpdateLocation();
241
-        $accountCreatorLocation->setLocation($this->location);
242
-        $accountCreatorLocation->setAccessToken($this->accessToken);
243
-        $data = $accountCreatorLocation->execute();
113
+		if ($result->num_rows > 0)
114
+		{
115
+			// output data of each row
116
+			while($row = $result->fetch_assoc())
117
+			{
118
+				$location->setLat($row['lat']);
119
+				$location->setLng($row['lng']);
120
+				$location->setCityName($row['name']);
121
+			}
122
+		}
123
+		else
124
+		{
125
+			echo "Error: 0 results";
126
+			error_log("Error no Location found - getLocation");
127
+		}
128
+
129
+		return $location;
130
+	}
131
+
132
+	function verifyCaptcha()
133
+	{
134
+		if(isset($_GET['deviceUid']))
135
+		{
136
+			$deviceUid = $_GET['deviceUid'];
137
+		}
138
+		if(isset($_POST['deviceUid']))
139
+		{
140
+			$deviceUid = $_POST['deviceUid'];
141
+		}
142
+		$jodelAccountForVerify = new JodelAccount($deviceUid);
143
+
144
+		$solution = $_GET['solution'];
145
+		$solution = array_map('intval', explode('-', $solution));
146
+
147
+		$accountCreator = new PostCaptcha();
148
+		$accountCreator->setAccessToken($jodelAccountForVerify->accessToken);
149
+		$accountCreator->captchaKey = $_GET['key'];
150
+		$accountCreator->captchaSolution = $solution;
151
+		$verified = $accountCreator->execute();
152
+
153
+		if(isset($verified->status_code))
154
+		{
155
+			return $verified->status_code;
156
+		}
157
+		return $verified['verified'];
158
+	}
159
+
160
+	//ToDo Spider Check
161
+	function votePostId($postId, $vote)
162
+	{
163
+		if(!$this->isAccountVerified())
164
+		{
165
+			$view = new View();
166
+			$view->showCaptcha($this->accessToken, $this->deviceUid);
167
+		}
168
+
169
+		if(!$this->deviceUidHasVotedThisPostId($postId))
170
+		{
171
+			if($vote == "up")
172
+			{
173
+				$accountCreator = new Upvote();
174
+			}
175
+			else if($vote == "down")
176
+			{
177
+				$accountCreator = new Downvote();
178
+			}
179
+			$accountCreator->setAccessToken($this->accessToken);
180
+			$accountCreator->postId = htmlspecialchars($postId);
181
+			$data = $accountCreator->execute();
182
+
183
+			if(array_key_exists('post', $data))
184
+			{
185
+				$this->addVoteWithPostIdAndTypeToDeviceUid($postId, $vote);
186
+				return TRUE;
187
+			}
188
+			else
189
+			{
190
+				return FALSE;
191
+				error_log("Could not vote: " . var_dump($data));
192
+			} 
193
+		}
194
+	}
195
+
196
+	//ToDo Spider Check
197
+	function sendJodel()
198
+	{
199
+		if(!$this->isAccountVerified())
200
+		{
201
+			showCaptcha($this->accessToken);
202
+		}
203
+
204
+		$accountCreator = new SendJodel();
205
+
206
+		if(isset($_POST['ancestor']))
207
+		{
208
+			$ancestor = $_POST['ancestor'];
209
+			$accountCreator->ancestor = $ancestor;
210
+		}
211
+		if(isset($_POST['color']))
212
+		{
213
+			$color = $_POST['color'];
214
+			switch ($color) {
215
+				case '8ABDB0':
216
+					$color = '8ABDB0';
217
+					break;
218
+				case '9EC41C':
219
+					$color = '9EC41C';
220
+					break;
221
+				case '06A3CB':
222
+					$color = '06A3CB';
223
+					break;
224
+				case 'FFBA00':
225
+					$color = 'FFBA00';
226
+					break;
227
+				case 'DD5F5F':
228
+					$color = 'DD5F5F';
229
+					break;
230
+				case 'FF9908':
231
+					$color = 'FF9908';
232
+					break;
233
+				default:
234
+					$color = '8ABDB0';
235
+					break;
236
+			}
237
+			$accountCreator->color = $color;
238
+		}
239
+
240
+		$accountCreatorLocation = new UpdateLocation();
241
+		$accountCreatorLocation->setLocation($this->location);
242
+		$accountCreatorLocation->setAccessToken($this->accessToken);
243
+		$data = $accountCreatorLocation->execute();
244 244
         
245
-        $accountCreator->location = $this->location;
245
+		$accountCreator->location = $this->location;
246 246
         
247
-        $accountCreator->setAccessToken($this->accessToken);
248
-        $data = $accountCreator->execute();
249
-
250
-        if(isset($_POST['ancestor']))
251
-        {
252
-            $actual_link = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
253
-            header('Location: ' . $actual_link . '#postId-' . htmlspecialchars($data['post_id']));
254
-            exit;
255
-        }
256
-        else
257
-        {
258
-            header('Location: ./#');
259
-            exit;
260
-        }
261
-    }
262
-
263
-    function isTokenFresh()
264
-    {
265
-        $db = new DatabaseConnect();  
266
-        $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'");
267
-
268
-        $access_token;
269
-
270
-        if ($result->num_rows > 0)
271
-        {
272
-                // output data of each row
273
-                while($row = $result->fetch_assoc()) {
274
-                        //$access_token = $row["access_token"];
275
-                        $expiration_date = $row["expiration_date"];
276
-                        $deviceUid = $row["device_uid"];
277
-                        $access_token = $row["access_token"];
278
-                }
279
-        }
280
-        else
281
-        {
282
-                echo '0 results';
283
-        }
284
-
285
-        if($expiration_date <= time()) {
286
-            $accountCreator = new CreateUser();
287
-            $accountCreator->setAccessToken($access_token);
288
-            $accountCreator->setDeviceUid($deviceUid);
289
-            $accountCreator->setLocation($this->location);
290
-            $data = $accountCreator->execute();
291
-
292
-            $access_token = (string)$data[0]['access_token'];
293
-            $expiration_date = $data[0]['expiration_date'];
294
-            $device_uid = (string)$data[1];
247
+		$accountCreator->setAccessToken($this->accessToken);
248
+		$data = $accountCreator->execute();
249
+
250
+		if(isset($_POST['ancestor']))
251
+		{
252
+			$actual_link = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
253
+			header('Location: ' . $actual_link . '#postId-' . htmlspecialchars($data['post_id']));
254
+			exit;
255
+		}
256
+		else
257
+		{
258
+			header('Location: ./#');
259
+			exit;
260
+		}
261
+	}
262
+
263
+	function isTokenFresh()
264
+	{
265
+		$db = new DatabaseConnect();  
266
+		$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'");
267
+
268
+		$access_token;
269
+
270
+		if ($result->num_rows > 0)
271
+		{
272
+				// output data of each row
273
+				while($row = $result->fetch_assoc()) {
274
+						//$access_token = $row["access_token"];
275
+						$expiration_date = $row["expiration_date"];
276
+						$deviceUid = $row["device_uid"];
277
+						$access_token = $row["access_token"];
278
+				}
279
+		}
280
+		else
281
+		{
282
+				echo '0 results';
283
+		}
284
+
285
+		if($expiration_date <= time()) {
286
+			$accountCreator = new CreateUser();
287
+			$accountCreator->setAccessToken($access_token);
288
+			$accountCreator->setDeviceUid($deviceUid);
289
+			$accountCreator->setLocation($this->location);
290
+			$data = $accountCreator->execute();
291
+
292
+			$access_token = (string)$data[0]['access_token'];
293
+			$expiration_date = $data[0]['expiration_date'];
294
+			$device_uid = (string)$data[1];
295 295
             
296
-            $db = new DatabaseConnect();  
297
-            $result = $db->query("UPDATE accounts 
296
+			$db = new DatabaseConnect();  
297
+			$result = $db->query("UPDATE accounts 
298 298
                                     SET access_token='" . $access_token . "',
299 299
                                         expiration_date='" . $expiration_date . "'
300 300
                                     WHERE device_uid='" . $device_uid . "'");
301 301
 
302
-            if($result === false){
303
-                    echo "Adding account failed: (" . $db->errno . ") " . $db->error;
304
-            }   
305
-        }
302
+			if($result === false){
303
+					echo "Adding account failed: (" . $db->errno . ") " . $db->error;
304
+			}   
305
+		}
306 306
         
307
-        return $access_token;
308
-    }
307
+		return $access_token;
308
+	}
309 309
 
310
-    function refreshToken()
311
-    {
310
+	function refreshToken()
311
+	{
312 312
 
313
-    }
313
+	}
314 314
 
315 315
 
316 316
 
317
-    function getAccessToken()
318
-    {
319
-        $db = new DatabaseConnect();
320
-        $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid  . "'");
317
+	function getAccessToken()
318
+	{
319
+		$db = new DatabaseConnect();
320
+		$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid  . "'");
321 321
         
322
-        $accessToken;
322
+		$accessToken;
323 323
         
324
-        if ($result->num_rows > 0)
325
-        {
326
-            // output data of each row
327
-            while($row = $result->fetch_assoc())
328
-            {
329
-                $accessToken = $row['access_token'];
330
-            }
331
-        }
332
-        else
333
-        {
334
-            echo "Error: 0 results";
335
-        }
336
-
337
-        return $accessToken;
338
-    }
339
-
340
-
341
-    function getKarma()
342
-    {
343
-        $accountCreator = new GetKarma();
344
-        $accountCreator->setAccessToken($this->accessToken);
345
-        $data = $accountCreator->execute();
324
+		if ($result->num_rows > 0)
325
+		{
326
+			// output data of each row
327
+			while($row = $result->fetch_assoc())
328
+			{
329
+				$accessToken = $row['access_token'];
330
+			}
331
+		}
332
+		else
333
+		{
334
+			echo "Error: 0 results";
335
+		}
336
+
337
+		return $accessToken;
338
+	}
339
+
340
+
341
+	function getKarma()
342
+	{
343
+		$accountCreator = new GetKarma();
344
+		$accountCreator->setAccessToken($this->accessToken);
345
+		$data = $accountCreator->execute();
346 346
         
347
-        return $data["karma"];
348
-    }
347
+		return $data["karma"];
348
+	}
349 349
 
350
-    function deviceUidHasVotedThisPostId($postId)
351
-    {
352
-        $db = new DatabaseConnect();
350
+	function deviceUidHasVotedThisPostId($postId)
351
+	{
352
+		$db = new DatabaseConnect();
353 353
 
354
-        $postId = $db->real_escape_string($postId);
354
+		$postId = $db->real_escape_string($postId);
355 355
 
356
-        $result = $db->query("SELECT id
356
+		$result = $db->query("SELECT id
357 357
                               FROM votes
358 358
                               WHERE (postId = '" . $postId . "' AND device_uid = '" . $this->deviceUid . "')");
359 359
         
360
-        if($result === false)
361
-        {
362
-            $error = db_error();
363
-            echo $error;
364
-            echo "Adding Vote failed: (" . $result->errno . ") " . $result->error;
365
-        }
366
-
367
-        if($result->num_rows == 0)
368
-        {
369
-            return FALSE;
370
-        }
371
-        else
372
-        {
373
-            return TRUE;
374
-        }
375
-    }
376
-
377
-    function addVoteWithPostIdAndTypeToDeviceUid($postId, $voteType)
378
-    {
379
-        $db = new DatabaseConnect();  
380
-
381
-        $postId = $db->real_escape_string($postId);
382
-        $voteType = $db->real_escape_string($voteType);
360
+		if($result === false)
361
+		{
362
+			$error = db_error();
363
+			echo $error;
364
+			echo "Adding Vote failed: (" . $result->errno . ") " . $result->error;
365
+		}
366
+
367
+		if($result->num_rows == 0)
368
+		{
369
+			return FALSE;
370
+		}
371
+		else
372
+		{
373
+			return TRUE;
374
+		}
375
+	}
376
+
377
+	function addVoteWithPostIdAndTypeToDeviceUid($postId, $voteType)
378
+	{
379
+		$db = new DatabaseConnect();  
380
+
381
+		$postId = $db->real_escape_string($postId);
382
+		$voteType = $db->real_escape_string($voteType);
383 383
         
384
-        if($this->deviceUidHasVotedThisPostId($postId))
385
-        {
386
-            return "Already voted";
387
-        }
384
+		if($this->deviceUidHasVotedThisPostId($postId))
385
+		{
386
+			return "Already voted";
387
+		}
388 388
 
389
-        $result = $db->query("INSERT INTO votes (device_uid, postId, type)
389
+		$result = $db->query("INSERT INTO votes (device_uid, postId, type)
390 390
                         VALUES ('" . $this->deviceUid . "','" . $postId . "','" . $voteType . "')");
391 391
         
392
-        if($result === false){
393
-                $error = db_error();
394
-                echo $error;
395
-                echo "Adding Vote failed: (" . $result->errno . ") " . $result->error;
396
-        }       
397
-    }
398
-
399
-    function registerAccount($location) {
400
-        $accountCreator = new CreateUser();
401
-        $accountCreator->setLocation($location);
402
-        $data = $accountCreator->execute();
392
+		if($result === false){
393
+				$error = db_error();
394
+				echo $error;
395
+				echo "Adding Vote failed: (" . $result->errno . ") " . $result->error;
396
+		}       
397
+	}
398
+
399
+	function registerAccount($location) {
400
+		$accountCreator = new CreateUser();
401
+		$accountCreator->setLocation($location);
402
+		$data = $accountCreator->execute();
403 403
         
404
-        $access_token = (string)$data[0]['access_token'];
405
-        $refresh_token = (string)$data[0]['refresh_token'];
406
-        $token_type = (string)$data[0]['token_type'];
407
-        $expires_in = $data[0]['expires_in'];
408
-        $expiration_date = $data[0]['expiration_date'];
409
-        $distinct_id = (string)$data[0]['distinct_id'];
410
-        $device_uid = (string)$data[1];
411
-
412
-        $name = $location->cityName;
413
-        $lat = $location->lat;
414
-        $lng = $location->lng;
404
+		$access_token = (string)$data[0]['access_token'];
405
+		$refresh_token = (string)$data[0]['refresh_token'];
406
+		$token_type = (string)$data[0]['token_type'];
407
+		$expires_in = $data[0]['expires_in'];
408
+		$expiration_date = $data[0]['expiration_date'];
409
+		$distinct_id = (string)$data[0]['distinct_id'];
410
+		$device_uid = (string)$data[1];
411
+
412
+		$name = $location->cityName;
413
+		$lat = $location->lat;
414
+		$lng = $location->lng;
415 415
         
416
-        $db = new DatabaseConnect();  
417
-        $result = $db->query("INSERT INTO accounts (access_token, refresh_token, token_type,
416
+		$db = new DatabaseConnect();  
417
+		$result = $db->query("INSERT INTO accounts (access_token, refresh_token, token_type,
418 418
                         expires_in, expiration_date, distinct_id, device_uid, name, lat, lng)
419 419
                         VALUES ('" . $access_token . "','" . $refresh_token . "','" . $token_type .
420
-                        "','" .  $expires_in . "','" . $expiration_date . "','" . $distinct_id .
421
-                        "','" . $device_uid . "','" . $name . "','" . $lat . "','" . $lng . "') ");
422
-
423
-        $success = TRUE;
424
-        if($result === false){
425
-                $error = db_error();
426
-                echo $error;
427
-                echo "Adding account failed: (" . $result->errno . ") " . $result->error;
428
-                $success = FALSE;
429
-        }   
420
+						"','" .  $expires_in . "','" . $expiration_date . "','" . $distinct_id .
421
+						"','" . $device_uid . "','" . $name . "','" . $lat . "','" . $lng . "') ");
422
+
423
+		$success = TRUE;
424
+		if($result === false){
425
+				$error = db_error();
426
+				echo $error;
427
+				echo "Adding account failed: (" . $result->errno . ") " . $result->error;
428
+				$success = FALSE;
429
+		}   
430 430
         
431
-        return $device_uid;
432
-    }
431
+		return $device_uid;
432
+	}
433 433
 
434
-    function createAccount()
435
-    {
436
-        $config = parse_ini_file('config/config.ini.php');
437
-        $location = new Location();
438
-        $location->setLat($config['default_lat']);
439
-        $location->setLng($config['default_lng']);
440
-        $location->setCityName($config['default_location']);
434
+	function createAccount()
435
+	{
436
+		$config = parse_ini_file('config/config.ini.php');
437
+		$location = new Location();
438
+		$location->setLat($config['default_lat']);
439
+		$location->setLng($config['default_lng']);
440
+		$location->setCityName($config['default_location']);
441 441
 
442
-        $deviceUid = $this->registerAccount($location);
442
+		$deviceUid = $this->registerAccount($location);
443 443
 
444
-        return $deviceUid;
445
-    }
444
+		return $deviceUid;
445
+	}
446 446
 }
447 447
\ No newline at end of file
Please login to merge, or discard this patch.
php/View.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -9,75 +9,75 @@  discard block
 block discarded – undo
9 9
 	 * Compute HTML Code
10 10
 	 */
11 11
  	function jodelToHtml($post, $view = 'time', $isDetailedView = FALSE)
12
-    {   //ToDO
13
-        //Replace # with link
14
-        //preg_replace('~(\#)([^\s!,. /()"\'?]+)~', '<a href="tag/$2">#$2</a>', $text);
15
-
16
-        //Time to time difference
17
-        $now = new DateTime();
18
-        $d = new DateTime($post['created_at']);
19
-        $timediff = $now->diff($d);
20
-
21
-        $timediff_inSeconds = (string)$timediff->format('%s');
22
-        $timediff_inMinutes = (string)$timediff->format('%i');
23
-        $timediff_inHours = (string)$timediff->format('%h');
24
-        $timediff_inDays = (string)$timediff->format('%d');
25
-        $timediff_inMonth = (string)$timediff->format('%m');
26
-
27
-        if($timediff_inMonth!=0)
28
-        {
29
-                $timediff = $timediff_inMonth . "m";
30
-        }
31
-        else
32
-        {
33
-            if($timediff_inDays!=0)
34
-            {
35
-                $timediff = $timediff_inDays . "d";
36
-            }
37
-            else
38
-            {
39
-                if($timediff_inHours!=0)
40
-                {
41
-                    $timediff = $timediff_inHours . "h";
42
-                }
43
-                else
44
-                {
45
-                    if($timediff_inMinutes!=0)
46
-                    {
47
-                        $timediff = $timediff_inMinutes . "m";
48
-                    }
49
-                    else
50
-                    {
51
-                        $timediff = $timediff_inSeconds . "s";
52
-                    }
53
-                }
54
-            }
55
-        }
56
-
57
-
58
-        ?>
12
+	{   //ToDO
13
+		//Replace # with link
14
+		//preg_replace('~(\#)([^\s!,. /()"\'?]+)~', '<a href="tag/$2">#$2</a>', $text);
15
+
16
+		//Time to time difference
17
+		$now = new DateTime();
18
+		$d = new DateTime($post['created_at']);
19
+		$timediff = $now->diff($d);
20
+
21
+		$timediff_inSeconds = (string)$timediff->format('%s');
22
+		$timediff_inMinutes = (string)$timediff->format('%i');
23
+		$timediff_inHours = (string)$timediff->format('%h');
24
+		$timediff_inDays = (string)$timediff->format('%d');
25
+		$timediff_inMonth = (string)$timediff->format('%m');
26
+
27
+		if($timediff_inMonth!=0)
28
+		{
29
+				$timediff = $timediff_inMonth . "m";
30
+		}
31
+		else
32
+		{
33
+			if($timediff_inDays!=0)
34
+			{
35
+				$timediff = $timediff_inDays . "d";
36
+			}
37
+			else
38
+			{
39
+				if($timediff_inHours!=0)
40
+				{
41
+					$timediff = $timediff_inHours . "h";
42
+				}
43
+				else
44
+				{
45
+					if($timediff_inMinutes!=0)
46
+					{
47
+						$timediff = $timediff_inMinutes . "m";
48
+					}
49
+					else
50
+					{
51
+						$timediff = $timediff_inSeconds . "s";
52
+					}
53
+				}
54
+			}
55
+		}
56
+
57
+
58
+		?>
59 59
         <article id ="postId-<?php echo $post['post_id']; ?>" class="jodel" style="background-color: #<?php echo $post['color'];?>;">
60 60
             <content>
61 61
                 <?php 
62
-                if(isset($post['image_url']))
63
-                {
64
-                    $regexRest = '/[^\w$ .!?-]+/u';
65
-
66
-                    echo '<img src="' . $post['image_url'] . '" alt="' . htmlspecialchars(preg_replace($regexRest, '', $post['message'])) . '">';
67
-                }
68
-                else {
69
-                    echo str_replace('  ', ' &nbsp;', nl2br(htmlspecialchars($post['message'])));
70
-                }
71
-                ?>
62
+				if(isset($post['image_url']))
63
+				{
64
+					$regexRest = '/[^\w$ .!?-]+/u';
65
+
66
+					echo '<img src="' . $post['image_url'] . '" alt="' . htmlspecialchars(preg_replace($regexRest, '', $post['message'])) . '">';
67
+				}
68
+				else {
69
+					echo str_replace('  ', ' &nbsp;', nl2br(htmlspecialchars($post['message'])));
70
+				}
71
+				?>
72 72
             </content>
73 73
             <aside>
74 74
                 <?php
75
-                    if($isDetailedView)
76
-                    {?>
75
+					if($isDetailedView)
76
+					{?>
77 77
                         <a href="index.php?vote=up&getPostDetails=true&postId=<?php echo $post['post_id'];?>&postId_parent=<?php echo htmlspecialchars($_GET['postId']);?>" rel="nofollow">
78 78
               <?php }
79
-                    else
80
-                    {?>
79
+					else
80
+					{?>
81 81
                         <a href="index.php?vote=up&postId=<?php echo $post['post_id'];?>" rel="nofollow">
82 82
               <?php } ?>
83 83
                             <i class="fa fa-angle-up fa-3x"></i>
@@ -85,12 +85,12 @@  discard block
 block discarded – undo
85 85
                             <br />
86 86
                         <?php echo $post["vote_count"];?><br />
87 87
                 <?php
88
-                    if($isDetailedView)
89
-                    {?>
88
+					if($isDetailedView)
89
+					{?>
90 90
                         <a href="index.php?vote=down&getPostDetails=true&postId=<?php echo $post['post_id'];?>&postId_parent=<?php echo htmlspecialchars($_GET['postId']);?>" rel="nofollow">
91 91
               <?php }
92
-                    else
93
-                    {?>
92
+					else
93
+					{?>
94 94
                         <a href="index.php?vote=down&postId=<?php echo $post['post_id'];?>" rel="nofollow">
95 95
               <?php } ?>
96 96
                             <i class="fa fa-angle-down fa-3x"></i>
@@ -113,39 +113,39 @@  discard block
 block discarded – undo
113 113
                                 <a href="index.php?getPostDetails=true&view=<?php echo $view;?>&postId=<?php echo $post["post_id"];?>">
114 114
                                     <i class="fa fa-commenting-o"></i>
115 115
                                     <?php if(array_key_exists("child_count", $post)) {
116
-                                                echo $post["child_count"];
117
-                                            } else echo "0";
118
-                                    ?>
116
+												echo $post["child_count"];
117
+											} else echo "0";
118
+									?>
119 119
                                     </a>
120 120
                             </span>
121 121
                             <?php } ?>
122 122
                         </td>
123 123
                         <td class="distance">
124 124
                             <?php
125
-                                if($isDetailedView)
126
-                                {
127
-                                    if(isset($post["parent_creator"]) && $post["parent_creator"] == 1)
128
-                                    {
129
-                                        ?>
125
+								if($isDetailedView)
126
+								{
127
+									if(isset($post["parent_creator"]) && $post["parent_creator"] == 1)
128
+									{
129
+										?>
130 130
                                         <span data-tooltip="Author">
131 131
                                             <i class="fa fa-user-o"></i> OJ |
132 132
                                         </span>
133 133
                                         <?php 
134
-                                    }
135
-                                    else
136
-                                    {
137
-                                        //Is not parent Jodel in detailed View
138
-                                        if(!array_key_exists('child_count', $post) && array_key_exists('parent_creator', $post))
139
-                                        {
140
-                                            ?>
134
+									}
135
+									else
136
+									{
137
+										//Is not parent Jodel in detailed View
138
+										if(!array_key_exists('child_count', $post) && array_key_exists('parent_creator', $post))
139
+										{
140
+											?>
141 141
                                             <span data-tooltip="Author">
142 142
                                                 <i class="fa fa-user-o"></i> #<?php echo $post["user_handle"];?> |
143 143
                                             </span>
144 144
                                             <?php
145
-                                        }
146
-                                    }
147
-                                }
148
-                                ?>
145
+										}
146
+									}
147
+								}
148
+								?>
149 149
 
150 150
                             <span class="tip" data-tooltip="Distance">
151 151
                                 <i class="fa fa-map-marker"></i>
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
             </footer>
159 159
         </article>
160 160
     <?php
161
-    }
161
+	}
162 162
 
163 163
 
164 164
 	/**
Please login to merge, or discard this patch.
php/Requests/GetPostDetails.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -3,18 +3,18 @@
 block discarded – undo
3 3
 
4 4
 class GetPostDetails extends AbstractRequest {
5 5
 		
6
-    function getApiEndPoint()
7
-    {
8
-        return '/v2/posts/' . $_GET['postId'];
9
-    }
10
-    function getPayload()
11
-    {
12
-        return array(
13
-        );
14
-    }
15
-    function getMethod()
16
-    {
17
-        return 'GET';
18
-    }
6
+	function getApiEndPoint()
7
+	{
8
+		return '/v2/posts/' . $_GET['postId'];
9
+	}
10
+	function getPayload()
11
+	{
12
+		return array(
13
+		);
14
+	}
15
+	function getMethod()
16
+	{
17
+		return 'GET';
18
+	}
19 19
 }
20 20
 
Please login to merge, or discard this patch.
php/jodel-web.php 1 patch
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -41,36 +41,36 @@  discard block
 block discarded – undo
41 41
 
42 42
 function isUserBot()
43 43
 {
44
-    preg_match('/bot|spider|google|twitter/i', $_SERVER['HTTP_USER_AGENT'], $matches);
44
+	preg_match('/bot|spider|google|twitter/i', $_SERVER['HTTP_USER_AGENT'], $matches);
45 45
 
46
-    return (isset($matches[0])) ? true : false;
46
+	return (isset($matches[0])) ? true : false;
47 47
 }
48 48
 
49 49
 function configPropertyExists($config, $property)
50 50
 {
51
-    if(!array_key_exists($property, $config) || !isset($config[$property]) || $config[$property] == '' || $config[$property] == 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
52
-    {
53
-        return FALSE;
54
-    }
55
-    else
56
-    {
57
-        return TRUE;
58
-    }
51
+	if(!array_key_exists($property, $config) || !isset($config[$property]) || $config[$property] == '' || $config[$property] == 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
52
+	{
53
+		return FALSE;
54
+	}
55
+	else
56
+	{
57
+		return TRUE;
58
+	}
59 59
 }
60 60
 
61 61
 function isDeviceUidInDatabase($deviceUid)
62 62
 {
63
-    $db = new DatabaseConnect();  
64
-    $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid  . "'");
63
+	$db = new DatabaseConnect();  
64
+	$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid  . "'");
65 65
 
66
-    if ($result->num_rows > 0)
67
-    {
68
-        return TRUE;
69
-    }
70
-    else
71
-    {
72
-        return FALSE;
73
-    }
66
+	if ($result->num_rows > 0)
67
+	{
68
+		return TRUE;
69
+	}
70
+	else
71
+	{
72
+		return FALSE;
73
+	}
74 74
 }
75 75
 
76 76
 	//Check if it's a Spider or Google Bot
@@ -97,14 +97,14 @@  discard block
 block discarded – undo
97 97
 	}
98 98
 	
99 99
 	if(configPropertyExists($config, 'karmaDeviceUid'))
100
-    {
101
-    	$jodelAccountForKarma = new JodelAccount($config['karmaDeviceUid']);
102
-    }
103
-    else
104
-    {
105
-    	error_log("No Karma deviceUid set in config file");
100
+	{
101
+		$jodelAccountForKarma = new JodelAccount($config['karmaDeviceUid']);
102
+	}
103
+	else
104
+	{
105
+		error_log("No Karma deviceUid set in config file");
106 106
 		$jodelAccountForKarma = new JodelAccount($deviceUid);
107
-    }
107
+	}
108 108
 
109 109
 	$newPositionStatus = $jodelAccountForView->location->getCityName();
110 110
 
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
 	{
152 152
 		$jodelAccountForKarma->votePostId($_GET['postId'], $_GET['vote']);
153 153
 		if(isset($_GET['getPostDetails']) && isset($_GET['getPostDetails']))
154
-        {
155
-            header('Location: index.php?getPostDetails=true&postId=' . htmlspecialchars($_GET['postId_parent']) . '#postId-' . htmlspecialchars($_GET['postId']));
156
-        }
157
-        else
158
-        {
159
-            header("Location: index.php#postId-" . htmlspecialchars($_GET['postId']));
160
-        }   
161
-        die();
154
+		{
155
+			header('Location: index.php?getPostDetails=true&postId=' . htmlspecialchars($_GET['postId_parent']) . '#postId-' . htmlspecialchars($_GET['postId']));
156
+		}
157
+		else
158
+		{
159
+			header("Location: index.php#postId-" . htmlspecialchars($_GET['postId']));
160
+		}   
161
+		die();
162 162
 	}
163 163
 	
164 164
 	//SendJodel
@@ -203,32 +203,32 @@  discard block
 block discarded – undo
203 203
 			if(!array_key_exists(0, $posts))
204 204
 			{
205 205
 				$posts[0] = array(
206
-			    "post_id" => "0",
207
-			    "discovered_by" => 0,
208
-			    "message" => "Not found",
209
-			    "created_at" => "2017-02-11T16:44:50.385Z",
210
-			    "updated_at" => "2017-02-11T16:44:50.385Z",
211
-			    "pin_count" => 0,
212
-			    "color" => "FFBA00",
213
-			    "got_thanks" => FALSE,
214
-			    "post_own" => "friend",
215
-			    "discovered" => 0,
216
-			    "distance" => 9,
217
-			    "vote_count" => 0,
218
-			    "location" =>
219
-			    array("name" => "Berlin",
220
-			      "loc_coordinates" =>
221
-			      array(
222
-			        "lat" => 0,
223
-			        "lng" => 0
224
-			      ),
225
-			      "loc_accuracy" => 0,
226
-			      "country" => "",
227
-			      "city" => "",
228
-			    ),
229
-			    "tags" =>
230
-			    array(),
231
-			    "user_handle" => "0"
206
+				"post_id" => "0",
207
+				"discovered_by" => 0,
208
+				"message" => "Not found",
209
+				"created_at" => "2017-02-11T16:44:50.385Z",
210
+				"updated_at" => "2017-02-11T16:44:50.385Z",
211
+				"pin_count" => 0,
212
+				"color" => "FFBA00",
213
+				"got_thanks" => FALSE,
214
+				"post_own" => "friend",
215
+				"discovered" => 0,
216
+				"distance" => 9,
217
+				"vote_count" => 0,
218
+				"location" =>
219
+				array("name" => "Berlin",
220
+				  "loc_coordinates" =>
221
+				  array(
222
+					"lat" => 0,
223
+					"lng" => 0
224
+				  ),
225
+				  "loc_accuracy" => 0,
226
+				  "country" => "",
227
+				  "city" => "",
228
+				),
229
+				"tags" =>
230
+				array(),
231
+				"user_handle" => "0"
232 232
 			 );
233 233
 			}
234 234
 		}
@@ -237,32 +237,32 @@  discard block
 block discarded – undo
237 237
 			$posts = array();
238 238
 			$posts[0] = 
239 239
 			array(
240
-			    "post_id" => "0",
241
-			    "discovered_by" => 0,
242
-			    "message" => "Bad Request",
243
-			    "created_at" => "2017-02-11T16:44:50.385Z",
244
-			    "updated_at" => "2017-02-11T16:44:50.385Z",
245
-			    "pin_count" => 0,
246
-			    "color" => "FFBA00",
247
-			    "got_thanks" => FALSE,
248
-			    "post_own" => "friend",
249
-			    "discovered" => 0,
250
-			    "distance" => 9,
251
-			    "vote_count" => 0,
252
-			    "location" =>
253
-			    array("name" => "Berlin",
254
-			      "loc_coordinates" =>
255
-			      array(
256
-			        "lat" => 0,
257
-			        "lng" => 0
258
-			      ),
259
-			      "loc_accuracy" => 0,
260
-			      "country" => "",
261
-			      "city" => "",
262
-			    ),
263
-			    "tags" =>
264
-			    array(),
265
-			    "user_handle" => "0"
240
+				"post_id" => "0",
241
+				"discovered_by" => 0,
242
+				"message" => "Bad Request",
243
+				"created_at" => "2017-02-11T16:44:50.385Z",
244
+				"updated_at" => "2017-02-11T16:44:50.385Z",
245
+				"pin_count" => 0,
246
+				"color" => "FFBA00",
247
+				"got_thanks" => FALSE,
248
+				"post_own" => "friend",
249
+				"discovered" => 0,
250
+				"distance" => 9,
251
+				"vote_count" => 0,
252
+				"location" =>
253
+				array("name" => "Berlin",
254
+				  "loc_coordinates" =>
255
+				  array(
256
+					"lat" => 0,
257
+					"lng" => 0
258
+				  ),
259
+				  "loc_accuracy" => 0,
260
+				  "country" => "",
261
+				  "city" => "",
262
+				),
263
+				"tags" =>
264
+				array(),
265
+				"user_handle" => "0"
266 266
 			 );
267 267
 
268 268
 
Please login to merge, or discard this patch.