Page 1 of 1

Recents Posts

Posted: 4. February 2025 15:02
by hs11
I created a page in PHP to export the latest posts and I'm using it as an iframe on the board3 portal. I would like to know how I can do this in an integrated way, through a module. Because I don't know much about development. And I would like if someone could help me with this.

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>

Re: Recents Posts

Posted: 4. February 2025 16:34
by Kirk
Go to ACP/Extensions/Portal/Portal Modules click on "Add module", select there "Custom Block"
Under "Activate BBCode for the custom block" set to no then place your iframe code in the input field.
Or create a module: [How To] Create a module for Board3 Portal 2.1.x

Re: Recents Posts

Posted: 4. February 2025 17:48
by hs11
I can't program the module, I wanted it in a module so I wouldn't use it as an iframe.

Re: Recents Posts

Posted: 4. February 2025 18:49
by Kirk
There is no other way to do this than to create your own module.

Re: Recents Posts

Posted: 5. February 2025 23:32
by hs11
How much would you charge to develop this for me?

Re: Recents Posts

Posted: 6. February 2025 05:48
by Kirk
No, it's far too time-consuming