Paste
Pasted as PHP by registered user atmaca ( 5 days ago )
<?php
// ft_reaction_summary.php
define('THIS_SCRIPT', 'ft_reaction_summary');
require_once('./global.php');
header('Content-Type: application/json; charset=utf-8');
global $vbulletin;
$vbulletin->input->clean_array_gpc('r', array(
'postid' => TYPE_UINT,
));
$postid = intval($vbulletin->GPC['postid']);
$userid = intval($vbulletin->userinfo['userid']);
if (!$postid)
{
echo json_encode(array(
'html' => '',
'user_reactionid' => 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['reactionid']);
if ($rid > 0)
{
$reaction_counts[$rid] = intval($row['total']);
}
}
// 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['reactionid']) > 0)
{
$user_reactionid = intval($user_row['reactionid']);
}
}
// Hiç tepki yoksa boş HTML dön
if (empty($reaction_counts))
{
echo json_encode(array(
'html' => '<span class="ft-reaction-summary-line"><span class="ft-summary-reaction-list"></span><span class="ft-summary-text"></span></span>',
'user_reactionid' => $user_reactionid, // büyük ihtimalle 0 olacak
));
exit;
}
// reactionid -> ikon yolu + label
$reaction_map = array(
1 => array('icon' => 'images/reactions/like.png', 'label' => 'Beğeni'),
2 => array('icon' => 'images/reactions/heart.png', 'label' => 'Kalp'),
3 => array('icon' => 'images/reactions/haha.png', 'label' => 'Haha'),
4 => array('icon' => 'images/reactions/wow.png', 'label' => 'Vay be'),
5 => array('icon' => 'images/reactions/sad.png', 'label' => 'Üzgün'),
6 => array('icon' => 'images/reactions/angry.png', 'label' => 'Kızgın'),
7 => array('icon' => 'images/reactions/care.png', 'label' => 'Umursuyor'),
);
// İ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]['icon']);
$label = htmlspecialchars($reaction_map[$rid]['label']);
$icon_html_parts[] =
'<span class="ft-summary-reaction" data-rid="' . $rid . '">' .
'<img class="ft-react-icon" src="' . $icon . '" alt="' . $label . '" />' .
'<span class="ft-summary-count">' . $cnt . '</span>' .
'</span>';
}
$icon_list_html = implode('', $icon_html_parts);
// Metin kısmı: toplam tepki sayısını yaz
$text_html = '';
if ($total_all == 1)
{
$text_html = '<span class="ft-summary-text">1 tepki</span>';
}
else
{
$text_html = '<span class="ft-summary-text">' . $total_all . ' tepki</span>';
}
// Dış sarmalayıcı
$html = '<span class="ft-reaction-summary-line">'
. '<span class="ft-summary-reaction-list">' . $icon_list_html . '</span>'
. $text_html
. '</span>';
echo json_encode(array(
'html' => $html,
'user_reactionid' => $user_reactionid,
));
exit;
Revise this Paste