Paste
Pasted as PHP by registered user atmaca ( 3 months ago )
<?php
define('THIS_SCRIPT', 'ft_react');
require_once('./global.php');
header('Content-Type: application/json; charset=UTF-8');
// Kullanıcı girişi zorunlu
if (empty($vbulletin->userinfo['userid']))
{
echo json_encode([
'success' => false,
'error' => 'login_required'
]);
exit;
}
$userid = intval($vbulletin->userinfo['userid']);
$username = $vbulletin->db->escape_string($vbulletin->userinfo['username']);
$postid = isset($_GET['postid']) ? intval($_GET['postid']) : 0;
$reaction = isset($_GET['reaction']) ? intval($_GET['reaction']) : 0;
// Güvenlik: postid / reaction kontrolü
if ($postid <= 0 || $reaction <= 0)
{
echo json_encode([
'success' => false,
'error' => 'invalid_params'
]);
exit;
}
// Şimdilik bütün tepki tipleri için tek type kullanıyoruz
$reaction_type = 1; // "reaction" gibi düşünebilirsin
// Bu kullanıcı bu mesaja daha önce tepki vermiş mi?
$existing = $vbulletin->db->query_first("
SELECT reactionid
FROM vbseo_likes
WHERE l_contentid = $postid
AND l_ctype = 1
AND l_cgroup = 0
AND l_from_userid = $userid
");
// Aynı tepkiye tekrar bastıysa → kaydı sil (toggle off)
if ($existing && intval($existing['reactionid']) === $reaction)
{
$vbulletin->db->query_write("
DELETE FROM vbseo_likes
WHERE l_contentid = $postid
AND l_ctype = 1
AND l_cgroup = 0
AND l_from_userid = $userid
");
echo json_encode([
'success' => true,
'reaction' => $reaction,
'removed' => true
]);
exit;
}
// Farklı bir tepkiye geçtiyse → tek satırı güncelle
if ($existing)
{
$vbulletin->db->query_write("
UPDATE vbseo_likes
SET reactionid = $reaction,
reaction_type = $reaction_type,
l_dateline = " . TIMENOW . "
WHERE l_contentid = $postid
AND l_ctype = 1
AND l_cgroup = 0
AND l_from_userid = $userid
");
}
else
{
// İlk kez tepki veriyorsa → yeni satır
$dest = $vbulletin->db->query_first("
SELECT userid
FROM " . TABLE_PREFIX . "post
WHERE postid = $postid
LIMIT 1
");
$dest_userid = intval($dest['userid']);
$vbulletin->db->query_write("
INSERT INTO vbseo_likes
(l_contentid, l_ctype, l_cgroup, l_from_userid, l_from_username,
l_dest_userid, l_dateline, reaction_type, reactionid)
VALUES
($postid, 1, 0, $userid, '$username',
$dest_userid, " . TIMENOW . ", $reaction_type, $reaction)
");
}
echo json_encode([
'success' => true,
'reaction' => $reaction,
'removed' => false
]);
exit;
Revise this Paste
Parent: 130364