@@ -2,22 +2,22 @@ |
||
2 | 2 | class PostCaptcha extends AbstractRequest |
3 | 3 | { |
4 | 4 | public $captchaKey; |
5 | - public $captchaSolution; |
|
5 | + public $captchaSolution; |
|
6 | 6 | |
7 | - function getApiEndPoint() |
|
8 | - { |
|
9 | - return '/v3/user/verification/imageCaptcha/'; |
|
10 | - } |
|
11 | - function getPayload() |
|
12 | - { |
|
13 | - return array( |
|
14 | - 'key' => $this->captchaKey, |
|
15 | - 'answer' => $this->captchaSolution, |
|
16 | - ); |
|
17 | - } |
|
18 | - function getMethod() |
|
19 | - { |
|
20 | - return 'POST'; |
|
21 | - } |
|
7 | + function getApiEndPoint() |
|
8 | + { |
|
9 | + return '/v3/user/verification/imageCaptcha/'; |
|
10 | + } |
|
11 | + function getPayload() |
|
12 | + { |
|
13 | + return array( |
|
14 | + 'key' => $this->captchaKey, |
|
15 | + 'answer' => $this->captchaSolution, |
|
16 | + ); |
|
17 | + } |
|
18 | + function getMethod() |
|
19 | + { |
|
20 | + return 'POST'; |
|
21 | + } |
|
22 | 22 | } |
23 | 23 |
@@ -2,18 +2,18 @@ |
||
2 | 2 | class GetUserConfig extends AbstractRequest |
3 | 3 | { |
4 | 4 | |
5 | - function getApiEndPoint() |
|
6 | - { |
|
7 | - return '/v3/user/config/'; |
|
8 | - } |
|
9 | - function getPayload() |
|
10 | - { |
|
11 | - return array( |
|
12 | - ); |
|
13 | - } |
|
14 | - function getMethod() |
|
15 | - { |
|
16 | - return 'GET'; |
|
17 | - } |
|
5 | + function getApiEndPoint() |
|
6 | + { |
|
7 | + return '/v3/user/config/'; |
|
8 | + } |
|
9 | + function getPayload() |
|
10 | + { |
|
11 | + return array( |
|
12 | + ); |
|
13 | + } |
|
14 | + function getMethod() |
|
15 | + { |
|
16 | + return 'GET'; |
|
17 | + } |
|
18 | 18 | } |
19 | 19 |
@@ -3,37 +3,37 @@ |
||
3 | 3 | |
4 | 4 | class UpdateLocation extends AbstractRequest { |
5 | 5 | /** |
6 | - * @var Location |
|
7 | - */ |
|
8 | - public $location; |
|
9 | - /** |
|
10 | - * @return Location |
|
11 | - */ |
|
12 | - public function getLocation() |
|
13 | - { |
|
14 | - return $this->location; |
|
15 | - } |
|
16 | - /** |
|
17 | - * @param Location $location |
|
18 | - */ |
|
19 | - public function setLocation($location) |
|
20 | - { |
|
21 | - $this->location = $location; |
|
22 | - } |
|
6 | + * @var Location |
|
7 | + */ |
|
8 | + public $location; |
|
9 | + /** |
|
10 | + * @return Location |
|
11 | + */ |
|
12 | + public function getLocation() |
|
13 | + { |
|
14 | + return $this->location; |
|
15 | + } |
|
16 | + /** |
|
17 | + * @param Location $location |
|
18 | + */ |
|
19 | + public function setLocation($location) |
|
20 | + { |
|
21 | + $this->location = $location; |
|
22 | + } |
|
23 | 23 | |
24 | - function getApiEndPoint() |
|
25 | - { |
|
26 | - return '/v2/users/location'; |
|
27 | - } |
|
28 | - function getPayload() |
|
29 | - { |
|
30 | - return array( |
|
24 | + function getApiEndPoint() |
|
25 | + { |
|
26 | + return '/v2/users/location'; |
|
27 | + } |
|
28 | + function getPayload() |
|
29 | + { |
|
30 | + return array( |
|
31 | 31 | 'location' => $this->getLocation()->toArray(), |
32 | - ); |
|
33 | - } |
|
34 | - function getMethod() |
|
35 | - { |
|
36 | - return 'PUT'; |
|
37 | - } |
|
32 | + ); |
|
33 | + } |
|
34 | + function getMethod() |
|
35 | + { |
|
36 | + return 'PUT'; |
|
37 | + } |
|
38 | 38 | } |
39 | 39 |
@@ -1,18 +1,18 @@ |
||
1 | 1 | <?php |
2 | 2 | class GetCaptcha extends AbstractRequest |
3 | 3 | { |
4 | - function getApiEndPoint() |
|
5 | - { |
|
6 | - return '/v3/user/verification/imageCaptcha/'; |
|
7 | - } |
|
8 | - function getPayload() |
|
9 | - { |
|
10 | - return array( |
|
11 | - ); |
|
12 | - } |
|
13 | - function getMethod() |
|
14 | - { |
|
15 | - return 'GET'; |
|
16 | - } |
|
4 | + function getApiEndPoint() |
|
5 | + { |
|
6 | + return '/v3/user/verification/imageCaptcha/'; |
|
7 | + } |
|
8 | + function getPayload() |
|
9 | + { |
|
10 | + return array( |
|
11 | + ); |
|
12 | + } |
|
13 | + function getMethod() |
|
14 | + { |
|
15 | + return 'GET'; |
|
16 | + } |
|
17 | 17 | } |
18 | 18 |
@@ -2,20 +2,20 @@ discard block |
||
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 = 'OFIqFvBgkccPNTVbIzkYaSmrwMlbVzRoOBBjXUIG'; |
|
8 | - const USERAGENT = 'Jodel/4.32.2 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )'; |
|
9 | - const CLIENT_TYPE = 'android_4.32.2'; |
|
5 | + const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
6 | + const APIURL = 'https://api.go-tellm.com/api'; |
|
7 | + const SECRET = 'OFIqFvBgkccPNTVbIzkYaSmrwMlbVzRoOBBjXUIG'; |
|
8 | + const USERAGENT = 'Jodel/4.32.2 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )'; |
|
9 | + const CLIENT_TYPE = 'android_4.32.2'; |
|
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 | - { |
|
17 | + public function execute() |
|
18 | + { |
|
19 | 19 | $result = new \stdClass(); |
20 | 20 | |
21 | 21 | $this->payLoad = $this->getPayload(); |
@@ -25,16 +25,16 @@ discard block |
||
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,86 +45,86 @@ discard block |
||
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 | - } |
|
73 | - switch ($result->status_code) { |
|
74 | - case 200: |
|
75 | - $result = json_decode($result->body, true); |
|
76 | - break; |
|
77 | - case 204: |
|
78 | - $result = "Success"; |
|
79 | - break; |
|
80 | - case 400: |
|
81 | - //throw new \Exception('Unauthorized'); |
|
82 | - error_log('Error 400 - Fehlerhafte Anfrage'); // - JodelDeviceId:' . $deviceUid); |
|
83 | - break; |
|
84 | - case 401: |
|
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 | + switch ($result->status_code) { |
|
74 | + case 200: |
|
75 | + $result = json_decode($result->body, true); |
|
76 | + break; |
|
77 | + case 204: |
|
78 | + $result = "Success"; |
|
79 | + break; |
|
80 | + case 400: |
|
81 | + //throw new \Exception('Unauthorized'); |
|
82 | + error_log('Error 400 - Fehlerhafte Anfrage'); // - JodelDeviceId:' . $deviceUid); |
|
83 | + break; |
|
84 | + case 401: |
|
85 | 85 | //throw new \Exception('Unauthorized'); |
86 | - error_log('Error 401 - Unauthorized'); // - JodelDeviceId:' . $deviceUid); |
|
87 | - break; |
|
88 | - case 404: |
|
89 | - //echo "Es wurde bereits gevoted"; |
|
90 | - error_log('Error 404 - Es wurde bereits gevoted'); // - JodelDeviceId:' . $deviceUid); |
|
86 | + error_log('Error 401 - Unauthorized'); // - JodelDeviceId:' . $deviceUid); |
|
87 | + break; |
|
88 | + case 404: |
|
89 | + //echo "Es wurde bereits gevoted"; |
|
90 | + error_log('Error 404 - Es wurde bereits gevoted'); // - JodelDeviceId:' . $deviceUid); |
|
91 | 91 | case 477: |
92 | - //echo "Es wurde bereits gevoted"; |
|
93 | - //throw new \Exception('Signing failed!'); |
|
94 | - error_log('Error 477 - Signing failed'); // - JodelDeviceId:' . $deviceUid); |
|
95 | - break; |
|
96 | - case 429: |
|
97 | - error_log('Error 429 - Too Many Requests'); // - JodelDeviceId:' . $deviceUid); |
|
98 | - exit("Error 429: Too Many Requests"); |
|
99 | - break; |
|
100 | - case 403: |
|
101 | - error_log('Error 403 - Access denied'); // - JodelDeviceId:' . $deviceUid); |
|
102 | - exit("Error 403: Access denied"); |
|
103 | - break; |
|
104 | - default: |
|
105 | - error_log('Error '.$result->status_code.' - Unauthorized'); // - JodelDeviceId:' . $deviceUid); |
|
106 | - //throw new \Exception('Unknown Error: '.$result->status_code); |
|
107 | - } |
|
92 | + //echo "Es wurde bereits gevoted"; |
|
93 | + //throw new \Exception('Signing failed!'); |
|
94 | + error_log('Error 477 - Signing failed'); // - JodelDeviceId:' . $deviceUid); |
|
95 | + break; |
|
96 | + case 429: |
|
97 | + error_log('Error 429 - Too Many Requests'); // - JodelDeviceId:' . $deviceUid); |
|
98 | + exit("Error 429: Too Many Requests"); |
|
99 | + break; |
|
100 | + case 403: |
|
101 | + error_log('Error 403 - Access denied'); // - JodelDeviceId:' . $deviceUid); |
|
102 | + exit("Error 403: Access denied"); |
|
103 | + break; |
|
104 | + default: |
|
105 | + error_log('Error '.$result->status_code.' - Unauthorized'); // - JodelDeviceId:' . $deviceUid); |
|
106 | + //throw new \Exception('Unknown Error: '.$result->status_code); |
|
107 | + } |
|
108 | 108 | |
109 | - if($device_uid != '') |
|
110 | - { |
|
109 | + if($device_uid != '') |
|
110 | + { |
|
111 | 111 | $result[0] = $result; |
112 | 112 | $result[1] = $device_uid; |
113 | 113 | } |
114 | 114 | |
115 | - /* |
|
115 | + /* |
|
116 | 116 | var_dump($result); |
117 | 117 | */ |
118 | 118 | |
119 | - return $result; |
|
120 | - } |
|
121 | - abstract function getPayload(); |
|
122 | - /** |
|
123 | - * Gets Sign headers |
|
124 | - * @return array headers |
|
125 | - */ |
|
126 | - private function getSignHeaders() |
|
127 | - { |
|
119 | + return $result; |
|
120 | + } |
|
121 | + abstract function getPayload(); |
|
122 | + /** |
|
123 | + * Gets Sign headers |
|
124 | + * @return array headers |
|
125 | + */ |
|
126 | + private function getSignHeaders() |
|
127 | + { |
|
128 | 128 | if($this->getAccessToken() == null) { |
129 | 129 | $payload_accessToken = ""; |
130 | 130 | } |
@@ -133,54 +133,54 @@ discard block |
||
133 | 133 | } |
134 | 134 | |
135 | 135 | |
136 | - $headers = array( |
|
137 | - "Connection" => "keep-alive", |
|
138 | - "Accept-Encoding" => "gzip", |
|
139 | - "Content-Type" => "application/json; charset=UTF-8", |
|
140 | - "User-Agent" => self::USERAGENT |
|
141 | - ); |
|
142 | - $timestamp = new DateTime(); |
|
143 | - $timestamp = $timestamp->format(DateTime::ATOM); |
|
144 | - $timestamp = substr($timestamp, 0, -6); |
|
145 | - $timestamp .= "Z"; |
|
146 | - $urlParts = parse_url($this->getFullUrl()); |
|
147 | - $url2 = ""; |
|
148 | - $req = [$this->getMethod(), |
|
149 | - $urlParts['host'], |
|
150 | - "443", |
|
151 | - $urlParts['path'], |
|
152 | - $payload_accessToken, |
|
153 | - $timestamp, |
|
154 | - $url2, |
|
155 | - $this->payLoad]; |
|
156 | - $reqString = implode("%", $req); |
|
157 | - $secret = self::SECRET; |
|
158 | - $signature = hash_hmac('sha1', $reqString, $secret); |
|
159 | - $signature = strtoupper($signature); |
|
160 | - $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
161 | - $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
162 | - $headers['X-Timestamp'] = $timestamp; |
|
163 | - $headers['X-Api-Version'] = '0.2'; |
|
164 | - return $headers; |
|
165 | - } |
|
166 | - private function getFullUrl() |
|
167 | - { |
|
168 | - return self::APIURL . $this->getApiEndPoint(); |
|
169 | - } |
|
170 | - abstract function getApiEndPoint(); |
|
171 | - abstract function getMethod(); |
|
172 | - /** |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - private function getAccessToken() |
|
176 | - { |
|
177 | - return $this->accessToken; |
|
178 | - } |
|
179 | - /** |
|
180 | - * @param string $accessToken |
|
181 | - */ |
|
182 | - public function setAccessToken($accessToken) |
|
183 | - { |
|
184 | - $this->accessToken = $accessToken; |
|
185 | - } |
|
136 | + $headers = array( |
|
137 | + "Connection" => "keep-alive", |
|
138 | + "Accept-Encoding" => "gzip", |
|
139 | + "Content-Type" => "application/json; charset=UTF-8", |
|
140 | + "User-Agent" => self::USERAGENT |
|
141 | + ); |
|
142 | + $timestamp = new DateTime(); |
|
143 | + $timestamp = $timestamp->format(DateTime::ATOM); |
|
144 | + $timestamp = substr($timestamp, 0, -6); |
|
145 | + $timestamp .= "Z"; |
|
146 | + $urlParts = parse_url($this->getFullUrl()); |
|
147 | + $url2 = ""; |
|
148 | + $req = [$this->getMethod(), |
|
149 | + $urlParts['host'], |
|
150 | + "443", |
|
151 | + $urlParts['path'], |
|
152 | + $payload_accessToken, |
|
153 | + $timestamp, |
|
154 | + $url2, |
|
155 | + $this->payLoad]; |
|
156 | + $reqString = implode("%", $req); |
|
157 | + $secret = self::SECRET; |
|
158 | + $signature = hash_hmac('sha1', $reqString, $secret); |
|
159 | + $signature = strtoupper($signature); |
|
160 | + $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
161 | + $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
162 | + $headers['X-Timestamp'] = $timestamp; |
|
163 | + $headers['X-Api-Version'] = '0.2'; |
|
164 | + return $headers; |
|
165 | + } |
|
166 | + private function getFullUrl() |
|
167 | + { |
|
168 | + return self::APIURL . $this->getApiEndPoint(); |
|
169 | + } |
|
170 | + abstract function getApiEndPoint(); |
|
171 | + abstract function getMethod(); |
|
172 | + /** |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + private function getAccessToken() |
|
176 | + { |
|
177 | + return $this->accessToken; |
|
178 | + } |
|
179 | + /** |
|
180 | + * @param string $accessToken |
|
181 | + */ |
|
182 | + public function setAccessToken($accessToken) |
|
183 | + { |
|
184 | + $this->accessToken = $accessToken; |
|
185 | + } |
|
186 | 186 | } |
@@ -2,25 +2,25 @@ |
||
2 | 2 | |
3 | 3 | class GetChannel extends AbstractRequest |
4 | 4 | { |
5 | - /** |
|
6 | - * @var Location |
|
7 | - */ |
|
8 | - public $location; |
|
9 | - public $channel; |
|
10 | - public $hasPayload = FALSE; |
|
5 | + /** |
|
6 | + * @var Location |
|
7 | + */ |
|
8 | + public $location; |
|
9 | + public $channel; |
|
10 | + public $hasPayload = FALSE; |
|
11 | 11 | |
12 | - function getApiEndPoint() |
|
13 | - { |
|
14 | - $apiEndPoint = '/v3/posts/hashtag/combo?hashtag=' . $this->channel; |
|
15 | - return $apiEndPoint; |
|
16 | - } |
|
17 | - function getPayload() |
|
18 | - { |
|
19 | - return array( |
|
20 | - ); |
|
21 | - } |
|
22 | - function getMethod() |
|
23 | - { |
|
24 | - return 'GET'; |
|
25 | - } |
|
12 | + function getApiEndPoint() |
|
13 | + { |
|
14 | + $apiEndPoint = '/v3/posts/hashtag/combo?hashtag=' . $this->channel; |
|
15 | + return $apiEndPoint; |
|
16 | + } |
|
17 | + function getPayload() |
|
18 | + { |
|
19 | + return array( |
|
20 | + ); |
|
21 | + } |
|
22 | + function getMethod() |
|
23 | + { |
|
24 | + return 'GET'; |
|
25 | + } |
|
26 | 26 | } |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | class Jodel |
4 | 4 | { |
5 | - public $jodel; |
|
5 | + public $jodel; |
|
6 | 6 | |
7 | 7 | |
8 | 8 | } |
9 | 9 | \ No newline at end of file |
@@ -2,445 +2,445 @@ |
||
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 |
@@ -9,75 +9,75 @@ discard block |
||
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(' ', ' ', 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(' ', ' ', 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 |
||
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 |
||
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 |
||
158 | 158 | </footer> |
159 | 159 | </article> |
160 | 160 | <?php |
161 | - } |
|
161 | + } |
|
162 | 162 | |
163 | 163 | |
164 | 164 | /** |