Code: Select all
<?php
// Configuração do phpBB
define('IN_PHPBB', true);
$phpbb_root_path = __DIR__ . '/../'; // Ajuste para acessar o phpBB a partir de uma pasta separada
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
// Inicializa o phpBB
$user->session_begin();
$auth->acl($user->data);
$user->setup();
// Consulta os últimos 15 tópicos visíveis para o usuário
$sql = 'SELECT t.topic_id, t.topic_title, t.forum_id, t.topic_time, t.topic_last_post_id, t.topic_poster, f.forum_name, u.username, u.user_id 
        FROM ' . TOPICS_TABLE . ' t
        JOIN ' . FORUMS_TABLE . ' f ON t.forum_id = f.forum_id
        JOIN ' . USERS_TABLE . ' u ON t.topic_poster = u.user_id
        WHERE t.topic_visibility = 1
        ORDER BY t.topic_time DESC
        LIMIT 15';
$result = $db->sql_query($sql);
$topics = [];
while ($row = $db->sql_fetchrow($result)) {
    if ($auth->acl_get('f_read', $row['forum_id'])) {
        $topics[] = $row;
    }
}
$db->sql_freeresult($result);
// Função para calcular tempo decorrido ou exibir a data
function time_elapsed_string($datetime) {
    $now = new DateTime();
    $ago = new DateTime('@' . $datetime);
    $diff = $now->diff($ago);
    $days = $diff->days;
    if ($days >= 1) {
        return date('d/m/Y H:i', $datetime);
    }
    $string = [
        'hora' => $diff->h,
        'minuto' => $diff->i,
        'segundo' => $diff->s,
    ];
    foreach ($string as $key => &$value) {
        if ($value) {
            return $value . ' ' . $key . ($value > 1 ? 's' : '') . ' atrás';
        }
    }
    return 'agora';
}
// Saída HTML para o iframe
header('Content-Type: text/html; charset=UTF-8');
?>
<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="../styles/zeina/theme/assets/css/stylesheet.css?assets_version=250" rel="stylesheet" media="screen">
    <style>
        body { font-family: Arial, sans-serif; font-size: 14px; margin: 10px; }
        ul { list-style: none; padding: 0; }
        li { margin-bottom: 10px; }
        a { text-decoration: none; color: #0073e6; }
        a:hover { text-decoration: underline; }
    </style>
</head>
<body>
    <ul>
        <?php foreach ($topics as $topic): ?>
            <li>
                <a class="font-semibold" href="../viewtopic.php?p=<?= $topic['topic_last_post_id'] ?>#p<?= $topic['topic_last_post_id'] ?>" target="_blank">
                    <?= htmlspecialchars($topic['topic_title']) ?>
                </a>
                <br>
                <small>
                    Por 
                    <a class="font-semibold" href="../memberlist.php?mode=viewprofile&u=<?= $topic['user_id'] ?>" target="_blank">
                        <?= htmlspecialchars($topic['username']) ?>
                    </a> 
                    em <?= time_elapsed_string($topic['topic_time']) ?>
                </small>
            </li>
        <?php endforeach; ?>
    </ul>
</body>
</html>

