@@ -36,7 +36,7 @@ |
||
| 36 | 36 | returnError($e); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | -} catch(Exception $e) { |
|
| 39 | +} catch (Exception $e) { |
|
| 40 | 40 | returnForbidden($e); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | $stmt = $calorie->readByDay(); |
| 33 | 33 | $num = $stmt->rowCount(); |
| 34 | 34 | |
| 35 | - if($num>0){ |
|
| 35 | + if ($num>0) { |
|
| 36 | 36 | |
| 37 | - $calories_arr=array(); |
|
| 38 | - while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ |
|
| 37 | + $calories_arr = array(); |
|
| 38 | + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { |
|
| 39 | 39 | |
| 40 | 40 | extract($row); |
| 41 | 41 | $calorie_item = array( |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | returnNoData(); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | -} catch(Exception $e) { |
|
| 56 | +} catch (Exception $e) { |
|
| 57 | 57 | returnForbidden($e); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -31,12 +31,12 @@ discard block |
||
| 31 | 31 | $stmt = $calorie->readDays(); |
| 32 | 32 | $num = $stmt->rowCount(); |
| 33 | 33 | |
| 34 | - if($num>0){ |
|
| 34 | + if ($num>0) { |
|
| 35 | 35 | |
| 36 | 36 | $i = 1; |
| 37 | - $val_arr=array(); |
|
| 37 | + $val_arr = array(); |
|
| 38 | 38 | |
| 39 | - while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ |
|
| 39 | + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { |
|
| 40 | 40 | extract($row); |
| 41 | 41 | $val_item = array( |
| 42 | 42 | "date" => $date, |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | returnNoData(); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | -} catch(Exception $e) { |
|
| 54 | +} catch (Exception $e) { |
|
| 55 | 55 | returnForbidden($e); |
| 56 | 56 | } |
| 57 | 57 | |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | header("Access-Control-Max-Age: 3600"); |
| 7 | 7 | header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"); |
| 8 | 8 | |
| 9 | -if($_SERVER['REQUEST_METHOD'] === "OPTIONS"){ |
|
| 9 | +if ($_SERVER['REQUEST_METHOD'] === "OPTIONS") { |
|
| 10 | 10 | die(); |
| 11 | 11 | } |
| 12 | 12 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | // Check if the nbf if it is defined. This is the time that the |
| 116 | 116 | // token can actually be used. If it's not yet that time, abort. |
| 117 | - if (isset($payload->nbf) && $payload->nbf > ($timestamp + static::$leeway)) { |
|
| 117 | + if (isset($payload->nbf) && $payload->nbf>($timestamp + static::$leeway)) { |
|
| 118 | 118 | throw new BeforeValidException( |
| 119 | 119 | 'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->nbf) |
| 120 | 120 | ); |
@@ -123,14 +123,14 @@ discard block |
||
| 123 | 123 | // Check that this token has been created before 'now'. This prevents |
| 124 | 124 | // using tokens that have been created for later use (and haven't |
| 125 | 125 | // correctly used the nbf claim). |
| 126 | - if (isset($payload->iat) && $payload->iat > ($timestamp + static::$leeway)) { |
|
| 126 | + if (isset($payload->iat) && $payload->iat>($timestamp + static::$leeway)) { |
|
| 127 | 127 | throw new BeforeValidException( |
| 128 | 128 | 'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->iat) |
| 129 | 129 | ); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // Check if this token has expired. |
| 133 | - if (isset($payload->exp) && ($timestamp - static::$leeway) >= $payload->exp) { |
|
| 133 | + if (isset($payload->exp) && ($timestamp - static::$leeway)>=$payload->exp) { |
|
| 134 | 134 | throw new ExpiredException('Expired token'); |
| 135 | 135 | } |
| 136 | 136 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | if ($keyId !== null) { |
| 160 | 160 | $header['kid'] = $keyId; |
| 161 | 161 | } |
| 162 | - if ( isset($head) && is_array($head) ) { |
|
| 162 | + if (isset($head) && is_array($head)) { |
|
| 163 | 163 | $header = array_merge($head, $header); |
| 164 | 164 | } |
| 165 | 165 | $segments = array(); |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | throw new DomainException('Algorithm not supported'); |
| 192 | 192 | } |
| 193 | 193 | list($function, $algorithm) = static::$supported_algs[$alg]; |
| 194 | - switch($function) { |
|
| 194 | + switch ($function) { |
|
| 195 | 195 | case 'hash_hmac': |
| 196 | 196 | return hash_hmac($algorithm, $msg, $key, true); |
| 197 | 197 | case 'openssl': |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | list($function, $algorithm) = static::$supported_algs[$alg]; |
| 228 | - switch($function) { |
|
| 228 | + switch ($function) { |
|
| 229 | 229 | case 'openssl': |
| 230 | 230 | $success = openssl_verify($msg, $signature, $key, $algorithm); |
| 231 | 231 | if ($success === 1) { |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | $len = min(static::safeStrlen($signature), static::safeStrlen($hash)); |
| 247 | 247 | |
| 248 | 248 | $status = 0; |
| 249 | - for ($i = 0; $i < $len; $i++) { |
|
| 249 | + for ($i = 0; $i<$len; $i++) { |
|
| 250 | 250 | $status |= (ord($signature[$i]) ^ ord($hash[$i])); |
| 251 | 251 | } |
| 252 | 252 | $status |= (static::safeStrlen($signature) ^ static::safeStrlen($hash)); |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | public static function jsonDecode($input) |
| 268 | 268 | { |
| 269 | - if (version_compare(PHP_VERSION, '5.4.0', '>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) { |
|
| 269 | + if (version_compare(PHP_VERSION, '5.4.0', '>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE>4)) { |
|
| 270 | 270 | /** In PHP >=5.4.0, json_decode() accepts an options parameter, that allows you |
| 271 | 271 | * to specify that large ints (like Steam Transaction IDs) should be treated as |
| 272 | 272 | * strings, rather than the PHP default behaviour of converting them to floats. |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | *them to strings) before decoding, hence the preg_replace() call. |
| 279 | 279 | */ |
| 280 | 280 | $max_int_length = strlen((string) PHP_INT_MAX) - 1; |
| 281 | - $json_without_bigints = preg_replace('/:\s*(-?\d{'.$max_int_length.',})/', ': "$1"', $input); |
|
| 281 | + $json_without_bigints = preg_replace('/:\s*(-?\d{' . $max_int_length . ',})/', ': "$1"', $input); |
|
| 282 | 282 | $obj = json_decode($json_without_bigints); |
| 283 | 283 | } |
| 284 | 284 | |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | */ |
| 320 | 320 | public static function urlsafeB64Decode($input) |
| 321 | 321 | { |
| 322 | - $remainder = strlen($input) % 4; |
|
| 322 | + $remainder = strlen($input)%4; |
|
| 323 | 323 | if ($remainder) { |
| 324 | 324 | $padlen = 4 - $remainder; |
| 325 | 325 | $input .= str_repeat('=', $padlen); |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | "expireAt" => time() + (604800), |
| 15 | 15 | ); |
| 16 | 16 | |
| 17 | -function authenticate(){ |
|
| 17 | +function authenticate() { |
|
| 18 | 18 | if (isset(getallheaders()['Authorization'])) { |
| 19 | 19 | list($type, $data) = explode(" ", getallheaders()['Authorization'], 2); |
| 20 | 20 | if (strcasecmp($type, "Bearer") == 0) { |
@@ -27,9 +27,9 @@ discard block |
||
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | -function returnSuccess($data = false){ |
|
| 30 | +function returnSuccess($data = false) { |
|
| 31 | 31 | http_response_code(200); |
| 32 | - if($data){ |
|
| 32 | + if ($data) { |
|
| 33 | 33 | echo json_encode(array( |
| 34 | 34 | "status" => "success", |
| 35 | 35 | "message" => "Request successfully handled", |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | die(); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | -function returnNoData(){ |
|
| 47 | +function returnNoData() { |
|
| 48 | 48 | http_response_code(204); |
| 49 | 49 | echo json_encode(array( |
| 50 | 50 | "status" => "success", |
@@ -53,9 +53,9 @@ discard block |
||
| 53 | 53 | die(); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | -function returnForbidden($reason = false){ |
|
| 56 | +function returnForbidden($reason = false) { |
|
| 57 | 57 | http_response_code(403); |
| 58 | - if($reason){ |
|
| 58 | + if ($reason) { |
|
| 59 | 59 | echo json_encode(array( |
| 60 | 60 | "status" => "unauthorized", |
| 61 | 61 | "message" => "User is not authorized to perform this action", |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | die(); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | -function returnBadRequest($reason = false){ |
|
| 73 | +function returnBadRequest($reason = false) { |
|
| 74 | 74 | http_response_code(400); |
| 75 | - if($reason){ |
|
| 75 | + if ($reason) { |
|
| 76 | 76 | echo json_encode(array( |
| 77 | 77 | "status" => "failed", |
| 78 | 78 | "message" => "Bad Request: Values are wrong or missing.", |
@@ -87,9 +87,9 @@ discard block |
||
| 87 | 87 | die(); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | -function returnError($reason = false){ |
|
| 90 | +function returnError($reason = false) { |
|
| 91 | 91 | http_response_code(500); |
| 92 | - if($reason){ |
|
| 92 | + if ($reason) { |
|
| 93 | 93 | echo json_encode(array( |
| 94 | 94 | "status" => "error", |
| 95 | 95 | "message" => "An internal error occured", |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | private $password = ""; |
| 10 | 10 | |
| 11 | 11 | public $conn; |
| 12 | - public function connect(){ |
|
| 12 | + public function connect() { |
|
| 13 | 13 | |
| 14 | 14 | $this->conn = null; |
| 15 | 15 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | $this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password); |
| 19 | 19 | |
| 20 | - } catch(PDOException $exception) { |
|
| 20 | + } catch (PDOException $exception) { |
|
| 21 | 21 | |
| 22 | 22 | echo "Connection error: " . $exception->getMessage(); |
| 23 | 23 | |
@@ -27,11 +27,11 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | $decoded = JWT::decode($token, $token_conf['secret'], $token_conf['algorithm']); |
| 29 | 29 | |
| 30 | - if($_FILES['img']['type'] == 'image/png'){ |
|
| 30 | + if ($_FILES['img']['type'] == 'image/png') { |
|
| 31 | 31 | $source = imagecreatefrompng($_FILES['img']['tmp_name']); |
| 32 | - } else if($_FILES['img']['type'] == 'image/jpeg') { |
|
| 32 | + } else if ($_FILES['img']['type'] == 'image/jpeg') { |
|
| 33 | 33 | $source = imagecreatefromjpeg($_FILES['img']['tmp_name']); |
| 34 | - } else if($_FILES['img']['type'] == 'image/gif') { |
|
| 34 | + } else if ($_FILES['img']['type'] == 'image/gif') { |
|
| 35 | 35 | $source = imagecreatefromgif($_FILES['img']['tmp_name']); |
| 36 | 36 | } else { |
| 37 | 37 | returnBadRequest(); |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | list($width, $height) = getimagesize($_FILES['img']['tmp_name']); |
| 42 | - $imageName = "minska-U".$decoded->data->id."U-T".time()."T-R".rand(100,999)."R.jpg"; |
|
| 42 | + $imageName = "minska-U" . $decoded->data->id . "U-T" . time() . "T-R" . rand(100, 999) . "R.jpg"; |
|
| 43 | 43 | $imageWidth = 300; |
| 44 | 44 | $imageHeight = $height*($imageWidth/$width); |
| 45 | 45 | $imageQuality = 80; |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | $rendered = imagecreatetruecolor($imageWidth, $imageHeight); |
| 49 | 49 | imagecopyresampled($rendered, $source, 0, 0, 0, 0, $imageWidth, $imageHeight, $width, $height); |
| 50 | - imagejpeg($rendered, $uploaddir ."/".$imageName, $imageQuality); |
|
| 50 | + imagejpeg($rendered, $uploaddir . "/" . $imageName, $imageQuality); |
|
| 51 | 51 | |
| 52 | 52 | returnSuccess($imageName); |
| 53 | 53 | |
@@ -31,11 +31,11 @@ discard block |
||
| 31 | 31 | $stmt = $template->read(); |
| 32 | 32 | $num = $stmt->rowCount(); |
| 33 | 33 | |
| 34 | - if($num>0){ |
|
| 34 | + if ($num>0) { |
|
| 35 | 35 | |
| 36 | - $templates_arr=array(); |
|
| 36 | + $templates_arr = array(); |
|
| 37 | 37 | |
| 38 | - while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){ |
|
| 38 | + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { |
|
| 39 | 39 | extract($row); |
| 40 | 40 | $template_item = array( |
| 41 | 41 | "id" => $id, |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | returnNoData(); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | -} catch(Exception $e){ |
|
| 56 | +} catch (Exception $e) { |
|
| 57 | 57 | returnForbidden($e); |
| 58 | 58 | } |
| 59 | 59 | |