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

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

global $vbulletin;

$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;]);

if (!$postid)
{
    echo json_encode(array(
        &#039;html&#039;             => &#039;&#039;,
        &#039;user_reactionid&#039;  => 0,
    ));
    exit;
}

// Bu posttaki tüm tepkileri say (vbseo_likes tablosu üzerinden)
$reactions_q = $vbulletin->db->query_read("
    SELECT reactionid, COUNT(*) AS total
    FROM vbseo_likes
    WHERE l_contentid = $postid
    GROUP BY reactionid
");

// reactionid => count map
$reaction_counts = array();
while ($row = $vbulletin->db->fetch_array($reactions_q))
{
    $rid = intval($row[&#039;reactionid&#039;]);
    if ($rid > 0)
    {
        $reaction_counts[$rid] = intval($row[&#039;total&#039;]);
    }
}

// O anki kullanıcının bu posttaki tepkisi
$user_reactionid = 0;
if ($userid)
{
    $user_row = $vbulletin->db->query_first("
        SELECT reactionid
        FROM vbseo_likes
        WHERE l_contentid   = $postid
          AND l_from_userid = $userid
        LIMIT 1
    ");
    if ($user_row && intval($user_row[&#039;reactionid&#039;]) > 0)
    {
        $user_reactionid = intval($user_row[&#039;reactionid&#039;]);
    }
}

// Hiç tepki yoksa boş HTML dön
if (empty($reaction_counts))
{
    echo json_encode(array(
        &#039;html&#039;            => &#039;<span class="ft-reaction-summary-line"><span class="ft-summary-reaction-list"></span><span class="ft-summary-text"></span></span>&#039;,
        &#039;user_reactionid&#039; => $user_reactionid, // büyük ihtimalle 0 olacak
    ));
    exit;
}

// reactionid -> ikon yolu + label
$reaction_map = array(
    1 => array(&#039;icon&#039; => &#039;images/reactions/like.png&#039;,  &#039;label&#039; => &#039;Beğeni&#039;),
    2 => array(&#039;icon&#039; => &#039;images/reactions/heart.png&#039;, &#039;label&#039; => &#039;Kalp&#039;),
    3 => array(&#039;icon&#039; => &#039;images/reactions/haha.png&#039;,  &#039;label&#039; => &#039;Haha&#039;),
    4 => array(&#039;icon&#039; => &#039;images/reactions/wow.png&#039;,   &#039;label&#039; => &#039;Vay be&#039;),
    5 => array(&#039;icon&#039; => &#039;images/reactions/sad.png&#039;,   &#039;label&#039; => &#039;Üzgün&#039;),
    6 => array(&#039;icon&#039; => &#039;images/reactions/angry.png&#039;, &#039;label&#039; => &#039;Kızgın&#039;),
    7 => array(&#039;icon&#039; => &#039;images/reactions/care.png&#039;,  &#039;label&#039; => &#039;Umursuyor&#039;),
);

// İkon listesini oluştur
$icon_html_parts = array();
$total_all       = 0;

foreach ($reaction_counts as $rid => $cnt)
{
    $total_all += $cnt;
    if (!isset($reaction_map[$rid]))
    {
        continue;
    }
    $icon  = htmlspecialchars($reaction_map[$rid][&#039;icon&#039;]);
    $label = htmlspecialchars($reaction_map[$rid][&#039;label&#039;]);

    $icon_html_parts[] =
        &#039;<span class="ft-summary-reaction" data-rid="&#039; . $rid . &#039;">&#039; .
            &#039;<img class="ft-react-icon" src="&#039; . $icon . &#039;" alt="&#039; . $label . &#039;" />&#039; .
            &#039;<span class="ft-summary-count">&#039; . $cnt . &#039;</span>&#039; .
        &#039;</span>&#039;;
}

$icon_list_html = implode(&#039;&#039;, $icon_html_parts);

// Metin kısmı: toplam tepki sayısını yaz
$text_html = &#039;&#039;;
if ($total_all == 1)
{
    $text_html = &#039;<span class="ft-summary-text">1 tepki</span>&#039;;
}
else
{
    $text_html = &#039;<span class="ft-summary-text">&#039; . $total_all . &#039; tepki</span>&#039;;
}

// Dış sarmalayıcı
$html = &#039;<span class="ft-reaction-summary-line">&#039;
      . &#039;<span class="ft-summary-reaction-list">&#039; . $icon_list_html . &#039;</span>&#039;
      . $text_html
      . &#039;</span>&#039;;

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

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