最后参数中的头像用户

Avatar user in last arguments

我有一个 phpBB 论坛,我想在最后一个参数中将用户头像添加到数据库查询中,我已经创建了提取最后一个参数的代码,但我还希望用户头像是开了话题

这是代码

PHP 文件

$sql = 'SELECT forum_id, topic_id, topic_title, topic_time, topic_views, topic_poster, topic_posts_approved, topic_first_poster_name, topic_first_poster_colour, topic_last_post_id, topic_last_poster_name, topic_last_poster_colour, topic_last_post_time, topic_last_view_time, topic_last_poster_id
    FROM ' . TOPICS_TABLE . '
    WHERE ' . $this->db->sql_in_set('forum_id', $flast) . '
    AND ' . $this->content_visibility->get_visibility_sql('topic', 'forum_id') . '
    ORDER BY topic_last_post_time DESC';
$result = $this->db->sql_query_limit($sql, $this->config['total']);

while ($row = $this->db->sql_fetchrow($result))
{
$this->template->assign_block_vars('topic', array(
        'LAST_TOPIC'      => append_sid("{$this->phpbb_root_path}viewtopic.$this->phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']),
        'U_LAST_TOPIC'   => append_sid("{$this->phpbb_root_path}viewtopic.$this->phpEx", 'f=' . $row['forum_id'] . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id']),
        'LAST_POSTER'     => append_sid("{$this->phpbb_root_path}memberlist.$this->phpEx", 'mode=viewprofile' . '&u=' . $row['topic_poster']),
        'USERNAME_LAST'  => append_sid("{$this->phpbb_root_path}memberlist.$this->phpEx", 'mode=viewprofile' . '&u=' . $row['topic_last_poster_id']),
        'TOPIC_TITLE'                   => $row['topic_title'],
        'TOPIC_VIEWS'                   => $row['topic_views'],
        'TOPIC_REPLIES'                 => $row['topic_posts_approved'],
        'TOPIC_LAST_POSTER_NAME'        => $row['topic_last_poster_name'],
        'TOPIC_LAST_POSTER_COLOUR'      => $row['topic_last_poster_colour'],
        'TOPIC_LAST_POST_TIME'          => $this->user->format_date($row['topic_last_post_time']),
        'TOPIC_LAST_VIEW_TIME'          => $this->user->format_date($row['topic_last_view_time']),
    ));
}
$this->db->sql_freeresult($result);

感谢您的大力帮助

您无需将用户头像存储到数据库中即可获得您描述的结果。有一个函数可以为您完成所有工作,它实际上被 phpBB 本身用来在 e.x 中显示用户头像。查看主题页面。

在 phpBB 3.0 中:

includes/functions_display.php
function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false)

在较新的版本中:

includes/functions.php
function phpbb_get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false, $lazy = false)

然后是这样的:

PHP

$this->template->assign_block_vars('last_topic', array(
        ...
        'USER_AVATAR'          => phpbb_get_user_avatar($data),
        ...
    ));
}

HTML

<!-- BEGIN last_topic -->
<li>
{L_POST_BY_AUTHOR}
{USER_AVATAR}
<a style="font-weight:bold; color: #{last_topic.TOPIC_LAST_POSTER_COLOUR};" href="{last_topic.USERNAME_LAST}"> <img src="{BOARD_URL}ext/galandas/lasttopics/styles/all/theme/images/icon_profile.png" height="20" width="20" title="{last_topic.TOPIC_LAST_POSTER_NAME}" alt="" /> {last_topic.TOPIC_LAST_POSTER_NAME}</a> <i class="fa fa-clock-o"></i> {last_topic.TOPIC_LAST_POST_TIME}&nbsp;<a href="{last_topic.LAST_LINK}" title="{last_topic.TOPIC_TITLE}"><span style="color: #BF0000">{last_topic.TOPIC_TITLE}</span></a> <a href="{last_topic.U_LAST_TOPIC}" title="{L_VIEW_LATEST_POST}"><i class="icon fa-external-link-square fa-fw icon-lightgray icon-md" aria-hidden="true"></i><span class="sr-only">{L_VIEW_LATEST_POST}</span></a> {L_REPLIES}&nbsp;{last_topic.TOPIC_REPLIES}&nbsp;{L_VIEWS} {last_topic.TOPIC_VIEWS}
</li>
<!-- END last_topic -->

编辑

传递给 phpbb_get_user_avatar 函数的参数应该是来自用户 table 的行,像这样:

$sql = 'SELECT u.*, s.*
    FROM ' . USERS_TABLE . ' u
        LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
    WHERE u.user_id = ' . $user_id . '
    ORDER BY s.session_time DESC';
$result = $db->sql_query_limit($sql, 1);
$data = $db->sql_fetchrow($result);

你应该根据你的代码调整它,没有人会给你一个即插即用的解决方案。