1
0
mirror of https://github.com/Daichimarukana/uwuzu.git synced 2026-06-05 03:24:41 +00:00

uwuzu version 1.2.18

This commit is contained in:
daichimarukana
2023-09-06 01:00:38 +09:00
parent 0bb6fa1508
commit 66a93d34ec
21 changed files with 317 additions and 274 deletions
+44 -36
View File
@@ -2,53 +2,61 @@
require('../db.php');
if (htmlentities(isset($_POST['uniqid'])) && htmlentities(isset($_POST['userid']))) {
session_name('uwuzu_s_id');
session_start();
session_regenerate_id(true);
$ses_userid = $_SESSION['userid'];
$postUniqid = htmlentities($_POST['uniqid']);
$userId = htmlentities($_POST['userid']);
try {
$pdo = new PDO('mysql:charset=utf8mb4;dbname='.DB_NAME.';host='.DB_HOST , DB_USER, DB_PASS);
if($userId === $ses_userid){
try {
$pdo = new PDO('mysql:charset=utf8mb4;dbname='.DB_NAME.';host='.DB_HOST , DB_USER, DB_PASS);
// 投稿のいいね情報を取得
$stmt = $pdo->prepare("SELECT favorite FROM ueuse WHERE uniqid = :uniqid");
$stmt->bindValue(':uniqid', $postUniqid, PDO::PARAM_STR);
$stmt->execute();
$post = $stmt->fetch(PDO::FETCH_ASSOC);
// 投稿のいいね情報を取得
$stmt = $pdo->prepare("SELECT favorite FROM ueuse WHERE uniqid = :uniqid");
$stmt->bindValue(':uniqid', $postUniqid, PDO::PARAM_STR);
$stmt->execute();
$post = $stmt->fetch(PDO::FETCH_ASSOC);
if ($post) {
$favoriteList = explode(',', $post['favorite']);
$index = array_search($userId, $favoriteList);
if ($index === false) {
// ユーザーIDを追加
$favoriteList[] = $userId;
} else {
// ユーザーIDを削除
array_splice($favoriteList, $index, 1);
}
// 新しいいいね情報を更新
$newFavorite = implode(',', $favoriteList);
$updateQuery = $pdo->prepare("UPDATE ueuse SET favorite = :favorite WHERE uniqid = :uniqid");
$updateQuery->bindValue(':favorite', $newFavorite, PDO::PARAM_STR);
$updateQuery->bindValue(':uniqid', $postUniqid, PDO::PARAM_STR);
$res = $updateQuery->execute();
if ($res) {
echo json_encode(['success' => true, 'newFavorite' => $newFavorite]);
exit;
} else {
echo json_encode(['success' => false, 'error' => 'いいねの更新に失敗しました。']);
exit;
}
if ($post) {
$favoriteList = explode(',', $post['favorite']);
$index = array_search($userId, $favoriteList);
if ($index === false) {
// ユーザーIDを追加
$favoriteList[] = $userId;
} else {
// ユーザーIDを削除
array_splice($favoriteList, $index, 1);
}
// 新しいいいね情報を更新
$newFavorite = implode(',', $favoriteList);
$updateQuery = $pdo->prepare("UPDATE ueuse SET favorite = :favorite WHERE uniqid = :uniqid");
$updateQuery->bindValue(':favorite', $newFavorite, PDO::PARAM_STR);
$updateQuery->bindValue(':uniqid', $postUniqid, PDO::PARAM_STR);
$res = $updateQuery->execute();
if ($res) {
echo json_encode(['success' => true, 'newFavorite' => $newFavorite]);
exit;
} else {
echo json_encode(['success' => false, 'error' => 'いいねの更新に失敗しました。']);
echo json_encode(['success' => false, 'error' => '投稿が見つかりません。']);
exit;
}
} else {
echo json_encode(['success' => false, 'error' => '投稿が見つかりません。']);
} catch(PDOException $e) {
echo json_encode(['success' => false, 'error' => 'データベースエラー:' . $e->getMessage()]);
exit;
}
} catch(PDOException $e) {
echo json_encode(['success' => false, 'error' => 'データベースエラー:' . $e->getMessage()]);
exit;
}
} else {
echo json_encode(['success' => false, 'error' => '必要なパラメータが提供されていません。']);