<?php
// Tepki özetini ve kullanıcının seçtiği ikonu JSON olarak döner

define(&#039;THIS_SCRIPT&#039;, &#039;ft_reaction_summary&#039;);
require_once(&#039;./global.php&#039;);

global $vbulletin;

// postid al
$vbulletin->input->clean_array_gpc(&#039;r&#039;, array(
    &#039;postid&#039; => TYPE_UINT,
));

$postid = intval($vbulletin->GPC[&#039;postid&#039;]);
$userid = intval($vbulletin->userinfo[&#039;userid&#039;]);

// Geçersiz postid ise boş dön
if (!$postid)
{
    header(&#039;Content-Type: application/json; charset=utf-8&#039;);
    echo json_encode(array(
        &#039;html&#039;            => &#039;&#039;,
        &#039;user_reactionid&#039; => 0,
    ));
    exit;
}

// ---------------------------------------------------------
// 1) Bu mesaja bırakılmış tüm tepkileri çek
// ---------------------------------------------------------

$reactions    = array(); // reactionid => [&#039;count&#039;=>..., &#039;users&#039;=>[ [&#039;userid&#039;=>..,&#039;username&#039;=>..], ... ]]
$uniqueUsers  = array(); // userid => username

$result = $vbulletin->db->query_read("
    SELECT l_from_userid, l_from_username, reactionid
    FROM vbseo_likes
    WHERE l_contentid = $postid
      AND l_ctype     = 1
      AND l_cgroup    = 0
");

while ($row = $vbulletin->db->fetch_array($result))
{
    $rid   = intval($row[&#039;reactionid&#039;]);
    $uid   = intval($row[&#039;l_from_userid&#039;]);
    $uname = $row[&#039;l_from_username&#039;];

    // reactionid grubu
    if (!isset($reactions[$rid]))
    {
        $reactions[$rid] = array(
            &#039;count&#039; => 0,
            &#039;users&#039; => array(),
        );
    }

    $reactions[$rid][&#039;count&#039;]++;
    $reactions[$rid][&#039;users&#039;][] = array(
        &#039;userid&#039;   => $uid,
        &#039;username&#039; => $uname,
    );

    // metin kısmı için benzersiz kullanıcı listesi
    if (!isset($uniqueUsers[$uid]))
    {
        $uniqueUsers[$uid] = $uname;
    }
}

$vbulletin->db->free_result($result);

$totalUsers = count($uniqueUsers);

// ---------------------------------------------------------
// 2) "X ve Y ifade bıraktı" metnini üret
// ---------------------------------------------------------

$text = &#039;&#039;;

if ($totalUsers > 0)
{
    $names = array_values($uniqueUsers);

    if ($totalUsers == 1)
    {
        $text = $names[0] . &#039; ifade bıraktı&#039;;
    }
    elseif ($totalUsers == 2)
    {
        $text = $names[0] . &#039; ve &#039; . $names[1] . &#039; ifade bıraktı&#039;;
    }
    else
    {
        $kalan = $totalUsers - 2;
        $text  = $names[0] . &#039;, &#039; . $names[1] . &#039; ve &#039; . $kalan . &#039; kişi daha ifade bıraktı&#039;;
    }
}

// ---------------------------------------------------------
// 3) reactionid -> ikon dosyası
// ---------------------------------------------------------

$reaction_icons = array(
    1 => &#039;like.png&#039;,
    2 => &#039;heart.png&#039;,
    3 => &#039;haha.png&#039;,
    4 => &#039;wow.png&#039;,
    5 => &#039;sad.png&#039;,
    6 => &#039;angry.png&#039;,
    7 => &#039;care.png&#039;,
);

// ---------------------------------------------------------
// 4) Özet satırının HTML&#039;i
// ---------------------------------------------------------

$summary_html .= &#039;<span class="ft-reaction-summary-line">&#039;;

// 1) ÖNCE ikon listesi
$summary_html .= &#039;<span class="ft-summary-reaction-list">&#039;;

foreach ($reactions as $rid => $data)
{
    if (empty($reaction_icons[$rid]))
    {
        continue;
    }

    $icon = $reaction_icons[$rid];

    $summary_html .=
        &#039;<span class="ft-summary-reaction">&#039;
      .     &#039;<a href="#" onclick="ft_open_react_modal(&#039; . $postid . &#039;, &#039; . $rid . &#039;); return false;">&#039;
      .         &#039;<img src="images/reactions/&#039; . $icon . &#039;"&#039;
      .               &#039; class="ft-summary-mini-icon" alt="" />&#039;
      .     &#039;</a>&#039;
      . &#039;</span>&#039;;
}

$summary_html .= &#039;</span>&#039;; // ft-summary-reaction-list

// 2) SONRA metin
$summary_html .= &#039;<span class="ft-summary-text">&#039;
              .  htmlspecialchars_uni($text)
              .  &#039;</span>&#039;;

$summary_html .= &#039;</span>&#039;; // ft-reaction-summary-line

// ---------------------------------------------------------
// 5) Bu mesaja ŞU ANKİ kullanıcının bıraktığı tepki
//    (beğen düğmesinin ikonunu ayarlamak için)
// ---------------------------------------------------------

$user_reactionid = 0;

if ($userid)
{
    $row = $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
        LIMIT 1
    ");

    if ($row)
    {
        $user_reactionid = intval($row[&#039;reactionid&#039;]);
    }
}

// ---------------------------------------------------------
// 6) JSON cevap
// ---------------------------------------------------------

header(&#039;Content-Type: application/json; charset=utf-8&#039;);

echo json_encode(array(
    &#039;html&#039;            => $summary_html,
    &#039;user_reactionid&#039; => $user_reactionid,
));

exit;

Add a code snippet to your website: www.paste.org