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