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_reaction_modal.php
define('THIS_SCRIPT', 'ft_reaction_modal');
require('./global.php');

global $vbulletin;

// Avatar fonksiyonu
require_once(DIR . '/includes/functions_user.php');

// Çıkış: JSON + UTF-8
header('Content-Type: application/json; charset=UTF-8');

/**
 * Verilen metni forum charset'inden UTF-8'e çevirir.
 * (TR genelde ISO-8859-9, EN ISO-8859-1 vb.)
 */
function ft_to_utf8($str)
{
    if ($str === '' || $str === null) {
        return '';
    }

    // Zaten geçerli UTF-8 ise hiç dokunma
    if (preg_match('//u', $str)) {
        return $str;
    }

    // Önce Türkçe paket (ISO-8859-9) olarak dene
    $tmp = @iconv('ISO-8859-9', 'UTF-8//IGNORE', $str);
    if ($tmp !== false) {
        return $tmp;
    }

    // Olmazsa İngilizce paket (ISO-8859-1) olarak dene
    $tmp = @iconv('ISO-8859-1', 'UTF-8//IGNORE', $str);
    if ($tmp !== false) {
        return $tmp;
    }

    // Hiçbiri olmadıysa, gelen haliyle bırak
    return $str;
}

// ---------------------------
// Reaksiyon meta (ikon + etiket)
// (Etiketler forum charset'inde)
// ---------------------------
$reaction_info = array(
    1 => array('icon' => 'like.png',  'label' => 'Beğen'),
    2 => array('icon' => 'heart.png', 'label' => 'Muhteşem'),
    3 => array('icon' => 'haha.png',  'label' => 'Hahaha'),
    4 => array('icon' => 'wow.png',   'label' => 'Şaşkın'),
    5 => array('icon' => 'sad.png',   'label' => 'Üzgün'),
    6 => array('icon' => 'angry.png', 'label' => 'Kızgın'),
    7 => array('icon' => 'care.png',  'label' => 'Yanındayım'),
);

$where_rid = '';
if ($filter_rid > 0)
{
    $where_rid = ' AND vl.reactionid = ' . intval($filter_rid);
}

// ---------------------------
// Veritabanından tepkileri çek
// ---------------------------
$result = $vbulletin->db->query_read("
    SELECT vl.reactionid,
           vl.l_dateline,
           u.userid,
           u.username,
           u.posts
    FROM vbseo_likes AS vl
    LEFT JOIN user AS u
        ON (u.userid = vl.l_from_userid)
    WHERE vl.l_contentid = $postid
          $where_rid
    ORDER BY vl.reactionid, vl.l_dateline DESC
");

$groups = array();

while ($row = $vbulletin->db->fetch_array($result))
{
    $rid = intval($row['reactionid']);
    if (!$rid || !isset($reaction_info[$rid])) {
        continue;
    }

    if (!isset($groups[$rid])) {
        $groups[$rid] = array(
            'reactionid' => $rid,
            'icon'       => $reaction_info[$rid]['icon'],
            'label'      => $reaction_info[$rid]['label'], // forum charset
            'count'      => 0,
            'users'      => array(),
        );
    }

    $timestamp = intval($row['l_dateline']);

    // vBulletin tarih formatı
    if (function_exists('vbdate')) {
        $fmt     = $vbulletin->options['dateformat'] . ' ' . $vbulletin->options['timeformat'];
        $datestr = vbdate($fmt, $timestamp, true);
    } else {
        $datestr = date('d.m.Y H:i', $timestamp);
    }

    // Avatar URL
    $avatarurl = '';
    if (!empty($row['userid']) && function_exists('fetch_avatar_url')) {
        $avatarinfo = fetch_avatar_url($row['userid']);
        // vB3: genelde [0] => url, [1] => boyut vb.
        if (is_array($avatarinfo) && !empty($avatarinfo[0])) {
            $avatarurl = $avatarinfo[0];
        }
    }

    $groups[$rid]['users'][] = array(
        'userid'   => intval($row['userid']),
        'username' => $row['username'],   // forum charset
        'posts'    => intval($row['posts']),
        'avatar'   => $avatarurl,         // URL (ASCII)
        'date'     => $datestr,           // forum charset
        'rawdate'  => $timestamp,
    );

    $groups[$rid]['count']++;
}

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

// ---------------------------
// Çıkışı UTF-8'e çevirip JSON üret
// ---------------------------
$out_groups = array();

foreach ($groups as $rid => $g)
{
    $out_group = array(
        'reactionid' => $g['reactionid'],
        'icon'       => $g['icon'],
        'label'      => ft_to_utf8($g['label']),
        'count'      => $g['count'],
        'users'      => array(),
    );

    foreach ($g['users'] as $u)
    {
        $out_group['users'][] = array(
            'userid'   => $u['userid'],
            'username' => ft_to_utf8($u['username']),
            'posts'    => $u['posts'],
            'avatar'   => $u['avatar'],          // URL UTF-8’e çevirmeye gerek yok ama zararı da yok
            'date'     => ft_to_utf8($u['date']),
            'rawdate'  => $u['rawdate'],
        );
    }

    $out_groups[] = $out_group;
}

// Başlık
$title = 'İfade Bırakanlar #' . $postid;

//JSON Çıktısı
echo json_encode(array(
    'title'  => $title,
    'groups' => $out_groups,
));
exit;

 

Revise this Paste

Your Name: Code Language: