@@ -44,17 +44,17 @@ |
||
| 44 | 44 | { |
| 45 | 45 | //insert voter into db |
| 46 | 46 | $db = new DatabaseConnect(); |
| 47 | - $result = $db->query("INSERT INTO users (user_token, remaining_votes, device_uid, rights) |
|
| 47 | + $result = $db->query("INSERT INTO users (user_token, remaining_votes, device_uid, rights) |
|
| 48 | 48 | VALUES ('" . $db->escape_string($_POST['user_token']) |
| 49 | - . "','" . $db->escape_string($_POST['remaining_votes']) |
|
| 50 | - . "','" . $db->escape_string($_POST['device_uid']) |
|
| 51 | - . "','" . $db->escape_string($_POST['rights']) . "')"); |
|
| 49 | + . "','" . $db->escape_string($_POST['remaining_votes']) |
|
| 50 | + . "','" . $db->escape_string($_POST['device_uid']) |
|
| 51 | + . "','" . $db->escape_string($_POST['rights']) . "')"); |
|
| 52 | 52 | |
| 53 | - if($result === false){ |
|
| 54 | - $error = db_error(); |
|
| 55 | - error_log($error); |
|
| 56 | - error_log("Adding Voter failed: (" . $result->errno . ") " . $result->error); |
|
| 57 | - } |
|
| 53 | + if($result === false){ |
|
| 54 | + $error = db_error(); |
|
| 55 | + error_log($error); |
|
| 56 | + error_log("Adding Voter failed: (" . $result->errno . ") " . $result->error); |
|
| 57 | + } |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | //Vote |
@@ -49,27 +49,27 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | function user_log($msg) |
| 51 | 51 | { |
| 52 | - $log = $msg . PHP_EOL; |
|
| 53 | - file_put_contents(realpath(__DIR__ . '/..') . '/logs/user_log-' . date("j.n.Y") . '.txt', $log, FILE_APPEND); |
|
| 52 | + $log = $msg . PHP_EOL; |
|
| 53 | + file_put_contents(realpath(__DIR__ . '/..') . '/logs/user_log-' . date("j.n.Y") . '.txt', $log, FILE_APPEND); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | function isUserBot() |
| 57 | 57 | { |
| 58 | - preg_match('/bot|spider|google|twitter/i', $_SERVER['HTTP_USER_AGENT'], $matches); |
|
| 58 | + preg_match('/bot|spider|google|twitter/i', $_SERVER['HTTP_USER_AGENT'], $matches); |
|
| 59 | 59 | |
| 60 | - return (isset($matches[0])) ? true : false; |
|
| 60 | + return (isset($matches[0])) ? true : false; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | function configPropertyExists($config, $property) |
| 64 | 64 | { |
| 65 | - if(!array_key_exists($property, $config) || !isset($config[$property]) || $config[$property] == '' || $config[$property] == 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') |
|
| 66 | - { |
|
| 67 | - return FALSE; |
|
| 68 | - } |
|
| 69 | - else |
|
| 70 | - { |
|
| 71 | - return TRUE; |
|
| 72 | - } |
|
| 65 | + if(!array_key_exists($property, $config) || !isset($config[$property]) || $config[$property] == '' || $config[$property] == 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') |
|
| 66 | + { |
|
| 67 | + return FALSE; |
|
| 68 | + } |
|
| 69 | + else |
|
| 70 | + { |
|
| 71 | + return TRUE; |
|
| 72 | + } |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | function isUserVoter() |
@@ -110,17 +110,17 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | function isDeviceUidInDatabase($deviceUid) |
| 112 | 112 | { |
| 113 | - $db = new DatabaseConnect(); |
|
| 114 | - $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid . "'"); |
|
| 113 | + $db = new DatabaseConnect(); |
|
| 114 | + $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid . "'"); |
|
| 115 | 115 | |
| 116 | - if ($result->num_rows > 0) |
|
| 117 | - { |
|
| 118 | - return TRUE; |
|
| 119 | - } |
|
| 120 | - else |
|
| 121 | - { |
|
| 122 | - return FALSE; |
|
| 123 | - } |
|
| 116 | + if ($result->num_rows > 0) |
|
| 117 | + { |
|
| 118 | + return TRUE; |
|
| 119 | + } |
|
| 120 | + else |
|
| 121 | + { |
|
| 122 | + return FALSE; |
|
| 123 | + } |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | //Check if it's a Spider or Google Bot |
@@ -147,14 +147,14 @@ discard block |
||
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | if(configPropertyExists($config, 'karmaDeviceUid')) |
| 150 | - { |
|
| 151 | - $jodelAccountForKarma = new JodelAccount($config['karmaDeviceUid']); |
|
| 152 | - } |
|
| 153 | - else |
|
| 154 | - { |
|
| 155 | - error_log("No Karma deviceUid set in config file"); |
|
| 150 | + { |
|
| 151 | + $jodelAccountForKarma = new JodelAccount($config['karmaDeviceUid']); |
|
| 152 | + } |
|
| 153 | + else |
|
| 154 | + { |
|
| 155 | + error_log("No Karma deviceUid set in config file"); |
|
| 156 | 156 | $jodelAccountForKarma = new JodelAccount($deviceUid); |
| 157 | - } |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | 159 | /* |
| 160 | 160 | * Cunstruct View |
@@ -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 = 'SDydTnTdqqaiAMfneLkqXYxamvNuUYOmkqpdiZTu'; |
|
| 8 | - const USERAGENT = 'Jodel/4.34.2 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )'; |
|
| 9 | - const CLIENT_TYPE = 'android_4.34.2'; |
|
| 5 | + const CLIENTID = '81e8a76e-1e02-4d17-9ba0-8a7020261b26'; |
|
| 6 | + const APIURL = 'https://api.go-tellm.com/api'; |
|
| 7 | + const SECRET = 'SDydTnTdqqaiAMfneLkqXYxamvNuUYOmkqpdiZTu'; |
|
| 8 | + const USERAGENT = 'Jodel/4.34.2 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )'; |
|
| 9 | + const CLIENT_TYPE = 'android_4.34.2'; |
|
| 10 | 10 | |
| 11 | - private $accessToken = null; |
|
| 12 | - private $payLoad; |
|
| 13 | - public $expects = ''; |
|
| 14 | - public $version = 'v2'; |
|
| 15 | - public $hasPayload = FALSE; |
|
| 11 | + private $accessToken = null; |
|
| 12 | + private $payLoad; |
|
| 13 | + public $expects = ''; |
|
| 14 | + public $version = 'v2'; |
|
| 15 | + public $hasPayload = FALSE; |
|
| 16 | 16 | |
| 17 | - public function execute() |
|
| 18 | - { |
|
| 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,112 +45,112 @@ 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 | - $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 | + $result = json_decode($result->body, true); |
|
| 90 | 90 | |
| 91 | - if(array_key_exists('error', $result) && $result['error'] == 'length') |
|
| 92 | - { |
|
| 91 | + if(array_key_exists('error', $result) && $result['error'] == 'length') |
|
| 92 | + { |
|
| 93 | 93 | |
| 94 | - } |
|
| 95 | - else |
|
| 96 | - { |
|
| 97 | - error_log('Error 401 - ' . print_r($result, true)); |
|
| 98 | - } |
|
| 99 | - break; |
|
| 100 | - case 404: |
|
| 101 | - error_log('Error 404 - ' . print_r($result, true)); |
|
| 102 | - $result = json_decode($result->body, true); |
|
| 103 | - break; |
|
| 94 | + } |
|
| 95 | + else |
|
| 96 | + { |
|
| 97 | + error_log('Error 401 - ' . print_r($result, true)); |
|
| 98 | + } |
|
| 99 | + break; |
|
| 100 | + case 404: |
|
| 101 | + error_log('Error 404 - ' . print_r($result, true)); |
|
| 102 | + $result = json_decode($result->body, true); |
|
| 103 | + break; |
|
| 104 | 104 | case 477: |
| 105 | - $result = json_decode($result->body, true); |
|
| 106 | - error_log('Error 477 - ' . print_r($result, true)); |
|
| 107 | - break; |
|
| 108 | - case 429: |
|
| 109 | - error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true)); |
|
| 110 | - exit("Error 429: Too Many Requests"); |
|
| 111 | - break; |
|
| 112 | - case 403: |
|
| 113 | - error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true)); |
|
| 114 | - $result = json_decode($result->body, true); |
|
| 115 | - break; |
|
| 116 | - case 502: |
|
| 117 | - error_log('Error 502 - ' . print_r($result, true)); |
|
| 118 | - $result = json_decode($result->body, true); |
|
| 119 | - header('location:'.$_SERVER['PHP_SELF']); |
|
| 120 | - break; |
|
| 121 | - case 503: |
|
| 122 | - error_log('Error 503 - ' . print_r($result, true)); |
|
| 123 | - $result = json_decode($result->body, true); |
|
| 105 | + $result = json_decode($result->body, true); |
|
| 106 | + error_log('Error 477 - ' . print_r($result, true)); |
|
| 107 | + break; |
|
| 108 | + case 429: |
|
| 109 | + error_log('Error 429 - Too Many Requests' . print_r(json_decode($result->body, true), true)); |
|
| 110 | + exit("Error 429: Too Many Requests"); |
|
| 111 | + break; |
|
| 112 | + case 403: |
|
| 113 | + error_log('Error 403 - Access denied:' . print_r(json_decode($result->body, true), true)); |
|
| 114 | + $result = json_decode($result->body, true); |
|
| 115 | + break; |
|
| 116 | + case 502: |
|
| 117 | + error_log('Error 502 - ' . print_r($result, true)); |
|
| 118 | + $result = json_decode($result->body, true); |
|
| 119 | + header('location:'.$_SERVER['PHP_SELF']); |
|
| 120 | + break; |
|
| 121 | + case 503: |
|
| 122 | + error_log('Error 503 - ' . print_r($result, true)); |
|
| 123 | + $result = json_decode($result->body, true); |
|
| 124 | 124 | |
| 125 | - if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable') |
|
| 126 | - { |
|
| 127 | - header('location:'.$_SERVER['PHP_SELF']); |
|
| 128 | - } |
|
| 129 | - break; |
|
| 130 | - default: |
|
| 131 | - error_log('Error '.$result->status_code.' - unknown error'); |
|
| 132 | - $result = json_decode($result->body, true); |
|
| 133 | - } |
|
| 125 | + if(array_key_exists('error', $result) && $result['error'] == 'Service Unavailable') |
|
| 126 | + { |
|
| 127 | + header('location:'.$_SERVER['PHP_SELF']); |
|
| 128 | + } |
|
| 129 | + break; |
|
| 130 | + default: |
|
| 131 | + error_log('Error '.$result->status_code.' - unknown error'); |
|
| 132 | + $result = json_decode($result->body, true); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - //important for account refresh |
|
| 136 | - if($device_uid != '') |
|
| 137 | - { |
|
| 135 | + //important for account refresh |
|
| 136 | + if($device_uid != '') |
|
| 137 | + { |
|
| 138 | 138 | $result[0] = $result; |
| 139 | 139 | $result[1] = $device_uid; |
| 140 | - } |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | 142 | |
| 143 | - /* var_dump($result); */ |
|
| 143 | + /* var_dump($result); */ |
|
| 144 | 144 | |
| 145 | - return $result; |
|
| 146 | - } |
|
| 147 | - abstract function getPayload(); |
|
| 148 | - /** |
|
| 149 | - * Gets Sign headers |
|
| 150 | - * @return array headers |
|
| 151 | - */ |
|
| 152 | - private function getSignHeaders() |
|
| 153 | - { |
|
| 145 | + return $result; |
|
| 146 | + } |
|
| 147 | + abstract function getPayload(); |
|
| 148 | + /** |
|
| 149 | + * Gets Sign headers |
|
| 150 | + * @return array headers |
|
| 151 | + */ |
|
| 152 | + private function getSignHeaders() |
|
| 153 | + { |
|
| 154 | 154 | if($this->getAccessToken() == null) { |
| 155 | 155 | $payload_accessToken = ""; |
| 156 | 156 | } |
@@ -159,54 +159,54 @@ discard block |
||
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | |
| 162 | - $headers = array( |
|
| 163 | - "Connection" => "keep-alive", |
|
| 164 | - "Accept-Encoding" => "gzip", |
|
| 165 | - "Content-Type" => "application/json; charset=UTF-8", |
|
| 166 | - "User-Agent" => self::USERAGENT |
|
| 167 | - ); |
|
| 168 | - $timestamp = new DateTime(); |
|
| 169 | - $timestamp = $timestamp->format(DateTime::ATOM); |
|
| 170 | - $timestamp = substr($timestamp, 0, -6); |
|
| 171 | - $timestamp .= "Z"; |
|
| 172 | - $urlParts = parse_url($this->getFullUrl()); |
|
| 173 | - $url2 = ""; |
|
| 174 | - $req = [$this->getMethod(), |
|
| 175 | - $urlParts['host'], |
|
| 176 | - "443", |
|
| 177 | - $urlParts['path'], |
|
| 178 | - $payload_accessToken, |
|
| 179 | - $timestamp, |
|
| 180 | - $url2, |
|
| 181 | - $this->payLoad]; |
|
| 182 | - $reqString = implode("%", $req); |
|
| 183 | - $secret = self::SECRET; |
|
| 184 | - $signature = hash_hmac('sha1', $reqString, $secret); |
|
| 185 | - $signature = strtoupper($signature); |
|
| 186 | - $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
| 187 | - $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
| 188 | - $headers['X-Timestamp'] = $timestamp; |
|
| 189 | - $headers['X-Api-Version'] = '0.2'; |
|
| 190 | - return $headers; |
|
| 191 | - } |
|
| 192 | - private function getFullUrl() |
|
| 193 | - { |
|
| 194 | - return self::APIURL . $this->getApiEndPoint(); |
|
| 195 | - } |
|
| 196 | - abstract function getApiEndPoint(); |
|
| 197 | - abstract function getMethod(); |
|
| 198 | - /** |
|
| 199 | - * @return string |
|
| 200 | - */ |
|
| 201 | - private function getAccessToken() |
|
| 202 | - { |
|
| 203 | - return $this->accessToken; |
|
| 204 | - } |
|
| 205 | - /** |
|
| 206 | - * @param string $accessToken |
|
| 207 | - */ |
|
| 208 | - public function setAccessToken($accessToken) |
|
| 209 | - { |
|
| 210 | - $this->accessToken = $accessToken; |
|
| 211 | - } |
|
| 162 | + $headers = array( |
|
| 163 | + "Connection" => "keep-alive", |
|
| 164 | + "Accept-Encoding" => "gzip", |
|
| 165 | + "Content-Type" => "application/json; charset=UTF-8", |
|
| 166 | + "User-Agent" => self::USERAGENT |
|
| 167 | + ); |
|
| 168 | + $timestamp = new DateTime(); |
|
| 169 | + $timestamp = $timestamp->format(DateTime::ATOM); |
|
| 170 | + $timestamp = substr($timestamp, 0, -6); |
|
| 171 | + $timestamp .= "Z"; |
|
| 172 | + $urlParts = parse_url($this->getFullUrl()); |
|
| 173 | + $url2 = ""; |
|
| 174 | + $req = [$this->getMethod(), |
|
| 175 | + $urlParts['host'], |
|
| 176 | + "443", |
|
| 177 | + $urlParts['path'], |
|
| 178 | + $payload_accessToken, |
|
| 179 | + $timestamp, |
|
| 180 | + $url2, |
|
| 181 | + $this->payLoad]; |
|
| 182 | + $reqString = implode("%", $req); |
|
| 183 | + $secret = self::SECRET; |
|
| 184 | + $signature = hash_hmac('sha1', $reqString, $secret); |
|
| 185 | + $signature = strtoupper($signature); |
|
| 186 | + $headers['X-Authorization'] = 'HMAC ' . $signature; |
|
| 187 | + $headers['X-Client-Type'] = self::CLIENT_TYPE; |
|
| 188 | + $headers['X-Timestamp'] = $timestamp; |
|
| 189 | + $headers['X-Api-Version'] = '0.2'; |
|
| 190 | + return $headers; |
|
| 191 | + } |
|
| 192 | + private function getFullUrl() |
|
| 193 | + { |
|
| 194 | + return self::APIURL . $this->getApiEndPoint(); |
|
| 195 | + } |
|
| 196 | + abstract function getApiEndPoint(); |
|
| 197 | + abstract function getMethod(); |
|
| 198 | + /** |
|
| 199 | + * @return string |
|
| 200 | + */ |
|
| 201 | + private function getAccessToken() |
|
| 202 | + { |
|
| 203 | + return $this->accessToken; |
|
| 204 | + } |
|
| 205 | + /** |
|
| 206 | + * @param string $accessToken |
|
| 207 | + */ |
|
| 208 | + public function setAccessToken($accessToken) |
|
| 209 | + { |
|
| 210 | + $this->accessToken = $accessToken; |
|
| 211 | + } |
|
| 212 | 212 | } |
@@ -65,6 +65,6 @@ |
||
| 65 | 65 | |
| 66 | 66 | if(!$db->query($query) || !$db->query($query2) || !$db->query($query3)) |
| 67 | 67 | { |
| 68 | - throw new Exception($db->error($mysqli)); |
|
| 68 | + throw new Exception($db->error($mysqli)); |
|
| 69 | 69 | } |
| 70 | 70 | |
@@ -2,112 +2,112 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class View |
| 4 | 4 | { |
| 5 | - public $country; |
|
| 6 | - public $city; |
|
| 7 | - public $hashtag; |
|
| 5 | + public $country; |
|
| 6 | + public $city; |
|
| 7 | + public $hashtag; |
|
| 8 | 8 | public $view; |
| 9 | - public $postId; |
|
| 10 | - public $isDetailedView; |
|
| 11 | - public $baseUrl; |
|
| 12 | - public $rights; |
|
| 9 | + public $postId; |
|
| 10 | + public $isDetailedView; |
|
| 11 | + public $baseUrl; |
|
| 12 | + public $rights; |
|
| 13 | 13 | |
| 14 | 14 | public $lastPostId = ''; |
| 15 | 15 | |
| 16 | - function __construct($baseUrl, $country, $city, $hashtag = '%23all', $view = 'time', $postId = '') |
|
| 17 | - { |
|
| 18 | - $this->baseUrl = $baseUrl; |
|
| 19 | - $this->country = $country; |
|
| 20 | - $this->city = $city; |
|
| 21 | - $this->hashtag = urldecode($hashtag); |
|
| 22 | - $this->view = $view; |
|
| 23 | - $this->postId = $postId; |
|
| 16 | + function __construct($baseUrl, $country, $city, $hashtag = '%23all', $view = 'time', $postId = '') |
|
| 17 | + { |
|
| 18 | + $this->baseUrl = $baseUrl; |
|
| 19 | + $this->country = $country; |
|
| 20 | + $this->city = $city; |
|
| 21 | + $this->hashtag = urldecode($hashtag); |
|
| 22 | + $this->view = $view; |
|
| 23 | + $this->postId = $postId; |
|
| 24 | 24 | |
| 25 | - if(isUserAdmin()) |
|
| 26 | - { |
|
| 27 | - $this->rights = 'admin'; |
|
| 28 | - } |
|
| 29 | - else if(isUserVoter()) |
|
| 30 | - { |
|
| 31 | - $this->rights = 'voter'; |
|
| 32 | - } |
|
| 33 | - else |
|
| 34 | - { |
|
| 35 | - $this->rights = 'user'; |
|
| 36 | - } |
|
| 25 | + if(isUserAdmin()) |
|
| 26 | + { |
|
| 27 | + $this->rights = 'admin'; |
|
| 28 | + } |
|
| 29 | + else if(isUserVoter()) |
|
| 30 | + { |
|
| 31 | + $this->rights = 'voter'; |
|
| 32 | + } |
|
| 33 | + else |
|
| 34 | + { |
|
| 35 | + $this->rights = 'user'; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - if($postId == '') |
|
| 39 | - { |
|
| 40 | - $this->isDetailedView = FALSE; |
|
| 41 | - } |
|
| 42 | - else |
|
| 43 | - { |
|
| 44 | - $this->isDetailedView = TRUE; |
|
| 45 | - } |
|
| 46 | - } |
|
| 38 | + if($postId == '') |
|
| 39 | + { |
|
| 40 | + $this->isDetailedView = FALSE; |
|
| 41 | + } |
|
| 42 | + else |
|
| 43 | + { |
|
| 44 | + $this->isDetailedView = TRUE; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | /** |
| 48 | 48 | * Compute HTML Code |
| 49 | 49 | */ |
| 50 | 50 | function jodelToHtml($post) |
| 51 | - { //ToDO |
|
| 52 | - //Replace # with link |
|
| 53 | - //preg_replace('~(\#)([^\s!,. /()"\'?]+)~', '<a href="tag/$2">#$2</a>', $text); |
|
| 51 | + { //ToDO |
|
| 52 | + //Replace # with link |
|
| 53 | + //preg_replace('~(\#)([^\s!,. /()"\'?]+)~', '<a href="tag/$2">#$2</a>', $text); |
|
| 54 | 54 | |
| 55 | - //Time to time difference |
|
| 56 | - $now = new DateTime(); |
|
| 57 | - $d = new DateTime($post['created_at']); |
|
| 58 | - $timediff = $now->diff($d); |
|
| 55 | + //Time to time difference |
|
| 56 | + $now = new DateTime(); |
|
| 57 | + $d = new DateTime($post['created_at']); |
|
| 58 | + $timediff = $now->diff($d); |
|
| 59 | 59 | |
| 60 | - $timediff_inSeconds = (string)$timediff->format('%s'); |
|
| 61 | - $timediff_inMinutes = (string)$timediff->format('%i'); |
|
| 62 | - $timediff_inHours = (string)$timediff->format('%h'); |
|
| 63 | - $timediff_inDays = (string)$timediff->format('%d'); |
|
| 64 | - $timediff_inMonth = (string)$timediff->format('%m'); |
|
| 60 | + $timediff_inSeconds = (string)$timediff->format('%s'); |
|
| 61 | + $timediff_inMinutes = (string)$timediff->format('%i'); |
|
| 62 | + $timediff_inHours = (string)$timediff->format('%h'); |
|
| 63 | + $timediff_inDays = (string)$timediff->format('%d'); |
|
| 64 | + $timediff_inMonth = (string)$timediff->format('%m'); |
|
| 65 | 65 | |
| 66 | - if($timediff_inMonth!=0) |
|
| 67 | - { |
|
| 68 | - $timediff = $timediff_inMonth . "m"; |
|
| 69 | - } |
|
| 70 | - else |
|
| 71 | - { |
|
| 72 | - if($timediff_inDays!=0) |
|
| 73 | - { |
|
| 74 | - $timediff = $timediff_inDays . "d"; |
|
| 75 | - } |
|
| 76 | - else |
|
| 77 | - { |
|
| 78 | - if($timediff_inHours!=0) |
|
| 79 | - { |
|
| 80 | - $timediff = $timediff_inHours . "h"; |
|
| 81 | - } |
|
| 82 | - else |
|
| 83 | - { |
|
| 84 | - if($timediff_inMinutes!=0) |
|
| 85 | - { |
|
| 86 | - $timediff = $timediff_inMinutes . "m"; |
|
| 87 | - } |
|
| 88 | - else |
|
| 89 | - { |
|
| 90 | - $timediff = $timediff_inSeconds . "s"; |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - } |
|
| 66 | + if($timediff_inMonth!=0) |
|
| 67 | + { |
|
| 68 | + $timediff = $timediff_inMonth . "m"; |
|
| 69 | + } |
|
| 70 | + else |
|
| 71 | + { |
|
| 72 | + if($timediff_inDays!=0) |
|
| 73 | + { |
|
| 74 | + $timediff = $timediff_inDays . "d"; |
|
| 75 | + } |
|
| 76 | + else |
|
| 77 | + { |
|
| 78 | + if($timediff_inHours!=0) |
|
| 79 | + { |
|
| 80 | + $timediff = $timediff_inHours . "h"; |
|
| 81 | + } |
|
| 82 | + else |
|
| 83 | + { |
|
| 84 | + if($timediff_inMinutes!=0) |
|
| 85 | + { |
|
| 86 | + $timediff = $timediff_inMinutes . "m"; |
|
| 87 | + } |
|
| 88 | + else |
|
| 89 | + { |
|
| 90 | + $timediff = $timediff_inSeconds . "s"; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | 96 | |
| 97 | - ?> |
|
| 97 | + ?> |
|
| 98 | 98 | <article id ="postId-<?php echo $post['post_id']; ?>" class="jodel" style="background-color: #<?php echo $post['color'];?>;"> |
| 99 | 99 | <content> |
| 100 | 100 | <?php |
| 101 | - if(isset($post['image_url'])) |
|
| 102 | - { |
|
| 103 | - $regexRest = '/[^\w$ .!?-]+/u'; |
|
| 101 | + if(isset($post['image_url'])) |
|
| 102 | + { |
|
| 103 | + $regexRest = '/[^\w$ .!?-]+/u'; |
|
| 104 | 104 | |
| 105 | - echo '<img src="' . $post['image_url'] . '" alt="' . htmlspecialchars(preg_replace($regexRest, '', $post['message'])) . '">'; |
|
| 106 | - } |
|
| 107 | - else { |
|
| 108 | - echo str_replace(' ', ' ', nl2br(htmlspecialchars($post['message']))); |
|
| 109 | - } |
|
| 110 | - ?> |
|
| 105 | + echo '<img src="' . $post['image_url'] . '" alt="' . htmlspecialchars(preg_replace($regexRest, '', $post['message'])) . '">'; |
|
| 106 | + } |
|
| 107 | + else { |
|
| 108 | + echo str_replace(' ', ' ', nl2br(htmlspecialchars($post['message']))); |
|
| 109 | + } |
|
| 110 | + ?> |
|
| 111 | 111 | </content> |
| 112 | 112 | <aside> |
| 113 | 113 | <button onclick="vote('<?php echo $post['post_id'];?>', 'up', this)"> |
@@ -136,10 +136,10 @@ discard block |
||
| 136 | 136 | <a href="<?php echo $this->changePostId($post['post_id'])->toUrl();?>"> |
| 137 | 137 | <i class="fa fa-commenting-o"></i> |
| 138 | 138 | <?php if(array_key_exists("child_count", $post)) |
| 139 | - { |
|
| 140 | - echo $post["child_count"]; |
|
| 141 | - } else echo "0"; |
|
| 142 | - ?> |
|
| 139 | + { |
|
| 140 | + echo $post["child_count"]; |
|
| 141 | + } else echo "0"; |
|
| 142 | + ?> |
|
| 143 | 143 | </a> |
| 144 | 144 | </span> |
| 145 | 145 | |
@@ -159,30 +159,30 @@ discard block |
||
| 159 | 159 | ?> |
| 160 | 160 | <span class="distance"> |
| 161 | 161 | <?php |
| 162 | - if($this->isDetailedView) |
|
| 163 | - { |
|
| 164 | - if(isset($post['user_handle']) && $post['user_handle'] == 'OJ') |
|
| 165 | - { |
|
| 166 | - ?> |
|
| 162 | + if($this->isDetailedView) |
|
| 163 | + { |
|
| 164 | + if(isset($post['user_handle']) && $post['user_handle'] == 'OJ') |
|
| 165 | + { |
|
| 166 | + ?> |
|
| 167 | 167 | <span data-tooltip="Author"> |
| 168 | 168 | <i class="fa fa-user-o"></i> OJ | |
| 169 | 169 | </span> |
| 170 | 170 | <?php |
| 171 | - } |
|
| 172 | - else |
|
| 173 | - { |
|
| 174 | - //Is not parent Jodel in detailed View |
|
| 175 | - if(!array_key_exists('child_count', $post)) |
|
| 176 | - { |
|
| 177 | - ?> |
|
| 171 | + } |
|
| 172 | + else |
|
| 173 | + { |
|
| 174 | + //Is not parent Jodel in detailed View |
|
| 175 | + if(!array_key_exists('child_count', $post)) |
|
| 176 | + { |
|
| 177 | + ?> |
|
| 178 | 178 | <span data-tooltip="Author"> |
| 179 | 179 | <i class="fa fa-user-o"></i> #<?php echo $post['user_handle'];?> | |
| 180 | 180 | </span> |
| 181 | 181 | <?php |
| 182 | - } |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - ?> |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + ?> |
|
| 186 | 186 | |
| 187 | 187 | <span class="tip" data-tooltip="Distance"> |
| 188 | 188 | <i class="fa fa-map-marker"></i> |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | </footer> |
| 196 | 196 | </article> |
| 197 | 197 | <?php |
| 198 | - } |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -232,147 +232,147 @@ discard block |
||
| 232 | 232 | return $description; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - function toUrl($msg = '') |
|
| 236 | - { |
|
| 237 | - $url = $this->baseUrl . 'index.php?country=DE' . |
|
| 238 | - '&city=' . urlencode($this->city) . |
|
| 239 | - '&hashtag=' . urlencode($this->hashtag) . |
|
| 240 | - '&view=' . $this->view; |
|
| 241 | - if($this->postId != '') |
|
| 242 | - { |
|
| 243 | - $url .= '&postId=' . $this->postId . |
|
| 244 | - '&getPostDetails=TRUE'; |
|
| 245 | - } |
|
| 235 | + function toUrl($msg = '') |
|
| 236 | + { |
|
| 237 | + $url = $this->baseUrl . 'index.php?country=DE' . |
|
| 238 | + '&city=' . urlencode($this->city) . |
|
| 239 | + '&hashtag=' . urlencode($this->hashtag) . |
|
| 240 | + '&view=' . $this->view; |
|
| 241 | + if($this->postId != '') |
|
| 242 | + { |
|
| 243 | + $url .= '&postId=' . $this->postId . |
|
| 244 | + '&getPostDetails=TRUE'; |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - if($msg != '') |
|
| 248 | - { |
|
| 249 | - $url .= '&msg=' . urlencode($msg); |
|
| 250 | - } |
|
| 247 | + if($msg != '') |
|
| 248 | + { |
|
| 249 | + $url .= '&msg=' . urlencode($msg); |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | - return $url; |
|
| 253 | - } |
|
| 252 | + return $url; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - function changePostId($postId) |
|
| 256 | - { |
|
| 257 | - $tempView = clone $this; |
|
| 258 | - $tempView->postId = $postId; |
|
| 259 | - $tempView->isDetailedView = TRUE; |
|
| 260 | - return $tempView; |
|
| 261 | - } |
|
| 255 | + function changePostId($postId) |
|
| 256 | + { |
|
| 257 | + $tempView = clone $this; |
|
| 258 | + $tempView->postId = $postId; |
|
| 259 | + $tempView->isDetailedView = TRUE; |
|
| 260 | + return $tempView; |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - function back() |
|
| 264 | - { |
|
| 265 | - $tempView = clone $this; |
|
| 266 | - $tempView->postId = ''; |
|
| 267 | - return $tempView; |
|
| 268 | - } |
|
| 263 | + function back() |
|
| 264 | + { |
|
| 265 | + $tempView = clone $this; |
|
| 266 | + $tempView->postId = ''; |
|
| 267 | + return $tempView; |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - function changeView($view) |
|
| 271 | - { |
|
| 272 | - $tempView = clone $this; |
|
| 273 | - $tempView->view = $view; |
|
| 274 | - return $tempView; |
|
| 275 | - } |
|
| 270 | + function changeView($view) |
|
| 271 | + { |
|
| 272 | + $tempView = clone $this; |
|
| 273 | + $tempView->view = $view; |
|
| 274 | + return $tempView; |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | 277 | function getPosts($jodelAccount) |
| 278 | 278 | { |
| 279 | - if($this->hashtag != '#all' && $this->hashtag != '' && $this->hashtag != NULL) |
|
| 280 | - { |
|
| 281 | - $accountCreator = new GetChannel(); |
|
| 282 | - $accountCreator->view = $this->view; |
|
| 283 | - $accountCreator->setAccessToken($jodelAccount->accessToken); |
|
| 284 | - $accountCreator->channel = $this->hashtag; |
|
| 285 | - $accountCreator->lastPostId = $this->lastPostId; |
|
| 286 | - $data = $accountCreator->execute(); |
|
| 287 | - } |
|
| 288 | - else |
|
| 289 | - { |
|
| 290 | - if($this->lastPostId == '' && $this->view == 'combo') |
|
| 291 | - { |
|
| 292 | - $url = "/v3/posts/location/combo"; |
|
| 293 | - } |
|
| 294 | - else |
|
| 295 | - { |
|
| 296 | - if($this->view == 'discussed') |
|
| 297 | - { |
|
| 298 | - $url = "/v2/posts/location/discussed/"; |
|
| 299 | - } |
|
| 300 | - else |
|
| 301 | - { |
|
| 302 | - if($this->view == 'popular') |
|
| 303 | - { |
|
| 304 | - $url = "/v2/posts/location/popular/"; |
|
| 305 | - } |
|
| 306 | - else |
|
| 307 | - { |
|
| 308 | - $url = "/v2/posts/location/"; |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - } |
|
| 279 | + if($this->hashtag != '#all' && $this->hashtag != '' && $this->hashtag != NULL) |
|
| 280 | + { |
|
| 281 | + $accountCreator = new GetChannel(); |
|
| 282 | + $accountCreator->view = $this->view; |
|
| 283 | + $accountCreator->setAccessToken($jodelAccount->accessToken); |
|
| 284 | + $accountCreator->channel = $this->hashtag; |
|
| 285 | + $accountCreator->lastPostId = $this->lastPostId; |
|
| 286 | + $data = $accountCreator->execute(); |
|
| 287 | + } |
|
| 288 | + else |
|
| 289 | + { |
|
| 290 | + if($this->lastPostId == '' && $this->view == 'combo') |
|
| 291 | + { |
|
| 292 | + $url = "/v3/posts/location/combo"; |
|
| 293 | + } |
|
| 294 | + else |
|
| 295 | + { |
|
| 296 | + if($this->view == 'discussed') |
|
| 297 | + { |
|
| 298 | + $url = "/v2/posts/location/discussed/"; |
|
| 299 | + } |
|
| 300 | + else |
|
| 301 | + { |
|
| 302 | + if($this->view == 'popular') |
|
| 303 | + { |
|
| 304 | + $url = "/v2/posts/location/popular/"; |
|
| 305 | + } |
|
| 306 | + else |
|
| 307 | + { |
|
| 308 | + $url = "/v2/posts/location/"; |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - $accountCreator = new GetPosts(); |
|
| 314 | - $accountCreator->setLastPostId($this->lastPostId); |
|
| 315 | - $accountCreator->setAccessToken($jodelAccount->accessToken); |
|
| 316 | - $accountCreator->setUrl($url); |
|
| 317 | - $accountCreator->version = 'v3'; |
|
| 313 | + $accountCreator = new GetPosts(); |
|
| 314 | + $accountCreator->setLastPostId($this->lastPostId); |
|
| 315 | + $accountCreator->setAccessToken($jodelAccount->accessToken); |
|
| 316 | + $accountCreator->setUrl($url); |
|
| 317 | + $accountCreator->version = 'v3'; |
|
| 318 | 318 | |
| 319 | - $config = parse_ini_file('config/config.ini.php'); |
|
| 320 | - $location = new Location(); |
|
| 321 | - $location->setLat($config['default_lat']); |
|
| 322 | - $location->setLng($config['default_lng']); |
|
| 323 | - $location->setCityName($config['default_location']); |
|
| 324 | - $accountCreator->location = $location; |
|
| 325 | - $data = $accountCreator->execute(); |
|
| 326 | - } |
|
| 327 | - if(array_key_exists('recent', $data) && array_key_exists(0, $data['recent'])) |
|
| 328 | - { |
|
| 329 | - return $data['recent']; |
|
| 330 | - } |
|
| 331 | - else if(array_key_exists('posts', $data)&& array_key_exists(0, $data['posts'])) |
|
| 332 | - { |
|
| 333 | - return $data['posts']; |
|
| 334 | - } |
|
| 335 | - else |
|
| 336 | - { |
|
| 337 | - if($this->lastPostId == '') |
|
| 338 | - { |
|
| 339 | - error_log('Could not find Posts in: ' . $this->city . ' Error: ' . print_r($data, true)); |
|
| 340 | - //error_log(print_r($data, true)); |
|
| 319 | + $config = parse_ini_file('config/config.ini.php'); |
|
| 320 | + $location = new Location(); |
|
| 321 | + $location->setLat($config['default_lat']); |
|
| 322 | + $location->setLng($config['default_lng']); |
|
| 323 | + $location->setCityName($config['default_location']); |
|
| 324 | + $accountCreator->location = $location; |
|
| 325 | + $data = $accountCreator->execute(); |
|
| 326 | + } |
|
| 327 | + if(array_key_exists('recent', $data) && array_key_exists(0, $data['recent'])) |
|
| 328 | + { |
|
| 329 | + return $data['recent']; |
|
| 330 | + } |
|
| 331 | + else if(array_key_exists('posts', $data)&& array_key_exists(0, $data['posts'])) |
|
| 332 | + { |
|
| 333 | + return $data['posts']; |
|
| 334 | + } |
|
| 335 | + else |
|
| 336 | + { |
|
| 337 | + if($this->lastPostId == '') |
|
| 338 | + { |
|
| 339 | + error_log('Could not find Posts in: ' . $this->city . ' Error: ' . print_r($data, true)); |
|
| 340 | + //error_log(print_r($data, true)); |
|
| 341 | 341 | |
| 342 | - $notFound[0] = array( |
|
| 343 | - "post_id" => "0", |
|
| 344 | - "discovered_by" => 0, |
|
| 345 | - "message" => "No more Posts found", |
|
| 346 | - "created_at" => "2017-02-11T16:44:50.385Z", |
|
| 347 | - "updated_at" => "2017-02-11T16:44:50.385Z", |
|
| 348 | - "pin_count" => 0, |
|
| 349 | - "color" => "5682a3", |
|
| 350 | - "got_thanks" => FALSE, |
|
| 351 | - "post_own" => "friend", |
|
| 352 | - "discovered" => 0, |
|
| 353 | - "distance" => 9, |
|
| 354 | - "vote_count" => 0, |
|
| 355 | - "location" => |
|
| 356 | - array("name" => "Berlin", |
|
| 357 | - "loc_coordinates" => |
|
| 358 | - array( |
|
| 359 | - "lat" => 0, |
|
| 360 | - "lng" => 0 |
|
| 361 | - ), |
|
| 362 | - "loc_accuracy" => 0, |
|
| 363 | - "country" => "", |
|
| 364 | - "city" => "", |
|
| 365 | - ), |
|
| 366 | - "tags" => |
|
| 367 | - array(), |
|
| 368 | - "user_handle" => "0" |
|
| 369 | - ); |
|
| 370 | - return $notFound; |
|
| 371 | - } |
|
| 372 | - else |
|
| 373 | - { |
|
| 374 | - return FALSE; |
|
| 375 | - } |
|
| 376 | - } |
|
| 342 | + $notFound[0] = array( |
|
| 343 | + "post_id" => "0", |
|
| 344 | + "discovered_by" => 0, |
|
| 345 | + "message" => "No more Posts found", |
|
| 346 | + "created_at" => "2017-02-11T16:44:50.385Z", |
|
| 347 | + "updated_at" => "2017-02-11T16:44:50.385Z", |
|
| 348 | + "pin_count" => 0, |
|
| 349 | + "color" => "5682a3", |
|
| 350 | + "got_thanks" => FALSE, |
|
| 351 | + "post_own" => "friend", |
|
| 352 | + "discovered" => 0, |
|
| 353 | + "distance" => 9, |
|
| 354 | + "vote_count" => 0, |
|
| 355 | + "location" => |
|
| 356 | + array("name" => "Berlin", |
|
| 357 | + "loc_coordinates" => |
|
| 358 | + array( |
|
| 359 | + "lat" => 0, |
|
| 360 | + "lng" => 0 |
|
| 361 | + ), |
|
| 362 | + "loc_accuracy" => 0, |
|
| 363 | + "country" => "", |
|
| 364 | + "city" => "", |
|
| 365 | + ), |
|
| 366 | + "tags" => |
|
| 367 | + array(), |
|
| 368 | + "user_handle" => "0" |
|
| 369 | + ); |
|
| 370 | + return $notFound; |
|
| 371 | + } |
|
| 372 | + else |
|
| 373 | + { |
|
| 374 | + return FALSE; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | 377 | } |
| 378 | 378 | } |
@@ -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,503 +71,503 @@ 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(); |
|
| 74 | + function getCaptcha() |
|
| 75 | + { |
|
| 76 | + $accountCreator = new GetCaptcha(); |
|
| 77 | + $accountCreator->setAccessToken($this->accessToken); |
|
| 78 | + $captcha = $accountCreator->execute(); |
|
| 79 | 79 | |
| 80 | - return array("image_url" => $captcha['image_url'], "key" => $captcha['key']); |
|
| 81 | - } |
|
| 80 | + return array("image_url" => $captcha['image_url'], "key" => $captcha['key']); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - function isAccountVerified() |
|
| 84 | - { |
|
| 85 | - $accountCreator = new GetUserConfig(); |
|
| 86 | - $accountCreator->setAccessToken($this->accessToken); |
|
| 87 | - $data = $accountCreator->execute(); |
|
| 83 | + function isAccountVerified() |
|
| 84 | + { |
|
| 85 | + $accountCreator = new GetUserConfig(); |
|
| 86 | + $accountCreator->setAccessToken($this->accessToken); |
|
| 87 | + $data = $accountCreator->execute(); |
|
| 88 | 88 | |
| 89 | - //error_log(print_r($data, true)); |
|
| 89 | + //error_log(print_r($data, true)); |
|
| 90 | 90 | |
| 91 | - return $data['verified']; |
|
| 92 | - } |
|
| 91 | + return $data['verified']; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - function locationEquals($city) |
|
| 95 | - { |
|
| 96 | - $url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($city) . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w'; |
|
| 97 | - $result = Requests::post($url); |
|
| 98 | - if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST') |
|
| 99 | - { |
|
| 100 | - error_log('Error locationEquals'); |
|
| 101 | - return FALSE; |
|
| 102 | - } |
|
| 103 | - else |
|
| 104 | - { |
|
| 105 | - $name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name']; |
|
| 106 | - $lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat']; |
|
| 107 | - $lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng']; |
|
| 108 | - } |
|
| 94 | + function locationEquals($city) |
|
| 95 | + { |
|
| 96 | + $url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($city) . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w'; |
|
| 97 | + $result = Requests::post($url); |
|
| 98 | + if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST') |
|
| 99 | + { |
|
| 100 | + error_log('Error locationEquals'); |
|
| 101 | + return FALSE; |
|
| 102 | + } |
|
| 103 | + else |
|
| 104 | + { |
|
| 105 | + $name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name']; |
|
| 106 | + $lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat']; |
|
| 107 | + $lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng']; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - $db = new DatabaseConnect(); |
|
| 111 | - $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
| 110 | + $db = new DatabaseConnect(); |
|
| 111 | + $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
| 112 | 112 | |
| 113 | - $location = new Location(); |
|
| 113 | + $location = new Location(); |
|
| 114 | 114 | |
| 115 | - if ($result->num_rows > 0) |
|
| 116 | - { |
|
| 117 | - // output data of each row |
|
| 118 | - while($row = $result->fetch_assoc()) |
|
| 119 | - { |
|
| 120 | - $location->setLat($row['lat']); |
|
| 121 | - $location->setLng($row['lng']); |
|
| 122 | - $location->setCityName($row['name']); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - else |
|
| 126 | - { |
|
| 127 | - error_log("Error no Location found - getLocation"); |
|
| 128 | - } |
|
| 115 | + if ($result->num_rows > 0) |
|
| 116 | + { |
|
| 117 | + // output data of each row |
|
| 118 | + while($row = $result->fetch_assoc()) |
|
| 119 | + { |
|
| 120 | + $location->setLat($row['lat']); |
|
| 121 | + $location->setLng($row['lng']); |
|
| 122 | + $location->setCityName($row['name']); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + else |
|
| 126 | + { |
|
| 127 | + error_log("Error no Location found - getLocation"); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - if($location->getLat() == $lat && $location->getLng() == $lng && $location->getCityName() == $name) |
|
| 131 | - { |
|
| 132 | - return TRUE; |
|
| 133 | - } |
|
| 134 | - else |
|
| 135 | - { |
|
| 136 | - return FALSE; |
|
| 137 | - } |
|
| 138 | - } |
|
| 130 | + if($location->getLat() == $lat && $location->getLng() == $lng && $location->getCityName() == $name) |
|
| 131 | + { |
|
| 132 | + return TRUE; |
|
| 133 | + } |
|
| 134 | + else |
|
| 135 | + { |
|
| 136 | + return FALSE; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - function setLocation() |
|
| 141 | - { |
|
| 142 | - //Is Channel or City |
|
| 143 | - if(substr($_GET['city'], 0, 1) === '#') |
|
| 144 | - { |
|
| 145 | - return htmlspecialchars($_GET['city']) . " " . $this->location->cityName; |
|
| 146 | - } |
|
| 147 | - else |
|
| 148 | - { |
|
| 149 | - $url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($_GET['city']) . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w'; |
|
| 150 | - $result = Requests::post($url); |
|
| 151 | - if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST') |
|
| 152 | - { |
|
| 153 | - return "0 results"; |
|
| 154 | - } |
|
| 155 | - else |
|
| 156 | - { |
|
| 157 | - $name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name']; |
|
| 158 | - $lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat']; |
|
| 159 | - $lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng']; |
|
| 160 | - |
|
| 161 | - $location = new Location(); |
|
| 162 | - $location->setLat($lat); |
|
| 163 | - $location->setLng($lng); |
|
| 164 | - $location->setCityName($name); |
|
| 165 | - $accountCreator = new UpdateLocation(); |
|
| 166 | - $accountCreator->setLocation($location); |
|
| 167 | - $accountCreator->setAccessToken($this->accessToken); |
|
| 168 | - $data = $accountCreator->execute(); |
|
| 169 | - |
|
| 170 | - //safe location to db |
|
| 171 | - $db = new DatabaseConnect(); |
|
| 172 | - |
|
| 173 | - if($data == 'Success') |
|
| 174 | - { |
|
| 175 | - $result = $db->query("UPDATE accounts |
|
| 140 | + function setLocation() |
|
| 141 | + { |
|
| 142 | + //Is Channel or City |
|
| 143 | + if(substr($_GET['city'], 0, 1) === '#') |
|
| 144 | + { |
|
| 145 | + return htmlspecialchars($_GET['city']) . " " . $this->location->cityName; |
|
| 146 | + } |
|
| 147 | + else |
|
| 148 | + { |
|
| 149 | + $url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($_GET['city']) . '&key=AIzaSyCwhnja-or07012HqrhPW7prHEDuSvFT4w'; |
|
| 150 | + $result = Requests::post($url); |
|
| 151 | + if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST') |
|
| 152 | + { |
|
| 153 | + return "0 results"; |
|
| 154 | + } |
|
| 155 | + else |
|
| 156 | + { |
|
| 157 | + $name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name']; |
|
| 158 | + $lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat']; |
|
| 159 | + $lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng']; |
|
| 160 | + |
|
| 161 | + $location = new Location(); |
|
| 162 | + $location->setLat($lat); |
|
| 163 | + $location->setLng($lng); |
|
| 164 | + $location->setCityName($name); |
|
| 165 | + $accountCreator = new UpdateLocation(); |
|
| 166 | + $accountCreator->setLocation($location); |
|
| 167 | + $accountCreator->setAccessToken($this->accessToken); |
|
| 168 | + $data = $accountCreator->execute(); |
|
| 169 | + |
|
| 170 | + //safe location to db |
|
| 171 | + $db = new DatabaseConnect(); |
|
| 172 | + |
|
| 173 | + if($data == 'Success') |
|
| 174 | + { |
|
| 175 | + $result = $db->query("UPDATE accounts |
|
| 176 | 176 | SET name='" . $name . "', |
| 177 | 177 | lat='" . $lat . "', |
| 178 | 178 | lng='" . $lng . "' |
| 179 | 179 | WHERE access_token='" . $this->accessToken . "'"); |
| 180 | 180 | |
| 181 | - if($result === false) |
|
| 182 | - { |
|
| 183 | - echo "Updating location failed: (" . $db->errno . ") " . $db->error; |
|
| 184 | - } |
|
| 185 | - else |
|
| 186 | - { |
|
| 187 | - user_log('User with JodelDeviceId:' . $this->deviceUid . ' [' . $_SERVER['REMOTE_ADDR'] . '][' . $_SERVER ['HTTP_USER_AGENT'] . '] changed to Location: ' . $name); |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return $name; |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - } |
|
| 181 | + if($result === false) |
|
| 182 | + { |
|
| 183 | + echo "Updating location failed: (" . $db->errno . ") " . $db->error; |
|
| 184 | + } |
|
| 185 | + else |
|
| 186 | + { |
|
| 187 | + user_log('User with JodelDeviceId:' . $this->deviceUid . ' [' . $_SERVER['REMOTE_ADDR'] . '][' . $_SERVER ['HTTP_USER_AGENT'] . '] changed to Location: ' . $name); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return $name; |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - function getLocation() |
|
| 197 | - { |
|
| 198 | - $db = new DatabaseConnect(); |
|
| 199 | - $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
| 196 | + function getLocation() |
|
| 197 | + { |
|
| 198 | + $db = new DatabaseConnect(); |
|
| 199 | + $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
| 200 | 200 | |
| 201 | - $location = new Location(); |
|
| 201 | + $location = new Location(); |
|
| 202 | 202 | |
| 203 | - if ($result->num_rows > 0) |
|
| 204 | - { |
|
| 205 | - // output data of each row |
|
| 206 | - while($row = $result->fetch_assoc()) |
|
| 207 | - { |
|
| 208 | - $location->setLat($row['lat']); |
|
| 209 | - $location->setLng($row['lng']); |
|
| 210 | - $location->setCityName($row['name']); |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - else |
|
| 214 | - { |
|
| 215 | - echo "Error: 0 results"; |
|
| 216 | - error_log("Error no Location found - getLocation"); |
|
| 217 | - } |
|
| 203 | + if ($result->num_rows > 0) |
|
| 204 | + { |
|
| 205 | + // output data of each row |
|
| 206 | + while($row = $result->fetch_assoc()) |
|
| 207 | + { |
|
| 208 | + $location->setLat($row['lat']); |
|
| 209 | + $location->setLng($row['lng']); |
|
| 210 | + $location->setCityName($row['name']); |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + else |
|
| 214 | + { |
|
| 215 | + echo "Error: 0 results"; |
|
| 216 | + error_log("Error no Location found - getLocation"); |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - return $location; |
|
| 220 | - } |
|
| 219 | + return $location; |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - function verifyCaptcha() |
|
| 223 | - { |
|
| 224 | - if(isset($_GET['deviceUid'])) |
|
| 225 | - { |
|
| 226 | - $deviceUid = $_GET['deviceUid']; |
|
| 227 | - $jodelAccountForVerify = new JodelAccount($deviceUid); |
|
| 228 | - } |
|
| 229 | - else if(isset($_POST['deviceUid'])) |
|
| 230 | - { |
|
| 231 | - $deviceUid = $_POST['deviceUid']; |
|
| 232 | - $jodelAccountForVerify = new JodelAccount($deviceUid); |
|
| 233 | - } |
|
| 234 | - else |
|
| 235 | - { |
|
| 236 | - $deviceUid = $this->deviceUid; |
|
| 237 | - $jodelAccountForVerify = $this; |
|
| 238 | - } |
|
| 222 | + function verifyCaptcha() |
|
| 223 | + { |
|
| 224 | + if(isset($_GET['deviceUid'])) |
|
| 225 | + { |
|
| 226 | + $deviceUid = $_GET['deviceUid']; |
|
| 227 | + $jodelAccountForVerify = new JodelAccount($deviceUid); |
|
| 228 | + } |
|
| 229 | + else if(isset($_POST['deviceUid'])) |
|
| 230 | + { |
|
| 231 | + $deviceUid = $_POST['deviceUid']; |
|
| 232 | + $jodelAccountForVerify = new JodelAccount($deviceUid); |
|
| 233 | + } |
|
| 234 | + else |
|
| 235 | + { |
|
| 236 | + $deviceUid = $this->deviceUid; |
|
| 237 | + $jodelAccountForVerify = $this; |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - $solution = $_GET['solution']; |
|
| 241 | - $solution = array_map('intval', explode('-', $solution)); |
|
| 240 | + $solution = $_GET['solution']; |
|
| 241 | + $solution = array_map('intval', explode('-', $solution)); |
|
| 242 | 242 | |
| 243 | - $accountCreator = new PostCaptcha(); |
|
| 244 | - $accountCreator->setAccessToken($jodelAccountForVerify->accessToken); |
|
| 245 | - $accountCreator->captchaKey = $_GET['key']; |
|
| 246 | - $accountCreator->captchaSolution = $solution; |
|
| 247 | - $verified = $accountCreator->execute(); |
|
| 243 | + $accountCreator = new PostCaptcha(); |
|
| 244 | + $accountCreator->setAccessToken($jodelAccountForVerify->accessToken); |
|
| 245 | + $accountCreator->captchaKey = $_GET['key']; |
|
| 246 | + $accountCreator->captchaSolution = $solution; |
|
| 247 | + $verified = $accountCreator->execute(); |
|
| 248 | 248 | |
| 249 | - if(isset($verified->status_code)) |
|
| 250 | - { |
|
| 251 | - return $verified->status_code; |
|
| 252 | - } |
|
| 253 | - return $verified['verified']; |
|
| 254 | - } |
|
| 249 | + if(isset($verified->status_code)) |
|
| 250 | + { |
|
| 251 | + return $verified->status_code; |
|
| 252 | + } |
|
| 253 | + return $verified['verified']; |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - //ToDo Spider Check |
|
| 257 | - function votePostId($postId, $vote) |
|
| 258 | - { |
|
| 259 | - if(!$this->isBot) |
|
| 260 | - { |
|
| 261 | - if(!$this->isAccountVerified()) |
|
| 262 | - { |
|
| 256 | + //ToDo Spider Check |
|
| 257 | + function votePostId($postId, $vote) |
|
| 258 | + { |
|
| 259 | + if(!$this->isBot) |
|
| 260 | + { |
|
| 261 | + if(!$this->isAccountVerified()) |
|
| 262 | + { |
|
| 263 | 263 | |
| 264 | - } |
|
| 265 | - |
|
| 266 | - if(!$this->hasVoted($postId)) |
|
| 267 | - { |
|
| 268 | - if($vote == "up") |
|
| 269 | - { |
|
| 270 | - $accountCreator = new Upvote(); |
|
| 271 | - } |
|
| 272 | - else if($vote == "down") |
|
| 273 | - { |
|
| 274 | - $accountCreator = new Downvote(); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - $accountCreator->setAccessToken($this->accessToken); |
|
| 278 | - $accountCreator->postId = htmlspecialchars($postId); |
|
| 279 | - $data = $accountCreator->execute(); |
|
| 280 | - |
|
| 281 | - user_log('User voted: ' . print_r($data, true)); |
|
| 282 | - |
|
| 283 | - if(array_key_exists('post', $data)) |
|
| 284 | - { |
|
| 285 | - $this->addVoteWithPostIdAndType($postId, $vote); |
|
| 286 | - return TRUE; |
|
| 287 | - } |
|
| 288 | - else if(array_key_exists('error', $data)) |
|
| 289 | - { |
|
| 290 | - error_log('Could not vote - Error: ' . $data['error']); |
|
| 291 | - } |
|
| 292 | - else |
|
| 293 | - { |
|
| 294 | - error_log('Could not vote: ' . print_r($data, true)); |
|
| 295 | - return FALSE; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - else |
|
| 299 | - { |
|
| 300 | - return FALSE; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return FALSE; |
|
| 305 | - } |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + if(!$this->hasVoted($postId)) |
|
| 267 | + { |
|
| 268 | + if($vote == "up") |
|
| 269 | + { |
|
| 270 | + $accountCreator = new Upvote(); |
|
| 271 | + } |
|
| 272 | + else if($vote == "down") |
|
| 273 | + { |
|
| 274 | + $accountCreator = new Downvote(); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + $accountCreator->setAccessToken($this->accessToken); |
|
| 278 | + $accountCreator->postId = htmlspecialchars($postId); |
|
| 279 | + $data = $accountCreator->execute(); |
|
| 280 | + |
|
| 281 | + user_log('User voted: ' . print_r($data, true)); |
|
| 282 | + |
|
| 283 | + if(array_key_exists('post', $data)) |
|
| 284 | + { |
|
| 285 | + $this->addVoteWithPostIdAndType($postId, $vote); |
|
| 286 | + return TRUE; |
|
| 287 | + } |
|
| 288 | + else if(array_key_exists('error', $data)) |
|
| 289 | + { |
|
| 290 | + error_log('Could not vote - Error: ' . $data['error']); |
|
| 291 | + } |
|
| 292 | + else |
|
| 293 | + { |
|
| 294 | + error_log('Could not vote: ' . print_r($data, true)); |
|
| 295 | + return FALSE; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + else |
|
| 299 | + { |
|
| 300 | + return FALSE; |
|
| 301 | + } |
|
| 302 | + } |
|
| 306 | 303 | |
| 307 | - //ToDo Spider Check |
|
| 308 | - function sendJodel($location, $view) |
|
| 309 | - { |
|
| 310 | - if($this->isAccountVerified() != 1) |
|
| 311 | - { |
|
| 312 | - $this->showCaptcha(); |
|
| 313 | - //$this->verifyCaptcha(); |
|
| 314 | - } |
|
| 304 | + return FALSE; |
|
| 305 | + } |
|
| 315 | 306 | |
| 316 | - $accountCreator = new SendJodel(); |
|
| 307 | + //ToDo Spider Check |
|
| 308 | + function sendJodel($location, $view) |
|
| 309 | + { |
|
| 310 | + if($this->isAccountVerified() != 1) |
|
| 311 | + { |
|
| 312 | + $this->showCaptcha(); |
|
| 313 | + //$this->verifyCaptcha(); |
|
| 314 | + } |
|
| 317 | 315 | |
| 318 | - if(isset($_POST['ancestor'])) |
|
| 319 | - { |
|
| 320 | - $ancestor = $_POST['ancestor']; |
|
| 321 | - $accountCreator->ancestor = $ancestor; |
|
| 322 | - } |
|
| 323 | - if(isset($_POST['color'])) |
|
| 324 | - { |
|
| 325 | - $color = $_POST['color']; |
|
| 326 | - switch ($color) { |
|
| 327 | - case '8ABDB0': |
|
| 328 | - $color = '8ABDB0'; |
|
| 329 | - break; |
|
| 330 | - case '9EC41C': |
|
| 331 | - $color = '9EC41C'; |
|
| 332 | - break; |
|
| 333 | - case '06A3CB': |
|
| 334 | - $color = '06A3CB'; |
|
| 335 | - break; |
|
| 336 | - case 'FFBA00': |
|
| 337 | - $color = 'FFBA00'; |
|
| 338 | - break; |
|
| 339 | - case 'DD5F5F': |
|
| 340 | - $color = 'DD5F5F'; |
|
| 341 | - break; |
|
| 342 | - case 'FF9908': |
|
| 343 | - $color = 'FF9908'; |
|
| 344 | - break; |
|
| 345 | - default: |
|
| 346 | - $color = '8ABDB0'; |
|
| 347 | - break; |
|
| 348 | - } |
|
| 349 | - $accountCreator->color = $color; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - $accountCreatorLocation = new UpdateLocation(); |
|
| 353 | - $accountCreatorLocation->setLocation($location); |
|
| 354 | - $accountCreatorLocation->setAccessToken($this->accessToken); |
|
| 355 | - $data = $accountCreatorLocation->execute(); |
|
| 316 | + $accountCreator = new SendJodel(); |
|
| 317 | + |
|
| 318 | + if(isset($_POST['ancestor'])) |
|
| 319 | + { |
|
| 320 | + $ancestor = $_POST['ancestor']; |
|
| 321 | + $accountCreator->ancestor = $ancestor; |
|
| 322 | + } |
|
| 323 | + if(isset($_POST['color'])) |
|
| 324 | + { |
|
| 325 | + $color = $_POST['color']; |
|
| 326 | + switch ($color) { |
|
| 327 | + case '8ABDB0': |
|
| 328 | + $color = '8ABDB0'; |
|
| 329 | + break; |
|
| 330 | + case '9EC41C': |
|
| 331 | + $color = '9EC41C'; |
|
| 332 | + break; |
|
| 333 | + case '06A3CB': |
|
| 334 | + $color = '06A3CB'; |
|
| 335 | + break; |
|
| 336 | + case 'FFBA00': |
|
| 337 | + $color = 'FFBA00'; |
|
| 338 | + break; |
|
| 339 | + case 'DD5F5F': |
|
| 340 | + $color = 'DD5F5F'; |
|
| 341 | + break; |
|
| 342 | + case 'FF9908': |
|
| 343 | + $color = 'FF9908'; |
|
| 344 | + break; |
|
| 345 | + default: |
|
| 346 | + $color = '8ABDB0'; |
|
| 347 | + break; |
|
| 348 | + } |
|
| 349 | + $accountCreator->color = $color; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + $accountCreatorLocation = new UpdateLocation(); |
|
| 353 | + $accountCreatorLocation->setLocation($location); |
|
| 354 | + $accountCreatorLocation->setAccessToken($this->accessToken); |
|
| 355 | + $data = $accountCreatorLocation->execute(); |
|
| 356 | 356 | |
| 357 | 357 | if($data != 'Success') |
| 358 | 358 | { |
| 359 | 359 | error_log('Could not set location befor Post: ' . print_r($data, true)); |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - $accountCreator->location = $this->location; |
|
| 362 | + $accountCreator->location = $this->location; |
|
| 363 | 363 | |
| 364 | - $image = ''; |
|
| 365 | - if(isset($_FILES['image']) && $_FILES['image']['size'] > 0) |
|
| 366 | - { |
|
| 367 | - $image = file_get_contents($_FILES['image']['tmp_name']); |
|
| 368 | - } |
|
| 364 | + $image = ''; |
|
| 365 | + if(isset($_FILES['image']) && $_FILES['image']['size'] > 0) |
|
| 366 | + { |
|
| 367 | + $image = file_get_contents($_FILES['image']['tmp_name']); |
|
| 368 | + } |
|
| 369 | 369 | |
| 370 | - $accountCreator->image = $image; |
|
| 370 | + $accountCreator->image = $image; |
|
| 371 | 371 | |
| 372 | - $accountCreator->setAccessToken($this->accessToken); |
|
| 373 | - $data = $accountCreator->execute(); |
|
| 372 | + $accountCreator->setAccessToken($this->accessToken); |
|
| 373 | + $data = $accountCreator->execute(); |
|
| 374 | 374 | |
| 375 | - if(isset($data['error']) && $data['error'] == 'length') |
|
| 376 | - { |
|
| 377 | - $errorMsg = 'Error: The input was to long'; |
|
| 378 | - return $errorMsg; |
|
| 379 | - } |
|
| 375 | + if(isset($data['error']) && $data['error'] == 'length') |
|
| 376 | + { |
|
| 377 | + $errorMsg = 'Error: The input was to long'; |
|
| 378 | + return $errorMsg; |
|
| 379 | + } |
|
| 380 | 380 | |
| 381 | - user_log('User posted: ' . print_r($data, true)); |
|
| 381 | + user_log('User posted: ' . print_r($data, true)); |
|
| 382 | 382 | |
| 383 | - if(isset($_POST['ancestor'])) |
|
| 384 | - { |
|
| 385 | - header('Location: ' . $view->toUrl()); |
|
| 386 | - exit; |
|
| 387 | - } |
|
| 388 | - else |
|
| 389 | - { |
|
| 390 | - header('Location: ' . $view->baseUrl); |
|
| 391 | - exit; |
|
| 392 | - } |
|
| 393 | - } |
|
| 383 | + if(isset($_POST['ancestor'])) |
|
| 384 | + { |
|
| 385 | + header('Location: ' . $view->toUrl()); |
|
| 386 | + exit; |
|
| 387 | + } |
|
| 388 | + else |
|
| 389 | + { |
|
| 390 | + header('Location: ' . $view->baseUrl); |
|
| 391 | + exit; |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | - function isTokenFresh() |
|
| 396 | - { |
|
| 397 | - $db = new DatabaseConnect(); |
|
| 398 | - $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
| 395 | + function isTokenFresh() |
|
| 396 | + { |
|
| 397 | + $db = new DatabaseConnect(); |
|
| 398 | + $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
| 399 | 399 | |
| 400 | - if ($result->num_rows > 0) |
|
| 401 | - { |
|
| 402 | - // output data of each row |
|
| 403 | - while($row = $result->fetch_assoc()) |
|
| 404 | - { |
|
| 405 | - $expiration_date = $row["expiration_date"]; |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - else |
|
| 409 | - { |
|
| 410 | - error_log('0 results'); |
|
| 411 | - } |
|
| 400 | + if ($result->num_rows > 0) |
|
| 401 | + { |
|
| 402 | + // output data of each row |
|
| 403 | + while($row = $result->fetch_assoc()) |
|
| 404 | + { |
|
| 405 | + $expiration_date = $row["expiration_date"]; |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + else |
|
| 409 | + { |
|
| 410 | + error_log('0 results'); |
|
| 411 | + } |
|
| 412 | 412 | |
| 413 | - if($expiration_date <= time()) |
|
| 414 | - { |
|
| 415 | - return FALSE; |
|
| 416 | - } |
|
| 413 | + if($expiration_date <= time()) |
|
| 414 | + { |
|
| 415 | + return FALSE; |
|
| 416 | + } |
|
| 417 | 417 | |
| 418 | - return TRUE; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - function refreshToken() |
|
| 422 | - { |
|
| 423 | - $accountCreator = new CreateUser(); |
|
| 424 | - $accountCreator->setAccessToken($this->accessToken); |
|
| 425 | - $accountCreator->setDeviceUid($this->deviceUid); |
|
| 426 | - $accountCreator->setLocation($this->location); |
|
| 427 | - $data = $accountCreator->execute(); |
|
| 428 | - |
|
| 429 | - $access_token = (string)$data[0]['access_token']; |
|
| 430 | - $expiration_date = $data[0]['expiration_date']; |
|
| 431 | - $device_uid = (string)$data[1]; |
|
| 418 | + return TRUE; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + function refreshToken() |
|
| 422 | + { |
|
| 423 | + $accountCreator = new CreateUser(); |
|
| 424 | + $accountCreator->setAccessToken($this->accessToken); |
|
| 425 | + $accountCreator->setDeviceUid($this->deviceUid); |
|
| 426 | + $accountCreator->setLocation($this->location); |
|
| 427 | + $data = $accountCreator->execute(); |
|
| 428 | + |
|
| 429 | + $access_token = (string)$data[0]['access_token']; |
|
| 430 | + $expiration_date = $data[0]['expiration_date']; |
|
| 431 | + $device_uid = (string)$data[1]; |
|
| 432 | 432 | |
| 433 | - $db = new DatabaseConnect(); |
|
| 434 | - $result = $db->query("UPDATE accounts |
|
| 433 | + $db = new DatabaseConnect(); |
|
| 434 | + $result = $db->query("UPDATE accounts |
|
| 435 | 435 | SET access_token='" . $access_token . "', |
| 436 | 436 | expiration_date='" . $expiration_date . "' |
| 437 | 437 | WHERE device_uid='" . $device_uid . "'"); |
| 438 | 438 | |
| 439 | - if($result === false){ |
|
| 440 | - error_log("Adding account failed: (" . $db->errno . ") " . $db->error); |
|
| 441 | - } |
|
| 442 | - } |
|
| 439 | + if($result === false){ |
|
| 440 | + error_log("Adding account failed: (" . $db->errno . ") " . $db->error); |
|
| 441 | + } |
|
| 442 | + } |
|
| 443 | 443 | |
| 444 | 444 | |
| 445 | 445 | |
| 446 | - function getAccessToken() |
|
| 447 | - { |
|
| 448 | - $db = new DatabaseConnect(); |
|
| 449 | - $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
| 446 | + function getAccessToken() |
|
| 447 | + { |
|
| 448 | + $db = new DatabaseConnect(); |
|
| 449 | + $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
|
| 450 | 450 | |
| 451 | - $accessToken; |
|
| 451 | + $accessToken; |
|
| 452 | 452 | |
| 453 | - if ($result->num_rows > 0) |
|
| 454 | - { |
|
| 455 | - // output data of each row |
|
| 456 | - while($row = $result->fetch_assoc()) |
|
| 457 | - { |
|
| 458 | - $accessToken = $row['access_token']; |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - else |
|
| 462 | - { |
|
| 463 | - error_log('Error: 0 results'); |
|
| 464 | - } |
|
| 453 | + if ($result->num_rows > 0) |
|
| 454 | + { |
|
| 455 | + // output data of each row |
|
| 456 | + while($row = $result->fetch_assoc()) |
|
| 457 | + { |
|
| 458 | + $accessToken = $row['access_token']; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + else |
|
| 462 | + { |
|
| 463 | + error_log('Error: 0 results'); |
|
| 464 | + } |
|
| 465 | 465 | |
| 466 | - return $accessToken; |
|
| 467 | - } |
|
| 466 | + return $accessToken; |
|
| 467 | + } |
|
| 468 | 468 | |
| 469 | 469 | |
| 470 | - function getKarma() |
|
| 471 | - { |
|
| 472 | - $accountCreator = new GetKarma(); |
|
| 473 | - $accountCreator->setAccessToken($this->accessToken); |
|
| 474 | - $data = $accountCreator->execute(); |
|
| 470 | + function getKarma() |
|
| 471 | + { |
|
| 472 | + $accountCreator = new GetKarma(); |
|
| 473 | + $accountCreator->setAccessToken($this->accessToken); |
|
| 474 | + $data = $accountCreator->execute(); |
|
| 475 | 475 | |
| 476 | - return $data['karma']; |
|
| 477 | - } |
|
| 476 | + return $data['karma']; |
|
| 477 | + } |
|
| 478 | 478 | |
| 479 | - function hasVoted($postId) |
|
| 480 | - { |
|
| 481 | - $db = new DatabaseConnect(); |
|
| 479 | + function hasVoted($postId) |
|
| 480 | + { |
|
| 481 | + $db = new DatabaseConnect(); |
|
| 482 | 482 | |
| 483 | - $postId = $db->real_escape_string($postId); |
|
| 483 | + $postId = $db->real_escape_string($postId); |
|
| 484 | 484 | |
| 485 | - $result = $db->query("SELECT id FROM votes WHERE (postId = '" . $postId . "' AND device_uid = '" . $this->deviceUid . "')"); |
|
| 485 | + $result = $db->query("SELECT id FROM votes WHERE (postId = '" . $postId . "' AND device_uid = '" . $this->deviceUid . "')"); |
|
| 486 | 486 | |
| 487 | - if($result === false) |
|
| 488 | - { |
|
| 489 | - $error = db_error(); |
|
| 490 | - echo $error; |
|
| 491 | - error_log("Adding Vote failed: (" . $result->errno . ") " . $result->error); |
|
| 492 | - } |
|
| 487 | + if($result === false) |
|
| 488 | + { |
|
| 489 | + $error = db_error(); |
|
| 490 | + echo $error; |
|
| 491 | + error_log("Adding Vote failed: (" . $result->errno . ") " . $result->error); |
|
| 492 | + } |
|
| 493 | 493 | |
| 494 | - if($result->num_rows == 0) |
|
| 495 | - { |
|
| 496 | - return FALSE; |
|
| 497 | - } |
|
| 498 | - else |
|
| 499 | - { |
|
| 500 | - return TRUE; |
|
| 501 | - } |
|
| 502 | - } |
|
| 494 | + if($result->num_rows == 0) |
|
| 495 | + { |
|
| 496 | + return FALSE; |
|
| 497 | + } |
|
| 498 | + else |
|
| 499 | + { |
|
| 500 | + return TRUE; |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | 503 | |
| 504 | - function addVoteWithPostIdAndType($postId, $voteType) |
|
| 505 | - { |
|
| 506 | - $db = new DatabaseConnect(); |
|
| 504 | + function addVoteWithPostIdAndType($postId, $voteType) |
|
| 505 | + { |
|
| 506 | + $db = new DatabaseConnect(); |
|
| 507 | 507 | |
| 508 | - $postId = $db->real_escape_string($postId); |
|
| 509 | - $voteType = $db->real_escape_string($voteType); |
|
| 508 | + $postId = $db->real_escape_string($postId); |
|
| 509 | + $voteType = $db->real_escape_string($voteType); |
|
| 510 | 510 | |
| 511 | - if($this->hasVoted($postId)) |
|
| 512 | - { |
|
| 513 | - return "Already voted"; |
|
| 514 | - } |
|
| 511 | + if($this->hasVoted($postId)) |
|
| 512 | + { |
|
| 513 | + return "Already voted"; |
|
| 514 | + } |
|
| 515 | 515 | |
| 516 | - $result = $db->query("INSERT INTO votes (device_uid, postId, type) |
|
| 516 | + $result = $db->query("INSERT INTO votes (device_uid, postId, type) |
|
| 517 | 517 | VALUES ('" . $this->deviceUid . "','" . $postId . "','" . $voteType . "')"); |
| 518 | 518 | |
| 519 | - if($result === false){ |
|
| 520 | - $error = db_error(); |
|
| 521 | - echo $error; |
|
| 522 | - echo "Adding Vote failed: (" . $result->errno . ") " . $result->error; |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - function registerAccount($location) { |
|
| 527 | - $accountCreator = new CreateUser(); |
|
| 528 | - $accountCreator->setLocation($location); |
|
| 529 | - $data = $accountCreator->execute(); |
|
| 519 | + if($result === false){ |
|
| 520 | + $error = db_error(); |
|
| 521 | + echo $error; |
|
| 522 | + echo "Adding Vote failed: (" . $result->errno . ") " . $result->error; |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + function registerAccount($location) { |
|
| 527 | + $accountCreator = new CreateUser(); |
|
| 528 | + $accountCreator->setLocation($location); |
|
| 529 | + $data = $accountCreator->execute(); |
|
| 530 | 530 | |
| 531 | - $access_token = (string)$data[0]['access_token']; |
|
| 532 | - $refresh_token = (string)$data[0]['refresh_token']; |
|
| 533 | - $token_type = (string)$data[0]['token_type']; |
|
| 534 | - $expires_in = $data[0]['expires_in']; |
|
| 535 | - $expiration_date = $data[0]['expiration_date']; |
|
| 536 | - $distinct_id = (string)$data[0]['distinct_id']; |
|
| 537 | - $device_uid = (string)$data[1]; |
|
| 538 | - |
|
| 539 | - $name = $location->cityName; |
|
| 540 | - $lat = $location->lat; |
|
| 541 | - $lng = $location->lng; |
|
| 531 | + $access_token = (string)$data[0]['access_token']; |
|
| 532 | + $refresh_token = (string)$data[0]['refresh_token']; |
|
| 533 | + $token_type = (string)$data[0]['token_type']; |
|
| 534 | + $expires_in = $data[0]['expires_in']; |
|
| 535 | + $expiration_date = $data[0]['expiration_date']; |
|
| 536 | + $distinct_id = (string)$data[0]['distinct_id']; |
|
| 537 | + $device_uid = (string)$data[1]; |
|
| 538 | + |
|
| 539 | + $name = $location->cityName; |
|
| 540 | + $lat = $location->lat; |
|
| 541 | + $lng = $location->lng; |
|
| 542 | 542 | |
| 543 | - $db = new DatabaseConnect(); |
|
| 544 | - $result = $db->query("INSERT INTO accounts (access_token, refresh_token, token_type, |
|
| 543 | + $db = new DatabaseConnect(); |
|
| 544 | + $result = $db->query("INSERT INTO accounts (access_token, refresh_token, token_type, |
|
| 545 | 545 | expires_in, expiration_date, distinct_id, device_uid, name, lat, lng) |
| 546 | 546 | VALUES ('" . $access_token . "','" . $refresh_token . "','" . $token_type . |
| 547 | - "','" . $expires_in . "','" . $expiration_date . "','" . $distinct_id . |
|
| 548 | - "','" . $device_uid . "','" . $name . "','" . $lat . "','" . $lng . "') "); |
|
| 549 | - |
|
| 550 | - $success = TRUE; |
|
| 551 | - if($result === false){ |
|
| 552 | - $error = $db->error(); |
|
| 553 | - echo $error; |
|
| 554 | - echo "Adding account failed: (" . $result->errno . ") " . $result->error; |
|
| 555 | - $success = FALSE; |
|
| 556 | - } |
|
| 547 | + "','" . $expires_in . "','" . $expiration_date . "','" . $distinct_id . |
|
| 548 | + "','" . $device_uid . "','" . $name . "','" . $lat . "','" . $lng . "') "); |
|
| 549 | + |
|
| 550 | + $success = TRUE; |
|
| 551 | + if($result === false){ |
|
| 552 | + $error = $db->error(); |
|
| 553 | + echo $error; |
|
| 554 | + echo "Adding account failed: (" . $result->errno . ") " . $result->error; |
|
| 555 | + $success = FALSE; |
|
| 556 | + } |
|
| 557 | 557 | |
| 558 | - return $device_uid; |
|
| 559 | - } |
|
| 558 | + return $device_uid; |
|
| 559 | + } |
|
| 560 | 560 | |
| 561 | - function createAccount() |
|
| 562 | - { |
|
| 563 | - $config = parse_ini_file('config/config.ini.php'); |
|
| 564 | - $location = new Location(); |
|
| 565 | - $location->setLat($config['default_lat']); |
|
| 566 | - $location->setLng($config['default_lng']); |
|
| 567 | - $location->setCityName($config['default_location']); |
|
| 561 | + function createAccount() |
|
| 562 | + { |
|
| 563 | + $config = parse_ini_file('config/config.ini.php'); |
|
| 564 | + $location = new Location(); |
|
| 565 | + $location->setLat($config['default_lat']); |
|
| 566 | + $location->setLng($config['default_lng']); |
|
| 567 | + $location->setCityName($config['default_location']); |
|
| 568 | 568 | |
| 569 | - $deviceUid = $this->registerAccount($location); |
|
| 569 | + $deviceUid = $this->registerAccount($location); |
|
| 570 | 570 | |
| 571 | - return $deviceUid; |
|
| 572 | - } |
|
| 571 | + return $deviceUid; |
|
| 572 | + } |
|
| 573 | 573 | } |
| 574 | 574 | \ No newline at end of file |