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