mirror of
https://github.com/Daichimarukana/uwuzu.git
synced 2026-06-05 03:24:41 +00:00
uwuzu v1.6.0 Hapuego
This commit is contained in:
+17
-27
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
$domain = $_SERVER['HTTP_HOST'];
|
||||
require('../../db.php');
|
||||
require("../../function/function.php");
|
||||
require(__DIR__ . '/../../db.php');
|
||||
require(__DIR__ . "/../../function/function.php");
|
||||
blockedIP($_SERVER['REMOTE_ADDR']);
|
||||
|
||||
header("Content-Type: application/json; charset=utf-8");
|
||||
@@ -35,6 +35,7 @@ if(isset($_GET['token']) || (!(empty($Get_Post_Json)))) {
|
||||
$err = "input_not_found";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
@@ -44,6 +45,7 @@ if(isset($_GET['token']) || (!(empty($Get_Post_Json)))) {
|
||||
$err = "input_not_found";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
@@ -52,31 +54,9 @@ if(isset($_GET['token']) || (!(empty($Get_Post_Json)))) {
|
||||
session_start();
|
||||
|
||||
if( !empty($pdo) ) {
|
||||
$userQuery = $pdo->prepare("SELECT username, userid, role FROM account WHERE token = :token");
|
||||
$userQuery->bindValue(':token', $token);
|
||||
$userQuery->execute();
|
||||
$userData = $userQuery->fetch();
|
||||
|
||||
if(empty($userData["userid"])){
|
||||
$err = "token_invalid";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
);
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}elseif($userData["role"] === "ice"){
|
||||
$err = "this_account_has_been_frozen";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
);
|
||||
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}else{
|
||||
$DataQuery = $pdo->prepare("SELECT username,userid,profile,datetime,follow,follower,iconname,headname,role,sacinfo,admin FROM account WHERE userid = :userid");
|
||||
$DataQuery->bindValue(':userid', $userData["userid"]);
|
||||
$DataQuery->execute();
|
||||
$userdata = $DataQuery->fetch();
|
||||
$AuthData = APIAuth($pdo, $token, "read:me");
|
||||
if($AuthData[0] === true){
|
||||
$userdata = $AuthData[2];
|
||||
|
||||
if (empty($userdata)){
|
||||
$response = array(
|
||||
@@ -158,6 +138,7 @@ if(isset($_GET['token']) || (!(empty($Get_Post_Json)))) {
|
||||
$All_ueuse = $allueuse->rowCount();
|
||||
|
||||
$response = array(
|
||||
'success' => true,
|
||||
'username' => decode_yajirushi(htmlspecialchars_decode($userdata["username"])),
|
||||
'userid' => decode_yajirushi(htmlspecialchars_decode($userdata["userid"])),
|
||||
'profile' => decode_yajirushi(htmlspecialchars_decode($userdata["profile"])),
|
||||
@@ -175,6 +156,14 @@ if(isset($_GET['token']) || (!(empty($Get_Post_Json)))) {
|
||||
'language' => "ja-JP",
|
||||
);
|
||||
}
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
}else{
|
||||
$err = $AuthData[1];
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
}
|
||||
@@ -182,6 +171,7 @@ if(isset($_GET['token']) || (!(empty($Get_Post_Json)))) {
|
||||
$err = "input_not_found";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
$domain = $_SERVER['HTTP_HOST'];
|
||||
require(__DIR__ . '/../../../db.php');
|
||||
require(__DIR__ . "/../../../function/function.php");
|
||||
$serversettings_file = __DIR__ . "/../../../server/serversettings.ini";
|
||||
$serversettings = parse_ini_file($serversettings_file, true);
|
||||
blockedIP($_SERVER['REMOTE_ADDR']);
|
||||
|
||||
header("Content-Type: application/json; charset=utf-8");
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
|
||||
|
||||
$pdo = null;
|
||||
try {
|
||||
$option = array(
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::MYSQL_ATTR_MULTI_STATEMENTS => false
|
||||
);
|
||||
$pdo = new PDO('mysql:charset=utf8mb4;dbname='.DB_NAME.';host='.DB_HOST , DB_USER, DB_PASS, $option);
|
||||
} catch(PDOException $e) {
|
||||
// 接続エラーのときエラー内容を取得する
|
||||
$error_message[] = $e->getMessage();
|
||||
}
|
||||
|
||||
$Get_Post_Json = file_get_contents("php://input");
|
||||
if(isset($_GET['token']) || (!(empty($Get_Post_Json)))) {
|
||||
//トークン取得
|
||||
if(!(empty($_GET['token']))){
|
||||
$token = safetext($_GET['token']);
|
||||
}else{
|
||||
$post_json = json_decode($Get_Post_Json, true);
|
||||
if(isset($post_json["token"])){
|
||||
$token = safetext($post_json["token"]);
|
||||
}else{
|
||||
$err = "input_not_found";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
if($token == ""){
|
||||
$err = "input_not_found";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
if(!(empty($_GET['limit']))){
|
||||
$limit = (int)$_GET['limit'];
|
||||
}elseif(!(empty($post_json["limit"]))){
|
||||
$limit = (int)$post_json["limit"];
|
||||
}else{
|
||||
$limit = 25;
|
||||
}
|
||||
if($limit > 100){
|
||||
$limit = 100;
|
||||
}
|
||||
|
||||
if(!(empty($_GET['page']))){
|
||||
$page = (int)$_GET['page'];
|
||||
}elseif(!(empty($post_json["page"]))){
|
||||
$page = (int)$post_json["page"];
|
||||
}else{
|
||||
$page = 1;
|
||||
}
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
session_start();
|
||||
|
||||
if( !empty($pdo) ) {
|
||||
$AuthData = APIAuth($pdo, $token, "read:notifications");
|
||||
if($AuthData[0] === true){
|
||||
$userData = $AuthData[2];
|
||||
|
||||
$messageQuery = $pdo->prepare("SELECT fromuserid,title,msg,url,datetime,userchk,category FROM notification WHERE touserid = :userid ORDER BY datetime DESC LIMIT :offset, :itemsPerPage");
|
||||
$messageQuery->bindValue(':userid', $userData["userid"], PDO::PARAM_STR);
|
||||
$messageQuery->bindValue(':offset', $offset, PDO::PARAM_INT);
|
||||
$messageQuery->bindValue(':itemsPerPage', $limit, PDO::PARAM_INT);
|
||||
$messageQuery->execute();
|
||||
|
||||
// トランザクション開始
|
||||
$pdo->beginTransaction();
|
||||
|
||||
while ($row = $messageQuery->fetch(PDO::FETCH_ASSOC)) {
|
||||
$messages[] = $row;
|
||||
}
|
||||
|
||||
if (!empty($messages)) {
|
||||
$response = array(
|
||||
'success' => true,
|
||||
); // ループ外で $response を初期化
|
||||
|
||||
foreach ($messages as $notificationdata) {
|
||||
$userQuery = $pdo->prepare("SELECT username, userid, iconname, headname, role FROM account WHERE userid = :userid");
|
||||
$userQuery->bindValue(':userid', $notificationdata["fromuserid"]);
|
||||
$userQuery->execute();
|
||||
$userData = $userQuery->fetch();
|
||||
|
||||
if ($userData) {
|
||||
$now_userdata = array(
|
||||
"username" => decode_yajirushi(htmlspecialchars_decode($userData['username'])),
|
||||
"userid" => decode_yajirushi(htmlspecialchars_decode($userData['userid'])),
|
||||
"user_icon" => decode_yajirushi(htmlspecialchars_decode(localcloudURLtoAPI(localcloudURL($userData['iconname'])))),
|
||||
"user_header" => decode_yajirushi(htmlspecialchars_decode(localcloudURLtoAPI(localcloudURL($userData['headname'])))),
|
||||
);
|
||||
}else if($notificationdata["fromuserid"] === "uwuzu-fromsys"){
|
||||
$now_userdata = array(
|
||||
"username" => decode_yajirushi(htmlspecialchars_decode($serversettings["serverinfo"]["server_name"])),
|
||||
"userid" => "uwuzu-fromsys",
|
||||
"user_icon" => decode_yajirushi(htmlspecialchars_decode(localcloudURLtoAPI(localcloudURL($serversettings["serverinfo"]["server_icon"])))),
|
||||
"user_header" => decode_yajirushi(htmlspecialchars_decode(localcloudURLtoAPI(localcloudURL($serversettings["serverinfo"]["server_head"])))),
|
||||
);
|
||||
}else{
|
||||
$now_userdata = array();
|
||||
}
|
||||
|
||||
if($notificationdata["userchk"] === "done"){
|
||||
$userchk = true;
|
||||
}else{
|
||||
$userchk = false;
|
||||
}
|
||||
|
||||
$item = [
|
||||
'from' => $now_userdata,
|
||||
'category' => decode_yajirushi(htmlspecialchars_decode($notificationdata["category"])),
|
||||
'title' => decode_yajirushi(htmlspecialchars_decode($notificationdata["title"])),
|
||||
'text' => decode_yajirushi(htmlspecialchars_decode($notificationdata["msg"])),
|
||||
'datetime' => decode_yajirushi(htmlspecialchars_decode($notificationdata["datetime"])),
|
||||
'is_checked' => $userchk,
|
||||
];
|
||||
|
||||
$response[] = $item; // ループ内で $response にデータを追加
|
||||
}
|
||||
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
$err = "notification_not_found";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
}else{
|
||||
$err = $AuthData[1];
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$err = "input_not_found";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
$domain = $_SERVER['HTTP_HOST'];
|
||||
require(__DIR__ . '/../../../db.php');
|
||||
require(__DIR__ . "/../../../function/function.php");
|
||||
blockedIP($_SERVER['REMOTE_ADDR']);
|
||||
|
||||
header("Content-Type: application/json; charset=utf-8");
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
|
||||
|
||||
$pdo = null;
|
||||
try {
|
||||
$option = array(
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::MYSQL_ATTR_MULTI_STATEMENTS => false
|
||||
);
|
||||
$pdo = new PDO('mysql:charset=utf8mb4;dbname=' . DB_NAME . ';host=' . DB_HOST, DB_USER, DB_PASS, $option);
|
||||
} catch (PDOException $e) {
|
||||
// 接続エラーのときエラー内容を取得する
|
||||
$error_message[] = $e->getMessage();
|
||||
}
|
||||
|
||||
$Get_Post_Json = file_get_contents("php://input");
|
||||
if (isset($_GET['token']) || (!(empty($Get_Post_Json)))) {
|
||||
//トークン取得
|
||||
if (!(empty($_GET['token']))) {
|
||||
$token = safetext($_GET['token']);
|
||||
} else {
|
||||
$post_json = json_decode($Get_Post_Json, true);
|
||||
if (isset($post_json["token"])) {
|
||||
$token = safetext($post_json["token"]);
|
||||
} else {
|
||||
$err = "input_not_found";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
if ($token == "") {
|
||||
$err = "input_not_found";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!(empty($_GET['limit']))) {
|
||||
$limit = (int)$_GET['limit'];
|
||||
} elseif (!(empty($post_json["limit"]))) {
|
||||
$limit = (int)$post_json["limit"];
|
||||
} else {
|
||||
$limit = 25;
|
||||
}
|
||||
if ($limit > 100) {
|
||||
$limit = 100;
|
||||
}
|
||||
|
||||
if (!(empty($_GET['page']))) {
|
||||
$page = (int)$_GET['page'];
|
||||
} elseif (!(empty($post_json["page"]))) {
|
||||
$page = (int)$post_json["page"];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
session_start();
|
||||
|
||||
if (!empty($pdo)) {
|
||||
$AuthData = APIAuth($pdo, $token, "write:notifications");
|
||||
if ($AuthData[0] === true) {
|
||||
$userData = $AuthData[2];
|
||||
|
||||
$pdo->beginTransaction();
|
||||
try {
|
||||
$stmt = $pdo->prepare("UPDATE notification SET userchk = 'done' WHERE touserid = :userid;");
|
||||
$stmt->bindValue(':userid', $userData["userid"], PDO::PARAM_STR);
|
||||
$res = $stmt->execute();
|
||||
if ($res) {
|
||||
$pdo->commit();
|
||||
$response = array(
|
||||
'success' => true
|
||||
);
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
$pdo->rollBack();
|
||||
$err = "update_failed";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
// 接続エラーのときエラー内容を取得する
|
||||
$error_message[] = $e->getMessage();
|
||||
}
|
||||
} else {
|
||||
$err = $AuthData[1];
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$err = "input_not_found";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
@@ -0,0 +1,443 @@
|
||||
<?php
|
||||
|
||||
$domain = $_SERVER['HTTP_HOST'];
|
||||
require(__DIR__ . '/../../../db.php');
|
||||
require(__DIR__ . "/../../../function/function.php");
|
||||
blockedIP($_SERVER['REMOTE_ADDR']);
|
||||
|
||||
header("Content-Type: application/json; charset=utf-8");
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
|
||||
$pdo = null;
|
||||
$error_message = array();
|
||||
try {
|
||||
$option = array(
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::MYSQL_ATTR_MULTI_STATEMENTS => false
|
||||
);
|
||||
$pdo = new PDO('mysql:charset=utf8mb4;dbname=' . DB_NAME . ';host=' . DB_HOST, DB_USER, DB_PASS, $option);
|
||||
} catch (PDOException $e) {
|
||||
// 接続エラーのときエラー内容を取得する
|
||||
$error_message[] = $e->getMessage();
|
||||
}
|
||||
|
||||
$Get_Post_Json = file_get_contents("php://input");
|
||||
if (isset($_GET['token']) || (!(empty($Get_Post_Json)))) {
|
||||
//トークン取得
|
||||
if (!(empty($_GET['token']))) {
|
||||
$token = safetext($_GET['token']);
|
||||
} else {
|
||||
$post_json = json_decode($Get_Post_Json, true);
|
||||
if (isset($post_json["token"])) {
|
||||
$token = safetext($post_json["token"]);
|
||||
} else {
|
||||
$err = "input_not_found";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
if ($token == "") {
|
||||
$err = "input_not_found";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!empty($pdo)) {
|
||||
$AuthData = APIAuth($pdo, $token, "write:me");
|
||||
if ($AuthData[0] === true) {
|
||||
if(file_exists(__DIR__ . "/../../../settings_admin/plugin_settings/amazons3_settings.php")){
|
||||
require_once __DIR__ . '/../../../settings_admin/plugin_settings/amazons3_settings.php';
|
||||
if(AMS3_CHKS == "true"){
|
||||
if(file_exists(__DIR__ . "/../../../plugin/aws/aws-autoloader.php")){
|
||||
require_once __DIR__ . '/../../../plugin/aws/aws-autoloader.php';
|
||||
}else{
|
||||
actionLog(null, "error", "settings", null, "AWS SDK for PHPが見つかりませんでした!", 4);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
actionLog(null, "error", "settings", null, "amazons3_settings.phpが見つかりませんでした!", 3);
|
||||
}
|
||||
|
||||
$userData = $AuthData[2];
|
||||
$userid = $userData["userid"];
|
||||
|
||||
$add_sql = array();
|
||||
|
||||
if (!(empty($_GET['username']))) {
|
||||
$username = safetext($_GET['username']);
|
||||
} elseif (!(empty($post_json["username"]))) {
|
||||
$username = safetext($post_json["username"]);
|
||||
} else {
|
||||
$username = null;
|
||||
}
|
||||
|
||||
// ユーザーネームの入力チェック
|
||||
if (!($username === null)) {
|
||||
if (empty($username)) {
|
||||
$error_message[] = '表示名を入力してください。(USERNAME_INPUT_PLEASE)';
|
||||
} else {
|
||||
// 文字数を確認
|
||||
if (50 < mb_strlen($username, 'UTF-8')) {
|
||||
$error_message[] = 'ユーザーネームは50文字以内で入力してください。(USERNAME_OVER_MAX_COUNT)';
|
||||
}
|
||||
}
|
||||
|
||||
$add_sql[] = "username = :username";
|
||||
}
|
||||
|
||||
|
||||
if (!(empty($_GET['profile']))) {
|
||||
$profile = safetext($_GET['profile']);
|
||||
} elseif (!(empty($post_json["profile"]))) {
|
||||
$profile = safetext($post_json["profile"]);
|
||||
} else {
|
||||
$profile = null;
|
||||
}
|
||||
|
||||
if (!($profile === null)) {
|
||||
if (1024 < mb_strlen($profile, 'UTF-8')) {
|
||||
$error_message[] = 'プロフィールは1024文字以内で入力してください。(INPUT_OVER_MAX_COUNT)';
|
||||
}
|
||||
$add_sql[] = "profile = :profile";
|
||||
}
|
||||
|
||||
|
||||
if (!(empty($post_json["icon"]))) {
|
||||
$imageData = base64_decode($post_json["icon"], true);
|
||||
|
||||
$tmpFilePath = tempnam(sys_get_temp_dir(), 'upload_' . createUniqId());
|
||||
file_put_contents($tmpFilePath, $imageData);
|
||||
|
||||
$IconFiles = [
|
||||
'name' => 'upload.png',
|
||||
'type' => check_mime($tmpFilePath),
|
||||
'tmp_name' => $tmpFilePath,
|
||||
'error' => UPLOAD_ERR_OK,
|
||||
'size' => strlen($imageData),
|
||||
];
|
||||
} else {
|
||||
$IconFiles = array();
|
||||
}
|
||||
|
||||
|
||||
if (isset($IconFiles)) {
|
||||
if (!(empty($IconFiles['name']))) {
|
||||
$uploadedFile = $IconFiles;
|
||||
if (check_mime($uploadedFile['tmp_name'])) {
|
||||
$extension = pathinfo($uploadedFile['name'], PATHINFO_EXTENSION);
|
||||
delete_exif($extension, $uploadedFile['tmp_name']);
|
||||
resizeImage($uploadedFile['tmp_name'], 512, 512);
|
||||
|
||||
if (AMS3_CHKS == "true") {
|
||||
$usericonurl = getUserData($pdo, $userid)["iconname"];
|
||||
if (filter_var($usericonurl, FILTER_VALIDATE_URL)) {
|
||||
$s3delresult = deleteAmazonS3($usericonurl);
|
||||
} else {
|
||||
$s3delresult = true;
|
||||
}
|
||||
if ($s3delresult == true) {
|
||||
$s3result = uploadAmazonS3($uploadedFile['tmp_name']);
|
||||
} else {
|
||||
$s3result = false;
|
||||
}
|
||||
} else {
|
||||
if (check_mime($uploadedFile['tmp_name']) == "image/webp") {
|
||||
$newFilename = createUniqId() . '-' . $userid . '.webp';
|
||||
} else {
|
||||
$newFilename = createUniqId() . '-' . $userid . '.' . $extension;
|
||||
}
|
||||
$uploadedPath = 'usericons/' . $newFilename;
|
||||
$result = rename($uploadedFile['tmp_name'], __DIR__ . '/../../../' . $uploadedPath);
|
||||
|
||||
if ($result) {
|
||||
$iconName = $uploadedPath; // 保存されたファイルのパスを使用
|
||||
$currentIconPath = getUserData($pdo, $userid)["iconname"];
|
||||
} else {
|
||||
$errnum = $uploadedFile['error'];
|
||||
$errcode = "ERROR";
|
||||
|
||||
switch ($errnum) {
|
||||
case 1:
|
||||
$errcode = "FILE_DEKASUGUI_PHP_INI_KAKUNIN";
|
||||
break;
|
||||
case 2:
|
||||
$errcode = "FILE_DEKASUGUI_HTML_KAKUNIN";
|
||||
break;
|
||||
case 3:
|
||||
$errcode = "FILE_SUKOSHIDAKE_UPLOAD";
|
||||
break;
|
||||
case 4:
|
||||
$errcode = "FILE_UPLOAD_DEKINAKATTA";
|
||||
break;
|
||||
case 6:
|
||||
$errcode = "TMP_FOLDER_NAI";
|
||||
break;
|
||||
case 7:
|
||||
$errcode = "FILE_KAKIKOMI_SIPPAI";
|
||||
break;
|
||||
case 8:
|
||||
$errcode = "PHPINFO()_KAKUNIN";
|
||||
break;
|
||||
case 0:
|
||||
// 成功だったのに move_uploaded_file() が失敗した
|
||||
if (!is_uploaded_file($uploadedFile['tmp_name'])) {
|
||||
$errcode = "TMP_FILE_NAI";
|
||||
} elseif (!is_writable(__DIR__ . '/../../../usericons/')) {
|
||||
$errcode = "SAVE_FOLDER_KAKIKOMI_KENNAI";
|
||||
} else {
|
||||
$errcode = "MOVE_UPLOAD_FILE_SIPPAI";
|
||||
}
|
||||
break;
|
||||
}
|
||||
$error_message[] = 'アップロード失敗!(1)エラーコード:' . $errcode . '';
|
||||
}
|
||||
}
|
||||
if (isset($s3result)) {
|
||||
if ($s3result == false) {
|
||||
$error_message[] = 'アップロード失敗!(1)エラーコード: S3ERROR';
|
||||
} else {
|
||||
$iconName = $s3result; // S3に保存されたファイルのパスを使用
|
||||
$currentIconPath = getUserData($pdo, $userid)["iconname"];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error_message[] = "使用できない画像形式です。(FILE_UPLOAD_DEKINAKATTA)";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(empty($iconName))) {
|
||||
$add_sql[] = "iconname = :iconname";
|
||||
}
|
||||
|
||||
|
||||
if (!(empty($post_json["header"]))) {
|
||||
$imageData = base64_decode($post_json["header"], true);
|
||||
|
||||
$tmpFilePath = tempnam(sys_get_temp_dir(), 'upload_' . createUniqId());
|
||||
file_put_contents($tmpFilePath, $imageData);
|
||||
|
||||
$HeadFiles = [
|
||||
'name' => 'upload.png',
|
||||
'type' => check_mime($tmpFilePath),
|
||||
'tmp_name' => $tmpFilePath,
|
||||
'error' => UPLOAD_ERR_OK,
|
||||
'size' => strlen($imageData),
|
||||
];
|
||||
} else {
|
||||
$HeadFiles = array();
|
||||
}
|
||||
|
||||
|
||||
if (isset($HeadFiles)) {
|
||||
if (!(empty($HeadFiles['name']))) {
|
||||
$uploadedFile = $HeadFiles;
|
||||
if (check_mime($uploadedFile['tmp_name'])) {
|
||||
$extension = pathinfo($uploadedFile['name'], PATHINFO_EXTENSION);
|
||||
delete_exif($extension, $uploadedFile['tmp_name']);
|
||||
resizeImage($uploadedFile['tmp_name'], 2048, 1024);
|
||||
|
||||
if (AMS3_CHKS == "true") {
|
||||
$userheadurl = getUserData($pdo, $userid)["headname"];
|
||||
if (filter_var($userheadurl, FILTER_VALIDATE_URL)) {
|
||||
$s3delresult = deleteAmazonS3($userheadurl);
|
||||
} else {
|
||||
$s3delresult = true;
|
||||
}
|
||||
if ($s3delresult == true) {
|
||||
$s3result = uploadAmazonS3($uploadedFile['tmp_name']);
|
||||
} else {
|
||||
$s3result = false;
|
||||
}
|
||||
} else {
|
||||
if (check_mime($uploadedFile['tmp_name']) == "image/webp") {
|
||||
$newFilename = createUniqId() . '-' . $userid . '.webp';
|
||||
} else {
|
||||
$newFilename = createUniqId() . '-' . $userid . '.' . $extension;
|
||||
}
|
||||
$uploadedPath = 'userheads/' . $newFilename;
|
||||
$result = rename($uploadedFile['tmp_name'], __DIR__ . '/../../../' . $uploadedPath);
|
||||
|
||||
if ($result) {
|
||||
$headName = $uploadedPath; // 保存されたファイルのパスを使用
|
||||
$currentHeadPath = getUserData($pdo, $userid)["headname"];
|
||||
} else {
|
||||
$errnum = $uploadedFile['error'];
|
||||
$errcode = "ERROR";
|
||||
|
||||
switch ($errnum) {
|
||||
case 1:
|
||||
$errcode = "FILE_DEKASUGUI_PHP_INI_KAKUNIN";
|
||||
break;
|
||||
case 2:
|
||||
$errcode = "FILE_DEKASUGUI_HTML_KAKUNIN";
|
||||
break;
|
||||
case 3:
|
||||
$errcode = "FILE_SUKOSHIDAKE_UPLOAD";
|
||||
break;
|
||||
case 4:
|
||||
$errcode = "FILE_UPLOAD_DEKINAKATTA";
|
||||
break;
|
||||
case 6:
|
||||
$errcode = "TMP_FOLDER_NAI";
|
||||
break;
|
||||
case 7:
|
||||
$errcode = "FILE_KAKIKOMI_SIPPAI";
|
||||
break;
|
||||
case 8:
|
||||
$errcode = "PHPINFO()_KAKUNIN";
|
||||
break;
|
||||
case 0:
|
||||
// 成功だったのに move_uploaded_file() が失敗した
|
||||
if (!is_uploaded_file($uploadedFile['tmp_name'])) {
|
||||
$errcode = "TMP_FILE_NAI";
|
||||
} elseif (!is_writable(__DIR__ . '/../../../usericons/')) {
|
||||
$errcode = "SAVE_FOLDER_KAKIKOMI_KENNAI";
|
||||
} else {
|
||||
$errcode = "MOVE_UPLOAD_FILE_SIPPAI";
|
||||
}
|
||||
break;
|
||||
}
|
||||
$error_message[] = 'アップロード失敗!(2)エラーコード:' . $errcode . '';
|
||||
}
|
||||
}
|
||||
if (isset($s3result)) {
|
||||
if ($s3result == false) {
|
||||
$error_message[] = 'アップロード失敗!(2)エラーコード: S3ERROR';
|
||||
} else {
|
||||
$headName = $s3result; // S3に保存されたファイルのパスを使用
|
||||
$currentHeadPath = getUserData($pdo, $userid)["headname"];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error_message[] = "使用できない画像形式です。(FILE_UPLOAD_DEKINAKATTA)";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!(empty($headName))) {
|
||||
$add_sql[] = "headname = :headname";
|
||||
}
|
||||
|
||||
if(empty($add_sql)) {
|
||||
$err = "input_not_found";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}else{
|
||||
$add_sql = implode(", ", $add_sql);
|
||||
}
|
||||
|
||||
if (empty($error_message)) {
|
||||
// トランザクション開始
|
||||
$pdo->beginTransaction();
|
||||
|
||||
try {
|
||||
|
||||
$stmt = $pdo->prepare("UPDATE account SET ".$add_sql." WHERE userid = :userid;");
|
||||
|
||||
// 他の値をセット
|
||||
if (!(empty($username))) {
|
||||
$stmt->bindValue(':username', $username, PDO::PARAM_STR);
|
||||
}
|
||||
if (!(empty($profile))) {
|
||||
$stmt->bindValue(':profile', $profile, PDO::PARAM_STR);
|
||||
}
|
||||
if (!(empty($iconName))) {
|
||||
$stmt->bindValue(':iconname', $iconName, PDO::PARAM_STR);
|
||||
}
|
||||
if (!(empty($headName))) {
|
||||
$stmt->bindValue(':headname', $headName, PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
$stmt->bindValue(':userid', $userid, PDO::PARAM_STR);
|
||||
$res = $stmt->execute();
|
||||
|
||||
// コミット
|
||||
if($res) {
|
||||
$pdo->commit();
|
||||
if (!(empty($iconName))) {
|
||||
if ($currentIconPath && !filter_var($currentIconPath, FILTER_VALIDATE_URL)) {
|
||||
$filePath = realpath(__DIR__ . '/../../../' . $currentIconPath);
|
||||
if ($filePath && file_exists($filePath)) {
|
||||
unlink($filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(empty($headName))) {
|
||||
if ($currentHeadPath && !filter_var($currentHeadPath, FILTER_VALIDATE_URL)) {
|
||||
$filePath = realpath(__DIR__ . '/../../../' . $currentHeadPath);
|
||||
if ($filePath && file_exists($filePath)) {
|
||||
unlink($filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$response = array(
|
||||
'success' => true
|
||||
);
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
} else {
|
||||
$pdo->rollBack();
|
||||
$err = "update_failed";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$pdo->rollBack();
|
||||
actionLog($userid, "error", "user-settings-api", null, $e, 4);
|
||||
$err = "update_failed";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = null;
|
||||
}else{
|
||||
$err = $error_message;
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$err = $AuthData[1];
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$err = "input_not_found";
|
||||
$response = array(
|
||||
'error_code' => $err,
|
||||
'success' => false
|
||||
);
|
||||
|
||||
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
Reference in New Issue
Block a user