Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.

Paste

Pasted as PHP by registered user atmaca ( 5 days ago )
<?php
// ft_react.php - Tepki ekleme / değiştirme / kaldırma

define('THIS_SCRIPT', 'ft_react');
require_once('./global.php');

header('Content-Type: application/json; charset=utf-8');

global $vbulletin;

// Giriş kontrolü
if (empty($vbulletin->userinfo['userid']))
{
    echo json_encode(array(
        'success' => false,
        'error'   => 'not_logged_in',
    ));
    exit;
}

// Parametreleri al
$vbulletin->input->clean_array_gpc('p', array(
    'type'       => TYPE_STR,   // şimdilik 'post'
    'postid'     => TYPE_UINT,
    'reactionid' => TYPE_UINT,
));

$type       = $vbulletin->GPC['type'];
$postid     = intval($vbulletin->GPC['postid']);
$reactionid = intval($vbulletin->GPC['reactionid']);
$userid     = intval($vbulletin->userinfo['userid']);
$username   = $vbulletin->userinfo['username'];

if (!$postid || !$reactionid)
{
    echo json_encode(array(
        'success' => false,
        'error'   => 'invalid_params',
    ));
    exit;
}

// Geçerli tepki ID'leri
$valid_reactions = array(1,2,3,4,5,6,7);
if (!in_array($reactionid, $valid_reactions))
{
    echo json_encode(array(
        'success' => false,
        'error'   => 'invalid_reaction',
    ));
    exit;
}

// Mesaj sahibini bul
$post = $vbulletin->db->query_first("
    SELECT userid
    FROM " . TABLE_PREFIX . "post
    WHERE postid = $postid
    LIMIT 1
");

if (!$post)
{
    echo json_encode(array(
        'success' => false,
        'error'   => 'post_not_found',
    ));
    exit;
}

$dest_userid = intval($post['userid']);

// Kullanıcı kendi mesajına tepki veremesin
if ($userid && $dest_userid == $userid)
{
    echo json_encode(array(
        'success' => false,
        'error'   => 'own_post',
    ));
    exit;
}

$now = TIMENOW;

// Bu kullanıcı bu posta daha önce tepki bırakmış mı?
$existing = $vbulletin->db->query_first("
    SELECT *
    FROM vbseo_likes
    WHERE l_contentid   = $postid
      AND l_ctype       = 1
      AND l_cgroup      = 0
      AND l_from_userid = $userid
    LIMIT 1
");

// Aynı tepkiye tekrar basarsa → kaydı sil (toggle off)
if ($existing && intval($existing['reactionid']) == $reactionid)
{
    $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(array(
        'success'         => true,
        'removed'         => true,
        'user_reactionid' => 0,
    ));
    exit;
}

// $new_reactionid: Kullanıcının o post için SON durumu
//   - 0      => tepki kaldırıldı
//   - 1..7   => seçilen reactionid

header('Content-Type: application/json; charset=UTF-8');
echo json_encode(array(
    'success'          => true,
    'user_reactionid'  => intval($new_reactionid),
));
exit;

// Kayıt var ama reaction farklıysa → UPDATE
if ($existing)
{
    $vbulletin->db->query_write("
        UPDATE vbseo_likes
        SET reactionid = $reactionid,
            l_dateline = $now
        WHERE l_contentid   = $postid
          AND l_ctype       = 1
          AND l_cgroup      = 0
          AND l_from_userid = $userid
    ");
}
else
{
    // Yeni tepki
    $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, reactionid)
        VALUES
            ($postid, 1, 0,
             $userid, '" . $vbulletin->db->escape_string($username) . "',
             $dest_userid, $now, $reactionid)
    ");
}

// Burada ileride vBSEO bildirim / sayaç entegrasyonu da yapabiliriz

echo json_encode(array(
    'success'         => true,
    'removed'         => false,
    'user_reactionid' => $reactionid,
));
exit;

 

Revise this Paste

Your Name: Code Language: