HEX
Server: LiteSpeed
System: Linux hippo 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: tsacademy (1021)
PHP: 8.1.29
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/tsacademy/domains/tsacademy.ir/private_html/bale-latest-ticker.php
<?php
require_once("wp-load.php");
global $wpdb;

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

/**
 * تنظیمات
 */
$limit_per_table = 6;   // از هر جدول چند پیام
$max_total = 12;        // حداکثر کل خروجی

$feeds = [
    [
        'table' => $wpdb->prefix . 'bale_messages',
        'title' => 'سهام',
        'url'   => 'https://tsacademy.ir/stock-tahlil/',
    ],
    [
        'table' => $wpdb->prefix . 'bale_messages_dollar',
        'title' => 'دلار',
        'url'   => 'https://tsacademy.ir/dollar-tahlil/',
    ],
    [
        'table' => $wpdb->prefix . 'bale_messages_gold',
        'title' => 'طلا',
        'url'   => 'https://tsacademy.ir/gold-tahlil/',
    ],
    [
        'table' => $wpdb->prefix . 'bale_messages_crypto',
        'title' => 'کریپتو',
        'url'   => 'https://tsacademy.ir/crypto-tahlil/',
    ],
];

$all = [];

foreach ($feeds as $feed) {
    $table = $feed['table'];

    $rows = $wpdb->get_results("
        SELECT id, msg_type, msg_text, created_at
        FROM {$table}
        WHERE msg_text IS NOT NULL
          AND TRIM(msg_text) <> ''
          AND msg_type IN ('text','photo','voice','video','document')
        ORDER BY id DESC
        LIMIT " . intval($limit_per_table) . "
    ");

    if (!$rows) continue;

    foreach ($rows as $row) {
        $text = trim((string)$row->msg_text);

        // حذف پیام‌های سیستمی و دستوری
        if ($text === '' || strpos($text, '/') === 0) {
            continue;
        }

        $all[] = [
            'id'         => (int)$row->id,
            'msg_type'   => $row->msg_type,
            'msg_text'   => wp_strip_all_tags($text),
            'created_at' => $row->created_at,
            'title'      => $feed['title'],
            'url'        => $feed['url'],
        ];
    }
}

/**
 * مرتب‌سازی بر اساس جدیدترین
 */
usort($all, function($a, $b){
    return strtotime($b['created_at']) - strtotime($a['created_at']);
});

/**
 * حذف موارد تکراری
 */
$seen = [];
$unique = [];

foreach ($all as $item) {
    $key = md5($item['title'] . '|' . $item['msg_text']);
    if (isset($seen[$key])) {
        continue;
    }
    $seen[$key] = true;
    $unique[] = $item;
}

/**
 * محدودیت نهایی
 */
$unique = array_slice($unique, 0, $max_total);

echo json_encode($unique, JSON_UNESCAPED_UNICODE);
exit;