Skip to content

[2.1]: guest avatar on the home page #8572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gevv opened this issue Apr 9, 2025 · 2 comments
Open

[2.1]: guest avatar on the home page #8572

gevv opened this issue Apr 9, 2025 · 2 comments

Comments

@gevv
Copy link

gevv commented Apr 9, 2025

Basic Information

Hello, If guest can send messages, the avatar on the home page is taken from the images in the topic (random)
https://www.simplemachines.org/community/index.php?msg=4188316

Steps to reproduce

Expected result

No response

Actual result

No response

Version/Git revision

2.1.4

Database Engine

All

Database Version

No response

PHP Version

8.1

Logs

Additional Information

No response

@DiegoAndresCortes
Copy link
Member

DiegoAndresCortes commented Apr 15, 2025

I confirmed this issue.
It only happens on the BoardIndex query, not in the MessageIndex:

Issue:

// Find all boards and categories, as well as related information. This will be sorted by the natural order of boards and categories, which we control.
if ($board_index_options['parent_id'] != 0 && $smcFunc['db_cte_support']())
$result_boards = $smcFunc['db_query']('', '
WITH RECURSIVE
boards_cte (child_level, id_board, name, description, redirect, num_posts, num_topics, unapproved_posts, unapproved_topics, id_parent, id_msg_updated, id_cat, id_last_msg, board_order)
AS
(
SELECT b.child_level, b.id_board, b.name, b.description, b.redirect, b.num_posts, b.num_topics, b.unapproved_posts, b.unapproved_topics, b.id_parent, b.id_msg_updated, b.id_cat, b.id_last_msg, b.board_order
FROM {db_prefix}boards AS b
WHERE {query_see_board} AND b.id_board = {int:id_parent}
UNION ALL
SELECT b.child_level, b.id_board, b.name, b.description, b.redirect, b.num_posts, b.num_topics, b.unapproved_posts, b.unapproved_topics, b.id_parent, b.id_msg_updated, b.id_cat, b.id_last_msg, b.board_order
FROM {db_prefix}boards AS b
JOIN boards_cte AS bc ON (b.id_parent = bc.id_board)
WHERE {query_see_board}
AND b.child_level BETWEEN {int:child_level} AND {int:max_child_level}
)
SELECT' . ($board_index_options['include_categories'] ? '
c.id_cat, c.name AS cat_name, c.description AS cat_desc,' : '') . '
' . (!empty($board_index_selects) ? implode(', ', $board_index_selects) : '') . ',
COALESCE(m.poster_time, 0) AS poster_time, COALESCE(mem.member_name, m.poster_name) AS poster_name,
m.subject, m.id_topic, COALESCE(mem.real_name, m.poster_name) AS real_name,
' . ($user_info['is_guest'] ? ' 1 AS is_read, 0 AS new_from,' : '
(CASE WHEN COALESCE(lb.id_msg, 0) >= b.id_last_msg THEN 1 ELSE 0 END) AS is_read, COALESCE(lb.id_msg, -1) + 1 AS new_from,' . ($board_index_options['include_categories'] ? '
c.can_collapse,' : '')) . '
COALESCE(mem.id_member, 0) AS id_member, mem.avatar, m.id_msg' . (!empty($settings['avatars_on_boardIndex']) ? ', mem.email_address, mem.avatar, COALESCE(am.id_attach, 0) AS member_id_attach, am.filename AS member_filename, am.attachment_type AS member_attach_type' : '') . '
FROM boards_cte AS b' . ($board_index_options['include_categories'] ? '
LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' : '') . '
LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = b.id_last_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (!empty($settings['avatars_on_boardIndex']) ? '
LEFT JOIN {db_prefix}attachments AS am ON (am.id_member = m.id_member)' : '') . '' . ($user_info['is_guest'] ? '' : '
LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})') . '
WHERE b.id_parent != 0
ORDER BY ' . (!empty($board_index_options['include_categories']) ? 'c.cat_order, ' : '') . 'b.child_level DESC, b.board_order DESC',
array_merge($board_index_parameters, array(
'id_parent' => $board_index_options['parent_id']
))
);
else
$result_boards = $smcFunc['db_query']('', '
SELECT' . ($board_index_options['include_categories'] ? '
c.id_cat, c.name AS cat_name, c.description AS cat_desc,' : '') . '
' . (!empty($board_index_selects) ? implode(', ', $board_index_selects) : '') . ',
COALESCE(m.poster_time, 0) AS poster_time, COALESCE(mem.member_name, m.poster_name) AS poster_name,
m.subject, m.id_topic, COALESCE(mem.real_name, m.poster_name) AS real_name,
' . ($user_info['is_guest'] ? ' 1 AS is_read, 0 AS new_from,' : '
(CASE WHEN COALESCE(lb.id_msg, 0) >= b.id_last_msg THEN 1 ELSE 0 END) AS is_read, COALESCE(lb.id_msg, -1) + 1 AS new_from,' . ($board_index_options['include_categories'] ? '
c.can_collapse,' : '')) . '
COALESCE(mem.id_member, 0) AS id_member, mem.avatar, m.id_msg' . (!empty($settings['avatars_on_boardIndex']) ? ', mem.email_address, mem.avatar, COALESCE(am.id_attach, 0) AS member_id_attach, am.filename AS member_filename, am.attachment_type AS member_attach_type' : '') . '
FROM {db_prefix}boards AS b' . ($board_index_options['include_categories'] ? '
LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' : '') . '
LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = b.id_last_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (!empty($settings['avatars_on_boardIndex']) ? '
LEFT JOIN {db_prefix}attachments AS am ON (am.id_member = m.id_member)' : '') . '' . ($user_info['is_guest'] ? '' : '
LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})') . '
WHERE {query_see_board}
AND b.child_level BETWEEN {int:child_level} AND {int:max_child_level}
ORDER BY ' . (!empty($board_index_options['include_categories']) ? 'c.cat_order, ' : '') . 'b.child_level DESC, b.board_order DESC',
$board_index_parameters
);

No Issues:

$result = $smcFunc['db_query']('substring', '
SELECT
t.id_topic, t.num_replies, t.locked, t.num_views, t.is_sticky, t.id_poll, t.id_previous_board,
' . ($user_info['is_guest'] ? '0' : 'COALESCE(lt.id_msg, COALESCE(lmr.id_msg, -1)) + 1') . ' AS new_from,
' . ($enableParticipation ? ' COALESCE(( SELECT 1 FROM {db_prefix}messages AS parti WHERE t.id_topic = parti.id_topic and parti.id_member = {int:current_member} LIMIT 1) , 0) as is_posted_in,
' : '') . '
t.id_last_msg, t.approved, t.unapproved_posts, ml.poster_time AS last_poster_time, t.id_redirect_topic,
ml.id_msg_modified, ml.subject AS last_subject, ml.icon AS last_icon,
ml.poster_name AS last_member_name, ml.id_member AS last_id_member,' . (!empty($settings['avatars_on_indexes']) ? ' meml.avatar, meml.email_address, memf.avatar AS first_member_avatar, memf.email_address AS first_member_mail, COALESCE(af.id_attach, 0) AS first_member_id_attach, af.filename AS first_member_filename, af.attachment_type AS first_member_attach_type, COALESCE(al.id_attach, 0) AS last_member_id_attach, al.filename AS last_member_filename, al.attachment_type AS last_member_attach_type,' : '') . '
COALESCE(meml.real_name, ml.poster_name) AS last_display_name, t.id_first_msg,
mf.poster_time AS first_poster_time, mf.subject AS first_subject, mf.icon AS first_icon,
mf.poster_name AS first_member_name, mf.id_member AS first_id_member,
COALESCE(memf.real_name, mf.poster_name) AS first_display_name, ' . (!empty($modSettings['preview_characters']) ? '
SUBSTRING(ml.body, 1, ' . ($modSettings['preview_characters'] + 256) . ') AS last_body,
SUBSTRING(mf.body, 1, ' . ($modSettings['preview_characters'] + 256) . ') AS first_body,' : '') . 'ml.smileys_enabled AS last_smileys, mf.smileys_enabled AS first_smileys
' . (!empty($message_index_selects) ? (', ' . implode(', ', $message_index_selects)) : '') . '
FROM (' . $sort_table . ') as st
JOIN {db_prefix}topics AS t ON (st.id_topic = t.id_topic)
JOIN {db_prefix}messages AS ml ON (ml.id_msg = st.id_last_msg)
JOIN {db_prefix}messages AS mf ON (mf.id_msg = st.id_first_msg)
LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)
LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)' . (!empty($settings['avatars_on_indexes']) ? '
LEFT JOIN {db_prefix}attachments AS af ON (af.id_member = memf.id_member)
LEFT JOIN {db_prefix}attachments AS al ON (al.id_member = meml.id_member)' : '') . '' . ($user_info['is_guest'] ? '' : '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = {int:current_board} AND lmr.id_member = {int:current_member})') . '
' . (!empty($message_index_tables) ? implode("\n\t\t\t\t", $message_index_tables) : '') . '
' . (!empty($message_index_wheres) ? ' WHERE ' . implode("\n\t\t\t\tAND ", $message_index_wheres) : '') . '
ORDER BY is_sticky' . ($fake_ascending ? '' : ' DESC') . ', ' . $_REQUEST['sort'] . ($ascending ? '' : ' DESC'),
$message_index_parameters
);

A simple guest check could be added to the set_avatar_data, without tweaking the query:

if (!empty($settings['avatars_on_boardIndex']))
$this_last_post['member']['avatar'] = set_avatar_data(array(
'avatar' => $row_board['avatar'],
'email' => $row_board['email_address'],
'filename' => !empty($row_board['member_filename']) ? $row_board['member_filename'] : ''
));

@DiegoAndresCortes
Copy link
Member

Steps to reproduce:

  1. Allow guests to post and upload attachments
  2. Enable avatars on boardindex for your theme:
    $settings['avatars_on_boardIndex'] = false;
  3. Post as a guest, including an attachment.

Result: The avatar of the guest will be the attachment instead of the default avatar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants