Completed
Push — master ( 81a7e0...24e24a )
by mains
02:43
created
php/Requests/AbstractRequest.php 1 patch
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -2,19 +2,19 @@  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 = 'plerFToqEdWlzShdZlTywaCHRuzlKIMsNmOJVDGE';
8
-    const USERAGENT = 'Jodel/4.31.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
9
-    const CLIENT_TYPE = 'android_4.31.1';
5
+	const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26';
6
+	const APIURL = 'https://api.go-tellm.com/api';
7
+	const SECRET = 'plerFToqEdWlzShdZlTywaCHRuzlKIMsNmOJVDGE';
8
+	const USERAGENT = 'Jodel/4.31.1 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )';
9
+	const CLIENT_TYPE = 'android_4.31.1';
10 10
     
11
-    private $accessToken = null;
12
-    private $payLoad;
13
-    public $expects = '';
14
-    public $version = 'v2';
11
+	private $accessToken = null;
12
+	private $payLoad;
13
+	public $expects = '';
14
+	public $version = 'v2';
15 15
 
16
-    public function execute()
17
-    {
16
+	public function execute()
17
+	{
18 18
 		$result = new \stdClass();
19 19
 		        
20 20
 		$this->payLoad = $this->getPayload();
@@ -24,96 +24,96 @@  discard block
 block discarded – undo
24 24
 		}
25 25
 				
26 26
 				
27
-        $this->payLoad = json_encode($this->payLoad);
28
-        $header = $this->getSignHeaders();
29
-        $url = $this->getFullUrl();
27
+		$this->payLoad = json_encode($this->payLoad);
28
+		$header = $this->getSignHeaders();
29
+		$url = $this->getFullUrl();
30 30
 
31
-        if ($this->getAccessToken()) {
32
-            $header['Authorization'] = "Bearer " . $this->getAccessToken();
33
-        }
34
-        //Comment out to debug the Request:
31
+		if ($this->getAccessToken()) {
32
+			$header['Authorization'] = "Bearer " . $this->getAccessToken();
33
+		}
34
+		//Comment out to debug the Request:
35 35
         
36
-        /*
36
+		/*
37 37
         var_dump($url);
38 38
         var_dump($header);
39 39
         var_dump($this->payLoad);
40 40
         */
41
-        /*
41
+		/*
42 42
         $options = array(
43 43
             'timeout' => 100,
44 44
             'connect_timeout' => 100,
45 45
             'proxy' => '186.103.169.165:8080',
46 46
         );*/
47 47
 
48
-        switch ($this->getMethod()) {
49
-            case 'POST':
50
-                $result = Requests::post($url, $header, $this->payLoad);
51
-                break;
52
-            case 'GET':
53
-                if($this->version == 'v3')
54
-                {
55
-                    $result = Requests::get($url, $header);
56
-                }
57
-                else
58
-                {
59
-                    $result = Requests::get($url, $header);
60
-                }
61
-                break;
62
-            case 'PUT':
63
-                $result = Requests::put($url, $header, $this->payLoad);
64
-                break;
65
-        }
66
-        switch ($result->status_code) {
67
-            case 200:
68
-                $result = json_decode($result->body, true);
69
-                break;
70
-            case 204:
71
-                $result = "Success";
72
-                break;
73
-            case 401:
48
+		switch ($this->getMethod()) {
49
+			case 'POST':
50
+				$result = Requests::post($url, $header, $this->payLoad);
51
+				break;
52
+			case 'GET':
53
+				if($this->version == 'v3')
54
+				{
55
+					$result = Requests::get($url, $header);
56
+				}
57
+				else
58
+				{
59
+					$result = Requests::get($url, $header);
60
+				}
61
+				break;
62
+			case 'PUT':
63
+				$result = Requests::put($url, $header, $this->payLoad);
64
+				break;
65
+		}
66
+		switch ($result->status_code) {
67
+			case 200:
68
+				$result = json_decode($result->body, true);
69
+				break;
70
+			case 204:
71
+				$result = "Success";
72
+				break;
73
+			case 401:
74 74
 				//throw new \Exception('Unauthorized');
75
-                error_log('Error 401 - Unauthorized - JodelDeviceId:' . $deviceUid);
76
-                break;
77
-            case 404:
78
-                //echo "Es wurde bereits gevoted";
79
-                error_log('Error 404 - Es wurde bereits gevoted - JodelDeviceId:' . $deviceUid);
75
+				error_log('Error 401 - Unauthorized - JodelDeviceId:' . $deviceUid);
76
+				break;
77
+			case 404:
78
+				//echo "Es wurde bereits gevoted";
79
+				error_log('Error 404 - Es wurde bereits gevoted - JodelDeviceId:' . $deviceUid);
80 80
 			case 477:
81
-                //echo "Es wurde bereits gevoted";
82
-                //throw  new \Exception('Signing failed!');
83
-                error_log('Error 477 - Signing failed - JodelDeviceId:' . $deviceUid);
84
-                break;
85
-            case 429:
86
-                error_log('Error 429 - Too Many Requests - JodelDeviceId:' . $deviceUid);
87
-            	exit("Error 429: Too Many Requests");
88
-            	break;
89
-            case 403:
90
-                error_log('Error 403 - Access denied - JodelDeviceId:' . $deviceUid);
91
-                exit("Error 403: Access denied");
92
-                break;
93
-            default:
94
-                error_log('Error '.$result->status_code.' - Unauthorized - JodelDeviceId:' . $deviceUid);
95
-                throw  new \Exception('Unknown Error: '.$result->status_code);
96
-        }
81
+				//echo "Es wurde bereits gevoted";
82
+				//throw  new \Exception('Signing failed!');
83
+				error_log('Error 477 - Signing failed - JodelDeviceId:' . $deviceUid);
84
+				break;
85
+			case 429:
86
+				error_log('Error 429 - Too Many Requests - JodelDeviceId:' . $deviceUid);
87
+				exit("Error 429: Too Many Requests");
88
+				break;
89
+			case 403:
90
+				error_log('Error 403 - Access denied - JodelDeviceId:' . $deviceUid);
91
+				exit("Error 403: Access denied");
92
+				break;
93
+			default:
94
+				error_log('Error '.$result->status_code.' - Unauthorized - JodelDeviceId:' . $deviceUid);
95
+				throw  new \Exception('Unknown Error: '.$result->status_code);
96
+		}
97 97
 
98
-        if($device_uid != "")
99
-        {
98
+		if($device_uid != "")
99
+		{
100 100
 			$result[0] = $result;
101 101
 			$result[1] = $device_uid;
102 102
 		}
103 103
 
104 104
         
105
-        /*var_dump($result);*/
105
+		/*var_dump($result);*/
106 106
         
107 107
 
108
-        return $result;
109
-    }
110
-    abstract function getPayload();
111
-    /**
112
-     * Gets Sign headers
113
-     * @return array headers
114
-     */
115
-    private function getSignHeaders()
116
-    {
108
+		return $result;
109
+	}
110
+	abstract function getPayload();
111
+	/**
112
+	 * Gets Sign headers
113
+	 * @return array headers
114
+	 */
115
+	private function getSignHeaders()
116
+	{
117 117
 			if($this->getAccessToken() == null) {
118 118
 				$payload_accessToken = "";
119 119
 			}
@@ -122,54 +122,54 @@  discard block
 block discarded – undo
122 122
 			}
123 123
 			
124 124
 			
125
-        $headers = array(
126
-            "Connection" => "keep-alive",
127
-            "Accept-Encoding" => "gzip",
128
-            "Content-Type" => "application/json; charset=UTF-8",
129
-            "User-Agent" => self::USERAGENT
130
-        );
131
-        $timestamp = new DateTime();
132
-        $timestamp = $timestamp->format(DateTime::ATOM);
133
-        $timestamp = substr($timestamp, 0, -6);
134
-        $timestamp .= "Z";
135
-        $urlParts = parse_url($this->getFullUrl());
136
-        $url2 = "";
137
-        $req = [$this->getMethod(),
138
-            $urlParts['host'],
139
-            "443",
140
-            $urlParts['path'],
141
-            $payload_accessToken,
142
-            $timestamp,
143
-            $url2,
144
-            $this->payLoad];
145
-        $reqString = implode("%", $req);
146
-        $secret = self::SECRET;
147
-        $signature = hash_hmac('sha1', $reqString, $secret);
148
-        $signature = strtoupper($signature);
149
-        $headers['X-Authorization'] = 'HMAC ' . $signature;
150
-        $headers['X-Client-Type'] = self::CLIENT_TYPE;
151
-        $headers['X-Timestamp'] = $timestamp;
152
-        $headers['X-Api-Version'] = '0.2';
153
-        return $headers;
154
-    }
155
-    private function getFullUrl()
156
-    {
157
-        return self::APIURL . $this->getApiEndPoint();
158
-    }
159
-    abstract function getApiEndPoint();
160
-    abstract function getMethod();
161
-    /**
162
-     * @return string
163
-     */
164
-    private function getAccessToken()
165
-    {
166
-        return $this->accessToken;
167
-    }
168
-    /**
169
-     * @param string $accessToken
170
-     */
171
-    public function setAccessToken($accessToken)
172
-    {
173
-        $this->accessToken = $accessToken;
174
-    }
125
+		$headers = array(
126
+			"Connection" => "keep-alive",
127
+			"Accept-Encoding" => "gzip",
128
+			"Content-Type" => "application/json; charset=UTF-8",
129
+			"User-Agent" => self::USERAGENT
130
+		);
131
+		$timestamp = new DateTime();
132
+		$timestamp = $timestamp->format(DateTime::ATOM);
133
+		$timestamp = substr($timestamp, 0, -6);
134
+		$timestamp .= "Z";
135
+		$urlParts = parse_url($this->getFullUrl());
136
+		$url2 = "";
137
+		$req = [$this->getMethod(),
138
+			$urlParts['host'],
139
+			"443",
140
+			$urlParts['path'],
141
+			$payload_accessToken,
142
+			$timestamp,
143
+			$url2,
144
+			$this->payLoad];
145
+		$reqString = implode("%", $req);
146
+		$secret = self::SECRET;
147
+		$signature = hash_hmac('sha1', $reqString, $secret);
148
+		$signature = strtoupper($signature);
149
+		$headers['X-Authorization'] = 'HMAC ' . $signature;
150
+		$headers['X-Client-Type'] = self::CLIENT_TYPE;
151
+		$headers['X-Timestamp'] = $timestamp;
152
+		$headers['X-Api-Version'] = '0.2';
153
+		return $headers;
154
+	}
155
+	private function getFullUrl()
156
+	{
157
+		return self::APIURL . $this->getApiEndPoint();
158
+	}
159
+	abstract function getApiEndPoint();
160
+	abstract function getMethod();
161
+	/**
162
+	 * @return string
163
+	 */
164
+	private function getAccessToken()
165
+	{
166
+		return $this->accessToken;
167
+	}
168
+	/**
169
+	 * @param string $accessToken
170
+	 */
171
+	public function setAccessToken($accessToken)
172
+	{
173
+		$this->accessToken = $accessToken;
174
+	}
175 175
 }
Please login to merge, or discard this patch.
php/jodel-web.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	
26 26
 	$access_token;
27 27
 
28
-	if ($result->num_rows > 0)
28
+	if($result->num_rows > 0)
29 29
 	{
30 30
 			// output data of each row
31 31
 			while($row = $result->fetch_assoc()) {
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 
43 43
 	if($expiration_date <= time()) {
44 44
 		$accountCreator = new CreateUser();
45
-		$accountCreator->setAccessToken($access_token);//$accountData->getAccessToken());
45
+		$accountCreator->setAccessToken($access_token); //$accountData->getAccessToken());
46 46
 		$accountCreator->setDeviceUid($deviceUid);
47 47
 		$accountCreator->setLocation($location);
48 48
 		$data = $accountCreator->execute();
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 									expiration_date='" . $expiration_date . "'
58 58
 								WHERE device_uid='" . $device_uid . "'");
59 59
 
60
-		if($result === false){
60
+		if($result === false) {
61 61
 				echo "Adding account failed: (" . $db->errno . ") " . $db->error;
62 62
 		}	
63 63
 	}
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	$db = new DatabaseConnect();  
71 71
 	$result = $db->query("SELECT * FROM accounts WHERE access_token='" . $accessToken . "'");
72 72
 	
73
-	if ($result->num_rows > 0)
73
+	if($result->num_rows > 0)
74 74
 	{
75 75
 			// output data of each row
76 76
 			while($row = $result->fetch_assoc()) {
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 
88 88
 	if($expiration_date <= time()) {
89 89
 		$accountCreator = new CreateUser();
90
-		$accountCreator->setAccessToken($access_token);//$accountData->getAccessToken());
90
+		$accountCreator->setAccessToken($access_token); //$accountData->getAccessToken());
91 91
 		$accountCreator->setDeviceUid($deviceUid);
92 92
 		$accountCreator->setLocation($location);
93 93
 		$data = $accountCreator->execute();
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 									expiration_date='" . $expiration_date . "'
103 103
 								WHERE device_uid='" . $device_uid . "'");
104 104
 
105
-		if($result === false){
105
+		if($result === false) {
106 106
 				echo "Adding account failed: (" . $db->errno . ") " . $db->error;
107 107
 		}	
108 108
 	}
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 
118 118
 	$access_token;
119 119
 
120
-	if ($result->num_rows > 0)
120
+	if($result->num_rows > 0)
121 121
 	{
122 122
 			// output data of each row
123 123
 			while($row = $result->fetch_assoc()) {
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 									expiration_date='" . $expiration_date . "'
150 150
 								WHERE device_uid='" . $device_uid . "'");
151 151
 
152
-		if($result === false){
152
+		if($result === false) {
153 153
 				echo "Adding account failed: (" . $db->errno . ") " . $db->error;
154 154
 		}	
155 155
 	}
@@ -160,11 +160,11 @@  discard block
 block discarded – undo
160 160
 function getLocationByAccessToken($accessToken)
161 161
 {
162 162
 	$db = new DatabaseConnect();
163
-	$result = $db->query("SELECT * FROM accounts WHERE access_token='" . $accessToken  . "'");
163
+	$result = $db->query("SELECT * FROM accounts WHERE access_token='" . $accessToken . "'");
164 164
 	
165 165
 	$location = new Location();
166 166
 	
167
-	if ($result->num_rows > 0)
167
+	if($result->num_rows > 0)
168 168
 	{
169 169
 		// output data of each row
170 170
 		while($row = $result->fetch_assoc())
@@ -185,11 +185,11 @@  discard block
 block discarded – undo
185 185
 function getLocationByDeviceUid($deviceUid)
186 186
 {
187 187
 	$db = new DatabaseConnect();
188
-	$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid  . "'");
188
+	$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid . "'");
189 189
 	
190 190
 	$location = new Location();
191 191
 	
192
-	if ($result->num_rows > 0)
192
+	if($result->num_rows > 0)
193 193
 	{
194 194
 		// output data of each row
195 195
 		while($row = $result->fetch_assoc())
@@ -210,11 +210,11 @@  discard block
 block discarded – undo
210 210
 function getAccessTokenByDeviceUid($deviceUid)
211 211
 {
212 212
 	$db = new DatabaseConnect();
213
-	$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid  . "'");
213
+	$result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid . "'");
214 214
 	
215 215
 	$accessToken;
216 216
 	
217
-	if ($result->num_rows > 0)
217
+	if($result->num_rows > 0)
218 218
 	{
219 219
 		// output data of each row
220 220
 		while($row = $result->fetch_assoc())
@@ -261,11 +261,11 @@  discard block
 block discarded – undo
261 261
 	$result = $db->query("INSERT INTO accounts (access_token, refresh_token, token_type,
262 262
 					expires_in, expiration_date, distinct_id, device_uid, name, lat, lng)
263 263
 					VALUES ('" . $access_token . "','" . $refresh_token . "','" . $token_type .
264
-					"','" .  $expires_in . "','" . $expiration_date . "','" . $distinct_id .
264
+					"','" . $expires_in . "','" . $expiration_date . "','" . $distinct_id .
265 265
 					"','" . $device_uid . "','" . $name . "','" . $lat . "','" . $lng . "') ");
266 266
 
267 267
 	$success = TRUE;
268
-	if($result === false){
268
+	if($result === false) {
269 269
 			$error = db_error();
270 270
 			echo $error;
271 271
 			echo "Adding account failed: (" . $result->errno . ") " . $result->error;
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 {
310 310
 	preg_match('/bot|spider|google|twitter/i', $_SERVER['HTTP_USER_AGENT'], $matches);
311 311
 
312
-    return (isset($matches[0])) ? true : false;
312
+    return (isset($matches[0]))?true : false;
313 313
 }
314 314
 
315 315
 function botDeviceUidIsSet($config)
@@ -340,25 +340,25 @@  discard block
 block discarded – undo
340 340
 	$timediff_inDays = (string)$timediff->format('%d');
341 341
 	$timediff_inMonth = (string)$timediff->format('%m');
342 342
 
343
-	if($timediff_inMonth!=0)
343
+	if($timediff_inMonth != 0)
344 344
 	{
345 345
 			$timediff = $timediff_inMonth . "m";
346 346
 	}
347 347
 	else
348 348
 	{
349
-		if($timediff_inDays!=0)
349
+		if($timediff_inDays != 0)
350 350
 		{
351 351
 			$timediff = $timediff_inDays . "d";
352 352
 		}
353 353
 		else
354 354
 		{
355
-			if($timediff_inHours!=0)
355
+			if($timediff_inHours != 0)
356 356
 			{
357 357
 				$timediff = $timediff_inHours . "h";
358 358
 			}
359 359
 			else
360 360
 			{
361
-				if($timediff_inMinutes!=0)
361
+				if($timediff_inMinutes != 0)
362 362
 				{
363 363
 					$timediff = $timediff_inMinutes . "m";
364 364
 				}
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
 
373 373
 
374 374
 	?>
375
-	<article id ="postId-<?php echo $post["post_id"]; ?>" class="jodel" style="background-color: #<?php echo $post["color"];?>;">
375
+	<article id ="postId-<?php echo $post["post_id"]; ?>" class="jodel" style="background-color: #<?php echo $post["color"]; ?>;">
376 376
 		<content>
377 377
 			<?php 
378 378
 			if(isset($post["image_url"])) {
@@ -387,24 +387,24 @@  discard block
 block discarded – undo
387 387
 			<?php
388 388
 				if($isDetailedView)
389 389
 				{?>
390
-					<a href="index.php?vote=up&getPostDetails=true&postID=<?php echo $post['post_id'];?>&postID_parent=<?php echo htmlspecialchars($_GET['postID']);?>">
390
+					<a href="index.php?vote=up&getPostDetails=true&postID=<?php echo $post['post_id']; ?>&postID_parent=<?php echo htmlspecialchars($_GET['postID']); ?>">
391 391
 		  <?php }
392 392
 				else
393 393
 				{?>
394
-					<a href="index.php?vote=up&postID=<?php echo $post['post_id'];?>">
394
+					<a href="index.php?vote=up&postID=<?php echo $post['post_id']; ?>">
395 395
 		  <?php } ?>
396 396
 						<i class="fa fa-angle-up fa-3x"></i>
397 397
 					</a>	
398 398
 						<br />
399
-					<?php echo $post["vote_count"];?><br />
399
+					<?php echo $post["vote_count"]; ?><br />
400 400
 			<?php
401 401
 				if($isDetailedView)
402 402
 				{?>
403
-					<a href="index.php?vote=down&getPostDetails=true&postID=<?php echo $post['post_id'];?>&postID_parent=<?php echo htmlspecialchars($_GET['postID']);?>">
403
+					<a href="index.php?vote=down&getPostDetails=true&postID=<?php echo $post['post_id']; ?>&postID_parent=<?php echo htmlspecialchars($_GET['postID']); ?>">
404 404
 		  <?php }
405 405
 				else
406 406
 				{?>
407
-					<a href="index.php?vote=down&postID=<?php echo $post['post_id'];?>">
407
+					<a href="index.php?vote=down&postID=<?php echo $post['post_id']; ?>">
408 408
 		  <?php } ?>
409 409
 						<i class="fa fa-angle-down fa-3x"></i>
410 410
 					</a>
@@ -416,14 +416,14 @@  discard block
 block discarded – undo
416 416
 					<td class="time">
417 417
 						<span class="tip" data-tooltip="Time">
418 418
 							<i class="fa fa-clock-o"></i>
419
-							<?php echo $timediff;?>
420
-							<span class="tiptext"><?php echo $d->format('Y-m-d H:i:s');?></span>
419
+							<?php echo $timediff; ?>
420
+							<span class="tiptext"><?php echo $d->format('Y-m-d H:i:s'); ?></span>
421 421
 						</span> 
422 422
 					</td>
423 423
 					<td class="comments">
424 424
 						<?php if(!$isDetailedView) {?>
425 425
 						<span data-tooltip="Comments">
426
-							<a href="index.php?getPostDetails=true&view=<?php echo $view;?>&postID=<?php echo $post["post_id"];?>">
426
+							<a href="index.php?getPostDetails=true&view=<?php echo $view; ?>&postID=<?php echo $post["post_id"]; ?>">
427 427
 								<i class="fa fa-commenting-o"></i>
428 428
 								<?php if(array_key_exists("child_count", $post)) {
429 429
 											echo $post["child_count"];
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 									{
453 453
 							  			?>
454 454
 							  			<span data-tooltip="Author">
455
-											<i class="fa fa-user-o"></i> #<?php echo $post["user_handle"];?> |
455
+											<i class="fa fa-user-o"></i> #<?php echo $post["user_handle"]; ?> |
456 456
 										</span>
457 457
 										<?php
458 458
 									}
@@ -462,8 +462,8 @@  discard block
 block discarded – undo
462 462
 
463 463
 						<span class="tip" data-tooltip="Distance">
464 464
 							<i class="fa fa-map-marker"></i>
465
-							<?php echo $post['distance'];?> km
466
-							<span class="tiptext"><?php echo $post['location']['name'];?></span>
465
+							<?php echo $post['distance']; ?> km
466
+							<span class="tiptext"><?php echo $post['location']['name']; ?></span>
467 467
 						</span>
468 468
 					</td>
469 469
 				</tr>
Please login to merge, or discard this patch.