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
// Tepki özetini ve kullanıcının seçtiği ikonu JSON olarak döner

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

global $vbulletin;

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

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

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

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

$reactions    = array(); // reactionid => ['count'=>..., 'users'=>[ ['userid'=>..,'username'=>..], ... ]]
$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['reactionid']);
    $uid   = intval($row['l_from_userid']);
    $uname = $row['l_from_username'];

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

    $reactions[$rid]['count']++;
    $reactions[$rid]['users'][] = array(
        'userid'   => $uid,
        'username' => $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 = '';

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

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

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

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

// ---------------------------------------------------------
// 4) Özet satırının HTML'i
// ---------------------------------------------------------

$summary_html .= '<span class="ft-reaction-summary-line">';

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

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

    $icon = $reaction_icons[$rid];

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

$summary_html .= '</span>'; // ft-summary-reaction-list

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

$summary_html .= '</span>'; // 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['reactionid']);
    }
}

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

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

echo json_encode(array(
    'html'            => $summary_html,
    'user_reactionid' => $user_reactionid,
));

exit;

 

Revise this Paste

Your Name: Code Language: