@@ -385,6 +385,9 @@ |
||
| 385 | 385 | } |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | + /** |
|
| 389 | + * @param Location $location |
|
| 390 | + */ |
|
| 388 | 391 | function registerAccount($location) { |
| 389 | 392 | $accountCreator = new CreateUser(); |
| 390 | 393 | $accountCreator->setLocation($location); |
@@ -2,434 +2,434 @@ |
||
| 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 | - $solution = $_GET['solution']; |
|
| 135 | - $solution = array_map('intval', explode('-', $solution)); |
|
| 136 | - |
|
| 137 | - $accountCreator = new PostCaptcha(); |
|
| 138 | - $accountCreator->setAccessToken($this->accessToken); |
|
| 139 | - $accountCreator->captchaKey = $_GET['key']; |
|
| 140 | - $accountCreator->captchaSolution = $solution; |
|
| 141 | - $verified = $accountCreator->execute(); |
|
| 142 | - |
|
| 143 | - return $verified['verified']; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - //ToDo Spider Check |
|
| 147 | - function votePostId() |
|
| 148 | - { |
|
| 149 | - if(!$this->isAccountVerified()) |
|
| 150 | - { |
|
| 151 | - $view = new View(); |
|
| 152 | - $view->showCaptcha($this->accessToken); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - if(!$this->deviceUidHasVotedThisPostId($_GET['postID'])) |
|
| 156 | - { |
|
| 157 | - if($_GET['vote'] == "up") |
|
| 158 | - { |
|
| 159 | - $accountCreator = new Upvote(); |
|
| 160 | - } |
|
| 161 | - else if($_GET['vote'] == "down") |
|
| 162 | - { |
|
| 163 | - $accountCreator = new Downvote(); |
|
| 164 | - } |
|
| 165 | - $accountCreator->setAccessToken($this->accessToken); |
|
| 166 | - $accountCreator->postId = htmlspecialchars($_GET['postID']); |
|
| 167 | - $data = $accountCreator->execute(); |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - $this->addVoteWithPostIdAndTypeToDeviceUid($_GET['postID'], $_GET['vote']); |
|
| 171 | - } |
|
| 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 | + $solution = $_GET['solution']; |
|
| 135 | + $solution = array_map('intval', explode('-', $solution)); |
|
| 136 | + |
|
| 137 | + $accountCreator = new PostCaptcha(); |
|
| 138 | + $accountCreator->setAccessToken($this->accessToken); |
|
| 139 | + $accountCreator->captchaKey = $_GET['key']; |
|
| 140 | + $accountCreator->captchaSolution = $solution; |
|
| 141 | + $verified = $accountCreator->execute(); |
|
| 142 | + |
|
| 143 | + return $verified['verified']; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + //ToDo Spider Check |
|
| 147 | + function votePostId() |
|
| 148 | + { |
|
| 149 | + if(!$this->isAccountVerified()) |
|
| 150 | + { |
|
| 151 | + $view = new View(); |
|
| 152 | + $view->showCaptcha($this->accessToken); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + if(!$this->deviceUidHasVotedThisPostId($_GET['postID'])) |
|
| 156 | + { |
|
| 157 | + if($_GET['vote'] == "up") |
|
| 158 | + { |
|
| 159 | + $accountCreator = new Upvote(); |
|
| 160 | + } |
|
| 161 | + else if($_GET['vote'] == "down") |
|
| 162 | + { |
|
| 163 | + $accountCreator = new Downvote(); |
|
| 164 | + } |
|
| 165 | + $accountCreator->setAccessToken($this->accessToken); |
|
| 166 | + $accountCreator->postId = htmlspecialchars($_GET['postID']); |
|
| 167 | + $data = $accountCreator->execute(); |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + $this->addVoteWithPostIdAndTypeToDeviceUid($_GET['postID'], $_GET['vote']); |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | 173 | |
| 174 | - if(isset($_GET['getPostDetails']) && isset($_GET['getPostDetails'])) |
|
| 175 | - { |
|
| 176 | - header('Location: index.php?getPostDetails=true&postID=' . htmlspecialchars($_GET['postID_parent']) . '#postId-' . htmlspecialchars($_GET['postID'])); |
|
| 177 | - } |
|
| 178 | - else |
|
| 179 | - { |
|
| 180 | - header("Location: index.php#postId-" . htmlspecialchars($_GET['postID'])); |
|
| 181 | - } |
|
| 182 | - die(); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - //ToDo Spider Check |
|
| 186 | - function sendJodel() |
|
| 187 | - { |
|
| 188 | - if(!$this->isAccountVerified()) |
|
| 189 | - { |
|
| 190 | - showCaptcha($this->accessToken); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - $accountCreator = new SendJodel(); |
|
| 194 | - |
|
| 195 | - if(isset($_POST['ancestor'])) |
|
| 196 | - { |
|
| 197 | - $ancestor = $_POST['ancestor']; |
|
| 198 | - $accountCreator->ancestor = $ancestor; |
|
| 199 | - } |
|
| 200 | - if(isset($_POST['color'])) |
|
| 201 | - { |
|
| 202 | - $color = $_POST['color']; |
|
| 203 | - switch ($color) { |
|
| 204 | - case '8ABDB0': |
|
| 205 | - $color = '8ABDB0'; |
|
| 206 | - break; |
|
| 207 | - case '9EC41C': |
|
| 208 | - $color = '9EC41C'; |
|
| 209 | - break; |
|
| 210 | - case '06A3CB': |
|
| 211 | - $color = '06A3CB'; |
|
| 212 | - break; |
|
| 213 | - case 'FFBA00': |
|
| 214 | - $color = 'FFBA00'; |
|
| 215 | - break; |
|
| 216 | - case 'DD5F5F': |
|
| 217 | - $color = 'DD5F5F'; |
|
| 218 | - break; |
|
| 219 | - case 'FF9908': |
|
| 220 | - $color = 'FF9908'; |
|
| 221 | - break; |
|
| 222 | - default: |
|
| 223 | - $color = '8ABDB0'; |
|
| 224 | - break; |
|
| 225 | - } |
|
| 226 | - $accountCreator->color = $color; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $accountCreatorLocation = new UpdateLocation(); |
|
| 230 | - $accountCreatorLocation->setLocation($this->location); |
|
| 231 | - $accountCreatorLocation->setAccessToken($this->accessToken); |
|
| 232 | - $data = $accountCreatorLocation->execute(); |
|
| 174 | + if(isset($_GET['getPostDetails']) && isset($_GET['getPostDetails'])) |
|
| 175 | + { |
|
| 176 | + header('Location: index.php?getPostDetails=true&postID=' . htmlspecialchars($_GET['postID_parent']) . '#postId-' . htmlspecialchars($_GET['postID'])); |
|
| 177 | + } |
|
| 178 | + else |
|
| 179 | + { |
|
| 180 | + header("Location: index.php#postId-" . htmlspecialchars($_GET['postID'])); |
|
| 181 | + } |
|
| 182 | + die(); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + //ToDo Spider Check |
|
| 186 | + function sendJodel() |
|
| 187 | + { |
|
| 188 | + if(!$this->isAccountVerified()) |
|
| 189 | + { |
|
| 190 | + showCaptcha($this->accessToken); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + $accountCreator = new SendJodel(); |
|
| 194 | + |
|
| 195 | + if(isset($_POST['ancestor'])) |
|
| 196 | + { |
|
| 197 | + $ancestor = $_POST['ancestor']; |
|
| 198 | + $accountCreator->ancestor = $ancestor; |
|
| 199 | + } |
|
| 200 | + if(isset($_POST['color'])) |
|
| 201 | + { |
|
| 202 | + $color = $_POST['color']; |
|
| 203 | + switch ($color) { |
|
| 204 | + case '8ABDB0': |
|
| 205 | + $color = '8ABDB0'; |
|
| 206 | + break; |
|
| 207 | + case '9EC41C': |
|
| 208 | + $color = '9EC41C'; |
|
| 209 | + break; |
|
| 210 | + case '06A3CB': |
|
| 211 | + $color = '06A3CB'; |
|
| 212 | + break; |
|
| 213 | + case 'FFBA00': |
|
| 214 | + $color = 'FFBA00'; |
|
| 215 | + break; |
|
| 216 | + case 'DD5F5F': |
|
| 217 | + $color = 'DD5F5F'; |
|
| 218 | + break; |
|
| 219 | + case 'FF9908': |
|
| 220 | + $color = 'FF9908'; |
|
| 221 | + break; |
|
| 222 | + default: |
|
| 223 | + $color = '8ABDB0'; |
|
| 224 | + break; |
|
| 225 | + } |
|
| 226 | + $accountCreator->color = $color; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $accountCreatorLocation = new UpdateLocation(); |
|
| 230 | + $accountCreatorLocation->setLocation($this->location); |
|
| 231 | + $accountCreatorLocation->setAccessToken($this->accessToken); |
|
| 232 | + $data = $accountCreatorLocation->execute(); |
|
| 233 | 233 | |
| 234 | - $accountCreator->location = $this->location; |
|
| 234 | + $accountCreator->location = $this->location; |
|
| 235 | 235 | |
| 236 | - $accountCreator->setAccessToken($this->accessToken); |
|
| 237 | - $data = $accountCreator->execute(); |
|
| 238 | - |
|
| 239 | - if(isset($_POST['ancestor'])) |
|
| 240 | - { |
|
| 241 | - $actual_link = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|
| 242 | - header('Location: ' . $actual_link . '#postId-' . htmlspecialchars($data['post_id'])); |
|
| 243 | - exit; |
|
| 244 | - } |
|
| 245 | - else |
|
| 246 | - { |
|
| 247 | - header('Location: ./#'); |
|
| 248 | - exit; |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - function isTokenFresh() |
|
| 253 | - { |
|
| 254 | - $db = new DatabaseConnect(); |
|
| 255 | - $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
| 256 | - |
|
| 257 | - $access_token; |
|
| 258 | - |
|
| 259 | - if ($result->num_rows > 0) |
|
| 260 | - { |
|
| 261 | - // output data of each row |
|
| 262 | - while($row = $result->fetch_assoc()) { |
|
| 263 | - //$access_token = $row["access_token"]; |
|
| 264 | - $expiration_date = $row["expiration_date"]; |
|
| 265 | - $deviceUid = $row["device_uid"]; |
|
| 266 | - $access_token = $row["access_token"]; |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - else |
|
| 270 | - { |
|
| 271 | - echo '0 results'; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - if($expiration_date <= time()) { |
|
| 275 | - $accountCreator = new CreateUser(); |
|
| 276 | - $accountCreator->setAccessToken($access_token); |
|
| 277 | - $accountCreator->setDeviceUid($deviceUid); |
|
| 278 | - $accountCreator->setLocation($this->location); |
|
| 279 | - $data = $accountCreator->execute(); |
|
| 280 | - |
|
| 281 | - $access_token = (string)$data[0]['access_token']; |
|
| 282 | - $expiration_date = $data[0]['expiration_date']; |
|
| 283 | - $device_uid = (string)$data[1]; |
|
| 236 | + $accountCreator->setAccessToken($this->accessToken); |
|
| 237 | + $data = $accountCreator->execute(); |
|
| 238 | + |
|
| 239 | + if(isset($_POST['ancestor'])) |
|
| 240 | + { |
|
| 241 | + $actual_link = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|
| 242 | + header('Location: ' . $actual_link . '#postId-' . htmlspecialchars($data['post_id'])); |
|
| 243 | + exit; |
|
| 244 | + } |
|
| 245 | + else |
|
| 246 | + { |
|
| 247 | + header('Location: ./#'); |
|
| 248 | + exit; |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + function isTokenFresh() |
|
| 253 | + { |
|
| 254 | + $db = new DatabaseConnect(); |
|
| 255 | + $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
| 256 | + |
|
| 257 | + $access_token; |
|
| 258 | + |
|
| 259 | + if ($result->num_rows > 0) |
|
| 260 | + { |
|
| 261 | + // output data of each row |
|
| 262 | + while($row = $result->fetch_assoc()) { |
|
| 263 | + //$access_token = $row["access_token"]; |
|
| 264 | + $expiration_date = $row["expiration_date"]; |
|
| 265 | + $deviceUid = $row["device_uid"]; |
|
| 266 | + $access_token = $row["access_token"]; |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + else |
|
| 270 | + { |
|
| 271 | + echo '0 results'; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + if($expiration_date <= time()) { |
|
| 275 | + $accountCreator = new CreateUser(); |
|
| 276 | + $accountCreator->setAccessToken($access_token); |
|
| 277 | + $accountCreator->setDeviceUid($deviceUid); |
|
| 278 | + $accountCreator->setLocation($this->location); |
|
| 279 | + $data = $accountCreator->execute(); |
|
| 280 | + |
|
| 281 | + $access_token = (string)$data[0]['access_token']; |
|
| 282 | + $expiration_date = $data[0]['expiration_date']; |
|
| 283 | + $device_uid = (string)$data[1]; |
|
| 284 | 284 | |
| 285 | - $db = new DatabaseConnect(); |
|
| 286 | - $result = $db->query("UPDATE accounts |
|
| 285 | + $db = new DatabaseConnect(); |
|
| 286 | + $result = $db->query("UPDATE accounts |
|
| 287 | 287 | SET access_token='" . $access_token . "', |
| 288 | 288 | expiration_date='" . $expiration_date . "' |
| 289 | 289 | WHERE device_uid='" . $device_uid . "'"); |
| 290 | 290 | |
| 291 | - if($result === false){ |
|
| 292 | - echo "Adding account failed: (" . $db->errno . ") " . $db->error; |
|
| 293 | - } |
|
| 294 | - } |
|
| 291 | + if($result === false){ |
|
| 292 | + echo "Adding account failed: (" . $db->errno . ") " . $db->error; |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - return $access_token; |
|
| 297 | - } |
|
| 296 | + return $access_token; |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - function refreshToken() |
|
| 300 | - { |
|
| 299 | + function refreshToken() |
|
| 300 | + { |
|
| 301 | 301 | |
| 302 | - } |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | 304 | |
| 305 | 305 | |
| 306 | - function getAccessToken() |
|
| 307 | - { |
|
| 308 | - $db = new DatabaseConnect(); |
|
| 309 | - $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
| 306 | + function getAccessToken() |
|
| 307 | + { |
|
| 308 | + $db = new DatabaseConnect(); |
|
| 309 | + $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
| 310 | 310 | |
| 311 | - $accessToken; |
|
| 311 | + $accessToken; |
|
| 312 | 312 | |
| 313 | - if ($result->num_rows > 0) |
|
| 314 | - { |
|
| 315 | - // output data of each row |
|
| 316 | - while($row = $result->fetch_assoc()) |
|
| 317 | - { |
|
| 318 | - $accessToken = $row['access_token']; |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - else |
|
| 322 | - { |
|
| 323 | - echo "Error: 0 results"; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - return $accessToken; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - function getKarma() |
|
| 331 | - { |
|
| 332 | - $accountCreator = new GetKarma(); |
|
| 333 | - $accountCreator->setAccessToken($this->accessToken); |
|
| 334 | - $data = $accountCreator->execute(); |
|
| 313 | + if ($result->num_rows > 0) |
|
| 314 | + { |
|
| 315 | + // output data of each row |
|
| 316 | + while($row = $result->fetch_assoc()) |
|
| 317 | + { |
|
| 318 | + $accessToken = $row['access_token']; |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + else |
|
| 322 | + { |
|
| 323 | + echo "Error: 0 results"; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + return $accessToken; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + function getKarma() |
|
| 331 | + { |
|
| 332 | + $accountCreator = new GetKarma(); |
|
| 333 | + $accountCreator->setAccessToken($this->accessToken); |
|
| 334 | + $data = $accountCreator->execute(); |
|
| 335 | 335 | |
| 336 | - return $data["karma"]; |
|
| 337 | - } |
|
| 336 | + return $data["karma"]; |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - function deviceUidHasVotedThisPostId($postId) |
|
| 340 | - { |
|
| 341 | - $db = new DatabaseConnect(); |
|
| 339 | + function deviceUidHasVotedThisPostId($postId) |
|
| 340 | + { |
|
| 341 | + $db = new DatabaseConnect(); |
|
| 342 | 342 | |
| 343 | - $postId = $db->real_escape_string($postId); |
|
| 343 | + $postId = $db->real_escape_string($postId); |
|
| 344 | 344 | |
| 345 | - $result = $db->query("SELECT id |
|
| 345 | + $result = $db->query("SELECT id |
|
| 346 | 346 | FROM votes |
| 347 | 347 | WHERE (postId = '" . $postId . "' AND device_uid = '" . $this->deviceUid . "')"); |
| 348 | 348 | |
| 349 | - if($result === false) |
|
| 350 | - { |
|
| 351 | - $error = db_error(); |
|
| 352 | - echo $error; |
|
| 353 | - echo "Adding Vote failed: (" . $result->errno . ") " . $result->error; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - if($result->num_rows == 0) |
|
| 357 | - { |
|
| 358 | - return FALSE; |
|
| 359 | - } |
|
| 360 | - else |
|
| 361 | - { |
|
| 362 | - return TRUE; |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - function addVoteWithPostIdAndTypeToDeviceUid($postId, $voteType) |
|
| 367 | - { |
|
| 368 | - $db = new DatabaseConnect(); |
|
| 369 | - |
|
| 370 | - $postId = $db->real_escape_string($postId); |
|
| 371 | - $voteType = $db->real_escape_string($voteType); |
|
| 349 | + if($result === false) |
|
| 350 | + { |
|
| 351 | + $error = db_error(); |
|
| 352 | + echo $error; |
|
| 353 | + echo "Adding Vote failed: (" . $result->errno . ") " . $result->error; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + if($result->num_rows == 0) |
|
| 357 | + { |
|
| 358 | + return FALSE; |
|
| 359 | + } |
|
| 360 | + else |
|
| 361 | + { |
|
| 362 | + return TRUE; |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + function addVoteWithPostIdAndTypeToDeviceUid($postId, $voteType) |
|
| 367 | + { |
|
| 368 | + $db = new DatabaseConnect(); |
|
| 369 | + |
|
| 370 | + $postId = $db->real_escape_string($postId); |
|
| 371 | + $voteType = $db->real_escape_string($voteType); |
|
| 372 | 372 | |
| 373 | - if($this->deviceUidHasVotedThisPostId($postId)) |
|
| 374 | - { |
|
| 375 | - return "Already voted"; |
|
| 376 | - } |
|
| 373 | + if($this->deviceUidHasVotedThisPostId($postId)) |
|
| 374 | + { |
|
| 375 | + return "Already voted"; |
|
| 376 | + } |
|
| 377 | 377 | |
| 378 | - $result = $db->query("INSERT INTO votes (device_uid, postId, type) |
|
| 378 | + $result = $db->query("INSERT INTO votes (device_uid, postId, type) |
|
| 379 | 379 | VALUES ('" . $this->deviceUid . "','" . $postId . "','" . $voteType . "')"); |
| 380 | 380 | |
| 381 | - if($result === false){ |
|
| 382 | - $error = db_error(); |
|
| 383 | - echo $error; |
|
| 384 | - echo "Adding Vote failed: (" . $result->errno . ") " . $result->error; |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - function registerAccount($location) { |
|
| 389 | - $accountCreator = new CreateUser(); |
|
| 390 | - $accountCreator->setLocation($location); |
|
| 391 | - $data = $accountCreator->execute(); |
|
| 381 | + if($result === false){ |
|
| 382 | + $error = db_error(); |
|
| 383 | + echo $error; |
|
| 384 | + echo "Adding Vote failed: (" . $result->errno . ") " . $result->error; |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + function registerAccount($location) { |
|
| 389 | + $accountCreator = new CreateUser(); |
|
| 390 | + $accountCreator->setLocation($location); |
|
| 391 | + $data = $accountCreator->execute(); |
|
| 392 | 392 | |
| 393 | - $access_token = (string)$data[0]['access_token']; |
|
| 394 | - $refresh_token = (string)$data[0]['refresh_token']; |
|
| 395 | - $token_type = (string)$data[0]['token_type']; |
|
| 396 | - $expires_in = $data[0]['expires_in']; |
|
| 397 | - $expiration_date = $data[0]['expiration_date']; |
|
| 398 | - $distinct_id = (string)$data[0]['distinct_id']; |
|
| 399 | - $device_uid = (string)$data[1]; |
|
| 400 | - |
|
| 401 | - $name = $location->cityName; |
|
| 402 | - $lat = $location->lat; |
|
| 403 | - $lng = $location->lng; |
|
| 393 | + $access_token = (string)$data[0]['access_token']; |
|
| 394 | + $refresh_token = (string)$data[0]['refresh_token']; |
|
| 395 | + $token_type = (string)$data[0]['token_type']; |
|
| 396 | + $expires_in = $data[0]['expires_in']; |
|
| 397 | + $expiration_date = $data[0]['expiration_date']; |
|
| 398 | + $distinct_id = (string)$data[0]['distinct_id']; |
|
| 399 | + $device_uid = (string)$data[1]; |
|
| 400 | + |
|
| 401 | + $name = $location->cityName; |
|
| 402 | + $lat = $location->lat; |
|
| 403 | + $lng = $location->lng; |
|
| 404 | 404 | |
| 405 | - $db = new DatabaseConnect(); |
|
| 406 | - $result = $db->query("INSERT INTO accounts (access_token, refresh_token, token_type, |
|
| 405 | + $db = new DatabaseConnect(); |
|
| 406 | + $result = $db->query("INSERT INTO accounts (access_token, refresh_token, token_type, |
|
| 407 | 407 | expires_in, expiration_date, distinct_id, device_uid, name, lat, lng) |
| 408 | 408 | VALUES ('" . $access_token . "','" . $refresh_token . "','" . $token_type . |
| 409 | - "','" . $expires_in . "','" . $expiration_date . "','" . $distinct_id . |
|
| 410 | - "','" . $device_uid . "','" . $name . "','" . $lat . "','" . $lng . "') "); |
|
| 411 | - |
|
| 412 | - $success = TRUE; |
|
| 413 | - if($result === false){ |
|
| 414 | - $error = db_error(); |
|
| 415 | - echo $error; |
|
| 416 | - echo "Adding account failed: (" . $result->errno . ") " . $result->error; |
|
| 417 | - $success = FALSE; |
|
| 418 | - } |
|
| 409 | + "','" . $expires_in . "','" . $expiration_date . "','" . $distinct_id . |
|
| 410 | + "','" . $device_uid . "','" . $name . "','" . $lat . "','" . $lng . "') "); |
|
| 411 | + |
|
| 412 | + $success = TRUE; |
|
| 413 | + if($result === false){ |
|
| 414 | + $error = db_error(); |
|
| 415 | + echo $error; |
|
| 416 | + echo "Adding account failed: (" . $result->errno . ") " . $result->error; |
|
| 417 | + $success = FALSE; |
|
| 418 | + } |
|
| 419 | 419 | |
| 420 | - return $device_uid; |
|
| 421 | - } |
|
| 420 | + return $device_uid; |
|
| 421 | + } |
|
| 422 | 422 | |
| 423 | - function createAccount() |
|
| 424 | - { |
|
| 425 | - $config = parse_ini_file('config/config.ini.php'); |
|
| 426 | - $location = new Location(); |
|
| 427 | - $location->setLat($config['default_lat']); |
|
| 428 | - $location->setLng($config['default_lng']); |
|
| 429 | - $location->setCityName($config['default_location']); |
|
| 423 | + function createAccount() |
|
| 424 | + { |
|
| 425 | + $config = parse_ini_file('config/config.ini.php'); |
|
| 426 | + $location = new Location(); |
|
| 427 | + $location->setLat($config['default_lat']); |
|
| 428 | + $location->setLng($config['default_lng']); |
|
| 429 | + $location->setCityName($config['default_location']); |
|
| 430 | 430 | |
| 431 | - $deviceUid = $this->registerAccount($location); |
|
| 431 | + $deviceUid = $this->registerAccount($location); |
|
| 432 | 432 | |
| 433 | - return $deviceUid; |
|
| 434 | - } |
|
| 433 | + return $deviceUid; |
|
| 434 | + } |
|
| 435 | 435 | } |
| 436 | 436 | \ No newline at end of file |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | { |
| 36 | 36 | $this::refreshToken(); |
| 37 | 37 | } |
| 38 | - $this->accessToken = $this::getAccessToken(); |
|
| 38 | + $this->accessToken = $this::getAccessToken(); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | function isAccountVerified() |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | } |
| 95 | 95 | else |
| 96 | 96 | { |
| 97 | - error_log('User with JodelDeviceId:' . $this->deviceUid . ' [' . $_SERVER['REMOTE_ADDR'] . '][' . $_SERVER ['HTTP_USER_AGENT'] . '] changed to Location: ' . $name); |
|
| 97 | + error_log('User with JodelDeviceId:' . $this->deviceUid . ' [' . $_SERVER['REMOTE_ADDR'] . '][' . $_SERVER ['HTTP_USER_AGENT'] . '] changed to Location: ' . $name); |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | function getLocation() |
| 107 | 107 | { |
| 108 | 108 | $db = new DatabaseConnect(); |
| 109 | - $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
| 109 | + $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
| 110 | 110 | |
| 111 | 111 | $location = new Location(); |
| 112 | 112 | |
| 113 | - if ($result->num_rows > 0) |
|
| 113 | + if($result->num_rows > 0) |
|
| 114 | 114 | { |
| 115 | 115 | // output data of each row |
| 116 | 116 | while($row = $result->fetch_assoc()) |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | if(isset($_POST['color'])) |
| 201 | 201 | { |
| 202 | 202 | $color = $_POST['color']; |
| 203 | - switch ($color) { |
|
| 203 | + switch($color) { |
|
| 204 | 204 | case '8ABDB0': |
| 205 | 205 | $color = '8ABDB0'; |
| 206 | 206 | break; |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | $access_token; |
| 258 | 258 | |
| 259 | - if ($result->num_rows > 0) |
|
| 259 | + if($result->num_rows > 0) |
|
| 260 | 260 | { |
| 261 | 261 | // output data of each row |
| 262 | 262 | while($row = $result->fetch_assoc()) { |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | expiration_date='" . $expiration_date . "' |
| 289 | 289 | WHERE device_uid='" . $device_uid . "'"); |
| 290 | 290 | |
| 291 | - if($result === false){ |
|
| 291 | + if($result === false) { |
|
| 292 | 292 | echo "Adding account failed: (" . $db->errno . ") " . $db->error; |
| 293 | 293 | } |
| 294 | 294 | } |
@@ -306,11 +306,11 @@ discard block |
||
| 306 | 306 | function getAccessToken() |
| 307 | 307 | { |
| 308 | 308 | $db = new DatabaseConnect(); |
| 309 | - $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
| 309 | + $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
| 310 | 310 | |
| 311 | 311 | $accessToken; |
| 312 | 312 | |
| 313 | - if ($result->num_rows > 0) |
|
| 313 | + if($result->num_rows > 0) |
|
| 314 | 314 | { |
| 315 | 315 | // output data of each row |
| 316 | 316 | while($row = $result->fetch_assoc()) |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | $result = $db->query("INSERT INTO votes (device_uid, postId, type) |
| 379 | 379 | VALUES ('" . $this->deviceUid . "','" . $postId . "','" . $voteType . "')"); |
| 380 | 380 | |
| 381 | - if($result === false){ |
|
| 381 | + if($result === false) { |
|
| 382 | 382 | $error = db_error(); |
| 383 | 383 | echo $error; |
| 384 | 384 | echo "Adding Vote failed: (" . $result->errno . ") " . $result->error; |
@@ -406,11 +406,11 @@ discard block |
||
| 406 | 406 | $result = $db->query("INSERT INTO accounts (access_token, refresh_token, token_type, |
| 407 | 407 | expires_in, expiration_date, distinct_id, device_uid, name, lat, lng) |
| 408 | 408 | VALUES ('" . $access_token . "','" . $refresh_token . "','" . $token_type . |
| 409 | - "','" . $expires_in . "','" . $expiration_date . "','" . $distinct_id . |
|
| 409 | + "','" . $expires_in . "','" . $expiration_date . "','" . $distinct_id . |
|
| 410 | 410 | "','" . $device_uid . "','" . $name . "','" . $lat . "','" . $lng . "') "); |
| 411 | 411 | |
| 412 | 412 | $success = TRUE; |
| 413 | - if($result === false){ |
|
| 413 | + if($result === false) { |
|
| 414 | 414 | $error = db_error(); |
| 415 | 415 | echo $error; |
| 416 | 416 | echo "Adding account failed: (" . $result->errno . ") " . $result->error; |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | { |
| 44 | 44 | preg_match('/bot|spider|google|twitter/i', $_SERVER['HTTP_USER_AGENT'], $matches); |
| 45 | 45 | |
| 46 | - return (isset($matches[0])) ? true : false; |
|
| 46 | + return (isset($matches[0]))?true : false; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | function configPropertyExists($config, $property) |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | function isDeviceUidInDatabase($deviceUid) |
| 62 | 62 | { |
| 63 | 63 | $db = new DatabaseConnect(); |
| 64 | - $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid . "'"); |
|
| 64 | + $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid . "'"); |
|
| 65 | 65 | |
| 66 | - if ($result->num_rows > 0) |
|
| 66 | + if($result->num_rows > 0) |
|
| 67 | 67 | { |
| 68 | 68 | return TRUE; |
| 69 | 69 | } |
@@ -85,8 +85,8 @@ discard block |
||
| 85 | 85 | if(!isset($_COOKIE['JodelDeviceId']) || !isDeviceUidInDatabase($_COOKIE['JodelDeviceId'])) |
| 86 | 86 | { |
| 87 | 87 | $jodelAccountForView = new JodelAccount(); |
| 88 | - setcookie('JodelDeviceId', $jodelAccountForView->deviceUid, time()+60*60*24*365*10); |
|
| 89 | - error_log('Created account with JodelDeviceId:' . $jodelAccountForView->deviceUid . ' for [' . $_SERVER ['HTTP_USER_AGENT'] . ']'); |
|
| 88 | + setcookie('JodelDeviceId', $jodelAccountForView->deviceUid, time() + 60 * 60 * 24 * 365 * 10); |
|
| 89 | + error_log('Created account with JodelDeviceId:' . $jodelAccountForView->deviceUid . ' for [' . $_SERVER ['HTTP_USER_AGENT'] . ']'); |
|
| 90 | 90 | |
| 91 | 91 | } |
| 92 | 92 | else |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | //Set View |
| 115 | 115 | if(isset($_GET['view'])) |
| 116 | 116 | { |
| 117 | - switch ($_GET['view']) { |
|
| 117 | + switch($_GET['view']) { |
|
| 118 | 118 | case 'comment': |
| 119 | 119 | $view = 'comment'; |
| 120 | 120 | break; |
@@ -312,13 +312,13 @@ discard block |
||
| 312 | 312 | else |
| 313 | 313 | { |
| 314 | 314 | $version = 'v2'; |
| 315 | - if($view=='comment') |
|
| 315 | + if($view == 'comment') |
|
| 316 | 316 | { |
| 317 | 317 | $url = "/v2/posts/location/discussed/"; |
| 318 | 318 | } |
| 319 | 319 | else |
| 320 | 320 | { |
| 321 | - if($view=='upVote') |
|
| 321 | + if($view == 'upVote') |
|
| 322 | 322 | { |
| 323 | 323 | $url = "/v2/posts/location/popular/"; |
| 324 | 324 | } |