mirror of
https://github.com/Daichimarukana/uwuzu.git
synced 2026-06-05 03:24:41 +00:00
uwuzu v1.4.8 Funium
This commit is contained in:
+7
-53
@@ -19,66 +19,20 @@ if (safetext(isset($_POST['uniqid'])) && safetext(isset($_POST['userid'])) && sa
|
||||
}
|
||||
|
||||
// データベース接続の設定
|
||||
$dbh = new PDO('mysql:charset=utf8mb4;dbname='.DB_NAME.';host='.DB_HOST, DB_USER, DB_PASS, array(
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
|
||||
));
|
||||
|
||||
$query = $dbh->prepare('SELECT * FROM account WHERE userid = :userid limit 1');
|
||||
$query = $pdo->prepare('SELECT * FROM account WHERE userid = :userid limit 1');
|
||||
|
||||
$query->execute(array(':userid' => $userId));
|
||||
|
||||
$result2 = $query->fetch();
|
||||
|
||||
if($result2["loginid"] === $loginid){
|
||||
$res = addFavorite($pdo, $postUniqid, $userId);
|
||||
|
||||
try {
|
||||
$pdo = new PDO('mysql:charset=utf8mb4;dbname='.DB_NAME.';host='.DB_HOST , DB_USER, DB_PASS);
|
||||
|
||||
// 投稿のいいね情報を取得
|
||||
$stmt = $pdo->prepare("SELECT account,ueuse,favorite FROM ueuse WHERE uniqid = :uniqid");
|
||||
$stmt->bindValue(':uniqid', $postUniqid, PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
$post = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!(empty($post))) {
|
||||
$favoriteList = explode(',', $post['favorite']);
|
||||
$index = array_search($userId, $favoriteList);
|
||||
|
||||
if ($index === false) {
|
||||
// ユーザーIDを追加
|
||||
$favoriteList[] = $userId;
|
||||
|
||||
send_notification(safetext($post['account']),$userId,"".$userId."さんがいいねしました!",safetext($post['ueuse']),"/!".$postUniqid."","favorite");
|
||||
|
||||
} 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;
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'error' => '投稿が見つかりません。']);
|
||||
exit;
|
||||
}
|
||||
} catch(PDOException $e) {
|
||||
echo json_encode(['success' => false, 'error' => 'データベースエラー:' . $e->getMessage()]);
|
||||
if ($res[0] === true) {
|
||||
echo json_encode(['success' => true, 'newFavorite' => $res[2]]);
|
||||
exit;
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'error' => 'いいねの更新に失敗しました。']);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user