From 93c02436fb0b7afffb6c62547385757b1a1b57f8 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Tue, 29 Apr 2025 02:06:11 +0500 Subject: feat: download user's profile banner --- public/account/index.php | 24 +++++++++++++++++++++--- public/account/login/twitch.php | 19 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) (limited to 'public/account') diff --git a/public/account/index.php b/public/account/index.php index 2edb39a..a216eea 100644 --- a/public/account/index.php +++ b/public/account/index.php @@ -16,7 +16,7 @@ if (!isset($_SESSION["user_id"], $_SESSION["user_name"])) { if ($_SERVER['REQUEST_METHOD'] == "POST") { $db = new PDO(DB_URL, DB_USER, DB_PASS); - $username = str_safe($_POST["username"], ACCOUNT_USERNAME_MAX_LENGTH); + $username = str_safe($_POST["username"] ?? "", ACCOUNT_USERNAME_MAX_LENGTH); if (!empty($username) && $username != $_SESSION["user_name"]) { if (!preg_match(ACCOUNT_USERNAME_REGEX, $username)) { @@ -43,7 +43,20 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { "../static/userdata/avatars/" . $_SESSION["user_id"], ACCOUNT_PFP_MAX_SIZE[0], ACCOUNT_PFP_MAX_SIZE[1], - false + false, + true + ); + } + + if (isset($_FILES["banner"])) { + $banner = $_FILES["banner"]; + resize_image( + $banner["tmp_name"], + "../static/userdata/banners/" . $_SESSION["user_id"], + ACCOUNT_BANNER_MAX_SIZE[0], + ACCOUNT_BANNER_MAX_SIZE[1], + false, + true ); } @@ -76,7 +89,12 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {

Profile picture

" id="pfp" width="64" height="64"> - + + +

Profile banner

+ " id="banner" width="192" + height="108"> +

Username

"> diff --git a/public/account/login/twitch.php b/public/account/login/twitch.php index ec10583..1c72bc3 100644 --- a/public/account/login/twitch.php +++ b/public/account/login/twitch.php @@ -139,4 +139,23 @@ if (!is_file("$path/$user_id")) { fclose($fp); } +// downloading profile banner +$path = "../../static/userdata/banners"; + +if (!is_dir($path)) { + mkdir($path, 0777, true); +} + +if (!is_file("$path/$user_id")) { + $fp = fopen("$path/$user_id", "wb"); + $request = curl_init(); + curl_setopt($request, CURLOPT_URL, $twitch_user["offline_image_url"]); + curl_setopt($request, CURLOPT_FILE, $fp); + curl_setopt($request, CURLOPT_HEADER, 0); + + curl_exec($request); + curl_close($request); + fclose($fp); +} + header("Location: /account"); \ No newline at end of file -- cgit v1.2.3